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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (335) hide show
  1. package/CHANGELOG.md +144 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +49 -0
  4. package/README.md +389 -2
  5. package/dist/annotate/angle-mark.d.ts +96 -0
  6. package/dist/annotate/angle-mark.d.ts.map +1 -0
  7. package/dist/annotate/angle-mark.js +97 -0
  8. package/dist/annotate/angle-mark.js.map +1 -0
  9. package/dist/annotate/curly-brace.d.ts +115 -0
  10. package/dist/annotate/curly-brace.d.ts.map +1 -0
  11. package/dist/annotate/curly-brace.js +99 -0
  12. package/dist/annotate/curly-brace.js.map +1 -0
  13. package/dist/annotate/emphasis-mark.d.ts +80 -0
  14. package/dist/annotate/emphasis-mark.d.ts.map +1 -0
  15. package/dist/annotate/emphasis-mark.js +80 -0
  16. package/dist/annotate/emphasis-mark.js.map +1 -0
  17. package/dist/browser/THIRD_PARTY_LICENSES.txt +420 -0
  18. package/dist/browser/chunks/chunk-IRZCG6PM.js +2 -0
  19. package/dist/browser/chunks/chunk-IRZCG6PM.js.map +7 -0
  20. package/dist/browser/chunks/chunk-WMVW6ZIV.js +2 -0
  21. package/dist/browser/chunks/chunk-WMVW6ZIV.js.map +7 -0
  22. package/dist/browser/chunks/mathjax-WV55AC2P.js +61 -0
  23. package/dist/browser/chunks/mathjax-WV55AC2P.js.map +7 -0
  24. package/dist/browser/index.js +2 -0
  25. package/dist/browser/index.js.map +7 -0
  26. package/dist/browser/kit.js +2 -0
  27. package/dist/browser/kit.js.map +7 -0
  28. package/dist/browser/manifest.json +30 -0
  29. package/dist/browser/tex.js +2 -0
  30. package/dist/browser/tex.js.map +7 -0
  31. package/dist/engine.d.ts +71 -0
  32. package/dist/engine.d.ts.map +1 -0
  33. package/dist/engine.js +45 -0
  34. package/dist/engine.js.map +1 -0
  35. package/dist/index.d.ts +30 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +30 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/kit/brace.d.ts +8 -0
  40. package/dist/kit/brace.d.ts.map +1 -0
  41. package/dist/kit/brace.js +36 -0
  42. package/dist/kit/brace.js.map +1 -0
  43. package/dist/kit/cache.d.ts +30 -0
  44. package/dist/kit/cache.d.ts.map +1 -0
  45. package/dist/kit/cache.js +53 -0
  46. package/dist/kit/cache.js.map +1 -0
  47. package/dist/kit/component.d.ts +51 -0
  48. package/dist/kit/component.d.ts.map +1 -0
  49. package/dist/kit/component.js +30 -0
  50. package/dist/kit/component.js.map +1 -0
  51. package/dist/kit/contour.d.ts +8 -0
  52. package/dist/kit/contour.d.ts.map +1 -0
  53. package/dist/kit/contour.js +93 -0
  54. package/dist/kit/contour.js.map +1 -0
  55. package/dist/kit/coords.d.ts +69 -0
  56. package/dist/kit/coords.d.ts.map +1 -0
  57. package/dist/kit/coords.js +224 -0
  58. package/dist/kit/coords.js.map +1 -0
  59. package/dist/kit/curve.d.ts +28 -0
  60. package/dist/kit/curve.d.ts.map +1 -0
  61. package/dist/kit/curve.js +29 -0
  62. package/dist/kit/curve.js.map +1 -0
  63. package/dist/kit/equation.d.ts +61 -0
  64. package/dist/kit/equation.d.ts.map +1 -0
  65. package/dist/kit/equation.js +168 -0
  66. package/dist/kit/equation.js.map +1 -0
  67. package/dist/kit/equation3d.d.ts +50 -0
  68. package/dist/kit/equation3d.d.ts.map +1 -0
  69. package/dist/kit/equation3d.js +103 -0
  70. package/dist/kit/equation3d.js.map +1 -0
  71. package/dist/kit/expression.d.ts +35 -0
  72. package/dist/kit/expression.d.ts.map +1 -0
  73. package/dist/kit/expression.js +124 -0
  74. package/dist/kit/expression.js.map +1 -0
  75. package/dist/kit/field-mark.d.ts +79 -0
  76. package/dist/kit/field-mark.d.ts.map +1 -0
  77. package/dist/kit/field-mark.js +109 -0
  78. package/dist/kit/field-mark.js.map +1 -0
  79. package/dist/kit/field.d.ts +14 -0
  80. package/dist/kit/field.d.ts.map +1 -0
  81. package/dist/kit/field.js +46 -0
  82. package/dist/kit/field.js.map +1 -0
  83. package/dist/kit/follow.d.ts +109 -0
  84. package/dist/kit/follow.d.ts.map +1 -0
  85. package/dist/kit/follow.js +163 -0
  86. package/dist/kit/follow.js.map +1 -0
  87. package/dist/kit/furniture.d.ts +32 -0
  88. package/dist/kit/furniture.d.ts.map +1 -0
  89. package/dist/kit/furniture.js +92 -0
  90. package/dist/kit/furniture.js.map +1 -0
  91. package/dist/kit/geometry.d.ts +13 -0
  92. package/dist/kit/geometry.d.ts.map +1 -0
  93. package/dist/kit/geometry.js +54 -0
  94. package/dist/kit/geometry.js.map +1 -0
  95. package/dist/kit/graph.d.ts +46 -0
  96. package/dist/kit/graph.d.ts.map +1 -0
  97. package/dist/kit/graph.js +90 -0
  98. package/dist/kit/graph.js.map +1 -0
  99. package/dist/kit/mark.d.ts +72 -0
  100. package/dist/kit/mark.d.ts.map +1 -0
  101. package/dist/kit/mark.js +87 -0
  102. package/dist/kit/mark.js.map +1 -0
  103. package/dist/kit/part-fills.d.ts +23 -0
  104. package/dist/kit/part-fills.d.ts.map +1 -0
  105. package/dist/kit/part-fills.js +46 -0
  106. package/dist/kit/part-fills.js.map +1 -0
  107. package/dist/kit/place.d.ts +20 -0
  108. package/dist/kit/place.d.ts.map +1 -0
  109. package/dist/kit/place.js +66 -0
  110. package/dist/kit/place.js.map +1 -0
  111. package/dist/kit/sampler.d.ts +17 -0
  112. package/dist/kit/sampler.d.ts.map +1 -0
  113. package/dist/kit/sampler.js +250 -0
  114. package/dist/kit/sampler.js.map +1 -0
  115. package/dist/kit/scale.d.ts +12 -0
  116. package/dist/kit/scale.d.ts.map +1 -0
  117. package/dist/kit/scale.js +37 -0
  118. package/dist/kit/scale.js.map +1 -0
  119. package/dist/kit/source.d.ts +22 -0
  120. package/dist/kit/source.d.ts.map +1 -0
  121. package/dist/kit/source.js +45 -0
  122. package/dist/kit/source.js.map +1 -0
  123. package/dist/kit/system.d.ts +31 -0
  124. package/dist/kit/system.d.ts.map +1 -0
  125. package/dist/kit/system.js +71 -0
  126. package/dist/kit/system.js.map +1 -0
  127. package/dist/kit/ticks.d.ts +19 -0
  128. package/dist/kit/ticks.d.ts.map +1 -0
  129. package/dist/kit/ticks.js +78 -0
  130. package/dist/kit/ticks.js.map +1 -0
  131. package/dist/kit/withdrawn.d.ts +9 -0
  132. package/dist/kit/withdrawn.d.ts.map +1 -0
  133. package/dist/kit/withdrawn.js +9 -0
  134. package/dist/kit/withdrawn.js.map +1 -0
  135. package/dist/marks/curve-area.d.ts +51 -0
  136. package/dist/marks/curve-area.d.ts.map +1 -0
  137. package/dist/marks/curve-area.js +59 -0
  138. package/dist/marks/curve-area.js.map +1 -0
  139. package/dist/marks/drop-lines.d.ts +57 -0
  140. package/dist/marks/drop-lines.d.ts.map +1 -0
  141. package/dist/marks/drop-lines.js +43 -0
  142. package/dist/marks/drop-lines.js.map +1 -0
  143. package/dist/marks/plot-point.d.ts +71 -0
  144. package/dist/marks/plot-point.d.ts.map +1 -0
  145. package/dist/marks/plot-point.js +71 -0
  146. package/dist/marks/plot-point.js.map +1 -0
  147. package/dist/marks/riemann-sum.d.ts +58 -0
  148. package/dist/marks/riemann-sum.d.ts.map +1 -0
  149. package/dist/marks/riemann-sum.js +63 -0
  150. package/dist/marks/riemann-sum.js.map +1 -0
  151. package/dist/marks/tangent-line.d.ts +71 -0
  152. package/dist/marks/tangent-line.d.ts.map +1 -0
  153. package/dist/marks/tangent-line.js +89 -0
  154. package/dist/marks/tangent-line.js.map +1 -0
  155. package/dist/marks/vector-arrow.d.ts +60 -0
  156. package/dist/marks/vector-arrow.d.ts.map +1 -0
  157. package/dist/marks/vector-arrow.js +67 -0
  158. package/dist/marks/vector-arrow.js.map +1 -0
  159. package/dist/nodes.d.ts +43 -0
  160. package/dist/nodes.d.ts.map +1 -0
  161. package/dist/nodes.js +57 -0
  162. package/dist/nodes.js.map +1 -0
  163. package/dist/plots/function-plot.d.ts +159 -0
  164. package/dist/plots/function-plot.d.ts.map +1 -0
  165. package/dist/plots/function-plot.js +184 -0
  166. package/dist/plots/function-plot.js.map +1 -0
  167. package/dist/plots/points-plot.d.ts +64 -0
  168. package/dist/plots/points-plot.d.ts.map +1 -0
  169. package/dist/plots/points-plot.js +72 -0
  170. package/dist/plots/points-plot.js.map +1 -0
  171. package/dist/plots/stream-lines.d.ts +76 -0
  172. package/dist/plots/stream-lines.d.ts.map +1 -0
  173. package/dist/plots/stream-lines.js +122 -0
  174. package/dist/plots/stream-lines.js.map +1 -0
  175. package/dist/plots/traced-path.d.ts +70 -0
  176. package/dist/plots/traced-path.d.ts.map +1 -0
  177. package/dist/plots/traced-path.js +41 -0
  178. package/dist/plots/traced-path.js.map +1 -0
  179. package/dist/plots/vector-field.d.ts +60 -0
  180. package/dist/plots/vector-field.d.ts.map +1 -0
  181. package/dist/plots/vector-field.js +77 -0
  182. package/dist/plots/vector-field.js.map +1 -0
  183. package/dist/structures/graph-layout.d.ts +11 -0
  184. package/dist/structures/graph-layout.d.ts.map +1 -0
  185. package/dist/structures/graph-layout.js +135 -0
  186. package/dist/structures/graph-layout.js.map +1 -0
  187. package/dist/structures/network-graph.d.ts +174 -0
  188. package/dist/structures/network-graph.d.ts.map +1 -0
  189. package/dist/structures/network-graph.js +240 -0
  190. package/dist/structures/network-graph.js.map +1 -0
  191. package/dist/structures/sample-space.d.ts +114 -0
  192. package/dist/structures/sample-space.d.ts.map +1 -0
  193. package/dist/structures/sample-space.js +161 -0
  194. package/dist/structures/sample-space.js.map +1 -0
  195. package/dist/systems/axes2d.d.ts +197 -0
  196. package/dist/systems/axes2d.d.ts.map +1 -0
  197. package/dist/systems/axes2d.js +157 -0
  198. package/dist/systems/axes2d.js.map +1 -0
  199. package/dist/systems/number-line.d.ts +101 -0
  200. package/dist/systems/number-line.d.ts.map +1 -0
  201. package/dist/systems/number-line.js +91 -0
  202. package/dist/systems/number-line.js.map +1 -0
  203. package/dist/systems/number-plane.d.ts +168 -0
  204. package/dist/systems/number-plane.d.ts.map +1 -0
  205. package/dist/systems/number-plane.js +186 -0
  206. package/dist/systems/number-plane.js.map +1 -0
  207. package/dist/systems/polar-plane.d.ts +98 -0
  208. package/dist/systems/polar-plane.d.ts.map +1 -0
  209. package/dist/systems/polar-plane.js +139 -0
  210. package/dist/systems/polar-plane.js.map +1 -0
  211. package/dist/tex/geometry.d.ts +85 -0
  212. package/dist/tex/geometry.d.ts.map +1 -0
  213. package/dist/tex/geometry.js +632 -0
  214. package/dist/tex/geometry.js.map +1 -0
  215. package/dist/tex/index.d.ts +11 -0
  216. package/dist/tex/index.d.ts.map +1 -0
  217. package/dist/tex/index.js +10 -0
  218. package/dist/tex/index.js.map +1 -0
  219. package/dist/tex/mathjax.d.ts +33 -0
  220. package/dist/tex/mathjax.d.ts.map +1 -0
  221. package/dist/tex/mathjax.js +74 -0
  222. package/dist/tex/mathjax.js.map +1 -0
  223. package/dist/tex/matrix.d.ts +101 -0
  224. package/dist/tex/matrix.d.ts.map +1 -0
  225. package/dist/tex/matrix.js +56 -0
  226. package/dist/tex/matrix.js.map +1 -0
  227. package/dist/tex/node.d.ts +98 -0
  228. package/dist/tex/node.d.ts.map +1 -0
  229. package/dist/tex/node.js +25 -0
  230. package/dist/tex/node.js.map +1 -0
  231. package/dist/tex/tween.d.ts +50 -0
  232. package/dist/tex/tween.d.ts.map +1 -0
  233. package/dist/tex/tween.js +253 -0
  234. package/dist/tex/tween.js.map +1 -0
  235. package/dist/tex/typeset.d.ts +133 -0
  236. package/dist/tex/typeset.d.ts.map +1 -0
  237. package/dist/tex/typeset.js +403 -0
  238. package/dist/tex/typeset.js.map +1 -0
  239. package/dist/three/axes3d.d.ts +247 -0
  240. package/dist/three/axes3d.d.ts.map +1 -0
  241. package/dist/three/axes3d.js +187 -0
  242. package/dist/three/axes3d.js.map +1 -0
  243. package/dist/three/curve-plot3d.d.ts +126 -0
  244. package/dist/three/curve-plot3d.d.ts.map +1 -0
  245. package/dist/three/curve-plot3d.js +109 -0
  246. package/dist/three/curve-plot3d.js.map +1 -0
  247. package/dist/three/entries.d.ts +17 -0
  248. package/dist/three/entries.d.ts.map +1 -0
  249. package/dist/three/entries.js +15 -0
  250. package/dist/three/entries.js.map +1 -0
  251. package/dist/three/label3d.d.ts +11 -0
  252. package/dist/three/label3d.d.ts.map +1 -0
  253. package/dist/three/label3d.js +42 -0
  254. package/dist/three/label3d.js.map +1 -0
  255. package/dist/three/plot-point3d.d.ts +99 -0
  256. package/dist/three/plot-point3d.d.ts.map +1 -0
  257. package/dist/three/plot-point3d.js +34 -0
  258. package/dist/three/plot-point3d.js.map +1 -0
  259. package/dist/three/space.d.ts +43 -0
  260. package/dist/three/space.d.ts.map +1 -0
  261. package/dist/three/space.js +58 -0
  262. package/dist/three/space.js.map +1 -0
  263. package/dist/three/surface-plot3d.d.ts +207 -0
  264. package/dist/three/surface-plot3d.d.ts.map +1 -0
  265. package/dist/three/surface-plot3d.js +261 -0
  266. package/dist/three/surface-plot3d.js.map +1 -0
  267. package/dist/three/vector-arrow3d.d.ts +96 -0
  268. package/dist/three/vector-arrow3d.d.ts.map +1 -0
  269. package/dist/three/vector-arrow3d.js +53 -0
  270. package/dist/three/vector-arrow3d.js.map +1 -0
  271. package/package.json +80 -3
  272. package/registry.json +251 -0
  273. package/src/annotate/angle-mark.ts +137 -0
  274. package/src/annotate/curly-brace.ts +148 -0
  275. package/src/annotate/emphasis-mark.ts +118 -0
  276. package/src/engine.ts +86 -0
  277. package/src/index.ts +29 -0
  278. package/src/kit/brace.ts +37 -0
  279. package/src/kit/cache.ts +61 -0
  280. package/src/kit/component.ts +57 -0
  281. package/src/kit/contour.ts +94 -0
  282. package/src/kit/coords.ts +278 -0
  283. package/src/kit/curve.ts +47 -0
  284. package/src/kit/equation.ts +181 -0
  285. package/src/kit/equation3d.ts +137 -0
  286. package/src/kit/expression.ts +159 -0
  287. package/src/kit/field-mark.ts +171 -0
  288. package/src/kit/field.ts +50 -0
  289. package/src/kit/follow.ts +229 -0
  290. package/src/kit/furniture.ts +113 -0
  291. package/src/kit/geometry.ts +49 -0
  292. package/src/kit/graph.ts +116 -0
  293. package/src/kit/mark.ts +152 -0
  294. package/src/kit/part-fills.ts +61 -0
  295. package/src/kit/place.ts +77 -0
  296. package/src/kit/sampler.ts +281 -0
  297. package/src/kit/scale.ts +39 -0
  298. package/src/kit/source.ts +57 -0
  299. package/src/kit/system.ts +105 -0
  300. package/src/kit/ticks.ts +85 -0
  301. package/src/kit/withdrawn.ts +8 -0
  302. package/src/marks/curve-area.ts +89 -0
  303. package/src/marks/drop-lines.ts +71 -0
  304. package/src/marks/plot-point.ts +102 -0
  305. package/src/marks/riemann-sum.ts +99 -0
  306. package/src/marks/tangent-line.ts +119 -0
  307. package/src/marks/vector-arrow.ts +98 -0
  308. package/src/nodes.ts +99 -0
  309. package/src/plots/function-plot.ts +220 -0
  310. package/src/plots/points-plot.ts +103 -0
  311. package/src/plots/stream-lines.ts +160 -0
  312. package/src/plots/traced-path.ts +70 -0
  313. package/src/plots/vector-field.ts +107 -0
  314. package/src/structures/graph-layout.ts +145 -0
  315. package/src/structures/network-graph.ts +291 -0
  316. package/src/structures/sample-space.ts +210 -0
  317. package/src/systems/axes2d.ts +226 -0
  318. package/src/systems/number-line.ts +130 -0
  319. package/src/systems/number-plane.ts +232 -0
  320. package/src/systems/polar-plane.ts +177 -0
  321. package/src/tex/geometry.ts +703 -0
  322. package/src/tex/index.ts +15 -0
  323. package/src/tex/mathjax.ts +82 -0
  324. package/src/tex/matrix.ts +97 -0
  325. package/src/tex/node.ts +74 -0
  326. package/src/tex/tween.ts +308 -0
  327. package/src/tex/typeset.ts +461 -0
  328. package/src/three/axes3d.ts +267 -0
  329. package/src/three/curve-plot3d.ts +146 -0
  330. package/src/three/entries.ts +42 -0
  331. package/src/three/label3d.ts +52 -0
  332. package/src/three/plot-point3d.ts +63 -0
  333. package/src/three/space.ts +92 -0
  334. package/src/three/surface-plot3d.ts +318 -0
  335. package/src/three/vector-arrow3d.ts +88 -0
