@glyphcss/react 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -37,41 +37,107 @@ import {
37
37
  shadeColor,
38
38
  rotateVec3,
39
39
  inverseRotateVec3,
40
- axesHelperPolygons,
41
- arrowPolygons,
42
- ringPolygons,
40
+ resolveGeometry as resolveGeometry2,
41
+ tetrahedronPolygons,
42
+ cubePolygons,
43
43
  octahedronPolygons,
44
+ dodecahedronPolygons,
45
+ icosahedronPolygons,
46
+ smallStellatedDodecahedronPolygons,
47
+ greatDodecahedronPolygons,
48
+ greatStellatedDodecahedronPolygons,
49
+ greatIcosahedronPolygons,
50
+ cuboctahedronPolygons,
51
+ icosidodecahedronPolygons,
52
+ truncatedTetrahedronPolygons,
53
+ truncatedCubePolygons,
54
+ truncatedOctahedronPolygons,
55
+ truncatedDodecahedronPolygons,
56
+ truncatedIcosahedronPolygons,
57
+ truncatedCuboctahedronPolygons,
58
+ truncatedIcosidodecahedronPolygons,
59
+ rhombicuboctahedronPolygons,
60
+ rhombicosidodecahedronPolygons,
61
+ snubCubePolygons,
62
+ snubDodecahedronPolygons,
63
+ rhombicDodecahedronPolygons,
64
+ rhombicTriacontahedronPolygons,
65
+ triakisTetrahedronPolygons,
66
+ triakisOctahedronPolygons,
67
+ triakisIcosahedronPolygons,
68
+ tetrakisHexahedronPolygons,
69
+ pentakisDodecahedronPolygons,
70
+ disdyakisDodecahedronPolygons,
71
+ disdyakisTriacontahedronPolygons,
72
+ deltoidalIcositetrahedronPolygons,
73
+ deltoidalHexecontahedronPolygons,
74
+ pentagonalIcositetrahedronPolygons,
75
+ pentagonalHexecontahedronPolygons,
76
+ prismPolygons,
77
+ antiprismPolygons,
78
+ bipyramidPolygons,
79
+ trapezohedronPolygons,
80
+ spherePolygons,
81
+ cylinderPolygons,
82
+ conePolygons,
83
+ torusPolygons,
84
+ pyramidPolygons,
85
+ planePolygons as planePolygons2,
86
+ ringPolygons,
87
+ ringQuadPolygons,
88
+ arrowPolygons,
89
+ axesHelperPolygons,
44
90
  buildSceneContext,
45
91
  computeSceneBbox,
46
92
  BASE_TILE,
47
93
  DEFAULT_CAMERA_STATE,
48
94
  DEFAULT_PROJECTION,
49
95
  normalizeInvertMultiplier,
50
- createGlyphcssAnimationMixer as createGlyphcssAnimationMixer2,
96
+ createGlyphAnimationMixer as createGlyphAnimationMixer2,
51
97
  LoopOnce,
52
98
  LoopRepeat,
53
99
  LoopPingPong
54
100
  } from "@glyphcss/core";
55
101
 
56
- // src/glyphcss/scene/GlyphcssScene.tsx
102
+ // src/glyphcss/scene/GlyphScene.tsx
57
103
  import { memo, useCallback, useEffect, useMemo, useRef } from "react";
58
- import { createGlyphcssScene, injectGlyphcssBaseStyles } from "glyphcss";
104
+ import { createGlyphScene, injectGlyphBaseStyles } from "glyphcss";
59
105
 
60
- // src/glyphcss/scene/context.ts
106
+ // src/glyphcss/camera/context.ts
61
107
  import { createContext, useContext } from "react";
