@motionscript/math 0.0.0-stage → 0.1.0-alpha.10

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 (335) hide show
  1. package/CHANGELOG.md +144 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +49 -0
  4. package/README.md +389 -2
  5. package/dist/annotate/angle-mark.d.ts +96 -0
  6. package/dist/annotate/angle-mark.d.ts.map +1 -0
  7. package/dist/annotate/angle-mark.js +97 -0
  8. package/dist/annotate/angle-mark.js.map +1 -0
  9. package/dist/annotate/curly-brace.d.ts +115 -0
  10. package/dist/annotate/curly-brace.d.ts.map +1 -0
  11. package/dist/annotate/curly-brace.js +99 -0
  12. package/dist/annotate/curly-brace.js.map +1 -0
  13. package/dist/annotate/emphasis-mark.d.ts +80 -0
  14. package/dist/annotate/emphasis-mark.d.ts.map +1 -0
  15. package/dist/annotate/emphasis-mark.js +80 -0
  16. package/dist/annotate/emphasis-mark.js.map +1 -0
  17. package/dist/browser/THIRD_PARTY_LICENSES.txt +420 -0
  18. package/dist/browser/chunks/chunk-IRZCG6PM.js +2 -0
  19. package/dist/browser/chunks/chunk-IRZCG6PM.js.map +7 -0
  20. package/dist/browser/chunks/chunk-WMVW6ZIV.js +2 -0
  21. package/dist/browser/chunks/chunk-WMVW6ZIV.js.map +7 -0
  22. package/dist/browser/chunks/mathjax-WV55AC2P.js +61 -0
  23. package/dist/browser/chunks/mathjax-WV55AC2P.js.map +7 -0
  24. package/dist/browser/index.js +2 -0
  25. package/dist/browser/index.js.map +7 -0
  26. package/dist/browser/kit.js +2 -0
  27. package/dist/browser/kit.js.map +7 -0
  28. package/dist/browser/manifest.json +30 -0
  29. package/dist/browser/tex.js +2 -0
  30. package/dist/browser/tex.js.map +7 -0
  31. package/dist/engine.d.ts +71 -0
  32. package/dist/engine.d.ts.map +1 -0
  33. package/dist/engine.js +45 -0
  34. package/dist/engine.js.map +1 -0
  35. package/dist/index.d.ts +30 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +30 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/kit/brace.d.ts +8 -0
  40. package/dist/kit/brace.d.ts.map +1 -0
  41. package/dist/kit/brace.js +36 -0
  42. package/dist/kit/brace.js.map +1 -0
  43. package/dist/kit/cache.d.ts +30 -0
  44. package/dist/kit/cache.d.ts.map +1 -0
  45. package/dist/kit/cache.js +53 -0
  46. package/dist/kit/cache.js.map +1 -0
  47. package/dist/kit/component.d.ts +51 -0
  48. package/dist/kit/component.d.ts.map +1 -0
  49. package/dist/kit/component.js +30 -0
  50. package/dist/kit/component.js.map +1 -0
  51. package/dist/kit/contour.d.ts +8 -0
  52. package/dist/kit/contour.d.ts.map +1 -0
  53. package/dist/kit/contour.js +93 -0
  54. package/dist/kit/contour.js.map +1 -0
  55. package/dist/kit/coords.d.ts +69 -0
  56. package/dist/kit/coords.d.ts.map +1 -0
  57. package/dist/kit/coords.js +224 -0
  58. package/dist/kit/coords.js.map +1 -0
  59. package/dist/kit/curve.d.ts +28 -0
  60. package/dist/kit/curve.d.ts.map +1 -0
  61. package/dist/kit/curve.js +29 -0
  62. package/dist/kit/curve.js.map +1 -0
  63. package/dist/kit/equation.d.ts +61 -0
  64. package/dist/kit/equation.d.ts.map +1 -0
  65. package/dist/kit/equation.js +168 -0
  66. package/dist/kit/equation.js.map +1 -0
  67. package/dist/kit/equation3d.d.ts +50 -0
  68. package/dist/kit/equation3d.d.ts.map +1 -0
  69. package/dist/kit/equation3d.js +103 -0
  70. package/dist/kit/equation3d.js.map +1 -0
  71. package/dist/kit/expression.d.ts +35 -0
  72. package/dist/kit/expression.d.ts.map +1 -0
  73. package/dist/kit/expression.js +124 -0
  74. package/dist/kit/expression.js.map +1 -0
  75. package/dist/kit/field-mark.d.ts +79 -0
  76. package/dist/kit/field-mark.d.ts.map +1 -0
  77. package/dist/kit/field-mark.js +109 -0
  78. package/dist/kit/field-mark.js.map +1 -0
  79. package/dist/kit/field.d.ts +14 -0
  80. package/dist/kit/field.d.ts.map +1 -0
  81. package/dist/kit/field.js +46 -0
  82. package/dist/kit/field.js.map +1 -0
  83. package/dist/kit/follow.d.ts +109 -0
  84. package/dist/kit/follow.d.ts.map +1 -0
  85. package/dist/kit/follow.js +163 -0
  86. package/dist/kit/follow.js.map +1 -0
  87. package/dist/kit/furniture.d.ts +32 -0
  88. package/dist/kit/furniture.d.ts.map +1 -0
  89. package/dist/kit/furniture.js +92 -0
  90. package/dist/kit/furniture.js.map +1 -0
  91. package/dist/kit/geometry.d.ts +13 -0
  92. package/dist/kit/geometry.d.ts.map +1 -0
  93. package/dist/kit/geometry.js +54 -0
  94. package/dist/kit/geometry.js.map +1 -0
  95. package/dist/kit/graph.d.ts +46 -0
  96. package/dist/kit/graph.d.ts.map +1 -0
  97. package/dist/kit/graph.js +90 -0
  98. package/dist/kit/graph.js.map +1 -0
  99. package/dist/kit/mark.d.ts +72 -0
  100. package/dist/kit/mark.d.ts.map +1 -0
  101. package/dist/kit/mark.js +87 -0
  102. package/dist/kit/mark.js.map +1 -0
  103. package/dist/kit/part-fills.d.ts +23 -0
  104. package/dist/kit/part-fills.d.ts.map +1 -0
  105. package/dist/kit/part-fills.js +46 -0
  106. package/dist/kit/part-fills.js.map +1 -0
  107. package/dist/kit/place.d.ts +20 -0
  108. package/dist/kit/place.d.ts.map +1 -0
  109. package/dist/kit/place.js +66 -0
  110. package/dist/kit/place.js.map +1 -0
  111. package/dist/kit/sampler.d.ts +17 -0
  112. package/dist/kit/sampler.d.ts.map +1 -0
  113. package/dist/kit/sampler.js +250 -0
  114. package/dist/kit/sampler.js.map +1 -0
  115. package/dist/kit/scale.d.ts +12 -0
  116. package/dist/kit/scale.d.ts.map +1 -0
  117. package/dist/kit/scale.js +37 -0
  118. package/dist/kit/scale.js.map +1 -0
  119. package/dist/kit/source.d.ts +22 -0
  120. package/dist/kit/source.d.ts.map +1 -0
  121. package/dist/kit/source.js +45 -0
  122. package/dist/kit/source.js.map +1 -0
  123. package/dist/kit/system.d.ts +31 -0
  124. package/dist/kit/system.d.ts.map +1 -0
  125. package/dist/kit/system.js +71 -0
  126. package/dist/kit/system.js.map +1 -0
  127. package/dist/kit/ticks.d.ts +19 -0
  128. package/dist/kit/ticks.d.ts.map +1 -0
  129. package/dist/kit/ticks.js +78 -0
  130. package/dist/kit/ticks.js.map +1 -0
  131. package/dist/kit/withdrawn.d.ts +9 -0
  132. package/dist/kit/withdrawn.d.ts.map +1 -0
  133. package/dist/kit/withdrawn.js +9 -0
  134. package/dist/kit/withdrawn.js.map +1 -0
  135. package/dist/marks/curve-area.d.ts +51 -0
  136. package/dist/marks/curve-area.d.ts.map +1 -0
  137. package/dist/marks/curve-area.js +59 -0
  138. package/dist/marks/curve-area.js.map +1 -0
  139. package/dist/marks/drop-lines.d.ts +57 -0
  140. package/dist/marks/drop-lines.d.ts.map +1 -0
  141. package/dist/marks/drop-lines.js +43 -0
  142. package/dist/marks/drop-lines.js.map +1 -0
  143. package/dist/marks/plot-point.d.ts +71 -0
  144. package/dist/marks/plot-point.d.ts.map +1 -0
  145. package/dist/marks/plot-point.js +71 -0
  146. package/dist/marks/plot-point.js.map +1 -0
  147. package/dist/marks/riemann-sum.d.ts +58 -0
  148. package/dist/marks/riemann-sum.d.ts.map +1 -0
  149. package/dist/marks/riemann-sum.js +63 -0
  150. package/dist/marks/riemann-sum.js.map +1 -0
  151. package/dist/marks/tangent-line.d.ts +71 -0
  152. package/dist/marks/tangent-line.d.ts.map +1 -0
  153. package/dist/marks/tangent-line.js +89 -0
  154. package/dist/marks/tangent-line.js.map +1 -0
  155. package/dist/marks/vector-arrow.d.ts +60 -0
  156. package/dist/marks/vector-arrow.d.ts.map +1 -0
  157. package/dist/marks/vector-arrow.js +67 -0
  158. package/dist/marks/vector-arrow.js.map +1 -0
  159. package/dist/nodes.d.ts +43 -0
  160. package/dist/nodes.d.ts.map +1 -0
  161. package/dist/nodes.js +57 -0
  162. package/dist/nodes.js.map +1 -0
  163. package/dist/plots/function-plot.d.ts +159 -0
  164. package/dist/plots/function-plot.d.ts.map +1 -0
  165. package/dist/plots/function-plot.js +184 -0
  166. package/dist/plots/function-plot.js.map +1 -0
  167. package/dist/plots/points-plot.d.ts +64 -0
  168. package/dist/plots/points-plot.d.ts.map +1 -0
  169. package/dist/plots/points-plot.js +72 -0
  170. package/dist/plots/points-plot.js.map +1 -0
  171. package/dist/plots/stream-lines.d.ts +76 -0
  172. package/dist/plots/stream-lines.d.ts.map +1 -0
  173. package/dist/plots/stream-lines.js +122 -0
  174. package/dist/plots/stream-lines.js.map +1 -0
  175. package/dist/plots/traced-path.d.ts +70 -0
  176. package/dist/plots/traced-path.d.ts.map +1 -0
  177. package/dist/plots/traced-path.js +41 -0
  178. package/dist/plots/traced-path.js.map +1 -0
  179. package/dist/plots/vector-field.d.ts +60 -0
  180. package/dist/plots/vector-field.d.ts.map +1 -0
  181. package/dist/plots/vector-field.js +77 -0
  182. package/dist/plots/vector-field.js.map +1 -0
  183. package/dist/structures/graph-layout.d.ts +11 -0
  184. package/dist/structures/graph-layout.d.ts.map +1 -0
  185. package/dist/structures/graph-layout.js +135 -0
  186. package/dist/structures/graph-layout.js.map +1 -0
  187. package/dist/structures/network-graph.d.ts +174 -0
  188. package/dist/structures/network-graph.d.ts.map +1 -0
  189. package/dist/structures/network-graph.js +240 -0
  190. package/dist/structures/network-graph.js.map +1 -0
  191. package/dist/structures/sample-space.d.ts +114 -0
  192. package/dist/structures/sample-space.d.ts.map +1 -0
  193. package/dist/structures/sample-space.js +161 -0
  194. package/dist/structures/sample-space.js.map +1 -0
  195. package/dist/systems/axes2d.d.ts +197 -0
  196. package/dist/systems/axes2d.d.ts.map +1 -0
  197. package/dist/systems/axes2d.js +157 -0
  198. package/dist/systems/axes2d.js.map +1 -0
  199. package/dist/systems/number-line.d.ts +101 -0
  200. package/dist/systems/number-line.d.ts.map +1 -0
  201. package/dist/systems/number-line.js +91 -0
  202. package/dist/systems/number-line.js.map +1 -0
  203. package/dist/systems/number-plane.d.ts +168 -0
  204. package/dist/systems/number-plane.d.ts.map +1 -0
  205. package/dist/systems/number-plane.js +186 -0
  206. package/dist/systems/number-plane.js.map +1 -0
  207. package/dist/systems/polar-plane.d.ts +98 -0
  208. package/dist/systems/polar-plane.d.ts.map +1 -0
  209. package/dist/systems/polar-plane.js +139 -0
  210. package/dist/systems/polar-plane.js.map +1 -0
  211. package/dist/tex/geometry.d.ts +85 -0
  212. package/dist/tex/geometry.d.ts.map +1 -0
  213. package/dist/tex/geometry.js +632 -0
  214. package/dist/tex/geometry.js.map +1 -0
  215. package/dist/tex/index.d.ts +11 -0
  216. package/dist/tex/index.d.ts.map +1 -0
  217. package/dist/tex/index.js +10 -0
  218. package/dist/tex/index.js.map +1 -0
  219. package/dist/tex/mathjax.d.ts +33 -0
  220. package/dist/tex/mathjax.d.ts.map +1 -0
  221. package/dist/tex/mathjax.js +74 -0
  222. package/dist/tex/mathjax.js.map +1 -0
  223. package/dist/tex/matrix.d.ts +101 -0
  224. package/dist/tex/matrix.d.ts.map +1 -0
  225. package/dist/tex/matrix.js +56 -0
  226. package/dist/tex/matrix.js.map +1 -0
  227. package/dist/tex/node.d.ts +98 -0
  228. package/dist/tex/node.d.ts.map +1 -0
  229. package/dist/tex/node.js +25 -0
  230. package/dist/tex/node.js.map +1 -0
  231. package/dist/tex/tween.d.ts +50 -0
  232. package/dist/tex/tween.d.ts.map +1 -0
  233. package/dist/tex/tween.js +253 -0
  234. package/dist/tex/tween.js.map +1 -0
  235. package/dist/tex/typeset.d.ts +133 -0
  236. package/dist/tex/typeset.d.ts.map +1 -0
  237. package/dist/tex/typeset.js +403 -0
  238. package/dist/tex/typeset.js.map +1 -0
  239. package/dist/three/axes3d.d.ts +247 -0
  240. package/dist/three/axes3d.d.ts.map +1 -0
  241. package/dist/three/axes3d.js +187 -0
  242. package/dist/three/axes3d.js.map +1 -0
  243. package/dist/three/curve-plot3d.d.ts +126 -0
  244. package/dist/three/curve-plot3d.d.ts.map +1 -0
  245. package/dist/three/curve-plot3d.js +109 -0
  246. package/dist/three/curve-plot3d.js.map +1 -0
  247. package/dist/three/entries.d.ts +17 -0
  248. package/dist/three/entries.d.ts.map +1 -0
  249. package/dist/three/entries.js +15 -0
  250. package/dist/three/entries.js.map +1 -0
  251. package/dist/three/label3d.d.ts +11 -0
  252. package/dist/three/label3d.d.ts.map +1 -0
  253. package/dist/three/label3d.js +42 -0
  254. package/dist/three/label3d.js.map +1 -0
  255. package/dist/three/plot-point3d.d.ts +99 -0
  256. package/dist/three/plot-point3d.d.ts.map +1 -0
  257. package/dist/three/plot-point3d.js +34 -0
  258. package/dist/three/plot-point3d.js.map +1 -0
  259. package/dist/three/space.d.ts +43 -0
  260. package/dist/three/space.d.ts.map +1 -0
  261. package/dist/three/space.js +58 -0
  262. package/dist/three/space.js.map +1 -0
  263. package/dist/three/surface-plot3d.d.ts +207 -0
  264. package/dist/three/surface-plot3d.d.ts.map +1 -0
  265. package/dist/three/surface-plot3d.js +261 -0
  266. package/dist/three/surface-plot3d.js.map +1 -0
  267. package/dist/three/vector-arrow3d.d.ts +96 -0
  268. package/dist/three/vector-arrow3d.d.ts.map +1 -0
  269. package/dist/three/vector-arrow3d.js +53 -0
  270. package/dist/three/vector-arrow3d.js.map +1 -0
  271. package/package.json +80 -3
  272. package/registry.json +251 -0
  273. package/src/annotate/angle-mark.ts +137 -0
  274. package/src/annotate/curly-brace.ts +148 -0
  275. package/src/annotate/emphasis-mark.ts +118 -0
  276. package/src/engine.ts +86 -0
  277. package/src/index.ts +29 -0
  278. package/src/kit/brace.ts +37 -0
  279. package/src/kit/cache.ts +61 -0
  280. package/src/kit/component.ts +57 -0
  281. package/src/kit/contour.ts +94 -0
  282. package/src/kit/coords.ts +278 -0
  283. package/src/kit/curve.ts +47 -0
  284. package/src/kit/equation.ts +181 -0
  285. package/src/kit/equation3d.ts +137 -0
  286. package/src/kit/expression.ts +159 -0
  287. package/src/kit/field-mark.ts +171 -0
  288. package/src/kit/field.ts +50 -0
  289. package/src/kit/follow.ts +229 -0
  290. package/src/kit/furniture.ts +113 -0
  291. package/src/kit/geometry.ts +49 -0
  292. package/src/kit/graph.ts +116 -0
  293. package/src/kit/mark.ts +152 -0
  294. package/src/kit/part-fills.ts +61 -0
  295. package/src/kit/place.ts +77 -0
  296. package/src/kit/sampler.ts +281 -0
  297. package/src/kit/scale.ts +39 -0
  298. package/src/kit/source.ts +57 -0
  299. package/src/kit/system.ts +105 -0
  300. package/src/kit/ticks.ts +85 -0
  301. package/src/kit/withdrawn.ts +8 -0
  302. package/src/marks/curve-area.ts +89 -0
  303. package/src/marks/drop-lines.ts +71 -0
  304. package/src/marks/plot-point.ts +102 -0
  305. package/src/marks/riemann-sum.ts +99 -0
  306. package/src/marks/tangent-line.ts +119 -0
  307. package/src/marks/vector-arrow.ts +98 -0
  308. package/src/nodes.ts +99 -0
  309. package/src/plots/function-plot.ts +220 -0
  310. package/src/plots/points-plot.ts +103 -0
  311. package/src/plots/stream-lines.ts +160 -0
  312. package/src/plots/traced-path.ts +70 -0
  313. package/src/plots/vector-field.ts +107 -0
  314. package/src/structures/graph-layout.ts +145 -0
  315. package/src/structures/network-graph.ts +291 -0
  316. package/src/structures/sample-space.ts +210 -0
  317. package/src/systems/axes2d.ts +226 -0
  318. package/src/systems/number-line.ts +130 -0
  319. package/src/systems/number-plane.ts +232 -0
  320. package/src/systems/polar-plane.ts +177 -0
  321. package/src/tex/geometry.ts +703 -0
  322. package/src/tex/index.ts +15 -0
  323. package/src/tex/mathjax.ts +82 -0
  324. package/src/tex/matrix.ts +97 -0
  325. package/src/tex/node.ts +74 -0
  326. package/src/tex/tween.ts +308 -0
  327. package/src/tex/typeset.ts +461 -0
  328. package/src/three/axes3d.ts +267 -0
  329. package/src/three/curve-plot3d.ts +146 -0
  330. package/src/three/entries.ts +42 -0
  331. package/src/three/label3d.ts +52 -0
  332. package/src/three/plot-point3d.ts +63 -0
  333. package/src/three/space.ts +92 -0
  334. package/src/three/surface-plot3d.ts +318 -0
  335. package/src/three/vector-arrow3d.ts +88 -0
