@widgetic/canvas 0.5.41 → 0.5.42

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 (85) hide show
  1. package/dist/canvas/autosaveScheduler.js +37 -89
  2. package/dist/canvas/boardFrame.js +1 -1
  3. package/dist/canvas/boardSurface.js +1 -1
  4. package/dist/canvas/canvasLogger.js +7 -19
  5. package/dist/canvas/chromeLayout.js +17 -18
  6. package/dist/canvas/eventScope.js +10 -14
  7. package/dist/canvas/host/CanvasHost.js +1286 -1536
  8. package/dist/canvas/host/CanvasHostApi.js +4 -19
  9. package/dist/canvas/host/browserServices.js +65 -116
  10. package/dist/canvas/host/conversion.js +82 -170
  11. package/dist/canvas/host/hostObject.js +7 -7
  12. package/dist/canvas/host/pageEvents.js +4 -4
  13. package/dist/canvas/host/screenRects.js +28 -31
  14. package/dist/canvas/host/strokeSnap.js +88 -143
  15. package/dist/canvas/openMarks.js +2 -2
  16. package/dist/canvas/outsideClickDeselect.js +6 -7
  17. package/dist/canvas/panZoomPosition.js +2 -2
  18. package/dist/canvas/preferredTextFont.js +13 -25
  19. package/dist/canvas/shapes/ShapeLibrary.js +138 -148
  20. package/dist/canvas/shapes/shapeImageStore.js +3 -3
  21. package/dist/canvas/shapes/strokeShapeSnap.js +188 -233
  22. package/dist/canvas/toolbarPosition.js +2 -2
  23. package/dist/canvas/ui/colorModel.js +21 -32
  24. package/dist/canvas/ui/colorPickerMessages.js +5 -5
  25. package/dist/canvas/ui/floatingCard.js +18 -18
  26. package/dist/canvas/ui/floatingLayer.js +5 -6
  27. package/dist/canvas/ui/keyHints.js +9 -11
  28. package/dist/canvas/ui/popoverSide.js +2 -3
  29. package/dist/canvas/ui/selectionTraits.js +34 -40
  30. package/dist/canvas/view/erasingMarks.js +7 -7
  31. package/dist/canvas/view/geometry.js +71 -90
  32. package/dist/components/preferenceStorage.js +2 -2
  33. package/dist/engine/EngineCore.js +696 -795
  34. package/dist/engine/codec/canvasDocument.js +183 -147
  35. package/dist/engine/codec/hostReadableKeys.js +1 -1
  36. package/dist/engine/core/arrange.js +26 -38
  37. package/dist/engine/core/arrow.js +76 -89
  38. package/dist/engine/core/arrowBinding.js +98 -116
  39. package/dist/engine/core/arrowBindingRecords.js +23 -38
  40. package/dist/engine/core/brush.js +67 -94
  41. package/dist/engine/core/defaults.js +90 -51
  42. package/dist/engine/core/freehand.js +147 -163
  43. package/dist/engine/core/geometry.js +47 -54
  44. package/dist/engine/core/history.js +33 -50
  45. package/dist/engine/core/hitTest.js +68 -81
  46. package/dist/engine/core/matrix.js +18 -20
  47. package/dist/engine/core/pathData.js +183 -210
  48. package/dist/engine/core/rotationReset.js +5 -6
  49. package/dist/engine/core/scene.js +129 -187
  50. package/dist/engine/core/scribble.js +59 -84
  51. package/dist/engine/core/shapePaths.js +12 -15
  52. package/dist/engine/core/shapeTools.js +72 -63
  53. package/dist/engine/core/snapping.js +65 -117
  54. package/dist/engine/core/style.js +31 -64
  55. package/dist/engine/core/transform.js +83 -94
  56. package/dist/engine/core/types.js +4 -4
  57. package/dist/engine/core/viewport.js +23 -36
  58. package/dist/engine/input/PointerController.js +467 -474
  59. package/dist/engine/input/arrowHandles.js +12 -12
  60. package/dist/engine/input/gestures.js +262 -308
  61. package/dist/engine/input/hoverCursor.js +1 -1
  62. package/dist/engine/input/keyboard.js +27 -30
  63. package/dist/engine/input/selectionHandles.js +45 -50
  64. package/dist/engine/input/types.js +1 -1
  65. package/dist/engine/render/rasterize.js +86 -158
  66. package/dist/engine/state.js +4 -15
  67. package/dist/engine/text/layoutText.js +43 -62
  68. package/dist/engine/text/textMetrics.js +8 -10
  69. package/dist/engine/widgets.js +101 -137
  70. package/dist/fonts/interFont.js +17 -68
  71. package/dist/fonts/workspaceFonts.js +32 -90
  72. package/dist/i18n/labels.js +4 -4
  73. package/dist/i18n/language.js +4 -4
  74. package/dist/i18n/messages.js +1 -1
  75. package/dist/i18n/shortcuts.js +14 -14
  76. package/dist/settings/workspaceToolSettings.js +32 -48
  77. package/dist/tools/components/catalog.js +64 -74
  78. package/dist/tools/components/grouping.js +6 -28
  79. package/dist/tools/definitions.js +5 -5
  80. package/dist/tools/executors.js +105 -141
  81. package/dist/tools/hostAdapter.js +11 -13
  82. package/dist/tools/sceneSummary.js +43 -57
  83. package/dist/tools/sketchIntent.js +13 -21
  84. package/dist/tools/types.js +1 -1
  85. package/package.json +1 -1
