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

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 (322) hide show
  1. package/CHANGELOG.md +92 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +48 -0
  4. package/README.md +385 -3
  5. package/dist/annotate/angle-mark.d.ts +46 -0
  6. package/dist/annotate/angle-mark.d.ts.map +1 -0
  7. package/dist/annotate/angle-mark.js +132 -0
  8. package/dist/annotate/angle-mark.js.map +1 -0
  9. package/dist/annotate/curly-brace.d.ts +46 -0
  10. package/dist/annotate/curly-brace.d.ts.map +1 -0
  11. package/dist/annotate/curly-brace.js +114 -0
  12. package/dist/annotate/curly-brace.js.map +1 -0
  13. package/dist/annotate/emphasis-mark.d.ts +20 -0
  14. package/dist/annotate/emphasis-mark.d.ts.map +1 -0
  15. package/dist/annotate/emphasis-mark.js +81 -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-3GJB6AVO.js +2 -0
  19. package/dist/browser/chunks/chunk-3GJB6AVO.js.map +7 -0
  20. package/dist/browser/chunks/chunk-D5WHCVBC.js +2 -0
  21. package/dist/browser/chunks/chunk-D5WHCVBC.js.map +7 -0
  22. package/dist/browser/chunks/chunk-WL4KEX7Y.js +2 -0
  23. package/dist/browser/chunks/chunk-WL4KEX7Y.js.map +7 -0
  24. package/dist/browser/chunks/mathjax-DNP3YRES.js +61 -0
  25. package/dist/browser/chunks/mathjax-DNP3YRES.js.map +7 -0
  26. package/dist/browser/index.js +2 -0
  27. package/dist/browser/index.js.map +7 -0
  28. package/dist/browser/kit.js +2 -0
  29. package/dist/browser/kit.js.map +7 -0
  30. package/dist/browser/manifest.json +30 -0
  31. package/dist/browser/tex.js +2 -0
  32. package/dist/browser/tex.js.map +7 -0
  33. package/dist/engine.d.ts +64 -0
  34. package/dist/engine.d.ts.map +1 -0
  35. package/dist/engine.js +42 -0
  36. package/dist/engine.js.map +1 -0
  37. package/dist/index.d.ts +30 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +30 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/kit/brace.d.ts +8 -0
  42. package/dist/kit/brace.d.ts.map +1 -0
  43. package/dist/kit/brace.js +36 -0
  44. package/dist/kit/brace.js.map +1 -0
  45. package/dist/kit/cache.d.ts +30 -0
  46. package/dist/kit/cache.d.ts.map +1 -0
  47. package/dist/kit/cache.js +53 -0
  48. package/dist/kit/cache.js.map +1 -0
  49. package/dist/kit/contour.d.ts +8 -0
  50. package/dist/kit/contour.d.ts.map +1 -0
  51. package/dist/kit/contour.js +93 -0
  52. package/dist/kit/contour.js.map +1 -0
  53. package/dist/kit/coords.d.ts +69 -0
  54. package/dist/kit/coords.d.ts.map +1 -0
  55. package/dist/kit/coords.js +224 -0
  56. package/dist/kit/coords.js.map +1 -0
  57. package/dist/kit/curve.d.ts +17 -0
  58. package/dist/kit/curve.d.ts.map +1 -0
  59. package/dist/kit/curve.js +22 -0
  60. package/dist/kit/curve.js.map +1 -0
  61. package/dist/kit/equation.d.ts +61 -0
  62. package/dist/kit/equation.d.ts.map +1 -0
  63. package/dist/kit/equation.js +168 -0
  64. package/dist/kit/equation.js.map +1 -0
  65. package/dist/kit/equation3d.d.ts +50 -0
  66. package/dist/kit/equation3d.d.ts.map +1 -0
  67. package/dist/kit/equation3d.js +103 -0
  68. package/dist/kit/equation3d.js.map +1 -0
  69. package/dist/kit/expression.d.ts +35 -0
  70. package/dist/kit/expression.d.ts.map +1 -0
  71. package/dist/kit/expression.js +124 -0
  72. package/dist/kit/expression.js.map +1 -0
  73. package/dist/kit/field-mark.d.ts +58 -0
  74. package/dist/kit/field-mark.d.ts.map +1 -0
  75. package/dist/kit/field-mark.js +129 -0
  76. package/dist/kit/field-mark.js.map +1 -0
  77. package/dist/kit/field.d.ts +14 -0
  78. package/dist/kit/field.d.ts.map +1 -0
  79. package/dist/kit/field.js +46 -0
  80. package/dist/kit/field.js.map +1 -0
  81. package/dist/kit/follow.d.ts +71 -0
  82. package/dist/kit/follow.d.ts.map +1 -0
  83. package/dist/kit/follow.js +159 -0
  84. package/dist/kit/follow.js.map +1 -0
  85. package/dist/kit/furniture.d.ts +30 -0
  86. package/dist/kit/furniture.d.ts.map +1 -0
  87. package/dist/kit/furniture.js +87 -0
  88. package/dist/kit/furniture.js.map +1 -0
  89. package/dist/kit/geometry.d.ts +13 -0
  90. package/dist/kit/geometry.d.ts.map +1 -0
  91. package/dist/kit/geometry.js +54 -0
  92. package/dist/kit/geometry.js.map +1 -0
  93. package/dist/kit/mark.d.ts +47 -0
  94. package/dist/kit/mark.d.ts.map +1 -0
  95. package/dist/kit/mark.js +103 -0
  96. package/dist/kit/mark.js.map +1 -0
  97. package/dist/kit/part-fills.d.ts +23 -0
  98. package/dist/kit/part-fills.d.ts.map +1 -0
  99. package/dist/kit/part-fills.js +46 -0
  100. package/dist/kit/part-fills.js.map +1 -0
  101. package/dist/kit/place.d.ts +18 -0
  102. package/dist/kit/place.d.ts.map +1 -0
  103. package/dist/kit/place.js +68 -0
  104. package/dist/kit/place.js.map +1 -0
  105. package/dist/kit/placement.d.ts +8 -0
  106. package/dist/kit/placement.d.ts.map +1 -0
  107. package/dist/kit/placement.js +8 -0
  108. package/dist/kit/placement.js.map +1 -0
  109. package/dist/kit/sampler.d.ts +17 -0
  110. package/dist/kit/sampler.d.ts.map +1 -0
  111. package/dist/kit/sampler.js +250 -0
  112. package/dist/kit/sampler.js.map +1 -0
  113. package/dist/kit/scale.d.ts +12 -0
  114. package/dist/kit/scale.d.ts.map +1 -0
  115. package/dist/kit/scale.js +37 -0
  116. package/dist/kit/scale.js.map +1 -0
  117. package/dist/kit/source.d.ts +22 -0
  118. package/dist/kit/source.d.ts.map +1 -0
  119. package/dist/kit/source.js +45 -0
  120. package/dist/kit/source.js.map +1 -0
  121. package/dist/kit/system.d.ts +33 -0
  122. package/dist/kit/system.d.ts.map +1 -0
  123. package/dist/kit/system.js +67 -0
  124. package/dist/kit/system.js.map +1 -0
  125. package/dist/kit/ticks.d.ts +19 -0
  126. package/dist/kit/ticks.d.ts.map +1 -0
  127. package/dist/kit/ticks.js +78 -0
  128. package/dist/kit/ticks.js.map +1 -0
  129. package/dist/kit/withdrawn.d.ts +9 -0
  130. package/dist/kit/withdrawn.d.ts.map +1 -0
  131. package/dist/kit/withdrawn.js +9 -0
  132. package/dist/kit/withdrawn.js.map +1 -0
  133. package/dist/marks/curve-area.d.ts +32 -0
  134. package/dist/marks/curve-area.d.ts.map +1 -0
  135. package/dist/marks/curve-area.js +82 -0
  136. package/dist/marks/curve-area.js.map +1 -0
  137. package/dist/marks/drop-lines.d.ts +22 -0
  138. package/dist/marks/drop-lines.d.ts.map +1 -0
  139. package/dist/marks/drop-lines.js +58 -0
  140. package/dist/marks/drop-lines.js.map +1 -0
  141. package/dist/marks/plot-point.d.ts +35 -0
  142. package/dist/marks/plot-point.d.ts.map +1 -0
  143. package/dist/marks/plot-point.js +97 -0
  144. package/dist/marks/plot-point.js.map +1 -0
  145. package/dist/marks/riemann-sum.d.ts +37 -0
  146. package/dist/marks/riemann-sum.d.ts.map +1 -0
  147. package/dist/marks/riemann-sum.js +91 -0
  148. package/dist/marks/riemann-sum.js.map +1 -0
  149. package/dist/marks/tangent-line.d.ts +27 -0
  150. package/dist/marks/tangent-line.d.ts.map +1 -0
  151. package/dist/marks/tangent-line.js +103 -0
  152. package/dist/marks/tangent-line.js.map +1 -0
  153. package/dist/marks/vector-arrow.d.ts +32 -0
  154. package/dist/marks/vector-arrow.d.ts.map +1 -0
  155. package/dist/marks/vector-arrow.js +87 -0
  156. package/dist/marks/vector-arrow.js.map +1 -0
  157. package/dist/nodes.d.ts +35 -0
  158. package/dist/nodes.d.ts.map +1 -0
  159. package/dist/nodes.js +63 -0
  160. package/dist/nodes.js.map +1 -0
  161. package/dist/plots/function-plot.d.ts +67 -0
  162. package/dist/plots/function-plot.d.ts.map +1 -0
  163. package/dist/plots/function-plot.js +215 -0
  164. package/dist/plots/function-plot.js.map +1 -0
  165. package/dist/plots/points-plot.d.ts +28 -0
  166. package/dist/plots/points-plot.d.ts.map +1 -0
  167. package/dist/plots/points-plot.js +99 -0
  168. package/dist/plots/points-plot.js.map +1 -0
  169. package/dist/plots/stream-lines.d.ts +35 -0
  170. package/dist/plots/stream-lines.d.ts.map +1 -0
  171. package/dist/plots/stream-lines.js +141 -0
  172. package/dist/plots/stream-lines.js.map +1 -0
  173. package/dist/plots/traced-path.d.ts +31 -0
  174. package/dist/plots/traced-path.d.ts.map +1 -0
  175. package/dist/plots/traced-path.js +56 -0
  176. package/dist/plots/traced-path.js.map +1 -0
  177. package/dist/plots/vector-field.d.ts +23 -0
  178. package/dist/plots/vector-field.d.ts.map +1 -0
  179. package/dist/plots/vector-field.js +91 -0
  180. package/dist/plots/vector-field.js.map +1 -0
  181. package/dist/structures/graph-layout.d.ts +11 -0
  182. package/dist/structures/graph-layout.d.ts.map +1 -0
  183. package/dist/structures/graph-layout.js +135 -0
  184. package/dist/structures/graph-layout.js.map +1 -0
  185. package/dist/structures/network-graph.d.ts +83 -0
  186. package/dist/structures/network-graph.d.ts.map +1 -0
  187. package/dist/structures/network-graph.js +289 -0
  188. package/dist/structures/network-graph.js.map +1 -0
  189. package/dist/structures/sample-space.d.ts +62 -0
  190. package/dist/structures/sample-space.d.ts.map +1 -0
  191. package/dist/structures/sample-space.js +199 -0
  192. package/dist/structures/sample-space.js.map +1 -0
  193. package/dist/systems/axes2d.d.ts +75 -0
  194. package/dist/systems/axes2d.d.ts.map +1 -0
  195. package/dist/systems/axes2d.js +193 -0
  196. package/dist/systems/axes2d.js.map +1 -0
  197. package/dist/systems/number-line.d.ts +49 -0
  198. package/dist/systems/number-line.d.ts.map +1 -0
  199. package/dist/systems/number-line.js +127 -0
  200. package/dist/systems/number-line.js.map +1 -0
  201. package/dist/systems/number-plane.d.ts +59 -0
  202. package/dist/systems/number-plane.d.ts.map +1 -0
  203. package/dist/systems/number-plane.js +193 -0
  204. package/dist/systems/number-plane.js.map +1 -0
  205. package/dist/systems/polar-plane.d.ts +48 -0
  206. package/dist/systems/polar-plane.d.ts.map +1 -0
  207. package/dist/systems/polar-plane.js +165 -0
  208. package/dist/systems/polar-plane.js.map +1 -0
  209. package/dist/tex/geometry.d.ts +85 -0
  210. package/dist/tex/geometry.d.ts.map +1 -0
  211. package/dist/tex/geometry.js +632 -0
  212. package/dist/tex/geometry.js.map +1 -0
  213. package/dist/tex/index.d.ts +11 -0
  214. package/dist/tex/index.d.ts.map +1 -0
  215. package/dist/tex/index.js +9 -0
  216. package/dist/tex/index.js.map +1 -0
  217. package/dist/tex/mathjax.d.ts +33 -0
  218. package/dist/tex/mathjax.d.ts.map +1 -0
  219. package/dist/tex/mathjax.js +74 -0
  220. package/dist/tex/mathjax.js.map +1 -0
  221. package/dist/tex/matrix.d.ts +31 -0
  222. package/dist/tex/matrix.d.ts.map +1 -0
  223. package/dist/tex/matrix.js +73 -0
  224. package/dist/tex/matrix.js.map +1 -0
  225. package/dist/tex/node.d.ts +215 -0
  226. package/dist/tex/node.d.ts.map +1 -0
  227. package/dist/tex/node.js +595 -0
  228. package/dist/tex/node.js.map +1 -0
  229. package/dist/tex/tween.d.ts +50 -0
  230. package/dist/tex/tween.d.ts.map +1 -0
  231. package/dist/tex/tween.js +253 -0
  232. package/dist/tex/tween.js.map +1 -0
  233. package/dist/three/axes3d.d.ts +87 -0
  234. package/dist/three/axes3d.d.ts.map +1 -0
  235. package/dist/three/axes3d.js +228 -0
  236. package/dist/three/axes3d.js.map +1 -0
  237. package/dist/three/curve-plot3d.d.ts +60 -0
  238. package/dist/three/curve-plot3d.d.ts.map +1 -0
  239. package/dist/three/curve-plot3d.js +143 -0
  240. package/dist/three/curve-plot3d.js.map +1 -0
  241. package/dist/three/label3d.d.ts +11 -0
  242. package/dist/three/label3d.d.ts.map +1 -0
  243. package/dist/three/label3d.js +40 -0
  244. package/dist/three/label3d.js.map +1 -0
  245. package/dist/three/plot-point3d.d.ts +26 -0
  246. package/dist/three/plot-point3d.d.ts.map +1 -0
  247. package/dist/three/plot-point3d.js +60 -0
  248. package/dist/three/plot-point3d.js.map +1 -0
  249. package/dist/three/space.d.ts +28 -0
  250. package/dist/three/space.d.ts.map +1 -0
  251. package/dist/three/space.js +47 -0
  252. package/dist/three/space.js.map +1 -0
  253. package/dist/three/surface-plot3d.d.ts +80 -0
  254. package/dist/three/surface-plot3d.d.ts.map +1 -0
  255. package/dist/three/surface-plot3d.js +290 -0
  256. package/dist/three/surface-plot3d.js.map +1 -0
  257. package/dist/three/vector-arrow3d.d.ts +25 -0
  258. package/dist/three/vector-arrow3d.d.ts.map +1 -0
  259. package/dist/three/vector-arrow3d.js +72 -0
  260. package/dist/three/vector-arrow3d.js.map +1 -0
  261. package/package.json +79 -3
  262. package/registry.json +251 -0
  263. package/src/annotate/angle-mark.ts +147 -0
  264. package/src/annotate/curly-brace.ts +126 -0
  265. package/src/annotate/emphasis-mark.ts +89 -0
  266. package/src/engine.ts +72 -0
  267. package/src/index.ts +29 -0
  268. package/src/kit/brace.ts +37 -0
  269. package/src/kit/cache.ts +61 -0
  270. package/src/kit/contour.ts +94 -0
  271. package/src/kit/coords.ts +278 -0
  272. package/src/kit/curve.ts +29 -0
  273. package/src/kit/equation.ts +181 -0
  274. package/src/kit/equation3d.ts +137 -0
  275. package/src/kit/expression.ts +159 -0
  276. package/src/kit/field-mark.ts +155 -0
  277. package/src/kit/field.ts +50 -0
  278. package/src/kit/follow.ts +203 -0
  279. package/src/kit/furniture.ts +108 -0
  280. package/src/kit/geometry.ts +49 -0
  281. package/src/kit/mark.ts +131 -0
  282. package/src/kit/part-fills.ts +61 -0
  283. package/src/kit/place.ts +101 -0
  284. package/src/kit/placement.ts +8 -0
  285. package/src/kit/sampler.ts +281 -0
  286. package/src/kit/scale.ts +39 -0
  287. package/src/kit/source.ts +57 -0
  288. package/src/kit/system.ts +99 -0
  289. package/src/kit/ticks.ts +85 -0
  290. package/src/kit/withdrawn.ts +8 -0
  291. package/src/marks/curve-area.ts +89 -0
  292. package/src/marks/drop-lines.ts +63 -0
  293. package/src/marks/plot-point.ts +107 -0
  294. package/src/marks/riemann-sum.ts +98 -0
  295. package/src/marks/tangent-line.ts +103 -0
  296. package/src/marks/vector-arrow.ts +98 -0
  297. package/src/nodes.ts +63 -0
  298. package/src/plots/function-plot.ts +236 -0
  299. package/src/plots/points-plot.ts +107 -0
  300. package/src/plots/stream-lines.ts +151 -0
  301. package/src/plots/traced-path.ts +52 -0
  302. package/src/plots/vector-field.ts +88 -0
  303. package/src/structures/graph-layout.ts +145 -0
  304. package/src/structures/network-graph.ts +308 -0
  305. package/src/structures/sample-space.ts +209 -0
  306. package/src/systems/axes2d.ts +217 -0
  307. package/src/systems/number-line.ts +131 -0
  308. package/src/systems/number-plane.ts +203 -0
  309. package/src/systems/polar-plane.ts +176 -0
  310. package/src/tex/geometry.ts +703 -0
  311. package/src/tex/index.ts +14 -0
  312. package/src/tex/mathjax.ts +82 -0
  313. package/src/tex/matrix.ts +75 -0
  314. package/src/tex/node.ts +641 -0
  315. package/src/tex/tween.ts +308 -0
  316. package/src/three/axes3d.ts +240 -0
  317. package/src/three/curve-plot3d.ts +147 -0
  318. package/src/three/label3d.ts +50 -0
  319. package/src/three/plot-point3d.ts +66 -0
  320. package/src/three/space.ts +67 -0
  321. package/src/three/surface-plot3d.ts +323 -0
  322. package/src/three/vector-arrow3d.ts +77 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-mark.js","sourceRoot":"","sources":["../../src/kit/field-mark.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,OAAO,EACP,UAAU,EACV,QAAQ,EACR,QAAQ,GASX,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,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AE,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;yCAAiC;AAGkB;IAA/F,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;gDAA+B;AAEjE;IAApD,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;+CAA8B;AAI1E;IADC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC;wCAGjC;AAID;IADC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC;yCAG7B;AAtBiB,SAAS;IAD9B,QAAQ,CAAC,GAAG,UAAU,EAAE,GAAG,YAAY,CAAC;GACnB,SAAS,CAyG9B","sourcesContent":["import {\r\n command,\r\n Graphics2D,\r\n property,\r\n withdraw,\r\n type Command,\r\n type CommandArgs,\r\n type Fill,\r\n type FillResolved,\r\n type PaintProps,\r\n type RenderContext2D,\r\n type StrokeResolved,\r\n type Vector2,\r\n} from \"@motionscript/sdk\";\r\nimport type { CoordinateMap } from \"./coords\";\r\nimport type { ExpressionScope } from \"./expression\";\r\nimport { fieldParams, parseField } from \"./field\";\r\nimport { boundsOfRuns, runsToPath, stated } from \"./geometry\";\r\nimport { Mark } from \"./mark\";\r\nimport { fillAt, lerpFillScale, readFillScale } from \"./scale\";\r\nimport { lerpParams, lerpSource, readSource, scopeFor, type PlotSource } from \"./source\";\r\nimport { FILL_PAINT, OUTLINE_TRIM } from \"./withdrawn\";\r\n\r\nexport interface FieldProps extends PaintProps {\r\n expression?: string | PlotSource;\r\n params?: ExpressionScope;\r\n strengthFills?: Fill[];\r\n maxMagnitude?: number;\r\n}\r\n\r\n/** A field's vector at a graph point, written into `out`; `false` where it has none. */\r\nexport type FieldSampler = (x: number, y: number, out: Vector2) => boolean;\r\n\r\n/** One thing a field draws, and how strong the field is there: what it is coloured by. */\r\nexport interface FieldStroke {\r\n runs: Vector2[][];\r\n magnitude: number;\r\n}\r\n\r\n/** How many shades the strength fills are drawn in: each is one path. */\r\nconst SHADES = 12;\r\n\r\n/**\r\n * A mark drawn from a vector field, `(P(x, y), Q(x, y))`: arrows, or the lines\r\n * that follow it, all in one stroke. Without strength fills it is one path in\r\n * the stroke's paint; with them, what it draws is sorted by the field's\r\n * strength into a few shades.\r\n */\r\n@withdraw(...FILL_PAINT, ...OUTLINE_TRIM)\r\nexport abstract class FieldMark<P extends FieldProps = FieldProps> extends Mark<P> {\r\n @property({ default: \"\", mapper: readSource, tween: lerpSource, kind: \"fieldEquation\" })\r\n declare expression: PlotSource;\r\n\r\n /** The equation's named values: any name in it that is not `x`, `y`, a function or a constant. */\r\n @property({ default: {}, tween: lerpParams }) declare params: ExpressionScope;\r\n\r\n /** Paints by the field's strength, weakest first. Empty draws everything in the stroke's own paint. */\r\n @property({ default: [], mapper: readFillScale, tween: lerpFillScale, kind: \"vector\" }) declare strengthFills: Fill[];\r\n /** The strength the last paint stands for; zero takes the strongest the field is where it is drawn. */\r\n @property({ default: 0, min: 0, step: 0.1 }) declare maxMagnitude: number;\r\n\r\n /** Change the field, each vector turning from the one into the other. */\r\n @command({ args: [\"expression\"] })\r\n morphTo(args: CommandArgs<{ expression: string }> & { duration: number }): Command<P> {\r\n return this.to({ data: stated(args.data) as Partial<P>, duration: args.duration, easing: args.easing });\r\n }\r\n\r\n /** Animate the equation's named values. */\r\n @command({ args: [\"params\"] })\r\n paramsTo(args: CommandArgs<{ params: ExpressionScope }> & { duration: number }): Command<P> {\r\n return this.to({ data: stated(args.data) as Partial<P>, duration: args.duration, easing: args.easing });\r\n }\r\n\r\n /** What is drawn of `field` through `map`. */\r\n protected abstract strokes(map: CoordinateMap, field: FieldSampler): FieldStroke[];\r\n\r\n /** The props of its own that change what {@link strokes} returns. */\r\n protected abstract own(): string;\r\n\r\n protected trace(map: CoordinateMap): Vector2[][] {\r\n const { area } = map;\r\n if (!Number.isFinite(area.maxX - area.minX)) return [];\r\n const { source, blend } = this.expression;\r\n const shift = this.shift();\r\n const key = [source, blend?.from, blend?.t, map.revision, JSON.stringify(this.params), shift.x, shift.y, this.own()].join(\"|\");\r\n if (key !== this._key) {\r\n this._key = key;\r\n const field = this._sampler(shift);\r\n this._drawn = field ? this.strokes(map, field) : [];\r\n this._runs = this._drawn.flatMap((stroke) => stroke.runs);\r\n }\r\n return this._runs;\r\n }\r\n\r\n protected override renderInk(ctx: RenderContext2D): void {\r\n const scale = this.strengthFills as unknown as FillResolved[][];\r\n const stroke = this.stroke as StrokeResolved[];\r\n const ink = scale.length > 0 && stroke.length > 0 ? boundsOfRuns(this._runs) : null;\r\n if (!ink) {\r\n super.renderInk(ctx);\r\n return;\r\n }\r\n const top = this.maxMagnitude > 0 ? this.maxMagnitude : this._drawn.reduce((most, drawn) => Math.max(most, drawn.magnitude), 0);\r\n const shades: Vector2[][][] = Array.from({ length: SHADES }, () => []);\r\n for (const drawn of this._drawn) {\r\n const share = top > 0 ? Math.min(1, drawn.magnitude / top) : 0;\r\n shades[Math.min(SHADES - 1, Math.floor(share * SHADES))].push(...drawn.runs);\r\n }\r\n shades.forEach((runs, index) => {\r\n if (runs.length === 0) return;\r\n const fill = fillAt(scale, (index + 0.5) / SHADES);\r\n ctx.draw(\r\n new Graphics2D()\r\n .path({ data: runsToPath(runs), centerBounds: [ink.minX, ink.minY, ink.maxX, ink.maxY], start: this.start, end: this.end })\r\n .shadow(this.shadow)\r\n .stroke(stroke.map((layer) => ({ ...layer, fill }))),\r\n );\r\n });\r\n }\r\n\r\n private _key = \"\";\r\n private _drawn: FieldStroke[] = [];\r\n private _runs: Vector2[][] = [];\r\n\r\n /** The field at a graph point, measured from this mark's own shift, mid-morph a blend of two. */\r\n private _sampler(shift: Vector2): FieldSampler | null {\r\n const { source, blend } = this.expression;\r\n const to = this._field(source, shift);\r\n if (!to || !blend) return to;\r\n const from = this._field(blend.from, shift);\r\n if (!from) return to;\r\n const start: Vector2 = { x: 0, y: 0 };\r\n return (x, y, out) => {\r\n if (!from(x, y, start) || !to(x, y, out)) return false;\r\n out.x = start.x + (out.x - start.x) * blend.t;\r\n out.y = start.y + (out.y - start.y) * blend.t;\r\n return true;\r\n };\r\n }\r\n\r\n private _field(source: string, shift: Vector2): FieldSampler | null {\r\n const names = fieldParams(source);\r\n const field = parseField(source, names);\r\n if (field instanceof Error) return null;\r\n const params = scopeFor(names, this.params);\r\n const { x, y } = field;\r\n return (gx, gy, out) => {\r\n const vx = x(gx - shift.x, gy - shift.y, params);\r\n const vy = y(gx - shift.x, gy - shift.y, params);\r\n out.x = vx;\r\n out.y = vy;\r\n return Number.isFinite(vx) && Number.isFinite(vy);\r\n };\r\n }\r\n}\r\n"]}
