@expofp/floorplan
Version:
Interactive floor plan library for expos and events
153 lines (152 loc) • 5.54 kB
JavaScript
(function() {
try {
var e = typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : {};
e.SENTRY_RELEASE = { id: "3.20.0" };
var t = new e.Error().stack;
t && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[t] = "b125e7f8-7616-41a1-a0be-f02f5877279e", e._sentryDebugIdIdentifier = "sentry-dbid-b125e7f8-7616-41a1-a0be-f02f5877279e");
} catch {}
})();
import { r as e } from "./rolldown-runtime-7-Wh3Cc7.js";
import { K as t, s as n } from "./i18n-B6dEf7vu.js";
import { t as r } from "./react-lDheuaid.js";
import { t as i } from "./jsx-runtime-BRhWrtmW.js";
import { r as a } from "./loadImage-DidrxJwE.js";
import { t as o } from "./index.module-CkZa7zY4.js";
import { t as s } from "./PermissionNotice-DDhK_CzL.js";
import { St as c, dn as l, s as u, y as d } from "./store-Dh-bVjb-.js";
import { r as f } from "./mobx-BHYB6eG8.js";
//#region src/components/gps/GpsPermissionRequest.tsx
var p = /* @__PURE__ */ e(r(), 1), m = i(), h = o(function({ isOpen: e, onAllow: t, onCancel: r }) {
return e ? /* @__PURE__ */ (0, m.jsx)(s, {
title: n("Show your position on the map"),
acceptText: n("Allow compass access"),
rejectText: n("Not now"),
onAccept: t,
onReject: r,
children: n("To display your current position and orient the map around you, we’ll ask for permission to access your device orientation")
}) : null;
});
function g(e) {
return Math.floor(e);
}
function _(e, t) {
return l(e, t) >= 3 || e.heading !== t.heading;
}
//#endregion
//#region src/components/gps/useUserLocationAndHeading.ts
var v = 120, y = 3e3, b = 360;
function x(e) {
let t = (0, p.useRef)(null), n = (0, p.useRef)(null), r = (0, p.useRef)(0), i = (0, p.useRef)(null), o = (0, p.useRef)(!1), s = (0, p.useRef)(null), c = (0, p.useRef)(!1), u = (0, p.useRef)(null), d = (t) => e(t), f = (e) => {
let t = Date.now();
if (t - r.current < v) return;
let n = i.current;
if (!s.current) {
s.current = e, r.current = t, i.current = e, d(e);
return;
}
let a = l(s.current, e), o;
c.current ? a <= 3 ? (c.current = !1, s.current = e, o = {
...s.current,
heading: e.heading
}) : (s.current = e, o = e) : a >= 3 ? (c.current = !0, s.current = e, u.current = null, o = e) : (u.current == null && (u.current = t), t - u.current > y && (s.current = e), o = {
...s.current,
heading: e.heading
}), !(n && !_(n, o)) && (r.current = t, i.current = o, d(o));
}, m = (0, p.useCallback)((e) => {
var t;
let r = (t = e.webkitCompassHeading) == null ? e.alpha == null ? null : b - e.alpha : t;
if (r == null) return;
let a = g(r);
n.current !== a && (n.current = a, i.current && f({
...i.current,
heading: a
}));
}, [e]);
return {
startGeolocation: () => {
t.current == null && (t.current = navigator.geolocation.watchPosition((e) => {
f({
lat: e.coords.latitude,
lng: e.coords.longitude,
heading: n.current
});
}, (e) => a.warn("Geolocation watch error:", e), {
enableHighAccuracy: !0,
maximumAge: 0
}));
},
startOrientation: () => {
o.current || (o.current = !0, window.addEventListener("deviceorientation", m, !0));
},
stopGeolocation: () => {
t.current != null && (navigator.geolocation.clearWatch(t.current), t.current = null), s.current = null, c.current = !1;
},
stopOrientation: () => {
o.current = !1, window.removeEventListener("deviceorientation", m, !0);
}
};
}
//#endregion
//#region src/components/gps/GpsManager.tsx
function S({ onPositionUpdate: e, onAllowCompass: t, onRejectCompass: n, orientationStorageKey: r = "compass-permission-granted", requestCompass: i = !0, requestCompassAllowed: o = !0 }) {
let { startOrientation: s, startGeolocation: l, stopOrientation: u, stopGeolocation: d } = x(e), [f, g] = (0, p.useState)(!1), [_, v] = (0, p.useState)(!1);
(0, p.useEffect)(() => (navigator.geolocation.getCurrentPosition(() => {
g(!0), l();
}, (e) => {
a.warn("Geolocation error:", e), g(!1);
}), () => {
u(), d();
}), [
l,
d,
u
]);
let y = async () => {
typeof DeviceOrientationEvent < "u" && typeof DeviceOrientationEvent.requestPermission == "function" && await DeviceOrientationEvent.requestPermission() !== "granted" || (localStorage.setItem(r, "true"), s(), v(!1), t == null || t());
}, b = (0, p.useCallback)(() => {
localStorage.setItem(r, "false"), v(!1), n == null || n();
}, [n]);
return (0, p.useEffect)(() => {
if (!f || !o || typeof navigator > "u" || !c) return;
let e = localStorage.getItem(r);
if (!e || i) {
v(!0);
return;
}
e === "true" && y();
}, [
f,
i,
o,
y
]), /* @__PURE__ */ (0, m.jsx)(h, {
isOpen: _,
onAllow: y,
onCancel: b
});
}
//#endregion
//#region src/components/GpsLoader.tsx
function C({ requestCompassAllowed: e }) {
let [n, r] = (0, p.useState)(!1), i = (0, p.useCallback)(({ lat: e, lng: t, angle: n, heading: r }) => {
u.routeStore.selectCurrentPosition(new d(0, 0, 0, n || r, e, t), !1);
}, []), a = (0, p.useCallback)(() => {
u.routeStore.requestCompass = void 0, r(!1);
}, [r]), o = (0, p.useCallback)(() => {
u.routeStore.requestCompass = void 0, r(!1);
}, [r]);
return f(() => u.uiState.hideCookieConsent, (e) => {
r(e);
}), f(() => u.routeStore.requestCompass, (e) => {
r(e);
}), /* @__PURE__ */ (0, m.jsx)(S, {
requestCompass: n,
requestCompassAllowed: e,
onRejectCompass: a,
onAllowCompass: o,
orientationStorageKey: t,
onPositionUpdate: i
});
}
//#endregion
export { C as default };