@particle-academy/fancy-3d 0.5.0 → 0.6.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/dist/index.d.cts CHANGED
@@ -1,4 +1,197 @@
1
- export { A as ActionSpec, a as AdapterContext, C as CalloutSpec, b as ChartSpec, c as CodeSpec, D as DemoPageSpec, F as FormSpec, I as ImageSpec, K as KanbanSpec, d as KpiSpec, P as ProfileSpec, S as Scene, e as SceneEdge, f as SceneNode, g as ScreenSpec, T as TableSpec, h as TextSpec, i as TimelineSpec, W as WidgetAdapter, j as WidgetSpec, n as nextId, r as renderScene } from './scene-ChcFkvmm.cjs';
1
+ import { S as Scene, a as SceneNode, b as WidgetSpec } from './scene-C_ISwOAL.cjs';
2
+ export { A as ActionSpec, c as AdapterContext, C as CalloutSpec, d as ChartSpec, e as CodeSpec, D as DemoPageSpec, F as FormSpec, I as ImageSpec, K as KanbanSpec, f as KpiSpec, P as ProfileSpec, g as SceneEdge, h as ScreenSpec, T as TableSpec, i as TextSpec, j as TimelineSpec, W as WidgetAdapter, n as nextId, r as renderScene } from './scene-C_ISwOAL.cjs';
2
3
  export { Canvas, CanvasContextValue, CanvasControlsProps, CanvasEdgeProps, CanvasEngine, CanvasEngineSpec, CanvasMinimapProps, CanvasNodeProps, CanvasProps, EdgeAnchor, EngineHandle, GridStyle, ViewportState, domEngine, useCanvas } from './canvas/index.cjs';
3
- import 'react/jsx-runtime';
4
4
  import 'react';
