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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (322) hide show
  1. package/CHANGELOG.md +110 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +48 -0
  4. package/README.md +385 -3
  5. package/dist/annotate/angle-mark.d.ts +46 -0
  6. package/dist/annotate/angle-mark.d.ts.map +1 -0
  7. package/dist/annotate/angle-mark.js +132 -0
  8. package/dist/annotate/angle-mark.js.map +1 -0
  9. package/dist/annotate/curly-brace.d.ts +46 -0
  10. package/dist/annotate/curly-brace.d.ts.map +1 -0
  11. package/dist/annotate/curly-brace.js +114 -0
  12. package/dist/annotate/curly-brace.js.map +1 -0
  13. package/dist/annotate/emphasis-mark.d.ts +20 -0
  14. package/dist/annotate/emphasis-mark.d.ts.map +1 -0
  15. package/dist/annotate/emphasis-mark.js +81 -0
  16. package/dist/annotate/emphasis-mark.js.map +1 -0
  17. package/dist/browser/THIRD_PARTY_LICENSES.txt +420 -0
  18. package/dist/browser/chunks/chunk-3GJB6AVO.js +2 -0
  19. package/dist/browser/chunks/chunk-3GJB6AVO.js.map +7 -0
  20. package/dist/browser/chunks/chunk-D5WHCVBC.js +2 -0
  21. package/dist/browser/chunks/chunk-D5WHCVBC.js.map +7 -0
  22. package/dist/browser/chunks/chunk-WL4KEX7Y.js +2 -0
  23. package/dist/browser/chunks/chunk-WL4KEX7Y.js.map +7 -0
  24. package/dist/browser/chunks/mathjax-DNP3YRES.js +61 -0
  25. package/dist/browser/chunks/mathjax-DNP3YRES.js.map +7 -0
  26. package/dist/browser/index.js +2 -0
  27. package/dist/browser/index.js.map +7 -0
  28. package/dist/browser/kit.js +2 -0
  29. package/dist/browser/kit.js.map +7 -0
  30. package/dist/browser/manifest.json +30 -0
  31. package/dist/browser/tex.js +2 -0
  32. package/dist/browser/tex.js.map +7 -0
  33. package/dist/engine.d.ts +64 -0
  34. package/dist/engine.d.ts.map +1 -0
  35. package/dist/engine.js +42 -0
  36. package/dist/engine.js.map +1 -0
  37. package/dist/index.d.ts +30 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +30 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/kit/brace.d.ts +8 -0
  42. package/dist/kit/brace.d.ts.map +1 -0
  43. package/dist/kit/brace.js +36 -0
  44. package/dist/kit/brace.js.map +1 -0
  45. package/dist/kit/cache.d.ts +30 -0
  46. package/dist/kit/cache.d.ts.map +1 -0
  47. package/dist/kit/cache.js +53 -0
  48. package/dist/kit/cache.js.map +1 -0
  49. package/dist/kit/contour.d.ts +8 -0
  50. package/dist/kit/contour.d.ts.map +1 -0
  51. package/dist/kit/contour.js +93 -0
  52. package/dist/kit/contour.js.map +1 -0
  53. package/dist/kit/coords.d.ts +69 -0
  54. package/dist/kit/coords.d.ts.map +1 -0
  55. package/dist/kit/coords.js +224 -0
  56. package/dist/kit/coords.js.map +1 -0
  57. package/dist/kit/curve.d.ts +17 -0
  58. package/dist/kit/curve.d.ts.map +1 -0
  59. package/dist/kit/curve.js +22 -0
  60. package/dist/kit/curve.js.map +1 -0
  61. package/dist/kit/equation.d.ts +61 -0
  62. package/dist/kit/equation.d.ts.map +1 -0
  63. package/dist/kit/equation.js +168 -0
  64. package/dist/kit/equation.js.map +1 -0
  65. package/dist/kit/equation3d.d.ts +50 -0
  66. package/dist/kit/equation3d.d.ts.map +1 -0
  67. package/dist/kit/equation3d.js +103 -0
  68. package/dist/kit/equation3d.js.map +1 -0
  69. package/dist/kit/expression.d.ts +35 -0
  70. package/dist/kit/expression.d.ts.map +1 -0
  71. package/dist/kit/expression.js +124 -0
  72. package/dist/kit/expression.js.map +1 -0
  73. package/dist/kit/field-mark.d.ts +58 -0
  74. package/dist/kit/field-mark.d.ts.map +1 -0
  75. package/dist/kit/field-mark.js +129 -0
  76. package/dist/kit/field-mark.js.map +1 -0
  77. package/dist/kit/field.d.ts +14 -0
  78. package/dist/kit/field.d.ts.map +1 -0
  79. package/dist/kit/field.js +46 -0
  80. package/dist/kit/field.js.map +1 -0
  81. package/dist/kit/follow.d.ts +71 -0
  82. package/dist/kit/follow.d.ts.map +1 -0
  83. package/dist/kit/follow.js +159 -0
  84. package/dist/kit/follow.js.map +1 -0
  85. package/dist/kit/furniture.d.ts +30 -0
  86. package/dist/kit/furniture.d.ts.map +1 -0
  87. package/dist/kit/furniture.js +87 -0
  88. package/dist/kit/furniture.js.map +1 -0
  89. package/dist/kit/geometry.d.ts +13 -0
  90. package/dist/kit/geometry.d.ts.map +1 -0
  91. package/dist/kit/geometry.js +54 -0
  92. package/dist/kit/geometry.js.map +1 -0
  93. package/dist/kit/mark.d.ts +47 -0
  94. package/dist/kit/mark.d.ts.map +1 -0
  95. package/dist/kit/mark.js +103 -0
  96. package/dist/kit/mark.js.map +1 -0
  97. package/dist/kit/part-fills.d.ts +23 -0
  98. package/dist/kit/part-fills.d.ts.map +1 -0
  99. package/dist/kit/part-fills.js +46 -0
  100. package/dist/kit/part-fills.js.map +1 -0
  101. package/dist/kit/place.d.ts +18 -0
  102. package/dist/kit/place.d.ts.map +1 -0
  103. package/dist/kit/place.js +68 -0
  104. package/dist/kit/place.js.map +1 -0
  105. package/dist/kit/placement.d.ts +8 -0
  106. package/dist/kit/placement.d.ts.map +1 -0
  107. package/dist/kit/placement.js +8 -0
  108. package/dist/kit/placement.js.map +1 -0
  109. package/dist/kit/sampler.d.ts +17 -0
  110. package/dist/kit/sampler.d.ts.map +1 -0
  111. package/dist/kit/sampler.js +250 -0
  112. package/dist/kit/sampler.js.map +1 -0
  113. package/dist/kit/scale.d.ts +12 -0
  114. package/dist/kit/scale.d.ts.map +1 -0
  115. package/dist/kit/scale.js +37 -0
  116. package/dist/kit/scale.js.map +1 -0
  117. package/dist/kit/source.d.ts +22 -0
  118. package/dist/kit/source.d.ts.map +1 -0
  119. package/dist/kit/source.js +45 -0
  120. package/dist/kit/source.js.map +1 -0
  121. package/dist/kit/system.d.ts +33 -0
  122. package/dist/kit/system.d.ts.map +1 -0
  123. package/dist/kit/system.js +67 -0
  124. package/dist/kit/system.js.map +1 -0
  125. package/dist/kit/ticks.d.ts +19 -0
  126. package/dist/kit/ticks.d.ts.map +1 -0
  127. package/dist/kit/ticks.js +78 -0
  128. package/dist/kit/ticks.js.map +1 -0
  129. package/dist/kit/withdrawn.d.ts +9 -0
  130. package/dist/kit/withdrawn.d.ts.map +1 -0
  131. package/dist/kit/withdrawn.js +9 -0
  132. package/dist/kit/withdrawn.js.map +1 -0
  133. package/dist/marks/curve-area.d.ts +32 -0
  134. package/dist/marks/curve-area.d.ts.map +1 -0
  135. package/dist/marks/curve-area.js +82 -0
  136. package/dist/marks/curve-area.js.map +1 -0
  137. package/dist/marks/drop-lines.d.ts +22 -0
  138. package/dist/marks/drop-lines.d.ts.map +1 -0
  139. package/dist/marks/drop-lines.js +58 -0
  140. package/dist/marks/drop-lines.js.map +1 -0
  141. package/dist/marks/plot-point.d.ts +35 -0
  142. package/dist/marks/plot-point.d.ts.map +1 -0
  143. package/dist/marks/plot-point.js +97 -0
  144. package/dist/marks/plot-point.js.map +1 -0
  145. package/dist/marks/riemann-sum.d.ts +37 -0
  146. package/dist/marks/riemann-sum.d.ts.map +1 -0
  147. package/dist/marks/riemann-sum.js +91 -0
  148. package/dist/marks/riemann-sum.js.map +1 -0
  149. package/dist/marks/tangent-line.d.ts +27 -0
  150. package/dist/marks/tangent-line.d.ts.map +1 -0
  151. package/dist/marks/tangent-line.js +103 -0
  152. package/dist/marks/tangent-line.js.map +1 -0
  153. package/dist/marks/vector-arrow.d.ts +32 -0
  154. package/dist/marks/vector-arrow.d.ts.map +1 -0
  155. package/dist/marks/vector-arrow.js +87 -0
  156. package/dist/marks/vector-arrow.js.map +1 -0
  157. package/dist/nodes.d.ts +35 -0
  158. package/dist/nodes.d.ts.map +1 -0
  159. package/dist/nodes.js +63 -0
  160. package/dist/nodes.js.map +1 -0
  161. package/dist/plots/function-plot.d.ts +67 -0
  162. package/dist/plots/function-plot.d.ts.map +1 -0
  163. package/dist/plots/function-plot.js +215 -0
  164. package/dist/plots/function-plot.js.map +1 -0
  165. package/dist/plots/points-plot.d.ts +28 -0
  166. package/dist/plots/points-plot.d.ts.map +1 -0
  167. package/dist/plots/points-plot.js +99 -0
  168. package/dist/plots/points-plot.js.map +1 -0
  169. package/dist/plots/stream-lines.d.ts +35 -0
  170. package/dist/plots/stream-lines.d.ts.map +1 -0
  171. package/dist/plots/stream-lines.js +141 -0
  172. package/dist/plots/stream-lines.js.map +1 -0
  173. package/dist/plots/traced-path.d.ts +31 -0
  174. package/dist/plots/traced-path.d.ts.map +1 -0
  175. package/dist/plots/traced-path.js +56 -0
  176. package/dist/plots/traced-path.js.map +1 -0
  177. package/dist/plots/vector-field.d.ts +23 -0
  178. package/dist/plots/vector-field.d.ts.map +1 -0
  179. package/dist/plots/vector-field.js +91 -0
  180. package/dist/plots/vector-field.js.map +1 -0
  181. package/dist/structures/graph-layout.d.ts +11 -0
  182. package/dist/structures/graph-layout.d.ts.map +1 -0
  183. package/dist/structures/graph-layout.js +135 -0
  184. package/dist/structures/graph-layout.js.map +1 -0
  185. package/dist/structures/network-graph.d.ts +83 -0
  186. package/dist/structures/network-graph.d.ts.map +1 -0
  187. package/dist/structures/network-graph.js +289 -0
  188. package/dist/structures/network-graph.js.map +1 -0
  189. package/dist/structures/sample-space.d.ts +62 -0
  190. package/dist/structures/sample-space.d.ts.map +1 -0
  191. package/dist/structures/sample-space.js +199 -0
  192. package/dist/structures/sample-space.js.map +1 -0
  193. package/dist/systems/axes2d.d.ts +75 -0
  194. package/dist/systems/axes2d.d.ts.map +1 -0
  195. package/dist/systems/axes2d.js +193 -0
  196. package/dist/systems/axes2d.js.map +1 -0
  197. package/dist/systems/number-line.d.ts +49 -0
  198. package/dist/systems/number-line.d.ts.map +1 -0
  199. package/dist/systems/number-line.js +127 -0
  200. package/dist/systems/number-line.js.map +1 -0
  201. package/dist/systems/number-plane.d.ts +59 -0
  202. package/dist/systems/number-plane.d.ts.map +1 -0
  203. package/dist/systems/number-plane.js +193 -0
  204. package/dist/systems/number-plane.js.map +1 -0
  205. package/dist/systems/polar-plane.d.ts +48 -0
  206. package/dist/systems/polar-plane.d.ts.map +1 -0
  207. package/dist/systems/polar-plane.js +165 -0
  208. package/dist/systems/polar-plane.js.map +1 -0
  209. package/dist/tex/geometry.d.ts +85 -0
  210. package/dist/tex/geometry.d.ts.map +1 -0
  211. package/dist/tex/geometry.js +632 -0
  212. package/dist/tex/geometry.js.map +1 -0
  213. package/dist/tex/index.d.ts +11 -0
  214. package/dist/tex/index.d.ts.map +1 -0
  215. package/dist/tex/index.js +9 -0
  216. package/dist/tex/index.js.map +1 -0
  217. package/dist/tex/mathjax.d.ts +33 -0
  218. package/dist/tex/mathjax.d.ts.map +1 -0
  219. package/dist/tex/mathjax.js +74 -0
  220. package/dist/tex/mathjax.js.map +1 -0
  221. package/dist/tex/matrix.d.ts +31 -0
  222. package/dist/tex/matrix.d.ts.map +1 -0
  223. package/dist/tex/matrix.js +73 -0
  224. package/dist/tex/matrix.js.map +1 -0
  225. package/dist/tex/node.d.ts +215 -0
  226. package/dist/tex/node.d.ts.map +1 -0
  227. package/dist/tex/node.js +595 -0
  228. package/dist/tex/node.js.map +1 -0
  229. package/dist/tex/tween.d.ts +50 -0
  230. package/dist/tex/tween.d.ts.map +1 -0
  231. package/dist/tex/tween.js +253 -0
  232. package/dist/tex/tween.js.map +1 -0
  233. package/dist/three/axes3d.d.ts +87 -0
  234. package/dist/three/axes3d.d.ts.map +1 -0
  235. package/dist/three/axes3d.js +228 -0
  236. package/dist/three/axes3d.js.map +1 -0
  237. package/dist/three/curve-plot3d.d.ts +60 -0
  238. package/dist/three/curve-plot3d.d.ts.map +1 -0
  239. package/dist/three/curve-plot3d.js +143 -0
  240. package/dist/three/curve-plot3d.js.map +1 -0
  241. package/dist/three/label3d.d.ts +11 -0
  242. package/dist/three/label3d.d.ts.map +1 -0
  243. package/dist/three/label3d.js +40 -0
  244. package/dist/three/label3d.js.map +1 -0
  245. package/dist/three/plot-point3d.d.ts +26 -0
  246. package/dist/three/plot-point3d.d.ts.map +1 -0
  247. package/dist/three/plot-point3d.js +60 -0
  248. package/dist/three/plot-point3d.js.map +1 -0
  249. package/dist/three/space.d.ts +28 -0
  250. package/dist/three/space.d.ts.map +1 -0
  251. package/dist/three/space.js +47 -0
  252. package/dist/three/space.js.map +1 -0
  253. package/dist/three/surface-plot3d.d.ts +80 -0
  254. package/dist/three/surface-plot3d.d.ts.map +1 -0
  255. package/dist/three/surface-plot3d.js +290 -0
  256. package/dist/three/surface-plot3d.js.map +1 -0
  257. package/dist/three/vector-arrow3d.d.ts +25 -0
  258. package/dist/three/vector-arrow3d.d.ts.map +1 -0
  259. package/dist/three/vector-arrow3d.js +72 -0
  260. package/dist/three/vector-arrow3d.js.map +1 -0
  261. package/package.json +79 -3
  262. package/registry.json +251 -0
  263. package/src/annotate/angle-mark.ts +147 -0
  264. package/src/annotate/curly-brace.ts +126 -0
  265. package/src/annotate/emphasis-mark.ts +89 -0
  266. package/src/engine.ts +72 -0
  267. package/src/index.ts +29 -0
  268. package/src/kit/brace.ts +37 -0
  269. package/src/kit/cache.ts +61 -0
  270. package/src/kit/contour.ts +94 -0
  271. package/src/kit/coords.ts +278 -0
  272. package/src/kit/curve.ts +29 -0
  273. package/src/kit/equation.ts +181 -0
  274. package/src/kit/equation3d.ts +137 -0
  275. package/src/kit/expression.ts +159 -0
  276. package/src/kit/field-mark.ts +155 -0
  277. package/src/kit/field.ts +50 -0
  278. package/src/kit/follow.ts +203 -0
  279. package/src/kit/furniture.ts +108 -0
  280. package/src/kit/geometry.ts +49 -0
  281. package/src/kit/mark.ts +131 -0
  282. package/src/kit/part-fills.ts +61 -0
  283. package/src/kit/place.ts +101 -0
  284. package/src/kit/placement.ts +8 -0
  285. package/src/kit/sampler.ts +281 -0
  286. package/src/kit/scale.ts +39 -0
  287. package/src/kit/source.ts +57 -0
  288. package/src/kit/system.ts +99 -0
  289. package/src/kit/ticks.ts +85 -0
  290. package/src/kit/withdrawn.ts +8 -0
  291. package/src/marks/curve-area.ts +89 -0
  292. package/src/marks/drop-lines.ts +63 -0
  293. package/src/marks/plot-point.ts +107 -0
  294. package/src/marks/riemann-sum.ts +98 -0
  295. package/src/marks/tangent-line.ts +103 -0
  296. package/src/marks/vector-arrow.ts +98 -0
  297. package/src/nodes.ts +63 -0
  298. package/src/plots/function-plot.ts +236 -0
  299. package/src/plots/points-plot.ts +107 -0
  300. package/src/plots/stream-lines.ts +151 -0
  301. package/src/plots/traced-path.ts +52 -0
  302. package/src/plots/vector-field.ts +88 -0
  303. package/src/structures/graph-layout.ts +145 -0
  304. package/src/structures/network-graph.ts +308 -0
  305. package/src/structures/sample-space.ts +209 -0
  306. package/src/systems/axes2d.ts +217 -0
  307. package/src/systems/number-line.ts +131 -0
  308. package/src/systems/number-plane.ts +203 -0
  309. package/src/systems/polar-plane.ts +176 -0
  310. package/src/tex/geometry.ts +703 -0
  311. package/src/tex/index.ts +14 -0
  312. package/src/tex/mathjax.ts +82 -0
  313. package/src/tex/matrix.ts +75 -0
  314. package/src/tex/node.ts +641 -0
  315. package/src/tex/tween.ts +308 -0
  316. package/src/three/axes3d.ts +240 -0
  317. package/src/three/curve-plot3d.ts +147 -0
  318. package/src/three/label3d.ts +50 -0
  319. package/src/three/plot-point3d.ts +66 -0
  320. package/src/three/space.ts +67 -0
  321. package/src/three/surface-plot3d.ts +323 -0
  322. package/src/three/vector-arrow3d.ts +77 -0
