@widgetic/canvas 0.5.45 → 0.5.47

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.
Files changed (137) hide show
  1. package/README.md +3 -2
  2. package/dist/canvas/DomCanvas.svelte +1 -2
  3. package/dist/canvas/autosaveScheduler.js +37 -89
  4. package/dist/canvas/boardFrame.js +1 -1
  5. package/dist/canvas/boardSurface.js +1 -1
  6. package/dist/canvas/canvasLogger.js +7 -19
  7. package/dist/canvas/chromeLayout.js +19 -21
  8. package/dist/canvas/eventScope.js +10 -14
  9. package/dist/canvas/host/CanvasHost.d.ts +6 -5
  10. package/dist/canvas/host/CanvasHost.js +1664 -1861
  11. package/dist/canvas/host/CanvasHostApi.js +4 -19
  12. package/dist/canvas/host/boardFiles.js +35 -51
  13. package/dist/canvas/host/browserServices.js +108 -196
  14. package/dist/canvas/host/conversion.js +82 -170
  15. package/dist/canvas/host/hostObject.js +7 -7
  16. package/dist/canvas/host/nearCards.js +18 -21
  17. package/dist/canvas/host/pageEvents.js +5 -5
  18. package/dist/canvas/host/pauseCollector.d.ts +18 -0
  19. package/dist/canvas/host/pauseCollector.js +45 -0
  20. package/dist/canvas/host/pictureSaves.js +9 -11
  21. package/dist/canvas/host/screenRects.js +28 -31
  22. package/dist/canvas/host/storedPictures.js +149 -243
  23. package/dist/canvas/host/strokeSnap.js +88 -143
  24. package/dist/canvas/index.d.ts +1 -1
  25. package/dist/canvas/openMarks.js +2 -2
  26. package/dist/canvas/outsideClickDeselect.js +6 -7
  27. package/dist/canvas/panZoomPosition.js +2 -2
  28. package/dist/canvas/preferredTextFont.js +13 -25
  29. package/dist/canvas/shapes/ShapeLibrary.js +138 -148
  30. package/dist/canvas/shapes/shapeImageStore.js +4 -4
  31. package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
  32. package/dist/canvas/toolbarPosition.js +2 -2
  33. package/dist/canvas/types.d.ts +7 -1
  34. package/dist/canvas/ui/CanvasContextMenu.svelte +40 -3
  35. package/dist/canvas/ui/CanvasHint.svelte +10 -9
  36. package/dist/canvas/ui/SelectionPanel.svelte +14 -12
  37. package/dist/canvas/ui/SelectionPanel.svelte.d.ts +0 -2
  38. package/dist/canvas/ui/ShapesMenu.svelte +6 -4
  39. package/dist/canvas/ui/ToolButton.svelte +7 -6
  40. package/dist/canvas/ui/colorModel.js +21 -32
  41. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  42. package/dist/canvas/ui/floatingCard.d.ts +28 -8
  43. package/dist/canvas/ui/floatingCard.js +48 -28
  44. package/dist/canvas/ui/floatingLayer.js +5 -6
  45. package/dist/canvas/ui/keyHints.js +9 -11
  46. package/dist/canvas/ui/popoverSide.js +2 -3
  47. package/dist/canvas/ui/selectionTraits.d.ts +8 -4
  48. package/dist/canvas/ui/selectionTraits.js +44 -58
  49. package/dist/canvas/view/CanvasStage.svelte +1 -1
  50. package/dist/canvas/view/SelectionOverlay.svelte +2 -2
  51. package/dist/canvas/view/erasingMarks.js +7 -7
  52. package/dist/canvas/view/geometry.d.ts +1 -1
  53. package/dist/canvas/view/geometry.js +72 -91
  54. package/dist/canvas/view/liftedScene.js +24 -36
  55. package/dist/canvas/view/mountedScene.js +76 -79
  56. package/dist/components/CanvasBoardPlaceholder.svelte +68 -10
  57. package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +10 -2
  58. package/dist/components/CanvasToolbarPlaceholder.svelte +25 -11
  59. package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +6 -0
  60. package/dist/components/boardLoaderDelay.d.ts +39 -0
  61. package/dist/components/boardLoaderDelay.js +71 -0
  62. package/dist/components/input-controls/ColorIC.svelte +1 -1
  63. package/dist/components/input-controls/FontSelectorIC.svelte +1 -1
  64. package/dist/components/preferenceStorage.js +2 -2
  65. package/dist/engine/EngineCore.d.ts +42 -10
  66. package/dist/engine/EngineCore.js +843 -916
  67. package/dist/engine/codec/canvasDocument.js +192 -155
  68. package/dist/engine/codec/hostReadableKeys.js +1 -1
  69. package/dist/engine/core/arrange.js +26 -38
  70. package/dist/engine/core/arrow.js +79 -92
  71. package/dist/engine/core/arrowBinding.js +98 -116
  72. package/dist/engine/core/arrowBindingRecords.js +23 -38
  73. package/dist/engine/core/brush.d.ts +24 -0
  74. package/dist/engine/core/brush.js +223 -103
  75. package/dist/engine/core/cameraMove.js +39 -51
  76. package/dist/engine/core/defaults.js +92 -51
  77. package/dist/engine/core/freehand.js +147 -163
  78. package/dist/engine/core/geometry.js +47 -54
  79. package/dist/engine/core/history.js +38 -55
  80. package/dist/engine/core/hitTest.js +68 -81
  81. package/dist/engine/core/matrix.js +18 -20
  82. package/dist/engine/core/pathData.js +183 -210
  83. package/dist/engine/core/rotationReset.js +5 -6
  84. package/dist/engine/core/scene.js +160 -224
  85. package/dist/engine/core/scribble.js +59 -84
  86. package/dist/engine/core/shapePaths.js +12 -15
  87. package/dist/engine/core/shapeTools.d.ts +23 -18
  88. package/dist/engine/core/shapeTools.js +104 -67
  89. package/dist/engine/core/snapping.js +65 -117
  90. package/dist/engine/core/style.d.ts +18 -2
  91. package/dist/engine/core/style.js +79 -80
  92. package/dist/engine/core/styleMemory.d.ts +88 -0
  93. package/dist/engine/core/styleMemory.js +189 -0
  94. package/dist/engine/core/transform.js +84 -95
  95. package/dist/engine/core/types.js +4 -4
  96. package/dist/engine/core/viewport.js +23 -36
  97. package/dist/engine/input/PointerController.js +513 -526
  98. package/dist/engine/input/arrowHandles.js +12 -12
  99. package/dist/engine/input/gestures.d.ts +8 -3
  100. package/dist/engine/input/gestures.js +378 -346
  101. package/dist/engine/input/hoverCursor.js +1 -1
  102. package/dist/engine/input/keyboard.js +42 -41
  103. package/dist/engine/input/selectionHandles.js +45 -50
  104. package/dist/engine/input/types.js +1 -1
  105. package/dist/engine/render/rasterize.js +86 -158
  106. package/dist/engine/state.js +6 -17
  107. package/dist/engine/text/layoutText.js +43 -62
  108. package/dist/engine/text/textMetrics.js +8 -10
  109. package/dist/engine/widgets.js +101 -137
  110. package/dist/fonts/interFont.js +30 -83
  111. package/dist/fonts/workspaceFonts.js +33 -92
  112. package/dist/i18n/labels.js +4 -4
  113. package/dist/i18n/language.js +4 -4
  114. package/dist/i18n/messages.js +1 -1
  115. package/dist/i18n/shortcuts.js +14 -14
  116. package/dist/index.d.ts +1 -1
  117. package/dist/poster/boardPlacement.d.ts +4 -1
  118. package/dist/poster/boardPlacement.js +34 -33
  119. package/dist/poster/boardPoster.js +58 -83
  120. package/dist/poster/paintBoardPoster.js +16 -39
  121. package/dist/poster/posterPictures.js +27 -43
  122. package/dist/settings/rememberedStyles.d.ts +22 -0
  123. package/dist/settings/rememberedStyles.js +47 -0
  124. package/dist/settings/rememberedTool.d.ts +50 -0
  125. package/dist/settings/rememberedTool.js +68 -0
  126. package/dist/settings/workspaceToolSettings.d.ts +25 -0
  127. package/dist/settings/workspaceToolSettings.js +38 -48
  128. package/dist/tools/components/catalog.js +64 -74
  129. package/dist/tools/components/grouping.js +6 -28
  130. package/dist/tools/definitions.js +5 -5
  131. package/dist/tools/executors.js +137 -169
  132. package/dist/tools/hostAdapter.js +10 -13
  133. package/dist/tools/sceneSummary.js +43 -57
  134. package/dist/tools/sketchIntent.js +13 -21
  135. package/dist/tools/styleArguments.js +19 -21
  136. package/dist/tools/types.js +1 -1
  137. package/package.json +5 -5
