@motionscript/math 0.1.0-alpha.5 → 0.1.0-alpha.7

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 +28 -0
  2. package/README.md +39 -33
  3. package/dist/annotate/angle-mark.d.ts +77 -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 +94 -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 +69 -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 +56 -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 +37 -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 +45 -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 +56 -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 +47 -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 +58 -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 +48 -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 +135 -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 +55 -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 +60 -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 +54 -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 +48 -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 +140 -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 +90 -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 +159 -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 +80 -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 +140 -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 +76 -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 +88 -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 +84 -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 +214 -54
  156. package/dist/three/axes3d.d.ts.map +1 -1
  157. package/dist/three/axes3d.js +163 -204
  158. package/dist/three/axes3d.js.map +1 -1
  159. package/dist/three/curve-plot3d.d.ts +108 -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 +85 -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 +176 -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 +87 -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 +187 -160
  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,91 +1,63 @@
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, fillProperty, node, property, strokeProperty, withdraw, } from "@motionscript/sdk";
8
- import { clamp, stated } from "../kit/geometry.js";
9
- import { Mark } from "../kit/mark.js";
10
- import { curveOf } from "../kit/curve.js";
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";
11
4
  import { lerpInterval, PLOT_COLOR, readInterval } from "../kit/furniture.js";
12
- import { SYSTEMS } from "../kit/placement.js";
13
- import { OUTLINE_TRIM } from "../kit/withdrawn.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";
14
8
  /** More rectangles than this is a filled area with extra steps. */
15
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
+ };
16
21
  /** Rectangles under a plot, each `dx` wide and as tall as the curve where it is sampled. */
17
- let RiemannSum = class RiemannSum extends Mark {
18
- constructor(props) {
19
- super(props ?? {});
20
- }
21
- /** Animate the rectangles' width: narrower is the sum closing in on the area. */
22
- refineTo(args) {
23
- return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });
24
- }
25
- /** Animate the span of x the rectangles cover. */
26
- domainTo(args) {
27
- return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });
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)]);
28
60
  }
