@glyphcss/react 0.0.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 ADDED
@@ -0,0 +1,808 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ BASE_TILE: () => import_core2.BASE_TILE,
24
+ CAMERA_BACKFACE_CULL_EPS: () => import_core2.CAMERA_BACKFACE_CULL_EPS,
25
+ DEFAULT_CAMERA_STATE: () => import_core2.DEFAULT_CAMERA_STATE,
26
+ DEFAULT_PROJECTION: () => import_core2.DEFAULT_PROJECTION,
27
+ GlyphcssAxesHelper: () => GlyphcssAxesHelper,
28
+ GlyphcssCamera: () => GlyphcssPerspectiveCamera,
29
+ GlyphcssCameraContext: () => GlyphcssCameraContext,
30
+ GlyphcssDirectionalLightHelper: () => GlyphcssDirectionalLightHelper,
31
+ GlyphcssFirstPersonControls: () => GlyphcssFirstPersonControls,
32
+ GlyphcssHotspot: () => GlyphcssHotspot,
33
+ GlyphcssMapControls: () => GlyphcssMapControls,
34
+ GlyphcssMesh: () => GlyphcssMesh,
35
+ GlyphcssOrbitControls: () => GlyphcssOrbitControls,
36
+ GlyphcssOrthographicCamera: () => GlyphcssOrthographicCamera,
37
+ GlyphcssPerspectiveCamera: () => GlyphcssPerspectiveCamera,
38
+ GlyphcssScene: () => GlyphcssScene,
39
+ GlyphcssSceneContext: () => GlyphcssSceneContext,
40
+ LoopOnce: () => import_core2.LoopOnce,
41
+ LoopPingPong: () => import_core2.LoopPingPong,
42
+ LoopRepeat: () => import_core2.LoopRepeat,
43
+ VOXEL_CAMERA_CULL_AXIS_EPS: () => import_core2.VOXEL_CAMERA_CULL_AXIS_EPS,
44
+ VOXEL_CAMERA_CULL_NORMAL_LIMIT: () => import_core2.VOXEL_CAMERA_CULL_NORMAL_LIMIT,
45
+ arrowPolygons: () => import_core2.arrowPolygons,
46
+ axesHelperPolygons: () => import_core2.axesHelperPolygons,
47
+ bakeSolidTextureSampledPolygons: () => import_core2.bakeSolidTextureSampledPolygons,
48
+ bakeSolidTextureSamples: () => import_core2.bakeSolidTextureSamples,
49
+ buildSceneContext: () => import_core2.buildSceneContext,
50
+ cameraCullNormalGroups: () => import_core2.cameraCullNormalGroups,
51
+ cameraCullNormalGroupsFromPolygons: () => import_core2.cameraCullNormalGroupsFromPolygons,
52
+ cameraCullNormalKey: () => import_core2.cameraCullNormalKey,
53
+ cameraCullVisibleSignature: () => import_core2.cameraCullVisibleSignature,
54
+ cameraFacingDepth: () => import_core2.cameraFacingDepth,
55
+ clampChannel: () => import_core2.clampChannel,
56
+ computeSceneBbox: () => import_core2.computeSceneBbox,
57
+ computeShapeLighting: () => import_core2.computeShapeLighting,
58
+ coverPlanarPolygons: () => import_core2.coverPlanarPolygons,
59
+ createGlyphcssAnimationMixer: () => import_core2.createGlyphcssAnimationMixer,
60
+ createIsometricCamera: () => import_core2.createIsometricCamera,
61
+ cullInteriorPolygons: () => import_core2.cullInteriorPolygons,
62
+ findGlyphcssMeshHandle: () => findGlyphcssMeshHandle,
63
+ formatColor: () => import_core2.formatColor,
64
+ injectGlyphcssBaseStyles: () => import_glyphcss8.injectGlyphcssBaseStyles,
65
+ inverseRotateVec3: () => import_core2.inverseRotateVec3,
66
+ isAxisAlignedSurfaceNormal: () => import_core2.isAxisAlignedSurfaceNormal,
67
+ isVoxelCameraCullableNormalGroups: () => import_core2.isVoxelCameraCullableNormalGroups,
68
+ loadMesh: () => import_core2.loadMesh,
69
+ mergePolygons: () => import_core2.mergePolygons,
70
+ normalFacesCamera: () => import_core2.normalFacesCamera,
71
+ normalizeInvertMultiplier: () => import_core2.normalizeInvertMultiplier,
72
+ normalizePolygons: () => import_core2.normalizePolygons,
73
+ octahedronPolygons: () => import_core2.octahedronPolygons,
74
+ optimizeMeshPolygons: () => import_core2.optimizeMeshPolygons,
75
+ parseColor: () => import_core2.parseColor,
76
+ parseGltf: () => import_core2.parseGltf,
77
+ parseHexColor: () => import_core2.parseHexColor,
78
+ parseMtl: () => import_core2.parseMtl,
79
+ parseObj: () => import_core2.parseObj,
80
+ parsePureColor: () => import_core2.parsePureColor,
81
+ parseRgbColor: () => import_core2.parseRgbColor,
82
+ parseVox: () => import_core2.parseVox,
83
+ polygonCssSurfaceNormal: () => import_core2.polygonCssSurfaceNormal,
84
+ polygonFaces: () => import_core2.polygonFaces,
85
+ polygonFacesCamera: () => import_core2.polygonFacesCamera,
86
+ ringPolygons: () => import_core2.ringPolygons,
87
+ rotateVec3: () => import_core2.rotateVec3,
88
+ shadeColor: () => import_core2.shadeColor,
89
+ useGlyphcssAnimation: () => useGlyphcssAnimation,
90
+ useGlyphcssCamera: () => useGlyphcssCamera,
91
+ useGlyphcssMesh: () => useGlyphcssMesh,
92
+ useGlyphcssSceneContext: () => useGlyphcssSceneContext
93
+ });
94
+ module.exports = __toCommonJS(src_exports);
95
+ var import_core2 = require("@glyphcss/core");
96
+
97
+ // src/glyphcss/scene/GlyphcssScene.tsx
98
+ var import_react2 = require("react");
99
+ var import_glyphcss = require("glyphcss");
100
+
101
+ // src/glyphcss/scene/context.ts
102
+ var import_react = require("react");
103
+ var GlyphcssSceneContext = (0, import_react.createContext)(null);
104
+ function useGlyphcssSceneContext() {
105
+ const ctx = (0, import_react.useContext)(GlyphcssSceneContext);
106
+ if (!ctx) {
107
+ throw new Error("glyphcss: GlyphcssMesh must be used inside a GlyphcssScene.");
108
+ }
109
+ return ctx;
110
+ }
111
+ var GlyphcssMeshContext = (0, import_react.createContext)(null);
112
+
113
+ // src/glyphcss/scene/GlyphcssScene.tsx
114
+ var import_jsx_runtime = require("react/jsx-runtime");
115
+ function GlyphcssSceneInner({
116
+ mode,
117
+ glyphPalette,
118
+ useColors,
119
+ cols,
120
+ rows,
121
+ cellAspect,
122
+ directionalLight,
123
+ ambientLight,
124
+ className,
125
+ style,
126
+ children
127
+ }) {
128
+ const hostRef = (0, import_react2.useRef)(null);
129
+ const sceneRef = (0, import_react2.useRef)(null);
130
+ const initialOpts = (0, import_react2.useMemo)(() => ({
131
+ mode,
132
+ glyphPalette,
133
+ useColors,
134
+ cols,
135
+ rows,
136
+ cellAspect,
137
+ directionalLight,
138
+ ambientLight
139
+ }), []);
140
+ const hostCallbackRef = (0, import_react2.useCallback)((el) => {
141
+ if (el && !sceneRef.current) {
142
+ hostRef.current = el;
143
+ (0, import_glyphcss.injectGlyphcssBaseStyles)(el.ownerDocument ?? void 0);
144
+ sceneRef.current = (0, import_glyphcss.createGlyphcssScene)(el, initialOpts);
145
+ } else if (!el && sceneRef.current) {
146
+ sceneRef.current.destroy();
147
+ sceneRef.current = null;
148
+ hostRef.current = null;
149
+ }
150
+ }, [initialOpts]);
151
+ (0, import_react2.useEffect)(() => {
152
+ const scene = sceneRef.current;
153
+ if (!scene) return;
154
+ const partial = {};
155
+ if (mode !== void 0) partial.mode = mode;
156
+ if (glyphPalette !== void 0) partial.glyphPalette = glyphPalette;
157
+ if (useColors !== void 0) partial.useColors = useColors;
158
+ if (cols !== void 0) partial.cols = cols;
159
+ if (rows !== void 0) partial.rows = rows;
160
+ if (cellAspect !== void 0) partial.cellAspect = cellAspect;
161
+ if (directionalLight !== void 0) partial.directionalLight = directionalLight;
162
+ if (ambientLight !== void 0) partial.ambientLight = ambientLight;
163
+ if (Object.keys(partial).length > 0) {
164
+ scene.setOptions(partial);
165
+ }
166
+ }, [mode, glyphPalette, useColors, cols, rows, cellAspect, directionalLight, ambientLight]);
167
+ const ctxValue = (0, import_react2.useMemo)(() => ({ sceneRef }), [sceneRef]);
168
+ const computedClassName = `glyphcss-host${className ? ` ${className}` : ""}`;
169
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GlyphcssSceneContext.Provider, { value: ctxValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: hostCallbackRef, className: computedClassName, style, children }) });
170
+ }
171
+ var GlyphcssScene = (0, import_react2.memo)(GlyphcssSceneInner);
172
+
173
+ // src/glyphcss/scene/GlyphcssMesh.tsx
174
+ var import_react3 = require("react");
175
+
176
+ // src/glyphcss/scene/events.ts
177
+ var MESH_REGISTRY = /* @__PURE__ */ new WeakMap();
178
+ function registerMeshElement(el, handle) {
179
+ MESH_REGISTRY.set(el, handle);
180
+ }
181
+ function unregisterMeshElement(el) {
182
+ MESH_REGISTRY.delete(el);
183
+ }
184
+ function findGlyphcssMeshHandle(el) {
185
+ let cur = el;
186
+ while (cur) {
187
+ if (cur instanceof HTMLElement) {
188
+ const h = MESH_REGISTRY.get(cur);
189
+ if (h) return h;
190
+ }
191
+ cur = cur.parentElement;
192
+ }
193
+ return null;
194
+ }
195
+
196
+ // src/glyphcss/scene/GlyphcssMesh.tsx
197
+ var import_jsx_runtime2 = require("react/jsx-runtime");
198
+ function GlyphcssMeshInner({
199
+ id,
200
+ triangles: trianglesProp,
201
+ position,
202
+ scale,
203
+ rotation,
204
+ className,
205
+ style,
206
+ children
207
+ }) {
208
+ const { sceneRef } = useGlyphcssSceneContext();
209
+ const meshRef = (0, import_react3.useRef)(null);
210
+ const wrapperRef = (0, import_react3.useRef)(null);
211
+ const triangles = (0, import_react3.useMemo)(() => trianglesProp ?? [], [trianglesProp]);
212
+ const transform = (0, import_react3.useMemo)(() => ({
213
+ position,
214
+ scale,
215
+ rotation
216
+ }), [position, scale, rotation]);
217
+ (0, import_react3.useEffect)(() => {
218
+ const scene = sceneRef.current;
219
+ if (!scene) return;
220
+ const handle = scene.add(triangles, transform);
221
+ meshRef.current = handle;
222
+ return () => {
223
+ handle.dispose();
224
+ meshRef.current = null;
225
+ };
226
+ }, [sceneRef, triangles]);
227
+ (0, import_react3.useEffect)(() => {
228
+ const mesh = meshRef.current;
229
+ if (!mesh) return;
230
+ mesh.setTransform(transform);
231
+ sceneRef.current?.rerender();
232
+ }, [sceneRef, transform]);
233
+ (0, import_react3.useEffect)(() => {
234
+ const el = wrapperRef.current;
235
+ const handle = meshRef.current;
236
+ if (!el || !handle) return;
237
+ registerMeshElement(el, handle);
238
+ return () => unregisterMeshElement(el);
239
+ });
240
+ const computedClassName = `glyphcss-mesh${className ? ` ${className}` : ""}`;
241
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
242
+ "div",
243
+ {
244
+ ref: wrapperRef,
245
+ "data-glyphcss-mesh-id": id,
246
+ className: computedClassName,
247
+ style,
248
+ children
249
+ }
250
+ );
251
+ }
252
+ var GlyphcssMesh = (0, import_react3.memo)(GlyphcssMeshInner);
253
+
254
+ // src/glyphcss/scene/GlyphcssHotspot.tsx
255
+ var import_react4 = require("react");
256
+ var import_jsx_runtime3 = require("react/jsx-runtime");
257
+ function GlyphcssHotspotInner({
258
+ id,
259
+ at,
260
+ size,
261
+ onClick,
262
+ className,
263
+ children
264
+ }) {
265
+ const { sceneRef } = useGlyphcssSceneContext();
266
+ const hotspotRef = (0, import_react4.useRef)(null);
267
+ const onClickRef = (0, import_react4.useRef)(onClick);
268
+ onClickRef.current = onClick;
269
+ const atKey = (0, import_react4.useMemo)(() => at.join(","), [at]);
270
+ const sizeKey = size ? size.join(",") : "";
271
+ (0, import_react4.useEffect)(() => {
272
+ const scene = sceneRef.current;
273
+ if (!scene) return;
274
+ const handle = scene.addHotspot(
275
+ { id, at, size },
276
+ () => {
277
+ }
278
+ );
279
+ hotspotRef.current = handle;
280
+ return () => {
281
+ handle.remove();
282
+ hotspotRef.current = null;
283
+ };
284
+ }, [sceneRef, id, atKey, sizeKey]);
285
+ if (!children && !onClick && !className) return null;
286
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
287
+ "div",
288
+ {
289
+ "data-glyphcss-hotspot-id": id,
290
+ className,
291
+ style: { display: "contents" },
292
+ onClick,
293
+ children
294
+ }
295
+ );
296
+ }
297
+ var GlyphcssHotspot = (0, import_react4.memo)(GlyphcssHotspotInner);
298
+
299
+ // src/glyphcss/scene/useGlyphcssMesh.ts
300
+ var import_react5 = require("react");
301
+ function useGlyphcssMesh(triangles, options) {
302
+ const { sceneRef } = useGlyphcssSceneContext();
303
+ const meshRef = (0, import_react5.useRef)(null);
304
+ const [loading] = (0, import_react5.useState)(false);
305
+ (0, import_react5.useEffect)(() => {
306
+ const scene = sceneRef.current;
307
+ if (!scene) return;
308
+ const handle = scene.add(triangles, options?.transform);
309
+ meshRef.current = handle;
310
+ return () => {
311
+ handle.dispose();
312
+ meshRef.current = null;
313
+ };
314
+ }, [sceneRef, triangles]);
315
+ (0, import_react5.useEffect)(() => {
316
+ const mesh = meshRef.current;
317
+ if (!mesh) return;
318
+ if (options?.transform) {
319
+ mesh.setTransform(options.transform);
320
+ sceneRef.current?.rerender();
321
+ }
322
+ }, [sceneRef, options?.transform]);
323
+ return { meshRef, loading };
324
+ }
325
+
326
+ // src/glyphcss/camera/GlyphcssPerspectiveCamera.tsx
327
+ var import_react7 = require("react");
328
+ var import_glyphcss2 = require("glyphcss");
329
+
330
+ // src/glyphcss/camera/context.ts
331
+ var import_react6 = require("react");
332
+ var GlyphcssCameraContext = (0, import_react6.createContext)(null);
333
+ function useGlyphcssCamera() {
334
+ const ctx = (0, import_react6.useContext)(GlyphcssCameraContext);
335
+ if (!ctx) {
336
+ throw new Error("glyphcss: camera hook must be used inside a GlyphcssCamera.");
337
+ }
338
+ return ctx;
339
+ }
340
+
341
+ // src/glyphcss/camera/GlyphcssPerspectiveCamera.tsx
342
+ var import_jsx_runtime4 = require("react/jsx-runtime");
343
+ function GlyphcssPerspectiveCameraInner({
344
+ rotX,
345
+ rotY,
346
+ distance,
347
+ scale,
348
+ stretch,
349
+ center,
350
+ children
351
+ }) {
352
+ const { sceneRef } = useGlyphcssSceneContext();
353
+ const cameraRef = (0, import_react7.useRef)(null);
354
+ if (!cameraRef.current) {
355
+ const opts = {};
356
+ if (rotX !== void 0) opts.rotX = rotX;
357
+ if (rotY !== void 0) opts.rotY = rotY;
358
+ if (distance !== void 0) opts.distance = distance;
359
+ if (scale !== void 0) opts.scale = scale;
360
+ if (stretch !== void 0) opts.stretch = stretch;
361
+ if (center !== void 0) opts.center = center;
362
+ cameraRef.current = (0, import_glyphcss2.createGlyphcssPerspectiveCamera)(opts);
363
+ }
364
+ (0, import_react7.useEffect)(() => {
365
+ const scene = sceneRef.current;
366
+ if (!scene || !cameraRef.current) return;
367
+ scene.setOptions({ camera: cameraRef.current });
368
+ scene.rerender();
369
+ }, [sceneRef]);
370
+ (0, import_react7.useEffect)(() => {
371
+ const camera = cameraRef.current;
372
+ if (!camera) return;
373
+ let dirty = false;
374
+ if (rotX !== void 0 && camera.rotX !== rotX) {
375
+ camera.rotX = rotX;
376
+ dirty = true;
377
+ }
378
+ if (rotY !== void 0 && camera.rotY !== rotY) {
379
+ camera.rotY = rotY;
380
+ dirty = true;
381
+ }
382
+ if (distance !== void 0 && camera.distance !== distance) {
383
+ camera.distance = distance;
384
+ dirty = true;
385
+ }
386
+ if (scale !== void 0 && camera.scale !== scale) {
387
+ camera.scale = scale;
388
+ dirty = true;
389
+ }
390
+ if (stretch !== void 0 && camera.stretch !== stretch) {
391
+ camera.stretch = stretch;
392
+ dirty = true;
393
+ }
394
+ if (dirty) {
395
+ sceneRef.current?.rerender();
396
+ }
397
+ });
398
+ const rerender = () => sceneRef.current?.rerender();
399
+ const ctxValue = (0, import_react7.useMemo)(() => ({ cameraRef, rerender }), [cameraRef]);
400
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(GlyphcssCameraContext.Provider, { value: ctxValue, children });
401
+ }
402
+ var GlyphcssPerspectiveCamera = (0, import_react7.memo)(GlyphcssPerspectiveCameraInner);
403
+
404
+ // src/glyphcss/camera/GlyphcssOrthographicCamera.tsx
405
+ var import_react8 = require("react");
406
+ var import_glyphcss3 = require("glyphcss");
407
+ var import_jsx_runtime5 = require("react/jsx-runtime");
408
+ function GlyphcssOrthographicCameraInner({
409
+ rotX,
410
+ rotY,
411
+ zoom,
412
+ center,
413
+ children
414
+ }) {
415
+ const { sceneRef } = useGlyphcssSceneContext();
416
+ const cameraRef = (0, import_react8.useRef)(null);
417
+ if (!cameraRef.current) {
418
+ const opts = {};
419
+ if (rotX !== void 0) opts.rotX = rotX;
420
+ if (rotY !== void 0) opts.rotY = rotY;
421
+ if (zoom !== void 0) opts.zoom = zoom;
422
+ if (center !== void 0) opts.center = center;
423
+ cameraRef.current = (0, import_glyphcss3.createGlyphcssOrthographicCamera)(opts);
424
+ }
425
+ (0, import_react8.useEffect)(() => {
426
+ const scene = sceneRef.current;
427
+ if (!scene || !cameraRef.current) return;
428
+ scene.setOptions({ camera: cameraRef.current });
429
+ scene.rerender();
430
+ }, [sceneRef]);
431
+ (0, import_react8.useEffect)(() => {
432
+ const camera = cameraRef.current;
433
+ if (!camera) return;
434
+ let dirty = false;
435
+ if (rotX !== void 0 && camera.rotX !== rotX) {
436
+ camera.rotX = rotX;
437
+ dirty = true;
438
+ }
439
+ if (rotY !== void 0 && camera.rotY !== rotY) {
440
+ camera.rotY = rotY;
441
+ dirty = true;
442
+ }
443
+ if (zoom !== void 0 && camera.scale !== zoom) {
444
+ camera.scale = zoom;
445
+ dirty = true;
446
+ }
447
+ if (dirty) sceneRef.current?.rerender();
448
+ });
449
+ const rerender = () => sceneRef.current?.rerender();
450
+ const ctxValue = (0, import_react8.useMemo)(() => ({ cameraRef, rerender }), [cameraRef]);
451
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(GlyphcssCameraContext.Provider, { value: ctxValue, children });
452
+ }
453
+ var GlyphcssOrthographicCamera = (0, import_react8.memo)(GlyphcssOrthographicCameraInner);
454
+
455
+ // src/glyphcss/camera/useGlyphcssCamera.ts
456
+ var import_react9 = require("react");
457
+ var import_glyphcss4 = require("glyphcss");
458
+
459
+ // src/glyphcss/controls/GlyphcssOrbitControls.tsx
460
+ var import_react10 = require("react");
461
+ var import_glyphcss5 = require("glyphcss");
462
+ function GlyphcssOrbitControls({
463
+ drag = true,
464
+ wheel = true,
465
+ invert = false,
466
+ animate = false
467
+ }) {
468
+ const { sceneRef } = useGlyphcssSceneContext();
469
+ const controlsRef = (0, import_react10.useRef)(null);
470
+ const propsRef = (0, import_react10.useRef)({ drag, wheel, invert, animate });
471
+ propsRef.current = { drag, wheel, invert, animate };
472
+ (0, import_react10.useEffect)(() => {
473
+ const scene = sceneRef.current;
474
+ if (!scene) return;
475
+ const opts = {
476
+ drag: propsRef.current.drag,
477
+ wheel: propsRef.current.wheel,
478
+ invert: propsRef.current.invert,
479
+ animate: propsRef.current.animate === false ? false : propsRef.current.animate
480
+ };
481
+ const controls = (0, import_glyphcss5.createGlyphcssOrbitControls)(scene, opts);
482
+ controlsRef.current = controls;
483
+ return () => {
484
+ controls.destroy();
485
+ controlsRef.current = null;
486
+ };
487
+ }, [sceneRef]);
488
+ (0, import_react10.useEffect)(() => {
489
+ const controls = controlsRef.current;
490
+ if (!controls) return;
491
+ controls.update({ drag, wheel, invert, animate: animate === false ? false : animate });
492
+ });
493
+ return null;
494
+ }
495
+
496
+ // src/glyphcss/controls/GlyphcssMapControls.tsx
497
+ var import_react11 = require("react");
498
+ var import_glyphcss6 = require("glyphcss");
499
+ function GlyphcssMapControls({
500
+ drag = true,
501
+ wheel = true,
502
+ invert = false,
503
+ animate = false
504
+ }) {
505
+ const { sceneRef } = useGlyphcssSceneContext();
506
+ const controlsRef = (0, import_react11.useRef)(null);
507
+ const propsRef = (0, import_react11.useRef)({ drag, wheel, invert, animate });
508
+ propsRef.current = { drag, wheel, invert, animate };
509
+ (0, import_react11.useEffect)(() => {
510
+ const scene = sceneRef.current;
511
+ if (!scene) return;
512
+ const opts = {
513
+ drag: propsRef.current.drag,
514
+ wheel: propsRef.current.wheel,
515
+ invert: propsRef.current.invert,
516
+ animate: propsRef.current.animate === false ? false : propsRef.current.animate
517
+ };
518
+ const controls = (0, import_glyphcss6.createGlyphcssMapControls)(scene, opts);
519
+ controlsRef.current = controls;
520
+ return () => {
521
+ controls.destroy();
522
+ controlsRef.current = null;
523
+ };
524
+ }, [sceneRef]);
525
+ (0, import_react11.useEffect)(() => {
526
+ const controls = controlsRef.current;
527
+ if (!controls) return;
528
+ controls.update({ drag, wheel, invert, animate: animate === false ? false : animate });
529
+ });
530
+ return null;
531
+ }
532
+
533
+ // src/glyphcss/controls/GlyphcssFirstPersonControls.tsx
534
+ var import_react12 = require("react");
535
+ var import_glyphcss7 = require("glyphcss");
536
+ function GlyphcssFirstPersonControls({
537
+ drag = true,
538
+ keyboard = true,
539
+ moveSpeed = 0.05,
540
+ lookSpeed = 4e-3,
541
+ invert = false
542
+ }) {
543
+ const { sceneRef } = useGlyphcssSceneContext();
544
+ const controlsRef = (0, import_react12.useRef)(null);
545
+ const propsRef = (0, import_react12.useRef)({ drag, keyboard, moveSpeed, lookSpeed, invert });
546
+ propsRef.current = { drag, keyboard, moveSpeed, lookSpeed, invert };
547
+ (0, import_react12.useEffect)(() => {
548
+ const scene = sceneRef.current;
549
+ if (!scene) return;
550
+ const opts = {
551
+ drag: propsRef.current.drag,
552
+ keyboard: propsRef.current.keyboard,
553
+ moveSpeed: propsRef.current.moveSpeed,
554
+ lookSpeed: propsRef.current.lookSpeed,
555
+ invert: propsRef.current.invert
556
+ };
557
+ const controls = (0, import_glyphcss7.createGlyphcssFirstPersonControls)(scene, opts);
558
+ controlsRef.current = controls;
559
+ return () => {
560
+ controls.destroy();
561
+ controlsRef.current = null;
562
+ };
563
+ }, [sceneRef]);
564
+ (0, import_react12.useEffect)(() => {
565
+ const controls = controlsRef.current;
566
+ if (!controls) return;
567
+ controls.update({ drag, keyboard, moveSpeed, lookSpeed, invert });
568
+ });
569
+ return null;
570
+ }
571
+
572
+ // src/glyphcss/helpers/GlyphcssAxesHelper.tsx
573
+ var import_react13 = require("react");
574
+ function axisTriangles(size) {
575
+ const s = size;
576
+ const t = s * 0.05;
577
+ const triangles = [];
578
+ function addBar(a, b, color) {
579
+ const v0 = [a[0] - t, a[1] - t, a[2]];
580
+ const v1 = [b[0] - t, b[1] - t, b[2]];
581
+ const v2 = [b[0] + t, b[1] + t, b[2]];
582
+ const v3 = [a[0] + t, a[1] + t, a[2]];
583
+ triangles.push({ vertices: [v0, v1, v2], color });
584
+ triangles.push({ vertices: [v0, v2, v3], color });
585
+ }
586
+ addBar([0, 0, 0], [s, 0, 0], "#ff0000");
587
+ addBar([0, 0, 0], [0, s, 0], "#00ff00");
588
+ addBar([0, 0, 0], [0, 0, s], "#0000ff");
589
+ return triangles;
590
+ }
591
+ function GlyphcssAxesHelperInner({ size = 1 }) {
592
+ const { sceneRef } = useGlyphcssSceneContext();
593
+ const meshRef = (0, import_react13.useRef)(null);
594
+ const triangles = (0, import_react13.useMemo)(() => axisTriangles(size), [size]);
595
+ (0, import_react13.useEffect)(() => {
596
+ const scene = sceneRef.current;
597
+ if (!scene) return;
598
+ const handle = scene.add(triangles);
599
+ meshRef.current = handle;
600
+ return () => {
601
+ handle.dispose();
602
+ meshRef.current = null;
603
+ };
604
+ }, [sceneRef, triangles]);
605
+ return null;
606
+ }
607
+ var GlyphcssAxesHelper = (0, import_react13.memo)(GlyphcssAxesHelperInner);
608
+
609
+ // src/glyphcss/helpers/GlyphcssDirectionalLightHelper.tsx
610
+ var import_react14 = require("react");
611
+ function lightMarkerTriangles(position, color, size) {
612
+ const [px, py, pz] = position;
613
+ const s = size;
614
+ const top = [px, py, pz + s];
615
+ const bot = [px, py, pz - s];
616
+ const right = [px + s, py, pz];
617
+ const left = [px - s, py, pz];
618
+ const front = [px, py + s, pz];
619
+ const back = [px, py - s, pz];
620
+ return [
621
+ { vertices: [top, right, front], color },
622
+ { vertices: [top, front, left], color },
623
+ { vertices: [top, left, back], color },
624
+ { vertices: [top, back, right], color },
625
+ { vertices: [bot, front, right], color },
626
+ { vertices: [bot, left, front], color },
627
+ { vertices: [bot, back, left], color },
628
+ { vertices: [bot, right, back], color }
629
+ ];
630
+ }
631
+ function GlyphcssDirectionalLightHelperInner({
632
+ position = [1, 1, 1],
633
+ color = "#ffff00",
634
+ size = 0.1
635
+ }) {
636
+ const { sceneRef } = useGlyphcssSceneContext();
637
+ const meshRef = (0, import_react14.useRef)(null);
638
+ const triangles = (0, import_react14.useMemo)(
639
+ () => lightMarkerTriangles(position, color, size),
640
+ [position, color, size]
641
+ );
642
+ (0, import_react14.useEffect)(() => {
643
+ const scene = sceneRef.current;
644
+ if (!scene) return;
645
+ const handle = scene.add(triangles);
646
+ meshRef.current = handle;
647
+ return () => {
648
+ handle.dispose();
649
+ meshRef.current = null;
650
+ };
651
+ }, [sceneRef, triangles]);
652
+ return null;
653
+ }
654
+ var GlyphcssDirectionalLightHelper = (0, import_react14.memo)(GlyphcssDirectionalLightHelperInner);
655
+
656
+ // src/glyphcss/styles/index.ts
657
+ var import_glyphcss8 = require("glyphcss");
658
+
659
+ // src/animation/useGlyphcssAnimation.ts
660
+ var import_react15 = require("react");
661
+ var import_core = require("@glyphcss/core");
662
+ function resolveRoot(rootArg) {
663
+ if (!rootArg) return null;
664
+ if ("current" in rootArg) return rootArg.current;
665
+ return rootArg;
666
+ }
667
+ function useGlyphcssAnimation(clips, controller, root) {
668
+ const internalRef = (0, import_react15.useRef)(null);
669
+ const mixerRef = (0, import_react15.useRef)(null);
670
+ (0, import_react15.useEffect)(() => {
671
+ if (!clips || clips.length === 0 || !controller) {
672
+ mixerRef.current = null;
673
+ return;
674
+ }
675
+ const resolvedRoot = resolveRoot(root) ?? internalRef.current;
676
+ if (!resolvedRoot) {
677
+ mixerRef.current = null;
678
+ return;
679
+ }
680
+ mixerRef.current = (0, import_core.createGlyphcssAnimationMixer)(resolvedRoot, controller);
681
+ return () => {
682
+ mixerRef.current?.stopAllAction();
683
+ mixerRef.current?.uncacheRoot();
684
+ mixerRef.current = null;
685
+ };
686
+ }, [clips, controller]);
687
+ (0, import_react15.useEffect)(() => {
688
+ if (!clips || clips.length === 0 || !controller) return;
689
+ let rafId;
690
+ let lastTime = null;
691
+ function tick(now) {
692
+ if (lastTime === null) {
693
+ lastTime = now;
694
+ rafId = requestAnimationFrame(tick);
695
+ return;
696
+ }
697
+ const dt = (now - lastTime) / 1e3;
698
+ lastTime = now;
699
+ mixerRef.current?.update(dt);
700
+ rafId = requestAnimationFrame(tick);
701
+ }
702
+ rafId = requestAnimationFrame(tick);
703
+ return () => {
704
+ cancelAnimationFrame(rafId);
705
+ lastTime = null;
706
+ };
707
+ }, [clips, controller]);
708
+ const resolvedClips = clips ?? [];
709
+ const resolvedNames = resolvedClips.map((c) => c.name);
710
+ const actions = (0, import_react15.useMemo)(() => {
711
+ const target = {};
712
+ for (const clip of resolvedClips) {
713
+ Object.defineProperty(target, clip.name, {
714
+ enumerable: true,
715
+ get() {
716
+ const m = mixerRef.current;
717
+ if (!m) return null;
718
+ try {
719
+ return m.clipAction(clip.name);
720
+ } catch {
721
+ return null;
722
+ }
723
+ }
724
+ });
725
+ }
726
+ return target;
727
+ }, [resolvedClips]);
728
+ return {
729
+ ref: internalRef,
730
+ mixer: mixerRef.current,
731
+ clips: resolvedClips,
732
+ names: resolvedNames,
733
+ actions
734
+ };
735
+ }
736
+ // Annotate the CommonJS export names for ESM import in node:
737
+ 0 && (module.exports = {
738
+ BASE_TILE,
739
+ CAMERA_BACKFACE_CULL_EPS,
740
+ DEFAULT_CAMERA_STATE,
741
+ DEFAULT_PROJECTION,
742
+ GlyphcssAxesHelper,
743
+ GlyphcssCamera,
744
+ GlyphcssCameraContext,
745
+ GlyphcssDirectionalLightHelper,
746
+ GlyphcssFirstPersonControls,
747
+ GlyphcssHotspot,
748
+ GlyphcssMapControls,
749
+ GlyphcssMesh,
750
+ GlyphcssOrbitControls,
751
+ GlyphcssOrthographicCamera,
752
+ GlyphcssPerspectiveCamera,
753
+ GlyphcssScene,
754
+ GlyphcssSceneContext,
755
+ LoopOnce,
756
+ LoopPingPong,
757
+ LoopRepeat,
758
+ VOXEL_CAMERA_CULL_AXIS_EPS,
759
+ VOXEL_CAMERA_CULL_NORMAL_LIMIT,
760
+ arrowPolygons,
761
+ axesHelperPolygons,
762
+ bakeSolidTextureSampledPolygons,
763
+ bakeSolidTextureSamples,
764
+ buildSceneContext,
765
+ cameraCullNormalGroups,
766
+ cameraCullNormalGroupsFromPolygons,
767
+ cameraCullNormalKey,
768
+ cameraCullVisibleSignature,
769
+ cameraFacingDepth,
770
+ clampChannel,
771
+ computeSceneBbox,
772
+ computeShapeLighting,
773
+ coverPlanarPolygons,
774
+ createGlyphcssAnimationMixer,
775
+ createIsometricCamera,
776
+ cullInteriorPolygons,
777
+ findGlyphcssMeshHandle,
778
+ formatColor,
779
+ injectGlyphcssBaseStyles,
780
+ inverseRotateVec3,
781
+ isAxisAlignedSurfaceNormal,
782
+ isVoxelCameraCullableNormalGroups,
783
+ loadMesh,
784
+ mergePolygons,
785
+ normalFacesCamera,
786
+ normalizeInvertMultiplier,
787
+ normalizePolygons,
788
+ octahedronPolygons,
789
+ optimizeMeshPolygons,
790
+ parseColor,
791
+ parseGltf,
792
+ parseHexColor,
793
+ parseMtl,
794
+ parseObj,
795
+ parsePureColor,
796
+ parseRgbColor,
797
+ parseVox,
798
+ polygonCssSurfaceNormal,
799
+ polygonFaces,
800
+ polygonFacesCamera,
801
+ ringPolygons,
802
+ rotateVec3,
803
+ shadeColor,
804
+ useGlyphcssAnimation,
805
+ useGlyphcssCamera,
806
+ useGlyphcssMesh,
807
+ useGlyphcssSceneContext
808
+ });