@relo-ui/web 0.0.0-stage → 0.1.0-rc.1

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 (127) hide show
  1. package/README.md +27 -2
  2. package/dist/LICENSE +202 -0
  3. package/dist/NOTICE +5 -0
  4. package/dist/core/contracts.d.ts +72 -0
  5. package/dist/core/contracts.js +76 -0
  6. package/dist/core/document.d.ts +16 -0
  7. package/dist/core/document.js +21 -0
  8. package/dist/core/engine.d.ts +8 -0
  9. package/dist/core/engine.js +28 -0
  10. package/dist/core/index.d.ts +7 -0
  11. package/dist/core/index.js +7 -0
  12. package/dist/core/runtime.d.ts +23 -0
  13. package/dist/core/runtime.js +46 -0
  14. package/dist/core/schema.d.ts +56 -0
  15. package/dist/core/schema.js +72 -0
  16. package/dist/core/session.d.ts +88 -0
  17. package/dist/core/session.js +520 -0
  18. package/dist/core/value.d.ts +18 -0
  19. package/dist/core/value.js +118 -0
  20. package/dist/dom/accessibility.d.ts +2 -0
  21. package/dist/dom/accessibility.js +69 -0
  22. package/dist/dom/icons.d.ts +1 -0
  23. package/dist/dom/icons.js +21 -0
  24. package/dist/dom/images.d.ts +59 -0
  25. package/dist/dom/images.js +406 -0
  26. package/dist/dom/index.d.ts +3 -0
  27. package/dist/dom/index.js +2 -0
  28. package/dist/dom/inputs.d.ts +5 -0
  29. package/dist/dom/inputs.js +85 -0
  30. package/dist/dom/lists.d.ts +7 -0
  31. package/dist/dom/lists.js +48 -0
  32. package/dist/dom/measurement.d.ts +16 -0
  33. package/dist/dom/measurement.js +67 -0
  34. package/dist/dom/motion-lifecycle.d.ts +17 -0
  35. package/dist/dom/motion-lifecycle.js +28 -0
  36. package/dist/dom/motion-plan.d.ts +44 -0
  37. package/dist/dom/motion-plan.js +31 -0
  38. package/dist/dom/motion.d.ts +73 -0
  39. package/dist/dom/motion.js +817 -0
  40. package/dist/dom/mount-plan.d.ts +15 -0
  41. package/dist/dom/mount-plan.js +58 -0
  42. package/dist/dom/presentation.d.ts +11 -0
  43. package/dist/dom/presentation.js +331 -0
  44. package/dist/dom/primitives.d.ts +16 -0
  45. package/dist/dom/primitives.js +378 -0
  46. package/dist/dom/range.d.ts +9 -0
  47. package/dist/dom/range.js +120 -0
  48. package/dist/dom/renderer.d.ts +99 -0
  49. package/dist/dom/renderer.js +1041 -0
  50. package/dist/dom/scroll.d.ts +7 -0
  51. package/dist/dom/scroll.js +167 -0
  52. package/dist/dom/shared-layout.d.ts +40 -0
  53. package/dist/dom/shared-layout.js +440 -0
  54. package/dist/dom/style.d.ts +35 -0
  55. package/dist/dom/style.js +337 -0
  56. package/dist/dom/text-motion.d.ts +17 -0
  57. package/dist/dom/text-motion.js +185 -0
  58. package/dist/dom/theme.d.ts +13 -0
  59. package/dist/dom/theme.js +65 -0
  60. package/dist/index.d.ts +10 -0
  61. package/dist/index.js +18 -0
  62. package/dist/licenses/Rust-COPYRIGHT-library.html +29357 -0
  63. package/dist/licenses/archery-1.2.3/LICENSE.md +21 -0
  64. package/dist/licenses/bytemuck-1.25.2/LICENSE-APACHE +61 -0
  65. package/dist/licenses/bytemuck-1.25.2/LICENSE-MIT +9 -0
  66. package/dist/licenses/bytemuck-1.25.2/LICENSE-ZLIB +11 -0
  67. package/dist/licenses/cargo.json +340 -0
  68. package/dist/licenses/cfg-if-1.0.5/LICENSE-APACHE +201 -0
  69. package/dist/licenses/cfg-if-1.0.5/LICENSE-MIT +25 -0
  70. package/dist/licenses/equivalent-1.0.2/LICENSE-APACHE +201 -0
  71. package/dist/licenses/equivalent-1.0.2/LICENSE-MIT +25 -0
  72. package/dist/licenses/futures-core-0.3.34/LICENSE-APACHE +202 -0
  73. package/dist/licenses/futures-core-0.3.34/LICENSE-MIT +26 -0
  74. package/dist/licenses/futures-task-0.3.34/LICENSE-APACHE +202 -0
  75. package/dist/licenses/futures-task-0.3.34/LICENSE-MIT +26 -0
  76. package/dist/licenses/futures-util-0.3.34/LICENSE-APACHE +202 -0
  77. package/dist/licenses/futures-util-0.3.34/LICENSE-MIT +26 -0
  78. package/dist/licenses/imbl-7.0.2/LICENCE.md +355 -0
  79. package/dist/licenses/imbl-sized-chunks-0.2.0/LICENCE.md +355 -0
  80. package/dist/licenses/itoa-1.0.18/LICENSE-APACHE +176 -0
  81. package/dist/licenses/itoa-1.0.18/LICENSE-MIT +23 -0
  82. package/dist/licenses/js-sys-0.3.106/LICENSE-APACHE +201 -0
  83. package/dist/licenses/js-sys-0.3.106/LICENSE-MIT +25 -0
  84. package/dist/licenses/memchr-2.8.3/COPYING +3 -0
  85. package/dist/licenses/memchr-2.8.3/LICENSE-MIT +21 -0
  86. package/dist/licenses/once_cell-1.21.4/LICENSE-APACHE +201 -0
  87. package/dist/licenses/once_cell-1.21.4/LICENSE-MIT +23 -0
  88. package/dist/licenses/pin-project-lite-0.2.17/LICENSE-APACHE +177 -0
  89. package/dist/licenses/pin-project-lite-0.2.17/LICENSE-MIT +23 -0
  90. package/dist/licenses/rand_core-0.9.5/COPYRIGHT +12 -0
  91. package/dist/licenses/rand_core-0.9.5/LICENSE-APACHE +187 -0
  92. package/dist/licenses/rand_core-0.9.5/LICENSE-MIT +26 -0
  93. package/dist/licenses/rand_xoshiro-0.7.0/COPYRIGHT +12 -0
  94. package/dist/licenses/rand_xoshiro-0.7.0/LICENSE-APACHE +176 -0
  95. package/dist/licenses/rand_xoshiro-0.7.0/LICENSE-MIT +25 -0
  96. package/dist/licenses/roxmltree-0.21.1/LICENSE-APACHE +201 -0
  97. package/dist/licenses/roxmltree-0.21.1/LICENSE-MIT +21 -0
  98. package/dist/licenses/safe_arch-0.7.4/LICENSE-APACHE.md +61 -0
  99. package/dist/licenses/safe_arch-0.7.4/LICENSE-MIT.md +9 -0
  100. package/dist/licenses/safe_arch-0.7.4/LICENSE-ZLIB.md +11 -0
  101. package/dist/licenses/serde-1.0.229/LICENSE-APACHE +176 -0
  102. package/dist/licenses/serde-1.0.229/LICENSE-MIT +23 -0
  103. package/dist/licenses/serde_core-1.0.229/LICENSE-APACHE +176 -0
  104. package/dist/licenses/serde_core-1.0.229/LICENSE-MIT +23 -0
  105. package/dist/licenses/serde_json-1.0.151/LICENSE-APACHE +176 -0
  106. package/dist/licenses/serde_json-1.0.151/LICENSE-MIT +23 -0
  107. package/dist/licenses/slab-0.4.12/LICENSE +25 -0
  108. package/dist/licenses/slotmap-1.1.1/LICENSE +19 -0
  109. package/dist/licenses/smallvec-1.16.3/LICENSE-APACHE +201 -0
  110. package/dist/licenses/smallvec-1.16.3/LICENSE-MIT +25 -0
  111. package/dist/licenses/taffy-0.15.0/taffy-0.15.0-LICENSE +22 -0
  112. package/dist/licenses/unicode-ident-1.0.26/LICENSE-APACHE +176 -0
  113. package/dist/licenses/unicode-ident-1.0.26/LICENSE-MIT +23 -0
  114. package/dist/licenses/unicode-ident-1.0.26/LICENSE-UNICODE +39 -0
  115. package/dist/licenses/wasm-bindgen-0.2.129/LICENSE-APACHE +201 -0
  116. package/dist/licenses/wasm-bindgen-0.2.129/LICENSE-MIT +25 -0
  117. package/dist/licenses/wasm-bindgen-shared-0.2.129/LICENSE-APACHE +201 -0
  118. package/dist/licenses/wasm-bindgen-shared-0.2.129/LICENSE-MIT +25 -0
  119. package/dist/licenses/web-time-1.1.0/LICENSE-APACHE +201 -0
  120. package/dist/licenses/web-time-1.1.0/LICENSE-MIT +21 -0
  121. package/dist/licenses/wide-0.7.33/LICENSE-ZLIB.md +11 -0
  122. package/dist/licenses/zmij-1.0.23/LICENSE-MIT +23 -0
  123. package/dist/wasm/relo_wasm.d.ts +179 -0
  124. package/dist/wasm/relo_wasm.js +1228 -0
  125. package/dist/wasm/relo_wasm_bg.wasm +0 -0
  126. package/dist/wasm/relo_wasm_bg.wasm.d.ts +65 -0
  127. package/package.json +25 -4