29
- isClosed() {
30
- return true;
31
- }
32
- trace(map) {
33
- const plot = curveOf(this, this.on);
34
- const [a, b] = this.domain;
35
- const dx = this.dx;
36
- if (!plot || !(b > a) || !(dx > 0))
37
- return [];
38
- const [yMin, yMax] = map.yRange;
39
- const base = clamp(0, yMin, yMax);
40
- const at = this.sample === "left" ? 0 : this.sample === "right" ? 1 : 0.5;
41
- const count = Math.min(MAX_RECTANGLES, Math.ceil((b - a) / dx - 1e-9));
42
- const runs = [];
43
- for (let i = 0; i < count; i++) {
44
- const left = a + i * dx;
45
- const right = Math.min(b, left + dx);
46
- const value = plot.valueAt(left + (right - left) * at);
47
- if (!Number.isFinite(value))
48
- continue;
49
- const height = clamp(value, yMin, yMax);
50
- runs.push([map.toPoint(left, base), map.toPoint(left, height), map.toPoint(right, height), map.toPoint(right, base)]);
51
- }
52
- return runs;
53
- }
54
- };
55
- __decorate([
56
- property({ default: "", kind: "nodeRef", nodeTypes: ["functionPlot"], animatable: false })
57
- ], RiemannSum.prototype, "on", void 0);
58
- __decorate([
59
- property({ default: [0, 1], mapper: readInterval, tween: lerpInterval })
60
- ], RiemannSum.prototype, "domain", void 0);
61
- __decorate([
62
- property({ default: 0.25, min: 0.001 })
63
- ], RiemannSum.prototype, "dx", void 0);
64
- __decorate([
65
- property({ default: "left", options: ["left", "right", "center"], animatable: false })
66
- ], RiemannSum.prototype, "sample", void 0);
67
- __decorate([
68
- fillProperty({ default: { type: "solid", color: PLOT_COLOR, opacity: 0.35 } })
69
- ], RiemannSum.prototype, "fill", void 0);
70
- __decorate([
71
- strokeProperty({ default: { weight: 1.5, fill: PLOT_COLOR, align: "center", join: "round" } })
72
- ], RiemannSum.prototype, "stroke", void 0);
73
- __decorate([
74
- command({ args: ["dx"] })
75
- ], RiemannSum.prototype, "refineTo", null);
76
- __decorate([
77
- command({ args: ["domain"] })
78
- ], RiemannSum.prototype, "domainTo", null);
79
- RiemannSum = __decorate([
80
- node({
81
- key: "riemannSum",
82
- within: SYSTEMS,
83
- beside: ["functionPlot"],
84
- parentKey: "shape",
85
- forkable: true,
86
- layout: { children: "freeform", defaultWidthMode: "hug", defaultHeightMode: "hug", acceptsChildren: false },
87
- }),
88
- withdraw(...OUTLINE_TRIM)
89
- ], RiemannSum);
90
- export { RiemannSum };
61
+ return runs;
62
+ }
91
63
  //# sourceMappingURL=riemann-sum.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"riemann-sum.js","sourceRoot":"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AE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC;0CAAwB;AAQvH;IADC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;0CAGzB;AAID;IADC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC;0CAG7B;AA1BQ,UAAU;IATtB,IAAI,CAAC;QACF,GAAG,EAAE,YAAY;QACjB,MAAM,EAAE,OAAO;QACf,MAAM,EAAE,CAAC,cAAc,CAAC;QACxB,SAAS,EAAE,OAAO;QAClB,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,gBAAgB,EAAE,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE;KAC9G,CAAC;IACD,QAAQ,CAAC,GAAG,YAAY,CAAC;GACb,UAAU,CAoDtB","sourcesContent":["import {\r\n command,\r\n fillProperty,\r\n node,\r\n property,\r\n strokeProperty,\r\n withdraw,\r\n type Command,\r\n type CommandArgs,\r\n type Fill,\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, Interval } from \"../kit/coords\";\r\nimport { clamp, stated } from \"../kit/geometry\";\r\nimport { Mark } from \"../kit/mark\";\r\nimport { curveOf } from \"../kit/curve\";\r\nimport { lerpInterval, PLOT_COLOR, readInterval } from \"../kit/furniture\";\r\nimport { SYSTEMS } from \"../kit/placement\";\r\nimport { OUTLINE_TRIM } from \"../kit/withdrawn\";\r\n\r\nexport type RiemannSample = \"left\" | \"right\" | \"center\";\r\n\r\nexport interface RiemannSumProps extends PaintProps {\r\n on?: string;\r\n domain?: Interval;\r\n dx?: number;\r\n sample?: RiemannSample;\r\n}\r\n\r\n/** More rectangles than this is a filled area with extra steps. */\r\nconst MAX_RECTANGLES = 2000;\r\n\r\n/** Rectangles under a plot, each `dx` wide and as tall as the curve where it is sampled. */\r\n@node({\r\n key: \"riemannSum\",\r\n within: SYSTEMS,\r\n beside: [\"functionPlot\"],\r\n parentKey: \"shape\",\r\n forkable: true,\r\n layout: { children: \"freeform\", defaultWidthMode: \"hug\", defaultHeightMode: \"hug\", acceptsChildren: false },\r\n})\r\n@withdraw(...OUTLINE_TRIM)\r\nexport class RiemannSum extends Mark<RiemannSumProps> {\r\n @property({ default: \"\", kind: \"nodeRef\", nodeTypes: [\"functionPlot\"], animatable: false }) declare on: string;\r\n @property({ default: [0, 1], mapper: readInterval, tween: lerpInterval })\r\n declare domain: Interval;\r\n /** Each rectangle's width, in graph units. */\r\n @property({ default: 0.25, min: 0.001 }) declare dx: number;\r\n /** Where in its width a rectangle reads the curve's height. */\r\n @property({ default: \"left\", options: [\"left\", \"right\", \"center\"], animatable: false }) declare sample: RiemannSample;\r\n\r\n @fillProperty({ default: { type: \"solid\", color: PLOT_COLOR, opacity: 0.35 } }) declare fill: Fill;\r\n @strokeProperty({ default: { weight: 1.5, fill: PLOT_COLOR, align: \"center\", join: \"round\" } }) declare stroke: Stroke;\r\n\r\n constructor(props?: NodeConfig<RiemannSum, RiemannSumProps>) {\r\n super(props ?? {});\r\n }\r\n\r\n /** Animate the rectangles' width: narrower is the sum closing in on the area. */\r\n @command({ args: [\"dx\"] })\r\n refineTo(args: CommandArgs<{ dx: number }> & { duration: number }): Command<RiemannSumProps> {\r\n return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });\r\n }\r\n\r\n /** Animate the span of x the rectangles cover. */\r\n @command({ args: [\"domain\"] })\r\n domainTo(args: CommandArgs<{ domain: Interval }> & { duration: number }): Command<RiemannSumProps> {\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 true;\r\n }\r\n\r\n protected trace(map: CoordinateMap): Vector2[][] {\r\n const plot = curveOf(this, this.on);\r\n const [a, b] = this.domain;\r\n const dx = this.dx;\r\n if (!plot || !(b > a) || !(dx > 0)) return [];\r\n const [yMin, yMax] = map.yRange;\r\n const base = clamp(0, yMin, yMax);\r\n const at = this.sample === \"left\" ? 0 : this.sample === \"right\" ? 1 : 0.5;\r\n const count = Math.min(MAX_RECTANGLES, Math.ceil((b - a) / dx - 1e-9));\r\n const runs: Vector2[][] = [];\r\n for (let i = 0; i < count; i++) {\r\n const left = a + i * dx;\r\n const right = Math.min(b, left + dx);\r\n const value = plot.valueAt(left + (right - left) * at);\r\n if (!Number.isFinite(value)) continue;\r\n const height = clamp(value, yMin, yMax);\r\n runs.push([map.toPoint(left, base), map.toPoint(left, height), map.toPoint(right, height), map.toPoint(right, base)]);\r\n }\r\n return runs;\r\n }\r\n}\r\n"]}
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,iBAAiB,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAoB,MAAM,aAAa,CAAC;AAWnF,mEAAmE;AACnE,MAAM,cAAc,GAAG,IAAI,CAAC;AAE5B,MAAM,KAAK,GAAG;IACV,uEAAuE;IACvE,GAAG,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC;IAC9B,EAAE,EAAE,QAAQ;IACZ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,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 {\r\n component2d,\r\n Types,\r\n type NodeOf,\r\n type NodeView,\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 { listed, omit, PAINT, PAINT_COMMANDS } from \"../kit/component\";\r\nimport type { Interval } from \"../kit/coords\";\r\nimport { curveValue } from \"../kit/curve\";\r\nimport { lerpInterval, PLOT_COLOR, readInterval } from \"../kit/furniture\";\r\nimport { clamp } from \"../kit/geometry\";\r\nimport { curveFor, PLANE_ENTRY, PLOT_REF } from \"../kit/graph\";\r\nimport { drawMark, inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\r\n\r\nexport type RiemannSample = \"left\" | \"right\" | \"center\";\r\n\r\nexport interface RiemannSumProps extends PaintProps {\r\n on?: string;\r\n domain?: Interval;\r\n dx?: number;\r\n sample?: RiemannSample;\r\n}\r\n\r\n/** More rectangles than this is a filled area with extra steps. */\r\nconst MAX_RECTANGLES = 2000;\r\n\r\nconst state = {\r\n // Its rectangles are revealed by `dx`, not by trimming their outlines.\r\n ...omit(PAINT, \"start\", \"end\"),\r\n on: PLOT_REF,\r\n domain: Types.custom<Interval>([0, 1], { resolve: readInterval, lerp: lerpInterval }),\r\n /** Each rectangle's width, in graph units. */\r\n dx: Types.number(0.25, { min: 0.001 }),\r\n /** Where in its width a rectangle reads the curve's height. */\r\n sample: listed([\"left\", \"right\", \"center\"], \"left\", { animatable: false }),\r\n graph: PLANE_ENTRY,\r\n};\r\n\r\ninterface SumValues {\r\n readonly on: NodeView | null;\r\n readonly domain: Interval;\r\n readonly dx: number;\r\n readonly sample: RiemannSample;\r\n}\r\n\r\n/** Rectangles under a plot, each `dx` wide and as tall as the curve where it is sampled. */\r\nexport const RiemannSum = traced(component2d({\r\n key: \"riemannSum\",\r\n state,\r\n defaults: {\r\n fill: { type: \"solid\", color: PLOT_COLOR, opacity: 0.35 },\r\n stroke: { weight: 1.5, fill: PLOT_COLOR, align: \"center\", join: \"round\" },\r\n width: \"hug\",\r\n height: \"hug\",\r\n },\r\n commands: {\r\n ...omit(PAINT_COMMANDS, \"progressTo\", \"flash\"),\r\n /** Animate the rectangles' width: narrower is the sum closing in on the area. */\r\n refineTo: { args: [\"dx\"] },\r\n /** Animate the span of x the rectangles cover. */\r\n domainTo: { args: [\"domain\"] },\r\n },\r\n measure: (_measurer, s) => inkSize(traceSum(s, reading(s))),\r\n render: (ctx, s) => drawMark(ctx, s, traceSum(s, reading(s)), { closed: true }),\r\n}), traceSum);\r\n\r\nexport type RiemannSum = NodeOf<typeof RiemannSum>;\r\n\r\nfunction traceSum(s: SumValues, { map, plane }: MarkReading): Vector2[][] {\r\n const plot = curveFor(plane, s.on);\r\n const [a, b] = s.domain;\r\n const dx = s.dx;\r\n if (!plot || !(b > a) || !(dx > 0)) return [];\r\n const [yMin, yMax] = map.yRange;\r\n const base = clamp(0, yMin, yMax);\r\n const at = s.sample === \"left\" ? 0 : s.sample === \"right\" ? 1 : 0.5;\r\n const count = Math.min(MAX_RECTANGLES, Math.ceil((b - a) / dx - 1e-9));\r\n const runs: Vector2[][] = [];\r\n for (let i = 0; i < count; i++) {\r\n const left = a + i * dx;\r\n const right = Math.min(b, left + dx);\r\n const value = curveValue(plot, left + (right - left) * at);\r\n if (!Number.isFinite(value)) continue;\r\n const height = clamp(value, yMin, yMax);\r\n runs.push([map.toPoint(left, base), map.toPoint(left, height), map.toPoint(right, height), map.toPoint(right, base)]);\r\n }\r\n return runs;\r\n}\r\n"]}
@@ -1,6 +1,5 @@
1
- import { type NodeConfig, type PaintProps, type Stroke, type Vector2 } from "@motionscript/sdk";
2
- import type { CoordinateMap } from "../kit/coords.js";
3
- import { Mark } from "../kit/mark.js";
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";
4
3
  export interface TangentLineProps extends PaintProps {
5
4
  on?: string;
6
5
  length?: number;
@@ -12,16 +11,61 @@ export interface TangentLineProps extends PaintProps {
12
11
  * `dx` it is the secant through `x` and `x + dx` instead, and `legs` draws that
13
12
  * secant's run and rise.
14
13
  */
15
- export declare class TangentLine extends Mark<TangentLineProps> {
16
- on: string;
17
- length: number;
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>;
18
17
  /** The second point's distance along x; zero is the tangent itself. */
19
- dx: number;
20
- legs: boolean;
21
- stroke: Stroke;
22
- constructor(props?: NodeConfig<TangentLine, TangentLineProps>);
23
- /** The slope drawn, in graph units: the curve's at `x`, or the secant's when there is a `dx`. */
24
- get slope(): number;
25
- protected trace(map: CoordinateMap): Vector2[][];
26
- }
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
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
24
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
25
+ start: import("@motionscript/sdk").Type<number, number, false>;
26
+ end: import("@motionscript/sdk").Type<number, number, false>;
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
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
44
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
45
+ start: import("@motionscript/sdk").Type<number, number, false>;
46
+ end: import("@motionscript/sdk").Type<number, number, false>;
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
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
57
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
58
+ start: import("@motionscript/sdk").Type<number, number, false>;
59
+ end: import("@motionscript/sdk").Type<number, number, false>;
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;
27
71
  //# sourceMappingURL=tangent-line.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tangent-line.d.ts","sourceRoot":"","sources":["../../src/marks/tangent-line.ts"],"names":[],"mappings":"AAAA,OAAO,EAKH,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,OAAO,EACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAInC,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;AAKD;;;;GAIG;AACH,qBAQa,WAAY,SAAQ,IAAI,CAAC,gBAAgB,CAAC;IACiD,EAAE,EAAE,MAAM,CAAC;IACvD,MAAM,EAAE,MAAM,CAAC;IACvE,uEAAuE;IAC7B,EAAE,EAAE,MAAM,CAAC;IACI,IAAI,EAAE,OAAO,CAAC;IAG/D,MAAM,EAAE,MAAM,CAAC;gBAEX,KAAK,CAAC,EAAE,UAAU,CAAC,WAAW,EAAE,gBAAgB,CAAC;IAI7D,iGAAiG;IACjG,IAAI,KAAK,IAAI,MAAM,CAKlB;IAED,SAAS,CAAC,KAAK,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,EAAE,EAAE;CAsCnD"}
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"}
@@ -1,103 +1,89 @@
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 { node, property, strokeProperty, withdraw, } from "@motionscript/sdk";
8
- import { Mark } from "../kit/mark.js";
9
- import { curveOf } from "../kit/curve.js";
10
- import { FILL_PAINT } from "../kit/withdrawn.js";
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";
11
6
  /** The step a slope is measured over, as a share of the system's width. */
12
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
+ };
13
19
  /**
14
20
  * The tangent to a plot at this node's `x`, a fixed length on screen. With a
15
21
  * `dx` it is the secant through `x` and `x + dx` instead, and `legs` draws that
16
22
  * secant's run and rise.
17
23
  */
18
- let TangentLine = class TangentLine extends Mark {
19
- constructor(props) {
20
- super(props ?? {});
21
- }
22
- /** The slope drawn, in graph units: the curve's at `x`, or the secant's when there is a `dx`. */
23
- get slope() {
24
- const plot = curveOf(this, this.on);
25
- if (!plot)
26
- return NaN;
27
- if (this.dx > 0)
28
- return (plot.valueAt(this.x + this.dx) - plot.valueAt(this.x)) / this.dx;
29
- return slopeAt(plot, this.x, 1e-6 * Math.max(1, Math.abs(this.x)));
30
- }
31
- trace(map) {
32
- const plot = curveOf(this, this.on);
33
- if (!plot)
34
- return [];
35
- const x = this.x;
36
- const y = plot.valueAt(x);
37
- if (!Number.isFinite(y))
38
- return [];
39
- const half = this.length / 2;
40
- if (this.dx > 0) {
41
- const y2 = plot.valueAt(x + this.dx);
42
- if (!Number.isFinite(y2))
43
- return [];
44
- const a = map.toPoint(x, y);
45
- const b = map.toPoint(x + this.dx, y2);
46
- const span = Math.hypot(b.x - a.x, b.y - a.y);
47
- if (span === 0)
48
- return [];
49
- const reach = Math.max(half, span / 2 + 16);
50
- const ux = (b.x - a.x) / span;
51
- const uy = (b.y - a.y) / span;
52
- const mx = (a.x + b.x) / 2;
53
- const my = (a.y + b.y) / 2;
54
- const secant = [{ x: mx - ux * reach, y: my - uy * reach }, { x: mx + ux * reach, y: my + uy * reach }];
55
- return this.legs ? [secant, [a, map.toPoint(x + this.dx, y), b]] : [secant];
56
- }
57
- const [xMin, xMax] = map.xRange;
58
- const h = Number.isFinite(xMax - xMin) ? (xMax - xMin) * SLOPE_STEP : 1e-4;
59
- const before = plot.valueAt(x - h);
60
- const after = plot.valueAt(x + h);
61
- if (!Number.isFinite(before) || !Number.isFinite(after))
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))
62
59
  return [];
63
- const p = map.toPoint(x, y);
64
- const a = map.toPoint(x - h, before);
65
- const b = map.toPoint(x + h, after);
60
+ const a = map.toPoint(x, y);
61
+ const b = map.toPoint(x + s.dx, y2);
66
62
  const span = Math.hypot(b.x - a.x, b.y - a.y);
67
63
  if (span === 0)
68
64
  return [];
65
+ const reach = Math.max(half, span / 2 + 16);
69
66
  const ux = (b.x - a.x) / span;
70
67
  const uy = (b.y - a.y) / span;
71
- return [[{ x: p.x - ux * half, y: p.y - uy * half }, { x: p.x + ux * half, y: p.y + uy * half }]];
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
72
  }
