@mun-ui/web 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.
Files changed (107) hide show
  1. package/LICENSE +21 -0
  2. package/dist/accessibility.d.ts +3 -0
  3. package/dist/accessibility.d.ts.map +1 -0
  4. package/dist/accessibility.js +195 -0
  5. package/dist/accessibility.js.map +1 -0
  6. package/dist/content-transition.d.ts +23 -0
  7. package/dist/content-transition.d.ts.map +1 -0
  8. package/dist/content-transition.js +780 -0
  9. package/dist/content-transition.js.map +1 -0
  10. package/dist/continuous-corners.d.ts +3 -0
  11. package/dist/continuous-corners.d.ts.map +1 -0
  12. package/dist/continuous-corners.js +71 -0
  13. package/dist/continuous-corners.js.map +1 -0
  14. package/dist/control-styles.d.ts +7 -0
  15. package/dist/control-styles.d.ts.map +1 -0
  16. package/dist/control-styles.js +141 -0
  17. package/dist/control-styles.js.map +1 -0
  18. package/dist/controls.d.ts +4 -0
  19. package/dist/controls.d.ts.map +1 -0
  20. package/dist/controls.js +249 -0
  21. package/dist/controls.js.map +1 -0
  22. package/dist/devtools.d.ts +50 -0
  23. package/dist/devtools.d.ts.map +1 -0
  24. package/dist/devtools.js +118 -0
  25. package/dist/devtools.js.map +1 -0
  26. package/dist/dom.d.ts +12 -0
  27. package/dist/dom.d.ts.map +1 -0
  28. package/dist/dom.js +5427 -0
  29. package/dist/dom.js.map +1 -0
  30. package/dist/element-motion.d.ts +29 -0
  31. package/dist/element-motion.d.ts.map +1 -0
  32. package/dist/element-motion.js +463 -0
  33. package/dist/element-motion.js.map +1 -0
  34. package/dist/focus.d.ts +3 -0
  35. package/dist/focus.d.ts.map +1 -0
  36. package/dist/focus.js +70 -0
  37. package/dist/focus.js.map +1 -0
  38. package/dist/gpu-island.d.ts +123 -0
  39. package/dist/gpu-island.d.ts.map +1 -0
  40. package/dist/gpu-island.js +1093 -0
  41. package/dist/gpu-island.js.map +1 -0
  42. package/dist/hydration.d.ts +18 -0
  43. package/dist/hydration.d.ts.map +1 -0
  44. package/dist/hydration.js +228 -0
  45. package/dist/hydration.js.map +1 -0
  46. package/dist/index.d.ts +9 -0
  47. package/dist/index.d.ts.map +1 -0
  48. package/dist/index.js +7 -0
  49. package/dist/index.js.map +1 -0
  50. package/dist/lazy-index.d.ts +42 -0
  51. package/dist/lazy-index.d.ts.map +1 -0
  52. package/dist/lazy-index.js +136 -0
  53. package/dist/lazy-index.js.map +1 -0
  54. package/dist/motion.d.ts +49 -0
  55. package/dist/motion.d.ts.map +1 -0
  56. package/dist/motion.js +793 -0
  57. package/dist/motion.js.map +1 -0
  58. package/dist/patch-ir.d.ts +44 -0
  59. package/dist/patch-ir.d.ts.map +1 -0
  60. package/dist/patch-ir.js +221 -0
  61. package/dist/patch-ir.js.map +1 -0
  62. package/dist/path-interpolation.d.ts +29 -0
  63. package/dist/path-interpolation.d.ts.map +1 -0
  64. package/dist/path-interpolation.js +318 -0
  65. package/dist/path-interpolation.js.map +1 -0
  66. package/dist/presentation.d.ts +4 -0
  67. package/dist/presentation.d.ts.map +1 -0
  68. package/dist/presentation.js +207 -0
  69. package/dist/presentation.js.map +1 -0
  70. package/dist/props.d.ts +24 -0
  71. package/dist/props.d.ts.map +1 -0
  72. package/dist/props.js +719 -0
  73. package/dist/props.js.map +1 -0
  74. package/dist/shared.d.ts +79 -0
  75. package/dist/shared.d.ts.map +1 -0
  76. package/dist/shared.js +806 -0
  77. package/dist/shared.js.map +1 -0
  78. package/dist/ssr.d.ts +3 -0
  79. package/dist/ssr.d.ts.map +1 -0
  80. package/dist/ssr.js +280 -0
  81. package/dist/ssr.js.map +1 -0
  82. package/dist/symbols.d.ts +5 -0
  83. package/dist/symbols.d.ts.map +1 -0
  84. package/dist/symbols.js +37 -0
  85. package/dist/symbols.js.map +1 -0
  86. package/dist/text-layout.d.ts +10 -0
  87. package/dist/text-layout.d.ts.map +1 -0
  88. package/dist/text-layout.js +280 -0
  89. package/dist/text-layout.js.map +1 -0
  90. package/dist/transition.d.ts +12 -0
  91. package/dist/transition.d.ts.map +1 -0
  92. package/dist/transition.js +172 -0
  93. package/dist/transition.js.map +1 -0
  94. package/dist/ui-ir.d.ts +12 -0
  95. package/dist/ui-ir.d.ts.map +1 -0
  96. package/dist/ui-ir.js +324 -0
  97. package/dist/ui-ir.js.map +1 -0
  98. package/dist/url-policy.d.ts +2 -0
  99. package/dist/url-policy.d.ts.map +1 -0
  100. package/dist/url-policy.js +27 -0
  101. package/dist/url-policy.js.map +1 -0
  102. package/dist/visual-effects.d.ts +5 -0
  103. package/dist/visual-effects.d.ts.map +1 -0
  104. package/dist/visual-effects.js +166 -0
  105. package/dist/visual-effects.js.map +1 -0
  106. package/package.json +47 -3
  107. package/README.md +0 -3