@@ -0,0 +1,1041 @@
1
+ import { captureList, listWindow } from './lists.js';
2
+ import { fail } from '../core/value.js';
3
+ import { paint, color, surfaceCSS, layoutStyle } from './style.js';
4
+ import { initializeAdvanced, updateAdvanced, activate, coordinateSelection, visible, selected, } from './primitives.js';
5
+ import { initializeScroll, captureScroll, finishScroll, scrollCommand } from './scroll.js';
6
+ import { MotionCoordinator } from './motion.js';
7
+ import { DomLayout } from './shared-layout.js';
8
+ import { MountPlan } from './mount-plan.js';
9
+ import { initializeInput, updateInput, inputCSS } from './inputs.js';
10
+ import { namedIcons } from './icons.js';
11
+ import { rangeCSS } from './range.js';
12
+ import { coordinateTables } from './accessibility.js';
13
+ import { DefaultImageLoader, MountedImage, imageCSS } from './images.js';
14
+ import { presentationCSS, positionPresentation } from './presentation.js';
15
+ import { themedNode, validateTheme } from './theme.js';
16
+ export const supportedBuiltins = new Set([
17
+ 'Column',
18
+ 'Row',
19
+ 'Overlay',
20
+ 'View',
21
+ 'Theme',
22
+ 'Direction',
23
+ 'Text',
24
+ 'Button',
25
+ 'TextField',
26
+ 'TextArea',
27
+ 'Toggle',
28
+ 'Progress',
29
+ 'Image',
30
+ 'Icon',
31
+ 'Pressable',
32
+ 'Scroll',
33
+ 'Spacer',
34
+ 'Divider',
35
+ 'Grid',
36
+ 'Checkable',
37
+ 'SelectionGroup',
38
+ 'Range',
39
+ 'Meter',
40
+ 'Popup',
41
+ 'Gesture',
42
+ 'RichText',
43
+ 'Split',
44
+ 'Scrollbar',
45
+ 'List',
46
+ ]);
47
+ const deniedImageLoader = async () => {
48
+ throw new Error('Image unavailable');
49
+ };
50
+ let labelSequence = 0;
51
+ export class RemoteSurface {
52
+ container;
53
+ options;
54
+ element;
55
+ styleElement;
56
+ mounted = new Map();
57
+ adapterElements = new WeakMap();
58
+ containerSize = { width: -1, height: -1 };
59
+ resize;
60
+ media = matchMedia('(prefers-color-scheme: dark)');
61
+ reducedMedia = matchMedia('(prefers-reduced-motion: reduce)');
62
+ controller = new AbortController();
63
+ release;
64
+ root;
65
+ frame = 0;
66
+ layingOut = false;
67
+ disposed = false;
68
+ mounts = new MountPlan();
69
+ rendering = false;
70
+ motion = new MotionCoordinator(() => this.layout(), () => this.primitiveHost.refresh());
71
+ refreshFrame = 0;
72
+ viewportRefresh = false;
73
+ stateRefresh = false;
74
+ interactionRevision = 0;
75
+ environment = [];
76
+ tableStructure = '';
77
+ labelStructure = '';
78
+ activationTarget;
79
+ primitiveHost = {
80
+ dispatch: (value, event, payload) => this.dispatch(value, event, payload),
81
+ requestLayout: () => this.requestLayout(),
82
+ focusOrigin: () => this.activationTarget ?? document.activeElement,
83
+ viewportChanged: () => {
84
+ this.viewportRefresh = true;
85
+ this.scheduleRefresh();
86
+ },
87
+ refresh: () => {
88
+ this.stateRefresh = true;
89
+ this.scheduleRefresh();
90
+ },
91
+ find: (id) => this.mounted.get(id),
92
+ };
93
+ hosts = new Map();
94
+ scheduleRefresh() {
95
+ if (!this.disposed && !this.refreshFrame)
96
+ this.refreshFrame = requestAnimationFrame(() => {
97
+ this.refreshFrame = 0;
98
+ this.render(this.options.session.graph, !this.stateRefresh);
99
+ });
100
+ }
101
+ interaction(value, kind, active) {
102
+ if (value[kind] === active)
103
+ return;
104
+ value[kind] = active;
105
+ const revision = ++this.interactionRevision;
106
+ for (let ancestor = value; ancestor; ancestor = ancestor.parent)
107
+ ancestor.extra.interactionRevision = revision;
108
+ this.primitiveHost.refresh();
109
+ }
110
+ geometryRevision = 0;
111
+ sharedLayout = new DomLayout(this.motion, () => this.rendering);
112
+ constructor(container, options) {
113
+ this.container = container;
114
+ this.options = options;
115
+ if (options.tokens)
116
+ options.tokens = validateTheme(options.tokens);
117
+ this.element = document.createElement('div');
118
+ this.element.className = 'relo-surface';
119
+ this.element.dir = options.direction ?? 'ltr';
120
+ this.styleElement = document.createElement('style');
121
+ this.styleElement.textContent = surfaceCSS + inputCSS + rangeCSS + presentationCSS + imageCSS;
122
+ container.append(this.styleElement, this.element);
123
+ this.resize = new ResizeObserver((entries) => {
124
+ for (const entry of entries) {
125
+ if (entry.target === container) {
126
+ if (container.clientWidth !== this.containerSize.width ||
127
+ (options.sizing === 'viewport' && container.clientHeight !== this.containerSize.height))
128
+ this.requestLayout();
129
+ }
130
+ else {
131
+ const value = this.adapterElements.get(entry.target);
132
+ const box = entry.borderBoxSize[0];
133
+ // Assigning an adapter's measured frame also fires ResizeObserver.
134
+ // Only an independent intrinsic resize needs another measurement.
135
+ if (value &&
136
+ box &&
137
+ (Math.abs(box.inlineSize - parseFloat(value.content.style.width)) > 0.5 ||
138
+ Math.abs(box.blockSize - parseFloat(value.content.style.height)) > 0.5))
139
+ this.requestLayout(value);
140
+ }
141
+ }
142
+ });
143
+ this.resize.observe(container);
144
+ this.media.addEventListener('change', () => this.render(options.session.graph), {
145
+ signal: this.controller.signal,
146
+ });
147
+ document.fonts?.addEventListener('loadingdone', () => {
148
+ this.requestLayout();
149
+ }, {
150
+ signal: this.controller.signal,
151
+ });
152
+ document.addEventListener('visibilitychange', () => {
153
+ this.motion.setVisible(!document.hidden);
154
+ this.syncImages();
155
+ for (const value of this.mounted.values())
156
+ value.adapter?.setVisible?.(visible(value) && !document.hidden);
157
+ }, { signal: this.controller.signal });
158
+ try {
159
+ this.release = options.session.attach(this);
160
+ }
161
+ catch (error) {
162
+ this.dispose();
163
+ throw error;
164
+ }
165
+ }
166
+ setTheme(tokens) {
167
+ this.options.tokens = validateTheme(tokens);
168
+ this.render(this.options.session.graph);
169
+ }
170
+ get dark() {
171
+ return this.options.theme === 'dark' || (this.options.theme !== 'light' && this.media.matches);
172
+ }
173
+ create(node) {
174
+ const element = document.createElement('div');
175
+ element.className = 'relo-box';
176
+ element.dataset.reloId = node.id;
177
+ element.dataset.reloType = node.type;
178
+ const value = {
179
+ node,
180
+ element,
181
+ childHost: element,
182
+ children: [],
183
+ controller: new AbortController(),
184
+ composing: false,
185
+ focused: false,
186
+ pressed: false,
187
+ prior: '',
188
+ style: layoutStyle(node.classes),
189
+ extra: {},
190
+ };
191
+ this.mounted.set(node.id, value);
192
+ const registration = this.options.session.components.get(node.type);
193
+ if (registration) {
194
+ const requirement = registration.definition.host;
195
+ let host;
196
+ if (requirement) {
197
+ if (this.options.componentHosts?.has(requirement.key))
198
+ host = this.options.componentHosts.get(requirement.key);
199
+ else {
200
+ if (!this.hosts.has(requirement.key))
201
+ this.hosts.set(requirement.key, requirement.create());
202
+ host = this.hosts.get(requirement.key).context;
203
+ }
204
+ }
205
+ const context = {
206
+ host,
207
+ report: (error) => this.options.session.report(error),
208
+ signal: value.controller.signal,
209
+ requestLayout: () => this.requestLayout(value),
210
+ emit: (event, payload = {}) => {
211
+ if (!registration.events.has(event)) {
212
+ this.options.session.report(new Error('Undeclared component event'));
213
+ return;
214
+ }
215
+ this.dispatch(value, event, payload);
216
+ },
217
+ };
218
+ value.adapter = registration.definition.create(context);
219
+ if (!(value.adapter.element instanceof HTMLElement))
220
+ fail('DOM adapters must supply an HTMLElement');
221
+ value.content = value.adapter.element;
222
+ element.append(value.content);
223
+ if (registration.maximumChildren) {
224
+ if (!value.adapter.childrenHost)
225
+ fail('Child-hosting adapters must supply childrenHost');
226
+ value.childHost = value.adapter.childrenHost;
227
+ }
228
+ this.resize.observe(value.content);
229
+ this.adapterElements.set(value.content, value);
230
+ }
231
+ else {
232
+ const advanced = initializeAdvanced(value, this.primitiveHost);
233
+ if (!advanced)
234
+ switch (node.type) {
235
+ case 'Text':
236
+ value.content = document.createElement('span');
237
+ break;
238
+ case 'Button':
239
+ value.content = document.createElement('button');
240
+ value.content.type = 'button';
241
+ break;
242
+ case 'Pressable':
243
+ // A Pressable may contain other controls. A native button would
244
+ // flatten their semantics and create invalid nested buttons.
245
+ value.content = document.createElement('div');
246
+ value.content.setAttribute('role', 'button');
247
+ value.content.tabIndex = 0;
248
+ value.childHost = value.content;
249
+ break;
250
+ case 'TextField':
251
+ value.content = document.createElement('input');
252
+ break;
253
+ case 'TextArea':
254
+ value.content = document.createElement('textarea');
255
+ break;
256
+ case 'Toggle':
257
+ value.content = document.createElement('input');
258
+ value.content.type = 'checkbox';
259
+ break;
260
+ case 'Progress':
261
+ value.content = document.createElement('progress');
262
+ break;
263
+ case 'Image':
264
+ value.content = document.createElement('img');
265
+ break;
266
+ case 'Icon':
267
+ value.content = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
268
+ break;
269
+ case 'Scroll':
270
+ value.content = document.createElement('div');
271
+ value.content.className = 'relo-scroll';
272
+ value.childHost = value.content;
273
+ break;
274
+ }
275
+ if (value.content && !advanced) {
276
+ value.content.classList.add('relo-control');
277
+ element.append(value.content);
278
+ }
279
+ initializeInput(value);
280
+ // These child hosts cover the outer box; authored insets belong to that
281
+ // box. Establish the reset before recording geometry, not during layout.
282
+ if (node.type === 'Pressable' || node.type === 'Checkable')
283
+ value.content.style.padding = '0';
284
+ if (node.type === 'Image')
285
+ value.extra.image = new MountedImage(value, (success) => this.dispatch(value, 'load', { success }));
286
+ if (!advanced)
287
+ this.listen(value);
288
+ }
289
+ element.addEventListener('focusin', () => {
290
+ this.interaction(value, 'focused', true);
291
+ }, { signal: value.controller.signal });
292
+ element.addEventListener('focusout', () => {
293
+ this.interaction(value, 'focused', false);
294
+ }, { signal: value.controller.signal });
295
+ element.addEventListener('pointerdown', () => {
296
+ this.interaction(value, 'pressed', true);
297
+ }, { signal: value.controller.signal });
298
+ for (const event of ['pointerup', 'pointercancel', 'pointerleave'])
299
+ element.addEventListener(event, () => {
300
+ this.interaction(value, 'pressed', false);
301
+ }, { signal: value.controller.signal });
302
+ return value;
303
+ }
304
+ listen(value) {
305
+ const { content, node } = value;
306
+ if (!content)
307
+ return;
308
+ const on = (name, handler) => content.addEventListener(name, handler, { signal: value.controller.signal });
309
+ if (node.type === 'Button' || node.type === 'Pressable')
310
+ content.setAttribute('data-relo-activation', '');
311
+ if (node.type === 'Button' || node.type === 'Pressable')
312
+ on('click', (event) => {
313
+ const target = event.target;
314
+ if (target.closest('[data-relo-activation],button,input,textarea,select,a,[role="checkbox"],[role="slider"]') !== content)
315
+ return;
316
+ activate(value, this.primitiveHost);
317
+ });
318
+ if (node.type === 'Pressable') {
319
+ on('keydown', (event) => {
320
+ const key = event;
321
+ if (event.target !== content || (key.key !== 'Enter' && key.key !== ' '))
322
+ return;
323
+ key.preventDefault();
324
+ if (key.key === 'Enter' && !key.repeat)
325
+ activate(value, this.primitiveHost);
326
+ });
327
+ on('keyup', (event) => {
328
+ const key = event;
329
+ if (event.target === content && key.key === ' ') {
330
+ key.preventDefault();
331
+ activate(value, this.primitiveHost);
332
+ }
333
+ });
334
+ }
335
+ if (node.type === 'Toggle')
336
+ on('change', () => this.dispatch(value, 'change', { value: content.checked }));
337
+ if (node.type === 'TextField' || node.type === 'TextArea') {
338
+ on('compositionstart', () => {
339
+ value.composing = true;
340
+ value.extra.committedText = content.value;
341
+ });
342
+ on('compositionend', () => {
343
+ value.composing = false;
344
+ const text = content.value;
345
+ if (text !== value.extra.committedText)
346
+ this.dispatch(value, 'change', { value: text });
347
+ value.extra.compositionText = text;
348
+ });
349
+ on('input', (event) => {
350
+ const text = content.value;
351
+ if (value.extra.compositionText === text) {
352
+ delete value.extra.compositionText;
353
+ return;
354
+ }
355
+ delete value.extra.compositionText;
356
+ if (!value.composing && !event.isComposing)
357
+ this.dispatch(value, 'change', { value: text });
358
+ });
359
+ if (node.type === 'TextField')
360
+ on('keydown', (event) => {
361
+ const key = event;
362
+ if (key.key === 'Enter' && !key.isComposing && !value.composing)
363
+ this.dispatch(value, 'submit', { value: content.value });
364
+ });
365
+ }
366
+ if (node.type === 'Scroll')
367
+ initializeScroll(value, this.primitiveHost);
368
+ }
369
+ dispatch(value, event, payload = {}) {
370
+ if (this.disposed ||
371
+ value.controller.signal.aborted ||
372
+ this.mounted.get(value.node.id) !== value ||
373
+ !visible(value) ||
374
+ value.node.props.enabled === false ||
375
+ !value.element.isConnected)
376
+ return;
377
+ for (let parent = value.element.parentElement; parent && parent !== this.element; parent = parent.parentElement)
378
+ if (parent.hidden || parent.getAttribute('aria-disabled') === 'true')
379
+ return;
380
+ const previous = this.activationTarget;
381
+ if (event === 'press')
382
+ this.activationTarget = value.content instanceof HTMLElement ? value.content : value.element;
383
+ try {
384
+ this.options.session.dispatch(value.node.id, event, payload);
385
+ }
386
+ finally {
387
+ this.activationTarget = previous;
388
+ }
389
+ }
390
+ render(graph, viewportOnly = false) {
391
+ if (this.disposed)
392
+ return;
393
+ const geometryBefore = this.geometryRevision;
394
+ // A graph commit already includes pending focus/pressed and viewport changes.
395
+ cancelAnimationFrame(this.refreshFrame);
396
+ this.refreshFrame = 0;
397
+ const viewportRefresh = this.viewportRefresh || viewportOnly;
398
+ this.viewportRefresh = this.stateRefresh = false;
399
+ const environment = [
400
+ this.options.tokens,
401
+ this.dark,
402
+ this.options.session.motionPolicy,
403
+ this.options.session.motionEpoch,
404
+ this.reducedMedia.matches,
405
+ this.element.dir,
406
+ ];
407
+ const environmentChanged = environment.some((part, index) => part !== this.environment[index]);
408
+ this.mounts.update(this.options.session, graph, false);
409
+ const replaceMounts = this.mounts.replaced;
410
+ const retired = new Set(this.mounts.retired);
411
+ for (const id of retired) {
412
+ const value = this.mounted.get(id);
413
+ if (value && !replaceMounts && (!value.parent || !retired.has(value.parent.node.id)))
414
+ this.motion.remove(id, this.dark);
415
+ }
416
+ for (const id of retired) {
417
+ const value = this.mounted.get(id);
418
+ if (value)
419
+ this.destroy(value);
420
+ }
421
+ this.rendering = true;
422
+ this.element.style.colorScheme = this.dark ? 'dark' : 'light';
423
+ const textCaptures = viewportOnly
424
+ ? undefined
425
+ : this.motion.captureText(this.mounted.values(), this.options.session.motionPolicy, this.options.session.motionEpoch);
426
+ this.motion.begin(this.options.session.motionEpoch);
427
+ for (const value of this.mounted.values())
428
+ if (value.node.type === 'Scroll')
429
+ captureScroll(value);
430
+ const reconcile = (node, parent, owner) => {
431
+ let value = this.mounted.get(node.id);
432
+ if (value && value.node.type !== node.type) {
433
+ this.destroy(value);
434
+ value = undefined;
435
+ }
436
+ const priorNode = value?.node;
437
+ const revision = value?.extra.interactionRevision ?? 0;
438
+ const context = [
439
+ owner?.extra.disabled,
440
+ owner?.extra.inheritedClasses,
441
+ owner?.extra.selectionContext,
442
+ owner?.extra.direction,
443
+ owner ? visible(owner) : true,
444
+ ];
445
+ if (value &&
446
+ !this.mounts.changed.has(node.id) &&
447
+ !viewportRefresh &&
448
+ !environmentChanged &&
449
+ value.extra.reconciledRevision === revision &&
450
+ value.element.parentElement === parent &&
451
+ context.every((part, index) => part === value.extra.parentContext?.[index])) {
452
+ return value;
453
+ }
454
+ if (value && node.type === 'List')
455
+ captureList(value);
456
+ value ??= this.create(node);
457
+ this.motion.beforeUpdate(value, node.shown && (node.type !== 'Popup' || node.props.value === true), this.dark);
458
+ value.extra.retaining = this.motion.isRetaining(node.id);
459
+ value.node = node;
460
+ value.parent = owner;
461
+ value.extra.selectionContext =
462
+ node.type === 'SelectionGroup' ? node.props : owner?.extra.selectionContext;
463
+ value.extra.direction =
464
+ node.type === 'Direction' ? node.props.value : (owner?.extra.direction ?? this.element.dir);
465
+ const wasMaterialized = value.extra.materialized;
466
+ value.extra.materialized = !this.sharedLayout || this.mounts.materialized(node.id);
467
+ value.extra.layoutIdentity = this.mounts.incarnation(node.id);
468
+ if (value.extra.materialized) {
469
+ if (wasMaterialized === false)
470
+ value.childHost = value.element;
471
+ if (value.element.parentElement !== parent)
472
+ parent.append(value.element);
473
+ }
474
+ else {
475
+ // The inert layout wrapper remains logical metadata. Its children use
476
+ // the nearest actual DOM container and Rust composes their offsets.
477
+ value.childHost = parent;
478
+ value.element.remove();
479
+ }
480
+ const beforeGeometry = value.extra.geometryKey;
481
+ const updateKey = [
482
+ node.props,
483
+ node.theme,
484
+ node.classes,
485
+ node.shown,
486
+ node.decoded,
487
+ node.label_target,
488
+ this.options.tokens,
489
+ this.dark,
490
+ this.options.session.motionPolicy,
491
+ this.options.session.motionEpoch,
492
+ this.reducedMedia.matches,
493
+ value.focused,
494
+ value.pressed,
495
+ selected(value),
496
+ visible(value),
497
+ owner?.extra.disabled,
498
+ owner?.extra.inheritedClasses,
499
+ value.extra.direction,
500
+ ];
501
+ value.extra.paintDirty =
502
+ !value.extra.updateKey ||
503
+ updateKey.some((part, index) => part !== value.extra.updateKey[index]);
504
+ if (value.extra.paintDirty) {
505
+ this.update(value);
506
+ value.extra.updateKey = updateKey;
507
+ }
508
+ if (value.extra.paintDirty || priorNode !== node) {
509
+ const css = value.element.style;
510
+ value.extra.geometryKey = JSON.stringify([
511
+ value.style,
512
+ css.padding,
513
+ css.paddingInlineStart,
514
+ css.paddingInlineEnd,
515
+ css.borderWidth,
516
+ css.font,
517
+ // WebKit can leave the font shorthand empty after longhand updates.
518
+ css.fontSize,
519
+ css.fontFamily,
520
+ css.fontWeight,
521
+ css.fontStyle,
522
+ css.lineHeight,
523
+ css.letterSpacing,
524
+ ['TextField', 'TextArea'].includes(node.type)
525
+ ? css.getPropertyValue('--relo-input-border-width')
526
+ : undefined,
527
+ value.content?.style.font,
528
+ value.content?.style.padding,
529
+ value.extra.direction,
530
+ ]);
531
+ if (beforeGeometry !== value.extra.geometryKey)
532
+ delete value.extra.insets;
533
+ const geometryProps = { ...node.props };
534
+ delete geometryProps.selected;
535
+ delete geometryProps.enabled;
536
+ // Native editor buffers and controlled values do not determine intrinsic
537
+ // geometry. Labels, validation messages and presentation still do.
538
+ if ([
539
+ 'Checkable',
540
+ 'Toggle',
541
+ 'Range',
542
+ 'Scrollbar',
543
+ 'SelectionGroup',
544
+ 'TextField',
545
+ 'TextArea',
546
+ ].includes(node.type))
547
+ delete geometryProps.value;
548
+ const contentKey = JSON.stringify([
549
+ geometryProps,
550
+ node.shown,
551
+ node.children.map((child) => child.id),
552
+ ]);
553
+ if (value.extra.contentKey !== contentKey ||
554
+ beforeGeometry !== value.extra.geometryKey ||
555
+ node.type === 'List')
556
+ for (let ancestor = value; ancestor; ancestor = ancestor.parent) {
557
+ ancestor.extra.geometryRevision = ++this.geometryRevision;
558
+ }
559
+ value.extra.contentKey = contentKey;
560
+ }
561
+ const previousChildren = value.children;
562
+ let children = node.children;
563
+ if (node.type === 'List')
564
+ children = listWindow(value);
565
+ value.children = children.map((child) => reconcile(child, value.childHost, value));
566
+ if (node.type === 'List') {
567
+ const visible = new Set(children.map((child) => child.id));
568
+ for (const child of previousChildren)
569
+ if (!visible.has(child.node.id))
570
+ this.destroyBranch(child);
571
+ }
572
+ if (value.extra.materialized) {
573
+ const physical = (children) => children.flatMap((child) => child.extra.materialized === false ? physical(child.children) : [child]);
574
+ physical(value.children).forEach((child, i) => {
575
+ const current = value.childHost.children[i];
576
+ if (current !== child.element)
577
+ value.childHost.insertBefore(child.element, current ?? null);
578
+ });
579
+ }
580
+ value.extra.parentContext = context;
581
+ value.extra.reconciledRevision = revision;
582
+ return value;
583
+ };
584
+ this.root = reconcile(graph, this.element);
585
+ // Focus, pressed colors and fixed-size values need paint, not another layout.
586
+ // Keep synchronous sizing when the host changed before ResizeObserver ran.
587
+ if (this.geometryRevision !== geometryBefore ||
588
+ environmentChanged ||
589
+ viewportRefresh ||
590
+ this.containerSize.width !== this.container.clientWidth ||
591
+ this.containerSize.height !== this.container.clientHeight)
592
+ this.layout();
593
+ if (this.disposed) {
594
+ this.rendering = false;
595
+ return;
596
+ }
597
+ for (const value of this.mounted.values()) {
598
+ if (value.node.type === 'SelectionGroup') {
599
+ const key = [value.node, value.extra.rovingId, value.extra.disabled, visible(value)];
600
+ if (!value.extra.selectionKey ||
601
+ key.some((part, index) => part !== value.extra.selectionKey[index])) {
602
+ coordinateSelection(value, this.primitiveHost);
603
+ value.extra.selectionKey = key;
604
+ }
605
+ }
606
+ if (value.node.type === 'Split' && value.children.length === 3) {
607
+ const props = value.node.props, vertical = props.orientation === 'vertical', separator = value.children[1].element;
608
+ separator.tabIndex = 0;
609
+ separator.setAttribute('role', 'separator');
610
+ separator.setAttribute('aria-label', props.label);
611
+ separator.setAttribute('aria-orientation', vertical ? 'horizontal' : 'vertical');
612
+ separator.setAttribute('aria-valuenow', String(props.value));
613
+ separator.setAttribute('aria-valuemin', String(props.min ?? 10));
614
+ separator.setAttribute('aria-valuemax', String(props.max ?? 90));
615
+ separator.style.touchAction = 'none';
616
+ separator.style.cursor = vertical ? 'row-resize' : 'col-resize';
617
+ }
618
+ }
619
+ const associations = [...this.mounted.values()].filter((value) => value.node.label_target);
620
+ const labelStructure = JSON.stringify(associations.map((value) => [value.node.id, value.node.label_target]));
621
+ if (labelStructure !== this.labelStructure) {
622
+ for (const value of this.mounted.values())
623
+ value.content?.removeAttribute('aria-labelledby');
624
+ for (const value of associations)
625
+ if (value.content) {
626
+ const target = this.mounted.get(value.node.label_target)?.content;
627
+ if (target) {
628
+ value.content.id ||= `relo-label-${++labelSequence}`;
629
+ target.setAttribute('aria-labelledby', value.content.id);
630
+ }
631
+ }
632
+ this.labelStructure = labelStructure;
633
+ }
634
+ const structure = (value) => [
635
+ value.node.id,
636
+ value.node.props.semantics,
637
+ value.node.props.columns,
638
+ value.node.shown,
639
+ value.children.map(structure),
640
+ ];
641
+ const tableStructure = JSON.stringify([...this.mounted.values()]
642
+ .filter((value) => value.node.props.semantics === 'table')
643
+ .map(structure));
644
+ if (tableStructure !== this.tableStructure) {
645
+ coordinateTables(this.mounted.values());
646
+ this.tableStructure = tableStructure;
647
+ }
648
+ this.motion.finishText(textCaptures, this.mounted.values(), this.options.session.motionPolicy);
649
+ this.motion.commit(this.mounted.values(), this.options.session.motionPolicy, this.dark);
650
+ this.rendering = false;
651
+ if (this.motion.layoutActive) {
652
+ this.layout();
653
+ this.motion.paintAll();
654
+ }
655
+ for (const value of this.mounted.values())
656
+ if (value.node.type === 'Scroll')
657
+ finishScroll(value, this.primitiveHost);
658
+ this.environment = environment;
659
+ }
660
+ update(value) {
661
+ const { node, element, content } = value, props = node.props;
662
+ value.extra.selected = selected(value);
663
+ value.extra.disabled = props.enabled === false || value.parent?.extra.disabled === true;
664
+ if (!visible(value) && element.contains(document.activeElement)) {
665
+ if (node.type === 'Popup')
666
+ value.extra.popupFocus = document.activeElement;
667
+ document.activeElement?.blur();
668
+ }
669
+ element.hidden = !node.shown && !this.motion.isRetaining(node.id);
670
+ element.inert = !visible(value);
671
+ if (!visible(value))
672
+ element.setAttribute('aria-hidden', 'true');
673
+ else
674
+ element.removeAttribute('aria-hidden');
675
+ if (value.extra.disabled)
676
+ element.setAttribute('aria-disabled', 'true');
677
+ else
678
+ element.removeAttribute('aria-disabled');
679
+ value.adapter?.setVisible?.(visible(value) && !document.hidden);
680
+ const inherited = value.parent?.extra.inheritedClasses ?? '';
681
+ const reduced = this.options.session.motionPolicy !== 'system' ||
682
+ node.theme.motion !== 'system' ||
683
+ this.reducedMedia.matches;
684
+ value.extra.paintNode = themedNode(node, this.options.tokens ?? {});
685
+ value.extra.dark = this.dark;
686
+ const paintKey = [
687
+ value.extra.paintNode.theme,
688
+ node.classes,
689
+ inherited,
690
+ this.dark,
691
+ value.focused,
692
+ value.pressed,
693
+ reduced,
694
+ value.extra.selected,
695
+ value.extra.disabled,
696
+ !!props.expanded,
697
+ !!props.validationMessage,
698
+ value.extra.direction,
699
+ visible(value),
700
+ this.options.session.motionEpoch,
701
+ ];
702
+ // Text/editor values and accessibility labels still update below. They do
703
+ // not require resetting fonts, borders and padding on the live element.
704
+ if (!value.extra.paintKey ||
705
+ paintKey.some((part, index) => part !== value.extra.paintKey[index])) {
706
+ const expanded = paint(element, content, {
707
+ ...value.extra.paintNode,
708
+ props: { ...props, selected: value.extra.selected, enabled: !value.extra.disabled },
709
+ classes: `${inherited} ${node.classes}`,
710
+ }, this.dark, value.focused, value.pressed, reduced);
711
+ value.style = layoutStyle(expanded);
712
+ value.extra.expanded = expanded;
713
+ value.extra.inheritedClasses = expanded
714
+ .split(/\s+/)
715
+ .filter((token) => token.startsWith('text-') || token.startsWith('font-'))
716
+ .join(' ');
717
+ value.extra.paintKey = paintKey;
718
+ }
719
+ if (node.props.part)
720
+ element.dataset.reloPart = node.props.part;
721
+ if (node.type === 'Direction')
722
+ element.dir = props.value;
723
+ const accessible = props.semantics && props.semantics !== 'none' ? element : (content ?? element);
724
+ if (props.label !== undefined)
725
+ accessible.setAttribute('aria-label', props.label);
726
+ else
727
+ accessible.removeAttribute('aria-label');
728
+ if (props.accessibilityHint || props.description)
729
+ accessible.setAttribute('aria-description', props.description ?? props.accessibilityHint);
730
+ else
731
+ accessible.removeAttribute('aria-description');
732
+ if (props.semantics && props.semantics !== 'none') {
733
+ accessible.setAttribute('role', { columnHeader: 'columnheader', rowHeader: 'rowheader' }[props.semantics] ?? props.semantics);
734
+ if (props.semantics === 'heading')
735
+ accessible.setAttribute('aria-level', '2');
736
+ }
737
+ else if (node.type === 'Text')
738
+ accessible.removeAttribute('role');
739
+ if (props.validationMessage) {
740
+ accessible.setAttribute('aria-invalid', 'true');
741
+ accessible.setAttribute('aria-description', props.validationMessage);
742
+ }
743
+ else
744
+ accessible.removeAttribute('aria-invalid');
745
+ if (content && 'disabled' in content)
746
+ content.disabled = value.extra.disabled;
747
+ if (value.adapter) {
748
+ value.adapter.update(node.decoded);
749
+ return;
750
+ }
751
+ updateInput(value);
752
+ updateAdvanced(value, this.primitiveHost);
753
+ switch (node.type) {
754
+ case 'Text':
755
+ if (content.textContent !== props.text)
756
+ content.textContent = props.text;
757
+ content.style.whiteSpace = 'pre-wrap';
758
+ if (props.live)
759
+ content.setAttribute('aria-live', props.live);
760
+ if (props.maxLines) {
761
+ Object.assign(content.style, {
762
+ display: '-webkit-box',
763
+ webkitBoxOrient: 'vertical',
764
+ webkitLineClamp: String(props.maxLines),
765
+ overflow: 'hidden',
766
+ });
767
+ }
768
+ else
769
+ Object.assign(content.style, {
770
+ display: 'block',
771
+ webkitBoxOrient: '',
772
+ webkitLineClamp: '',
773
+ overflow: 'visible',
774
+ });
775
+ break;
776
+ case 'Button':
777
+ if (content.textContent !== props.title)
778
+ content.textContent = props.title;
779
+ break;
780
+ case 'Pressable':
781
+ content.setAttribute('role', props.role ?? 'button');
782
+ content.setAttribute('aria-disabled', String(value.extra.disabled));
783
+ content.tabIndex = value.extra.disabled ? -1 : 0;
784
+ if (props.selected !== undefined)
785
+ content.setAttribute('aria-selected', String(props.selected));
786
+ if (props.expanded !== undefined)
787
+ content.setAttribute('aria-expanded', String(props.expanded));
788
+ break;
789
+ case 'TextField':
790
+ case 'TextArea': {
791
+ const input = content;
792
+ if (!value.composing && input.value !== (props.value ?? '')) {
793
+ const start = input.selectionStart, end = input.selectionEnd, direction = input.selectionDirection;
794
+ input.value = props.value ?? '';
795
+ if (document.activeElement === input && start !== null && end !== null)
796
+ try {
797
+ input.setSelectionRange(Math.min(start, input.value.length), Math.min(end, input.value.length), direction ?? undefined);
798
+ }
799
+ catch { }
800
+ }
801
+ input.placeholder = props.placeholder ?? '';
802
+ input.setAttribute('autocomplete', { newPassword: 'new-password', oneTimeCode: 'one-time-code', none: 'off' }[props.contentType] ??
803
+ props.contentType ??
804
+ 'off');
805
+ input.inputMode =
806
+ { number: 'numeric', decimal: 'decimal', phone: 'tel', email: 'email' }[props.keyboard] ?? 'text';
807
+ if (node.type === 'TextField')
808
+ input.type = props.secure ? 'password' : 'text';
809
+ input.spellcheck = props.autocorrect !== false;
810
+ break;
811
+ }
812
+ case 'Toggle': {
813
+ const input = content;
814
+ input.checked = props.value ?? false;
815
+ input.setAttribute('role', 'switch');
816
+ break;
817
+ }
818
+ case 'Progress':
819
+ content.removeAttribute('value');
820
+ break;
821
+ case 'Image': {
822
+ const image = content;
823
+ image.alt = '';
824
+ image.setAttribute('aria-hidden', 'true');
825
+ element.setAttribute('role', 'img');
826
+ if (!props.label)
827
+ element.setAttribute('aria-hidden', 'true');
828
+ else {
829
+ element.removeAttribute('aria-hidden');
830
+ element.setAttribute('aria-label', props.label);
831
+ }
832
+ image.style.objectFit = props.fit === 'cover' ? 'cover' : 'contain';
833
+ value.extra.imageSource = new URL(props.source ?? '', this.options.imageBaseUrl ?? document.baseURI).href;
834
+ break;
835
+ }
836
+ case 'Icon':
837
+ this.icon(value);
838
+ break;
839
+ case 'Divider':
840
+ if (props.decorative === false) {
841
+ element.setAttribute('role', 'separator');
842
+ element.setAttribute('aria-orientation', props.orientation ?? 'horizontal');
843
+ element.removeAttribute('aria-hidden');
844
+ }
845
+ else {
846
+ element.removeAttribute('role');
847
+ element.setAttribute('aria-hidden', 'true');
848
+ }
849
+ element.style.backgroundColor = color(node, 'separator', this.dark);
850
+ break;
851
+ case 'Scroll':
852
+ content.style.overflowX = props.axis === 'horizontal' ? 'auto' : 'hidden';
853
+ content.style.overflowY = props.axis === 'horizontal' ? 'hidden' : 'auto';
854
+ // A carousel contains horizontal overscroll, while vertical wheels keep
855
+ // scrolling its enclosing page instead of getting trapped over tiles.
856
+ content.style.overscrollBehaviorX =
857
+ props.axis === 'horizontal' ? 'contain' : 'auto';
858
+ content.style.overscrollBehaviorY =
859
+ props.axis === 'horizontal' ? 'auto' : 'contain';
860
+ break;
861
+ }
862
+ }
863
+ icon(value) {
864
+ const svg = value.content, props = value.node.props;
865
+ svg.setAttribute('viewBox', (props.viewBox ?? [0, 0, 24, 24]).join(' '));
866
+ svg.setAttribute('aria-hidden', String(!props.label));
867
+ if (value.node.geometry) {
868
+ let path = svg.firstChild;
869
+ if (!path || path.nodeName !== 'path') {
870
+ svg.replaceChildren();
871
+ path = document.createElementNS(svg.namespaceURI, 'path');
872
+ svg.append(path);
873
+ }
874
+ path.setAttribute('d', value.node.geometry
875
+ .map((command) => `${command.kind}${command.values.join(' ')}`)
876
+ .join(' '));
877
+ path.setAttribute('fill', props.paint === 'fill' ? 'currentColor' : 'none');
878
+ path.setAttribute('stroke', props.paint === 'fill' ? 'none' : 'currentColor');
879
+ path.setAttribute('stroke-width', String(props.strokeWidth ?? 2));
880
+ path.setAttribute('stroke-linecap', props.lineCap ?? 'round');
881
+ path.setAttribute('stroke-linejoin', props.lineJoin ?? 'round');
882
+ path.setAttribute('fill-rule', props.fillRule ?? 'nonzero');
883
+ }
884
+ else {
885
+ let path = svg.firstChild;
886
+ if (!path || path.nodeName !== 'path') {
887
+ svg.replaceChildren();
888
+ path = document.createElementNS(svg.namespaceURI, 'path');
889
+ svg.append(path);
890
+ }
891
+ path.setAttribute('d', namedIcons[props.name] ?? '');
892
+ path.setAttribute('stroke', 'currentColor');
893
+ path.setAttribute('stroke-width', '2');
894
+ path.setAttribute('stroke-linecap', 'round');
895
+ path.setAttribute('stroke-linejoin', 'round');
896
+ path.setAttribute('fill', props.name === 'heart.fill' ? 'currentColor' : 'none');
897
+ }
898
+ }
899
+ syncImages() {
900
+ for (const value of this.mounted.values())
901
+ if (value.extra.image) {
902
+ const image = value.content, url = new URL(value.extra.imageSource);
903
+ const allowed = ['http:', 'https:'].includes(url.protocol) &&
904
+ (!this.options.imageAllowed || this.options.imageAllowed(url));
905
+ value.extra.image.update(value.extra.imageSource, allowed
906
+ ? (this.options.imageLoader ?? DefaultImageLoader.shared.load)
907
+ : deniedImageLoader, parseFloat(image.style.width) || 0, parseFloat(image.style.height) || 0, visible(value) && !document.hidden);
908
+ }
909
+ }
910
+ requestLayout(value) {
911
+ if (value) {
912
+ delete value.extra.insets;
913
+ for (let ancestor = value; ancestor; ancestor = ancestor.parent) {
914
+ ancestor.extra.geometryRevision = ++this.geometryRevision;
915
+ }
916
+ }
917
+ else
918
+ this.clearMeasurements();
919
+ if (!this.disposed && !this.frame)
920
+ this.frame = requestAnimationFrame(() => {
921
+ this.frame = 0;
922
+ this.layout();
923
+ });
924
+ }
925
+ clearMeasurements() {
926
+ this.sharedLayout?.invalidate();
927
+ for (const value of this.mounted.values())
928
+ delete value.extra.insets;
929
+ }
930
+ layout() {
931
+ if (!this.root || this.layingOut || this.disposed)
932
+ return;
933
+ this.layingOut = true;
934
+ try {
935
+ for (const value of this.mounted.values())
936
+ if (value.node.type === 'List' && !value.extra.listAnchor)
937
+ captureList(value);
938
+ const width = this.container.clientWidth;
939
+ const height = this.options.sizing === 'viewport' ? this.container.clientHeight : undefined;
940
+ this.containerSize = { width, height: this.container.clientHeight };
941
+ const size = this.sharedLayout.layout(this.root, width, height);
942
+ if (this.disposed || !this.root)
943
+ return;
944
+ this.element.style.width = `${width}px`;
945
+ this.element.style.height = `${height ?? size.height}px`;
946
+ this.root.element.style.left = '0px';
947
+ this.root.element.style.top = '0px';
948
+ for (const value of this.mounted.values()) {
949
+ if (value.node.type !== 'List')
950
+ continue;
951
+ // Correct content shifts, preserving native scroll movement during layout.
952
+ const delta = value.extra.listPendingDelta ?? 0;
953
+ if (Math.abs(delta) > 0.01)
954
+ value.content.scrollTop += delta;
955
+ delete value.extra.listPendingDelta;
956
+ delete value.extra.listAnchor;
957
+ }
958
+ for (const value of this.mounted.values())
959
+ if (value.node.type === 'Popup')
960
+ positionPresentation(value, this.primitiveHost);
961
+ this.syncImages();
962
+ for (const value of this.mounted.values())
963
+ value.adapter?.layout?.({
964
+ width: value.element.offsetWidth,
965
+ height: value.element.offsetHeight,
966
+ });
967
+ }
968
+ finally {
969
+ this.layingOut = false;
970
+ }
971
+ }
972
+ async command(id, name, payload, signal) {
973
+ const value = this.mounted.get(id);
974
+ if (!value || !visible(value) || !value.element.isConnected || value.extra.disabled)
975
+ fail('Ref is not attached, visible and enabled', 'missingRef');
976
+ if (value.adapter)
977
+ return this.options.session.componentCommand(id, name, value.adapter, payload, AbortSignal.any([signal, value.controller.signal]));
978
+ const content = value.content;
979
+ if (name === 'focus') {
980
+ content?.focus();
981
+ return {};
982
+ }
983
+ if (name === 'blur') {
984
+ content?.blur();
985
+ return {};
986
+ }
987
+ if (name === 'scrollTo' && value.node.type === 'Scroll') {
988
+ scrollCommand(value, payload);
989
+ return {};
990
+ }
991
+ fail('Command unavailable', 'missingRef');
992
+ }
993
+ destroy(value) {
994
+ if (value.controller.signal.aborted)
995
+ return;
996
+ value.controller.abort();
997
+ if (value.content) {
998
+ this.resize.unobserve(value.content);
999
+ this.adapterElements.delete(value.content);
1000
+ }
1001
+ value.adapter?.dispose();
1002
+ if (value.content instanceof HTMLImageElement)
1003
+ value.content.removeAttribute('src');
1004
+ value.element.remove();
1005
+ this.mounted.delete(value.node.id);
1006
+ }
1007
+ destroyBranch(value) {
1008
+ if (this.mounted.get(value.node.id) !== value)
1009
+ return;
1010
+ value.children.forEach((child) => this.destroyBranch(child));
1011
+ this.motion.forget(value.node.id);
1012
+ this.destroy(value);
1013
+ }
1014
+ detach() {
1015
+ const release = this.release;
1016
+ this.release = undefined;
1017
+ release?.();
1018
+ }
1019
+ dispose() {
1020
+ if (this.disposed)
1021
+ return;
1022
+ this.disposed = true;
1023
+ this.clearMeasurements();
1024
+ this.detach();
1025
+ this.controller.abort();
1026
+ this.resize.disconnect();
1027
+ cancelAnimationFrame(this.frame);
1028
+ for (const value of [...this.mounted.values()])
1029
+ this.destroy(value);
1030
+ this.root = undefined;
1031
+ for (const host of this.hosts.values())
1032
+ host.dispose();
1033
+ this.hosts.clear();
1034
+ this.motion.dispose();
1035
+ this.sharedLayout?.dispose();
1036
+ this.mounts.dispose();
1037
+ cancelAnimationFrame(this.refreshFrame);
1038
+ this.styleElement.remove();
1039
+ this.element.remove();
1040
+ }
1041
+ }