@motionscript/math 0.1.0-alpha.4 → 0.1.0-alpha.6

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 (233) hide show
  1. package/CHANGELOG.md +132 -92
  2. package/README.md +39 -33
  3. package/dist/annotate/angle-mark.d.ts +52 -27
  4. package/dist/annotate/angle-mark.d.ts.map +1 -1
  5. package/dist/annotate/angle-mark.js +80 -115
  6. package/dist/annotate/angle-mark.js.map +1 -1
  7. package/dist/annotate/curly-brace.d.ts +59 -25
  8. package/dist/annotate/curly-brace.d.ts.map +1 -1
  9. package/dist/annotate/curly-brace.js +85 -100
  10. package/dist/annotate/curly-brace.js.map +1 -1
  11. package/dist/annotate/emphasis-mark.d.ts +43 -9
  12. package/dist/annotate/emphasis-mark.d.ts.map +1 -1
  13. package/dist/annotate/emphasis-mark.js +33 -34
  14. package/dist/annotate/emphasis-mark.js.map +1 -1
  15. package/dist/browser/chunks/chunk-ABYBW64J.js +2 -0
  16. package/dist/browser/chunks/chunk-ABYBW64J.js.map +7 -0
  17. package/dist/browser/chunks/chunk-K77KLQX4.js +2 -0
  18. package/dist/browser/chunks/chunk-K77KLQX4.js.map +7 -0
  19. package/dist/browser/index.js +1 -1
  20. package/dist/browser/index.js.map +3 -3
  21. package/dist/browser/kit.js +1 -1
  22. package/dist/browser/manifest.json +1 -1
  23. package/dist/browser/tex.js +1 -1
  24. package/dist/browser/tex.js.map +2 -2
  25. package/dist/engine.d.ts +26 -19
  26. package/dist/engine.d.ts.map +1 -1
  27. package/dist/engine.js +17 -14
  28. package/dist/engine.js.map +1 -1
  29. package/dist/kit/component.d.ts +51 -0
  30. package/dist/kit/component.d.ts.map +1 -0
  31. package/dist/kit/component.js +30 -0
  32. package/dist/kit/component.js.map +1 -0
  33. package/dist/kit/curve.d.ts +22 -11
  34. package/dist/kit/curve.d.ts.map +1 -1
  35. package/dist/kit/curve.js +25 -18
  36. package/dist/kit/curve.js.map +1 -1
  37. package/dist/kit/field-mark.d.ts +58 -35
  38. package/dist/kit/field-mark.d.ts.map +1 -1
  39. package/dist/kit/field-mark.js +100 -120
  40. package/dist/kit/field-mark.js.map +1 -1
  41. package/dist/kit/follow.d.ts +67 -29
  42. package/dist/kit/follow.d.ts.map +1 -1
  43. package/dist/kit/follow.js +114 -110
  44. package/dist/kit/follow.js.map +1 -1
  45. package/dist/kit/furniture.d.ts +3 -1
  46. package/dist/kit/furniture.d.ts.map +1 -1
  47. package/dist/kit/furniture.js +5 -0
  48. package/dist/kit/furniture.js.map +1 -1
  49. package/dist/kit/graph.d.ts +46 -0
  50. package/dist/kit/graph.d.ts.map +1 -0
  51. package/dist/kit/graph.js +90 -0
  52. package/dist/kit/graph.js.map +1 -0
  53. package/dist/kit/mark.d.ts +64 -39
  54. package/dist/kit/mark.d.ts.map +1 -1
  55. package/dist/kit/mark.js +80 -96
  56. package/dist/kit/mark.js.map +1 -1
  57. package/dist/kit/place.d.ts +10 -8
  58. package/dist/kit/place.d.ts.map +1 -1
  59. package/dist/kit/place.js +28 -30
  60. package/dist/kit/place.js.map +1 -1
  61. package/dist/kit/system.d.ts +27 -29
  62. package/dist/kit/system.d.ts.map +1 -1
  63. package/dist/kit/system.js +62 -58
  64. package/dist/kit/system.js.map +1 -1
  65. package/dist/kit/withdrawn.d.ts +3 -3
  66. package/dist/kit/withdrawn.js +3 -3
  67. package/dist/kit/withdrawn.js.map +1 -1
  68. package/dist/marks/curve-area.d.ts +24 -18
  69. package/dist/marks/curve-area.d.ts.map +1 -1
  70. package/dist/marks/curve-area.js +50 -73
  71. package/dist/marks/curve-area.js.map +1 -1
  72. package/dist/marks/drop-lines.d.ts +28 -10
  73. package/dist/marks/drop-lines.d.ts.map +1 -1
  74. package/dist/marks/drop-lines.js +37 -52
  75. package/dist/marks/drop-lines.js.map +1 -1
  76. package/dist/marks/plot-point.d.ts +37 -20
  77. package/dist/marks/plot-point.d.ts.map +1 -1
  78. package/dist/marks/plot-point.js +65 -91
  79. package/dist/marks/plot-point.js.map +1 -1
  80. package/dist/marks/riemann-sum.d.ts +30 -26
  81. package/dist/marks/riemann-sum.d.ts.map +1 -1
  82. package/dist/marks/riemann-sum.js +57 -85
  83. package/dist/marks/riemann-sum.js.map +1 -1
  84. package/dist/marks/tangent-line.d.ts +38 -14
  85. package/dist/marks/tangent-line.d.ts.map +1 -1
  86. package/dist/marks/tangent-line.js +73 -87
  87. package/dist/marks/tangent-line.js.map +1 -1
  88. package/dist/marks/vector-arrow.d.ts +30 -20
  89. package/dist/marks/vector-arrow.d.ts.map +1 -1
  90. package/dist/marks/vector-arrow.js +58 -78
  91. package/dist/marks/vector-arrow.js.map +1 -1
  92. package/dist/nodes.d.ts +13 -5
  93. package/dist/nodes.d.ts.map +1 -1
  94. package/dist/nodes.js +0 -6
  95. package/dist/nodes.js.map +1 -1
  96. package/dist/plots/function-plot.d.ts +107 -43
  97. package/dist/plots/function-plot.d.ts.map +1 -1
  98. package/dist/plots/function-plot.js +146 -177
  99. package/dist/plots/function-plot.js.map +1 -1
  100. package/dist/plots/points-plot.d.ts +34 -19
  101. package/dist/plots/points-plot.d.ts.map +1 -1
  102. package/dist/plots/points-plot.js +31 -58
  103. package/dist/plots/points-plot.js.map +1 -1
  104. package/dist/plots/stream-lines.d.ts +38 -19
  105. package/dist/plots/stream-lines.d.ts.map +1 -1
  106. package/dist/plots/stream-lines.js +60 -79
  107. package/dist/plots/stream-lines.js.map +1 -1
  108. package/dist/plots/traced-path.d.ts +34 -15
  109. package/dist/plots/traced-path.d.ts.map +1 -1
  110. package/dist/plots/traced-path.js +33 -48
  111. package/dist/plots/traced-path.js.map +1 -1
  112. package/dist/plots/vector-field.d.ts +31 -11
  113. package/dist/plots/vector-field.d.ts.map +1 -1
  114. package/dist/plots/vector-field.js +50 -64
  115. package/dist/plots/vector-field.js.map +1 -1
  116. package/dist/structures/network-graph.d.ts +99 -49
  117. package/dist/structures/network-graph.d.ts.map +1 -1
  118. package/dist/structures/network-graph.js +168 -217
  119. package/dist/structures/network-graph.js.map +1 -1
  120. package/dist/structures/sample-space.d.ts +69 -38
  121. package/dist/structures/sample-space.d.ts.map +1 -1
  122. package/dist/structures/sample-space.js +132 -170
  123. package/dist/structures/sample-space.js.map +1 -1
  124. package/dist/systems/axes2d.d.ts +126 -37
  125. package/dist/systems/axes2d.d.ts.map +1 -1
  126. package/dist/systems/axes2d.js +147 -183
  127. package/dist/systems/axes2d.js.map +1 -1
  128. package/dist/systems/number-line.d.ts +51 -28
  129. package/dist/systems/number-line.d.ts.map +1 -1
  130. package/dist/systems/number-line.js +82 -118
  131. package/dist/systems/number-line.js.map +1 -1
  132. package/dist/systems/number-plane.d.ts +92 -31
  133. package/dist/systems/number-plane.d.ts.map +1 -1
  134. package/dist/systems/number-plane.js +142 -149
  135. package/dist/systems/number-plane.js.map +1 -1
  136. package/dist/systems/polar-plane.d.ts +47 -26
  137. package/dist/systems/polar-plane.d.ts.map +1 -1
  138. package/dist/systems/polar-plane.js +107 -133
  139. package/dist/systems/polar-plane.js.map +1 -1
  140. package/dist/tex/index.d.ts.map +1 -1
  141. package/dist/tex/index.js +1 -0
  142. package/dist/tex/index.js.map +1 -1
  143. package/dist/tex/matrix.d.ts +56 -18
  144. package/dist/tex/matrix.d.ts.map +1 -1
  145. package/dist/tex/matrix.js +33 -50
  146. package/dist/tex/matrix.js.map +1 -1
  147. package/dist/tex/node.d.ts +55 -201
  148. package/dist/tex/node.d.ts.map +1 -1
  149. package/dist/tex/node.js +23 -593
  150. package/dist/tex/node.js.map +1 -1
  151. package/dist/tex/typeset.d.ts +133 -0
  152. package/dist/tex/typeset.d.ts.map +1 -0
  153. package/dist/tex/typeset.js +403 -0
  154. package/dist/tex/typeset.js.map +1 -0
  155. package/dist/three/axes3d.d.ts +140 -54
  156. package/dist/three/axes3d.d.ts.map +1 -1
  157. package/dist/three/axes3d.js +159 -204
  158. package/dist/three/axes3d.js.map +1 -1
  159. package/dist/three/curve-plot3d.d.ts +70 -42
  160. package/dist/three/curve-plot3d.d.ts.map +1 -1
  161. package/dist/three/curve-plot3d.js +97 -132
  162. package/dist/three/curve-plot3d.js.map +1 -1
  163. package/dist/three/entries.d.ts +17 -0
  164. package/dist/three/entries.d.ts.map +1 -0
  165. package/dist/three/entries.js +15 -0
  166. package/dist/three/entries.js.map +1 -0
  167. package/dist/three/plot-point3d.d.ts +57 -12
  168. package/dist/three/plot-point3d.d.ts.map +1 -1
  169. package/dist/three/plot-point3d.js +27 -53
  170. package/dist/three/plot-point3d.js.map +1 -1
  171. package/dist/three/space.d.ts +17 -2
  172. package/dist/three/space.d.ts.map +1 -1
  173. package/dist/three/space.js +19 -8
  174. package/dist/three/space.js.map +1 -1
  175. package/dist/three/surface-plot3d.d.ts +131 -49
  176. package/dist/three/surface-plot3d.d.ts.map +1 -1
  177. package/dist/three/surface-plot3d.js +227 -261
  178. package/dist/three/surface-plot3d.js.map +1 -1
  179. package/dist/three/vector-arrow3d.d.ts +58 -16
  180. package/dist/three/vector-arrow3d.d.ts.map +1 -1
  181. package/dist/three/vector-arrow3d.js +48 -67
  182. package/dist/three/vector-arrow3d.js.map +1 -1
  183. package/package.json +4 -4
  184. package/src/annotate/angle-mark.ts +95 -105
  185. package/src/annotate/curly-brace.ts +107 -85
  186. package/src/annotate/emphasis-mark.ts +55 -26
  187. package/src/engine.ts +35 -21
  188. package/src/kit/component.ts +57 -0
  189. package/src/kit/curve.ts +38 -20
  190. package/src/kit/field-mark.ts +124 -108
  191. package/src/kit/follow.ts +146 -120
  192. package/src/kit/furniture.ts +6 -1
  193. package/src/kit/graph.ts +116 -0
  194. package/src/kit/mark.ts +135 -114
  195. package/src/kit/place.ts +32 -56
  196. package/src/kit/system.ts +77 -71
  197. package/src/kit/withdrawn.ts +3 -3
  198. package/src/marks/curve-area.ts +65 -65
  199. package/src/marks/drop-lines.ts +50 -42
  200. package/src/marks/plot-point.ts +77 -82
  201. package/src/marks/riemann-sum.ts +73 -72
  202. package/src/marks/tangent-line.ts +87 -71
  203. package/src/marks/vector-arrow.ts +73 -73
  204. package/src/nodes.ts +41 -5
  205. package/src/plots/function-plot.ts +155 -171
  206. package/src/plots/points-plot.ts +46 -50
  207. package/src/plots/stream-lines.ts +75 -66
  208. package/src/plots/traced-path.ts +51 -33
  209. package/src/plots/vector-field.ts +68 -49
  210. package/src/structures/network-graph.ts +168 -185
  211. package/src/structures/sample-space.ts +149 -148
  212. package/src/systems/axes2d.ts +165 -156
  213. package/src/systems/number-line.ts +91 -92
  214. package/src/systems/number-plane.ts +149 -120
  215. package/src/systems/polar-plane.ts +117 -116
  216. package/src/tex/index.ts +2 -1
  217. package/src/tex/matrix.ts +62 -40
  218. package/src/tex/node.ts +54 -621
  219. package/src/tex/typeset.ts +461 -0
  220. package/src/three/axes3d.ts +182 -161
  221. package/src/three/curve-plot3d.ts +107 -110
  222. package/src/three/entries.ts +42 -0
  223. package/src/three/plot-point3d.ts +42 -45
  224. package/src/three/space.ts +34 -9
  225. package/src/three/surface-plot3d.ts +312 -323
  226. package/src/three/vector-arrow3d.ts +65 -54
  227. package/dist/browser/chunks/chunk-3GJB6AVO.js +0 -2
  228. package/dist/browser/chunks/chunk-3GJB6AVO.js.map +0 -7
  229. package/dist/browser/chunks/chunk-D5WHCVBC.js +0 -2
  230. package/dist/browser/chunks/chunk-D5WHCVBC.js.map +0 -7
  231. package/dist/browser/chunks/chunk-WL4KEX7Y.js +0 -2
  232. package/dist/browser/chunks/chunk-WL4KEX7Y.js.map +0 -7
  233. package/src/kit/placement.ts +0 -8
