@widgetic/canvas 0.5.18 → 0.5.20

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.
Files changed (48) hide show
  1. package/README.md +110 -0
  2. package/dist/canvas/Canvas.svelte +174 -50
  3. package/dist/canvas/Canvas.svelte.d.ts +6 -0
  4. package/dist/canvas/CanvasToolbar.svelte +146 -178
  5. package/dist/canvas/CanvasToolbar.svelte.d.ts +2 -2
  6. package/dist/canvas/ContextMenu.svelte +52 -28
  7. package/dist/canvas/PanZoomPanel.svelte +32 -23
  8. package/dist/canvas/WidgetSelectionLayer.svelte +1 -1
  9. package/dist/canvas/eventScope.d.ts +56 -0
  10. package/dist/canvas/eventScope.js +89 -0
  11. package/dist/canvas/props-panel/PropsPanel.svelte +117 -146
  12. package/dist/canvas/props-panel/TextPropsICSection.svelte +18 -14
  13. package/dist/canvas/shadowRootText.d.ts +5 -0
  14. package/dist/canvas/shadowRootText.js +43 -0
  15. package/dist/canvas/shapes/FrameShape.js +4 -2
  16. package/dist/canvas/shapes/ImageShape.js +9 -11
  17. package/dist/canvas/shapes/ShapeLibrary.d.ts +3 -1
  18. package/dist/canvas/shapes/ShapeLibrary.js +26 -26
  19. package/dist/canvas/shapes/WidgetShape.js +6 -3
  20. package/dist/components/Tooltip.svelte +4 -1
  21. package/dist/components/index.d.ts +3 -0
  22. package/dist/components/index.js +4 -0
  23. package/dist/components/input-controls/ColorIC.svelte +15 -10
  24. package/dist/components/input-controls/ColorIC.svelte.d.ts +1 -1
  25. package/dist/components/input-controls/FontSelectorIC.svelte +12 -3
  26. package/dist/components/input-controls/SliderUnitIC.svelte +21 -7
  27. package/dist/components/input-controls/SliderUnitIC.svelte.d.ts +1 -1
  28. package/dist/components/input-controls/TextAlignIC.svelte +10 -5
  29. package/dist/components/input-controls/TextStyleIC.svelte +11 -7
  30. package/dist/components/preferenceStorage.d.ts +14 -0
  31. package/dist/components/preferenceStorage.js +25 -0
  32. package/dist/i18n/index.d.ts +2 -0
  33. package/dist/i18n/index.js +2 -0
  34. package/dist/i18n/labels.d.ts +23 -0
  35. package/dist/i18n/labels.js +75 -0
  36. package/dist/i18n/language.d.ts +23 -0
  37. package/dist/i18n/language.js +33 -0
  38. package/dist/i18n/messages.d.ts +277 -0
  39. package/dist/i18n/messages.js +292 -0
  40. package/dist/i18n/shapeWords.d.ts +30 -0
  41. package/dist/i18n/shapeWords.js +36 -0
  42. package/dist/i18n/shortcuts.d.ts +52 -0
  43. package/dist/i18n/shortcuts.js +104 -0
  44. package/dist/i18n/slots.d.ts +20 -0
  45. package/dist/i18n/slots.js +40 -0
  46. package/dist/index.d.ts +4 -0
  47. package/dist/index.js +5 -0
  48. package/package.json +11 -2
