@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
@@ -0,0 +1,780 @@
1
+ import { Animation } from "@mun-ui/core/compat";
2
+ import { createInterpolator } from "@mun-ui/animation";
3
+ import { munMotion } from "./element-motion.js";
4
+ import { createSvgPathInterpolator, mapSvgPathBetweenViewBoxes, matchSvgPathLayers, svgPathLength, } from "./path-interpolation.js";
5
+ const activeContentTransitions = new WeakMap();
6
+ function normalizedRect(element) {
7
+ try {
8
+ const rect = element.getBoundingClientRect();
9
+ const value = { left: rect.left, top: rect.top, width: rect.width, height: rect.height };
10
+ return Object.values(value).every(Number.isFinite) && value.width > 0 && value.height > 0 ? value : undefined;
11
+ }
12
+ catch {
13
+ return undefined;
14
+ }
15
+ }
16
+ // One live MediaQueryList per window; its .matches tracks the preference.
17
+ const reducedMotionQueries = new WeakMap();
18
+ function reducedMotion(element) {
19
+ try {
20
+ const view = element.ownerDocument.defaultView;
21
+ if (!view)
22
+ return false;
23
+ let query = reducedMotionQueries.get(view);
24
+ if (query === undefined) {
25
+ query = view.matchMedia?.("(prefers-reduced-motion: reduce)") ?? null;
26
+ reducedMotionQueries.set(view, query);
27
+ }
28
+ return query?.matches === true;
29
+ }
30
+ catch {
31
+ return false;
32
+ }
33
+ }
34
+ function replaceActiveTransition(element, next) {
35
+ activeContentTransitions.get(element)?.cancel();
36
+ if (next)
37
+ activeContentTransitions.set(element, next);
38
+ else
39
+ activeContentTransitions.delete(element);
40
+ }
41
+ export function cancelWebContentTransition(element) {
42
+ replaceActiveTransition(element, undefined);
43
+ }
44
+ function finishTracked(element, handle, cleanup) {
45
+ let finished = false;
46
+ const finish = () => {
47
+ if (finished)
48
+ return;
49
+ finished = true;
50
+ cleanup();
51
+ if (activeContentTransitions.get(element) === tracked)
52
+ activeContentTransitions.delete(element);
53
+ };
54
+ const tracked = {
55
+ finished: handle.finished,
56
+ cancel() { handle.cancel(); finish(); },
57
+ };
58
+ replaceActiveTransition(element, tracked);
59
+ void handle.finished.then(finish, finish);
60
+ return tracked;
61
+ }
62
+ function fallbackDirection(fallback) {
63
+ if (fallback === "downUp")
64
+ return -1;
65
+ if (fallback === "upDown")
66
+ return 1;
67
+ return 0;
68
+ }
69
+ function unitProgress(value) {
70
+ return Math.max(0, Math.min(1, value));
71
+ }
72
+ function stagedString(element, name, propsReader) {
73
+ const value = propsReader?.(element)?.[name];
74
+ if (typeof value === "string")
75
+ return value;
76
+ const attribute = element.getAttribute(name);
77
+ return attribute === null ? undefined : attribute;
78
+ }
79
+ function svgLayerMap(root, propsReader) {
80
+ const result = new Map();
81
+ for (const child of root.children) {
82
+ const id = stagedString(child, "data-mun-symbol-layer", propsReader);
83
+ if (id)
84
+ result.set(id, child);
85
+ }
86
+ return result;
87
+ }
88
+ function isOrdinalLayerId(id) {
89
+ return /^layer:\d+$/.test(id);
90
+ }
91
+ function symbolLayerTarget(element, id, propsReader) {
92
+ return {
93
+ id,
94
+ d: stagedString(element, "d", propsReader),
95
+ fill: stagedString(element, "fill", propsReader),
96
+ stroke: stagedString(element, "stroke", propsReader),
97
+ strokeWidth: stagedString(element, "stroke-width", propsReader) ?? stagedString(element, "strokeWidth", propsReader),
98
+ opacity: stagedString(element, "opacity", propsReader),
99
+ transform: stagedString(element, "transform", propsReader),
100
+ };
101
+ }
102
+ function fixedSvgOverlay(root, rect) {
103
+ const document = root.ownerDocument;
104
+ if (!document.body)
105
+ return undefined;
106
+ const overlay = root.namespaceURI === "http://www.w3.org/2000/svg" && root.localName === "svg"
107
+ ? root.cloneNode(false)
108
+ : document.createElementNS("http://www.w3.org/2000/svg", "svg");
109
+ overlay.removeAttribute("id");
110
+ overlay.removeAttribute("role");
111
+ overlay.removeAttribute("aria-label");
112
+ overlay.setAttribute("aria-hidden", "true");
113
+ overlay.setAttribute("data-mun-symbol-transition-layer", "");
114
+ // Preserve inherited presentation attributes/classes and inline styling from
115
+ // the live symbol. Paths commonly use currentColor or inherit fill/stroke,
116
+ // so recreating a bare <svg> can visibly change the disappearing layer.
117
+ overlay.style.position = "fixed";
118
+ overlay.style.left = `${rect.left}px`;
119
+ overlay.style.top = `${rect.top}px`;
120
+ overlay.style.width = `${rect.width}px`;
121
+ overlay.style.height = `${rect.height}px`;
122
+ overlay.style.pointerEvents = "none";
123
+ overlay.style.overflow = "visible";
124
+ overlay.style.zIndex = "2147483645";
125
+ document.body.appendChild(overlay);
126
+ return overlay;
127
+ }
128
+ function startWholeSymbolTransition(live, oldClone, animation, fallback) {
129
+ const style = live.style;
130
+ const oldStyle = oldClone.style;
131
+ const previousOpacity = style.opacity;
132
+ const previousTransform = style.transform;
133
+ const direction = fallbackDirection(fallback);
134
+ const distance = Math.max(4, (normalizedRect(live)?.height ?? 24) * 0.14);
135
+ const handle = munMotion.animate({
136
+ animation,
137
+ onUpdate(raw) {
138
+ const progress = unitProgress(raw);
139
+ style.opacity = String(progress);
140
+ oldStyle.opacity = String(1 - progress);
141
+ if (direction !== 0) {
142
+ style.transform = `translateY(${direction * distance * (1 - raw)}px)`;
143
+ oldStyle.transform = `translateY(${-direction * distance * raw}px)`;
144
+ }
145
+ },
146
+ });
147
+ finishTracked(live, handle, () => {
148
+ style.opacity = previousOpacity;
149
+ style.transform = previousTransform;
150
+ oldClone.remove();
151
+ });
152
+ }
153
+ function startLayerTransition(live, oldOverlay, enteringIds, animation, fallback) {
154
+ const layers = svgLayerMap(live);
155
+ const entering = [...enteringIds].map(id => layers.get(id)).filter((value) => Boolean(value));
156
+ const oldPaths = oldOverlay ? [...oldOverlay.children] : [];
157
+ if (entering.length === 0 && oldPaths.length === 0) {
158
+ oldOverlay?.remove();
159
+ return;
160
+ }
161
+ const direction = fallbackDirection(fallback);
162
+ const distance = Math.max(3, (normalizedRect(live)?.height ?? 24) * 0.11);
163
+ const saved = entering.map(element => {
164
+ const style = element.style;
165
+ const value = { element, opacity: style.opacity, transform: style.transform, transformBox: style.transformBox, transformOrigin: style.transformOrigin };
166
+ style.transformBox = "fill-box";
167
+ style.transformOrigin = "center";
168
+ return value;
169
+ });
170
+ for (const element of oldPaths) {
171
+ const style = element.style;
172
+ style.transformBox = "fill-box";
173
+ style.transformOrigin = "center";
174
+ }
175
+ const handle = munMotion.animate({
176
+ animation,
177
+ onUpdate(raw) {
178
+ const progress = unitProgress(raw);
179
+ for (const { element } of saved) {
180
+ const style = element.style;
181
+ style.opacity = String(progress);
182
+ if (direction !== 0)
183
+ style.transform = `translateY(${direction * distance * (1 - raw)}px)`;
184
+ }
185
+ for (const element of oldPaths) {
186
+ const style = element.style;
187
+ style.opacity = String(1 - progress);
188
+ if (direction !== 0)
189
+ style.transform = `translateY(${-direction * distance * raw}px)`;
190
+ }
191
+ },
192
+ });
193
+ finishTracked(live, handle, () => {
194
+ for (const item of saved) {
195
+ const style = item.element.style;
196
+ style.opacity = item.opacity;
197
+ style.transform = item.transform;
198
+ style.transformBox = item.transformBox;
199
+ style.transformOrigin = item.transformOrigin;
200
+ }
201
+ oldOverlay?.remove();
202
+ });
203
+ }
204
+ function pathMorph(from, to) {
205
+ if (!from || !to)
206
+ return undefined;
207
+ try {
208
+ return createSvgPathInterpolator(from, to);
209
+ }
210
+ catch {
211
+ return undefined;
212
+ }
213
+ }
214
+ function pathInput(element) {
215
+ const d = element.getAttribute("d");
216
+ if (!d)
217
+ return undefined;
218
+ return {
219
+ id: element.getAttribute("data-mun-symbol-layer") ?? undefined,
220
+ d,
221
+ fill: element.getAttribute("fill") ?? undefined,
222
+ stroke: element.getAttribute("stroke") ?? undefined,
223
+ strokeWidth: element.getAttribute("stroke-width") ?? undefined,
224
+ };
225
+ }
226
+ function targetInput(target) {
227
+ if (!target.d)
228
+ return undefined;
229
+ return { id: target.id, d: target.d, fill: target.fill, stroke: target.stroke, strokeWidth: target.strokeWidth };
230
+ }
231
+ function colorMixer(from, to) {
232
+ if (!from || !to || from === to || from === "none" || to === "none")
233
+ return undefined;
234
+ try {
235
+ return createInterpolator(from, to, { type: "color", color: { space: "oklab" } });
236
+ }
237
+ catch {
238
+ return undefined;
239
+ }
240
+ }
241
+ function numericMixer(from, to) {
242
+ const left = from === null ? Number.NaN : Number(from);
243
+ const right = to === undefined ? Number.NaN : Number(to);
244
+ if (!Number.isFinite(left) || !Number.isFinite(right) || left === right)
245
+ return undefined;
246
+ return progress => String(left + (right - left) * progress);
247
+ }
248
+ function transformMixer(from, to) {
249
+ if (!from || !to || from === to)
250
+ return undefined;
251
+ try {
252
+ return createInterpolator(from, to, { type: "transform" });
253
+ }
254
+ catch {
255
+ return undefined;
256
+ }
257
+ }
258
+ function presentationMorph(source, target) {
259
+ const fill = colorMixer(source.getAttribute("fill"), target.fill);
260
+ const stroke = colorMixer(source.getAttribute("stroke"), target.stroke);
261
+ const strokeWidth = numericMixer(source.getAttribute("stroke-width"), target.strokeWidth);
262
+ const opacity = numericMixer(source.getAttribute("opacity"), target.opacity);
263
+ const transform = transformMixer(source.getAttribute("transform"), target.transform);
264
+ return progress => {
265
+ if (fill)
266
+ source.setAttribute("fill", fill(progress));
267
+ if (stroke)
268
+ source.setAttribute("stroke", stroke(progress));
269
+ if (strokeWidth)
270
+ source.setAttribute("stroke-width", strokeWidth(progress));
271
+ if (opacity)
272
+ source.setAttribute("opacity", opacity(progress));
273
+ if (transform)
274
+ source.setAttribute("transform", transform(progress));
275
+ };
276
+ }
277
+ function isStrokeOnly(target) {
278
+ return Boolean(target.stroke && target.stroke !== "none" && (!target.fill || target.fill === "none"));
279
+ }
280
+ function presentationKindForElement(element) {
281
+ const stroke = element.getAttribute("stroke");
282
+ const fill = element.getAttribute("fill");
283
+ const hasStroke = Boolean(stroke && stroke !== "none");
284
+ const hasFill = Boolean(fill && fill !== "none");
285
+ if (hasStroke && hasFill)
286
+ return "mixed";
287
+ return hasStroke ? "stroke" : "fill";
288
+ }
289
+ /**
290
+ * Morph unmatched semantic layers instead of fading the entire symbol. This is
291
+ * what makes arbitrary icon packs useful: explicit layer names may differ, but
292
+ * their actual geometry still has a continuous path from old to new.
293
+ */
294
+ function startMorphingLayerTransition(live, oldOverlay, targets, animation, fallback, allowTopologyDuplication) {
295
+ const liveLayers = svgLayerMap(live);
296
+ const entering = targets.map(target => liveLayers.get(target.id)).filter((value) => Boolean(value));
297
+ const oldPaths = oldOverlay ? [...oldOverlay.children] : [];
298
+ if (entering.length === 0 && oldPaths.length === 0) {
299
+ oldOverlay?.remove();
300
+ return;
301
+ }
302
+ const savedEntering = entering.map(element => {
303
+ const style = element.style;
304
+ const saved = {
305
+ element,
306
+ opacity: style.opacity,
307
+ transform: style.transform,
308
+ transformBox: style.transformBox,
309
+ transformOrigin: style.transformOrigin,
310
+ };
311
+ style.opacity = "0";
312
+ style.transformBox = "fill-box";
313
+ style.transformOrigin = "center";
314
+ return saved;
315
+ });
316
+ const sourceInputs = oldPaths.map(pathInput);
317
+ const targetInputs = targets.map(targetInput);
318
+ const validSourceIndices = sourceInputs.map((value, index) => value ? index : -1).filter(index => index >= 0);
319
+ const validTargetIndices = targetInputs.map((value, index) => value ? index : -1).filter(index => index >= 0);
320
+ const matches = matchSvgPathLayers(validSourceIndices.map(index => sourceInputs[index]), validTargetIndices.map(index => targetInputs[index]));
321
+ const matchedSources = new Set();
322
+ const matchedTargets = new Set();
323
+ const pairs = matches.map(match => {
324
+ const sourceIndex = validSourceIndices[match.sourceIndex];
325
+ const targetIndex = validTargetIndices[match.targetIndex];
326
+ const source = oldPaths[sourceIndex];
327
+ const target = targets[targetIndex];
328
+ matchedSources.add(sourceIndex);
329
+ matchedTargets.add(targetIndex);
330
+ const morph = pathMorph(source.getAttribute("d"), target.d);
331
+ const style = source.style;
332
+ style.transformBox = "fill-box";
333
+ style.transformOrigin = "center";
334
+ return { source, target, morph, presentation: presentationMorph(source, target), confidence: match.confidence };
335
+ });
336
+ // For unrelated shapes with no semantic common layer, preserve full
337
+ // continuity across topology changes by splitting/merging the closest
338
+ // geometry. When semantic common layers exist, additions/removals should
339
+ // remain additions/removals (e.g. a slash drawing onto Wi-Fi), not steal an
340
+ // unrelated base contour merely to avoid an appearance animation.
341
+ if (allowTopologyDuplication && oldPaths.length > 0) {
342
+ for (let targetIndex = 0; targetIndex < targets.length; targetIndex += 1) {
343
+ if (matchedTargets.has(targetIndex) || !targets[targetIndex].d)
344
+ continue;
345
+ const candidates = oldPaths.map((source, sourceIndex) => ({ source, sourceIndex, input: pathInput(source) })).filter(item => item.input);
346
+ const one = targetInput(targets[targetIndex]);
347
+ if (!one || candidates.length === 0)
348
+ continue;
349
+ const best = matchSvgPathLayers(candidates.map(item => item.input), [one]).sort((a, b) => b.confidence - a.confidence)[0];
350
+ if (!best)
351
+ continue;
352
+ const template = candidates[best.sourceIndex].source;
353
+ const duplicate = template.cloneNode(true);
354
+ oldOverlay?.appendChild(duplicate);
355
+ const style = duplicate.style;
356
+ style.transformBox = "fill-box";
357
+ style.transformOrigin = "center";
358
+ const target = targets[targetIndex];
359
+ pairs.push({
360
+ source: duplicate,
361
+ target,
362
+ morph: pathMorph(duplicate.getAttribute("d"), target.d),
363
+ presentation: presentationMorph(duplicate, target),
364
+ confidence: best.confidence,
365
+ });
366
+ matchedTargets.add(targetIndex);
367
+ }
368
+ }
369
+ const disappearing = oldPaths.filter((_path, index) => !matchedSources.has(index));
370
+ const appearing = savedEntering.filter((_item, index) => !matchedTargets.has(index));
371
+ for (const element of disappearing) {
372
+ const style = element.style;
373
+ style.transformBox = "fill-box";
374
+ style.transformOrigin = "center";
375
+ }
376
+ const disappearingStrokes = new Map();
377
+ for (const element of disappearing) {
378
+ const input = pathInput(element);
379
+ if (input && presentationKindForElement(element) === "stroke") {
380
+ try {
381
+ disappearingStrokes.set(element, Math.max(0.01, svgPathLength(input.d)));
382
+ }
383
+ catch { /* malformed external paths retain the regular fallback */ }
384
+ }
385
+ }
386
+ const direction = fallbackDirection(fallback);
387
+ const distance = Math.max(3, (normalizedRect(live)?.height ?? 24) * 0.1);
388
+ const handle = munMotion.animate({
389
+ animation,
390
+ onUpdate(raw) {
391
+ const progress = unitProgress(raw);
392
+ // Opacity must remain a legal CSS value, while transforms deliberately
393
+ // consume unclamped spring progress so the visual can overshoot/settle.
394
+ const springScale = Math.max(0.5, 1 + (raw - progress) * 0.28);
395
+ for (const { source, morph, presentation, confidence } of pairs) {
396
+ // Poor correspondence should not extrapolate geometry far enough to
397
+ // invert a concave shape. High-confidence matches retain the full
398
+ // spring overshoot; uncertain matches keep the silhouette monotonic
399
+ // while the wrapper still carries spring energy.
400
+ const geometryProgress = confidence >= 0.55 ? raw : progress;
401
+ if (morph)
402
+ source.setAttribute("d", morph(geometryProgress));
403
+ presentation(progress);
404
+ const style = source.style;
405
+ style.opacity = "1";
406
+ style.transform = `scale(${springScale})`;
407
+ }
408
+ for (const element of disappearing) {
409
+ const style = element.style;
410
+ const strokeLength = disappearingStrokes.get(element);
411
+ if (strokeLength !== undefined) {
412
+ style.opacity = "1";
413
+ style.strokeDasharray = String(strokeLength);
414
+ style.strokeDashoffset = String(strokeLength * progress);
415
+ style.transform = "";
416
+ }
417
+ else {
418
+ style.opacity = String(1 - progress);
419
+ style.transform = direction === 0
420
+ ? `scale(${Math.max(0.8, 1 - raw * 0.12)})`
421
+ : `translateY(${-direction * distance * raw}px) scale(${Math.max(0.8, 1 - raw * 0.08)})`;
422
+ }
423
+ }
424
+ for (const { element } of appearing) {
425
+ const style = element.style;
426
+ const target = targets.find(item => item.id === element.getAttribute("data-mun-symbol-layer"));
427
+ if (target && isStrokeOnly(target) && target.d) {
428
+ const length = Math.max(0.01, svgPathLength(target.d));
429
+ style.opacity = "1";
430
+ style.strokeDasharray = String(length);
431
+ style.strokeDashoffset = String(length * (1 - progress));
432
+ style.transform = "";
433
+ }
434
+ else {
435
+ style.opacity = String(progress);
436
+ style.transform = direction === 0
437
+ ? `scale(${0.88 + raw * 0.12})`
438
+ : `translateY(${direction * distance * (1 - raw)}px) scale(${0.92 + raw * 0.08})`;
439
+ }
440
+ }
441
+ },
442
+ });
443
+ finishTracked(live, handle, () => {
444
+ for (const item of savedEntering) {
445
+ const style = item.element.style;
446
+ style.opacity = item.opacity;
447
+ style.transform = item.transform;
448
+ style.transformBox = item.transformBox;
449
+ style.transformOrigin = item.transformOrigin;
450
+ style.strokeDasharray = "";
451
+ style.strokeDashoffset = "";
452
+ }
453
+ oldOverlay?.remove();
454
+ });
455
+ }
456
+ /**
457
+ * Snapshot the disappearing part of a VectorSymbol before reconciliation.
458
+ * Matched layers remain live and are morphed through the attribute-motion lane.
459
+ */
460
+ export function prepareWebSymbolContentTransition(live, candidate, transition, animation, candidateProps) {
461
+ if (transition.descriptor.kind !== "symbolEffect" || !animation || reducedMotion(live))
462
+ return undefined;
463
+ if (live.getAttribute("data-mun") !== "VectorSymbol" || stagedString(candidate, "data-mun", candidateProps) !== "VectorSymbol")
464
+ return undefined;
465
+ const rect = normalizedRect(live);
466
+ if (!rect)
467
+ return undefined;
468
+ replaceActiveTransition(live, undefined);
469
+ const before = svgLayerMap(live);
470
+ const after = svgLayerMap(candidate, candidateProps);
471
+ const beforeViewBox = live.getAttribute("viewBox") ?? undefined;
472
+ const afterViewBox = stagedString(candidate, "viewBox", candidateProps);
473
+ const effect = transition.descriptor.effect.descriptor;
474
+ const matchingIds = [...before.keys()].filter(id => after.has(id));
475
+ // Generated ordinal IDs describe source order, not semantic identity. For
476
+ // automatic/magic replacement we therefore morph the complete geometry.
477
+ // Explicit author IDs still preserve true semantic sublayers in-place.
478
+ const common = new Set(effect.mode === "magicReplace" || effect.mode === "automatic"
479
+ ? matchingIds.filter(id => !isOrdinalLayerId(id))
480
+ : matchingIds);
481
+ const whole = effect.mode === "wholeSymbol";
482
+ if (whole) {
483
+ const overlay = fixedSvgOverlay(live, rect);
484
+ if (!overlay)
485
+ return undefined;
486
+ for (const child of live.children)
487
+ overlay.appendChild(child.cloneNode(true));
488
+ let cancelled = false;
489
+ return {
490
+ complete() {
491
+ if (cancelled)
492
+ return;
493
+ startWholeSymbolTransition(live, overlay, animation, effect.fallback);
494
+ },
495
+ cancel() { cancelled = true; overlay.remove(); },
496
+ };
497
+ }
498
+ const oldOnly = [...before.keys()].filter(id => !common.has(id));
499
+ const newOnlyIds = [...after.keys()].filter(id => !common.has(id));
500
+ const newOnly = new Set(newOnlyIds);
501
+ const morphTargets = newOnlyIds.map(id => {
502
+ const target = symbolLayerTarget(after.get(id), id, candidateProps);
503
+ return target.d && beforeViewBox !== afterViewBox
504
+ ? { ...target, d: mapSvgPathBetweenViewBoxes(target.d, afterViewBox, beforeViewBox) }
505
+ : target;
506
+ });
507
+ let overlay;
508
+ if (oldOnly.length > 0) {
509
+ overlay = fixedSvgOverlay(live, rect);
510
+ if (overlay)
511
+ for (const id of oldOnly)
512
+ overlay.appendChild(before.get(id).cloneNode(true));
513
+ }
514
+ let cancelled = false;
515
+ return {
516
+ complete() {
517
+ if (cancelled)
518
+ return;
519
+ if (effect.mode === "magicReplace" || effect.mode === "automatic") {
520
+ startMorphingLayerTransition(live, overlay, morphTargets, animation, effect.fallback, common.size === 0);
521
+ }
522
+ else {
523
+ startLayerTransition(live, overlay, newOnly, animation, effect.fallback);
524
+ }
525
+ },
526
+ cancel() { cancelled = true; overlay?.remove(); },
527
+ };
528
+ }
529
+ function graphemes(value) {
530
+ const Segmenter = Intl.Segmenter;
531
+ if (!Segmenter)
532
+ return Array.from(value);
533
+ try {
534
+ return [...new Segmenter(undefined, { granularity: "grapheme" }).segment(value)].map(item => item.segment);
535
+ }
536
+ catch {
537
+ return Array.from(value);
538
+ }
539
+ }
540
+ function lcsPairs(left, right) {
541
+ const rows = left.length + 1;
542
+ const columns = right.length + 1;
543
+ const table = Array.from({ length: rows }, () => new Uint16Array(columns));
544
+ for (let i = left.length - 1; i >= 0; i -= 1) {
545
+ for (let j = right.length - 1; j >= 0; j -= 1) {
546
+ table[i][j] = left[i] === right[j] ? table[i + 1][j + 1] + 1 : Math.max(table[i + 1][j], table[i][j + 1]);
547
+ }
548
+ }
549
+ const result = new Map();
550
+ let i = 0;
551
+ let j = 0;
552
+ while (i < left.length && j < right.length) {
553
+ if (left[i] === right[j]) {
554
+ result.set(i, j);
555
+ i += 1;
556
+ j += 1;
557
+ }
558
+ else if (table[i + 1][j] >= table[i][j + 1])
559
+ i += 1;
560
+ else
561
+ j += 1;
562
+ }
563
+ return result;
564
+ }
565
+ const maximumGraphemeMatchingCells = 65_536;
566
+ function copyTextStyle(source, target) {
567
+ try {
568
+ const style = source.ownerDocument.defaultView?.getComputedStyle(source);
569
+ if (!style)
570
+ return;
571
+ for (const name of ["font", "font-family", "font-size", "font-weight", "font-style", "letter-spacing", "line-height", "color", "text-align", "text-transform", "direction", "white-space"]) {
572
+ const value = style.getPropertyValue(name);
573
+ if (value)
574
+ target.style.setProperty(name, value);
575
+ }
576
+ }
577
+ catch { /* detached/synthetic DOM can omit computed styles */ }
578
+ }
579
+ function makeTextOverlay(element, rect) {
580
+ const document = element.ownerDocument;
581
+ if (!document.body)
582
+ return undefined;
583
+ const overlay = document.createElement("div");
584
+ overlay.setAttribute("aria-hidden", "true");
585
+ overlay.setAttribute("data-mun-text-transition-layer", "");
586
+ overlay.style.cssText = `position:fixed;left:${rect.left}px;top:${rect.top}px;width:${rect.width}px;height:${rect.height}px;pointer-events:none;overflow:visible;z-index:2147483645;`;
587
+ copyTextStyle(element, overlay);
588
+ document.body.appendChild(overlay);
589
+ return overlay;
590
+ }
591
+ function concealLiveText(element) {
592
+ const style = element.style;
593
+ const properties = ["color", "text-shadow", "-webkit-text-fill-color"];
594
+ const previous = properties.map(name => ({
595
+ name,
596
+ value: style.getPropertyValue(name),
597
+ priority: style.getPropertyPriority(name),
598
+ }));
599
+ style.setProperty("color", "transparent", "important");
600
+ style.setProperty("text-shadow", "none", "important");
601
+ style.setProperty("-webkit-text-fill-color", "transparent", "important");
602
+ return () => {
603
+ for (const item of previous) {
604
+ if (item.value)
605
+ style.setProperty(item.name, item.value, item.priority);
606
+ else
607
+ style.removeProperty(item.name);
608
+ }
609
+ };
610
+ }
611
+ function measureGraphemeRow(overlay, text) {
612
+ const row = overlay.ownerDocument.createElement("div");
613
+ row.style.cssText = "position:absolute;inset:0;white-space:pre;";
614
+ const spans = graphemes(text).map(value => {
615
+ const span = overlay.ownerDocument.createElement("span");
616
+ span.textContent = value;
617
+ row.appendChild(span);
618
+ return span;
619
+ });
620
+ overlay.appendChild(row);
621
+ const base = overlay.getBoundingClientRect();
622
+ const rects = spans.map(span => {
623
+ const rect = span.getBoundingClientRect();
624
+ return { left: rect.left - base.left, top: rect.top - base.top, width: rect.width, height: rect.height };
625
+ });
626
+ row.remove();
627
+ return { spans, rects };
628
+ }
629
+ function visualGlyph(overlay, value, rect) {
630
+ const span = overlay.ownerDocument.createElement("span");
631
+ span.textContent = value;
632
+ span.style.cssText = `position:absolute;left:${rect.left}px;top:${rect.top}px;white-space:pre;transform-origin:center;`;
633
+ overlay.appendChild(span);
634
+ return span;
635
+ }
636
+ function numericDirection(from, to, explicit) {
637
+ const before = Number(from.replaceAll(",", ""));
638
+ const after = explicit ?? Number(to.replaceAll(",", ""));
639
+ if (Number.isFinite(before) && Number.isFinite(after) && before !== after)
640
+ return after > before ? -1 : 1;
641
+ return -1;
642
+ }
643
+ function textPushVector(element, direction) {
644
+ if (direction === "up")
645
+ return { x: 0, y: -1 };
646
+ if (direction === "down")
647
+ return { x: 0, y: 1 };
648
+ let rtl = false;
649
+ try {
650
+ rtl = element.ownerDocument.defaultView?.getComputedStyle(element).direction === "rtl";
651
+ }
652
+ catch { /* detached/synthetic DOM */ }
653
+ const leading = rtl ? 1 : -1;
654
+ return { x: direction === "leading" ? leading : -leading, y: 0 };
655
+ }
656
+ /** Animate replacement of the single text payload inside a stable Text View. */
657
+ export function playWebTextContentTransition(element, from, to, transition, animation, beforeRect) {
658
+ const descriptor = transition.descriptor;
659
+ if (descriptor.kind === "identity" || from === to || !animation || reducedMotion(element))
660
+ return undefined;
661
+ const rect = normalizedRect(element) ?? beforeRect;
662
+ if (!rect)
663
+ return undefined;
664
+ const overlay = makeTextOverlay(element, rect);
665
+ if (!overlay)
666
+ return undefined;
667
+ replaceActiveTransition(element, undefined);
668
+ const reveal = concealLiveText(element);
669
+ if (descriptor.kind === "numericText") {
670
+ const oldSpan = visualGlyph(overlay, from, { left: 0, top: 0, width: rect.width, height: rect.height });
671
+ const newSpan = visualGlyph(overlay, to, { left: 0, top: 0, width: rect.width, height: rect.height });
672
+ const direction = numericDirection(from, to, descriptor.value);
673
+ const distance = Math.max(4, rect.height * 0.58);
674
+ const handle = munMotion.animate({ animation, onUpdate(raw) {
675
+ const progress = unitProgress(raw);
676
+ oldSpan.style.opacity = String(1 - progress);
677
+ oldSpan.style.transform = `translateY(${direction * distance * raw}px)`;
678
+ newSpan.style.opacity = String(progress);
679
+ newSpan.style.transform = `translateY(${-direction * distance * (1 - raw)}px)`;
680
+ } });
681
+ return finishTracked(element, handle, () => { reveal(); overlay.remove(); });
682
+ }
683
+ if (descriptor.kind === "blurReplace") {
684
+ const oldSpan = visualGlyph(overlay, from, { left: 0, top: 0, width: rect.width, height: rect.height });
685
+ const newSpan = visualGlyph(overlay, to, { left: 0, top: 0, width: rect.width, height: rect.height });
686
+ const radius = descriptor.radius;
687
+ const handle = munMotion.animate({ animation, onUpdate(raw) {
688
+ const progress = unitProgress(raw);
689
+ oldSpan.style.opacity = String(1 - progress);
690
+ oldSpan.style.filter = `blur(${radius * progress}px)`;
691
+ oldSpan.style.transform = `scale(${1 + raw * 0.035})`;
692
+ newSpan.style.opacity = String(progress);
693
+ newSpan.style.filter = `blur(${radius * (1 - progress)}px)`;
694
+ newSpan.style.transform = `scale(${0.965 + raw * 0.035})`;
695
+ } });
696
+ return finishTracked(element, handle, () => { reveal(); overlay.remove(); });
697
+ }
698
+ if (descriptor.kind === "push") {
699
+ const oldSpan = visualGlyph(overlay, from, { left: 0, top: 0, width: rect.width, height: rect.height });
700
+ const newSpan = visualGlyph(overlay, to, { left: 0, top: 0, width: rect.width, height: rect.height });
701
+ const vector = textPushVector(element, descriptor.direction);
702
+ const distance = Math.max(6, (vector.y === 0 ? rect.width : rect.height) * 0.32);
703
+ const handle = munMotion.animate({ animation, onUpdate(raw) {
704
+ const progress = unitProgress(raw);
705
+ oldSpan.style.opacity = String(1 - progress);
706
+ oldSpan.style.transform = `translate(${vector.x * distance * raw}px, ${vector.y * distance * raw}px)`;
707
+ newSpan.style.opacity = String(progress);
708
+ newSpan.style.transform = `translate(${-vector.x * distance * (1 - raw)}px, ${-vector.y * distance * (1 - raw)}px)`;
709
+ } });
710
+ return finishTracked(element, handle, () => { reveal(); overlay.remove(); });
711
+ }
712
+ if (descriptor.kind === "scale") {
713
+ const oldSpan = visualGlyph(overlay, from, { left: 0, top: 0, width: rect.width, height: rect.height });
714
+ const newSpan = visualGlyph(overlay, to, { left: 0, top: 0, width: rect.width, height: rect.height });
715
+ const targetScale = descriptor.scale;
716
+ const handle = munMotion.animate({ animation, onUpdate(raw) {
717
+ const progress = unitProgress(raw);
718
+ oldSpan.style.opacity = String(1 - progress);
719
+ oldSpan.style.transform = `scale(${1 + (targetScale - 1) * raw})`;
720
+ newSpan.style.opacity = String(progress);
721
+ newSpan.style.transform = `scale(${targetScale + (1 - targetScale) * raw})`;
722
+ } });
723
+ return finishTracked(element, handle, () => { reveal(); overlay.remove(); });
724
+ }
725
+ if (descriptor.kind !== "interpolate") {
726
+ const oldSpan = visualGlyph(overlay, from, { left: 0, top: 0, width: rect.width, height: rect.height });
727
+ const newSpan = visualGlyph(overlay, to, { left: 0, top: 0, width: rect.width, height: rect.height });
728
+ const handle = munMotion.animate({ animation, onUpdate(raw) {
729
+ const progress = unitProgress(raw);
730
+ oldSpan.style.opacity = String(1 - progress);
731
+ newSpan.style.opacity = String(progress);
732
+ } });
733
+ return finishTracked(element, handle, () => { reveal(); overlay.remove(); });
734
+ }
735
+ const oldValues = graphemes(from);
736
+ const newValues = graphemes(to);
737
+ // LCS gives stable repeated-grapheme matching, but its matrix is O(n*m).
738
+ // Long prose is better served by a bounded whole-text crossfade than by
739
+ // allocating a large table for an effect intended primarily for labels.
740
+ if (oldValues.length * newValues.length > maximumGraphemeMatchingCells) {
741
+ const oldSpan = visualGlyph(overlay, from, { left: 0, top: 0, width: rect.width, height: rect.height });
742
+ const newSpan = visualGlyph(overlay, to, { left: 0, top: 0, width: rect.width, height: rect.height });
743
+ const handle = munMotion.animate({ animation, onUpdate(raw) {
744
+ const progress = unitProgress(raw);
745
+ oldSpan.style.opacity = String(1 - progress);
746
+ newSpan.style.opacity = String(progress);
747
+ } });
748
+ return finishTracked(element, handle, () => { reveal(); overlay.remove(); });
749
+ }
750
+ const oldLayout = measureGraphemeRow(overlay, from).rects;
751
+ const newLayout = measureGraphemeRow(overlay, to).rects;
752
+ const pairs = lcsPairs(oldValues, newValues);
753
+ const matchedNew = new Set(pairs.values());
754
+ const oldGlyphs = oldValues.map((value, index) => visualGlyph(overlay, value, oldLayout[index] ?? { left: 0, top: 0, width: 0, height: rect.height }));
755
+ const newGlyphs = newValues.map((value, index) => matchedNew.has(index) ? undefined : visualGlyph(overlay, value, newLayout[index] ?? { left: 0, top: 0, width: 0, height: rect.height }));
756
+ const handle = munMotion.animate({ animation, onUpdate(raw) {
757
+ const progress = unitProgress(raw);
758
+ for (let index = 0; index < oldGlyphs.length; index += 1) {
759
+ const glyph = oldGlyphs[index];
760
+ const match = pairs.get(index);
761
+ if (match === undefined) {
762
+ glyph.style.opacity = String(1 - progress);
763
+ glyph.style.transform = `scale(${1 - raw * 0.12})`;
764
+ continue;
765
+ }
766
+ const fromRect = oldLayout[index];
767
+ const toRect = newLayout[match];
768
+ if (!fromRect || !toRect)
769
+ continue;
770
+ glyph.style.transform = `translate(${(toRect.left - fromRect.left) * raw}px, ${(toRect.top - fromRect.top) * raw}px)`;
771
+ }
772
+ for (const glyph of newGlyphs)
773
+ if (glyph) {
774
+ glyph.style.opacity = String(progress);
775
+ glyph.style.transform = `scale(${0.88 + raw * 0.12})`;
776
+ }
777
+ } });
778
+ return finishTracked(element, handle, () => { reveal(); overlay.remove(); });
779
+ }
780
+ //# sourceMappingURL=content-transition.js.map