@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
|
@@ -9,13 +9,12 @@
|
|
|
9
9
|
* The side is given as a function, so a card that the page moves while the canvas is open takes its tooltips with it.
|
|
10
10
|
*/
|
|
11
11
|
import { getContext, setContext } from 'svelte';
|
|
12
|
-
|
|
12
|
+
const POPOVER_SIDE_CONTEXT_KEY = Symbol('widgetic-canvas-popover-side');
|
|
13
13
|
/** Called by a card of the chrome, before its children are made. */
|
|
14
14
|
export function providePopoverSide(getSide) {
|
|
15
15
|
setContext(POPOVER_SIDE_CONTEXT_KEY, getSide);
|
|
16
16
|
}
|
|
17
17
|
/** The side to open a tooltip or a menu to. A button used outside a card of the chrome opens upward, as the bottom toolbar always did. */
|
|
18
18
|
export function usePopoverSide() {
|
|
19
|
-
|
|
20
|
-
return (_a = getContext(POPOVER_SIDE_CONTEXT_KEY)) !== null && _a !== void 0 ? _a : (function () { return 'top'; });
|
|
19
|
+
return getContext(POPOVER_SIDE_CONTEXT_KEY) ?? (() => 'top');
|
|
21
20
|
}
|
|
@@ -5,26 +5,17 @@
|
|
|
5
5
|
* of shape has is the engine's own rule (`style.ts` says which keys of a style patch a shape takes), so the panel never
|
|
6
6
|
* offers a control that would change nothing.
|
|
7
7
|
*/
|
|
8
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
9
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
10
|
-
if (ar || !(i in from)) {
|
|
11
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
12
|
-
ar[i] = from[i];
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
16
|
-
};
|
|
17
8
|
import { isArrow } from '../../engine/core/arrow.js';
|
|
18
9
|
import { isBrushStroke } from '../../engine/core/brush.js';
|
|
19
10
|
import { leafShapesOf, normalizeSelection } from '../../engine/core/scene.js';
|
|
20
11
|
import { lineColorOf, paintsFillOnStroke, pathSupportsRoundness } from '../../engine/core/style.js';
|
|
21
|
-
|
|
12
|
+
const NONE = { kind: 'none' };
|
|
22
13
|
/** One value out of many: the value they all have, `mixed` when they differ, `none` when there is nothing to compare. */
|
|
23
14
|
export function unify(values) {
|
|
24
15
|
if (values.length === 0)
|
|
25
16
|
return NONE;
|
|
26
|
-
|
|
27
|
-
return values.every(
|
|
17
|
+
const first = values[0];
|
|
18
|
+
return values.every((value) => Object.is(value, first)) ? { kind: 'same', value: first } : { kind: 'mixed' };
|
|
28
19
|
}
|
|
29
20
|
/** Whether a shape has a fill and a stroke of its own: the three kinds of vector shape. */
|
|
30
21
|
function isVector(shape) {
|
|
@@ -32,43 +23,46 @@ function isVector(shape) {
|
|
|
32
23
|
}
|
|
33
24
|
/** Describes the selection for the panel. */
|
|
34
25
|
export function describeSelection(scene, selectedIds) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
26
|
+
const unitIds = normalizeSelection(scene, selectedIds);
|
|
27
|
+
const unitIdSet = new Set(unitIds);
|
|
28
|
+
const units = scene.filter((object) => unitIdSet.has(object.id));
|
|
29
|
+
const shapes = leafShapesOf(scene, unitIds);
|
|
30
|
+
const only = units.length === 1 ? units[0] : undefined;
|
|
31
|
+
const widgetCard = only && only.type === 'widget' ? only : null;
|
|
41
32
|
// The card of a widget is the page's to style (it shows the widget): the panel does not paint it.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
33
|
+
const targets = shapes.filter((shape) => shape.type !== 'widget');
|
|
34
|
+
const vectors = targets.filter(isVector);
|
|
35
|
+
const texts = targets.filter((shape) => shape.type === 'text');
|
|
45
36
|
// A brush stroke is a filled outline, but to a person it is a line: its colour is the Stroke, and it has no Fill. An arrow is a line too.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
37
|
+
const fillValues = [
|
|
38
|
+
...vectors
|
|
39
|
+
.filter((shape) => !isBrushStroke(shape) && !isArrow(shape))
|
|
40
|
+
.map((shape) => (paintsFillOnStroke(shape) ? shape.stroke : shape.fill)),
|
|
41
|
+
...texts.map((shape) => shape.color)
|
|
42
|
+
];
|
|
43
|
+
const strokeValues = vectors.filter((shape) => !paintsFillOnStroke(shape)).map(lineColorOf);
|
|
44
|
+
const roundnessValues = vectors
|
|
45
|
+
.filter((shape) => shape.type === 'rect' || (shape.type === 'path' && pathSupportsRoundness(shape.shape)))
|
|
46
|
+
.map((shape) => (shape.type === 'rect' || shape.type === 'path' ? shape.roundness : 0));
|
|
53
47
|
return {
|
|
54
|
-
targets
|
|
55
|
-
units
|
|
48
|
+
targets,
|
|
49
|
+
units,
|
|
56
50
|
fill: unify(fillValues),
|
|
57
51
|
stroke: unify(strokeValues),
|
|
58
|
-
strokeWidth: unify(vectors.map(
|
|
52
|
+
strokeWidth: unify(vectors.map((shape) => shape.strokeWidth)),
|
|
59
53
|
roundness: unify(roundnessValues),
|
|
60
|
-
opacity: unify(targets.map(
|
|
54
|
+
opacity: unify(targets.map((shape) => shape.opacity)),
|
|
61
55
|
text: texts.length === 0
|
|
62
56
|
? null
|
|
63
57
|
: {
|
|
64
|
-
fontSize: unify(texts.map(
|
|
65
|
-
fontFamily: unify(texts.map(
|
|
66
|
-
bold: unify(texts.map(
|
|
67
|
-
italic: unify(texts.map(
|
|
68
|
-
underline: unify(texts.map(
|
|
69
|
-
align: unify(texts.map(
|
|
58
|
+
fontSize: unify(texts.map((shape) => shape.fontSize)),
|
|
59
|
+
fontFamily: unify(texts.map((shape) => shape.fontFamily)),
|
|
60
|
+
bold: unify(texts.map((shape) => shape.fontWeight === 'bold')),
|
|
61
|
+
italic: unify(texts.map((shape) => shape.fontStyle === 'italic')),
|
|
62
|
+
underline: unify(texts.map((shape) => shape.underline)),
|
|
63
|
+
align: unify(texts.map((shape) => shape.align))
|
|
70
64
|
},
|
|
71
|
-
widgetCard
|
|
65
|
+
widgetCard
|
|
72
66
|
};
|
|
73
67
|
}
|
|
74
68
|
/** The number of a trait for a control, or a fallback when the shapes differ or the control does not apply. */
|
|
@@ -95,7 +89,7 @@ export function showStrokeColorRow(traits, wireframeMode) {
|
|
|
95
89
|
return false;
|
|
96
90
|
if (!wireframeMode)
|
|
97
91
|
return true;
|
|
98
|
-
return traits.targets.some(
|
|
92
|
+
return traits.targets.some((shape) => {
|
|
99
93
|
if (shape.type === 'rect' || shape.type === 'ellipse')
|
|
100
94
|
return false;
|
|
101
95
|
if (shape.type !== 'path')
|
|
@@ -4,9 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
It draws what the engine's state says and nothing else. A press, a move and a release go to the host, which gives them
|
|
6
6
|
to the engine's pointer controller; the wheel is the host's own listener (it must not be passive). The board is a drawing:
|
|
7
|
-
what is at its left stays at its left and text is read left to right on every screen, so it
|
|
7
|
+
what is at its left stays at its left and text is read left to right on every screen, so it sits in a `dir="ltr"` element
|
|
8
|
+
(`LeftToRightScope`: the attribute is not on the board's own element, which changes at every frame of a pan, see there).
|
|
9
|
+
|
|
10
|
+
On a big board only the objects near the view are elements of the world layer (`mountedScene.ts`): the work of a pan, a zoom
|
|
11
|
+
or a drag is then the work of what is near the view, and not of everything that is on the board.
|
|
8
12
|
-->
|
|
9
13
|
<script lang="ts">
|
|
14
|
+
import { onDestroy } from 'svelte';
|
|
10
15
|
import { DEFAULT_WIDGET_RUNTIME } from '../../engine/state.js';
|
|
11
16
|
import type { EngineState } from '../../engine/state.js';
|
|
12
17
|
import { useCanvasLanguage } from '../../i18n/language.js';
|
|
@@ -15,11 +20,14 @@
|
|
|
15
20
|
import CanvasHint from '../ui/CanvasHint.svelte';
|
|
16
21
|
import LoadNotice from '../ui/LoadNotice.svelte';
|
|
17
22
|
import EraserTrail from './EraserTrail.svelte';
|
|
23
|
+
import LeftToRightScope from './LeftToRightScope.svelte';
|
|
18
24
|
import ObjectView from './ObjectView.svelte';
|
|
19
25
|
import SelectionOverlay from './SelectionOverlay.svelte';
|
|
20
26
|
import TextEditor from './TextEditor.svelte';
|
|
21
27
|
import { createErasingMarks } from './erasingMarks.js';
|
|
22
28
|
import { BOARD_SURFACE_COLOR, cssCursor, dotGridStyle } from './geometry.js';
|
|
29
|
+
import { createLiftedView } from './liftedScene.js';
|
|
30
|
+
import { createMountedScene } from './mountedScene.js';
|
|
23
31
|
|
|
24
32
|
interface Props {
|
|
25
33
|
host: CanvasHost;
|
|
@@ -41,7 +49,6 @@
|
|
|
41
49
|
let { host, state, ui, advancedFeatures, loading, showEmptyBoardHint, frameElsewhere, board = $bindable(null) }: Props = $props();
|
|
42
50
|
|
|
43
51
|
const { t } = useCanvasLanguage();
|
|
44
|
-
const worldTransform = $derived(`translate(${state.viewport.x}px, ${state.viewport.y}px) scale(${state.viewport.zoom})`);
|
|
45
52
|
// The shapes the eraser has marked, as a set: each object asks whether it is one of them. A store of its own, told only
|
|
46
53
|
// when the eraser's list is replaced, and not something derived from `state`: `state` is a new object at every frame of a
|
|
47
54
|
// pan or a drag, and an object that asked something derived from it would be checked again at every one of them (see
|
|
@@ -49,6 +56,32 @@
|
|
|
49
56
|
const erasingMarks = createErasingMarks();
|
|
50
57
|
$effect.pre(() => erasingMarks.take(state.overlay.erasing));
|
|
51
58
|
|
|
59
|
+
// The objects that have an element: the ones near the view, once the board is big (see `mountedScene.ts`). A store of its own
|
|
60
|
+
// for the same reason as the eraser's marks: the list is a different one only when an object comes near, goes far, or is
|
|
61
|
+
// changed, and a pan that does none of that must not make the list of objects look again at every one of them.
|
|
62
|
+
const mountedScene = createMountedScene();
|
|
63
|
+
function updateMountedScene(): void {
|
|
64
|
+
mountedScene.take({ scene: state.scene, viewport: state.viewport, viewSize: state.viewSize, editingTextId: state.editingTextId });
|
|
65
|
+
}
|
|
66
|
+
// Once now, for a board that is drawn where effects do not run (the server); the effect keeps it up to date from then on.
|
|
67
|
+
updateMountedScene();
|
|
68
|
+
$effect.pre(updateMountedScene);
|
|
69
|
+
onDestroy(() => mountedScene.destroy());
|
|
70
|
+
// The list as a value of the component, and not as `$mountedScene` in the markup. Svelte cannot know that nobody changes the items
|
|
71
|
+
// of an each block over a store in place, so it makes every item mutable, and every one of them then counts as changed at every
|
|
72
|
+
// update of the list: a drag of one shape woke every object of the board, at every frame. Over a derived value the items are
|
|
73
|
+
// compared by identity and only the object that is a different record is told (held by `tests/view/stageUpdates.test.mjs`).
|
|
74
|
+
//
|
|
75
|
+
// While a big selection is carried, the objects are drawn from the records the drag began with and the world layer is moved by how
|
|
76
|
+
// far the selection has gone, so that a step of the drag writes the few objects that are not carried and not every one that is (see
|
|
77
|
+
// `liftedScene.ts`). At every other time `lifted` is the list as it is, and the world layer is moved by the view alone.
|
|
78
|
+
const liftedView = createLiftedView();
|
|
79
|
+
const lifted = $derived(liftedView.show($mountedScene, state.overlay.carry));
|
|
80
|
+
const mountedObjects = $derived(lifted.objects);
|
|
81
|
+
const worldTransform = $derived(
|
|
82
|
+
`translate(${state.viewport.x + lifted.offsetX * state.viewport.zoom}px, ${state.viewport.y + lifted.offsetY * state.viewport.zoom}px) scale(${state.viewport.zoom})`
|
|
83
|
+
);
|
|
84
|
+
|
|
52
85
|
/** Hands the board element to the shell (the host is attached to it), and takes it back when the board goes. */
|
|
53
86
|
function shareBoard(element: HTMLElement): () => void {
|
|
54
87
|
board = element;
|
|
@@ -58,75 +91,76 @@
|
|
|
58
91
|
}
|
|
59
92
|
</script>
|
|
60
93
|
|
|
61
|
-
|
|
62
|
-
<!--
|
|
63
|
-
<!--
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
>
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
<LeftToRightScope>
|
|
95
|
+
<!-- A drawing surface for a pointer: it carries the focus for the shortcuts, and its name says what it is. -->
|
|
96
|
+
<!-- No focus outline on the board: the ring was clipped by overflow and drew attention away from objects when Shift was held. -->
|
|
97
|
+
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
98
|
+
<div
|
|
99
|
+
{@attach shareBoard}
|
|
100
|
+
class="absolute inset-0 touch-none select-none overflow-hidden outline-none [-webkit-touch-callout:none]"
|
|
101
|
+
role="application"
|
|
102
|
+
tabindex="0"
|
|
103
|
+
aria-label={$t('canvas.state.boardLabel')}
|
|
104
|
+
aria-busy={loading}
|
|
105
|
+
data-canvas-surface
|
|
106
|
+
style="cursor:{loading ? 'progress' : cssCursor(state.cursor)};background-color:{BOARD_SURFACE_COLOR};{dotGridStyle(state.viewport)}"
|
|
107
|
+
onpointerdown={(event) => host.handlePointerDown(event)}
|
|
108
|
+
onpointermove={(event) => host.handlePointerMove(event)}
|
|
109
|
+
onpointerup={(event) => host.handlePointerUp(event)}
|
|
110
|
+
onpointercancel={(event) => host.handlePointerCancel(event)}
|
|
111
|
+
onpointerleave={(event) => host.handlePointerLeave(event)}
|
|
112
|
+
oncontextmenu={(event) => host.handleContextMenu(event)}
|
|
113
|
+
ondragover={(event) => host.handleDragOver(event)}
|
|
114
|
+
ondrop={(event) => host.handleDrop(event)}
|
|
115
|
+
>
|
|
116
|
+
<div class="absolute inset-0 origin-top-left" style="transform:{worldTransform};" data-canvas-world>
|
|
117
|
+
{#each mountedObjects as object (object.id)}
|
|
118
|
+
{#if object.type === 'text' && state.editingTextId === object.id}
|
|
119
|
+
<TextEditor shape={object} {host} />
|
|
120
|
+
{:else}
|
|
121
|
+
<ObjectView
|
|
122
|
+
{object}
|
|
123
|
+
{host}
|
|
124
|
+
runtime={object.type === 'widget' ? (state.widgets[object.widgetId] ?? DEFAULT_WIDGET_RUNTIME) : DEFAULT_WIDGET_RUNTIME}
|
|
125
|
+
pending={object.type === 'widget' ? state.pending[object.id] : undefined}
|
|
126
|
+
nameRevision={ui.nameRevision}
|
|
127
|
+
fontRevision={state.fontRevision}
|
|
128
|
+
primaryRing={advancedFeatures}
|
|
129
|
+
erasing={$erasingMarks.has(object.id)}
|
|
130
|
+
/>
|
|
131
|
+
{/if}
|
|
132
|
+
{/each}
|
|
133
|
+
{#if state.overlay.preview}
|
|
134
|
+
<ObjectView object={state.overlay.preview} {host} />
|
|
98
135
|
{/if}
|
|
99
|
-
|
|
100
|
-
{#if state.overlay.preview}
|
|
101
|
-
<ObjectView object={state.overlay.preview} {host} />
|
|
102
|
-
{/if}
|
|
103
|
-
</div>
|
|
136
|
+
</div>
|
|
104
137
|
|
|
105
|
-
|
|
138
|
+
<SelectionOverlay {state} {host} gestureKind={ui.gestureKind} {advancedFeatures} {frameElsewhere} />
|
|
106
139
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
140
|
+
{#if state.scribble}
|
|
141
|
+
<EraserTrail trail={state.scribble} viewport={state.viewport} />
|
|
142
|
+
{/if}
|
|
110
143
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
144
|
+
{#if showEmptyBoardHint}
|
|
145
|
+
<CanvasHint />
|
|
146
|
+
{/if}
|
|
114
147
|
|
|
115
|
-
|
|
148
|
+
<LoadNotice status={ui.loadStatus} />
|
|
116
149
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
150
|
+
{#if ui.loadPhase === 'error'}
|
|
151
|
+
<div
|
|
152
|
+
class="pointer-events-auto absolute inset-x-4 bottom-4 z-20 mx-auto w-11/12 max-w-md rounded-xl border border-destructive/30 bg-destructive/10 p-4 text-destructive shadow-floating"
|
|
153
|
+
role="alert"
|
|
154
|
+
>
|
|
155
|
+
<p class="text-body-medium">{$t('canvas.state.initFailed')}</p>
|
|
156
|
+
</div>
|
|
157
|
+
{/if}
|
|
125
158
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
</div>
|
|
159
|
+
{#if loading}
|
|
160
|
+
<!-- The board stays visible while its content loads. Input waits, so a late load cannot replace what was just drawn. -->
|
|
161
|
+
<div class="absolute inset-0 z-30 cursor-progress" data-canvas-loader>
|
|
162
|
+
<CanvasBoardPlaceholder showSurface={false} />
|
|
163
|
+
</div>
|
|
164
|
+
{/if}
|
|
165
|
+
</div>
|
|
166
|
+
</LeftToRightScope>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The element that says "left to right" for the board, and has nothing else to say.
|
|
3
|
+
|
|
4
|
+
The board is a drawing, so it keeps its direction on every screen (see `CanvasStage.svelte`). The attribute is set here, in a
|
|
5
|
+
component of its own, and not on the board's own element, on purpose. Svelte writes `element.dir = element.dir` again in the
|
|
6
|
+
update of any element that has a `dir` attribute, and it puts that line in the one update that all the changing attributes of
|
|
7
|
+
a component share. The board's element changes its style at every frame of a pan or a zoom (the dot grid), so the write ran
|
|
8
|
+
at every one of them, and the browser answers a write of `dir` by working out the style of everything below the element again:
|
|
9
|
+
a restyle of every object at every frame, 55 to 70% of the CPU of a frame with 3000 objects (measured with the stress page).
|
|
10
|
+
Here nothing ever changes, so the line runs once, when the board is made.
|
|
11
|
+
|
|
12
|
+
`contents`: the element has no box of its own, so the board lays itself out in the canvas exactly as if it were not here, and
|
|
13
|
+
what is below it still inherits the direction (`direction` is inherited through the element's style, box or no box).
|
|
14
|
+
-->
|
|
15
|
+
<script lang="ts">
|
|
16
|
+
import type { Snippet } from 'svelte';
|
|
17
|
+
|
|
18
|
+
let { children }: { children: Snippet } = $props();
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<div class="contents" dir="ltr">{@render children()}</div>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
children: Snippet;
|
|
4
|
+
};
|
|
5
|
+
declare const LeftToRightScope: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
6
|
+
type LeftToRightScope = ReturnType<typeof LeftToRightScope>;
|
|
7
|
+
export default LeftToRightScope;
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
/** What the page said about this card's widget (only read for a widget card). */
|
|
36
36
|
runtime?: WidgetRuntime;
|
|
37
37
|
pending?: PendingWidgetState | undefined;
|
|
38
|
-
/**
|
|
38
|
+
/** Counts the times the page said its widgets changed (`widgetNameRevision`): a card asks again whether its widget is still there. */
|
|
39
39
|
nameRevision?: number;
|
|
40
40
|
/** Counts the times fonts finished loading: the lines of a text are drawn again, because letters changed width. */
|
|
41
41
|
fontRevision?: number;
|
|
@@ -79,12 +79,16 @@
|
|
|
79
79
|
);
|
|
80
80
|
const textStyle = $derived(look.type === 'text' ? textBoxCss(look) : '');
|
|
81
81
|
|
|
82
|
-
//
|
|
83
|
-
|
|
82
|
+
// A card whose widget is gone says so. (A card whose widget is there draws no words: its name is in the selection panel.)
|
|
83
|
+
// The engine's flag and the page's `isWidgetKnown` are not something a view can watch, so the card asks again whenever the page
|
|
84
|
+
// marked its widget as gone (the runtime changes) or said that its widgets changed (the revision). Without these reads a card
|
|
85
|
+
// that was drawn empty stays empty when its widget is found to be gone, and the person is never told.
|
|
86
|
+
const cardOrphaned = $derived.by(() => {
|
|
87
|
+
if (look.type !== 'widget') return false;
|
|
84
88
|
void nameRevision;
|
|
85
|
-
|
|
89
|
+
void runtime.orphaned;
|
|
90
|
+
return host.isCardOrphaned(look);
|
|
86
91
|
});
|
|
87
|
-
const cardOrphaned = $derived(look.type === 'widget' ? host.isCardOrphaned(look) : false);
|
|
88
92
|
|
|
89
93
|
// Laid out again when the text, its style or its width change, and when the fonts arrive: not when the text is only carried.
|
|
90
94
|
const textLayout = $derived.by(() => {
|
|
@@ -223,14 +227,15 @@
|
|
|
223
227
|
>
|
|
224
228
|
{#if look.thumbnail && !runtime.hiddenImage}
|
|
225
229
|
<img class="size-full select-none object-fill" src={look.thumbnail} alt="" draggable="false" />
|
|
226
|
-
{:else if !runtime.hiddenImage}
|
|
227
|
-
<!--
|
|
230
|
+
{:else if cardOrphaned && !runtime.hiddenImage}
|
|
231
|
+
<!-- The widget is gone and no screenshot is left: a dashed card says so. A card whose widget is there says nothing:
|
|
232
|
+
the page lays the live widget over it, and a "Widget preview" placeholder would show through while it builds. -->
|
|
228
233
|
<div
|
|
229
234
|
class="flex size-full flex-col items-center justify-center gap-1 rounded-lg border-[1.5px] border-dashed border-slate-400 px-3 text-center"
|
|
230
235
|
>
|
|
231
|
-
<span class="text-[28px] leading-none" aria-hidden="true"
|
|
232
|
-
<span class="max-w-full truncate text-sm font-semibold text-slate-800">{
|
|
233
|
-
<span class="text-xs text-slate-500">{
|
|
236
|
+
<span class="text-[28px] leading-none" aria-hidden="true">⚠️</span>
|
|
237
|
+
<span class="max-w-full truncate text-sm font-semibold text-slate-800">{$t('canvas.widget.unlinkedName')}</span>
|
|
238
|
+
<span class="text-xs text-slate-500">{$t('canvas.widget.removeFromCanvas')}</span>
|
|
234
239
|
</div>
|
|
235
240
|
{/if}
|
|
236
241
|
{#if primaryRing && look.isPrimary}
|
|
@@ -7,7 +7,7 @@ interface Props {
|
|
|
7
7
|
/** What the page said about this card's widget (only read for a widget card). */
|
|
8
8
|
runtime?: WidgetRuntime;
|
|
9
9
|
pending?: PendingWidgetState | undefined;
|
|
10
|
-
/**
|
|
10
|
+
/** Counts the times the page said its widgets changed (`widgetNameRevision`): a card asks again whether its widget is still there. */
|
|
11
11
|
nameRevision?: number;
|
|
12
12
|
/** Counts the times fonts finished loading: the lines of a text are drawn again, because letters changed width. */
|
|
13
13
|
fontRevision?: number;
|
|
@@ -12,18 +12,18 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { writable } from 'svelte/store';
|
|
14
14
|
/** The set while nothing is marked: one shared set, so that "nothing marked" is the same value every time. */
|
|
15
|
-
export
|
|
15
|
+
export const NOTHING_ERASED = new Set();
|
|
16
16
|
export function createErasingMarks() {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
const { subscribe, set } = writable(NOTHING_ERASED);
|
|
18
|
+
let listSeen = null;
|
|
19
|
+
let current = NOTHING_ERASED;
|
|
20
20
|
return {
|
|
21
|
-
subscribe
|
|
22
|
-
take
|
|
21
|
+
subscribe,
|
|
22
|
+
take(marked) {
|
|
23
23
|
if (marked === listSeen)
|
|
24
24
|
return;
|
|
25
25
|
listSeen = marked;
|
|
26
|
-
|
|
26
|
+
const next = marked.length === 0 ? NOTHING_ERASED : new Set(marked);
|
|
27
27
|
// A store tells its subscribers of every `set` of an object, equal or not: nothing marked before and nothing now is no news.
|
|
28
28
|
if (next === current)
|
|
29
29
|
return;
|