@mun-ui/react 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/dist/advanced.d.ts +7 -0
- package/dist/advanced.d.ts.map +1 -0
- package/dist/advanced.js +6 -0
- package/dist/advanced.js.map +1 -0
- package/dist/continuous-corners.d.ts +4 -0
- package/dist/continuous-corners.d.ts.map +1 -0
- package/dist/continuous-corners.js +54 -0
- package/dist/continuous-corners.js.map +1 -0
- package/dist/controls.d.ts +7 -0
- package/dist/controls.d.ts.map +1 -0
- package/dist/controls.js +6 -0
- package/dist/controls.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/interop.d.ts +23 -0
- package/dist/interop.d.ts.map +1 -0
- package/dist/interop.js +75 -0
- package/dist/interop.js.map +1 -0
- package/dist/legacy/builder.d.ts +6 -0
- package/dist/legacy/builder.d.ts.map +1 -0
- package/dist/legacy/builder.js +13 -0
- package/dist/legacy/builder.js.map +1 -0
- package/dist/legacy/closures.d.ts +3 -0
- package/dist/legacy/closures.d.ts.map +1 -0
- package/dist/legacy/closures.js +3 -0
- package/dist/legacy/closures.js.map +1 -0
- package/dist/legacy/collections.d.ts +53 -0
- package/dist/legacy/collections.d.ts.map +1 -0
- package/dist/legacy/collections.js +154 -0
- package/dist/legacy/collections.js.map +1 -0
- package/dist/legacy/compiler/ast.d.ts +84 -0
- package/dist/legacy/compiler/ast.d.ts.map +1 -0
- package/dist/legacy/compiler/ast.js +697 -0
- package/dist/legacy/compiler/ast.js.map +1 -0
- package/dist/legacy/compiler/builder-transform.d.ts +2 -0
- package/dist/legacy/compiler/builder-transform.d.ts.map +1 -0
- package/dist/legacy/compiler/builder-transform.js +422 -0
- package/dist/legacy/compiler/builder-transform.js.map +1 -0
- package/dist/legacy/compiler/errors.d.ts +5 -0
- package/dist/legacy/compiler/errors.d.ts.map +1 -0
- package/dist/legacy/compiler/errors.js +7 -0
- package/dist/legacy/compiler/errors.js.map +1 -0
- package/dist/legacy/compiler/index.d.ts +15 -0
- package/dist/legacy/compiler/index.d.ts.map +1 -0
- package/dist/legacy/compiler/index.js +10 -0
- package/dist/legacy/compiler/index.js.map +1 -0
- package/dist/legacy/compiler/language-service.d.ts +26 -0
- package/dist/legacy/compiler/language-service.d.ts.map +1 -0
- package/dist/legacy/compiler/language-service.js +35 -0
- package/dist/legacy/compiler/language-service.js.map +1 -0
- package/dist/legacy/compiler/language-tools.d.ts +12 -0
- package/dist/legacy/compiler/language-tools.d.ts.map +1 -0
- package/dist/legacy/compiler/language-tools.js +44 -0
- package/dist/legacy/compiler/language-tools.js.map +1 -0
- package/dist/legacy/compiler/source-map.d.ts +36 -0
- package/dist/legacy/compiler/source-map.d.ts.map +1 -0
- package/dist/legacy/compiler/source-map.js +188 -0
- package/dist/legacy/compiler/source-map.js.map +1 -0
- package/dist/legacy/compiler/struct-transform.d.ts +18 -0
- package/dist/legacy/compiler/struct-transform.d.ts.map +1 -0
- package/dist/legacy/compiler/struct-transform.js +268 -0
- package/dist/legacy/compiler/struct-transform.js.map +1 -0
- package/dist/legacy/compiler/swc-transform.d.ts +7 -0
- package/dist/legacy/compiler/swc-transform.d.ts.map +1 -0
- package/dist/legacy/compiler/swc-transform.js +33 -0
- package/dist/legacy/compiler/swc-transform.js.map +1 -0
- package/dist/legacy/compiler/typescript-language-service.d.ts +12 -0
- package/dist/legacy/compiler/typescript-language-service.d.ts.map +1 -0
- package/dist/legacy/compiler/typescript-language-service.js +185 -0
- package/dist/legacy/compiler/typescript-language-service.js.map +1 -0
- package/dist/legacy/compiler/vite-builder.d.ts +11 -0
- package/dist/legacy/compiler/vite-builder.d.ts.map +1 -0
- package/dist/legacy/compiler/vite-builder.js +40 -0
- package/dist/legacy/compiler/vite-builder.js.map +1 -0
- package/dist/legacy/controls.d.ts +59 -0
- package/dist/legacy/controls.d.ts.map +1 -0
- package/dist/legacy/controls.js +119 -0
- package/dist/legacy/controls.js.map +1 -0
- package/dist/legacy/coordinate.d.ts +17 -0
- package/dist/legacy/coordinate.d.ts.map +1 -0
- package/dist/legacy/coordinate.js +17 -0
- package/dist/legacy/coordinate.js.map +1 -0
- package/dist/legacy/elements.d.ts +98 -0
- package/dist/legacy/elements.d.ts.map +1 -0
- package/dist/legacy/elements.js +367 -0
- package/dist/legacy/elements.js.map +1 -0
- package/dist/legacy/experimental.d.ts +19 -0
- package/dist/legacy/experimental.d.ts.map +1 -0
- package/dist/legacy/experimental.js +16 -0
- package/dist/legacy/experimental.js.map +1 -0
- package/dist/legacy/index.d.ts +27 -0
- package/dist/legacy/index.d.ts.map +1 -0
- package/dist/legacy/index.js +13 -0
- package/dist/legacy/index.js.map +1 -0
- package/dist/legacy/jsx-dev-runtime.d.ts +3 -0
- package/dist/legacy/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/legacy/jsx-dev-runtime.js +2 -0
- package/dist/legacy/jsx-dev-runtime.js.map +1 -0
- package/dist/legacy/jsx-runtime.d.ts +61 -0
- package/dist/legacy/jsx-runtime.d.ts.map +1 -0
- package/dist/legacy/jsx-runtime.js +56 -0
- package/dist/legacy/jsx-runtime.js.map +1 -0
- package/dist/legacy/layout-engine.d.ts +15 -0
- package/dist/legacy/layout-engine.d.ts.map +1 -0
- package/dist/legacy/layout-engine.js +11 -0
- package/dist/legacy/layout-engine.js.map +1 -0
- package/dist/legacy/layout.d.ts +19 -0
- package/dist/legacy/layout.d.ts.map +1 -0
- package/dist/legacy/layout.js +102 -0
- package/dist/legacy/layout.js.map +1 -0
- package/dist/legacy/modifiers.d.ts +12 -0
- package/dist/legacy/modifiers.d.ts.map +1 -0
- package/dist/legacy/modifiers.js +242 -0
- package/dist/legacy/modifiers.js.map +1 -0
- package/dist/legacy/presentation.d.ts +40 -0
- package/dist/legacy/presentation.d.ts.map +1 -0
- package/dist/legacy/presentation.js +449 -0
- package/dist/legacy/presentation.js.map +1 -0
- package/dist/legacy/react-types.d.ts +9 -0
- package/dist/legacy/react-types.d.ts.map +1 -0
- package/dist/legacy/react-types.js +2 -0
- package/dist/legacy/react-types.js.map +1 -0
- package/dist/legacy/runtime/arrays.d.ts +5 -0
- package/dist/legacy/runtime/arrays.d.ts.map +1 -0
- package/dist/legacy/runtime/arrays.js +27 -0
- package/dist/legacy/runtime/arrays.js.map +1 -0
- package/dist/legacy/runtime/coordinate-runtime.d.ts +10 -0
- package/dist/legacy/runtime/coordinate-runtime.d.ts.map +1 -0
- package/dist/legacy/runtime/coordinate-runtime.js +7 -0
- package/dist/legacy/runtime/coordinate-runtime.js.map +1 -0
- package/dist/legacy/runtime/jsx-node.d.ts +9 -0
- package/dist/legacy/runtime/jsx-node.d.ts.map +1 -0
- package/dist/legacy/runtime/jsx-node.js +10 -0
- package/dist/legacy/runtime/jsx-node.js.map +1 -0
- package/dist/legacy/runtime/layout-observer.d.ts +4 -0
- package/dist/legacy/runtime/layout-observer.d.ts.map +1 -0
- package/dist/legacy/runtime/layout-observer.js +22 -0
- package/dist/legacy/runtime/layout-observer.js.map +1 -0
- package/dist/legacy/runtime/modifier-pipeline.d.ts +10 -0
- package/dist/legacy/runtime/modifier-pipeline.d.ts.map +1 -0
- package/dist/legacy/runtime/modifier-pipeline.js +17 -0
- package/dist/legacy/runtime/modifier-pipeline.js.map +1 -0
- package/dist/legacy/runtime/renderer.d.ts +24 -0
- package/dist/legacy/runtime/renderer.d.ts.map +1 -0
- package/dist/legacy/runtime/renderer.js +94 -0
- package/dist/legacy/runtime/renderer.js.map +1 -0
- package/dist/legacy/runtime/view-graph.d.ts +22 -0
- package/dist/legacy/runtime/view-graph.d.ts.map +1 -0
- package/dist/legacy/runtime/view-graph.js +70 -0
- package/dist/legacy/runtime/view-graph.js.map +1 -0
- package/dist/legacy/runtime/view-storage.d.ts +14 -0
- package/dist/legacy/runtime/view-storage.d.ts.map +1 -0
- package/dist/legacy/runtime/view-storage.js +15 -0
- package/dist/legacy/runtime/view-storage.js.map +1 -0
- package/dist/legacy/state.d.ts +8 -0
- package/dist/legacy/state.d.ts.map +1 -0
- package/dist/legacy/state.js +23 -0
- package/dist/legacy/state.js.map +1 -0
- package/dist/legacy/types.d.ts +111 -0
- package/dist/legacy/types.d.ts.map +1 -0
- package/dist/legacy/types.js +2 -0
- package/dist/legacy/types.js.map +1 -0
- package/dist/legacy/view-system.d.ts +111 -0
- package/dist/legacy/view-system.d.ts.map +1 -0
- package/dist/legacy/view-system.js +421 -0
- package/dist/legacy/view-system.js.map +1 -0
- package/dist/legacy/view.d.ts +15 -0
- package/dist/legacy/view.d.ts.map +1 -0
- package/dist/legacy/view.js +30 -0
- package/dist/legacy/view.js.map +1 -0
- package/dist/legacy/vite.d.ts +32 -0
- package/dist/legacy/vite.d.ts.map +1 -0
- package/dist/legacy/vite.js +540 -0
- package/dist/legacy/vite.js.map +1 -0
- package/dist/presentation.d.ts +7 -0
- package/dist/presentation.d.ts.map +1 -0
- package/dist/presentation.js +6 -0
- package/dist/presentation.js.map +1 -0
- package/dist/renderer.d.ts +34 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +1513 -0
- package/dist/renderer.js.map +1 -0
- package/dist/views.d.ts +7 -0
- package/dist/views.d.ts.map +1 -0
- package/dist/views.js +6 -0
- package/dist/views.js.map +1 -0
- package/package.json +79 -3
- package/README.md +0 -3
package/dist/renderer.js
ADDED
|
@@ -0,0 +1,1513 @@
|
|
|
1
|
+
import { Fragment, cloneElement, createElement, forwardRef, useEffect, useMemo, useRef, useState, useSyncExternalStore, } from "react";
|
|
2
|
+
import { createRoot, hydrateRoot } from "react-dom/client";
|
|
3
|
+
import { animationCSSStyle, Animation, collectStateReads, currentRenderTransaction, classNameOf, edgeInsetsFromCss, frameStyle, isForeignComponent, isStateRef, layoutLength, renderViewNode, stateTransaction, stateVersion, subscribeState, swiftUIAnimatableModifierNames, viewIdentityKey, withRenderTransaction, zeroGeometry, } from "@mun-ui/core/compat";
|
|
4
|
+
import { ignoresSafeAreaStyle, paddingStyle, safeAreaPaddingStyle } from "@mun-ui/core/internal/runtime";
|
|
5
|
+
import { keyedCollectionEntryKey, keyedCollectionEntries, reactiveIdentity, } from "@mun-ui/core/internal/runtime";
|
|
6
|
+
import { APPLE_CONTINUOUS_CORNER_SMOOTHING } from "@mun-ui/core/corners";
|
|
7
|
+
import { attachContinuousCorners, disposeContinuousCorners, isContinuousCornerStyle } from "./continuous-corners.js";
|
|
8
|
+
function setForwardedRef(reference, value) {
|
|
9
|
+
if (typeof reference === "function") {
|
|
10
|
+
reference(value);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (!reference || typeof reference !== "object")
|
|
14
|
+
return;
|
|
15
|
+
try {
|
|
16
|
+
const target = reference;
|
|
17
|
+
target.current = value;
|
|
18
|
+
}
|
|
19
|
+
catch { /* readonly or hostile refs are ignored */ }
|
|
20
|
+
}
|
|
21
|
+
function runReactParticleFallback(canvas, node) {
|
|
22
|
+
const context = canvas.getContext("2d");
|
|
23
|
+
if (!context)
|
|
24
|
+
return () => undefined;
|
|
25
|
+
const count = node.ir.render.vertexCount;
|
|
26
|
+
const data = node.options.initialData ? new Float32Array(node.options.initialData) : new Float32Array(count * 8);
|
|
27
|
+
if (!node.options.initialData)
|
|
28
|
+
for (let index = 0; index < count; index += 1) {
|
|
29
|
+
const offset = index * 8;
|
|
30
|
+
data[offset] = ((index * 37) % Math.max(1, count)) / Math.max(1, count - 1) * 2 - 1;
|
|
31
|
+
data[offset + 1] = ((index * 53) % Math.max(1, count)) / Math.max(1, count - 1) * 2 - 1;
|
|
32
|
+
data[offset + 2] = (((index * 17) % 31) - 15) / 150;
|
|
33
|
+
data[offset + 3] = (((index * 23) % 29) - 14) / 150;
|
|
34
|
+
data[offset + 4] = 0.7;
|
|
35
|
+
data[offset + 5] = 0.8;
|
|
36
|
+
data[offset + 6] = 1;
|
|
37
|
+
data[offset + 7] = 1;
|
|
38
|
+
}
|
|
39
|
+
let request = 0;
|
|
40
|
+
let stopped = false;
|
|
41
|
+
const draw = () => {
|
|
42
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
43
|
+
for (let index = 0; index < count; index += 1) {
|
|
44
|
+
const offset = index * 8;
|
|
45
|
+
context.fillStyle = `rgba(${data[offset + 4] * 255},${data[offset + 5] * 255},${data[offset + 6] * 255},${data[offset + 7]})`;
|
|
46
|
+
context.fillRect((data[offset] + 1) * canvas.width / 2, (1 - data[offset + 1]) * canvas.height / 2, 2, 2);
|
|
47
|
+
if (node.ir.fallback === "canvas") {
|
|
48
|
+
data[offset] = Math.max(-1, Math.min(1, data[offset] + data[offset + 2]));
|
|
49
|
+
data[offset + 1] = Math.max(-1, Math.min(1, data[offset + 1] + data[offset + 3]));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (!stopped && node.ir.fallback === "canvas")
|
|
53
|
+
request = requestAnimationFrame(draw);
|
|
54
|
+
};
|
|
55
|
+
draw();
|
|
56
|
+
return () => { stopped = true; if (request)
|
|
57
|
+
cancelAnimationFrame(request); };
|
|
58
|
+
}
|
|
59
|
+
function ReactGPUIslandCanvas({ node }) {
|
|
60
|
+
const canvas = useRef(null);
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (!canvas.current)
|
|
63
|
+
return;
|
|
64
|
+
canvas.current.dataset.munGpuBackend = node.ir.fallback === "canvas" ? "cpu-canvas" : "static";
|
|
65
|
+
return runReactParticleFallback(canvas.current, node);
|
|
66
|
+
}, [node]);
|
|
67
|
+
return createElement("canvas", {
|
|
68
|
+
ref: canvas,
|
|
69
|
+
width: node.options.width,
|
|
70
|
+
height: node.options.height,
|
|
71
|
+
className: node.options.class,
|
|
72
|
+
style: node.options.style,
|
|
73
|
+
"aria-label": node.options.ariaLabel,
|
|
74
|
+
"data-mun-gpu-island": node.ir.id,
|
|
75
|
+
"data-mun-gpu-kind": node.ir.kind,
|
|
76
|
+
"data-mun-gpu-owner": "react",
|
|
77
|
+
"data-mun-gpu-readback": "forbidden",
|
|
78
|
+
"data-mun-gpu-fallback": node.ir.fallback,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const ContinuousCornerHost = forwardRef(function ContinuousCornerHost(input, forwardedRef) {
|
|
82
|
+
const { as, children, ...hostProps } = input;
|
|
83
|
+
const host = useRef(null);
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
setForwardedRef(forwardedRef, host.current);
|
|
86
|
+
return () => setForwardedRef(forwardedRef, null);
|
|
87
|
+
}, [forwardedRef]);
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
const element = host.current;
|
|
90
|
+
if (!element)
|
|
91
|
+
return;
|
|
92
|
+
attachContinuousCorners(element);
|
|
93
|
+
return () => disposeContinuousCorners(element);
|
|
94
|
+
}, [hostProps.style]);
|
|
95
|
+
return createElement(as, { ...hostProps, ref: host }, children);
|
|
96
|
+
});
|
|
97
|
+
function alignmentCSSPosition(value, fallback = "center") {
|
|
98
|
+
switch (value) {
|
|
99
|
+
case "leading": return "left center";
|
|
100
|
+
case "trailing": return "right center";
|
|
101
|
+
case "top": return "center top";
|
|
102
|
+
case "bottom": return "center bottom";
|
|
103
|
+
case "topLeading": return "left top";
|
|
104
|
+
case "topTrailing": return "right top";
|
|
105
|
+
case "bottomLeading": return "left bottom";
|
|
106
|
+
case "bottomTrailing": return "right bottom";
|
|
107
|
+
case "center": return "center";
|
|
108
|
+
default: return fallback;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function alignmentCSSPlace(value, fallback = "center") {
|
|
112
|
+
switch (value) {
|
|
113
|
+
case "leading": return "center start";
|
|
114
|
+
case "trailing": return "center end";
|
|
115
|
+
case "top": return "start center";
|
|
116
|
+
case "bottom": return "end center";
|
|
117
|
+
case "topLeading": return "start start";
|
|
118
|
+
case "topTrailing": return "start end";
|
|
119
|
+
case "bottomLeading": return "end start";
|
|
120
|
+
case "bottomTrailing": return "end end";
|
|
121
|
+
default: return fallback;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const filterTemplate = "blur(var(--mun-blur,0px)) brightness(var(--mun-brightness,1)) contrast(var(--mun-contrast,1)) saturate(var(--mun-saturation,1)) grayscale(var(--mun-grayscale,0)) hue-rotate(var(--mun-hue-rotation,0deg)) invert(var(--mun-color-invert,0))";
|
|
125
|
+
const finite = (value, fallback) => typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
126
|
+
const fontWeights = Object.freeze({ ultraLight: 100, thin: 200, light: 300, regular: 400, medium: 500, semibold: 600, bold: 700, heavy: 800, black: 900 });
|
|
127
|
+
const longPresses = new WeakMap();
|
|
128
|
+
const longPressFallbackKey = {};
|
|
129
|
+
function longPressProps(modifier) {
|
|
130
|
+
const duration = Math.max(0, finite(modifier.arguments[0], 0.5)) * 1000;
|
|
131
|
+
const distance = Math.max(0, finite(modifier.arguments[1], 10));
|
|
132
|
+
const action = modifier.arguments[2];
|
|
133
|
+
const changed = modifier.arguments[3];
|
|
134
|
+
if (typeof action !== "function")
|
|
135
|
+
return {};
|
|
136
|
+
const pressOf = (event) => {
|
|
137
|
+
const element = event?.currentTarget;
|
|
138
|
+
const key = (element && typeof element === "object" ? element : longPressFallbackKey);
|
|
139
|
+
let press = longPresses.get(key);
|
|
140
|
+
if (!press)
|
|
141
|
+
longPresses.set(key, press = { originX: 0, originY: 0, active: false, recognized: false });
|
|
142
|
+
press.changed = changed;
|
|
143
|
+
return press;
|
|
144
|
+
};
|
|
145
|
+
const clear = (press) => {
|
|
146
|
+
if (press.timer !== undefined)
|
|
147
|
+
clearTimeout(press.timer);
|
|
148
|
+
press.timer = undefined;
|
|
149
|
+
if (press.active && typeof press.changed === "function")
|
|
150
|
+
press.changed(false);
|
|
151
|
+
press.active = false;
|
|
152
|
+
};
|
|
153
|
+
const cancel = (event) => clear(pressOf(event));
|
|
154
|
+
return {
|
|
155
|
+
onPointerDown(event) {
|
|
156
|
+
const press = pressOf(event);
|
|
157
|
+
clear(press);
|
|
158
|
+
press.active = true;
|
|
159
|
+
press.recognized = false;
|
|
160
|
+
press.originX = finite(event?.clientX, 0);
|
|
161
|
+
press.originY = finite(event?.clientY, 0);
|
|
162
|
+
if (typeof changed === "function")
|
|
163
|
+
changed(true);
|
|
164
|
+
press.timer = setTimeout(() => { press.timer = undefined; press.recognized = true; action(); }, duration);
|
|
165
|
+
},
|
|
166
|
+
// The click that follows a recognized long press is not also a tap.
|
|
167
|
+
onClickCapture(event) {
|
|
168
|
+
const press = pressOf(event);
|
|
169
|
+
if (!press.recognized)
|
|
170
|
+
return;
|
|
171
|
+
press.recognized = false;
|
|
172
|
+
event?.stopPropagation?.();
|
|
173
|
+
event?.preventDefault?.();
|
|
174
|
+
},
|
|
175
|
+
onPointerMove(event) {
|
|
176
|
+
const press = pressOf(event);
|
|
177
|
+
if (!press.active)
|
|
178
|
+
return;
|
|
179
|
+
if (Math.hypot(finite(event?.clientX, press.originX) - press.originX, finite(event?.clientY, press.originY) - press.originY) > distance)
|
|
180
|
+
clear(press);
|
|
181
|
+
},
|
|
182
|
+
onPointerUp: cancel,
|
|
183
|
+
onPointerCancel: cancel,
|
|
184
|
+
onPointerLeave: cancel,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/** Return in a bare single-line field is SwiftUI's submit trigger; browsers only submit inputs owned by a form. */
|
|
188
|
+
function submitKeyDown(submit) {
|
|
189
|
+
return (event) => {
|
|
190
|
+
if (event?.key !== "Enter" || event.isComposing || event.defaultPrevented || event.shiftKey || event.altKey || event.ctrlKey || event.metaKey)
|
|
191
|
+
return;
|
|
192
|
+
const target = event.target;
|
|
193
|
+
if (target?.localName !== "input" || target.form)
|
|
194
|
+
return;
|
|
195
|
+
if (/^(?:button|submit|reset|checkbox|radio|file|image|color|range)$/.test(String(target.type ?? "text")))
|
|
196
|
+
return;
|
|
197
|
+
submit();
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function modifierProps(modifier) {
|
|
201
|
+
const [value] = modifier.arguments;
|
|
202
|
+
let result;
|
|
203
|
+
switch (modifier.name) {
|
|
204
|
+
case "padding":
|
|
205
|
+
result = { style: paddingStyle(value, modifier.arguments[1]) };
|
|
206
|
+
break;
|
|
207
|
+
case "margin":
|
|
208
|
+
result = { style: { margin: layoutLength(value) } };
|
|
209
|
+
break;
|
|
210
|
+
case "gap":
|
|
211
|
+
result = { style: { gap: layoutLength(value) } };
|
|
212
|
+
break;
|
|
213
|
+
case "font":
|
|
214
|
+
result = { style: { font: value } };
|
|
215
|
+
break;
|
|
216
|
+
case "fontSize":
|
|
217
|
+
result = { style: { fontSize: layoutLength(value) } };
|
|
218
|
+
break;
|
|
219
|
+
case "bold":
|
|
220
|
+
result = { style: { fontWeight: value === false ? "normal" : 700 } };
|
|
221
|
+
break;
|
|
222
|
+
case "fontWeight":
|
|
223
|
+
result = { style: { fontWeight: typeof value === "number" ? value : typeof value === "string" ? fontWeights[value] ?? value : undefined } };
|
|
224
|
+
break;
|
|
225
|
+
case "fontDesign":
|
|
226
|
+
result = { style: { fontFamily: value === "serif" ? "ui-serif, Georgia, serif" : value === "rounded" ? "ui-rounded, system-ui, sans-serif" : value === "monospaced" ? "ui-monospace, SFMono-Regular, Menlo, monospace" : value === "default" ? "system-ui, -apple-system, sans-serif" : undefined } };
|
|
227
|
+
break;
|
|
228
|
+
case "fontWidth":
|
|
229
|
+
result = { style: { fontStretch: value === "compressed" ? "50%" : value === "condensed" ? "75%" : value === "expanded" ? "125%" : "100%" } };
|
|
230
|
+
break;
|
|
231
|
+
case "italic":
|
|
232
|
+
result = { style: { fontStyle: value === false ? "normal" : "italic" } };
|
|
233
|
+
break;
|
|
234
|
+
case "underline":
|
|
235
|
+
result = { style: value === false ? { textDecorationLine: "none" } : { textDecorationLine: "underline", textDecorationStyle: modifier.arguments[1] ?? "solid", textDecorationColor: modifier.arguments[2] ?? undefined } };
|
|
236
|
+
break;
|
|
237
|
+
case "strikethrough":
|
|
238
|
+
result = { style: value === false ? { textDecorationLine: "none" } : { textDecorationLine: "line-through", textDecorationStyle: modifier.arguments[1] ?? "solid", textDecorationColor: modifier.arguments[2] ?? undefined } };
|
|
239
|
+
break;
|
|
240
|
+
case "monospaced":
|
|
241
|
+
result = { style: value === false ? {} : { fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace" } };
|
|
242
|
+
break;
|
|
243
|
+
case "monospacedDigit":
|
|
244
|
+
result = { style: { fontVariantNumeric: "tabular-nums" } };
|
|
245
|
+
break;
|
|
246
|
+
case "kerning":
|
|
247
|
+
case "tracking":
|
|
248
|
+
result = { style: { letterSpacing: `${finite(value, 0)}px` } };
|
|
249
|
+
break;
|
|
250
|
+
case "baselineOffset":
|
|
251
|
+
result = { style: { position: "relative", top: `${-finite(value, 0)}px` } };
|
|
252
|
+
break;
|
|
253
|
+
case "lineSpacing":
|
|
254
|
+
result = { style: { lineHeight: `calc(1em + ${finite(value, 0)}px)` } };
|
|
255
|
+
break;
|
|
256
|
+
case "lineLimit": {
|
|
257
|
+
const lines = typeof value === "number" && value > 0 ? Math.floor(value) : undefined;
|
|
258
|
+
result = { style: lines ? { display: "-webkit-box", WebkitBoxOrient: "vertical", WebkitLineClamp: lines, overflow: "hidden", minHeight: modifier.arguments[1] ? `${lines}lh` : "min-content" } : { WebkitLineClamp: "unset" } };
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
case "minimumScaleFactor":
|
|
262
|
+
result = { style: { "--mun-minimum-scale-factor": Math.max(0, Math.min(1, finite(value, 1))) } };
|
|
263
|
+
break;
|
|
264
|
+
case "multilineTextAlignment":
|
|
265
|
+
result = { style: { textAlign: value === "leading" ? "start" : value === "trailing" ? "end" : "center" } };
|
|
266
|
+
break;
|
|
267
|
+
case "truncationMode":
|
|
268
|
+
result = { style: { textOverflow: "ellipsis", overflow: "hidden", whiteSpace: "nowrap", direction: value === "head" ? "rtl" : undefined } };
|
|
269
|
+
break;
|
|
270
|
+
case "textCase":
|
|
271
|
+
result = { style: { textTransform: value === "uppercase" ? "uppercase" : value === "lowercase" ? "lowercase" : "none" } };
|
|
272
|
+
break;
|
|
273
|
+
case "allowsTightening":
|
|
274
|
+
result = { style: { "--mun-allows-tightening": value === false ? 0 : 1 } };
|
|
275
|
+
break;
|
|
276
|
+
case "foreground":
|
|
277
|
+
case "foregroundStyle":
|
|
278
|
+
result = { style: { color: value } };
|
|
279
|
+
break;
|
|
280
|
+
case "background":
|
|
281
|
+
result = { style: { background: value, backgroundPosition: alignmentCSSPosition(modifier.arguments[1]) } };
|
|
282
|
+
break;
|
|
283
|
+
case "opacity": {
|
|
284
|
+
const opacity = typeof value === "number" && Number.isFinite(value) ? Math.max(0, Math.min(1, value)) : 1;
|
|
285
|
+
result = { style: { opacity } };
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
case "scaleEffect": {
|
|
289
|
+
const scale = typeof value === "number" ? `${value}`
|
|
290
|
+
: value && typeof value === "object" ? `${Number(value.x ?? value.width ?? 1)} ${Number(value.y ?? value.height ?? 1)}` : "1";
|
|
291
|
+
result = { style: { scale, transformOrigin: alignmentCSSPosition(modifier.arguments[1]) } };
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
case "rotationEffect":
|
|
295
|
+
result = { style: {
|
|
296
|
+
rotate: `${typeof value === "number" && Number.isFinite(value) ? value : 0}deg`,
|
|
297
|
+
transformOrigin: alignmentCSSPosition(modifier.arguments[1]),
|
|
298
|
+
} };
|
|
299
|
+
break;
|
|
300
|
+
case "offset": {
|
|
301
|
+
const second = modifier.arguments[1];
|
|
302
|
+
let x = 0;
|
|
303
|
+
let y = 0;
|
|
304
|
+
if (typeof value === "number") {
|
|
305
|
+
x = value;
|
|
306
|
+
y = typeof second === "number" ? second : 0;
|
|
307
|
+
}
|
|
308
|
+
else if (value && typeof value === "object") {
|
|
309
|
+
const point = value;
|
|
310
|
+
x = Number(point.x ?? point.width ?? 0);
|
|
311
|
+
y = Number(point.y ?? point.height ?? 0);
|
|
312
|
+
}
|
|
313
|
+
result = { style: { translate: `${Number.isFinite(x) ? x : 0}px ${Number.isFinite(y) ? y : 0}px` } };
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
case "aspectRatio": {
|
|
317
|
+
const ratio = typeof value === "number" && value > 0 ? value : value && typeof value === "object" ? finite(value.width, 0) / Math.max(finite(value.height, 0), Number.EPSILON) : undefined;
|
|
318
|
+
result = { style: { aspectRatio: ratio, objectFit: modifier.arguments[1] === "fill" ? "cover" : "contain" } };
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
case "scaledToFit":
|
|
322
|
+
result = { style: { objectFit: "contain", maxWidth: "100%", maxHeight: "100%" } };
|
|
323
|
+
break;
|
|
324
|
+
case "scaledToFill":
|
|
325
|
+
result = { style: { objectFit: "cover", width: "100%", height: "100%" } };
|
|
326
|
+
break;
|
|
327
|
+
case "fixedSize":
|
|
328
|
+
result = { style: { width: value !== false ? "max-content" : undefined, height: modifier.arguments[1] !== false ? "max-content" : undefined } };
|
|
329
|
+
break;
|
|
330
|
+
case "layoutPriority":
|
|
331
|
+
result = { style: { flexShrink: finite(value, 0) > 0 ? 0 : 1, "--mun-layout-priority": finite(value, 0) } };
|
|
332
|
+
break;
|
|
333
|
+
case "position": {
|
|
334
|
+
const x = typeof value === "number" ? value : finite(value?.x, 0);
|
|
335
|
+
const y = typeof value === "number" ? finite(modifier.arguments[1], 0) : finite(value?.y, 0);
|
|
336
|
+
result = { style: { position: "absolute", left: `${x}px`, top: `${y}px`, transform: "translate(-50%, -50%)" } };
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
case "zIndex":
|
|
340
|
+
result = { style: { zIndex: finite(value, 0) } };
|
|
341
|
+
break;
|
|
342
|
+
case "ignoresSafeArea":
|
|
343
|
+
result = { style: ignoresSafeAreaStyle(modifier.arguments[1]) };
|
|
344
|
+
break;
|
|
345
|
+
case "safeAreaPadding":
|
|
346
|
+
result = { style: safeAreaPaddingStyle(value, modifier.arguments[1]) };
|
|
347
|
+
break;
|
|
348
|
+
case "gridCellColumns":
|
|
349
|
+
result = { style: { gridColumn: `span ${Math.max(1, Math.floor(finite(value, 1)))}` } };
|
|
350
|
+
break;
|
|
351
|
+
case "gridCellUnsizedAxes":
|
|
352
|
+
result = { style: { minWidth: value === "horizontal" || value === "all" ? 0 : undefined, minHeight: value === "vertical" || value === "all" ? 0 : undefined } };
|
|
353
|
+
break;
|
|
354
|
+
case "gridCellAnchor":
|
|
355
|
+
result = { style: { placeSelf: alignmentCSSPlace(value) } };
|
|
356
|
+
break;
|
|
357
|
+
case "gridColumnAlignment":
|
|
358
|
+
result = { style: { justifySelf: value === "leading" ? "start" : value === "trailing" ? "end" : "center" } };
|
|
359
|
+
break;
|
|
360
|
+
case "transformEffect": {
|
|
361
|
+
const t = value && typeof value === "object" ? value : {};
|
|
362
|
+
result = { style: { transform: `matrix(${finite(t.a, 1)}, ${finite(t.b, 0)}, ${finite(t.c, 0)}, ${finite(t.d, 1)}, ${finite(t.tx, 0)}, ${finite(t.ty, 0)})` } };
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
case "projectionEffect":
|
|
366
|
+
result = { style: { transform: typeof value === "string" ? value : Array.isArray(value) && value.length === 16 ? `matrix3d(${value.map(item => finite(item, 0)).join(",")})` : undefined } };
|
|
367
|
+
break;
|
|
368
|
+
case "rotation3DEffect": {
|
|
369
|
+
const axis = modifier.arguments[1] && typeof modifier.arguments[1] === "object" ? modifier.arguments[1] : {};
|
|
370
|
+
result = { style: { transform: `rotate3d(${finite(axis.x, 0)}, ${finite(axis.y, 0)}, ${finite(axis.z, 1)}, ${finite(value, 0)}deg)`, transformOrigin: alignmentCSSPosition(modifier.arguments[2]) } };
|
|
371
|
+
break;
|
|
372
|
+
}
|
|
373
|
+
case "mask":
|
|
374
|
+
result = { style: modifier.props && typeof modifier.props === "object" && "style" in modifier.props ? modifier.props.style : {} };
|
|
375
|
+
break;
|
|
376
|
+
case "clipShape":
|
|
377
|
+
result = { style: modifier.props && typeof modifier.props === "object" && "style" in modifier.props ? modifier.props.style : {} };
|
|
378
|
+
break;
|
|
379
|
+
case "clipped":
|
|
380
|
+
result = { style: { overflow: "hidden" } };
|
|
381
|
+
break;
|
|
382
|
+
case "fill":
|
|
383
|
+
result = { style: { background: String(value) } };
|
|
384
|
+
break;
|
|
385
|
+
// CSS has no centered stroke; an inset border follows the shape's corner radius.
|
|
386
|
+
case "stroke":
|
|
387
|
+
result = { style: { background: "transparent", border: `${layoutLength(modifier.arguments[1] ?? 1) ?? "1px"} solid ${String(value)}`, boxSizing: "border-box" } };
|
|
388
|
+
break;
|
|
389
|
+
case "cornerRadius":
|
|
390
|
+
result = { style: { borderRadius: layoutLength(value) } };
|
|
391
|
+
break;
|
|
392
|
+
case "resizable":
|
|
393
|
+
result = { style: { width: "100%", height: "100%" } };
|
|
394
|
+
break;
|
|
395
|
+
case "border":
|
|
396
|
+
result = { style: { border: `${layoutLength(modifier.arguments[1] ?? 1) ?? "1px"} solid ${String(value)}` } };
|
|
397
|
+
break;
|
|
398
|
+
case "shadow":
|
|
399
|
+
result = { style: { boxShadow: `${finite(modifier.arguments[2], 0)}px ${finite(modifier.arguments[3], 0)}px ${Math.max(0, finite(modifier.arguments[1], 0))}px ${String(value)}` } };
|
|
400
|
+
break;
|
|
401
|
+
case "blur":
|
|
402
|
+
result = { style: { filter: filterTemplate, "--mun-blur": `${Math.max(0, finite(value, 0))}px` } };
|
|
403
|
+
break;
|
|
404
|
+
case "brightness":
|
|
405
|
+
result = { style: { filter: filterTemplate, "--mun-brightness": Math.max(0, 1 + finite(value, 0)) } };
|
|
406
|
+
break;
|
|
407
|
+
case "contrast":
|
|
408
|
+
result = { style: { filter: filterTemplate, "--mun-contrast": Math.max(0, finite(value, 1)) } };
|
|
409
|
+
break;
|
|
410
|
+
case "saturation":
|
|
411
|
+
result = { style: { filter: filterTemplate, "--mun-saturation": Math.max(0, finite(value, 1)) } };
|
|
412
|
+
break;
|
|
413
|
+
case "grayscale":
|
|
414
|
+
result = { style: { filter: filterTemplate, "--mun-grayscale": Math.max(0, Math.min(1, finite(value, 0))) } };
|
|
415
|
+
break;
|
|
416
|
+
case "hueRotation":
|
|
417
|
+
result = { style: { filter: filterTemplate, "--mun-hue-rotation": `${finite(value, 0)}deg` } };
|
|
418
|
+
break;
|
|
419
|
+
case "colorInvert":
|
|
420
|
+
result = { style: { filter: filterTemplate, "--mun-color-invert": 1 } };
|
|
421
|
+
break;
|
|
422
|
+
case "colorMultiply":
|
|
423
|
+
result = { style: { "--mun-color-multiply": String(value) } };
|
|
424
|
+
break;
|
|
425
|
+
case "blendMode":
|
|
426
|
+
result = { style: { mixBlendMode: value === "colorDodge" ? "color-dodge" : value === "colorBurn" ? "color-burn" : value === "softLight" ? "soft-light" : value === "hardLight" ? "hard-light" : value === "plusLighter" ? "plus-lighter" : value } };
|
|
427
|
+
break;
|
|
428
|
+
case "compositingGroup":
|
|
429
|
+
result = { style: { isolation: "isolate" } };
|
|
430
|
+
break;
|
|
431
|
+
case "drawingGroup":
|
|
432
|
+
result = { style: { isolation: "isolate", contain: "paint" } };
|
|
433
|
+
break;
|
|
434
|
+
case "luminanceToAlpha":
|
|
435
|
+
result = { style: { filter: `${filterTemplate} grayscale(1)` } };
|
|
436
|
+
break;
|
|
437
|
+
case "tint": {
|
|
438
|
+
const tint = typeof value === "string" ? value : undefined;
|
|
439
|
+
result = { style: { accentColor: tint ?? "auto", "--mun-tint": tint ?? "initial" } };
|
|
440
|
+
break;
|
|
441
|
+
}
|
|
442
|
+
case "backgroundStyle":
|
|
443
|
+
result = { style: { background: String(value), "--mun-background-style": String(value) } };
|
|
444
|
+
break;
|
|
445
|
+
case "dynamicTypeSize":
|
|
446
|
+
result = { style: { "--mun-dynamic-type-size": String(value) } };
|
|
447
|
+
break;
|
|
448
|
+
case "disabled":
|
|
449
|
+
result = value === true ? { disabled: true, inert: true, "aria-disabled": true } : { disabled: false, inert: false, "aria-disabled": false };
|
|
450
|
+
break;
|
|
451
|
+
case "hidden":
|
|
452
|
+
result = { style: { visibility: "hidden" } };
|
|
453
|
+
break;
|
|
454
|
+
case "allowsHitTesting":
|
|
455
|
+
result = { style: { pointerEvents: value === false ? "none" : "auto" } };
|
|
456
|
+
break;
|
|
457
|
+
case "onTapGesture": {
|
|
458
|
+
const count = typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : 1;
|
|
459
|
+
const action = modifier.arguments[1];
|
|
460
|
+
result = typeof action !== "function" ? {} : count === 1 ? { onClick: action } : count === 2 ? { onDoubleClick: action } : { onClick(event) { if (event?.detail === count)
|
|
461
|
+
action(); } };
|
|
462
|
+
break;
|
|
463
|
+
}
|
|
464
|
+
case "onLongPressGesture":
|
|
465
|
+
result = longPressProps(modifier);
|
|
466
|
+
break;
|
|
467
|
+
case "onHover":
|
|
468
|
+
result = typeof value === "function" ? { onPointerEnter: () => value(true), onPointerLeave: () => value(false) } : {};
|
|
469
|
+
break;
|
|
470
|
+
case "preferredColorScheme":
|
|
471
|
+
result = { style: { colorScheme: value === "light" || value === "dark" ? value : "normal" } };
|
|
472
|
+
break;
|
|
473
|
+
case "controlSize":
|
|
474
|
+
result = { style: { "--mun-control-size": String(value) } };
|
|
475
|
+
break;
|
|
476
|
+
case "buttonStyle":
|
|
477
|
+
result = { style: { "--mun-button-style": String(value) } };
|
|
478
|
+
break;
|
|
479
|
+
case "toggleStyle":
|
|
480
|
+
result = { style: { "--mun-toggle-style": String(value) } };
|
|
481
|
+
break;
|
|
482
|
+
case "pickerStyle":
|
|
483
|
+
result = { style: { "--mun-picker-style": String(value) } };
|
|
484
|
+
break;
|
|
485
|
+
case "textFieldStyle":
|
|
486
|
+
result = { style: { "--mun-text-field-style": String(value) } };
|
|
487
|
+
break;
|
|
488
|
+
case "textEditorStyle":
|
|
489
|
+
result = { style: { "--mun-text-editor-style": String(value) } };
|
|
490
|
+
break;
|
|
491
|
+
case "listStyle":
|
|
492
|
+
result = { style: { "--mun-list-style": String(value) } };
|
|
493
|
+
break;
|
|
494
|
+
case "labelStyle":
|
|
495
|
+
result = { style: { "--mun-label-style": String(value) } };
|
|
496
|
+
break;
|
|
497
|
+
case "progressViewStyle":
|
|
498
|
+
result = { style: { "--mun-progress-view-style": String(value) } };
|
|
499
|
+
break;
|
|
500
|
+
case "scrollDisabled":
|
|
501
|
+
result = { style: value === true ? { overflow: "hidden" } : {} };
|
|
502
|
+
break;
|
|
503
|
+
case "scrollIndicators":
|
|
504
|
+
result = { style: value === "hidden" ? { scrollbarWidth: "none" } : {} };
|
|
505
|
+
break;
|
|
506
|
+
case "scrollBounceBehavior":
|
|
507
|
+
result = { style: { overscrollBehavior: value === "always" || value === "basedOnSize" ? "auto" : "none" } };
|
|
508
|
+
break;
|
|
509
|
+
case "scrollClipDisabled":
|
|
510
|
+
result = { style: value === false ? {} : { overflow: "visible" } };
|
|
511
|
+
break;
|
|
512
|
+
case "listRowInsets":
|
|
513
|
+
result = { style: paddingStyle(value, modifier.arguments[1]) };
|
|
514
|
+
break;
|
|
515
|
+
case "listRowBackground":
|
|
516
|
+
result = { style: typeof value === "string" ? { background: value } : {} };
|
|
517
|
+
break;
|
|
518
|
+
case "listRowSeparator":
|
|
519
|
+
case "listSectionSeparator":
|
|
520
|
+
result = { style: value === "hidden" ? { borderBlockStyle: "none" } : value === "visible" ? { borderBlockStyle: "solid" } : {} };
|
|
521
|
+
break;
|
|
522
|
+
case "symbolRenderingMode":
|
|
523
|
+
result = { style: { "--mun-symbol-rendering-mode": value == null ? "automatic" : String(value) } };
|
|
524
|
+
break;
|
|
525
|
+
case "symbolVariant":
|
|
526
|
+
result = { style: { "--mun-symbol-variant": String(value) } };
|
|
527
|
+
break;
|
|
528
|
+
case "id":
|
|
529
|
+
result = { "data-mun-id": String(value), key: value };
|
|
530
|
+
break;
|
|
531
|
+
case "onSubmit":
|
|
532
|
+
result = typeof value === "function" ? { onSubmit: (event) => { event.preventDefault?.(); value(); }, onKeyDown: submitKeyDown(value) } : {};
|
|
533
|
+
break;
|
|
534
|
+
case "focusable":
|
|
535
|
+
result = value === false ? { tabIndex: -1 } : { tabIndex: 0, ...(typeof modifier.arguments[1] === "function" ? { onFocus: () => modifier.arguments[1](true), onBlur: () => modifier.arguments[1](false) } : {}) };
|
|
536
|
+
break;
|
|
537
|
+
case "draggable":
|
|
538
|
+
result = { draggable: true, onDragStart: (event) => { let serialized = String(value); try {
|
|
539
|
+
serialized = typeof value === "string" ? value : JSON.stringify(value);
|
|
540
|
+
}
|
|
541
|
+
catch { } ; event.dataTransfer?.setData?.("application/x-mun+json", serialized); } };
|
|
542
|
+
break;
|
|
543
|
+
case "dropDestination": {
|
|
544
|
+
const action = modifier.arguments[1];
|
|
545
|
+
const targeted = modifier.arguments[2];
|
|
546
|
+
result = typeof action === "function" ? {
|
|
547
|
+
onDragEnter: (event) => { event.preventDefault?.(); if (typeof targeted === "function")
|
|
548
|
+
targeted(true); },
|
|
549
|
+
onDragOver: (event) => event.preventDefault?.(),
|
|
550
|
+
onDragLeave: () => { if (typeof targeted === "function")
|
|
551
|
+
targeted(false); },
|
|
552
|
+
onDrop: (event) => { event.preventDefault?.(); if (typeof targeted === "function")
|
|
553
|
+
targeted(false); const raw = event.dataTransfer?.getData?.("application/x-mun+json") ?? ""; let item = raw; try {
|
|
554
|
+
item = JSON.parse(raw);
|
|
555
|
+
}
|
|
556
|
+
catch { } ; action([item], { x: finite(event.clientX, 0), y: finite(event.clientY, 0) }); },
|
|
557
|
+
} : {};
|
|
558
|
+
break;
|
|
559
|
+
}
|
|
560
|
+
case "scrollDismissesKeyboard":
|
|
561
|
+
result = value === "never" ? {} : { onScroll(event) { const active = event?.currentTarget?.ownerDocument?.activeElement; active?.blur?.(); } };
|
|
562
|
+
break;
|
|
563
|
+
case "accessibilityLabel":
|
|
564
|
+
result = { "aria-label": String(value) };
|
|
565
|
+
break;
|
|
566
|
+
case "accessibilityHint":
|
|
567
|
+
result = { "aria-description": String(value) };
|
|
568
|
+
break;
|
|
569
|
+
case "accessibilityValue":
|
|
570
|
+
result = { "aria-valuetext": String(value) };
|
|
571
|
+
break;
|
|
572
|
+
case "accessibilityHidden":
|
|
573
|
+
result = { "aria-hidden": Boolean(value) };
|
|
574
|
+
break;
|
|
575
|
+
case "accessibilityIdentifier":
|
|
576
|
+
result = { "data-accessibility-id": String(value) };
|
|
577
|
+
break;
|
|
578
|
+
case "accessibilityHeading":
|
|
579
|
+
result = { role: "heading", "aria-level": /^h([1-6])$/.test(String(value)) ? Number(String(value).slice(1)) : 2 };
|
|
580
|
+
break;
|
|
581
|
+
case "accessibilitySortPriority":
|
|
582
|
+
result = { "data-accessibility-sort-priority": String(finite(value, 0)) };
|
|
583
|
+
break;
|
|
584
|
+
case "accessibilityElement":
|
|
585
|
+
result = { role: value === "contain" ? "group" : undefined, "data-accessibility-children": String(value ?? "ignore") };
|
|
586
|
+
break;
|
|
587
|
+
case "accessibilityAction":
|
|
588
|
+
result = typeof modifier.arguments[1] === "function" ? { "data-accessibility-action": String(value), onClick: modifier.arguments[1] } : {};
|
|
589
|
+
break;
|
|
590
|
+
case "continuousCorners": {
|
|
591
|
+
const smoothing = typeof value === "number" && Number.isFinite(value) ? Math.max(0, Math.min(1, value)) : APPLE_CONTINUOUS_CORNER_SMOOTHING;
|
|
592
|
+
result = { style: { cornerShape: "squircle", "--mun-corner-style": "continuous", "--mun-corner-smoothing": smoothing, "--mun-corner-preserve-smoothing": 1 } };
|
|
593
|
+
break;
|
|
594
|
+
}
|
|
595
|
+
case "style":
|
|
596
|
+
result = { style: value };
|
|
597
|
+
break;
|
|
598
|
+
case "className":
|
|
599
|
+
result = { className: classNameOf(value) };
|
|
600
|
+
break;
|
|
601
|
+
case "withProps":
|
|
602
|
+
result = value && typeof value === "object" ? value : {};
|
|
603
|
+
break;
|
|
604
|
+
case "keyed":
|
|
605
|
+
result = { key: value };
|
|
606
|
+
break;
|
|
607
|
+
case "elementRef":
|
|
608
|
+
result = { ref: value };
|
|
609
|
+
break;
|
|
610
|
+
case "frame":
|
|
611
|
+
result = { style: frameStyle(value && typeof value === "object" ? value : {}, modifier.arguments[1]) };
|
|
612
|
+
break;
|
|
613
|
+
case "animation": {
|
|
614
|
+
const selected = modifier.arguments.length === 0 ? Animation.default : value;
|
|
615
|
+
result = { style: animationCSSStyle(selected) ?? {} };
|
|
616
|
+
break;
|
|
617
|
+
}
|
|
618
|
+
case "animationAuto": {
|
|
619
|
+
const properties = Array.isArray(value)
|
|
620
|
+
? value.filter((property) => typeof property === "string")
|
|
621
|
+
: [];
|
|
622
|
+
const style = animationCSSStyle(Animation.default);
|
|
623
|
+
result = {
|
|
624
|
+
style: style
|
|
625
|
+
? { ...style, ...(properties.length > 0 ? { transitionProperty: properties.join(", ") } : {}) }
|
|
626
|
+
: {},
|
|
627
|
+
};
|
|
628
|
+
break;
|
|
629
|
+
}
|
|
630
|
+
default: result = {};
|
|
631
|
+
}
|
|
632
|
+
const transaction = currentRenderTransaction();
|
|
633
|
+
if (swiftUIAnimatableModifierNames.has(modifier.name) && transaction.animation && !transaction.disablesAnimations) {
|
|
634
|
+
const animationStyle = animationCSSStyle(transaction.animation);
|
|
635
|
+
if (animationStyle)
|
|
636
|
+
result = { ...result, style: { ...(result.style && typeof result.style === "object" ? result.style : {}), ...animationStyle } };
|
|
637
|
+
}
|
|
638
|
+
return result;
|
|
639
|
+
}
|
|
640
|
+
function nativeElementProps(props) {
|
|
641
|
+
try {
|
|
642
|
+
const normalized = {};
|
|
643
|
+
for (const key of Reflect.ownKeys(props)) {
|
|
644
|
+
if (typeof key !== "string")
|
|
645
|
+
continue;
|
|
646
|
+
const descriptor = Object.getOwnPropertyDescriptor(props, key);
|
|
647
|
+
if (!descriptor || !("value" in descriptor))
|
|
648
|
+
continue;
|
|
649
|
+
const value = descriptor.value;
|
|
650
|
+
const primitive = value === undefined || value === null || typeof value === "string" || typeof value === "boolean"
|
|
651
|
+
|| (typeof value === "number" && Number.isFinite(value));
|
|
652
|
+
if (primitive
|
|
653
|
+
|| (key === "style" && typeof value === "object" && value !== null)
|
|
654
|
+
|| (key === "ref" && (typeof value === "object" || typeof value === "function"))
|
|
655
|
+
|| (/^on[A-Za-z]/.test(key) && typeof value === "function")) {
|
|
656
|
+
Object.defineProperty(normalized, key, { ...descriptor, configurable: true });
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
return normalized;
|
|
660
|
+
}
|
|
661
|
+
catch {
|
|
662
|
+
return {};
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
function applyProps(content, extra) {
|
|
666
|
+
if (content && typeof content === "object" && "type" in content && "props" in content) {
|
|
667
|
+
const element = content;
|
|
668
|
+
const appliedExtra = typeof element.type === "string" && !element.type.includes("-") ? nativeElementProps(extra) : extra;
|
|
669
|
+
const current = (element.props ?? {});
|
|
670
|
+
const currentStyle = current.style && typeof current.style === "object" ? current.style : {};
|
|
671
|
+
const nextStyle = appliedExtra.style && typeof appliedExtra.style === "object" ? appliedExtra.style : undefined;
|
|
672
|
+
const currentClass = typeof current.className === "string" ? current.className : "";
|
|
673
|
+
const nextClass = typeof appliedExtra.className === "string" ? appliedExtra.className : "";
|
|
674
|
+
const className = [currentClass, nextClass].filter(Boolean).join(" ");
|
|
675
|
+
const composedStyle = nextStyle ? { ...currentStyle, ...nextStyle } : currentStyle;
|
|
676
|
+
if (nextStyle?.transform && currentStyle.transform)
|
|
677
|
+
composedStyle.transform = `${currentStyle.transform} ${nextStyle.transform}`;
|
|
678
|
+
// Several modifiers can handle one event on one element (Button + .onTapGesture,
|
|
679
|
+
// .onHover + .onLongPressGesture); run the inner handler first, then the new one.
|
|
680
|
+
const composed = {};
|
|
681
|
+
for (const key of Object.keys(appliedExtra)) {
|
|
682
|
+
const next = appliedExtra[key];
|
|
683
|
+
const before = current[key];
|
|
684
|
+
if (typeof next === "function" && typeof before === "function" && before !== next && /^on[A-Z]/.test(key)) {
|
|
685
|
+
composed[key] = (...args) => { before(...args); next(...args); };
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
const props = {
|
|
689
|
+
...appliedExtra,
|
|
690
|
+
...composed,
|
|
691
|
+
...(className ? { className } : {}),
|
|
692
|
+
...("style" in appliedExtra ? { style: composedStyle } : {}),
|
|
693
|
+
};
|
|
694
|
+
return cloneElement(element, props);
|
|
695
|
+
}
|
|
696
|
+
return createElement(Fragment, null, content);
|
|
697
|
+
}
|
|
698
|
+
function normalizeElementProps(props) {
|
|
699
|
+
if (!props)
|
|
700
|
+
return null;
|
|
701
|
+
// Core element props are immutable snapshots. The overwhelming majority of
|
|
702
|
+
// host rows (key/data/aria/primitive props) already use names React accepts,
|
|
703
|
+
// so avoid cloning and enumerating them twice merely to discover there was
|
|
704
|
+
// nothing to normalize.
|
|
705
|
+
let needsNormalization = false;
|
|
706
|
+
for (const key of Object.keys(props)) {
|
|
707
|
+
const value = props[key];
|
|
708
|
+
if (key === "class" || key === "for" || (key === "style" && typeof value === "string")
|
|
709
|
+
|| (typeof value === "function" && /^on[a-z]/.test(key))) {
|
|
710
|
+
needsNormalization = true;
|
|
711
|
+
break;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
if (!needsNormalization)
|
|
715
|
+
return props;
|
|
716
|
+
const next = { ...props };
|
|
717
|
+
if ("class" in next && !("className" in next)) {
|
|
718
|
+
next.className = next.class;
|
|
719
|
+
delete next.class;
|
|
720
|
+
}
|
|
721
|
+
if ("for" in next && !("htmlFor" in next)) {
|
|
722
|
+
next.htmlFor = next.for;
|
|
723
|
+
delete next.for;
|
|
724
|
+
}
|
|
725
|
+
if (typeof next.style === "string") {
|
|
726
|
+
next.style = Object.fromEntries(next.style.split(";").flatMap(declaration => {
|
|
727
|
+
const colon = declaration.indexOf(":");
|
|
728
|
+
if (colon < 0)
|
|
729
|
+
return [];
|
|
730
|
+
const rawName = declaration.slice(0, colon).trim();
|
|
731
|
+
const value = declaration.slice(colon + 1).trim();
|
|
732
|
+
if (!rawName || !value)
|
|
733
|
+
return [];
|
|
734
|
+
const name = rawName.startsWith("--") ? rawName : rawName.replace(/-([a-z])/g, (_match, character) => character.toUpperCase());
|
|
735
|
+
return [[name, value]];
|
|
736
|
+
}));
|
|
737
|
+
}
|
|
738
|
+
for (const [key, value] of Object.entries(next)) {
|
|
739
|
+
if (typeof value === "function" && /^on[a-z]/.test(key)) {
|
|
740
|
+
delete next[key];
|
|
741
|
+
next[`on${key[2].toUpperCase()}${key.slice(3)}`] = value;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
return next;
|
|
745
|
+
}
|
|
746
|
+
const directCollectionUnsafeTags = new Set([
|
|
747
|
+
"script", "style", "title", "textarea", "xmp", "iframe", "noembed", "noframes", "plaintext",
|
|
748
|
+
"area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr",
|
|
749
|
+
"table", "caption", "colgroup", "thead", "tbody", "tfoot", "tr", "td", "th",
|
|
750
|
+
"select", "option", "optgroup", "template", "svg", "math",
|
|
751
|
+
]);
|
|
752
|
+
const directCollectionUnsafeProps = new Set([
|
|
753
|
+
"children", "key", "ref", "innerHTML", "outerHTML", "textContent", "innerText", "dangerouslySetInnerHTML", "__proto__",
|
|
754
|
+
]);
|
|
755
|
+
function directCollectionPropsSafe(props) {
|
|
756
|
+
if (!props)
|
|
757
|
+
return true;
|
|
758
|
+
try {
|
|
759
|
+
for (const key of Reflect.ownKeys(props)) {
|
|
760
|
+
if (typeof key !== "string")
|
|
761
|
+
return false;
|
|
762
|
+
const descriptor = Object.getOwnPropertyDescriptor(props, key);
|
|
763
|
+
if (!descriptor || !("value" in descriptor))
|
|
764
|
+
return false;
|
|
765
|
+
const value = descriptor.value;
|
|
766
|
+
if (directCollectionUnsafeProps.has(key) || key.startsWith("data-mun-") || /^on[a-z]/i.test(key))
|
|
767
|
+
return false;
|
|
768
|
+
if (key === "style") {
|
|
769
|
+
if (value === undefined || value === null || typeof value === "string")
|
|
770
|
+
continue;
|
|
771
|
+
if (typeof value !== "object")
|
|
772
|
+
return false;
|
|
773
|
+
for (const styleKey of Reflect.ownKeys(value)) {
|
|
774
|
+
if (typeof styleKey !== "string" || styleKey === "__proto__")
|
|
775
|
+
return false;
|
|
776
|
+
const styleDescriptor = Object.getOwnPropertyDescriptor(value, styleKey);
|
|
777
|
+
if (!styleDescriptor || !("value" in styleDescriptor))
|
|
778
|
+
return false;
|
|
779
|
+
const item = styleDescriptor.value;
|
|
780
|
+
if (item !== undefined && item !== null && typeof item !== "string"
|
|
781
|
+
&& (typeof item !== "number" || !Number.isFinite(item)))
|
|
782
|
+
return false;
|
|
783
|
+
}
|
|
784
|
+
continue;
|
|
785
|
+
}
|
|
786
|
+
const primitive = value === undefined || value === null || typeof value === "string" || typeof value === "boolean"
|
|
787
|
+
|| (typeof value === "number" && Number.isFinite(value));
|
|
788
|
+
if (!primitive)
|
|
789
|
+
return false;
|
|
790
|
+
}
|
|
791
|
+
return true;
|
|
792
|
+
}
|
|
793
|
+
catch {
|
|
794
|
+
return false;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
function directCollectionText(value) {
|
|
798
|
+
if (value === null || value === undefined || typeof value === "boolean")
|
|
799
|
+
return { ok: true, value: null };
|
|
800
|
+
if (typeof value === "string" || typeof value === "number")
|
|
801
|
+
return { ok: true, value };
|
|
802
|
+
if (typeof value === "bigint")
|
|
803
|
+
return { ok: true, value: String(value) };
|
|
804
|
+
return { ok: false };
|
|
805
|
+
}
|
|
806
|
+
function renderDirectCollectionRow(node, item, index, key) {
|
|
807
|
+
const plan = node.compiled;
|
|
808
|
+
if (plan?.kind !== "flat-text-host")
|
|
809
|
+
return undefined;
|
|
810
|
+
let type;
|
|
811
|
+
let props;
|
|
812
|
+
let textValue;
|
|
813
|
+
if (typeof plan.hostType === "string" && typeof plan.evaluateText === "function") {
|
|
814
|
+
type = plan.hostType;
|
|
815
|
+
if (type.includes("-") || directCollectionUnsafeTags.has(type.toLowerCase()))
|
|
816
|
+
return undefined;
|
|
817
|
+
if (plan.staticProps === null)
|
|
818
|
+
props = null;
|
|
819
|
+
else if (plan.staticProps !== undefined)
|
|
820
|
+
props = plan.staticProps;
|
|
821
|
+
else if (plan.evaluateProps)
|
|
822
|
+
props = plan.evaluateProps(item, index);
|
|
823
|
+
else
|
|
824
|
+
return undefined;
|
|
825
|
+
if (!directCollectionPropsSafe(props))
|
|
826
|
+
return undefined;
|
|
827
|
+
textValue = plan.evaluateText(item, index);
|
|
828
|
+
}
|
|
829
|
+
else {
|
|
830
|
+
const row = plan.evaluate(item, index);
|
|
831
|
+
if (!row || typeof row !== "object" || typeof row.type !== "string" || row.type.includes("-")
|
|
832
|
+
|| directCollectionUnsafeTags.has(row.type.toLowerCase()) || !directCollectionPropsSafe(row.props))
|
|
833
|
+
return undefined;
|
|
834
|
+
type = row.type;
|
|
835
|
+
props = row.props;
|
|
836
|
+
textValue = row.text;
|
|
837
|
+
}
|
|
838
|
+
const text = directCollectionText(textValue);
|
|
839
|
+
if (!text.ok)
|
|
840
|
+
return undefined;
|
|
841
|
+
if (props === null)
|
|
842
|
+
return createElement(type, { key }, text.value);
|
|
843
|
+
return createElement(type, { ...(normalizeElementProps(props) ?? {}), key }, text.value);
|
|
844
|
+
}
|
|
845
|
+
function renderDirectCollectionEntry(node, entry) {
|
|
846
|
+
return renderDirectCollectionRow(node, entry.item, entry.index, entry.key);
|
|
847
|
+
}
|
|
848
|
+
function reactCollectionItems(node, previous, notifications, forceFullSnapshot = false) {
|
|
849
|
+
if (!node.readItems)
|
|
850
|
+
return node.items;
|
|
851
|
+
const source = isStateRef(node.source) ? node.source : undefined;
|
|
852
|
+
if (forceFullSnapshot || !previous || !source)
|
|
853
|
+
return node.readItems();
|
|
854
|
+
const sourceIdentity = reactiveIdentity(source.value);
|
|
855
|
+
let next;
|
|
856
|
+
const mutable = () => next ??= [...previous];
|
|
857
|
+
for (const notification of notifications) {
|
|
858
|
+
if (notification.dependency !== source)
|
|
859
|
+
continue;
|
|
860
|
+
for (const mutation of notification.batch.mutations) {
|
|
861
|
+
const target = mutation.target;
|
|
862
|
+
if (mutation.kind === "replace") {
|
|
863
|
+
if (mutation.snapshot)
|
|
864
|
+
return mutation.snapshot;
|
|
865
|
+
if (!target || !Object.is(target, sourceIdentity))
|
|
866
|
+
return node.readItems();
|
|
867
|
+
if (typeof mutation.property !== "string")
|
|
868
|
+
return node.readItems();
|
|
869
|
+
const index = Number(mutation.property);
|
|
870
|
+
if (!Number.isSafeInteger(index) || index < 0 || index >= previous.length || String(index) !== mutation.property)
|
|
871
|
+
return node.readItems();
|
|
872
|
+
mutable()[index] = mutation.value;
|
|
873
|
+
continue;
|
|
874
|
+
}
|
|
875
|
+
if (!target || !Object.is(target, sourceIdentity))
|
|
876
|
+
continue;
|
|
877
|
+
if (mutation.kind === "set") {
|
|
878
|
+
if (mutation.property === "length") {
|
|
879
|
+
const length = typeof mutation.value === "number" ? mutation.value : Number.NaN;
|
|
880
|
+
if (!Number.isSafeInteger(length) || length < 0)
|
|
881
|
+
return node.readItems();
|
|
882
|
+
mutable().length = length;
|
|
883
|
+
continue;
|
|
884
|
+
}
|
|
885
|
+
if (typeof mutation.property === "string") {
|
|
886
|
+
const index = Number(mutation.property);
|
|
887
|
+
if (Number.isSafeInteger(index) && index >= 0 && index < 0xffff_ffff && String(index) === mutation.property)
|
|
888
|
+
mutable()[index] = mutation.value;
|
|
889
|
+
}
|
|
890
|
+
continue;
|
|
891
|
+
}
|
|
892
|
+
if (mutation.kind === "delete") {
|
|
893
|
+
if (typeof mutation.property === "string") {
|
|
894
|
+
const index = Number(mutation.property);
|
|
895
|
+
if (Number.isSafeInteger(index) && index >= 0 && index < 0xffff_ffff && String(index) === mutation.property)
|
|
896
|
+
delete mutable()[index];
|
|
897
|
+
}
|
|
898
|
+
continue;
|
|
899
|
+
}
|
|
900
|
+
if (mutation.kind !== "array") {
|
|
901
|
+
if (mutation.kind === "invalidate" || mutation.kind === "define")
|
|
902
|
+
return node.readItems();
|
|
903
|
+
continue;
|
|
904
|
+
}
|
|
905
|
+
const values = mutable();
|
|
906
|
+
const arguments_ = [...(mutation.arguments ?? [])];
|
|
907
|
+
switch (mutation.method) {
|
|
908
|
+
case "push":
|
|
909
|
+
values.push(...arguments_);
|
|
910
|
+
break;
|
|
911
|
+
case "pop":
|
|
912
|
+
values.pop();
|
|
913
|
+
break;
|
|
914
|
+
case "shift":
|
|
915
|
+
values.shift();
|
|
916
|
+
break;
|
|
917
|
+
case "unshift":
|
|
918
|
+
values.unshift(...arguments_);
|
|
919
|
+
break;
|
|
920
|
+
case "splice":
|
|
921
|
+
Array.prototype.splice.apply(values, arguments_);
|
|
922
|
+
break;
|
|
923
|
+
case "reverse":
|
|
924
|
+
values.reverse();
|
|
925
|
+
break;
|
|
926
|
+
case "copyWithin":
|
|
927
|
+
Array.prototype.copyWithin.apply(values, arguments_);
|
|
928
|
+
break;
|
|
929
|
+
case "fill":
|
|
930
|
+
Array.prototype.fill.apply(values, arguments_);
|
|
931
|
+
break;
|
|
932
|
+
default: return node.readItems();
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
return next ?? previous;
|
|
937
|
+
}
|
|
938
|
+
function reactCollectionMutationEffects(node, items, notifications, forceAllWithoutBatch = false) {
|
|
939
|
+
if (forceAllWithoutBatch)
|
|
940
|
+
return { forceAll: true, touchedItems: new Set() };
|
|
941
|
+
if (notifications.length === 0)
|
|
942
|
+
return { forceAll: false, touchedItems: new Set() };
|
|
943
|
+
const source = isStateRef(node.source) ? node.source : undefined;
|
|
944
|
+
const sourceIdentity = source ? reactiveIdentity(source.value) : undefined;
|
|
945
|
+
const candidateTargets = new Set();
|
|
946
|
+
let forceAll = false;
|
|
947
|
+
for (const notification of notifications) {
|
|
948
|
+
if (source && notification.dependency !== source) {
|
|
949
|
+
forceAll = true;
|
|
950
|
+
break;
|
|
951
|
+
}
|
|
952
|
+
for (const mutation of notification.batch.mutations) {
|
|
953
|
+
const target = mutation.target;
|
|
954
|
+
if (!target) {
|
|
955
|
+
if (mutation.kind === "invalidate")
|
|
956
|
+
forceAll = true;
|
|
957
|
+
continue;
|
|
958
|
+
}
|
|
959
|
+
if (sourceIdentity && Object.is(target, sourceIdentity))
|
|
960
|
+
continue;
|
|
961
|
+
candidateTargets.add(target);
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
if (forceAll || candidateTargets.size === 0)
|
|
965
|
+
return { forceAll, touchedItems: candidateTargets };
|
|
966
|
+
const itemIdentities = new Set();
|
|
967
|
+
for (const item of items) {
|
|
968
|
+
const identity = reactiveIdentity(item);
|
|
969
|
+
if (identity && typeof identity === "object")
|
|
970
|
+
itemIdentities.add(identity);
|
|
971
|
+
}
|
|
972
|
+
for (const target of candidateTargets) {
|
|
973
|
+
// A direct row-object mutation can invalidate that row precisely. A deeper
|
|
974
|
+
// nested target is not cheaply attributable to one row here, so retain the
|
|
975
|
+
// compiler's correctness contract by invalidating all rows conservatively.
|
|
976
|
+
if (!itemIdentities.has(target))
|
|
977
|
+
return { forceAll: true, touchedItems: candidateTargets };
|
|
978
|
+
}
|
|
979
|
+
return { forceAll: false, touchedItems: candidateTargets };
|
|
980
|
+
}
|
|
981
|
+
function renderCompiledCollectionRows(node, renderEntry, previousRows, notifications, items, forceAllWithoutBatch = false) {
|
|
982
|
+
const plan = node.compiled;
|
|
983
|
+
if (plan?.kind !== "flat-text-host")
|
|
984
|
+
return undefined;
|
|
985
|
+
const effects = reactCollectionMutationEffects(node, items, notifications, forceAllWithoutBatch);
|
|
986
|
+
const occurrences = new Map();
|
|
987
|
+
const children = new Array(items.length);
|
|
988
|
+
const rows = new Array(items.length);
|
|
989
|
+
let previousByKey;
|
|
990
|
+
for (let index = 0; index < items.length; index += 1) {
|
|
991
|
+
const item = items[index];
|
|
992
|
+
const resolved = node.key(item, index);
|
|
993
|
+
if (!resolved || typeof resolved.identity !== "string" || typeof resolved.display !== "string") {
|
|
994
|
+
throw new TypeError("Keyed collection identity must contain string identity and display values");
|
|
995
|
+
}
|
|
996
|
+
const occurrence = occurrences.get(resolved.identity) ?? 0;
|
|
997
|
+
occurrences.set(resolved.identity, occurrence + 1);
|
|
998
|
+
if (occurrence > 0)
|
|
999
|
+
node.onDuplicateKey?.(resolved.display, occurrence);
|
|
1000
|
+
const key = keyedCollectionEntryKey(resolved.identity, occurrence);
|
|
1001
|
+
const itemIdentity = reactiveIdentity(item);
|
|
1002
|
+
let previous = previousRows[index];
|
|
1003
|
+
if (previous?.key !== key && plan.indexIndependent && previousRows.length > 0) {
|
|
1004
|
+
previousByKey ??= new Map(previousRows.flatMap(row => row ? [[row.key, row]] : []));
|
|
1005
|
+
previous = previousByKey.get(key);
|
|
1006
|
+
}
|
|
1007
|
+
const touched = itemIdentity && typeof itemIdentity === "object" && effects.touchedItems.has(itemIdentity);
|
|
1008
|
+
if (!effects.forceAll && !touched && previous && previous.key === key && previous.plan === plan
|
|
1009
|
+
&& Object.is(previous.itemIdentity, itemIdentity) && (plan.indexIndependent || previous.index === index)) {
|
|
1010
|
+
children[index] = previous.node;
|
|
1011
|
+
rows[index] = previous;
|
|
1012
|
+
continue;
|
|
1013
|
+
}
|
|
1014
|
+
const direct = renderDirectCollectionRow(node, item, index, key);
|
|
1015
|
+
if (direct !== undefined) {
|
|
1016
|
+
children[index] = direct;
|
|
1017
|
+
rows[index] = { key, baseKey: resolved.identity, occurrence, itemIdentity, index, plan, node: direct };
|
|
1018
|
+
continue;
|
|
1019
|
+
}
|
|
1020
|
+
const entry = {
|
|
1021
|
+
key,
|
|
1022
|
+
baseKey: resolved.identity,
|
|
1023
|
+
displayKey: resolved.display,
|
|
1024
|
+
occurrence,
|
|
1025
|
+
item,
|
|
1026
|
+
index,
|
|
1027
|
+
};
|
|
1028
|
+
const fallback = createElement(Fragment, { key }, renderEntry(entry));
|
|
1029
|
+
children[index] = fallback;
|
|
1030
|
+
}
|
|
1031
|
+
return { children, rows };
|
|
1032
|
+
}
|
|
1033
|
+
function localizedCompiledCollectionIndex(node, notifications, itemCount) {
|
|
1034
|
+
const source = isStateRef(node.source) ? node.source : undefined;
|
|
1035
|
+
if (!source || notifications.length !== 1)
|
|
1036
|
+
return undefined;
|
|
1037
|
+
const notification = notifications[0];
|
|
1038
|
+
if (notification.dependency !== source || notification.batch.mutations.length !== 1)
|
|
1039
|
+
return undefined;
|
|
1040
|
+
const mutation = notification.batch.mutations[0];
|
|
1041
|
+
if (mutation.kind !== "replace" && mutation.kind !== "set")
|
|
1042
|
+
return undefined;
|
|
1043
|
+
const target = mutation.target ? reactiveIdentity(mutation.target) : undefined;
|
|
1044
|
+
if (!target || !Object.is(target, reactiveIdentity(source.value)) || typeof mutation.property !== "string")
|
|
1045
|
+
return undefined;
|
|
1046
|
+
const index = Number(mutation.property);
|
|
1047
|
+
return Number.isSafeInteger(index) && index >= 0 && index < itemCount && String(index) === mutation.property
|
|
1048
|
+
? index
|
|
1049
|
+
: undefined;
|
|
1050
|
+
}
|
|
1051
|
+
function renderLocalizedCompiledCollectionRow(node, previousRows, previousChildren, items, index) {
|
|
1052
|
+
const plan = node.compiled;
|
|
1053
|
+
const previous = previousRows[index];
|
|
1054
|
+
if (plan?.kind !== "flat-text-host" || !previous || previous.plan !== plan
|
|
1055
|
+
|| previousRows.length !== items.length || previousChildren.length !== items.length)
|
|
1056
|
+
return undefined;
|
|
1057
|
+
const item = items[index];
|
|
1058
|
+
const resolved = node.key(item, index);
|
|
1059
|
+
if (!resolved || resolved.identity !== previous.baseKey)
|
|
1060
|
+
return undefined;
|
|
1061
|
+
const direct = renderDirectCollectionRow(node, item, index, previous.key);
|
|
1062
|
+
if (direct === undefined)
|
|
1063
|
+
return undefined;
|
|
1064
|
+
const children = previousChildren.slice();
|
|
1065
|
+
const rows = previousRows.slice();
|
|
1066
|
+
children[index] = direct;
|
|
1067
|
+
rows[index] = {
|
|
1068
|
+
key: previous.key,
|
|
1069
|
+
baseKey: previous.baseKey,
|
|
1070
|
+
occurrence: previous.occurrence,
|
|
1071
|
+
itemIdentity: reactiveIdentity(item),
|
|
1072
|
+
index,
|
|
1073
|
+
plan,
|
|
1074
|
+
node: direct,
|
|
1075
|
+
};
|
|
1076
|
+
return { children, rows };
|
|
1077
|
+
}
|
|
1078
|
+
function isStableCompiledReplacement(node, notifications, itemCount) {
|
|
1079
|
+
const source = isStateRef(node.source) ? node.source : undefined;
|
|
1080
|
+
if (!source || notifications.length !== 1)
|
|
1081
|
+
return false;
|
|
1082
|
+
const notification = notifications[0];
|
|
1083
|
+
if (notification.dependency !== source || notification.batch.mutations.length !== 1)
|
|
1084
|
+
return false;
|
|
1085
|
+
const mutation = notification.batch.mutations[0];
|
|
1086
|
+
return mutation.kind === "replace" && mutation.property === undefined
|
|
1087
|
+
&& mutation.snapshot?.length === itemCount;
|
|
1088
|
+
}
|
|
1089
|
+
/**
|
|
1090
|
+
* Full immutable map-style updates commonly replace every row object while
|
|
1091
|
+
* preserving the key sequence. Reuse each row's already-encoded occurrence
|
|
1092
|
+
* key instead of rebuilding occurrence maps and entry-key strings.
|
|
1093
|
+
*/
|
|
1094
|
+
function renderStableCompiledReplacementRows(node, previousRows, items) {
|
|
1095
|
+
const plan = node.compiled;
|
|
1096
|
+
if (plan?.kind !== "flat-text-host" || previousRows.length !== items.length)
|
|
1097
|
+
return undefined;
|
|
1098
|
+
const children = new Array(items.length);
|
|
1099
|
+
const rows = new Array(items.length);
|
|
1100
|
+
for (let index = 0; index < items.length; index += 1) {
|
|
1101
|
+
const previous = previousRows[index];
|
|
1102
|
+
if (!previous || previous.plan !== plan || previous.index !== index)
|
|
1103
|
+
return undefined;
|
|
1104
|
+
const item = items[index];
|
|
1105
|
+
const resolved = node.key(item, index);
|
|
1106
|
+
if (!resolved || resolved.identity !== previous.baseKey)
|
|
1107
|
+
return undefined;
|
|
1108
|
+
if (previous.occurrence > 0)
|
|
1109
|
+
node.onDuplicateKey?.(resolved.display, previous.occurrence);
|
|
1110
|
+
const direct = renderDirectCollectionRow(node, item, index, previous.key);
|
|
1111
|
+
if (direct === undefined)
|
|
1112
|
+
return undefined;
|
|
1113
|
+
children[index] = direct;
|
|
1114
|
+
rows[index] = {
|
|
1115
|
+
key: previous.key,
|
|
1116
|
+
baseKey: previous.baseKey,
|
|
1117
|
+
occurrence: previous.occurrence,
|
|
1118
|
+
itemIdentity: reactiveIdentity(item),
|
|
1119
|
+
index,
|
|
1120
|
+
plan,
|
|
1121
|
+
node: direct,
|
|
1122
|
+
};
|
|
1123
|
+
}
|
|
1124
|
+
return { children, rows };
|
|
1125
|
+
}
|
|
1126
|
+
function ReactCollectionHost({ node, renderEntry, }) {
|
|
1127
|
+
const compiledRows = useRef([]);
|
|
1128
|
+
const compiledChildren = useRef([]);
|
|
1129
|
+
const pendingNotifications = useRef([]);
|
|
1130
|
+
const sourceVersion = useRef(undefined);
|
|
1131
|
+
const compiledItems = useRef(undefined);
|
|
1132
|
+
// Keep collection reads below their own React boundary. The direct plan
|
|
1133
|
+
// avoids rebuilding row View graphs, while collectStateReads still retains
|
|
1134
|
+
// the generic fallback's dependency semantics for manually supplied plans
|
|
1135
|
+
// and ordinary State-backed ForEach nodes.
|
|
1136
|
+
const reactive = useReactiveGraph(() => {
|
|
1137
|
+
const notifications = pendingNotifications.current;
|
|
1138
|
+
pendingNotifications.current = [];
|
|
1139
|
+
const source = isStateRef(node.source) ? node.source : undefined;
|
|
1140
|
+
const nextSourceVersion = source ? stateVersion(source) : undefined;
|
|
1141
|
+
const missedMutation = compiledRows.current.length > 0
|
|
1142
|
+
&& sourceVersion.current !== undefined
|
|
1143
|
+
&& nextSourceVersion !== sourceVersion.current
|
|
1144
|
+
&& notifications.length === 0;
|
|
1145
|
+
sourceVersion.current = nextSourceVersion;
|
|
1146
|
+
const nextItems = node.compiled?.kind === "flat-text-host"
|
|
1147
|
+
? reactCollectionItems(node, compiledItems.current, notifications, missedMutation)
|
|
1148
|
+
: undefined;
|
|
1149
|
+
const stableReplacement = !missedMutation && nextItems && isStableCompiledReplacement(node, notifications, nextItems.length)
|
|
1150
|
+
? renderStableCompiledReplacementRows(node, compiledRows.current, nextItems)
|
|
1151
|
+
: undefined;
|
|
1152
|
+
const localIndex = !missedMutation && nextItems
|
|
1153
|
+
? localizedCompiledCollectionIndex(node, notifications, nextItems.length)
|
|
1154
|
+
: undefined;
|
|
1155
|
+
const localized = nextItems && localIndex !== undefined
|
|
1156
|
+
? renderLocalizedCompiledCollectionRow(node, compiledRows.current, compiledChildren.current, nextItems, localIndex)
|
|
1157
|
+
: undefined;
|
|
1158
|
+
const compiled = stableReplacement ?? localized ?? (nextItems
|
|
1159
|
+
? renderCompiledCollectionRows(node, renderEntry, compiledRows.current, notifications, nextItems, missedMutation)
|
|
1160
|
+
: undefined);
|
|
1161
|
+
if (compiled) {
|
|
1162
|
+
compiledRows.current = compiled.rows;
|
|
1163
|
+
compiledChildren.current = compiled.children;
|
|
1164
|
+
compiledItems.current = nextItems;
|
|
1165
|
+
return createElement(Fragment, null, compiled.children);
|
|
1166
|
+
}
|
|
1167
|
+
compiledRows.current = [];
|
|
1168
|
+
compiledChildren.current = [];
|
|
1169
|
+
compiledItems.current = undefined;
|
|
1170
|
+
return createElement(Fragment, null, keyedCollectionEntries(node).map(entry => {
|
|
1171
|
+
const direct = renderDirectCollectionEntry(node, entry);
|
|
1172
|
+
return direct ?? createElement(Fragment, { key: entry.key }, renderEntry(entry));
|
|
1173
|
+
}));
|
|
1174
|
+
}, undefined, false, (dependency, batch) => {
|
|
1175
|
+
pendingNotifications.current.push({ dependency, batch });
|
|
1176
|
+
});
|
|
1177
|
+
return withRenderTransaction(reactive.transaction, () => reactive.value);
|
|
1178
|
+
}
|
|
1179
|
+
function normalizeForeignProps(type, props, children) {
|
|
1180
|
+
if (!isForeignComponent(type))
|
|
1181
|
+
return normalizeElementProps(props);
|
|
1182
|
+
const next = normalizeElementProps({ ...type.props, ...type.events, ...(props ?? {}) }) ?? {};
|
|
1183
|
+
if (type.key !== undefined)
|
|
1184
|
+
next.key = type.key;
|
|
1185
|
+
for (const [name, slot] of Object.entries(type.slots)) {
|
|
1186
|
+
next[name] = (...args) => renderViewNode(typeof slot === "function" ? slot(...args) : slot, renderer);
|
|
1187
|
+
}
|
|
1188
|
+
if (children.length > 0 && !("children" in next))
|
|
1189
|
+
next.children = children;
|
|
1190
|
+
return next;
|
|
1191
|
+
}
|
|
1192
|
+
let nextStateDependencyId = 1;
|
|
1193
|
+
const stateDependencyIds = new WeakMap();
|
|
1194
|
+
function stateDependencyId(state) {
|
|
1195
|
+
let id = stateDependencyIds.get(state);
|
|
1196
|
+
if (id === undefined) {
|
|
1197
|
+
id = nextStateDependencyId++;
|
|
1198
|
+
stateDependencyIds.set(state, id);
|
|
1199
|
+
}
|
|
1200
|
+
return id;
|
|
1201
|
+
}
|
|
1202
|
+
function collectCompilerOwnedCollectionStates(value, result = new Set()) {
|
|
1203
|
+
if (Array.isArray(value)) {
|
|
1204
|
+
for (const child of value)
|
|
1205
|
+
collectCompilerOwnedCollectionStates(child, result);
|
|
1206
|
+
return result;
|
|
1207
|
+
}
|
|
1208
|
+
if (value === null || typeof value !== "object")
|
|
1209
|
+
return result;
|
|
1210
|
+
const node = value;
|
|
1211
|
+
switch (node.kind) {
|
|
1212
|
+
case "collection":
|
|
1213
|
+
if (node.compiled?.evaluateKey && isStateRef(node.source))
|
|
1214
|
+
result.add(node.source);
|
|
1215
|
+
return result;
|
|
1216
|
+
case "element":
|
|
1217
|
+
case "fragment":
|
|
1218
|
+
case "lazy":
|
|
1219
|
+
for (const child of node.children ?? [])
|
|
1220
|
+
collectCompilerOwnedCollectionStates(child, result);
|
|
1221
|
+
return result;
|
|
1222
|
+
case "template":
|
|
1223
|
+
for (const slot of node.slots ?? [])
|
|
1224
|
+
collectCompilerOwnedCollectionStates(slot, result);
|
|
1225
|
+
return result;
|
|
1226
|
+
case "modified":
|
|
1227
|
+
collectCompilerOwnedCollectionStates(node.content, result);
|
|
1228
|
+
return result;
|
|
1229
|
+
default:
|
|
1230
|
+
return result;
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
function pruneCompilerOwnedDependencies(value, dependencies, observedDependencies) {
|
|
1234
|
+
for (const dependency of collectCompilerOwnedCollectionStates(value)) {
|
|
1235
|
+
if (!observedDependencies.has(dependency))
|
|
1236
|
+
dependencies.delete(dependency);
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
function useReactiveGraph(compute, staticDependencies, staticDependenciesComplete = false, onMutation, pruneDependencies) {
|
|
1240
|
+
const mutationObserver = useRef(onMutation);
|
|
1241
|
+
mutationObserver.current = onMutation;
|
|
1242
|
+
const previousVersions = useRef(new Map());
|
|
1243
|
+
let transaction;
|
|
1244
|
+
for (const [dependency, previousVersion] of previousVersions.current) {
|
|
1245
|
+
if (stateVersion(dependency) === previousVersion)
|
|
1246
|
+
continue;
|
|
1247
|
+
const candidate = stateTransaction(dependency);
|
|
1248
|
+
if (!transaction || candidate.animation || candidate.disablesAnimations)
|
|
1249
|
+
transaction = candidate;
|
|
1250
|
+
}
|
|
1251
|
+
const declaredDependencies = staticDependencies?.();
|
|
1252
|
+
const dependencies = new Set(declaredDependencies ?? []);
|
|
1253
|
+
const observedDependencies = new Set();
|
|
1254
|
+
const needsObservedDependencies = Boolean(pruneDependencies);
|
|
1255
|
+
const value = withRenderTransaction(transaction, () => declaredDependencies && staticDependenciesComplete && !needsObservedDependencies
|
|
1256
|
+
? compute()
|
|
1257
|
+
: collectStateReads(compute, dependency => {
|
|
1258
|
+
observedDependencies.add(dependency);
|
|
1259
|
+
if (!(declaredDependencies && staticDependenciesComplete))
|
|
1260
|
+
dependencies.add(dependency);
|
|
1261
|
+
}));
|
|
1262
|
+
pruneDependencies?.(value, dependencies, observedDependencies);
|
|
1263
|
+
const dependencyList = [...dependencies];
|
|
1264
|
+
const nextVersions = new Map();
|
|
1265
|
+
for (const dependency of dependencyList)
|
|
1266
|
+
nextVersions.set(dependency, stateVersion(dependency));
|
|
1267
|
+
previousVersions.current = nextVersions;
|
|
1268
|
+
// Subscribe keyed by the dependency-set identity so useSyncExternalStore
|
|
1269
|
+
// only re-subscribes when the set actually changes instead of every commit.
|
|
1270
|
+
const dependencyKey = dependencyList.map(stateDependencyId).sort((left, right) => left - right).join(",");
|
|
1271
|
+
const subscribe = useMemo(() => (listener) => {
|
|
1272
|
+
const unsubscribers = dependencyList.map(dependency => subscribeState(dependency, (_transaction, batch) => {
|
|
1273
|
+
mutationObserver.current?.(dependency, batch);
|
|
1274
|
+
listener();
|
|
1275
|
+
}));
|
|
1276
|
+
return () => unsubscribers.forEach(unsubscribe => unsubscribe());
|
|
1277
|
+
},
|
|
1278
|
+
// The dependency list is rebuilt every render, but this key changes only
|
|
1279
|
+
// when the actual set changes.
|
|
1280
|
+
[dependencyKey]);
|
|
1281
|
+
const getSnapshot = useMemo(() => () => {
|
|
1282
|
+
let version = 0;
|
|
1283
|
+
for (const dependency of dependencyList)
|
|
1284
|
+
version += stateVersion(dependency);
|
|
1285
|
+
return version;
|
|
1286
|
+
}, [dependencyKey]);
|
|
1287
|
+
useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
1288
|
+
return { value, transaction };
|
|
1289
|
+
}
|
|
1290
|
+
function geometryFromElement(element) {
|
|
1291
|
+
let rect;
|
|
1292
|
+
try {
|
|
1293
|
+
rect = element.getBoundingClientRect();
|
|
1294
|
+
}
|
|
1295
|
+
catch {
|
|
1296
|
+
return zeroGeometry;
|
|
1297
|
+
}
|
|
1298
|
+
const frame = {
|
|
1299
|
+
x: rect.x,
|
|
1300
|
+
y: rect.y,
|
|
1301
|
+
width: rect.width,
|
|
1302
|
+
height: rect.height,
|
|
1303
|
+
top: rect.top,
|
|
1304
|
+
right: rect.right,
|
|
1305
|
+
bottom: rect.bottom,
|
|
1306
|
+
left: rect.left,
|
|
1307
|
+
};
|
|
1308
|
+
const document = element.ownerDocument;
|
|
1309
|
+
const view = document.defaultView;
|
|
1310
|
+
const fallback = { frame, size: { width: rect.width, height: rect.height }, safeAreaInsets: zeroGeometry.safeAreaInsets };
|
|
1311
|
+
if (!view?.getComputedStyle || !document.body)
|
|
1312
|
+
return fallback;
|
|
1313
|
+
const probe = document.createElement("div");
|
|
1314
|
+
probe.style.cssText = "position:fixed;inset:0;visibility:hidden;pointer-events:none;padding:env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)";
|
|
1315
|
+
try {
|
|
1316
|
+
document.body.appendChild(probe);
|
|
1317
|
+
const style = view.getComputedStyle(probe);
|
|
1318
|
+
const safeAreaInsets = edgeInsetsFromCss({ top: style.paddingTop, right: style.paddingRight, bottom: style.paddingBottom, left: style.paddingLeft });
|
|
1319
|
+
return { frame, size: { width: rect.width, height: rect.height }, safeAreaInsets };
|
|
1320
|
+
}
|
|
1321
|
+
catch {
|
|
1322
|
+
// Geometry is still useful when CSSOM access is unavailable (sandboxed or
|
|
1323
|
+
// synthetic documents). Safe-area measurement is optional, not fatal.
|
|
1324
|
+
return fallback;
|
|
1325
|
+
}
|
|
1326
|
+
finally {
|
|
1327
|
+
try {
|
|
1328
|
+
probe.remove();
|
|
1329
|
+
}
|
|
1330
|
+
catch { /* detached/synthetic DOM cleanup is best-effort */ }
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
function sameGeometry(left, right) {
|
|
1334
|
+
return left.frame.x === right.frame.x
|
|
1335
|
+
&& left.frame.y === right.frame.y
|
|
1336
|
+
&& left.frame.width === right.frame.width
|
|
1337
|
+
&& left.frame.height === right.frame.height
|
|
1338
|
+
&& left.safeAreaInsets.top === right.safeAreaInsets.top
|
|
1339
|
+
&& left.safeAreaInsets.right === right.safeAreaInsets.right
|
|
1340
|
+
&& left.safeAreaInsets.bottom === right.safeAreaInsets.bottom
|
|
1341
|
+
&& left.safeAreaInsets.left === right.safeAreaInsets.left;
|
|
1342
|
+
}
|
|
1343
|
+
function GeometryHost({ render }) {
|
|
1344
|
+
const host = useRef(null);
|
|
1345
|
+
const [geometry, setGeometry] = useState(zeroGeometry);
|
|
1346
|
+
const reactive = useReactiveGraph(() => render(geometry));
|
|
1347
|
+
useEffect(() => {
|
|
1348
|
+
const element = host.current;
|
|
1349
|
+
if (!element)
|
|
1350
|
+
return undefined;
|
|
1351
|
+
const update = () => {
|
|
1352
|
+
const next = geometryFromElement(element);
|
|
1353
|
+
setGeometry(previous => sameGeometry(previous, next) ? previous : next);
|
|
1354
|
+
};
|
|
1355
|
+
update();
|
|
1356
|
+
let observer;
|
|
1357
|
+
try {
|
|
1358
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
1359
|
+
observer = new ResizeObserver(update);
|
|
1360
|
+
observer.observe(element);
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
catch {
|
|
1364
|
+
try {
|
|
1365
|
+
observer?.disconnect();
|
|
1366
|
+
}
|
|
1367
|
+
catch { /* broken observers are already inert */ }
|
|
1368
|
+
observer = undefined;
|
|
1369
|
+
}
|
|
1370
|
+
const view = element.ownerDocument.defaultView;
|
|
1371
|
+
try {
|
|
1372
|
+
view?.addEventListener("resize", update);
|
|
1373
|
+
}
|
|
1374
|
+
catch { /* synthetic window: initial measurement is still valid */ }
|
|
1375
|
+
return () => {
|
|
1376
|
+
try {
|
|
1377
|
+
observer?.disconnect();
|
|
1378
|
+
}
|
|
1379
|
+
catch { /* best-effort cleanup */ }
|
|
1380
|
+
try {
|
|
1381
|
+
view?.removeEventListener("resize", update);
|
|
1382
|
+
}
|
|
1383
|
+
catch { /* best-effort cleanup */ }
|
|
1384
|
+
};
|
|
1385
|
+
}, []);
|
|
1386
|
+
return createElement("div", { ref: host, "data-mun": "GeometryReader", style: { boxSizing: "border-box", width: "100%" } }, reactive.value);
|
|
1387
|
+
}
|
|
1388
|
+
function renderStatefulView({ node, ...forwardedProps }) {
|
|
1389
|
+
const [state] = useState(() => node.state?.(node.props) ?? {});
|
|
1390
|
+
const resolvedProps = { ...node.props, ...state };
|
|
1391
|
+
const reactive = useReactiveGraph(() => node.render(resolvedProps), node.dependencies ? () => node.dependencies(resolvedProps) : undefined, node.dependenciesComplete === true, undefined, pruneCompilerOwnedDependencies);
|
|
1392
|
+
return applyProps(withRenderTransaction(reactive.transaction, () => renderViewNode(reactive.value, renderer)), forwardedProps);
|
|
1393
|
+
}
|
|
1394
|
+
const reactTemplateFactories = new WeakMap();
|
|
1395
|
+
function compileReactTemplate(value) {
|
|
1396
|
+
if (value !== null && typeof value === "object") {
|
|
1397
|
+
if (value.kind === "slot") {
|
|
1398
|
+
const index = value.index;
|
|
1399
|
+
return renderSlot => renderSlot(index);
|
|
1400
|
+
}
|
|
1401
|
+
if (value.kind === "fragment") {
|
|
1402
|
+
const children = value.children.map(compileReactTemplate);
|
|
1403
|
+
return renderSlot => createElement(Fragment, null, ...children.map(child => child(renderSlot)));
|
|
1404
|
+
}
|
|
1405
|
+
if (value.kind === "element") {
|
|
1406
|
+
const type = value.type;
|
|
1407
|
+
const props = value.props;
|
|
1408
|
+
const children = value.children.map(compileReactTemplate);
|
|
1409
|
+
return renderSlot => createElement(type, props, ...children.map(child => child(renderSlot)));
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
const staticValue = value === null || value === undefined || value === false || value === true ? null : value;
|
|
1413
|
+
return () => staticValue;
|
|
1414
|
+
}
|
|
1415
|
+
const renderer = {
|
|
1416
|
+
element(type, props, ...children) {
|
|
1417
|
+
const component = isForeignComponent(type) ? type.component : type;
|
|
1418
|
+
const normalizedProps = normalizeForeignProps(type, props, children);
|
|
1419
|
+
if (typeof component === "string" && isContinuousCornerStyle(normalizedProps?.style)) {
|
|
1420
|
+
return createElement(ContinuousCornerHost, { as: component, ...(normalizedProps ?? {}) }, ...children);
|
|
1421
|
+
}
|
|
1422
|
+
return createElement(component, normalizedProps, ...children);
|
|
1423
|
+
},
|
|
1424
|
+
fragment(children) {
|
|
1425
|
+
return createElement(Fragment, null, ...children);
|
|
1426
|
+
},
|
|
1427
|
+
value(value) {
|
|
1428
|
+
return value;
|
|
1429
|
+
},
|
|
1430
|
+
gpuIsland(node, identity) {
|
|
1431
|
+
return createElement(ReactGPUIslandCanvas, { key: viewIdentityKey(identity), node });
|
|
1432
|
+
},
|
|
1433
|
+
template(node, renderSlot) {
|
|
1434
|
+
let factory = reactTemplateFactories.get(node.template);
|
|
1435
|
+
if (!factory) {
|
|
1436
|
+
factory = compileReactTemplate(node.template.root);
|
|
1437
|
+
reactTemplateFactories.set(node.template, factory);
|
|
1438
|
+
}
|
|
1439
|
+
return factory(renderSlot);
|
|
1440
|
+
},
|
|
1441
|
+
collection(node, renderEntry, identity) {
|
|
1442
|
+
return createElement(ReactCollectionHost, { key: viewIdentityKey(identity), node, renderEntry });
|
|
1443
|
+
},
|
|
1444
|
+
modifier(content, modifier, renderArgument) {
|
|
1445
|
+
if (modifier.name === "frame") {
|
|
1446
|
+
return createElement("div", modifierProps(modifier), content);
|
|
1447
|
+
}
|
|
1448
|
+
if ((modifier.name === "background" || modifier.name === "overlay" || modifier.name === "listRowBackground") && typeof modifier.arguments[0] !== "string" && modifier.arguments[0] != null && renderArgument) {
|
|
1449
|
+
// The layer rectangle never intercepts input; an overlay's own content does (matches @mun-ui/web layerStyles).
|
|
1450
|
+
const layer = modifier.name === "overlay" ? createElement("div", { style: { display: "contents", pointerEvents: "auto" } }, renderArgument(0)) : renderArgument(0);
|
|
1451
|
+
const layerNode = createElement("div", { style: { gridArea: "1 / 1", placeSelf: alignmentCSSPlace(modifier.arguments[1]), pointerEvents: "none" } }, layer);
|
|
1452
|
+
const contentNode = createElement("div", { style: { gridArea: "1 / 1", minWidth: 0, minHeight: 0 } }, content);
|
|
1453
|
+
return createElement("div", { style: { display: "grid", position: "relative" } }, modifier.name !== "overlay" ? layerNode : contentNode, modifier.name !== "overlay" ? contentNode : layerNode);
|
|
1454
|
+
}
|
|
1455
|
+
return applyProps(content, modifierProps(modifier));
|
|
1456
|
+
},
|
|
1457
|
+
view(node, _render, identity) {
|
|
1458
|
+
return createElement(renderStatefulView, { key: viewIdentityKey(identity), node });
|
|
1459
|
+
},
|
|
1460
|
+
geometry(_node, render) {
|
|
1461
|
+
return createElement(GeometryHost, { render });
|
|
1462
|
+
},
|
|
1463
|
+
};
|
|
1464
|
+
function RenderValue({ value, body }) {
|
|
1465
|
+
const reactive = useReactiveGraph(() => body ? body() : value ?? null);
|
|
1466
|
+
return withRenderTransaction(reactive.transaction, () => renderViewNode(reactive.value, renderer));
|
|
1467
|
+
}
|
|
1468
|
+
export function render(value) {
|
|
1469
|
+
return renderViewNode(value, renderer);
|
|
1470
|
+
}
|
|
1471
|
+
/** Subscribe a React component to a Mun State without making State a React primitive. */
|
|
1472
|
+
export function useMunState(state) {
|
|
1473
|
+
useSyncExternalStore(listener => subscribeState(state, listener), () => stateVersion(state), () => stateVersion(state));
|
|
1474
|
+
return state.value;
|
|
1475
|
+
}
|
|
1476
|
+
export function MunView({ value, render: renderBody, body, props }) {
|
|
1477
|
+
const factory = renderBody ?? (body ? () => body(props ?? {}) : undefined);
|
|
1478
|
+
return createElement(RenderValue, { value, body: factory });
|
|
1479
|
+
}
|
|
1480
|
+
/** Wrap a graph factory as a React component, retaining React props at the bridge. */
|
|
1481
|
+
export function createReactView(body) {
|
|
1482
|
+
return (props) => createElement((MunView), { body, props });
|
|
1483
|
+
}
|
|
1484
|
+
function StatefulMunView({ definition, props, }) {
|
|
1485
|
+
const [state] = useState(() => definition.state(props));
|
|
1486
|
+
const reactive = useReactiveGraph(() => definition.body(state, props), definition.dependencies ? () => definition.dependencies(state, props) : undefined, definition.dependenciesComplete === true);
|
|
1487
|
+
return withRenderTransaction(reactive.transaction, () => renderViewNode(reactive.value, renderer));
|
|
1488
|
+
}
|
|
1489
|
+
export function statefulView(definition) {
|
|
1490
|
+
return (props) => createElement(StatefulMunView, { definition, props });
|
|
1491
|
+
}
|
|
1492
|
+
export function view(input) {
|
|
1493
|
+
if (typeof input === "function")
|
|
1494
|
+
return createReactView(input);
|
|
1495
|
+
return (props) => createElement(StatefulMunView, { definition: input, props });
|
|
1496
|
+
}
|
|
1497
|
+
/** Mount a graph into a React-managed DOM root, optionally hydrating SSR markup. */
|
|
1498
|
+
export function mount(value, target, options = {}) {
|
|
1499
|
+
const element = createElement(MunView, { value });
|
|
1500
|
+
let root;
|
|
1501
|
+
if (options.hydrate) {
|
|
1502
|
+
root = hydrateRoot(target, element);
|
|
1503
|
+
}
|
|
1504
|
+
else {
|
|
1505
|
+
root = createRoot(target);
|
|
1506
|
+
root.render(element);
|
|
1507
|
+
}
|
|
1508
|
+
return () => root.unmount();
|
|
1509
|
+
}
|
|
1510
|
+
export function createRenderer() {
|
|
1511
|
+
return renderer;
|
|
1512
|
+
}
|
|
1513
|
+
//# sourceMappingURL=renderer.js.map
|