@widgetic/canvas 0.5.44 → 0.5.45

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 (160) hide show
  1. package/dist/canvas/DomCanvas.svelte +52 -3
  2. package/dist/canvas/DomCanvas.svelte.d.ts +59 -34
  3. package/dist/canvas/autosaveScheduler.js +89 -37
  4. package/dist/canvas/boardFrame.js +1 -1
  5. package/dist/canvas/boardSurface.js +1 -1
  6. package/dist/canvas/canvasLogger.js +19 -7
  7. package/dist/canvas/chromeLayout.js +21 -19
  8. package/dist/canvas/eventScope.js +14 -10
  9. package/dist/canvas/host/CanvasHost.d.ts +68 -1
  10. package/dist/canvas/host/CanvasHost.js +1901 -1407
  11. package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
  12. package/dist/canvas/host/CanvasHostApi.js +28 -5
  13. package/dist/canvas/host/boardFiles.d.ts +90 -0
  14. package/dist/canvas/host/boardFiles.js +155 -0
  15. package/dist/canvas/host/browserServices.d.ts +17 -0
  16. package/dist/canvas/host/browserServices.js +211 -65
  17. package/dist/canvas/host/conversion.js +170 -82
  18. package/dist/canvas/host/hostObject.js +7 -7
  19. package/dist/canvas/host/nearCards.js +21 -18
  20. package/dist/canvas/host/pageEvents.js +5 -5
  21. package/dist/canvas/host/pictureSaves.js +11 -9
  22. package/dist/canvas/host/screenRects.js +31 -28
  23. package/dist/canvas/host/storedPictures.js +243 -149
  24. package/dist/canvas/host/strokeSnap.js +143 -88
  25. package/dist/canvas/index.d.ts +1 -0
  26. package/dist/canvas/openMarks.js +2 -2
  27. package/dist/canvas/outsideClickDeselect.js +7 -6
  28. package/dist/canvas/panZoomPosition.js +2 -2
  29. package/dist/canvas/preferredTextFont.js +25 -13
  30. package/dist/canvas/shapes/ShapeLibrary.js +148 -138
  31. package/dist/canvas/shapes/shapeImageStore.js +4 -4
  32. package/dist/canvas/shapes/strokeShapeSnap.js +233 -188
  33. package/dist/canvas/toolbarPosition.js +2 -2
  34. package/dist/canvas/ui/CanvasContextMenu.svelte +7 -0
  35. package/dist/canvas/ui/CanvasToolbar.svelte +4 -1
  36. package/dist/canvas/ui/CanvasToolbar.svelte.d.ts +2 -0
  37. package/dist/canvas/ui/SelectionPanel.svelte +78 -17
  38. package/dist/canvas/ui/ShapesMenu.svelte +65 -31
  39. package/dist/canvas/ui/ShapesMenu.svelte.d.ts +2 -0
  40. package/dist/canvas/ui/ShortcutTooltip.svelte +64 -0
  41. package/dist/canvas/ui/ShortcutTooltip.svelte.d.ts +24 -0
  42. package/dist/canvas/ui/ToolButton.svelte +34 -55
  43. package/dist/canvas/ui/ToolButton.svelte.d.ts +4 -1
  44. package/dist/canvas/ui/colorModel.js +32 -21
  45. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  46. package/dist/canvas/ui/floatingCard.d.ts +26 -4
  47. package/dist/canvas/ui/floatingCard.js +43 -21
  48. package/dist/canvas/ui/floatingLayer.js +6 -5
  49. package/dist/canvas/ui/icons.d.ts +1 -1
  50. package/dist/canvas/ui/icons.js +1 -1
  51. package/dist/canvas/ui/keyHints.js +11 -9
  52. package/dist/canvas/ui/popoverSide.js +3 -2
  53. package/dist/canvas/ui/selectionTraits.d.ts +12 -0
  54. package/dist/canvas/ui/selectionTraits.js +66 -35
  55. package/dist/canvas/ui/sizeLabelVisibility.d.ts +4 -2
  56. package/dist/canvas/ui/sizeLabelVisibility.js +5 -5
  57. package/dist/canvas/view/CanvasStage.svelte +7 -2
  58. package/dist/canvas/view/CanvasStage.svelte.d.ts +2 -0
  59. package/dist/canvas/view/SelectionOverlay.svelte +17 -10
  60. package/dist/canvas/view/WidgetChromeLayer.svelte +15 -3
  61. package/dist/canvas/view/erasingMarks.js +7 -7
  62. package/dist/canvas/view/geometry.d.ts +1 -1
  63. package/dist/canvas/view/geometry.js +90 -71
  64. package/dist/canvas/view/liftedScene.js +36 -24
  65. package/dist/canvas/view/mountedScene.js +79 -76
  66. package/dist/components/CanvasBoardPoster.svelte +206 -0
  67. package/dist/components/CanvasBoardPoster.svelte.d.ts +17 -0
  68. package/dist/components/CanvasToolbarPlaceholder.svelte +115 -0
  69. package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +9 -0
  70. package/dist/components/index.d.ts +7 -0
  71. package/dist/components/index.js +8 -0
  72. package/dist/components/preferenceStorage.js +2 -2
  73. package/dist/engine/EngineCore.d.ts +37 -2
  74. package/dist/engine/EngineCore.js +946 -768
  75. package/dist/engine/codec/canvasDocument.d.ts +7 -0
  76. package/dist/engine/codec/canvasDocument.js +172 -186
  77. package/dist/engine/codec/hostReadableKeys.js +1 -1
  78. package/dist/engine/core/arrange.js +38 -26
  79. package/dist/engine/core/arrow.d.ts +18 -8
  80. package/dist/engine/core/arrow.js +109 -84
  81. package/dist/engine/core/arrowBinding.d.ts +1 -1
  82. package/dist/engine/core/arrowBinding.js +126 -101
  83. package/dist/engine/core/arrowBindingRecords.d.ts +9 -3
  84. package/dist/engine/core/arrowBindingRecords.js +48 -29
  85. package/dist/engine/core/brush.d.ts +8 -0
  86. package/dist/engine/core/brush.js +98 -78
  87. package/dist/engine/core/cameraMove.d.ts +6 -0
  88. package/dist/engine/core/cameraMove.js +56 -38
  89. package/dist/engine/core/defaults.js +51 -90
  90. package/dist/engine/core/freehand.js +163 -147
  91. package/dist/engine/core/geometry.js +54 -47
  92. package/dist/engine/core/history.js +55 -38
  93. package/dist/engine/core/hitTest.js +81 -68
  94. package/dist/engine/core/matrix.js +20 -18
  95. package/dist/engine/core/pathData.js +210 -183
  96. package/dist/engine/core/rotationReset.js +6 -5
  97. package/dist/engine/core/scene.d.ts +22 -0
  98. package/dist/engine/core/scene.js +288 -139
  99. package/dist/engine/core/scribble.js +84 -59
  100. package/dist/engine/core/shapePaths.js +15 -12
  101. package/dist/engine/core/shapeTools.js +63 -72
  102. package/dist/engine/core/snapping.js +117 -65
  103. package/dist/engine/core/style.d.ts +10 -0
  104. package/dist/engine/core/style.js +82 -33
  105. package/dist/engine/core/transform.d.ts +6 -0
  106. package/dist/engine/core/transform.js +103 -83
  107. package/dist/engine/core/types.d.ts +7 -0
  108. package/dist/engine/core/types.js +4 -4
  109. package/dist/engine/core/viewport.js +36 -23
  110. package/dist/engine/input/PointerController.d.ts +15 -1
  111. package/dist/engine/input/PointerController.js +547 -476
  112. package/dist/engine/input/arrowHandles.js +12 -12
  113. package/dist/engine/input/gestures.d.ts +3 -1
  114. package/dist/engine/input/gestures.js +340 -266
  115. package/dist/engine/input/hoverCursor.js +1 -1
  116. package/dist/engine/input/keyboard.d.ts +22 -3
  117. package/dist/engine/input/keyboard.js +131 -32
  118. package/dist/engine/input/selectionHandles.js +50 -45
  119. package/dist/engine/input/types.d.ts +7 -0
  120. package/dist/engine/input/types.js +1 -1
  121. package/dist/engine/render/rasterize.js +158 -86
  122. package/dist/engine/state.d.ts +18 -0
  123. package/dist/engine/state.js +25 -4
  124. package/dist/engine/text/layoutText.js +62 -43
  125. package/dist/engine/text/textMetrics.js +10 -8
  126. package/dist/engine/widgets.js +137 -101
  127. package/dist/fonts/interFont.js +83 -30
  128. package/dist/fonts/workspaceFonts.d.ts +6 -0
  129. package/dist/fonts/workspaceFonts.js +108 -34
  130. package/dist/i18n/labels.js +4 -4
  131. package/dist/i18n/language.d.ts +3 -3
  132. package/dist/i18n/language.js +4 -4
  133. package/dist/i18n/messages.d.ts +6 -0
  134. package/dist/i18n/messages.js +7 -1
  135. package/dist/i18n/shortcuts.d.ts +6 -4
  136. package/dist/i18n/shortcuts.js +30 -26
  137. package/dist/index.d.ts +1 -0
  138. package/dist/poster/boardPlacement.d.ts +80 -0
  139. package/dist/poster/boardPlacement.js +140 -0
  140. package/dist/poster/boardPoster.d.ts +80 -0
  141. package/dist/poster/boardPoster.js +251 -0
  142. package/dist/poster/paintBoardPoster.d.ts +49 -0
  143. package/dist/poster/paintBoardPoster.js +112 -0
  144. package/dist/poster/posterPictures.d.ts +32 -0
  145. package/dist/poster/posterPictures.js +138 -0
  146. package/dist/settings/workspaceToolSettings.d.ts +6 -0
  147. package/dist/settings/workspaceToolSettings.js +58 -34
  148. package/dist/tools/components/catalog.js +74 -64
  149. package/dist/tools/components/grouping.js +28 -6
  150. package/dist/tools/definitions.js +31 -9
  151. package/dist/tools/executors.js +214 -106
  152. package/dist/tools/hostAdapter.d.ts +5 -1
  153. package/dist/tools/hostAdapter.js +15 -11
  154. package/dist/tools/sceneSummary.js +57 -43
  155. package/dist/tools/sketchIntent.js +21 -13
  156. package/dist/tools/styleArguments.d.ts +35 -0
  157. package/dist/tools/styleArguments.js +93 -0
  158. package/dist/tools/types.d.ts +26 -1
  159. package/dist/tools/types.js +2 -1
  160. package/package.json +1 -1
