@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
@@ -7,148 +7,101 @@
7
7
  * pointer speeds up: sweeping quickly across a board must not catch on every shape on the way, only a slow,
8
8
  * deliberate move should (the same idea Memoreco's layout editor uses).
9
9
  */
10
- var __assign = (this && this.__assign) || function () {
11
- __assign = Object.assign || function(t) {
12
- for (var s, i = 1, n = arguments.length; i < n; i++) {
13
- s = arguments[i];
14
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
15
- t[p] = s[p];
16
- }
17
- return t;
18
- };
19
- return __assign.apply(this, arguments);
20
- };
21
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
22
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
23
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
24
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
25
- };
26
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
27
- if (kind === "m") throw new TypeError("Private method is not writable");
28
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
29
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
30
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
31
- };
32
- var _PointerSpeedTracker_last, _PointerSpeedTracker_speed;
33
10
  import { clampNumber } from './geometry.js';
34
11
  /** How far, in screen pixels, a line reaches to catch the dragged edge when the pointer is slow. */
35
- export var SNAP_THRESHOLD_PIXELS = 8;
12
+ export const SNAP_THRESHOLD_PIXELS = 8;
36
13
  /** At or below this speed (pixels per millisecond) the snap has its full reach. */
37
- export var SNAP_SLOW_SPEED = 0.25;
14
+ export const SNAP_SLOW_SPEED = 0.25;
38
15
  /** At or above this speed the snap has no reach at all. */
39
- export var SNAP_FAST_SPEED = 0.9;
16
+ export const SNAP_FAST_SPEED = 0.9;
40
17
  /** Weight of the newest sample in the smoothed pointer speed. */
41
- export var SNAP_SPEED_SMOOTHING = 0.35;
42
- export var NO_SNAP = Object.freeze({ deltaX: 0, deltaY: 0, guides: [] });
18
+ export const SNAP_SPEED_SMOOTHING = 0.35;
19
+ export const NO_SNAP = Object.freeze({ deltaX: 0, deltaY: 0, guides: [] });
43
20
  /** The reach of a snap in world units for a pointer moving at `speed`, at `zoom`. */
