@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.
- package/README.md +27 -2
- package/dist/LICENSE +202 -0
- package/dist/NOTICE +5 -0
- package/dist/core/contracts.d.ts +72 -0
- package/dist/core/contracts.js +76 -0
- package/dist/core/document.d.ts +16 -0
- package/dist/core/document.js +21 -0
- package/dist/core/engine.d.ts +8 -0
- package/dist/core/engine.js +28 -0
- package/dist/core/index.d.ts +7 -0
- package/dist/core/index.js +7 -0
- package/dist/core/runtime.d.ts +23 -0
- package/dist/core/runtime.js +46 -0
- package/dist/core/schema.d.ts +56 -0
- package/dist/core/schema.js +72 -0
- package/dist/core/session.d.ts +88 -0
- package/dist/core/session.js +520 -0
- package/dist/core/value.d.ts +18 -0
- package/dist/core/value.js +118 -0
- package/dist/dom/accessibility.d.ts +2 -0
- package/dist/dom/accessibility.js +69 -0
- package/dist/dom/icons.d.ts +1 -0
- package/dist/dom/icons.js +21 -0
- package/dist/dom/images.d.ts +59 -0
- package/dist/dom/images.js +406 -0
- package/dist/dom/index.d.ts +3 -0
- package/dist/dom/index.js +2 -0
- package/dist/dom/inputs.d.ts +5 -0
- package/dist/dom/inputs.js +85 -0
- package/dist/dom/lists.d.ts +7 -0
- package/dist/dom/lists.js +48 -0
- package/dist/dom/measurement.d.ts +16 -0
- package/dist/dom/measurement.js +67 -0
- package/dist/dom/motion-lifecycle.d.ts +17 -0
- package/dist/dom/motion-lifecycle.js +28 -0
- package/dist/dom/motion-plan.d.ts +44 -0
- package/dist/dom/motion-plan.js +31 -0
- package/dist/dom/motion.d.ts +73 -0
- package/dist/dom/motion.js +817 -0
- package/dist/dom/mount-plan.d.ts +15 -0
- package/dist/dom/mount-plan.js +58 -0
- package/dist/dom/presentation.d.ts +11 -0
- package/dist/dom/presentation.js +331 -0
- package/dist/dom/primitives.d.ts +16 -0
- package/dist/dom/primitives.js +378 -0
- package/dist/dom/range.d.ts +9 -0
- package/dist/dom/range.js +120 -0
- package/dist/dom/renderer.d.ts +99 -0
- package/dist/dom/renderer.js +1041 -0
- package/dist/dom/scroll.d.ts +7 -0
- package/dist/dom/scroll.js +167 -0
- package/dist/dom/shared-layout.d.ts +40 -0
- package/dist/dom/shared-layout.js +440 -0
- package/dist/dom/style.d.ts +35 -0
- package/dist/dom/style.js +337 -0
- package/dist/dom/text-motion.d.ts +17 -0
- package/dist/dom/text-motion.js +185 -0
- package/dist/dom/theme.d.ts +13 -0
- package/dist/dom/theme.js +65 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +18 -0
- package/dist/licenses/Rust-COPYRIGHT-library.html +29357 -0
- package/dist/licenses/archery-1.2.3/LICENSE.md +21 -0
- package/dist/licenses/bytemuck-1.25.2/LICENSE-APACHE +61 -0
- package/dist/licenses/bytemuck-1.25.2/LICENSE-MIT +9 -0
- package/dist/licenses/bytemuck-1.25.2/LICENSE-ZLIB +11 -0
- package/dist/licenses/cargo.json +340 -0
- package/dist/licenses/cfg-if-1.0.5/LICENSE-APACHE +201 -0
- package/dist/licenses/cfg-if-1.0.5/LICENSE-MIT +25 -0
- package/dist/licenses/equivalent-1.0.2/LICENSE-APACHE +201 -0
- package/dist/licenses/equivalent-1.0.2/LICENSE-MIT +25 -0
- package/dist/licenses/futures-core-0.3.34/LICENSE-APACHE +202 -0
- package/dist/licenses/futures-core-0.3.34/LICENSE-MIT +26 -0
- package/dist/licenses/futures-task-0.3.34/LICENSE-APACHE +202 -0
- package/dist/licenses/futures-task-0.3.34/LICENSE-MIT +26 -0
- package/dist/licenses/futures-util-0.3.34/LICENSE-APACHE +202 -0
- package/dist/licenses/futures-util-0.3.34/LICENSE-MIT +26 -0
- package/dist/licenses/imbl-7.0.2/LICENCE.md +355 -0
- package/dist/licenses/imbl-sized-chunks-0.2.0/LICENCE.md +355 -0
- package/dist/licenses/itoa-1.0.18/LICENSE-APACHE +176 -0
- package/dist/licenses/itoa-1.0.18/LICENSE-MIT +23 -0
- package/dist/licenses/js-sys-0.3.106/LICENSE-APACHE +201 -0
- package/dist/licenses/js-sys-0.3.106/LICENSE-MIT +25 -0
- package/dist/licenses/memchr-2.8.3/COPYING +3 -0
- package/dist/licenses/memchr-2.8.3/LICENSE-MIT +21 -0
- package/dist/licenses/once_cell-1.21.4/LICENSE-APACHE +201 -0
- package/dist/licenses/once_cell-1.21.4/LICENSE-MIT +23 -0
- package/dist/licenses/pin-project-lite-0.2.17/LICENSE-APACHE +177 -0
- package/dist/licenses/pin-project-lite-0.2.17/LICENSE-MIT +23 -0
- package/dist/licenses/rand_core-0.9.5/COPYRIGHT +12 -0
- package/dist/licenses/rand_core-0.9.5/LICENSE-APACHE +187 -0
- package/dist/licenses/rand_core-0.9.5/LICENSE-MIT +26 -0
- package/dist/licenses/rand_xoshiro-0.7.0/COPYRIGHT +12 -0
- package/dist/licenses/rand_xoshiro-0.7.0/LICENSE-APACHE +176 -0
- package/dist/licenses/rand_xoshiro-0.7.0/LICENSE-MIT +25 -0
- package/dist/licenses/roxmltree-0.21.1/LICENSE-APACHE +201 -0
- package/dist/licenses/roxmltree-0.21.1/LICENSE-MIT +21 -0
- package/dist/licenses/safe_arch-0.7.4/LICENSE-APACHE.md +61 -0
- package/dist/licenses/safe_arch-0.7.4/LICENSE-MIT.md +9 -0
- package/dist/licenses/safe_arch-0.7.4/LICENSE-ZLIB.md +11 -0
- package/dist/licenses/serde-1.0.229/LICENSE-APACHE +176 -0
- package/dist/licenses/serde-1.0.229/LICENSE-MIT +23 -0
- package/dist/licenses/serde_core-1.0.229/LICENSE-APACHE +176 -0
- package/dist/licenses/serde_core-1.0.229/LICENSE-MIT +23 -0
- package/dist/licenses/serde_json-1.0.151/LICENSE-APACHE +176 -0
- package/dist/licenses/serde_json-1.0.151/LICENSE-MIT +23 -0
- package/dist/licenses/slab-0.4.12/LICENSE +25 -0
- package/dist/licenses/slotmap-1.1.1/LICENSE +19 -0
- package/dist/licenses/smallvec-1.16.3/LICENSE-APACHE +201 -0
- package/dist/licenses/smallvec-1.16.3/LICENSE-MIT +25 -0
- package/dist/licenses/taffy-0.15.0/taffy-0.15.0-LICENSE +22 -0
- package/dist/licenses/unicode-ident-1.0.26/LICENSE-APACHE +176 -0
- package/dist/licenses/unicode-ident-1.0.26/LICENSE-MIT +23 -0
- package/dist/licenses/unicode-ident-1.0.26/LICENSE-UNICODE +39 -0
- package/dist/licenses/wasm-bindgen-0.2.129/LICENSE-APACHE +201 -0
- package/dist/licenses/wasm-bindgen-0.2.129/LICENSE-MIT +25 -0
- package/dist/licenses/wasm-bindgen-shared-0.2.129/LICENSE-APACHE +201 -0
- package/dist/licenses/wasm-bindgen-shared-0.2.129/LICENSE-MIT +25 -0
- package/dist/licenses/web-time-1.1.0/LICENSE-APACHE +201 -0
- package/dist/licenses/web-time-1.1.0/LICENSE-MIT +21 -0
- package/dist/licenses/wide-0.7.33/LICENSE-ZLIB.md +11 -0
- package/dist/licenses/zmij-1.0.23/LICENSE-MIT +23 -0
- package/dist/wasm/relo_wasm.d.ts +179 -0
- package/dist/wasm/relo_wasm.js +1228 -0
- package/dist/wasm/relo_wasm_bg.wasm +0 -0
- package/dist/wasm/relo_wasm_bg.wasm.d.ts +65 -0
- package/package.json +25 -4
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Mounted } from './renderer.js';
|
|
2
|
+
import type { PrimitiveHost } from './primitives.js';
|
|
3
|
+
import { type JsonValue } from '../core/value.js';
|
|
4
|
+
export declare function initializeScroll(value: Mounted, host: PrimitiveHost): void;
|
|
5
|
+
export declare function captureScroll(value: Mounted): void;
|
|
6
|
+
export declare function finishScroll(value: Mounted, host: PrimitiveHost): void;
|
|
7
|
+
export declare function scrollCommand(value: Mounted, payload: JsonValue): void;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { fail } from '../core/value.js';
|
|
2
|
+
function metrics(value) {
|
|
3
|
+
const element = value.content, horizontal = value.node.props.axis === 'horizontal', viewport = horizontal ? element.clientWidth : element.clientHeight, content = horizontal ? element.scrollWidth : element.scrollHeight, max = Math.max(0, content - viewport), rtl = horizontal && getComputedStyle(element).direction === 'rtl', offset = Math.max(0, Math.min(max, horizontal ? (rtl ? max + element.scrollLeft : element.scrollLeft) : element.scrollTop));
|
|
4
|
+
return { element, horizontal, viewport, content, max, offset, rtl };
|
|
5
|
+
}
|
|
6
|
+
export function initializeScroll(value, host) {
|
|
7
|
+
const element = value.content;
|
|
8
|
+
const settle = () => {
|
|
9
|
+
if (!value.node.props.paging)
|
|
10
|
+
return;
|
|
11
|
+
const m = metrics(value);
|
|
12
|
+
setOffset(value, Math.round(m.offset / Math.max(1, m.viewport)) * m.viewport);
|
|
13
|
+
reportPage(value, host);
|
|
14
|
+
};
|
|
15
|
+
element.addEventListener('scroll', () => {
|
|
16
|
+
const m = metrics(value);
|
|
17
|
+
value.extra.wasAtEnd = m.offset >= m.max - 2;
|
|
18
|
+
delete value.extra.anchor;
|
|
19
|
+
report(value, host);
|
|
20
|
+
if (value.node.props.paging && !('onscrollend' in element)) {
|
|
21
|
+
clearTimeout(value.extra.scrollTimer);
|
|
22
|
+
value.extra.scrollTimer = setTimeout(settle, 100);
|
|
23
|
+
}
|
|
24
|
+
}, { signal: value.controller.signal });
|
|
25
|
+
element.addEventListener('scrollend', settle, { signal: value.controller.signal });
|
|
26
|
+
value.controller.signal.addEventListener('abort', () => clearTimeout(value.extra.scrollTimer));
|
|
27
|
+
}
|
|
28
|
+
export function captureScroll(value) {
|
|
29
|
+
const m = metrics(value);
|
|
30
|
+
value.extra.wasAtEnd = m.offset >= m.max - 2;
|
|
31
|
+
if (!m.horizontal) {
|
|
32
|
+
const viewport = m.element.getBoundingClientRect();
|
|
33
|
+
const rows = value.children.length === 1 ? value.children[0].children : value.children;
|
|
34
|
+
const first = rows.find((child) => child.element.getBoundingClientRect().bottom > viewport.top);
|
|
35
|
+
if (first)
|
|
36
|
+
value.extra.anchor = {
|
|
37
|
+
id: first.node.id,
|
|
38
|
+
// Content coordinates exclude native scrolling while layout runs.
|
|
39
|
+
offset: first.element.getBoundingClientRect().top - viewport.top + m.element.scrollTop,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function setOffset(value, offset) {
|
|
44
|
+
const m = metrics(value), clamped = Math.max(0, Math.min(m.max, offset));
|
|
45
|
+
if (m.horizontal) {
|
|
46
|
+
const left = m.rtl ? clamped - m.max : clamped;
|
|
47
|
+
if (m.element.scrollLeft !== left)
|
|
48
|
+
m.element.scrollLeft = left;
|
|
49
|
+
}
|
|
50
|
+
else if (m.element.scrollTop !== clamped)
|
|
51
|
+
m.element.scrollTop = clamped;
|
|
52
|
+
}
|
|
53
|
+
function report(value, host) {
|
|
54
|
+
const m = metrics(value), payload = {
|
|
55
|
+
offset: m.offset,
|
|
56
|
+
atEnd: m.offset >= m.max - 2,
|
|
57
|
+
content: m.content,
|
|
58
|
+
viewport: m.viewport,
|
|
59
|
+
}, key = JSON.stringify(payload);
|
|
60
|
+
if (m.viewport > 0 && key !== value.extra.metrics) {
|
|
61
|
+
value.extra.metrics = key;
|
|
62
|
+
if (value.node.observed_events?.includes('scroll'))
|
|
63
|
+
queueMicrotask(() => host.dispatch(value, 'scroll', payload));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function reportPage(value, host) {
|
|
67
|
+
const m = metrics(value);
|
|
68
|
+
if (!value.node.props.paging || !m.viewport)
|
|
69
|
+
return;
|
|
70
|
+
const count = Math.max(1, Math.ceil(m.content / m.viewport)), physical = Math.max(0, Math.min(count - 1, Math.round(m.offset / m.viewport))), index = value.node.props.pageExtent === 'viewport' && m.rtl ? count - 1 - physical : physical, key = `${index}:${count}`;
|
|
71
|
+
value.extra.currentPage = index;
|
|
72
|
+
if (key !== value.extra.pageMetrics) {
|
|
73
|
+
value.extra.pageMetrics = key;
|
|
74
|
+
if (value.node.observed_events?.includes('pageChange'))
|
|
75
|
+
queueMicrotask(() => host.dispatch(value, 'pageChange', { index, count }));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export function finishScroll(value, host) {
|
|
79
|
+
const m = metrics(value), props = value.node.props;
|
|
80
|
+
m.element.style.scrollbarWidth = props.indicators === false ? 'none' : 'thin';
|
|
81
|
+
m.element.style.scrollSnapType = props.paging
|
|
82
|
+
? m.horizontal
|
|
83
|
+
? 'x mandatory'
|
|
84
|
+
: 'y mandatory'
|
|
85
|
+
: '';
|
|
86
|
+
let markers = value.extra.snapMarkers;
|
|
87
|
+
if (props.paging && m.viewport > 0) {
|
|
88
|
+
const count = Math.min(1024, Math.max(1, Math.ceil(m.content / m.viewport)));
|
|
89
|
+
if (!markers) {
|
|
90
|
+
markers = document.createElement('div');
|
|
91
|
+
markers.setAttribute('aria-hidden', 'true');
|
|
92
|
+
markers.style.cssText = 'position:absolute;left:0;top:0;pointer-events:none';
|
|
93
|
+
m.element.append(markers);
|
|
94
|
+
value.extra.snapMarkers = markers;
|
|
95
|
+
}
|
|
96
|
+
while (markers.children.length > count)
|
|
97
|
+
markers.lastElementChild.remove();
|
|
98
|
+
while (markers.children.length < count)
|
|
99
|
+
markers.append(document.createElement('div'));
|
|
100
|
+
[...markers.children].forEach((child, index) => Object.assign(child.style, {
|
|
101
|
+
position: 'absolute',
|
|
102
|
+
scrollSnapAlign: 'start',
|
|
103
|
+
scrollSnapStop: 'always',
|
|
104
|
+
left: `${m.horizontal ? index * m.viewport - (m.rtl ? m.max : 0) : 0}px`,
|
|
105
|
+
top: `${m.horizontal ? 0 : index * m.viewport}px`,
|
|
106
|
+
width: `${m.horizontal ? Math.max(1, Math.min(m.viewport, m.content - index * m.viewport)) : 1}px`,
|
|
107
|
+
height: `${m.horizontal ? 1 : Math.max(1, Math.min(m.viewport, m.content - index * m.viewport))}px`,
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
else if (markers) {
|
|
111
|
+
markers.remove();
|
|
112
|
+
delete value.extra.snapMarkers;
|
|
113
|
+
}
|
|
114
|
+
if (props.paging) {
|
|
115
|
+
const count = Math.max(1, Math.ceil(m.content / Math.max(1, m.viewport))), bound = props.page;
|
|
116
|
+
if (bound !== value.extra.boundPage || m.viewport !== value.extra.pageViewport) {
|
|
117
|
+
const page = Math.max(0, Math.min(count - 1, bound !== value.extra.boundPage
|
|
118
|
+
? (bound ?? value.extra.currentPage ?? 0)
|
|
119
|
+
: (value.extra.currentPage ?? bound ?? 0)));
|
|
120
|
+
setOffset(value, (props.pageExtent === 'viewport' && m.rtl ? count - 1 - page : page) * m.viewport);
|
|
121
|
+
value.extra.boundPage = bound;
|
|
122
|
+
value.extra.pageViewport = m.viewport;
|
|
123
|
+
}
|
|
124
|
+
reportPage(value, host);
|
|
125
|
+
}
|
|
126
|
+
else if (!m.horizontal) {
|
|
127
|
+
if (props.follow === 'end' && value.extra.wasAtEnd !== false)
|
|
128
|
+
setOffset(value, m.max);
|
|
129
|
+
else if (value.extra.anchor) {
|
|
130
|
+
const anchor = host.find(value.extra.anchor.id);
|
|
131
|
+
if (anchor) {
|
|
132
|
+
const delta = anchor.element.getBoundingClientRect().top -
|
|
133
|
+
m.element.getBoundingClientRect().top +
|
|
134
|
+
m.element.scrollTop -
|
|
135
|
+
value.extra.anchor.offset;
|
|
136
|
+
if (Math.abs(delta) > 0.5)
|
|
137
|
+
m.element.scrollTop += delta;
|
|
138
|
+
}
|
|
139
|
+
delete value.extra.anchor;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
report(value, host);
|
|
143
|
+
}
|
|
144
|
+
export function scrollCommand(value, payload) {
|
|
145
|
+
if (!payload ||
|
|
146
|
+
typeof payload !== 'object' ||
|
|
147
|
+
Array.isArray(payload) ||
|
|
148
|
+
Object.keys(payload).some((key) => !['x', 'y', 'edge'].includes(key)))
|
|
149
|
+
fail('Invalid scroll arguments');
|
|
150
|
+
const input = payload, m = metrics(value);
|
|
151
|
+
for (const key of ['x', 'y'])
|
|
152
|
+
if (input[key] !== undefined &&
|
|
153
|
+
(typeof input[key] !== 'number' || input[key] < 0 || input[key] > 1e6))
|
|
154
|
+
fail('Invalid scroll coordinate');
|
|
155
|
+
if (input.edge !== undefined) {
|
|
156
|
+
if (!['start', 'end'].includes(input.edge))
|
|
157
|
+
fail('Invalid scroll edge');
|
|
158
|
+
setOffset(value, input.edge === 'end' ? m.max : 0);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
let offset = (m.horizontal ? input.x : input.y);
|
|
162
|
+
offset ??= 0;
|
|
163
|
+
if (value.node.props.paging)
|
|
164
|
+
offset = Math.round(offset / Math.max(1, m.viewport)) * m.viewport;
|
|
165
|
+
setOffset(value, offset);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { IntrinsicMeasurements } from './measurement.js';
|
|
2
|
+
import type { Mounted } from './renderer.js';
|
|
3
|
+
import type { MotionCoordinator } from './motion.js';
|
|
4
|
+
/** Native DOM widgets provide leaf metrics; retained Rust owns container layout. */
|
|
5
|
+
export declare class DomLayout {
|
|
6
|
+
private readonly motion;
|
|
7
|
+
private readonly rendering;
|
|
8
|
+
private readonly engine;
|
|
9
|
+
private readonly cached;
|
|
10
|
+
private readonly nodes;
|
|
11
|
+
private readonly handles;
|
|
12
|
+
private readonly logicalIDs;
|
|
13
|
+
private readonly styles;
|
|
14
|
+
private readonly styleKeys;
|
|
15
|
+
private readonly typography;
|
|
16
|
+
private readonly textMetrics;
|
|
17
|
+
private readonly ownsTextMetrics;
|
|
18
|
+
private readonly targets;
|
|
19
|
+
private readonly scopes;
|
|
20
|
+
private epoch;
|
|
21
|
+
private phase;
|
|
22
|
+
private invalidated;
|
|
23
|
+
private size;
|
|
24
|
+
private get closing();
|
|
25
|
+
constructor(motion: MotionCoordinator, rendering: () => boolean, textMetrics?: IntrinsicMeasurements);
|
|
26
|
+
invalidate(): void;
|
|
27
|
+
private flushInvalidation;
|
|
28
|
+
layout(root: Mounted, width: number, height?: number): {
|
|
29
|
+
width: number;
|
|
30
|
+
height: number;
|
|
31
|
+
};
|
|
32
|
+
private performLayout;
|
|
33
|
+
private readInsets;
|
|
34
|
+
private measure;
|
|
35
|
+
private apply;
|
|
36
|
+
private scope;
|
|
37
|
+
private layoutSeparate;
|
|
38
|
+
dispose(): void;
|
|
39
|
+
private release;
|
|
40
|
+
}
|
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
import { getEngine } from '../core/engine.js';
|
|
2
|
+
import { fail } from '../core/value.js';
|
|
3
|
+
import { measureInput } from './inputs.js';
|
|
4
|
+
import { IntrinsicMeasurements, textMeasurementStyle } from './measurement.js';
|
|
5
|
+
import { measureList } from './lists.js';
|
|
6
|
+
import { presentationSize } from './presentation.js';
|
|
7
|
+
const address = (node) => `${node.slot}:${node.generation}`;
|
|
8
|
+
/** Native DOM widgets provide leaf metrics; retained Rust owns container layout. */
|
|
9
|
+
export class DomLayout {
|
|
10
|
+
motion;
|
|
11
|
+
rendering;
|
|
12
|
+
engine = new (getEngine().WasmPresentation)(1);
|
|
13
|
+
cached = new WeakMap();
|
|
14
|
+
nodes = new Map();
|
|
15
|
+
handles = new Map();
|
|
16
|
+
logicalIDs = new Map();
|
|
17
|
+
styles = new WeakMap();
|
|
18
|
+
styleKeys = new WeakMap();
|
|
19
|
+
typography = new WeakMap();
|
|
20
|
+
textMetrics;
|
|
21
|
+
ownsTextMetrics;
|
|
22
|
+
targets = new Map();
|
|
23
|
+
scopes = new Map();
|
|
24
|
+
epoch = 0;
|
|
25
|
+
phase = 'idle';
|
|
26
|
+
invalidated = false;
|
|
27
|
+
size = { width: 0, height: 0 };
|
|
28
|
+
get closing() {
|
|
29
|
+
return this.phase === 'closing' || this.phase === 'closed';
|
|
30
|
+
}
|
|
31
|
+
constructor(motion, rendering, textMetrics) {
|
|
32
|
+
this.motion = motion;
|
|
33
|
+
this.rendering = rendering;
|
|
34
|
+
this.ownsTextMetrics = !textMetrics;
|
|
35
|
+
this.textMetrics = textMetrics ?? new IntrinsicMeasurements();
|
|
36
|
+
}
|
|
37
|
+
invalidate() {
|
|
38
|
+
if (this.closing)
|
|
39
|
+
return;
|
|
40
|
+
this.epoch++;
|
|
41
|
+
this.textMetrics.clear();
|
|
42
|
+
this.invalidated = true;
|
|
43
|
+
if (this.phase === 'idle')
|
|
44
|
+
this.flushInvalidation();
|
|
45
|
+
for (const scope of this.scopes.values())
|
|
46
|
+
scope.invalidate();
|
|
47
|
+
}
|
|
48
|
+
flushInvalidation() {
|
|
49
|
+
if (!this.invalidated)
|
|
50
|
+
return;
|
|
51
|
+
this.invalidated = false;
|
|
52
|
+
this.engine.invalidate_all_intrinsics();
|
|
53
|
+
}
|
|
54
|
+
layout(root, width, height) {
|
|
55
|
+
if (this.closing || this.phase === 'layout')
|
|
56
|
+
return this.size;
|
|
57
|
+
this.phase = 'layout';
|
|
58
|
+
try {
|
|
59
|
+
this.size = this.performLayout(root, width, height);
|
|
60
|
+
return this.size;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (this.closing)
|
|
64
|
+
return this.size;
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
// Firefox can deliver pagehide during a synchronous DOM measurement.
|
|
69
|
+
// Release the Wasm owner only after its mutable call has returned.
|
|
70
|
+
if (this.closing)
|
|
71
|
+
this.release();
|
|
72
|
+
else {
|
|
73
|
+
this.phase = 'idle';
|
|
74
|
+
this.flushInvalidation();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
performLayout(root, width, height) {
|
|
79
|
+
const candidates = [];
|
|
80
|
+
const aliases = new Map();
|
|
81
|
+
const describe = (value, isRoot = false, paging, parentKey = '') => {
|
|
82
|
+
const revision = value.extra.geometryRevision ?? 0;
|
|
83
|
+
const key = parentKey
|
|
84
|
+
? `${parentKey}/${value.extra.layoutIdentity}`
|
|
85
|
+
: value.extra.layoutIdentity;
|
|
86
|
+
const rootSize = `${isRoot ? `${width}:${height}` : ''}|${paging?.pages ?? ''}:${paging?.page ?? ''}`;
|
|
87
|
+
const prior = this.cached.get(value);
|
|
88
|
+
if (prior &&
|
|
89
|
+
prior.revision === revision &&
|
|
90
|
+
prior.epoch === this.epoch &&
|
|
91
|
+
prior.rootSize === rootSize &&
|
|
92
|
+
prior.key === key)
|
|
93
|
+
return { reuse: prior.handle };
|
|
94
|
+
const insets = this.readInsets(value);
|
|
95
|
+
let childPaging;
|
|
96
|
+
let role;
|
|
97
|
+
if (paging?.page)
|
|
98
|
+
role = { page: paging.pages };
|
|
99
|
+
else if (paging) {
|
|
100
|
+
const pages = value.node.type === 'Row' ? Math.max(1, value.children.length) : undefined;
|
|
101
|
+
role = pages ? { strip: pages } : 'wrapper';
|
|
102
|
+
childPaging = pages ? { pages, page: true } : paging;
|
|
103
|
+
}
|
|
104
|
+
if (value.node.type === 'Scroll' &&
|
|
105
|
+
value.node.props.pageExtent === 'viewport' &&
|
|
106
|
+
value.node.props.axis === 'horizontal')
|
|
107
|
+
childPaging = {};
|
|
108
|
+
const source = {
|
|
109
|
+
kind: value.node.type,
|
|
110
|
+
classes: value.extra.expanded ?? value.node.classes,
|
|
111
|
+
props: value.node.props,
|
|
112
|
+
padding: insets.padding,
|
|
113
|
+
border: insets.border,
|
|
114
|
+
rtl: value.extra.direction === 'rtl',
|
|
115
|
+
shown: value.node.shown,
|
|
116
|
+
stacked: value.parent?.node.type === 'Overlay',
|
|
117
|
+
paging: role,
|
|
118
|
+
fillWidth: isRoot,
|
|
119
|
+
fillHeight: isRoot && height !== undefined,
|
|
120
|
+
scrollChild: value.parent?.node.type === 'Scroll',
|
|
121
|
+
};
|
|
122
|
+
this.styles.set(value, value.node.type === 'Popup' ? { padding: [0, 0, 0, 0], border: [0, 0, 0, 0] } : insets);
|
|
123
|
+
if (value.content instanceof HTMLElement &&
|
|
124
|
+
['Text', 'Button', 'RichText'].includes(value.node.type))
|
|
125
|
+
this.typography.set(value, textMeasurementStyle(value.content));
|
|
126
|
+
const separate = value.node.type === 'Popup' || value.node.type === 'List';
|
|
127
|
+
const children = separate
|
|
128
|
+
? []
|
|
129
|
+
: value.children.map((child) => describe(child, false, childPaging, key));
|
|
130
|
+
candidates.push([value, revision, rootSize, key]);
|
|
131
|
+
aliases.set(key, value.node.id);
|
|
132
|
+
return {
|
|
133
|
+
key,
|
|
134
|
+
kind: value.node.type,
|
|
135
|
+
source,
|
|
136
|
+
properties: { materialized: value.extra.materialized !== false },
|
|
137
|
+
intrinsicRevision: children.length || value.node.type === 'Popup' ? null : revision,
|
|
138
|
+
children,
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
const prepared = JSON.parse(this.engine.prepare(JSON.stringify(describe(root, true)), false));
|
|
142
|
+
const batch = JSON.parse(this.engine.commit(prepared.token));
|
|
143
|
+
for (const operation of batch.operations) {
|
|
144
|
+
if (operation.op === 'create') {
|
|
145
|
+
const id = aliases.get(operation.key);
|
|
146
|
+
this.handles.set(id, operation.node);
|
|
147
|
+
this.logicalIDs.set(address(operation.node), id);
|
|
148
|
+
}
|
|
149
|
+
if (operation.op === 'retire') {
|
|
150
|
+
const id = this.logicalIDs.get(address(operation.node));
|
|
151
|
+
if (id && address(this.handles.get(id)) === address(operation.node))
|
|
152
|
+
this.handles.delete(id);
|
|
153
|
+
this.logicalIDs.delete(address(operation.node));
|
|
154
|
+
this.nodes.delete(address(operation.node));
|
|
155
|
+
this.targets.delete(address(operation.node));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
for (const [value, revision, rootSize, key] of candidates) {
|
|
159
|
+
const handle = this.handles.get(value.node.id);
|
|
160
|
+
this.cached.set(value, { revision, epoch: this.epoch, rootSize, handle, key });
|
|
161
|
+
this.nodes.set(address(handle), value);
|
|
162
|
+
}
|
|
163
|
+
const measure = (raw) => {
|
|
164
|
+
const request = JSON.parse(raw), value = this.nodes.get(request.node);
|
|
165
|
+
return JSON.stringify(this.measure(value, request));
|
|
166
|
+
};
|
|
167
|
+
const targets = JSON.parse(this.engine.compute_targets(width, height, measure));
|
|
168
|
+
if (this.closing)
|
|
169
|
+
return this.size;
|
|
170
|
+
for (const positioned of targets.frames)
|
|
171
|
+
this.targets.set(address(positioned.node), positioned.frame);
|
|
172
|
+
for (const [key, value] of this.nodes) {
|
|
173
|
+
const frame = this.targets.get(key);
|
|
174
|
+
if (!frame || this.motion.preservesLayout(value))
|
|
175
|
+
continue;
|
|
176
|
+
value.extra.targetGeometry = frame;
|
|
177
|
+
if (!this.rendering())
|
|
178
|
+
this.motion.layoutTarget(value.node.id, frame);
|
|
179
|
+
}
|
|
180
|
+
const overrides = this.rendering()
|
|
181
|
+
? []
|
|
182
|
+
: [...this.nodes].flatMap(([key, value]) => {
|
|
183
|
+
const values = this.motion.layoutOverrides(value.node.id);
|
|
184
|
+
return values ? [{ node: this.handles.get(value.node.id), values }] : [];
|
|
185
|
+
});
|
|
186
|
+
this.engine.set_layout_overrides(JSON.stringify(overrides));
|
|
187
|
+
const frames = JSON.parse(this.engine.compute(width, height, measure));
|
|
188
|
+
if (this.closing)
|
|
189
|
+
return this.size;
|
|
190
|
+
for (const positioned of frames.frames)
|
|
191
|
+
this.apply(this.nodes.get(address(positioned.node)), positioned.frame, positioned.native);
|
|
192
|
+
for (const [value, scope] of this.scopes)
|
|
193
|
+
if (value.controller.signal.aborted) {
|
|
194
|
+
scope.dispose();
|
|
195
|
+
this.scopes.delete(value);
|
|
196
|
+
}
|
|
197
|
+
for (const value of this.nodes.values()) {
|
|
198
|
+
if (this.closing)
|
|
199
|
+
break;
|
|
200
|
+
this.layoutSeparate(value);
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
width: parseFloat(root.element.style.width),
|
|
204
|
+
height: parseFloat(root.element.style.height),
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
readInsets(value) {
|
|
208
|
+
const prior = this.styles.get(value);
|
|
209
|
+
if (prior &&
|
|
210
|
+
this.styleKeys.get(value)?.key === value.extra.geometryKey &&
|
|
211
|
+
this.styleKeys.get(value)?.epoch === this.epoch)
|
|
212
|
+
return { padding: prior.padding, border: prior.border };
|
|
213
|
+
const detached = !value.element.isConnected;
|
|
214
|
+
const visibility = value.element.style.visibility;
|
|
215
|
+
// Only a compiler-proven inert wrapper can be detached. Probe its own CSS
|
|
216
|
+
// in the physical parent's context; no editor or child is moved. Cache by
|
|
217
|
+
// authored style so ordinary text edits never repeat this probe.
|
|
218
|
+
if (detached) {
|
|
219
|
+
value.element.style.visibility = 'hidden';
|
|
220
|
+
value.childHost.append(value.element);
|
|
221
|
+
}
|
|
222
|
+
try {
|
|
223
|
+
const css = getComputedStyle(value.element);
|
|
224
|
+
const edges = (prefix) => ['Top', 'Right', 'Bottom', 'Left'].map((edge) => parseFloat(css[`${prefix}${edge}${prefix === 'border' ? 'Width' : ''}`]) || 0);
|
|
225
|
+
const result = { padding: edges('padding'), border: edges('border') };
|
|
226
|
+
this.styleKeys.set(value, { key: value.extra.geometryKey, epoch: this.epoch });
|
|
227
|
+
return result;
|
|
228
|
+
}
|
|
229
|
+
finally {
|
|
230
|
+
if (detached) {
|
|
231
|
+
value.element.remove();
|
|
232
|
+
value.element.style.visibility = visibility;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
measure(value, request) {
|
|
237
|
+
const elements = [value.content, value.extra.inputBox].filter((element) => element instanceof HTMLElement);
|
|
238
|
+
const saved = elements.map((element) => [
|
|
239
|
+
element.style.width,
|
|
240
|
+
element.style.height,
|
|
241
|
+
element.style.maxWidth,
|
|
242
|
+
]);
|
|
243
|
+
let restore = false;
|
|
244
|
+
try {
|
|
245
|
+
const known = request.knownWidth;
|
|
246
|
+
const available = request.availableWidth;
|
|
247
|
+
const limit = available.definite;
|
|
248
|
+
const width = known ?? limit ?? (available === 'minContent' ? 44 : 240);
|
|
249
|
+
let measured;
|
|
250
|
+
if (value.extra.inputBox) {
|
|
251
|
+
restore = true;
|
|
252
|
+
measured = { width, height: measureInput(value, width) };
|
|
253
|
+
}
|
|
254
|
+
else if (value.adapter?.measure)
|
|
255
|
+
measured = value.adapter.measure(width);
|
|
256
|
+
else if (value.node.type === 'List')
|
|
257
|
+
measured = { width, height: Math.min(300, value.extra.totalHeight ?? 0) };
|
|
258
|
+
else if (value.node.type === 'Range')
|
|
259
|
+
measured = { width, height: 48 };
|
|
260
|
+
else if (value.node.type === 'Image')
|
|
261
|
+
measured = { width: 96, height: 160 };
|
|
262
|
+
else if (value.node.type === 'Icon')
|
|
263
|
+
measured = { width: value.node.props.size ?? 24, height: value.node.props.size ?? 24 };
|
|
264
|
+
else if (value.node.type === 'Divider')
|
|
265
|
+
measured =
|
|
266
|
+
value.node.props.orientation === 'vertical'
|
|
267
|
+
? { width: 1, height: request.knownHeight ?? 24 }
|
|
268
|
+
: { width: 1, height: 1 };
|
|
269
|
+
else if (value.content) {
|
|
270
|
+
const content = value.content;
|
|
271
|
+
const probe = () => {
|
|
272
|
+
restore = true;
|
|
273
|
+
// A target proposal must not be clamped by the widget's previous frame.
|
|
274
|
+
// Read untransformed layout metrics so ancestor scale/rotation cannot
|
|
275
|
+
// feed back into intrinsic text size during an animation.
|
|
276
|
+
content.style.maxWidth = 'none';
|
|
277
|
+
content.style.height = 'auto';
|
|
278
|
+
content.style.width =
|
|
279
|
+
known === null
|
|
280
|
+
? available === 'minContent'
|
|
281
|
+
? 'min-content'
|
|
282
|
+
: 'max-content'
|
|
283
|
+
: `${known}px`;
|
|
284
|
+
const read = () => {
|
|
285
|
+
const css = getComputedStyle(content);
|
|
286
|
+
const extra = (axis) => css.boxSizing === 'border-box'
|
|
287
|
+
? 0
|
|
288
|
+
: (axis === 'width'
|
|
289
|
+
? ['paddingLeft', 'paddingRight', 'borderLeftWidth', 'borderRightWidth']
|
|
290
|
+
: ['paddingTop', 'paddingBottom', 'borderTopWidth', 'borderBottomWidth']).reduce((sum, name) => sum + (parseFloat(css[name]) || 0), 0);
|
|
291
|
+
return {
|
|
292
|
+
width: parseFloat(css.width) + extra('width'),
|
|
293
|
+
height: parseFloat(css.height) + extra('height'),
|
|
294
|
+
};
|
|
295
|
+
};
|
|
296
|
+
let rect = read();
|
|
297
|
+
if (known === null && limit !== undefined && rect.width > limit) {
|
|
298
|
+
content.style.width = `${limit}px`;
|
|
299
|
+
rect = read();
|
|
300
|
+
}
|
|
301
|
+
return rect;
|
|
302
|
+
};
|
|
303
|
+
const typography = this.typography.get(value);
|
|
304
|
+
measured =
|
|
305
|
+
typography && content instanceof HTMLElement
|
|
306
|
+
? this.textMetrics.measure(JSON.stringify([
|
|
307
|
+
value.node.type,
|
|
308
|
+
typography,
|
|
309
|
+
content.innerHTML,
|
|
310
|
+
known === null ? available : known,
|
|
311
|
+
]), probe)
|
|
312
|
+
: probe();
|
|
313
|
+
}
|
|
314
|
+
else
|
|
315
|
+
measured = { width: 0, height: 0 };
|
|
316
|
+
if (!Number.isFinite(measured.width) ||
|
|
317
|
+
!Number.isFinite(measured.height) ||
|
|
318
|
+
measured.width < 0 ||
|
|
319
|
+
measured.height < 0)
|
|
320
|
+
fail('Invalid native DOM measurement');
|
|
321
|
+
return { width: measured.width, height: measured.height, firstBaseline: null };
|
|
322
|
+
}
|
|
323
|
+
finally {
|
|
324
|
+
if (restore)
|
|
325
|
+
elements.forEach((element, index) => {
|
|
326
|
+
element.style.width = saved[index][0];
|
|
327
|
+
element.style.height = saved[index][1];
|
|
328
|
+
element.style.maxWidth = saved[index][2];
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
apply(value, logical, native) {
|
|
333
|
+
// Hidden layout frames are zeroed by Rust. An opacity/transform-only exit
|
|
334
|
+
// still draws its old subtree; applying those frames rewraps its live text
|
|
335
|
+
// at the origin before it fades. Size exits continue using real layout.
|
|
336
|
+
if (this.motion.preservesLayout(value))
|
|
337
|
+
return;
|
|
338
|
+
value.extra.layoutGeometry = logical;
|
|
339
|
+
if (!native)
|
|
340
|
+
return;
|
|
341
|
+
const frame = native.frame;
|
|
342
|
+
const style = this.styles.get(value);
|
|
343
|
+
const [pt, pr, pb, pl] = this.motion.layoutOverrides(value.node.id)?.padding ?? style.padding;
|
|
344
|
+
const [bt, br, bb, bl] = style.border;
|
|
345
|
+
const inner = {
|
|
346
|
+
width: Math.max(0, frame.width - pl - pr - bl - br),
|
|
347
|
+
height: Math.max(0, frame.height - pt - pb - bt - bb),
|
|
348
|
+
};
|
|
349
|
+
const parent = native.parent ? this.nodes.get(address(native.parent)) : undefined, scroll = parent?.node.type === 'Scroll';
|
|
350
|
+
const insets = parent && this.styles.get(parent);
|
|
351
|
+
Object.assign(value.element.style, {
|
|
352
|
+
left: `${frame.x - (insets ? insets.border[3] + (scroll ? insets.padding[3] : 0) : 0)}px`,
|
|
353
|
+
top: `${frame.y - (insets ? insets.border[0] + (scroll ? insets.padding[0] : 0) : 0)}px`,
|
|
354
|
+
width: `${frame.width}px`,
|
|
355
|
+
height: `${frame.height}px`,
|
|
356
|
+
});
|
|
357
|
+
// CSS border boxes cannot shrink below their insets. Rust's allocation
|
|
358
|
+
// still reaches zero; clip native paint to that allocation during collapse.
|
|
359
|
+
// Children retain their identity, padding and editing buffers.
|
|
360
|
+
const allocation = this.motion.layoutOverrides(value.node.id);
|
|
361
|
+
value.element.style.clipPath =
|
|
362
|
+
allocation?.width !== undefined || allocation?.height !== undefined
|
|
363
|
+
? `polygon(0 0,${frame.width}px 0,${frame.width}px ${frame.height}px,0 ${frame.height}px)`
|
|
364
|
+
: '';
|
|
365
|
+
if (value.node.type === 'Scroll' || value.node.type === 'List')
|
|
366
|
+
Object.assign(value.content.style, {
|
|
367
|
+
position: 'absolute',
|
|
368
|
+
left: `${pl}px`,
|
|
369
|
+
top: `${pt}px`,
|
|
370
|
+
width: `${inner.width}px`,
|
|
371
|
+
height: `${inner.height}px`,
|
|
372
|
+
});
|
|
373
|
+
else if (value.extra.inputBox)
|
|
374
|
+
measureInput(value, inner.width, inner.height);
|
|
375
|
+
else if (value.content)
|
|
376
|
+
Object.assign(value.content.style, {
|
|
377
|
+
width: `${inner.width}px`,
|
|
378
|
+
height: `${inner.height}px`,
|
|
379
|
+
});
|
|
380
|
+
if (value.node.type === 'Pressable' || value.node.type === 'Checkable')
|
|
381
|
+
Object.assign(value.content.style, {
|
|
382
|
+
position: 'absolute',
|
|
383
|
+
left: '0px',
|
|
384
|
+
top: '0px',
|
|
385
|
+
width: `${frame.width}px`,
|
|
386
|
+
height: `${frame.height}px`,
|
|
387
|
+
border: '0',
|
|
388
|
+
borderRadius: 'inherit',
|
|
389
|
+
background: 'transparent',
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
scope(root) {
|
|
393
|
+
let value = this.scopes.get(root);
|
|
394
|
+
if (!value) {
|
|
395
|
+
value = new DomLayout(this.motion, this.rendering, this.textMetrics);
|
|
396
|
+
this.scopes.set(root, value);
|
|
397
|
+
}
|
|
398
|
+
return value;
|
|
399
|
+
}
|
|
400
|
+
layoutSeparate(value) {
|
|
401
|
+
if (value.node.type === 'List') {
|
|
402
|
+
const width = value.content.clientWidth;
|
|
403
|
+
measureList(value, width, (child) => this.scope(child).layout(child, width));
|
|
404
|
+
}
|
|
405
|
+
else if (value.node.type === 'Popup' && value.node.props.value && value.node.shown) {
|
|
406
|
+
const bounds = presentationSize(value);
|
|
407
|
+
const height = Math.max(0, ...value.children.map((child) => this.scope(child).layout(child, bounds.width).height));
|
|
408
|
+
value.childHost.style.width = `${bounds.width}px`;
|
|
409
|
+
value.childHost.style.height = `${height}px`;
|
|
410
|
+
if (value.node.props.mode !== 'edge')
|
|
411
|
+
value.content.style.height = `${Math.min(bounds.height, height + 32)}px`;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
dispose() {
|
|
415
|
+
if (this.closing)
|
|
416
|
+
return;
|
|
417
|
+
if (this.phase === 'layout') {
|
|
418
|
+
this.phase = 'closing';
|
|
419
|
+
for (const scope of this.scopes.values())
|
|
420
|
+
scope.dispose();
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
this.release();
|
|
424
|
+
}
|
|
425
|
+
release() {
|
|
426
|
+
if (this.phase === 'closed')
|
|
427
|
+
return;
|
|
428
|
+
this.phase = 'closed';
|
|
429
|
+
this.engine.free();
|
|
430
|
+
for (const scope of this.scopes.values())
|
|
431
|
+
scope.dispose();
|
|
432
|
+
this.scopes.clear();
|
|
433
|
+
this.nodes.clear();
|
|
434
|
+
this.handles.clear();
|
|
435
|
+
this.logicalIDs.clear();
|
|
436
|
+
this.targets.clear();
|
|
437
|
+
if (this.ownsTextMetrics)
|
|
438
|
+
this.textMetrics.clear();
|
|
439
|
+
}
|
|
440
|
+
}
|