@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.
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
package/README.md CHANGED
@@ -37,6 +37,116 @@ You can preview the production build with `npm run preview`.
37
37
 
38
38
  > To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
39
39
 
40
+ ## Languages
41
+
42
+ The canvas shows English until it is told otherwise. Two props of `Canvas` change that, and both can change while the
43
+ canvas is open:
44
+
45
+ ```svelte
46
+ <Canvas
47
+ locale="de"
48
+ messages={{
49
+ 'canvas.tool.draw': 'Zeichnen',
50
+ 'canvas.tool.undoTitle': 'Rückgängig (Strg+Z)',
51
+ 'canvas.zoom.expandTitle': 'Zoom {percent} % — zum Erweitern klicken',
52
+ }}
53
+ />
54
+ ```
55
+
56
+ - **`locale`** is a BCP 47 language tag (`de`, `pt-BR`, `ar-EG`). It decides the plural rules and how numbers are written,
57
+ all through `Intl`. It translates nothing. Blank or left out is English. A tag the browser does not know is said once
58
+ in the console and numbers stay English.
59
+ - **`messages`** replaces words. Every word the canvas shows is a message with a key; give the keys you want to change
60
+ and every key you leave out stays English, so a language can be added one screen at a time. A key that does not exist
61
+ is ignored and the console says which key you probably meant.
62
+
63
+ `CANVAS_MESSAGES` is the list: an object of every key and its English text, and it is the list to hand to a translator:
64
+
65
+ ```ts
66
+ import { CANVAS_MESSAGES } from '@widgetic/canvas';
67
+
68
+ console.log(Object.keys(CANVAS_MESSAGES).length); // every word of the canvas
69
+ console.log(CANVAS_MESSAGES['canvas.zoom.expandTitle']); // 'Zoom {percent}% — click to expand'
70
+ ```
71
+
72
+ A page that loads the canvas on demand can read the words without loading it: `@widgetic/canvas/i18n` has
73
+ `CANVAS_MESSAGES` and `checkCanvasMessages` and nothing else, so it brings the translator and the list of words, not
74
+ `Canvas.svelte` or the drawing library.
75
+
76
+ | Keys start with | The words of |
77
+ | --- | --- |
78
+ | `canvas.state.`, `canvas.error.` | "Loading canvas…", the line when the canvas could not start, and the dialog when a picture cannot be loaded from an address |
79
+ | `canvas.defaults.`, `canvas.draw.` | what new things start with ("Hello World!", "Type here", "Frame"), and the words drawn onto an empty image or video and onto a widget with no picture |
80
+ | `canvas.tool.`, `canvas.menu.`, `canvas.category.`, `canvas.shape.` | the toolbar: the tools and their hints, the menu of shapes, its groups, and the name of every shape in it |
81
+ | `canvas.action.`, `canvas.layer.` | cut, copy, paste, group, the order of the layers (the context menu, the toolbar and the properties panel) |
82
+ | `canvas.shortcuts.`, `canvas.key.` | the list of keyboard shortcuts and the names of keys that are words ("Ctrl/Cmd", "Del", "Space") |
83
+ | `canvas.zoom.` | the pan and zoom panel |
84
+ | `canvas.props.`, `canvas.type.`, `canvas.field.`, `canvas.arrange.`, `canvas.image.`, `canvas.widget.`, `canvas.control.` | the properties panel: its sections and fields, what the selected thing is called, aligning, the picture of an image, widgets, and the colour and text controls |
85
+
86
+ ### Writing a message
87
+
88
+ A message is text. Two kinds of `{...}` have a meaning:
89
+
90
+ | Write | It shows |
91
+ | --- | --- |
92
+ | `{name}` | a value the canvas puts in (`'canvas.tool.withKey': '{name} ({key})'`). A number is written the way the locale writes numbers. |
93
+ | `{count, plural, one {# child} other {# children}}` | the branch that fits the number in the page's language. `other` is required; `=0 {none}` matches exactly 0; `#` is the number. A language with more forms says so: Polish uses `one`, `few`, `many` and `other`. |
94
+
95
+ `\{`, `\}`, `\#` and `\\` write that character itself. Each English message names the values it is given: a translation
96
+ may leave one out, and it may use a value in any order, but it cannot ask for a value the message is never given (it
97
+ would show as written, `{other}`). The line under the list of shortcuts (`canvas.shortcuts.footer`) has three parts that
98
+ the screen draws itself (`{key}`, `{hint}`, `{icon}`): put them where your language needs them.
99
+
100
+ ### Finding a mistake before a visitor does
101
+
102
+ `checkCanvasMessages(messages)` checks a `messages` object without showing anything, and `describeMessageProblem` (from
103
+ `@widgetic/design-system/i18n`) turns each problem into a sentence. It finds a key that does not exist (with the nearest
104
+ real one), a value that is not text, a template that does not parse, and a message that asks for a value it is never
105
+ given. An empty list means every message will be used. Put it in a test of your page:
106
+
107
+ ```ts
108
+ import { checkCanvasMessages } from '@widgetic/canvas';
109
+ import { describeMessageProblem } from '@widgetic/design-system/i18n';
110
+ import german from './canvas.de.json';
111
+
112
+ expect(checkCanvasMessages(german).map(describeMessageProblem)).toEqual([]);
113
+ ```
114
+
115
+ While the canvas runs, a message that cannot be used is never thrown: the English text of that key is shown and the
116
+ console says `[Canvas] ...` once.
117
+
118
+ ### What stays as it is
119
+
120
+ - **Words that belong to someone else.** The names of widgets, frames and files, and what people typed into a text, are
121
+ shown as they were written.
122
+ - **What a new thing starts with is saved with it.** A new frame's label, the text "Hello World!", the text box's
123
+ "Type here", "Untitled Frame" and the name of an unlinked widget are written into the canvas in the language it was
124
+ made in, like anything else a person could have typed. Opening that canvas in another language shows them as saved.
125
+ - **Words drawn onto the canvas itself** ("Drop image / or / double click" on an empty image, the name and preview line
126
+ of a widget, the label above a frame) are painted by the shapes, which read them from the canvas they are on and draw
127
+ them again whenever the language changes. A longer translation makes the block on an empty image smaller, never wider
128
+ than its box. A shape that is not on a canvas yet speaks English.
129
+ - **The one dialog.** When a picture cannot be loaded from an address, the canvas asks the browser to say so with its
130
+ own `alert`: the words are yours, the dialog is the browser's.
131
+ - **Names the canvas saves.** The groups of the shape library (`Geometric Shapes`, `Symbol Shapes` …) and a shape's key
132
+ are data a saved canvas knows its shapes by, and the descriptions of shapes the canvas hands to your
133
+ `onRecognizeStroke` (`rectangle or square`, `oval (ellipse)` …) are written for the recognizer, not for a screen: they
134
+ stay English. Each screen says the groups and the shapes through a message (`canvas.category.*`, `canvas.shape.*`).
135
+ - **Keys.** Names of keys that are words (`Ctrl/Cmd`, `Del`, `Click`) are messages, so a language can write "Strg" or
136
+ "Entf". Letters and symbols (`V`, `↑`, `]`) are the same on every keyboard, and the `⌘` glyphs in the context menu
137
+ are the Mac key caps.
138
+ - **Right to left.** The canvas has no prop for it: its toolbar, the properties panel, the menus and the lists are laid
139
+ out with logical sides (`start` and `end`, never `left` and `right`), so they start at the start of the line wherever the
140
+ screen around the canvas is read right to left (the widget creator sets that on its root). The drawing board itself
141
+ (`<canvas dir="ltr">`), the widgets drawn on it and the text alignment buttons, whose left, centre and right are sides of
142
+ the page, stay left to right. `tests/canvas-direction.test.mjs` keeps it so. For a language written right to left a name that is put inside a sentence sits between two invisible marks (Unicode isolates U+2068 and U+2069, made by the shared translator), so the words around it cannot turn it around; a test that compares text has to leave them out.
143
+ - **The design system.** The canvas needs `@widgetic/design-system` **0.5.16 or newer**: the translator comes from
144
+ `@widgetic/design-system/i18n`, the same one the File Browser, the editor and the chat use.
145
+
146
+ A part used on its own (a `ColorIC` or a `TextAlignIC` outside a `Canvas`) speaks English; call
147
+ `provideCanvasLanguage({ locale, messages })` in the component that holds it to give it a language. Inside a `Canvas` it
148
+ reads the language of that canvas, so two canvases on one page can speak two languages.
149
+
40
150
  ## Text Tool Improvements (2025-10-29)
41
151
 
42
152
  - Configure `fabric.Textbox` with TLdraw-like border and selection colours using native Fabric properties (`borderColor`, `editingBorderColor`, `selectionColor`, etc.) without introducing extra overlay objects.