@mappedin/react-sdk 6.0.1-beta.8 → 6.1.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.
package/lib/esm/index.js CHANGED
@@ -1 +1,727 @@
1
- import{a as w,h as E,i as V,j as b}from"./chunk-NMYDM4WH.js";import"./chunk-5CLC3TYJ.js";import"./chunk-2VWRFWQ6.js";import"./chunk-VSK4OUQK.js";import"./chunk-W7UWRYFM.js";import{a as o,j as a}from"./chunk-U7HFWTFB.js";a();a();import{useContext as j,useEffect as W,useRef as H,useState as K}from"react";import{createPortal as _}from"react-dom";a();import{createContext as C,useContext as O}from"react";a();var N=class N extends Error{constructor(t){super("".concat(t," must be used within a MapView component."))}};o(N,"MapViewNullError");var m=N;var p=C({mapData:void 0,mapView:void 0});function R(){let{mapData:e,mapView:t}=O(p);if(!e||!t)throw new m("useMap");return{mapData:e,mapView:t}}o(R,"useMap");a();import{useEffect as k}from"react";function u(e,t){k(()=>{t!=null&&typeof e=="function"&&e(t)},[e,t])}o(u,"useOnLoad");var Re=o(e=>{let{mapView:t}=j(p),r=H(),[n,i]=K(null);return W(()=>{if(t==null)throw new m("Marker");return r.current=t.Markers.add(e.target,"",{...e.options,dynamicResize:!0}),i(r.current),()=>{t==null||r.current==null||t.Markers.remove(r.current)}},[t,e.target,e.options]),u(e.onLoad,n),t==null||n==null?null:_(e.children,n.contentEl,n.id)},"Marker");a();import{useContext as z,useEffect as I,useRef as U,useState as F}from"react";function Ie(e){let{mapView:t}=z(p),r=U(),[n,i]=F(void 0);return I(()=>{if(t==null)throw new m("Label");return r.current=t.Labels.add(e.target,e.text,e.options),i(r.current),()=>{t==null||r.current==null||t.Labels.remove(r.current)}},[t,e.target,e.text,e.options]),u(e.onLoad,n),null}o(Ie,"Label");a();import{useCallback as G,useContext as Y,useEffect as $}from"react";function Be(e,t){let{mapView:r}=Y(p),n=G(i=>t(i),[t]);$(()=>{if(r==null)throw new m("useEvent");return r.on(e,n),()=>{r!=null&&r.off(e,n)}},[r,e,t])}o(Be,"useEvent");a();import{useContext as q,useEffect as B,useRef as J,useState as Q}from"react";function at(e){let{mapView:t}=q(p),r=J(),[n,i]=Q(void 0);return B(()=>{if(t==null)throw new m("Path");let d=!1,f=t.Paths.add(e.coordinate,e.options);return f.then(s=>{d?t.Paths.remove(s):(r.current=s,i(s))}),()=>{d=!0,r.current?t.Paths.remove(r.current):f.then(s=>{t.Paths.remove(s)})}},[t,e.coordinate,e.options]),u(e.onLoad,n),null}o(at,"Path");a();import x,{useCallback as X,useEffect as Z,useMemo as ee,useRef as v,useState as A}from"react";var te={width:"100%",height:"100%",position:"relative"};function lt(e){let{mapData:t,options:r,style:n,fallback:i,children:d,...f}=e,s=v(!1),[c,h]=A(void 0),[y,M]=A(!0),P=v(null),L=ee(()=>r,[]),g=X(()=>{if(t&&(P!=null&&P.current)){if(c)return;V(P.current,t,L).then(S=>{h(S)}).catch(S=>{w.error("Failed to render MapView",S)}).finally(()=>{M(!1)})}},[t,P.current,L]);return Z(()=>{s.current||(s.current=!0,g())},[g]),u(e.onLoad,c),x.createElement(p.Provider,{value:{mapData:t,mapView:c}},x.createElement("div",{"data-testid":"mappedin-map",ref:P,style:{...te,...n},...f}),y?x.createElement(x.Fragment,null,i):d)}o(lt,"MapView");a();import{useContext as re,useEffect as D,useRef as ae,useState as oe}from"react";function wt(e){let{mapView:t}=re(p),[r,n]=oe(!1),i=ae(Promise.resolve());return D(()=>{if(t==null)throw new m("Navigation");let d=!1,f=o(()=>d?Promise.resolve():t.Navigation.draw(e.directions,e.options).then(()=>{d||n(!0)}),"navigationOperation");return i.current=i.current.then(f),()=>{d=!0,i.current=i.current.then(()=>{t.Navigation.clear()})}},[t,e.directions,e.options]),D(()=>{r!==!1&&typeof e.onLoad=="function"&&e.onLoad()},[e.onLoad,r]),null}o(wt,"Navigation");a();import{useContext as ne,useEffect as ie,useRef as pe,useState as me}from"react";function Et(e){let{mapView:t}=ne(p),r=pe(),[n,i]=me(void 0);return ie(()=>{if(t==null)throw new Error("MapView not initialized");return r.current=t.Shapes.add(e.geometry,e.style,e.floor),i(r.current),()=>{t==null||r.current==null||t.Shapes.remove(r.current)}},[t,e.geometry,e.style,e.floor]),u(e.onLoad,n),null}o(Et,"Shape");a();import{useContext as se,useEffect as ue,useRef as de,useState as le}from"react";function Rt(e){let{mapView:t}=se(p),r=de(),[n,i]=le(void 0);return ue(()=>{if(t==null)throw new m("Model");return r.current=t.Models.add(e.models,e.options),i(r.current),()=>{if(!(t==null||r.current==null))for(let d of r.current)t.Models.remove(d)}},[t,e.models,e.options]),u(e.onLoad,n),null}o(Rt,"Model");a();import{useCallback as fe,useEffect as ce,useMemo as Me,useRef as Pe,useState as T}from"react";function zt(e){let[t,r]=T(void 0),[n,i]=T(!0),[d,f]=T(void 0),s=Pe(0),c=Me(()=>e,[]),h=fe(()=>{let y=++s.current;i(!0),f(void 0),E(c).then(M=>{s.current===y&&r(M)}).catch(M=>{s.current===y&&(w.error("Failed to fetch MapData",M),f(M))}).finally(()=>{s.current===y&&i(!1)})},[c]);return ce(()=>{h()},[h]),{mapData:t,isLoading:n,error:d}}o(zt,"useMapData");var Gt=b;export{Ie as Label,lt as MapView,Re as Marker,Rt as Model,wt as Navigation,at as Path,Et as Shape,Gt as default,Be as useEvent,R as useMap,zt as useMapData};
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
11
+ var __commonJS = (cb, mod) => function __require() {
12
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+
31
+ // <define:process>
32
+ var define_process_default;
33
+ var init_define_process = __esm({
34
+ "<define:process>"() {
35
+ define_process_default = { env: { npm_package_version: "6.1.0" } };
36
+ }
37
+ });
38
+
39
+ // ../../node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js
40
+ var require_fast_deep_equal = __commonJS({
41
+ "../../node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js"(exports, module) {
42
+ "use strict";
43
+ init_define_process();
44
+ module.exports = /* @__PURE__ */ __name(function equal3(a, b) {
45
+ if (a === b) return true;
46
+ if (a && b && typeof a == "object" && typeof b == "object") {
47
+ if (a.constructor !== b.constructor) return false;
48
+ var length, i, keys;
49
+ if (Array.isArray(a)) {
50
+ length = a.length;
51
+ if (length != b.length) return false;
52
+ for (i = length; i-- !== 0; )
53
+ if (!equal3(a[i], b[i])) return false;
54
+ return true;
55
+ }
56
+ if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
57
+ if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
58
+ if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
59
+ keys = Object.keys(a);
60
+ length = keys.length;
61
+ if (length !== Object.keys(b).length) return false;
62
+ for (i = length; i-- !== 0; )
63
+ if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
64
+ for (i = length; i-- !== 0; ) {
65
+ var key = keys[i];
66
+ if (!equal3(a[key], b[key])) return false;
67
+ }
68
+ return true;
69
+ }
70
+ return a !== a && b !== b;
71
+ }, "equal");
72
+ }
73
+ });
74
+
75
+ // src/index.tsx
76
+ init_define_process();
77
+
78
+ // src/MapDataProvider.tsx
79
+ init_define_process();
80
+ import React, { createContext, useCallback, useMemo, useRef } from "react";
81
+ var MapDataContext = createContext({
82
+ getCache: /* @__PURE__ */ __name(() => void 0, "getCache"),
83
+ setCache: /* @__PURE__ */ __name(() => {
84
+ }, "setCache")
85
+ });
86
+ function MapDataProvider({ mapData, children }) {
87
+ const cachedEntryRef = useRef(
88
+ mapData ? { mapData, options: {} } : void 0
89
+ );
90
+ const getCache = useCallback(() => cachedEntryRef.current, []);
91
+ const setCache = useCallback((entry) => {
92
+ cachedEntryRef.current = entry;
93
+ }, []);
94
+ const contextValue = useMemo(
95
+ () => ({
96
+ getCache,
97
+ setCache
98
+ }),
99
+ [getCache, setCache]
100
+ );
101
+ return /* @__PURE__ */ React.createElement(MapDataContext.Provider, { value: contextValue }, children);
102
+ }
103
+ __name(MapDataProvider, "MapDataProvider");
104
+
105
+ // src/hooks/useMapData.tsx
106
+ init_define_process();
107
+ var import_fast_deep_equal2 = __toESM(require_fast_deep_equal());
108
+ import { useCallback as useCallback2, useContext, useEffect, useRef as useRef3, useState } from "react";
109
+ import { getMapData } from "@mappedin/mappedin-js";
110
+
111
+ // ../packages/common/Mappedin.Logger.ts
112
+ init_define_process();
113
+ var MI_ERROR_LABEL = "[MappedinJS]";
114
+ function createLogger(name = "", { prefix = MI_ERROR_LABEL } = {}) {
115
+ const label = `${prefix}${name ? `-${name}` : ""}`;
116
+ const rnDebug = /* @__PURE__ */ __name((type, args) => {
117
+ if (typeof window !== "undefined" && window.rnDebug) {
118
+ const processed = args.map((arg) => {
119
+ if (arg instanceof Error && arg.stack) {
120
+ return `${arg.message}
121
+ ${arg.stack}`;
122
+ }
123
+ return arg;
124
+ });
125
+ window.rnDebug(`${name} ${type}: ${processed.join(" ")}`);
126
+ }
127
+ }, "rnDebug");
128
+ return {
129
+ logState: define_process_default.env.NODE_ENV === "test" ? 3 /* SILENT */ : 0 /* LOG */,
130
+ log(...args) {
131
+ if (this.logState <= 0 /* LOG */) {
132
+ console.log(label, ...args);
133
+ rnDebug("log", args);
134
+ }
135
+ },
136
+ warn(...args) {
137
+ if (this.logState <= 1 /* WARN */) {
138
+ console.warn(label, ...args);
139
+ rnDebug("warn", args);
140
+ }
141
+ },
142
+ error(...args) {
143
+ if (this.logState <= 2 /* ERROR */) {
144
+ console.error(label, ...args);
145
+ rnDebug("error", args);
146
+ }
147
+ },
148
+ // It's a bit tricky to prepend [MappedinJs] to assert and time because of how the output is structured in the console, so it is left out for simplicity
149
+ assert(...args) {
150
+ console.assert(...args);
151
+ },
152
+ time(label2) {
153
+ console.time(label2);
154
+ },
155
+ timeEnd(label2) {
156
+ console.timeEnd(label2);
157
+ },
158
+ setLevel(level) {
159
+ if (0 /* LOG */ <= level && level <= 3 /* SILENT */) {
160
+ this.logState = level;
161
+ }
162
+ }
163
+ };
164
+ }
165
+ __name(createLogger, "createLogger");
166
+ var Logger = createLogger();
167
+ var Mappedin_Logger_default = Logger;
168
+
169
+ // src/hooks/useMemoDeep.tsx
170
+ init_define_process();
171
+ var import_fast_deep_equal = __toESM(require_fast_deep_equal());
172
+ import { useRef as useRef2 } from "react";
173
+ function useMemoDeep(factory, deps) {
174
+ const valueRef = useRef2();
175
+ const depsRef = useRef2();
176
+ if (!(0, import_fast_deep_equal.default)(deps, depsRef.current)) {
177
+ valueRef.current = factory();
178
+ depsRef.current = deps;
179
+ }
180
+ return valueRef.current;
181
+ }
182
+ __name(useMemoDeep, "useMemoDeep");
183
+
184
+ // src/hooks/useMapData.tsx
185
+ function useMapData(options) {
186
+ const { getCache, setCache } = useContext(MapDataContext);
187
+ const [mapData, setMapData] = useState(void 0);
188
+ const [isLoading, setIsLoading] = useState(true);
189
+ const [error, setError] = useState(void 0);
190
+ const fetchIdRef = useRef3(0);
191
+ const memoizedOptions = useMemoDeep(
192
+ () => options && { ...options, analytics: { context: "reactsdk", ...options?.analytics } },
193
+ [options]
194
+ );
195
+ const fetchMapData = useCallback2((options2) => {
196
+ const fetchId = ++fetchIdRef.current;
197
+ setIsLoading(true);
198
+ setError(void 0);
199
+ getMapData(options2).then((fetchedMapData) => {
200
+ if (fetchIdRef.current === fetchId) {
201
+ setMapData(fetchedMapData);
202
+ }
203
+ }).catch((err) => {
204
+ if (fetchIdRef.current === fetchId) {
205
+ Mappedin_Logger_default.error("Failed to fetch MapData", err);
206
+ setError(err);
207
+ }
208
+ }).finally(() => {
209
+ if (fetchIdRef.current === fetchId) setIsLoading(false);
210
+ });
211
+ }, []);
212
+ useEffect(() => {
213
+ const cachedEntry = getCache?.();
214
+ if (cachedEntry != null) {
215
+ if (
216
+ // No options provided, use cached data
217
+ memoizedOptions == null || // Options provided and matches cached data
218
+ cachedEntry.mapData.mapId === memoizedOptions.mapId && (0, import_fast_deep_equal2.default)(cachedEntry.options, memoizedOptions)
219
+ ) {
220
+ setMapData(cachedEntry.mapData);
221
+ setIsLoading(false);
222
+ setError(void 0);
223
+ return;
224
+ }
225
+ }
226
+ if (!memoizedOptions) {
227
+ setError(new Error("useMapData requires options if not use within a MapDataProvider or MapView component."));
228
+ return;
229
+ }
230
+ fetchMapData(memoizedOptions);
231
+ }, [fetchMapData, getCache, memoizedOptions]);
232
+ useEffect(() => {
233
+ const cachedEntry = getCache?.();
234
+ if (mapData != null && (cachedEntry == null || cachedEntry.mapData.mapId === mapData.mapId)) {
235
+ setCache?.({ mapData, options: memoizedOptions || {} });
236
+ }
237
+ }, [mapData, memoizedOptions, getCache, setCache]);
238
+ return { mapData, isLoading, error };
239
+ }
240
+ __name(useMapData, "useMapData");
241
+
242
+ // src/hooks/useMapDataEvent.tsx
243
+ init_define_process();
244
+ import { useCallback as useCallback3, useContext as useContext2, useEffect as useEffect2 } from "react";
245
+ function useMapDataEvent(event, callback) {
246
+ const { getCache: getCachedMapData } = useContext2(MapDataContext);
247
+ const handleCallback = useCallback3((payload) => callback(payload), [callback]);
248
+ useEffect2(() => {
249
+ const mapData = getCachedMapData?.()?.mapData;
250
+ if (mapData == null) {
251
+ throw new Error("useMapDataEvent must be used within a MapDataProvider or MapView component.");
252
+ }
253
+ mapData.on(event, handleCallback);
254
+ return () => {
255
+ if (mapData == null) {
256
+ return;
257
+ }
258
+ mapData.off(event, handleCallback);
259
+ };
260
+ }, [getCachedMapData, event, handleCallback]);
261
+ }
262
+ __name(useMapDataEvent, "useMapDataEvent");
263
+
264
+ // src/MapView.tsx
265
+ init_define_process();
266
+ import React2, {
267
+ useCallback as useCallback4,
268
+ useEffect as useEffect3,
269
+ useMemo as useMemo2,
270
+ useRef as useRef4,
271
+ useState as useState2,
272
+ forwardRef,
273
+ useImperativeHandle,
274
+ createContext as createContext2
275
+ } from "react";
276
+ import { show3dMap } from "@mappedin/mappedin-js";
277
+ var MapViewContext = createContext2({
278
+ mapView: void 0,
279
+ extensions: {}
280
+ });
281
+ var DEFAULT_STYLE = {
282
+ width: "100%",
283
+ height: "100%",
284
+ position: "relative"
285
+ };
286
+ var MapView = forwardRef((props, ref) => {
287
+ const { mapData, options, style, fallback, children, ...rest } = props;
288
+ const thisRef = useRef4({
289
+ extensions: {}
290
+ // store the extensions in the ref so we don't re-render children when they change
291
+ }).current;
292
+ const [isLoading, setIsLoading] = useState2(true);
293
+ const [isMounted, setIsMounted] = useState2(false);
294
+ const mapEl = useRef4(null);
295
+ const memoizedMapData = useMemo2(() => mapData, [mapData]);
296
+ const memoizedOptions = useMemoDeep(() => options, [options]);
297
+ useImperativeHandle(ref, () => thisRef.mapView);
298
+ const contextValue = useMemo2(() => {
299
+ return {
300
+ mapView: thisRef.mapView,
301
+ extensions: thisRef.extensions
302
+ };
303
+ }, [memoizedMapData, thisRef.mapView, thisRef.extensions]);
304
+ const cleanUpExtensions = useCallback4((extensions) => {
305
+ try {
306
+ const extensionNames = Object.keys(extensions);
307
+ for (const extensionName of extensionNames) {
308
+ const extensionEntry = extensions[extensionName];
309
+ if (extensionEntry) {
310
+ extensionEntry.onDeregister(extensionEntry.instance);
311
+ delete extensions[extensionName];
312
+ }
313
+ }
314
+ } catch (error) {
315
+ Mappedin_Logger_default.error("Failed to clean up extensions", error);
316
+ }
317
+ return {};
318
+ }, []);
319
+ const destroyMapView = useCallback4((mapView) => {
320
+ const mapViewToDestroy = mapView || thisRef.mapView;
321
+ try {
322
+ mapViewToDestroy?.destroy?.();
323
+ } catch (error) {
324
+ Mappedin_Logger_default.error("Failed to destroy MapView", error);
325
+ }
326
+ if (!mapView) {
327
+ thisRef.extensions = cleanUpExtensions(thisRef.extensions);
328
+ thisRef.mapView = void 0;
329
+ setIsMounted(false);
330
+ }
331
+ }, []);
332
+ useEffect3(() => {
333
+ if (!memoizedMapData || !mapEl.current) {
334
+ return;
335
+ }
336
+ destroyMapView();
337
+ let cancelled = false;
338
+ setIsLoading(true);
339
+ show3dMap(mapEl.current, memoizedMapData, memoizedOptions).then((mapView) => {
340
+ if (!cancelled) {
341
+ thisRef.mapView = mapView;
342
+ setIsMounted(true);
343
+ } else {
344
+ destroyMapView(mapView);
345
+ }
346
+ }).catch((err) => {
347
+ Mappedin_Logger_default.error("Failed to render MapView", err);
348
+ }).finally(() => {
349
+ if (!cancelled) {
350
+ setIsLoading(false);
351
+ }
352
+ });
353
+ return () => {
354
+ cancelled = true;
355
+ if (thisRef.mapView) {
356
+ destroyMapView();
357
+ }
358
+ };
359
+ }, [memoizedMapData, memoizedOptions, destroyMapView]);
360
+ return /* @__PURE__ */ React2.createElement(MapDataProvider, { mapData: memoizedMapData }, /* @__PURE__ */ React2.createElement(MapViewContext.Provider, { value: contextValue }, /* @__PURE__ */ React2.createElement("div", { "data-testid": "mappedin-map", ref: mapEl, style: { ...DEFAULT_STYLE, ...style }, ...rest }), isLoading ? /* @__PURE__ */ React2.createElement(React2.Fragment, null, fallback) : isMounted ? children : null));
361
+ });
362
+
363
+ // src/hooks/useMapViewEvent.tsx
364
+ init_define_process();
365
+ import { useCallback as useCallback5, useContext as useContext3, useEffect as useEffect4 } from "react";
366
+
367
+ // src/errors.ts
368
+ init_define_process();
369
+ var MapViewNullError = class extends Error {
370
+ static {
371
+ __name(this, "MapViewNullError");
372
+ }
373
+ constructor(name) {
374
+ super(`${name} must be used within a MapView component.`);
375
+ }
376
+ };
377
+
378
+ // src/hooks/useMapViewEvent.tsx
379
+ function useMapViewEvent(event, callback) {
380
+ const { mapView } = useContext3(MapViewContext);
381
+ const handleCallback = useCallback5((payload) => callback(payload), [callback]);
382
+ useEffect4(() => {
383
+ if (mapView == null) {
384
+ throw new MapViewNullError("useMapViewEvent");
385
+ }
386
+ mapView.on(event, handleCallback);
387
+ return () => {
388
+ if (mapView == null) {
389
+ return;
390
+ }
391
+ mapView.off(event, handleCallback);
392
+ };
393
+ }, [mapView, event, callback]);
394
+ }
395
+ __name(useMapViewEvent, "useMapViewEvent");
396
+
397
+ // src/hooks/useMapViewExtension.tsx
398
+ init_define_process();
399
+ import { useCallback as useCallback6, useContext as useContext4 } from "react";
400
+ function useMapViewExtension(name, options) {
401
+ const { extensions } = useContext4(MapViewContext);
402
+ if (!options?.onRegister || !options?.onDeregister) {
403
+ throw new Error("onRegister and onDeregister are required");
404
+ }
405
+ const register = useCallback6(() => {
406
+ const existingEntry = extensions[name];
407
+ let instance = existingEntry?.instance;
408
+ if (!instance) {
409
+ instance = options.onRegister();
410
+ extensions[name] = {
411
+ instance,
412
+ onDeregister: options.onDeregister
413
+ };
414
+ }
415
+ return instance;
416
+ }, [extensions, name, options.onRegister]);
417
+ const deregister = useCallback6(() => {
418
+ const extensionEntry = extensions[name];
419
+ if (extensionEntry) {
420
+ extensionEntry.onDeregister(extensionEntry.instance);
421
+ delete extensions[name];
422
+ }
423
+ }, [extensions, name, options.onDeregister]);
424
+ return {
425
+ register,
426
+ deregister
427
+ };
428
+ }
429
+ __name(useMapViewExtension, "useMapViewExtension");
430
+
431
+ // src/Path.tsx
432
+ init_define_process();
433
+ import { useContext as useContext5, useEffect as useEffect6, useRef as useRef6, forwardRef as forwardRef2, useImperativeHandle as useImperativeHandle2, useState as useState3 } from "react";
434
+
435
+ // src/hooks/useUpdateEffect.ts
436
+ init_define_process();
437
+ import { useEffect as useEffect5, useRef as useRef5 } from "react";
438
+ function useUpdateEffect(effect, deps) {
439
+ const isInitialRender = useRef5(true);
440
+ useEffect5(() => {
441
+ if (isInitialRender.current) {
442
+ isInitialRender.current = false;
443
+ return;
444
+ }
445
+ return effect();
446
+ }, deps);
447
+ }
448
+ __name(useUpdateEffect, "useUpdateEffect");
449
+
450
+ // src/Path.tsx
451
+ var Path = forwardRef2((props, ref) => {
452
+ const { mapView } = useContext5(MapViewContext);
453
+ const pathRef = useRef6();
454
+ const memoizedOptions = useMemoDeep(() => props.options, [props.options]);
455
+ const [pathReady, setPathReady] = useState3(false);
456
+ useImperativeHandle2(ref, () => pathRef.current, [pathReady]);
457
+ useEffect6(() => {
458
+ if (mapView == null) {
459
+ throw new MapViewNullError("Path");
460
+ }
461
+ const path = mapView.Paths.add(props.coordinate, memoizedOptions);
462
+ path.animation.then(() => {
463
+ props.onDrawComplete?.();
464
+ });
465
+ pathRef.current = path;
466
+ setPathReady(true);
467
+ return () => {
468
+ if (pathRef.current) {
469
+ mapView.Paths.remove(pathRef.current);
470
+ }
471
+ setPathReady(false);
472
+ };
473
+ }, [mapView, props.coordinate]);
474
+ useUpdateEffect(() => {
475
+ if (pathRef.current && memoizedOptions) {
476
+ mapView?.updateState(pathRef.current, memoizedOptions);
477
+ }
478
+ }, [memoizedOptions]);
479
+ return null;
480
+ });
481
+
482
+ // src/Navigation.tsx
483
+ init_define_process();
484
+ import { useContext as useContext6, useEffect as useEffect7 } from "react";
485
+ function Navigation(props) {
486
+ const { mapView } = useContext6(MapViewContext);
487
+ const memoizedOptions = useMemoDeep(() => props.options, [props.options]);
488
+ useEffect7(() => {
489
+ if (mapView == null) {
490
+ throw new MapViewNullError("Navigation");
491
+ }
492
+ mapView.Navigation.draw(props.directions, memoizedOptions).then(() => {
493
+ props.onDrawComplete?.();
494
+ });
495
+ return () => {
496
+ mapView.Navigation.clear();
497
+ };
498
+ }, [mapView, props.directions, memoizedOptions]);
499
+ return null;
500
+ }
501
+ __name(Navigation, "Navigation");
502
+
503
+ // src/Shape.tsx
504
+ init_define_process();
505
+ import { useContext as useContext7, useEffect as useEffect8, useRef as useRef7, forwardRef as forwardRef3, useImperativeHandle as useImperativeHandle3, useState as useState4 } from "react";
506
+ var Shape = forwardRef3((props, ref) => {
507
+ const { mapView } = useContext7(MapViewContext);
508
+ const shapeRef = useRef7();
509
+ const memoizedStyle = useMemoDeep(() => props.style, [props.style]);
510
+ const [shapeReady, setShapeReady] = useState4(false);
511
+ useImperativeHandle3(ref, () => shapeRef.current, [shapeReady]);
512
+ useEffect8(() => {
513
+ if (mapView == null) {
514
+ throw new Error("MapView not initialized");
515
+ }
516
+ shapeRef.current = mapView.Shapes.add(props.geometry, props.style, props.floor);
517
+ setShapeReady(true);
518
+ return () => {
519
+ if (mapView == null || shapeRef.current == null) {
520
+ return;
521
+ }
522
+ mapView.Shapes.remove(shapeRef.current);
523
+ setShapeReady(false);
524
+ };
525
+ }, [mapView, props.geometry, props.style, props.floor]);
526
+ useUpdateEffect(() => {
527
+ if (shapeRef.current && memoizedStyle) {
528
+ mapView?.updateState(shapeRef.current, memoizedStyle);
529
+ }
530
+ }, [memoizedStyle]);
531
+ return null;
532
+ });
533
+
534
+ // src/Model.tsx
535
+ init_define_process();
536
+ import { useContext as useContext8, useEffect as useEffect9, useRef as useRef8, forwardRef as forwardRef4, useImperativeHandle as useImperativeHandle4, useState as useState5 } from "react";
537
+ var Model = forwardRef4((props, ref) => {
538
+ const { mapView } = useContext8(MapViewContext);
539
+ const modelRef = useRef8();
540
+ const memoizedOptions = useMemoDeep(() => props.options, [props.options]);
541
+ const [modelReady, setModelReady] = useState5(false);
542
+ useImperativeHandle4(ref, () => modelRef.current, [modelReady]);
543
+ useEffect9(() => {
544
+ if (mapView == null) {
545
+ throw new MapViewNullError("Model");
546
+ }
547
+ modelRef.current = mapView.Models.add(props.coordinate, props.url, memoizedOptions);
548
+ setModelReady(true);
549
+ return () => {
550
+ if (mapView == null || modelRef.current == null) {
551
+ return;
552
+ }
553
+ mapView.Models.remove(modelRef.current);
554
+ setModelReady(false);
555
+ };
556
+ }, [mapView, props.url]);
557
+ useUpdateEffect(() => {
558
+ if (modelRef.current) {
559
+ mapView?.updateState(modelRef.current, {
560
+ position: props.coordinate,
561
+ ...memoizedOptions
562
+ });
563
+ }
564
+ }, [props.coordinate, memoizedOptions]);
565
+ return null;
566
+ });
567
+
568
+ // src/hooks/useMap.tsx
569
+ init_define_process();
570
+ import { useContext as useContext9 } from "react";
571
+ function useMap() {
572
+ const { mapView } = useContext9(MapViewContext);
573
+ const { getCache: getCachedMapData } = useContext9(MapDataContext);
574
+ if (!mapView) {
575
+ throw new MapViewNullError("useMap");
576
+ }
577
+ return { mapData: getCachedMapData?.()?.mapData || mapView.getMapData(), mapView };
578
+ }
579
+ __name(useMap, "useMap");
580
+
581
+ // src/Marker.tsx
582
+ init_define_process();
583
+ import React3, {
584
+ useCallback as useCallback7,
585
+ useContext as useContext10,
586
+ useEffect as useEffect10,
587
+ useMemo as useMemo3,
588
+ useRef as useRef9,
589
+ forwardRef as forwardRef5,
590
+ useImperativeHandle as useImperativeHandle5,
591
+ useState as useState6
592
+ } from "react";
593
+ import { createPortal } from "react-dom";
594
+
595
+ // ../packages/common/random-id.ts
596
+ init_define_process();
597
+ var SLICE_POSITIONS = [0, 4, 6, 8, 10];
598
+ var randomId = /* @__PURE__ */ __name(() => {
599
+ const array = new Array(16).fill(0);
600
+ let seed = Math.random() * 4294967296;
601
+ for (let i = 0; i < array.length; i++) {
602
+ if (i > 0 && (i & 3) === 0) {
603
+ seed = Math.random() * 4294967296;
604
+ }
605
+ array[i] = seed >>> ((i & 3) << 3) & 255;
606
+ }
607
+ const hexArray = array.map((n) => n.toString(16).padStart(2, "0"));
608
+ hexArray[6] = "4" + hexArray[6][1];
609
+ hexArray[8] = ["8", "9", "a", "b"].includes(hexArray[7][0]) ? hexArray[7] : "a" + hexArray[7][1];
610
+ return SLICE_POSITIONS.map(
611
+ (v, i) => hexArray.slice(v, i === SLICE_POSITIONS.length - 1 ? void 0 : SLICE_POSITIONS[i + 1]).join("")
612
+ ).join("-");
613
+ }, "randomId");
614
+
615
+ // src/Marker.tsx
616
+ var Marker = forwardRef5((props, ref) => {
617
+ const { mapView } = useContext10(MapViewContext);
618
+ const markerRef = useRef9();
619
+ const [markerReady, setMarkerReady] = useState6(false);
620
+ const memoizedOptions = useMemoDeep(() => props.options, [props.options]);
621
+ useImperativeHandle5(ref, () => markerRef.current, [markerReady]);
622
+ useEffect10(() => {
623
+ if (mapView == null) {
624
+ throw new MapViewNullError("Marker");
625
+ }
626
+ markerRef.current = mapView.Markers.add(props.target, "", memoizedOptions);
627
+ setMarkerReady(true);
628
+ return () => {
629
+ if (mapView == null || markerRef.current == null) {
630
+ return;
631
+ }
632
+ mapView.Markers.remove(markerRef.current);
633
+ setMarkerReady(false);
634
+ };
635
+ }, [mapView, props.target]);
636
+ useUpdateEffect(() => {
637
+ if (markerRef.current && memoizedOptions) {
638
+ mapView?.updateState(markerRef.current, memoizedOptions);
639
+ }
640
+ }, [memoizedOptions]);
641
+ if (mapView == null || markerRef.current == null) {
642
+ return null;
643
+ }
644
+ return createPortal(props.children, markerRef.current.contentEl, markerRef.current.id);
645
+ });
646
+ var AnimatedMarker = forwardRef5(
647
+ (props, ref) => {
648
+ const { mapView } = useContext10(MapViewContext);
649
+ const keyRef = useRef9(randomId());
650
+ const markerRef = useRef9();
651
+ const [markerReady, setMarkerReady] = useState6(false);
652
+ const initialTarget = useRef9(props.target);
653
+ useImperativeHandle5(ref, () => markerRef.current, [markerReady]);
654
+ const handleMarkerRef = useCallback7((marker) => {
655
+ markerRef.current = marker || void 0;
656
+ setMarkerReady(!!marker);
657
+ }, []);
658
+ useEffect10(() => {
659
+ if (mapView == null) {
660
+ throw new MapViewNullError("Marker");
661
+ }
662
+ if (markerRef.current && markerRef.current.target !== props.target) {
663
+ const { duration = 300, easing = "linear" } = props;
664
+ mapView.Markers.animateTo(markerRef.current, props.target, { duration, easing });
665
+ }
666
+ return () => {
667
+ setMarkerReady(false);
668
+ };
669
+ }, [mapView, props.target]);
670
+ const propsWithoutAnimation = useMemo3(
671
+ () => ({ ...props, duration: void 0, easing: void 0 }),
672
+ [props.duration, props.easing]
673
+ );
674
+ return /* @__PURE__ */ React3.createElement(Marker, { ...propsWithoutAnimation, key: keyRef.current, target: initialTarget.current, ref: handleMarkerRef });
675
+ }
676
+ );
677
+
678
+ // src/Label.tsx
679
+ init_define_process();
680
+ import { forwardRef as forwardRef6, useContext as useContext11, useEffect as useEffect11, useImperativeHandle as useImperativeHandle6, useRef as useRef10, useState as useState7 } from "react";
681
+ var Label = forwardRef6((props, ref) => {
682
+ const { mapView } = useContext11(MapViewContext);
683
+ const labelRef = useRef10();
684
+ const [isLabelReady, setIsLabelReady] = useState7(false);
685
+ const memoizedOptions = useMemoDeep(() => props.options, [props.options]);
686
+ useImperativeHandle6(ref, () => labelRef.current, [isLabelReady]);
687
+ useEffect11(() => {
688
+ if (mapView == null) {
689
+ throw new MapViewNullError("Label");
690
+ }
691
+ labelRef.current = mapView.Labels.add(props.target, props.text, memoizedOptions);
692
+ setIsLabelReady(true);
693
+ return () => {
694
+ if (mapView == null || labelRef.current == null) {
695
+ return;
696
+ }
697
+ mapView.Labels.remove(labelRef.current);
698
+ setIsLabelReady(false);
699
+ };
700
+ }, [mapView, props.target]);
701
+ useUpdateEffect(() => {
702
+ if (labelRef.current) {
703
+ mapView?.updateState(labelRef.current, {
704
+ text: props.text,
705
+ ...memoizedOptions
706
+ });
707
+ }
708
+ }, [props.text, memoizedOptions]);
709
+ return null;
710
+ });
711
+ export {
712
+ AnimatedMarker,
713
+ Label,
714
+ MapDataProvider,
715
+ MapView,
716
+ Marker,
717
+ Model,
718
+ Navigation,
719
+ Path,
720
+ Shape,
721
+ useMap,
722
+ useMapData,
723
+ useMapDataEvent,
724
+ useMapViewEvent,
725
+ useMapViewExtension
726
+ };
727
+ //# sourceMappingURL=index.js.map