package/dist/props.js ADDED
@@ -0,0 +1,719 @@
1
+ import { isSafeUrlAttribute } from "./url-policy.js";
2
+ import { classNameOf } from "@mun-ui/core/compat";
3
+ import { cssPropertyName, isEventPropName, htmlAttributeName, isBooleanHtmlAttribute, isEnumeratedBooleanAttribute, normalizedTextAreaValue } from "./shared.js";
4
+ import { animateDomAttribute, animateDomStyles, cancelDomAnimations, cancelDomAttributeAnimation, cancelDomStyleAnimation } from "./motion.js";
5
+ import { syncFocusScope } from "./focus.js";
6
+ import { syncContinuousCorners } from "./continuous-corners.js";
7
+ import { syncControlStyles } from "./control-styles.js";
8
+ import { syncTextLayout } from "./text-layout.js";
9
+ import { syncVisualEffects } from "./visual-effects.js";
10
+ import { syncBuiltinControls } from "./controls.js";
11
+ import { syncSymbolRenderingMode } from "./symbols.js";
12
+ import { syncAccessibilityElement } from "./accessibility.js";
13
+ export function syncBrowserFeatures(element, props) {
14
+ syncContinuousCorners(element, props?.style);
15
+ syncControlStyles(element);
16
+ syncTextLayout(element, props?.style);
17
+ syncVisualEffects(element, props);
18
+ syncBuiltinControls(element);
19
+ syncSymbolRenderingMode(element);
20
+ syncAccessibilityElement(element, props);
21
+ }
22
+ const XLINK_NS = "http://www.w3.org/1999/xlink";
23
+ const XML_NS = "http://www.w3.org/XML/1998/namespace";
24
+ function styleDeclaration(element) {
25
+ return element.style;
26
+ }
27
+ function domStyle(element, value) {
28
+ if (typeof value !== "object" || value === null) {
29
+ if (typeof value === "string")
30
+ element.setAttribute("style", value);
31
+ return;
32
+ }
33
+ const style = styleDeclaration(element);
34
+ if (!style)
35
+ return;
36
+ for (const [key, item] of Object.entries(value)) {
37
+ if (item === undefined || item === null)
38
+ continue;
39
+ style.setProperty(cssPropertyName(key), String(item));
40
+ }
41
+ }
42
+ const refPairs = new WeakMap();
43
+ export function setDomRef(reference, element) {
44
+ const pair = reference && typeof reference === "object" ? refPairs.get(reference) : undefined;
45
+ if (pair) {
46
+ const cleanups = pair.map(item => setDomRef(item, element));
47
+ return () => {
48
+ const errors = [];
49
+ for (const cleanup of cleanups) {
50
+ try {
51
+ cleanup();
52
+ }
53
+ catch (error) {
54
+ errors.push(error);
55
+ }
56
+ }
57
+ if (errors.length === 1)
58
+ throw errors[0];
59
+ if (errors.length > 1)
60
+ throw new AggregateError(errors, "DOM ref cleanup failed");
61
+ };
62
+ }
63
+ if (typeof reference === "function") {
64
+ reference(element);
65
+ return () => reference(null);
66
+ }
67
+ if (!reference || typeof reference !== "object")
68
+ return () => undefined;
69
+ const target = reference;
70
+ try {
71
+ const descriptor = Object.getOwnPropertyDescriptor(reference, "current");
72
+ if (!descriptor || !("value" in descriptor) || descriptor.writable !== true)
73
+ return () => undefined;
74
+ target.current = element;
75
+ }
76
+ catch {
77
+ return () => undefined;
78
+ }
79
+ return () => {
80
+ try {
81
+ const descriptor = Object.getOwnPropertyDescriptor(reference, "current");
82
+ if (descriptor && "value" in descriptor && descriptor.writable === true && descriptor.value === element)
83
+ target.current = null;
84
+ }
85
+ catch { /* detached hostile refs are already inert */ }
86
+ };
87
+ }
88
+ // An elementRef modifier must not replace a View's internal lifecycle ref.
89
+ // Keep the combined reference stable across renders to avoid false unmounts.
90
+ // Cleanup belongs to each mounted element, even when callers share ref pairs.
91
+ const combinedRefs = new WeakMap();
92
+ export function combineDomRefs(previous, incoming) {
93
+ const isReference = (value) => value !== null && (typeof value === "object" || typeof value === "function");
94
+ if (!isReference(previous))
95
+ return incoming;
96
+ if (!isReference(incoming) || previous === incoming)
97
+ return previous;
98
+ let byIncoming = combinedRefs.get(previous);
99
+ if (!byIncoming)
100
+ combinedRefs.set(previous, byIncoming = new WeakMap());
101
+ let combined = byIncoming.get(incoming);
102
+ if (!combined) {
103
+ combined = Object.freeze({});
104
+ refPairs.set(combined, [previous, incoming]);
105
+ byIncoming.set(incoming, combined);
106
+ }
107
+ return combined;
108
+ }
109
+ function domEvent(key) {
110
+ const raw = key.slice(2);
111
+ const capture = raw.endsWith("Capture") && raw !== "GotPointerCapture" && raw !== "LostPointerCapture";
112
+ const normalized = (capture ? raw.slice(0, -"Capture".length) : raw).toLowerCase();
113
+ const name = normalized === "doubleclick" ? "dblclick" : normalized;
114
+ return { name, capture, storageKey: `${capture ? "capture" : "bubble"}:${name}` };
115
+ }
116
+ export function setDomEvent(element, key, value, context, attach = true) {
117
+ const event = domEvent(key);
118
+ const listeners = context.eventListeners.get(element) ?? new Map();
119
+ const hadListeners = listeners.size > 0;
120
+ const previous = listeners.get(event.storageKey);
121
+ if (attach && typeof value === "function") {
122
+ // Keep one native listener attached for the lifetime of the prop and only
123
+ // replace the current callback. Rendered event closures are commonly new
124
+ // function identities even when the DOM node is reused; remove/add on
125
+ // every reconciliation is pure overhead and can perturb event ordering.
126
+ if (previous) {
127
+ previous.handler = value;
128
+ }
129
+ else {
130
+ const invoker = ((nativeEvent) => invoker.handler?.call(element, nativeEvent));
131
+ invoker.handler = value;
132
+ element.addEventListener(event.name, invoker, event.capture);
133
+ listeners.set(event.storageKey, invoker);
134
+ }
135
+ }
136
+ else if (previous) {
137
+ element.removeEventListener(event.name, previous, event.capture);
138
+ listeners.delete(event.storageKey);
139
+ }
140
+ const hasListeners = listeners.size > 0;
141
+ if (hasListeners)
142
+ context.eventListeners.set(element, listeners);
143
+ else
144
+ context.eventListeners.delete(element);
145
+ if (!hadListeners && hasListeners)
146
+ context.eventTargetCount += 1;
147
+ else if (hadListeners && !hasListeners)
148
+ context.eventTargetCount = Math.max(0, context.eventTargetCount - 1);
149
+ }
150
+ export function clearDomEvents(element, context) {
151
+ const listeners = context.eventListeners.get(element);
152
+ if (!listeners)
153
+ return;
154
+ for (const [storageKey, listener] of listeners) {
155
+ const separator = storageKey.indexOf(":");
156
+ const capture = storageKey.slice(0, separator) === "capture";
157
+ element.removeEventListener(storageKey.slice(separator + 1), listener, capture);
158
+ }
159
+ context.eventListeners.delete(element);
160
+ context.eventTargetCount = Math.max(0, context.eventTargetCount - 1);
161
+ }
162
+ function namespacedAttribute(name) {
163
+ if (name.startsWith("xlink:"))
164
+ return { namespace: XLINK_NS, localName: name.slice(6), qualifiedName: name };
165
+ if (name.startsWith("xml:"))
166
+ return { namespace: XML_NS, localName: name.slice(4), qualifiedName: name };
167
+ return { localName: name, qualifiedName: name };
168
+ }
169
+ function setAttribute(element, name, value) {
170
+ if (!isSafeUrlAttribute(name, value)) {
171
+ removeAttribute(element, name);
172
+ return;
173
+ }
174
+ const attribute = namespacedAttribute(name);
175
+ if (attribute.namespace)
176
+ element.setAttributeNS(attribute.namespace, attribute.qualifiedName, value);
177
+ else
178
+ element.setAttribute(attribute.qualifiedName, value);
179
+ }
180
+ function removeAttribute(element, name) {
181
+ const attribute = namespacedAttribute(name);
182
+ if (attribute.namespace)
183
+ element.removeAttributeNS(attribute.namespace, attribute.localName);
184
+ else
185
+ element.removeAttribute(attribute.qualifiedName);
186
+ }
187
+ function setDomProperty(element, name, value) {
188
+ if (name !== "value" && name !== "checked" && name !== "selected" && name !== "disabled" && name !== "multiple" && name !== "muted")
189
+ return;
190
+ try {
191
+ element[name] = value;
192
+ }
193
+ catch { /* attribute remains authoritative */ }
194
+ }
195
+ function isHtmlTextArea(element) {
196
+ return element.namespaceURI === "http://www.w3.org/1999/xhtml" && element.localName.toLowerCase() === "textarea";
197
+ }
198
+ function isHtmlSelect(element) {
199
+ return element.namespaceURI === "http://www.w3.org/1999/xhtml" && element.localName.toLowerCase() === "select";
200
+ }
201
+ export function synchronizeDomSelectValue(element, props) {
202
+ const value = props?.value;
203
+ if (!isHtmlSelect(element) || value === undefined || value === null)
204
+ return;
205
+ const normalized = String(value);
206
+ let matched = false;
207
+ for (const option of element.querySelectorAll("option")) {
208
+ const selected = !matched && option.value === normalized;
209
+ if (selected)
210
+ matched = true;
211
+ if (selected)
212
+ option.setAttribute("selected", "");
213
+ else
214
+ option.removeAttribute("selected");
215
+ }
216
+ setDomProperty(element, "value", normalized);
217
+ removeAttribute(element, "value");
218
+ }
219
+ function applyAttributeValue(element, key, value) {
220
+ if (key === "unsafeHTML") {
221
+ if (typeof value !== "string")
222
+ throw new TypeError("unsafeHTML must be a string");
223
+ if (element.innerHTML !== value)
224
+ element.innerHTML = value;
225
+ return;
226
+ }
227
+ const name = htmlAttributeName(key);
228
+ if (!isSafeUrlAttribute(name, value)) {
229
+ removeAttribute(element, name);
230
+ return;
231
+ }
232
+ const customElement = element.localName.includes("-");
233
+ if (customElement && (key in element || typeof value === "object" || typeof value === "function")) {
234
+ try {
235
+ ;
236
+ element[key] = value;
237
+ if (typeof value === "object" || typeof value === "function")
238
+ removeAttribute(element, name);
239
+ return;
240
+ }
241
+ catch { /* fall through to attribute semantics */ }
242
+ }
243
+ if (isBooleanHtmlAttribute(name)) {
244
+ setDomProperty(element, name, Boolean(value));
245
+ if (value)
246
+ setAttribute(element, name, "");
247
+ else
248
+ removeAttribute(element, name);
249
+ return;
250
+ }
251
+ if (value === false || value === true) {
252
+ if (name.startsWith("aria-") || name.startsWith("data-") || isEnumeratedBooleanAttribute(name)) {
253
+ setAttribute(element, name, String(value));
254
+ }
255
+ else if (value) {
256
+ setAttribute(element, name, "");
257
+ }
258
+ else {
259
+ setAttribute(element, name, "false");
260
+ }
261
+ setDomProperty(element, name, value);
262
+ return;
263
+ }
264
+ if (name === "value" && isHtmlTextArea(element)) {
265
+ // A textarea's initial value is represented by its text content, not a
266
+ // value attribute. Keep defaultValue and the live controlled value aligned.
267
+ const normalized = normalizedTextAreaValue(value);
268
+ element.textContent = normalized;
269
+ setDomProperty(element, name, normalized);
270
+ removeAttribute(element, name);
271
+ return;
272
+ }
273
+ if (name === "value" && isHtmlSelect(element)) {
274
+ setDomProperty(element, name, String(value));
275
+ removeAttribute(element, name);
276
+ return;
277
+ }
278
+ setDomProperty(element, name, value);
279
+ setAttribute(element, name, String(value));
280
+ }
281
+ function rememberDomKey(element, props, context) {
282
+ const nextKey = typeof props?.key === "string" || typeof props?.key === "number" ? props.key : undefined;
283
+ if (nextKey === undefined)
284
+ return;
285
+ context.hasDomKeys = true;
286
+ context.domKeys.set(element, nextKey);
287
+ }
288
+ /** Structural graph fields are reconciler metadata, never DOM properties. */
289
+ function renderableDomProps(props) {
290
+ if (!props)
291
+ return undefined;
292
+ const keys = Object.keys(props);
293
+ let structural = 0;
294
+ for (const key of keys)
295
+ if (key === "key" || key === "children")
296
+ structural += 1;
297
+ if (structural === 0)
298
+ return props;
299
+ if (structural === keys.length)
300
+ return undefined;
301
+ const filtered = {};
302
+ for (const key of keys) {
303
+ if (key === "key" || key === "children")
304
+ continue;
305
+ filtered[key] = props[key];
306
+ }
307
+ return filtered;
308
+ }
309
+ function trackDomRef(element, props, context) {
310
+ const reference = props?.ref;
311
+ if (reference !== undefined && reference !== null) {
312
+ context.hasRefs = true;
313
+ context.refElements.add(element);
314
+ }
315
+ else {
316
+ context.refElements.delete(element);
317
+ }
318
+ }
319
+ function stageDomProps(element, props, context) {
320
+ rememberDomKey(element, props, context);
321
+ const renderable = renderableDomProps(props);
322
+ if (!renderable)
323
+ return;
324
+ const previous = context.domProps.get(element);
325
+ const hasClass = Object.prototype.hasOwnProperty.call(renderable, "class") || Object.prototype.hasOwnProperty.call(renderable, "className");
326
+ if (!previous && !hasClass) {
327
+ // Element props are already snapshotted by @mun-ui/core. Keeping that
328
+ // immutable record directly avoids allocating another object for the very
329
+ // common first staging pass; later modifiers still merge through the path
330
+ // below when the same candidate receives more props.
331
+ context.domProps.set(element, renderable);
332
+ }
333
+ else {
334
+ const before = previous ?? {};
335
+ const previousStyle = before.style && typeof before.style === "object" ? before.style : undefined;
336
+ const nextStyle = renderable.style && typeof renderable.style === "object" ? renderable.style : undefined;
337
+ const remembered = {
338
+ ...before,
339
+ ...renderable,
340
+ ...(nextStyle ? { style: { ...(previousStyle ?? {}), ...nextStyle } } : {}),
341
+ };
342
+ if (hasClass) {
343
+ const beforeClass = classNameOf(before.class ?? before.className);
344
+ const incoming = classNameOf(renderable.class ?? renderable.className);
345
+ const combined = [beforeClass, incoming].filter(Boolean).join(" ");
346
+ delete remembered.className;
347
+ if (combined)
348
+ remembered.class = combined;
349
+ else
350
+ delete remembered.class;
351
+ }
352
+ context.domProps.set(element, remembered);
353
+ }
354
+ trackDomRef(element, context.domProps.get(element), context);
355
+ }
356
+ export function rememberDomProps(element, props, context, merge = true) {
357
+ rememberDomKey(element, props, context);
358
+ const renderable = renderableDomProps(props);
359
+ if (!renderable) {
360
+ if (!merge) {
361
+ context.domProps.delete(element);
362
+ context.refElements.delete(element);
363
+ }
364
+ return;
365
+ }
366
+ const previousStored = merge ? context.domProps.get(element) : undefined;
367
+ const hasClass = Object.prototype.hasOwnProperty.call(renderable, "class") || Object.prototype.hasOwnProperty.call(renderable, "className");
368
+ if (!previousStored && !hasClass) {
369
+ // Core graph props are immutable snapshots, so a fresh node can retain the
370
+ // record directly instead of cloning it merely for future reconciliation.
371
+ context.domProps.set(element, renderable);
372
+ trackDomRef(element, renderable, context);
373
+ return;
374
+ }
375
+ const previous = previousStored ?? {};
376
+ const currentStyle = previous.style && typeof previous.style === "object" ? previous.style : {};
377
+ const nextStyle = renderable.style && typeof renderable.style === "object" ? renderable.style : undefined;
378
+ const remembered = {
379
+ ...previous,
380
+ ...renderable,
381
+ ...(nextStyle ? { style: { ...currentStyle, ...nextStyle } } : {}),
382
+ };
383
+ if (hasClass && element.getAttribute("class") !== null) {
384
+ remembered.class = element.getAttribute("class") ?? "";
385
+ delete remembered.className;
386
+ }
387
+ context.domProps.set(element, remembered);
388
+ trackDomRef(element, remembered, context);
389
+ }
390
+ function mergeHydrationProps(previous, next) {
391
+ const previousStyle = previous.style && typeof previous.style === "object" ? previous.style : undefined;
392
+ const nextStyle = next.style && typeof next.style === "object" ? next.style : undefined;
393
+ return { ...previous, ...next, ...(previousStyle && nextStyle ? { style: { ...previousStyle, ...nextStyle } } : {}) };
394
+ }
395
+ function applyDomPropsNow(element, props, context, remember) {
396
+ if (context.hydrating) {
397
+ // Modifiers apply their props as further chunks on the same element.
398
+ // Accumulate them like rememberDomProps does, or the last chunk (say a
399
+ // clipShape style) would hide the element's own ref and event handlers
400
+ // from hydration activation.
401
+ const previous = context.hydrationProps.get(element);
402
+ context.hydrationProps.set(element, previous && props ? mergeHydrationProps(previous, props) : props ?? previous);
403
+ }
404
+ if (context.hydrating && context.hydrationLiveNodes?.has(element)) {
405
+ // A speculative hydration pass must not mutate the SSR DOM before the
406
+ // entire graph has been structurally and semantically validated. Keep the
407
+ // same staged prop merge semantics used by detached candidates, then let
408
+ // the successful hydration activation attach events/properties in one pass.
409
+ if (props)
410
+ stageDomProps(element, props, context);
411
+ context.hydrationProps.set(element, context.domProps.get(element) ?? props);
412
+ return;
413
+ }
414
+ if (!props)
415
+ return;
416
+ if (context.stagingProps && !context.hydrating) {
417
+ stageDomProps(element, props, context);
418
+ return;
419
+ }
420
+ rememberDomKey(element, props, context);
421
+ const renderable = renderableDomProps(props);
422
+ if (!renderable)
423
+ return;
424
+ const entries = Object.entries(renderable);
425
+ if (entries.length === 0)
426
+ return;
427
+ // Keep callback/object refs indexed even when props are applied directly
428
+ // (for example during a direct initial mount or staged-prop activation).
429
+ // commitRefs() relies on refElements rather than scanning the DOM.
430
+ trackDomRef(element, renderable, context);
431
+ for (const [key, value] of entries) {
432
+ if (key === "children" || key === "key")
433
+ continue;
434
+ if (isEventPropName(key)) {
435
+ setDomEvent(element, key, value, context, !context.hydrating && !context.stagingEvents && typeof value === "function");
436
+ continue;
437
+ }
438
+ if (value === undefined || value === null)
439
+ continue;
440
+ if (key === "style") {
441
+ domStyle(element, value);
442
+ continue;
443
+ }
444
+ if (key === "className" || key === "class") {
445
+ const next = [element.getAttribute("class"), classNameOf(value)].filter(Boolean).join(" ");
446
+ if (next)
447
+ element.setAttribute("class", next);
448
+ continue;
449
+ }
450
+ if (key === "ref")
451
+ continue;
452
+ applyAttributeValue(element, key, value);
453
+ }
454
+ if (remember)
455
+ rememberDomProps(element, props, context);
456
+ }
457
+ export function applyDomProps(element, props, context) {
458
+ applyDomPropsNow(element, props, context, true);
459
+ if (!context.stagingProps && !context.hydrating && props
460
+ && Object.prototype.hasOwnProperty.call(props, "data-mun-focus-scope")) {
461
+ syncFocusScope(element, props["data-mun-focus-scope"]);
462
+ }
463
+ if (!context.stagingProps && !context.hydrating)
464
+ syncBrowserFeatures(element, context.domProps.get(element));
465
+ }
466
+ export function commitStagedDomProps(element, context) {
467
+ const props = context.domProps.get(element);
468
+ if (!props || Object.keys(props).length === 0)
469
+ return;
470
+ const stagingProps = context.stagingProps;
471
+ const stagingEvents = context.stagingEvents;
472
+ context.stagingProps = false;
473
+ context.stagingEvents = false;
474
+ try {
475
+ // stageDomProps already holds the normalized snapshot. Do not clone it a
476
+ // second time merely because the candidate is becoming live.
477
+ applyDomPropsNow(element, props, context, false);
478
+ if (Object.prototype.hasOwnProperty.call(props, "data-mun-focus-scope")) {
479
+ syncFocusScope(element, props["data-mun-focus-scope"]);
480
+ }
481
+ syncBrowserFeatures(element, props);
482
+ }
483
+ finally {
484
+ context.stagingProps = stagingProps;
485
+ context.stagingEvents = stagingEvents;
486
+ }
487
+ }
488
+ function removeDomProp(element, key) {
489
+ if (key === "unsafeHTML") {
490
+ element.innerHTML = "";
491
+ return;
492
+ }
493
+ if (key === "style") {
494
+ element.removeAttribute("style");
495
+ return;
496
+ }
497
+ if (key === "class" || key === "className") {
498
+ element.removeAttribute("class");
499
+ return;
500
+ }
501
+ const name = htmlAttributeName(key);
502
+ if (element.localName.includes("-") && key in element) {
503
+ try {
504
+ element[key] = undefined;
505
+ }
506
+ catch { /* remove the attribute below */ }
507
+ }
508
+ if (isBooleanHtmlAttribute(name))
509
+ setDomProperty(element, name, false);
510
+ else if (name === "value")
511
+ setDomProperty(element, name, "");
512
+ if (key !== "children" && key !== "key" && key !== "ref" && !isEventPropName(key))
513
+ removeAttribute(element, name);
514
+ }
515
+ function sameDomProps(previous, next, nextKeys) {
516
+ const previousKeys = Object.keys(previous);
517
+ if (previousKeys.length !== nextKeys.length)
518
+ return false;
519
+ for (const key of nextKeys) {
520
+ if (!Object.prototype.hasOwnProperty.call(previous, key))
521
+ return false;
522
+ if (Object.is(previous[key], next[key]))
523
+ continue;
524
+ // View bodies rebuild their style object on every render. Comparing it by
525
+ // identity sends every styled element through the full per-key style diff
526
+ // even when nothing changed, so compare plain style records shallowly.
527
+ if (key === "style" && shallowStyleEqual(previous[key], next[key]))
528
+ continue;
529
+ return false;
530
+ }
531
+ return true;
532
+ }
533
+ function shallowStyleEqual(left, right) {
534
+ if (typeof left !== "object" || left === null || typeof right !== "object" || right === null)
535
+ return false;
536
+ const leftRecord = left;
537
+ const rightRecord = right;
538
+ let leftCount = 0;
539
+ for (const key in leftRecord) {
540
+ if (!Object.prototype.hasOwnProperty.call(leftRecord, key))
541
+ continue;
542
+ leftCount += 1;
543
+ if (!Object.prototype.hasOwnProperty.call(rightRecord, key) || !Object.is(leftRecord[key], rightRecord[key]))
544
+ return false;
545
+ }
546
+ let rightCount = 0;
547
+ for (const key in rightRecord)
548
+ if (Object.prototype.hasOwnProperty.call(rightRecord, key))
549
+ rightCount += 1;
550
+ return leftCount === rightCount;
551
+ }
552
+ function canFastPatchPrimitive(key, value) {
553
+ if (key === "children" || key === "key" || key === "ref" || key === "style" || key === "class" || key === "className")
554
+ return false;
555
+ if (isEventPropName(key))
556
+ return false;
557
+ return value === undefined || value === null || (typeof value !== "object" && typeof value !== "function");
558
+ }
559
+ export function patchDomProps(element, next, context, motionPolicy, attributeMotionPolicy) {
560
+ rememberDomKey(element, next, context);
561
+ const renderable = renderableDomProps(next);
562
+ const previousStored = context.domProps.get(element);
563
+ const nextKeys = renderable ? Object.keys(renderable) : [];
564
+ if (!previousStored && nextKeys.length === 0) {
565
+ context.refElements.delete(element);
566
+ return;
567
+ }
568
+ if (!attributeMotionPolicy && previousStored && renderable && nextKeys.length === 1) {
569
+ const key = nextKeys[0];
570
+ const previousKeys = Object.keys(previousStored);
571
+ if (previousKeys.length === 1 && previousKeys[0] === key
572
+ && canFastPatchPrimitive(key, previousStored[key])
573
+ && canFastPatchPrimitive(key, renderable[key])) {
574
+ if (Object.is(previousStored[key], renderable[key]))
575
+ return;
576
+ if (renderable[key] === undefined || renderable[key] === null) {
577
+ removeDomProp(element, key);
578
+ context.domProps.delete(element);
579
+ context.refElements.delete(element);
580
+ }
581
+ else {
582
+ applyAttributeValue(element, key, renderable[key]);
583
+ context.domProps.set(element, renderable);
584
+ }
585
+ return;
586
+ }
587
+ }
588
+ if (previousStored && renderable && sameDomProps(previousStored, renderable, nextKeys))
589
+ return;
590
+ const previous = previousStored ?? {};
591
+ for (const key of Object.keys(previous)) {
592
+ if (key === "ref" || key === "key" || key === "children")
593
+ continue;
594
+ if (renderable && Object.prototype.hasOwnProperty.call(renderable, key))
595
+ continue;
596
+ if (isEventPropName(key))
597
+ setDomEvent(element, key, undefined, context, false);
598
+ else {
599
+ if (key === "style")
600
+ cancelDomAnimations(element);
601
+ else
602
+ cancelDomAttributeAnimation(element, htmlAttributeName(key));
603
+ removeDomProp(element, key);
604
+ }
605
+ }
606
+ for (const [key, value] of Object.entries(renderable ?? {})) {
607
+ if (key === "children" || key === "key")
608
+ continue;
609
+ if (isEventPropName(key)) {
610
+ setDomEvent(element, key, value, context, typeof value === "function");
611
+ continue;
612
+ }
613
+ if (value === undefined || value === null) {
614
+ if (previous[key] !== undefined)
615
+ removeDomProp(element, key);
616
+ continue;
617
+ }
618
+ if (key === "style") {
619
+ const previousStyle = previous.style;
620
+ if (typeof value === "object" && value !== null && typeof previousStyle === "object" && previousStyle !== null) {
621
+ const style = styleDeclaration(element);
622
+ if (style) {
623
+ const before = previousStyle;
624
+ const after = value;
625
+ for (const styleKey of Object.keys(before)) {
626
+ if (Object.prototype.hasOwnProperty.call(after, styleKey))
627
+ continue;
628
+ const cssName = cssPropertyName(styleKey);
629
+ cancelDomStyleAnimation(element, cssName);
630
+ style.removeProperty(cssName);
631
+ }
632
+ const motionChanges = [];
633
+ const discreteChanges = [];
634
+ for (const [styleKey, styleValue] of Object.entries(after)) {
635
+ if (styleValue === undefined || styleValue === null) {
636
+ if (before[styleKey] !== undefined && before[styleKey] !== null) {
637
+ const cssName = cssPropertyName(styleKey);
638
+ cancelDomStyleAnimation(element, cssName);
639
+ style.removeProperty(cssName);
640
+ }
641
+ continue;
642
+ }
643
+ if (Object.is(before[styleKey], styleValue))
644
+ continue;
645
+ const cssName = cssPropertyName(styleKey);
646
+ const explicitAnimation = motionPolicy?.animationForProperty(cssName, before[styleKey], styleValue);
647
+ const animation = explicitAnimation === undefined ? context.activeTransaction?.animation : explicitAnimation;
648
+ const currentValue = style.getPropertyValue(cssName) || before[styleKey];
649
+ if (animation
650
+ && !context.activeTransaction?.disablesAnimations
651
+ && currentValue !== undefined
652
+ && currentValue !== null) {
653
+ motionChanges.push({ property: cssName, from: currentValue, to: styleValue, animation });
654
+ }
655
+ else {
656
+ discreteChanges.push({ property: cssName, value: styleValue });
657
+ }
658
+ }
659
+ // Start every eligible channel together. Each change still carries its
660
+ // own Animation, so a spring width and linear opacity can share one
661
+ // engine frame without sharing curve state or cancelling each other.
662
+ const animated = animateDomStyles(element, motionChanges);
663
+ for (const change of motionChanges) {
664
+ if (animated.has(change.property))
665
+ continue;
666
+ cancelDomStyleAnimation(element, change.property);
667
+ style.setProperty(change.property, String(change.to));
668
+ }
669
+ for (const change of discreteChanges) {
670
+ cancelDomStyleAnimation(element, change.property);
671
+ style.setProperty(change.property, String(change.value));
672
+ }
673
+ }
674
+ }
675
+ else if (!Object.is(previousStyle, value)) {
676
+ cancelDomAnimations(element);
677
+ element.removeAttribute("style");
678
+ domStyle(element, value);
679
+ }
680
+ continue;
681
+ }
682
+ if (key === "className" || key === "class") {
683
+ const className = classNameOf(value);
684
+ const previousClassName = classNameOf(previous[key]);
685
+ if (className !== previousClassName) {
686
+ if (className)
687
+ element.setAttribute("class", className);
688
+ else
689
+ element.removeAttribute("class");
690
+ }
691
+ continue;
692
+ }
693
+ if (key === "ref")
694
+ continue;
695
+ if (Object.is(previous[key], value))
696
+ continue;
697
+ const attributeName = htmlAttributeName(key);
698
+ const attributeAnimation = attributeMotionPolicy?.animationForAttribute(attributeName, previous[key], value);
699
+ if (attributeAnimation && !context.activeTransaction?.disablesAnimations) {
700
+ const current = element.getAttribute(attributeName) ?? previous[key];
701
+ if (current !== undefined && current !== null
702
+ && animateDomAttribute(element, attributeName, current, value, attributeAnimation))
703
+ continue;
704
+ }
705
+ cancelDomAttributeAnimation(element, attributeName);
706
+ applyAttributeValue(element, key, value);
707
+ }
708
+ if (!renderable || nextKeys.length === 0) {
709
+ context.domProps.delete(element);
710
+ context.refElements.delete(element);
711
+ }
712
+ else {
713
+ context.domProps.set(element, renderable);
714
+ trackDomRef(element, renderable, context);
715
+ }
716
+ syncFocusScope(element, renderable?.["data-mun-focus-scope"]);
717
+ syncBrowserFeatures(element, renderable);
718
+ }
719
+ //# sourceMappingURL=props.js.map