@scenography/react 0.1.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.cjs +54 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +27 -0
- package/dist/index.d.mts +27 -0
- package/dist/index.mjs +53 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +45 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let react = require("react");
|
|
3
|
+
let _scenography_engine = require("@scenography/engine");
|
|
4
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
|
+
//#region src/Gallery.tsx
|
|
6
|
+
const fillStyle = {
|
|
7
|
+
display: "block",
|
|
8
|
+
width: "100%",
|
|
9
|
+
height: "100%"
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Declarative React wrapper over the engine. Mounts a `createGallery` onto a
|
|
13
|
+
* canvas, keeps it sized to its container, and feeds scene changes through
|
|
14
|
+
* `setScene` so edits reconcile without remounting.
|
|
15
|
+
*/
|
|
16
|
+
function Gallery({ scene, className, style, onReady }) {
|
|
17
|
+
const canvasRef = (0, react.useRef)(null);
|
|
18
|
+
const galleryRef = (0, react.useRef)(null);
|
|
19
|
+
(0, react.useEffect)(() => {
|
|
20
|
+
const canvas = canvasRef.current;
|
|
21
|
+
if (!canvas) return;
|
|
22
|
+
const gallery = (0, _scenography_engine.createGallery)(scene, { canvas });
|
|
23
|
+
galleryRef.current = gallery;
|
|
24
|
+
gallery.start();
|
|
25
|
+
onReady?.(gallery);
|
|
26
|
+
const resize = () => {
|
|
27
|
+
const parent = canvas.parentElement;
|
|
28
|
+
if (parent) gallery.resize(parent.clientWidth, parent.clientHeight);
|
|
29
|
+
};
|
|
30
|
+
resize();
|
|
31
|
+
const observer = new ResizeObserver(resize);
|
|
32
|
+
if (canvas.parentElement) observer.observe(canvas.parentElement);
|
|
33
|
+
return () => {
|
|
34
|
+
observer.disconnect();
|
|
35
|
+
gallery.dispose();
|
|
36
|
+
galleryRef.current = null;
|
|
37
|
+
};
|
|
38
|
+
}, []);
|
|
39
|
+
(0, react.useEffect)(() => {
|
|
40
|
+
galleryRef.current?.setScene(scene);
|
|
41
|
+
}, [scene]);
|
|
42
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("canvas", {
|
|
43
|
+
ref: canvasRef,
|
|
44
|
+
className,
|
|
45
|
+
style: {
|
|
46
|
+
...fillStyle,
|
|
47
|
+
...style
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
exports.Gallery = Gallery;
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/Gallery.tsx"],"sourcesContent":["import { useEffect, useRef, type CSSProperties } from \"react\";\nimport { createGallery, type Gallery as GalleryInstance } from \"@scenography/engine\";\nimport type { Scene } from \"@scenography/core\";\n\nexport interface GalleryProps {\n /** The scene definition to render. Changing it hot-reconciles in place. */\n scene: Scene;\n className?: string;\n style?: CSSProperties;\n /** Called once with the gallery instance after it mounts (escape hatch). */\n onReady?: (gallery: GalleryInstance) => void;\n}\n\nconst fillStyle: CSSProperties = { display: \"block\", width: \"100%\", height: \"100%\" };\n\n/**\n * Declarative React wrapper over the engine. Mounts a `createGallery` onto a\n * canvas, keeps it sized to its container, and feeds scene changes through\n * `setScene` so edits reconcile without remounting.\n */\nexport function Gallery({ scene, className, style, onReady }: GalleryProps): JSX.Element {\n const canvasRef = useRef<HTMLCanvasElement>(null);\n const galleryRef = useRef<GalleryInstance | null>(null);\n\n // Mount once: create the gallery, track container size, run the loop.\n useEffect(() => {\n const canvas = canvasRef.current;\n if (!canvas) return;\n\n const gallery = createGallery(scene, { canvas });\n galleryRef.current = gallery;\n gallery.start();\n onReady?.(gallery);\n\n const resize = (): void => {\n const parent = canvas.parentElement;\n if (parent) gallery.resize(parent.clientWidth, parent.clientHeight);\n };\n resize();\n const observer = new ResizeObserver(resize);\n if (canvas.parentElement) observer.observe(canvas.parentElement);\n\n return () => {\n observer.disconnect();\n gallery.dispose();\n galleryRef.current = null;\n };\n // Mount/unmount only — scene updates are handled below.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // Hot-reconcile whenever the scene definition changes.\n useEffect(() => {\n galleryRef.current?.setScene(scene);\n }, [scene]);\n\n return <canvas ref={canvasRef} className={className} style={{ ...fillStyle, ...style }} />;\n}\n"],"mappings":";;;;;AAaA,MAAM,YAA2B;CAAE,SAAS;CAAS,OAAO;CAAQ,QAAQ;AAAO;;;;;;AAOnF,SAAgB,QAAQ,EAAE,OAAO,WAAW,OAAO,WAAsC;CACvF,MAAM,aAAA,GAAA,MAAA,OAAA,CAAsC,IAAI;CAChD,MAAM,cAAA,GAAA,MAAA,OAAA,CAA4C,IAAI;CAGtD,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,MAAM,SAAS,UAAU;EACzB,IAAI,CAAC,QAAQ;EAEb,MAAM,WAAA,GAAA,oBAAA,cAAA,CAAwB,OAAO,EAAE,OAAO,CAAC;EAC/C,WAAW,UAAU;EACrB,QAAQ,MAAM;EACd,UAAU,OAAO;EAEjB,MAAM,eAAqB;GACzB,MAAM,SAAS,OAAO;GACtB,IAAI,QAAQ,QAAQ,OAAO,OAAO,aAAa,OAAO,YAAY;EACpE;EACA,OAAO;EACP,MAAM,WAAW,IAAI,eAAe,MAAM;EAC1C,IAAI,OAAO,eAAe,SAAS,QAAQ,OAAO,aAAa;EAE/D,aAAa;GACX,SAAS,WAAW;GACpB,QAAQ,QAAQ;GAChB,WAAW,UAAU;EACvB;CAGF,GAAG,CAAC,CAAC;CAGL,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,WAAW,SAAS,SAAS,KAAK;CACpC,GAAG,CAAC,KAAK,CAAC;CAEV,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,UAAD;EAAQ,KAAK;EAAsB;EAAW,OAAO;GAAE,GAAG;GAAW,GAAG;EAAM;CAAI,CAAA;AAC3F"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CSSProperties } from "react";
|
|
2
|
+
import { Gallery as Gallery$1 } from "@scenography/engine";
|
|
3
|
+
import { Scene } from "@scenography/core";
|
|
4
|
+
|
|
5
|
+
//#region src/Gallery.d.ts
|
|
6
|
+
interface GalleryProps {
|
|
7
|
+
/** The scene definition to render. Changing it hot-reconciles in place. */
|
|
8
|
+
scene: Scene;
|
|
9
|
+
className?: string;
|
|
10
|
+
style?: CSSProperties;
|
|
11
|
+
/** Called once with the gallery instance after it mounts (escape hatch). */
|
|
12
|
+
onReady?: (gallery: Gallery$1) => void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Declarative React wrapper over the engine. Mounts a `createGallery` onto a
|
|
16
|
+
* canvas, keeps it sized to its container, and feeds scene changes through
|
|
17
|
+
* `setScene` so edits reconcile without remounting.
|
|
18
|
+
*/
|
|
19
|
+
declare function Gallery({
|
|
20
|
+
scene,
|
|
21
|
+
className,
|
|
22
|
+
style,
|
|
23
|
+
onReady
|
|
24
|
+
}: GalleryProps): JSX.Element;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { Gallery, type GalleryProps };
|
|
27
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CSSProperties } from "react";
|
|
2
|
+
import { Gallery as Gallery$1 } from "@scenography/engine";
|
|
3
|
+
import { Scene } from "@scenography/core";
|
|
4
|
+
|
|
5
|
+
//#region src/Gallery.d.ts
|
|
6
|
+
interface GalleryProps {
|
|
7
|
+
/** The scene definition to render. Changing it hot-reconciles in place. */
|
|
8
|
+
scene: Scene;
|
|
9
|
+
className?: string;
|
|
10
|
+
style?: CSSProperties;
|
|
11
|
+
/** Called once with the gallery instance after it mounts (escape hatch). */
|
|
12
|
+
onReady?: (gallery: Gallery$1) => void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Declarative React wrapper over the engine. Mounts a `createGallery` onto a
|
|
16
|
+
* canvas, keeps it sized to its container, and feeds scene changes through
|
|
17
|
+
* `setScene` so edits reconcile without remounting.
|
|
18
|
+
*/
|
|
19
|
+
declare function Gallery({
|
|
20
|
+
scene,
|
|
21
|
+
className,
|
|
22
|
+
style,
|
|
23
|
+
onReady
|
|
24
|
+
}: GalleryProps): JSX.Element;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { Gallery, type GalleryProps };
|
|
27
|
+
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { createGallery } from "@scenography/engine";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/Gallery.tsx
|
|
5
|
+
const fillStyle = {
|
|
6
|
+
display: "block",
|
|
7
|
+
width: "100%",
|
|
8
|
+
height: "100%"
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Declarative React wrapper over the engine. Mounts a `createGallery` onto a
|
|
12
|
+
* canvas, keeps it sized to its container, and feeds scene changes through
|
|
13
|
+
* `setScene` so edits reconcile without remounting.
|
|
14
|
+
*/
|
|
15
|
+
function Gallery({ scene, className, style, onReady }) {
|
|
16
|
+
const canvasRef = useRef(null);
|
|
17
|
+
const galleryRef = useRef(null);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const canvas = canvasRef.current;
|
|
20
|
+
if (!canvas) return;
|
|
21
|
+
const gallery = createGallery(scene, { canvas });
|
|
22
|
+
galleryRef.current = gallery;
|
|
23
|
+
gallery.start();
|
|
24
|
+
onReady?.(gallery);
|
|
25
|
+
const resize = () => {
|
|
26
|
+
const parent = canvas.parentElement;
|
|
27
|
+
if (parent) gallery.resize(parent.clientWidth, parent.clientHeight);
|
|
28
|
+
};
|
|
29
|
+
resize();
|
|
30
|
+
const observer = new ResizeObserver(resize);
|
|
31
|
+
if (canvas.parentElement) observer.observe(canvas.parentElement);
|
|
32
|
+
return () => {
|
|
33
|
+
observer.disconnect();
|
|
34
|
+
gallery.dispose();
|
|
35
|
+
galleryRef.current = null;
|
|
36
|
+
};
|
|
37
|
+
}, []);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
galleryRef.current?.setScene(scene);
|
|
40
|
+
}, [scene]);
|
|
41
|
+
return /* @__PURE__ */ jsx("canvas", {
|
|
42
|
+
ref: canvasRef,
|
|
43
|
+
className,
|
|
44
|
+
style: {
|
|
45
|
+
...fillStyle,
|
|
46
|
+
...style
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { Gallery };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/Gallery.tsx"],"sourcesContent":["import { useEffect, useRef, type CSSProperties } from \"react\";\nimport { createGallery, type Gallery as GalleryInstance } from \"@scenography/engine\";\nimport type { Scene } from \"@scenography/core\";\n\nexport interface GalleryProps {\n /** The scene definition to render. Changing it hot-reconciles in place. */\n scene: Scene;\n className?: string;\n style?: CSSProperties;\n /** Called once with the gallery instance after it mounts (escape hatch). */\n onReady?: (gallery: GalleryInstance) => void;\n}\n\nconst fillStyle: CSSProperties = { display: \"block\", width: \"100%\", height: \"100%\" };\n\n/**\n * Declarative React wrapper over the engine. Mounts a `createGallery` onto a\n * canvas, keeps it sized to its container, and feeds scene changes through\n * `setScene` so edits reconcile without remounting.\n */\nexport function Gallery({ scene, className, style, onReady }: GalleryProps): JSX.Element {\n const canvasRef = useRef<HTMLCanvasElement>(null);\n const galleryRef = useRef<GalleryInstance | null>(null);\n\n // Mount once: create the gallery, track container size, run the loop.\n useEffect(() => {\n const canvas = canvasRef.current;\n if (!canvas) return;\n\n const gallery = createGallery(scene, { canvas });\n galleryRef.current = gallery;\n gallery.start();\n onReady?.(gallery);\n\n const resize = (): void => {\n const parent = canvas.parentElement;\n if (parent) gallery.resize(parent.clientWidth, parent.clientHeight);\n };\n resize();\n const observer = new ResizeObserver(resize);\n if (canvas.parentElement) observer.observe(canvas.parentElement);\n\n return () => {\n observer.disconnect();\n gallery.dispose();\n galleryRef.current = null;\n };\n // Mount/unmount only — scene updates are handled below.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // Hot-reconcile whenever the scene definition changes.\n useEffect(() => {\n galleryRef.current?.setScene(scene);\n }, [scene]);\n\n return <canvas ref={canvasRef} className={className} style={{ ...fillStyle, ...style }} />;\n}\n"],"mappings":";;;;AAaA,MAAM,YAA2B;CAAE,SAAS;CAAS,OAAO;CAAQ,QAAQ;AAAO;;;;;;AAOnF,SAAgB,QAAQ,EAAE,OAAO,WAAW,OAAO,WAAsC;CACvF,MAAM,YAAY,OAA0B,IAAI;CAChD,MAAM,aAAa,OAA+B,IAAI;CAGtD,gBAAgB;EACd,MAAM,SAAS,UAAU;EACzB,IAAI,CAAC,QAAQ;EAEb,MAAM,UAAU,cAAc,OAAO,EAAE,OAAO,CAAC;EAC/C,WAAW,UAAU;EACrB,QAAQ,MAAM;EACd,UAAU,OAAO;EAEjB,MAAM,eAAqB;GACzB,MAAM,SAAS,OAAO;GACtB,IAAI,QAAQ,QAAQ,OAAO,OAAO,aAAa,OAAO,YAAY;EACpE;EACA,OAAO;EACP,MAAM,WAAW,IAAI,eAAe,MAAM;EAC1C,IAAI,OAAO,eAAe,SAAS,QAAQ,OAAO,aAAa;EAE/D,aAAa;GACX,SAAS,WAAW;GACpB,QAAQ,QAAQ;GAChB,WAAW,UAAU;EACvB;CAGF,GAAG,CAAC,CAAC;CAGL,gBAAgB;EACd,WAAW,SAAS,SAAS,KAAK;CACpC,GAAG,CAAC,KAAK,CAAC;CAEV,OAAO,oBAAC,UAAD;EAAQ,KAAK;EAAsB;EAAW,OAAO;GAAE,GAAG;GAAW,GAAG;EAAM;CAAI,CAAA;AAC3F"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@scenography/react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React bindings for scenography: a declarative <Gallery> component over the engine, with hot scene updates.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "./dist/index.cjs",
|
|
11
|
+
"module": "./dist/index.mjs",
|
|
12
|
+
"types": "./dist/index.d.cts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"import": {
|
|
16
|
+
"types": "./dist/index.d.mts",
|
|
17
|
+
"default": "./dist/index.mjs"
|
|
18
|
+
},
|
|
19
|
+
"require": {
|
|
20
|
+
"types": "./dist/index.d.cts",
|
|
21
|
+
"default": "./dist/index.cjs"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@scenography/engine": "0.1.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/react": "^18.3.0",
|
|
30
|
+
"@types/three": "^0.160.0",
|
|
31
|
+
"react": "^18.3.0",
|
|
32
|
+
"three": "^0.160.0",
|
|
33
|
+
"@scenography/core": "0.1.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"react": ">=18",
|
|
37
|
+
"three": ">=0.160.0",
|
|
38
|
+
"@scenography/core": "0.1.0"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsdown",
|
|
42
|
+
"dev": "tsdown --watch",
|
|
43
|
+
"typecheck": "tsc --noEmit"
|
|
44
|
+
}
|
|
45
|
+
}
|