@motionscript/math 0.1.0 → 0.1.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (252) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/annotate/angle-mark.d.ts +4 -14
  3. package/dist/annotate/angle-mark.d.ts.map +1 -1
  4. package/dist/annotate/angle-mark.js +2 -1
  5. package/dist/annotate/angle-mark.js.map +1 -1
  6. package/dist/annotate/curly-brace.d.ts +4 -16
  7. package/dist/annotate/curly-brace.d.ts.map +1 -1
  8. package/dist/annotate/curly-brace.js.map +1 -1
  9. package/dist/annotate/emphasis-mark.d.ts +0 -5
  10. package/dist/annotate/emphasis-mark.d.ts.map +1 -1
  11. package/dist/annotate/emphasis-mark.js.map +1 -1
  12. package/dist/browser/chunks/chunk-FZ2YBTPL.js +2 -0
  13. package/dist/browser/chunks/chunk-FZ2YBTPL.js.map +7 -0
  14. package/dist/browser/chunks/chunk-T42HWKBC.js +2 -0
  15. package/dist/browser/chunks/chunk-T42HWKBC.js.map +7 -0
  16. package/dist/browser/chunks/{mathjax-WV55AC2P.js → mathjax-SOM6RSPV.js} +1 -1
  17. package/dist/browser/chunks/{mathjax-WV55AC2P.js.map → mathjax-SOM6RSPV.js.map} +2 -2
  18. package/dist/browser/index.js +1 -1
  19. package/dist/browser/index.js.map +3 -3
  20. package/dist/browser/kit.js +1 -1
  21. package/dist/browser/manifest.json +1 -1
  22. package/dist/browser/tex.js +1 -1
  23. package/dist/engine.d.ts +3 -4
  24. package/dist/engine.d.ts.map +1 -1
  25. package/dist/engine.js +3 -4
  26. package/dist/engine.js.map +1 -1
  27. package/dist/kit/cache.d.ts +10 -21
  28. package/dist/kit/cache.d.ts.map +1 -1
  29. package/dist/kit/cache.js +33 -24
  30. package/dist/kit/cache.js.map +1 -1
  31. package/dist/kit/component.d.ts +5 -14
  32. package/dist/kit/component.d.ts.map +1 -1
  33. package/dist/kit/component.js +1 -8
  34. package/dist/kit/component.js.map +1 -1
  35. package/dist/kit/coords.d.ts +1 -1
  36. package/dist/kit/coords.d.ts.map +1 -1
  37. package/dist/kit/coords.js +2 -1
  38. package/dist/kit/coords.js.map +1 -1
  39. package/dist/kit/curve.d.ts +1 -5
  40. package/dist/kit/curve.d.ts.map +1 -1
  41. package/dist/kit/curve.js.map +1 -1
  42. package/dist/kit/equation.d.ts +10 -30
  43. package/dist/kit/equation.d.ts.map +1 -1
  44. package/dist/kit/equation.js +9 -44
  45. package/dist/kit/equation.js.map +1 -1
  46. package/dist/kit/equation3d.d.ts +3 -3
  47. package/dist/kit/equation3d.d.ts.map +1 -1
  48. package/dist/kit/equation3d.js +27 -59
  49. package/dist/kit/equation3d.js.map +1 -1
  50. package/dist/kit/expression.d.ts +7 -7
  51. package/dist/kit/expression.d.ts.map +1 -1
  52. package/dist/kit/expression.js +18 -17
  53. package/dist/kit/expression.js.map +1 -1
  54. package/dist/kit/field-mark.d.ts +0 -7
  55. package/dist/kit/field-mark.d.ts.map +1 -1
  56. package/dist/kit/field-mark.js.map +1 -1
  57. package/dist/kit/field.d.ts +2 -2
  58. package/dist/kit/field.d.ts.map +1 -1
  59. package/dist/kit/field.js +11 -31
  60. package/dist/kit/field.js.map +1 -1
  61. package/dist/kit/follow.d.ts +3 -10
  62. package/dist/kit/follow.d.ts.map +1 -1
  63. package/dist/kit/follow.js +5 -11
  64. package/dist/kit/follow.js.map +1 -1
  65. package/dist/kit/furniture.d.ts +2 -1
  66. package/dist/kit/furniture.d.ts.map +1 -1
  67. package/dist/kit/furniture.js +6 -3
  68. package/dist/kit/furniture.js.map +1 -1
  69. package/dist/kit/geometry.d.ts +1 -0
  70. package/dist/kit/geometry.d.ts.map +1 -1
  71. package/dist/kit/geometry.js +3 -0
  72. package/dist/kit/geometry.js.map +1 -1
  73. package/dist/kit/mark.d.ts +4 -10
  74. package/dist/kit/mark.d.ts.map +1 -1
  75. package/dist/kit/mark.js.map +1 -1
  76. package/dist/kit/place.d.ts +3 -5
  77. package/dist/kit/place.d.ts.map +1 -1
  78. package/dist/kit/place.js +3 -5
  79. package/dist/kit/place.js.map +1 -1
  80. package/dist/kit/sampler.d.ts +0 -5
  81. package/dist/kit/sampler.d.ts.map +1 -1
  82. package/dist/kit/sampler.js.map +1 -1
  83. package/dist/kit/system.d.ts +0 -1
  84. package/dist/kit/system.d.ts.map +1 -1
  85. package/dist/kit/system.js +3 -10
  86. package/dist/kit/system.js.map +1 -1
  87. package/dist/marks/curve-area.d.ts +2 -12
  88. package/dist/marks/curve-area.d.ts.map +1 -1
  89. package/dist/marks/curve-area.js +4 -9
  90. package/dist/marks/curve-area.js.map +1 -1
  91. package/dist/marks/drop-lines.d.ts +1 -5
  92. package/dist/marks/drop-lines.d.ts.map +1 -1
  93. package/dist/marks/drop-lines.js.map +1 -1
  94. package/dist/marks/plot-point.d.ts +4 -13
  95. package/dist/marks/plot-point.d.ts.map +1 -1
  96. package/dist/marks/plot-point.js.map +1 -1
  97. package/dist/marks/riemann-sum.d.ts +1 -7
  98. package/dist/marks/riemann-sum.d.ts.map +1 -1
  99. package/dist/marks/riemann-sum.js +2 -2
  100. package/dist/marks/riemann-sum.js.map +1 -1
  101. package/dist/marks/tangent-line.d.ts +2 -12
  102. package/dist/marks/tangent-line.d.ts.map +1 -1
  103. package/dist/marks/tangent-line.js +1 -5
  104. package/dist/marks/tangent-line.js.map +1 -1
  105. package/dist/marks/vector-arrow.d.ts +2 -11
  106. package/dist/marks/vector-arrow.d.ts.map +1 -1
  107. package/dist/marks/vector-arrow.js +3 -6
  108. package/dist/marks/vector-arrow.js.map +1 -1
  109. package/dist/nodes.d.ts +1 -12
  110. package/dist/nodes.d.ts.map +1 -1
  111. package/dist/nodes.js.map +1 -1
  112. package/dist/plots/function-plot.d.ts +1 -6
  113. package/dist/plots/function-plot.d.ts.map +1 -1
  114. package/dist/plots/function-plot.js +1 -5
  115. package/dist/plots/function-plot.js.map +1 -1
  116. package/dist/plots/points-plot.d.ts +1 -6
  117. package/dist/plots/points-plot.d.ts.map +1 -1
  118. package/dist/plots/points-plot.js.map +1 -1
  119. package/dist/plots/stream-lines.d.ts +0 -7
  120. package/dist/plots/stream-lines.d.ts.map +1 -1
  121. package/dist/plots/stream-lines.js.map +1 -1
  122. package/dist/plots/traced-path.d.ts +1 -12
  123. package/dist/plots/traced-path.d.ts.map +1 -1
  124. package/dist/plots/traced-path.js +1 -6
  125. package/dist/plots/traced-path.js.map +1 -1
  126. package/dist/plots/vector-field.d.ts +1 -10
  127. package/dist/plots/vector-field.d.ts.map +1 -1
  128. package/dist/plots/vector-field.js +3 -6
  129. package/dist/plots/vector-field.js.map +1 -1
  130. package/dist/structures/network-graph.d.ts +15 -34
  131. package/dist/structures/network-graph.d.ts.map +1 -1
  132. package/dist/structures/network-graph.js +2 -5
  133. package/dist/structures/network-graph.js.map +1 -1
  134. package/dist/structures/sample-space.d.ts +8 -22
  135. package/dist/structures/sample-space.d.ts.map +1 -1
  136. package/dist/structures/sample-space.js +3 -5
  137. package/dist/structures/sample-space.js.map +1 -1
  138. package/dist/systems/axes2d.d.ts +0 -1
  139. package/dist/systems/axes2d.d.ts.map +1 -1
  140. package/dist/systems/axes2d.js +3 -4
  141. package/dist/systems/axes2d.js.map +1 -1
  142. package/dist/systems/number-line.d.ts +7 -22
  143. package/dist/systems/number-line.d.ts.map +1 -1
  144. package/dist/systems/number-line.js +2 -2
  145. package/dist/systems/number-line.js.map +1 -1
  146. package/dist/systems/number-plane.d.ts +12 -27
  147. package/dist/systems/number-plane.d.ts.map +1 -1
  148. package/dist/systems/number-plane.js +1 -7
  149. package/dist/systems/number-plane.js.map +1 -1
  150. package/dist/systems/polar-plane.d.ts +11 -26
  151. package/dist/systems/polar-plane.d.ts.map +1 -1
  152. package/dist/systems/polar-plane.js +7 -10
  153. package/dist/systems/polar-plane.js.map +1 -1
  154. package/dist/tex/geometry.d.ts +5 -24
  155. package/dist/tex/geometry.d.ts.map +1 -1
  156. package/dist/tex/geometry.js +19 -90
  157. package/dist/tex/geometry.js.map +1 -1
  158. package/dist/tex/mathjax.d.ts +0 -13
  159. package/dist/tex/mathjax.d.ts.map +1 -1
  160. package/dist/tex/mathjax.js +4 -24
  161. package/dist/tex/mathjax.js.map +1 -1
  162. package/dist/tex/matrix.d.ts +1 -10
  163. package/dist/tex/matrix.d.ts.map +1 -1
  164. package/dist/tex/matrix.js +1 -5
  165. package/dist/tex/matrix.js.map +1 -1
  166. package/dist/tex/tween.d.ts +9 -30
  167. package/dist/tex/tween.d.ts.map +1 -1
  168. package/dist/tex/tween.js +19 -67
  169. package/dist/tex/tween.js.map +1 -1
  170. package/dist/tex/typeset.d.ts +2 -23
  171. package/dist/tex/typeset.d.ts.map +1 -1
  172. package/dist/tex/typeset.js +4 -30
  173. package/dist/tex/typeset.js.map +1 -1
  174. package/dist/three/axes3d.d.ts +32 -62
  175. package/dist/three/axes3d.d.ts.map +1 -1
  176. package/dist/three/axes3d.js +5 -13
  177. package/dist/three/axes3d.js.map +1 -1
  178. package/dist/three/curve-plot3d.d.ts +4 -15
  179. package/dist/three/curve-plot3d.d.ts.map +1 -1
  180. package/dist/three/curve-plot3d.js.map +1 -1
  181. package/dist/three/plot-point3d.d.ts +7 -14
  182. package/dist/three/plot-point3d.d.ts.map +1 -1
  183. package/dist/three/plot-point3d.js.map +1 -1
  184. package/dist/three/space.d.ts +3 -8
  185. package/dist/three/space.d.ts.map +1 -1
  186. package/dist/three/space.js +1 -8
  187. package/dist/three/space.js.map +1 -1
  188. package/dist/three/surface-plot3d.d.ts +9 -23
  189. package/dist/three/surface-plot3d.d.ts.map +1 -1
  190. package/dist/three/surface-plot3d.js.map +1 -1
  191. package/dist/three/vector-arrow3d.d.ts +1 -7
  192. package/dist/three/vector-arrow3d.d.ts.map +1 -1
  193. package/dist/three/vector-arrow3d.js.map +1 -1
  194. package/package.json +4 -4
  195. package/src/annotate/angle-mark.ts +4 -14
  196. package/src/annotate/curly-brace.ts +2 -14
  197. package/src/annotate/emphasis-mark.ts +1 -6
  198. package/src/engine.ts +3 -4
  199. package/src/kit/cache.ts +33 -25
  200. package/src/kit/component.ts +5 -19
  201. package/src/kit/coords.ts +2 -2
  202. package/src/kit/curve.ts +1 -5
  203. package/src/kit/equation.ts +12 -50
  204. package/src/kit/equation3d.ts +23 -59
  205. package/src/kit/expression.ts +18 -23
  206. package/src/kit/field-mark.ts +1 -7
  207. package/src/kit/field.ts +10 -26
  208. package/src/kit/follow.ts +5 -13
  209. package/src/kit/furniture.ts +7 -4
  210. package/src/kit/geometry.ts +4 -0
  211. package/src/kit/mark.ts +4 -11
  212. package/src/kit/place.ts +3 -5
  213. package/src/kit/sampler.ts +0 -6
  214. package/src/kit/system.ts +3 -12
  215. package/src/marks/curve-area.ts +3 -16
  216. package/src/marks/drop-lines.ts +0 -6
  217. package/src/marks/plot-point.ts +2 -12
  218. package/src/marks/riemann-sum.ts +2 -10
  219. package/src/marks/tangent-line.ts +1 -13
  220. package/src/marks/vector-arrow.ts +3 -13
  221. package/src/nodes.ts +1 -12
  222. package/src/plots/function-plot.ts +1 -6
  223. package/src/plots/points-plot.ts +0 -7
  224. package/src/plots/stream-lines.ts +1 -8
  225. package/src/plots/traced-path.ts +2 -13
  226. package/src/plots/vector-field.ts +4 -12
  227. package/src/structures/network-graph.ts +6 -25
  228. package/src/structures/sample-space.ts +5 -20
  229. package/src/systems/axes2d.ts +3 -6
  230. package/src/systems/number-line.ts +4 -20
  231. package/src/systems/number-plane.ts +4 -19
  232. package/src/systems/polar-plane.ts +11 -25
  233. package/src/tex/geometry.ts +24 -126
  234. package/src/tex/mathjax.ts +4 -26
  235. package/src/tex/matrix.ts +1 -11
  236. package/src/tex/tween.ts +21 -75
  237. package/src/tex/typeset.ts +4 -37
  238. package/src/three/axes3d.ts +7 -42
  239. package/src/three/curve-plot3d.ts +0 -12
  240. package/src/three/plot-point3d.ts +0 -10
  241. package/src/three/space.ts +2 -11
  242. package/src/three/surface-plot3d.ts +0 -15
  243. package/src/three/vector-arrow3d.ts +0 -8
  244. package/dist/browser/chunks/chunk-IRZCG6PM.js +0 -2
  245. package/dist/browser/chunks/chunk-IRZCG6PM.js.map +0 -7
  246. package/dist/browser/chunks/chunk-WMVW6ZIV.js +0 -2
  247. package/dist/browser/chunks/chunk-WMVW6ZIV.js.map +0 -7
  248. package/dist/kit/withdrawn.d.ts +0 -9
  249. package/dist/kit/withdrawn.d.ts.map +0 -1
  250. package/dist/kit/withdrawn.js +0 -9
  251. package/dist/kit/withdrawn.js.map +0 -1
  252. package/src/kit/withdrawn.ts +0 -8
