@widgetic/canvas 0.5.41 → 0.5.43

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 (131) hide show
  1. package/README.md +1 -0
  2. package/dist/canvas/DomCanvas.svelte +49 -20
  3. package/dist/canvas/DomCanvas.svelte.d.ts +13 -7
  4. package/dist/canvas/autosaveScheduler.js +37 -89
  5. package/dist/canvas/boardFrame.js +1 -1
  6. package/dist/canvas/boardSurface.js +1 -1
  7. package/dist/canvas/canvasLogger.js +7 -19
  8. package/dist/canvas/chromeLayout.d.ts +14 -3
  9. package/dist/canvas/chromeLayout.js +30 -20
  10. package/dist/canvas/eventScope.js +10 -14
  11. package/dist/canvas/host/CanvasHost.d.ts +47 -5
  12. package/dist/canvas/host/CanvasHost.js +1481 -1566
  13. package/dist/canvas/host/CanvasHostApi.js +4 -19
  14. package/dist/canvas/host/browserServices.js +65 -116
  15. package/dist/canvas/host/conversion.js +82 -170
  16. package/dist/canvas/host/hostObject.js +7 -7
  17. package/dist/canvas/host/nearCards.d.ts +33 -0
  18. package/dist/canvas/host/nearCards.js +78 -0
  19. package/dist/canvas/host/pageEvents.d.ts +16 -4
  20. package/dist/canvas/host/pageEvents.js +17 -8
  21. package/dist/canvas/host/pictureSaves.d.ts +33 -0
  22. package/dist/canvas/host/pictureSaves.js +42 -0
  23. package/dist/canvas/host/screenRects.d.ts +5 -0
  24. package/dist/canvas/host/screenRects.js +28 -31
  25. package/dist/canvas/host/storedPictures.d.ts +88 -0
  26. package/dist/canvas/host/storedPictures.js +288 -0
  27. package/dist/canvas/host/strokeSnap.js +88 -143
  28. package/dist/canvas/index.d.ts +1 -1
  29. package/dist/canvas/index.js +1 -1
  30. package/dist/canvas/openMarks.js +2 -2
  31. package/dist/canvas/outsideClickDeselect.js +6 -7
  32. package/dist/canvas/panZoomPosition.js +2 -2
  33. package/dist/canvas/preferredTextFont.js +13 -25
  34. package/dist/canvas/shapes/ShapeLibrary.js +138 -148
  35. package/dist/canvas/shapes/shapeImageStore.d.ts +45 -2
  36. package/dist/canvas/shapes/shapeImageStore.js +10 -3
  37. package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
  38. package/dist/canvas/toolbarPosition.d.ts +2 -2
  39. package/dist/canvas/toolbarPosition.js +4 -4
  40. package/dist/canvas/ui/SelectionPanel.svelte +28 -5
  41. package/dist/canvas/ui/SelectionPanel.svelte.d.ts +7 -0
  42. package/dist/canvas/ui/SelectorIndicator.svelte +81 -0
  43. package/dist/canvas/ui/SelectorIndicator.svelte.d.ts +11 -0
  44. package/dist/canvas/ui/ToolButton.svelte +8 -2
  45. package/dist/canvas/ui/colorModel.js +21 -32
  46. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  47. package/dist/canvas/ui/floatingCard.d.ts +2 -2
  48. package/dist/canvas/ui/floatingCard.js +20 -20
  49. package/dist/canvas/ui/floatingLayer.d.ts +13 -2
  50. package/dist/canvas/ui/floatingLayer.js +18 -7
  51. package/dist/canvas/ui/keyHints.js +9 -11
  52. package/dist/canvas/ui/popoverSide.js +2 -3
  53. package/dist/canvas/ui/selectionTraits.js +34 -40
  54. package/dist/canvas/view/CanvasStage.svelte +101 -67
  55. package/dist/canvas/view/LeftToRightScope.svelte +21 -0
  56. package/dist/canvas/view/LeftToRightScope.svelte.d.ts +7 -0
  57. package/dist/canvas/view/ObjectView.svelte +15 -10
  58. package/dist/canvas/view/ObjectView.svelte.d.ts +1 -1
  59. package/dist/canvas/view/erasingMarks.js +7 -7
  60. package/dist/canvas/view/geometry.js +71 -90
  61. package/dist/canvas/view/liftedScene.d.ts +31 -0
  62. package/dist/canvas/view/liftedScene.js +146 -0
  63. package/dist/canvas/view/mountedScene.d.ts +71 -0
  64. package/dist/canvas/view/mountedScene.js +363 -0
  65. package/dist/components/preferenceStorage.js +2 -2
  66. package/dist/engine/EngineCore.d.ts +15 -1
  67. package/dist/engine/EngineCore.js +724 -797
  68. package/dist/engine/codec/canvasDocument.d.ts +5 -0
  69. package/dist/engine/codec/canvasDocument.js +212 -149
  70. package/dist/engine/codec/hostReadableKeys.js +1 -1
  71. package/dist/engine/core/arrange.js +26 -38
  72. package/dist/engine/core/arrow.js +76 -89
  73. package/dist/engine/core/arrowBinding.js +98 -116
  74. package/dist/engine/core/arrowBindingRecords.js +23 -38
  75. package/dist/engine/core/brush.js +67 -94
  76. package/dist/engine/core/defaults.js +90 -51
  77. package/dist/engine/core/freehand.js +147 -163
  78. package/dist/engine/core/geometry.js +47 -54
  79. package/dist/engine/core/history.d.ts +6 -0
  80. package/dist/engine/core/history.js +49 -50
  81. package/dist/engine/core/hitTest.js +68 -81
  82. package/dist/engine/core/matrix.js +18 -20
  83. package/dist/engine/core/pathData.js +183 -210
  84. package/dist/engine/core/rotationReset.js +5 -6
  85. package/dist/engine/core/scene.d.ts +10 -0
  86. package/dist/engine/core/scene.js +153 -187
  87. package/dist/engine/core/scribble.js +59 -84
  88. package/dist/engine/core/shapePaths.js +12 -15
  89. package/dist/engine/core/shapeTools.js +72 -63
  90. package/dist/engine/core/snapping.js +65 -117
  91. package/dist/engine/core/style.js +31 -64
  92. package/dist/engine/core/transform.js +83 -94
  93. package/dist/engine/core/types.d.ts +8 -2
  94. package/dist/engine/core/types.js +4 -4
  95. package/dist/engine/core/viewport.js +23 -36
  96. package/dist/engine/input/PointerController.js +467 -474
  97. package/dist/engine/input/arrowHandles.js +12 -12
  98. package/dist/engine/input/gestures.js +265 -309
  99. package/dist/engine/input/hoverCursor.js +1 -1
  100. package/dist/engine/input/keyboard.js +27 -30
  101. package/dist/engine/input/selectionHandles.js +45 -50
  102. package/dist/engine/input/types.js +1 -1
  103. package/dist/engine/render/rasterize.js +86 -158
  104. package/dist/engine/state.d.ts +20 -0
  105. package/dist/engine/state.js +5 -15
  106. package/dist/engine/text/layoutText.js +43 -62
  107. package/dist/engine/text/textMetrics.js +8 -10
  108. package/dist/engine/widgets.js +101 -137
  109. package/dist/fonts/interFont.d.ts +10 -1
  110. package/dist/fonts/interFont.js +47 -75
  111. package/dist/fonts/workspaceFonts.js +32 -90
  112. package/dist/i18n/labels.js +4 -4
  113. package/dist/i18n/language.d.ts +3 -3
  114. package/dist/i18n/language.js +4 -4
  115. package/dist/i18n/messages.d.ts +8 -1
  116. package/dist/i18n/messages.js +10 -2
  117. package/dist/i18n/shortcuts.js +14 -14
  118. package/dist/index.d.ts +1 -1
  119. package/dist/index.js +1 -1
  120. package/dist/settings/workspaceToolSettings.js +32 -48
  121. package/dist/tools/components/catalog.js +64 -74
  122. package/dist/tools/components/grouping.js +6 -28
  123. package/dist/tools/definitions.js +5 -5
  124. package/dist/tools/executors.js +105 -141
  125. package/dist/tools/hostAdapter.js +11 -13
  126. package/dist/tools/sceneSummary.js +43 -57
  127. package/dist/tools/sketchIntent.js +13 -21
  128. package/dist/tools/types.js +1 -1
  129. package/package.json +1 -1
  130. package/dist/canvas/ui/SelectorBar.svelte +0 -84
  131. package/dist/canvas/ui/SelectorBar.svelte.d.ts +0 -12