@@ -0,0 +1,14 @@
1
+ import { type CompiledExpression } from "./expression.js";
2
+ /** A vector at every point of the plane, two parts in `x` and `y`: `(-y, x)`. A warp is written the same way. */
3
+ export interface FieldEquation {
4
+ x: CompiledExpression;
5
+ y: CompiledExpression;
6
+ }
7
+ export declare const FIELD_VARIABLES: readonly ["x", "y"];
8
+ /** The named values a field's equation reads: every name that is not `x` or `y`. */
9
+ export declare function fieldParams(source: string): readonly string[];
10
+ /** `source` as a field, or the reason it is not one. Memoised, so an unchanged equation is the identical object. */
11
+ export declare function parseField(source: string, params?: readonly string[]): FieldEquation | Error;
12
+ /** Why `source` is not a field, or `null`; empty text is not an error. */
13
+ export declare function fieldError(source: string): string | null;
14
+ //# sourceMappingURL=field.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../src/kit/field.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2B,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEhF,iHAAiH;AACjH,MAAM,WAAW,aAAa;IAC1B,CAAC,EAAE,kBAAkB,CAAC;IACtB,CAAC,EAAE,kBAAkB,CAAC;CACzB;AAED,eAAO,MAAM,eAAe,qBAAsB,CAAC;AAKnD,oFAAoF;AACpF,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAE7D;AAED,oHAAoH;AACpH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,SAAS,MAAM,EAAO,GAAG,aAAa,GAAG,KAAK,CAqBhG;AAED,0EAA0E;AAC1E,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAIxD"}
@@ -0,0 +1,46 @@
1
+ import { createBoundedCache } from "./cache.js";
2
+ import { equationNames, splitTuple } from "./equation.js";
3
+ import { compileExpressionCached } from "./expression.js";
4
+ export const FIELD_VARIABLES = ["x", "y"];
5
+ const NAMES = new Set(FIELD_VARIABLES);
6
+ const fields = createBoundedCache(128);
7
+ /** The named values a field's equation reads: every name that is not `x` or `y`. */
8
+ export function fieldParams(source) {
9
+ return equationNames(source).filter((name) => !NAMES.has(name));
10
+ }
11
+ /** `source` as a field, or the reason it is not one. Memoised, so an unchanged equation is the identical object. */
12
+ export function parseField(source, params = []) {
13
+ const key = `${params.join(",")}|${source}`;
14
+ const hit = fields.get(key);
15
+ if (hit !== undefined)
16
+ return hit;
17
+ let result;
18
+ try {
19
+ const text = source.trim();
20
+ if (text === "")
21
+ throw new Error("Empty equation");
22
+ const parts = splitTuple(text);
23
+ if (parts?.length !== 2)
24
+ throw new Error("A field has two parts: (x, y)");
25
+ const [x, y] = parts.map((part) => {
26
+ const compiled = compileExpressionCached(part.trim(), FIELD_VARIABLES, params);
27
+ if (compiled instanceof Error)
28
+ throw compiled;
29
+ return compiled;
30
+ });
31
+ result = { x, y };
32
+ }
33
+ catch (error) {
34
+ result = error instanceof Error ? error : new Error(String(error));
35
+ }
36
+ fields.set(key, result);
37
+ return result;
38
+ }
39
+ /** Why `source` is not a field, or `null`; empty text is not an error. */
40
+ export function fieldError(source) {
41
+ if (source.trim() === "")
42
+ return null;
43
+ const field = parseField(source, fieldParams(source));
44
+ return field instanceof Error ? field.message : null;
45
+ }
46
+ //# sourceMappingURL=field.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field.js","sourceRoot":"","sources":["../../src/kit/field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,uBAAuB,EAA2B,MAAM,cAAc,CAAC;AAQhF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,CAAU,CAAC;AAEnD,MAAM,KAAK,GAAwB,IAAI,GAAG,CAAC,eAAe,CAAC,CAAC;AAC5D,MAAM,MAAM,GAAG,kBAAkB,CAAwB,GAAG,CAAC,CAAC;AAE9D,oFAAoF;AACpF,MAAM,UAAU,WAAW,CAAC,MAAc;IACtC,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AACpE,CAAC;AAED,oHAAoH;AACpH,MAAM,UAAU,UAAU,CAAC,MAAc,EAAE,SAA4B,EAAE;IACrE,MAAM,GAAG,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,MAAM,EAAE,CAAC;IAC5C,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC5B,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,GAAG,CAAC;IAClC,IAAI,MAA6B,CAAC;IAClC,IAAI,CAAC;QACD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;QAC3B,IAAI,IAAI,KAAK,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;QACnD,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,KAAK,EAAE,MAAM,KAAK,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;QAC1E,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;YAC9B,MAAM,QAAQ,GAAG,uBAAuB,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,eAAe,EAAE,MAAM,CAAC,CAAC;YAC/E,IAAI,QAAQ,YAAY,KAAK;gBAAE,MAAM,QAAQ,CAAC;YAC9C,OAAO,QAAQ,CAAC;QACpB,CAAC,CAAC,CAAC;QACH,MAAM,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IACtB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,MAAM,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACvE,CAAC;IACD,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACxB,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,UAAU,CAAC,MAAc;IACrC,IAAI,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE;QAAE,OAAO,IAAI,CAAC;IACtC,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IACtD,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;AACzD,CAAC","sourcesContent":["import { createBoundedCache } from \"./cache\";\r\nimport { equationNames, splitTuple } from \"./equation\";\r\nimport { compileExpressionCached, type CompiledExpression } from \"./expression\";\r\n\r\n/** A vector at every point of the plane, two parts in `x` and `y`: `(-y, x)`. A warp is written the same way. */\r\nexport interface FieldEquation {\r\n x: CompiledExpression;\r\n y: CompiledExpression;\r\n}\r\n\r\nexport const FIELD_VARIABLES = [\"x\", \"y\"] as const;\r\n\r\nconst NAMES: ReadonlySet<string> = new Set(FIELD_VARIABLES);\r\nconst fields = createBoundedCache<FieldEquation | Error>(128);\r\n\r\n/** The named values a field's equation reads: every name that is not `x` or `y`. */\r\nexport function fieldParams(source: string): readonly string[] {\r\n return equationNames(source).filter((name) => !NAMES.has(name));\r\n}\r\n\r\n/** `source` as a field, or the reason it is not one. Memoised, so an unchanged equation is the identical object. */\r\nexport function parseField(source: string, params: readonly string[] = []): FieldEquation | Error {\r\n const key = `${params.join(\",\")}|${source}`;\r\n const hit = fields.get(key);\r\n if (hit !== undefined) return hit;\r\n let result: FieldEquation | Error;\r\n try {\r\n const text = source.trim();\r\n if (text === \"\") throw new Error(\"Empty equation\");\r\n const parts = splitTuple(text);\r\n if (parts?.length !== 2) throw new Error(\"A field has two parts: (x, y)\");\r\n const [x, y] = parts.map((part) => {\r\n const compiled = compileExpressionCached(part.trim(), FIELD_VARIABLES, params);\r\n if (compiled instanceof Error) throw compiled;\r\n return compiled;\r\n });\r\n result = { x, y };\r\n } catch (error) {\r\n result = error instanceof Error ? error : new Error(String(error));\r\n }\r\n fields.set(key, result);\r\n return result;\r\n}\r\n\r\n/** Why `source` is not a field, or `null`; empty text is not an error. */\r\nexport function fieldError(source: string): string | null {\r\n if (source.trim() === \"\") return null;\r\n const field = parseField(source, fieldParams(source));\r\n return field instanceof Error ? field.message : null;\r\n}\r\n"]}
@@ -0,0 +1,71 @@
1
+ import { Graphics2D, PaintNode, type BoxBounds, type Command, type CommandArgs, type Node2D, type PaintProps, type PathCommand, type Size2D, type Vector2 } from "@motionscript/sdk";
2
+ /** A node with parts that can be pointed at by name: a formula's terms. */
3
+ export interface Parted {
4
+ /** The box of `part`, y-up from the node's centre, or `null` when it has no such part. */
5
+ partBounds(part: string, occurrence?: number): BoxBounds | null;
6
+ }
7
+ /** What a mark is drawn on: a node by id, and one part of it where it has parts. */
8
+ export interface Target {
9
+ on: string;
10
+ part?: string;
11
+ occurrence?: number;
12
+ }
13
+ /** A target on its way to another: `t` of the way from `from`, or from the mark's resting target. */
14
+ export interface Retarget extends Target {
15
+ from?: Target | null;
16
+ t: number;
17
+ }
18
+ /** A target's four corners in its mark's own frame, y-up: top left, top right, bottom right, bottom left. */
19
+ export type Quad = [Vector2, Vector2, Vector2, Vector2];
20
+ /**
21
+ * The node a mark is drawn on: the one `on` names, or, naming none, the nearest
22
+ * node with parts the mark sits inside. Putting a box in a formula is how it is
23
+ * told which.
24
+ */
25
+ export declare function followed(mark: Node2D, on: string): Node2D | null;
26
+ /** Where `target` is, as `mark` sees it; `null` when it names no node or part. */
27
+ export declare function quadOf(mark: Node2D, target: Target): Quad | null;
28
+ export interface FollowProps extends PaintProps {
29
+ on?: string;
30
+ part?: string;
31
+ occurrence?: number;
32
+ retarget?: Retarget | null;
33
+ }
34
+ /**
35
+ * A mark drawn on another node, or on one part of a formula: a brace, a box,
36
+ * an underline. It has no size of its own and takes no place in a layout; it
37
+ * is drawn where its target is, wherever the two are in the tree, and its
38
+ * selection box is its ink.
39
+ */
40
+ export declare abstract class FollowMark<P extends FollowProps = FollowProps> extends PaintNode<P> {
41
+ /** The node this mark is drawn on, by id. Left empty, it is the formula the mark sits inside. */
42
+ on: string;
43
+ /** One part of that node, by its source, where it has parts: `x^2` of a formula. */
44
+ part: string;
45
+ /** Which of the places the part is written, counted from 1. */
46
+ occurrence: number;
47
+ /** Where a `retargetTo` has taken the mark, and how far along it is. Not an author's to state. */
48
+ retarget: Retarget | null;
49
+ /** Move the mark onto another node, or another part. */
50
+ retargetTo(args: CommandArgs<Partial<Target>> & {
51
+ duration: number;
52
+ }): Command<P>;
53
+ /** The outline to draw around `quad`, in the mark's own frame, y-up. */
54
+ protected abstract outline(quad: Quad): PathCommand[];
55
+ /** The target's corners now: its resting one, or part-way to where a `retargetTo` is taking it. */
56
+ protected quad(): Quad | null;
57
+ measure(): Partial<Size2D>;
58
+ protected shapeGraphics(): Graphics2D | null;
59
+ _localBounds(): BoxBounds;
60
+ private _outline;
61
+ }
62
+ export declare const add: (a: Vector2, b: Vector2, k?: number) => Vector2;
63
+ export declare const between: (a: Vector2, b: Vector2, t?: number) => Vector2;
64
+ /** The unit vector from `a` to `b`, and its length; a zero one points right. */
65
+ export declare function heading(a: Vector2, b: Vector2): {
66
+ unit: Vector2;
67
+ length: number;
68
+ };
69
+ /** A quad grown by `by` pixels on every side, along its own edges. */
70
+ export declare function grown(quad: Quad, by: number): Quad;
71
+ //# sourceMappingURL=follow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"follow.d.ts","sourceRoot":"","sources":["../../src/kit/follow.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,UAAU,EACV,SAAS,EAIT,KAAK,SAAS,EACd,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,MAAM,EACX,KAAK,OAAO,EACf,MAAM,mBAAmB,CAAC;AAG3B,2EAA2E;AAC3E,MAAM,WAAW,MAAM;IACnB,0FAA0F;IAC1F,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;CACnE;AAMD,oFAAoF;AACpF,MAAM,WAAW,MAAM;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,qGAAqG;AACrG,MAAM,WAAW,QAAS,SAAQ,MAAM;IACpC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,CAAC,EAAE,MAAM,CAAC;CACb;AAED,6GAA6G;AAC7G,MAAM,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC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,EAAE,GAAG,OAAO,EAAE,UAAK,KAAG,OAAmD,CAAC;AACxG,eAAO,MAAM,OAAO,GAAI,GAAG,OAAO,EAAE,GAAG,OAAO,EAAE,UAAO,KAAG,OAAmE,CAAC;AAE9H,gFAAgF;AAChF,wBAAgB,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAKjF;AAED,sEAAsE;AACtE,wBAAgB,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAUlD"}
@@ -0,0 +1,159 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { command, findNode2D, frameIn, Graphics2D, PaintNode, pathOps, property, withdraw, } from "@motionscript/sdk";
8
+ import { FILL_PAINT } from "./withdrawn.js";
9
+ function isParted(node) {
10
+ return typeof node.partBounds === "function";
11
+ }
12
+ /**
13
+ * The node a mark is drawn on: the one `on` names, or, naming none, the nearest
14
+ * node with parts the mark sits inside. Putting a box in a formula is how it is
15
+ * told which.
16
+ */
17
+ export function followed(mark, on) {
18
+ if (on !== "") {
19
+ const node = findNode2D(mark, on);
20
+ return node && node !== mark ? node : null;
21
+ }
22
+ for (let at = mark.parent; at; at = at.parent) {
23
+ if (isParted(at))
24
+ return at;
25
+ }
26
+ return null;
27
+ }
28
+ /** Where `target` is, as `mark` sees it; `null` when it names no node or part. */
29
+ export function quadOf(mark, target) {
30
+ const node = followed(mark, target.on);
31
+ if (!node)
32
+ return null;
33
+ const box = target.part && isParted(node)
34
+ ? node.partBounds(target.part, target.occurrence || 1)
35
+ : { x: 0, y: 0, width: node.layoutBounds.width, height: node.layoutBounds.height };
36
+ if (!box)
37
+ return null;
38
+ const frame = frameIn(mark, node);
39
+ const turn = (frame.rotation * Math.PI) / 180;
40
+ const cos = Math.cos(turn);
41
+ const sin = Math.sin(turn);
42
+ // The engine's turn is clockwise, in a y-up frame.
43
+ const place = (x, y) => ({
44
+ x: frame.x + (cos * x + sin * y) * frame.scale,
45
+ y: frame.y + (-sin * x + cos * y) * frame.scale,
46
+ });
47
+ const w = box.width / 2;
48
+ const h = box.height / 2;
49
+ return [place(box.x - w, box.y + h), place(box.x + w, box.y + h), place(box.x + w, box.y - h), place(box.x - w, box.y - h)];
50
+ }
51
+ function lerpQuad(a, b, t) {
52
+ return a.map((from, i) => ({ x: from.x + (b[i].x - from.x) * t, y: from.y + (b[i].y - from.y) * t }));
53
+ }
54
+ const restOf = ({ on, part, occurrence }) => ({ on, part, occurrence });
55
+ function lerpRetarget(from, to, t) {
56
+ if (t <= 0 || !to)
57
+ return t < 1 ? from : to;
58
+ return { ...restOf(to), from: from ? restOf(from) : null, t };
59
+ }
60
+ /** Every drawn point's centre frame: the mark's own centre, so its outline is where it says. */
61
+ const OWN_FRAME = [-1, -1, 1, 1];
62
+ /**
63
+ * A mark drawn on another node, or on one part of a formula: a brace, a box,
64
+ * an underline. It has no size of its own and takes no place in a layout; it
65
+ * is drawn where its target is, wherever the two are in the tree, and its
66
+ * selection box is its ink.
67
+ */
68
+ let FollowMark = class FollowMark extends PaintNode {
69
+ /** Move the mark onto another node, or another part. */
70
+ retargetTo(args) {
71
+ const next = args.data ?? {};
72
+ const held = this.retarget ?? this;
73
+ const to = {
74
+ on: next.on ?? held.on,
75
+ part: next.part ?? (next.on ? "" : held.part),
76
+ occurrence: next.occurrence ?? 1,
77
+ t: 1,
78
+ };
79
+ return this.to({ data: { retarget: to }, duration: args.duration, easing: args.easing });
80
+ }
81
+ /** The target's corners now: its resting one, or part-way to where a `retargetTo` is taking it. */
82
+ quad() {
83
+ const state = this.retarget;
84
+ if (!state)
85
+ return quadOf(this, this);
86
+ const to = quadOf(this, state);
87
+ const from = quadOf(this, state.from ?? this);
88
+ if (!from || !to || state.t >= 1)
89
+ return to ?? from;
90
+ return lerpQuad(from, to, state.t);
91
+ }
92
+ measure() {
93
+ return { width: 0, height: 0 };
94
+ }
95
+ shapeGraphics() {
96
+ const data = this._outline();
97
+ if (data.length === 0)
98
+ return null;
99
+ return new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: this.start, end: this.end });
100
+ }
101
+ _localBounds() {
102
+ const ink = pathOps.bounds(this._outline());
103
+ if (!ink)
104
+ return { x: 0, y: 0, width: 0, height: 0 };
105
+ return { x: (ink.minX + ink.maxX) / 2, y: (ink.minY + ink.maxY) / 2, width: ink.maxX - ink.minX, height: ink.maxY - ink.minY };
106
+ }
107
+ _outline() {
108
+ const quad = this.quad();
109
+ return quad ? this.outline(quad) : [];
110
+ }
111
+ };
112
+ __decorate([
113
+ property({ default: "", kind: "nodeRef", animatable: false })
114
+ ], FollowMark.prototype, "on", void 0);
115
+ __decorate([
116
+ property({ default: "", animatable: false })
117
+ ], FollowMark.prototype, "part", void 0);
118
+ __decorate([
119
+ property({ default: 1, min: 1, step: 1, animatable: false })
120
+ ], FollowMark.prototype, "occurrence", void 0);
121
+ __decorate([
122
+ property({ default: null, tween: lerpRetarget })
123
+ ], FollowMark.prototype, "retarget", void 0);
124
+ __decorate([
125
+ command({
126
+ args: [
127
+ { key: "on", kind: "nodeRef" },
128
+ { key: "part", kind: "text", default: "" },
129
+ { key: "occurrence", kind: "number", min: 1, step: 1, default: 1 },
130
+ ],
131
+ })
132
+ ], FollowMark.prototype, "retargetTo", null);
133
+ FollowMark = __decorate([
134
+ withdraw(...FILL_PAINT)
135
+ ], FollowMark);
136
+ export { FollowMark };
137
+ // --- Geometry the marks share ---
138
+ export const add = (a, b, k = 1) => ({ x: a.x + b.x * k, y: a.y + b.y * k });
139
+ export const between = (a, b, t = 0.5) => ({ x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t });
140
+ /** The unit vector from `a` to `b`, and its length; a zero one points right. */
141
+ export function heading(a, b) {
142
+ const dx = b.x - a.x;
143
+ const dy = b.y - a.y;
144
+ const length = Math.hypot(dx, dy);
145
+ return { unit: length === 0 ? { x: 1, y: 0 } : { x: dx / length, y: dy / length }, length };
146
+ }
147
+ /** A quad grown by `by` pixels on every side, along its own edges. */
148
+ export function grown(quad, by) {
149
+ const [tl, tr, br, bl] = quad;
150
+ const across = heading(tl, tr).unit;
151
+ const up = heading(bl, tl).unit;
152
+ return [
153
+ add(add(tl, across, -by), up, by),
154
+ add(add(tr, across, by), up, by),
155
+ add(add(br, across, by), up, -by),
156
+ add(add(bl, across, -by), up, -by),
157
+ ];
158
+ }
159
+ //# sourceMappingURL=follow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"follow.js","sourceRoot":"","sources":["../../src/kit/follow.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,OAAO,EACP,UAAU,EACV,OAAO,EACP,UAAU,EACV,SAAS,EACT,OAAO,EACP,QAAQ,EACR,QAAQ,GASX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAQzC,SAAS,QAAQ,CAAC,IAAY;IAC1B,OAAO,OAAQ,IAAwB,CAAC,UAAU,KAAK,UAAU,CAAC;AACtE,CAAC;AAkBD;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,EAAU;IAC7C,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAClC,OAAO,IAAI,IAAI,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CA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AAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC;AAChG,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,KAAK,CAAC,IAAU,EAAE,EAAU;IACxC,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC;IAC9B,MAAM,MAAM,GAAG,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC;IACpC,MAAM,EAAE,GAAG,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC;IAChC,OAAO;QACH,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC;QACjC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC;QAChC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;QACjC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;KACrC,CAAC;AACN,CAAC","sourcesContent":["import {\r\n command,\r\n findNode2D,\r\n frameIn,\r\n Graphics2D,\r\n PaintNode,\r\n pathOps,\r\n property,\r\n withdraw,\r\n type BoxBounds,\r\n type Command,\r\n type CommandArgs,\r\n type Node2D,\r\n type PaintProps,\r\n type PathCommand,\r\n type Size2D,\r\n type Vector2,\r\n} from \"@motionscript/sdk\";\r\nimport { FILL_PAINT } from \"./withdrawn\";\r\n\r\n/** A node with parts that can be pointed at by name: a formula's terms. */\r\nexport interface Parted {\r\n /** The box of `part`, y-up from the node's centre, or `null` when it has no such part. */\r\n partBounds(part: string, occurrence?: number): BoxBounds | null;\r\n}\r\n\r\nfunction isParted(node: object): node is Parted {\r\n return typeof (node as Partial<Parted>).partBounds === \"function\";\r\n}\r\n\r\n/** What a mark is drawn on: a node by id, and one part of it where it has parts. */\r\nexport interface Target {\r\n on: string;\r\n part?: string;\r\n occurrence?: number;\r\n}\r\n\r\n/** A target on its way to another: `t` of the way from `from`, or from the mark's resting target. */\r\nexport interface Retarget extends Target {\r\n from?: Target | null;\r\n t: number;\r\n}\r\n\r\n/** A target's four corners in its mark's own frame, y-up: top left, top right, bottom right, bottom left. */\r\nexport type Quad = [Vector2, Vector2, Vector2, Vector2];\r\n\r\n/**\r\n * The node a mark is drawn on: the one `on` names, or, naming none, the nearest\r\n * node with parts the mark sits inside. Putting a box in a formula is how it is\r\n * told which.\r\n */\r\nexport function followed(mark: Node2D, on: string): Node2D | null {\r\n if (on !== \"\") {\r\n const node = findNode2D(mark, on);\r\n return node && node !== mark ? node : null;\r\n }\r\n for (let at: Node2D | null = mark.parent; at; at = at.parent) {\r\n if (isParted(at)) return at;\r\n }\r\n return null;\r\n}\r\n\r\n/** Where `target` is, as `mark` sees it; `null` when it names no node or part. */\r\nexport function quadOf(mark: Node2D, target: Target): Quad | null {\r\n const node = followed(mark, target.on);\r\n if (!node) return null;\r\n const box: BoxBounds | null =\r\n target.part && isParted(node)\r\n ? node.partBounds(target.part, target.occurrence || 1)\r\n : { x: 0, y: 0, width: node.layoutBounds.width, height: node.layoutBounds.height };\r\n if (!box) return null;\r\n const frame = frameIn(mark, node);\r\n const turn = (frame.rotation * Math.PI) / 180;\r\n const cos = Math.cos(turn);\r\n const sin = Math.sin(turn);\r\n // The engine's turn is clockwise, in a y-up frame.\r\n const place = (x: number, y: number): Vector2 => ({\r\n x: frame.x + (cos * x + sin * y) * frame.scale,\r\n y: frame.y + (-sin * x + cos * y) * frame.scale,\r\n });\r\n const w = box.width / 2;\r\n const h = box.height / 2;\r\n return [place(box.x - w, box.y + h), place(box.x + w, box.y + h), place(box.x + w, box.y - h), place(box.x - w, box.y - h)];\r\n}\r\n\r\nfunction lerpQuad(a: Quad, b: Quad, t: number): Quad {\r\n return a.map((from, i) => ({ x: from.x + (b[i].x - from.x) * t, y: from.y + (b[i].y - from.y) * t })) as Quad;\r\n}\r\n\r\nconst restOf = ({ on, part, occurrence }: Target): Target => ({ on, part, occurrence });\r\n\r\nfunction lerpRetarget(from: Retarget | null, to: Retarget | null, t: number): Retarget | null {\r\n if (t <= 0 || !to) return t < 1 ? from : to;\r\n return { ...restOf(to), from: from ? restOf(from) : null, t };\r\n}\r\n\r\nexport interface FollowProps extends PaintProps {\r\n on?: string;\r\n part?: string;\r\n occurrence?: number;\r\n retarget?: Retarget | null;\r\n}\r\n\r\n/** Every drawn point's centre frame: the mark's own centre, so its outline is where it says. */\r\nconst OWN_FRAME: [number, number, number, number] = [-1, -1, 1, 1];\r\n\r\n/**\r\n * A mark drawn on another node, or on one part of a formula: a brace, a box,\r\n * an underline. It has no size of its own and takes no place in a layout; it\r\n * is drawn where its target is, wherever the two are in the tree, and its\r\n * selection box is its ink.\r\n */\r\n@withdraw(...FILL_PAINT)\r\nexport abstract class FollowMark<P extends FollowProps = FollowProps> extends PaintNode<P> {\r\n /** The node this mark is drawn on, by id. Left empty, it is the formula the mark sits inside. */\r\n @property({ default: \"\", kind: \"nodeRef\", animatable: false }) declare on: string;\r\n /** One part of that node, by its source, where it has parts: `x^2` of a formula. */\r\n @property({ default: \"\", animatable: false }) declare part: string;\r\n /** Which of the places the part is written, counted from 1. */\r\n @property({ default: 1, min: 1, step: 1, animatable: false }) declare occurrence: number;\r\n /** Where a `retargetTo` has taken the mark, and how far along it is. Not an author's to state. */\r\n @property({ default: null, tween: lerpRetarget }) declare retarget: Retarget | null;\r\n\r\n /** Move the mark onto another node, or another part. */\r\n @command({\r\n args: [\r\n { key: \"on\", kind: \"nodeRef\" },\r\n { key: \"part\", kind: \"text\", default: \"\" },\r\n { key: \"occurrence\", kind: \"number\", min: 1, step: 1, default: 1 },\r\n ],\r\n })\r\n retargetTo(args: CommandArgs<Partial<Target>> & { duration: number }): Command<P> {\r\n const next = args.data ?? {};\r\n const held = this.retarget ?? this;\r\n const to: Retarget = {\r\n on: next.on ?? held.on,\r\n part: next.part ?? (next.on ? \"\" : held.part),\r\n occurrence: next.occurrence ?? 1,\r\n t: 1,\r\n };\r\n return this.to({ data: { retarget: to } as Partial<P>, duration: args.duration, easing: args.easing });\r\n }\r\n\r\n /** The outline to draw around `quad`, in the mark's own frame, y-up. */\r\n protected abstract outline(quad: Quad): PathCommand[];\r\n\r\n /** The target's corners now: its resting one, or part-way to where a `retargetTo` is taking it. */\r\n protected quad(): Quad | null {\r\n const state = this.retarget;\r\n if (!state) return quadOf(this, this);\r\n const to = quadOf(this, state);\r\n const from = quadOf(this, state.from ?? this);\r\n if (!from || !to || state.t >= 1) return to ?? from;\r\n return lerpQuad(from, to, state.t);\r\n }\r\n\r\n override measure(): Partial<Size2D> {\r\n return { width: 0, height: 0 };\r\n }\r\n\r\n protected override shapeGraphics(): Graphics2D | null {\r\n const data = this._outline();\r\n if (data.length === 0) return null;\r\n return new Graphics2D().path({ data, centerBounds: OWN_FRAME, start: this.start, end: this.end });\r\n }\r\n\r\n override _localBounds(): BoxBounds {\r\n const ink = pathOps.bounds(this._outline());\r\n if (!ink) return { x: 0, y: 0, width: 0, height: 0 };\r\n return { x: (ink.minX + ink.maxX) / 2, y: (ink.minY + ink.maxY) / 2, width: ink.maxX - ink.minX, height: ink.maxY - ink.minY };\r\n }\r\n\r\n private _outline(): PathCommand[] {\r\n const quad = this.quad();\r\n return quad ? this.outline(quad) : [];\r\n }\r\n}\r\n\r\n// --- Geometry the marks share ---\r\n\r\nexport const add = (a: Vector2, b: Vector2, k = 1): Vector2 => ({ x: a.x + b.x * k, y: a.y + b.y * k });\r\nexport const between = (a: Vector2, b: Vector2, t = 0.5): Vector2 => ({ x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t });\r\n\r\n/** The unit vector from `a` to `b`, and its length; a zero one points right. */\r\nexport function heading(a: Vector2, b: Vector2): { unit: Vector2; length: number } {\r\n const dx = b.x - a.x;\r\n const dy = b.y - a.y;\r\n const length = Math.hypot(dx, dy);\r\n return { unit: length === 0 ? { x: 1, y: 0 } : { x: dx / length, y: dy / length }, length };\r\n}\r\n\r\n/** A quad grown by `by` pixels on every side, along its own edges. */\r\nexport function grown(quad: Quad, by: number): Quad {\r\n const [tl, tr, br, bl] = quad;\r\n const across = heading(tl, tr).unit;\r\n const up = heading(bl, tl).unit;\r\n return [\r\n add(add(tl, across, -by), up, by),\r\n add(add(tr, across, by), up, by),\r\n add(add(br, across, by), up, -by),\r\n add(add(bl, across, -by), up, -by),\r\n ];\r\n}\r\n"]}
@@ -0,0 +1,30 @@
1
+ import { Graphics2D, type AssetScope, type Color, type StrokeResolved, type Vector2 } from "@motionscript/sdk";
2
+ import type { Interval } from "./coords.js";
3
+ /** Shared drawing for the systems' own furniture: axis lines, tick marks and their numbers. */
4
+ /** What a system draws its axes and numbers in, and a plot its curve, until told otherwise. */
5
+ export declare const AXIS_COLOR = "#9ca3af";
6
+ export declare const PLOT_COLOR = "#58a6ff";
7
+ /** A stroke without end markers: an axis wears a tip, its ticks do not. */
8
+ export declare function withoutTips(stroke: StrokeResolved[]): StrokeResolved[];
9
+ export interface LabelStyle {
10
+ fontSize: number;
11
+ fontFamily: string;
12
+ color: Color;
13
+ }
14
+ export interface Label {
15
+ text: string;
16
+ /** Where the label's box is anchored, in pixels. */
17
+ at: Vector2;
18
+ align: "left" | "center" | "right";
19
+ }
20
+ /** Ask the host for MathJax when any of `texts` is a formula, so it is there before the node is laid out. */
21
+ export declare function declareFormulas(assets: AssetScope, texts: readonly string[]): void;
22
+ /** What draws `labels`: text in the scene's face, and a typeset formula for each one written as such. */
23
+ export declare function drawLabels(labels: readonly Label[], style: LabelStyle): Graphics2D[];
24
+ /** Whether a mark `u` of the way along an axis is inside the part of it drawn so far. */
25
+ export declare function drawn(u: number, start: number, end: number): boolean;
26
+ /** How far along `range` a value is, 0 to 1, by pixel distance. */
27
+ export declare function along(at: Vector2, from: Vector2, to: Vector2): number;
28
+ export declare function lerpInterval(from: Interval, to: Interval, t: number): Interval;
29
+ export declare function readInterval(value: Interval | undefined, previous?: Interval): Interval;
30
+ //# sourceMappingURL=furniture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"furniture.d.ts","sourceRoot":"","sources":["../../src/kit/furniture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,UAAU,EAAgB,KAAK,UAAU,EAAE,KAAK,KAAK,EAAE,KAAK,cAAc,EAAE,KAAK,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEpI,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,+FAA+F;AAE/F,+FAA+F;AAC/F,eAAO,MAAM,UAAU,YAAY,CAAC;AACpC,eAAO,MAAM,UAAU,YAAY,CAAC;AAEpC,2EAA2E;AAC3E,wBAAgB,WAAW,CAAC,MAAM,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CAEtE;AAED,MAAM,WAAW,UAAU;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;CAChB;AAED,MAAM,WAAW,KAAK;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;CACtC;AAQD,6GAA6G;AAC7G,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAElF;AAED,yGAAyG;AACzG,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,EAAE,KAAK,EAAE,UAAU,GAAG,UAAU,EAAE,CA6BpF;AAkBD,yFAAyF;AACzF,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAEpE;AAED,mEAAmE;AACnE,wBAAgB,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,GAAG,MAAM,CAKrE;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,GAAG,QAAQ,CAE9E;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAGvF"}
@@ -0,0 +1,87 @@
1
+ import { Fills, Graphics2D, toPathString } from "@motionscript/sdk";
2
+ import { buildLatexPath, LatexNotLoaded, loadMathJax, MATHJAX_LOADER } from "../tex/geometry.js";
3
+ /** Shared drawing for the systems' own furniture: axis lines, tick marks and their numbers. */
4
+ /** What a system draws its axes and numbers in, and a plot its curve, until told otherwise. */
5
+ export const AXIS_COLOR = "#9ca3af";
6
+ export const PLOT_COLOR = "#58a6ff";
7
+ /** A stroke without end markers: an axis wears a tip, its ticks do not. */
8
+ export function withoutTips(stroke) {
9
+ return stroke.map((layer) => ({ ...layer, startCap: undefined, endCap: undefined }));
10
+ }
11
+ /** How wide a label's box is, in ems: room for a long number, so alignment is by the box's edge. */
12
+ const LABEL_BOX_EM = 8;
13
+ /** A label written between dollar signs is a formula: `$\\frac{\\pi}{2}$`. */
14
+ const FORMULA = /^\$([\s\S]+)\$$/;
15
+ /** Ask the host for MathJax when any of `texts` is a formula, so it is there before the node is laid out. */
16
+ export function declareFormulas(assets, texts) {
17
+ if (texts.some((text) => FORMULA.test(text.trim())))
18
+ assets.loader(MATHJAX_LOADER, loadMathJax, { gate: "layout" });
19
+ }
20
+ /** What draws `labels`: text in the scene's face, and a typeset formula for each one written as such. */
21
+ export function drawLabels(labels, style) {
22
+ const out = [];
23
+ const fill = Fills.color(style.color);
24
+ const text = new Graphics2D();
25
+ const width = style.fontSize * LABEL_BOX_EM;
26
+ let written = false;
27
+ for (const label of labels) {
28
+ const formula = FORMULA.exec(label.text.trim());
29
+ const glyphs = formula ? typeset(formula[1], label, style.fontSize) : null;
30
+ if (glyphs) {
31
+ for (const glyph of glyphs)
32
+ out.push(glyph.fill(fill));
33
+ continue;
34
+ }
35
+ const { at, align } = label;
36
+ written = true;
37
+ text.text({
38
+ text: label.text,
39
+ fontSize: style.fontSize,
40
+ // An empty family is left out, so the label takes the scene's own face.
41
+ ...(style.fontFamily === "" ? {} : { fontFamily: style.fontFamily }),
42
+ wrap: false,
43
+ width,
44
+ textAlign: align,
45
+ x: align === "center" ? at.x : align === "right" ? at.x - width / 2 : at.x + width / 2,
46
+ y: at.y,
47
+ });
48
+ }
49
+ if (written)
50
+ out.push(text.fill(fill));
51
+ return out;
52
+ }
53
+ // A formula's glyphs with its box anchored at the label's point; `null` for one that will not typeset, which is then
54
+ // drawn as written, and nothing at all while MathJax is still on its way: its source is not a stand-in for it.
55
+ function typeset(source, { at, align }, fontSize) {
56
+ let formula;
57
+ try {
58
+ formula = buildLatexPath(source, fontSize);
59
+ }
60
+ catch (error) {
61
+ return error instanceof LatexNotLoaded ? [] : null;
62
+ }
63
+ const [minX, minY, maxX, maxY] = formula.bounds;
64
+ const dx = at.x + (align === "left" ? formula.width / 2 : align === "right" ? -formula.width / 2 : 0);
65
+ // Glyph paths are y-down; the frame whose centre lands on the node's is shifted the other way.
66
+ const frame = [minX - dx, minY + at.y, maxX - dx, maxY + at.y];
67
+ return formula.tokens.map((token) => new Graphics2D().path({ data: toPathString(token.path), centerBounds: frame }));
68
+ }
69
+ /** Whether a mark `u` of the way along an axis is inside the part of it drawn so far. */
70
+ export function drawn(u, start, end) {
71
+ return u >= start - 1e-9 && u <= end + 1e-9;
72
+ }
73
+ /** How far along `range` a value is, 0 to 1, by pixel distance. */
74
+ export function along(at, from, to) {
75
+ const dx = to.x - from.x;
76
+ const dy = to.y - from.y;
77
+ const length = dx * dx + dy * dy;
78
+ return length === 0 ? 0 : ((at.x - from.x) * dx + (at.y - from.y) * dy) / length;
79
+ }
80
+ export function lerpInterval(from, to, t) {
81
+ return [from[0] + (to[0] - from[0]) * t, from[1] + (to[1] - from[1]) * t];
82
+ }
83
+ export function readInterval(value, previous) {
84
+ const [min, max] = Array.isArray(value) ? value : (previous ?? [0, 1]);
85
+ return [Number(min), Number(max)];
86
+ }
87
+ //# sourceMappingURL=furniture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"furniture.js","sourceRoot":"","sources":["../../src/kit/furniture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAkE,MAAM,mBAAmB,CAAC;AACpI,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAG9F,+FAA+F;AAE/F,+FAA+F;AAC/F,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAC;AACpC,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAC;AAEpC,2EAA2E;AAC3E,MAAM,UAAU,WAAW,CAAC,MAAwB;IAChD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;AACzF,CAAC;AAeD,oGAAoG;AACpG,MAAM,YAAY,GAAG,CAAC,CAAC;AAEvB,8EAA8E;AAC9E,MAAM,OAAO,GAAG,iBAAiB,CAAC;AAElC,6GAA6G;AAC7G,MAAM,UAAU,eAAe,CAAC,MAAkB,EAAE,KAAwB;IACxE,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI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C,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAA2B,EAAE,QAAmB;IACzE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACvE,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AACtC,CAAC","sourcesContent":["import { Fills, Graphics2D, toPathString, type AssetScope, type Color, type StrokeResolved, type Vector2 } from \"@motionscript/sdk\";\r\nimport { buildLatexPath, LatexNotLoaded, loadMathJax, MATHJAX_LOADER } from \"../tex/geometry\";\r\nimport type { Interval } from \"./coords\";\r\n\r\n/** Shared drawing for the systems' own furniture: axis lines, tick marks and their numbers. */\r\n\r\n/** What a system draws its axes and numbers in, and a plot its curve, until told otherwise. */\r\nexport const AXIS_COLOR = \"#9ca3af\";\r\nexport const PLOT_COLOR = \"#58a6ff\";\r\n\r\n/** A stroke without end markers: an axis wears a tip, its ticks do not. */\r\nexport function withoutTips(stroke: StrokeResolved[]): StrokeResolved[] {\r\n return stroke.map((layer) => ({ ...layer, startCap: undefined, endCap: undefined }));\r\n}\r\n\r\nexport interface LabelStyle {\r\n fontSize: number;\r\n fontFamily: string;\r\n color: Color;\r\n}\r\n\r\nexport interface Label {\r\n text: string;\r\n /** Where the label's box is anchored, in pixels. */\r\n at: Vector2;\r\n align: \"left\" | \"center\" | \"right\";\r\n}\r\n\r\n/** How wide a label's box is, in ems: room for a long number, so alignment is by the box's edge. */\r\nconst LABEL_BOX_EM = 8;\r\n\r\n/** A label written between dollar signs is a formula: `$\\\\frac{\\\\pi}{2}$`. */\r\nconst FORMULA = /^\\$([\\s\\S]+)\\$$/;\r\n\r\n/** Ask the host for MathJax when any of `texts` is a formula, so it is there before the node is laid out. */\r\nexport function declareFormulas(assets: AssetScope, texts: readonly string[]): void {\r\n if (texts.some((text) => FORMULA.test(text.trim()))) assets.loader(MATHJAX_LOADER, loadMathJax, { gate: \"layout\" });\r\n}\r\n\r\n/** What draws `labels`: text in the scene's face, and a typeset formula for each one written as such. */\r\nexport function drawLabels(labels: readonly Label[], style: LabelStyle): Graphics2D[] {\r\n const out: Graphics2D[] = [];\r\n const fill = Fills.color(style.color);\r\n const text = new Graphics2D();\r\n const width = style.fontSize * LABEL_BOX_EM;\r\n let written = false;\r\n for (const label of labels) {\r\n const formula = FORMULA.exec(label.text.trim());\r\n const glyphs = formula ? typeset(formula[1], label, style.fontSize) : null;\r\n if (glyphs) {\r\n for (const glyph of glyphs) out.push(glyph.fill(fill));\r\n continue;\r\n }\r\n const { at, align } = label;\r\n written = true;\r\n text.text({\r\n text: label.text,\r\n fontSize: style.fontSize,\r\n // An empty family is left out, so the label takes the scene's own face.\r\n ...(style.fontFamily === \"\" ? {} : { fontFamily: style.fontFamily }),\r\n wrap: false,\r\n width,\r\n textAlign: align,\r\n x: align === \"center\" ? at.x : align === \"right\" ? at.x - width / 2 : at.x + width / 2,\r\n y: at.y,\r\n });\r\n }\r\n if (written) out.push(text.fill(fill));\r\n return out;\r\n}\r\n\r\n// A formula's glyphs with its box anchored at the label's point; `null` for one that will not typeset, which is then\r\n// drawn as written, and nothing at all while MathJax is still on its way: its source is not a stand-in for it.\r\nfunction typeset(source: string, { at, align }: Label, fontSize: number): Graphics2D[] | null {\r\n let formula: ReturnType<typeof buildLatexPath>;\r\n try {\r\n formula = buildLatexPath(source, fontSize);\r\n } catch (error) {\r\n return error instanceof LatexNotLoaded ? [] : null;\r\n }\r\n const [minX, minY, maxX, maxY] = formula.bounds;\r\n const dx = at.x + (align === \"left\" ? formula.width / 2 : align === \"right\" ? -formula.width / 2 : 0);\r\n // Glyph paths are y-down; the frame whose centre lands on the node's is shifted the other way.\r\n const frame: [number, number, number, number] = [minX - dx, minY + at.y, maxX - dx, maxY + at.y];\r\n return formula.tokens.map((token) => new Graphics2D().path({ data: toPathString(token.path), centerBounds: frame }));\r\n}\r\n\r\n/** Whether a mark `u` of the way along an axis is inside the part of it drawn so far. */\r\nexport function drawn(u: number, start: number, end: number): boolean {\r\n return u >= start - 1e-9 && u <= end + 1e-9;\r\n}\r\n\r\n/** How far along `range` a value is, 0 to 1, by pixel distance. */\r\nexport function along(at: Vector2, from: Vector2, to: Vector2): number {\r\n const dx = to.x - from.x;\r\n const dy = to.y - from.y;\r\n const length = dx * dx + dy * dy;\r\n return length === 0 ? 0 : ((at.x - from.x) * dx + (at.y - from.y) * dy) / length;\r\n}\r\n\r\nexport function lerpInterval(from: Interval, to: Interval, t: number): Interval {\r\n return [from[0] + (to[0] - from[0]) * t, from[1] + (to[1] - from[1]) * t];\r\n}\r\n\r\nexport function readInterval(value: Interval | undefined, previous?: Interval): Interval {\r\n const [min, max] = Array.isArray(value) ? value : (previous ?? [0, 1]);\r\n return [Number(min), Number(max)];\r\n}\r\n"]}
@@ -0,0 +1,13 @@
1
+ import type { Extents, PathCommand, Vector2 } from "@motionscript/sdk";
2
+ /**
3
+ * Runs of pixel points as path commands. Commands are y-up like every other
4
+ * `Graphics2D` op (only an SVG `d` string is y-down), so nothing is flipped here.
5
+ */
6
+ export declare function runsToPath(runs: readonly (readonly Vector2[])[], closed?: boolean): PathCommand[];
7
+ export declare function boundsOfRuns(runs: readonly (readonly Vector2[])[]): Extents | null;
8
+ /** `area` grown by `margin` on every side. */
9
+ export declare function inflate(area: Extents, margin: number): Extents;
10
+ export declare function clamp(value: number, min: number, max: number): number;
11
+ /** `data` without the arguments a command was not given, which arrive as `undefined` and are not destinations. */
12
+ export declare function stated<T extends object>(data: T | undefined): Partial<T>;
13
+ //# sourceMappingURL=geometry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../../src/kit/geometry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEvE;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,UAAQ,GAAG,WAAW,EAAE,CAS/F;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,OAAO,EAAE,CAAC,EAAE,GAAG,OAAO,GAAG,IAAI,CAYlF;AAED,8CAA8C;AAC9C,wBAAgB,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAE9D;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,kHAAkH;AAClH,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC,CAOxE"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Runs of pixel points as path commands. Commands are y-up like every other
3
+ * `Graphics2D` op (only an SVG `d` string is y-down), so nothing is flipped here.
4
+ */
5
+ export function runsToPath(runs, closed = false) {
6
+ const out = [];
7
+ for (const run of runs) {
8
+ if (run.length < 2)
9
+ continue;
10
+ out.push({ type: "M", x: run[0].x, y: run[0].y });
11
+ for (let i = 1; i < run.length; i++)
12
+ out.push({ type: "L", x: run[i].x, y: run[i].y });
13
+ if (closed)
14
+ out.push({ type: "Z" });
15
+ }
16
+ return out;
17
+ }
18
+ export function boundsOfRuns(runs) {
19
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
20
+ for (const run of runs) {
21
+ if (run.length < 2)
22
+ continue;
23
+ for (const p of run) {
24
+ if (p.x < minX)
25
+ minX = p.x;
26
+ if (p.x > maxX)
27
+ maxX = p.x;
28
+ if (p.y < minY)
29
+ minY = p.y;
30
+ if (p.y > maxY)
31
+ maxY = p.y;
32
+ }
33
+ }
34
+ return minX <= maxX ? { minX, minY, maxX, maxY } : null;
35
+ }
36
+ /** `area` grown by `margin` on every side. */
37
+ export function inflate(area, margin) {
38
+ return { minX: area.minX - margin, minY: area.minY - margin, maxX: area.maxX + margin, maxY: area.maxY + margin };
39
+ }
40
+ export function clamp(value, min, max) {
41
+ return value < min ? min : value > max ? max : value;
42
+ }
43
+ /** `data` without the arguments a command was not given, which arrive as `undefined` and are not destinations. */
44
+ export function stated(data) {
45
+ const out = {};
46
+ if (!data)
47
+ return out;
48
+ for (const key of Object.keys(data)) {
49
+ if (data[key] !== undefined)
50
+ out[key] = data[key];
51
+ }
52
+ return out;
53
+ }
54
+ //# sourceMappingURL=geometry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometry.js","sourceRoot":"","sources":["../../src/kit/geometry.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,IAAqC,EAAE,MAAM,GAAG,KAAK;IAC5E,MAAM,GAAG,GAAkB,EAAE,CAAC;IAC9B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACrB,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC;YAAE,SAAS;QAC7B,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAClD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAA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,EAAE,IAAI,CAAC,IAAI,GAAG,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,GAAG,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,GAAG,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,GAAG,MAAM,EAAE,CAAC;AACtH,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,KAAa,EAAE,GAAW,EAAE,GAAW;IACzD,OAAO,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC;AACzD,CAAC;AAED,kHAAkH;AAClH,MAAM,UAAU,MAAM,CAAmB,IAAmB;IACxD,MAAM,GAAG,GAAe,EAAE,CAAC;IAC3B,IAAI,CAAC,IAAI;QAAE,OAAO,GAAG,CAAC;IACtB,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAgB,EAAE,CAAC;QACjD,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,SAAS;YAAE,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IACtD,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC","sourcesContent":["import type { Extents, PathCommand, Vector2 } from \"@motionscript/sdk\";\r\n\r\n/**\r\n * Runs of pixel points as path commands. Commands are y-up like every other\r\n * `Graphics2D` op (only an SVG `d` string is y-down), so nothing is flipped here.\r\n */\r\nexport function runsToPath(runs: readonly (readonly Vector2[])[], closed = false): PathCommand[] {\r\n const out: PathCommand[] = [];\r\n for (const run of runs) {\r\n if (run.length < 2) continue;\r\n out.push({ type: \"M\", x: run[0].x, y: run[0].y });\r\n for (let i = 1; i < run.length; i++) out.push({ type: \"L\", x: run[i].x, y: run[i].y });\r\n if (closed) out.push({ type: \"Z\" });\r\n }\r\n return out;\r\n}\r\n\r\nexport function boundsOfRuns(runs: readonly (readonly Vector2[])[]): Extents | null {\r\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\r\n for (const run of runs) {\r\n if (run.length < 2) continue;\r\n for (const p of run) {\r\n if (p.x < minX) minX = p.x;\r\n if (p.x > maxX) maxX = p.x;\r\n if (p.y < minY) minY = p.y;\r\n if (p.y > maxY) maxY = p.y;\r\n }\r\n }\r\n return minX <= maxX ? { minX, minY, maxX, maxY } : null;\r\n}\r\n\r\n/** `area` grown by `margin` on every side. */\r\nexport function inflate(area: Extents, margin: number): Extents {\r\n return { minX: area.minX - margin, minY: area.minY - margin, maxX: area.maxX + margin, maxY: area.maxY + margin };\r\n}\r\n\r\nexport function clamp(value: number, min: number, max: number): number {\r\n return value < min ? min : value > max ? max : value;\r\n}\r\n\r\n/** `data` without the arguments a command was not given, which arrive as `undefined` and are not destinations. */\r\nexport function stated<T extends object>(data: T | undefined): Partial<T> {\r\n const out: Partial<T> = {};\r\n if (!data) return out;\r\n for (const key of Object.keys(data) as (keyof T)[]) {\r\n if (data[key] !== undefined) out[key] = data[key];\r\n }\r\n return out;\r\n}\r\n"]}