@@ -0,0 +1,50 @@
1
+ /**
2
+ * The tool a board opens with.
3
+ *
4
+ * A board used to open with the pencil every time (where the page shows the drawing tools), so a refresh took the person back to the
5
+ * pencil from whatever tool they had chosen. It now opens with the tool they had last, kept for the workspace beside the rest of their
6
+ * tool settings (`workspaceToolSettings.ts`), and with the pencil (Select, where the page hides the drawing tools) when none was kept.
7
+ *
8
+ * One rule decides it for the board (`CanvasHost`) and for the picture of the toolbar that is drawn before the board is there
9
+ * (`CanvasToolbarPlaceholder`), so the tool that is lit does not change at the hand-over.
10
+ */
11
+ import type { ToolId } from '../engine/state.js';
12
+ import { type SettingsStorageAdapter } from './workspaceToolSettings.js';
13
+ /**
14
+ * The tools a board can open with: the ones that have a button on the toolbar, the shapes of the Shapes menu included. `pan` has no
15
+ * button (it is the H key and the space bar) and a library shape needs the key of its shape, so neither is kept.
16
+ */
17
+ export declare const REMEMBERED_TOOL_IDS: readonly ["select", "draw", "erase", "arrow", "text", "rect", "rounded-rect", "ellipse", "circle", "triangle"];
18
+ export type RememberedToolId = (typeof REMEMBERED_TOOL_IDS)[number];
19
+ /** The tools of the Shapes menu (its button is the one that is lit while one of them is the tool). */
20
+ export declare const SHAPE_TOOL_IDS: readonly ["rect", "rounded-rect", "ellipse", "circle", "triangle"];
21
+ /** The tools of the drawing group: the page takes their buttons off (`showDrawingTools: false`), and a board does not open with a tool it has no button for. */
22
+ export declare const DRAWING_GROUP_TOOL_IDS: readonly ["draw", "erase", "arrow", "text"];
23
+ /** Whether a value is a tool that is kept (anything else that a storage holds is the same as nothing). */
24
+ export declare function isRememberedTool(value: unknown): value is RememberedToolId;
25
+ /** The tool of this change of tool, when it is one that is kept; null for the others (the hand, a library shape). */
26
+ export declare function toolToRemember(tool: ToolId): RememberedToolId | null;
27
+ /** Whether the tool is one of the drawing group, which a page may take off its toolbar. */
28
+ export declare function isDrawingGroupTool(tool: ToolId): boolean;
29
+ /** The tool of a board where none was kept: the pencil where the page shows the drawing tools (a board opens ready for a sketch), else Select. */
30
+ export declare function defaultFirstTool(showDrawingTools: boolean): ToolId;
31
+ /**
32
+ * The tool a board opens with, given what was kept (anything, as it came from a storage) and whether the page shows the drawing tools:
33
+ * what was kept, when the board has a button for it, else the tool of a board where none was kept.
34
+ */
35
+ export declare function toolTheBoardOpensWith(options: {
36
+ rememberedToolId: unknown;
37
+ showDrawingTools: boolean;
38
+ }): ToolId;
39
+ /** Where the tool was kept: the workspace, and the person where the page says who they are. */
40
+ export interface RememberedToolScope {
41
+ workspaceId?: string | null;
42
+ userId?: string | null;
43
+ }
44
+ /** The tool kept for this workspace and person, or null (nothing kept, no workspace to keep it for, a store that refuses, or a value that is no tool). */
45
+ export declare function readRememberedToolId(scope: RememberedToolScope, adapter?: SettingsStorageAdapter): RememberedToolId | null;
46
+ /** The tool a board opens with: read from the storage of the workspace, decided by `toolTheBoardOpensWith`. */
47
+ export declare function firstToolOfBoard(options: RememberedToolScope & {
48
+ showDrawingTools: boolean;
49
+ adapter?: SettingsStorageAdapter;
50
+ }): ToolId;
@@ -0,0 +1,68 @@
1
+ /**
2
+ * The tool a board opens with.
3
+ *
4
+ * A board used to open with the pencil every time (where the page shows the drawing tools), so a refresh took the person back to the
5
+ * pencil from whatever tool they had chosen. It now opens with the tool they had last, kept for the workspace beside the rest of their
6
+ * tool settings (`workspaceToolSettings.ts`), and with the pencil (Select, where the page hides the drawing tools) when none was kept.
7
+ *
8
+ * One rule decides it for the board (`CanvasHost`) and for the picture of the toolbar that is drawn before the board is there
9
+ * (`CanvasToolbarPlaceholder`), so the tool that is lit does not change at the hand-over.
10
+ */
11
+ import { loadWorkspaceToolSettings } from './workspaceToolSettings.js';
12
+ /**
13
+ * The tools a board can open with: the ones that have a button on the toolbar, the shapes of the Shapes menu included. `pan` has no
14
+ * button (it is the H key and the space bar) and a library shape needs the key of its shape, so neither is kept.
15
+ */
16
+ export const REMEMBERED_TOOL_IDS = ['select', 'draw', 'erase', 'arrow', 'text', 'rect', 'rounded-rect', 'ellipse', 'circle', 'triangle'];
17
+ /** The tools of the Shapes menu (its button is the one that is lit while one of them is the tool). */
18
+ export const SHAPE_TOOL_IDS = ['rect', 'rounded-rect', 'ellipse', 'circle', 'triangle'];
19
+ /** The tools of the drawing group: the page takes their buttons off (`showDrawingTools: false`), and a board does not open with a tool it has no button for. */
20
+ export const DRAWING_GROUP_TOOL_IDS = ['draw', 'erase', 'arrow', 'text'];
21
+ /** Whether a value is a tool that is kept (anything else that a storage holds is the same as nothing). */
22
+ export function isRememberedTool(value) {
23
+ return typeof value === 'string' && REMEMBERED_TOOL_IDS.includes(value);
24
+ }
25
+ /** The tool of this change of tool, when it is one that is kept; null for the others (the hand, a library shape). */
26
+ export function toolToRemember(tool) {
27
+ return isRememberedTool(tool) ? tool : null;
28
+ }
29
+ /** Whether the tool is one of the drawing group, which a page may take off its toolbar. */
30
+ export function isDrawingGroupTool(tool) {
31
+ return DRAWING_GROUP_TOOL_IDS.includes(tool);
32
+ }
33
+ /** The tool of a board where none was kept: the pencil where the page shows the drawing tools (a board opens ready for a sketch), else Select. */
34
+ export function defaultFirstTool(showDrawingTools) {
35
+ return showDrawingTools ? 'draw' : 'select';
36
+ }
37
+ /**
38
+ * The tool a board opens with, given what was kept (anything, as it came from a storage) and whether the page shows the drawing tools:
39
+ * what was kept, when the board has a button for it, else the tool of a board where none was kept.
40
+ */
41
+ export function toolTheBoardOpensWith(options) {
42
+ const { rememberedToolId, showDrawingTools } = options;
43
+ if (!isRememberedTool(rememberedToolId))
44
+ return defaultFirstTool(showDrawingTools);
45
+ if (!showDrawingTools && isDrawingGroupTool(rememberedToolId))
46
+ return defaultFirstTool(showDrawingTools);
47
+ return rememberedToolId;
48
+ }
49
+ /** The tool kept for this workspace and person, or null (nothing kept, no workspace to keep it for, a store that refuses, or a value that is no tool). */
50
+ export function readRememberedToolId(scope, adapter) {
51
+ const { workspaceId, userId } = scope;
52
+ if (!workspaceId)
53
+ return null;
54
+ try {
55
+ const stored = loadWorkspaceToolSettings({ workspaceId, userId }, adapter)?.tool?.id;
56
+ return isRememberedTool(stored) ? stored : null;
57
+ }
58
+ catch (error) {
59
+ // A store that blocks reading is the same as a store with nothing in it.
60
+ console.warn('[canvas] The tool that was kept could not be read, so the board opens with the usual one:', error);
61
+ return null;
62
+ }
63
+ }
64
+ /** The tool a board opens with: read from the storage of the workspace, decided by `toolTheBoardOpensWith`. */
65
+ export function firstToolOfBoard(options) {
66
+ const { showDrawingTools, adapter, ...scope } = options;
67
+ return toolTheBoardOpensWith({ rememberedToolId: readRememberedToolId(scope, adapter), showDrawingTools });
68
+ }
@@ -7,6 +7,12 @@ export interface SettingsStorageAdapter {
7
7
  load(key: string): string | null;
8
8
  save(key: string, value: string): void;
9
9
  }
