@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.
Files changed (210) hide show
  1. package/README.md +105 -36
  2. package/dist/canvas/DomCanvas.svelte +449 -0
  3. package/dist/canvas/DomCanvas.svelte.d.ts +221 -0
  4. package/dist/canvas/boardFrame.d.ts +13 -0
  5. package/dist/canvas/boardFrame.js +13 -0
  6. package/dist/canvas/boardSurface.d.ts +9 -0
  7. package/dist/canvas/boardSurface.js +9 -0
  8. package/dist/canvas/chromeLayout.d.ts +76 -0
  9. package/dist/canvas/chromeLayout.js +121 -0
  10. package/dist/canvas/emptyBoardHint.d.ts +17 -0
  11. package/dist/canvas/emptyBoardHint.js +12 -0
  12. package/dist/canvas/eventScope.d.ts +1 -1
  13. package/dist/canvas/eventScope.js +1 -1
  14. package/dist/canvas/host/CanvasHost.d.ts +348 -0
  15. package/dist/canvas/host/CanvasHost.js +1715 -0
  16. package/dist/canvas/host/CanvasHostApi.d.ts +30 -0
  17. package/dist/canvas/host/CanvasHostApi.js +95 -0
  18. package/dist/canvas/host/browserServices.d.ts +46 -0
  19. package/dist/canvas/host/browserServices.js +167 -0
  20. package/dist/canvas/host/conversion.d.ts +53 -0
  21. package/dist/canvas/host/conversion.js +125 -0
  22. package/dist/canvas/host/hostObject.d.ts +40 -0
  23. package/dist/canvas/host/hostObject.js +93 -0
  24. package/dist/canvas/host/pageEvents.d.ts +24 -0
  25. package/dist/canvas/host/pageEvents.js +35 -0
  26. package/dist/canvas/host/screenRects.d.ts +66 -0
  27. package/dist/canvas/host/screenRects.js +102 -0
  28. package/dist/canvas/host/strokeSnap.d.ts +67 -0
  29. package/dist/canvas/host/strokeSnap.js +165 -0
  30. package/dist/canvas/index.d.ts +7 -7
  31. package/dist/canvas/index.js +8 -8
  32. package/dist/canvas/openMarks.d.ts +17 -0
  33. package/dist/canvas/openMarks.js +26 -0
  34. package/dist/canvas/panZoomPosition.d.ts +15 -0
  35. package/dist/canvas/panZoomPosition.js +16 -0
  36. package/dist/canvas/preferredTextFont.d.ts +12 -0
  37. package/dist/canvas/preferredTextFont.js +38 -0
  38. package/dist/canvas/shapes/ShapeLibrary.d.ts +1 -1
  39. package/dist/canvas/shapes/ShapeLibrary.js +13 -1
  40. package/dist/canvas/shapes/strokeShapeSnap.d.ts +14 -12
  41. package/dist/canvas/shapes/strokeShapeSnap.js +10 -8
  42. package/dist/canvas/toolbarPosition.d.ts +11 -11
  43. package/dist/canvas/toolbarPosition.js +11 -24
  44. package/dist/canvas/types.d.ts +14 -0
  45. package/dist/canvas/ui/CanvasContextMenu.svelte +173 -0
  46. package/dist/canvas/ui/CanvasContextMenu.svelte.d.ts +12 -0
  47. package/dist/canvas/ui/CanvasHint.svelte +21 -0
  48. package/dist/canvas/ui/CanvasHint.svelte.d.ts +18 -0
  49. package/dist/canvas/ui/CanvasToolbar.svelte +95 -0
  50. package/dist/canvas/ui/CanvasToolbar.svelte.d.ts +14 -0
  51. package/dist/canvas/ui/ColorField.svelte +156 -0
  52. package/dist/canvas/ui/ColorField.svelte.d.ts +14 -0
  53. package/dist/canvas/ui/LoadNotice.svelte +39 -0
  54. package/dist/canvas/ui/LoadNotice.svelte.d.ts +8 -0
  55. package/dist/canvas/ui/SelectionPanel.svelte +300 -0
  56. package/dist/canvas/ui/SelectionPanel.svelte.d.ts +20 -0
  57. package/dist/canvas/ui/SelectorBar.svelte +82 -0
  58. package/dist/canvas/ui/SelectorBar.svelte.d.ts +12 -0
  59. package/dist/canvas/ui/ShapesMenu.svelte +185 -0
  60. package/dist/canvas/ui/ShapesMenu.svelte.d.ts +15 -0
  61. package/dist/canvas/ui/ShortcutsPanel.svelte +124 -0
  62. package/dist/canvas/ui/ShortcutsPanel.svelte.d.ts +7 -0
  63. package/dist/canvas/ui/ToolButton.svelte +78 -0
  64. package/dist/canvas/ui/ToolButton.svelte.d.ts +20 -0
  65. package/dist/canvas/ui/WidgetActions.svelte +145 -0
  66. package/dist/canvas/ui/WidgetActions.svelte.d.ts +19 -0
  67. package/dist/canvas/ui/ZoomControl.svelte +89 -0
  68. package/dist/canvas/ui/ZoomControl.svelte.d.ts +18 -0
  69. package/dist/canvas/ui/colorModel.d.ts +18 -0
  70. package/dist/canvas/ui/colorModel.js +85 -0
  71. package/dist/canvas/ui/colorPickerMessages.d.ts +5 -0
  72. package/dist/canvas/ui/colorPickerMessages.js +15 -0
  73. package/dist/canvas/ui/floatingCard.d.ts +107 -0
  74. package/dist/canvas/ui/floatingCard.js +107 -0
  75. package/dist/canvas/ui/floatingLayer.d.ts +21 -0
  76. package/dist/canvas/ui/floatingLayer.js +52 -0
  77. package/dist/canvas/ui/icons.d.ts +12 -0
  78. package/dist/canvas/ui/icons.js +7 -0
  79. package/dist/canvas/ui/keyHints.d.ts +27 -0
  80. package/dist/canvas/ui/keyHints.js +43 -0
  81. package/dist/canvas/ui/popoverSide.d.ts +5 -0
  82. package/dist/canvas/ui/popoverSide.js +20 -0
  83. package/dist/canvas/ui/selectionTraits.d.ts +61 -0
  84. package/dist/canvas/ui/selectionTraits.js +99 -0
  85. package/dist/canvas/view/CanvasStage.svelte +132 -0
  86. package/dist/canvas/view/CanvasStage.svelte.d.ts +21 -0
  87. package/dist/canvas/view/EraserTrail.svelte +50 -0
  88. package/dist/canvas/view/EraserTrail.svelte.d.ts +9 -0
  89. package/dist/canvas/view/ObjectView.svelte +245 -0
  90. package/dist/canvas/view/ObjectView.svelte.d.ts +21 -0
  91. package/dist/canvas/view/SelectionOverlay.svelte +487 -0
  92. package/dist/canvas/view/SelectionOverlay.svelte.d.ts +17 -0
  93. package/dist/canvas/view/TextEditor.svelte +76 -0
  94. package/dist/canvas/view/TextEditor.svelte.d.ts +9 -0
  95. package/dist/canvas/view/WidgetChromeLayer.svelte +83 -0
  96. package/dist/canvas/view/WidgetChromeLayer.svelte.d.ts +13 -0
  97. package/dist/canvas/view/erasingMarks.d.ts +13 -0
  98. package/dist/canvas/view/erasingMarks.js +34 -0
  99. package/dist/canvas/view/geometry.d.ts +169 -0
  100. package/dist/canvas/view/geometry.js +272 -0
  101. package/dist/components/CanvasBoardPlaceholder.svelte +5 -3
  102. package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +3 -3
  103. package/dist/components/index.js +1 -1
  104. package/dist/components/input-controls/ColorIC.svelte +2 -2
  105. package/dist/engine/EngineCore.d.ts +273 -0
  106. package/dist/engine/EngineCore.js +1051 -0
  107. package/dist/engine/codec/canvasDocument.d.ts +57 -0
  108. package/dist/engine/codec/canvasDocument.js +471 -0
  109. package/dist/engine/codec/hostReadableKeys.d.ts +25 -0
  110. package/dist/engine/codec/hostReadableKeys.js +25 -0
  111. package/dist/engine/core/arrange.d.ts +20 -0
  112. package/dist/engine/core/arrange.js +81 -0
  113. package/dist/engine/core/arrow.d.ts +91 -0
  114. package/dist/engine/core/arrow.js +182 -0
  115. package/dist/engine/core/brush.d.ts +68 -0
  116. package/dist/engine/core/brush.js +173 -0
  117. package/dist/engine/core/defaults.d.ts +70 -0
  118. package/dist/engine/core/defaults.js +158 -0
  119. package/dist/engine/core/freehand.d.ts +130 -0
  120. package/dist/engine/core/freehand.js +430 -0
  121. package/dist/engine/core/geometry.d.ts +44 -0
  122. package/dist/engine/core/geometry.js +216 -0
  123. package/dist/engine/core/history.d.ts +39 -0
  124. package/dist/engine/core/history.js +69 -0
  125. package/dist/engine/core/hitTest.d.ts +54 -0
  126. package/dist/engine/core/hitTest.js +298 -0
  127. package/dist/engine/core/matrix.d.ts +47 -0
  128. package/dist/engine/core/matrix.js +101 -0
  129. package/dist/engine/core/pathData.d.ts +50 -0
  130. package/dist/engine/core/pathData.js +550 -0
  131. package/dist/engine/core/rotationReset.d.ts +10 -0
  132. package/dist/engine/core/rotationReset.js +17 -0
  133. package/dist/engine/core/scene.d.ts +99 -0
  134. package/dist/engine/core/scene.js +450 -0
  135. package/dist/engine/core/scribble.d.ts +64 -0
  136. package/dist/engine/core/scribble.js +121 -0
  137. package/dist/engine/core/shapePaths.d.ts +34 -0
  138. package/dist/engine/core/shapePaths.js +69 -0
  139. package/dist/engine/core/shapeTools.d.ts +80 -0
  140. package/dist/engine/core/shapeTools.js +161 -0
  141. package/dist/engine/core/snapping.d.ts +64 -0
  142. package/dist/engine/core/snapping.js +164 -0
  143. package/dist/engine/core/style.d.ts +40 -0
  144. package/dist/engine/core/style.js +151 -0
  145. package/dist/engine/core/transform.d.ts +79 -0
  146. package/dist/engine/core/transform.js +258 -0
  147. package/dist/engine/core/types.d.ts +238 -0
  148. package/dist/engine/core/types.js +31 -0
  149. package/dist/engine/core/viewport.d.ts +32 -0
  150. package/dist/engine/core/viewport.js +84 -0
  151. package/dist/engine/input/PointerController.d.ts +38 -0
  152. package/dist/engine/input/PointerController.js +545 -0
  153. package/dist/engine/input/arrowHandles.d.ts +38 -0
  154. package/dist/engine/input/arrowHandles.js +60 -0
  155. package/dist/engine/input/gestures.d.ts +79 -0
  156. package/dist/engine/input/gestures.js +769 -0
  157. package/dist/engine/input/hoverCursor.d.ts +29 -0
  158. package/dist/engine/input/hoverCursor.js +23 -0
  159. package/dist/engine/input/keyboard.d.ts +75 -0
  160. package/dist/engine/input/keyboard.js +264 -0
  161. package/dist/engine/input/selectionHandles.d.ts +89 -0
  162. package/dist/engine/input/selectionHandles.js +169 -0
  163. package/dist/engine/input/types.d.ts +82 -0
  164. package/dist/engine/input/types.js +5 -0
  165. package/dist/engine/render/rasterize.d.ts +74 -0
  166. package/dist/engine/render/rasterize.js +273 -0
  167. package/dist/engine/state.d.ts +124 -0
  168. package/dist/engine/state.js +47 -0
  169. package/dist/engine/text/layoutText.d.ts +53 -0
  170. package/dist/engine/text/layoutText.js +170 -0
  171. package/dist/engine/widgets.d.ts +124 -0
  172. package/dist/engine/widgets.js +345 -0
  173. package/dist/i18n/labels.d.ts +4 -15
  174. package/dist/i18n/labels.js +33 -53
  175. package/dist/i18n/language.d.ts +3 -3
  176. package/dist/i18n/messages.d.ts +52 -124
  177. package/dist/i18n/messages.js +59 -133
  178. package/dist/i18n/shortcuts.d.ts +0 -1
  179. package/dist/i18n/shortcuts.js +2 -11
  180. package/dist/index.d.ts +4 -2
  181. package/dist/index.js +5 -3
  182. package/package.json +30 -5
  183. package/dist/canvas/Canvas.svelte +0 -13363
  184. package/dist/canvas/Canvas.svelte.d.ts +0 -286
  185. package/dist/canvas/CanvasToolbar.svelte +0 -1498
  186. package/dist/canvas/CanvasToolbar.svelte.d.ts +0 -69
  187. package/dist/canvas/ContextMenu.svelte +0 -305
  188. package/dist/canvas/ContextMenu.svelte.d.ts +0 -42
  189. package/dist/canvas/PanZoomPanel.svelte +0 -478
  190. package/dist/canvas/PanZoomPanel.svelte.d.ts +0 -38
  191. package/dist/canvas/WidgetSelectionLayer.svelte +0 -156
  192. package/dist/canvas/WidgetSelectionLayer.svelte.d.ts +0 -11
  193. package/dist/canvas/props-panel/PropsPanel.svelte +0 -2075
  194. package/dist/canvas/props-panel/PropsPanel.svelte.d.ts +0 -84
  195. package/dist/canvas/props-panel/TextPropsICSection.svelte +0 -242
  196. package/dist/canvas/props-panel/TextPropsICSection.svelte.d.ts +0 -40
  197. package/dist/canvas/shadowRootText.d.ts +0 -5
  198. package/dist/canvas/shadowRootText.js +0 -43
  199. package/dist/canvas/shapes/FrameShape.d.ts +0 -97
  200. package/dist/canvas/shapes/FrameShape.js +0 -953
  201. package/dist/canvas/shapes/ImageShape.d.ts +0 -47
  202. package/dist/canvas/shapes/ImageShape.js +0 -339
  203. package/dist/canvas/shapes/WidgetShape.d.ts +0 -30
  204. package/dist/canvas/shapes/WidgetShape.js +0 -200
  205. package/dist/canvas/widgetPreviewGeometry.d.ts +0 -19
  206. package/dist/canvas/widgetPreviewGeometry.js +0 -66
  207. package/dist/i18n/shapeWords.d.ts +0 -30
  208. package/dist/i18n/shapeWords.js +0 -36
  209. package/dist/i18n/slots.d.ts +0 -20
  210. package/dist/i18n/slots.js +0 -40