@@ -9,13 +9,12 @@
9
9
  * The side is given as a function, so a card that the page moves while the canvas is open takes its tooltips with it.
10
10
  */
11
11
  import { getContext, setContext } from 'svelte';
12
- var POPOVER_SIDE_CONTEXT_KEY = Symbol('widgetic-canvas-popover-side');
12
+ const POPOVER_SIDE_CONTEXT_KEY = Symbol('widgetic-canvas-popover-side');
13
13
  /** Called by a card of the chrome, before its children are made. */
14
14
  export function providePopoverSide(getSide) {
15
15
  setContext(POPOVER_SIDE_CONTEXT_KEY, getSide);
16
16
  }
17
17
  /** The side to open a tooltip or a menu to. A button used outside a card of the chrome opens upward, as the bottom toolbar always did. */
18
18
  export function usePopoverSide() {
19
- var _a;
20
- return (_a = getContext(POPOVER_SIDE_CONTEXT_KEY)) !== null && _a !== void 0 ? _a : (function () { return 'top'; });
19
+ return getContext(POPOVER_SIDE_CONTEXT_KEY) ?? (() => 'top');
21
20
  }
@@ -5,26 +5,17 @@
5
5
  * of shape has is the engine's own rule (`style.ts` says which keys of a style patch a shape takes), so the panel never
