react-three-map 0.3.5 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +25 -0
  3. package/dist/cjs/main.js +1 -1
  4. package/dist/es/main.mjs +4 -2
  5. package/dist/es/main.mjs.map +1 -1
  6. package/dist/es/main10.mjs +10 -0
  7. package/dist/es/main10.mjs.map +1 -0
  8. package/dist/es/main11.mjs +52 -0
  9. package/dist/es/main11.mjs.map +1 -0
  10. package/dist/es/main12.mjs +9 -0
  11. package/dist/es/main12.mjs.map +1 -0
  12. package/dist/es/main13.mjs +56 -0
  13. package/dist/es/main13.mjs.map +1 -0
  14. package/dist/es/main2.mjs +17 -29
  15. package/dist/es/main2.mjs.map +1 -1
  16. package/dist/es/main3.mjs +38 -6
  17. package/dist/es/main3.mjs.map +1 -1
  18. package/dist/es/main4.mjs +20 -16
  19. package/dist/es/main4.mjs.map +1 -1
  20. package/dist/es/main5.mjs +3 -60
  21. package/dist/es/main5.mjs.map +1 -1
  22. package/dist/es/main6.mjs +5 -12
  23. package/dist/es/main6.mjs.map +1 -1
  24. package/dist/es/main7.mjs +10 -52
  25. package/dist/es/main7.mjs.map +1 -1
  26. package/dist/es/main8.mjs +14 -5
  27. package/dist/es/main8.mjs.map +1 -1
  28. package/dist/es/main9.mjs +15 -0
  29. package/dist/es/main9.mjs.map +1 -0
  30. package/dist/maplibre/cjs/main.js +1 -1
  31. package/dist/maplibre/es/main.mjs +4 -2
  32. package/dist/maplibre/es/main.mjs.map +1 -1
  33. package/dist/maplibre/es/main10.mjs +10 -0
  34. package/dist/maplibre/es/main10.mjs.map +1 -0
  35. package/dist/maplibre/es/main11.mjs +52 -0
  36. package/dist/maplibre/es/main11.mjs.map +1 -0
  37. package/dist/maplibre/es/main12.mjs +9 -0
  38. package/dist/maplibre/es/main12.mjs.map +1 -0
  39. package/dist/maplibre/es/main13.mjs +56 -0
  40. package/dist/maplibre/es/main13.mjs.map +1 -0
  41. package/dist/maplibre/es/main2.mjs +17 -29
  42. package/dist/maplibre/es/main2.mjs.map +1 -1
  43. package/dist/maplibre/es/main3.mjs +38 -6
  44. package/dist/maplibre/es/main3.mjs.map +1 -1
  45. package/dist/maplibre/es/main4.mjs +20 -16
  46. package/dist/maplibre/es/main4.mjs.map +1 -1
  47. package/dist/maplibre/es/main5.mjs +3 -60
  48. package/dist/maplibre/es/main5.mjs.map +1 -1
  49. package/dist/maplibre/es/main6.mjs +5 -12
  50. package/dist/maplibre/es/main6.mjs.map +1 -1
  51. package/dist/maplibre/es/main7.mjs +10 -52
  52. package/dist/maplibre/es/main7.mjs.map +1 -1
  53. package/dist/maplibre/es/main8.mjs +14 -5
  54. package/dist/maplibre/es/main8.mjs.map +1 -1
  55. package/dist/maplibre/es/main9.mjs +15 -0
  56. package/dist/maplibre/es/main9.mjs.map +1 -0
  57. package/dist/maplibre/types/api/canvas-props.d.ts +8 -0
  58. package/dist/maplibre/types/api/coordinates.d.ts +7 -0
  59. package/dist/maplibre/types/core/store.d.ts +12 -0
  60. package/dist/maplibre/types/core/sync-camera.d.ts +2 -0
  61. package/dist/maplibre/types/core/use-canvas.d.ts +7 -9
  62. package/dist/maplibre/types/core/use-coords.d.ts +5 -0
  63. package/dist/maplibre/types/core/use-create-root.d.ts +13 -0
  64. package/dist/maplibre/types/core/use-on-add.d.ts +6 -4
  65. package/dist/maplibre/types/core/use-render.d.ts +3 -2
  66. package/dist/maplibre/types/maplibre/canvas.d.ts +2 -8
  67. package/dist/maplibre/types/maplibre.index.d.ts +2 -0
  68. package/dist/types/api/canvas-props.d.ts +8 -0
  69. package/dist/types/api/coordinates.d.ts +7 -0
  70. package/dist/types/core/store.d.ts +12 -0
  71. package/dist/types/core/sync-camera.d.ts +2 -0
  72. package/dist/types/core/use-canvas.d.ts +7 -9
  73. package/dist/types/core/use-coords.d.ts +5 -0
  74. package/dist/types/core/use-create-root.d.ts +13 -0
  75. package/dist/types/core/use-on-add.d.ts +6 -4
  76. package/dist/types/core/use-render.d.ts +3 -2
  77. package/dist/types/mapbox/canvas.d.ts +3 -9
  78. package/dist/types/mapbox.index.d.ts +2 -0
  79. package/package.json +5 -5
  80. package/stories/README.md +1 -0
  81. package/stories/package.json +31 -0
  82. package/stories/sandbox.config.json +3 -0
  83. package/stories/yarn.lock +4295 -0
  84. package/dist/maplibre/types/core/state-ref.d.ts +0 -8
  85. package/dist/types/core/state-ref.d.ts +0 -8
