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