@mappedin/dynamic-focus 6.0.1-beta.61 → 6.5.0-beta.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.
@@ -1,77 +1 @@
1
- import {
2
- DynamicFocus,
3
- __name
4
- } from "../chunk-RSECYADN.js";
5
-
6
- // src/react/use-dynamic-focus.ts
7
- import { useCallback, useState, useMemo } from "react";
8
- import { useMap, useMapViewExtension } from "@mappedin/react-sdk";
9
- function useForceUpdate() {
10
- const [, setState] = useState({});
11
- return useCallback(() => setState({}), []);
12
- }
13
- __name(useForceUpdate, "useForceUpdate");
14
- function useDynamicFocus() {
15
- const { mapView } = useMap();
16
- const forceUpdate = useForceUpdate();
17
- const { register } = useMapViewExtension("dynamic-focus", {
18
- onRegister: /* @__PURE__ */ __name(() => {
19
- const df = new DynamicFocus(mapView);
20
- df.on("state-change", forceUpdate);
21
- return df;
22
- }, "onRegister"),
23
- onDeregister: /* @__PURE__ */ __name((df) => {
24
- df.off("state-change", forceUpdate);
25
- df.destroy();
26
- }, "onDeregister")
27
- });
28
- const dynamicFocus = register();
29
- if (!dynamicFocus) {
30
- throw new Error("DynamicFocus is not initialized");
31
- }
32
- return useMemo(() => {
33
- const boundFunctions = /* @__PURE__ */ new WeakMap();
34
- return new Proxy(dynamicFocus, {
35
- get(target, prop) {
36
- const value = target[prop];
37
- if (typeof value === "function") {
38
- if (!boundFunctions.has(value)) {
39
- boundFunctions.set(value, value.bind(target));
40
- }
41
- return boundFunctions.get(value);
42
- }
43
- return value;
44
- }
45
- });
46
- }, [dynamicFocus]);
47
- }
48
- __name(useDynamicFocus, "useDynamicFocus");
49
-
50
- // src/react/use-dynamic-focus-event.ts
51
- import { useCallback as useCallback2, useEffect, useRef } from "react";
52
- function useDynamicFocusEvent(event, callback) {
53
- const instance = useDynamicFocus();
54
- const callbackRef = useRef(callback);
55
- callbackRef.current = callback;
56
- const handleCallback = useCallback2((payload) => {
57
- callbackRef.current(payload);
58
- }, []);
59
- useEffect(() => {
60
- if (instance == null) {
61
- return;
62
- }
63
- instance.on(event, handleCallback);
64
- return () => {
65
- if (instance == null) {
66
- return;
67
- }
68
- instance.off(event, handleCallback);
69
- };
70
- }, [instance, event, handleCallback]);
71
- }
72
- __name(useDynamicFocusEvent, "useDynamicFocusEvent");
73
- export {
74
- useDynamicFocus,
75
- useDynamicFocusEvent
76
- };
77
- //# sourceMappingURL=index.js.map
1
+ import{a as t,b as a}from"../chunk-D4Z7IQAJ.js";import{useCallback as y,useState as p,useMemo as F}from"react";import{useMap as l,useMapViewExtension as D}from"@mappedin/react-sdk";function d(){let[,n]=p({});return y(()=>n({}),[])}t(d,"useForceUpdate");function i(){let{mapView:n}=l(),r=d(),{register:o}=D("dynamic-focus",{onRegister:t(()=>{let e=new a(n);return e.on("state-change",r),e},"onRegister"),onDeregister:t(e=>{e.off("state-change",r),e.destroy()},"onDeregister")}),s=o();if(!s)throw new Error("DynamicFocus is not initialized");return F(()=>{let e=new WeakMap;return new Proxy(s,{get(u,m){let c=u[m];return typeof c=="function"?(e.has(c)||e.set(c,c.bind(u)),e.get(c)):c}})},[s])}t(i,"useDynamicFocus");import{useCallback as w,useEffect as E,useRef as k}from"react";function x(n,r){let o=i(),s=k(r);s.current=r;let e=w(u=>{s.current(u)},[]);E(()=>{if(o!=null)return o.on(n,e),()=>{o!=null&&o.off(n,e)}},[o,n,e])}t(x,"useDynamicFocusEvent");export{i as useDynamicFocus,x as useDynamicFocusEvent};
@@ -1,97 +1,5 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
- // src/rn/use-dynamic-focus.ts
5
- import { useState, useCallback as useCallback2, useContext as useContext2, useRef } from "react";
6
- import { MappedinContext as MappedinContext2 } from "@mappedin/react-native-sdk";
7
-
8
- // src/rn/use-dynamic-focus-events.ts
9
- import { useCallback, useContext } from "react";
10
-
11
- // ../packages/common/Mappedin.Logger.ts
12
- var MI_ERROR_LABEL = "[MappedinJS]";
13
- function createLogger(name = "", { prefix = MI_ERROR_LABEL } = {}) {
14
- const label = `${prefix}${name ? `-${name}` : ""}`;
15
- const rnDebug = /* @__PURE__ */ __name((type, args) => {
16
- if (typeof window !== "undefined" && window.rnDebug) {
17
- const processed = args.map((arg) => {
18
- if (arg instanceof Error && arg.stack) {
19
- return `${arg.message}
20
- ${arg.stack}`;
21
- }
22
- return arg;
23
- });
24
- window.rnDebug(`${name} ${type}: ${processed.join(" ")}`);
25
- }
26
- }, "rnDebug");
27
- return {
28
- logState: false ? 3 /* SILENT */ : 0 /* LOG */,
29
- log(...args) {
30
- if (this.logState <= 0 /* LOG */) {
31
- console.log(label, ...args);
32
- rnDebug("log", args);
33
- }
34
- },
35
- warn(...args) {
36
- if (this.logState <= 1 /* WARN */) {
37
- console.warn(label, ...args);
38
- rnDebug("warn", args);
39
- }
40
- },
41
- error(...args) {
42
- if (this.logState <= 2 /* ERROR */) {
43
- console.error(label, ...args);
44
- rnDebug("error", args);
45
- }
46
- },
47
- // 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
48
- assert(...args) {
49
- console.assert(...args);
50
- },
51
- time(label2) {
52
- console.time(label2);
53
- },
54
- timeEnd(label2) {
55
- console.timeEnd(label2);
56
- },
57
- setLevel(level) {
58
- if (0 /* LOG */ <= level && level <= 3 /* SILENT */) {
59
- this.logState = level;
60
- }
61
- }
62
- };
63
- }
64
- __name(createLogger, "createLogger");
65
- var Logger = createLogger();
66
-
67
- // src/logger.ts
68
- var Logger2 = createLogger("", { prefix: "[DynamicFocus]" });
69
-
70
- // src/rn/use-dynamic-focus-events.ts
71
- import {
72
- MappedinContext,
73
- useEventCallback,
74
- createEventSetupScript,
75
- createEventCleanupScript
76
- } from "@mappedin/react-native-sdk";
77
-
78
- // src/rn/utils/facade-hydration.ts
79
- function hydrateFacades(mapData, facades) {
80
- return facades.map((facadeData) => {
81
- if (facadeData && facadeData.id) {
82
- const hydratedFacade = mapData.getById("facade", facadeData.id);
83
- return hydratedFacade || facadeData;
84
- }
85
- return facadeData;
86
- });
87
- }
88
- __name(hydrateFacades, "hydrateFacades");
89
-
90
- // src/rn/use-dynamic-focus-registration.ts
91
- import { useRegisterExtension } from "@mappedin/react-native-sdk";
92
-
93
- // src/rn/extension-source.ts
94
- var EXTENSION_SOURCE_PLACEHOLDER = `
1
+ var W=Object.defineProperty,l=(e,i)=>W(e,"name",{value:i,configurable:!0});import{useState as _,useCallback as c,useContext as T,useRef as A}from"react";import{MappedinContext as I}from"@mappedin/react-native-sdk";import{useCallback as B,useContext as Z}from"react";var $="[MappedinJS]";function m(e="",{prefix:i=$}={}){const o=`${i}${e?`-${e}`:""}`,a=l((t,d)=>{if(typeof window<"u"&&window.rnDebug){const f=d.map(s=>s instanceof Error&&s.stack?`${s.message}
2
+ ${s.stack}`:s);window.rnDebug(`${e} ${t}: ${f.join(" ")}`)}},"rnDebug");return{logState:0,log(...t){this.logState<=0&&(console.log(o,...t),a("log",t))},warn(...t){this.logState<=1&&(console.warn(o,...t),a("warn",t))},error(...t){this.logState<=2&&(console.error(o,...t),a("error",t))},assert(...t){console.assert(...t)},time(t){console.time(t)},timeEnd(t){console.timeEnd(t)},setLevel(t){0<=t&&t<=3&&(this.logState=t)}}}l(m,"createLogger");var U=m(),w=m("",{prefix:"[DynamicFocus]"});import{MappedinContext as j,useEventCallback as L,createEventSetupScript as R,createEventCleanupScript as V}from"@mappedin/react-native-sdk";function v(e,i){return i.map(o=>o&&o.id&&e.getById("facade",o.id)||o)}l(v,"hydrateFacades");import{useRegisterExtension as N}from"@mappedin/react-native-sdk";var P=`
95
3
  // Define require function that uses bridge.modules for external dependencies
