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