@widgetic/canvas 0.5.18 → 0.5.19
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 +110 -0
- package/dist/canvas/Canvas.svelte +174 -50
- package/dist/canvas/Canvas.svelte.d.ts +6 -0
- package/dist/canvas/CanvasToolbar.svelte +146 -178
- package/dist/canvas/CanvasToolbar.svelte.d.ts +2 -2
- package/dist/canvas/ContextMenu.svelte +52 -28
- package/dist/canvas/PanZoomPanel.svelte +32 -23
- package/dist/canvas/WidgetSelectionLayer.svelte +1 -1
- package/dist/canvas/eventScope.d.ts +56 -0
- package/dist/canvas/eventScope.js +89 -0
- package/dist/canvas/props-panel/PropsPanel.svelte +117 -146
- package/dist/canvas/props-panel/TextPropsICSection.svelte +18 -14
- package/dist/canvas/shadowRootText.d.ts +5 -0
- package/dist/canvas/shadowRootText.js +43 -0
- package/dist/canvas/shapes/FrameShape.js +4 -2
- package/dist/canvas/shapes/ImageShape.js +9 -11
- package/dist/canvas/shapes/ShapeLibrary.d.ts +3 -1
- package/dist/canvas/shapes/ShapeLibrary.js +26 -26
- package/dist/canvas/shapes/WidgetShape.js +6 -3
- package/dist/components/Tooltip.svelte +4 -1
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.js +4 -0
- package/dist/components/input-controls/ColorIC.svelte +15 -10
- package/dist/components/input-controls/ColorIC.svelte.d.ts +1 -1
- package/dist/components/input-controls/FontSelectorIC.svelte +12 -3
- package/dist/components/input-controls/SliderUnitIC.svelte +21 -7
- package/dist/components/input-controls/SliderUnitIC.svelte.d.ts +1 -1
- package/dist/components/input-controls/TextAlignIC.svelte +10 -5
- package/dist/components/input-controls/TextStyleIC.svelte +11 -7
- package/dist/components/preferenceStorage.d.ts +14 -0
- package/dist/components/preferenceStorage.js +25 -0
- package/dist/i18n/index.d.ts +2 -0
- package/dist/i18n/index.js +2 -0
- package/dist/i18n/labels.d.ts +23 -0
- package/dist/i18n/labels.js +75 -0
- package/dist/i18n/language.d.ts +23 -0
- package/dist/i18n/language.js +33 -0
- package/dist/i18n/messages.d.ts +277 -0
- package/dist/i18n/messages.js +292 -0
- package/dist/i18n/shapeWords.d.ts +30 -0
- package/dist/i18n/shapeWords.js +36 -0
- package/dist/i18n/shortcuts.d.ts +52 -0
- package/dist/i18n/shortcuts.js +104 -0
- package/dist/i18n/slots.d.ts +20 -0
- package/dist/i18n/slots.js +40 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/package.json +11 -2
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import ColorIC from '../../components/input-controls/ColorIC.svelte';
|
|
3
3
|
import SliderUnitIC from '../../components/input-controls/SliderUnitIC.svelte';
|
|
4
|
+
import { useCanvasLanguage } from '../../i18n/language.js';
|
|
5
|
+
|
|
6
|
+
// The words of the section, in the language of the canvas it is on (English when it is used on its own)
|
|
7
|
+
const { t } = useCanvasLanguage();
|
|
4
8
|
|
|
5
9
|
let className = '';
|
|
6
10
|
export { className as class };
|
|
@@ -53,7 +57,7 @@
|
|
|
53
57
|
|
|
54
58
|
{#if showFontSize}
|
|
55
59
|
<SliderUnitIC
|
|
56
|
-
label=
|
|
60
|
+
label={$t('canvas.field.fontSize')}
|
|
57
61
|
value={fontSize}
|
|
58
62
|
min={8}
|
|
59
63
|
max={120}
|
|
@@ -65,7 +69,7 @@
|
|
|
65
69
|
|
|
66
70
|
{#if showFontFamily}
|
|
67
71
|
<div class="prop-section">
|
|
68
|
-
<span class="prop-label">
|
|
72
|
+
<span class="prop-label">{$t('canvas.control.fontFamily')}</span>
|
|
69
73
|
<select
|
|
70
74
|
value={fontFamily}
|
|
71
75
|
onchange={handleFontFamilyChange}
|
|
@@ -80,28 +84,28 @@
|
|
|
80
84
|
|
|
81
85
|
{#if showTextStyle}
|
|
82
86
|
<div class="prop-section">
|
|
83
|
-
<span class="prop-label">
|
|
87
|
+
<span class="prop-label">{$t('canvas.control.textStyle')}</span>
|
|
84
88
|
<div class="text-style-buttons">
|
|
85
89
|
<button
|
|
86
90
|
class="style-btn {fontWeight === 'bold' ? 'active' : ''}"
|
|
87
91
|
onclick={() => onFontWeightChange(fontWeight === 'bold' ? 'normal' : 'bold')}
|
|
88
|
-
title=
|
|
92
|
+
title={$t('canvas.control.bold')}
|
|
89
93
|
>
|
|
90
|
-
<strong>
|
|
94
|
+
<strong>{$t('canvas.control.boldMark')}</strong>
|
|
91
95
|
</button>
|
|
92
96
|
<button
|
|
93
97
|
class="style-btn {fontStyle === 'italic' ? 'active' : ''}"
|
|
94
98
|
onclick={() => onFontStyleChange(fontStyle === 'italic' ? 'normal' : 'italic')}
|
|
95
|
-
title=
|
|
99
|
+
title={$t('canvas.control.italic')}
|
|
96
100
|
>
|
|
97
|
-
<em>
|
|
101
|
+
<em>{$t('canvas.control.italicMark')}</em>
|
|
98
102
|
</button>
|
|
99
103
|
<button
|
|
100
104
|
class="style-btn {underline ? 'active' : ''}"
|
|
101
105
|
onclick={() => onUnderlineChange(!underline)}
|
|
102
|
-
title=
|
|
106
|
+
title={$t('canvas.control.underline')}
|
|
103
107
|
>
|
|
104
|
-
<span style="text-decoration: underline">
|
|
108
|
+
<span style="text-decoration: underline">{$t('canvas.control.underlineMark')}</span>
|
|
105
109
|
</button>
|
|
106
110
|
</div>
|
|
107
111
|
</div>
|
|
@@ -109,22 +113,22 @@
|
|
|
109
113
|
|
|
110
114
|
{#if showTextAlign}
|
|
111
115
|
<div class="prop-section">
|
|
112
|
-
<span class="prop-label">
|
|
116
|
+
<span class="prop-label">{$t('canvas.control.textAlign')}</span>
|
|
113
117
|
<div class="align-buttons">
|
|
114
118
|
<button
|
|
115
119
|
class="align-btn {textAlign === 'left' ? 'active' : ''}"
|
|
116
120
|
onclick={() => onTextAlignChange('left')}
|
|
117
|
-
title=
|
|
121
|
+
title={$t('canvas.control.alignLeft')}
|
|
118
122
|
>⫷</button>
|
|
119
123
|
<button
|
|
120
124
|
class="align-btn {textAlign === 'center' ? 'active' : ''}"
|
|
121
125
|
onclick={() => onTextAlignChange('center')}
|
|
122
|
-
title=
|
|
126
|
+
title={$t('canvas.control.alignCenter')}
|
|
123
127
|
>☰</button>
|
|
124
128
|
<button
|
|
125
129
|
class="align-btn {textAlign === 'right' ? 'active' : ''}"
|
|
126
130
|
onclick={() => onTextAlignChange('right')}
|
|
127
|
-
title=
|
|
131
|
+
title={$t('canvas.control.alignRight')}
|
|
128
132
|
>⫸</button>
|
|
129
133
|
</div>
|
|
130
134
|
</div>
|
|
@@ -132,7 +136,7 @@
|
|
|
132
136
|
|
|
133
137
|
{#if showTextColor}
|
|
134
138
|
<ColorIC
|
|
135
|
-
label=
|
|
139
|
+
label={$t('canvas.field.textColor')}
|
|
136
140
|
value={textColor}
|
|
137
141
|
onChange={onTextColorChange}
|
|
138
142
|
/>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { IText } from 'fabric';
|
|
2
|
+
import { canvasLog } from './canvasLogger';
|
|
3
|
+
import { getShadowRootOf } from './eventScope';
|
|
4
|
+
let isInstalled = false;
|
|
5
|
+
/**
|
|
6
|
+
* Teaches the text objects of Fabric to keep their hidden text area inside the shadow root their canvas is in.
|
|
7
|
+
* Safe to call again: it only changes Fabric once.
|
|
8
|
+
*/
|
|
9
|
+
export function installTextareaInShadowRoot() {
|
|
10
|
+
if (isInstalled)
|
|
11
|
+
return;
|
|
12
|
+
isInstalled = true;
|
|
13
|
+
const textPrototype = IText.prototype;
|
|
14
|
+
const originalInitHiddenTextarea = textPrototype.initHiddenTextarea;
|
|
15
|
+
const originalCalcTextareaPosition = textPrototype._calcTextareaPosition;
|
|
16
|
+
/** Whether the hidden text area of this text is the one the canvas keeps in its own wrapper. */
|
|
17
|
+
const keptInWrapper = (text) => !!text.canvas?.wrapperEl && text.hiddenTextareaContainer === text.canvas.wrapperEl;
|
|
18
|
+
textPrototype.initHiddenTextarea = function () {
|
|
19
|
+
try {
|
|
20
|
+
const canvas = this.canvas;
|
|
21
|
+
if (!this.hiddenTextareaContainer && canvas?.wrapperEl && getShadowRootOf(canvas.getElement?.())) {
|
|
22
|
+
this.hiddenTextareaContainer = canvas.wrapperEl;
|
|
23
|
+
canvasLog('Canvas: the text being edited keeps its hidden text area inside the shadow root');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
console.warn('Canvas: could not choose a place for the hidden text area, Fabric will use the page', error);
|
|
28
|
+
}
|
|
29
|
+
originalInitHiddenTextarea.call(this);
|
|
30
|
+
};
|
|
31
|
+
textPrototype._calcTextareaPosition = function () {
|
|
32
|
+
const position = originalCalcTextareaPosition.call(this);
|
|
33
|
+
// Fabric adds the canvas's offset on the document to the position; the wrapper has its own origin, so it comes off again.
|
|
34
|
+
const offset = this.canvas?._offset;
|
|
35
|
+
if (!keptInWrapper(this) || !offset)
|
|
36
|
+
return position;
|
|
37
|
+
const left = Number.parseFloat(position.left);
|
|
38
|
+
const top = Number.parseFloat(position.top);
|
|
39
|
+
if (!Number.isFinite(left) || !Number.isFinite(top))
|
|
40
|
+
return position;
|
|
41
|
+
return { ...position, left: `${left - offset.left}px`, top: `${top - offset.top}px` };
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import { Group, Rect, Control, controlsUtils, util, LayoutManager, FixedLayout, classRegistry } from 'fabric';
|
|
21
21
|
import { canvasLog, canvasWarn } from '../canvasLogger';
|
|
22
|
+
import { shapeWordsOf } from '../../i18n/shapeWords.js';
|
|
22
23
|
// ─────────────────────────────────────────────
|
|
23
24
|
// Constants
|
|
24
25
|
// ─────────────────────────────────────────────
|
|
@@ -93,7 +94,8 @@ function wrapText(ctx, text, maxWidth) {
|
|
|
93
94
|
// Helper: Draw the label above the frame
|
|
94
95
|
// ─────────────────────────────────────────────
|
|
95
96
|
function renderFrameLabel(ctx, frame) {
|
|
96
|
-
|
|
97
|
+
// A frame with no name says "Frame", in the language of the canvas it is on
|
|
98
|
+
const text = frame._labelText || shapeWordsOf(frame.canvas).frameLabel;
|
|
97
99
|
const fontSize = frame._labelFontSize || DEFAULT_LABEL_FONT_SIZE;
|
|
98
100
|
const fontFamily = frame._labelFontFamily || DEFAULT_LABEL_FONT_FAMILY;
|
|
99
101
|
const textColor = frame._labelColor || DEFAULT_LABEL_COLOR;
|
|
@@ -236,7 +238,7 @@ classRegistry.setClass(FrameShape);
|
|
|
236
238
|
// Create a new FrameShape instance
|
|
237
239
|
// ─────────────────────────────────────────────
|
|
238
240
|
export function createFrameShape(options = {}) {
|
|
239
|
-
const { left = 0, top = 0, width = 200, height = 150, fill = DEFAULT_FILL, stroke = DEFAULT_STROKE, strokeWidth = DEFAULT_STROKE_WIDTH, labelText =
|
|
241
|
+
const { left = 0, top = 0, width = 200, height = 150, fill = DEFAULT_FILL, stroke = DEFAULT_STROKE, strokeWidth = DEFAULT_STROKE_WIDTH, labelText = shapeWordsOf(undefined).frameLabel, labelFontSize = DEFAULT_LABEL_FONT_SIZE, labelFontFamily = DEFAULT_LABEL_FONT_FAMILY, labelColor = DEFAULT_LABEL_COLOR, labelBackgroundColor = DEFAULT_LABEL_BG_COLOR, labelTextAlign = 'left', labelFontWeight = 'normal', labelFontStyle = 'normal', labelUnderline = false, } = options;
|
|
240
242
|
// Enforce minimum dimensions
|
|
241
243
|
const finalWidth = Math.max(width, MIN_FRAME_WIDTH);
|
|
242
244
|
const finalHeight = Math.max(height, MIN_FRAME_HEIGHT);
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import { Rect, classRegistry } from 'fabric';
|
|
15
15
|
import { canvasLog, canvasWarn } from '../canvasLogger';
|
|
16
|
+
import { shapeWordsOf } from '../../i18n/shapeWords.js';
|
|
16
17
|
// ── Custom property names for base ImageShape ─────────────────────────────────
|
|
17
18
|
export const IMAGE_SHAPE_CUSTOM_PROPS = [
|
|
18
19
|
'_customType',
|
|
@@ -225,7 +226,13 @@ export class ImageShape extends Rect {
|
|
|
225
226
|
const iconSize = 36;
|
|
226
227
|
const fontSize = 16;
|
|
227
228
|
const lineGap = fontSize + 6;
|
|
228
|
-
|
|
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);
|
|
229
236
|
const contentHeight = iconSize + 12 + lineGap * 2;
|
|
230
237
|
const contentScale = Math.max(0.7, Math.min((visualW * 0.88) / contentWidth, (visualH * 0.7) / contentHeight));
|
|
231
238
|
ctx.fillStyle = '#94a3b8';
|
|
@@ -236,16 +243,7 @@ export class ImageShape extends Rect {
|
|
|
236
243
|
ctx.font = `${iconSize}px Arial`;
|
|
237
244
|
ctx.fillText(this._customType === 'video' ? '🎬' : '🖼️', 0, -28);
|
|
238
245
|
ctx.font = `${fontSize}px Arial`;
|
|
239
|
-
|
|
240
|
-
ctx.fillText('Drop video', 0, 8);
|
|
241
|
-
ctx.fillText('or', 0, 8 + lineGap);
|
|
242
|
-
ctx.fillText('double click', 0, 8 + lineGap * 2);
|
|
243
|
-
}
|
|
244
|
-
else {
|
|
245
|
-
ctx.fillText('Drop image', 0, 8);
|
|
246
|
-
ctx.fillText('or', 0, 8 + lineGap);
|
|
247
|
-
ctx.fillText('double click', 0, 8 + lineGap * 2);
|
|
248
|
-
}
|
|
246
|
+
lines.forEach((line, lineIndex) => ctx.fillText(line, 0, 8 + lineGap * lineIndex));
|
|
249
247
|
ctx.restore();
|
|
250
248
|
ctx.restore();
|
|
251
249
|
}
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* 'strokeRound' – apply round linecap / linejoin (line-only: check, X, +, -)
|
|
11
11
|
* 'pathRegen' – regenerate sub-shape path data with rounded corners (rects & polygons)
|
|
12
12
|
*/
|
|
13
|
+
import type { CanvasMessageKey } from '../../i18n/messages.js';
|
|
13
14
|
export type CornerRadiusMode = 'none' | 'clipPath' | 'strokeRound' | 'pathRegen';
|
|
14
15
|
export type RegenSubShape = {
|
|
15
16
|
type: 'rect';
|
|
@@ -26,7 +27,8 @@ export type RegenSubShape = {
|
|
|
26
27
|
};
|
|
27
28
|
export interface LibraryShape {
|
|
28
29
|
key: string;
|
|
29
|
-
|
|
30
|
+
/** The message that names the shape (see i18n/messages.ts): the toolbar says it in the page's language. */
|
|
31
|
+
labelKey: CanvasMessageKey;
|
|
30
32
|
category: string;
|
|
31
33
|
pathData: string;
|
|
32
34
|
iconSvg: string;
|
|
@@ -208,7 +208,7 @@ export function generatePathForShape(shape, roundnessPercent) {
|
|
|
208
208
|
const GEOMETRIC_SHAPES = [
|
|
209
209
|
{
|
|
210
210
|
key: 'hexagon',
|
|
211
|
-
|
|
211
|
+
labelKey: 'canvas.shape.hexagon',
|
|
212
212
|
category: 'Geometric Shapes',
|
|
213
213
|
pathData: 'M 50 3 L 93 27 L 93 73 L 50 97 L 7 73 L 7 27 Z',
|
|
214
214
|
iconSvg: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><polygon points="12,2 21.5,7 21.5,17 12,22 2.5,17 2.5,7" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg>`,
|
|
@@ -220,7 +220,7 @@ const GEOMETRIC_SHAPES = [
|
|
|
220
220
|
},
|
|
221
221
|
{
|
|
222
222
|
key: 'oval',
|
|
223
|
-
|
|
223
|
+
labelKey: 'canvas.shape.oval',
|
|
224
224
|
category: 'Geometric Shapes',
|
|
225
225
|
// Capsule/stadium shape: wide rounded rect with max corner radius (half the height).
|
|
226
226
|
// 160×90 content area, corner radius = 45 (half of 90). Produces semicircle caps like a pill.
|
|
@@ -234,7 +234,7 @@ const GEOMETRIC_SHAPES = [
|
|
|
234
234
|
const MEDIA_SHAPES = [
|
|
235
235
|
{
|
|
236
236
|
key: 'play',
|
|
237
|
-
|
|
237
|
+
labelKey: 'canvas.shape.play',
|
|
238
238
|
category: 'Media Icons',
|
|
239
239
|
pathData: 'M 10 5 L 10 95 L 90 50 Z',
|
|
240
240
|
iconSvg: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><polygon points="5,3 5,21 20,12" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg>`,
|
|
@@ -245,7 +245,7 @@ const MEDIA_SHAPES = [
|
|
|
245
245
|
},
|
|
246
246
|
{
|
|
247
247
|
key: 'pause',
|
|
248
|
-
|
|
248
|
+
labelKey: 'canvas.shape.pause',
|
|
249
249
|
category: 'Media Icons',
|
|
250
250
|
pathData: 'M 15 5 L 15 95 L 35 95 L 35 5 Z M 65 5 L 65 95 L 85 95 L 85 5 Z',
|
|
251
251
|
iconSvg: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><rect x="6" y="4" width="4" height="16" rx="1" fill="none" stroke="currentColor" stroke-width="1.5"/><rect x="14" y="4" width="4" height="16" rx="1" fill="none" stroke="currentColor" stroke-width="1.5"/></svg>`,
|
|
@@ -257,7 +257,7 @@ const MEDIA_SHAPES = [
|
|
|
257
257
|
},
|
|
258
258
|
{
|
|
259
259
|
key: 'stop',
|
|
260
|
-
|
|
260
|
+
labelKey: 'canvas.shape.stop',
|
|
261
261
|
category: 'Media Icons',
|
|
262
262
|
pathData: 'M 10 10 L 10 90 L 90 90 L 90 10 Z',
|
|
263
263
|
iconSvg: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><rect x="5" y="5" width="14" height="14" rx="1.5" fill="none" stroke="currentColor" stroke-width="1.5"/></svg>`,
|
|
@@ -268,7 +268,7 @@ const MEDIA_SHAPES = [
|
|
|
268
268
|
},
|
|
269
269
|
{
|
|
270
270
|
key: 'rewind',
|
|
271
|
-
|
|
271
|
+
labelKey: 'canvas.shape.rewind',
|
|
272
272
|
category: 'Media Icons',
|
|
273
273
|
pathData: 'M 50 5 L 50 95 L 5 50 Z M 95 5 L 95 95 L 50 50 Z',
|
|
274
274
|
iconSvg: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><polygon points="12,3 12,21 3,12" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/><polygon points="21,3 21,21 12,12" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg>`,
|
|
@@ -280,7 +280,7 @@ const MEDIA_SHAPES = [
|
|
|
280
280
|
},
|
|
281
281
|
{
|
|
282
282
|
key: 'fast-forward',
|
|
283
|
-
|
|
283
|
+
labelKey: 'canvas.shape.fastForward',
|
|
284
284
|
category: 'Media Icons',
|
|
285
285
|
pathData: 'M 5 5 L 5 95 L 50 50 Z M 50 5 L 50 95 L 95 50 Z',
|
|
286
286
|
iconSvg: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><polygon points="3,3 3,21 12,12" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/><polygon points="12,3 12,21 21,12" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg>`,
|
|
@@ -292,7 +292,7 @@ const MEDIA_SHAPES = [
|
|
|
292
292
|
},
|
|
293
293
|
{
|
|
294
294
|
key: 'record',
|
|
295
|
-
|
|
295
|
+
labelKey: 'canvas.shape.record',
|
|
296
296
|
category: 'Media Icons',
|
|
297
297
|
// Already a circle — no corner rounding needed
|
|
298
298
|
pathData: 'M 50 5 A 45 45 0 1 1 49.999 5 Z',
|
|
@@ -304,7 +304,7 @@ const MEDIA_SHAPES = [
|
|
|
304
304
|
const ARROW_SHAPES = [
|
|
305
305
|
{
|
|
306
306
|
key: 'arrow-right',
|
|
307
|
-
|
|
307
|
+
labelKey: 'canvas.shape.arrowRight',
|
|
308
308
|
category: 'Arrow Shapes',
|
|
309
309
|
pathData: 'M 5 40 L 65 40 L 65 20 L 95 50 L 65 80 L 65 60 L 5 60 Z',
|
|
310
310
|
iconSvg: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><path d="M5 12 H19 M13 6 L19 12 L13 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>`,
|
|
@@ -313,7 +313,7 @@ const ARROW_SHAPES = [
|
|
|
313
313
|
},
|
|
314
314
|
{
|
|
315
315
|
key: 'arrow-left',
|
|
316
|
-
|
|
316
|
+
labelKey: 'canvas.shape.arrowLeft',
|
|
317
317
|
category: 'Arrow Shapes',
|
|
318
318
|
pathData: 'M 95 40 L 35 40 L 35 20 L 5 50 L 35 80 L 35 60 L 95 60 Z',
|
|
319
319
|
iconSvg: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><path d="M19 12 H5 M11 6 L5 12 L11 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>`,
|
|
@@ -322,7 +322,7 @@ const ARROW_SHAPES = [
|
|
|
322
322
|
},
|
|
323
323
|
{
|
|
324
324
|
key: 'arrow-up',
|
|
325
|
-
|
|
325
|
+
labelKey: 'canvas.shape.arrowUp',
|
|
326
326
|
category: 'Arrow Shapes',
|
|
327
327
|
pathData: 'M 40 95 L 40 35 L 20 35 L 50 5 L 80 35 L 60 35 L 60 95 Z',
|
|
328
328
|
iconSvg: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><path d="M12 19 V5 M6 11 L12 5 L18 11" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>`,
|
|
@@ -331,7 +331,7 @@ const ARROW_SHAPES = [
|
|
|
331
331
|
},
|
|
332
332
|
{
|
|
333
333
|
key: 'arrow-down',
|
|
334
|
-
|
|
334
|
+
labelKey: 'canvas.shape.arrowDown',
|
|
335
335
|
category: 'Arrow Shapes',
|
|
336
336
|
pathData: 'M 60 5 L 60 65 L 80 65 L 50 95 L 20 65 L 40 65 L 40 5 Z',
|
|
337
337
|
iconSvg: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><path d="M12 5 V19 M6 13 L12 19 L18 13" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>`,
|
|
@@ -340,7 +340,7 @@ const ARROW_SHAPES = [
|
|
|
340
340
|
},
|
|
341
341
|
{
|
|
342
342
|
key: 'double-arrow',
|
|
343
|
-
|
|
343
|
+
labelKey: 'canvas.shape.doubleArrow',
|
|
344
344
|
category: 'Arrow Shapes',
|
|
345
345
|
pathData: 'M 30 20 L 5 50 L 30 80 L 30 62 L 70 62 L 70 80 L 95 50 L 70 20 L 70 38 L 30 38 Z',
|
|
346
346
|
iconSvg: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><path d="M7 12 H17 M5 8 L1 12 L5 16 M19 8 L23 12 L19 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>`,
|
|
@@ -349,7 +349,7 @@ const ARROW_SHAPES = [
|
|
|
349
349
|
},
|
|
350
350
|
{
|
|
351
351
|
key: 'curved-arrow',
|
|
352
|
-
|
|
352
|
+
labelKey: 'canvas.shape.curvedArrow',
|
|
353
353
|
category: 'Arrow Shapes',
|
|
354
354
|
// Uses pathRegen mode: generatePathForShape() has a special case for 'curved-arrow'
|
|
355
355
|
// that rounds only the arrowhead tip via a Quadratic Bezier. clipPath was avoided
|
|
@@ -365,7 +365,7 @@ const ARROW_SHAPES = [
|
|
|
365
365
|
const UI_ICON_SHAPES = [
|
|
366
366
|
{
|
|
367
367
|
key: 'check',
|
|
368
|
-
|
|
368
|
+
labelKey: 'canvas.shape.checkMark',
|
|
369
369
|
category: 'UI Icons',
|
|
370
370
|
// Open path — round by setting strokeLineCap/strokeLineJoin
|
|
371
371
|
pathData: 'M 5 55 L 35 85 L 95 15',
|
|
@@ -374,7 +374,7 @@ const UI_ICON_SHAPES = [
|
|
|
374
374
|
},
|
|
375
375
|
{
|
|
376
376
|
key: 'cross',
|
|
377
|
-
|
|
377
|
+
labelKey: 'canvas.shape.cross',
|
|
378
378
|
category: 'UI Icons',
|
|
379
379
|
pathData: 'M 10 10 L 90 90 M 90 10 L 10 90',
|
|
380
380
|
iconSvg: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><path d="M5 5 L19 19 M19 5 L5 19" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>`,
|
|
@@ -382,7 +382,7 @@ const UI_ICON_SHAPES = [
|
|
|
382
382
|
},
|
|
383
383
|
{
|
|
384
384
|
key: 'plus',
|
|
385
|
-
|
|
385
|
+
labelKey: 'canvas.shape.plus',
|
|
386
386
|
category: 'UI Icons',
|
|
387
387
|
pathData: 'M 50 10 L 50 90 M 10 50 L 90 50',
|
|
388
388
|
iconSvg: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><path d="M12 5 V19 M5 12 H19" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>`,
|
|
@@ -390,7 +390,7 @@ const UI_ICON_SHAPES = [
|
|
|
390
390
|
},
|
|
391
391
|
{
|
|
392
392
|
key: 'minus',
|
|
393
|
-
|
|
393
|
+
labelKey: 'canvas.shape.minus',
|
|
394
394
|
category: 'UI Icons',
|
|
395
395
|
pathData: 'M 10 50 L 90 50',
|
|
396
396
|
iconSvg: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><path d="M5 12 H19" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>`,
|
|
@@ -398,7 +398,7 @@ const UI_ICON_SHAPES = [
|
|
|
398
398
|
},
|
|
399
399
|
{
|
|
400
400
|
key: 'info',
|
|
401
|
-
|
|
401
|
+
labelKey: 'canvas.shape.info',
|
|
402
402
|
category: 'UI Icons',
|
|
403
403
|
// Outer circle is already curved — no corner rounding
|
|
404
404
|
pathData: 'M 50 5 A 45 45 0 1 1 49.999 5 Z M 50 30 L 50 32 M 50 42 L 50 72',
|
|
@@ -407,7 +407,7 @@ const UI_ICON_SHAPES = [
|
|
|
407
407
|
},
|
|
408
408
|
{
|
|
409
409
|
key: 'warning',
|
|
410
|
-
|
|
410
|
+
labelKey: 'canvas.shape.warning',
|
|
411
411
|
category: 'UI Icons',
|
|
412
412
|
// Outer triangle + inner ! lines (inner lines kept fixed)
|
|
413
413
|
pathData: 'M 50 5 L 95 90 L 5 90 Z M 50 40 L 50 60 M 50 70 L 50 72',
|
|
@@ -423,7 +423,7 @@ const UI_ICON_SHAPES = [
|
|
|
423
423
|
const SYMBOL_SHAPES = [
|
|
424
424
|
{
|
|
425
425
|
key: 'star',
|
|
426
|
-
|
|
426
|
+
labelKey: 'canvas.shape.star',
|
|
427
427
|
category: 'Symbol Shapes',
|
|
428
428
|
pathData: 'M 50 5 L 61 35 L 95 35 L 68 57 L 79 91 L 50 70 L 21 91 L 32 57 L 5 35 L 39 35 Z',
|
|
429
429
|
iconSvg: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><polygon points="12,2 15.09,8.26 22,9.27 17,14.14 18.18,21.02 12,17.77 5.82,21.02 7,14.14 2,9.27 8.91,8.26" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg>`,
|
|
@@ -435,7 +435,7 @@ const SYMBOL_SHAPES = [
|
|
|
435
435
|
},
|
|
436
436
|
{
|
|
437
437
|
key: 'heart',
|
|
438
|
-
|
|
438
|
+
labelKey: 'canvas.shape.heart',
|
|
439
439
|
category: 'Symbol Shapes',
|
|
440
440
|
// Already curved — no corner rounding
|
|
441
441
|
pathData: 'M 50 85 C 5 55 5 20 25 15 C 35 12 45 17 50 25 C 55 17 65 12 75 15 C 95 20 95 55 50 85 Z',
|
|
@@ -444,7 +444,7 @@ const SYMBOL_SHAPES = [
|
|
|
444
444
|
},
|
|
445
445
|
{
|
|
446
446
|
key: 'speech-bubble',
|
|
447
|
-
|
|
447
|
+
labelKey: 'canvas.shape.speechBubble',
|
|
448
448
|
category: 'Symbol Shapes',
|
|
449
449
|
pathData: 'M 10 10 L 10 65 L 35 65 L 50 90 L 65 65 L 90 65 L 90 10 Z',
|
|
450
450
|
iconSvg: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><path d="M4 4 H20 A2 2 0 0 1 22 6 V15 A2 2 0 0 1 20 17 H9 L4 21 V17 A2 2 0 0 1 2 15 V6 A2 2 0 0 1 4 4 Z" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg>`,
|
|
@@ -458,7 +458,7 @@ const SYMBOL_SHAPES = [
|
|
|
458
458
|
},
|
|
459
459
|
{
|
|
460
460
|
key: 'diamond',
|
|
461
|
-
|
|
461
|
+
labelKey: 'canvas.shape.rhombus',
|
|
462
462
|
category: 'Symbol Shapes',
|
|
463
463
|
pathData: 'M 50 5 L 95 50 L 50 95 L 5 50 Z',
|
|
464
464
|
iconSvg: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><polygon points="12,2 22,12 12,22 2,12" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg>`,
|
|
@@ -470,7 +470,7 @@ const SYMBOL_SHAPES = [
|
|
|
470
470
|
},
|
|
471
471
|
{
|
|
472
472
|
key: 'lightning',
|
|
473
|
-
|
|
473
|
+
labelKey: 'canvas.shape.lightning',
|
|
474
474
|
category: 'Symbol Shapes',
|
|
475
475
|
pathData: 'M 55 5 L 20 52 L 45 52 L 38 95 L 80 42 L 55 42 Z',
|
|
476
476
|
iconSvg: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><path d="M13 2 L5 13 H11 L9 22 L19 9 H13 Z" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg>`,
|
|
@@ -482,7 +482,7 @@ const SYMBOL_SHAPES = [
|
|
|
482
482
|
},
|
|
483
483
|
{
|
|
484
484
|
key: 'shield',
|
|
485
|
-
|
|
485
|
+
labelKey: 'canvas.shape.shield',
|
|
486
486
|
category: 'Symbol Shapes',
|
|
487
487
|
pathData: 'M 50 5 L 90 20 L 90 55 C 90 75 70 90 50 95 C 30 90 10 75 10 55 L 10 20 Z',
|
|
488
488
|
iconSvg: `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><path d="M12 3 L20 7 V13 C20 17.5 16.5 21 12 22 C7.5 21 4 17.5 4 13 V7 Z" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg>`,
|
|
@@ -16,6 +16,7 @@ import { Rect, classRegistry } from 'fabric';
|
|
|
16
16
|
import { ImageShape, IMAGE_SHAPE_CUSTOM_PROPS } from './ImageShape';
|
|
17
17
|
import { canvasLog, canvasWarn } from '../canvasLogger';
|
|
18
18
|
import { getShapeImageStore, isInlineImageData, shapeImageRef } from './shapeImageStore';
|
|
19
|
+
import { shapeWordsOf } from '../../i18n/shapeWords.js';
|
|
19
20
|
// Widget-specific custom properties (on top of IMAGE_SHAPE_CUSTOM_PROPS)
|
|
20
21
|
export const WIDGET_SHAPE_EXTRA_PROPS = [
|
|
21
22
|
'_isWidgetImage',
|
|
@@ -111,14 +112,16 @@ export class WidgetShape extends ImageShape {
|
|
|
111
112
|
ctx.textAlign = 'center';
|
|
112
113
|
ctx.textBaseline = 'middle';
|
|
113
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);
|
|
114
117
|
// Widget icon
|
|
115
118
|
const iconSize = Math.min(48, availableH * 0.28);
|
|
116
119
|
ctx.font = `${iconSize}px Arial`;
|
|
117
120
|
ctx.fillText(isOrphaned ? '⚠️' : '🧩', 0, -availableH * 0.18);
|
|
118
121
|
// Widget name
|
|
119
122
|
const name = isOrphaned
|
|
120
|
-
?
|
|
121
|
-
: (this._widgetName ||
|
|
123
|
+
? words.unlinkedWidget
|
|
124
|
+
: (this._widgetName || words.widgetName);
|
|
122
125
|
const maxTextWidth = availableW - 24;
|
|
123
126
|
let fontSize = Math.max(11, Math.min(18, availableW * 0.06));
|
|
124
127
|
ctx.font = `600 ${fontSize}px system-ui, -apple-system, sans-serif`;
|
|
@@ -134,7 +137,7 @@ export class WidgetShape extends ImageShape {
|
|
|
134
137
|
// Subtitle
|
|
135
138
|
ctx.font = `400 ${Math.max(10, fontSize - 3)}px system-ui, -apple-system, sans-serif`;
|
|
136
139
|
ctx.fillStyle = '#64748b';
|
|
137
|
-
ctx.fillText(isOrphaned ?
|
|
140
|
+
ctx.fillText(isOrphaned ? words.removeFromCanvas : words.widgetPreview, 0, availableH * 0.06 + fontSize + 6);
|
|
138
141
|
ctx.restore();
|
|
139
142
|
}
|
|
140
143
|
// ── Serialisation ─────────────────────────────────────────────────────────
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* causing mis-positioning).
|
|
14
14
|
*/
|
|
15
15
|
import { onDestroy } from 'svelte';
|
|
16
|
+
import { getTransientHostFor } from '../canvas/eventScope';
|
|
16
17
|
|
|
17
18
|
// Tooltip label
|
|
18
19
|
export let text: string = '';
|
|
@@ -42,7 +43,9 @@
|
|
|
42
43
|
|
|
43
44
|
tooltipBodyEl = document.createElement('div');
|
|
44
45
|
arrowBodyEl = document.createElement('div');
|
|
45
|
-
|
|
46
|
+
// The page's <body> — or, for a tooltip in a shadow root (a partner's page), the shadow root itself, which is as
|
|
47
|
+
// high as it can go there and leaves the partner's <body> alone.
|
|
48
|
+
getTransientHostFor(triggerEl).appendChild(tooltipBodyEl);
|
|
46
49
|
|
|
47
50
|
// Base tooltip styles
|
|
48
51
|
Object.assign(tooltipBodyEl.style, {
|
|
@@ -4,8 +4,11 @@
|
|
|
4
4
|
* Import: import { Tooltip, ColorIC } from '@widgetic/canvas/components';
|
|
5
5
|
*/
|
|
6
6
|
export { default as Tooltip } from './Tooltip.svelte';
|
|
7
|
+
export { setCanvasPreferenceStorage, getCanvasPreferenceStorage } from './preferenceStorage';
|
|
8
|
+
export type { CanvasPreferenceStorage } from './preferenceStorage';
|
|
7
9
|
export { default as ColorIC } from './input-controls/ColorIC.svelte';
|
|
8
10
|
export { default as FontSelectorIC } from './input-controls/FontSelectorIC.svelte';
|
|
9
11
|
export { default as SliderUnitIC } from './input-controls/SliderUnitIC.svelte';
|
|
10
12
|
export { default as TextAlignIC } from './input-controls/TextAlignIC.svelte';
|
|
11
13
|
export { default as TextStyleIC } from './input-controls/TextStyleIC.svelte';
|
|
14
|
+
export { provideCanvasLanguage, useCanvasLanguage } from '../i18n/index.js';
|
package/dist/components/index.js
CHANGED
|
@@ -5,9 +5,13 @@
|
|
|
5
5
|
*/
|
|
6
6
|
// General Components
|
|
7
7
|
export { default as Tooltip } from './Tooltip.svelte';
|
|
8
|
+
// Where the canvas keeps a visitor's choices (the host can install a store of its own)
|
|
9
|
+
export { setCanvasPreferenceStorage, getCanvasPreferenceStorage } from './preferenceStorage';
|
|
8
10
|
// Input Controllers
|
|
9
11
|
export { default as ColorIC } from './input-controls/ColorIC.svelte';
|
|
10
12
|
export { default as FontSelectorIC } from './input-controls/FontSelectorIC.svelte';
|
|
11
13
|
export { default as SliderUnitIC } from './input-controls/SliderUnitIC.svelte';
|
|
12
14
|
export { default as TextAlignIC } from './input-controls/TextAlignIC.svelte';
|
|
13
15
|
export { default as TextStyleIC } from './input-controls/TextStyleIC.svelte';
|
|
16
|
+
// The language of a part used on its own: give it one with provideCanvasLanguage, or it speaks English
|
|
17
|
+
export { provideCanvasLanguage, useCanvasLanguage } from '../i18n/index.js';
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { onMount } from 'svelte';
|
|
3
|
+
import { getCanvasPreferenceStorage } from '../preferenceStorage';
|
|
4
|
+
import { useCanvasLanguage } from '../../i18n/language.js';
|
|
5
|
+
|
|
6
|
+
// The words of the control, in the language of the canvas it is on (English when it is used on its own)
|
|
7
|
+
const { t } = useCanvasLanguage();
|
|
3
8
|
|
|
4
9
|
let className = '';
|
|
5
10
|
export { className as class };
|
|
@@ -8,8 +13,8 @@
|
|
|
8
13
|
// Current color value
|
|
9
14
|
export let value: string = '#000000';
|
|
10
15
|
|
|
11
|
-
// Label for the color picker
|
|
12
|
-
export let label: string =
|
|
16
|
+
// Label for the color picker. Without one it says "Color", in the page's language.
|
|
17
|
+
export let label: string | null = null;
|
|
13
18
|
|
|
14
19
|
// Callback when color changes
|
|
15
20
|
export let onChange: (color: string) => void = () => {};
|
|
@@ -94,10 +99,10 @@
|
|
|
94
99
|
return `#${toHex(r)}${toHex(g)}${toHex(b)}`.toUpperCase();
|
|
95
100
|
}
|
|
96
101
|
|
|
97
|
-
// Load custom presets from localStorage on mount
|
|
102
|
+
// Load custom presets from the preference store (localStorage unless the host installed another) on mount
|
|
98
103
|
onMount(() => {
|
|
99
104
|
try {
|
|
100
|
-
const stored =
|
|
105
|
+
const stored = getCanvasPreferenceStorage()?.getItem(PRESETS_STORAGE_KEY);
|
|
101
106
|
if (stored) {
|
|
102
107
|
customPresets = JSON.parse(stored);
|
|
103
108
|
}
|
|
@@ -106,10 +111,10 @@
|
|
|
106
111
|
}
|
|
107
112
|
});
|
|
108
113
|
|
|
109
|
-
// Save custom presets to
|
|
114
|
+
// Save custom presets to the preference store
|
|
110
115
|
function saveCustomPresets() {
|
|
111
116
|
try {
|
|
112
|
-
|
|
117
|
+
getCanvasPreferenceStorage()?.setItem(PRESETS_STORAGE_KEY, JSON.stringify(customPresets));
|
|
113
118
|
} catch (e) {
|
|
114
119
|
console.warn('ColorPicker: Failed to save custom presets', e);
|
|
115
120
|
}
|
|
@@ -197,7 +202,7 @@
|
|
|
197
202
|
</script>
|
|
198
203
|
|
|
199
204
|
<div class="{className ? className + ' ' : ''}color-picker-component" style={style}>
|
|
200
|
-
<span class="prop-label">{label}</span>
|
|
205
|
+
<span class="prop-label">{label ?? $t('canvas.control.color')}</span>
|
|
201
206
|
|
|
202
207
|
{#if showPicker}
|
|
203
208
|
<div class="color-input-row">
|
|
@@ -207,7 +212,7 @@
|
|
|
207
212
|
oninput={handleColorPickerInput}
|
|
208
213
|
onchange={handleColorPickerChange}
|
|
209
214
|
class="color-swatch"
|
|
210
|
-
title=
|
|
215
|
+
title={$t('canvas.control.openPicker')}
|
|
211
216
|
/>
|
|
212
217
|
<input
|
|
213
218
|
type="text"
|
|
@@ -235,7 +240,7 @@
|
|
|
235
240
|
{#if !presets && isCustomPreset(color)}
|
|
236
241
|
<button
|
|
237
242
|
class="delete-btn"
|
|
238
|
-
title=
|
|
243
|
+
title={$t('canvas.control.removeColor')}
|
|
239
244
|
onclick={(e) => handleDeletePreset(e, color)}
|
|
240
245
|
>×</button>
|
|
241
246
|
{/if}
|
|
@@ -360,7 +365,7 @@
|
|
|
360
365
|
.delete-btn {
|
|
361
366
|
position: absolute;
|
|
362
367
|
top: -4px;
|
|
363
|
-
|
|
368
|
+
inset-inline-end: -4px;
|
|
364
369
|
width: 14px;
|
|
365
370
|
height: 14px;
|
|
366
371
|
padding: 0;
|