5
+
6
+ /**
7
+ * Unit scale, layout and camera framing — defined ONCE, here, for every renderer.
8
+ *
9
+ * A `Scene` is laid out in CSS pixels: `position` is a node's top-left corner
10
+ * and `size` its box, with y growing downward, exactly as the DOM renderer
11
+ * places it. A WebGL renderer needs world units, a y-up axis and a camera. If
12
+ * each adapter (or each app) picks those for itself, the same Scene comes out
13
+ * at a different size, spacing and angle on every engine. These functions are
14
+ * the one conversion, and the camera they produce shows the scene at the same
15
+ * on-screen scale the DOM `<Canvas fitOnMount>` would.
16
+ *
17
+ * World convention (right-handed, as three.js): x to the viewer's right, y up,
18
+ * z toward the viewer; the scene is centred on the origin and faces +z. An
19
+ * adapter for a left-handed engine (Babylon.js) converts at its own boundary.
20
+ */
21
+
22
+ /** CSS pixels of a Scene per world unit. The one unit scale for every engine. */
23
+ declare const PX_PER_UNIT = 100;
24
+ /** The box a node takes when its `size` is not given. */
25
+ declare const DEFAULT_NODE_SIZE: Readonly<{
26
+ w: number;
27
+ h: number;
28
+ }>;
29
+ /** Space kept around the scene when it is fitted into a viewport, in scene px. */
30
+ declare const FIT_PADDING = 40;
31
+ /** A fitted scene is never magnified past this. */
32
+ declare const FIT_MAX_ZOOM = 1.5;
33
+ interface SceneBounds {
34
+ minX: number;
35
+ minY: number;
36
+ maxX: number;
37
+ maxY: number;
38
+ }
39
+ /** A node's box, in scene px. */
40
+ declare function nodeSize(node: SceneNode): {
41
+ w: number;
42
+ h: number;
43
+ };
44
+ /** The box around every node, in scene px; `null` for an empty scene. */
45
+ declare function sceneBounds(scene: Scene): SceneBounds | null;
46
+ /**
47
+ * The zoom that fits `bounds` into a `width` x `height` viewport: what the DOM
48
+ * `<Canvas fitOnMount>` applies, and what `frameScene` reproduces in 3D.
49
+ */
50
+ declare function fitZoom(bounds: SceneBounds, width: number, height: number): number;
51
+ /** Where one node sits in the world, in world units (see the module note for axes). */
52
+ interface WorldPlacement {
53
+ id: string;
54
+ /** Centre of the node. */
55
+ x: number;
56
+ y: number;
57
+ z: number;
58
+ width: number;
59
+ height: number;
60
+ /** The node's box in scene px — the size to paint or mount its widget at. */
61
+ pixelWidth: number;
62
+ pixelHeight: number;
63
+ }
64
+ /**
65
+ * Every node's world placement: centred on the origin, y flipped to point up,
66
+ * `PX_PER_UNIT` scene px per unit. `position.z` (scene px) moves a node toward
67
+ * the viewer.
68
+ */
69
+ declare function sceneToWorld(scene: Scene, pxPerUnit?: number): WorldPlacement[];
70
+ interface SceneFrameOptions {
71
+ /** Viewport size in CSS px. */
72
+ width: number;
73
+ height: number;
74
+ /** The camera's VERTICAL field of view, in radians. */
75
+ fovY: number;
76
+ /** Scene px per world unit. Defaults to `PX_PER_UNIT`. */
77
+ pxPerUnit?: number;
78
+ }
79
+ /** A front-on camera for a scene, in the world convention above. */
80
+ interface SceneFrame {
81
+ /** The point the camera looks at: the scene's centre, the origin. */
82
+ target: [number, number, number];
83
+ /** Distance from the target along +z. */
84
+ distance: number;
85
+ /** Polar angle from +y: always pi/2, level with the scene, never tilted. */
86
+ beta: number;
87
+ /** The fitted zoom: screen px per scene px at the target plane. */
88
+ zoom: number;
89
+ }
90
+ /**
91
+ * The camera that shows `scene` exactly as the DOM `<Canvas fitOnMount>` shows
92
+ * it: level and front-on, at the distance where one scene px covers `zoom`
93
+ * screen px on the plane the cards sit in.
94
+ */
95
+ declare function frameScene(scene: Scene, opts: SceneFrameOptions): SceneFrame;
96
+
97
+ /**
98
+ * The scene theme — defined ONCE, here, for every renderer.
99
+ *
100
+ * The DOM renderer draws a widget with react-fancy, which is light by default
101
+ * and dark under a `.dark` / `[data-theme="dark"]` ancestor. A WebGL renderer
102
+ * paints the same widget onto a texture, so it has no stylesheet to inherit
103
+ * from: it needs the colours spelled out. These palettes are those colours,
104
+ * taken from the react-fancy defaults the DOM renderer shows (zinc surfaces,
105
+ * white / zinc-900 cards), and `resolveSceneTheme` reads the mode the same way
106
+ * react-fancy's `dark` variant does. An adapter that invents its own colours
107
+ * renders a different scene, which is the bug this module exists to prevent.
108
+ */
109
+ type SceneTheme = "light" | "dark";
110
+ /** Every colour a painted widget or a WebGL stage needs, for one theme. */
111
+ interface ScenePalette {
112
+ /** The surface behind the scene (the canvas / clear colour). */
113
+ canvas: string;
114
+ /** Dot-grid colour on the canvas, as the DOM `<Canvas>` draws it. */
115
+ grid: string;
116
+ /** Card face. */
117
+ card: string;
118
+ /** Card outline. */
119
+ cardBorder: string;
120
+ /** Extruded card sides and back. */
121
+ edge: string;
122
+ /** Primary text (values, names, headings). */
123
+ text: string;
124
+ /** Body text. */
125
+ body: string;
126
+ /** Labels, captions, secondary text. */
127
+ muted: string;
128
+ /** Inset panels inside a card (kanban columns, inputs). */
129
+ subtle: string;
130
+ /** Accent (selection ring, primary button, default chart colour). */
131
+ accent: string;
132
+ /** Text on the accent colour. */
133
+ onAccent: string;
134
+ /** Avatar fallback disc. */
135
+ avatar: string;
136
+ /** Avatar initials. */
137
+ avatarText: string;
138
+ success: string;
139
+ warning: string;
140
+ danger: string;
141
+ info: string;
142
+ /** Code block background and text. */
143
+ code: string;
144
+ codeText: string;
145
+ }
146
+ declare const SCENE_PALETTES: Record<SceneTheme, ScenePalette>;
147
+ /** The selector react-fancy's `dark` variant matches (`.dark` or `[data-theme="dark"]`). */
148
+ declare const DARK_THEME_SELECTOR = ".dark, [data-theme=\"dark\"]";
149
+ /**
150
+ * The theme a scene renders in. An explicit theme wins; otherwise the mode is
151
+ * read exactly as the DOM renderer's react-fancy cards read it — a `.dark` or
152
+ * `[data-theme="dark"]` on `el` or any ancestor (the document root when no
153
+ * element is given) — and is light when there is no document.
154
+ */
155
+ declare function resolveSceneTheme(theme?: SceneTheme | "auto", el?: Element | null): SceneTheme;
156
+ /** The palette for a theme (resolving `"auto"` / undefined as `resolveSceneTheme` does). */
157
+ declare function scenePalette(theme?: SceneTheme | "auto", el?: Element | null): ScenePalette;
158
+
159
+ /**
160
+ * Canvas-2D painters for every `WidgetSpec` — the texture a WebGL renderer puts
161
+ * on a card. Engine-free (a `CanvasRenderingContext2D` is all it touches), so it
162
+ * lives in the core and every adapter paints the SAME card. It used to be copied
163
+ * into each adapter with its own hard-coded dark colours and its own fixed pixel
164
+ * sizes, so a scene the DOM drew light came out dark, with text twice the size.
165
+ *
166
+ * Metrics are the DOM renderer's, in scene px: paint at a node's `size` and the
167
+ * card matches the react-fancy card the DOM renderer draws for it (16px padding,
168
+ * 12px uppercase labels, 24px KPI value, 40px avatar). Colours come from the
169
+ * scene palette (`theme.ts`). Painting at a larger pixel size scales the whole
170
+ * card, so text stays in proportion at any texture resolution.
171
+ */
172
+
173
+ interface PaintWidgetOptions {
174
+ /** Theme or explicit palette. Default: the document's mode, as the DOM renderer reads it. */
175
+ theme?: SceneTheme | "auto" | ScenePalette;
176
+ selected?: boolean;
177
+ /**
178
+ * The node's box in scene px. The card is drawn at these metrics and scaled
179
+ * to fill `w` x `h`, so a texture painted at 2x its node size is simply
180
+ * sharper, never laid out differently. Defaults to the target's height
181
+ * matched to `DEFAULT_NODE_SIZE.h` when not given and the target is not a node.
182
+ */
183
+ scenePx?: {
184
+ w: number;
185
+ h: number;
186
+ };
187
+ }
188
+ /**
189
+ * Paint `spec` as a card filling `w` x `h` px of `ctx`. The card is laid out at
190
+ * `opts.scenePx` (the node's own size) and scaled to the target, so it reads
191
+ * the same as the DOM card at any texture resolution. Without `scenePx`, a
192
+ * target at or above the default node height is treated as 1:1 scene px, and a
193
+ * smaller one is laid out at that height and scaled down.
194
+ */
195
+ declare function paintWidget(ctx: CanvasRenderingContext2D, spec: WidgetSpec, w: number, h: number, opts?: PaintWidgetOptions): void;
196
+
197
+ export { DARK_THEME_SELECTOR, DEFAULT_NODE_SIZE, FIT_MAX_ZOOM, FIT_PADDING, PX_PER_UNIT, type PaintWidgetOptions, SCENE_PALETTES, Scene, type SceneBounds, type SceneFrame, type SceneFrameOptions, SceneNode, type ScenePalette, type SceneTheme, WidgetSpec, type WorldPlacement, fitZoom, frameScene, nodeSize, paintWidget, resolveSceneTheme, sceneBounds, scenePalette, sceneToWorld };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,197 @@
1
- export { A as ActionSpec, a as AdapterContext, C as CalloutSpec, b as ChartSpec, c as CodeSpec, D as DemoPageSpec, F as FormSpec, I as ImageSpec, K as KanbanSpec, d as KpiSpec, P as ProfileSpec, S as Scene, e as SceneEdge, f as SceneNode, g as ScreenSpec, T as TableSpec, h as TextSpec, i as TimelineSpec, W as WidgetAdapter, j as WidgetSpec, n as nextId, r as renderScene } from './scene-ChcFkvmm.js';
1
+ import { S as Scene, a as SceneNode, b as WidgetSpec } from './scene-C_ISwOAL.js';
2
+ export { A as ActionSpec, c as AdapterContext, C as CalloutSpec, d as ChartSpec, e as CodeSpec, D as DemoPageSpec, F as FormSpec, I as ImageSpec, K as KanbanSpec, f as KpiSpec, P as ProfileSpec, g as SceneEdge, h as ScreenSpec, T as TableSpec, i as TextSpec, j as TimelineSpec, W as WidgetAdapter, n as nextId, r as renderScene } from './scene-C_ISwOAL.js';
2
3
  export { Canvas, CanvasContextValue, CanvasControlsProps, CanvasEdgeProps, CanvasEngine, CanvasEngineSpec, CanvasMinimapProps, CanvasNodeProps, CanvasProps, EdgeAnchor, EngineHandle, GridStyle, ViewportState, domEngine, useCanvas } from './canvas/index.js';
