@widgetic/canvas 0.5.42 → 0.5.44

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 (69) hide show
  1. package/README.md +1 -0
  2. package/dist/canvas/DomCanvas.svelte +53 -20
  3. package/dist/canvas/DomCanvas.svelte.d.ts +19 -7
  4. package/dist/canvas/chromeLayout.d.ts +14 -3
  5. package/dist/canvas/chromeLayout.js +14 -3
  6. package/dist/canvas/host/CanvasHost.d.ts +66 -6
  7. package/dist/canvas/host/CanvasHost.js +316 -91
  8. package/dist/canvas/host/CanvasHostApi.d.ts +2 -2
  9. package/dist/canvas/host/CanvasHostApi.js +5 -1
  10. package/dist/canvas/host/nearCards.d.ts +33 -0
  11. package/dist/canvas/host/nearCards.js +78 -0
  12. package/dist/canvas/host/pageEvents.d.ts +16 -4
  13. package/dist/canvas/host/pageEvents.js +13 -4
  14. package/dist/canvas/host/pictureSaves.d.ts +33 -0
  15. package/dist/canvas/host/pictureSaves.js +42 -0
  16. package/dist/canvas/host/screenRects.d.ts +5 -0
  17. package/dist/canvas/host/storedPictures.d.ts +88 -0
  18. package/dist/canvas/host/storedPictures.js +288 -0
  19. package/dist/canvas/index.d.ts +2 -1
  20. package/dist/canvas/index.js +1 -1
  21. package/dist/canvas/shapes/shapeImageStore.d.ts +45 -2
  22. package/dist/canvas/shapes/shapeImageStore.js +7 -0
  23. package/dist/canvas/toolbarPosition.d.ts +2 -2
  24. package/dist/canvas/toolbarPosition.js +2 -2
  25. package/dist/canvas/types.d.ts +17 -0
  26. package/dist/canvas/ui/ColorField.svelte +7 -2
  27. package/dist/canvas/ui/SelectionPanel.svelte +56 -31
  28. package/dist/canvas/ui/SelectionPanel.svelte.d.ts +7 -0
  29. package/dist/canvas/ui/SelectorIndicator.svelte +81 -0
  30. package/dist/canvas/ui/SelectorIndicator.svelte.d.ts +11 -0
  31. package/dist/canvas/ui/ToolButton.svelte +11 -3
  32. package/dist/canvas/ui/floatingCard.d.ts +2 -2
  33. package/dist/canvas/ui/floatingCard.js +2 -2
  34. package/dist/canvas/ui/floatingLayer.d.ts +13 -2
  35. package/dist/canvas/ui/floatingLayer.js +14 -2
  36. package/dist/canvas/view/CanvasStage.svelte +101 -67
  37. package/dist/canvas/view/LeftToRightScope.svelte +21 -0
  38. package/dist/canvas/view/LeftToRightScope.svelte.d.ts +7 -0
  39. package/dist/canvas/view/ObjectView.svelte +15 -10
  40. package/dist/canvas/view/ObjectView.svelte.d.ts +1 -1
  41. package/dist/canvas/view/liftedScene.d.ts +31 -0
  42. package/dist/canvas/view/liftedScene.js +146 -0
  43. package/dist/canvas/view/mountedScene.d.ts +71 -0
  44. package/dist/canvas/view/mountedScene.js +363 -0
  45. package/dist/engine/EngineCore.d.ts +89 -1
  46. package/dist/engine/EngineCore.js +158 -4
  47. package/dist/engine/codec/canvasDocument.d.ts +5 -0
  48. package/dist/engine/codec/canvasDocument.js +31 -4
  49. package/dist/engine/core/cameraMove.d.ts +67 -0
  50. package/dist/engine/core/cameraMove.js +154 -0
  51. package/dist/engine/core/history.d.ts +6 -0
  52. package/dist/engine/core/history.js +16 -0
  53. package/dist/engine/core/scene.d.ts +10 -0
  54. package/dist/engine/core/scene.js +24 -0
  55. package/dist/engine/core/types.d.ts +8 -2
  56. package/dist/engine/input/PointerController.js +12 -0
  57. package/dist/engine/input/gestures.js +4 -2
  58. package/dist/engine/state.d.ts +20 -0
  59. package/dist/engine/state.js +1 -0
  60. package/dist/fonts/interFont.d.ts +10 -1
  61. package/dist/fonts/interFont.js +36 -13
  62. package/dist/i18n/language.d.ts +3 -3
  63. package/dist/i18n/messages.d.ts +8 -1
  64. package/dist/i18n/messages.js +9 -1
  65. package/dist/index.d.ts +2 -2
  66. package/dist/index.js +1 -1
  67. package/package.json +1 -1
  68. package/dist/canvas/ui/SelectorBar.svelte +0 -84
  69. package/dist/canvas/ui/SelectorBar.svelte.d.ts +0 -12