@@ -1 +1 @@
1
- {"version":3,"file":"points-plot.js","sourceRoot":"","sources":["../../src/plots/points-plot.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,OAAO,EACP,IAAI,EACJ,QAAQ,EACR,cAAc,GAOjB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,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jI,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;aACpI,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IACD,IAAI,CAAC,MAAM;QAAE,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACrC,OAAO,GAAG,CAAC;AACf,CAAC","sourcesContent":["import {\r\n command,\r\n node,\r\n property,\r\n strokeProperty,\r\n type Command,\r\n type CommandArgs,\r\n type NodeConfig,\r\n type PaintProps,\r\n type Stroke,\r\n type Vector2,\r\n} from \"@motionscript/sdk\";\r\nimport type { CoordinateMap } from \"../kit/coords\";\r\nimport { stated } from \"../kit/geometry\";\r\nimport { Mark } from \"../kit/mark\";\r\nimport { PLOT_COLOR } from \"../kit/furniture\";\r\nimport { SYSTEMS } from \"../kit/placement\";\r\n\r\nexport interface PointsPlotProps extends PaintProps {\r\n points?: Vector2[];\r\n closed?: boolean;\r\n smooth?: boolean;\r\n}\r\n\r\n// A shorter list is padded with its own last point, so a line grows new points out of its end.\r\nfunction lerpPoints(from: Vector2[], to: Vector2[], t: number): Vector2[] {\r\n const count = Math.max(from.length, to.length);\r\n if (from.length === 0 || to.length === 0) return t < 1 ? from : to;\r\n const out = new Array<Vector2>(count);\r\n for (let i = 0; i < count; i++) {\r\n const a = from[Math.min(i, from.length - 1)];\r\n const b = to[Math.min(i, to.length - 1)];\r\n out[i] = { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t };\r\n }\r\n return out;\r\n}\r\n\r\n/** Points on the curve between each pair of a smooth line's points. */\r\nconst SMOOTH_STEPS = 16;\r\n\r\n/** A line through listed graph points: data, or a shape drawn in graph coordinates when closed, which is when it is filled. */\r\n@node({\r\n key: \"pointsPlot\",\r\n within: SYSTEMS,\r\n parentKey: \"shape\",\r\n forkable: true,\r\n layout: { children: \"freeform\", defaultWidthMode: \"hug\", defaultHeightMode: \"hug\", acceptsChildren: false },\r\n seed: { points: [{ x: -2, y: -1 }, { x: 0, y: 1 }, { x: 2, y: 0 }] },\r\n})\r\nexport class PointsPlot extends Mark<PointsPlotProps> {\r\n @property({ default: [], tween: lerpPoints }) declare points: Vector2[];\r\n /** Join the last point to the first. */\r\n @property({ default: false, animatable: false }) declare closed: boolean;\r\n /** Curve through the points instead of turning a corner at each. */\r\n @property({ default: false, animatable: false }) declare smooth: boolean;\r\n\r\n @strokeProperty({ default: { weight: 3, fill: PLOT_COLOR, align: \"center\", cap: \"round\", join: \"round\" } })\r\n declare stroke: Stroke;\r\n\r\n constructor(props?: NodeConfig<PointsPlot, PointsPlotProps>) {\r\n super(props ?? {});\r\n }\r\n\r\n /** Move the points to new places; extra ones grow from the line's end. */\r\n @command({ args: [\"points\"] })\r\n pointsTo(args: CommandArgs<{ points: Vector2[] }> & { duration: number }): Command<PointsPlotProps> {\r\n return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });\r\n }\r\n\r\n protected override isClosed(): boolean {\r\n return this.closed;\r\n }\r\n\r\n // An open line has no inside, so its fill waits until it is closed.\r\n protected override paintsFill(): boolean {\r\n return this.closed;\r\n }\r\n\r\n protected trace(map: CoordinateMap): Vector2[][] {\r\n const shift = this.shift();\r\n const pixels = this.points.map((p) => map.toPoint(p.x + shift.x, p.y + shift.y));\r\n if (pixels.length < 2) return [];\r\n return [this.smooth && pixels.length > 2 ? spline(pixels, this.closed) : pixels];\r\n }\r\n}\r\n\r\n// Catmull–Rom, so the curve passes through every point it was given.\r\nfunction spline(points: readonly Vector2[], closed: boolean): Vector2[] {\r\n const n = points.length;\r\n const at = (i: number): Vector2 => (closed ? points[((i % n) + n) % n] : points[Math.max(0, Math.min(n - 1, i))]);\r\n const out: Vector2[] = [];\r\n const spans = closed ? n : n - 1;\r\n for (let i = 0; i < spans; i++) {\r\n const p0 = at(i - 1), p1 = at(i), p2 = at(i + 1), p3 = at(i + 2);\r\n for (let s = 0; s < SMOOTH_STEPS; s++) {\r\n const t = s / SMOOTH_STEPS;\r\n const t2 = t * t;\r\n const t3 = t2 * t;\r\n out.push({\r\n x: 0.5 * (2 * p1.x + (p2.x - p0.x) * t + (2 * p0.x - 5 * p1.x + 4 * p2.x - p3.x) * t2 + (3 * p1.x - p0.x - 3 * p2.x + p3.x) * t3),\r\n y: 0.5 * (2 * p1.y + (p2.y - p0.y) * t + (2 * p0.y - 5 * p1.y + 4 * p2.y - p3.y) * t2 + (3 * p1.y - p0.y - 3 * p2.y + p3.y) * t3),\r\n });\r\n }\r\n }\r\n if (!closed) out.push(points[n - 1]);\r\n return out;\r\n}\r\n"]}
1
+ {"version":3,"file":"points-plot.js","sourceRoot":"","sources":["../../src/plots/points-plot.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,KAAK,GAaR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAoB,MAAM,aAAa,CAAC;AAQnF,+FAA+F;AAC/F,SAAS,UAAU,CAAC,IAAe,EAAE,EAAa,EAAE,CAAS;IACzD,MAAM,KAAK,GAAG,IAAI,CAA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CAAC,CAAC,CAAC;IACrC,OAAO,GAAG,CAAC;AACf,CAAC","sourcesContent":["import {\r\n component2d,\r\n Types,\r\n type NodeOf,\r\n type PaintProps,\r\n type Vector2,\r\n // Named so the emitted declaration reaches these through the sdk, not core.\r\n type Fill as _Fill,\r\n type FillResolved as _FillResolved,\r\n type Node2D as _Node2D,\r\n type Node2DProps as _Node2DProps,\r\n type Shadow as _Shadow,\r\n type ShadowResolved as _ShadowResolved,\r\n type Stroke as _Stroke,\r\n type StrokeResolved as _StrokeResolved,\r\n} from \"@motionscript/sdk\";\r\nimport { PAINT, PAINT_COMMANDS } from \"../kit/component\";\r\nimport { PLOT_COLOR } from \"../kit/furniture\";\r\nimport { PLANE_ENTRY } from \"../kit/graph\";\r\nimport { drawMark, inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\r\n\r\nexport interface PointsPlotProps extends PaintProps {\r\n points?: Vector2[];\r\n closed?: boolean;\r\n smooth?: boolean;\r\n}\r\n\r\n// A shorter list is padded with its own last point, so a line grows new points out of its end.\r\nfunction lerpPoints(from: Vector2[], to: Vector2[], t: number): Vector2[] {\r\n const count = Math.max(from.length, to.length);\r\n if (from.length === 0 || to.length === 0) return t < 1 ? from : to;\r\n const out = new Array<Vector2>(count);\r\n for (let i = 0; i < count; i++) {\r\n const a = from[Math.min(i, from.length - 1)];\r\n const b = to[Math.min(i, to.length - 1)];\r\n out[i] = { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t };\r\n }\r\n return out;\r\n}\r\n\r\n/** Points on the curve between each pair of a smooth line's points. */\r\nconst SMOOTH_STEPS = 16;\r\n\r\nconst state = {\r\n ...PAINT,\r\n points: Types.custom<Vector2[]>([], { lerp: lerpPoints }),\r\n /** Join the last point to the first. */\r\n closed: Types.boolean(false, { animatable: false }),\r\n /** Curve through the points instead of turning a corner at each. */\r\n smooth: Types.boolean(false, { animatable: false }),\r\n graph: PLANE_ENTRY,\r\n};\r\n\r\ninterface PointsValues {\r\n readonly points: Vector2[];\r\n readonly closed: boolean;\r\n readonly smooth: boolean;\r\n}\r\n\r\n/** A line through listed graph points: data, or a shape drawn in graph coordinates when closed, which is when it is filled. */\r\nexport const PointsPlot = traced(component2d({\r\n key: \"pointsPlot\",\r\n state,\r\n defaults: { stroke: { weight: 3, fill: PLOT_COLOR, align: \"center\", cap: \"round\", join: \"round\" }, width: \"hug\", height: \"hug\" },\r\n commands: {\r\n ...PAINT_COMMANDS,\r\n /** Move the points to new places; extra ones grow from the line's end. */\r\n pointsTo: { args: [\"points\"] },\r\n },\r\n measure: (_measurer, s) => inkSize(tracePoints(s, reading(s))),\r\n // An open line has no inside, so its fill waits until it is closed.\r\n render: (ctx, s) => drawMark(ctx, s, tracePoints(s, reading(s)), { closed: s.closed, fills: s.closed }),\r\n}), tracePoints);\r\n\r\nexport type PointsPlot = NodeOf<typeof PointsPlot>;\r\n\r\nfunction tracePoints(s: PointsValues, { map, shift }: MarkReading): Vector2[][] {\r\n const pixels = s.points.map((p) => map.toPoint(p.x + shift.x, p.y + shift.y));\r\n if (pixels.length < 2) return [];\r\n return [s.smooth && pixels.length > 2 ? spline(pixels, s.closed) : pixels];\r\n}\r\n\r\n// Catmull–Rom, so the curve passes through every point it was given.\r\nfunction spline(points: readonly Vector2[], closed: boolean): Vector2[] {\r\n const n = points.length;\r\n const at = (i: number): Vector2 => (closed ? points[((i % n) + n) % n] : points[Math.max(0, Math.min(n - 1, i))]);\r\n const out: Vector2[] = [];\r\n const spans = closed ? n : n - 1;\r\n for (let i = 0; i < spans; i++) {\r\n const p0 = at(i - 1), p1 = at(i), p2 = at(i + 1), p3 = at(i + 2);\r\n for (let s = 0; s < SMOOTH_STEPS; s++) {\r\n const t = s / SMOOTH_STEPS;\r\n const t2 = t * t;\r\n const t3 = t2 * t;\r\n out.push({\r\n x: 0.5 * (2 * p1.x + (p2.x - p0.x) * t + (2 * p0.x - 5 * p1.x + 4 * p2.x - p3.x) * t2 + (3 * p1.x - p0.x - 3 * p2.x + p3.x) * t3),\r\n y: 0.5 * (2 * p1.y + (p2.y - p0.y) * t + (2 * p0.y - 5 * p1.y + 4 * p2.y - p3.y) * t2 + (3 * p1.y - p0.y - 3 * p2.y + p3.y) * t3),\r\n });\r\n }\r\n }\r\n if (!closed) out.push(points[n - 1]);\r\n return out;\r\n}\r\n"]}
@@ -1,6 +1,5 @@
1
- import { type Command, type CommandArgs, type NodeConfig, type Stroke } from "@motionscript/sdk";
2
- import type { CoordinateMap } from "../kit/coords.js";
3
- import { FieldMark, type FieldProps, type FieldSampler, type FieldStroke } from "../kit/field-mark.js";
1
+ import { type NodeOf, type Fill as _Fill, type FillResolved as _FillResolved, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Shadow as _Shadow, type ShadowResolved as _ShadowResolved, type Stroke as _Stroke, type StrokeResolved as _StrokeResolved } from "@motionscript/sdk";
2
+ import { type FieldProps } from "../kit/field-mark.js";
4
3
  export interface StreamLinesProps extends FieldProps {
5
4
  spacing?: number;
6
5
  length?: number;
@@ -12,24 +11,44 @@ export interface StreamLinesProps extends FieldProps {
12
11
  * grid: `(-y, x)` draws circles. With a `window` below one, each line shows
13
12
  * only a stretch of itself, and `flowTo` sends those stretches along.
14
13
  */
15
- export declare class StreamLines extends FieldMark<StreamLinesProps> {
14
+ export declare const StreamLines: import("@motionscript/sdk").Component<"streamLines", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
16
15
  /** How far apart the lines start, in graph units. */
17
- spacing: number;
16
+ spacing: import("@motionscript/sdk").Type<number, number, false>;
18
17
  /** How far each line runs from where it starts, in graph units along itself. */
19
- length: number;
18
+ length: import("@motionscript/sdk").Type<number, number, false>;
20
19
  /** The share of each line that is shown at once; one shows all of it. */
21
- window: number;
20
+ window: import("@motionscript/sdk").Type<number, number, false>;
22
21
  /** Where along its line each shown stretch is: one turn of it runs every line from end to end. */
23
- phase: number;
24
- stroke: Stroke;
25
- constructor(props?: NodeConfig<StreamLines, StreamLinesProps>);
26
- /** Send the shown stretches along their lines: a whole number runs each line that many times over. */
27
- flowTo(args: CommandArgs<{
28
- phase: number;
29
- }> & {
30
- duration: number;
31
- }): Command<StreamLinesProps>;
32
- protected own(): string;
33
- protected strokes(map: CoordinateMap, field: FieldSampler): FieldStroke[];
34
- }
22
+ phase: import("@motionscript/sdk").Type<number, number, false>;
23
+ expression: import("@motionscript/sdk").Type<string | import("../index.js").PlotSource, import("../index.js").PlotSource, false>;
24
+ params: import("@motionscript/sdk").Type<Readonly<Record<string, number>>, Readonly<Record<string, number>>, false>;
25
+ strengthFills: import("@motionscript/sdk").Type<_Fill[], _FillResolved[][], false>;
26
+ maxMagnitude: import("@motionscript/sdk").Type<number, number, false>;
27
+ graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
28
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
29
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
30
+ }>, {
31
+ readonly flowTo: readonly ["phase"];
32
+ readonly morphTo: readonly ["expression"];
33
+ readonly paramsTo: readonly ["params"];
34
+ readonly strokeTo: readonly ["stroke"];
35
+ readonly shadowTo: readonly ["shadow"];
36
+ }, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
37
+ /** How far apart the lines start, in graph units. */
38
+ spacing: import("@motionscript/sdk").Type<number, number, false>;
39
+ /** How far each line runs from where it starts, in graph units along itself. */
40
+ length: import("@motionscript/sdk").Type<number, number, false>;
41
+ /** The share of each line that is shown at once; one shows all of it. */
42
+ window: import("@motionscript/sdk").Type<number, number, false>;
43
+ /** Where along its line each shown stretch is: one turn of it runs every line from end to end. */
44
+ phase: import("@motionscript/sdk").Type<number, number, false>;
45
+ expression: import("@motionscript/sdk").Type<string | import("../index.js").PlotSource, import("../index.js").PlotSource, false>;
46
+ params: import("@motionscript/sdk").Type<Readonly<Record<string, number>>, Readonly<Record<string, number>>, false>;
47
+ strengthFills: import("@motionscript/sdk").Type<_Fill[], _FillResolved[][], false>;
48
+ maxMagnitude: import("@motionscript/sdk").Type<number, number, false>;
49
+ graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
50
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
51
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
52
+ }>, null>>;
53
+ export type StreamLines = NodeOf<typeof StreamLines>;
35
54
  //# sourceMappingURL=stream-lines.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stream-lines.d.ts","sourceRoot":"","sources":["../../src/plots/stream-lines.ts"],"names":[],"mappings":"AAAA,OAAO,EAKH,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,MAAM,EAEd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,KAAK,UAAU,EAAE,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAKpG,MAAM,WAAW,gBAAiB,SAAQ,UAAU;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAOD;;;;GAIG;AACH,qBAQa,WAAY,SAAQ,SAAS,CAAC,gBAAgB,CAAC;IACxD,qDAAqD;IACG,OAAO,EAAE,MAAM,CAAC;IACxE,gFAAgF;IAC3B,MAAM,EAAE,MAAM,CAAC;IACpE,yEAAyE;IACR,MAAM,EAAE,MAAM,CAAC;IAChF,kGAAkG;IACpD,KAAK,EAAE,MAAM,CAAC;IAGpD,MAAM,EAAE,MAAM,CAAC;gBAEX,KAAK,CAAC,EAAE,UAAU,CA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,WAAW,CAAC,CAAC"}
@@ -1,94 +1,75 @@
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, node, property, strokeProperty, } from "@motionscript/sdk";
8
- import { FieldMark } from "../kit/field-mark.js";
1
+ import { component2d, Types, } from "@motionscript/sdk";
2
+ import { drawField, FIELD_COMMANDS, FIELD_STATE, traceField } from "../kit/field-mark.js";
9
3
  import { PLOT_COLOR } from "../kit/furniture.js";
10
- import { clamp, stated } from "../kit/geometry.js";
11
- import { SYSTEMS } from "../kit/placement.js";
4
+ import { clamp } from "../kit/geometry.js";
5
+ import { inkSize, reading, traced } from "../kit/mark.js";
12
6
  const MAX_LINES = 1600;
13
7
  /** Steps a line takes across one spacing: what keeps a tight swirl round. */
14
8
  const STEPS_PER_SPACING = 8;
15
9
  const MAX_STEPS = 600;
10
+ const state = {
11
+ ...FIELD_STATE,
12
+ /** How far apart the lines start, in graph units. */
13
+ spacing: Types.number(1, { min: 0.01, step: 0.1 }),
14
+ /** How far each line runs from where it starts, in graph units along itself. */
15
+ length: Types.number(3, { min: 0, step: 0.1 }),
16
+ /** The share of each line that is shown at once; one shows all of it. */
17
+ window: Types.number(1, { min: 0.01, max: 1, step: 0.01 }),
18
+ /** Where along its line each shown stretch is: one turn of it runs every line from end to end. */
19
+ phase: Types.number(0, { step: 0.01 }),
20
+ };
21
+ const LINES = {
22
+ own: (s) => `${s.spacing}|${s.length}|${s.window}|${s.phase}`,
23
+ strokes: (s, map, field) => lines(s, map, field),
24
+ };
25
+ const traceLines = (s, read) => traceField("streamLines", LINES, s, read);
16
26
  /**
17
27
  * The lines a vector field carries a point along, one from each point of a
18
28
  * grid: `(-y, x)` draws circles. With a `window` below one, each line shows
19
29
  * only a stretch of itself, and `flowTo` sends those stretches along.
20
30
  */
21
- let StreamLines = class StreamLines extends FieldMark {
22
- constructor(props) {
23
- super(props ?? {});
24
- }
25
- /** Send the shown stretches along their lines: a whole number runs each line that many times over. */
26
- flowTo(args) {
27
- return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });
28
- }
29
- own() {
30
- return `${this.spacing}|${this.length}|${this.window}|${this.phase}`;
31
- }
32
- strokes(map, field) {
33
- const [x0, x1] = map.xRange;
34
- const [y0, y1] = map.yRange;
35
- let spacing = Math.max(this.spacing, 1e-6);
36
- const count = () => (Math.floor((x1 - x0) / spacing) + 1) * (Math.floor((y1 - y0) / spacing) + 1);
37
- while (count() > MAX_LINES)
38
- spacing *= 2;
39
- const step = spacing / STEPS_PER_SPACING;
40
- const steps = Math.min(MAX_STEPS, Math.round(this.length / step));
41
- if (steps < 1)
42
- return [];
43
- // A line is followed a little past what is shown, so it leaves the box rather than stopping at its edge.
44
- const inside = (x, y) => x >= x0 - spacing && x <= x1 + spacing && y >= y0 - spacing && y <= y1 + spacing;
45
- const window = clamp(this.window, 0, 1);
46
- const drawn = [];
47
- let index = 0;
48
- for (let i = Math.ceil(x0 / spacing - 1e-9); i * spacing <= x1 + 1e-9; i++) {
49
- for (let j = Math.ceil(y0 / spacing - 1e-9); j * spacing <= y1 + 1e-9; j++) {
50
- const line = follow(field, i * spacing, j * spacing, step, steps, inside);
51
- index++;
52
- if (line.points.length < 2)
53
- continue;
54
- const shown = window >= 1 ? line.points : stretch(line.points, window, this.phase + stagger(index));
55
- if (shown.length < 2)
56
- continue;
57
- drawn.push({ runs: [shown.map((p) => map.toPoint(p.x, p.y))], magnitude: line.magnitude });
58
- }
31
+ export const StreamLines = traced(component2d({
32
+ key: "streamLines",
33
+ state,
34
+ defaults: { stroke: { weight: 2, fill: PLOT_COLOR, align: "center", cap: "round", join: "round" }, width: "hug", height: "hug" },
35
+ commands: {
36
+ ...FIELD_COMMANDS,
37
+ /** Send the shown stretches along their lines: a whole number runs each line that many times over. */
38
+ flowTo: { args: ["phase"] },
39
+ },
40
+ measure: (_measurer, s) => inkSize(traceLines(s, reading(s)).runs),
41
+ render: (ctx, s) => drawField(ctx, s, traceLines(s, reading(s))),
42
+ }), (s, read) => traceLines(s, read).runs);
43
+ function lines(s, map, field) {
44
+ const [x0, x1] = map.xRange;
45
+ const [y0, y1] = map.yRange;
46
+ let spacing = Math.max(s.spacing, 1e-6);
47
+ const count = () => (Math.floor((x1 - x0) / spacing) + 1) * (Math.floor((y1 - y0) / spacing) + 1);
48
+ while (count() > MAX_LINES)
49
+ spacing *= 2;
50
+ const step = spacing / STEPS_PER_SPACING;
51
+ const steps = Math.min(MAX_STEPS, Math.round(s.length / step));
52
+ if (steps < 1)
53
+ return [];
54
+ // A line is followed a little past what is shown, so it leaves the box rather than stopping at its edge.
55
+ const inside = (x, y) => x >= x0 - spacing && x <= x1 + spacing && y >= y0 - spacing && y <= y1 + spacing;
56
+ const window = clamp(s.window, 0, 1);
57
+ const drawn = [];
58
+ let index = 0;
59
+ for (let i = Math.ceil(x0 / spacing - 1e-9); i * spacing <= x1 + 1e-9; i++) {
60
+ for (let j = Math.ceil(y0 / spacing - 1e-9); j * spacing <= y1 + 1e-9; j++) {
61
+ const line = follow(field, i * spacing, j * spacing, step, steps, inside);
62
+ index++;
63
+ if (line.points.length < 2)
64
+ continue;
65
+ const shown = window >= 1 ? line.points : stretch(line.points, window, s.phase + stagger(index));
66
+ if (shown.length < 2)
67
+ continue;
68
+ drawn.push({ runs: [shown.map((p) => map.toPoint(p.x, p.y))], magnitude: line.magnitude });
59
69
  }
60
- return drawn;
61
70
  }
62
- };
63
- __decorate([
64
- property({ default: 1, min: 0.01, step: 0.1 })
65
- ], StreamLines.prototype, "spacing", void 0);
66
- __decorate([
67
- property({ default: 3, min: 0, step: 0.1 })
68
- ], StreamLines.prototype, "length", void 0);
69
- __decorate([
70
- property({ default: 1, min: 0.01, max: 1, step: 0.01 })
71
- ], StreamLines.prototype, "window", void 0);
72
- __decorate([
73
- property({ default: 0, step: 0.01 })
74
- ], StreamLines.prototype, "phase", void 0);
75
- __decorate([
76
- strokeProperty({ default: { weight: 2, fill: PLOT_COLOR, align: "center", cap: "round", join: "round" } })
77
- ], StreamLines.prototype, "stroke", void 0);
78
- __decorate([
79
- command({ args: ["phase"] })
80
- ], StreamLines.prototype, "flowTo", null);
81
- StreamLines = __decorate([
82
- node({
83
- key: "streamLines",
84
- within: SYSTEMS,
85
- parentKey: "shape",
86
- forkable: true,
87
- layout: { children: "freeform", defaultWidthMode: "hug", defaultHeightMode: "hug", acceptsChildren: false },
88
- seed: { expression: "(sin(y), cos(x))" },
89
- })
90
- ], StreamLines);
91
- export { StreamLines };
71
+ return drawn;
72
+ }
92
73
  /** The graph points a field carries a point through from `(x, y)`, at an even pace, and how strong it was on the way. */
93
74
  function follow(field, x, y, step, steps, inside) {
94
75
  const points = [{ x, y }];
@@ -1 +1 @@
1
- {"version":3,"file":"stream-lines.js","sourceRoot":"","sources":["../../src/plots/stream-lines.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,OAAO,EACP,IAAI,EACJ,QAAQ,EACR,cAAc,GAMjB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,SAAS,EAAwD,MAAM,mBAAmB,CAAC;AACpG,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAS3C,MAAM,SAAS,GAAG,IAAI,CAAC;AACvB,6EAA6E;AAC7E,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,MAAM,SAAS,GAAG,GAAG,CAAC;AAEtB;;;;GAIG;AASI,IAAM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,CAAC,EAAE,GAAG,CAAC,CAAC;IAC5B,IAAI,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IAC5B,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;IAC/B,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED,6HAA6H;AAC7H,SAAS,OAAO,CAAC,KAAa;IAC1B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,UAAU,CAAC;IACrD,OAAO,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import {\r\n command,\r\n node,\r\n property,\r\n strokeProperty,\r\n type Command,\r\n type CommandArgs,\r\n type NodeConfig,\r\n type Stroke,\r\n type Vector2,\r\n} from \"@motionscript/sdk\";\r\nimport type { CoordinateMap } from \"../kit/coords\";\r\nimport { FieldMark, type FieldProps, type FieldSampler, type FieldStroke } from \"../kit/field-mark\";\r\nimport { PLOT_COLOR } from \"../kit/furniture\";\r\nimport { clamp, stated } from \"../kit/geometry\";\r\nimport { SYSTEMS } from \"../kit/placement\";\r\n\r\nexport interface StreamLinesProps extends FieldProps {\r\n spacing?: number;\r\n length?: number;\r\n window?: number;\r\n phase?: number;\r\n}\r\n\r\nconst MAX_LINES = 1600;\r\n/** Steps a line takes across one spacing: what keeps a tight swirl round. */\r\nconst STEPS_PER_SPACING = 8;\r\nconst MAX_STEPS = 600;\r\n\r\n/**\r\n * The lines a vector field carries a point along, one from each point of a\r\n * grid: `(-y, x)` draws circles. With a `window` below one, each line shows\r\n * only a stretch of itself, and `flowTo` sends those stretches along.\r\n */\r\n@node({\r\n key: \"streamLines\",\r\n within: SYSTEMS,\r\n parentKey: \"shape\",\r\n forkable: true,\r\n layout: { children: \"freeform\", defaultWidthMode: \"hug\", defaultHeightMode: \"hug\", acceptsChildren: false },\r\n seed: { expression: \"(sin(y), cos(x))\" },\r\n})\r\nexport class StreamLines extends FieldMark<StreamLinesProps> {\r\n /** How far apart the lines start, in graph units. */\r\n @property({ default: 1, min: 0.01, step: 0.1 }) declare spacing: number;\r\n /** How far each line runs from where it starts, in graph units along itself. */\r\n @property({ default: 3, min: 0, step: 0.1 }) declare length: number;\r\n /** The share of each line that is shown at once; one shows all of it. */\r\n @property({ default: 1, min: 0.01, max: 1, step: 0.01 }) declare window: number;\r\n /** Where along its line each shown stretch is: one turn of it runs every line from end to end. */\r\n @property({ default: 0, step: 0.01 }) declare phase: number;\r\n\r\n @strokeProperty({ default: { weight: 2, fill: PLOT_COLOR, align: \"center\", cap: \"round\", join: \"round\" } })\r\n declare stroke: Stroke;\r\n\r\n constructor(props?: NodeConfig<StreamLines, StreamLinesProps>) {\r\n super(props ?? {});\r\n }\r\n\r\n /** Send the shown stretches along their lines: a whole number runs each line that many times over. */\r\n @command({ args: [\"phase\"] })\r\n flowTo(args: CommandArgs<{ phase: number }> & { duration: number }): Command<StreamLinesProps> {\r\n return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });\r\n }\r\n\r\n protected own(): string {\r\n return `${this.spacing}|${this.length}|${this.window}|${this.phase}`;\r\n }\r\n\r\n protected strokes(map: CoordinateMap, field: FieldSampler): FieldStroke[] {\r\n const [x0, x1] = map.xRange;\r\n const [y0, y1] = map.yRange;\r\n let spacing = Math.max(this.spacing, 1e-6);\r\n const count = () => (Math.floor((x1 - x0) / spacing) + 1) * (Math.floor((y1 - y0) / spacing) + 1);\r\n while (count() > MAX_LINES) spacing *= 2;\r\n const step = spacing / STEPS_PER_SPACING;\r\n const steps = Math.min(MAX_STEPS, Math.round(this.length / step));\r\n if (steps < 1) return [];\r\n // A line is followed a little past what is shown, so it leaves the box rather than stopping at its edge.\r\n const inside = (x: number, y: number) => x >= x0 - spacing && x <= x1 + spacing && y >= y0 - spacing && y <= y1 + spacing;\r\n const window = clamp(this.window, 0, 1);\r\n\r\n const drawn: FieldStroke[] = [];\r\n let index = 0;\r\n for (let i = Math.ceil(x0 / spacing - 1e-9); i * spacing <= x1 + 1e-9; i++) {\r\n for (let j = Math.ceil(y0 / spacing - 1e-9); j * spacing <= y1 + 1e-9; j++) {\r\n const line = follow(field, i * spacing, j * spacing, step, steps, inside);\r\n index++;\r\n if (line.points.length < 2) continue;\r\n const shown = window >= 1 ? line.points : stretch(line.points, window, this.phase + stagger(index));\r\n if (shown.length < 2) continue;\r\n drawn.push({ runs: [shown.map((p) => map.toPoint(p.x, p.y))], magnitude: line.magnitude });\r\n }\r\n }\r\n return drawn;\r\n }\r\n}\r\n\r\n/** The graph points a field carries a point through from `(x, y)`, at an even pace, and how strong it was on the way. */\r\nfunction follow(\r\n field: FieldSampler,\r\n x: number,\r\n y: number,\r\n step: number,\r\n steps: number,\r\n inside: (x: number, y: number) => boolean,\r\n): { points: Vector2[]; magnitude: number } {\r\n const points: Vector2[] = [{ x, y }];\r\n const v: Vector2 = { x: 0, y: 0 };\r\n let strength = 0;\r\n let read = 0;\r\n // The field's direction at a point, as a unit step; `false` where it has none or is at rest.\r\n const heading = (px: number, py: number, out: Vector2): boolean => {\r\n if (!field(px, py, v)) return false;\r\n const magnitude = Math.hypot(v.x, v.y);\r\n if (!(magnitude > 1e-9)) return false;\r\n out.x = v.x / magnitude;\r\n out.y = v.y / magnitude;\r\n strength += magnitude;\r\n read++;\r\n return true;\r\n };\r\n const a: Vector2 = { x: 0, y: 0 };\r\n const b: Vector2 = { x: 0, y: 0 };\r\n for (let i = 0; i < steps; i++) {\r\n // Midpoint rule: the direction half a step on is the one the whole step takes.\r\n if (!heading(x, y, a) || !heading(x + (a.x * step) / 2, y + (a.y * step) / 2, b)) break;\r\n x += b.x * step;\r\n y += b.y * step;\r\n if (!inside(x, y)) break;\r\n points.push({ x, y });\r\n }\r\n return { points, magnitude: read > 0 ? strength / read : 0 };\r\n}\r\n\r\n/** The part of `points` a window `share` long shows at `phase`: it enters at one end and leaves by the other. */\r\nfunction stretch(points: Vector2[], share: number, phase: number): Vector2[] {\r\n const turn = phase - Math.floor(phase);\r\n const end = turn * (1 + share);\r\n const from = Math.max(0, end - share);\r\n const to = Math.min(1, end);\r\n if (!(to > from)) return [];\r\n const last = points.length - 1;\r\n return points.slice(Math.floor(from * last), Math.ceil(to * last) + 1);\r\n}\r\n\r\n/** A share of a turn that differs from line to line and never from frame to frame, so the stretches do not march in step. */\r\nfunction stagger(index: number): number {\r\n const mixed = Math.sin(index * 12.9898) * 43758.5453;\r\n return mixed - Math.floor(mixed);\r\n}\r\n"]}
1
+ {"version":3,"file":"stream-lines.js","sourceRoot":"","sources":["../../src/plots/stream-lines.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,KAAK,GAYR,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,EAA6F,MAAM,mBAAmB,CAAC;AAClL,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAoB,MAAM,aAAa,CAAC;AASzE,MAAM,SAAS,GAAG,IAAI,CAAC;AACvB,6EAA6E;AAC7E,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,MAAM,SAAS,GAAG,GAAG,CAAC;AAEtB,MAAM,KAAK,GAAG;IACV,GAAG,WAAW;IACd,qDAAqD;IACrD,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IAClD,gFAAgF;IAChF,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,EA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AAK,CAAC,CAAC;IACtC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC5B,IAAI,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IAC5B,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;IAC/B,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED,6HAA6H;AAC7H,SAAS,OAAO,CAAC,KAAa;IAC1B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,OAAO,CAAC,GAAG,UAAU,CAAC;IACrD,OAAO,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import {\r\n component2d,\r\n Types,\r\n type NodeOf,\r\n type Vector2,\r\n // Named so the emitted declaration reaches these through the sdk, not core.\r\n type Fill as _Fill,\r\n type FillResolved as _FillResolved,\r\n type Node2D as _Node2D,\r\n type Node2DProps as _Node2DProps,\r\n type Shadow as _Shadow,\r\n type ShadowResolved as _ShadowResolved,\r\n type Stroke as _Stroke,\r\n type StrokeResolved as _StrokeResolved,\r\n} from \"@motionscript/sdk\";\r\nimport type { CoordinateMap } from \"../kit/coords\";\r\nimport { drawField, FIELD_COMMANDS, FIELD_STATE, traceField, type FieldDrawing, type FieldProps, type FieldSampler, type FieldStroke, type FieldValues } from \"../kit/field-mark\";\r\nimport { PLOT_COLOR } from \"../kit/furniture\";\r\nimport { clamp } from \"../kit/geometry\";\r\nimport { inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\r\n\r\nexport interface StreamLinesProps extends FieldProps {\r\n spacing?: number;\r\n length?: number;\r\n window?: number;\r\n phase?: number;\r\n}\r\n\r\nconst MAX_LINES = 1600;\r\n/** Steps a line takes across one spacing: what keeps a tight swirl round. */\r\nconst STEPS_PER_SPACING = 8;\r\nconst MAX_STEPS = 600;\r\n\r\nconst state = {\r\n ...FIELD_STATE,\r\n /** How far apart the lines start, in graph units. */\r\n spacing: Types.number(1, { min: 0.01, step: 0.1 }),\r\n /** How far each line runs from where it starts, in graph units along itself. */\r\n length: Types.number(3, { min: 0, step: 0.1 }),\r\n /** The share of each line that is shown at once; one shows all of it. */\r\n window: Types.number(1, { min: 0.01, max: 1, step: 0.01 }),\r\n /** Where along its line each shown stretch is: one turn of it runs every line from end to end. */\r\n phase: Types.number(0, { step: 0.01 }),\r\n};\r\n\r\ninterface LinesValues extends FieldValues {\r\n readonly spacing: number;\r\n readonly length: number;\r\n readonly window: number;\r\n readonly phase: number;\r\n}\r\n\r\nconst LINES: FieldDrawing<LinesValues> = {\r\n own: (s) => `${s.spacing}|${s.length}|${s.window}|${s.phase}`,\r\n strokes: (s, map, field) => lines(s, map, field),\r\n};\r\n\r\nconst traceLines = (s: LinesValues, read: MarkReading) => traceField(\"streamLines\", LINES, s, read);\r\n\r\n/**\r\n * The lines a vector field carries a point along, one from each point of a\r\n * grid: `(-y, x)` draws circles. With a `window` below one, each line shows\r\n * only a stretch of itself, and `flowTo` sends those stretches along.\r\n */\r\nexport const StreamLines = traced(component2d({\r\n key: \"streamLines\",\r\n state,\r\n defaults: { stroke: { weight: 2, fill: PLOT_COLOR, align: \"center\", cap: \"round\", join: \"round\" }, width: \"hug\", height: \"hug\" },\r\n commands: {\r\n ...FIELD_COMMANDS,\r\n /** Send the shown stretches along their lines: a whole number runs each line that many times over. */\r\n flowTo: { args: [\"phase\"] },\r\n },\r\n measure: (_measurer, s) => inkSize(traceLines(s, reading(s)).runs),\r\n render: (ctx, s) => drawField(ctx, s, traceLines(s, reading(s))),\r\n}), (s: LinesValues, read: MarkReading) => traceLines(s, read).runs);\r\n\r\nexport type StreamLines = NodeOf<typeof StreamLines>;\r\n\r\nfunction lines(s: LinesValues, map: CoordinateMap, field: FieldSampler): FieldStroke[] {\r\n const [x0, x1] = map.xRange;\r\n const [y0, y1] = map.yRange;\r\n let spacing = Math.max(s.spacing, 1e-6);\r\n const count = () => (Math.floor((x1 - x0) / spacing) + 1) * (Math.floor((y1 - y0) / spacing) + 1);\r\n while (count() > MAX_LINES) spacing *= 2;\r\n const step = spacing / STEPS_PER_SPACING;\r\n const steps = Math.min(MAX_STEPS, Math.round(s.length / step));\r\n if (steps < 1) return [];\r\n // A line is followed a little past what is shown, so it leaves the box rather than stopping at its edge.\r\n const inside = (x: number, y: number) => x >= x0 - spacing && x <= x1 + spacing && y >= y0 - spacing && y <= y1 + spacing;\r\n const window = clamp(s.window, 0, 1);\r\n\r\n const drawn: FieldStroke[] = [];\r\n let index = 0;\r\n for (let i = Math.ceil(x0 / spacing - 1e-9); i * spacing <= x1 + 1e-9; i++) {\r\n for (let j = Math.ceil(y0 / spacing - 1e-9); j * spacing <= y1 + 1e-9; j++) {\r\n const line = follow(field, i * spacing, j * spacing, step, steps, inside);\r\n index++;\r\n if (line.points.length < 2) continue;\r\n const shown = window >= 1 ? line.points : stretch(line.points, window, s.phase + stagger(index));\r\n if (shown.length < 2) continue;\r\n drawn.push({ runs: [shown.map((p) => map.toPoint(p.x, p.y))], magnitude: line.magnitude });\r\n }\r\n }\r\n return drawn;\r\n}\r\n\r\n/** The graph points a field carries a point through from `(x, y)`, at an even pace, and how strong it was on the way. */\r\nfunction follow(\r\n field: FieldSampler,\r\n x: number,\r\n y: number,\r\n step: number,\r\n steps: number,\r\n inside: (x: number, y: number) => boolean,\r\n): { points: Vector2[]; magnitude: number } {\r\n const points: Vector2[] = [{ x, y }];\r\n const v: Vector2 = { x: 0, y: 0 };\r\n let strength = 0;\r\n let read = 0;\r\n // The field's direction at a point, as a unit step; `false` where it has none or is at rest.\r\n const heading = (px: number, py: number, out: Vector2): boolean => {\r\n if (!field(px, py, v)) return false;\r\n const magnitude = Math.hypot(v.x, v.y);\r\n if (!(magnitude > 1e-9)) return false;\r\n out.x = v.x / magnitude;\r\n out.y = v.y / magnitude;\r\n strength += magnitude;\r\n read++;\r\n return true;\r\n };\r\n const a: Vector2 = { x: 0, y: 0 };\r\n const b: Vector2 = { x: 0, y: 0 };\r\n for (let i = 0; i < steps; i++) {\r\n // Midpoint rule: the direction half a step on is the one the whole step takes.\r\n if (!heading(x, y, a) || !heading(x + (a.x * step) / 2, y + (a.y * step) / 2, b)) break;\r\n x += b.x * step;\r\n y += b.y * step;\r\n if (!inside(x, y)) break;\r\n points.push({ x, y });\r\n }\r\n return { points, magnitude: read > 0 ? strength / read : 0 };\r\n}\r\n\r\n/** The part of `points` a window `share` long shows at `phase`: it enters at one end and leaves by the other. */\r\nfunction stretch(points: Vector2[], share: number, phase: number): Vector2[] {\r\n const turn = phase - Math.floor(phase);\r\n const end = turn * (1 + share);\r\n const from = Math.max(0, end - share);\r\n const to = Math.min(1, end);\r\n if (!(to > from)) return [];\r\n const last = points.length - 1;\r\n return points.slice(Math.floor(from * last), Math.ceil(to * last) + 1);\r\n}\r\n\r\n/** A share of a turn that differs from line to line and never from frame to frame, so the stretches do not march in step. */\r\nfunction stagger(index: number): number {\r\n const mixed = Math.sin(index * 12.9898) * 43758.5453;\r\n return mixed - Math.floor(mixed);\r\n}\r\n"]}
@@ -1,6 +1,6 @@
1
- import { type Command, type CommandArgs, type NodeConfig } from "@motionscript/sdk";
1
+ import { type NodeOf, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Shadow as _Shadow, type ShadowResolved as _ShadowResolved, type Stroke as _Stroke, type StrokeResolved as _StrokeResolved } from "@motionscript/sdk";
2
2
  import type { Interval } from "../kit/coords.js";
3
- import { FunctionPlot, type FunctionPlotProps } from "./function-plot.js";
3
+ import { type FunctionPlotProps } from "./function-plot.js";
4
4
  export interface TracedPathProps extends FunctionPlotProps {
5
5
  from?: number;
6
6
  value?: number;
@@ -12,20 +12,39 @@ export interface TracedPathProps extends FunctionPlotProps {
12
12
  * (`"=[t]"`) and the trail grows as the variable is driven, or drive it with
13
13
  * `traceTo`; a `tail` keeps only its most recent stretch.
14
14
  */
15
- export declare class TracedPath extends FunctionPlot<TracedPathProps> {
15
+ export declare const TracedPath: import("@motionscript/sdk").Component<"tracedPath", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
16
16
  /** The value the trail starts at. */
17
- from: number;
17
+ from: import("@motionscript/sdk").Type<number, number, false>;
18
18
  /** The value the point is at now: where the trail ends. */
19
- value: number;
19
+ value: import("@motionscript/sdk").Type<number, number, false>;
20
20
  /** How much of the trail is kept, in the value's own units; zero keeps all of it. */
21
- tail: number;
22
- constructor(props?: NodeConfig<TracedPath, TracedPathProps>);
23
- /** Carry the point on to another value, the trail following it. */
24
- traceTo(args: CommandArgs<{
25
- value: number;
26
- }> & {
27
- duration: number;
28
- }): Command<TracedPathProps>;
29
- protected span(): Interval | null;
30
- }
21
+ tail: import("@motionscript/sdk").Type<number, number, false>;
22
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
23
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
24
+ params: import("@motionscript/sdk").Type<Readonly<Record<string, number>>, Readonly<Record<string, number>>, false>;
25
+ expression: import("@motionscript/sdk").Type<string | import("../index.js").PlotSource, import("../index.js").PlotSource, false>;
26
+ domain: import("@motionscript/sdk").Type<Interval | null, Interval | null, false>;
27
+ graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
28
+ }>, {
29
+ readonly traceTo: readonly ["value"];
30
+ readonly strokeTo: readonly ["stroke"];
31
+ readonly shadowTo: readonly ["shadow"];
32
+ readonly morphTo: readonly ["expression"];
33
+ readonly paramsTo: readonly ["params"];
34
+ readonly domainTo: readonly ["domain"];
35
+ }, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
36
+ /** The value the trail starts at. */
37
+ from: import("@motionscript/sdk").Type<number, number, false>;
38
+ /** The value the point is at now: where the trail ends. */
39
+ value: import("@motionscript/sdk").Type<number, number, false>;
40
+ /** How much of the trail is kept, in the value's own units; zero keeps all of it. */
41
+ tail: import("@motionscript/sdk").Type<number, number, false>;
42
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
43
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
44
+ params: import("@motionscript/sdk").Type<Readonly<Record<string, number>>, Readonly<Record<string, number>>, false>;
45
+ expression: import("@motionscript/sdk").Type<string | import("../index.js").PlotSource, import("../index.js").PlotSource, false>;
46
+ domain: import("@motionscript/sdk").Type<Interval | null, Interval | null, false>;
47
+ graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
48
+ }>, null>>;
49
+ export type TracedPath = NodeOf<typeof TracedPath>;
31
50
  //# sourceMappingURL=traced-path.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"traced-path.d.ts","sourceRoot":"","sources":["../../src/plots/traced-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqC,KAAK,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACvH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAG9C,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAGvE,MAAM,WAAW,eAAgB,SAAQ,iBAAiB;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,qBASa,UAAW,SAAQ,YAAY,CAAC,eAAe,CAAC;IACzD,qCAAqC;IACQ,IAAI,EAAE,MAAM,CAAC;IAC1D,2DAA2D;IACd,KAAK,EAAE,MAAM,CAAC;IAC3D,qFAAqF;IAChC,IAAI,EAAE,MAAM,CAAC;gBAEtD,KAAK,CAAC,EAAE,UAAU,CAAC,UAAU,EAAE,eAAe,CAAC;IAI3D,mEAAmE;IAEnE,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,eAAe,CAAC;cAI3E,IAAI,IAAI,QAAQ,GAAG,IAAI;CAK7C"}
1
+ {"version":3,"file":"traced-path.d.ts","sourceRoot":"","sources":["../../src/plots/traced-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,KAAK,MAAM,EAEX,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EAChC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACtC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACzC,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAqD,KAAK,iBAAiB,EAAmB,MAAM,iBAAiB,CAAC;AAE7H,MAAM,WAAW,eAAgB,SAAQ,iBAAiB;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAmBD;;;;;GAKG;AACH,eAAO,MAAM,UAAU;IApBnB,qCAAqC;;IAErC,2DAA2D;;IAE3D,qFAAqF;;;;;;;;;;;;;;;;IAJrF,qCAAqC;;IAErC,2DAA2D;;IAE3D,qFAAqF;;;;;;;;UA2B1E,CAAC;AAEhB,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC"}
@@ -1,56 +1,41 @@
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;
1
+ import { component2d, Types, } from "@motionscript/sdk";
2
+ import { omit } from "../kit/component.js";
3
+ import { drawMark, inkSize, reading, traced } from "../kit/mark.js";
4
+ import { PLOT_COMMANDS, PLOT_STATE, PLOT_STROKE, tracePlot } from "./function-plot.js";
5
+ const state = {
6
+ // It reveals itself by its value, so it trims no outline of its own.
7
+ ...omit(PLOT_STATE, "start", "end"),
8
+ /** The value the trail starts at. */
9
+ from: Types.number(0, { step: 0.1 }),
10
+ /** The value the point is at now: where the trail ends. */
11
+ value: Types.number(0, { step: 0.1 }),
12
+ /** How much of the trail is kept, in the value's own units; zero keeps all of it. */
13
+ tail: Types.number(0, { min: 0, step: 0.1 }),
6
14
  };
7
- import { command, node, property, withdraw } from "@motionscript/sdk";
8
- import { stated } from "../kit/geometry.js";
9
- import { SYSTEMS } from "../kit/placement.js";
10
- import { FunctionPlot } from "./function-plot.js";
11
- import { OUTLINE_TRIM } from "../kit/withdrawn.js";
12
15
  /**
13
16
  * The trail a point leaves as a value changes: the curve of its equation from
14
17
  * where the value began to where it is now. Bind `value` to a variable
15
18
  * (`"=[t]"`) and the trail grows as the variable is driven, or drive it with
16
19
  * `traceTo`; a `tail` keeps only its most recent stretch.
17
20
  */
18
- let TracedPath = class TracedPath extends FunctionPlot {
19
- constructor(props) {
20
- super((props ?? {}));
21
- }
22
- /** Carry the point on to another value, the trail following it. */
23
- traceTo(args) {
24
- return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });
25
- }
26
- span() {
27
- const { from, value, tail } = this;
28
- const kept = tail > 0 ? Math.min(Math.abs(value - from), tail) : Math.abs(value - from);
29
- return value >= from ? [value - kept, value] : [value, value + kept];
30
- }
31
- };
32
- __decorate([
33
- property({ default: 0, step: 0.1 })
34
- ], TracedPath.prototype, "from", void 0);
35
- __decorate([
36
- property({ default: 0, step: 0.1 })
37
- ], TracedPath.prototype, "value", void 0);
38
- __decorate([
39
- property({ default: 0, min: 0, step: 0.1 })
40
- ], TracedPath.prototype, "tail", void 0);
41
- __decorate([
42
- command({ args: ["value"] })
43
- ], TracedPath.prototype, "traceTo", null);
44
- TracedPath = __decorate([
45
- node({
46
- key: "tracedPath",
47
- within: SYSTEMS,
48
- parentKey: "functionPlot",
49
- forkable: true,
50
- layout: { children: "freeform", defaultWidthMode: "hug", defaultHeightMode: "hug", acceptsChildren: false },
51
- seed: { expression: "(2cos(t), sin(2t))", value: 6.28 },
52
- }),
53
- withdraw(...OUTLINE_TRIM)
54
- ], TracedPath);
55
- export { TracedPath };
21
+ export const TracedPath = traced(component2d({
22
+ key: "tracedPath",
23
+ state,
24
+ defaults: { stroke: PLOT_STROKE, width: "hug", height: "hug" },
25
+ commands: {
26
+ ...omit(PLOT_COMMANDS, "progressTo", "flash"),
27
+ /** Carry the point on to another value, the trail following it. */
28
+ traceTo: { args: ["value"] },
29
+ },
30
+ measure: (_measurer, s) => inkSize(traceTrail(s, reading(s))),
31
+ render: (ctx, s) => drawMark(ctx, s, traceTrail(s, reading(s))),
32
+ }), traceTrail);
33
+ function traceTrail(s, read) {
34
+ return tracePlot(s, read, span(s));
35
+ }
36
+ /** The span of the free variable the trail covers: from where the value began, or its tail, to where it is. */
37
+ function span({ from, value, tail }) {
38
+ const kept = tail > 0 ? Math.min(Math.abs(value - from), tail) : Math.abs(value - from);
39
+ return value >= from ? [value - kept, value] : [value, value + kept];
40
+ }
56
41
  //# sourceMappingURL=traced-path.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"traced-path.js","sourceRoot":"","sources":["../../src/plots/traced-path.ts"],"names":[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,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;wCAAsB;AAEb;IAA5C,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;yCAAuB;AAEN;IAApD,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;wCAAsB;AAQlE;IADC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;yCAG5B;AAhBQ,UAAU;IATtB,IAAI,CAAC;QACF,GAAG,EAAE,YAAY;QACjB,MAAM,EAAE,OAAO;QACf,SAAS,EAAE,cAAc;QACzB,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,gBAAgB,EAAE,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE;QAC3G,IAAI,EAAE,EAAE,UAAU,EAAE,oBAAoB,EAAE,KAAK,EAAE,IAAI,EAAE;KAC1D,CAAC;IACD,QAAQ,CAAC,GAAG,YAAY,CAAC;GACb,UAAU,CAuBtB","sourcesContent":["import { command, node, property, withdraw, type Command, type CommandArgs, type NodeConfig } from \"@motionscript/sdk\";\r\nimport type { Interval } from \"../kit/coords\";\r\nimport { stated } from \"../kit/geometry\";\r\nimport { SYSTEMS } from \"../kit/placement\";\r\nimport { FunctionPlot, type FunctionPlotProps } from \"./function-plot\";\r\nimport { OUTLINE_TRIM } from \"../kit/withdrawn\";\r\n\r\nexport interface TracedPathProps extends FunctionPlotProps {\r\n from?: number;\r\n value?: number;\r\n tail?: number;\r\n}\r\n\r\n/**\r\n * The trail a point leaves as a value changes: the curve of its equation from\r\n * where the value began to where it is now. Bind `value` to a variable\r\n * (`\"=[t]\"`) and the trail grows as the variable is driven, or drive it with\r\n * `traceTo`; a `tail` keeps only its most recent stretch.\r\n */\r\n@node({\r\n key: \"tracedPath\",\r\n within: SYSTEMS,\r\n parentKey: \"functionPlot\",\r\n forkable: true,\r\n layout: { children: \"freeform\", defaultWidthMode: \"hug\", defaultHeightMode: \"hug\", acceptsChildren: false },\r\n seed: { expression: \"(2cos(t), sin(2t))\", value: 6.28 },\r\n})\r\n@withdraw(...OUTLINE_TRIM)\r\nexport class TracedPath extends FunctionPlot<TracedPathProps> {\r\n /** The value the trail starts at. */\r\n @property({ default: 0, step: 0.1 }) declare from: number;\r\n /** The value the point is at now: where the trail ends. */\r\n @property({ default: 0, step: 0.1 }) declare value: number;\r\n /** How much of the trail is kept, in the value's own units; zero keeps all of it. */\r\n @property({ default: 0, min: 0, step: 0.1 }) declare tail: number;\r\n\r\n constructor(props?: NodeConfig<TracedPath, TracedPathProps>) {\r\n super((props ?? {}) as NodeConfig<FunctionPlot<TracedPathProps>, TracedPathProps>);\r\n }\r\n\r\n /** Carry the point on to another value, the trail following it. */\r\n @command({ args: [\"value\"] })\r\n traceTo(args: CommandArgs<{ value: number }> & { duration: number }): Command<TracedPathProps> {\r\n return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });\r\n }\r\n\r\n protected override span(): Interval | null {\r\n const { from, value, tail } = this;\r\n const kept = tail > 0 ? Math.min(Math.abs(value - from), tail) : Math.abs(value - from);\r\n return value >= from ? [value - kept, value] : [value, value + kept];\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"traced-path.js","sourceRoot":"","sources":["../../src/plots/traced-path.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,KAAK,GASR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAoB,MAAM,aAAa,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAA2C,MAAM,iBAAiB,CAAC;AAQ7H,M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IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACvC,CAAC;AAED,+GAA+G;AAC/G,SAAS,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAe;IAC5C,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IACxF,OAAO,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC,CAAC;AACzE,CAAC","sourcesContent":["import {\r\n component2d,\r\n Types,\r\n type NodeOf,\r\n // Named so the emitted declaration reaches these through the sdk, not core.\r\n type Node2D as _Node2D,\r\n type Node2DProps as _Node2DProps,\r\n type Shadow as _Shadow,\r\n type ShadowResolved as _ShadowResolved,\r\n type Stroke as _Stroke,\r\n type StrokeResolved as _StrokeResolved,\r\n} from \"@motionscript/sdk\";\r\nimport { omit } from \"../kit/component\";\r\nimport type { Interval } from \"../kit/coords\";\r\nimport { drawMark, inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\r\nimport { PLOT_COMMANDS, PLOT_STATE, PLOT_STROKE, tracePlot, type FunctionPlotProps, type PlotValues } from \"./function-plot\";\r\n\r\nexport interface TracedPathProps extends FunctionPlotProps {\r\n from?: number;\r\n value?: number;\r\n tail?: number;\r\n}\r\n\r\nconst state = {\r\n // It reveals itself by its value, so it trims no outline of its own.\r\n ...omit(PLOT_STATE, \"start\", \"end\"),\r\n /** The value the trail starts at. */\r\n from: Types.number(0, { step: 0.1 }),\r\n /** The value the point is at now: where the trail ends. */\r\n value: Types.number(0, { step: 0.1 }),\r\n /** How much of the trail is kept, in the value's own units; zero keeps all of it. */\r\n tail: Types.number(0, { min: 0, step: 0.1 }),\r\n};\r\n\r\ninterface TrailValues extends PlotValues {\r\n readonly from: number;\r\n readonly value: number;\r\n readonly tail: number;\r\n}\r\n\r\n/**\r\n * The trail a point leaves as a value changes: the curve of its equation from\r\n * where the value began to where it is now. Bind `value` to a variable\r\n * (`\"=[t]\"`) and the trail grows as the variable is driven, or drive it with\r\n * `traceTo`; a `tail` keeps only its most recent stretch.\r\n */\r\nexport const TracedPath = traced(component2d({\r\n key: \"tracedPath\",\r\n state,\r\n defaults: { stroke: PLOT_STROKE, width: \"hug\", height: \"hug\" },\r\n commands: {\r\n ...omit(PLOT_COMMANDS, \"progressTo\", \"flash\"),\r\n /** Carry the point on to another value, the trail following it. */\r\n traceTo: { args: [\"value\"] },\r\n },\r\n measure: (_measurer, s) => inkSize(traceTrail(s, reading(s))),\r\n render: (ctx, s) => drawMark(ctx, s, traceTrail(s, reading(s))),\r\n}), traceTrail);\r\n\r\nexport type TracedPath = NodeOf<typeof TracedPath>;\r\n\r\nfunction traceTrail(s: TrailValues, read: MarkReading) {\r\n return tracePlot(s, read, span(s));\r\n}\r\n\r\n/** The span of the free variable the trail covers: from where the value began, or its tail, to where it is. */\r\nfunction span({ from, value, tail }: TrailValues): Interval {\r\n const kept = tail > 0 ? Math.min(Math.abs(value - from), tail) : Math.abs(value - from);\r\n return value >= from ? [value - kept, value] : [value, value + kept];\r\n}\r\n"]}