@@ -19,48 +19,12 @@
19
19
  *
20
20
  * Kept free of Svelte and of the DOM (the clock can be replaced) so that Node can test it.
21
21
  */
22
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
23
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
24
- return new (P || (P = Promise))(function (resolve, reject) {
25
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
26
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
27
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
28
- step((generator = generator.apply(thisArg, _arguments || [])).next());
29
- });
30
- };
31
- var __generator = (this && this.__generator) || function (thisArg, body) {
32
- 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);
33
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
34
- function verb(n) { return function (v) { return step([n, v]); }; }
35
- function step(op) {
36
- if (f) throw new TypeError("Generator is already executing.");
37
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
38
- 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;
39
- if (y = 0, t) op = [op[0] & 2, t.value];
40
- switch (op[0]) {
41
- case 0: case 1: t = op; break;
42
- case 4: _.label++; return { value: op[1], done: false };
43
- case 5: _.label++; y = op[1]; op = [0]; continue;
44
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
45
- default:
46
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
47
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
48
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
49
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
50
- if (t[2]) _.ops.pop();
51
- _.trys.pop(); continue;
52
- }
53
- op = body.call(thisArg, _);
54
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
55
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
56
- }
57
- };
58
22
  /** The shortest time a save that is held back waits before the host is asked again, so that a delay of 0 does not spin. */