@@ -0,0 +1,71 @@
1
+ import { component2d, Graphics2D, Types, } from "@motionscript/sdk";
2
+ import { listed, omit, PAINT, PAINT_COMMANDS, painted } from "../kit/component.js";
3
+ import { curveValue } from "../kit/curve.js";
4
+ import { drawLabels, loadFormulas } from "../kit/furniture.js";
5
+ import { curveFor, PLANE_ENTRY, PLOT_REF } from "../kit/graph.js";
6
+ import { strokeShape } from "../kit/mark.js";
7
+ import { anchored } from "../kit/place.js";
8
+ const state = {
9
+ // A dot has no outline worth trimming.
10
+ ...omit(PAINT, "start", "end"),
11
+ /** The plot this point rides, by id; empty for a point that sits at its own `x`/`y`. */
12
+ on: PLOT_REF,
13
+ radius: Types.number(7, { min: 0, unit: "px" }),
14
+ label: Types.text("", { animatable: false }),
15
+ labelSide: listed(["above", "below", "left", "right"], "above", { animatable: false }),
16
+ labelSize: Types.number(18, { min: 1, unit: "px" }),
17
+ labelColor: Types.color("#e5e7eb"),
18
+ fontFamily: Types.text("", { animatable: false }),
19
+ graph: PLANE_ENTRY,
20
+ /** The graph height the point is at: the curve's when it rides one. A formula reads it back as `[key.value]`. */
21
+ value: Types.number(0, { private: true }),
22
+ };
23
+ /**
24
+ * A dot at graph coordinates, with an optional label. Named a plot in `on`, it
25
+ * rides that curve: its `x` is where along it, and its height is the curve's.
26
+ */
27
+ export const PlotPoint = anchored(component2d({
28
+ key: "plotPoint",
29
+ state,
30
+ defaults: { fill: "#e5e7eb", width: "hug", height: "hug", value: (s) => heightOf(s.graph, s.on, s.x, s.y) },
31
+ load: (loader, s) => {
32
+ if (s.label !== "" && s.fontFamily !== "")
33
+ loader.font(s.fontFamily);
34
+ loadFormulas(loader, [s.label]);
35
+ },
36
+ commands: omit(PAINT_COMMANDS, "progressTo", "flash"),
37
+ measure: (_measurer, s) => ({ width: s.radius * 2, height: s.radius * 2 }),
38
+ render: (ctx, s) => {
39
+ const size = s.radius * 2;
40
+ const shape = size > 0 ? () => new Graphics2D().ellipse({ x: 0, y: 0, width: size, height: size }) : null;
41
+ painted(ctx, () => {
42
+ if (shape)
43
+ ctx.draw(shape().shadow(s.shadow).fill(s.fill));
44
+ if (s.label === "")
45
+ return;
46
+ const gap = s.radius + s.labelSize * 0.45;
47
+ const side = s.labelSide;
48
+ const horizontal = side === "left" || side === "right";
49
+ const label = {
50
+ text: s.label,
51
+ align: side === "left" ? "right" : side === "right" ? "left" : "center",
52
+ at: {
53
+ x: horizontal ? (side === "left" ? -1 : 1) * gap : 0,
54
+ y: horizontal ? 0 : (side === "below" ? -1 : 1) * (gap + s.labelSize / 2),
55
+ },
56
+ };
57
+ ctx.draw(drawLabels([label], { fontSize: s.labelSize, fontFamily: s.fontFamily, color: s.labelColor }));
58
+ }, () => {
59
+ if (shape)
60
+ strokeShape(ctx, shape, s);
61
+ });
62
+ },
63
+ }), (s, plane) => (x, y) => ({ x, y: heightOf(plane, s.on, x, y) }));
64
+ /** The height a point at `x`/`y` sits at: the curve's, when it rides one that has a value there. */
65
+ function heightOf(plane, on, x, y) {
66
+ const curve = curveFor(plane, on);
67
+ const height = curve ? curveValue(curve, x) : NaN;
68
+ // Off the end of its curve a point stays where its own `y` puts it rather than vanishing.
69
+ return Number.isFinite(height) ? height : y;
70
+ }
71
+ //# sourceMappingURL=plot-point.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plot-point.js","sourceRoot":"","sources":["../../src/marks/plot-point.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,UAAU,EACV,KAAK,GAcR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,YAAY,EAAc,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,QA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,CAAC,EAAE,CAAC,CAA2B,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAI/F,oGAAoG;AACpG,SAAS,QAAQ,CAAC,KAAwB,EAAE,EAAW,EAAE,CAAS,EAAE,CAAS;IACzE,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IAClD,0FAA0F;IAC1F,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import {\n component2d,\n Graphics2D,\n Types,\n type Color,\n type NodeOf,\n type NormalizedColor,\n type PaintProps,\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 type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\";\nimport { listed, omit, PAINT, PAINT_COMMANDS, painted } from \"../kit/component\";\nimport { curveValue } from \"../kit/curve\";\nimport { drawLabels, loadFormulas, type Label } from \"../kit/furniture\";\nimport { curveFor, PLANE_ENTRY, PLOT_REF, type GraphPlane } from \"../kit/graph\";\nimport { strokeShape } from \"../kit/mark\";\nimport { anchored } from \"../kit/place\";\n\nexport interface PlotPointProps extends PaintProps {\n on?: string;\n radius?: number;\n label?: string;\n labelSide?: \"above\" | \"below\" | \"left\" | \"right\";\n labelSize?: number;\n labelColor?: Color;\n fontFamily?: string;\n}\n\nconst state = {\n // A dot has no outline worth trimming.\n ...omit(PAINT, \"start\", \"end\"),\n /** The plot this point rides, by id; empty for a point that sits at its own `x`/`y`. */\n on: PLOT_REF,\n radius: Types.number(7, { min: 0, unit: \"px\" }),\n label: Types.text(\"\", { animatable: false }),\n labelSide: listed([\"above\", \"below\", \"left\", \"right\"], \"above\", { animatable: false }),\n labelSize: Types.number(18, { min: 1, unit: \"px\" }),\n labelColor: Types.color(\"#e5e7eb\"),\n fontFamily: Types.text(\"\", { animatable: false }),\n graph: PLANE_ENTRY,\n /** The graph height the point is at: the curve's when it rides one. A formula reads it back as `[key.value]`. */\n value: Types.number(0, { private: true }),\n};\n\n/**\n * A dot at graph coordinates, with an optional label. Named a plot in `on`, it\n * rides that curve: its `x` is where along it, and its height is the curve's.\n */\nexport const PlotPoint = anchored(component2d({\n key: \"plotPoint\",\n state,\n defaults: { fill: \"#e5e7eb\", width: \"hug\", height: \"hug\", value: (s) => heightOf(s.graph, s.on, s.x, s.y) },\n load: (loader, s) => {\n if (s.label !== \"\" && s.fontFamily !== \"\") loader.font(s.fontFamily);\n loadFormulas(loader, [s.label]);\n },\n commands: omit(PAINT_COMMANDS, \"progressTo\", \"flash\"),\n measure: (_measurer, s) => ({ width: s.radius * 2, height: s.radius * 2 }),\n render: (ctx, s) => {\n const size = s.radius * 2;\n const shape = size > 0 ? () => new Graphics2D().ellipse({ x: 0, y: 0, width: size, height: size }) : null;\n painted(\n ctx,\n () => {\n if (shape) ctx.draw(shape().shadow(s.shadow).fill(s.fill));\n if (s.label === \"\") return;\n const gap = s.radius + s.labelSize * 0.45;\n const side = s.labelSide;\n const horizontal = side === \"left\" || side === \"right\";\n const label: Label = {\n text: s.label,\n align: side === \"left\" ? \"right\" : side === \"right\" ? \"left\" : \"center\",\n at: {\n x: horizontal ? (side === \"left\" ? -1 : 1) * gap : 0,\n y: horizontal ? 0 : (side === \"below\" ? -1 : 1) * (gap + s.labelSize / 2),\n },\n };\n ctx.draw(drawLabels([label], { fontSize: s.labelSize, fontFamily: s.fontFamily, color: s.labelColor as NormalizedColor }));\n },\n () => {\n if (shape) strokeShape(ctx, shape, s);\n },\n );\n },\n}), (s: { readonly on: unknown }, plane) => (x, y) => ({ x, y: heightOf(plane, s.on, x, y) }));\n\nexport type PlotPoint = NodeOf<typeof PlotPoint>;\n\n/** The height a point at `x`/`y` sits at: the curve's, when it rides one that has a value there. */\nfunction heightOf(plane: GraphPlane | null, on: unknown, x: number, y: number): number {\n const curve = curveFor(plane, on);\n const height = curve ? curveValue(curve, x) : NaN;\n // Off the end of its curve a point stays where its own `y` puts it rather than vanishing.\n return Number.isFinite(height) ? height : y;\n}\n"]}
@@ -0,0 +1,58 @@
1
+ import { type NodeOf, type NodeView, type PaintProps, 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 { Interval } from "../kit/coords.js";
3
+ export type RiemannSample = "left" | "right" | "center";
4
+ export interface RiemannSumProps extends PaintProps {
5
+ on?: string;
6
+ domain?: Interval;
7
+ dx?: number;
8
+ sample?: RiemannSample;
9
+ }
10
+ /** Rectangles under a plot, each `dx` wide and as tall as the curve where it is sampled. */
11
+ export declare const RiemannSum: import("@motionscript/sdk").Component<"riemannSum", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
12
+ on: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
13
+ domain: import("@motionscript/sdk").Type<Interval, Interval, false>;
14
+ /** Each rectangle's width, in graph units. */
15
+ dx: import("@motionscript/sdk").Type<number, number, false>;
16
+ /** Where in its width a rectangle reads the curve's height. */
17
+ sample: import("@motionscript/sdk").Type<"center" | "right" | "left", "center" | "right" | "left", false>;
18
+ graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
19
+ fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
20
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
21
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
22
+ }>, {
23
+ readonly refineTo: readonly ["dx"];
24
+ readonly domainTo: readonly ["domain"];
25
+ readonly fillTo: readonly ["fill"];
26
+ readonly strokeTo: readonly ["stroke"];
27
+ readonly shadowTo: readonly ["shadow"];
28
+ }, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
29
+ on: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
30
+ domain: import("@motionscript/sdk").Type<Interval, Interval, false>;
31
+ /** Each rectangle's width, in graph units. */
32
+ dx: import("@motionscript/sdk").Type<number, number, false>;
33
+ /** Where in its width a rectangle reads the curve's height. */
34
+ sample: import("@motionscript/sdk").Type<"center" | "right" | "left", "center" | "right" | "left", false>;
35
+ graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
36
+ fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
37
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
38
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
39
+ }>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
40
+ on: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
41
+ domain: import("@motionscript/sdk").Type<Interval, Interval, false>;
42
+ /** Each rectangle's width, in graph units. */
43
+ dx: import("@motionscript/sdk").Type<number, number, false>;
44
+ /** Where in its width a rectangle reads the curve's height. */
45
+ sample: import("@motionscript/sdk").Type<"center" | "right" | "left", "center" | "right" | "left", false>;
46
+ graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
47
+ fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
48
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
49
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
50
+ }>, {
51
+ readonly refineTo: readonly ["dx"];
52
+ readonly domainTo: readonly ["domain"];
53
+ readonly fillTo: readonly ["fill"];
54
+ readonly strokeTo: readonly ["stroke"];
55
+ readonly shadowTo: readonly ["shadow"];
56
+ }, _Node2D<_Node2DProps>>>>;
57
+ export type RiemannSum = NodeOf<typeof RiemannSum>;
58
+ //# sourceMappingURL=riemann-sum.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"riemann-sum.d.ts","sourceRoot":"","sources":["../../src/marks/riemann-sum.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,KAAK,MAAM,EACX,KAAK,QAAQ,EACb,KAAK,UAAU,EAGf,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,EACtC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACzC,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAO9C,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAExD,MAAM,WAAW,eAAgB,SAAQ,UAAU;IAC/C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,QAAQ,CAAC;IAClB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,aAAa,CAAC;CAC1B;AAwBD,4FAA4F;AAC5F,eAAO,MAAM,UAAU;;;IAfnB,8CAA8C;;IAE9C,+DAA+D;;;;;;;;;;;;;;;IAF/D,8CAA8C;;IAE9C,+DAA+D;;;;;;;;;IAF/D,8CAA8C;;IAE9C,+DAA+D;;;;;;;;;;;;2BA+BtD,CAAC;AAEd,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC"}
@@ -0,0 +1,63 @@
1
+ import { component2d, Types, } from "@motionscript/sdk";
2
+ import { listed, omit, PAINT, PAINT_COMMANDS } from "../kit/component.js";
3
+ import { curveValue } from "../kit/curve.js";
4
+ import { lerpInterval, PLOT_COLOR, readInterval } from "../kit/furniture.js";
5
+ import { clamp } from "../kit/geometry.js";
6
+ import { curveFor, PLANE_ENTRY, PLOT_REF } from "../kit/graph.js";
7
+ import { drawMark, inkSize, reading, traced } from "../kit/mark.js";
8
+ /** More rectangles than this is a filled area with extra steps. */
9
+ const MAX_RECTANGLES = 2000;
10
+ const state = {
11
+ // Its rectangles are revealed by `dx`, not by trimming their outlines.
12
+ ...omit(PAINT, "start", "end"),
13
+ on: PLOT_REF,
14
+ domain: Types.custom([0, 1], { resolve: readInterval, lerp: lerpInterval }),
15
+ /** Each rectangle's width, in graph units. */
16
+ dx: Types.number(0.25, { min: 0.001 }),
17
+ /** Where in its width a rectangle reads the curve's height. */
18
+ sample: listed(["left", "right", "center"], "left", { animatable: false }),
19
+ graph: PLANE_ENTRY,
20
+ };
21
+ /** Rectangles under a plot, each `dx` wide and as tall as the curve where it is sampled. */
22
+ export const RiemannSum = traced(component2d({
23
+ key: "riemannSum",
24
+ state,
25
+ defaults: {
26
+ fill: { type: "solid", color: PLOT_COLOR, opacity: 0.35 },
27
+ stroke: { weight: 1.5, fill: PLOT_COLOR, align: "center", join: "round" },
28
+ width: "hug",
29
+ height: "hug",
30
+ },
31
+ commands: {
32
+ ...omit(PAINT_COMMANDS, "progressTo", "flash"),
33
+ /** Animate the rectangles' width: narrower is the sum closing in on the area. */
34
+ refineTo: { args: ["dx"] },
35
+ /** Animate the span of x the rectangles cover. */
36
+ domainTo: { args: ["domain"] },
37
+ },
38
+ measure: (_measurer, s) => inkSize(traceSum(s, reading(s))),
39
+ render: (ctx, s) => drawMark(ctx, s, traceSum(s, reading(s)), { closed: true }),
40
+ }), traceSum);
41
+ function traceSum(s, { map, plane }) {
42
+ const plot = curveFor(plane, s.on);
43
+ const [a, b] = s.domain;
44
+ const dx = s.dx;
45
+ if (!plot || !(b > a) || !(dx > 0))
46
+ return [];
47
+ const [yMin, yMax] = map.yRange;
48
+ const base = clamp(0, yMin, yMax);
49
+ const at = s.sample === "left" ? 0 : s.sample === "right" ? 1 : 0.5;
50
+ const count = Math.min(MAX_RECTANGLES, Math.ceil((b - a) / dx - 1e-9));
51
+ const runs = [];
52
+ for (let i = 0; i < count; i++) {
53
+ const left = a + i * dx;
54
+ const right = Math.min(b, left + dx);
55
+ const value = curveValue(plot, left + (right - left) * at);
56
+ if (!Number.isFinite(value))
57
+ continue;
58
+ const height = clamp(value, yMin, yMax);
59
+ runs.push([map.toPoint(left, base), map.toPoint(left, height), map.toPoint(right, height), map.toPoint(right, base)]);
60
+ }
61
+ return runs;
62
+ }
63
+ //# sourceMappingURL=riemann-sum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"riemann-sum.js","sourceRoot":"","sources":["../../src/marks/riemann-sum.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,KAAK,GAcR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,KAAK,EAAE,MAAM,i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AAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IACpE,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;IACvE,MAAM,IAAI,GAAgB,EAAE,CAAC;IAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;QACxB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;QACrC,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QAC3D,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;YAAE,SAAS;QACtC,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAC1H,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["import {\n component2d,\n Types,\n type NodeOf,\n type NodeView,\n type PaintProps,\n type Vector2,\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 type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\";\nimport { listed, omit, PAINT, PAINT_COMMANDS } from \"../kit/component\";\nimport type { Interval } from \"../kit/coords\";\nimport { curveValue } from \"../kit/curve\";\nimport { lerpInterval, PLOT_COLOR, readInterval } from \"../kit/furniture\";\nimport { clamp } from \"../kit/geometry\";\nimport { curveFor, PLANE_ENTRY, PLOT_REF } from \"../kit/graph\";\nimport { drawMark, inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\n\nexport type RiemannSample = \"left\" | \"right\" | \"center\";\n\nexport interface RiemannSumProps extends PaintProps {\n on?: string;\n domain?: Interval;\n dx?: number;\n sample?: RiemannSample;\n}\n\n/** More rectangles than this is a filled area with extra steps. */\nconst MAX_RECTANGLES = 2000;\n\nconst state = {\n // Its rectangles are revealed by `dx`, not by trimming their outlines.\n ...omit(PAINT, \"start\", \"end\"),\n on: PLOT_REF,\n domain: Types.custom<Interval>([0, 1], { resolve: readInterval, lerp: lerpInterval }),\n /** Each rectangle's width, in graph units. */\n dx: Types.number(0.25, { min: 0.001 }),\n /** Where in its width a rectangle reads the curve's height. */\n sample: listed([\"left\", \"right\", \"center\"], \"left\", { animatable: false }),\n graph: PLANE_ENTRY,\n};\n\ninterface SumValues {\n readonly on: NodeView | null;\n readonly domain: Interval;\n readonly dx: number;\n readonly sample: RiemannSample;\n}\n\n/** Rectangles under a plot, each `dx` wide and as tall as the curve where it is sampled. */\nexport const RiemannSum = traced(component2d({\n key: \"riemannSum\",\n state,\n defaults: {\n fill: { type: \"solid\", color: PLOT_COLOR, opacity: 0.35 },\n stroke: { weight: 1.5, fill: PLOT_COLOR, align: \"center\", join: \"round\" },\n width: \"hug\",\n height: \"hug\",\n },\n commands: {\n ...omit(PAINT_COMMANDS, \"progressTo\", \"flash\"),\n /** Animate the rectangles' width: narrower is the sum closing in on the area. */\n refineTo: { args: [\"dx\"] },\n /** Animate the span of x the rectangles cover. */\n domainTo: { args: [\"domain\"] },\n },\n measure: (_measurer, s) => inkSize(traceSum(s, reading(s))),\n render: (ctx, s) => drawMark(ctx, s, traceSum(s, reading(s)), { closed: true }),\n}), traceSum);\n\nexport type RiemannSum = NodeOf<typeof RiemannSum>;\n\nfunction traceSum(s: SumValues, { map, plane }: MarkReading): Vector2[][] {\n const plot = curveFor(plane, s.on);\n const [a, b] = s.domain;\n const dx = s.dx;\n if (!plot || !(b > a) || !(dx > 0)) return [];\n const [yMin, yMax] = map.yRange;\n const base = clamp(0, yMin, yMax);\n const at = s.sample === \"left\" ? 0 : s.sample === \"right\" ? 1 : 0.5;\n const count = Math.min(MAX_RECTANGLES, Math.ceil((b - a) / dx - 1e-9));\n const runs: Vector2[][] = [];\n for (let i = 0; i < count; i++) {\n const left = a + i * dx;\n const right = Math.min(b, left + dx);\n const value = curveValue(plot, left + (right - left) * at);\n if (!Number.isFinite(value)) continue;\n const height = clamp(value, yMin, yMax);\n runs.push([map.toPoint(left, base), map.toPoint(left, height), map.toPoint(right, height), map.toPoint(right, base)]);\n }\n return runs;\n}\n"]}
@@ -0,0 +1,71 @@
1
+ import { type NodeOf, type NodeView, type PaintProps, 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 CurveValues } from "../kit/curve.js";
3
+ export interface TangentLineProps extends PaintProps {
4
+ on?: string;
5
+ length?: number;
6
+ dx?: number;
7
+ legs?: boolean;
8
+ }
9
+ /**
10
+ * The tangent to a plot at this node's `x`, a fixed length on screen. With a
11
+ * `dx` it is the secant through `x` and `x + dx` instead, and `legs` draws that
12
+ * secant's run and rise.
13
+ */
14
+ export declare const TangentLine: import("@motionscript/sdk").Component<"tangentLine", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
15
+ on: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
16
+ length: import("@motionscript/sdk").Type<number, number, false>;
17
+ /** The second point's distance along x; zero is the tangent itself. */
18
+ dx: import("@motionscript/sdk").Type<number, number, false>;
19
+ legs: import("@motionscript/sdk").Type<boolean, boolean, false>;
20
+ graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
21
+ /** The slope drawn, in graph units: the curve's at `x`, or the secant's when there is a `dx`. A formula reads it back as `[key.slope]`. */
22
+ slope: import("@motionscript/sdk").Type<number, number, true>;
23
+ start: import("@motionscript/sdk").Type<number, number, false>;
24
+ end: import("@motionscript/sdk").Type<number, number, false>;
25
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
26
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
27
+ }>, {
28
+ strokeTo: readonly ["stroke"];
29
+ shadowTo: readonly ["shadow"];
30
+ progressTo: readonly ["start", "end"];
31
+ flash: {
32
+ readonly portion: import("@motionscript/sdk").Type<number, number, false>;
33
+ };
34
+ }, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
35
+ on: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
36
+ length: import("@motionscript/sdk").Type<number, number, false>;
37
+ /** The second point's distance along x; zero is the tangent itself. */
38
+ dx: import("@motionscript/sdk").Type<number, number, false>;
39
+ legs: import("@motionscript/sdk").Type<boolean, boolean, false>;
40
+ graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
41
+ /** The slope drawn, in graph units: the curve's at `x`, or the secant's when there is a `dx`. A formula reads it back as `[key.slope]`. */
42
+ slope: import("@motionscript/sdk").Type<number, number, true>;
43
+ start: import("@motionscript/sdk").Type<number, number, false>;
44
+ end: import("@motionscript/sdk").Type<number, number, false>;
45
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
46
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
47
+ }>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
48
+ on: import("@motionscript/sdk").Type<string, NodeView<import("@motionscript/sdk").Element<string, unknown, unknown>> | null, false>;
49
+ length: import("@motionscript/sdk").Type<number, number, false>;
50
+ /** The second point's distance along x; zero is the tangent itself. */
51
+ dx: import("@motionscript/sdk").Type<number, number, false>;
52
+ legs: import("@motionscript/sdk").Type<boolean, boolean, false>;
53
+ graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
54
+ /** The slope drawn, in graph units: the curve's at `x`, or the secant's when there is a `dx`. A formula reads it back as `[key.slope]`. */
55
+ slope: import("@motionscript/sdk").Type<number, number, true>;
56
+ start: import("@motionscript/sdk").Type<number, number, false>;
57
+ end: import("@motionscript/sdk").Type<number, number, false>;
58
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
59
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
60
+ }>, {
61
+ strokeTo: readonly ["stroke"];
62
+ shadowTo: readonly ["shadow"];
63
+ progressTo: readonly ["start", "end"];
64
+ flash: {
65
+ readonly portion: import("@motionscript/sdk").Type<number, number, false>;
66
+ };
67
+ }, _Node2D<_Node2DProps>>>>;
68
+ export type TangentLine = NodeOf<typeof TangentLine>;
69
+ /** The slope a tangent at `x` draws on `curve`, in graph units: the curve's at `x`, or the secant's to `x + dx`. */
70
+ export declare function tangentSlope(curve: CurveValues, x: number, dx?: number): number;
71
+ //# sourceMappingURL=tangent-line.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tangent-line.d.ts","sourceRoot":"","sources":["../../src/marks/tangent-line.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,KAAK,MAAM,EACX,KAAK,QAAQ,EACb,KAAK,UAAU,EAGf,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,EAAc,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAI5D,MAAM,WAAW,gBAAiB,SAAQ,UAAU;IAChD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,OAAO,CAAC;CAClB;AAyBD;;;;GAIG;AACH,eAAO,MAAM,WAAW;;;IArBpB,uEAAuE;;;;IAIvE,2IAA2I;;;;;;;;;;;;;;;;IAJ3I,uEAAuE;;;;IAIvE,2IAA2I;;;;;;;;;IAJ3I,uEAAuE;;;;IAIvE,2IAA2I;;;;;;;;;;;;;2BAgC9H,CAAC;AAElB,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC;AAErD,oHAAoH;AACpH,wBAAgB,YAAY,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,SAAI,GAAG,MAAM,CAI1E"}
@@ -0,0 +1,89 @@
1
+ import { component2d, Types, } from "@motionscript/sdk";
2
+ import { omit, PAINT, PAINT_COMMANDS } from "../kit/component.js";
3
+ import { curveValue } from "../kit/curve.js";
4
+ import { curveFor, PLANE_ENTRY, PLOT_REF } from "../kit/graph.js";
5
+ import { drawMark, inkSize, reading, traced } from "../kit/mark.js";
6
+ /** The step a slope is measured over, as a share of the system's width. */
7
+ const SLOPE_STEP = 1e-4;
8
+ const state = {
9
+ ...omit(PAINT, "fill"),
10
+ on: PLOT_REF,
11
+ length: Types.number(260, { min: 0, unit: "px" }),
12
+ /** The second point's distance along x; zero is the tangent itself. */
13
+ dx: Types.number(0, { min: 0 }),
14
+ legs: Types.boolean(false, { animatable: false }),
15
+ graph: PLANE_ENTRY,
16
+ /** The slope drawn, in graph units: the curve's at `x`, or the secant's when there is a `dx`. A formula reads it back as `[key.slope]`. */
17
+ slope: Types.number(NaN, { private: true }),
18
+ };
19
+ /**
20
+ * The tangent to a plot at this node's `x`, a fixed length on screen. With a
21
+ * `dx` it is the secant through `x` and `x + dx` instead, and `legs` draws that
22
+ * secant's run and rise.
23
+ */
24
+ export const TangentLine = traced(component2d({
25
+ key: "tangentLine",
26
+ state,
27
+ defaults: {
28
+ stroke: { weight: 3, fill: "#f59e0b", align: "center", cap: "round", join: "round" },
29
+ width: "hug",
30
+ height: "hug",
31
+ slope: (s) => {
32
+ const plot = curveFor(s.graph, s.on);
33
+ return plot ? tangentSlope(plot, s.x, s.dx) : NaN;
34
+ },
35
+ },
36
+ commands: omit(PAINT_COMMANDS, "fillTo"),
37
+ measure: (_measurer, s) => inkSize(traceTangent(s, reading(s))),
38
+ render: (ctx, s) => drawMark(ctx, s, traceTangent(s, reading(s))),
39
+ }), traceTangent);
40
+ /** The slope a tangent at `x` draws on `curve`, in graph units: the curve's at `x`, or the secant's to `x + dx`. */
41
+ export function tangentSlope(curve, x, dx = 0) {
42
+ if (dx > 0)
43
+ return (curveValue(curve, x + dx) - curveValue(curve, x)) / dx;
44
+ const h = 1e-6 * Math.max(1, Math.abs(x));
45
+ return (curveValue(curve, x + h) - curveValue(curve, x - h)) / (2 * h);
46
+ }
47
+ function traceTangent(s, { map, plane }) {
48
+ const plot = curveFor(plane, s.on);
49
+ if (!plot)
50
+ return [];
51
+ const x = s.x;
52
+ const y = curveValue(plot, x);
53
+ if (!Number.isFinite(y))
54
+ return [];
55
+ const half = s.length / 2;
56
+ if (s.dx > 0) {
57
+ const y2 = curveValue(plot, x + s.dx);
58
+ if (!Number.isFinite(y2))
59
+ return [];
60
+ const a = map.toPoint(x, y);
61
+ const b = map.toPoint(x + s.dx, y2);
62
+ const span = Math.hypot(b.x - a.x, b.y - a.y);
63
+ if (span === 0)
64
+ return [];
65
+ const reach = Math.max(half, span / 2 + 16);
66
+ const ux = (b.x - a.x) / span;
67
+ const uy = (b.y - a.y) / span;
68
+ const mx = (a.x + b.x) / 2;
69
+ const my = (a.y + b.y) / 2;
70
+ const secant = [{ x: mx - ux * reach, y: my - uy * reach }, { x: mx + ux * reach, y: my + uy * reach }];
71
+ return s.legs ? [secant, [a, map.toPoint(x + s.dx, y), b]] : [secant];
72
+ }
73
+ const [xMin, xMax] = map.xRange;
74
+ const h = Number.isFinite(xMax - xMin) ? (xMax - xMin) * SLOPE_STEP : 1e-4;
75
+ const before = curveValue(plot, x - h);
76
+ const after = curveValue(plot, x + h);
77
+ if (!Number.isFinite(before) || !Number.isFinite(after))
78
+ return [];
79
+ const p = map.toPoint(x, y);
80
+ const a = map.toPoint(x - h, before);
81
+ const b = map.toPoint(x + h, after);
82
+ const span = Math.hypot(b.x - a.x, b.y - a.y);
83
+ if (span === 0)
84
+ return [];
85
+ const ux = (b.x - a.x) / span;
86
+ const uy = (b.y - a.y) / span;
87
+ return [[{ x: p.x - ux * half, y: p.y - uy * half }, { x: p.x + ux * half, y: p.y + uy * half }]];
88
+ }
89
+ //# sourceMappingURL=tangent-line.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tangent-line.js","sourceRoot":"","sources":["../../src/marks/tangent-line.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,KAAK,GAYR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAoB,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,OAAO,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CAAC;IACrC,MAAM,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IACpC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9C,IAAI,IAAI,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAC1B,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAC9B,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAC9B,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC;AACtG,CAAC","sourcesContent":["import {\n component2d,\n Types,\n type NodeOf,\n type NodeView,\n type PaintProps,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\";\nimport { omit, PAINT, PAINT_COMMANDS } from \"../kit/component\";\nimport { curveValue, type CurveValues } from \"../kit/curve\";\nimport { curveFor, PLANE_ENTRY, PLOT_REF } from \"../kit/graph\";\nimport { drawMark, inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\n\nexport interface TangentLineProps extends PaintProps {\n on?: string;\n length?: number;\n dx?: number;\n legs?: boolean;\n}\n\n/** The step a slope is measured over, as a share of the system's width. */\nconst SLOPE_STEP = 1e-4;\n\nconst state = {\n ...omit(PAINT, \"fill\"),\n on: PLOT_REF,\n length: Types.number(260, { min: 0, unit: \"px\" }),\n /** The second point's distance along x; zero is the tangent itself. */\n dx: Types.number(0, { min: 0 }),\n legs: Types.boolean(false, { animatable: false }),\n graph: PLANE_ENTRY,\n /** The slope drawn, in graph units: the curve's at `x`, or the secant's when there is a `dx`. A formula reads it back as `[key.slope]`. */\n slope: Types.number(NaN, { private: true }),\n};\n\ninterface TangentValues {\n readonly x: number;\n readonly on: NodeView | null;\n readonly length: number;\n readonly dx: number;\n readonly legs: boolean;\n}\n\n/**\n * The tangent to a plot at this node's `x`, a fixed length on screen. With a\n * `dx` it is the secant through `x` and `x + dx` instead, and `legs` draws that\n * secant's run and rise.\n */\nexport const TangentLine = traced(component2d({\n key: \"tangentLine\",\n state,\n defaults: {\n stroke: { weight: 3, fill: \"#f59e0b\", align: \"center\", cap: \"round\", join: \"round\" },\n width: \"hug\",\n height: \"hug\",\n slope: (s) => {\n const plot = curveFor(s.graph, s.on);\n return plot ? tangentSlope(plot, s.x, s.dx) : NaN;\n },\n },\n commands: omit(PAINT_COMMANDS, \"fillTo\"),\n measure: (_measurer, s) => inkSize(traceTangent(s, reading(s))),\n render: (ctx, s) => drawMark(ctx, s, traceTangent(s, reading(s))),\n}), traceTangent);\n\nexport type TangentLine = NodeOf<typeof TangentLine>;\n\n/** The slope a tangent at `x` draws on `curve`, in graph units: the curve's at `x`, or the secant's to `x + dx`. */\nexport function tangentSlope(curve: CurveValues, x: number, dx = 0): number {\n if (dx > 0) return (curveValue(curve, x + dx) - curveValue(curve, x)) / dx;\n const h = 1e-6 * Math.max(1, Math.abs(x));\n return (curveValue(curve, x + h) - curveValue(curve, x - h)) / (2 * h);\n}\n\nfunction traceTangent(s: TangentValues, { map, plane }: MarkReading): Vector2[][] {\n const plot = curveFor(plane, s.on);\n if (!plot) return [];\n const x = s.x;\n const y = curveValue(plot, x);\n if (!Number.isFinite(y)) return [];\n const half = s.length / 2;\n\n if (s.dx > 0) {\n const y2 = curveValue(plot, x + s.dx);\n if (!Number.isFinite(y2)) return [];\n const a = map.toPoint(x, y);\n const b = map.toPoint(x + s.dx, y2);\n const span = Math.hypot(b.x - a.x, b.y - a.y);\n if (span === 0) return [];\n const reach = Math.max(half, span / 2 + 16);\n const ux = (b.x - a.x) / span;\n const uy = (b.y - a.y) / span;\n const mx = (a.x + b.x) / 2;\n const my = (a.y + b.y) / 2;\n const secant = [{ x: mx - ux * reach, y: my - uy * reach }, { x: mx + ux * reach, y: my + uy * reach }];\n return s.legs ? [secant, [a, map.toPoint(x + s.dx, y), b]] : [secant];\n }\n\n const [xMin, xMax] = map.xRange;\n const h = Number.isFinite(xMax - xMin) ? (xMax - xMin) * SLOPE_STEP : 1e-4;\n const before = curveValue(plot, x - h);\n const after = curveValue(plot, x + h);\n if (!Number.isFinite(before) || !Number.isFinite(after)) return [];\n const p = map.toPoint(x, y);\n const a = map.toPoint(x - h, before);\n const b = map.toPoint(x + h, after);\n const span = Math.hypot(b.x - a.x, b.y - a.y);\n if (span === 0) return [];\n const ux = (b.x - a.x) / span;\n const uy = (b.y - a.y) / span;\n return [[{ x: p.x - ux * half, y: p.y - uy * half }, { x: p.x + ux * half, y: p.y + uy * half }]];\n}\n"]}
@@ -0,0 +1,60 @@
1
+ import { type NodeOf, type PaintProps, type Vector2, 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
+ export interface VectorArrowProps extends PaintProps {
3
+ tail?: Vector2;
4
+ head?: Vector2;
5
+ bend?: number;
6
+ }
7
+ /**
8
+ * An arrow from `tail` to `head`, two graph points. Its arrowhead is the stroke's
9
+ * `endCap`, so a plain segment, a double arrow or a dashed one is a change of
10
+ * stroke. (`from` and `to` are not its names because every node has a `to`.)
11
+ */
12
+ export declare const VectorArrow: import("@motionscript/sdk").Component<"vectorArrow", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
13
+ tail: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
14
+ head: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
15
+ /** The arc the arrow sweeps, in degrees: zero is straight, positive bows to its left. */
16
+ bend: import("@motionscript/sdk").Type<number, number, false>;
17
+ graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
18
+ start: import("@motionscript/sdk").Type<number, number, false>;
19
+ end: import("@motionscript/sdk").Type<number, number, false>;
20
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
21
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
22
+ }>, {
23
+ readonly endpointsTo: readonly ["tail", "head"];
24
+ readonly strokeTo: readonly ["stroke"];
25
+ readonly shadowTo: readonly ["shadow"];
26
+ readonly progressTo: readonly ["start", "end"];
27
+ readonly flash: {
28
+ readonly portion: import("@motionscript/sdk").Type<number, number, false>;
29
+ };
30
+ }, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
31
+ tail: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
32
+ head: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
33
+ /** The arc the arrow sweeps, in degrees: zero is straight, positive bows to its left. */
34
+ bend: import("@motionscript/sdk").Type<number, number, false>;
35
+ graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
36
+ start: import("@motionscript/sdk").Type<number, number, false>;
37
+ end: import("@motionscript/sdk").Type<number, number, false>;
38
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
39
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
40
+ }>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
41
+ tail: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
42
+ head: import("@motionscript/sdk").Type<Vector2, Vector2, false>;
43
+ /** The arc the arrow sweeps, in degrees: zero is straight, positive bows to its left. */
44
+ bend: import("@motionscript/sdk").Type<number, number, false>;
45
+ graph: import("@motionscript/sdk").Type<import("../index.js").GraphPlane | null, import("../index.js").GraphPlane | null, true>;
46
+ start: import("@motionscript/sdk").Type<number, number, false>;
47
+ end: import("@motionscript/sdk").Type<number, number, false>;
48
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
49
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
50
+ }>, {
51
+ readonly endpointsTo: readonly ["tail", "head"];
52
+ readonly strokeTo: readonly ["stroke"];
53
+ readonly shadowTo: readonly ["shadow"];
54
+ readonly progressTo: readonly ["start", "end"];
55
+ readonly flash: {
56
+ readonly portion: import("@motionscript/sdk").Type<number, number, false>;
57
+ };
58
+ }, _Node2D<_Node2DProps>>>>;
59
+ export type VectorArrow = NodeOf<typeof VectorArrow>;
60
+ //# sourceMappingURL=vector-arrow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vector-arrow.d.ts","sourceRoot":"","sources":["../../src/marks/vector-arrow.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,OAAO,EAEZ,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;AAK3B,MAAM,WAAW,gBAAiB,SAAQ,UAAU;IAChD,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAgCD;;;;GAIG;AACH,eAAO,MAAM,WAAW;;;IA5BpB,yFAAyF;;;;;;;;;;;;;;;;;;IAAzF,yFAAyF;;;;;;;;;;IAAzF,yFAAyF;;;;;;;;;;;;;;;2BAwC9E,CAAC;AAEhB,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC"}
@@ -0,0 +1,67 @@
1
+ import { component2d, Types, } from "@motionscript/sdk";
2
+ import { omit, PAINT, PAINT_COMMANDS } from "../kit/component.js";
3
+ import { PLANE_ENTRY } from "../kit/graph.js";
4
+ import { drawMark, graphPoint, inkSize, ownPoint, reading, traced } from "../kit/mark.js";
5
+ /** Degrees of arc per drawn segment of a bent arrow. */
6
+ const BEND_STEP = 4;
7
+ const state = {
8
+ ...omit(PAINT, "fill"),
9
+ tail: Types.vector2(),
10
+ head: Types.vector2({ x: 1, y: 1 }),
11
+ /** The arc the arrow sweeps, in degrees: zero is straight, positive bows to its left. */
12
+ bend: Types.number(0, { min: -180, max: 180, unit: "°" }),
13
+ graph: PLANE_ENTRY,
14
+ };
15
+ /** A handle on one end of the arrow: where the end is in its own frame, and the graph point a drop there gives. */
16
+ const end = (which) => ({
17
+ at: (s) => {
18
+ const read = reading(s);
19
+ return ownPoint(read, traceArrow(s, read), s[which]);
20
+ },
21
+ value: (at, s) => {
22
+ const read = reading(s);
23
+ return graphPoint(read, traceArrow(s, read), at);
24
+ },
25
+ });
26
+ /**
27
+ * An arrow from `tail` to `head`, two graph points. Its arrowhead is the stroke's
28
+ * `endCap`, so a plain segment, a double arrow or a dashed one is a change of
29
+ * stroke. (`from` and `to` are not its names because every node has a `to`.)
30
+ */
31
+ export const VectorArrow = traced(component2d({
32
+ key: "vectorArrow",
33
+ state,
34
+ defaults: { stroke: { weight: 4, fill: "#e5e7eb", align: "center", endCap: "triangle" }, width: "hug", height: "hug" },
35
+ commands: {
36
+ ...omit(PAINT_COMMANDS, "fillTo"),
37
+ /** Move either end, in graph coordinates. */
38
+ endpointsTo: { args: ["tail", "head"] },
39
+ },
40
+ handles: { tail: end("tail"), head: end("head") },
41
+ measure: (_measurer, s) => inkSize(traceArrow(s, reading(s))),
42
+ render: (ctx, s) => drawMark(ctx, s, traceArrow(s, reading(s))),
43
+ }), traceArrow);
44
+ function traceArrow(s, { map, shift }) {
45
+ const a = map.toPoint(s.tail.x + shift.x, s.tail.y + shift.y);
46
+ const b = map.toPoint(s.head.x + shift.x, s.head.y + shift.y);
47
+ const sweep = (s.bend * Math.PI) / 180;
48
+ const chord = Math.hypot(b.x - a.x, b.y - a.y);
49
+ if (Math.abs(sweep) < 1e-3 || chord === 0)
50
+ return [[a, b]];
51
+ // The circle through both ends that subtends `sweep` at its centre.
52
+ const radius = chord / (2 * Math.sin(Math.abs(sweep) / 2));
53
+ const side = Math.sign(sweep);
54
+ const reach = radius * Math.cos(sweep / 2);
55
+ // The centre sits to the arrow's right for a positive sweep, so the arc bows to its left.
56
+ const cx = (a.x + b.x) / 2 + (side * (b.y - a.y) * reach) / chord;
57
+ const cy = (a.y + b.y) / 2 - (side * (b.x - a.x) * reach) / chord;
58
+ const from = Math.atan2(a.y - cy, a.x - cx);
59
+ const steps = Math.max(8, Math.ceil(Math.abs(s.bend) / BEND_STEP));
60
+ const run = [];
61
+ for (let i = 0; i <= steps; i++) {
62
+ const angle = from - (sweep * i) / steps;
63
+ run.push({ x: cx + radius * Math.cos(angle), y: cy + radius * Math.sin(angle) });
64
+ }
65
+ return [run];
66
+ }
67
+ //# sourceMappingURL=vector-arrow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vector-arrow.js","sourceRoot":"","sources":["../../src/marks/vector-arrow.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,KAAK,GAWR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,IAAI,EAAE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I,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;IAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;IACnE,MAAM,GAAG,GAAc,EAAE,CAAC;IAC1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;QACzC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACrF,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,CAAC;AACjB,CAAC","sourcesContent":["import {\n component2d,\n Types,\n type NodeOf,\n type PaintProps,\n type Vector2,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n} from \"@motionscript/sdk\";\nimport { omit, PAINT, PAINT_COMMANDS } from \"../kit/component\";\nimport { PLANE_ENTRY } from \"../kit/graph\";\nimport { drawMark, graphPoint, inkSize, ownPoint, reading, traced, type MarkReading, type MarkState } from \"../kit/mark\";\n\nexport interface VectorArrowProps extends PaintProps {\n tail?: Vector2;\n head?: Vector2;\n bend?: number;\n}\n\n/** Degrees of arc per drawn segment of a bent arrow. */\nconst BEND_STEP = 4;\n\nconst state = {\n ...omit(PAINT, \"fill\"),\n tail: Types.vector2(),\n head: Types.vector2({ x: 1, y: 1 }),\n /** The arc the arrow sweeps, in degrees: zero is straight, positive bows to its left. */\n bend: Types.number(0, { min: -180, max: 180, unit: \"°\" }),\n graph: PLANE_ENTRY,\n};\n\ninterface ArrowValues {\n readonly tail: Vector2;\n readonly head: Vector2;\n readonly bend: number;\n}\n\n/** A handle on one end of the arrow: where the end is in its own frame, and the graph point a drop there gives. */\nconst end = (which: \"tail\" | \"head\") => ({\n at: (s: ArrowValues & MarkState) => {\n const read = reading(s);\n return ownPoint(read, traceArrow(s, read), s[which]);\n },\n value: (at: Vector2, s: ArrowValues & MarkState) => {\n const read = reading(s);\n return graphPoint(read, traceArrow(s, read), at);\n },\n});\n\n/**\n * An arrow from `tail` to `head`, two graph points. Its arrowhead is the stroke's\n * `endCap`, so a plain segment, a double arrow or a dashed one is a change of\n * stroke. (`from` and `to` are not its names because every node has a `to`.)\n */\nexport const VectorArrow = traced(component2d({\n key: \"vectorArrow\",\n state,\n defaults: { stroke: { weight: 4, fill: \"#e5e7eb\", align: \"center\", endCap: \"triangle\" }, width: \"hug\", height: \"hug\" },\n commands: {\n ...omit(PAINT_COMMANDS, \"fillTo\"),\n /** Move either end, in graph coordinates. */\n endpointsTo: { args: [\"tail\", \"head\"] },\n },\n handles: { tail: end(\"tail\"), head: end(\"head\") },\n measure: (_measurer, s) => inkSize(traceArrow(s, reading(s))),\n render: (ctx, s) => drawMark(ctx, s, traceArrow(s, reading(s))),\n}), traceArrow);\n\nexport type VectorArrow = NodeOf<typeof VectorArrow>;\n\nfunction traceArrow(s: ArrowValues, { map, shift }: MarkReading): Vector2[][] {\n const a = map.toPoint(s.tail.x + shift.x, s.tail.y + shift.y);\n const b = map.toPoint(s.head.x + shift.x, s.head.y + shift.y);\n const sweep = (s.bend * Math.PI) / 180;\n const chord = Math.hypot(b.x - a.x, b.y - a.y);\n if (Math.abs(sweep) < 1e-3 || chord === 0) return [[a, b]];\n\n // The circle through both ends that subtends `sweep` at its centre.\n const radius = chord / (2 * Math.sin(Math.abs(sweep) / 2));\n const side = Math.sign(sweep);\n const reach = radius * Math.cos(sweep / 2);\n // The centre sits to the arrow's right for a positive sweep, so the arc bows to its left.\n const cx = (a.x + b.x) / 2 + (side * (b.y - a.y) * reach) / chord;\n const cy = (a.y + b.y) / 2 - (side * (b.x - a.x) * reach) / chord;\n const from = Math.atan2(a.y - cy, a.x - cx);\n const steps = Math.max(8, Math.ceil(Math.abs(s.bend) / BEND_STEP));\n const run: Vector2[] = [];\n for (let i = 0; i <= steps; i++) {\n const angle = from - (sweep * i) / steps;\n run.push({ x: cx + radius * Math.cos(angle), y: cy + radius * Math.sin(angle) });\n }\n return [run];\n}\n"]}