@widgetic/canvas 0.5.35 → 0.5.37
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 +105 -36
- package/dist/canvas/DomCanvas.svelte +449 -0
- package/dist/canvas/DomCanvas.svelte.d.ts +221 -0
- package/dist/canvas/boardFrame.d.ts +13 -0
- package/dist/canvas/boardFrame.js +13 -0
- package/dist/canvas/boardSurface.d.ts +9 -0
- package/dist/canvas/boardSurface.js +9 -0
- package/dist/canvas/chromeLayout.d.ts +76 -0
- package/dist/canvas/chromeLayout.js +121 -0
- package/dist/canvas/emptyBoardHint.d.ts +17 -0
- package/dist/canvas/emptyBoardHint.js +12 -0
- package/dist/canvas/eventScope.d.ts +1 -1
- package/dist/canvas/eventScope.js +1 -1
- package/dist/canvas/host/CanvasHost.d.ts +348 -0
- package/dist/canvas/host/CanvasHost.js +1715 -0
- package/dist/canvas/host/CanvasHostApi.d.ts +30 -0
- package/dist/canvas/host/CanvasHostApi.js +95 -0
- package/dist/canvas/host/browserServices.d.ts +46 -0
- package/dist/canvas/host/browserServices.js +167 -0
- package/dist/canvas/host/conversion.d.ts +53 -0
- package/dist/canvas/host/conversion.js +125 -0
- package/dist/canvas/host/hostObject.d.ts +40 -0
- package/dist/canvas/host/hostObject.js +93 -0
- package/dist/canvas/host/pageEvents.d.ts +24 -0
- package/dist/canvas/host/pageEvents.js +35 -0
- package/dist/canvas/host/screenRects.d.ts +66 -0
- package/dist/canvas/host/screenRects.js +102 -0
- package/dist/canvas/host/strokeSnap.d.ts +67 -0
- package/dist/canvas/host/strokeSnap.js +165 -0
- package/dist/canvas/index.d.ts +7 -7
- package/dist/canvas/index.js +8 -8
- package/dist/canvas/openMarks.d.ts +17 -0
- package/dist/canvas/openMarks.js +26 -0
- package/dist/canvas/panZoomPosition.d.ts +15 -0
- package/dist/canvas/panZoomPosition.js +16 -0
- package/dist/canvas/preferredTextFont.d.ts +12 -0
- package/dist/canvas/preferredTextFont.js +38 -0
- package/dist/canvas/shapes/ShapeLibrary.d.ts +1 -1
- package/dist/canvas/shapes/ShapeLibrary.js +13 -1
- package/dist/canvas/shapes/strokeShapeSnap.d.ts +14 -12
- package/dist/canvas/shapes/strokeShapeSnap.js +10 -8
- package/dist/canvas/toolbarPosition.d.ts +11 -11
- package/dist/canvas/toolbarPosition.js +11 -24
- package/dist/canvas/types.d.ts +14 -0
- package/dist/canvas/ui/CanvasContextMenu.svelte +173 -0
- package/dist/canvas/ui/CanvasContextMenu.svelte.d.ts +12 -0
- package/dist/canvas/ui/CanvasHint.svelte +21 -0
- package/dist/canvas/ui/CanvasHint.svelte.d.ts +18 -0
- package/dist/canvas/ui/CanvasToolbar.svelte +95 -0
- package/dist/canvas/ui/CanvasToolbar.svelte.d.ts +14 -0
- package/dist/canvas/ui/ColorField.svelte +156 -0
- package/dist/canvas/ui/ColorField.svelte.d.ts +14 -0
- package/dist/canvas/ui/LoadNotice.svelte +39 -0
- package/dist/canvas/ui/LoadNotice.svelte.d.ts +8 -0
- package/dist/canvas/ui/SelectionPanel.svelte +300 -0
- package/dist/canvas/ui/SelectionPanel.svelte.d.ts +20 -0
- package/dist/canvas/ui/SelectorBar.svelte +82 -0
- package/dist/canvas/ui/SelectorBar.svelte.d.ts +12 -0
- package/dist/canvas/ui/ShapesMenu.svelte +185 -0
- package/dist/canvas/ui/ShapesMenu.svelte.d.ts +15 -0
- package/dist/canvas/ui/ShortcutsPanel.svelte +124 -0
- package/dist/canvas/ui/ShortcutsPanel.svelte.d.ts +7 -0
- package/dist/canvas/ui/ToolButton.svelte +78 -0
- package/dist/canvas/ui/ToolButton.svelte.d.ts +20 -0
- package/dist/canvas/ui/WidgetActions.svelte +145 -0
- package/dist/canvas/ui/WidgetActions.svelte.d.ts +19 -0
- package/dist/canvas/ui/ZoomControl.svelte +89 -0
- package/dist/canvas/ui/ZoomControl.svelte.d.ts +18 -0
- package/dist/canvas/ui/colorModel.d.ts +18 -0
- package/dist/canvas/ui/colorModel.js +85 -0
- package/dist/canvas/ui/colorPickerMessages.d.ts +5 -0
- package/dist/canvas/ui/colorPickerMessages.js +15 -0
- package/dist/canvas/ui/floatingCard.d.ts +107 -0
- package/dist/canvas/ui/floatingCard.js +107 -0
- package/dist/canvas/ui/floatingLayer.d.ts +21 -0
- package/dist/canvas/ui/floatingLayer.js +52 -0
- package/dist/canvas/ui/icons.d.ts +12 -0
- package/dist/canvas/ui/icons.js +7 -0
- package/dist/canvas/ui/keyHints.d.ts +27 -0
- package/dist/canvas/ui/keyHints.js +43 -0
- package/dist/canvas/ui/popoverSide.d.ts +5 -0
- package/dist/canvas/ui/popoverSide.js +20 -0
- package/dist/canvas/ui/selectionTraits.d.ts +61 -0
- package/dist/canvas/ui/selectionTraits.js +99 -0
- package/dist/canvas/view/CanvasStage.svelte +132 -0
- package/dist/canvas/view/CanvasStage.svelte.d.ts +21 -0
- package/dist/canvas/view/EraserTrail.svelte +50 -0
- package/dist/canvas/view/EraserTrail.svelte.d.ts +9 -0
- package/dist/canvas/view/ObjectView.svelte +245 -0
- package/dist/canvas/view/ObjectView.svelte.d.ts +21 -0
- package/dist/canvas/view/SelectionOverlay.svelte +487 -0
- package/dist/canvas/view/SelectionOverlay.svelte.d.ts +17 -0
- package/dist/canvas/view/TextEditor.svelte +76 -0
- package/dist/canvas/view/TextEditor.svelte.d.ts +9 -0
- package/dist/canvas/view/WidgetChromeLayer.svelte +83 -0
- package/dist/canvas/view/WidgetChromeLayer.svelte.d.ts +13 -0
- package/dist/canvas/view/erasingMarks.d.ts +13 -0
- package/dist/canvas/view/erasingMarks.js +34 -0
- package/dist/canvas/view/geometry.d.ts +169 -0
- package/dist/canvas/view/geometry.js +272 -0
- package/dist/components/CanvasBoardPlaceholder.svelte +5 -3
- package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +3 -3
- package/dist/components/index.js +1 -1
- package/dist/components/input-controls/ColorIC.svelte +2 -2
- package/dist/engine/EngineCore.d.ts +273 -0
- package/dist/engine/EngineCore.js +1051 -0
- package/dist/engine/codec/canvasDocument.d.ts +57 -0
- package/dist/engine/codec/canvasDocument.js +471 -0
- package/dist/engine/codec/hostReadableKeys.d.ts +25 -0
- package/dist/engine/codec/hostReadableKeys.js +25 -0
- package/dist/engine/core/arrange.d.ts +20 -0
- package/dist/engine/core/arrange.js +81 -0
- package/dist/engine/core/arrow.d.ts +91 -0
- package/dist/engine/core/arrow.js +182 -0
- package/dist/engine/core/brush.d.ts +68 -0
- package/dist/engine/core/brush.js +173 -0
- package/dist/engine/core/defaults.d.ts +70 -0
- package/dist/engine/core/defaults.js +158 -0
- package/dist/engine/core/freehand.d.ts +130 -0
- package/dist/engine/core/freehand.js +430 -0
- package/dist/engine/core/geometry.d.ts +44 -0
- package/dist/engine/core/geometry.js +216 -0
- package/dist/engine/core/history.d.ts +39 -0
- package/dist/engine/core/history.js +69 -0
- package/dist/engine/core/hitTest.d.ts +54 -0
- package/dist/engine/core/hitTest.js +298 -0
- package/dist/engine/core/matrix.d.ts +47 -0
- package/dist/engine/core/matrix.js +101 -0
- package/dist/engine/core/pathData.d.ts +50 -0
- package/dist/engine/core/pathData.js +550 -0
- package/dist/engine/core/rotationReset.d.ts +10 -0
- package/dist/engine/core/rotationReset.js +17 -0
- package/dist/engine/core/scene.d.ts +99 -0
- package/dist/engine/core/scene.js +450 -0
- package/dist/engine/core/scribble.d.ts +64 -0
- package/dist/engine/core/scribble.js +121 -0
- package/dist/engine/core/shapePaths.d.ts +34 -0
- package/dist/engine/core/shapePaths.js +69 -0
- package/dist/engine/core/shapeTools.d.ts +80 -0
- package/dist/engine/core/shapeTools.js +161 -0
- package/dist/engine/core/snapping.d.ts +64 -0
- package/dist/engine/core/snapping.js +164 -0
- package/dist/engine/core/style.d.ts +40 -0
- package/dist/engine/core/style.js +151 -0
- package/dist/engine/core/transform.d.ts +79 -0
- package/dist/engine/core/transform.js +258 -0
- package/dist/engine/core/types.d.ts +238 -0
- package/dist/engine/core/types.js +31 -0
- package/dist/engine/core/viewport.d.ts +32 -0
- package/dist/engine/core/viewport.js +84 -0
- package/dist/engine/input/PointerController.d.ts +38 -0
- package/dist/engine/input/PointerController.js +545 -0
- package/dist/engine/input/arrowHandles.d.ts +38 -0
- package/dist/engine/input/arrowHandles.js +60 -0
- package/dist/engine/input/gestures.d.ts +79 -0
- package/dist/engine/input/gestures.js +769 -0
- package/dist/engine/input/hoverCursor.d.ts +29 -0
- package/dist/engine/input/hoverCursor.js +23 -0
- package/dist/engine/input/keyboard.d.ts +75 -0
- package/dist/engine/input/keyboard.js +264 -0
- package/dist/engine/input/selectionHandles.d.ts +89 -0
- package/dist/engine/input/selectionHandles.js +169 -0
- package/dist/engine/input/types.d.ts +82 -0
- package/dist/engine/input/types.js +5 -0
- package/dist/engine/render/rasterize.d.ts +74 -0
- package/dist/engine/render/rasterize.js +273 -0
- package/dist/engine/state.d.ts +124 -0
- package/dist/engine/state.js +47 -0
- package/dist/engine/text/layoutText.d.ts +53 -0
- package/dist/engine/text/layoutText.js +170 -0
- package/dist/engine/widgets.d.ts +124 -0
- package/dist/engine/widgets.js +345 -0
- package/dist/i18n/labels.d.ts +4 -15
- package/dist/i18n/labels.js +33 -53
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +52 -124
- package/dist/i18n/messages.js +59 -133
- package/dist/i18n/shortcuts.d.ts +0 -1
- package/dist/i18n/shortcuts.js +2 -11
- package/dist/index.d.ts +4 -2
- package/dist/index.js +5 -3
- package/package.json +30 -5
- package/dist/canvas/Canvas.svelte +0 -13363
- package/dist/canvas/Canvas.svelte.d.ts +0 -286
- package/dist/canvas/CanvasToolbar.svelte +0 -1498
- package/dist/canvas/CanvasToolbar.svelte.d.ts +0 -69
- package/dist/canvas/ContextMenu.svelte +0 -305
- package/dist/canvas/ContextMenu.svelte.d.ts +0 -42
- package/dist/canvas/PanZoomPanel.svelte +0 -478
- package/dist/canvas/PanZoomPanel.svelte.d.ts +0 -38
- package/dist/canvas/WidgetSelectionLayer.svelte +0 -156
- package/dist/canvas/WidgetSelectionLayer.svelte.d.ts +0 -11
- package/dist/canvas/props-panel/PropsPanel.svelte +0 -2075
- package/dist/canvas/props-panel/PropsPanel.svelte.d.ts +0 -84
- package/dist/canvas/props-panel/TextPropsICSection.svelte +0 -242
- package/dist/canvas/props-panel/TextPropsICSection.svelte.d.ts +0 -40
- package/dist/canvas/shadowRootText.d.ts +0 -5
- package/dist/canvas/shadowRootText.js +0 -43
- package/dist/canvas/shapes/FrameShape.d.ts +0 -97
- package/dist/canvas/shapes/FrameShape.js +0 -953
- package/dist/canvas/shapes/ImageShape.d.ts +0 -47
- package/dist/canvas/shapes/ImageShape.js +0 -339
- package/dist/canvas/shapes/WidgetShape.d.ts +0 -30
- package/dist/canvas/shapes/WidgetShape.js +0 -200
- package/dist/canvas/widgetPreviewGeometry.d.ts +0 -19
- package/dist/canvas/widgetPreviewGeometry.js +0 -66
- package/dist/i18n/shapeWords.d.ts +0 -30
- package/dist/i18n/shapeWords.js +0 -36
- package/dist/i18n/slots.d.ts +0 -20
- package/dist/i18n/slots.js +0 -40
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The side of a card that its tooltips and menus open to.
|
|
3
|
+
*
|
|
4
|
+
* A card against the bottom edge opens upward, one against the top edge opens downward, and one that stands upright against
|
|
5
|
+
* the left or right edge opens sideways, into the board (see `chromeLayout.ts`). The card that knows where it stands
|
|
6
|
+
* provides the side, and the buttons, the tooltips and the Shapes menu inside it ask for it, so none of them is handed the
|
|
7
|
+
* side one by one.
|
|
8
|
+
*
|
|
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
|
+
*/
|
|
11
|
+
import { getContext, setContext } from 'svelte';
|
|
12
|
+
const POPOVER_SIDE_CONTEXT_KEY = Symbol('widgetic-canvas-popover-side');
|
|
13
|
+
/** Called by a card of the chrome, before its children are made. */
|
|
14
|
+
export function providePopoverSide(getSide) {
|
|
15
|
+
setContext(POPOVER_SIDE_CONTEXT_KEY, getSide);
|
|
16
|
+
}
|
|
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
|
+
export function usePopoverSide() {
|
|
19
|
+
return getContext(POPOVER_SIDE_CONTEXT_KEY) ?? (() => 'top');
|
|
20
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the selection panel shows for the selection: one value per control, or "mixed" when the selected shapes disagree.
|
|
3
|
+
*
|
|
4
|
+
* Pure functions of the scene and the selected ids, so Node can test them and the panel stays a view. Which control a kind
|
|
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
|
+
* offers a control that would change nothing.
|
|
7
|
+
*/
|
|
8
|
+
import type { Scene } from '../../engine/core/scene.js';
|
|
9
|
+
import type { ObjectId, SceneObject, ShapeObject, TextAlign, WidgetObject } from '../../engine/core/types.js';
|
|
10
|
+
/** A value the selected shapes share, differ in, or do not have at all. */
|
|
11
|
+
export type Trait<T> = {
|
|
12
|
+
kind: 'none';
|
|
13
|
+
} | {
|
|
14
|
+
kind: 'mixed';
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'same';
|
|
17
|
+
value: T;
|
|
18
|
+
};
|
|
19
|
+
/** One value out of many: the value they all have, `mixed` when they differ, `none` when there is nothing to compare. */
|
|
20
|
+
export declare function unify<T>(values: readonly T[]): Trait<T>;
|
|
21
|
+
export interface TextTraits {
|
|
22
|
+
fontSize: Trait<number>;
|
|
23
|
+
fontFamily: Trait<string>;
|
|
24
|
+
bold: Trait<boolean>;
|
|
25
|
+
italic: Trait<boolean>;
|
|
26
|
+
underline: Trait<boolean>;
|
|
27
|
+
align: Trait<TextAlign>;
|
|
28
|
+
}
|
|
29
|
+
export interface SelectionTraits {
|
|
30
|
+
/** The shapes the panel edits: the selected shapes and the members of the selected groups. */
|
|
31
|
+
targets: ShapeObject[];
|
|
32
|
+
/** The units that are selected (a group is one), outermost first in paint order. */
|
|
33
|
+
units: SceneObject[];
|
|
34
|
+
/** The colour of the inside (or of the letters of a text, or of the line of a line-only icon). */
|
|
35
|
+
fill: Trait<string>;
|
|
36
|
+
/** The colour of the outline, for the shapes that have an inside as well. */
|
|
37
|
+
stroke: Trait<string>;
|
|
38
|
+
strokeWidth: Trait<number>;
|
|
39
|
+
/** 0..100 */
|
|
40
|
+
roundness: Trait<number>;
|
|
41
|
+
/** 0..1 */
|
|
42
|
+
opacity: Trait<number>;
|
|
43
|
+
/** Present when the selection holds text. */
|
|
44
|
+
text: TextTraits | null;
|
|
45
|
+
/** The widget card, when the one thing selected is a widget card (its panel is about the widget, not about paint). */
|
|
46
|
+
widgetCard: WidgetObject | null;
|
|
47
|
+
}
|
|
48
|
+
/** Describes the selection for the panel. */
|
|
49
|
+
export declare function describeSelection(scene: Scene, selectedIds: readonly ObjectId[]): SelectionTraits;
|
|
50
|
+
/** The number of a trait for a control, or a fallback when the shapes differ or the control does not apply. */
|
|
51
|
+
export declare function traitNumber(trait: Trait<number>, fallback: number): number;
|
|
52
|
+
/** What the font size stepper shows: a whole number, never a long float from resizing. */
|
|
53
|
+
export declare function formatFontSizeDisplay(trait: Trait<number>): number | '–';
|
|
54
|
+
/**
|
|
55
|
+
* Whether the fill colour row should show in the wireframe look. Shapes stay plain; text colour is still editable.
|
|
56
|
+
*/
|
|
57
|
+
export declare function showFillColorRow(traits: SelectionTraits, wireframeMode: boolean): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Whether the stroke colour row should show in the wireframe look. Ink lines stay editable; filled shapes do not.
|
|
60
|
+
*/
|
|
61
|
+
export declare function showStrokeColorRow(traits: SelectionTraits, wireframeMode: boolean): boolean;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the selection panel shows for the selection: one value per control, or "mixed" when the selected shapes disagree.
|
|
3
|
+
*
|
|
4
|
+
* Pure functions of the scene and the selected ids, so Node can test them and the panel stays a view. Which control a kind
|
|
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
|
+
* offers a control that would change nothing.
|
|
7
|
+
*/
|
|
8
|
+
import { isArrow } from '../../engine/core/arrow.js';
|
|
9
|
+
import { isBrushStroke } from '../../engine/core/brush.js';
|
|
10
|
+
import { leafShapesOf, normalizeSelection } from '../../engine/core/scene.js';
|
|
11
|
+
import { lineColorOf, paintsFillOnStroke, pathSupportsRoundness } from '../../engine/core/style.js';
|
|
12
|
+
const NONE = { kind: 'none' };
|
|
13
|
+
/** One value out of many: the value they all have, `mixed` when they differ, `none` when there is nothing to compare. */
|
|
14
|
+
export function unify(values) {
|
|
15
|
+
if (values.length === 0)
|
|
16
|
+
return NONE;
|
|
17
|
+
const first = values[0];
|
|
18
|
+
return values.every((value) => Object.is(value, first)) ? { kind: 'same', value: first } : { kind: 'mixed' };
|
|
19
|
+
}
|
|
20
|
+
/** Whether a shape has a fill and a stroke of its own: the three kinds of vector shape. */
|
|
21
|
+
function isVector(shape) {
|
|
22
|
+
return shape.type === 'rect' || shape.type === 'ellipse' || shape.type === 'path';
|
|
23
|
+
}
|
|
24
|
+
/** Describes the selection for the panel. */
|
|
25
|
+
export function describeSelection(scene, selectedIds) {
|
|
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;
|
|
32
|
+
// The card of a widget is the page's to style (it shows the widget): the panel does not paint it.
|
|
33
|
+
const targets = shapes.filter((shape) => shape.type !== 'widget');
|
|
34
|
+
const vectors = targets.filter(isVector);
|
|
35
|
+
const texts = targets.filter((shape) => shape.type === 'text');
|
|
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.
|
|
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));
|
|
47
|
+
return {
|
|
48
|
+
targets,
|
|
49
|
+
units,
|
|
50
|
+
fill: unify(fillValues),
|
|
51
|
+
stroke: unify(strokeValues),
|
|
52
|
+
strokeWidth: unify(vectors.map((shape) => shape.strokeWidth)),
|
|
53
|
+
roundness: unify(roundnessValues),
|
|
54
|
+
opacity: unify(targets.map((shape) => shape.opacity)),
|
|
55
|
+
text: texts.length === 0
|
|
56
|
+
? null
|
|
57
|
+
: {
|
|
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))
|
|
64
|
+
},
|
|
65
|
+
widgetCard
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** The number of a trait for a control, or a fallback when the shapes differ or the control does not apply. */
|
|
69
|
+
export function traitNumber(trait, fallback) {
|
|
70
|
+
return trait.kind === 'same' ? trait.value : fallback;
|
|
71
|
+
}
|
|
72
|
+
/** What the font size stepper shows: a whole number, never a long float from resizing. */
|
|
73
|
+
export function formatFontSizeDisplay(trait) {
|
|
74
|
+
return trait.kind === 'same' ? Math.round(trait.value) : '–';
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Whether the fill colour row should show in the wireframe look. Shapes stay plain; text colour is still editable.
|
|
78
|
+
*/
|
|
79
|
+
export function showFillColorRow(traits, wireframeMode) {
|
|
80
|
+
if (traits.fill.kind === 'none')
|
|
81
|
+
return false;
|
|
82
|
+
return !wireframeMode || traits.text !== null;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Whether the stroke colour row should show in the wireframe look. Ink lines stay editable; filled shapes do not.
|
|
86
|
+
*/
|
|
87
|
+
export function showStrokeColorRow(traits, wireframeMode) {
|
|
88
|
+
if (traits.stroke.kind === 'none')
|
|
89
|
+
return false;
|
|
90
|
+
if (!wireframeMode)
|
|
91
|
+
return true;
|
|
92
|
+
return traits.targets.some((shape) => {
|
|
93
|
+
if (shape.type === 'rect' || shape.type === 'ellipse')
|
|
94
|
+
return false;
|
|
95
|
+
if (shape.type !== 'path')
|
|
96
|
+
return false;
|
|
97
|
+
return isBrushStroke(shape) || isArrow(shape) || !paintsFillOnStroke(shape);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The board: the element that takes the pointer, with the dot grid under the objects, the world layer that carries them, and
|
|
3
|
+
what is drawn over them (the selection, the text field, the hint of an empty board, the loader).
|
|
4
|
+
|
|
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
|
+
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 is `dir="ltr"`.
|
|
8
|
+
-->
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import { DEFAULT_WIDGET_RUNTIME } from '../../engine/state.js';
|
|
11
|
+
import type { EngineState } from '../../engine/state.js';
|
|
12
|
+
import { useCanvasLanguage } from '../../i18n/language.js';
|
|
13
|
+
import CanvasBoardPlaceholder from '../../components/CanvasBoardPlaceholder.svelte';
|
|
14
|
+
import type { CanvasHost, HostUiState } from '../host/CanvasHost.js';
|
|
15
|
+
import CanvasHint from '../ui/CanvasHint.svelte';
|
|
16
|
+
import LoadNotice from '../ui/LoadNotice.svelte';
|
|
17
|
+
import EraserTrail from './EraserTrail.svelte';
|
|
18
|
+
import ObjectView from './ObjectView.svelte';
|
|
19
|
+
import SelectionOverlay from './SelectionOverlay.svelte';
|
|
20
|
+
import TextEditor from './TextEditor.svelte';
|
|
21
|
+
import { createErasingMarks } from './erasingMarks.js';
|
|
22
|
+
import { BOARD_SURFACE_COLOR, cssCursor, dotGridStyle } from './geometry.js';
|
|
23
|
+
|
|
24
|
+
interface Props {
|
|
25
|
+
host: CanvasHost;
|
|
26
|
+
/** The engine's state: the scene, the selection, the viewport, the tool. */
|
|
27
|
+
state: EngineState;
|
|
28
|
+
/** The host's own state: the loading phase, what is open, what the pointer is doing. */
|
|
29
|
+
ui: HostUiState;
|
|
30
|
+
advancedFeatures: boolean;
|
|
31
|
+
/** The board is loading, or the page says its data is: input waits and the loader shows. */
|
|
32
|
+
loading: boolean;
|
|
33
|
+
/** Whether the empty-board hint is shown (see `emptyBoardHint.ts`). */
|
|
34
|
+
showEmptyBoardHint: boolean;
|
|
35
|
+
/** True when the frame of a selected live widget card is drawn in the page's own layer above it. */
|
|
36
|
+
frameElsewhere: boolean;
|
|
37
|
+
/** The element the pointer events come from, handed to the shell (it is what the host is attached to). */
|
|
38
|
+
board?: HTMLElement | null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let { host, state, ui, advancedFeatures, loading, showEmptyBoardHint, frameElsewhere, board = $bindable(null) }: Props = $props();
|
|
42
|
+
|
|
43
|
+
const { t } = useCanvasLanguage();
|
|
44
|
+
const worldTransform = $derived(`translate(${state.viewport.x}px, ${state.viewport.y}px) scale(${state.viewport.zoom})`);
|
|
45
|
+
// 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
|
+
// when the eraser's list is replaced, and not something derived from `state`: `state` is a new object at every frame of a
|
|
47
|
+
// pan or a drag, and an object that asked something derived from it would be checked again at every one of them (see
|
|
48
|
+
// `erasingMarks.ts`). The effect only hands the list over; it runs at every frame and does nothing while the list is the same.
|
|
49
|
+
const erasingMarks = createErasingMarks();
|
|
50
|
+
$effect.pre(() => erasingMarks.take(state.overlay.erasing));
|
|
51
|
+
|
|
52
|
+
/** Hands the board element to the shell (the host is attached to it), and takes it back when the board goes. */
|
|
53
|
+
function shareBoard(element: HTMLElement): () => void {
|
|
54
|
+
board = element;
|
|
55
|
+
return () => {
|
|
56
|
+
board = null;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
</script>
|
|
60
|
+
|
|
61
|
+
<!-- A drawing surface for a pointer: it carries the focus for the shortcuts, and its name says what it is. -->
|
|
62
|
+
<!-- No focus outline on the board: the ring was clipped by overflow and drew attention away from objects when Shift was held. -->
|
|
63
|
+
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
64
|
+
<div
|
|
65
|
+
{@attach shareBoard}
|
|
66
|
+
class="absolute inset-0 touch-none select-none overflow-hidden outline-none [-webkit-touch-callout:none]"
|
|
67
|
+
dir="ltr"
|
|
68
|
+
role="application"
|
|
69
|
+
tabindex="0"
|
|
70
|
+
aria-label={$t('canvas.state.boardLabel')}
|
|
71
|
+
aria-busy={loading}
|
|
72
|
+
data-canvas-surface
|
|
73
|
+
style="cursor:{loading ? 'progress' : cssCursor(state.cursor)};background-color:{BOARD_SURFACE_COLOR};{dotGridStyle(state.viewport)}"
|
|
74
|
+
onpointerdown={(event) => host.handlePointerDown(event)}
|
|
75
|
+
onpointermove={(event) => host.handlePointerMove(event)}
|
|
76
|
+
onpointerup={(event) => host.handlePointerUp(event)}
|
|
77
|
+
onpointercancel={(event) => host.handlePointerCancel(event)}
|
|
78
|
+
onpointerleave={(event) => host.handlePointerLeave(event)}
|
|
79
|
+
oncontextmenu={(event) => host.handleContextMenu(event)}
|
|
80
|
+
ondragover={(event) => host.handleDragOver(event)}
|
|
81
|
+
ondrop={(event) => host.handleDrop(event)}
|
|
82
|
+
>
|
|
83
|
+
<div class="absolute inset-0 origin-top-left" style="transform:{worldTransform};" data-canvas-world>
|
|
84
|
+
{#each state.scene as object (object.id)}
|
|
85
|
+
{#if object.type === 'text' && state.editingTextId === object.id}
|
|
86
|
+
<TextEditor shape={object} {host} />
|
|
87
|
+
{:else}
|
|
88
|
+
<ObjectView
|
|
89
|
+
{object}
|
|
90
|
+
{host}
|
|
91
|
+
runtime={object.type === 'widget' ? (state.widgets[object.widgetId] ?? DEFAULT_WIDGET_RUNTIME) : DEFAULT_WIDGET_RUNTIME}
|
|
92
|
+
pending={object.type === 'widget' ? state.pending[object.id] : undefined}
|
|
93
|
+
nameRevision={ui.nameRevision}
|
|
94
|
+
fontRevision={state.fontRevision}
|
|
95
|
+
primaryRing={advancedFeatures}
|
|
96
|
+
erasing={$erasingMarks.has(object.id)}
|
|
97
|
+
/>
|
|
98
|
+
{/if}
|
|
99
|
+
{/each}
|
|
100
|
+
{#if state.overlay.preview}
|
|
101
|
+
<ObjectView object={state.overlay.preview} {host} />
|
|
102
|
+
{/if}
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
<SelectionOverlay {state} {host} gestureKind={ui.gestureKind} {advancedFeatures} {frameElsewhere} />
|
|
106
|
+
|
|
107
|
+
{#if state.scribble}
|
|
108
|
+
<EraserTrail trail={state.scribble} viewport={state.viewport} />
|
|
109
|
+
{/if}
|
|
110
|
+
|
|
111
|
+
{#if showEmptyBoardHint}
|
|
112
|
+
<CanvasHint />
|
|
113
|
+
{/if}
|
|
114
|
+
|
|
115
|
+
<LoadNotice status={ui.loadStatus} />
|
|
116
|
+
|
|
117
|
+
{#if ui.loadPhase === 'error'}
|
|
118
|
+
<div
|
|
119
|
+
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"
|
|
120
|
+
role="alert"
|
|
121
|
+
>
|
|
122
|
+
<p class="text-body-medium">{$t('canvas.state.initFailed')}</p>
|
|
123
|
+
</div>
|
|
124
|
+
{/if}
|
|
125
|
+
|
|
126
|
+
{#if loading}
|
|
127
|
+
<!-- The board stays visible while its content loads. Input waits, so a late load cannot replace what was just drawn. -->
|
|
128
|
+
<div class="absolute inset-0 z-30 cursor-progress" data-canvas-loader>
|
|
129
|
+
<CanvasBoardPlaceholder showSurface={false} />
|
|
130
|
+
</div>
|
|
131
|
+
{/if}
|
|
132
|
+
</div>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { EngineState } from '../../engine/state.js';
|
|
2
|
+
import type { CanvasHost, HostUiState } from '../host/CanvasHost.js';
|
|
3
|
+
interface Props {
|
|
4
|
+
host: CanvasHost;
|
|
5
|
+
/** The engine's state: the scene, the selection, the viewport, the tool. */
|
|
6
|
+
state: EngineState;
|
|
7
|
+
/** The host's own state: the loading phase, what is open, what the pointer is doing. */
|
|
8
|
+
ui: HostUiState;
|
|
9
|
+
advancedFeatures: boolean;
|
|
10
|
+
/** The board is loading, or the page says its data is: input waits and the loader shows. */
|
|
11
|
+
loading: boolean;
|
|
12
|
+
/** Whether the empty-board hint is shown (see `emptyBoardHint.ts`). */
|
|
13
|
+
showEmptyBoardHint: boolean;
|
|
14
|
+
/** True when the frame of a selected live widget card is drawn in the page's own layer above it. */
|
|
15
|
+
frameElsewhere: boolean;
|
|
16
|
+
/** The element the pointer events come from, handed to the shell (it is what the host is attached to). */
|
|
17
|
+
board?: HTMLElement | null;
|
|
18
|
+
}
|
|
19
|
+
declare const CanvasStage: import("svelte").Component<Props, {}, "board">;
|
|
20
|
+
type CanvasStage = ReturnType<typeof CanvasStage>;
|
|
21
|
+
export default CanvasStage;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The smear that follows the eraser while it is dragged: a short trail, thin at its tail and as wide as a thumb at the
|
|
3
|
+
pointer, eaten away from the tail as the pointer rests and after it lets go. It shows how far the eraser reaches; which
|
|
4
|
+
shapes it took is shown by the shapes themselves, which stay on the board, faded, until the pointer is released.
|
|
5
|
+
|
|
6
|
+
It is drawn in the board's pixels, over the objects, and never takes the pointer. The points are kept in the world, so the
|
|
7
|
+
trail stays with what it passed over when the board is panned or zoomed meanwhile. The engine keeps the trail alive and
|
|
8
|
+
the host's frame clock steps it; this only draws what `state.scribble` says.
|
|
9
|
+
-->
|
|
10
|
+
<script lang="ts">
|
|
11
|
+
import { EASE_LINEAR, circlePathData, freehandOutline, outlinePathData } from '../../engine/core/freehand.js';
|
|
12
|
+
import { SCRIBBLE_CONFIG } from '../../engine/core/scribble.js';
|
|
13
|
+
import type { ScribbleView } from '../../engine/core/scribble.js';
|
|
14
|
+
import type { Viewport } from '../../engine/core/types.js';
|
|
15
|
+
import { worldToScreen } from '../../engine/core/viewport.js';
|
|
16
|
+
|
|
17
|
+
interface Props {
|
|
18
|
+
trail: ScribbleView;
|
|
19
|
+
viewport: Viewport;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let { trail, viewport }: Props = $props();
|
|
23
|
+
|
|
24
|
+
// The outline of the trail, as path data in board pixels: the same outline the pencil's strokes are made with.
|
|
25
|
+
const pathData = $derived.by(() => {
|
|
26
|
+
if (trail.points.length === 0) return '';
|
|
27
|
+
try {
|
|
28
|
+
const screenPoints = trail.points.map((point) => worldToScreen(viewport, point));
|
|
29
|
+
const outline = freehandOutline(screenPoints, {
|
|
30
|
+
size: trail.size,
|
|
31
|
+
start: { taper: true, easing: EASE_LINEAR },
|
|
32
|
+
last: trail.stopping,
|
|
33
|
+
simulatePressure: false,
|
|
34
|
+
streamline: SCRIBBLE_CONFIG.streamline
|
|
35
|
+
});
|
|
36
|
+
// Too short to have an outline: one dot, as wide as the head.
|
|
37
|
+
if (outline.length < 4) return circlePathData(screenPoints[screenPoints.length - 1], trail.size / 2);
|
|
38
|
+
return outlinePathData(outline);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.warn('Canvas: the eraser trail could not be drawn', error);
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
</script>
|
|
45
|
+
|
|
46
|
+
{#if pathData}
|
|
47
|
+
<svg class="pointer-events-none absolute inset-0 size-full overflow-visible" aria-hidden="true" data-canvas-eraser-trail>
|
|
48
|
+
<path d={pathData} class="fill-muted-foreground/40" fill-opacity={SCRIBBLE_CONFIG.opacity} />
|
|
49
|
+
</svg>
|
|
50
|
+
{/if}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ScribbleView } from '../../engine/core/scribble.js';
|
|
2
|
+
import type { Viewport } from '../../engine/core/types.js';
|
|
3
|
+
interface Props {
|
|
4
|
+
trail: ScribbleView;
|
|
5
|
+
viewport: Viewport;
|
|
6
|
+
}
|
|
7
|
+
declare const EraserTrail: import("svelte").Component<Props, {}, "">;
|
|
8
|
+
type EraserTrail = ReturnType<typeof EraserTrail>;
|
|
9
|
+
export default EraserTrail;
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
One object of the board, drawn as DOM in its own box of the world layer.
|
|
3
|
+
|
|
4
|
+
A vector shape is an SVG whose box is placed with one CSS matrix (its position and its turn), so a stroke keeps its width
|
|
5
|
+
at any size and the browser does the drawing. Text is a block of lines, each laid out by the engine and never wrapped by
|
|
6
|
+
the browser. A picture is an <img>. A widget card is a rounded white card with the last screenshot of the widget.
|
|
7
|
+
|
|
8
|
+
The element never takes the pointer: what is under it is found by the engine's own hit test, in the world, so a stroke
|
|
9
|
+
is picked by its line and not by its box.
|
|
10
|
+
|
|
11
|
+
Each object's element carries `data-canvas-object` (its id) and `data-canvas-object-type`: the hooks tests and pages
|
|
12
|
+
use to find a shape on the board.
|
|
13
|
+
|
|
14
|
+
Where an object stands and what it looks like are kept apart. A drag writes a new record for every object it carries, at
|
|
15
|
+
every step, and a board of hundreds of objects cannot afford to work out the paint, the lines of a text and the style of
|
|
16
|
+
each of them again for that. `look` is the first record of a look, kept for as long as the object only moves (see
|
|
17
|
+
`sameLook`), and everything an element says about the object's appearance is read from it, so a move runs one thing per
|
|
18
|
+
object: the placement.
|
|
19
|
+
-->
|
|
20
|
+
<script lang="ts">
|
|
21
|
+
import { textDirection } from '../../engine/text/layoutText.js';
|
|
22
|
+
import { cornerRadiusOf } from '../../engine/render/rasterize.js';
|
|
23
|
+
import { ERASING_OPACITY } from '../../engine/core/scribble.js';
|
|
24
|
+
import { DEFAULT_WIDGET_RUNTIME } from '../../engine/state.js';
|
|
25
|
+
import type { PendingWidgetState, WidgetRuntime } from '../../engine/state.js';
|
|
26
|
+
import { isBoxedObject } from '../../engine/core/types.js';
|
|
27
|
+
import type { SceneObject } from '../../engine/core/types.js';
|
|
28
|
+
import type { CanvasHost } from '../host/CanvasHost.js';
|
|
29
|
+
import { useCanvasLanguage } from '../../i18n/language.js';
|
|
30
|
+
import { boxSizeCss, placementCss, sameLook, svgPaintOf, textBoxCss } from './geometry.js';
|
|
31
|
+
|
|
32
|
+
interface Props {
|
|
33
|
+
object: SceneObject;
|
|
34
|
+
host: CanvasHost;
|
|
35
|
+
/** What the page said about this card's widget (only read for a widget card). */
|
|
36
|
+
runtime?: WidgetRuntime;
|
|
37
|
+
pending?: PendingWidgetState | undefined;
|
|
38
|
+
/** The words of a widget card, said by the page's name for the widget (changes when the page renames it). */
|
|
39
|
+
nameRevision?: number;
|
|
40
|
+
/** Counts the times fonts finished loading: the lines of a text are drawn again, because letters changed width. */
|
|
41
|
+
fontRevision?: number;
|
|
42
|
+
/** Whether the primary widget's red ring is drawn (only while the page's advanced tools are on). */
|
|
43
|
+
primaryRing?: boolean;
|
|
44
|
+
/** The eraser has marked this shape: it stays where it is, faded, until the pointer is released. */
|
|
45
|
+
erasing?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let {
|
|
49
|
+
object,
|
|
50
|
+
host,
|
|
51
|
+
runtime = DEFAULT_WIDGET_RUNTIME,
|
|
52
|
+
pending = undefined,
|
|
53
|
+
nameRevision = 0,
|
|
54
|
+
fontRevision = 0,
|
|
55
|
+
primaryRing = false,
|
|
56
|
+
erasing = false
|
|
57
|
+
}: Props = $props();
|
|
58
|
+
|
|
59
|
+
// The red of the primary widget's stroke, as the saved boards always drew it.
|
|
60
|
+
const PRIMARY_RING_COLOR = '#DC2626';
|
|
61
|
+
|
|
62
|
+
const { t } = useCanvasLanguage();
|
|
63
|
+
|
|
64
|
+
// The record the object looks like, kept while only its place and turn change: the same record again means that no
|
|
65
|
+
// effect below that reads it runs. (The record's own position is old by then, and never read from here.)
|
|
66
|
+
let lookRecord: SceneObject | null = null;
|
|
67
|
+
const look = $derived.by(() => {
|
|
68
|
+
if (lookRecord === null || !sameLook(lookRecord, object)) lookRecord = object;
|
|
69
|
+
return lookRecord;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Where the box stands: the one thing a move changes. It is set as a style of its own, so a move writes one property and
|
|
73
|
+
// the browser does not read the whole style of the box again.
|
|
74
|
+
const placementOf = (box: SceneObject): string => (isBoxedObject(box) ? placementCss(box) : '');
|
|
75
|
+
// The box's size and the opacity, and for a text the rest of its style: the same string while the object only moves.
|
|
76
|
+
// A shape the eraser has marked is drawn at a third of its own opacity, so it is plain which shapes are about to go.
|
|
77
|
+
const frameStyle = $derived(
|
|
78
|
+
isBoxedObject(look) ? `${boxSizeCss(look)}opacity:${erasing ? look.opacity * ERASING_OPACITY : look.opacity};` : ''
|
|
79
|
+
);
|
|
80
|
+
const textStyle = $derived(look.type === 'text' ? textBoxCss(look) : '');
|
|
81
|
+
|
|
82
|
+
// The name a card shows. Reads the revision so a rename on the page redraws the card.
|
|
83
|
+
const cardName = $derived.by(() => {
|
|
84
|
+
void nameRevision;
|
|
85
|
+
return look.type === 'widget' ? host.widgetLabel(look) : '';
|
|
86
|
+
});
|
|
87
|
+
const cardOrphaned = $derived(look.type === 'widget' ? host.isCardOrphaned(look) : false);
|
|
88
|
+
|
|
89
|
+
// 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
|
+
const textLayout = $derived.by(() => {
|
|
91
|
+
void fontRevision;
|
|
92
|
+
return look.type === 'text' ? host.textLayoutOf(look) : null;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const pendingWords = $derived(
|
|
96
|
+
pending === 'duplicating'
|
|
97
|
+
? $t('canvas.widget.duplicating')
|
|
98
|
+
: pending === 'converting'
|
|
99
|
+
? $t('canvas.widget.converting')
|
|
100
|
+
: pending === 'linking'
|
|
101
|
+
? $t('canvas.widget.linking')
|
|
102
|
+
: ''
|
|
103
|
+
);
|
|
104
|
+
</script>
|
|
105
|
+
|
|
106
|
+
{#if look.type === 'rect'}
|
|
107
|
+
{@const paint = svgPaintOf(look)}
|
|
108
|
+
{@const radius = cornerRadiusOf(look)}
|
|
109
|
+
<svg
|
|
110
|
+
class="pointer-events-none absolute overflow-visible"
|
|
111
|
+
data-canvas-object={look.id}
|
|
112
|
+
data-canvas-object-type={look.type}
|
|
113
|
+
style={frameStyle}
|
|
114
|
+
style:transform={placementOf(object)}
|
|
115
|
+
width={look.width}
|
|
116
|
+
height={look.height}
|
|
117
|
+
aria-hidden="true"
|
|
118
|
+
>
|
|
119
|
+
<rect
|
|
120
|
+
x="0"
|
|
121
|
+
y="0"
|
|
122
|
+
width={look.width}
|
|
123
|
+
height={look.height}
|
|
124
|
+
rx={radius}
|
|
125
|
+
ry={radius}
|
|
126
|
+
fill={paint.fill}
|
|
127
|
+
fill-opacity={paint.fillOpacity}
|
|
128
|
+
stroke={paint.stroke}
|
|
129
|
+
stroke-width={paint.strokeWidth}
|
|
130
|
+
stroke-dasharray={paint.strokeDasharray}
|
|
131
|
+
stroke-linecap={paint.strokeLinecap}
|
|
132
|
+
/>
|
|
133
|
+
</svg>
|
|
134
|
+
{:else if look.type === 'ellipse'}
|
|
135
|
+
{@const paint = svgPaintOf(look)}
|
|
136
|
+
<svg
|
|
137
|
+
class="pointer-events-none absolute overflow-visible"
|
|
138
|
+
data-canvas-object={look.id}
|
|
139
|
+
data-canvas-object-type={look.type}
|
|
140
|
+
style={frameStyle}
|
|
141
|
+
style:transform={placementOf(object)}
|
|
142
|
+
width={look.width}
|
|
143
|
+
height={look.height}
|
|
144
|
+
aria-hidden="true"
|
|
145
|
+
>
|
|
146
|
+
<ellipse
|
|
147
|
+
cx={look.width / 2}
|
|
148
|
+
cy={look.height / 2}
|
|
149
|
+
rx={look.width / 2}
|
|
150
|
+
ry={look.height / 2}
|
|
151
|
+
fill={paint.fill}
|
|
152
|
+
fill-opacity={paint.fillOpacity}
|
|
153
|
+
stroke={paint.stroke}
|
|
154
|
+
stroke-width={paint.strokeWidth}
|
|
155
|
+
stroke-dasharray={paint.strokeDasharray}
|
|
156
|
+
stroke-linecap={paint.strokeLinecap}
|
|
157
|
+
/>
|
|
158
|
+
</svg>
|
|
159
|
+
{:else if look.type === 'path'}
|
|
160
|
+
{@const paint = svgPaintOf(look)}
|
|
161
|
+
<svg
|
|
162
|
+
class="pointer-events-none absolute overflow-visible"
|
|
163
|
+
data-canvas-object={look.id}
|
|
164
|
+
data-canvas-object-type={look.type}
|
|
165
|
+
style={frameStyle}
|
|
166
|
+
style:transform={placementOf(object)}
|
|
167
|
+
width={look.width}
|
|
168
|
+
height={look.height}
|
|
169
|
+
aria-hidden="true"
|
|
170
|
+
>
|
|
171
|
+
<path
|
|
172
|
+
d={look.d}
|
|
173
|
+
fill={paint.fill}
|
|
174
|
+
fill-opacity={paint.fillOpacity}
|
|
175
|
+
stroke={paint.stroke}
|
|
176
|
+
stroke-width={paint.strokeWidth}
|
|
177
|
+
stroke-dasharray={paint.strokeDasharray}
|
|
178
|
+
stroke-linecap={paint.strokeLinecap ?? look.lineCap}
|
|
179
|
+
stroke-linejoin={look.lineJoin}
|
|
180
|
+
/>
|
|
181
|
+
</svg>
|
|
182
|
+
{:else if look.type === 'text' && textLayout}
|
|
183
|
+
<!-- The board is left to right on every screen; a text reads the way its first letter does (Hebrew and Arabic from right to left). -->
|
|
184
|
+
<div
|
|
185
|
+
class="pointer-events-none absolute box-border overflow-visible"
|
|
186
|
+
data-canvas-object={look.id}
|
|
187
|
+
data-canvas-object-type={look.type}
|
|
188
|
+
style="{frameStyle}{textStyle}"
|
|
189
|
+
style:transform={placementOf(object)}
|
|
190
|
+
dir={textDirection(look.text)}
|
|
191
|
+
aria-hidden="true"
|
|
192
|
+
>
|
|
193
|
+
{#each textLayout.lines as line, lineIndex (lineIndex)}
|
|
194
|
+
<div class="whitespace-pre">{line}</div>
|
|
195
|
+
{/each}
|
|
196
|
+
</div>
|
|
197
|
+
{:else if look.type === 'image'}
|
|
198
|
+
<div
|
|
199
|
+
class="pointer-events-none absolute"
|
|
200
|
+
style={frameStyle}
|
|
201
|
+
style:transform={placementOf(object)}
|
|
202
|
+
data-canvas-object={look.id}
|
|
203
|
+
data-canvas-object-type={look.type}
|
|
204
|
+
aria-hidden="true"
|
|
205
|
+
>
|
|
206
|
+
{#if look.src}
|
|
207
|
+
<img class="size-full select-none object-fill" src={look.src} alt="" draggable="false" />
|
|
208
|
+
{:else}
|
|
209
|
+
<!-- The bytes are still coming from the page's store: a quiet block of the same size. -->
|
|
210
|
+
<div class="size-full animate-pulse rounded-sm bg-accent motion-reduce:animate-none"></div>
|
|
211
|
+
{/if}
|
|
212
|
+
</div>
|
|
213
|
+
{:else if look.type === 'widget'}
|
|
214
|
+
<div
|
|
215
|
+
class="pointer-events-none absolute overflow-hidden rounded-lg bg-white"
|
|
216
|
+
style={frameStyle}
|
|
217
|
+
style:transform={placementOf(object)}
|
|
218
|
+
data-widget-card={look.widgetId}
|
|
219
|
+
data-canvas-object={look.id}
|
|
220
|
+
data-canvas-object-type={look.type}
|
|
221
|
+
aria-hidden="true"
|
|
222
|
+
>
|
|
223
|
+
{#if look.thumbnail && !runtime.hiddenImage}
|
|
224
|
+
<img class="size-full select-none object-fill" src={look.thumbnail} alt="" draggable="false" />
|
|
225
|
+
{:else if !runtime.hiddenImage}
|
|
226
|
+
<!-- No screenshot yet: a dashed card with the widget's name, as the saved boards always showed it. -->
|
|
227
|
+
<div
|
|
228
|
+
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"
|
|
229
|
+
>
|
|
230
|
+
<span class="text-[28px] leading-none" aria-hidden="true">{cardOrphaned ? '⚠️' : '🧩'}</span>
|
|
231
|
+
<span class="max-w-full truncate text-sm font-semibold text-slate-800">{cardOrphaned ? $t('canvas.widget.unlinkedName') : cardName}</span>
|
|
232
|
+
<span class="text-xs text-slate-500">{cardOrphaned ? $t('canvas.widget.removeFromCanvas') : $t('canvas.draw.widgetPreview')}</span>
|
|
233
|
+
</div>
|
|
234
|
+
{/if}
|
|
235
|
+
{#if primaryRing && look.isPrimary}
|
|
236
|
+
<div class="absolute inset-0 rounded-lg border-2" style="border-color:{PRIMARY_RING_COLOR};"></div>
|
|
237
|
+
{/if}
|
|
238
|
+
{#if pending}
|
|
239
|
+
<div class="absolute inset-0 flex flex-col items-center justify-center gap-2 bg-white/70" role="status">
|
|
240
|
+
<span class="size-5 animate-spin rounded-full border-2 border-border border-t-primary" aria-hidden="true"></span>
|
|
241
|
+
<span class="text-xs font-medium text-muted-foreground">{pendingWords}</span>
|
|
242
|
+
</div>
|
|
243
|
+
{/if}
|
|
244
|
+
</div>
|
|
245
|
+
{/if}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PendingWidgetState, WidgetRuntime } from '../../engine/state.js';
|
|
2
|
+
import type { SceneObject } from '../../engine/core/types.js';
|
|
3
|
+
import type { CanvasHost } from '../host/CanvasHost.js';
|
|
4
|
+
interface Props {
|
|
5
|
+
object: SceneObject;
|
|
6
|
+
host: CanvasHost;
|
|
7
|
+
/** What the page said about this card's widget (only read for a widget card). */
|
|
8
|
+
runtime?: WidgetRuntime;
|
|
9
|
+
pending?: PendingWidgetState | undefined;
|
|
10
|
+
/** The words of a widget card, said by the page's name for the widget (changes when the page renames it). */
|
|
11
|
+
nameRevision?: number;
|
|
12
|
+
/** Counts the times fonts finished loading: the lines of a text are drawn again, because letters changed width. */
|
|
13
|
+
fontRevision?: number;
|
|
14
|
+
/** Whether the primary widget's red ring is drawn (only while the page's advanced tools are on). */
|
|
15
|
+
primaryRing?: boolean;
|
|
16
|
+
/** The eraser has marked this shape: it stays where it is, faded, until the pointer is released. */
|
|
17
|
+
erasing?: boolean;
|
|
18
|
+
}
|
|
19
|
+
declare const ObjectView: import("svelte").Component<Props, {}, "">;
|
|
20
|
+
type ObjectView = ReturnType<typeof ObjectView>;
|
|
21
|
+
export default ObjectView;
|