@@ -0,0 +1,9 @@
1
+ interface Props {
2
+ /** Where the toolbar stands: one of the eight places of `toolbarPosition` (anything else is the bottom centre, as in the canvas). */
3
+ toolbarPosition?: string | null;
4
+ /** The same option the canvas has: false draws nothing, as the canvas draws no toolbar then. */
5
+ showDrawingTools?: boolean;
6
+ }
7
+ declare const CanvasToolbarPlaceholder: import("svelte").Component<Props, {}, "">;
8
+ type CanvasToolbarPlaceholder = ReturnType<typeof CanvasToolbarPlaceholder>;
9
+ export default CanvasToolbarPlaceholder;
@@ -5,6 +5,13 @@
5
5
  */
6
6
  export { default as Tooltip } from './Tooltip.svelte';
7
7
  export { default as CanvasBoardPlaceholder, CANVAS_BOARD_BACKGROUND } from './CanvasBoardPlaceholder.svelte';
8
+ export { default as CanvasToolbarPlaceholder } from './CanvasToolbarPlaceholder.svelte';
9
+ export { default as CanvasBoardPoster } from './CanvasBoardPoster.svelte';
10
+ export { createBoardPoster, parseBoardPoster, boardPostersMatch, BOARD_POSTER_VERSION, BOARD_POSTER_STORAGE_KIND, DEFAULT_POSTER_SURFACE } from '../poster/boardPoster.js';
11
+ export type { BoardPoster, BoardPosterOptions, ParsedBoardPoster } from '../poster/boardPoster.js';
12
+ export type { PosterPictureResolver } from '../poster/posterPictures.js';
13
+ export { BOARD_PLACEMENT_STORAGE_KEY, boardLayoutOf, measureBoardPlacement, rememberBoardPlacement, recallBoardPlacement } from '../poster/boardPlacement.js';
14
+ export type { BoardPlacement, BoardPlacementDetails, BoardLayoutClass } from '../poster/boardPlacement.js';
8
15
  export { setCanvasPreferenceStorage, getCanvasPreferenceStorage } from './preferenceStorage';