@@ -0,0 +1,154 @@
1
+ /**
2
+ * Moving the view the way a camera moves: from where it looks now to a place it is asked to look at, with the position and the
3
+ * zoom changing together, on one eased progress, and ending exactly on the place.
4
+ *
5
+ * A view is what the board looks at (`CameraView`): the point of the world in the middle of the board element, and the zoom (1 is
6
+ * 100%). The viewport the engine keeps (`x`, `y`, `zoom`) is worked out from it for the size of the board at that moment, so a board
7
+ * that is resized on the way still ends with the place in its middle.
8
+ *
9
+ * There are two shapes of path between two views (`CameraPathShape`):
10
+ *
11
+ * - `'ease'`, the default: the position and the zoom ease together. The centre goes in a straight line and the zoom changes by the
12
+ * same factor at every step, both on the one eased progress, so they start, speed up, slow down and arrive at the same moment, and
13
+ * the zoom never goes beyond its two ends. This is what "ease the position and the zoom at the same time" asks for.
14
+ * - `'fly'`: the path of van Wijk and Nuij, "Smooth and efficient zooming and panning" (2003), the one d3's `interpolateZoom` draws.
15
+ * A view that only zooms moves like a plain zoom; a view that has to go far zooms out on the way and in again at the end, so what
16
+ * the person looks at does not rush past. The position and the zoom still ride on one progress, but not at the same rate (the view
17
+ * zooms out while it pans and in as it arrives), so it is not the plain ease above.
18
+ *
19
+ * Both last as long as the length of the van Wijk path says, so a move takes the same time whichever shape it has.
20
+ *
21
+ * Nothing here knows the clock or the page: the engine asks for the view at a progress, and a test asks for the same.
22
+ */
23
+ import { clampNumber } from './geometry.js';
24
+ import { clampZoom, screenToWorld } from './viewport.js';
25
+ /** The shape a move has when nobody chose one: the position and the zoom ease together. */
26
+ export const DEFAULT_CAMERA_PATH_SHAPE = 'ease';
27
+ /** The shortest a move lasts when nobody gave its length, in milliseconds: a shorter one is too quick for the eye to follow. */
28
+ export const CAMERA_MOVE_MIN_DURATION_MS = 380;
29
+ /** The longest a move lasts when nobody gave its length, in milliseconds: a long way across the board still takes under a second. */
30
+ export const CAMERA_MOVE_MAX_DURATION_MS = 1000;
31
+ /** The time for each unit of the length of a path, in milliseconds. */
32
+ export const CAMERA_MOVE_MS_PER_UNIT = 800;
33
+ /**
34
+ * How much the path zooms out on its way when the move is long (ρ in the paper). The square root of 2 is the value its authors
35
+ * found the most pleasing: a larger one zooms out more, and 0 would be a straight line.
36
+ */
37
+ const PATH_CURVATURE = Math.SQRT2;
38
+ /** A move whose centres are closer than this fraction of the narrower view is a plain zoom: there is nothing to pan. */
39
+ const PLAIN_ZOOM_DISTANCE_RATIO = 1e-6;
40
+ /** Two viewports less than this many pixels apart look the same to a person. */
41
+ const SAME_VIEWPORT_PIXELS = 0.5;
42
+ /** Two zooms that differ by less than this fraction look the same to a person. */
43
+ const SAME_ZOOM_RATIO = 1e-4;
44
+ /** The view that a viewport shows in a board element of `viewSize`. */
45
+ export function cameraOfViewport(viewport, viewSize) {
46
+ return { center: screenToWorld(viewport, { x: viewSize.width / 2, y: viewSize.height / 2 }), zoom: viewport.zoom };
47
+ }
48
+ /** The viewport that shows `camera` in a board element of `viewSize`. */
49
+ export function viewportOfCamera(camera, viewSize) {
50
+ return {
51
+ x: viewSize.width / 2 - camera.center.x * camera.zoom,
52
+ y: viewSize.height / 2 - camera.center.y * camera.zoom,
53
+ zoom: camera.zoom
54
+ };
55
+ }
56
+ /** Whether two viewports look the same to a person: less than half a pixel apart, with a zoom that differs by less than 0.01%. */
57
+ export function viewportsMatch(first, second) {
58
+ return (Math.abs(first.x - second.x) < SAME_VIEWPORT_PIXELS &&
59
+ Math.abs(first.y - second.y) < SAME_VIEWPORT_PIXELS &&
60
+ Math.abs(first.zoom - second.zoom) < SAME_ZOOM_RATIO * Math.max(first.zoom, second.zoom));
61
+ }
62
+ /** Slow start, quick middle, slow end: the way a person expects a camera to move. `progress` and the answer are between 0 and 1. */
63
+ export function easeInOutCubic(progress) {
64
+ const clampedProgress = clampNumber(progress, 0, 1);
65
+ return clampedProgress < 0.5 ? 4 * clampedProgress ** 3 : 1 - (-2 * clampedProgress + 2) ** 3 / 2;
66
+ }
67
+ function isUsableView(view) {
68
+ return Number.isFinite(view.center.x) && Number.isFinite(view.center.y) && Number.isFinite(view.zoom) && view.zoom > 0;
69
+ }
70
+ /** A zoom ratio this close to 1 (its logarithm is this close to 0) is no zoom: the centre then goes by the plain share of the progress. */
71
+ const NO_ZOOM_LOGARITHM = 1e-9;
72
+ /**
73
+ * The view between two views with no detour: the zoom changes by the same factor at every step, and the centre goes along the
74
+ * straight line between the two centres, the way it does when a person zooms about one fixed point of the board and pans nothing
75
+ * else.
76
+ *
77
+ * The centre is not simply `progress` of the way along that line. The world grows on screen by the same factor at every step, so
78
+ * once the zoom grows by more than about 2.7 times in all, the place would first be carried away from the middle of the board, and
79
+ * only then come back to it (the swing of a plain tween). Here the share of the line is
80
+ * `(1 - zoomRatio^-progress) / (1 - 1 / zoomRatio)`, with which the place only ever comes closer to the middle of the board, on
81
+ * screen, as the zoom goes on; with no change of zoom it is `progress` itself, and zooming out it is the same formula.
82
+ */
83
+ function straightView(from, to, progress) {
84
+ const zoomLogarithm = Math.log(to.zoom / from.zoom);
85
+ const lineShare = Math.abs(zoomLogarithm) < NO_ZOOM_LOGARITHM ? progress : Math.expm1(-progress * zoomLogarithm) / Math.expm1(-zoomLogarithm);
86
+ return {
87
+ center: { x: from.center.x + (to.center.x - from.center.x) * lineShare, y: from.center.y + (to.center.y - from.center.y) * lineShare },
88
+ zoom: clampZoom(from.zoom * Math.exp(zoomLogarithm * progress))
89
+ };
90
+ }
91
+ /**
92
+ * The path from one view to another, or `null` when there is no path to draw: the board has no size yet, or one of the views is not
93
+ * a view (a centre that is not a point, a zoom that is not above 0). The caller then puts the view in place at once.
94
+ *
95
+ * `shape` is how the view goes (see `CameraPathShape`): by default the position and the zoom ease together, and `'fly'` takes the
96
+ * path of van Wijk and Nuij. How long the move lasts comes from the length of that path whichever shape is asked for.
97
+ */
98
+ export function createCameraPath(from, to, viewSize, shape = DEFAULT_CAMERA_PATH_SHAPE) {
99
+ // The path measures a view by the width of the world it shows along the longer side of the board.
100
+ const extent = Math.max(viewSize.width, viewSize.height);
101
+ if (!(extent > 0) || !isUsableView(from) || !isUsableView(to))
102
+ return null;
103
+ const startWidth = extent / from.zoom;
104
+ const endWidth = extent / to.zoom;
105
+ const deltaX = to.center.x - from.center.x;
106
+ const deltaY = to.center.y - from.center.y;
107
+ const distance = Math.hypot(deltaX, deltaY);
108
+ let length;
109
+ let sampleAt;
110
+ if (distance < Math.min(startWidth, endWidth) * PLAIN_ZOOM_DISTANCE_RATIO) {
111
+ // Nothing to pan: a plain zoom, by the same factor at every step.
112
+ length = Math.log(endWidth / startWidth) / PATH_CURVATURE;
113
+ sampleAt = (progress) => ({ fraction: progress, width: startWidth * Math.exp(PATH_CURVATURE * length * progress) });
114
+ }
115
+ else {
116
+ const curvatureSquared = PATH_CURVATURE ** 2;
117
+ const widthGrowth = endWidth ** 2 - startWidth ** 2;
118
+ const panPart = curvatureSquared ** 2 * distance ** 2;
119
+ // `asinh` rather than the logarithm of the square root: for a view that zooms in a long way with a short pan, the
120
+ // difference of two nearly equal numbers would come out as 0.
121
+ const startAngle = -Math.asinh((widthGrowth + panPart) / (2 * startWidth * curvatureSquared * distance));
122
+ const endAngle = -Math.asinh((widthGrowth - panPart) / (2 * endWidth * curvatureSquared * distance));
123
+ length = (endAngle - startAngle) / PATH_CURVATURE;
124
+ sampleAt = (progress) => {
125
+ const along = PATH_CURVATURE * length * progress + startAngle;
126
+ return {
127
+ fraction: (startWidth / (curvatureSquared * distance)) * (Math.cosh(startAngle) * Math.tanh(along) - Math.sinh(startAngle)),
128
+ width: (startWidth * Math.cosh(startAngle)) / Math.cosh(along)
129
+ };
130
+ };
131
+ }
132
+ const pathLength = Number.isFinite(length) ? Math.abs(length) : 1;
133
+ return {
134
+ length: pathLength,
135
+ duration: clampNumber(pathLength * CAMERA_MOVE_MS_PER_UNIT, CAMERA_MOVE_MIN_DURATION_MS, CAMERA_MOVE_MAX_DURATION_MS),
136
+ at(progress) {
137
+ if (!Number.isFinite(progress) || progress <= 0)
138
+ return { center: { ...from.center }, zoom: from.zoom };
139
+ if (progress >= 1)
140
+ return { center: { ...to.center }, zoom: to.zoom };
141
+ // No detour: the centre and the zoom change at the same rate on the one progress, and arrive together.
142
+ if (shape !== 'fly')
143
+ return straightView(from, to, progress);
144
+ const sample = sampleAt(progress);
145
+ // A path that came out as something that is not a number (a move across a distance no board has) is walked in a straight line.
146
+ if (!Number.isFinite(sample.fraction) || !(sample.width > 0) || !Number.isFinite(sample.width))
147
+ return straightView(from, to, progress);
148
+ return {
149
+ center: { x: from.center.x + deltaX * sample.fraction, y: from.center.y + deltaY * sample.fraction },
150
+ zoom: clampZoom(extent / sample.width)
151
+ };
152
+ }
153
+ };
154
+ }
@@ -34,6 +34,12 @@ export declare class HistoryStack<State> {
34
34
  redo(): State | null;
35
35
  /** Replaces the current step without adding one (for a change that must not be undone on its own). */
36
36
  replaceCurrent(state: State): void;
37
+ /**
38
+ * Rewrites every step, the past and the future of the cursor too, with no step added (a repair that all of them must have, as
39
+ * a picture that arrived late: going back to a step from before it came must not take it away). A step that the rewrite
40
+ * leaves as it is keeps its identity, and a state that is held by two steps is rewritten once.
41
+ */
42
+ mapAll(rewrite: (state: State) => State): void;
37
43
  /** Forgets everything and starts again from this state (a canvas was loaded). */
38
44
  reset(state: State): void;
39
45
  }