10
+ /**
11
+ * What the person last chose for each kind of element, so the next element of the kind starts with it (see `engine/core/styleMemory.ts`,
12
+ * which says what each kind is and what is kept of it). `text`, `paint` (the shapes with an inside), `icon` (the line-only icons of the
13
+ * library: a check, a cross, a plus, a minus) and `arrow` hold keys of the settings panel, each only the ones its kind remembers.
14
+ * Values are checked key by key when they are read, so an entry from an older version, or one that was damaged, gives what it can.
15
+ */
10
16
  export interface WorkspaceToolSettingsV1 {
11
17
  v: typeof WORKSPACE_TOOL_SETTINGS_SCHEMA_VERSION;
12
18
  text?: {
@@ -17,6 +23,7 @@ export interface WorkspaceToolSettingsV1 {
17
23
  color?: string;
18
24
  align?: 'left' | 'center' | 'right';
19
25
  underline?: boolean;
26
+ opacity?: number;
20
27
  };
21
28
  paint?: {
22
29
  fill?: string;
@@ -26,9 +33,19 @@ export interface WorkspaceToolSettingsV1 {
26
33
  opacity?: number;
27
34
  roundness?: number;
28
35
  };
36
+ /** The line-only icons of the library: the colour of the line, its width and opacity, how round its ends are. Left out until the person styles one. */
37
+ icon?: {
38
+ stroke?: string;
39
+ strokeWidth?: number;
40
+ strokeStyle?: 'solid' | 'dashed' | 'dotted';
41
+ opacity?: number;
42
+ roundness?: number;
43
+ };
29
44
  arrow?: {
30
45
  stroke?: string;
31
46
  strokeWidth?: number;
47
+ strokeStyle?: 'solid' | 'dashed' | 'dotted';
48
+ opacity?: number;
32
49
  headStart?: boolean;
33
50
  headEnd?: boolean;
34
51
  };
@@ -38,6 +55,14 @@ export interface WorkspaceToolSettingsV1 {
38
55
  width?: number;
39
56
  opacity?: number;
40
57
  };
58
+ /**
59
+ * The tool the person last had chosen on the toolbar, so a board opened again (a refresh included) starts with it and not always with
60
+ * the pencil (see `rememberedTool.ts`, which says which tools are kept). Left out until a tool is chosen. The id is checked when it
61
+ * is read: a value that is not a tool of the toolbar is the same as none.
62
+ */
63
+ tool?: {
64
+ id?: string;
65
+ };
41
66
  }
42
67
  export interface WorkspaceToolSettingsScope {
43
68
  workspaceId: string;
@@ -1,41 +1,29 @@
1
1
  /**
2
2
  * Last-used tool settings per workspace (item B16). Debounced writes, flush on pagehide.
3
3
  */
4
- var __assign = (this && this.__assign) || function () {
5
- __assign = Object.assign || function(t) {
6
- for (var s, i = 1, n = arguments.length; i < n; i++) {
7
- s = arguments[i];
8
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
9
- t[p] = s[p];
10
- }
11
- return t;
12
- };
13
- return __assign.apply(this, arguments);
14
- };
15
4
  import { getCanvasPreferenceStorage } from '../components/preferenceStorage.js';
16
- export var WORKSPACE_TOOL_SETTINGS_SCHEMA_VERSION = 1;
17
- export var WORKSPACE_TOOL_SETTINGS_KEY_PREFIX = 'widgetic-canvas:workspace-tool-settings:v1:';
5
+ export const WORKSPACE_TOOL_SETTINGS_SCHEMA_VERSION = 1;
6
+ export const WORKSPACE_TOOL_SETTINGS_KEY_PREFIX = 'widgetic-canvas:workspace-tool-settings:v1:';
18
7
  function storageKey(scope) {
19
- var userPart = scope.userId ? ":".concat(scope.userId) : '';
20
- return "".concat(WORKSPACE_TOOL_SETTINGS_KEY_PREFIX).concat(scope.workspaceId).concat(userPart);
8
+ const userPart = scope.userId ? `:${scope.userId}` : '';
9
+ return `${WORKSPACE_TOOL_SETTINGS_KEY_PREFIX}${scope.workspaceId}${userPart}`;
21
10
  }
22
11
  function adapterFromPreferenceStorage() {
23
- var storage = getCanvasPreferenceStorage();
12
+ const storage = getCanvasPreferenceStorage();
24
13
  return {
25
- load: function (key) {
26
- var _a;
14
+ load(key) {
27
15
  try {
28
- return (_a = storage === null || storage === void 0 ? void 0 : storage.getItem(key)) !== null && _a !== void 0 ? _a : null;
16
+ return storage?.getItem(key) ?? null;
29
17
  }
30
- catch (_b) {
18
+ catch {
31
19
  return null;
32
20
  }
33
21
  },
34
- save: function (key, value) {
22
+ save(key, value) {
35
23
  try {
36
- storage === null || storage === void 0 ? void 0 : storage.setItem(key, value);
24
+ storage?.setItem(key, value);
37
25
  }
38
- catch (_a) {
26
+ catch {
39
27
  // quota / private mode
40
28
  }
41
29
  }
@@ -45,53 +33,56 @@ export function parseWorkspaceToolSettings(raw) {
45
33
  if (!raw)
46
34
  return null;
47
35
  try {
48
- var parsed = JSON.parse(raw);
49
- if ((parsed === null || parsed === void 0 ? void 0 : parsed.v) !== WORKSPACE_TOOL_SETTINGS_SCHEMA_VERSION)
36
+ const parsed = JSON.parse(raw);
37
+ if (parsed?.v !== WORKSPACE_TOOL_SETTINGS_SCHEMA_VERSION)
50
38
  return null;
51
39
  return parsed;
52
40
  }
53
- catch (_a) {
41
+ catch {
54
42
  return null;
55
43
  }
56
44
  }
57
- export function loadWorkspaceToolSettings(scope, adapter) {
58
- if (adapter === void 0) { adapter = adapterFromPreferenceStorage(); }
45
+ export function loadWorkspaceToolSettings(scope, adapter = adapterFromPreferenceStorage()) {
59
46
  return parseWorkspaceToolSettings(adapter.load(storageKey(scope)));
60
47
  }
61
- /** The settings with a patch laid over them: each part (text, paint, arrow, pen) keeps what the patch does not say. */
48
+ /** The settings with a patch laid over them: each part (text, paint, icon, arrow, pen, tool) keeps what the patch does not say. */
62
49
  function mergeSettings(current, patch) {
63
- var merged = {
50
+ const merged = {
64
51
  v: WORKSPACE_TOOL_SETTINGS_SCHEMA_VERSION,
65
- text: __assign(__assign({}, current.text), patch.text),
66
- paint: __assign(__assign({}, current.paint), patch.paint),
67
- arrow: __assign(__assign({}, current.arrow), patch.arrow)
52
+ text: { ...current.text, ...patch.text },
53
+ paint: { ...current.paint, ...patch.paint },
54
+ arrow: { ...current.arrow, ...patch.arrow }
68
55
  };
56
+ // The line-only icons are written only when the person styled one: settings of a person who never did hold none.
57
+ if (current.icon || patch.icon)
58
+ merged.icon = { ...current.icon, ...patch.icon };
69
59
  // The pen is written only when there is one: settings of a person who never touched it hold none.
70
60
  if (current.pen || patch.pen)
71
- merged.pen = __assign(__assign({}, current.pen), patch.pen);
61
+ merged.pen = { ...current.pen, ...patch.pen };
62
+ // The tool is written only when one was chosen, for the same reason.
63
+ if (current.tool || patch.tool)
64
+ merged.tool = { ...current.tool, ...patch.tool };
72
65
  return merged;
73
66
  }
74
- var pending = null;
75
- var debounceTimer;
76
- export function saveWorkspaceToolSettingsDebounced(scope, patch, adapter) {
77
- var _a, _b;
78
- if (adapter === void 0) { adapter = adapterFromPreferenceStorage(); }
67
+ let pending = null;
68
+ let debounceTimer;
69
+ export function saveWorkspaceToolSettingsDebounced(scope, patch, adapter = adapterFromPreferenceStorage()) {
79
70
  // A change that waits for its write (see the delay below) is part of the settings already: the next change is laid over it, and not
80
71
  // over what the storage still holds, so two changes made within the delay are both kept. A change that waits for another workspace
81
72
  // is written first, and is not lost to this one.
82
73
  if (pending && storageKey(pending.scope) !== storageKey(scope))
83
74
  flushWorkspaceToolSettingsPending();
84
- var current = (_b = (_a = pending === null || pending === void 0 ? void 0 : pending.value) !== null && _a !== void 0 ? _a : loadWorkspaceToolSettings(scope, adapter)) !== null && _b !== void 0 ? _b : { v: WORKSPACE_TOOL_SETTINGS_SCHEMA_VERSION };
85
- var merged = mergeSettings(current, patch);
86
- pending = { scope: scope, value: merged, adapter: adapter };
75
+ const current = pending?.value ?? loadWorkspaceToolSettings(scope, adapter) ?? { v: WORKSPACE_TOOL_SETTINGS_SCHEMA_VERSION };
76
+ const merged = mergeSettings(current, patch);
77
+ pending = { scope, value: merged, adapter };
87
78
  if (debounceTimer !== undefined)
88
79
  clearTimeout(debounceTimer);
89
- debounceTimer = setTimeout(function () { return flushWorkspaceToolSettingsPending(); }, 400);
80
+ debounceTimer = setTimeout(() => flushWorkspaceToolSettingsPending(), 400);
90
81
  }
91
82
  export function flushWorkspaceToolSettingsPending() {
92
83
  if (!pending)
93
84
  return;
94
- var scope = pending.scope, value = pending.value, adapter = pending.adapter;
85
+ const { scope, value, adapter } = pending;
95
86
  pending = null;
96
87
  if (debounceTimer !== undefined) {
97
88
  clearTimeout(debounceTimer);
@@ -100,15 +91,14 @@ export function flushWorkspaceToolSettingsPending() {
100
91
  try {
101
92
  adapter.save(storageKey(scope), JSON.stringify(value));
102
93
  }
103
- catch (_a) {
94
+ catch {
104
95
  // ignored
105
96
  }
106
97
  }
107
98
  /** Merges a patch into settings without debounce (tests). */
108
99
  export function saveWorkspaceToolSettingsNow(scope, patch, adapter) {
109
- var _a;
110
- var current = (_a = loadWorkspaceToolSettings(scope, adapter)) !== null && _a !== void 0 ? _a : { v: WORKSPACE_TOOL_SETTINGS_SCHEMA_VERSION };
111
- var merged = mergeSettings(current, patch);
100
+ const current = loadWorkspaceToolSettings(scope, adapter) ?? { v: WORKSPACE_TOOL_SETTINGS_SCHEMA_VERSION };
101
+ const merged = mergeSettings(current, patch);
112
102
  adapter.save(storageKey(scope), JSON.stringify(merged));
113
103
  return merged;
114
104
  }
@@ -1,12 +1,3 @@
1
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
- if (ar || !(i in from)) {
4
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
- ar[i] = from[i];
6
- }
7
- }
8
- return to.concat(ar || Array.prototype.slice.call(from));
9
- };
10
1
  import { createPathObject, createRectObject, createTextObject } from '../../engine/core/defaults.js';
11
2
  import { buildArrow } from '../../engine/core/arrow.js';
12
3
  import { serializePathData } from '../../engine/core/pathData.js';
@@ -14,27 +5,27 @@ import { packGroup } from './grouping.js';
14
5
  function snap(value) {
15
6
  return Math.round(value / 8) * 8;
16
7
  }
17
- var STROKE = '#9ca3af';
18
- var STROKE_WIDTH = 2;
8
+ const STROKE = '#9ca3af';
9
+ const STROKE_WIDTH = 2;
19
10
  export function drawUiComponent(kind, x, y, width, height, label) {
20
- var objects = [];
21
- var px = snap(x);
22
- var py = snap(y);
23
- var w = snap(Math.max(160, width));
24
- var h = snap(Math.max(120, height));
11
+ const objects = [];
12
+ const px = snap(x);
13
+ const py = snap(y);
14
+ const w = snap(Math.max(160, width));
15
+ const h = snap(Math.max(120, height));
25
16
  switch (kind) {
26
17
  case 'video_player': {
27
- var title = createTextObject({
18
+ const title = createTextObject({
28
19
  x: px,
29
20
  y: py - 28,
30
- text: (label === null || label === void 0 ? void 0 : label.trim()) || 'Video player',
21
+ text: label?.trim() || 'Video player',
31
22
  fontSize: 14,
32
23
  fontWeight: 'bold',
33
24
  autoWidth: true
34
25
  });
35
- var thumbW = w;
36
- var thumbH = snap(thumbW * (9 / 16));
37
- var frame = createRectObject({
26
+ const thumbW = w;
27
+ const thumbH = snap(thumbW * (9 / 16));
28
+ const frame = createRectObject({
38
29
  x: px,
39
30
  y: py,
40
31
  width: thumbW,
@@ -43,7 +34,7 @@ export function drawUiComponent(kind, x, y, width, height, label) {
43
34
  stroke: STROKE,
44
35
  strokeWidth: STROKE_WIDTH
45
36
  });
46
- var screen = createRectObject({
37
+ const screen = createRectObject({
47
38
  x: px + 12,
48
39
  y: py + 12,
49
40
  width: thumbW - 24,
@@ -53,15 +44,15 @@ export function drawUiComponent(kind, x, y, width, height, label) {
53
44
  stroke: 'transparent',
54
45
  strokeWidth: 0
55
46
  });
56
- var screenLabel = createTextObject({
47
+ const screenLabel = createTextObject({
57
48
  x: px + 16,
58
49
  y: py + 4,
59
50
  text: 'Thumbnail',
60
51
  fontSize: 11,
61
52
  autoWidth: true
62
53
  });
63
- var playSize = 56;
64
- var play = createRectObject({
54
+ const playSize = 56;
55
+ const play = createRectObject({
65
56
  x: px + thumbW / 2 - playSize / 2,
66
57
  y: py + thumbH / 2 - playSize / 2,
67
58
  width: playSize,
@@ -71,8 +62,8 @@ export function drawUiComponent(kind, x, y, width, height, label) {
71
62
  stroke: '#d1d5db',
72
63
  strokeWidth: 1
73
64
  });
74
- var screenGroup = packGroup([frame, screen, play, screenLabel], {});
75
- var navBar = createRectObject({
65
+ const screenGroup = packGroup([frame, screen, play, screenLabel], {});
66
+ const navBar = createRectObject({
76
67
  x: px,
77
68
  y: py + thumbH + 16,
78
69
  width: thumbW,
@@ -82,8 +73,8 @@ export function drawUiComponent(kind, x, y, width, height, label) {
82
73
  stroke: STROKE,
83
74
  strokeWidth: STROKE_WIDTH
84
75
  });
85
- var navThumbs = [];
86
- for (var i = 0; i < 5; i++) {
76
+ const navThumbs = [];
77
+ for (let i = 0; i < 5; i++) {
87
78
  navThumbs.push(createRectObject({
88
79
  x: px + 16 + i * 56,
89
80
  y: py + thumbH + 32,
@@ -95,7 +86,7 @@ export function drawUiComponent(kind, x, y, width, height, label) {
95
86
  strokeWidth: 0
96
87
  }));
97
88
  }
98
- var navTitle = createTextObject({
89
+ const navTitle = createTextObject({
99
90
  x: px,
100
91
  y: py + thumbH + 4,
101
92
  text: 'Navigation',
@@ -103,16 +94,16 @@ export function drawUiComponent(kind, x, y, width, height, label) {
103
94
  fontWeight: 'bold',
104
95
  autoWidth: true
105
96
  });
106
- var navGroup = packGroup(__spreadArray([navBar, navTitle], navThumbs, true), {});
107
- objects.push.apply(objects, __spreadArray(__spreadArray([title], screenGroup.objects, false), navGroup.objects, false));
97
+ const navGroup = packGroup([navBar, navTitle, ...navThumbs], {});
98
+ objects.push(title, ...screenGroup.objects, ...navGroup.objects);
108
99
  return {
109
- objects: objects,
100
+ objects,
110
101
  rootLabel: 'Video player',
111
102
  highlightIds: [navGroup.groupId]
112
103
  };
113
104
  }
114
105
  case 'navigation_bar': {
115
- var bar = createRectObject({
106
+ const bar = createRectObject({
116
107
  x: px,
117
108
  y: py + 20,
118
109
  width: w,
@@ -122,32 +113,32 @@ export function drawUiComponent(kind, x, y, width, height, label) {
122
113
  strokeWidth: STROKE_WIDTH,
123
114
  fill: '#f9fafb'
124
115
  });
125
- var title = createTextObject({
116
+ const title = createTextObject({
126
117
  x: px,
127
118
  y: py,
128
- text: (label === null || label === void 0 ? void 0 : label.trim()) || 'Navigation bar',
119
+ text: label?.trim() || 'Navigation bar',
129
120
  fontSize: 12,
130
121
  fontWeight: 'bold',
131
122
  autoWidth: true
132
123
  });
133
- var tabs = [];
134
- for (var i = 0; i < 4; i++) {
124
+ const tabs = [];
125
+ for (let i = 0; i < 4; i++) {
135
126
  tabs.push(createTextObject({
136
127
  x: px + 16 + i * 96,
137
128
  y: py + 36,
138
- text: "Nav ".concat(i + 1),
129
+ text: `Nav ${i + 1}`,
139
130
  fontSize: 14,
140
131
  autoWidth: true
141
132
  }));
142
133
  }
143
- var packed = packGroup(__spreadArray([bar], tabs, true), {});
144
- objects.push.apply(objects, __spreadArray([title], packed.objects, false));
145
- return { objects: objects, rootLabel: (label === null || label === void 0 ? void 0 : label.trim()) || 'Navigation bar' };
134
+ const packed = packGroup([bar, ...tabs], {});
135
+ objects.push(title, ...packed.objects);
136
+ return { objects, rootLabel: label?.trim() || 'Navigation bar' };
146
137
  }
147
138
  case 'button': {
148
- var btnH = snap(Math.max(44, Math.min(48, h)));
149
- var btnW = snap(Math.max(128, w));
150
- var btn = createRectObject({
139
+ const btnH = snap(Math.max(44, Math.min(48, h)));
140
+ const btnW = snap(Math.max(128, w));
141
+ const btn = createRectObject({
151
142
  x: px,
152
143
  y: py + 22,
153
144
  width: btnW,
@@ -157,14 +148,14 @@ export function drawUiComponent(kind, x, y, width, height, label) {
157
148
  stroke: STROKE,
158
149
  strokeWidth: STROKE_WIDTH
159
150
  });
160
- var caption = createTextObject({
151
+ const caption = createTextObject({
161
152
  x: px + 16,
162
153
  y: py + 34,
163
- text: label !== null && label !== void 0 ? label : 'Button',
154
+ text: label ?? 'Button',
164
155
  fontSize: 15,
165
156
  autoWidth: true
166
157
  });
167
- var title = createTextObject({
158
+ const title = createTextObject({
168
159
  x: px,
169
160
  y: py,
170
161
  text: 'Button',
@@ -172,13 +163,13 @@ export function drawUiComponent(kind, x, y, width, height, label) {
172
163
  color: '#6b7280',
173
164
  autoWidth: true
174
165
  });
175
- var packed = packGroup([btn, caption], {});
176
- objects.push.apply(objects, __spreadArray([title], packed.objects, false));
177
- return { objects: objects, rootLabel: label !== null && label !== void 0 ? label : 'Button' };
166
+ const packed = packGroup([btn, caption], {});
167
+ objects.push(title, ...packed.objects);
168
+ return { objects, rootLabel: label ?? 'Button' };
178
169
  }
179
170
  case 'card': {
180
- var cardH = snap(Math.max(160, h));
181
- var card = createRectObject({
171
+ const cardH = snap(Math.max(160, h));
172
+ const card = createRectObject({
182
173
  x: px,
183
174
  y: py + 24,
184
175
  width: w,
@@ -188,15 +179,15 @@ export function drawUiComponent(kind, x, y, width, height, label) {
188
179
  strokeWidth: STROKE_WIDTH,
189
180
  fill: '#ffffff'
190
181
  });
191
- var heading = createTextObject({
182
+ const heading = createTextObject({
192
183
  x: px + 16,
193
184
  y: py + 40,
194
- text: label !== null && label !== void 0 ? label : 'Card title',
185
+ text: label ?? 'Card title',
195
186
  fontSize: 18,
196
187
  fontWeight: 'bold',
197
188
  autoWidth: true
198
189
  });
199
- var body = createRectObject({
190
+ const body = createRectObject({
200
191
  x: px + 16,
201
192
  y: py + 72,
202
193
  width: w - 32,
@@ -206,15 +197,15 @@ export function drawUiComponent(kind, x, y, width, height, label) {
206
197
  stroke: 'transparent',
207
198
  strokeWidth: 0
208
199
  });
209
- var title = createTextObject({ x: px, y: py, text: 'Card', fontSize: 11, color: '#6b7280', autoWidth: true });
210
- var packed = packGroup([card, heading, body], {});
211
- objects.push.apply(objects, __spreadArray([title], packed.objects, false));
212
- return { objects: objects, rootLabel: label !== null && label !== void 0 ? label : 'Card' };
200
+ const title = createTextObject({ x: px, y: py, text: 'Card', fontSize: 11, color: '#6b7280', autoWidth: true });
201
+ const packed = packGroup([card, heading, body], {});
202
+ objects.push(title, ...packed.objects);
203
+ return { objects, rootLabel: label ?? 'Card' };
213
204
  }
214
205
  case 'form': {
215
- var title = createTextObject({ x: px, y: py, text: label !== null && label !== void 0 ? label : 'Form', fontSize: 12, fontWeight: 'bold', autoWidth: true });
216
- var fields = [];
217
- for (var i = 0; i < 3; i++) {
206
+ const title = createTextObject({ x: px, y: py, text: label ?? 'Form', fontSize: 12, fontWeight: 'bold', autoWidth: true });
207
+ const fields = [];
208
+ for (let i = 0; i < 3; i++) {
218
209
  fields.push(createRectObject({
219
210
  x: px,
220
211
  y: py + 32 + i * 48,
@@ -226,12 +217,12 @@ export function drawUiComponent(kind, x, y, width, height, label) {
226
217
  fill: '#fff'
227
218
  }));
228
219
  }
229
- var packed = packGroup(fields, {});
230
- objects.push.apply(objects, __spreadArray([title], packed.objects, false));
231
- return { objects: objects, rootLabel: label !== null && label !== void 0 ? label : 'Form' };
220
+ const packed = packGroup(fields, {});
221
+ objects.push(title, ...packed.objects);
222
+ return { objects, rootLabel: label ?? 'Form' };
232
223
  }
233
224
  default: {
234
- var box = createRectObject({
225
+ const box = createRectObject({
235
226
  x: px,
236
227
  y: py + 20,
237
228
  width: w,
@@ -240,21 +231,20 @@ export function drawUiComponent(kind, x, y, width, height, label) {
240
231
  stroke: STROKE,
241
232
  strokeWidth: STROKE_WIDTH
242
233
  });
243
- var title = createTextObject({
234
+ const title = createTextObject({
244
235
  x: px,
245
236
  y: py,
246
- text: label !== null && label !== void 0 ? label : kind.replace(/_/g, ' '),
237
+ text: label ?? kind.replace(/_/g, ' '),
247
238
  fontSize: 14,
248
239
  autoWidth: true
249
240
  });
250
241
  objects.push(title, box);
251
- return { objects: objects, rootLabel: label !== null && label !== void 0 ? label : kind };
242
+ return { objects, rootLabel: label ?? kind };
252
243
  }
253
244
  }
254
245
  }
255
- export function makeArrowBetween(fromX, fromY, toX, toY, strokeWidth) {
256
- if (strokeWidth === void 0) { strokeWidth = 2; }
257
- var geometry = buildArrow({ x: fromX, y: fromY }, { x: toX, y: toY }, 0, strokeWidth);
246
+ export function makeArrowBetween(fromX, fromY, toX, toY, strokeWidth = 2) {
247
+ const geometry = buildArrow({ x: fromX, y: fromY }, { x: toX, y: toY }, 0, strokeWidth);
258
248
  return createPathObject({
259
249
  x: geometry.box.x,
260
250
  y: geometry.box.y,
@@ -264,7 +254,7 @@ export function makeArrowBetween(fromX, fromY, toX, toY, strokeWidth) {
264
254
  shape: 'arrow',
265
255
  arrow: geometry.spec,
266
256
  stroke: '#111827',
267
- strokeWidth: strokeWidth,
257
+ strokeWidth,
268
258
  fill: 'transparent'
269
259
  });
270
260
  }