@@ -1,63 +1,6 @@
1
- import { createRoot as v } from "@react-three/fiber";
2
- import { useState as h } from "react";
3
- import { createEvents as d } from "./main7.mjs";
4
- import { useFunction as c } from "./main8.mjs";
5
- function w(e, { frameloop: u, ...n }) {
6
- const [l, r] = h(!1), g = c((t, m) => {
7
- const o = t.getCanvas(), i = v(o);
8
- i.configure({
9
- dpr: window.devicePixelRatio,
10
- events: d(),
11
- ...n,
12
- frameloop: "never",
13
- gl: {
14
- context: m,
15
- depth: !0,
16
- autoClear: !1,
17
- antialias: !0,
18
- ...n == null ? void 0 : n.gl
19
- },
20
- onCreated: (a) => {
21
- u === "demand" && a.set({
22
- frameloop: u,
23
- invalidate: () => {
24
- t.triggerRepaint();
25
- }
26
- }), e.current = {
27
- state: a,
28
- map: t,
29
- root: i
30
- }, a.gl.forceContextLoss = () => {
31
- };
32
- },
33
- camera: {
34
- matrixAutoUpdate: !1
35
- },
36
- size: {
37
- width: o.clientWidth,
38
- height: o.clientHeight,
39
- top: 0,
40
- left: 0,
41
- ...n == null ? void 0 : n.size
42
- }
43
- }), e.current = {
44
- map: t,
45
- root: i
46
- }, t.on("resize", s), setTimeout(() => r(!0));
47
- }), s = c(() => {
48
- var i;
49
- if (!((i = e.current) != null && i.state))
50
- return;
51
- const t = e.current.state, o = e.current.map.getCanvas();
52
- t.setSize(o.width, o.height);
53
- }), f = c((t) => {
54
- setTimeout(() => {
55
- e.current && (e.current.root.unmount(), t.off("resize", s));
56
- });
57
- });
58
- return { onAdd: g, onRemove: f, mounted: l };
59
- }
1
+ import { useThree as r } from "@react-three/fiber";
2
+ const m = () => r((e) => e.r3m);
60
3
  export {
61
- w as useOnAdd
4
+ m as useR3M
62
5
  };
63
6
  //# sourceMappingURL=main5.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"main5.mjs","sources":["../../../src/core/use-on-add.ts"],"sourcesContent":["import { RenderProps, createRoot } from \"@react-three/fiber\";\nimport { useState } from \"react\";\nimport { createEvents } from \"./create-events\";\nimport { MapInstance } from \"./generic-map\";\nimport { StateRef } from \"./state-ref\";\nimport { useFunction } from \"./use-function\";\n\nexport function useOnAdd(ref: StateRef, { frameloop, ...renderProps }: RenderProps<HTMLCanvasElement>) {\n\n const [mounted, setMounted] = useState(false);\n\n const onAdd = useFunction((map: MapInstance, gl: WebGLRenderingContext) => {\n\n const canvas = map.getCanvas();\n const root = createRoot(canvas);\n root.configure({\n dpr: window.devicePixelRatio,\n events: createEvents(),\n ...renderProps,\n frameloop: 'never',\n gl: {\n context: gl,\n depth: true,\n autoClear: false,\n antialias: true,\n ...renderProps?.gl,\n },\n onCreated: (state) => {\n\n if (frameloop === 'demand') {\n state.set({\n frameloop,\n invalidate: () => {\n map.triggerRepaint();\n }\n })\n }\n\n ref.current = {\n state,\n map,\n root,\n }\n\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n state.gl.forceContextLoss = () => { };\n \n },\n camera: {\n matrixAutoUpdate: false,\n },\n size: {\n width: canvas.clientWidth,\n height: canvas.clientHeight,\n top: 0,\n left: 0,\n ...renderProps?.size,\n },\n });\n\n ref.current = {\n map,\n root,\n }\n\n map.on('resize', onResize)\n\n setTimeout(() => setMounted(true));\n\n })\n\n const onResize = useFunction(() => {\n if (!ref.current?.state) return;\n const state = ref.current.state;\n const map = ref.current.map;\n const canvas = map.getCanvas();\n state.setSize(canvas.width, canvas.height);\n })\n\n const onRemove = useFunction((map: MapInstance) => {\n setTimeout(() => {\n if (!ref.current) return;\n ref.current.root.unmount();\n map.off('resize', onResize)\n })\n })\n\n return { onAdd, onRemove, mounted };\n}"],"names":["useOnAdd","ref","frameloop","renderProps","mounted","setMounted","useState","onAdd","useFunction","map","gl","canvas","root","createRoot","createEvents","state","onResize","_a","onRemove"],"mappings":";;;;AAOO,SAASA,EAASC,GAAe,EAAE,WAAAC,GAAW,GAAGC,KAA+C;AAErG,QAAM,CAACC,GAASC,CAAU,IAAIC,EAAS,EAAK,GAEtCC,IAAQC,EAAY,CAACC,GAAkBC,MAA8B;AAEnE,UAAAC,IAASF,EAAI,aACbG,IAAOC,EAAWF,CAAM;AAC9B,IAAAC,EAAK,UAAU;AAAA,MACb,KAAK,OAAO;AAAA,MACZ,QAAQE,EAAa;AAAA,MACrB,GAAGX;AAAA,MACH,WAAW;AAAA,MACX,IAAI;AAAA,QACF,SAASO;AAAA,QACT,OAAO;AAAA,QACP,WAAW;AAAA,QACX,WAAW;AAAA,QACX,GAAGP,KAAA,gBAAAA,EAAa;AAAA,MAClB;AAAA,MACA,WAAW,CAACY,MAAU;AAEpB,QAAIb,MAAc,YAChBa,EAAM,IAAI;AAAA,UACR,WAAAb;AAAA,UACA,YAAY,MAAM;AAChB,YAAAO,EAAI,eAAe;AAAA,UACrB;AAAA,QAAA,CACD,GAGHR,EAAI,UAAU;AAAA,UACZ,OAAAc;AAAA,UACA,KAAAN;AAAA,UACA,MAAAG;AAAA,QAAA,GAIIG,EAAA,GAAG,mBAAmB,MAAM;AAAA,QAAA;AAAA,MAEpC;AAAA,MACA,QAAQ;AAAA,QACN,kBAAkB;AAAA,MACpB;AAAA,MACA,MAAM;AAAA,QACJ,OAAOJ,EAAO;AAAA,QACd,QAAQA,EAAO;AAAA,QACf,KAAK;AAAA,QACL,MAAM;AAAA,QACN,GAAGR,KAAA,gBAAAA,EAAa;AAAA,MAClB;AAAA,IAAA,CACD,GAEDF,EAAI,UAAU;AAAA,MACZ,KAAAQ;AAAA,MACA,MAAAG;AAAA,IAAA,GAGEH,EAAA,GAAG,UAAUO,CAAQ,GAEd,WAAA,MAAMX,EAAW,EAAI,CAAC;AAAA,EAAA,CAElC,GAEKW,IAAWR,EAAY,MAAM;;AAC7B,QAAA,GAACS,IAAAhB,EAAI,YAAJ,QAAAgB,EAAa;AAAO;AACnB,UAAAF,IAAQd,EAAI,QAAQ,OAEpBU,IADMV,EAAI,QAAQ,IACL;AACnB,IAAAc,EAAM,QAAQJ,EAAO,OAAOA,EAAO,MAAM;AAAA,EAAA,CAC1C,GAEKO,IAAWV,EAAY,CAACC,MAAqB;AACjD,eAAW,MAAM;AACf,MAAKR,EAAI,YACLA,EAAA,QAAQ,KAAK,WACbQ,EAAA,IAAI,UAAUO,CAAQ;AAAA,IAAA,CAC3B;AAAA,EAAA,CACF;AAEM,SAAA,EAAE,OAAAT,GAAO,UAAAW,GAAU,SAAAd;AAC5B;"}
