@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,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ImageShape — custom Rect subclass for image placeholders on canvas.
|
|
3
|
-
*
|
|
4
|
-
* Responsibilities:
|
|
5
|
-
* - When _hasImage = false → renders placeholder UI (icon + "Drop image" text + dashed border)
|
|
6
|
-
* - When _hasImage = true → renders the loaded image (clipped, with optional corner radius)
|
|
7
|
-
*
|
|
8
|
-
* This is the base class for images on canvas. For widget-specific behavior
|
|
9
|
-
* (linked to a widget via _widgetId), see WidgetShape which extends this class.
|
|
10
|
-
*
|
|
11
|
-
* Fabric serialises as type:'ImageShape'. Old saves with type:'Rect' + _customType:'image'
|
|
12
|
-
* are handled by upgradeToImageShape() which swaps the prototype chain.
|
|
13
|
-
*/
|
|
14
|
-
import { Rect } from 'fabric';
|
|
15
|
-
export declare const IMAGE_SHAPE_CUSTOM_PROPS: string[];
|
|
16
|
-
export declare class ImageShape extends Rect {
|
|
17
|
-
static type: string;
|
|
18
|
-
_customType: string;
|
|
19
|
-
_hasImage: boolean;
|
|
20
|
-
_imageElement: HTMLImageElement | null;
|
|
21
|
-
_imageUrl: string | null;
|
|
22
|
-
_originalFilename: string | null;
|
|
23
|
-
_originalAspectRatio: number | null;
|
|
24
|
-
_cornerRoundness: number;
|
|
25
|
-
_cornerRoundnessPixels: number;
|
|
26
|
-
_objectId: string | null;
|
|
27
|
-
_videoElement: HTMLVideoElement | null;
|
|
28
|
-
_videoObjectUrl: string | null;
|
|
29
|
-
_render(ctx: CanvasRenderingContext2D): void;
|
|
30
|
-
private _renderImage;
|
|
31
|
-
getVideoPlayBadgeRadius(): number;
|
|
32
|
-
isVideoPlayBadgeHit(scenePoint: {
|
|
33
|
-
x: number;
|
|
34
|
-
y: number;
|
|
35
|
-
}): boolean;
|
|
36
|
-
toggleVideoPlayback(): Promise<boolean>;
|
|
37
|
-
private _renderVideoChrome;
|
|
38
|
-
private _renderPlaceholderOverlay;
|
|
39
|
-
toObject(propertiesToInclude?: any[]): any;
|
|
40
|
-
static fromObject(object: Record<string, unknown>, options?: Record<string, unknown>): Promise<ImageShape>;
|
|
41
|
-
static reloadImage(shape: ImageShape): void;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Upgrades a plain Rect with _customType:'image' to an ImageShape instance by
|
|
45
|
-
* swapping the prototype chain. No object re-creation needed.
|
|
46
|
-
*/
|
|
47
|
-
export declare function upgradeToImageShape(obj: any): ImageShape | null;
|
|
@@ -1,339 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ImageShape — custom Rect subclass for image placeholders on canvas.
|
|
3
|
-
*
|
|
4
|
-
* Responsibilities:
|
|
5
|
-
* - When _hasImage = false → renders placeholder UI (icon + "Drop image" text + dashed border)
|
|
6
|
-
* - When _hasImage = true → renders the loaded image (clipped, with optional corner radius)
|
|
7
|
-
*
|
|
8
|
-
* This is the base class for images on canvas. For widget-specific behavior
|
|
9
|
-
* (linked to a widget via _widgetId), see WidgetShape which extends this class.
|
|
10
|
-
*
|
|
11
|
-
* Fabric serialises as type:'ImageShape'. Old saves with type:'Rect' + _customType:'image'
|
|
12
|
-
* are handled by upgradeToImageShape() which swaps the prototype chain.
|
|
13
|
-
*/
|
|
14
|
-
import { Rect, classRegistry } from 'fabric';
|
|
15
|
-
import { canvasLog, canvasWarn } from '../canvasLogger';
|
|
16
|
-
import { shapeWordsOf } from '../../i18n/shapeWords.js';
|
|
17
|
-
// ── Custom property names for base ImageShape ─────────────────────────────────
|
|
18
|
-
export const IMAGE_SHAPE_CUSTOM_PROPS = [
|
|
19
|
-
'_customType',
|
|
20
|
-
'_hasImage',
|
|
21
|
-
'_imageUrl',
|
|
22
|
-
'_originalFilename',
|
|
23
|
-
'_originalAspectRatio',
|
|
24
|
-
'_cornerRoundness',
|
|
25
|
-
'_cornerRoundnessPixels',
|
|
26
|
-
'_objectId',
|
|
27
|
-
];
|
|
28
|
-
export class ImageShape extends Rect {
|
|
29
|
-
static type = 'ImageShape';
|
|
30
|
-
// Custom fields — typed for IDE support
|
|
31
|
-
_customType = 'image';
|
|
32
|
-
_hasImage = false;
|
|
33
|
-
_imageElement = null;
|
|
34
|
-
_imageUrl = null;
|
|
35
|
-
_originalFilename = null;
|
|
36
|
-
_originalAspectRatio = null;
|
|
37
|
-
_cornerRoundness = 0;
|
|
38
|
-
_cornerRoundnessPixels = 0;
|
|
39
|
-
_objectId = null;
|
|
40
|
-
_videoElement = null;
|
|
41
|
-
_videoObjectUrl = null;
|
|
42
|
-
// ── Placeholder rendering ─────────────────────────────────────────────────
|
|
43
|
-
_render(ctx) {
|
|
44
|
-
const hasVideoFrame = this._customType === 'video' && !!this._videoElement && this._videoElement.readyState >= 2;
|
|
45
|
-
const hasImage = (this._hasImage && this._imageElement) || hasVideoFrame;
|
|
46
|
-
if (hasImage) {
|
|
47
|
-
this._renderImage(ctx);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
super._render(ctx);
|
|
51
|
-
this._renderPlaceholderOverlay(ctx);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
// ── Image rendering ───────────────────────────────────────────────────────
|
|
55
|
-
_renderImage(ctx) {
|
|
56
|
-
const w = this.width || 100;
|
|
57
|
-
const h = this.height || 100;
|
|
58
|
-
const r = this._cornerRoundnessPixels || 0;
|
|
59
|
-
ctx.save();
|
|
60
|
-
ctx.beginPath();
|
|
61
|
-
if (r > 0) {
|
|
62
|
-
const minDim = Math.min(w, h);
|
|
63
|
-
if (r >= minDim / 2) {
|
|
64
|
-
if (w === h) {
|
|
65
|
-
ctx.arc(0, 0, w / 2, 0, Math.PI * 2);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
ctx.ellipse(0, 0, w / 2, h / 2, 0, 0, Math.PI * 2);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
ctx.moveTo(-w / 2 + r, -h / 2);
|
|
73
|
-
ctx.arcTo(w / 2, -h / 2, w / 2, h / 2, r);
|
|
74
|
-
ctx.arcTo(w / 2, h / 2, -w / 2, h / 2, r);
|
|
75
|
-
ctx.arcTo(-w / 2, h / 2, -w / 2, -h / 2, r);
|
|
76
|
-
ctx.arcTo(-w / 2, -h / 2, w / 2, -h / 2, r);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
ctx.rect(-w / 2, -h / 2, w, h);
|
|
81
|
-
}
|
|
82
|
-
ctx.closePath();
|
|
83
|
-
ctx.clip();
|
|
84
|
-
const img = this._imageElement;
|
|
85
|
-
const video = this._customType === 'video' ? this._videoElement : null;
|
|
86
|
-
const useVideo = !!(video && video.readyState >= 2);
|
|
87
|
-
const source = useVideo ? video : (img && img.complete && img.naturalWidth > 0 ? img : null);
|
|
88
|
-
const imgReady = !!source;
|
|
89
|
-
// Live HTML overlay active: paint solid fill so the old screenshot does not ghost in the padding.
|
|
90
|
-
if (this._isWidgetImage && this._hideImageForLivePreview) {
|
|
91
|
-
ctx.fillStyle = '#f3f4f6';
|
|
92
|
-
ctx.fillRect(-w / 2, -h / 2, w, h);
|
|
93
|
-
}
|
|
94
|
-
else if (source) {
|
|
95
|
-
if (this._isWidgetImage && img && img.complete && img.naturalWidth > 0 && !useVideo) {
|
|
96
|
-
const imgW = img.naturalWidth;
|
|
97
|
-
const imgH = img.naturalHeight;
|
|
98
|
-
const scale = Math.min(w / imgW, h / imgH);
|
|
99
|
-
const dw = imgW * scale;
|
|
100
|
-
const dh = imgH * scale;
|
|
101
|
-
ctx.drawImage(img, -dw / 2, -dh / 2, dw, dh);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
ctx.drawImage(source, -w / 2, -h / 2, w, h);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
ctx.restore();
|
|
108
|
-
if (this._customType === 'video' && imgReady) {
|
|
109
|
-
this._renderVideoChrome(ctx, w, h);
|
|
110
|
-
}
|
|
111
|
-
if (this.stroke && (this.strokeWidth ?? 0) > 0) {
|
|
112
|
-
ctx.save();
|
|
113
|
-
ctx.strokeStyle = this.stroke;
|
|
114
|
-
ctx.lineWidth = this.strokeWidth ?? 1;
|
|
115
|
-
if (this.strokeDashArray)
|
|
116
|
-
ctx.setLineDash(this.strokeDashArray);
|
|
117
|
-
ctx.beginPath();
|
|
118
|
-
if (r > 0) {
|
|
119
|
-
const minDim = Math.min(w, h);
|
|
120
|
-
if (r >= minDim / 2) {
|
|
121
|
-
if (w === h) {
|
|
122
|
-
ctx.arc(0, 0, w / 2, 0, Math.PI * 2);
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
ctx.ellipse(0, 0, w / 2, h / 2, 0, 0, Math.PI * 2);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
ctx.moveTo(-w / 2 + r, -h / 2);
|
|
130
|
-
ctx.arcTo(w / 2, -h / 2, w / 2, h / 2, r);
|
|
131
|
-
ctx.arcTo(w / 2, h / 2, -w / 2, h / 2, r);
|
|
132
|
-
ctx.arcTo(-w / 2, h / 2, -w / 2, -h / 2, r);
|
|
133
|
-
ctx.arcTo(-w / 2, -h / 2, w / 2, -h / 2, r);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
ctx.rect(-w / 2, -h / 2, w, h);
|
|
138
|
-
}
|
|
139
|
-
ctx.closePath();
|
|
140
|
-
ctx.stroke();
|
|
141
|
-
ctx.restore();
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
getVideoPlayBadgeRadius() {
|
|
145
|
-
const w = this.width || 100;
|
|
146
|
-
const h = this.height || 100;
|
|
147
|
-
const size = Math.max(18, Math.min(w, h) * 0.22);
|
|
148
|
-
return (size / 2) * Math.max(this.scaleX || 1, this.scaleY || 1);
|
|
149
|
-
}
|
|
150
|
-
isVideoPlayBadgeHit(scenePoint) {
|
|
151
|
-
if (this._customType !== 'video' || !this._videoElement)
|
|
152
|
-
return false;
|
|
153
|
-
const center = this.getCenterPoint();
|
|
154
|
-
const radius = this.getVideoPlayBadgeRadius();
|
|
155
|
-
const dx = scenePoint.x - center.x;
|
|
156
|
-
const dy = scenePoint.y - center.y;
|
|
157
|
-
return dx * dx + dy * dy <= radius * radius;
|
|
158
|
-
}
|
|
159
|
-
async toggleVideoPlayback() {
|
|
160
|
-
const video = this._videoElement;
|
|
161
|
-
if (!video) {
|
|
162
|
-
canvasWarn('ImageShape: no video element to play');
|
|
163
|
-
return false;
|
|
164
|
-
}
|
|
165
|
-
try {
|
|
166
|
-
if (video.paused) {
|
|
167
|
-
await video.play();
|
|
168
|
-
canvasLog('ImageShape: video playing');
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
video.pause();
|
|
172
|
-
canvasLog('ImageShape: video paused');
|
|
173
|
-
}
|
|
174
|
-
this.dirty = true;
|
|
175
|
-
return true;
|
|
176
|
-
}
|
|
177
|
-
catch (err) {
|
|
178
|
-
canvasWarn('ImageShape: video play/pause failed', err);
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
_renderVideoChrome(ctx, w, h) {
|
|
183
|
-
const video = this._videoElement;
|
|
184
|
-
const playing = !!(video && !video.paused && !video.ended);
|
|
185
|
-
const size = Math.max(18, Math.min(w, h) * 0.22);
|
|
186
|
-
ctx.save();
|
|
187
|
-
ctx.beginPath();
|
|
188
|
-
ctx.arc(0, 0, size / 2, 0, Math.PI * 2);
|
|
189
|
-
ctx.fillStyle = 'rgba(0, 0, 0, 0.45)';
|
|
190
|
-
ctx.fill();
|
|
191
|
-
ctx.fillStyle = '#ffffff';
|
|
192
|
-
if (playing) {
|
|
193
|
-
const barW = size * 0.08;
|
|
194
|
-
const barH = size * 0.28;
|
|
195
|
-
const gap = size * 0.08;
|
|
196
|
-
ctx.fillRect(-gap / 2 - barW, -barH / 2, barW, barH);
|
|
197
|
-
ctx.fillRect(gap / 2, -barH / 2, barW, barH);
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
ctx.beginPath();
|
|
201
|
-
const tri = size * 0.18;
|
|
202
|
-
ctx.moveTo(-tri * 0.35, -tri);
|
|
203
|
-
ctx.lineTo(tri * 0.85, 0);
|
|
204
|
-
ctx.lineTo(-tri * 0.35, tri);
|
|
205
|
-
ctx.closePath();
|
|
206
|
-
ctx.fill();
|
|
207
|
-
}
|
|
208
|
-
if (video && Number.isFinite(video.duration) && video.duration > 0) {
|
|
209
|
-
const barH = Math.max(4, Math.min(8, h * 0.06));
|
|
210
|
-
const progress = Math.max(0, Math.min(1, video.currentTime / video.duration));
|
|
211
|
-
ctx.fillStyle = 'rgba(0, 0, 0, 0.45)';
|
|
212
|
-
ctx.fillRect(-w / 2, h / 2 - barH, w, barH);
|
|
213
|
-
ctx.fillStyle = '#ffffff';
|
|
214
|
-
ctx.fillRect(-w / 2, h / 2 - barH, w * progress, barH);
|
|
215
|
-
}
|
|
216
|
-
ctx.restore();
|
|
217
|
-
}
|
|
218
|
-
// ── Placeholder icon + text overlay ──────────────────────────────────────
|
|
219
|
-
_renderPlaceholderOverlay(ctx) {
|
|
220
|
-
const scaleX = Math.abs(this.scaleX || 1) || 1;
|
|
221
|
-
const scaleY = Math.abs(this.scaleY || 1) || 1;
|
|
222
|
-
ctx.save();
|
|
223
|
-
ctx.scale(1 / scaleX, 1 / scaleY);
|
|
224
|
-
const visualW = Math.abs((this.width || 100) * scaleX);
|
|
225
|
-
const visualH = Math.abs((this.height || 100) * scaleY);
|
|
226
|
-
const iconSize = 36;
|
|
227
|
-
const fontSize = 16;
|
|
228
|
-
const lineGap = fontSize + 6;
|
|
229
|
-
// The three lines are in the language of the canvas this shape is on ("Drop image", "or", "double click" in
|
|
230
|
-
// English). They can be longer than the English ones, so the block is made wide enough for the longest.
|
|
231
|
-
const words = shapeWordsOf(this.canvas);
|
|
232
|
-
const lines = [this._customType === 'video' ? words.dropVideo : words.dropImage, words.or, words.doubleClick];
|
|
233
|
-
ctx.font = `${fontSize}px Arial`;
|
|
234
|
-
const widestLine = Math.max(...lines.map((line) => ctx.measureText(line).width));
|
|
235
|
-
const contentWidth = Math.max(168, widestLine);
|
|
236
|
-
const contentHeight = iconSize + 12 + lineGap * 2;
|
|
237
|
-
const contentScale = Math.max(0.7, Math.min((visualW * 0.88) / contentWidth, (visualH * 0.7) / contentHeight));
|
|
238
|
-
ctx.fillStyle = '#94a3b8';
|
|
239
|
-
ctx.textAlign = 'center';
|
|
240
|
-
ctx.textBaseline = 'middle';
|
|
241
|
-
ctx.save();
|
|
242
|
-
ctx.scale(contentScale, contentScale);
|
|
243
|
-
ctx.font = `${iconSize}px Arial`;
|
|
244
|
-
ctx.fillText(this._customType === 'video' ? '🎬' : '🖼️', 0, -28);
|
|
245
|
-
ctx.font = `${fontSize}px Arial`;
|
|
246
|
-
lines.forEach((line, lineIndex) => ctx.fillText(line, 0, 8 + lineGap * lineIndex));
|
|
247
|
-
ctx.restore();
|
|
248
|
-
ctx.restore();
|
|
249
|
-
}
|
|
250
|
-
// ── Serialisation ─────────────────────────────────────────────────────────
|
|
251
|
-
toObject(propertiesToInclude) {
|
|
252
|
-
const extras = IMAGE_SHAPE_CUSTOM_PROPS.concat(propertiesToInclude ?? []);
|
|
253
|
-
const base = super.toObject(extras);
|
|
254
|
-
return {
|
|
255
|
-
...base,
|
|
256
|
-
type: this.constructor.type,
|
|
257
|
-
_imageElement: undefined,
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
// ── Deserialisation ───────────────────────────────────────────────────────
|
|
261
|
-
static fromObject(object, options) {
|
|
262
|
-
return Rect.fromObject({ ...object, type: 'rect' }, options).then((rect) => {
|
|
263
|
-
Object.setPrototypeOf(rect, ImageShape.prototype);
|
|
264
|
-
const shape = rect;
|
|
265
|
-
for (const prop of IMAGE_SHAPE_CUSTOM_PROPS) {
|
|
266
|
-
if (prop in object && shape[prop] === undefined || shape[prop] !== object[prop]) {
|
|
267
|
-
shape[prop] = object[prop];
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
if (shape._imageUrl) {
|
|
271
|
-
ImageShape.reloadImage(shape);
|
|
272
|
-
}
|
|
273
|
-
canvasLog('ImageShape: fromObject — restored', shape._objectId || 'shape', 'hasImage:', shape._hasImage);
|
|
274
|
-
return shape;
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
// ── Image loading ─────────────────────────────────────────────────────────
|
|
278
|
-
static reloadImage(shape) {
|
|
279
|
-
if (!shape._imageUrl)
|
|
280
|
-
return;
|
|
281
|
-
const img = new Image();
|
|
282
|
-
img.crossOrigin = 'anonymous';
|
|
283
|
-
img.onload = () => {
|
|
284
|
-
shape._imageElement = img;
|
|
285
|
-
shape._hasImage = true;
|
|
286
|
-
shape.dirty = true;
|
|
287
|
-
const parentGroup = shape.group;
|
|
288
|
-
if (parentGroup) {
|
|
289
|
-
parentGroup.dirty = true;
|
|
290
|
-
}
|
|
291
|
-
const canvasRef = shape.canvas;
|
|
292
|
-
if (canvasRef) {
|
|
293
|
-
canvasRef.requestRenderAll();
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
requestAnimationFrame(() => {
|
|
297
|
-
const c = shape.canvas;
|
|
298
|
-
if (c) {
|
|
299
|
-
const pg = shape.group;
|
|
300
|
-
if (pg)
|
|
301
|
-
pg.dirty = true;
|
|
302
|
-
c.requestRenderAll();
|
|
303
|
-
}
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
canvasLog('ImageShape: image reloaded from URL', shape._imageUrl?.substring(0, 60));
|
|
307
|
-
};
|
|
308
|
-
img.onerror = () => {
|
|
309
|
-
canvasWarn('ImageShape: failed to reload image', shape._imageUrl?.substring(0, 60));
|
|
310
|
-
};
|
|
311
|
-
img.src = shape._imageUrl;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
// Register so loadFromJSON can resolve type:'ImageShape'
|
|
315
|
-
classRegistry.setClass(ImageShape);
|
|
316
|
-
// ── Upgrade helper for backward-compat (old saves: type:'Rect' + _customType:'image') ─
|
|
317
|
-
/**
|
|
318
|
-
* Upgrades a plain Rect with _customType:'image' to an ImageShape instance by
|
|
319
|
-
* swapping the prototype chain. No object re-creation needed.
|
|
320
|
-
*/
|
|
321
|
-
export function upgradeToImageShape(obj) {
|
|
322
|
-
if (!obj || (obj._customType !== 'image' && obj._customType !== 'video'))
|
|
323
|
-
return null;
|
|
324
|
-
if (obj instanceof ImageShape)
|
|
325
|
-
return obj;
|
|
326
|
-
try {
|
|
327
|
-
Object.setPrototypeOf(obj, ImageShape.prototype);
|
|
328
|
-
const shape = obj;
|
|
329
|
-
if (shape._imageUrl && !shape._imageElement) {
|
|
330
|
-
ImageShape.reloadImage(shape);
|
|
331
|
-
}
|
|
332
|
-
canvasLog('ImageShape: upgraded Rect → ImageShape for', shape._objectId || 'shape');
|
|
333
|
-
return shape;
|
|
334
|
-
}
|
|
335
|
-
catch (err) {
|
|
336
|
-
canvasWarn('ImageShape: upgradeToImageShape failed', err);
|
|
337
|
-
return null;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { ImageShape } from './ImageShape';
|
|
2
|
-
export declare const WIDGET_SHAPE_EXTRA_PROPS: string[];
|
|
3
|
-
export declare const WIDGET_SHAPE_CUSTOM_PROPS: string[];
|
|
4
|
-
/** Pulls a shape's thumbnail back from the host store and repaints it. */
|
|
5
|
-
export declare function restoreThumbnailFromStore(shape: WidgetShape): Promise<void>;
|
|
6
|
-
export declare class WidgetShape extends ImageShape {
|
|
7
|
-
static type: string;
|
|
8
|
-
_isWidgetImage: boolean;
|
|
9
|
-
_widgetId: string | null;
|
|
10
|
-
_widgetName: string | null;
|
|
11
|
-
/** True when _widgetId no longer exists in the host widget list (deleted or moved). */
|
|
12
|
-
_widgetOrphaned: boolean;
|
|
13
|
-
/** Reference to the thumbnail bytes held by the host store, when externalized. */
|
|
14
|
-
_imageRef: string | null;
|
|
15
|
-
/**
|
|
16
|
-
* Runtime-only: when live HTML iframe overlays the shape, hide the screenshot
|
|
17
|
-
* (draw a solid fill instead) so it does not ghost in the padding. Not serialized.
|
|
18
|
-
*/
|
|
19
|
-
_hideImageForLivePreview: boolean;
|
|
20
|
-
/** Custom placeholder overlay: replace generic "Drop image" text with the widget name. */
|
|
21
|
-
_render(ctx: CanvasRenderingContext2D): void;
|
|
22
|
-
private _renderWidgetPlaceholder;
|
|
23
|
-
toObject(propertiesToInclude?: any[]): any;
|
|
24
|
-
static fromObject(object: Record<string, unknown>, options?: Record<string, unknown>): Promise<WidgetShape>;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Upgrades an ImageShape to a WidgetShape by swapping the prototype chain.
|
|
28
|
-
* Called when user clicks "Convert to Widget".
|
|
29
|
-
*/
|
|
30
|
-
export declare function upgradeToWidgetShape(obj: any): WidgetShape | null;
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WidgetShape — extends ImageShape with widget-specific properties.
|
|
3
|
-
*
|
|
4
|
-
* Adds _isWidgetImage and _widgetId to link an image placeholder to a
|
|
5
|
-
* generated widget in the Widgetic platform.
|
|
6
|
-
*
|
|
7
|
-
* When an ImageShape is "converted to widget", its prototype is swapped
|
|
8
|
-
* to WidgetShape via upgradeToWidgetShape(), and the serialized type
|
|
9
|
-
* becomes 'WidgetShape'.
|
|
10
|
-
*
|
|
11
|
-
* Backward-compat: old saves that stored widget links directly on ImageShape
|
|
12
|
-
* (with type:'ImageShape' + _isWidgetImage:true) are handled by the
|
|
13
|
-
* classRegistry alias and the reviver in Canvas.svelte.
|
|
14
|
-
*/
|
|
15
|
-
import { Rect, classRegistry } from 'fabric';
|
|
16
|
-
import { ImageShape, IMAGE_SHAPE_CUSTOM_PROPS } from './ImageShape';
|
|
17
|
-
import { canvasLog, canvasWarn } from '../canvasLogger';
|
|
18
|
-
import { getShapeImageStore, isInlineImageData, shapeImageRef } from './shapeImageStore';
|
|
19
|
-
import { shapeWordsOf } from '../../i18n/shapeWords.js';
|
|
20
|
-
// Widget-specific custom properties (on top of IMAGE_SHAPE_CUSTOM_PROPS)
|
|
21
|
-
export const WIDGET_SHAPE_EXTRA_PROPS = [
|
|
22
|
-
'_isWidgetImage',
|
|
23
|
-
'_widgetId',
|
|
24
|
-
'_widgetName',
|
|
25
|
-
'_widgetOrphaned',
|
|
26
|
-
/** Stands in for the thumbnail bytes when a host store holds them. */
|
|
27
|
-
'_imageRef',
|
|
28
|
-
];
|
|
29
|
-
// Full list: base image props + widget props
|
|
30
|
-
export const WIDGET_SHAPE_CUSTOM_PROPS = [
|
|
31
|
-
...IMAGE_SHAPE_CUSTOM_PROPS,
|
|
32
|
-
...WIDGET_SHAPE_EXTRA_PROPS,
|
|
33
|
-
];
|
|
34
|
-
/** What the store already holds per reference, so repeat saves are skipped. */
|
|
35
|
-
const lastStoredThumbnailByRef = new Map();
|
|
36
|
-
/**
|
|
37
|
-
* Hands the thumbnail bytes to the host store and returns the fields that keep
|
|
38
|
-
* them out of the serialized shape. Returns nothing to change when there is no
|
|
39
|
-
* store, no inline bytes, or no stable reference to file them under — those
|
|
40
|
-
* shapes keep serializing as before.
|
|
41
|
-
*/
|
|
42
|
-
function externalizeThumbnail(shape) {
|
|
43
|
-
const store = getShapeImageStore();
|
|
44
|
-
if (!store || !isInlineImageData(shape._imageUrl))
|
|
45
|
-
return {};
|
|
46
|
-
const ref = shapeImageRef(shape._widgetId, shape._objectId);
|
|
47
|
-
if (!ref)
|
|
48
|
-
return {};
|
|
49
|
-
try {
|
|
50
|
-
// Undo history serializes on every edit, so only a changed screenshot is
|
|
51
|
-
// worth another write.
|
|
52
|
-
if (lastStoredThumbnailByRef.get(ref) !== shape._imageUrl) {
|
|
53
|
-
store.save(ref, shape._imageUrl);
|
|
54
|
-
lastStoredThumbnailByRef.set(ref, shape._imageUrl);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
catch (err) {
|
|
58
|
-
canvasWarn('WidgetShape: thumbnail store rejected the save, keeping it inline', err);
|
|
59
|
-
return {};
|
|
60
|
-
}
|
|
61
|
-
shape._imageRef = ref;
|
|
62
|
-
return { _imageUrl: undefined, _imageRef: ref };
|
|
63
|
-
}
|
|
64
|
-
/** Pulls a shape's thumbnail back from the host store and repaints it. */
|
|
65
|
-
export async function restoreThumbnailFromStore(shape) {
|
|
66
|
-
const store = getShapeImageStore();
|
|
67
|
-
if (!store || !shape._imageRef || shape._imageUrl)
|
|
68
|
-
return;
|
|
69
|
-
try {
|
|
70
|
-
const url = await store.load(shape._imageRef);
|
|
71
|
-
if (!url || shape._imageUrl)
|
|
72
|
-
return;
|
|
73
|
-
if (isInlineImageData(url))
|
|
74
|
-
lastStoredThumbnailByRef.set(shape._imageRef, url);
|
|
75
|
-
shape._imageUrl = url;
|
|
76
|
-
ImageShape.reloadImage(shape);
|
|
77
|
-
}
|
|
78
|
-
catch (err) {
|
|
79
|
-
canvasWarn('WidgetShape: could not restore thumbnail for', shape._imageRef, err);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
export class WidgetShape extends ImageShape {
|
|
83
|
-
static type = 'WidgetShape';
|
|
84
|
-
_isWidgetImage = false;
|
|
85
|
-
_widgetId = null;
|
|
86
|
-
_widgetName = null;
|
|
87
|
-
/** True when _widgetId no longer exists in the host widget list (deleted or moved). */
|
|
88
|
-
_widgetOrphaned = false;
|
|
89
|
-
/** Reference to the thumbnail bytes held by the host store, when externalized. */
|
|
90
|
-
_imageRef = null;
|
|
91
|
-
/**
|
|
92
|
-
* Runtime-only: when live HTML iframe overlays the shape, hide the screenshot
|
|
93
|
-
* (draw a solid fill instead) so it does not ghost in the padding. Not serialized.
|
|
94
|
-
*/
|
|
95
|
-
_hideImageForLivePreview = false;
|
|
96
|
-
/** Custom placeholder overlay: replace generic "Drop image" text with the widget name. */
|
|
97
|
-
_render(ctx) {
|
|
98
|
-
const hasImage = this._hasImage && this._imageElement;
|
|
99
|
-
if (hasImage) {
|
|
100
|
-
super._render(ctx);
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
// Draw the underlying rect background (dashed border stays via stroke).
|
|
104
|
-
Rect.prototype._render.call(this, ctx);
|
|
105
|
-
this._renderWidgetPlaceholder(ctx);
|
|
106
|
-
}
|
|
107
|
-
_renderWidgetPlaceholder(ctx) {
|
|
108
|
-
const availableW = this.width || 100;
|
|
109
|
-
const availableH = this.height || 100;
|
|
110
|
-
ctx.save();
|
|
111
|
-
ctx.fillStyle = '#475569';
|
|
112
|
-
ctx.textAlign = 'center';
|
|
113
|
-
ctx.textBaseline = 'middle';
|
|
114
|
-
const isOrphaned = !!this._widgetOrphaned;
|
|
115
|
-
// The words are in the language of the canvas this shape is on
|
|
116
|
-
const words = shapeWordsOf(this.canvas);
|
|
117
|
-
// Widget icon
|
|
118
|
-
const iconSize = Math.min(48, availableH * 0.28);
|
|
119
|
-
ctx.font = `${iconSize}px Arial`;
|
|
120
|
-
ctx.fillText(isOrphaned ? '⚠️' : '🧩', 0, -availableH * 0.18);
|
|
121
|
-
// Widget name
|
|
122
|
-
const name = isOrphaned
|
|
123
|
-
? words.unlinkedWidget
|
|
124
|
-
: (this._widgetName || words.widgetName);
|
|
125
|
-
const maxTextWidth = availableW - 24;
|
|
126
|
-
let fontSize = Math.max(11, Math.min(18, availableW * 0.06));
|
|
127
|
-
ctx.font = `600 ${fontSize}px system-ui, -apple-system, sans-serif`;
|
|
128
|
-
let displayName = name;
|
|
129
|
-
// Truncate with ellipsis if too wide
|
|
130
|
-
while (ctx.measureText(displayName).width > maxTextWidth && displayName.length > 4) {
|
|
131
|
-
displayName = displayName.slice(0, -1);
|
|
132
|
-
}
|
|
133
|
-
if (displayName.length < name.length)
|
|
134
|
-
displayName = displayName.slice(0, -1) + '…';
|
|
135
|
-
ctx.fillStyle = '#1e293b';
|
|
136
|
-
ctx.fillText(displayName, 0, availableH * 0.06);
|
|
137
|
-
// Subtitle
|
|
138
|
-
ctx.font = `400 ${Math.max(10, fontSize - 3)}px system-ui, -apple-system, sans-serif`;
|
|
139
|
-
ctx.fillStyle = '#64748b';
|
|
140
|
-
ctx.fillText(isOrphaned ? words.removeFromCanvas : words.widgetPreview, 0, availableH * 0.06 + fontSize + 6);
|
|
141
|
-
ctx.restore();
|
|
142
|
-
}
|
|
143
|
-
// ── Serialisation ─────────────────────────────────────────────────────────
|
|
144
|
-
toObject(propertiesToInclude) {
|
|
145
|
-
const extras = WIDGET_SHAPE_CUSTOM_PROPS.concat(propertiesToInclude ?? []);
|
|
146
|
-
const base = super.toObject(extras);
|
|
147
|
-
return {
|
|
148
|
-
...base,
|
|
149
|
-
...externalizeThumbnail(this),
|
|
150
|
-
type: WidgetShape.type,
|
|
151
|
-
_imageElement: undefined,
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
// ── Deserialisation ───────────────────────────────────────────────────────
|
|
155
|
-
static fromObject(object, options) {
|
|
156
|
-
return Rect.fromObject({ ...object, type: 'rect' }, options).then((rect) => {
|
|
157
|
-
Object.setPrototypeOf(rect, WidgetShape.prototype);
|
|
158
|
-
const shape = rect;
|
|
159
|
-
for (const prop of WIDGET_SHAPE_CUSTOM_PROPS) {
|
|
160
|
-
if (prop in object && shape[prop] === undefined || shape[prop] !== object[prop]) {
|
|
161
|
-
shape[prop] = object[prop];
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
if (shape._imageUrl) {
|
|
165
|
-
ImageShape.reloadImage(shape);
|
|
166
|
-
}
|
|
167
|
-
else if (shape._imageRef) {
|
|
168
|
-
void restoreThumbnailFromStore(shape);
|
|
169
|
-
}
|
|
170
|
-
canvasLog('WidgetShape: fromObject — restored', shape._objectId || 'shape', 'hasImage:', shape._hasImage, 'isWidget:', shape._isWidgetImage, 'widgetId:', shape._widgetId);
|
|
171
|
-
return shape;
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
// Register so loadFromJSON can resolve type:'WidgetShape'
|
|
176
|
-
classRegistry.setClass(WidgetShape);
|
|
177
|
-
/**
|
|
178
|
-
* Upgrades an ImageShape to a WidgetShape by swapping the prototype chain.
|
|
179
|
-
* Called when user clicks "Convert to Widget".
|
|
180
|
-
*/
|
|
181
|
-
export function upgradeToWidgetShape(obj) {
|
|
182
|
-
if (!obj)
|
|
183
|
-
return null;
|
|
184
|
-
if (obj instanceof WidgetShape)
|
|
185
|
-
return obj;
|
|
186
|
-
try {
|
|
187
|
-
Object.setPrototypeOf(obj, WidgetShape.prototype);
|
|
188
|
-
const shape = obj;
|
|
189
|
-
shape._isWidgetImage = true;
|
|
190
|
-
if (shape._imageRef && !shape._imageUrl) {
|
|
191
|
-
void restoreThumbnailFromStore(shape);
|
|
192
|
-
}
|
|
193
|
-
canvasLog('WidgetShape: upgraded ImageShape → WidgetShape for', shape._objectId || 'shape');
|
|
194
|
-
return shape;
|
|
195
|
-
}
|
|
196
|
-
catch (err) {
|
|
197
|
-
canvasWarn('WidgetShape: upgradeToWidgetShape failed', err);
|
|
198
|
-
return null;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Local widget pixels -> CSS viewport pixels (no selection padding/stroke).
|
|
3
|
-
* Fabric matrices include rotation, skew, flips and owning groups. CSS starts
|
|
4
|
-
* at the top-left, while Fabric transforms around the object's center.
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* @param {import('fabric').FabricObject} object
|
|
8
|
-
* @param {import('fabric').Canvas} canvas
|
|
9
|
-
* @param {HTMLCanvasElement} canvasElement
|
|
10
|
-
*/
|
|
11
|
-
export function getWidgetPreviewGeometry(object: import("fabric").FabricObject, canvas: import("fabric").Canvas, canvasElement: HTMLCanvasElement): {
|
|
12
|
-
left: number;
|
|
13
|
-
top: number;
|
|
14
|
-
width: number;
|
|
15
|
-
height: number;
|
|
16
|
-
localWidth: number;
|
|
17
|
-
localHeight: number;
|
|
18
|
-
matrix: number[];
|
|
19
|
-
} | null;
|