@expofp/floorplan
Version:
Interactive floor plan library for expos and events
152 lines (151 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.7.8" };
var t = new e.Error().stack;
t && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[t] = "c79fbb9e-def3-4032-9cc0-03feec590c6e", e._sentryDebugIdIdentifier = "sentry-dbid-c79fbb9e-def3-4032-9cc0-03feec590c6e");
} catch {}
})();
import { r as e } from "./rolldown-runtime-YBAZwyzS.js";
import { t } from "./react-Di3Pmpio.js";
import { t as n } from "./jsx-runtime-C8yjdFgZ.js";
import { ct as r, q as i, s as a } from "./i18n-BEer1tI4.js";
import { n as o } from "./Button-C4gPbjAY.js";
import { t as s } from "./PermissionNotice-D-iU7GsJ.js";
import { E as c, it as l, jt as u, o as d } from "./store-DTwRqruF.js";
import { r as f } from "./mobx-BLgYz-7U.js";
//#region src/components/gps/GpsPermissionRequest.tsx
var p = /* @__PURE__ */ e(t(), 1), m = n(), h = o(function({ isOpen: e, onAllow: t, onCancel: n }) {
return e ? /* @__PURE__ */ (0, m.jsx)(s, {
title: a("Show your position on the map"),
acceptText: a("Allow compass access"),
rejectText: a("Not now"),
onAccept: t,
onReject: n,
children: a("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.lat, e.lng, t.lat, t.lng) >= 3 ? !0 : 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), i = (0, p.useRef)(0), a = (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 - i.current < v) return;
let n = a.current;
if (!s.current) {
s.current = e, i.current = t, a.current = e, d(e);
return;
}
let r = l(s.current.lat, s.current.lng, e.lat, e.lng), o;
c.current ? r <= 3 ? (c.current = !1, s.current = e, o = {
...s.current,
heading: e.heading
}) : (s.current = e, o = e) : r >= 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)) && (i.current = t, a.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 i = g(r);
n.current !== i && (n.current = i, a.current && f({
...a.current,
heading: i
}));
}, [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) => r.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: i = "compass-permission-granted", requestCompass: a = !0, requestCompassAllowed: o = !0 }) {
let { startOrientation: s, startGeolocation: c, stopOrientation: l, stopGeolocation: d } = x(e), [f, g] = (0, p.useState)(!1), [_, v] = (0, p.useState)(!1);
(0, p.useEffect)(() => (navigator.geolocation.getCurrentPosition(() => {
g(!0), c();
}, (e) => {
r.warn("Geolocation error:", e), g(!1);
}), () => {
l(), d();
}), [
c,
d,
l
]);
let y = async () => {
typeof DeviceOrientationEvent < "u" && typeof DeviceOrientationEvent.requestPermission == "function" && await DeviceOrientationEvent.requestPermission() !== "granted" || (localStorage.setItem(i, "true"), s(), v(!1), t == null || t());
}, b = (0, p.useCallback)(() => {
localStorage.setItem(i, "false"), v(!1), n == null || n();
}, [n]);
return (0, p.useEffect)(() => {
if (!f || !o || typeof navigator > "u" || !u) return;
let e = localStorage.getItem(i);
if (!e || a) {
v(!0);
return;
}
e === "true" && y();
}, [
f,
a,
o,
y
]), /* @__PURE__ */ (0, m.jsx)(h, {
isOpen: _,
onAllow: y,
onCancel: b
});
}
//#endregion
//#region src/components/GpsLoader.tsx
function C({ requestCompassAllowed: e }) {
let [t, n] = (0, p.useState)(!1), r = (0, p.useCallback)(({ lat: e, lng: t, angle: n, heading: r }) => {
d.routeStore.selectCurrentPosition(new c(0, 0, 0, n || r, e, t), !1);
}, []), a = (0, p.useCallback)(() => {
d.routeStore.requestCompass = void 0, n(!1);
}, [n]), o = (0, p.useCallback)(() => {
d.routeStore.requestCompass = void 0, n(!1);
}, [n]);
return f(() => d.uiState.hideCookieConsent, (e) => {
n(e);
}), f(() => d.routeStore.requestCompass, (e) => {
n(e);
}), /* @__PURE__ */ (0, m.jsx)(S, {
requestCompass: t,
requestCompassAllowed: e,
onRejectCompass: a,
onAllowCompass: o,
orientationStorageKey: i,
onPositionUpdate: r
});
}
//#endregion
export { C as default };