@@ -0,0 +1,52 @@
1
+ import type { Translate } from '@widgetic/design-system/i18n';
2
+ import type { CanvasMessageKey } from './messages.js';
3
+ type Translator = Translate<CanvasMessageKey>;
4
+ /**
5
+ * The key that chooses each tool. The hints of the toolbar and the list of keyboard shortcuts read the same letters, so
6
+ * the two cannot disagree. A letter is the same on every keyboard, so it is not a message.
7
+ */
8
+ export declare const TOOL_KEYS: {
9
+ readonly select: "V";
10
+ readonly hand: "H";
11
+ readonly erase: "E";
12
+ readonly draw: "D";
13
+ readonly arrow: "A";
14
+ readonly rectangle: "R";
15
+ readonly triangle: "G";
16
+ readonly ellipse: "O";
17
+ readonly frame: "F";
18
+ readonly text: "T";
19
+ readonly image: "I";
20
+ };
21
+ /**
22
+ * One key of a shortcut: a key that is a word (a message, so a language can write "Strg" for "Ctrl"), a key cap that
23
+ * reads the same everywhere ("V", "↑", "]"), or `null` for the "+" that is drawn between two keys (a `null` rather than
24
+ * "+" so the "+" key itself can be a key cap).
25
+ */
26
+ export type ShortcutKey = {
27
+ name: CanvasMessageKey;
28
+ } | {
29
+ cap: string;
30
+ } | null;
31
+ export interface ShortcutDefinition {
32
+ keys: readonly ShortcutKey[];
33
+ label: CanvasMessageKey;
34
+ }
35
+ export interface ShortcutGroupDefinition {
36
+ title: CanvasMessageKey;
37
+ shortcuts: readonly ShortcutDefinition[];
38
+ }
39
+ /** The keyboard shortcuts of the canvas, in the order of the list that opens with "?". */
40
+ export declare const SHORTCUT_GROUPS: readonly ShortcutGroupDefinition[];
41
+ /** What the list of shortcuts draws: a key is the text of a key cap, and `null` is the "+" between two keys. */
42
+ export interface ShortcutRow {
43
+ label: string;
44
+ keys: (string | null)[];
45
+ }
46
+ export interface ShortcutGroup {
47
+ title: string;
48
+ shortcuts: ShortcutRow[];
49
+ }
50
+ /** The list of keyboard shortcuts in the page's language. */
51
+ export declare function shortcutGroups(t: Translator): ShortcutGroup[];
52
+ export {};
@@ -0,0 +1,104 @@
1
+ /**
2
+ * The key that chooses each tool. The hints of the toolbar and the list of keyboard shortcuts read the same letters, so
3
+ * the two cannot disagree. A letter is the same on every keyboard, so it is not a message.
4
+ */
5
+ export const TOOL_KEYS = {
6
+ select: 'V',
7
+ hand: 'H',
8
+ erase: 'E',
9
+ draw: 'D',
10
+ arrow: 'A',
11
+ rectangle: 'R',
12
+ triangle: 'G',
13
+ ellipse: 'O',
14
+ frame: 'F',
15
+ text: 'T',
16
+ image: 'I'
17
+ };
18
+ const named = (name) => ({ name });
19
+ const cap = (text) => ({ cap: text });
20
+ const PLUS = null;
21
+ const CTRL = named('canvas.key.ctrlCmd');
22
+ const ALT = named('canvas.key.alt');
23
+ const SHIFT = named('canvas.key.shift');
24
+ /** The keyboard shortcuts of the canvas, in the order of the list that opens with "?". */
25
+ export const SHORTCUT_GROUPS = [
26
+ {
27
+ title: 'canvas.shortcuts.groupTools',
28
+ shortcuts: [
29
+ { keys: [cap(TOOL_KEYS.select)], label: 'canvas.tool.select' },
30
+ { keys: [cap(TOOL_KEYS.hand)], label: 'canvas.tool.hand' },
31
+ { keys: [cap(TOOL_KEYS.erase)], label: 'canvas.tool.erase' },
32
+ { keys: [cap(TOOL_KEYS.draw)], label: 'canvas.tool.draw' },
33
+ { keys: [cap(TOOL_KEYS.arrow)], label: 'canvas.tool.arrow' },
34
+ { keys: [cap(TOOL_KEYS.rectangle)], label: 'canvas.tool.rectangle' },
35
+ { keys: [cap(TOOL_KEYS.triangle)], label: 'canvas.tool.triangle' },
36
+ { keys: [cap(TOOL_KEYS.ellipse)], label: 'canvas.tool.ellipse' },
37
+ { keys: [cap(TOOL_KEYS.frame)], label: 'canvas.tool.frame' },
38
+ { keys: [cap(TOOL_KEYS.text)], label: 'canvas.tool.text' },
39
+ { keys: [cap(TOOL_KEYS.image)], label: 'canvas.tool.image' }
40
+ ]
41
+ },
42
+ {
43
+ title: 'canvas.shortcuts.groupSelection',
44
+ shortcuts: [
45
+ { keys: [CTRL, PLUS, cap('A')], label: 'canvas.action.selectAll' },
46
+ { keys: [ALT, PLUS, named('canvas.key.click')], label: 'canvas.shortcuts.drillThrough' },
47
+ { keys: [CTRL, PLUS, cap('D')], label: 'canvas.action.duplicate' },
48
+ { keys: [CTRL, PLUS, cap('C')], label: 'canvas.action.copy' },
49
+ { keys: [CTRL, PLUS, cap('V')], label: 'canvas.action.paste' },
50
+ { keys: [named('canvas.key.delete')], label: 'canvas.action.delete' },
51
+ { keys: [CTRL, PLUS, cap('G')], label: 'canvas.action.group' },
52
+ { keys: [CTRL, PLUS, SHIFT, PLUS, cap('G')], label: 'canvas.action.ungroup' }
53
+ ]
54
+ },
55
+ {
56
+ title: 'canvas.shortcuts.groupHistory',
57
+ shortcuts: [
58
+ { keys: [CTRL, PLUS, cap('Z')], label: 'canvas.tool.undo' },
59
+ { keys: [CTRL, PLUS, SHIFT, PLUS, cap('Z')], label: 'canvas.tool.redo' },
60
+ { keys: [CTRL, PLUS, cap('Y')], label: 'canvas.shortcuts.redoAlt' },
61
+ { keys: [CTRL, PLUS, cap('S')], label: 'canvas.shortcuts.save' }
62
+ ]
63
+ },
64
+ {
65
+ title: 'canvas.shortcuts.groupZoom',
66
+ shortcuts: [
67
+ // The last "+" here is the key itself; the PLUS before it is the sign between the two keys
68
+ { keys: [CTRL, PLUS, cap('+')], label: 'canvas.shortcuts.zoomIn' },
69
+ { keys: [CTRL, PLUS, cap('−')], label: 'canvas.shortcuts.zoomOut' },
70
+ { keys: [CTRL, PLUS, cap('0')], label: 'canvas.shortcuts.zoomReset' },
71
+ { keys: [CTRL, PLUS, cap('9')], label: 'canvas.shortcuts.fit' },
72
+ { keys: [named('canvas.key.space'), PLUS, named('canvas.key.drag')], label: 'canvas.shortcuts.pan' },
73
+ // The four arrow keys are four key caps next to each other, with no sign between them
74
+ { keys: [cap('↑'), cap('↓'), cap('←'), cap('→')], label: 'canvas.shortcuts.move1' },
75
+ { keys: [SHIFT, PLUS, cap('↑'), cap('↓'), cap('←'), cap('→')], label: 'canvas.shortcuts.move10' }
76
+ ]
77
+ },
78
+ {
79
+ title: 'canvas.layer.title',
80
+ shortcuts: [
81
+ { keys: [cap(']')], label: 'canvas.layer.forward' },
82
+ { keys: [cap('[')], label: 'canvas.layer.backward' },
83
+ { keys: [CTRL, PLUS, cap(']')], label: 'canvas.layer.front' },
84
+ { keys: [CTRL, PLUS, cap('[')], label: 'canvas.layer.back' }
85
+ ]
86
+ },
87
+ {
88
+ title: 'canvas.tool.frame',
89
+ shortcuts: [
90
+ { keys: [ALT, PLUS, named('canvas.key.dragCorner')], label: 'canvas.shortcuts.frameResize' },
91
+ { keys: [named('canvas.key.doubleClick')], label: 'canvas.shortcuts.frameEdit' }
92
+ ]
93
+ }
94
+ ];
95
+ /** The list of keyboard shortcuts in the page's language. */
96
+ export function shortcutGroups(t) {
97
+ return SHORTCUT_GROUPS.map((group) => ({
98
+ title: t(group.title),
99
+ shortcuts: group.shortcuts.map((shortcut) => ({
100
+ label: t(shortcut.label),
101
+ keys: shortcut.keys.map((key) => (key === null ? null : 'name' in key ? t(key.name) : key.cap))
102
+ }))
103
+ }));
104
+ }
@@ -0,0 +1,20 @@
1
+ import type { Translate } from '@widgetic/design-system/i18n';
2
+ import type { CanvasMessageKey } from './messages.js';
3
+ /** A piece of a sentence that has markup inside it: plain text, or the place of one of its named parts. */
4
+ export type SentencePart = {
5
+ text: string;
6
+ } | {
7
+ slot: string;
8
+ };
9
+ /**
10
+ * Cuts a translated sentence into plain text and the places of its named parts. For a sentence that has markup inside
11
+ * it, such as a key shown as a key cap: the page's translation says where each part goes (`{key}`), so a language can
12
+ * put the parts in the order it needs, and the screen draws each part itself.
13
+ *
14
+ * sentenceParts('canvas.shortcuts.footer', ['key', 'hint', 'icon'], t)
15
+ * // → [{ text: 'Press ' }, { slot: 'key' }, { text: ' ' }, { slot: 'hint' }, { text: ' or click ' }, …]
16
+ *
17
+ * A part the translation leaves out is simply not in the list; a `{name}` that is not one of `slotNames` is shown as it
18
+ * is written, like any other message.
19
+ */
20
+ export declare function sentenceParts(key: CanvasMessageKey, slotNames: readonly string[], t: Translate<CanvasMessageKey>): SentencePart[];
@@ -0,0 +1,40 @@
1
+ // Two characters a translator never types (private use): they mark where a slot starts and ends, so the finished sentence
2
+ // can be cut there again. Two different marks, so a stray one in a translation cannot swallow the slot next to it.
3
+ const SLOT_OPEN = '\uE000';
4
+ const SLOT_CLOSE = '\uE001';
5
+ /**
6
+ * Cuts a translated sentence into plain text and the places of its named parts. For a sentence that has markup inside
7
+ * it, such as a key shown as a key cap: the page's translation says where each part goes (`{key}`), so a language can
8
+ * put the parts in the order it needs, and the screen draws each part itself.
9
+ *
10
+ * sentenceParts('canvas.shortcuts.footer', ['key', 'hint', 'icon'], t)
11
+ * // → [{ text: 'Press ' }, { slot: 'key' }, { text: ' ' }, { slot: 'hint' }, { text: ' or click ' }, …]
12
+ *
13
+ * A part the translation leaves out is simply not in the list; a `{name}` that is not one of `slotNames` is shown as it
14
+ * is written, like any other message.
15
+ */
16
+ export function sentenceParts(key, slotNames, t) {
17
+ const values = {};
18
+ for (const name of slotNames)
19
+ values[name] = `${SLOT_OPEN}${name}${SLOT_CLOSE}`;
20
+ const sentence = t(key, values);
21
+ const parts = [];
22
+ const slotPattern = new RegExp(`${SLOT_OPEN}([^${SLOT_OPEN}${SLOT_CLOSE}]*)${SLOT_CLOSE}`, 'g');
23
+ let textFrom = 0;
24
+ for (const found of sentence.matchAll(slotPattern)) {
25
+ // Something between the two marks that is not one of our parts was typed by the translator: it stays text
26
+ if (!slotNames.includes(found[1]))
27
+ continue;
28
+ const at = found.index ?? 0;
29
+ if (at > textFrom)
30
+ parts.push({ text: sentence.slice(textFrom, at) });
31
+ parts.push({ slot: found[1] });
32
+ textFrom = at + found[0].length;
33
+ }
34
+ if (textFrom < sentence.length)
35
+ parts.push({ text: sentence.slice(textFrom) });
36
+ // A mark that was somehow in the translation itself is not part of any text (and a text that was only that is no text)
37
+ return parts
38
+ .map((part) => ('text' in part ? { text: part.text.split(SLOT_OPEN).join('').split(SLOT_CLOSE).join('') } : part))
39
+ .filter((part) => !('text' in part) || part.text !== '');
40
+ }
package/dist/index.d.ts CHANGED
@@ -11,3 +11,7 @@ export type { WidgetConversionPayload, StrokeRecognizer, StrokeRecognitionReques
11
11
  export { setShapeImageStore, getShapeImageStore } from './canvas';
12
12
  export type { ShapeImageStore } from './canvas';
13
13
  export { Tooltip, ColorIC, FontSelectorIC, SliderUnitIC, TextAlignIC, TextStyleIC } from './components';
14
+ export { setCanvasPreferenceStorage, getCanvasPreferenceStorage } from './components';
15
+ export type { CanvasPreferenceStorage } from './components';
16
+ export { CANVAS_MESSAGES, checkCanvasMessages, provideCanvasLanguage, useCanvasLanguage } from './i18n/index.js';
17
+ export type { CanvasMessageKey } from './i18n/index.js';
package/dist/index.js CHANGED
@@ -12,3 +12,8 @@ export { Canvas, CanvasToolbar, ContextMenu, PanZoomPanel, PropsPanel } from './
12
12
  export { setShapeImageStore, getShapeImageStore } from './canvas';
13
13
  // Lightweight components (safe for static import)
14
14
  export { Tooltip, ColorIC, FontSelectorIC, SliderUnitIC, TextAlignIC, TextStyleIC } from './components';
15
+ // The visitor's choices (saved colors) live in localStorage unless the host installs a store of its own
16
+ export { setCanvasPreferenceStorage, getCanvasPreferenceStorage } from './components';
17
+ // The words of the canvas: a page gives `locale` and `messages` to <Canvas>. These name every message, check a page's
18
+ // messages, and let a part used on its own (such as the colour control) speak a language too.
19
+ export { CANVAS_MESSAGES, checkCanvasMessages, provideCanvasLanguage, useCanvasLanguage } from './i18n/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/canvas",
3
- "version": "0.5.18",
3
+ "version": "0.5.20",
4
4
  "type": "module",
5
5
  "svelte": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -26,6 +26,11 @@
26
26
  "svelte": "./dist/components/index.js",
27
27
  "default": "./dist/components/index.js"
28
28
  },
