@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
@@ -9,205 +9,117 @@
9
9
  *
10
10
  * Plain TypeScript over the engine's records and the rasterizer: runs in Node.
11
11
  */
12
- var __assign = (this && this.__assign) || function () {
13
- __assign = Object.assign || function(t) {
14
- for (var s, i = 1, n = arguments.length; i < n; i++) {
15
- s = arguments[i];
16
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
17
- t[p] = s[p];
18
- }
19
- return t;
20
- };
21
- return __assign.apply(this, arguments);
22
- };
23
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
24
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
25
- return new (P || (P = Promise))(function (resolve, reject) {
26
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
27
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
28
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
29
- step((generator = generator.apply(thisArg, _arguments || [])).next());
30
- });
31
- };
32
- var __generator = (this && this.__generator) || function (thisArg, body) {
33
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
34
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
35
- function verb(n) { return function (v) { return step([n, v]); }; }
36
- function step(op) {
37
- if (f) throw new TypeError("Generator is already executing.");
38
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
39
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
40
- if (y = 0, t) op = [op[0] & 2, t.value];
41
- switch (op[0]) {
42
- case 0: case 1: t = op; break;
43
- case 4: _.label++; return { value: op[1], done: false };
44
- case 5: _.label++; y = op[1]; op = [0]; continue;
45
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
46
- default:
47
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
48
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
49
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
50
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
51
- if (t[2]) _.ops.pop();
52
- _.trys.pop(); continue;
53
- }
54
- op = body.call(thisArg, _);
55
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
56
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
57
- }
58
- };
59
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
60
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
61
- if (ar || !(i in from)) {
62
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
63
- ar[i] = from[i];
64
- }
65
- }
66
- return to.concat(ar || Array.prototype.slice.call(from));
67
- };
68
12
  import { leafShapesOf } from '../../engine/core/scene.js';
69
13
  import { rasterBoundsOf, renderShapesToDataUrl } from '../../engine/render/rasterize.js';
70
- import { selectionConversionBounds } from '../../engine/widgets.js';
14
+ import { ConversionRegistry, selectionConversionBounds } from '../../engine/widgets.js';
71
15
  import { hostCustomTypeOf, hostObjectById, hostTypeOf, selectedHostObject } from './hostObject.js';
72
16
  /** Message key integrators pass through `translate` as `untitledShapeName` in {@link buildConversionPayload}. */
73
- export var UNTITLED_SHAPE_MESSAGE_KEY = 'canvas.defaults.untitledShape';
17
+ export const UNTITLED_SHAPE_MESSAGE_KEY = 'canvas.defaults.untitledShape';
74
18
  /** The background of a screenshot: opaque, so a model that reads a transparent PNG as black still sees the drawing. */
75
- export var SCREENSHOT_BACKGROUND = '#ffffff';
19
+ export const SCREENSHOT_BACKGROUND = '#ffffff';
76
20
  /** A screenshot is twice the size of the board (as the canvas it replaces made them), so small text stays legible. */
77
- export var SCREENSHOT_SCALE = 2;
21
+ export const SCREENSHOT_SCALE = 2;
78
22
  /** What is selected, as the conversion and the capture see it. Null when nothing is. */
