@widgetic/canvas 0.5.41 → 0.5.42
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/dist/canvas/autosaveScheduler.js +37 -89
- package/dist/canvas/boardFrame.js +1 -1
- package/dist/canvas/boardSurface.js +1 -1
- package/dist/canvas/canvasLogger.js +7 -19
- package/dist/canvas/chromeLayout.js +17 -18
- package/dist/canvas/eventScope.js +10 -14
- package/dist/canvas/host/CanvasHost.js +1286 -1536
- 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/pageEvents.js +4 -4
- package/dist/canvas/host/screenRects.js +28 -31
- package/dist/canvas/host/strokeSnap.js +88 -143
- package/dist/canvas/openMarks.js +2 -2
- package/dist/canvas/outsideClickDeselect.js +6 -7
- package/dist/canvas/panZoomPosition.js +2 -2
- package/dist/canvas/preferredTextFont.js +13 -25
- package/dist/canvas/shapes/ShapeLibrary.js +138 -148
- package/dist/canvas/shapes/shapeImageStore.js +3 -3
- package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
- package/dist/canvas/toolbarPosition.js +2 -2
- package/dist/canvas/ui/colorModel.js +21 -32
- package/dist/canvas/ui/colorPickerMessages.js +5 -5
- package/dist/canvas/ui/floatingCard.js +18 -18
- package/dist/canvas/ui/floatingLayer.js +5 -6
- package/dist/canvas/ui/keyHints.js +9 -11
- package/dist/canvas/ui/popoverSide.js +2 -3
- package/dist/canvas/ui/selectionTraits.js +34 -40
- package/dist/canvas/view/erasingMarks.js +7 -7
- package/dist/canvas/view/geometry.js +71 -90
- package/dist/components/preferenceStorage.js +2 -2
- package/dist/engine/EngineCore.js +696 -795
- package/dist/engine/codec/canvasDocument.js +183 -147
- 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.js +33 -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.js +129 -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.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 +262 -308
- 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.js +4 -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.js +17 -68
- package/dist/fonts/workspaceFonts.js +32 -90
- package/dist/i18n/labels.js +4 -4
- package/dist/i18n/language.js +4 -4
- package/dist/i18n/messages.js +1 -1
- package/dist/i18n/shortcuts.js +14 -14
- package/dist/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
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { CHROME_ANCHORS, normalizeAnchor } from './chromeLayout.js';
|
|
13
13
|
/** The places the toolbar can stand: `TL TC TR` (top), `CL CR` (the sides) and `BL BC BR` (bottom). */
|
|
14
|
-
export
|
|
14
|
+
export const TOOLBAR_POSITIONS = CHROME_ANCHORS;
|
|
15
15
|
/** Where the toolbar stands when the host says nothing: the bottom centre, as it always did. */
|
|
16
|
-
export
|
|
16
|
+
export const DEFAULT_TOOLBAR_POSITION = 'BC';
|
|
17
17
|
/**
|
|
18
18
|
* The position to use for what a host passed. Anything that is not one of the eight (the middle of the board, a word in
|
|
19
19
|
* lower case, nothing at all) is the default, so that a mistake in the host's option never takes the toolbar off the
|
|
@@ -5,17 +5,8 @@
|
|
|
5
5
|
* and the panel has to show it and to take what a person types. Plain functions, free of Svelte and of the DOM, so Node
|
|
6
6
|
* can test them.
|
|
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
|
/** The colours the panel offers first, one click each. The first two are the board's own ink and paper. */
|
|
18
|
-
export
|
|
9
|
+
export const COLOR_PRESETS = [
|
|
19
10
|
'#0F172A',
|
|
20
11
|
'#FFFFFF',
|
|
21
12
|
'#EF4444',
|
|
@@ -27,61 +18,59 @@ export var COLOR_PRESETS = [
|
|
|
27
18
|
'#EC4899',
|
|
28
19
|
'#6B7280'
|
|
29
20
|
];
|
|
30
|
-
|
|
21
|
+
const HEX_PATTERN = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
31
22
|
/** True for a colour that paints nothing: `transparent`, or a colour that is fully see-through. */
|
|
32
23
|
export function isNoColor(color) {
|
|
33
24
|
if (!color)
|
|
34
25
|
return true;
|
|
35
|
-
|
|
26
|
+
const text = color.trim().toLowerCase();
|
|
36
27
|
if (text === 'transparent' || text === 'none')
|
|
37
28
|
return true;
|
|
38
|
-
|
|
29
|
+
const rgba = text.match(/^rgba\(\s*[^,]+,\s*[^,]+,\s*[^,]+,\s*([\d.]+)\s*\)$/);
|
|
39
30
|
return rgba ? Number.parseFloat(rgba[1]) === 0 : false;
|
|
40
31
|
}
|
|
41
32
|
/** What a person typed (`f80`, `#FF8800`, `ff8800`) as `#RRGGBB`, or null when it is not a colour. */
|
|
42
33
|
export function parseHexInput(text) {
|
|
43
|
-
|
|
34
|
+
const match = text.trim().match(HEX_PATTERN);
|
|
44
35
|
if (!match)
|
|
45
36
|
return null;
|
|
46
|
-
|
|
47
|
-
return
|
|
37
|
+
const digits = match[1].length === 3 ? [...match[1]].map((digit) => digit + digit).join('') : match[1];
|
|
38
|
+
return `#${digits.toUpperCase()}`;
|
|
48
39
|
}
|
|
49
40
|
function toHexByte(value) {
|
|
50
41
|
return Math.max(0, Math.min(255, Math.round(value))).toString(16).padStart(2, '0');
|
|
51
42
|
}
|
|
52
43
|
function hslToHex(hue, saturation, lightness) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
44
|
+
const s = saturation / 100;
|
|
45
|
+
const l = lightness / 100;
|
|
46
|
+
const a = s * Math.min(l, 1 - l);
|
|
47
|
+
const channel = (n) => {
|
|
48
|
+
const k = (n + hue / 30) % 12;
|
|
58
49
|
return toHexByte(255 * (l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1)));
|
|
59
50
|
};
|
|
60
|
-
return
|
|
51
|
+
return `#${channel(0)}${channel(8)}${channel(4)}`.toUpperCase();
|
|
61
52
|
}
|
|
62
53
|
/**
|
|
63
54
|
* A stored colour as `#RRGGBB`: a hex, an `rgb()` or `hsl()` an older canvas may hold, or the nearest the browser can
|
|
64
55
|
* say for a colour name. `fallback` is what is answered for a colour that cannot be read.
|
|
65
56
|
*/
|
|
66
|
-
export function colorToHex(color, fallback) {
|
|
67
|
-
var _a;
|
|
68
|
-
if (fallback === void 0) { fallback = '#000000'; }
|
|
57
|
+
export function colorToHex(color, fallback = '#000000') {
|
|
69
58
|
if (!color)
|
|
70
59
|
return fallback;
|
|
71
|
-
|
|
60
|
+
const hex = parseHexInput(color);
|
|
72
61
|
if (hex)
|
|
73
62
|
return hex;
|
|
74
|
-
|
|
75
|
-
|
|
63
|
+
const text = color.trim();
|
|
64
|
+
const rgb = text.match(/^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)/i);
|
|
76
65
|
if (rgb)
|
|
77
|
-
return
|
|
78
|
-
|
|
66
|
+
return `#${toHexByte(Number(rgb[1]))}${toHexByte(Number(rgb[2]))}${toHexByte(Number(rgb[3]))}`.toUpperCase();
|
|
67
|
+
const hsl = text.match(/^hsla?\(\s*([\d.]+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%/i);
|
|
79
68
|
if (hsl)
|
|
80
69
|
return hslToHex(Number(hsl[1]), Number(hsl[2]), Number(hsl[3]));
|
|
81
|
-
return
|
|
70
|
+
return NAMED_COLORS[text.toLowerCase()] ?? fallback;
|
|
82
71
|
}
|
|
83
72
|
/** The few colour names an older canvas may hold. A name that is not here reads as the fallback. */
|
|
84
|
-
|
|
73
|
+
const NAMED_COLORS = Object.freeze({
|
|
85
74
|
black: '#000000',
|
|
86
75
|
white: '#FFFFFF',
|
|
87
76
|
red: '#FF0000',
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/** Names the colour picker fills in at runtime (`{s}`, `{v}`, `{hex}`), built without literals the word scan would read. */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
const s = `{${'s'}}`;
|
|
3
|
+
const v = `{${'v'}}`;
|
|
4
|
+
const hex = `{${'hex'}}`;
|
|
5
5
|
/** Words the design-system colour picker speaks; templates keep their placeholders for the picker to replace. */
|
|
6
6
|
export function colorPickerMessages(t) {
|
|
7
7
|
return {
|
|
8
8
|
area: t('canvas.colorPicker.area'),
|
|
9
|
-
areaValue: t('canvas.colorPicker.areaValue', { s
|
|
9
|
+
areaValue: t('canvas.colorPicker.areaValue', { s, v }),
|
|
10
10
|
hue: t('canvas.colorPicker.hue'),
|
|
11
11
|
hex: t('canvas.panel.hex'),
|
|
12
12
|
add: t('canvas.colorPicker.add'),
|
|
13
|
-
swatch: t('canvas.colorPicker.swatch', { hex
|
|
13
|
+
swatch: t('canvas.colorPicker.swatch', { hex })
|
|
14
14
|
};
|
|
15
15
|
}
|
|
@@ -12,16 +12,16 @@
|
|
|
12
12
|
* when it reads this file. Kept free of Svelte and of the DOM so that Node can test it.
|
|
13
13
|
*/
|
|
14
14
|
/** The card itself: its corners, border, fill, padding and shadow. */
|
|
15
|
-
export
|
|
15
|
+
export const FLOATING_CARD_CLASSES = 'rounded-xl border border-border bg-background p-[3px] shadow-floating';
|
|
16
16
|
/**
|
|
17
17
|
* The padding of the canvas's menus (the Shapes menu, the right-click menu and their submenus). They are the design system's
|
|
18
18
|
* Dropdown Menu, drawn in Figma the same way as the cards above: the first row stands 4 px from the outer edge, the 1 px
|
|
19
19
|
* border inside that. The component's own padding (4 px, beside the border) makes a menu 2 px larger each way than Figma's:
|
|
20
20
|
* the Shape Menu is 196 x 246 there, and measures 246 only with 3 px.
|
|
21
21
|
*/
|
|
22
|
-
export
|
|
22
|
+
export const MENU_PADDING_CLASS = 'p-[3px]';
|
|
23
23
|
/** Figma "Layer Menu" (519:*): 4 px inset, 220 × 136 with 32 px rows. */
|
|
24
|
-
export
|
|
24
|
+
export const LAYER_MENU_PADDING_CLASS = 'p-1';
|
|
25
25
|
/**
|
|
26
26
|
* A menu, a popover or a tooltip of the design system slides and fades in, and its classes do not ask whether the system wants
|
|
27
27
|
* less motion. The canvas adds this to each one it draws: with `prefers-reduced-motion: reduce` the card appears and goes
|
|
@@ -30,9 +30,9 @@ export var LAYER_MENU_PADDING_CLASS = 'p-1';
|
|
|
30
30
|
* The states are those of the three components: a menu and a popover are `open` and `closed`, a tooltip `delayed-open`,
|
|
31
31
|
* `instant-open` and `closed`.
|
|
32
32
|
*/
|
|
33
|
-
export
|
|
33
|
+
export const OVERLAY_REDUCED_MOTION_CLASSES = 'motion-reduce:animate-none motion-reduce:data-[state=open]:animate-none motion-reduce:data-[state=closed]:animate-none motion-reduce:data-[state=delayed-open]:animate-none motion-reduce:data-[state=instant-open]:animate-none';
|
|
34
34
|
/** Canvas-floated surfaces stay below site dialogs and toasts (design-system overlays use z-50). */
|
|
35
|
-
export
|
|
35
|
+
export const CANVAS_OVERLAY_Z_CLASS = 'z-40';
|
|
36
36
|
/**
|
|
37
37
|
* The ring of a menu's button while its menu is open, and while the keyboard is on it: 2 px of ring standing 2 px off the
|
|
38
38
|
* button, with the board's colour in the gap, as the design system draws its focus ring. Figma draws the open "Shapes" button
|
|
@@ -42,23 +42,23 @@ export var CANVAS_OVERLAY_Z_CLASS = 'z-40';
|
|
|
42
42
|
* `--tw-ring-offset-width` with `!important` on every element that has `aria-expanded` (a menu's button always has), so the
|
|
43
43
|
* offset of a ring on such a button is lost, whatever class asks for it.
|
|
44
44
|
*/
|
|
45
|
-
export
|
|
45
|
+
export const MENU_TRIGGER_RING_CLASSES = 'focus-visible:shadow-[0_0_0_2px_var(--color-background),0_0_0_4px_var(--color-ring)] data-[state=open]:shadow-[0_0_0_2px_var(--color-background),0_0_0_4px_var(--color-ring)]';
|
|
46
46
|
/**
|
|
47
47
|
* Tabler toolbar icons are 16 px (`size-4`) with stroke 2 in a 24 px viewBox: 2 × 16 / 24 = 1.333 px on screen.
|
|
48
48
|
* A library shape glyph is drawn in a 100 px viewBox, so it needs a stroke of 1.333 × 100 / 16 = 8.33 in its own units to
|
|
49
49
|
* look as thick. The design system's menu item forces `size-4` and `stroke-2` on every svg inside it through CSS, which beats
|
|
50
50
|
* the `stroke-width` attribute (the glyphs were 0.32 px thick), so the width is set inline on the glyph.
|
|
51
51
|
*/
|
|
52
|
-
export
|
|
53
|
-
export
|
|
54
|
-
export
|
|
55
|
-
export
|
|
56
|
-
export
|
|
57
|
-
export
|
|
58
|
-
export
|
|
59
|
-
export
|
|
52
|
+
export const TOOLBAR_ICON_STROKE_CLASSES = '[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg]:stroke-2';
|
|
53
|
+
export const TOOLBAR_ICON_SIZE_PX = 16;
|
|
54
|
+
export const TOOLBAR_ICON_VIEWBOX = 24;
|
|
55
|
+
export const TOOLBAR_ICON_STROKE_UNITS = 2;
|
|
56
|
+
export const TOOLBAR_ICON_STROKE_PX = (TOOLBAR_ICON_STROKE_UNITS * TOOLBAR_ICON_SIZE_PX) / TOOLBAR_ICON_VIEWBOX;
|
|
57
|
+
export const SHAPE_LIBRARY_ICON_SIZE_PX = TOOLBAR_ICON_SIZE_PX;
|
|
58
|
+
export const SHAPE_LIBRARY_VIEWBOX = 100;
|
|
59
|
+
export const SHAPE_LIBRARY_STROKE_WIDTH = (TOOLBAR_ICON_STROKE_PX * SHAPE_LIBRARY_VIEWBOX) / SHAPE_LIBRARY_ICON_SIZE_PX;
|
|
60
60
|
/** Figma's measures of the cards, in px (a Figma frame counts an inside stroke as part of the card). */
|
|
61
|
-
export
|
|
61
|
+
export const FLOATING_CARD_METRICS = {
|
|
62
62
|
/** The whole toolbar: five tools, the Shapes menu and the history group, with their dividers. */
|
|
63
63
|
toolbarWidth: 349,
|
|
64
64
|
toolbarHeight: 44,
|
|
@@ -76,7 +76,7 @@ export var FLOATING_CARD_METRICS = {
|
|
|
76
76
|
* with. (An upright bar is as long as the board is tall, so it always has them.) Written out in full, so a page's stylesheet
|
|
77
77
|
* picks it up.
|
|
78
78
|
*/
|
|
79
|
-
export
|
|
79
|
+
export const TOOLBAR_HISTORY_VISIBLE_FROM = 'hidden @[384px]:flex';
|
|
80
80
|
/**
|
|
81
81
|
* The width of board from which the zoom card is drawn, by the way it stands beside the toolbar (see `chromeLayout.ts`, which
|
|
82
82
|
* picks the case from the two anchors a page named). Narrower than that the zoom card is not drawn, as in Figma's phone: a
|
|
@@ -92,7 +92,7 @@ export var TOOLBAR_HISTORY_VISIBLE_FROM = 'hidden @[384px]:flex';
|
|
|
92
92
|
* - `centredBesideCornerToolbar`: the toolbar at a corner and the zoom card centred: the card's left edge has to clear the
|
|
93
93
|
* toolbar's right edge, which is 365 px from the board's left edge.
|
|
94
94
|
*/
|
|
95
|
-
export
|
|
95
|
+
export const ZOOM_CONTROL_MIN_WIDTHS = {
|
|
96
96
|
alone: 512,
|
|
97
97
|
sameSlot: 560,
|
|
98
98
|
oppositeCorners: 560,
|
|
@@ -100,7 +100,7 @@ export var ZOOM_CONTROL_MIN_WIDTHS = {
|
|
|
100
100
|
centredBesideCornerToolbar: 912
|
|
101
101
|
};
|
|
102
102
|
/** The classes that show the zoom card from each of those widths. Written out in full, so a page's stylesheet picks every one up. */
|
|
103
|
-
export
|
|
103
|
+
export const ZOOM_CONTROL_VISIBLE_FROM = {
|
|
104
104
|
alone: 'hidden @lg:flex',
|
|
105
105
|
sameSlot: 'hidden @[560px]:flex',
|
|
106
106
|
oppositeCorners: 'hidden @[560px]:flex',
|
|
@@ -12,23 +12,22 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { getContext, setContext } from 'svelte';
|
|
14
14
|
import { readable } from 'svelte/store';
|
|
15
|
-
|
|
15
|
+
const FLOATING_LAYER_CONTEXT_KEY = Symbol('widgetic-canvas-floating-layer');
|
|
16
16
|
/**
|
|
17
17
|
* The classes of the layer's element: no size (so it catches no press, and no `pointer-events: none` is needed, which the
|
|
18
18
|
* menus inside would inherit), above the chrome, and a containing block for what is fixed inside it.
|
|
19
19
|
*/
|
|
20
|
-
export
|
|
20
|
+
export const FLOATING_LAYER_CLASSES = 'absolute inset-0 z-50 h-0 w-0 [contain:layout]';
|
|
21
21
|
/** Called by the canvas that owns the layer, before its children are made. */
|
|
22
22
|
export function provideFloatingLayer(layer) {
|
|
23
23
|
setContext(FLOATING_LAYER_CONTEXT_KEY, layer);
|
|
24
24
|
}
|
|
25
25
|
/** The element to draw a floating thing into. A piece used outside a canvas has none, and the library's own default applies. */
|
|
26
26
|
export function useFloatingLayer() {
|
|
27
|
-
|
|
28
|
-
return (_a = getContext(FLOATING_LAYER_CONTEXT_KEY)) !== null && _a !== void 0 ? _a : readable(null);
|
|
27
|
+
return getContext(FLOATING_LAYER_CONTEXT_KEY) ?? readable(null);
|
|
29
28
|
}
|
|
30
29
|
/** Below design-system dialogs, dropdowns and toasts (`z-50`); still above normal page content so a compact card does not cover menus. */
|
|
31
|
-
export
|
|
30
|
+
export const CANVAS_OVERLAY_PORTAL_Z_CLASS = 'z-40';
|
|
32
31
|
/**
|
|
33
32
|
* Portal target for a menu, popover or tooltip: `document.body` in the light DOM, else the in-canvas floating layer.
|
|
34
33
|
* Floating UI still measures from the trigger; only the mount node changes.
|
|
@@ -39,7 +38,7 @@ export function canvasOverlayPortalProps(floatingLayer) {
|
|
|
39
38
|
? { to: document.body, class: CANVAS_OVERLAY_PORTAL_Z_CLASS }
|
|
40
39
|
: { class: CANVAS_OVERLAY_PORTAL_Z_CLASS };
|
|
41
40
|
}
|
|
42
|
-
|
|
41
|
+
const root = floatingLayer.getRootNode();
|
|
43
42
|
if (typeof Document !== 'undefined' && root instanceof Document) {
|
|
44
43
|
return { to: document.body, class: CANVAS_OVERLAY_PORTAL_Z_CLASS };
|
|
45
44
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
/** The platform name of a browser, from the newer API when there is one. */
|
|
2
2
|
function platformName(nav) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return (_c = (_b = (_a = withData.userAgentData) === null || _a === void 0 ? void 0 : _a.platform) !== null && _b !== void 0 ? _b : nav.platform) !== null && _c !== void 0 ? _c : '';
|
|
3
|
+
const withData = nav;
|
|
4
|
+
return withData.userAgentData?.platform ?? nav.platform ?? '';
|
|
6
5
|
}
|
|
7
6
|
/** True on a Mac, an iPhone or an iPad, where the shortcut key is Command and the menus print it as a symbol. */
|
|
8
|
-
export function isApplePlatform(nav) {
|
|
9
|
-
if (nav === void 0) { nav = typeof navigator === 'undefined' ? undefined : navigator; }
|
|
7
|
+
export function isApplePlatform(nav = typeof navigator === 'undefined' ? undefined : navigator) {
|
|
10
8
|
if (!nav)
|
|
11
9
|
return false;
|
|
12
10
|
return /mac|iphone|ipad|ipod/i.test(platformName(nav));
|
|
@@ -19,7 +17,7 @@ export function isApplePlatform(nav) {
|
|
|
19
17
|
export function ariaKeyShortcut(chord, apple) {
|
|
20
18
|
if (typeof chord.key !== 'string')
|
|
21
19
|
return undefined;
|
|
22
|
-
|
|
20
|
+
const parts = [];
|
|
23
21
|
if (chord.mod)
|
|
24
22
|
parts.push(apple ? 'Meta' : 'Control');
|
|
25
23
|
if (chord.shift)
|
|
@@ -32,10 +30,10 @@ export function ariaKeyShortcut(chord, apple) {
|
|
|
32
30
|
* the same in every language; the words of the others come from the page's language.
|
|
33
31
|
*/
|
|
34
32
|
export function chordText(chord, apple, t) {
|
|
35
|
-
|
|
33
|
+
const key = typeof chord.key === 'string' ? chord.key : t(chord.key.name);
|
|
36
34
|
if (apple)
|
|
37
|
-
return
|
|
38
|
-
|
|
35
|
+
return `${chord.shift ? '⇧' : ''}${chord.mod ? '⌘' : ''}${key}`;
|
|
36
|
+
const parts = [];
|
|
39
37
|
if (chord.mod)
|
|
40
38
|
parts.push(t('canvas.key.ctrl'));
|
|
41
39
|
if (chord.shift)
|
|
@@ -48,8 +46,8 @@ export function chordText(chord, apple, t) {
|
|
|
48
46
|
* elsewhere. The toolbar and zoom control keep `chordText` (symbols on Apple).
|
|
49
47
|
*/
|
|
50
48
|
export function menuChordText(chord, apple, t) {
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
const key = typeof chord.key === 'string' ? chord.key : t(chord.key.name);
|
|
50
|
+
const parts = [];
|
|
53
51
|
if (chord.shift)
|
|
54
52
|
parts.push(t('canvas.key.shift'));
|
|
55
53
|
if (chord.mod)
|
|
@@ -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')
|
|
@@ -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;
|