@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
@@ -12,26 +12,6 @@
12
12
  * - Everything read is validated and clamped, because a saved canvas is data from a database and from other
13
13
  * people's browsers: colours, fonts and addresses that could carry more than a value are replaced by defaults.
14
14
  */
15
- var __assign = (this && this.__assign) || function () {
16
- __assign = Object.assign || function(t) {
17
- for (var s, i = 1, n = arguments.length; i < n; i++) {
18
- s = arguments[i];
19
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
20
- t[p] = s[p];
21
- }
22
- return t;
23
- };
24
- return __assign.apply(this, arguments);
25
- };
26
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
27
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
28
- if (ar || !(i in from)) {
29
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
30
- ar[i] = from[i];
31
- }
32
- }
33
- return to.concat(ar || Array.prototype.slice.call(from));
34
- };
35
15
  import { arrowPointsOfLegacyPath, buildArrow } from '../core/arrow.js';
36
16
  import { dropDanglingBindings, withBindings } from '../core/arrowBindingRecords.js';
37
17
  import { BRUSH_MAX_POINTS, brushOutlineData } from '../core/brush.js';
@@ -45,17 +25,18 @@ import { CANVAS_DOCUMENT_VERSION, MIN_OBJECT_SIZE } from '../core/types.js';
45
25
  import { sanitizeViewport } from '../core/viewport.js';
46
26
  import { HOST_READABLE_KEYS } from './hostReadableKeys.js';
47
27
  /** The most objects a board may hold when it is read; a text with more is cut here and says so. */
48
- export var MAX_OBJECTS_PER_DOCUMENT = 20000;
49
- var MAX_TEXT_LENGTH = 100000;
50
- var MAX_PATH_DATA_LENGTH = 500000;
51
- var MAX_COORDINATE = 1000000;
52
- var MAX_SIZE = 100000;
28
+ export const MAX_OBJECTS_PER_DOCUMENT = 20_000;
29
+ const MAX_TEXT_LENGTH = 100_000;
30
+ const MAX_PATH_DATA_LENGTH = 500_000;
31
+ const MAX_COORDINATE = 1_000_000;
32
+ const MAX_SIZE = 100_000;
53
33
  // --- Writing -----------------------------------------------------------------------------------
54
- var BOX_KEYS = ['x', 'y', 'width', 'height', 'rotation', 'opacity'];
55
- var PAINT_KEYS = ['fill', 'fillOpacity', 'stroke', 'strokeWidth', 'strokeStyle'];
34
+ const BOX_KEYS = ['x', 'y', 'width', 'height', 'rotation', 'opacity'];
35
+ const PAINT_KEYS = ['fill', 'fillOpacity', 'stroke', 'strokeWidth', 'strokeStyle'];
56
36
  // The words audit reads every string inside a property called `text` as a sentence a person can read; these are the
57
37
  // names of fields, so the list of a text object's keys lives in a constant of its own.