29
+ "./i18n": {
30
+ "types": "./dist/i18n/index.d.ts",
31
+ "svelte": "./dist/i18n/index.js",
32
+ "default": "./dist/i18n/index.js"
33
+ },
29
34
  "./icons/*": {
30
35
  "types": "./dist/icons/*.d.ts",
31
36
  "svelte": "./dist/icons/*.js",
@@ -47,7 +52,7 @@
47
52
  "build": "vite build && npm run package",
48
53
  "package": "NODE_ENV=production svelte-package",
49
54
  "package:watch": "NODE_ENV=development svelte-package --watch",
50
- "test": "node --test \"scripts/*.test.ts\"",
55
+ "test": "node --test \"scripts/*.test.ts\" \"tests/*.test.mjs\"",
51
56
  "preview": "vite preview",
52
57
  "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
53
58
  "check:peers": "check-design-system-peers ..",
@@ -87,6 +92,10 @@
87
92
  "fabric": "^6.6.5",
88
93
  "tailwindcss-animate": "^1.0.7"
89
94
  },
95
+ "overrides": {
96
+ "form-data": "^4.0.6",
97
+ "tar": "^7.5.22"
98
+ },
90
99
  "volta": {
91
100
  "node": "22.14.0",
92
101
  "npm": "11.1.0"