motionary 10.0.0 → 10.1.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 (63) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +45 -0
  3. package/bin/create-motionary-plugin.mjs +124 -0
  4. package/dist/chunks/keyframes-CyH_abhI.js +183 -0
  5. package/dist/chunks/keyframes-CyH_abhI.js.map +1 -0
  6. package/dist/chunks/keyframes-cUdsXSXQ.cjs +187 -0
  7. package/dist/chunks/keyframes-cUdsXSXQ.cjs.map +1 -0
  8. package/dist/chunks/registry-C0xLNq3-.cjs +81 -0
  9. package/dist/chunks/registry-C0xLNq3-.cjs.map +1 -0
  10. package/dist/chunks/registry-jF8VIA_9.js +69 -0
  11. package/dist/chunks/registry-jF8VIA_9.js.map +1 -0
  12. package/dist/chunks/tween-DDObu9iA.js +542 -0
  13. package/dist/chunks/tween-DDObu9iA.js.map +1 -0
  14. package/dist/chunks/tween-JEthWrjo.cjs +554 -0
  15. package/dist/chunks/tween-JEthWrjo.cjs.map +1 -0
  16. package/dist/components/marketplace.cjs +104 -0
  17. package/dist/components/marketplace.cjs.map +1 -1
  18. package/dist/components/marketplace.d.cts +33 -2
  19. package/dist/components/marketplace.d.ts +33 -2
  20. package/dist/components/marketplace.js +101 -1
  21. package/dist/components/marketplace.js.map +1 -1
  22. package/dist/components/widgets.cjs +420 -199
  23. package/dist/components/widgets.cjs.map +1 -1
  24. package/dist/components/widgets.d.cts +42 -2
  25. package/dist/components/widgets.d.ts +42 -2
  26. package/dist/components/widgets.js +420 -201
  27. package/dist/components/widgets.js.map +1 -1
  28. package/dist/llms-full.txt +3018 -0
  29. package/dist/llms.txt +207 -0
  30. package/dist/manifest.json +7562 -0
  31. package/dist/manifest.schema.json +85 -0
  32. package/dist/runtime/format-css.cjs +184 -0
  33. package/dist/runtime/format-css.cjs.map +1 -0
  34. package/dist/runtime/format-css.d.cts +174 -0
  35. package/dist/runtime/format-css.d.ts +174 -0
  36. package/dist/runtime/format-css.iife.js +2 -0
  37. package/dist/runtime/format-css.iife.js.map +1 -0
  38. package/dist/runtime/format-css.js +176 -0
  39. package/dist/runtime/format-css.js.map +1 -0
  40. package/dist/runtime/format-motion.cjs +138 -0
  41. package/dist/runtime/format-motion.cjs.map +1 -0
  42. package/dist/runtime/format-motion.d.cts +208 -0
  43. package/dist/runtime/format-motion.d.ts +208 -0
  44. package/dist/runtime/format-motion.iife.js +2 -0
  45. package/dist/runtime/format-motion.iife.js.map +1 -0
  46. package/dist/runtime/format-motion.js +132 -0
  47. package/dist/runtime/format-motion.js.map +1 -0
  48. package/dist/runtime.cjs +78 -0
  49. package/dist/runtime.cjs.map +1 -0
  50. package/dist/runtime.d.cts +236 -0
  51. package/dist/runtime.d.ts +236 -0
  52. package/dist/runtime.iife.js +2 -0
  53. package/dist/runtime.iife.js.map +1 -0
  54. package/dist/runtime.js +54 -0
  55. package/dist/runtime.js.map +1 -0
  56. package/dist/widgets.umd.js +1 -1
  57. package/dist/widgets.umd.js.map +1 -1
  58. package/docs/ROADMAP.md +69 -38
  59. package/docs/components.md +55 -0
  60. package/docs/runtime/core.md +55 -0
  61. package/docs/runtime/format-css.md +59 -0
  62. package/docs/runtime/format-motion.md +56 -0
  63. package/package.json +48 -6
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-css.iife.js","sources":["../../src/runtime/keyframes.ts","../../src/runtime/format-css.ts","../../src/runtime/iife/format-css.ts"],"sourcesContent":["/**\n * Normalised keyframes shared by the format loaders: a list of frames with\n * offsets in [0, 1], camelCase props and an optional per-segment easing,\n * played as a runtime `Timeline` (one tween per segment).\n */\nimport { Timeline, Tween, parseValue, type Target, type PlayOptions } from './tween';\nimport { parseEase, type Ease } from './ease';\n\nexport interface Frame {\n offset: number;\n props: Record<string, string | number>;\n /** Easing from this frame to the next. */\n easing?: string;\n}\n\nexport interface KeyframesPlayOptions extends PlayOptions {\n /** ms (default 1000). */\n duration?: number;\n /** Default easing for segments without their own (default 'linear', as in CSS / WAAPI keyframes). */\n ease?: string | Ease;\n}\n\nexport const camelProp = (k: string): string => (k.startsWith('--') ? k : k.trim().replace(/-([a-z])/g, (_, c: string) => c.toUpperCase()));\n\n/** Fill in missing offsets (spaced evenly between known ones, first 0 / last 1), as the WAAPI does. */\nexport function distributeOffsets<T extends { offset?: number | null }>(frames: T[]): (T & { offset: number })[] {\n const out = frames.map((f) => ({ ...f })) as (T & { offset: number })[];\n if (!out.length) return out;\n if (out[0].offset == null) out[0].offset = out.length === 1 ? 1 : 0;\n if (out[out.length - 1].offset == null) out[out.length - 1].offset = 1;\n let i = 0;\n while (i < out.length) {\n if (out[i].offset != null) { i++; continue; }\n const a = i - 1;\n let b = i;\n while (out[b].offset == null) b++;\n const from = out[a].offset, to = out[b].offset;\n for (let k = i; k < b; k++) out[k].offset = from + ((to - from) * (k - a)) / (b - a);\n i = b;\n }\n return out;\n}\n\n/** CSS transform functions → runtime transform shorthands (translate/rotate/scale/skew); null when not representable (matrix, 3D, …). */\nexport function transformToProps(t: string): Record<string, string | number> | null {\n if (!t || t === 'none') return { x: 0, y: 0, rotate: 0, scale: 1 };\n const out: Record<string, string | number> = {};\n const re = /([a-zA-Z][a-zA-Z0-9]*)\\(([^)]*)\\)/g;\n let m: RegExpExecArray | null;\n let rest = t;\n while ((m = re.exec(t))) {\n rest = rest.replace(m[0], '');\n const args = m[2].split(/[\\s,]+/).filter(Boolean);\n switch (m[1]) {\n case 'translate': out.x = args[0]; out.y = args[1] ?? 0; break;\n case 'translateX': out.x = args[0]; break;\n case 'translateY': out.y = args[0]; break;\n case 'translate3d': if (parseFloat(args[2] || '0') !== 0) return null; out.x = args[0]; out.y = args[1] ?? 0; break;\n case 'scale3d': if (parseFloat(args[2] ?? '1') !== 1) return null; if (args[1] !== undefined && args[1] !== args[0]) { out.scaleX = +args[0]; out.scaleY = +args[1]; } else out.scale = +args[0]; break;\n case 'rotate': case 'rotateZ': out.rotate = args[0]; break;\n case 'scale': if (args[1] !== undefined && args[1] !== args[0]) { out.scaleX = +args[0]; out.scaleY = +args[1]; } else out.scale = +args[0]; break;\n case 'scaleX': out.scaleX = +args[0]; break;\n case 'scaleY': out.scaleY = +args[0]; break;\n case 'skewX': out.skewX = args[0]; break;\n case 'skewY': out.skewY = args[0]; break;\n default: return null;\n }\n }\n return rest.trim() ? null : out;\n}\n\n/** Expand `transform` into shorthands where possible (kept as a discrete prop otherwise). */\nexport function expandProps(props: Record<string, string | number>): Record<string, string | number> {\n const out: Record<string, string | number> = {};\n for (const [k, v] of Object.entries(props)) {\n if (k === 'transform' && typeof v === 'string') {\n const t = transformToProps(v);\n if (t) { Object.assign(out, t); continue; }\n }\n out[k] = v;\n }\n return out;\n}\n\nconst tweenable = (v: string | number): boolean => {\n try { parseValue(v); return true; } catch { return false; }\n};\n\n/**\n * Play frames on a target as a `Timeline` (paused unless `paused: false`).\n * Props missing from a frame hold their previous value; non-numeric values\n * (e.g. `display`, `matrix(...)`) switch discretely at the segment midpoint.\n */\nexport function framesToTimeline(target: Target, frames: Frame[], o: KeyframesPlayOptions = {}): Timeline {\n const dur = o.duration ?? 1000;\n const fs = [...frames].sort((a, b) => a.offset - b.offset).map((f) => ({ ...f, props: expandProps(f.props) }));\n const tl = new Timeline({ repeat: o.repeat, yoyo: o.yoyo, delay: o.delay, onUpdate: o.onUpdate, onComplete: o.onComplete });\n const keys = Array.from(new Set(fs.flatMap((f) => Object.keys(f.props))));\n // carry values forward / backward so every frame has every key\n const filled = fs.map((f) => ({ ...f, props: { ...f.props } }));\n for (const k of keys) {\n let last: string | number | undefined;\n for (const f of filled) { if (k in f.props) last = f.props[k]; else if (last !== undefined) f.props[k] = last; }\n let next: string | number | undefined;\n for (let i = filled.length - 1; i >= 0; i--) { if (k in filled[i].props) next = filled[i].props[k]; else if (next !== undefined) filled[i].props[k] = next; }\n }\n const def = o.ease ?? 'linear';\n if (filled.length === 1) filled.unshift({ ...filled[0], offset: 0 });\n for (let i = 0; i < filled.length - 1; i++) {\n const a = filled[i], b = filled[i + 1];\n const segDur = Math.max(0, (b.offset - a.offset) * dur);\n const from: Record<string, string | number> = {}, to: Record<string, string | number> = {};\n const discrete: [string, string | number][] = [];\n for (const k of keys) {\n if (tweenable(a.props[k]) && tweenable(b.props[k])) { from[k] = a.props[k]; to[k] = b.props[k]; }\n else discrete.push([k, b.props[k]]);\n }\n tl.add(new Tween(target, { from, to, duration: segDur, ease: a.easing ? parseEase(a.easing) : def, paused: true }), a.offset * dur);\n for (const [k, v] of discrete) tl.call(() => { if ((target as any).style) (target as HTMLElement).style.setProperty(k.replace(/[A-Z]/g, (c) => '-' + c.toLowerCase()), String(v)); else (target as any)[k] = v; }, a.offset * dur + segDur / 2);\n }\n if (o.paused === false) tl.play();\n return tl;\n}\n","/**\n * `motionary/runtime/format-css` (10.1) — import CSS `@keyframes` and Web\n * Animations API keyframes into the runtime timeline.\n *\n * - `parseKeyframes(cssText)` — every `@keyframes` block of a stylesheet\n * (incl. `-webkit-`), percentages / `from` / `to` / lists (`0%, 100%`),\n * per-frame `animation-timing-function`, `!important` ignored as in CSS.\n * - `fromCssRule(rule)` — a live `CSSKeyframesRule`.\n * - `fromWaapi(keyframes)` — array form (`[{ opacity: 0 }, { opacity: 1, offset: .8 }]`)\n * and property-indexed form (`{ opacity: [0, 1], easing: 'ease-out' }`), with\n * offsets distributed like the WAAPI.\n * - `playKeyframes(target, frames, { duration, … })` — a runtime `Timeline`.\n *\n * Unsupported (documented in docs/runtime/format-css.md): `composite: add / accumulate`,\n * `@property` typed interpolation, 3D / matrix transforms (switch discretely).\n */\nimport { RUNTIME_VERSION, type RuntimeModule } from './registry';\nimport { camelProp, distributeOffsets, framesToTimeline, type Frame, type KeyframesPlayOptions } from './keyframes';\nimport type { Target } from './tween';\n\nexport type { Frame, KeyframesPlayOptions } from './keyframes';\n\nexport interface KeyframesDef {\n name: string;\n frames: Frame[];\n}\n\n/** Strip comments. */\nconst clean = (css: string) => css.replace(/\\/\\*[\\s\\S]*?\\*\\//g, '');\n\nfunction block(css: string, open: number): [string, number] {\n let depth = 0;\n for (let i = open; i < css.length; i++) {\n if (css[i] === '{') depth++;\n else if (css[i] === '}' && --depth === 0) return [css.slice(open + 1, i), i + 1];\n }\n throw new Error('[motionary] format-css: unbalanced braces in @keyframes');\n}\n\nfunction decls(body: string): { props: Record<string, string>; easing?: string } {\n const props: Record<string, string> = {};\n let easing: string | undefined;\n // split on ';' outside parentheses\n let depth = 0, cur = '';\n const parts: string[] = [];\n for (const ch of body) {\n if (ch === '(') depth++;\n if (ch === ')') depth--;\n if (ch === ';' && !depth) { parts.push(cur); cur = ''; } else cur += ch;\n }\n parts.push(cur);\n for (const p of parts) {\n const i = p.indexOf(':');\n if (i < 0) continue;\n const k = p.slice(0, i).trim();\n const v = p.slice(i + 1).replace(/!important/i, '').trim();\n if (!k || !v) continue;\n if (k === 'animation-timing-function' || k === '-webkit-animation-timing-function') easing = v;\n else props[camelProp(k)] = v;\n }\n return { props, easing };\n}\n\nconst offsetOf = (sel: string): number => {\n const s = sel.trim().toLowerCase();\n if (s === 'from') return 0;\n if (s === 'to') return 1;\n const n = parseFloat(s);\n if (!s.endsWith('%') || !Number.isFinite(n)) throw new Error(`[motionary] format-css: bad keyframe selector \"${sel}\"`);\n return n / 100;\n};\n\n/** Parse the body of one `@keyframes` block. */\nexport function parseKeyframesBody(body: string): Frame[] {\n const frames: Frame[] = [];\n let i = 0;\n while (i < body.length) {\n const open = body.indexOf('{', i);\n if (open < 0) break;\n const sel = body.slice(i, open);\n const [inner, end] = block(body, open);\n const d = decls(inner);\n for (const part of sel.split(',')) if (part.trim()) frames.push({ offset: offsetOf(part), props: { ...d.props }, ...(d.easing ? { easing: d.easing } : {}) });\n i = end;\n }\n // merge duplicate offsets (later declarations win, as in CSS)\n const by = new Map<number, Frame>();\n for (const f of frames.sort((a, b) => a.offset - b.offset)) {\n const prev = by.get(f.offset);\n by.set(f.offset, prev ? { offset: f.offset, props: { ...prev.props, ...f.props }, easing: f.easing ?? prev.easing } : f);\n }\n return Array.from(by.values());\n}\n\n/** Every `@keyframes` block in a stylesheet's text. */\nexport function parseKeyframes(cssText: string): KeyframesDef[] {\n const css = clean(cssText);\n const out: KeyframesDef[] = [];\n const re = /@(?:-webkit-|-moz-)?keyframes\\s+([\"']?)([\\w-]+)\\1\\s*\\{/g;\n let m: RegExpExecArray | null;\n while ((m = re.exec(css))) {\n const [body, end] = block(css, m.index + m[0].length - 1);\n out.push({ name: m[2], frames: parseKeyframesBody(body) });\n re.lastIndex = end;\n }\n return out;\n}\n\n/** A live `CSSKeyframesRule` (e.g. from `document.styleSheets`). */\nexport function fromCssRule(rule: { name: string; cssText: string }): KeyframesDef {\n const css = rule.cssText;\n const open = css.indexOf('{');\n return { name: rule.name, frames: parseKeyframesBody(block(css, open)[0]) };\n}\n\ntype WaapiFrame = Record<string, unknown> & { offset?: number | null; easing?: string };\n\n/** WAAPI keyframes (array or property-indexed form) → frames. */\nexport function fromWaapi(kf: WaapiFrame[] | Record<string, unknown>): Frame[] {\n let list: WaapiFrame[];\n if (Array.isArray(kf)) list = kf;\n else {\n const n = Math.max(...Object.entries(kf).filter(([k]) => k !== 'easing' && k !== 'offset' && k !== 'composite').map(([, v]) => (Array.isArray(v) ? v.length : 1)));\n list = Array.from({ length: n }, (_, i) => {\n const f: WaapiFrame = {};\n for (const [k, v] of Object.entries(kf)) {\n if (k === 'composite') continue;\n const arr = Array.isArray(v) ? v : [v];\n if (k === 'offset') { if (arr[i] !== undefined) f.offset = arr[i] as number; continue; }\n if (k === 'easing') { const e = arr[Math.min(i, arr.length - 1)]; if (e !== undefined) f.easing = e as string; continue; }\n if (arr.length === 1 && n > 1) { if (i === n - 1) f[k] = arr[0]; continue; }\n if (arr[i] !== undefined) f[k] = arr[i];\n }\n return f;\n });\n }\n return distributeOffsets(list).map((f) => {\n const props: Record<string, string | number> = {};\n for (const [k, v] of Object.entries(f)) if (k !== 'offset' && k !== 'easing' && k !== 'composite' && (typeof v === 'string' || typeof v === 'number')) props[camelProp(k === 'cssFloat' ? 'float' : k)] = v;\n return { offset: f.offset, props, ...(f.easing ? { easing: f.easing } : {}) };\n });\n}\n\n/** Frames in WAAPI array form (for `element.animate()`). */\nexport function toWaapi(frames: Frame[]): Keyframe[] {\n return frames.map((f) => ({ ...f.props, offset: f.offset, ...(f.easing ? { easing: f.easing } : {}) })) as Keyframe[];\n}\n\n/** Play frames (or a `KeyframesDef`) on a target. Returns the runtime timeline (playing unless `paused: true`). */\nexport function playKeyframes(target: Target, frames: Frame[] | KeyframesDef, o: KeyframesPlayOptions = {}) {\n return framesToTimeline(target, Array.isArray(frames) ? frames : frames.frames, { ...o, paused: o.paused ?? false });\n}\n\nexport interface FormatCssApi {\n parseKeyframes: typeof parseKeyframes;\n fromCssRule: typeof fromCssRule;\n fromWaapi: typeof fromWaapi;\n toWaapi: typeof toWaapi;\n playKeyframes: typeof playKeyframes;\n}\n\n/** The module object for `use(formatCss)`. */\nexport const formatCss: RuntimeModule<FormatCssApi> = { id: 'format-css', version: RUNTIME_VERSION, requires: ['core'], api: { parseKeyframes, fromCssRule, fromWaapi, toWaapi, playKeyframes } };\n","// CDN build: load runtime.iife.js first, then this file → registers motionary/runtime/format-css and adds its API to window.MotionaryRuntime.\nimport { register } from '../registry';\nimport { formatCss } from '../format-css';\nexport * from '../format-css';\nregister(formatCss);\n"],"names":["camelProp","k","startsWith","trim","replace","_","c","toUpperCase","transformToProps","t","x","y","rotate","scale","out","re","m","rest","exec","args","split","filter","Boolean","parseFloat","undefined","scaleX","scaleY","skewX","skewY","expandProps","props","v","Object","entries","assign","tweenable","parseValue","block","css","open","depth","i","length","slice","Error","decls","body","easing","cur","parts","ch","push","p","indexOf","offsetOf","sel","s","toLowerCase","n","endsWith","Number","isFinite","parseKeyframesBody","frames","inner","end","d","part","offset","by","Map","f","sort","a","b","prev","get","set","Array","from","values","parseKeyframes","cssText","clean","index","name","lastIndex","fromCssRule","rule","fromWaapi","kf","list","isArray","Math","max","map","arr","e","min","to","distributeOffsets","toWaapi","playKeyframes","target","o","dur","duration","fs","tl","Timeline","repeat","yoyo","delay","onUpdate","onComplete","keys","Set","flatMap","filled","last","next","def","ease","unshift","segDur","discrete","add","Tween","parseEase","paused","call","style","setProperty","String","play","framesToTimeline","formatCss","id","version","RUNTIME_VERSION","requires","api","register"],"mappings":"gCAsBO,MAAMA,EAAaC,GAAuBA,EAAEC,WAAW,MAAQD,EAAIA,EAAEE,OAAOC,QAAQ,YAAa,CAACC,EAAGC,IAAcA,EAAEC,eAsBtH,SAAUC,EAAiBC,GAC/B,IAAKA,GAAW,SAANA,EAAc,MAAO,CAAEC,EAAG,EAAGC,EAAG,EAAGC,OAAQ,EAAGC,MAAO,GAC/D,MAAMC,EAAuC,CAAA,EACvCC,EAAK,qCACX,IAAIC,EACAC,EAAOR,EACX,KAAQO,EAAID,EAAGG,KAAKT,IAAK,CACvBQ,EAAOA,EAAKb,QAAQY,EAAE,GAAI,IAC1B,MAAMG,EAAOH,EAAE,GAAGI,MAAM,UAAUC,OAAOC,SACzC,OAAQN,EAAE,IACR,IAAK,YAAaF,EAAIJ,EAAIS,EAAK,GAAIL,EAAIH,EAAIQ,EAAK,IAAM,EAAG,MACzD,IAAK,aAAcL,EAAIJ,EAAIS,EAAK,GAAI,MACpC,IAAK,aAAcL,EAAIH,EAAIQ,EAAK,GAAI,MACpC,IAAK,cAAe,GAAmC,IAA/BI,WAAWJ,EAAK,IAAM,KAAY,OAAO,KAAML,EAAIJ,EAAIS,EAAK,GAAIL,EAAIH,EAAIQ,EAAK,IAAM,EAAG,MAC9G,IAAK,UAAW,GAAmC,IAA/BI,WAAWJ,EAAK,IAAM,KAAY,OAAO,UAAsBK,IAAZL,EAAK,IAAoBA,EAAK,KAAOA,EAAK,IAAML,EAAIW,QAAUN,EAAK,GAAIL,EAAIY,QAAUP,EAAK,IAAWL,EAAID,OAASM,EAAK,GAAI,MAClM,IAAK,SAAU,IAAK,UAAWL,EAAIF,OAASO,EAAK,GAAI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,GAAM,IAAMA,EAAEmD,eAAgB4E,OAAOtG,IAAWwE,EAAetG,GAAK8B,GAAM0C,EAAEL,OAASqC,EAAMmB,EAAS,EAC/O,CAEA,OADiB,IAAbpB,EAAEyB,QAAkBrB,EAAG0B,OACpB1B,CACT,CC4BS2B,CAAiBhC,EAAQzB,MAAMc,QAAQ7B,GAAUA,EAASA,EAAOA,OAAQ,IAAKyC,EAAGyB,OAAQzB,EAAEyB,SAAU,GAC9G,CAWO,MAAMO,EAAyC,CAAEC,GAAI,aAAcC,QAASC,EAAAA,gBAAiBC,SAAU,CAAC,QAASC,IAAK,CAAE5D,iBAAgBM,cAAaE,YAAWY,UAASC,kBC9JhLwC,EAAAA,SAASN"}
@@ -0,0 +1,176 @@
1
+ import { R as RUNTIME_VERSION } from '../chunks/registry-jF8VIA_9.js';
2
+ import { f as framesToTimeline, d as distributeOffsets, c as camelProp } from '../chunks/keyframes-CyH_abhI.js';
3
+ import '../chunks/tween-DDObu9iA.js';
4
+
5
+ /**
6
+ * `motionary/runtime/format-css` (10.1) — import CSS `@keyframes` and Web
7
+ * Animations API keyframes into the runtime timeline.
8
+ *
9
+ * - `parseKeyframes(cssText)` — every `@keyframes` block of a stylesheet
10
+ * (incl. `-webkit-`), percentages / `from` / `to` / lists (`0%, 100%`),
11
+ * per-frame `animation-timing-function`, `!important` ignored as in CSS.
12
+ * - `fromCssRule(rule)` — a live `CSSKeyframesRule`.
13
+ * - `fromWaapi(keyframes)` — array form (`[{ opacity: 0 }, { opacity: 1, offset: .8 }]`)
14
+ * and property-indexed form (`{ opacity: [0, 1], easing: 'ease-out' }`), with
15
+ * offsets distributed like the WAAPI.
16
+ * - `playKeyframes(target, frames, { duration, … })` — a runtime `Timeline`.
17
+ *
18
+ * Unsupported (documented in docs/runtime/format-css.md): `composite: add / accumulate`,
19
+ * `@property` typed interpolation, 3D / matrix transforms (switch discretely).
20
+ */
21
+ /** Strip comments. */
22
+ const clean = (css) => css.replace(/\/\*[\s\S]*?\*\//g, '');
23
+ function block(css, open) {
24
+ let depth = 0;
25
+ for (let i = open; i < css.length; i++) {
26
+ if (css[i] === '{')
27
+ depth++;
28
+ else if (css[i] === '}' && --depth === 0)
29
+ return [css.slice(open + 1, i), i + 1];
30
+ }
31
+ throw new Error('[motionary] format-css: unbalanced braces in @keyframes');
32
+ }
33
+ function decls(body) {
34
+ const props = {};
35
+ let easing;
36
+ // split on ';' outside parentheses
37
+ let depth = 0, cur = '';
38
+ const parts = [];
39
+ for (const ch of body) {
40
+ if (ch === '(')
41
+ depth++;
42
+ if (ch === ')')
43
+ depth--;
44
+ if (ch === ';' && !depth) {
45
+ parts.push(cur);
46
+ cur = '';
47
+ }
48
+ else
49
+ cur += ch;
50
+ }
51
+ parts.push(cur);
52
+ for (const p of parts) {
53
+ const i = p.indexOf(':');
54
+ if (i < 0)
55
+ continue;
56
+ const k = p.slice(0, i).trim();
57
+ const v = p.slice(i + 1).replace(/!important/i, '').trim();
58
+ if (!k || !v)
59
+ continue;
60
+ if (k === 'animation-timing-function' || k === '-webkit-animation-timing-function')
61
+ easing = v;
62
+ else
63
+ props[camelProp(k)] = v;
64
+ }
65
+ return { props, easing };
66
+ }
67
+ const offsetOf = (sel) => {
68
+ const s = sel.trim().toLowerCase();
69
+ if (s === 'from')
70
+ return 0;
71
+ if (s === 'to')
72
+ return 1;
73
+ const n = parseFloat(s);
74
+ if (!s.endsWith('%') || !Number.isFinite(n))
75
+ throw new Error(`[motionary] format-css: bad keyframe selector "${sel}"`);
76
+ return n / 100;
77
+ };
78
+ /** Parse the body of one `@keyframes` block. */
79
+ function parseKeyframesBody(body) {
80
+ const frames = [];
81
+ let i = 0;
82
+ while (i < body.length) {
83
+ const open = body.indexOf('{', i);
84
+ if (open < 0)
85
+ break;
86
+ const sel = body.slice(i, open);
87
+ const [inner, end] = block(body, open);
88
+ const d = decls(inner);
89
+ for (const part of sel.split(','))
90
+ if (part.trim())
91
+ frames.push({ offset: offsetOf(part), props: { ...d.props }, ...(d.easing ? { easing: d.easing } : {}) });
92
+ i = end;
93
+ }
94
+ // merge duplicate offsets (later declarations win, as in CSS)
95
+ const by = new Map();
96
+ for (const f of frames.sort((a, b) => a.offset - b.offset)) {
97
+ const prev = by.get(f.offset);
98
+ by.set(f.offset, prev ? { offset: f.offset, props: { ...prev.props, ...f.props }, easing: f.easing ?? prev.easing } : f);
99
+ }
100
+ return Array.from(by.values());
101
+ }
102
+ /** Every `@keyframes` block in a stylesheet's text. */
103
+ function parseKeyframes(cssText) {
104
+ const css = clean(cssText);
105
+ const out = [];
106
+ const re = /@(?:-webkit-|-moz-)?keyframes\s+(["']?)([\w-]+)\1\s*\{/g;
107
+ let m;
108
+ while ((m = re.exec(css))) {
109
+ const [body, end] = block(css, m.index + m[0].length - 1);
110
+ out.push({ name: m[2], frames: parseKeyframesBody(body) });
111
+ re.lastIndex = end;
112
+ }
113
+ return out;
114
+ }
115
+ /** A live `CSSKeyframesRule` (e.g. from `document.styleSheets`). */
116
+ function fromCssRule(rule) {
117
+ const css = rule.cssText;
118
+ const open = css.indexOf('{');
119
+ return { name: rule.name, frames: parseKeyframesBody(block(css, open)[0]) };
120
+ }
121
+ /** WAAPI keyframes (array or property-indexed form) → frames. */
122
+ function fromWaapi(kf) {
123
+ let list;
124
+ if (Array.isArray(kf))
125
+ list = kf;
126
+ else {
127
+ const n = Math.max(...Object.entries(kf).filter(([k]) => k !== 'easing' && k !== 'offset' && k !== 'composite').map(([, v]) => (Array.isArray(v) ? v.length : 1)));
128
+ list = Array.from({ length: n }, (_, i) => {
129
+ const f = {};
130
+ for (const [k, v] of Object.entries(kf)) {
131
+ if (k === 'composite')
132
+ continue;
133
+ const arr = Array.isArray(v) ? v : [v];
134
+ if (k === 'offset') {
135
+ if (arr[i] !== undefined)
136
+ f.offset = arr[i];
137
+ continue;
138
+ }
139
+ if (k === 'easing') {
140
+ const e = arr[Math.min(i, arr.length - 1)];
141
+ if (e !== undefined)
142
+ f.easing = e;
143
+ continue;
144
+ }
145
+ if (arr.length === 1 && n > 1) {
146
+ if (i === n - 1)
147
+ f[k] = arr[0];
148
+ continue;
149
+ }
150
+ if (arr[i] !== undefined)
151
+ f[k] = arr[i];
152
+ }
153
+ return f;
154
+ });
155
+ }
156
+ return distributeOffsets(list).map((f) => {
157
+ const props = {};
158
+ for (const [k, v] of Object.entries(f))
159
+ if (k !== 'offset' && k !== 'easing' && k !== 'composite' && (typeof v === 'string' || typeof v === 'number'))
160
+ props[camelProp(k === 'cssFloat' ? 'float' : k)] = v;
161
+ return { offset: f.offset, props, ...(f.easing ? { easing: f.easing } : {}) };
162
+ });
163
+ }
164
+ /** Frames in WAAPI array form (for `element.animate()`). */
165
+ function toWaapi(frames) {
166
+ return frames.map((f) => ({ ...f.props, offset: f.offset, ...(f.easing ? { easing: f.easing } : {}) }));
167
+ }
168
+ /** Play frames (or a `KeyframesDef`) on a target. Returns the runtime timeline (playing unless `paused: true`). */
169
+ function playKeyframes(target, frames, o = {}) {
170
+ return framesToTimeline(target, Array.isArray(frames) ? frames : frames.frames, { ...o, paused: o.paused ?? false });
171
+ }
172
+ /** The module object for `use(formatCss)`. */
173
+ const formatCss = { id: 'format-css', version: RUNTIME_VERSION, requires: ['core'], api: { parseKeyframes, fromCssRule, fromWaapi, toWaapi, playKeyframes } };
174
+
175
+ export { formatCss, fromCssRule, fromWaapi, parseKeyframes, parseKeyframesBody, playKeyframes, toWaapi };
176
+ //# sourceMappingURL=format-css.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-css.js","sources":["../../src/runtime/format-css.ts"],"sourcesContent":["/**\n * `motionary/runtime/format-css` (10.1) — import CSS `@keyframes` and Web\n * Animations API keyframes into the runtime timeline.\n *\n * - `parseKeyframes(cssText)` — every `@keyframes` block of a stylesheet\n * (incl. `-webkit-`), percentages / `from` / `to` / lists (`0%, 100%`),\n * per-frame `animation-timing-function`, `!important` ignored as in CSS.\n * - `fromCssRule(rule)` — a live `CSSKeyframesRule`.\n * - `fromWaapi(keyframes)` — array form (`[{ opacity: 0 }, { opacity: 1, offset: .8 }]`)\n * and property-indexed form (`{ opacity: [0, 1], easing: 'ease-out' }`), with\n * offsets distributed like the WAAPI.\n * - `playKeyframes(target, frames, { duration, … })` — a runtime `Timeline`.\n *\n * Unsupported (documented in docs/runtime/format-css.md): `composite: add / accumulate`,\n * `@property` typed interpolation, 3D / matrix transforms (switch discretely).\n */\nimport { RUNTIME_VERSION, type RuntimeModule } from './registry';\nimport { camelProp, distributeOffsets, framesToTimeline, type Frame, type KeyframesPlayOptions } from './keyframes';\nimport type { Target } from './tween';\n\nexport type { Frame, KeyframesPlayOptions } from './keyframes';\n\nexport interface KeyframesDef {\n name: string;\n frames: Frame[];\n}\n\n/** Strip comments. */\nconst clean = (css: string) => css.replace(/\\/\\*[\\s\\S]*?\\*\\//g, '');\n\nfunction block(css: string, open: number): [string, number] {\n let depth = 0;\n for (let i = open; i < css.length; i++) {\n if (css[i] === '{') depth++;\n else if (css[i] === '}' && --depth === 0) return [css.slice(open + 1, i), i + 1];\n }\n throw new Error('[motionary] format-css: unbalanced braces in @keyframes');\n}\n\nfunction decls(body: string): { props: Record<string, string>; easing?: string } {\n const props: Record<string, string> = {};\n let easing: string | undefined;\n // split on ';' outside parentheses\n let depth = 0, cur = '';\n const parts: string[] = [];\n for (const ch of body) {\n if (ch === '(') depth++;\n if (ch === ')') depth--;\n if (ch === ';' && !depth) { parts.push(cur); cur = ''; } else cur += ch;\n }\n parts.push(cur);\n for (const p of parts) {\n const i = p.indexOf(':');\n if (i < 0) continue;\n const k = p.slice(0, i).trim();\n const v = p.slice(i + 1).replace(/!important/i, '').trim();\n if (!k || !v) continue;\n if (k === 'animation-timing-function' || k === '-webkit-animation-timing-function') easing = v;\n else props[camelProp(k)] = v;\n }\n return { props, easing };\n}\n\nconst offsetOf = (sel: string): number => {\n const s = sel.trim().toLowerCase();\n if (s === 'from') return 0;\n if (s === 'to') return 1;\n const n = parseFloat(s);\n if (!s.endsWith('%') || !Number.isFinite(n)) throw new Error(`[motionary] format-css: bad keyframe selector \"${sel}\"`);\n return n / 100;\n};\n\n/** Parse the body of one `@keyframes` block. */\nexport function parseKeyframesBody(body: string): Frame[] {\n const frames: Frame[] = [];\n let i = 0;\n while (i < body.length) {\n const open = body.indexOf('{', i);\n if (open < 0) break;\n const sel = body.slice(i, open);\n const [inner, end] = block(body, open);\n const d = decls(inner);\n for (const part of sel.split(',')) if (part.trim()) frames.push({ offset: offsetOf(part), props: { ...d.props }, ...(d.easing ? { easing: d.easing } : {}) });\n i = end;\n }\n // merge duplicate offsets (later declarations win, as in CSS)\n const by = new Map<number, Frame>();\n for (const f of frames.sort((a, b) => a.offset - b.offset)) {\n const prev = by.get(f.offset);\n by.set(f.offset, prev ? { offset: f.offset, props: { ...prev.props, ...f.props }, easing: f.easing ?? prev.easing } : f);\n }\n return Array.from(by.values());\n}\n\n/** Every `@keyframes` block in a stylesheet's text. */\nexport function parseKeyframes(cssText: string): KeyframesDef[] {\n const css = clean(cssText);\n const out: KeyframesDef[] = [];\n const re = /@(?:-webkit-|-moz-)?keyframes\\s+([\"']?)([\\w-]+)\\1\\s*\\{/g;\n let m: RegExpExecArray | null;\n while ((m = re.exec(css))) {\n const [body, end] = block(css, m.index + m[0].length - 1);\n out.push({ name: m[2], frames: parseKeyframesBody(body) });\n re.lastIndex = end;\n }\n return out;\n}\n\n/** A live `CSSKeyframesRule` (e.g. from `document.styleSheets`). */\nexport function fromCssRule(rule: { name: string; cssText: string }): KeyframesDef {\n const css = rule.cssText;\n const open = css.indexOf('{');\n return { name: rule.name, frames: parseKeyframesBody(block(css, open)[0]) };\n}\n\ntype WaapiFrame = Record<string, unknown> & { offset?: number | null; easing?: string };\n\n/** WAAPI keyframes (array or property-indexed form) → frames. */\nexport function fromWaapi(kf: WaapiFrame[] | Record<string, unknown>): Frame[] {\n let list: WaapiFrame[];\n if (Array.isArray(kf)) list = kf;\n else {\n const n = Math.max(...Object.entries(kf).filter(([k]) => k !== 'easing' && k !== 'offset' && k !== 'composite').map(([, v]) => (Array.isArray(v) ? v.length : 1)));\n list = Array.from({ length: n }, (_, i) => {\n const f: WaapiFrame = {};\n for (const [k, v] of Object.entries(kf)) {\n if (k === 'composite') continue;\n const arr = Array.isArray(v) ? v : [v];\n if (k === 'offset') { if (arr[i] !== undefined) f.offset = arr[i] as number; continue; }\n if (k === 'easing') { const e = arr[Math.min(i, arr.length - 1)]; if (e !== undefined) f.easing = e as string; continue; }\n if (arr.length === 1 && n > 1) { if (i === n - 1) f[k] = arr[0]; continue; }\n if (arr[i] !== undefined) f[k] = arr[i];\n }\n return f;\n });\n }\n return distributeOffsets(list).map((f) => {\n const props: Record<string, string | number> = {};\n for (const [k, v] of Object.entries(f)) if (k !== 'offset' && k !== 'easing' && k !== 'composite' && (typeof v === 'string' || typeof v === 'number')) props[camelProp(k === 'cssFloat' ? 'float' : k)] = v;\n return { offset: f.offset, props, ...(f.easing ? { easing: f.easing } : {}) };\n });\n}\n\n/** Frames in WAAPI array form (for `element.animate()`). */\nexport function toWaapi(frames: Frame[]): Keyframe[] {\n return frames.map((f) => ({ ...f.props, offset: f.offset, ...(f.easing ? { easing: f.easing } : {}) })) as Keyframe[];\n}\n\n/** Play frames (or a `KeyframesDef`) on a target. Returns the runtime timeline (playing unless `paused: true`). */\nexport function playKeyframes(target: Target, frames: Frame[] | KeyframesDef, o: KeyframesPlayOptions = {}) {\n return framesToTimeline(target, Array.isArray(frames) ? frames : frames.frames, { ...o, paused: o.paused ?? false });\n}\n\nexport interface FormatCssApi {\n parseKeyframes: typeof parseKeyframes;\n fromCssRule: typeof fromCssRule;\n fromWaapi: typeof fromWaapi;\n toWaapi: typeof toWaapi;\n playKeyframes: typeof playKeyframes;\n}\n\n/** The module object for `use(formatCss)`. */\nexport const formatCss: RuntimeModule<FormatCssApi> = { id: 'format-css', version: RUNTIME_VERSION, requires: ['core'], api: { parseKeyframes, fromCssRule, fromWaapi, toWaapi, playKeyframes } };\n"],"names":[],"mappings":";;;;AAAA;;;;;;;;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EAAE,MAA8B,EAAE,IAA0B,EAAE,EAAA;AACxG,IAAA,OAAO,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,IAAI,KAAK,EAAE,CAAC;AACtH;AAUA;AACO,MAAM,SAAS,GAAgC,EAAE,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,EAAE;;;;"}
@@ -0,0 +1,138 @@
1
+ 'use strict';
2
+
3
+ var registry = require('../chunks/registry-C0xLNq3-.cjs');
4
+ var tween = require('../chunks/tween-JEthWrjo.cjs');
5
+ var keyframes = require('../chunks/keyframes-cUdsXSXQ.cjs');
6
+
7
+ /**
8
+ * `motionary/runtime/format-motion` (10.1) — play Motion / Framer-style
9
+ * keyframe JSON with the runtime:
10
+ *
11
+ * ```json
12
+ * { "initial": { "opacity": 0, "y": 40 },
13
+ * "animate": { "opacity": 1, "y": [40, -8, 0], "rotate": 0 },
14
+ * "transition": { "duration": 0.6, "ease": "easeOut", "times": [0, 0.7, 1], "delay": 0.1,
15
+ * "repeat": 1, "repeatType": "reverse", "opacity": { "duration": 0.3 } } }
16
+ * ```
17
+ *
18
+ * Supported: `initial` / `animate` (numbers, unit strings, colours, arrays as
19
+ * keyframes), the transform shorthands `x y scale scaleX scaleY rotate skewX skewY`,
20
+ * transition `duration` / `delay` (seconds) / `ease` (names or `[x1, y1, x2, y2]`) /
21
+ * `times` / `repeat` (`Infinity` ok) / `repeatType` (`loop`, `reverse`, `mirror`),
22
+ * per-property transitions, and `type: "spring"` (`stiffness`, `damping`, `mass`,
23
+ * or `bounce` + `duration`) simulated into an easing curve.
24
+ * Not supported: `layout`, gestures (`whileHover` …), variants propagation,
25
+ * `staggerChildren` (use the runtime timeline `stagger`).
26
+ */
27
+ const NAMES = { 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' };
28
+ /** A Motion ease → runtime ease. */
29
+ function motionEase(e) {
30
+ if (Array.isArray(e))
31
+ return tween.cubicBezier(e[0], e[1], e[2], e[3]);
32
+ if (!e)
33
+ return tween.EASES['cubic-out'];
34
+ const n = NAMES[e] || e;
35
+ if (!tween.EASES[n])
36
+ throw new Error(`[motionary] format-motion: unknown ease "${e}"`);
37
+ return tween.EASES[n];
38
+ }
39
+ /** Simulate a damped spring (unit step) → [ease, duration ms]. */
40
+ function springEase(o) {
41
+ let k = o.stiffness ?? 100, c = o.damping ?? 10;
42
+ const m = o.mass ?? 1;
43
+ if (o.bounce !== undefined && o.duration !== undefined) {
44
+ // map bounce + duration to stiffness / damping (critical damping at bounce 0)
45
+ const zeta = 1 - Math.min(0.95, Math.max(0, o.bounce));
46
+ const w = (2 * Math.PI) / Math.max(0.05, o.duration);
47
+ k = m * w * w;
48
+ c = 2 * zeta * Math.sqrt(k * m);
49
+ }
50
+ const dt = 1 / 120;
51
+ const samples = [0];
52
+ let x = 0, v = 0, t = 0, still = 0;
53
+ while (t < 10) {
54
+ const a = (-k * (x - 1) - c * v) / m;
55
+ v += a * dt;
56
+ x += v * dt;
57
+ t += dt;
58
+ samples.push(x);
59
+ if (Math.abs(x - 1) < 0.001 && Math.abs(v) < 0.01) {
60
+ if (++still > 12)
61
+ break;
62
+ }
63
+ else
64
+ still = 0;
65
+ }
66
+ const n = samples.length - 1;
67
+ samples[n] = 1;
68
+ const ease = (p) => {
69
+ if (p <= 0)
70
+ return 0;
71
+ if (p >= 1)
72
+ return 1;
73
+ const f = p * n, i = Math.floor(f);
74
+ return samples[i] + (samples[i + 1] - samples[i]) * (f - i);
75
+ };
76
+ return [ease, Math.round(t * 1000)];
77
+ }
78
+ /** Motion def → one keyframe track per transition group (`[frames, transition]`). */
79
+ function fromMotion(def) {
80
+ const base = def.transition || {};
81
+ const groups = new Map();
82
+ for (const k of Object.keys(def.animate)) {
83
+ const own = base[k] && typeof base[k] === 'object' ? k : '';
84
+ groups.set(own, [...(groups.get(own) || []), k]);
85
+ }
86
+ return Array.from(groups.entries()).map(([g, props]) => {
87
+ const tr = g ? { ...base, ...base[g] } : base;
88
+ const len = Math.max(...props.map((p) => (Array.isArray(def.animate[p]) ? def.animate[p].length : 1)));
89
+ const n = Math.max(2, len);
90
+ const times = tr.times && tr.times.length === n ? tr.times : Array.from({ length: n }, (_, i) => i / (n - 1));
91
+ const frames = times.map((offset) => ({ offset, props: {} }));
92
+ for (const p of props) {
93
+ const v = def.animate[p];
94
+ const arr = Array.isArray(v) ? v : [def.initial && p in def.initial ? def.initial[p] : undefined, v];
95
+ const list = arr.length === n ? arr : [...Array(n - arr.length).fill(arr[0]), ...arr];
96
+ list.forEach((x, i) => { if (x !== undefined && x !== null)
97
+ frames[i].props[p] = x; });
98
+ }
99
+ if (Array.isArray(tr.ease) && tr.ease.length && (Array.isArray(tr.ease[0]) || typeof tr.ease[0] === 'string')) {
100
+ tr.ease.forEach((e, i) => { if (frames[i])
101
+ frames[i].easing = Array.isArray(e) ? `cubic-bezier(${e.join(',')})` : NAMES[e] || e; });
102
+ }
103
+ return { frames, transition: tr, props };
104
+ });
105
+ }
106
+ /**
107
+ * Apply `initial` immediately and play `animate` with the transition.
108
+ * Returns a runtime `Timeline` (one child per transition group), playing unless `paused`.
109
+ */
110
+ function playMotion(target, def, o = {}) {
111
+ const tl = new tween.Timeline({});
112
+ if (def.initial)
113
+ for (const [k, v] of Object.entries(def.initial))
114
+ keyframes.framesToTimeline(target, [{ offset: 0, props: { [k]: v } }], { duration: 0 }).seek(0);
115
+ for (const { frames, transition: tr } of fromMotion(def)) {
116
+ let ease;
117
+ let dur = (tr.duration ?? 0.3) * 1000;
118
+ if (tr.type === 'spring')
119
+ [ease, dur] = springEase({ ...tr, duration: tr.duration });
120
+ else if (!Array.isArray(tr.ease) || typeof tr.ease[0] === 'number')
121
+ ease = motionEase(tr.ease);
122
+ const rep = tr.repeat === Infinity ? -1 : tr.repeat || 0;
123
+ const child = keyframes.framesToTimeline(target, frames, { duration: dur, ease, repeat: rep, yoyo: rep !== 0 && tr.repeatType !== 'loop' && !!tr.repeatType });
124
+ tl.add(child, (tr.delay || 0) * 1000);
125
+ }
126
+ if (!o.paused)
127
+ tl.play();
128
+ return tl;
129
+ }
130
+ /** The module object for `use(formatMotion)`. */
131
+ const formatMotion = { id: 'format-motion', version: registry.RUNTIME_VERSION, requires: ['core'], api: { fromMotion, playMotion, springEase, motionEase } };
132
+
133
+ exports.formatMotion = formatMotion;
134
+ exports.fromMotion = fromMotion;
135
+ exports.motionEase = motionEase;
136
+ exports.playMotion = playMotion;
137
+ exports.springEase = springEase;
138
+ //# sourceMappingURL=format-motion.cjs.map
@@ -0,0 +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,UAA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CAAC,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE;;;;;;;;"}
@@ -0,0 +1,208 @@
1
+ /** A runtime module: `{ id, version, api }`, registered with `use()`. */
2
+ interface RuntimeModule<A = unknown> {
3
+ /** Module id: 'core', 'format-css', 'scroll', … (import path `motionary/runtime/<id>`). */
4
+ id: string;
5
+ version: string;
6
+ /** Other modules this one needs (registered first by `use()` callers). */
7
+ requires?: string[];
8
+ /** The module's public API (what `requireModule(id)` returns). */
9
+ api: A;
10
+ /** Optional one-time setup, called on first registration. */
11
+ setup?(registry: RuntimeRegistry): void;
12
+ }
13
+ interface RuntimeRegistry {
14
+ version: string;
15
+ modules: Map<string, RuntimeModule>;
16
+ /** Shared per-page state slots (the ticker lives here). */
17
+ slots: Record<string, unknown>;
18
+ }
19
+
20
+ /** Easing functions (t ∈ [0, 1] → progress). Original implementations of the standard Penner-style curves. */
21
+ type Ease = (t: number) => number;
22
+
23
+ type Target = object | Element;
24
+ type Props = Record<string, number | string>;
25
+ interface PlayOptions {
26
+ /** Delay before the first iteration, ms. */
27
+ delay?: number;
28
+ /** Extra iterations (-1 = forever). */
29
+ repeat?: number;
30
+ /** Alternate direction on every other iteration. */
31
+ yoyo?: boolean;
32
+ /** Start paused (`play()` to start). */
33
+ paused?: boolean;
34
+ onUpdate?: (progress: number) => void;
35
+ onComplete?: () => void;
36
+ }
37
+ interface TweenOptions extends PlayOptions {
38
+ to?: Props;
39
+ from?: Props;
40
+ /** ms (default 600). */
41
+ duration?: number;
42
+ ease?: string | Ease;
43
+ /** Delay added per target index (ms) when several targets are given. */
44
+ stagger?: number;
45
+ }
46
+ /** Common playback: delay, repeat, yoyo, direction, ticker attachment, promise. */
47
+ declare abstract class Playable {
48
+ delay: number;
49
+ repeat: number;
50
+ yoyo: boolean;
51
+ /** Playback rate multiplier. */
52
+ timeScale: number;
53
+ onUpdate?: (progress: number) => void;
54
+ onComplete?: () => void;
55
+ protected _t: number;
56
+ private _dir;
57
+ private _off;
58
+ private _done;
59
+ private _resolve;
60
+ /** Resolves on completion (forward end, or start when reversed). */
61
+ finished: Promise<void>;
62
+ /** Set when owned by a timeline (then the ticker never drives it). */
63
+ parent: Timeline | null;
64
+ constructor(o: PlayOptions);
65
+ /** One iteration, ms. */
66
+ abstract get duration(): number;
67
+ /** Render at `ms` into one iteration. */
68
+ protected abstract renderLocal(ms: number, iterationEnded: boolean): void;
69
+ get totalDuration(): number;
70
+ get time(): number;
71
+ get progress(): number;
72
+ set progress(p: number);
73
+ get isActive(): boolean;
74
+ get reversed(): boolean;
75
+ /** Jump to `ms` (total time, including the delay) and render. */
76
+ seek(ms: number): this;
77
+ play(): this;
78
+ pause(): this;
79
+ /** Play backwards from the current time. */
80
+ reverse(): this;
81
+ restart(): this;
82
+ /** Stop and detach for good. */
83
+ kill(): void;
84
+ /** Promise-like: `await tween(...)`. */
85
+ then<R>(ok?: (v: void) => R, err?: (e: unknown) => R): Promise<R>;
86
+ private attach;
87
+ private advance;
88
+ protected complete(): void;
89
+ }
90
+ /** Position: ms number, '<' (start of previous), '>' (end of previous, default), '+=200' / '-=200' (relative to the end), 'label', 'label+=100', '<+=100'. */
91
+ type Position = number | string;
92
+ interface TimelineOptions extends PlayOptions {
93
+ /** Defaults merged into every `.to()`. */
94
+ defaults?: Omit<TweenOptions, 'to' | 'from'>;
95
+ }
96
+ /** A sequence of tweens, nested timelines and callbacks. */
97
+ declare class Timeline extends Playable {
98
+ private children;
99
+ private labels;
100
+ private prevStart;
101
+ private prevEnd;
102
+ private defaults;
103
+ private lastLocal;
104
+ constructor(o?: TimelineOptions);
105
+ get duration(): number;
106
+ private resolve;
107
+ /** Add a tween, timeline or callback at a position. */
108
+ add(item: Playable | (() => void), position?: Position): this;
109
+ /** `tween(target, vars)` placed at `position` (stagger across several targets). */
110
+ to(target: Target | Target[] | ArrayLike<Target>, vars: TweenOptions, position?: Position): this;
111
+ call(fn: () => void, position?: Position): this;
112
+ label(name: string, position?: Position): this;
113
+ /** Time of a label, ms. */
114
+ labelTime(name: string): number | undefined;
115
+ remove(item: Playable): void;
116
+ /** Children in start order (callbacks excluded). */
117
+ getChildren(): Playable[];
118
+ protected renderLocal(ms: number): void;
119
+ }
120
+
121
+ /**
122
+ * Normalised keyframes shared by the format loaders: a list of frames with
123
+ * offsets in [0, 1], camelCase props and an optional per-segment easing,
124
+ * played as a runtime `Timeline` (one tween per segment).
125
+ */
126
+
127
+ interface Frame {
128
+ offset: number;
129
+ props: Record<string, string | number>;
130
+ /** Easing from this frame to the next. */
131
+ easing?: string;
132
+ }
133
+
134
+ /**
135
+ * `motionary/runtime/format-motion` (10.1) — play Motion / Framer-style
136
+ * keyframe JSON with the runtime:
137
+ *
138
+ * ```json
139
+ * { "initial": { "opacity": 0, "y": 40 },
140
+ * "animate": { "opacity": 1, "y": [40, -8, 0], "rotate": 0 },
141
+ * "transition": { "duration": 0.6, "ease": "easeOut", "times": [0, 0.7, 1], "delay": 0.1,
142
+ * "repeat": 1, "repeatType": "reverse", "opacity": { "duration": 0.3 } } }
143
+ * ```
144
+ *
145
+ * Supported: `initial` / `animate` (numbers, unit strings, colours, arrays as
146
+ * keyframes), the transform shorthands `x y scale scaleX scaleY rotate skewX skewY`,
147
+ * transition `duration` / `delay` (seconds) / `ease` (names or `[x1, y1, x2, y2]`) /
148
+ * `times` / `repeat` (`Infinity` ok) / `repeatType` (`loop`, `reverse`, `mirror`),
149
+ * per-property transitions, and `type: "spring"` (`stiffness`, `damping`, `mass`,
150
+ * or `bounce` + `duration`) simulated into an easing curve.
151
+ * Not supported: `layout`, gestures (`whileHover` …), variants propagation,
152
+ * `staggerChildren` (use the runtime timeline `stagger`).
153
+ */
154
+
155
+ type V = number | string;
156
+ interface MotionTransition {
157
+ duration?: number;
158
+ delay?: number;
159
+ ease?: string | number[] | (string | number[])[];
160
+ times?: number[];
161
+ repeat?: number;
162
+ repeatType?: 'loop' | 'reverse' | 'mirror';
163
+ type?: 'tween' | 'spring' | 'keyframes' | 'inertia';
164
+ stiffness?: number;
165
+ damping?: number;
166
+ mass?: number;
167
+ bounce?: number;
168
+ [prop: string]: unknown;
169
+ }
170
+ interface MotionDef {
171
+ initial?: Record<string, V> | false;
172
+ animate: Record<string, V | V[]>;
173
+ transition?: MotionTransition;
174
+ }
175
+ /** A Motion ease → runtime ease. */
176
+ declare function motionEase(e: string | number[] | undefined): Ease;
177
+ /** Simulate a damped spring (unit step) → [ease, duration ms]. */
178
+ declare function springEase(o: {
179
+ stiffness?: number;
180
+ damping?: number;
181
+ mass?: number;
182
+ bounce?: number;
183
+ duration?: number;
184
+ }): [Ease, number];
185
+ /** Motion def → one keyframe track per transition group (`[frames, transition]`). */
186
+ declare function fromMotion(def: MotionDef): {
187
+ frames: Frame[];
188
+ transition: MotionTransition;
189
+ props: string[];
190
+ }[];
191
+ /**
192
+ * Apply `initial` immediately and play `animate` with the transition.
193
+ * Returns a runtime `Timeline` (one child per transition group), playing unless `paused`.
194
+ */
195
+ declare function playMotion(target: Target, def: MotionDef, o?: {
196
+ paused?: boolean;
197
+ }): Timeline;
198
+ interface FormatMotionApi {
199
+ fromMotion: typeof fromMotion;
200
+ playMotion: typeof playMotion;
201
+ springEase: typeof springEase;
202
+ motionEase: typeof motionEase;
203
+ }
204
+ /** The module object for `use(formatMotion)`. */
205
+ declare const formatMotion: RuntimeModule<FormatMotionApi>;
206
+
207
+ export { formatMotion, fromMotion, motionEase, playMotion, springEase };
208
+ export type { FormatMotionApi, MotionDef, MotionTransition };