react-three-map 0.3.5 → 0.4.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/CHANGELOG.md +12 -0
- package/README.md +25 -0
- package/dist/cjs/main.js +337 -1
- package/dist/es/main.mjs +4 -2
- package/dist/es/main.mjs.map +1 -1
- package/dist/es/main10.mjs +18 -0
- package/dist/es/main10.mjs.map +1 -0
- package/dist/es/main11.mjs +66 -0
- package/dist/es/main11.mjs.map +1 -0
- package/dist/es/main12.mjs +12 -0
- package/dist/es/main12.mjs.map +1 -0
- package/dist/es/main13.mjs +83 -0
- package/dist/es/main13.mjs.map +1 -0
- package/dist/es/main2.mjs +18 -29
- package/dist/es/main2.mjs.map +1 -1
- package/dist/es/main3.mjs +52 -6
- package/dist/es/main3.mjs.map +1 -1
- package/dist/es/main4.mjs +22 -16
- package/dist/es/main4.mjs.map +1 -1
- package/dist/es/main5.mjs +3 -60
- package/dist/es/main5.mjs.map +1 -1
- package/dist/es/main6.mjs +33 -12
- package/dist/es/main6.mjs.map +1 -1
- package/dist/es/main7.mjs +11 -52
- package/dist/es/main7.mjs.map +1 -1
- package/dist/es/main8.mjs +20 -5
- package/dist/es/main8.mjs.map +1 -1
- package/dist/es/main9.mjs +23 -0
- package/dist/es/main9.mjs.map +1 -0
- package/dist/maplibre/cjs/main.js +337 -1
- package/dist/maplibre/es/main.mjs +4 -2
- package/dist/maplibre/es/main.mjs.map +1 -1
- package/dist/maplibre/es/main10.mjs +18 -0
- package/dist/maplibre/es/main10.mjs.map +1 -0
- package/dist/maplibre/es/main11.mjs +66 -0
- package/dist/maplibre/es/main11.mjs.map +1 -0
- package/dist/maplibre/es/main12.mjs +12 -0
- package/dist/maplibre/es/main12.mjs.map +1 -0
- package/dist/maplibre/es/main13.mjs +83 -0
- package/dist/maplibre/es/main13.mjs.map +1 -0
- package/dist/maplibre/es/main2.mjs +18 -29
- package/dist/maplibre/es/main2.mjs.map +1 -1
- package/dist/maplibre/es/main3.mjs +52 -6
- package/dist/maplibre/es/main3.mjs.map +1 -1
- package/dist/maplibre/es/main4.mjs +22 -16
- package/dist/maplibre/es/main4.mjs.map +1 -1
- package/dist/maplibre/es/main5.mjs +3 -60
- package/dist/maplibre/es/main5.mjs.map +1 -1
- package/dist/maplibre/es/main6.mjs +33 -12
- package/dist/maplibre/es/main6.mjs.map +1 -1
- package/dist/maplibre/es/main7.mjs +11 -52
- package/dist/maplibre/es/main7.mjs.map +1 -1
- package/dist/maplibre/es/main8.mjs +20 -5
- package/dist/maplibre/es/main8.mjs.map +1 -1
- package/dist/maplibre/es/main9.mjs +23 -0
- package/dist/maplibre/es/main9.mjs.map +1 -0
- package/dist/maplibre/types/api/canvas-props.d.ts +8 -0
- package/dist/maplibre/types/api/coordinates.d.ts +7 -0
- package/dist/maplibre/types/core/store.d.ts +12 -0
- package/dist/maplibre/types/core/sync-camera.d.ts +2 -0
- package/dist/maplibre/types/core/use-canvas.d.ts +7 -9
- package/dist/maplibre/types/core/use-coords.d.ts +5 -0
- package/dist/maplibre/types/core/use-create-root.d.ts +13 -0
- package/dist/maplibre/types/core/use-on-add.d.ts +6 -4
- package/dist/maplibre/types/core/use-render.d.ts +3 -2
- package/dist/maplibre/types/maplibre/canvas.d.ts +2 -8
- package/dist/maplibre/types/maplibre.index.d.ts +2 -0
- package/dist/types/api/canvas-props.d.ts +8 -0
- package/dist/types/api/coordinates.d.ts +7 -0
- package/dist/types/core/store.d.ts +12 -0
- package/dist/types/core/sync-camera.d.ts +2 -0
- package/dist/types/core/use-canvas.d.ts +7 -9
- package/dist/types/core/use-coords.d.ts +5 -0
- package/dist/types/core/use-create-root.d.ts +13 -0
- package/dist/types/core/use-on-add.d.ts +6 -4
- package/dist/types/core/use-render.d.ts +3 -2
- package/dist/types/mapbox/canvas.d.ts +3 -9
- package/dist/types/mapbox.index.d.ts +2 -0
- package/package.json +5 -5
- package/stories/README.md +1 -0
- package/stories/package.json +31 -0
- package/stories/sandbox.config.json +3 -0
- package/stories/yarn.lock +4295 -0
- package/dist/maplibre/types/core/state-ref.d.ts +0 -8
- package/dist/types/core/state-ref.d.ts +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# react-three-map
|
|
2
2
|
|
|
3
|
+
## 0.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 41dd225: Improve camera decomposition so the camera matrix and world matrix have more useful values.
|
|
8
|
+
|
|
9
|
+
## 0.4.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- bad8670: Add `<Coordinates>` component to render multiple 3D objects at different coordiantes.
|
|
14
|
+
|
|
3
15
|
## 0.3.5
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -138,3 +138,28 @@ Therefore, the following `<Canvas>` props are ignored:
|
|
|
138
138
|
- orthographic
|
|
139
139
|
- dpr
|
|
140
140
|
|
|
141
|
+
### Coordinates
|
|
142
|
+
|
|
143
|
+
[](https://rodrigohamuy.github.io/react-three-map/?story=multi-coordinates--default)
|
|
144
|
+
|
|
145
|
+
This component allows you to have 3D objects at different coordinates.
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
```tsx
|
|
149
|
+
import { Canvas, Coordinates } from 'react-three-map'
|
|
150
|
+
|
|
151
|
+
<Canvas latitude={51} longitude={0}>
|
|
152
|
+
<Coordinates latitude={50} longitude={0}>
|
|
153
|
+
<mesh><sphereGeometry /></mesh>
|
|
154
|
+
</Coordinates>
|
|
155
|
+
<Coordinates latitude={52} longitude={0}>
|
|
156
|
+
<mesh><sphereGeometry /></mesh>
|
|
157
|
+
</Coordinates>
|
|
158
|
+
</Canvas>
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
| Props | Description | Default |
|
|
162
|
+
| --------- | ------------------------------------------------ | ---------- |
|
|
163
|
+
| latitude | The latitude coordinate where to add the scene. | |
|
|
164
|
+
| longitude | The longitude coordinate where to add the scene. | |
|
|
165
|
+
| altitude | The altitude coordinate where to add the scene. | `0` |
|
package/dist/cjs/main.js
CHANGED
|
@@ -1 +1,337 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const fiber = require("@react-three/fiber");
|
|
5
|
+
const mapboxGl = require("mapbox-gl");
|
|
6
|
+
const react = require("react");
|
|
7
|
+
const reactMapGl = require("react-map-gl");
|
|
8
|
+
const THREE = require("three");
|
|
9
|
+
function _interopNamespaceDefault(e) {
|
|
10
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
11
|
+
if (e) {
|
|
12
|
+
for (const k in e) {
|
|
13
|
+
if (k !== "default") {
|
|
14
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: () => e[k]
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
n.default = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
const THREE__namespace = /* @__PURE__ */ _interopNamespaceDefault(THREE);
|
|
26
|
+
const quat = new THREE.Quaternion();
|
|
27
|
+
const euler = new THREE.Euler();
|
|
28
|
+
const pos = new THREE.Vector3();
|
|
29
|
+
const scale = new THREE.Vector3();
|
|
30
|
+
const m4 = new THREE.Matrix4();
|
|
31
|
+
function coordsToMatrix({ longitude, latitude, altitude, fromLngLat: fromLngLat2 }) {
|
|
32
|
+
const center = fromLngLat2([longitude, latitude], altitude);
|
|
33
|
+
const scaleUnit = center.meterInMercatorCoordinateUnits();
|
|
34
|
+
pos.set(center.x, center.y, center.z || 0);
|
|
35
|
+
scale.set(scaleUnit, -scaleUnit, scaleUnit);
|
|
36
|
+
quat.setFromEuler(euler.set(-Math.PI * 0.5, 0, 0));
|
|
37
|
+
return m4.compose(pos, quat, scale).toArray();
|
|
38
|
+
}
|
|
39
|
+
function useCoords({ latitude, longitude, altitude, fromLngLat: fromLngLat2 }) {
|
|
40
|
+
const m42 = react.useMemo(() => coordsToMatrix({
|
|
41
|
+
latitude,
|
|
42
|
+
longitude,
|
|
43
|
+
altitude,
|
|
44
|
+
fromLngLat: fromLngLat2
|
|
45
|
+
}), [latitude, longitude, altitude, fromLngLat2]);
|
|
46
|
+
return m42;
|
|
47
|
+
}
|
|
48
|
+
const DOM_EVENTS = {
|
|
49
|
+
onClick: ["click", false],
|
|
50
|
+
onContextMenu: ["contextmenu", false],
|
|
51
|
+
onDoubleClick: ["dblclick", false],
|
|
52
|
+
onWheel: ["wheel", true],
|
|
53
|
+
onPointerDown: ["pointerdown", true],
|
|
54
|
+
onPointerUp: ["pointerup", true],
|
|
55
|
+
onPointerLeave: ["pointerleave", true],
|
|
56
|
+
onPointerMove: ["pointermove", true],
|
|
57
|
+
onPointerCancel: ["pointercancel", true],
|
|
58
|
+
onLostPointerCapture: ["lostpointercapture", true]
|
|
59
|
+
};
|
|
60
|
+
const identity = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
61
|
+
function createEvents() {
|
|
62
|
+
return (store) => {
|
|
63
|
+
const { handlePointer } = fiber.createEvents(store);
|
|
64
|
+
const rayCamera = new THREE.PerspectiveCamera();
|
|
65
|
+
rayCamera.position.z = 5;
|
|
66
|
+
rayCamera.matrixAutoUpdate = false;
|
|
67
|
+
rayCamera.matrixWorldAutoUpdate = false;
|
|
68
|
+
rayCamera.lookAt(0, 0, 0);
|
|
69
|
+
return {
|
|
70
|
+
priority: 1,
|
|
71
|
+
enabled: true,
|
|
72
|
+
compute(event, state) {
|
|
73
|
+
state.size.width = state.gl.domElement.width / window.devicePixelRatio;
|
|
74
|
+
state.size.height = state.gl.domElement.height / window.devicePixelRatio;
|
|
75
|
+
state.pointer.x = event.offsetX / state.size.width * 2 - 1;
|
|
76
|
+
state.pointer.y = 1 - event.offsetY / state.size.height * 2;
|
|
77
|
+
rayCamera.copy(state.camera);
|
|
78
|
+
const projByViewInv2 = rayCamera.userData.projByViewInv || identity;
|
|
79
|
+
rayCamera.matrix.identity();
|
|
80
|
+
rayCamera.matrixWorld.identity();
|
|
81
|
+
rayCamera.matrixWorldInverse.copy(rayCamera.matrixWorld).invert();
|
|
82
|
+
rayCamera.projectionMatrixInverse.fromArray(projByViewInv2);
|
|
83
|
+
rayCamera.projectionMatrix.fromArray(rayCamera.userData.projByView);
|
|
84
|
+
state.raycaster.camera = state.camera;
|
|
85
|
+
state.raycaster.ray.origin.setScalar(0).applyMatrix4(rayCamera.projectionMatrixInverse);
|
|
86
|
+
state.raycaster.ray.direction.set(state.pointer.x, state.pointer.y, 1).applyMatrix4(rayCamera.projectionMatrixInverse).sub(state.raycaster.ray.origin).normalize();
|
|
87
|
+
},
|
|
88
|
+
connected: void 0,
|
|
89
|
+
handlers: Object.keys(DOM_EVENTS).reduce(
|
|
90
|
+
(acc, key) => ({ ...acc, [key]: handlePointer(key) }),
|
|
91
|
+
{}
|
|
92
|
+
),
|
|
93
|
+
update: () => {
|
|
94
|
+
var _a;
|
|
95
|
+
const { events, internal } = store.getState();
|
|
96
|
+
if (((_a = internal.lastEvent) == null ? void 0 : _a.current) && events.handlers) {
|
|
97
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
connect: (target) => {
|
|
101
|
+
var _a;
|
|
102
|
+
const { set, events } = store.getState();
|
|
103
|
+
(_a = events.disconnect) == null ? void 0 : _a.call(events);
|
|
104
|
+
set((state) => ({ events: { ...state.events, connected: target.parentNode } }));
|
|
105
|
+
Object.entries(events.handlers ?? []).forEach(([name, event]) => {
|
|
106
|
+
const [eventName, passive] = DOM_EVENTS[name];
|
|
107
|
+
target.addEventListener(eventName, event, { passive });
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
disconnect: () => {
|
|
111
|
+
const { set, events } = store.getState();
|
|
112
|
+
if (events.connected) {
|
|
113
|
+
Object.entries(events.handlers ?? []).forEach(([name, event]) => {
|
|
114
|
+
if (events && events.connected instanceof HTMLElement) {
|
|
115
|
+
const [eventName] = DOM_EVENTS[name];
|
|
116
|
+
events.connected.removeEventListener(eventName, event);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
set((state) => ({ events: { ...state.events, connected: void 0 } }));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const useFunction = (callback) => {
|
|
126
|
+
const callbackRef = react.useRef(callback);
|
|
127
|
+
callbackRef.current = callback;
|
|
128
|
+
return react.useCallback((...args) => {
|
|
129
|
+
return callbackRef.current(...args);
|
|
130
|
+
}, []);
|
|
131
|
+
};
|
|
132
|
+
function useOnAdd(fromLngLat2, { frameloop, ...renderProps }) {
|
|
133
|
+
const [mounted, setMounted] = react.useState(false);
|
|
134
|
+
const r3mRef = react.useRef({ fromLngLat: fromLngLat2 });
|
|
135
|
+
const onAdd = useFunction((map, gl) => {
|
|
136
|
+
const canvas = map.getCanvas();
|
|
137
|
+
const root = fiber.createRoot(canvas);
|
|
138
|
+
root.configure({
|
|
139
|
+
dpr: window.devicePixelRatio,
|
|
140
|
+
events: createEvents(),
|
|
141
|
+
...renderProps,
|
|
142
|
+
frameloop: "never",
|
|
143
|
+
gl: {
|
|
144
|
+
context: gl,
|
|
145
|
+
depth: true,
|
|
146
|
+
autoClear: false,
|
|
147
|
+
antialias: true,
|
|
148
|
+
...renderProps == null ? void 0 : renderProps.gl
|
|
149
|
+
},
|
|
150
|
+
onCreated: (state) => {
|
|
151
|
+
state.gl.forceContextLoss = () => {
|
|
152
|
+
};
|
|
153
|
+
},
|
|
154
|
+
camera: {
|
|
155
|
+
matrixAutoUpdate: false,
|
|
156
|
+
near: 0
|
|
157
|
+
},
|
|
158
|
+
size: {
|
|
159
|
+
width: canvas.clientWidth,
|
|
160
|
+
height: canvas.clientHeight,
|
|
161
|
+
top: 0,
|
|
162
|
+
left: 0,
|
|
163
|
+
...renderProps == null ? void 0 : renderProps.size
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
const store = fiber._roots.get(canvas).store;
|
|
167
|
+
r3mRef.current.map = map;
|
|
168
|
+
r3mRef.current.root = root;
|
|
169
|
+
r3mRef.current.state = store.getState();
|
|
170
|
+
store.setState({ r3m: r3mRef.current });
|
|
171
|
+
if (frameloop === "demand") {
|
|
172
|
+
store.setState({
|
|
173
|
+
frameloop,
|
|
174
|
+
invalidate: () => {
|
|
175
|
+
map.triggerRepaint();
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
setTimeout(() => setMounted(true));
|
|
180
|
+
});
|
|
181
|
+
const onRemove = useFunction(() => {
|
|
182
|
+
if (!r3mRef.current.root)
|
|
183
|
+
return;
|
|
184
|
+
r3mRef.current.root.unmount();
|
|
185
|
+
r3mRef.current.root = void 0;
|
|
186
|
+
});
|
|
187
|
+
react.useEffect(() => () => onRemove(), [onRemove]);
|
|
188
|
+
return { onAdd, onRemove, mounted, r3mRef };
|
|
189
|
+
}
|
|
190
|
+
const useCreateRoot = ({
|
|
191
|
+
children,
|
|
192
|
+
frameloop,
|
|
193
|
+
fromLngLat: fromLngLat2,
|
|
194
|
+
...renderProps
|
|
195
|
+
}) => {
|
|
196
|
+
const id = react.useId();
|
|
197
|
+
const { onAdd, onRemove, mounted, r3mRef } = useOnAdd(fromLngLat2, { frameloop, ...renderProps });
|
|
198
|
+
react.useEffect(() => {
|
|
199
|
+
if (!mounted)
|
|
200
|
+
return;
|
|
201
|
+
if (!r3mRef.current.root)
|
|
202
|
+
return;
|
|
203
|
+
r3mRef.current.root.render(/* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children }));
|
|
204
|
+
}, [r3mRef, mounted, children]);
|
|
205
|
+
return { id, onAdd, onRemove, r3mRef };
|
|
206
|
+
};
|
|
207
|
+
const originMx = new THREE.Matrix4();
|
|
208
|
+
const projByView = new THREE.Matrix4();
|
|
209
|
+
const projByViewInv = new THREE.Matrix4();
|
|
210
|
+
const fwd = new THREE.Vector3();
|
|
211
|
+
function syncCamera(camera, origin, mapCamMx) {
|
|
212
|
+
projByView.fromArray(mapCamMx).multiply(originMx.fromArray(origin));
|
|
213
|
+
projByViewInv.copy(projByView).invert();
|
|
214
|
+
updateCamera(camera, projByViewInv);
|
|
215
|
+
camera.updateMatrix();
|
|
216
|
+
camera.updateMatrixWorld(true);
|
|
217
|
+
camera.projectionMatrix.copy(camera.matrix).premultiply(projByView);
|
|
218
|
+
camera.projectionMatrixInverse.copy(camera.projectionMatrix).invert();
|
|
219
|
+
camera.far = calculateFar(
|
|
220
|
+
camera.matrix.elements[10],
|
|
221
|
+
camera.matrix.elements[14],
|
|
222
|
+
camera.near
|
|
223
|
+
);
|
|
224
|
+
camera.userData.projByView = projByView.toArray();
|
|
225
|
+
camera.userData.projByViewInv = projByViewInv.toArray();
|
|
226
|
+
}
|
|
227
|
+
const updateCamera = (target, projByViewInv2) => {
|
|
228
|
+
target.position.setScalar(0).applyMatrix4(projByViewInv2);
|
|
229
|
+
target.up.set(0, -1, 0).applyMatrix4(projByViewInv2).negate().add(target.position).normalize();
|
|
230
|
+
fwd.set(0, 0, 1).applyMatrix4(projByViewInv2);
|
|
231
|
+
target.lookAt(fwd);
|
|
232
|
+
};
|
|
233
|
+
function calculateFar(c, d, near) {
|
|
234
|
+
const numerator = d * (c - 1);
|
|
235
|
+
const denominator = c * near + near;
|
|
236
|
+
const far = numerator / denominator;
|
|
237
|
+
return far;
|
|
238
|
+
}
|
|
239
|
+
function useRender(origin, r3mRef, frameloop) {
|
|
240
|
+
const render = useFunction((_gl, mapCamMx) => {
|
|
241
|
+
const r3m = r3mRef.current;
|
|
242
|
+
if (!r3m.state || !r3m.map)
|
|
243
|
+
return;
|
|
244
|
+
const camera = r3m.state.camera;
|
|
245
|
+
const gl = r3m.state.gl;
|
|
246
|
+
const advance = r3m.state.advance;
|
|
247
|
+
r3m.mapCamMx = mapCamMx;
|
|
248
|
+
syncCamera(camera, origin, mapCamMx);
|
|
249
|
+
gl.resetState();
|
|
250
|
+
advance(Date.now() * 1e-3, true);
|
|
251
|
+
if (frameloop === "always")
|
|
252
|
+
r3m.map.triggerRepaint();
|
|
253
|
+
});
|
|
254
|
+
return render;
|
|
255
|
+
}
|
|
256
|
+
function useCanvas({
|
|
257
|
+
longitude,
|
|
258
|
+
latitude,
|
|
259
|
+
altitude = 0,
|
|
260
|
+
frameloop = "always",
|
|
261
|
+
fromLngLat: fromLngLat2,
|
|
262
|
+
...renderProps
|
|
263
|
+
}) {
|
|
264
|
+
const m42 = useCoords({
|
|
265
|
+
latitude,
|
|
266
|
+
longitude,
|
|
267
|
+
altitude,
|
|
268
|
+
fromLngLat: fromLngLat2
|
|
269
|
+
});
|
|
270
|
+
const { id, onAdd, onRemove, r3mRef } = useCreateRoot({ frameloop, fromLngLat: fromLngLat2, ...renderProps });
|
|
271
|
+
const render = useRender(m42, r3mRef, frameloop);
|
|
272
|
+
return { id, onAdd, onRemove, render };
|
|
273
|
+
}
|
|
274
|
+
fiber.extend(THREE__namespace);
|
|
275
|
+
const fromLngLat = mapboxGl.MercatorCoordinate.fromLngLat;
|
|
276
|
+
const Canvas = react.memo((props) => {
|
|
277
|
+
const { id, onAdd, onRemove, render } = useCanvas({ ...props, fromLngLat });
|
|
278
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
279
|
+
reactMapGl.Layer,
|
|
280
|
+
{
|
|
281
|
+
id,
|
|
282
|
+
type: "custom",
|
|
283
|
+
renderingMode: "3d",
|
|
284
|
+
onAdd,
|
|
285
|
+
onRemove,
|
|
286
|
+
render
|
|
287
|
+
}
|
|
288
|
+
);
|
|
289
|
+
});
|
|
290
|
+
const useR3M = () => fiber.useThree((s) => s.r3m);
|
|
291
|
+
const Coordinates = react.memo(({
|
|
292
|
+
latitude,
|
|
293
|
+
longitude,
|
|
294
|
+
altitude = 0,
|
|
295
|
+
children
|
|
296
|
+
}) => {
|
|
297
|
+
const [scene] = react.useState(() => new THREE.Scene());
|
|
298
|
+
const r3m = useR3M();
|
|
299
|
+
const origin = useCoords({
|
|
300
|
+
latitude,
|
|
301
|
+
longitude,
|
|
302
|
+
altitude,
|
|
303
|
+
fromLngLat: r3m.fromLngLat
|
|
304
|
+
});
|
|
305
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fiber.createPortal(/* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
306
|
+
/* @__PURE__ */ jsxRuntime.jsx(RenderAtCoords, { r3m, origin }),
|
|
307
|
+
children
|
|
308
|
+
] }), scene, { events: { priority: 2 } }) });
|
|
309
|
+
});
|
|
310
|
+
Coordinates.displayName = "Coordinates";
|
|
311
|
+
function RenderAtCoords({ r3m, origin }) {
|
|
312
|
+
const { gl, scene, set } = fiber.useThree();
|
|
313
|
+
const cameraRef = react.useRef(null);
|
|
314
|
+
fiber.useFrame(() => {
|
|
315
|
+
if (!r3m.mapCamMx)
|
|
316
|
+
return;
|
|
317
|
+
if (!cameraRef.current)
|
|
318
|
+
return;
|
|
319
|
+
syncCamera(cameraRef.current, origin, r3m.mapCamMx);
|
|
320
|
+
gl.render(scene, cameraRef.current);
|
|
321
|
+
});
|
|
322
|
+
react.useLayoutEffect(() => {
|
|
323
|
+
if (!cameraRef.current)
|
|
324
|
+
return;
|
|
325
|
+
set({
|
|
326
|
+
invalidate: () => {
|
|
327
|
+
if (!r3m.map)
|
|
328
|
+
return;
|
|
329
|
+
r3m.map.triggerRepaint();
|
|
330
|
+
},
|
|
331
|
+
camera: cameraRef.current
|
|
332
|
+
});
|
|
333
|
+
}, [set, r3m]);
|
|
334
|
+
return /* @__PURE__ */ jsxRuntime.jsx("perspectiveCamera", { ref: cameraRef });
|
|
335
|
+
}
|
|
336
|
+
exports.Canvas = Canvas;
|
|
337
|
+
exports.Coordinates = Coordinates;
|
package/dist/es/main.mjs
CHANGED
package/dist/es/main.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"main.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Quaternion, Euler, Vector3, Matrix4 } from "three";
|
|
2
|
+
const quat = new Quaternion();
|
|
3
|
+
const euler = new Euler();
|
|
4
|
+
const pos = new Vector3();
|
|
5
|
+
const scale = new Vector3();
|
|
6
|
+
const m4 = new Matrix4();
|
|
7
|
+
function coordsToMatrix({ longitude, latitude, altitude, fromLngLat }) {
|
|
8
|
+
const center = fromLngLat([longitude, latitude], altitude);
|
|
9
|
+
const scaleUnit = center.meterInMercatorCoordinateUnits();
|
|
10
|
+
pos.set(center.x, center.y, center.z || 0);
|
|
11
|
+
scale.set(scaleUnit, -scaleUnit, scaleUnit);
|
|
12
|
+
quat.setFromEuler(euler.set(-Math.PI * 0.5, 0, 0));
|
|
13
|
+
return m4.compose(pos, quat, scale).toArray();
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
coordsToMatrix
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=main10.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main10.mjs","sources":["../../src/core/coords-to-matrix.ts"],"sourcesContent":["import { Euler, Matrix4, Quaternion, Vector3 } from \"three\";\nimport { FromLngLat } from \"./generic-map\";\n\nconst quat = new Quaternion();\nconst euler = new Euler();\nconst pos = new Vector3();\nconst scale = new Vector3();\nconst m4 = new Matrix4();\n\n/** calculate Matrix4 from coordinates */\nexport function coordsToMatrix({ longitude, latitude, altitude, fromLngLat }: {\n longitude: number, latitude: number, altitude: number, fromLngLat: FromLngLat\n}) {\n const center = fromLngLat([longitude, latitude], altitude);\n const scaleUnit = center.meterInMercatorCoordinateUnits();\n pos.set(center.x, center.y, center.z || 0);\n scale.set(scaleUnit, -scaleUnit, scaleUnit);\n quat.setFromEuler(euler.set(-Math.PI * .5, 0, 0));\n return m4.compose(pos, quat, scale).toArray();\n}\n"],"names":[],"mappings":";AAGA,MAAM,OAAO,IAAI;AACjB,MAAM,QAAQ,IAAI;AAClB,MAAM,MAAM,IAAI;AAChB,MAAM,QAAQ,IAAI;AAClB,MAAM,KAAK,IAAI;AAGR,SAAS,eAAe,EAAE,WAAW,UAAU,UAAU,cAE7D;AACD,QAAM,SAAS,WAAW,CAAC,WAAW,QAAQ,GAAG,QAAQ;AACnD,QAAA,YAAY,OAAO;AACzB,MAAI,IAAI,OAAO,GAAG,OAAO,GAAG,OAAO,KAAK,CAAC;AACzC,QAAM,IAAI,WAAW,CAAC,WAAW,SAAS;AACrC,OAAA,aAAa,MAAM,IAAI,CAAC,KAAK,KAAK,KAAI,GAAG,CAAC,CAAC;AAChD,SAAO,GAAG,QAAQ,KAAK,MAAM,KAAK,EAAE;AACtC;"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { createRoot, _roots } from "@react-three/fiber";
|
|
2
|
+
import { useState, useRef, useEffect } from "react";
|
|
3
|
+
import { createEvents } from "./main13.mjs";
|
|
4
|
+
import { useFunction } from "./main12.mjs";
|
|
5
|
+
function useOnAdd(fromLngLat, { frameloop, ...renderProps }) {
|
|
6
|
+
const [mounted, setMounted] = useState(false);
|
|
7
|
+
const r3mRef = useRef({ fromLngLat });
|
|
8
|
+
const onAdd = useFunction((map, gl) => {
|
|
9
|
+
const canvas = map.getCanvas();
|
|
10
|
+
const root = createRoot(canvas);
|
|
11
|
+
root.configure({
|
|
12
|
+
dpr: window.devicePixelRatio,
|
|
13
|
+
events: createEvents(),
|
|
14
|
+
...renderProps,
|
|
15
|
+
frameloop: "never",
|
|
16
|
+
gl: {
|
|
17
|
+
context: gl,
|
|
18
|
+
depth: true,
|
|
19
|
+
autoClear: false,
|
|
20
|
+
antialias: true,
|
|
21
|
+
...renderProps == null ? void 0 : renderProps.gl
|
|
22
|
+
},
|
|
23
|
+
onCreated: (state) => {
|
|
24
|
+
state.gl.forceContextLoss = () => {
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
camera: {
|
|
28
|
+
matrixAutoUpdate: false,
|
|
29
|
+
near: 0
|
|
30
|
+
},
|
|
31
|
+
size: {
|
|
32
|
+
width: canvas.clientWidth,
|
|
33
|
+
height: canvas.clientHeight,
|
|
34
|
+
top: 0,
|
|
35
|
+
left: 0,
|
|
36
|
+
...renderProps == null ? void 0 : renderProps.size
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const store = _roots.get(canvas).store;
|
|
40
|
+
r3mRef.current.map = map;
|
|
41
|
+
r3mRef.current.root = root;
|
|
42
|
+
r3mRef.current.state = store.getState();
|
|
43
|
+
store.setState({ r3m: r3mRef.current });
|
|
44
|
+
if (frameloop === "demand") {
|
|
45
|
+
store.setState({
|
|
46
|
+
frameloop,
|
|
47
|
+
invalidate: () => {
|
|
48
|
+
map.triggerRepaint();
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
setTimeout(() => setMounted(true));
|
|
53
|
+
});
|
|
54
|
+
const onRemove = useFunction(() => {
|
|
55
|
+
if (!r3mRef.current.root)
|
|
56
|
+
return;
|
|
57
|
+
r3mRef.current.root.unmount();
|
|
58
|
+
r3mRef.current.root = void 0;
|
|
59
|
+
});
|
|
60
|
+
useEffect(() => () => onRemove(), [onRemove]);
|
|
61
|
+
return { onAdd, onRemove, mounted, r3mRef };
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
useOnAdd
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=main11.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main11.mjs","sources":["../../src/core/use-on-add.ts"],"sourcesContent":["import { RenderProps, _roots, createRoot } from \"@react-three/fiber\";\nimport { useEffect, useRef, useState } from \"react\";\nimport { createEvents } from \"./create-events\";\nimport { FromLngLat, MapInstance } from \"./generic-map\";\nimport { R3mStore } from \"./store\";\nimport { useFunction } from \"./use-function\";\n\nexport function useOnAdd(\n fromLngLat: FromLngLat,\n { frameloop, ...renderProps }: RenderProps<HTMLCanvasElement>\n) {\n\n const [mounted, setMounted] = useState(false);\n\n const r3mRef = useRef<R3mStore>({ fromLngLat });\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 // eslint-disable-next-line @typescript-eslint/no-empty-function\n state.gl.forceContextLoss = () => { };\n },\n camera: {\n matrixAutoUpdate: false,\n near: 0,\n },\n size: {\n width: canvas.clientWidth,\n height: canvas.clientHeight,\n top: 0,\n left: 0,\n ...renderProps?.size,\n },\n });\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const store = _roots.get(canvas)!.store;\n\n r3mRef.current.map = map;\n r3mRef.current.root = root;\n r3mRef.current.state = store.getState();\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n store.setState({ r3m: r3mRef.current } as any);\n\n if (frameloop === 'demand') {\n store.setState({\n frameloop,\n invalidate: () => {\n map.triggerRepaint();\n },\n })\n }\n\n setTimeout(() => setMounted(true));\n\n })\n\n const onRemove = useFunction(() => {\n if (!r3mRef.current.root) return;\n r3mRef.current.root.unmount();\n r3mRef.current.root = undefined;\n })\n\n // on unmount\n useEffect(() => () => onRemove(), [onRemove])\n\n return { onAdd, onRemove, mounted, r3mRef };\n}"],"names":[],"mappings":";;;;AAOO,SAAS,SACd,YACA,EAAE,WAAW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AA,CACvB;AAGD,YAAU,MAAM,MAAM,SAAY,GAAA,CAAC,QAAQ,CAAC;AAE5C,SAAO,EAAE,OAAO,UAAU,SAAS,OAAO;AAC5C;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useRef, useCallback } from "react";
|
|
2
|
+
const useFunction = (callback) => {
|
|
3
|
+
const callbackRef = useRef(callback);
|
|
4
|
+
callbackRef.current = callback;
|
|
5
|
+
return useCallback((...args) => {
|
|
6
|
+
return callbackRef.current(...args);
|
|
7
|
+
}, []);
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
useFunction
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=main12.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main12.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":[],"mappings":";AAGa,MAAA,cAAc,CAAoC,aAAmB;AAC1E,QAAA,cAAc,OAAO,QAAQ;AACnC,cAAY,UAAU;AACf,SAAA,YAAY,IAAI,SAAgB;AAC9B,WAAA,YAAY,QAAQ,GAAG,IAAI;AAAA,EACpC,GAAG,CAAE,CAAA;AACP;"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { createEvents as createEvents$1 } from "@react-three/fiber";
|
|
2
|
+
import { PerspectiveCamera } from "three";
|
|
3
|
+
const DOM_EVENTS = {
|
|
4
|
+
onClick: ["click", false],
|
|
5
|
+
onContextMenu: ["contextmenu", false],
|
|
6
|
+
onDoubleClick: ["dblclick", false],
|
|
7
|
+
onWheel: ["wheel", true],
|
|
8
|
+
onPointerDown: ["pointerdown", true],
|
|
9
|
+
onPointerUp: ["pointerup", true],
|
|
10
|
+
onPointerLeave: ["pointerleave", true],
|
|
11
|
+
onPointerMove: ["pointermove", true],
|
|
12
|
+
onPointerCancel: ["pointercancel", true],
|
|
13
|
+
onLostPointerCapture: ["lostpointercapture", true]
|
|
14
|
+
};
|
|
15
|
+
const identity = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
16
|
+
function createEvents() {
|
|
17
|
+
return (store) => {
|
|
18
|
+
const { handlePointer } = createEvents$1(store);
|
|
19
|
+
const rayCamera = new PerspectiveCamera();
|
|
20
|
+
rayCamera.position.z = 5;
|
|
21
|
+
rayCamera.matrixAutoUpdate = false;
|
|
22
|
+
rayCamera.matrixWorldAutoUpdate = false;
|
|
23
|
+
rayCamera.lookAt(0, 0, 0);
|
|
24
|
+
return {
|
|
25
|
+
priority: 1,
|
|
26
|
+
enabled: true,
|
|
27
|
+
compute(event, state) {
|
|
28
|
+
state.size.width = state.gl.domElement.width / window.devicePixelRatio;
|
|
29
|
+
state.size.height = state.gl.domElement.height / window.devicePixelRatio;
|
|
30
|
+
state.pointer.x = event.offsetX / state.size.width * 2 - 1;
|
|
31
|
+
state.pointer.y = 1 - event.offsetY / state.size.height * 2;
|
|
32
|
+
rayCamera.copy(state.camera);
|
|
33
|
+
const projByViewInv = rayCamera.userData.projByViewInv || identity;
|
|
34
|
+
rayCamera.matrix.identity();
|
|
35
|
+
rayCamera.matrixWorld.identity();
|
|
36
|
+
rayCamera.matrixWorldInverse.copy(rayCamera.matrixWorld).invert();
|
|
37
|
+
rayCamera.projectionMatrixInverse.fromArray(projByViewInv);
|
|
38
|
+
rayCamera.projectionMatrix.fromArray(rayCamera.userData.projByView);
|
|
39
|
+
state.raycaster.camera = state.camera;
|
|
40
|
+
state.raycaster.ray.origin.setScalar(0).applyMatrix4(rayCamera.projectionMatrixInverse);
|
|
41
|
+
state.raycaster.ray.direction.set(state.pointer.x, state.pointer.y, 1).applyMatrix4(rayCamera.projectionMatrixInverse).sub(state.raycaster.ray.origin).normalize();
|
|
42
|
+
},
|
|
43
|
+
connected: void 0,
|
|
44
|
+
handlers: Object.keys(DOM_EVENTS).reduce(
|
|
45
|
+
(acc, key) => ({ ...acc, [key]: handlePointer(key) }),
|
|
46
|
+
{}
|
|
47
|
+
),
|
|
48
|
+
update: () => {
|
|
49
|
+
var _a;
|
|
50
|
+
const { events, internal } = store.getState();
|
|
51
|
+
if (((_a = internal.lastEvent) == null ? void 0 : _a.current) && events.handlers) {
|
|
52
|
+
events.handlers.onPointerMove(internal.lastEvent.current);
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
connect: (target) => {
|
|
56
|
+
var _a;
|
|
57
|
+
const { set, events } = store.getState();
|
|
58
|
+
(_a = events.disconnect) == null ? void 0 : _a.call(events);
|
|
59
|
+
set((state) => ({ events: { ...state.events, connected: target.parentNode } }));
|
|
60
|
+
Object.entries(events.handlers ?? []).forEach(([name, event]) => {
|
|
61
|
+
const [eventName, passive] = DOM_EVENTS[name];
|
|
62
|
+
target.addEventListener(eventName, event, { passive });
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
disconnect: () => {
|
|
66
|
+
const { set, events } = store.getState();
|
|
67
|
+
if (events.connected) {
|
|
68
|
+
Object.entries(events.handlers ?? []).forEach(([name, event]) => {
|
|
69
|
+
if (events && events.connected instanceof HTMLElement) {
|
|
70
|
+
const [eventName] = DOM_EVENTS[name];
|
|
71
|
+
events.connected.removeEventListener(eventName, event);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
set((state) => ({ events: { ...state.events, connected: void 0 } }));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export {
|
|
81
|
+
createEvents
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=main13.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main13.mjs","sources":["../../src/core/create-events.ts"],"sourcesContent":["import { Events, RenderProps, RootState, createEvents as createFiberEvents } from \"@react-three/fiber\";\nimport { PerspectiveCamera } from \"three\";\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\nconst identity = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]\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 const rayCamera = new PerspectiveCamera();\n rayCamera.position.z = 5\n rayCamera.matrixAutoUpdate = false;\n rayCamera.matrixWorldAutoUpdate = false;\n rayCamera.lookAt(0, 0, 0)\n\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\n rayCamera.copy(state.camera as PerspectiveCamera);\n\n const projByViewInv = rayCamera.userData.projByViewInv || identity;\n\n rayCamera.matrix.identity();\n rayCamera.matrixWorld.identity();\n rayCamera.matrixWorldInverse.copy(rayCamera.matrixWorld).invert();\n rayCamera.projectionMatrixInverse.fromArray(projByViewInv)\n rayCamera.projectionMatrix.fromArray(rayCamera.userData.projByView)\n\n state.raycaster.camera = state.camera;\n state.raycaster.ray.origin.setScalar(0).applyMatrix4(rayCamera.projectionMatrixInverse);\n state.raycaster.ray.direction\n .set(state.pointer.x, state.pointer.y, 1)\n .applyMatrix4(rayCamera.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":["createFiberEvents"],"mappings":";;AAMA,MAAM,aAAa;AAAA,EACjB,SAAS,CAAC,SAAS,KAAK;AAAA,EACxB,eAAe,CAAC,eAAe,KAAK;AAAA,EACpC,eAAe,CAAC,YAAY,KAAK;AAAA,EACjC,SAAS,CAAC,SAAS,IAAI;AAAA,EACvB,eAAe,CAAC,eAAe,IAAI;AAAA,EACnC,aAAa,CAAC,aAAa,IAAI;AAAA,EAC/B,gBAAgB,CAAC,gBAAgB,IAAI;AAAA,EACrC,eAAe,CAAC,eAAe,IAAI;AAAA,EACnC,iBAAiB,CAAC,iBAAiB,IAAI;AAAA,EACvC,sBAAsB,CAAC,sBAAsB,IAAI;AACnD;AAEA,MAAM,WAAW,CAAC,GAAG,GAAG,GAAG,GAAG,GAA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