96
4
  globalThis.require = globalThis.require || ((id) => {
97
5
  if (window.bridge?.modules?.[id]) {
@@ -100,9 +8,8 @@ var EXTENSION_SOURCE_PLACEHOLDER = `
100
8
  throw new Error('Module not found: ' + id);
101
9
  });
102
10
 
103
- "use strict";var DynamicFocus=(()=>{var J=Object.defineProperty;var Ut=Object.getOwnPropertyDescriptor;var \$t=Object.getOwnPropertyNames;var Ht=Object.prototype.hasOwnProperty;var Mt=r=>{throw TypeError(r)};var qt=(r,t,e)=>t in r?J(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var s=(r,t)=>J(r,"name",{value:t,configurable:!0}),st=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var Wt=(r,t)=>{for(var e in t)J(r,e,{get:t[e],enumerable:!0})},Kt=(r,t,e,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of \$t(t))!Ht.call(r,i)&&i!==e&&J(r,i,{get:()=>t[i],enumerable:!(a=Ut(t,i))||a.enumerable});return r};var zt=r=>Kt(J({},"__esModule",{value:!0}),r);var m=(r,t,e)=>qt(r,typeof t!="symbol"?t+"":t,e),pt=(r,t,e)=>t.has(r)||Mt("Cannot "+e);var o=(r,t,e)=>(pt(r,t,"read from private field"),e?e.call(r):t.get(r)),u=(r,t,e)=>t.has(r)?Mt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(r):t.set(r,e),l=(r,t,e,a)=>(pt(r,t,"write to private field"),a?a.call(r,e):t.set(r,e),e),b=(r,t,e)=>(pt(r,t,"access private method"),e);var oo={};Wt(oo,{DynamicFocus:()=>ft});var mt=st("@mappedin/mappedin-js");function Vt(r,t){if(r==null||t==null)return r===t;if(r.length!==t.length)return!1;for(let e=0;e<r.length;e++)if(r[e]!==t[e])return!1;return!0}s(Vt,"arraysEqual");var Ft=class Ft{constructor(){m(this,"_subscribers",{});m(this,"_destroyed",!1)}publish(t,e){!this._subscribers||!this._subscribers[t]||this._destroyed||this._subscribers[t].forEach(function(a){typeof a=="function"&&a(e)})}on(t,e){(!this._subscribers||this._destroyed)&&(this._subscribers={}),this._subscribers[t]=this._subscribers[t]||[],this._subscribers[t].push(e)}off(t,e){if(!this._subscribers||this._subscribers[t]==null||this._destroyed)return;let a=this._subscribers[t].indexOf(e);a!==-1&&this._subscribers[t].splice(a,1)}destroy(){this._destroyed=!0,this._subscribers={}}};s(Ft,"PubSub");var lt=Ft;var Y=st("@mappedin/mappedin-js");var E,X,w,S,F,k,j,G,gt=class gt{constructor(t,e){m(this,"__type","building");u(this,E);u(this,X,new Map);u(this,w,new Map);u(this,S,[]);u(this,F);u(this,k);m(this,"defaultFloor");m(this,"activeFloor");m(this,"excluded",!1);m(this,"floorsAltitudesMap",new Map);m(this,"aboveGroundFloors",[]);u(this,j);u(this,G);l(this,E,t),l(this,X,new Map(t.floors.map(i=>[i.id,i]))),l(this,w,new Map(t.floors.map(i=>[i.elevation,i]))),l(this,S,Array.from(o(this,w).values()).sort((i,c)=>i.elevation-c.elevation)),this.defaultFloor=t.defaultFloor,this.activeFloor=this.defaultFloor,l(this,F,e),this.aboveGroundFloors=o(this,S).filter(i=>i.elevation>=0);let a=t.facade?.spaces.map(i=>o(this,F).getState(i)).sort((i,c)=>i.altitude-c.altitude);if(a&&a.length===this.aboveGroundFloors.length)for(let i in this.aboveGroundFloors){let c=this.aboveGroundFloors[i],y=a[i];this.floorsAltitudesMap.set(c.elevation,{altitude:y.altitude,effectiveHeight:y.height})}}get id(){return o(this,E).id}get name(){return o(this,E).name}get floors(){return o(this,E).floors}get floorStack(){return o(this,E)}get facade(){return o(this,E).facade}get isCurrentFloorStack(){return this.id===o(this,F).currentFloorStack.id}get isIndoor(){let t=o(this,F).getState(this.facade);return this.isCurrentFloorStack||t?.visible===!1&&t?.opacity===0}get canSetFloor(){return this.isIndoor||!this.excluded}get maxElevation(){return o(this,j)==null&&l(this,j,Math.max(...o(this,w).keys())),o(this,j)}get minElevation(){return o(this,G)==null&&l(this,G,Math.min(...o(this,w).keys())),o(this,G)}has(t){return Y.Floor.is(t)?o(this,X).has(t.id):Y.FloorStack.is(t)?t.id===o(this,E).id:Y.Facade.is(t)?t.id===this.facade.id:!1}getFloorByElevation(t){return o(this,w).get(t)}getNearestFloorByElevation(t){let e=this.getFloorByElevation(t);if(e)return e;if(t>=0){if(t>this.maxElevation)return o(this,S)[o(this,S).length-1];for(let a=o(this,S).length-1;a>=0;a--){let i=o(this,S)[a];if(i.elevation<=t)return i}}else{if(t<this.minElevation)return o(this,S)[0];for(let a of o(this,S))if(a.elevation>=t)return a}}getHighestFloor(){return o(this,S)[o(this,S).length-1]}cancelAnimation(){o(this,k)&&(o(this,k).animation.cancel(),l(this,k,void 0))}async animateFacade(t,e={duration:150}){let a=o(this,k)?.state||o(this,F).getState(this.facade);if(!a||!t||a?.opacity===t.opacity&&a?.visible===t.visible)return{result:"completed"};this.cancelAnimation();let{opacity:i,visible:c}=t;if(o(this,F).updateState(this.facade,{visible:!0}),i!==void 0){l(this,k,{animation:o(this,F).animateState(this.facade,{opacity:i},{duration:e.duration}),state:t});let y=await o(this,k).animation;if(l(this,k,void 0),y.result==="cancelled")return y}return c===!1&&o(this,F).updateState(this.facade,{visible:c}),{result:"completed"}}destroy(){this.cancelAnimation(),o(this,E).floors.forEach(t=>{o(this,F).updateState(t,{visible:t.id===o(this,F).currentFloor.id})}),this.has(o(this,F).currentFloor)||o(this,F).updateState(this.facade,{visible:!0,opacity:1})}};E=new WeakMap,X=new WeakMap,w=new WeakMap,S=new WeakMap,F=new WeakMap,k=new WeakMap,j=new WeakMap,G=new WeakMap,s(gt,"Building");var ut=gt;function xt(r,t,e){return r>=t?"in-range":r<=e?"out-of-range":"transition"}s(xt,"getZoomState");function dt(r,t,e){if(r.__type==="outdoors"&&"floor"in r)return r.floor;let a=r;if(a.excluded)return a.activeFloor;switch(t){case"lock-elevation":return a.getFloorByElevation(e);case"nearest-elevation":return a.getNearestFloorByElevation(e);default:break}return a.isIndoor?a.activeFloor:a.defaultFloor}s(dt,"getFloorToShow");function Qt(r,t){return{facade:r,state:{type:"facade",visible:!t,opacity:t?0:1}}}s(Qt,"getFacadeState");function Jt(r,t,e){return{outdoorOpacity:1,floorStates:r.floors.map(a=>{let i=a.id===t.id&&e;return{floor:a,state:{type:"floor",visible:i,geometry:{visible:i},labels:{enabled:i},markers:{enabled:i},footprint:{visible:!1},occlusion:{enabled:!1}}}})}}s(Jt,"getSingleBuildingState");function Ot(r,t){if(!t.includes("lock-elevation"))return 1;for(let e of r)if(e.outdoorOpacity>=0&&e.outdoorOpacity<=1)return e.outdoorOpacity;return 1}s(Ot,"getOutdoorOpacity");function Bt(r,t,e){switch(e){case"in-range":return r[0]?.canSetFloor?r[0]:void 0;case"out-of-range":return t;case"transition":default:return}}s(Bt,"getSetFloorTargetFromZoomState");function _t(r,t,e,a,i,c,y,p,z,rt,O){let C=new Map;for(let f of r){let P=t.has(f.id),R=yt(f,e,a==="in-range",P,i,c,p.includes(f.id),O),Q=e.floorStack.id===f.id?f.activeFloor:dt(f,i,c),nt=z.enabled?rt(f.floors,Q||f.activeFloor,z?.floorGap,y,f.floorsAltitudesMap):Jt(f.floorStack,Q||f.activeFloor,R),Yt=Qt(f.facade,R);C.set(f.id,{building:f,showIndoor:R,floorStackState:nt,facadeState:Yt,inFocus:P,floorToShow:Q})}return C}s(_t,"getBuildingStates");function Nt(r,t){return r.excluded?"none":t?"indoor":"outdoor"}s(Nt,"getBuildingAnimationType");function yt(r,t,e,a,i,c,y,p){if(r.id===t.floorStack.id)return!0;if(r.excluded)return!1;if(y===!0)return!0;if(!p)return t.floorStack.type!=="Outdoor";if(!e||!a)return!1;switch(i){case"lock-elevation":return r.getFloorByElevation(c)!=null;default:break}return!0}s(yt,"shouldShowIndoor");function It(r,t,e){return r!==t&&!e}s(It,"shouldDeferSetFloor");var Lt=["default-floor","lock-elevation","nearest-elevation"];var ct=st("@mappedin/mappedin-js");var Xt="[MappedinJS]";function St(r="",{prefix:t=Xt}={}){let e=\`\${t}\${r?\`-\${r}\`:""}\`,a=s((i,c)=>{if(typeof window<"u"&&window.rnDebug){let y=c.map(p=>p instanceof Error&&p.stack?\`\${p.message}
104
- \${p.stack}\`:p);window.rnDebug(\`\${r} \${i}: \${y.join(" ")}\`)}},"rnDebug");return{logState:0,log(...i){this.logState<=0&&(console.log(e,...i),a("log",i))},warn(...i){this.logState<=1&&(console.warn(e,...i),a("warn",i))},error(...i){this.logState<=2&&(console.error(e,...i),a("error",i))},assert(...i){console.assert(...i)},time(i){console.time(i)},timeEnd(i){console.timeEnd(i)},setLevel(i){0<=i&&i<=3&&(this.logState=i)}}}s(St,"createLogger");var to=St();var U=to;function Zt(r,t,e,a){return(r<t||r>e)&&U.warn(a),Math.min(e,Math.max(t,r))}s(Zt,"clampWithWarning");function bt(r,t){return!ct.Floor.is(r)||r?.floorStack==null||!ct.FloorStack.is(t)?!1:r.floorStack.id!==t.id?(U.warn(\`Floor (\${r.id}) does not belong to floor stack (\${t.id}).\`),!1):!0}s(bt,"validateFloorForStack");function Et(r,t,e,a){return Zt(r,t,e,\`\${a} must be between \${t} and \${e}.\`)}s(Et,"validateZoomThreshold");var \$=St("",{prefix:"[DynamicFocus]"});var D,H,tt,vt,kt=class kt{constructor(t,e){u(this,tt);m(this,"__type","outdoors");u(this,D);u(this,H);l(this,D,t),l(this,H,e)}get id(){return o(this,D).id}get floorStack(){return o(this,D)}get floor(){return o(this,D).defaultFloor}matchesFloorStack(t){return t===o(this,D)||t===o(this,D).id}show(){b(this,tt,vt).call(this,!0)}hide(){b(this,tt,vt).call(this,!1)}destroy(){this.matchesFloorStack(o(this,H).currentFloorStack)||this.hide()}};D=new WeakMap,H=new WeakMap,tt=new WeakSet,vt=s(function(t){for(let e of o(this,D).floors)o(this,H).updateState(e,{visible:t})},"#setVisible"),s(kt,"Outdoors");var ht=kt;function Ct(r,t){let e=r.find(i=>i.type?.toLowerCase()==="outdoor");if(e)return e;let a=r.find(i=>i.facade==null&&!t.has(i.id));return a||(\$.warn("No good candidate for the outdoor floor stack was found. Using the first floor stack."),r[0])}s(Ct,"getOutdoorFloorStack");var Pt=st("@mappedin/mappedin-js"),Rt={indoorZoomThreshold:18,outdoorZoomThreshold:17,setFloorOnFocus:!0,autoFocus:!1,indoorAnimationOptions:{duration:150},outdoorAnimationOptions:{duration:150},autoAdjustFacadeHeights:!1,mode:"default-floor",preloadFloors:!0,customMultiFloorVisibilityState:Pt.getMultiFloorState,dynamicBuildingInteriors:!0};var v,n,B,d,_,N,h,M,I,L,A,q,T,V,W,x,g,Dt,Tt,ot,et,it,at,K,At,jt,Gt,Z,wt=class wt{constructor(t){u(this,g);u(this,v);u(this,n);u(this,B);u(this,d,Rt);u(this,_,[]);u(this,N,new Set);u(this,h,new Map);u(this,M);u(this,I,!1);u(this,L,!1);u(this,A,0);u(this,q,0);u(this,T,"transition");u(this,V,"outdoor");u(this,W,[]);u(this,x,!1);m(this,"sceneUpdateQueue",Promise.resolve());m(this,"on",s((t,e)=>{o(this,v).on(t,e)},"on"));m(this,"off",s((t,e)=>{o(this,v).off(t,e)},"off"));u(this,ot,s(t=>{if(!this.isEnabled)return;let{facades:e}=t;if(!(Vt(e,this.focusedFacades)&&o(this,V)==="transition"&&!o(this,L))){if(l(this,L,!1),l(this,_,[]),o(this,N).clear(),e.length>0)for(let a of e){let i=o(this,h).get(a.floorStack.id);i&&(o(this,N).add(i.id),o(this,_).push(i))}o(this,d).autoFocus&&this.focus()}},"#handleFacadesInViewChange"));u(this,et,s(async t=>{if(!this.isEnabled)return;let{floor:e}=t,a=o(this,h).get(e.floorStack.id);if(a&&(a.activeFloor=e),a?.excluded===!1&&!o(this,M).matchesFloorStack(e.floorStack)&&l(this,A,e.elevation),o(this,n).manualFloorVisibility===!0){t.reason!=="dynamic-focus"&&(await o(this,Z).call(this,e),o(this,v).publish("focus",{facades:this.focusedFacades}));let i=a?.floorsAltitudesMap.get(e.elevation)?.altitude??0;o(this,n).options.multiFloorView!=null&&o(this,n).options.multiFloorView?.enabled&&o(this,n).options.multiFloorView?.updateCameraElevationOnFloorChange&&o(this,n).Camera.elevation!==i&&o(this,n).Camera.animateElevation(i,{duration:750,easing:"ease-in-out"})}},"#handleFloorChangeStart"));u(this,it,s(()=>{l(this,I,!0)},"#handleUserInteractionStart"));u(this,at,s(()=>{l(this,I,!1)},"#handleUserInteractionEnd"));u(this,K,s(t=>{if(!this.isEnabled)return;let{zoomLevel:e}=t,a=xt(e,o(this,d).indoorZoomThreshold,o(this,d).outdoorZoomThreshold);o(this,T)!==a&&(l(this,T,a),a==="in-range"?this.setIndoor():a==="out-of-range"&&this.setOutdoor())},"#handleCameraChange"));u(this,Z,s(async t=>{if(o(this,n).manualFloorVisibility!==!0||!this.isEnabled)return;let e=t||o(this,n).currentFloor,a=o(this,n).options.multiFloorView,i=o(this,n).Navigation?.floors?.map(p=>p.id)||[],c=o(this,n).Navigation?.floorStacks.map(p=>p.id)||[],y=new Promise(async p=>{await this.sceneUpdateQueue;let z=_t(Array.from(o(this,h).values()),o(this,N),e,o(this,T),o(this,d).mode,o(this,A),i,c,a,o(this,d).customMultiFloorVisibilityState??mt.getMultiFloorState,o(this,d).dynamicBuildingInteriors),rt=[];await Promise.all(Array.from(z.values()).map(async O=>{let{building:C,showIndoor:f,floorStackState:P,facadeState:R,inFocus:Q}=O;rt.push(P);let nt=Nt(C,f);if(nt==="indoor")return b(this,g,jt).call(this,C,P,R,Q);if(nt==="outdoor")return b(this,g,Gt).call(this,C,P,R,c)})),o(this,n).Outdoor.setOpacity(Ot(rt,o(this,d).mode)),l(this,W,o(this,_).filter(O=>z.get(O.id)?.showIndoor===!0).map(O=>O.facade)),o(this,v).publish("focus",{facades:o(this,W)}),p()});return this.sceneUpdateQueue=y,y},"#applyBuildingStates"));l(this,v,new lt),l(this,n,t),\$.setLevel(U.logState),l(this,B,o(this,n).getMapData()),l(this,A,o(this,n).currentFloor.elevation),l(this,q,o(this,n).Camera.elevation);for(let e of o(this,B).getByType("facade"))o(this,h).set(e.floorStack.id,new ut(e.floorStack,o(this,n)));l(this,M,new ht(Ct(o(this,B).getByType("floor-stack"),o(this,h)),o(this,n))),o(this,n).on("floor-change-start",o(this,et)),o(this,n).on("camera-change",o(this,K)),o(this,n).on("facades-in-view-change",o(this,ot)),o(this,n).on("user-interaction-start",o(this,it)),o(this,n).on("user-interaction-end",o(this,at))}enable(t){if(o(this,x)){\$.warn("enable() called on an already enabled Dynamic Focus instance.");return}l(this,x,!0),o(this,n).manualFloorVisibility=!0,o(this,M).show(),this.updateState({...o(this,d),...t}),o(this,K).call(this,{zoomLevel:o(this,n).Camera.zoomLevel,center:o(this,n).Camera.center,bearing:o(this,n).Camera.bearing,pitch:o(this,n).Camera.pitch}),o(this,n).Camera.updateFacadesInView()}disable(){if(!o(this,x)){\$.warn("disable() called on an already disabled Dynamic Focus instance.");return}l(this,x,!1),o(this,n).manualFloorVisibility=!1}get isEnabled(){return o(this,x)}get isIndoor(){return o(this,V)==="indoor"}get isOutdoor(){return o(this,V)==="outdoor"}setIndoor(){l(this,V,"indoor"),l(this,T,"in-range"),b(this,g,Dt).call(this)}setOutdoor(){l(this,V,"outdoor"),l(this,T,"out-of-range"),b(this,g,Dt).call(this)}get focusedFacades(){return[...o(this,W)]}getState(){return{...o(this,d)}}updateState(t){let e=!1;t.indoorZoomThreshold!=null&&(t.indoorZoomThreshold=Et(t.indoorZoomThreshold,t?.outdoorZoomThreshold??o(this,d).outdoorZoomThreshold,o(this,n).Camera.maxZoomLevel,"indoorZoomThreshold"),e=!0),t.outdoorZoomThreshold!=null&&(t.outdoorZoomThreshold=Et(t.outdoorZoomThreshold,o(this,n).Camera.minZoomLevel,t?.indoorZoomThreshold??o(this,d).indoorZoomThreshold,"outdoorZoomThreshold"),e=!0),t.mode!=null&&(t.mode=Lt.includes(t.mode)?t.mode:"default-floor"),t.autoAdjustFacadeHeights!=null&&(o(this,d).autoAdjustFacadeHeights=t.autoAdjustFacadeHeights),t.dynamicBuildingInteriors!=null&&t.dynamicBuildingInteriors!==o(this,d).dynamicBuildingInteriors&&(e=!0),l(this,d,Object.assign({},o(this,d),Object.fromEntries(Object.entries(t).filter(([,a])=>a!=null)))),t.mode!=null&&t.preloadFloors&&b(this,g,Tt).call(this,t.mode),e&&o(this,Z).call(this)}destroy(){this.disable(),o(this,n).off("facades-in-view-change",o(this,ot)),o(this,n).off("floor-change-start",o(this,et)),o(this,n).off("camera-change",o(this,K)),o(this,n).off("user-interaction-start",o(this,it)),o(this,n).off("user-interaction-end",o(this,at)),o(this,h).forEach(t=>t.destroy()),o(this,M).destroy(),o(this,v).destroy()}async focus(t=o(this,d).setFloorOnFocus){if(t)if(It(o(this,q),o(this,n).Camera.elevation,o(this,I)))l(this,q,o(this,n).Camera.elevation),l(this,L,!0);else{let e=Bt(o(this,_),o(this,M),o(this,T)),a=e?dt(e,o(this,d).mode,o(this,A)):void 0;a&&a.id!==o(this,n).currentFloor.id&&o(this,n).setFloor(a,{context:"dynamic-focus"})}await o(this,Z).call(this),o(this,v).publish("focus",{facades:this.focusedFacades})}preloadFloors(){b(this,g,Tt).call(this,o(this,d).mode)}setDefaultFloorForStack(t,e){if(!bt(e,t))return;let a=o(this,h).get(t.id);a&&(a.defaultFloor=e)}resetDefaultFloorForStack(t){let e=o(this,h).get(t.id);e&&(e.defaultFloor=t.defaultFloor)}getDefaultFloorForStack(t){return o(this,h).get(t.id)?.defaultFloor||t.defaultFloor||t.floors[0]}setCurrentFloorForStack(t,e){if(!bt(e,t))return;let a=o(this,h).get(t.id);a&&(a.activeFloor=e,o(this,Z).call(this))}exclude(t){let e=Array.isArray(t)?t:[t];for(let a of e){let i=o(this,h).get(a.id);i&&(i.excluded=!0)}}include(t){let e=Array.isArray(t)?t:[t];for(let a of e){let i=o(this,h).get(a.id);i&&(i.excluded=!1)}}getCurrentFloorForStack(t){return o(this,h).get(t.id)?.activeFloor||this.getDefaultFloorForStack(t)}};v=new WeakMap,n=new WeakMap,B=new WeakMap,d=new WeakMap,_=new WeakMap,N=new WeakMap,h=new WeakMap,M=new WeakMap,I=new WeakMap,L=new WeakMap,A=new WeakMap,q=new WeakMap,T=new WeakMap,V=new WeakMap,W=new WeakMap,x=new WeakMap,g=new WeakSet,Dt=s(function(){o(this,d).autoFocus&&(o(this,I)?this.focus():l(this,L,!0)),o(this,v).publish("state-change")},"#handleViewStateChange"),Tt=s(function(t){o(this,n).preloadFloors(o(this,B).getByType("facade").map(e=>dt(o(this,h).get(e.floorStack.id),t,o(this,A))).filter(e=>e!=null&&mt.Floor.is(e)))},"#preloadFloors"),ot=new WeakMap,et=new WeakMap,it=new WeakMap,at=new WeakMap,K=new WeakMap,At=s(function(t,e,a){t.forEach(i=>{if(i.floor)if(e){let c=a!==void 0?{...i.state,labels:{...i.state.labels,enabled:i.state.labels.enabled&&a},markers:{...i.state.markers,enabled:i.state.markers.enabled&&a},occlusion:{...i.state.occlusion,enabled:i.state.occlusion.enabled&&a}}:i.state;o(this,n).updateState(i.floor,c)}else o(this,n).updateState(i.floor,{visible:!1})})},"#updateFloorVisibility"),jt=s(async function(t,e,a,i){return b(this,g,At).call(this,e.floorStates,!0,i),t.animateFacade(a.state,o(this,d).indoorAnimationOptions)},"#animateIndoorSequence"),Gt=s(async function(t,e,a,i){let c=await t.animateFacade(a.state,o(this,d).outdoorAnimationOptions);return c.result==="completed"&&b(this,g,At).call(this,e.floorStates,yt(t,o(this,n).currentFloor,o(this,T)==="in-range",o(this,N).has(t.id),o(this,d).mode,o(this,A),i.includes(t.floorStack.id),o(this,d).dynamicBuildingInteriors)),c},"#animateOutdoorSequence"),Z=new WeakMap,s(wt,"DynamicFocus");var ft=wt;return zt(oo);})();
105
- //# sourceMappingURL=dynamic-focus.iife.js.map
11
+ "use strict";var DynamicFocus=(()=>{var J=Object.defineProperty;var Ut=Object.getOwnPropertyDescriptor;var $t=Object.getOwnPropertyNames;var Ht=Object.prototype.hasOwnProperty;var Mt=r=>{throw TypeError(r)};var qt=(r,t,e)=>t in r?J(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var s=(r,t)=>J(r,"name",{value:t,configurable:!0}),st=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var Wt=(r,t)=>{for(var e in t)J(r,e,{get:t[e],enumerable:!0})},Kt=(r,t,e,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of $t(t))!Ht.call(r,i)&&i!==e&&J(r,i,{get:()=>t[i],enumerable:!(a=Ut(t,i))||a.enumerable});return r};var zt=r=>Kt(J({},"__esModule",{value:!0}),r);var m=(r,t,e)=>qt(r,typeof t!="symbol"?t+"":t,e),pt=(r,t,e)=>t.has(r)||Mt("Cannot "+e);var o=(r,t,e)=>(pt(r,t,"read from private field"),e?e.call(r):t.get(r)),u=(r,t,e)=>t.has(r)?Mt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(r):t.set(r,e),l=(r,t,e,a)=>(pt(r,t,"write to private field"),a?a.call(r,e):t.set(r,e),e),b=(r,t,e)=>(pt(r,t,"access private method"),e);var oo={};Wt(oo,{DynamicFocus:()=>ft});var mt=st("@mappedin/mappedin-js");function Vt(r,t){if(r==null||t==null)return r===t;if(r.length!==t.length)return!1;for(let e=0;e<r.length;e++)if(r[e]!==t[e])return!1;return!0}s(Vt,"arraysEqual");var Ft=class Ft{constructor(){m(this,"_subscribers",{});m(this,"_destroyed",!1)}publish(t,e){!this._subscribers||!this._subscribers[t]||this._destroyed||this._subscribers[t].forEach(function(a){typeof a=="function"&&a(e)})}on(t,e){(!this._subscribers||this._destroyed)&&(this._subscribers={}),this._subscribers[t]=this._subscribers[t]||[],this._subscribers[t].push(e)}off(t,e){if(!this._subscribers||this._subscribers[t]==null||this._destroyed)return;let a=this._subscribers[t].indexOf(e);a!==-1&&this._subscribers[t].splice(a,1)}destroy(){this._destroyed=!0,this._subscribers={}}};s(Ft,"PubSub");var lt=Ft;var Y=st("@mappedin/mappedin-js");var E,X,w,S,F,k,G,j,gt=class gt{constructor(t,e){m(this,"__type","building");u(this,E);u(this,X,new Map);u(this,w,new Map);u(this,S,[]);u(this,F);u(this,k);m(this,"defaultFloor");m(this,"activeFloor");m(this,"excluded",!1);m(this,"floorsAltitudesMap",new Map);m(this,"aboveGroundFloors",[]);u(this,G);u(this,j);l(this,E,t),l(this,X,new Map(t.floors.map(i=>[i.id,i]))),l(this,w,new Map(t.floors.map(i=>[i.elevation,i]))),l(this,S,Array.from(o(this,w).values()).sort((i,c)=>i.elevation-c.elevation)),this.defaultFloor=t.defaultFloor,this.activeFloor=this.defaultFloor,l(this,F,e),this.aboveGroundFloors=o(this,S).filter(i=>i.elevation>=0);let a=t.facade?.spaces.map(i=>o(this,F).getState(i)).sort((i,c)=>i.altitude-c.altitude);if(a&&a.length===this.aboveGroundFloors.length)for(let i in this.aboveGroundFloors){let c=this.aboveGroundFloors[i],y=a[i];this.floorsAltitudesMap.set(c.elevation,{altitude:y.altitude,effectiveHeight:y.height})}}get id(){return o(this,E).id}get name(){return o(this,E).name}get floors(){return o(this,E).floors}get floorStack(){return o(this,E)}get facade(){return o(this,E).facade}get isCurrentFloorStack(){return this.id===o(this,F).currentFloorStack.id}get isIndoor(){let t=o(this,F).getState(this.facade);return this.isCurrentFloorStack||t?.visible===!1&&t?.opacity===0}get canSetFloor(){return this.isIndoor||!this.excluded}get maxElevation(){return o(this,G)==null&&l(this,G,Math.max(...o(this,w).keys())),o(this,G)}get minElevation(){return o(this,j)==null&&l(this,j,Math.min(...o(this,w).keys())),o(this,j)}has(t){return Y.Floor.is(t)?o(this,X).has(t.id):Y.FloorStack.is(t)?t.id===o(this,E).id:Y.Facade.is(t)?t.id===this.facade.id:!1}getFloorByElevation(t){return o(this,w).get(t)}getNearestFloorByElevation(t){let e=this.getFloorByElevation(t);if(e)return e;if(t>=0){if(t>this.maxElevation)return o(this,S)[o(this,S).length-1];for(let a=o(this,S).length-1;a>=0;a--){let i=o(this,S)[a];if(i.elevation<=t)return i}}else{if(t<this.minElevation)return o(this,S)[0];for(let a of o(this,S))if(a.elevation>=t)return a}}getHighestFloor(){return o(this,S)[o(this,S).length-1]}cancelAnimation(){o(this,k)&&(o(this,k).animation.cancel(),l(this,k,void 0))}async animateFacade(t,e={duration:150}){let a=o(this,k)?.state||o(this,F).getState(this.facade);if(!a||!t||a?.opacity===t.opacity&&a?.visible===t.visible)return{result:"completed"};this.cancelAnimation();let{opacity:i,visible:c}=t;if(o(this,F).updateState(this.facade,{visible:!0}),i!==void 0){l(this,k,{animation:o(this,F).animateState(this.facade,{opacity:i},{duration:e.duration}),state:t});let y=await o(this,k).animation;if(l(this,k,void 0),y.result==="cancelled")return y}return c===!1&&o(this,F).updateState(this.facade,{visible:c}),{result:"completed"}}destroy(){this.cancelAnimation(),o(this,E).floors.forEach(t=>{o(this,F).updateState(t,{visible:t.id===o(this,F).currentFloor.id})}),this.has(o(this,F).currentFloor)||o(this,F).updateState(this.facade,{visible:!0,opacity:1})}};E=new WeakMap,X=new WeakMap,w=new WeakMap,S=new WeakMap,F=new WeakMap,k=new WeakMap,G=new WeakMap,j=new WeakMap,s(gt,"Building");var ut=gt;function xt(r,t,e){return r>=t?"in-range":r<=e?"out-of-range":"transition"}s(xt,"getZoomState");function dt(r,t,e){if(r.__type==="outdoors"&&"floor"in r)return r.floor;let a=r;if(a.excluded)return a.activeFloor;switch(t){case"lock-elevation":return a.getFloorByElevation(e);case"nearest-elevation":return a.getNearestFloorByElevation(e);default:break}return a.isIndoor?a.activeFloor:a.defaultFloor}s(dt,"getFloorToShow");function Qt(r,t){return{facade:r,state:{type:"facade",visible:!t,opacity:t?0:1}}}s(Qt,"getFacadeState");function Jt(r,t,e){return{outdoorOpacity:"initial",floorStates:r.floors.map(a=>{let i=a.id===t.id&&e;return{floor:a,state:{type:"floor",visible:i,geometry:{visible:i},labels:{enabled:i},markers:{enabled:i},footprint:{visible:!1},occlusion:{enabled:!1}}}})}}s(Jt,"getSingleBuildingState");function Ot(r,t){if(!t.includes("lock-elevation"))return"initial";for(let e of r)if(typeof e.outdoorOpacity=="number"&&e.outdoorOpacity>=0&&e.outdoorOpacity<=1)return e.outdoorOpacity;return"initial"}s(Ot,"getOutdoorOpacity");function Bt(r,t,e){switch(e){case"in-range":return r[0]?.canSetFloor?r[0]:void 0;case"out-of-range":return t;case"transition":default:return}}s(Bt,"getSetFloorTargetFromZoomState");function _t(r,t,e,a,i,c,y,p,z,rt,O){let C=new Map;for(let f of r){let P=t.has(f.id),R=yt(f,e,a==="in-range",P,i,c,p.includes(f.id),O),Q=e.floorStack.id===f.id?f.activeFloor:dt(f,i,c),nt=z.enabled?rt(f.floors,Q||f.activeFloor,z?.floorGap,y,f.floorsAltitudesMap):Jt(f.floorStack,Q||f.activeFloor,R),Yt=Qt(f.facade,R);C.set(f.id,{building:f,showIndoor:R,floorStackState:nt,facadeState:Yt,inFocus:P,floorToShow:Q})}return C}s(_t,"getBuildingStates");function Nt(r,t){return r.excluded?"none":t?"indoor":"outdoor"}s(Nt,"getBuildingAnimationType");function yt(r,t,e,a,i,c,y,p){if(r.id===t.floorStack.id)return!0;if(r.excluded)return!1;if(y===!0)return!0;if(!p)return t.floorStack.type!=="Outdoor";if(!e||!a)return!1;switch(i){case"lock-elevation":return r.getFloorByElevation(c)!=null;default:break}return!0}s(yt,"shouldShowIndoor");function It(r,t,e){return r!==t&&!e}s(It,"shouldDeferSetFloor");var Lt=["default-floor","lock-elevation","nearest-elevation"];var ct=st("@mappedin/mappedin-js");var Xt="[MappedinJS]";function St(r="",{prefix:t=Xt}={}){let e=\`\${t}\${r?\`-\${r}\`:""}\`,a=s((i,c)=>{if(typeof window<"u"&&window.rnDebug){let y=c.map(p=>p instanceof Error&&p.stack?\`\${p.message}
12
+ \${p.stack}\`:p);window.rnDebug(\`\${r} \${i}: \${y.join(" ")}\`)}},"rnDebug");return{logState:0,log(...i){this.logState<=0&&(console.log(e,...i),a("log",i))},warn(...i){this.logState<=1&&(console.warn(e,...i),a("warn",i))},error(...i){this.logState<=2&&(console.error(e,...i),a("error",i))},assert(...i){console.assert(...i)},time(i){console.time(i)},timeEnd(i){console.timeEnd(i)},setLevel(i){0<=i&&i<=3&&(this.logState=i)}}}s(St,"createLogger");var to=St();var U=to;function Zt(r,t,e,a){return(r<t||r>e)&&U.warn(a),Math.min(e,Math.max(t,r))}s(Zt,"clampWithWarning");function bt(r,t){return!ct.Floor.is(r)||r?.floorStack==null||!ct.FloorStack.is(t)?!1:r.floorStack.id!==t.id?(U.warn(\`Floor (\${r.id}) does not belong to floor stack (\${t.id}).\`),!1):!0}s(bt,"validateFloorForStack");function Et(r,t,e,a){return Zt(r,t,e,\`\${a} must be between \${t} and \${e}.\`)}s(Et,"validateZoomThreshold");var $=St("",{prefix:"[DynamicFocus]"});var D,H,tt,vt,kt=class kt{constructor(t,e){u(this,tt);m(this,"__type","outdoors");u(this,D);u(this,H);l(this,D,t),l(this,H,e)}get id(){return o(this,D).id}get floorStack(){return o(this,D)}get floor(){return o(this,D).defaultFloor}matchesFloorStack(t){return t===o(this,D)||t===o(this,D).id}show(){b(this,tt,vt).call(this,!0)}hide(){b(this,tt,vt).call(this,!1)}destroy(){this.matchesFloorStack(o(this,H).currentFloorStack)||this.hide()}};D=new WeakMap,H=new WeakMap,tt=new WeakSet,vt=s(function(t){for(let e of o(this,D).floors)o(this,H).updateState(e,{visible:t})},"#setVisible"),s(kt,"Outdoors");var ht=kt;function Ct(r,t){let e=r.find(i=>i.type?.toLowerCase()==="outdoor");if(e)return e;let a=r.find(i=>i.facade==null&&!t.has(i.id));return a||($.warn("No good candidate for the outdoor floor stack was found. Using the first floor stack."),r[0])}s(Ct,"getOutdoorFloorStack");var Pt=st("@mappedin/mappedin-js"),Rt={indoorZoomThreshold:18,outdoorZoomThreshold:17,setFloorOnFocus:!0,autoFocus:!1,indoorAnimationOptions:{duration:150},outdoorAnimationOptions:{duration:150},autoAdjustFacadeHeights:!1,mode:"default-floor",preloadFloors:!0,customMultiFloorVisibilityState:Pt.getMultiFloorState,dynamicBuildingInteriors:!0};var v,n,B,d,_,N,h,M,I,L,A,q,T,V,W,x,g,Dt,Tt,ot,et,it,at,K,At,Gt,jt,Z,wt=class wt{constructor(t){u(this,g);u(this,v);u(this,n);u(this,B);u(this,d,Rt);u(this,_,[]);u(this,N,new Set);u(this,h,new Map);u(this,M);u(this,I,!1);u(this,L,!1);u(this,A,0);u(this,q,0);u(this,T,"transition");u(this,V,"outdoor");u(this,W,[]);u(this,x,!1);m(this,"sceneUpdateQueue",Promise.resolve());m(this,"on",s((t,e)=>{o(this,v).on(t,e)},"on"));m(this,"off",s((t,e)=>{o(this,v).off(t,e)},"off"));u(this,ot,s(t=>{if(!this.isEnabled)return;let{facades:e}=t;if(!(Vt(e,this.focusedFacades)&&o(this,V)==="transition"&&!o(this,L))){if(l(this,L,!1),l(this,_,[]),o(this,N).clear(),e.length>0)for(let a of e){let i=o(this,h).get(a.floorStack.id);i&&(o(this,N).add(i.id),o(this,_).push(i))}o(this,d).autoFocus&&this.focus()}},"#handleFacadesInViewChange"));u(this,et,s(async t=>{if(!this.isEnabled)return;let{floor:e}=t,a=o(this,h).get(e.floorStack.id);if(a&&(a.activeFloor=e),a?.excluded===!1&&!o(this,M).matchesFloorStack(e.floorStack)&&l(this,A,e.elevation),o(this,n).manualFloorVisibility===!0){t.reason!=="dynamic-focus"&&(await o(this,Z).call(this,e),o(this,v).publish("focus",{facades:this.focusedFacades}));let i=a?.floorsAltitudesMap.get(e.elevation)?.altitude??0;o(this,n).options.multiFloorView!=null&&o(this,n).options.multiFloorView?.enabled&&o(this,n).options.multiFloorView?.updateCameraElevationOnFloorChange&&o(this,n).Camera.elevation!==i&&o(this,n).Camera.animateElevation(i,{duration:750,easing:"ease-in-out"})}},"#handleFloorChangeStart"));u(this,it,s(()=>{l(this,I,!0)},"#handleUserInteractionStart"));u(this,at,s(()=>{l(this,I,!1)},"#handleUserInteractionEnd"));u(this,K,s(t=>{if(!this.isEnabled)return;let{zoomLevel:e}=t,a=xt(e,o(this,d).indoorZoomThreshold,o(this,d).outdoorZoomThreshold);o(this,T)!==a&&(l(this,T,a),a==="in-range"?this.setIndoor():a==="out-of-range"&&this.setOutdoor())},"#handleCameraChange"));u(this,Z,s(async t=>{if(o(this,n).manualFloorVisibility!==!0||!this.isEnabled)return;let e=t||o(this,n).currentFloor,a=o(this,n).options.multiFloorView,i=o(this,n).Navigation?.floors?.map(p=>p.id)||[],c=o(this,n).Navigation?.floorStacks.map(p=>p.id)||[],y=new Promise(async p=>{await this.sceneUpdateQueue;let z=_t(Array.from(o(this,h).values()),o(this,N),e,o(this,T),o(this,d).mode,o(this,A),i,c,a,o(this,d).customMultiFloorVisibilityState??mt.getMultiFloorState,o(this,d).dynamicBuildingInteriors),rt=[];await Promise.all(Array.from(z.values()).map(async O=>{let{building:C,showIndoor:f,floorStackState:P,facadeState:R,inFocus:Q}=O;rt.push(P);let nt=Nt(C,f);if(nt==="indoor")return b(this,g,Gt).call(this,C,P,R,Q);if(nt==="outdoor")return b(this,g,jt).call(this,C,P,R,c)})),o(this,n).Outdoor.setOpacity(Ot(rt,o(this,d).mode)),l(this,W,o(this,_).filter(O=>z.get(O.id)?.showIndoor===!0).map(O=>O.facade)),o(this,v).publish("focus",{facades:o(this,W)}),p()});return this.sceneUpdateQueue=y,y},"#applyBuildingStates"));l(this,v,new lt),l(this,n,t),$.setLevel(U.logState),l(this,B,o(this,n).getMapData()),l(this,A,o(this,n).currentFloor.elevation),l(this,q,o(this,n).Camera.elevation);for(let e of o(this,B).getByType("facade"))o(this,h).set(e.floorStack.id,new ut(e.floorStack,o(this,n)));l(this,M,new ht(Ct(o(this,B).getByType("floor-stack"),o(this,h)),o(this,n))),o(this,n).on("floor-change-start",o(this,et)),o(this,n).on("camera-change",o(this,K)),o(this,n).on("facades-in-view-change",o(this,ot)),o(this,n).on("user-interaction-start",o(this,it)),o(this,n).on("user-interaction-end",o(this,at))}enable(t){if(o(this,x)){$.warn("enable() called on an already enabled Dynamic Focus instance.");return}l(this,x,!0),o(this,n).manualFloorVisibility=!0,o(this,M).show(),this.updateState({...o(this,d),...t}),o(this,K).call(this,{zoomLevel:o(this,n).Camera.zoomLevel,center:o(this,n).Camera.center,bearing:o(this,n).Camera.bearing,pitch:o(this,n).Camera.pitch}),o(this,n).Camera.updateFacadesInView()}disable(){if(!o(this,x)){$.warn("disable() called on an already disabled Dynamic Focus instance.");return}l(this,x,!1),o(this,n).manualFloorVisibility=!1}get isEnabled(){return o(this,x)}get isIndoor(){return o(this,V)==="indoor"}get isOutdoor(){return o(this,V)==="outdoor"}setIndoor(){l(this,V,"indoor"),l(this,T,"in-range"),b(this,g,Dt).call(this)}setOutdoor(){l(this,V,"outdoor"),l(this,T,"out-of-range"),b(this,g,Dt).call(this)}get focusedFacades(){return[...o(this,W)]}getState(){return{...o(this,d)}}updateState(t){let e=!1;t.indoorZoomThreshold!=null&&(t.indoorZoomThreshold=Et(t.indoorZoomThreshold,t?.outdoorZoomThreshold??o(this,d).outdoorZoomThreshold,o(this,n).Camera.maxZoomLevel,"indoorZoomThreshold"),e=!0),t.outdoorZoomThreshold!=null&&(t.outdoorZoomThreshold=Et(t.outdoorZoomThreshold,o(this,n).Camera.minZoomLevel,t?.indoorZoomThreshold??o(this,d).indoorZoomThreshold,"outdoorZoomThreshold"),e=!0),t.mode!=null&&(t.mode=Lt.includes(t.mode)?t.mode:"default-floor"),t.autoAdjustFacadeHeights!=null&&(o(this,d).autoAdjustFacadeHeights=t.autoAdjustFacadeHeights),t.dynamicBuildingInteriors!=null&&t.dynamicBuildingInteriors!==o(this,d).dynamicBuildingInteriors&&(e=!0),l(this,d,Object.assign({},o(this,d),Object.fromEntries(Object.entries(t).filter(([,a])=>a!=null)))),t.mode!=null&&t.preloadFloors&&b(this,g,Tt).call(this,t.mode),e&&o(this,Z).call(this)}destroy(){this.disable(),o(this,n).off("facades-in-view-change",o(this,ot)),o(this,n).off("floor-change-start",o(this,et)),o(this,n).off("camera-change",o(this,K)),o(this,n).off("user-interaction-start",o(this,it)),o(this,n).off("user-interaction-end",o(this,at)),o(this,h).forEach(t=>t.destroy()),o(this,M).destroy(),o(this,v).destroy()}async focus(t=o(this,d).setFloorOnFocus){if(t)if(It(o(this,q),o(this,n).Camera.elevation,o(this,I)))l(this,q,o(this,n).Camera.elevation),l(this,L,!0);else{let e=Bt(o(this,_),o(this,M),o(this,T)),a=e?dt(e,o(this,d).mode,o(this,A)):void 0;a&&a.id!==o(this,n).currentFloor.id&&o(this,n).setFloor(a,{context:"dynamic-focus"})}await o(this,Z).call(this),o(this,v).publish("focus",{facades:this.focusedFacades})}preloadFloors(){b(this,g,Tt).call(this,o(this,d).mode)}setDefaultFloorForStack(t,e){if(!bt(e,t))return;let a=o(this,h).get(t.id);a&&(a.defaultFloor=e)}resetDefaultFloorForStack(t){let e=o(this,h).get(t.id);e&&(e.defaultFloor=t.defaultFloor)}getDefaultFloorForStack(t){return o(this,h).get(t.id)?.defaultFloor||t.defaultFloor||t.floors[0]}setCurrentFloorForStack(t,e){if(!bt(e,t))return;let a=o(this,h).get(t.id);a&&(a.activeFloor=e,o(this,Z).call(this))}exclude(t){let e=Array.isArray(t)?t:[t];for(let a of e){let i=o(this,h).get(a.id);i&&(i.excluded=!0)}}include(t){let e=Array.isArray(t)?t:[t];for(let a of e){let i=o(this,h).get(a.id);i&&(i.excluded=!1)}}getCurrentFloorForStack(t){return o(this,h).get(t.id)?.activeFloor||this.getDefaultFloorForStack(t)}};v=new WeakMap,n=new WeakMap,B=new WeakMap,d=new WeakMap,_=new WeakMap,N=new WeakMap,h=new WeakMap,M=new WeakMap,I=new WeakMap,L=new WeakMap,A=new WeakMap,q=new WeakMap,T=new WeakMap,V=new WeakMap,W=new WeakMap,x=new WeakMap,g=new WeakSet,Dt=s(function(){o(this,d).autoFocus&&(o(this,I)?this.focus():l(this,L,!0)),o(this,v).publish("state-change")},"#handleViewStateChange"),Tt=s(function(t){o(this,n).preloadFloors(o(this,B).getByType("facade").map(e=>dt(o(this,h).get(e.floorStack.id),t,o(this,A))).filter(e=>e!=null&&mt.Floor.is(e)))},"#preloadFloors"),ot=new WeakMap,et=new WeakMap,it=new WeakMap,at=new WeakMap,K=new WeakMap,At=s(function(t,e,a){t.forEach(i=>{if(i.floor)if(e){let c=a!==void 0?{...i.state,labels:{...i.state.labels,enabled:i.state.labels.enabled&&a},markers:{...i.state.markers,enabled:i.state.markers.enabled&&a},occlusion:{...i.state.occlusion,enabled:i.state.occlusion.enabled&&a}}:i.state;o(this,n).updateState(i.floor,c)}else o(this,n).updateState(i.floor,{visible:!1})})},"#updateFloorVisibility"),Gt=s(async function(t,e,a,i){return b(this,g,At).call(this,e.floorStates,!0,i),t.animateFacade(a.state,o(this,d).indoorAnimationOptions)},"#animateIndoorSequence"),jt=s(async function(t,e,a,i){let c=await t.animateFacade(a.state,o(this,d).outdoorAnimationOptions);return c.result==="completed"&&b(this,g,At).call(this,e.floorStates,yt(t,o(this,n).currentFloor,o(this,T)==="in-range",o(this,N).has(t.id),o(this,d).mode,o(this,A),i.includes(t.floorStack.id),o(this,d).dynamicBuildingInteriors)),c},"#animateOutdoorSequence"),Z=new WeakMap,s(wt,"DynamicFocus");var ft=wt;return zt(oo);})();
106
13
 
107
14
 
108
15
  // Register the extension
@@ -115,164 +22,4 @@ if (window.bridge && window.bridge.extensions) {
115
22
  }
116
23
  } else {
117
24
  if (window.rnDebug) window.rnDebug('Bridge or extensions not available for registration');
118
- }`;
119
- function getRegistrationScript() {
120
- return EXTENSION_SOURCE_PLACEHOLDER;
121
- }
122
- __name(getRegistrationScript, "getRegistrationScript");
123
-
124
- // src/rn/use-dynamic-focus-registration.ts
125
- function useDynamicFocusRegistration() {
126
- useRegisterExtension({
127
- extensionName: "dynamic-focus",
128
- getRegistrationScript,
129
- logger: Logger2
130
- });
131
- }
132
- __name(useDynamicFocusRegistration, "useDynamicFocusRegistration");
133
-
134
- // src/rn/use-dynamic-focus-events.ts
135
- function useDynamicFocusEvent(event, callback) {
136
- if (typeof event !== "string" || event.length === 0) {
137
- throw new Error("Event parameter must be a non-empty string");
138
- }
139
- if (typeof callback !== "function") {
140
- throw new Error("Callback parameter must be a function");
141
- }
142
- const context = useContext(MappedinContext);
143
- const { extensions, mapData } = context;
144
- if (!mapData) {
145
- throw new Error("Map data is not available");
146
- }
147
- useDynamicFocusRegistration();
148
- const extensionRegistrationState = extensions?.["dynamic-focus"]?.registrationState || "unregistered";
149
- const extensionIsReady = extensionRegistrationState === "registered";
150
- const processedCallback = useCallback(
151
- (payload) => {
152
- try {
153
- let processedPayload = payload;
154
- if (event === "focus" && payload.facades) {
155
- processedPayload = {
156
- ...payload,
157
- facades: hydrateFacades(mapData, payload.facades)
158
- };
159
- }
160
- callback(processedPayload);
161
- } catch (error) {
162
- Logger2.error(`Error in dynamic focus event callback for ${String(event)}:`, error);
163
- }
164
- },
165
- [event, mapData, callback]
166
- );
167
- useEventCallback({
168
- eventKey: `dynamic-focus:${String(event)}`,
169
- callback: processedCallback,
170
- setupScript: /* @__PURE__ */ __name(() => createEventSetupScript({
171
- extensionName: "dynamic-focus",
172
- eventName: String(event)
173
- }), "setupScript"),
174
- cleanupScript: /* @__PURE__ */ __name(() => createEventCleanupScript({
175
- extensionName: "dynamic-focus",
176
- eventName: String(event)
177
- }), "cleanupScript"),
178
- shouldInject: extensionIsReady
179
- });
180
- }
181
- __name(useDynamicFocusEvent, "useDynamicFocusEvent");
182
-
183
- // src/rn/use-dynamic-focus.ts
184
- function useDynamicFocus() {
185
- const context = useContext2(MappedinContext2);
186
- const { bridge, extensions, updateExtensionState } = context;
187
- useDynamicFocusRegistration();
188
- const extensionState = extensions["dynamic-focus"];
189
- const registrationState = extensionState?.registrationState || "unregistered";
190
- const isReady = registrationState === "registered";
191
- const isEnabled = extensionState?.isEnabled || false;
192
- const [focusedFacades, setFocusedFacades] = useState(extensionState?.focusedFacades || []);
193
- const extensionsRef = useRef(extensions);
194
- extensionsRef.current = extensions;
195
- useDynamicFocusEvent(
196
- "focus",
197
- useCallback2(
198
- (event) => {
199
- const newFocusedFacades = event.facades;
200
- setFocusedFacades(newFocusedFacades);
201
- updateExtensionState("dynamic-focus", (prev) => ({
202
- ...prev,
203
- registrationState,
204
- focusedFacades: newFocusedFacades
205
- }));
206
- },
207
- [registrationState, updateExtensionState]
208
- )
209
- );
210
- const callExtensionMethod = useCallback2(
211
- async (method, args = []) => {
212
- if (!bridge?.isReady) {
213
- throw new Error("Bridge is not ready. Ensure the WebView is loaded.");
214
- }
215
- return await bridge.instruct({
216
- type: "extension",
217
- payload: {
218
- name: "dynamic-focus",
219
- method,
220
- args
221
- }
222
- });
223
- },
224
- [bridge]
225
- );
226
- const enable = useCallback2(
227
- async (options) => {
228
- const currentExtensionState = extensionsRef.current?.["dynamic-focus"];
229
- const currentIsEnabled = currentExtensionState?.isEnabled || false;
230
- if (currentIsEnabled) {
231
- return;
232
- }
233
- await callExtensionMethod("enable", [options]);
234
- updateExtensionState("dynamic-focus", (prev) => ({ ...prev, isEnabled: true }));
235
- },
236
- [callExtensionMethod, updateExtensionState]
237
- );
238
- const updateState = useCallback2(
239
- async (state) => {
240
- return await callExtensionMethod("updateState", [state]);
241
- },
242
- [callExtensionMethod]
243
- );
244
- const getState = useCallback2(async () => {
245
- return await callExtensionMethod("getState");
246
- }, [callExtensionMethod]);
247
- const focus = useCallback2(
248
- async (setFloor) => {
249
- return await callExtensionMethod("focus", [setFloor]);
250
- },
251
- [callExtensionMethod]
252
- );
253
- const disable = useCallback2(async () => {
254
- await callExtensionMethod("disable");
255
- setFocusedFacades([]);
256
- updateExtensionState("dynamic-focus", {
257
- registrationState: "unregistered",
258
- isEnabled: false,
259
- focusedFacades: []
260
- });
261
- }, [callExtensionMethod, setFocusedFacades, updateExtensionState]);
262
- return {
263
- isReady,
264
- isEnabled,
265
- focusedFacades,
266
- updateState,
267
- getState,
268
- focus,
269
- disable,
270
- enable
271
- };
272
- }
273
- __name(useDynamicFocus, "useDynamicFocus");
274
- export {
275
- useDynamicFocus,
276
- useDynamicFocusEvent
277
- };
278
- //# sourceMappingURL=index-rn.js.map
25
+ }`;function S(){return P}l(S,"getRegistrationScript");function g(){N({extensionName:"dynamic-focus",getRegistrationScript:S,logger:w})}l(g,"useDynamicFocusRegistration");function b(e,i){if(typeof e!="string"||e.length===0)throw new Error("Event parameter must be a non-empty string");if(typeof i!="function")throw new Error("Callback parameter must be a function");const o=Z(j),{extensions:a,mapData:t}=o;if(!t)throw new Error("Map data is not available");g();const f=(a?.["dynamic-focus"]?.registrationState||"unregistered")==="registered",s=B(h=>{try{let u=h;e==="focus"&&h.facades&&(u={...h,facades:v(t,h.facades)}),i(u)}catch(u){w.error(`Error in dynamic focus event callback for ${String(e)}:`,u)}},[e,t,i]);L({eventKey:`dynamic-focus:${String(e)}`,callback:s,setupScript:l(()=>R({extensionName:"dynamic-focus",eventName:String(e)}),"setupScript"),cleanupScript:l(()=>V({extensionName:"dynamic-focus",eventName:String(e)}),"cleanupScript"),shouldInject:f})}l(b,"useDynamicFocusEvent");function k(){const e=T(I),{bridge:i,extensions:o,updateExtensionState:a}=e;g();const t=o["dynamic-focus"],d=t?.registrationState||"unregistered",f=d==="registered",s=t?.isEnabled||!1,[h,u]=_(t?.focusedFacades||[]),y=A(o);y.current=o,b("focus",c(n=>{const p=n.facades;u(p),a("dynamic-focus",F=>({...F,registrationState:d,focusedFacades:p}))},[d,a]));const r=c(async(n,p=[])=>{if(!i?.isReady)throw new Error("Bridge is not ready. Ensure the WebView is loaded.");return await i.instruct({type:"extension",payload:{name:"dynamic-focus",method:n,args:p}})},[i]),E=c(async n=>{y.current?.["dynamic-focus"]?.isEnabled||(await r("enable",[n]),a("dynamic-focus",D=>({...D,isEnabled:!0})))},[r,a]),M=c(async n=>await r("updateState",[n]),[r]),x=c(async()=>await r("getState"),[r]),C=c(async n=>await r("focus",[n]),[r]),O=c(async()=>{await r("disable"),u([]),a("dynamic-focus",{registrationState:"unregistered",isEnabled:!1,focusedFacades:[]})},[r,u,a]);return{isReady:f,isEnabled:s,focusedFacades:h,updateState:M,getState:x,focus:C,disable:O,enable:E}}l(k,"useDynamicFocus");export{k as useDynamicFocus,b as useDynamicFocusEvent};
@@ -1,10 +1,10 @@
1
1
  export declare const Logger: {
2
- logState: import("../../packages/common/Mappedin.Logger").E_SDK_LOG_LEVEL;
2
+ logState: import("@mappedin/mappedin-js").E_SDK_LOG_LEVEL;
3
3
  log(...args: any[]): void;
4
4
  warn(...args: any[]): void;
5
5
  error(...args: any[]): void;
6
6
  assert(...args: any[]): void;
7
7
  time(label: string): void;
8
8
  timeEnd(label: string): void;
9
- setLevel(level: import("../../packages/common/Mappedin.Logger").E_SDK_LOG_LEVEL): void;
9
+ setLevel(level: import("@mappedin/mappedin-js").E_SDK_LOG_LEVEL): void;
10
10
  };
package/lib/rn/types.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import type { Facade, Floor, TFacadeState } from '@mappedin/mappedin-js';
2
- import type { VisibilityState as BuildingFloorStackState } from '../../mappedin-js/src/api-geojson/multi-floor';
1
+ import type { Facade, Floor, TFacadeState, VisibilityState as BuildingFloorStackState } from '@mappedin/mappedin-js';
3
2
  export type MultiFloorVisibilityState = (floors: Floor[], currentFloor: Floor, floorGap: number, floorIdsInNavigation: Floor['id'][], floorsVisualHeightMap?: Map<number, {
4
3
  altitude: number;
5
4
  effectiveHeight: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mappedin/dynamic-focus",
3
- "version": "6.0.1-beta.61",
3
+ "version": "6.5.0-beta.0",
4
4
  "homepage": "https://developer.mappedin.com/",
5
5
  "private": false,
6
6
  "main": "lib/esm/index.js",
@@ -37,9 +37,9 @@
37
37
  "license": "SEE LICENSE IN LICENSE.txt",
38
38
  "peerDependencies": {
39
39
  "react": ">=16.8.0",
40
- "@mappedin/mappedin-js": "^6.1.2",
41
- "@mappedin/react-sdk": "^6.1.2",
42
- "@mappedin/react-native-sdk": "^6.1.2"
40
+ "@mappedin/mappedin-js": "^6.5.0",
41
+ "@mappedin/react-native-sdk": "^6.5.0",
42
+ "@mappedin/react-sdk": "^6.5.0"
43
43
  },
44
44
  "peerDependenciesMeta": {
45
45
  "@mappedin/react-sdk": {
@@ -60,13 +60,15 @@
60
60
  "scripts": {
61
61
  "start": "pnpm build && concurrently \"node scripts/build.mjs --watchChanges\" \"node scripts/start.mjs\"",
62
62
  "build": "pnpm clean && tsc -b && node scripts/build.mjs",
63
- "build:prod": "cross-env NODE_ENV=production pnpm build && pnpm build:rn",
63
+ "build:prod": "cross-env NODE_ENV=production RN_BUILD=true pnpm build",
64
64
  "build:rn": "cross-env RN_BUILD=true pnpm build",
65
+ "build:examples": "node ../scripts/build-examples.mjs dynamic-focus",
65
66
  "types": "tsc -b",
66
67
  "test": "pnpm -w test dynamic-focus",
67
68
  "test:cov": "NODE_ENV=test jest --coverage",
68
69
  "version:ci": "pnpm version --no-commit-hooks --no-git-tag-version",
69
70
  "clean": "rm -rf lib/** && rm -rf examples/dist/**",
70
- "docs": "pnpm build && typedoc"
71
+ "docs": "pnpm build && pnpm docs:build",
72
+ "docs:build": "typedoc"
71
73
  }
72
74
  }