@clipkit/runtime 1.0.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 (219) hide show
  1. package/LICENSE +54 -0
  2. package/README.md +98 -0
  3. package/dist/animation/easings.d.ts +9 -0
  4. package/dist/animation/easings.d.ts.map +1 -0
  5. package/dist/animation/easings.js +230 -0
  6. package/dist/animation/easings.js.map +1 -0
  7. package/dist/animation/expr.d.ts +44 -0
  8. package/dist/animation/expr.d.ts.map +1 -0
  9. package/dist/animation/expr.js +236 -0
  10. package/dist/animation/expr.js.map +1 -0
  11. package/dist/animation/keyframes.d.ts +23 -0
  12. package/dist/animation/keyframes.d.ts.map +1 -0
  13. package/dist/animation/keyframes.js +117 -0
  14. package/dist/animation/keyframes.js.map +1 -0
  15. package/dist/animation/motion-path.d.ts +18 -0
  16. package/dist/animation/motion-path.d.ts.map +1 -0
  17. package/dist/animation/motion-path.js +269 -0
  18. package/dist/animation/motion-path.js.map +1 -0
  19. package/dist/animation/noise1d.d.ts +5 -0
  20. package/dist/animation/noise1d.d.ts.map +1 -0
  21. package/dist/animation/noise1d.js +27 -0
  22. package/dist/animation/noise1d.js.map +1 -0
  23. package/dist/animation/presets.d.ts +60 -0
  24. package/dist/animation/presets.d.ts.map +1 -0
  25. package/dist/animation/presets.js +221 -0
  26. package/dist/animation/presets.js.map +1 -0
  27. package/dist/assets/cache.d.ts +18 -0
  28. package/dist/assets/cache.d.ts.map +1 -0
  29. package/dist/assets/cache.js +56 -0
  30. package/dist/assets/cache.js.map +1 -0
  31. package/dist/assets/fonts.d.ts +20 -0
  32. package/dist/assets/fonts.d.ts.map +1 -0
  33. package/dist/assets/fonts.js +127 -0
  34. package/dist/assets/fonts.js.map +1 -0
  35. package/dist/assets/loader.d.ts +18 -0
  36. package/dist/assets/loader.d.ts.map +1 -0
  37. package/dist/assets/loader.js +87 -0
  38. package/dist/assets/loader.js.map +1 -0
  39. package/dist/assets/lut.d.ts +5 -0
  40. package/dist/assets/lut.d.ts.map +1 -0
  41. package/dist/assets/lut.js +77 -0
  42. package/dist/assets/lut.js.map +1 -0
  43. package/dist/assets/media-time.d.ts +31 -0
  44. package/dist/assets/media-time.d.ts.map +1 -0
  45. package/dist/assets/media-time.js +65 -0
  46. package/dist/assets/media-time.js.map +1 -0
  47. package/dist/assets/mp4-frame-source.d.ts +44 -0
  48. package/dist/assets/mp4-frame-source.d.ts.map +1 -0
  49. package/dist/assets/mp4-frame-source.js +387 -0
  50. package/dist/assets/mp4-frame-source.js.map +1 -0
  51. package/dist/audio/encoder.d.ts +31 -0
  52. package/dist/audio/encoder.d.ts.map +1 -0
  53. package/dist/audio/encoder.js +96 -0
  54. package/dist/audio/encoder.js.map +1 -0
  55. package/dist/audio/fades.d.ts +16 -0
  56. package/dist/audio/fades.d.ts.map +1 -0
  57. package/dist/audio/fades.js +43 -0
  58. package/dist/audio/fades.js.map +1 -0
  59. package/dist/audio/limiter.d.ts +8 -0
  60. package/dist/audio/limiter.d.ts.map +1 -0
  61. package/dist/audio/limiter.js +39 -0
  62. package/dist/audio/limiter.js.map +1 -0
  63. package/dist/audio/loader.d.ts +6 -0
  64. package/dist/audio/loader.d.ts.map +1 -0
  65. package/dist/audio/loader.js +42 -0
  66. package/dist/audio/loader.js.map +1 -0
  67. package/dist/audio/mixer.d.ts +17 -0
  68. package/dist/audio/mixer.d.ts.map +1 -0
  69. package/dist/audio/mixer.js +204 -0
  70. package/dist/audio/mixer.js.map +1 -0
  71. package/dist/audio/varispeed.d.ts +24 -0
  72. package/dist/audio/varispeed.d.ts.map +1 -0
  73. package/dist/audio/varispeed.js +114 -0
  74. package/dist/audio/varispeed.js.map +1 -0
  75. package/dist/audio/wav.d.ts +6 -0
  76. package/dist/audio/wav.d.ts.map +1 -0
  77. package/dist/audio/wav.js +62 -0
  78. package/dist/audio/wav.js.map +1 -0
  79. package/dist/backend/backend.d.ts +579 -0
  80. package/dist/backend/backend.d.ts.map +1 -0
  81. package/dist/backend/backend.js +17 -0
  82. package/dist/backend/backend.js.map +1 -0
  83. package/dist/backend/webgl-backend.d.ts +97 -0
  84. package/dist/backend/webgl-backend.d.ts.map +1 -0
  85. package/dist/backend/webgl-backend.js +2142 -0
  86. package/dist/backend/webgl-backend.js.map +1 -0
  87. package/dist/backend/webgpu-backend.d.ts +121 -0
  88. package/dist/backend/webgpu-backend.d.ts.map +1 -0
  89. package/dist/backend/webgpu-backend.js +2481 -0
  90. package/dist/backend/webgpu-backend.js.map +1 -0
  91. package/dist/compositor/bitfont.d.ts +8 -0
  92. package/dist/compositor/bitfont.d.ts.map +1 -0
  93. package/dist/compositor/bitfont.js +52 -0
  94. package/dist/compositor/bitfont.js.map +1 -0
  95. package/dist/compositor/camera.d.ts +5 -0
  96. package/dist/compositor/camera.d.ts.map +1 -0
  97. package/dist/compositor/camera.js +114 -0
  98. package/dist/compositor/camera.js.map +1 -0
  99. package/dist/compositor/color.d.ts +26 -0
  100. package/dist/compositor/color.d.ts.map +1 -0
  101. package/dist/compositor/color.js +189 -0
  102. package/dist/compositor/color.js.map +1 -0
  103. package/dist/compositor/element-renderers/caption.d.ts +4 -0
  104. package/dist/compositor/element-renderers/caption.d.ts.map +1 -0
  105. package/dist/compositor/element-renderers/caption.js +376 -0
  106. package/dist/compositor/element-renderers/caption.js.map +1 -0
  107. package/dist/compositor/element-renderers/group.d.ts +12 -0
  108. package/dist/compositor/element-renderers/group.d.ts.map +1 -0
  109. package/dist/compositor/element-renderers/group.js +259 -0
  110. package/dist/compositor/element-renderers/group.js.map +1 -0
  111. package/dist/compositor/element-renderers/image.d.ts +4 -0
  112. package/dist/compositor/element-renderers/image.d.ts.map +1 -0
  113. package/dist/compositor/element-renderers/image.js +97 -0
  114. package/dist/compositor/element-renderers/image.js.map +1 -0
  115. package/dist/compositor/element-renderers/lit.d.ts +6 -0
  116. package/dist/compositor/element-renderers/lit.d.ts.map +1 -0
  117. package/dist/compositor/element-renderers/lit.js +82 -0
  118. package/dist/compositor/element-renderers/lit.js.map +1 -0
  119. package/dist/compositor/element-renderers/particles.d.ts +4 -0
  120. package/dist/compositor/element-renderers/particles.d.ts.map +1 -0
  121. package/dist/compositor/element-renderers/particles.js +212 -0
  122. package/dist/compositor/element-renderers/particles.js.map +1 -0
  123. package/dist/compositor/element-renderers/shape.d.ts +4 -0
  124. package/dist/compositor/element-renderers/shape.d.ts.map +1 -0
  125. package/dist/compositor/element-renderers/shape.js +171 -0
  126. package/dist/compositor/element-renderers/shape.js.map +1 -0
  127. package/dist/compositor/element-renderers/svg.d.ts +4 -0
  128. package/dist/compositor/element-renderers/svg.d.ts.map +1 -0
  129. package/dist/compositor/element-renderers/svg.js +210 -0
  130. package/dist/compositor/element-renderers/svg.js.map +1 -0
  131. package/dist/compositor/element-renderers/text.d.ts +25 -0
  132. package/dist/compositor/element-renderers/text.d.ts.map +1 -0
  133. package/dist/compositor/element-renderers/text.js +1358 -0
  134. package/dist/compositor/element-renderers/text.js.map +1 -0
  135. package/dist/compositor/element-renderers/video.d.ts +12 -0
  136. package/dist/compositor/element-renderers/video.d.ts.map +1 -0
  137. package/dist/compositor/element-renderers/video.js +109 -0
  138. package/dist/compositor/element-renderers/video.js.map +1 -0
  139. package/dist/compositor/fit.d.ts +18 -0
  140. package/dist/compositor/fit.d.ts.map +1 -0
  141. package/dist/compositor/fit.js +106 -0
  142. package/dist/compositor/fit.js.map +1 -0
  143. package/dist/compositor/lighting.d.ts +63 -0
  144. package/dist/compositor/lighting.d.ts.map +1 -0
  145. package/dist/compositor/lighting.js +141 -0
  146. package/dist/compositor/lighting.js.map +1 -0
  147. package/dist/compositor/mat4.d.ts +88 -0
  148. package/dist/compositor/mat4.d.ts.map +1 -0
  149. package/dist/compositor/mat4.js +245 -0
  150. package/dist/compositor/mat4.js.map +1 -0
  151. package/dist/compositor/project.d.ts +24 -0
  152. package/dist/compositor/project.d.ts.map +1 -0
  153. package/dist/compositor/project.js +105 -0
  154. package/dist/compositor/project.js.map +1 -0
  155. package/dist/compositor/render-context.d.ts +194 -0
  156. package/dist/compositor/render-context.d.ts.map +1 -0
  157. package/dist/compositor/render-context.js +10 -0
  158. package/dist/compositor/render-context.js.map +1 -0
  159. package/dist/compositor/resolve.d.ts +80 -0
  160. package/dist/compositor/resolve.d.ts.map +1 -0
  161. package/dist/compositor/resolve.js +276 -0
  162. package/dist/compositor/resolve.js.map +1 -0
  163. package/dist/compositor/scene.d.ts +10 -0
  164. package/dist/compositor/scene.d.ts.map +1 -0
  165. package/dist/compositor/scene.js +658 -0
  166. package/dist/compositor/scene.js.map +1 -0
  167. package/dist/compositor/transform.d.ts +73 -0
  168. package/dist/compositor/transform.d.ts.map +1 -0
  169. package/dist/compositor/transform.js +229 -0
  170. package/dist/compositor/transform.js.map +1 -0
  171. package/dist/compositor/unit.d.ts +27 -0
  172. package/dist/compositor/unit.d.ts.map +1 -0
  173. package/dist/compositor/unit.js +74 -0
  174. package/dist/compositor/unit.js.map +1 -0
  175. package/dist/encoder/exporter.d.ts +95 -0
  176. package/dist/encoder/exporter.d.ts.map +1 -0
  177. package/dist/encoder/exporter.js +341 -0
  178. package/dist/encoder/exporter.js.map +1 -0
  179. package/dist/encoder/index.d.ts +3 -0
  180. package/dist/encoder/index.d.ts.map +1 -0
  181. package/dist/encoder/index.js +2 -0
  182. package/dist/encoder/index.js.map +1 -0
  183. package/dist/index.d.ts +12 -0
  184. package/dist/index.d.ts.map +1 -0
  185. package/dist/index.js +27 -0
  186. package/dist/index.js.map +1 -0
  187. package/dist/logger.d.ts +13 -0
  188. package/dist/logger.d.ts.map +1 -0
  189. package/dist/logger.js +32 -0
  190. package/dist/logger.js.map +1 -0
  191. package/dist/runtime.d.ts +216 -0
  192. package/dist/runtime.d.ts.map +1 -0
  193. package/dist/runtime.js +1012 -0
  194. package/dist/runtime.js.map +1 -0
  195. package/dist/svg/morph.d.ts +6 -0
  196. package/dist/svg/morph.d.ts.map +1 -0
  197. package/dist/svg/morph.js +62 -0
  198. package/dist/svg/morph.js.map +1 -0
  199. package/dist/svg/svg-renderer.d.ts +18 -0
  200. package/dist/svg/svg-renderer.d.ts.map +1 -0
  201. package/dist/svg/svg-renderer.js +142 -0
  202. package/dist/svg/svg-renderer.js.map +1 -0
  203. package/dist/text/caption-chunk.d.ts +17 -0
  204. package/dist/text/caption-chunk.d.ts.map +1 -0
  205. package/dist/text/caption-chunk.js +76 -0
  206. package/dist/text/caption-chunk.js.map +1 -0
  207. package/dist/text/font-atlas.d.ts +63 -0
  208. package/dist/text/font-atlas.d.ts.map +1 -0
  209. package/dist/text/font-atlas.js +225 -0
  210. package/dist/text/font-atlas.js.map +1 -0
  211. package/dist/text/measure.d.ts +38 -0
  212. package/dist/text/measure.d.ts.map +1 -0
  213. package/dist/text/measure.js +164 -0
  214. package/dist/text/measure.js.map +1 -0
  215. package/dist/text/text-animation.d.ts +52 -0
  216. package/dist/text/text-animation.d.ts.map +1 -0
  217. package/dist/text/text-animation.js +133 -0
  218. package/dist/text/text-animation.js.map +1 -0
  219. package/package.json +47 -0
