react-three-map 0.1.2 → 0.1.3
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/cjs/main.js.js +1 -1
- package/dist/es/main.js4.mjs +32 -26
- package/dist/es/main.js4.mjs.map +1 -1
- package/package.json +2 -4
package/dist/cjs/main.js.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react/jsx-runtime"),h=require("@react-three/fiber"),d=require("react"),w=require("react-map-gl/maplibre"),m=require("three"),E=require("maplibre-gl");function b(n){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const e=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(r,t,e.get?e:{enumerable:!0,get:()=>n[t]})}}return r.default=n,Object.freeze(r)}const j=b(m),x=new m.Quaternion,C=new m.Euler,y=new m.Vector3,M=new m.Vector3;function R({longitude:n,latitude:r,altitude:t}){const e=E.MercatorCoordinate.fromLngLat([n,r],t),o=e.meterInMercatorCoordinateUnits();return y.set(e.x,e.y,e.z||0),M.set(o,-o,o),x.setFromEuler(C.set(-Math.PI*.5,0,0)),new m.Matrix4().compose(y,x,M)}const g={onClick:["click",!1],onContextMenu:["contextmenu",!1],onDoubleClick:["dblclick",!1],onWheel:["wheel",!0],onPointerDown:["pointerdown",!0],onPointerUp:["pointerup",!0],onPointerLeave:["pointerleave",!0],onPointerMove:["pointermove",!0],onPointerCancel:["pointercancel",!0],onLostPointerCapture:["lostpointercapture",!0]};function z(){return n=>{const{handlePointer:r}=h.createEvents(n);return{priority:1,enabled:!0,compute(t,e){e.size.width=e.gl.domElement.width,e.size.height=e.gl.domElement.height,e.pointer.x=t.offsetX/(e.size.width/window.devicePixelRatio)*2-1,e.pointer.y=1-t.offsetY/(e.size.height/window.devicePixelRatio)*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()},connected:void 0,handlers:Object.keys(g).reduce((t,e)=>({...t,[e]:r(e)}),{}),update:()=>{var o;const{events:t,internal:e}=n.getState();(o=e.lastEvent)!=null&&o.current&&t.handlers&&t.handlers.onPointerMove(e.lastEvent.current)},connect:t=>{var s;const{set:e,events:o}=n.getState();(s=o.disconnect)==null||s.call(o),e(c=>({events:{...c.events,connected:t}})),Object.entries(o.handlers??[]).forEach(([c,i])=>{const[l,a]=g[c];t.addEventListener(l,i,{passive:a})})},disconnect:()=>{const{set:t,events:e}=n.getState();e.connected&&(Object.entries(e.handlers??[]).forEach(([o,s])=>{if(e&&e.connected instanceof HTMLElement){const[c]=g[o];e.connected.removeEventListener(c,s)}}),t(o=>({events:{...o.events,connected:void 0}})))}}}}const v=n=>{const r=d.useRef(n);return r.current=n,d.useCallback((...t)=>r.current(...t),[])};function S(n,r){const[t,e]=d.useState(!1),o=v((i,l)=>{const a=i.getCanvas(),u=h.createRoot(a);u.configure({frameloop:"never",dpr:window.devicePixelRatio,shadows:!0,events:z(),...r,gl:{context:l,depth:!0,autoClear:!1,antialias:!0,...r==null?void 0:r.gl},onCreated:f=>{n.current={state:f,map:i,root:u},f.gl.forceContextLoss=()=>{}},camera:{matrixAutoUpdate:!1},size:{width:a.clientWidth,height:a.clientHeight,top:0,left:0,...r==null?void 0:r.size}}),n.current={map:i,root:u},i.on("resize",s),setTimeout(()=>e(!0))}),s=v(()=>{var u;if(!((u=n.current)!=null&&u.state))return;const i=n.current.state,a=n.current.map.getCanvas();i.setSize(a.width,a.height)}),c=v(i=>{setTimeout(()=>{n.current&&(n.current.root.unmount(),i.off(c))})});return{onAdd:o,onRemove:c,mounted:t}}function O(n,r){const t=w.useMap();return v((o,s)=>{var a;if(!t.current||!((a=r.current)!=null&&a.state))return;const c=r.current.state.camera,i=r.current.state.gl,l=r.current.state.advance;c.projectionMatrix.fromArray(s).multiply(n),c.projectionMatrixInverse.copy(c.projectionMatrix).invert(),i.resetState(),l(Date.now()*.001,!0),t.current.triggerRepaint()})}h.extend(j);const L=d.memo(({longitude:n,latitude:r,altitude:t=0,children:e,...o})=>{const s=d.useId(),c=d.useRef(),i=d.useMemo(()=>R({latitude:r,longitude:n,altitude:t}),[r,n,t]),{onAdd:l,onRemove:a,mounted:u}=S(c,o),f=O(i,c);return d.useEffect(()=>{u&&c.current&&c.current.root.render(p.jsx(p.Fragment,{children:e}))},[c,u,e]),p.jsx(w.Layer,{id:s,type:"custom",renderingMode:"3d",onAdd:l,onRemove:a,render:f})});exports.Canvas=L;
|
package/dist/es/main.js4.mjs
CHANGED
|
@@ -1,51 +1,57 @@
|
|
|
1
|
-
import { createRoot as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
function C(e,
|
|
6
|
-
const [
|
|
7
|
-
const
|
|
8
|
-
|
|
1
|
+
import { createRoot as h } from "@react-three/fiber";
|
|
2
|
+
import { useState as g } from "react";
|
|
3
|
+
import { createEvents as v } from "./main.js6.mjs";
|
|
4
|
+
import { useFunction as a } from "./main.js7.mjs";
|
|
5
|
+
function C(e, o) {
|
|
6
|
+
const [m, l] = g(!1), r = a((t, u) => {
|
|
7
|
+
const n = t.getCanvas(), i = h(n);
|
|
8
|
+
i.configure({
|
|
9
9
|
frameloop: "never",
|
|
10
10
|
dpr: window.devicePixelRatio,
|
|
11
11
|
shadows: !0,
|
|
12
|
-
events:
|
|
13
|
-
...
|
|
12
|
+
events: v(),
|
|
13
|
+
...o,
|
|
14
14
|
gl: {
|
|
15
|
-
context:
|
|
15
|
+
context: u,
|
|
16
16
|
depth: !0,
|
|
17
17
|
autoClear: !1,
|
|
18
18
|
antialias: !0,
|
|
19
|
-
...
|
|
19
|
+
...o == null ? void 0 : o.gl
|
|
20
20
|
},
|
|
21
|
-
onCreated: (
|
|
21
|
+
onCreated: (s) => {
|
|
22
22
|
e.current = {
|
|
23
|
-
state:
|
|
24
|
-
map:
|
|
25
|
-
root:
|
|
26
|
-
},
|
|
23
|
+
state: s,
|
|
24
|
+
map: t,
|
|
25
|
+
root: i
|
|
26
|
+
}, s.gl.forceContextLoss = () => {
|
|
27
27
|
};
|
|
28
28
|
},
|
|
29
29
|
camera: {
|
|
30
30
|
matrixAutoUpdate: !1
|
|
31
31
|
},
|
|
32
32
|
size: {
|
|
33
|
-
width:
|
|
34
|
-
height:
|
|
33
|
+
width: n.clientWidth,
|
|
34
|
+
height: n.clientHeight,
|
|
35
35
|
top: 0,
|
|
36
36
|
left: 0,
|
|
37
|
-
...
|
|
37
|
+
...o == null ? void 0 : o.size
|
|
38
38
|
}
|
|
39
39
|
}), e.current = {
|
|
40
|
-
map:
|
|
41
|
-
root:
|
|
42
|
-
}, setTimeout(() =>
|
|
43
|
-
}),
|
|
40
|
+
map: t,
|
|
41
|
+
root: i
|
|
42
|
+
}, t.on("resize", f), setTimeout(() => l(!0));
|
|
43
|
+
}), f = a(() => {
|
|
44
|
+
var i;
|
|
45
|
+
if (!((i = e.current) != null && i.state))
|
|
46
|
+
return;
|
|
47
|
+
const t = e.current.state, n = e.current.map.getCanvas();
|
|
48
|
+
t.setSize(n.width, n.height);
|
|
49
|
+
}), c = a((t) => {
|
|
44
50
|
setTimeout(() => {
|
|
45
|
-
e.current && e.current.root.unmount();
|
|
51
|
+
e.current && (e.current.root.unmount(), t.off(c));
|
|
46
52
|
});
|
|
47
53
|
});
|
|
48
|
-
return { onAdd:
|
|
54
|
+
return { onAdd: r, onRemove: c, mounted: m };
|
|
49
55
|
}
|
|
50
56
|
export {
|
|
51
57
|
C as useOnAdd
|
package/dist/es/main.js4.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js4.mjs","sources":["../../src/canvas/use-on-add.ts"],"sourcesContent":["import { RenderProps, createRoot } from \"@react-three/fiber\";\nimport { MapInstance } from \"react-map-gl\";\nimport { createEvents } from \"./create-events\";\nimport { StateRef } from \"./state-ref\";\nimport { useFunction } from \"./use-function\";\
|
|
1
|
+
{"version":3,"file":"main.js4.mjs","sources":["../../src/canvas/use-on-add.ts"],"sourcesContent":["import { RenderProps, createRoot } from \"@react-three/fiber\";\nimport { useState } from \"react\";\nimport { MapInstance } from \"react-map-gl\";\nimport { createEvents } from \"./create-events\";\nimport { StateRef } from \"./state-ref\";\nimport { useFunction } from \"./use-function\";\n\nexport function useOnAdd (ref: StateRef, 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 frameloop: \"never\",\n dpr: window.devicePixelRatio,\n shadows: true,\n events: createEvents(),\n ...renderProps,\n gl: {\n context: gl,\n depth: true,\n autoClear: false,\n antialias: true,\n ...renderProps?.gl,\n },\n onCreated: (state) => {\n ref.current = {\n state,\n map,\n root,\n }\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n state.gl.forceContextLoss = () => { };\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(onRemove);\n })\n })\n\n return {onAdd, onRemove, mounted};\n}"],"names":["useOnAdd","ref","renderProps","mounted","setMounted","useState","onAdd","useFun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AQJ,EAAO,OAAOA,EAAO,MAAM;AAAA,EAAA,CAC1C,GAEKO,IAAWV,EAAY,CAACC,MAAmB;AAC/C,eAAW,MAAI;AACb,MAAIP,EAAI,YACJA,EAAA,QAAQ,KAAK,WACjBO,EAAI,IAAIS,CAAQ;AAAA,IAAA,CACjB;AAAA,EAAA,CACF;AAEM,SAAA,EAAC,OAAAX,GAAO,UAAAW,GAAU,SAAAd;AAC3B;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-three-map",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Use react-three-fiber inside MapLibre and Mapbox",
|
|
5
5
|
"main": "dist/cjs/main.js",
|
|
6
6
|
"module": "dist/es/main.js",
|
|
@@ -22,9 +22,7 @@
|
|
|
22
22
|
"preview": "vite preview",
|
|
23
23
|
"ts": "tsc -w",
|
|
24
24
|
"stories": "yarn ladle serve",
|
|
25
|
-
"build:stories": "yarn ladle build"
|
|
26
|
-
"release": "npm run publish",
|
|
27
|
-
"prerelease": "yarn build"
|
|
25
|
+
"build:stories": "yarn ladle build"
|
|
28
26
|
},
|
|
29
27
|
"dependencies": {},
|
|
30
28
|
"devDependencies": {
|