@widgetic/canvas 0.5.28 → 0.5.30
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/dist/canvas/Canvas.svelte +169 -4
- package/dist/canvas/Canvas.svelte.d.ts +5 -0
- package/dist/canvas/CanvasToolbar.svelte +6 -3
- package/dist/canvas/CanvasToolbar.svelte.d.ts +1 -1
- package/dist/canvas/PanZoomPanel.svelte +25 -22
- package/dist/canvas/PanZoomPanel.svelte.d.ts +1 -0
- package/dist/canvas/WidgetSelectionLayer.svelte +13 -3
- package/dist/canvas/WidgetSelectionLayer.svelte.d.ts +1 -0
- package/package.json +1 -1
|
@@ -190,6 +190,8 @@
|
|
|
190
190
|
// Extra canvas chrome (undo/redo/lock, frame, image, shape library).
|
|
191
191
|
// Default off for the sketch MVP. Same pattern as wireframeMode: keep the code, hide the UI.
|
|
192
192
|
export let advancedFeatures: boolean = false;
|
|
193
|
+
/** The zoom pill. Off on the site when debug is off. The save control stays. */
|
|
194
|
+
export let showZoomPanel: boolean = true;
|
|
193
195
|
/** When true and advanced is on, Frame/Image/Video stay on the toolbar. Default true. */
|
|
194
196
|
export let mediaBtsOnBar: boolean = true;
|
|
195
197
|
|
|
@@ -887,6 +889,130 @@
|
|
|
887
889
|
canvas.requestRenderAll();
|
|
888
890
|
}
|
|
889
891
|
}
|
|
892
|
+
|
|
893
|
+
/** Screenshot of every shape on the board, cropped to their bounds. */
|
|
894
|
+
export async function captureCanvasSketch(): Promise<string> {
|
|
895
|
+
if (!canvas) return '';
|
|
896
|
+
// Do not discard an ActiveSelection: Fabric 6 empties it on deselect.
|
|
897
|
+
// Selection handles sit on the upper canvas, so toDataURL leaves them out.
|
|
898
|
+
const objects = canvas.getObjects().filter((object: any) => object.visible !== false && !object.excludeFromExport);
|
|
899
|
+
if (objects.length === 0) return '';
|
|
900
|
+
let left = Infinity;
|
|
901
|
+
let top = Infinity;
|
|
902
|
+
let right = -Infinity;
|
|
903
|
+
let bottom = -Infinity;
|
|
904
|
+
for (const object of objects) {
|
|
905
|
+
const bounds = object.getBoundingRect();
|
|
906
|
+
left = Math.min(left, bounds.left);
|
|
907
|
+
top = Math.min(top, bounds.top);
|
|
908
|
+
right = Math.max(right, bounds.left + bounds.width);
|
|
909
|
+
bottom = Math.max(bottom, bounds.top + bounds.height);
|
|
910
|
+
}
|
|
911
|
+
if (!Number.isFinite(left) || right <= left || bottom <= top) return '';
|
|
912
|
+
skipGroupIdleOutline = true;
|
|
913
|
+
skipTextPlaceholder = true;
|
|
914
|
+
try {
|
|
915
|
+
canvas.renderAll();
|
|
916
|
+
const dataUrl = canvas.toDataURL({
|
|
917
|
+
format: 'png',
|
|
918
|
+
multiplier: 2,
|
|
919
|
+
left: Math.floor(left),
|
|
920
|
+
top: Math.floor(top),
|
|
921
|
+
width: Math.max(1, Math.ceil(right - left)),
|
|
922
|
+
height: Math.max(1, Math.ceil(bottom - top)),
|
|
923
|
+
});
|
|
924
|
+
canvasLog('Canvas sketch captured', { shapes: objects.length, bytes: dataUrl.length });
|
|
925
|
+
return dataUrl;
|
|
926
|
+
} catch (captureError) {
|
|
927
|
+
console.error('Canvas: captureCanvasSketch failed', captureError);
|
|
928
|
+
return '';
|
|
929
|
+
} finally {
|
|
930
|
+
skipGroupIdleOutline = false;
|
|
931
|
+
skipTextPlaceholder = false;
|
|
932
|
+
canvas.requestRenderAll();
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
/**
|
|
937
|
+
* Turn the whole board into one WidgetShape. A board that is already only
|
|
938
|
+
* this widget is left as it is.
|
|
939
|
+
*/
|
|
940
|
+
export async function absorbCanvasSketchIntoWidget(
|
|
941
|
+
widgetId: string,
|
|
942
|
+
screenshotDataUrl: string
|
|
943
|
+
): Promise<string | null> {
|
|
944
|
+
if (!canvas || !widgetId) return null;
|
|
945
|
+
try {
|
|
946
|
+
canvas.discardActiveObject();
|
|
947
|
+
} catch (discardError) {
|
|
948
|
+
console.warn('Canvas: discard before sketch absorb failed', discardError);
|
|
949
|
+
}
|
|
950
|
+
const objects = canvas.getObjects().filter((object: any) => !object.excludeFromExport);
|
|
951
|
+
// A text-only prompt has nothing to absorb. The live preview still needs a
|
|
952
|
+
// frame, so the board gets the same placeholder a shape would have had.
|
|
953
|
+
if (objects.length === 0) {
|
|
954
|
+
canvasLog('Canvas: empty board, placing a preview frame', widgetId.substring(0, 8));
|
|
955
|
+
return addWidgetShape(widgetId, undefined, 0, 1, screenshotDataUrl || null);
|
|
956
|
+
}
|
|
957
|
+
const alreadyThisWidget = objects.every((object: any) => object._isWidgetImage && object._widgetId === widgetId);
|
|
958
|
+
if (alreadyThisWidget) {
|
|
959
|
+
return (objects[0] as any)._objectId ?? null;
|
|
960
|
+
}
|
|
961
|
+
let left = Infinity;
|
|
962
|
+
let top = Infinity;
|
|
963
|
+
let right = -Infinity;
|
|
964
|
+
let bottom = -Infinity;
|
|
965
|
+
for (const object of objects) {
|
|
966
|
+
const bounds = object.getBoundingRect();
|
|
967
|
+
left = Math.min(left, bounds.left);
|
|
968
|
+
top = Math.min(top, bounds.top);
|
|
969
|
+
right = Math.max(right, bounds.left + bounds.width);
|
|
970
|
+
bottom = Math.max(bottom, bounds.top + bounds.height);
|
|
971
|
+
}
|
|
972
|
+
const bounds = {
|
|
973
|
+
left: Number.isFinite(left) ? left : 80,
|
|
974
|
+
top: Number.isFinite(top) ? top : 80,
|
|
975
|
+
width: Math.max(120, right - left),
|
|
976
|
+
height: Math.max(80, bottom - top),
|
|
977
|
+
};
|
|
978
|
+
for (const object of objects) canvas.remove(object);
|
|
979
|
+
const widgetImage = createImagePlaceholder({
|
|
980
|
+
left: bounds.left,
|
|
981
|
+
top: bounds.top,
|
|
982
|
+
width: bounds.width,
|
|
983
|
+
height: bounds.height,
|
|
984
|
+
}) as any;
|
|
985
|
+
upgradeToWidgetShape(widgetImage);
|
|
986
|
+
clearWidgetShapeDefaultBorder(widgetImage);
|
|
987
|
+
lockWidgetShapeBodyDrag(widgetImage);
|
|
988
|
+
const newObjectId = `widget_img_${Date.now()}`;
|
|
989
|
+
widgetImage._objectId = newObjectId;
|
|
990
|
+
widgetImage._customType = 'image';
|
|
991
|
+
widgetImage._widgetId = widgetId;
|
|
992
|
+
widgetImage._imageUrl = screenshotDataUrl;
|
|
993
|
+
widgetImage._hasImage = !!screenshotDataUrl;
|
|
994
|
+
widgetImage._originalFilename = 'widget-screenshot.png';
|
|
995
|
+
canvas.add(widgetImage);
|
|
996
|
+
if (screenshotDataUrl) {
|
|
997
|
+
const image = new Image();
|
|
998
|
+
image.onload = () => {
|
|
999
|
+
widgetImage._imageElement = image;
|
|
1000
|
+
widgetImage._originalAspectRatio = image.width / image.height;
|
|
1001
|
+
widgetImage.dirty = true;
|
|
1002
|
+
canvas?.requestRenderAll();
|
|
1003
|
+
takeHistorySnapshot();
|
|
1004
|
+
};
|
|
1005
|
+
image.onerror = () => {
|
|
1006
|
+
console.error('Canvas: Failed to load canvas sketch into WidgetShape');
|
|
1007
|
+
};
|
|
1008
|
+
image.src = screenshotDataUrl;
|
|
1009
|
+
}
|
|
1010
|
+
canvas.setActiveObject(widgetImage);
|
|
1011
|
+
selectedObject = widgetImage;
|
|
1012
|
+
canvas.requestRenderAll();
|
|
1013
|
+
canvasLog('Canvas sketch absorbed into one WidgetShape', { widgetId, objectId: newObjectId });
|
|
1014
|
+
return newObjectId;
|
|
1015
|
+
}
|
|
890
1016
|
|
|
891
1017
|
// Extract metadata from object for onObjectClick callback
|
|
892
1018
|
function extractObjectMetadata(target: any): Record<string, any> {
|
|
@@ -2748,12 +2874,15 @@
|
|
|
2748
2874
|
upgradeToImageShape(obj);
|
|
2749
2875
|
if ((obj as any)._isWidgetImage) {
|
|
2750
2876
|
lockWidgetShapeBodyDrag(obj);
|
|
2751
|
-
|
|
2877
|
+
applyWidgetShapeChrome(obj);
|
|
2878
|
+
if ((obj as any)._isPrimaryWidget && advancedFeatures) {
|
|
2752
2879
|
obj.set({
|
|
2753
2880
|
stroke: PRIMARY_WIDGET_STROKE,
|
|
2754
2881
|
strokeWidth: PRIMARY_WIDGET_STROKE_WIDTH,
|
|
2755
2882
|
strokeDashArray: null,
|
|
2756
2883
|
});
|
|
2884
|
+
} else if (!advancedFeatures) {
|
|
2885
|
+
obj.set({ stroke: 'transparent', strokeWidth: 0, strokeDashArray: null });
|
|
2757
2886
|
}
|
|
2758
2887
|
}
|
|
2759
2888
|
canvasLog('Canvas: object:added — upgraded image shape for', (obj as any)._objectId || 'image');
|
|
@@ -6589,6 +6718,39 @@
|
|
|
6589
6718
|
refreshTextShapeChrome();
|
|
6590
6719
|
}
|
|
6591
6720
|
|
|
6721
|
+
/**
|
|
6722
|
+
* Simple canvas: corner handles stay. Rotate and the mid-edge scales do not.
|
|
6723
|
+
* Advanced turns those handles back on.
|
|
6724
|
+
*/
|
|
6725
|
+
function applyWidgetShapeChrome(obj: any) {
|
|
6726
|
+
if (!obj?._isWidgetImage || typeof obj.setControlsVisibility !== 'function') return;
|
|
6727
|
+
obj.setControlsVisibility({
|
|
6728
|
+
ml: !!advancedFeatures,
|
|
6729
|
+
mr: !!advancedFeatures,
|
|
6730
|
+
mt: !!advancedFeatures,
|
|
6731
|
+
mb: !!advancedFeatures,
|
|
6732
|
+
mtr: !!advancedFeatures,
|
|
6733
|
+
tl: true,
|
|
6734
|
+
tr: true,
|
|
6735
|
+
bl: true,
|
|
6736
|
+
br: true,
|
|
6737
|
+
});
|
|
6738
|
+
}
|
|
6739
|
+
|
|
6740
|
+
function refreshWidgetShapeChrome() {
|
|
6741
|
+
if (!canvas) return;
|
|
6742
|
+
for (const obj of canvas.getObjects()) applyWidgetShapeChrome(obj);
|
|
6743
|
+
const primary = canvas.getObjects().find((object: any) => object._isWidgetImage && object._isPrimaryWidget) as any;
|
|
6744
|
+
applyPrimaryWidgetStrokes(primary?._widgetId ?? null);
|
|
6745
|
+
canvas.requestRenderAll();
|
|
6746
|
+
}
|
|
6747
|
+
|
|
6748
|
+
let widgetChromeAdvanced: boolean | null = null;
|
|
6749
|
+
$: if (canvas && widgetChromeAdvanced !== advancedFeatures) {
|
|
6750
|
+
widgetChromeAdvanced = advancedFeatures;
|
|
6751
|
+
refreshWidgetShapeChrome();
|
|
6752
|
+
}
|
|
6753
|
+
|
|
6592
6754
|
/** Fold a uniform scale into fontSize so the glyphs are redrawn, not stretched. */
|
|
6593
6755
|
function bakeTextboxScaleIntoFont(tb: any) {
|
|
6594
6756
|
if (!tb || tb.type !== 'textbox' || tb._bakingTextScale) return;
|
|
@@ -8493,7 +8655,7 @@ function checkAndAddNewShapeToFrame(shape: any) {
|
|
|
8493
8655
|
if (!anyObj._isWidgetImage) continue;
|
|
8494
8656
|
const isPrimary = !!(primaryWidgetId && anyObj._widgetId === primaryWidgetId);
|
|
8495
8657
|
anyObj._isPrimaryWidget = isPrimary;
|
|
8496
|
-
if (isPrimary) {
|
|
8658
|
+
if (isPrimary && advancedFeatures) {
|
|
8497
8659
|
obj.set({
|
|
8498
8660
|
stroke: PRIMARY_WIDGET_STROKE,
|
|
8499
8661
|
strokeWidth: PRIMARY_WIDGET_STROKE_WIDTH,
|
|
@@ -12646,6 +12808,7 @@ function checkAndAddNewShapeToFrame(shape: any) {
|
|
|
12646
12808
|
isPanActive={activeTool === 'pan'}
|
|
12647
12809
|
{showGrid}
|
|
12648
12810
|
{advancedFeatures}
|
|
12811
|
+
showZoomControls={showZoomPanel}
|
|
12649
12812
|
onPanToggle={() => activeTool === 'pan' ? onSelectSelectTool() : onSelectPanTool()}
|
|
12650
12813
|
onZoomIn={zoomIn}
|
|
12651
12814
|
onZoomOut={zoomOut}
|
|
@@ -12721,10 +12884,11 @@ function checkAndAddNewShapeToFrame(shape: any) {
|
|
|
12721
12884
|
/>
|
|
12722
12885
|
|
|
12723
12886
|
{#if canvas && widgetSelectionLayerTarget}
|
|
12724
|
-
<WidgetSelectionLayer fabricCanvas={canvas} target={widgetSelectionLayerTarget} />
|
|
12887
|
+
<WidgetSelectionLayer fabricCanvas={canvas} target={widgetSelectionLayerTarget} {advancedFeatures} />
|
|
12725
12888
|
{/if}
|
|
12726
12889
|
|
|
12727
|
-
<!--
|
|
12890
|
+
<!-- Props and Convert stay in the code. The simple canvas hides them until Advanced is on. -->
|
|
12891
|
+
{#if advancedFeatures}
|
|
12728
12892
|
<PropsPanel
|
|
12729
12893
|
{selectedObject}
|
|
12730
12894
|
{wireframeMode}
|
|
@@ -12790,6 +12954,7 @@ function checkAndAddNewShapeToFrame(shape: any) {
|
|
|
12790
12954
|
onWidthChange={updateSelectedWidth}
|
|
12791
12955
|
onHeightChange={updateSelectedHeight}
|
|
12792
12956
|
/>
|
|
12957
|
+
{/if}
|
|
12793
12958
|
|
|
12794
12959
|
<!-- Custom Context Menu (shown on right-click) -->
|
|
12795
12960
|
<ContextMenu
|
|
@@ -36,6 +36,7 @@ declare const Canvas: $$__sveltets_2_IsomorphicComponent<{
|
|
|
36
36
|
panZoomPosition?: "TL" | "TC" | "TR" | "BL" | "BC" | "BR";
|
|
37
37
|
wireframeMode?: boolean;
|
|
38
38
|
advancedFeatures?: boolean;
|
|
39
|
+
/** The zoom pill. Off on the site when debug is off. The save control stays. */ showZoomPanel?: boolean;
|
|
39
40
|
/** When true and advanced is on, Frame/Image/Video stay on the toolbar. Default true. */ mediaBtsOnBar?: boolean;
|
|
40
41
|
initialData?: string | null;
|
|
41
42
|
onReady?: (() => void) | null;
|
|
@@ -68,6 +69,8 @@ declare const Canvas: $$__sveltets_2_IsomorphicComponent<{
|
|
|
68
69
|
*/ locale?: string | null;
|
|
69
70
|
messages?: Readonly<Record<string, unknown>> | null;
|
|
70
71
|
shapeFillColor?: () => string;
|
|
72
|
+
captureCanvasSketch?: () => Promise<string>;
|
|
73
|
+
absorbCanvasSketchIntoWidget?: (widgetId: string, screenshotDataUrl: string) => Promise<string | null>;
|
|
71
74
|
deselectAll?: () => void;
|
|
72
75
|
duplicateSelectedObjects?: () => Promise<void>;
|
|
73
76
|
deleteSelectedObjects?: () => Promise<void>;
|
|
@@ -164,6 +167,8 @@ declare const Canvas: $$__sveltets_2_IsomorphicComponent<{
|
|
|
164
167
|
[evt: string]: CustomEvent<any>;
|
|
165
168
|
}, {}, {
|
|
166
169
|
shapeFillColor: () => string;
|
|
170
|
+
captureCanvasSketch: () => Promise<string>;
|
|
171
|
+
absorbCanvasSketchIntoWidget: (widgetId: string, screenshotDataUrl: string) => Promise<string | null>;
|
|
167
172
|
deselectAll: () => void;
|
|
168
173
|
duplicateSelectedObjects: () => Promise<void>;
|
|
169
174
|
deleteSelectedObjects: () => Promise<void>;
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
/** Draw-to-place: activates library shape tool so user clicks-and-drags to size it. */
|
|
76
76
|
export let onSelectLibraryShapeTool: (shapeKey: string, pathData: string) => void = () => {};
|
|
77
77
|
|
|
78
|
-
/** Extra tools (undo
|
|
78
|
+
/** Extra tools (undo, redo, lock, shapes). Arrow stays on the simple bar. */
|
|
79
79
|
export let advancedFeatures: boolean = false;
|
|
80
80
|
/**
|
|
81
81
|
* When true (default) and advancedFeatures is on, Frame / Image / Video sit on the toolbar.
|
|
@@ -106,6 +106,8 @@
|
|
|
106
106
|
// When a library shape was last selected, store its info for the trigger button
|
|
107
107
|
let lastSelectedLibraryShape: LibraryShape | null = null;
|
|
108
108
|
let shapesDropdownOpen = false;
|
|
109
|
+
// The shapes menu is part of the advanced toolbar. Close it when that mode turns off.
|
|
110
|
+
$: if (!advancedFeatures) shapesDropdownOpen = false;
|
|
109
111
|
let shapesDropdownNeedsScroll = false;
|
|
110
112
|
// DEV FLAG: when true the dropdown stays open after selecting a shape so
|
|
111
113
|
// multiple shapes can be placed in a row. Set to false for production.
|
|
@@ -483,7 +485,6 @@
|
|
|
483
485
|
so dropdowns and tooltips are rendered as siblings OUTSIDE this div -->
|
|
484
486
|
<div class="tools-ct flex flex-row">
|
|
485
487
|
{#if advancedFeatures}
|
|
486
|
-
<!-- ── Utility cluster: Undo, Redo, Hand, Lock | Divider ── -->
|
|
487
488
|
<Tooltip text={$t('canvas.tool.undoTitle')}>
|
|
488
489
|
<div class="disabled-tooltip-wrap">
|
|
489
490
|
<button
|
|
@@ -682,7 +683,8 @@
|
|
|
682
683
|
</Tooltip>
|
|
683
684
|
{/if}
|
|
684
685
|
|
|
685
|
-
<!-- Shapes: tldraw-style split — left activates tool, right opens dropdown.
|
|
686
|
+
<!-- Shapes: tldraw-style split — left activates tool, right opens dropdown. Advanced only. -->
|
|
687
|
+
{#if advancedFeatures}
|
|
686
688
|
<div class="shapes-split-ct" bind:this={dropdownTriggerEl}>
|
|
687
689
|
<Tooltip text={dropdownButtonTooltip}>
|
|
688
690
|
<button
|
|
@@ -713,6 +715,7 @@
|
|
|
713
715
|
</button>
|
|
714
716
|
</Tooltip>
|
|
715
717
|
</div>
|
|
718
|
+
{/if}
|
|
716
719
|
</div>
|
|
717
720
|
</div>
|
|
718
721
|
|
|
@@ -45,7 +45,7 @@ declare const CanvasToolbar: $$__sveltets_2_IsomorphicComponent<{
|
|
|
45
45
|
/** Passed by Canvas.svelte but never read here — export const keeps the
|
|
46
46
|
* init-set contract without the unused-reactive warning. */ onInsertLibraryShape?: (shapeKey: string, pathData: string) => void;
|
|
47
47
|
/** Draw-to-place: activates library shape tool so user clicks-and-drags to size it. */ onSelectLibraryShapeTool?: (shapeKey: string, pathData: string) => void;
|
|
48
|
-
/** Extra tools (undo
|
|
48
|
+
/** Extra tools (undo, redo, lock, shapes). Arrow stays on the simple bar. */ advancedFeatures?: boolean;
|
|
49
49
|
/**
|
|
50
50
|
* When true (default) and advancedFeatures is on, Frame / Image / Video sit on the toolbar.
|
|
51
51
|
* When false, they leave the bar and appear under More Shapes → Media Shapes.
|
|
@@ -33,6 +33,8 @@
|
|
|
33
33
|
|
|
34
34
|
/** Extra view controls (grid, pan, 1:1, fit, shortcuts). Zoom ± / % and save stay available. */
|
|
35
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;
|
|
36
38
|
|
|
37
39
|
// Save button: visible when showSaveButton is true
|
|
38
40
|
export let showSaveButton: boolean = false;
|
|
@@ -72,7 +74,28 @@
|
|
|
72
74
|
}
|
|
73
75
|
</script>
|
|
74
76
|
|
|
75
|
-
<div class="pan-zoom-panel-ct {className ? className + ' ' : ''}pan-zoom-panel {isMinimized ? 'pan-zoom-panel-minimized' : ''}" style={style}>
|
|
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}
|
|
98
|
+
{#if showZoomControls}
|
|
76
99
|
{#if isMinimized}
|
|
77
100
|
<Tooltip text={$t('canvas.zoom.expandTitle', { percent: String(zoomLevel) })} position="above">
|
|
78
101
|
<button
|
|
@@ -232,27 +255,6 @@
|
|
|
232
255
|
</Tooltip>
|
|
233
256
|
{/if}
|
|
234
257
|
|
|
235
|
-
{#if showSaveButton && advancedFeatures}
|
|
236
|
-
<div class="divider"></div>
|
|
237
|
-
<Tooltip text={$t(hasUnsavedChanges ? 'canvas.zoom.unsavedTitle' : 'canvas.zoom.savedTitle')} position="above">
|
|
238
|
-
<button
|
|
239
|
-
class="panel-btn save-btn {hasUnsavedChanges ? 'save-btn--dirty' : ''}"
|
|
240
|
-
onclick={() => onSave?.()}
|
|
241
|
-
aria-label={$t(hasUnsavedChanges ? 'canvas.zoom.unsavedTitle' : 'canvas.zoom.savedTitle')}
|
|
242
|
-
>
|
|
243
|
-
{#if hasUnsavedChanges}
|
|
244
|
-
<span class="save-dirty-dot">●</span>
|
|
245
|
-
{:else}
|
|
246
|
-
<svg width="14" height="14" viewBox="0 0 14 14" fill="none">
|
|
247
|
-
<path d="M2 2h8l2 2v8a1 1 0 01-1 1H3a1 1 0 01-1-1V2z" stroke="currentColor" stroke-width="1.3"/>
|
|
248
|
-
<rect x="4.5" y="2" width="3" height="3.5" rx="0.5" stroke="currentColor" stroke-width="1.2"/>
|
|
249
|
-
<rect x="3" y="7.5" width="8" height="4" rx="0.5" stroke="currentColor" stroke-width="1.2"/>
|
|
250
|
-
</svg>
|
|
251
|
-
{/if}
|
|
252
|
-
</button>
|
|
253
|
-
</Tooltip>
|
|
254
|
-
{/if}
|
|
255
|
-
|
|
256
258
|
<div class="pan-zoom-minimize-anchor">
|
|
257
259
|
<Tooltip text={$t('canvas.zoom.minimize')} position="above">
|
|
258
260
|
<button
|
|
@@ -268,6 +270,7 @@
|
|
|
268
270
|
</Tooltip>
|
|
269
271
|
</div>
|
|
270
272
|
{/if}
|
|
273
|
+
{/if}
|
|
271
274
|
</div>
|
|
272
275
|
|
|
273
276
|
<style>
|
|
@@ -27,6 +27,7 @@ declare const PanZoomPanel: $$__sveltets_2_IsomorphicComponent<{
|
|
|
27
27
|
onShortcutsToggle?: () => void;
|
|
28
28
|
shortcutsOpen?: boolean;
|
|
29
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;
|
|
30
31
|
showSaveButton?: boolean;
|
|
31
32
|
hasUnsavedChanges?: boolean;
|
|
32
33
|
onSave?: (() => void) | null;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { Portal } from '@widgetic/design-system';
|
|
5
5
|
import { canvasWarn } from './canvasLogger';
|
|
6
6
|
|
|
7
|
-
let { fabricCanvas, target, class: className = '', style = '' }: { fabricCanvas: Canvas; target: string; class?: string; style?: string } = $props();
|
|
7
|
+
let { fabricCanvas, target, advancedFeatures = true, class: className = '', style = '' }: { fabricCanvas: Canvas; target: string; advancedFeatures?: boolean; class?: string; style?: string } = $props();
|
|
8
8
|
let drawingCanvas: HTMLCanvasElement | null = null;
|
|
9
9
|
function captureDrawingCanvas(node: HTMLCanvasElement) {
|
|
10
10
|
drawingCanvas = node;
|
|
@@ -76,8 +76,8 @@
|
|
|
76
76
|
const retina = fabricCanvas.getRetinaScaling();
|
|
77
77
|
context.setTransform(retina, 0, 0, retina, 0, 0);
|
|
78
78
|
// Red primary stroke is part of the object, not the selection border.
|
|
79
|
-
//
|
|
80
|
-
if ((selected as any)._isPrimaryWidget && selected.strokeWidth) {
|
|
79
|
+
// The simple canvas hides it. Advanced paints it above the HTML preview.
|
|
80
|
+
if (advancedFeatures && (selected as any)._isPrimaryWidget && selected.strokeWidth) {
|
|
81
81
|
context.save();
|
|
82
82
|
context.transform(...fabricCanvas.viewportTransform);
|
|
83
83
|
context.transform(...selected.calcTransformMatrix());
|
|
@@ -93,14 +93,24 @@
|
|
|
93
93
|
// Fabric's internal control geometry (oCoords/controls) isn't on the
|
|
94
94
|
// public FabricObject type; this layer re-renders it as hit regions.
|
|
95
95
|
const sel = selected as any;
|
|
96
|
+
const hiddenWhenSimple = new Set(['ml', 'mr', 'mt', 'mb', 'mtr']);
|
|
96
97
|
controls = Object.entries(sel.oCoords || {}).flatMap(([key, position]: [string, any]) => {
|
|
97
98
|
const control = sel.controls[key];
|
|
99
|
+
if (!advancedFeatures && hiddenWhenSimple.has(key)) return [];
|
|
98
100
|
if (!sel.hasControls || !control?.getVisibility(sel, key)) return [];
|
|
99
101
|
const points = position.corner;
|
|
100
102
|
return [{ key, points: ['tl', 'tr', 'br', 'bl'].map(corner => `${points[corner].x * scaleX},${points[corner].y * scaleY}`).join(' '), cursor: control.cursorStyleHandler({}, control, sel) }];
|
|
101
103
|
});
|
|
102
104
|
}
|
|
103
105
|
|
|
106
|
+
// The board flips Advanced after this layer is already mounted. Repaint once
|
|
107
|
+
// the flag has landed, so a render that raced the prop does not leave the
|
|
108
|
+
// rotate handle or the red stroke up.
|
|
109
|
+
$effect(() => {
|
|
110
|
+
void advancedFeatures;
|
|
111
|
+
if (drawingCanvas) redraw();
|
|
112
|
+
});
|
|
113
|
+
|
|
104
114
|
onMount(() => {
|
|
105
115
|
let animationFrame = 0;
|
|
106
116
|
function scheduleRedraw() {
|