package/LICENSE ADDED
@@ -0,0 +1,54 @@
1
+ Business Source License 1.1
2
+
3
+ Parameters
4
+
5
+ Licensor: Clipkit Contributors
6
+
7
+ Licensed Work: @clipkit/runtime
8
+ The Licensed Work is (c) 2026 Clipkit Contributors
9
+
10
+ Additional Use Grant: You may make use of the Licensed Work, provided
11
+ that you do not use the Licensed Work for a
12
+ Competing Service.
13
+
14
+ A "Competing Service" is a commercial product or
15
+ service offered to third parties that provides
16
+ Clipkit Protocol video rendering as a service
17
+ (whether offered as software-as-a-service, a
18
+ hosted API, or any similar offering whose primary
19
+ purpose is providing rendering of Clipkit
20
+ Protocol documents).
21
+
22
+ For clarity, the following uses are NOT a
23
+ Competing Service and ARE permitted:
24
+ - embedding the Licensed Work in your own
25
+ application or website (including as a
26
+ dependency of @clipkit/editor or other tools
27
+ built on the runtime)
28
+ - rendering videos for your own product or app
29
+ - rendering videos for your own customers as
30
+ part of a broader product offering
31
+ - internal use within an organization
32
+ - personal, educational, or research use
33
+ - non-commercial open-source projects
34
+ - building your own independent implementation
35
+ of the Clipkit Protocol
36
+
37
+ Change Date: Four years from the date the Licensed Work is
38
+ published.
39
+
40
+ Change License: Apache License, Version 2.0
41
+
42
+ For information about alternative licensing arrangements for the
43
+ Licensed Work, please contact ianscott313@gmail.com.
44
+
45
+ ----------------------------------------------------------------------
46
+
47
+ The canonical Business Source License 1.1 text is available at:
48
+
49
+ https://mariadb.com/bsl11/
50
+
51
+ The Licensor's parameters above modify the canonical text in accordance
52
+ with the BSL's parameter mechanism. The parameters and the canonical
53
+ text together constitute the full license.
54
+ </content>
package/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # @clipkit/runtime
2
+
3
+ WebGPU compositor + WebCodecs encoder for the Clipkit schema. Browser-first (Phase 1 — Node support comes later).
4
+
5
+ > **Status:** Phase 2a — port + cleanup of the existing webgpu-video-editor renderer. Audio path and caption rendering land in Phase 2b/2c.
6
+
7
+ ## Install
8
+
9
+ ```ts
10
+ import {
11
+ ClipkitRenderer,
12
+ ClipkitExporter,
13
+ setLogger,
14
+ type Source,
15
+ } from '@clipkit/runtime';
16
+ ```
17
+
18
+ ## Preview
19
+
20
+ ```ts
21
+ const canvas = document.querySelector('canvas')!;
22
+ const renderer = new ClipkitRenderer(canvas);
23
+ await renderer.initialize();
24
+
25
+ const source: Source = { /* ... */ };
26
+ const frameLoop = () => {
27
+ renderer.render(source, currentTime);
28
+ requestAnimationFrame(frameLoop);
29
+ };
30
+ frameLoop();
31
+ ```
32
+
33
+ ## Export
34
+
35
+ ```ts
36
+ const exporter = new ClipkitExporter(canvas, renderer);
37
+ const blob = await exporter.export(source, {
38
+ codec: 'avc1.42002A',
39
+ bitrate: 5_000_000,
40
+ framerate: 30,
41
+ onProgress: (p) => console.log(`${(p * 100).toFixed(1)}%`),
42
+ });
43
+
44
+ const url = URL.createObjectURL(blob);
45
+ // → playable MP4
46
+ ```
47
+
48
+ ## Logging
49
+
50
+ The runtime emits debug/info/warn/error logs prefixed with `[clipkit]`. Default is `'console'`:
51
+
52
+ ```ts
53
+ import { setLogger } from '@clipkit/runtime';
54
+
55
+ setLogger('silent'); // suppress all
56
+ setLogger({ debug, info, warn, error });// custom sink
57
+ ```
58
+
59
+ ## What's covered today
60
+
61
+ - WebGPU compositor with WebGL2 fallback: shape, text, image, video elements.
62
+ - `caption` element with word-level timing and four kinetic styles (`tiktok_bounce`, `fade_reveal`, `kinetic_typewriter`, `word_pop`).
63
+ - Keyframe-based property animation (29 easings).
64
+ - Named animation presets (`fade-in`, `slide-up-in`, etc.) compiled to tweens.
65
+ - WebCodecs H.264 video export via mp4-muxer.
66
+ - **Audio export:** `audio` elements decoded on preload, mixed via OfflineAudioContext, encoded as AAC, written to an audio track in the output MP4.
67
+ - FontFace-API-driven font loading with explicit loaded/ready state.
68
+
69
+ ## Known port-time bugs (inherited from upstream, fix list)
70
+
71
+ - **`border_radius` discards entire shape.** The shape fragment shader uses `border_radius` in normalized texcoord space (0..1) but the JS writes it in pixels — any value ≥ 0.5 makes `length(corner) > radius` true for every fragment and discards the whole shape. Use `border_radius: 0` until the shader is normalized (send `border_radius_px / min(width_px, height_px)`).
72
+ - **Property-evaluator cache key includes time** (`{ms}_{ids}`), so every distinct frame is a cache miss. The cache is effectively a no-op for static properties; values fall through to `evaluateStaticValue` correctly but waste CPU.
73
+ - **`shapeType` uniform is declared `u32` in the shader but written as `f32`.** For values 0/1 the bit patterns happen to land on `u32 0` and `u32 1065353216` respectively — works for rectangle (path !== "ellipse" → 0), would silently break any future shape-type that's not 0 or "ellipse".
74
+
75
+ These don't block Phase 2a (port + canary), but they should be cleaned up before Phase 2c (caption renderer touches the shape pipeline).
76
+
77
+ ## Known limitations
78
+
79
+ - **No preview audio playback yet** — `audio` elements are silent during preview but DO appear in the MP4 export. Real-time audio playback through Web Audio is a follow-up.
80
+ - **Audio `volume` keyframes are not yet animated** — only the static `volume` value applies. Animating volume requires a per-element GainNode with parameter automation; the API extension is small.
81
+ - **No caption wrapping** — long captions render on a single line. Multi-line wrap is a follow-up.
82
+ - **No composition nesting** — `composition` elements are currently no-ops. Recursive rendering through `composition.elements` is deferred.
83
+
84
+ ## Browser support
85
+
86
+ WebGPU is the primary backend; WebGL2 is the automatic fallback. The runtime tries WebGPU first and falls through to WebGL2 if `requestAdapter` returns null.
87
+
88
+ - **Chrome / Edge (desktop + Android):** WebGPU works. Full feature support.
89
+ - **Safari:** WebGPU is enabled by default in recent versions. WebGL2 fallback covers older Safari.
90
+ - **Firefox:** WebGL2 fallback (WebGPU not yet stable).
91
+
92
+ WebCodecs (used by the encoder) is more constrained — Chrome/Edge full, Safari partial, Firefox in progress. Preview works on all four browsers via WebGL2 even when export doesn't.
93
+
94
+ ### Gotcha: canvas locking
95
+
96
+ Once a canvas has been bound to a graphics context via `getContext('webgpu')` or `getContext('webgl2')`, **it's locked to that context type for life**. You can't switch a canvas from WebGPU to WebGL2 (or vice versa) after the first context is acquired — subsequent `getContext` calls with the other type return `null`.
97
+
98
+ If your app needs to switch backends at runtime (e.g. a settings toggle), **provide a fresh canvas** for the new `ClipkitRuntime`. In React, this means a `key` prop that changes when the backend changes so the canvas remounts.
@@ -0,0 +1,9 @@
1
+ import type { EasingFunction } from '@clipkit/protocol';
2
+ /**
3
+ * Apply an easing to a progress value in 0..1.
4
+ * Accepts named easings and the parametric `cubic-bezier(...)` / `steps(n)`
5
+ * forms. Unknown easings fall back to linear so a bad schema value never
6
+ * throws.
7
+ */
8
+ export declare function applyEasing(name: EasingFunction | string | undefined, t: number): number;
9
+ //# sourceMappingURL=easings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"easings.d.ts","sourceRoot":"","sources":["../../src/animation/easings.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAuOxD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,GAAG,SAAS,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAMxF"}
@@ -0,0 +1,230 @@
1
+ // Easing functions. All take and return progress in 0..1 (back / elastic /
2
+ // spring overshoot outside [0, 1] mid-curve by design).
3
+ //
4
+ // Names match the schema's EASING_FUNCTIONS const array in @clipkit/protocol,
5
+ // which is the single source of truth for valid easing names. Two parametric
6
+ // forms are also accepted: `cubic-bezier(x1, y1, x2, y2)` and `steps(n)` —
7
+ // parsed on first use and cached.
8
+ const linear = (t) => t;
9
+ const easeIn = (t) => t * t;
10
+ const easeOut = (t) => t * (2 - t);
11
+ const easeInOut = (t) => (t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t);
12
+ const easeInCubic = (t) => t * t * t;
13
+ const easeOutCubic = (t) => 1 - Math.pow(1 - t, 3);
14
+ const easeInOutCubic = (t) => t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
15
+ const easeInQuad = easeIn;
16
+ const easeOutQuad = easeOut;
17
+ const easeInOutQuad = easeInOut;
18
+ const easeInQuart = (t) => t * t * t * t;
19
+ const easeOutQuart = (t) => 1 - Math.pow(1 - t, 4);
20
+ const easeInOutQuart = (t) => t < 0.5 ? 8 * t * t * t * t : 1 - Math.pow(-2 * t + 2, 4) / 2;
21
+ const easeInQuint = (t) => t * t * t * t * t;
22
+ const easeOutQuint = (t) => 1 - Math.pow(1 - t, 5);
23
+ const easeInOutQuint = (t) => t < 0.5 ? 16 * t * t * t * t * t : 1 - Math.pow(-2 * t + 2, 5) / 2;
24
+ const easeInSine = (t) => 1 - Math.cos((t * Math.PI) / 2);
25
+ const easeOutSine = (t) => Math.sin((t * Math.PI) / 2);
26
+ const easeInOutSine = (t) => -(Math.cos(Math.PI * t) - 1) / 2;
27
+ const easeInExpo = (t) => (t === 0 ? 0 : Math.pow(2, 10 * t - 10));
28
+ const easeOutExpo = (t) => (t === 1 ? 1 : 1 - Math.pow(2, -10 * t));
29
+ const easeInOutExpo = (t) => {
30
+ if (t === 0)
31
+ return 0;
32
+ if (t === 1)
33
+ return 1;
34
+ return t < 0.5
35
+ ? Math.pow(2, 20 * t - 10) / 2
36
+ : (2 - Math.pow(2, -20 * t + 10)) / 2;
37
+ };
38
+ const easeInCirc = (t) => 1 - Math.sqrt(1 - Math.pow(t, 2));
39
+ const easeOutCirc = (t) => Math.sqrt(1 - Math.pow(t - 1, 2));
40
+ const easeInOutCirc = (t) => t < 0.5
41
+ ? (1 - Math.sqrt(1 - Math.pow(2 * t, 2))) / 2
42
+ : (Math.sqrt(1 - Math.pow(-2 * t + 2, 2)) + 1) / 2;
43
+ const c1 = 1.70158;
44
+ const c2 = c1 * 1.525;
45
+ const c3 = c1 + 1;
46
+ const easeInBack = (t) => c3 * t * t * t - c1 * t * t;
47
+ const easeOutBack = (t) => 1 + c3 * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2);
48
+ const easeInOutBack = (t) => t < 0.5
49
+ ? (Math.pow(2 * t, 2) * ((c2 + 1) * 2 * t - c2)) / 2
50
+ : (Math.pow(2 * t - 2, 2) * ((c2 + 1) * (t * 2 - 2) + c2) + 2) / 2;
51
+ // Damped harmonic oscillator. Mass=1, damping=10, stiffness=100 — the classic
52
+ // springy defaults. Underdamped → overshoots ~5%, settles by t≈1.
53
+ // position(t) = 1 − e^(−ζω₀t) · [cos(ω_d t) + (ζω₀ / ω_d) · sin(ω_d t)]
54
+ const spring = (t) => {
55
+ const mass = 1;
56
+ const damping = 10;
57
+ const stiffness = 100;
58
+ const omega0 = Math.sqrt(stiffness / mass);
59
+ const zeta = damping / (2 * Math.sqrt(stiffness * mass));
60
+ // The animation runs at t ∈ [0, 1]; scale physics time so the spring is
61
+ // mostly settled by the end of the easing curve. The spring naturally
62
+ // settles by ~1s of physics time at these params; we let the curve play
63
+ // over our [0, 1] window directly.
64
+ const phys = t;
65
+ if (zeta < 1) {
66
+ const omegaD = omega0 * Math.sqrt(1 - zeta * zeta);
67
+ return 1 - Math.exp(-zeta * omega0 * phys) *
68
+ (Math.cos(omegaD * phys) + ((zeta * omega0) / omegaD) * Math.sin(omegaD * phys));
69
+ }
70
+ // Critically damped fallback (rare with default params).
71
+ return 1 - Math.exp(-omega0 * phys) * (1 + omega0 * phys);
72
+ };
73
+ // Elastic — decaying sinusoidal overshoot (easings.net formulas).
74
+ const c4 = (2 * Math.PI) / 3;
75
+ const c5 = (2 * Math.PI) / 4.5;
76
+ const elasticIn = (t) => -Math.pow(2, 10 * t - 10) * Math.sin((t * 10 - 10.75) * c4);
77
+ const elasticOut = (t) => Math.pow(2, -10 * t) * Math.sin((t * 10 - 0.75) * c4) + 1;
78
+ const elasticInOut = (t) => t < 0.5
79
+ ? -(Math.pow(2, 20 * t - 10) * Math.sin((20 * t - 11.125) * c5)) / 2
80
+ : (Math.pow(2, -20 * t + 10) * Math.sin((20 * t - 11.125) * c5)) / 2 + 1;
81
+ // Bounce — piecewise parabolic "ball drop" (easings.net formulas).
82
+ const bounceOut = (t) => {
83
+ const n1 = 7.5625;
84
+ const d1 = 2.75;
85
+ if (t < 1 / d1)
86
+ return n1 * t * t;
87
+ if (t < 2 / d1)
88
+ return n1 * (t -= 1.5 / d1) * t + 0.75;
89
+ if (t < 2.5 / d1)
90
+ return n1 * (t -= 2.25 / d1) * t + 0.9375;
91
+ return n1 * (t -= 2.625 / d1) * t + 0.984375;
92
+ };
93
+ const bounceIn = (t) => 1 - bounceOut(1 - t);
94
+ const bounceInOut = (t) => t < 0.5 ? (1 - bounceOut(1 - 2 * t)) / 2 : (1 + bounceOut(2 * t - 1)) / 2;
95
+ const REGISTRY = {
96
+ 'linear': linear,
97
+ 'ease': easeInOut, // CSS "ease" is roughly the same shape
98
+ 'ease-in': easeIn,
99
+ 'ease-out': easeOut,
100
+ 'ease-in-out': easeInOut,
101
+ 'ease-in-cubic': easeInCubic,
102
+ 'ease-out-cubic': easeOutCubic,
103
+ 'ease-in-out-cubic': easeInOutCubic,
104
+ 'ease-in-quad': easeInQuad,
105
+ 'ease-out-quad': easeOutQuad,
106
+ 'ease-in-out-quad': easeInOutQuad,
107
+ 'ease-in-quart': easeInQuart,
108
+ 'ease-out-quart': easeOutQuart,
109
+ 'ease-in-out-quart': easeInOutQuart,
110
+ 'ease-in-quint': easeInQuint,
111
+ 'ease-out-quint': easeOutQuint,
112
+ 'ease-in-out-quint': easeInOutQuint,
113
+ 'ease-in-sine': easeInSine,
114
+ 'ease-out-sine': easeOutSine,
115
+ 'ease-in-out-sine': easeInOutSine,
116
+ 'ease-in-expo': easeInExpo,
117
+ 'ease-out-expo': easeOutExpo,
118
+ 'ease-in-out-expo': easeInOutExpo,
119
+ 'ease-in-circ': easeInCirc,
120
+ 'ease-out-circ': easeOutCirc,
121
+ 'ease-in-out-circ': easeInOutCirc,
122
+ 'ease-in-back': easeInBack,
123
+ 'ease-out-back': easeOutBack,
124
+ 'ease-in-out-back': easeInOutBack,
125
+ 'spring': spring,
126
+ 'elastic-in': elasticIn,
127
+ 'elastic-out': elasticOut,
128
+ 'elastic-in-out': elasticInOut,
129
+ 'bounce-in': bounceIn,
130
+ 'bounce-out': bounceOut,
131
+ 'bounce-in-out': bounceInOut,
132
+ };
133
+ // ── Parametric easings ──────────────────────────────────────────────────────
134
+ /**
135
+ * CSS cubic-bezier timing function. Control points (x1, y1) / (x2, y2);
136
+ * endpoints fixed at (0,0) and (1,1). Solve x(s) = t for the curve
137
+ * parameter s via Newton-Raphson with a bisection fallback, then return
138
+ * y(s). Same approach as every browser's implementation.
139
+ */
140
+ function cubicBezier(x1, y1, x2, y2) {
141
+ // Polynomial coefficients for B(s) = ((a·s + b)·s + c)·s.
142
+ const cxc = 3 * x1;
143
+ const bxc = 3 * (x2 - x1) - cxc;
144
+ const axc = 1 - cxc - bxc;
145
+ const cyc = 3 * y1;
146
+ const byc = 3 * (y2 - y1) - cyc;
147
+ const ayc = 1 - cyc - byc;
148
+ const sampleX = (s) => ((axc * s + bxc) * s + cxc) * s;
149
+ const sampleY = (s) => ((ayc * s + byc) * s + cyc) * s;
150
+ const sampleDX = (s) => (3 * axc * s + 2 * bxc) * s + cxc;
151
+ return (t) => {
152
+ // Newton-Raphson — converges in a few iterations for sane curves.
153
+ let s = t;
154
+ for (let i = 0; i < 8; i++) {
155
+ const x = sampleX(s) - t;
156
+ if (Math.abs(x) < 1e-6)
157
+ return sampleY(s);
158
+ const dx = sampleDX(s);
159
+ if (Math.abs(dx) < 1e-6)
160
+ break;
161
+ s -= x / dx;
162
+ }
163
+ // Bisection fallback for flat-derivative regions.
164
+ let lo = 0;
165
+ let hi = 1;
166
+ s = t;
167
+ while (lo < hi) {
168
+ const x = sampleX(s);
169
+ if (Math.abs(x - t) < 1e-6)
170
+ break;
171
+ if (x < t)
172
+ lo = s;
173
+ else
174
+ hi = s;
175
+ s = (lo + hi) / 2;
176
+ if (hi - lo < 1e-6)
177
+ break;
178
+ }
179
+ return sampleY(s);
180
+ };
181
+ }
182
+ /** CSS steps(n, end): n equidistant steps, jumping at each interval's end. */
183
+ function steps(n) {
184
+ return (t) => Math.floor(t * n) / n;
185
+ }
186
+ const CUBIC_BEZIER_RE = /^cubic-bezier\(\s*(-?\d*\.?\d+)\s*,\s*(-?\d*\.?\d+)\s*,\s*(-?\d*\.?\d+)\s*,\s*(-?\d*\.?\d+)\s*\)$/;
187
+ const STEPS_RE = /^steps\(\s*(\d+)\s*\)$/;
188
+ // Parsed-parametric cache. Invalid strings cache `null` so a bad schema
189
+ // value doesn't re-run the regexes every frame.
190
+ const parametricCache = new Map();
191
+ function parseParametric(name) {
192
+ const cached = parametricCache.get(name);
193
+ if (cached !== undefined)
194
+ return cached;
195
+ let fn = null;
196
+ const bez = CUBIC_BEZIER_RE.exec(name);
197
+ if (bez) {
198
+ // x coordinates must stay in [0, 1] for x(s) to be invertible.
199
+ const x1 = Math.min(1, Math.max(0, parseFloat(bez[1])));
200
+ const x2 = Math.min(1, Math.max(0, parseFloat(bez[3])));
201
+ fn = cubicBezier(x1, parseFloat(bez[2]), x2, parseFloat(bez[4]));
202
+ }
203
+ else {
204
+ const st = STEPS_RE.exec(name);
205
+ if (st) {
206
+ const n = parseInt(st[1], 10);
207
+ if (n > 0)
208
+ fn = steps(n);
209
+ }
210
+ }
211
+ parametricCache.set(name, fn);
212
+ return fn;
213
+ }
214
+ /**
215
+ * Apply an easing to a progress value in 0..1.
216
+ * Accepts named easings and the parametric `cubic-bezier(...)` / `steps(n)`
217
+ * forms. Unknown easings fall back to linear so a bad schema value never
218
+ * throws.
219
+ */
220
+ export function applyEasing(name, t) {
221
+ if (t <= 0)
222
+ return 0;
223
+ if (t >= 1)
224
+ return 1;
225
+ if (!name)
226
+ return t;
227
+ const fn = REGISTRY[name] ?? parseParametric(name);
228
+ return (fn ?? linear)(t);
229
+ }
230
+ //# sourceMappingURL=easings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"easings.js","sourceRoot":"","sources":["../../src/animation/easings.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,wDAAwD;AACxD,EAAE;AACF,8EAA8E;AAC9E,6EAA6E;AAC7E,2EAA2E;AAC3E,kCAAkC;AAMlC,MAAM,MAAM,GAAW,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAEhC,MAAM,MAAM,GAAW,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;AACpC,MAAM,OAAO,GAAW,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAC3C,MAAM,SAAS,GAAW,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAE9E,MAAM,WAAW,GAAW,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAC7C,MAAM,YAAY,GAAW,C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,EAAE,EAAE,CAAC,CAAC;IAC9B,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,IAAyC,EAAE,CAAS;IAC9E,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,CAAC,CAAC;IACrB,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,CAAC,CAAC;IACrB,IAAI,CAAC,IAAI;QAAE,OAAO,CAAC,CAAC;IACpB,MAAM,EAAE,GAAG,QAAQ,CAAC,IAAsB,CAAC,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;IACrE,OAAO,CAAC,EAAE,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,44 @@
1
+ export interface ExprScope {
2
+ /** element-local time, seconds */ t: number;
3
+ /** element duration, seconds */ dur: number;
4
+ /** index within a generated set */ i: number;
5
+ /** sibling count */ n: number;
6
+ /** the property's base/static value */ value: number;
7
+ }
8
+ type Node = {
9
+ k: 'num';
10
+ v: number;
11
+ } | {
12
+ k: 'var';
13
+ name: string;
14
+ } | {
15
+ k: 'un';
16
+ op: string;
17
+ a: Node;
18
+ } | {
19
+ k: 'bin';
20
+ op: string;
21
+ a: Node;
22
+ b: Node;
23
+ } | {
24
+ k: 'tern';
25
+ c: Node;
26
+ a: Node;
27
+ b: Node;
28
+ } | {
29
+ k: 'call';
30
+ name: string;
31
+ args: Node[];
32
+ };
33
+ export declare function compileExpr(src: string): Node | null;
34
+ /** True when a property value is an expression object `{ expr: string }`. */
35
+ export declare function isExpr(v: unknown): v is {
36
+ expr: string;
37
+ };
38
+ /** Evaluate `{expr}` in the given scope; returns NaN-guarded `scope.value` on
39
+ * parse error or non-finite result. */
40
+ export declare function evalExpr(value: {
41
+ expr: string;
42
+ }, scope: ExprScope): number;
43
+ export {};
44
+ //# sourceMappingURL=expr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expr.d.ts","sourceRoot":"","sources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