@@ -0,0 +1,228 @@
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 { Canvas3D, colorProperty, command, Geo, Graphics3D, Mat, node, property, } from "@motionscript/sdk";
8
+ import { AXIS_COLOR, lerpInterval, readInterval } from "../kit/furniture.js";
9
+ import { clamp, stated } from "../kit/geometry.js";
10
+ import { formatTick, ticksFor } from "../kit/ticks.js";
11
+ import { drawLabel3D } from "./label3d.js";
12
+ import { graphSpace } from "./space.js";
13
+ /** How many pixels of a 2D axis one scene unit counts as, when an axis picks its own tick spacing. */
14
+ const UNIT_AS_PIXELS = 64;
15
+ /** The turn that lays a shape built along the scene's +y along each graph axis. */
16
+ const ALONG = { x: [90, 0, 0], y: [0, 0, -90], z: [0, 0, 0] };
17
+ /** The graph axis each axis's tick marks lie along. */
18
+ const TICK_ALONG = { x: "y", y: "x", z: "y" };
19
+ /**
20
+ * A 3D graph: three axes through a box of graph coordinates, z up, seen through
21
+ * a camera of its own, so it stands on a 2D stage as it is, the way `axes2d`
22
+ * does. Its 3D children sit in its graph coordinates: a surface, a space curve,
23
+ * a point, an arrow, or any 3D node. `orbitTo` swings the camera round it.
24
+ */
25
+ let Axes3d = class Axes3d extends Canvas3D {
26
+ constructor(props) {
27
+ super((props ?? {}));
28
+ }
29
+ /** Animate the window of values the axes show; everything drawn in them follows. */
30
+ rangeTo(args) {
31
+ return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });
32
+ }
33
+ declareAssets(assets) {
34
+ super.declareAssets(assets);
35
+ if (this.fontFamily !== "")
36
+ assets.font(this.fontFamily);
37
+ }
38
+ /** @internal */
39
+ _spaceOf() {
40
+ return this._graphSpace();
41
+ }
42
+ /** @internal */
43
+ _graphSpace() {
44
+ const { xRange, yRange, zRange, xLength, yLength, zLength } = this;
45
+ const key = [xRange, yRange, zRange, xLength, yLength, zLength].join("|");
46
+ if (key !== this._spaceKey) {
47
+ this._space = graphSpace(xRange, yRange, zRange, { x: xLength, y: yLength, z: zLength });
48
+ this._spaceKey = key;
49
+ }
50
+ return this._space;
51
+ }
52
+ buildScene3D() {
53
+ const scene = super.buildScene3D();
54
+ scene.draw(this._furniture());
55
+ return scene;
56
+ }
57
+ _space = null;
58
+ _spaceKey = "";
59
+ /** The axes, their ticks, numbers and titles, and the grid, in the scene's units. */
60
+ _furniture() {
61
+ const space = this._graphSpace();
62
+ const g3 = new Graphics3D();
63
+ const ranges = { x: space.xRange, y: space.yRange, z: space.zRange };
64
+ const lengths = { x: this.xLength, y: this.yLength, z: this.zLength };
65
+ const steps = { x: this.xStep, y: this.yStep, z: this.zStep };
66
+ const titles = { x: this.xLabel, y: this.yLabel, z: this.zLabel };
67
+ // Where each axis is crossed by the other two: their zero, or the nearest end of a range without one.
68
+ const cross = {
69
+ x: clamp(0, ranges.x[0], ranges.x[1]),
70
+ y: clamp(0, ranges.y[0], ranges.y[1]),
71
+ z: clamp(0, ranges.z[0], ranges.z[1]),
72
+ };
73
+ const at = (axis, value, shift = {}) => {
74
+ const point = { ...cross, [axis]: value };
75
+ const local = space.toLocal(point.x, point.y, point.z);
76
+ const moved = space.offset(0, 0, 0);
77
+ for (const key of ["x", "y", "z"]) {
78
+ const by = shift[key];
79
+ if (by === undefined)
80
+ continue;
81
+ // A shift is in scene units, along the graph axis it names.
82
+ if (key === "x")
83
+ moved.z += by;
84
+ else if (key === "y")
85
+ moved.x += by;
86
+ else
87
+ moved.y += by;
88
+ }
89
+ return { x: local.x + moved.x, y: local.y + moved.y, z: local.z + moved.z };
90
+ };
91
+ const { thickness, tickSize } = this;
92
+ const paint = Mat.basic({ color: this.color });
93
+ const style = { size: this.labelSize, color: this.labelColor, fontFamily: this.fontFamily };
94
+ const tipLength = this.tips ? thickness * 9 : 0;
95
+ const marks = [];
96
+ const plane = [];
97
+ for (const axis of ["x", "y", "z"]) {
98
+ const [min, max] = ranges[axis];
99
+ const length = lengths[axis];
100
+ if (!(max > min) || !(length > 0))
101
+ continue;
102
+ if (thickness > 0) {
103
+ const from = at(axis, min);
104
+ const to = at(axis, max);
105
+ g3.mesh(Geo.cylinder({ radius: thickness, height: length, segments: [12, 1] }), paint, {
106
+ position: { x: (from.x + to.x) / 2, y: (from.y + to.y) / 2, z: (from.z + to.z) / 2 },
107
+ rotation: ALONG[axis],
108
+ });
109
+ if (this.tips) {
110
+ g3.mesh(Geo.cone({ radius: thickness * 3.2, height: tipLength, segments: [16, 1] }), paint, {
111
+ position: at(axis, max, { [axis]: tipLength / 2 }),
112
+ rotation: ALONG[axis],
113
+ });
114
+ }
115
+ }
116
+ const ticks = ticksFor(ranges[axis], steps[axis], length * UNIT_AS_PIXELS);
117
+ const side = TICK_ALONG[axis];
118
+ for (const value of ticks.values) {
119
+ // The crossing is marked by the other axes, and the far end by the tip.
120
+ if (Math.abs(value - cross[axis]) < 1e-9 || (this.tips && Math.abs(value - max) < 1e-9))
121
+ continue;
122
+ if (this.ticks && tickSize > 0)
123
+ marks.push({ position: at(axis, value), rotation: ALONG[side] });
124
+ if (this.labels) {
125
+ drawLabel3D(g3, formatTick(value, ticks.step), at(axis, value, { [side]: -(tickSize / 2 + style.size * 0.8) }), style);
126
+ }
127
+ }
128
+ drawLabel3D(g3, titles[axis], at(axis, max, { [axis]: tipLength + style.size * 0.9 }), style);
129
+ if (this.grid && axis !== "z") {
130
+ const other = axis === "x" ? "y" : "x";
131
+ for (const value of ticks.values) {
132
+ const a = { x: 0, y: 0, z: cross.z, [axis]: value, [other]: ranges[other][0] };
133
+ const b = { ...a, [other]: ranges[other][1] };
134
+ plane.push(space.toLocal(a.x, a.y, a.z), space.toLocal(b.x, b.y, b.z));
135
+ }
136
+ }
137
+ }
138
+ if (marks.length > 0) {
139
+ g3.instances(Geo.cylinder({ radius: Math.max(thickness * 0.7, 0.008), height: tickSize, segments: [8, 1] }), paint, marks);
140
+ }
141
+ if (plane.length > 0)
142
+ g3.line({ points: plane, segments: true, stroke: { fill: this.gridLineColor } });
143
+ return g3;
144
+ }
145
+ };
146
+ __decorate([
147
+ property({ default: [-3, 3], mapper: readInterval, tween: lerpInterval })
148
+ ], Axes3d.prototype, "xRange", void 0);
149
+ __decorate([
150
+ property({ default: [-3, 3], mapper: readInterval, tween: lerpInterval })
151
+ ], Axes3d.prototype, "yRange", void 0);
152
+ __decorate([
153
+ property({ default: [-2, 2], mapper: readInterval, tween: lerpInterval })
154
+ ], Axes3d.prototype, "zRange", void 0);
155
+ __decorate([
156
+ property({ default: 6, min: 0.01, step: 0.1 })
157
+ ], Axes3d.prototype, "xLength", void 0);
158
+ __decorate([
159
+ property({ default: 6, min: 0.01, step: 0.1 })
160
+ ], Axes3d.prototype, "yLength", void 0);
161
+ __decorate([
162
+ property({ default: 4, min: 0.01, step: 0.1 })
163
+ ], Axes3d.prototype, "zLength", void 0);
164
+ __decorate([
165
+ property({ default: 0, min: 0 })
166
+ ], Axes3d.prototype, "xStep", void 0);
167
+ __decorate([
168
+ property({ default: 0, min: 0 })
169
+ ], Axes3d.prototype, "yStep", void 0);
170
+ __decorate([
171
+ property({ default: 0, min: 0 })
172
+ ], Axes3d.prototype, "zStep", void 0);
173
+ __decorate([
174
+ colorProperty({ default: AXIS_COLOR })
175
+ ], Axes3d.prototype, "color", void 0);
176
+ __decorate([
177
+ property({ default: 0.02, min: 0, step: 0.005 })
178
+ ], Axes3d.prototype, "thickness", void 0);
179
+ __decorate([
180
+ property({ default: true, animatable: false })
181
+ ], Axes3d.prototype, "tips", void 0);
182
+ __decorate([
183
+ property({ default: true, animatable: false })
184
+ ], Axes3d.prototype, "ticks", void 0);
185
+ __decorate([
186
+ property({ default: 0.16, min: 0, step: 0.01 })
187
+ ], Axes3d.prototype, "tickSize", void 0);
188
+ __decorate([
189
+ property({ default: false, animatable: false })
190
+ ], Axes3d.prototype, "grid", void 0);
191
+ __decorate([
192
+ colorProperty({ default: "#374151" })
193
+ ], Axes3d.prototype, "gridLineColor", void 0);
194
+ __decorate([
195
+ property({ default: false, animatable: false })
196
+ ], Axes3d.prototype, "labels", void 0);
197
+ __decorate([
198
+ property({ default: 0.26, min: 0.01, step: 0.01 })
199
+ ], Axes3d.prototype, "labelSize", void 0);
200
+ __decorate([
201
+ colorProperty({ default: AXIS_COLOR })
202
+ ], Axes3d.prototype, "labelColor", void 0);
203
+ __decorate([
204
+ property({ default: "", animatable: false })
205
+ ], Axes3d.prototype, "fontFamily", void 0);
206
+ __decorate([
207
+ property({ default: "x", animatable: false })
208
+ ], Axes3d.prototype, "xLabel", void 0);
209
+ __decorate([
210
+ property({ default: "y", animatable: false })
211
+ ], Axes3d.prototype, "yLabel", void 0);
212
+ __decorate([
213
+ property({ default: "z", animatable: false })
214
+ ], Axes3d.prototype, "zLabel", void 0);
215
+ __decorate([
216
+ command({ args: ["xRange", "yRange", "zRange"] })
217
+ ], Axes3d.prototype, "rangeTo", null);
218
+ Axes3d = __decorate([
219
+ node({
220
+ key: "axes3d",
221
+ parentKey: "canvas3d",
222
+ forkable: true,
223
+ layout: { defaultWidthMode: "fixed", defaultHeightMode: "fixed", acceptsChildren: true },
224
+ seed: { width: 800, height: 500 },
225
+ })
226
+ ], Axes3d);
227
+ export { Axes3d };
228
+ //# sourceMappingURL=axes3d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"axes3d.js","sourceRoot":"","sources":["../../src/three/axes3d.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,QAAQ,EACR,aAAa,EACb,OAAO,EACP,GAAG,EACH,UAAU,EACV,GAAG,EACH,IAAI,EACJ,QAAQ,GAWX,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,WAAW,EAAqB,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAmB,MAAM,SAAS,C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AAC;sCAAwB;AAQtE;IADC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,CAAC;qCAGjD;AA9CQ,MAAM;IAPlB,IAAI,CAAC;QACF,GAAG,EAAE,QAAQ;QACb,SAAS,EAAE,UAAU;QACrB,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,EAAE,gBAAgB,EAAE,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE;QACxF,IAAI,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE;KACpC,CAAC;GACW,MAAM,CAkKlB","sourcesContent":["import {\r\n Canvas3D,\r\n colorProperty,\r\n command,\r\n Geo,\r\n Graphics3D,\r\n Mat,\r\n node,\r\n property,\r\n type AssetScope,\r\n type Canvas3DProps,\r\n type Color,\r\n type Command,\r\n type CommandArgs,\r\n type NodeConfig,\r\n type Scene3D,\r\n type Transform3D,\r\n type Vector3,\r\n type Vector3Input,\r\n} from \"@motionscript/sdk\";\r\nimport type { Interval } from \"../kit/coords\";\r\nimport { AXIS_COLOR, lerpInterval, readInterval } from \"../kit/furniture\";\r\nimport { clamp, stated } from \"../kit/geometry\";\r\nimport { formatTick, ticksFor } from \"../kit/ticks\";\r\nimport { drawLabel3D, type LabelStyle3D } from \"./label3d\";\r\nimport { graphSpace, type GraphSpace } from \"./space\";\r\n\r\nexport interface Axes3dProps extends Canvas3DProps {\r\n xRange?: Interval;\r\n yRange?: Interval;\r\n zRange?: Interval;\r\n xLength?: number;\r\n yLength?: number;\r\n zLength?: number;\r\n xStep?: number;\r\n yStep?: number;\r\n zStep?: number;\r\n color?: Color;\r\n thickness?: number;\r\n tips?: boolean;\r\n ticks?: boolean;\r\n tickSize?: number;\r\n grid?: boolean;\r\n gridLineColor?: Color;\r\n labels?: boolean;\r\n labelSize?: number;\r\n labelColor?: Color;\r\n fontFamily?: string;\r\n xLabel?: string;\r\n yLabel?: string;\r\n zLabel?: string;\r\n}\r\n\r\n/** How many pixels of a 2D axis one scene unit counts as, when an axis picks its own tick spacing. */\r\nconst UNIT_AS_PIXELS = 64;\r\n\r\ntype AxisName = \"x\" | \"y\" | \"z\";\r\n\r\n/** The turn that lays a shape built along the scene's +y along each graph axis. */\r\nconst ALONG: Record<AxisName, Vector3Input> = { x: [90, 0, 0], y: [0, 0, -90], z: [0, 0, 0] };\r\n\r\n/** The graph axis each axis's tick marks lie along. */\r\nconst TICK_ALONG: Record<AxisName, AxisName> = { x: \"y\", y: \"x\", z: \"y\" };\r\n\r\n/**\r\n * A 3D graph: three axes through a box of graph coordinates, z up, seen through\r\n * a camera of its own, so it stands on a 2D stage as it is, the way `axes2d`\r\n * does. Its 3D children sit in its graph coordinates: a surface, a space curve,\r\n * a point, an arrow, or any 3D node. `orbitTo` swings the camera round it.\r\n */\r\n@node({\r\n key: \"axes3d\",\r\n parentKey: \"canvas3d\",\r\n forkable: true,\r\n layout: { defaultWidthMode: \"fixed\", defaultHeightMode: \"fixed\", acceptsChildren: true },\r\n seed: { width: 800, height: 500 },\r\n})\r\nexport class Axes3d<P extends Axes3dProps = Axes3dProps> extends Canvas3D<P> {\r\n @property({ default: [-3, 3], mapper: readInterval, tween: lerpInterval }) declare xRange: Interval;\r\n @property({ default: [-3, 3], mapper: readInterval, tween: lerpInterval }) declare yRange: Interval;\r\n @property({ default: [-2, 2], mapper: readInterval, tween: lerpInterval }) declare zRange: Interval;\r\n\r\n /** How long each axis is drawn, in scene units. */\r\n @property({ default: 6, min: 0.01, step: 0.1 }) declare xLength: number;\r\n @property({ default: 6, min: 0.01, step: 0.1 }) declare yLength: number;\r\n @property({ default: 4, min: 0.01, step: 0.1 }) declare zLength: number;\r\n\r\n /** The spacing of each axis's ticks; zero picks a tidy one for the axis's length. */\r\n @property({ default: 0, min: 0 }) declare xStep: number;\r\n @property({ default: 0, min: 0 }) declare yStep: number;\r\n @property({ default: 0, min: 0 }) declare zStep: number;\r\n\r\n @colorProperty({ default: AXIS_COLOR }) declare color: Color;\r\n /** The radius of an axis line, in scene units. */\r\n @property({ default: 0.02, min: 0, step: 0.005 }) declare thickness: number;\r\n @property({ default: true, animatable: false }) declare tips: boolean;\r\n @property({ default: true, animatable: false }) declare ticks: boolean;\r\n @property({ default: 0.16, min: 0, step: 0.01 }) declare tickSize: number;\r\n\r\n /** Lines across the plane the x and y axes lie in, at each of their ticks. */\r\n @property({ default: false, animatable: false }) declare grid: boolean;\r\n /** (`gridColor` is the viewport's own reference grid.) */\r\n @colorProperty({ default: \"#374151\" }) declare gridLineColor: Color;\r\n\r\n /** A number at each tick. */\r\n @property({ default: false, animatable: false }) declare labels: boolean;\r\n /** The height of a label's text, in scene units. */\r\n @property({ default: 0.26, min: 0.01, step: 0.01 }) declare labelSize: number;\r\n @colorProperty({ default: AXIS_COLOR }) declare labelColor: Color;\r\n @property({ default: \"\", animatable: false }) declare fontFamily: string;\r\n /** A title at the positive end of each axis. */\r\n @property({ default: \"x\", animatable: false }) declare xLabel: string;\r\n @property({ default: \"y\", animatable: false }) declare yLabel: string;\r\n @property({ default: \"z\", animatable: false }) declare zLabel: string;\r\n\r\n constructor(props?: NodeConfig<Axes3d<P>, P>) {\r\n super((props ?? {}) as NodeConfig<Canvas3D<P>, P>);\r\n }\r\n\r\n /** Animate the window of values the axes show; everything drawn in them follows. */\r\n @command({ args: [\"xRange\", \"yRange\", \"zRange\"] })\r\n rangeTo(args: CommandArgs<{ xRange?: Interval; yRange?: Interval; zRange?: Interval }> & { duration: number }): Command<P> {\r\n return this.to({ data: stated(args.data) as Partial<P>, duration: args.duration, easing: args.easing });\r\n }\r\n\r\n override declareAssets(assets: AssetScope): void {\r\n super.declareAssets(assets);\r\n if (this.fontFamily !== \"\") assets.font(this.fontFamily);\r\n }\r\n\r\n /** @internal */\r\n override _spaceOf(): GraphSpace {\r\n return this._graphSpace();\r\n }\r\n\r\n /** @internal */\r\n _graphSpace(): GraphSpace {\r\n const { xRange, yRange, zRange, xLength, yLength, zLength } = this;\r\n const key = [xRange, yRange, zRange, xLength, yLength, zLength].join(\"|\");\r\n if (key !== this._spaceKey) {\r\n this._space = graphSpace(xRange, yRange, zRange, { x: xLength, y: yLength, z: zLength });\r\n this._spaceKey = key;\r\n }\r\n return this._space!;\r\n }\r\n\r\n protected override buildScene3D(): Scene3D {\r\n const scene = super.buildScene3D();\r\n scene.draw(this._furniture());\r\n return scene;\r\n }\r\n\r\n private _space: GraphSpace | null = null;\r\n private _spaceKey = \"\";\r\n\r\n /** The axes, their ticks, numbers and titles, and the grid, in the scene's units. */\r\n private _furniture(): Graphics3D {\r\n const space = this._graphSpace();\r\n const g3 = new Graphics3D();\r\n const ranges: Record<AxisName, Interval> = { x: space.xRange, y: space.yRange, z: space.zRange };\r\n const lengths: Record<AxisName, number> = { x: this.xLength, y: this.yLength, z: this.zLength };\r\n const steps: Record<AxisName, number> = { x: this.xStep, y: this.yStep, z: this.zStep };\r\n const titles: Record<AxisName, string> = { x: this.xLabel, y: this.yLabel, z: this.zLabel };\r\n // Where each axis is crossed by the other two: their zero, or the nearest end of a range without one.\r\n const cross: Record<AxisName, number> = {\r\n x: clamp(0, ranges.x[0], ranges.x[1]),\r\n y: clamp(0, ranges.y[0], ranges.y[1]),\r\n z: clamp(0, ranges.z[0], ranges.z[1]),\r\n };\r\n const at = (axis: AxisName, value: number, shift: Partial<Record<AxisName, number>> = {}): Vector3 => {\r\n const point = { ...cross, [axis]: value };\r\n const local = space.toLocal(point.x, point.y, point.z);\r\n const moved = space.offset(0, 0, 0);\r\n for (const key of [\"x\", \"y\", \"z\"] as const) {\r\n const by = shift[key];\r\n if (by === undefined) continue;\r\n // A shift is in scene units, along the graph axis it names.\r\n if (key === \"x\") moved.z += by;\r\n else if (key === \"y\") moved.x += by;\r\n else moved.y += by;\r\n }\r\n return { x: local.x + moved.x, y: local.y + moved.y, z: local.z + moved.z };\r\n };\r\n\r\n const { thickness, tickSize } = this;\r\n const paint = Mat.basic({ color: this.color });\r\n const style: LabelStyle3D = { size: this.labelSize, color: this.labelColor, fontFamily: this.fontFamily };\r\n const tipLength = this.tips ? thickness * 9 : 0;\r\n const marks: Transform3D[] = [];\r\n const plane: Vector3[] = [];\r\n\r\n for (const axis of [\"x\", \"y\", \"z\"] as const) {\r\n const [min, max] = ranges[axis];\r\n const length = lengths[axis];\r\n if (!(max > min) || !(length > 0)) continue;\r\n\r\n if (thickness > 0) {\r\n const from = at(axis, min);\r\n const to = at(axis, max);\r\n g3.mesh(Geo.cylinder({ radius: thickness, height: length, segments: [12, 1] }), paint, {\r\n position: { x: (from.x + to.x) / 2, y: (from.y + to.y) / 2, z: (from.z + to.z) / 2 },\r\n rotation: ALONG[axis],\r\n });\r\n if (this.tips) {\r\n g3.mesh(Geo.cone({ radius: thickness * 3.2, height: tipLength, segments: [16, 1] }), paint, {\r\n position: at(axis, max, { [axis]: tipLength / 2 }),\r\n rotation: ALONG[axis],\r\n });\r\n }\r\n }\r\n\r\n const ticks = ticksFor(ranges[axis], steps[axis], length * UNIT_AS_PIXELS);\r\n const side = TICK_ALONG[axis];\r\n for (const value of ticks.values) {\r\n // The crossing is marked by the other axes, and the far end by the tip.\r\n if (Math.abs(value - cross[axis]) < 1e-9 || (this.tips && Math.abs(value - max) < 1e-9)) continue;\r\n if (this.ticks && tickSize > 0) marks.push({ position: at(axis, value), rotation: ALONG[side] });\r\n if (this.labels) {\r\n drawLabel3D(g3, formatTick(value, ticks.step), at(axis, value, { [side]: -(tickSize / 2 + style.size * 0.8) }), style);\r\n }\r\n }\r\n drawLabel3D(g3, titles[axis], at(axis, max, { [axis]: tipLength + style.size * 0.9 }), style);\r\n\r\n if (this.grid && axis !== \"z\") {\r\n const other = axis === \"x\" ? \"y\" : \"x\";\r\n for (const value of ticks.values) {\r\n const a = { x: 0, y: 0, z: cross.z, [axis]: value, [other]: ranges[other][0] };\r\n const b = { ...a, [other]: ranges[other][1] };\r\n plane.push(space.toLocal(a.x, a.y, a.z), space.toLocal(b.x, b.y, b.z));\r\n }\r\n }\r\n }\r\n\r\n if (marks.length > 0) {\r\n g3.instances(Geo.cylinder({ radius: Math.max(thickness * 0.7, 0.008), height: tickSize, segments: [8, 1] }), paint, marks);\r\n }\r\n if (plane.length > 0) g3.line({ points: plane, segments: true, stroke: { fill: this.gridLineColor } });\r\n return g3;\r\n }\r\n}\r\n"]}
@@ -0,0 +1,60 @@
1
+ import { Mesh3D, type Command, type CommandArgs, type Geometry3D, type Mesh3DProps, type NodeConfig } from "@motionscript/sdk";
2
+ import type { Interval } from "../kit/coords.js";
3
+ import type { ExpressionScope } from "../kit/expression.js";
4
+ import { type PlotSource } from "../kit/source.js";
5
+ export interface CurvePlot3dProps extends Mesh3DProps {
6
+ expression?: string | PlotSource;
7
+ domain?: Interval | null;
8
+ params?: ExpressionScope;
9
+ samples?: number;
10
+ thickness?: number;
11
+ start?: number;
12
+ end?: number;
13
+ }
14
+ /** A curve through a 3D graph, three parts in `t`: `(cos(t), sin(t), t / 4)`. */
15
+ export declare class CurvePlot3d extends Mesh3D<CurvePlot3dProps> {
16
+ expression: PlotSource;
17
+ /** The span of `t` that is drawn; 0 to 1 when left out. */
18
+ domain: Interval | null;
19
+ params: ExpressionScope;
20
+ /** How many points the curve is drawn through. */
21
+ samples: number;
22
+ /** The radius of the line, in scene units. */
23
+ thickness: number;
24
+ /** The part of the curve that is drawn, as shares of its length in `t`. */
25
+ start: number;
26
+ end: number;
27
+ constructor(props?: NodeConfig<CurvePlot3d, CurvePlot3dProps>);
28
+ /** Change the equation, the curve bending from the one into the other. */
29
+ morphTo(args: CommandArgs<{
30
+ expression: string;
31
+ }> & {
32
+ duration: number;
33
+ }): Command<CurvePlot3dProps>;
34
+ /** Animate the equation's named values. */
35
+ paramsTo(args: CommandArgs<{
36
+ params: ExpressionScope;
37
+ }> & {
38
+ duration: number;
39
+ }): Command<CurvePlot3dProps>;
40
+ /** Animate the span of `t` that is drawn. */
41
+ domainTo(args: CommandArgs<{
42
+ domain: Interval | null;
43
+ }> & {
44
+ duration: number;
45
+ }): Command<CurvePlot3dProps>;
46
+ /** Draw the curve on, or wipe it off: animates `start` and `end`. */
47
+ progressTo(args: CommandArgs<{
48
+ start?: number;
49
+ end?: number;
50
+ }> & {
51
+ duration: number;
52
+ }): Command<CurvePlot3dProps>;
53
+ protected buildGeometry(): Geometry3D | undefined;
54
+ private _key;
55
+ private _run;
56
+ private _points;
57
+ /** `source` as a graph point for a share `u` of its span, or `false` where it has none. */
58
+ private _curve;
59
+ }
60
+ //# sourceMappingURL=curve-plot3d.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"curve-plot3d.d.ts","sourceRoot":"","sources":["../../src/three/curve-plot3d.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,MAAM,EAGN,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,UAAU,EAElB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGzD,OAAO,EAA4D,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAG1G,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACjD,UAAU,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IACjC,MAAM,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;IACzB,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,iFAAiF;AACjF,qBAOa,WAAY,SAAQ,MAAM,CAAC,gBAAgB,CAAC;IAE7C,UAAU,EAAE,UAAU,CAAC;IAE/B,2DAA2D;IAC0C,MAAM,EAAE,QAAQ,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,143 @@
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, Geo, Mesh3D, node, property, } from "@motionscript/sdk";
8
+ import { parseSpaceCurve, spaceCurveParams } from "../kit/equation3d.js";
9
+ import { PLOT_COLOR } from "../kit/furniture.js";
10
+ import { clamp, stated } from "../kit/geometry.js";
11
+ import { lerpDomain, lerpParams, lerpSource, readSource, scopeFor } from "../kit/source.js";
12
+ import { spaceOf } from "./space.js";
13
+ /** A curve through a 3D graph, three parts in `t`: `(cos(t), sin(t), t / 4)`. */
14
+ let CurvePlot3d = class CurvePlot3d extends Mesh3D {
15
+ constructor(props) {
16
+ super(props ?? {});
17
+ if (props?.fill === undefined)
18
+ this.applyProp("fill", PLOT_COLOR);
19
+ }
20
+ /** Change the equation, the curve bending from the one into the other. */
21
+ morphTo(args) {
22
+ return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });
23
+ }
24
+ /** Animate the equation's named values. */
25
+ paramsTo(args) {
26
+ return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });
27
+ }
28
+ /** Animate the span of `t` that is drawn. */
29
+ domainTo(args) {
30
+ return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });
31
+ }
32
+ /** Draw the curve on, or wipe it off: animates `start` and `end`. */
33
+ progressTo(args) {
34
+ return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });
35
+ }
36
+ buildGeometry() {
37
+ const space = spaceOf(this);
38
+ if (!space)
39
+ return undefined;
40
+ const points = this._points(space);
41
+ if (points.length < 2)
42
+ return undefined;
43
+ return Geo.tube({ points, radius: this.thickness, segments: [points.length - 1, 8] });
44
+ }
45
+ _key = "";
46
+ _run = [];
47
+ _points(space) {
48
+ const { source, blend } = this.expression;
49
+ const start = clamp(this.start, 0, 1);
50
+ const end = clamp(this.end, 0, 1);
51
+ const samples = Math.max(2, Math.round(this.samples));
52
+ const key = [source, blend?.from, blend?.t, space.revision, this.domain, JSON.stringify(this.params), start, end, samples].join("|");
53
+ if (key === this._key)
54
+ return this._run;
55
+ this._key = key;
56
+ this._run = [];
57
+ const to = this._curve(source);
58
+ if (!to || !(end > start))
59
+ return this._run;
60
+ const from = blend ? this._curve(blend.from) : null;
61
+ const steps = Math.max(1, Math.round(samples * (end - start)));
62
+ const a = { x: 0, y: 0, z: 0 };
63
+ const b = { x: 0, y: 0, z: 0 };
64
+ for (let i = 0; i <= steps; i++) {
65
+ const u = start + ((end - start) * i) / steps;
66
+ if (!to(u, b))
67
+ continue;
68
+ if (from && blend) {
69
+ if (!from(u, a))
70
+ continue;
71
+ b.x = a.x + (b.x - a.x) * blend.t;
72
+ b.y = a.y + (b.y - a.y) * blend.t;
73
+ b.z = a.z + (b.z - a.z) * blend.t;
74
+ }
75
+ this._run.push(space.offset(b.x, b.y, b.z));
76
+ }
77
+ return this._run;
78
+ }
79
+ /** `source` as a graph point for a share `u` of its span, or `false` where it has none. */
80
+ _curve(source) {
81
+ const equation = equationOf(source);
82
+ if (!equation)
83
+ return null;
84
+ const params = scopeFor(spaceCurveParams(source), this.params);
85
+ const [t0, t1] = this.domain ?? [0, 1];
86
+ const { x, y, z } = equation;
87
+ return (u, out) => {
88
+ const t = t0 + (t1 - t0) * u;
89
+ out.x = x(t, 0, params);
90
+ out.y = y(t, 0, params);
91
+ out.z = z(t, 0, params);
92
+ return Number.isFinite(out.x) && Number.isFinite(out.y) && Number.isFinite(out.z);
93
+ };
94
+ }
95
+ };
96
+ __decorate([
97
+ property({ default: "", mapper: readSource, tween: lerpSource, kind: "spaceCurveEquation" })
98
+ ], CurvePlot3d.prototype, "expression", void 0);
99
+ __decorate([
100
+ property({ default: null, tween: lerpDomain, kind: "range", defaultMin: 0, defaultMax: 1 })
101
+ ], CurvePlot3d.prototype, "domain", void 0);
102
+ __decorate([
103
+ property({ default: {}, tween: lerpParams })
104
+ ], CurvePlot3d.prototype, "params", void 0);
105
+ __decorate([
106
+ property({ default: 160, min: 2, max: 2000, step: 1, animatable: false })
107
+ ], CurvePlot3d.prototype, "samples", void 0);
108
+ __decorate([
109
+ property({ default: 0.04, min: 0.001, step: 0.005 })
110
+ ], CurvePlot3d.prototype, "thickness", void 0);
111
+ __decorate([
112
+ property({ default: 0, min: 0, max: 1, step: 0.01 })
113
+ ], CurvePlot3d.prototype, "start", void 0);
114
+ __decorate([
115
+ property({ default: 1, min: 0, max: 1, step: 0.01 })
116
+ ], CurvePlot3d.prototype, "end", void 0);
117
+ __decorate([
118
+ command({ args: ["expression"] })
119
+ ], CurvePlot3d.prototype, "morphTo", null);
120
+ __decorate([
121
+ command({ args: ["params"] })
122
+ ], CurvePlot3d.prototype, "paramsTo", null);
123
+ __decorate([
124
+ command({ args: ["domain"] })
125
+ ], CurvePlot3d.prototype, "domainTo", null);
126
+ __decorate([
127
+ command({ args: ["start", "end"] })
128
+ ], CurvePlot3d.prototype, "progressTo", null);
129
+ CurvePlot3d = __decorate([
130
+ node({
131
+ key: "curvePlot3d",
132
+ within: ["axes3d"],
133
+ forkable: true,
134
+ layout: { acceptsChildren: false },
135
+ seed: { expression: "(2cos(t), 2sin(t), t / 4)", domain: [-6.28, 6.28], fill: PLOT_COLOR },
136
+ })
137
+ ], CurvePlot3d);
138
+ export { CurvePlot3d };
139
+ function equationOf(source) {
140
+ const equation = parseSpaceCurve(source, spaceCurveParams(source));
141
+ return equation instanceof Error ? null : equation;
142
+ }
143
+ //# sourceMappingURL=curve-plot3d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"curve-plot3d.js","sourceRoot":"","sources":["../../src/three/curve-plot3d.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MAAM,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC;IACnE,OAAO,QAAQ,YAAY,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC;AACvD,CAAC","sourcesContent":["import {\r\n command,\r\n Geo,\r\n Mesh3D,\r\n node,\r\n property,\r\n type Command,\r\n type CommandArgs,\r\n type Geometry3D,\r\n type Mesh3DProps,\r\n type NodeConfig,\r\n type Vector3,\r\n} from \"@motionscript/sdk\";\r\nimport type { Interval } from \"../kit/coords\";\r\nimport { parseSpaceCurve, spaceCurveParams, type SpaceCurveEquation } from \"../kit/equation3d\";\r\nimport type { ExpressionScope } from \"../kit/expression\";\r\nimport { PLOT_COLOR } from \"../kit/furniture\";\r\nimport { clamp, stated } from \"../kit/geometry\";\r\nimport { lerpDomain, lerpParams, lerpSource, readSource, scopeFor, type PlotSource } from \"../kit/source\";\r\nimport { spaceOf, type GraphSpace } from \"./space\";\r\n\r\nexport interface CurvePlot3dProps extends Mesh3DProps {\r\n expression?: string | PlotSource;\r\n domain?: Interval | null;\r\n params?: ExpressionScope;\r\n samples?: number;\r\n thickness?: number;\r\n start?: number;\r\n end?: number;\r\n}\r\n\r\n/** A curve through a 3D graph, three parts in `t`: `(cos(t), sin(t), t / 4)`. */\r\n@node({\r\n key: \"curvePlot3d\",\r\n within: [\"axes3d\"],\r\n forkable: true,\r\n layout: { acceptsChildren: false },\r\n seed: { expression: \"(2cos(t), 2sin(t), t / 4)\", domain: [-6.28, 6.28], fill: PLOT_COLOR },\r\n})\r\nexport class CurvePlot3d extends Mesh3D<CurvePlot3dProps> {\r\n @property({ default: \"\", mapper: readSource, tween: lerpSource, kind: \"spaceCurveEquation\" })\r\n declare expression: PlotSource;\r\n\r\n /** The span of `t` that is drawn; 0 to 1 when left out. */\r\n @property({ default: null, tween: lerpDomain, kind: \"range\", defaultMin: 0, defaultMax: 1 }) declare domain: Interval | null;\r\n\r\n @property({ default: {}, tween: lerpParams }) declare params: ExpressionScope;\r\n\r\n /** How many points the curve is drawn through. */\r\n @property({ default: 160, min: 2, max: 2000, step: 1, animatable: false }) declare samples: number;\r\n /** The radius of the line, in scene units. */\r\n @property({ default: 0.04, min: 0.001, step: 0.005 }) declare thickness: number;\r\n\r\n /** The part of the curve that is drawn, as shares of its length in `t`. */\r\n @property({ default: 0, min: 0, max: 1, step: 0.01 }) declare start: number;\r\n @property({ default: 1, min: 0, max: 1, step: 0.01 }) declare end: number;\r\n\r\n constructor(props?: NodeConfig<CurvePlot3d, CurvePlot3dProps>) {\r\n super(props ?? {});\r\n if (props?.fill === undefined) this.applyProp(\"fill\", PLOT_COLOR);\r\n }\r\n\r\n /** Change the equation, the curve bending from the one into the other. */\r\n @command({ args: [\"expression\"] })\r\n morphTo(args: CommandArgs<{ expression: string }> & { duration: number }): Command<CurvePlot3dProps> {\r\n return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });\r\n }\r\n\r\n /** Animate the equation's named values. */\r\n @command({ args: [\"params\"] })\r\n paramsTo(args: CommandArgs<{ params: ExpressionScope }> & { duration: number }): Command<CurvePlot3dProps> {\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 `t` that is drawn. */\r\n @command({ args: [\"domain\"] })\r\n domainTo(args: CommandArgs<{ domain: Interval | null }> & { duration: number }): Command<CurvePlot3dProps> {\r\n return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });\r\n }\r\n\r\n /** Draw the curve on, or wipe it off: animates `start` and `end`. */\r\n @command({ args: [\"start\", \"end\"] })\r\n progressTo(args: CommandArgs<{ start?: number; end?: number }> & { duration: number }): Command<CurvePlot3dProps> {\r\n return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });\r\n }\r\n\r\n protected override buildGeometry(): Geometry3D | undefined {\r\n const space = spaceOf(this);\r\n if (!space) return undefined;\r\n const points = this._points(space);\r\n if (points.length < 2) return undefined;\r\n return Geo.tube({ points, radius: this.thickness, segments: [points.length - 1, 8] });\r\n }\r\n\r\n private _key = \"\";\r\n private _run: Vector3[] = [];\r\n\r\n private _points(space: GraphSpace): Vector3[] {\r\n const { source, blend } = this.expression;\r\n const start = clamp(this.start, 0, 1);\r\n const end = clamp(this.end, 0, 1);\r\n const samples = Math.max(2, Math.round(this.samples));\r\n const key = [source, blend?.from, blend?.t, space.revision, this.domain, JSON.stringify(this.params), start, end, samples].join(\"|\");\r\n if (key === this._key) return this._run;\r\n this._key = key;\r\n this._run = [];\r\n const to = this._curve(source);\r\n if (!to || !(end > start)) return this._run;\r\n const from = blend ? this._curve(blend.from) : null;\r\n const steps = Math.max(1, Math.round(samples * (end - start)));\r\n const a: Vector3 = { x: 0, y: 0, z: 0 };\r\n const b: Vector3 = { x: 0, y: 0, z: 0 };\r\n for (let i = 0; i <= steps; i++) {\r\n const u = start + ((end - start) * i) / steps;\r\n if (!to(u, b)) continue;\r\n if (from && blend) {\r\n if (!from(u, a)) continue;\r\n b.x = a.x + (b.x - a.x) * blend.t;\r\n b.y = a.y + (b.y - a.y) * blend.t;\r\n b.z = a.z + (b.z - a.z) * blend.t;\r\n }\r\n this._run.push(space.offset(b.x, b.y, b.z));\r\n }\r\n return this._run;\r\n }\r\n\r\n /** `source` as a graph point for a share `u` of its span, or `false` where it has none. */\r\n private _curve(source: string): ((u: number, out: Vector3) => boolean) | null {\r\n const equation = equationOf(source);\r\n if (!equation) return null;\r\n const params = scopeFor(spaceCurveParams(source), this.params);\r\n const [t0, t1] = this.domain ?? [0, 1];\r\n const { x, y, z } = equation;\r\n return (u, out) => {\r\n const t = t0 + (t1 - t0) * u;\r\n out.x = x(t, 0, params);\r\n out.y = y(t, 0, params);\r\n out.z = z(t, 0, params);\r\n return Number.isFinite(out.x) && Number.isFinite(out.y) && Number.isFinite(out.z);\r\n };\r\n }\r\n}\r\n\r\nfunction equationOf(source: string): SpaceCurveEquation | null {\r\n const equation = parseSpaceCurve(source, spaceCurveParams(source));\r\n return equation instanceof Error ? null : equation;\r\n}\r\n"]}
@@ -0,0 +1,11 @@
1
+ import { type Color, type Graphics3D, type Vector3 } from "@motionscript/sdk";
2
+ /** Text in a 3D graph: a camera-facing card, so a number reads square-on from wherever the scene is seen. */
3
+ export interface LabelStyle3D {
4
+ /** The height of the text's em, in scene units. */
5
+ size: number;
6
+ color: Color;
7
+ fontFamily: string;
8
+ }
9
+ /** Draw `text` centred on `at`, a local point. */
10
+ export declare function drawLabel3D(g3: Graphics3D, text: string, at: Vector3, style: LabelStyle3D): void;
11
+ //# sourceMappingURL=label3d.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"label3d.d.ts","sourceRoot":"","sources":["../../src/three/label3d.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,KAAK,KAAK,EAAE,KAAK,UAAU,EAAyB,KAAK,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAGlI,6GAA6G;AAE7G,MAAM,WAAW,YAAY;IACzB,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,KAAK,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACtB;AA6BD,kDAAkD;AAClD,wBAAgB,WAAW,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI,CAShG"}
@@ -0,0 +1,40 @@
1
+ import { Fills, Graphics2D, Mat, Tex } from "@motionscript/sdk";
2
+ import { createBoundedCache } from "../kit/cache.js";
3
+ /** The em the text is rasterized at, in buffer pixels, and the card's height around it. */
4
+ const EM = 64;
5
+ const CARD_HEIGHT = 96;
6
+ // A texture's identity is its source object, so one text in one style is one source for as long as it is asked for.
7
+ const cards = createBoundedCache(256);
8
+ function card(text, style) {
9
+ const key = `${style.fontFamily}|${JSON.stringify(style.color)}|${text}`;
10
+ const hit = cards.get(key);
11
+ if (hit)
12
+ return hit;
13
+ const width = Math.min(1024, Math.max(128, Math.ceil((text.length * EM * 0.62 + EM) / 32) * 32));
14
+ const source = new Graphics2D()
15
+ .text({
16
+ text,
17
+ fontSize: EM,
18
+ ...(style.fontFamily === "" ? {} : { fontFamily: style.fontFamily }),
19
+ wrap: false,
20
+ width,
21
+ textAlign: "center",
22
+ })
23
+ .fill(Fills.color(style.color));
24
+ const made = { texture: Tex.surface(source, { width, height: CARD_HEIGHT }), width };
25
+ cards.set(key, made);
26
+ return made;
27
+ }
28
+ /** Draw `text` centred on `at`, a local point. */
29
+ export function drawLabel3D(g3, text, at, style) {
30
+ if (text === "" || !(style.size > 0))
31
+ return;
32
+ const { texture, width } = card(text, style);
33
+ const height = (style.size * CARD_HEIGHT) / EM;
34
+ g3.sprite({
35
+ material: Mat.sprite({ map: texture, transparent: true, depthWrite: false }),
36
+ position: at,
37
+ scale: [(height * width) / CARD_HEIGHT, height, 1],
38
+ });
39
+ }
40
+ //# sourceMappingURL=label3d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"label3d.js","sourceRoot":"","sources":["../../src/three/label3d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,EAAoE,MAAM,mBAAmB,CAAC;AAClI,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAWlD,2FAA2F;AAC3F,MAAM,EAAE,GAAG,EAAE,CAAC;AACd,MAAM,WAAW,GAAG,EAAE,CAAC;AAEvB,oHAAoH;AACpH,MAAM,KAAK,GAAG,kBAAkB,CAA+C,GAAG,CAAC,CAAC;AAEpF,SAAS,IAAI,CAAC,IAAY,EAAE,KAAmB;IAC3C,MAAM,GAAG,GAAG,GAAG,KAAK,CAAC,UAAU,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC;IACzE,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,GAAG;QAAE,OAAO,GAAG,CAAC;IAC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AE,CAAC,MAAM,CAAC;QACN,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;QAC5E,QAAQ,EAAE,EAAE;QACZ,KAAK,EAAE,CAAC,CAAC,MAAM,GAAG,KAAK,CAAC,GAAG,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;KACrD,CAAC,CAAC;AACP,CAAC","sourcesContent":["import { Fills, Graphics2D, Mat, Tex, type Color, type Graphics3D, type SurfaceTexture3D, type Vector3 } from \"@motionscript/sdk\";\r\nimport { createBoundedCache } from \"../kit/cache\";\r\n\r\n/** Text in a 3D graph: a camera-facing card, so a number reads square-on from wherever the scene is seen. */\r\n\r\nexport interface LabelStyle3D {\r\n /** The height of the text's em, in scene units. */\r\n size: number;\r\n color: Color;\r\n fontFamily: string;\r\n}\r\n\r\n/** The em the text is rasterized at, in buffer pixels, and the card's height around it. */\r\nconst EM = 64;\r\nconst CARD_HEIGHT = 96;\r\n\r\n// A texture's identity is its source object, so one text in one style is one source for as long as it is asked for.\r\nconst cards = createBoundedCache<{ texture: SurfaceTexture3D; width: number }>(256);\r\n\r\nfunction card(text: string, style: LabelStyle3D): { texture: SurfaceTexture3D; width: number } {\r\n const key = `${style.fontFamily}|${JSON.stringify(style.color)}|${text}`;\r\n const hit = cards.get(key);\r\n if (hit) return hit;\r\n const width = Math.min(1024, Math.max(128, Math.ceil((text.length * EM * 0.62 + EM) / 32) * 32));\r\n const source = new Graphics2D()\r\n .text({\r\n text,\r\n fontSize: EM,\r\n ...(style.fontFamily === \"\" ? {} : { fontFamily: style.fontFamily }),\r\n wrap: false,\r\n width,\r\n textAlign: \"center\",\r\n })\r\n .fill(Fills.color(style.color));\r\n const made = { texture: Tex.surface(source, { width, height: CARD_HEIGHT }), width };\r\n cards.set(key, made);\r\n return made;\r\n}\r\n\r\n/** Draw `text` centred on `at`, a local point. */\r\nexport function drawLabel3D(g3: Graphics3D, text: string, at: Vector3, style: LabelStyle3D): void {\r\n if (text === \"\" || !(style.size > 0)) return;\r\n const { texture, width } = card(text, style);\r\n const height = (style.size * CARD_HEIGHT) / EM;\r\n g3.sprite({\r\n material: Mat.sprite({ map: texture, transparent: true, depthWrite: false }),\r\n position: at,\r\n scale: [(height * width) / CARD_HEIGHT, height, 1],\r\n });\r\n}\r\n"]}
@@ -0,0 +1,26 @@
1
+ import { Graphics3D, Mesh3D, type AssetScope, type Color, type Geometry3D, type Mesh3DProps, type NodeConfig } from "@motionscript/sdk";
2
+ export interface PlotPoint3dProps extends Mesh3DProps {
3
+ radius?: number;
4
+ label?: string;
5
+ labelSize?: number;
6
+ labelColor?: Color;
7
+ fontFamily?: string;
8
+ }
9
+ /**
10
+ * A dot at graph coordinates in a 3D graph, with an optional label. Put inside
11
+ * a surface it rides it: its `x` and `y` say where, and its height is the surface's.
12
+ */
13
+ export declare class PlotPoint3d extends Mesh3D<PlotPoint3dProps> {
14
+ /** In scene units, so a point is the same size whatever the axes show. */
15
+ radius: number;
16
+ label: string;
17
+ /** The height of the label's text, in scene units. */
18
+ labelSize: number;
19
+ labelColor: Color;
20
+ fontFamily: string;
21
+ constructor(props?: NodeConfig<PlotPoint3d, PlotPoint3dProps>);
22
+ declareAssets(assets: AssetScope): void;
23
+ protected buildGeometry(): Geometry3D | undefined;
24
+ protected buildGraphics3D(): Graphics3D;
25
+ }
26
+ //# sourceMappingURL=plot-point3d.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plot-point3d.d.ts","sourceRoot":"","sources":["../../src/three/plot-point3d.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,UAAU,EACV,MAAM,EAGN,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,UAAU,EAClB,MAAM,mBAAmB,CAAC;AAG3B,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACjD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,qBAOa,WAAY,SAAQ,MAAM,CAAC,gBAAgB,CAAC;IACrD,0EAA0E;IAClB,MAAM,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACpE,sDAAsD;IACM,SAAS,EAAE,MAAM,CAAC;IAC/B,UAAU,EAAE,KAAK,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;gBAE7D,KAAK,CAAC,EAAE,UAAU,CAAC,WAAW,EAAE,gBAAgB,CAAC;IAIpD,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;cAK7B,aAAa,IAAI,UAAU,GAAG,SAAS;cAIvC,eAAe,IAAI,UAAU;CASnD"}