motionary 10.1.0 → 10.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 (270) hide show
  1. package/AGENTS.md +61 -0
  2. package/CHANGELOG.md +14 -0
  3. package/README.md +37 -0
  4. package/dist/chunks/{keyframes-CyH_abhI.js → keyframes-W-474DMc.js} +2 -2
  5. package/dist/chunks/{keyframes-CyH_abhI.js.map → keyframes-W-474DMc.js.map} +1 -1
  6. package/dist/chunks/{keyframes-cUdsXSXQ.cjs → keyframes-ZheOkpt0.cjs} +2 -2
  7. package/dist/chunks/{keyframes-cUdsXSXQ.cjs.map → keyframes-ZheOkpt0.cjs.map} +1 -1
  8. package/dist/chunks/{registry-jF8VIA_9.js → registry-BIEjKngP.js} +2 -2
  9. package/dist/chunks/{registry-jF8VIA_9.js.map → registry-BIEjKngP.js.map} +1 -1
  10. package/dist/chunks/{registry-C0xLNq3-.cjs → registry-eJgpFAzI.cjs} +2 -2
  11. package/dist/chunks/{registry-C0xLNq3-.cjs.map → registry-eJgpFAzI.cjs.map} +1 -1
  12. package/dist/chunks/ticker-CM_56oVy.js +70 -0
  13. package/dist/chunks/ticker-CM_56oVy.js.map +1 -0
  14. package/dist/chunks/ticker-D4o6enH0.cjs +72 -0
  15. package/dist/chunks/ticker-D4o6enH0.cjs.map +1 -0
  16. package/dist/chunks/{tween-JEthWrjo.cjs → tween-CBuWYpI-.cjs} +5 -72
  17. package/dist/chunks/tween-CBuWYpI-.cjs.map +1 -0
  18. package/dist/chunks/{tween-DDObu9iA.js → tween-CqX1JBuj.js} +5 -71
  19. package/dist/chunks/tween-CqX1JBuj.js.map +1 -0
  20. package/dist/components/core.cjs +106 -0
  21. package/dist/components/core.cjs.map +1 -1
  22. package/dist/components/core.d.cts +44 -2
  23. package/dist/components/core.d.ts +44 -2
  24. package/dist/components/core.js +105 -1
  25. package/dist/components/core.js.map +1 -1
  26. package/dist/components/widgets.cjs +401 -198
  27. package/dist/components/widgets.cjs.map +1 -1
  28. package/dist/components/widgets.d.cts +146 -2
  29. package/dist/components/widgets.d.ts +146 -2
  30. package/dist/components/widgets.js +399 -199
  31. package/dist/components/widgets.js.map +1 -1
  32. package/dist/llms-full.txt +98 -1
  33. package/dist/llms.txt +6 -2
  34. package/dist/manifest.json +259 -1
  35. package/dist/runtime/format-css.cjs +4 -3
  36. package/dist/runtime/format-css.cjs.map +1 -1
  37. package/dist/runtime/format-css.js +4 -3
  38. package/dist/runtime/format-css.js.map +1 -1
  39. package/dist/runtime/format-motion.cjs +4 -3
  40. package/dist/runtime/format-motion.cjs.map +1 -1
  41. package/dist/runtime/format-motion.js +4 -3
  42. package/dist/runtime/format-motion.js.map +1 -1
  43. package/dist/runtime/format-svg.cjs +457 -0
  44. package/dist/runtime/format-svg.cjs.map +1 -0
  45. package/dist/runtime/format-svg.d.cts +214 -0
  46. package/dist/runtime/format-svg.d.ts +214 -0
  47. package/dist/runtime/format-svg.iife.js +2 -0
  48. package/dist/runtime/format-svg.iife.js.map +1 -0
  49. package/dist/runtime/format-svg.js +446 -0
  50. package/dist/runtime/format-svg.js.map +1 -0
  51. package/dist/runtime/scroll.cjs +301 -0
  52. package/dist/runtime/scroll.cjs.map +1 -0
  53. package/dist/runtime/scroll.d.cts +236 -0
  54. package/dist/runtime/scroll.d.ts +236 -0
  55. package/dist/runtime/scroll.iife.js +2 -0
  56. package/dist/runtime/scroll.iife.js.map +1 -0
  57. package/dist/runtime/scroll.js +292 -0
  58. package/dist/runtime/scroll.js.map +1 -0
  59. package/dist/runtime.cjs +5 -4
  60. package/dist/runtime.cjs.map +1 -1
  61. package/dist/runtime.d.cts +1 -1
  62. package/dist/runtime.d.ts +1 -1
  63. package/dist/runtime.iife.js +1 -1
  64. package/dist/runtime.iife.js.map +1 -1
  65. package/dist/runtime.js +5 -4
  66. package/dist/runtime.js.map +1 -1
  67. package/dist/widgets.umd.js +1 -1
  68. package/dist/widgets.umd.js.map +1 -1
  69. package/docs/ROADMAP.md +1 -1
  70. package/docs/ai-prompt-guide.md +54 -0
  71. package/docs/components/README.md +253 -0
  72. package/docs/components/usa-accordion.md +38 -0
  73. package/docs/components/usa-acrylic.md +38 -0
  74. package/docs/components/usa-add-to-cart.md +40 -0
  75. package/docs/components/usa-ambient.md +32 -0
  76. package/docs/components/usa-anim-icon.md +34 -0
  77. package/docs/components/usa-audio.md +38 -0
  78. package/docs/components/usa-aurora.md +36 -0
  79. package/docs/components/usa-auto-animate.md +44 -0
  80. package/docs/components/usa-auto-skeleton.md +38 -0
  81. package/docs/components/usa-avatar-stack.md +38 -0
  82. package/docs/components/usa-back-to-top.md +32 -0
  83. package/docs/components/usa-badge-wall.md +39 -0
  84. package/docs/components/usa-badge.md +36 -0
  85. package/docs/components/usa-bar-chart.md +33 -0
  86. package/docs/components/usa-bg-generator.md +32 -0
  87. package/docs/components/usa-blobs.md +32 -0
  88. package/docs/components/usa-bottom-sheet.md +32 -0
  89. package/docs/components/usa-button.md +78 -0
  90. package/docs/components/usa-card-stack.md +40 -0
  91. package/docs/components/usa-card.md +94 -0
  92. package/docs/components/usa-carousel-3d.md +40 -0
  93. package/docs/components/usa-carousel.md +40 -0
  94. package/docs/components/usa-cart-drawer.md +33 -0
  95. package/docs/components/usa-chapter-nav.md +40 -0
  96. package/docs/components/usa-chat-composer.md +33 -0
  97. package/docs/components/usa-check.md +32 -0
  98. package/docs/components/usa-checkbox.md +32 -0
  99. package/docs/components/usa-click.md +36 -0
  100. package/docs/components/usa-clock-control.md +37 -0
  101. package/docs/components/usa-code-export.md +36 -0
  102. package/docs/components/usa-color-picker.md +32 -0
  103. package/docs/components/usa-command-palette.md +39 -0
  104. package/docs/components/usa-compare.md +38 -0
  105. package/docs/components/usa-countdown.md +32 -0
  106. package/docs/components/usa-counter.md +32 -0
  107. package/docs/components/usa-cube-gallery.md +40 -0
  108. package/docs/components/usa-cube.md +36 -0
  109. package/docs/components/usa-cursor.md +32 -0
  110. package/docs/components/usa-date-picker.md +32 -0
  111. package/docs/components/usa-depth.md +44 -0
  112. package/docs/components/usa-dialog.md +40 -0
  113. package/docs/components/usa-disclosure.md +38 -0
  114. package/docs/components/usa-distort.md +36 -0
  115. package/docs/components/usa-dock.md +40 -0
  116. package/docs/components/usa-dot-network.md +32 -0
  117. package/docs/components/usa-double-tap.md +36 -0
  118. package/docs/components/usa-draggable.md +38 -0
  119. package/docs/components/usa-draw.md +36 -0
  120. package/docs/components/usa-drawer.md +34 -0
  121. package/docs/components/usa-equalizer.md +33 -0
  122. package/docs/components/usa-fab.md +40 -0
  123. package/docs/components/usa-festival-banner.md +32 -0
  124. package/docs/components/usa-field.md +34 -0
  125. package/docs/components/usa-file-drop.md +35 -0
  126. package/docs/components/usa-fullpage.md +38 -0
  127. package/docs/components/usa-fx.md +851 -0
  128. package/docs/components/usa-gauge.md +32 -0
  129. package/docs/components/usa-gen-art.md +32 -0
  130. package/docs/components/usa-gesture-fx.md +36 -0
  131. package/docs/components/usa-gesture-sticker.md +36 -0
  132. package/docs/components/usa-glitch.md +32 -0
  133. package/docs/components/usa-globe.md +33 -0
  134. package/docs/components/usa-gradient-text.md +32 -0
  135. package/docs/components/usa-grain.md +36 -0
  136. package/docs/components/usa-grid-glow.md +36 -0
  137. package/docs/components/usa-gyro-card.md +38 -0
  138. package/docs/components/usa-handwriting.md +32 -0
  139. package/docs/components/usa-hero-video.md +38 -0
  140. package/docs/components/usa-hold.md +32 -0
  141. package/docs/components/usa-hud-panel.md +38 -0
  142. package/docs/components/usa-hydrate.md +42 -0
  143. package/docs/components/usa-icon-morph.md +34 -0
  144. package/docs/components/usa-install-button.md +32 -0
  145. package/docs/components/usa-kanban.md +46 -0
  146. package/docs/components/usa-keyframe-editor.md +37 -0
  147. package/docs/components/usa-kpi.md +32 -0
  148. package/docs/components/usa-leaderboard.md +41 -0
  149. package/docs/components/usa-like.md +32 -0
  150. package/docs/components/usa-liquid-nav.md +36 -0
  151. package/docs/components/usa-liquid.md +36 -0
  152. package/docs/components/usa-loading-bar.md +35 -0
  153. package/docs/components/usa-location-card.md +34 -0
  154. package/docs/components/usa-lottie-icon.md +34 -0
  155. package/docs/components/usa-lottie.md +32 -0
  156. package/docs/components/usa-lyrics.md +38 -0
  157. package/docs/components/usa-magnetic.md +32 -0
  158. package/docs/components/usa-marquee.md +38 -0
  159. package/docs/components/usa-mask-reveal.md +36 -0
  160. package/docs/components/usa-masonry-flow.md +42 -0
  161. package/docs/components/usa-masonry.md +38 -0
  162. package/docs/components/usa-menu-toggle.md +34 -0
  163. package/docs/components/usa-menu.md +44 -0
  164. package/docs/components/usa-message-list.md +39 -0
  165. package/docs/components/usa-milestones.md +40 -0
  166. package/docs/components/usa-modal.md +42 -0
  167. package/docs/components/usa-morph.md +34 -0
  168. package/docs/components/usa-motion-inspector.md +32 -0
  169. package/docs/components/usa-motion-prefs.md +32 -0
  170. package/docs/components/usa-motion-spec.md +32 -0
  171. package/docs/components/usa-motion-switch.md +34 -0
  172. package/docs/components/usa-motion-theme.md +40 -0
  173. package/docs/components/usa-motion.md +42 -0
  174. package/docs/components/usa-music-player.md +36 -0
  175. package/docs/components/usa-native-preview.md +36 -0
  176. package/docs/components/usa-nav-morph.md +40 -0
  177. package/docs/components/usa-navbar.md +36 -0
  178. package/docs/components/usa-notification-bell.md +37 -0
  179. package/docs/components/usa-odometer.md +34 -0
  180. package/docs/components/usa-organic-card.md +36 -0
  181. package/docs/components/usa-otp.md +33 -0
  182. package/docs/components/usa-overscroll.md +36 -0
  183. package/docs/components/usa-pack.md +111 -0
  184. package/docs/components/usa-pagination.md +32 -0
  185. package/docs/components/usa-panorama.md +32 -0
  186. package/docs/components/usa-particles.md +32 -0
  187. package/docs/components/usa-pause-all.md +32 -0
  188. package/docs/components/usa-perf-monitor.md +32 -0
  189. package/docs/components/usa-pinch-zoom.md +36 -0
  190. package/docs/components/usa-player.md +38 -0
  191. package/docs/components/usa-plugin-card.md +61 -0
  192. package/docs/components/usa-plugin-store.md +36 -0
  193. package/docs/components/usa-popover.md +38 -0
  194. package/docs/components/usa-post-fx.md +36 -0
  195. package/docs/components/usa-presence.md +36 -0
  196. package/docs/components/usa-press.md +32 -0
  197. package/docs/components/usa-prize-wheel.md +32 -0
  198. package/docs/components/usa-product-gallery.md +40 -0
  199. package/docs/components/usa-progress-ring.md +38 -0
  200. package/docs/components/usa-progress.md +34 -0
  201. package/docs/components/usa-prop-panel.md +34 -0
  202. package/docs/components/usa-pull-cord.md +32 -0
  203. package/docs/components/usa-pull-refresh.md +37 -0
  204. package/docs/components/usa-radar.md +32 -0
  205. package/docs/components/usa-reactions.md +32 -0
  206. package/docs/components/usa-red-envelope.md +32 -0
  207. package/docs/components/usa-retro-button.md +34 -0
  208. package/docs/components/usa-reveal.md +36 -0
  209. package/docs/components/usa-ripple.md +32 -0
  210. package/docs/components/usa-scene.md +38 -0
  211. package/docs/components/usa-scramble.md +32 -0
  212. package/docs/components/usa-scroll-highlight.md +34 -0
  213. package/docs/components/usa-scroll-progress.md +36 -0
  214. package/docs/components/usa-scroll-scene.md +66 -0
  215. package/docs/components/usa-scrolly.md +40 -0
  216. package/docs/components/usa-segmented.md +40 -0
  217. package/docs/components/usa-shader.md +74 -0
  218. package/docs/components/usa-sheet.md +42 -0
  219. package/docs/components/usa-shimmer-text.md +32 -0
  220. package/docs/components/usa-shortcut.md +34 -0
  221. package/docs/components/usa-skeleton-reveal.md +42 -0
  222. package/docs/components/usa-skeleton.md +36 -0
  223. package/docs/components/usa-sketch-chart.md +32 -0
  224. package/docs/components/usa-slider.md +32 -0
  225. package/docs/components/usa-sparkline.md +32 -0
  226. package/docs/components/usa-spatial-card.md +40 -0
  227. package/docs/components/usa-spinner.md +34 -0
  228. package/docs/components/usa-splash.md +36 -0
  229. package/docs/components/usa-split-text.md +32 -0
  230. package/docs/components/usa-spotlight.md +40 -0
  231. package/docs/components/usa-spring.md +42 -0
  232. package/docs/components/usa-stagger.md +40 -0
  233. package/docs/components/usa-star-rating.md +34 -0
  234. package/docs/components/usa-stepper.md +42 -0
  235. package/docs/components/usa-sticky-stack.md +40 -0
  236. package/docs/components/usa-sticky-wall.md +40 -0
  237. package/docs/components/usa-stories.md +38 -0
  238. package/docs/components/usa-story.md +80 -0
  239. package/docs/components/usa-suggestion-chips.md +32 -0
  240. package/docs/components/usa-swipe-deck.md +40 -0
  241. package/docs/components/usa-swipeable.md +36 -0
  242. package/docs/components/usa-switch.md +32 -0
  243. package/docs/components/usa-tab-bar.md +46 -0
  244. package/docs/components/usa-tabs.md +40 -0
  245. package/docs/components/usa-terminal.md +38 -0
  246. package/docs/components/usa-text-rotate.md +32 -0
  247. package/docs/components/usa-theme-surface.md +36 -0
  248. package/docs/components/usa-theme-switcher.md +32 -0
  249. package/docs/components/usa-tilt.md +36 -0
  250. package/docs/components/usa-timeline.md +40 -0
  251. package/docs/components/usa-tip.md +44 -0
  252. package/docs/components/usa-toast-stack.md +36 -0
  253. package/docs/components/usa-toaster.md +36 -0
  254. package/docs/components/usa-typewriter.md +32 -0
  255. package/docs/components/usa-upload-progress.md +33 -0
  256. package/docs/components/usa-video-card.md +40 -0
  257. package/docs/components/usa-view-switch.md +38 -0
  258. package/docs/components/usa-voice-button.md +33 -0
  259. package/docs/components/usa-volume-knob.md +32 -0
  260. package/docs/components/usa-water-ripple.md +36 -0
  261. package/docs/components/usa-wave-text.md +32 -0
  262. package/docs/components/usa-weather-card.md +32 -0
  263. package/docs/components/usa-worker-canvas.md +32 -0
  264. package/docs/components/usa-xp-bar.md +33 -0
  265. package/docs/components.md +50 -0
  266. package/docs/runtime/format-svg.md +62 -0
  267. package/docs/runtime/scroll.md +61 -0
  268. package/package.json +25 -3
  269. package/dist/chunks/tween-DDObu9iA.js.map +0 -1
  270. package/dist/chunks/tween-JEthWrjo.cjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"format-motion.cjs","sources":["../../src/runtime/format-motion.ts"],"sourcesContent":["/**\n * `motionary/runtime/format-motion` (10.1) — play Motion / Framer-style\n * keyframe JSON with the runtime:\n *\n * ```json\n * { \"initial\": { \"opacity\": 0, \"y\": 40 },\n * \"animate\": { \"opacity\": 1, \"y\": [40, -8, 0], \"rotate\": 0 },\n * \"transition\": { \"duration\": 0.6, \"ease\": \"easeOut\", \"times\": [0, 0.7, 1], \"delay\": 0.1,\n * \"repeat\": 1, \"repeatType\": \"reverse\", \"opacity\": { \"duration\": 0.3 } } }\n * ```\n *\n * Supported: `initial` / `animate` (numbers, unit strings, colours, arrays as\n * keyframes), the transform shorthands `x y scale scaleX scaleY rotate skewX skewY`,\n * transition `duration` / `delay` (seconds) / `ease` (names or `[x1, y1, x2, y2]`) /\n * `times` / `repeat` (`Infinity` ok) / `repeatType` (`loop`, `reverse`, `mirror`),\n * per-property transitions, and `type: \"spring\"` (`stiffness`, `damping`, `mass`,\n * or `bounce` + `duration`) simulated into an easing curve.\n * Not supported: `layout`, gestures (`whileHover` …), variants propagation,\n * `staggerChildren` (use the runtime timeline `stagger`).\n */\nimport { RUNTIME_VERSION, type RuntimeModule } from './registry';\nimport { Timeline, type Target } from './tween';\nimport { cubicBezier, type Ease, EASES } from './ease';\nimport { framesToTimeline, type Frame } from './keyframes';\n\ntype V = number | string;\nexport interface MotionTransition {\n duration?: number;\n delay?: number;\n ease?: string | number[] | (string | number[])[];\n times?: number[];\n repeat?: number;\n repeatType?: 'loop' | 'reverse' | 'mirror';\n type?: 'tween' | 'spring' | 'keyframes' | 'inertia';\n stiffness?: number;\n damping?: number;\n mass?: number;\n bounce?: number;\n [prop: string]: unknown;\n}\nexport interface MotionDef {\n initial?: Record<string, V> | false;\n animate: Record<string, V | V[]>;\n transition?: MotionTransition;\n}\n\nconst NAMES: Record<string, string> = { linear: 'linear', easeIn: 'cubic-in', easeOut: 'cubic-out', easeInOut: 'cubic-in-out', circIn: 'circ-in', circOut: 'circ-out', circInOut: 'circ-in-out', backIn: 'back-in', backOut: 'back-out', backInOut: 'back-in-out', anticipate: 'back-in-out' };\n\n/** A Motion ease → runtime ease. */\nexport function motionEase(e: string | number[] | undefined): Ease {\n if (Array.isArray(e)) return cubicBezier(e[0], e[1], e[2], e[3]);\n if (!e) return EASES['cubic-out'];\n const n = NAMES[e] || e;\n if (!EASES[n]) throw new Error(`[motionary] format-motion: unknown ease \"${e}\"`);\n return EASES[n];\n}\n\n/** Simulate a damped spring (unit step) → [ease, duration ms]. */\nexport function springEase(o: { stiffness?: number; damping?: number; mass?: number; bounce?: number; duration?: number }): [Ease, number] {\n let k = o.stiffness ?? 100, c = o.damping ?? 10;\n const m = o.mass ?? 1;\n if (o.bounce !== undefined && o.duration !== undefined) {\n // map bounce + duration to stiffness / damping (critical damping at bounce 0)\n const zeta = 1 - Math.min(0.95, Math.max(0, o.bounce));\n const w = (2 * Math.PI) / Math.max(0.05, o.duration);\n k = m * w * w;\n c = 2 * zeta * Math.sqrt(k * m);\n }\n const dt = 1 / 120;\n const samples: number[] = [0];\n let x = 0, v = 0, t = 0, still = 0;\n while (t < 10) {\n const a = (-k * (x - 1) - c * v) / m;\n v += a * dt;\n x += v * dt;\n t += dt;\n samples.push(x);\n if (Math.abs(x - 1) < 0.001 && Math.abs(v) < 0.01) { if (++still > 12) break; } else still = 0;\n }\n const n = samples.length - 1;\n samples[n] = 1;\n const ease: Ease = (p) => {\n if (p <= 0) return 0;\n if (p >= 1) return 1;\n const f = p * n, i = Math.floor(f);\n return samples[i] + (samples[i + 1] - samples[i]) * (f - i);\n };\n return [ease, Math.round(t * 1000)];\n}\n\n/** Motion def → one keyframe track per transition group (`[frames, transition]`). */\nexport function fromMotion(def: MotionDef): { frames: Frame[]; transition: MotionTransition; props: string[] }[] {\n const base = def.transition || {};\n const groups = new Map<string, string[]>();\n for (const k of Object.keys(def.animate)) {\n const own = base[k] && typeof base[k] === 'object' ? k : '';\n groups.set(own, [...(groups.get(own) || []), k]);\n }\n return Array.from(groups.entries()).map(([g, props]) => {\n const tr: MotionTransition = g ? { ...base, ...(base[g] as MotionTransition) } : base;\n const len = Math.max(...props.map((p) => (Array.isArray(def.animate[p]) ? (def.animate[p] as V[]).length : 1)));\n const n = Math.max(2, len);\n const times = tr.times && tr.times.length === n ? tr.times : Array.from({ length: n }, (_, i) => i / (n - 1));\n const frames: Frame[] = times.map((offset) => ({ offset, props: {} }));\n for (const p of props) {\n const v = def.animate[p];\n const arr = Array.isArray(v) ? v : [def.initial && p in def.initial ? def.initial[p] : undefined, v];\n const list = arr.length === n ? arr : [...Array(n - arr.length).fill(arr[0]), ...arr];\n list.forEach((x, i) => { if (x !== undefined && x !== null) frames[i].props[p] = x as V; });\n }\n if (Array.isArray(tr.ease) && tr.ease.length && (Array.isArray(tr.ease[0]) || typeof tr.ease[0] === 'string')) {\n (tr.ease as (string | number[])[]).forEach((e, i) => { if (frames[i]) frames[i].easing = Array.isArray(e) ? `cubic-bezier(${e.join(',')})` : NAMES[e] || e; });\n }\n return { frames, transition: tr, props };\n });\n}\n\n/**\n * Apply `initial` immediately and play `animate` with the transition.\n * Returns a runtime `Timeline` (one child per transition group), playing unless `paused`.\n */\nexport function playMotion(target: Target, def: MotionDef, o: { paused?: boolean } = {}): Timeline {\n const tl = new Timeline({});\n if (def.initial) for (const [k, v] of Object.entries(def.initial)) framesToTimeline(target, [{ offset: 0, props: { [k]: v } }], { duration: 0 }).seek(0);\n for (const { frames, transition: tr } of fromMotion(def)) {\n let ease: Ease | undefined;\n let dur = (tr.duration ?? 0.3) * 1000;\n if (tr.type === 'spring') [ease, dur] = springEase({ ...tr, duration: tr.duration });\n else if (!Array.isArray(tr.ease) || typeof tr.ease[0] === 'number') ease = motionEase(tr.ease as string | number[] | undefined);\n const rep = tr.repeat === Infinity ? -1 : tr.repeat || 0;\n const child = framesToTimeline(target, frames, { duration: dur, ease, repeat: rep, yoyo: rep !== 0 && tr.repeatType !== 'loop' && !!tr.repeatType });\n tl.add(child, (tr.delay || 0) * 1000);\n }\n if (!o.paused) tl.play();\n return tl;\n}\n\nexport interface FormatMotionApi {\n fromMotion: typeof fromMotion;\n playMotion: typeof playMotion;\n springEase: typeof springEase;\n motionEase: typeof motionEase;\n}\n\n/** The module object for `use(formatMotion)`. */\nexport const formatMotion: RuntimeModule<FormatMotionApi> = { id: 'format-motion', version: RUNTIME_VERSION, requires: ['core'], api: { fromMotion, playMotion, springEase, motionEase } };\n"],"names":["cubicBezier","EASES","Timeline","framesToTimeline","RUNTIME_VERSION"],"mappings":";;;;;;AAAA;;;;;;;;;;;;;;;;;;;AAmBG;AA2BH,MAAM,KAAK,GAA2B,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,aAAa,EAAE;AAE9R;AACM,SAAU,UAAU,CAAC,CAAgC,EAAA;AACzD,IAAA,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAAE,OAAOA,iBAAW,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAChE,IAAA,IAAI,CAAC,CAAC;AAAE,QAAA,OAAOC,WAAK,CAAC,WAAW,CAAC;IACjC,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACvB,IAAA,IAAI,CAACA,WAAK,CAAC,CAAC,CAAC;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA,CAAA,CAAG,CAAC;AAChF,IAAA,OAAOA,WAAK,CAAC,CAAC,CAAC;AACjB;AAEA;AACM,SAAU,UAAU,CAAC,CAA8F,EAAA;AACvH,IAAA,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS,IAAI,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC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EAAE,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,UAAU,KAAK,MAAM,IAAI,CAAC,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC;AACpJ,QAAA,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC,IAAI,IAAI,CAAC;IACvC;IACA,IAAI,CAAC,CAAC,CAAC,MAAM;QAAE,EAAE,CAAC,IAAI,EAAE;AACxB,IAAA,OAAO,EAAE;AACX;AASA;AACO,MAAM,YAAY,GAAmC,EAAE,EAAE,EAAE,eAAe,EAAE,OAAO,EAAEC,wBAAe,EAAE,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE;;;;;;;;"}
