@motionscript/math 0.1.0-alpha.5 → 0.1.0-alpha.6
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.
- package/CHANGELOG.md +22 -0
- package/README.md +39 -33
- package/dist/annotate/angle-mark.d.ts +52 -27
- package/dist/annotate/angle-mark.d.ts.map +1 -1
- package/dist/annotate/angle-mark.js +80 -115
- package/dist/annotate/angle-mark.js.map +1 -1
- package/dist/annotate/curly-brace.d.ts +59 -25
- package/dist/annotate/curly-brace.d.ts.map +1 -1
- package/dist/annotate/curly-brace.js +85 -100
- package/dist/annotate/curly-brace.js.map +1 -1
- package/dist/annotate/emphasis-mark.d.ts +43 -9
- package/dist/annotate/emphasis-mark.d.ts.map +1 -1
- package/dist/annotate/emphasis-mark.js +33 -34
- package/dist/annotate/emphasis-mark.js.map +1 -1
- package/dist/browser/chunks/chunk-ABYBW64J.js +2 -0
- package/dist/browser/chunks/chunk-ABYBW64J.js.map +7 -0
- package/dist/browser/chunks/chunk-K77KLQX4.js +2 -0
- package/dist/browser/chunks/chunk-K77KLQX4.js.map +7 -0
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +3 -3
- package/dist/browser/kit.js +1 -1
- package/dist/browser/manifest.json +1 -1
- package/dist/browser/tex.js +1 -1
- package/dist/browser/tex.js.map +2 -2
- package/dist/engine.d.ts +26 -19
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +17 -14
- package/dist/engine.js.map +1 -1
- package/dist/kit/component.d.ts +51 -0
- package/dist/kit/component.d.ts.map +1 -0
- package/dist/kit/component.js +30 -0
- package/dist/kit/component.js.map +1 -0
- package/dist/kit/curve.d.ts +22 -11
- package/dist/kit/curve.d.ts.map +1 -1
- package/dist/kit/curve.js +25 -18
- package/dist/kit/curve.js.map +1 -1
- package/dist/kit/field-mark.d.ts +58 -35
- package/dist/kit/field-mark.d.ts.map +1 -1
- package/dist/kit/field-mark.js +100 -120
- package/dist/kit/field-mark.js.map +1 -1
- package/dist/kit/follow.d.ts +67 -29
- package/dist/kit/follow.d.ts.map +1 -1
- package/dist/kit/follow.js +114 -110
- package/dist/kit/follow.js.map +1 -1
- package/dist/kit/furniture.d.ts +3 -1
- package/dist/kit/furniture.d.ts.map +1 -1
- package/dist/kit/furniture.js +5 -0
- package/dist/kit/furniture.js.map +1 -1
- package/dist/kit/graph.d.ts +46 -0
- package/dist/kit/graph.d.ts.map +1 -0
- package/dist/kit/graph.js +90 -0
- package/dist/kit/graph.js.map +1 -0
- package/dist/kit/mark.d.ts +64 -39
- package/dist/kit/mark.d.ts.map +1 -1
- package/dist/kit/mark.js +80 -96
- package/dist/kit/mark.js.map +1 -1
- package/dist/kit/place.d.ts +10 -8
- package/dist/kit/place.d.ts.map +1 -1
- package/dist/kit/place.js +28 -30
- package/dist/kit/place.js.map +1 -1
- package/dist/kit/system.d.ts +27 -29
- package/dist/kit/system.d.ts.map +1 -1
- package/dist/kit/system.js +62 -58
- package/dist/kit/system.js.map +1 -1
- package/dist/kit/withdrawn.d.ts +3 -3
- package/dist/kit/withdrawn.js +3 -3
- package/dist/kit/withdrawn.js.map +1 -1
- package/dist/marks/curve-area.d.ts +24 -18
- package/dist/marks/curve-area.d.ts.map +1 -1
- package/dist/marks/curve-area.js +50 -73
- package/dist/marks/curve-area.js.map +1 -1
- package/dist/marks/drop-lines.d.ts +28 -10
- package/dist/marks/drop-lines.d.ts.map +1 -1
- package/dist/marks/drop-lines.js +37 -52
- package/dist/marks/drop-lines.js.map +1 -1
- package/dist/marks/plot-point.d.ts +37 -20
- package/dist/marks/plot-point.d.ts.map +1 -1
- package/dist/marks/plot-point.js +65 -91
- package/dist/marks/plot-point.js.map +1 -1
- package/dist/marks/riemann-sum.d.ts +30 -26
- package/dist/marks/riemann-sum.d.ts.map +1 -1
- package/dist/marks/riemann-sum.js +57 -85
- package/dist/marks/riemann-sum.js.map +1 -1
- package/dist/marks/tangent-line.d.ts +38 -14
- package/dist/marks/tangent-line.d.ts.map +1 -1
- package/dist/marks/tangent-line.js +73 -87
- package/dist/marks/tangent-line.js.map +1 -1
- package/dist/marks/vector-arrow.d.ts +30 -20
- package/dist/marks/vector-arrow.d.ts.map +1 -1
- package/dist/marks/vector-arrow.js +58 -78
- package/dist/marks/vector-arrow.js.map +1 -1
- package/dist/nodes.d.ts +13 -5
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +0 -6
- package/dist/nodes.js.map +1 -1
- package/dist/plots/function-plot.d.ts +107 -43
- package/dist/plots/function-plot.d.ts.map +1 -1
- package/dist/plots/function-plot.js +146 -177
- package/dist/plots/function-plot.js.map +1 -1
- package/dist/plots/points-plot.d.ts +34 -19
- package/dist/plots/points-plot.d.ts.map +1 -1
- package/dist/plots/points-plot.js +31 -58
- package/dist/plots/points-plot.js.map +1 -1
- package/dist/plots/stream-lines.d.ts +38 -19
- package/dist/plots/stream-lines.d.ts.map +1 -1
- package/dist/plots/stream-lines.js +60 -79
- package/dist/plots/stream-lines.js.map +1 -1
- package/dist/plots/traced-path.d.ts +34 -15
- package/dist/plots/traced-path.d.ts.map +1 -1
- package/dist/plots/traced-path.js +33 -48
- package/dist/plots/traced-path.js.map +1 -1
- package/dist/plots/vector-field.d.ts +31 -11
- package/dist/plots/vector-field.d.ts.map +1 -1
- package/dist/plots/vector-field.js +50 -64
- package/dist/plots/vector-field.js.map +1 -1
- package/dist/structures/network-graph.d.ts +99 -49
- package/dist/structures/network-graph.d.ts.map +1 -1
- package/dist/structures/network-graph.js +168 -217
- package/dist/structures/network-graph.js.map +1 -1
- package/dist/structures/sample-space.d.ts +69 -38
- package/dist/structures/sample-space.d.ts.map +1 -1
- package/dist/structures/sample-space.js +132 -170
- package/dist/structures/sample-space.js.map +1 -1
- package/dist/systems/axes2d.d.ts +126 -37
- package/dist/systems/axes2d.d.ts.map +1 -1
- package/dist/systems/axes2d.js +147 -183
- package/dist/systems/axes2d.js.map +1 -1
- package/dist/systems/number-line.d.ts +51 -28
- package/dist/systems/number-line.d.ts.map +1 -1
- package/dist/systems/number-line.js +82 -118
- package/dist/systems/number-line.js.map +1 -1
- package/dist/systems/number-plane.d.ts +92 -31
- package/dist/systems/number-plane.d.ts.map +1 -1
- package/dist/systems/number-plane.js +142 -149
- package/dist/systems/number-plane.js.map +1 -1
- package/dist/systems/polar-plane.d.ts +47 -26
- package/dist/systems/polar-plane.d.ts.map +1 -1
- package/dist/systems/polar-plane.js +107 -133
- package/dist/systems/polar-plane.js.map +1 -1
- package/dist/tex/index.d.ts.map +1 -1
- package/dist/tex/index.js +1 -0
- package/dist/tex/index.js.map +1 -1
- package/dist/tex/matrix.d.ts +56 -18
- package/dist/tex/matrix.d.ts.map +1 -1
- package/dist/tex/matrix.js +33 -50
- package/dist/tex/matrix.js.map +1 -1
- package/dist/tex/node.d.ts +55 -201
- package/dist/tex/node.d.ts.map +1 -1
- package/dist/tex/node.js +23 -593
- package/dist/tex/node.js.map +1 -1
- package/dist/tex/typeset.d.ts +133 -0
- package/dist/tex/typeset.d.ts.map +1 -0
- package/dist/tex/typeset.js +403 -0
- package/dist/tex/typeset.js.map +1 -0
- package/dist/three/axes3d.d.ts +140 -54
- package/dist/three/axes3d.d.ts.map +1 -1
- package/dist/three/axes3d.js +159 -204
- package/dist/three/axes3d.js.map +1 -1
- package/dist/three/curve-plot3d.d.ts +70 -42
- package/dist/three/curve-plot3d.d.ts.map +1 -1
- package/dist/three/curve-plot3d.js +97 -132
- package/dist/three/curve-plot3d.js.map +1 -1
- package/dist/three/entries.d.ts +17 -0
- package/dist/three/entries.d.ts.map +1 -0
- package/dist/three/entries.js +15 -0
- package/dist/three/entries.js.map +1 -0
- package/dist/three/plot-point3d.d.ts +57 -12
- package/dist/three/plot-point3d.d.ts.map +1 -1
- package/dist/three/plot-point3d.js +27 -53
- package/dist/three/plot-point3d.js.map +1 -1
- package/dist/three/space.d.ts +17 -2
- package/dist/three/space.d.ts.map +1 -1
- package/dist/three/space.js +19 -8
- package/dist/three/space.js.map +1 -1
- package/dist/three/surface-plot3d.d.ts +131 -49
- package/dist/three/surface-plot3d.d.ts.map +1 -1
- package/dist/three/surface-plot3d.js +227 -261
- package/dist/three/surface-plot3d.js.map +1 -1
- package/dist/three/vector-arrow3d.d.ts +58 -16
- package/dist/three/vector-arrow3d.d.ts.map +1 -1
- package/dist/three/vector-arrow3d.js +48 -67
- package/dist/three/vector-arrow3d.js.map +1 -1
- package/package.json +4 -4
- package/src/annotate/angle-mark.ts +95 -105
- package/src/annotate/curly-brace.ts +107 -85
- package/src/annotate/emphasis-mark.ts +55 -26
- package/src/engine.ts +35 -21
- package/src/kit/component.ts +57 -0
- package/src/kit/curve.ts +38 -20
- package/src/kit/field-mark.ts +124 -108
- package/src/kit/follow.ts +146 -120
- package/src/kit/furniture.ts +6 -1
- package/src/kit/graph.ts +116 -0
- package/src/kit/mark.ts +135 -114
- package/src/kit/place.ts +32 -56
- package/src/kit/system.ts +77 -71
- package/src/kit/withdrawn.ts +3 -3
- package/src/marks/curve-area.ts +65 -65
- package/src/marks/drop-lines.ts +50 -42
- package/src/marks/plot-point.ts +77 -82
- package/src/marks/riemann-sum.ts +73 -72
- package/src/marks/tangent-line.ts +87 -71
- package/src/marks/vector-arrow.ts +73 -73
- package/src/nodes.ts +41 -5
- package/src/plots/function-plot.ts +155 -171
- package/src/plots/points-plot.ts +46 -50
- package/src/plots/stream-lines.ts +75 -66
- package/src/plots/traced-path.ts +51 -33
- package/src/plots/vector-field.ts +68 -49
- package/src/structures/network-graph.ts +168 -185
- package/src/structures/sample-space.ts +149 -148
- package/src/systems/axes2d.ts +165 -156
- package/src/systems/number-line.ts +91 -92
- package/src/systems/number-plane.ts +149 -120
- package/src/systems/polar-plane.ts +117 -116
- package/src/tex/index.ts +2 -1
- package/src/tex/matrix.ts +62 -40
- package/src/tex/node.ts +54 -621
- package/src/tex/typeset.ts +461 -0
- package/src/three/axes3d.ts +182 -161
- package/src/three/curve-plot3d.ts +107 -110
- package/src/three/entries.ts +42 -0
- package/src/three/plot-point3d.ts +42 -45
- package/src/three/space.ts +34 -9
- package/src/three/surface-plot3d.ts +312 -323
- package/src/three/vector-arrow3d.ts +65 -54
- package/dist/browser/chunks/chunk-3GJB6AVO.js +0 -2
- package/dist/browser/chunks/chunk-3GJB6AVO.js.map +0 -7
- package/dist/browser/chunks/chunk-D5WHCVBC.js +0 -2
- package/dist/browser/chunks/chunk-D5WHCVBC.js.map +0 -7
- package/dist/browser/chunks/chunk-WL4KEX7Y.js +0 -2
- package/dist/browser/chunks/chunk-WL4KEX7Y.js.map +0 -7
- package/src/kit/placement.ts +0 -8
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Extents, type NodeOf, type Stroke, type StrokeResolved, type Color as _Color, type Fill as _Fill, type FillResolved as _FillResolved, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type NormalizedColor as _NormalizedColor, type Shadow as _Shadow, type ShadowResolved as _ShadowResolved } from "@motionscript/sdk";
|
|
2
2
|
import { type CoordinateMap, type Matrix2 } from "../kit/coords.js";
|
|
3
|
-
import { Axes2d, type Axes2dProps, type AxisLayout } from "./axes2d.js";
|
|
4
3
|
import { type PlotSource } from "../kit/source.js";
|
|
4
|
+
import { type Axes2dProps, type AxesValues } from "./axes2d.js";
|
|
5
5
|
export interface NumberPlaneProps extends Axes2dProps {
|
|
6
6
|
grid?: boolean;
|
|
7
7
|
gridStroke?: Stroke;
|
|
@@ -11,6 +11,15 @@ export interface NumberPlaneProps extends Axes2dProps {
|
|
|
11
11
|
warp?: string | PlotSource;
|
|
12
12
|
ghost?: boolean;
|
|
13
13
|
}
|
|
14
|
+
type PlaneValues = AxesValues & {
|
|
15
|
+
readonly grid: boolean;
|
|
16
|
+
readonly gridStroke: StrokeResolved[];
|
|
17
|
+
readonly minorStroke: StrokeResolved[];
|
|
18
|
+
readonly minorDivisions: number;
|
|
19
|
+
readonly matrix: Matrix2;
|
|
20
|
+
readonly warp: PlotSource;
|
|
21
|
+
readonly ghost: boolean;
|
|
22
|
+
};
|
|
14
23
|
/**
|
|
15
24
|
* Axes over a full grid, with square units unless told otherwise: the plane
|
|
16
25
|
* vectors and transformations are drawn on. Its `matrix` shears, turns or
|
|
@@ -18,42 +27,94 @@ export interface NumberPlaneProps extends Axes2dProps {
|
|
|
18
27
|
* function of its own points; the grid, the axes and everything on the plane
|
|
19
28
|
* go with it.
|
|
20
29
|
*/
|
|
21
|
-
export declare
|
|
22
|
-
grid: boolean
|
|
30
|
+
export declare const NumberPlane: import("@motionscript/sdk").Component<"numberPlane", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
31
|
+
grid: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
23
32
|
/** The line at every tick. */
|
|
24
|
-
gridStroke: Stroke
|
|
33
|
+
gridStroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
|
|
25
34
|
/** The lines between ticks. */
|
|
26
|
-
minorStroke: Stroke
|
|
35
|
+
minorStroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
|
|
27
36
|
/** How many parts the space between two ticks is cut into; one draws no line between them. */
|
|
28
|
-
minorDivisions: number
|
|
37
|
+
minorDivisions: import("@motionscript/sdk").Type<number, number, false>;
|
|
29
38
|
/** A linear map of the plane, row by row: `[a, b, c, d]` sends `(x, y)` to `(ax + by, cx + dy)`. */
|
|
30
|
-
matrix: Matrix2
|
|
39
|
+
matrix: import("@motionscript/sdk").Type<Matrix2 | readonly (readonly number[])[], Matrix2, false>;
|
|
31
40
|
/**
|
|
32
41
|
* Where each point of the plane is sent, two parts in x and y:
|
|
33
42
|
* `(x + sin(y), y + sin(x))`. Empty leaves the plane flat.
|
|
34
43
|
*/
|
|
35
|
-
warp: PlotSource
|
|
44
|
+
warp: import("@motionscript/sdk").Type<string | PlotSource, PlotSource, false>;
|
|
36
45
|
/** Leave the plane as it was, faintly, behind one that has been transformed or warped. */
|
|
37
|
-
ghost: boolean
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
46
|
+
ghost: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
47
|
+
xRange: import("@motionscript/sdk").Type<import("../index.js").Interval, import("../index.js").Interval, false>;
|
|
48
|
+
yRange: import("@motionscript/sdk").Type<import("../index.js").Interval, import("../index.js").Interval, false>;
|
|
49
|
+
xStep: import("@motionscript/sdk").Type<number, number, false>;
|
|
50
|
+
yStep: import("@motionscript/sdk").Type<number, number, false>;
|
|
51
|
+
xScaling: import("@motionscript/sdk").Type<"linear" | "log", "linear" | "log", false>;
|
|
52
|
+
yScaling: import("@motionscript/sdk").Type<"linear" | "log", "linear" | "log", false>;
|
|
53
|
+
squareUnits: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
54
|
+
ticks: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
55
|
+
tickSize: import("@motionscript/sdk").Type<number, number, false>;
|
|
56
|
+
labels: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
57
|
+
labelSize: import("@motionscript/sdk").Type<number, number, false>;
|
|
58
|
+
labelColor: import("@motionscript/sdk").Type<_Color, _NormalizedColor, false>;
|
|
59
|
+
fontFamily: import("@motionscript/sdk").Type<string, string, false>;
|
|
60
|
+
xLabel: import("@motionscript/sdk").Type<string, string, false>;
|
|
61
|
+
yLabel: import("@motionscript/sdk").Type<string, string, false>;
|
|
62
|
+
fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
63
|
+
stroke: import("@motionscript/sdk").Attribute<Stroke, StrokeResolved[]>;
|
|
64
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
65
|
+
start: import("@motionscript/sdk").Type<number, number, false>;
|
|
66
|
+
end: import("@motionscript/sdk").Type<number, number, false>;
|
|
67
|
+
}>, {
|
|
68
|
+
readonly transformTo: readonly ["matrix"];
|
|
69
|
+
readonly warpTo: readonly ["warp"];
|
|
70
|
+
readonly rangeTo: readonly ["xRange", "yRange"];
|
|
71
|
+
readonly fillTo: readonly ["fill"];
|
|
72
|
+
readonly strokeTo: readonly ["stroke"];
|
|
73
|
+
readonly shadowTo: readonly ["shadow"];
|
|
74
|
+
readonly progressTo: readonly ["start", "end"];
|
|
75
|
+
readonly flash: {
|
|
76
|
+
readonly portion: import("@motionscript/sdk").Type<number, number, false>;
|
|
77
|
+
};
|
|
78
|
+
}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
79
|
+
grid: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
80
|
+
/** The line at every tick. */
|
|
81
|
+
gridStroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
|
|
82
|
+
/** The lines between ticks. */
|
|
83
|
+
minorStroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
|
|
84
|
+
/** How many parts the space between two ticks is cut into; one draws no line between them. */
|
|
85
|
+
minorDivisions: import("@motionscript/sdk").Type<number, number, false>;
|
|
86
|
+
/** A linear map of the plane, row by row: `[a, b, c, d]` sends `(x, y)` to `(ax + by, cx + dy)`. */
|
|
87
|
+
matrix: import("@motionscript/sdk").Type<Matrix2 | readonly (readonly number[])[], Matrix2, false>;
|
|
88
|
+
/**
|
|
89
|
+
* Where each point of the plane is sent, two parts in x and y:
|
|
90
|
+
* `(x + sin(y), y + sin(x))`. Empty leaves the plane flat.
|
|
91
|
+
*/
|
|
92
|
+
warp: import("@motionscript/sdk").Type<string | PlotSource, PlotSource, false>;
|
|
93
|
+
/** Leave the plane as it was, faintly, behind one that has been transformed or warped. */
|
|
94
|
+
ghost: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
95
|
+
xRange: import("@motionscript/sdk").Type<import("../index.js").Interval, import("../index.js").Interval, false>;
|
|
96
|
+
yRange: import("@motionscript/sdk").Type<import("../index.js").Interval, import("../index.js").Interval, false>;
|
|
97
|
+
xStep: import("@motionscript/sdk").Type<number, number, false>;
|
|
98
|
+
yStep: import("@motionscript/sdk").Type<number, number, false>;
|
|
99
|
+
xScaling: import("@motionscript/sdk").Type<"linear" | "log", "linear" | "log", false>;
|
|
100
|
+
yScaling: import("@motionscript/sdk").Type<"linear" | "log", "linear" | "log", false>;
|
|
101
|
+
squareUnits: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
102
|
+
ticks: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
103
|
+
tickSize: import("@motionscript/sdk").Type<number, number, false>;
|
|
104
|
+
labels: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
105
|
+
labelSize: import("@motionscript/sdk").Type<number, number, false>;
|
|
106
|
+
labelColor: import("@motionscript/sdk").Type<_Color, _NormalizedColor, false>;
|
|
107
|
+
fontFamily: import("@motionscript/sdk").Type<string, string, false>;
|
|
108
|
+
xLabel: import("@motionscript/sdk").Type<string, string, false>;
|
|
109
|
+
yLabel: import("@motionscript/sdk").Type<string, string, false>;
|
|
110
|
+
fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
|
|
111
|
+
stroke: import("@motionscript/sdk").Attribute<Stroke, StrokeResolved[]>;
|
|
112
|
+
shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
|
|
113
|
+
start: import("@motionscript/sdk").Type<number, number, false>;
|
|
114
|
+
end: import("@motionscript/sdk").Type<number, number, false>;
|
|
115
|
+
}>, null>>;
|
|
116
|
+
export type NumberPlane = NodeOf<typeof NumberPlane>;
|
|
117
|
+
/** The plane's map on a plot area: the flat one, sent through its matrix and its warp. */
|
|
118
|
+
export declare function planeMap(area: Extents, s: PlaneValues): CoordinateMap;
|
|
119
|
+
export {};
|
|
59
120
|
//# sourceMappingURL=number-plane.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number-plane.d.ts","sourceRoot":"","sources":["../../src/systems/number-plane.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"number-plane.d.ts","sourceRoot":"","sources":["../../src/systems/number-plane.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,KAAK,OAAO,EACZ,KAAK,MAAM,EACX,KAAK,MAAM,EACX,KAAK,cAAc,EAEnB,KAAK,KAAK,IAAI,MAAM,EACpB,KAAK,IAAI,IAAI,KAAK,EAClB,KAAK,YAAY,IAAI,aAAa,EAClC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EAChC,KAAK,eAAe,IAAI,gBAAgB,EACxC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACzC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAOH,KAAK,aAAa,EAClB,KAAK,OAAO,EAEf,MAAM,eAAe,CAAC;AAGvB,OAAO,EAA0B,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAExE,OAAO,EAAiE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAmB,MAAM,UAAU,CAAC;AAE7I,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACjD,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC;IAClD,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAsBD,KAAK,WAAW,GAAG,UAAU,GAAG;IAC5B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,UAAU,EAAE,cAAc,EAAE,CAAC;IACtC,QAAQ,CAAC,WAAW,EAAE,cAAc,EAAE,CAAC;IACvC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,WAAW;;IAlCpB,8BAA8B;;IAE9B,+BAA+B;;IAE/B,8FAA8F;;IAE9F,oGAAoG;;IAEpG;;;OAGG;;IAEH,0FAA0F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAb1F,8BAA8B;;IAE9B,+BAA+B;;IAE/B,8FAA8F;;IAE9F,oGAAoG;;IAEpG;;;OAGG;;IAEH,0FAA0F;;;;;;;;;;;;;;;;;;;;;;UA8C5F,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC;AAErD,0FAA0F;AAC1F,wBAAgB,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,WAAW,GAAG,aAAa,CAErE"}
|
|
@@ -1,16 +1,29 @@
|
|
|
1
|
-
|
|
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, Graphics2D, node, property, strokeProperty, } from "@motionscript/sdk";
|
|
1
|
+
import { component2d, Graphics2D, Types, } from "@motionscript/sdk";
|
|
8
2
|
import { isIdentityMatrix, lerpMatrix, lineThrough, readMatrix, transformedMap, warpedMap, } from "../kit/coords.js";
|
|
9
3
|
import { fieldParams, parseField } from "../kit/field.js";
|
|
10
|
-
import { Axes2d } from "./axes2d.js";
|
|
11
4
|
import { AXIS_COLOR } from "../kit/furniture.js";
|
|
12
|
-
import { stated } from "../kit/geometry.js";
|
|
13
5
|
import { lerpSource, readSource } from "../kit/source.js";
|
|
6
|
+
import { drawSystem, plotArea, systemLayout, systemOpenPlane, systemProvides, systemSize } from "../kit/system.js";
|
|
7
|
+
import { AXES, AXES_COMMANDS, axesFurniture, axesMap, axesOf, loadAxes } from "./axes2d.js";
|
|
8
|
+
const state = {
|
|
9
|
+
...AXES,
|
|
10
|
+
grid: Types.boolean(true, { animatable: false }),
|
|
11
|
+
/** The line at every tick. */
|
|
12
|
+
gridStroke: Types.stroke({ weight: 1.5, fill: "#3b4658", align: "center" }),
|
|
13
|
+
/** The lines between ticks. */
|
|
14
|
+
minorStroke: Types.stroke({ weight: 1, fill: "#232b38", align: "center" }),
|
|
15
|
+
/** How many parts the space between two ticks is cut into; one draws no line between them. */
|
|
16
|
+
minorDivisions: Types.number(2, { min: 1, max: 10, step: 1 }),
|
|
17
|
+
/** A linear map of the plane, row by row: `[a, b, c, d]` sends `(x, y)` to `(ax + by, cx + dy)`. */
|
|
18
|
+
matrix: Types.custom([1, 0, 0, 1], { resolve: readMatrix, lerp: lerpMatrix }),
|
|
19
|
+
/**
|
|
20
|
+
* Where each point of the plane is sent, two parts in x and y:
|
|
21
|
+
* `(x + sin(y), y + sin(x))`. Empty leaves the plane flat.
|
|
22
|
+
*/
|
|
23
|
+
warp: Types.custom("", { resolve: readSource, lerp: lerpSource, kind: "fieldEquation" }),
|
|
24
|
+
/** Leave the plane as it was, faintly, behind one that has been transformed or warped. */
|
|
25
|
+
ghost: Types.boolean(true, { animatable: false }),
|
|
26
|
+
};
|
|
14
27
|
/**
|
|
15
28
|
* Axes over a full grid, with square units unless told otherwise: the plane
|
|
16
29
|
* vectors and transformations are drawn on. Its `matrix` shears, turns or
|
|
@@ -18,159 +31,139 @@ import { lerpSource, readSource } from "../kit/source.js";
|
|
|
18
31
|
* function of its own points; the grid, the axes and everything on the plane
|
|
19
32
|
* go with it.
|
|
20
33
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
34
|
+
export const NumberPlane = component2d({
|
|
35
|
+
key: "numberPlane",
|
|
36
|
+
state,
|
|
37
|
+
defaults: {
|
|
38
|
+
squareUnits: true,
|
|
39
|
+
stroke: { weight: 2, fill: AXIS_COLOR, align: "center" },
|
|
24
40
|
// A transformed plane reaches past its box, and so does what is on it: both are kept in unless told otherwise.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
clip: (s) => spills(s),
|
|
42
|
+
},
|
|
43
|
+
load: (loader, s) => loadAxes(loader, s),
|
|
44
|
+
commands: {
|
|
45
|
+
...AXES_COMMANDS,
|
|
46
|
+
/** Send the plane through a matrix: a shear, a turn, a squeeze, a flip. */
|
|
47
|
+
transformTo: { args: ["matrix"] },
|
|
48
|
+
/** Bend the plane, each point travelling to where the warp sends it; an empty one flattens it again. */
|
|
49
|
+
warpTo: { args: ["warp"] },
|
|
50
|
+
},
|
|
51
|
+
provide: (s) => systemProvides(s),
|
|
52
|
+
measure: (_measurer, s) => systemSize(s),
|
|
53
|
+
layout: (box, s, children) => systemLayout(box, s, children, planeMap),
|
|
54
|
+
plane: (box, s) => systemOpenPlane(box, s, planeMap),
|
|
55
|
+
render: (ctx, s) => {
|
|
56
|
+
const { flat, map } = planeMaps(plotArea(ctx.size, s.padding), s);
|
|
57
|
+
drawSystem(ctx, s, map, (on) => axesFurniture(on, s, (x, y) => grid(s, flat, on, x, y)));
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
/** The plane's map on a plot area: the flat one, sent through its matrix and its warp. */
|
|
61
|
+
export function planeMap(area, s) {
|
|
62
|
+
return planeMaps(area, s).map;
|
|
63
|
+
}
|
|
64
|
+
/** The flat plane on a plot area, and the plane as its matrix and its warp have it. */
|
|
65
|
+
function planeMaps(area, s) {
|
|
66
|
+
const flat = axesMap(area, s);
|
|
67
|
+
const map = isIdentityMatrix(s.matrix) ? flat : transformedMap(flat, s.matrix);
|
|
68
|
+
const { source, blend } = s.warp;
|
|
69
|
+
const to = warpOf(source);
|
|
70
|
+
if (!blend)
|
|
71
|
+
return { flat, map: to ? warpedMap(map, to, source) : map };
|
|
72
|
+
// Mid-warp each point is part of the way from where the old warp had it to where the new one sends it.
|
|
73
|
+
const from = warpOf(blend.from);
|
|
74
|
+
if (!from && !to)
|
|
75
|
+
return { flat, map };
|
|
76
|
+
const start = { x: 0, y: 0 };
|
|
77
|
+
return {
|
|
78
|
+
flat,
|
|
79
|
+
map: warpedMap(map, (x, y, out) => {
|
|
50
80
|
if (!(from ?? STAY)(x, y, start) || !(to ?? STAY)(x, y, out))
|
|
51
81
|
return false;
|
|
52
82
|
out.x = start.x + (out.x - start.x) * blend.t;
|
|
53
83
|
out.y = start.y + (out.y - start.y) * blend.t;
|
|
54
84
|
return true;
|
|
55
|
-
}, `${blend.from}>${source}@${blend.t}`)
|
|
85
|
+
}, `${blend.from}>${source}@${blend.t}`),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/** Whether the plane reaches past its box: it is transformed or warped. */
|
|
89
|
+
function spills(s) {
|
|
90
|
+
if (!isIdentityMatrix(s.matrix))
|
|
91
|
+
return true;
|
|
92
|
+
const { source, blend } = s.warp;
|
|
93
|
+
return warpOf(source) !== null || (blend !== undefined && warpOf(blend.from) !== null);
|
|
94
|
+
}
|
|
95
|
+
/** The grid behind the axes, with the flat plane faintly behind a transformed one. */
|
|
96
|
+
function grid(s, flat, map, x, y) {
|
|
97
|
+
if (!s.grid)
|
|
98
|
+
return [];
|
|
99
|
+
const parts = [];
|
|
100
|
+
if (s.ghost && flat.revision !== map.revision) {
|
|
101
|
+
const [gx, gy] = axesOf(flat, s);
|
|
102
|
+
parts.push(...ruled(s, flat, gx, gy, true));
|
|
56
103
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
104
|
+
parts.push(...ruled(s, map, x, y, false));
|
|
105
|
+
return parts;
|
|
106
|
+
}
|
|
107
|
+
/** The grid of `map`: every line, or only the ones at a tick, in the fainter stroke, for a ghost. */
|
|
108
|
+
function ruled(s, map, x, y, ghost) {
|
|
109
|
+
const { start, end } = s;
|
|
110
|
+
const [xMin, xMax] = map.xRange;
|
|
111
|
+
const [yMin, yMax] = map.yRange;
|
|
112
|
+
const lines = (values, vertical) => {
|
|
113
|
+
const g = new Graphics2D();
|
|
114
|
+
for (const value of values) {
|
|
115
|
+
g.line({
|
|
116
|
+
points: vertical ? lineThrough(map, value, yMin, value, yMax) : lineThrough(map, xMin, value, xMax, value),
|
|
117
|
+
radius: 0,
|
|
118
|
+
start,
|
|
119
|
+
end,
|
|
120
|
+
});
|
|
65
121
|
}
|
|
66
|
-
|
|
122
|
+
return g;
|
|
123
|
+
};
|
|
124
|
+
const parts = [];
|
|
125
|
+
const minor = s.minorStroke;
|
|
126
|
+
if (ghost) {
|
|
127
|
+
if (minor.length === 0)
|
|
128
|
+
return parts;
|
|
129
|
+
if (x.marks.values.length > 0)
|
|
130
|
+
parts.push(lines(x.marks.values, true).stroke(minor));
|
|
131
|
+
if (y.marks.values.length > 0)
|
|
132
|
+
parts.push(lines(y.marks.values, false).stroke(minor));
|
|
67
133
|
return parts;
|
|
68
134
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
end,
|
|
83
|
-
});
|
|
135
|
+
const divisions = Math.round(s.minorDivisions);
|
|
136
|
+
if (minor.length > 0 && divisions > 1) {
|
|
137
|
+
const between = (axis, [min, max]) => {
|
|
138
|
+
const { step, values } = axis.marks;
|
|
139
|
+
if (!(step > 0) || values.length === 0)
|
|
140
|
+
return [];
|
|
141
|
+
const out = [];
|
|
142
|
+
for (let base = values[0] - step; base < max; base += step) {
|
|
143
|
+
for (let i = 1; i < divisions; i++) {
|
|
144
|
+
const value = base + (step * i) / divisions;
|
|
145
|
+
if (value > min && value < max)
|
|
146
|
+
out.push(value);
|
|
147
|
+
}
|
|
84
148
|
}
|
|
85
|
-
return
|
|
149
|
+
return out;
|
|
86
150
|
};
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
if (
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
parts.push(lines(x.marks.values, true).stroke(minor));
|
|
94
|
-
if (y.marks.values.length > 0)
|
|
95
|
-
parts.push(lines(y.marks.values, false).stroke(minor));
|
|
96
|
-
return parts;
|
|
97
|
-
}
|
|
98
|
-
const divisions = Math.round(this.minorDivisions);
|
|
99
|
-
if (minor.length > 0 && divisions > 1) {
|
|
100
|
-
const between = (axis, [min, max]) => {
|
|
101
|
-
const { step, values } = axis.marks;
|
|
102
|
-
if (!(step > 0) || values.length === 0)
|
|
103
|
-
return [];
|
|
104
|
-
const out = [];
|
|
105
|
-
for (let base = values[0] - step; base < max; base += step) {
|
|
106
|
-
for (let i = 1; i < divisions; i++) {
|
|
107
|
-
const value = base + (step * i) / divisions;
|
|
108
|
-
if (value > min && value < max)
|
|
109
|
-
out.push(value);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return out;
|
|
113
|
-
};
|
|
114
|
-
const xs = between(x, map.xRange);
|
|
115
|
-
const ys = between(y, map.yRange);
|
|
116
|
-
if (xs.length > 0)
|
|
117
|
-
parts.push(lines(xs, true).stroke(minor));
|
|
118
|
-
if (ys.length > 0)
|
|
119
|
-
parts.push(lines(ys, false).stroke(minor));
|
|
120
|
-
}
|
|
121
|
-
const major = this.gridStroke;
|
|
122
|
-
if (major.length > 0) {
|
|
123
|
-
if (x.marks.values.length > 0)
|
|
124
|
-
parts.push(lines(x.marks.values, true).stroke(major));
|
|
125
|
-
if (y.marks.values.length > 0)
|
|
126
|
-
parts.push(lines(y.marks.values, false).stroke(major));
|
|
127
|
-
}
|
|
128
|
-
return parts;
|
|
151
|
+
const xs = between(x, map.xRange);
|
|
152
|
+
const ys = between(y, map.yRange);
|
|
153
|
+
if (xs.length > 0)
|
|
154
|
+
parts.push(lines(xs, true).stroke(minor));
|
|
155
|
+
if (ys.length > 0)
|
|
156
|
+
parts.push(lines(ys, false).stroke(minor));
|
|
129
157
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
], NumberPlane.prototype, "minorStroke", void 0);
|
|
140
|
-
__decorate([
|
|
141
|
-
property({ default: 2, min: 1, max: 10, step: 1 })
|
|
142
|
-
], NumberPlane.prototype, "minorDivisions", void 0);
|
|
143
|
-
__decorate([
|
|
144
|
-
property({ default: [1, 0, 0, 1], mapper: readMatrix, tween: lerpMatrix })
|
|
145
|
-
], NumberPlane.prototype, "matrix", void 0);
|
|
146
|
-
__decorate([
|
|
147
|
-
property({ default: "", mapper: readSource, tween: lerpSource, kind: "fieldEquation" })
|
|
148
|
-
], NumberPlane.prototype, "warp", void 0);
|
|
149
|
-
__decorate([
|
|
150
|
-
property({ default: true, animatable: false })
|
|
151
|
-
], NumberPlane.prototype, "ghost", void 0);
|
|
152
|
-
__decorate([
|
|
153
|
-
property({ default: true, animatable: false })
|
|
154
|
-
], NumberPlane.prototype, "squareUnits", void 0);
|
|
155
|
-
__decorate([
|
|
156
|
-
strokeProperty({ default: { weight: 2, fill: AXIS_COLOR, align: "center" } })
|
|
157
|
-
], NumberPlane.prototype, "stroke", void 0);
|
|
158
|
-
__decorate([
|
|
159
|
-
command({ args: ["matrix"] })
|
|
160
|
-
], NumberPlane.prototype, "transformTo", null);
|
|
161
|
-
__decorate([
|
|
162
|
-
command({ args: ["warp"] })
|
|
163
|
-
], NumberPlane.prototype, "warpTo", null);
|
|
164
|
-
NumberPlane = __decorate([
|
|
165
|
-
node({
|
|
166
|
-
key: "numberPlane",
|
|
167
|
-
parentKey: "axes2d",
|
|
168
|
-
forkable: true,
|
|
169
|
-
layout: { children: "freeform", defaultWidthMode: "fixed", defaultHeightMode: "fixed", acceptsChildren: true },
|
|
170
|
-
seed: { width: 800, height: 500 },
|
|
171
|
-
})
|
|
172
|
-
], NumberPlane);
|
|
173
|
-
export { NumberPlane };
|
|
158
|
+
const major = s.gridStroke;
|
|
159
|
+
if (major.length > 0) {
|
|
160
|
+
if (x.marks.values.length > 0)
|
|
161
|
+
parts.push(lines(x.marks.values, true).stroke(major));
|
|
162
|
+
if (y.marks.values.length > 0)
|
|
163
|
+
parts.push(lines(y.marks.values, false).stroke(major));
|
|
164
|
+
}
|
|
165
|
+
return parts;
|
|
166
|
+
}
|
|
174
167
|
const STAY = (x, y, out) => {
|
|
175
168
|
out.x = x;
|
|
176
169
|
out.y = y;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number-plane.js","sourceRoot":"","sources":["../../src/systems/number-plane.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACH,OAAO,EACP,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,cAAc,GAOjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACH,g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AAC;AAEF,4GAA4G;AAC5G,SAAS,MAAM,CAAC,MAAc;IAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IACpF,IAAI,CAAC,KAAK,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,IAAI,CAAC;IAClD,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC;IACvB,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE;QACnB,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QACrB,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QACrB,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QACX,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QACX,OAAO,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACtD,CAAC,CAAC;AACN,CAAC","sourcesContent":["import {\r\n command,\r\n Graphics2D,\r\n node,\r\n property,\r\n strokeProperty,\r\n type Command,\r\n type CommandArgs,\r\n type Extents,\r\n type NodeConfig,\r\n type Stroke,\r\n type StrokeResolved,\r\n} from \"@motionscript/sdk\";\r\nimport {\r\n isIdentityMatrix,\r\n lerpMatrix,\r\n lineThrough,\r\n readMatrix,\r\n transformedMap,\r\n warpedMap,\r\n type CoordinateMap,\r\n type Matrix2,\r\n type Warp,\r\n} from \"../kit/coords\";\r\nimport { fieldParams, parseField } from \"../kit/field\";\r\nimport { Axes2d, type Axes2dProps, type AxisLayout } from \"./axes2d\";\r\nimport { AXIS_COLOR } from \"../kit/furniture\";\r\nimport { stated } from \"../kit/geometry\";\r\nimport { lerpSource, readSource, type PlotSource } from \"../kit/source\";\r\n\r\nexport interface NumberPlaneProps extends Axes2dProps {\r\n grid?: boolean;\r\n gridStroke?: Stroke;\r\n minorStroke?: Stroke;\r\n minorDivisions?: number;\r\n matrix?: Matrix2 | readonly (readonly number[])[];\r\n warp?: string | PlotSource;\r\n ghost?: boolean;\r\n}\r\n\r\n/**\r\n * Axes over a full grid, with square units unless told otherwise: the plane\r\n * vectors and transformations are drawn on. Its `matrix` shears, turns or\r\n * squeezes the whole plane about its origin, and its `warp` bends it by a\r\n * function of its own points; the grid, the axes and everything on the plane\r\n * go with it.\r\n */\r\n@node({\r\n key: \"numberPlane\",\r\n parentKey: \"axes2d\",\r\n forkable: true,\r\n layout: { children: \"freeform\", defaultWidthMode: \"fixed\", defaultHeightMode: \"fixed\", acceptsChildren: true },\r\n seed: { width: 800, height: 500 },\r\n})\r\nexport class NumberPlane extends Axes2d<NumberPlaneProps> {\r\n @property({ default: true, animatable: false }) declare grid: boolean;\r\n /** The line at every tick. */\r\n @strokeProperty({ default: { weight: 1.5, fill: \"#3b4658\", align: \"center\" } }) declare gridStroke: Stroke;\r\n /** The lines between ticks. */\r\n @strokeProperty({ default: { weight: 1, fill: \"#232b38\", align: \"center\" } }) declare minorStroke: Stroke;\r\n /** How many parts the space between two ticks is cut into; one draws no line between them. */\r\n @property({ default: 2, min: 1, max: 10, step: 1 }) declare minorDivisions: number;\r\n\r\n /** A linear map of the plane, row by row: `[a, b, c, d]` sends `(x, y)` to `(ax + by, cx + dy)`. */\r\n @property({ default: [1, 0, 0, 1], mapper: readMatrix, tween: lerpMatrix }) declare matrix: Matrix2;\r\n /**\r\n * Where each point of the plane is sent, two parts in x and y:\r\n * `(x + sin(y), y + sin(x))`. Empty leaves the plane flat.\r\n */\r\n @property({ default: \"\", mapper: readSource, tween: lerpSource, kind: \"fieldEquation\" }) declare warp: PlotSource;\r\n /** Leave the plane as it was, faintly, behind one that has been transformed or warped. */\r\n @property({ default: true, animatable: false }) declare ghost: boolean;\r\n\r\n @property({ default: true, animatable: false }) declare squareUnits: boolean;\r\n @strokeProperty({ default: { weight: 2, fill: AXIS_COLOR, align: \"center\" } }) declare stroke: Stroke;\r\n\r\n constructor(props?: NodeConfig<NumberPlane, NumberPlaneProps>) {\r\n super((props ?? {}) as NodeConfig<Axes2d<NumberPlaneProps>, NumberPlaneProps>);\r\n // A transformed plane reaches past its box, and so does what is on it: both are kept in unless told otherwise.\r\n if (props?.clip === undefined) this.applyProp(\"clip\", () => this.coordinates.spills === true);\r\n }\r\n\r\n /** Send the plane through a matrix: a shear, a turn, a squeeze, a flip. */\r\n @command({ args: [\"matrix\"] })\r\n transformTo(args: CommandArgs<{ matrix: Matrix2 | readonly (readonly number[])[] }> & { duration: number }): Command<NumberPlaneProps> {\r\n return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });\r\n }\r\n\r\n /** Bend the plane, each point travelling to where the warp sends it; an empty one flattens it again. */\r\n @command({ args: [\"warp\"] })\r\n warpTo(args: CommandArgs<{ warp: string }> & { duration: number }): Command<NumberPlaneProps> {\r\n return this.to({ data: stated(args.data), duration: args.duration, easing: args.easing });\r\n }\r\n\r\n protected override mapFor(area: Extents): CoordinateMap {\r\n const flat = super.mapFor(area);\r\n this._flat = flat;\r\n const map = isIdentityMatrix(this.matrix) ? flat : transformedMap(flat, this.matrix);\r\n const { source, blend } = this.warp;\r\n const to = warpOf(source);\r\n if (!blend) return to ? warpedMap(map, to, source) : map;\r\n // Mid-warp each point is part of the way from where the old warp had it to where the new one sends it.\r\n const from = warpOf(blend.from);\r\n if (!from && !to) return map;\r\n const start = { x: 0, y: 0 };\r\n return warpedMap(\r\n map,\r\n (x, y, out) => {\r\n if (!(from ?? STAY)(x, y, start) || !(to ?? STAY)(x, y, out)) return false;\r\n out.x = start.x + (out.x - start.x) * blend.t;\r\n out.y = start.y + (out.y - start.y) * blend.t;\r\n return true;\r\n },\r\n `${blend.from}>${source}@${blend.t}`,\r\n );\r\n }\r\n\r\n protected override backdrop(map: CoordinateMap, x: AxisLayout, y: AxisLayout): Graphics2D[] {\r\n if (!this.grid) return [];\r\n const parts: Graphics2D[] = [];\r\n const flat = this._flat;\r\n if (this.ghost && flat && flat.revision !== map.revision) {\r\n const [gx, gy] = this.axes(flat);\r\n parts.push(...this._ruled(flat, gx, gy, true));\r\n }\r\n parts.push(...this._ruled(map, x, y, false));\r\n return parts;\r\n }\r\n\r\n private _flat: CoordinateMap | null = null;\r\n\r\n /** The grid of `map`: every line, or only the ones at a tick, in the fainter stroke, for a ghost. */\r\n private _ruled(map: CoordinateMap, x: AxisLayout, y: AxisLayout, ghost: boolean): Graphics2D[] {\r\n const { start, end } = this;\r\n const [xMin, xMax] = map.xRange;\r\n const [yMin, yMax] = map.yRange;\r\n const lines = (values: readonly number[], vertical: boolean): Graphics2D => {\r\n const g = new Graphics2D();\r\n for (const value of values) {\r\n g.line({\r\n points: vertical ? lineThrough(map, value, yMin, value, yMax) : lineThrough(map, xMin, value, xMax, value),\r\n radius: 0,\r\n start,\r\n end,\r\n });\r\n }\r\n return g;\r\n };\r\n const parts: Graphics2D[] = [];\r\n const minor = this.minorStroke as StrokeResolved[];\r\n if (ghost) {\r\n if (minor.length === 0) return parts;\r\n if (x.marks.values.length > 0) parts.push(lines(x.marks.values, true).stroke(minor));\r\n if (y.marks.values.length > 0) parts.push(lines(y.marks.values, false).stroke(minor));\r\n return parts;\r\n }\r\n const divisions = Math.round(this.minorDivisions);\r\n if (minor.length > 0 && divisions > 1) {\r\n const between = (axis: AxisLayout, [min, max]: readonly [number, number]): number[] => {\r\n const { step, values } = axis.marks;\r\n if (!(step > 0) || values.length === 0) return [];\r\n const out: number[] = [];\r\n for (let base = values[0] - step; base < max; base += step) {\r\n for (let i = 1; i < divisions; i++) {\r\n const value = base + (step * i) / divisions;\r\n if (value > min && value < max) out.push(value);\r\n }\r\n }\r\n return out;\r\n };\r\n const xs = between(x, map.xRange);\r\n const ys = between(y, map.yRange);\r\n if (xs.length > 0) parts.push(lines(xs, true).stroke(minor));\r\n if (ys.length > 0) parts.push(lines(ys, false).stroke(minor));\r\n }\r\n const major = this.gridStroke as StrokeResolved[];\r\n if (major.length > 0) {\r\n if (x.marks.values.length > 0) parts.push(lines(x.marks.values, true).stroke(major));\r\n if (y.marks.values.length > 0) parts.push(lines(y.marks.values, false).stroke(major));\r\n }\r\n return parts;\r\n }\r\n}\r\n\r\nconst STAY: Warp = (x, y, out) => {\r\n out.x = x;\r\n out.y = y;\r\n return true;\r\n};\r\n\r\n/** `source` as a warp, or `null` for text that is empty or not a field: the plane is then left as it is. */\r\nfunction warpOf(source: string): Warp | null {\r\n const field = source.trim() === \"\" ? null : parseField(source, fieldParams(source));\r\n if (!field || field instanceof Error) return null;\r\n const { x, y } = field;\r\n return (gx, gy, out) => {\r\n const wx = x(gx, gy);\r\n const wy = y(gx, gy);\r\n out.x = wx;\r\n out.y = wy;\r\n return Number.isFinite(wx) && Number.isFinite(wy);\r\n };\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"number-plane.js","sourceRoot":"","sources":["../../src/systems/number-plane.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,UAAU,EACV,KAAK,GAcR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACH,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,UAAU,EACV,cAAc,EACd,SAAS,GAIZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAmB,MAAM,eAAe,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChH,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAsD,MAAM,UAAU,CA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AAK,CAAC;AACjB,CAAC;AAED,MAAM,IAAI,GAAS,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE;IAC7B,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IACV,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AAEF,4GAA4G;AAC5G,SAAS,MAAM,CAAC,MAAc;IAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IACpF,IAAI,CAAC,KAAK,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,IAAI,CAAC;IAClD,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC;IACvB,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE;QACnB,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QACrB,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QACrB,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QACX,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QACX,OAAO,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACtD,CAAC,CAAC;AACN,CAAC","sourcesContent":["import {\r\n component2d,\r\n Graphics2D,\r\n Types,\r\n type Extents,\r\n type NodeOf,\r\n type Stroke,\r\n type StrokeResolved,\r\n // Named so the emitted declaration reaches these through the sdk, not core.\r\n type Color as _Color,\r\n type Fill as _Fill,\r\n type FillResolved as _FillResolved,\r\n type Node2D as _Node2D,\r\n type Node2DProps as _Node2DProps,\r\n type NormalizedColor as _NormalizedColor,\r\n type Shadow as _Shadow,\r\n type ShadowResolved as _ShadowResolved,\r\n} from \"@motionscript/sdk\";\r\nimport {\r\n isIdentityMatrix,\r\n lerpMatrix,\r\n lineThrough,\r\n readMatrix,\r\n transformedMap,\r\n warpedMap,\r\n type CoordinateMap,\r\n type Matrix2,\r\n type Warp,\r\n} from \"../kit/coords\";\r\nimport { fieldParams, parseField } from \"../kit/field\";\r\nimport { AXIS_COLOR } from \"../kit/furniture\";\r\nimport { lerpSource, readSource, type PlotSource } from \"../kit/source\";\r\nimport { drawSystem, plotArea, systemLayout, systemOpenPlane, systemProvides, systemSize } from \"../kit/system\";\r\nimport { AXES, AXES_COMMANDS, axesFurniture, axesMap, axesOf, loadAxes, type Axes2dProps, type AxesValues, type AxisLayout } from \"./axes2d\";\r\n\r\nexport interface NumberPlaneProps extends Axes2dProps {\r\n grid?: boolean;\r\n gridStroke?: Stroke;\r\n minorStroke?: Stroke;\r\n minorDivisions?: number;\r\n matrix?: Matrix2 | readonly (readonly number[])[];\r\n warp?: string | PlotSource;\r\n ghost?: boolean;\r\n}\r\n\r\nconst state = {\r\n ...AXES,\r\n grid: Types.boolean(true, { animatable: false }),\r\n /** The line at every tick. */\r\n gridStroke: Types.stroke({ weight: 1.5, fill: \"#3b4658\", align: \"center\" }),\r\n /** The lines between ticks. */\r\n minorStroke: Types.stroke({ weight: 1, fill: \"#232b38\", align: \"center\" }),\r\n /** How many parts the space between two ticks is cut into; one draws no line between them. */\r\n minorDivisions: Types.number(2, { min: 1, max: 10, step: 1 }),\r\n /** A linear map of the plane, row by row: `[a, b, c, d]` sends `(x, y)` to `(ax + by, cx + dy)`. */\r\n matrix: Types.custom<Matrix2 | readonly (readonly number[])[], Matrix2>([1, 0, 0, 1], { resolve: readMatrix, lerp: lerpMatrix }),\r\n /**\r\n * Where each point of the plane is sent, two parts in x and y:\r\n * `(x + sin(y), y + sin(x))`. Empty leaves the plane flat.\r\n */\r\n warp: Types.custom<string | PlotSource, PlotSource>(\"\", { resolve: readSource, lerp: lerpSource, kind: \"fieldEquation\" }),\r\n /** Leave the plane as it was, faintly, behind one that has been transformed or warped. */\r\n ghost: Types.boolean(true, { animatable: false }),\r\n};\r\n\r\ntype PlaneValues = AxesValues & {\r\n readonly grid: boolean;\r\n readonly gridStroke: StrokeResolved[];\r\n readonly minorStroke: StrokeResolved[];\r\n readonly minorDivisions: number;\r\n readonly matrix: Matrix2;\r\n readonly warp: PlotSource;\r\n readonly ghost: boolean;\r\n};\r\n\r\n/**\r\n * Axes over a full grid, with square units unless told otherwise: the plane\r\n * vectors and transformations are drawn on. Its `matrix` shears, turns or\r\n * squeezes the whole plane about its origin, and its `warp` bends it by a\r\n * function of its own points; the grid, the axes and everything on the plane\r\n * go with it.\r\n */\r\nexport const NumberPlane = component2d({\r\n key: \"numberPlane\",\r\n state,\r\n defaults: {\r\n squareUnits: true,\r\n stroke: { weight: 2, fill: AXIS_COLOR, align: \"center\" },\r\n // A transformed plane reaches past its box, and so does what is on it: both are kept in unless told otherwise.\r\n clip: (s) => spills(s),\r\n },\r\n load: (loader, s) => loadAxes(loader, s),\r\n commands: {\r\n ...AXES_COMMANDS,\r\n /** Send the plane through a matrix: a shear, a turn, a squeeze, a flip. */\r\n transformTo: { args: [\"matrix\"] },\r\n /** Bend the plane, each point travelling to where the warp sends it; an empty one flattens it again. */\r\n warpTo: { args: [\"warp\"] },\r\n },\r\n provide: (s) => systemProvides(s),\r\n measure: (_measurer, s) => systemSize(s),\r\n layout: (box, s, children) => systemLayout(box, s, children, planeMap),\r\n plane: (box, s) => systemOpenPlane(box, s, planeMap),\r\n render: (ctx, s) => {\r\n const { flat, map } = planeMaps(plotArea(ctx.size, s.padding), s);\r\n drawSystem(ctx, s, map, (on) => axesFurniture(on, s, (x, y) => grid(s, flat, on, x, y)));\r\n },\r\n});\r\n\r\nexport type NumberPlane = NodeOf<typeof NumberPlane>;\r\n\r\n/** The plane's map on a plot area: the flat one, sent through its matrix and its warp. */\r\nexport function planeMap(area: Extents, s: PlaneValues): CoordinateMap {\r\n return planeMaps(area, s).map;\r\n}\r\n\r\n/** The flat plane on a plot area, and the plane as its matrix and its warp have it. */\r\nfunction planeMaps(area: Extents, s: PlaneValues): { flat: CoordinateMap; map: CoordinateMap } {\r\n const flat = axesMap(area, s);\r\n const map = isIdentityMatrix(s.matrix) ? flat : transformedMap(flat, s.matrix);\r\n const { source, blend } = s.warp;\r\n const to = warpOf(source);\r\n if (!blend) return { flat, map: to ? warpedMap(map, to, source) : map };\r\n // Mid-warp each point is part of the way from where the old warp had it to where the new one sends it.\r\n const from = warpOf(blend.from);\r\n if (!from && !to) return { flat, map };\r\n const start = { x: 0, y: 0 };\r\n return {\r\n flat,\r\n map: warpedMap(\r\n map,\r\n (x, y, out) => {\r\n if (!(from ?? STAY)(x, y, start) || !(to ?? STAY)(x, y, out)) return false;\r\n out.x = start.x + (out.x - start.x) * blend.t;\r\n out.y = start.y + (out.y - start.y) * blend.t;\r\n return true;\r\n },\r\n `${blend.from}>${source}@${blend.t}`,\r\n ),\r\n };\r\n}\r\n\r\n/** Whether the plane reaches past its box: it is transformed or warped. */\r\nfunction spills(s: PlaneValues): boolean {\r\n if (!isIdentityMatrix(s.matrix)) return true;\r\n const { source, blend } = s.warp;\r\n return warpOf(source) !== null || (blend !== undefined && warpOf(blend.from) !== null);\r\n}\r\n\r\n/** The grid behind the axes, with the flat plane faintly behind a transformed one. */\r\nfunction grid(s: PlaneValues, flat: CoordinateMap, map: CoordinateMap, x: AxisLayout, y: AxisLayout): Graphics2D[] {\r\n if (!s.grid) return [];\r\n const parts: Graphics2D[] = [];\r\n if (s.ghost && flat.revision !== map.revision) {\r\n const [gx, gy] = axesOf(flat, s);\r\n parts.push(...ruled(s, flat, gx, gy, true));\r\n }\r\n parts.push(...ruled(s, map, x, y, false));\r\n return parts;\r\n}\r\n\r\n/** The grid of `map`: every line, or only the ones at a tick, in the fainter stroke, for a ghost. */\r\nfunction ruled(s: PlaneValues, map: CoordinateMap, x: AxisLayout, y: AxisLayout, ghost: boolean): Graphics2D[] {\r\n const { start, end } = s;\r\n const [xMin, xMax] = map.xRange;\r\n const [yMin, yMax] = map.yRange;\r\n const lines = (values: readonly number[], vertical: boolean): Graphics2D => {\r\n const g = new Graphics2D();\r\n for (const value of values) {\r\n g.line({\r\n points: vertical ? lineThrough(map, value, yMin, value, yMax) : lineThrough(map, xMin, value, xMax, value),\r\n radius: 0,\r\n start,\r\n end,\r\n });\r\n }\r\n return g;\r\n };\r\n const parts: Graphics2D[] = [];\r\n const minor = s.minorStroke;\r\n if (ghost) {\r\n if (minor.length === 0) return parts;\r\n if (x.marks.values.length > 0) parts.push(lines(x.marks.values, true).stroke(minor));\r\n if (y.marks.values.length > 0) parts.push(lines(y.marks.values, false).stroke(minor));\r\n return parts;\r\n }\r\n const divisions = Math.round(s.minorDivisions);\r\n if (minor.length > 0 && divisions > 1) {\r\n const between = (axis: AxisLayout, [min, max]: readonly [number, number]): number[] => {\r\n const { step, values } = axis.marks;\r\n if (!(step > 0) || values.length === 0) return [];\r\n const out: number[] = [];\r\n for (let base = values[0] - step; base < max; base += step) {\r\n for (let i = 1; i < divisions; i++) {\r\n const value = base + (step * i) / divisions;\r\n if (value > min && value < max) out.push(value);\r\n }\r\n }\r\n return out;\r\n };\r\n const xs = between(x, map.xRange);\r\n const ys = between(y, map.yRange);\r\n if (xs.length > 0) parts.push(lines(xs, true).stroke(minor));\r\n if (ys.length > 0) parts.push(lines(ys, false).stroke(minor));\r\n }\r\n const major = s.gridStroke;\r\n if (major.length > 0) {\r\n if (x.marks.values.length > 0) parts.push(lines(x.marks.values, true).stroke(major));\r\n if (y.marks.values.length > 0) parts.push(lines(y.marks.values, false).stroke(major));\r\n }\r\n return parts;\r\n}\r\n\r\nconst STAY: Warp = (x, y, out) => {\r\n out.x = x;\r\n out.y = y;\r\n return true;\r\n};\r\n\r\n/** `source` as a warp, or `null` for text that is empty or not a field: the plane is then left as it is. */\r\nfunction warpOf(source: string): Warp | null {\r\n const field = source.trim() === \"\" ? null : parseField(source, fieldParams(source));\r\n if (!field || field instanceof Error) return null;\r\n const { x, y } = field;\r\n return (gx, gy, out) => {\r\n const wx = x(gx, gy);\r\n const wy = y(gx, gy);\r\n out.x = wx;\r\n out.y = wy;\r\n return Number.isFinite(wx) && Number.isFinite(wy);\r\n };\r\n}\r\n"]}
|