@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,6 +1,5 @@
1
- import { Graphics2D, type AssetScope, type Color, type Command, type CommandArgs, type Extents, type NodeConfig, type PaintProps, type Stroke, type Vector2 } from "@motionscript/sdk";
1
+ import { Graphics2D, type Color, type Extents, type InsetsResolved, type Loader, type NodeOf, type NormalizedColor, type PaintProps, type StrokeResolved, type Values, type Vector2, type Fill as _Fill, type FillResolved as _FillResolved, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Shadow as _Shadow, type ShadowResolved as _ShadowResolved, type Stroke as _Stroke } from "@motionscript/sdk";
2
2
  import { type AxisScaling, type CoordinateMap, type Interval } from "../kit/coords.js";
3
- import { CoordinateSystem } from "../kit/system.js";
4
3
  import { type Ticks } from "../kit/ticks.js";
5
4
  export interface Axes2dProps extends PaintProps {
6
5
  xRange?: Interval;
@@ -20,7 +19,7 @@ export interface Axes2dProps extends PaintProps {
20
19
  yLabel?: string;
21
20
  }
22
21
  /** One axis, as its furniture is drawn: its line's ends and what is marked along it. */
23
- interface AxisLayout {
22
+ export interface AxisLayout {
24
23
  from: Vector2;
25
24
  to: Vector2;
26
25
  /** The pixel points that draw its line: its two ends, or more where the system's map bends it. */
@@ -31,45 +30,168 @@ interface AxisLayout {
31
30
  /** A mark's pixel point. */
32
31
  at(value: number): Vector2;
33
32
  }
33
+ /** An x and a y axis's entries: what a number plane is built on too. */
34
+ export declare const AXES: {
35
+ xRange: import("@motionscript/sdk").Type<Interval, Interval, false>;
36
+ yRange: import("@motionscript/sdk").Type<Interval, Interval, false>;
37
+ /** The spacing of each axis's ticks; zero picks a tidy one for the axis's length. */
38
+ xStep: import("@motionscript/sdk").Type<number, number, false>;
39
+ yStep: import("@motionscript/sdk").Type<number, number, false>;
40
+ xScaling: import("@motionscript/sdk").Type<"linear" | "log", "linear" | "log", false>;
41
+ yScaling: import("@motionscript/sdk").Type<"linear" | "log", "linear" | "log", false>;
42
+ /** Give a y unit the length of an x unit: `yRange` keeps its centre and takes the span that fits. */
43
+ squareUnits: import("@motionscript/sdk").Type<boolean, boolean, false>;
44
+ ticks: import("@motionscript/sdk").Type<boolean, boolean, false>;
45
+ tickSize: import("@motionscript/sdk").Type<number, number, false>;
46
+ labels: import("@motionscript/sdk").Type<boolean, boolean, false>;
47
+ labelSize: import("@motionscript/sdk").Type<number, number, false>;
48
+ labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
49
+ fontFamily: import("@motionscript/sdk").Type<string, string, false>;
50
+ /** A title at the positive end of each axis. */
51
+ xLabel: import("@motionscript/sdk").Type<string, string, false>;
52
+ yLabel: import("@motionscript/sdk").Type<string, string, false>;
53
+ fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
54
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, StrokeResolved[]>;
55
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
56
+ start: import("@motionscript/sdk").Type<number, number, false>;
57
+ end: import("@motionscript/sdk").Type<number, number, false>;
58
+ };
59
+ /** The axes' own commands, beside a shape's paints. */
60
+ export declare const AXES_COMMANDS: {
61
+ /** Animate the window of values the axes show: a pan when a range's ends move alike, a zoom when they do not. */
62
+ rangeTo: {
63
+ args: readonly ["xRange", "yRange"];
64
+ };
65
+ fillTo: {
66
+ readonly args: readonly ["fill"];
67
+ readonly run?: undefined;
68
+ };
69
+ strokeTo: {
70
+ readonly args: readonly ["stroke"];
71
+ readonly run?: undefined;
72
+ };
73
+ shadowTo: {
74
+ readonly args: readonly ["shadow"];
75
+ readonly run?: undefined;
76
+ };
77
+ progressTo: {
78
+ readonly args: readonly ["start", "end"];
79
+ readonly run?: undefined;
80
+ };
81
+ flash: {
82
+ readonly args: {
83
+ readonly portion: import("@motionscript/sdk").Type<number, number, false>;
84
+ };
85
+ run(timeline: any, state: any, children: any): import("@motionscript/sdk").Piece;
86
+ };
87
+ };
88
+ /** What axes are drawn from: their own entries, as a number plane's helpers read them too. */
89
+ export type AxesValues = Values<typeof AXES> & {
90
+ readonly padding: InsetsResolved;
91
+ readonly clip: boolean;
92
+ };
93
+ /** What axes declare before they are laid out: their face, and MathJax for a title written as a formula. */
94
+ export declare function loadAxes(loader: Loader, s: AxesValues): void;
95
+ /** How the axes' values land on a plot area. */
96
+ export declare function axesMap(area: Extents, s: AxesValues): CoordinateMap;
97
+ /** The two axes as laid out on `map`: where each runs, what it marks, and where the other crosses it. */
98
+ export declare function axesOf(map: CoordinateMap, s: AxesValues): [AxisLayout, AxisLayout];
99
+ /** What the axes draw of themselves on `map`, over what `backdrop` draws behind them (a number plane's grid). */
100
+ export declare function axesFurniture(map: CoordinateMap, s: AxesValues, backdrop?: (x: AxisLayout, y: AxisLayout) => Graphics2D[]): Graphics2D[];
34
101
  /**
35
102
  * An x and a y axis, crossing at the origin while it is in range and at the
36
103
  * nearest edge otherwise. Children sit in its graph coordinates.
37
104
  */
38
- export declare class Axes2d<P extends Axes2dProps = Axes2dProps> extends CoordinateSystem<P> {
39
- xRange: Interval;
40
- yRange: Interval;
105
+ export declare const Axes2d: import("@motionscript/sdk").Component<"axes2d", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
106
+ xRange: import("@motionscript/sdk").Type<Interval, Interval, false>;
107
+ yRange: import("@motionscript/sdk").Type<Interval, Interval, false>;
41
108
  /** The spacing of each axis's ticks; zero picks a tidy one for the axis's length. */
42
- xStep: number;
43
- yStep: number;
44
- xScaling: AxisScaling;
45
- yScaling: AxisScaling;
109
+ xStep: import("@motionscript/sdk").Type<number, number, false>;
110
+ yStep: import("@motionscript/sdk").Type<number, number, false>;
111
+ xScaling: import("@motionscript/sdk").Type<"linear" | "log", "linear" | "log", false>;
112
+ yScaling: import("@motionscript/sdk").Type<"linear" | "log", "linear" | "log", false>;
46
113
  /** Give a y unit the length of an x unit: `yRange` keeps its centre and takes the span that fits. */
47
- squareUnits: boolean;
48
- ticks: boolean;
49
- tickSize: number;
50
- labels: boolean;
51
- labelSize: number;
52
- labelColor: Color;
53
- fontFamily: string;
114
+ squareUnits: import("@motionscript/sdk").Type<boolean, boolean, false>;
115
+ ticks: import("@motionscript/sdk").Type<boolean, boolean, false>;
116
+ tickSize: import("@motionscript/sdk").Type<number, number, false>;
117
+ labels: import("@motionscript/sdk").Type<boolean, boolean, false>;
118
+ labelSize: import("@motionscript/sdk").Type<number, number, false>;
119
+ labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
120
+ fontFamily: import("@motionscript/sdk").Type<string, string, false>;
54
121
  /** A title at the positive end of each axis. */
55
- xLabel: string;
56
- yLabel: string;
57
- stroke: Stroke;
58
- constructor(props?: NodeConfig<Axes2d<P>, P>);
59
- /** Animate the window of values the axes show: a pan when a range's ends move alike, a zoom when they do not. */
60
- rangeTo(args: CommandArgs<{
61
- xRange?: Interval;
62
- yRange?: Interval;
63
- }> & {
64
- duration: number;
65
- }): Command<P>;
66
- declareAssets(assets: AssetScope): void;
67
- protected mapFor(area: Extents): CoordinateMap;
68
- protected furniture(map: CoordinateMap): Graphics2D[];
69
- /** What is drawn behind the axes: nothing here, a grid on a number plane. */
70
- protected backdrop(_map: CoordinateMap, _x: AxisLayout, _y: AxisLayout): Graphics2D[];
71
- /** The two axes as laid out: where each runs, what it marks, and where the other crosses it. */
72
- protected axes(map: CoordinateMap): [AxisLayout, AxisLayout];
73
- }
74
- export type { AxisLayout };
122
+ xLabel: import("@motionscript/sdk").Type<string, string, false>;
123
+ yLabel: import("@motionscript/sdk").Type<string, string, false>;
124
+ fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
125
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, StrokeResolved[]>;
126
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
127
+ start: import("@motionscript/sdk").Type<number, number, false>;
128
+ end: import("@motionscript/sdk").Type<number, number, false>;
129
+ }>, {
130
+ rangeTo: readonly ["xRange", "yRange"];
131
+ fillTo: readonly ["fill"];
132
+ strokeTo: readonly ["stroke"];
133
+ shadowTo: readonly ["shadow"];
134
+ progressTo: readonly ["start", "end"];
135
+ flash: {
136
+ readonly portion: import("@motionscript/sdk").Type<number, number, false>;
137
+ };
138
+ }, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
139
+ xRange: import("@motionscript/sdk").Type<Interval, Interval, false>;
140
+ yRange: import("@motionscript/sdk").Type<Interval, Interval, false>;
141
+ /** The spacing of each axis's ticks; zero picks a tidy one for the axis's length. */
142
+ xStep: import("@motionscript/sdk").Type<number, number, false>;
143
+ yStep: import("@motionscript/sdk").Type<number, number, false>;
144
+ xScaling: import("@motionscript/sdk").Type<"linear" | "log", "linear" | "log", false>;
145
+ yScaling: import("@motionscript/sdk").Type<"linear" | "log", "linear" | "log", false>;
146
+ /** Give a y unit the length of an x unit: `yRange` keeps its centre and takes the span that fits. */
147
+ squareUnits: import("@motionscript/sdk").Type<boolean, boolean, false>;
148
+ ticks: import("@motionscript/sdk").Type<boolean, boolean, false>;
149
+ tickSize: import("@motionscript/sdk").Type<number, number, false>;
150
+ labels: import("@motionscript/sdk").Type<boolean, boolean, false>;
151
+ labelSize: import("@motionscript/sdk").Type<number, number, false>;
152
+ labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
153
+ fontFamily: import("@motionscript/sdk").Type<string, string, false>;
154
+ /** A title at the positive end of each axis. */
155
+ xLabel: import("@motionscript/sdk").Type<string, string, false>;
156
+ yLabel: import("@motionscript/sdk").Type<string, string, false>;
157
+ fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
158
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, StrokeResolved[]>;
159
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
160
+ start: import("@motionscript/sdk").Type<number, number, false>;
161
+ end: import("@motionscript/sdk").Type<number, number, false>;
162
+ }>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
163
+ xRange: import("@motionscript/sdk").Type<Interval, Interval, false>;
164
+ yRange: import("@motionscript/sdk").Type<Interval, Interval, false>;
165
+ /** The spacing of each axis's ticks; zero picks a tidy one for the axis's length. */
166
+ xStep: import("@motionscript/sdk").Type<number, number, false>;
167
+ yStep: import("@motionscript/sdk").Type<number, number, false>;
168
+ xScaling: import("@motionscript/sdk").Type<"linear" | "log", "linear" | "log", false>;
169
+ yScaling: import("@motionscript/sdk").Type<"linear" | "log", "linear" | "log", false>;
170
+ /** Give a y unit the length of an x unit: `yRange` keeps its centre and takes the span that fits. */
171
+ squareUnits: import("@motionscript/sdk").Type<boolean, boolean, false>;
172
+ ticks: import("@motionscript/sdk").Type<boolean, boolean, false>;
173
+ tickSize: import("@motionscript/sdk").Type<number, number, false>;
174
+ labels: import("@motionscript/sdk").Type<boolean, boolean, false>;
175
+ labelSize: import("@motionscript/sdk").Type<number, number, false>;
176
+ labelColor: import("@motionscript/sdk").Type<Color, NormalizedColor, false>;
177
+ fontFamily: import("@motionscript/sdk").Type<string, string, false>;
178
+ /** A title at the positive end of each axis. */
179
+ xLabel: import("@motionscript/sdk").Type<string, string, false>;
180
+ yLabel: import("@motionscript/sdk").Type<string, string, false>;
181
+ fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
182
+ stroke: import("@motionscript/sdk").Attribute<_Stroke, StrokeResolved[]>;
183
+ shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
184
+ start: import("@motionscript/sdk").Type<number, number, false>;
185
+ end: import("@motionscript/sdk").Type<number, number, false>;
186
+ }>, {
187
+ rangeTo: readonly ["xRange", "yRange"];
188
+ fillTo: readonly ["fill"];
189
+ strokeTo: readonly ["stroke"];
190
+ shadowTo: readonly ["shadow"];
191
+ progressTo: readonly ["start", "end"];
192
+ flash: {
193
+ readonly portion: import("@motionscript/sdk").Type<number, number, false>;
194
+ };
195
+ }, _Node2D<_Node2DProps>>>>;
196
+ export type Axes2d = NodeOf<typeof Axes2d>;
75
197
  //# sourceMappingURL=axes2d.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"axes2d.d.ts","sourceRoot":"","sources":["../../src/systems/axes2d.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,UAAU,EAIV,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,UAAU,EAEf,KAAK,UAAU,EACf,KAAK,MAAM,EAEX,KAAK,OAA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AU,EACb,QAAQ,GAAE,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,KAAK,UAAU,EAAa,GACpE,UAAU,EAAE,CAuDd;AAED;;;GAGG;AACH,eAAO,MAAM,MAAM;;;IAhJf,qFAAqF;;;;;IAKrF,qGAAqG;;;;;;;;IAQrG,gDAAgD;;;;;;;;;;;;;;;;;;;;IAbhD,qFAAqF;;;;;IAKrF,qGAAqG;;;;;;;;IAQrG,gDAAgD;;;;;;;;;;;IAbhD,qFAAqF;;;;;IAKrF,qGAAqG;;;;;;;;IAQrG,gDAAgD;;;;;;;;;;;;;;;;;2BA8IlD,CAAC;AAEH,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,MAAM,CAAC,CAAC"}