@@ -0,0 +1,46 @@
1
+ import { fillOps, lerpNumber } from "@motionscript/sdk";
2
+ // Every entry is kept as written, one with no part yet included, so an editor
3
+ // showing the list shows the row it just added; the drawing skips it.
4
+ export function readPartFills(value) {
5
+ if (!Array.isArray(value))
6
+ return [];
7
+ return value.map((entry) => ({
8
+ part: String(entry?.part ?? ""),
9
+ fill: fillOps.resolve(entry?.fill ?? "#ffffff"),
10
+ occurrence: Math.max(0, Math.round(entry?.occurrence ?? 0)),
11
+ mix: Math.min(1, Math.max(0, entry?.mix ?? 1)),
12
+ }));
13
+ }
14
+ const keyOf = (entry) => `${entry.occurrence}|${entry.part}`;
15
+ // A paint that arrives grows from the node's own, and one that leaves fades back to it.
16
+ export function lerpPartFills(from, to, t) {
17
+ if (t <= 0)
18
+ return from;
19
+ if (t >= 1)
20
+ return to;
21
+ const before = new Map(from.map((entry) => [keyOf(entry), entry]));
22
+ const out = to.map((entry) => {
23
+ const was = before.get(keyOf(entry));
24
+ before.delete(keyOf(entry));
25
+ return was
26
+ ? { ...entry, fill: fillOps.lerp(was.fill, entry.fill, t), mix: lerpNumber(was.mix, entry.mix, t) }
27
+ : { ...entry, mix: entry.mix * t };
28
+ });
29
+ for (const gone of before.values())
30
+ out.push({ ...gone, mix: gone.mix * (1 - t) });
31
+ return out;
32
+ }
33
+ /** Each part fill with its own key, the one in place of an earlier one for the same part and occurrence. */
34
+ export function withPartFill(fills, entry) {
35
+ const occurrence = Math.max(0, Math.round(entry.occurrence ?? 0));
36
+ return [...fills.filter((was) => was.part !== entry.part || was.occurrence !== occurrence), { ...entry, occurrence }];
37
+ }
38
+ /** `base` with a part's fill laid over it while it arrives, in place of it once it has. */
39
+ export function partPaint(base, entry) {
40
+ if (!entry || entry.mix <= 0)
41
+ return base;
42
+ if (entry.mix >= 1)
43
+ return entry.fill;
44
+ return [...base, ...entry.fill.map((layer) => ({ ...layer, opacity: (layer.opacity ?? 1) * entry.m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AG,CAAC,UAAU,KAAK,UAAU,CAAC,EAAE,EAAE,GAAG,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;AAC1H,CAAC;AAED,2FAA2F;AAC3F,MAAM,UAAU,SAAS,CAAC,IAAoB,EAAE,KAAmC;IAC/E,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1C,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC,IAAI,CAAC;IACtC,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;AAC9G,CAAC","sourcesContent":["import { fillOps, lerpNumber, type Fill, type FillResolved } from \"@motionscript/sdk\";\n\n/** A paint for one part of a node, named the way the node names its parts: a formula's term, a graph's vertex or edge. */\nexport interface PartFill {\n part: string;\n fill: Fill;\n /** Which of the places the part is written, counted from 1; 0 is all of them. */\n occurrence?: number;\n /** How far from the node's own paint to `fill`, 0 to 1. A tween's state: an author leaves it out. */\n mix?: number;\n}\n\nexport interface PartFillResolved {\n part: string;\n fill: FillResolved[];\n occurrence: number;\n mix: number;\n}\n\n// Every entry is kept as written, one with no part yet included, so an editor\n// showing the list shows the row it just added; the drawing skips it.\nexport function readPartFills(value: readonly PartFill[] | null | undefined): PartFillResolved[] {\n if (!Array.isArray(value)) return [];\n return value.map((entry) => ({\n part: String(entry?.part ?? \"\"),\n fill: fillOps.resolve(entry?.fill ?? \"#ffffff\"),\n occurrence: Math.max(0, Math.round(entry?.occurrence ?? 0)),\n mix: Math.min(1, Math.max(0, entry?.mix ?? 1)),\n }));\n}\n\nconst keyOf = (entry: PartFillResolved) => `${entry.occurrence}|${entry.part}`;\n\n// A paint that arrives grows from the node's own, and one that leaves fades back to it.\nexport function lerpPartFills(from: PartFillResolved[], to: PartFillResolved[], t: number): PartFillResolved[] {\n if (t <= 0) return from;\n if (t >= 1) return to;\n const before = new Map(from.map((entry) => [keyOf(entry), entry]));\n const out = to.map((entry) => {\n const was = before.get(keyOf(entry));\n before.delete(keyOf(entry));\n return was\n ? { ...entry, fill: fillOps.lerp(was.fill, entry.fill, t), mix: lerpNumber(was.mix, entry.mix, t) }\n : { ...entry, mix: entry.mix * t };\n });\n for (const gone of before.values()) out.push({ ...gone, mix: gone.mix * (1 - t) });\n return out;\n}\n\n/** Each part fill with its own key, the one in place of an earlier one for the same part and occurrence. */\nexport function withPartFill(fills: readonly PartFillResolved[], entry: PartFill): PartFill[] {\n const occurrence = Math.max(0, Math.round(entry.occurrence ?? 0));\n return [...fills.filter((was) => was.part !== entry.part || was.occurrence !== occurrence), { ...entry, occurrence }];\n}\n\n/** `base` with a part's fill laid over it while it arrives, in place of it once it has. */\nexport function partPaint(base: FillResolved[], entry: PartFillResolved | undefined): FillResolved[] {\n if (!entry || entry.mix <= 0) return base;\n if (entry.mix >= 1) return entry.fill;\n return [...base, ...entry.fill.map((layer) => ({ ...layer, opacity: (layer.opacity ?? 1) * entry.mix }))];\n}\n"]}
@@ -0,0 +1,20 @@
1
+ import type { ChildPlane, ChildView, Placement2D, Size2D, Vector2 } from "@motionscript/sdk";
2
+ import type { CoordinateMap } from "./coords.js";
3
+ import type { GraphPlane } from "./graph.js";
4
+ /** Where a child that sits somewhere other than its own `x`/`y` is (a point riding a curve), given its own `x`/`y`. */
5
+ export type Anchor = (x: number, y: number) => Vector2;
6
+ /** `component`, declared to sit at `anchor` of its own `x`/`y` on a graph. Hand back the component. */
7
+ export declare function anchored<C extends {
8
+ is(child: ChildView): boolean;
9
+ }>(component: C, anchor: (state: never, plane: GraphPlane) => Anchor | null): C;
10
+ /**
11
+ * Lay `children` out on `map`, for whichever node holds them: a coordinate
12
+ * system, or a plot holding the marks that read it. A mark goes on its ink;
13
+ * anything else keeps its own size and has its `x`/`y` read as graph
14
+ * coordinates. `origin` is the holder's own centre in the map's pixels (y-up),
15
+ * since a child's box is placed from there.
16
+ */
17
+ export declare function placeOnMap(children: readonly ChildView[], map: CoordinateMap, origin: Vector2, room: Size2D, plane: GraphPlane): Placement2D[];
18
+ /** The plane of a child that is not there yet, under a holder centred on `origin`: where a host would drop one. */
19
+ export declare function openPlane(map: CoordinateMap, origin: Vector2): ChildPlane;
20
+ //# sourceMappingURL=place.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"place.d.ts","sourceRoot":"","sources":["../../src/kit/place.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC7F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAG1C,uHAAuH;AACvH,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC;AAIvD,uGAAuG;AACvG,wBAAgB,QAAQ,CAAC,CAAC,SAAS;IAAE,EAAE,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAA;CAAE,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,KAAK,MAAM,GAAG,IAAI,GAAG,CAAC,CAGjJ;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,SAAS,SAAS,EAAE,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,WAAW,EAAE,CAqB9I;AAED,mHAAmH;AACnH,wBAAgB,SAAS,CAAC,GAAG,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,GAAG,UAAU,CAQzE"}
@@ -0,0 +1,66 @@
1
+ import { boundsOfRuns } from "./geometry.js";
2
+ import { markRuns } from "./mark.js";
3
+ const anchors = [];
4
+ /** `component`, declared to sit at `anchor` of its own `x`/`y` on a graph. Hand back the component. */
5
+ export function anchored(component, anchor) {
6
+ anchors.push({ is: (child) => component.is(child), anchor });
7
+ return component;
8
+ }
9
+ /**
10
+ * Lay `children` out on `map`, for whichever node holds them: a coordinate
11
+ * system, or a plot holding the marks that read it. A mark goes on its ink;
12
+ * anything else keeps its own size and has its `x`/`y` read as graph
13
+ * coordinates. `origin` is the holder's own centre in the map's pixels (y-up),
14
+ * since a child's box is placed from there.
15
+ */
16
+ export function placeOnMap(children, map, origin, room, plane) {
17
+ return children.map((child) => {
18
+ const runs = markRuns(child, map, plane);
19
+ if (runs) {
20
+ const ink = boundsOfRuns(runs);
21
+ const cx = ink ? (ink.minX + ink.maxX) / 2 : origin.x;
22
+ const cy = ink ? (ink.minY + ink.maxY) / 2 : origin.y;
23
+ return {
24
+ x: cx - origin.x,
25
+ y: cy - origin.y,
26
+ width: ink ? ink.maxX - ink.minX : 0,
27
+ height: ink ? ink.maxY - ink.minY : 0,
28
+ plane: markPlane(map, cx, cy),
29
+ };
30
+ }
31
+ const size = child.measure({ width: room.width, height: room.height });
32
+ const entry = anchors.find((a) => a.is(child));
33
+ const anchor = entry ? entry.anchor(child.state, plane) : null;
34
+ // Its box is centred on the map's own centre, so its offset from there is its point.
35
+ return { x: -origin.x, y: -origin.y, width: size.width, height: size.height, plane: pointPlane(map, anchor) };
36
+ });
37
+ }
38
+ /** The plane of a child that is not there yet, under a holder centred on `origin`: where a host would drop one. */
39
+ export function openPlane(map, origin) {
40
+ return {
41
+ toOffset: (x, y) => {
42
+ const at = map.toPoint(x, y);
43
+ return { x: at.x - origin.x, y: at.y - origin.y };
44
+ },
45
+ toCoords: (x, y) => map.toCoords(x + origin.x, y + origin.y),
46
+ };
47
+ }
48
+ function pointPlane(map, anchor) {
49
+ const point = { x: 0, y: 0 };
50
+ return {
51
+ toOffset: (x, y) => {
52
+ const at = anchor?.(x, y);
53
+ return at ? map.toPoint(at.x, at.y, point) : map.toPoint(x, y, point);
54
+ },
55
+ toCoords: (x, y) => map.toCoords(x, y),
56
+ };
57
+ }
58
+ // A mark reads its own `x`/`y` as it draws, so its holder adds nothing; a drag still answers in graph units.
59
+ function markPlane(map, cx, cy) {
60
+ const none = { x: 0, y: 0 };
61
+ return {
62
+ toOffset: () => none,
63
+ toCoords: (x, y) => map.toCoords(cx + x, cy + y),
64
+ };
65
+ }
66
+ //# sourceMappingURL=place.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"place.js","sourceRoot":"","sources":["../../src/kit/place.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAKlC,MAAM,OAAO,GAA0H,EAAE,CAAC;AAE1I,uGAAuG;AACvG,MAAM,UAAU,QAAQ,CAA8C,SAAY,EAAE,MAA0D;IAC1I,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7D,OAAO,SAAS,CAAC;AACrB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,QAA8B,EAAE,GAAkB,EAAE,MAAe,EAAE,IAAY,EAAE,KAAiB;IAC3H,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAC1B,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;QACzC,IAAI,IAAI,EAAE,CAAC;YACP,MAAM,GAAG,GAAG,YAAY,CAAC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AAC;QACD,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;KACzC,CAAC;AACN,CAAC;AAED,6GAA6G;AAC7G,SAAS,SAAS,CAAC,GAAkB,EAAE,EAAU,EAAE,EAAU;IACzD,MAAM,IAAI,GAAY,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IACrC,OAAO;QACH,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI;QACpB,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;KACnD,CAAC;AACN,CAAC","sourcesContent":["import type { ChildPlane, ChildView, Placement2D, Size2D, Vector2 } from \"@motionscript/sdk\";\nimport type { CoordinateMap } from \"./coords\";\nimport { boundsOfRuns } from \"./geometry\";\nimport type { GraphPlane } from \"./graph\";\nimport { markRuns } from \"./mark\";\n\n/** Where a child that sits somewhere other than its own `x`/`y` is (a point riding a curve), given its own `x`/`y`. */\nexport type Anchor = (x: number, y: number) => Vector2;\n\nconst anchors: { readonly is: (child: ChildView) => boolean; readonly anchor: (state: never, plane: GraphPlane) => Anchor | null }[] = [];\n\n/** `component`, declared to sit at `anchor` of its own `x`/`y` on a graph. Hand back the component. */\nexport function anchored<C extends { is(child: ChildView): boolean }>(component: C, anchor: (state: never, plane: GraphPlane) => Anchor | null): C {\n anchors.push({ is: (child) => component.is(child), anchor });\n return component;\n}\n\n/**\n * Lay `children` out on `map`, for whichever node holds them: a coordinate\n * system, or a plot holding the marks that read it. A mark goes on its ink;\n * anything else keeps its own size and has its `x`/`y` read as graph\n * coordinates. `origin` is the holder's own centre in the map's pixels (y-up),\n * since a child's box is placed from there.\n */\nexport function placeOnMap(children: readonly ChildView[], map: CoordinateMap, origin: Vector2, room: Size2D, plane: GraphPlane): Placement2D[] {\n return children.map((child) => {\n const runs = markRuns(child, map, plane);\n if (runs) {\n const ink = boundsOfRuns(runs);\n const cx = ink ? (ink.minX + ink.maxX) / 2 : origin.x;\n const cy = ink ? (ink.minY + ink.maxY) / 2 : origin.y;\n return {\n x: cx - origin.x,\n y: cy - origin.y,\n width: ink ? ink.maxX - ink.minX : 0,\n height: ink ? ink.maxY - ink.minY : 0,\n plane: markPlane(map, cx, cy),\n };\n }\n const size = child.measure({ width: room.width, height: room.height });\n const entry = anchors.find((a) => a.is(child));\n const anchor = entry ? (entry.anchor as (state: unknown, plane: GraphPlane) => Anchor | null)(child.state, plane) : null;\n // Its box is centred on the map's own centre, so its offset from there is its point.\n return { x: -origin.x, y: -origin.y, width: size.width, height: size.height, plane: pointPlane(map, anchor) };\n });\n}\n\n/** The plane of a child that is not there yet, under a holder centred on `origin`: where a host would drop one. */\nexport function openPlane(map: CoordinateMap, origin: Vector2): ChildPlane {\n return {\n toOffset: (x, y) => {\n const at = map.toPoint(x, y);\n return { x: at.x - origin.x, y: at.y - origin.y };\n },\n toCoords: (x, y) => map.toCoords(x + origin.x, y + origin.y),\n };\n}\n\nfunction pointPlane(map: CoordinateMap, anchor: Anchor | null): ChildPlane {\n const point: Vector2 = { x: 0, y: 0 };\n return {\n toOffset: (x, y) => {\n const at = anchor?.(x, y);\n return at ? map.toPoint(at.x, at.y, point) : map.toPoint(x, y, point);\n },\n toCoords: (x, y) => map.toCoords(x, y),\n };\n}\n\n// A mark reads its own `x`/`y` as it draws, so its holder adds nothing; a drag still answers in graph units.\nfunction markPlane(map: CoordinateMap, cx: number, cy: number): ChildPlane {\n const none: Vector2 = { x: 0, y: 0 };\n return {\n toOffset: () => none,\n toCoords: (x, y) => map.toCoords(cx + x, cy + y),\n };\n}\n"]}
@@ -0,0 +1,17 @@
1
+ import type { Extents, Vector2 } from "@motionscript/sdk";
2
+ /**
3
+ * Turns a curve into the polylines that draw it: adaptively, so a straight
4
+ * stretch costs two points and a tight bend as many as it needs, and broken
5
+ * wherever the curve is, at an asymptote or the edge of its domain.
6
+ */
7
+ /** A curve's parameter to its pixel, written into `out`. `false` where the curve is undefined. */
8
+ export type CurveProjection = (t: number, out: Vector2) => boolean;
9
+ export interface SampleOptions {
10
+ /** The equal steps the parameter range starts as, before any is split. */
11
+ seeds?: number;
12
+ /** A parameter step that is not split again, however bent. */
13
+ minStep?: number;
14
+ }
15
+ /** The runs of points that draw `project` over `[t0, t1]`, clipped to `clip`. */
16
+ export declare function sampleCurve(project: CurveProjection, t0: number, t1: number, clip: Extents, { seeds, minStep }?: SampleOptions): Vector2[][];
17
+ //# sourceMappingURL=sampler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sampler.d.ts","sourceRoot":"","sources":["../../src/kit/sampler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE1D;;;;GAIG;AAEH,kGAAkG;AAClG,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC;AAEnE,MAAM,WAAW,aAAa;IAC1B,0EAA0E;IAC1E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8DAA8D;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AA8CD,iFAAiF;AACjF,wBAAgB,WAAW,CACvB,OAAO,EAAE,eAAe,EACxB,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,OAAO,EACb,EAAE,KAAqB,EAAE,OAAW,EAAE,GAAE,aAAkB,GAC3D,OAAO,EAAE,EAAE,CAsFb"}
@@ -0,0 +1,250 @@
1
+ /** Path coordinates are 32-bit floats in the renderer; past this a clamped point still clips to the same edge. */
2
+ const COORD_LIMIT = 16_000;
3
+ /** How far, in pixels, the drawn chord may stray from the curve. */
4
+ const TOLERANCE_PX = 0.25;
5
+ /** A turn, in radians, a chord is allowed to hide: what keeps a symmetric bump from reading as flat. */
6
+ const ANGLE_TOLERANCE = 0.05;
7
+ const MAX_DEPTH = 12;
8
+ const MAX_EVALUATIONS = 40_000;
9
+ const MAX_POINTS = 24_000;
10
+ /** Bisections spent finding where a domain ends. */
11
+ const BOUNDARY_STEPS = 60;
12
+ const DEFAULT_SEEDS = 256;
13
+ // Midpoints are pooled: a refine is a depth-first walk, so a slot is free again
14
+ // as soon as the seed interval it was taken for is done.
15
+ const arena = [];
16
+ let arenaMark = 0;
17
+ function takeSample() {
18
+ let slot = arena[arenaMark];
19
+ if (slot === undefined) {
20
+ slot = blank();
21
+ arena.push(slot);
22
+ }
23
+ arenaMark++;
24
+ return slot;
25
+ }
26
+ function blank() {
27
+ return { t: 0, px: 0, py: 0, rx: 0, ry: 0, ok: false };
28
+ }
29
+ const scratch = { x: 0, y: 0 };
30
+ /** The runs of points that draw `project` over `[t0, t1]`, clipped to `clip`. */
31
+ export function sampleCurve(project, t0, t1, clip, { seeds = DEFAULT_SEEDS, minStep = 0 } = {}) {
32
+ if (!(t1 > t0) || !Number.isFinite(t0) || !Number.isFinite(t1))
33
+ return [];
34
+ const pen = new CurvePen(clip);
35
+ let spent = 0;
36
+ const write = (slot, t) => {
37
+ const defined = project(t, scratch);
38
+ spent++;
39
+ const ok = defined && Number.isFinite(scratch.x) && Number.isFinite(scratch.y);
40
+ slot.t = t;
41
+ slot.rx = ok ? scratch.x : 0;
42
+ slot.ry = ok ? scratch.y : 0;
43
+ slot.px = clampCoord(slot.rx);
44
+ slot.py = clampCoord(slot.ry);
45
+ slot.ok = ok;
46
+ return slot;
47
+ };
48
+ const at = (t) => write(takeSample(), t);
49
+ // The last defined point before `to`, which is not: where `sqrt(x)` meets its axis.
50
+ const edgeOf = (from, to) => {
51
+ let inside = from;
52
+ let outsideT = to.t;
53
+ for (let i = 0; i < BOUNDARY_STEPS; i++) {
54
+ if (spent >= MAX_EVALUATIONS || offFrame(inside, clip))
55
+ break;
56
+ const midT = (inside.t + outsideT) / 2;
57
+ if (midT === inside.t || midT === outsideT)
58
+ break;
59
+ const mid = at(midT);
60
+ if (!mid.ok) {
61
+ outsideT = midT;
62
+ continue;
63
+ }
64
+ const settled = Math.abs(mid.px - inside.px) < TOLERANCE_PX && Math.abs(mid.py - inside.py) < TOLERANCE_PX;
65
+ inside = mid;
66
+ if (settled)
67
+ break;
68
+ }
69
+ return inside;
70
+ };
71
+ const emit = (a, m, b, floored) => {
72
+ if (a.ok && b.ok) {
73
+ if (floored && diverges(a, m, b, clip))
74
+ pen.break();
75
+ else
76
+ pen.draw(a, b);
77
+ return;
78
+ }
79
+ if (a.ok) {
80
+ const edge = edgeOf(a, b);
81
+ if (edge.t !== a.t)
82
+ pen.draw(a, edge);
83
+ pen.break();
84
+ return;
85
+ }
86
+ pen.break();
87
+ if (b.ok) {
88
+ const edge = edgeOf(b, a);
89
+ if (edge.t !== b.t)
90
+ pen.draw(edge, b);
91
+ else
92
+ pen.start(b);
93
+ }
94
+ };
95
+ const refine = (a, b, depth) => {
96
+ if (spent >= MAX_EVALUATIONS || pen.points >= MAX_POINTS) {
97
+ emit(a, null, b, false);
98
+ return;
99
+ }
100
+ const m = at((a.t + b.t) / 2);
101
+ const floored = depth >= MAX_DEPTH || b.t - a.t <= minStep;
102
+ if (floored || flat(a, m, b)) {
103
+ emit(a, m, b, floored);
104
+ return;
105
+ }
106
+ refine(a, m, depth + 1);
107
+ refine(m, b, depth + 1);
108
+ };
109
+ const count = Math.max(1, Math.round(seeds));
110
+ const step = (t1 - t0) / count;
111
+ const ends = [blank(), blank()];
112
+ let previous = write(ends[0], t0);
113
+ for (let i = 1; i <= count; i++) {
114
+ const next = write(ends[i & 1], i === count ? t1 : t0 + i * step);
115
+ arenaMark = 0;
116
+ refine(previous, next, 0);
117
+ previous = next;
118
+ }
119
+ arenaMark = 0;
120
+ return pen.finish();
121
+ }
122
+ function flat(a, m, b) {
123
+ if (a.ok !== m.ok || m.ok !== b.ok)
124
+ return false;
125
+ if (!a.ok)
126
+ return true;
127
+ const dx = b.px - a.px;
128
+ const dy = b.py - a.py;
129
+ const length = Math.hypot(dx, dy) || 1;
130
+ if (Math.abs((m.px - a.px) * dy - (m.py - a.py) * dx) / length > TOLERANCE_PX)
131
+ return false;
132
+ let turn = Math.abs(Math.atan2(m.py - a.py, m.px - a.px) - Math.atan2(b.py - m.py, b.px - m.px));
133
+ if (turn > Math.PI)
134
+ turn = 2 * Math.PI - turn;
135
+ return turn < ANGLE_TOLERANCE;
136
+ }
137
+ // Two neighbours on opposite sides of the frame, with nothing between them that
138
+ // is between them: an asymptote, not a steep line.
139
+ function diverges(a, m, b, clip) {
140
+ const straddles = (a.py > clip.maxY && b.py < clip.minY) || (a.py < clip.minY && b.py > clip.maxY) ||
141
+ (a.px > clip.maxX && b.px < clip.minX) || (a.px < clip.minX && b.px > clip.maxX);
142
+ if (!straddles || m === null)
143
+ return false;
144
+ if (!m.ok)
145
+ return true;
146
+ return (m.ry < Math.min(a.ry, b.ry) || m.ry > Math.max(a.ry, b.ry) ||
147
+ m.rx < Math.min(a.rx, b.rx) || m.rx > Math.max(a.rx, b.rx));
148
+ }
149
+ function offFrame(sample, clip) {
150
+ return sample.py > clip.maxY || sample.py < clip.minY || sample.px > clip.maxX || sample.px < clip.minX;
151
+ }
152
+ function clampCoord(value) {
153
+ if (value > COORD_LIMIT)
154
+ return COORD_LIMIT;
155
+ if (value < -COORD_LIMIT)
156
+ return -COORD_LIMIT;
157
+ return value;
158
+ }
159
+ class CurvePen {
160
+ clip;
161
+ points = 0;
162
+ runs = [];
163
+ open = [];
164
+ cursor = null;
165
+ constructor(clip) {
166
+ this.clip = clip;
167
+ }
168
+ draw(a, b) {
169
+ const segment = clipSegment(a.px, a.py, b.px, b.py, this.clip);
170
+ if (!segment) {
171
+ this.break();
172
+ return;
173
+ }
174
+ const [start, end] = segment;
175
+ if (this.cursor && samePoint(this.cursor, start)) {
176
+ this.push(end);
177
+ }
178
+ else {
179
+ this.break();
180
+ this.push(start);
181
+ this.push(end);
182
+ }
183
+ this.cursor = end;
184
+ }
185
+ start(b) {
186
+ this.break();
187
+ if (!inside(b.px, b.py, this.clip))
188
+ return;
189
+ this.cursor = { x: b.px, y: b.py };
190
+ this.push(this.cursor);
191
+ }
192
+ break() {
193
+ if (this.open.length >= 2)
194
+ this.runs.push(this.open);
195
+ this.open = [];
196
+ this.cursor = null;
197
+ }
198
+ finish() {
199
+ this.break();
200
+ return this.runs;
201
+ }
202
+ push(point) {
203
+ this.open.push(point);
204
+ this.points++;
205
+ }
206
+ }
207
+ function samePoint(a, b) {
208
+ return Math.abs(a.x - b.x) < 0.1 && Math.abs(a.y - b.y) < 0.1;
209
+ }
210
+ function inside(x, y, clip) {
211
+ return x >= clip.minX && x <= clip.maxX && y >= clip.minY && y <= clip.maxY;
212
+ }
213
+ // Liang–Barsky: the part of a segment inside the clip, or null when none is.
214
+ function clipSegment(ax, ay, bx, by, clip) {
215
+ const dx = bx - ax;
216
+ const dy = by - ay;
217
+ let t0 = 0;
218
+ let t1 = 1;
219
+ const edges = [
220
+ [-dx, ax - clip.minX],
221
+ [dx, clip.maxX - ax],
222
+ [-dy, ay - clip.minY],
223
+ [dy, clip.maxY - ay],
224
+ ];
225
+ for (const [p, q] of edges) {
226
+ if (p === 0) {
227
+ if (q < 0)
228
+ return null;
229
+ continue;
230
+ }
231
+ const r = q / p;
232
+ if (p < 0) {
233
+ if (r > t1)
234
+ return null;
235
+ if (r > t0)
236
+ t0 = r;
237
+ }
238
+ else {
239
+ if (r < t0)
240
+ return null;
241
+ if (r < t1)
242
+ t1 = r;
243
+ }
244
+ }
245
+ return [
246
+ { x: ax + t0 * dx, y: ay + t0 * dy },
247
+ { x: ax + t1 * dx, y: ay + t1 * dy },
248
+ ];
249
+ }
250
+ //# sourceMappingURL=sampler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sampler.js","sourceRoot":"","sources":["../../src/kit/sampler.ts"],"names":[],"mappings":"AAkBA,kHAAkH;AACl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AC;IACX,IAAI,EAAE,GAAG,CAAC,CAAC;IACX,MAAM,KAAK,GAAuB;QAC9B,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC;QACrB,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QACpB,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC;QACrB,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;KACvB,CAAC;IACF,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACV,IAAI,CAAC,GAAG,CAAC;gBAAE,OAAO,IAAI,CAAC;YACvB,SAAS;QACb,CAAC;QACD,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAChB,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACR,IAAI,CAAC,GAAG,EAAE;gBAAE,OAAO,IAAI,CAAC;YACxB,IAAI,CAAC,GAAG,EAAE;gBAAE,EAAE,GAAG,CAAC,CAAC;QACvB,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,GAAG,EAAE;gBAAE,OAAO,IAAI,CAAC;YACxB,IAAI,CAAC,GAAG,EAAE;gBAAE,EAAE,GAAG,CAAC,CAAC;QACvB,CAAC;IACL,CAAC;IACD,OAAO;QACH,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;QACpC,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;KACvC,CAAC;AACN,CAAC","sourcesContent":["import type { Extents, Vector2 } from \"@motionscript/sdk\";\n\n/**\n * Turns a curve into the polylines that draw it: adaptively, so a straight\n * stretch costs two points and a tight bend as many as it needs, and broken\n * wherever the curve is, at an asymptote or the edge of its domain.\n */\n\n/** A curve's parameter to its pixel, written into `out`. `false` where the curve is undefined. */\nexport type CurveProjection = (t: number, out: Vector2) => boolean;\n\nexport interface SampleOptions {\n /** The equal steps the parameter range starts as, before any is split. */\n seeds?: number;\n /** A parameter step that is not split again, however bent. */\n minStep?: number;\n}\n\n/** Path coordinates are 32-bit floats in the renderer; past this a clamped point still clips to the same edge. */\nconst COORD_LIMIT = 16_000;\n/** How far, in pixels, the drawn chord may stray from the curve. */\nconst TOLERANCE_PX = 0.25;\n/** A turn, in radians, a chord is allowed to hide: what keeps a symmetric bump from reading as flat. */\nconst ANGLE_TOLERANCE = 0.05;\nconst MAX_DEPTH = 12;\nconst MAX_EVALUATIONS = 40_000;\nconst MAX_POINTS = 24_000;\n/** Bisections spent finding where a domain ends. */\nconst BOUNDARY_STEPS = 60;\nconst DEFAULT_SEEDS = 256;\n\ninterface Sample {\n t: number;\n px: number;\n py: number;\n /** The pixel before clamping: what tells an asymptote from a steep line. */\n rx: number;\n ry: number;\n ok: boolean;\n}\n\n// Midpoints are pooled: a refine is a depth-first walk, so a slot is free again\n// as soon as the seed interval it was taken for is done.\nconst arena: Sample[] = [];\nlet arenaMark = 0;\n\nfunction takeSample(): Sample {\n let slot = arena[arenaMark];\n if (slot === undefined) {\n slot = blank();\n arena.push(slot);\n }\n arenaMark++;\n return slot;\n}\n\nfunction blank(): Sample {\n return { t: 0, px: 0, py: 0, rx: 0, ry: 0, ok: false };\n}\n\nconst scratch: Vector2 = { x: 0, y: 0 };\n\n/** The runs of points that draw `project` over `[t0, t1]`, clipped to `clip`. */\nexport function sampleCurve(\n project: CurveProjection,\n t0: number,\n t1: number,\n clip: Extents,\n { seeds = DEFAULT_SEEDS, minStep = 0 }: SampleOptions = {},\n): Vector2[][] {\n if (!(t1 > t0) || !Number.isFinite(t0) || !Number.isFinite(t1)) return [];\n const pen = new CurvePen(clip);\n let spent = 0;\n\n const write = (slot: Sample, t: number): Sample => {\n const defined = project(t, scratch);\n spent++;\n const ok = defined && Number.isFinite(scratch.x) && Number.isFinite(scratch.y);\n slot.t = t;\n slot.rx = ok ? scratch.x : 0;\n slot.ry = ok ? scratch.y : 0;\n slot.px = clampCoord(slot.rx);\n slot.py = clampCoord(slot.ry);\n slot.ok = ok;\n return slot;\n };\n const at = (t: number): Sample => write(takeSample(), t);\n\n // The last defined point before `to`, which is not: where `sqrt(x)` meets its axis.\n const edgeOf = (from: Sample, to: Sample): Sample => {\n let inside = from;\n let outsideT = to.t;\n for (let i = 0; i < BOUNDARY_STEPS; i++) {\n if (spent >= MAX_EVALUATIONS || offFrame(inside, clip)) break;\n const midT = (inside.t + outsideT) / 2;\n if (midT === inside.t || midT === outsideT) break;\n const mid = at(midT);\n if (!mid.ok) {\n outsideT = midT;\n continue;\n }\n const settled = Math.abs(mid.px - inside.px) < TOLERANCE_PX && Math.abs(mid.py - inside.py) < TOLERANCE_PX;\n inside = mid;\n if (settled) break;\n }\n return inside;\n };\n\n const emit = (a: Sample, m: Sample | null, b: Sample, floored: boolean): void => {\n if (a.ok && b.ok) {\n if (floored && diverges(a, m, b, clip)) pen.break();\n else pen.draw(a, b);\n return;\n }\n if (a.ok) {\n const edge = edgeOf(a, b);\n if (edge.t !== a.t) pen.draw(a, edge);\n pen.break();\n return;\n }\n pen.break();\n if (b.ok) {\n const edge = edgeOf(b, a);\n if (edge.t !== b.t) pen.draw(edge, b);\n else pen.start(b);\n }\n };\n\n const refine = (a: Sample, b: Sample, depth: number): void => {\n if (spent >= MAX_EVALUATIONS || pen.points >= MAX_POINTS) {\n emit(a, null, b, false);\n return;\n }\n const m = at((a.t + b.t) / 2);\n const floored = depth >= MAX_DEPTH || b.t - a.t <= minStep;\n if (floored || flat(a, m, b)) {\n emit(a, m, b, floored);\n return;\n }\n refine(a, m, depth + 1);\n refine(m, b, depth + 1);\n };\n\n const count = Math.max(1, Math.round(seeds));\n const step = (t1 - t0) / count;\n const ends: [Sample, Sample] = [blank(), blank()];\n let previous = write(ends[0], t0);\n for (let i = 1; i <= count; i++) {\n const next = write(ends[i & 1], i === count ? t1 : t0 + i * step);\n arenaMark = 0;\n refine(previous, next, 0);\n previous = next;\n }\n arenaMark = 0;\n return pen.finish();\n}\n\nfunction flat(a: Sample, m: Sample, b: Sample): boolean {\n if (a.ok !== m.ok || m.ok !== b.ok) return false;\n if (!a.ok) return true;\n const dx = b.px - a.px;\n const dy = b.py - a.py;\n const length = Math.hypot(dx, dy) || 1;\n if (Math.abs((m.px - a.px) * dy - (m.py - a.py) * dx) / length > TOLERANCE_PX) return false;\n let turn = Math.abs(Math.atan2(m.py - a.py, m.px - a.px) - Math.atan2(b.py - m.py, b.px - m.px));\n if (turn > Math.PI) turn = 2 * Math.PI - turn;\n return turn < ANGLE_TOLERANCE;\n}\n\n// Two neighbours on opposite sides of the frame, with nothing between them that\n// is between them: an asymptote, not a steep line.\nfunction diverges(a: Sample, m: Sample | null, b: Sample, clip: Extents): boolean {\n const straddles =\n (a.py > clip.maxY && b.py < clip.minY) || (a.py < clip.minY && b.py > clip.maxY) ||\n (a.px > clip.maxX && b.px < clip.minX) || (a.px < clip.minX && b.px > clip.maxX);\n if (!straddles || m === null) return false;\n if (!m.ok) return true;\n return (\n m.ry < Math.min(a.ry, b.ry) || m.ry > Math.max(a.ry, b.ry) ||\n m.rx < Math.min(a.rx, b.rx) || m.rx > Math.max(a.rx, b.rx)\n );\n}\n\nfunction offFrame(sample: Sample, clip: Extents): boolean {\n return sample.py > clip.maxY || sample.py < clip.minY || sample.px > clip.maxX || sample.px < clip.minX;\n}\n\nfunction clampCoord(value: number): number {\n if (value > COORD_LIMIT) return COORD_LIMIT;\n if (value < -COORD_LIMIT) return -COORD_LIMIT;\n return value;\n}\n\nclass CurvePen {\n points = 0;\n private readonly runs: Vector2[][] = [];\n private open: Vector2[] = [];\n private cursor: Vector2 | null = null;\n\n constructor(private readonly clip: Extents) {}\n\n draw(a: Sample, b: Sample): void {\n const segment = clipSegment(a.px, a.py, b.px, b.py, this.clip);\n if (!segment) {\n this.break();\n return;\n }\n const [start, end] = segment;\n if (this.cursor && samePoint(this.cursor, start)) {\n this.push(end);\n } else {\n this.break();\n this.push(start);\n this.push(end);\n }\n this.cursor = end;\n }\n\n start(b: Sample): void {\n this.break();\n if (!inside(b.px, b.py, this.clip)) return;\n this.cursor = { x: b.px, y: b.py };\n this.push(this.cursor);\n }\n\n break(): void {\n if (this.open.length >= 2) this.runs.push(this.open);\n this.open = [];\n this.cursor = null;\n }\n\n finish(): Vector2[][] {\n this.break();\n return this.runs;\n }\n\n private push(point: Vector2): void {\n this.open.push(point);\n this.points++;\n }\n}\n\nfunction samePoint(a: Vector2, b: Vector2): boolean {\n return Math.abs(a.x - b.x) < 0.1 && Math.abs(a.y - b.y) < 0.1;\n}\n\nfunction inside(x: number, y: number, clip: Extents): boolean {\n return x >= clip.minX && x <= clip.maxX && y >= clip.minY && y <= clip.maxY;\n}\n\n// Liang–Barsky: the part of a segment inside the clip, or null when none is.\nfunction clipSegment(ax: number, ay: number, bx: number, by: number, clip: Extents): [Vector2, Vector2] | null {\n const dx = bx - ax;\n const dy = by - ay;\n let t0 = 0;\n let t1 = 1;\n const edges: [number, number][] = [\n [-dx, ax - clip.minX],\n [dx, clip.maxX - ax],\n [-dy, ay - clip.minY],\n [dy, clip.maxY - ay],\n ];\n for (const [p, q] of edges) {\n if (p === 0) {\n if (q < 0) return null;\n continue;\n }\n const r = q / p;\n if (p < 0) {\n if (r > t1) return null;\n if (r > t0) t0 = r;\n } else {\n if (r < t0) return null;\n if (r < t1) t1 = r;\n }\n }\n return [\n { x: ax + t0 * dx, y: ay + t0 * dy },\n { x: ax + t1 * dx, y: ay + t1 * dy },\n ];\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import { type Color, type Fill, type FillResolved, type NormalizedColor } from "@motionscript/sdk";
2
+ /** A run of colours a value is read off, lowest first: a surface's height, a field's strength. */
3
+ export declare function readScale(value: readonly Color[] | undefined): NormalizedColor[];
4
+ export declare function lerpScale(from: NormalizedColor[], to: NormalizedColor[], t: number): NormalizedColor[];
5
+ /** The colour `share` of the way along `scale`, 0 to 1. */
6
+ export declare function colorAt(scale: readonly NormalizedColor[], share: number): NormalizedColor;
7
+ /** A run of paints a value is read off, lowest first: a field's strength. Every entry is kept as written. */
8
+ export declare function readFillScale(value: readonly Fill[] | undefined): FillResolved[][];
9
+ export declare function lerpFillScale(from: FillResolved[][], to: FillResolved[][], t: number): FillResolved[][];
10
+ /** The paint `share` of the way along `scale`, 0 to 1. */
11
+ export declare function fillAt(scale: readonly FillResolved[][], share: number): FillResolved[];
12
+ //# sourceMappingURL=scale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scale.d.ts","sourceRoot":"","sources":["../../src/kit/scale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,KAAK,EAAE,KAAK,IAAI,EAAE,KAAK,YAAY,EAAE,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGtH,kGAAkG;AAElG,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,KAAK,EAAE,GAAG,SAAS,GAAG,eAAe,EAAE,CAEhF;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,eAAe,EAAE,EAAE,EAAE,EAAE,eAAe,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,eAAe,EAAE,CAGtG;AAED,2DAA2D;AAC3D,wBAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,eAAe,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,eAAe,CAKzF;AAED,6GAA6G;AAC7G,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,SAAS,GAAG,YAAY,EAAE,EAAE,CAElF;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,YAAY,EAAE,EAAE,CAGvG;AAED,0DAA0D;AAC1D,wBAAgB,MAAM,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,EAAE,CAKtF"}
@@ -0,0 +1,37 @@
1
+ import { colorOps, fillOps } from "@motionscript/sdk";
2
+ import { clamp } from "./geometry.js";
3
+ /** A run of colours a value is read off, lowest first: a surface's height, a field's strength. */
4
+ export function readScale(value) {
5
+ return (value ?? []).map((color) => colorOps.resolve(color));
6
+ }
7
+ export function lerpScale(from, to, t) {
8
+ if (from.length !== to.length)
9
+ return t < 1 ? from : to;
10
+ return to.map((color, index) => colorOps.lerp(from[index], color, t));
11
+ }
12
+ /** The colour `share` of the way along `scale`, 0 to 1. */
13
+ export function colorAt(scale, share) {
14
+ if (scale.length === 1)
15
+ return scale[0];
16
+ const at = clamp(share, 0, 1) * (scale.length - 1);
17
+ const index = Math.min(scale.length - 2, Math.floor(at));
18
+ return colorOps.lerp(scale[index], scale[index + 1], at - index);
19
+ }
20
+ /** A run of paints a value is read off, lowest first: a field's strength. Every entry is kept as written. */
21
+ export function readFillScale(value) {
22
+ return (Array.isArray(value) ? value : []).map((fill) => fillOps.resolve(fill ?? []));
23
+ }
24
+ export function lerpFillScale(from, to, t) {
25
+ if (from.length !== to.length)
26
+ return t < 1 ? from : to;
27
+ return to.map((fill, index) => fillOps.lerp(from[index], fill, t));
28
+ }
29
+ /** The paint `share` of the way along `scale`, 0 to 1. */
30
+ export function fillAt(scale, share) {
31
+ if (scale.length === 1)
32
+ return scale[0];
33
+ const at = clamp(share, 0, 1) * (scale.length - 1);
34
+ const index = Math.min(scale.length - 2, Math.floor(at));
35
+ return fillOps.lerp(scale[index], scale[index + 1], at - index);
36
+ }
37
+ //# sourceMappingURL=scale.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scale.js","sourceRoot":"","sources":["../../src/kit/scale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAk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color, type Fill, type FillResolved, type NormalizedColor } from \"@motionscript/sdk\";\nimport { clamp } from \"./geometry\";\n\n/** A run of colours a value is read off, lowest first: a surface's height, a field's strength. */\n\nexport function readScale(value: readonly Color[] | undefined): NormalizedColor[] {\n return (value ?? []).map((color) => colorOps.resolve(color));\n}\n\nexport function lerpScale(from: NormalizedColor[], to: NormalizedColor[], t: number): NormalizedColor[] {\n if (from.length !== to.length) return t < 1 ? from : to;\n return to.map((color, index) => colorOps.lerp(from[index], color, t));\n}\n\n/** The colour `share` of the way along `scale`, 0 to 1. */\nexport function colorAt(scale: readonly NormalizedColor[], share: number): NormalizedColor {\n if (scale.length === 1) return scale[0];\n const at = clamp(share, 0, 1) * (scale.length - 1);\n const index = Math.min(scale.length - 2, Math.floor(at));\n return colorOps.lerp(scale[index], scale[index + 1], at - index);\n}\n\n/** A run of paints a value is read off, lowest first: a field's strength. Every entry is kept as written. */\nexport function readFillScale(value: readonly Fill[] | undefined): FillResolved[][] {\n return (Array.isArray(value) ? value : []).map((fill) => fillOps.resolve(fill ?? []));\n}\n\nexport function lerpFillScale(from: FillResolved[][], to: FillResolved[][], t: number): FillResolved[][] {\n if (from.length !== to.length) return t < 1 ? from : to;\n return to.map((fill, index) => fillOps.lerp(from[index], fill, t));\n}\n\n/** The paint `share` of the way along `scale`, 0 to 1. */\nexport function fillAt(scale: readonly FillResolved[][], share: number): FillResolved[] {\n if (scale.length === 1) return scale[0];\n const at = clamp(share, 0, 1) * (scale.length - 1);\n const index = Math.min(scale.length - 2, Math.floor(at));\n return fillOps.lerp(scale[index], scale[index + 1], at - index);\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import type { Interval } from "./coords.js";
2
+ import type { ExpressionScope } from "./expression.js";
3
+ /** What a plot's equation, domain and named values are held as, and how each tweens: shared by every plot, 2D and 3D. */
4
+ /** An equation on its way to another: both are drawn, `t` of the way across. */
5
+ export interface PlotSource {
6
+ source: string;
7
+ blend?: {
8
+ from: string;
9
+ t: number;
10
+ };
11
+ }
12
+ export declare function readSource(value: string | PlotSource | undefined): PlotSource;
13
+ export declare function lerpSource(from: PlotSource, to: PlotSource, t: number): PlotSource;
14
+ export declare function lerpDomain(from: Interval | null, to: Interval | null, t: number): Interval | null;
15
+ /** What a named value is until it is given one. */
16
+ export declare const UNSET_PARAM = 1;
17
+ export declare function lerpParams(from: ExpressionScope, to: ExpressionScope, t: number): ExpressionScope;
18
+ /** `params` with every name of `names` given a value, so one nobody has set yet still draws. */
19
+ export declare function scopeFor(names: readonly string[], params: ExpressionScope): ExpressionScope;
20
+ /** A string as a number that changes when it does: what a geometry's `revision` wants. */
21
+ export declare function revisionOf(key: string): number;
22
+ //# sourceMappingURL=source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/kit/source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,yHAAyH;AAEzH,gFAAgF;AAChF,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACvC;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,GAAG,UAAU,CAG7E;AAGD,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,GAAG,UAAU,CAGlF;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,EAAE,EAAE,EAAE,QAAQ,GAAG,IAAI,EAAE,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAGjG;AAED,mDAAmD;AACnD,eAAO,MAAM,WAAW,IAAI,CAAC;AAE7B,wBAAgB,UAAU,CAAC,IAAI,EAAE,eAAe,EAAE,EAAE,EAAE,eAAe,EAAE,CAAC,EAAE,MAAM,GAAG,eAAe,CAOjG;AAED,gGAAgG;AAChG,wBAAgB,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,eAAe,GAAG,eAAe,CAM3F;AAED,0FAA0F;AAC1F,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAO9C"}
@@ -0,0 +1,45 @@
1
+ export function readSource(value) {
2
+ if (typeof value === "string")
3
+ return { source: value };
4
+ return value ?? { source: "" };
5
+ }
6
+ // Mid-tween the prop holds both equations, so a seek restores the blend with it.
7
+ export function lerpSource(from, to, t) {
8
+ if (t <= 0 || from.source === to.source)
9
+ return t <= 0 ? from : to;
10
+ return t >= 1 ? to : { source: to.source, blend: { from: from.source, t } };
11
+ }
12
+ export function lerpDomain(from, to, t) {
13
+ if (!from || !to)
14
+ return t < 1 ? from : to;
15
+ return [from[0] + (to[0] - from[0]) * t, from[1] + (to[1] - from[1]) * t];
16
+ }
17
+ /** What a named value is until it is given one. */
18
+ export const UNSET_PARAM = 1;
19
+ export function lerpParams(from, to, t) {
20
+ const out = { ...from };
21
+ for (const [name, value] of Object.entries(to)) {
22
+ const start = from[name] ?? UNSET_PARAM;
23
+ out[name] = start + (value - start) * t;
24
+ }
25
+ return out;
26
+ }
27
+ /** `params` with every name of `names` given a value, so one nobody has set yet still draws. */
28
+ export function scopeFor(names, params) {
29
+ let filled = null;
30
+ for (const name of names) {
31
+ if (typeof params[name] !== "number")
32
+ (filled ??= { ...params })[name] = UNSET_PARAM;
33
+ }
34
+ return filled ?? params;
35
+ }
36
+ /** A string as a number that changes when it does: what a geometry's `revision` wants. */
37
+ export function revisionOf(key) {
38
+ let hash = 0x811c9dc5;
39
+ for (let i = 0; i < key.length; i++) {
40
+ hash ^= key.charCodeAt(i);
41
+ hash = Math.imul(hash, 0x01000193);
42
+ }
43
+ return hash >>> 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\"./coords\";\nimport type { ExpressionScope } from \"./expression\";\n\n/** What a plot's equation, domain and named values are held as, and how each tweens: shared by every plot, 2D and 3D. */\n\n/** An equation on its way to another: both are drawn, `t` of the way across. */\nexport interface PlotSource {\n source: string;\n blend?: { from: string; t: number };\n}\n\nexport function readSource(value: string | PlotSource | undefined): PlotSource {\n if (typeof value === \"string\") return { source: value };\n return value ?? { source: \"\" };\n}\n\n// Mid-tween the prop holds both equations, so a seek restores the blend with it.\nexport function lerpSource(from: PlotSource, to: PlotSource, t: number): PlotSource {\n if (t <= 0 || from.source === to.source) return t <= 0 ? from : to;\n return t >= 1 ? to : { source: to.source, blend: { from: from.source, t } };\n}\n\nexport function lerpDomain(from: Interval | null, to: Interval | null, t: number): Interval | null {\n if (!from || !to) return t < 1 ? from : to;\n return [from[0] + (to[0] - from[0]) * t, from[1] + (to[1] - from[1]) * t];\n}\n\n/** What a named value is until it is given one. */\nexport const UNSET_PARAM = 1;\n\nexport function lerpParams(from: ExpressionScope, to: ExpressionScope, t: number): ExpressionScope {\n const out: Record<string, number> = { ...from };\n for (const [name, value] of Object.entries(to)) {\n const start = from[name] ?? UNSET_PARAM;\n out[name] = start + (value - start) * t;\n }\n return out;\n}\n\n/** `params` with every name of `names` given a value, so one nobody has set yet still draws. */\nexport function scopeFor(names: readonly string[], params: ExpressionScope): ExpressionScope {\n let filled: Record<string, number> | null = null;\n for (const name of names) {\n if (typeof params[name] !== \"number\") (filled ??= { ...params })[name] = UNSET_PARAM;\n }\n return filled ?? params;\n}\n\n/** A string as a number that changes when it does: what a geometry's `revision` wants. */\nexport function revisionOf(key: string): number {\n let hash = 0x811c9dc5;\n for (let i = 0; i < key.length; i++) {\n hash ^= key.charCodeAt(i);\n hash = Math.imul(hash, 0x01000193);\n }\n return hash >>> 0;\n}\n"]}