79
23
  export function describeSelection(engine) {
80
- var _a;
81
- var selectedIds = engine.state.selectedIds;
24
+ const { selectedIds } = engine.state;
82
25
  if (selectedIds.length === 0)
83
26
  return null;
84
- var units = engine.selectedObjects();
85
- var shapes = leafShapesOf(engine.state.scene, selectedIds);
86
- var bounds = selectionConversionBounds(engine);
27
+ const units = engine.selectedObjects();
28
+ const shapes = leafShapesOf(engine.state.scene, selectedIds);
29
+ const bounds = selectionConversionBounds(engine);
87
30
  if (units.length === 0 || shapes.length === 0 || !bounds)
88
31
  return null;
89
- var host = selectedHostObject(engine);
90
- var name = host ? (host.id === '' ? host.type : ((_a = host._customType) !== null && _a !== void 0 ? _a : host.type)) : 'object';
91
- var kinds = new Set(shapes.map(function (shape) { var _a; return (_a = hostCustomTypeOf(shape)) !== null && _a !== void 0 ? _a : hostTypeOf(shape); }));
32
+ const host = selectedHostObject(engine);
33
+ const name = host ? (host.id === '' ? host.type : (host._customType ?? host.type)) : 'object';
34
+ const kinds = new Set(shapes.map((shape) => hostCustomTypeOf(shape) ?? hostTypeOf(shape)));
92
35
  return {
93
- units: units,
94
- shapes: shapes,
95
- bounds: bounds,
96
- name: name,
97
- shapeTypes: __spreadArray([], kinds, true),
98
- hasImages: shapes.some(function (shape) { return shape.type === 'image' && Boolean(shape.src || shape.imageRef); }),
99
- hasText: shapes.some(function (shape) { return shape.type === 'text'; })
36
+ units,
37
+ shapes,
38
+ bounds,
39
+ name,
40
+ shapeTypes: [...kinds],
41
+ hasImages: shapes.some((shape) => shape.type === 'image' && Boolean(shape.src || shape.imageRef)),
42
+ hasText: shapes.some((shape) => shape.type === 'text')
100
43
  };
101
44
  }
102
45
  /** A PNG of some shapes on a plain background, cropped to what they cover. Empty when there is nothing to draw. */
