@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
package/src/engine.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The math **kit**: what the nodes share, and what a copied one does not copy.
|
|
3
3
|
*
|
|
4
4
|
* `ms add` writes a node's own files into a project and rewrites its reach for
|
|
5
|
-
* these to `@motionscript/math`, so MathJax, the morph and every shared
|
|
5
|
+
* these to `@motionscript/math`, so MathJax, the morph and every shared module
|
|
6
6
|
* stay a real dependency with one identity.
|
|
7
7
|
*/
|
|
8
8
|
export {
|
|
@@ -13,19 +13,31 @@ export { defaultLatexMorph } from './tex/tween';
|
|
|
13
13
|
export type { AnimatedToken, LatexMorphStrategy } from './tex/tween';
|
|
14
14
|
export { Latex } from './tex/node';
|
|
15
15
|
export type { LatexProps, LatexStrategies } from './tex/node';
|
|
16
|
+
export {
|
|
17
|
+
drawFormula, formula, formulaFrame, formulaOf, isFormula, latexPartBounds, layoutFormula, lerpMorph, loadFormula, measureFormula, Morph, morphOf,
|
|
18
|
+
partBoundsIn, settled, TYPESET, TYPESET_COMMANDS,
|
|
19
|
+
} from './tex/typeset';
|
|
20
|
+
export type { FormulaFrame, Morphing, TypesetValues } from './tex/typeset';
|
|
16
21
|
export { lerpPartFills, partPaint, readPartFills, withPartFill } from './kit/part-fills';
|
|
17
22
|
export type { PartFill, PartFillResolved } from './kit/part-fills';
|
|
18
23
|
export { FILL_PAINT, OUTLINE_TRIM, STROKE_PAINT } from './kit/withdrawn';
|
|
19
24
|
export { createBoundedCache } from './kit/cache';
|
|
25
|
+
export { listed, omit, PAINT, PAINT_COMMANDS, painted } from './kit/component';
|
|
20
26
|
export type { BoundedCache } from './kit/cache';
|
|
21
27
|
|
|
22
|
-
export {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
export
|
|
26
|
-
export type {
|
|
27
|
-
export {
|
|
28
|
-
export {
|
|
28
|
+
export { drawSystem, plotArea, systemLayout, systemMap, systemOpenPlane, systemProvides, systemSize } from './kit/system';
|
|
29
|
+
export type { MapFor, SystemState } from './kit/system';
|
|
30
|
+
// A number plane is axes with a grid, so a copied one builds on these rather than a copy of them.
|
|
31
|
+
export { Axes2d, AXES, AXES_COMMANDS, axesFurniture, axesMap, axesOf, loadAxes } from './systems/axes2d';
|
|
32
|
+
export type { Axes2dProps, AxesValues, AxisLayout } from './systems/axes2d';
|
|
33
|
+
export type { Anchor } from './kit/place';
|
|
34
|
+
export { anchored, openPlane, placeOnMap } from './kit/place';
|
|
35
|
+
export {
|
|
36
|
+
castsShadow, drawMark, graphPoint, inkCentre, inkSize, markRuns, markShape, ownPoint, reading, strokeShape, traced,
|
|
37
|
+
} from './kit/mark';
|
|
38
|
+
export type { MarkOptions, MarkPaint, MarkReading, MarkState, Tracer } from './kit/mark';
|
|
39
|
+
export { curveFor, PLANE_ENTRY, PLOT, PLOT_REF, plotPlane, refId, settle, SYSTEM, SYSTEM_ENTRY, systemPlane } from './kit/graph';
|
|
40
|
+
export type { GraphPlane } from './kit/graph';
|
|
29
41
|
export { axisScale, cartesianMap, resolveInterval, PIXEL_MAP } from './kit/coords';
|
|
30
42
|
export type { AxisScale, AxisScaling, CartesianOptions, CoordinateMap, Interval } from './kit/coords';
|
|
31
43
|
export { compileExpression, compileExpressionCached, expressionVocabulary, MATH_DIALECT } from './kit/expression';
|
|
@@ -39,30 +51,32 @@ export type { CurveProjection, SampleOptions } from './kit/sampler';
|
|
|
39
51
|
export { formatTick, ticksFor } from './kit/ticks';
|
|
40
52
|
export type { Ticks } from './kit/ticks';
|
|
41
53
|
export { boundsOfRuns, clamp, inflate, runsToPath, stated } from './kit/geometry';
|
|
42
|
-
export {
|
|
43
|
-
export type {
|
|
44
|
-
export { along, AXIS_COLOR, drawLabels, drawn, lerpInterval, PLOT_COLOR, readInterval, withoutTips } from './kit/furniture';
|
|
54
|
+
export { CURVE_KEYS, curveValue, isCurve } from './kit/curve';
|
|
55
|
+
export type { CurveValues } from './kit/curve';
|
|
56
|
+
export { along, AXIS_COLOR, declareFormulas, drawLabels, drawn, lerpInterval, loadFormulas, PLOT_COLOR, readInterval, withoutTips } from './kit/furniture';
|
|
45
57
|
export type { Label, LabelStyle } from './kit/furniture';
|
|
46
|
-
export {
|
|
47
|
-
|
|
58
|
+
export {
|
|
59
|
+
add, between, container, FOLLOW_COMMANDS, FOLLOW_STATE, followedQuad, grown, heading, outlineBounds, OWN_FRAME, resting,
|
|
60
|
+
} from './kit/follow';
|
|
61
|
+
export type { FollowProps, FollowValues, Parted, Quad, Retarget, Target } from './kit/follow';
|
|
48
62
|
export {
|
|
49
63
|
parseSpaceCurve, parseSurface, spaceCurveError, spaceCurveParams, surfaceError, surfaceParams, EQUATION_KINDS, EQUATION_VARIABLES_3D,
|
|
50
64
|
} from './kit/equation3d';
|
|
51
65
|
export type { EquationLanguage, SpaceCurveEquation, SurfaceEquation } from './kit/equation3d';
|
|
52
|
-
export { aim, graphSpace, spaceOf } from './three/space';
|
|
53
|
-
export type { GraphSpace } from './three/space';
|
|
66
|
+
export { aim, graphEntry, graphOf, graphSpace, spaceOf, GRAPH_3D } from './three/space';
|
|
67
|
+
export type { Graph3D, GraphSpace } from './three/space';
|
|
68
|
+
export { domainEntry, meshEntries } from './three/entries';
|
|
54
69
|
export { drawLabel3D } from './three/label3d';
|
|
55
70
|
export type { LabelStyle3D } from './three/label3d';
|
|
56
|
-
// A traced path is a plot whose span follows a value, so a copied one
|
|
57
|
-
export { FunctionPlot } from './plots/function-plot';
|
|
58
|
-
export type { FunctionPlotProps } from './plots/function-plot';
|
|
59
|
-
export {
|
|
60
|
-
export type { FieldProps, FieldSampler, FieldStroke } from './kit/field-mark';
|
|
71
|
+
// A traced path is a plot whose span follows a value, so a copied one builds on these rather than a copy of them.
|
|
72
|
+
export { FunctionPlot, PLOT_COMMANDS, PLOT_STATE, PLOT_STROKE, tracePlot } from './plots/function-plot';
|
|
73
|
+
export type { FunctionPlotProps, PlotValues } from './plots/function-plot';
|
|
74
|
+
export { drawField, FIELD_COMMANDS, FIELD_STATE, traceField } from './kit/field-mark';
|
|
75
|
+
export type { FieldDrawing, FieldProps, FieldSampler, FieldStroke, FieldValues } from './kit/field-mark';
|
|
61
76
|
export { fieldError, fieldParams, parseField, FIELD_VARIABLES } from './kit/field';
|
|
62
77
|
export type { FieldEquation } from './kit/field';
|
|
63
78
|
export { traceContour } from './kit/contour';
|
|
64
79
|
export { colorAt, fillAt, lerpFillScale, lerpScale, readFillScale, readScale } from './kit/scale';
|
|
65
|
-
export { SYSTEMS, SYSTEMS_AND_PLOT } from './kit/placement';
|
|
66
80
|
export {
|
|
67
81
|
IDENTITY_MATRIX, isIdentityMatrix, lerpMatrix, lineThrough, readMatrix, transformedMap, warpedMap,
|
|
68
82
|
} from './kit/coords';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Paint,
|
|
3
|
+
Types,
|
|
4
|
+
type EntryOptions,
|
|
5
|
+
type RenderContext,
|
|
6
|
+
type Type,
|
|
7
|
+
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
8
|
+
type Fill as _Fill,
|
|
9
|
+
type FillResolved as _FillResolved,
|
|
10
|
+
type Shadow as _Shadow,
|
|
11
|
+
type ShadowResolved as _ShadowResolved,
|
|
12
|
+
type Stroke as _Stroke,
|
|
13
|
+
type StrokeResolved as _StrokeResolved,
|
|
14
|
+
} from "@motionscript/sdk";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* What a component in this kit shares beyond the factory: the paints a math
|
|
18
|
+
* node draws with, listed choices, and the order a node paints in.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const { overlay: _overlay, ...paint } = Paint.state;
|
|
22
|
+
const { overlayTo: _overlayTo, ...paintCommands } = Paint.commands;
|
|
23
|
+
|
|
24
|
+
/** A math node's paints: fill, stroke, shadow and the outline trim, with no overlay. */
|
|
25
|
+
export const PAINT = paint;
|
|
26
|
+
export const PAINT_COMMANDS = paintCommands;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* One of `values`, held as text with its choices listed (no `kind: "enum"`).
|
|
30
|
+
*/
|
|
31
|
+
export function listed<const V extends readonly string[]>(values: V, initial: V[number], options?: ListedOptions): Type<V[number]>;
|
|
32
|
+
/** With no default: an arg left out is one the command was not given. */
|
|
33
|
+
export function listed<const V extends readonly string[]>(values: V, initial: undefined, options?: ListedOptions): Type<V[number] | undefined>;
|
|
34
|
+
export function listed(values: readonly string[], initial: string | undefined, options: ListedOptions = {}): Type<string | undefined> {
|
|
35
|
+
return Types.custom<string | undefined, string | undefined, EntryOptions & { readonly options: readonly string[] }>(initial, { ...options, options: values });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface ListedOptions {
|
|
39
|
+
readonly animatable?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** `record` without `keys`: the paints a node has no use for. */
|
|
43
|
+
export function omit<T extends object, const K extends keyof T>(record: T, ...keys: K[]): Omit<T, K> {
|
|
44
|
+
const out = { ...record };
|
|
45
|
+
for (const key of keys) delete out[key];
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* A node's paint order: its own paint under its children, then what it lays
|
|
51
|
+
* over them, each cut at the near plane of a space it crosses.
|
|
52
|
+
*/
|
|
53
|
+
export function painted(ctx: RenderContext, own: () => void, over: () => void = () => { }): void {
|
|
54
|
+
ctx.inFront(own);
|
|
55
|
+
ctx.children();
|
|
56
|
+
ctx.inFront(over);
|
|
57
|
+
}
|
package/src/kit/curve.ts
CHANGED
|
@@ -1,29 +1,47 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { NodeView } from "@motionscript/sdk";
|
|
2
|
+
import { equationParams, parseEquation } from "./equation";
|
|
3
|
+
import type { ExpressionScope } from "./expression";
|
|
4
|
+
import { scopeFor, type PlotSource } from "./source";
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
|
-
* A
|
|
5
|
-
*
|
|
7
|
+
* A curve as a mark reads it: what a plot is drawn from, its own `x`/`y`, and
|
|
8
|
+
* whether a system laid it out, which is when those are a shift in graph units.
|
|
9
|
+
* Data rather than a class, so a copied plot is ridden like the kit's own.
|
|
6
10
|
*/
|
|
7
|
-
export interface
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
export interface CurveValues {
|
|
12
|
+
readonly expression: PlotSource;
|
|
13
|
+
readonly params: ExpressionScope;
|
|
14
|
+
readonly x: number;
|
|
15
|
+
readonly y: number;
|
|
16
|
+
/** The plane the plot was laid out on; `null` outside any system. */
|
|
17
|
+
readonly graph?: object | null;
|
|
10
18
|
}
|
|
11
19
|
|
|
12
|
-
/** The
|
|
13
|
-
export
|
|
14
|
-
if (id === "") return null;
|
|
15
|
-
const found = findNode2D(from, id) as (Node2D & Partial<Curve>) | null;
|
|
16
|
-
return found && typeof found.valueAt === "function" ? (found as Node2D & Curve) : null;
|
|
17
|
-
}
|
|
20
|
+
/** The node types a point, a tangent or an area can ride: they have a height at each `x`. */
|
|
21
|
+
export const CURVE_KEYS: readonly string[] = ["functionPlot", "tracedPath"];
|
|
18
22
|
|
|
19
23
|
/**
|
|
20
|
-
* The curve
|
|
21
|
-
*
|
|
24
|
+
* The curve's height at graph `x`, or `NaN` where it has none or is not a
|
|
25
|
+
* function of `x`. What a point, a tangent or an area riding a plot reads.
|
|
22
26
|
*/
|
|
23
|
-
export function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
export function curveValue(curve: CurveValues, x: number): number {
|
|
28
|
+
const { source, blend } = curve.expression;
|
|
29
|
+
const shift = curve.graph ? curve : NO_SHIFT;
|
|
30
|
+
const value = heightOf(source, curve.params, x - shift.x) + shift.y;
|
|
31
|
+
if (!blend) return value;
|
|
32
|
+
const from = heightOf(blend.from, curve.params, x - shift.x) + shift.y;
|
|
33
|
+
return from + (value - from) * blend.t;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Whether `view` is a node a mark can ride. */
|
|
37
|
+
export function isCurve(view: unknown): view is NodeView & { readonly state: CurveValues } {
|
|
38
|
+
return typeof view === "object" && view !== null && CURVE_KEYS.includes((view as { key?: string }).key ?? "");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const NO_SHIFT = { x: 0, y: 0 };
|
|
42
|
+
|
|
43
|
+
function heightOf(source: string, params: ExpressionScope, x: number): number {
|
|
44
|
+
const equation = parseEquation(source, equationParams(source));
|
|
45
|
+
if (equation instanceof Error || equation.kind !== "function" || equation.of !== "x") return NaN;
|
|
46
|
+
return equation.f(x, 0, scopeFor(equationParams(source), params));
|
|
29
47
|
}
|
package/src/kit/field-mark.ts
CHANGED
|
@@ -1,25 +1,34 @@
|
|
|
1
1
|
import {
|
|
2
|
-
command,
|
|
3
2
|
Graphics2D,
|
|
4
|
-
|
|
5
|
-
withdraw,
|
|
6
|
-
type Command,
|
|
7
|
-
type CommandArgs,
|
|
3
|
+
Types,
|
|
8
4
|
type Fill,
|
|
9
5
|
type FillResolved,
|
|
10
6
|
type PaintProps,
|
|
11
|
-
type
|
|
7
|
+
type RenderContext,
|
|
12
8
|
type StrokeResolved,
|
|
13
9
|
type Vector2,
|
|
10
|
+
// Named so the emitted declaration reaches these through the sdk, not core.
|
|
11
|
+
type Shadow as _Shadow,
|
|
12
|
+
type ShadowResolved as _ShadowResolved,
|
|
13
|
+
type Stroke as _Stroke,
|
|
14
14
|
} from "@motionscript/sdk";
|
|
15
|
+
import { createBoundedCache } from "./cache";
|
|
16
|
+
import { omit, PAINT, PAINT_COMMANDS } from "./component";
|
|
15
17
|
import type { CoordinateMap } from "./coords";
|
|
16
18
|
import type { ExpressionScope } from "./expression";
|
|
17
19
|
import { fieldParams, parseField } from "./field";
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
+
import { runsToPath } from "./geometry";
|
|
21
|
+
import { PLANE_ENTRY } from "./graph";
|
|
22
|
+
import { drawMark, type MarkPaint, type MarkReading } from "./mark";
|
|
20
23
|
import { fillAt, lerpFillScale, readFillScale } from "./scale";
|
|
21
24
|
import { lerpParams, lerpSource, readSource, scopeFor, type PlotSource } from "./source";
|
|
22
|
-
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* What a mark drawn from a vector field, `(P(x, y), Q(x, y))`, shares: arrows,
|
|
28
|
+
* or the lines that follow it, all in one stroke. Without strength fills it is
|
|
29
|
+
* one path in the stroke's paint; with them, what it draws is sorted by the
|
|
30
|
+
* field's strength into a few shades.
|
|
31
|
+
*/
|
|
23
32
|
|
|
24
33
|
export interface FieldProps extends PaintProps {
|
|
25
34
|
expression?: string | PlotSource;
|
|
@@ -40,116 +49,123 @@ export interface FieldStroke {
|
|
|
40
49
|
/** How many shades the strength fills are drawn in: each is one path. */
|
|
41
50
|
const SHADES = 12;
|
|
42
51
|
|
|
43
|
-
/**
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
* strength into a few shades.
|
|
48
|
-
*/
|
|
49
|
-
@withdraw(...FILL_PAINT, ...OUTLINE_TRIM)
|
|
50
|
-
export abstract class FieldMark<P extends FieldProps = FieldProps> extends Mark<P> {
|
|
51
|
-
@property({ default: "", mapper: readSource, tween: lerpSource, kind: "fieldEquation" })
|
|
52
|
-
declare expression: PlotSource;
|
|
53
|
-
|
|
52
|
+
/** A field mark's entries. It is only strokes, revealed its own way: it has no fill and trims no outline. */
|
|
53
|
+
export const FIELD_STATE = {
|
|
54
|
+
...omit(PAINT, "fill", "start", "end"),
|
|
55
|
+
expression: Types.custom<string | PlotSource, PlotSource>("", { resolve: readSource, lerp: lerpSource, kind: "fieldEquation" }),
|
|
54
56
|
/** The equation's named values: any name in it that is not `x`, `y`, a function or a constant. */
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
params: Types.custom<ExpressionScope>({}, { lerp: lerpParams }),
|
|
57
58
|
/** Paints by the field's strength, weakest first. Empty draws everything in the stroke's own paint. */
|
|
58
|
-
|
|
59
|
+
strengthFills: Types.custom<Fill[], FillResolved[][]>([], { resolve: readFillScale, lerp: lerpFillScale, kind: "vector" }),
|
|
59
60
|
/** The strength the last paint stands for; zero takes the strongest the field is where it is drawn. */
|
|
60
|
-
|
|
61
|
+
maxMagnitude: Types.number(0, { min: 0, step: 0.1 }),
|
|
62
|
+
graph: PLANE_ENTRY,
|
|
63
|
+
};
|
|
61
64
|
|
|
65
|
+
export const FIELD_COMMANDS = {
|
|
66
|
+
...omit(PAINT_COMMANDS, "fillTo", "progressTo", "flash"),
|
|
62
67
|
/** Change the field, each vector turning from the one into the other. */
|
|
63
|
-
|
|
64
|
-
morphTo(args: CommandArgs<{ expression: string }> & { duration: number }): Command<P> {
|
|
65
|
-
return this.to({ data: stated(args.data) as Partial<P>, duration: args.duration, easing: args.easing });
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
+
morphTo: { args: ["expression"] as const },
|
|
68
69
|
/** Animate the equation's named values. */
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return this.to({ data: stated(args.data) as Partial<P>, duration: args.duration, easing: args.easing });
|
|
72
|
-
}
|
|
70
|
+
paramsTo: { args: ["params"] as const },
|
|
71
|
+
};
|
|
73
72
|
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
/** What a field mark is drawn from. */
|
|
74
|
+
export interface FieldValues {
|
|
75
|
+
readonly expression: PlotSource;
|
|
76
|
+
readonly params: ExpressionScope;
|
|
77
|
+
}
|
|
76
78
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
/** What one kind of field mark draws of `field` through `map`, and the entries of its own that change it. */
|
|
80
|
+
export interface FieldDrawing<S> {
|
|
81
|
+
strokes(s: S, map: CoordinateMap, field: FieldSampler): FieldStroke[];
|
|
82
|
+
/** The entries of its own that change what `strokes` returns, as a key. */
|
|
83
|
+
own(s: S): string;
|
|
84
|
+
}
|
|
79
85
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const shift = this.shift();
|
|
85
|
-
const key = [source, blend?.from, blend?.t, map.revision, JSON.stringify(this.params), shift.x, shift.y, this.own()].join("|");
|
|
86
|
-
if (key !== this._key) {
|
|
87
|
-
this._key = key;
|
|
88
|
-
const field = this._sampler(shift);
|
|
89
|
-
this._drawn = field ? this.strokes(map, field) : [];
|
|
90
|
-
this._runs = this._drawn.flatMap((stroke) => stroke.runs);
|
|
91
|
-
}
|
|
92
|
-
return this._runs;
|
|
93
|
-
}
|
|
86
|
+
interface Traced {
|
|
87
|
+
readonly drawn: FieldStroke[];
|
|
88
|
+
readonly runs: Vector2[][];
|
|
89
|
+
}
|
|
94
90
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
ctx.draw(
|
|
113
|
-
new Graphics2D()
|
|
114
|
-
.path({ data: runsToPath(runs), centerBounds: [ink.minX, ink.minY, ink.maxX, ink.maxY], start: this.start, end: this.end })
|
|
115
|
-
.shadow(this.shadow)
|
|
116
|
-
.stroke(stroke.map((layer) => ({ ...layer, fill }))),
|
|
117
|
-
);
|
|
118
|
-
});
|
|
119
|
-
}
|
|
91
|
+
const traces = createBoundedCache<Traced>(64);
|
|
92
|
+
const EMPTY: Traced = { drawn: [], runs: [] };
|
|
93
|
+
|
|
94
|
+
/** What a field mark of `kind` draws through `read`: each stroke with its strength, and all their runs. */
|
|
95
|
+
export function traceField<S extends FieldValues>(kind: string, drawing: FieldDrawing<S>, s: S, { map, shift }: MarkReading): Traced {
|
|
96
|
+
const { area } = map;
|
|
97
|
+
if (!Number.isFinite(area.maxX - area.minX)) return EMPTY;
|
|
98
|
+
const { source, blend } = s.expression;
|
|
99
|
+
const key = [kind, source, blend?.from, blend?.t, map.revision, JSON.stringify(s.params), shift.x, shift.y, drawing.own(s)].join("|");
|
|
100
|
+
const known = traces.get(key);
|
|
101
|
+
if (known) return known;
|
|
102
|
+
const field = sampler(s, shift);
|
|
103
|
+
const drawn = field ? drawing.strokes(s, map, field) : [];
|
|
104
|
+
const traced = { drawn, runs: drawn.flatMap((stroke) => stroke.runs) };
|
|
105
|
+
traces.set(key, traced);
|
|
106
|
+
return traced;
|
|
107
|
+
}
|
|
120
108
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
109
|
+
/** A field mark's paint: one stroke, or a shade per strength when it has strength fills. */
|
|
110
|
+
export function drawField(
|
|
111
|
+
ctx: RenderContext,
|
|
112
|
+
s: MarkPaint & { readonly strengthFills: FillResolved[][]; readonly maxMagnitude: number },
|
|
113
|
+
{ drawn, runs }: Traced,
|
|
114
|
+
): void {
|
|
115
|
+
const scale = s.strengthFills;
|
|
116
|
+
const stroke = s.stroke as StrokeResolved[];
|
|
117
|
+
const shaded = scale.length > 0 && stroke.length > 0;
|
|
118
|
+
drawMark(ctx, s, runs, {
|
|
119
|
+
ink: shaded
|
|
120
|
+
? (ctx, ink) => {
|
|
121
|
+
const top = s.maxMagnitude > 0 ? s.maxMagnitude : drawn.reduce((most, d) => Math.max(most, d.magnitude), 0);
|
|
122
|
+
const shades: Vector2[][][] = Array.from({ length: SHADES }, () => []);
|
|
123
|
+
for (const d of drawn) {
|
|
124
|
+
const share = top > 0 ? Math.min(1, d.magnitude / top) : 0;
|
|
125
|
+
shades[Math.min(SHADES - 1, Math.floor(share * SHADES))].push(...d.runs);
|
|
126
|
+
}
|
|
127
|
+
shades.forEach((shade, index) => {
|
|
128
|
+
if (shade.length === 0) return;
|
|
129
|
+
const fill = fillAt(scale, (index + 0.5) / SHADES);
|
|
130
|
+
ctx.draw(
|
|
131
|
+
new Graphics2D()
|
|
132
|
+
.path({ data: runsToPath(shade), centerBounds: [ink.minX, ink.minY, ink.maxX, ink.maxY], start: s.start ?? 0, end: s.end ?? 1 })
|
|
133
|
+
.shadow(s.shadow)
|
|
134
|
+
.stroke(stroke.map((layer) => ({ ...layer, fill }))),
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
: undefined,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
124
141
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
142
|
+
/** The field at a graph point, measured from the mark's own shift, mid-morph a blend of two. */
|
|
143
|
+
function sampler(s: FieldValues, shift: Vector2): FieldSampler | null {
|
|
144
|
+
const { source, blend } = s.expression;
|
|
145
|
+
const to = fieldOf(source, s.params, shift);
|
|
146
|
+
if (!to || !blend) return to;
|
|
147
|
+
const from = fieldOf(blend.from, s.params, shift);
|
|
148
|
+
if (!from) return to;
|
|
149
|
+
const start: Vector2 = { x: 0, y: 0 };
|
|
150
|
+
return (x, y, out) => {
|
|
151
|
+
if (!from(x, y, start) || !to(x, y, out)) return false;
|
|
152
|
+
out.x = start.x + (out.x - start.x) * blend.t;
|
|
153
|
+
out.y = start.y + (out.y - start.y) * blend.t;
|
|
154
|
+
return true;
|
|
155
|
+
};
|
|
156
|
+
}
|
|
140
157
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
158
|
+
function fieldOf(source: string, params: ExpressionScope, shift: Vector2): FieldSampler | null {
|
|
159
|
+
const names = fieldParams(source);
|
|
160
|
+
const field = parseField(source, names);
|
|
161
|
+
if (field instanceof Error) return null;
|
|
162
|
+
const scope = scopeFor(names, params);
|
|
163
|
+
const { x, y } = field;
|
|
164
|
+
return (gx, gy, out) => {
|
|
165
|
+
const vx = x(gx - shift.x, gy - shift.y, scope);
|
|
166
|
+
const vy = y(gx - shift.x, gy - shift.y, scope);
|
|
167
|
+
out.x = vx;
|
|
168
|
+
out.y = vy;
|
|
169
|
+
return Number.isFinite(vx) && Number.isFinite(vy);
|
|
170
|
+
};
|
|
155
171
|
}
|