package/README.md CHANGED
@@ -49,8 +49,8 @@ canvas is open:
49
49
  locale="de"
50
50
  messages={{
51
51
  'canvas.tool.draw': 'Zeichnen',
52
- 'canvas.tool.undoTitle': 'Rückgängig (Strg+Z)',
53
- 'canvas.zoom.expandTitle': 'Zoom {percent} % — zum Erweitern klicken',
52
+ 'canvas.tool.undo': 'Rückgängig',
53
+ 'canvas.zoom.resetLabel': 'Zoom auf 100 % zurücksetzen',
54
54
  }}
55
55
  />
56
56
  ```
@@ -68,22 +68,23 @@ canvas is open:
68
68
  import { CANVAS_MESSAGES } from '@widgetic/canvas';
69
69
 
70
70
  console.log(Object.keys(CANVAS_MESSAGES).length); // every word of the canvas
71
- console.log(CANVAS_MESSAGES['canvas.zoom.expandTitle']); // 'Zoom {percent}% — click to expand'
71
+ console.log(CANVAS_MESSAGES['canvas.zoom.fitLabel']); // 'Fit content to view'
72
72
  ```
73
73
 
74
74
  A page that loads the canvas on demand can read the words without loading it: `@widgetic/canvas/i18n` has
75
75
  `CANVAS_MESSAGES` and `checkCanvasMessages` and nothing else, so it brings the translator and the list of words, not
