@widgetic/canvas 0.5.42 → 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.
- package/README.md +1 -0
- package/dist/canvas/DomCanvas.svelte +49 -20
- package/dist/canvas/DomCanvas.svelte.d.ts +13 -7
- package/dist/canvas/chromeLayout.d.ts +14 -3
- package/dist/canvas/chromeLayout.js +14 -3
- package/dist/canvas/host/CanvasHost.d.ts +47 -5
- package/dist/canvas/host/CanvasHost.js +256 -91
- package/dist/canvas/host/nearCards.d.ts +33 -0
- package/dist/canvas/host/nearCards.js +78 -0
- package/dist/canvas/host/pageEvents.d.ts +16 -4
- package/dist/canvas/host/pageEvents.js +13 -4
- package/dist/canvas/host/pictureSaves.d.ts +33 -0
- package/dist/canvas/host/pictureSaves.js +42 -0
- package/dist/canvas/host/screenRects.d.ts +5 -0
- package/dist/canvas/host/storedPictures.d.ts +88 -0
- package/dist/canvas/host/storedPictures.js +288 -0
- package/dist/canvas/index.d.ts +1 -1
- package/dist/canvas/index.js +1 -1
- package/dist/canvas/shapes/shapeImageStore.d.ts +45 -2
- package/dist/canvas/shapes/shapeImageStore.js +7 -0
- package/dist/canvas/toolbarPosition.d.ts +2 -2
- package/dist/canvas/toolbarPosition.js +2 -2
- package/dist/canvas/ui/SelectionPanel.svelte +28 -5
- package/dist/canvas/ui/SelectionPanel.svelte.d.ts +7 -0
- package/dist/canvas/ui/SelectorIndicator.svelte +81 -0
- package/dist/canvas/ui/SelectorIndicator.svelte.d.ts +11 -0
- package/dist/canvas/ui/ToolButton.svelte +8 -2
- package/dist/canvas/ui/floatingCard.d.ts +2 -2
- package/dist/canvas/ui/floatingCard.js +2 -2
- package/dist/canvas/ui/floatingLayer.d.ts +13 -2
- package/dist/canvas/ui/floatingLayer.js +14 -2
- package/dist/canvas/view/CanvasStage.svelte +101 -67
- package/dist/canvas/view/LeftToRightScope.svelte +21 -0
- package/dist/canvas/view/LeftToRightScope.svelte.d.ts +7 -0
- package/dist/canvas/view/ObjectView.svelte +15 -10
- package/dist/canvas/view/ObjectView.svelte.d.ts +1 -1
- package/dist/canvas/view/liftedScene.d.ts +31 -0
- package/dist/canvas/view/liftedScene.js +146 -0
- package/dist/canvas/view/mountedScene.d.ts +71 -0
- package/dist/canvas/view/mountedScene.js +363 -0
- package/dist/engine/EngineCore.d.ts +15 -1
- package/dist/engine/EngineCore.js +30 -4
- package/dist/engine/codec/canvasDocument.d.ts +5 -0
- package/dist/engine/codec/canvasDocument.js +31 -4
- package/dist/engine/core/history.d.ts +6 -0
- package/dist/engine/core/history.js +16 -0
- package/dist/engine/core/scene.d.ts +10 -0
- package/dist/engine/core/scene.js +24 -0
- package/dist/engine/core/types.d.ts +8 -2
- package/dist/engine/input/gestures.js +4 -2
- package/dist/engine/state.d.ts +20 -0
- package/dist/engine/state.js +1 -0
- package/dist/fonts/interFont.d.ts +10 -1
- package/dist/fonts/interFont.js +36 -13
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +8 -1
- package/dist/i18n/messages.js +9 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/canvas/ui/SelectorBar.svelte +0 -84
- package/dist/canvas/ui/SelectorBar.svelte.d.ts +0 -12
|
@@ -16,15 +16,58 @@
|
|
|
16
16
|
* With no store installed nothing changes — shapes keep serializing inline, so
|
|
17
17
|
* a consumer that has not wired one up is never left with blank shapes.
|
|
18
18
|
*/
|
|
19
|
+
/**
|
|
20
|
+
* What the canvas tells the store about a read, when it knows (see `ShapeImageStore.load`).
|
|
21
|
+
*
|
|
22
|
+
* `visible`: the picture is on screen right now, and the person is looking at its place: answer as soon as you can.
|
|
23
|
+
* `background`: the picture is of an object that is off the screen, asked for ahead of time: nobody is waiting for it, so a
|
|
24
|
+
* store that has a queue, a network or a limit of its own may serve it after the ones that are `visible`. It must still
|
|
25
|
+
* answer: a board that is panned to it expects its picture to be there, or on its way.
|
|
26
|
+
*/
|
|
27
|
+
export interface ShapeImageLoadOptions {
|
|
28
|
+
priority?: 'visible' | 'background';
|
|
29
|
+
}
|
|
19
30
|
export interface ShapeImageStore {
|
|
20
31
|
/**
|
|
21
32
|
* Persist the bytes for a reference. Called during serialization, so it must
|
|
22
33
|
* return immediately — write in the background and swallow failures.
|
|
23
34
|
*/
|
|
24
35
|
save(ref: string, dataUrl: string): void;
|
|
25
|
-
/**
|
|
26
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Resolve a reference to a data URL or any URL an `Image` can load.
|
|
38
|
+
*
|
|
39
|
+
* An object URL (`blob:`) is a good answer for a picture that is big: the board holds a short address instead of megabytes of
|
|
40
|
+
* text, and the browser reads the bytes where it keeps them. The canvas never writes one into the saved text (it writes the
|
|
41
|
+
* reference, which the store resolves again at the next load), so the store may hand out one it will not be able to hand out
|
|
42
|
+
* again after a reload. What a `blob:` address cannot do is leave the page: a card whose screenshot is one is not answered by
|
|
43
|
+
* `getWidgetShapeDataUrl` (it needs bytes), so a store gives `blob:` addresses for the pictures of the person's own and
|
|
44
|
+
* bytes for the screenshots of widget cards, unless the page that asks for the bytes can read an object URL.
|
|
45
|
+
*
|
|
46
|
+
* The canvas asks for the pictures on screen first, a few at a time, and for the others after them; the second argument says
|
|
47
|
+
* which kind this one is. A store written before the argument existed ignores it, which is fine.
|
|
48
|
+
*/
|
|
49
|
+
load(ref: string, options?: ShapeImageLoadOptions): Promise<string | null>;
|
|
50
|
+
/**
|
|
51
|
+
* Optional. A picture the person has just put on the board (dropped, pasted or chosen), as bytes (a data URL).
|
|
52
|
+
*
|
|
53
|
+
* The store may keep the bytes under `ref` (as `save` does) and answer with a short address, an object URL (`blob:`), for the
|
|
54
|
+
* board to hold instead of the text: the board then never holds the megabytes, and the picture is the store's from the first
|
|
55
|
+
* moment, so the saved text carries the reference only. Answer `null` to leave the picture as it is (a small one, a page that
|
|
56
|
+
* cannot show an object URL, a limit reached, nowhere to keep the bytes yet): the canvas then keeps the bytes inline, and the
|
|
57
|
+
* next save hands them to `save` as it always did. When this answers with an address the bytes MUST have been kept: the canvas
|
|
58
|
+
* will not offer them again. It must return at once and never throw (a throw is treated as `null`).
|
|
59
|
+
*
|
|
60
|
+
* A store written before this existed has no `adopt`, and nothing changes for it.
|
|
61
|
+
*/
|
|
62
|
+
adopt?(ref: string, dataUrl: string): string | null;
|
|
27
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Whether this canvas knows what to do with an object URL (`blob:`) that a store gives for a reference: it keeps the address for as
|
|
66
|
+
* long as the page lives, and writes the reference in the saved text, never the address (see `externalizeBytes`). A page that
|
|
67
|
+
* wants to give object URLs asks for this first, so that a page updated before the canvas is does not get a saved board with
|
|
68
|
+
* addresses in it that no other page can read.
|
|
69
|
+
*/
|
|
70
|
+
export declare const SHAPE_IMAGE_STORE_OBJECT_URLS = true;
|
|
28
71
|
export declare function setShapeImageStore(store: ShapeImageStore | null): void;
|
|
29
72
|
export declare function getShapeImageStore(): ShapeImageStore | null;
|
|
30
73
|
/** Inline bytes — the thing that must not reach the canvas JSON. */
|
|
@@ -16,6 +16,13 @@
|
|
|
16
16
|
* With no store installed nothing changes — shapes keep serializing inline, so
|
|
17
17
|
* a consumer that has not wired one up is never left with blank shapes.
|
|
18
18
|
*/
|
|
19
|
+
/**
|
|
20
|
+
* Whether this canvas knows what to do with an object URL (`blob:`) that a store gives for a reference: it keeps the address for as
|
|
21
|
+
* long as the page lives, and writes the reference in the saved text, never the address (see `externalizeBytes`). A page that
|
|
22
|
+
* wants to give object URLs asks for this first, so that a page updated before the canvas is does not get a saved board with
|
|
23
|
+
* addresses in it that no other page can read.
|
|
24
|
+
*/
|
|
25
|
+
export const SHAPE_IMAGE_STORE_OBJECT_URLS = true;
|
|
19
26
|
let installedStore = null;
|
|
20
27
|
export function setShapeImageStore(store) {
|
|
21
28
|
installedStore = store;
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* The toolbar has always been at the bottom centre. A host that has something of its own there (Shopify's Sidekick sits in
|
|
5
5
|
* the same spot, a partner may have a cookie bar or a chat bubble) names another anchor with the `toolbarPosition` option:
|
|
6
6
|
* any of the eight places `chromeLayout.ts` describes (the top edge, the bottom edge, or the middle of the left or right
|
|
7
|
-
* edge, where the toolbar stands upright). The
|
|
8
|
-
*
|
|
7
|
+
* edge, where the toolbar stands upright). The toolbar stays where it is for the life of the board: the selector's
|
|
8
|
+
* indicator is a card of its own at the top centre (below the toolbar when a host put the toolbar there).
|
|
9
9
|
*
|
|
10
10
|
* Kept free of Svelte and of the DOM so that Node can test it.
|
|
11
11
|
*/
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* The toolbar has always been at the bottom centre. A host that has something of its own there (Shopify's Sidekick sits in
|
|
5
5
|
* the same spot, a partner may have a cookie bar or a chat bubble) names another anchor with the `toolbarPosition` option:
|
|
6
6
|
* any of the eight places `chromeLayout.ts` describes (the top edge, the bottom edge, or the middle of the left or right
|
|
7
|
-
* edge, where the toolbar stands upright). The
|
|
8
|
-
*
|
|
7
|
+
* edge, where the toolbar stands upright). The toolbar stays where it is for the life of the board: the selector's
|
|
8
|
+
* indicator is a card of its own at the top centre (below the toolbar when a host put the toolbar there).
|
|
9
9
|
*
|
|
10
10
|
* Kept free of Svelte and of the DOM so that Node can test it.
|
|
11
11
|
*/
|
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
is still being dragged is one step of the history, taken when it ends.
|
|
12
12
|
|
|
13
13
|
A selection shows a settings control at the corner; it opens the panel, and the close button collapses it again without
|
|
14
|
-
changing when the selection changes.
|
|
14
|
+
changing when the selection changes. Nothing opens the panel by itself, not a selection and not a text: it is closed by
|
|
15
|
+
default, it stays as the person left it while the selection moves from one object to another, and it goes back to the
|
|
16
|
+
settings control when nothing is selected any more (the host does that, see `#onEngineState`). It stands
|
|
15
17
|
in the top corner at the end of the line, and keeps clear of the cards the page put there: below the ones on the top
|
|
16
18
|
edge, and beside an upright one on the right edge (see `PanelClearance`).
|
|
17
19
|
-->
|
|
@@ -53,9 +55,16 @@
|
|
|
53
55
|
canOpenDetails: boolean;
|
|
54
56
|
/** What the panel keeps clear of: the cards that stand on the top edge, and an upright one on the right edge. */
|
|
55
57
|
clearance: PanelClearance;
|
|
58
|
+
/**
|
|
59
|
+
* A selected widget card (one whose widget is there) has no settings: no settings control at the corner and no panel.
|
|
60
|
+
* Its name, its id and its preview belong to the page's own chrome. A card whose widget is gone is left out of this: the
|
|
61
|
+
* panel's rule for a lone card (`shouldOfferSelectionPanelForTraits`) applies to it, and the card itself says so and
|
|
62
|
+
* offers the way to take it off the board.
|
|
63
|
+
*/
|
|
64
|
+
widgetCardHasNoSettings?: boolean;
|
|
56
65
|
}
|
|
57
66
|
|
|
58
|
-
let { host, state, ui, wireframeMode, canCapture, canConvert, canRename, canRefresh, canOpenDetails, clearance }: Props = $props();
|
|
67
|
+
let { host, state, ui, wireframeMode, canCapture, canConvert, canRename, canRefresh, canOpenDetails, clearance, widgetCardHasNoSettings = false }: Props = $props();
|
|
59
68
|
|
|
60
69
|
const { t } = useCanvasLanguage();
|
|
61
70
|
const floatingLayer = useFloatingLayer();
|
|
@@ -118,15 +127,22 @@
|
|
|
118
127
|
* Gives the thumb of a design-system slider the name of its row. The slider draws its thumb itself and takes no name for
|
|
119
128
|
* it, so a screen reader would say "slider" and nothing more (the group around it is not the thumb's name). The thumb is
|
|
120
129
|
* found by its role, and again if the slider draws it anew.
|
|
130
|
+
*
|
|
131
|
+
* The slider also writes the attributes of its thumb again after the thumb is drawn, and that takes the name away (found with the
|
|
132
|
+
* accessibility check: the thumbs were named for an instant, and then said "slider" and nothing more). So the name is put back
|
|
133
|
+
* when the thumb loses it, not only when it appears. A thumb that already has the name is not written to: a write that changes
|
|
134
|
+
* nothing is a change to the observer, and the observer would then go round and round.
|
|
121
135
|
*/
|
|
122
136
|
function nameSliderThumb(name: string): Attachment<HTMLElement> {
|
|
123
137
|
return (row) => {
|
|
124
138
|
const applyName = (): void => {
|
|
125
|
-
for (const thumb of row.querySelectorAll('[role="slider"]'))
|
|
139
|
+
for (const thumb of row.querySelectorAll('[role="slider"]')) {
|
|
140
|
+
if (thumb.getAttribute('aria-label') !== name) thumb.setAttribute('aria-label', name);
|
|
141
|
+
}
|
|
126
142
|
};
|
|
127
143
|
applyName();
|
|
128
144
|
const observer = new MutationObserver(applyName);
|
|
129
|
-
observer.observe(row, { childList: true, subtree: true });
|
|
145
|
+
observer.observe(row, { childList: true, subtree: true, attributes: true, attributeFilter: ['aria-label'] });
|
|
130
146
|
return () => observer.disconnect();
|
|
131
147
|
};
|
|
132
148
|
}
|
|
@@ -152,8 +168,15 @@
|
|
|
152
168
|
const strokeWidthValue = $derived(traitNumber(traits.strokeWidth, 0));
|
|
153
169
|
const fontSizeValue = $derived(traits.text ? traitNumber(traits.text.fontSize, 16) : 16);
|
|
154
170
|
|
|
171
|
+
// The widget on the board is not edited here: a selected card whose widget is there has no settings control and no panel.
|
|
172
|
+
const selectionIsAWidgetWithoutSettings = $derived(
|
|
173
|
+
widgetCardHasNoSettings && traits.widgetCard !== null && !host.isCardOrphaned(traits.widgetCard)
|
|
174
|
+
);
|
|
175
|
+
// A lone widget card does not open the sketch settings panel on any board (`shouldOfferSelectionPanelForTraits`); on the
|
|
176
|
+
// simple board it does not even when the page can capture (`selectionIsAWidgetWithoutSettings`).
|
|
155
177
|
const showPanel = $derived(
|
|
156
|
-
|
|
178
|
+
!selectionIsAWidgetWithoutSettings &&
|
|
179
|
+
((shouldOfferSelectionPanelForTraits(traits) && hasSelection) || (canCapture && !canConvert))
|
|
157
180
|
);
|
|
158
181
|
const showFillColor = $derived(showFillColorRow(traits, wireframeMode));
|
|
159
182
|
const showStrokeColor = $derived(showStrokeColorRow(traits, wireframeMode));
|
|
@@ -14,6 +14,13 @@ interface Props {
|
|
|
14
14
|
canOpenDetails: boolean;
|
|
15
15
|
/** What the panel keeps clear of: the cards that stand on the top edge, and an upright one on the right edge. */
|
|
16
16
|
clearance: PanelClearance;
|
|
17
|
+
/**
|
|
18
|
+
* A selected widget card (one whose widget is there) has no settings: no settings control at the corner and no panel.
|
|
19
|
+
* Its name, its id and its preview belong to the page's own chrome. A card whose widget is gone is left out of this: the
|
|
20
|
+
* panel's rule for a lone card (`shouldOfferSelectionPanelForTraits`) applies to it, and the card itself says so and
|
|
21
|
+
* offers the way to take it off the board.
|
|
22
|
+
*/
|
|
23
|
+
widgetCardHasNoSettings?: boolean;
|
|
17
24
|
}
|
|
18
25
|
declare const SelectionPanel: import("svelte").Component<Props, {}, "">;
|
|
19
26
|
type SelectionPanel = ReturnType<typeof SelectionPanel>;
|
|
@@ -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,6 +38,8 @@
|
|
|
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
|
|
|
@@ -45,6 +47,10 @@
|
|
|
45
47
|
const SQUARE_CLASSES = { toolbar: 'size-9', compact: 'size-8' } as const;
|
|
46
48
|
const LEVEL_CLASSES =
|
|
47
49
|
'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';
|
|
50
|
+
// 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
|
|
51
|
+
// 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
|
|
52
|
+
// the accessibility check). It gets the ring that the zoom level and the Shapes button show, and only when the keyboard has the focus.
|
|
53
|
+
const ACTIVE_FOCUS_CLASSES = 'data-[active]:focus-visible:ring-2 data-[active]:focus-visible:ring-ring';
|
|
48
54
|
</script>
|
|
49
55
|
|
|
50
56
|
<Tooltip.Root>
|
|
@@ -63,14 +69,14 @@
|
|
|
63
69
|
aria-pressed={toggle ? active : undefined}
|
|
64
70
|
aria-keyshortcuts={keyShortcuts}
|
|
65
71
|
data-active={active ? '' : undefined}
|
|
66
|
-
class="{SQUARE_CLASSES[size]} data-[active]:bg-brand-subtle data-[active]:text-foreground {className}"
|
|
72
|
+
class="{SQUARE_CLASSES[size]} data-[active]:bg-brand-subtle data-[active]:text-foreground {ACTIVE_FOCUS_CLASSES} {className}"
|
|
67
73
|
>
|
|
68
74
|
{@render children()}
|
|
69
75
|
</IconButton>
|
|
70
76
|
{/if}
|
|
71
77
|
{/snippet}
|
|
72
78
|
</Tooltip.Trigger>
|
|
73
|
-
<Tooltip.Portal to={
|
|
79
|
+
<Tooltip.Portal to={overlayPortal.to} disabled={overlayPortal.disabled}>
|
|
74
80
|
<Tooltip.Content side={popoverSide()} sideOffset={8} class="{CANVAS_OVERLAY_Z_CLASS} {OVERLAY_REDUCED_MOTION_CLASSES}">
|
|
75
81
|
<span class="flex items-center gap-2">
|
|
76
82
|
<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
|
|
3
|
-
*
|
|
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
|
|
3
|
-
*
|
|
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
|
-
/**
|
|
10
|
-
|
|
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
|
-
/**
|
|
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(
|
|
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
|
|
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
|
-
|
|
62
|
-
<!--
|
|
63
|
-
<!--
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
>
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
100
|
-
{#if state.overlay.preview}
|
|
101
|
-
<ObjectView object={state.overlay.preview} {host} />
|
|
102
|
-
{/if}
|
|
103
|
-
</div>
|
|
136
|
+
</div>
|
|
104
137
|
|
|
105
|
-
|
|
138
|
+
<SelectionOverlay {state} {host} gestureKind={ui.gestureKind} {advancedFeatures} {frameElsewhere} />
|
|
106
139
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
140
|
+
{#if state.scribble}
|
|
141
|
+
<EraserTrail trail={state.scribble} viewport={state.viewport} />
|
|
142
|
+
{/if}
|
|
110
143
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
144
|
+
{#if showEmptyBoardHint}
|
|
145
|
+
<CanvasHint />
|
|
146
|
+
{/if}
|
|
114
147
|
|
|
115
|
-
|
|
148
|
+
<LoadNotice status={ui.loadStatus} />
|
|
116
149
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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>
|