@widgetic/canvas 0.5.34 → 0.5.36
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 +454 -0
- package/dist/canvas/DomCanvas.svelte.d.ts +222 -0
- package/dist/canvas/autosaveScheduler.d.ts +58 -0
- package/dist/canvas/autosaveScheduler.js +157 -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 +351 -0
- package/dist/canvas/host/CanvasHost.js +1740 -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 +51 -0
- package/dist/canvas/host/conversion.js +123 -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 +9 -7
- package/dist/canvas/index.js +9 -7
- 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 +24 -0
- package/dist/canvas/toolbarPosition.js +24 -0
- 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 +20 -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 +155 -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 +152 -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 +51 -122
- package/dist/i18n/messages.js +58 -131
- package/dist/i18n/shortcuts.d.ts +0 -1
- package/dist/i18n/shortcuts.js +2 -11
- package/dist/index.d.ts +6 -2
- package/dist/index.js +6 -2
- package/package.json +30 -5
- package/dist/canvas/Canvas.svelte +0 -13299
- package/dist/canvas/Canvas.svelte.d.ts +0 -281
- 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,13 @@
|
|
|
1
|
+
import type { EngineState } from '../../engine/state.js';
|
|
2
|
+
import type { CanvasHost } from '../host/CanvasHost.js';
|
|
3
|
+
interface Props {
|
|
4
|
+
host: CanvasHost;
|
|
5
|
+
state: EngineState;
|
|
6
|
+
gestureKind: string | null;
|
|
7
|
+
advancedFeatures: boolean;
|
|
8
|
+
/** The id or class of the page's element (or the element itself) that stands above its live widgets. */
|
|
9
|
+
target: string | HTMLElement;
|
|
10
|
+
}
|
|
11
|
+
declare const WidgetChromeLayer: import("svelte").Component<Props, {}, "">;
|
|
12
|
+
type WidgetChromeLayer = ReturnType<typeof WidgetChromeLayer>;
|
|
13
|
+
export default WidgetChromeLayer;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Readable } from 'svelte/store';
|
|
2
|
+
import type { ObjectId } from '../../engine/core/types.js';
|
|
3
|
+
/** The set while nothing is marked: one shared set, so that "nothing marked" is the same value every time. */
|
|
4
|
+
export declare const NOTHING_ERASED: ReadonlySet<ObjectId>;
|
|
5
|
+
export interface ErasingMarks extends Readable<ReadonlySet<ObjectId>> {
|
|
6
|
+
/**
|
|
7
|
+
* Takes the list the engine holds (`state.overlay.erasing`). The engine replaces that list when the eraser marks a shape
|
|
8
|
+
* and keeps the very same list in between, so the same list again is nothing new: the set is made again, and the
|
|
9
|
+
* subscribers told, only when the list is a different one.
|
|
10
|
+
*/
|
|
11
|
+
take(marked: readonly ObjectId[]): void;
|
|
12
|
+
}
|
|
13
|
+
export declare function createErasingMarks(): ErasingMarks;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shapes the eraser has marked, as a set that the objects of the board ask ("am I one of them?").
|
|
3
|
+
*
|
|
4
|
+
* It is a store of its own, and not something `CanvasStage` derives from the engine's state, on purpose. The state is a new
|
|
5
|
+
* object at every frame of a pan, a zoom or a drag, and everything derived from it is marked for a check at every one of
|
|
6
|
+
* them, whether its answer changes or not. An object that asked the eraser's list through the state was checked again at
|
|
7
|
+
* every frame (300 objects, about 0.05 ms a frame more on a pan, measured with the stress page), so a pan or a drag with
|
|
8
|
+
* the eraser nowhere near paid for a feature that was not in use. Asked of this store, an object hears of it only when the
|
|
9
|
+
* eraser marks a shape or lets go of one.
|
|
10
|
+
*
|
|
11
|
+
* Plain TypeScript with no Svelte file in it, so that Node can test it.
|
|
12
|
+
*/
|
|
13
|
+
import { writable } from 'svelte/store';
|
|
14
|
+
/** The set while nothing is marked: one shared set, so that "nothing marked" is the same value every time. */
|
|
15
|
+
export const NOTHING_ERASED = new Set();
|
|
16
|
+
export function createErasingMarks() {
|
|
17
|
+
const { subscribe, set } = writable(NOTHING_ERASED);
|
|
18
|
+
let listSeen = null;
|
|
19
|
+
let current = NOTHING_ERASED;
|
|
20
|
+
return {
|
|
21
|
+
subscribe,
|
|
22
|
+
take(marked) {
|
|
23
|
+
if (marked === listSeen)
|
|
24
|
+
return;
|
|
25
|
+
listSeen = marked;
|
|
26
|
+
const next = marked.length === 0 ? NOTHING_ERASED : new Set(marked);
|
|
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
|
+
if (next === current)
|
|
29
|
+
return;
|
|
30
|
+
current = next;
|
|
31
|
+
set(next);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The numbers the board's views are drawn from: where a box stands on the screen, how big the dots of the grid are,
|
|
3
|
+
* which cursor the board shows. Plain functions of the engine's records and the viewport, free of Svelte and the DOM, so
|
|
4
|
+
* a view only writes what they return and Node can test them.
|
|
5
|
+
*/
|
|
6
|
+
import type { ArrowObject } from '../../engine/core/arrow.js';
|
|
7
|
+
import type { Scene } from '../../engine/core/scene.js';
|
|
8
|
+
import type { SelectionFrame } from '../../engine/core/transform.js';
|
|
9
|
+
import type { ObjectId, PaintProps, Point, Rect, SceneObject, ShapeObject, TextObject, Viewport } from '../../engine/core/types.js';
|
|
10
|
+
import type { Readout } from '../../engine/state.js';
|
|
11
|
+
/**
|
|
12
|
+
* The CSS transform that puts a box where it stands in the world layer: its turn about its own middle, then its move.
|
|
13
|
+
* A box that is not turned (nearly every box) is a plain move and is written without any matrix product: this is the one
|
|
14
|
+
* string that is written again for every object a drag carries, at every step of the drag.
|
|
15
|
+
*/
|
|
16
|
+
export declare function placementCss(box: Rect & {
|
|
17
|
+
rotation?: number;
|
|
18
|
+
}): string;
|
|
19
|
+
/** The size of an object's box and the corner it turns about: what its style says apart from where it stands. */
|
|
20
|
+
export declare function boxSizeCss(box: {
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
}): string;
|
|
24
|
+
/** The CSS that puts an object's box where it belongs in the world layer: its size, and its turn about its own middle. */
|
|
25
|
+
export declare function boxStyle(box: Rect & {
|
|
26
|
+
rotation?: number;
|
|
27
|
+
}): string;
|
|
28
|
+
/** What a text's style says apart from its box: the padding, the colours, the font, and how its lines sit in the box. */
|
|
29
|
+
export declare function textBoxCss(text: TextObject): string;
|
|
30
|
+
/**
|
|
31
|
+
* True when two records of an object differ only in where they stand (its position and its turn).
|
|
32
|
+
*
|
|
33
|
+
* A drag writes a new record for every object it carries, at every step, and an object that only moved must not be drawn
|
|
34
|
+
* again: its view keeps the first record of a look to draw from, and only its placement follows the object. Records are
|
|
35
|
+
* flat (strings, numbers, flags), so a field is compared by value.
|
|
36
|
+
*/
|
|
37
|
+
export declare function sameLook(first: SceneObject, second: SceneObject): boolean;
|
|
38
|
+
/** What a vector shape is painted with, as the attributes of an SVG element. */
|
|
39
|
+
export interface SvgPaint {
|
|
40
|
+
fill: string;
|
|
41
|
+
fillOpacity: number;
|
|
42
|
+
stroke: string;
|
|
43
|
+
strokeWidth: number;
|
|
44
|
+
strokeDasharray: string | undefined;
|
|
45
|
+
strokeLinecap: 'butt' | 'round' | 'square' | undefined;
|
|
46
|
+
}
|
|
47
|
+
/** A colour of `transparent` (or a stroke with no width) is "none" in SVG. */
|
|
48
|
+
export declare function svgPaintOf(shape: PaintProps): SvgPaint;
|
|
49
|
+
/** Where a frame stands on the screen: the box before its turn, and the turn. */
|
|
50
|
+
export interface ScreenFrame {
|
|
51
|
+
/** Pixels from the left and top of the board to the top-left corner of the box before it is turned. */
|
|
52
|
+
left: number;
|
|
53
|
+
top: number;
|
|
54
|
+
width: number;
|
|
55
|
+
height: number;
|
|
56
|
+
rotation: number;
|
|
57
|
+
/** Where the middle of the box is. */
|
|
58
|
+
centerX: number;
|
|
59
|
+
centerY: number;
|
|
60
|
+
}
|
|
61
|
+
export declare function screenFrameOf(frame: SelectionFrame | (Rect & {
|
|
62
|
+
rotation: number;
|
|
63
|
+
}), viewport: Viewport): ScreenFrame;
|
|
64
|
+
/**
|
|
65
|
+
* The CSS that places a box in a layer that covers the board, in pixels from the layer's top left corner.
|
|
66
|
+
*
|
|
67
|
+
* The board is a drawing, not a line of text: what is at its left stays at its left on every screen, so a position here is
|
|
68
|
+
* a physical distance from the left edge, and is not written with the start of the line.
|
|
69
|
+
*/
|
|
70
|
+
export declare function layerBoxStyle(box: {
|
|
71
|
+
left: number;
|
|
72
|
+
top: number;
|
|
73
|
+
width?: number;
|
|
74
|
+
height?: number;
|
|
75
|
+
}): string;
|
|
76
|
+
/** The CSS that puts a box of `width` by `height` (a square when only `width` is given) with its middle on a point of the layer that covers the board. */
|
|
77
|
+
export declare function layerCenteredStyle(center: Point, width: number, height?: number): string;
|
|
78
|
+
/** The CSS that places a point of the layer that covers the board (the corner a label starts from). */
|
|
79
|
+
export declare function layerPointStyle(point: Point): string;
|
|
80
|
+
/**
|
|
81
|
+
* Where the outline of an arrow goes in a layer that covers the board: the CSS that puts the corner of its box where the box is
|
|
82
|
+
* on the screen, and the scale from the coordinates of its path to pixels.
|
|
83
|
+
*/
|
|
84
|
+
export declare function arrowOutlinePlacement(box: Rect, viewport: Viewport): {
|
|
85
|
+
style: string;
|
|
86
|
+
scale: number;
|
|
87
|
+
};
|
|
88
|
+
/** The CSS that places a screen frame in a layer that covers the board. */
|
|
89
|
+
export declare function screenFrameStyle(frame: ScreenFrame): string;
|
|
90
|
+
/**
|
|
91
|
+
* What the figure in the middle of a selection says: a size as `450 × 149`, an angle as `35°`. Numbers and signs, no
|
|
92
|
+
* words, so it needs no translation (the page that shows it sets its direction to left to right, so the order holds).
|
|
93
|
+
*/
|
|
94
|
+
export declare function formatReadout(readout: Readout): string;
|
|
95
|
+
/**
|
|
96
|
+
* Where the size label sits at rest: centred like the resize readout, or null when the frame is too small.
|
|
97
|
+
* The label never sits outside the selection frame (rotation dot lives below).
|
|
98
|
+
*/
|
|
99
|
+
export declare function restingSizeLabelPoint(frame: ScreenFrame, text: string, margin?: number): Point | null;
|
|
100
|
+
/** A point at `distance` pixels below the bottom edge of a turned frame, in the middle of that edge: where the size label goes. */
|
|
101
|
+
export declare function pointBelowFrame(frame: ScreenFrame, distance: number): Point;
|
|
102
|
+
/**
|
|
103
|
+
* The outline to draw around a unit (a shape, or a group with all of its members): the shape's own turned box for one
|
|
104
|
+
* shape, the upright rectangle around the members for a group.
|
|
105
|
+
*/
|
|
106
|
+
export declare function outlineOfUnit(scene: Scene, id: ObjectId): (Rect & {
|
|
107
|
+
rotation: number;
|
|
108
|
+
}) | null;
|
|
109
|
+
/**
|
|
110
|
+
* What is drawn round the units a marquee would take: the box of each shape or group as it stands on the screen, and each
|
|
111
|
+
* arrow by itself (an arrow is outlined along its line, as it is when the pointer is over it).
|
|
112
|
+
*/
|
|
113
|
+
export interface MarqueeOutlines {
|
|
114
|
+
frames: readonly {
|
|
115
|
+
id: ObjectId;
|
|
116
|
+
frame: ScreenFrame;
|
|
117
|
+
}[];
|
|
118
|
+
arrows: readonly ArrowObject[];
|
|
119
|
+
}
|
|
120
|
+
/** What a marquee that takes nothing draws: the one shared empty answer, so a derived value that holds it stays the same. */
|
|
121
|
+
export declare const NO_MARQUEE_OUTLINES: MarqueeOutlines;
|
|
122
|
+
/**
|
|
123
|
+
* The outlines of the units a marquee would take, in the order given (paint order). One pass over the scene finds the units,
|
|
124
|
+
* so a marquee over the whole board costs one more pass for every group in it and no more for a shape.
|
|
125
|
+
*/
|
|
126
|
+
export declare function marqueeOutlinesOf(scene: Scene, ids: readonly ObjectId[], viewport: Viewport): MarqueeOutlines;
|
|
127
|
+
/**
|
|
128
|
+
* The line a marquee draws round each unit it would take, written as the data of two SVG paths and not as one element per unit:
|
|
129
|
+
* over a board of three hundred an element each would be three hundred elements made as the rectangle grows and destroyed all
|
|
130
|
+
* at once in the frame of the release, with the work of a Svelte block for every one of them, where the paths are two elements
|
|
131
|
+
* whatever the count.
|
|
132
|
+
*
|
|
133
|
+
* `upright` holds the boxes that are not turned, `turned` the boxes that are. Both are one line of 1 px just outside the edge
|
|
134
|
+
* of the box, as the outline of a unit under the pointer is.
|
|
135
|
+
*/
|
|
136
|
+
export interface OutlinePaths {
|
|
137
|
+
upright: string;
|
|
138
|
+
turned: string;
|
|
139
|
+
}
|
|
140
|
+
/** What a marquee that takes nothing draws: the one shared empty answer. */
|
|
141
|
+
export declare const NO_OUTLINE_PATHS: OutlinePaths;
|
|
142
|
+
/**
|
|
143
|
+
* The paths of the outlines of some frames, in the order given.
|
|
144
|
+
*
|
|
145
|
+
* A box that is not turned is snapped to whole pixels the way the browser snaps the box of an element (its left and top, and its
|
|
146
|
+
* right and bottom), so a line of 1 px lies on the pixels just outside the edge, as the outline of an element does; the path
|
|
147
|
+
* is drawn with crisp edges for the same reason. A box that is turned is four corners, drawn smooth. A frame with a number
|
|
148
|
+
* that is not finite is left out: one such number would spoil the whole path.
|
|
149
|
+
*/
|
|
150
|
+
export declare function outlinePathsOf(frames: readonly {
|
|
151
|
+
frame: ScreenFrame;
|
|
152
|
+
}[]): OutlinePaths;
|
|
153
|
+
/** The rectangle around a shape as the board shows it: for a shape that is turned, the box that holds its corners. */
|
|
154
|
+
export declare function upright(shape: ShapeObject): Rect;
|
|
155
|
+
/**
|
|
156
|
+
* The dot grid under the objects (Figma "Dot Grid": a dot every 24 world units, 2 pixels across, the ink colour at 30%).
|
|
157
|
+
* It moves and scales with the world, and doubles its step while the dots would be closer than 12 pixels.
|
|
158
|
+
*/
|
|
159
|
+
export declare const DOT_GRID_STEP = 24;
|
|
160
|
+
/**
|
|
161
|
+
* One dot in the middle of a cell, as a gradient: it takes its colour from the page's `foreground` token (a data URL
|
|
162
|
+
* cannot), stays two pixels across at every zoom, and costs one background layer however large the board is.
|
|
163
|
+
*/
|
|
164
|
+
export declare const DOT_GRID_IMAGE = "radial-gradient(circle at 50% 50%, color-mix(in srgb, var(--foreground, #0f172a) 30%, transparent) 0, color-mix(in srgb, var(--foreground, #0f172a) 30%, transparent) 1px, transparent 1.5px)";
|
|
165
|
+
export declare function dotGridStyle(viewport: Viewport): string;
|
|
166
|
+
/** The CSS `cursor` for what the engine asked the board to show. */
|
|
167
|
+
export declare function cssCursor(cursor: string): string;
|
|
168
|
+
/** The board's own colour under the dots (one constant, shared with the placeholder: see boardSurface.ts). */
|
|
169
|
+
export { BOARD_SURFACE_COLOR } from '../boardSurface.js';
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The numbers the board's views are drawn from: where a box stands on the screen, how big the dots of the grid are,
|
|
3
|
+
* which cursor the board shows. Plain functions of the engine's records and the viewport, free of Svelte and the DOM, so
|
|
4
|
+
* a view only writes what they return and Node can test them.
|
|
5
|
+
*/
|
|
6
|
+
import { isArrow } from '../../engine/core/arrow.js';
|
|
7
|
+
import { strokeDashArray } from '../../engine/core/defaults.js';
|
|
8
|
+
import { boxToWorldMatrix, degreesToRadians, matrixToCss } from '../../engine/core/matrix.js';
|
|
9
|
+
import { boundsOfObjects, shapeBounds } from '../../engine/core/scene.js';
|
|
10
|
+
import { worldToScreen } from '../../engine/core/viewport.js';
|
|
11
|
+
import { ROTATE_CURSOR } from '../../engine/input/selectionHandles.js';
|
|
12
|
+
import { fontShorthand } from '../../engine/text/layoutText.js';
|
|
13
|
+
/**
|
|
14
|
+
* The CSS transform that puts a box where it stands in the world layer: its turn about its own middle, then its move.
|
|
15
|
+
* A box that is not turned (nearly every box) is a plain move and is written without any matrix product: this is the one
|
|
16
|
+
* string that is written again for every object a drag carries, at every step of the drag.
|
|
17
|
+
*/
|
|
18
|
+
export function placementCss(box) {
|
|
19
|
+
if (!box.rotation)
|
|
20
|
+
return `matrix(1, 0, 0, 1, ${Number(box.x.toFixed(5))}, ${Number(box.y.toFixed(5))})`;
|
|
21
|
+
return matrixToCss(boxToWorldMatrix(box));
|
|
22
|
+
}
|
|
23
|
+
/** The size of an object's box and the corner it turns about: what its style says apart from where it stands. */
|
|
24
|
+
export function boxSizeCss(box) {
|
|
25
|
+
return `left:0;top:0;width:${trim(box.width)}px;height:${trim(box.height)}px;transform-origin:0 0;`;
|
|
26
|
+
}
|
|
27
|
+
/** The CSS that puts an object's box where it belongs in the world layer: its size, and its turn about its own middle. */
|
|
28
|
+
export function boxStyle(box) {
|
|
29
|
+
return `${boxSizeCss(box)}transform:${placementCss(box)};`;
|
|
30
|
+
}
|
|
31
|
+
/** What a text's style says apart from its box: the padding, the colours, the font, and how its lines sit in the box. */
|
|
32
|
+
export function textBoxCss(text) {
|
|
33
|
+
return `padding:${text.padding}px;background-color:${text.backgroundColor};color:${text.color};font:${fontShorthand(text)};line-height:${text.lineHeight};text-align:${text.align};${text.underline ? 'text-decoration:underline;' : ''}`;
|
|
34
|
+
}
|
|
35
|
+
/** The fields of a record that say where an object stands; every other field says what it looks like. */
|
|
36
|
+
const PLACEMENT_FIELDS = new Set(['x', 'y', 'rotation']);
|
|
37
|
+
/**
|
|
38
|
+
* True when two records of an object differ only in where they stand (its position and its turn).
|
|
39
|
+
*
|
|
40
|
+
* A drag writes a new record for every object it carries, at every step, and an object that only moved must not be drawn
|
|
41
|
+
* again: its view keeps the first record of a look to draw from, and only its placement follows the object. Records are
|
|
42
|
+
* flat (strings, numbers, flags), so a field is compared by value.
|
|
43
|
+
*/
|
|
44
|
+
export function sameLook(first, second) {
|
|
45
|
+
if (first === second)
|
|
46
|
+
return true;
|
|
47
|
+
if (first.type !== second.type)
|
|
48
|
+
return false;
|
|
49
|
+
const before = first;
|
|
50
|
+
const after = second;
|
|
51
|
+
for (const key in after) {
|
|
52
|
+
if (!PLACEMENT_FIELDS.has(key) && before[key] !== after[key])
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
// A field that was dropped is a change too (a record with the same fields never takes this loop further).
|
|
56
|
+
for (const key in before) {
|
|
57
|
+
if (!PLACEMENT_FIELDS.has(key) && !(key in after))
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
/** A colour of `transparent` (or a stroke with no width) is "none" in SVG. */
|
|
63
|
+
export function svgPaintOf(shape) {
|
|
64
|
+
const hasStroke = shape.stroke !== 'transparent' && shape.strokeWidth > 0;
|
|
65
|
+
const dash = hasStroke ? strokeDashArray(shape.strokeStyle, shape.strokeWidth) : null;
|
|
66
|
+
return {
|
|
67
|
+
fill: shape.fill === 'transparent' ? 'none' : shape.fill,
|
|
68
|
+
fillOpacity: shape.fillOpacity,
|
|
69
|
+
stroke: hasStroke ? shape.stroke : 'none',
|
|
70
|
+
strokeWidth: hasStroke ? shape.strokeWidth : 0,
|
|
71
|
+
strokeDasharray: dash && dash.length > 0 ? dash.join(' ') : undefined,
|
|
72
|
+
// A dotted line is zero-length dashes: only a round cap turns each into a dot.
|
|
73
|
+
strokeLinecap: shape.strokeStyle === 'dotted' ? 'round' : undefined
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export function screenFrameOf(frame, viewport) {
|
|
77
|
+
const center = worldToScreen(viewport, { x: frame.x + frame.width / 2, y: frame.y + frame.height / 2 });
|
|
78
|
+
const width = frame.width * viewport.zoom;
|
|
79
|
+
const height = frame.height * viewport.zoom;
|
|
80
|
+
return { left: center.x - width / 2, top: center.y - height / 2, width, height, rotation: frame.rotation, centerX: center.x, centerY: center.y };
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The CSS that places a box in a layer that covers the board, in pixels from the layer's top left corner.
|
|
84
|
+
*
|
|
85
|
+
* The board is a drawing, not a line of text: what is at its left stays at its left on every screen, so a position here is
|
|
86
|
+
* a physical distance from the left edge, and is not written with the start of the line.
|
|
87
|
+
*/
|
|
88
|
+
export function layerBoxStyle(box) {
|
|
89
|
+
const size = (box.width === undefined ? '' : `width:${trim(box.width)}px;`) + (box.height === undefined ? '' : `height:${trim(box.height)}px;`);
|
|
90
|
+
// rtl-ok: a place on the drawing, measured from the left edge of the layer on every screen
|
|
91
|
+
return `left:${trim(box.left)}px;top:${trim(box.top)}px;${size}`;
|
|
92
|
+
}
|
|
93
|
+
/** The CSS that puts a box of `width` by `height` (a square when only `width` is given) with its middle on a point of the layer that covers the board. */
|
|
94
|
+
export function layerCenteredStyle(center, width, height = width) {
|
|
95
|
+
// rtl-ok: a place on the drawing, measured from the left edge of the layer on every screen
|
|
96
|
+
return layerBoxStyle({ left: center.x - width / 2, top: center.y - height / 2, width, height });
|
|
97
|
+
}
|
|
98
|
+
/** The CSS that places a point of the layer that covers the board (the corner a label starts from). */
|
|
99
|
+
export function layerPointStyle(point) {
|
|
100
|
+
return layerBoxStyle({ left: point.x, top: point.y });
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Where the outline of an arrow goes in a layer that covers the board: the CSS that puts the corner of its box where the box is
|
|
104
|
+
* on the screen, and the scale from the coordinates of its path to pixels.
|
|
105
|
+
*/
|
|
106
|
+
export function arrowOutlinePlacement(box, viewport) {
|
|
107
|
+
const corner = worldToScreen(viewport, { x: box.x, y: box.y });
|
|
108
|
+
return { style: layerBoxStyle({ left: corner.x, top: corner.y }), scale: viewport.zoom };
|
|
109
|
+
}
|
|
110
|
+
/** The CSS that places a screen frame in a layer that covers the board. */
|
|
111
|
+
export function screenFrameStyle(frame) {
|
|
112
|
+
const turn = frame.rotation === 0 ? '' : `transform:rotate(${trim(frame.rotation)}deg);`;
|
|
113
|
+
return `${layerBoxStyle(frame)}${turn}`;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* What the figure in the middle of a selection says: a size as `450 × 149`, an angle as `35°`. Numbers and signs, no
|
|
117
|
+
* words, so it needs no translation (the page that shows it sets its direction to left to right, so the order holds).
|
|
118
|
+
*/
|
|
119
|
+
export function formatReadout(readout) {
|
|
120
|
+
return readout.kind === 'size' ? `${readout.width} × ${readout.height}` : `${readout.degrees}°`;
|
|
121
|
+
}
|
|
122
|
+
/** Rough size of the centred size label (px-1.5 py-0.5 text-xs), used to keep it inside the frame. */
|
|
123
|
+
const SIZE_LABEL_CHAR_PX = 7.5;
|
|
124
|
+
const SIZE_LABEL_PAD_X = 12;
|
|
125
|
+
const SIZE_LABEL_HEIGHT = 22;
|
|
126
|
+
/**
|
|
127
|
+
* Where the size label sits at rest: centred like the resize readout, or null when the frame is too small.
|
|
128
|
+
* The label never sits outside the selection frame (rotation dot lives below).
|
|
129
|
+
*/
|
|
130
|
+
export function restingSizeLabelPoint(frame, text, margin = 4) {
|
|
131
|
+
const width = text.length * SIZE_LABEL_CHAR_PX + SIZE_LABEL_PAD_X;
|
|
132
|
+
if (frame.width < width + margin * 2 || frame.height < SIZE_LABEL_HEIGHT + margin * 2)
|
|
133
|
+
return null;
|
|
134
|
+
return { x: frame.centerX, y: frame.centerY };
|
|
135
|
+
}
|
|
136
|
+
/** A point at `distance` pixels below the bottom edge of a turned frame, in the middle of that edge: where the size label goes. */
|
|
137
|
+
export function pointBelowFrame(frame, distance) {
|
|
138
|
+
const radians = degreesToRadians(frame.rotation);
|
|
139
|
+
const reach = frame.height / 2 + distance;
|
|
140
|
+
return { x: frame.centerX - Math.sin(radians) * reach, y: frame.centerY + Math.cos(radians) * reach };
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* The outline to draw around a unit (a shape, or a group with all of its members): the shape's own turned box for one
|
|
144
|
+
* shape, the upright rectangle around the members for a group.
|
|
145
|
+
*/
|
|
146
|
+
export function outlineOfUnit(scene, id) {
|
|
147
|
+
const object = scene.find((candidate) => candidate.id === id);
|
|
148
|
+
if (!object)
|
|
149
|
+
return null;
|
|
150
|
+
if (object.type !== 'group') {
|
|
151
|
+
const shape = object;
|
|
152
|
+
return { x: shape.x, y: shape.y, width: shape.width, height: shape.height, rotation: shape.rotation };
|
|
153
|
+
}
|
|
154
|
+
const bounds = boundsOfObjects(scene, [id]);
|
|
155
|
+
return bounds ? { ...bounds, rotation: 0 } : null;
|
|
156
|
+
}
|
|
157
|
+
/** What a marquee that takes nothing draws: the one shared empty answer, so a derived value that holds it stays the same. */
|
|
158
|
+
export const NO_MARQUEE_OUTLINES = Object.freeze({ frames: Object.freeze([]), arrows: Object.freeze([]) });
|
|
159
|
+
/**
|
|
160
|
+
* The outlines of the units a marquee would take, in the order given (paint order). One pass over the scene finds the units,
|
|
161
|
+
* so a marquee over the whole board costs one more pass for every group in it and no more for a shape.
|
|
162
|
+
*/
|
|
163
|
+
export function marqueeOutlinesOf(scene, ids, viewport) {
|
|
164
|
+
if (ids.length === 0)
|
|
165
|
+
return NO_MARQUEE_OUTLINES;
|
|
166
|
+
const wanted = new Set(ids);
|
|
167
|
+
const found = new Map();
|
|
168
|
+
for (const object of scene) {
|
|
169
|
+
if (wanted.has(object.id))
|
|
170
|
+
found.set(object.id, object);
|
|
171
|
+
}
|
|
172
|
+
const frames = [];
|
|
173
|
+
const arrows = [];
|
|
174
|
+
for (const id of ids) {
|
|
175
|
+
const object = found.get(id);
|
|
176
|
+
if (!object)
|
|
177
|
+
continue;
|
|
178
|
+
if (object.type === 'path' && isArrow(object)) {
|
|
179
|
+
arrows.push(object);
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
const outline = object.type === 'group' ? outlineOfUnit(scene, id) : { x: object.x, y: object.y, width: object.width, height: object.height, rotation: object.rotation };
|
|
183
|
+
if (outline)
|
|
184
|
+
frames.push({ id, frame: screenFrameOf(outline, viewport) });
|
|
185
|
+
}
|
|
186
|
+
return frames.length === 0 && arrows.length === 0 ? NO_MARQUEE_OUTLINES : { frames, arrows };
|
|
187
|
+
}
|
|
188
|
+
/** What a marquee that takes nothing draws: the one shared empty answer. */
|
|
189
|
+
export const NO_OUTLINE_PATHS = Object.freeze({ upright: '', turned: '' });
|
|
190
|
+
/** Half the width of the line, in pixels: the line is centred this far outside the edge, so it covers the pixel just outside it. */
|
|
191
|
+
const OUTLINE_HALF_WIDTH = 0.5;
|
|
192
|
+
/**
|
|
193
|
+
* The paths of the outlines of some frames, in the order given.
|
|
194
|
+
*
|
|
195
|
+
* A box that is not turned is snapped to whole pixels the way the browser snaps the box of an element (its left and top, and its
|
|
196
|
+
* right and bottom), so a line of 1 px lies on the pixels just outside the edge, as the outline of an element does; the path
|
|
197
|
+
* is drawn with crisp edges for the same reason. A box that is turned is four corners, drawn smooth. A frame with a number
|
|
198
|
+
* that is not finite is left out: one such number would spoil the whole path.
|
|
199
|
+
*/
|
|
200
|
+
export function outlinePathsOf(frames) {
|
|
201
|
+
if (frames.length === 0)
|
|
202
|
+
return NO_OUTLINE_PATHS;
|
|
203
|
+
let upright = '';
|
|
204
|
+
let turned = '';
|
|
205
|
+
for (const { frame } of frames) {
|
|
206
|
+
if (!Number.isFinite(frame.left + frame.top + frame.width + frame.height + frame.rotation))
|
|
207
|
+
continue;
|
|
208
|
+
if (frame.rotation === 0) {
|
|
209
|
+
const left = Math.round(frame.left);
|
|
210
|
+
const top = Math.round(frame.top);
|
|
211
|
+
const reachRight = Math.round(frame.left + frame.width) - left + 2 * OUTLINE_HALF_WIDTH;
|
|
212
|
+
const reachDown = Math.round(frame.top + frame.height) - top + 2 * OUTLINE_HALF_WIDTH;
|
|
213
|
+
upright += `M${left - OUTLINE_HALF_WIDTH} ${top - OUTLINE_HALF_WIDTH}h${reachRight}v${reachDown}h${-reachRight}z`;
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
const radians = degreesToRadians(frame.rotation);
|
|
217
|
+
const cosine = Math.cos(radians);
|
|
218
|
+
const sine = Math.sin(radians);
|
|
219
|
+
const halfWidth = frame.width / 2 + OUTLINE_HALF_WIDTH;
|
|
220
|
+
const halfHeight = frame.height / 2 + OUTLINE_HALF_WIDTH;
|
|
221
|
+
// The four corners of the box grown by half the width of the line, turned about the middle of the box (clockwise, as CSS turns).
|
|
222
|
+
const corners = [
|
|
223
|
+
[-halfWidth, -halfHeight],
|
|
224
|
+
[halfWidth, -halfHeight],
|
|
225
|
+
[halfWidth, halfHeight],
|
|
226
|
+
[-halfWidth, halfHeight]
|
|
227
|
+
];
|
|
228
|
+
turned += corners
|
|
229
|
+
.map(([cornerX, cornerY], index) => {
|
|
230
|
+
const x = frame.centerX + cornerX * cosine - cornerY * sine;
|
|
231
|
+
const y = frame.centerY + cornerX * sine + cornerY * cosine;
|
|
232
|
+
return `${index === 0 ? 'M' : 'L'}${Math.round(x * 100) / 100} ${Math.round(y * 100) / 100}`;
|
|
233
|
+
})
|
|
234
|
+
.join('');
|
|
235
|
+
turned += 'z';
|
|
236
|
+
}
|
|
237
|
+
return upright === '' && turned === '' ? NO_OUTLINE_PATHS : { upright, turned };
|
|
238
|
+
}
|
|
239
|
+
/** The rectangle around a shape as the board shows it: for a shape that is turned, the box that holds its corners. */
|
|
240
|
+
export function upright(shape) {
|
|
241
|
+
return shapeBounds(shape);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* The dot grid under the objects (Figma "Dot Grid": a dot every 24 world units, 2 pixels across, the ink colour at 30%).
|
|
245
|
+
* It moves and scales with the world, and doubles its step while the dots would be closer than 12 pixels.
|
|
246
|
+
*/
|
|
247
|
+
export const DOT_GRID_STEP = 24;
|
|
248
|
+
const DOT_GRID_MIN_SCREEN_STEP = 12;
|
|
249
|
+
/**
|
|
250
|
+
* One dot in the middle of a cell, as a gradient: it takes its colour from the page's `foreground` token (a data URL
|
|
251
|
+
* cannot), stays two pixels across at every zoom, and costs one background layer however large the board is.
|
|
252
|
+
*/
|
|
253
|
+
export const DOT_GRID_IMAGE = 'radial-gradient(circle at 50% 50%, color-mix(in srgb, var(--foreground, #0f172a) 30%, transparent) 0, color-mix(in srgb, var(--foreground, #0f172a) 30%, transparent) 1px, transparent 1.5px)';
|
|
254
|
+
export function dotGridStyle(viewport) {
|
|
255
|
+
let step = DOT_GRID_STEP;
|
|
256
|
+
while (step * viewport.zoom < DOT_GRID_MIN_SCREEN_STEP)
|
|
257
|
+
step *= 2;
|
|
258
|
+
const size = step * viewport.zoom;
|
|
259
|
+
// The cells follow the world origin, and the dot is in the middle of each, as in the design.
|
|
260
|
+
return `background-image:${DOT_GRID_IMAGE};background-size:${trim(size)}px ${trim(size)}px;background-position:${trim(viewport.x)}px ${trim(viewport.y)}px;`;
|
|
261
|
+
}
|
|
262
|
+
/** The pointer of the board has a name for the turning handle that CSS does not know: it is drawn as a small arc with an arrowhead. */
|
|
263
|
+
const ROTATE_CURSOR_CSS = "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%230f2010' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 11a8 8 0 1 0-2.3 5.7'/%3E%3Cpath d='M20 4v7h-7'/%3E%3C/svg%3E\") 12 12, grab";
|
|
264
|
+
/** The CSS `cursor` for what the engine asked the board to show. */
|
|
265
|
+
export function cssCursor(cursor) {
|
|
266
|
+
return cursor === ROTATE_CURSOR ? ROTATE_CURSOR_CSS : cursor;
|
|
267
|
+
}
|
|
268
|
+
/** The board's own colour under the dots (one constant, shared with the placeholder: see boardSurface.ts). */
|
|
269
|
+
export { BOARD_SURFACE_COLOR } from '../boardSurface.js';
|
|
270
|
+
function trim(value) {
|
|
271
|
+
return Number(value.toFixed(3));
|
|
272
|
+
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
<script module lang="ts">
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { BOARD_SURFACE_COLOR } from '../canvas/boardSurface.js';
|
|
3
|
+
|
|
4
|
+
/** Colour of an empty board: the design system's `muted` token, the same the board is painted with. */
|
|
5
|
+
export const CANVAS_BOARD_BACKGROUND = BOARD_SURFACE_COLOR;
|
|
4
6
|
</script>
|
|
5
7
|
|
|
6
8
|
<script lang="ts">
|
|
7
9
|
import { provideCanvasLanguage, useCanvasLanguage } from '../i18n/language.js';
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
|
-
* The empty board, drawn
|
|
12
|
+
* The empty board, drawn before the canvas itself is there.
|
|
11
13
|
*
|
|
12
14
|
* A host shows it while the canvas code is still downloading, so the page
|
|
13
15
|
* has its board at first paint. The real canvas replaces it with the same
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/** Colour of an empty board
|
|
2
|
-
export declare const CANVAS_BOARD_BACKGROUND = "#
|
|
1
|
+
/** Colour of an empty board: the design system's `muted` token, the same the board is painted with. */
|
|
2
|
+
export declare const CANVAS_BOARD_BACKGROUND = "var(--muted, #f5f5f5)";
|
|
3
3
|
/**
|
|
4
|
-
* The empty board, drawn
|
|
4
|
+
* The empty board, drawn before the canvas itself is there.
|
|
5
5
|
*
|
|
6
6
|
* A host shows it while the canvas code is still downloading, so the page
|
|
7
7
|
* has its board at first paint. The real canvas replaces it with the same
|
package/dist/components/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
// General Components
|
|
7
7
|
export { default as Tooltip } from './Tooltip.svelte';
|
|
8
|
-
// The empty board
|
|
8
|
+
// The empty board: shown while the canvas code downloads
|
|
9
9
|
export { default as CanvasBoardPlaceholder, CANVAS_BOARD_BACKGROUND } from './CanvasBoardPlaceholder.svelte';
|
|
10
10
|
// Where the canvas keeps a visitor's choices (the host can install a store of its own)
|
|
11
11
|
export { setCanvasPreferenceStorage, getCanvasPreferenceStorage } from './preferenceStorage';
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
// Hide the color picker swatch + hex input row (show only label + presets)
|
|
26
26
|
export let showPicker: boolean = true;
|
|
27
27
|
|
|
28
|
-
// Storage key for custom presets (shared across all instances)
|
|
29
|
-
const PRESETS_STORAGE_KEY = '
|
|
28
|
+
// Storage key for custom presets (shared across all instances).
|
|
29
|
+
const PRESETS_STORAGE_KEY = 'widgetic-canvas-color-presets';
|
|
30
30
|
|
|
31
31
|
// Default color presets (cannot be deleted)
|
|
32
32
|
const defaultPresets = [
|