@tinyvolt/pie 0.8.2 → 0.10.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 +13 -0
- package/dist/lib/customModules.js +17 -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 +41 -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/runner.d.ts +36 -0
- package/dist/lib/python/runner.js +221 -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 +9 -0
- package/dist/runtime.jsx +6 -0
- package/init/index.js +2 -2
- package/init/site-agents.md +7 -3
- package/package.json +15 -6
- package/pages/about.md +4 -0
- package/runtime-agents.md +146 -0
- package/src/app.css +7 -665
- package/src/components/SplitPane.tsx +11 -9
- package/src/lib/customModules.ts +30 -0
- package/src/lib/markdown/compile.ts +49 -0
- package/src/lib/markdown/components/CanvasPage.tsx +9 -4
- package/src/lib/markdown/components/PiePage.tsx +48 -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 +48 -8
- package/src/lib/nodes/functions/vitePlugin.ts +8 -10
- package/src/lib/nodes/state/Node.ts +27 -19
- package/src/lib/nodes/state/NodeStore.ts +12 -1
- 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 +2 -3
- package/src/runtime.css +29 -0
- package/src/runtime.tsx +15 -0
|
@@ -3,6 +3,7 @@ import { createStore, reconcile } from 'solid-js/store';
|
|
|
3
3
|
import { AnyNode, ScalarNode, TextNode } from './Node';
|
|
4
4
|
import { NameGenerator } from './NameGenerator';
|
|
5
5
|
import { num, scalar } from '../jax';
|
|
6
|
+
import type { Collapsed, SplitSide } from '~/components/SplitPane';
|
|
6
7
|
|
|
7
8
|
/** Below this many pixels per unit, the grid hides its lines and keeps only the axes. */
|
|
8
9
|
export const MIN_GRID_UNIT = 20;
|
|
@@ -20,6 +21,13 @@ export class NodeStore {
|
|
|
20
21
|
public canvasBounds: Accessor<{ width: number; height: number }>;
|
|
21
22
|
public setCanvasBounds: (bounds: { width: number; height: number }) => void;
|
|
22
23
|
|
|
24
|
+
/** The side of the page the canvas sits on. */
|
|
25
|
+
public canvasSide: Accessor<SplitSide>;
|
|
26
|
+
public setCanvasSide: (side: SplitSide) => void;
|
|
27
|
+
/** The page's collapsed pane: `first` is the canvas, `second` the text. */
|
|
28
|
+
public collapsedPane: Accessor<Collapsed>;
|
|
29
|
+
public setCollapsedPane: (c: Collapsed) => void;
|
|
30
|
+
|
|
23
31
|
/** Pixels per grid unit, read from the `unit` node. */
|
|
24
32
|
public unit!: Accessor<number>;
|
|
25
33
|
/** Opacity multiplier for the grid lines and axes, read from the `gridOpacity` node. */
|
|
@@ -31,7 +39,7 @@ export class NodeStore {
|
|
|
31
39
|
|
|
32
40
|
public nameGenerator: NameGenerator;
|
|
33
41
|
|
|
34
|
-
constructor() {
|
|
42
|
+
constructor(canvasSide: SplitSide, collapsedPane: Collapsed) {
|
|
35
43
|
const [nodesState, setNodesState] = createStore<Record<string, NodeSignal>>({});
|
|
36
44
|
this.nodes = nodesState;
|
|
37
45
|
this.setNodes = (id, value) => { setNodesState(id, value as any); };
|
|
@@ -41,6 +49,9 @@ export class NodeStore {
|
|
|
41
49
|
this.canvasBounds = canvasBounds;
|
|
42
50
|
this.setCanvasBounds = setCanvasBounds;
|
|
43
51
|
|
|
52
|
+
[this.canvasSide, this.setCanvasSide] = createSignal(canvasSide);
|
|
53
|
+
[this.collapsedPane, this.setCollapsedPane] = createSignal(collapsedPane);
|
|
54
|
+
|
|
44
55
|
createRoot(() => {
|
|
45
56
|
this.unit = createMemo(() => {
|
|
46
57
|
const node = this.nodes['unit']?.signal() as ScalarNode | undefined;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// The site's own functions, node types and UIs: its `functions/`, `nodes/` and `ui/` folders.
|
|
2
|
+
// The page route imports this file. `checkFunctions` loads it at build start, so a name used twice fails the build.
|
|
3
|
+
import { setCustomModules, type CustomModule } from './customModules';
|
|
4
|
+
|
|
5
|
+
/** `/functions/a.ts` -> `functions/a.ts`, with its exports. */
|
|
6
|
+
const files = (modules: Record<string, Record<string, unknown>>): CustomModule[] =>
|
|
7
|
+
Object.entries(modules).map(([path, exports]) => ({ file: path.slice(1), exports }));
|
|
8
|
+
|
|
9
|
+
setCustomModules({
|
|
10
|
+
functions: files(import.meta.glob('/functions/**/*.ts', { eager: true })),
|
|
11
|
+
nodes: files(import.meta.glob('/nodes/**/*.{ts,tsx}', { eager: true })),
|
|
12
|
+
ui: files(import.meta.glob('/ui/**/*.{ts,tsx}', { eager: true })),
|
|
13
|
+
});
|
package/src/lib/ui/dragUi.ts
CHANGED
|
@@ -61,6 +61,8 @@ export function dragUi(e: PointerEvent, box: HTMLElement, text: HTMLElement) {
|
|
|
61
61
|
let frame = 0;
|
|
62
62
|
const line = document.createElement('div');
|
|
63
63
|
line.className = 'python-editor-ui-drop-line';
|
|
64
|
+
// Holds the box and the line while dragging. Inside the page, so styles limited to it apply; `fixed` keeps them unclipped.
|
|
65
|
+
const floating = text.parentElement!;
|
|
64
66
|
|
|
65
67
|
const overLayer = () => layer !== null && inside(layer.getBoundingClientRect(), pointer);
|
|
66
68
|
|
|
@@ -72,7 +74,7 @@ export function dragUi(e: PointerEvent, box: HTMLElement, text: HTMLElement) {
|
|
|
72
74
|
line.style.left = `${textRect.left}px`;
|
|
73
75
|
line.style.width = `${textRect.width}px`;
|
|
74
76
|
line.style.top = `${nearestGap(text, box, pointer.y).y}px`;
|
|
75
|
-
if (!line.isConnected)
|
|
77
|
+
if (!line.isConnected) floating.append(line);
|
|
76
78
|
};
|
|
77
79
|
|
|
78
80
|
const autoScroll = () => {
|
|
@@ -93,7 +95,7 @@ export function dragUi(e: PointerEvent, box: HTMLElement, text: HTMLElement) {
|
|
|
93
95
|
document.body.style.userSelect = 'none';
|
|
94
96
|
box.classList.add('python-editor-ui-dragging');
|
|
95
97
|
box.style.position = 'fixed';
|
|
96
|
-
|
|
98
|
+
floating.append(box);
|
|
97
99
|
frame = requestAnimationFrame(autoScroll);
|
|
98
100
|
};
|
|
99
101
|
|
package/src/lib/ui/registry.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import type { Component } from 'solid-js';
|
|
2
|
+
import type { CustomModule } from '~/lib/customModules';
|
|
3
|
+
import * as checkboxes from './components/checkboxes';
|
|
4
|
+
import * as latex from './components/latex';
|
|
5
|
+
import * as radio from './components/radio';
|
|
6
|
+
import * as slider from './components/slider';
|
|
7
|
+
import * as textbox from './components/textbox';
|
|
2
8
|
|
|
3
9
|
/** A UI: a Solid component. `args` holds the call's positional arguments; its keyword arguments are the other props. */
|
|
4
10
|
export type UiComponent = Component<any>;
|
|
5
11
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
12
|
+
const BUILTINS: CustomModule[] = [
|
|
13
|
+
{ file: 'src/lib/ui/components/checkboxes.tsx', exports: checkboxes },
|
|
14
|
+
{ file: 'src/lib/ui/components/latex.tsx', exports: latex },
|
|
15
|
+
{ file: 'src/lib/ui/components/radio.tsx', exports: radio },
|
|
16
|
+
{ file: 'src/lib/ui/components/slider.tsx', exports: slider },
|
|
17
|
+
{ file: 'src/lib/ui/components/textbox.tsx', exports: textbox },
|
|
18
|
+
];
|
|
9
19
|
|
|
10
20
|
const isComponent = (name: string, value: unknown): value is UiComponent =>
|
|
11
21
|
/^[A-Z][A-Za-z0-9]*$/.test(name) && typeof value === 'function';
|
|
@@ -13,21 +23,32 @@ const isComponent = (name: string, value: unknown): value is UiComponent =>
|
|
|
13
23
|
/** Its name in Python: `Slider` gives `pie.ui.slider`, `MatrixProduct` gives `pie.ui.matrix_product`. */
|
|
14
24
|
const pythonName = (exportName: string) => exportName.replace(/(?<!^)([A-Z])/g, '_$1').toLowerCase();
|
|
15
25
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
let components = new Map<string, UiComponent>();
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Replaces the custom UIs with the PascalCase exports of `modules`, e.g. a site's `ui/**\/*.{ts,tsx}`.
|
|
30
|
+
* Throws on a name used twice, leaving the UIs as they were.
|
|
31
|
+
*/
|
|
32
|
+
export function setCustomUis(modules: CustomModule[]) {
|
|
33
|
+
const uis = new Map<string, UiComponent>();
|
|
34
|
+
const sourceFile = new Map<string, string>();
|
|
35
|
+
for (const { file, exports } of [...BUILTINS, ...modules]) {
|
|
36
|
+
for (const [exportName, value] of Object.entries(exports)) {
|
|
37
|
+
if (!isComponent(exportName, value)) continue;
|
|
38
|
+
const name = pythonName(exportName);
|
|
39
|
+
const other = sourceFile.get(name);
|
|
40
|
+
if (other !== undefined) {
|
|
41
|
+
throw new Error(`Duplicate UI 'pie.ui.${name}': ${file} and ${other}`);
|
|
42
|
+
}
|
|
43
|
+
uis.set(name, value);
|
|
44
|
+
sourceFile.set(name, file);
|
|
25
45
|
}
|
|
26
|
-
components.set(name, value);
|
|
27
|
-
sourceFile.set(name, file);
|
|
28
46
|
}
|
|
47
|
+
components = uis;
|
|
29
48
|
}
|
|
30
49
|
|
|
50
|
+
setCustomUis([]);
|
|
51
|
+
|
|
31
52
|
export function getUi(name: string): UiComponent | undefined {
|
|
32
53
|
return components.get(name);
|
|
33
54
|
}
|