@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
|
@@ -16,10 +16,9 @@
|
|
|
16
16
|
*/
|
|
17
17
|
/** The shadow root a node lives in, or null when it lives in the page itself (or is not in a tree at all). */
|
|
18
18
|
export function getShadowRootOf(node) {
|
|
19
|
-
|
|
20
|
-
var root = (_a = node === null || node === void 0 ? void 0 : node.getRootNode) === null || _a === void 0 ? void 0 : _a.call(node);
|
|
19
|
+
const root = node?.getRootNode?.();
|
|
21
20
|
// (`instanceof ShadowRoot` would not hold for a root made by another window, an iframe's, say.)
|
|
22
|
-
|
|
21
|
+
const isShadowRoot = !!root && root.nodeType === 11 && 'host' in root;
|
|
23
22
|
return isShadowRoot ? root : null;
|
|
24
23
|
}
|
|
25
24
|
/**
|
|
@@ -32,14 +31,14 @@ export function getShadowRootOf(node) {
|
|
|
32
31
|
* Has to be called while the event is being dispatched (`composedPath()` is empty afterwards).
|
|
33
32
|
*/
|
|
34
33
|
export function eventIsForScope(event, scopeNode) {
|
|
35
|
-
|
|
34
|
+
const shadowRoot = getShadowRootOf(scopeNode);
|
|
36
35
|
if (!shadowRoot)
|
|
37
36
|
return true;
|
|
38
37
|
return event.composedPath().includes(shadowRoot);
|
|
39
38
|
}
|
|
40
39
|
/** The element that has the focus in the tree `scopeNode` lives in: the page's, or the shadow root's own. */
|
|
41
40
|
export function getFocusedElementIn(scopeNode) {
|
|
42
|
-
|
|
41
|
+
const shadowRoot = getShadowRootOf(scopeNode);
|
|
43
42
|
return shadowRoot ? shadowRoot.activeElement : document.activeElement;
|
|
44
43
|
}
|
|
45
44
|
/**
|
|
@@ -47,8 +46,7 @@ export function getFocusedElementIn(scopeNode) {
|
|
|
47
46
|
* event from inside a shadow root; the first element of the path is the one that was pressed.
|
|
48
47
|
*/
|
|
49
48
|
export function getEventOrigin(event) {
|
|
50
|
-
|
|
51
|
-
var first = (_a = event.composedPath()[0]) !== null && _a !== void 0 ? _a : event.target;
|
|
49
|
+
const first = event.composedPath()[0] ?? event.target;
|
|
52
50
|
return first && first.nodeType === 1 ? first : null;
|
|
53
51
|
}
|
|
54
52
|
/**
|
|
@@ -66,8 +64,7 @@ export function eventWentThrough(event, element) {
|
|
|
66
64
|
* page never sees it, and otherwise `document.body`.
|
|
67
65
|
*/
|
|
68
66
|
export function getTransientHostFor(scopeNode) {
|
|
69
|
-
|
|
70
|
-
return (_a = getShadowRootOf(scopeNode)) !== null && _a !== void 0 ? _a : document.body;
|
|
67
|
+
return getShadowRootOf(scopeNode) ?? document.body;
|
|
71
68
|
}
|
|
72
69
|
/**
|
|
73
70
|
* Whether the canvas whose element is `scopeNode` should take the keyboard back after the element that held it went away
|
|
@@ -79,15 +76,14 @@ export function getTransientHostFor(scopeNode) {
|
|
|
79
76
|
* the shortcuts do not mind where the focus is, so there is nothing to do.
|
|
80
77
|
*/
|
|
81
78
|
export function shouldTakeFocusBack(scopeNode) {
|
|
82
|
-
|
|
83
|
-
var shadowRoot = getShadowRootOf(scopeNode);
|
|
79
|
+
const shadowRoot = getShadowRootOf(scopeNode);
|
|
84
80
|
if (!shadowRoot)
|
|
85
81
|
return false;
|
|
86
82
|
if (shadowRoot.activeElement)
|
|
87
83
|
return false;
|
|
88
84
|
// The focus in the tree the shadow root's host is in (the page's, or another shadow root's).
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
85
|
+
const outerTree = shadowRoot.host.getRootNode();
|
|
86
|
+
const focusOutside = outerTree.activeElement;
|
|
87
|
+
const outerBody = outerTree.body ?? null;
|
|
92
88
|
return !focusOutside || focusOutside === shadowRoot.host || focusOutside === outerBody;
|
|
93
89
|
}
|
|
@@ -28,8 +28,8 @@ import type { CanvasMessageKey } from '../../i18n/messages.js';
|
|
|
28
28
|
import type { ObjectClickPayload, StrokeRecognizer } from '../types.js';
|
|
29
29
|
import type { LoadedImageFile } from './browserServices.js';
|
|
30
30
|
import type { HostObject } from './hostObject.js';
|
|
31
|
-
import type { ScreenRect, WidgetScreenRect } from './screenRects.js';
|
|
32
|
-
/** The words of the selector
|
|
31
|
+
import type { ListWidgetScreenRectsOptions, ScreenRect, WidgetScreenRect } from './screenRects.js';
|
|
32
|
+
/** The words of the selector's indicator at the top of the board (the line that says how to use the selector). */
|
|
33
33
|
export interface SelectorGuide {
|
|
34
34
|
click: string;
|
|
35
35
|
parentChild: string;
|
|
@@ -63,10 +63,23 @@ export interface CanvasHostProps {
|
|
|
63
63
|
toolbarPosition: ToolbarPosition;
|
|
64
64
|
wireframeMode: boolean;
|
|
65
65
|
advancedFeatures: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Shows the selector's indicator at the top of the board: the card that says whether the page's element selector is on,
|
|
68
|
+
* with the instructions of `selectorGuide`. The page turns it on while a widget stands on the board and the person has
|
|
69
|
+
* not closed it (see `onDismissElementSelectorHint`). The toolbar is not affected: it stays as `showDrawingTools` says.
|
|
70
|
+
*/
|
|
66
71
|
showElementSelector: boolean;
|
|
67
72
|
showDrawingTools: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* The page's element selector is picking elements of the widget now (the Select tool is chosen and the page has not paused
|
|
75
|
+
* it). The indicator says "Selector on" while it is, and the arrow keys belong to the selector (parent and child) and not
|
|
76
|
+
* to the selection of the board, whether or not the indicator is shown.
|
|
77
|
+
*/
|
|
68
78
|
elementSelectorActive: boolean;
|
|
79
|
+
/** Accepted for the pages that set it. The Select tool turns the selector on and off now, so the canvas never calls it. */
|
|
69
80
|
onToggleElementSelector: (() => void) | null;
|
|
81
|
+
/** The person closed the indicator (its X). The page decides when the hint comes back: it sets `showElementSelector`. */
|
|
82
|
+
onDismissElementSelectorHint: (() => void) | null;
|
|
70
83
|
selectorGuide: SelectorGuide | null;
|
|
71
84
|
showZoomPanel: boolean;
|
|
72
85
|
mediaBtsOnBar: boolean;
|
|
@@ -111,6 +124,13 @@ export interface CanvasHostProps {
|
|
|
111
124
|
workspaceId: string | null;
|
|
112
125
|
userId: string | null;
|
|
113
126
|
workspaceFonts: readonly WorkspaceCanvasFont[];
|
|
127
|
+
/**
|
|
128
|
+
* Where the canvas gets Inter from when the page does not declare it itself: the addresses of its WOFF2 files (URLs, or
|
|
129
|
+
* `data:` URLs for a page with a strict `font-src`), in order of preference. The canvas registers them as the family
|
|
130
|
+
* `Inter`. Empty unless the page passes some: the canvas then asks nobody for a font file and waits for the Inter the
|
|
131
|
+
* page declares (the design system's `fonts.css` does), so it never requests a path of a page that is not ours.
|
|
132
|
+
*/
|
|
133
|
+
interFontSources: readonly string[];
|
|
114
134
|
}
|
|
115
135
|
/** What each prop is until the page sets it (the values the canvas this one replaces had, but for `panZoomPosition`). */
|
|
116
136
|
export declare const DEFAULT_HOST_PROPS: Readonly<CanvasHostProps>;
|
|
@@ -161,6 +181,12 @@ export declare const TOUCH_LONG_PRESS_DELAY_MS = 500;
|
|
|
161
181
|
export declare const TOUCH_LONG_PRESS_SLOP = 8;
|
|
162
182
|
/** How long after the finger that opened the menu lifts its release is still told apart from a choice (see `isMenuHeldByItsFinger`). */
|
|
163
183
|
export declare const TOUCH_MENU_RELEASE_GRACE_MS = 400;
|
|
184
|
+
/**
|
|
185
|
+
* How long the host waits for the pictures it was told to wait for (the ones on screen when a board is opened, or all of them
|
|
186
|
+
* when a capture needs them) before it goes on without them. A page whose store never answers must not keep the board shut for
|
|
187
|
+
* good; the pictures that come later still go on the board.
|
|
188
|
+
*/
|
|
189
|
+
export declare const PICTURE_PATIENCE_MS = 15000;
|
|
164
190
|
/** Says a message of the catalog in the language of the canvas (the host only ever asks for keys the catalog has). */
|
|
165
191
|
export type Translate = CatalogTranslate<CanvasMessageKey>;
|
|
166
192
|
/** A picture's size on the board: its own size, or the biggest one that fits `IMAGE_INSERT_MAX_SIDE`. */
|
|
@@ -241,6 +267,12 @@ export declare class CanvasHost {
|
|
|
241
267
|
* a canvas) opens as an empty board, says so, and nothing is saved until the person changes something.
|
|
242
268
|
*/
|
|
243
269
|
loadCanvas(jsonString: string): Promise<void>;
|
|
270
|
+
/**
|
|
271
|
+
* Resolves when every picture of the board has been asked for and put on it (at once when none is on its way): what draws the
|
|
272
|
+
* whole board, a capture for instance, waits for it. It gives up after `PICTURE_PATIENCE_MS`, so a store that never answers cannot
|
|
273
|
+
* hold anything for good; what was missing is then left out, as a picture the store could not give.
|
|
274
|
+
*/
|
|
275
|
+
whenPicturesLoaded(): Promise<void>;
|
|
244
276
|
/** Empties the board (an undo step) and tells the page. */
|
|
245
277
|
onClearAllObjects(): void;
|
|
246
278
|
setTool(tool: ToolId, options?: {
|
|
@@ -248,7 +280,10 @@ export declare class CanvasHost {
|
|
|
248
280
|
}): void;
|
|
249
281
|
/** A letter of the keyboard chose a tool (or the menu did). */
|
|
250
282
|
chooseShortcutTool(tool: ToolShortcut): void;
|
|
251
|
-
/**
|
|
283
|
+
/**
|
|
284
|
+
* The Select tool. The page hears `widgetic:canvas-tool` for it (the creator's element selector is on while this tool is
|
|
285
|
+
* chosen), and the older `widgetic:canvas-select-tool`, which a page that was written before the selector followed the tool still reads.
|
|
286
|
+
*/
|
|
252
287
|
onSelectSelectTool(): void;
|
|
253
288
|
onSelectDrawTool(): void;
|
|
254
289
|
onSelectEraseTool(): void;
|
|
@@ -329,8 +364,15 @@ export declare class CanvasHost {
|
|
|
329
364
|
selectWidgetShapeById(widgetId: string): boolean;
|
|
330
365
|
getSelectedWidgetShapeId(): string | null;
|
|
331
366
|
getHoveredWidgetShapeId(): string | null;
|
|
332
|
-
/**
|
|
333
|
-
|
|
367
|
+
/**
|
|
368
|
+
* The cards a live widget can be drawn over, with where each is on the page.
|
|
369
|
+
*
|
|
370
|
+
* On a board of many cards (`NEAR_CARDS_MINIMUM` or more) only the cards near the view are listed, the selected one and the one
|
|
371
|
+
* under the pointer wherever they are (see `nearCards.ts`): a page that lays a live widget over each card it is given then runs
|
|
372
|
+
* the widgets that are near, and lets the others go until the view comes back to them. `{ all: true }` lists every card, as
|
|
373
|
+
* the list did before. `getWidgetShapeScreenRect(widgetId)` answers for any card, near or not.
|
|
374
|
+
*/
|
|
375
|
+
listWidgetShapeScreenRects(options?: ListWidgetScreenRectsOptions): WidgetScreenRect[];
|
|
334
376
|
/** Where the card of a widget is on the page, with the board it is on. */
|
|
335
377
|
getWidgetShapeScreenRect(widgetId: string): ScreenRect | null;
|
|
336
378
|
/** Where any object is on the page: the id of an object, of a group, or of a selection a conversion remembered. */
|