@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
|
@@ -41,7 +41,7 @@ export function hostCustomTypeOf(object) {
|
|
|
41
41
|
return null;
|
|
42
42
|
}
|
|
43
43
|
function viewOf(object, index, scene) {
|
|
44
|
-
|
|
44
|
+
const view = {
|
|
45
45
|
id: object.id,
|
|
46
46
|
_objectId: object.id,
|
|
47
47
|
type: hostTypeOf(object),
|
|
@@ -54,7 +54,7 @@ function viewOf(object, index, scene) {
|
|
|
54
54
|
view._isPrimaryWidget = object.isPrimary;
|
|
55
55
|
}
|
|
56
56
|
if (object.type === 'group') {
|
|
57
|
-
view.objects = scene.filter(
|
|
57
|
+
view.objects = scene.filter((member) => member.parentId === object.id).map((member) => viewOf(member, index, scene));
|
|
58
58
|
}
|
|
59
59
|
return view;
|
|
60
60
|
}
|
|
@@ -62,7 +62,7 @@ function viewOf(object, index, scene) {
|
|
|
62
62
|
export function hostObjectById(engine, id) {
|
|
63
63
|
if (!id)
|
|
64
64
|
return null;
|
|
65
|
-
|
|
65
|
+
const object = engine.getObject(id);
|
|
66
66
|
if (!object)
|
|
67
67
|
return null;
|
|
68
68
|
return viewOf(object, engine.sceneIndex(), engine.state.scene);
|
|
@@ -72,11 +72,11 @@ export function hostObjectById(engine, id) {
|
|
|
72
72
|
* Null when nothing is selected.
|
|
73
73
|
*/
|
|
74
74
|
export function selectedHostObject(engine) {
|
|
75
|
-
|
|
75
|
+
const selected = engine.selectedObjects();
|
|
76
76
|
if (selected.length === 0)
|
|
77
77
|
return null;
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
const index = engine.sceneIndex();
|
|
79
|
+
const scene = engine.state.scene;
|
|
80
80
|
if (selected.length === 1)
|
|
81
81
|
return viewOf(selected[0], index, scene);
|
|
82
82
|
return {
|
|
@@ -84,7 +84,7 @@ export function selectedHostObject(engine) {
|
|
|
84
84
|
_objectId: '',
|
|
85
85
|
type: 'activeSelection',
|
|
86
86
|
_customType: null,
|
|
87
|
-
objects: selected.map(
|
|
87
|
+
objects: selected.map((object) => viewOf(object, index, scene))
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
/** The shapes behind a list of units (a group counts through its members), for the conversion payload. */
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Rect, Size, Viewport } from '../../engine/core/types.js';
|
|
2
|
+
/** A board with fewer cards than this lists every one of them. */
|
|
3
|
+
export declare const NEAR_CARDS_MINIMUM = 8;
|
|
4
|
+
/** How far past the view a card is listed, as a share of the view's width and height, on every side. */
|
|
5
|
+
export declare const NEAR_CARD_MARGIN_RATIO = 1;
|
|
6
|
+
/** How far past the view a card that is listed already stays listed, in the same measure. More than `NEAR_CARD_MARGIN_RATIO`. */
|
|
7
|
+
export declare const KEEP_CARD_MARGIN_RATIO = 2;
|
|
8
|
+
/** What the host knows of a card that could be listed. */
|
|
9
|
+
export interface CardCandidate {
|
|
10
|
+
widgetId: string;
|
|
11
|
+
/** Where the card is in the world: its box, turned (what decides whether it is near the view). */
|
|
12
|
+
bounds: Rect;
|
|
13
|
+
/** The card is listed wherever it is (it is selected, or the pointer is over it). */
|
|
14
|
+
always: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface NearCardsOptions {
|
|
17
|
+
/** Boards with fewer cards than this list every card (default `NEAR_CARDS_MINIMUM`). */
|
|
18
|
+
minimumCards?: number;
|
|
19
|
+
/** Default `NEAR_CARD_MARGIN_RATIO`. */
|
|
20
|
+
nearMarginRatio?: number;
|
|
21
|
+
/** Default `KEEP_CARD_MARGIN_RATIO`; never less than the near margin. */
|
|
22
|
+
keepMarginRatio?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface NearCards {
|
|
25
|
+
/**
|
|
26
|
+
* The widget ids to list, out of the cards that could be listed. Called at every frame in which the board changed, so it makes
|
|
27
|
+
* nothing but a set of ids. Remembers what it answered: that is what lets a card at the edge keep its place (see above).
|
|
28
|
+
*/
|
|
29
|
+
choose(cards: readonly CardCandidate[], viewport: Viewport, viewSize: Size): Set<string>;
|
|
30
|
+
/** Forgets what was listed (the board was replaced). */
|
|
31
|
+
reset(): void;
|
|
32
|
+
}
|
|
33
|
+
export declare function createNearCards(options?: NearCardsOptions): NearCards;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which cards of the board `listWidgetShapeScreenRects()` gives to the page: the ones near what the person sees.
|
|
3
|
+
*
|
|
4
|
+
* The page lays a live widget (an iframe, a whole running widget) over every card it is given, and moves it again at every frame in
|
|
5
|
+
* which the board changed. The list used to hold every card of the board, so a board of a few dozen cards had a few dozen widgets
|
|
6
|
+
* running, nearly all of them far outside the screen, and each change of the view made the page work for all of them. Now a card is
|
|
7
|
+
* listed only while it is close to the view; the page lays a live widget over it when it gets near and lets it go when it is far,
|
|
8
|
+
* exactly as the board does for its own elements (`mountedScene.ts`).
|
|
9
|
+
*
|
|
10
|
+
* What it decides, in short:
|
|
11
|
+
*
|
|
12
|
+
* - A board with fewer cards than `NEAR_CARDS_MINIMUM` lists every one of them, as it always did: a few widgets are what the
|
|
13
|
+
* person asked for, and what a card is made of (a widget that is running, what was typed in it) is not thrown away for nothing.
|
|
14
|
+
* - Above that, a card is listed when its box touches the *near area*: the view, with a whole view of room on every side. That is
|
|
15
|
+
* a wide margin on purpose: a live widget takes time to load, so it should be ready before the card is on the screen.
|
|
16
|
+
* - A card that is listed already stays listed until it is out of the *keep area*: the view with two whole views of room on
|
|
17
|
+
* every side. A pan that goes out and comes back (the hand of a person does that all the time) must not have the page build the
|
|
18
|
+
* same widget twice, and a card at the edge of the near area must not come and go with every pixel of the pan.
|
|
19
|
+
* - The card that is selected, and the one the pointer is over, are always listed wherever they are: the person is working with
|
|
20
|
+
* them (the page draws its frame and its drag bar for them).
|
|
21
|
+
* - A board that has no size yet (nothing is known to be far) lists every card.
|
|
22
|
+
*
|
|
23
|
+
* Plain TypeScript with no Svelte file in it, so that Node can test it.
|
|
24
|
+
*/
|
|
25
|
+
import { rectsIntersect } from '../../engine/core/geometry.js';
|
|
26
|
+
import { visibleWorldRect } from '../../engine/core/viewport.js';
|
|
27
|
+
/** A board with fewer cards than this lists every one of them. */
|
|
28
|
+
export const NEAR_CARDS_MINIMUM = 8;
|
|
29
|
+
/** How far past the view a card is listed, as a share of the view's width and height, on every side. */
|
|
30
|
+
export const NEAR_CARD_MARGIN_RATIO = 1;
|
|
31
|
+
/** How far past the view a card that is listed already stays listed, in the same measure. More than `NEAR_CARD_MARGIN_RATIO`. */
|
|
32
|
+
export const KEEP_CARD_MARGIN_RATIO = 2;
|
|
33
|
+
/** A view with `ratio` of its width and height added on every side. */
|
|
34
|
+
function viewWithMargin(view, ratio) {
|
|
35
|
+
const marginX = view.width * ratio;
|
|
36
|
+
const marginY = view.height * ratio;
|
|
37
|
+
return { x: view.x - marginX, y: view.y - marginY, width: view.width + marginX * 2, height: view.height + marginY * 2 };
|
|
38
|
+
}
|
|
39
|
+
/** A rectangle made of finite numbers, with some size: anything else says the board has no size (or no view) yet. */
|
|
40
|
+
function isUsableView(view) {
|
|
41
|
+
return Number.isFinite(view.x) && Number.isFinite(view.y) && Number.isFinite(view.width) && Number.isFinite(view.height) && view.width > 0 && view.height > 0;
|
|
42
|
+
}
|
|
43
|
+
export function createNearCards(options = {}) {
|
|
44
|
+
const minimumCards = options.minimumCards ?? NEAR_CARDS_MINIMUM;
|
|
45
|
+
const nearMarginRatio = options.nearMarginRatio ?? NEAR_CARD_MARGIN_RATIO;
|
|
46
|
+
const keepMarginRatio = Math.max(nearMarginRatio, options.keepMarginRatio ?? KEEP_CARD_MARGIN_RATIO);
|
|
47
|
+
/** The ids that were listed the last time: the cards that keep their place while they are inside the keep area. */
|
|
48
|
+
let listed = new Set();
|
|
49
|
+
function listEveryCard(cards) {
|
|
50
|
+
listed = new Set(cards.map((card) => card.widgetId));
|
|
51
|
+
return new Set(listed);
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
choose(cards, viewport, viewSize) {
|
|
55
|
+
if (cards.length < minimumCards)
|
|
56
|
+
return listEveryCard(cards);
|
|
57
|
+
if (!Number.isFinite(viewport.zoom) || viewport.zoom <= 0)
|
|
58
|
+
return listEveryCard(cards);
|
|
59
|
+
const view = visibleWorldRect(viewport, viewSize);
|
|
60
|
+
if (!isUsableView(view))
|
|
61
|
+
return listEveryCard(cards);
|
|
62
|
+
const nearArea = viewWithMargin(view, nearMarginRatio);
|
|
63
|
+
const keepArea = viewWithMargin(view, keepMarginRatio);
|
|
64
|
+
const next = new Set();
|
|
65
|
+
for (const card of cards) {
|
|
66
|
+
if (card.always || rectsIntersect(nearArea, card.bounds) || (listed.has(card.widgetId) && rectsIntersect(keepArea, card.bounds))) {
|
|
67
|
+
next.add(card.widgetId);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
listed = next;
|
|
71
|
+
return new Set(next);
|
|
72
|
+
},
|
|
73
|
+
reset() {
|
|
74
|
+
if (listed.size > 0)
|
|
75
|
+
listed = new Set();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
2
|
+
* The events the canvas sends to its page, on `window`.
|
|
3
3
|
*
|
|
4
|
-
* The widget creator listens to
|
|
4
|
+
* The widget creator listens to them, so their names and what they carry are part of the host contract:
|
|
5
5
|
*
|
|
6
|
-
* - `widgetic:canvas-select-tool` (no detail): the Select tool was chosen. The creator
|
|
7
|
-
* widget when it
|
|
6
|
+
* - `widgetic:canvas-select-tool` (no detail): the Select tool was chosen. The creator used to close the element selector of
|
|
7
|
+
* every widget when it heard it; it now listens to `widgetic:canvas-tool` instead (the Select tool is what turns the
|
|
8
|
+
* selector on), and this one is kept for the pages that still read it.
|
|
9
|
+
* - `widgetic:canvas-tool` (`{ tool }`): the tool changed, and once when the board opens, so a page that starts listening
|
|
10
|
+
* before the board is up always hears the first tool. `tool` is the engine's own name for it (`select`, `draw`, `erase`,
|
|
11
|
+
* `text`, `arrow`, `pan`, `rect`, ...). The creator turns its element selector on while it is `select`.
|
|
8
12
|
* - `widgetic:widget-shape-pointer-block` (`{ widgetId, active }`): a widget card is being stretched (`active: true`, with
|
|
9
13
|
* the widget's id) or the stretch ended (`active: false`, `widgetId: null`). The creator lets the pointer through the live
|
|
10
14
|
* widget laid over the card while the stretch lasts, so the iframe does not take the gesture.
|
|
@@ -12,13 +16,21 @@
|
|
|
12
16
|
* Kept free of Svelte so that Node can test it. A page rendered on the server has no `window` and gets nothing.
|
|
13
17
|
*/
|
|
14
18
|
export declare const CANVAS_SELECT_TOOL_EVENT = "widgetic:canvas-select-tool";
|
|
19
|
+
export declare const CANVAS_TOOL_EVENT = "widgetic:canvas-tool";
|
|
15
20
|
export declare const WIDGET_POINTER_BLOCK_EVENT = "widgetic:widget-shape-pointer-block";
|
|
16
21
|
export interface WidgetPointerBlockDetail {
|
|
17
22
|
/** The widget whose card is being stretched, or null when the stretch ended. */
|
|
18
23
|
widgetId: string | null;
|
|
19
24
|
active: boolean;
|
|
20
25
|
}
|
|
26
|
+
/** What `widgetic:canvas-tool` carries. */
|
|
27
|
+
export interface CanvasToolDetail {
|
|
28
|
+
/** The tool that is chosen now: the engine's name for it (`select`, `draw`, `erase`, `text`, `arrow`, `pan`, ...). */
|
|
29
|
+
tool: string;
|
|
30
|
+
}
|
|
21
31
|
/** The Select tool was chosen. */
|
|
22
32
|
export declare function announceSelectTool(): void;
|
|
33
|
+
/** The tool changed (or the board opened with this tool). */
|
|
34
|
+
export declare function announceCanvasTool(tool: string): void;
|
|
23
35
|
/** A widget card is being stretched, or no longer is. */
|
|
24
36
|
export declare function announceWidgetPointerBlock(detail: WidgetPointerBlockDetail): void;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
2
|
+
* The events the canvas sends to its page, on `window`.
|
|
3
3
|
*
|
|
4
|
-
* The widget creator listens to
|
|
4
|
+
* The widget creator listens to them, so their names and what they carry are part of the host contract:
|
|
5
5
|
*
|
|
6
|
-
* - `widgetic:canvas-select-tool` (no detail): the Select tool was chosen. The creator
|
|
7
|
-
* widget when it
|
|
6
|
+
* - `widgetic:canvas-select-tool` (no detail): the Select tool was chosen. The creator used to close the element selector of
|
|
7
|
+
* every widget when it heard it; it now listens to `widgetic:canvas-tool` instead (the Select tool is what turns the
|
|
8
|
+
* selector on), and this one is kept for the pages that still read it.
|
|
9
|
+
* - `widgetic:canvas-tool` (`{ tool }`): the tool changed, and once when the board opens, so a page that starts listening
|
|
10
|
+
* before the board is up always hears the first tool. `tool` is the engine's own name for it (`select`, `draw`, `erase`,
|
|
11
|
+
* `text`, `arrow`, `pan`, `rect`, ...). The creator turns its element selector on while it is `select`.
|
|
8
12
|
* - `widgetic:widget-shape-pointer-block` (`{ widgetId, active }`): a widget card is being stretched (`active: true`, with
|
|
9
13
|
* the widget's id) or the stretch ended (`active: false`, `widgetId: null`). The creator lets the pointer through the live
|
|
10
14
|
* widget laid over the card while the stretch lasts, so the iframe does not take the gesture.
|
|
@@ -12,23 +16,28 @@
|
|
|
12
16
|
* Kept free of Svelte so that Node can test it. A page rendered on the server has no `window` and gets nothing.
|
|
13
17
|
*/
|
|
14
18
|
import { canvasWarn } from '../canvasLogger.js';
|
|
15
|
-
export
|
|
16
|
-
export
|
|
19
|
+
export const CANVAS_SELECT_TOOL_EVENT = 'widgetic:canvas-select-tool';
|
|
20
|
+
export const CANVAS_TOOL_EVENT = 'widgetic:canvas-tool';
|
|
21
|
+
export const WIDGET_POINTER_BLOCK_EVENT = 'widgetic:widget-shape-pointer-block';
|
|
17
22
|
function dispatchOnWindow(name, detail) {
|
|
18
23
|
if (typeof window === 'undefined' || typeof CustomEvent === 'undefined')
|
|
19
24
|
return;
|
|
20
25
|
try {
|
|
21
|
-
window.dispatchEvent(detail === undefined ? new CustomEvent(name) : new CustomEvent(name, { detail
|
|
26
|
+
window.dispatchEvent(detail === undefined ? new CustomEvent(name) : new CustomEvent(name, { detail }));
|
|
22
27
|
}
|
|
23
28
|
catch (error) {
|
|
24
29
|
// A page that cannot take the event keeps its canvas.
|
|
25
|
-
canvasWarn(
|
|
30
|
+
canvasWarn(`Canvas: could not send ${name}`, error);
|
|
26
31
|
}
|
|
27
32
|
}
|
|
28
33
|
/** The Select tool was chosen. */
|
|
29
34
|
export function announceSelectTool() {
|
|
30
35
|
dispatchOnWindow(CANVAS_SELECT_TOOL_EVENT);
|
|
31
36
|
}
|
|
37
|
+
/** The tool changed (or the board opened with this tool). */
|
|
38
|
+
export function announceCanvasTool(tool) {
|
|
39
|
+
dispatchOnWindow(CANVAS_TOOL_EVENT, { tool: String(tool) });
|
|
40
|
+
}
|
|
32
41
|
/** A widget card is being stretched, or no longer is. */
|
|
33
42
|
export function announceWidgetPointerBlock(detail) {
|
|
34
43
|
dispatchOnWindow(WIDGET_POINTER_BLOCK_EVENT, { widgetId: detail.widgetId === null ? null : String(detail.widgetId), active: detail.active });
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the board has already given to the page's picture store, so that a save gives the store only what it has not got yet.
|
|
3
|
+
*
|
|
4
|
+
* Saving writes the whole board, and the writer hands the store the bytes of every picture that is still held inline, on every
|
|
5
|
+
* save. The bytes stay in the board in memory (only the saved text leaves them out), so a board with a few photos on it wrote
|
|
6
|
+
* the same megabytes again after every small change: a page whose store keeps them on disk did a structured clone of each of
|
|
7
|
+
* them, on the main thread, for bytes that had not changed.
|
|
8
|
+
*
|
|
9
|
+
* The store is given a picture once for a set of bytes. A save that comes with the same bytes again is not passed on.
|
|
10
|
+
*
|
|
11
|
+
* - Only what the store accepted is remembered. A `save` that throws is not: the writer keeps those bytes in the text, and the
|
|
12
|
+
* next save offers them again.
|
|
13
|
+
* - The first save that is complete forgets whatever it did not see, so a picture that left the board is offered again if an
|
|
14
|
+
* undo brings it back (the store may have dropped it meanwhile).
|
|
15
|
+
* - A store that was replaced by another has none of it: everything is offered again.
|
|
16
|
+
* - What is compared is the bytes, not the reference: a picture that was replaced under the same reference (a new screenshot of
|
|
17
|
+
* a widget) is given again.
|
|
18
|
+
*/
|
|
19
|
+
import type { ImageBytesSink } from '../../engine/codec/canvasDocument.js';
|
|
20
|
+
import type { ShapeImageStore } from '../shapes/shapeImageStore.js';
|
|
21
|
+
export interface PictureSaveMemory {
|
|
22
|
+
/**
|
|
23
|
+
* The place for the writer to put bytes during one save, or null when there is no store (the bytes then stay in the text).
|
|
24
|
+
* Call `finishSave` when the save is over.
|
|
25
|
+
*/
|
|
26
|
+
startSave(store: ShapeImageStore | null): ImageBytesSink | null;
|
|
27
|
+
/**
|
|
28
|
+
* Ends the save that began last. `completed` is false when the save failed half way: what it handed over is kept, and nothing
|
|
29
|
+
* is forgotten, since the part it did not get to says nothing about the pictures it did not see.
|
|
30
|
+
*/
|
|
31
|
+
finishSave(completed: boolean): void;
|
|
32
|
+
}
|
|
33
|
+
export declare function createPictureSaveMemory(): PictureSaveMemory;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export function createPictureSaveMemory() {
|
|
2
|
+
/** The store the memory is about. */
|
|
3
|
+
let rememberedFor = null;
|
|
4
|
+
/** Reference → the bytes the store accepted for it. */
|
|
5
|
+
let remembered = new Map();
|
|
6
|
+
/** What the save that is on its way has handed over or found already handed over, by reference; null between saves. */
|
|
7
|
+
let thisSave = null;
|
|
8
|
+
return {
|
|
9
|
+
startSave(store) {
|
|
10
|
+
if (!store) {
|
|
11
|
+
thisSave = null;
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
if (store !== rememberedFor) {
|
|
15
|
+
rememberedFor = store;
|
|
16
|
+
remembered = new Map();
|
|
17
|
+
}
|
|
18
|
+
const seenInThisSave = new Map();
|
|
19
|
+
thisSave = seenInThisSave;
|
|
20
|
+
return {
|
|
21
|
+
save(reference, dataUrl) {
|
|
22
|
+
// A throw from the store is the writer's to deal with, and nothing is noted for it.
|
|
23
|
+
if (remembered.get(reference) !== dataUrl)
|
|
24
|
+
store.save(reference, dataUrl);
|
|
25
|
+
seenInThisSave.set(reference, dataUrl);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
finishSave(completed) {
|
|
30
|
+
const seenInThisSave = thisSave;
|
|
31
|
+
thisSave = null;
|
|
32
|
+
if (!seenInThisSave)
|
|
33
|
+
return;
|
|
34
|
+
if (completed) {
|
|
35
|
+
remembered = seenInThisSave;
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
for (const [reference, dataUrl] of seenInThisSave)
|
|
39
|
+
remembered.set(reference, dataUrl);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -47,6 +47,11 @@ export interface WidgetScreenRect extends WidgetPreviewGeometry {
|
|
|
47
47
|
widgetId: string;
|
|
48
48
|
hovered: boolean;
|
|
49
49
|
}
|
|
50
|
+
/** What `listWidgetShapeScreenRects()` can be asked (see `nearCards.ts` for which cards it lists when it is not asked for all). */
|
|
51
|
+
export interface ListWidgetScreenRectsOptions {
|
|
52
|
+
/** Every card of the board, near the view or not: what the list held before it was limited to the cards near the view. */
|
|
53
|
+
all?: boolean;
|
|
54
|
+
}
|
|
50
55
|
/** A point of the world on the page. */
|
|
51
56
|
export declare function worldPointToPage(viewport: Viewport, frame: BoardFrame, x: number, y: number): {
|
|
52
57
|
x: number;
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
import { boxToWorldMatrix } from '../../engine/core/matrix.js';
|
|
12
12
|
import { shapeBounds } from '../../engine/core/scene.js';
|
|
13
13
|
function cssScaleOf(frame) {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const layoutWidth = frame.layoutWidth && frame.layoutWidth > 0 ? frame.layoutWidth : frame.width;
|
|
15
|
+
const layoutHeight = frame.layoutHeight && frame.layoutHeight > 0 ? frame.layoutHeight : frame.height;
|
|
16
16
|
return {
|
|
17
17
|
scaleX: layoutWidth > 0 && frame.width > 0 ? frame.width / layoutWidth : 1,
|
|
18
18
|
scaleY: layoutHeight > 0 && frame.height > 0 ? frame.height / layoutHeight : 1
|
|
@@ -20,7 +20,7 @@ function cssScaleOf(frame) {
|
|
|
20
20
|
}
|
|
21
21
|
/** A point of the world on the page. */
|
|
22
22
|
export function worldPointToPage(viewport, frame, x, y) {
|
|
23
|
-
|
|
23
|
+
const { scaleX, scaleY } = cssScaleOf(frame);
|
|
24
24
|
return {
|
|
25
25
|
x: frame.left + (viewport.x + x * viewport.zoom) * scaleX,
|
|
26
26
|
y: frame.top + (viewport.y + y * viewport.zoom) * scaleY
|
|
@@ -28,12 +28,12 @@ export function worldPointToPage(viewport, frame, x, y) {
|
|
|
28
28
|
}
|
|
29
29
|
/** The matrix from a box's own pixels to the page, or null when something is not a finite number. */
|
|
30
30
|
export function boxToPageMatrix(box, viewport, frame) {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
const { scaleX, scaleY } = cssScaleOf(frame);
|
|
32
|
+
const world = boxToWorldMatrix(box);
|
|
33
33
|
// page = frame + scale * (viewport.translate + zoom * world)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
const zoomX = viewport.zoom * scaleX;
|
|
35
|
+
const zoomY = viewport.zoom * scaleY;
|
|
36
|
+
const matrix = [
|
|
37
37
|
world[0] * zoomX,
|
|
38
38
|
world[1] * zoomY,
|
|
39
39
|
world[2] * zoomX,
|
|
@@ -45,34 +45,31 @@ export function boxToPageMatrix(box, viewport, frame) {
|
|
|
45
45
|
}
|
|
46
46
|
/** The geometry of a card on the page. Null when the numbers are not usable. */
|
|
47
47
|
export function widgetPreviewGeometry(shape, viewport, frame) {
|
|
48
|
-
|
|
48
|
+
const matrix = boxToPageMatrix(shape, viewport, frame);
|
|
49
49
|
if (!matrix)
|
|
50
50
|
return null;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
const localWidth = shape.width || 1;
|
|
52
|
+
const localHeight = shape.height || 1;
|
|
53
|
+
const corners = [
|
|
54
54
|
[0, 0],
|
|
55
55
|
[localWidth, 0],
|
|
56
56
|
[0, localHeight],
|
|
57
57
|
[localWidth, localHeight]
|
|
58
|
-
].map(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
var ys = corners.map(function (corner) { return corner.y; });
|
|
67
|
-
var left = Math.min.apply(Math, xs);
|
|
68
|
-
var top = Math.min.apply(Math, ys);
|
|
58
|
+
].map(([x, y]) => ({
|
|
59
|
+
x: matrix[0] * x + matrix[2] * y + matrix[4],
|
|
60
|
+
y: matrix[1] * x + matrix[3] * y + matrix[5]
|
|
61
|
+
}));
|
|
62
|
+
const xs = corners.map((corner) => corner.x);
|
|
63
|
+
const ys = corners.map((corner) => corner.y);
|
|
64
|
+
const left = Math.min(...xs);
|
|
65
|
+
const top = Math.min(...ys);
|
|
69
66
|
return {
|
|
70
|
-
left
|
|
71
|
-
top
|
|
72
|
-
width: Math.max
|
|
73
|
-
height: Math.max
|
|
74
|
-
localWidth
|
|
75
|
-
localHeight
|
|
67
|
+
left,
|
|
68
|
+
top,
|
|
69
|
+
width: Math.max(...xs) - left,
|
|
70
|
+
height: Math.max(...ys) - top,
|
|
71
|
+
localWidth,
|
|
72
|
+
localHeight,
|
|
76
73
|
// The old canvas answered with the matrix of the card's pixels, one unit per local pixel.
|
|
77
74
|
matrix: [matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]]
|
|
78
75
|
};
|
|
@@ -83,8 +80,8 @@ export function screenRectOfShape(shape, viewport, frame) {
|
|
|
83
80
|
}
|
|
84
81
|
/** The box of a rectangle of the world on the page, with the board it sits on. */
|
|
85
82
|
export function screenRectOfBounds(bounds, viewport, frame) {
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
const topLeft = worldPointToPage(viewport, frame, bounds.x, bounds.y);
|
|
84
|
+
const bottomRight = worldPointToPage(viewport, frame, bounds.x + bounds.width, bounds.y + bounds.height);
|
|
88
85
|
return {
|
|
89
86
|
left: Math.min(topLeft.x, bottomRight.x),
|
|
90
87
|
top: Math.min(topLeft.y, bottomRight.y),
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { Scene } from '../../engine/core/scene.js';
|
|
2
|
+
import type { ObjectId, Rect } from '../../engine/core/types.js';
|
|
3
|
+
import type { ShapeImageStore } from '../shapes/shapeImageStore.js';
|
|
4
|
+
/** How many pictures are asked of the store at the same time. */
|
|
5
|
+
export declare const PICTURE_LOAD_CONCURRENCY = 6;
|
|
6
|
+
/** How long the pictures that came in are kept before they are put on the board together (so that a burst is one change, not forty). */
|
|
7
|
+
export declare const PICTURE_APPLY_DELAY_MS = 40;
|
|
8
|
+
/**
|
|
9
|
+
* How long the pictures that are not on screen wait for the ones that are, at most. They wait for them to come in, so that the
|
|
10
|
+
* store and the network are the on-screen pictures' alone; one that hangs must not hold back the rest of the board for ever.
|
|
11
|
+
*/
|
|
12
|
+
export declare const PICTURE_BACKGROUND_GRACE_MS = 3000;
|
|
13
|
+
/** An object that points at a picture and does not hold its bytes yet. */
|
|
14
|
+
export interface MissingPicture {
|
|
15
|
+
objectId: ObjectId;
|
|
16
|
+
/** What the page's store knows the picture by. */
|
|
17
|
+
reference: string;
|
|
18
|
+
/** Where the object paints, in the world (what decides whether it is on screen). */
|
|
19
|
+
bounds: Rect;
|
|
20
|
+
}
|
|
21
|
+
/** A picture that the store gave back, with the reference it was asked for (the object may have been given another since). */
|
|
22
|
+
export interface LoadedPicture {
|
|
23
|
+
reference: string;
|
|
24
|
+
dataUrl: string;
|
|
25
|
+
}
|
|
26
|
+
/** The objects of a scene that point at a picture and do not hold its bytes, in the order of the scene. */
|
|
27
|
+
export declare function picturesStillMissing(scene: Scene): MissingPicture[];
|
|
28
|
+
/**
|
|
29
|
+
* A scene with the pictures that came in put into the objects that were waiting for exactly that picture. An object that holds a
|
|
30
|
+
* picture by now (the person put another one there), or points at another reference, or is gone, is left as it is. The very same
|
|
31
|
+
* scene when nothing changed.
|
|
32
|
+
*/
|
|
33
|
+
export declare function fillPictures(scene: Scene, loaded: ReadonlyMap<ObjectId, LoadedPicture>): Scene;
|
|
34
|
+
/**
|
|
35
|
+
* Waits for a promise for at most `milliseconds`. True when it finished in time, false when the time ran out first (the promise is
|
|
36
|
+
* not stopped: whatever it was doing goes on). A promise that fails counts as finished: the caller only wanted to know that it is over.
|
|
37
|
+
*/
|
|
38
|
+
export declare function waitUpTo(promise: Promise<unknown>, milliseconds: number): Promise<boolean>;
|
|
39
|
+
/** A rectangle made of finite numbers with some size: anything else says the board has no size (or no view) yet. */
|
|
40
|
+
export declare function isUsableView(view: Rect | null | undefined): view is Rect;
|
|
41
|
+
/** How many of the pictures are of objects that touch the view. All of them when the view is not known: nothing is known to be far. */
|
|
42
|
+
export declare function countPicturesInView(missing: readonly MissingPicture[], view: Rect | null | undefined): number;
|
|
43
|
+
/**
|
|
44
|
+
* The pictures still to be asked for, handing out the one to ask next: the ones of objects that touch the view first, the nearest
|
|
45
|
+
* to the middle of the view first among those and among the others. The order is made again when the view has moved by a quarter
|
|
46
|
+
* of itself or changed its size by a quarter (not at every pan frame, and not at every picture), and it is the scene's own order
|
|
47
|
+
* when the view is not known.
|
|
48
|
+
*/
|
|
49
|
+
export declare class PictureQueue {
|
|
50
|
+
#private;
|
|
51
|
+
constructor(missing: readonly MissingPicture[]);
|
|
52
|
+
/** How many are still to be asked for. */
|
|
53
|
+
get length(): number;
|
|
54
|
+
/** The picture to ask for next, or undefined when none is left. */
|
|
55
|
+
take(view: Rect | null | undefined): MissingPicture | undefined;
|
|
56
|
+
/** Puts back a picture that was taken and not asked for after all: it is the next one to be handed out (it was the best). */
|
|
57
|
+
giveBack(picture: MissingPicture): void;
|
|
58
|
+
}
|
|
59
|
+
/** What `startLoadingPictures` needs to know about the board and the page. */
|
|
60
|
+
export interface PictureLoadPlan {
|
|
61
|
+
missing: readonly MissingPicture[];
|
|
62
|
+
store: ShapeImageStore;
|
|
63
|
+
/** The rectangle of the world that is on screen right now, or null when that is not known. */
|
|
64
|
+
currentView(): Rect | null;
|
|
65
|
+
/** Puts pictures that came in on the board. Called with a batch, never with an empty one. */
|
|
66
|
+
apply(loaded: ReadonlyMap<ObjectId, LoadedPicture>): void;
|
|
67
|
+
/** True once the board is gone or was replaced by another one: nothing more is asked, and nothing that came is put on the board. */
|
|
68
|
+
isCancelled(): boolean;
|
|
69
|
+
/** Says what went wrong with one picture (the others go on). */
|
|
70
|
+
warn(message: string, ...details: unknown[]): void;
|
|
71
|
+
concurrency?: number;
|
|
72
|
+
applyDelayMs?: number;
|
|
73
|
+
backgroundGraceMs?: number;
|
|
74
|
+
}
|
|
75
|
+
export interface PictureLoad {
|
|
76
|
+
/**
|
|
77
|
+
* Resolves when no picture of an object that is on screen is left to be asked for or to be answered (found or not), and the ones
|
|
78
|
+
* that were found are on the board: the pictures the board waits for before it opens. At once when none is on screen.
|
|
79
|
+
*/
|
|
80
|
+
firstScreenful: Promise<void>;
|
|
81
|
+
/** Resolves when every picture has been answered (or the board was replaced), and the ones that were found are on the board. */
|
|
82
|
+
everything: Promise<void>;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Asks the store for the missing pictures, a few at a time and in the order of `PictureQueue`, and puts what comes in on the board
|
|
86
|
+
* in small batches. Never throws: a picture the store cannot give is a warning, and the others go on.
|
|
87
|
+
*/
|
|
88
|
+
export declare function startLoadingPictures(plan: PictureLoadPlan): PictureLoad;
|