@widgetic/canvas 0.5.35 → 0.5.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +105 -36
- package/dist/canvas/DomCanvas.svelte +449 -0
- package/dist/canvas/DomCanvas.svelte.d.ts +221 -0
- package/dist/canvas/boardFrame.d.ts +13 -0
- package/dist/canvas/boardFrame.js +13 -0
- package/dist/canvas/boardSurface.d.ts +9 -0
- package/dist/canvas/boardSurface.js +9 -0
- package/dist/canvas/chromeLayout.d.ts +76 -0
- package/dist/canvas/chromeLayout.js +121 -0
- package/dist/canvas/emptyBoardHint.d.ts +17 -0
- package/dist/canvas/emptyBoardHint.js +12 -0
- package/dist/canvas/eventScope.d.ts +1 -1
- package/dist/canvas/eventScope.js +1 -1
- package/dist/canvas/host/CanvasHost.d.ts +348 -0
- package/dist/canvas/host/CanvasHost.js +1715 -0
- package/dist/canvas/host/CanvasHostApi.d.ts +30 -0
- package/dist/canvas/host/CanvasHostApi.js +95 -0
- package/dist/canvas/host/browserServices.d.ts +46 -0
- package/dist/canvas/host/browserServices.js +167 -0
- package/dist/canvas/host/conversion.d.ts +53 -0
- package/dist/canvas/host/conversion.js +125 -0
- package/dist/canvas/host/hostObject.d.ts +40 -0
- package/dist/canvas/host/hostObject.js +93 -0
- package/dist/canvas/host/pageEvents.d.ts +24 -0
- package/dist/canvas/host/pageEvents.js +35 -0
- package/dist/canvas/host/screenRects.d.ts +66 -0
- package/dist/canvas/host/screenRects.js +102 -0
- package/dist/canvas/host/strokeSnap.d.ts +67 -0
- package/dist/canvas/host/strokeSnap.js +165 -0
- package/dist/canvas/index.d.ts +7 -7
- package/dist/canvas/index.js +8 -8
- package/dist/canvas/openMarks.d.ts +17 -0
- package/dist/canvas/openMarks.js +26 -0
- package/dist/canvas/panZoomPosition.d.ts +15 -0
- package/dist/canvas/panZoomPosition.js +16 -0
- package/dist/canvas/preferredTextFont.d.ts +12 -0
- package/dist/canvas/preferredTextFont.js +38 -0
- package/dist/canvas/shapes/ShapeLibrary.d.ts +1 -1
- package/dist/canvas/shapes/ShapeLibrary.js +13 -1
- package/dist/canvas/shapes/strokeShapeSnap.d.ts +14 -12
- package/dist/canvas/shapes/strokeShapeSnap.js +10 -8
- package/dist/canvas/toolbarPosition.d.ts +11 -11
- package/dist/canvas/toolbarPosition.js +11 -24
- package/dist/canvas/types.d.ts +14 -0
- package/dist/canvas/ui/CanvasContextMenu.svelte +173 -0
- package/dist/canvas/ui/CanvasContextMenu.svelte.d.ts +12 -0
- package/dist/canvas/ui/CanvasHint.svelte +21 -0
- package/dist/canvas/ui/CanvasHint.svelte.d.ts +18 -0
- package/dist/canvas/ui/CanvasToolbar.svelte +95 -0
- package/dist/canvas/ui/CanvasToolbar.svelte.d.ts +14 -0
- package/dist/canvas/ui/ColorField.svelte +156 -0
- package/dist/canvas/ui/ColorField.svelte.d.ts +14 -0
- package/dist/canvas/ui/LoadNotice.svelte +39 -0
- package/dist/canvas/ui/LoadNotice.svelte.d.ts +8 -0
- package/dist/canvas/ui/SelectionPanel.svelte +300 -0
- package/dist/canvas/ui/SelectionPanel.svelte.d.ts +20 -0
- package/dist/canvas/ui/SelectorBar.svelte +82 -0
- package/dist/canvas/ui/SelectorBar.svelte.d.ts +12 -0
- package/dist/canvas/ui/ShapesMenu.svelte +185 -0
- package/dist/canvas/ui/ShapesMenu.svelte.d.ts +15 -0
- package/dist/canvas/ui/ShortcutsPanel.svelte +124 -0
- package/dist/canvas/ui/ShortcutsPanel.svelte.d.ts +7 -0
- package/dist/canvas/ui/ToolButton.svelte +78 -0
- package/dist/canvas/ui/ToolButton.svelte.d.ts +20 -0
- package/dist/canvas/ui/WidgetActions.svelte +145 -0
- package/dist/canvas/ui/WidgetActions.svelte.d.ts +19 -0
- package/dist/canvas/ui/ZoomControl.svelte +89 -0
- package/dist/canvas/ui/ZoomControl.svelte.d.ts +18 -0
- package/dist/canvas/ui/colorModel.d.ts +18 -0
- package/dist/canvas/ui/colorModel.js +85 -0
- package/dist/canvas/ui/colorPickerMessages.d.ts +5 -0
- package/dist/canvas/ui/colorPickerMessages.js +15 -0
- package/dist/canvas/ui/floatingCard.d.ts +107 -0
- package/dist/canvas/ui/floatingCard.js +107 -0
- package/dist/canvas/ui/floatingLayer.d.ts +21 -0
- package/dist/canvas/ui/floatingLayer.js +52 -0
- package/dist/canvas/ui/icons.d.ts +12 -0
- package/dist/canvas/ui/icons.js +7 -0
- package/dist/canvas/ui/keyHints.d.ts +27 -0
- package/dist/canvas/ui/keyHints.js +43 -0
- package/dist/canvas/ui/popoverSide.d.ts +5 -0
- package/dist/canvas/ui/popoverSide.js +20 -0
- package/dist/canvas/ui/selectionTraits.d.ts +61 -0
- package/dist/canvas/ui/selectionTraits.js +99 -0
- package/dist/canvas/view/CanvasStage.svelte +132 -0
- package/dist/canvas/view/CanvasStage.svelte.d.ts +21 -0
- package/dist/canvas/view/EraserTrail.svelte +50 -0
- package/dist/canvas/view/EraserTrail.svelte.d.ts +9 -0
- package/dist/canvas/view/ObjectView.svelte +245 -0
- package/dist/canvas/view/ObjectView.svelte.d.ts +21 -0
- package/dist/canvas/view/SelectionOverlay.svelte +487 -0
- package/dist/canvas/view/SelectionOverlay.svelte.d.ts +17 -0
- package/dist/canvas/view/TextEditor.svelte +76 -0
- package/dist/canvas/view/TextEditor.svelte.d.ts +9 -0
- package/dist/canvas/view/WidgetChromeLayer.svelte +83 -0
- package/dist/canvas/view/WidgetChromeLayer.svelte.d.ts +13 -0
- package/dist/canvas/view/erasingMarks.d.ts +13 -0
- package/dist/canvas/view/erasingMarks.js +34 -0
- package/dist/canvas/view/geometry.d.ts +169 -0
- package/dist/canvas/view/geometry.js +272 -0
- package/dist/components/CanvasBoardPlaceholder.svelte +5 -3
- package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +3 -3
- package/dist/components/index.js +1 -1
- package/dist/components/input-controls/ColorIC.svelte +2 -2
- package/dist/engine/EngineCore.d.ts +273 -0
- package/dist/engine/EngineCore.js +1051 -0
- package/dist/engine/codec/canvasDocument.d.ts +57 -0
- package/dist/engine/codec/canvasDocument.js +471 -0
- package/dist/engine/codec/hostReadableKeys.d.ts +25 -0
- package/dist/engine/codec/hostReadableKeys.js +25 -0
- package/dist/engine/core/arrange.d.ts +20 -0
- package/dist/engine/core/arrange.js +81 -0
- package/dist/engine/core/arrow.d.ts +91 -0
- package/dist/engine/core/arrow.js +182 -0
- package/dist/engine/core/brush.d.ts +68 -0
- package/dist/engine/core/brush.js +173 -0
- package/dist/engine/core/defaults.d.ts +70 -0
- package/dist/engine/core/defaults.js +158 -0
- package/dist/engine/core/freehand.d.ts +130 -0
- package/dist/engine/core/freehand.js +430 -0
- package/dist/engine/core/geometry.d.ts +44 -0
- package/dist/engine/core/geometry.js +216 -0
- package/dist/engine/core/history.d.ts +39 -0
- package/dist/engine/core/history.js +69 -0
- package/dist/engine/core/hitTest.d.ts +54 -0
- package/dist/engine/core/hitTest.js +298 -0
- package/dist/engine/core/matrix.d.ts +47 -0
- package/dist/engine/core/matrix.js +101 -0
- package/dist/engine/core/pathData.d.ts +50 -0
- package/dist/engine/core/pathData.js +550 -0
- package/dist/engine/core/rotationReset.d.ts +10 -0
- package/dist/engine/core/rotationReset.js +17 -0
- package/dist/engine/core/scene.d.ts +99 -0
- package/dist/engine/core/scene.js +450 -0
- package/dist/engine/core/scribble.d.ts +64 -0
- package/dist/engine/core/scribble.js +121 -0
- package/dist/engine/core/shapePaths.d.ts +34 -0
- package/dist/engine/core/shapePaths.js +69 -0
- package/dist/engine/core/shapeTools.d.ts +80 -0
- package/dist/engine/core/shapeTools.js +161 -0
- package/dist/engine/core/snapping.d.ts +64 -0
- package/dist/engine/core/snapping.js +164 -0
- package/dist/engine/core/style.d.ts +40 -0
- package/dist/engine/core/style.js +151 -0
- package/dist/engine/core/transform.d.ts +79 -0
- package/dist/engine/core/transform.js +258 -0
- package/dist/engine/core/types.d.ts +238 -0
- package/dist/engine/core/types.js +31 -0
- package/dist/engine/core/viewport.d.ts +32 -0
- package/dist/engine/core/viewport.js +84 -0
- package/dist/engine/input/PointerController.d.ts +38 -0
- package/dist/engine/input/PointerController.js +545 -0
- package/dist/engine/input/arrowHandles.d.ts +38 -0
- package/dist/engine/input/arrowHandles.js +60 -0
- package/dist/engine/input/gestures.d.ts +79 -0
- package/dist/engine/input/gestures.js +769 -0
- package/dist/engine/input/hoverCursor.d.ts +29 -0
- package/dist/engine/input/hoverCursor.js +23 -0
- package/dist/engine/input/keyboard.d.ts +75 -0
- package/dist/engine/input/keyboard.js +264 -0
- package/dist/engine/input/selectionHandles.d.ts +89 -0
- package/dist/engine/input/selectionHandles.js +169 -0
- package/dist/engine/input/types.d.ts +82 -0
- package/dist/engine/input/types.js +5 -0
- package/dist/engine/render/rasterize.d.ts +74 -0
- package/dist/engine/render/rasterize.js +273 -0
- package/dist/engine/state.d.ts +124 -0
- package/dist/engine/state.js +47 -0
- package/dist/engine/text/layoutText.d.ts +53 -0
- package/dist/engine/text/layoutText.js +170 -0
- package/dist/engine/widgets.d.ts +124 -0
- package/dist/engine/widgets.js +345 -0
- package/dist/i18n/labels.d.ts +4 -15
- package/dist/i18n/labels.js +33 -53
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +52 -124
- package/dist/i18n/messages.js +59 -133
- package/dist/i18n/shortcuts.d.ts +0 -1
- package/dist/i18n/shortcuts.js +2 -11
- package/dist/index.d.ts +4 -2
- package/dist/index.js +5 -3
- package/package.json +30 -5
- package/dist/canvas/Canvas.svelte +0 -13363
- package/dist/canvas/Canvas.svelte.d.ts +0 -286
- package/dist/canvas/CanvasToolbar.svelte +0 -1498
- package/dist/canvas/CanvasToolbar.svelte.d.ts +0 -69
- package/dist/canvas/ContextMenu.svelte +0 -305
- package/dist/canvas/ContextMenu.svelte.d.ts +0 -42
- package/dist/canvas/PanZoomPanel.svelte +0 -478
- package/dist/canvas/PanZoomPanel.svelte.d.ts +0 -38
- package/dist/canvas/WidgetSelectionLayer.svelte +0 -156
- package/dist/canvas/WidgetSelectionLayer.svelte.d.ts +0 -11
- package/dist/canvas/props-panel/PropsPanel.svelte +0 -2075
- package/dist/canvas/props-panel/PropsPanel.svelte.d.ts +0 -84
- package/dist/canvas/props-panel/TextPropsICSection.svelte +0 -242
- package/dist/canvas/props-panel/TextPropsICSection.svelte.d.ts +0 -40
- package/dist/canvas/shadowRootText.d.ts +0 -5
- package/dist/canvas/shadowRootText.js +0 -43
- package/dist/canvas/shapes/FrameShape.d.ts +0 -97
- package/dist/canvas/shapes/FrameShape.js +0 -953
- package/dist/canvas/shapes/ImageShape.d.ts +0 -47
- package/dist/canvas/shapes/ImageShape.js +0 -339
- package/dist/canvas/shapes/WidgetShape.d.ts +0 -30
- package/dist/canvas/shapes/WidgetShape.js +0 -200
- package/dist/canvas/widgetPreviewGeometry.d.ts +0 -19
- package/dist/canvas/widgetPreviewGeometry.js +0 -66
- package/dist/i18n/shapeWords.d.ts +0 -30
- package/dist/i18n/shapeWords.js +0 -36
- package/dist/i18n/slots.d.ts +0 -20
- package/dist/i18n/slots.js +0 -40
|
@@ -1,478 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
// Pan Zoom Panel - Canvas navigation and view controls
|
|
3
|
-
import Tooltip from '../components/Tooltip.svelte';
|
|
4
|
-
import { useCanvasLanguage } from '../i18n/language.js';
|
|
5
|
-
|
|
6
|
-
// The words of the panel, in the language of the canvas it is on (English when it is used on its own)
|
|
7
|
-
const { t } = useCanvasLanguage();
|
|
8
|
-
|
|
9
|
-
let className = '';
|
|
10
|
-
export { className as class };
|
|
11
|
-
export let style = '';
|
|
12
|
-
|
|
13
|
-
// Current zoom level (percentage)
|
|
14
|
-
export let zoomLevel: number = 100;
|
|
15
|
-
|
|
16
|
-
// Is pan tool active
|
|
17
|
-
export let isPanActive: boolean = false;
|
|
18
|
-
|
|
19
|
-
// Is grid visible
|
|
20
|
-
export let showGrid: boolean = false;
|
|
21
|
-
|
|
22
|
-
// Callbacks
|
|
23
|
-
export let onPanToggle: () => void = () => {};
|
|
24
|
-
export let onZoomIn: () => void = () => {};
|
|
25
|
-
export let onZoomOut: () => void = () => {};
|
|
26
|
-
export let onZoomReset: () => void = () => {};
|
|
27
|
-
export let onZoomFit: () => void = () => {};
|
|
28
|
-
export let onZoomChange: (percent: number) => void = () => {};
|
|
29
|
-
export let onGridToggle: () => void = () => {};
|
|
30
|
-
export let onShortcutsToggle: () => void = () => {};
|
|
31
|
-
// Reflects open state so the button can show an active style
|
|
32
|
-
export let shortcutsOpen: boolean = false;
|
|
33
|
-
|
|
34
|
-
/** Extra view controls (grid, pan, 1:1, fit, shortcuts). Zoom ± / % and save stay available. */
|
|
35
|
-
export let advancedFeatures: boolean = false;
|
|
36
|
-
/** The percent pill and the zoom tools. The save control stays when this is off. */
|
|
37
|
-
export let showZoomControls: boolean = true;
|
|
38
|
-
|
|
39
|
-
// Save button: visible when showSaveButton is true
|
|
40
|
-
export let showSaveButton: boolean = false;
|
|
41
|
-
export let hasUnsavedChanges: boolean = false;
|
|
42
|
-
export let onSave: (() => void) | null = null;
|
|
43
|
-
|
|
44
|
-
// Editable zoom input
|
|
45
|
-
let zoomInputValue = zoomLevel.toString();
|
|
46
|
-
$: zoomInputValue = zoomLevel.toString();
|
|
47
|
-
|
|
48
|
-
function handleZoomInputChange(e: Event) {
|
|
49
|
-
const input = e.target as HTMLInputElement;
|
|
50
|
-
zoomInputValue = input.value;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function handleZoomInputBlur() {
|
|
54
|
-
const value = parseInt(zoomInputValue);
|
|
55
|
-
if (!isNaN(value) && value >= 10 && value <= 500) {
|
|
56
|
-
onZoomChange(value);
|
|
57
|
-
} else {
|
|
58
|
-
zoomInputValue = zoomLevel.toString();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function handleZoomInputKeydown(e: KeyboardEvent) {
|
|
63
|
-
if (e.key === 'Enter') {
|
|
64
|
-
handleZoomInputBlur();
|
|
65
|
-
(e.target as HTMLInputElement).blur();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
let isMinimized = true;
|
|
70
|
-
|
|
71
|
-
function toggleMinimized() {
|
|
72
|
-
isMinimized = !isMinimized;
|
|
73
|
-
// console.log('[PanZoomPanel] minimized:', isMinimized);
|
|
74
|
-
}
|
|
75
|
-
</script>
|
|
76
|
-
|
|
77
|
-
<div class="pan-zoom-panel-ct {className ? className + ' ' : ''}pan-zoom-panel {isMinimized || !showZoomControls ? 'pan-zoom-panel-minimized' : ''}" style={style}>
|
|
78
|
-
{#if showSaveButton}
|
|
79
|
-
<Tooltip text={$t(hasUnsavedChanges ? 'canvas.zoom.unsavedTitle' : 'canvas.zoom.savedTitle')} position="above">
|
|
80
|
-
<button
|
|
81
|
-
type="button"
|
|
82
|
-
class="panel-btn save-btn {hasUnsavedChanges ? 'save-btn--dirty' : ''}"
|
|
83
|
-
onclick={() => onSave?.()}
|
|
84
|
-
aria-label={$t(hasUnsavedChanges ? 'canvas.zoom.unsavedTitle' : 'canvas.zoom.savedTitle')}
|
|
85
|
-
>
|
|
86
|
-
{#if hasUnsavedChanges}
|
|
87
|
-
<span class="save-dirty-dot">●</span>
|
|
88
|
-
{:else}
|
|
89
|
-
<svg width="14" height="14" viewBox="0 0 14 14" fill="none">
|
|
90
|
-
<path d="M2 2h8l2 2v8a1 1 0 01-1 1H3a1 1 0 01-1-1V2z" stroke="currentColor" stroke-width="1.3"/>
|
|
91
|
-
<rect x="4.5" y="2" width="3" height="3.5" rx="0.5" stroke="currentColor" stroke-width="1.2"/>
|
|
92
|
-
<rect x="3" y="7.5" width="8" height="4" rx="0.5" stroke="currentColor" stroke-width="1.2"/>
|
|
93
|
-
</svg>
|
|
94
|
-
{/if}
|
|
95
|
-
</button>
|
|
96
|
-
</Tooltip>
|
|
97
|
-
{#if isPanActive}
|
|
98
|
-
<span class="canvas-pan-banner pointer-events-none ms-2 inline-flex items-center rounded-md bg-[#1f2937] px-2 py-1 text-[11px] font-medium text-white shadow-sm">{$t('canvas.zoom.panBanner')}</span>
|
|
99
|
-
{/if}
|
|
100
|
-
{/if}
|
|
101
|
-
{#if showZoomControls}
|
|
102
|
-
{#if isMinimized}
|
|
103
|
-
<Tooltip text={$t('canvas.zoom.expandTitle', { percent: String(zoomLevel) })} position="above">
|
|
104
|
-
<button
|
|
105
|
-
type="button"
|
|
106
|
-
class="panel-btn pan-zoom-expand-btn"
|
|
107
|
-
onclick={toggleMinimized}
|
|
108
|
-
aria-label={$t('canvas.zoom.expandLabel')}
|
|
109
|
-
>
|
|
110
|
-
<span class="text-btn">{zoomLevel}%</span>
|
|
111
|
-
</button>
|
|
112
|
-
</Tooltip>
|
|
113
|
-
{:else}
|
|
114
|
-
{#if advancedFeatures}
|
|
115
|
-
<!-- Grid Toggle -->
|
|
116
|
-
<Tooltip text={$t('canvas.zoom.gridTitle')} position="above">
|
|
117
|
-
<button
|
|
118
|
-
class="panel-btn grid-btn {showGrid ? 'active' : ''}"
|
|
119
|
-
onclick={onGridToggle}
|
|
120
|
-
aria-label={$t('canvas.zoom.gridLabel')}
|
|
121
|
-
>
|
|
122
|
-
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
123
|
-
<rect x="3" y="3" width="7" height="7"/>
|
|
124
|
-
<rect x="14" y="3" width="7" height="7"/>
|
|
125
|
-
<rect x="14" y="14" width="7" height="7"/>
|
|
126
|
-
<rect x="3" y="14" width="7" height="7"/>
|
|
127
|
-
</svg>
|
|
128
|
-
</button>
|
|
129
|
-
</Tooltip>
|
|
130
|
-
|
|
131
|
-
<div class="divider"></div>
|
|
132
|
-
|
|
133
|
-
<!-- Pan Tool -->
|
|
134
|
-
<Tooltip text={$t('canvas.zoom.panTitle')} position="above">
|
|
135
|
-
<button
|
|
136
|
-
class="panel-btn pan-btn {isPanActive ? 'active' : ''}"
|
|
137
|
-
onclick={onPanToggle}
|
|
138
|
-
aria-label={$t('canvas.zoom.panLabel')}
|
|
139
|
-
>
|
|
140
|
-
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
141
|
-
<path d="M18 11V6a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v0"/>
|
|
142
|
-
<path d="M14 10V4a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v2"/>
|
|
143
|
-
<path d="M10 10.5V6a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v8"/>
|
|
144
|
-
<path d="M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15"/>
|
|
145
|
-
</svg>
|
|
146
|
-
</button>
|
|
147
|
-
</Tooltip>
|
|
148
|
-
|
|
149
|
-
<div class="divider"></div>
|
|
150
|
-
{/if}
|
|
151
|
-
|
|
152
|
-
<!-- Zoom Out -->
|
|
153
|
-
<Tooltip text={$t('canvas.zoom.outTitle')} position="above">
|
|
154
|
-
<button
|
|
155
|
-
class="panel-btn"
|
|
156
|
-
onclick={onZoomOut}
|
|
157
|
-
disabled={zoomLevel <= 10}
|
|
158
|
-
aria-label={$t('canvas.zoom.outLabel')}
|
|
159
|
-
>
|
|
160
|
-
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
161
|
-
<circle cx="11" cy="11" r="8"/>
|
|
162
|
-
<line x1="21" y1="21" x2="16.65" y2="16.65"/>
|
|
163
|
-
<line x1="8" y1="11" x2="14" y2="11"/>
|
|
164
|
-
</svg>
|
|
165
|
-
</button>
|
|
166
|
-
</Tooltip>
|
|
167
|
-
|
|
168
|
-
<!-- Zoom Level Input -->
|
|
169
|
-
<div class="zoom-level">
|
|
170
|
-
<Tooltip text={$t('canvas.zoom.resetTitle')} position="above">
|
|
171
|
-
<button
|
|
172
|
-
type="button"
|
|
173
|
-
class="zoom-reset-in-input"
|
|
174
|
-
onclick={onZoomReset}
|
|
175
|
-
aria-label={$t('canvas.zoom.resetLabel')}
|
|
176
|
-
>
|
|
177
|
-
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
|
178
|
-
<polyline points="1 4 1 10 7 10"/>
|
|
179
|
-
<path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10"/>
|
|
180
|
-
</svg>
|
|
181
|
-
</button>
|
|
182
|
-
</Tooltip>
|
|
183
|
-
<input
|
|
184
|
-
type="text"
|
|
185
|
-
class="zoom-input"
|
|
186
|
-
value={zoomInputValue}
|
|
187
|
-
oninput={handleZoomInputChange}
|
|
188
|
-
onblur={handleZoomInputBlur}
|
|
189
|
-
onkeydown={handleZoomInputKeydown}
|
|
190
|
-
maxlength="3"
|
|
191
|
-
aria-label={$t('canvas.zoom.levelLabel')}
|
|
192
|
-
/>
|
|
193
|
-
<span class="zoom-unit">%</span>
|
|
194
|
-
</div>
|
|
195
|
-
|
|
196
|
-
<!-- Zoom In -->
|
|
197
|
-
<Tooltip text={$t('canvas.zoom.inTitle')} position="above">
|
|
198
|
-
<button
|
|
199
|
-
class="panel-btn"
|
|
200
|
-
onclick={onZoomIn}
|
|
201
|
-
disabled={zoomLevel >= 500}
|
|
202
|
-
aria-label={$t('canvas.zoom.inLabel')}
|
|
203
|
-
>
|
|
204
|
-
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
205
|
-
<circle cx="11" cy="11" r="8"/>
|
|
206
|
-
<line x1="21" y1="21" x2="16.65" y2="16.65"/>
|
|
207
|
-
<line x1="11" y1="8" x2="11" y2="14"/>
|
|
208
|
-
<line x1="8" y1="11" x2="14" y2="11"/>
|
|
209
|
-
</svg>
|
|
210
|
-
</button>
|
|
211
|
-
</Tooltip>
|
|
212
|
-
|
|
213
|
-
{#if advancedFeatures}
|
|
214
|
-
<div class="divider"></div>
|
|
215
|
-
|
|
216
|
-
<!-- Reset Zoom (100%) -->
|
|
217
|
-
<Tooltip text={$t('canvas.zoom.oneToOneTitle')} position="above">
|
|
218
|
-
<button
|
|
219
|
-
class="panel-btn"
|
|
220
|
-
onclick={onZoomReset}
|
|
221
|
-
aria-label={$t('canvas.zoom.resetLabel')}
|
|
222
|
-
>
|
|
223
|
-
<span class="text-btn">1:1</span>
|
|
224
|
-
</button>
|
|
225
|
-
</Tooltip>
|
|
226
|
-
|
|
227
|
-
<!-- Fit to View -->
|
|
228
|
-
<Tooltip text={$t('canvas.zoom.fitTitle')} position="above">
|
|
229
|
-
<button
|
|
230
|
-
class="panel-btn"
|
|
231
|
-
onclick={onZoomFit}
|
|
232
|
-
aria-label={$t('canvas.zoom.fitLabel')}
|
|
233
|
-
>
|
|
234
|
-
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
235
|
-
<path d="M8 3H5a2 2 0 0 0-2 2v3"/>
|
|
236
|
-
<path d="M21 8V5a2 2 0 0 0-2-2h-3"/>
|
|
237
|
-
<path d="M3 16v3a2 2 0 0 0 2 2h3"/>
|
|
238
|
-
<path d="M16 21h3a2 2 0 0 0 2-2v-3"/>
|
|
239
|
-
</svg>
|
|
240
|
-
</button>
|
|
241
|
-
</Tooltip>
|
|
242
|
-
|
|
243
|
-
<div class="divider"></div>
|
|
244
|
-
|
|
245
|
-
<!-- Keyboard Shortcuts — moved here from toolbar so it lives with view controls, not drawing tools -->
|
|
246
|
-
<Tooltip text={$t('canvas.zoom.shortcutsTitle')} position="above">
|
|
247
|
-
<button
|
|
248
|
-
class="panel-btn shortcuts-btn {shortcutsOpen ? 'active' : ''}"
|
|
249
|
-
onclick={onShortcutsToggle}
|
|
250
|
-
aria-label={$t('canvas.zoom.shortcutsLabel')}
|
|
251
|
-
>
|
|
252
|
-
<!-- Keyboard icon — larger so it's clearly readable -->
|
|
253
|
-
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
|
|
254
|
-
<rect x="2" y="6" width="20" height="13" rx="2"/>
|
|
255
|
-
<path d="M6 10h.01M10 10h.01M14 10h.01M18 10h.01M8 14h8M6 14h.01M18 14h.01"/>
|
|
256
|
-
</svg>
|
|
257
|
-
</button>
|
|
258
|
-
</Tooltip>
|
|
259
|
-
{/if}
|
|
260
|
-
|
|
261
|
-
<div class="pan-zoom-minimize-anchor">
|
|
262
|
-
<Tooltip text={$t('canvas.zoom.minimize')} position="above">
|
|
263
|
-
<button
|
|
264
|
-
type="button"
|
|
265
|
-
class="pan-zoom-minimize-btn"
|
|
266
|
-
onclick={toggleMinimized}
|
|
267
|
-
aria-label={$t('canvas.zoom.minimize')}
|
|
268
|
-
>
|
|
269
|
-
<svg width="8" height="8" viewBox="0 0 12 12" fill="none" aria-hidden="true">
|
|
270
|
-
<rect x="2" y="5.25" width="8" height="1.5" rx="0.25" fill="currentColor"/>
|
|
271
|
-
</svg>
|
|
272
|
-
</button>
|
|
273
|
-
</Tooltip>
|
|
274
|
-
</div>
|
|
275
|
-
{/if}
|
|
276
|
-
{/if}
|
|
277
|
-
</div>
|
|
278
|
-
|
|
279
|
-
<style>
|
|
280
|
-
.pan-zoom-panel {
|
|
281
|
-
position: relative;
|
|
282
|
-
display: flex;
|
|
283
|
-
align-items: center;
|
|
284
|
-
gap: 4px;
|
|
285
|
-
width: max-content;
|
|
286
|
-
max-width: 100%;
|
|
287
|
-
padding: 6px 10px;
|
|
288
|
-
background: white;
|
|
289
|
-
border: 2px solid #e5e7eb;
|
|
290
|
-
border-radius: 8px;
|
|
291
|
-
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
|
292
|
-
overflow: visible;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
.pan-zoom-minimize-anchor {
|
|
296
|
-
position: absolute;
|
|
297
|
-
top: -8px;
|
|
298
|
-
inset-inline-end: -8px;
|
|
299
|
-
z-index: 2;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
.pan-zoom-minimize-btn {
|
|
303
|
-
display: flex;
|
|
304
|
-
align-items: center;
|
|
305
|
-
justify-content: center;
|
|
306
|
-
width: 14px;
|
|
307
|
-
height: 14px;
|
|
308
|
-
padding: 0;
|
|
309
|
-
border-radius: 9999px;
|
|
310
|
-
background: #ffffff;
|
|
311
|
-
border: 1px solid #9ca3af;
|
|
312
|
-
color: #9ca3af;
|
|
313
|
-
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
|
|
314
|
-
cursor: pointer;
|
|
315
|
-
transition: color 0.15s ease, border-color 0.15s ease;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
.pan-zoom-minimize-btn:hover:not(:disabled) {
|
|
319
|
-
background: #ffffff;
|
|
320
|
-
border-color: #111827;
|
|
321
|
-
color: #111827;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
.pan-zoom-panel-minimized {
|
|
325
|
-
padding: 4px;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
.pan-zoom-expand-btn {
|
|
329
|
-
min-width: 44px;
|
|
330
|
-
width: auto;
|
|
331
|
-
padding: 0 8px;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
.panel-btn {
|
|
335
|
-
display: flex;
|
|
336
|
-
align-items: center;
|
|
337
|
-
justify-content: center;
|
|
338
|
-
width: 32px;
|
|
339
|
-
height: 32px;
|
|
340
|
-
padding: 0;
|
|
341
|
-
border: 1px solid transparent;
|
|
342
|
-
border-radius: 6px;
|
|
343
|
-
background: transparent;
|
|
344
|
-
color: #6b7280;
|
|
345
|
-
cursor: pointer;
|
|
346
|
-
transition: all 0.15s ease;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
.panel-btn:hover:not(:disabled) {
|
|
350
|
-
background: #f3f4f6;
|
|
351
|
-
color: #374151;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
.panel-btn:active:not(:disabled) {
|
|
355
|
-
background: #e5e7eb;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
.panel-btn.active {
|
|
359
|
-
background: var(--main-color, #314F2F);
|
|
360
|
-
color: white !important;
|
|
361
|
-
border-color: var(--main-color, #314F2F);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/* Host apps (widget-creator / site) may set a global svg color; force icons to follow the button. */
|
|
365
|
-
.panel-btn.active :global(svg),
|
|
366
|
-
.panel-btn.active :global(svg *) {
|
|
367
|
-
color: white !important;
|
|
368
|
-
stroke: currentColor !important;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
.panel-btn.active:hover {
|
|
372
|
-
background: var(--main-color-hover, #263d24);
|
|
373
|
-
color: white !important;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
.panel-btn.active:hover :global(svg),
|
|
377
|
-
.panel-btn.active:hover :global(svg *) {
|
|
378
|
-
color: white !important;
|
|
379
|
-
stroke: currentColor !important;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
.panel-btn:disabled {
|
|
383
|
-
opacity: 0.4;
|
|
384
|
-
cursor: not-allowed;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
.pan-zoom-panel button:focus,
|
|
388
|
-
.pan-zoom-panel button:focus-visible,
|
|
389
|
-
.pan-zoom-panel input:focus,
|
|
390
|
-
.pan-zoom-panel input:focus-visible {
|
|
391
|
-
outline: none;
|
|
392
|
-
box-shadow: none;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
/* Keyboard shortcuts button — slightly bigger to ensure the icon is clearly readable */
|
|
396
|
-
.shortcuts-btn {
|
|
397
|
-
width: 36px;
|
|
398
|
-
height: 36px;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
.text-btn {
|
|
402
|
-
font-size: 11px;
|
|
403
|
-
font-weight: 600;
|
|
404
|
-
letter-spacing: -0.5px;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
.divider {
|
|
408
|
-
width: 1px;
|
|
409
|
-
height: 24px;
|
|
410
|
-
background: #e5e7eb;
|
|
411
|
-
margin: 0 4px;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
.zoom-level {
|
|
415
|
-
display: flex;
|
|
416
|
-
align-items: center;
|
|
417
|
-
border: 1px solid #e5e7eb;
|
|
418
|
-
border-radius: 4px;
|
|
419
|
-
overflow: hidden;
|
|
420
|
-
background: #f9fafb;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
.zoom-reset-in-input {
|
|
424
|
-
display: flex;
|
|
425
|
-
align-items: center;
|
|
426
|
-
justify-content: center;
|
|
427
|
-
width: 18px;
|
|
428
|
-
height: 24px;
|
|
429
|
-
padding: 0;
|
|
430
|
-
margin: 0;
|
|
431
|
-
margin-inline-start: 2px;
|
|
432
|
-
border: none;
|
|
433
|
-
background: transparent;
|
|
434
|
-
color: #6b7280;
|
|
435
|
-
cursor: pointer;
|
|
436
|
-
flex-shrink: 0;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
.zoom-reset-in-input:hover {
|
|
440
|
-
color: #111827;
|
|
441
|
-
background: #f3f4f6;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
.zoom-input {
|
|
445
|
-
width: 28px;
|
|
446
|
-
padding: 4px 0;
|
|
447
|
-
border: none;
|
|
448
|
-
background: transparent;
|
|
449
|
-
font-size: 12px;
|
|
450
|
-
font-weight: 500;
|
|
451
|
-
text-align: center;
|
|
452
|
-
outline: none;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
.zoom-input:focus {
|
|
456
|
-
background: white;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
.zoom-unit {
|
|
460
|
-
width: 18px;
|
|
461
|
-
padding: 4px 0;
|
|
462
|
-
margin: 0;
|
|
463
|
-
margin-inline-end: 2px;
|
|
464
|
-
font-size: 11px;
|
|
465
|
-
color: #6b7280;
|
|
466
|
-
text-align: center;
|
|
467
|
-
flex-shrink: 0;
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
.save-btn--dirty {
|
|
471
|
-
color: #ef4444 !important;
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
.save-dirty-dot {
|
|
475
|
-
font-size: 16px;
|
|
476
|
-
line-height: 1;
|
|
477
|
-
}
|
|
478
|
-
</style>
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
2
|
-
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
3
|
-
$$bindings?: Bindings;
|
|
4
|
-
} & Exports;
|
|
5
|
-
(internal: unknown, props: Props & {
|
|
6
|
-
$$events?: Events;
|
|
7
|
-
$$slots?: Slots;
|
|
8
|
-
}): Exports & {
|
|
9
|
-
$set?: any;
|
|
10
|
-
$on?: any;
|
|
11
|
-
};
|
|
12
|
-
z_$$bindings?: Bindings;
|
|
13
|
-
}
|
|
14
|
-
declare const PanZoomPanel: $$__sveltets_2_IsomorphicComponent<{
|
|
15
|
-
class?: string;
|
|
16
|
-
style?: string;
|
|
17
|
-
zoomLevel?: number;
|
|
18
|
-
isPanActive?: boolean;
|
|
19
|
-
showGrid?: boolean;
|
|
20
|
-
onPanToggle?: () => void;
|
|
21
|
-
onZoomIn?: () => void;
|
|
22
|
-
onZoomOut?: () => void;
|
|
23
|
-
onZoomReset?: () => void;
|
|
24
|
-
onZoomFit?: () => void;
|
|
25
|
-
onZoomChange?: (percent: number) => void;
|
|
26
|
-
onGridToggle?: () => void;
|
|
27
|
-
onShortcutsToggle?: () => void;
|
|
28
|
-
shortcutsOpen?: boolean;
|
|
29
|
-
/** Extra view controls (grid, pan, 1:1, fit, shortcuts). Zoom ± / % and save stay available. */ advancedFeatures?: boolean;
|
|
30
|
-
/** The percent pill and the zoom tools. The save control stays when this is off. */ showZoomControls?: boolean;
|
|
31
|
-
showSaveButton?: boolean;
|
|
32
|
-
hasUnsavedChanges?: boolean;
|
|
33
|
-
onSave?: (() => void) | null;
|
|
34
|
-
}, {
|
|
35
|
-
[evt: string]: CustomEvent<any>;
|
|
36
|
-
}, {}, {}, string>;
|
|
37
|
-
type PanZoomPanel = InstanceType<typeof PanZoomPanel>;
|
|
38
|
-
export default PanZoomPanel;
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { onMount } from 'svelte';
|
|
3
|
-
import type { Canvas } from 'fabric';
|
|
4
|
-
import { Portal } from '@widgetic/design-system';
|
|
5
|
-
import { canvasWarn } from './canvasLogger';
|
|
6
|
-
|
|
7
|
-
let { fabricCanvas, target, advancedFeatures = true, class: className = '', style = '' }: { fabricCanvas: Canvas; target: string; advancedFeatures?: boolean; class?: string; style?: string } = $props();
|
|
8
|
-
let drawingCanvas: HTMLCanvasElement | null = null;
|
|
9
|
-
function captureDrawingCanvas(node: HTMLCanvasElement) {
|
|
10
|
-
drawingCanvas = node;
|
|
11
|
-
return { destroy() { drawingCanvas = null; } };
|
|
12
|
-
}
|
|
13
|
-
let controls: { key: string; points: string; cursor: string }[] = $state([]);
|
|
14
|
-
let viewport = $state({ left: 0, top: 0, width: 0, height: 0 });
|
|
15
|
-
let activePointer: number | null = null;
|
|
16
|
-
let lastPointerEvent: PointerEvent | null = null;
|
|
17
|
-
|
|
18
|
-
// Route only control gestures through Fabric's existing DOM event handlers.
|
|
19
|
-
// Pointer capture prevents neighboring iframes from stealing the gesture.
|
|
20
|
-
function routeMouseEvent(type: 'mousedown' | 'mousemove' | 'mouseup', event: PointerEvent) {
|
|
21
|
-
fabricCanvas.upperCanvasEl.dispatchEvent(new MouseEvent(type, {
|
|
22
|
-
bubbles: true, cancelable: true, clientX: event.clientX, clientY: event.clientY,
|
|
23
|
-
button: 0, buttons: type === 'mouseup' ? 0 : 1,
|
|
24
|
-
shiftKey: event.shiftKey, altKey: event.altKey,
|
|
25
|
-
ctrlKey: event.ctrlKey, metaKey: event.metaKey,
|
|
26
|
-
}));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function startControl(event: PointerEvent) {
|
|
30
|
-
if (event.button !== 0 || activePointer !== null) return;
|
|
31
|
-
event.preventDefault();
|
|
32
|
-
event.stopPropagation();
|
|
33
|
-
try {
|
|
34
|
-
(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId);
|
|
35
|
-
activePointer = event.pointerId;
|
|
36
|
-
lastPointerEvent = event;
|
|
37
|
-
routeMouseEvent('mousedown', event);
|
|
38
|
-
} catch (error) {
|
|
39
|
-
activePointer = null;
|
|
40
|
-
canvasWarn('Canvas: could not start widget control gesture', error);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function moveControl(event: PointerEvent) {
|
|
45
|
-
if (activePointer !== event.pointerId) return;
|
|
46
|
-
lastPointerEvent = event;
|
|
47
|
-
routeMouseEvent('mousemove', event);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function finishControl(event: PointerEvent) {
|
|
51
|
-
if (activePointer !== event.pointerId) return;
|
|
52
|
-
activePointer = null;
|
|
53
|
-
routeMouseEvent('mouseup', event);
|
|
54
|
-
const target = event.currentTarget as HTMLElement | null;
|
|
55
|
-
if (target?.hasPointerCapture?.(event.pointerId)) {
|
|
56
|
-
target.releasePointerCapture(event.pointerId);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function redraw() {
|
|
61
|
-
if (!drawingCanvas || fabricCanvas.disposed) return;
|
|
62
|
-
const upper = fabricCanvas.upperCanvasEl;
|
|
63
|
-
const bounds = upper.getBoundingClientRect();
|
|
64
|
-
viewport = { left: bounds.left, top: bounds.top, width: bounds.width, height: bounds.height };
|
|
65
|
-
if (drawingCanvas.width !== upper.width) drawingCanvas.width = upper.width;
|
|
66
|
-
if (drawingCanvas.height !== upper.height) drawingCanvas.height = upper.height;
|
|
67
|
-
const context = drawingCanvas.getContext('2d');
|
|
68
|
-
if (!context) return;
|
|
69
|
-
context.setTransform(1, 0, 0, 1, 0, 0);
|
|
70
|
-
context.clearRect(0, 0, drawingCanvas.width, drawingCanvas.height);
|
|
71
|
-
const selected = fabricCanvas.getActiveObject();
|
|
72
|
-
if (!selected || !(selected as any)._isWidgetImage || fabricCanvas.skipTargetFind || fabricCanvas.isDrawingMode) {
|
|
73
|
-
controls = [];
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const retina = fabricCanvas.getRetinaScaling();
|
|
77
|
-
context.setTransform(retina, 0, 0, retina, 0, 0);
|
|
78
|
-
// Red primary stroke is part of the object, not the selection border.
|
|
79
|
-
// The simple canvas hides it. Advanced paints it above the HTML preview.
|
|
80
|
-
if (advancedFeatures && (selected as any)._isPrimaryWidget && selected.strokeWidth) {
|
|
81
|
-
context.save();
|
|
82
|
-
context.transform(...fabricCanvas.viewportTransform);
|
|
83
|
-
context.transform(...selected.calcTransformMatrix());
|
|
84
|
-
context.strokeStyle = selected.stroke as string;
|
|
85
|
-
context.lineWidth = selected.strokeWidth;
|
|
86
|
-
context.strokeRect(-selected.width / 2, -selected.height / 2, selected.width, selected.height);
|
|
87
|
-
context.restore();
|
|
88
|
-
}
|
|
89
|
-
selected.setCoords();
|
|
90
|
-
// The rotate square is on the shared control. Hide it before the first
|
|
91
|
-
// chrome refresh, so a saved widget does not show it while Advanced is off.
|
|
92
|
-
if (!advancedFeatures && typeof (selected as any).setControlsVisibility === 'function') {
|
|
93
|
-
(selected as any).setControlsVisibility({ mtr: false });
|
|
94
|
-
}
|
|
95
|
-
selected._renderControls(context);
|
|
96
|
-
const scaleX = bounds.width / fabricCanvas.getWidth();
|
|
97
|
-
const scaleY = bounds.height / fabricCanvas.getHeight();
|
|
98
|
-
// Fabric's internal control geometry (oCoords/controls) isn't on the
|
|
99
|
-
// public FabricObject type; this layer re-renders it as hit regions.
|
|
100
|
-
const sel = selected as any;
|
|
101
|
-
const hiddenWhenSimple = new Set(['ml', 'mr', 'mt', 'mb', 'mtr']);
|
|
102
|
-
controls = Object.entries(sel.oCoords || {}).flatMap(([key, position]: [string, any]) => {
|
|
103
|
-
const control = sel.controls[key];
|
|
104
|
-
if (!advancedFeatures && hiddenWhenSimple.has(key)) return [];
|
|
105
|
-
if (!sel.hasControls || !control?.getVisibility(sel, key)) return [];
|
|
106
|
-
const points = position.corner;
|
|
107
|
-
return [{ key, points: ['tl', 'tr', 'br', 'bl'].map(corner => `${points[corner].x * scaleX},${points[corner].y * scaleY}`).join(' '), cursor: control.cursorStyleHandler({}, control, sel) }];
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// The board flips Advanced after this layer is already mounted. Repaint once
|
|
112
|
-
// the flag has landed, so a render that raced the prop does not leave the
|
|
113
|
-
// rotate handle or the red stroke up.
|
|
114
|
-
$effect(() => {
|
|
115
|
-
void advancedFeatures;
|
|
116
|
-
if (drawingCanvas) redraw();
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
onMount(() => {
|
|
120
|
-
let animationFrame = 0;
|
|
121
|
-
function scheduleRedraw() {
|
|
122
|
-
if (animationFrame) return;
|
|
123
|
-
animationFrame = requestAnimationFrame(() => {
|
|
124
|
-
animationFrame = 0;
|
|
125
|
-
redraw();
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
const disposeRender = fabricCanvas.on('after:render', scheduleRedraw);
|
|
129
|
-
const observer = new ResizeObserver(scheduleRedraw);
|
|
130
|
-
observer.observe(fabricCanvas.upperCanvasEl);
|
|
131
|
-
window.addEventListener('scroll', scheduleRedraw, true);
|
|
132
|
-
window.addEventListener('resize', scheduleRedraw);
|
|
133
|
-
scheduleRedraw();
|
|
134
|
-
return () => {
|
|
135
|
-
if (activePointer !== null && lastPointerEvent && !fabricCanvas.disposed) finishControl(lastPointerEvent);
|
|
136
|
-
disposeRender();
|
|
137
|
-
observer.disconnect();
|
|
138
|
-
window.removeEventListener('scroll', scheduleRedraw, true);
|
|
139
|
-
window.removeEventListener('resize', scheduleRedraw);
|
|
140
|
-
cancelAnimationFrame(animationFrame);
|
|
141
|
-
};
|
|
142
|
-
});
|
|
143
|
-
</script>
|
|
144
|
-
|
|
145
|
-
<Portal {target} style="z-index: 70; pointer-events: none;">
|
|
146
|
-
<div class="canvas-widget-selection-layer fixed pointer-events-none overflow-hidden {className}" style="left: {viewport.left}px; /* rtl-ok: laid over the board where the board is on the screen, measured from the left edge of the window */ top: {viewport.top}px; width: {viewport.width}px; height: {viewport.height}px; pointer-events: none; {style}">
|
|
147
|
-
<canvas class="canvas-widget-selection-paint h-full w-full pointer-events-none" use:captureDrawingCanvas aria-hidden="true"></canvas>
|
|
148
|
-
<svg class="canvas-widget-control-hit-regions absolute inset-0 h-full w-full pointer-events-none" aria-hidden="true">
|
|
149
|
-
{#each controls as control (control.key)}
|
|
150
|
-
<!-- Fabric controls are pointer affordances; equivalent numeric dimensions remain in PropsPanel. -->
|
|
151
|
-
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
152
|
-
<polygon class="canvas-widget-control-hit-region pointer-events-auto touch-none" data-control={control.key} points={control.points} fill="transparent" style="cursor: {control.cursor};" onpointerdown={startControl} onpointermove={moveControl} onpointerup={finishControl} onpointercancel={finishControl} onlostpointercapture={finishControl} />
|
|
153
|
-
{/each}
|
|
154
|
-
</svg>
|
|
155
|
-
</div>
|
|
156
|
-
</Portal>
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Canvas } from 'fabric';
|
|
2
|
-
type $$ComponentProps = {
|
|
3
|
-
fabricCanvas: Canvas;
|
|
4
|
-
target: string;
|
|
5
|
-
advancedFeatures?: boolean;
|
|
6
|
-
class?: string;
|
|
7
|
-
style?: string;
|
|
8
|
-
};
|
|
9
|
-
declare const WidgetSelectionLayer: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
10
|
-
type WidgetSelectionLayer = ReturnType<typeof WidgetSelectionLayer>;
|
|
11
|
-
export default WidgetSelectionLayer;
|