@@ -1 +1 @@
1
- {"version":3,"file":"number-plane.js","sourceRoot":"","sources":["../../src/systems/number-plane.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,UAAU,EACV,KAAK,GAcR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACH,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,UAAU,EACV,cAAc,EACd,SAAS,GAIZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAmB,MAAM,eAAe,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChH,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAsD,MAAM,UAAU,CAAC;AAY7I,MAAM,KAAK,GAAG;IACV,GAAG,IAAI;IACP,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IAChD,8BAA8B;IAC9B,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,SAA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G,SAAS,MAAM,CAAC,MAAc;IAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IACpF,IAAI,CAAC,KAAK,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,IAAI,CAAC;IAClD,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC;IACvB,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE;QACnB,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QACrB,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QACrB,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QACX,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QACX,OAAO,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACtD,CAAC,CAAC;AACN,CAAC","sourcesContent":["import {\n component2d,\n Graphics2D,\n Types,\n type Extents,\n type NodeOf,\n type Stroke,\n type StrokeResolved,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Color as _Color,\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type NormalizedColor as _NormalizedColor,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n} from \"@motionscript/sdk\";\nimport {\n isIdentityMatrix,\n lerpMatrix,\n lineThrough,\n readMatrix,\n transformedMap,\n warpedMap,\n type CoordinateMap,\n type Matrix2,\n type Warp,\n} from \"../kit/coords\";\nimport { fieldParams, parseField } from \"../kit/field\";\nimport { AXIS_COLOR } from \"../kit/furniture\";\nimport { lerpSource, readSource, type PlotSource } from \"../kit/source\";\nimport { drawSystem, plotArea, systemLayout, systemOpenPlane, systemProvides, systemSize } from \"../kit/system\";\nimport { AXES, AXES_COMMANDS, axesFurniture, axesMap, axesOf, loadAxes, type Axes2dProps, type AxesValues, type AxisLayout } from \"./axes2d\";\n\nexport interface NumberPlaneProps extends Axes2dProps {\n grid?: boolean;\n gridStroke?: Stroke;\n minorStroke?: Stroke;\n minorDivisions?: number;\n matrix?: Matrix2 | readonly (readonly number[])[];\n warp?: string | PlotSource;\n ghost?: boolean;\n}\n\nconst state = {\n ...AXES,\n grid: Types.boolean(true, { animatable: false }),\n /** The line at every tick. */\n gridStroke: Types.stroke({ weight: 1.5, fill: \"#3b4658\", align: \"center\" }),\n /** The lines between ticks. */\n minorStroke: Types.stroke({ weight: 1, fill: \"#232b38\", align: \"center\" }),\n /** How many parts the space between two ticks is cut into; one draws no line between them. */\n minorDivisions: Types.number(2, { min: 1, max: 10, step: 1 }),\n /** A linear map of the plane, row by row: `[a, b, c, d]` sends `(x, y)` to `(ax + by, cx + dy)`. */\n matrix: Types.custom<Matrix2 | readonly (readonly number[])[], Matrix2>([1, 0, 0, 1], { resolve: readMatrix, lerp: lerpMatrix }),\n /**\n * Where each point of the plane is sent, two parts in x and y:\n * `(x + sin(y), y + sin(x))`. Empty leaves the plane flat.\n */\n warp: Types.custom<string | PlotSource, PlotSource>(\"\", { resolve: readSource, lerp: lerpSource, kind: \"fieldEquation\" }),\n /** Leave the plane as it was, faintly, behind one that has been transformed or warped. */\n ghost: Types.boolean(true, { animatable: false }),\n};\n\ntype PlaneValues = AxesValues & {\n readonly grid: boolean;\n readonly gridStroke: StrokeResolved[];\n readonly minorStroke: StrokeResolved[];\n readonly minorDivisions: number;\n readonly matrix: Matrix2;\n readonly warp: PlotSource;\n readonly ghost: boolean;\n};\n\n/**\n * Axes over a full grid, with square units unless told otherwise: the plane\n * vectors and transformations are drawn on. Its `matrix` shears, turns or\n * squeezes the whole plane about its origin, and its `warp` bends it by a\n * function of its own points; the grid, the axes and everything on the plane\n * go with it.\n */\nexport const NumberPlane = component2d({\n key: \"numberPlane\",\n state,\n defaults: {\n squareUnits: true,\n stroke: { weight: 2, fill: AXIS_COLOR, align: \"center\" },\n // A transformed plane reaches past its box, and so does what is on it: both are kept in unless told otherwise.\n clip: (s) => spills(s),\n },\n load: (loader, s) => loadAxes(loader, s),\n commands: {\n ...AXES_COMMANDS,\n /** Send the plane through a matrix: a shear, a turn, a squeeze, a flip. */\n transformTo: { args: [\"matrix\"] },\n /** Bend the plane, each point travelling to where the warp sends it; an empty one flattens it again. */\n warpTo: { args: [\"warp\"] },\n },\n provide: (s) => systemProvides(s),\n measure: (_measurer, s) => systemSize(s),\n layout: (box, s, children) => systemLayout(box, s, children, planeMap),\n plane: (box, s) => systemOpenPlane(box, s, planeMap),\n render: (ctx, s) => {\n const { flat, map } = planeMaps(plotArea(ctx.size, s.padding), s);\n drawSystem(ctx, s, map, (on) => axesFurniture(on, s, (x, y) => grid(s, flat, on, x, y)));\n },\n});\n\nexport type NumberPlane = NodeOf<typeof NumberPlane>;\n\n/** The plane's map on a plot area: the flat one, sent through its matrix and its warp. */\nexport function planeMap(area: Extents, s: PlaneValues): CoordinateMap {\n return planeMaps(area, s).map;\n}\n\n/** The flat plane on a plot area, and the plane as its matrix and its warp have it. */\nfunction planeMaps(area: Extents, s: PlaneValues): { flat: CoordinateMap; map: CoordinateMap } {\n const flat = axesMap(area, s);\n const map = isIdentityMatrix(s.matrix) ? flat : transformedMap(flat, s.matrix);\n const { source, blend } = s.warp;\n const to = warpOf(source);\n if (!blend) return { flat, map: to ? warpedMap(map, to, source) : map };\n // Mid-warp each point is part of the way from where the old warp had it to where the new one sends it.\n const from = warpOf(blend.from);\n if (!from && !to) return { flat, map };\n const start = { x: 0, y: 0 };\n return {\n flat,\n map: warpedMap(\n map,\n (x, y, out) => {\n if (!(from ?? STAY)(x, y, start) || !(to ?? STAY)(x, y, out)) return false;\n out.x = start.x + (out.x - start.x) * blend.t;\n out.y = start.y + (out.y - start.y) * blend.t;\n return true;\n },\n `${blend.from}>${source}@${blend.t}`,\n ),\n };\n}\n\n/** Whether the plane reaches past its box: it is transformed or warped. */\nfunction spills(s: PlaneValues): boolean {\n if (!isIdentityMatrix(s.matrix)) return true;\n const { source, blend } = s.warp;\n return warpOf(source) !== null || (blend !== undefined && warpOf(blend.from) !== null);\n}\n\n/** The grid behind the axes, with the flat plane faintly behind a transformed one. */\nfunction grid(s: PlaneValues, flat: CoordinateMap, map: CoordinateMap, x: AxisLayout, y: AxisLayout): Graphics2D[] {\n if (!s.grid) return [];\n const parts: Graphics2D[] = [];\n if (s.ghost && flat.revision !== map.revision) {\n const [gx, gy] = axesOf(flat, s);\n parts.push(...ruled(s, flat, gx, gy, true));\n }\n parts.push(...ruled(s, map, x, y, false));\n return parts;\n}\n\n/** The grid of `map`: every line, or only the ones at a tick, in the fainter stroke, for a ghost. */\nfunction ruled(s: PlaneValues, map: CoordinateMap, x: AxisLayout, y: AxisLayout, ghost: boolean): Graphics2D[] {\n const { start, end } = s;\n const [xMin, xMax] = map.xRange;\n const [yMin, yMax] = map.yRange;\n const lines = (values: readonly number[], vertical: boolean): Graphics2D => {\n const g = new Graphics2D();\n for (const value of values) {\n g.line({\n points: vertical ? lineThrough(map, value, yMin, value, yMax) : lineThrough(map, xMin, value, xMax, value),\n radius: 0,\n start,\n end,\n });\n }\n return g;\n };\n const parts: Graphics2D[] = [];\n const minor = s.minorStroke;\n if (ghost) {\n if (minor.length === 0) return parts;\n if (x.marks.values.length > 0) parts.push(lines(x.marks.values, true).stroke(minor));\n if (y.marks.values.length > 0) parts.push(lines(y.marks.values, false).stroke(minor));\n return parts;\n }\n const divisions = Math.round(s.minorDivisions);\n if (minor.length > 0 && divisions > 1) {\n const between = (axis: AxisLayout, [min, max]: readonly [number, number]): number[] => {\n const { step, values } = axis.marks;\n if (!(step > 0) || values.length === 0) return [];\n const out: number[] = [];\n for (let base = values[0] - step; base < max; base += step) {\n for (let i = 1; i < divisions; i++) {\n const value = base + (step * i) / divisions;\n if (value > min && value < max) out.push(value);\n }\n }\n return out;\n };\n const xs = between(x, map.xRange);\n const ys = between(y, map.yRange);\n if (xs.length > 0) parts.push(lines(xs, true).stroke(minor));\n if (ys.length > 0) parts.push(lines(ys, false).stroke(minor));\n }\n const major = s.gridStroke;\n if (major.length > 0) {\n if (x.marks.values.length > 0) parts.push(lines(x.marks.values, true).stroke(major));\n if (y.marks.values.length > 0) parts.push(lines(y.marks.values, false).stroke(major));\n }\n return parts;\n}\n\nconst STAY: Warp = (x, y, out) => {\n out.x = x;\n out.y = y;\n return true;\n};\n\n/** `source` as a warp, or `null` for text that is empty or not a field: the plane is then left as it is. */\nfunction warpOf(source: string): Warp | null {\n const field = source.trim() === \"\" ? null : parseField(source, fieldParams(source));\n if (!field || field instanceof Error) return null;\n const { x, y } = field;\n return (gx, gy, out) => {\n const wx = x(gx, gy);\n const wy = y(gx, gy);\n out.x = wx;\n out.y = wy;\n return Number.isFinite(wx) && Number.isFinite(wy);\n };\n}\n"]}
1
+ {"version":3,"file":"number-plane.js","sourceRoot":"","sources":["../../src/systems/number-plane.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,UAAU,EACV,KAAK,GAeR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACH,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,UAAU,EACV,cAAc,EACd,SAAS,GAIZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAmB,MAAM,eAAe,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChH,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM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AC,CAAC;IAC1F,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,MAAM,IAAI,GAAS,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE;IAC7B,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IACV,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AAEF,4GAA4G;AAC5G,SAAS,MAAM,CAAC,MAAc;IAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IACpF,IAAI,CAAC,KAAK,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,IAAI,CAAC;IAClD,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC;IACvB,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE;QACnB,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QACrB,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QACrB,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QACX,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QACX,OAAO,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACtD,CAAC,CAAC;AACN,CAAC","sourcesContent":["import {\n component2d,\n Graphics2D,\n Types,\n type Extents,\n type NodeOf,\n type Stroke as _Stroke,\n\n type StrokeResolved,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Color as _Color,\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type NormalizedColor as _NormalizedColor,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n} from \"@motionscript/sdk\";\nimport {\n isIdentityMatrix,\n lerpMatrix,\n lineThrough,\n readMatrix,\n transformedMap,\n warpedMap,\n type CoordinateMap,\n type Matrix2,\n type Warp,\n} from \"../kit/coords\";\nimport { fieldParams, parseField } from \"../kit/field\";\nimport { AXIS_COLOR } from \"../kit/furniture\";\nimport { lerpSource, readSource, type PlotSource } from \"../kit/source\";\nimport { drawSystem, plotArea, systemLayout, systemOpenPlane, systemProvides, systemSize } from \"../kit/system\";\nimport { AXES, AXES_COMMANDS, axesFurniture, axesMap, axesOf, loadAxes, type AxesValues, type AxisLayout } from \"./axes2d\";\n\nconst state = {\n ...AXES,\n grid: Types.boolean(true, { animatable: false }),\n /** The line at every tick. */\n gridStroke: Types.stroke({ weight: 1.5, fill: \"#3b4658\", align: \"center\" }),\n /** The lines between ticks. */\n minorStroke: Types.stroke({ weight: 1, fill: \"#232b38\", align: \"center\" }),\n /** How many parts the space between two ticks is cut into; one draws no line between them. */\n minorDivisions: Types.number(2, { min: 1, max: 10, step: 1 }),\n /** A linear map of the plane, row by row: `[a, b, c, d]` sends `(x, y)` to `(ax + by, cx + dy)`. */\n matrix: Types.custom<Matrix2 | readonly (readonly number[])[], Matrix2>([1, 0, 0, 1], { resolve: readMatrix, lerp: lerpMatrix }),\n /**\n * Where each point of the plane is sent, two parts in x and y:\n * `(x + sin(y), y + sin(x))`. Empty leaves the plane flat.\n */\n warp: Types.custom<string | PlotSource, PlotSource>(\"\", { resolve: readSource, lerp: lerpSource, kind: \"fieldEquation\" }),\n /** Leave the plane as it was, faintly, behind one that has been transformed or warped. */\n ghost: Types.boolean(true, { animatable: false }),\n};\n\ntype PlaneValues = AxesValues & {\n readonly grid: boolean;\n readonly gridStroke: StrokeResolved[];\n readonly minorStroke: StrokeResolved[];\n readonly minorDivisions: number;\n readonly matrix: Matrix2;\n readonly warp: PlotSource;\n readonly ghost: boolean;\n};\n\n/** Axes over a full grid with square units: the plane vectors and transformations are drawn on. `matrix` and `warp` move the grid, the axes and everything on the plane. */\nexport const NumberPlane = component2d({\n key: \"numberPlane\",\n state,\n defaults: {\n squareUnits: true,\n stroke: { weight: 2, fill: AXIS_COLOR, align: \"center\" },\n // A transformed plane reaches past its box, and so does what is on it: both are kept in unless told otherwise.\n clip: (s) => spills(s),\n },\n load: (loader, s) => loadAxes(loader, s),\n commands: {\n ...AXES_COMMANDS,\n /** Send the plane through a matrix: a shear, a turn, a squeeze, a flip. */\n transformTo: { args: [\"matrix\"] },\n /** Bend the plane, each point travelling to where the warp sends it; an empty one flattens it again. */\n warpTo: { args: [\"warp\"] },\n },\n provide: (s) => systemProvides(s),\n measure: (_measurer, s) => systemSize(s),\n layout: (box, s, children) => systemLayout(box, s, children, planeMap),\n plane: (box, s) => systemOpenPlane(box, s, planeMap),\n render: (ctx, s) => {\n const { flat, map } = planeMaps(plotArea(ctx.size, s.padding), s);\n drawSystem(ctx, s, map, (on) => axesFurniture(on, s, (x, y) => grid(s, flat, on, x, y)));\n },\n});\n\nexport type NumberPlane = NodeOf<typeof NumberPlane>;\n\n/** The plane's map on a plot area: the flat one, sent through its matrix and its warp. */\nexport function planeMap(area: Extents, s: PlaneValues): CoordinateMap {\n return planeMaps(area, s).map;\n}\n\n/** The flat plane on a plot area, and the plane as its matrix and its warp have it. */\nfunction planeMaps(area: Extents, s: PlaneValues): { flat: CoordinateMap; map: CoordinateMap } {\n const flat = axesMap(area, s);\n const map = isIdentityMatrix(s.matrix) ? flat : transformedMap(flat, s.matrix);\n const { source, blend } = s.warp;\n const to = warpOf(source);\n if (!blend) return { flat, map: to ? warpedMap(map, to, source) : map };\n // Mid-warp each point is part of the way from where the old warp had it to where the new one sends it.\n const from = warpOf(blend.from);\n if (!from && !to) return { flat, map };\n const start = { x: 0, y: 0 };\n return {\n flat,\n map: warpedMap(\n map,\n (x, y, out) => {\n if (!(from ?? STAY)(x, y, start) || !(to ?? STAY)(x, y, out)) return false;\n out.x = start.x + (out.x - start.x) * blend.t;\n out.y = start.y + (out.y - start.y) * blend.t;\n return true;\n },\n `${blend.from}>${source}@${blend.t}`,\n ),\n };\n}\n\n/** Whether the plane reaches past its box: it is transformed or warped. */\nfunction spills(s: PlaneValues): boolean {\n if (!isIdentityMatrix(s.matrix)) return true;\n const { source, blend } = s.warp;\n return warpOf(source) !== null || (blend !== undefined && warpOf(blend.from) !== null);\n}\n\n/** The grid behind the axes, with the flat plane faintly behind a transformed one. */\nfunction grid(s: PlaneValues, flat: CoordinateMap, map: CoordinateMap, x: AxisLayout, y: AxisLayout): Graphics2D[] {\n if (!s.grid) return [];\n const parts: Graphics2D[] = [];\n if (s.ghost && flat.revision !== map.revision) {\n const [gx, gy] = axesOf(flat, s);\n parts.push(...ruled(s, flat, gx, gy, true));\n }\n parts.push(...ruled(s, map, x, y, false));\n return parts;\n}\n\n/** The grid of `map`: every line, or only the ones at a tick, in the fainter stroke, for a ghost. */\nfunction ruled(s: PlaneValues, map: CoordinateMap, x: AxisLayout, y: AxisLayout, ghost: boolean): Graphics2D[] {\n const { start, end } = s;\n const [xMin, xMax] = map.xRange;\n const [yMin, yMax] = map.yRange;\n const lines = (values: readonly number[], vertical: boolean): Graphics2D => {\n const g = new Graphics2D();\n for (const value of values) {\n g.line({\n points: vertical ? lineThrough(map, value, yMin, value, yMax) : lineThrough(map, xMin, value, xMax, value),\n radius: 0,\n start,\n end,\n });\n }\n return g;\n };\n const parts: Graphics2D[] = [];\n const minor = s.minorStroke;\n if (ghost) {\n if (minor.length === 0) return parts;\n if (x.marks.values.length > 0) parts.push(lines(x.marks.values, true).stroke(minor));\n if (y.marks.values.length > 0) parts.push(lines(y.marks.values, false).stroke(minor));\n return parts;\n }\n const divisions = Math.round(s.minorDivisions);\n if (minor.length > 0 && divisions > 1) {\n const between = (axis: AxisLayout, [min, max]: readonly [number, number]): number[] => {\n const { step, values } = axis.marks;\n if (!(step > 0) || values.length === 0) return [];\n const out: number[] = [];\n for (let base = values[0] - step; base < max; base += step) {\n for (let i = 1; i < divisions; i++) {\n const value = base + (step * i) / divisions;\n if (value > min && value < max) out.push(value);\n }\n }\n return out;\n };\n const xs = between(x, map.xRange);\n const ys = between(y, map.yRange);\n if (xs.length > 0) parts.push(lines(xs, true).stroke(minor));\n if (ys.length > 0) parts.push(lines(ys, false).stroke(minor));\n }\n const major = s.gridStroke;\n if (major.length > 0) {\n if (x.marks.values.length > 0) parts.push(lines(x.marks.values, true).stroke(major));\n if (y.marks.values.length > 0) parts.push(lines(y.marks.values, false).stroke(major));\n }\n return parts;\n}\n\nconst STAY: Warp = (x, y, out) => {\n out.x = x;\n out.y = y;\n return true;\n};\n\n/** `source` as a warp, or `null` for text that is empty or not a field: the plane is then left as it is. */\nfunction warpOf(source: string): Warp | null {\n const field = source.trim() === \"\" ? null : parseField(source, fieldParams(source));\n if (!field || field instanceof Error) return null;\n const { x, y } = field;\n return (gx, gy, out) => {\n const wx = x(gx, gy);\n const wy = y(gx, gy);\n out.x = wx;\n out.y = wy;\n return Number.isFinite(wx) && Number.isFinite(wy);\n };\n}\n"]}
@@ -1,20 +1,5 @@
1
- import { type Color, type NodeOf, type NormalizedColor, type PaintProps, type Stroke, type StrokeResolved, type Fill as _Fill, type FillResolved as _FillResolved, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Shadow as _Shadow, type ShadowResolved as _ShadowResolved } from "@motionscript/sdk";
2
- export interface PolarPlaneProps extends PaintProps {
3
- radius?: number;
4
- ringStep?: number;
5
- spokes?: number;
6
- angleUnit?: "degrees" | "radians";
7
- gridStroke?: Stroke;
8
- labels?: boolean;
9
- labelSize?: number;
10
- labelColor?: Color;
11
- fontFamily?: string;
12
- }
13
- /**
14
- * Rings and spokes about an origin: the plane a polar curve is read on.
15
- * Children sit in its graph coordinates, x and y in the units its rings count,
16
- * so a plot of `r = 1 + cos(theta)`, a point or an arrow goes on it as on axes.
17
- */
1
+ import { type NodeOf, type Color as _Color, type NormalizedColor, type Stroke as _Stroke, type StrokeResolved, type Fill as _Fill, type FillResolved as _FillResolved, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Shadow as _Shadow, type ShadowResolved as _ShadowResolved } from "@motionscript/sdk";
2
+ /** Rings and spokes about an origin: the plane a polar curve is read on. Children sit in its graph coordinates, as on axes. */
18
3
  export declare const PolarPlane: import("@motionscript/sdk").Component<"polarPlane", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
19
4
  /** The radius of the outermost ring, in graph units. */
20
5
  radius: import("@motionscript/sdk").Type<number, number, false>;
@@ -24,14 +9,14 @@ export declare const PolarPlane: import("@motionscript/sdk").Component<"polarPla
24
9
  spokes: import("@motionscript/sdk").Type<number, number, false>;
25
10
  angleUnit: import("@motionscript/sdk").Type<"degrees" | "radians", "degrees" | "radians", false>;
26
11
  /** The inner rings and the spokes. */
27
- gridStroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
12
+ gridStroke: import("@motionscript/sdk").Type<_Stroke, StrokeResolved[], false>;
28
13
  /** A number at each ring, and an angle at each spoke. */
29
14
  labels: import("@motionscript/sdk").Type<boolean, boolean, false>;
30
15
  labelSize: import("@motionscript/sdk").Type<number, number, false>;
31
- labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
16
+ labelColor: import("@motionscript/sdk").Type<_Color, NormalizedColor, false>;
32
17
  fontFamily: import("@motionscript/sdk").Type<string, string, false>;
33
18
  fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
34
- stroke: import("@motionscript/sdk").Attribute<Stroke, StrokeResolved[]>;
19
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, StrokeResolved[]>;
35
20
  shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
36
21
  start: import("@motionscript/sdk").Type<number, number, false>;
37
22
  end: import("@motionscript/sdk").Type<number, number, false>;
@@ -53,14 +38,14 @@ export declare const PolarPlane: import("@motionscript/sdk").Component<"polarPla
53
38
  spokes: import("@motionscript/sdk").Type<number, number, false>;
54
39
  angleUnit: import("@motionscript/sdk").Type<"degrees" | "radians", "degrees" | "radians", false>;
55
40
  /** The inner rings and the spokes. */
56
- gridStroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
41
+ gridStroke: import("@motionscript/sdk").Type<_Stroke, StrokeResolved[], false>;
57
42
  /** A number at each ring, and an angle at each spoke. */
58
43
  labels: import("@motionscript/sdk").Type<boolean, boolean, false>;
59
44
  labelSize: import("@motionscript/sdk").Type<number, number, false>;
60
- labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
45
+ labelColor: import("@motionscript/sdk").Type<_Color, NormalizedColor, false>;
61
46
  fontFamily: import("@motionscript/sdk").Type<string, string, false>;
62
47
  fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
63
- stroke: import("@motionscript/sdk").Attribute<Stroke, StrokeResolved[]>;
48
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, StrokeResolved[]>;
64
49
  shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
65
50
  start: import("@motionscript/sdk").Type<number, number, false>;
66
51
  end: import("@motionscript/sdk").Type<number, number, false>;
@@ -73,14 +58,14 @@ export declare const PolarPlane: import("@motionscript/sdk").Component<"polarPla
73
58
  spokes: import("@motionscript/sdk").Type<number, number, false>;
74
59
  angleUnit: import("@motionscript/sdk").Type<"degrees" | "radians", "degrees" | "radians", false>;
75
60
  /** The inner rings and the spokes. */
76
- gridStroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
61
+ gridStroke: import("@motionscript/sdk").Type<_Stroke, StrokeResolved[], false>;
77
62
  /** A number at each ring, and an angle at each spoke. */
78
63
  labels: import("@motionscript/sdk").Type<boolean, boolean, false>;
79
64
  labelSize: import("@motionscript/sdk").Type<number, number, false>;
80
- labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
65
+ labelColor: import("@motionscript/sdk").Type<_Color, NormalizedColor, false>;
81
66
  fontFamily: import("@motionscript/sdk").Type<string, string, false>;
82
67
  fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
83
- stroke: import("@motionscript/sdk").Attribute<Stroke, StrokeResolved[]>;
68
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, StrokeResolved[]>;
84
69
  shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
85
70
  start: import("@motionscript/sdk").Type<number, number, false>;
86
71
  end: import("@motionscript/sdk").Type<number, number, false>;
@@ -1 +1 @@
1
- {"version":3,"file":"polar-plane.d.ts","sourceRoot":"","sources":["../../src/systems/polar-plane.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,KAAK,KAAK,EAEV,KAAK,MAAM,EACX,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,cAAc,EAGnB,KAAK,IAAI,IAAI,KAAK,EAClB,KAAK,YAAY,IAAI,aAAa,EAClC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EAChC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACzC,MAAM,mBAAmB,CAAC;AAO3B,MAAM,WAAW,eAAgB,SAAQ,UAAU;IAC/C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IAClC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAyBD;;;;GAIG;AACH,eAAO,MAAM,UAAU;IAvBnB,wDAAwD;;IAExD,4EAA4E;;IAE5E,wDAAwD;;;IAGxD,sCAAsC;;IAEtC,yDAAyD;;;;;;;;;;;;;;;;;;;;IATzD,wDAAwD;;IAExD,4EAA4E;;IAE5E,wDAAwD;;;IAGxD,sCAAsC;;IAEtC,yDAAyD;;;;;;;;;;;IATzD,wDAAwD;;IAExD,4EAA4E;;IAE5E,wDAAwD;;;IAGxD,sCAAsC;;IAEtC,yDAAyD;;;;;;;;;;;;;;;;;;;2BAgC3D,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC"}
1
+ {"version":3,"file":"polar-plane.d.ts","sourceRoot":"","sources":["../../src/systems/polar-plane.ts"],"names":[],"mappings":"AAAA,OAAO,EAKH,KAAK,MAAM,EACX,KAAK,KAAK,IAAI,MAAM,EAEpB,KAAK,eAAe,EACpB,KAAK,MAAM,IAAI,OAAO,EAEtB,KAAK,cAAc,EAGnB,KAAK,IAAI,IAAI,KAAK,EAClB,KAAK,YAAY,IAAI,aAAa,EAClC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EAChC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACzC,MAAM,mBAAmB,CAAC;AA+B3B,+HAA+H;AAC/H,eAAO,MAAM,UAAU;IAnBnB,wDAAwD;;IAExD,4EAA4E;;IAE5E,wDAAwD;;;IAGxD,sCAAsC;;IAEtC,yDAAyD;;;;;;;;;;;;;;;;;;;;IATzD,wDAAwD;;IAExD,4EAA4E;;IAE5E,wDAAwD;;;IAGxD,sCAAsC;;IAEtC,yDAAyD;;;;;;;;;;;IATzD,wDAAwD;;IAExD,4EAA4E;;IAE5E,wDAAwD;;;IAGxD,sCAAsC;;IAEtC,yDAAyD;;;;;;;;;;;;;;;;;;;2BA4B3D,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC"}
@@ -2,6 +2,7 @@ import { component2d, Graphics2D, Types, } from "@motionscript/sdk";
2
2
  import { listed, PAINT, PAINT_COMMANDS } from "../kit/component.js";
3
3
  import { cartesianMap } from "../kit/coords.js";
4
4
  import { AXIS_COLOR, drawLabels } from "../kit/furniture.js";
5
+ import { radians } from "../kit/geometry.js";
5
6
  import { drawSystem, systemLayout, systemMap, systemOpenPlane, systemProvides, systemSize } from "../kit/system.js";
6
7
  import { formatTick, ticksFor } from "../kit/ticks.js";
7
8
  /** How much room, in label sizes, the angles written round the outer ring take from the plane. */
@@ -23,11 +24,7 @@ const state = {
23
24
  labelColor: Types.color(AXIS_COLOR),
24
25
  fontFamily: Types.text("", { animatable: false }),
25
26
  };
26
- /**
27
- * Rings and spokes about an origin: the plane a polar curve is read on.
28
- * Children sit in its graph coordinates, x and y in the units its rings count,
29
- * so a plot of `r = 1 + cos(theta)`, a point or an arrow goes on it as on axes.
30
- */
27
+ /** Rings and spokes about an origin: the plane a polar curve is read on. Children sit in its graph coordinates, as on axes. */
31
28
  export const PolarPlane = component2d({
32
29
  key: "polarPlane",
33
30
  state,
@@ -69,7 +66,7 @@ function polarFurniture(map, s) {
69
66
  if (!(reach > 0))
70
67
  return [];
71
68
  const at = (r, degrees) => {
72
- const angle = (degrees * Math.PI) / 180;
69
+ const angle = radians(degrees);
73
70
  return map.toPoint(r * Math.cos(angle), r * Math.sin(angle));
74
71
  };
75
72
  const ring = (g, r) => {
@@ -109,10 +106,10 @@ function polarFurniture(map, s) {
109
106
  }
110
107
  for (const degrees of turns) {
111
108
  const p = at(radius, degrees);
112
- const cos = Math.cos((degrees * Math.PI) / 180);
113
- const sin = Math.sin((degrees * Math.PI) / 180);
109
+ const cos = Math.cos(radians(degrees));
110
+ const sin = Math.sin(radians(degrees));
114
111
  labels.push({
115
- text: s.angleUnit === "degrees" ? `${formatTick(degrees, 1)}°` : radians(degrees),
112
+ text: s.angleUnit === "degrees" ? `${formatTick(degrees, 1)}°` : radiansLabel(degrees),
116
113
  at: { x: p.x + cos * size * 0.6, y: p.y + sin * size * 1.05 },
117
114
  align: cos > 0.3 ? "left" : cos < -0.3 ? "right" : "center",
118
115
  });
@@ -121,7 +118,7 @@ function polarFurniture(map, s) {
121
118
  return parts;
122
119
  }
123
120
  /** An angle in degrees as a fraction of π: 90 is `π/2`, 240 is `4π/3`. */
124
- function radians(degrees) {
121
+ function radiansLabel(degrees) {
125
122
  if (degrees === 0)
126
123
  return "0";
127
124
  let numerator = Math.round(degrees);
@@ -1 +1 @@
1
- {"version":3,"file":"polar-plane.js","sourceRoot":"","sources":["../../src/systems/polar-plane.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,UAAU,EACV,KAAK,GAgBR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAsB,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAc,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACjH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAcpD,kGAAkG;AAClG,MAAM,UAAU,GAAG,GAAG,CAAC;AAEvB,MAAM,KAAK,GAAG;IACV,GAAG,KAAK;IACR,wDAAwD;IACxD,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IACnD,4EAA4E;IAC5E,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;IACrC,wDAAwD;IACxD,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,CAA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B,CAAC;AAED,0EAA0E;AAC1E,SAAS,OAAO,CAAC,OAAe;IAC5B,IAAI,OAAO,KAAK,CAAC;QAAE,OAAO,GAAG,CAAC;IAC9B,IAAI,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACpC,IAAI,WAAW,GAAG,GAAG,CAAC;IACtB,KAAK,IAAI,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,WAAW,GAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QAC7D,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACV,SAAS,IAAI,CAAC,CAAC;YACf,WAAW,IAAI,CAAC,CAAC;YACjB,MAAM;QACV,CAAC;IACL,CAAC;IACD,MAAM,GAAG,GAAG,SAAS,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,CAAC;IACpD,OAAO,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,WAAW,EAAE,CAAC;AAC7D,CAAC","sourcesContent":["import {\n component2d,\n Graphics2D,\n Types,\n type Color,\n type Extents,\n type NodeOf,\n type NormalizedColor,\n type PaintProps,\n type Stroke,\n type StrokeResolved,\n type Values,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n} from \"@motionscript/sdk\";\nimport { listed, PAINT, PAINT_COMMANDS } from \"../kit/component\";\nimport { cartesianMap, type CoordinateMap } from \"../kit/coords\";\nimport { AXIS_COLOR, drawLabels, type Label } from \"../kit/furniture\";\nimport { drawSystem, systemLayout, systemMap, systemOpenPlane, systemProvides, systemSize } from \"../kit/system\";\nimport { formatTick, ticksFor } from \"../kit/ticks\";\n\nexport interface PolarPlaneProps extends PaintProps {\n radius?: number;\n ringStep?: number;\n spokes?: number;\n angleUnit?: \"degrees\" | \"radians\";\n gridStroke?: Stroke;\n labels?: boolean;\n labelSize?: number;\n labelColor?: Color;\n fontFamily?: string;\n}\n\n/** How much room, in label sizes, the angles written round the outer ring take from the plane. */\nconst LABEL_ROOM = 2.2;\n\nconst state = {\n ...PAINT,\n /** The radius of the outermost ring, in graph units. */\n radius: Types.number(4, { min: 0.0001, step: 0.5 }),\n /** The spacing of the rings; zero picks a tidy one for the plane's size. */\n ringStep: Types.number(0, { min: 0 }),\n /** How many spokes divide the turn; zero draws none. */\n spokes: Types.number(12, { min: 0, max: 72, step: 1, animatable: false }),\n angleUnit: listed([\"degrees\", \"radians\"], \"degrees\", { animatable: false }),\n /** The inner rings and the spokes. */\n gridStroke: Types.stroke({ weight: 1.25, fill: \"#3b4658\", align: \"center\" }),\n /** A number at each ring, and an angle at each spoke. */\n labels: Types.boolean(true, { animatable: false }),\n labelSize: Types.number(16, { min: 1, unit: \"px\" }),\n labelColor: Types.color(AXIS_COLOR),\n fontFamily: Types.text(\"\", { animatable: false }),\n};\n\ntype PolarValues = Values<typeof state>;\n\n/**\n * Rings and spokes about an origin: the plane a polar curve is read on.\n * Children sit in its graph coordinates, x and y in the units its rings count,\n * so a plot of `r = 1 + cos(theta)`, a point or an arrow goes on it as on axes.\n */\nexport const PolarPlane = component2d({\n key: \"polarPlane\",\n state,\n /** The outer ring and the two lines through the origin. */\n defaults: { stroke: { weight: 2, fill: AXIS_COLOR, align: \"center\" } },\n load: (loader, s) => {\n if (s.fontFamily !== \"\") loader.font(s.fontFamily);\n },\n commands: {\n ...PAINT_COMMANDS,\n /** Animate how far out the plane reaches: a zoom about its origin. */\n rangeTo: { args: [\"radius\"] },\n },\n provide: (s) => systemProvides(s),\n measure: (_measurer, s) => systemSize(s),\n layout: (box, s, children) => systemLayout(box, s, children, polarMap),\n plane: (box, s) => systemOpenPlane(box, s, polarMap),\n render: (ctx, s) => drawSystem(ctx, s, systemMap(ctx.size, s, polarMap), (map) => polarFurniture(map, s)),\n});\n\nexport type PolarPlane = NodeOf<typeof PolarPlane>;\n\nfunction polarMap(area: Extents, s: PolarValues): CoordinateMap {\n const width = area.maxX - area.minX;\n const height = area.maxY - area.minY;\n // The outer ring fits the shorter side, less the room its angles are written in; units are square.\n const reach = Math.max(1, Math.min(width, height) / 2 - (s.labels ? s.labelSize * LABEL_ROOM : 0));\n const unit = reach / Math.max(s.radius, 1e-9);\n return cartesianMap({\n xRange: [-width / 2 / unit, width / 2 / unit],\n yRange: [-height / 2 / unit, height / 2 / unit],\n area,\n });\n}\n\nfunction polarFurniture(map: CoordinateMap, s: PolarValues): Graphics2D[] {\n const stroke = s.stroke as StrokeResolved[];\n const grid = s.gridStroke as StrokeResolved[];\n const { start, end, radius } = s;\n const centre = map.toPoint(0, 0);\n const reach = map.toPoint(radius, 0).x - centre.x;\n if (!(reach > 0)) return [];\n const at = (r: number, degrees: number) => {\n const angle = (degrees * Math.PI) / 180;\n return map.toPoint(r * Math.cos(angle), r * Math.sin(angle));\n };\n const ring = (g: Graphics2D, r: number): Graphics2D => {\n const size = (map.toPoint(r, 0).x - centre.x) * 2;\n return g.ellipse({ x: centre.x, y: centre.y, width: size, height: size, start, end });\n };\n\n const parts: Graphics2D[] = [];\n const marks = ticksFor([0, radius], s.ringStep, reach);\n const rings = marks.values.filter((r) => r > 0 && r < radius * (1 - 1e-9));\n const count = Math.round(s.spokes);\n const turns = Array.from({ length: count }, (_, i) => (360 * i) / count);\n\n if (grid.length > 0) {\n const inner = new Graphics2D();\n for (const r of rings) ring(inner, r);\n // The four along the axes are drawn with them.\n for (const degrees of turns) {\n if (degrees % 90 !== 0) inner.line({ points: [centre, at(radius, degrees)], radius: 0, start, end });\n }\n if (rings.length > 0 || turns.some((degrees) => degrees % 90 !== 0)) parts.push(inner.stroke(grid));\n }\n if (stroke.length > 0) {\n parts.push(\n ring(new Graphics2D(), radius)\n .line({ points: [at(radius, 180), at(radius, 0)], radius: 0, start, end })\n .line({ points: [at(radius, 270), at(radius, 90)], radius: 0, start, end })\n .stroke(stroke),\n );\n }\n if (!s.labels) return parts;\n\n const size = s.labelSize;\n const labels: Label[] = [];\n for (const r of [...rings, radius]) {\n const p = map.toPoint(r, 0);\n labels.push({ text: formatTick(r, marks.step), at: { x: p.x - size * 0.2, y: p.y - size * 0.95 }, align: \"right\" });\n }\n for (const degrees of turns) {\n const p = at(radius, degrees);\n const cos = Math.cos((degrees * Math.PI) / 180);\n const sin = Math.sin((degrees * Math.PI) / 180);\n labels.push({\n text: s.angleUnit === \"degrees\" ? `${formatTick(degrees, 1)}°` : radians(degrees),\n at: { x: p.x + cos * size * 0.6, y: p.y + sin * size * 1.05 },\n align: cos > 0.3 ? \"left\" : cos < -0.3 ? \"right\" : \"center\",\n });\n }\n parts.push(...drawLabels(labels, { fontSize: size, fontFamily: s.fontFamily, color: s.labelColor as NormalizedColor }));\n return parts;\n}\n\n/** An angle in degrees as a fraction of π: 90 is `π/2`, 240 is `4π/3`. */\nfunction radians(degrees: number): string {\n if (degrees === 0) return \"0\";\n let numerator = Math.round(degrees);\n let denominator = 180;\n for (let a = numerator, b = denominator; ; [a, b] = [b, a % b]) {\n if (b === 0) {\n numerator /= a;\n denominator /= a;\n break;\n }\n }\n const top = numerator === 1 ? \"π\" : `${numerator}π`;\n return denominator === 1 ? top : `${top}/${denominator}`;\n}\n"]}
1
+ {"version":3,"file":"polar-plane.js","sourceRoot":"","sources":["../../src/systems/polar-plane.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,UAAU,EACV,KAAK,GAiBR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAsB,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAc,MAAM,kBAAkB,CAAC;A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GAAG,CAAC;IACpD,OAAO,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,WAAW,EAAE,CAAC;AAC7D,CAAC","sourcesContent":["import {\n component2d,\n Graphics2D,\n Types,\n type Extents,\n type NodeOf,\n type Color as _Color,\n\n type NormalizedColor,\n type Stroke as _Stroke,\n\n type StrokeResolved,\n type Values,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n} from \"@motionscript/sdk\";\nimport { listed, PAINT, PAINT_COMMANDS } from \"../kit/component\";\nimport { cartesianMap, type CoordinateMap } from \"../kit/coords\";\nimport { AXIS_COLOR, drawLabels, type Label } from \"../kit/furniture\";\nimport { radians } from \"../kit/geometry\";\nimport { drawSystem, systemLayout, systemMap, systemOpenPlane, systemProvides, systemSize } from \"../kit/system\";\nimport { formatTick, ticksFor } from \"../kit/ticks\";\n\n/** How much room, in label sizes, the angles written round the outer ring take from the plane. */\nconst LABEL_ROOM = 2.2;\n\nconst state = {\n ...PAINT,\n /** The radius of the outermost ring, in graph units. */\n radius: Types.number(4, { min: 0.0001, step: 0.5 }),\n /** The spacing of the rings; zero picks a tidy one for the plane's size. */\n ringStep: Types.number(0, { min: 0 }),\n /** How many spokes divide the turn; zero draws none. */\n spokes: Types.number(12, { min: 0, max: 72, step: 1, animatable: false }),\n angleUnit: listed([\"degrees\", \"radians\"], \"degrees\", { animatable: false }),\n /** The inner rings and the spokes. */\n gridStroke: Types.stroke({ weight: 1.25, fill: \"#3b4658\", align: \"center\" }),\n /** A number at each ring, and an angle at each spoke. */\n labels: Types.boolean(true, { animatable: false }),\n labelSize: Types.number(16, { min: 1, unit: \"px\" }),\n labelColor: Types.color(AXIS_COLOR),\n fontFamily: Types.text(\"\", { animatable: false }),\n};\n\ntype PolarValues = Values<typeof state>;\n\n/** Rings and spokes about an origin: the plane a polar curve is read on. Children sit in its graph coordinates, as on axes. */\nexport const PolarPlane = component2d({\n key: \"polarPlane\",\n state,\n /** The outer ring and the two lines through the origin. */\n defaults: { stroke: { weight: 2, fill: AXIS_COLOR, align: \"center\" } },\n load: (loader, s) => {\n if (s.fontFamily !== \"\") loader.font(s.fontFamily);\n },\n commands: {\n ...PAINT_COMMANDS,\n /** Animate how far out the plane reaches: a zoom about its origin. */\n rangeTo: { args: [\"radius\"] },\n },\n provide: (s) => systemProvides(s),\n measure: (_measurer, s) => systemSize(s),\n layout: (box, s, children) => systemLayout(box, s, children, polarMap),\n plane: (box, s) => systemOpenPlane(box, s, polarMap),\n render: (ctx, s) => drawSystem(ctx, s, systemMap(ctx.size, s, polarMap), (map) => polarFurniture(map, s)),\n});\n\nexport type PolarPlane = NodeOf<typeof PolarPlane>;\n\nfunction polarMap(area: Extents, s: PolarValues): CoordinateMap {\n const width = area.maxX - area.minX;\n const height = area.maxY - area.minY;\n // The outer ring fits the shorter side, less the room its angles are written in; units are square.\n const reach = Math.max(1, Math.min(width, height) / 2 - (s.labels ? s.labelSize * LABEL_ROOM : 0));\n const unit = reach / Math.max(s.radius, 1e-9);\n return cartesianMap({\n xRange: [-width / 2 / unit, width / 2 / unit],\n yRange: [-height / 2 / unit, height / 2 / unit],\n area,\n });\n}\n\nfunction polarFurniture(map: CoordinateMap, s: PolarValues): Graphics2D[] {\n const stroke = s.stroke as StrokeResolved[];\n const grid = s.gridStroke as StrokeResolved[];\n const { start, end, radius } = s;\n const centre = map.toPoint(0, 0);\n const reach = map.toPoint(radius, 0).x - centre.x;\n if (!(reach > 0)) return [];\n const at = (r: number, degrees: number) => {\n const angle = radians(degrees);\n return map.toPoint(r * Math.cos(angle), r * Math.sin(angle));\n };\n const ring = (g: Graphics2D, r: number): Graphics2D => {\n const size = (map.toPoint(r, 0).x - centre.x) * 2;\n return g.ellipse({ x: centre.x, y: centre.y, width: size, height: size, start, end });\n };\n\n const parts: Graphics2D[] = [];\n const marks = ticksFor([0, radius], s.ringStep, reach);\n const rings = marks.values.filter((r) => r > 0 && r < radius * (1 - 1e-9));\n const count = Math.round(s.spokes);\n const turns = Array.from({ length: count }, (_, i) => (360 * i) / count);\n\n if (grid.length > 0) {\n const inner = new Graphics2D();\n for (const r of rings) ring(inner, r);\n // The four along the axes are drawn with them.\n for (const degrees of turns) {\n if (degrees % 90 !== 0) inner.line({ points: [centre, at(radius, degrees)], radius: 0, start, end });\n }\n if (rings.length > 0 || turns.some((degrees) => degrees % 90 !== 0)) parts.push(inner.stroke(grid));\n }\n if (stroke.length > 0) {\n parts.push(\n ring(new Graphics2D(), radius)\n .line({ points: [at(radius, 180), at(radius, 0)], radius: 0, start, end })\n .line({ points: [at(radius, 270), at(radius, 90)], radius: 0, start, end })\n .stroke(stroke),\n );\n }\n if (!s.labels) return parts;\n\n const size = s.labelSize;\n const labels: Label[] = [];\n for (const r of [...rings, radius]) {\n const p = map.toPoint(r, 0);\n labels.push({ text: formatTick(r, marks.step), at: { x: p.x - size * 0.2, y: p.y - size * 0.95 }, align: \"right\" });\n }\n for (const degrees of turns) {\n const p = at(radius, degrees);\n const cos = Math.cos(radians(degrees));\n const sin = Math.sin(radians(degrees));\n labels.push({\n text: s.angleUnit === \"degrees\" ? `${formatTick(degrees, 1)}°` : radiansLabel(degrees),\n at: { x: p.x + cos * size * 0.6, y: p.y + sin * size * 1.05 },\n align: cos > 0.3 ? \"left\" : cos < -0.3 ? \"right\" : \"center\",\n });\n }\n parts.push(...drawLabels(labels, { fontSize: size, fontFamily: s.fontFamily, color: s.labelColor as NormalizedColor }));\n return parts;\n}\n\n/** An angle in degrees as a fraction of π: 90 is `π/2`, 240 is `4π/3`. */\nfunction radiansLabel(degrees: number): string {\n if (degrees === 0) return \"0\";\n let numerator = Math.round(degrees);\n let denominator = 180;\n for (let a = numerator, b = denominator; ; [a, b] = [b, a % b]) {\n if (b === 0) {\n numerator /= a;\n denominator /= a;\n break;\n }\n }\n const top = numerator === 1 ? \"π\" : `${numerator}π`;\n return denominator === 1 ? top : `${top}/${denominator}`;\n}\n"]}
@@ -6,7 +6,6 @@ import { PathCommand } from '@motionscript/sdk';
6
6
  export declare const MATHJAX_LOADER = "math:mathjax";
7
7
  /** Load MathJax, once. A host that typesets outside a scene (a tool, a test) awaits this first. */
8
8
  export declare function loadMathJax(): Promise<void>;
9
- /** Whether MathJax has loaded, so a formula can be typeset now. */
10
9
  export declare function mathJaxLoaded(): boolean;
11
10
  /** What a formula is before MathJax has loaded: nothing to draw, and nothing cached. */
12
11
  export declare function blankLatex(): LatexPathResult;
@@ -15,26 +14,17 @@ export declare class LatexNotLoaded extends Error {
15
14
  constructor();
16
15
  }
17
16
  /**
18
- * A formula MathJax could not typeset.
19
- *
20
- * MathJax does not throw on malformed TeX. It typesets an error box in place of
21
- * the formula and tags it `data-mjx-error`, so the failure arrives as a drawing:
22
- * nothing at all from the browser adaptor and a filled bar from the DOM-free
23
- * one, which left a host able to tell a bad formula from a blank one only by the
24
- * token count. {@link buildLatexPath} raises this instead, the same way under
25
- * both adaptors. `\require` is an error too, since only the packages named above
26
- * are loaded.
17
+ * A formula MathJax could not typeset. MathJax does not throw on malformed TeX:
18
+ * it typesets an error box tagged `data-mjx-error`, so {@link buildLatexPath}
19
+ * raises this instead, the same under both adaptors. `\require` is an error too.
27
20
  */
28
21
  export declare class LatexError extends Error {
29
- /** The formula that failed, as it was given. */
30
22
  readonly latex: string;
31
- /** MathJax's own description of what is wrong with it. */
32
23
  readonly reason: string;
33
24
  constructor(latex: string, reason: string);
34
25
  }
35
- /** A single rendered glyph or shape with its character key and path commands. */
36
26
  export interface LatexToken {
37
- /** Character this token represents, or a synthetic key for non-glyph shapes. */
27
+ /** The character, or a synthetic key (`__rect_N`, `__path_N`) for a rule or bare path. */
38
28
  token: string;
39
29
  path: PathCommand[];
40
30
  /** The source of the top-level term the token belongs to, `a^2` in `a^2 + b^2`; empty for none. */
@@ -45,7 +35,6 @@ export interface LatexToken {
45
35
  * `+`. Every group the typesetter makes is one, so parts nest.
46
36
  */
47
37
  export interface LatexPart {
48
- /** The part's own source. */
49
38
  latex: string;
50
39
  /** The tokens it draws, as a span of the formula's token list: `from` up to, not including, `to`. */
51
40
  from: number;
@@ -54,20 +43,12 @@ export interface LatexPart {
54
43
  parent: number;
55
44
  }
56
45
  export interface LatexPathResult {
57
- /** All tokens in render order. */
58
46
  tokens: LatexToken[];
59
47
  /** Every part of the formula, outermost first, in source order. */
60
48
  parts: LatexPart[];
61
- /** Flat array of all path commands (for legacy single-path rendering). */
62
- commands: PathCommand[];
63
49
  width: number;
64
50
  height: number;
65
- /**
66
- * Bounding box over every token, in token coordinate space:
67
- * [minX, minY, maxX, maxY]. All tokens share this frame, so passing it as
68
- * each path's center frame keeps their relative layout (instead of each
69
- * glyph centering on its own bbox).
70
- */
51
+ /** [minX, minY, maxX, maxY] over every token: the one centring frame they all share. */
71
52
  bounds: [number, number, number, number];
72
53
  }
73
54
  export declare function buildLatexPath(text: string, fontSize: number): LatexPathResult;
@@ -1 +1 @@
1
- {"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../../src/tex/geometry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAahD;;;GAGG;AACH,eAAO,MAAM,cAAc,iBAAiB,CAAC;AAE7C,mGAAmG;AACnG,wBAAgB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAM3C;AAED,mEAAmE;AACnE,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAED,wFAAwF;AACxF,wBAAgB,UAAU,IAAI,eAAe,CAE5C;AAED,kGAAkG;AAClG,qBAAa,cAAe,SAAQ,KAAK;;CAKxC;AAID;;;;;;;;;;GAUG;AACH,qBAAa,UAAW,SAAQ,KAAK;IACjC,gDAAgD;IAChD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,E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,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAiBvD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC,CAwB/G"}
@@ -16,13 +16,12 @@ export function loadMathJax() {
16
16
  });
17
17
  return loading;
18
18
  }
19
- /** Whether MathJax has loaded, so a formula can be typeset now. */
20
19
  export function mathJaxLoaded() {
21
20
  return runtime !== null;
22
21
  }
23
22
  /** What a formula is before MathJax has loaded: nothing to draw, and nothing cached. */
24
23
  export function blankLatex() {
25
- return { tokens: [], parts: [], commands: [], width: 0, height: 0, bounds: [0, 0, 0, 0] };
24
+ return { tokens: [], parts: [], width: 0, height: 0, bounds: [0, 0, 0, 0] };
26
25
  }
27
26
  /** MathJax is not loaded yet: what typesetting throws before {@link loadMathJax} has resolved. */
28
27
  export class LatexNotLoaded extends Error {
@@ -31,22 +30,13 @@ export class LatexNotLoaded extends Error {
31
30
  this.name = 'LatexNotLoaded';
32
31
  }
33
32
  }
34
- // --- Public API ---
35
33
  /**
36
- * A formula MathJax could not typeset.
37
- *
38
- * MathJax does not throw on malformed TeX. It typesets an error box in place of
39
- * the formula and tags it `data-mjx-error`, so the failure arrives as a drawing:
40
- * nothing at all from the browser adaptor and a filled bar from the DOM-free
41
- * one, which left a host able to tell a bad formula from a blank one only by the
42
- * token count. {@link buildLatexPath} raises this instead, the same way under
43
- * both adaptors. `\require` is an error too, since only the packages named above
44
- * are loaded.
34
+ * A formula MathJax could not typeset. MathJax does not throw on malformed TeX:
35
+ * it typesets an error box tagged `data-mjx-error`, so {@link buildLatexPath}
36
+ * raises this instead, the same under both adaptors. `\require` is an error too.
45
37
  */
46
38
  export class LatexError extends Error {
47
- /** The formula that failed, as it was given. */
48
39
  latex;
49
- /** MathJax's own description of what is wrong with it. */
50
40
  reason;
51
41
  constructor(latex, reason) {
52
42
  super(`Cannot typeset "${latex}": ${reason}`);
@@ -56,29 +46,10 @@ export class LatexError extends Error {
56
46
  }
57
47
  }
58
48
  /**
59
- * Formulas already worked out, and formulas already sized.
60
- *
61
- * `buildLatexPath` is a pure function of `(text, fontSize)` and used to have no
62
- * memory, which made every caller pay full price for a question it had already
63
- * asked. The callers are not occasional about it either: constructing a `Latex`
64
- * resolves its formula, and so does every `to({ latex })` the moment it starts,
65
- * so a scene re-resolves every formula in it whenever it is rebuilt *and*
66
- * whenever the playhead moves backwards, since a backward seek replays the
67
- * scene's generator from its first frame. An editor that rebuilds on a keystroke
68
- * and seeks on a click asks for the same handful of formulas hundreds of times.
69
- *
70
- * Two memos, each keyed by what its stage actually depends on, and deliberately
71
- * different sizes:
72
- *
73
- * - {@link geometryCache} is everything up to the type size, keyed by the text
74
- * alone. This is the expensive one, and it is generously sized because
75
- * nothing a scene does can churn it: a deck holds as many distinct formulas
76
- * as it holds, and it holds them for as long as it is open.
77
- * - {@link pathCache} is the finished result, keyed by text *and* size. Small
78
- * on purpose: an animated `fontSize` inserts a distinct key every frame, and
79
- * the right thing for a stream like that is to churn a little memo rather
80
- * than a big one. What a miss costs here is arithmetic over glyphs already
81
- * worked out — no MathJax, no parse.
49
+ * `geometryCache` is keyed by text alone and sized for a whole deck. `pathCache`
50
+ * is keyed by text and size and kept small: an animated `fontSize` adds a key
51
+ * every frame, and a miss there is only arithmetic over cached geometry.
52
+ * Backward seeks and rebuilds re-ask for the same formulas hundreds of times.
82
53
  */
83
54
  const geometryCache = createBoundedCache(128);
84
55
  const pathCache = createBoundedCache(64);
@@ -109,11 +80,7 @@ function buildLatexGeometry(text) {
109
80
  const heightAttr = adaptor.getAttribute(svgEl, 'height') ?? '';
110
81
  return parseLatexSvg(svgEl, parseFloat(heightAttr) || 0);
111
82
  }
112
- /**
113
- * MathJax's description of the error box in a typeset formula, or `null` when
114
- * there is none. Read through the adaptor, so a real DOM and the DOM-free tree
115
- * give the same answer.
116
- */
83
+ /** MathJax's description of the error box in a typeset formula, or `null`; read through the adaptor so a real DOM and the DOM-free tree agree. */
117
84
  function mathJaxError(svgEl) {
118
85
  for (const el of adaptor.tags(svgEl, 'g')) {
119
86
  const reason = adaptor.getAttribute(el, 'data-mjx-error');
@@ -123,19 +90,9 @@ function mathJaxError(svgEl) {
123
90
  return null;
124
91
  }
125
92
  /**
126
- * A cached result, handed out safely.
127
- *
128
- * `tokens`, `commands` and the path arrays inside them are shared: they are read
129
- * by everything downstream and written by none of it — `Latex` maps tokens into
130
- * its own wrappers, and the morph builds new paths rather than editing the ones
131
- * it is given — so copying them would be copying the whole formula for nothing.
132
- *
133
- * `bounds` is copied, because it is the one field a caller *stores*: `Latex`
134
- * assigns `result.bounds` straight to `this._bounds` and hands it to the
135
- * renderer as a shared centring frame. That was one node holding its own array
136
- * before there was a memo, and would be two nodes drawing the same formula
137
- * holding one array between them after — four numbers is not a price worth
138
- * paying to find out whether anything downstream ever writes to it.
93
+ * Tokens and their paths are shared, since nothing downstream writes to them.
94
+ * `bounds` is copied: `Latex` stores it and hands it to the renderer as a
95
+ * centring frame, and two nodes on one formula must not share an array.
139
96
  */
140
97
  function lend(result) {
141
98
  const [minX, minY, maxX, maxY] = result.bounds;
@@ -181,11 +138,7 @@ function applyMatrix(x, y, m) {
181
138
  x * m[1] + y * m[3] + m[5],
182
139
  ];
183
140
  }
184
- // --- Glyph ID → character decoding ---
185
- /**
186
- * MathJax SVG glyph IDs look like "MJX-1-TEX-N-78" or "MJX-1-TEX-I-1D465".
187
- * The last segment is the Unicode codepoint in hex.
188
- */
141
+ /** A MathJax glyph id ends in the codepoint in hex: `MJX-1-TEX-I-1D465`. */
189
142
  function glyphIdToChar(id) {
190
143
  const parts = id.split('-');
191
144
  const hex = parts[parts.length - 1];
@@ -204,23 +157,11 @@ function parentKind(node) {
204
157
  return parent ? String(adaptor.kind(parent)).toLowerCase() : "";
205
158
  }
206
159
  /**
207
- * The size-independent half: MathJax's own SVG tree in, glyph geometry out.
208
- *
209
- * Walked through the **adaptor** rather than a `DOMParser`. MathJax already
210
- * builds this tree, and the adaptor is its own abstraction over "a real DOM" and
211
- * "the DOM-free `LiteElement` tree" — the two this module already picks between
212
- * at load. Serialising it to a string and parsing it back needed a `DOMParser`,
213
- * which Node does not have, so every LaTeX node threw `DOMParser is not defined`
214
- * and could not render headlessly at all: no export, and nothing the visual
215
- * suite could check.
216
- *
217
- * Reading the tree directly is also one representation instead of three (tree →
218
- * string → tree), so a browser and a headless host cannot disagree about how the
219
- * markup re-parsed.
160
+ * The size-independent half. Walks MathJax's tree through the adaptor, not a
161
+ * `DOMParser`, which Node lacks: a headless host could not render any formula.
220
162
  */
221
163
  function parseLatexSvg(svgEl, heightEx) {
222
- // Pre-parse the glyph dictionary. `tags` reaches every <path> in the tree,
223
- // including the ones inside <defs> that the `use` elements reference.
164
+ // `tags` reaches the <path>s inside <defs> that the `use` elements reference.
224
165
  const glyphMap = new Map();
225
166
  for (const el of adaptor.tags(svgEl, 'path')) {
226
167
  const id = adaptor.getAttribute(el, 'id');
@@ -229,7 +170,6 @@ function parseLatexSvg(svgEl, heightEx) {
229
170
  glyphMap.set(`#${id}`, expandToAbsolute(tokenisePath(d)));
230
171
  }
231
172
  }
232
- // Collect raw tokens — each <use> is one token, rects/paths are grouped as synthetic tokens
233
173
  const rawTokens = [];
234
174
  const parts = [];
235
175
  let synthIdx = 0;
@@ -266,7 +206,6 @@ function parseLatexSvg(svgEl, heightEx) {
266
206
  }
267
207
  cmds.push({ cmd: gc.cmd, args: shiftedArgs });
268
208
  }
269
- // Derive character from glyph ID
270
209
  const rawId = href.startsWith('#') ? href.slice(1) : href;
271
210
  pushCmds(glyphIdToChar(rawId), cmds);
272
211
  }
@@ -323,20 +262,14 @@ function parseLatexSvg(svgEl, heightEx) {
323
262
  for (let i = part.from; i < part.to; i++)
324
263
  rawTokens[i].term = part.latex;
325
264
  }
326
- // Bounding box across all raw commands, in the SVG's own coordinates.
327
265
  const box = svgBBox(rawTokens.flatMap(t => t.cmds));
328
266
  return { tokens: rawTokens, parts, box, heightEx };
329
267
  }
330
- /**
331
- * The size-dependent half: glyph geometry in, a laid-out formula out.
332
- *
333
- * Everything here is one uniform scale about the geometry's own centre, which
334
- * is exactly why {@link LatexGeometry} is worth remembering on its own.
335
- */
268
+ /** The size-dependent half: one uniform scale about the geometry's own centre. */
336
269
  function scaleLatexGeometry(geometry, fontSize) {
337
270
  const { tokens: rawTokens, parts, box, heightEx } = geometry;
338
271
  if (rawTokens.length === 0)
339
- return { tokens: [], parts: [], commands: [], width: 0, height: 0, bounds: [0, 0, 0, 0] };
272
+ return { tokens: [], parts: [], width: 0, height: 0, bounds: [0, 0, 0, 0] };
340
273
  const { minX, minY, maxX, maxY } = box;
341
274
  const svgW = maxX - minX;
342
275
  const svgH = maxY - minY;
@@ -380,15 +313,11 @@ function scaleLatexGeometry(geometry, fontSize) {
380
313
  path: rawCmdsToPathCommands(rt.cmds),
381
314
  ...(rt.term !== undefined && { term: rt.term }),
382
315
  }));
383
- const commands = tokens.flatMap(t => t.path);
384
- // Shared center frame for all tokens, in token coordinate space. tx/ty map
385
- // the SVG bbox corners; this is the frame every token's path is laid out in.
386
316
  const bounds = [
387
317
  tx(minX), ty(minY), tx(maxX), ty(maxY),
388
318
  ];
389
- return { tokens, parts, commands, width: svgW * scale, height: svgH * scale, bounds };
319
+ return { tokens, parts, width: svgW * scale, height: svgH * scale, bounds };
390
320
  }
391
- // --- Parts ---
392
321
  // Spacing and grouping braces are how a source is written, not what it says:
393
322
  // `x^{2}` and `x^2` name one part.
394
323
  function partKey(latex) {