@scenography/react 0.6.0 → 0.7.1
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 +142 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -1
- package/dist/index.d.mts +34 -1
- package/dist/index.mjs +144 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -65,6 +65,148 @@ function Gallery({ scene, className, style, options, onReady }) {
|
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
//#endregion
|
|
68
|
+
//#region src/LoadingScreen.tsx
|
|
69
|
+
const EMPTY = {
|
|
70
|
+
loaded: 0,
|
|
71
|
+
total: 0,
|
|
72
|
+
done: false
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Full-screen black loading cover for a gallery. Shows the initial asset
|
|
76
|
+
* progress from `gallery.loading`; once done, the bar becomes an "Entrar"
|
|
77
|
+
* button. The click is the user gesture needed for fullscreen, the landscape
|
|
78
|
+
* lock and audio autoplay, and gives time to rotate the phone.
|
|
79
|
+
*/
|
|
80
|
+
function LoadingScreen({ gallery, title, label = "Cargando…", enterLabel = "Entrar", rotateHint = "Gira el móvil para ver la sala en horizontal", onEnter, fadeDuration = 600 }) {
|
|
81
|
+
const [state, setState] = (0, react.useState)(EMPTY);
|
|
82
|
+
const [entered, setEntered] = (0, react.useState)(false);
|
|
83
|
+
const [gone, setGone] = (0, react.useState)(false);
|
|
84
|
+
const [portrait, setPortrait] = (0, react.useState)(false);
|
|
85
|
+
const timer = (0, react.useRef)(null);
|
|
86
|
+
(0, react.useEffect)(() => {
|
|
87
|
+
if (!gallery) return;
|
|
88
|
+
return gallery.loading.subscribe(setState);
|
|
89
|
+
}, [gallery]);
|
|
90
|
+
(0, react.useEffect)(() => {
|
|
91
|
+
const orientation = window.matchMedia("(orientation: portrait)");
|
|
92
|
+
const touch = window.matchMedia("(pointer: coarse)").matches;
|
|
93
|
+
const update = () => setPortrait(touch && orientation.matches);
|
|
94
|
+
update();
|
|
95
|
+
orientation.addEventListener("change", update);
|
|
96
|
+
return () => orientation.removeEventListener("change", update);
|
|
97
|
+
}, []);
|
|
98
|
+
(0, react.useEffect)(() => () => {
|
|
99
|
+
if (timer.current !== null) window.clearTimeout(timer.current);
|
|
100
|
+
}, []);
|
|
101
|
+
const enter = (0, react.useCallback)(() => {
|
|
102
|
+
if (entered) return;
|
|
103
|
+
if (window.matchMedia("(pointer: coarse)").matches) try {
|
|
104
|
+
const fullscreen = document.documentElement.requestFullscreen?.();
|
|
105
|
+
const screenOrientation = screen.orientation;
|
|
106
|
+
if (fullscreen) fullscreen.then(() => screenOrientation?.lock?.("landscape")).catch(() => void 0);
|
|
107
|
+
} catch {}
|
|
108
|
+
onEnter?.();
|
|
109
|
+
setEntered(true);
|
|
110
|
+
timer.current = window.setTimeout(() => setGone(true), fadeDuration);
|
|
111
|
+
}, [
|
|
112
|
+
entered,
|
|
113
|
+
fadeDuration,
|
|
114
|
+
onEnter
|
|
115
|
+
]);
|
|
116
|
+
if (gone) return null;
|
|
117
|
+
const ready = gallery !== null && state.done;
|
|
118
|
+
const progress = state.total > 0 ? state.loaded / state.total : 0;
|
|
119
|
+
const percent = Math.round(progress * 100);
|
|
120
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
121
|
+
style: {
|
|
122
|
+
position: "fixed",
|
|
123
|
+
inset: 0,
|
|
124
|
+
zIndex: 1e4,
|
|
125
|
+
display: "flex",
|
|
126
|
+
flexDirection: "column",
|
|
127
|
+
alignItems: "center",
|
|
128
|
+
justifyContent: "center",
|
|
129
|
+
gap: "1.25rem",
|
|
130
|
+
padding: "2rem",
|
|
131
|
+
background: "#000",
|
|
132
|
+
color: "#fff",
|
|
133
|
+
textAlign: "center",
|
|
134
|
+
fontFamily: "ui-sans-serif, system-ui, sans-serif",
|
|
135
|
+
opacity: entered ? 0 : 1,
|
|
136
|
+
pointerEvents: entered ? "none" : "auto",
|
|
137
|
+
transition: `opacity ${fadeDuration}ms ease`
|
|
138
|
+
},
|
|
139
|
+
children: [title ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h1", {
|
|
140
|
+
style: {
|
|
141
|
+
margin: 0,
|
|
142
|
+
fontSize: "clamp(1.5rem, 4vw, 2.25rem)",
|
|
143
|
+
fontWeight: 600
|
|
144
|
+
},
|
|
145
|
+
children: title
|
|
146
|
+
}) : null, ready ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
147
|
+
type: "button",
|
|
148
|
+
onClick: enter,
|
|
149
|
+
onPointerUp: enter,
|
|
150
|
+
style: {
|
|
151
|
+
padding: "0.8rem 2.4rem",
|
|
152
|
+
border: "1px solid rgba(255,255,255,0.6)",
|
|
153
|
+
borderRadius: 999,
|
|
154
|
+
background: "#fff",
|
|
155
|
+
color: "#000",
|
|
156
|
+
font: "inherit",
|
|
157
|
+
fontSize: "1.05rem",
|
|
158
|
+
fontWeight: 600,
|
|
159
|
+
cursor: "pointer"
|
|
160
|
+
},
|
|
161
|
+
children: enterLabel
|
|
162
|
+
}), portrait ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
163
|
+
style: {
|
|
164
|
+
margin: 0,
|
|
165
|
+
maxWidth: "22rem",
|
|
166
|
+
opacity: .75,
|
|
167
|
+
lineHeight: 1.5
|
|
168
|
+
},
|
|
169
|
+
children: rotateHint
|
|
170
|
+
}) : null] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
171
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
172
|
+
style: {
|
|
173
|
+
margin: 0,
|
|
174
|
+
opacity: .75
|
|
175
|
+
},
|
|
176
|
+
children: label
|
|
177
|
+
}),
|
|
178
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
179
|
+
role: "progressbar",
|
|
180
|
+
"aria-valuemin": 0,
|
|
181
|
+
"aria-valuemax": 100,
|
|
182
|
+
"aria-valuenow": percent,
|
|
183
|
+
style: {
|
|
184
|
+
width: "min(20rem, 72vw)",
|
|
185
|
+
height: "0.35rem",
|
|
186
|
+
borderRadius: 999,
|
|
187
|
+
background: "rgba(255,255,255,0.18)",
|
|
188
|
+
overflow: "hidden"
|
|
189
|
+
},
|
|
190
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: {
|
|
191
|
+
width: `${percent}%`,
|
|
192
|
+
height: "100%",
|
|
193
|
+
background: "#fff",
|
|
194
|
+
transition: "width 200ms ease"
|
|
195
|
+
} })
|
|
196
|
+
}),
|
|
197
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
198
|
+
style: {
|
|
199
|
+
margin: 0,
|
|
200
|
+
fontSize: "0.8rem",
|
|
201
|
+
opacity: .6
|
|
202
|
+
},
|
|
203
|
+
children: [percent, " %"]
|
|
204
|
+
})
|
|
205
|
+
] })]
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
//#endregion
|
|
68
209
|
exports.Gallery = Gallery;
|
|
210
|
+
exports.LoadingScreen = LoadingScreen;
|
|
69
211
|
|
|
70
212
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../src/Gallery.tsx"],"sourcesContent":["import { useEffect, useRef, type CSSProperties } from \"react\";\nimport {\n createGallery,\n type Gallery as GalleryInstance,\n type GalleryOptions,\n} from \"@scenography/engine\";\nimport type { Scene } from \"@scenography/scene\";\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 /** Engine options (antialias, ssao, …). Applied once on mount. */\n options?: Omit<GalleryOptions, \"canvas\">;\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, options, 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, ...options });\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 // Apply render-feature toggles live (antialias/ssao/bloom/shadows).\n useEffect(() => {\n galleryRef.current?.setRender({\n antialias: options?.antialias,\n ssao: options?.ssao,\n bloom: options?.bloom,\n shadows: options?.shadows,\n });\n }, [options?.antialias, options?.ssao, options?.bloom, options?.shadows]);\n\n return <canvas ref={canvasRef} className={className} style={{ ...fillStyle, ...style }} />;\n}\n"],"mappings":";;;;;AAmBA,MAAM,YAA2B;CAAE,SAAS;CAAS,OAAO;CAAQ,QAAQ;AAAO;;;;;;AAOnF,SAAgB,QAAQ,EAAE,OAAO,WAAW,OAAO,SAAS,WAAsC;CAChG,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;GAAE;GAAQ,GAAG;EAAQ,CAAC;EAC3D,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;CAGV,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,WAAW,SAAS,UAAU;GAC5B,WAAW,SAAS;GACpB,MAAM,SAAS;GACf,OAAO,SAAS;GAChB,SAAS,SAAS;EACpB,CAAC;CACH,GAAG;EAAC,SAAS;EAAW,SAAS;EAAM,SAAS;EAAO,SAAS;CAAO,CAAC;CAExE,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,UAAD;EAAQ,KAAK;EAAsB;EAAW,OAAO;GAAE,GAAG;GAAW,GAAG;EAAM;CAAI,CAAA;AAC3F"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/Gallery.tsx","../src/LoadingScreen.tsx"],"sourcesContent":["import { useEffect, useRef, type CSSProperties } from \"react\";\nimport {\n createGallery,\n type Gallery as GalleryInstance,\n type GalleryOptions,\n} from \"@scenography/engine\";\nimport type { Scene } from \"@scenography/scene\";\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 /** Engine options (antialias, ssao, …). Applied once on mount. */\n options?: Omit<GalleryOptions, \"canvas\">;\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, options, 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, ...options });\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 // Apply render-feature toggles live (antialias/ssao/bloom/shadows).\n useEffect(() => {\n galleryRef.current?.setRender({\n antialias: options?.antialias,\n ssao: options?.ssao,\n bloom: options?.bloom,\n shadows: options?.shadows,\n });\n }, [options?.antialias, options?.ssao, options?.bloom, options?.shadows]);\n\n return <canvas ref={canvasRef} className={className} style={{ ...fillStyle, ...style }} />;\n}\n","import { useCallback, useEffect, useRef, useState } from \"react\";\nimport type { Gallery, LoadingState } from \"@scenography/engine\";\n\nexport interface LoadingScreenProps {\n /** The live gallery, or null until `onReady` fires. */\n gallery: Gallery | null;\n /** Room title shown above the progress. */\n title?: string;\n /** Text while the assets load. Defaults to `\"Cargando…\"`. */\n label?: string;\n /** Button label once everything is ready. Defaults to `\"Entrar\"`. */\n enterLabel?: string;\n /** Hint shown in portrait on touch devices. */\n rotateHint?: string;\n /** Called when the visitor enters, before the fade starts. */\n onEnter?: () => void;\n /** Fade duration in ms. Defaults to `600`. */\n fadeDuration?: number;\n}\n\nconst EMPTY: LoadingState = { loaded: 0, total: 0, done: false };\n\n/**\n * Full-screen black loading cover for a gallery. Shows the initial asset\n * progress from `gallery.loading`; once done, the bar becomes an \"Entrar\"\n * button. The click is the user gesture needed for fullscreen, the landscape\n * lock and audio autoplay, and gives time to rotate the phone.\n */\nexport function LoadingScreen({\n gallery,\n title,\n label = \"Cargando…\",\n enterLabel = \"Entrar\",\n rotateHint = \"Gira el móvil para ver la sala en horizontal\",\n onEnter,\n fadeDuration = 600,\n}: LoadingScreenProps) {\n const [state, setState] = useState<LoadingState>(EMPTY);\n const [entered, setEntered] = useState(false);\n const [gone, setGone] = useState(false);\n const [portrait, setPortrait] = useState(false);\n const timer = useRef<number | null>(null);\n\n useEffect(() => {\n if (!gallery) return;\n return gallery.loading.subscribe(setState);\n }, [gallery]);\n\n useEffect(() => {\n const orientation = window.matchMedia(\"(orientation: portrait)\");\n const touch = window.matchMedia(\"(pointer: coarse)\").matches;\n const update = (): void => setPortrait(touch && orientation.matches);\n update();\n orientation.addEventListener(\"change\", update);\n return () => orientation.removeEventListener(\"change\", update);\n }, []);\n\n useEffect(\n () => () => {\n if (timer.current !== null) window.clearTimeout(timer.current);\n },\n [],\n );\n\n const enter = useCallback((): void => {\n if (entered) return;\n // Ask for fullscreen and the landscape lock, but never let them hold up the\n // room: some mobile browsers leave these promises pending or reject them,\n // and the visitor must enter anyway. The call still happens inside the\n // click gesture, which is what the browser requires.\n if (window.matchMedia(\"(pointer: coarse)\").matches) {\n try {\n const fullscreen = document.documentElement.requestFullscreen?.();\n const screenOrientation = (screen as Screen & { orientation?: ScreenOrientation })\n .orientation as (ScreenOrientation & { lock?: (value: string) => Promise<void> }) | undefined;\n if (fullscreen) {\n void fullscreen\n .then(() => screenOrientation?.lock?.(\"landscape\"))\n .catch(() => undefined);\n }\n } catch {\n // Not supported: continue into the room.\n }\n }\n onEnter?.();\n setEntered(true);\n timer.current = window.setTimeout(() => setGone(true), fadeDuration);\n }, [entered, fadeDuration, onEnter]);\n\n if (gone) return null;\n\n const ready = gallery !== null && state.done;\n const progress = state.total > 0 ? state.loaded / state.total : 0;\n const percent = Math.round(progress * 100);\n\n return (\n <div\n style={{\n position: \"fixed\",\n inset: 0,\n zIndex: 10000,\n display: \"flex\",\n flexDirection: \"column\",\n alignItems: \"center\",\n justifyContent: \"center\",\n gap: \"1.25rem\",\n padding: \"2rem\",\n background: \"#000\",\n color: \"#fff\",\n textAlign: \"center\",\n fontFamily: \"ui-sans-serif, system-ui, sans-serif\",\n opacity: entered ? 0 : 1,\n pointerEvents: entered ? \"none\" : \"auto\",\n transition: `opacity ${fadeDuration}ms ease`,\n }}\n >\n {title ? (\n <h1 style={{ margin: 0, fontSize: \"clamp(1.5rem, 4vw, 2.25rem)\", fontWeight: 600 }}>\n {title}\n </h1>\n ) : null}\n\n {ready ? (\n <>\n <button\n type=\"button\"\n onClick={enter}\n onPointerUp={enter}\n style={{\n padding: \"0.8rem 2.4rem\",\n border: \"1px solid rgba(255,255,255,0.6)\",\n borderRadius: 999,\n background: \"#fff\",\n color: \"#000\",\n font: \"inherit\",\n fontSize: \"1.05rem\",\n fontWeight: 600,\n cursor: \"pointer\",\n }}\n >\n {enterLabel}\n </button>\n {portrait ? (\n <p style={{ margin: 0, maxWidth: \"22rem\", opacity: 0.75, lineHeight: 1.5 }}>{rotateHint}</p>\n ) : null}\n </>\n ) : (\n <>\n <p style={{ margin: 0, opacity: 0.75 }}>{label}</p>\n <div\n role=\"progressbar\"\n aria-valuemin={0}\n aria-valuemax={100}\n aria-valuenow={percent}\n style={{\n width: \"min(20rem, 72vw)\",\n height: \"0.35rem\",\n borderRadius: 999,\n background: \"rgba(255,255,255,0.18)\",\n overflow: \"hidden\",\n }}\n >\n <div\n style={{\n width: `${percent}%`,\n height: \"100%\",\n background: \"#fff\",\n transition: \"width 200ms ease\",\n }}\n />\n </div>\n <p style={{ margin: 0, fontSize: \"0.8rem\", opacity: 0.6 }}>{percent} %</p>\n </>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;AAmBA,MAAM,YAA2B;CAAE,SAAS;CAAS,OAAO;CAAQ,QAAQ;AAAO;;;;;;AAOnF,SAAgB,QAAQ,EAAE,OAAO,WAAW,OAAO,SAAS,WAAsC;CAChG,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;GAAE;GAAQ,GAAG;EAAQ,CAAC;EAC3D,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;CAGV,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd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ACT,QAAQ;IACR,cAAc;IACd,YAAY;IACZ,OAAO;IACP,MAAM;IACN,UAAU;IACV,YAAY;IACZ,QAAQ;GACV;aAEC;EACK,CAAA,GACP,WACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,KAAD;GAAG,OAAO;IAAE,QAAQ;IAAG,UAAU;IAAS,SAAS;IAAM,YAAY;GAAI;aAAI;EAAc,CAAA,IACzF,IACJ,EAAA,CAAA,IAEF,iBAAA,GAAA,kBAAA,KAAA,CAAA,kBAAA,UAAA,EAAA,UAAA;GACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,KAAD;IAAG,OAAO;KAAE,QAAQ;KAAG,SAAS;IAAK;cAAI;GAAS,CAAA;GAClD,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;IACE,MAAK;IACL,iBAAe;IACf,iBAAe;IACf,iBAAe;IACf,OAAO;KACL,OAAO;KACP,QAAQ;KACR,cAAc;KACd,YAAY;KACZ,UAAU;IACZ;cAEA,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD,EACE,OAAO;KACL,OAAO,GAAG,QAAQ;KAClB,QAAQ;KACR,YAAY;KACZ,YAAY;IACd,EACD,CAAA;GACE,CAAA;GACL,iBAAA,GAAA,kBAAA,KAAA,CAAC,KAAD;IAAG,OAAO;KAAE,QAAQ;KAAG,UAAU;KAAU,SAAS;IAAI;cAAxD,CAA4D,SAAQ,IAAK;;EACzE,EAAA,CAAA,CAED;;AAET"}
|
package/dist/index.d.cts
CHANGED
|
@@ -26,5 +26,38 @@ declare function Gallery({
|
|
|
26
26
|
onReady
|
|
27
27
|
}: GalleryProps): JSX.Element;
|
|
28
28
|
//#endregion
|
|
29
|
-
|
|
29
|
+
//#region src/LoadingScreen.d.ts
|
|
30
|
+
interface LoadingScreenProps {
|
|
31
|
+
/** The live gallery, or null until `onReady` fires. */
|
|
32
|
+
gallery: Gallery$1 | null;
|
|
33
|
+
/** Room title shown above the progress. */
|
|
34
|
+
title?: string;
|
|
35
|
+
/** Text while the assets load. Defaults to `"Cargando…"`. */
|
|
36
|
+
label?: string;
|
|
37
|
+
/** Button label once everything is ready. Defaults to `"Entrar"`. */
|
|
38
|
+
enterLabel?: string;
|
|
39
|
+
/** Hint shown in portrait on touch devices. */
|
|
40
|
+
rotateHint?: string;
|
|
41
|
+
/** Called when the visitor enters, before the fade starts. */
|
|
42
|
+
onEnter?: () => void;
|
|
43
|
+
/** Fade duration in ms. Defaults to `600`. */
|
|
44
|
+
fadeDuration?: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Full-screen black loading cover for a gallery. Shows the initial asset
|
|
48
|
+
* progress from `gallery.loading`; once done, the bar becomes an "Entrar"
|
|
49
|
+
* button. The click is the user gesture needed for fullscreen, the landscape
|
|
50
|
+
* lock and audio autoplay, and gives time to rotate the phone.
|
|
51
|
+
*/
|
|
52
|
+
declare function LoadingScreen({
|
|
53
|
+
gallery,
|
|
54
|
+
title,
|
|
55
|
+
label,
|
|
56
|
+
enterLabel,
|
|
57
|
+
rotateHint,
|
|
58
|
+
onEnter,
|
|
59
|
+
fadeDuration
|
|
60
|
+
}: LoadingScreenProps): import("react").JSX.Element | null;
|
|
61
|
+
//#endregion
|
|
62
|
+
export { Gallery, type GalleryProps, LoadingScreen, type LoadingScreenProps };
|
|
30
63
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -26,5 +26,38 @@ declare function Gallery({
|
|
|
26
26
|
onReady
|
|
27
27
|
}: GalleryProps): JSX.Element;
|
|
28
28
|
//#endregion
|
|
29
|
-
|
|
29
|
+
//#region src/LoadingScreen.d.ts
|
|
30
|
+
interface LoadingScreenProps {
|
|
31
|
+
/** The live gallery, or null until `onReady` fires. */
|
|
32
|
+
gallery: Gallery$1 | null;
|
|
33
|
+
/** Room title shown above the progress. */
|
|
34
|
+
title?: string;
|
|
35
|
+
/** Text while the assets load. Defaults to `"Cargando…"`. */
|
|
36
|
+
label?: string;
|
|
37
|
+
/** Button label once everything is ready. Defaults to `"Entrar"`. */
|
|
38
|
+
enterLabel?: string;
|
|
39
|
+
/** Hint shown in portrait on touch devices. */
|
|
40
|
+
rotateHint?: string;
|
|
41
|
+
/** Called when the visitor enters, before the fade starts. */
|
|
42
|
+
onEnter?: () => void;
|
|
43
|
+
/** Fade duration in ms. Defaults to `600`. */
|
|
44
|
+
fadeDuration?: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Full-screen black loading cover for a gallery. Shows the initial asset
|
|
48
|
+
* progress from `gallery.loading`; once done, the bar becomes an "Entrar"
|
|
49
|
+
* button. The click is the user gesture needed for fullscreen, the landscape
|
|
50
|
+
* lock and audio autoplay, and gives time to rotate the phone.
|
|
51
|
+
*/
|
|
52
|
+
declare function LoadingScreen({
|
|
53
|
+
gallery,
|
|
54
|
+
title,
|
|
55
|
+
label,
|
|
56
|
+
enterLabel,
|
|
57
|
+
rotateHint,
|
|
58
|
+
onEnter,
|
|
59
|
+
fadeDuration
|
|
60
|
+
}: LoadingScreenProps): import("react").JSX.Element | null;
|
|
61
|
+
//#endregion
|
|
62
|
+
export { Gallery, type GalleryProps, LoadingScreen, type LoadingScreenProps };
|
|
30
63
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useEffect, useRef } from "react";
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
2
|
import { createGallery } from "@scenography/engine";
|
|
3
|
-
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
4
|
//#region src/Gallery.tsx
|
|
5
5
|
const fillStyle = {
|
|
6
6
|
display: "block",
|
|
@@ -64,6 +64,147 @@ function Gallery({ scene, className, style, options, onReady }) {
|
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
//#endregion
|
|
67
|
-
|
|
67
|
+
//#region src/LoadingScreen.tsx
|
|
68
|
+
const EMPTY = {
|
|
69
|
+
loaded: 0,
|
|
70
|
+
total: 0,
|
|
71
|
+
done: false
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Full-screen black loading cover for a gallery. Shows the initial asset
|
|
75
|
+
* progress from `gallery.loading`; once done, the bar becomes an "Entrar"
|
|
76
|
+
* button. The click is the user gesture needed for fullscreen, the landscape
|
|
77
|
+
* lock and audio autoplay, and gives time to rotate the phone.
|
|
78
|
+
*/
|
|
79
|
+
function LoadingScreen({ gallery, title, label = "Cargando…", enterLabel = "Entrar", rotateHint = "Gira el móvil para ver la sala en horizontal", onEnter, fadeDuration = 600 }) {
|
|
80
|
+
const [state, setState] = useState(EMPTY);
|
|
81
|
+
const [entered, setEntered] = useState(false);
|
|
82
|
+
const [gone, setGone] = useState(false);
|
|
83
|
+
const [portrait, setPortrait] = useState(false);
|
|
84
|
+
const timer = useRef(null);
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (!gallery) return;
|
|
87
|
+
return gallery.loading.subscribe(setState);
|
|
88
|
+
}, [gallery]);
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
const orientation = window.matchMedia("(orientation: portrait)");
|
|
91
|
+
const touch = window.matchMedia("(pointer: coarse)").matches;
|
|
92
|
+
const update = () => setPortrait(touch && orientation.matches);
|
|
93
|
+
update();
|
|
94
|
+
orientation.addEventListener("change", update);
|
|
95
|
+
return () => orientation.removeEventListener("change", update);
|
|
96
|
+
}, []);
|
|
97
|
+
useEffect(() => () => {
|
|
98
|
+
if (timer.current !== null) window.clearTimeout(timer.current);
|
|
99
|
+
}, []);
|
|
100
|
+
const enter = useCallback(() => {
|
|
101
|
+
if (entered) return;
|
|
102
|
+
if (window.matchMedia("(pointer: coarse)").matches) try {
|
|
103
|
+
const fullscreen = document.documentElement.requestFullscreen?.();
|
|
104
|
+
const screenOrientation = screen.orientation;
|
|
105
|
+
if (fullscreen) fullscreen.then(() => screenOrientation?.lock?.("landscape")).catch(() => void 0);
|
|
106
|
+
} catch {}
|
|
107
|
+
onEnter?.();
|
|
108
|
+
setEntered(true);
|
|
109
|
+
timer.current = window.setTimeout(() => setGone(true), fadeDuration);
|
|
110
|
+
}, [
|
|
111
|
+
entered,
|
|
112
|
+
fadeDuration,
|
|
113
|
+
onEnter
|
|
114
|
+
]);
|
|
115
|
+
if (gone) return null;
|
|
116
|
+
const ready = gallery !== null && state.done;
|
|
117
|
+
const progress = state.total > 0 ? state.loaded / state.total : 0;
|
|
118
|
+
const percent = Math.round(progress * 100);
|
|
119
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
120
|
+
style: {
|
|
121
|
+
position: "fixed",
|
|
122
|
+
inset: 0,
|
|
123
|
+
zIndex: 1e4,
|
|
124
|
+
display: "flex",
|
|
125
|
+
flexDirection: "column",
|
|
126
|
+
alignItems: "center",
|
|
127
|
+
justifyContent: "center",
|
|
128
|
+
gap: "1.25rem",
|
|
129
|
+
padding: "2rem",
|
|
130
|
+
background: "#000",
|
|
131
|
+
color: "#fff",
|
|
132
|
+
textAlign: "center",
|
|
133
|
+
fontFamily: "ui-sans-serif, system-ui, sans-serif",
|
|
134
|
+
opacity: entered ? 0 : 1,
|
|
135
|
+
pointerEvents: entered ? "none" : "auto",
|
|
136
|
+
transition: `opacity ${fadeDuration}ms ease`
|
|
137
|
+
},
|
|
138
|
+
children: [title ? /* @__PURE__ */ jsx("h1", {
|
|
139
|
+
style: {
|
|
140
|
+
margin: 0,
|
|
141
|
+
fontSize: "clamp(1.5rem, 4vw, 2.25rem)",
|
|
142
|
+
fontWeight: 600
|
|
143
|
+
},
|
|
144
|
+
children: title
|
|
145
|
+
}) : null, ready ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("button", {
|
|
146
|
+
type: "button",
|
|
147
|
+
onClick: enter,
|
|
148
|
+
onPointerUp: enter,
|
|
149
|
+
style: {
|
|
150
|
+
padding: "0.8rem 2.4rem",
|
|
151
|
+
border: "1px solid rgba(255,255,255,0.6)",
|
|
152
|
+
borderRadius: 999,
|
|
153
|
+
background: "#fff",
|
|
154
|
+
color: "#000",
|
|
155
|
+
font: "inherit",
|
|
156
|
+
fontSize: "1.05rem",
|
|
157
|
+
fontWeight: 600,
|
|
158
|
+
cursor: "pointer"
|
|
159
|
+
},
|
|
160
|
+
children: enterLabel
|
|
161
|
+
}), portrait ? /* @__PURE__ */ jsx("p", {
|
|
162
|
+
style: {
|
|
163
|
+
margin: 0,
|
|
164
|
+
maxWidth: "22rem",
|
|
165
|
+
opacity: .75,
|
|
166
|
+
lineHeight: 1.5
|
|
167
|
+
},
|
|
168
|
+
children: rotateHint
|
|
169
|
+
}) : null] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
170
|
+
/* @__PURE__ */ jsx("p", {
|
|
171
|
+
style: {
|
|
172
|
+
margin: 0,
|
|
173
|
+
opacity: .75
|
|
174
|
+
},
|
|
175
|
+
children: label
|
|
176
|
+
}),
|
|
177
|
+
/* @__PURE__ */ jsx("div", {
|
|
178
|
+
role: "progressbar",
|
|
179
|
+
"aria-valuemin": 0,
|
|
180
|
+
"aria-valuemax": 100,
|
|
181
|
+
"aria-valuenow": percent,
|
|
182
|
+
style: {
|
|
183
|
+
width: "min(20rem, 72vw)",
|
|
184
|
+
height: "0.35rem",
|
|
185
|
+
borderRadius: 999,
|
|
186
|
+
background: "rgba(255,255,255,0.18)",
|
|
187
|
+
overflow: "hidden"
|
|
188
|
+
},
|
|
189
|
+
children: /* @__PURE__ */ jsx("div", { style: {
|
|
190
|
+
width: `${percent}%`,
|
|
191
|
+
height: "100%",
|
|
192
|
+
background: "#fff",
|
|
193
|
+
transition: "width 200ms ease"
|
|
194
|
+
} })
|
|
195
|
+
}),
|
|
196
|
+
/* @__PURE__ */ jsxs("p", {
|
|
197
|
+
style: {
|
|
198
|
+
margin: 0,
|
|
199
|
+
fontSize: "0.8rem",
|
|
200
|
+
opacity: .6
|
|
201
|
+
},
|
|
202
|
+
children: [percent, " %"]
|
|
203
|
+
})
|
|
204
|
+
] })]
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
//#endregion
|
|
208
|
+
export { Gallery, LoadingScreen };
|
|
68
209
|
|
|
69
210
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/Gallery.tsx"],"sourcesContent":["import { useEffect, useRef, type CSSProperties } from \"react\";\nimport {\n createGallery,\n type Gallery as GalleryInstance,\n type GalleryOptions,\n} from \"@scenography/engine\";\nimport type { Scene } from \"@scenography/scene\";\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 /** Engine options (antialias, ssao, …). Applied once on mount. */\n options?: Omit<GalleryOptions, \"canvas\">;\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, options, 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, ...options });\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 // Apply render-feature toggles live (antialias/ssao/bloom/shadows).\n useEffect(() => {\n galleryRef.current?.setRender({\n antialias: options?.antialias,\n ssao: options?.ssao,\n bloom: options?.bloom,\n shadows: options?.shadows,\n });\n }, [options?.antialias, options?.ssao, options?.bloom, options?.shadows]);\n\n return <canvas ref={canvasRef} className={className} style={{ ...fillStyle, ...style }} />;\n}\n"],"mappings":";;;;AAmBA,MAAM,YAA2B;CAAE,SAAS;CAAS,OAAO;CAAQ,QAAQ;AAAO;;;;;;AAOnF,SAAgB,QAAQ,EAAE,OAAO,WAAW,OAAO,SAAS,WAAsC;CAChG,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;GAAE;GAAQ,GAAG;EAAQ,CAAC;EAC3D,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;CAGV,gBAAgB;EACd,WAAW,SAAS,UAAU;GAC5B,WAAW,SAAS;GACpB,MAAM,SAAS;GACf,OAAO,SAAS;GAChB,SAAS,SAAS;EACpB,CAAC;CACH,GAAG;EAAC,SAAS;EAAW,SAAS;EAAM,SAAS;EAAO,SAAS;CAAO,CAAC;CAExE,OAAO,oBAAC,UAAD;EAAQ,KAAK;EAAsB;EAAW,OAAO;GAAE,GAAG;GAAW,GAAG;EAAM;CAAI,CAAA;AAC3F"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/Gallery.tsx","../src/LoadingScreen.tsx"],"sourcesContent":["import { useEffect, useRef, type CSSProperties } from \"react\";\nimport {\n createGallery,\n type Gallery as GalleryInstance,\n type GalleryOptions,\n} from \"@scenography/engine\";\nimport type { Scene } from \"@scenography/scene\";\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 /** Engine options (antialias, ssao, …). Applied once on mount. */\n options?: Omit<GalleryOptions, \"canvas\">;\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, options, 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, ...options });\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 // Apply render-feature toggles live (antialias/ssao/bloom/shadows).\n useEffect(() => {\n galleryRef.current?.setRender({\n antialias: options?.antialias,\n ssao: options?.ssao,\n bloom: options?.bloom,\n shadows: options?.shadows,\n });\n }, [options?.antialias, options?.ssao, options?.bloom, options?.shadows]);\n\n return <canvas ref={canvasRef} className={className} style={{ ...fillStyle, ...style }} />;\n}\n","import { useCallback, useEffect, useRef, useState } from \"react\";\nimport type { Gallery, LoadingState } from \"@scenography/engine\";\n\nexport interface LoadingScreenProps {\n /** The live gallery, or null until `onReady` fires. */\n gallery: Gallery | null;\n /** Room title shown above the progress. */\n title?: string;\n /** Text while the assets load. Defaults to `\"Cargando…\"`. */\n label?: string;\n /** Button label once everything is ready. Defaults to `\"Entrar\"`. */\n enterLabel?: string;\n /** Hint shown in portrait on touch devices. */\n rotateHint?: string;\n /** Called when the visitor enters, before the fade starts. */\n onEnter?: () => void;\n /** Fade duration in ms. Defaults to `600`. */\n fadeDuration?: number;\n}\n\nconst EMPTY: LoadingState = { loaded: 0, total: 0, done: false };\n\n/**\n * Full-screen black loading cover for a gallery. Shows the initial asset\n * progress from `gallery.loading`; once done, the bar becomes an \"Entrar\"\n * button. The click is the user gesture needed for fullscreen, the landscape\n * lock and audio autoplay, and gives time to rotate the phone.\n */\nexport function LoadingScreen({\n gallery,\n title,\n label = \"Cargando…\",\n enterLabel = \"Entrar\",\n rotateHint = \"Gira el móvil para ver la sala en horizontal\",\n onEnter,\n fadeDuration = 600,\n}: LoadingScreenProps) {\n const [state, setState] = useState<LoadingState>(EMPTY);\n const [entered, setEntered] = useState(false);\n const [gone, setGone] = useState(false);\n const [portrait, setPortrait] = useState(false);\n const timer = useRef<number | null>(null);\n\n useEffect(() => {\n if (!gallery) return;\n return gallery.loading.subscribe(setState);\n }, [gallery]);\n\n useEffect(() => {\n const orientation = window.matchMedia(\"(orientation: portrait)\");\n const touch = window.matchMedia(\"(pointer: coarse)\").matches;\n const update = (): void => setPortrait(touch && orientation.matches);\n update();\n orientation.addEventListener(\"change\", update);\n return () => orientation.removeEventListener(\"change\", update);\n }, []);\n\n useEffect(\n () => () => {\n if (timer.current !== null) window.clearTimeout(timer.current);\n },\n [],\n );\n\n const enter = useCallback((): void => {\n if (entered) return;\n // Ask for fullscreen and the landscape lock, but never let them hold up the\n // room: some mobile browsers leave these promises pending or reject them,\n // and the visitor must enter anyway. The call still happens inside the\n // click gesture, which is what the browser requires.\n if (window.matchMedia(\"(pointer: coarse)\").matches) {\n try {\n const fullscreen = document.documentElement.requestFullscreen?.();\n const screenOrientation = (screen as Screen & { orientation?: ScreenOrientation })\n .orientation as (ScreenOrientation & { lock?: (value: string) => Promise<void> }) | undefined;\n if (fullscreen) {\n void fullscreen\n .then(() => screenOrientation?.lock?.(\"landscape\"))\n .catch(() => undefined);\n }\n } catch {\n // Not supported: continue into the room.\n }\n }\n onEnter?.();\n setEntered(true);\n timer.current = window.setTimeout(() => setGone(true), fadeDuration);\n }, [entered, fadeDuration, onEnter]);\n\n if (gone) return null;\n\n const ready = gallery !== null && state.done;\n const progress = state.total > 0 ? state.loaded / state.total : 0;\n const percent = Math.round(progress * 100);\n\n return (\n <div\n style={{\n position: \"fixed\",\n inset: 0,\n zIndex: 10000,\n display: \"flex\",\n flexDirection: \"column\",\n alignItems: \"center\",\n justifyContent: \"center\",\n gap: \"1.25rem\",\n padding: \"2rem\",\n background: \"#000\",\n color: \"#fff\",\n textAlign: \"center\",\n fontFamily: \"ui-sans-serif, system-ui, sans-serif\",\n opacity: entered ? 0 : 1,\n pointerEvents: entered ? \"none\" : \"auto\",\n transition: `opacity ${fadeDuration}ms ease`,\n }}\n >\n {title ? (\n <h1 style={{ margin: 0, fontSize: \"clamp(1.5rem, 4vw, 2.25rem)\", fontWeight: 600 }}>\n {title}\n </h1>\n ) : null}\n\n {ready ? (\n <>\n <button\n type=\"button\"\n onClick={enter}\n onPointerUp={enter}\n style={{\n padding: \"0.8rem 2.4rem\",\n border: \"1px solid rgba(255,255,255,0.6)\",\n borderRadius: 999,\n background: \"#fff\",\n color: \"#000\",\n font: \"inherit\",\n fontSize: \"1.05rem\",\n fontWeight: 600,\n cursor: \"pointer\",\n }}\n >\n {enterLabel}\n </button>\n {portrait ? (\n <p style={{ margin: 0, maxWidth: \"22rem\", opacity: 0.75, lineHeight: 1.5 }}>{rotateHint}</p>\n ) : null}\n </>\n ) : (\n <>\n <p style={{ margin: 0, opacity: 0.75 }}>{label}</p>\n <div\n role=\"progressbar\"\n aria-valuemin={0}\n aria-valuemax={100}\n aria-valuenow={percent}\n style={{\n width: \"min(20rem, 72vw)\",\n height: \"0.35rem\",\n borderRadius: 999,\n background: \"rgba(255,255,255,0.18)\",\n overflow: \"hidden\",\n }}\n >\n <div\n style={{\n width: `${percent}%`,\n height: \"100%\",\n background: \"#fff\",\n transition: \"width 200ms ease\",\n }}\n />\n </div>\n <p style={{ margin: 0, fontSize: \"0.8rem\", opacity: 0.6 }}>{percent} %</p>\n </>\n )}\n </div>\n );\n}\n"],"mappings":";;;;AAmBA,MAAM,YAA2B;CAAE,SAAS;CAAS,OAAO;CAAQ,QAAQ;AAAO;;;;;;AAOnF,SAAgB,QAAQ,EAAE,OAAO,WAAW,OAAO,SAAS,WAAsC;CAChG,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;GAAE;GAAQ,GAAG;EAAQ,CAAC;EAC3D,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,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;IACV,YAAY;IACZ,QAAQ;GACV;aAEC;EACK,CAAA,GACP,WACC,oBAAC,KAAD;GAAG,OAAO;IAAE,QAAQ;IAAG,UAAU;IAAS,SAAS;IAAM,YAAY;GAAI;aAAI;EAAc,CAAA,IACzF,IACJ,EAAA,CAAA,IAEF,qBAAA,UAAA,EAAA,UAAA;GACE,oBAAC,KAAD;IAAG,OAAO;KAAE,QAAQ;KAAG,SAAS;IAAK;cAAI;GAAS,CAAA;GAClD,oBAAC,OAAD;IACE,MAAK;IACL,iBAAe;IACf,iBAAe;IACf,iBAAe;IACf,OAAO;KACL,OAAO;KACP,QAAQ;KACR,cAAc;KACd,YAAY;KACZ,UAAU;IACZ;cAEA,oBAAC,OAAD,EACE,OAAO;KACL,OAAO,GAAG,QAAQ;KAClB,QAAQ;KACR,YAAY;KACZ,YAAY;IACd,EACD,CAAA;GACE,CAAA;GACL,qBAAC,KAAD;IAAG,OAAO;KAAE,QAAQ;KAAG,UAAU;KAAU,SAAS;IAAI;cAAxD,CAA4D,SAAQ,IAAK;;EACzE,EAAA,CAAA,CAED;;AAET"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scenography/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "React bindings for scenography: a declarative <Gallery> component over the engine, with hot scene updates.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -23,19 +23,19 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@scenography/engine": "0.
|
|
26
|
+
"@scenography/engine": "0.7.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/react": "^18.3.0",
|
|
30
30
|
"@types/three": "^0.160.0",
|
|
31
31
|
"react": "^18.3.0",
|
|
32
32
|
"three": "^0.160.0",
|
|
33
|
-
"@scenography/scene": "0.
|
|
33
|
+
"@scenography/scene": "0.7.1"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"react": ">=18",
|
|
37
37
|
"three": ">=0.160.0",
|
|
38
|
-
"@scenography/scene": "0.
|
|
38
|
+
"@scenography/scene": "0.7.1"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "tsdown",
|