73
- };
74
- __decorate([
75
- property({ default: "", kind: "nodeRef", nodeTypes: ["functionPlot"], animatable: false })
76
- ], TangentLine.prototype, "on", void 0);
77
- __decorate([
78
- property({ default: 260, min: 0, unit: "px" })
79
- ], TangentLine.prototype, "length", void 0);
80
- __decorate([
81
- property({ default: 0, min: 0 })
82
- ], TangentLine.prototype, "dx", void 0);
83
- __decorate([
84
- property({ default: false, animatable: false })
85
- ], TangentLine.prototype, "legs", void 0);
86
- __decorate([
87
- strokeProperty({ default: { weight: 3, fill: "#f59e0b", align: "center", cap: "round", join: "round" } })
88
- ], TangentLine.prototype, "stroke", void 0);
89
- TangentLine = __decorate([
90
- node({
91
- key: "tangentLine",
92
- within: ["functionPlot"],
93
- parentKey: "shape",
94
- forkable: true,
95
- layout: { children: "freeform", defaultWidthMode: "hug", defaultHeightMode: "hug", acceptsChildren: false },
96
- }),
97
- withdraw(...FILL_PAINT)
98
- ], TangentLine);
99
- export { TangentLine };
100
- function slopeAt(plot, x, h) {
101
- return (plot.valueAt(x + h) - plot.valueAt(x - h)) / (2 * h);
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 }]];
102
88
  }
