@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
package/README.md
CHANGED
|
@@ -217,6 +217,7 @@ ORIGIN=http://127.0.0.1:5181 node scripts/browser/conformance.mjs # the host c
|
|
|
217
217
|
ORIGIN=http://127.0.0.1:5181 node scripts/browser/interaction.mjs # a real mouse and keyboard: tools, gestures, keys
|
|
218
218
|
ORIGIN=http://127.0.0.1:5181 node scripts/browser/shadow.mjs # inside a shadow root, as the UI SDK mounts it
|
|
219
219
|
ORIGIN=http://127.0.0.1:5181 node scripts/browser/widgetCard.mjs # a live widget laid over a card
|
|
220
|
+
ORIGIN=http://127.0.0.1:5181 node scripts/browser/selector.mjs # the element selector: its indicator, the toolbar that stays, a card with no placeholder
|
|
220
221
|
ORIGIN=http://127.0.0.1:5181 node scripts/browser/touch.mjs # touch and pen
|
|
221
222
|
ORIGIN=http://127.0.0.1:5181 node scripts/browser/responsive.mjs # the Figma layouts at desktop, tablet and phone widths
|
|
222
223
|
ORIGIN=http://127.0.0.1:5181 node scripts/browser/a11y.mjs # the accessibility tree, focus, reduced motion
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
import { CanvasHost, DEFAULT_HOST_PROPS } from './host/CanvasHost.js';
|
|
30
30
|
import type { CanvasHostProps, SelectorGuide } from './host/CanvasHost.js';
|
|
31
31
|
import { forwardToHost } from './host/CanvasHostApi.js';
|
|
32
|
-
import { chromeSlots, panelClearanceFor, zoomVisibilityMinWidth } from './chromeLayout.js';
|
|
32
|
+
import { chromeSlots, panelClearanceFor, selectorIndicatorTopClassFor, zoomVisibilityMinWidth } from './chromeLayout.js';
|
|
33
33
|
import { DEFAULT_PAN_ZOOM_POSITION, normalizePanZoomPosition } from './panZoomPosition.js';
|
|
34
34
|
import type { PanZoomPosition } from './panZoomPosition.js';
|
|
35
35
|
import { DEFAULT_TOOLBAR_POSITION, normalizeToolbarPosition } from './toolbarPosition.js';
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
import CanvasToolbar from './ui/CanvasToolbar.svelte';
|
|
39
39
|
import { FLOATING_LAYER_CLASSES, provideFloatingLayer } from './ui/floatingLayer.js';
|
|
40
40
|
import SelectionPanel from './ui/SelectionPanel.svelte';
|
|
41
|
-
import
|
|
41
|
+
import SelectorIndicator from './ui/SelectorIndicator.svelte';
|
|
42
42
|
import ShortcutsPanel from './ui/ShortcutsPanel.svelte';
|
|
43
43
|
import ZoomControl from './ui/ZoomControl.svelte';
|
|
44
44
|
import { shouldShowEmptyBoardHint } from './emptyBoardHint.js';
|
|
@@ -68,10 +68,10 @@
|
|
|
68
68
|
export let panZoomPosition: PanZoomPosition = DEFAULT_PAN_ZOOM_POSITION;
|
|
69
69
|
|
|
70
70
|
// Where the drawing toolbar stands: any of the same eight places (BC, the bottom centre, is the default). On the left or
|
|
71
|
-
// the right edge it stands upright, and its menus open sideways.
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
//
|
|
71
|
+
// the right edge it stands upright, and its menus open sideways. A host that has something of its own at the bottom
|
|
72
|
+
// centre of the page (Shopify's Sidekick) names the place it wants; two cards named for one place stand side by side.
|
|
73
|
+
// Anything that is not one of the eight is the bottom centre. (The toolbar stays after the first generation: the
|
|
74
|
+
// selector's indicator is a card of its own at the top.)
|
|
75
75
|
export let toolbarPosition: ToolbarPosition = DEFAULT_TOOLBAR_POSITION;
|
|
76
76
|
|
|
77
77
|
// Wireframe mode: hides the colour fields of the selection panel and keeps new objects white with a dark stroke
|
|
@@ -82,13 +82,17 @@
|
|
|
82
82
|
// panel) is always there. Default off for the sketch MVP.
|
|
83
83
|
export let advancedFeatures: CanvasHostProps['advancedFeatures'] = DEFAULT_HOST_PROPS.advancedFeatures;
|
|
84
84
|
|
|
85
|
-
/** The
|
|
85
|
+
/** The selector's indicator at the top of the board: shown while the page says so (a widget stands on the board and the hint is not closed). */
|
|
86
86
|
export let showElementSelector: CanvasHostProps['showElementSelector'] = DEFAULT_HOST_PROPS.showElementSelector;
|
|
87
|
-
/**
|
|
87
|
+
/** The drawing toolbar. The page keeps it for as long as the board is drawn on, widget or not. */
|
|
88
88
|
export let showDrawingTools: CanvasHostProps['showDrawingTools'] = DEFAULT_HOST_PROPS.showDrawingTools;
|
|
89
|
+
/** The page's element selector is picking now: the indicator says "Selector on", and the arrow keys are the selector's. */
|
|
89
90
|
export let elementSelectorActive: CanvasHostProps['elementSelectorActive'] = DEFAULT_HOST_PROPS.elementSelectorActive;
|
|
91
|
+
/** Accepted for the pages that set it: the Select tool turns the selector on and off now. */
|
|
90
92
|
export let onToggleElementSelector: CanvasHostProps['onToggleElementSelector'] = DEFAULT_HOST_PROPS.onToggleElementSelector;
|
|
91
|
-
/**
|
|
93
|
+
/** The person closed the selector's indicator. The page decides when it comes back. */
|
|
94
|
+
export let onDismissElementSelectorHint: CanvasHostProps['onDismissElementSelectorHint'] = DEFAULT_HOST_PROPS.onDismissElementSelectorHint;
|
|
95
|
+
/** Words for the selector's indicator. */
|
|
92
96
|
export let selectorGuide: SelectorGuide | null = DEFAULT_HOST_PROPS.selectorGuide;
|
|
93
97
|
/** The zoom card. Off on the site when debug is off. The save control stays. */
|
|
94
98
|
export let showZoomPanel: CanvasHostProps['showZoomPanel'] = DEFAULT_HOST_PROPS.showZoomPanel;
|
|
@@ -199,6 +203,12 @@
|
|
|
199
203
|
export let userId: CanvasHostProps['userId'] = DEFAULT_HOST_PROPS.userId;
|
|
200
204
|
/** Brand-kit fonts for this workspace (B15). */
|
|
201
205
|
export let workspaceFonts: CanvasHostProps['workspaceFonts'] = DEFAULT_HOST_PROPS.workspaceFonts;
|
|
206
|
+
/**
|
|
207
|
+
* Where the canvas gets Inter from when the page does not declare it: the addresses of its WOFF2 files (URLs, or `data:`
|
|
208
|
+
* URLs for a page with a strict `font-src`). None by default, so the canvas asks no one for a file and waits for the
|
|
209
|
+
* Inter the page declares itself.
|
|
210
|
+
*/
|
|
211
|
+
export let interFontSources: CanvasHostProps['interFontSources'] = DEFAULT_HOST_PROPS.interFontSources;
|
|
202
212
|
|
|
203
213
|
/**
|
|
204
214
|
* The language of the canvas: `locale` ("de", "pt-BR") picks the plural rules, the number format and the language
|
|
@@ -237,6 +247,7 @@
|
|
|
237
247
|
showDrawingTools,
|
|
238
248
|
elementSelectorActive,
|
|
239
249
|
onToggleElementSelector,
|
|
250
|
+
onDismissElementSelectorHint,
|
|
240
251
|
selectorGuide,
|
|
241
252
|
showZoomPanel,
|
|
242
253
|
mediaBtsOnBar,
|
|
@@ -269,7 +280,8 @@
|
|
|
269
280
|
keepCenterOnResize,
|
|
270
281
|
workspaceId,
|
|
271
282
|
userId,
|
|
272
|
-
workspaceFonts
|
|
283
|
+
workspaceFonts,
|
|
284
|
+
interFontSources
|
|
273
285
|
};
|
|
274
286
|
$: host.setProps(hostProps);
|
|
275
287
|
|
|
@@ -314,15 +326,28 @@
|
|
|
314
326
|
});
|
|
315
327
|
// A live widget laid over a selected card hides the frame the board draws, so the page's own layer draws it instead.
|
|
316
328
|
$: frameElsewhere = widgetSelectionLayerTarget !== '' && onlyCardIsSelected(engineState);
|
|
317
|
-
$: showSelectorBar = !showDrawingTools && showElementSelector;
|
|
318
329
|
$: showZoomControl = showZoomPanel || showSaveButton;
|
|
319
330
|
// Where the two cards of the chrome stand. Each names one of eight anchors; two named for the same one share a slot, side by side.
|
|
320
331
|
$: toolbarAnchor = normalizeToolbarPosition(toolbarPosition);
|
|
321
332
|
$: zoomAnchor = normalizePanZoomPosition(panZoomPosition);
|
|
322
|
-
$: slots = chromeSlots(toolbarAnchor, zoomAnchor, { toolbar: showDrawingTools
|
|
333
|
+
$: slots = chromeSlots(toolbarAnchor, zoomAnchor, { toolbar: showDrawingTools, zoom: showZoomControl });
|
|
323
334
|
$: zoomVisibleMinWidth = zoomVisibilityMinWidth(toolbarAnchor, zoomAnchor);
|
|
335
|
+
// The selector's indicator stands at the top centre, below a card the page put there. Closing it hides it at once; it shows
|
|
336
|
+
// again when the page turns `showElementSelector` off and on (the next widget), or says nothing and keeps it on.
|
|
337
|
+
let selectorHintClosed = false;
|
|
338
|
+
$: if (!showElementSelector) selectorHintClosed = false;
|
|
339
|
+
$: showSelectorIndicator = showElementSelector && !selectorHintClosed;
|
|
340
|
+
$: selectorIndicatorTopClass = selectorIndicatorTopClassFor(slots);
|
|
341
|
+
function closeSelectorHint(): void {
|
|
342
|
+
selectorHintClosed = true;
|
|
343
|
+
try {
|
|
344
|
+
onDismissElementSelectorHint?.();
|
|
345
|
+
} catch (error) {
|
|
346
|
+
console.warn('Canvas: onDismissElementSelectorHint failed', error);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
324
349
|
// The selection panel stands in the top corner at the end of the line: it keeps clear of the cards the page put there.
|
|
325
|
-
$: panelClearance = panelClearanceFor(slots);
|
|
350
|
+
$: panelClearance = panelClearanceFor(slots, { selectorIndicator: showSelectorIndicator });
|
|
326
351
|
|
|
327
352
|
/**
|
|
328
353
|
* THE FUNCTIONS THE PAGE CALLS
|
|
@@ -425,25 +450,28 @@
|
|
|
425
450
|
|
|
426
451
|
<!-- The chrome: siblings of the board, so a press on a button never reaches it. It waits while the board loads. -->
|
|
427
452
|
<div class="pointer-events-none absolute inset-0 z-10 transition-opacity duration-200 motion-reduce:transition-none {loading ? 'opacity-60' : ''}" inert={loading}>
|
|
428
|
-
<!-- One slot for each place that has a card: the toolbar
|
|
453
|
+
<!-- One slot for each place that has a card: the toolbar and the zoom control, side by side when they share a place. -->
|
|
429
454
|
{#each slots as slot (slot.anchor)}
|
|
430
455
|
<div class={slot.classes} data-canvas-slot={slot.anchor}>
|
|
431
456
|
{#each slot.cards as card (card)}
|
|
432
457
|
{#if card === 'toolbar'}
|
|
433
|
-
{
|
|
434
|
-
<CanvasToolbar {host} state={engineState} ui={uiState} {showDrawingTools} anchor={toolbarAnchor} />
|
|
435
|
-
{:else}
|
|
436
|
-
<SelectorBar active={elementSelectorActive} guide={selectorGuide} anchor={toolbarAnchor} onToggle={() => onToggleElementSelector?.()} />
|
|
437
|
-
{/if}
|
|
458
|
+
<CanvasToolbar {host} state={engineState} ui={uiState} {showDrawingTools} anchor={toolbarAnchor} />
|
|
438
459
|
{:else}
|
|
439
460
|
<ZoomControl {host} state={engineState} ui={uiState} anchor={zoomAnchor} visibleMinWidth={zoomVisibleMinWidth} showZoom={showZoomPanel} {showSaveButton} />
|
|
440
461
|
{/if}
|
|
441
462
|
{/each}
|
|
442
463
|
</div>
|
|
443
464
|
{/each}
|
|
465
|
+
|
|
466
|
+
<!-- The selector's indicator: at the top centre while a widget stands on the board, until the person closes it. -->
|
|
467
|
+
{#if showSelectorIndicator}
|
|
468
|
+
<div class="absolute inset-x-4 flex justify-center {selectorIndicatorTopClass}" data-canvas-selector-indicator-slot>
|
|
469
|
+
<SelectorIndicator active={elementSelectorActive} guide={selectorGuide} onDismiss={closeSelectorHint} />
|
|
470
|
+
</div>
|
|
471
|
+
{/if}
|
|
444
472
|
</div>
|
|
445
473
|
|
|
446
|
-
<!-- The panel that edits the selection: a selection opens it, and its close button puts it away. -->
|
|
474
|
+
<!-- The panel that edits the selection: a selection shows its settings control (it never opens the panel by itself), the control opens it, and its close button puts it away. -->
|
|
447
475
|
<SelectionPanel
|
|
448
476
|
{host}
|
|
449
477
|
state={engineState}
|
|
@@ -455,6 +483,7 @@
|
|
|
455
483
|
canRefresh={!!onRefreshScreenshot}
|
|
456
484
|
canOpenDetails={!!onWidgetImageClick}
|
|
457
485
|
clearance={panelClearance}
|
|
486
|
+
widgetCardHasNoSettings={!advancedFeatures}
|
|
458
487
|
/>
|
|
459
488
|
|
|
460
489
|
<CanvasContextMenu {host} state={engineState} ui={uiState} board={boardElement} />
|
|
@@ -26,11 +26,12 @@ declare const DomCanvas: $$__sveltets_2_IsomorphicComponent<{
|
|
|
26
26
|
toolbarPosition?: ToolbarPosition;
|
|
27
27
|
wireframeMode?: CanvasHostProps["wireframeMode"];
|
|
28
28
|
advancedFeatures?: CanvasHostProps["advancedFeatures"];
|
|
29
|
-
/** The
|
|
30
|
-
/**
|
|
31
|
-
elementSelectorActive?: CanvasHostProps["elementSelectorActive"];
|
|
32
|
-
onToggleElementSelector?: CanvasHostProps["onToggleElementSelector"];
|
|
33
|
-
/**
|
|
29
|
+
/** The selector's indicator at the top of the board: shown while the page says so (a widget stands on the board and the hint is not closed). */ showElementSelector?: CanvasHostProps["showElementSelector"];
|
|
30
|
+
/** The drawing toolbar. The page keeps it for as long as the board is drawn on, widget or not. */ showDrawingTools?: CanvasHostProps["showDrawingTools"];
|
|
31
|
+
/** The page's element selector is picking now: the indicator says "Selector on", and the arrow keys are the selector's. */ elementSelectorActive?: CanvasHostProps["elementSelectorActive"];
|
|
32
|
+
/** Accepted for the pages that set it: the Select tool turns the selector on and off now. */ onToggleElementSelector?: CanvasHostProps["onToggleElementSelector"];
|
|
33
|
+
/** The person closed the selector's indicator. The page decides when it comes back. */ onDismissElementSelectorHint?: CanvasHostProps["onDismissElementSelectorHint"];
|
|
34
|
+
/** Words for the selector's indicator. */ selectorGuide?: SelectorGuide | null;
|
|
34
35
|
/** The zoom card. Off on the site when debug is off. The save control stays. */ showZoomPanel?: CanvasHostProps["showZoomPanel"];
|
|
35
36
|
/** Accepted for the pages that set it. The design puts Image in the Shapes menu, so it no longer changes what is drawn. */ mediaBtsOnBar?: CanvasHostProps["mediaBtsOnBar"];
|
|
36
37
|
initialData?: CanvasHostProps["initialData"];
|
|
@@ -66,6 +67,11 @@ declare const DomCanvas: $$__sveltets_2_IsomorphicComponent<{
|
|
|
66
67
|
/** Workspace id for persisted tool settings (B16). */ workspaceId?: CanvasHostProps["workspaceId"];
|
|
67
68
|
/** Optional user id when the host distinguishes users inside one workspace embed. */ userId?: CanvasHostProps["userId"];
|
|
68
69
|
/** Brand-kit fonts for this workspace (B15). */ workspaceFonts?: CanvasHostProps["workspaceFonts"];
|
|
70
|
+
/**
|
|
71
|
+
* Where the canvas gets Inter from when the page does not declare it: the addresses of its WOFF2 files (URLs, or `data:`
|
|
72
|
+
* URLs for a page with a strict `font-src`). None by default, so the canvas asks no one for a file and waits for the
|
|
73
|
+
* Inter the page declares itself.
|
|
74
|
+
*/ interFontSources?: CanvasHostProps["interFontSources"];
|
|
69
75
|
/**
|
|
70
76
|
* The language of the canvas: `locale` ("de", "pt-BR") picks the plural rules, the number format and the language
|
|
71
77
|
* the page's own words are in; `messages` are the page's own words, keyed like CANVAS_MESSAGES (a key left out
|
|
@@ -91,7 +97,7 @@ declare const DomCanvas: $$__sveltets_2_IsomorphicComponent<{
|
|
|
91
97
|
replaceObjectWithWidgetImage?: (objectId: string, widgetId: string, screenshotDataUrl: string) => Promise<string | null>;
|
|
92
98
|
updateWidgetImage?: (widgetId: string, newScreenshotDataUrl: string) => void;
|
|
93
99
|
selectWidgetShape?: (widgetId: string) => boolean;
|
|
94
|
-
listWidgetShapeScreenRects?: () => import("./host/screenRects.js").WidgetScreenRect[];
|
|
100
|
+
listWidgetShapeScreenRects?: (options?: import("./host/screenRects.js").ListWidgetScreenRectsOptions) => import("./host/screenRects.js").WidgetScreenRect[];
|
|
95
101
|
getWidgetShapeScreenRect?: (widgetId: string) => import("./host/screenRects.js").ScreenRect | null;
|
|
96
102
|
getObjectScreenRect?: (objectId: string) => import("./host/screenRects.js").ScreenRect | null;
|
|
97
103
|
getWidgetShapeDataUrl?: (widgetId: string) => string | null;
|
|
@@ -171,7 +177,7 @@ declare const DomCanvas: $$__sveltets_2_IsomorphicComponent<{
|
|
|
171
177
|
replaceObjectWithWidgetImage: (objectId: string, widgetId: string, screenshotDataUrl: string) => Promise<string | null>;
|
|
172
178
|
updateWidgetImage: (widgetId: string, newScreenshotDataUrl: string) => void;
|
|
173
179
|
selectWidgetShape: (widgetId: string) => boolean;
|
|
174
|
-
listWidgetShapeScreenRects: () => import("./host/screenRects.js").WidgetScreenRect[];
|
|
180
|
+
listWidgetShapeScreenRects: (options?: import("./host/screenRects.js").ListWidgetScreenRectsOptions) => import("./host/screenRects.js").WidgetScreenRect[];
|
|
175
181
|
getWidgetShapeScreenRect: (widgetId: string) => import("./host/screenRects.js").ScreenRect | null;
|
|
176
182
|
getObjectScreenRect: (objectId: string) => import("./host/screenRects.js").ScreenRect | null;
|
|
177
183
|
getWidgetShapeDataUrl: (widgetId: string) => string | null;
|
|
@@ -19,48 +19,12 @@
|
|
|
19
19
|
*
|
|
20
20
|
* Kept free of Svelte and of the DOM (the clock can be replaced) so that Node can test it.
|
|
21
21
|
*/
|
|
22
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
23
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
24
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
25
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
26
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
27
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
28
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
32
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
33
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
34
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
35
|
-
function step(op) {
|
|
36
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
37
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
38
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
39
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
40
|
-
switch (op[0]) {
|
|
41
|
-
case 0: case 1: t = op; break;
|
|
42
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
43
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
44
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
45
|
-
default:
|
|
46
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
47
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
48
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
49
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
50
|
-
if (t[2]) _.ops.pop();
|
|
51
|
-
_.trys.pop(); continue;
|
|
52
|
-
}
|
|
53
|
-
op = body.call(thisArg, _);
|
|
54
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
55
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
22
|
/** The shortest time a save that is held back waits before the host is asked again, so that a delay of 0 does not spin. */
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
now:
|
|
62
|
-
setTimer:
|
|
63
|
-
clearTimer:
|
|
23
|
+
const SHORTEST_RECHECK_DELAY_MS = 250;
|
|
24
|
+
const realClock = {
|
|
25
|
+
now: () => Date.now(),
|
|
26
|
+
setTimer: (callback, delayMs) => setTimeout(callback, delayMs),
|
|
27
|
+
clearTimer: (handle) => clearTimeout(handle)
|
|
64
28
|
};
|
|
65
29
|
/** A number a host passed as a duration: anything that is not a finite number of at least 0 is 0. */
|
|
66
30
|
function toDurationMs(value) {
|
|
@@ -70,20 +34,19 @@ function isPromiseLike(value) {
|
|
|
70
34
|
return !!value && typeof value.then === 'function';
|
|
71
35
|
}
|
|
72
36
|
export function createAutosaveScheduler(options) {
|
|
73
|
-
|
|
74
|
-
var clock = (_a = options.clock) !== null && _a !== void 0 ? _a : realClock;
|
|
37
|
+
const clock = options.clock ?? realClock;
|
|
75
38
|
/** Something changed that no save has taken yet. */
|
|
76
|
-
|
|
39
|
+
let dirty = false;
|
|
77
40
|
/** When the first change that no save has taken yet was made: where the longest wait is counted from. */
|
|
78
|
-
|
|
79
|
-
|
|
41
|
+
let firstChangeAt = null;
|
|
42
|
+
let timerHandle = null;
|
|
80
43
|
/** The save that is on its way, if there is one. It never rejects. */
|
|
81
|
-
|
|
44
|
+
let saveOnItsWay = null;
|
|
82
45
|
/** The next save fell due while another was on its way: it starts as soon as that one is done. */
|
|
83
|
-
|
|
46
|
+
let dueWhileSaving = false;
|
|
84
47
|
/** How many saves in a row have failed. A save that goes through, or a board that was just loaded, makes it 0. */
|
|
85
|
-
|
|
86
|
-
|
|
48
|
+
let failuresInARow = 0;
|
|
49
|
+
let disposed = false;
|
|
87
50
|
function stopTimer() {
|
|
88
51
|
if (timerHandle === null)
|
|
89
52
|
return;
|
|
@@ -107,8 +70,7 @@ export function createAutosaveScheduler(options) {
|
|
|
107
70
|
}
|
|
108
71
|
/** Starts the save, or, when the host holds saves back, looks again a delay later. */
|
|
109
72
|
function saveUnlessHeldBack() {
|
|
110
|
-
|
|
111
|
-
if ((_a = options.isSuspended) === null || _a === void 0 ? void 0 : _a.call(options)) {
|
|
73
|
+
if (options.isSuspended?.()) {
|
|
112
74
|
startTimer(Math.max(toDurationMs(options.getDelayMs()), SHORTEST_RECHECK_DELAY_MS));
|
|
113
75
|
return;
|
|
114
76
|
}
|
|
@@ -118,7 +80,7 @@ export function createAutosaveScheduler(options) {
|
|
|
118
80
|
function scheduleRetry() {
|
|
119
81
|
if (disposed || timerHandle !== null || !options.getRetryDelayMs)
|
|
120
82
|
return;
|
|
121
|
-
|
|
83
|
+
let waitMs = 0;
|
|
122
84
|
try {
|
|
123
85
|
waitMs = toDurationMs(options.getRetryDelayMs(failuresInARow));
|
|
124
86
|
}
|
|
@@ -129,13 +91,12 @@ export function createAutosaveScheduler(options) {
|
|
|
129
91
|
startTimer(waitMs);
|
|
130
92
|
}
|
|
131
93
|
function noteFailure(error) {
|
|
132
|
-
var _a;
|
|
133
94
|
// What the failed save was meant to keep is not kept: it is unsaved again, and the retry (or the next change or
|
|
134
95
|
// flush) tries again.
|
|
135
96
|
dirty = true;
|
|
136
97
|
failuresInARow += 1;
|
|
137
98
|
try {
|
|
138
|
-
|
|
99
|
+
options.onSaveFailed?.(error);
|
|
139
100
|
}
|
|
140
101
|
catch (reportError) {
|
|
141
102
|
console.warn('[autosave] onSaveFailed threw', reportError);
|
|
@@ -149,7 +110,7 @@ export function createAutosaveScheduler(options) {
|
|
|
149
110
|
// made while the save is on its way) is unsaved again, and is the next save's.
|
|
150
111
|
dirty = false;
|
|
151
112
|
firstChangeAt = null;
|
|
152
|
-
|
|
113
|
+
let outcome;
|
|
153
114
|
try {
|
|
154
115
|
outcome = options.save();
|
|
155
116
|
}
|
|
@@ -161,11 +122,11 @@ export function createAutosaveScheduler(options) {
|
|
|
161
122
|
failuresInARow = 0;
|
|
162
123
|
return Promise.resolve();
|
|
163
124
|
}
|
|
164
|
-
|
|
165
|
-
.then(
|
|
125
|
+
const running = Promise.resolve(outcome)
|
|
126
|
+
.then(() => {
|
|
166
127
|
failuresInARow = 0;
|
|
167
|
-
},
|
|
168
|
-
.then(
|
|
128
|
+
}, (error) => noteFailure(error))
|
|
129
|
+
.then(() => {
|
|
169
130
|
if (saveOnItsWay === running)
|
|
170
131
|
saveOnItsWay = null;
|
|
171
132
|
if (disposed)
|
|
@@ -181,36 +142,23 @@ export function createAutosaveScheduler(options) {
|
|
|
181
142
|
function markChanged() {
|
|
182
143
|
if (disposed)
|
|
183
144
|
return;
|
|
184
|
-
|
|
145
|
+
const now = clock.now();
|
|
185
146
|
dirty = true;
|
|
186
147
|
if (firstChangeAt === null)
|
|
187
148
|
firstChangeAt = now;
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
149
|
+
const quietUntil = now + toDurationMs(options.getDelayMs());
|
|
150
|
+
const longestWait = toDurationMs(options.getMaxWaitMs());
|
|
151
|
+
const dueAt = longestWait > 0 ? Math.min(quietUntil, firstChangeAt + longestWait) : quietUntil;
|
|
191
152
|
startTimer(dueAt - now);
|
|
192
153
|
}
|
|
193
|
-
function flush() {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
_a.sent();
|
|
202
|
-
return [3 /*break*/, 0];
|
|
203
|
-
case 2:
|
|
204
|
-
// Nothing changed since the last save (or the last failure left nothing unsaved): there is nothing to send.
|
|
205
|
-
if (disposed || !dirty)
|
|
206
|
-
return [2 /*return*/];
|
|
207
|
-
return [4 /*yield*/, startSave()];
|
|
208
|
-
case 3:
|
|
209
|
-
_a.sent();
|
|
210
|
-
return [2 /*return*/];
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
});
|
|
154
|
+
async function flush() {
|
|
155
|
+
// A save on its way finishes first, so that two never overlap.
|
|
156
|
+
while (saveOnItsWay)
|
|
157
|
+
await saveOnItsWay;
|
|
158
|
+
// Nothing changed since the last save (or the last failure left nothing unsaved): there is nothing to send.
|
|
159
|
+
if (disposed || !dirty)
|
|
160
|
+
return;
|
|
161
|
+
await startSave();
|
|
214
162
|
}
|
|
215
163
|
function cancel() {
|
|
216
164
|
stopTimer();
|
|
@@ -224,10 +172,10 @@ export function createAutosaveScheduler(options) {
|
|
|
224
172
|
disposed = true;
|
|
225
173
|
}
|
|
226
174
|
return {
|
|
227
|
-
markChanged
|
|
228
|
-
flush
|
|
229
|
-
cancel
|
|
230
|
-
dispose
|
|
175
|
+
markChanged,
|
|
176
|
+
flush,
|
|
177
|
+
cancel,
|
|
178
|
+
dispose,
|
|
231
179
|
get isDirty() {
|
|
232
180
|
return dirty;
|
|
233
181
|
}
|
|
@@ -10,4 +10,4 @@
|
|
|
10
10
|
* Written out in full, so that the stylesheet of a page that installs the canvas picks every class up when it reads this
|
|
11
11
|
* file. Kept free of Svelte and of the DOM so that Node can test it.
|
|
12
12
|
*/
|
|
13
|
-
export
|
|
13
|
+
export const BOARD_FRAME_CLASSES = 'rounded-card after:pointer-events-none after:absolute after:inset-0 after:z-50 after:rounded-[inherit] after:border after:border-border';
|
|
@@ -10,4 +10,4 @@
|
|
|
10
10
|
* white in the design, while the full canvas stays `muted`). Nothing else changes: the variable is not set anywhere else, so
|
|
11
11
|
* the board, the creator and the embeds keep the token.
|
|
12
12
|
*/
|
|
13
|
-
export
|
|
13
|
+
export const BOARD_SURFACE_COLOR = 'var(--canvas-surface, var(--muted, #f5f5f5))';
|
|
@@ -1,31 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
let _enabled = true;
|
|
2
2
|
export function setCanvasLogsEnabled(enabled) {
|
|
3
3
|
_enabled = enabled;
|
|
4
4
|
}
|
|
5
5
|
export function isCanvasLogsEnabled() {
|
|
6
6
|
return _enabled;
|
|
7
7
|
}
|
|
8
|
-
export function canvasLog() {
|
|
9
|
-
var args = [];
|
|
10
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
11
|
-
args[_i] = arguments[_i];
|
|
12
|
-
}
|
|
8
|
+
export function canvasLog(...args) {
|
|
13
9
|
if (_enabled)
|
|
14
|
-
console.log
|
|
10
|
+
console.log(...args);
|
|
15
11
|
}
|
|
16
|
-
export function canvasWarn() {
|
|
17
|
-
var args = [];
|
|
18
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
19
|
-
args[_i] = arguments[_i];
|
|
20
|
-
}
|
|
12
|
+
export function canvasWarn(...args) {
|
|
21
13
|
if (_enabled)
|
|
22
|
-
console.warn
|
|
14
|
+
console.warn(...args);
|
|
23
15
|
}
|
|
24
|
-
export function canvasDebug() {
|
|
25
|
-
var args = [];
|
|
26
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
27
|
-
args[_i] = arguments[_i];
|
|
28
|
-
}
|
|
16
|
+
export function canvasDebug(...args) {
|
|
29
17
|
if (_enabled)
|
|
30
|
-
console.debug
|
|
18
|
+
console.debug(...args);
|
|
31
19
|
}
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
export declare const CHROME_ANCHORS: readonly ["TL", "TC", "TR", "CL", "CR", "BL", "BC", "BR"];
|
|
22
22
|
/** One of {@link CHROME_ANCHORS}. */
|
|
23
23
|
export type ChromeAnchor = (typeof CHROME_ANCHORS)[number];
|
|
24
|
-
/** The cards of the chrome that stand on their own anchor: the drawing toolbar
|
|
24
|
+
/** The cards of the chrome that stand on their own anchor: the drawing toolbar and the zoom control. */
|
|
25
25
|
export type ChromeCardId = 'toolbar' | 'zoom';
|
|
26
26
|
/** The side of a card its menus and tooltips open to. */
|
|
27
27
|
export type PopoverSide = 'top' | 'bottom' | 'left' | 'right';
|
|
@@ -63,6 +63,12 @@ export declare function chromeSlots(toolbarAnchor: ChromeAnchor, zoomAnchor: Chr
|
|
|
63
63
|
export declare function zoomVisibilityClasses(toolbarAnchor: ChromeAnchor, zoomAnchor: ChromeAnchor): string;
|
|
64
64
|
/** Minimum board width (px) before the zoom card is drawn; pairs with scoped `@container` CSS in `ZoomControl.svelte`. */
|
|
65
65
|
export declare function zoomVisibilityMinWidth(toolbarAnchor: ChromeAnchor, zoomAnchor: ChromeAnchor): number;
|
|
66
|
+
/**
|
|
67
|
+
* The place of the selector's indicator: the top centre, 16 px from the edge like the other cards, and below a card that
|
|
68
|
+
* stands at the top centre itself (the toolbar or the zoom control, when a page put one there). The classes are written
|
|
69
|
+
* out in full, so that the stylesheet of a page that installs the canvas picks both up.
|
|
70
|
+
*/
|
|
71
|
+
export declare function selectorIndicatorTopClassFor(slots: readonly ChromeSlot[]): string;
|
|
66
72
|
/** What the selection panel (top right, 336 px wide) has to keep clear of. */
|
|
67
73
|
export interface PanelClearance {
|
|
68
74
|
/** A card stands on the top edge: the panel starts below it. */
|
|
@@ -74,5 +80,10 @@ export interface PanelClearance {
|
|
|
74
80
|
*/
|
|
75
81
|
besideSideCard: ChromeCardId | null;
|
|
76
82
|
}
|
|
77
|
-
/**
|
|
78
|
-
|
|
83
|
+
/**
|
|
84
|
+
* What the panel keeps clear of, for the slots that are drawn. The selector's indicator, when it is shown, stands across the
|
|
85
|
+
* top centre (it can be as wide as the board), so the panel starts below it as it does below a card of the top edge.
|
|
86
|
+
*/
|
|
87
|
+
export declare function panelClearanceFor(slots: readonly ChromeSlot[], options?: {
|
|
88
|
+
selectorIndicator?: boolean;
|
|
89
|
+
}): PanelClearance;
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import { ZOOM_CONTROL_MIN_WIDTHS, ZOOM_CONTROL_VISIBLE_FROM } from './ui/floatingCard.js';
|
|
21
21
|
/** The eight places a card can stand. */
|
|
22
|
-
export
|
|
22
|
+
export const CHROME_ANCHORS = ['TL', 'TC', 'TR', 'CL', 'CR', 'BL', 'BC', 'BR'];
|
|
23
23
|
/**
|
|
24
24
|
* The classes that put an anchor in place, 16 px from the edges as the Figma design has it. Written out in full, so that
|
|
25
25
|
* the stylesheet of a page that installs the canvas picks every one of them up when it reads this file.
|
|
26
26
|
*/
|
|
27
|
-
|
|
27
|
+
const ANCHOR_CLASSES = {
|
|
28
28
|
// rtl-ok: the page names a corner of the screen, as it is drawn
|
|
29
29
|
TL: 'absolute top-4 left-4',
|
|
30
30
|
TC: 'absolute top-4 left-1/2 -translate-x-1/2',
|
|
@@ -45,9 +45,9 @@ var ANCHOR_CLASSES = {
|
|
|
45
45
|
* are against), a column on a side edge (centred on each other, so the layout does not depend on the direction of the
|
|
46
46
|
* page). A slot never grows larger than the board minus its 16 px edges.
|
|
47
47
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
const SLOT_TOP_ROW_CLASSES = 'flex flex-row items-start gap-2 max-w-[calc(100%-2rem)]';
|
|
49
|
+
const SLOT_BOTTOM_ROW_CLASSES = 'flex flex-row items-end gap-2 max-w-[calc(100%-2rem)]';
|
|
50
|
+
const SLOT_COLUMN_CLASSES = 'flex flex-col items-center gap-2 max-h-[calc(100%-2rem)]';
|
|
51
51
|
/** The anchor to use for what a page passed: anything that is not one of the eight is the fallback, so a mistyped option never takes a card off the board. */
|
|
52
52
|
export function normalizeAnchor(value, fallback) {
|
|
53
53
|
return CHROME_ANCHORS.includes(value) ? value : fallback;
|
|
@@ -77,19 +77,18 @@ export function anchorClasses(anchor) {
|
|
|
77
77
|
* from one anchor to another does not make the other one start again.
|
|
78
78
|
*/
|
|
79
79
|
export function chromeSlots(toolbarAnchor, zoomAnchor, shown) {
|
|
80
|
-
|
|
81
|
-
for (
|
|
82
|
-
|
|
83
|
-
var cards = [];
|
|
80
|
+
const slots = [];
|
|
81
|
+
for (const anchor of CHROME_ANCHORS) {
|
|
82
|
+
const cards = [];
|
|
84
83
|
if (shown.toolbar && toolbarAnchor === anchor)
|
|
85
84
|
cards.push('toolbar');
|
|
86
85
|
if (shown.zoom && zoomAnchor === anchor)
|
|
87
86
|
cards.push('zoom');
|
|
88
87
|
if (cards.length === 0)
|
|
89
88
|
continue;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
slots.push({ anchor
|
|
89
|
+
const vertical = isSideAnchor(anchor);
|
|
90
|
+
const layout = vertical ? SLOT_COLUMN_CLASSES : isTopAnchor(anchor) ? SLOT_TOP_ROW_CLASSES : SLOT_BOTTOM_ROW_CLASSES;
|
|
91
|
+
slots.push({ anchor, cards, vertical, classes: `${ANCHOR_CLASSES[anchor]} ${layout}` });
|
|
93
92
|
}
|
|
94
93
|
return slots;
|
|
95
94
|
}
|
|
@@ -102,8 +101,8 @@ export function zoomVisibilityClasses(toolbarAnchor, zoomAnchor) {
|
|
|
102
101
|
// A card on a side edge shares no line with a card on the top or the bottom edge, and neither do two cards on different edges.
|
|
103
102
|
if (isSideAnchor(toolbarAnchor) || isSideAnchor(zoomAnchor) || toolbarAnchor[0] !== zoomAnchor[0])
|
|
104
103
|
return ZOOM_CONTROL_VISIBLE_FROM.alone;
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
const toolbarColumn = toolbarAnchor[1];
|
|
105
|
+
const zoomColumn = zoomAnchor[1];
|
|
107
106
|
if (toolbarColumn === zoomColumn)
|
|
108
107
|
return ZOOM_CONTROL_VISIBLE_FROM.sameSlot;
|
|
109
108
|
if (toolbarColumn === 'C')
|
|
@@ -114,7 +113,7 @@ export function zoomVisibilityClasses(toolbarAnchor, zoomAnchor) {
|
|
|
114
113
|
}
|
|
115
114
|
/** Minimum board width (px) before the zoom card is drawn; pairs with scoped `@container` CSS in `ZoomControl.svelte`. */
|
|
116
115
|
export function zoomVisibilityMinWidth(toolbarAnchor, zoomAnchor) {
|
|
117
|
-
|
|
116
|
+
const className = zoomVisibilityClasses(toolbarAnchor, zoomAnchor);
|
|
118
117
|
if (className === ZOOM_CONTROL_VISIBLE_FROM.alone)
|
|
119
118
|
return ZOOM_CONTROL_MIN_WIDTHS.alone;
|
|
120
119
|
if (className === ZOOM_CONTROL_VISIBLE_FROM.sameSlot)
|
|
@@ -125,13 +124,24 @@ export function zoomVisibilityMinWidth(toolbarAnchor, zoomAnchor) {
|
|
|
125
124
|
return ZOOM_CONTROL_MIN_WIDTHS.centredBesideCornerToolbar;
|
|
126
125
|
return ZOOM_CONTROL_MIN_WIDTHS.oppositeCorners;
|
|
127
126
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
/**
|
|
128
|
+
* The place of the selector's indicator: the top centre, 16 px from the edge like the other cards, and below a card that
|
|
129
|
+
* stands at the top centre itself (the toolbar or the zoom control, when a page put one there). The classes are written
|
|
130
|
+
* out in full, so that the stylesheet of a page that installs the canvas picks both up.
|
|
131
|
+
*/
|
|
132
|
+
export function selectorIndicatorTopClassFor(slots) {
|
|
133
|
+
return slots.some((slot) => slot.anchor === 'TC') ? 'top-16' : 'top-4';
|
|
134
|
+
}
|
|
135
|
+
const TOP_PANEL_CONFLICT_ANCHORS = new Set(['TC', 'TR']);
|
|
136
|
+
/**
|
|
137
|
+
* What the panel keeps clear of, for the slots that are drawn. The selector's indicator, when it is shown, stands across the
|
|
138
|
+
* top centre (it can be as wide as the board), so the panel starts below it as it does below a card of the top edge.
|
|
139
|
+
*/
|
|
140
|
+
export function panelClearanceFor(slots, options = {}) {
|
|
141
|
+
const rightEdgeSlot = slots.find((slot) => slot.anchor === 'CR');
|
|
132
142
|
return {
|
|
133
143
|
// Top-left chrome (e.g. zoom on the creator big page) does not overlap the top-right selection panel.
|
|
134
|
-
belowTopCards: slots.some(
|
|
144
|
+
belowTopCards: options.selectorIndicator === true || slots.some((slot) => TOP_PANEL_CONFLICT_ANCHORS.has(slot.anchor)),
|
|
135
145
|
besideSideCard: rightEdgeSlot ? (rightEdgeSlot.cards.includes('toolbar') ? 'toolbar' : 'zoom') : null
|
|
136
146
|
};
|
|
137
147
|
}
|