@@ -61,6 +61,22 @@ export class HistoryStack {
61
61
  replaceCurrent(state) {
62
62
  this.entries[this.cursor] = state;
63
63
  }
64
+ /**
65
+ * Rewrites every step, the past and the future of the cursor too, with no step added (a repair that all of them must have, as
66
+ * a picture that arrived late: going back to a step from before it came must not take it away). A step that the rewrite
67
+ * leaves as it is keeps its identity, and a state that is held by two steps is rewritten once.
68
+ */
69
+ mapAll(rewrite) {
70
+ const rewritten = new Map();
71
+ this.entries = this.entries.map((entry) => {
72
+ let result = rewritten.get(entry);
73
+ if (result === undefined) {
74
+ result = rewrite(entry);
75
+ rewritten.set(entry, result);
76
+ }
77
+ return result;
78
+ });
79
+ }
64
80
  /** Forgets everything and starts again from this state (a canvas was loaded). */
65
81
  reset(state) {
66
82
  this.entries = [state];
@@ -49,6 +49,16 @@ export declare function flattenSceneTree(roots: readonly SceneNode[]): SceneObje
49
49
  /** Repairs a list of records into a valid scene: unique ids, groups before their members, no empty groups. */
50
50
  export declare function normalizeScene(scene: Scene): SceneObject[];
51
51
  export declare function addObjects(scene: Scene, objects: readonly SceneObject[]): SceneObject[];
52
+ /**
53
+ * Where something the person draws goes: on top of everything, except that it stays under the widget cards. The page lays
54
+ * the live widget over its card, so whatever is drawn after a widget stands has to go behind it, as the card does, and
55
+ * never hide it (and the sketch the widget was built from is not taken for the widget's content).
56
+ *
57
+ * The new objects go under the lowest card, or under the group that holds it. A card, and an object that is a member of
58
+ * a group already, keep the place the caller gave them (the end of the list), so adding a card, or a copy of a group,
59
+ * works as it always did. With no card on the board this is `addObjects`.
60
+ */
61
+ export declare function addObjectsBehindWidgetCards(scene: Scene, objects: readonly SceneObject[]): SceneObject[];
52
62
  /** Removes the objects and everything below them, then any group left with no members. */
53
63
  export declare function removeObjects(scene: Scene, ids: Iterable<ObjectId>): Scene;
54
64
  /** Changes one object. Returns the same scene when the object is missing or the patch changes nothing. */
@@ -238,6 +238,30 @@ function findSiblingList(roots, id) {
238
238
  export function addObjects(scene, objects) {
239
239
  return objects.length === 0 ? [...scene] : [...scene, ...objects];
240
240
  }
241
+ /**
242
+ * Where something the person draws goes: on top of everything, except that it stays under the widget cards. The page lays
243
+ * the live widget over its card, so whatever is drawn after a widget stands has to go behind it, as the card does, and
244
+ * never hide it (and the sketch the widget was built from is not taken for the widget's content).
245
+ *
246
+ * The new objects go under the lowest card, or under the group that holds it. A card, and an object that is a member of
247
+ * a group already, keep the place the caller gave them (the end of the list), so adding a card, or a copy of a group,
248
+ * works as it always did. With no card on the board this is `addObjects`.
249
+ */
250
+ export function addObjectsBehindWidgetCards(scene, objects) {
251
+ if (objects.length === 0)
252
+ return [...scene];
253
+ if (objects.some((object) => object.type === 'widget' || object.parentId !== null))
254
+ return [...scene, ...objects];
255
+ const lowestCard = scene.find((object) => object.type === 'widget');
256
+ if (!lowestCard)
257
+ return [...scene, ...objects];
258
+ // A group comes before its members in the list: the objects go before the group that holds the card, not between its members.
259
+ const unitId = topLevelAncestorId(indexScene(scene), lowestCard.id);
260
+ const at = scene.findIndex((object) => object.id === unitId);
261
+ if (at < 0)
262
+ return [...scene, ...objects];
263
+ return [...scene.slice(0, at), ...objects, ...scene.slice(at)];
264
+ }
241
265
  /** Removes the objects and everything below them, then any group left with no members. */
242
266
  export function removeObjects(scene, ids) {
243
267
  const doomed = withDescendantIds(scene, ids);
@@ -196,7 +196,10 @@ export interface TextObject extends ObjectBase, BoxProps {
196
196
  }
197
197
  export interface ImageObject extends ObjectBase, BoxProps {
198
198
  type: 'image';
199
- /** A `data:` or `http(s)` address, or null while the image is only a placeholder. */
199
+ /**
200
+ * A `data:` or `http(s)` address, or an object URL (`blob:`) the host's image store gave for `imageRef`, or null while the
201
+ * image is only a placeholder. An object URL is never written into the saved text: its `imageRef` is.
202
+ */
200
203
  src: string | null;
201
204
  /** The reference under which the host's image store keeps the bytes, when they are not inline. */
202
205
  imageRef: string | null;
@@ -215,7 +218,10 @@ export interface WidgetObject extends ObjectBase, BoxProps {
215
218
  widgetName: string | null;
216
219
  /** The widget the board is about (the host draws a mark around it in the advanced mode). */
217
220
  isPrimary: boolean;
218
- /** The last screenshot of the widget: inline bytes or an address. */
221
+ /**
222
+ * The last screenshot of the widget: inline bytes or an address (an object URL, `blob:`, is one the store gave for
223
+ * `thumbnailRef`: it is never written into the saved text, and `getWidgetShapeDataUrl` answers `null` for it).
224
+ */
219
225
  thumbnail: string | null;
220
226
  /** The reference under which the host's image store keeps the screenshot. */
221
227
  thumbnailRef: string | null;
@@ -112,6 +112,8 @@ export class PointerController {
112
112
  pointerDown(input) {
113
113
  this.#lastInput = input;
114
114
  this.#engine.cancelRotationReset();
115
+ // A press on the board takes the view back from a move that is on its way (see `EngineCore.flyTo`).
116
+ this.#engine.cancelViewportMove();
115
117
  this.#forgetStalePointers(input.time);
116
118
  this.#pointers.set(input.pointerId, { x: input.x, y: input.y, seenAt: input.time });
117
119
  this.#engine.lastPointerWorld = this.#engine.toWorld({ x: input.x, y: input.y });
@@ -278,6 +280,12 @@ export class PointerController {
278
280
  this.#begin(createMoveGesture(this.#context, input, moving, { onClick, immovable: this.#isHeldByLiveWidget(moving) }));
279
281
  return true;
280
282
  }
283
+ // Empty board, and this is the second press of a double click (or a double tap): the view eases back to 100%, with the middle of
284
+ // everything that is drawn in the middle of the board. The first press already cleared the selection.
285
+ if (doubleClick) {
286
+ engine.flyToContent();
287
+ return true;
288
+ }
281
289
  // Empty board. A finger pans (a tap clears the selection); a mouse drags a marquee.
282
290
  if (input.pointerType === 'touch') {
283
291
  this.#begin(createPanGesture(this.#context, input, { onTap: () => engine.clearSelection() }));
@@ -478,6 +486,10 @@ export class PointerController {
478
486
  pointerUp(input) {
479
487
  this.#lastInput = input;
480
488
  this.#pointers.delete(input.pointerId);
489
+ // A press that was dragged away from where it began was not a click, so the next press at that place is not its second half.
490
+ if (this.#lastClick && distanceBetween({ x: this.#lastClick.x, y: this.#lastClick.y }, { x: input.x, y: input.y }) > DOUBLE_CLICK_DISTANCE) {
491
+ this.#lastClick = null;
492
+ }
481
493
  if (this.#pinch) {
482
494
  if (this.#pointers.size < 2)
483
495
  this.#endPinch();
@@ -122,8 +122,10 @@ export function createMoveGesture(context, start, unitIds, options = {}) {
122
122
  }
123
123
  carried ??= movingShapeIds(startScene, [...moving]);
124
124
  engine.applyScene(translateShapes(startScene, carried, deltaX, deltaY), 'transient');
125
- // The handles step aside while the selection is carried: what is carried is all that is to be seen.
126
- engine.setOverlay({ guides, dragging: 'move' });
125
+ // The handles step aside while the selection is carried: what is carried is all that is to be seen. The board is also told
126
+ // what is carried, from which records and how far (`CarriedShapes`), so that it can draw a big selection as one layer and
127
+ // not as a new record for every shape at every step; the records written above are the same, and the engine reads only them.
128
+ engine.setOverlay({ guides, dragging: 'move', carry: { startRecords: engine.sceneIndex(startScene), shapeIds: carried, deltaX, deltaY } });
127
129
  };
128
130
  return {
129
131
  kind: 'move',
@@ -48,6 +48,24 @@ export interface VirtualCursor {
48
48
  y: number;
49
49
  angle: number;
50
50
  }
51
+ /**
52
+ * The shapes a drag carries, and how far: what the board needs to draw them as one layer while the pointer is down, with one
53
+ * move of the layer in place of one new record for every shape at every step (see `canvas/view/liftedScene.ts`).
54
+ *
55
+ * The engine does not depend on it: it writes the carried shapes' new records at every step all the same (the frame, the
56
+ * guides, the ties of the arrows, the host's own layers and the undo step all read them), so what this says is only the part
57
+ * of the truth that a view can use to draw the same board with less work. It is a new object at every step of the drag, with
58
+ * the same `startRecords` and `shapeIds` (the same objects, which is what tells a view that the drag is the same one).
59
+ */
60
+ export interface CarriedShapes {
61
+ /** The board as the drag began, by id: the records the carried shapes are drawn from for as long as the drag lasts. */
62
+ startRecords: ReadonlyMap<ObjectId, SceneObject>;
63
+ /** The shapes that are carried (shapes, never groups: a group is carried by its members). */
64
+ shapeIds: ReadonlySet<ObjectId>;
65
+ /** How far they have been carried since the drag began, in world units. */
66
+ deltaX: number;
67
+ deltaY: number;
68
+ }
51
69
  /** What the board draws on top of the objects while something is being done. */
52
70
  export interface EngineOverlay {
53
71
  /** The rectangle being dragged out to select (world units). */
@@ -67,6 +85,8 @@ export interface EngineOverlay {
67
85
  textDraft: Rect | null;
68
86
  /** What the selection is being put through. The frame follows it: the handles go while it is carried, the outline dashes while it is stretched. */
69
87
  dragging: SelectionDrag | null;
88
+ /** While the selection is carried: which shapes, from which records, and how far (a view may draw them as one layer). */
89
+ carry: CarriedShapes | null;
70
90
  /** The size or the angle shown in the middle of the selection while it is stretched or turned. */
71
91
  readout: Readout | null;
72
92
  /** The pointer drawn on a handle while the real one is hidden. */
@@ -13,6 +13,7 @@ export const EMPTY_OVERLAY = Object.freeze({
13
13
  preview: null,
14
14
  textDraft: null,
15
15
  dragging: null,
16
+ carry: null,
16
17
  readout: null,
17
18
  virtualCursor: null,
18
19
  erasing: Object.freeze([]),
@@ -1,5 +1,14 @@
1
1
  /**
2
2
  * Ensures Inter is loaded before text is measured (item B14). Host pages usually ship Inter via the design system.
3
+ *
4
+ * The page's own `@font-face` for Inter is what the canvas waits for. A page that does not declare Inter in its
5
+ * stylesheets can give the canvas the WOFF2 addresses of the font (`interFontSources`, URLs or `data:` URLs), and the
6
+ * canvas registers them as the family `Inter`. On its own the canvas asks nobody for a font file: on a page that is not
7
+ * ours (a partner's) a request for a path of its origin is a 404 in its logs, or a violation of its `font-src`.
3
8
  */
4
9
  export declare const INTER_FONT_FAMILY = "Inter";
5
- export declare function ensureInterFontLoaded(): Promise<void>;
10
+ /**
11
+ * Registers the Inter files the host gave (none by default) and waits for Inter to be usable, the host's or the page's own.
12
+ * It never rejects: when a file cannot be loaded the page's fonts are used and one warning says so.
13
+ */
14
+ export declare function ensureInterFontLoaded(sources?: readonly string[]): Promise<void>;
@@ -1,24 +1,46 @@
1
1
  /**
2
2
  * Ensures Inter is loaded before text is measured (item B14). Host pages usually ship Inter via the design system.
3
+ *
4
+ * The page's own `@font-face` for Inter is what the canvas waits for. A page that does not declare Inter in its
5
+ * stylesheets can give the canvas the WOFF2 addresses of the font (`interFontSources`, URLs or `data:` URLs), and the
6
+ * canvas registers them as the family `Inter`. On its own the canvas asks nobody for a font file: on a page that is not
7
+ * ours (a partner's) a request for a path of its origin is a 404 in its logs, or a violation of its `font-src`.
3
8
  */
4
9
  export const INTER_FONT_FAMILY = 'Inter';
5
- const INTER_SOURCES = [
6
- "url('/fonts/Inter/InterVariable.woff2') format('woff2')",
7
- "url('/fonts/Inter/Inter-Regular.woff2') format('woff2')"
8
- ];
9
- let interLoad = null;
10
- export function ensureInterFontLoaded() {
10
+ /** One load per list of addresses: the page's fonts are global, so asking twice for the same list changes nothing. */
11
+ const interLoads = new Map();
12
+ /** The `src` of a font face for one address the host gave. Quotes and backslashes are escaped, so an address cannot end the string. */
13
+ function toFontFaceSource(address) {
14
+ return `url("${address.replace(/["\\]/g, '\\$&')}") format('woff2')`;
15
+ }
16
+ /**
17
+ * Registers the Inter files the host gave (none by default) and waits for Inter to be usable, the host's or the page's own.
18
+ * It never rejects: when a file cannot be loaded the page's fonts are used and one warning says so.
19
+ */
20
+ export function ensureInterFontLoaded(sources = []) {
11
21
  if (typeof document === 'undefined')
12
22
  return Promise.resolve();
13
- if (interLoad)
14
- return interLoad;
15
- interLoad = (async () => {
16
- try {
17
- if (typeof FontFace !== 'undefined') {
18
- const face = new FontFace(INTER_FONT_FAMILY, INTER_SOURCES.join(', '), { weight: '100 900', style: 'normal', display: 'swap' });
23
+ const loadKey = sources.join('\n');
24
+ const existingLoad = interLoads.get(loadKey);
25
+ if (existingLoad)
26
+ return existingLoad;
27
+ const load = (async () => {
28
+ if (sources.length > 0 && typeof FontFace !== 'undefined' && document.fonts?.add) {
29
+ try {
30
+ const face = new FontFace(INTER_FONT_FAMILY, sources.map(toFontFaceSource).join(', '), {
31
+ weight: '100 900',
32
+ style: 'normal',
33
+ display: 'swap'
34
+ });
19
35
  const loaded = await face.load();
20
36
  document.fonts.add(loaded);
21
37
  }
38
+ catch (error) {
39
+ console.warn('Canvas: the Inter files the page gave could not be loaded, the fonts of the page are used', error);
40
+ }
41
+ }
42
+ // A failed file above must not skip this: it waits for whatever Inter the page declares itself.
43
+ try {
22
44
  if (document.fonts?.load) {
23
45
  await document.fonts.load('16px Inter');
24
46
  }
@@ -27,5 +49,6 @@ export function ensureInterFontLoaded() {
27
49
  console.warn('Canvas: Inter could not be preloaded, fallback fonts will be used', error);
28
50
  }
29
51
  })();
30
- return interLoad;
52
+ interLoads.set(loadKey, load);
53
+ return load;
31
54
  }
@@ -3,18 +3,18 @@ import { type MessageOverrides, type MessageProblem } from '@widgetic/design-sys
3
3
  * Called by the root component of a canvas while it is created, so everything inside it speaks the page's language.
4
4
  * It gives back the words as stores and `update(settings)` for when the page sets the language again.
5
5
  */
6
- export declare const provideCanvasLanguage: (initial: import("@widgetic/design-system/i18n").I18nSettings) => import("@widgetic/design-system/i18n").I18nHandle<"canvas.state.loading" | "canvas.state.initFailed" | "canvas.state.boardLabel" | "canvas.state.unsupported" | "canvas.state.invalid" | "canvas.state.dismiss" | "canvas.hint.title" | "canvas.hint.description" | "canvas.defaults.textBox" | "canvas.defaults.untitledShape" | "canvas.draw.widgetName" | "canvas.draw.widgetPreview" | "canvas.toolbar.label" | "canvas.tool.select" | "canvas.tool.hand" | "canvas.tool.erase" | "canvas.tool.draw" | "canvas.tool.arrow" | "canvas.tool.rectangle" | "canvas.tool.roundedRectangle" | "canvas.tool.triangle" | "canvas.tool.ellipse" | "canvas.tool.circle" | "canvas.tool.text" | "canvas.tool.selector" | "canvas.tool.image" | "canvas.tool.svg" | "canvas.tool.shapes" | "canvas.tool.moreShapes" | "canvas.tool.undo" | "canvas.tool.redo" | "canvas.menu.media" | "canvas.category.geometric" | "canvas.category.arrows" | "canvas.category.media" | "canvas.category.ui" | "canvas.category.symbols" | "canvas.shape.hexagon" | "canvas.shape.pentagon" | "canvas.shape.oval" | "canvas.shape.play" | "canvas.shape.pause" | "canvas.shape.stop" | "canvas.shape.rewind" | "canvas.shape.fastForward" | "canvas.shape.record" | "canvas.shape.arrowRight" | "canvas.shape.arrowLeft" | "canvas.shape.arrowUp" | "canvas.shape.arrowDown" | "canvas.shape.doubleArrow" | "canvas.shape.curvedArrow" | "canvas.shape.checkMark" | "canvas.shape.cross" | "canvas.shape.plus" | "canvas.shape.minus" | "canvas.shape.info" | "canvas.shape.warning" | "canvas.shape.star" | "canvas.shape.heart" | "canvas.shape.speechBubble" | "canvas.shape.rhombus" | "canvas.shape.lightning" | "canvas.shape.shield" | "canvas.action.cut" | "canvas.action.copy" | "canvas.action.paste" | "canvas.action.duplicate" | "canvas.action.delete" | "canvas.action.group" | "canvas.action.ungroup" | "canvas.action.selectAll" | "canvas.layer.title" | "canvas.layer.front" | "canvas.layer.forward" | "canvas.layer.backward" | "canvas.layer.back" | "canvas.shortcuts.title" | "canvas.shortcuts.close" | "canvas.shortcuts.groupTools" | "canvas.shortcuts.groupSelection" | "canvas.shortcuts.groupHistory" | "canvas.shortcuts.groupZoom" | "canvas.shortcuts.drillThrough" | "canvas.shortcuts.redoAlt" | "canvas.shortcuts.save" | "canvas.shortcuts.zoomIn" | "canvas.shortcuts.zoomOut" | "canvas.shortcuts.zoomReset" | "canvas.shortcuts.fit" | "canvas.shortcuts.pan" | "canvas.shortcuts.move1" | "canvas.shortcuts.move10" | "canvas.key.ctrl" | "canvas.key.ctrlCmd" | "canvas.key.alt" | "canvas.key.shift" | "canvas.key.delete" | "canvas.key.space" | "canvas.key.click" | "canvas.key.drag" | "canvas.zoom.groupLabel" | "canvas.zoom.outLabel" | "canvas.zoom.inLabel" | "canvas.zoom.resetLabel" | "canvas.zoom.fitLabel" | "canvas.zoom.unsavedTitle" | "canvas.zoom.savedTitle" | "canvas.panel.label" | "canvas.panel.close" | "canvas.panel.open" | "canvas.panel.actions" | "canvas.panel.fill" | "canvas.panel.stroke" | "canvas.panel.strokeWidth" | "canvas.panel.roundness" | "canvas.panel.opacity" | "canvas.panel.fontSize" | "canvas.panel.decrease" | "canvas.panel.increase" | "canvas.panel.mixed" | "canvas.panel.none" | "canvas.panel.noColor" | "canvas.panel.pickColor" | "canvas.panel.hex" | "canvas.colorPicker.area" | "canvas.colorPicker.areaValue" | "canvas.colorPicker.hue" | "canvas.colorPicker.add" | "canvas.colorPicker.swatch" | "canvas.type.none" | "canvas.type.widget" | "canvas.type.drawing" | "canvas.type.group" | "canvas.type.selection" | "canvas.type.drawingOf" | "canvas.widget.createPreview" | "canvas.widget.capture" | "canvas.widget.linked" | "canvas.widget.converting" | "canvas.widget.duplicating" | "canvas.widget.linking" | "canvas.widget.unlinkedTitle" | "canvas.widget.orphanNotice" | "canvas.widget.removeFromCanvas" | "canvas.widget.namePlaceholder" | "canvas.widget.openDetails" | "canvas.widget.refreshPreview" | "canvas.widget.primary" | "canvas.widget.primaryTitle" | "canvas.widget.setPrimary" | "canvas.widget.unlinkedName" | "canvas.control.color" | "canvas.control.value" | "canvas.control.openPicker" | "canvas.control.removeColor" | "canvas.control.fontFamily" | "canvas.panel.fontGroupDefault" | "canvas.panel.fontGroupMore" | "canvas.panel.fontGroupWorkspace" | "canvas.control.textStyle" | "canvas.control.bold" | "canvas.control.boldMark" | "canvas.control.italic" | "canvas.control.italicMark" | "canvas.control.underline" | "canvas.control.underlineMark" | "canvas.control.textAlign" | "canvas.control.alignLeft" | "canvas.control.alignCenter" | "canvas.control.alignRight">;
6
+ export declare const provideCanvasLanguage: (initial: import("@widgetic/design-system/i18n").I18nSettings) => import("@widgetic/design-system/i18n").I18nHandle<"canvas.state.loading" | "canvas.state.initFailed" | "canvas.state.boardLabel" | "canvas.state.unsupported" | "canvas.state.invalid" | "canvas.state.dismiss" | "canvas.hint.title" | "canvas.hint.description" | "canvas.defaults.textBox" | "canvas.defaults.untitledShape" | "canvas.draw.widgetName" | "canvas.toolbar.label" | "canvas.tool.select" | "canvas.tool.hand" | "canvas.tool.erase" | "canvas.tool.draw" | "canvas.tool.arrow" | "canvas.tool.rectangle" | "canvas.tool.roundedRectangle" | "canvas.tool.triangle" | "canvas.tool.ellipse" | "canvas.tool.circle" | "canvas.tool.text" | "canvas.tool.selector" | "canvas.tool.image" | "canvas.tool.svg" | "canvas.tool.shapes" | "canvas.tool.moreShapes" | "canvas.tool.undo" | "canvas.tool.redo" | "canvas.selector.on" | "canvas.selector.off" | "canvas.selector.offHint" | "canvas.selector.dismiss" | "canvas.menu.media" | "canvas.category.geometric" | "canvas.category.arrows" | "canvas.category.media" | "canvas.category.ui" | "canvas.category.symbols" | "canvas.shape.hexagon" | "canvas.shape.pentagon" | "canvas.shape.oval" | "canvas.shape.play" | "canvas.shape.pause" | "canvas.shape.stop" | "canvas.shape.rewind" | "canvas.shape.fastForward" | "canvas.shape.record" | "canvas.shape.arrowRight" | "canvas.shape.arrowLeft" | "canvas.shape.arrowUp" | "canvas.shape.arrowDown" | "canvas.shape.doubleArrow" | "canvas.shape.curvedArrow" | "canvas.shape.checkMark" | "canvas.shape.cross" | "canvas.shape.plus" | "canvas.shape.minus" | "canvas.shape.info" | "canvas.shape.warning" | "canvas.shape.star" | "canvas.shape.heart" | "canvas.shape.speechBubble" | "canvas.shape.rhombus" | "canvas.shape.lightning" | "canvas.shape.shield" | "canvas.action.cut" | "canvas.action.copy" | "canvas.action.paste" | "canvas.action.duplicate" | "canvas.action.delete" | "canvas.action.group" | "canvas.action.ungroup" | "canvas.action.selectAll" | "canvas.layer.title" | "canvas.layer.front" | "canvas.layer.forward" | "canvas.layer.backward" | "canvas.layer.back" | "canvas.shortcuts.title" | "canvas.shortcuts.close" | "canvas.shortcuts.groupTools" | "canvas.shortcuts.groupSelection" | "canvas.shortcuts.groupHistory" | "canvas.shortcuts.groupZoom" | "canvas.shortcuts.drillThrough" | "canvas.shortcuts.redoAlt" | "canvas.shortcuts.save" | "canvas.shortcuts.zoomIn" | "canvas.shortcuts.zoomOut" | "canvas.shortcuts.zoomReset" | "canvas.shortcuts.fit" | "canvas.shortcuts.pan" | "canvas.shortcuts.move1" | "canvas.shortcuts.move10" | "canvas.key.ctrl" | "canvas.key.ctrlCmd" | "canvas.key.alt" | "canvas.key.shift" | "canvas.key.delete" | "canvas.key.space" | "canvas.key.click" | "canvas.key.drag" | "canvas.zoom.groupLabel" | "canvas.zoom.outLabel" | "canvas.zoom.inLabel" | "canvas.zoom.resetLabel" | "canvas.zoom.fitLabel" | "canvas.zoom.unsavedTitle" | "canvas.zoom.savedTitle" | "canvas.panel.label" | "canvas.panel.close" | "canvas.panel.open" | "canvas.panel.actions" | "canvas.panel.fill" | "canvas.panel.stroke" | "canvas.panel.strokeWidth" | "canvas.panel.roundness" | "canvas.panel.opacity" | "canvas.panel.fontSize" | "canvas.panel.decrease" | "canvas.panel.increase" | "canvas.panel.mixed" | "canvas.panel.none" | "canvas.panel.noColor" | "canvas.panel.pickColor" | "canvas.panel.hex" | "canvas.colorPicker.area" | "canvas.colorPicker.areaValue" | "canvas.colorPicker.hue" | "canvas.colorPicker.add" | "canvas.colorPicker.swatch" | "canvas.type.none" | "canvas.type.widget" | "canvas.type.drawing" | "canvas.type.group" | "canvas.type.selection" | "canvas.type.drawingOf" | "canvas.widget.createPreview" | "canvas.widget.capture" | "canvas.widget.linked" | "canvas.widget.converting" | "canvas.widget.duplicating" | "canvas.widget.linking" | "canvas.widget.unlinkedTitle" | "canvas.widget.orphanNotice" | "canvas.widget.removeFromCanvas" | "canvas.widget.namePlaceholder" | "canvas.widget.openDetails" | "canvas.widget.refreshPreview" | "canvas.widget.primary" | "canvas.widget.primaryTitle" | "canvas.widget.setPrimary" | "canvas.widget.unlinkedName" | "canvas.control.color" | "canvas.control.value" | "canvas.control.openPicker" | "canvas.control.removeColor" | "canvas.control.fontFamily" | "canvas.panel.fontGroupDefault" | "canvas.panel.fontGroupMore" | "canvas.panel.fontGroupWorkspace" | "canvas.control.textStyle" | "canvas.control.bold" | "canvas.control.boldMark" | "canvas.control.italic" | "canvas.control.italicMark" | "canvas.control.underline" | "canvas.control.underlineMark" | "canvas.control.textAlign" | "canvas.control.alignLeft" | "canvas.control.alignCenter" | "canvas.control.alignRight">;
7
7
  /**
8
8
  * Called by a part of the canvas while it is created. Gives its words as stores, so a part that is already on the screen
9
9
  * changes when the page sets the language again. Outside a canvas (a part used on its own, such as the colour control)
10
10
  * it speaks English.
11
11
  */
12
- export declare const useCanvasLanguage: () => import("@widgetic/design-system/i18n").I18nContext<"canvas.state.loading" | "canvas.state.initFailed" | "canvas.state.boardLabel" | "canvas.state.unsupported" | "canvas.state.invalid" | "canvas.state.dismiss" | "canvas.hint.title" | "canvas.hint.description" | "canvas.defaults.textBox" | "canvas.defaults.untitledShape" | "canvas.draw.widgetName" | "canvas.draw.widgetPreview" | "canvas.toolbar.label" | "canvas.tool.select" | "canvas.tool.hand" | "canvas.tool.erase" | "canvas.tool.draw" | "canvas.tool.arrow" | "canvas.tool.rectangle" | "canvas.tool.roundedRectangle" | "canvas.tool.triangle" | "canvas.tool.ellipse" | "canvas.tool.circle" | "canvas.tool.text" | "canvas.tool.selector" | "canvas.tool.image" | "canvas.tool.svg" | "canvas.tool.shapes" | "canvas.tool.moreShapes" | "canvas.tool.undo" | "canvas.tool.redo" | "canvas.menu.media" | "canvas.category.geometric" | "canvas.category.arrows" | "canvas.category.media" | "canvas.category.ui" | "canvas.category.symbols" | "canvas.shape.hexagon" | "canvas.shape.pentagon" | "canvas.shape.oval" | "canvas.shape.play" | "canvas.shape.pause" | "canvas.shape.stop" | "canvas.shape.rewind" | "canvas.shape.fastForward" | "canvas.shape.record" | "canvas.shape.arrowRight" | "canvas.shape.arrowLeft" | "canvas.shape.arrowUp" | "canvas.shape.arrowDown" | "canvas.shape.doubleArrow" | "canvas.shape.curvedArrow" | "canvas.shape.checkMark" | "canvas.shape.cross" | "canvas.shape.plus" | "canvas.shape.minus" | "canvas.shape.info" | "canvas.shape.warning" | "canvas.shape.star" | "canvas.shape.heart" | "canvas.shape.speechBubble" | "canvas.shape.rhombus" | "canvas.shape.lightning" | "canvas.shape.shield" | "canvas.action.cut" | "canvas.action.copy" | "canvas.action.paste" | "canvas.action.duplicate" | "canvas.action.delete" | "canvas.action.group" | "canvas.action.ungroup" | "canvas.action.selectAll" | "canvas.layer.title" | "canvas.layer.front" | "canvas.layer.forward" | "canvas.layer.backward" | "canvas.layer.back" | "canvas.shortcuts.title" | "canvas.shortcuts.close" | "canvas.shortcuts.groupTools" | "canvas.shortcuts.groupSelection" | "canvas.shortcuts.groupHistory" | "canvas.shortcuts.groupZoom" | "canvas.shortcuts.drillThrough" | "canvas.shortcuts.redoAlt" | "canvas.shortcuts.save" | "canvas.shortcuts.zoomIn" | "canvas.shortcuts.zoomOut" | "canvas.shortcuts.zoomReset" | "canvas.shortcuts.fit" | "canvas.shortcuts.pan" | "canvas.shortcuts.move1" | "canvas.shortcuts.move10" | "canvas.key.ctrl" | "canvas.key.ctrlCmd" | "canvas.key.alt" | "canvas.key.shift" | "canvas.key.delete" | "canvas.key.space" | "canvas.key.click" | "canvas.key.drag" | "canvas.zoom.groupLabel" | "canvas.zoom.outLabel" | "canvas.zoom.inLabel" | "canvas.zoom.resetLabel" | "canvas.zoom.fitLabel" | "canvas.zoom.unsavedTitle" | "canvas.zoom.savedTitle" | "canvas.panel.label" | "canvas.panel.close" | "canvas.panel.open" | "canvas.panel.actions" | "canvas.panel.fill" | "canvas.panel.stroke" | "canvas.panel.strokeWidth" | "canvas.panel.roundness" | "canvas.panel.opacity" | "canvas.panel.fontSize" | "canvas.panel.decrease" | "canvas.panel.increase" | "canvas.panel.mixed" | "canvas.panel.none" | "canvas.panel.noColor" | "canvas.panel.pickColor" | "canvas.panel.hex" | "canvas.colorPicker.area" | "canvas.colorPicker.areaValue" | "canvas.colorPicker.hue" | "canvas.colorPicker.add" | "canvas.colorPicker.swatch" | "canvas.type.none" | "canvas.type.widget" | "canvas.type.drawing" | "canvas.type.group" | "canvas.type.selection" | "canvas.type.drawingOf" | "canvas.widget.createPreview" | "canvas.widget.capture" | "canvas.widget.linked" | "canvas.widget.converting" | "canvas.widget.duplicating" | "canvas.widget.linking" | "canvas.widget.unlinkedTitle" | "canvas.widget.orphanNotice" | "canvas.widget.removeFromCanvas" | "canvas.widget.namePlaceholder" | "canvas.widget.openDetails" | "canvas.widget.refreshPreview" | "canvas.widget.primary" | "canvas.widget.primaryTitle" | "canvas.widget.setPrimary" | "canvas.widget.unlinkedName" | "canvas.control.color" | "canvas.control.value" | "canvas.control.openPicker" | "canvas.control.removeColor" | "canvas.control.fontFamily" | "canvas.panel.fontGroupDefault" | "canvas.panel.fontGroupMore" | "canvas.panel.fontGroupWorkspace" | "canvas.control.textStyle" | "canvas.control.bold" | "canvas.control.boldMark" | "canvas.control.italic" | "canvas.control.italicMark" | "canvas.control.underline" | "canvas.control.underlineMark" | "canvas.control.textAlign" | "canvas.control.alignLeft" | "canvas.control.alignCenter" | "canvas.control.alignRight">;
12
+ export declare const useCanvasLanguage: () => import("@widgetic/design-system/i18n").I18nContext<"canvas.state.loading" | "canvas.state.initFailed" | "canvas.state.boardLabel" | "canvas.state.unsupported" | "canvas.state.invalid" | "canvas.state.dismiss" | "canvas.hint.title" | "canvas.hint.description" | "canvas.defaults.textBox" | "canvas.defaults.untitledShape" | "canvas.draw.widgetName" | "canvas.toolbar.label" | "canvas.tool.select" | "canvas.tool.hand" | "canvas.tool.erase" | "canvas.tool.draw" | "canvas.tool.arrow" | "canvas.tool.rectangle" | "canvas.tool.roundedRectangle" | "canvas.tool.triangle" | "canvas.tool.ellipse" | "canvas.tool.circle" | "canvas.tool.text" | "canvas.tool.selector" | "canvas.tool.image" | "canvas.tool.svg" | "canvas.tool.shapes" | "canvas.tool.moreShapes" | "canvas.tool.undo" | "canvas.tool.redo" | "canvas.selector.on" | "canvas.selector.off" | "canvas.selector.offHint" | "canvas.selector.dismiss" | "canvas.menu.media" | "canvas.category.geometric" | "canvas.category.arrows" | "canvas.category.media" | "canvas.category.ui" | "canvas.category.symbols" | "canvas.shape.hexagon" | "canvas.shape.pentagon" | "canvas.shape.oval" | "canvas.shape.play" | "canvas.shape.pause" | "canvas.shape.stop" | "canvas.shape.rewind" | "canvas.shape.fastForward" | "canvas.shape.record" | "canvas.shape.arrowRight" | "canvas.shape.arrowLeft" | "canvas.shape.arrowUp" | "canvas.shape.arrowDown" | "canvas.shape.doubleArrow" | "canvas.shape.curvedArrow" | "canvas.shape.checkMark" | "canvas.shape.cross" | "canvas.shape.plus" | "canvas.shape.minus" | "canvas.shape.info" | "canvas.shape.warning" | "canvas.shape.star" | "canvas.shape.heart" | "canvas.shape.speechBubble" | "canvas.shape.rhombus" | "canvas.shape.lightning" | "canvas.shape.shield" | "canvas.action.cut" | "canvas.action.copy" | "canvas.action.paste" | "canvas.action.duplicate" | "canvas.action.delete" | "canvas.action.group" | "canvas.action.ungroup" | "canvas.action.selectAll" | "canvas.layer.title" | "canvas.layer.front" | "canvas.layer.forward" | "canvas.layer.backward" | "canvas.layer.back" | "canvas.shortcuts.title" | "canvas.shortcuts.close" | "canvas.shortcuts.groupTools" | "canvas.shortcuts.groupSelection" | "canvas.shortcuts.groupHistory" | "canvas.shortcuts.groupZoom" | "canvas.shortcuts.drillThrough" | "canvas.shortcuts.redoAlt" | "canvas.shortcuts.save" | "canvas.shortcuts.zoomIn" | "canvas.shortcuts.zoomOut" | "canvas.shortcuts.zoomReset" | "canvas.shortcuts.fit" | "canvas.shortcuts.pan" | "canvas.shortcuts.move1" | "canvas.shortcuts.move10" | "canvas.key.ctrl" | "canvas.key.ctrlCmd" | "canvas.key.alt" | "canvas.key.shift" | "canvas.key.delete" | "canvas.key.space" | "canvas.key.click" | "canvas.key.drag" | "canvas.zoom.groupLabel" | "canvas.zoom.outLabel" | "canvas.zoom.inLabel" | "canvas.zoom.resetLabel" | "canvas.zoom.fitLabel" | "canvas.zoom.unsavedTitle" | "canvas.zoom.savedTitle" | "canvas.panel.label" | "canvas.panel.close" | "canvas.panel.open" | "canvas.panel.actions" | "canvas.panel.fill" | "canvas.panel.stroke" | "canvas.panel.strokeWidth" | "canvas.panel.roundness" | "canvas.panel.opacity" | "canvas.panel.fontSize" | "canvas.panel.decrease" | "canvas.panel.increase" | "canvas.panel.mixed" | "canvas.panel.none" | "canvas.panel.noColor" | "canvas.panel.pickColor" | "canvas.panel.hex" | "canvas.colorPicker.area" | "canvas.colorPicker.areaValue" | "canvas.colorPicker.hue" | "canvas.colorPicker.add" | "canvas.colorPicker.swatch" | "canvas.type.none" | "canvas.type.widget" | "canvas.type.drawing" | "canvas.type.group" | "canvas.type.selection" | "canvas.type.drawingOf" | "canvas.widget.createPreview" | "canvas.widget.capture" | "canvas.widget.linked" | "canvas.widget.converting" | "canvas.widget.duplicating" | "canvas.widget.linking" | "canvas.widget.unlinkedTitle" | "canvas.widget.orphanNotice" | "canvas.widget.removeFromCanvas" | "canvas.widget.namePlaceholder" | "canvas.widget.openDetails" | "canvas.widget.refreshPreview" | "canvas.widget.primary" | "canvas.widget.primaryTitle" | "canvas.widget.setPrimary" | "canvas.widget.unlinkedName" | "canvas.control.color" | "canvas.control.value" | "canvas.control.openPicker" | "canvas.control.removeColor" | "canvas.control.fontFamily" | "canvas.panel.fontGroupDefault" | "canvas.panel.fontGroupMore" | "canvas.panel.fontGroupWorkspace" | "canvas.control.textStyle" | "canvas.control.bold" | "canvas.control.boldMark" | "canvas.control.italic" | "canvas.control.italicMark" | "canvas.control.underline" | "canvas.control.underlineMark" | "canvas.control.textAlign" | "canvas.control.alignLeft" | "canvas.control.alignCenter" | "canvas.control.alignRight">;
13
13
  /**
14
14
  * The English `t` of the canvas, for code that has no component around it. The screens of the canvas get their words, in
15
15
  * the page's language, from `useCanvasLanguage`.
16
16
  */
17
- export declare const translateEnglish: import("@widgetic/design-system/i18n").Translate<"canvas.state.loading" | "canvas.state.initFailed" | "canvas.state.boardLabel" | "canvas.state.unsupported" | "canvas.state.invalid" | "canvas.state.dismiss" | "canvas.hint.title" | "canvas.hint.description" | "canvas.defaults.textBox" | "canvas.defaults.untitledShape" | "canvas.draw.widgetName" | "canvas.draw.widgetPreview" | "canvas.toolbar.label" | "canvas.tool.select" | "canvas.tool.hand" | "canvas.tool.erase" | "canvas.tool.draw" | "canvas.tool.arrow" | "canvas.tool.rectangle" | "canvas.tool.roundedRectangle" | "canvas.tool.triangle" | "canvas.tool.ellipse" | "canvas.tool.circle" | "canvas.tool.text" | "canvas.tool.selector" | "canvas.tool.image" | "canvas.tool.svg" | "canvas.tool.shapes" | "canvas.tool.moreShapes" | "canvas.tool.undo" | "canvas.tool.redo" | "canvas.menu.media" | "canvas.category.geometric" | "canvas.category.arrows" | "canvas.category.media" | "canvas.category.ui" | "canvas.category.symbols" | "canvas.shape.hexagon" | "canvas.shape.pentagon" | "canvas.shape.oval" | "canvas.shape.play" | "canvas.shape.pause" | "canvas.shape.stop" | "canvas.shape.rewind" | "canvas.shape.fastForward" | "canvas.shape.record" | "canvas.shape.arrowRight" | "canvas.shape.arrowLeft" | "canvas.shape.arrowUp" | "canvas.shape.arrowDown" | "canvas.shape.doubleArrow" | "canvas.shape.curvedArrow" | "canvas.shape.checkMark" | "canvas.shape.cross" | "canvas.shape.plus" | "canvas.shape.minus" | "canvas.shape.info" | "canvas.shape.warning" | "canvas.shape.star" | "canvas.shape.heart" | "canvas.shape.speechBubble" | "canvas.shape.rhombus" | "canvas.shape.lightning" | "canvas.shape.shield" | "canvas.action.cut" | "canvas.action.copy" | "canvas.action.paste" | "canvas.action.duplicate" | "canvas.action.delete" | "canvas.action.group" | "canvas.action.ungroup" | "canvas.action.selectAll" | "canvas.layer.title" | "canvas.layer.front" | "canvas.layer.forward" | "canvas.layer.backward" | "canvas.layer.back" | "canvas.shortcuts.title" | "canvas.shortcuts.close" | "canvas.shortcuts.groupTools" | "canvas.shortcuts.groupSelection" | "canvas.shortcuts.groupHistory" | "canvas.shortcuts.groupZoom" | "canvas.shortcuts.drillThrough" | "canvas.shortcuts.redoAlt" | "canvas.shortcuts.save" | "canvas.shortcuts.zoomIn" | "canvas.shortcuts.zoomOut" | "canvas.shortcuts.zoomReset" | "canvas.shortcuts.fit" | "canvas.shortcuts.pan" | "canvas.shortcuts.move1" | "canvas.shortcuts.move10" | "canvas.key.ctrl" | "canvas.key.ctrlCmd" | "canvas.key.alt" | "canvas.key.shift" | "canvas.key.delete" | "canvas.key.space" | "canvas.key.click" | "canvas.key.drag" | "canvas.zoom.groupLabel" | "canvas.zoom.outLabel" | "canvas.zoom.inLabel" | "canvas.zoom.resetLabel" | "canvas.zoom.fitLabel" | "canvas.zoom.unsavedTitle" | "canvas.zoom.savedTitle" | "canvas.panel.label" | "canvas.panel.close" | "canvas.panel.open" | "canvas.panel.actions" | "canvas.panel.fill" | "canvas.panel.stroke" | "canvas.panel.strokeWidth" | "canvas.panel.roundness" | "canvas.panel.opacity" | "canvas.panel.fontSize" | "canvas.panel.decrease" | "canvas.panel.increase" | "canvas.panel.mixed" | "canvas.panel.none" | "canvas.panel.noColor" | "canvas.panel.pickColor" | "canvas.panel.hex" | "canvas.colorPicker.area" | "canvas.colorPicker.areaValue" | "canvas.colorPicker.hue" | "canvas.colorPicker.add" | "canvas.colorPicker.swatch" | "canvas.type.none" | "canvas.type.widget" | "canvas.type.drawing" | "canvas.type.group" | "canvas.type.selection" | "canvas.type.drawingOf" | "canvas.widget.createPreview" | "canvas.widget.capture" | "canvas.widget.linked" | "canvas.widget.converting" | "canvas.widget.duplicating" | "canvas.widget.linking" | "canvas.widget.unlinkedTitle" | "canvas.widget.orphanNotice" | "canvas.widget.removeFromCanvas" | "canvas.widget.namePlaceholder" | "canvas.widget.openDetails" | "canvas.widget.refreshPreview" | "canvas.widget.primary" | "canvas.widget.primaryTitle" | "canvas.widget.setPrimary" | "canvas.widget.unlinkedName" | "canvas.control.color" | "canvas.control.value" | "canvas.control.openPicker" | "canvas.control.removeColor" | "canvas.control.fontFamily" | "canvas.panel.fontGroupDefault" | "canvas.panel.fontGroupMore" | "canvas.panel.fontGroupWorkspace" | "canvas.control.textStyle" | "canvas.control.bold" | "canvas.control.boldMark" | "canvas.control.italic" | "canvas.control.italicMark" | "canvas.control.underline" | "canvas.control.underlineMark" | "canvas.control.textAlign" | "canvas.control.alignLeft" | "canvas.control.alignCenter" | "canvas.control.alignRight">;
17
+ export declare const translateEnglish: import("@widgetic/design-system/i18n").Translate<"canvas.state.loading" | "canvas.state.initFailed" | "canvas.state.boardLabel" | "canvas.state.unsupported" | "canvas.state.invalid" | "canvas.state.dismiss" | "canvas.hint.title" | "canvas.hint.description" | "canvas.defaults.textBox" | "canvas.defaults.untitledShape" | "canvas.draw.widgetName" | "canvas.toolbar.label" | "canvas.tool.select" | "canvas.tool.hand" | "canvas.tool.erase" | "canvas.tool.draw" | "canvas.tool.arrow" | "canvas.tool.rectangle" | "canvas.tool.roundedRectangle" | "canvas.tool.triangle" | "canvas.tool.ellipse" | "canvas.tool.circle" | "canvas.tool.text" | "canvas.tool.selector" | "canvas.tool.image" | "canvas.tool.svg" | "canvas.tool.shapes" | "canvas.tool.moreShapes" | "canvas.tool.undo" | "canvas.tool.redo" | "canvas.selector.on" | "canvas.selector.off" | "canvas.selector.offHint" | "canvas.selector.dismiss" | "canvas.menu.media" | "canvas.category.geometric" | "canvas.category.arrows" | "canvas.category.media" | "canvas.category.ui" | "canvas.category.symbols" | "canvas.shape.hexagon" | "canvas.shape.pentagon" | "canvas.shape.oval" | "canvas.shape.play" | "canvas.shape.pause" | "canvas.shape.stop" | "canvas.shape.rewind" | "canvas.shape.fastForward" | "canvas.shape.record" | "canvas.shape.arrowRight" | "canvas.shape.arrowLeft" | "canvas.shape.arrowUp" | "canvas.shape.arrowDown" | "canvas.shape.doubleArrow" | "canvas.shape.curvedArrow" | "canvas.shape.checkMark" | "canvas.shape.cross" | "canvas.shape.plus" | "canvas.shape.minus" | "canvas.shape.info" | "canvas.shape.warning" | "canvas.shape.star" | "canvas.shape.heart" | "canvas.shape.speechBubble" | "canvas.shape.rhombus" | "canvas.shape.lightning" | "canvas.shape.shield" | "canvas.action.cut" | "canvas.action.copy" | "canvas.action.paste" | "canvas.action.duplicate" | "canvas.action.delete" | "canvas.action.group" | "canvas.action.ungroup" | "canvas.action.selectAll" | "canvas.layer.title" | "canvas.layer.front" | "canvas.layer.forward" | "canvas.layer.backward" | "canvas.layer.back" | "canvas.shortcuts.title" | "canvas.shortcuts.close" | "canvas.shortcuts.groupTools" | "canvas.shortcuts.groupSelection" | "canvas.shortcuts.groupHistory" | "canvas.shortcuts.groupZoom" | "canvas.shortcuts.drillThrough" | "canvas.shortcuts.redoAlt" | "canvas.shortcuts.save" | "canvas.shortcuts.zoomIn" | "canvas.shortcuts.zoomOut" | "canvas.shortcuts.zoomReset" | "canvas.shortcuts.fit" | "canvas.shortcuts.pan" | "canvas.shortcuts.move1" | "canvas.shortcuts.move10" | "canvas.key.ctrl" | "canvas.key.ctrlCmd" | "canvas.key.alt" | "canvas.key.shift" | "canvas.key.delete" | "canvas.key.space" | "canvas.key.click" | "canvas.key.drag" | "canvas.zoom.groupLabel" | "canvas.zoom.outLabel" | "canvas.zoom.inLabel" | "canvas.zoom.resetLabel" | "canvas.zoom.fitLabel" | "canvas.zoom.unsavedTitle" | "canvas.zoom.savedTitle" | "canvas.panel.label" | "canvas.panel.close" | "canvas.panel.open" | "canvas.panel.actions" | "canvas.panel.fill" | "canvas.panel.stroke" | "canvas.panel.strokeWidth" | "canvas.panel.roundness" | "canvas.panel.opacity" | "canvas.panel.fontSize" | "canvas.panel.decrease" | "canvas.panel.increase" | "canvas.panel.mixed" | "canvas.panel.none" | "canvas.panel.noColor" | "canvas.panel.pickColor" | "canvas.panel.hex" | "canvas.colorPicker.area" | "canvas.colorPicker.areaValue" | "canvas.colorPicker.hue" | "canvas.colorPicker.add" | "canvas.colorPicker.swatch" | "canvas.type.none" | "canvas.type.widget" | "canvas.type.drawing" | "canvas.type.group" | "canvas.type.selection" | "canvas.type.drawingOf" | "canvas.widget.createPreview" | "canvas.widget.capture" | "canvas.widget.linked" | "canvas.widget.converting" | "canvas.widget.duplicating" | "canvas.widget.linking" | "canvas.widget.unlinkedTitle" | "canvas.widget.orphanNotice" | "canvas.widget.removeFromCanvas" | "canvas.widget.namePlaceholder" | "canvas.widget.openDetails" | "canvas.widget.refreshPreview" | "canvas.widget.primary" | "canvas.widget.primaryTitle" | "canvas.widget.setPrimary" | "canvas.widget.unlinkedName" | "canvas.control.color" | "canvas.control.value" | "canvas.control.openPicker" | "canvas.control.removeColor" | "canvas.control.fontFamily" | "canvas.panel.fontGroupDefault" | "canvas.panel.fontGroupMore" | "canvas.panel.fontGroupWorkspace" | "canvas.control.textStyle" | "canvas.control.bold" | "canvas.control.boldMark" | "canvas.control.italic" | "canvas.control.italicMark" | "canvas.control.underline" | "canvas.control.underlineMark" | "canvas.control.textAlign" | "canvas.control.alignLeft" | "canvas.control.alignCenter" | "canvas.control.alignRight">;
18
18
  /**
19
19
  * Checks a page's `messages` against the canvas's catalog without showing anything: a key that does not exist (with the
20
20
  * nearest real one), a value that is not text, a template that does not parse, or one that asks for a value the message
@@ -31,7 +31,6 @@ export declare const CANVAS_MESSAGES: {
31
31
  readonly 'canvas.defaults.untitledShape': "Untitled Shape";
32
32
  /** What a widget on the canvas is called until it has a name. */
33
33
  readonly 'canvas.draw.widgetName': "Widget";
34
- readonly 'canvas.draw.widgetPreview': "Widget preview";
35
34
  /** The name of the bar of tools, for a screen reader. */
36
35
  readonly 'canvas.toolbar.label': "Canvas tools";
37
36
  readonly 'canvas.tool.select': "Select";
@@ -52,6 +51,14 @@ export declare const CANVAS_MESSAGES: {
52
51
  readonly 'canvas.tool.moreShapes': "More shapes";
53
52
  readonly 'canvas.tool.undo': "Undo";
54
53
  readonly 'canvas.tool.redo': "Redo";
54
+ /** Said while the Select tool picks elements of the widget. */
55
+ readonly 'canvas.selector.on': "Selector on";
56
+ /** Said while another tool is chosen. */
57
+ readonly 'canvas.selector.off': "Selector off";
58
+ /** Said beside "Selector off": what to do to pick an element of the widget. */
59
+ readonly 'canvas.selector.offHint': "Choose the Select tool to pick an element of your widget.";
60
+ /** The name of the button that closes the indicator. */
61
+ readonly 'canvas.selector.dismiss': "Hide the selector hint";
55
62
  /** The group of image and SVG in the menu of shapes. */
56
63
  readonly 'canvas.menu.media': "Media";
57
64
  /** The groups of the shape library. */
@@ -35,7 +35,6 @@ export const CANVAS_MESSAGES = {
35
35
  // ===== Words drawn onto the canvas itself (on a widget card) =====
36
36
  /** What a widget on the canvas is called until it has a name. */
37
37
  'canvas.draw.widgetName': 'Widget',
38
- 'canvas.draw.widgetPreview': 'Widget preview',
39
38
  // ===== The names of the tools (also the names of the buttons that choose them) =====
40
39
  /** The name of the bar of tools, for a screen reader. */
41
40
  'canvas.toolbar.label': 'Canvas tools',
@@ -57,6 +56,15 @@ export const CANVAS_MESSAGES = {
57
56
  'canvas.tool.moreShapes': 'More shapes',
58
57
  'canvas.tool.undo': 'Undo',
59
58
  'canvas.tool.redo': 'Redo',
59
+ // ===== The selector's indicator (the hint at the top of the board while a widget stands on it) =====
60
+ /** Said while the Select tool picks elements of the widget. */
61
+ 'canvas.selector.on': 'Selector on',
62
+ /** Said while another tool is chosen. */
63
+ 'canvas.selector.off': 'Selector off',
64
+ /** Said beside "Selector off": what to do to pick an element of the widget. */
65
+ 'canvas.selector.offHint': 'Choose the Select tool to pick an element of your widget.',
66
+ /** The name of the button that closes the indicator. */
67
+ 'canvas.selector.dismiss': 'Hide the selector hint',
60
68
  // ===== The menu of shapes under the toolbar =====
61
69
  /** The group of image and SVG in the menu of shapes. */
62
70
  'canvas.menu.media': 'Media',
package/dist/index.d.ts CHANGED
@@ -7,12 +7,12 @@
7
7
  * - Dynamic: const { Canvas } = await import('@widgetic/canvas')
8
8
  */
9
9
  export { Canvas } from './canvas';
10
- export type { WidgetConversionPayload, StrokeRecognizer, StrokeRecognitionRequest, StrokeRecognitionResult } from './canvas';
10
+ export type { WidgetConversionPayload, StrokeRecognizer, StrokeRecognitionRequest, StrokeRecognitionResult, CanvasFlyOptions, CanvasMoveOptions } from './canvas';
11
11
  export { TOOLBAR_POSITIONS, DEFAULT_TOOLBAR_POSITION } from './canvas';
12
12
  export type { ToolbarPosition } from './canvas';
13
13
  export { PAN_ZOOM_POSITIONS, DEFAULT_PAN_ZOOM_POSITION } from './canvas';
14
14
  export type { PanZoomPosition } from './canvas';
15
- export { setShapeImageStore, getShapeImageStore } from './canvas';
15
+ export { setShapeImageStore, getShapeImageStore, SHAPE_IMAGE_STORE_OBJECT_URLS } from './canvas';
16
16
  export type { ShapeImageStore } from './canvas';
17
17
  export { Tooltip, ColorIC, FontSelectorIC, SliderUnitIC, TextAlignIC, TextStyleIC } from './components';
18
18
  export { setCanvasPreferenceStorage, getCanvasPreferenceStorage } from './components';
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ export { TOOLBAR_POSITIONS, DEFAULT_TOOLBAR_POSITION } from './canvas';
13
13
  // Where the zoom control stands: one of the same eight places (the `panZoomPosition` option of <Canvas>)
14
14
  export { PAN_ZOOM_POSITIONS, DEFAULT_PAN_ZOOM_POSITION } from './canvas';
15
15
  // Widget thumbnails live outside the canvas JSON when the host installs a store
16
- export { setShapeImageStore, getShapeImageStore } from './canvas';
16
+ export { setShapeImageStore, getShapeImageStore, SHAPE_IMAGE_STORE_OBJECT_URLS } from './canvas';
17
17
  // Lightweight components (safe for static import)
18
18
  export { Tooltip, ColorIC, FontSelectorIC, SliderUnitIC, TextAlignIC, TextStyleIC } from './components';
19
19
  // The visitor's choices (saved colors) live in localStorage unless the host installs a store of its own