9
16
  export type { CanvasPreferenceStorage } from './preferenceStorage';
10
17
  export { default as ColorIC } from './input-controls/ColorIC.svelte';
@@ -7,6 +7,14 @@
7
7
  export { default as Tooltip } from './Tooltip.svelte';
8
8
  // The empty board: shown while the canvas code downloads
9
9
  export { default as CanvasBoardPlaceholder, CANVAS_BOARD_BACKGROUND } from './CanvasBoardPlaceholder.svelte';
10
+ // The drawing toolbar as it stands before the canvas is there: a host draws it next to the empty board so the bar is there at first paint
11
+ export { default as CanvasToolbarPlaceholder } from './CanvasToolbarPlaceholder.svelte';
12
+ // The poster of the board: the objects of the saved view, drawn from the first frame while the canvas code is on its way.
13
+ // A host keeps one with `createBoardPoster` at every save, reads it back with `parseBoardPoster`, and draws it with <CanvasBoardPoster>.
14
+ export { default as CanvasBoardPoster } from './CanvasBoardPoster.svelte';
15
+ export { createBoardPoster, parseBoardPoster, boardPostersMatch, BOARD_POSTER_VERSION, BOARD_POSTER_STORAGE_KIND, DEFAULT_POSTER_SURFACE } from '../poster/boardPoster.js';
16
+ // Where the board stands in its host's page, remembered so the next visit draws the poster and the toolbar in place at first paint
17
+ export { BOARD_PLACEMENT_STORAGE_KEY, boardLayoutOf, measureBoardPlacement, rememberBoardPlacement, recallBoardPlacement } from '../poster/boardPlacement.js';
10
18
  // Where the canvas keeps a visitor's choices (the host can install a store of its own)