59
- var SHORTEST_RECHECK_DELAY_MS = 250;
60
- var realClock = {
61
- now: function () { return Date.now(); },
62
- setTimer: function (callback, delayMs) { return setTimeout(callback, delayMs); },
63
- clearTimer: function (handle) { return clearTimeout(handle); }
23
+ const SHORTEST_RECHECK_DELAY_MS = 250;
24
+ const realClock = {
25
+ now: () => Date.now(),
26
+ setTimer: (callback, delayMs) => setTimeout(callback, delayMs),
27
+ clearTimer: (handle) => clearTimeout(handle)
64
28
  };
65
29
  /** A number a host passed as a duration: anything that is not a finite number of at least 0 is 0. */
66
30
  function toDurationMs(value) {
@@ -70,20 +34,19 @@ function isPromiseLike(value) {
70
34
  return !!value && typeof value.then === 'function';
71
35
  }
72
36
  export function createAutosaveScheduler(options) {
73
- var _a;
74
- var clock = (_a = options.clock) !== null && _a !== void 0 ? _a : realClock;
37
+ const clock = options.clock ?? realClock;
75
38
  /** Something changed that no save has taken yet. */
76
- var dirty = false;
39
+ let dirty = false;
77
40
  /** When the first change that no save has taken yet was made: where the longest wait is counted from. */
78
- var firstChangeAt = null;
79
- var timerHandle = null;
41
+ let firstChangeAt = null;
42
+ let timerHandle = null;
80
43
  /** The save that is on its way, if there is one. It never rejects. */
81
- var saveOnItsWay = null;
44
+ let saveOnItsWay = null;
82
45
  /** The next save fell due while another was on its way: it starts as soon as that one is done. */
83
- var dueWhileSaving = false;
46
+ let dueWhileSaving = false;
84
47
  /** How many saves in a row have failed. A save that goes through, or a board that was just loaded, makes it 0. */
85
- var failuresInARow = 0;
86
- var disposed = false;
48
+ let failuresInARow = 0;
49
+ let disposed = false;
87
50
  function stopTimer() {
88
51
  if (timerHandle === null)
89
52
  return;
@@ -107,8 +70,7 @@ export function createAutosaveScheduler(options) {
107
70
  }
108
71
  /** Starts the save, or, when the host holds saves back, looks again a delay later. */
109
72
  function saveUnlessHeldBack() {
110
- var _a;
111
- if ((_a = options.isSuspended) === null || _a === void 0 ? void 0 : _a.call(options)) {
73
+ if (options.isSuspended?.()) {
112
74
  startTimer(Math.max(toDurationMs(options.getDelayMs()), SHORTEST_RECHECK_DELAY_MS));
113
75
  return;
114
76
  }
@@ -118,7 +80,7 @@ export function createAutosaveScheduler(options) {
118
80
  function scheduleRetry() {
119
81
  if (disposed || timerHandle !== null || !options.getRetryDelayMs)
120
82
  return;
121
- var waitMs = 0;
83
+ let waitMs = 0;
122
84
  try {
123
85
  waitMs = toDurationMs(options.getRetryDelayMs(failuresInARow));
124
86
  }
@@ -129,13 +91,12 @@ export function createAutosaveScheduler(options) {
129
91
  startTimer(waitMs);
130
92
  }
131
93
  function noteFailure(error) {
132
- var _a;
133
94
  // What the failed save was meant to keep is not kept: it is unsaved again, and the retry (or the next change or
134
95
  // flush) tries again.
135
96
  dirty = true;
136
97
  failuresInARow += 1;
137
98
  try {
138
- (_a = options.onSaveFailed) === null || _a === void 0 ? void 0 : _a.call(options, error);
99
+ options.onSaveFailed?.(error);
139
100
  }
140
101
  catch (reportError) {
141
102
  console.warn('[autosave] onSaveFailed threw', reportError);
@@ -149,7 +110,7 @@ export function createAutosaveScheduler(options) {
149
110
  // made while the save is on its way) is unsaved again, and is the next save's.
150
111
  dirty = false;
151
112
  firstChangeAt = null;
152
- var outcome;
113
+ let outcome;
153
114
  try {
154
115
  outcome = options.save();
155
116
  }
@@ -161,11 +122,11 @@ export function createAutosaveScheduler(options) {
161
122
  failuresInARow = 0;
162
123
  return Promise.resolve();
163
124
  }
164
- var running = Promise.resolve(outcome)
165
- .then(function () {
125
+ const running = Promise.resolve(outcome)
126
+ .then(() => {
166
127
  failuresInARow = 0;
167
- }, function (error) { return noteFailure(error); })
168
- .then(function () {
128
+ }, (error) => noteFailure(error))
129
+ .then(() => {
169
130
  if (saveOnItsWay === running)
170
131
  saveOnItsWay = null;
171
132
  if (disposed)
@@ -181,36 +142,23 @@ export function createAutosaveScheduler(options) {
181
142
  function markChanged() {
182
143
  if (disposed)
183
144
  return;
184
- var now = clock.now();
145
+ const now = clock.now();
185
146
  dirty = true;
186
147
  if (firstChangeAt === null)
187
148
  firstChangeAt = now;
188
- var quietUntil = now + toDurationMs(options.getDelayMs());
189
- var longestWait = toDurationMs(options.getMaxWaitMs());
190
- var dueAt = longestWait > 0 ? Math.min(quietUntil, firstChangeAt + longestWait) : quietUntil;
149
+ const quietUntil = now + toDurationMs(options.getDelayMs());
150
+ const longestWait = toDurationMs(options.getMaxWaitMs());
151
+ const dueAt = longestWait > 0 ? Math.min(quietUntil, firstChangeAt + longestWait) : quietUntil;
191
152
  startTimer(dueAt - now);
192
153
  }
193
- function flush() {
194
- return __awaiter(this, void 0, Promise, function () {
195
- return __generator(this, function (_a) {
196
- switch (_a.label) {
197
- case 0:
198
- if (!saveOnItsWay) return [3 /*break*/, 2];
199
- return [4 /*yield*/, saveOnItsWay];
200
- case 1:
201
- _a.sent();
202
- return [3 /*break*/, 0];
203
- case 2:
204
- // Nothing changed since the last save (or the last failure left nothing unsaved): there is nothing to send.
205
- if (disposed || !dirty)
206
- return [2 /*return*/];
207
- return [4 /*yield*/, startSave()];
208
- case 3:
209
- _a.sent();
210
- return [2 /*return*/];
211
- }
212
- });
213
- });
154
+ async function flush() {
155
+ // A save on its way finishes first, so that two never overlap.
156
+ while (saveOnItsWay)
157
+ await saveOnItsWay;
158
+ // Nothing changed since the last save (or the last failure left nothing unsaved): there is nothing to send.
159
+ if (disposed || !dirty)
160
+ return;
161
+ await startSave();
214
162
  }
215
163
  function cancel() {
216
164
  stopTimer();
@@ -224,10 +172,10 @@ export function createAutosaveScheduler(options) {
224
172
  disposed = true;
225
173
  }
226
174
  return {
227
- markChanged: markChanged,
228
- flush: flush,
229
- cancel: cancel,
230
- dispose: dispose,
175
+ markChanged,
176
+ flush,
177
+ cancel,
178
+ dispose,
231
179
  get isDirty() {
232
180
  return dirty;
233
181
  }
@@ -10,4 +10,4 @@
10
10
  * Written out in full, so that the stylesheet of a page that installs the canvas picks every class up when it reads this
11
11
  * file. Kept free of Svelte and of the DOM so that Node can test it.
12
12
  */
13
- export var BOARD_FRAME_CLASSES = 'rounded-card after:pointer-events-none after:absolute after:inset-0 after:z-50 after:rounded-[inherit] after:border after:border-border';
13
+ export const BOARD_FRAME_CLASSES = 'rounded-card after:pointer-events-none after:absolute after:inset-0 after:z-50 after:rounded-[inherit] after:border after:border-border';
@@ -10,4 +10,4 @@
10
10
  * white in the design, while the full canvas stays `muted`). Nothing else changes: the variable is not set anywhere else, so
11
11
  * the board, the creator and the embeds keep the token.
12
12
  */
13
- export var BOARD_SURFACE_COLOR = 'var(--canvas-surface, var(--muted, #f5f5f5))';
13
+ export const BOARD_SURFACE_COLOR = 'var(--canvas-surface, var(--muted, #f5f5f5))';
@@ -1,31 +1,19 @@
1
- var _enabled = true;
1
+ let _enabled = true;
2
2
  export function setCanvasLogsEnabled(enabled) {
3
3
  _enabled = enabled;
4
4
  }
5
5
  export function isCanvasLogsEnabled() {
6
6
  return _enabled;
7
7
  }
8
- export function canvasLog() {
9
- var args = [];
10
- for (var _i = 0; _i < arguments.length; _i++) {
11
- args[_i] = arguments[_i];
12
- }
8
+ export function canvasLog(...args) {
13
9
  if (_enabled)
14
- console.log.apply(console, args);
10
+ console.log(...args);
15
11
  }
16
- export function canvasWarn() {
17
- var args = [];
18
- for (var _i = 0; _i < arguments.length; _i++) {
19
- args[_i] = arguments[_i];
20
- }
12
+ export function canvasWarn(...args) {
21
13
  if (_enabled)
22
- console.warn.apply(console, args);
14
+ console.warn(...args);
23
15
  }
24
- export function canvasDebug() {
25
- var args = [];
26
- for (var _i = 0; _i < arguments.length; _i++) {
27
- args[_i] = arguments[_i];
28
- }
16
+ export function canvasDebug(...args) {
29
17
  if (_enabled)
30
- console.debug.apply(console, args);
18
+ console.debug(...args);
31
19
  }
@@ -19,12 +19,12 @@
19
19
  */
20
20
  import { ZOOM_CONTROL_MIN_WIDTHS, ZOOM_CONTROL_VISIBLE_FROM } from './ui/floatingCard.js';
21
21
  /** The eight places a card can stand. */
22
- export var CHROME_ANCHORS = ['TL', 'TC', 'TR', 'CL', 'CR', 'BL', 'BC', 'BR'];
22
+ export const CHROME_ANCHORS = ['TL', 'TC', 'TR', 'CL', 'CR', 'BL', 'BC', 'BR'];
23
23
  /**
24
24
  * The classes that put an anchor in place, 16 px from the edges as the Figma design has it. Written out in full, so that
25
25
  * the stylesheet of a page that installs the canvas picks every one of them up when it reads this file.
26
26
  */
27
- var ANCHOR_CLASSES = {
27
+ const ANCHOR_CLASSES = {
28
28
  // rtl-ok: the page names a corner of the screen, as it is drawn
29
29
  TL: 'absolute top-4 left-4',
30
30
  TC: 'absolute top-4 left-1/2 -translate-x-1/2',
@@ -45,9 +45,9 @@ var ANCHOR_CLASSES = {
45
45
  * are against), a column on a side edge (centred on each other, so the layout does not depend on the direction of the
46
46
  * page). A slot never grows larger than the board minus its 16 px edges.
47
47
  */
48
- var SLOT_TOP_ROW_CLASSES = 'flex flex-row items-start gap-2 max-w-[calc(100%-2rem)]';
49
- var SLOT_BOTTOM_ROW_CLASSES = 'flex flex-row items-end gap-2 max-w-[calc(100%-2rem)]';
50
- var SLOT_COLUMN_CLASSES = 'flex flex-col items-center gap-2 max-h-[calc(100%-2rem)]';
48
+ const SLOT_TOP_ROW_CLASSES = 'flex flex-row items-start gap-2 max-w-[calc(100%-2rem)]';
49
+ const SLOT_BOTTOM_ROW_CLASSES = 'flex flex-row items-end gap-2 max-w-[calc(100%-2rem)]';
50
+ const SLOT_COLUMN_CLASSES = 'flex flex-col items-center gap-2 max-h-[calc(100%-2rem)]';
51
51
  /** The anchor to use for what a page passed: anything that is not one of the eight is the fallback, so a mistyped option never takes a card off the board. */
52
52
  export function normalizeAnchor(value, fallback) {
53
53
  return CHROME_ANCHORS.includes(value) ? value : fallback;
@@ -77,19 +77,18 @@ export function anchorClasses(anchor) {
77
77
  * from one anchor to another does not make the other one start again.
78
78
  */
79
79
  export function chromeSlots(toolbarAnchor, zoomAnchor, shown) {
80
- var slots = [];
81
- for (var _i = 0, CHROME_ANCHORS_1 = CHROME_ANCHORS; _i < CHROME_ANCHORS_1.length; _i++) {
82
- var anchor = CHROME_ANCHORS_1[_i];
83
- var cards = [];
80
+ const slots = [];
81
+ for (const anchor of CHROME_ANCHORS) {
82
+ const cards = [];
84
83
  if (shown.toolbar && toolbarAnchor === anchor)
85
84
  cards.push('toolbar');
86
85
  if (shown.zoom && zoomAnchor === anchor)
87
86
  cards.push('zoom');
88
87
  if (cards.length === 0)
89
88
  continue;
90
- var vertical = isSideAnchor(anchor);
91
- var layout = vertical ? SLOT_COLUMN_CLASSES : isTopAnchor(anchor) ? SLOT_TOP_ROW_CLASSES : SLOT_BOTTOM_ROW_CLASSES;
92
- slots.push({ anchor: anchor, cards: cards, vertical: vertical, classes: "".concat(ANCHOR_CLASSES[anchor], " ").concat(layout) });
89
+ const vertical = isSideAnchor(anchor);
90
+ const layout = vertical ? SLOT_COLUMN_CLASSES : isTopAnchor(anchor) ? SLOT_TOP_ROW_CLASSES : SLOT_BOTTOM_ROW_CLASSES;
91
+ slots.push({ anchor, cards, vertical, classes: `${ANCHOR_CLASSES[anchor]} ${layout}` });
93
92
  }
94
93
  return slots;
95
94
  }
@@ -102,8 +101,8 @@ export function zoomVisibilityClasses(toolbarAnchor, zoomAnchor) {
102
101
  // A card on a side edge shares no line with a card on the top or the bottom edge, and neither do two cards on different edges.
103
102
  if (isSideAnchor(toolbarAnchor) || isSideAnchor(zoomAnchor) || toolbarAnchor[0] !== zoomAnchor[0])
104
103
  return ZOOM_CONTROL_VISIBLE_FROM.alone;
105
- var toolbarColumn = toolbarAnchor[1];
106
- var zoomColumn = zoomAnchor[1];
104
+ const toolbarColumn = toolbarAnchor[1];
105
+ const zoomColumn = zoomAnchor[1];
107
106
  if (toolbarColumn === zoomColumn)
108
107
  return ZOOM_CONTROL_VISIBLE_FROM.sameSlot;
109
108
  if (toolbarColumn === 'C')
@@ -114,7 +113,7 @@ export function zoomVisibilityClasses(toolbarAnchor, zoomAnchor) {
114
113
  }
115
114
  /** Minimum board width (px) before the zoom card is drawn; pairs with scoped `@container` CSS in `ZoomControl.svelte`. */
116
115
  export function zoomVisibilityMinWidth(toolbarAnchor, zoomAnchor) {
117
- var className = zoomVisibilityClasses(toolbarAnchor, zoomAnchor);
116
+ const className = zoomVisibilityClasses(toolbarAnchor, zoomAnchor);
118
117
  if (className === ZOOM_CONTROL_VISIBLE_FROM.alone)
119
118
  return ZOOM_CONTROL_MIN_WIDTHS.alone;
120
119
  if (className === ZOOM_CONTROL_VISIBLE_FROM.sameSlot)
@@ -125,13 +124,13 @@ export function zoomVisibilityMinWidth(toolbarAnchor, zoomAnchor) {
125
124
  return ZOOM_CONTROL_MIN_WIDTHS.centredBesideCornerToolbar;
126
125
  return ZOOM_CONTROL_MIN_WIDTHS.oppositeCorners;
127
126
  }
128
- var TOP_PANEL_CONFLICT_ANCHORS = new Set(['TC', 'TR']);
127
+ const TOP_PANEL_CONFLICT_ANCHORS = new Set(['TC', 'TR']);
129
128
  /** What the panel keeps clear of, for the slots that are drawn. */
130
129
  export function panelClearanceFor(slots) {
131
- var rightEdgeSlot = slots.find(function (slot) { return slot.anchor === 'CR'; });
130
+ const rightEdgeSlot = slots.find((slot) => slot.anchor === 'CR');
132
131
  return {
133
132
  // Top-left chrome (e.g. zoom on the creator big page) does not overlap the top-right selection panel.
134
- belowTopCards: slots.some(function (slot) { return TOP_PANEL_CONFLICT_ANCHORS.has(slot.anchor); }),
133
+ belowTopCards: slots.some((slot) => TOP_PANEL_CONFLICT_ANCHORS.has(slot.anchor)),
135
134
  besideSideCard: rightEdgeSlot ? (rightEdgeSlot.cards.includes('toolbar') ? 'toolbar' : 'zoom') : null
136
135
  };
137
136
  }
@@ -16,10 +16,9 @@
16
16
  */
17
17
  /** The shadow root a node lives in, or null when it lives in the page itself (or is not in a tree at all). */
18
18
  export function getShadowRootOf(node) {
19
- var _a;
20
- var root = (_a = node === null || node === void 0 ? void 0 : node.getRootNode) === null || _a === void 0 ? void 0 : _a.call(node);
19
+ const root = node?.getRootNode?.();
21
20
  // (`instanceof ShadowRoot` would not hold for a root made by another window, an iframe's, say.)
22
- var isShadowRoot = !!root && root.nodeType === 11 && 'host' in root;
21
+ const isShadowRoot = !!root && root.nodeType === 11 && 'host' in root;
23
22
  return isShadowRoot ? root : null;
24
23
  }
25
24
  /**
@@ -32,14 +31,14 @@ export function getShadowRootOf(node) {
32
31
  * Has to be called while the event is being dispatched (`composedPath()` is empty afterwards).
33
32
  */
34
33
  export function eventIsForScope(event, scopeNode) {
35
- var shadowRoot = getShadowRootOf(scopeNode);
34
+ const shadowRoot = getShadowRootOf(scopeNode);
36
35
  if (!shadowRoot)
37
36
  return true;
38
37
  return event.composedPath().includes(shadowRoot);
39
38
  }
40
39
  /** The element that has the focus in the tree `scopeNode` lives in: the page's, or the shadow root's own. */
41
40
  export function getFocusedElementIn(scopeNode) {
42
- var shadowRoot = getShadowRootOf(scopeNode);
41
+ const shadowRoot = getShadowRootOf(scopeNode);
43
42
  return shadowRoot ? shadowRoot.activeElement : document.activeElement;
44
43
  }
45
44
  /**
@@ -47,8 +46,7 @@ export function getFocusedElementIn(scopeNode) {
47
46
  * event from inside a shadow root; the first element of the path is the one that was pressed.
48
47
  */
49
48
  export function getEventOrigin(event) {
50
- var _a;
51
- var first = (_a = event.composedPath()[0]) !== null && _a !== void 0 ? _a : event.target;
49
+ const first = event.composedPath()[0] ?? event.target;
52
50
  return first && first.nodeType === 1 ? first : null;
53
51
  }
54
52
  /**
@@ -66,8 +64,7 @@ export function eventWentThrough(event, element) {
66
64
  * page never sees it, and otherwise `document.body`.
67
65
  */
68
66
  export function getTransientHostFor(scopeNode) {
69
- var _a;
70
- return (_a = getShadowRootOf(scopeNode)) !== null && _a !== void 0 ? _a : document.body;
67
+ return getShadowRootOf(scopeNode) ?? document.body;
71
68
  }
72
69
  /**
73
70
  * Whether the canvas whose element is `scopeNode` should take the keyboard back after the element that held it went away
@@ -79,15 +76,14 @@ export function getTransientHostFor(scopeNode) {
79
76
  * the shortcuts do not mind where the focus is, so there is nothing to do.
80
77
  */
81
78
  export function shouldTakeFocusBack(scopeNode) {
82
- var _a;
83
- var shadowRoot = getShadowRootOf(scopeNode);
79
+ const shadowRoot = getShadowRootOf(scopeNode);
84
80
  if (!shadowRoot)
85
81
  return false;
86
82
  if (shadowRoot.activeElement)
87
83
  return false;
88
84
  // The focus in the tree the shadow root's host is in (the page's, or another shadow root's).
89
- var outerTree = shadowRoot.host.getRootNode();
90
- var focusOutside = outerTree.activeElement;
91
- var outerBody = (_a = outerTree.body) !== null && _a !== void 0 ? _a : null;
85
+ const outerTree = shadowRoot.host.getRootNode();
86
+ const focusOutside = outerTree.activeElement;
87
+ const outerBody = outerTree.body ?? null;
92
88
  return !focusOutside || focusOutside === shadowRoot.host || focusOutside === outerBody;
93
89
  }