@particle-academy/fancy-3d 0.1.6 → 0.3.2
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 +64 -7
- package/dist/babylon.d.cts +1 -1
- package/dist/babylon.d.ts +1 -1
- package/dist/babylon.js +1 -2
- package/dist/babylon.js.map +1 -1
- package/dist/canvas/index.cjs +802 -0
- package/dist/canvas/index.cjs.map +1 -0
- package/dist/canvas/index.d.cts +205 -0
- package/dist/canvas/index.d.ts +205 -0
- package/dist/canvas/index.js +4 -0
- package/dist/canvas/index.js.map +1 -0
- package/dist/chunk-DGUM43GV.js +10 -0
- package/dist/chunk-DGUM43GV.js.map +1 -0
- package/dist/chunk-USH43TOO.js +791 -0
- package/dist/chunk-USH43TOO.js.map +1 -0
- package/dist/dom.d.cts +1 -1
- package/dist/dom.d.ts +1 -1
- package/dist/dom.js +1 -1
- package/dist/index.cjs +798 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -188
- package/dist/index.d.ts +4 -188
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +2 -2
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +3 -3
- package/dist/react.d.ts +3 -3
- package/dist/react.js +3 -3
- package/dist/react.js.map +1 -1
- package/dist/scene-ChcFkvmm.d.cts +188 -0
- package/dist/scene-ChcFkvmm.d.ts +188 -0
- package/docs/Canvas.md +154 -0
- package/package.json +11 -1
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Engine-agnostic scene description.
|
|
3
|
+
*
|
|
4
|
+
* A scene is plain JSON-serializable data. Adapters consume it to render the
|
|
5
|
+
* scene into a concrete engine — DOM, BabylonJS, three.js, native canvas, etc.
|
|
6
|
+
* The same `Scene` should produce a recognizably similar result on every
|
|
7
|
+
* supported engine.
|
|
8
|
+
*/
|
|
9
|
+
type WidgetSpec = KpiSpec | ChartSpec | KanbanSpec | TableSpec | ProfileSpec | CalloutSpec | FormSpec | ActionSpec | TimelineSpec | CodeSpec | ImageSpec | TextSpec | DemoPageSpec | ScreenSpec;
|
|
10
|
+
interface KpiSpec {
|
|
11
|
+
kind: "kpi";
|
|
12
|
+
label: string;
|
|
13
|
+
value: string;
|
|
14
|
+
delta?: string;
|
|
15
|
+
trend?: "up" | "down" | "flat";
|
|
16
|
+
}
|
|
17
|
+
interface ChartSpec {
|
|
18
|
+
kind: "chart";
|
|
19
|
+
title: string;
|
|
20
|
+
variant: "line" | "bar" | "area";
|
|
21
|
+
series: number[];
|
|
22
|
+
color?: string;
|
|
23
|
+
}
|
|
24
|
+
interface KanbanSpec {
|
|
25
|
+
kind: "kanban";
|
|
26
|
+
columns: {
|
|
27
|
+
title: string;
|
|
28
|
+
cards: string[];
|
|
29
|
+
}[];
|
|
30
|
+
}
|
|
31
|
+
interface TableSpec {
|
|
32
|
+
kind: "table";
|
|
33
|
+
title: string;
|
|
34
|
+
columns: string[];
|
|
35
|
+
rows: (string | number)[][];
|
|
36
|
+
}
|
|
37
|
+
interface ProfileSpec {
|
|
38
|
+
kind: "profile";
|
|
39
|
+
name: string;
|
|
40
|
+
role: string;
|
|
41
|
+
initials: string;
|
|
42
|
+
status?: "online" | "away" | "offline";
|
|
43
|
+
}
|
|
44
|
+
interface CalloutSpec {
|
|
45
|
+
kind: "callout";
|
|
46
|
+
tone: "info" | "success" | "warning" | "danger";
|
|
47
|
+
title: string;
|
|
48
|
+
body: string;
|
|
49
|
+
}
|
|
50
|
+
interface FormSpec {
|
|
51
|
+
kind: "form";
|
|
52
|
+
title: string;
|
|
53
|
+
fields: {
|
|
54
|
+
id: string;
|
|
55
|
+
label: string;
|
|
56
|
+
type: "text" | "switch" | "number";
|
|
57
|
+
}[];
|
|
58
|
+
}
|
|
59
|
+
interface ActionSpec {
|
|
60
|
+
kind: "action";
|
|
61
|
+
title: string;
|
|
62
|
+
buttons: {
|
|
63
|
+
label: string;
|
|
64
|
+
variant?: "primary" | "secondary" | "ghost";
|
|
65
|
+
}[];
|
|
66
|
+
}
|
|
67
|
+
interface TimelineSpec {
|
|
68
|
+
kind: "timeline";
|
|
69
|
+
title: string;
|
|
70
|
+
events: {
|
|
71
|
+
at: string;
|
|
72
|
+
label: string;
|
|
73
|
+
}[];
|
|
74
|
+
}
|
|
75
|
+
interface CodeSpec {
|
|
76
|
+
kind: "code";
|
|
77
|
+
title: string;
|
|
78
|
+
language: string;
|
|
79
|
+
code: string;
|
|
80
|
+
}
|
|
81
|
+
interface ImageSpec {
|
|
82
|
+
kind: "image";
|
|
83
|
+
src: string;
|
|
84
|
+
alt: string;
|
|
85
|
+
caption?: string;
|
|
86
|
+
}
|
|
87
|
+
interface TextSpec {
|
|
88
|
+
kind: "text";
|
|
89
|
+
heading: string;
|
|
90
|
+
body: string;
|
|
91
|
+
}
|
|
92
|
+
interface DemoPageSpec {
|
|
93
|
+
kind: "demoPage";
|
|
94
|
+
name: string;
|
|
95
|
+
description: string;
|
|
96
|
+
path: string;
|
|
97
|
+
accent: string;
|
|
98
|
+
category: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* A 3D-native widget — a screen-shaped panel with a bezel frame, status LED,
|
|
102
|
+
* and optional 2D content drawn into the screen surface. Designed to feel
|
|
103
|
+
* like a hardware display in a 3D scene.
|
|
104
|
+
*/
|
|
105
|
+
interface ScreenSpec {
|
|
106
|
+
kind: "screen";
|
|
107
|
+
/** Screen contents — either a static label or a paint callback that draws
|
|
108
|
+
* onto a 2D context sized to the screen's inner area. */
|
|
109
|
+
content: {
|
|
110
|
+
type: "label";
|
|
111
|
+
title: string;
|
|
112
|
+
subtitle?: string;
|
|
113
|
+
} | {
|
|
114
|
+
type: "image";
|
|
115
|
+
src: string;
|
|
116
|
+
alt?: string;
|
|
117
|
+
} | {
|
|
118
|
+
type: "paint";
|
|
119
|
+
paint: (ctx: CanvasRenderingContext2D, w: number, h: number) => void;
|
|
120
|
+
};
|
|
121
|
+
/** Bezel color (CSS hex). Defaults to a dark frame. */
|
|
122
|
+
bezel?: string;
|
|
123
|
+
/** Bezel thickness in pixels, scaled with the screen's pixel size. */
|
|
124
|
+
bezelThickness?: number;
|
|
125
|
+
/** Power state — controls the LED + screen brightness. */
|
|
126
|
+
on?: boolean;
|
|
127
|
+
/** Background fill color when the content does not fill the screen. */
|
|
128
|
+
background?: string;
|
|
129
|
+
/** Brightness multiplier, 0..1. Defaults to 1 when on, 0.05 when off. */
|
|
130
|
+
brightness?: number;
|
|
131
|
+
}
|
|
132
|
+
interface SceneNode {
|
|
133
|
+
id: string;
|
|
134
|
+
position: {
|
|
135
|
+
x: number;
|
|
136
|
+
y: number;
|
|
137
|
+
z?: number;
|
|
138
|
+
};
|
|
139
|
+
size?: {
|
|
140
|
+
w: number;
|
|
141
|
+
h: number;
|
|
142
|
+
};
|
|
143
|
+
widget: WidgetSpec;
|
|
144
|
+
}
|
|
145
|
+
interface SceneEdge {
|
|
146
|
+
id: string;
|
|
147
|
+
from: string;
|
|
148
|
+
to: string;
|
|
149
|
+
label?: string;
|
|
150
|
+
curve?: "bezier" | "step" | "straight";
|
|
151
|
+
animated?: boolean;
|
|
152
|
+
}
|
|
153
|
+
interface Scene {
|
|
154
|
+
nodes: SceneNode[];
|
|
155
|
+
edges: SceneEdge[];
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* A WidgetAdapter renders one WidgetSpec for one engine. Each engine ships
|
|
159
|
+
* its own adapter; the scene data does not change.
|
|
160
|
+
*
|
|
161
|
+
* The DOM adapter returns a React element. A BabylonJS adapter returns a
|
|
162
|
+
* `Mesh`. A three.js adapter would return an `Object3D`.
|
|
163
|
+
*/
|
|
164
|
+
interface WidgetAdapter<T> {
|
|
165
|
+
render(spec: WidgetSpec, ctx: AdapterContext): T;
|
|
166
|
+
}
|
|
167
|
+
interface AdapterContext {
|
|
168
|
+
/** Notify the host when the widget requests selection. */
|
|
169
|
+
onSelect?: (id: string) => void;
|
|
170
|
+
/** The id of the node this widget belongs to. */
|
|
171
|
+
nodeId: string;
|
|
172
|
+
/** Whether the node is currently selected — adapters may render an outline. */
|
|
173
|
+
selected: boolean;
|
|
174
|
+
}
|
|
175
|
+
declare function nextId(prefix: string): string;
|
|
176
|
+
/**
|
|
177
|
+
* Convenience: walk a Scene and call the adapter on every node.
|
|
178
|
+
*
|
|
179
|
+
* Engine-agnostic — every adapter (DOM, Babylon, three) can share it. The
|
|
180
|
+
* host is responsible for placing the returned render results inside its
|
|
181
|
+
* scene graph.
|
|
182
|
+
*/
|
|
183
|
+
declare function renderScene<T>(scene: Scene, adapter: WidgetAdapter<T>, ctxFor: (node: SceneNode) => AdapterContext): {
|
|
184
|
+
node: SceneNode;
|
|
185
|
+
rendered: T;
|
|
186
|
+
}[];
|
|
187
|
+
|
|
188
|
+
export { type ActionSpec as A, type CalloutSpec as C, type DemoPageSpec as D, type FormSpec as F, type ImageSpec as I, type KanbanSpec as K, type ProfileSpec as P, type Scene as S, type TableSpec as T, type WidgetAdapter as W, type AdapterContext as a, type ChartSpec as b, type CodeSpec as c, type KpiSpec as d, type SceneEdge as e, type SceneNode as f, type ScreenSpec as g, type TextSpec as h, type TimelineSpec as i, type WidgetSpec as j, nextId as n, renderScene as r };
|
package/docs/Canvas.md
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# Canvas
|
|
2
|
+
|
|
3
|
+
An infinite pannable and zoomable surface for positioning nodes with edges between them. Engine-pluggable: defaults to a pure DOM/CSS3D rendering (zero-overhead Web3D), but can mount a Babylon `Scene` (`engine="babylon"`) or any custom engine implementing the `CanvasEngine` interface. Includes minimap, zoom controls, optional grid, and an obstacle-aware edge renderer.
|
|
4
|
+
|
|
5
|
+
## Import
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { Canvas, useCanvas } from "@particle-academy/fancy-3d/canvas";
|
|
9
|
+
// (or from the package root — both work, subpath is tree-shake friendly)
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Engines
|
|
13
|
+
|
|
14
|
+
`<Canvas>` accepts an `engine` prop that selects the 3D backend mounted alongside the 2D canvas:
|
|
15
|
+
|
|
16
|
+
| Spec | Effect |
|
|
17
|
+
|------|--------|
|
|
18
|
+
| `"dom"` (default) | No extra runtime — plain DOM/CSS3D. Zero-cost for 2D-only use. |
|
|
19
|
+
| `"babylon"` | Mounts a Babylon `Engine` + `Scene` + `ArcRotateCamera` over the canvas. The live `BABYLON.Scene` is exposed via `useCanvas().engine.root` so children can register meshes. Requires `@babylonjs/core` peer dep. |
|
|
20
|
+
| `CanvasEngine` (custom) | Any object implementing `{ name, mount(host, viewport): EngineHandle }`. Use this to plug in three.js, native canvas, WebXR, or future spatial runtimes. |
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
<Canvas engine="dom"> ... </Canvas> // default — 2D only
|
|
24
|
+
<Canvas engine="babylon"> ... </Canvas> // 3D scene mounted alongside
|
|
25
|
+
<Canvas engine={myThreeEngine}> ... </Canvas> // custom engine
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The `CanvasEngine` interface:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
interface CanvasEngine {
|
|
32
|
+
name: string;
|
|
33
|
+
mount(host: HTMLElement, viewport: ViewportState): EngineHandle;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface EngineHandle {
|
|
37
|
+
name: string;
|
|
38
|
+
root: unknown; // engine-specific (e.g. BABYLON.Scene)
|
|
39
|
+
updateViewport(viewport: ViewportState): void;
|
|
40
|
+
dispose(): void;
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Adapter components that target a specific engine should narrow on `name`:
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
const { engine } = useCanvas();
|
|
48
|
+
if (engine?.name === "babylon") {
|
|
49
|
+
const scene = engine.root as BABYLON.Scene;
|
|
50
|
+
// attach meshes to `scene` here
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Roadmap to MR
|
|
55
|
+
|
|
56
|
+
- **0.3** — texture-mode rendering: project the 2D Canvas surface onto a Babylon plane via `DynamicTexture`, so the same node graph appears as both a flat overlay and a placed-in-space surface.
|
|
57
|
+
- **0.4** — depth-aware overlays: per-node `z` projection so 2D widgets sit at the right depth relative to 3D meshes.
|
|
58
|
+
- **0.5** — hand-tracking event mapping + WebXR engine adapter: pinch/grab gestures route to existing `<Canvas.Node>` drag handlers; full WebXR session driven from inside `<Canvas>`.
|
|
59
|
+
|
|
60
|
+
## Basic Usage
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
<Canvas className="h-96 w-full" showGrid>
|
|
64
|
+
<Canvas.Node id="a" x={50} y={50} draggable>
|
|
65
|
+
<div className="rounded border bg-white p-4">Node A</div>
|
|
66
|
+
</Canvas.Node>
|
|
67
|
+
<Canvas.Node id="b" x={300} y={150} draggable>
|
|
68
|
+
<div className="rounded border bg-white p-4">Node B</div>
|
|
69
|
+
</Canvas.Node>
|
|
70
|
+
<Canvas.Edge from="a" to="b" curve="bezier" markerEnd="canvas-arrow" />
|
|
71
|
+
<Canvas.Controls />
|
|
72
|
+
<Canvas.Minimap />
|
|
73
|
+
</Canvas>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Props
|
|
77
|
+
|
|
78
|
+
### Canvas (root)
|
|
79
|
+
|
|
80
|
+
| Prop | Type | Default | Description |
|
|
81
|
+
|------|------|---------|-------------|
|
|
82
|
+
| viewport | `ViewportState` | - | Controlled viewport `{ panX, panY, zoom }` |
|
|
83
|
+
| defaultViewport | `ViewportState` | `{ panX: 0, panY: 0, zoom: 1 }` | Default viewport (uncontrolled) |
|
|
84
|
+
| onViewportChange | `(viewport: ViewportState) => void` | - | Callback when viewport changes |
|
|
85
|
+
| minZoom | `number` | `0.1` | Minimum zoom level |
|
|
86
|
+
| maxZoom | `number` | `3` | Maximum zoom level |
|
|
87
|
+
| pannable | `boolean` | `true` | Enable panning (click+drag on background) |
|
|
88
|
+
| zoomable | `boolean` | `true` | Enable zoom (Ctrl+scroll) |
|
|
89
|
+
| gridSize | `number` | `20` | Grid cell size in canvas-space pixels |
|
|
90
|
+
| showGrid | `boolean` | `false` | Display the canvas grid background |
|
|
91
|
+
| gridStyle | `'dots' \| 'lines' \| 'none'` | `'dots'` | Grid pattern when shown. `'none'` hides the grid even when `showGrid` is true |
|
|
92
|
+
| gridColor | `string` | `'rgb(161 161 170 / 0.3)'` | Any CSS color for grid dots/lines |
|
|
93
|
+
| snapToGrid | `boolean` | `false` | Snap dragged nodes to the grid |
|
|
94
|
+
| fitOnMount | `boolean` | `false` | Auto-fit all nodes into view on mount |
|
|
95
|
+
| className | `string` | - | Additional CSS classes |
|
|
96
|
+
| style | `CSSProperties` | - | Inline styles |
|
|
97
|
+
|
|
98
|
+
### Canvas.Node
|
|
99
|
+
|
|
100
|
+
| Prop | Type | Default | Description |
|
|
101
|
+
|------|------|---------|-------------|
|
|
102
|
+
| id | `string` | - | Unique node identifier (required) |
|
|
103
|
+
| x | `number` | - | X position in canvas coordinates (required) |
|
|
104
|
+
| y | `number` | - | Y position in canvas coordinates (required) |
|
|
105
|
+
| draggable | `boolean` | - | Allow drag-to-move |
|
|
106
|
+
| onPositionChange | `(x: number, y: number) => void` | - | Callback when dragged to a new position |
|
|
107
|
+
| className | `string` | - | Additional CSS classes |
|
|
108
|
+
| style | `CSSProperties` | - | Inline styles |
|
|
109
|
+
|
|
110
|
+
### Canvas.Edge
|
|
111
|
+
|
|
112
|
+
| Prop | Type | Default | Description |
|
|
113
|
+
|------|------|---------|-------------|
|
|
114
|
+
| from | `string` | - | Source node id (required) |
|
|
115
|
+
| to | `string` | - | Target node id (required) |
|
|
116
|
+
| fromAnchor | `EdgeAnchor` | - | Anchor point on source: `"top"`, `"bottom"`, `"left"`, `"right"`, `"center"`, `"auto"` |
|
|
117
|
+
| toAnchor | `EdgeAnchor` | - | Anchor point on target |
|
|
118
|
+
| curve | `"bezier" \| "step" \| "straight"` | - | Path interpolation |
|
|
119
|
+
| color | `string` | - | Stroke color |
|
|
120
|
+
| strokeWidth | `number` | - | Stroke width |
|
|
121
|
+
| dashed | `boolean` | - | Dashed line |
|
|
122
|
+
| animated | `boolean` | - | Animated dash pattern |
|
|
123
|
+
| label | `ReactNode` | - | Label at the midpoint |
|
|
124
|
+
| markerStart | `string` | - | SVG marker id for start (e.g. `"canvas-arrow"`, `"canvas-circle"`, `"canvas-diamond"`) |
|
|
125
|
+
| markerEnd | `string` | - | SVG marker id for end |
|
|
126
|
+
| className | `string` | - | Additional CSS classes |
|
|
127
|
+
|
|
128
|
+
### Canvas.Controls
|
|
129
|
+
|
|
130
|
+
| Prop | Type | Default | Description |
|
|
131
|
+
|------|------|---------|-------------|
|
|
132
|
+
| showZoomIn | `boolean` | - | Show zoom-in button |
|
|
133
|
+
| showZoomOut | `boolean` | - | Show zoom-out button |
|
|
134
|
+
| showReset | `boolean` | - | Show reset-viewport button |
|
|
135
|
+
| showFitAll | `boolean` | - | Show fit-all button |
|
|
136
|
+
| className | `string` | - | Additional CSS classes |
|
|
137
|
+
|
|
138
|
+
### Canvas.Minimap
|
|
139
|
+
|
|
140
|
+
| Prop | Type | Default | Description |
|
|
141
|
+
|------|------|---------|-------------|
|
|
142
|
+
| width | `number` | - | Minimap width in px |
|
|
143
|
+
| height | `number` | - | Minimap height in px |
|
|
144
|
+
| className | `string` | - | Additional CSS classes |
|
|
145
|
+
|
|
146
|
+
### ViewportState
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
{ panX: number; panY: number; zoom: number }
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Built-in SVG Markers
|
|
153
|
+
|
|
154
|
+
The Canvas includes predefined SVG markers for edge endpoints: `"canvas-arrow"`, `"canvas-circle"`, `"canvas-diamond"`, `"canvas-one"`, `"canvas-crow-foot"`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@particle-academy/fancy-3d",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Bring Particle Academy's fancy components into 3D — engine-agnostic scene types, a BabylonJS adapter, and 3D-native components like Screen.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -52,6 +52,16 @@
|
|
|
52
52
|
"types": "./dist/react.d.cts",
|
|
53
53
|
"default": "./dist/react.cjs"
|
|
54
54
|
}
|
|
55
|
+
},
|
|
56
|
+
"./canvas": {
|
|
57
|
+
"import": {
|
|
58
|
+
"types": "./dist/canvas/index.d.ts",
|
|
59
|
+
"default": "./dist/canvas/index.js"
|
|
60
|
+
},
|
|
61
|
+
"require": {
|
|
62
|
+
"types": "./dist/canvas/index.d.cts",
|
|
63
|
+
"default": "./dist/canvas/index.cjs"
|
|
64
|
+
}
|
|
55
65
|
}
|
|
56
66
|
},
|
|
57
67
|
"files": [
|