#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
fix(annotate): transparent shape fills and hollow default shapes (#8574)
Reece Browne59b20609227e
diff --git a/frontend/editor/public/locales/en-US/translation.toml b/frontend/editor/public/locales/en-US/translation.tomlindex b8acd8e86d..736e610b3c 100644--- a/frontend/editor/public/locales/en-US/translation.toml+++ b/frontend/editor/public/locales/en-US/translation.toml@@ -3631,6 +3631,7 @@ tooltip = "Pick color from screen"hue = "Hue"saturation = "Saturation and brightness"title = "Choose color"+transparent = "Transparent"[common]actions = "Actions"diff --git a/frontend/editor/src/core/components/annotation/shared/ColorControl.tsx b/frontend/editor/src/core/components/annotation/shared/ColorControl.tsxindex 21fb153443..db85d4f897 100644--- a/frontend/editor/src/core/components/annotation/shared/ColorControl.tsx+++ b/frontend/editor/src/core/components/annotation/shared/ColorControl.tsx@@ -6,7 +6,7 @@ import {ColorPicker as MantineColorPicker,Group,} from "@mantine/core";-import { useState, useCallback, useEffect } from "react";+import { useState, useCallback, useEffect, type CSSProperties } from "react";import { useTranslation } from "react-i18next";import { Icon } from "@app/ui/Icon";import { ActionIcon } from "@app/ui/ActionIcon";@@ -21,6 +21,13 @@ interface EyeDropper {}declare const EyeDropper: { new (): EyeDropper };+// Mantine's dark-scheme checkerboard is near-black and vanishes on dark+// surfaces; the light one reads as "transparent" in both schemes.+const LIGHT_CHECKERBOARD = {+ "--alpha-overlay-color": "var(--mantine-color-gray-3)",+ "--alpha-overlay-bg": "var(--mantine-color-white)",+} as CSSProperties;+interface ColorControlProps {value: string;onChange: (color: string) => void;@@ -72,7 +79,11 @@ export function ColorControl({disabled={disabled}aria-label={label}>- <ColorSwatch color={localColor} size={18} />+ <ColorSwatch+ color={localColor}+ size={18}+ style={LIGHT_CHECKERBOARD}+ /></button></Tooltip></Popover.Target>@@ -93,13 +104,34 @@ export function ColorControl({"#ff00ff","#00ffff","#ffa500",- "transparent",]}swatchesPerRow={5}size="sm"/>- {supportsEyeDropper && (- <Group justify="flex-end">+ {/* Outside the picker's swatches: in hex format Mantine strips the+ alpha channel, so a "transparent" swatch there emits #000000. */}+ <Group justify="space-between">+ <Tooltip label={t("colorPicker.transparent", "Transparent")}>+ <ColorSwatch+ component="button"+ type="button"+ color="transparent"+ size={22}+ aria-label={t("colorPicker.transparent", "Transparent")}+ aria-pressed={localColor === "transparent"}+ withShadow={false}+ style={{+ ...LIGHT_CHECKERBOARD,+ cursor: "pointer",+ border: "1px solid var(--c-border-strong)",+ }}+ onClick={() => {+ setLocalColor("transparent");+ onChange("transparent");+ }}+ />+ </Tooltip>+ {supportsEyeDropper && (<Tooltiplabel={t("color.eyeDropper.tooltip", "Pick colour from screen")}>@@ -116,8 +148,8 @@ export function ColorControl({<Icon name="pipette" size={16} /></ActionIcon></Tooltip>- </Group>- )}+ )}+ </Group></Stack></Popover.Dropdown></Popover>diff --git a/frontend/editor/src/core/components/annotation/shared/ColorPicker.tsx b/frontend/editor/src/core/components/annotation/shared/ColorPicker.tsxindex bfc53d5252..9137222e66 100644--- a/frontend/editor/src/core/components/annotation/shared/ColorPicker.tsx+++ b/frontend/editor/src/core/components/annotation/shared/ColorPicker.tsx@@ -76,7 +76,7 @@ export const ColorPicker: React.FC<ColorPickerProps> = ({{resolvedOpacityLabel}</Text><Slider- min={10}+ min={0}max={100}value={opacity}onChange={onOpacityChange}diff --git a/frontend/editor/src/core/components/annotation/shared/OpacityControl.tsx b/frontend/editor/src/core/components/annotation/shared/OpacityControl.tsxindex fb2fe032f3..8ec8204a10 100644--- a/frontend/editor/src/core/components/annotation/shared/OpacityControl.tsx+++ b/frontend/editor/src/core/components/annotation/shared/OpacityControl.tsx@@ -40,7 +40,7 @@ export function OpacityControl({<Slidervalue={value}onChange={onChange}- min={10}+ min={0}max={100}label={(val) => `${val}%`}/>diff --git a/frontend/editor/src/core/components/annotation/shared/PropertiesPopover.tsx b/frontend/editor/src/core/components/annotation/shared/PropertiesPopover.tsxindex 080a972cb3..a875747505 100644--- a/frontend/editor/src/core/components/annotation/shared/PropertiesPopover.tsx+++ b/frontend/editor/src/core/components/annotation/shared/PropertiesPopover.tsx@@ -81,7 +81,7 @@ export function PropertiesPopover({<Slidervalue={Math.round((obj?.opacity ?? 1) * 100)}onChange={(val) => onUpdate({ opacity: val / 100 })}- min={10}+ min={0}max={100}label={(val) => `${val}%`}/>@@ -139,7 +139,7 @@ export function PropertiesPopover({fillOpacity: newOpacity,});}}- min={10}+ min={0}max={100}label={(val) => `${val}%`}/>diff --git a/frontend/editor/src/core/components/viewer/AnnotationAPIBridge.tsx b/frontend/editor/src/core/components/viewer/AnnotationAPIBridge.tsxindex e09647fda5..eb183fb5fe 100644--- a/frontend/editor/src/core/components/viewer/AnnotationAPIBridge.tsx+++ b/frontend/editor/src/core/components/viewer/AnnotationAPIBridge.tsx@@ -160,9 +160,9 @@ const DEFAULTS = {inkHighlighter: "#ffd54f",text: "#111111",note: "#ffd54f",- shapeFill: "#0000ff",- shapeStroke: "#cf5b5b",- shapeOpacity: 0.5,+ shapeFill: "transparent",+ shapeStroke: "#000000",+ shapeOpacity: 1,};const withCustomData = (options?: AnnotationToolOptions) =>@@ -280,9 +280,9 @@ const TOOL_DEFAULT_BUILDERS: Record<AnnotationToolId, ToolDefaultsBuilder> = {opacity: options?.opacity ?? DEFAULTS.shapeOpacity,fillOpacity: options?.fillOpacity ?? DEFAULTS.shapeOpacity,strokeOpacity: options?.strokeOpacity ?? DEFAULTS.shapeOpacity,- borderWidth: options?.borderWidth ?? 1,- strokeWidth: options?.borderWidth ?? 1,- lineWidth: options?.borderWidth ?? 1,+ borderWidth: options?.borderWidth ?? 8,+ strokeWidth: options?.borderWidth ?? 8,+ lineWidth: options?.borderWidth ?? 8,...withCustomData(options),}),circle: (options) => ({@@ -292,9 +292,9 @@ const TOOL_DEFAULT_BUILDERS: Record<AnnotationToolId, ToolDefaultsBuilder> = {opacity: options?.opacity ?? DEFAULTS.shapeOpacity,fillOpacity: options?.fillOpacity ?? DEFAULTS.shapeOpacity,strokeOpacity: options?.strokeOpacity ?? DEFAULTS.shapeOpacity,- borderWidth: options?.borderWidth ?? 1,- strokeWidth: options?.borderWidth ?? 1,- lineWidth: options?.borderWidth ?? 1,+ borderWidth: options?.borderWidth ?? 8,+ strokeWidth: options?.borderWidth ?? 8,+ lineWidth: options?.borderWidth ?? 8,...withCustomData(options),}),line: (options) => ({@@ -334,9 +334,9 @@ const TOOL_DEFAULT_BUILDERS: Record<AnnotationToolId, ToolDefaultsBuilder> = {opacity: options?.opacity ?? DEFAULTS.shapeOpacity,fillOpacity: options?.fillOpacity ?? DEFAULTS.shapeOpacity,strokeOpacity: options?.strokeOpacity ?? DEFAULTS.shapeOpacity,- borderWidth: options?.borderWidth ?? 1,- strokeWidth: options?.borderWidth ?? 1,- lineWidth: options?.borderWidth ?? 1,+ borderWidth: options?.borderWidth ?? 8,+ strokeWidth: options?.borderWidth ?? 8,+ lineWidth: options?.borderWidth ?? 8,...withCustomData(options),}),stamp: buildStampDefaults,diff --git a/frontend/editor/src/core/components/viewer/annotationTools.ts b/frontend/editor/src/core/components/viewer/annotationTools.tsindex 00674f2deb..c19628ad10 100644--- a/frontend/editor/src/core/components/viewer/annotationTools.ts+++ b/frontend/editor/src/core/components/viewer/annotationTools.ts@@ -178,12 +178,12 @@ export function registerAnnotationTools(annotation.type === PdfAnnotationSubtype.SQUARE ? 10 : 0,defaults: {type: PdfAnnotationSubtype.SQUARE,- color: "#0000ff", // fill color (blue)- strokeColor: "#cf5b5b", // border color (reddish pink)- opacity: 0.5,- borderWidth: 1,- strokeWidth: 1,- lineWidth: 1,+ color: "transparent", // fill color+ strokeColor: "#000000", // border color+ opacity: 1,+ borderWidth: 8,+ strokeWidth: 8,+ lineWidth: 8,},clickBehavior: {enabled: true,@@ -203,12 +203,12 @@ export function registerAnnotationTools(annotation.type === PdfAnnotationSubtype.CIRCLE ? 10 : 0,defaults: {type: PdfAnnotationSubtype.CIRCLE,- color: "#0000ff", // fill color (blue)- strokeColor: "#cf5b5b", // border color (reddish pink)- opacity: 0.5,- borderWidth: 1,- strokeWidth: 1,- lineWidth: 1,+ color: "transparent", // fill color+ strokeColor: "#000000", // border color+ opacity: 1,+ borderWidth: 8,+ strokeWidth: 8,+ lineWidth: 8,},clickBehavior: {enabled: true,@@ -311,10 +311,10 @@ export function registerAnnotationTools(annotation.type === PdfAnnotationSubtype.POLYGON ? 10 : 0,defaults: {type: PdfAnnotationSubtype.POLYGON,- color: "#0000ff", // fill color (blue)- strokeColor: "#cf5b5b", // border color (reddish pink)- opacity: 0.5,- borderWidth: 1,+ color: "transparent", // fill color+ strokeColor: "#000000", // border color+ opacity: 1,+ borderWidth: 8,},clickBehavior: {enabled: true,diff --git a/frontend/editor/src/core/components/viewer/useAnnotationMenuHandlers.ts b/frontend/editor/src/core/components/viewer/useAnnotationMenuHandlers.tsindex e4e5b450c2..e5dc841211 100644--- a/frontend/editor/src/core/components/viewer/useAnnotationMenuHandlers.ts+++ b/frontend/editor/src/core/components/viewer/useAnnotationMenuHandlers.ts@@ -199,7 +199,7 @@ export function useAnnotationMenuHandlers({return obj.color || obj.strokeColor || "#000000";})();const strokeColor = obj?.strokeColor || obj?.color || "#000000";- const fillColor = obj?.color || obj?.fillColor || "#0000ff";+ const fillColor = obj?.color || obj?.fillColor || "transparent";const backgroundColor =obj?.backgroundColor || obj?.fillColor || obj?.color || "#ffffff";const textColor = obj?.textColor || obj?.color || "#000000";@@ -248,7 +248,7 @@ export function useAnnotationMenuHandlers({if (target === "stroke") {patch.strokeColor = color;- patch.color = obj?.color || "#0000ff";+ patch.color = obj?.color || "transparent";patch.strokeWidth = currentWidth;} else if (target === "fill") {patch.color = color;diff --git a/frontend/editor/src/core/tools/annotate/AnnotationPanel.tsx b/frontend/editor/src/core/tools/annotate/AnnotationPanel.tsxindex 86d75a6b4e..606ccd5207 100644--- a/frontend/editor/src/core/tools/annotate/AnnotationPanel.tsx+++ b/frontend/editor/src/core/tools/annotate/AnnotationPanel.tsx@@ -592,7 +592,7 @@ export function AnnotationPanel(props: AnnotationPanelProps) {{t("annotation.opacity", "Opacity")}</Text><Slider- min={10}+ min={0}max={100}value={highlightOpacity}onChange={setHighlightOpacity}@@ -606,7 +606,7 @@ export function AnnotationPanel(props: AnnotationPanelProps) {{t("annotation.opacity", "Opacity")}</Text><Slider- min={10}+ min={0}max={100}value={underlineOpacity}onChange={setUnderlineOpacity}@@ -778,7 +778,7 @@ export function AnnotationPanel(props: AnnotationPanelProps) {{t("annotation.opacity", "Opacity")}</Text><Slider- min={10}+ min={0}max={100}value={shapeOpacity}onChange={(value) => {diff --git a/frontend/editor/src/core/tools/annotate/useAnnotationStyleState.ts b/frontend/editor/src/core/tools/annotate/useAnnotationStyleState.tsindex a0e1b1b469..700e24423b 100644--- a/frontend/editor/src/core/tools/annotate/useAnnotationStyleState.ts+++ b/frontend/editor/src/core/tools/annotate/useAnnotationStyleState.ts@@ -92,12 +92,12 @@ export const useAnnotationStyleState = (>("left");const [textBackgroundColor, setTextBackgroundColor] = useState<string>("");const [noteBackgroundColor, setNoteBackgroundColor] = useState("#ffd54f");- const [shapeStrokeColor, setShapeStrokeColor] = useState("#cf5b5b");- const [shapeFillColor, setShapeFillColor] = useState("#0000ff");- const [shapeOpacity, setShapeOpacity] = useState(50);- const [shapeStrokeOpacity, setShapeStrokeOpacity] = useState(50);- const [shapeFillOpacity, setShapeFillOpacity] = useState(50);- const [shapeThickness, setShapeThickness] = useState(2);+ const [shapeStrokeColor, setShapeStrokeColor] = useState("#000000");+ const [shapeFillColor, setShapeFillColor] = useState("transparent");+ const [shapeOpacity, setShapeOpacity] = useState(100);+ const [shapeStrokeOpacity, setShapeStrokeOpacity] = useState(100);+ const [shapeFillOpacity, setShapeFillOpacity] = useState(100);+ const [shapeThickness, setShapeThickness] = useState(8);const buildToolOptions = useCallback<BuildToolOptionsFn>((toolId, extras) => {