@tinyvolt/pie 0.9.0 → 0.11.0
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/README.md +18 -1
- package/dist/components/SplitPane.d.ts +21 -0
- package/dist/components/SplitPane.jsx +113 -0
- package/dist/components/icons.d.ts +12 -0
- package/dist/components/icons.jsx +45 -0
- package/dist/lib/autodiff/index.d.ts +28 -0
- package/dist/lib/autodiff/index.js +39 -0
- package/dist/lib/customModules.d.ts +19 -0
- package/dist/lib/customModules.js +52 -0
- package/dist/lib/markdown/compile.d.ts +27 -0
- package/dist/lib/markdown/compile.js +26 -0
- package/dist/lib/markdown/components/CanvasPage.d.ts +9 -0
- package/dist/lib/markdown/components/CanvasPage.jsx +16 -0
- package/dist/lib/markdown/components/MarkdownBody.d.ts +11 -0
- package/dist/lib/markdown/components/MarkdownBody.jsx +37 -0
- package/dist/lib/markdown/components/PiePage.d.ts +14 -0
- package/dist/lib/markdown/components/PiePage.jsx +42 -0
- package/dist/lib/markdown/components/PythonEditor.d.ts +10 -0
- package/dist/lib/markdown/components/PythonEditor.jsx +209 -0
- package/dist/lib/markdown/features/build.d.ts +60 -0
- package/dist/lib/markdown/features/build.js +36 -0
- package/dist/lib/markdown/features/glossary/View.d.ts +9 -0
- package/dist/lib/markdown/features/glossary/View.jsx +62 -0
- package/dist/lib/markdown/features/glossary/build.d.ts +6 -0
- package/dist/lib/markdown/features/glossary/build.js +81 -0
- package/dist/lib/markdown/features/sidebar/View.d.ts +11 -0
- package/dist/lib/markdown/features/sidebar/View.jsx +45 -0
- package/dist/lib/markdown/features/sidebar/build.d.ts +3 -0
- package/dist/lib/markdown/features/sidebar/build.js +7 -0
- package/dist/lib/markdown/features/tags/build.d.ts +7 -0
- package/dist/lib/markdown/features/tags/build.js +22 -0
- package/dist/lib/markdown/features/tags/url.d.ts +6 -0
- package/dist/lib/markdown/features/tags/url.js +10 -0
- package/dist/lib/markdown/features/toc/build.d.ts +7 -0
- package/dist/lib/markdown/features/toc/build.js +62 -0
- package/dist/lib/markdown/features/views.d.ts +4 -0
- package/dist/lib/markdown/features/views.jsx +11 -0
- package/dist/lib/markdown/frontmatter.d.ts +44 -0
- package/dist/lib/markdown/frontmatter.js +109 -0
- package/dist/lib/markdown/render.d.ts +6 -0
- package/dist/lib/markdown/render.js +95 -0
- package/dist/lib/nodes/animation.d.ts +14 -0
- package/dist/lib/nodes/animation.js +34 -0
- package/dist/lib/nodes/components/CenteredGrid.d.ts +20 -0
- package/dist/lib/nodes/components/CenteredGrid.jsx +44 -0
- package/dist/lib/nodes/components/NodeCanvas.d.ts +7 -0
- package/dist/lib/nodes/components/NodeCanvas.jsx +50 -0
- package/dist/lib/nodes/execute.d.ts +27 -0
- package/dist/lib/nodes/execute.js +159 -0
- package/dist/lib/nodes/functions/Node2NodeFunc.d.ts +70 -0
- package/dist/lib/nodes/functions/Node2NodeFunc.js +223 -0
- package/dist/lib/nodes/functions/array.d.ts +12 -0
- package/dist/lib/nodes/functions/array.js +31 -0
- package/dist/lib/nodes/functions/autodiff.d.ts +12 -0
- package/dist/lib/nodes/functions/autodiff.js +60 -0
- package/dist/lib/nodes/functions/basic.d.ts +111 -0
- package/dist/lib/nodes/functions/basic.js +275 -0
- package/dist/lib/nodes/functions/registry.d.ts +9 -0
- package/dist/lib/nodes/functions/registry.js +45 -0
- package/dist/lib/nodes/functions/sideEffects.d.ts +78 -0
- package/dist/lib/nodes/functions/sideEffects.js +201 -0
- package/dist/lib/nodes/hooks/useCanvasGestures.d.ts +9 -0
- package/dist/lib/nodes/hooks/useCanvasGestures.js +120 -0
- package/dist/lib/nodes/hooks/useCanvasResize.d.ts +2 -0
- package/dist/lib/nodes/hooks/useCanvasResize.js +33 -0
- package/dist/lib/nodes/jax.d.ts +46 -0
- package/dist/lib/nodes/jax.js +120 -0
- package/dist/lib/nodes/render/renderLogic.d.ts +13 -0
- package/dist/lib/nodes/render/renderLogic.jsx +234 -0
- package/dist/lib/nodes/state/NameGenerator.d.ts +10 -0
- package/dist/lib/nodes/state/NameGenerator.js +29 -0
- package/dist/lib/nodes/state/Node.d.ts +134 -0
- package/dist/lib/nodes/state/Node.js +57 -0
- package/dist/lib/nodes/state/NodeStore.d.ts +49 -0
- package/dist/lib/nodes/state/NodeStore.js +138 -0
- package/dist/lib/nodes/tensors/broadcast.d.ts +18 -0
- package/dist/lib/nodes/tensors/broadcast.js +92 -0
- package/dist/lib/nodes/tensors/tensor.d.ts +13 -0
- package/dist/lib/nodes/tensors/tensor.js +34 -0
- package/dist/lib/python/lift.d.ts +51 -0
- package/dist/lib/python/lift.js +155 -0
- package/dist/lib/python/py/pie.py +303 -0
- package/dist/lib/python/py/pie_mpl.py +15 -0
- package/dist/lib/python/py/show_figures.py +5 -0
- package/dist/lib/python/runPage.d.ts +21 -0
- package/dist/lib/python/runPage.js +60 -0
- package/dist/lib/python/runner.d.ts +68 -0
- package/dist/lib/python/runner.js +243 -0
- package/dist/lib/python/worker.d.ts +1 -0
- package/dist/lib/python/worker.js +111 -0
- package/dist/lib/ui/UiLayer.d.ts +2 -0
- package/dist/lib/ui/UiLayer.jsx +15 -0
- package/dist/lib/ui/UiView.d.ts +23 -0
- package/dist/lib/ui/UiView.jsx +56 -0
- package/dist/lib/ui/components/checkboxes.d.ts +10 -0
- package/dist/lib/ui/components/checkboxes.jsx +30 -0
- package/dist/lib/ui/components/latex.d.ts +8 -0
- package/dist/lib/ui/components/latex.jsx +41 -0
- package/dist/lib/ui/components/radio.d.ts +6 -0
- package/dist/lib/ui/components/radio.jsx +19 -0
- package/dist/lib/ui/components/slider.d.ts +8 -0
- package/dist/lib/ui/components/slider.jsx +7 -0
- package/dist/lib/ui/components/textbox.d.ts +5 -0
- package/dist/lib/ui/components/textbox.jsx +21 -0
- package/dist/lib/ui/dragUi.d.ts +10 -0
- package/dist/lib/ui/dragUi.js +129 -0
- package/dist/lib/ui/nodeHandle.d.ts +15 -0
- package/dist/lib/ui/nodeHandle.js +37 -0
- package/dist/lib/ui/registry.d.ts +10 -0
- package/dist/lib/ui/registry.js +42 -0
- package/dist/runtime.css +696 -0
- package/dist/runtime.d.ts +10 -0
- package/dist/runtime.jsx +7 -0
- package/init/index.js +2 -2
- package/init/site-agents.md +2 -1
- package/package.json +15 -6
- package/runtime-agents.md +168 -0
- package/src/app.css +7 -665
- package/src/lib/customModules.ts +67 -0
- package/src/lib/markdown/compile.ts +49 -0
- package/src/lib/markdown/components/PiePage.tsx +49 -0
- package/src/lib/markdown/features/build.ts +15 -6
- package/src/lib/markdown/features/sidebar/View.tsx +4 -2
- package/src/lib/markdown/features/tags/build.ts +6 -3
- package/src/lib/markdown/pages.ts +1 -9
- package/src/lib/markdown/vitePlugin.ts +4 -8
- package/src/lib/nodes/functions/registry.ts +30 -21
- package/src/lib/nodes/functions/sideEffects.ts +14 -8
- package/src/lib/nodes/functions/vitePlugin.ts +8 -10
- package/src/lib/nodes/state/Node.ts +27 -19
- package/src/lib/python/runPage.ts +78 -0
- package/src/lib/python/runner.ts +189 -164
- package/src/lib/siteModules.ts +13 -0
- package/src/lib/ui/dragUi.ts +4 -2
- package/src/lib/ui/registry.ts +35 -14
- package/src/page.css +664 -0
- package/src/routes/[...slug].tsx +1 -0
- package/src/runtime.css +29 -0
- package/src/runtime.tsx +16 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { Node2NodeFunc } from './Node2NodeFunc';
|
|
2
|
+
/**
|
|
3
|
+
* Create a scalar value from another scalar.
|
|
4
|
+
* @param value - Input scalar value
|
|
5
|
+
* @returns Scalar node
|
|
6
|
+
* @auxiliaryNodes None
|
|
7
|
+
*/
|
|
8
|
+
export declare const Scalar: Node2NodeFunc;
|
|
9
|
+
/**
|
|
10
|
+
* Create a text node with a string value. It is drawn only when given both x and y.
|
|
11
|
+
* @param value - Text string value (default '')
|
|
12
|
+
* @param x - X coordinate of the center (default: not drawn)
|
|
13
|
+
* @param y - Y coordinate of the center (default: not drawn)
|
|
14
|
+
* @param fontSize - Font size in pixels (default 12)
|
|
15
|
+
* @param w - Box width: 0 with h 0 = one line, no box; above 0 = fixed; -1 = fits the text, at most 5 (default 0)
|
|
16
|
+
* @param h - Box height: 0 with w 0 = one line, no box; above 0 = fixed; -1 = fits the text, at most 5 (default 0)
|
|
17
|
+
* @returns Text node
|
|
18
|
+
* @auxiliaryNodes None
|
|
19
|
+
*/
|
|
20
|
+
export declare const Text: Node2NodeFunc;
|
|
21
|
+
/**
|
|
22
|
+
* Create a point from x and y coordinates.
|
|
23
|
+
* @param x - X coordinate
|
|
24
|
+
* @param y - Y coordinate
|
|
25
|
+
* @returns Point node
|
|
26
|
+
* @auxiliaryNodes None
|
|
27
|
+
*/
|
|
28
|
+
export declare const Point: Node2NodeFunc;
|
|
29
|
+
/**
|
|
30
|
+
* Create a triangle from three vertex points.
|
|
31
|
+
* @param vertex1 - First vertex point
|
|
32
|
+
* @param vertex2 - Second vertex point
|
|
33
|
+
* @param vertex3 - Third vertex point
|
|
34
|
+
* @returns Triangle node
|
|
35
|
+
* @auxiliaryNodes l_0, l_1, l_2 (Line nodes)
|
|
36
|
+
*/
|
|
37
|
+
export declare const Triangle: Node2NodeFunc;
|
|
38
|
+
/**
|
|
39
|
+
* Create a line from two points.
|
|
40
|
+
* @param point1 - First point
|
|
41
|
+
* @param point2 - Second point
|
|
42
|
+
* @returns Line node
|
|
43
|
+
* @auxiliaryNodes None
|
|
44
|
+
*/
|
|
45
|
+
export declare const Line: Node2NodeFunc;
|
|
46
|
+
/**
|
|
47
|
+
* Compute the distance between two points.
|
|
48
|
+
* @param point1 - First point
|
|
49
|
+
* @param point2 - Second point
|
|
50
|
+
* @returns Scalar node
|
|
51
|
+
* @auxiliaryNodes None
|
|
52
|
+
*/
|
|
53
|
+
export declare const Distance: Node2NodeFunc;
|
|
54
|
+
/**
|
|
55
|
+
* Create a circle with a center point and radius.
|
|
56
|
+
* @param center - Center point of the circle
|
|
57
|
+
* @param radius - Radius of the circle
|
|
58
|
+
* @returns Circle node
|
|
59
|
+
* @auxiliaryNodes None
|
|
60
|
+
*/
|
|
61
|
+
export declare const Circle: Node2NodeFunc;
|
|
62
|
+
/**
|
|
63
|
+
* Create an ellipse with center, radii, and rotation.
|
|
64
|
+
* @param center - Center point of the ellipse
|
|
65
|
+
* @param radiusX - Horizontal radius
|
|
66
|
+
* @param radiusY - Vertical radius
|
|
67
|
+
* @param rotation - Rotation angle in degrees
|
|
68
|
+
* @returns Ellipse node
|
|
69
|
+
* @auxiliaryNodes None
|
|
70
|
+
*/
|
|
71
|
+
export declare const Ellipse: Node2NodeFunc;
|
|
72
|
+
/**
|
|
73
|
+
* Create a quadratic Bezier curve from two endpoints and a control point.
|
|
74
|
+
* @param p1 - Start point
|
|
75
|
+
* @param control - Control point
|
|
76
|
+
* @param p2 - End point
|
|
77
|
+
* @returns BezierQuadratic node
|
|
78
|
+
* @auxiliaryNodes None
|
|
79
|
+
*/
|
|
80
|
+
export declare const BezierQuadratic: Node2NodeFunc;
|
|
81
|
+
/**
|
|
82
|
+
* Create a cubic Bezier curve from two endpoints and two control points.
|
|
83
|
+
* @param p1 - Start point
|
|
84
|
+
* @param control1 - First control point
|
|
85
|
+
* @param control2 - Second control point
|
|
86
|
+
* @param p2 - End point
|
|
87
|
+
* @returns BezierCubic node
|
|
88
|
+
* @auxiliaryNodes None
|
|
89
|
+
*/
|
|
90
|
+
export declare const BezierCubic: Node2NodeFunc;
|
|
91
|
+
/**
|
|
92
|
+
* Create an arc with center, radius, and start/end angles.
|
|
93
|
+
* @param center - Center point of the arc
|
|
94
|
+
* @param radius - Radius of the arc
|
|
95
|
+
* @param startAngle - Start angle in degrees
|
|
96
|
+
* @param endAngle - End angle in degrees
|
|
97
|
+
* @returns Arc node
|
|
98
|
+
* @auxiliaryNodes None
|
|
99
|
+
*/
|
|
100
|
+
export declare const Arc: Node2NodeFunc;
|
|
101
|
+
/**
|
|
102
|
+
* Create an ellipse from two foci and a string length.
|
|
103
|
+
* @param focus1 - First focus point
|
|
104
|
+
* @param focus2 - Second focus point
|
|
105
|
+
* @param stringLength - Total string length (sum of distances from any point on ellipse to both foci)
|
|
106
|
+
* @returns Ellipse node
|
|
107
|
+
* @auxiliaryNodes center, radiusX, radiusY, rotation
|
|
108
|
+
*/
|
|
109
|
+
export declare const EllipseFromFociAndStringLength: Node2NodeFunc;
|
|
110
|
+
/** Docs category for the functions defined in this file. */
|
|
111
|
+
export declare const category = "Basic Figures";
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { scalar, num, add, sub, mul, div, sqrt, ref } from '../jax';
|
|
2
|
+
/**
|
|
3
|
+
* Create a scalar value from another scalar.
|
|
4
|
+
* @param value - Input scalar value
|
|
5
|
+
* @returns Scalar node
|
|
6
|
+
* @auxiliaryNodes None
|
|
7
|
+
*/
|
|
8
|
+
export const Scalar = {
|
|
9
|
+
keyword: 'scalar', outputType: 'Scalar',
|
|
10
|
+
parameters: [{ name: 'value', type: 'Scalar' }],
|
|
11
|
+
compute(inputs) {
|
|
12
|
+
const inner = (ins) => {
|
|
13
|
+
const valueNode = ins[0];
|
|
14
|
+
const value = valueNode?.value || scalar(0);
|
|
15
|
+
return { main: { type: 'Scalar', value } };
|
|
16
|
+
};
|
|
17
|
+
return inner(inputs);
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Create a text node with a string value. It is drawn only when given both x and y.
|
|
22
|
+
* @param value - Text string value (default '')
|
|
23
|
+
* @param x - X coordinate of the center (default: not drawn)
|
|
24
|
+
* @param y - Y coordinate of the center (default: not drawn)
|
|
25
|
+
* @param fontSize - Font size in pixels (default 12)
|
|
26
|
+
* @param w - Box width: 0 with h 0 = one line, no box; above 0 = fixed; -1 = fits the text, at most 5 (default 0)
|
|
27
|
+
* @param h - Box height: 0 with w 0 = one line, no box; above 0 = fixed; -1 = fits the text, at most 5 (default 0)
|
|
28
|
+
* @returns Text node
|
|
29
|
+
* @auxiliaryNodes None
|
|
30
|
+
*/
|
|
31
|
+
export const Text = {
|
|
32
|
+
keyword: 'text', outputType: 'Text',
|
|
33
|
+
parameters: [
|
|
34
|
+
{ name: 'value', type: 'Text', defaultValue: '' },
|
|
35
|
+
{ name: 'x', type: 'Scalar', defaultValue: null },
|
|
36
|
+
{ name: 'y', type: 'Scalar', defaultValue: null },
|
|
37
|
+
{ name: 'fontSize', type: 'Scalar', defaultValue: 12 },
|
|
38
|
+
{ name: 'w', type: 'Scalar', defaultValue: 0 },
|
|
39
|
+
{ name: 'h', type: 'Scalar', defaultValue: 0 },
|
|
40
|
+
],
|
|
41
|
+
compute(inputs) {
|
|
42
|
+
const inner = (ins) => {
|
|
43
|
+
const textNode = ins[0];
|
|
44
|
+
const value = textNode?.value || '';
|
|
45
|
+
const [x, y, fontSize, w, h] = ins.slice(1);
|
|
46
|
+
return { main: { type: 'Text', value, x, y, fontSize, w, h } };
|
|
47
|
+
};
|
|
48
|
+
return inner(inputs);
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Create a point from x and y coordinates.
|
|
53
|
+
* @param x - X coordinate
|
|
54
|
+
* @param y - Y coordinate
|
|
55
|
+
* @returns Point node
|
|
56
|
+
* @auxiliaryNodes None
|
|
57
|
+
*/
|
|
58
|
+
export const Point = {
|
|
59
|
+
keyword: 'point', outputType: 'Point',
|
|
60
|
+
parameters: [{ name: 'x', type: 'Scalar' }, { name: 'y', type: 'Scalar' }],
|
|
61
|
+
compute(inputs) {
|
|
62
|
+
const inner = (ins) => {
|
|
63
|
+
const xNode = ins[0];
|
|
64
|
+
const yNode = ins[1];
|
|
65
|
+
return {
|
|
66
|
+
main: {
|
|
67
|
+
type: 'Point',
|
|
68
|
+
x: xNode.value,
|
|
69
|
+
y: yNode.value
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
return inner(inputs);
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Create a triangle from three vertex points.
|
|
78
|
+
* @param vertex1 - First vertex point
|
|
79
|
+
* @param vertex2 - Second vertex point
|
|
80
|
+
* @param vertex3 - Third vertex point
|
|
81
|
+
* @returns Triangle node
|
|
82
|
+
* @auxiliaryNodes l_0, l_1, l_2 (Line nodes)
|
|
83
|
+
*/
|
|
84
|
+
export const Triangle = {
|
|
85
|
+
keyword: 'triangle', outputType: 'Triangle',
|
|
86
|
+
parameters: [{ name: 'vertex1', type: 'Point' }, { name: 'vertex2', type: 'Point' }, { name: 'vertex3', type: 'Point' }],
|
|
87
|
+
compute(inputs) {
|
|
88
|
+
const inner = (ins) => {
|
|
89
|
+
const nodes = {};
|
|
90
|
+
for (let i = 0; i < 3; i++) {
|
|
91
|
+
nodes[`l_${i}`] = { type: 'Line', p1: ins[i], p2: ins[(i + 1) % 3] };
|
|
92
|
+
}
|
|
93
|
+
nodes['main'] = { type: 'Triangle', vertices: ins };
|
|
94
|
+
return nodes;
|
|
95
|
+
};
|
|
96
|
+
return inner(inputs);
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Create a line from two points.
|
|
101
|
+
* @param point1 - First point
|
|
102
|
+
* @param point2 - Second point
|
|
103
|
+
* @returns Line node
|
|
104
|
+
* @auxiliaryNodes None
|
|
105
|
+
*/
|
|
106
|
+
export const Line = {
|
|
107
|
+
keyword: 'line', outputType: 'Line',
|
|
108
|
+
parameters: [{ name: 'point1', type: 'Point' }, { name: 'point2', type: 'Point' }],
|
|
109
|
+
compute(inputs) {
|
|
110
|
+
const inner = (ins) => ({ main: { type: 'Line', p1: ins[0], p2: ins[1] } });
|
|
111
|
+
return inner(inputs);
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Compute the distance between two points.
|
|
116
|
+
* @param point1 - First point
|
|
117
|
+
* @param point2 - Second point
|
|
118
|
+
* @returns Scalar node
|
|
119
|
+
* @auxiliaryNodes None
|
|
120
|
+
*/
|
|
121
|
+
export const Distance = {
|
|
122
|
+
keyword: 'distance', outputType: 'Scalar',
|
|
123
|
+
parameters: [{ name: 'point1', type: 'Point' }, { name: 'point2', type: 'Point' }],
|
|
124
|
+
compute(inputs) {
|
|
125
|
+
const inner = (ins) => {
|
|
126
|
+
const p1 = ins[0];
|
|
127
|
+
const p2 = ins[1];
|
|
128
|
+
const dx = sub(ref(p2.x), ref(p1.x));
|
|
129
|
+
const dy = sub(ref(p2.y), ref(p1.y));
|
|
130
|
+
const value = sqrt(add(mul(ref(dx), ref(dx)), mul(ref(dy), ref(dy))));
|
|
131
|
+
return { main: { type: 'Scalar', value } };
|
|
132
|
+
};
|
|
133
|
+
return inner(inputs);
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Create a circle with a center point and radius.
|
|
138
|
+
* @param center - Center point of the circle
|
|
139
|
+
* @param radius - Radius of the circle
|
|
140
|
+
* @returns Circle node
|
|
141
|
+
* @auxiliaryNodes None
|
|
142
|
+
*/
|
|
143
|
+
export const Circle = {
|
|
144
|
+
keyword: 'circle', outputType: 'Circle',
|
|
145
|
+
parameters: [{ name: 'center', type: 'Point' }, { name: 'radius', type: 'Scalar' }],
|
|
146
|
+
compute(inputs) {
|
|
147
|
+
const inner = (ins) => ({ main: { type: 'Circle', center: ins[0], radius: ins[1] } });
|
|
148
|
+
return inner(inputs);
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Create an ellipse with center, radii, and rotation.
|
|
153
|
+
* @param center - Center point of the ellipse
|
|
154
|
+
* @param radiusX - Horizontal radius
|
|
155
|
+
* @param radiusY - Vertical radius
|
|
156
|
+
* @param rotation - Rotation angle in degrees
|
|
157
|
+
* @returns Ellipse node
|
|
158
|
+
* @auxiliaryNodes None
|
|
159
|
+
*/
|
|
160
|
+
export const Ellipse = {
|
|
161
|
+
keyword: 'ellipse', outputType: 'Ellipse',
|
|
162
|
+
parameters: [
|
|
163
|
+
{ name: 'center', type: 'Point' },
|
|
164
|
+
{ name: 'radiusX', type: 'Scalar' },
|
|
165
|
+
{ name: 'radiusY', type: 'Scalar' },
|
|
166
|
+
{ name: 'rotation', type: 'Scalar' }
|
|
167
|
+
],
|
|
168
|
+
compute(inputs) {
|
|
169
|
+
const inner = (ins) => ({ main: { type: 'Ellipse', center: ins[0], radiusX: ins[1], radiusY: ins[2], rotation: ins[3] } });
|
|
170
|
+
return inner(inputs);
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* Create a quadratic Bezier curve from two endpoints and a control point.
|
|
175
|
+
* @param p1 - Start point
|
|
176
|
+
* @param control - Control point
|
|
177
|
+
* @param p2 - End point
|
|
178
|
+
* @returns BezierQuadratic node
|
|
179
|
+
* @auxiliaryNodes None
|
|
180
|
+
*/
|
|
181
|
+
export const BezierQuadratic = {
|
|
182
|
+
keyword: 'bezier_quadratic', outputType: 'BezierQuadratic',
|
|
183
|
+
parameters: [{ name: 'p1', type: 'Point' }, { name: 'control', type: 'Point' }, { name: 'p2', type: 'Point' }],
|
|
184
|
+
compute(inputs) {
|
|
185
|
+
const inner = (ins) => ({ main: { type: 'BezierQuadratic', p1: ins[0], control: ins[1], p2: ins[2] } });
|
|
186
|
+
return inner(inputs);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Create a cubic Bezier curve from two endpoints and two control points.
|
|
191
|
+
* @param p1 - Start point
|
|
192
|
+
* @param control1 - First control point
|
|
193
|
+
* @param control2 - Second control point
|
|
194
|
+
* @param p2 - End point
|
|
195
|
+
* @returns BezierCubic node
|
|
196
|
+
* @auxiliaryNodes None
|
|
197
|
+
*/
|
|
198
|
+
export const BezierCubic = {
|
|
199
|
+
keyword: 'bezier_cubic', outputType: 'BezierCubic',
|
|
200
|
+
parameters: [{ name: 'p1', type: 'Point' }, { name: 'control1', type: 'Point' }, { name: 'control2', type: 'Point' }, { name: 'p2', type: 'Point' }],
|
|
201
|
+
compute(inputs) {
|
|
202
|
+
const inner = (ins) => ({ main: { type: 'BezierCubic', p1: ins[0], control1: ins[1], control2: ins[2], p2: ins[3] } });
|
|
203
|
+
return inner(inputs);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* Create an arc with center, radius, and start/end angles.
|
|
208
|
+
* @param center - Center point of the arc
|
|
209
|
+
* @param radius - Radius of the arc
|
|
210
|
+
* @param startAngle - Start angle in degrees
|
|
211
|
+
* @param endAngle - End angle in degrees
|
|
212
|
+
* @returns Arc node
|
|
213
|
+
* @auxiliaryNodes None
|
|
214
|
+
*/
|
|
215
|
+
export const Arc = {
|
|
216
|
+
keyword: 'arc', outputType: 'Arc',
|
|
217
|
+
parameters: [{ name: 'center', type: 'Point' }, { name: 'radius', type: 'Scalar' }, { name: 'startAngle', type: 'Scalar' }, { name: 'endAngle', type: 'Scalar' }],
|
|
218
|
+
compute(inputs) {
|
|
219
|
+
const inner = (ins) => ({ main: { type: 'Arc', center: ins[0], radius: ins[1], startAngle: ins[2], endAngle: ins[3] } });
|
|
220
|
+
return inner(inputs);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* Create an ellipse from two foci and a string length.
|
|
225
|
+
* @param focus1 - First focus point
|
|
226
|
+
* @param focus2 - Second focus point
|
|
227
|
+
* @param stringLength - Total string length (sum of distances from any point on ellipse to both foci)
|
|
228
|
+
* @returns Ellipse node
|
|
229
|
+
* @auxiliaryNodes center, radiusX, radiusY, rotation
|
|
230
|
+
*/
|
|
231
|
+
export const EllipseFromFociAndStringLength = {
|
|
232
|
+
keyword: 'ellipse_from_foci', outputType: 'Ellipse',
|
|
233
|
+
parameters: [
|
|
234
|
+
{ name: 'focus1', type: 'Point' },
|
|
235
|
+
{ name: 'focus2', type: 'Point' },
|
|
236
|
+
{ name: 'stringLength', type: 'Scalar' }
|
|
237
|
+
],
|
|
238
|
+
compute(inputs) {
|
|
239
|
+
const inner = (ins) => {
|
|
240
|
+
const focus1 = ins[0];
|
|
241
|
+
const focus2 = ins[1];
|
|
242
|
+
const stringLengthNode = ins[2];
|
|
243
|
+
const dx = sub(ref(focus2.x), ref(focus1.x));
|
|
244
|
+
const dy = sub(ref(focus2.y), ref(focus1.y));
|
|
245
|
+
const focalDistance = sqrt(add(mul(ref(dx), ref(dx)), mul(ref(dy), ref(dy))));
|
|
246
|
+
if (num(stringLengthNode.value) <= num(focalDistance)) {
|
|
247
|
+
return { main: { type: 'Dummy' } };
|
|
248
|
+
}
|
|
249
|
+
const cx = div(add(ref(focus1.x), ref(focus2.x)), scalar(2));
|
|
250
|
+
const cy = div(add(ref(focus1.y), ref(focus2.y)), scalar(2));
|
|
251
|
+
const center = { type: 'Point', x: cx, y: cy };
|
|
252
|
+
const c = div(ref(focalDistance), scalar(2));
|
|
253
|
+
const a = div(ref(stringLengthNode.value), scalar(2));
|
|
254
|
+
const cSquared = mul(ref(c), ref(c));
|
|
255
|
+
const aSquared = mul(ref(a), ref(a));
|
|
256
|
+
const bSquared = sub(ref(aSquared), ref(cSquared));
|
|
257
|
+
const b = sqrt(ref(bSquared));
|
|
258
|
+
const angleRad = scalar(Math.atan2(num(dy), num(dx)));
|
|
259
|
+
const angleDeg = div(mul(ref(angleRad), scalar(180)), scalar(Math.PI));
|
|
260
|
+
const radiusX = { type: 'Scalar', value: a };
|
|
261
|
+
const radiusY = { type: 'Scalar', value: b };
|
|
262
|
+
const rotation = { type: 'Scalar', value: angleDeg };
|
|
263
|
+
return {
|
|
264
|
+
center,
|
|
265
|
+
radiusX,
|
|
266
|
+
radiusY,
|
|
267
|
+
rotation,
|
|
268
|
+
main: { type: 'Ellipse', center, radiusX, radiusY, rotation }
|
|
269
|
+
};
|
|
270
|
+
};
|
|
271
|
+
return inner(inputs);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
/** Docs category for the functions defined in this file. */
|
|
275
|
+
export const category = 'Basic Figures';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CustomModule } from '../../customModules';
|
|
2
|
+
import { Node2NodeFunc, SideEffectFunc } from './Node2NodeFunc';
|
|
3
|
+
/**
|
|
4
|
+
* Replaces the custom functions with the `Node2NodeFunc`s and `SideEffectFunc`s that `modules` export, e.g. a site's `functions/**\/*.ts`.
|
|
5
|
+
* Throws on a keyword used twice, leaving the functions as they were.
|
|
6
|
+
*/
|
|
7
|
+
export declare function setCustomFunctions(modules: CustomModule[]): void;
|
|
8
|
+
export declare function getFunction(keyword: string): Node2NodeFunc | undefined;
|
|
9
|
+
export declare function getSideEffect(keyword: string): SideEffectFunc | undefined;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as basicNodes from './basic';
|
|
2
|
+
import * as autodiffNodes from './autodiff';
|
|
3
|
+
import * as arrayNodes from './array';
|
|
4
|
+
import * as sideEffects from './sideEffects';
|
|
5
|
+
const isNode2NodeFunc = (fn) => typeof fn === 'object' && fn !== null && typeof fn.compute === 'function';
|
|
6
|
+
const isSideEffectFunc = (fn) => typeof fn === 'object' && fn !== null && typeof fn.run === 'function';
|
|
7
|
+
const BUILTINS = [
|
|
8
|
+
{ file: 'src/lib/nodes/functions/basic.ts', exports: basicNodes },
|
|
9
|
+
{ file: 'src/lib/nodes/functions/autodiff.ts', exports: autodiffNodes },
|
|
10
|
+
{ file: 'src/lib/nodes/functions/array.ts', exports: arrayNodes },
|
|
11
|
+
{ file: 'src/lib/nodes/functions/sideEffects.ts', exports: sideEffects },
|
|
12
|
+
];
|
|
13
|
+
let functionRegistry = new Map();
|
|
14
|
+
let sideEffectRegistry = new Map();
|
|
15
|
+
/**
|
|
16
|
+
* Replaces the custom functions with the `Node2NodeFunc`s and `SideEffectFunc`s that `modules` export, e.g. a site's `functions/**\/*.ts`.
|
|
17
|
+
* Throws on a keyword used twice, leaving the functions as they were.
|
|
18
|
+
*/
|
|
19
|
+
export function setCustomFunctions(modules) {
|
|
20
|
+
const functions = new Map();
|
|
21
|
+
const effects = new Map();
|
|
22
|
+
const sourceFile = new Map();
|
|
23
|
+
for (const { file, exports } of [...BUILTINS, ...modules]) {
|
|
24
|
+
for (const fn of Object.values(exports).filter(fn => isNode2NodeFunc(fn) || isSideEffectFunc(fn))) {
|
|
25
|
+
const other = sourceFile.get(fn.keyword);
|
|
26
|
+
if (other !== undefined) {
|
|
27
|
+
throw new Error(`Duplicate function keyword '${fn.keyword}': ${file} and ${other}`);
|
|
28
|
+
}
|
|
29
|
+
if (isSideEffectFunc(fn))
|
|
30
|
+
effects.set(fn.keyword, fn);
|
|
31
|
+
else
|
|
32
|
+
functions.set(fn.keyword, fn);
|
|
33
|
+
sourceFile.set(fn.keyword, file);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
functionRegistry = functions;
|
|
37
|
+
sideEffectRegistry = effects;
|
|
38
|
+
}
|
|
39
|
+
setCustomFunctions([]);
|
|
40
|
+
export function getFunction(keyword) {
|
|
41
|
+
return functionRegistry.get(keyword);
|
|
42
|
+
}
|
|
43
|
+
export function getSideEffect(keyword) {
|
|
44
|
+
return sideEffectRegistry.get(keyword);
|
|
45
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { SideEffectFunc } from './Node2NodeFunc';
|
|
2
|
+
import { AnyNode } from '../state/Node';
|
|
3
|
+
import { NodeStore } from '../state/NodeStore';
|
|
4
|
+
import type { Track } from '../animation';
|
|
5
|
+
/**
|
|
6
|
+
* Saves `node` with `changes`, new values for some of its numbers, in place of `node`.
|
|
7
|
+
* It has no inputs, so it no longer follows the old node's.
|
|
8
|
+
* With `animate`, returns a track that moves the numbers from their old values to the new ones.
|
|
9
|
+
*/
|
|
10
|
+
export declare function replaceNode<N extends AnyNode>(store: NodeStore, node: N, changes: Partial<N>, animate: boolean): Track | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Hide a node: it is not drawn on the canvas.
|
|
13
|
+
* @param node - Node to hide
|
|
14
|
+
*/
|
|
15
|
+
export declare const Hide: SideEffectFunc;
|
|
16
|
+
/**
|
|
17
|
+
* Show a hidden node.
|
|
18
|
+
* @param node - Node to show
|
|
19
|
+
*/
|
|
20
|
+
export declare const Show: SideEffectFunc;
|
|
21
|
+
/**
|
|
22
|
+
* Remove a node from the canvas.
|
|
23
|
+
* @param node - Node to remove
|
|
24
|
+
*/
|
|
25
|
+
export declare const Remove: SideEffectFunc;
|
|
26
|
+
/**
|
|
27
|
+
* Set a node's fill.
|
|
28
|
+
* @param node - Node to change
|
|
29
|
+
* @param color - A CSS color, like 'red' or '#ff0000', or 'none'
|
|
30
|
+
*/
|
|
31
|
+
export declare const SetFill: SideEffectFunc;
|
|
32
|
+
/**
|
|
33
|
+
* Set a node's stroke.
|
|
34
|
+
* @param node - Node to change
|
|
35
|
+
* @param color - A CSS color, like 'red' or '#ff0000', or 'none'
|
|
36
|
+
*/
|
|
37
|
+
export declare const SetStroke: SideEffectFunc;
|
|
38
|
+
/**
|
|
39
|
+
* Clear the canvas and reset the system nodes.
|
|
40
|
+
*/
|
|
41
|
+
export declare const Clear: SideEffectFunc;
|
|
42
|
+
/**
|
|
43
|
+
* Show the canvas, and move it to `side` when given.
|
|
44
|
+
* @param side - 'left', 'right', 'top' or 'bottom' (default: where it is now)
|
|
45
|
+
*/
|
|
46
|
+
export declare const ShowCanvas: SideEffectFunc;
|
|
47
|
+
/**
|
|
48
|
+
* Hide the canvas. Its nodes stay.
|
|
49
|
+
*/
|
|
50
|
+
export declare const HideCanvas: SideEffectFunc;
|
|
51
|
+
/**
|
|
52
|
+
* Move a point to (x, y). With `animate=True` it moves there over half a second.
|
|
53
|
+
* @param point - Point to move
|
|
54
|
+
* @param x - New x coordinate
|
|
55
|
+
* @param y - New y coordinate
|
|
56
|
+
*/
|
|
57
|
+
export declare const TranslatePointTo: SideEffectFunc;
|
|
58
|
+
/**
|
|
59
|
+
* Move a point by (dx, dy). With `animate=True` it moves there over half a second.
|
|
60
|
+
* @param point - Point to move
|
|
61
|
+
* @param dx - Change in x
|
|
62
|
+
* @param dy - Change in y
|
|
63
|
+
*/
|
|
64
|
+
export declare const TranslatePointBy: SideEffectFunc;
|
|
65
|
+
/**
|
|
66
|
+
* Set a scalar to a new value. With `animate=True` it gets there over half a second.
|
|
67
|
+
* @param target - Scalar to change
|
|
68
|
+
* @param value - New value
|
|
69
|
+
*/
|
|
70
|
+
export declare const TranslateScalarTo: SideEffectFunc;
|
|
71
|
+
/**
|
|
72
|
+
* Add `delta` to a scalar. With `animate=True` it gets there over half a second.
|
|
73
|
+
* @param target - Scalar to change
|
|
74
|
+
* @param delta - Amount to add
|
|
75
|
+
*/
|
|
76
|
+
export declare const TranslateScalarBy: SideEffectFunc;
|
|
77
|
+
/** Docs category for the functions defined in this file. */
|
|
78
|
+
export declare const category = "Side Effects";
|