103
89
  //# sourceMappingURL=tangent-line.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tangent-line.js","sourceRoot":"","sources":["../../src/marks/tangent-line.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,IAAI,EACJ,QAAQ,EACR,cAAc,EACd,QAAQ,GAKX,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,OAAO,EAAc,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAS9C,2EAA2E;AAC3E,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB;;;;GAIG;AASI,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,IAAsB;IAUnD,YAAY,KAAiD;QACzD,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IACvB,CAAC;IAED,iGAAiG;IACjG,IAAI,KAAK;QACL,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI;YAAE,OAAO,GAAG,CAAC;QAC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IAAW,EAAE,CAAS,EAAE,CAAS;IAC9C,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import {\r\n node,\r\n property,\r\n strokeProperty,\r\n withdraw,\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 { Mark } from \"../kit/mark\";\r\nimport { curveOf, type Curve } from \"../kit/curve\";\r\nimport { FILL_PAINT } from \"../kit/withdrawn\";\r\n\r\nexport interface TangentLineProps extends PaintProps {\r\n on?: string;\r\n length?: number;\r\n dx?: number;\r\n legs?: boolean;\r\n}\r\n\r\n/** The step a slope is measured over, as a share of the system's width. */\r\nconst SLOPE_STEP = 1e-4;\r\n\r\n/**\r\n * The tangent to a plot at this node's `x`, a fixed length on screen. With a\r\n * `dx` it is the secant through `x` and `x + dx` instead, and `legs` draws that\r\n * secant's run and rise.\r\n */\r\n@node({\r\n key: \"tangentLine\",\r\n within: [\"functionPlot\"],\r\n parentKey: \"shape\",\r\n forkable: true,\r\n layout: { children: \"freeform\", defaultWidthMode: \"hug\", defaultHeightMode: \"hug\", acceptsChildren: false },\r\n})\r\n@withdraw(...FILL_PAINT)\r\nexport class TangentLine extends Mark<TangentLineProps> {\r\n @property({ default: \"\", kind: \"nodeRef\", nodeTypes: [\"functionPlot\"], animatable: false }) declare on: string;\r\n @property({ default: 260, min: 0, unit: \"px\" }) declare length: number;\r\n /** The second point's distance along x; zero is the tangent itself. */\r\n @property({ default: 0, min: 0 }) declare dx: number;\r\n @property({ default: false, animatable: false }) declare legs: boolean;\r\n\r\n @strokeProperty({ default: { weight: 3, fill: \"#f59e0b\", align: \"center\", cap: \"round\", join: \"round\" } })\r\n declare stroke: Stroke;\r\n\r\n constructor(props?: NodeConfig<TangentLine, TangentLineProps>) {\r\n super(props ?? {});\r\n }\r\n\r\n /** The slope drawn, in graph units: the curve's at `x`, or the secant's when there is a `dx`. */\r\n get slope(): number {\r\n const plot = curveOf(this, this.on);\r\n if (!plot) return NaN;\r\n if (this.dx > 0) return (plot.valueAt(this.x + this.dx) - plot.valueAt(this.x)) / this.dx;\r\n return slopeAt(plot, this.x, 1e-6 * Math.max(1, Math.abs(this.x)));\r\n }\r\n\r\n protected trace(map: CoordinateMap): Vector2[][] {\r\n const plot = curveOf(this, this.on);\r\n if (!plot) return [];\r\n const x = this.x;\r\n const y = plot.valueAt(x);\r\n if (!Number.isFinite(y)) return [];\r\n const half = this.length / 2;\r\n\r\n if (this.dx > 0) {\r\n const y2 = plot.valueAt(x + this.dx);\r\n if (!Number.isFinite(y2)) return [];\r\n const a = map.toPoint(x, y);\r\n const b = map.toPoint(x + this.dx, y2);\r\n const span = Math.hypot(b.x - a.x, b.y - a.y);\r\n if (span === 0) return [];\r\n const reach = Math.max(half, span / 2 + 16);\r\n const ux = (b.x - a.x) / span;\r\n const uy = (b.y - a.y) / span;\r\n const mx = (a.x + b.x) / 2;\r\n const my = (a.y + b.y) / 2;\r\n const secant = [{ x: mx - ux * reach, y: my - uy * reach }, { x: mx + ux * reach, y: my + uy * reach }];\r\n return this.legs ? [secant, [a, map.toPoint(x + this.dx, y), b]] : [secant];\r\n }\r\n\r\n const [xMin, xMax] = map.xRange;\r\n const h = Number.isFinite(xMax - xMin) ? (xMax - xMin) * SLOPE_STEP : 1e-4;\r\n const before = plot.valueAt(x - h);\r\n const after = plot.valueAt(x + h);\r\n if (!Number.isFinite(before) || !Number.isFinite(after)) return [];\r\n const p = map.toPoint(x, y);\r\n const a = map.toPoint(x - h, before);\r\n const b = map.toPoint(x + h, after);\r\n const span = Math.hypot(b.x - a.x, b.y - a.y);\r\n if (span === 0) return [];\r\n const ux = (b.x - a.x) / span;\r\n const uy = (b.y - a.y) / span;\r\n return [[{ x: p.x - ux * half, y: p.y - uy * half }, { x: p.x + ux * half, y: p.y + uy * half }]];\r\n }\r\n}\r\n\r\nfunction slopeAt(plot: Curve, x: number, h: number): number {\r\n return (plot.valueAt(x + h) - plot.valueAt(x - h)) / (2 * h);\r\n}\r\n"]}
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,EAAE,OAAO,EAAE,MAAM,EAAoB,MAAM,aAAa,CAAC;AASnF,2EAA2E;AAC3E,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB,MAAM,KAAK,GAAG;IACV,GAAG,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC;IACtB,EAAE,EAAE,QAAQ;IACZ,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACjD,uEAAuE;IACvE,EAAE,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;IAC/B,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IACjD,KAAK,EAAE,WAAW;IAClB,2IAA2I;IAC3I,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;CAC9C,CAAC;AAUF;;;;GAIG;A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AAE,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 {\r\n component2d,\r\n Types,\r\n type NodeOf,\r\n type NodeView,\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 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, PAINT, PAINT_COMMANDS } from \"../kit/component\";\r\nimport { curveValue, type CurveValues } from \"../kit/curve\";\r\nimport { curveFor, PLANE_ENTRY, PLOT_REF } from \"../kit/graph\";\r\nimport { drawMark, inkSize, reading, traced, type MarkReading } from \"../kit/mark\";\r\n\r\nexport interface TangentLineProps extends PaintProps {\r\n on?: string;\r\n length?: number;\r\n dx?: number;\r\n legs?: boolean;\r\n}\r\n\r\n/** The step a slope is measured over, as a share of the system's width. */\r\nconst SLOPE_STEP = 1e-4;\r\n\r\nconst state = {\r\n ...omit(PAINT, \"fill\"),\r\n on: PLOT_REF,\r\n length: Types.number(260, { min: 0, unit: \"px\" }),\r\n /** The second point's distance along x; zero is the tangent itself. */\r\n dx: Types.number(0, { min: 0 }),\r\n legs: Types.boolean(false, { animatable: false }),\r\n graph: PLANE_ENTRY,\r\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]`. */\r\n slope: Types.number(NaN, { private: true }),\r\n};\r\n\r\ninterface TangentValues {\r\n readonly x: number;\r\n readonly on: NodeView | null;\r\n readonly length: number;\r\n readonly dx: number;\r\n readonly legs: boolean;\r\n}\r\n\r\n/**\r\n * The tangent to a plot at this node's `x`, a fixed length on screen. With a\r\n * `dx` it is the secant through `x` and `x + dx` instead, and `legs` draws that\r\n * secant's run and rise.\r\n */\r\nexport const TangentLine = traced(component2d({\r\n key: \"tangentLine\",\r\n state,\r\n defaults: {\r\n stroke: { weight: 3, fill: \"#f59e0b\", align: \"center\", cap: \"round\", join: \"round\" },\r\n width: \"hug\",\r\n height: \"hug\",\r\n slope: (s) => {\r\n const plot = curveFor(s.graph, s.on);\r\n return plot ? tangentSlope(plot, s.x, s.dx) : NaN;\r\n },\r\n },\r\n commands: omit(PAINT_COMMANDS, \"fillTo\"),\r\n measure: (_measurer, s) => inkSize(traceTangent(s, reading(s))),\r\n render: (ctx, s) => drawMark(ctx, s, traceTangent(s, reading(s))),\r\n}), traceTangent);\r\n\r\nexport type TangentLine = NodeOf<typeof TangentLine>;\r\n\r\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`. */\r\nexport function tangentSlope(curve: CurveValues, x: number, dx = 0): number {\r\n if (dx > 0) return (curveValue(curve, x + dx) - curveValue(curve, x)) / dx;\r\n const h = 1e-6 * Math.max(1, Math.abs(x));\r\n return (curveValue(curve, x + h) - curveValue(curve, x - h)) / (2 * h);\r\n}\r\n\r\nfunction traceTangent(s: TangentValues, { map, plane }: MarkReading): Vector2[][] {\r\n const plot = curveFor(plane, s.on);\r\n if (!plot) return [];\r\n const x = s.x;\r\n const y = curveValue(plot, x);\r\n if (!Number.isFinite(y)) return [];\r\n const half = s.length / 2;\r\n\r\n if (s.dx > 0) {\r\n const y2 = curveValue(plot, x + s.dx);\r\n if (!Number.isFinite(y2)) return [];\r\n const a = map.toPoint(x, y);\r\n const b = map.toPoint(x + s.dx, y2);\r\n const span = Math.hypot(b.x - a.x, b.y - a.y);\r\n if (span === 0) return [];\r\n const reach = Math.max(half, span / 2 + 16);\r\n const ux = (b.x - a.x) / span;\r\n const uy = (b.y - a.y) / span;\r\n const mx = (a.x + b.x) / 2;\r\n const my = (a.y + b.y) / 2;\r\n const secant = [{ x: mx - ux * reach, y: my - uy * reach }, { x: mx + ux * reach, y: my + uy * reach }];\r\n return s.legs ? [secant, [a, map.toPoint(x + s.dx, y), b]] : [secant];\r\n }\r\n\r\n const [xMin, xMax] = map.xRange;\r\n const h = Number.isFinite(xMax - xMin) ? (xMax - xMin) * SLOPE_STEP : 1e-4;\r\n const before = curveValue(plot, x - h);\r\n const after = curveValue(plot, x + h);\r\n if (!Number.isFinite(before) || !Number.isFinite(after)) return [];\r\n const p = map.toPoint(x, y);\r\n const a = map.toPoint(x - h, before);\r\n const b = map.toPoint(x + h, after);\r\n const span = Math.hypot(b.x - a.x, b.y - a.y);\r\n if (span === 0) return [];\r\n const ux = (b.x - a.x) / span;\r\n const uy = (b.y - a.y) / span;\r\n return [[{ x: p.x - ux * half, y: p.y - uy * half }, { x: p.x + ux * half, y: p.y + uy * half }]];\r\n}\r\n"]}
@@ -1,6 +1,4 @@
1
- import { type Command, type CommandArgs, type NodeConfig, type NodeHandle, type PaintProps, type Stroke, type Vector2 } from "@motionscript/sdk";
2
- import type { CoordinateMap } from "../kit/coords.js";
3
- import { Mark } from "../kit/mark.js";
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";
4
2
  export interface VectorArrowProps extends PaintProps {
5
3
  tail?: Vector2;
6
4
  head?: Vector2;
@@ -11,22 +9,52 @@ export interface VectorArrowProps extends PaintProps {
11
9
  * `endCap`, so a plain segment, a double arrow or a dashed one is a change of
12
10
  * stroke. (`from` and `to` are not its names because every node has a `to`.)
13
11
  */
14
- export declare class VectorArrow extends Mark<VectorArrowProps> {
15
- tail: Vector2;
16
- head: Vector2;
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>;
17
15
  /** The arc the arrow sweeps, in degrees: zero is straight, positive bows to its left. */
18
- bend: number;
19
- stroke: Stroke;
20
- constructor(props?: NodeConfig<VectorArrow, VectorArrowProps>);
21
- /** Move either end, in graph coordinates. */
22
- endpointsTo(args: CommandArgs<{
23
- tail?: Vector2;
24
- head?: Vector2;
25
- }> & {
26
- duration: number;
27
- }): Command<VectorArrowProps>;
28
- protected trace(map: CoordinateMap): Vector2[][];
29
- _handles(): readonly NodeHandle[];
30
- _handleValue(prop: string, at: Vector2): Vector2 | null;
31
- }
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
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
19
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
20
+ start: import("@motionscript/sdk").Type<number, number, false>;
21
+ end: import("@motionscript/sdk").Type<number, number, false>;
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
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
37
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
38
+ start: import("@motionscript/sdk").Type<number, number, false>;
39
+ end: import("@motionscript/sdk").Type<number, number, false>;
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
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
47
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
48
+ start: import("@motionscript/sdk").Type<number, number, false>;
49
+ end: import("@motionscript/sdk").Type<number, number, false>;
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>;
32
60
  //# sourceMappingURL=vector-arrow.d.ts.map