@widgetic/canvas 0.5.45 → 0.5.46

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 (113) hide show
  1. package/README.md +1 -1
  2. package/dist/canvas/autosaveScheduler.js +37 -89
  3. package/dist/canvas/boardFrame.js +1 -1
  4. package/dist/canvas/boardSurface.js +1 -1
  5. package/dist/canvas/canvasLogger.js +7 -19
  6. package/dist/canvas/chromeLayout.js +19 -21
  7. package/dist/canvas/eventScope.js +10 -14
  8. package/dist/canvas/host/CanvasHost.d.ts +6 -2
  9. package/dist/canvas/host/CanvasHost.js +1615 -1847
  10. package/dist/canvas/host/CanvasHostApi.js +4 -19
  11. package/dist/canvas/host/boardFiles.js +35 -51
  12. package/dist/canvas/host/browserServices.js +108 -196
  13. package/dist/canvas/host/conversion.js +82 -170
  14. package/dist/canvas/host/hostObject.js +7 -7
  15. package/dist/canvas/host/nearCards.js +18 -21
  16. package/dist/canvas/host/pageEvents.js +5 -5
  17. package/dist/canvas/host/pictureSaves.js +9 -11
  18. package/dist/canvas/host/screenRects.js +28 -31
  19. package/dist/canvas/host/storedPictures.js +149 -243
  20. package/dist/canvas/host/strokeSnap.js +88 -143
  21. package/dist/canvas/index.d.ts +1 -1
  22. package/dist/canvas/openMarks.js +2 -2
  23. package/dist/canvas/outsideClickDeselect.js +6 -7
  24. package/dist/canvas/panZoomPosition.js +2 -2
  25. package/dist/canvas/preferredTextFont.js +13 -25
  26. package/dist/canvas/shapes/ShapeLibrary.js +138 -148
  27. package/dist/canvas/shapes/shapeImageStore.js +4 -4
  28. package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
  29. package/dist/canvas/toolbarPosition.js +2 -2
  30. package/dist/canvas/types.d.ts +7 -1
  31. package/dist/canvas/ui/colorModel.js +21 -32
  32. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  33. package/dist/canvas/ui/floatingCard.js +21 -21
  34. package/dist/canvas/ui/floatingLayer.js +5 -6
  35. package/dist/canvas/ui/keyHints.js +9 -11
  36. package/dist/canvas/ui/popoverSide.js +2 -3
  37. package/dist/canvas/ui/selectionTraits.js +35 -41
  38. package/dist/canvas/view/CanvasStage.svelte +1 -1
  39. package/dist/canvas/view/erasingMarks.js +7 -7
  40. package/dist/canvas/view/geometry.js +71 -90
  41. package/dist/canvas/view/liftedScene.js +24 -36
  42. package/dist/canvas/view/mountedScene.js +76 -79
  43. package/dist/components/CanvasBoardPlaceholder.svelte +68 -10
  44. package/dist/components/CanvasBoardPlaceholder.svelte.d.ts +10 -2
  45. package/dist/components/CanvasToolbarPlaceholder.svelte +25 -11
  46. package/dist/components/CanvasToolbarPlaceholder.svelte.d.ts +6 -0
  47. package/dist/components/boardLoaderDelay.d.ts +39 -0
  48. package/dist/components/boardLoaderDelay.js +71 -0
  49. package/dist/components/preferenceStorage.js +2 -2
  50. package/dist/engine/EngineCore.d.ts +9 -2
  51. package/dist/engine/EngineCore.js +798 -907
  52. package/dist/engine/codec/canvasDocument.js +192 -155
  53. package/dist/engine/codec/hostReadableKeys.js +1 -1
  54. package/dist/engine/core/arrange.js +26 -38
  55. package/dist/engine/core/arrow.js +79 -92
  56. package/dist/engine/core/arrowBinding.js +98 -116
  57. package/dist/engine/core/arrowBindingRecords.js +23 -38
  58. package/dist/engine/core/brush.js +84 -96
  59. package/dist/engine/core/cameraMove.js +39 -51
  60. package/dist/engine/core/defaults.js +92 -51
  61. package/dist/engine/core/freehand.js +147 -163
  62. package/dist/engine/core/geometry.js +47 -54
  63. package/dist/engine/core/history.js +38 -55
  64. package/dist/engine/core/hitTest.js +68 -81
  65. package/dist/engine/core/matrix.js +18 -20
  66. package/dist/engine/core/pathData.js +183 -210
  67. package/dist/engine/core/rotationReset.js +5 -6
  68. package/dist/engine/core/scene.js +160 -224
  69. package/dist/engine/core/scribble.js +59 -84
  70. package/dist/engine/core/shapePaths.js +12 -15
  71. package/dist/engine/core/shapeTools.js +72 -63
  72. package/dist/engine/core/snapping.js +65 -117
  73. package/dist/engine/core/style.js +32 -65
  74. package/dist/engine/core/transform.js +84 -95
  75. package/dist/engine/core/types.js +4 -4
  76. package/dist/engine/core/viewport.js +23 -36
  77. package/dist/engine/input/PointerController.js +513 -526
  78. package/dist/engine/input/arrowHandles.js +12 -12
  79. package/dist/engine/input/gestures.js +267 -310
  80. package/dist/engine/input/hoverCursor.js +1 -1
  81. package/dist/engine/input/keyboard.js +35 -39
  82. package/dist/engine/input/selectionHandles.js +45 -50
  83. package/dist/engine/input/types.js +1 -1
  84. package/dist/engine/render/rasterize.js +86 -158
  85. package/dist/engine/state.js +6 -17
  86. package/dist/engine/text/layoutText.js +43 -62
  87. package/dist/engine/text/textMetrics.js +8 -10
  88. package/dist/engine/widgets.js +101 -137
  89. package/dist/fonts/interFont.js +30 -83
  90. package/dist/fonts/workspaceFonts.js +33 -92
  91. package/dist/i18n/labels.js +4 -4
  92. package/dist/i18n/language.js +4 -4
  93. package/dist/i18n/messages.js +1 -1
  94. package/dist/i18n/shortcuts.js +14 -14
  95. package/dist/index.d.ts +1 -1
  96. package/dist/poster/boardPlacement.js +28 -30
  97. package/dist/poster/boardPoster.js +58 -83
  98. package/dist/poster/paintBoardPoster.js +16 -39
  99. package/dist/poster/posterPictures.js +27 -43
  100. package/dist/settings/rememberedTool.d.ts +50 -0
  101. package/dist/settings/rememberedTool.js +68 -0
  102. package/dist/settings/workspaceToolSettings.d.ts +8 -0
  103. package/dist/settings/workspaceToolSettings.js +35 -48
  104. package/dist/tools/components/catalog.js +64 -74
  105. package/dist/tools/components/grouping.js +6 -28
  106. package/dist/tools/definitions.js +5 -5
  107. package/dist/tools/executors.js +137 -169
  108. package/dist/tools/hostAdapter.js +11 -13
  109. package/dist/tools/sceneSummary.js +43 -57
  110. package/dist/tools/sketchIntent.js +13 -21
  111. package/dist/tools/styleArguments.js +19 -21
  112. package/dist/tools/types.js +1 -1
  113. package/package.json +2 -2