6
6
  * offers a control that would change nothing.
7
7
  */
8
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
9
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
10
- if (ar || !(i in from)) {
11
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
12
- ar[i] = from[i];
13
- }
14
- }
15
- return to.concat(ar || Array.prototype.slice.call(from));
16
- };
17
8
  import { isArrow } from '../../engine/core/arrow.js';
18
9
  import { isBrushStroke } from '../../engine/core/brush.js';
19
10
  import { leafShapesOf, normalizeSelection } from '../../engine/core/scene.js';
20
11
  import { lineColorOf, paintsFillOnStroke, pathSupportsRoundness } from '../../engine/core/style.js';
21
- var NONE = { kind: 'none' };
12
+ const NONE = { kind: 'none' };
22
13
  /** One value out of many: the value they all have, `mixed` when they differ, `none` when there is nothing to compare. */
23
14
  export function unify(values) {
24
15
  if (values.length === 0)
25
16
  return NONE;
26
- var first = values[0];
27
- return values.every(function (value) { return Object.is(value, first); }) ? { kind: 'same', value: first } : { kind: 'mixed' };
17
+ const first = values[0];
18
+ return values.every((value) => Object.is(value, first)) ? { kind: 'same', value: first } : { kind: 'mixed' };
28
19
  }
29
20
  /** Whether a shape has a fill and a stroke of its own: the three kinds of vector shape. */
