@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
package/src/tex/matrix.ts CHANGED
@@ -1,5 +1,28 @@
1
- import { command, node, property, type Command, type CommandArgs, type NodeConfig } from "@motionscript/sdk";
2
- import { Latex, type LatexProps } from "./node";
1
+ import {
2
+ component2d,
3
+ Types,
4
+ type EntryOptions,
5
+ type NodeOf,
6
+ // Named so the emitted declaration reaches these through the sdk, not core.
7
+ type Alignment as _Alignment,
8
+ type Fill as _Fill,
9
+ type FillResolved as _FillResolved,
10
+ type FlowMode as _FlowMode,
11
+ type FlowResolved as _FlowResolved,
12
+ type GapSize as _GapSize,
13
+ type Node2D as _Node2D,
14
+ type Node2DProps as _Node2DProps,
15
+ type Shadow as _Shadow,
16
+ type ShadowResolved as _ShadowResolved,
17
+ type Stroke as _Stroke,
18
+ type StrokeResolved as _StrokeResolved,
19
+ type Vector2 as _Vector2,
20
+ } from "@motionscript/sdk";
21
+ import type { LatexProps } from "./node";
22
+ import {
23
+ drawFormula, formula, formulaFrame, layoutFormula, lerpMorph, loadFormula, measureFormula, morphOf, TYPESET, TYPESET_COMMANDS,
24
+ type Morphing,
25
+ } from "./typeset";
3
26
 
4
27
  export type MatrixBrackets = "square" | "round" | "bar" | "double" | "curly" | "none";
5
28
 
@@ -17,6 +40,8 @@ const ENVIRONMENT: Record<MatrixBrackets, string> = {
17
40
  none: "matrix",
18
41
  };
19
42
 
43
+ const BRACKETS = ["square", "round", "bar", "double", "curly", "none"] as const;
44
+
20
45
  /** The LaTeX a matrix of `entries` is typeset from; empty for one with no entries. */
21
46
  export function matrixSource(entries: readonly (readonly string[])[], brackets: MatrixBrackets = "square"): string {
22
47
  const rows = entries.filter((row) => Array.isArray(row) && row.length > 0);
@@ -25,51 +50,48 @@ export function matrixSource(entries: readonly (readonly string[])[], brackets:
25
50
  return `\\begin{${environment}} ${rows.map((row) => row.join(" & ")).join(" \\\\ ")} \\end{${environment}}`;
26
51
  }
27
52
 
28
- // A list of rows is a whole value: it changes at the end of a tween, and the morph draws the way there.
29
- // (A function, not a generic arrow: a copied component is compiled as TSX, where `<T>(` opens an element.)
30
- function atTheEnd<T>(from: T, to: T, t: number): T {
31
- return t < 1 ? from : to;
53
+ interface MatrixValues {
54
+ readonly entries: Morphing<string[][]>;
55
+ readonly brackets: Morphing<MatrixBrackets>;
32
56
  }
33
57
 
34
- type MatrixNext = Partial<LatexMatrixProps>;
58
+ /** The matrix's source now: mid-tween of its entries or its brackets, both ends of it. */
59
+ function sourceOf(s: MatrixValues): Morphing<string> {
60
+ return morphOf([s.entries, s.brackets], ([entries, brackets]) => matrixSource(entries as string[][], brackets as MatrixBrackets));
61
+ }
62
+
63
+ const state = {
64
+ ...TYPESET,
65
+ // Unused by the matrix's own drawing: its entries say what it writes.
66
+ latex: Types.custom<string, Morphing<string>, EntryOptions & { readonly kind: "text"; readonly multiline: true }>("", {
67
+ kind: "text", multiline: true, lerp: lerpMorph,
68
+ }),
69
+ /** A list of rows is a whole value: mid-tween it holds both, and the morph draws the way there. */
70
+ entries: Types.custom<string[][], Morphing<string[][]>>([["a", "b"], ["c", "d"]], { lerp: lerpMorph }),
71
+ brackets: Types.custom<MatrixBrackets, Morphing<MatrixBrackets>, EntryOptions & { readonly options: typeof BRACKETS }>("square", {
72
+ options: BRACKETS, animatable: false, lerp: lerpMorph,
73
+ }),
74
+ };
35
75
 
36
76
  /**
37
77
  * A matrix typeset from its entries, row by row, inside the brackets it is
38
78
  * given. Each entry is a piece of LaTeX and is one of the formula's parts, so
39
79
  * it can be painted, boxed or braced by its own source.
40
80
  */
41
- @node({
81
+ export const LatexMatrix = formula(component2d({
42
82
  key: "latexMatrix",
43
- parentKey: "latex",
44
- forkable: true,
45
- layout: { children: "freeform", defaultWidthMode: "hug", defaultHeightMode: "hug", acceptsChildren: true },
46
- seed: { fill: [{ type: "solid", color: [0.412, 0.565, 0.867, 1], opacity: 1, enabled: true }] },
47
- })
48
- export class LatexMatrix extends Latex {
49
- @property({ default: [["a", "b"], ["c", "d"]], tween: atTheEnd }) declare entries: string[][];
50
- @property({ default: "square", options: ["square", "round", "bar", "double", "curly", "none"], animatable: false })
51
- declare brackets: MatrixBrackets;
52
-
53
- constructor(props?: NodeConfig<LatexMatrix, LatexMatrixProps>) {
54
- super(props as never);
55
- }
83
+ state,
84
+ defaults: { width: "hug", height: "hug" },
85
+ load: (loader) => loadFormula(loader),
86
+ commands: {
87
+ ...TYPESET_COMMANDS,
88
+ morphTo: { args: ["latex"] },
89
+ /** Change the entries: the ones both matrices write travel, the rest fade. */
90
+ entriesTo: { args: ["entries"] },
91
+ },
92
+ measure: (_measurer, s) => measureFormula(formulaFrame(sourceOf(s), s.fontSize, s.partFills), s),
93
+ layout: (box, s, children) => layoutFormula(box, s, children),
94
+ render: (ctx, s) => drawFormula(ctx, s, formulaFrame(sourceOf(s), s.fontSize, s.partFills)),
95
+ }), sourceOf);
56
96
 
57
- /** Change the entries: the ones both matrices write travel, the rest fade. */
58
- @command({ args: ["entries"] })
59
- entriesTo(args: CommandArgs<{ entries: string[][] }> & { duration: number }): Command<LatexProps> {
60
- const entries = args.data?.entries;
61
- return this.to({ data: (entries === undefined ? {} : { entries }) as Partial<LatexProps>, duration: args.duration, easing: args.easing });
62
- }
63
-
64
- override _source(next: MatrixNext = {}): string {
65
- return matrixSource(next.entries ?? this.entries, next.brackets ?? this.brackets);
66
- }
67
-
68
- override _sourceProps(next: MatrixNext = {}): Partial<LatexProps> {
69
- return { entries: next.entries ?? this.entries, brackets: next.brackets ?? this.brackets } as Partial<LatexProps>;
70
- }
71
-
72
- override _resets(next: MatrixNext): boolean {
73
- return next.entries !== undefined || next.brackets !== undefined || next.fontSize !== undefined;
74
- }
75
- }
97
+ export type LatexMatrix = NodeOf<typeof LatexMatrix>;