11
19
  export { setCanvasPreferenceStorage, getCanvasPreferenceStorage } from './preferenceStorage';
12
20
  // Input Controllers
@@ -6,7 +6,7 @@
6
6
  * is written into the page's storage and a browser that several visitors share does not pass one visitor's choices on
7
7
  * to the next. The host does this once, before the canvas is shown.
8
8
  */
9
- let installedStorage = null;
9
+ var installedStorage = null;
10
10
  /** Installs the store the canvas keeps the visitor's choices in; `null` goes back to the browser's `localStorage`. */
11
11
  export function setCanvasPreferenceStorage(storage) {
12
12
  installedStorage = storage;
@@ -18,7 +18,7 @@ export function getCanvasPreferenceStorage() {
18
18
  try {
19
19
  return typeof localStorage === 'undefined' ? null : localStorage;
20
20
  }
21
- catch {
21
+ catch (_a) {
22
22
  // Reading `localStorage` itself throws where the browser blocks storage for the page.
23
23
  return null;
24
24
  }
@@ -18,7 +18,7 @@ import type { ReorderMode, Scene } from './core/scene.js';
18
18
  import type { StylePatch } from './core/style.js';
19
19
  import type { SelectionFrame } from './core/transform.js';
20
20
  import type { ObjectId, Point, Rect, RectObject, SceneObject, ShapeObject, Size, TextObject, Viewport, WidgetObject } from './core/types.js';
21
- import type { EngineOverlay, EngineState, PendingWidgetState, ToolId, WidgetRuntime } from './state.js';
21
+ import type { EngineOverlay, EngineState, PendingWidgetState, PenStyle, ToolId, WidgetRuntime } from './state.js';
22
22
  import type { MeasureText } from './text/layoutText.js';
23
23
  /** How many undo steps the board keeps (as the canvas it replaces did). */
24
24
  export declare const HISTORY_LIMIT = 50;
@@ -47,6 +47,11 @@ export interface EngineServices {
47
47
  * in its place at once instead of easing it there.
48
48
  */
49
49
  prefersReducedMotion?: () => boolean;
50
+ /**
51
+ * Says something worth following about what the person did (once per action, never per frame): the canvas passes its console
52
+ * logger. The engine says nothing when no function is given, as in the tests.
53
+ */
54
+ log?: (message: string, details?: Record<string, unknown>) => void;
50
55
  }
51
56
  /** A place to look at: the point of the world that goes to the middle of the board element, and the zoom to arrive at. */
52
57
  export interface ViewTarget {
@@ -58,6 +63,11 @@ export interface ViewTarget {
58
63
  export interface ViewMoveOptions {
59
64
  /** How long the move takes, in milliseconds. Left out: worked out from how far the view goes, and always under a second. */
60
65
  duration?: number;
66
+ /**
67
+ * How much of the worked-out time the move takes: 0.5 is twice as quick, 2 is twice as slow. Only used when `duration` is left
68
+ * out (a duration that is given is the time of the move, exactly). A value that is not above 0 is taken for 1.
69
+ */
70
+ durationScale?: number;
61
71
  /**
62
72
  * The shape of the move: how much of the way is done (0 to 1) when this much of the time has passed (0 to 1), for the
63
73
  * position and the zoom together. Left out: slow start, quick middle, slow end.
@@ -103,6 +113,8 @@ export interface EngineHooks {
103
113
  onSelectionChange?: (selectedIds: readonly ObjectId[]) => void;
104
114
  /** Widget cards are about to be deleted: one question per widget, and one `false` cancels the whole delete. */
105
115
  confirmWidgetDeletion?: ((widgetId: string) => Promise<boolean> | boolean) | null;
116
+ /** Whether widget cards may be duplicated/pasted on the board. Defaults to true. */
117
+ canDuplicateWidget?: () => boolean;
106
118
  /** A widget card was duplicated or pasted: the host makes a copy of the widget and links it with `linkObjectToWidget`. */
107
119
  onWidgetDuplicated?: ((sourceWidgetId: string, clone: WidgetObject) => void) | null;
108
120
  /** Something went wrong in a hook the host supplied. */
@@ -308,13 +320,26 @@ export declare class EngineCore {
308
320
  text?: Partial<Pick<TextObject, 'fontFamily' | 'fontSize' | 'fontWeight' | 'fontStyle' | 'color' | 'align' | 'underline'>> | null;
309
321
  paint?: Partial<Pick<RectObject, 'fill' | 'stroke' | 'strokeWidth' | 'strokeStyle' | 'opacity' | 'roundness'>> | null;
310
322
  }): void;
323
+ /**
324
+ * Changes how the Draw tool draws: the lines drawn from now on take the colour, the width and the opacity that are asked for. A key
325
+ * that is left out stays as it was; a value that cannot be a line's (a width under 1 or above 200, an opacity out of range, a
326
+ * colour that is not a word, a number that is not a number) is brought to what a line can be, or ignored when it is not a value
327
+ * at all. Nothing on the board changes (that is `setStyle`, for the selection), and nothing is added to the history. Returns
328
+ * whether the pen came out different.
329
+ */
330
+ setPenStyle(patch: Partial<PenStyle>): boolean;
311
331
  workspacePaintForNewShape(wireframe: boolean): Partial<RectObject>;
312
332
  /**
313
333
  * Makes a text object, puts it on the board and starts editing it. A click makes a label whose width follows its
314
334
  * text; a width makes a box whose lines wrap. Nothing is recorded until the editing ends with text in it.
335
+ *
336
+ * `placeholder: true` is the text the Text tool puts on the board the moment it is chosen: its box (as wide as the placeholder
337
+ * prompt) is centred on `point` instead of starting there, and a press elsewhere on the board while it is still empty keeps the
338
+ * tool, so that press (or drag) places the text there (see `endTextEdit`).
315
339
  */
316
340
  createText(point: Point, options?: {
317
341
  width?: number;
342
+ placeholder?: boolean;
318
343
  }): ObjectId;
319
344
  /** Starts editing the text of an existing text object. */
320
345
  beginTextEdit(id: ObjectId): boolean;
@@ -323,8 +348,14 @@ export declare class EngineCore {
323
348
  /**
324
349
  * Finishes the edit. An empty text is removed (a new one leaves nothing behind, not even an undo step);
325
350
  * otherwise creation and typing together are one undo step.
351
+ *
352
+ * `keepPlaceholderTool` is for a press on the board that ends the edit: when what ends is the empty placeholder the Text tool
353
+ * put on the board (see `createText`), the tool is not left, so the press goes on to be a press of the Text tool and puts the
354
+ * text where the person pressed. Any other end of the edit leaves the Text tool, as before.
326
355
  */
327
- endTextEdit(): ObjectId | null;
356
+ endTextEdit(options?: {
357
+ keepPlaceholderTool?: boolean;
358
+ }): ObjectId | null;
328
359
  /** Changes how the selection looks. `commit: false` is for a slider that is still being dragged: call `commit()` when it ends. */
329
360
  setStyle(patch: StylePatch, options?: {
330
361
  commit?: boolean;
@@ -343,6 +374,10 @@ export declare class EngineCore {
343
374
  nudgeSelection(deltaX: number, deltaY: number): boolean;
344
375
  alignSelection(mode: AlignMode): boolean;
345
376
  distributeSelection(axis: DistributeAxis): boolean;
377
+ /**
378
+ * Puts the selection in front of or behind the others (`front` and `back` all the way, `forward` and `backward` one step).
379
+ * Shapes that arrows tie together are one diagram: what is joined to the selection by arrows, at any distance, goes with it.
380
+ */
346
381
  reorderSelection(mode: ReorderMode): boolean;
347
382
  /** Puts the selected units in a group, which becomes the selection. */
348
383
  groupSelection(): boolean;