@widgetic/canvas 0.5.45 → 0.5.47
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 +3 -2
- package/dist/canvas/DomCanvas.svelte +1 -2
- 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.js +19 -21
- package/dist/canvas/eventScope.js +10 -14
- package/dist/canvas/host/CanvasHost.d.ts +6 -5
- package/dist/canvas/host/CanvasHost.js +1664 -1861
- package/dist/canvas/host/CanvasHostApi.js +4 -19
- package/dist/canvas/host/boardFiles.js +35 -51
- package/dist/canvas/host/browserServices.js +108 -196
- package/dist/canvas/host/conversion.js +82 -170
- package/dist/canvas/host/hostObject.js +7 -7
- package/dist/canvas/host/nearCards.js +18 -21
- package/dist/canvas/host/pageEvents.js +5 -5
- package/dist/canvas/host/pauseCollector.d.ts +18 -0
- package/dist/canvas/host/pauseCollector.js +45 -0
- package/dist/canvas/host/pictureSaves.js +9 -11
- package/dist/canvas/host/screenRects.js +28 -31
- package/dist/canvas/host/storedPictures.js +149 -243
- package/dist/canvas/host/strokeSnap.js +88 -143
- package/dist/canvas/index.d.ts +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.js +4 -4
- package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
- package/dist/canvas/toolbarPosition.js +2 -2
- package/dist/canvas/types.d.ts +7 -1
- package/dist/canvas/ui/CanvasContextMenu.svelte +40 -3
- package/dist/canvas/ui/CanvasHint.svelte +10 -9
- package/dist/canvas/ui/SelectionPanel.svelte +14 -12
- package/dist/canvas/ui/SelectionPanel.svelte.d.ts +0 -2
- package/dist/canvas/ui/ShapesMenu.svelte +6 -4
- package/dist/canvas/ui/ToolButton.svelte +7 -6
- package/dist/canvas/ui/colorModel.js +21 -32
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.d.ts +28 -8
- package/dist/canvas/ui/floatingCard.js +48 -28
- package/dist/canvas/ui/floatingLayer.js +5 -6
- package/dist/canvas/ui/keyHints.js +9 -11
- package/dist/canvas/ui/popoverSide.js +2 -3
- package/dist/canvas/ui/selectionTraits.d.ts +8 -4
- package/dist/canvas/ui/selectionTraits.js +44 -58
- package/dist/canvas/view/CanvasStage.svelte +1 -1
- package/dist/canvas/view/SelectionOverlay.svelte +2 -2
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.d.ts +1 -1
- package/dist/canvas/view/geometry.js +72 -91
- package/dist/canvas/view/liftedScene.js +24 -36
- package/dist/canvas/view/mountedScene.js +76 -79
- package/dist/components/CanvasBoardPlaceholder.svelte +68 -10
- package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +10 -2
- package/dist/components/CanvasToolbarPlaceholder.svelte +25 -11
- package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +6 -0
- package/dist/components/boardLoaderDelay.d.ts +39 -0
- package/dist/components/boardLoaderDelay.js +71 -0
- package/dist/components/input-controls/ColorIC.svelte +1 -1
- package/dist/components/input-controls/FontSelectorIC.svelte +1 -1
- package/dist/components/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.d.ts +42 -10
- package/dist/engine/EngineCore.js +843 -916
- package/dist/engine/codec/canvasDocument.js +192 -155
- package/dist/engine/codec/hostReadableKeys.js +1 -1
- package/dist/engine/core/arrange.js +26 -38
- package/dist/engine/core/arrow.js +79 -92
- package/dist/engine/core/arrowBinding.js +98 -116
- package/dist/engine/core/arrowBindingRecords.js +23 -38
- package/dist/engine/core/brush.d.ts +24 -0
- package/dist/engine/core/brush.js +223 -103
- package/dist/engine/core/cameraMove.js +39 -51
- package/dist/engine/core/defaults.js +92 -51
- package/dist/engine/core/freehand.js +147 -163
- package/dist/engine/core/geometry.js +47 -54
- package/dist/engine/core/history.js +38 -55
- 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.js +160 -224
- package/dist/engine/core/scribble.js +59 -84
- package/dist/engine/core/shapePaths.js +12 -15
- package/dist/engine/core/shapeTools.d.ts +23 -18
- package/dist/engine/core/shapeTools.js +104 -67
- package/dist/engine/core/snapping.js +65 -117
- package/dist/engine/core/style.d.ts +18 -2
- package/dist/engine/core/style.js +79 -80
- package/dist/engine/core/styleMemory.d.ts +88 -0
- package/dist/engine/core/styleMemory.js +189 -0
- package/dist/engine/core/transform.js +84 -95
- package/dist/engine/core/types.js +4 -4
- package/dist/engine/core/viewport.js +23 -36
- package/dist/engine/input/PointerController.js +513 -526
- package/dist/engine/input/arrowHandles.js +12 -12
- package/dist/engine/input/gestures.d.ts +8 -3
- package/dist/engine/input/gestures.js +378 -346
- package/dist/engine/input/hoverCursor.js +1 -1
- package/dist/engine/input/keyboard.js +42 -41
- 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.js +6 -17
- 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.js +30 -83
- package/dist/fonts/workspaceFonts.js +33 -92
- package/dist/i18n/labels.js +4 -4
- package/dist/i18n/language.js +4 -4
- package/dist/i18n/messages.js +1 -1
- package/dist/i18n/shortcuts.js +14 -14
- package/dist/index.d.ts +1 -1
- package/dist/poster/boardPlacement.d.ts +4 -1
- package/dist/poster/boardPlacement.js +34 -33
- package/dist/poster/boardPoster.js +58 -83
- package/dist/poster/paintBoardPoster.js +16 -39
- package/dist/poster/posterPictures.js +27 -43
- package/dist/settings/rememberedStyles.d.ts +22 -0
- package/dist/settings/rememberedStyles.js +47 -0
- package/dist/settings/rememberedTool.d.ts +50 -0
- package/dist/settings/rememberedTool.js +68 -0
- package/dist/settings/workspaceToolSettings.d.ts +25 -0
- package/dist/settings/workspaceToolSettings.js +38 -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 +137 -169
- package/dist/tools/hostAdapter.js +10 -13
- package/dist/tools/sceneSummary.js +43 -57
- package/dist/tools/sketchIntent.js +13 -21
- package/dist/tools/styleArguments.js +19 -21
- package/dist/tools/types.js +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When the loader of an empty board may first be seen.
|
|
3
|
+
*
|
|
4
|
+
* A board that opens fast (its code and its saved text are already in the browser) should show no loader at all: a spinner
|
|
5
|
+
* that flashes for a tenth of a second reads as a stutter, not as progress. So the loader of a placeholder waits for
|
|
6
|
+
* `BOARD_LOADER_DELAY_MS`, counted from the moment the opening began, and a board that is there before that never shows one.
|
|
7
|
+
*
|
|
8
|
+
* Opening a board draws up to three placeholders, one after the other: the page's own (while the creator downloads), the
|
|
9
|
+
* creator's (while the canvas code downloads) and the canvas's (while its saved text loads). If each counted from its own start,
|
|
10
|
+
* the loader would go away and come back again at every hand-over, and the wait would be three times as long. They share one
|
|
11
|
+
* count instead: the time since the first of them was drawn. The count is kept for `BOARD_LOADER_HANDOVER_MS` after the last one
|
|
12
|
+
* is gone, so that the next one, drawn in the same moment, continues it; after that the next placeholder starts a new opening.
|
|
13
|
+
*
|
|
14
|
+
* The count lives on `globalThis` under a registered symbol, not in this module: the page's placeholder and the creator's can come
|
|
15
|
+
* from two copies of this file (one for each bundle that has it), and two copies would each start their own count.
|
|
16
|
+
*/
|
|
17
|
+
/** How long an opening may take before its loader is first seen, in milliseconds. */
|
|
18
|
+
export const BOARD_LOADER_DELAY_MS = 400;
|
|
19
|
+
/** How long after its last placeholder is gone an opening is still the same one, in milliseconds. */
|
|
20
|
+
export const BOARD_LOADER_HANDOVER_MS = 300;
|
|
21
|
+
const OPENING_KEY = Symbol.for('widgetic.canvas.boardLoaderOpening');
|
|
22
|
+
/** The clock of the page, in milliseconds, that never goes back. */
|
|
23
|
+
function pageClock() {
|
|
24
|
+
return typeof performance !== 'undefined' && typeof performance.now === 'function' ? performance.now() : Date.now();
|
|
25
|
+
}
|
|
26
|
+
/** The one record of this page, made the first time it is asked for. */
|
|
27
|
+
function openingOfPage() {
|
|
28
|
+
const shared = globalThis;
|
|
29
|
+
const existing = shared[OPENING_KEY];
|
|
30
|
+
if (existing)
|
|
31
|
+
return existing;
|
|
32
|
+
const fresh = { openedAt: Number.NEGATIVE_INFINITY, claims: 0, lastReleasedAt: Number.NEGATIVE_INFINITY };
|
|
33
|
+
shared[OPENING_KEY] = fresh;
|
|
34
|
+
return fresh;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A placeholder asks when its loader may be seen, and tells when it is gone. `now` is the clock; tests pass their own.
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* const claim = claimBoardLoader();
|
|
41
|
+
* // show the loader after claim.delayMs
|
|
42
|
+
* claim.release(); // when the placeholder goes away
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export function claimBoardLoader(now = pageClock) {
|
|
46
|
+
const opening = openingOfPage();
|
|
47
|
+
const claimedAt = now();
|
|
48
|
+
// Nothing is drawn and the last placeholder went a while ago: this is a new opening
|
|
49
|
+
if (opening.claims === 0 && claimedAt - opening.lastReleasedAt > BOARD_LOADER_HANDOVER_MS) {
|
|
50
|
+
opening.openedAt = claimedAt;
|
|
51
|
+
}
|
|
52
|
+
opening.claims += 1;
|
|
53
|
+
const delayMs = Math.max(0, BOARD_LOADER_DELAY_MS - (claimedAt - opening.openedAt));
|
|
54
|
+
let released = false;
|
|
55
|
+
return {
|
|
56
|
+
delayMs,
|
|
57
|
+
release: () => {
|
|
58
|
+
if (released)
|
|
59
|
+
return;
|
|
60
|
+
released = true;
|
|
61
|
+
opening.claims = Math.max(0, opening.claims - 1);
|
|
62
|
+
if (opening.claims === 0)
|
|
63
|
+
opening.lastReleasedAt = now();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** Forgets the opening of this page. For tests: a page never needs it. */
|
|
68
|
+
export function resetBoardLoaderOpening() {
|
|
69
|
+
const shared = globalThis;
|
|
70
|
+
delete shared[OPENING_KEY];
|
|
71
|
+
}
|
|
@@ -228,7 +228,7 @@
|
|
|
228
228
|
|
|
229
229
|
<div class="presets-container overflow-x-hidden p-2 border border-gray-300 rounded-md {presets ? 'fixed-palette' : ''}"
|
|
230
230
|
style={presets ? `grid-template-columns: repeat(${Math.min(presets.length, 8)}, 1fr); max-height: none;` : ''}>
|
|
231
|
-
{#each allPresets as color}
|
|
231
|
+
{#each allPresets as color, presetIndex (presetIndex)}
|
|
232
232
|
<div class="preset-wrapper">
|
|
233
233
|
<button
|
|
234
234
|
class="preset-btn"
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* is written into the page's storage and a browser that several visitors share does not pass one visitor's choices on
|
|
7
7
|
* to the next. The host does this once, before the canvas is shown.
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
let installedStorage = null;
|
|
10
10
|
/** Installs the store the canvas keeps the visitor's choices in; `null` goes back to the browser's `localStorage`. */
|
|
11
11
|
export function setCanvasPreferenceStorage(storage) {
|
|
12
12
|
installedStorage = storage;
|
|
@@ -18,7 +18,7 @@ export function getCanvasPreferenceStorage() {
|
|
|
18
18
|
try {
|
|
19
19
|
return typeof localStorage === 'undefined' ? null : localStorage;
|
|
20
20
|
}
|
|
21
|
-
catch
|
|
21
|
+
catch {
|
|
22
22
|
// Reading `localStorage` itself throws where the browser blocks storage for the page.
|
|
23
23
|
return null;
|
|
24
24
|
}
|
|
@@ -16,8 +16,9 @@ import type { AlignMode, DistributeAxis } from './core/arrange.js';
|
|
|
16
16
|
import type { ArrowHandleId } from './core/arrow.js';
|
|
17
17
|
import type { ReorderMode, Scene } from './core/scene.js';
|
|
18
18
|
import type { StylePatch } from './core/style.js';
|
|
19
|
+
import type { PatchedStyleKind, RememberedStyles, StyleMemoryKind } from './core/styleMemory.js';
|
|
19
20
|
import type { SelectionFrame } from './core/transform.js';
|
|
20
|
-
import type { ObjectId, Point, Rect,
|
|
21
|
+
import type { ObjectId, Point, Rect, SceneObject, ShapeObject, Size, Viewport, WidgetObject } from './core/types.js';
|
|
21
22
|
import type { EngineOverlay, EngineState, PendingWidgetState, PenStyle, ToolId, WidgetRuntime } from './state.js';
|
|
22
23
|
import type { MeasureText } from './text/layoutText.js';
|
|
23
24
|
/** How many undo steps the board keeps (as the canvas it replaces did). */
|
|
@@ -96,6 +97,8 @@ export interface ViewObjectsMoveOptions extends ViewMoveOptions {
|
|
|
96
97
|
*/
|
|
97
98
|
zoom?: number | 'fit' | 'keep';
|
|
98
99
|
}
|
|
100
|
+
/** Why the board is empty when `onCleared` is called: the page cleared it (`'clear-all'`) or the person deleted its last objects (`'deleted'`). */
|
|
101
|
+
export type BoardClearCause = 'clear-all' | 'deleted';
|
|
99
102
|
/** What the engine tells the host shell. Every hook is optional and read at the moment it is needed. */
|
|
100
103
|
export interface EngineHooks {
|
|
101
104
|
/** The person changed the board: it needs saving. */
|
|
@@ -107,10 +110,22 @@ export interface EngineHooks {
|
|
|
107
110
|
* empty new text is dropped after something was typed in it (the save that held the typed letters is out of date).
|
|
108
111
|
*/
|
|
109
112
|
onDraftChange?: () => void;
|
|
110
|
-
/**
|
|
111
|
-
|
|
113
|
+
/**
|
|
114
|
+
* The board was emptied, and why: `'clear-all'` (the page asked for it, `clearAll()`) or `'deleted'` (the person's delete or cut took
|
|
115
|
+
* the last object off the board). The eraser and an undo that end on an empty board are not told: they are not a clear. A page that
|
|
116
|
+
* eases the view back to the start (`flyToContent`) does it for the cleared board, and waits for the person's own clear: a page
|
|
117
|
+
* clears the board itself when it opens another one, and then it is the board that opens that sets the view.
|
|
118
|
+
*/
|
|
119
|
+
onCleared?: (cause: BoardClearCause) => void;
|
|
112
120
|
/** The selection changed (a selection, a deselection, after a delete or an undo). */
|
|
113
121
|
onSelectionChange?: (selectedIds: readonly ObjectId[]) => void;
|
|
122
|
+
/**
|
|
123
|
+
* The person restyled something and so changed what the next element of a kind starts with: the kinds that came out different (see
|
|
124
|
+
* `EngineCore.rememberedStyles`, and `EngineState.penStyle` for `'pen'`). The host keeps them for the workspace. Called for every
|
|
125
|
+
* change of the memory, a drag of a slider included, and not when an edit says what the memory holds already, nor when the memory
|
|
126
|
+
* is loaded (`setRememberedStyles`).
|
|
127
|
+
*/
|
|
128
|
+
onStyleRemembered?: (kinds: readonly StyleMemoryKind[]) => void;
|
|
114
129
|
/** Widget cards are about to be deleted: one question per widget, and one `false` cancels the whole delete. */
|
|
115
130
|
confirmWidgetDeletion?: ((widgetId: string) => Promise<boolean> | boolean) | null;
|
|
116
131
|
/** Whether widget cards may be duplicated/pasted on the board. Defaults to true. */
|
|
@@ -316,19 +331,29 @@ export declare class EngineCore {
|
|
|
316
331
|
notifyFontsChanged(): void;
|
|
317
332
|
/** Remembers the font family for the next text object the person places. */
|
|
318
333
|
setPreferredTextFontFamily(fontFamily: string): void;
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
334
|
+
/**
|
|
335
|
+
* What the person last chose for each kind of element: the next shape, line icon, arrow or text starts with it, laid over the look it
|
|
336
|
+
* would start with (see `core/styleMemory.ts`). It is what the panel was used for, in this session and, when the host loaded it
|
|
337
|
+
* (`setRememberedStyles`), in the sessions before. The pen of the Draw tool is `state.penStyle`.
|
|
338
|
+
*/
|
|
339
|
+
get rememberedStyles(): RememberedStyles;
|
|
340
|
+
/**
|
|
341
|
+
* Loads what was kept for a workspace (the host does, when the board is opened in one), instead of what the engine has: a kind that
|
|
342
|
+
* the storage does not hold goes back to nothing remembered. What the storage holds is checked key by key (a value that is not one of
|
|
343
|
+
* the key is dropped, a number is brought into its range), so a damaged or an older entry cannot give a shape a look it cannot have.
|
|
344
|
+
* Not an edit of the person: nobody is told (`onStyleRemembered`) and nothing is saved because of it.
|
|
345
|
+
*/
|
|
346
|
+
setRememberedStyles(stored: {
|
|
347
|
+
readonly [kind in PatchedStyleKind]?: unknown;
|
|
348
|
+
} | null): void;
|
|
323
349
|
/**
|
|
324
350
|
* Changes how the Draw tool draws: the lines drawn from now on take the colour, the width and the opacity that are asked for. A key
|
|
325
|
-
* that is left out stays as it was; a value that cannot be a line's (a width under 1 or above
|
|
351
|
+
* that is left out stays as it was; a value that cannot be a line's (a width under 1 or above 50, an opacity out of range, a
|
|
326
352
|
* colour that is not a word, a number that is not a number) is brought to what a line can be, or ignored when it is not a value
|
|
327
353
|
* at all. Nothing on the board changes (that is `setStyle`, for the selection), and nothing is added to the history. Returns
|
|
328
354
|
* whether the pen came out different.
|
|
329
355
|
*/
|
|
330
356
|
setPenStyle(patch: Partial<PenStyle>): boolean;
|
|
331
|
-
workspacePaintForNewShape(wireframe: boolean): Partial<RectObject>;
|
|
332
357
|
/**
|
|
333
358
|
* Makes a text object, puts it on the board and starts editing it. A click makes a label whose width follows its
|
|
334
359
|
* text; a width makes a box whose lines wrap. Nothing is recorded until the editing ends with text in it.
|
|
@@ -356,7 +381,14 @@ export declare class EngineCore {
|
|
|
356
381
|
endTextEdit(options?: {
|
|
357
382
|
keepPlaceholderTool?: boolean;
|
|
358
383
|
}): ObjectId | null;
|
|
359
|
-
/**
|
|
384
|
+
/**
|
|
385
|
+
* Changes how the selection looks. `commit: false` is for a slider that is still being dragged: call `commit()` when it ends.
|
|
386
|
+
*
|
|
387
|
+
* What the person chose is also what the next element of each kind in the selection starts with, until they choose again (a
|
|
388
|
+
* rectangle's fill, stroke and width are the next rectangle's, the next ellipse's, the next star's; an arrow's colour is the next
|
|
389
|
+
* arrow's; a text's size is the next text's; the colour of a line drawn by hand is the pen's). It is kept for every change, a drag
|
|
390
|
+
* of a slider included and a value the selection has already, and the host is told (`onStyleRemembered`). See `core/styleMemory.ts`.
|
|
391
|
+
*/
|
|
360
392
|
setStyle(patch: StylePatch, options?: {
|
|
361
393
|
commit?: boolean;
|
|
362
394
|
}): boolean;
|