62
- var GlyphcssSceneContext = createContext(null);
63
- function useGlyphcssSceneContext() {
64
- const ctx = useContext(GlyphcssSceneContext);
108
+ var GlyphCameraContext = createContext(null);
109
+ function useGlyphCamera() {
110
+ const ctx = useContext(GlyphCameraContext);
111
+ if (!ctx) {
112
+ throw new Error("glyphcss: camera hook must be used inside a GlyphCamera.");
113
+ }
114
+ return ctx;
115
+ }
116
+ function useGlyphCameraContext() {
117
+ const ctx = useContext(GlyphCameraContext);
118
+ if (!ctx) {
119
+ throw new Error(
120
+ "glyphcss: GlyphScene must be placed inside a GlyphPerspectiveCamera or GlyphOrthographicCamera."
121
+ );
122
+ }
123
+ return ctx;
124
+ }
125
+
126
+ // src/glyphcss/scene/context.ts
127
+ import { createContext as createContext2, useContext as useContext2 } from "react";
128
+ var GlyphSceneContext = createContext2(null);
129
+ function useGlyphSceneContext() {
130
+ const ctx = useContext2(GlyphSceneContext);
65
131
  if (!ctx) {
66
- throw new Error("glyphcss: GlyphcssMesh must be used inside a GlyphcssScene.");
132
+ throw new Error("glyphcss: component must be used inside a GlyphScene.");
67
133
  }
68
134
  return ctx;
69
135
  }
70
- var GlyphcssMeshContext = createContext(null);
136
+ var GlyphMeshContext = createContext2(null);
71
137
 
72
- // src/glyphcss/scene/GlyphcssScene.tsx
138
+ // src/glyphcss/scene/GlyphScene.tsx
73
139
  import { jsx } from "react/jsx-runtime";
74
- function GlyphcssSceneInner({
140
+ function GlyphSceneInner({
75
141
  mode,
76
142
  glyphPalette,
77
143
  useColors,
@@ -80,10 +146,14 @@ function GlyphcssSceneInner({
80
146
  cellAspect,
81
147
  directionalLight,
82
148
  ambientLight,
149
+ smoothShading,
150
+ creaseAngle,
151
+ autoSize,
83
152
  className,
84
153
  style,
85
154
  children
86
155
  }) {
156
+ const { cameraRef, sceneRerenderRef } = useGlyphCameraContext();
87
157
  const hostRef = useRef(null);
88
158
  const sceneRef = useRef(null);
89
159
  const initialOpts = useMemo(() => ({
@@ -94,19 +164,26 @@ function GlyphcssSceneInner({
94
164
  rows,
95
165
  cellAspect,
96
166
  directionalLight,
97
- ambientLight
167
+ ambientLight,
168
+ smoothShading,
169
+ creaseAngle,
170
+ autoSize,
171
+ camera: cameraRef.current ?? void 0
98
172
  }), []);
99
173
  const hostCallbackRef = useCallback((el) => {
100
174
  if (el && !sceneRef.current) {
101
175
  hostRef.current = el;
102
- injectGlyphcssBaseStyles(el.ownerDocument ?? void 0);
103
- sceneRef.current = createGlyphcssScene(el, initialOpts);
176
+ injectGlyphBaseStyles(el.ownerDocument ?? void 0);
177
+ const camera = cameraRef.current ?? void 0;
178
+ sceneRef.current = createGlyphScene(el, { ...initialOpts, camera });
179
+ sceneRerenderRef.current = () => sceneRef.current?.rerender();
104
180
  } else if (!el && sceneRef.current) {
105
181
  sceneRef.current.destroy();
106
182
  sceneRef.current = null;
183
+ sceneRerenderRef.current = null;
107
184
  hostRef.current = null;
108
185
  }
109
- }, [initialOpts]);
186
+ }, [initialOpts, cameraRef, sceneRerenderRef]);
110
187
  useEffect(() => {
111
188
  const scene = sceneRef.current;
112
189
  if (!scene) return;
@@ -119,18 +196,22 @@ function GlyphcssSceneInner({
119
196
  if (cellAspect !== void 0) partial.cellAspect = cellAspect;
120
197
  if (directionalLight !== void 0) partial.directionalLight = directionalLight;
121
198
  if (ambientLight !== void 0) partial.ambientLight = ambientLight;
199
+ if (smoothShading !== void 0) partial.smoothShading = smoothShading;
200
+ if (creaseAngle !== void 0) partial.creaseAngle = creaseAngle;
201
+ if (autoSize !== void 0) partial.autoSize = autoSize;
122
202
  if (Object.keys(partial).length > 0) {
123
203
  scene.setOptions(partial);
124
204
  }
125
- }, [mode, glyphPalette, useColors, cols, rows, cellAspect, directionalLight, ambientLight]);
205
+ }, [mode, glyphPalette, useColors, cols, rows, cellAspect, directionalLight, ambientLight, smoothShading, creaseAngle, autoSize]);
126
206
  const ctxValue = useMemo(() => ({ sceneRef }), [sceneRef]);
127
- const computedClassName = `glyphcss-host${className ? ` ${className}` : ""}`;
128
- return /* @__PURE__ */ jsx(GlyphcssSceneContext.Provider, { value: ctxValue, children: /* @__PURE__ */ jsx("div", { ref: hostCallbackRef, className: computedClassName, style, children }) });
207
+ const computedClassName = `glyph-host${className ? ` ${className}` : ""}`;
208
+ return /* @__PURE__ */ jsx(GlyphSceneContext.Provider, { value: ctxValue, children: /* @__PURE__ */ jsx("div", { ref: hostCallbackRef, className: computedClassName, style, children }) });
129
209
  }
130
- var GlyphcssScene = memo(GlyphcssSceneInner);
210
+ var GlyphScene = memo(GlyphSceneInner);
131
211
 
132
- // src/glyphcss/scene/GlyphcssMesh.tsx
212
+ // src/glyphcss/scene/GlyphMesh.tsx
133
213
  import { memo as memo2, useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2 } from "react";
214
+ import { resolveGeometry } from "@glyphcss/core";
134
215
 
135
216
  // src/glyphcss/scene/events.ts
136
217
  var MESH_REGISTRY = /* @__PURE__ */ new WeakMap();
@@ -140,7 +221,7 @@ function registerMeshElement(el, handle) {
140
221
  function unregisterMeshElement(el) {
141
222
  MESH_REGISTRY.delete(el);
142
223
  }
143
- function findGlyphcssMeshHandle(el) {
224
+ function findGlyphMeshHandle(el) {
144
225
  let cur = el;
145
226
  while (cur) {
146
227
  if (cur instanceof HTMLElement) {
@@ -151,12 +232,33 @@ function findGlyphcssMeshHandle(el) {
151
232
  }
152
233
  return null;
153
234
  }
235
+ function pointInMeshElement(meshEl, clientX, clientY) {
236
+ const r = meshEl.getBoundingClientRect();
237
+ if (r.width <= 0 || r.height <= 0) return false;
238
+ return clientX >= r.left && clientX <= r.right && clientY >= r.top && clientY <= r.bottom;
239
+ }
240
+ function findMeshUnderPoint(clientX, clientY, filter) {
241
+ if (typeof document === "undefined") return null;
242
+ const meshEls = Array.from(
243
+ document.querySelectorAll(".glyph-mesh")
244
+ );
245
+ for (const meshEl of meshEls) {
246
+ if (filter && !filter(meshEl)) continue;
247
+ const handle = findGlyphMeshHandle(meshEl);
248
+ if (!handle) continue;
249
+ if (pointInMeshElement(meshEl, clientX, clientY)) return handle;
250
+ }
251
+ return null;
252
+ }
154
253
 
155
- // src/glyphcss/scene/GlyphcssMesh.tsx
254
+ // src/glyphcss/scene/GlyphMesh.tsx
156
255
  import { jsx as jsx2 } from "react/jsx-runtime";
157
- function GlyphcssMeshInner({
256
+ function GlyphMeshInner({
158
257
  id,
159
- triangles: trianglesProp,
258
+ polygons: polygonsProp,
259
+ geometry,
260
+ size = 1,
261
+ color,
160
262
  position,
161
263
  scale,
162
264
  rotation,
@@ -164,25 +266,30 @@ function GlyphcssMeshInner({
164
266
  style,
165
267
  children
166
268
  }) {
167
- const { sceneRef } = useGlyphcssSceneContext();
269
+ const { sceneRef } = useGlyphSceneContext();
168
270
  const meshRef = useRef2(null);
169
271
  const wrapperRef = useRef2(null);
170
- const triangles = useMemo2(() => trianglesProp ?? [], [trianglesProp]);
272
+ const polygons = useMemo2(() => {
273
+ if (polygonsProp !== void 0) return polygonsProp;
274
+ if (geometry !== void 0) return resolveGeometry(geometry, { size, color });
275
+ return [];
276
+ }, [polygonsProp, geometry, size, color]);
171
277
  const transform = useMemo2(() => ({
278
+ id,
172
279
  position,
173
280
  scale,
174
281
  rotation
175
- }), [position, scale, rotation]);
282
+ }), [id, position, scale, rotation]);
176
283
  useEffect2(() => {
177
284
  const scene = sceneRef.current;
178
285
  if (!scene) return;
179
- const handle = scene.add(triangles, transform);
286
+ const handle = scene.add(polygons, transform);
180
287
  meshRef.current = handle;
181
288
  return () => {
182
289
  handle.dispose();
183
290
  meshRef.current = null;
184
291
  };
185
- }, [sceneRef, triangles]);
292
+ }, [sceneRef, polygons]);
186
293
  useEffect2(() => {
187
294
  const mesh = meshRef.current;
188
295
  if (!mesh) return;
@@ -196,24 +303,60 @@ function GlyphcssMeshInner({
196
303
  registerMeshElement(el, handle);
197
304
  return () => unregisterMeshElement(el);
198
305
  });
199
- const computedClassName = `glyphcss-mesh${className ? ` ${className}` : ""}`;
306
+ const computedClassName = `glyph-mesh${className ? ` ${className}` : ""}`;
200
307
  return /* @__PURE__ */ jsx2(
201
308
  "div",
202
309
  {
203
310
  ref: wrapperRef,
204
- "data-glyphcss-mesh-id": id,
311
+ "data-glyph-mesh-id": id,
205
312
  className: computedClassName,
206
313
  style,
207
314
  children
208
315
  }
209
316
  );
210
317
  }
211
- var GlyphcssMesh = memo2(GlyphcssMeshInner);
318
+ var GlyphMesh = memo2(GlyphMeshInner);
212
319
 
213
- // src/glyphcss/scene/GlyphcssHotspot.tsx
214
- import { memo as memo3, useEffect as useEffect3, useMemo as useMemo3, useRef as useRef3 } from "react";
320
+ // src/glyphcss/scene/GlyphGround.tsx
321
+ import { memo as memo3, useMemo as useMemo3 } from "react";
322
+ import { planePolygons } from "@glyphcss/core";
215
323
  import { jsx as jsx3 } from "react/jsx-runtime";
216
- function GlyphcssHotspotInner({
324
+ function GlyphGroundInner({
325
+ size = 5,
326
+ color = "#444444",
327
+ position = [0, -0.5, 0],
328
+ rotation,
329
+ id,
330
+ className,
331
+ style
332
+ }) {
333
+ const polygons = useMemo3(
334
+ () => planePolygons({
335
+ axis: 1,
336
+ size,
337
+ offset: 0,
338
+ color
339
+ }),
340
+ [size, color]
341
+ );
342
+ return /* @__PURE__ */ jsx3(
343
+ GlyphMesh,
344
+ {
345
+ id,
346
+ polygons,
347
+ position,
348
+ rotation,
349
+ className,
350
+ style
351
+ }
352
+ );
353
+ }
354
+ var GlyphGround = memo3(GlyphGroundInner);
355
+
356
+ // src/glyphcss/scene/GlyphHotspot.tsx
357
+ import { memo as memo4, useEffect as useEffect3, useMemo as useMemo4, useRef as useRef3, useState } from "react";
358
+ import { createPortal } from "react-dom";
359
+ function GlyphHotspotInner({
217
360
  id,
218
361
  at,
219
362
  size,
@@ -221,56 +364,60 @@ function GlyphcssHotspotInner({
221
364
  className,
222
365
  children
223
366
  }) {
224
- const { sceneRef } = useGlyphcssSceneContext();
367
+ const { sceneRef } = useGlyphSceneContext();
225
368
  const hotspotRef = useRef3(null);
226
369
  const onClickRef = useRef3(onClick);
227
370
  onClickRef.current = onClick;
228
- const atKey = useMemo3(() => at.join(","), [at]);
371
+ const [overlayEl, setOverlayEl] = useState(null);
372
+ const atKey = useMemo4(() => at.join(","), [at]);
229
373
  const sizeKey = size ? size.join(",") : "";
230
374
  useEffect3(() => {
231
375
  const scene = sceneRef.current;
232
376
  if (!scene) return;
233
377
  const handle = scene.addHotspot(
234
378
  { id, at, size },
235
- () => {
236
- }
379
+ () => onClickRef.current?.({})
237
380
  );
238
381
  hotspotRef.current = handle;
382
+ setOverlayEl(handle.el);
239
383
  return () => {
240
384
  handle.remove();
241
385
  hotspotRef.current = null;
386
+ setOverlayEl(null);
242
387
  };
243
388
  }, [sceneRef, id, atKey, sizeKey]);
244
- if (!children && !onClick && !className) return null;
245
- return /* @__PURE__ */ jsx3(
246
- "div",
247
- {
248
- "data-glyphcss-hotspot-id": id,
249
- className,
250
- style: { display: "contents" },
251
- onClick,
252
- children
253
- }
254
- );
389
+ useEffect3(() => {
390
+ const el = overlayEl;
391
+ if (!el || !onClick) return;
392
+ const handler = (e) => onClick(e);
393
+ el.addEventListener("click", handler);
394
+ return () => el.removeEventListener("click", handler);
395
+ }, [overlayEl, onClick]);
396
+ useEffect3(() => {
397
+ if (!overlayEl) return;
398
+ overlayEl.className = `glyph-hotspot${className ? ` ${className}` : ""}`;
399
+ }, [overlayEl, className]);
400
+ if (!children || !overlayEl) return null;
401
+ return createPortal(children, overlayEl);
255
402
  }
256
- var GlyphcssHotspot = memo3(GlyphcssHotspotInner);
403
+ var GlyphHotspot = memo4(GlyphHotspotInner);
257
404
 
258
- // src/glyphcss/scene/useGlyphcssMesh.ts
259
- import { useEffect as useEffect4, useRef as useRef4, useState } from "react";
260
- function useGlyphcssMesh(triangles, options) {
261
- const { sceneRef } = useGlyphcssSceneContext();
405
+ // src/glyphcss/scene/useGlyphMesh.ts
406
+ import { useEffect as useEffect4, useRef as useRef4, useState as useState2 } from "react";
407
+ function useGlyphMesh(polygons, options) {
408
+ const { sceneRef } = useGlyphSceneContext();
262
409
  const meshRef = useRef4(null);
263
- const [loading] = useState(false);
410
+ const [loading] = useState2(false);
264
411
  useEffect4(() => {
265
412
  const scene = sceneRef.current;
266
413
  if (!scene) return;
267
- const handle = scene.add(triangles, options?.transform);
414
+ const handle = scene.add(polygons, options?.transform);
268
415
  meshRef.current = handle;
269
416
  return () => {
270
417
  handle.dispose();
271
418
  meshRef.current = null;
272
419
  };
273
- }, [sceneRef, triangles]);
420
+ }, [sceneRef, polygons]);
274
421
  useEffect4(() => {
275
422
  const mesh = meshRef.current;
276
423
  if (!mesh) return;
@@ -282,50 +429,29 @@ function useGlyphcssMesh(triangles, options) {
282
429
  return { meshRef, loading };
283
430
  }
284
431
 
285
- // src/glyphcss/camera/GlyphcssPerspectiveCamera.tsx
286
- import { memo as memo4, useEffect as useEffect5, useMemo as useMemo4, useRef as useRef5 } from "react";
287
- import { createGlyphcssPerspectiveCamera } from "glyphcss";
288
-
289
- // src/glyphcss/camera/context.ts
290
- import { createContext as createContext2, useContext as useContext2 } from "react";
291
- var GlyphcssCameraContext = createContext2(null);
292
- function useGlyphcssCamera() {
293
- const ctx = useContext2(GlyphcssCameraContext);
294
- if (!ctx) {
295
- throw new Error("glyphcss: camera hook must be used inside a GlyphcssCamera.");
296
- }
297
- return ctx;
298
- }
299
-
300
- // src/glyphcss/camera/GlyphcssPerspectiveCamera.tsx
432
+ // src/glyphcss/camera/GlyphOrthographicCamera.tsx
433
+ import { memo as memo5, useEffect as useEffect5, useMemo as useMemo5, useRef as useRef5 } from "react";
434
+ import { createGlyphOrthographicCamera } from "glyphcss";
301
435
  import { jsx as jsx4 } from "react/jsx-runtime";
302
- function GlyphcssPerspectiveCameraInner({
436
+ function GlyphOrthographicCameraInner({
303
437
  rotX,
304
438
  rotY,
305
- distance,
306
- scale,
307
- stretch,
439
+ zoom,
308
440
  center,
441
+ className,
442
+ style,
309
443
  children
310
444
  }) {
311
- const { sceneRef } = useGlyphcssSceneContext();
312
445
  const cameraRef = useRef5(null);
446
+ const sceneRerenderRef = useRef5(null);
313
447
  if (!cameraRef.current) {
314
448
  const opts = {};
315
449
  if (rotX !== void 0) opts.rotX = rotX;
316
450
  if (rotY !== void 0) opts.rotY = rotY;
317
- if (distance !== void 0) opts.distance = distance;
318
- if (scale !== void 0) opts.scale = scale;
319
- if (stretch !== void 0) opts.stretch = stretch;
451
+ if (zoom !== void 0) opts.zoom = zoom;
320
452
  if (center !== void 0) opts.center = center;
321
- cameraRef.current = createGlyphcssPerspectiveCamera(opts);
453
+ cameraRef.current = createGlyphOrthographicCamera(opts);
322
454
  }
323
- useEffect5(() => {
324
- const scene = sceneRef.current;
325
- if (!scene || !cameraRef.current) return;
326
- scene.setOptions({ camera: cameraRef.current });
327
- scene.rerender();
328
- }, [sceneRef]);
329
455
  useEffect5(() => {
330
456
  const camera = cameraRef.current;
331
457
  if (!camera) return;
@@ -338,55 +464,47 @@ function GlyphcssPerspectiveCameraInner({
338
464
  camera.rotY = rotY;
339
465
  dirty = true;
340
466
  }
341
- if (distance !== void 0 && camera.distance !== distance) {
342
- camera.distance = distance;
343
- dirty = true;
344
- }
345
- if (scale !== void 0 && camera.scale !== scale) {
346
- camera.scale = scale;
347
- dirty = true;
348
- }
349
- if (stretch !== void 0 && camera.stretch !== stretch) {
350
- camera.stretch = stretch;
467
+ if (zoom !== void 0 && camera.zoom !== zoom) {
468
+ camera.zoom = zoom;
351
469
  dirty = true;
352
470
  }
353
471
  if (dirty) {
354
- sceneRef.current?.rerender();
472
+ sceneRerenderRef.current?.();
355
473
  }
356
474
  });
357
- const rerender = () => sceneRef.current?.rerender();
358
- const ctxValue = useMemo4(() => ({ cameraRef, rerender }), [cameraRef]);
359
- return /* @__PURE__ */ jsx4(GlyphcssCameraContext.Provider, { value: ctxValue, children });
475
+ const rerender = useMemo5(() => () => sceneRerenderRef.current?.(), []);
476
+ const ctxValue = useMemo5(() => ({ cameraRef, rerender, sceneRerenderRef }), [cameraRef, rerender]);
477
+ return /* @__PURE__ */ jsx4(GlyphCameraContext.Provider, { value: ctxValue, children: /* @__PURE__ */ jsx4("div", { className, style, children }) });
360
478
  }
361
- var GlyphcssPerspectiveCamera = memo4(GlyphcssPerspectiveCameraInner);
479
+ var GlyphOrthographicCamera = memo5(GlyphOrthographicCameraInner);
362
480
 
363
- // src/glyphcss/camera/GlyphcssOrthographicCamera.tsx
364
- import { memo as memo5, useEffect as useEffect6, useMemo as useMemo5, useRef as useRef6 } from "react";
365
- import { createGlyphcssOrthographicCamera } from "glyphcss";
481
+ // src/glyphcss/camera/GlyphPerspectiveCamera.tsx
482
+ import { memo as memo6, useEffect as useEffect6, useMemo as useMemo6, useRef as useRef6 } from "react";
483
+ import { createGlyphPerspectiveCamera } from "glyphcss";
366
484
  import { jsx as jsx5 } from "react/jsx-runtime";
367
- function GlyphcssOrthographicCameraInner({
485
+ function GlyphPerspectiveCameraInner({
368
486
  rotX,
369
487
  rotY,
488
+ distance,
370
489
  zoom,
490
+ stretch,
371
491
  center,
492
+ className,
493
+ style,
372
494
  children
373
495
  }) {
374
- const { sceneRef } = useGlyphcssSceneContext();
375
496
  const cameraRef = useRef6(null);
497
+ const sceneRerenderRef = useRef6(null);
376
498
  if (!cameraRef.current) {
377
499
  const opts = {};
378
500
  if (rotX !== void 0) opts.rotX = rotX;
379
501
  if (rotY !== void 0) opts.rotY = rotY;
502
+ if (distance !== void 0) opts.distance = distance;
380
503
  if (zoom !== void 0) opts.zoom = zoom;
504
+ if (stretch !== void 0) opts.stretch = stretch;
381
505
  if (center !== void 0) opts.center = center;
382
- cameraRef.current = createGlyphcssOrthographicCamera(opts);
506
+ cameraRef.current = createGlyphPerspectiveCamera(opts);
383
507
  }
384
- useEffect6(() => {
385
- const scene = sceneRef.current;
386
- if (!scene || !cameraRef.current) return;
387
- scene.setOptions({ camera: cameraRef.current });
388
- scene.rerender();
389
- }, [sceneRef]);
390
508
  useEffect6(() => {
391
509
  const camera = cameraRef.current;
392
510
  if (!camera) return;
@@ -399,36 +517,46 @@ function GlyphcssOrthographicCameraInner({
399
517
  camera.rotY = rotY;
400
518
  dirty = true;
401
519
  }
402
- if (zoom !== void 0 && camera.scale !== zoom) {
403
- camera.scale = zoom;
520
+ if (distance !== void 0 && camera.distance !== distance) {
521
+ camera.distance = distance;
522
+ dirty = true;
523
+ }
524
+ if (zoom !== void 0 && camera.zoom !== zoom) {
525
+ camera.zoom = zoom;
526
+ dirty = true;
527
+ }
528
+ if (stretch !== void 0 && camera.stretch !== stretch) {
529
+ camera.stretch = stretch;
404
530
  dirty = true;
405
531
  }
406
- if (dirty) sceneRef.current?.rerender();
532
+ if (dirty) {
533
+ sceneRerenderRef.current?.();
534
+ }
407
535
  });
408
- const rerender = () => sceneRef.current?.rerender();
409
- const ctxValue = useMemo5(() => ({ cameraRef, rerender }), [cameraRef]);
410
- return /* @__PURE__ */ jsx5(GlyphcssCameraContext.Provider, { value: ctxValue, children });
536
+ const rerender = useMemo6(() => () => sceneRerenderRef.current?.(), []);
537
+ const ctxValue = useMemo6(() => ({ cameraRef, rerender, sceneRerenderRef }), [cameraRef, rerender]);
538
+ return /* @__PURE__ */ jsx5(GlyphCameraContext.Provider, { value: ctxValue, children: /* @__PURE__ */ jsx5("div", { className, style, children }) });
411
539
  }
412
- var GlyphcssOrthographicCamera = memo5(GlyphcssOrthographicCameraInner);
540
+ var GlyphPerspectiveCamera = memo6(GlyphPerspectiveCameraInner);
413
541
 
414
- // src/glyphcss/camera/useGlyphcssCamera.ts
415
- import { useCallback as useCallback2, useEffect as useEffect7, useRef as useRef7 } from "react";
416
- import { createGlyphcssPerspectiveCamera as createGlyphcssPerspectiveCamera2 } from "glyphcss";
542
+ // src/glyphcss/camera/useGlyphCamera.ts
543
+ import { useCallback as useCallback2, useRef as useRef7 } from "react";
544
+ import { createGlyphPerspectiveCamera as createGlyphPerspectiveCamera2 } from "glyphcss";
417
545
 
418
- // src/glyphcss/controls/GlyphcssOrbitControls.tsx
419
- import { useEffect as useEffect8, useRef as useRef8 } from "react";
420
- import { createGlyphcssOrbitControls } from "glyphcss";
421
- function GlyphcssOrbitControls({
546
+ // src/glyphcss/controls/GlyphOrbitControls.tsx
547
+ import { useEffect as useEffect7, useRef as useRef8 } from "react";
548
+ import { createGlyphOrbitControls } from "glyphcss";
549
+ function GlyphOrbitControls({
422
550
  drag = true,
423
551
  wheel = true,
424
552
  invert = false,
425
553
  animate = false
426
554
  }) {
427
- const { sceneRef } = useGlyphcssSceneContext();
555
+ const { sceneRef } = useGlyphSceneContext();
428
556
  const controlsRef = useRef8(null);
429
557
  const propsRef = useRef8({ drag, wheel, invert, animate });
430
558
  propsRef.current = { drag, wheel, invert, animate };
431
- useEffect8(() => {
559
+ useEffect7(() => {
432
560
  const scene = sceneRef.current;
433
561
  if (!scene) return;
434
562
  const opts = {
@@ -437,14 +565,14 @@ function GlyphcssOrbitControls({
437
565
  invert: propsRef.current.invert,
438
566
  animate: propsRef.current.animate === false ? false : propsRef.current.animate
439
567
  };
440
- const controls = createGlyphcssOrbitControls(scene, opts);
568
+ const controls = createGlyphOrbitControls(scene, opts);
441
569
  controlsRef.current = controls;
442
570
  return () => {
443
571
  controls.destroy();
444
572
  controlsRef.current = null;
445
573
  };
446
574
  }, [sceneRef]);
447
- useEffect8(() => {
575
+ useEffect7(() => {
448
576
  const controls = controlsRef.current;
449
577
  if (!controls) return;
450
578
  controls.update({ drag, wheel, invert, animate: animate === false ? false : animate });
@@ -452,20 +580,20 @@ function GlyphcssOrbitControls({
452
580
  return null;
453
581
  }
454
582
 
455
- // src/glyphcss/controls/GlyphcssMapControls.tsx
456
- import { useEffect as useEffect9, useRef as useRef9 } from "react";
457
- import { createGlyphcssMapControls } from "glyphcss";
458
- function GlyphcssMapControls({
583
+ // src/glyphcss/controls/GlyphMapControls.tsx
584
+ import { useEffect as useEffect8, useRef as useRef9 } from "react";
585
+ import { createGlyphMapControls } from "glyphcss";
586
+ function GlyphMapControls({
459
587
  drag = true,
460
588
  wheel = true,
461
589
  invert = false,
462
590
  animate = false
463
591
  }) {
464
- const { sceneRef } = useGlyphcssSceneContext();
592
+ const { sceneRef } = useGlyphSceneContext();
465
593
  const controlsRef = useRef9(null);
466
594
  const propsRef = useRef9({ drag, wheel, invert, animate });
467
595
  propsRef.current = { drag, wheel, invert, animate };
468
- useEffect9(() => {
596
+ useEffect8(() => {
469
597
  const scene = sceneRef.current;
470
598
  if (!scene) return;
471
599
  const opts = {
@@ -474,14 +602,14 @@ function GlyphcssMapControls({
474
602
  invert: propsRef.current.invert,
475
603
  animate: propsRef.current.animate === false ? false : propsRef.current.animate
476
604
  };
477
- const controls = createGlyphcssMapControls(scene, opts);
605
+ const controls = createGlyphMapControls(scene, opts);
478
606
  controlsRef.current = controls;
479
607
  return () => {
480
608
  controls.destroy();
481
609
  controlsRef.current = null;
482
610
  };
483
611
  }, [sceneRef]);
484
- useEffect9(() => {
612
+ useEffect8(() => {
485
613
  const controls = controlsRef.current;
486
614
  if (!controls) return;
487
615
  controls.update({ drag, wheel, invert, animate: animate === false ? false : animate });
@@ -489,21 +617,21 @@ function GlyphcssMapControls({
489
617
  return null;
490
618
  }
491
619
 
492
- // src/glyphcss/controls/GlyphcssFirstPersonControls.tsx
493
- import { useEffect as useEffect10, useRef as useRef10 } from "react";
494
- import { createGlyphcssFirstPersonControls } from "glyphcss";
495
- function GlyphcssFirstPersonControls({
620
+ // src/glyphcss/controls/GlyphFirstPersonControls.tsx
621
+ import { useEffect as useEffect9, useRef as useRef10 } from "react";
622
+ import { createGlyphFirstPersonControls } from "glyphcss";
623
+ function GlyphFirstPersonControls({
496
624
  drag = true,
497
625
  keyboard = true,
498
626
  moveSpeed = 0.05,
499
627
  lookSpeed = 4e-3,
500
628
  invert = false
501
629
  }) {
502
- const { sceneRef } = useGlyphcssSceneContext();
630
+ const { sceneRef } = useGlyphSceneContext();
503
631
  const controlsRef = useRef10(null);
504
632
  const propsRef = useRef10({ drag, keyboard, moveSpeed, lookSpeed, invert });
505
633
  propsRef.current = { drag, keyboard, moveSpeed, lookSpeed, invert };
506
- useEffect10(() => {
634
+ useEffect9(() => {
507
635
  const scene = sceneRef.current;
508
636
  if (!scene) return;
509
637
  const opts = {
@@ -513,14 +641,14 @@ function GlyphcssFirstPersonControls({
513
641
  lookSpeed: propsRef.current.lookSpeed,
514
642
  invert: propsRef.current.invert
515
643
  };
516
- const controls = createGlyphcssFirstPersonControls(scene, opts);
644
+ const controls = createGlyphFirstPersonControls(scene, opts);
517
645
  controlsRef.current = controls;
518
646
  return () => {
519
647
  controls.destroy();
520
648
  controlsRef.current = null;
521
649
  };
522
650
  }, [sceneRef]);
523
- useEffect10(() => {
651
+ useEffect9(() => {
524
652
  const controls = controlsRef.current;
525
653
  if (!controls) return;
526
654
  controls.update({ drag, keyboard, moveSpeed, lookSpeed, invert });
@@ -528,46 +656,46 @@ function GlyphcssFirstPersonControls({
528
656
  return null;
529
657
  }
530
658
 
531
- // src/glyphcss/helpers/GlyphcssAxesHelper.tsx
532
- import { memo as memo6, useEffect as useEffect11, useMemo as useMemo7, useRef as useRef11 } from "react";
533
- function axisTriangles(size) {
659
+ // src/glyphcss/helpers/GlyphAxesHelper.tsx
660
+ import { memo as memo7, useEffect as useEffect10, useMemo as useMemo7, useRef as useRef11 } from "react";
661
+ function axisPolygons(size) {
534
662
  const s = size;
535
663
  const t = s * 0.05;
536
- const triangles = [];
664
+ const polygons = [];
537
665
  function addBar(a, b, color) {
538
666
  const v0 = [a[0] - t, a[1] - t, a[2]];
539
667
  const v1 = [b[0] - t, b[1] - t, b[2]];
540
668
  const v2 = [b[0] + t, b[1] + t, b[2]];
541
669
  const v3 = [a[0] + t, a[1] + t, a[2]];
542
- triangles.push({ vertices: [v0, v1, v2], color });
543
- triangles.push({ vertices: [v0, v2, v3], color });
670
+ polygons.push({ vertices: [v0, v1, v2], color });
671
+ polygons.push({ vertices: [v0, v2, v3], color });
544
672
  }
545
673
  addBar([0, 0, 0], [s, 0, 0], "#ff0000");
546
674
  addBar([0, 0, 0], [0, s, 0], "#00ff00");
547
675
  addBar([0, 0, 0], [0, 0, s], "#0000ff");
548
- return triangles;
676
+ return polygons;
549
677
  }
550
- function GlyphcssAxesHelperInner({ size = 1 }) {
551
- const { sceneRef } = useGlyphcssSceneContext();
678
+ function GlyphAxesHelperInner({ size = 1 }) {
679
+ const { sceneRef } = useGlyphSceneContext();
552
680
  const meshRef = useRef11(null);
553
- const triangles = useMemo7(() => axisTriangles(size), [size]);
554
- useEffect11(() => {
681
+ const polygons = useMemo7(() => axisPolygons(size), [size]);
682
+ useEffect10(() => {
555
683
  const scene = sceneRef.current;
556
684
  if (!scene) return;
557
- const handle = scene.add(triangles);
685
+ const handle = scene.add(polygons);
558
686
  meshRef.current = handle;
559
687
  return () => {
560
688
  handle.dispose();
561
689
  meshRef.current = null;
562
690
  };
563
- }, [sceneRef, triangles]);
691
+ }, [sceneRef, polygons]);
564
692
  return null;
565
693
  }
566
- var GlyphcssAxesHelper = memo6(GlyphcssAxesHelperInner);
694
+ var GlyphAxesHelper = memo7(GlyphAxesHelperInner);
567
695
 
568
- // src/glyphcss/helpers/GlyphcssDirectionalLightHelper.tsx
569
- import { memo as memo7, useEffect as useEffect12, useMemo as useMemo8, useRef as useRef12 } from "react";
570
- function lightMarkerTriangles(position, color, size) {
696
+ // src/glyphcss/helpers/GlyphDirectionalLightHelper.tsx
697
+ import { memo as memo8, useEffect as useEffect11, useMemo as useMemo8, useRef as useRef12 } from "react";
698
+ function lightMarkerPolygons(position, color, size) {
571
699
  const [px, py, pz] = position;
572
700
  const s = size;
573
701
  const top = [px, py, pz + s];
@@ -587,46 +715,46 @@ function lightMarkerTriangles(position, color, size) {
587
715
  { vertices: [bot, right, back], color }
588
716
  ];
589
717
  }
590
- function GlyphcssDirectionalLightHelperInner({
718
+ function GlyphDirectionalLightHelperInner({
591
719
  position = [1, 1, 1],
592
720
  color = "#ffff00",
593
721
  size = 0.1
594
722
  }) {
595
- const { sceneRef } = useGlyphcssSceneContext();
723
+ const { sceneRef } = useGlyphSceneContext();
596
724
  const meshRef = useRef12(null);
597
- const triangles = useMemo8(
598
- () => lightMarkerTriangles(position, color, size),
725
+ const polygons = useMemo8(
726
+ () => lightMarkerPolygons(position, color, size),
599
727
  [position, color, size]
600
728
  );
601
- useEffect12(() => {
729
+ useEffect11(() => {
602
730
  const scene = sceneRef.current;
603
731
  if (!scene) return;
604
- const handle = scene.add(triangles);
732
+ const handle = scene.add(polygons);
605
733
  meshRef.current = handle;
606
734
  return () => {
607
735
  handle.dispose();
608
736
  meshRef.current = null;
609
737
  };
610
- }, [sceneRef, triangles]);
738
+ }, [sceneRef, polygons]);
611
739
  return null;
612
740
  }
613
- var GlyphcssDirectionalLightHelper = memo7(GlyphcssDirectionalLightHelperInner);
741
+ var GlyphDirectionalLightHelper = memo8(GlyphDirectionalLightHelperInner);
614
742
 
615
743
  // src/glyphcss/styles/index.ts
616
- import { injectGlyphcssBaseStyles as injectGlyphcssBaseStyles2 } from "glyphcss";
744
+ import { injectGlyphBaseStyles as injectGlyphBaseStyles2 } from "glyphcss";
617
745
 
618
- // src/animation/useGlyphcssAnimation.ts
619
- import { useEffect as useEffect13, useRef as useRef13, useMemo as useMemo9 } from "react";
620
- import { createGlyphcssAnimationMixer } from "@glyphcss/core";
746
+ // src/animation/useGlyphAnimation.ts
747
+ import { useEffect as useEffect12, useRef as useRef13, useMemo as useMemo9 } from "react";
748
+ import { createGlyphAnimationMixer } from "@glyphcss/core";
621
749
  function resolveRoot(rootArg) {
622
750
  if (!rootArg) return null;
623
751
  if ("current" in rootArg) return rootArg.current;
624
752
  return rootArg;
625
753
  }
626
- function useGlyphcssAnimation(clips, controller, root) {
754
+ function useGlyphAnimation(clips, controller, root) {
627
755
  const internalRef = useRef13(null);
628
756
  const mixerRef = useRef13(null);
629
- useEffect13(() => {
757
+ useEffect12(() => {
630
758
  if (!clips || clips.length === 0 || !controller) {
631
759
  mixerRef.current = null;
632
760
  return;
@@ -636,14 +764,14 @@ function useGlyphcssAnimation(clips, controller, root) {
636
764
  mixerRef.current = null;
637
765
  return;
638
766
  }
639
- mixerRef.current = createGlyphcssAnimationMixer(resolvedRoot, controller);
767
+ mixerRef.current = createGlyphAnimationMixer(resolvedRoot, controller);
640
768
  return () => {
641
769
  mixerRef.current?.stopAllAction();
642
770
  mixerRef.current?.uncacheRoot();
643
771
  mixerRef.current = null;
644
772
  };
645
773
  }, [clips, controller]);
646
- useEffect13(() => {
774
+ useEffect12(() => {
647
775
  if (!clips || clips.length === 0 || !controller) return;
648
776
  let rafId;
649
777
  let lastTime = null;
@@ -697,28 +825,31 @@ export {
697
825
  CAMERA_BACKFACE_CULL_EPS,
698
826
  DEFAULT_CAMERA_STATE,
699
827
  DEFAULT_PROJECTION,
700
- GlyphcssAxesHelper,
701
- GlyphcssPerspectiveCamera as GlyphcssCamera,
702
- GlyphcssCameraContext,
703
- GlyphcssDirectionalLightHelper,
704
- GlyphcssFirstPersonControls,
705
- GlyphcssHotspot,
706
- GlyphcssMapControls,
707
- GlyphcssMesh,
708
- GlyphcssOrbitControls,
709
- GlyphcssOrthographicCamera,
710
- GlyphcssPerspectiveCamera,
711
- GlyphcssScene,
712
- GlyphcssSceneContext,
828
+ GlyphAxesHelper,
829
+ GlyphOrthographicCamera as GlyphCamera,
830
+ GlyphCameraContext,
831
+ GlyphDirectionalLightHelper,
832
+ GlyphFirstPersonControls,
833
+ GlyphGround,
834
+ GlyphHotspot,
835
+ GlyphMapControls,
836
+ GlyphMesh,
837
+ GlyphOrbitControls,
838
+ GlyphOrthographicCamera,
839
+ GlyphPerspectiveCamera,
840
+ GlyphScene,
841
+ GlyphSceneContext,
713
842
  LoopOnce,
714
843
  LoopPingPong,
715
844
  LoopRepeat,
716
845
  VOXEL_CAMERA_CULL_AXIS_EPS,
717
846
  VOXEL_CAMERA_CULL_NORMAL_LIMIT,
847
+ antiprismPolygons,
718
848
  arrowPolygons,
719
849
  axesHelperPolygons,
720
850
  bakeSolidTextureSampledPolygons,
721
851
  bakeSolidTextureSamples,
852
+ bipyramidPolygons,
722
853
  buildSceneContext,
723
854
  cameraCullNormalGroups,
724
855
  cameraCullNormalGroupsFromPolygons,
@@ -728,13 +859,28 @@ export {
728
859
  clampChannel,
729
860
  computeSceneBbox,
730
861
  computeShapeLighting,
862
+ conePolygons,
731
863
  coverPlanarPolygons,
732
- createGlyphcssAnimationMixer2 as createGlyphcssAnimationMixer,
864
+ createGlyphAnimationMixer2 as createGlyphAnimationMixer,
733
865
  createIsometricCamera,
866
+ cubePolygons,
867
+ cuboctahedronPolygons,
734
868
  cullInteriorPolygons,
735
- findGlyphcssMeshHandle,
869
+ cylinderPolygons,
870
+ deltoidalHexecontahedronPolygons,
871
+ deltoidalIcositetrahedronPolygons,
872
+ disdyakisDodecahedronPolygons,
873
+ disdyakisTriacontahedronPolygons,
874
+ dodecahedronPolygons,
875
+ findGlyphMeshHandle,
876
+ findMeshUnderPoint,
736
877
  formatColor,
737
- injectGlyphcssBaseStyles2 as injectGlyphcssBaseStyles,
878
+ greatDodecahedronPolygons,
879
+ greatIcosahedronPolygons,
880
+ greatStellatedDodecahedronPolygons,
881
+ icosahedronPolygons,
882
+ icosidodecahedronPolygons,
883
+ injectGlyphBaseStyles2 as injectGlyphBaseStyles,
738
884
  inverseRotateVec3,
739
885
  isAxisAlignedSurfaceNormal,
740
886
  isVoxelCameraCullableNormalGroups,
@@ -753,14 +899,45 @@ export {
753
899
  parsePureColor,
754
900
  parseRgbColor,
755
901
  parseVox,
902
+ pentagonalHexecontahedronPolygons,
903
+ pentagonalIcositetrahedronPolygons,
904
+ pentakisDodecahedronPolygons,
905
+ planePolygons2 as planePolygons,
906
+ pointInMeshElement,
756
907
  polygonCssSurfaceNormal,
757
908
  polygonFaces,
758
909
  polygonFacesCamera,
910
+ prismPolygons,
911
+ pyramidPolygons,
912
+ resolveGeometry2 as resolveGeometry,
913
+ rhombicDodecahedronPolygons,
914
+ rhombicTriacontahedronPolygons,
915
+ rhombicosidodecahedronPolygons,
916
+ rhombicuboctahedronPolygons,
759
917
  ringPolygons,
918
+ ringQuadPolygons,
760
919
  rotateVec3,
761
920
  shadeColor,
762
- useGlyphcssAnimation,
763
- useGlyphcssCamera,
764
- useGlyphcssMesh,
765
- useGlyphcssSceneContext
921
+ smallStellatedDodecahedronPolygons,
922
+ snubCubePolygons,
923
+ snubDodecahedronPolygons,
924
+ spherePolygons,
925
+ tetrahedronPolygons,
926
+ tetrakisHexahedronPolygons,
927
+ torusPolygons,
928
+ trapezohedronPolygons,
929
+ triakisIcosahedronPolygons,
930
+ triakisOctahedronPolygons,
931
+ triakisTetrahedronPolygons,
932
+ truncatedCubePolygons,
933
+ truncatedCuboctahedronPolygons,
934
+ truncatedDodecahedronPolygons,
935
+ truncatedIcosahedronPolygons,
936
+ truncatedIcosidodecahedronPolygons,
937
+ truncatedOctahedronPolygons,
938
+ truncatedTetrahedronPolygons,
939
+ useGlyphAnimation,
940
+ useGlyphCamera,
941
+ useGlyphMesh,
942
+ useGlyphSceneContext
766
943
  };