76
- `Canvas.svelte` or the drawing library.
76
+ the canvas itself.
77
77
 
78
78
  | Keys start with | The words of |
79
79
  | --- | --- |
80
- | `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 |
81
- | `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 |
82
- | `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 |
83
- | `canvas.action.`, `canvas.layer.` | cut, copy, paste, group, the order of the layers (the context menu, the toolbar and the properties panel) |
80
+ | `canvas.state.` | "Loading canvas…", the line when the canvas could not start, the name of the board for a screen reader, and the notice when a saved canvas cannot be opened |
81
+ | `canvas.hint.` | the hint on an empty board |
82
+ | `canvas.defaults.`, `canvas.draw.` | what new things start with ("Type here", "Untitled Shape"), and the words a widget card draws (its name when it has none, "Widget preview") |
83
+ | `canvas.toolbar.`, `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 |
84
+ | `canvas.action.`, `canvas.layer.` | cut, copy, paste, group, and the order of the layers (the context menu) |
84
85
  | `canvas.shortcuts.`, `canvas.key.` | the list of keyboard shortcuts and the names of keys that are words ("Ctrl/Cmd", "Del", "Space") |
85
- | `canvas.zoom.` | the pan and zoom panel |
86
- | `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 |
86
+ | `canvas.zoom.` | the zoom control |
87
+ | `canvas.panel.`, `canvas.type.`, `canvas.widget.`, `canvas.control.` | the selection panel: its sections, what the selected thing is called, the widget actions, and the colour and text controls |
87
88
 
88
89
  ### Writing a message
89
90
 
@@ -91,7 +92,7 @@ A message is text. Two kinds of `{...}` have a meaning:
91
92
 
92
93
  | Write | It shows |
93
94
  | --- | --- |
94
- | `{name}` | a value the canvas puts in (`'canvas.tool.withKey': '{name} ({key})'`). A number is written the way the locale writes numbers. |
95
+ | `{name}` | a value the canvas puts in (`'canvas.type.drawingOf': '{name} (Drawing)'`). A number is written the way the locale writes numbers. |
95
96
  | `{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`. |
96
97
 
97
98
  `\{`, `\}`, `\#` and `\\` write that character itself. Each English message names the values it is given: a translation
@@ -119,42 +120,110 @@ console says `[Canvas] ...` once.
119
120
 
120
121
  ### What stays as it is
121
122
 
122
- - **Words that belong to someone else.** The names of widgets, frames and files, and what people typed into a text, are
123
- shown as they were written.
124
- - **What a new thing starts with is saved with it.** A new frame's label, the text "Hello World!", the text box's
125
- "Type here", "Untitled Frame" and the name of an unlinked widget are written into the canvas in the language it was
126
- made in, like anything else a person could have typed. Opening that canvas in another language shows them as saved.
127
- - **Words drawn onto the canvas itself** ("Drop image / or / double click" on an empty image, the name and preview line
128
- of a widget, the label above a frame) are painted by the shapes, which read them from the canvas they are on and draw
129
- them again whenever the language changes. A longer translation makes the block on an empty image smaller, never wider
130
- than its box. A shape that is not on a canvas yet speaks English.
131
- - **The one dialog.** When a picture cannot be loaded from an address, the canvas asks the browser to say so with its
132
- own `alert`: the words are yours, the dialog is the browser's.
123
+ - **Words that belong to someone else.** The names of widgets and files, and what people typed into a text, are shown
124
+ as they were written.
125
+ - **What a new thing starts with.** A new text starts empty and shows "Type here" until something is typed; a selection
126
+ that becomes a widget is sent to your `onConvertToWidget` under the name "Untitled Shape" when it has none. Both are
127
+ messages, said in the language of the canvas they are on.
128
+ - **Words a widget card draws** (its name, "Widget preview" when it has no picture yet) are read from the canvas the card
129
+ is on and shown again whenever the language changes. They are never written into the saved canvas, and the picture
130
+ sent to the AI says them in the same language.
133
131
  - **Names the canvas saves.** The groups of the shape library (`Geometric Shapes`, `Symbol Shapes` …) and a shape's key
134
132
  are data a saved canvas knows its shapes by, and the descriptions of shapes the canvas hands to your
135
133
  `onRecognizeStroke` (`rectangle or square`, `oval (ellipse)` …) are written for the recognizer, not for a screen: they
136
134
  stay English. Each screen says the groups and the shapes through a message (`canvas.category.*`, `canvas.shape.*`).
137
135
  - **Keys.** Names of keys that are words (`Ctrl/Cmd`, `Del`, `Click`) are messages, so a language can write "Strg" or
138
- "Entf". Letters and symbols (`V`, `↑`, `]`) are the same on every keyboard, and the `⌘` glyphs in the context menu
139
- are the Mac key caps.
140
- - **Right to left.** The canvas has no prop for it: its toolbar, the properties panel, the menus and the lists are laid
141
- out with logical sides (`start` and `end`, never `left` and `right`), so they start at the start of the line wherever the
142
- screen around the canvas is read right to left (the widget creator sets that on its root). The drawing board itself
143
- (`<canvas dir="ltr">`), the widgets drawn on it and the text alignment buttons, whose left, centre and right are sides of
144
- 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.
145
- - **The design system.** The canvas needs `@widgetic/design-system` **0.5.16 or newer**: the translator comes from
146
- `@widgetic/design-system/i18n`, the same one the File Browser, the editor and the chat use.
136
+ "Entf". Letters and symbols (`V`, `↑`, `]`) are the same on every keyboard, and the `⌘` glyphs in the menus are the
137
+ Mac key caps.
138
+ - **Right to left.** The canvas has no prop for it: its toolbar, the selection 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
140
+ the screen around the canvas is read right to left (the widget creator sets that on its root). The drawing board
141
+ itself (`dir="ltr"`), the widgets drawn on it and the three text alignment buttons, whose left, centre and right are
142
+ sides of the page, stay left to right. A text on the board is written the way its first letter is (Hebrew and Arabic
143
+ from right to left), on the board, in the field it is typed in and in the picture sent to the AI.
144
+ `tests/canvas-direction.test.mjs` keeps it so. For a language written right to left a name that is put inside a
145
+ sentence sits between two invisible marks (Unicode isolates U+2068 and U+2069, made by the shared translator), so the
146
+ words around it cannot turn it around; a test that compares text has to leave them out.
147
+ - **The design system.** The canvas needs `@widgetic/design-system` **0.5.23 or newer**: the translator comes from
148
+ `@widgetic/design-system/i18n`, the same one the File Browser, the editor and the chat use, and the toolbar parts
149
+ (`IconButton`, `StepperButton`, the soft `Input`) first shipped in 0.5.23.
147
150
 
148
151
  A part used on its own (a `ColorIC` or a `TextAlignIC` outside a `Canvas`) speaks English; call
149
152
  `provideCanvasLanguage({ locale, messages })` in the component that holds it to give it a language. Inside a `Canvas` it
150
153
  reads the language of that canvas, so two canvases on one page can speak two languages.
151
154
 
152
- ## Text Tool Improvements (2025-10-29)
155
+ ## How the canvas works
153
156
 
154
- - Configure `fabric.Textbox` with TLdraw-like border and selection colours using native Fabric properties (`borderColor`, `editingBorderColor`, `selectionColor`, etc.) without introducing extra overlay objects.
155
- - Simplified the edit lifecycle: Fabric now handles hover/edit visuals, while we ensure placeholders restore after `editing:exited` and outside clicks call `exitEditing()`.
156
- - Kept textbox focusing logic lightweight—just focus the hidden textarea and rely on Fabric’s built-in selection/caret behaviour.
157
- - Resolved previous lint warnings in `src/lib/canvas/tools/ToolController.ts` by tightening event typings and removing unused overlay helpers.
157
+ The canvas is a Svelte DOM canvas: every shape on the board is an element (an `<svg>`, a text block, an image, a widget
158
+ card) inside one layer that is moved and scaled as a whole, so the browser does the drawing, the text and the zoom. There
159
+ is no drawing library underneath. What a page sees is unchanged: `Canvas` takes the same props and exports the same
160
+ functions as before, and sends the same two events on `window`.
161
+
162
+ ```
163
+ Canvas (DomCanvas.svelte, the one public component: props in, exported functions out)
164
+ └─ CanvasHost (plain TypeScript: props, autosave, widget cards, conversions, the page's callbacks)
165
+ └─ EngineCore (the scene, the selection, the history, the viewport; no DOM, runs in Node)
166
+ ├─ PointerController (what a press, a move and a release do, by tool)
167
+ └─ keyboard routing (the shortcuts)
168
+ ```
169
+
170
+ The saved canvas is a versioned document (`CANVAS_DOCUMENT_VERSION = 2`): a flat, z-ordered list of shapes (`rect`,
171
+ `ellipse`, `path`, `text`, `image`, `widget`, `group`). The keys a page reads out of it (`canvas.objects`, `type`,
172
+ `_widgetId`, `_isWidgetImage`) are unchanged. A canvas saved by the old drawing-library engine is not read: it opens
173
+ empty with a notice and is left as it is until something new is added.
174
+
175
+ **The pencil is a brush.** A stroke is thicker where the hand slows down (a pen's own pressure draws it when the device reports
176
+ one), a click is a round dot, **Shift** draws a straight line, and a resize makes a stroke longer, never fatter. A board saves
177
+ each stroke as its line and its pressures (`ink`) and draws the outline again when it is read.
178
+
179
+ **An arrow is two points and a bend.** Its open head keeps its size when the arrow is stretched, a selected arrow has a handle
180
+ on each end and one in the middle that bends it (**Shift** holds the direction to steps of 15°), and a board saves it as
181
+ `arrow` and draws the outline again when it is read. An arrow does not attach to a shape. **The eraser marks** the shapes the
182
+ pointer passes over, dimmed, and removes them all in one step on release (**Esc** leaves them).
183
+
184
+ **The toolbar and the zoom control stand at one of eight places:** `toolbarPosition` and `panZoomPosition` take `TL` `TC` `TR`
185
+ `CL` `CR` `BL` `BC` `BR` (the defaults, `BC` and `BL`, are the Widgetic layout; the Shopify package passes
186
+ `toolbarPosition="BL"` and `panZoomPosition="BR"`).
187
+
188
+ **Freehand shape snap (off by default).** A stroke that is a clean rectangle, circle, oval, triangle, diamond or hexagon
189
+ stays as it was drawn unless the page asks: pass `shapeSnap={true}` on `<Canvas>` and a finished Draw stroke is replaced by
190
+ that shape when the geometry is confident (a stroke it cannot decide is handed to the page's optional `onRecognizeStroke`).
191
+ The package constant `CANVAS_SHAPE_SNAP_ENABLED` stays `false`: it is the one line that turns the snap on for every page, or
192
+ back off.
193
+
194
+ [`__docs/dom-canvas.md`](./__docs/dom-canvas.md) explains the parts, the host contract, the document, the tools and the
195
+ tests. The engine this one replaced is gone from the package, with no fallback to it: no dependency, no reader for its saved
196
+ files, and no document about it. Its specs and progress log are only in the git history (`git show d824044:__specs/<file>`).
197
+
198
+ ## Tests
199
+
200
+ `npm test` runs everything in Node (no browser): the engine and the host against a fake page, the document codec, the
201
+ message catalog and the audits that hold every visible word to a message and every side to `start` and `end`.
202
+ `npm run check` type-checks the Svelte files.
203
+
204
+ The browser checks live in `scripts/browser/` (Playwright and Chrome are borrowed from `../ui-sdk/modules`, nothing is
205
+ installed here). They are not npm scripts: start the dev server (`npm run dev`, port 5181) and run one against it.
206
+
207
+ ```bash
208
+ ORIGIN=http://127.0.0.1:5181 node scripts/browser/conformance.mjs # the host contract, as a page uses it
209
+ ORIGIN=http://127.0.0.1:5181 node scripts/browser/interaction.mjs # a real mouse and keyboard: tools, gestures, keys
210
+ ORIGIN=http://127.0.0.1:5181 node scripts/browser/shadow.mjs # inside a shadow root, as the UI SDK mounts it
211
+ ORIGIN=http://127.0.0.1:5181 node scripts/browser/widgetCard.mjs # a live widget laid over a card
212
+ ORIGIN=http://127.0.0.1:5181 node scripts/browser/touch.mjs # touch and pen
213
+ ORIGIN=http://127.0.0.1:5181 node scripts/browser/responsive.mjs # the Figma layouts at desktop, tablet and phone widths
214
+ ORIGIN=http://127.0.0.1:5181 node scripts/browser/a11y.mjs # the accessibility tree, focus, reduced motion
215
+ ORIGIN=http://127.0.0.1:5181 node scripts/browser/chrome.mjs # where the toolbar and the zoom control stand, at each of eight places
216
+ ORIGIN=http://127.0.0.1:5181 node scripts/browser/eraser.mjs # the eraser marks, then removes on release
217
+ ORIGIN=http://127.0.0.1:5181 node scripts/browser/brush.mjs # the pencil's brush
218
+ ORIGIN=http://127.0.0.1:5181 node scripts/browser/handles.mjs # handles and rotation (a text is not turned)
219
+ ORIGIN=http://127.0.0.1:5181 node scripts/browser/marquee.mjs # what a marquee would take is outlined while it is dragged
220
+ ORIGIN=http://127.0.0.1:5181 node scripts/browser/outlinePixels.mjs # ... and that outline is the pointer's, pixel for pixel
221
+ ORIGIN=http://127.0.0.1:5181 node scripts/browser/arrows.mjs # arrows and their handles
222
+ npm run build && npx vite preview --port 5182 # a production build, in one terminal ...
223
+ node scripts/browser/stress.mjs # ... and the frame cost, in another
224
+ ```
225
+
226
+ Each prints one line per check and exits 1 when one fails. `__docs/dom-canvas.md` says what each holds.
158
227
 
159
228
  ## Publishing
160
229