@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
@@ -1,54 +1,16 @@
1
1
  /**
2
2
  * Workspace brand-kit fonts registered for the canvas font picker (item B15).
3
3
  */
4
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
5
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6
- return new (P || (P = Promise))(function (resolve, reject) {
7
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
8
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
9
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
10
- step((generator = generator.apply(thisArg, _arguments || [])).next());
11
- });
12
- };
13
- var __generator = (this && this.__generator) || function (thisArg, body) {
14
- 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);
15
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
16
- function verb(n) { return function (v) { return step([n, v]); }; }
17
- function step(op) {
18
- if (f) throw new TypeError("Generator is already executing.");
19
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
20
- 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;
21
- if (y = 0, t) op = [op[0] & 2, t.value];
22
- switch (op[0]) {
23
- case 0: case 1: t = op; break;
24
- case 4: _.label++; return { value: op[1], done: false };
25
- case 5: _.label++; y = op[1]; op = [0]; continue;
26
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
27
- default:
28
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
29
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
30
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
31
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
32
- if (t[2]) _.ops.pop();
33
- _.trys.pop(); continue;
34
- }
35
- op = body.call(thisArg, _);
36
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
37
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
38
- }
39
- };
40
- var registered = new Set();
4
+ const registered = new Set();
41
5
  /** The registration that is under way (or the last one that was): the next list waits for it, so fonts are never loaded twice. */
42
- var registerQueue = Promise.resolve();
6
+ let registerQueue = Promise.resolve();
43
7
  function familyKey(font) {
44
- var _a, _b;
45
- return "".concat(font.family, "|").concat((_a = font.weight) !== null && _a !== void 0 ? _a : '400', "|").concat((_b = font.style) !== null && _b !== void 0 ? _b : 'normal');
8
+ return `${font.family}|${font.weight ?? '400'}|${font.style ?? 'normal'}`;
46
9
  }
