@motionscript/math 0.0.0-stage → 0.1.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +110 -0
- package/LICENSE +201 -0
- package/NOTICE +48 -0
- package/README.md +385 -3
- package/dist/annotate/angle-mark.d.ts +46 -0
- package/dist/annotate/angle-mark.d.ts.map +1 -0
- package/dist/annotate/angle-mark.js +132 -0
- package/dist/annotate/angle-mark.js.map +1 -0
- package/dist/annotate/curly-brace.d.ts +46 -0
- package/dist/annotate/curly-brace.d.ts.map +1 -0
- package/dist/annotate/curly-brace.js +114 -0
- package/dist/annotate/curly-brace.js.map +1 -0
- package/dist/annotate/emphasis-mark.d.ts +20 -0
- package/dist/annotate/emphasis-mark.d.ts.map +1 -0
- package/dist/annotate/emphasis-mark.js +81 -0
- package/dist/annotate/emphasis-mark.js.map +1 -0
- package/dist/browser/THIRD_PARTY_LICENSES.txt +420 -0
- package/dist/browser/chunks/chunk-3GJB6AVO.js +2 -0
- package/dist/browser/chunks/chunk-3GJB6AVO.js.map +7 -0
- package/dist/browser/chunks/chunk-D5WHCVBC.js +2 -0
- package/dist/browser/chunks/chunk-D5WHCVBC.js.map +7 -0
- package/dist/browser/chunks/chunk-WL4KEX7Y.js +2 -0
- package/dist/browser/chunks/chunk-WL4KEX7Y.js.map +7 -0
- package/dist/browser/chunks/mathjax-DNP3YRES.js +61 -0
- package/dist/browser/chunks/mathjax-DNP3YRES.js.map +7 -0
- package/dist/browser/index.js +2 -0
- package/dist/browser/index.js.map +7 -0
- package/dist/browser/kit.js +2 -0
- package/dist/browser/kit.js.map +7 -0
- package/dist/browser/manifest.json +30 -0
- package/dist/browser/tex.js +2 -0
- package/dist/browser/tex.js.map +7 -0
- package/dist/engine.d.ts +64 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +42 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/kit/brace.d.ts +8 -0
- package/dist/kit/brace.d.ts.map +1 -0
- package/dist/kit/brace.js +36 -0
- package/dist/kit/brace.js.map +1 -0
- package/dist/kit/cache.d.ts +30 -0
- package/dist/kit/cache.d.ts.map +1 -0
- package/dist/kit/cache.js +53 -0
- package/dist/kit/cache.js.map +1 -0
- package/dist/kit/contour.d.ts +8 -0
- package/dist/kit/contour.d.ts.map +1 -0
- package/dist/kit/contour.js +93 -0
- package/dist/kit/contour.js.map +1 -0
- package/dist/kit/coords.d.ts +69 -0
- package/dist/kit/coords.d.ts.map +1 -0
- package/dist/kit/coords.js +224 -0
- package/dist/kit/coords.js.map +1 -0
- package/dist/kit/curve.d.ts +17 -0
- package/dist/kit/curve.d.ts.map +1 -0
- package/dist/kit/curve.js +22 -0
- package/dist/kit/curve.js.map +1 -0
- package/dist/kit/equation.d.ts +61 -0
- package/dist/kit/equation.d.ts.map +1 -0
- package/dist/kit/equation.js +168 -0
- package/dist/kit/equation.js.map +1 -0
- package/dist/kit/equation3d.d.ts +50 -0
- package/dist/kit/equation3d.d.ts.map +1 -0
- package/dist/kit/equation3d.js +103 -0
- package/dist/kit/equation3d.js.map +1 -0
- package/dist/kit/expression.d.ts +35 -0
- package/dist/kit/expression.d.ts.map +1 -0
- package/dist/kit/expression.js +124 -0
- package/dist/kit/expression.js.map +1 -0
- package/dist/kit/field-mark.d.ts +58 -0
- package/dist/kit/field-mark.d.ts.map +1 -0
- package/dist/kit/field-mark.js +129 -0
- package/dist/kit/field-mark.js.map +1 -0
- package/dist/kit/field.d.ts +14 -0
- package/dist/kit/field.d.ts.map +1 -0
- package/dist/kit/field.js +46 -0
- package/dist/kit/field.js.map +1 -0
- package/dist/kit/follow.d.ts +71 -0
- package/dist/kit/follow.d.ts.map +1 -0
- package/dist/kit/follow.js +159 -0
- package/dist/kit/follow.js.map +1 -0
- package/dist/kit/furniture.d.ts +30 -0
- package/dist/kit/furniture.d.ts.map +1 -0
- package/dist/kit/furniture.js +87 -0
- package/dist/kit/furniture.js.map +1 -0
- package/dist/kit/geometry.d.ts +13 -0
- package/dist/kit/geometry.d.ts.map +1 -0
- package/dist/kit/geometry.js +54 -0
- package/dist/kit/geometry.js.map +1 -0
- package/dist/kit/mark.d.ts +47 -0
- package/dist/kit/mark.d.ts.map +1 -0
- package/dist/kit/mark.js +103 -0
- package/dist/kit/mark.js.map +1 -0
- package/dist/kit/part-fills.d.ts +23 -0
- package/dist/kit/part-fills.d.ts.map +1 -0
- package/dist/kit/part-fills.js +46 -0
- package/dist/kit/part-fills.js.map +1 -0
- package/dist/kit/place.d.ts +18 -0
- package/dist/kit/place.d.ts.map +1 -0
- package/dist/kit/place.js +68 -0
- package/dist/kit/place.js.map +1 -0
- package/dist/kit/placement.d.ts +8 -0
- package/dist/kit/placement.d.ts.map +1 -0
- package/dist/kit/placement.js +8 -0
- package/dist/kit/placement.js.map +1 -0
- package/dist/kit/sampler.d.ts +17 -0
- package/dist/kit/sampler.d.ts.map +1 -0
- package/dist/kit/sampler.js +250 -0
- package/dist/kit/sampler.js.map +1 -0
- package/dist/kit/scale.d.ts +12 -0
- package/dist/kit/scale.d.ts.map +1 -0
- package/dist/kit/scale.js +37 -0
- package/dist/kit/scale.js.map +1 -0
- package/dist/kit/source.d.ts +22 -0
- package/dist/kit/source.d.ts.map +1 -0
- package/dist/kit/source.js +45 -0
- package/dist/kit/source.js.map +1 -0
- package/dist/kit/system.d.ts +33 -0
- package/dist/kit/system.d.ts.map +1 -0
- package/dist/kit/system.js +67 -0
- package/dist/kit/system.js.map +1 -0
- package/dist/kit/ticks.d.ts +19 -0
- package/dist/kit/ticks.d.ts.map +1 -0
- package/dist/kit/ticks.js +78 -0
- package/dist/kit/ticks.js.map +1 -0
- package/dist/kit/withdrawn.d.ts +9 -0
- package/dist/kit/withdrawn.d.ts.map +1 -0
- package/dist/kit/withdrawn.js +9 -0
- package/dist/kit/withdrawn.js.map +1 -0
- package/dist/marks/curve-area.d.ts +32 -0
- package/dist/marks/curve-area.d.ts.map +1 -0
- package/dist/marks/curve-area.js +82 -0
- package/dist/marks/curve-area.js.map +1 -0
- package/dist/marks/drop-lines.d.ts +22 -0
- package/dist/marks/drop-lines.d.ts.map +1 -0
- package/dist/marks/drop-lines.js +58 -0
- package/dist/marks/drop-lines.js.map +1 -0
- package/dist/marks/plot-point.d.ts +35 -0
- package/dist/marks/plot-point.d.ts.map +1 -0
- package/dist/marks/plot-point.js +97 -0
- package/dist/marks/plot-point.js.map +1 -0
- package/dist/marks/riemann-sum.d.ts +37 -0
- package/dist/marks/riemann-sum.d.ts.map +1 -0
- package/dist/marks/riemann-sum.js +91 -0
- package/dist/marks/riemann-sum.js.map +1 -0
- package/dist/marks/tangent-line.d.ts +27 -0
- package/dist/marks/tangent-line.d.ts.map +1 -0
- package/dist/marks/tangent-line.js +103 -0
- package/dist/marks/tangent-line.js.map +1 -0
- package/dist/marks/vector-arrow.d.ts +32 -0
- package/dist/marks/vector-arrow.d.ts.map +1 -0
- package/dist/marks/vector-arrow.js +87 -0
- package/dist/marks/vector-arrow.js.map +1 -0
- package/dist/nodes.d.ts +35 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/nodes.js +63 -0
- package/dist/nodes.js.map +1 -0
- package/dist/plots/function-plot.d.ts +67 -0
- package/dist/plots/function-plot.d.ts.map +1 -0
- package/dist/plots/function-plot.js +215 -0
- package/dist/plots/function-plot.js.map +1 -0
- package/dist/plots/points-plot.d.ts +28 -0
- package/dist/plots/points-plot.d.ts.map +1 -0
- package/dist/plots/points-plot.js +99 -0
- package/dist/plots/points-plot.js.map +1 -0
- package/dist/plots/stream-lines.d.ts +35 -0
- package/dist/plots/stream-lines.d.ts.map +1 -0
- package/dist/plots/stream-lines.js +141 -0
- package/dist/plots/stream-lines.js.map +1 -0
- package/dist/plots/traced-path.d.ts +31 -0
- package/dist/plots/traced-path.d.ts.map +1 -0
- package/dist/plots/traced-path.js +56 -0
- package/dist/plots/traced-path.js.map +1 -0
- package/dist/plots/vector-field.d.ts +23 -0
- package/dist/plots/vector-field.d.ts.map +1 -0
- package/dist/plots/vector-field.js +91 -0
- package/dist/plots/vector-field.js.map +1 -0
- package/dist/structures/graph-layout.d.ts +11 -0
- package/dist/structures/graph-layout.d.ts.map +1 -0
- package/dist/structures/graph-layout.js +135 -0
- package/dist/structures/graph-layout.js.map +1 -0
- package/dist/structures/network-graph.d.ts +83 -0
- package/dist/structures/network-graph.d.ts.map +1 -0
- package/dist/structures/network-graph.js +289 -0
- package/dist/structures/network-graph.js.map +1 -0
- package/dist/structures/sample-space.d.ts +62 -0
- package/dist/structures/sample-space.d.ts.map +1 -0
- package/dist/structures/sample-space.js +199 -0
- package/dist/structures/sample-space.js.map +1 -0
- package/dist/systems/axes2d.d.ts +75 -0
- package/dist/systems/axes2d.d.ts.map +1 -0
- package/dist/systems/axes2d.js +193 -0
- package/dist/systems/axes2d.js.map +1 -0
- package/dist/systems/number-line.d.ts +49 -0
- package/dist/systems/number-line.d.ts.map +1 -0
- package/dist/systems/number-line.js +127 -0
- package/dist/systems/number-line.js.map +1 -0
- package/dist/systems/number-plane.d.ts +59 -0
- package/dist/systems/number-plane.d.ts.map +1 -0
- package/dist/systems/number-plane.js +193 -0
- package/dist/systems/number-plane.js.map +1 -0
- package/dist/systems/polar-plane.d.ts +48 -0
- package/dist/systems/polar-plane.d.ts.map +1 -0
- package/dist/systems/polar-plane.js +165 -0
- package/dist/systems/polar-plane.js.map +1 -0
- package/dist/tex/geometry.d.ts +85 -0
- package/dist/tex/geometry.d.ts.map +1 -0
- package/dist/tex/geometry.js +632 -0
- package/dist/tex/geometry.js.map +1 -0
- package/dist/tex/index.d.ts +11 -0
- package/dist/tex/index.d.ts.map +1 -0
- package/dist/tex/index.js +9 -0
- package/dist/tex/index.js.map +1 -0
- package/dist/tex/mathjax.d.ts +33 -0
- package/dist/tex/mathjax.d.ts.map +1 -0
- package/dist/tex/mathjax.js +74 -0
- package/dist/tex/mathjax.js.map +1 -0
- package/dist/tex/matrix.d.ts +31 -0
- package/dist/tex/matrix.d.ts.map +1 -0
- package/dist/tex/matrix.js +73 -0
- package/dist/tex/matrix.js.map +1 -0
- package/dist/tex/node.d.ts +215 -0
- package/dist/tex/node.d.ts.map +1 -0
- package/dist/tex/node.js +595 -0
- package/dist/tex/node.js.map +1 -0
- package/dist/tex/tween.d.ts +50 -0
- package/dist/tex/tween.d.ts.map +1 -0
- package/dist/tex/tween.js +253 -0
- package/dist/tex/tween.js.map +1 -0
- package/dist/three/axes3d.d.ts +87 -0
- package/dist/three/axes3d.d.ts.map +1 -0
- package/dist/three/axes3d.js +228 -0
- package/dist/three/axes3d.js.map +1 -0
- package/dist/three/curve-plot3d.d.ts +60 -0
- package/dist/three/curve-plot3d.d.ts.map +1 -0
- package/dist/three/curve-plot3d.js +143 -0
- package/dist/three/curve-plot3d.js.map +1 -0
- package/dist/three/label3d.d.ts +11 -0
- package/dist/three/label3d.d.ts.map +1 -0
- package/dist/three/label3d.js +40 -0
- package/dist/three/label3d.js.map +1 -0
- package/dist/three/plot-point3d.d.ts +26 -0
- package/dist/three/plot-point3d.d.ts.map +1 -0
- package/dist/three/plot-point3d.js +60 -0
- package/dist/three/plot-point3d.js.map +1 -0
- package/dist/three/space.d.ts +28 -0
- package/dist/three/space.d.ts.map +1 -0
- package/dist/three/space.js +47 -0
- package/dist/three/space.js.map +1 -0
- package/dist/three/surface-plot3d.d.ts +80 -0
- package/dist/three/surface-plot3d.d.ts.map +1 -0
- package/dist/three/surface-plot3d.js +290 -0
- package/dist/three/surface-plot3d.js.map +1 -0
- package/dist/three/vector-arrow3d.d.ts +25 -0
- package/dist/three/vector-arrow3d.d.ts.map +1 -0
- package/dist/three/vector-arrow3d.js +72 -0
- package/dist/three/vector-arrow3d.js.map +1 -0
- package/package.json +79 -3
- package/registry.json +251 -0
- package/src/annotate/angle-mark.ts +147 -0
- package/src/annotate/curly-brace.ts +126 -0
- package/src/annotate/emphasis-mark.ts +89 -0
- package/src/engine.ts +72 -0
- package/src/index.ts +29 -0
- package/src/kit/brace.ts +37 -0
- package/src/kit/cache.ts +61 -0
- package/src/kit/contour.ts +94 -0
- package/src/kit/coords.ts +278 -0
- package/src/kit/curve.ts +29 -0
- package/src/kit/equation.ts +181 -0
- package/src/kit/equation3d.ts +137 -0
- package/src/kit/expression.ts +159 -0
- package/src/kit/field-mark.ts +155 -0
- package/src/kit/field.ts +50 -0
- package/src/kit/follow.ts +203 -0
- package/src/kit/furniture.ts +108 -0
- package/src/kit/geometry.ts +49 -0
- package/src/kit/mark.ts +131 -0
- package/src/kit/part-fills.ts +61 -0
- package/src/kit/place.ts +101 -0
- package/src/kit/placement.ts +8 -0
- package/src/kit/sampler.ts +281 -0
- package/src/kit/scale.ts +39 -0
- package/src/kit/source.ts +57 -0
- package/src/kit/system.ts +99 -0
- package/src/kit/ticks.ts +85 -0
- package/src/kit/withdrawn.ts +8 -0
- package/src/marks/curve-area.ts +89 -0
- package/src/marks/drop-lines.ts +63 -0
- package/src/marks/plot-point.ts +107 -0
- package/src/marks/riemann-sum.ts +98 -0
- package/src/marks/tangent-line.ts +103 -0
- package/src/marks/vector-arrow.ts +98 -0
- package/src/nodes.ts +63 -0
- package/src/plots/function-plot.ts +236 -0
- package/src/plots/points-plot.ts +107 -0
- package/src/plots/stream-lines.ts +151 -0
- package/src/plots/traced-path.ts +52 -0
- package/src/plots/vector-field.ts +88 -0
- package/src/structures/graph-layout.ts +145 -0
- package/src/structures/network-graph.ts +308 -0
- package/src/structures/sample-space.ts +209 -0
- package/src/systems/axes2d.ts +217 -0
- package/src/systems/number-line.ts +131 -0
- package/src/systems/number-plane.ts +203 -0
- package/src/systems/polar-plane.ts +176 -0
- package/src/tex/geometry.ts +703 -0
- package/src/tex/index.ts +14 -0
- package/src/tex/mathjax.ts +82 -0
- package/src/tex/matrix.ts +75 -0
- package/src/tex/node.ts +641 -0
- package/src/tex/tween.ts +308 -0
- package/src/three/axes3d.ts +240 -0
- package/src/three/curve-plot3d.ts +147 -0
- package/src/three/label3d.ts +50 -0
- package/src/three/plot-point3d.ts +66 -0
- package/src/three/space.ts +67 -0
- package/src/three/surface-plot3d.ts +323 -0
- package/src/three/vector-arrow3d.ts +77 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Graphics2D, PaintNode, type BoxBounds, type ChildPlane, type Extents, type MeasureContext2D, type Node2D, type PaintProps, type RenderContext2D, type Size2D, type Vector2 } from "@motionscript/sdk";
|
|
2
|
+
import { type CoordinateMap } from "./coords.js";
|
|
3
|
+
/**
|
|
4
|
+
* A node drawn in graph coordinates: a plot, an area, an arrow between two
|
|
5
|
+
* graph points. It answers with runs of pixel points and is otherwise a shape,
|
|
6
|
+
* so fill, stroke, shadow and `progressTo` are the inherited ones and its box
|
|
7
|
+
* is the tight box of its ink.
|
|
8
|
+
*
|
|
9
|
+
* Inside a coordinate system the system lays it out and its own `x`/`y` are a
|
|
10
|
+
* shift in graph units, which {@link shift} reports and {@link trace} applies.
|
|
11
|
+
* Outside one a graph unit is a pixel and `x`/`y` are the usual offset.
|
|
12
|
+
*
|
|
13
|
+
* A mark that takes children holds them on the same map it is drawn through: a
|
|
14
|
+
* plot holding the area under it and the point that rides it.
|
|
15
|
+
*/
|
|
16
|
+
export declare abstract class Mark<P extends PaintProps = PaintProps> extends PaintNode<P> {
|
|
17
|
+
/** The runs this mark draws, in pixels, y-up from the system's centre. */
|
|
18
|
+
protected abstract trace(map: CoordinateMap): Vector2[][];
|
|
19
|
+
/** Whether each run is closed into an outline. */
|
|
20
|
+
protected isClosed(): boolean;
|
|
21
|
+
/** This mark's own `x`/`y` as a shift in graph units: zero outside a system, where they are pixels. */
|
|
22
|
+
protected shift(): Vector2;
|
|
23
|
+
/** A graph point in this mark's own frame, where a handle on it sits. */
|
|
24
|
+
protected ownPoint(point: Vector2): Vector2;
|
|
25
|
+
/** The graph point at `at` in this mark's own frame: {@link ownPoint} undone. */
|
|
26
|
+
protected graphPoint(at: Vector2): Vector2;
|
|
27
|
+
/** Whether the fill is painted: a mark whose ink has no inside yet (an open line) says no. */
|
|
28
|
+
protected paintsFill(): boolean;
|
|
29
|
+
measure(): Partial<Size2D>;
|
|
30
|
+
protected shapeGraphics(): Graphics2D | null;
|
|
31
|
+
protected renderSelf(ctx: RenderContext2D): void;
|
|
32
|
+
/** The stroke along the ink. A mark that strokes it differently overrides this, not `renderStroke`. */
|
|
33
|
+
protected renderInk(ctx: RenderContext2D): void;
|
|
34
|
+
protected renderStroke(): void;
|
|
35
|
+
protected layoutChildren(rect: BoxBounds, scope: MeasureContext2D): void;
|
|
36
|
+
_planeOf(child: Node2D | null): ChildPlane | null;
|
|
37
|
+
private _data;
|
|
38
|
+
private _ink;
|
|
39
|
+
private _inSystem;
|
|
40
|
+
private _map;
|
|
41
|
+
private _planes;
|
|
42
|
+
/** Its own centre in the map's pixels: where its children's boxes are placed from. */
|
|
43
|
+
private _centre;
|
|
44
|
+
/** @internal What a system lays this mark out on: its ink, drawn through `map`. */
|
|
45
|
+
_resolve(map: CoordinateMap, inSystem?: boolean): Extents | null;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=mark.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mark.d.ts","sourceRoot":"","sources":["../../src/kit/mark.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,UAAU,EACV,SAAS,EACT,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,gBAAgB,EACrB,KAAK,MAAM,EACX,KAAK,UAAU,EAEf,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,OAAO,EACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAa,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAIzD;;;;;;;;;;;;GAYG;AACH,8BAAsB,IAAI,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,CAAE,SAAQ,SAAS,CAAC,CAAC,CAAC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3
|
+
import { boundsOfRuns, runsToPath } from "./geometry.js";
|
|
4
|
+
import { openPlane, placeOnMap } from "./place.js";
|
|
5
|
+
/**
|
|
6
|
+
* A node drawn in graph coordinates: a plot, an area, an arrow between two
|
|
7
|
+
* graph points. It answers with runs of pixel points and is otherwise a shape,
|
|
8
|
+
* so fill, stroke, shadow and `progressTo` are the inherited ones and its box
|
|
9
|
+
* is the tight box of its ink.
|
|
10
|
+
*
|
|
11
|
+
* Inside a coordinate system the system lays it out and its own `x`/`y` are a
|
|
12
|
+
* shift in graph units, which {@link shift} reports and {@link trace} applies.
|
|
13
|
+
* Outside one a graph unit is a pixel and `x`/`y` are the usual offset.
|
|
14
|
+
*
|
|
15
|
+
* A mark that takes children holds them on the same map it is drawn through: a
|
|
16
|
+
* plot holding the area under it and the point that rides it.
|
|
17
|
+
*/
|
|
18
|
+
export class Mark extends PaintNode {
|
|
19
|
+
/** Whether each run is closed into an outline. */
|
|
20
|
+
isClosed() {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
/** This mark's own `x`/`y` as a shift in graph units: zero outside a system, where they are pixels. */
|
|
24
|
+
shift() {
|
|
25
|
+
return this._inSystem ? { x: this.x, y: this.y } : NO_SHIFT;
|
|
26
|
+
}
|
|
27
|
+
/** A graph point in this mark's own frame, where a handle on it sits. */
|
|
28
|
+
ownPoint(point) {
|
|
29
|
+
const shift = this.shift();
|
|
30
|
+
const at = this._map.toPoint(point.x + shift.x, point.y + shift.y);
|
|
31
|
+
const centre = this._centre();
|
|
32
|
+
return { x: at.x - centre.x, y: at.y - centre.y };
|
|
33
|
+
}
|
|
34
|
+
/** The graph point at `at` in this mark's own frame: {@link ownPoint} undone. */
|
|
35
|
+
graphPoint(at) {
|
|
36
|
+
const shift = this.shift();
|
|
37
|
+
const centre = this._centre();
|
|
38
|
+
const point = this._map.toCoords(at.x + centre.x, at.y + centre.y);
|
|
39
|
+
return { x: point.x - shift.x, y: point.y - shift.y };
|
|
40
|
+
}
|
|
41
|
+
/** Whether the fill is painted: a mark whose ink has no inside yet (an open line) says no. */
|
|
42
|
+
paintsFill() {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
measure() {
|
|
46
|
+
const ink = this._resolve(PIXEL_MAP, false);
|
|
47
|
+
return ink ? { width: ink.maxX - ink.minX, height: ink.maxY - ink.minY } : { width: 0, height: 0 };
|
|
48
|
+
}
|
|
49
|
+
shapeGraphics() {
|
|
50
|
+
const ink = this._ink;
|
|
51
|
+
if (!ink || this._data.length === 0)
|
|
52
|
+
return null;
|
|
53
|
+
return new Graphics2D().path({
|
|
54
|
+
data: this._data,
|
|
55
|
+
centerBounds: [ink.minX, ink.minY, ink.maxX, ink.maxY],
|
|
56
|
+
start: this.start,
|
|
57
|
+
end: this.end,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
// A mark's stroke is its ink, so it is painted before its children rather
|
|
61
|
+
// than over them: a point or a tangent riding a plot sits on the curve.
|
|
62
|
+
renderSelf(ctx) {
|
|
63
|
+
if (this.paintsFill())
|
|
64
|
+
super.renderSelf(ctx);
|
|
65
|
+
this.renderInk(ctx);
|
|
66
|
+
}
|
|
67
|
+
/** The stroke along the ink. A mark that strokes it differently overrides this, not `renderStroke`. */
|
|
68
|
+
renderInk(ctx) {
|
|
69
|
+
super.renderStroke(ctx);
|
|
70
|
+
}
|
|
71
|
+
renderStroke() { }
|
|
72
|
+
layoutChildren(rect, scope) {
|
|
73
|
+
const children = this.flowChildren();
|
|
74
|
+
if (children.length === 0)
|
|
75
|
+
return;
|
|
76
|
+
const room = { x: 0, y: 0, width: rect.width, height: rect.height };
|
|
77
|
+
this._planes = placeOnMap(children, this._map, this._centre(), room, scope);
|
|
78
|
+
}
|
|
79
|
+
_planeOf(child) {
|
|
80
|
+
return child ? (this._planes.get(child) ?? null) : openPlane(this._map, this._centre());
|
|
81
|
+
}
|
|
82
|
+
_data = [];
|
|
83
|
+
_ink = null;
|
|
84
|
+
_inSystem = false;
|
|
85
|
+
_map = PIXEL_MAP;
|
|
86
|
+
_planes = new WeakMap();
|
|
87
|
+
/** Its own centre in the map's pixels: where its children's boxes are placed from. */
|
|
88
|
+
_centre() {
|
|
89
|
+
const ink = this._ink;
|
|
90
|
+
return ink ? { x: (ink.minX + ink.maxX) / 2, y: (ink.minY + ink.maxY) / 2 } : NO_SHIFT;
|
|
91
|
+
}
|
|
92
|
+
/** @internal What a system lays this mark out on: its ink, drawn through `map`. */
|
|
93
|
+
_resolve(map, inSystem = true) {
|
|
94
|
+
this._inSystem = inSystem;
|
|
95
|
+
this._map = map;
|
|
96
|
+
const runs = this.trace(map);
|
|
97
|
+
this._data = runsToPath(runs, this.isClosed());
|
|
98
|
+
this._ink = boundsOfRuns(runs);
|
|
99
|
+
return this._ink;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const NO_SHIFT = { x: 0, y: 0 };
|
|
103
|
+
//# sourceMappingURL=mark.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mark.js","sourceRoot":"","sources":["../../src/kit/mark.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,UAAU,EACV,SAAS,GAWZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAsB,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEhD;;;;;;;;;;;;GAYG;AACH,MAAM,OAAgB,IAAwC,SAAQ,SAAY;IAI9E,kDAAkD;IACxC,QAAQ;QACd,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,uGAAuG;IAC7F,KAAK;QACX,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;IAChE,C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IAAI,CAAC,CAAC;QAC/B,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;CACJ;AAED,MAAM,QAAQ,GAAY,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC","sourcesContent":["import {\r\n Graphics2D,\r\n PaintNode,\r\n type BoxBounds,\r\n type ChildPlane,\r\n type Extents,\r\n type MeasureContext2D,\r\n type Node2D,\r\n type PaintProps,\r\n type PathCommand,\r\n type RenderContext2D,\r\n type Size2D,\r\n type Vector2,\r\n} from \"@motionscript/sdk\";\r\nimport { PIXEL_MAP, type CoordinateMap } from \"./coords\";\r\nimport { boundsOfRuns, runsToPath } from \"./geometry\";\r\nimport { openPlane, placeOnMap } from \"./place\";\r\n\r\n/**\r\n * A node drawn in graph coordinates: a plot, an area, an arrow between two\r\n * graph points. It answers with runs of pixel points and is otherwise a shape,\r\n * so fill, stroke, shadow and `progressTo` are the inherited ones and its box\r\n * is the tight box of its ink.\r\n *\r\n * Inside a coordinate system the system lays it out and its own `x`/`y` are a\r\n * shift in graph units, which {@link shift} reports and {@link trace} applies.\r\n * Outside one a graph unit is a pixel and `x`/`y` are the usual offset.\r\n *\r\n * A mark that takes children holds them on the same map it is drawn through: a\r\n * plot holding the area under it and the point that rides it.\r\n */\r\nexport abstract class Mark<P extends PaintProps = PaintProps> extends PaintNode<P> {\r\n /** The runs this mark draws, in pixels, y-up from the system's centre. */\r\n protected abstract trace(map: CoordinateMap): Vector2[][];\r\n\r\n /** Whether each run is closed into an outline. */\r\n protected isClosed(): boolean {\r\n return false;\r\n }\r\n\r\n /** This mark's own `x`/`y` as a shift in graph units: zero outside a system, where they are pixels. */\r\n protected shift(): Vector2 {\r\n return this._inSystem ? { x: this.x, y: this.y } : NO_SHIFT;\r\n }\r\n\r\n /** A graph point in this mark's own frame, where a handle on it sits. */\r\n protected ownPoint(point: Vector2): Vector2 {\r\n const shift = this.shift();\r\n const at = this._map.toPoint(point.x + shift.x, point.y + shift.y);\r\n const centre = this._centre();\r\n return { x: at.x - centre.x, y: at.y - centre.y };\r\n }\r\n\r\n /** The graph point at `at` in this mark's own frame: {@link ownPoint} undone. */\r\n protected graphPoint(at: Vector2): Vector2 {\r\n const shift = this.shift();\r\n const centre = this._centre();\r\n const point = this._map.toCoords(at.x + centre.x, at.y + centre.y);\r\n return { x: point.x - shift.x, y: point.y - shift.y };\r\n }\r\n\r\n /** Whether the fill is painted: a mark whose ink has no inside yet (an open line) says no. */\r\n protected paintsFill(): boolean {\r\n return true;\r\n }\r\n\r\n override measure(): Partial<Size2D> {\r\n const ink = this._resolve(PIXEL_MAP, false);\r\n return ink ? { width: ink.maxX - ink.minX, height: ink.maxY - ink.minY } : { width: 0, height: 0 };\r\n }\r\n\r\n protected override shapeGraphics(): Graphics2D | null {\r\n const ink = this._ink;\r\n if (!ink || this._data.length === 0) return null;\r\n return new Graphics2D().path({\r\n data: this._data,\r\n centerBounds: [ink.minX, ink.minY, ink.maxX, ink.maxY],\r\n start: this.start,\r\n end: this.end,\r\n });\r\n }\r\n\r\n // A mark's stroke is its ink, so it is painted before its children rather\r\n // than over them: a point or a tangent riding a plot sits on the curve.\r\n protected override renderSelf(ctx: RenderContext2D): void {\r\n if (this.paintsFill()) super.renderSelf(ctx);\r\n this.renderInk(ctx);\r\n }\r\n\r\n /** The stroke along the ink. A mark that strokes it differently overrides this, not `renderStroke`. */\r\n protected renderInk(ctx: RenderContext2D): void {\r\n super.renderStroke(ctx);\r\n }\r\n\r\n protected override renderStroke(): void {}\r\n\r\n protected override layoutChildren(rect: BoxBounds, scope: MeasureContext2D): void {\r\n const children = this.flowChildren();\r\n if (children.length === 0) return;\r\n const room = { x: 0, y: 0, width: rect.width, height: rect.height };\r\n this._planes = placeOnMap(children, this._map, this._centre(), room, scope);\r\n }\r\n\r\n override _planeOf(child: Node2D | null): ChildPlane | null {\r\n return child ? (this._planes.get(child) ?? null) : openPlane(this._map, this._centre());\r\n }\r\n\r\n private _data: PathCommand[] = [];\r\n private _ink: Extents | null = null;\r\n private _inSystem = false;\r\n private _map: CoordinateMap = PIXEL_MAP;\r\n private _planes = new WeakMap<Node2D, ChildPlane>();\r\n\r\n /** Its own centre in the map's pixels: where its children's boxes are placed from. */\r\n private _centre(): Vector2 {\r\n const ink = this._ink;\r\n return ink ? { x: (ink.minX + ink.maxX) / 2, y: (ink.minY + ink.maxY) / 2 } : NO_SHIFT;\r\n }\r\n\r\n /** @internal What a system lays this mark out on: its ink, drawn through `map`. */\r\n _resolve(map: CoordinateMap, inSystem = true): Extents | null {\r\n this._inSystem = inSystem;\r\n this._map = map;\r\n const runs = this.trace(map);\r\n this._data = runsToPath(runs, this.isClosed());\r\n this._ink = boundsOfRuns(runs);\r\n return this._ink;\r\n }\r\n}\r\n\r\nconst NO_SHIFT: Vector2 = { x: 0, y: 0 };\r\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Fill, type FillResolved } from "@motionscript/sdk";
|
|
2
|
+
/** A paint for one part of a node, named the way the node names its parts: a formula's term, a graph's vertex or edge. */
|
|
3
|
+
export interface PartFill {
|
|
4
|
+
part: string;
|
|
5
|
+
fill: Fill;
|
|
6
|
+
/** Which of the places the part is written, counted from 1; 0 is all of them. */
|
|
7
|
+
occurrence?: number;
|
|
8
|
+
/** How far from the node's own paint to `fill`, 0 to 1. A tween's state: an author leaves it out. */
|
|
9
|
+
mix?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface PartFillResolved {
|
|
12
|
+
part: string;
|
|
13
|
+
fill: FillResolved[];
|
|
14
|
+
occurrence: number;
|
|
15
|
+
mix: number;
|
|
16
|
+
}
|
|
17
|
+
export declare function readPartFills(value: readonly PartFill[] | null | undefined): PartFillResolved[];
|
|
18
|
+
export declare function lerpPartFills(from: PartFillResolved[], to: PartFillResolved[], t: number): PartFillResolved[];
|
|
19
|
+
/** Each part fill with its own key, the one in place of an earlier one for the same part and occurrence. */
|
|
20
|
+
export declare function withPartFill(fills: readonly PartFillResolved[], entry: PartFill): PartFill[];
|
|
21
|
+
/** `base` with a part's fill laid over it while it arrives, in place of it once it has. */
|
|
22
|
+
export declare function partPaint(base: FillResolved[], entry: PartFillResolved | undefined): FillResolved[];
|
|
23
|
+
//# sourceMappingURL=part-fills.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"part-fills.d.ts","sourceRoot":"","sources":["../../src/kit/part-fills.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,IAAI,EAAE,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtF,0HAA0H;AAC1H,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,CAAC;IACX,iFAAiF;IACjF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qGAAqG;IACrG,GAAG,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,YAAY,EAAE,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;CACf;AAID,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,GAAG,IAAI,GAAG,SAAS,GAAG,gBAAgB,EAAE,CAQ/F;AAKD,wBAAgB,aAAa,CAAC,IAAI,EAAE,gBAAgB,EAAE,EAAE,EAAE,EAAE,gBAAgB,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAa7G;AAED,4GAA4G;AAC5G,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,gBAAgB,EAAE,EAAE,KAAK,EAAE,QAAQ,GAAG,QAAQ,EAAE,CAG5F;AAED,2FAA2F;AAC3F,wBAAgB,SAAS,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,gBAAgB,GAAG,SAAS,GAAG,YAAY,EAAE,CAInG"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { fillOps, lerpNumber } from "@motionscript/sdk";
|
|
2
|
+
// Every entry is kept as written, one with no part yet included, so an editor
|
|
3
|
+
// showing the list shows the row it just added; the drawing skips it.
|
|
4
|
+
export function readPartFills(value) {
|
|
5
|
+
if (!Array.isArray(value))
|
|
6
|
+
return [];
|
|
7
|
+
return value.map((entry) => ({
|
|
8
|
+
part: String(entry?.part ?? ""),
|
|
9
|
+
fill: fillOps.resolve(entry?.fill ?? "#ffffff"),
|
|
10
|
+
occurrence: Math.max(0, Math.round(entry?.occurrence ?? 0)),
|
|
11
|
+
mix: Math.min(1, Math.max(0, entry?.mix ?? 1)),
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
const keyOf = (entry) => `${entry.occurrence}|${entry.part}`;
|
|
15
|
+
// A paint that arrives grows from the node's own, and one that leaves fades back to it.
|
|
16
|
+
export function lerpPartFills(from, to, t) {
|
|
17
|
+
if (t <= 0)
|
|
18
|
+
return from;
|
|
19
|
+
if (t >= 1)
|
|
20
|
+
return to;
|
|
21
|
+
const before = new Map(from.map((entry) => [keyOf(entry), entry]));
|
|
22
|
+
const out = to.map((entry) => {
|
|
23
|
+
const was = before.get(keyOf(entry));
|
|
24
|
+
before.delete(keyOf(entry));
|
|
25
|
+
return was
|
|
26
|
+
? { ...entry, fill: fillOps.lerp(was.fill, entry.fill, t), mix: lerpNumber(was.mix, entry.mix, t) }
|
|
27
|
+
: { ...entry, mix: entry.mix * t };
|
|
28
|
+
});
|
|
29
|
+
for (const gone of before.values())
|
|
30
|
+
out.push({ ...gone, mix: gone.mix * (1 - t) });
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
/** Each part fill with its own key, the one in place of an earlier one for the same part and occurrence. */
|
|
34
|
+
export function withPartFill(fills, entry) {
|
|
35
|
+
const occurrence = Math.max(0, Math.round(entry.occurrence ?? 0));
|
|
36
|
+
return [...fills.filter((was) => was.part !== entry.part || was.occurrence !== occurrence), { ...entry, occurrence }];
|
|
37
|
+
}
|
|
38
|
+
/** `base` with a part's fill laid over it while it arrives, in place of it once it has. */
|
|
39
|
+
export function partPaint(base, entry) {
|
|
40
|
+
if (!entry || entry.mix <= 0)
|
|
41
|
+
return base;
|
|
42
|
+
if (entry.mix >= 1)
|
|
43
|
+
return entry.fill;
|
|
44
|
+
return [...base, ...entry.fill.map((layer) => ({ ...layer, opacity: (layer.opacity ?? 1) * entry.mix }))];
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=part-fills.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"part-fills.js","sourceRoot":"","sources":["../../src/kit/part-fills.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAgC,MAAM,mBAAmB,CAAC;AAmBtF,8EAA8E;AAC9E,sEAAsE;AACtE,MAAM,UAAU,aAAa,CAAC,KAA6C;IACvE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACrC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACzB,IAAI,EAAE,MAAM,CAAC,KAAK,EAAE,IAAI,IAAI,EAAE,CAAC;QAC/B,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,IAAI,SAAS,CAAC;QAC/C,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,UAAU,IAAI,CAAC,CAAC,CAAC;QAC3D,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;KACjD,CAAC,CAAC,CAAC;AACR,CAAC;AAED,MAAM,KAAK,GAAG,CAAC,KAAuB,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,UAAU,IAAI,KA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YAAY,CAAC,KAAkC,EAAE,KAAe;IAC5E,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,IAAI,CAAC,CAAC,CAAC,CAAC;IAClE,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,GAAG,CAAC,UAAU,KAAK,UAAU,CAAC,EAAE,EAAE,GAAG,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;AAC1H,CAAC;AAED,2FAA2F;AAC3F,MAAM,UAAU,SAAS,CAAC,IAAoB,EAAE,KAAmC;IAC/E,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1C,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC,IAAI,CAAC;IACtC,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;AAC9G,CAAC","sourcesContent":["import { fillOps, lerpNumber, type Fill, type FillResolved } from \"@motionscript/sdk\";\r\n\r\n/** A paint for one part of a node, named the way the node names its parts: a formula's term, a graph's vertex or edge. */\r\nexport interface PartFill {\r\n part: string;\r\n fill: Fill;\r\n /** Which of the places the part is written, counted from 1; 0 is all of them. */\r\n occurrence?: number;\r\n /** How far from the node's own paint to `fill`, 0 to 1. A tween's state: an author leaves it out. */\r\n mix?: number;\r\n}\r\n\r\nexport interface PartFillResolved {\r\n part: string;\r\n fill: FillResolved[];\r\n occurrence: number;\r\n mix: number;\r\n}\r\n\r\n// Every entry is kept as written, one with no part yet included, so an editor\r\n// showing the list shows the row it just added; the drawing skips it.\r\nexport function readPartFills(value: readonly PartFill[] | null | undefined): PartFillResolved[] {\r\n if (!Array.isArray(value)) return [];\r\n return value.map((entry) => ({\r\n part: String(entry?.part ?? \"\"),\r\n fill: fillOps.resolve(entry?.fill ?? \"#ffffff\"),\r\n occurrence: Math.max(0, Math.round(entry?.occurrence ?? 0)),\r\n mix: Math.min(1, Math.max(0, entry?.mix ?? 1)),\r\n }));\r\n}\r\n\r\nconst keyOf = (entry: PartFillResolved) => `${entry.occurrence}|${entry.part}`;\r\n\r\n// A paint that arrives grows from the node's own, and one that leaves fades back to it.\r\nexport function lerpPartFills(from: PartFillResolved[], to: PartFillResolved[], t: number): PartFillResolved[] {\r\n if (t <= 0) return from;\r\n if (t >= 1) return to;\r\n const before = new Map(from.map((entry) => [keyOf(entry), entry]));\r\n const out = to.map((entry) => {\r\n const was = before.get(keyOf(entry));\r\n before.delete(keyOf(entry));\r\n return was\r\n ? { ...entry, fill: fillOps.lerp(was.fill, entry.fill, t), mix: lerpNumber(was.mix, entry.mix, t) }\r\n : { ...entry, mix: entry.mix * t };\r\n });\r\n for (const gone of before.values()) out.push({ ...gone, mix: gone.mix * (1 - t) });\r\n return out;\r\n}\r\n\r\n/** Each part fill with its own key, the one in place of an earlier one for the same part and occurrence. */\r\nexport function withPartFill(fills: readonly PartFillResolved[], entry: PartFill): PartFill[] {\r\n const occurrence = Math.max(0, Math.round(entry.occurrence ?? 0));\r\n return [...fills.filter((was) => was.part !== entry.part || was.occurrence !== occurrence), { ...entry, occurrence }];\r\n}\r\n\r\n/** `base` with a part's fill laid over it while it arrives, in place of it once it has. */\r\nexport function partPaint(base: FillResolved[], entry: PartFillResolved | undefined): FillResolved[] {\r\n if (!entry || entry.mix <= 0) return base;\r\n if (entry.mix >= 1) return entry.fill;\r\n return [...base, ...entry.fill.map((layer) => ({ ...layer, opacity: (layer.opacity ?? 1) * entry.mix }))];\r\n}\r\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type BoxBounds, type ChildPlane, type MeasureContext2D, type Node2D, type Vector2 } from "@motionscript/sdk";
|
|
2
|
+
import type { CoordinateMap } from "./coords.js";
|
|
3
|
+
/** A child that sits somewhere other than its own `x`/`y`: a point riding a curve. */
|
|
4
|
+
export interface Anchored {
|
|
5
|
+
/** The graph coordinates the child is at, given its own `x`/`y`. */
|
|
6
|
+
anchorAt(x: number, y: number): Vector2;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Lay `children` out on `map`, for whichever node holds them: a coordinate
|
|
10
|
+
* system, or a plot holding the marks that read it. A mark goes on its ink;
|
|
11
|
+
* anything else keeps its own size and has its `x`/`y` read as graph
|
|
12
|
+
* coordinates. `origin` is the holder's own centre in the map's pixels (y-up),
|
|
13
|
+
* since a child's box is placed from there. Returns each child's plane.
|
|
14
|
+
*/
|
|
15
|
+
export declare function placeOnMap(children: readonly Node2D[], map: CoordinateMap, origin: Vector2, room: BoxBounds, scope: MeasureContext2D): WeakMap<Node2D, ChildPlane>;
|
|
16
|
+
/** The plane of a child that is not there yet, under a holder centred on `origin`: where a host would drop one. */
|
|
17
|
+
export declare function openPlane(map: CoordinateMap, origin: Vector2): ChildPlane;
|
|
18
|
+
//# sourceMappingURL=place.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"place.d.ts","sourceRoot":"","sources":["../../src/kit/place.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,KAAK,SAAS,EACd,KAAK,UAAU,EAEf,KAAK,gBAAgB,EACrB,KAAK,MAAM,EACX,KAAK,OAAO,EACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,sFAAsF;AACtF,MAAM,WAAW,QAAQ;IACrB,oEAAoE;IACpE,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC3C;AAeD;;;;;;GAMG;AACH,wBAAgB,UAAU,CACtB,QAAQ,EAAE,SAAS,MAAM,EAAE,EAC3B,GAAG,EAAE,aAAa,EAClB,MAAM,EAAE,OAAO,EACf,IAAI,EAAE,SAAS,EACf,KAAK,EAAE,gBAAgB,GACxB,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC,CAyB7B;AAED,mHAAmH;AACnH,wBAAgB,SAAS,CAAC,GAAG,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,GAAG,UAAU,CAQzE"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { flowOps, } from "@motionscript/sdk";
|
|
2
|
+
function isAnchored(node) {
|
|
3
|
+
return typeof node.anchorAt === "function";
|
|
4
|
+
}
|
|
5
|
+
function isTraced(node) {
|
|
6
|
+
return typeof node._resolve === "function";
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Lay `children` out on `map`, for whichever node holds them: a coordinate
|
|
10
|
+
* system, or a plot holding the marks that read it. A mark goes on its ink;
|
|
11
|
+
* anything else keeps its own size and has its `x`/`y` read as graph
|
|
12
|
+
* coordinates. `origin` is the holder's own centre in the map's pixels (y-up),
|
|
13
|
+
* since a child's box is placed from there. Returns each child's plane.
|
|
14
|
+
*/
|
|
15
|
+
export function placeOnMap(children, map, origin, room, scope) {
|
|
16
|
+
const planes = new WeakMap();
|
|
17
|
+
const others = [];
|
|
18
|
+
for (const child of children) {
|
|
19
|
+
if (!isTraced(child)) {
|
|
20
|
+
others.push(child);
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const ink = child._resolve(map);
|
|
24
|
+
const cx = ink ? (ink.minX + ink.maxX) / 2 : origin.x;
|
|
25
|
+
const cy = ink ? (ink.minY + ink.maxY) / 2 : origin.y;
|
|
26
|
+
child.layout({ x: cx - origin.x, y: origin.y - cy, width: ink ? ink.maxX - ink.minX : 0, height: ink ? ink.maxY - ink.minY : 0 }, scope);
|
|
27
|
+
planes.set(child, markPlane(map, cx, cy));
|
|
28
|
+
}
|
|
29
|
+
if (others.length === 0)
|
|
30
|
+
return planes;
|
|
31
|
+
const sizes = flowOps.measure({}, others, room, scope).sizes;
|
|
32
|
+
others.forEach((child, i) => {
|
|
33
|
+
// Its box is centred on the map's own centre, so its offset from there is its point.
|
|
34
|
+
child.layout({ x: -origin.x, y: origin.y, width: sizes[i].width, height: sizes[i].height }, scope);
|
|
35
|
+
planes.set(child, pointPlane(map, child));
|
|
36
|
+
});
|
|
37
|
+
return planes;
|
|
38
|
+
}
|
|
39
|
+
/** The plane of a child that is not there yet, under a holder centred on `origin`: where a host would drop one. */
|
|
40
|
+
export function openPlane(map, origin) {
|
|
41
|
+
return {
|
|
42
|
+
toOffset: (x, y) => {
|
|
43
|
+
const at = map.toPoint(x, y);
|
|
44
|
+
return { x: at.x - origin.x, y: at.y - origin.y };
|
|
45
|
+
},
|
|
46
|
+
toCoords: (x, y) => map.toCoords(x + origin.x, y + origin.y),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function pointPlane(map, child) {
|
|
50
|
+
const point = { x: 0, y: 0 };
|
|
51
|
+
const anchored = isAnchored(child) ? child : null;
|
|
52
|
+
return {
|
|
53
|
+
toOffset: (x, y) => {
|
|
54
|
+
const at = anchored?.anchorAt(x, y);
|
|
55
|
+
return at ? map.toPoint(at.x, at.y, point) : map.toPoint(x, y, point);
|
|
56
|
+
},
|
|
57
|
+
toCoords: (x, y) => map.toCoords(x, y),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
// A mark reads its own `x`/`y` as it draws, so its holder adds nothing; a drag still answers in graph units.
|
|
61
|
+
function markPlane(map, cx, cy) {
|
|
62
|
+
const none = { x: 0, y: 0 };
|
|
63
|
+
return {
|
|
64
|
+
toOffset: () => none,
|
|
65
|
+
toCoords: (x, y) => map.toCoords(cx + x, cy + y),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//# sourceMapping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Q,EAAE,GAAG,EAAE,CAAC,IAAI;QACpB,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;KACnD,CAAC;AACN,CAAC","sourcesContent":["import {\r\n flowOps,\r\n type BoxBounds,\r\n type ChildPlane,\r\n type Extents,\r\n type MeasureContext2D,\r\n type Node2D,\r\n type Vector2,\r\n} from \"@motionscript/sdk\";\r\nimport type { CoordinateMap } from \"./coords\";\r\n\r\n/** A child that sits somewhere other than its own `x`/`y`: a point riding a curve. */\r\nexport interface Anchored {\r\n /** The graph coordinates the child is at, given its own `x`/`y`. */\r\n anchorAt(x: number, y: number): Vector2;\r\n}\r\n\r\nfunction isAnchored(node: object): node is Anchored {\r\n return typeof (node as Partial<Anchored>).anchorAt === \"function\";\r\n}\r\n\r\n/** A child drawn through a map and laid out on its ink: a mark, told apart by what it does so a copied one is too. */\r\ninterface Traced {\r\n _resolve(map: CoordinateMap, inSystem?: boolean): Extents | null;\r\n}\r\n\r\nfunction isTraced(node: object): node is Traced {\r\n return typeof (node as Partial<Traced>)._resolve === \"function\";\r\n}\r\n\r\n/**\r\n * Lay `children` out on `map`, for whichever node holds them: a coordinate\r\n * system, or a plot holding the marks that read it. A mark goes on its ink;\r\n * anything else keeps its own size and has its `x`/`y` read as graph\r\n * coordinates. `origin` is the holder's own centre in the map's pixels (y-up),\r\n * since a child's box is placed from there. Returns each child's plane.\r\n */\r\nexport function placeOnMap(\r\n children: readonly Node2D[],\r\n map: CoordinateMap,\r\n origin: Vector2,\r\n room: BoxBounds,\r\n scope: MeasureContext2D,\r\n): WeakMap<Node2D, ChildPlane> {\r\n const planes = new WeakMap<Node2D, ChildPlane>();\r\n const others: Node2D[] = [];\r\n for (const child of children) {\r\n if (!isTraced(child)) {\r\n others.push(child);\r\n continue;\r\n }\r\n const ink = child._resolve(map);\r\n const cx = ink ? (ink.minX + ink.maxX) / 2 : origin.x;\r\n const cy = ink ? (ink.minY + ink.maxY) / 2 : origin.y;\r\n child.layout(\r\n { x: cx - origin.x, y: origin.y - cy, width: ink ? ink.maxX - ink.minX : 0, height: ink ? ink.maxY - ink.minY : 0 },\r\n scope,\r\n );\r\n planes.set(child, markPlane(map, cx, cy));\r\n }\r\n if (others.length === 0) return planes;\r\n const sizes = flowOps.measure({}, others, room, scope).sizes;\r\n others.forEach((child, i) => {\r\n // Its box is centred on the map's own centre, so its offset from there is its point.\r\n child.layout({ x: -origin.x, y: origin.y, width: sizes[i].width, height: sizes[i].height }, scope);\r\n planes.set(child, pointPlane(map, child));\r\n });\r\n return planes;\r\n}\r\n\r\n/** The plane of a child that is not there yet, under a holder centred on `origin`: where a host would drop one. */\r\nexport function openPlane(map: CoordinateMap, origin: Vector2): ChildPlane {\r\n return {\r\n toOffset: (x, y) => {\r\n const at = map.toPoint(x, y);\r\n return { x: at.x - origin.x, y: at.y - origin.y };\r\n },\r\n toCoords: (x, y) => map.toCoords(x + origin.x, y + origin.y),\r\n };\r\n}\r\n\r\nfunction pointPlane(map: CoordinateMap, child: Node2D): ChildPlane {\r\n const point: Vector2 = { x: 0, y: 0 };\r\n const anchored = isAnchored(child) ? child : null;\r\n return {\r\n toOffset: (x, y) => {\r\n const at = anchored?.anchorAt(x, y);\r\n return at ? map.toPoint(at.x, at.y, point) : map.toPoint(x, y, point);\r\n },\r\n toCoords: (x, y) => map.toCoords(x, y),\r\n };\r\n}\r\n\r\n// A mark reads its own `x`/`y` as it draws, so its holder adds nothing; a drag still answers in graph units.\r\nfunction markPlane(map: CoordinateMap, cx: number, cy: number): ChildPlane {\r\n const none: Vector2 = { x: 0, y: 0 };\r\n return {\r\n toOffset: () => none,\r\n toCoords: (x, y) => map.toCoords(cx + x, cy + y),\r\n };\r\n}\r\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The coordinate systems a 2D plot or mark goes inside, for a node's `within`.
|
|
3
|
+
* A number plane is built on `axes2d`, so naming that covers it.
|
|
4
|
+
*/
|
|
5
|
+
export declare const SYSTEMS: readonly string[];
|
|
6
|
+
/** The systems, and a plot: where a mark that may ride a curve goes. */
|
|
7
|
+
export declare const SYSTEMS_AND_PLOT: readonly string[];
|
|
8
|
+
//# sourceMappingURL=placement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placement.d.ts","sourceRoot":"","sources":["../../src/kit/placement.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,OAAO,EAAE,SAAS,MAAM,EAA2C,CAAC;AAEjF,wEAAwE;AACxE,eAAO,MAAM,gBAAgB,EAAE,SAAS,MAAM,EAAiC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The coordinate systems a 2D plot or mark goes inside, for a node's `within`.
|
|
3
|
+
* A number plane is built on `axes2d`, so naming that covers it.
|
|
4
|
+
*/
|
|
5
|
+
export const SYSTEMS = ["axes2d", "numberLine", "polarPlane"];
|
|
6
|
+
/** The systems, and a plot: where a mark that may ride a curve goes. */
|
|
7
|
+
export const SYSTEMS_AND_PLOT = [...SYSTEMS, "functionPlot"];
|
|
8
|
+
//# sourceMappingURL=placement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placement.js","sourceRoot":"","sources":["../../src/kit/placement.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAsB,CAAC,QAAQ,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC;AAEjF,wEAAwE;AACxE,MAAM,CAAC,MAAM,gBAAgB,GAAsB,CAAC,GAAG,OAAO,EAAE,cAAc,CAAC,CAAC","sourcesContent":["/**\r\n * The coordinate systems a 2D plot or mark goes inside, for a node's `within`.\r\n * A number plane is built on `axes2d`, so naming that covers it.\r\n */\r\nexport const SYSTEMS: readonly string[] = [\"axes2d\", \"numberLine\", \"polarPlane\"];\r\n\r\n/** The systems, and a plot: where a mark that may ride a curve goes. */\r\nexport const SYSTEMS_AND_PLOT: readonly string[] = [...SYSTEMS, \"functionPlot\"];\r\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Extents, Vector2 } from "@motionscript/sdk";
|
|
2
|
+
/**
|
|
3
|
+
* Turns a curve into the polylines that draw it: adaptively, so a straight
|
|
4
|
+
* stretch costs two points and a tight bend as many as it needs, and broken
|
|
5
|
+
* wherever the curve is, at an asymptote or the edge of its domain.
|
|
6
|
+
*/
|
|
7
|
+
/** A curve's parameter to its pixel, written into `out`. `false` where the curve is undefined. */
|
|
8
|
+
export type CurveProjection = (t: number, out: Vector2) => boolean;
|
|
9
|
+
export interface SampleOptions {
|
|
10
|
+
/** The equal steps the parameter range starts as, before any is split. */
|
|
11
|
+
seeds?: number;
|
|
12
|
+
/** A parameter step that is not split again, however bent. */
|
|
13
|
+
minStep?: number;
|
|
14
|
+
}
|
|
15
|
+
/** The runs of points that draw `project` over `[t0, t1]`, clipped to `clip`. */
|
|
16
|
+
export declare function sampleCurve(project: CurveProjection, t0: number, t1: number, clip: Extents, { seeds, minStep }?: SampleOptions): Vector2[][];
|
|
17
|
+
//# sourceMappingURL=sampler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sampler.d.ts","sourceRoot":"","sources":["../../src/kit/sampler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE1D;;;;GAIG;AAEH,kGAAkG;AAClG,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC;AAEnE,MAAM,WAAW,aAAa;IAC1B,0EAA0E;IAC1E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8DAA8D;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AA8CD,iFAAiF;AACjF,wBAAgB,WAAW,CACvB,OAAO,EAAE,eAAe,EACxB,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,OAAO,EACb,EAAE,KAAqB,EAAE,OAAW,EAAE,GAAE,aAAkB,GAC3D,OAAO,EAAE,EAAE,CAsFb"}
|