@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,81 @@
1
+ <!--
2
+ The selector's indicator: a small card at the top of the board, for as long as a widget stands on it and the person has not
3
+ closed it. It says whether the page's element selector is picking elements of the widget, and how to use it.
4
+
5
+ The selector has no switch of its own: it is on while the Select tool is chosen on the toolbar (the page decides, see
6
+ `elementSelectorActive`), so this card only reports it. While the selector is on it gives the instructions the page gave
7
+ (click an element, the arrow keys to move between parent and child, a held key to use the widget, Escape to finish): the
8
+ card has one form, the open one, so the instructions are there before anything is pressed. While another tool is chosen it
9
+ says the selector is off and which tool turns it on.
10
+
11
+ The X closes the hint (not the selector): the page hears of it (`onDismissElementSelectorHint`) and decides when the hint
12
+ comes back. The words come from the page (`selectorGuide`), already in its language; the key caps are the keys themselves.
13
+
14
+ The card stands at the top centre (`selectorIndicatorTopClassFor`), so its tooltips open downward.
15
+ -->
16
+ <script lang="ts">
17
+ import { useCanvasLanguage } from '../../i18n/language.js';
18
+ import type { SelectorGuide } from '../host/CanvasHost.js';
19
+ import { FLOATING_CARD_CLASSES } from './floatingCard.js';
20
+ import { IconSelectElement, IconX } from './icons.js';
21
+ import { providePopoverSide } from './popoverSide.js';
22
+ import ToolButton from './ToolButton.svelte';
23
+
24
+ interface Props {
25
+ /** The selector is picking elements now (the Select tool is chosen and the page's selector is on). */
26
+ active: boolean;
27
+ guide: SelectorGuide | null;
28
+ /** The person closed the hint. */
29
+ onDismiss: () => void;
30
+ }
31
+
32
+ let { active, guide, onDismiss }: Props = $props();
33
+
34
+ const { t } = useCanvasLanguage();
35
+
36
+ providePopoverSide(() => 'bottom');
37
+ </script>
38
+
39
+ {#snippet keyCap(cap: string)}
40
+ <kbd class="rounded-md border border-border bg-muted px-1.5 py-0.5 font-sans text-xs text-muted-foreground">{cap}</kbd>
41
+ {/snippet}
42
+
43
+ {#snippet dot()}
44
+ <span class="text-border" aria-hidden="true">·</span>
45
+ {/snippet}
46
+
47
+ <!-- `widget-selector-bar` is the name pages' own tests have always found the card by (it was a bar at the bottom before). -->
48
+ <div
49
+ role="group"
50
+ aria-label={$t('canvas.tool.selector')}
51
+ data-canvas-selector-indicator
52
+ data-active={active ? '' : undefined}
53
+ class="widget-selector-bar pointer-events-auto flex max-w-full items-center gap-2 {FLOATING_CARD_CLASSES}"
54
+ >
55
+ <span class="flex shrink-0 items-center gap-1.5 ps-2 text-caption-medium text-foreground [&_svg]:size-4 [&_svg]:shrink-0" role="status">
56
+ <IconSelectElement />
57
+ <span class="size-1.5 shrink-0 rounded-full {active ? 'bg-primary' : 'bg-border'}" aria-hidden="true"></span>
58
+ <span class="whitespace-nowrap">{active ? $t('canvas.selector.on') : $t('canvas.selector.off')}</span>
59
+ </span>
60
+ {#if !active}
61
+ <span class="min-w-0 text-caption-medium text-muted-foreground">{$t('canvas.selector.offHint')}</span>
62
+ {:else if guide}
63
+ <div class="flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-1 text-caption-medium text-muted-foreground">
64
+ <span>{guide.click}</span>
65
+ {@render dot()}
66
+ {@render keyCap('↑')}
67
+ {@render keyCap('↓')}
68
+ <span>{guide.parentChild}</span>
69
+ {@render dot()}
70
+ <span>{guide.hold}</span>
71
+ {@render keyCap(guide.cmd)}
72
+ <span>{guide.interact}</span>
73
+ {@render dot()}
74
+ {@render keyCap(guide.esc)}
75
+ <span>{guide.done}</span>
76
+ </div>
77
+ {/if}
78
+ <ToolButton label={$t('canvas.selector.dismiss')} size="compact" onclick={onDismiss}>
79
+ <IconX />
80
+ </ToolButton>
81
+ </div>
@@ -0,0 +1,11 @@
1
+ import type { SelectorGuide } from '../host/CanvasHost.js';
2
+ interface Props {
3
+ /** The selector is picking elements now (the Select tool is chosen and the page's selector is on). */
4
+ active: boolean;
5
+ guide: SelectorGuide | null;
6
+ /** The person closed the hint. */
7
+ onDismiss: () => void;
8
+ }
9
+ declare const SelectorIndicator: import("svelte").Component<Props, {}, "">;
10
+ type SelectorIndicator = ReturnType<typeof SelectorIndicator>;
11
+ export default SelectorIndicator;
@@ -38,13 +38,21 @@
38
38
 
39
39
  // The tooltip is drawn into the canvas's floating layer, not in place: see floatingLayer.ts.
40
40
  const floatingLayer = useFloatingLayer();
41
+ // Until the canvas has made its layer nothing is mounted (the tooltip is closed then anyway), so the page's body is not written to.
42
+ const overlayPortal = $derived(canvasOverlayPortalProps($floatingLayer));
41
43
  // It opens away from the edge the card stands on: upward from the bottom, downward from the top, sideways from a side.
42
44
  const popoverSide = usePopoverSide();
43
45
 
44
46
  // Written out in full, so that the stylesheet of a page that installs the canvas picks every class up.
45
47
  const SQUARE_CLASSES = { toolbar: 'size-9', compact: 'size-8' } as const;
48
+ // The zoom level is a real button, so it shrinks a little while it is pressed like the zoom buttons beside it, through the design
49
+ // system's `press-feedback` (which keeps still for a person who asked for less motion).
46
50
  const LEVEL_CLASSES =
47
- 'inline-flex h-8 w-10 shrink-0 items-center justify-center rounded-lg text-xs font-medium text-muted-foreground transition-colors duration-fast motion-reduce:transition-none hover:bg-accent hover:text-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50';
51
+ 'press-feedback inline-flex h-8 w-10 shrink-0 items-center justify-center rounded-lg text-xs font-medium text-muted-foreground transition-colors duration-fast motion-reduce:transition-none hover:bg-accent hover:text-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50';
52
+ // The design system's Icon Button shows the keyboard focus by a tint of its background, and the brand tint of the tool that is on
53
+ // is a background too, that wins over it: the tool in use, which is where the keyboard begins, showed no focus at all (found with
54
+ // the accessibility check). It gets the ring that the zoom level and the Shapes button show, and only when the keyboard has the focus.
55
+ const ACTIVE_FOCUS_CLASSES = 'data-[active]:focus-visible:ring-2 data-[active]:focus-visible:ring-ring';
48
56
  </script>
49
57
 
50
58
  <Tooltip.Root>
@@ -63,14 +71,14 @@
63
71
  aria-pressed={toggle ? active : undefined}
64
72
  aria-keyshortcuts={keyShortcuts}
65
73
  data-active={active ? '' : undefined}
66
- class="{SQUARE_CLASSES[size]} data-[active]:bg-brand-subtle data-[active]:text-foreground {className}"
74
+ class="{SQUARE_CLASSES[size]} data-[active]:bg-brand-subtle data-[active]:text-foreground {ACTIVE_FOCUS_CLASSES} {className}"
67
75
  >
68
76
  {@render children()}
69
77
  </IconButton>
70
78
  {/if}
71
79
  {/snippet}
72
80
  </Tooltip.Trigger>
73
- <Tooltip.Portal to={canvasOverlayPortalProps($floatingLayer).to}>
81
+ <Tooltip.Portal to={overlayPortal.to} disabled={overlayPortal.disabled}>
74
82
  <Tooltip.Content side={popoverSide()} sideOffset={8} class="{CANVAS_OVERLAY_Z_CLASS} {OVERLAY_REDUCED_MOTION_CLASSES}">
75
83
  <span class="flex items-center gap-2">
76
84
  <span>{label}</span>
@@ -1,6 +1,6 @@
1
1
  /**
2
- * The look of the small cards that float over the board: the toolbar, the zoom control, the Save button and the element
3
- * selector bar, and the widths of the board at which the zoom control gives way to the toolbar.
2
+ * The look of the small cards that float over the board: the toolbar, the zoom control, the Save button and the selector's
3
+ * indicator, and the widths of the board at which the zoom control gives way to the toolbar.
4
4
  *
5
5
  * Figma draws each card with 4 px of padding and a 1 px border that sits *inside* that padding (an inside stroke takes no
6
6
  * room in a Figma layout), so a card of 36 px buttons measures 44 px high and the zoom control, with its 32 px buttons, 40 px.
@@ -1,6 +1,6 @@
1
1
  /**
2
- * The look of the small cards that float over the board: the toolbar, the zoom control, the Save button and the element
3
- * selector bar, and the widths of the board at which the zoom control gives way to the toolbar.
2
+ * The look of the small cards that float over the board: the toolbar, the zoom control, the Save button and the selector's
3
+ * indicator, and the widths of the board at which the zoom control gives way to the toolbar.
4
4
  *
5
5
  * Figma draws each card with 4 px of padding and a 1 px border that sits *inside* that padding (an inside stroke takes no
6
6
  * room in a Figma layout), so a card of 36 px buttons measures 44 px high and the zoom control, with its 32 px buttons, 40 px.
@@ -6,16 +6,27 @@ import type { Readable } from 'svelte/store';
6
6
  export declare const FLOATING_LAYER_CLASSES = "absolute inset-0 z-50 h-0 w-0 [contain:layout]";
7
7
  /** Called by the canvas that owns the layer, before its children are made. */
8
8
  export declare function provideFloatingLayer(layer: Readable<HTMLElement | null>): void;
9
- /** The element to draw a floating thing into. A piece used outside a canvas has none, and the library's own default applies. */
10
- export declare function useFloatingLayer(): Readable<HTMLElement | null>;
9
+ /**
10
+ * The element to draw a floating thing into. A piece used outside a canvas has none (`undefined`), and the library's own
11
+ * default applies. Inside a canvas the value is `null` until the canvas has made its layer, a moment after its first render.
12
+ */
13
+ export declare function useFloatingLayer(): Readable<HTMLElement | null | undefined>;
11
14
  /** Below design-system dialogs, dropdowns and toasts (`z-50`); still above normal page content so a compact card does not cover menus. */
12
15
  export declare const CANVAS_OVERLAY_PORTAL_Z_CLASS = "z-40";
13
16
  export type CanvasOverlayPortalProps = {
14
17
  to?: HTMLElement;
18
+ /** True while the canvas has no layer yet: nothing is mounted anywhere, and the content (closed, so empty) stays in place. */
19
+ disabled?: boolean;
15
20
  class?: string;
16
21
  };
17
22
  /**
18
23
  * Portal target for a menu, popover or tooltip: `document.body` in the light DOM, else the in-canvas floating layer.
19
24
  * Floating UI still measures from the trigger; only the mount node changes.
25
+ *
26
+ * `null` is a canvas that has not made its layer yet. The pieces that portal a tooltip (the toolbar's buttons) are made
27
+ * with the first render, before the layer exists, and the portal mounts its content when it is made even if the tooltip
28
+ * is closed. Mounting on `document.body` then would write to the page, and the page may not be ours (a partner's, with
29
+ * the canvas in a shadow root), so nothing is mounted until there is a layer: a tooltip or a menu is closed at that
30
+ * moment, and mounts in the layer once the layer exists. `undefined` is a piece used outside a canvas.
20
31
  */
21
32
  export declare function canvasOverlayPortalProps(floatingLayer: HTMLElement | null | undefined): CanvasOverlayPortalProps;
@@ -22,17 +22,29 @@ export const FLOATING_LAYER_CLASSES = 'absolute inset-0 z-50 h-0 w-0 [contain:la
22
22
  export function provideFloatingLayer(layer) {
23
23
  setContext(FLOATING_LAYER_CONTEXT_KEY, layer);
24
24
  }
25
- /** The element to draw a floating thing into. A piece used outside a canvas has none, and the library's own default applies. */
25
+ /**
26
+ * The element to draw a floating thing into. A piece used outside a canvas has none (`undefined`), and the library's own
27
+ * default applies. Inside a canvas the value is `null` until the canvas has made its layer, a moment after its first render.
28
+ */
26
29
  export function useFloatingLayer() {
27
- return getContext(FLOATING_LAYER_CONTEXT_KEY) ?? readable(null);
30
+ return getContext(FLOATING_LAYER_CONTEXT_KEY) ?? readable(undefined);
28
31
  }
29
32
  /** Below design-system dialogs, dropdowns and toasts (`z-50`); still above normal page content so a compact card does not cover menus. */
30
33
  export const CANVAS_OVERLAY_PORTAL_Z_CLASS = 'z-40';
31
34
  /**
32
35
  * Portal target for a menu, popover or tooltip: `document.body` in the light DOM, else the in-canvas floating layer.
33
36
  * Floating UI still measures from the trigger; only the mount node changes.
37
+ *
38
+ * `null` is a canvas that has not made its layer yet. The pieces that portal a tooltip (the toolbar's buttons) are made
39
+ * with the first render, before the layer exists, and the portal mounts its content when it is made even if the tooltip
40
+ * is closed. Mounting on `document.body` then would write to the page, and the page may not be ours (a partner's, with
41
+ * the canvas in a shadow root), so nothing is mounted until there is a layer: a tooltip or a menu is closed at that
42
+ * moment, and mounts in the layer once the layer exists. `undefined` is a piece used outside a canvas.
34
43
  */
35
44
  export function canvasOverlayPortalProps(floatingLayer) {
45
+ if (floatingLayer === null) {
46
+ return { disabled: true, class: CANVAS_OVERLAY_PORTAL_Z_CLASS };
47
+ }
36
48
  if (!floatingLayer) {
37
49
  return typeof document !== 'undefined'
38
50
  ? { to: document.body, class: CANVAS_OVERLAY_PORTAL_Z_CLASS }
@@ -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;
@@ -0,0 +1,31 @@
1
+ import type { ObjectId, SceneObject } from '../../engine/core/types.js';
2
+ import type { CarriedShapes } from '../../engine/state.js';
3
+ /** A carried selection is drawn as one layer only when at least this many of its objects have an element: a few cost nothing to write. */
4
+ export declare const LIFT_MINIMUM_CARRIED = 40;
5
+ /**
6
+ * ...and only when the objects that are not carried (and have an element) are at most this share of the ones that are, when the drag
7
+ * begins: the work of a step is the work for those, so that is how much of the work is left (a third at the most, with one half).
8
+ */
9
+ export declare const LIFT_UNCARRIED_SHARE = 0.5;
10
+ /** What the stage draws: the objects, and how far the world layer is moved on top of the view's own move, in world units. */
11
+ export interface LiftedScene {
12
+ objects: readonly SceneObject[];
13
+ offsetX: number;
14
+ offsetY: number;
15
+ }
16
+ export interface LiftedView {
17
+ /**
18
+ * What to draw for the objects that have an element (`mounted`, from the engine's records) and what the engine says is carried
19
+ * (`carry`, null when nothing is). Called at every step of a drag, so it does one pass over the list and nothing more.
20
+ */
21
+ show(mounted: readonly SceneObject[], carry: CarriedShapes | null): LiftedScene;
22
+ }
23
+ /** How many of the objects are carried. */
24
+ export declare function countCarried(objects: readonly SceneObject[], shapeIds: ReadonlySet<ObjectId>): number;
25
+ /**
26
+ * The records to draw while the carried shapes are lifted: each carried object as it was when the drag began (the very same record at
27
+ * every step), each of the others as the engine holds it, moved back by how far the selection has been carried. Null when a carried
28
+ * object has no record from the start, which says that what the engine handed over is not what this drag is made of.
29
+ */
30
+ export declare function recordsWhileLifted(mounted: readonly SceneObject[], carry: CarriedShapes): SceneObject[] | null;
31
+ export declare function createLiftedView(): LiftedView;