58
- var TEXT_OBJECT_KEYS = __spreadArray(__spreadArray([], BOX_KEYS, true), [
38
+ const TEXT_OBJECT_KEYS = [
39
+ ...BOX_KEYS,
59
40
  'text',
60
41
  'color',
61
42
  'fontSize',
@@ -68,14 +49,14 @@ var TEXT_OBJECT_KEYS = __spreadArray(__spreadArray([], BOX_KEYS, true), [
68
49
  'padding',
69
50
  'backgroundColor',
70
51
  'autoWidth'
71
- ], false);
72
- var KEYS_BY_TYPE = {
73
- rect: __spreadArray(__spreadArray(__spreadArray([], BOX_KEYS, true), PAINT_KEYS, true), ['roundness'], false),
74
- ellipse: __spreadArray(__spreadArray(__spreadArray([], BOX_KEYS, true), PAINT_KEYS, true), ['aspectLocked'], false),
75
- path: __spreadArray(__spreadArray(__spreadArray([], BOX_KEYS, true), PAINT_KEYS, true), ['d', 'shape', 'roundness', 'aspectLocked', 'flipX', 'flipY', 'lineCap', 'lineJoin', 'ink', 'arrow'], false),
52
+ ];
53
+ const KEYS_BY_TYPE = {
54
+ rect: [...BOX_KEYS, ...PAINT_KEYS, 'roundness'],
55
+ ellipse: [...BOX_KEYS, ...PAINT_KEYS, 'aspectLocked'],
56
+ path: [...BOX_KEYS, ...PAINT_KEYS, 'd', 'shape', 'roundness', 'aspectLocked', 'flipX', 'flipY', 'lineCap', 'lineJoin', 'ink', 'arrow'],
76
57
  text: TEXT_OBJECT_KEYS,
77
- image: __spreadArray(__spreadArray([], BOX_KEYS, true), ['src', 'imageRef', 'fileName', 'libraryFileId', 'libraryFileUrl', 'naturalWidth', 'naturalHeight'], false),
78
- widget: __spreadArray(__spreadArray([], BOX_KEYS, true), ['widgetId', 'widgetName', 'isPrimary', 'thumbnail', 'thumbnailRef'], false),
58
+ image: [...BOX_KEYS, 'src', 'imageRef', 'fileName', 'libraryFileId', 'libraryFileUrl', 'naturalWidth', 'naturalHeight'],
59
+ widget: [...BOX_KEYS, 'widgetId', 'widgetName', 'isPrimary', 'thumbnail', 'thumbnailRef'],
79
60
  group: []
80
61
  };
81
62
  /**
@@ -87,8 +68,7 @@ function isPageLocalAddress(address) {
87
68
  }
88
69
  /** The reference and the (possibly inline) bytes of a picture, with the bytes moved to the store when there is one. */
89
70
  function externalizeBytes(inline, existingRef, makeRef, options) {
90
- var _a;
91
- var store = options.imageStore;
71
+ const store = options.imageStore;
92
72
  // An object URL the store gave for a reference is not bytes, and it must never reach the text: the next page cannot read it, and
93
73
  // a board that holds an address is not asked to read the picture again, so the card would stay blank. The picture is the
94
74
  // store's already, under the reference it was given for: only the reference is written. With no store, or with no reference to
@@ -97,7 +77,7 @@ function externalizeBytes(inline, existingRef, makeRef, options) {
97
77
  return { value: null, ref: existingRef };
98
78
  if (!store || !inline || !inline.startsWith('data:'))
99
79
  return { value: inline, ref: existingRef };
100
- var ref = existingRef !== null && existingRef !== void 0 ? existingRef : makeRef();
80
+ const ref = existingRef ?? makeRef();
101
81
  if (!ref)
102
82
  return { value: inline, ref: existingRef };
103
83
  try {
@@ -107,14 +87,14 @@ function externalizeBytes(inline, existingRef, makeRef, options) {
107
87
  // A store that refuses (it has nowhere to keep the bytes yet) must not take the whole save down with it, and must not
108
88
  // cost a picture: the bytes stay in the text, as if there were no store, and are offered again at the next save.
109
89
  try {
110
- (_a = options.onImageStoreRefused) === null || _a === void 0 ? void 0 : _a.call(options, ref, error);
90
+ options.onImageStoreRefused?.(ref, error);
111
91
  }
112
- catch (_b) {
92
+ catch {
113
93
  // The report is a courtesy; a report that fails changes nothing about the save.
114
94
  }
115
95
  return { value: inline, ref: existingRef };
116
96
  }
117
- return { value: null, ref: ref };
97
+ return { value: null, ref };
118
98
  }
119
99
  /** A tie of an arrow's end as it is saved: the shape it holds to (`target`) and, for a point of the outline, where on the shape's box. */
120
100
  function writeArrowBinding(binding) {
@@ -123,21 +103,19 @@ function writeArrowBinding(binding) {
123
103
  : { target: binding.targetId, kind: 'center' };
124
104
  }
125
105
  function serializeObject(object, options) {
126
- var _a;
127
- var record = (_a = { id: object.id }, _a[HOST_READABLE_KEYS.objectType] = object.type, _a.parentId = object.parentId, _a);
128
- var source = object;
129
- var overrides = {};
106
+ const record = { id: object.id, [HOST_READABLE_KEYS.objectType]: object.type, parentId: object.parentId };
107
+ const source = object;
108
+ let overrides = {};
130
109
  if (object.type === 'widget') {
131
- var thumbnail = externalizeBytes(object.thumbnail, object.thumbnailRef, function () { return "widget:".concat(object.widgetId); }, options);
110
+ const thumbnail = externalizeBytes(object.thumbnail, object.thumbnailRef, () => `widget:${object.widgetId}`, options);
132
111
  overrides = { thumbnail: thumbnail.value, thumbnailRef: thumbnail.ref };
133
112
  }
134
113
  else if (object.type === 'image') {
135
- var image = externalizeBytes(object.src, object.imageRef, function () { return "shape:".concat(object.id); }, options);
114
+ const image = externalizeBytes(object.src, object.imageRef, () => `shape:${object.id}`, options);
136
115
  overrides = { src: image.value, imageRef: image.ref };
137
116
  }
138
- for (var _i = 0, _b = KEYS_BY_TYPE[object.type]; _i < _b.length; _i++) {
139
- var key = _b[_i];
140
- var value = key in overrides ? overrides[key] : source[key];
117
+ for (const key of KEYS_BY_TYPE[object.type]) {
118
+ const value = key in overrides ? overrides[key] : source[key];
141
119
  record[key] = typeof value === 'number' ? roundTo(value, 3) : value;
142
120
  }
143
121
  if (object.type === 'widget') {
@@ -158,8 +136,15 @@ function serializeObject(object, options) {
158
136
  // An arrow is saved as its two ends and its bend, for the same reason: its head and shaft are drawn from them when it is read.
159
137
  if (object.arrow) {
160
138
  delete record.d;
161
- var _c = object.arrow, start = _c.start, end = _c.end, bend = _c.bend, startBinding = _c.startBinding, endBinding = _c.endBinding;
162
- record.arrow = __assign(__assign({ start: [roundTo(start.x, 3), roundTo(start.y, 3)], end: [roundTo(end.x, 3), roundTo(end.y, 3)], bend: roundTo(bend, 3) }, (startBinding ? { startBinding: writeArrowBinding(startBinding) } : {})), (endBinding ? { endBinding: writeArrowBinding(endBinding) } : {}));
139
+ const { start, end, bend, startBinding, endBinding } = object.arrow;
140
+ record.arrow = {
141
+ start: [roundTo(start.x, 3), roundTo(start.y, 3)],
142
+ end: [roundTo(end.x, 3), roundTo(end.y, 3)],
143
+ bend: roundTo(bend, 3),
144
+ // What its ends are tied to, written only for an end that is tied: a board of free arrows is the text it always was.
145
+ ...(startBinding ? { startBinding: writeArrowBinding(startBinding) } : {}),
146
+ ...(endBinding ? { endBinding: writeArrowBinding(endBinding) } : {})
147
+ };
163
148
  }
164
149
  else
165
150
  delete record.arrow;
@@ -167,28 +152,23 @@ function serializeObject(object, options) {
167
152
  return record;
168
153
  }
169
154
  /** The document for a board, as a plain object (the form `serializeCanvasDocument` writes). */
170
- export function createCanvasDocument(scene, viewport, options) {
171
- var _a;
172
- if (options === void 0) { options = {}; }
155
+ export function createCanvasDocument(scene, viewport, options = {}) {
173
156
  return {
174
157
  version: CANVAS_DOCUMENT_VERSION,
175
- savedAt: ((_a = options.now) !== null && _a !== void 0 ? _a : new Date()).toISOString(),
158
+ savedAt: (options.now ?? new Date()).toISOString(),
176
159
  viewport: { x: roundTo(viewport.x, 2), y: roundTo(viewport.y, 2), zoom: roundTo(viewport.zoom, 4) },
177
- canvas: { objects: scene.map(function (object) { return serializeObject(object, options); }) }
160
+ canvas: { objects: scene.map((object) => serializeObject(object, options)) }
178
161
  };
179
162
  }
180
163
  /** The text a board is saved as. */
181
- export function serializeCanvasDocument(scene, viewport, options) {
182
- if (options === void 0) { options = {}; }
164
+ export function serializeCanvasDocument(scene, viewport, options = {}) {
183
165
  return JSON.stringify(createCanvasDocument(scene, viewport, options));
184
166
  }
185
167
  function isRecord(value) {
186
168
  return typeof value === 'object' && value !== null && !Array.isArray(value);
187
169
  }
188
- function readNumber(value, fallback, minimum, maximum) {
189
- if (minimum === void 0) { minimum = -Infinity; }
190
- if (maximum === void 0) { maximum = Infinity; }
191
- var number = typeof value === 'number' ? value : typeof value === 'string' && value.trim() !== '' ? Number(value) : NaN;
170
+ function readNumber(value, fallback, minimum = -Infinity, maximum = Infinity) {
171
+ const number = typeof value === 'number' ? value : typeof value === 'string' && value.trim() !== '' ? Number(value) : NaN;
192
172
  if (!Number.isFinite(number))
193
173
  return fallback;
194
174
  return clampNumber(number, minimum, maximum);
@@ -196,23 +176,21 @@ function readNumber(value, fallback, minimum, maximum) {
196
176
  function readBoolean(value, fallback) {
197
177
  return typeof value === 'boolean' ? value : fallback;
198
178
  }
199
- function readString(value, fallback, maximumLength) {
200
- if (maximumLength === void 0) { maximumLength = 1000; }
179
+ function readString(value, fallback, maximumLength = 1000) {
201
180
  return typeof value === 'string' ? value.slice(0, maximumLength) : fallback;
202
181
  }
203
- function readNullableString(value, maximumLength) {
204
- if (maximumLength === void 0) { maximumLength = 1000; }
182
+ function readNullableString(value, maximumLength = 1000) {
205
183
  return typeof value === 'string' && value !== '' ? value.slice(0, maximumLength) : null;
206
184
  }
207
185
  function readOneOf(value, allowed, fallback) {
208
186
  return typeof value === 'string' && allowed.includes(value) ? value : fallback;
209
187
  }
210
188
  /** A hex, `rgb()`, `hsl()` or named colour: nothing that could carry more than a colour into CSS or SVG. */
211
- var COLOR_PATTERN = /^(#[0-9a-f]{3,8}|(?:rgb|hsl)a?\([0-9a-z\s.,%/+-]{1,80}\)|[a-z]{3,30})$/i;
189
+ const COLOR_PATTERN = /^(#[0-9a-f]{3,8}|(?:rgb|hsl)a?\([0-9a-z\s.,%/+-]{1,80}\)|[a-z]{3,30})$/i;
212
190
  export function readColor(value, fallback) {
213
191
  return typeof value === 'string' && COLOR_PATTERN.test(value.trim()) ? value.trim() : fallback;
214
192
  }
215
- var FONT_FAMILY_PATTERN = /^[\p{L}\p{N}\s,'"\-_.]{1,200}$/u;
193
+ const FONT_FAMILY_PATTERN = /^[\p{L}\p{N}\s,'"\-_.]{1,200}$/u;
216
194
  /** Whether a text is a well-formed font family name (what a saved board accepts: letters, digits, spaces and a few marks). */
217
195
  export function isFontFamilyName(value) {
218
196
  return typeof value === 'string' && FONT_FAMILY_PATTERN.test(value);
@@ -220,15 +198,15 @@ export function isFontFamilyName(value) {
220
198
  function readFontFamily(value) {
221
199
  return typeof value === 'string' && FONT_FAMILY_PATTERN.test(value) ? value : TEXT_DEFAULTS.fontFamily;
222
200
  }
223
- var IMAGE_ADDRESS_PATTERN = /^(?:data:image\/[a-z0-9.+-]+[;,]|https?:\/\/|blob:|\/(?!\/))/i;
201
+ const IMAGE_ADDRESS_PATTERN = /^(?:data:image\/[a-z0-9.+-]+[;,]|https?:\/\/|blob:|\/(?!\/))/i;
224
202
  /** An image address the browser may load into an `<img>`: inline bytes, http(s), a blob or a path of this site. */
225
203
  export function readImageAddress(value) {
226
204
  if (typeof value !== 'string' || value === '')
227
205
  return null;
228
206
  return IMAGE_ADDRESS_PATTERN.test(value) ? value : null;
229
207
  }
230
- var LIBRARY_ADDRESS_PATTERN = /^(?:https?:\/\/|\/(?!\/))/i;
231
- var LIBRARY_ADDRESS_MAX_LENGTH = 2000;
208
+ const LIBRARY_ADDRESS_PATTERN = /^(?:https?:\/\/|\/(?!\/))/i;
209
+ const LIBRARY_ADDRESS_MAX_LENGTH = 2000;
232
210
  /**
233
211
  * Where the person's file library keeps a picture: an http(s) address or a path of the page. Never inline bytes (the library
234
212
  * address only names the file; the board's own bytes live in `src`/`imageRef`), and never anything a link could abuse.
@@ -238,9 +216,9 @@ export function readLibraryFileAddress(value) {
238
216
  return null;
239
217
  return LIBRARY_ADDRESS_PATTERN.test(value) ? value : null;
240
218
  }
241
- var STROKE_STYLES = ['solid', 'dashed', 'dotted'];
242
- var LINE_CAPS = ['butt', 'round', 'square'];
243
- var LINE_JOINS = ['miter', 'round', 'bevel'];
219
+ const STROKE_STYLES = ['solid', 'dashed', 'dotted'];
220
+ const LINE_CAPS = ['butt', 'round', 'square'];
221
+ const LINE_JOINS = ['miter', 'round', 'bevel'];
244
222
  function readBox(raw) {
245
223
  return {
246
224
  x: readNumber(raw.x, 0, -MAX_COORDINATE, MAX_COORDINATE),
@@ -260,9 +238,9 @@ function readPaint(raw, defaults) {
260
238
  strokeStyle: readOneOf(raw.strokeStyle, STROKE_STYLES, 'solid')
261
239
  };
262
240
  }
263
- var PAINT_FALLBACK = { fill: '#ffffff', stroke: '#374151', strokeWidth: 2 };
241
+ const PAINT_FALLBACK = { fill: '#ffffff', stroke: '#374151', strokeWidth: 2 };
264
242
  function readId(raw, seen) {
265
- var id = typeof raw.id === 'string' && raw.id !== '' && raw.id.length <= 128 ? raw.id : createObjectId();
243
+ let id = typeof raw.id === 'string' && raw.id !== '' && raw.id.length <= 128 ? raw.id : createObjectId();
266
244
  // Two objects with the same id would be one on the board: the second gets a new one.
267
245
  while (seen.has(id))
268
246
  id = createObjectId();
@@ -273,19 +251,30 @@ function readParentId(raw) {
273
251
  return typeof raw.parentId === 'string' && raw.parentId !== '' && raw.parentId.length <= 128 ? raw.parentId : null;
274
252
  }
275
253
  function readRect(raw, id) {
276
- return createRectObject(__assign(__assign(__assign({ id: id, parentId: readParentId(raw) }, readBox(raw)), readPaint(raw, PAINT_FALLBACK)), { roundness: readNumber(raw.roundness, 0, 0, 100) }));
254
+ return createRectObject({
255
+ id,
256
+ parentId: readParentId(raw),
257
+ ...readBox(raw),
258
+ ...readPaint(raw, PAINT_FALLBACK),
259
+ roundness: readNumber(raw.roundness, 0, 0, 100)
260
+ });
277
261
  }
278
262
  function readEllipse(raw, id) {
279
- return createEllipseObject(__assign(__assign(__assign({ id: id, parentId: readParentId(raw) }, readBox(raw)), readPaint(raw, PAINT_FALLBACK)), { aspectLocked: readBoolean(raw.aspectLocked, false) }));
263
+ return createEllipseObject({
264
+ id,
265
+ parentId: readParentId(raw),
266
+ ...readBox(raw),
267
+ ...readPaint(raw, PAINT_FALLBACK),
268
+ aspectLocked: readBoolean(raw.aspectLocked, false)
269
+ });
280
270
  }
281
- var BRUSH_PRESSURES = ['pen', 'speed'];
271
+ const BRUSH_PRESSURES = ['pen', 'speed'];
282
272
  /** The line of a brush stroke, or null when there is none to draw: points that are not numbers are dropped, and a long line is cut. */
283
273
  function readInk(value) {
284
274
  if (!isRecord(value) || !Array.isArray(value.points))
285
275
  return null;
286
- var points = [];
287
- for (var _i = 0, _a = value.points.slice(0, BRUSH_MAX_POINTS); _i < _a.length; _i++) {
288
- var entry = _a[_i];
276
+ const points = [];
277
+ for (const entry of value.points.slice(0, BRUSH_MAX_POINTS)) {
289
278
  if (!Array.isArray(entry) || typeof entry[0] !== 'number' || typeof entry[1] !== 'number')
290
279
  continue;
291
280
  if (!Number.isFinite(entry[0]) || !Number.isFinite(entry[1]))
@@ -298,24 +287,24 @@ function readInk(value) {
298
287
  }
299
288
  if (points.length === 0)
300
289
  return null;
301
- return { points: points, pressure: readOneOf(value.pressure, BRUSH_PRESSURES, 'speed') };
290
+ return { points, pressure: readOneOf(value.pressure, BRUSH_PRESSURES, 'speed') };
302
291
  }
303
292
  /** The two ends and the bend of an arrow, or null when the record has none that can be read. */
304
293
  function readArrowSpec(value) {
305
294
  if (!isRecord(value))
306
295
  return null;
307
- var readPoint = function (entry) {
296
+ const readPoint = (entry) => {
308
297
  if (!Array.isArray(entry) || typeof entry[0] !== 'number' || typeof entry[1] !== 'number')
309
298
  return null;
310
299
  if (!Number.isFinite(entry[0]) || !Number.isFinite(entry[1]))
311
300
  return null;
312
301
  return { x: clampNumber(entry[0], -MAX_COORDINATE, MAX_COORDINATE), y: clampNumber(entry[1], -MAX_COORDINATE, MAX_COORDINATE) };
313
302
  };
314
- var start = readPoint(value.start);
315
- var end = readPoint(value.end);
303
+ const start = readPoint(value.start);
304
+ const end = readPoint(value.end);
316
305
  if (!start || !end)
317
306
  return null;
318
- return withBindings({ start: start, end: end, bend: readNumber(value.bend, 0, -2 * MAX_SIZE, 2 * MAX_SIZE) }, { startBinding: readArrowBinding(value.startBinding), endBinding: readArrowBinding(value.endBinding) });
307
+ return withBindings({ start, end, bend: readNumber(value.bend, 0, -2 * MAX_SIZE, 2 * MAX_SIZE) }, { startBinding: readArrowBinding(value.startBinding), endBinding: readArrowBinding(value.endBinding) });
319
308
  }
320
309
  /**
321
310
  * What an end of an arrow is tied to, or null when the record says nothing that can be read: a shape (by its id), and for a point of
@@ -324,17 +313,17 @@ function readArrowSpec(value) {
324
313
  function readArrowBinding(value) {
325
314
  if (!isRecord(value))
326
315
  return null;
327
- var targetId = typeof value.target === 'string' && value.target !== '' && value.target.length <= 128 ? value.target : null;
316
+ const targetId = typeof value.target === 'string' && value.target !== '' && value.target.length <= 128 ? value.target : null;
328
317
  if (!targetId)
329
318
  return null;
330
319
  if (value.kind === 'center')
331
- return { targetId: targetId, kind: 'center' };
320
+ return { targetId, kind: 'center' };
332
321
  if (value.kind !== 'edge' || !Array.isArray(value.anchor))
333
322
  return null;
334
- var _a = value.anchor, across = _a[0], down = _a[1];
323
+ const [across, down] = value.anchor;
335
324
  if (typeof across !== 'number' || typeof down !== 'number' || !Number.isFinite(across) || !Number.isFinite(down))
336
325
  return null;
337
- return { targetId: targetId, kind: 'edge', anchor: { x: clampNumber(across, 0, 1), y: clampNumber(down, 0, 1) } };
326
+ return { targetId, kind: 'edge', anchor: { x: clampNumber(across, 0, 1), y: clampNumber(down, 0, 1) } };
338
327
  }
339
328
  /**
340
329
  * An arrow drawn from its points. They are in the coordinates of the saved box, which is kept as it is when it holds what is drawn
@@ -342,57 +331,56 @@ function readArrowBinding(value) {
342
331
  * where it was in the world. An arrow is upright: a turn the record carries is applied to its points.
343
332
  */
344
333
  function arrowFromSpec(spec, box, strokeWidth) {
345
- var _a, _b;
346
- var start = spec.start, end = spec.end;
334
+ let { start, end } = spec;
347
335
  // What its ends are tied to is not a place on the board: it needs no turn.
348
- var tiesOfSpec = { startBinding: (_a = spec.startBinding) !== null && _a !== void 0 ? _a : null, endBinding: (_b = spec.endBinding) !== null && _b !== void 0 ? _b : null };
336
+ const tiesOfSpec = { startBinding: spec.startBinding ?? null, endBinding: spec.endBinding ?? null };
349
337
  if (box.rotation !== 0) {
350
- var radians = degreesToRadians(box.rotation);
351
- var cosine_1 = Math.cos(radians);
352
- var sine_1 = Math.sin(radians);
353
- var centerX_1 = box.width / 2;
354
- var centerY_1 = box.height / 2;
355
- var turn = function (point) { return ({
356
- x: centerX_1 + (point.x - centerX_1) * cosine_1 - (point.y - centerY_1) * sine_1,
357
- y: centerY_1 + (point.x - centerX_1) * sine_1 + (point.y - centerY_1) * cosine_1
358
- }); };
338
+ const radians = degreesToRadians(box.rotation);
339
+ const cosine = Math.cos(radians);
340
+ const sine = Math.sin(radians);
341
+ const centerX = box.width / 2;
342
+ const centerY = box.height / 2;
343
+ const turn = (point) => ({
344
+ x: centerX + (point.x - centerX) * cosine - (point.y - centerY) * sine,
345
+ y: centerY + (point.x - centerX) * sine + (point.y - centerY) * cosine
346
+ });
359
347
  start = turn(start);
360
348
  end = turn(end);
361
349
  }
362
- var geometry = buildArrow(start, end, spec.bend, strokeWidth);
363
- var holdsWhatIsDrawn = box.rotation === 0 &&
350
+ const geometry = buildArrow(start, end, spec.bend, strokeWidth);
351
+ const holdsWhatIsDrawn = box.rotation === 0 &&
364
352
  Math.abs(geometry.box.x) <= 0.5 &&
365
353
  Math.abs(geometry.box.y) <= 0.5 &&
366
354
  Math.abs(geometry.box.width - box.width) <= 0.5 &&
367
355
  Math.abs(geometry.box.height - box.height) <= 0.5;
368
356
  if (holdsWhatIsDrawn) {
369
357
  // In the frame of the points, which is the frame of the saved box: the path comes back in the frame of its own bounds.
370
- var commands = translatePathCommands(geometry.commands, geometry.box.x, geometry.box.y);
371
- return { d: serializePathData(commands), arrow: withBindings({ start: start, end: end, bend: geometry.spec.bend }, tiesOfSpec), box: box };
358
+ const commands = translatePathCommands(geometry.commands, geometry.box.x, geometry.box.y);
359
+ return { d: serializePathData(commands), arrow: withBindings({ start, end, bend: geometry.spec.bend }, tiesOfSpec), box };
372
360
  }
373
361
  return {
374
362
  d: serializePathData(geometry.commands),
375
363
  arrow: withBindings(geometry.spec, tiesOfSpec),
376
- box: __assign(__assign({}, box), { rotation: 0, x: box.x + geometry.box.x, y: box.y + geometry.box.y, width: geometry.box.width, height: geometry.box.height })
364
+ box: { ...box, rotation: 0, x: box.x + geometry.box.x, y: box.y + geometry.box.y, width: geometry.box.width, height: geometry.box.height }
377
365
  };
378
366
  }
379
367
  function readPath(raw, id, index, warnings) {
380
- var paint = readPaint(raw, { fill: 'transparent', stroke: '#1f2937', strokeWidth: 3 });
381
- var ink = readInk(raw.ink);
382
- var shape = readNullableString(raw.shape, 100);
383
- var box = readBox(raw);
368
+ const paint = readPaint(raw, { fill: 'transparent', stroke: '#1f2937', strokeWidth: 3 });
369
+ const ink = readInk(raw.ink);
370
+ const shape = readNullableString(raw.shape, 100);
371
+ let box = readBox(raw);
384
372
  // An arrow has no outline of its own in the file either: it is drawn from its points. A board saved before arrows had points
385
373
  // has the outline only, and its arrow is found in that.
386
- var arrowSpec = ink ? null : readArrowSpec(raw.arrow);
374
+ let arrowSpec = ink ? null : readArrowSpec(raw.arrow);
387
375
  if (!ink && !arrowSpec && shape === 'arrow' && typeof raw.d === 'string' && raw.d.length <= MAX_PATH_DATA_LENGTH) {
388
- var legacy = arrowPointsOfLegacyPath(parsePathData(raw.d));
376
+ const legacy = arrowPointsOfLegacyPath(parsePathData(raw.d));
389
377
  if (legacy)
390
- arrowSpec = __assign(__assign({}, legacy), { bend: 0 });
378
+ arrowSpec = { ...legacy, bend: 0 };
391
379
  }
392
- var arrow = null;
393
- var d;
380
+ let arrow = null;
381
+ let d;
394
382
  if (arrowSpec) {
395
- var drawn = arrowFromSpec(arrowSpec, box, paint.strokeWidth);
383
+ const drawn = arrowFromSpec(arrowSpec, box, paint.strokeWidth);
396
384
  d = drawn.d;
397
385
  arrow = drawn.arrow;
398
386
  box = drawn.box;
@@ -402,50 +390,100 @@ function readPath(raw, id, index, warnings) {
402
390
  d = ink ? brushOutlineData(ink, paint.strokeWidth) : typeof raw.d === 'string' ? raw.d : '';
403
391
  }
404
392
  if (d.length === 0 || d.length > MAX_PATH_DATA_LENGTH || parsePathData(d).length < 2) {
405
- warnings.push({ code: 'bad-path', index: index, detail: 'The outline of the shape is missing or cannot be read.' });
393
+ warnings.push({ code: 'bad-path', index, detail: 'The outline of the shape is missing or cannot be read.' });
406
394
  return null;
407
395
  }
408
- var path = createPathObject(__assign(__assign(__assign({ id: id, parentId: readParentId(raw) }, box), paint), { d: d, shape: shape, roundness: readNumber(raw.roundness, 0, 0, 100), aspectLocked: readBoolean(raw.aspectLocked, false), flipX: readBoolean(raw.flipX, false), flipY: readBoolean(raw.flipY, false), lineCap: readOneOf(raw.lineCap, LINE_CAPS, 'round'), lineJoin: readOneOf(raw.lineJoin, LINE_JOINS, 'round'), ink: ink, arrow: arrow }));
396
+ const path = createPathObject({
397
+ id,
398
+ parentId: readParentId(raw),
399
+ ...box,
400
+ ...paint,
401
+ d,
402
+ shape,
403
+ roundness: readNumber(raw.roundness, 0, 0, 100),
404
+ aspectLocked: readBoolean(raw.aspectLocked, false),
405
+ flipX: readBoolean(raw.flipX, false),
406
+ flipY: readBoolean(raw.flipY, false),
407
+ lineCap: readOneOf(raw.lineCap, LINE_CAPS, 'round'),
408
+ lineJoin: readOneOf(raw.lineJoin, LINE_JOINS, 'round'),
409
+ ink,
410
+ arrow
411
+ });
409
412
  // A line (an arrow, a line-only icon) saved with no width, as the Width control once allowed, would stay invisible on the board:
410
413
  // it comes back with the thinnest line it can have. A brush stroke is drawn from its ink and keeps the width it was drawn with.
411
414
  // (The head of an arrow drawn above is the same for a width of 0 as for the thinnest line, so it needs no drawing again.)
412
- var thinnestLine = ink ? 0 : minimumStrokeWidthOf(path);
413
- return path.strokeWidth < thinnestLine ? __assign(__assign({}, path), { strokeWidth: thinnestLine }) : path;
415
+ const thinnestLine = ink ? 0 : minimumStrokeWidthOf(path);
416
+ return path.strokeWidth < thinnestLine ? { ...path, strokeWidth: thinnestLine } : path;
414
417
  }
415
418
  function readText(raw, id) {
416
- return createTextObject(__assign(__assign({ id: id, parentId: readParentId(raw) }, readBox(raw)), { text: readString(raw.text, '', MAX_TEXT_LENGTH), color: readColor(raw.color, TEXT_DEFAULTS.color), fontSize: readNumber(raw.fontSize, TEXT_DEFAULTS.fontSize, 4, 600), fontFamily: readFontFamily(raw.fontFamily), fontWeight: readOneOf(raw.fontWeight, ['normal', 'bold'], 'normal'), fontStyle: readOneOf(raw.fontStyle, ['normal', 'italic'], 'normal'), underline: readBoolean(raw.underline, false), align: readOneOf(raw.align, ['left', 'center', 'right'], 'left'), lineHeight: readNumber(raw.lineHeight, 1.2, 0.5, 4), padding: readNumber(raw.padding, 0, 0, 200), backgroundColor: readColor(raw.backgroundColor, 'transparent'), autoWidth: readBoolean(raw.autoWidth, true) }));
419
+ return createTextObject({
420
+ id,
421
+ parentId: readParentId(raw),
422
+ ...readBox(raw),
423
+ text: readString(raw.text, '', MAX_TEXT_LENGTH),
424
+ color: readColor(raw.color, TEXT_DEFAULTS.color),
425
+ fontSize: readNumber(raw.fontSize, TEXT_DEFAULTS.fontSize, 4, 600),
426
+ fontFamily: readFontFamily(raw.fontFamily),
427
+ fontWeight: readOneOf(raw.fontWeight, ['normal', 'bold'], 'normal'),
428
+ fontStyle: readOneOf(raw.fontStyle, ['normal', 'italic'], 'normal'),
429
+ underline: readBoolean(raw.underline, false),
430
+ align: readOneOf(raw.align, ['left', 'center', 'right'], 'left'),
431
+ lineHeight: readNumber(raw.lineHeight, 1.2, 0.5, 4),
432
+ padding: readNumber(raw.padding, 0, 0, 200),
433
+ backgroundColor: readColor(raw.backgroundColor, 'transparent'),
434
+ autoWidth: readBoolean(raw.autoWidth, true)
435
+ });
417
436
  }
418
437
  function readImage(raw, id) {
419
- return createImageObject(__assign(__assign({ id: id, parentId: readParentId(raw) }, readBox(raw)), { src: readImageAddress(raw.src), imageRef: readNullableString(raw.imageRef, 200), fileName: readNullableString(raw.fileName, 300), libraryFileId: readNullableString(raw.libraryFileId, 200), libraryFileUrl: readLibraryFileAddress(raw.libraryFileUrl), naturalWidth: readNumber(raw.naturalWidth, 0, 0, MAX_SIZE), naturalHeight: readNumber(raw.naturalHeight, 0, 0, MAX_SIZE) }));
438
+ return createImageObject({
439
+ id,
440
+ parentId: readParentId(raw),
441
+ ...readBox(raw),
442
+ src: readImageAddress(raw.src),
443
+ imageRef: readNullableString(raw.imageRef, 200),
444
+ fileName: readNullableString(raw.fileName, 300),
445
+ libraryFileId: readNullableString(raw.libraryFileId, 200),
446
+ libraryFileUrl: readLibraryFileAddress(raw.libraryFileUrl),
447
+ naturalWidth: readNumber(raw.naturalWidth, 0, 0, MAX_SIZE),
448
+ naturalHeight: readNumber(raw.naturalHeight, 0, 0, MAX_SIZE)
449
+ });
420
450
  }
421
451
  function readWidget(raw, id, index, warnings) {
422
- var _a;
423
452
  // The creator reads `_widgetId`; the canvas's own key is `widgetId`. Either names the widget.
424
- var widgetId = (_a = readNullableString(raw.widgetId, 200)) !== null && _a !== void 0 ? _a : readNullableString(raw[HOST_READABLE_KEYS.widgetId], 200);
453
+ const widgetId = readNullableString(raw.widgetId, 200) ?? readNullableString(raw[HOST_READABLE_KEYS.widgetId], 200);
425
454
  if (!widgetId) {
426
- warnings.push({ code: 'bad-object', index: index, detail: 'A widget card has no widget id.' });
455
+ warnings.push({ code: 'bad-object', index, detail: 'A widget card has no widget id.' });
427
456
  return null;
428
457
  }
429
- return createWidgetObject(__assign(__assign({ id: id, widgetId: widgetId, parentId: readParentId(raw) }, readBox(raw)), { widgetName: readNullableString(raw.widgetName, 300), isPrimary: readBoolean(raw.isPrimary, false), thumbnail: readImageAddress(raw.thumbnail), thumbnailRef: readNullableString(raw.thumbnailRef, 200) }));
458
+ return createWidgetObject({
459
+ id,
460
+ widgetId,
461
+ parentId: readParentId(raw),
462
+ ...readBox(raw),
463
+ widgetName: readNullableString(raw.widgetName, 300),
464
+ isPrimary: readBoolean(raw.isPrimary, false),
465
+ thumbnail: readImageAddress(raw.thumbnail),
466
+ thumbnailRef: readNullableString(raw.thumbnailRef, 200)
467
+ });
430
468
  }
431
469
  function readGroup(raw, id) {
432
- return createGroupObject({ id: id, parentId: readParentId(raw) });
470
+ return createGroupObject({ id, parentId: readParentId(raw) });
433
471
  }
434
472
  function readObject(raw, index, seen, warnings) {
435
473
  if (!isRecord(raw)) {
436
- warnings.push({ code: 'bad-object', index: index, detail: 'An entry of the list is not an object.' });
474
+ warnings.push({ code: 'bad-object', index, detail: 'An entry of the list is not an object.' });
437
475
  return null;
438
476
  }
439
477
  // Readers outside the canvas treat these as "not there": so does the canvas.
440
478
  if (raw[HOST_READABLE_KEYS.visible] === false || raw[HOST_READABLE_KEYS.excludeFromExport] === true)
441
479
  return null;
442
- var type = raw[HOST_READABLE_KEYS.objectType];
443
- var known = ['rect', 'ellipse', 'path', 'text', 'image', 'widget', 'group'];
480
+ const type = raw[HOST_READABLE_KEYS.objectType];
481
+ const known = ['rect', 'ellipse', 'path', 'text', 'image', 'widget', 'group'];
444
482
  if (typeof type !== 'string' || !known.includes(type)) {
445
- warnings.push({ code: 'unknown-type', index: index, detail: typeof type === 'string' ? type : String(type) });
483
+ warnings.push({ code: 'unknown-type', index, detail: typeof type === 'string' ? type : String(type) });
446
484
  return null;
447
485
  }
448
- var id = readId(raw, seen);
486
+ const id = readId(raw, seen);
449
487
  switch (type) {
450
488
  case 'rect':
451
489
  return readRect(raw, id);
@@ -463,28 +501,27 @@ function readObject(raw, index, seen, warnings) {
463
501
  return readGroup(raw, id);
464
502
  }
465
503
  }
466
- var EMPTY_VIEWPORT = { x: 0, y: 0, zoom: 1 };
504
+ const EMPTY_VIEWPORT = { x: 0, y: 0, zoom: 1 };
467
505
  /**
468
506
  * Reads a saved canvas: the text `serializeCanvasDocument` wrote, or the same thing already parsed.
469
507
  * Never throws.
470
508
  */
471
509
  export function parseCanvasDocument(input) {
472
- var _a;
473
- var warnings = [];
474
- var nothing = function (status) { return ({
510
+ const warnings = [];
511
+ const nothing = (status) => ({
475
512
  scene: [],
476
- viewport: __assign({}, EMPTY_VIEWPORT),
477
- status: status,
478
- warnings: warnings
479
- }); };
513
+ viewport: { ...EMPTY_VIEWPORT },
514
+ status,
515
+ warnings
516
+ });
480
517
  if (input === null || input === undefined || (typeof input === 'string' && input.trim() === ''))
481
518
  return nothing('empty');
482
- var document = input;
519
+ let document = input;
483
520
  if (typeof input === 'string') {
484
521
  try {
485
522
  document = JSON.parse(input);
486
523
  }
487
- catch (_b) {
524
+ catch {
488
525
  warnings.push({ code: 'not-json' });
489
526
  return nothing('invalid');
490
527
  }
@@ -494,19 +531,19 @@ export function parseCanvasDocument(input) {
494
531
  return nothing('invalid');
495
532
  }
496
533
  if (document.version !== CANVAS_DOCUMENT_VERSION) {
497
- warnings.push({ code: 'unsupported-version', detail: String((_a = document.version) !== null && _a !== void 0 ? _a : 'none') });
534
+ warnings.push({ code: 'unsupported-version', detail: String(document.version ?? 'none') });
498
535
  return nothing('unsupported');
499
536
  }
500
- var canvas = document.canvas;
501
- var list = isRecord(canvas) && Array.isArray(canvas.objects) ? canvas.objects : [];
502
- var limited = list.length > MAX_OBJECTS_PER_DOCUMENT ? list.slice(0, MAX_OBJECTS_PER_DOCUMENT) : list;
537
+ const canvas = document.canvas;
538
+ const list = isRecord(canvas) && Array.isArray(canvas.objects) ? canvas.objects : [];
539
+ const limited = list.length > MAX_OBJECTS_PER_DOCUMENT ? list.slice(0, MAX_OBJECTS_PER_DOCUMENT) : list;
503
540
  if (limited.length < list.length) {
504
- warnings.push({ code: 'too-many-objects', detail: "".concat(list.length, " objects, the first ").concat(limited.length, " were read.") });
541
+ warnings.push({ code: 'too-many-objects', detail: `${list.length} objects, the first ${limited.length} were read.` });
505
542
  }
506
- var seen = new Set();
507
- var objects = [];
508
- limited.forEach(function (raw, index) {
509
- var object = readObject(raw, index, seen, warnings);
543
+ const seen = new Set();
544
+ const objects = [];
545
+ limited.forEach((raw, index) => {
546
+ const object = readObject(raw, index, seen, warnings);
510
547
  if (object)
511
548
  objects.push(object);
512
549
  });
@@ -515,6 +552,6 @@ export function parseCanvasDocument(input) {
515
552
  scene: dropDanglingBindings(normalizeScene(objects)),
516
553
  viewport: sanitizeViewport(document.viewport),
517
554
  status: 'ok',
518
- warnings: warnings
555
+ warnings
519
556
  };
520
557
  }
@@ -9,7 +9,7 @@
9
9
  * accepts them, and `tests/engine/codec.test.mjs` fails if either changes. Every other key of the format
10
10
  * is the canvas's own and can change with a version.
11
11
  */
12
- export var HOST_READABLE_KEYS = Object.freeze({
12
+ export const HOST_READABLE_KEYS = Object.freeze({
13
13
  /** `document.canvas.objects`: always an array. Readers fall back to `document.objects` for a bare list. */
14
14
  documentObjects: Object.freeze(['canvas', 'objects']),
15
15
  /** The kind of an object: a string. */