30
21
  function isVector(shape) {
@@ -32,43 +23,46 @@ function isVector(shape) {
32
23
  }
33
24
  /** Describes the selection for the panel. */
34
25
  export function describeSelection(scene, selectedIds) {
35
- var unitIds = normalizeSelection(scene, selectedIds);
36
- var unitIdSet = new Set(unitIds);
37
- var units = scene.filter(function (object) { return unitIdSet.has(object.id); });
38
- var shapes = leafShapesOf(scene, unitIds);
39
- var only = units.length === 1 ? units[0] : undefined;
40
- var widgetCard = only && only.type === 'widget' ? only : null;
26
+ const unitIds = normalizeSelection(scene, selectedIds);
27
+ const unitIdSet = new Set(unitIds);
28
+ const units = scene.filter((object) => unitIdSet.has(object.id));
29
+ const shapes = leafShapesOf(scene, unitIds);
30
+ const only = units.length === 1 ? units[0] : undefined;
31
+ const widgetCard = only && only.type === 'widget' ? only : null;
41
32
  // The card of a widget is the page's to style (it shows the widget): the panel does not paint it.
42
- var targets = shapes.filter(function (shape) { return shape.type !== 'widget'; });
43
- var vectors = targets.filter(isVector);
44
- var texts = targets.filter(function (shape) { return shape.type === 'text'; });
33
+ const targets = shapes.filter((shape) => shape.type !== 'widget');
34
+ const vectors = targets.filter(isVector);
35
+ const texts = targets.filter((shape) => shape.type === 'text');
45
36
  // A brush stroke is a filled outline, but to a person it is a line: its colour is the Stroke, and it has no Fill. An arrow is a line too.
46
- var fillValues = __spreadArray(__spreadArray([], vectors
47
- .filter(function (shape) { return !isBrushStroke(shape) && !isArrow(shape); })
48
- .map(function (shape) { return (paintsFillOnStroke(shape) ? shape.stroke : shape.fill); }), true), texts.map(function (shape) { return shape.color; }), true);
49
- var strokeValues = vectors.filter(function (shape) { return !paintsFillOnStroke(shape); }).map(lineColorOf);
50
- var roundnessValues = vectors
51
- .filter(function (shape) { return shape.type === 'rect' || (shape.type === 'path' && pathSupportsRoundness(shape.shape)); })
52
- .map(function (shape) { return (shape.type === 'rect' || shape.type === 'path' ? shape.roundness : 0); });
37
+ const fillValues = [
38
+ ...vectors
39
+ .filter((shape) => !isBrushStroke(shape) && !isArrow(shape))
40
+ .map((shape) => (paintsFillOnStroke(shape) ? shape.stroke : shape.fill)),
41
+ ...texts.map((shape) => shape.color)
42
+ ];
43
+ const strokeValues = vectors.filter((shape) => !paintsFillOnStroke(shape)).map(lineColorOf);
44
+ const roundnessValues = vectors
45
+ .filter((shape) => shape.type === 'rect' || (shape.type === 'path' && pathSupportsRoundness(shape.shape)))
46
+ .map((shape) => (shape.type === 'rect' || shape.type === 'path' ? shape.roundness : 0));
53
47
  return {
54
- targets: targets,
55
- units: units,
48
+ targets,
49
+ units,
56
50
  fill: unify(fillValues),
57
51
  stroke: unify(strokeValues),
58
- strokeWidth: unify(vectors.map(function (shape) { return shape.strokeWidth; })),
52
+ strokeWidth: unify(vectors.map((shape) => shape.strokeWidth)),
59
53
  roundness: unify(roundnessValues),
60
- opacity: unify(targets.map(function (shape) { return shape.opacity; })),
54
+ opacity: unify(targets.map((shape) => shape.opacity)),
61
55
  text: texts.length === 0
62
56
  ? null
63
57
  : {
64
- fontSize: unify(texts.map(function (shape) { return shape.fontSize; })),
65
- fontFamily: unify(texts.map(function (shape) { return shape.fontFamily; })),
66
- bold: unify(texts.map(function (shape) { return shape.fontWeight === 'bold'; })),
67
- italic: unify(texts.map(function (shape) { return shape.fontStyle === 'italic'; })),
68
- underline: unify(texts.map(function (shape) { return shape.underline; })),
69
- align: unify(texts.map(function (shape) { return shape.align; }))
58
+ fontSize: unify(texts.map((shape) => shape.fontSize)),
59
+ fontFamily: unify(texts.map((shape) => shape.fontFamily)),
60
+ bold: unify(texts.map((shape) => shape.fontWeight === 'bold')),
61
+ italic: unify(texts.map((shape) => shape.fontStyle === 'italic')),
62
+ underline: unify(texts.map((shape) => shape.underline)),
63
+ align: unify(texts.map((shape) => shape.align))
70
64
  },
71
- widgetCard: widgetCard
65
+ widgetCard
72
66
  };
73
67
  }
74
68
  /** The number of a trait for a control, or a fallback when the shapes differ or the control does not apply. */
@@ -95,7 +89,7 @@ export function showStrokeColorRow(traits, wireframeMode) {
95
89
  return false;
96
90
  if (!wireframeMode)
97
91
  return true;
98
- return traits.targets.some(function (shape) {
92
+ return traits.targets.some((shape) => {
99
93
  if (shape.type === 'rect' || shape.type === 'ellipse')
100
94
  return false;
101
95
  if (shape.type !== 'path')
@@ -4,9 +4,14 @@
4
4
 
5
5
  It draws what the engine's state says and nothing else. A press, a move and a release go to the host, which gives them
6
6
  to the engine's pointer controller; the wheel is the host's own listener (it must not be passive). The board is a drawing:
7
- what is at its left stays at its left and text is read left to right on every screen, so it is `dir="ltr"`.
7
+ what is at its left stays at its left and text is read left to right on every screen, so it sits in a `dir="ltr"` element
8
+ (`LeftToRightScope`: the attribute is not on the board's own element, which changes at every frame of a pan, see there).
9
+
10
+ On a big board only the objects near the view are elements of the world layer (`mountedScene.ts`): the work of a pan, a zoom
11
+ or a drag is then the work of what is near the view, and not of everything that is on the board.
8
12
  -->
9
13
  <script lang="ts">
14
+ import { onDestroy } from 'svelte';
10
15
  import { DEFAULT_WIDGET_RUNTIME } from '../../engine/state.js';
11
16
  import type { EngineState } from '../../engine/state.js';
12
17
  import { useCanvasLanguage } from '../../i18n/language.js';
@@ -15,11 +20,14 @@
15
20
  import CanvasHint from '../ui/CanvasHint.svelte';
16
21
  import LoadNotice from '../ui/LoadNotice.svelte';
17
22
  import EraserTrail from './EraserTrail.svelte';
23
+ import LeftToRightScope from './LeftToRightScope.svelte';
18
24
  import ObjectView from './ObjectView.svelte';
19
25
  import SelectionOverlay from './SelectionOverlay.svelte';
20
26
  import TextEditor from './TextEditor.svelte';
21
27
  import { createErasingMarks } from './erasingMarks.js';
22
28
  import { BOARD_SURFACE_COLOR, cssCursor, dotGridStyle } from './geometry.js';
29
+ import { createLiftedView } from './liftedScene.js';
30
+ import { createMountedScene } from './mountedScene.js';
23
31
 
24
32
  interface Props {
25
33
  host: CanvasHost;
@@ -41,7 +49,6 @@
41
49
  let { host, state, ui, advancedFeatures, loading, showEmptyBoardHint, frameElsewhere, board = $bindable(null) }: Props = $props();
42
50
 
43
51
  const { t } = useCanvasLanguage();
44
- const worldTransform = $derived(`translate(${state.viewport.x}px, ${state.viewport.y}px) scale(${state.viewport.zoom})`);
45
52
  // The shapes the eraser has marked, as a set: each object asks whether it is one of them. A store of its own, told only
46
53
  // when the eraser's list is replaced, and not something derived from `state`: `state` is a new object at every frame of a
47
54
  // pan or a drag, and an object that asked something derived from it would be checked again at every one of them (see
@@ -49,6 +56,32 @@
49
56
  const erasingMarks = createErasingMarks();
50
57
  $effect.pre(() => erasingMarks.take(state.overlay.erasing));
51
58
 
59
+ // The objects that have an element: the ones near the view, once the board is big (see `mountedScene.ts`). A store of its own
60
+ // for the same reason as the eraser's marks: the list is a different one only when an object comes near, goes far, or is
61
+ // changed, and a pan that does none of that must not make the list of objects look again at every one of them.
62
+ const mountedScene = createMountedScene();
63
+ function updateMountedScene(): void {
64
+ mountedScene.take({ scene: state.scene, viewport: state.viewport, viewSize: state.viewSize, editingTextId: state.editingTextId });
65
+ }
66
+ // Once now, for a board that is drawn where effects do not run (the server); the effect keeps it up to date from then on.
67
+ updateMountedScene();
68
+ $effect.pre(updateMountedScene);
69
+ onDestroy(() => mountedScene.destroy());
70
+ // The list as a value of the component, and not as `$mountedScene` in the markup. Svelte cannot know that nobody changes the items
71
+ // of an each block over a store in place, so it makes every item mutable, and every one of them then counts as changed at every
72
+ // update of the list: a drag of one shape woke every object of the board, at every frame. Over a derived value the items are
73
+ // compared by identity and only the object that is a different record is told (held by `tests/view/stageUpdates.test.mjs`).
74
+ //
75
+ // While a big selection is carried, the objects are drawn from the records the drag began with and the world layer is moved by how
76
+ // far the selection has gone, so that a step of the drag writes the few objects that are not carried and not every one that is (see
77
+ // `liftedScene.ts`). At every other time `lifted` is the list as it is, and the world layer is moved by the view alone.
78
+ const liftedView = createLiftedView();
79
+ const lifted = $derived(liftedView.show($mountedScene, state.overlay.carry));
80
+ const mountedObjects = $derived(lifted.objects);
81
+ const worldTransform = $derived(
82
+ `translate(${state.viewport.x + lifted.offsetX * state.viewport.zoom}px, ${state.viewport.y + lifted.offsetY * state.viewport.zoom}px) scale(${state.viewport.zoom})`
83
+ );
84
+
52
85
  /** Hands the board element to the shell (the host is attached to it), and takes it back when the board goes. */
53
86
  function shareBoard(element: HTMLElement): () => void {
54
87
  board = element;
@@ -58,75 +91,76 @@
58
91
  }
59
92
  </script>
60
93
 
61
- <!-- A drawing surface for a pointer: it carries the focus for the shortcuts, and its name says what it is. -->
62
- <!-- No focus outline on the board: the ring was clipped by overflow and drew attention away from objects when Shift was held. -->
63
- <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
64
- <div
65
- {@attach shareBoard}
66
- class="absolute inset-0 touch-none select-none overflow-hidden outline-none [-webkit-touch-callout:none]"
67
- dir="ltr"
68
- role="application"
69
- tabindex="0"
70
- aria-label={$t('canvas.state.boardLabel')}
71
- aria-busy={loading}
72
- data-canvas-surface
73
- style="cursor:{loading ? 'progress' : cssCursor(state.cursor)};background-color:{BOARD_SURFACE_COLOR};{dotGridStyle(state.viewport)}"
74
- onpointerdown={(event) => host.handlePointerDown(event)}
75
- onpointermove={(event) => host.handlePointerMove(event)}
76
- onpointerup={(event) => host.handlePointerUp(event)}
77
- onpointercancel={(event) => host.handlePointerCancel(event)}
78
- onpointerleave={(event) => host.handlePointerLeave(event)}
79
- oncontextmenu={(event) => host.handleContextMenu(event)}
80
- ondragover={(event) => host.handleDragOver(event)}
81
- ondrop={(event) => host.handleDrop(event)}
82
- >
83
- <div class="absolute inset-0 origin-top-left" style="transform:{worldTransform};" data-canvas-world>
84
- {#each state.scene as object (object.id)}
85
- {#if object.type === 'text' && state.editingTextId === object.id}
86
- <TextEditor shape={object} {host} />
87
- {:else}
88
- <ObjectView
89
- {object}
90
- {host}
91
- runtime={object.type === 'widget' ? (state.widgets[object.widgetId] ?? DEFAULT_WIDGET_RUNTIME) : DEFAULT_WIDGET_RUNTIME}
92
- pending={object.type === 'widget' ? state.pending[object.id] : undefined}
93
- nameRevision={ui.nameRevision}
94
- fontRevision={state.fontRevision}
95
- primaryRing={advancedFeatures}
96
- erasing={$erasingMarks.has(object.id)}
97
- />
94
+ <LeftToRightScope>
95
+ <!-- A drawing surface for a pointer: it carries the focus for the shortcuts, and its name says what it is. -->
96
+ <!-- No focus outline on the board: the ring was clipped by overflow and drew attention away from objects when Shift was held. -->
97
+ <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
98
+ <div
99
+ {@attach shareBoard}
100
+ class="absolute inset-0 touch-none select-none overflow-hidden outline-none [-webkit-touch-callout:none]"
101
+ role="application"
102
+ tabindex="0"
103
+ aria-label={$t('canvas.state.boardLabel')}
104
+ aria-busy={loading}
105
+ data-canvas-surface
106
+ style="cursor:{loading ? 'progress' : cssCursor(state.cursor)};background-color:{BOARD_SURFACE_COLOR};{dotGridStyle(state.viewport)}"
107
+ onpointerdown={(event) => host.handlePointerDown(event)}
108
+ onpointermove={(event) => host.handlePointerMove(event)}
109
+ onpointerup={(event) => host.handlePointerUp(event)}
110
+ onpointercancel={(event) => host.handlePointerCancel(event)}
111
+ onpointerleave={(event) => host.handlePointerLeave(event)}
112
+ oncontextmenu={(event) => host.handleContextMenu(event)}
113
+ ondragover={(event) => host.handleDragOver(event)}
114
+ ondrop={(event) => host.handleDrop(event)}
115
+ >
116
+ <div class="absolute inset-0 origin-top-left" style="transform:{worldTransform};" data-canvas-world>
117
+ {#each mountedObjects as object (object.id)}
118
+ {#if object.type === 'text' && state.editingTextId === object.id}
119
+ <TextEditor shape={object} {host} />
120
+ {:else}
121
+ <ObjectView
122
+ {object}
123
+ {host}
124
+ runtime={object.type === 'widget' ? (state.widgets[object.widgetId] ?? DEFAULT_WIDGET_RUNTIME) : DEFAULT_WIDGET_RUNTIME}
125
+ pending={object.type === 'widget' ? state.pending[object.id] : undefined}
126
+ nameRevision={ui.nameRevision}
127
+ fontRevision={state.fontRevision}
128
+ primaryRing={advancedFeatures}
129
+ erasing={$erasingMarks.has(object.id)}
130
+ />
131
+ {/if}
132
+ {/each}
133
+ {#if state.overlay.preview}
134
+ <ObjectView object={state.overlay.preview} {host} />
98
135
  {/if}
99
- {/each}
100
- {#if state.overlay.preview}
101
- <ObjectView object={state.overlay.preview} {host} />
102
- {/if}
103
- </div>
136
+ </div>
104
137
 
105
- <SelectionOverlay {state} {host} gestureKind={ui.gestureKind} {advancedFeatures} {frameElsewhere} />
138
+ <SelectionOverlay {state} {host} gestureKind={ui.gestureKind} {advancedFeatures} {frameElsewhere} />
106
139
 
107
- {#if state.scribble}
108
- <EraserTrail trail={state.scribble} viewport={state.viewport} />
109
- {/if}
140
+ {#if state.scribble}
141
+ <EraserTrail trail={state.scribble} viewport={state.viewport} />
142
+ {/if}
110
143
 
111
- {#if showEmptyBoardHint}
112
- <CanvasHint />
113
- {/if}
144
+ {#if showEmptyBoardHint}
145
+ <CanvasHint />
146
+ {/if}
114
147
 
115
- <LoadNotice status={ui.loadStatus} />
148
+ <LoadNotice status={ui.loadStatus} />
116
149
 
117
- {#if ui.loadPhase === 'error'}
118
- <div
119
- class="pointer-events-auto absolute inset-x-4 bottom-4 z-20 mx-auto w-11/12 max-w-md rounded-xl border border-destructive/30 bg-destructive/10 p-4 text-destructive shadow-floating"
120
- role="alert"
121
- >
122
- <p class="text-body-medium">{$t('canvas.state.initFailed')}</p>
123
- </div>
124
- {/if}
150
+ {#if ui.loadPhase === 'error'}
151
+ <div
152
+ class="pointer-events-auto absolute inset-x-4 bottom-4 z-20 mx-auto w-11/12 max-w-md rounded-xl border border-destructive/30 bg-destructive/10 p-4 text-destructive shadow-floating"
153
+ role="alert"
154
+ >
155
+ <p class="text-body-medium">{$t('canvas.state.initFailed')}</p>
156
+ </div>
157
+ {/if}
125
158
 
126
- {#if loading}
127
- <!-- The board stays visible while its content loads. Input waits, so a late load cannot replace what was just drawn. -->
128
- <div class="absolute inset-0 z-30 cursor-progress" data-canvas-loader>
129
- <CanvasBoardPlaceholder showSurface={false} />
130
- </div>
131
- {/if}
132
- </div>
159
+ {#if loading}
160
+ <!-- The board stays visible while its content loads. Input waits, so a late load cannot replace what was just drawn. -->
161
+ <div class="absolute inset-0 z-30 cursor-progress" data-canvas-loader>
162
+ <CanvasBoardPlaceholder showSurface={false} />
163
+ </div>
164
+ {/if}
165
+ </div>
166
+ </LeftToRightScope>
@@ -0,0 +1,21 @@
1
+ <!--
2
+ The element that says "left to right" for the board, and has nothing else to say.
3
+
4
+ The board is a drawing, so it keeps its direction on every screen (see `CanvasStage.svelte`). The attribute is set here, in a
5
+ component of its own, and not on the board's own element, on purpose. Svelte writes `element.dir = element.dir` again in the
6
+ update of any element that has a `dir` attribute, and it puts that line in the one update that all the changing attributes of
7
+ a component share. The board's element changes its style at every frame of a pan or a zoom (the dot grid), so the write ran
8
+ at every one of them, and the browser answers a write of `dir` by working out the style of everything below the element again:
9
+ a restyle of every object at every frame, 55 to 70% of the CPU of a frame with 3000 objects (measured with the stress page).
10
+ Here nothing ever changes, so the line runs once, when the board is made.
11
+
12
+ `contents`: the element has no box of its own, so the board lays itself out in the canvas exactly as if it were not here, and
13
+ what is below it still inherits the direction (`direction` is inherited through the element's style, box or no box).
14
+ -->
15
+ <script lang="ts">
16
+ import type { Snippet } from 'svelte';
17
+
18
+ let { children }: { children: Snippet } = $props();
19
+ </script>
20
+
21
+ <div class="contents" dir="ltr">{@render children()}</div>
@@ -0,0 +1,7 @@
1
+ import type { Snippet } from 'svelte';
2
+ type $$ComponentProps = {
3
+ children: Snippet;
4
+ };
5
+ declare const LeftToRightScope: import("svelte").Component<$$ComponentProps, {}, "">;
6
+ type LeftToRightScope = ReturnType<typeof LeftToRightScope>;
7
+ export default LeftToRightScope;
@@ -35,7 +35,7 @@
35
35
  /** What the page said about this card's widget (only read for a widget card). */
36
36
  runtime?: WidgetRuntime;
37
37
  pending?: PendingWidgetState | undefined;
38
- /** The words of a widget card, said by the page's name for the widget (changes when the page renames it). */
38
+ /** Counts the times the page said its widgets changed (`widgetNameRevision`): a card asks again whether its widget is still there. */
39
39
  nameRevision?: number;
40
40
  /** Counts the times fonts finished loading: the lines of a text are drawn again, because letters changed width. */
41
41
  fontRevision?: number;
@@ -79,12 +79,16 @@
79
79
  );
80
80
  const textStyle = $derived(look.type === 'text' ? textBoxCss(look) : '');
81
81
 
82
- // The name a card shows. Reads the revision so a rename on the page redraws the card.
83
- const cardName = $derived.by(() => {
82
+ // A card whose widget is gone says so. (A card whose widget is there draws no words: its name is in the selection panel.)
83
+ // The engine's flag and the page's `isWidgetKnown` are not something a view can watch, so the card asks again whenever the page
84
+ // marked its widget as gone (the runtime changes) or said that its widgets changed (the revision). Without these reads a card
85
+ // that was drawn empty stays empty when its widget is found to be gone, and the person is never told.
86
+ const cardOrphaned = $derived.by(() => {
87
+ if (look.type !== 'widget') return false;
84
88
  void nameRevision;
85
- return look.type === 'widget' ? host.widgetLabel(look) : '';
89
+ void runtime.orphaned;
90
+ return host.isCardOrphaned(look);
86
91
  });
87
- const cardOrphaned = $derived(look.type === 'widget' ? host.isCardOrphaned(look) : false);
88
92
 
89
93
  // Laid out again when the text, its style or its width change, and when the fonts arrive: not when the text is only carried.
90
94
  const textLayout = $derived.by(() => {
@@ -223,14 +227,15 @@
223
227
  >
224
228
  {#if look.thumbnail && !runtime.hiddenImage}
225
229
  <img class="size-full select-none object-fill" src={look.thumbnail} alt="" draggable="false" />
226
- {:else if !runtime.hiddenImage}
227
- <!-- No screenshot yet: a dashed card with the widget's name, as the saved boards always showed it. -->
230
+ {:else if cardOrphaned && !runtime.hiddenImage}
231
+ <!-- The widget is gone and no screenshot is left: a dashed card says so. A card whose widget is there says nothing:
232
+ the page lays the live widget over it, and a "Widget preview" placeholder would show through while it builds. -->
228
233
  <div
229
234
  class="flex size-full flex-col items-center justify-center gap-1 rounded-lg border-[1.5px] border-dashed border-slate-400 px-3 text-center"
230
235
  >
231
- <span class="text-[28px] leading-none" aria-hidden="true">{cardOrphaned ? '⚠️' : '🧩'}</span>
232
- <span class="max-w-full truncate text-sm font-semibold text-slate-800">{cardOrphaned ? $t('canvas.widget.unlinkedName') : cardName}</span>
233
- <span class="text-xs text-slate-500">{cardOrphaned ? $t('canvas.widget.removeFromCanvas') : $t('canvas.draw.widgetPreview')}</span>
236
+ <span class="text-[28px] leading-none" aria-hidden="true">⚠️</span>
237
+ <span class="max-w-full truncate text-sm font-semibold text-slate-800">{$t('canvas.widget.unlinkedName')}</span>
238
+ <span class="text-xs text-slate-500">{$t('canvas.widget.removeFromCanvas')}</span>
234
239
  </div>
235
240
  {/if}
236
241
  {#if primaryRing && look.isPrimary}
@@ -7,7 +7,7 @@ interface Props {
7
7
  /** What the page said about this card's widget (only read for a widget card). */
8
8
  runtime?: WidgetRuntime;
9
9
  pending?: PendingWidgetState | undefined;
10
- /** The words of a widget card, said by the page's name for the widget (changes when the page renames it). */
10
+ /** Counts the times the page said its widgets changed (`widgetNameRevision`): a card asks again whether its widget is still there. */
11
11
  nameRevision?: number;
12
12
  /** Counts the times fonts finished loading: the lines of a text are drawn again, because letters changed width. */
13
13
  fontRevision?: number;
@@ -12,18 +12,18 @@
12
12
  */
13
13
  import { writable } from 'svelte/store';
14
14
  /** The set while nothing is marked: one shared set, so that "nothing marked" is the same value every time. */
15
- export var NOTHING_ERASED = new Set();
15
+ export const NOTHING_ERASED = new Set();
16
16
  export function createErasingMarks() {
17
- var _a = writable(NOTHING_ERASED), subscribe = _a.subscribe, set = _a.set;
18
- var listSeen = null;
19
- var current = NOTHING_ERASED;
17
+ const { subscribe, set } = writable(NOTHING_ERASED);
18
+ let listSeen = null;
19
+ let current = NOTHING_ERASED;
20
20
  return {
21
- subscribe: subscribe,
22
- take: function (marked) {
21
+ subscribe,
22
+ take(marked) {
23
23
  if (marked === listSeen)
24
24
  return;
25
25
  listSeen = marked;
26
- var next = marked.length === 0 ? NOTHING_ERASED : new Set(marked);
26
+ const next = marked.length === 0 ? NOTHING_ERASED : new Set(marked);
27
27
  // A store tells its subscribers of every `set` of an object, equal or not: nothing marked before and nothing now is no news.
28
28
  if (next === current)
29
29
  return;