103
- export function screenshotOfShapes(shapes, deps) {
104
- return __awaiter(this, void 0, Promise, function () {
105
- var error_1;
106
- return __generator(this, function (_a) {
107
- switch (_a.label) {
108
- case 0:
109
- if (shapes.length === 0 || !rasterBoundsOf(shapes))
110
- return [2 /*return*/, ''];
111
- _a.label = 1;
112
- case 1:
113
- _a.trys.push([1, 3, , 4]);
114
- return [4 /*yield*/, renderShapesToDataUrl(shapes, deps.raster, {
115
- scale: SCREENSHOT_SCALE,
116
- background: SCREENSHOT_BACKGROUND,
117
- widgetFallbackName: deps.widgetFallbackName
118
- })];
119
- case 2: return [2 /*return*/, _a.sent()];
120
- case 3:
121
- error_1 = _a.sent();
122
- console.warn('Canvas: could not draw the screenshot', error_1);
123
- return [2 /*return*/, ''];
124
- case 4: return [2 /*return*/];
125
- }
46
+ export async function screenshotOfShapes(shapes, deps) {
47
+ if (shapes.length === 0 || !rasterBoundsOf(shapes))
48
+ return '';
49
+ try {
50
+ return await renderShapesToDataUrl(shapes, deps.raster, {
51
+ scale: SCREENSHOT_SCALE,
52
+ background: SCREENSHOT_BACKGROUND,
53
+ widgetFallbackName: deps.widgetFallbackName
126
54
  });
127
- });
55
+ }
56
+ catch (error) {
57
+ console.warn('Canvas: could not draw the screenshot', error);
58
+ return '';
59
+ }
128
60
  }
129
61
  /** What the host needs to turn a selection into a widget, or null when nothing is selected. */
130
- export function buildConversionPayload(deps) {
131
- return __awaiter(this, void 0, Promise, function () {
132
- var engine, conversions, selection, single, frameId, screenshot, frame;
133
- return __generator(this, function (_a) {
134
- switch (_a.label) {
135
- case 0:
136
- engine = deps.engine, conversions = deps.conversions;
137
- selection = describeSelection(engine);
138
- if (!selection)
139
- return [2 /*return*/, null];
140
- single = selection.units.length === 1 ? selection.units[0] : null;
141
- frameId = single ? single.id : engine.services.createId('selection');
142
- if (!single) {
143
- conversions.remember(frameId, { unitIds: selection.units.map(function (unit) { return unit.id; }), bounds: selection.bounds });
144
- }
145
- return [4 /*yield*/, screenshotOfShapes(selection.shapes, deps)];
146
- case 1:
147
- screenshot = _a.sent();
148
- frame = single ? hostObjectById(engine, single.id) : selectedHostObject(engine);
149
- return [2 /*return*/, {
150
- frameName: selection.name || deps.untitledShapeName,
151
- frameId: frameId,
152
- screenshot: screenshot,
153
- canvasData: {
154
- frame: frame ? __assign({}, frame) : {},
155
- children: [],
156
- bounds: { left: selection.bounds.x, top: selection.bounds.y, width: selection.bounds.width, height: selection.bounds.height }
157
- },
158
- metadata: {
159
- childCount: selection.shapes.length,
160
- shapeTypes: selection.shapeTypes,
161
- hasImages: selection.hasImages,
162
- hasText: selection.hasText
163
- }
164
- }];
165
- }
166
- });
167
- });
62
+ export async function buildConversionPayload(deps) {
63
+ const { engine, conversions } = deps;
64
+ const selection = describeSelection(engine);
65
+ if (!selection)
66
+ return null;
67
+ // One object is converted by its own id. Several have none: the selection gets one and is remembered under it,
68
+ // before anything (the screenshot takes a moment) can clear the selection.
69
+ const single = selection.units.length === 1 ? selection.units[0] : null;
70
+ const frameId = single ? single.id : engine.services.createId('selection');
71
+ if (!single) {
72
+ conversions.remember(frameId, { unitIds: selection.units.map((unit) => unit.id), bounds: selection.bounds });
73
+ }
74
+ const screenshot = await screenshotOfShapes(selection.shapes, deps);
75
+ const frame = single ? hostObjectById(engine, single.id) : selectedHostObject(engine);
76
+ return {
77
+ frameName: selection.name || deps.untitledShapeName,
78
+ frameId,
79
+ screenshot,
80
+ canvasData: {
81
+ frame: frame ? { ...frame } : {},
82
+ children: [],
83
+ bounds: { left: selection.bounds.x, top: selection.bounds.y, width: selection.bounds.width, height: selection.bounds.height }
84
+ },
85
+ metadata: {
86
+ childCount: selection.shapes.length,
87
+ shapeTypes: selection.shapeTypes,
88
+ hasImages: selection.hasImages,
89
+ hasText: selection.hasText
90
+ }
91
+ };
168
92
  }
169
93
  /** The extra facts the host is given about what was captured. */
170
94
  function metadataOf(selection) {
171
- var _a, _b, _c;
172
- var metadata = {};
173
- var only = selection.shapes.length === 1 && selection.units.length === 1 ? selection.shapes[0] : null;
95
+ const metadata = {};
96
+ const only = selection.shapes.length === 1 && selection.units.length === 1 ? selection.shapes[0] : null;
174
97
  if (only && only.type === 'image') {
175
98
  metadata.hasImage = Boolean(only.src || only.imageRef);
176
- metadata.imageUrl = (_a = only.src) !== null && _a !== void 0 ? _a : null;
177
- metadata.originalFilename = (_b = only.fileName) !== null && _b !== void 0 ? _b : null;
99
+ metadata.imageUrl = only.src ?? null;
100
+ metadata.originalFilename = only.fileName ?? null;
178
101
  }
179
102
  if (only && only.type === 'text')
180
103
  metadata.text = only.text;
181
- if (selection.units.length > 1 || ((_c = selection.units[0]) === null || _c === void 0 ? void 0 : _c.type) === 'group')
104
+ if (selection.units.length > 1 || selection.units[0]?.type === 'group')
182
105
  metadata.objectCount = selection.shapes.length;
183
106
  return metadata;
184
107
  }
185
108
  /** What the host is given when a selection is captured (the "capture" button of the selection panel). */
186
- export function buildCapturePayload(deps) {
187
- return __awaiter(this, void 0, Promise, function () {
188
- var engine, selection, single, screenshot, host;
189
- var _a, _b;
190
- return __generator(this, function (_c) {
191
- switch (_c.label) {
192
- case 0:
193
- engine = deps.engine;
194
- selection = describeSelection(engine);
195
- if (!selection)
196
- return [2 /*return*/, null];
197
- single = selection.units.length === 1 ? selection.units[0] : null;
198
- return [4 /*yield*/, screenshotOfShapes(selection.shapes, deps)];
199
- case 1:
200
- screenshot = _c.sent();
201
- host = selectedHostObject(engine);
202
- return [2 /*return*/, {
203
- screenshot: screenshot,
204
- objectType: (_a = host === null || host === void 0 ? void 0 : host.type) !== null && _a !== void 0 ? _a : 'unknown',
205
- customType: (_b = host === null || host === void 0 ? void 0 : host._customType) !== null && _b !== void 0 ? _b : undefined,
206
- bounds: { left: selection.bounds.x, top: selection.bounds.y, width: selection.bounds.width, height: selection.bounds.height },
207
- objectId: single ? single.id : engine.services.createId('selection'),
208
- metadata: metadataOf(selection)
209
- }];
210
- }
211
- });
212
- });
109
+ export async function buildCapturePayload(deps) {
110
+ const { engine } = deps;
111
+ const selection = describeSelection(engine);
112
+ if (!selection)
113
+ return null;
114
+ const single = selection.units.length === 1 ? selection.units[0] : null;
115
+ const screenshot = await screenshotOfShapes(selection.shapes, deps);
116
+ const host = selectedHostObject(engine);
117
+ return {
118
+ screenshot,
119
+ objectType: host?.type ?? 'unknown',
120
+ customType: host?._customType ?? undefined,
121
+ bounds: { left: selection.bounds.x, top: selection.bounds.y, width: selection.bounds.width, height: selection.bounds.height },
122
+ objectId: single ? single.id : engine.services.createId('selection'),
123
+ metadata: metadataOf(selection)
124
+ };
213
125
  }
@@ -41,7 +41,7 @@ export function hostCustomTypeOf(object) {
41
41
  return null;
42
42
  }
43
43
  function viewOf(object, index, scene) {
44
- var view = {
44
+ const view = {
45
45
  id: object.id,
46
46
  _objectId: object.id,
47
47
  type: hostTypeOf(object),
@@ -54,7 +54,7 @@ function viewOf(object, index, scene) {
54
54
  view._isPrimaryWidget = object.isPrimary;
55
55
  }
56
56
  if (object.type === 'group') {
57
- view.objects = scene.filter(function (member) { return member.parentId === object.id; }).map(function (member) { return viewOf(member, index, scene); });
57
+ view.objects = scene.filter((member) => member.parentId === object.id).map((member) => viewOf(member, index, scene));
58
58
  }
59
59
  return view;
60
60
  }
@@ -62,7 +62,7 @@ function viewOf(object, index, scene) {
62
62
  export function hostObjectById(engine, id) {
63
63
  if (!id)
64
64
  return null;
65
- var object = engine.getObject(id);
65
+ const object = engine.getObject(id);
66
66
  if (!object)
67
67
  return null;
68
68
  return viewOf(object, engine.sceneIndex(), engine.state.scene);
@@ -72,11 +72,11 @@ export function hostObjectById(engine, id) {
72
72
  * Null when nothing is selected.
73
73
  */
74
74
  export function selectedHostObject(engine) {
75
- var selected = engine.selectedObjects();
75
+ const selected = engine.selectedObjects();
76
76
  if (selected.length === 0)
77
77
  return null;
78
- var index = engine.sceneIndex();
79
- var scene = engine.state.scene;
78
+ const index = engine.sceneIndex();
79
+ const scene = engine.state.scene;
80
80
  if (selected.length === 1)
81
81
  return viewOf(selected[0], index, scene);
82
82
  return {
@@ -84,7 +84,7 @@ export function selectedHostObject(engine) {
84
84
  _objectId: '',
85
85
  type: 'activeSelection',
86
86
  _customType: null,
87
- objects: selected.map(function (object) { return viewOf(object, index, scene); })
87
+ objects: selected.map((object) => viewOf(object, index, scene))
88
88
  };
89
89
  }
90
90
  /** The shapes behind a list of units (a group counts through its members), for the conversion payload. */
@@ -25,47 +25,44 @@
25
25
  import { rectsIntersect } from '../../engine/core/geometry.js';
26
26
  import { visibleWorldRect } from '../../engine/core/viewport.js';
27
27
  /** A board with fewer cards than this lists every one of them. */
28
- export var NEAR_CARDS_MINIMUM = 8;
28
+ export const NEAR_CARDS_MINIMUM = 8;
29
29
  /** How far past the view a card is listed, as a share of the view's width and height, on every side. */
30
- export var NEAR_CARD_MARGIN_RATIO = 1;
30
+ export const NEAR_CARD_MARGIN_RATIO = 1;
31
31
  /** How far past the view a card that is listed already stays listed, in the same measure. More than `NEAR_CARD_MARGIN_RATIO`. */
32
- export var KEEP_CARD_MARGIN_RATIO = 2;
32
+ export const KEEP_CARD_MARGIN_RATIO = 2;
33
33
  /** A view with `ratio` of its width and height added on every side. */
34
34
  function viewWithMargin(view, ratio) {
35
- var marginX = view.width * ratio;
36
- var marginY = view.height * ratio;
35
+ const marginX = view.width * ratio;
36
+ const marginY = view.height * ratio;
37
37
  return { x: view.x - marginX, y: view.y - marginY, width: view.width + marginX * 2, height: view.height + marginY * 2 };
38
38
  }
39
39
  /** A rectangle made of finite numbers, with some size: anything else says the board has no size (or no view) yet. */
40
40
  function isUsableView(view) {
41
41
  return Number.isFinite(view.x) && Number.isFinite(view.y) && Number.isFinite(view.width) && Number.isFinite(view.height) && view.width > 0 && view.height > 0;
42
42
  }
43
- export function createNearCards(options) {
44
- var _a, _b, _c;
45
- if (options === void 0) { options = {}; }
46
- var minimumCards = (_a = options.minimumCards) !== null && _a !== void 0 ? _a : NEAR_CARDS_MINIMUM;
47
- var nearMarginRatio = (_b = options.nearMarginRatio) !== null && _b !== void 0 ? _b : NEAR_CARD_MARGIN_RATIO;
48
- var keepMarginRatio = Math.max(nearMarginRatio, (_c = options.keepMarginRatio) !== null && _c !== void 0 ? _c : KEEP_CARD_MARGIN_RATIO);
43
+ export function createNearCards(options = {}) {
44
+ const minimumCards = options.minimumCards ?? NEAR_CARDS_MINIMUM;
45
+ const nearMarginRatio = options.nearMarginRatio ?? NEAR_CARD_MARGIN_RATIO;
46
+ const keepMarginRatio = Math.max(nearMarginRatio, options.keepMarginRatio ?? KEEP_CARD_MARGIN_RATIO);
49
47
  /** The ids that were listed the last time: the cards that keep their place while they are inside the keep area. */
50
- var listed = new Set();
48
+ let listed = new Set();
51
49
  function listEveryCard(cards) {
52
- listed = new Set(cards.map(function (card) { return card.widgetId; }));
50
+ listed = new Set(cards.map((card) => card.widgetId));
53
51
  return new Set(listed);
54
52
  }
55
53
  return {
56
- choose: function (cards, viewport, viewSize) {
54
+ choose(cards, viewport, viewSize) {
57
55
  if (cards.length < minimumCards)
58
56
  return listEveryCard(cards);
59
57
  if (!Number.isFinite(viewport.zoom) || viewport.zoom <= 0)
60
58
  return listEveryCard(cards);
61
- var view = visibleWorldRect(viewport, viewSize);
59
+ const view = visibleWorldRect(viewport, viewSize);
62
60
  if (!isUsableView(view))
63
61
  return listEveryCard(cards);
64
- var nearArea = viewWithMargin(view, nearMarginRatio);
65
- var keepArea = viewWithMargin(view, keepMarginRatio);
66
- var next = new Set();
67
- for (var _i = 0, cards_1 = cards; _i < cards_1.length; _i++) {
68
- var card = cards_1[_i];
62
+ const nearArea = viewWithMargin(view, nearMarginRatio);
63
+ const keepArea = viewWithMargin(view, keepMarginRatio);
64
+ const next = new Set();
65
+ for (const card of cards) {
69
66
  if (card.always || rectsIntersect(nearArea, card.bounds) || (listed.has(card.widgetId) && rectsIntersect(keepArea, card.bounds))) {
70
67
  next.add(card.widgetId);
71
68
  }
@@ -73,7 +70,7 @@ export function createNearCards(options) {
73
70
  listed = next;
74
71
  return new Set(next);
75
72
  },
76
- reset: function () {
73
+ reset() {
77
74
  if (listed.size > 0)
78
75
  listed = new Set();
79
76
  }
@@ -16,18 +16,18 @@
16
16
  * Kept free of Svelte so that Node can test it. A page rendered on the server has no `window` and gets nothing.
17
17
  */
18
18
  import { canvasWarn } from '../canvasLogger.js';
19
- export var CANVAS_SELECT_TOOL_EVENT = 'widgetic:canvas-select-tool';
20
- export var CANVAS_TOOL_EVENT = 'widgetic:canvas-tool';
21
- export var WIDGET_POINTER_BLOCK_EVENT = 'widgetic:widget-shape-pointer-block';
19
+ export const CANVAS_SELECT_TOOL_EVENT = 'widgetic:canvas-select-tool';
20
+ export const CANVAS_TOOL_EVENT = 'widgetic:canvas-tool';
21
+ export const WIDGET_POINTER_BLOCK_EVENT = 'widgetic:widget-shape-pointer-block';
22
22
  function dispatchOnWindow(name, detail) {
23
23
  if (typeof window === 'undefined' || typeof CustomEvent === 'undefined')
24
24
  return;
25
25
  try {
26
- window.dispatchEvent(detail === undefined ? new CustomEvent(name) : new CustomEvent(name, { detail: detail }));
26
+ window.dispatchEvent(detail === undefined ? new CustomEvent(name) : new CustomEvent(name, { detail }));
27
27
  }
28
28
  catch (error) {
29
29
  // A page that cannot take the event keeps its canvas.
30
- canvasWarn("Canvas: could not send ".concat(name), error);
30
+ canvasWarn(`Canvas: could not send ${name}`, error);
31
31
  }
32
32
  }
33
33
  /** The Select tool was chosen. */
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Gathers what happens in a burst (the steps of a drag of a slider, the ticks of a colour picker) and hands it over once, when the burst
3
+ * pauses: the host uses it to say a thing in the console once for a drag and not once for every step of it.
4
+ *
5
+ * It is only a delay and a set: nothing is ever kept past the pause, and a collector that is cancelled (the board is closed) says nothing.
6
+ * The delay is the host's to choose, so the console says it at the moment the settings of the workspace are written (400 ms).
7
+ */
8
+ export interface PauseCollector<Item> {
9
+ /** Notes what happened and starts the wait again: the pause is counted from the last thing that happened. */
10
+ add(items: readonly Item[]): void;
11
+ /** Forgets what was gathered and says nothing about it (the board is gone). */
12
+ cancel(): void;
13
+ }
14
+ /**
15
+ * @param delayMs How long nothing may happen before what was gathered is handed over.
16
+ * @param onPause Called once for each burst with what happened in it, each item once, in the order it first happened.
17
+ */
18
+ export declare function createPauseCollector<Item>(delayMs: number, onPause: (items: Item[]) => void): PauseCollector<Item>;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Gathers what happens in a burst (the steps of a drag of a slider, the ticks of a colour picker) and hands it over once, when the burst
3
+ * pauses: the host uses it to say a thing in the console once for a drag and not once for every step of it.
4
+ *
5
+ * It is only a delay and a set: nothing is ever kept past the pause, and a collector that is cancelled (the board is closed) says nothing.
6
+ * The delay is the host's to choose, so the console says it at the moment the settings of the workspace are written (400 ms).
7
+ */
8
+ import { canvasWarn } from '../canvasLogger.js';
9
+ /**
10
+ * @param delayMs How long nothing may happen before what was gathered is handed over.
11
+ * @param onPause Called once for each burst with what happened in it, each item once, in the order it first happened.
12
+ */
13
+ export function createPauseCollector(delayMs, onPause) {
14
+ const gathered = new Set();
15
+ let timer = null;
16
+ const cancel = () => {
17
+ if (timer !== null)
18
+ clearTimeout(timer);
19
+ timer = null;
20
+ gathered.clear();
21
+ };
22
+ return {
23
+ add(items) {
24
+ if (items.length === 0)
25
+ return;
26
+ for (const item of items)
27
+ gathered.add(item);
28
+ if (timer !== null)
29
+ clearTimeout(timer);
30
+ timer = setTimeout(() => {
31
+ timer = null;
32
+ const burst = [...gathered];
33
+ gathered.clear();
34
+ // A handler that fails must not take the page with it: it is a console line.
35
+ try {
36
+ onPause(burst);
37
+ }
38
+ catch (error) {
39
+ canvasWarn('Canvas: a pause handler failed', error);
40
+ }
41
+ }, delayMs);
42
+ },
43
+ cancel
44
+ };
45
+ }
@@ -1,12 +1,12 @@
1
1
  export function createPictureSaveMemory() {
2
2
  /** The store the memory is about. */
3
- var rememberedFor = null;
3
+ let rememberedFor = null;
4
4
  /** Reference → the bytes the store accepted for it. */
5
- var remembered = new Map();
5
+ let remembered = new Map();
6
6
  /** What the save that is on its way has handed over or found already handed over, by reference; null between saves. */
7
- var thisSave = null;
7
+ let thisSave = null;
8
8
  return {
9
- startSave: function (store) {
9
+ startSave(store) {
10
10
  if (!store) {
11
11
  thisSave = null;
12
12
  return null;
@@ -15,10 +15,10 @@ export function createPictureSaveMemory() {
15
15
  rememberedFor = store;
16
16
  remembered = new Map();
17
17
  }
18
- var seenInThisSave = new Map();
18
+ const seenInThisSave = new Map();
19
19
  thisSave = seenInThisSave;
20
20
  return {
21
- save: function (reference, dataUrl) {
21
+ save(reference, dataUrl) {
22
22
  // A throw from the store is the writer's to deal with, and nothing is noted for it.
23
23
  if (remembered.get(reference) !== dataUrl)
24
24
  store.save(reference, dataUrl);
@@ -26,8 +26,8 @@ export function createPictureSaveMemory() {
26
26
  }
27
27
  };
28
28
  },
29
- finishSave: function (completed) {
30
- var seenInThisSave = thisSave;
29
+ finishSave(completed) {
30
+ const seenInThisSave = thisSave;
31
31
  thisSave = null;
32
32
  if (!seenInThisSave)
33
33
  return;
@@ -35,10 +35,8 @@ export function createPictureSaveMemory() {
35
35
  remembered = seenInThisSave;
36
36
  return;
37
37
  }
38
- for (var _i = 0, seenInThisSave_1 = seenInThisSave; _i < seenInThisSave_1.length; _i++) {
39
- var _a = seenInThisSave_1[_i], reference = _a[0], dataUrl = _a[1];
38
+ for (const [reference, dataUrl] of seenInThisSave)
40
39
  remembered.set(reference, dataUrl);
41
- }
42
40
  }
43
41
  };
44
42
  }