1
+ {"version":3,"file":"main5.mjs","sources":["../../../src/core/store.ts"],"sourcesContent":["import { ReconcilerRoot, RootState, useThree } from \"@react-three/fiber\";\nimport { Matrix4Tuple } from \"three\";\nimport { FromLngLat, MapInstance } from \"./generic-map\";\n\n/** react-three-map store */\nexport interface R3mStore {\n fromLngLat: FromLngLat,\n map?: MapInstance;\n mapCamMx?: Matrix4Tuple;\n state?: RootState\n root?: ReconcilerRoot<HTMLCanvasElement>;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const useR3M = (): R3mStore => useThree((s: any) => s.r3m);"],"names":["useR3M","useThree","s"],"mappings":";AAcO,MAAMA,IAAS,MAAgBC,EAAS,CAACC,MAAWA,EAAE,GAAG;"}
@@ -1,16 +1,9 @@
1
- import { Matrix4 as u } from "three";
2
- import { useFunction as m } from "./main8.mjs";
3
- const p = new u();
4
- function g(n, r, o) {
5
- return m((l, a) => {
6
- var e;
7
- if (!((e = r.current) != null && e.state))
8
- return;
9
- const t = r.current.state.camera, c = r.current.state.gl, i = r.current.state.advance;
10
- t.projectionMatrix.fromArray(a).multiply(p.fromArray(n)), t.projectionMatrixInverse.copy(t.projectionMatrix).invert(), c.resetState(), i(Date.now() * 1e-3, !0), o === "always" && r.current.map.triggerRepaint();
11
- });
1
+ import { Matrix4 as i } from "three";
2
+ const n = new i();
3
+ function p(r, o, t) {
4
+ r.projectionMatrix.fromArray(t).multiply(n.fromArray(o)), r.projectionMatrixInverse.copy(r.projectionMatrix).invert();
12
5
  }
13
6
  export {
14
- g as useRender
7
+ p as syncCamera
15
8
  };
16
9
  //# sourceMappingURL=main6.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"main6.mjs","sources":["../../../src/core/use-render.ts"],"sourcesContent":["import { Matrix4, Matrix4Tuple } from \"three\";\nimport { StateRef } from \"./state-ref\";\nimport { useFunction } from \"./use-function\";\n\nconst mx = new Matrix4();\n\nexport function useRender(\n m4: Matrix4Tuple, stateRef: StateRef, frameloop: 'always' | 'demand'\n) {\n\n const render = useFunction((_gl: WebGL2RenderingContext, matrix: number[]) => {\n if (!stateRef.current?.state) return;\n const camera = stateRef.current.state.camera;\n const gl = stateRef.current.state.gl;\n const advance = stateRef.current.state.advance;\n camera.projectionMatrix.fromArray(matrix).multiply(mx.fromArray(m4));\n camera.projectionMatrixInverse.copy(camera.projectionMatrix).invert();\n gl.resetState();\n advance(Date.now() * 0.001, true);\n if (frameloop === 'always') stateRef.current.map.triggerRepaint();\n })\n\n return render;\n\n}"],"names":["mx","Matrix4","useRender","m4","stateRef","frameloop","useFunction","_gl","matrix","_a","camera","gl","advance"],"mappings":";;AAIA,MAAMA,IAAK,IAAIC;AAEC,SAAAC,EACdC,GAAkBC,GAAoBC,GACtC;AAcO,SAZQC,EAAY,CAACC,GAA6BC,MAAqB;;AACxE,QAAA,GAACC,IAAAL,EAAS,YAAT,QAAAK,EAAkB;AAAO;AACxB,UAAAC,IAASN,EAAS,QAAQ,MAAM,QAChCO,IAAKP,EAAS,QAAQ,MAAM,IAC5BQ,IAAUR,EAAS,QAAQ,MAAM;AAChC,IAAAM,EAAA,iBAAiB,UAAUF,CAAM,EAAE,SAASR,EAAG,UAAUG,CAAE,CAAC,GACnEO,EAAO,wBAAwB,KAAKA,EAAO,gBAAgB,EAAE,UAC7DC,EAAG,WAAW,GACdC,EAAQ,KAAK,IAAQ,IAAA,MAAO,EAAI,GAC5BP,MAAc,YAAmBD,EAAA,QAAQ,IAAI;EAAe,CACjE;AAIH;"}
1
+ {"version":3,"file":"main6.mjs","sources":["../../../src/core/sync-camera.ts"],"sourcesContent":["import { Matrix4, Matrix4Tuple, PerspectiveCamera } from \"three\";\n\nconst mx = new Matrix4();\n\nexport function syncCamera(camera: PerspectiveCamera, origin: Matrix4Tuple, mapCamMx: Matrix4Tuple) {\n camera.projectionMatrix.fromArray(mapCamMx).multiply(mx.fromArray(origin));\n camera.projectionMatrixInverse.copy(camera.projectionMatrix).invert();\n}"],"names":["mx","Matrix4","syncCamera","camera","origin","mapCamMx"],"mappings":";AAEA,MAAMA,IAAK,IAAIC;AAEC,SAAAC,EAAWC,GAA2BC,GAAsBC,GAAwB;AAC3F,EAAAF,EAAA,iBAAiB,UAAUE,CAAQ,EAAE,SAASL,EAAG,UAAUI,CAAM,CAAC,GACzED,EAAO,wBAAwB,KAAKA,EAAO,gBAAgB,EAAE;AAC/D;"}
@@ -1,56 +1,14 @@
1
- import { createEvents as p } from "@react-three/fiber";
2
- const c = {
3
- onClick: ["click", !1],
4
- onContextMenu: ["contextmenu", !1],
5
- onDoubleClick: ["dblclick", !1],
6
- onWheel: ["wheel", !0],
7
- onPointerDown: ["pointerdown", !0],
8
- onPointerUp: ["pointerup", !0],
9
- onPointerLeave: ["pointerleave", !0],
10
- onPointerMove: ["pointermove", !0],
11
- onPointerCancel: ["pointercancel", !0],
12
- onLostPointerCapture: ["lostpointercapture", !0]
13
- };
14
- function u() {
15
- return (o) => {
16
- const { handlePointer: a } = p(o);
17
- return {
18
- priority: 1,
19
- enabled: !0,
20
- compute(n, e) {
21
- e.size.width = e.gl.domElement.width / window.devicePixelRatio, e.size.height = e.gl.domElement.height / window.devicePixelRatio, e.pointer.x = n.offsetX / e.size.width * 2 - 1, e.pointer.y = 1 - n.offsetY / e.size.height * 2, e.raycaster.camera = e.camera, e.raycaster.ray.origin.setScalar(0).applyMatrix4(e.camera.projectionMatrixInverse), e.raycaster.ray.direction.set(e.pointer.x, e.pointer.y, 1).applyMatrix4(e.camera.projectionMatrixInverse).sub(e.raycaster.ray.origin).normalize();
22
- },
23
- connected: void 0,
24
- handlers: Object.keys(c).reduce(
25
- (n, e) => ({ ...n, [e]: a(e) }),
26
- {}
27
- ),
28
- update: () => {
29
- var t;
30
- const { events: n, internal: e } = o.getState();
31
- (t = e.lastEvent) != null && t.current && n.handlers && n.handlers.onPointerMove(e.lastEvent.current);
32
- },
33
- connect: (n) => {
34
- var i;
35
- const { set: e, events: t } = o.getState();
36
- (i = t.disconnect) == null || i.call(t), e((r) => ({ events: { ...r.events, connected: n.parentNode } })), Object.entries(t.handlers ?? []).forEach(([r, l]) => {
37
- const [s, d] = c[r];
38
- n.addEventListener(s, l, { passive: d });
39
- });
40
- },
41
- disconnect: () => {
42
- const { set: n, events: e } = o.getState();
43
- e.connected && (Object.entries(e.handlers ?? []).forEach(([t, i]) => {
44
- if (e && e.connected instanceof HTMLElement) {
45
- const [r] = c[t];
46
- e.connected.removeEventListener(r, i);
47
- }
48
- }), n((t) => ({ events: { ...t.events, connected: void 0 } })));
49
- }
50
- };
51
- };
1
+ import { useMemo as c } from "react";
2
+ import { coordsToMatrix as p } from "./main10.mjs";
3
+ function x({ latitude: o, longitude: r, altitude: m, fromLngLat: s }) {
4
+ return c(() => p({
5
+ latitude: o,
6
+ longitude: r,
7
+ altitude: m,
8
+ fromLngLat: s
9
+ }), [o, r, m, s]);
52
10
  }
53
11
  export {
54
- u as createEvents
12
+ x as useCoords
55
13
  };
56
14
  //# sourceMappingURL=main7.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"main7.mjs","sources":["../../../src/core/create-events.ts"],"sourcesContent":["import { Events, RenderProps, RootState, createEvents as createFiberEvents } from \"@react-three/fiber\";\nimport { UseBoundStore } from \"zustand\";\n\ntype DomEvent = PointerEvent | MouseEvent | WheelEvent;\n\nconst DOM_EVENTS = {\n onClick: [\"click\", false],\n onContextMenu: [\"contextmenu\", false],\n onDoubleClick: [\"dblclick\", false],\n onWheel: [\"wheel\", true],\n onPointerDown: [\"pointerdown\", true],\n onPointerUp: [\"pointerup\", true],\n onPointerLeave: [\"pointerleave\", true],\n onPointerMove: [\"pointermove\", true],\n onPointerCancel: [\"pointercancel\", true],\n onLostPointerCapture: [\"lostpointercapture\", true],\n} as const;\n\n/** ThreeLayer event manager for MapLibre and Mapbox */\nexport function createEvents(): RenderProps<HTMLCanvasElement>[\"events\"] {\n return (store: UseBoundStore<RootState>) => {\n const { handlePointer } = createFiberEvents(store);\n return {\n priority: 1,\n enabled: true,\n compute(event: DomEvent, state: RootState) {\n state.size.width = state.gl.domElement.width / window.devicePixelRatio;\n state.size.height = state.gl.domElement.height / window.devicePixelRatio;\n state.pointer.x = (event.offsetX / state.size.width) * 2 - 1;\n state.pointer.y = 1 - (event.offsetY / state.size.height) * 2;\n state.raycaster.camera = state.camera;\n state.raycaster.ray.origin.setScalar(0).applyMatrix4(state.camera.projectionMatrixInverse);\n state.raycaster.ray.direction\n .set(state.pointer.x, state.pointer.y, 1)\n .applyMatrix4(state.camera.projectionMatrixInverse)\n .sub(state.raycaster.ray.origin)\n .normalize();\n },\n connected: undefined,\n handlers: Object.keys(DOM_EVENTS).reduce(\n (acc, key) => ({ ...acc, [key]: handlePointer(key) }),\n {}\n ) as unknown as Events,\n update: () => {\n const { events, internal } = store.getState();\n if (internal.lastEvent?.current && events.handlers) {\n events.handlers.onPointerMove(internal.lastEvent.current);\n }\n },\n connect: (target: HTMLElement) => {\n const { set, events } = store.getState();\n events.disconnect?.();\n set((state) => ({ events: { ...state.events, connected: target.parentNode } }));\n Object.entries(events.handlers ?? []).forEach(([name, event]) => {\n const [eventName, passive] = DOM_EVENTS[name as keyof typeof DOM_EVENTS];\n target.addEventListener(eventName, event, { passive });\n });\n },\n disconnect: () => {\n const { set, events } = store.getState();\n if (events.connected) {\n Object.entries(events.handlers ?? []).forEach(([name, event]) => {\n if (events && events.connected instanceof HTMLElement) {\n const [eventName] = DOM_EVENTS[name as keyof typeof DOM_EVENTS];\n events.connected.removeEventListener(eventName, event);\n }\n });\n set((state) => ({ events: { ...state.events, connected: undefined } }));\n }\n },\n };\n };\n}\n"],"names":["DOM_EVENTS","createEvents","store","handlePointer","createFiberEvents","event","state","acc","key","events","internal","_a","target","set","name","eventName","passive"],"mappings":"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"}
1
+ {"version":3,"file":"main7.mjs","sources":["../../../src/core/use-coords.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport { coordsToMatrix } from \"./coords-to-matrix\";\n\ntype Props = Parameters<typeof coordsToMatrix>[0];\n\n/** calculate matrix from coordinates */\nexport function useCoords({latitude, longitude, altitude, fromLngLat}: Props) {\n const m4 = useMemo(() => coordsToMatrix({\n latitude, longitude, altitude, fromLngLat,\n }), [latitude, longitude, altitude, fromLngLat]);\n\n return m4;\n}"],"names":["useCoords","latitude","longitude","altitude","fromLngLat","useMemo","coordsToMatrix"],"mappings":";;AAMO,SAASA,EAAU,EAAC,UAAAC,GAAU,WAAAC,GAAW,UAAAC,GAAU,YAAAC,KAAoB;AAKrE,SAJIC,EAAQ,MAAMC,EAAe;AAAA,IACtC,UAAAL;AAAA,IAAU,WAAAC;AAAA,IAAW,UAAAC;AAAA,IAAU,YAAAC;AAAA,EAAA,CAChC,GAAG,CAACH,GAAUC,GAAWC,GAAUC,CAAU,CAAC;AAGjD;"}
@@ -1,9 +1,18 @@
1
- import { useRef as n, useCallback as u } from "react";
2
- const o = (r) => {
3
- const e = n(r);
4
- return e.current = r, u((...t) => e.current(...t), []);
1
+ import { jsx as d, Fragment as c } from "react/jsx-runtime";
2
+ import { useId as i, useEffect as p } from "react";
3
+ import { useOnAdd as R } from "./main11.mjs";
4
+ const g = ({
5
+ children: o,
6
+ frameloop: t,
7
+ fromLngLat: n,
8
+ ...m
9
+ }) => {
10
+ const u = i(), { onAdd: f, onRemove: s, mounted: e, r3mRef: r } = R(n, { frameloop: t, ...m });
11
+ return p(() => {
12
+ e && r.current.root && r.current.root.render(/* @__PURE__ */ d(c, { children: o }));
13
+ }, [r, e, o]), { id: u, onAdd: f, onRemove: s, r3mRef: r };
5
14
  };
6
15
  export {
7
- o as useFunction
16
+ g as useCreateRoot
8
17
  };
9
18
  //# sourceMappingURL=main8.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"main8.mjs","sources":["../../../src/core/use-function.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nexport const useFunction = <T extends (...args: any[]) => any>(callback: T): T => {\n const callbackRef = useRef(callback);\n callbackRef.current = callback;\n return useCallback((...args: any[]) => {\n return callbackRef.current(...args);\n }, []) as T;\n};\n"],"names":["useFunction","callback","callbackRef","useRef","useCallback","args"],"mappings":";AAGa,MAAAA,IAAc,CAAoCC,MAAmB;AAC1E,QAAAC,IAAcC,EAAOF,CAAQ;AACnC,SAAAC,EAAY,UAAUD,GACfG,EAAY,IAAIC,MACdH,EAAY,QAAQ,GAAGG,CAAI,GACjC,CAAE,CAAA;AACP;"}
1
+ {"version":3,"file":"main8.mjs","sources":["../../../src/core/use-create-root.tsx"],"sourcesContent":["import { RenderProps } from \"@react-three/fiber\";\nimport { PropsWithChildren, useEffect, useId } from \"react\";\nimport { FromLngLat } from \"./generic-map\";\nimport { useOnAdd } from \"./use-on-add\";\n\nexport interface useCanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {\n frameloop: 'always' | 'demand',\n fromLngLat: FromLngLat\n}\n\nexport const useCreateRoot = (({\n children, frameloop, fromLngLat, ...renderProps\n}: useCanvasProps) => {\n\n const id = useId();\n\n const { onAdd, onRemove, mounted, r3mRef } = useOnAdd(fromLngLat, { frameloop, ...renderProps });\n\n useEffect(() => {\n if (!mounted) return;\n if (!r3mRef.current.root) return;\n r3mRef.current.root.render(<>\n {children}\n </>);\n }, [r3mRef, mounted, children])\n\n return { id, onAdd, onRemove, r3mRef }\n})"],"names":["useCreateRoot","children","frameloop","fromLngLat","renderProps","id","useId","onAdd","onRemove","mounted","r3mRef","useOnAdd","useEffect","jsx","Fragment"],"mappings":";;;AAUO,MAAMA,IAAiB,CAAC;AAAA,EAC7B,UAAAC;AAAA,EAAU,WAAAC;AAAA,EAAW,YAAAC;AAAA,EAAY,GAAGC;AACtC,MAAsB;AAEpB,QAAMC,IAAKC,KAEL,EAAE,OAAAC,GAAO,UAAAC,GAAU,SAAAC,GAAS,QAAAC,EAAO,IAAIC,EAASR,GAAY,EAAE,WAAAD,GAAW,GAAGE,EAAa,CAAA;AAE/F,SAAAQ,EAAU,MAAM;AACd,IAAKH,KACAC,EAAO,QAAQ,QACpBA,EAAO,QAAQ,KAAK,OAAO,gBAAAG,EAAAC,GAAA,EACxB,UAAAb,EACH,CAAA,CAAG;AAAA,EACF,GAAA,CAACS,GAAQD,GAASR,CAAQ,CAAC,GAEvB,EAAE,IAAAI,GAAI,OAAAE,GAAO,UAAAC,GAAU,QAAAE,EAAO;AACvC;"}
@@ -0,0 +1,15 @@
1
+ import { syncCamera as m } from "./main6.mjs";
2
+ import { useFunction as i } from "./main12.mjs";
3
+ function g(r, a, n) {
4
+ return i((p, t) => {
5
+ const e = a.current;
6
+ if (!e.state || !e.map)
7
+ return;
8
+ const s = e.state.camera, c = e.state.gl, o = e.state.advance;
9
+ e.mapCamMx = t, m(s, r, t), c.resetState(), o(Date.now() * 1e-3, !0), n === "always" && e.map.triggerRepaint();
10
+ });
11
+ }
12
+ export {
13
+ g as useRender
14
+ };
15
+ //# sourceMappingURL=main9.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main9.mjs","sources":["../../../src/core/use-render.ts"],"sourcesContent":["import { MutableRefObject } from \"react\";\nimport { Matrix4Tuple, PerspectiveCamera } from \"three\";\nimport { R3mStore } from \"./store\";\nimport { syncCamera } from \"./sync-camera\";\nimport { useFunction } from \"./use-function\";\n\nexport function useRender(\n origin: Matrix4Tuple, r3mRef: MutableRefObject<R3mStore>, frameloop: 'always' | 'demand'\n) {\n\n const render = useFunction((_gl: WebGL2RenderingContext, mapCamMx: number[]) => {\n const r3m = r3mRef.current;\n if (!r3m.state || !r3m.map) return;\n const camera = r3m.state.camera;\n const gl = r3m.state.gl;\n const advance = r3m.state.advance;\n r3m.mapCamMx = mapCamMx as Matrix4Tuple;\n syncCamera(camera as PerspectiveCamera, origin, mapCamMx as Matrix4Tuple);\n gl.resetState();\n advance(Date.now() * 0.001, true);\n if (frameloop === 'always') r3m.map.triggerRepaint();\n })\n\n return render;\n\n}"],"names":["useRender","origin","r3mRef","frameloop","useFunction","_gl","mapCamMx","r3m","camera","gl","advance","syncCamera"],"mappings":";;AAMgB,SAAAA,EACdC,GAAsBC,GAAoCC,GAC1D;AAeO,SAbQC,EAAY,CAACC,GAA6BC,MAAuB;AAC9E,UAAMC,IAAML,EAAO;AACnB,QAAI,CAACK,EAAI,SAAS,CAACA,EAAI;AAAK;AACtB,UAAAC,IAASD,EAAI,MAAM,QACnBE,IAAKF,EAAI,MAAM,IACfG,IAAUH,EAAI,MAAM;AAC1B,IAAAA,EAAI,WAAWD,GACJK,EAAAH,GAA6BP,GAAQK,CAAwB,GACxEG,EAAG,WAAW,GACdC,EAAQ,KAAK,IAAQ,IAAA,MAAO,EAAI,GAC5BP,MAAc,YAAUI,EAAI,IAAI;EAAe,CACpD;AAIH;"}
@@ -0,0 +1,8 @@
1
+ import { RenderProps } from "@react-three/fiber";
2
+ import { PropsWithChildren } from "react";
3
+ export interface CanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {
4
+ longitude: number;
5
+ latitude: number;
6
+ altitude?: number;
7
+ frameloop?: 'always' | 'demand';
8
+ }
@@ -0,0 +1,7 @@
1
+ import { PropsWithChildren } from "react";
2
+ export interface CoordinatesProps extends PropsWithChildren {
3
+ longitude: number;
4
+ latitude: number;
5
+ altitude?: number;
6
+ }
7
+ export declare const Coordinates: import("react").NamedExoticComponent<CoordinatesProps>;
@@ -0,0 +1,12 @@
1
+ import { ReconcilerRoot, RootState } from "@react-three/fiber";
2
+ import { Matrix4Tuple } from "three";
3
+ import { FromLngLat, MapInstance } from "./generic-map";
4
+ /** react-three-map store */
5
+ export interface R3mStore {
6
+ fromLngLat: FromLngLat;
7
+ map?: MapInstance;
8
+ mapCamMx?: Matrix4Tuple;
9
+ state?: RootState;
10
+ root?: ReconcilerRoot<HTMLCanvasElement>;
11
+ }
12
+ export declare const useR3M: () => R3mStore;
@@ -0,0 +1,2 @@
1
+ import { Matrix4Tuple, PerspectiveCamera } from "three";
2
+ export declare function syncCamera(camera: PerspectiveCamera, origin: Matrix4Tuple, mapCamMx: Matrix4Tuple): void;
@@ -1,13 +1,11 @@
1
- import { RenderProps } from "@react-three/fiber";
2
- import { PropsWithChildren } from "react";
3
- import { Matrix4Tuple } from "three";
4
- export interface useCanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {
5
- frameloop: 'always' | 'demand';
6
- m4: Matrix4Tuple;
1
+ import { CanvasProps } from "../api/canvas-props";
2
+ import { FromLngLat } from "./generic-map";
3
+ export interface useCanvasProps extends CanvasProps {
4
+ fromLngLat: FromLngLat;
7
5
  }
8
- export declare const useCanvas: ({ m4, children, frameloop, ...renderProps }: useCanvasProps) => {
6
+ export declare function useCanvas({ longitude, latitude, altitude, frameloop, fromLngLat, ...renderProps }: useCanvasProps): {
9
7
  id: string;
10
8
  onAdd: (map: import("./generic-map").MapInstance, gl: WebGLRenderingContext) => void;
11
- onRemove: (map: import("./generic-map").MapInstance) => void;
12
- render: (_gl: WebGL2RenderingContext, matrix: number[]) => void;
9
+ onRemove: () => void;
10
+ render: (_gl: WebGL2RenderingContext, mapCamMx: number[]) => void;
13
11
  };
@@ -0,0 +1,5 @@
1
+ import { coordsToMatrix } from "./coords-to-matrix";
2
+ type Props = Parameters<typeof coordsToMatrix>[0];
3
+ /** calculate matrix from coordinates */
4
+ export declare function useCoords({ latitude, longitude, altitude, fromLngLat }: Props): import("three").Matrix4Tuple;
5
+ export {};
@@ -0,0 +1,13 @@
1
+ import { RenderProps } from "@react-three/fiber";
2
+ import { PropsWithChildren } from "react";
3
+ import { FromLngLat } from "./generic-map";
4
+ export interface useCanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {
5
+ frameloop: 'always' | 'demand';
6
+ fromLngLat: FromLngLat;
7
+ }
8
+ export declare const useCreateRoot: ({ children, frameloop, fromLngLat, ...renderProps }: useCanvasProps) => {
9
+ id: string;
10
+ onAdd: (map: import("./generic-map").MapInstance, gl: WebGLRenderingContext) => void;
11
+ onRemove: () => void;
12
+ r3mRef: import("react").MutableRefObject<import("./store").R3mStore>;
13
+ };
@@ -1,8 +1,10 @@
1
+ /// <reference types="react" />
1
2
  import { RenderProps } from "@react-three/fiber";
2
- import { MapInstance } from "./generic-map";
3
- import { StateRef } from "./state-ref";
4
- export declare function useOnAdd(ref: StateRef, { frameloop, ...renderProps }: RenderProps<HTMLCanvasElement>): {
3
+ import { FromLngLat, MapInstance } from "./generic-map";
4
+ import { R3mStore } from "./store";
5
+ export declare function useOnAdd(fromLngLat: FromLngLat, { frameloop, ...renderProps }: RenderProps<HTMLCanvasElement>): {
5
6
  onAdd: (map: MapInstance, gl: WebGLRenderingContext) => void;
6
- onRemove: (map: MapInstance) => void;
7
+ onRemove: () => void;
7
8
  mounted: boolean;
9
+ r3mRef: import("react").MutableRefObject<R3mStore>;
8
10
  };
@@ -1,3 +1,4 @@
1
+ import { MutableRefObject } from "react";
1
2
  import { Matrix4Tuple } from "three";
2
- import { StateRef } from "./state-ref";
3
- export declare function useRender(m4: Matrix4Tuple, stateRef: StateRef, frameloop: 'always' | 'demand'): (_gl: WebGL2RenderingContext, matrix: number[]) => void;
3
+ import { R3mStore } from "./store";
4
+ export declare function useRender(origin: Matrix4Tuple, r3mRef: MutableRefObject<R3mStore>, frameloop: 'always' | 'demand'): (_gl: WebGL2RenderingContext, mapCamMx: number[]) => void;
@@ -1,10 +1,4 @@
1
- import { RenderProps } from "@react-three/fiber";
2
- import { PropsWithChildren } from "react";
3
- export interface CanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {
4
- longitude: number;
5
- latitude: number;
6
- altitude?: number;
7
- frameloop?: 'always' | 'demand';
8
- }
1
+ /// <reference types="react" />
2
+ import { CanvasProps } from "../api/canvas-props";
9
3
  /** react`-three-fiber` canvas inside `MapLibre` */
10
4
  export declare const Canvas: import("react").NamedExoticComponent<CanvasProps>;
@@ -1 +1,3 @@
1
1
  export * from './maplibre/canvas';
2
+ export * from './api/canvas-props';
3
+ export * from './api/coordinates';
@@ -0,0 +1,8 @@
1
+ import { RenderProps } from "@react-three/fiber";
2
+ import { PropsWithChildren } from "react";
3
+ export interface CanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {
4
+ longitude: number;
5
+ latitude: number;
6
+ altitude?: number;
7
+ frameloop?: 'always' | 'demand';
8
+ }
@@ -0,0 +1,7 @@
1
+ import { PropsWithChildren } from "react";
2
+ export interface CoordinatesProps extends PropsWithChildren {
3
+ longitude: number;
4
+ latitude: number;
5
+ altitude?: number;
6
+ }
7
+ export declare const Coordinates: import("react").NamedExoticComponent<CoordinatesProps>;
@@ -0,0 +1,12 @@
1
+ import { ReconcilerRoot, RootState } from "@react-three/fiber";
2
+ import { Matrix4Tuple } from "three";
3
+ import { FromLngLat, MapInstance } from "./generic-map";
4
+ /** react-three-map store */
5
+ export interface R3mStore {
6
+ fromLngLat: FromLngLat;
7
+ map?: MapInstance;
8
+ mapCamMx?: Matrix4Tuple;
9
+ state?: RootState;
10
+ root?: ReconcilerRoot<HTMLCanvasElement>;
11
+ }
12
+ export declare const useR3M: () => R3mStore;
@@ -0,0 +1,2 @@
1
+ import { Matrix4Tuple, PerspectiveCamera } from "three";
2
+ export declare function syncCamera(camera: PerspectiveCamera, origin: Matrix4Tuple, mapCamMx: Matrix4Tuple): void;
@@ -1,13 +1,11 @@
1
- import { RenderProps } from "@react-three/fiber";
2
- import { PropsWithChildren } from "react";
3
- import { Matrix4Tuple } from "three";
4
- export interface useCanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {
5
- frameloop: 'always' | 'demand';
6
- m4: Matrix4Tuple;
1
+ import { CanvasProps } from "../api/canvas-props";
2
+ import { FromLngLat } from "./generic-map";
3
+ export interface useCanvasProps extends CanvasProps {
4
+ fromLngLat: FromLngLat;
7
5
  }
8
- export declare const useCanvas: ({ m4, children, frameloop, ...renderProps }: useCanvasProps) => {
6
+ export declare function useCanvas({ longitude, latitude, altitude, frameloop, fromLngLat, ...renderProps }: useCanvasProps): {
9
7
  id: string;
10
8
  onAdd: (map: import("./generic-map").MapInstance, gl: WebGLRenderingContext) => void;
11
- onRemove: (map: import("./generic-map").MapInstance) => void;
12
- render: (_gl: WebGL2RenderingContext, matrix: number[]) => void;
9
+ onRemove: () => void;
10
+ render: (_gl: WebGL2RenderingContext, mapCamMx: number[]) => void;
13
11
  };
@@ -0,0 +1,5 @@
1
+ import { coordsToMatrix } from "./coords-to-matrix";
2
+ type Props = Parameters<typeof coordsToMatrix>[0];
3
+ /** calculate matrix from coordinates */
4
+ export declare function useCoords({ latitude, longitude, altitude, fromLngLat }: Props): import("three").Matrix4Tuple;
5
+ export {};
@@ -0,0 +1,13 @@
1
+ import { RenderProps } from "@react-three/fiber";
2
+ import { PropsWithChildren } from "react";
3
+ import { FromLngLat } from "./generic-map";
4
+ export interface useCanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {
5
+ frameloop: 'always' | 'demand';
6
+ fromLngLat: FromLngLat;
7
+ }
8
+ export declare const useCreateRoot: ({ children, frameloop, fromLngLat, ...renderProps }: useCanvasProps) => {
9
+ id: string;
10
+ onAdd: (map: import("./generic-map").MapInstance, gl: WebGLRenderingContext) => void;
11
+ onRemove: () => void;
12
+ r3mRef: import("react").MutableRefObject<import("./store").R3mStore>;
13
+ };
@@ -1,8 +1,10 @@
1
+ /// <reference types="react" />
1
2
  import { RenderProps } from "@react-three/fiber";
2
- import { MapInstance } from "./generic-map";
3
- import { StateRef } from "./state-ref";
4
- export declare function useOnAdd(ref: StateRef, { frameloop, ...renderProps }: RenderProps<HTMLCanvasElement>): {
3
+ import { FromLngLat, MapInstance } from "./generic-map";
4
+ import { R3mStore } from "./store";
5
+ export declare function useOnAdd(fromLngLat: FromLngLat, { frameloop, ...renderProps }: RenderProps<HTMLCanvasElement>): {
5
6
  onAdd: (map: MapInstance, gl: WebGLRenderingContext) => void;
6
- onRemove: (map: MapInstance) => void;
7
+ onRemove: () => void;
7
8
  mounted: boolean;
9
+ r3mRef: import("react").MutableRefObject<R3mStore>;
8
10
  };
@@ -1,3 +1,4 @@
1
+ import { MutableRefObject } from "react";
1
2
  import { Matrix4Tuple } from "three";
2
- import { StateRef } from "./state-ref";
3
- export declare function useRender(m4: Matrix4Tuple, stateRef: StateRef, frameloop: 'always' | 'demand'): (_gl: WebGL2RenderingContext, matrix: number[]) => void;
3
+ import { R3mStore } from "./store";
4
+ export declare function useRender(origin: Matrix4Tuple, r3mRef: MutableRefObject<R3mStore>, frameloop: 'always' | 'demand'): (_gl: WebGL2RenderingContext, mapCamMx: number[]) => void;
@@ -1,10 +1,4 @@
1
- import { RenderProps } from "@react-three/fiber";
2
- import { PropsWithChildren } from "react";
3
- export interface CanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'frameloop'>, PropsWithChildren {
4
- longitude: number;
5
- latitude: number;
6
- altitude?: number;
7
- frameloop?: 'always' | 'demand';
8
- }
9
- /** react`-three-fiber` canvas inside `MapLibre` */
1
+ /// <reference types="react" />
2
+ import { CanvasProps } from "../api/canvas-props";
3
+ /** react`-three-fiber` canvas inside `Mapbox` */
10
4
  export declare const Canvas: import("react").NamedExoticComponent<CanvasProps>;
@@ -1 +1,3 @@
1
1
  export * from './mapbox/canvas';
2
+ export * from './api/canvas-props';
3
+ export * from './api/coordinates';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-three-map",
3
- "version": "0.3.5",
3
+ "version": "0.4.0",
4
4
  "description": "Use react-three-fiber inside MapLibre and Mapbox",
5
5
  "main": "dist/cjs/main.js",
6
6
  "module": "dist/es/main.mjs",
@@ -21,11 +21,11 @@
21
21
  "build:mapbox": "cross-env LIB_MODE=1 MAP_MODE=1 vite build",
22
22
  "postbuild:mapbox": "cross-env LIB_MODE=2 MAP_MODE=1 vite build",
23
23
  "release": "yarn build && yarn changeset publish",
24
- "lint": "eslint src example-maplibre/src example-mapbox/src --ext ts,tsx --fix",
24
+ "lint": "eslint src example-maplibre/src example-mapbox/src stories --ext ts,tsx --fix",
25
25
  "preview": "vite preview",
26
26
  "ts": "tsc -w",
27
27
  "ts:check": "tsc",
28
- "stories": "yarn ladle serve",
28
+ "dev": "yarn ladle serve",
29
29
  "build:stories": "yarn ladle build"
30
30
  },
31
31
  "dependencies": {},
@@ -37,7 +37,7 @@
37
37
  "@types/node": "^20.3.1",
38
38
  "@types/react": "^18.0.37",
39
39
  "@types/react-dom": "^18.0.11",
40
- "@types/three": "^0.152.1",
40
+ "@types/three": "^0.154.0",
41
41
  "@typescript-eslint/eslint-plugin": "^5.59.11",
42
42
  "@typescript-eslint/parser": "^5.59.11",
43
43
  "@vitejs/plugin-react": "^4.0.0",
@@ -55,7 +55,7 @@
55
55
  "three": "^0.153.0",
56
56
  "three-stdlib": "^2.23.8",
57
57
  "typescript": "~5.0.2",
58
- "vite": "^4.3.9",
58
+ "vite": "^4.4.4",
59
59
  "web-ifc-three": "^0.0.125"
60
60
  },
61
61
  "peerDependencies": {
@@ -0,0 +1 @@
1
+ This folder is being used as both a CodeSandbox CI and also as the main main stories from the root folder.
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "stories",
3
+ "version": "0.0.0",
4
+ "license": "MIT",
5
+ "scripts": {
6
+ "dev": "yarn ladle serve"
7
+ },
8
+ "dependencies": {
9
+ "@ladle/react": "^2.16.0",
10
+ "@react-three/drei": "^9.78.2",
11
+ "@react-three/fiber": "^8.13.5",
12
+ "leva": "^0.9.35",
13
+ "mapbox-gl": "^2.15.0",
14
+ "maplibre-gl": "^3.2.0",
15
+ "react": "^18.2.0",
16
+ "react-dom": "^18.2.0",
17
+ "react-map-gl": "^7.1.2",
18
+ "react-three-map": "^0.3.5",
19
+ "three": "^0.154.0",
20
+ "three-stdlib": "^2.23.13",
21
+ "web-ifc-three": "^0.0.125"
22
+ },
23
+ "devDependencies": {
24
+ "@types/react": "^18.2.15",
25
+ "@types/react-dom": "^18.2.7",
26
+ "@types/three": "^0.154.0",
27
+ "@vitejs/plugin-react": "^4.0.3",
28
+ "typescript": "^5.1.6",
29
+ "vite": "^4.4.4"
30
+ }
31
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "port": 61000
3
+ }