@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.
- package/README.md +1 -0
- package/dist/canvas/DomCanvas.svelte +49 -20
- package/dist/canvas/DomCanvas.svelte.d.ts +13 -7
- package/dist/canvas/autosaveScheduler.js +37 -89
- package/dist/canvas/boardFrame.js +1 -1
- package/dist/canvas/boardSurface.js +1 -1
- package/dist/canvas/canvasLogger.js +7 -19
- package/dist/canvas/chromeLayout.d.ts +14 -3
- package/dist/canvas/chromeLayout.js +30 -20
- package/dist/canvas/eventScope.js +10 -14
- package/dist/canvas/host/CanvasHost.d.ts +47 -5
- package/dist/canvas/host/CanvasHost.js +1481 -1566
- package/dist/canvas/host/CanvasHostApi.js +4 -19
- package/dist/canvas/host/browserServices.js +65 -116
- package/dist/canvas/host/conversion.js +82 -170
- package/dist/canvas/host/hostObject.js +7 -7
- 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 +17 -8
- 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/screenRects.js +28 -31
- package/dist/canvas/host/storedPictures.d.ts +88 -0
- package/dist/canvas/host/storedPictures.js +288 -0
- package/dist/canvas/host/strokeSnap.js +88 -143
- package/dist/canvas/index.d.ts +1 -1
- package/dist/canvas/index.js +1 -1
- package/dist/canvas/openMarks.js +2 -2
- package/dist/canvas/outsideClickDeselect.js +6 -7
- package/dist/canvas/panZoomPosition.js +2 -2
- package/dist/canvas/preferredTextFont.js +13 -25
- package/dist/canvas/shapes/ShapeLibrary.js +138 -148
- package/dist/canvas/shapes/shapeImageStore.d.ts +45 -2
- package/dist/canvas/shapes/shapeImageStore.js +10 -3
- package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
- package/dist/canvas/toolbarPosition.d.ts +2 -2
- package/dist/canvas/toolbarPosition.js +4 -4
- 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/colorModel.js +21 -32
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.d.ts +2 -2
- package/dist/canvas/ui/floatingCard.js +20 -20
- package/dist/canvas/ui/floatingLayer.d.ts +13 -2
- package/dist/canvas/ui/floatingLayer.js +18 -7
- package/dist/canvas/ui/keyHints.js +9 -11
- package/dist/canvas/ui/popoverSide.js +2 -3
- package/dist/canvas/ui/selectionTraits.js +34 -40
- 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/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.js +71 -90
- 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/components/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.d.ts +15 -1
- package/dist/engine/EngineCore.js +724 -797
- package/dist/engine/codec/canvasDocument.d.ts +5 -0
- package/dist/engine/codec/canvasDocument.js +212 -149
- package/dist/engine/codec/hostReadableKeys.js +1 -1
- package/dist/engine/core/arrange.js +26 -38
- package/dist/engine/core/arrow.js +76 -89
- package/dist/engine/core/arrowBinding.js +98 -116
- package/dist/engine/core/arrowBindingRecords.js +23 -38
- package/dist/engine/core/brush.js +67 -94
- package/dist/engine/core/defaults.js +90 -51
- package/dist/engine/core/freehand.js +147 -163
- package/dist/engine/core/geometry.js +47 -54
- package/dist/engine/core/history.d.ts +6 -0
- package/dist/engine/core/history.js +49 -50
- package/dist/engine/core/hitTest.js +68 -81
- package/dist/engine/core/matrix.js +18 -20
- package/dist/engine/core/pathData.js +183 -210
- package/dist/engine/core/rotationReset.js +5 -6
- package/dist/engine/core/scene.d.ts +10 -0
- package/dist/engine/core/scene.js +153 -187
- package/dist/engine/core/scribble.js +59 -84
- package/dist/engine/core/shapePaths.js +12 -15
- package/dist/engine/core/shapeTools.js +72 -63
- package/dist/engine/core/snapping.js +65 -117
- package/dist/engine/core/style.js +31 -64
- package/dist/engine/core/transform.js +83 -94
- package/dist/engine/core/types.d.ts +8 -2
- package/dist/engine/core/types.js +4 -4
- package/dist/engine/core/viewport.js +23 -36
- package/dist/engine/input/PointerController.js +467 -474
- package/dist/engine/input/arrowHandles.js +12 -12
- package/dist/engine/input/gestures.js +265 -309
- package/dist/engine/input/hoverCursor.js +1 -1
- package/dist/engine/input/keyboard.js +27 -30
- package/dist/engine/input/selectionHandles.js +45 -50
- package/dist/engine/input/types.js +1 -1
- package/dist/engine/render/rasterize.js +86 -158
- package/dist/engine/state.d.ts +20 -0
- package/dist/engine/state.js +5 -15
- package/dist/engine/text/layoutText.js +43 -62
- package/dist/engine/text/textMetrics.js +8 -10
- package/dist/engine/widgets.js +101 -137
- package/dist/fonts/interFont.d.ts +10 -1
- package/dist/fonts/interFont.js +47 -75
- package/dist/fonts/workspaceFonts.js +32 -90
- package/dist/i18n/labels.js +4 -4
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/language.js +4 -4
- package/dist/i18n/messages.d.ts +8 -1
- package/dist/i18n/messages.js +10 -2
- package/dist/i18n/shortcuts.js +14 -14
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/settings/workspaceToolSettings.js +32 -48
- package/dist/tools/components/catalog.js +64 -74
- package/dist/tools/components/grouping.js +6 -28
- package/dist/tools/definitions.js +5 -5
- package/dist/tools/executors.js +105 -141
- package/dist/tools/hostAdapter.js +11 -13
- package/dist/tools/sceneSummary.js +43 -57
- package/dist/tools/sketchIntent.js +13 -21
- package/dist/tools/types.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
|
@@ -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,16 +4,16 @@
|
|
|
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
|
*/
|
|
12
12
|
import { CHROME_ANCHORS, normalizeAnchor } from './chromeLayout.js';
|
|
13
13
|
/** The places the toolbar can stand: `TL TC TR` (top), `CL CR` (the sides) and `BL BC BR` (bottom). */
|
|
14
|
-
export
|
|
14
|
+
export const TOOLBAR_POSITIONS = CHROME_ANCHORS;
|
|
15
15
|
/** Where the toolbar stands when the host says nothing: the bottom centre, as it always did. */
|
|
16
|
-
export
|
|
16
|
+
export const DEFAULT_TOOLBAR_POSITION = 'BC';
|
|
17
17
|
/**
|
|
18
18
|
* The position to use for what a host passed. Anything that is not one of the eight (the middle of the board, a word in
|
|
19
19
|
* lower case, nothing at all) is the default, so that a mistake in the host's option never takes the toolbar off the
|
|
@@ -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>
|
|
@@ -5,17 +5,8 @@
|
|
|
5
5
|
* and the panel has to show it and to take what a person types. Plain functions, free of Svelte and of the DOM, so Node
|
|
6
6
|
* can test them.
|
|
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
|
/** The colours the panel offers first, one click each. The first two are the board's own ink and paper. */
|
|
18
|
-
export
|
|
9
|
+
export const COLOR_PRESETS = [
|
|
19
10
|
'#0F172A',
|
|
20
11
|
'#FFFFFF',
|
|
21
12
|
'#EF4444',
|
|
@@ -27,61 +18,59 @@ export var COLOR_PRESETS = [
|
|
|
27
18
|
'#EC4899',
|
|
28
19
|
'#6B7280'
|
|
29
20
|
];
|
|
30
|
-
|
|
21
|
+
const HEX_PATTERN = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
31
22
|
/** True for a colour that paints nothing: `transparent`, or a colour that is fully see-through. */
|
|
32
23
|
export function isNoColor(color) {
|
|
33
24
|
if (!color)
|
|
34
25
|
return true;
|
|
35
|
-
|
|
26
|
+
const text = color.trim().toLowerCase();
|
|
36
27
|
if (text === 'transparent' || text === 'none')
|
|
37
28
|
return true;
|
|
38
|
-
|
|
29
|
+
const rgba = text.match(/^rgba\(\s*[^,]+,\s*[^,]+,\s*[^,]+,\s*([\d.]+)\s*\)$/);
|
|
39
30
|
return rgba ? Number.parseFloat(rgba[1]) === 0 : false;
|
|
40
31
|
}
|
|
41
32
|
/** What a person typed (`f80`, `#FF8800`, `ff8800`) as `#RRGGBB`, or null when it is not a colour. */
|
|
42
33
|
export function parseHexInput(text) {
|
|
43
|
-
|
|
34
|
+
const match = text.trim().match(HEX_PATTERN);
|
|
44
35
|
if (!match)
|
|
45
36
|
return null;
|
|
46
|
-
|
|
47
|
-
return
|
|
37
|
+
const digits = match[1].length === 3 ? [...match[1]].map((digit) => digit + digit).join('') : match[1];
|
|
38
|
+
return `#${digits.toUpperCase()}`;
|
|
48
39
|
}
|
|
49
40
|
function toHexByte(value) {
|
|
50
41
|
return Math.max(0, Math.min(255, Math.round(value))).toString(16).padStart(2, '0');
|
|
51
42
|
}
|
|
52
43
|
function hslToHex(hue, saturation, lightness) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
44
|
+
const s = saturation / 100;
|
|
45
|
+
const l = lightness / 100;
|
|
46
|
+
const a = s * Math.min(l, 1 - l);
|
|
47
|
+
const channel = (n) => {
|
|
48
|
+
const k = (n + hue / 30) % 12;
|
|
58
49
|
return toHexByte(255 * (l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1)));
|
|
59
50
|
};
|
|
60
|
-
return
|
|
51
|
+
return `#${channel(0)}${channel(8)}${channel(4)}`.toUpperCase();
|
|
61
52
|
}
|
|
62
53
|
/**
|
|
63
54
|
* A stored colour as `#RRGGBB`: a hex, an `rgb()` or `hsl()` an older canvas may hold, or the nearest the browser can
|
|
64
55
|
* say for a colour name. `fallback` is what is answered for a colour that cannot be read.
|
|
65
56
|
*/
|
|
66
|
-
export function colorToHex(color, fallback) {
|
|
67
|
-
var _a;
|
|
68
|
-
if (fallback === void 0) { fallback = '#000000'; }
|
|
57
|
+
export function colorToHex(color, fallback = '#000000') {
|
|
69
58
|
if (!color)
|
|
70
59
|
return fallback;
|
|
71
|
-
|
|
60
|
+
const hex = parseHexInput(color);
|
|
72
61
|
if (hex)
|
|
73
62
|
return hex;
|
|
74
|
-
|
|
75
|
-
|
|
63
|
+
const text = color.trim();
|
|
64
|
+
const rgb = text.match(/^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/i);
|
|
76
65
|
if (rgb)
|
|
77
|
-
return
|
|
78
|
-
|
|
66
|
+
return `#${toHexByte(Number(rgb[1]))}${toHexByte(Number(rgb[2]))}${toHexByte(Number(rgb[3]))}`.toUpperCase();
|
|
67
|
+
const hsl = text.match(/^hsla?\(\s*([\d.]+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%/i);
|
|
79
68
|
if (hsl)
|
|
80
69
|
return hslToHex(Number(hsl[1]), Number(hsl[2]), Number(hsl[3]));
|
|
81
|
-
return
|
|
70
|
+
return NAMED_COLORS[text.toLowerCase()] ?? fallback;
|
|
82
71
|
}
|
|
83
72
|
/** The few colour names an older canvas may hold. A name that is not here reads as the fallback. */
|
|
84
|
-
|
|
73
|
+
const NAMED_COLORS = Object.freeze({
|
|
85
74
|
black: '#000000',
|
|
86
75
|
white: '#FFFFFF',
|
|
87
76
|
red: '#FF0000',
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/** Names the colour picker fills in at runtime (`{s}`, `{v}`, `{hex}`), built without literals the word scan would read. */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
const s = `{${'s'}}`;
|
|
3
|
+
const v = `{${'v'}}`;
|
|
4
|
+
const hex = `{${'hex'}}`;
|
|
5
5
|
/** Words the design-system colour picker speaks; templates keep their placeholders for the picker to replace. */
|
|
6
6
|
export function colorPickerMessages(t) {
|
|
7
7
|
return {
|
|
8
8
|
area: t('canvas.colorPicker.area'),
|
|
9
|
-
areaValue: t('canvas.colorPicker.areaValue', { s
|
|
9
|
+
areaValue: t('canvas.colorPicker.areaValue', { s, v }),
|
|
10
10
|
hue: t('canvas.colorPicker.hue'),
|
|
11
11
|
hex: t('canvas.panel.hex'),
|
|
12
12
|
add: t('canvas.colorPicker.add'),
|
|
13
|
-
swatch: t('canvas.colorPicker.swatch', { hex
|
|
13
|
+
swatch: t('canvas.colorPicker.swatch', { hex })
|
|
14
14
|
};
|
|
15
15
|
}
|
|
@@ -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.
|
|
@@ -12,16 +12,16 @@
|
|
|
12
12
|
* when it reads this file. Kept free of Svelte and of the DOM so that Node can test it.
|
|
13
13
|
*/
|
|
14
14
|
/** The card itself: its corners, border, fill, padding and shadow. */
|
|
15
|
-
export
|
|
15
|
+
export const FLOATING_CARD_CLASSES = 'rounded-xl border border-border bg-background p-[3px] shadow-floating';
|
|
16
16
|
/**
|
|
17
17
|
* The padding of the canvas's menus (the Shapes menu, the right-click menu and their submenus). They are the design system's
|
|
18
18
|
* Dropdown Menu, drawn in Figma the same way as the cards above: the first row stands 4 px from the outer edge, the 1 px
|
|
19
19
|
* border inside that. The component's own padding (4 px, beside the border) makes a menu 2 px larger each way than Figma's:
|
|
20
20
|
* the Shape Menu is 196 x 246 there, and measures 246 only with 3 px.
|
|
21
21
|
*/
|
|
22
|
-
export
|
|
22
|
+
export const MENU_PADDING_CLASS = 'p-[3px]';
|
|
23
23
|
/** Figma "Layer Menu" (519:*): 4 px inset, 220 × 136 with 32 px rows. */
|
|
24
|
-
export
|
|
24
|
+
export const LAYER_MENU_PADDING_CLASS = 'p-1';
|
|
25
25
|
/**
|
|
26
26
|
* A menu, a popover or a tooltip of the design system slides and fades in, and its classes do not ask whether the system wants
|
|
27
27
|
* less motion. The canvas adds this to each one it draws: with `prefers-reduced-motion: reduce` the card appears and goes
|
|
@@ -30,9 +30,9 @@ export var LAYER_MENU_PADDING_CLASS = 'p-1';
|
|
|
30
30
|
* The states are those of the three components: a menu and a popover are `open` and `closed`, a tooltip `delayed-open`,
|
|
31
31
|
* `instant-open` and `closed`.
|
|
32
32
|
*/
|
|
33
|
-
export
|
|
33
|
+
export const OVERLAY_REDUCED_MOTION_CLASSES = 'motion-reduce:animate-none motion-reduce:data-[state=open]:animate-none motion-reduce:data-[state=closed]:animate-none motion-reduce:data-[state=delayed-open]:animate-none motion-reduce:data-[state=instant-open]:animate-none';
|
|
34
34
|
/** Canvas-floated surfaces stay below site dialogs and toasts (design-system overlays use z-50). */
|
|
35
|
-
export
|
|
35
|
+
export const CANVAS_OVERLAY_Z_CLASS = 'z-40';
|
|
36
36
|
/**
|
|
37
37
|
* The ring of a menu's button while its menu is open, and while the keyboard is on it: 2 px of ring standing 2 px off the
|
|
38
38
|
* button, with the board's colour in the gap, as the design system draws its focus ring. Figma draws the open "Shapes" button
|
|
@@ -42,23 +42,23 @@ export var CANVAS_OVERLAY_Z_CLASS = 'z-40';
|
|
|
42
42
|
* `--tw-ring-offset-width` with `!important` on every element that has `aria-expanded` (a menu's button always has), so the
|
|
43
43
|
* offset of a ring on such a button is lost, whatever class asks for it.
|
|
44
44
|
*/
|
|
45
|
-
export
|
|
45
|
+
export const MENU_TRIGGER_RING_CLASSES = 'focus-visible:shadow-[0_0_0_2px_var(--color-background),0_0_0_4px_var(--color-ring)] data-[state=open]:shadow-[0_0_0_2px_var(--color-background),0_0_0_4px_var(--color-ring)]';
|
|
46
46
|
/**
|
|
47
47
|
* Tabler toolbar icons are 16 px (`size-4`) with stroke 2 in a 24 px viewBox: 2 × 16 / 24 = 1.333 px on screen.
|
|
48
48
|
* A library shape glyph is drawn in a 100 px viewBox, so it needs a stroke of 1.333 × 100 / 16 = 8.33 in its own units to
|
|
49
49
|
* look as thick. The design system's menu item forces `size-4` and `stroke-2` on every svg inside it through CSS, which beats
|
|
50
50
|
* the `stroke-width` attribute (the glyphs were 0.32 px thick), so the width is set inline on the glyph.
|
|
51
51
|
*/
|
|
52
|
-
export
|
|
53
|
-
export
|
|
54
|
-
export
|
|
55
|
-
export
|
|
56
|
-
export
|
|
57
|
-
export
|
|
58
|
-
export
|
|
59
|
-
export
|
|
52
|
+
export const TOOLBAR_ICON_STROKE_CLASSES = '[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg]:stroke-2';
|
|
53
|
+
export const TOOLBAR_ICON_SIZE_PX = 16;
|
|
54
|
+
export const TOOLBAR_ICON_VIEWBOX = 24;
|
|
55
|
+
export const TOOLBAR_ICON_STROKE_UNITS = 2;
|
|
56
|
+
export const TOOLBAR_ICON_STROKE_PX = (TOOLBAR_ICON_STROKE_UNITS * TOOLBAR_ICON_SIZE_PX) / TOOLBAR_ICON_VIEWBOX;
|
|
57
|
+
export const SHAPE_LIBRARY_ICON_SIZE_PX = TOOLBAR_ICON_SIZE_PX;
|
|
58
|
+
export const SHAPE_LIBRARY_VIEWBOX = 100;
|
|
59
|
+
export const SHAPE_LIBRARY_STROKE_WIDTH = (TOOLBAR_ICON_STROKE_PX * SHAPE_LIBRARY_VIEWBOX) / SHAPE_LIBRARY_ICON_SIZE_PX;
|
|
60
60
|
/** Figma's measures of the cards, in px (a Figma frame counts an inside stroke as part of the card). */
|
|
61
|
-
export
|
|
61
|
+
export const FLOATING_CARD_METRICS = {
|
|
62
62
|
/** The whole toolbar: five tools, the Shapes menu and the history group, with their dividers. */
|
|
63
63
|
toolbarWidth: 349,
|
|
64
64
|
toolbarHeight: 44,
|
|
@@ -76,7 +76,7 @@ export var FLOATING_CARD_METRICS = {
|
|
|
76
76
|
* with. (An upright bar is as long as the board is tall, so it always has them.) Written out in full, so a page's stylesheet
|
|
77
77
|
* picks it up.
|
|
78
78
|
*/
|
|
79
|
-
export
|
|
79
|
+
export const TOOLBAR_HISTORY_VISIBLE_FROM = 'hidden @[384px]:flex';
|
|
80
80
|
/**
|
|
81
81
|
* The width of board from which the zoom card is drawn, by the way it stands beside the toolbar (see `chromeLayout.ts`, which
|
|
82
82
|
* picks the case from the two anchors a page named). Narrower than that the zoom card is not drawn, as in Figma's phone: a
|
|
@@ -92,7 +92,7 @@ export var TOOLBAR_HISTORY_VISIBLE_FROM = 'hidden @[384px]:flex';
|
|
|
92
92
|
* - `centredBesideCornerToolbar`: the toolbar at a corner and the zoom card centred: the card's left edge has to clear the
|
|
93
93
|
* toolbar's right edge, which is 365 px from the board's left edge.
|
|
94
94
|
*/
|
|
95
|
-
export
|
|
95
|
+
export const ZOOM_CONTROL_MIN_WIDTHS = {
|
|
96
96
|
alone: 512,
|
|
97
97
|
sameSlot: 560,
|
|
98
98
|
oppositeCorners: 560,
|
|
@@ -100,7 +100,7 @@ export var ZOOM_CONTROL_MIN_WIDTHS = {
|
|
|
100
100
|
centredBesideCornerToolbar: 912
|
|
101
101
|
};
|
|
102
102
|
/** The classes that show the zoom card from each of those widths. Written out in full, so a page's stylesheet picks every one up. */
|
|
103
|
-
export
|
|
103
|
+
export const ZOOM_CONTROL_VISIBLE_FROM = {
|
|
104
104
|
alone: 'hidden @lg:flex',
|
|
105
105
|
sameSlot: 'hidden @[560px]:flex',
|
|
106
106
|
oppositeCorners: 'hidden @[560px]:flex',
|
|
@@ -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;
|
|
@@ -12,34 +12,45 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { getContext, setContext } from 'svelte';
|
|
14
14
|
import { readable } from 'svelte/store';
|
|
15
|
-
|
|
15
|
+
const FLOATING_LAYER_CONTEXT_KEY = Symbol('widgetic-canvas-floating-layer');
|
|
16
16
|
/**
|
|
17
17
|
* The classes of the layer's element: no size (so it catches no press, and no `pointer-events: none` is needed, which the
|
|
18
18
|
* menus inside would inherit), above the chrome, and a containing block for what is fixed inside it.
|
|
19
19
|
*/
|
|
20
|
-
export
|
|
20
|
+
export const FLOATING_LAYER_CLASSES = 'absolute inset-0 z-50 h-0 w-0 [contain:layout]';
|
|
21
21
|
/** Called by the canvas that owns the layer, before its children are made. */
|
|
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
|
-
|
|
28
|
-
return (_a = getContext(FLOATING_LAYER_CONTEXT_KEY)) !== null && _a !== void 0 ? _a : readable(null);
|
|
30
|
+
return getContext(FLOATING_LAYER_CONTEXT_KEY) ?? readable(undefined);
|
|
29
31
|
}
|
|
30
32
|
/** Below design-system dialogs, dropdowns and toasts (`z-50`); still above normal page content so a compact card does not cover menus. */
|
|
31
|
-
export
|
|
33
|
+
export const CANVAS_OVERLAY_PORTAL_Z_CLASS = 'z-40';
|
|
32
34
|
/**
|
|
33
35
|
* Portal target for a menu, popover or tooltip: `document.body` in the light DOM, else the in-canvas floating layer.
|
|
34
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.
|
|
35
43
|
*/
|
|
36
44
|
export function canvasOverlayPortalProps(floatingLayer) {
|
|
45
|
+
if (floatingLayer === null) {
|
|
46
|
+
return { disabled: true, class: CANVAS_OVERLAY_PORTAL_Z_CLASS };
|
|
47
|
+
}
|
|
37
48
|
if (!floatingLayer) {
|
|
38
49
|
return typeof document !== 'undefined'
|
|
39
50
|
? { to: document.body, class: CANVAS_OVERLAY_PORTAL_Z_CLASS }
|
|
40
51
|
: { class: CANVAS_OVERLAY_PORTAL_Z_CLASS };
|
|
41
52
|
}
|
|
42
|
-
|
|
53
|
+
const root = floatingLayer.getRootNode();
|
|
43
54
|
if (typeof Document !== 'undefined' && root instanceof Document) {
|
|
44
55
|
return { to: document.body, class: CANVAS_OVERLAY_PORTAL_Z_CLASS };
|
|
45
56
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
/** The platform name of a browser, from the newer API when there is one. */
|
|
2
2
|
function platformName(nav) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return (_c = (_b = (_a = withData.userAgentData) === null || _a === void 0 ? void 0 : _a.platform) !== null && _b !== void 0 ? _b : nav.platform) !== null && _c !== void 0 ? _c : '';
|
|
3
|
+
const withData = nav;
|
|
4
|
+
return withData.userAgentData?.platform ?? nav.platform ?? '';
|
|
6
5
|
}
|
|
7
6
|
/** True on a Mac, an iPhone or an iPad, where the shortcut key is Command and the menus print it as a symbol. */
|
|
8
|
-
export function isApplePlatform(nav) {
|
|
9
|
-
if (nav === void 0) { nav = typeof navigator === 'undefined' ? undefined : navigator; }
|
|
7
|
+
export function isApplePlatform(nav = typeof navigator === 'undefined' ? undefined : navigator) {
|
|
10
8
|
if (!nav)
|
|
11
9
|
return false;
|
|
12
10
|
return /mac|iphone|ipad|ipod/i.test(platformName(nav));
|
|
@@ -19,7 +17,7 @@ export function isApplePlatform(nav) {
|
|
|
19
17
|
export function ariaKeyShortcut(chord, apple) {
|
|
20
18
|
if (typeof chord.key !== 'string')
|
|
21
19
|
return undefined;
|
|
22
|
-
|
|
20
|
+
const parts = [];
|
|
23
21
|
if (chord.mod)
|
|
24
22
|
parts.push(apple ? 'Meta' : 'Control');
|
|
25
23
|
if (chord.shift)
|
|
@@ -32,10 +30,10 @@ export function ariaKeyShortcut(chord, apple) {
|
|
|
32
30
|
* the same in every language; the words of the others come from the page's language.
|
|
33
31
|
*/
|
|
34
32
|
export function chordText(chord, apple, t) {
|
|
35
|
-
|
|
33
|
+
const key = typeof chord.key === 'string' ? chord.key : t(chord.key.name);
|
|
36
34
|
if (apple)
|
|
37
|
-
return
|
|
38
|
-
|
|
35
|
+
return `${chord.shift ? '⇧' : ''}${chord.mod ? '⌘' : ''}${key}`;
|
|
36
|
+
const parts = [];
|
|
39
37
|
if (chord.mod)
|
|
40
38
|
parts.push(t('canvas.key.ctrl'));
|
|
41
39
|
if (chord.shift)
|
|
@@ -48,8 +46,8 @@ export function chordText(chord, apple, t) {
|
|
|
48
46
|
* elsewhere. The toolbar and zoom control keep `chordText` (symbols on Apple).
|
|
49
47
|
*/
|
|
50
48
|
export function menuChordText(chord, apple, t) {
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
const key = typeof chord.key === 'string' ? chord.key : t(chord.key.name);
|
|
50
|
+
const parts = [];
|
|
53
51
|
if (chord.shift)
|
|
54
52
|
parts.push(t('canvas.key.shift'));
|
|
55
53
|
if (chord.mod)
|