@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,15 @@
1
+ import type { RemoteSession, RenderNode } from '../core/session.js';
2
+ /** One logical identity journal per attachment, including unmounted list rows. */
3
+ export declare class MountPlan {
4
+ private readonly engine;
5
+ private readonly entries;
6
+ private readonly keys;
7
+ changed: Set<string>;
8
+ retired: string[];
9
+ replaced: boolean;
10
+ private closed;
11
+ update(session: RemoteSession, root: RenderNode, replace: boolean): void;
12
+ materialized(id: string): boolean;
13
+ incarnation(id: string): string | undefined;
14
+ dispose(): void;
15
+ }
@@ -0,0 +1,58 @@
1
+ import { getEngine } from '../core/engine.js';
2
+ const address = (node) => `${node.slot}:${node.generation}`;
3
+ /** One logical identity journal per attachment, including unmounted list rows. */
4
+ export class MountPlan {
5
+ engine = new (getEngine().WasmMountTree)(1);
6
+ entries = new Map();
7
+ keys = new Map();
8
+ changed = new Set();
9
+ retired = [];
10
+ replaced = false;
11
+ closed = false;
12
+ update(session, root, replace) {
13
+ if (this.closed)
14
+ return;
15
+ const token = session.prepareMount(this.engine, root.id, replace);
16
+ const result = JSON.parse(this.engine.commit(token));
17
+ this.changed = new Set(result.changed);
18
+ this.retired = result.retired;
19
+ this.replaced = result.replaced;
20
+ for (const operation of result.batch.operations) {
21
+ if (operation.op === 'create') {
22
+ this.entries.set(operation.key, {
23
+ handle: operation.node,
24
+ materialized: operation.properties.materialized,
25
+ });
26
+ this.keys.set(address(operation.node), operation.key);
27
+ }
28
+ else if (operation.op === 'update') {
29
+ const key = this.keys.get(address(operation.node));
30
+ if ('materialized' in operation.properties.set)
31
+ this.entries.get(key).materialized = operation.properties.set.materialized;
32
+ }
33
+ else if (operation.op === 'retire') {
34
+ const key = this.keys.get(address(operation.node));
35
+ if (key && address(this.entries.get(key).handle) === address(operation.node))
36
+ this.entries.delete(key);
37
+ this.keys.delete(address(operation.node));
38
+ }
39
+ }
40
+ }
41
+ materialized(id) {
42
+ return this.entries.get(id)?.materialized !== false;
43
+ }
44
+ incarnation(id) {
45
+ const entry = this.entries.get(id);
46
+ return entry ? address(entry.handle) : undefined;
47
+ }
48
+ dispose() {
49
+ if (this.closed)
50
+ return;
51
+ this.closed = true;
52
+ this.entries.clear();
53
+ this.keys.clear();
54
+ this.changed.clear();
55
+ this.retired = [];
56
+ this.engine.free();
57
+ }
58
+ }
@@ -0,0 +1,11 @@
1
+ import type { Mounted } from './renderer.js';
2
+ import type { PrimitiveHost } from './primitives.js';
3
+ export declare function closePresentation(value: Mounted): void;
4
+ export declare function initializePresentation(value: Mounted, host: PrimitiveHost): void;
5
+ export declare function updatePresentation(value: Mounted, host: PrimitiveHost): void;
6
+ export declare function positionPresentation(value: Mounted, host: PrimitiveHost): void;
7
+ export declare function presentationSize(value: Mounted): {
8
+ width: number;
9
+ height: number;
10
+ };
11
+ export declare const presentationCSS = "\n.relo-surface .relo-popup::backdrop{background:rgb(0 0 0 / .1)}\n.relo-surface .relo-sheet-handle{position:absolute;top:2px;left:calc(50% - 24px);width:48px;height:12px;cursor:ns-resize;touch-action:none;border-radius:8px}\n.relo-surface .relo-sheet-handle::after{content:'';position:absolute;left:10px;right:10px;top:4px;height:4px;background:currentColor;opacity:.3;border-radius:2px}\n.relo-surface .relo-sheet-handle[hidden]{display:none}\n";
@@ -0,0 +1,331 @@
1
+ import { color } from './style.js';
2
+ let nextOpen = 0;
3
+ const opened = new Map();
4
+ function top(value) {
5
+ return opened.get(value) === Math.max(0, ...opened.values());
6
+ }
7
+ function viewport() {
8
+ const v = window.visualViewport;
9
+ return {
10
+ left: v?.offsetLeft ?? 0,
11
+ top: v?.offsetTop ?? 0,
12
+ width: v?.width ?? innerWidth,
13
+ height: v?.height ?? innerHeight,
14
+ };
15
+ }
16
+ export function closePresentation(value) {
17
+ const dialog = value.content;
18
+ if (dialog.matches(':popover-open'))
19
+ dialog.hidePopover();
20
+ if (dialog.open)
21
+ dialog.close();
22
+ opened.delete(value);
23
+ cancelAnimationFrame(value.extra.initialFocus ?? 0);
24
+ const target = value.extra.restoreFocus;
25
+ if (value.node.props.mode !== 'notification' &&
26
+ target?.isConnected &&
27
+ !target.closest('[hidden],[inert]'))
28
+ target.focus({ preventScroll: true });
29
+ value.extra.restoreFocus = undefined;
30
+ value.element.hidden = true;
31
+ }
32
+ export function initializePresentation(value, host) {
33
+ const dialog = value.content;
34
+ value.extra.onPresentationHidden = () => closePresentation(value);
35
+ dialog.classList.add('relo-popup');
36
+ const on = (target, name, handler) => target.addEventListener(name, handler, { signal: value.controller.signal });
37
+ const dismiss = () => {
38
+ if (value.node.props.dismissible !== false)
39
+ host.dispatch(value, 'change', { value: false });
40
+ };
41
+ on(dialog, 'keydown', (event) => {
42
+ const key = event;
43
+ if (key.key !== 'Tab' || dialog.inert || value.node.props.mode === 'notification')
44
+ return;
45
+ const targets = [
46
+ ...dialog.querySelectorAll('input,textarea,button,select,a[href],[tabindex]'),
47
+ ].filter((element) => element.tabIndex >= 0 &&
48
+ !element.matches(':disabled') &&
49
+ !element.closest('[hidden],[inert]') &&
50
+ element.getClientRects().length > 0);
51
+ if (!targets.length) {
52
+ key.preventDefault();
53
+ dialog.focus();
54
+ return;
55
+ }
56
+ const current = targets.indexOf(document.activeElement);
57
+ key.preventDefault();
58
+ targets[(current + (key.shiftKey ? -1 : 1) + targets.length) % targets.length].focus();
59
+ });
60
+ on(dialog, 'cancel', (event) => {
61
+ event.preventDefault();
62
+ dismiss();
63
+ });
64
+ on(dialog, 'click', (event) => {
65
+ if (event.target !== dialog)
66
+ return;
67
+ const r = dialog.getBoundingClientRect(), e = event;
68
+ if (e.clientX < r.left || e.clientX > r.right || e.clientY < r.top || e.clientY > r.bottom)
69
+ dismiss();
70
+ });
71
+ on(document, 'pointerdown', (event) => {
72
+ if (!opened.has(value) ||
73
+ !top(value) ||
74
+ ['modal', 'edge'].includes(value.node.props.mode ?? 'modal') ||
75
+ value.node.props.mode === 'notification')
76
+ return;
77
+ const anchor = host.find(value.node.presentation_anchor ?? '')?.element;
78
+ if (!dialog.contains(event.target) && !anchor?.contains(event.target))
79
+ dismiss();
80
+ });
81
+ on(document, 'keydown', (event) => {
82
+ const key = event;
83
+ if (key.key === 'Escape' &&
84
+ opened.has(value) &&
85
+ top(value) &&
86
+ !['modal', 'edge'].includes(value.node.props.mode ?? 'modal')) {
87
+ key.preventDefault();
88
+ dismiss();
89
+ }
90
+ });
91
+ const reposition = () => {
92
+ if (dialog.open)
93
+ host.requestLayout();
94
+ };
95
+ on(window, 'resize', reposition);
96
+ document.addEventListener('scroll', reposition, {
97
+ capture: true,
98
+ passive: true,
99
+ signal: value.controller.signal,
100
+ });
101
+ if (window.visualViewport) {
102
+ on(window.visualViewport, 'resize', reposition);
103
+ on(window.visualViewport, 'scroll', reposition);
104
+ }
105
+ let drag;
106
+ const handle = document.createElement('div');
107
+ handle.className = 'relo-sheet-handle';
108
+ handle.tabIndex = 0;
109
+ handle.setAttribute('role', 'separator');
110
+ dialog.prepend(handle);
111
+ value.extra.sheetHandle = handle;
112
+ on(handle, 'keydown', (event) => {
113
+ const key = event, props = value.node.props;
114
+ const direction = key.key === 'ArrowUp' ? 1 : key.key === 'ArrowDown' ? -1 : 0;
115
+ if (!direction || !props.detents)
116
+ return;
117
+ key.preventDefault();
118
+ const index = Math.max(0, Math.min(props.detents.length - 1, (props.detent ?? 0) + direction));
119
+ if (index !== props.detent)
120
+ host.dispatch(value, 'detentChange', { value: index });
121
+ });
122
+ on(dialog, 'pointerdown', (event) => {
123
+ const e = event, props = value.node.props;
124
+ if (props.mode !== 'edge' || e.button !== 0 || value.extra.disabled)
125
+ return;
126
+ const target = e.target;
127
+ if (target !== handle && target !== dialog && !(target === value.childHost))
128
+ return;
129
+ if (!props.dismissible && !props.detents)
130
+ return;
131
+ const vertical = ['top', 'bottom'].includes(props.side ?? 'bottom');
132
+ const point = vertical ? e.clientY : e.clientX;
133
+ drag = {
134
+ start: point,
135
+ time: e.timeStamp,
136
+ height: dialog.getBoundingClientRect().height,
137
+ last: point,
138
+ lastTime: e.timeStamp,
139
+ speed: 0,
140
+ id: e.pointerId,
141
+ };
142
+ dialog.setPointerCapture(e.pointerId);
143
+ e.preventDefault();
144
+ });
145
+ on(dialog, 'pointermove', (event) => {
146
+ const e = event;
147
+ if (!drag || drag.id !== e.pointerId)
148
+ return;
149
+ const side = value.node.props.side ?? 'bottom', point = ['top', 'bottom'].includes(side) ? e.clientY : e.clientX;
150
+ const signed = side === 'top' || side === 'left' ? -1 : 1, distance = (point - drag.start) * signed;
151
+ drag.speed = (((point - drag.last) * signed) / Math.max(1, e.timeStamp - drag.lastTime)) * 1000;
152
+ drag.last = point;
153
+ drag.lastTime = e.timeStamp;
154
+ if (value.node.props.detents) {
155
+ dialog.style.height = `${Math.max(48, Math.min(viewport().height - 16, drag.height - distance))}px`;
156
+ host.requestLayout();
157
+ }
158
+ else
159
+ dialog.style.translate = `${side === 'left' || side === 'right' ? point - drag.start + 'px' : '0'} ${side === 'top' || side === 'bottom' ? point - drag.start + 'px' : '0'}`;
160
+ });
161
+ for (const name of ['pointerup', 'pointercancel'])
162
+ on(dialog, name, (event) => {
163
+ const e = event;
164
+ if (!drag || drag.id !== e.pointerId)
165
+ return;
166
+ const props = value.node.props, side = props.side ?? 'bottom', point = ['top', 'bottom'].includes(side) ? e.clientY : e.clientX, distance = (point - drag.start) * (side === 'top' || side === 'left' ? -1 : 1), speed = drag.speed;
167
+ if (name === 'pointerup') {
168
+ if (props.dismissible !== false &&
169
+ (props.detent ?? 0) === 0 &&
170
+ (distance > 80 || speed > 800))
171
+ dismiss();
172
+ else if (props.detents) {
173
+ const fractions = props.detents, fraction = dialog.getBoundingClientRect().height / Math.max(1, viewport().height - 16);
174
+ let index = fractions.reduce((best, next, i) => Math.abs(next - fraction) < Math.abs(fractions[best] - fraction) ? i : best, 0);
175
+ if (Math.abs(speed) > 800)
176
+ index = Math.max(0, Math.min(fractions.length - 1, (props.detent ?? 0) + (speed < 0 ? 1 : -1)));
177
+ if (index !== props.detent)
178
+ host.dispatch(value, 'detentChange', { value: index });
179
+ }
180
+ }
181
+ drag = undefined;
182
+ dialog.style.translate = '';
183
+ updatePresentation(value, host);
184
+ host.requestLayout();
185
+ });
186
+ value.extra.sheetDragging = () => !!drag;
187
+ value.controller.signal.addEventListener('abort', () => {
188
+ opened.delete(value);
189
+ cancelAnimationFrame(value.extra.initialFocus ?? 0);
190
+ if (dialog.matches(':popover-open'))
191
+ dialog.hidePopover();
192
+ if (dialog.open)
193
+ dialog.close();
194
+ });
195
+ }
196
+ export function updatePresentation(value, host) {
197
+ const props = value.node.props, dialog = value.content;
198
+ value.element.hidden = (!value.node.shown || !props.value) && !value.extra.retaining;
199
+ const wasInert = dialog.inert;
200
+ if (!value.node.shown || !props.value) {
201
+ if (dialog.contains(document.activeElement))
202
+ value.extra.popupFocus = document.activeElement;
203
+ }
204
+ dialog.inert = !value.node.shown || !props.value;
205
+ dialog.setAttribute('aria-hidden', String(dialog.inert));
206
+ if (!props.value || !value.node.shown) {
207
+ if (!value.extra.retaining)
208
+ closePresentation(value);
209
+ return;
210
+ }
211
+ dialog.hidden = false;
212
+ if (wasInert && value.extra.popupFocus?.isConnected)
213
+ queueMicrotask(() => {
214
+ if (!dialog.inert)
215
+ value.extra.popupFocus?.focus({ preventScroll: true });
216
+ });
217
+ const mode = props.mode ?? 'modal', modal = ['modal', 'edge'].includes(mode);
218
+ if (value.extra.presentationMode !== mode && dialog.open) {
219
+ if (dialog.matches(':popover-open'))
220
+ dialog.hidePopover();
221
+ dialog.close();
222
+ }
223
+ value.extra.presentationMode = mode;
224
+ Object.assign(dialog.style, {
225
+ position: 'fixed',
226
+ inset: 'auto',
227
+ boxSizing: 'border-box',
228
+ padding: '16px',
229
+ border: '1px solid #9995',
230
+ borderRadius: '12px',
231
+ background: color(value.extra.paintNode ?? value.node, 'surface', value.extra.dark),
232
+ color: color(value.extra.paintNode ?? value.node, 'foreground', value.extra.dark),
233
+ maxWidth: 'calc(100vw - 16px)',
234
+ maxHeight: 'calc(100dvh - 16px)',
235
+ overflow: 'auto',
236
+ width: `min(${mode === 'anchored' ? 320 : 512}px, calc(100vw - 32px))`,
237
+ margin: '0',
238
+ pointerEvents: 'auto',
239
+ });
240
+ if (!dialog.open && dialog.isConnected) {
241
+ value.extra.restoreFocus = host.focusOrigin();
242
+ opened.set(value, ++nextOpen);
243
+ if (modal) {
244
+ dialog.removeAttribute('popover');
245
+ dialog.showModal();
246
+ }
247
+ else {
248
+ dialog.setAttribute('popover', 'manual');
249
+ dialog.show();
250
+ dialog.showPopover();
251
+ }
252
+ if (mode !== 'notification')
253
+ value.extra.initialFocus = requestAnimationFrame(() => {
254
+ value.extra.initialFocus = requestAnimationFrame(() => {
255
+ if (!dialog.open)
256
+ return;
257
+ (dialog.querySelector('input:not([disabled]),textarea:not([disabled]),button:not([disabled]),[tabindex="0"]:not(.relo-sheet-handle)') ?? dialog).focus({ preventScroll: true });
258
+ });
259
+ });
260
+ }
261
+ const handle = value.extra.sheetHandle;
262
+ handle.hidden = mode !== 'edge';
263
+ handle.setAttribute('aria-label', `${props.label ?? 'Sheet'} size`);
264
+ handle.setAttribute('aria-orientation', 'horizontal');
265
+ handle.setAttribute('aria-valuemin', '0');
266
+ handle.setAttribute('aria-valuemax', String((props.detents?.length ?? 1) - 1));
267
+ handle.setAttribute('aria-valuenow', String(props.detent ?? 0));
268
+ positionPresentation(value, host);
269
+ }
270
+ export function positionPresentation(value, host) {
271
+ const props = value.node.props, dialog = value.content;
272
+ if (!dialog.open)
273
+ return;
274
+ const v = viewport(), pad = 8, w = dialog.getBoundingClientRect().width, h = dialog.getBoundingClientRect().height, mode = props.mode ?? 'modal', side = props.side ?? 'bottom';
275
+ let x = v.left + (v.width - w) / 2, y = v.top + (v.height - h) / 2;
276
+ if (mode === 'edge' || mode === 'notification') {
277
+ if (side === 'bottom')
278
+ y = v.top + v.height - h - pad;
279
+ else if (side === 'top')
280
+ y = v.top + pad;
281
+ else {
282
+ x = side === 'left' ? v.left + pad : v.left + v.width - w - pad;
283
+ y = v.top + pad;
284
+ }
285
+ }
286
+ else if (mode === 'anchored') {
287
+ const r = host.find(value.node.presentation_anchor ?? '')?.element.getBoundingClientRect();
288
+ if (r) {
289
+ x = r.left;
290
+ y = r.bottom + 8;
291
+ if (side === 'top')
292
+ y = r.top - h - 8;
293
+ else if (side === 'left') {
294
+ x = r.left - w - 8;
295
+ y = r.top;
296
+ }
297
+ else if (side === 'right') {
298
+ x = r.right + 8;
299
+ y = r.top;
300
+ }
301
+ if (y + h > v.top + v.height - pad)
302
+ y = r.top - h - 8;
303
+ if (y < v.top + pad)
304
+ y = r.bottom + 8;
305
+ if (x + w > v.left + v.width - pad && side === 'right')
306
+ x = r.left - w - 8;
307
+ else if (x < v.left + pad && side === 'left')
308
+ x = r.right + 8;
309
+ }
310
+ }
311
+ dialog.style.left = `${Math.max(v.left + pad, Math.min(v.left + v.width - w - pad, x))}px`;
312
+ dialog.style.top = `${Math.max(v.top + pad, Math.min(v.top + v.height - h - pad, y))}px`;
313
+ }
314
+ export function presentationSize(value) {
315
+ const props = value.node.props, v = viewport(), dialog = value.content;
316
+ if (props.mode === 'edge') {
317
+ const side = props.side ?? 'bottom', vertical = ['top', 'bottom'].includes(side);
318
+ dialog.style.width = vertical ? `${v.width - 16}px` : `${Math.min(320, v.width * 0.85)}px`;
319
+ if (!value.extra.sheetDragging())
320
+ dialog.style.height = vertical
321
+ ? `${(props.detents?.[props.detent ?? 0] ?? 0.7) * (v.height - 16)}px`
322
+ : `${v.height - 16}px`;
323
+ }
324
+ return { width: Math.max(0, dialog.clientWidth - 32), height: Math.max(0, v.height - 16) };
325
+ }
326
+ export const presentationCSS = `
327
+ .relo-surface .relo-popup::backdrop{background:rgb(0 0 0 / .1)}
328
+ .relo-surface .relo-sheet-handle{position:absolute;top:2px;left:calc(50% - 24px);width:48px;height:12px;cursor:ns-resize;touch-action:none;border-radius:8px}
329
+ .relo-surface .relo-sheet-handle::after{content:'';position:absolute;left:10px;right:10px;top:4px;height:4px;background:currentColor;opacity:.3;border-radius:2px}
330
+ .relo-surface .relo-sheet-handle[hidden]{display:none}
331
+ `;
@@ -0,0 +1,16 @@
1
+ import { type JsonValue } from '../core/value.js';
2
+ import type { Mounted } from './renderer.js';
3
+ export interface PrimitiveHost {
4
+ dispatch(value: Mounted, event: string, payload?: JsonValue): void;
5
+ requestLayout(): void;
6
+ viewportChanged(): void;
7
+ focusOrigin(): Element | null;
8
+ refresh(): void;
9
+ find(id: string): Mounted | undefined;
10
+ }
11
+ export declare function visible(value: Mounted): boolean;
12
+ export declare function selected(value: Mounted): boolean;
13
+ export declare function activate(value: Mounted, host: PrimitiveHost): void;
14
+ export declare function coordinateSelection(value: Mounted, host: PrimitiveHost): void;
15
+ export declare function initializeAdvanced(value: Mounted, host: PrimitiveHost): boolean;
16
+ export declare function updateAdvanced(value: Mounted, host: PrimitiveHost): void;