3
- import 'react/jsx-runtime';
4
4
  import 'react';
5
+
6
+ /**
7
+ * Unit scale, layout and camera framing — defined ONCE, here, for every renderer.
8
+ *
9
+ * A `Scene` is laid out in CSS pixels: `position` is a node's top-left corner
10
+ * and `size` its box, with y growing downward, exactly as the DOM renderer
11
+ * places it. A WebGL renderer needs world units, a y-up axis and a camera. If
12
+ * each adapter (or each app) picks those for itself, the same Scene comes out
13
+ * at a different size, spacing and angle on every engine. These functions are
14
+ * the one conversion, and the camera they produce shows the scene at the same
15
+ * on-screen scale the DOM `<Canvas fitOnMount>` would.
16
+ *
17
+ * World convention (right-handed, as three.js): x to the viewer's right, y up,
18
+ * z toward the viewer; the scene is centred on the origin and faces +z. An
19
+ * adapter for a left-handed engine (Babylon.js) converts at its own boundary.
20
+ */
21
+
22
+ /** CSS pixels of a Scene per world unit. The one unit scale for every engine. */
23
+ declare const PX_PER_UNIT = 100;
24
+ /** The box a node takes when its `size` is not given. */
25
+ declare const DEFAULT_NODE_SIZE: Readonly<{
26
+ w: number;
27
+ h: number;
28
+ }>;
29
+ /** Space kept around the scene when it is fitted into a viewport, in scene px. */
30
+ declare const FIT_PADDING = 40;
31
+ /** A fitted scene is never magnified past this. */
32
+ declare const FIT_MAX_ZOOM = 1.5;
33
+ interface SceneBounds {
34
+ minX: number;
35
+ minY: number;
36
+ maxX: number;
37
+ maxY: number;
38
+ }
39
+ /** A node's box, in scene px. */
40
+ declare function nodeSize(node: SceneNode): {
41
+ w: number;
42
+ h: number;
43
+ };
44
+ /** The box around every node, in scene px; `null` for an empty scene. */
45
+ declare function sceneBounds(scene: Scene): SceneBounds | null;
46
+ /**
47
+ * The zoom that fits `bounds` into a `width` x `height` viewport: what the DOM
48
+ * `<Canvas fitOnMount>` applies, and what `frameScene` reproduces in 3D.
49
+ */
50
+ declare function fitZoom(bounds: SceneBounds, width: number, height: number): number;
51
+ /** Where one node sits in the world, in world units (see the module note for axes). */
52
+ interface WorldPlacement {
53
+ id: string;
54
+ /** Centre of the node. */
55
+ x: number;
56
+ y: number;
57
+ z: number;
58
+ width: number;
59
+ height: number;
60
+ /** The node's box in scene px — the size to paint or mount its widget at. */
61
+ pixelWidth: number;
62
+ pixelHeight: number;
63
+ }
64
+ /**
65
+ * Every node's world placement: centred on the origin, y flipped to point up,
66
+ * `PX_PER_UNIT` scene px per unit. `position.z` (scene px) moves a node toward
67
+ * the viewer.
68
+ */
69
+ declare function sceneToWorld(scene: Scene, pxPerUnit?: number): WorldPlacement[];
70
+ interface SceneFrameOptions {
71
+ /** Viewport size in CSS px. */
72
+ width: number;
73
+ height: number;
74
+ /** The camera's VERTICAL field of view, in radians. */
75
+ fovY: number;
76
+ /** Scene px per world unit. Defaults to `PX_PER_UNIT`. */
77
+ pxPerUnit?: number;
78
+ }
79
+ /** A front-on camera for a scene, in the world convention above. */
80
+ interface SceneFrame {
81
+ /** The point the camera looks at: the scene's centre, the origin. */
82
+ target: [number, number, number];
83
+ /** Distance from the target along +z. */
84
+ distance: number;
85
+ /** Polar angle from +y: always pi/2, level with the scene, never tilted. */
86
+ beta: number;
87
+ /** The fitted zoom: screen px per scene px at the target plane. */
88
+ zoom: number;
89
+ }
90
+ /**
91
+ * The camera that shows `scene` exactly as the DOM `<Canvas fitOnMount>` shows
92
+ * it: level and front-on, at the distance where one scene px covers `zoom`
93
+ * screen px on the plane the cards sit in.
94
+ */
95
+ declare function frameScene(scene: Scene, opts: SceneFrameOptions): SceneFrame;
96
+
97
+ /**
98
+ * The scene theme — defined ONCE, here, for every renderer.
99
+ *
100
+ * The DOM renderer draws a widget with react-fancy, which is light by default
101
+ * and dark under a `.dark` / `[data-theme="dark"]` ancestor. A WebGL renderer
102
+ * paints the same widget onto a texture, so it has no stylesheet to inherit
103
+ * from: it needs the colours spelled out. These palettes are those colours,
104
+ * taken from the react-fancy defaults the DOM renderer shows (zinc surfaces,
105
+ * white / zinc-900 cards), and `resolveSceneTheme` reads the mode the same way
106
+ * react-fancy's `dark` variant does. An adapter that invents its own colours
107
+ * renders a different scene, which is the bug this module exists to prevent.
108
+ */
109
+ type SceneTheme = "light" | "dark";
110
+ /** Every colour a painted widget or a WebGL stage needs, for one theme. */
111
+ interface ScenePalette {
112
+ /** The surface behind the scene (the canvas / clear colour). */
113
+ canvas: string;
114
+ /** Dot-grid colour on the canvas, as the DOM `<Canvas>` draws it. */
115
+ grid: string;
116
+ /** Card face. */
117
+ card: string;
118
+ /** Card outline. */
119
+ cardBorder: string;
120
+ /** Extruded card sides and back. */
121
+ edge: string;
122
+ /** Primary text (values, names, headings). */
123
+ text: string;
124
+ /** Body text. */
125
+ body: string;
126
+ /** Labels, captions, secondary text. */
127
+ muted: string;
128
+ /** Inset panels inside a card (kanban columns, inputs). */
129
+ subtle: string;
130
+ /** Accent (selection ring, primary button, default chart colour). */
131
+ accent: string;
132
+ /** Text on the accent colour. */
133
+ onAccent: string;
134
+ /** Avatar fallback disc. */
135
+ avatar: string;
136
+ /** Avatar initials. */
137
+ avatarText: string;
138
+ success: string;
139
+ warning: string;
140
+ danger: string;
141
+ info: string;
142
+ /** Code block background and text. */
143
+ code: string;
144
+ codeText: string;
145
+ }
146
+ declare const SCENE_PALETTES: Record<SceneTheme, ScenePalette>;
147
+ /** The selector react-fancy's `dark` variant matches (`.dark` or `[data-theme="dark"]`). */
148
+ declare const DARK_THEME_SELECTOR = ".dark, [data-theme=\"dark\"]";
149
+ /**
150
+ * The theme a scene renders in. An explicit theme wins; otherwise the mode is
151
+ * read exactly as the DOM renderer's react-fancy cards read it — a `.dark` or
152
+ * `[data-theme="dark"]` on `el` or any ancestor (the document root when no
153
+ * element is given) — and is light when there is no document.
154
+ */
155
+ declare function resolveSceneTheme(theme?: SceneTheme | "auto", el?: Element | null): SceneTheme;
156
+ /** The palette for a theme (resolving `"auto"` / undefined as `resolveSceneTheme` does). */
157
+ declare function scenePalette(theme?: SceneTheme | "auto", el?: Element | null): ScenePalette;
158
+
159
+ /**
160
+ * Canvas-2D painters for every `WidgetSpec` — the texture a WebGL renderer puts
161
+ * on a card. Engine-free (a `CanvasRenderingContext2D` is all it touches), so it
162
+ * lives in the core and every adapter paints the SAME card. It used to be copied
163
+ * into each adapter with its own hard-coded dark colours and its own fixed pixel
164
+ * sizes, so a scene the DOM drew light came out dark, with text twice the size.
165
+ *
166
+ * Metrics are the DOM renderer's, in scene px: paint at a node's `size` and the
167
+ * card matches the react-fancy card the DOM renderer draws for it (16px padding,
168
+ * 12px uppercase labels, 24px KPI value, 40px avatar). Colours come from the
169
+ * scene palette (`theme.ts`). Painting at a larger pixel size scales the whole
170
+ * card, so text stays in proportion at any texture resolution.
171
+ */
172
+
173
+ interface PaintWidgetOptions {
174
+ /** Theme or explicit palette. Default: the document's mode, as the DOM renderer reads it. */
175
+ theme?: SceneTheme | "auto" | ScenePalette;
176
+ selected?: boolean;
177
+ /**
178
+ * The node's box in scene px. The card is drawn at these metrics and scaled
179
+ * to fill `w` x `h`, so a texture painted at 2x its node size is simply
180
+ * sharper, never laid out differently. Defaults to the target's height
181
+ * matched to `DEFAULT_NODE_SIZE.h` when not given and the target is not a node.
182
+ */
183
+ scenePx?: {
184
+ w: number;
185
+ h: number;
186
+ };
187
+ }
188
+ /**
189
+ * Paint `spec` as a card filling `w` x `h` px of `ctx`. The card is laid out at
190
+ * `opts.scenePx` (the node's own size) and scaled to the target, so it reads
191
+ * the same as the DOM card at any texture resolution. Without `scenePx`, a
192
+ * target at or above the default node height is treated as 1:1 scene px, and a
193
+ * smaller one is laid out at that height and scaled down.
194
+ */
195
+ declare function paintWidget(ctx: CanvasRenderingContext2D, spec: WidgetSpec, w: number, h: number, opts?: PaintWidgetOptions): void;
196
+
197
+ export { DARK_THEME_SELECTOR, DEFAULT_NODE_SIZE, FIT_MAX_ZOOM, FIT_PADDING, PX_PER_UNIT, type PaintWidgetOptions, SCENE_PALETTES, Scene, type SceneBounds, type SceneFrame, type SceneFrameOptions, SceneNode, type ScenePalette, type SceneTheme, WidgetSpec, type WorldPlacement, fitZoom, frameScene, nodeSize, paintWidget, resolveSceneTheme, sceneBounds, scenePalette, sceneToWorld };