44
- export function snapReachInWorld(zoom, speed, basePixels) {
45
- if (speed === void 0) { speed = 0; }
46
- if (basePixels === void 0) { basePixels = SNAP_THRESHOLD_PIXELS; }
47
- var speedFactor = clampNumber((speed - SNAP_SLOW_SPEED) / (SNAP_FAST_SPEED - SNAP_SLOW_SPEED), 0, 1);
21
+ export function snapReachInWorld(zoom, speed = 0, basePixels = SNAP_THRESHOLD_PIXELS) {
22
+ const speedFactor = clampNumber((speed - SNAP_SLOW_SPEED) / (SNAP_FAST_SPEED - SNAP_SLOW_SPEED), 0, 1);
48
23
  return (basePixels * (1 - speedFactor)) / Math.max(zoom, 1e-6);
49
24
  }
50
25
  /** Follows how fast the pointer moves, smoothed, in screen pixels per millisecond. */
51
- var PointerSpeedTracker = /** @class */ (function () {
52
- function PointerSpeedTracker() {
53
- _PointerSpeedTracker_last.set(this, null);
54
- _PointerSpeedTracker_speed.set(this, 0);
55
- }
26
+ export class PointerSpeedTracker {
27
+ #last = null;
28
+ #speed = 0;
56
29
  /** Records a pointer position (screen space) and returns the smoothed speed. */
57
- PointerSpeedTracker.prototype.update = function (x, y, time) {
58
- if (__classPrivateFieldGet(this, _PointerSpeedTracker_last, "f") && time > __classPrivateFieldGet(this, _PointerSpeedTracker_last, "f").time) {
59
- var instant = Math.hypot(x - __classPrivateFieldGet(this, _PointerSpeedTracker_last, "f").x, y - __classPrivateFieldGet(this, _PointerSpeedTracker_last, "f").y) / (time - __classPrivateFieldGet(this, _PointerSpeedTracker_last, "f").time);
60
- __classPrivateFieldSet(this, _PointerSpeedTracker_speed, __classPrivateFieldGet(this, _PointerSpeedTracker_speed, "f") * (1 - SNAP_SPEED_SMOOTHING) + instant * SNAP_SPEED_SMOOTHING, "f");
30
+ update(x, y, time) {
31
+ if (this.#last && time > this.#last.time) {
32
+ const instant = Math.hypot(x - this.#last.x, y - this.#last.y) / (time - this.#last.time);
33
+ this.#speed = this.#speed * (1 - SNAP_SPEED_SMOOTHING) + instant * SNAP_SPEED_SMOOTHING;
61
34
  }
62
- __classPrivateFieldSet(this, _PointerSpeedTracker_last, { x: x, y: y, time: time }, "f");
63
- return __classPrivateFieldGet(this, _PointerSpeedTracker_speed, "f");
64
- };
65
- Object.defineProperty(PointerSpeedTracker.prototype, "speed", {
66
- get: function () {
67
- return __classPrivateFieldGet(this, _PointerSpeedTracker_speed, "f");
68
- },
69
- enumerable: false,
70
- configurable: true
71
- });
72
- PointerSpeedTracker.prototype.reset = function () {
73
- __classPrivateFieldSet(this, _PointerSpeedTracker_last, null, "f");
74
- __classPrivateFieldSet(this, _PointerSpeedTracker_speed, 0, "f");
75
- };
76
- return PointerSpeedTracker;
77
- }());
78
- export { PointerSpeedTracker };
79
- _PointerSpeedTracker_last = new WeakMap(), _PointerSpeedTracker_speed = new WeakMap();
35
+ this.#last = { x, y, time };
36
+ return this.#speed;
37
+ }
38
+ get speed() {
39
+ return this.#speed;
40
+ }
41
+ reset() {
42
+ this.#last = null;
43
+ this.#speed = 0;
44
+ }
45
+ }
80
46
  function verticalLinesOf(rects) {
81
- var lines = [];
82
- for (var _i = 0, rects_1 = rects; _i < rects_1.length; _i++) {
83
- var rect = rects_1[_i];
84
- lines.push({ position: rect.x, rect: rect }, { position: rect.x + rect.width / 2, rect: rect }, { position: rect.x + rect.width, rect: rect });
47
+ const lines = [];
48
+ for (const rect of rects) {
49
+ lines.push({ position: rect.x, rect }, { position: rect.x + rect.width / 2, rect }, { position: rect.x + rect.width, rect });
85
50
  }
86
51
  return lines;
87
52
  }
88
53
  function horizontalLinesOf(rects) {
89
- var lines = [];
90
- for (var _i = 0, rects_2 = rects; _i < rects_2.length; _i++) {
91
- var rect = rects_2[_i];
92
- lines.push({ position: rect.y, rect: rect }, { position: rect.y + rect.height / 2, rect: rect }, { position: rect.y + rect.height, rect: rect });
54
+ const lines = [];
55
+ for (const rect of rects) {
56
+ lines.push({ position: rect.y, rect }, { position: rect.y + rect.height / 2, rect }, { position: rect.y + rect.height, rect });
93
57
  }
94
58
  return lines;
95
59
  }
96
60
  /** The smallest signed distance from any anchor to any line, if it is within `reach`. */
97
61
  function nearestOffset(anchors, lines, reach) {
98
- var best = null;
99
- for (var _i = 0, anchors_1 = anchors; _i < anchors_1.length; _i++) {
100
- var anchor = anchors_1[_i];
101
- for (var _a = 0, lines_1 = lines; _a < lines_1.length; _a++) {
102
- var line = lines_1[_a];
103
- var offset = line.position - anchor;
62
+ let best = null;
63
+ for (const anchor of anchors) {
64
+ for (const line of lines) {
65
+ const offset = line.position - anchor;
104
66
  if (Math.abs(offset) <= reach && (best === null || Math.abs(offset) < Math.abs(best.offset) - 1e-9)) {
105
- best = { offset: offset };
67
+ best = { offset };
106
68
  }
107
69
  }
108
70
  }
109
71
  return best;
110
72
  }
111
- var MATCH_EPSILON = 0.01;
73
+ const MATCH_EPSILON = 0.01;
112
74
  /**
113
75
  * The guides to draw for a box that sits where it will land: every line of the other shapes that one of
114
76
  * its anchors is on, spanning both shapes.
115
77
  */
116
- export function guidesFor(box, others, anchorsOf) {
117
- if (anchorsOf === void 0) { anchorsOf = 'both'; }
118
- var guides = [];
78
+ export function guidesFor(box, others, anchorsOf = 'both') {
79
+ const guides = [];
119
80
  if (anchorsOf !== 'y') {
120
- var anchors = [box.x, box.x + box.width / 2, box.x + box.width];
121
- var _loop_1 = function (line) {
122
- if (anchors.some(function (anchor) { return Math.abs(anchor - line.position) <= MATCH_EPSILON; })) {
123
- var top = Math.min(box.y, line.rect.y);
124
- var bottom = Math.max(box.y + box.height, line.rect.y + line.rect.height);
81
+ const anchors = [box.x, box.x + box.width / 2, box.x + box.width];
82
+ for (const line of verticalLinesOf(others)) {
83
+ if (anchors.some((anchor) => Math.abs(anchor - line.position) <= MATCH_EPSILON)) {
84
+ const top = Math.min(box.y, line.rect.y);
85
+ const bottom = Math.max(box.y + box.height, line.rect.y + line.rect.height);
125
86
  mergeGuide(guides, { orientation: 'vertical', position: line.position, from: top, to: bottom });
126
87
  }
127
- };
128
- for (var _i = 0, _a = verticalLinesOf(others); _i < _a.length; _i++) {
129
- var line = _a[_i];
130
- _loop_1(line);
131
88
  }
132
89
  }
133
90
  if (anchorsOf !== 'x') {
134
- var anchors = [box.y, box.y + box.height / 2, box.y + box.height];
135
- var _loop_2 = function (line) {
136
- if (anchors.some(function (anchor) { return Math.abs(anchor - line.position) <= MATCH_EPSILON; })) {
137
- var left = Math.min(box.x, line.rect.x);
138
- var right = Math.max(box.x + box.width, line.rect.x + line.rect.width);
91
+ const anchors = [box.y, box.y + box.height / 2, box.y + box.height];
92
+ for (const line of horizontalLinesOf(others)) {
93
+ if (anchors.some((anchor) => Math.abs(anchor - line.position) <= MATCH_EPSILON)) {
94
+ const left = Math.min(box.x, line.rect.x);
95
+ const right = Math.max(box.x + box.width, line.rect.x + line.rect.width);
139
96
  mergeGuide(guides, { orientation: 'horizontal', position: line.position, from: left, to: right });
140
97
  }
141
- };
142
- for (var _b = 0, _c = horizontalLinesOf(others); _b < _c.length; _b++) {
143
- var line = _c[_b];
144
- _loop_2(line);
145
98
  }
146
99
  }
147
100
  return guides;
148
101
  }
149
102
  /** Adds a guide, or stretches the one already on the same line to cover it. */
150
103
  function mergeGuide(guides, guide) {
151
- var existing = guides.find(function (candidate) { return candidate.orientation === guide.orientation && Math.abs(candidate.position - guide.position) <= MATCH_EPSILON; });
104
+ const existing = guides.find((candidate) => candidate.orientation === guide.orientation && Math.abs(candidate.position - guide.position) <= MATCH_EPSILON);
152
105
  if (!existing) {
153
106
  guides.push(guide);
154
107
  return;
@@ -161,34 +114,30 @@ function mergeGuide(guides, guide) {
161
114
  * far to nudge it and which guides to show once it is there.
162
115
  */
163
116
  export function computeMoveSnap(moving, others, reach) {
164
- var _a, _b;
165
117
  if (others.length === 0 || reach <= 0)
166
118
  return NO_SNAP;
167
- var x = nearestOffset([moving.x, moving.x + moving.width / 2, moving.x + moving.width], verticalLinesOf(others), reach);
168
- var y = nearestOffset([moving.y, moving.y + moving.height / 2, moving.y + moving.height], horizontalLinesOf(others), reach);
169
- var deltaX = (_a = x === null || x === void 0 ? void 0 : x.offset) !== null && _a !== void 0 ? _a : 0;
170
- var deltaY = (_b = y === null || y === void 0 ? void 0 : y.offset) !== null && _b !== void 0 ? _b : 0;
119
+ const x = nearestOffset([moving.x, moving.x + moving.width / 2, moving.x + moving.width], verticalLinesOf(others), reach);
120
+ const y = nearestOffset([moving.y, moving.y + moving.height / 2, moving.y + moving.height], horizontalLinesOf(others), reach);
121
+ const deltaX = x?.offset ?? 0;
122
+ const deltaY = y?.offset ?? 0;
171
123
  if (!x && !y)
172
124
  return NO_SNAP;
173
- var landed = __assign(__assign({}, moving), { x: moving.x + deltaX, y: moving.y + deltaY });
174
- return { deltaX: deltaX, deltaY: deltaY, guides: guidesFor(landed, others, x && y ? 'both' : x ? 'x' : 'y') };
125
+ const landed = { ...moving, x: moving.x + deltaX, y: moving.y + deltaY };
126
+ return { deltaX, deltaY, guides: guidesFor(landed, others, x && y ? 'both' : x ? 'x' : 'y') };
175
127
  }
176
128
  /**
177
129
  * Snaps one point (the corner or edge a handle drags, or a corner of a shape being drawn) to the lines of
178
130
  * the other shapes. `axes` says which coordinates may snap (an edge handle moves one only).
179
131
  */
180
- export function snapPoint(point, others, reach, axes) {
181
- var _a, _b;
182
- if (axes === void 0) { axes = { x: true, y: true }; }
132
+ export function snapPoint(point, others, reach, axes = { x: true, y: true }) {
183
133
  if (others.length === 0 || reach <= 0)
184
- return { point: point, guides: [] };
185
- var x = axes.x ? nearestOffset([point.x], verticalLinesOf(others), reach) : null;
186
- var y = axes.y ? nearestOffset([point.y], horizontalLinesOf(others), reach) : null;
187
- var snapped = { x: point.x + ((_a = x === null || x === void 0 ? void 0 : x.offset) !== null && _a !== void 0 ? _a : 0), y: point.y + ((_b = y === null || y === void 0 ? void 0 : y.offset) !== null && _b !== void 0 ? _b : 0) };
188
- var guides = [];
134
+ return { point, guides: [] };
135
+ const x = axes.x ? nearestOffset([point.x], verticalLinesOf(others), reach) : null;
136
+ const y = axes.y ? nearestOffset([point.y], horizontalLinesOf(others), reach) : null;
137
+ const snapped = { x: point.x + (x?.offset ?? 0), y: point.y + (y?.offset ?? 0) };
138
+ const guides = [];
189
139
  if (x) {
190
- for (var _i = 0, _c = verticalLinesOf(others); _i < _c.length; _i++) {
191
- var line = _c[_i];
140
+ for (const line of verticalLinesOf(others)) {
192
141
  if (Math.abs(line.position - snapped.x) <= MATCH_EPSILON) {
193
142
  mergeGuide(guides, {
194
143
  orientation: 'vertical',
@@ -200,8 +149,7 @@ export function snapPoint(point, others, reach, axes) {
200
149
  }
201
150
  }
202
151
  if (y) {
203
- for (var _d = 0, _e = horizontalLinesOf(others); _d < _e.length; _d++) {
204
- var line = _e[_d];
152
+ for (const line of horizontalLinesOf(others)) {
205
153
  if (Math.abs(line.position - snapped.y) <= MATCH_EPSILON) {
206
154
  mergeGuide(guides, {
207
155
  orientation: 'horizontal',
@@ -212,5 +160,5 @@ export function snapPoint(point, others, reach, axes) {
212
160
  }
213
161
  }
214
162
  }
215
- return { point: snapped, guides: guides };
163
+ return { point: snapped, guides };
216
164
  }
@@ -29,8 +29,11 @@ export interface StylePatch {
29
29
  }
30
30
  /** Whether the Roundness control means something for the path (rounded corners or round line ends). */
31
31
  export declare function pathSupportsRoundness(shapeKey: string | null): boolean;
32
- /** The widest a line may be made with the Width control (the pen's too: see `EngineCore.setPenStyle`). */
33
- export declare const MAX_STROKE_WIDTH = 200;
32
+ /**
33
+ * The widest a line may be made with the Width control, for every kind of shape, an arrow and a line drawn by hand (the pen's too: see
34
+ * `EngineCore.setPenStyle`). It was 200; a line thicker than 50 is not needed. A board saved with a thicker one opens as it was.
35
+ */
36
+ export declare const MAX_STROKE_WIDTH = 50;
34
37
  /** The thinnest line a shape that is only a line can be given (the brush's own least is the same): with none, nothing of it is left. */
35
38
  export declare const MIN_LINE_STROKE_WIDTH = 1;
36
39
  /**
@@ -46,5 +49,18 @@ export declare function paintsFillOnStroke(shape: ShapeObject): boolean;
46
49
  * follow the pressure) the fill of that outline. The panel's Stroke colour and the shape snap read and write the line this way.
47
50
  */
48
51
  export declare function lineColorOf(shape: ShapeObject): string;
52
+ /**
53
+ * A number of a patch brought into the range its key has (a width from 0 to 50, an opacity from 0 to 1, a size from 4 to 600 ...). A key
54
+ * with no range keeps the number as it is. The one place the ranges are applied, so a value kept for later and a value written to a shape
55
+ * can never disagree on what the key allows.
56
+ */
57
+ export declare function clampedStyleNumber(key: keyof StylePatch, value: number): number;
58
+ /**
59
+ * The keys of a patch that a shape takes, at the values it takes them at: what `applyStylePatch` writes into the shape, whether or not
60
+ * the shape already has it. A number is brought into its range, a line is never made so thin that it is gone, and the Fill of a shape
61
+ * that is only a line (a check, a cross) is its Stroke. This is also what an edit of the selection says about the next element of its
62
+ * kind (see `styleMemory.ts`), so the memory and the shape always agree on what a value is.
63
+ */
64
+ export declare function acceptedStylePatch(shape: ShapeObject, requested: StylePatch): StylePatch;
49
65
  /** Applies the keys of a patch that mean something for the shape. Same object back when nothing changes. */
50
66
  export declare function applyStylePatch(shape: ShapeObject, requested: StylePatch): ShapeObject;
@@ -5,45 +5,14 @@
5
5
  * its kind and ignores the rest (an image has no stroke, a rectangle no font). A shape comes back unchanged
6
6
  * (the same object) when the patch changes nothing for it, so the renderer redraws only what is different.
7
7
  */
8
- var __assign = (this && this.__assign) || function () {
9
- __assign = Object.assign || function(t) {
10
- for (var s, i = 1, n = arguments.length; i < n; i++) {
11
- s = arguments[i];
12
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
13
- t[p] = s[p];
14
- }
15
- return t;
16
- };
17
- return __assign.apply(this, arguments);
18
- };
19
- var __rest = (this && this.__rest) || function (s, e) {
20
- var t = {};
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
22
- t[p] = s[p];
23
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
24
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
25
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
26
- t[p[i]] = s[p[i]];
27
- }
28
- return t;
29
- };
30
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
31
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
32
- if (ar || !(i in from)) {
33
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
34
- ar[i] = from[i];
35
- }
36
- }
37
- return to.concat(ar || Array.prototype.slice.call(from));
38
- };
39
8
  import { getShapeByKey } from '../../canvas/shapes/ShapeLibrary.js';
40
9
  import { isArrow, reshapeArrow } from './arrow.js';
41
10
  import { MIN_BRUSH_WIDTH, isBrushStroke, reshapeBrushStroke } from './brush.js';
42
11
  import { clampNumber } from './geometry.js';
43
12
  import { mirrorPathCommands, serializePathData } from './pathData.js';
44
13
  import { regeneratedPathCommands } from './shapePaths.js';
45
- var PAINT_KEYS = ['fill', 'fillOpacity', 'stroke', 'strokeWidth', 'strokeStyle'];
46
- var TEXT_KEYS = [
14
+ const PAINT_KEYS = ['fill', 'fillOpacity', 'stroke', 'strokeWidth', 'strokeStyle'];
15
+ const TEXT_KEYS = [
47
16
  'color',
48
17
  'fontSize',
49
18
  'fontFamily',
@@ -59,16 +28,16 @@ var TEXT_KEYS = [
59
28
  function keysFor(shape) {
60
29
  switch (shape.type) {
61
30
  case 'rect':
62
- return __spreadArray(['opacity', 'roundness'], PAINT_KEYS, true);
31
+ return ['opacity', 'roundness', ...PAINT_KEYS];
63
32
  case 'ellipse':
64
- return __spreadArray(['opacity'], PAINT_KEYS, true);
33
+ return ['opacity', ...PAINT_KEYS];
65
34
  case 'path':
66
35
  // An arrow is a line and a head: nothing to fill, no corner to round.
67
36
  if (isArrow(shape))
68
37
  return ['opacity', 'stroke', 'strokeWidth', 'strokeStyle'];
69
- return __spreadArray(['opacity', 'roundness'], PAINT_KEYS, true);
38
+ return ['opacity', 'roundness', ...PAINT_KEYS];
70
39
  case 'text':
71
- return __spreadArray(['opacity'], TEXT_KEYS, true);
40
+ return ['opacity', ...TEXT_KEYS];
72
41
  default:
73
42
  return ['opacity'];
74
43
  }
@@ -77,18 +46,20 @@ function keysFor(shape) {
77
46
  export function pathSupportsRoundness(shapeKey) {
78
47
  if (shapeKey === 'triangle')
79
48
  return true;
80
- var shape = getShapeByKey(shapeKey);
49
+ const shape = getShapeByKey(shapeKey);
81
50
  return !!shape && (shape.cornerRadiusMode === 'pathRegen' || shape.cornerRadiusMode === 'strokeRound');
82
51
  }
83
52
  /** Whether the shape's roundness is the shape of its line ends rather than of its corners. */
84
53
  function roundnessIsLineEnds(shapeKey) {
85
- var _a;
86
- return ((_a = getShapeByKey(shapeKey)) === null || _a === void 0 ? void 0 : _a.cornerRadiusMode) === 'strokeRound';
54
+ return getShapeByKey(shapeKey)?.cornerRadiusMode === 'strokeRound';
87
55
  }
88
- /** The widest a line may be made with the Width control (the pen's too: see `EngineCore.setPenStyle`). */
89
- export var MAX_STROKE_WIDTH = 200;
56
+ /**
57
+ * The widest a line may be made with the Width control, for every kind of shape, an arrow and a line drawn by hand (the pen's too: see
58
+ * `EngineCore.setPenStyle`). It was 200; a line thicker than 50 is not needed. A board saved with a thicker one opens as it was.
59
+ */
60
+ export const MAX_STROKE_WIDTH = 50;
90
61
  /** The thinnest line a shape that is only a line can be given (the brush's own least is the same): with none, nothing of it is left. */
91
- export var MIN_LINE_STROKE_WIDTH = 1;
62
+ export const MIN_LINE_STROKE_WIDTH = 1;
92
63
  /**
93
64
  * The least the Width control may give a shape. A shape with an inside can go without an outline (0), but an arrow, a line-only
94
65
  * icon (a check, a cross, a plus, a minus) or a brush stroke is its line: with none it would vanish from the board, so it keeps
@@ -99,7 +70,7 @@ export function minimumStrokeWidthOf(shape) {
99
70
  return MIN_BRUSH_WIDTH;
100
71
  return isArrow(shape) || paintsFillOnStroke(shape) ? MIN_LINE_STROKE_WIDTH : 0;
101
72
  }
102
- var RANGES = {
73
+ const RANGES = {
103
74
  opacity: [0, 1],
104
75
  fillOpacity: [0, 1],
105
76
  strokeWidth: [0, MAX_STROKE_WIDTH],
@@ -109,7 +80,7 @@ var RANGES = {
109
80
  padding: [0, 200]
110
81
  };
111
82
  /** The line-only icons of the library (a check, a cross, a plus, a minus): their colour is the colour of the line. */
112
- var LINE_ICON_KEYS = new Set(['cross', 'plus', 'minus', 'check']);
83
+ const LINE_ICON_KEYS = new Set(['cross', 'plus', 'minus', 'check']);
113
84
  /** Whether the "Fill" colour of this shape is really the colour of its line, because it has no inside. */
114
85
  export function paintsFillOnStroke(shape) {
115
86
  if (shape.type !== 'path' || !shape.shape)
@@ -126,73 +97,101 @@ export function lineColorOf(shape) {
126
97
  return shape.type === 'rect' || shape.type === 'ellipse' || shape.type === 'path' ? shape.stroke : '';
127
98
  }
128
99
  /**
129
- * A patch for a brush stroke: the Stroke colour is the colour of the outline, the Width draws the brush again at the new width.
130
- * Everything else the patch carries means nothing to a stroke and is left out. Same object back when nothing changes.
100
+ * The keys of a patch that a brush stroke takes, at the values it takes them at: the Stroke colour is the colour of the outline, the
101
+ * Width is the nominal width of the brush (from the brush's least to the widest), and the opacity is the whole stroke's. Everything else
102
+ * the patch carries means nothing to a stroke and is left out.
131
103
  */
104
+ function acceptedBrushStylePatch(patch) {
105
+ const accepted = {};
106
+ if (patch.opacity !== undefined)
107
+ accepted.opacity = clampNumber(patch.opacity, 0, 1);
108
+ if (patch.stroke !== undefined)
109
+ accepted.stroke = patch.stroke;
110
+ if (patch.strokeWidth !== undefined)
111
+ accepted.strokeWidth = clampNumber(patch.strokeWidth, MIN_BRUSH_WIDTH, MAX_STROKE_WIDTH);
112
+ return accepted;
113
+ }
114
+ /** A patch for a brush stroke: the Stroke colour is the colour of the outline, the Width draws the brush again at the new width. Same object back when nothing changes. */
132
115
  function applyBrushStylePatch(shape, patch) {
133
- var next = shape;
134
- if (patch.opacity !== undefined) {
135
- var opacity = clampNumber(patch.opacity, 0, 1);
136
- if (opacity !== next.opacity)
137
- next = __assign(__assign({}, next), { opacity: opacity });
138
- }
139
- if (patch.stroke !== undefined && patch.stroke !== next.fill)
140
- next = __assign(__assign({}, next), { fill: patch.stroke });
141
- if (patch.strokeWidth !== undefined) {
142
- var strokeWidth = clampNumber(patch.strokeWidth, MIN_BRUSH_WIDTH, MAX_STROKE_WIDTH);
143
- if (strokeWidth !== next.strokeWidth)
144
- next = reshapeBrushStroke(next, { strokeWidth: strokeWidth });
145
- }
116
+ const accepted = acceptedBrushStylePatch(patch);
117
+ let next = shape;
118
+ if (accepted.opacity !== undefined && accepted.opacity !== next.opacity)
119
+ next = { ...next, opacity: accepted.opacity };
120
+ if (accepted.stroke !== undefined && accepted.stroke !== next.fill)
121
+ next = { ...next, fill: accepted.stroke };
122
+ if (accepted.strokeWidth !== undefined && accepted.strokeWidth !== next.strokeWidth)
123
+ next = reshapeBrushStroke(next, { strokeWidth: accepted.strokeWidth });
146
124
  return next;
147
125
  }
148
- /** Applies the keys of a patch that mean something for the shape. Same object back when nothing changes. */
149
- export function applyStylePatch(shape, requested) {
126
+ /**
127
+ * A number of a patch brought into the range its key has (a width from 0 to 50, an opacity from 0 to 1, a size from 4 to 600 ...). A key
128
+ * with no range keeps the number as it is. The one place the ranges are applied, so a value kept for later and a value written to a shape
129
+ * can never disagree on what the key allows.
130
+ */
131
+ export function clampedStyleNumber(key, value) {
132
+ const range = RANGES[key];
133
+ return range ? clampNumber(value, range[0], range[1]) : value;
134
+ }
135
+ /**
136
+ * The keys of a patch that a shape takes, at the values it takes them at: what `applyStylePatch` writes into the shape, whether or not
137
+ * the shape already has it. A number is brought into its range, a line is never made so thin that it is gone, and the Fill of a shape
138
+ * that is only a line (a check, a cross) is its Stroke. This is also what an edit of the selection says about the next element of its
139
+ * kind (see `styleMemory.ts`), so the memory and the shape always agree on what a value is.
140
+ */
141
+ export function acceptedStylePatch(shape, requested) {
150
142
  if (isBrushStroke(shape))
151
- return applyBrushStylePatch(shape, requested);
152
- var patch = requested;
143
+ return acceptedBrushStylePatch(requested);
144
+ let patch = requested;
153
145
  if (patch.fill !== undefined && paintsFillOnStroke(shape)) {
154
146
  // The panel's Fill colour is the colour of the line for these icons.
155
- var fill = patch.fill, rest = __rest(patch, ["fill"]);
156
- patch = __assign(__assign({}, rest), { stroke: fill });
147
+ const { fill, ...rest } = patch;
148
+ patch = { ...rest, stroke: fill };
157
149
  }
158
- var allowed = keysFor(shape);
159
- var changes = {};
160
- for (var _i = 0, allowed_1 = allowed; _i < allowed_1.length; _i++) {
161
- var key = allowed_1[_i];
150
+ const accepted = {};
151
+ for (const key of keysFor(shape)) {
162
152
  if (!(key in patch))
163
153
  continue;
164
- var value = patch[key];
154
+ let value = patch[key];
165
155
  if (value === undefined)
166
156
  continue;
167
- var range = RANGES[key];
168
- if (range && typeof value === 'number')
169
- value = clampNumber(value, range[0], range[1]);
157
+ if (typeof value === 'number')
158
+ value = clampedStyleNumber(key, value);
170
159
  // A line is never made so thin that it is gone (an arrow with no line would vanish with nothing left to take hold of).
171
160
  if (key === 'strokeWidth' && typeof value === 'number')
172
161
  value = Math.max(value, minimumStrokeWidthOf(shape));
162
+ accepted[key] = value;
163
+ }
164
+ return accepted;
165
+ }
166
+ /** Applies the keys of a patch that mean something for the shape. Same object back when nothing changes. */
167
+ export function applyStylePatch(shape, requested) {
168
+ if (isBrushStroke(shape))
169
+ return applyBrushStylePatch(shape, requested);
170
+ const changes = {};
171
+ for (const [key, value] of Object.entries(acceptedStylePatch(shape, requested))) {
173
172
  if (shape[key] !== value)
174
173
  changes[key] = value;
175
174
  }
176
175
  if (Object.keys(changes).length === 0)
177
176
  return shape;
178
- var next = __assign(__assign({}, shape), changes);
177
+ let next = { ...shape, ...changes };
179
178
  // The head of an arrow is sized by the width of its line (a thicker line has a bigger head, a thinner one keeps the head of the
180
179
  // Arrow tool's width), so a new width draws the arrow again.
181
180
  if (isArrow(next) && 'strokeWidth' in changes)
182
181
  next = reshapeArrow(next);
183
182
  if (next.type === 'path' && 'roundness' in changes) {
184
183
  if (roundnessIsLineEnds(next.shape)) {
185
- var rounded = next.roundness > 0;
186
- next = __assign(__assign({}, next), { lineCap: (rounded ? 'round' : 'butt'), lineJoin: (rounded ? 'round' : 'miter') });
184
+ const rounded = next.roundness > 0;
185
+ next = { ...next, lineCap: (rounded ? 'round' : 'butt'), lineJoin: (rounded ? 'round' : 'miter') };
187
186
  }
188
187
  else {
189
- var commands = regeneratedPathCommands(next, next.width, next.height);
188
+ const commands = regeneratedPathCommands(next, next.width, next.height);
190
189
  if (commands) {
191
- next = __assign(__assign({}, next), { d: serializePathData(mirrorPathCommands(commands, next.width, next.height, next.flipX, next.flipY)) });
190
+ next = { ...next, d: serializePathData(mirrorPathCommands(commands, next.width, next.height, next.flipX, next.flipY)) };
192
191
  }
193
192
  else {
194
193
  // Nothing to rebuild (the path is drawn, not generated): the roundness stays as it was.
195
- next = __assign(__assign({}, next), { roundness: shape.type === 'path' ? shape.roundness : 0 });
194
+ next = { ...next, roundness: shape.type === 'path' ? shape.roundness : 0 };
196
195
  }
197
196
  }
198
197
  }
@@ -0,0 +1,88 @@
1
+ /**
2
+ * What the board remembers of how the person last styled each kind of element, so that the next element of that kind starts the way
3
+ * the last one was left ("after changing the fill and the colour of the stroke and the stroke width, those should be maintained across
4
+ * all the shapes until the user edits them again. The same should be true for the other elements as well", 19 Nov 2026).
5
+ *
6
+ * An element is of one of five kinds, and each kind remembers only what the person did to elements of that kind:
7
+ *
8
+ * - `shape`: a rectangle, an ellipse, a triangle and every shape of the library that has an inside (fill, stroke, width, opacity, roundness).
9
+ * - `lineIcon`: the four shapes of the library that are only a line (a check, a cross, a plus, a minus): the colour of the line, its width,
10
+ * its opacity and how round its ends are. They have no inside, so a fill chosen for a rectangle is no business of theirs, and a colour
11
+ * chosen for a check does not turn the next rectangle's outline.
12
+ * - `arrow`: the colour, the width and the opacity of the line (an arrow has no inside and no corners).
13
+ * - `text`: the font, the size, bold, italic, underline, the alignment, the colour of the letters and the opacity.
14
+ * - `pen`: a line drawn by hand. Its three settings are the pen of the Draw tool (`EngineState.penStyle`), so an edit of a drawn line is
15
+ * an edit of the pen, and the engine keeps the pen itself; this file only says that the edit is one.
16
+ *
17
+ * The memory is a set of patches in the panel's own keys (`StylePatch`). An edit of the selection is turned into one by `styleEditOf`,
18
+ * through `acceptedStylePatch`, so a value is remembered exactly as the shape took it (a width of 0 is 1 for an arrow, a width of 900 is
19
+ * 50), and a new element is given the memory by `withRememberedStyle`, through `applyStylePatch`, the one door every style goes through:
20
+ * the head of an arrow follows its width and the corners of a triangle are drawn again for their roundness, as when the panel is used.
21
+ *
22
+ * Everything here is a pure function of values. The engine holds the memory, records the edits of `setStyle` into it and tells the host,
23
+ * which keeps it for the workspace (`CanvasHost`, `workspaceToolSettings.ts`).
24
+ */
25
+ import type { StylePatch } from './style.js';
26
+ import type { ShapeObject } from './types.js';
27
+ /** The kinds of element whose last style is remembered. */
28
+ export type StyleMemoryKind = 'shape' | 'lineIcon' | 'arrow' | 'text' | 'pen';
29
+ /** The kinds remembered as a patch of the panel's keys: the pen is not (it is the pen of the Draw tool, `EngineState.penStyle`). */
30
+ export type PatchedStyleKind = Exclude<StyleMemoryKind, 'pen'>;
31
+ export declare const PATCHED_STYLE_KINDS: readonly PatchedStyleKind[];
32
+ /**
33
+ * The keys of an edit that each kind remembers. What is not here is the element's own business and is never carried over: its place and
34
+ * size, its text, how it is rotated, what it is tied to. (A key that a kind does not take at all, such as a fill for an arrow, is not
35
+ * here either: `acceptedStylePatch` has already dropped it.)
36
+ */
37
+ export declare const REMEMBERED_STYLE_KEYS: Readonly<Record<StyleMemoryKind, readonly (keyof StylePatch)[]>>;
38
+ /** The kind of element a shape is, or null for what has no style to remember (a picture, a widget card). */
39
+ export declare function styleMemoryKindOf(shape: ShapeObject): StyleMemoryKind | null;
40
+ /** What an edit of one element says about the next element of its kind. */
41
+ export interface StyleEdit {
42
+ kind: StyleMemoryKind;
43
+ style: StylePatch;
44
+ }
45
+ /**
46
+ * What an edit says about the next element of the shape's kind: the keys of the patch that the shape takes and that its kind
47
+ * remembers, at the values the shape takes them at. Null when it says nothing (a picture, or a patch of keys the kind has no use for).
48
+ *
49
+ * The keys the shape already holds are in it too: a person who picks the colour a shape has already has said what the next one should
50
+ * be, and it may be another colour than the memory holds.
51
+ */
52
+ export declare function styleEditOf(shape: ShapeObject, patch: StylePatch): StyleEdit | null;
53
+ /** The last style of each kind of element that is remembered as a patch (empty where the person has not styled one yet). */
54
+ export type RememberedStyles = {
55
+ readonly [kind in PatchedStyleKind]: Readonly<StylePatch>;
56
+ };
57
+ export declare const NO_REMEMBERED_STYLES: RememberedStyles;
58
+ /**
59
+ * The memory with some edits laid over it, and the kinds that came out different. Where the edits say nothing new the very same object
60
+ * comes back with no kind named, so a drag that goes on saying the same colour tells nobody anything. The pen is not part of the memory
61
+ * (the engine keeps it), so an edit of a drawn line is passed over here.
62
+ */
63
+ export declare function rememberStyleEdits(styles: RememberedStyles, edits: readonly StyleEdit[]): {
64
+ styles: RememberedStyles;
65
+ changed: PatchedStyleKind[];
66
+ };
67
+ /**
68
+ * What the storage holds for a kind, as a memory can hold it: key by key, a value that is not one of the key is dropped (the rest stays),
69
+ * a number is brought into its range (a width that was kept when the widest was 200 comes down to 50), and a key the kind does not
70
+ * remember is left out. Anything that is not an object is no memory at all.
71
+ */
72
+ export declare function sanitizeRememberedStyle(kind: PatchedStyleKind, stored: unknown): Readonly<StylePatch>;
73
+ /**
74
+ * What the storage holds for every kind, as a memory can hold it (`sanitizeRememberedStyle` for each). Nothing stored: nothing remembered.
75
+ * A kind the storage has no part for is nothing remembered for that kind.
76
+ */
77
+ export declare function sanitizeRememberedStyles(stored: {
78
+ readonly [kind in PatchedStyleKind]?: unknown;
79
+ } | null): RememberedStyles;
80
+ /**
81
+ * A new element with what the person last chose for its kind laid over what it starts with. `leave` names keys of the memory that the
82
+ * element keeps as it starts (the rounded square keeps the soft corners it is chosen for). The element comes out as the panel would
83
+ * make it: the head of an arrow follows its width, the corners of a triangle are drawn again for their roundness. The very same object
84
+ * back when there is nothing to lay over.
85
+ */
86
+ export declare function withRememberedStyle<Element extends ShapeObject>(element: Element, remembered: Readonly<StylePatch> | undefined, options?: {
87
+ leave?: readonly (keyof StylePatch)[];
88
+ }): Element;