@@ -1,193 +1,157 @@
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 { colorProperty, command, Graphics2D, node, property, strokeProperty, } from "@motionscript/sdk";
1
+ import { component2d, Graphics2D, Types, } from "@motionscript/sdk";
2
+ import { listed, PAINT, PAINT_COMMANDS } from "../kit/component.js";
8
3
  import { cartesianMap, lineThrough, resolveInterval } from "../kit/coords.js";
9
- import { clamp, stated } from "../kit/geometry.js";
10
- import { CoordinateSystem } from "../kit/system.js";
4
+ import { clamp } from "../kit/geometry.js";
5
+ import { drawSystem, systemLayout, systemMap, systemOpenPlane, systemProvides, systemSize } from "../kit/system.js";
11
6
  import { formatTick, ticksFor } from "../kit/ticks.js";
12
- import { along, AXIS_COLOR, declareFormulas, drawLabels, drawn, lerpInterval, readInterval, withoutTips } from "../kit/furniture.js";
13
- /**
14
- * An x and a y axis, crossing at the origin while it is in range and at the
15
- * nearest edge otherwise. Children sit in its graph coordinates.
16
- */
17
- let Axes2d = class Axes2d extends CoordinateSystem {
18
- constructor(props) {
19
- super((props ?? {}));
20
- }
7
+ import { along, AXIS_COLOR, drawLabels, drawn, loadFormulas, lerpInterval, readInterval, withoutTips } from "../kit/furniture.js";
8
+ const interval = (initial) => Types.custom(initial, { resolve: readInterval, lerp: lerpInterval });
9
+ /** An x and a y axis's entries: what a number plane is built on too. */
10
+ export const AXES = {
11
+ ...PAINT,
12
+ xRange: interval([-5, 5]),
13
+ yRange: interval([-3, 3]),
14
+ /** The spacing of each axis's ticks; zero picks a tidy one for the axis's length. */
15
+ xStep: Types.number(0, { min: 0 }),
16
+ yStep: Types.number(0, { min: 0 }),
17
+ xScaling: listed(["linear", "log"], "linear", { animatable: false }),
18
+ yScaling: listed(["linear", "log"], "linear", { animatable: false }),
19
+ /** Give a y unit the length of an x unit: `yRange` keeps its centre and takes the span that fits. */
20
+ squareUnits: Types.boolean(false, { animatable: false }),
21
+ ticks: Types.boolean(true, { animatable: false }),
22
+ tickSize: Types.number(10, { min: 0, unit: "px" }),
23
+ labels: Types.boolean(true, { animatable: false }),
24
+ labelSize: Types.number(18, { min: 1, unit: "px" }),
25
+ labelColor: Types.color(AXIS_COLOR),
26
+ fontFamily: Types.text("", { animatable: false }),
27
+ /** A title at the positive end of each axis. */
28
+ xLabel: Types.text("", { animatable: false }),
29
+ yLabel: Types.text("", { animatable: false }),
30
+ };
31
+ /** The axes' own commands, beside a shape's paints. */
32
+ export const AXES_COMMANDS = {
33
+ ...PAINT_COMMANDS,
21
34
  /** Animate the window of values the axes show: a pan when a range's ends move alike, a zoom when they do not. */
22
- rangeTo(args) {
23
- return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });
24
- }
25
- declareAssets(assets) {
26
- super.declareAssets(assets);
27
- if (this.fontFamily !== "")
28
- assets.font(this.fontFamily);
29
- declareFormulas(assets, [this.xLabel, this.yLabel]);
35
+ rangeTo: { args: ["xRange", "yRange"] },
36
+ };
37
+ /** What axes declare before they are laid out: their face, and MathJax for a title written as a formula. */
38
+ export function loadAxes(loader, s) {
39
+ if (s.fontFamily !== "")
40
+ loader.font(s.fontFamily);
41
+ loadFormulas(loader, [s.xLabel, s.yLabel]);
42
+ }
43
+ /** How the axes' values land on a plot area. */
44
+ export function axesMap(area, s) {
45
+ const xRange = resolveInterval(s.xRange, s.xScaling);
46
+ let yRange = resolveInterval(s.yRange, s.yScaling);
47
+ const width = area.maxX - area.minX;
48
+ if (s.squareUnits && s.xScaling === "linear" && s.yScaling === "linear" && width > 0) {
49
+ const span = ((xRange[1] - xRange[0]) * (area.maxY - area.minY)) / width;
50
+ const centre = (yRange[0] + yRange[1]) / 2;
51
+ if (span > 0)
52
+ yRange = [centre - span / 2, centre + span / 2];
30
53
  }
31
- mapFor(area) {
32
- const xRange = resolveInterval(this.xRange, this.xScaling);
33
- let yRange = resolveInterval(this.yRange, this.yScaling);
34
- const width = area.maxX - area.minX;
35
- if (this.squareUnits && this.xScaling === "linear" && this.yScaling === "linear" && width > 0) {
36
- const span = ((xRange[1] - xRange[0]) * (area.maxY - area.minY)) / width;
37
- const centre = (yRange[0] + yRange[1]) / 2;
38
- if (span > 0)
39
- yRange = [centre - span / 2, centre + span / 2];
40
- }
41
- return cartesianMap({ xRange, yRange, area, xScaling: this.xScaling, yScaling: this.yScaling });
54
+ return cartesianMap({ xRange, yRange, area, xScaling: s.xScaling, yScaling: s.yScaling });
55
+ }
56
+ /** The two axes as laid out on `map`: where each runs, what it marks, and where the other crosses it. */
57
+ export function axesOf(map, s) {
58
+ const [xMin, xMax] = map.xRange;
59
+ const [yMin, yMax] = map.yRange;
60
+ // An axis sits on the other's zero, or on its near edge when zero is out of range or it is logarithmic.
61
+ const crossX = s.xScaling === "log" ? xMin : clamp(0, xMin, xMax);
62
+ const crossY = s.yScaling === "log" ? yMin : clamp(0, yMin, yMax);
63
+ const xFrom = map.toPoint(xMin, crossY);
64
+ const xTo = map.toPoint(xMax, crossY);
65
+ const yFrom = map.toPoint(crossX, yMin);
66
+ const yTo = map.toPoint(crossX, yMax);
67
+ return [
68
+ {
69
+ from: xFrom,
70
+ to: xTo,
71
+ line: lineThrough(map, xMin, crossY, xMax, crossY),
72
+ marks: ticksFor(map.xRange, s.xStep, Math.hypot(xTo.x - xFrom.x, xTo.y - xFrom.y), s.xScaling),
73
+ crossing: crossX,
74
+ at: (value) => map.toPoint(value, crossY),
75
+ },
76
+ {
77
+ from: yFrom,
78
+ to: yTo,
79
+ line: lineThrough(map, crossX, yMin, crossX, yMax),
80
+ marks: ticksFor(map.yRange, s.yStep, Math.hypot(yTo.x - yFrom.x, yTo.y - yFrom.y), s.yScaling),
81
+ crossing: crossY,
82
+ at: (value) => map.toPoint(crossX, value),
83
+ },
84
+ ];
85
+ }
86
+ /** What the axes draw of themselves on `map`, over what `backdrop` draws behind them (a number plane's grid). */
87
+ export function axesFurniture(map, s, backdrop = () => []) {
88
+ const stroke = s.stroke;
89
+ const { start, end } = s;
90
+ const [x, y] = axesOf(map, s);
91
+ const parts = [...backdrop(x, y)];
92
+ if (stroke.length === 0 && !s.labels)
93
+ return parts;
94
+ if (stroke.length > 0) {
95
+ parts.push(new Graphics2D()
96
+ .line({ points: x.line, radius: 0, start, end })
97
+ .line({ points: y.line, radius: 0, start, end })
98
+ .stroke(stroke));
42
99
  }
43
- furniture(map) {
44
- const stroke = this.stroke;
45
- const { start, end } = this;
46
- const [x, y] = this.axes(map);
47
- const parts = [...this.backdrop(map, x, y)];
48
- if (stroke.length === 0 && !this.labels)
49
- return parts;
50
- if (stroke.length > 0) {
51
- parts.push(new Graphics2D()
52
- .line({ points: x.line, radius: 0, start, end })
53
- .line({ points: y.line, radius: 0, start, end })
54
- .stroke(stroke));
55
- }
56
- const half = this.tickSize / 2;
57
- const gap = half + this.labelSize * 0.35;
58
- const tickMarks = new Graphics2D();
59
- const labels = [];
60
- let ticked = false;
61
- const mark = (axis, horizontal) => {
62
- for (const value of axis.marks.values) {
63
- if (Math.abs(value - axis.crossing) < 1e-9 * Math.max(1, Math.abs(value)))
64
- continue;
65
- const at = axis.at(value);
66
- if (!drawn(along(at, axis.from, axis.to), start, end))
67
- continue;
68
- if (this.ticks && half > 0) {
69
- tickMarks.line({
70
- points: horizontal
71
- ? [{ x: at.x, y: at.y - half }, { x: at.x, y: at.y + half }]
72
- : [{ x: at.x - half, y: at.y }, { x: at.x + half, y: at.y }],
73
- radius: 0,
74
- });
75
- ticked = true;
76
- }
77
- if (!this.labels)
78
- continue;
79
- labels.push(horizontal
80
- ? { text: formatTick(value, axis.marks.step), at: { x: at.x, y: at.y - gap - this.labelSize / 2 }, align: "center" }
81
- : { text: formatTick(value, axis.marks.step), at: { x: at.x - gap, y: at.y }, align: "right" });
100
+ const half = s.tickSize / 2;
101
+ const gap = half + s.labelSize * 0.35;
102
+ const tickMarks = new Graphics2D();
103
+ const labels = [];
104
+ let ticked = false;
105
+ const mark = (axis, horizontal) => {
106
+ for (const value of axis.marks.values) {
107
+ if (Math.abs(value - axis.crossing) < 1e-9 * Math.max(1, Math.abs(value)))
108
+ continue;
109
+ const at = axis.at(value);
110
+ if (!drawn(along(at, axis.from, axis.to), start, end))
111
+ continue;
112
+ if (s.ticks && half > 0) {
113
+ tickMarks.line({
114
+ points: horizontal
115
+ ? [{ x: at.x, y: at.y - half }, { x: at.x, y: at.y + half }]
116
+ : [{ x: at.x - half, y: at.y }, { x: at.x + half, y: at.y }],
117
+ radius: 0,
118
+ });
119
+ ticked = true;
82
120
  }
83
- };
84
- mark(x, true);
85
- mark(y, false);
86
- if (ticked && stroke.length > 0)
87
- parts.push(tickMarks.stroke(withoutTips(stroke)));
88
- if (this.xLabel !== "" && end >= 1) {
89
- labels.push({ text: this.xLabel, at: { x: x.to.x, y: x.to.y + gap + this.labelSize / 2 }, align: "right" });
90
- }
91
- if (this.yLabel !== "" && end >= 1) {
92
- labels.push({ text: this.yLabel, at: { x: y.to.x + gap, y: y.to.y - this.labelSize / 2 }, align: "left" });
121
+ if (!s.labels)
122
+ continue;
123
+ labels.push(horizontal
124
+ ? { text: formatTick(value, axis.marks.step), at: { x: at.x, y: at.y - gap - s.labelSize / 2 }, align: "center" }
125
+ : { text: formatTick(value, axis.marks.step), at: { x: at.x - gap, y: at.y }, align: "right" });
93
126
  }
94
- parts.push(...drawLabels(labels, { fontSize: this.labelSize, fontFamily: this.fontFamily, color: this.labelColor }));
95
- return parts;
96
- }
97
- /** What is drawn behind the axes: nothing here, a grid on a number plane. */
98
- backdrop(_map, _x, _y) {
99
- return [];
127
+ };
128
+ mark(x, true);
129
+ mark(y, false);
130
+ if (ticked && stroke.length > 0)
131
+ parts.push(tickMarks.stroke(withoutTips(stroke)));
132
+ if (s.xLabel !== "" && end >= 1) {
133
+ labels.push({ text: s.xLabel, at: { x: x.to.x, y: x.to.y + gap + s.labelSize / 2 }, align: "right" });
100
134
  }
101
- /** The two axes as laid out: where each runs, what it marks, and where the other crosses it. */
102
- axes(map) {
103
- const [xMin, xMax] = map.xRange;
104
- const [yMin, yMax] = map.yRange;
105
- // An axis sits on the other's zero, or on its near edge when zero is out of range or it is logarithmic.
106
- const crossX = this.xScaling === "log" ? xMin : clamp(0, xMin, xMax);
107
- const crossY = this.yScaling === "log" ? yMin : clamp(0, yMin, yMax);
108
- const xFrom = map.toPoint(xMin, crossY);
109
- const xTo = map.toPoint(xMax, crossY);
110
- const yFrom = map.toPoint(crossX, yMin);
111
- const yTo = map.toPoint(crossX, yMax);
112
- return [
113
- {
114
- from: xFrom,
115
- to: xTo,
116
- line: lineThrough(map, xMin, crossY, xMax, crossY),
117
- marks: ticksFor(map.xRange, this.xStep, Math.hypot(xTo.x - xFrom.x, xTo.y - xFrom.y), this.xScaling),
118
- crossing: crossX,
119
- at: (value) => map.toPoint(value, crossY),
120
- },
121
- {
122
- from: yFrom,
123
- to: yTo,
124
- line: lineThrough(map, crossX, yMin, crossX, yMax),
125
- marks: ticksFor(map.yRange, this.yStep, Math.hypot(yTo.x - yFrom.x, yTo.y - yFrom.y), this.yScaling),
126
- crossing: crossY,
127
- at: (value) => map.toPoint(crossX, value),
128
- },
129
- ];
135
+ if (s.yLabel !== "" && end >= 1) {
136
+ labels.push({ text: s.yLabel, at: { x: y.to.x + gap, y: y.to.y - s.labelSize / 2 }, align: "left" });
130
137
  }
131
- };
132
- __decorate([
133
- property({ default: [-5, 5], mapper: readInterval, tween: lerpInterval })
134
- ], Axes2d.prototype, "xRange", void 0);
135
- __decorate([
136
- property({ default: [-3, 3], mapper: readInterval, tween: lerpInterval })
137
- ], Axes2d.prototype, "yRange", void 0);
138
- __decorate([
139
- property({ default: 0, min: 0 })
140
- ], Axes2d.prototype, "xStep", void 0);
141
- __decorate([
142
- property({ default: 0, min: 0 })
143
- ], Axes2d.prototype, "yStep", void 0);
144
- __decorate([
145
- property({ default: "linear", options: ["linear", "log"], animatable: false })
146
- ], Axes2d.prototype, "xScaling", void 0);
147
- __decorate([
148
- property({ default: "linear", options: ["linear", "log"], animatable: false })
149
- ], Axes2d.prototype, "yScaling", void 0);
150
- __decorate([
151
- property({ default: false, animatable: false })
152
- ], Axes2d.prototype, "squareUnits", void 0);
153
- __decorate([
154
- property({ default: true, animatable: false })
155
- ], Axes2d.prototype, "ticks", void 0);
156
- __decorate([
157
- property({ default: 10, min: 0, unit: "px" })
158
- ], Axes2d.prototype, "tickSize", void 0);
159
- __decorate([
160
- property({ default: true, animatable: false })
161
- ], Axes2d.prototype, "labels", void 0);
162
- __decorate([
163
- property({ default: 18, min: 1, unit: "px" })
164
- ], Axes2d.prototype, "labelSize", void 0);
165
- __decorate([
166
- colorProperty({ default: AXIS_COLOR })
167
- ], Axes2d.prototype, "labelColor", void 0);
168
- __decorate([
169
- property({ default: "", animatable: false })
170
- ], Axes2d.prototype, "fontFamily", void 0);
171
- __decorate([
172
- property({ default: "", animatable: false })
173
- ], Axes2d.prototype, "xLabel", void 0);
174
- __decorate([
175
- property({ default: "", animatable: false })
176
- ], Axes2d.prototype, "yLabel", void 0);
177
- __decorate([
178
- strokeProperty({ default: { weight: 2, fill: AXIS_COLOR, align: "center", endCap: "triangle", capScale: 5 } })
179
- ], Axes2d.prototype, "stroke", void 0);
180
- __decorate([
181
- command({ args: ["xRange", "yRange"] })
182
- ], Axes2d.prototype, "rangeTo", null);
183
- Axes2d = __decorate([
184
- node({
185
- key: "axes2d",
186
- parentKey: "node",
187
- forkable: true,
188
- layout: { children: "freeform", defaultWidthMode: "fixed", defaultHeightMode: "fixed", acceptsChildren: true },
189
- seed: { width: 800, height: 500, padding: 32 },
190
- })
191
- ], Axes2d);
192
- export { Axes2d };
138
+ parts.push(...drawLabels(labels, { fontSize: s.labelSize, fontFamily: s.fontFamily, color: s.labelColor }));
139
+ return parts;
140
+ }
141
+ /**
142
+ * An x and a y axis, crossing at the origin while it is in range and at the
143
+ * nearest edge otherwise. Children sit in its graph coordinates.
144
+ */
145
+ export const Axes2d = component2d({
146
+ key: "axes2d",
147
+ state: AXES,
148
+ defaults: { stroke: { weight: 2, fill: AXIS_COLOR, align: "center", endCap: "triangle", capScale: 5 } },
149
+ load: (loader, s) => loadAxes(loader, s),
150
+ commands: AXES_COMMANDS,
151
+ provide: (s) => systemProvides(s),
152
+ measure: (_measurer, s) => systemSize(s),
153
+ layout: (box, s, children) => systemLayout(box, s, children, axesMap),
154
+ plane: (box, s) => systemOpenPlane(box, s, axesMap),
155
+ render: (ctx, s) => drawSystem(ctx, s, systemMap(ctx.size, s, axesMap), (map) => axesFurniture(map, s)),
156
+ });
193
157
  //# sourceMappingURL=axes2d.js.map