@widgetic/canvas 0.5.45 → 0.5.46
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 -1
- 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 -2
- package/dist/canvas/host/CanvasHost.js +1615 -1847
- 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/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/colorModel.js +21 -32
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.js +21 -21
- 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.js +35 -41
- package/dist/canvas/view/CanvasStage.svelte +1 -1
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.js +71 -90
- 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/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.d.ts +9 -2
- package/dist/engine/EngineCore.js +798 -907
- 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.js +84 -96
- 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.js +72 -63
- package/dist/engine/core/snapping.js +65 -117
- package/dist/engine/core/style.js +32 -65
- 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.js +267 -310
- package/dist/engine/input/hoverCursor.js +1 -1
- package/dist/engine/input/keyboard.js +35 -39
- 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.js +28 -30
- package/dist/poster/boardPoster.js +58 -83
- package/dist/poster/paintBoardPoster.js +16 -39
- package/dist/poster/posterPictures.js +27 -43
- package/dist/settings/rememberedTool.d.ts +50 -0
- package/dist/settings/rememberedTool.js +68 -0
- package/dist/settings/workspaceToolSettings.d.ts +8 -0
- package/dist/settings/workspaceToolSettings.js +35 -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 +11 -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 +2 -2
|
@@ -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
|
+
}
|
|
@@ -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
|
}
|
|
@@ -96,6 +96,8 @@ export interface ViewObjectsMoveOptions extends ViewMoveOptions {
|
|
|
96
96
|
*/
|
|
97
97
|
zoom?: number | 'fit' | 'keep';
|
|
98
98
|
}
|
|
99
|
+
/** Why the board is empty when `onCleared` is called: the page cleared it (`'clear-all'`) or the person deleted its last objects (`'deleted'`). */
|
|
100
|
+
export type BoardClearCause = 'clear-all' | 'deleted';
|
|
99
101
|
/** What the engine tells the host shell. Every hook is optional and read at the moment it is needed. */
|
|
100
102
|
export interface EngineHooks {
|
|
101
103
|
/** The person changed the board: it needs saving. */
|
|
@@ -107,8 +109,13 @@ export interface EngineHooks {
|
|
|
107
109
|
* empty new text is dropped after something was typed in it (the save that held the typed letters is out of date).
|
|
108
110
|
*/
|
|
109
111
|
onDraftChange?: () => void;
|
|
110
|
-
/**
|
|
111
|
-
|
|
112
|
+
/**
|
|
113
|
+
* The board was emptied, and why: `'clear-all'` (the page asked for it, `clearAll()`) or `'deleted'` (the person's delete or cut took
|
|
114
|
+
* 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
|
|
115
|
+
* eases the view back to the start (`flyToContent`) does it for the cleared board, and waits for the person's own clear: a page
|
|
116
|
+
* clears the board itself when it opens another one, and then it is the board that opens that sets the view.
|
|
117
|
+
*/
|
|
118
|
+
onCleared?: (cause: BoardClearCause) => void;
|
|
112
119
|
/** The selection changed (a selection, a deselection, after a delete or an undo). */
|
|
113
120
|
onSelectionChange?: (selectedIds: readonly ObjectId[]) => void;
|
|
114
121
|
/** Widget cards are about to be deleted: one question per widget, and one `false` cancels the whole delete. */
|