@@ -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. */
@@ -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
  }
@@ -11,8 +11,8 @@
11
11
  import { boxToWorldMatrix } from '../../engine/core/matrix.js';
12
12
  import { shapeBounds } from '../../engine/core/scene.js';
13
13
  function cssScaleOf(frame) {
14
- var layoutWidth = frame.layoutWidth && frame.layoutWidth > 0 ? frame.layoutWidth : frame.width;
15
- var layoutHeight = frame.layoutHeight && frame.layoutHeight > 0 ? frame.layoutHeight : frame.height;
14
+ const layoutWidth = frame.layoutWidth && frame.layoutWidth > 0 ? frame.layoutWidth : frame.width;
15
+ const layoutHeight = frame.layoutHeight && frame.layoutHeight > 0 ? frame.layoutHeight : frame.height;
16
16
  return {
17
17
  scaleX: layoutWidth > 0 && frame.width > 0 ? frame.width / layoutWidth : 1,
18
18
  scaleY: layoutHeight > 0 && frame.height > 0 ? frame.height / layoutHeight : 1
@@ -20,7 +20,7 @@ function cssScaleOf(frame) {
20
20
  }
21
21
  /** A point of the world on the page. */
22
22
  export function worldPointToPage(viewport, frame, x, y) {
23
- var _a = cssScaleOf(frame), scaleX = _a.scaleX, scaleY = _a.scaleY;
23
+ const { scaleX, scaleY } = cssScaleOf(frame);
24
24
  return {
25
25
  x: frame.left + (viewport.x + x * viewport.zoom) * scaleX,
26
26
  y: frame.top + (viewport.y + y * viewport.zoom) * scaleY
@@ -28,12 +28,12 @@ export function worldPointToPage(viewport, frame, x, y) {
28
28
  }
29
29
  /** The matrix from a box's own pixels to the page, or null when something is not a finite number. */
30
30
  export function boxToPageMatrix(box, viewport, frame) {
31
- var _a = cssScaleOf(frame), scaleX = _a.scaleX, scaleY = _a.scaleY;
32
- var world = boxToWorldMatrix(box);
31
+ const { scaleX, scaleY } = cssScaleOf(frame);
32
+ const world = boxToWorldMatrix(box);
33
33
  // page = frame + scale * (viewport.translate + zoom * world)
34
- var zoomX = viewport.zoom * scaleX;
35
- var zoomY = viewport.zoom * scaleY;
36
- var matrix = [
34
+ const zoomX = viewport.zoom * scaleX;
35
+ const zoomY = viewport.zoom * scaleY;
36
+ const matrix = [
37
37
  world[0] * zoomX,
38
38
  world[1] * zoomY,
39
39
  world[2] * zoomX,
@@ -45,34 +45,31 @@ export function boxToPageMatrix(box, viewport, frame) {
45
45
  }
46
46
  /** The geometry of a card on the page. Null when the numbers are not usable. */
47
47
  export function widgetPreviewGeometry(shape, viewport, frame) {
48
- var matrix = boxToPageMatrix(shape, viewport, frame);
48
+ const matrix = boxToPageMatrix(shape, viewport, frame);
49
49
  if (!matrix)
50
50
  return null;
51
- var localWidth = shape.width || 1;
52
- var localHeight = shape.height || 1;
53
- var corners = [
51
+ const localWidth = shape.width || 1;
52
+ const localHeight = shape.height || 1;
53
+ const corners = [
54
54
  [0, 0],
55
55
  [localWidth, 0],
56
56
  [0, localHeight],
57
57
  [localWidth, localHeight]
58
- ].map(function (_a) {
59
- var x = _a[0], y = _a[1];
60
- return ({
61
- x: matrix[0] * x + matrix[2] * y + matrix[4],
62
- y: matrix[1] * x + matrix[3] * y + matrix[5]
63
- });
64
- });
65
- var xs = corners.map(function (corner) { return corner.x; });
66
- var ys = corners.map(function (corner) { return corner.y; });
67
- var left = Math.min.apply(Math, xs);
68
- var top = Math.min.apply(Math, ys);
58
+ ].map(([x, y]) => ({
59
+ x: matrix[0] * x + matrix[2] * y + matrix[4],
60
+ y: matrix[1] * x + matrix[3] * y + matrix[5]
61
+ }));
62
+ const xs = corners.map((corner) => corner.x);
63
+ const ys = corners.map((corner) => corner.y);
64
+ const left = Math.min(...xs);
65
+ const top = Math.min(...ys);
69
66
  return {
70
- left: left,
71
- top: top,
72
- width: Math.max.apply(Math, xs) - left,
73
- height: Math.max.apply(Math, ys) - top,
74
- localWidth: localWidth,
75
- localHeight: localHeight,
67
+ left,
68
+ top,
69
+ width: Math.max(...xs) - left,
70
+ height: Math.max(...ys) - top,
71
+ localWidth,
72
+ localHeight,
76
73
  // The old canvas answered with the matrix of the card's pixels, one unit per local pixel.
77
74
  matrix: [matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]]
78
75
  };
@@ -83,8 +80,8 @@ export function screenRectOfShape(shape, viewport, frame) {
83
80
  }
84
81
  /** The box of a rectangle of the world on the page, with the board it sits on. */
85
82
  export function screenRectOfBounds(bounds, viewport, frame) {
86
- var topLeft = worldPointToPage(viewport, frame, bounds.x, bounds.y);
87
- var bottomRight = worldPointToPage(viewport, frame, bounds.x + bounds.width, bounds.y + bounds.height);
83
+ const topLeft = worldPointToPage(viewport, frame, bounds.x, bounds.y);
84
+ const bottomRight = worldPointToPage(viewport, frame, bounds.x + bounds.width, bounds.y + bounds.height);
88
85
  return {
89
86
  left: Math.min(topLeft.x, bottomRight.x),
90
87
  top: Math.min(topLeft.y, bottomRight.y),