47
10
  export function listWorkspaceFontFamilies(fonts) {
48
- var seen = new Set();
49
- var out = [];
50
- for (var _i = 0, fonts_1 = fonts; _i < fonts_1.length; _i++) {
51
- var font = fonts_1[_i];
11
+ const seen = new Set();
12
+ const out = [];
13
+ for (const font of fonts) {
52
14
  if (!font.family || seen.has(font.family))
53
15
  continue;
54
16
  seen.add(font.family);
@@ -57,58 +19,37 @@ export function listWorkspaceFontFamilies(fonts) {
57
19
  return out;
58
20
  }
59
21
  /** How long a font file gets to arrive before it is given up on (until a later list tries it again). */
60
- var FONT_LOAD_TIMEOUT_MS = 12000;
22
+ const FONT_LOAD_TIMEOUT_MS = 12_000;
61
23
  /** Loads a font face, giving up after `FONT_LOAD_TIMEOUT_MS`; the timer never outlives the load. */
62
24
  function loadFaceWithTimeout(face) {
63
- var timer;
64
- var timeUp = new Promise(function (_, reject) {
65
- timer = setTimeout(function () { return reject(new Error('font load timeout')); }, FONT_LOAD_TIMEOUT_MS);
25
+ let timer;
26
+ const timeUp = new Promise((_, reject) => {
27
+ timer = setTimeout(() => reject(new Error('font load timeout')), FONT_LOAD_TIMEOUT_MS);
66
28
  });
67
- return Promise.race([face.load(), timeUp]).finally(function () { return clearTimeout(timer); });
29
+ return Promise.race([face.load(), timeUp]).finally(() => clearTimeout(timer));
68
30
  }
69
31
  /** Registers the fonts of one list that are not registered yet, one after the other. A font that fails is left out and tried again by a later list. */
70
- function registerFontsOnce(fonts) {
71
- return __awaiter(this, void 0, Promise, function () {
72
- var _i, fonts_2, font, key, format, source, face, loaded, error_1;
73
- var _a, _b;
74
- return __generator(this, function (_c) {
75
- switch (_c.label) {
76
- case 0:
77
- _i = 0, fonts_2 = fonts;
78
- _c.label = 1;
79
- case 1:
80
- if (!(_i < fonts_2.length)) return [3 /*break*/, 6];
81
- font = fonts_2[_i];
82
- key = familyKey(font);
83
- if (registered.has(key) || !font.url)
84
- return [3 /*break*/, 5];
85
- _c.label = 2;
86
- case 2:
87
- _c.trys.push([2, 4, , 5]);
88
- format = font.format ? " format('".concat(font.format, "')") : '';
89
- source = "url(".concat(JSON.stringify(font.url), ")").concat(format);
90
- face = new FontFace(font.family, source, {
91
- weight: String((_a = font.weight) !== null && _a !== void 0 ? _a : '400'),
92
- style: (_b = font.style) !== null && _b !== void 0 ? _b : 'normal',
93
- display: 'swap'
94
- });
95
- return [4 /*yield*/, loadFaceWithTimeout(face)];
96
- case 3:
97
- loaded = _c.sent();
98
- document.fonts.add(loaded);
99
- registered.add(key);
100
- return [3 /*break*/, 5];
101
- case 4:
102
- error_1 = _c.sent();
103
- console.warn("Canvas: workspace font \"".concat(font.family, "\" could not load"), error_1);
104
- return [3 /*break*/, 5];
105
- case 5:
106
- _i++;
107
- return [3 /*break*/, 1];
108
- case 6: return [2 /*return*/];
109
- }
110
- });
111
- });
32
+ async function registerFontsOnce(fonts) {
33
+ for (const font of fonts) {
34
+ const key = familyKey(font);
35
+ if (registered.has(key) || !font.url)
36
+ continue;
37
+ try {
38
+ const format = font.format ? ` format('${font.format}')` : '';
39
+ const source = `url(${JSON.stringify(font.url)})${format}`;
40
+ const face = new FontFace(font.family, source, {
41
+ weight: String(font.weight ?? '400'),
42
+ style: font.style ?? 'normal',
43
+ display: 'swap'
44
+ });
45
+ const loaded = await loadFaceWithTimeout(face);
46
+ document.fonts.add(loaded);
47
+ registered.add(key);
48
+ }
49
+ catch (error) {
50
+ console.warn(`Canvas: workspace font "${font.family}" could not load`, error);
51
+ }
52
+ }
112
53
  }
113
54
  /**
114
55
  * Registers the brand-kit fonts with the browser, so a text set in one is drawn in it. The page loads its brand kit after the
@@ -120,6 +61,6 @@ export function registerWorkspaceFonts(fonts) {
120
61
  if (typeof document === 'undefined' || typeof FontFace === 'undefined')
121
62
  return Promise.resolve();
122
63
  // `registerFontsOnce` never rejects (each font is tried inside its own try/catch), so the queue never stays broken.
123
- registerQueue = registerQueue.then(function () { return registerFontsOnce(fonts); });
64
+ registerQueue = registerQueue.then(() => registerFontsOnce(fonts));
124
65
  return registerQueue;
125
66
  }
@@ -1,7 +1,7 @@
1
1
  import { getShapeByKey } from '../canvas/shapes/ShapeLibrary.js';
2
2
  // The groups of the shape library are kept under their English names (a shape of a saved canvas knows its group by that
3
3
  // name); this says each in the page's language.
4
- var CATEGORY_KEYS = {
4
+ const CATEGORY_KEYS = {
5
5
  'Geometric Shapes': 'canvas.category.geometric',
6
6
  'Arrow Shapes': 'canvas.category.arrows',
7
7
  'Media Icons': 'canvas.category.media',
@@ -11,14 +11,14 @@ var CATEGORY_KEYS = {
11
11
  /** The name of a group of the shape library, by the English name the library keeps it under. */
12
12
  export function categoryLabel(category, t) {
13
13
  // Only the table's own entries: a group called "constructor" is not a method of the table.
14
- var key = Object.prototype.hasOwnProperty.call(CATEGORY_KEYS, category) ? CATEGORY_KEYS[category] : undefined;
14
+ const key = Object.prototype.hasOwnProperty.call(CATEGORY_KEYS, category) ? CATEGORY_KEYS[category] : undefined;
15
15
  return key ? t(key) : category;
16
16
  }
17
17
  /** The name of a library shape the library no longer knows (an old save): its key as words ("arrow-right" → "Arrow Right"). */
18
18
  function wordsOfKey(shapeKey) {
19
19
  return shapeKey
20
20
  .split('-')
21
- .map(function (word) { return word.charAt(0).toUpperCase() + word.slice(1); })
21
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
22
22
  .join(' ');
23
23
  }
24
24
  /**
@@ -49,7 +49,7 @@ export function objectName(object, t) {
49
49
  return t('canvas.tool.triangle');
50
50
  if (object.shape === 'arrow')
51
51
  return t('canvas.tool.arrow');
52
- var known = getShapeByKey(object.shape);
52
+ const known = getShapeByKey(object.shape);
53
53
  return t('canvas.type.drawingOf', { name: known ? t(known.labelKey) : wordsOfKey(object.shape) });
54
54
  }
55
55
  }
@@ -6,23 +6,23 @@ import { CANVAS_MESSAGES } from './messages.js';
6
6
  * canvas) reads its words from it (`useCanvasLanguage`). The context belongs to one root, so two canvases on a page can
7
7
  * speak two languages.
8
8
  */
9
- var canvasWords = createI18n({ catalog: CANVAS_MESSAGES, label: 'Canvas' });
9
+ const canvasWords = createI18n({ catalog: CANVAS_MESSAGES, label: 'Canvas' });
10
10
  /**
11
11
  * Called by the root component of a canvas while it is created, so everything inside it speaks the page's language.
12
12
  * It gives back the words as stores and `update(settings)` for when the page sets the language again.
13
13
  */
14
- export var provideCanvasLanguage = canvasWords.provideI18n;
14
+ export const provideCanvasLanguage = canvasWords.provideI18n;
15
15
  /**
16
16
  * Called by a part of the canvas while it is created. Gives its words as stores, so a part that is already on the screen
17
17
  * changes when the page sets the language again. Outside a canvas (a part used on its own, such as the colour control)
18
18
  * it speaks English.
19
19
  */
20
- export var useCanvasLanguage = canvasWords.useI18n;
20
+ export const useCanvasLanguage = canvasWords.useI18n;
21
21
  /**
22
22
  * The English `t` of the canvas, for code that has no component around it. The screens of the canvas get their words, in
23
23
  * the page's language, from `useCanvasLanguage`.
24
24
  */
25
- export var translateEnglish = canvasWords.translateEnglish;
25
+ export const translateEnglish = canvasWords.translateEnglish;
26
26
  /**
27
27
  * Checks a page's `messages` against the canvas's catalog without showing anything: a key that does not exist (with the
28
28
  * nearest real one), a value that is not text, a template that does not parse, or one that asks for a value the message
@@ -14,7 +14,7 @@
14
14
  * - the English names the canvas keeps for the things it saves ("libraryShape", "Symbol Shapes", a shape's key): they
15
15
  * are data, and a screen says them with the messages below.
16
16
  */
17
- export var CANVAS_MESSAGES = {
17
+ export const CANVAS_MESSAGES = {
18
18
  // ===== The canvas itself =====
19
19
  'canvas.state.loading': 'Loading canvas…',
20
20
  'canvas.state.initFailed': 'Canvas failed to initialize.',
@@ -3,7 +3,7 @@
3
3
  * the two cannot disagree. A letter is the same on every keyboard, so it is not a message. `G` is not one of them on purpose: it
4
4
  * hides the alignment guides while it is held (the triangle has `Y`).
5
5
  */
6
- export var TOOL_KEYS = {
6
+ export const TOOL_KEYS = {
7
7
  select: 'V',
8
8
  hand: 'H',
9
9
  erase: 'E',
@@ -21,21 +21,21 @@ export var TOOL_KEYS = {
21
21
  * toolbar buttons name it in `aria-keyshortcuts`. A digit is the same on every keyboard, so it is not a message either. The
22
22
  * engine's table (`TOOL_DIGITS`) is the one that answers the key; a test holds the two together.
23
23
  */
24
- export var TOOL_DIGIT_KEYS = {
24
+ export const TOOL_DIGIT_KEYS = {
25
25
  select: '1',
26
26
  draw: '2',
27
27
  erase: '3',
28
28
  arrow: '4',
29
29
  text: '5'
30
30
  };
31
- var named = function (name) { return ({ name: name }); };
32
- var cap = function (text) { return ({ cap: text }); };
33
- var PLUS = null;
34
- var CTRL = named('canvas.key.ctrlCmd');
35
- var ALT = named('canvas.key.alt');
36
- var SHIFT = named('canvas.key.shift');
31
+ const named = (name) => ({ name });
32
+ const cap = (text) => ({ cap: text });
33
+ const PLUS = null;
34
+ const CTRL = named('canvas.key.ctrlCmd');
35
+ const ALT = named('canvas.key.alt');
36
+ const SHIFT = named('canvas.key.shift');
37
37
  /** The keyboard shortcuts of the canvas, in the order of the list that opens with "?". */
38
- export var SHORTCUT_GROUPS = [
38
+ export const SHORTCUT_GROUPS = [
39
39
  {
40
40
  title: 'canvas.shortcuts.groupTools',
41
41
  shortcuts: [
@@ -103,11 +103,11 @@ export var SHORTCUT_GROUPS = [
103
103
  ];
104
104
  /** The list of keyboard shortcuts in the page's language. */
105
105
  export function shortcutGroups(t) {
106
- return SHORTCUT_GROUPS.map(function (group) { return ({
106
+ return SHORTCUT_GROUPS.map((group) => ({
107
107
  title: t(group.title),
108
- shortcuts: group.shortcuts.map(function (shortcut) { return ({
108
+ shortcuts: group.shortcuts.map((shortcut) => ({
109
109
  label: t(shortcut.label),
110
- keys: shortcut.keys.map(function (key) { return (key === null ? null : 'name' in key ? t(key.name) : key.cap); })
111
- }); })
112
- }); });
110
+ keys: shortcut.keys.map((key) => (key === null ? null : 'name' in key ? t(key.name) : key.cap))
111
+ }))
112
+ }));
113
113
  }
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  * - Dynamic: const { Canvas } = await import('@widgetic/canvas')
8
8
  */
9
9
  export { Canvas } from './canvas';
10
- export type { WidgetConversionPayload, StrokeRecognizer, StrokeRecognitionRequest, StrokeRecognitionResult, CanvasFlyOptions, CanvasMoveOptions } from './canvas';
10
+ export type { WidgetConversionPayload, StrokeRecognizer, StrokeRecognitionRequest, StrokeRecognitionResult, CanvasClearCause, CanvasFlyOptions, CanvasMoveOptions } from './canvas';
11
11
  export type { BoardFileKind, BoardFilePickRequest, BoardFilePicker, BoardLibraryFile, BoardPicture, BoardPictureLibraryFile } from './canvas';
12
12
  export { TOOLBAR_POSITIONS, DEFAULT_TOOLBAR_POSITION } from './canvas';
13
13
  export type { ToolbarPosition } from './canvas';
@@ -18,16 +18,16 @@
18
18
  * It holds nothing private: pixel distances and the toolbar's place.
19
19
  */
20
20
  /** Where the placement is kept. The page and the creator are separate programs on one origin, so they meet here. */
21
- export var BOARD_PLACEMENT_STORAGE_KEY = 'widgetic.canvas.boardPlacement';
22
- export var BOARD_PLACEMENT_VERSION = 1;
21
+ export const BOARD_PLACEMENT_STORAGE_KEY = 'widgetic.canvas.boardPlacement';
22
+ export const BOARD_PLACEMENT_VERSION = 1;
23
23
  /** The window width from which the chat stands beside the board. */
24
- export var WIDE_LAYOUT_MIN_WIDTH = 1024;
24
+ export const WIDE_LAYOUT_MIN_WIDTH = 1024;
25
25
  /** The window width from which the chat stands below the board. */
26
- export var MEDIUM_LAYOUT_MIN_WIDTH = 768;
26
+ export const MEDIUM_LAYOUT_MIN_WIDTH = 768;
27
27
  /** The most a distance may be (a placement with more is not a board card, it is a measurement gone wrong). */
28
- var MAX_DISTANCE = 2000;
28
+ const MAX_DISTANCE = 2_000;
29
29
  /** The smallest board a placement may describe, in CSS pixels on each side. */
30
- var MIN_BOARD_SIDE = 120;
30
+ const MIN_BOARD_SIDE = 120;
31
31
  /** The layout the creator is in at this window width. */
32
32
  export function boardLayoutOf(viewportWidth) {
33
33
  if (viewportWidth >= WIDE_LAYOUT_MIN_WIDTH)
@@ -44,23 +44,23 @@ function distanceIsUsable(value) {
44
44
  * size, the board lies outside the host, or it is too small to be a board.
45
45
  */
46
46
  export function measureBoardPlacement(host, board, details) {
47
- var top = Math.round(board.top - host.top);
48
- var left = Math.round(board.left - host.left);
49
- var right = Math.round(host.right - board.right);
50
- var bottom = Math.round(host.bottom - board.bottom);
47
+ const top = Math.round(board.top - host.top);
48
+ const left = Math.round(board.left - host.left);
49
+ const right = Math.round(host.right - board.right);
50
+ const bottom = Math.round(host.bottom - board.bottom);
51
51
  if (![top, right, bottom, left].every(distanceIsUsable))
52
52
  return null;
53
- var boardWidth = host.right - host.left - left - right;
54
- var boardHeight = host.bottom - host.top - top - bottom;
53
+ const boardWidth = host.right - host.left - left - right;
54
+ const boardHeight = host.bottom - host.top - top - bottom;
55
55
  if (!(boardWidth >= MIN_BOARD_SIDE) || !(boardHeight >= MIN_BOARD_SIDE))
56
56
  return null;
57
57
  return {
58
58
  version: BOARD_PLACEMENT_VERSION,
59
59
  layout: boardLayoutOf(details.viewportWidth),
60
- top: top,
61
- right: right,
62
- bottom: bottom,
63
- left: left,
60
+ top,
61
+ right,
62
+ bottom,
63
+ left,
64
64
  toolbarPosition: typeof details.toolbarPosition === 'string' && details.toolbarPosition.length <= 8 ? details.toolbarPosition : null,
65
65
  showDrawingTools: details.showDrawingTools !== false
66
66
  };
@@ -69,27 +69,26 @@ function defaultStorage() {
69
69
  try {
70
70
  return typeof localStorage === 'undefined' ? null : localStorage;
71
71
  }
72
- catch (_a) {
72
+ catch {
73
73
  // A sandboxed frame refuses even the lookup.
74
74
  return null;
75
75
  }
76
76
  }
77
77
  /** What was written last by this page, so a placement that has not changed is not written again (a measurement is taken at every save). */
78
- var lastWritten = null;
78
+ let lastWritten = null;
79
79
  /** Keeps the placement for the next visit. Writes only what changed. Returns whether it wrote. Never throws. */
80
- export function rememberBoardPlacement(placement, storage) {
81
- if (storage === void 0) { storage = defaultStorage(); }
80
+ export function rememberBoardPlacement(placement, storage = defaultStorage()) {
82
81
  if (!storage)
83
82
  return false;
84
83
  try {
85
- var text = JSON.stringify(placement);
84
+ const text = JSON.stringify(placement);
86
85
  if (text === lastWritten)
87
86
  return false;
88
87
  storage.setItem(BOARD_PLACEMENT_STORAGE_KEY, text);
89
88
  lastWritten = text;
90
89
  return true;
91
90
  }
92
- catch (_a) {
91
+ catch {
93
92
  // Storage is full or refused: the next visit draws the empty board, as it did before the placement existed.
94
93
  return false;
95
94
  }
@@ -98,18 +97,17 @@ export function rememberBoardPlacement(placement, storage) {
98
97
  * The placement kept by the last visit, for the layout the window is in now. Null when none was kept, it is damaged, or it was
99
98
  * measured in another layout (its distances would put the board in the wrong place).
100
99
  */
101
- export function recallBoardPlacement(viewportWidth, storage) {
102
- if (storage === void 0) { storage = defaultStorage(); }
100
+ export function recallBoardPlacement(viewportWidth, storage = defaultStorage()) {
103
101
  if (!storage)
104
102
  return null;
105
103
  try {
106
- var text = storage.getItem(BOARD_PLACEMENT_STORAGE_KEY);
104
+ const text = storage.getItem(BOARD_PLACEMENT_STORAGE_KEY);
107
105
  if (!text)
108
106
  return null;
109
- var value = JSON.parse(text);
107
+ const value = JSON.parse(text);
110
108
  if (typeof value !== 'object' || value === null)
111
109
  return null;
112
- var record = value;
110
+ const record = value;
113
111
  if (record.version !== BOARD_PLACEMENT_VERSION)
114
112
  return null;
115
113
  if (record.layout !== boardLayoutOf(viewportWidth))
@@ -118,7 +116,7 @@ export function recallBoardPlacement(viewportWidth, storage) {
118
116
  return null;
119
117
  if (typeof record.showDrawingTools !== 'boolean')
120
118
  return null;
121
- var toolbarPosition = typeof record.toolbarPosition === 'string' && record.toolbarPosition.length <= 8 ? record.toolbarPosition : null;
119
+ const toolbarPosition = typeof record.toolbarPosition === 'string' && record.toolbarPosition.length <= 8 ? record.toolbarPosition : null;
122
120
  return {
123
121
  version: BOARD_PLACEMENT_VERSION,
124
122
  layout: record.layout,
@@ -126,11 +124,11 @@ export function recallBoardPlacement(viewportWidth, storage) {
126
124
  right: record.right,
127
125
  bottom: record.bottom,
128
126
  left: record.left,
129
- toolbarPosition: toolbarPosition,
127
+ toolbarPosition,
130
128
  showDrawingTools: record.showDrawingTools
131
129
  };
132
130
  }
133
- catch (_a) {
131
+ catch {
134
132
  return null;
135
133
  }
136
134
  }