1
+ {"version":3,"file":"format-motion.cjs","sources":["../../src/runtime/format-motion.ts"],"sourcesContent":["/**\n * `motionary/runtime/format-motion` (10.1) — play Motion / Framer-style\n * keyframe JSON with the runtime:\n *\n * ```json\n * { \"initial\": { \"opacity\": 0, \"y\": 40 },\n * \"animate\": { \"opacity\": 1, \"y\": [40, -8, 0], \"rotate\": 0 },\n * \"transition\": { \"duration\": 0.6, \"ease\": \"easeOut\", \"times\": [0, 0.7, 1], \"delay\": 0.1,\n * \"repeat\": 1, \"repeatType\": \"reverse\", \"opacity\": { \"duration\": 0.3 } } }\n * ```\n *\n * Supported: `initial` / `animate` (numbers, unit strings, colours, arrays as\n * keyframes), the transform shorthands `x y scale scaleX scaleY rotate skewX skewY`,\n * transition `duration` / `delay` (seconds) / `ease` (names or `[x1, y1, x2, y2]`) /\n * `times` / `repeat` (`Infinity` ok) / `repeatType` (`loop`, `reverse`, `mirror`),\n * per-property transitions, and `type: \"spring\"` (`stiffness`, `damping`, `mass`,\n * or `bounce` + `duration`) simulated into an easing curve.\n * Not supported: `layout`, gestures (`whileHover` …), variants propagation,\n * `staggerChildren` (use the runtime timeline `stagger`).\n */\nimport { RUNTIME_VERSION, type RuntimeModule } from './registry';\nimport { Timeline, type Target } from './tween';\nimport { cubicBezier, type Ease, EASES } from './ease';\nimport { framesToTimeline, type Frame } from './keyframes';\n\ntype V = number | string;\nexport interface MotionTransition {\n duration?: number;\n delay?: number;\n ease?: string | number[] | (string | number[])[];\n times?: number[];\n repeat?: number;\n repeatType?: 'loop' | 'reverse' | 'mirror';\n type?: 'tween' | 'spring' | 'keyframes' | 'inertia';\n stiffness?: number;\n damping?: number;\n mass?: number;\n bounce?: number;\n [prop: string]: unknown;\n}\nexport interface MotionDef {\n initial?: Record<string, V> | false;\n animate: Record<string, V | V[]>;\n transition?: MotionTransition;\n}\n\nconst NAMES: Record<string, string> = { linear: 'linear', easeIn: 'cubic-in', easeOut: 'cubic-out', easeInOut: 'cubic-in-out', circIn: 'circ-in', circOut: 'circ-out', circInOut: 'circ-in-out', backIn: 'back-in', backOut: 'back-out', backInOut: 'back-in-out', anticipate: 'back-in-out' };\n\n/** A Motion ease → runtime ease. */\nexport function motionEase(e: string | number[] | undefined): Ease {\n if (Array.isArray(e)) return cubicBezier(e[0], e[1], e[2], e[3]);\n if (!e) return EASES['cubic-out'];\n const n = NAMES[e] || e;\n if (!EASES[n]) throw new Error(`[motionary] format-motion: unknown ease \"${e}\"`);\n return EASES[n];\n}\n\n/** Simulate a damped spring (unit step) → [ease, duration ms]. */\nexport function springEase(o: { stiffness?: number; damping?: number; mass?: number; bounce?: number; duration?: number }): [Ease, number] {\n let k = o.stiffness ?? 100, c = o.damping ?? 10;\n const m = o.mass ?? 1;\n if (o.bounce !== undefined && o.duration !== undefined) {\n // map bounce + duration to stiffness / damping (critical damping at bounce 0)\n const zeta = 1 - Math.min(0.95, Math.max(0, o.bounce));\n const w = (2 * Math.PI) / Math.max(0.05, o.duration);\n k = m * w * w;\n c = 2 * zeta * Math.sqrt(k * m);\n }\n const dt = 1 / 120;\n const samples: number[] = [0];\n let x = 0, v = 0, t = 0, still = 0;\n while (t < 10) {\n const a = (-k * (x - 1) - c * v) / m;\n v += a * dt;\n x += v * dt;\n t += dt;\n samples.push(x);\n if (Math.abs(x - 1) < 0.001 && Math.abs(v) < 0.01) { if (++still > 12) break; } else still = 0;\n }\n const n = samples.length - 1;\n samples[n] = 1;\n const ease: Ease = (p) => {\n if (p <= 0) return 0;\n if (p >= 1) return 1;\n const f = p * n, i = Math.floor(f);\n return samples[i] + (samples[i + 1] - samples[i]) * (f - i);\n };\n return [ease, Math.round(t * 1000)];\n}\n\n/** Motion def → one keyframe track per transition group (`[frames, transition]`). */\nexport function fromMotion(def: MotionDef): { frames: Frame[]; transition: MotionTransition; props: string[] }[] {\n const base = def.transition || {};\n const groups = new Map<string, string[]>();\n for (const k of Object.keys(def.animate)) {\n const own = base[k] && typeof base[k] === 'object' ? k : '';\n groups.set(own, [...(groups.get(own) || []), k]);\n }\n return Array.from(groups.entries()).map(([g, props]) => {\n const tr: MotionTransition = g ? { ...base, ...(base[g] as MotionTransition) } : base;\n const len = Math.max(...props.map((p) => (Array.isArray(def.animate[p]) ? (def.animate[p] as V[]).length : 1)));\n const n = Math.max(2, len);\n const times = tr.times && tr.times.length === n ? tr.times : Array.from({ length: n }, (_, i) => i / (n - 1));\n const frames: Frame[] = times.map((offset) => ({ offset, props: {} }));\n for (const p of props) {\n const v = def.animate[p];\n const arr = Array.isArray(v) ? v : [def.initial && p in def.initial ? def.initial[p] : undefined, v];\n const list = arr.length === n ? arr : [...Array(n - arr.length).fill(arr[0]), ...arr];\n list.forEach((x, i) => { if (x !== undefined && x !== null) frames[i].props[p] = x as V; });\n }\n if (Array.isArray(tr.ease) && tr.ease.length && (Array.isArray(tr.ease[0]) || typeof tr.ease[0] === 'string')) {\n (tr.ease as (string | number[])[]).forEach((e, i) => { if (frames[i]) frames[i].easing = Array.isArray(e) ? `cubic-bezier(${e.join(',')})` : NAMES[e] || e; });\n }\n return { frames, transition: tr, props };\n });\n}\n\n/**\n * Apply `initial` immediately and play `animate` with the transition.\n * Returns a runtime `Timeline` (one child per transition group), playing unless `paused`.\n */\nexport function playMotion(target: Target, def: MotionDef, o: { paused?: boolean } = {}): Timeline {\n const tl = new Timeline({});\n if (def.initial) for (const [k, v] of Object.entries(def.initial)) framesToTimeline(target, [{ offset: 0, props: { [k]: v } }], { duration: 0 }).seek(0);\n for (const { frames, transition: tr } of fromMotion(def)) {\n let ease: Ease | undefined;\n let dur = (tr.duration ?? 0.3) * 1000;\n if (tr.type === 'spring') [ease, dur] = springEase({ ...tr, duration: tr.duration });\n else if (!Array.isArray(tr.ease) || typeof tr.ease[0] === 'number') ease = motionEase(tr.ease as string | number[] | undefined);\n const rep = tr.repeat === Infinity ? -1 : tr.repeat || 0;\n const child = framesToTimeline(target, frames, { duration: dur, ease, repeat: rep, yoyo: rep !== 0 && tr.repeatType !== 'loop' && !!tr.repeatType });\n tl.add(child, (tr.delay || 0) * 1000);\n }\n if (!o.paused) tl.play();\n return tl;\n}\n\nexport interface FormatMotionApi {\n fromMotion: typeof fromMotion;\n playMotion: typeof playMotion;\n springEase: typeof springEase;\n motionEase: typeof motionEase;\n}\n\n/** The module object for `use(formatMotion)`. */\nexport const formatMotion: RuntimeModule<FormatMotionApi> = { id: 'format-motion', version: RUNTIME_VERSION, requires: ['core'], api: { fromMotion, playMotion, springEase, motionEase } };\n"],"names":["cubicBezier","EASES","Timeline","framesToTimeline","RUNTIME_VERSION"],"mappings":";;;;;;;AAAA;;;;;;;;;;;;;;;;;;;AAmBG;AA2BH,MAAM,KAAK,GAA2B,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,aAAa,EAAE;AAE9R;AACM,SAAU,UAAU,CAAC,CAA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import { c as cubicBezier, E as EASES, T as Timeline } from '../chunks/tween-DDObu9iA.js';
3
- import { f as framesToTimeline } from '../chunks/keyframes-CyH_abhI.js';
1
+ import { R as RUNTIME_VERSION } from '../chunks/registry-BIEjKngP.js';
2
+ import { c as cubicBezier, E as EASES, T as Timeline } from '../chunks/tween-CqX1JBuj.js';
3
+ import { f as framesToTimeline } from '../chunks/keyframes-W-474DMc.js';
4
+ import '../chunks/ticker-CM_56oVy.js';
4
5
 
5
6
  /**
6
7
  * `motionary/runtime/format-motion` (10.1) — play Motion / Framer-style
@@ -1 +1 @@
1
- {"version":3,"file":"format-motion.js","sources":["../../src/runtime/format-motion.ts"],"sourcesContent":["/**\n * `motionary/runtime/format-motion` (10.1) — play Motion / Framer-style\n * keyframe JSON with the runtime:\n *\n * ```json\n * { \"initial\": { \"opacity\": 0, \"y\": 40 },\n * \"animate\": { \"opacity\": 1, \"y\": [40, -8, 0], \"rotate\": 0 },\n * \"transition\": { \"duration\": 0.6, \"ease\": \"easeOut\", \"times\": [0, 0.7, 1], \"delay\": 0.1,\n * \"repeat\": 1, \"repeatType\": \"reverse\", \"opacity\": { \"duration\": 0.3 } } }\n * ```\n *\n * Supported: `initial` / `animate` (numbers, unit strings, colours, arrays as\n * keyframes), the transform shorthands `x y scale scaleX scaleY rotate skewX skewY`,\n * transition `duration` / `delay` (seconds) / `ease` (names or `[x1, y1, x2, y2]`) /\n * `times` / `repeat` (`Infinity` ok) / `repeatType` (`loop`, `reverse`, `mirror`),\n * per-property transitions, and `type: \"spring\"` (`stiffness`, `damping`, `mass`,\n * or `bounce` + `duration`) simulated into an easing curve.\n * Not supported: `layout`, gestures (`whileHover` …), variants propagation,\n * `staggerChildren` (use the runtime timeline `stagger`).\n */\nimport { RUNTIME_VERSION, type RuntimeModule } from './registry';\nimport { Timeline, type Target } from './tween';\nimport { cubicBezier, type Ease, EASES } from './ease';\nimport { framesToTimeline, type Frame } from './keyframes';\n\ntype V = number | string;\nexport interface MotionTransition {\n duration?: number;\n delay?: number;\n ease?: string | number[] | (string | number[])[];\n times?: number[];\n repeat?: number;\n repeatType?: 'loop' | 'reverse' | 'mirror';\n type?: 'tween' | 'spring' | 'keyframes' | 'inertia';\n stiffness?: number;\n damping?: number;\n mass?: number;\n bounce?: number;\n [prop: string]: unknown;\n}\nexport interface MotionDef {\n initial?: Record<string, V> | false;\n animate: Record<string, V | V[]>;\n transition?: MotionTransition;\n}\n\nconst NAMES: Record<string, string> = { linear: 'linear', easeIn: 'cubic-in', easeOut: 'cubic-out', easeInOut: 'cubic-in-out', circIn: 'circ-in', circOut: 'circ-out', circInOut: 'circ-in-out', backIn: 'back-in', backOut: 'back-out', backInOut: 'back-in-out', anticipate: 'back-in-out' };\n\n/** A Motion ease → runtime ease. */\nexport function motionEase(e: string | number[] | undefined): Ease {\n if (Array.isArray(e)) return cubicBezier(e[0], e[1], e[2], e[3]);\n if (!e) return EASES['cubic-out'];\n const n = NAMES[e] || e;\n if (!EASES[n]) throw new Error(`[motionary] format-motion: unknown ease \"${e}\"`);\n return EASES[n];\n}\n\n/** Simulate a damped spring (unit step) → [ease, duration ms]. */\nexport function springEase(o: { stiffness?: number; damping?: number; mass?: number; bounce?: number; duration?: number }): [Ease, number] {\n let k = o.stiffness ?? 100, c = o.damping ?? 10;\n const m = o.mass ?? 1;\n if (o.bounce !== undefined && o.duration !== undefined) {\n // map bounce + duration to stiffness / damping (critical damping at bounce 0)\n const zeta = 1 - Math.min(0.95, Math.max(0, o.bounce));\n const w = (2 * Math.PI) / Math.max(0.05, o.duration);\n k = m * w * w;\n c = 2 * zeta * Math.sqrt(k * m);\n }\n const dt = 1 / 120;\n const samples: number[] = [0];\n let x = 0, v = 0, t = 0, still = 0;\n while (t < 10) {\n const a = (-k * (x - 1) - c * v) / m;\n v += a * dt;\n x += v * dt;\n t += dt;\n samples.push(x);\n if (Math.abs(x - 1) < 0.001 && Math.abs(v) < 0.01) { if (++still > 12) break; } else still = 0;\n }\n const n = samples.length - 1;\n samples[n] = 1;\n const ease: Ease = (p) => {\n if (p <= 0) return 0;\n if (p >= 1) return 1;\n const f = p * n, i = Math.floor(f);\n return samples[i] + (samples[i + 1] - samples[i]) * (f - i);\n };\n return [ease, Math.round(t * 1000)];\n}\n\n/** Motion def → one keyframe track per transition group (`[frames, transition]`). */\nexport function fromMotion(def: MotionDef): { frames: Frame[]; transition: MotionTransition; props: string[] }[] {\n const base = def.transition || {};\n const groups = new Map<string, string[]>();\n for (const k of Object.keys(def.animate)) {\n const own = base[k] && typeof base[k] === 'object' ? k : '';\n groups.set(own, [...(groups.get(own) || []), k]);\n }\n return Array.from(groups.entries()).map(([g, props]) => {\n const tr: MotionTransition = g ? { ...base, ...(base[g] as MotionTransition) } : base;\n const len = Math.max(...props.map((p) => (Array.isArray(def.animate[p]) ? (def.animate[p] as V[]).length : 1)));\n const n = Math.max(2, len);\n const times = tr.times && tr.times.length === n ? tr.times : Array.from({ length: n }, (_, i) => i / (n - 1));\n const frames: Frame[] = times.map((offset) => ({ offset, props: {} }));\n for (const p of props) {\n const v = def.animate[p];\n const arr = Array.isArray(v) ? v : [def.initial && p in def.initial ? def.initial[p] : undefined, v];\n const list = arr.length === n ? arr : [...Array(n - arr.length).fill(arr[0]), ...arr];\n list.forEach((x, i) => { if (x !== undefined && x !== null) frames[i].props[p] = x as V; });\n }\n if (Array.isArray(tr.ease) && tr.ease.length && (Array.isArray(tr.ease[0]) || typeof tr.ease[0] === 'string')) {\n (tr.ease as (string | number[])[]).forEach((e, i) => { if (frames[i]) frames[i].easing = Array.isArray(e) ? `cubic-bezier(${e.join(',')})` : NAMES[e] || e; });\n }\n return { frames, transition: tr, props };\n });\n}\n\n/**\n * Apply `initial` immediately and play `animate` with the transition.\n * Returns a runtime `Timeline` (one child per transition group), playing unless `paused`.\n */\nexport function playMotion(target: Target, def: MotionDef, o: { paused?: boolean } = {}): Timeline {\n const tl = new Timeline({});\n if (def.initial) for (const [k, v] of Object.entries(def.initial)) framesToTimeline(target, [{ offset: 0, props: { [k]: v } }], { duration: 0 }).seek(0);\n for (const { frames, transition: tr } of fromMotion(def)) {\n let ease: Ease | undefined;\n let dur = (tr.duration ?? 0.3) * 1000;\n if (tr.type === 'spring') [ease, dur] = springEase({ ...tr, duration: tr.duration });\n else if (!Array.isArray(tr.ease) || typeof tr.ease[0] === 'number') ease = motionEase(tr.ease as string | number[] | undefined);\n const rep = tr.repeat === Infinity ? -1 : tr.repeat || 0;\n const child = framesToTimeline(target, frames, { duration: dur, ease, repeat: rep, yoyo: rep !== 0 && tr.repeatType !== 'loop' && !!tr.repeatType });\n tl.add(child, (tr.delay || 0) * 1000);\n }\n if (!o.paused) tl.play();\n return tl;\n}\n\nexport interface FormatMotionApi {\n fromMotion: typeof fromMotion;\n playMotion: typeof playMotion;\n springEase: typeof springEase;\n motionEase: typeof motionEase;\n}\n\n/** The module object for `use(formatMotion)`. */\nexport const formatMotion: RuntimeModule<FormatMotionApi> = { id: 'format-motion', version: RUNTIME_VERSION, requires: ['core'], api: { fromMotion, playMotion, springEase, motionEase } };\n"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;;;;;;;;;;AAmBG;AA2BH,MAAM,KAAK,GAA2B,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,aAAa,EAAE;AAE9R;AACM,SAAU,UAAU,CAAC,CAAgC,EAAA;AACzD,IAAA,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAAE,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC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E,aAAA,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ;AAAE,YAAA,IAAI,GAAG,UAAU,CAAC,EAAE,CAAC,IAAqC,CAAC;QAC/H,MAAM,GAAG,GAAG,EAAE,CAAC,MAAM,KAAK,QAAQ,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,IAAI,CAAC;AACxD,QAAA,MAAM,KAAK,GAAG,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,UAAU,KAAK,MAAM,IAAI,CAAC,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC;AACpJ,QAAA,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC,IAAI,IAAI,CAAC;IACvC;IACA,IAAI,CAAC,CAAC,CAAC,MAAM;QAAE,EAAE,CAAC,IAAI,EAAE;AACxB,IAAA,OAAO,EAAE;AACX;AASA;AACO,MAAM,YAAY,GAAmC,EAAE,EAAE,EAAE,eAAe,EAAE,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE;;;;"}
1
+ {"version":3,"file":"format-motion.js","sources":["../../src/runtime/format-motion.ts"],"sourcesContent":["/**\n * `motionary/runtime/format-motion` (10.1) — play Motion / Framer-style\n * keyframe JSON with the runtime:\n *\n * ```json\n * { \"initial\": { \"opacity\": 0, \"y\": 40 },\n * \"animate\": { \"opacity\": 1, \"y\": [40, -8, 0], \"rotate\": 0 },\n * \"transition\": { \"duration\": 0.6, \"ease\": \"easeOut\", \"times\": [0, 0.7, 1], \"delay\": 0.1,\n * \"repeat\": 1, \"repeatType\": \"reverse\", \"opacity\": { \"duration\": 0.3 } } }\n * ```\n *\n * Supported: `initial` / `animate` (numbers, unit strings, colours, arrays as\n * keyframes), the transform shorthands `x y scale scaleX scaleY rotate skewX skewY`,\n * transition `duration` / `delay` (seconds) / `ease` (names or `[x1, y1, x2, y2]`) /\n * `times` / `repeat` (`Infinity` ok) / `repeatType` (`loop`, `reverse`, `mirror`),\n * per-property transitions, and `type: \"spring\"` (`stiffness`, `damping`, `mass`,\n * or `bounce` + `duration`) simulated into an easing curve.\n * Not supported: `layout`, gestures (`whileHover` …), variants propagation,\n * `staggerChildren` (use the runtime timeline `stagger`).\n */\nimport { RUNTIME_VERSION, type RuntimeModule } from './registry';\nimport { Timeline, type Target } from './tween';\nimport { cubicBezier, type Ease, EASES } from './ease';\nimport { framesToTimeline, type Frame } from './keyframes';\n\ntype V = number | string;\nexport interface MotionTransition {\n duration?: number;\n delay?: number;\n ease?: string | number[] | (string | number[])[];\n times?: number[];\n repeat?: number;\n repeatType?: 'loop' | 'reverse' | 'mirror';\n type?: 'tween' | 'spring' | 'keyframes' | 'inertia';\n stiffness?: number;\n damping?: number;\n mass?: number;\n bounce?: number;\n [prop: string]: unknown;\n}\nexport interface MotionDef {\n initial?: Record<string, V> | false;\n animate: Record<string, V | V[]>;\n transition?: MotionTransition;\n}\n\nconst NAMES: Record<string, string> = { linear: 'linear', easeIn: 'cubic-in', easeOut: 'cubic-out', easeInOut: 'cubic-in-out', circIn: 'circ-in', circOut: 'circ-out', circInOut: 'circ-in-out', backIn: 'back-in', backOut: 'back-out', backInOut: 'back-in-out', anticipate: 'back-in-out' };\n\n/** A Motion ease → runtime ease. */\nexport function motionEase(e: string | number[] | undefined): Ease {\n if (Array.isArray(e)) return cubicBezier(e[0], e[1], e[2], e[3]);\n if (!e) return EASES['cubic-out'];\n const n = NAMES[e] || e;\n if (!EASES[n]) throw new Error(`[motionary] format-motion: unknown ease \"${e}\"`);\n return EASES[n];\n}\n\n/** Simulate a damped spring (unit step) → [ease, duration ms]. */\nexport function springEase(o: { stiffness?: number; damping?: number; mass?: number; bounce?: number; duration?: number }): [Ease, number] {\n let k = o.stiffness ?? 100, c = o.damping ?? 10;\n const m = o.mass ?? 1;\n if (o.bounce !== undefined && o.duration !== undefined) {\n // map bounce + duration to stiffness / damping (critical damping at bounce 0)\n const zeta = 1 - Math.min(0.95, Math.max(0, o.bounce));\n const w = (2 * Math.PI) / Math.max(0.05, o.duration);\n k = m * w * w;\n c = 2 * zeta * Math.sqrt(k * m);\n }\n const dt = 1 / 120;\n const samples: number[] = [0];\n let x = 0, v = 0, t = 0, still = 0;\n while (t < 10) {\n const a = (-k * (x - 1) - c * v) / m;\n v += a * dt;\n x += v * dt;\n t += dt;\n samples.push(x);\n if (Math.abs(x - 1) < 0.001 && Math.abs(v) < 0.01) { if (++still > 12) break; } else still = 0;\n }\n const n = samples.length - 1;\n samples[n] = 1;\n const ease: Ease = (p) => {\n if (p <= 0) return 0;\n if (p >= 1) return 1;\n const f = p * n, i = Math.floor(f);\n return samples[i] + (samples[i + 1] - samples[i]) * (f - i);\n };\n return [ease, Math.round(t * 1000)];\n}\n\n/** Motion def → one keyframe track per transition group (`[frames, transition]`). */\nexport function fromMotion(def: MotionDef): { frames: Frame[]; transition: MotionTransition; props: string[] }[] {\n const base = def.transition || {};\n const groups = new Map<string, string[]>();\n for (const k of Object.keys(def.animate)) {\n const own = base[k] && typeof base[k] === 'object' ? k : '';\n groups.set(own, [...(groups.get(own) || []), k]);\n }\n return Array.from(groups.entries()).map(([g, props]) => {\n const tr: MotionTransition = g ? { ...base, ...(base[g] as MotionTransition) } : base;\n const len = Math.max(...props.map((p) => (Array.isArray(def.animate[p]) ? (def.animate[p] as V[]).length : 1)));\n const n = Math.max(2, len);\n const times = tr.times && tr.times.length === n ? tr.times : Array.from({ length: n }, (_, i) => i / (n - 1));\n const frames: Frame[] = times.map((offset) => ({ offset, props: {} }));\n for (const p of props) {\n const v = def.animate[p];\n const arr = Array.isArray(v) ? v : [def.initial && p in def.initial ? def.initial[p] : undefined, v];\n const list = arr.length === n ? arr : [...Array(n - arr.length).fill(arr[0]), ...arr];\n list.forEach((x, i) => { if (x !== undefined && x !== null) frames[i].props[p] = x as V; });\n }\n if (Array.isArray(tr.ease) && tr.ease.length && (Array.isArray(tr.ease[0]) || typeof tr.ease[0] === 'string')) {\n (tr.ease as (string | number[])[]).forEach((e, i) => { if (frames[i]) frames[i].easing = Array.isArray(e) ? `cubic-bezier(${e.join(',')})` : NAMES[e] || e; });\n }\n return { frames, transition: tr, props };\n });\n}\n\n/**\n * Apply `initial` immediately and play `animate` with the transition.\n * Returns a runtime `Timeline` (one child per transition group), playing unless `paused`.\n */\nexport function playMotion(target: Target, def: MotionDef, o: { paused?: boolean } = {}): Timeline {\n const tl = new Timeline({});\n if (def.initial) for (const [k, v] of Object.entries(def.initial)) framesToTimeline(target, [{ offset: 0, props: { [k]: v } }], { duration: 0 }).seek(0);\n for (const { frames, transition: tr } of fromMotion(def)) {\n let ease: Ease | undefined;\n let dur = (tr.duration ?? 0.3) * 1000;\n if (tr.type === 'spring') [ease, dur] = springEase({ ...tr, duration: tr.duration });\n else if (!Array.isArray(tr.ease) || typeof tr.ease[0] === 'number') ease = motionEase(tr.ease as string | number[] | undefined);\n const rep = tr.repeat === Infinity ? -1 : tr.repeat || 0;\n const child = framesToTimeline(target, frames, { duration: dur, ease, repeat: rep, yoyo: rep !== 0 && tr.repeatType !== 'loop' && !!tr.repeatType });\n tl.add(child, (tr.delay || 0) * 1000);\n }\n if (!o.paused) tl.play();\n return tl;\n}\n\nexport interface FormatMotionApi {\n fromMotion: typeof fromMotion;\n playMotion: typeof playMotion;\n springEase: typeof springEase;\n motionEase: typeof motionEase;\n}\n\n/** The module object for `use(formatMotion)`. */\nexport const formatMotion: RuntimeModule<FormatMotionApi> = { id: 'format-motion', version: RUNTIME_VERSION, requires: ['core'], api: { fromMotion, playMotion, springEase, motionEase } };\n"],"names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;IACvC;IACA,IAAI,CAAC,CAAC,CAAC,MAAM;QAAE,EAAE,CAAC,IAAI,EAAE;AACxB,IAAA,OAAO,EAAE;AACX;AASA;AACO,MAAM,YAAY,GAAmC,EAAE,EAAE,EAAE,eAAe,EAAE,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE;;;;"}
@@ -0,0 +1,457 @@
1
+ 'use strict';
2
+
3
+ var registry = require('../chunks/registry-eJgpFAzI.cjs');
4
+ var tween = require('../chunks/tween-CBuWYpI-.cjs');
5
+ require('../chunks/ticker-D4o6enH0.cjs');
6
+
7
+ /**
8
+ * `motionary/runtime/format-svg` (10.2) — SVG animation with the runtime
9
+ * (original implementation):
10
+ *
11
+ * - **Path geometry** without the DOM (SSR / workers): `parsePath(d)` (all
12
+ * commands, relative + absolute, arcs), `flattenPath(d)`, `pathLength(d)`,
13
+ * `pointAtLength(d, len)`, `samplePath(d, n)`.
14
+ * - **Path morphing**: `morphPath(from, to, { points })` → `(p) => d` — both
15
+ * paths are resampled to the same number of points (any command mix, any
16
+ * point counts), aligned to the closest start point, then interpolated.
17
+ * - **SMIL playback**: `playSmil(svg)` reads `<animate>`, `<set>`,
18
+ * `<animateTransform>` (translate / scale / rotate / skewX / skewY) and
19
+ * `<animateMotion>` (`path` or `<mpath>`, `rotate="auto"`) — `from` / `to` /
20
+ * `by` / `values`, `keyTimes`, `keySplines` (`calcMode="spline"`),
21
+ * `calcMode="discrete"`, `dur`, numeric `begin` offsets, `repeatCount`
22
+ * (incl. `indefinite`), `fill="freeze"` — and replays them as a runtime
23
+ * timeline (seek, scrub, reverse, timeScale) instead of the browser's SMIL clock.
24
+ * - CSS-animated SVG: use `motionary/runtime/format-css` (`@keyframes` in the SVG's `<style>`).
25
+ *
26
+ * Not supported (documented): event / syncbase `begin` values (`click`,
27
+ * `a.end`), `accumulate` / `additive="sum"`, `<animateColor>` (deprecated).
28
+ */
29
+ const ARGS = { M: 2, L: 2, H: 1, V: 1, C: 6, S: 4, Q: 4, T: 2, A: 7, Z: 0 };
30
+ /** Parse path data into absolute commands (M L C Q A Z; H/V/S/T expanded). */
31
+ function parsePath(d) {
32
+ const toks = d.match(/[a-zA-Z]|[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g) || [];
33
+ const out = [];
34
+ let i = 0, cmd = '', x = 0, y = 0, sx = 0, sy = 0, lc = null, lq = null;
35
+ const num = () => parseFloat(toks[i++]);
36
+ while (i < toks.length) {
37
+ if (/[a-zA-Z]/.test(toks[i]))
38
+ cmd = toks[i++];
39
+ else if (!cmd)
40
+ throw new Error('[motionary] format-svg: path must start with a command');
41
+ const C = cmd.toUpperCase(), rel = cmd !== C;
42
+ const n = ARGS[C];
43
+ if (n === undefined)
44
+ throw new Error(`[motionary] format-svg: unknown path command "${cmd}"`);
45
+ if (C === 'Z') {
46
+ out.push(['Z']);
47
+ x = sx;
48
+ y = sy;
49
+ lc = lq = null;
50
+ continue;
51
+ }
52
+ const a = [];
53
+ for (let k = 0; k < n; k++)
54
+ a.push(num());
55
+ if (a.some((v) => Number.isNaN(v)))
56
+ break;
57
+ const ox = rel ? x : 0, oy = rel ? y : 0;
58
+ switch (C) {
59
+ case 'M':
60
+ x = a[0] + ox;
61
+ y = a[1] + oy;
62
+ sx = x;
63
+ sy = y;
64
+ out.push(['M', x, y]);
65
+ cmd = rel ? 'l' : 'L';
66
+ lc = lq = null;
67
+ break;
68
+ case 'L':
69
+ x = a[0] + ox;
70
+ y = a[1] + oy;
71
+ out.push(['L', x, y]);
72
+ lc = lq = null;
73
+ break;
74
+ case 'H':
75
+ x = a[0] + ox;
76
+ out.push(['L', x, y]);
77
+ lc = lq = null;
78
+ break;
79
+ case 'V':
80
+ y = a[0] + (rel ? y : 0);
81
+ out.push(['L', x, y]);
82
+ lc = lq = null;
83
+ break;
84
+ case 'C': {
85
+ const c = [a[0] + ox, a[1] + oy, a[2] + ox, a[3] + oy, a[4] + ox, a[5] + oy];
86
+ out.push(['C', ...c]);
87
+ lc = [c[2], c[3]];
88
+ x = c[4];
89
+ y = c[5];
90
+ lq = null;
91
+ break;
92
+ }
93
+ case 'S': {
94
+ const c1 = lc ? [2 * x - lc[0], 2 * y - lc[1]] : [x, y];
95
+ const c = [a[0] + ox, a[1] + oy, a[2] + ox, a[3] + oy];
96
+ out.push(['C', c1[0], c1[1], ...c]);
97
+ lc = [c[0], c[1]];
98
+ x = c[2];
99
+ y = c[3];
100
+ lq = null;
101
+ break;
102
+ }
103
+ case 'Q': {
104
+ const c = [a[0] + ox, a[1] + oy, a[2] + ox, a[3] + oy];
105
+ out.push(['Q', ...c]);
106
+ lq = [c[0], c[1]];
107
+ x = c[2];
108
+ y = c[3];
109
+ lc = null;
110
+ break;
111
+ }
112
+ case 'T': {
113
+ const c1 = lq ? [2 * x - lq[0], 2 * y - lq[1]] : [x, y];
114
+ x = a[0] + ox;
115
+ y = a[1] + oy;
116
+ out.push(['Q', c1[0], c1[1], x, y]);
117
+ lq = c1;
118
+ lc = null;
119
+ break;
120
+ }
121
+ case 'A': {
122
+ x = a[5] + ox;
123
+ y = a[6] + oy;
124
+ out.push(['A', a[0], a[1], a[2], a[3], a[4], x, y]);
125
+ lc = lq = null;
126
+ break;
127
+ }
128
+ }
129
+ }
130
+ return out;
131
+ }
132
+ /** Endpoint-parameterised arc → points (SVG spec F.6.5 conversion). */
133
+ function arcPoints(x1, y1, rx, ry, phiDeg, large, sweep, x2, y2, seg) {
134
+ if (!rx || !ry)
135
+ return [[x2, y2]];
136
+ rx = Math.abs(rx);
137
+ ry = Math.abs(ry);
138
+ const phi = (phiDeg * Math.PI) / 180, cos = Math.cos(phi), sin = Math.sin(phi);
139
+ const dx = (x1 - x2) / 2, dy = (y1 - y2) / 2;
140
+ const xp = cos * dx + sin * dy, yp = -sin * dx + cos * dy;
141
+ const lam = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);
142
+ if (lam > 1) {
143
+ rx *= Math.sqrt(lam);
144
+ ry *= Math.sqrt(lam);
145
+ }
146
+ const num = rx * rx * ry * ry - rx * rx * yp * yp - ry * ry * xp * xp;
147
+ const den = rx * rx * yp * yp + ry * ry * xp * xp;
148
+ let co = Math.sqrt(Math.max(0, num / den));
149
+ if (large === sweep)
150
+ co = -co;
151
+ const cxp = (co * rx * yp) / ry, cyp = (-co * ry * xp) / rx;
152
+ const cx = cos * cxp - sin * cyp + (x1 + x2) / 2, cy = sin * cxp + cos * cyp + (y1 + y2) / 2;
153
+ const ang = (ux, uy, vx, vy) => Math.atan2(ux * vy - uy * vx, ux * vx + uy * vy);
154
+ const t1 = ang(1, 0, (xp - cxp) / rx, (yp - cyp) / ry);
155
+ let dt = ang((xp - cxp) / rx, (yp - cyp) / ry, (-xp - cxp) / rx, (-yp - cyp) / ry);
156
+ if (!sweep && dt > 0)
157
+ dt -= 2 * Math.PI;
158
+ if (sweep && dt < 0)
159
+ dt += 2 * Math.PI;
160
+ const n = Math.max(2, Math.ceil((Math.abs(dt) / (Math.PI / 2)) * seg));
161
+ const pts = [];
162
+ for (let k = 1; k <= n; k++) {
163
+ const t = t1 + (dt * k) / n;
164
+ pts.push([cx + rx * Math.cos(t) * cos - ry * Math.sin(t) * sin, cy + rx * Math.cos(t) * sin + ry * Math.sin(t) * cos]);
165
+ }
166
+ return pts;
167
+ }
168
+ /** Flatten a path into polylines (one per subpath); `segments` points per curve. */
169
+ function flattenPath(d, segments = 16) {
170
+ const cmds = typeof d === 'string' ? parsePath(d) : d;
171
+ const subs = [];
172
+ let cur = [], x = 0, y = 0;
173
+ for (const c of cmds) {
174
+ const [k, ...a] = c;
175
+ if (k === 'M') {
176
+ if (cur.length)
177
+ subs.push(cur);
178
+ cur = [[a[0], a[1]]];
179
+ x = a[0];
180
+ y = a[1];
181
+ continue;
182
+ }
183
+ if (!cur.length)
184
+ cur = [[x, y]];
185
+ if (k === 'L')
186
+ cur.push([a[0], a[1]]);
187
+ else if (k === 'C')
188
+ for (let i = 1; i <= segments; i++) {
189
+ const t = i / segments, u = 1 - t;
190
+ cur.push([u * u * u * x + 3 * u * u * t * a[0] + 3 * u * t * t * a[2] + t * t * t * a[4], u * u * u * y + 3 * u * u * t * a[1] + 3 * u * t * t * a[3] + t * t * t * a[5]]);
191
+ }
192
+ else if (k === 'Q')
193
+ for (let i = 1; i <= segments; i++) {
194
+ const t = i / segments, u = 1 - t;
195
+ cur.push([u * u * x + 2 * u * t * a[0] + t * t * a[2], u * u * y + 2 * u * t * a[1] + t * t * a[3]]);
196
+ }
197
+ else if (k === 'A')
198
+ cur.push(...arcPoints(x, y, a[0], a[1], a[2], a[3], a[4], a[5], a[6], segments / 4));
199
+ else if (k === 'Z') {
200
+ cur.push([cur[0][0], cur[0][1]]);
201
+ subs.push(cur);
202
+ x = cur[0][0];
203
+ y = cur[0][1];
204
+ cur = [];
205
+ continue;
206
+ }
207
+ const last = cur[cur.length - 1];
208
+ x = last[0];
209
+ y = last[1];
210
+ }
211
+ if (cur.length)
212
+ subs.push(cur);
213
+ return subs;
214
+ }
215
+ const dist = (a, b) => Math.hypot(b[0] - a[0], b[1] - a[1]);
216
+ /** Total length of a path. */
217
+ function pathLength(d) {
218
+ return flattenPath(d, 48).reduce((s, pl) => s + pl.slice(1).reduce((t, p, i) => t + dist(pl[i], p), 0), 0);
219
+ }
220
+ /** Point (and tangent angle, degrees) at a distance along the path. */
221
+ function pointAtLength(d, len) {
222
+ const pl = flattenPath(d, 48).flat();
223
+ let acc = 0;
224
+ for (let i = 1; i < pl.length; i++) {
225
+ const s = dist(pl[i - 1], pl[i]);
226
+ if (acc + s >= len || i === pl.length - 1) {
227
+ const t = s ? Math.min(1, Math.max(0, (len - acc) / s)) : 0;
228
+ return { x: pl[i - 1][0] + (pl[i][0] - pl[i - 1][0]) * t, y: pl[i - 1][1] + (pl[i][1] - pl[i - 1][1]) * t, angle: (Math.atan2(pl[i][1] - pl[i - 1][1], pl[i][0] - pl[i - 1][0]) * 180) / Math.PI };
229
+ }
230
+ acc += s;
231
+ }
232
+ return { x: pl[0]?.[0] ?? 0, y: pl[0]?.[1] ?? 0, angle: 0 };
233
+ }
234
+ /** `n` points evenly spaced along the path (all subpaths joined). */
235
+ function samplePath(d, n = 64) {
236
+ const total = pathLength(d);
237
+ return Array.from({ length: n }, (_, i) => {
238
+ const p = pointAtLength(d, (total * i) / (n - 1 || 1));
239
+ return [p.x, p.y];
240
+ });
241
+ }
242
+ const r3 = (v) => Math.round(v * 1000) / 1000;
243
+ const closed = (d) => /z\s*$/i.test(d.trim());
244
+ /**
245
+ * Morph between two paths of any shape: `const f = morphPath(a, b); el.setAttribute('d', f(0.5))`.
246
+ * Closed paths are rotated so their start points line up (less twisting).
247
+ */
248
+ function morphPath(from, to, o = {}) {
249
+ const n = o.points ?? 64;
250
+ const A = samplePath(from, n);
251
+ let B = samplePath(to, n);
252
+ const isClosed = closed(from) && closed(to);
253
+ if (isClosed) {
254
+ let best = 0, bestD = Infinity;
255
+ for (let s = 0; s < n; s++) {
256
+ let sum = 0;
257
+ for (let i = 0; i < n; i += 4)
258
+ sum += dist(A[i], B[(i + s) % n]);
259
+ if (sum < bestD) {
260
+ bestD = sum;
261
+ best = s;
262
+ }
263
+ }
264
+ B = B.map((_, i) => B[(i + best) % n]);
265
+ }
266
+ return (p) => {
267
+ if (p <= 0)
268
+ return from;
269
+ if (p >= 1)
270
+ return to;
271
+ return 'M' + A.map((a, i) => `${r3(a[0] + (B[i][0] - a[0]) * p)} ${r3(a[1] + (B[i][1] - a[1]) * p)}`).join('L') + (isClosed ? 'Z' : '');
272
+ };
273
+ }
274
+ /* ------------------------------------------------------------------ SMIL */
275
+ /** '2s', '150ms', '1.5', 'indefinite' → ms (NaN for indefinite / unsupported). */
276
+ function smilTime(v) {
277
+ if (!v)
278
+ return NaN;
279
+ const s = v.trim();
280
+ const m = /^(-?[\d.]+)(ms|s|min|h)?$/.exec(s);
281
+ if (!m) {
282
+ const c = /^(?:(\d+):)?(\d+):(\d+(?:\.\d+)?)$/.exec(s);
283
+ return c ? ((+(c[1] || 0) * 60 + +c[2]) * 60 + +c[3]) * 1000 : NaN;
284
+ }
285
+ const n = parseFloat(m[1]);
286
+ return m[2] === 'ms' ? n : m[2] === 'min' ? n * 60000 : m[2] === 'h' ? n * 3600000 : n * 1000;
287
+ }
288
+ const numList = (s) => s.trim().split(/[\s,]+/).filter(Boolean).map(Number);
289
+ const lerpNumbers = (a, b, p) => {
290
+ const x = numList(a), y = numList(b);
291
+ return x.map((v, i) => r3(v + ((y[i] ?? v) - v) * p)).join(' ');
292
+ };
293
+ const lerpAny = (a, b, p) => {
294
+ try {
295
+ const x = tween.parseValue(a), y = tween.parseValue(b);
296
+ if (x.kind === 'str' || y.kind === 'str')
297
+ throw 0; // number lists / keywords: handled below
298
+ if (x.kind === 'col' || y.kind === 'col') {
299
+ const ca = x.kind === 'col' ? x.c : [0, 0, 0, 1], cb = y.kind === 'col' ? y.c : [0, 0, 0, 1];
300
+ const c = ca.map((v, i) => v + (cb[i] - v) * p);
301
+ return `rgba(${Math.round(c[0])},${Math.round(c[1])},${Math.round(c[2])},${r3(c[3])})`;
302
+ }
303
+ return `${r3(x.v + (y.v - x.v) * p)}${y.u || x.u}`;
304
+ }
305
+ catch {
306
+ if (/^[-\d.\s,e]+$/i.test(a) && /^[-\d.\s,e]+$/i.test(b))
307
+ return lerpNumbers(a, b, p);
308
+ return p < 0.5 ? a : b;
309
+ }
310
+ };
311
+ /** Read the SMIL animation elements of an SVG (without playing them). */
312
+ function readSmil(svg) {
313
+ const out = [];
314
+ svg.querySelectorAll('animate, set, animateTransform, animateMotion').forEach((el) => {
315
+ const kind = el.localName;
316
+ const href = el.getAttribute('href') || el.getAttribute('xlink:href');
317
+ const target = href ? svg.querySelector(href) : el.parentElement;
318
+ if (!target)
319
+ return;
320
+ const begin = smilTime((el.getAttribute('begin') || '0').split(';')[0]);
321
+ const dur = kind === 'set' ? smilTime(el.getAttribute('dur')) || 0 : smilTime(el.getAttribute('dur'));
322
+ const rc = el.getAttribute('repeatCount');
323
+ const rd = smilTime(el.getAttribute('repeatDur'));
324
+ let repeat = rc === 'indefinite' || el.getAttribute('repeatDur') === 'indefinite' ? -1 : rc ? Math.max(0, Math.ceil(parseFloat(rc)) - 1) : 0;
325
+ if (!rc && rd > 0 && dur > 0)
326
+ repeat = Math.ceil(rd / dur) - 1;
327
+ const attribute = kind === 'animateTransform' ? 'transform' : kind === 'animateMotion' ? 'transform' : el.getAttribute('attributeName') || '';
328
+ let values;
329
+ const v = el.getAttribute('values');
330
+ if (kind === 'set')
331
+ values = [el.getAttribute('to') || ''];
332
+ else if (kind === 'animateMotion') {
333
+ const mp = el.querySelector('mpath');
334
+ const ref = mp && (mp.getAttribute('href') || mp.getAttribute('xlink:href'));
335
+ values = [(ref && svg.querySelector(ref)?.getAttribute('d')) || el.getAttribute('path') || ''];
336
+ }
337
+ else if (v)
338
+ values = v.split(';').map((s) => s.trim()).filter((s) => s !== '');
339
+ else {
340
+ const base = target.getAttribute(attribute) || (attribute === 'opacity' ? '1' : '0');
341
+ const from = el.getAttribute('from') ?? base;
342
+ const by = el.getAttribute('by');
343
+ const to = el.getAttribute('to') ?? (by !== null ? numList(from).map((x, i) => x + (numList(by)[i] ?? 0)).join(' ') : base);
344
+ values = [from, to];
345
+ }
346
+ const kt = el.getAttribute('keyTimes');
347
+ out.push({ kind, target, attribute, begin: Number.isFinite(begin) ? begin : 0, dur: Number.isFinite(dur) ? dur : 0, repeat, freeze: el.getAttribute('fill') === 'freeze' || (kind === 'set' && !el.getAttribute('dur')) /* a <set> without dur holds its value */, values, keyTimes: kt ? kt.split(';').map(Number) : [], calcMode: el.getAttribute('calcMode') || (kind === 'animateMotion' ? 'paced' : 'linear'), type: el.getAttribute('type') || undefined, ...(el.getAttribute('rotate') ? { rotate: el.getAttribute('rotate') } : {}), ...(el.getAttribute('keySplines') ? { keySplines: el.getAttribute('keySplines') } : {}) });
348
+ });
349
+ return out;
350
+ }
351
+ /** One SMIL animation replayed as a runtime Playable. */
352
+ class SmilTrack extends tween.Playable {
353
+ constructor(info) {
354
+ super({ repeat: info.repeat });
355
+ this.info = info;
356
+ this.morphs = [];
357
+ this.base = info.target.getAttribute(info.attribute);
358
+ this.interp = info.attribute === 'd' ? (a, b, p) => this.morph(a, b)(p) : info.kind === 'animateTransform' ? lerpNumbers : lerpAny;
359
+ this.splines = (info.keySplines || '').split(';').filter((s) => s.trim()).map((s) => { const n = numList(s); return tween.cubicBezier(n[0], n[1], n[2], n[3]); });
360
+ }
361
+ morph(a, b) {
362
+ const key = a + '|' + b;
363
+ const hit = this.morphs[key];
364
+ return hit || (this.morphs[key] = morphPath(a, b));
365
+ }
366
+ get duration() {
367
+ return this.info.dur;
368
+ }
369
+ write(v) {
370
+ const { kind, target, type } = this.info;
371
+ if (kind === 'animateTransform')
372
+ target.setAttribute('transform', `${type || 'translate'}(${v})`);
373
+ else
374
+ target.setAttribute(this.info.attribute, v);
375
+ }
376
+ renderLocal(ms, ended) {
377
+ const i = this.info;
378
+ if (ended && ms >= i.dur && !i.freeze && this.repeat >= 0) {
379
+ if (this.base === null)
380
+ i.target.removeAttribute(i.attribute);
381
+ else
382
+ i.target.setAttribute(i.attribute, this.base);
383
+ return;
384
+ }
385
+ const p = i.dur ? Math.min(1, ms / i.dur) : 1;
386
+ if (i.kind === 'set')
387
+ return this.write(i.values[0]);
388
+ if (i.kind === 'animateMotion') {
389
+ const d = i.values[0];
390
+ const len = pathLength(d);
391
+ const pt = pointAtLength(d, len * p);
392
+ const rot = i.rotate;
393
+ const a = rot === 'auto' ? pt.angle : rot === 'auto-reverse' ? pt.angle + 180 : parseFloat(rot) || 0;
394
+ i.target.setAttribute('transform', `translate(${r3(pt.x)} ${r3(pt.y)})${a ? ` rotate(${r3(a)})` : ''}`);
395
+ return;
396
+ }
397
+ const vals = i.values;
398
+ if (vals.length === 1)
399
+ return this.write(vals[0]);
400
+ const kt = i.keyTimes.length === vals.length ? i.keyTimes : vals.map((_, k) => k / (vals.length - 1));
401
+ if (i.calcMode === 'discrete') {
402
+ const kd = i.keyTimes.length === vals.length ? i.keyTimes : vals.map((_, k) => k / vals.length);
403
+ let k = 0;
404
+ while (k < kd.length - 1 && p >= kd[k + 1])
405
+ k++;
406
+ return this.write(vals[k]);
407
+ }
408
+ let k = 0;
409
+ while (k < kt.length - 2 && p > kt[k + 1])
410
+ k++;
411
+ const span = kt[k + 1] - kt[k] || 1;
412
+ let local = Math.min(1, Math.max(0, (p - kt[k]) / span));
413
+ if (i.calcMode === 'spline' && this.splines[k])
414
+ local = this.splines[k](local);
415
+ this.write(this.interp(vals[k], vals[k + 1], local));
416
+ }
417
+ }
418
+ /**
419
+ * Replay an SVG's SMIL animations with the runtime. The SMIL elements are
420
+ * detached while the runtime drives the attributes (call `restore()` to put
421
+ * them back). Playing unless `paused: true`.
422
+ */
423
+ function playSmil(svg, o = {}) {
424
+ const animations = readSmil(svg);
425
+ const els = Array.from(svg.querySelectorAll('animate, set, animateTransform, animateMotion'));
426
+ const parents = els.map((e) => [e, e.parentNode, e.nextSibling]);
427
+ els.forEach((e) => e.remove());
428
+ const tl = new tween.Timeline({});
429
+ for (const a of animations)
430
+ tl.add(new SmilTrack(a), a.begin);
431
+ if (o.timeScale)
432
+ tl.timeScale = o.timeScale;
433
+ if (!o.paused)
434
+ tl.play();
435
+ return {
436
+ timeline: tl,
437
+ animations,
438
+ restore() {
439
+ tl.kill();
440
+ parents.forEach(([e, p, next]) => p?.insertBefore(e, next && next.parentNode === p ? next : null));
441
+ },
442
+ };
443
+ }
444
+ /** The module object for `use(formatSvg)`. */
445
+ const formatSvg = { id: 'format-svg', version: registry.RUNTIME_VERSION, requires: ['core'], api: { parsePath, flattenPath, pathLength, pointAtLength, samplePath, morphPath, readSmil, playSmil, smilTime } };
446
+
447
+ exports.flattenPath = flattenPath;
448
+ exports.formatSvg = formatSvg;
449
+ exports.morphPath = morphPath;
450
+ exports.parsePath = parsePath;
451
+ exports.pathLength = pathLength;
452
+ exports.playSmil = playSmil;
453
+ exports.pointAtLength = pointAtLength;
454
+ exports.readSmil = readSmil;
455
+ exports.samplePath = samplePath;
456
+ exports.smilTime = smilTime;
457
+ //# sourceMappingURL=format-svg.cjs.map