@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,817 @@
1
+ import { getEngine } from '../core/engine.js';
2
+ import { chromeShadow, color } from './style.js';
3
+ import { motionPlan, usesPaintedBorder, } from './motion-plan.js';
4
+ import { TextMotion } from './text-motion.js';
5
+ import { paintRange, paintScrollbar } from './range.js';
6
+ import { transition } from './motion-lifecycle.js';
7
+ function lifecycleSize(plan) {
8
+ return (plan.enter_target.width !== null ||
9
+ plan.enter_target.height !== null ||
10
+ plan.exit_target.width !== null ||
11
+ plan.exit_target.height !== null);
12
+ }
13
+ function sized(entry) {
14
+ return !!(entry.plan.mask & 64) || lifecycleSize(entry.plan);
15
+ }
16
+ const STRIDE = 32, CAPACITY = 1024;
17
+ function shown(node) {
18
+ return node.node.shown && (node.node.type !== 'Popup' || node.node.props.value === true);
19
+ }
20
+ function resolvedRadius(radius, width, height) {
21
+ return Math.max(0, Math.min(radius, width / 2, height / 2));
22
+ }
23
+ function presentation(node) {
24
+ return node.node.type === 'Popup' ? node.content : node.element;
25
+ }
26
+ function rgba(text) {
27
+ const numbers = text.match(/[\d.]+/g)?.map(Number) ?? [0, 0, 0, 0];
28
+ return [numbers[0] / 255, numbers[1] / 255, numbers[2] / 255, numbers[3] ?? 1];
29
+ }
30
+ const displayColors = new Map();
31
+ const linearColors = new Map();
32
+ function cssColor(values) {
33
+ const key = values.join(',');
34
+ const cached = displayColors.get(key);
35
+ if (cached)
36
+ return cached;
37
+ const c = getEngine().motion_display_color(new Float64Array(values));
38
+ const result = `rgba(${Math.round(c[0] * 255)},${Math.round(c[1] * 255)},${Math.round(c[2] * 255)},${c[3]})`;
39
+ if (displayColors.size >= 128)
40
+ displayColors.delete(displayColors.keys().next().value);
41
+ displayColors.set(key, result);
42
+ return result;
43
+ }
44
+ function linear(text) {
45
+ let result = linearColors.get(text);
46
+ if (!result) {
47
+ result = Array.from(getEngine().motion_linear_color(new Float64Array(rgba(text))));
48
+ if (linearColors.size >= 128)
49
+ linearColors.delete(linearColors.keys().next().value);
50
+ linearColors.set(text, result);
51
+ }
52
+ return result;
53
+ }
54
+ export class MotionCoordinator {
55
+ onFrame;
56
+ text = new TextMotion();
57
+ captureText(nodes, policy, epoch) {
58
+ return epoch === this.epoch && policy === 'system' && !this.media.matches
59
+ ? this.text.before(nodes)
60
+ : undefined;
61
+ }
62
+ finishText(captures, nodes, policy) {
63
+ if (policy !== 'system' || this.media.matches)
64
+ this.text.clear();
65
+ else if (captures)
66
+ this.text.after(captures, nodes, this.now());
67
+ }
68
+ rows = new Float64Array(CAPACITY * STRIDE);
69
+ used = new Set();
70
+ firstFree = 0;
71
+ high = 0;
72
+ frame = 0;
73
+ disposed = false;
74
+ entries = new Map();
75
+ media = matchMedia('(prefers-reduced-motion: reduce)');
76
+ epoch = -1;
77
+ ghostCount = 0;
78
+ time = performance.now() / 1000;
79
+ real = this.time;
80
+ paused = document.hidden;
81
+ controller = new AbortController();
82
+ constructor(onFrame, refresh) {
83
+ this.onFrame = onFrame;
84
+ this.media.addEventListener('change', refresh, { signal: this.controller.signal });
85
+ }
86
+ now() {
87
+ const real = performance.now() / 1000;
88
+ if (!this.paused)
89
+ this.time += real - this.real;
90
+ this.real = real;
91
+ return this.time;
92
+ }
93
+ setVisible(visible) {
94
+ this.now();
95
+ this.paused = !visible;
96
+ if (!visible) {
97
+ cancelAnimationFrame(this.frame);
98
+ this.frame = 0;
99
+ }
100
+ else
101
+ this.wake();
102
+ }
103
+ begin(epoch) {
104
+ if (epoch !== this.epoch) {
105
+ this.clear();
106
+ this.epoch = epoch;
107
+ }
108
+ getEngine().motion_sample(this.rows.subarray(0, this.high * STRIDE), this.now());
109
+ for (const entry of this.entries.values())
110
+ if (!entry.ghost) {
111
+ if (!entry.exiting &&
112
+ entry.rows.every((index) => index < 0 || this.rows[index * STRIDE + 17] === 0) &&
113
+ entry.target[1] === 0 &&
114
+ entry.target[2] === 0 &&
115
+ entry.target[3] === 1 &&
116
+ entry.target[4] === 1 &&
117
+ entry.target[5] === 0)
118
+ continue;
119
+ entry.painted = undefined;
120
+ this.paint(entry, entry.target);
121
+ entry.element.style.transform = 'none';
122
+ entry.painted = undefined;
123
+ }
124
+ }
125
+ allocate(value, channel) {
126
+ // Preserve first-fit reuse without rescanning the occupied prefix. A full
127
+ // pool must fail immediately when many new presentations request channels.
128
+ if (this.firstFree === CAPACITY)
129
+ return -1;
130
+ const index = this.firstFree;
131
+ this.used.add(index);
132
+ while (this.firstFree < CAPACITY && this.used.has(this.firstFree))
133
+ this.firstFree++;
134
+ this.high = Math.max(this.high, index + 1);
135
+ const row = this.rows.subarray(index * STRIDE, (index + 1) * STRIDE);
136
+ row.fill(0);
137
+ row[0] = row[2] = row[3] = value;
138
+ row[13] = channel === 0 || (channel >= 6 && channel <= 17) ? 0.001 : 0.1;
139
+ row[14] = 0.01;
140
+ row[15] = channel === 0 || (channel >= 6 && channel <= 17) ? 0 : -1e9;
141
+ row[16] = channel === 0 || (channel >= 6 && channel <= 17) ? 1 : 1e9;
142
+ return index;
143
+ }
144
+ configure(index, target, settings, animated) {
145
+ const row = this.rows.subarray(index * STRIDE, (index + 1) * STRIDE);
146
+ row[6] = settings.mass;
147
+ row[7] = settings.stiffness;
148
+ row[8] = settings.damping;
149
+ row[9] = settings.engine;
150
+ row[10] = settings.duration;
151
+ row[11] = settings.ease;
152
+ row[21] = settings.delay;
153
+ getEngine().motion_retarget(row, target, this.now(), animated);
154
+ }
155
+ beforeUpdate(node, nextShown, dark) {
156
+ const entry = this.entries.get(node.node.id);
157
+ if (!entry || !shown(node) || nextShown || entry.plan.disabled)
158
+ return;
159
+ const target = this.endpoint(entry, entry.plan.exit_target, dark);
160
+ if (entry.plan.mask & 64)
161
+ target[22] = 0;
162
+ if (!entry.plan.exit.length && !(entry.plan.mask & 64))
163
+ return;
164
+ const decision = transition(entry.plan, {
165
+ initialized: true,
166
+ shown: true,
167
+ phaseActive: entry.phaseActive,
168
+ requested: false,
169
+ running: this.running(entry),
170
+ visible: true,
171
+ });
172
+ entry.phaseActive = decision.phaseActive;
173
+ entry.exiting = true;
174
+ entry.settledHidden = false;
175
+ entry.collapsing =
176
+ !!(entry.plan.mask & 64) ||
177
+ entry.plan.exit_target.width !== null ||
178
+ entry.plan.exit_target.height !== null;
179
+ const values = this.values(entry);
180
+ entry.target = target;
181
+ target.forEach((next, index) => {
182
+ if (!decision.selects(index) || (next === values[index] && entry.rows[index] < 0))
183
+ return;
184
+ if (entry.rows[index] < 0)
185
+ entry.rows[index] = this.allocate(values[index], index);
186
+ if (entry.rows[index] >= 0)
187
+ this.configure(entry.rows[index], next, decision.settings, decision.animates(index));
188
+ });
189
+ }
190
+ running(entry) {
191
+ return entry.rows.some((index) => index >= 0 && this.rows[index * STRIDE + 17] !== 0);
192
+ }
193
+ isRetaining(id) {
194
+ const entry = this.entries.get(id);
195
+ return !!(entry?.exiting &&
196
+ entry.rows.some((index) => index >= 0 && this.rows[index * STRIDE + 17] !== 0));
197
+ }
198
+ isCollapsing(id) {
199
+ return !!(this.entries.get(id)?.collapsing && this.isRetaining(id));
200
+ }
201
+ /** Retained visual exits keep their last frames after logical layout removes them. */
202
+ preservesLayout(node) {
203
+ for (let current = node; current; current = current.parent)
204
+ if (this.isRetaining(current.node.id) && !this.isCollapsing(current.node.id))
205
+ return true;
206
+ return false;
207
+ }
208
+ finishHidden(entry) {
209
+ if (!entry.exiting || entry.settledHidden || this.isRetaining(entry.id))
210
+ return;
211
+ entry.settledHidden = true;
212
+ entry.element.hidden = true;
213
+ entry.node.extra.onPresentationHidden?.();
214
+ }
215
+ get layoutActive() {
216
+ return [...this.entries.values()].some((entry) => !entry.ghost &&
217
+ // Only live geometry channels need layout. A color or range-value spring
218
+ // on a size-enabled control must not invalidate the whole surface.
219
+ entry.rows.some((index, channel) => channel >= 21 && channel <= 28 && index >= 0 && this.rows[index * STRIDE + 17] !== 0));
220
+ }
221
+ values(entry) {
222
+ return entry.target.map((target, index) => entry.rows[index] >= 0 ? this.rows[entry.rows[index] * STRIDE] : target);
223
+ }
224
+ targets(node, plan, dark) {
225
+ const element = presentation(node), css = getComputedStyle(element), transform = [...plan.transform], width = node.extra.targetGeometry?.width ?? element.offsetWidth, height = node.extra.targetGeometry?.height ?? element.offsetHeight;
226
+ for (let index = 0; index < 2; index++)
227
+ if (plan.full[index])
228
+ transform[index] *= index === 0 ? element.offsetWidth : element.offsetHeight;
229
+ if (plan.logical_x && css.direction === 'rtl')
230
+ transform[0] *= -1;
231
+ const value = node.node.props.value;
232
+ const values = Array.isArray(value) ? value : [value];
233
+ return [
234
+ Number(css.opacity),
235
+ ...transform,
236
+ ...linear(css.backgroundColor),
237
+ ...linear(css.color),
238
+ ...linear(css.borderColor),
239
+ resolvedRadius(parseFloat(element.style.getPropertyValue('--relo-radius-target') || css.borderRadius) || 0, width, height),
240
+ parseFloat(element.style.getPropertyValue('--relo-border-target') || css.borderWidth) || 0,
241
+ Number(element.style.getPropertyValue('--relo-shadow-target') ||
242
+ (css.boxShadow === 'none' ? 0 : 1)),
243
+ width,
244
+ height,
245
+ parseFloat(css.paddingTop),
246
+ parseFloat(css.paddingRight),
247
+ parseFloat(css.paddingBottom),
248
+ parseFloat(css.paddingLeft),
249
+ node.style.gapX,
250
+ node.style.gapY,
251
+ 0,
252
+ 0,
253
+ typeof values[0] === 'number' ? values[0] : 0,
254
+ typeof values[1] === 'number' ? values[1] : 0,
255
+ ];
256
+ }
257
+ endpoint(entry, endpoint, dark) {
258
+ const result = [...entry.target], element = entry.element;
259
+ endpoint.transform.forEach((value, index) => {
260
+ if (value !== null)
261
+ result[index + 1] =
262
+ value *
263
+ (index < 2 && endpoint.full[index]
264
+ ? index === 0
265
+ ? element.offsetWidth
266
+ : element.offsetHeight
267
+ : 1);
268
+ });
269
+ if (endpoint.logical_x &&
270
+ endpoint.transform[0] !== null &&
271
+ entry.node.extra.direction === 'rtl')
272
+ result[1] *= -1;
273
+ if (endpoint.opacity !== null)
274
+ result[0] = endpoint.opacity;
275
+ for (const [field, start] of [
276
+ ['background', 6],
277
+ ['foreground', 10],
278
+ ['border', 14],
279
+ ]) {
280
+ const name = endpoint[field];
281
+ if (name) {
282
+ const probe = document.createElement('span');
283
+ probe.style.color = color(entry.node.extra.paintNode ?? entry.node.node, name, dark);
284
+ element.append(probe);
285
+ const channels = linear(getComputedStyle(probe).color);
286
+ probe.remove();
287
+ result.splice(start, 4, ...channels);
288
+ }
289
+ }
290
+ if (endpoint.radius)
291
+ result[18] =
292
+ (entry.node.extra.paintNode ?? entry.node.node).theme.radii[endpoint.radius] ??
293
+ { none: 0, sm: 4, md: 6, lg: 8, xl: 12, '2xl': 16, full: 9999 }[endpoint.radius] ??
294
+ 0;
295
+ if (endpoint.border_width !== null)
296
+ result[19] = endpoint.border_width;
297
+ if (endpoint.shadow !== null)
298
+ result[20] = endpoint.shadow;
299
+ if (endpoint.width !== null)
300
+ result[21] = endpoint.width;
301
+ if (endpoint.height !== null)
302
+ result[22] = endpoint.height;
303
+ result[18] = resolvedRadius(result[18], result[21], result[22]);
304
+ return result;
305
+ }
306
+ commit(nodes, policy, dark) {
307
+ const ids = new Set();
308
+ const updates = [];
309
+ let loops = 0;
310
+ if (policy !== 'system' || this.media.matches) {
311
+ for (const [id, entry] of this.entries)
312
+ if (entry.ghost) {
313
+ this.release(entry);
314
+ this.entries.delete(id);
315
+ this.ghostCount--;
316
+ }
317
+ }
318
+ for (const node of nodes) {
319
+ if (node.extra.materialized === false)
320
+ continue;
321
+ ids.add(node.node.id);
322
+ const existing = this.entries.get(node.node.id);
323
+ // Style resolution may have overwritten sampled chrome even if the new
324
+ // numeric targets are unchanged (for example, inherited visibility).
325
+ if (existing && node.extra.paintDirty)
326
+ existing.painted = undefined;
327
+ const geometryUnchanged = existing &&
328
+ existing.geometry === node.extra.layoutGeometry &&
329
+ (parseFloat(node.element.style.left) || 0) === existing.left &&
330
+ (parseFloat(node.element.style.top) || 0) === existing.top;
331
+ if (!node.extra.paintDirty &&
332
+ existing?.node === node &&
333
+ !existing.exiting &&
334
+ geometryUnchanged &&
335
+ existing.rows.every((index) => index < 0 || this.rows[index * STRIDE + 17] === 0) &&
336
+ !existing.plan.looping &&
337
+ existing.target[1] === 0 &&
338
+ existing.target[2] === 0 &&
339
+ existing.target[3] === 1 &&
340
+ existing.target[4] === 1 &&
341
+ existing.target[5] === 0)
342
+ continue;
343
+ const states = (node.extra.selected ||
344
+ node.node.props.selected ||
345
+ (node.node.type === 'Checkable' && node.node.props.value === true)
346
+ ? 1
347
+ : 0) |
348
+ (node.node.props.expanded ? 2 : 0) |
349
+ (node.pressed ? 4 : 0) |
350
+ (node.focused ? 8 : 0) |
351
+ (node.node.props.validationMessage ? 16 : 0) |
352
+ (node.extra.disabled ? 32 : 0);
353
+ const reduced = policy !== 'system' || node.node.theme.motion !== 'system' || this.media.matches;
354
+ const classes = node.extra.expanded ?? node.node.classes;
355
+ const plan = { ...motionPlan(classes, states, reduced) };
356
+ if (reduced)
357
+ plan.disabled = true;
358
+ updates.push({
359
+ node,
360
+ plan,
361
+ target: shown(node) || (!existing && plan.mask & 64) ? this.targets(node, plan, dark) : undefined,
362
+ });
363
+ node.extra.paintDirty = false;
364
+ }
365
+ // Read presentation targets together. Interleaving computed-style/geometry
366
+ // reads with paint writes forced a browser layout for each changed node.
367
+ for (const { node, plan, target } of updates) {
368
+ let entry = this.entries.get(node.node.id);
369
+ if (entry)
370
+ entry.geometry = node.extra.layoutGeometry;
371
+ if (!shown(node)) {
372
+ if (entry) {
373
+ entry.node = node;
374
+ entry.plan = plan;
375
+ if (plan.disabled) {
376
+ for (const row of entry.rows)
377
+ if (row >= 0)
378
+ this.configure(row, this.rows[row * STRIDE + 2], plan.settings, false);
379
+ }
380
+ entry.element.hidden = !this.isRetaining(entry.id);
381
+ this.paint(entry, this.values(entry));
382
+ this.finishHidden(entry);
383
+ }
384
+ else if (plan.mask & 64) {
385
+ target[21] = node.parent?.element.offsetWidth ?? target[21];
386
+ target[22] = 0;
387
+ entry = {
388
+ id: node.node.id,
389
+ element: presentation(node),
390
+ node,
391
+ plan,
392
+ geometry: node.extra.layoutGeometry,
393
+ target: target,
394
+ rows: Array(33).fill(-1),
395
+ left: 0,
396
+ top: 0,
397
+ exiting: true,
398
+ collapsing: true,
399
+ };
400
+ this.entries.set(entry.id, entry);
401
+ }
402
+ continue;
403
+ }
404
+ if (!entry) {
405
+ entry = {
406
+ id: node.node.id,
407
+ element: presentation(node),
408
+ node,
409
+ plan,
410
+ geometry: node.extra.layoutGeometry,
411
+ target: target,
412
+ rows: Array(33).fill(-1),
413
+ left: parseFloat(node.element.style.left) || 0,
414
+ top: parseFloat(node.element.style.top) || 0,
415
+ };
416
+ this.entries.set(entry.id, entry);
417
+ const decision = transition(plan, {
418
+ initialized: false,
419
+ shown: true,
420
+ requested: true,
421
+ running: false,
422
+ visible: true,
423
+ });
424
+ entry.phaseActive = decision.phaseActive;
425
+ const seed = decision.seedEnter
426
+ ? this.endpoint(entry, plan.enter_target, dark)
427
+ : entry.target;
428
+ entry.target.forEach((target, index) => {
429
+ if (decision.selects(index)) {
430
+ const row = this.allocate(seed[index], index);
431
+ entry.rows[index] = row;
432
+ if (row >= 0)
433
+ this.configure(row, target, decision.settings, decision.animates(index));
434
+ }
435
+ });
436
+ }
437
+ else {
438
+ const targets = target, left = parseFloat(node.element.style.left) || 0, top = parseFloat(node.element.style.top) || 0;
439
+ entry.node = node;
440
+ entry.element = presentation(node);
441
+ const decision = transition(plan, {
442
+ initialized: true,
443
+ shown: !entry.exiting,
444
+ phaseActive: entry.phaseActive,
445
+ requested: true,
446
+ running: this.running(entry),
447
+ visible: true,
448
+ });
449
+ entry.phaseActive = decision.phaseActive;
450
+ if (decision.resetVelocity) {
451
+ const seed = this.endpoint(entry, plan.enter_target, dark);
452
+ seed.forEach((value, index) => {
453
+ const row = entry.rows[index];
454
+ if (row >= 0) {
455
+ this.rows[row * STRIDE] =
456
+ this.rows[row * STRIDE + 2] =
457
+ this.rows[row * STRIDE + 3] =
458
+ value;
459
+ this.rows[row * STRIDE + 1] =
460
+ this.rows[row * STRIDE + 4] =
461
+ this.rows[row * STRIDE + 17] =
462
+ 0;
463
+ }
464
+ });
465
+ }
466
+ entry.exiting = false;
467
+ entry.settledHidden = false;
468
+ entry.element.hidden = false;
469
+ entry.plan = plan;
470
+ entry.collapsing = false;
471
+ if (plan.layout && !plan.disabled) {
472
+ for (const [index, delta] of [
473
+ [29, entry.left - left],
474
+ [30, entry.top - top],
475
+ ])
476
+ if (delta) {
477
+ if (entry.rows[index] < 0)
478
+ entry.rows[index] = this.allocate(0, index);
479
+ const indexRow = entry.rows[index];
480
+ if (indexRow >= 0) {
481
+ const row = this.rows.subarray(indexRow * STRIDE, (indexRow + 1) * STRIDE), s = plan.settings;
482
+ row[6] = s.mass;
483
+ row[7] = s.stiffness;
484
+ row[8] = s.damping;
485
+ row[9] = s.engine;
486
+ row[10] = s.duration;
487
+ row[11] = s.ease;
488
+ row[21] = s.delay;
489
+ getEngine().motion_rebase(row, delta, this.now(), true);
490
+ }
491
+ }
492
+ }
493
+ entry.left = left;
494
+ entry.top = top;
495
+ targets.forEach((target, index) => {
496
+ const selected = decision.animates(index) &&
497
+ !(index >= 31 && index <= 32 && node.extra.directManipulation);
498
+ if (entry.rows[index] < 0 && selected && target !== entry.target[index])
499
+ entry.rows[index] = this.allocate(entry.target[index], index);
500
+ const row = entry.rows[index];
501
+ const loopChannel = plan.looping === 1 ? 5 : 0;
502
+ if (plan.looping &&
503
+ !plan.disabled &&
504
+ index === loopChannel &&
505
+ row >= 0 &&
506
+ this.rows[row * STRIDE + 9] === plan.looping + 1)
507
+ return;
508
+ if (row >= 0 && index !== 29 && index !== 30)
509
+ this.configure(row, target, decision.settings, selected);
510
+ });
511
+ entry.target = targets;
512
+ }
513
+ const rect = plan.looping ? node.element.getBoundingClientRect() : undefined;
514
+ if (plan.looping &&
515
+ !plan.disabled &&
516
+ loops < 64 &&
517
+ rect.bottom > 0 &&
518
+ rect.top < innerHeight &&
519
+ rect.right > 0 &&
520
+ rect.left < innerWidth) {
521
+ loops++;
522
+ const index = plan.looping === 1 ? 5 : 0;
523
+ if (entry.rows[index] < 0)
524
+ entry.rows[index] = this.allocate(entry.target[index], index);
525
+ const rowIndex = entry.rows[index];
526
+ if (rowIndex >= 0) {
527
+ const row = this.rows.subarray(rowIndex * STRIDE, (rowIndex + 1) * STRIDE);
528
+ if (row[9] !== plan.looping + 1) {
529
+ row[9] = plan.looping + 1;
530
+ row[5] = this.now();
531
+ }
532
+ row[17] = 1;
533
+ }
534
+ }
535
+ else if (plan.looping) {
536
+ const rowIndex = entry.rows[plan.looping === 1 ? 5 : 0];
537
+ if (rowIndex >= 0)
538
+ this.rows[rowIndex * STRIDE + 17] = 0;
539
+ }
540
+ this.paint(entry, this.values(entry));
541
+ }
542
+ for (const [id, entry] of this.entries)
543
+ if (!entry.ghost && !ids.has(id)) {
544
+ this.release(entry);
545
+ this.entries.delete(id);
546
+ }
547
+ this.wake();
548
+ }
549
+ depart(entry, dark) {
550
+ if (!entry.plan.exit.length || entry.plan.disabled || this.ghostCount >= 64) {
551
+ this.release(entry);
552
+ return;
553
+ }
554
+ this.paint(entry, this.values(entry));
555
+ const rect = entry.element.getBoundingClientRect(), pixels = rect.width * rect.height;
556
+ if ([...this.entries.values()]
557
+ .filter((value) => value.ghost)
558
+ .reduce((sum, value) => sum + (value.pixels ?? 0), pixels) > 4_000_000) {
559
+ this.release(entry);
560
+ return;
561
+ }
562
+ const css = getComputedStyle(entry.element);
563
+ const matrix = new DOMMatrixReadOnly(css.transform);
564
+ const [ox, oy] = css.transformOrigin.split(' ').map(parseFloat);
565
+ const width = entry.element.offsetWidth, height = entry.element.offsetHeight;
566
+ const corners = [
567
+ [0, 0],
568
+ [width, 0],
569
+ [0, height],
570
+ [width, height],
571
+ ].map(([x, y]) => ({
572
+ x: matrix.a * (x - ox) + matrix.c * (y - oy) + ox + matrix.e,
573
+ y: matrix.b * (x - ox) + matrix.d * (y - oy) + oy + matrix.f,
574
+ }));
575
+ const clone = entry.element.cloneNode(true);
576
+ clone.inert = true;
577
+ clone.setAttribute('aria-hidden', 'true');
578
+ clone.removeAttribute('id');
579
+ clone.dataset.reloExit = '';
580
+ clone.querySelectorAll('[id]').forEach((node) => node.removeAttribute('id'));
581
+ Object.assign(clone.style, {
582
+ position: 'fixed',
583
+ left: `${rect.left - Math.min(...corners.map((point) => point.x))}px`,
584
+ top: `${rect.top - Math.min(...corners.map((point) => point.y))}px`,
585
+ width: `${width}px`,
586
+ height: `${height}px`,
587
+ pointerEvents: 'none',
588
+ margin: '0',
589
+ });
590
+ entry.element.parentElement?.closest('.relo-surface')?.append(clone);
591
+ entry.ghost = true;
592
+ entry.pixels = pixels;
593
+ entry.element = clone;
594
+ entry.id = `ghost-${++this.ghostCount}-${performance.now()}`;
595
+ this.entries.set(entry.id, entry);
596
+ const target = this.endpoint(entry, entry.plan.exit_target, dark), start = this.values(entry);
597
+ entry.target = target;
598
+ target.forEach((value, index) => {
599
+ if (start[index] !== value) {
600
+ if (entry.rows[index] < 0)
601
+ entry.rows[index] = this.allocate(start[index], index);
602
+ if (entry.rows[index] >= 0)
603
+ this.configure(entry.rows[index], value, entry.plan.exit_settings, true);
604
+ }
605
+ });
606
+ }
607
+ remove(id, dark) {
608
+ const entry = this.entries.get(id);
609
+ if (entry) {
610
+ this.entries.delete(id);
611
+ this.depart(entry, dark);
612
+ }
613
+ }
614
+ /** Physical virtualization ends a presentation, never logical presence. */
615
+ forget(id) {
616
+ const entry = this.entries.get(id);
617
+ if (entry) {
618
+ this.release(entry);
619
+ this.entries.delete(id);
620
+ }
621
+ }
622
+ paint(entry, values) {
623
+ if (entry.painted?.every((value, index) => value === values[index]))
624
+ return;
625
+ entry.painted = values;
626
+ const s = entry.element.style;
627
+ s.opacity = String(values[0]);
628
+ s.transformOrigin = `${entry.plan.origin[0] * 100}% ${entry.plan.origin[1] * 100}%`;
629
+ s.transform =
630
+ values[1] ||
631
+ values[2] ||
632
+ values[29] ||
633
+ values[30] ||
634
+ values[3] !== 1 ||
635
+ values[4] !== 1 ||
636
+ values[5]
637
+ ? `translate(${values[1] + values[29]}px,${values[2] + values[30]}px) scale(${values[3]},${values[4]}) rotate(${values[5]}deg)`
638
+ : 'none';
639
+ s.backgroundColor = cssColor(values.slice(6, 10));
640
+ s.color = cssColor(values.slice(10, 14));
641
+ s.borderColor = cssColor(values.slice(14, 18));
642
+ s.borderRadius = `${resolvedRadius(values[18], values[21], values[22])}px`;
643
+ const paintedBorder = usesPaintedBorder(entry.plan);
644
+ s.borderWidth = `${paintedBorder ? 0 : Math.max(0, values[19])}px`;
645
+ s.boxShadow = chromeShadow(paintedBorder ? Math.max(0, values[19]) : 0, s.borderColor, values[20]);
646
+ if (sized(entry)) {
647
+ s.width = `${Math.max(0, values[21])}px`;
648
+ s.height = `${Math.max(0, values[22])}px`;
649
+ }
650
+ if (entry.plan.mask & 128) {
651
+ s.paddingTop = `${values[23]}px`;
652
+ s.paddingRight = `${values[24]}px`;
653
+ s.paddingBottom = `${values[25]}px`;
654
+ s.paddingLeft = `${values[26]}px`;
655
+ }
656
+ if (entry.plan.mask & 256) {
657
+ const props = entry.node.node.props;
658
+ if (entry.node.node.type === 'Range') {
659
+ paintRange(entry.node, Array.isArray(props.value) ? values.slice(31, 33) : [values[31]]);
660
+ entry.node.content?.querySelectorAll('input').forEach((input, index) => {
661
+ input.setAttribute('aria-valuenow', String(Array.isArray(props.value) ? props.value[index] : props.value));
662
+ });
663
+ }
664
+ else if (entry.node.node.type === 'Scrollbar') {
665
+ paintScrollbar(entry.node, values[31]);
666
+ }
667
+ else if (entry.node.node.type === 'Meter' &&
668
+ props.value !== null &&
669
+ props.value !== undefined) {
670
+ entry.node.content.value = values[31] - (props.min ?? 0);
671
+ entry.node.content.setAttribute('aria-valuenow', String(props.value));
672
+ }
673
+ }
674
+ }
675
+ overrides(id) {
676
+ const entry = this.entries.get(id);
677
+ if (!entry)
678
+ return {};
679
+ const v = this.values(entry);
680
+ return {
681
+ ...(sized(entry)
682
+ ? { width: { fixed: Math.max(0, v[21]) }, height: { fixed: Math.max(0, v[22]) } }
683
+ : {}),
684
+ ...(entry.plan.mask & 128 ? { gapX: v[27], gapY: v[28] } : {}),
685
+ };
686
+ }
687
+ /** A layout pass may change an intrinsic target without a document update. */
688
+ layoutTarget(id, size) {
689
+ const entry = this.entries.get(id);
690
+ if (!entry || entry.exiting)
691
+ return;
692
+ if (!sized(entry)) {
693
+ if (entry.target[21] === size.width && entry.target[22] === size.height)
694
+ return;
695
+ entry.target[21] = size.width;
696
+ entry.target[22] = size.height;
697
+ // Host resize is geometry, not a fresh authored transition. Update
698
+ // measured targets immediately so subsequent reversals start in bounds.
699
+ for (let axis = 0; axis < 2; axis++) {
700
+ if (!entry.plan.full[axis])
701
+ continue;
702
+ const value = entry.plan.transform[axis] *
703
+ (axis ? size.height : size.width) *
704
+ (!axis && entry.plan.logical_x && entry.node.extra.direction === 'rtl' ? -1 : 1);
705
+ entry.target[axis + 1] = value;
706
+ const row = entry.rows[axis + 1];
707
+ if (row >= 0)
708
+ this.configure(row, value, entry.plan.settings, false);
709
+ }
710
+ const rawRadius = parseFloat(entry.element.style.getPropertyValue('--relo-radius-target'));
711
+ if (Number.isFinite(rawRadius)) {
712
+ const radius = resolvedRadius(rawRadius, size.width, size.height);
713
+ if (radius !== entry.target[18]) {
714
+ entry.target[18] = radius;
715
+ if (entry.rows[18] >= 0)
716
+ this.configure(entry.rows[18], radius, entry.plan.settings, false);
717
+ }
718
+ }
719
+ entry.painted = undefined;
720
+ this.paint(entry, this.values(entry));
721
+ return;
722
+ }
723
+ for (const [index, target] of [
724
+ [21, size.width],
725
+ [22, size.height],
726
+ ]) {
727
+ if (entry.target[index] === target)
728
+ continue;
729
+ entry.target[index] = target;
730
+ const row = entry.rows[index];
731
+ if (row >= 0)
732
+ this.configure(row, target, entry.plan.settings, !entry.plan.disabled);
733
+ }
734
+ }
735
+ /** Only active geometry channels override the immutable authored layout. */
736
+ layoutOverrides(id) {
737
+ const entry = this.entries.get(id);
738
+ if (!entry ||
739
+ entry.ghost ||
740
+ !entry.rows.some((row, channel) => channel >= 21 && channel <= 28 && row >= 0 && this.rows[row * STRIDE + 17] !== 0))
741
+ return;
742
+ const values = this.values(entry);
743
+ return {
744
+ ...(sized(entry) ? { width: Math.max(0, values[21]), height: Math.max(0, values[22]) } : {}),
745
+ ...(entry.plan.mask & 128
746
+ ? { padding: values.slice(23, 27), gapX: values[27], gapY: values[28] }
747
+ : {}),
748
+ ...(!entry.node.node.shown ? { shown: true } : {}),
749
+ };
750
+ }
751
+ paintAll() {
752
+ for (const entry of this.entries.values())
753
+ this.paint(entry, this.values(entry));
754
+ }
755
+ wake() {
756
+ if (this.disposed ||
757
+ this.paused ||
758
+ this.frame ||
759
+ (!this.text.active && ![...this.used].some((index) => this.rows[index * STRIDE + 17] !== 0)))
760
+ return;
761
+ this.frame = requestAnimationFrame(() => {
762
+ this.frame = 0;
763
+ const layout = this.layoutActive;
764
+ // Capture activity before sampling: a row can settle in this sample and
765
+ // still needs its final value painted. Static siblings need no frame work.
766
+ const moving = [...this.entries.values()].filter((entry) => entry.rows.some((index) => index >= 0 && this.rows[index * STRIDE + 17] !== 0));
767
+ getEngine().motion_sample(this.rows.subarray(0, this.high * STRIDE), this.now());
768
+ if (layout)
769
+ this.onFrame();
770
+ for (const entry of moving)
771
+ this.paint(entry, this.values(entry));
772
+ this.text.sample(this.now(), this.layoutActive);
773
+ for (const [id, entry] of this.entries) {
774
+ this.finishHidden(entry);
775
+ if (!this.running(entry))
776
+ entry.phaseActive = false;
777
+ if (entry.ghost &&
778
+ entry.rows.every((index) => index < 0 || this.rows[index * STRIDE + 17] === 0)) {
779
+ entry.element.remove();
780
+ this.release(entry);
781
+ this.entries.delete(id);
782
+ this.ghostCount--;
783
+ }
784
+ }
785
+ this.wake();
786
+ });
787
+ }
788
+ release(entry) {
789
+ for (const index of entry.rows)
790
+ if (index >= 0) {
791
+ this.rows[index * STRIDE + 17] = 0;
792
+ this.used.delete(index);
793
+ this.firstFree = Math.min(this.firstFree, index);
794
+ }
795
+ if (entry.ghost)
796
+ entry.element.remove();
797
+ while (this.high && !this.used.has(this.high - 1))
798
+ this.high--;
799
+ }
800
+ clear() {
801
+ this.text.clear();
802
+ cancelAnimationFrame(this.frame);
803
+ this.frame = 0;
804
+ for (const entry of this.entries.values())
805
+ this.release(entry);
806
+ this.entries.clear();
807
+ this.used.clear();
808
+ this.firstFree = 0;
809
+ this.high = 0;
810
+ this.ghostCount = 0;
811
+ }
812
+ dispose() {
813
+ this.clear();
814
+ this.controller.abort();
815
+ this.disposed = true;
816
+ }
817
+ }