UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

1,131 lines (1,130 loc) 34.6 kB
(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] = "39db3266-7481-4d16-bbfd-bd22062e0ddb", e._sentryDebugIdIdentifier = "sentry-dbid-39db3266-7481-4d16-bbfd-bd22062e0ddb"); } catch {} })(); import { r as e } from "./rolldown-runtime-7-Wh3Cc7.js"; import { A as t, v as n } from "./i18n-B6dEf7vu.js"; import { t as r } from "./react-lDheuaid.js"; import { r as i, t as a } from "./loadImage-DidrxJwE.js"; import { At as o, Bt as s, Ct as c, D as l, Dt as u, E as d, Gt as f, It as p, Lt as m, Mt as h, Nt as g, O as _, Ot as v, Pt as y, Qt as b, Rt as x, T as S, Tt as C, Ut as w, _n as T, a as E, an as D, bn as O, c as k, cn as A, fn as j, gn as M, hn as N, ht as P, jt as ee, k as te, ln as F, mn as ne, mt as I, pn as L, s as R, t as re, un as z, v as ie, vn as B, vt as ae, yt as oe } from "./store-Dh-bVjb-.js"; //#region src/components/Map/traffic/trafficLayers.ts var se = "traffic_route", ce = "traffic_route_stop", le = "traffic_vehicles", ue = "build_route_lines", de = "build_route_dots", fe = 5; function pe() { let e = []; for (let t = 0; t < fe; t++) e.push({ name: me(t), children: [] }), e.push({ name: he(t), children: [], interactive: !0 }); return e.push({ name: le, children: [], interactive: !0 }), e.push({ name: ue, children: [] }), e.push({ name: de, children: [], interactive: !0 }), e; } function me(e) { return `${se}_${e + 1}`; } function he(e) { return `${ce}_${e + 1}`; } function ge() { return RegExp(`^${se}_\\d+$`); } function _e() { return RegExp(`^${ce}_\\d+$`); } //#endregion //#region src/components/Map/drawing/config/config-booth-badge-eligibility.ts var ve = /* @__PURE__ */ e(F(), 1); function ye(e) { return e.hideExhibitorBoothNumber || e.hideBoothBadges || !e.hasExhibitors ? !1 : e.noLabels || !e.hideLogoInBooth && e.hasLogoInBooth; } //#endregion //#region src/components/Map/drawing/config/config-booth-badge.ts var be = .5, xe = .3, Se = 15, Ce = 24, we = 30, Te = 12, Ee = .8, De = document.createElement("canvas").getContext("2d"); function Oe(e) { return e.length <= Se ? e : e.slice(0, Se - 1) + "…"; } function ke(e) { var t, n; if (!((t = e.paths) != null && t.length)) return []; let r = ((n = e.layer) == null ? void 0 : n.name) || "", i = []; for (let t of e.paths) for (let e of D(t.index, r)) i.push(e); return i; } function Ae(e) { let t = ke(e); return t.length ? j.fromPoints(t.flat().map(([e, t]) => ({ x: e, y: t }))) : null; } function je(e) { let t = [], n = []; for (let r of e) { let e = t.length; t.push({ x: r[0][0], y: r[0][1] }), t.push({ x: r[1][0], y: r[1][1] }), t.push({ x: r[2][0], y: r[2][1] }), n.push([ e, e + 1, e + 2 ]); } return new N(t, n); } function V(e, t, n) { return n.containsPoint({ x: e, y: t }); } function Me(e, t, n, r, i, a, o, s) { if (!e.length || !V(n, r, t)) return o; let c = { x: n, y: r }, l = 0, u = o; for (let e = 0; e < 10; e++) { let e = (l + u) / 2, o = i * e, d = a * e; [ T({ x: n + o, y: r }, s, c), T({ x: n, y: r + d }, s, c), T({ x: n + o, y: r + d }, s, c) ].every((e) => V(e.x, e.y, t)) ? l = e : u = e; } return l; } function Ne(e) { var t; return (t = Ae(e)) == null ? e.rect : t; } function Pe(e, t, n, r, i, a) { var o; if (t.length) { let o = Ne(e), s = { x: i > 0 ? o.min.x : o.max.x, y: a > 0 ? o.min.y : o.max.y }, c = /* @__PURE__ */ new Set(), l = null, u = Infinity; for (let e of t) for (let t of e) { let e = `${t[0]},${t[1]}`; if (c.has(e)) continue; c.add(e); let o = t[0] + r * i, d = t[1] + r * a; if (V(o, d, n)) { let e = Math.abs(o - s.x) + Math.abs(d - s.y); e < u && (u = e, l = { x: o, y: d }); } } if (l) return l; } let s = i > 0 ? e.rect.min.x + r : e.rect.max.x - r, c = a > 0 ? e.rect.min.y + r : e.rect.max.y - r, l = (o = e.rotate) == null ? 0 : o; return l ? T({ x: s, y: c }, l, e.rect.center) : { x: s, y: c }; } function H(e) { return e && e !== "none" ? e : void 0; } function Fe(e) { var t; let n = H(e.borderColor) || H(O.boothBorderColor) || O.colors.booths.default; return ((t = e.paths) == null ? void 0 : t.length) > 1 && H(e.paths[e.paths.length - 1].color) || n; } function Ie(e, t) { var r; let i = Oe(t.title || t.name), a = Fe(t), s = ie((0, ve.default)(a).hex()), l = window.devicePixelRatio || 1, u = ae(); De.font = f(we, u); let d = De.measureText(i).width, m = Math.ceil(d + Te * 2), g = (t.borderWidth || re.borderWidth) / 2, _ = m * Ee, v = 54 * Ee, y = t.rect.size.width, b = t.rect.size.height, x = (e) => { let t = e ? b : y, n = e ? y : b; return Math.min(t > 0 ? t * be / _ : Infinity, n > 0 ? n * xe / v : Infinity); }, S = ke(t), w = je(S), E = (r = t.rotate) == null ? 0 : r, D = 0, O, A, j, M = () => { let e = Pe(t, S, w, g, D === 0 || D === 3 ? 1 : -1, D === 0 || D === 1 ? 1 : -1); O = e.x, A = e.y; let n = x(D === 1 || D === 3); j = Me(S, w, O, A, _, v, n, E); }; M(); let N = (e, t) => { let n = e / 2, r = t / 2; return new ne(T({ x: O + n, y: A + r }, E, { x: O, y: A }), { x: e, y: t }, E); }, P = (e) => { let t = Math.min(e, j); return N(_ * t, v * t); }, te = oe(u, e.fontUrls), F = o(N(1, 1), a); F.hidden = !0, F.dim = !t.skipDim && void 0; let I = ee(h([[i], []], s, 0, [te, te]), N(1, 1), [0, 0], { horizontal: "center", vertical: "center" }); I.hidden = !0, I.dim = !t.skipDim && void 0; let L = () => !!(t.layer && !t.layer.visible), R = []; R.push(n(() => t.skipDim, (t) => { F.dim = !t && void 0, I.dim = !t && void 0, e.update(F, I); })), R.push(n(() => { var e, n; return (e = (n = t.layer) == null ? void 0 : n.visible) == null || e; }, (t) => { F.hidden = !t, I.hidden = !t, e.update(F, I); })); let z = (e) => { F.shape = p(P(e)), F.hidden = L(); }, B = (e) => { let t = Math.min(e, j); I.lines[0].fontSize = Ce / l * t, I.bounds = p(P(e)), I.hidden = L(); }; return e.onPtScale(`badge-bg-${t.id}`, (e) => (z(e), F)), e.onPtScale(`badge-text-${t.id}`, (e) => (B(e), I)), R.push(n(() => k.mapSettings, ({ roll: n }) => { c(n == null ? 0 : n) && e.onRoll(`badge-roll-${t.id}`, (t) => { let n = C(t, E); n !== void 0 && (E += n, D = (D + (n > 0 ? 1 : 3)) % 4, M(), z(e.scale), B(e.scale), e.update(F, I)); }); }, { fireImmediately: !0 })), { bg: F, text: I, dispose: () => { R.forEach((e) => e()), R.length = 0; } }; } function Le(e, t, n) { let r = [], i = [], a = []; for (let t of n) if (t instanceof b && ye({ hideExhibitorBoothNumber: A.hideExhibitorBoothNumber, hideBoothBadges: A.hideBoothBadges, hideLogoInBooth: k.hideLogoInBooth, noLabels: t.noLabels, hasExhibitors: t.exhibitors.length > 0, hasLogoInBooth: t.exhibitors.some((e) => e.logoInBooth && e.logo) })) { let { bg: n, text: o, dispose: s } = Ie(e, t); r.push(n), i.push(o), a.push(s); } let o = () => { a.forEach((e) => e()), a.length = 0; }; return r.length ? { layer: { name: `${t}:badges`, children: [{ name: `${t}:badgeBgs`, children: r }, { name: `${t}:badgeTexts`, children: i }] }, cleanup: o } : { layer: null, cleanup: o }; } //#endregion //#region src/components/Map/drawing/config/config-markers.ts var Re = "_selected", ze = "markers"; function Be(e) { let t = [], r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = [], o = e.scene.rootLayer.children.find((e) => e.name === ze); async function s(e) { let t = []; e.forEach((e) => { let { name: n, content: i, width: a, height: o, scale: s } = e; if (r.has(n)) return; let c = new Image(), l = new Promise((e, t) => { c.onload = () => { r.set(n, { img: c, width: a, height: o, scale: s }), e(); }, c.onerror = (e) => { t(e); }; }); t.push(l), c.src = i, c.crossOrigin = "anonymous"; }), await Promise.all(t); } let c = (e) => `marker-ptScaleHandlers-${e.id}`, l = (e) => `marker-rollHandlers-${e.id}`, d = (t, n) => { e.onPtScale(n, (e) => { let { center: n, rotation: r } = t.bounds, { width: i, height: a } = t.source; return t.bounds = p(x(n.x, n.y, i, a, e, r)), t; }); }, f = (t, n) => { e.onRoll(n, (e) => (t.bounds.rotation = e, t)); }; function m() { let t = R.routeStore.markersData.markers; if (!t.length) return; a = []; let n = e.scale, s = B(e.angle); t.forEach((e) => { var t, o; let c = r.get(e.icon); if (!c) return; let l = c.scale || window.devicePixelRatio, d = e.icon; if (!i.has(d)) { let e = w(c.img, c.width, c.height, l); i.set(d, e); } let f = i.get(d), p = r.get(e.selectedIcon), m = e.selectedIcon; if (!i.has(m)) { let e = w(p.img, p.width, p.height, l); i.set(m, e); } let h = i.get(m), g = (t = (o = E.findLayer(e.z)) == null ? void 0 : o.visible) == null || t, _ = x(e.x, e.y, f.width, f.height, n, s), v = x(e.x, e.y, h.width, h.height, n, s), y; switch (e.position) { case "lefttop": y = [0, 0]; break; case "centertop": y = [.5, 0]; break; case "centerbottom": y = [.5, 1]; break; default: y = [.5, .5]; } let b = { ...u(f, _, { hidden: !g, origin: y }), id: e.id, scale: l }, S = { ...u(h, v, { hidden: !(g && e.active), origin: y }), id: `${e.id}${Re}`, scale: l }; a.push(b, S); }), o.children = a, a.forEach((e) => { d(e, c(e)), f(e, l(e)); }); } function h() { a.forEach((t) => { e.ptScaleRegistry.unregisterByName(c(t)), e.rollRegistry.unregisterByName(l(t)); }), o.children = [], a = []; } function g() { let e = R.routeStore.markersData.markers; e.length && e.forEach((e) => { var t, n; let r = a.find((t) => t.id === e.id), i = a.find((t) => t.id === `${e.id}${Re}`); if (!r) return; let o = (t = (n = E.findLayer(e.z)) == null ? void 0 : n.visible) == null || t; e.active ? (r.hidden = !0, i.hidden = !(o && e.active)) : (r.hidden = !o, i.hidden = !0); }); } return t.push(n(() => [R.routeStore.selectedMarkers, R.layerStore.visible], () => { if (!R.routeStore.markersData.markers.length) { h(), e.update(o); return; } g(), e.update(...a); })), t.push(n(() => R.routeStore.markersData.markers, () => { s(R.routeStore.markersData.icons).then(() => { m(), e.update(o); }); }, { fireImmediately: !0 })), function() { t.forEach((e) => e()), t.length = 0; }; } function Ve(e, t, n) { for (let r of R.routeStore.markersData.markers) { let i = R.routeStore.markersData.icons.find((e) => e.name === r.icon); if (!i) continue; let a = i.width * n * devicePixelRatio, o = i.height * n * devicePixelRatio; if (He(e, t, r.x, r.y, a, o)) { let e = R.layerStore.findLayer(r.z); if (!e || e && e.visible) return r; } } return null; } function He(e, t, n, r, i, a) { return j.fromCenter({ x: n, y: r }, { x: 2 * i, y: 2 * a }).containsPoint({ x: e, y: t }); } //#endregion //#region src/components/Map/drawing/config/config-all.ts function Ue(e) { let { defaultLayer: t } = R.layerStore, { layers: n } = R.layerStore; if (t) { let e = [...n], r = n.indexOf(t); e.splice(r, 1), n = [t, ...e]; } let r = n.filter((e) => !e.rootParent).map((t) => P(t, e)); return Promise.all(r).then((t) => { let n = v(_, [], { dim: !1, interactive: !0 }), r = v(l, [], { dim: !1 }), i = v(ze, []), a = v(te, [], { dim: !1 }), o = v(d, [], { dim: !1 }), c = v(S, [], { dim: !1 }), u = [], f = []; for (let e of t.flat()) s(e.name) ? (e.dim = !1, f.push(e)) : u.push(e); let { layer: p, cleanup: m } = Le(e, "root", R.boothStore.booths); return { layers: [ ...u, ...p ? [p] : [], ...f, ...pe(), i, a, r, o, n, c ], cleanup: m }; }); } //#endregion //#region src/components/Map/traffic/UpdateQueue.ts var U = /* @__PURE__ */ e(r(), 1), We = class { constructor() { this.queue = [], this.isProcessing = !1, this.rafId = null, this.CHUNK_SIZE = 100, this.TIME_BUDGET = 4; } add(e) { this.queue.push(e), this.scheduleProcessing(); } scheduleProcessing() { this.isProcessing || this.queue.length === 0 || (this.isProcessing = !0, this.queue.length <= this.CHUNK_SIZE * 2 ? Promise.resolve().then(() => this.processMicrotaskQueue()) : this.rafId = requestAnimationFrame((e) => { this.processQueue(e); })); } processMicrotaskQueue() { let e = performance.now(), t = 0; for (; this.queue.length > 0 && t < this.CHUNK_SIZE;) { let n = this.queue.shift(); try { n(); } catch (e) { console.warn("UpdateQueue task error:", e); } if (t++, performance.now() - e > this.TIME_BUDGET) break; } this.queue.length > 0 ? Promise.resolve().then(() => this.processMicrotaskQueue()) : this.isProcessing = !1; } processQueue(e) { this.rafId = null; let t = 0; for (; this.queue.length > 0 && t < this.CHUNK_SIZE;) { let n = this.queue.shift(); try { n(); } catch (e) { console.warn("UpdateQueue task error:", e); } if (t++, performance.now() - e > this.TIME_BUDGET) break; } this.queue.length > 0 ? this.rafId = requestAnimationFrame((e) => this.processQueue(e)) : this.isProcessing = !1; } destroy() { this.rafId !== null && (cancelAnimationFrame(this.rafId), this.rafId = null), this.queue = [], this.isProcessing = !1; } }, W = 49, Ge = `hsl(257, 76%, ${W}%)`, Ke = `hsl(339.903, 82%, ${W}%)`, qe = `hsl(257, 76%, ${Math.round(W * 1.82)}%)`, G = 4, Je = G, Ye = "U", Xe = "R", Ze = "S", Qe = "P", $e = class { constructor() { this._state = [[]], this.index = 0, this.pointHashSet = /* @__PURE__ */ new Set(), this.locked = !1, this.storageKey = "expofp_build_route_state", this._selected = 0; } get points() { return this._state[this.index]; } set points(e) { this._state.push(e), this.setIndex(), this.save(); } setIndex() { this.index = Math.max(this._state.length - 1, 0); } genPointHash(e) { return `${e.x},${e.y}`; } add(e) { let t = this.genPointHash(e); this.pointHashSet.has(t) || (this.pointHashSet.add(t), this.points = [...this.points, e]); } undo() { this.index && (this._state.pop(), this.setIndex(), this.save(), this.select(this.points.length - 1)); } execute(e) { try { if (this.locked) return; this.locked = !0, e(); } finally { requestAnimationFrame(() => { this.locked = !1; }); } } log(e, t = 12) { console.log(`%c${e}`, `color: black; font-size: ${t}px; background: LemonChiffon;`); } instruct() { this.log(`How to Build a Route: Add Point: Click on the map. Apply Smoothing: Press ${Xe}. Apply Simplification: Press ${Ze}. Undo: Press ${Ye}. Enable/Disable Preview: Press ${Qe}. `, 16); } applyChaikinSmoothing(e, t, n) { let r = []; if (n >= 1 && e.length >= 2) { r = [e[0]]; for (let t = 1; t < e.length; t++) { let i = e[t - 1], a = e[t]; for (let e = 1; e <= n; e++) { let t = e / (n + 1); r.push({ x: i.x + (a.x - i.x) * t, y: i.y + (a.y - i.y) * t }); } r.push(a); } } else r = e.slice(); for (let e = 0; e < t && !(r.length < 2); e++) { let e = [{ ...r[0] }]; for (let t = 1; t < r.length; t++) { let n = r[t - 1], i = r[t]; e.push({ x: .75 * n.x + .25 * i.x, y: .75 * n.y + .25 * i.y }), e.push({ x: .25 * n.x + .75 * i.x, y: .25 * n.y + .75 * i.y }); } e.push({ ...r[r.length - 1] }), r = e; } return r; } applySmoothing() { this.points.length < 3 || (this.points = this.applyChaikinSmoothing(this.points, 1, 0), this.select(this.points.length - 1)); } save() { try { this.points.length ? sessionStorage.setItem(this.storageKey, JSON.stringify(this.points)) : sessionStorage.removeItem(this.storageKey); } catch (e) { console.warn(e); } } restore() { try { let e = sessionStorage.getItem(this.storageKey); if (!e) return; let t = JSON.parse(e); if (!Array.isArray(t)) return; t.forEach((e) => this.add(e)), this.select(this.points.length - 1); } catch (e) { console.warn(e); } } topologyPreservingSimplify(e, t) { if (e.length <= 2) return e.map((e) => ({ ...e })); let n = (e, t, n) => { let r = e.x, i = e.y, a = t.x, o = t.y, s = n.x, c = n.y; return Math.abs((c - o) * r - (s - a) * i + s * o - c * a) / (Math.sqrt((c - o) ** 2 + (s - a) ** 2) || 1e-10); }, r = (e, t, n, r) => { let i = L({ p0: e, p1: t }, { p0: n, p1: r }); return i !== null && i.onLine1 && i.onLine2; }, i = Array(e.length).fill(!1); i[0] = i[i.length - 1] = !0; let a = [], o = (s, c) => { if (c <= s + 1) return; let l = e[s], u = e[c], d = 0, f = 0; for (let t = s + 1; t < c; t++) { let r = n(e[t], l, u); r > d && (d = r, f = t); } if (d > t) { let t = e[f], n = !0; for (let e = 0; e < a.length - 1; e++) if (r(a[e], a[e + 1], l, t) || r(a[e], a[e + 1], t, u)) { n = !1; break; } n && (i[f] = !0, o(s, f), o(f, c)); } }; return o(0, e.length - 1), e.filter((e, t) => i[t]); } applySimplification() { this.points = this.topologyPreservingSimplify(this.points, .5), this.select(this.points.length - 1); } get selected() { return this._selected; } select(e) { this._selected = Math.max(0, Math.min(e, this.points.length - 1)); } }; function et({ enabled: e, rendererService: t }) { let n = (0, U.useRef)(!1), r = (0, U.useRef)(), i = (0, U.useMemo)(() => m(G, Ge), []), a = (0, U.useMemo)(() => m(G, Ke), []), o = (0, U.useMemo)(() => new $e(), []), s = (0, U.useRef)(new We()), c = (0, U.useMemo)(() => { if (!t.scene) return {}; let e = t.scene.rootLayer.children; return { linesLayer: e.find((e) => e.name === ue), pointsLayer: e.find((e) => e.name === de) }; }, [t.scene]), l = (0, U.useCallback)(() => { if (!(t != null && t.renderer) || !c || !i || !a) return; let { linesLayer: e, pointsLayer: l } = c; if (!e || !l) return; let u = o.points, d = n.current; d ? l.children.length = 0 : l.children = u.map(({ x: e, y: t }, n) => { let s = n == o.selected ? a : i; return { source: s, bounds: p(x(e, t, s.width, s.height, r.current)) }; }); let f = []; for (let e = 1; e < u.length; e++) { let t = u[e - 1], n = u[e]; f.push({ points: [t, n], color: d ? Ge : qe, width: Je }); } f.length ? e.children = f : e.children.length = 0, s.current.add(() => t.update(l, e)), o.instruct(), o.log(JSON.stringify(o.points)); }, [ t, o, c, i, a ]), u = (0, U.useCallback)((e) => { let t = e.key.toUpperCase(); o.execute(() => { switch (t) { case Ye: e.preventDefault(), o.undo(), n.current = !1, l(); break; case Xe: e.preventDefault(), o.applySmoothing(), n.current = !1, l(); break; case Ze: e.preventDefault(), o.applySimplification(), n.current = !1, l(); break; case Qe: e.preventDefault(), n.current = !n.current, l(); break; } }); }, [o, l]), d = (0, U.useCallback)(({ ptScale: e, sceneId: n }) => { if (!g(n) || !(t != null && t.renderer) || !c) return; let { pointsLayer: i } = c; i && (r.current = e, o.execute(() => { let e = i.children, n = []; for (let t of e) t.bounds = p(x(t.bounds.center.x, t.bounds.center.y, t.source.width, t.source.height, r.current)), n.push(t); s.current.add(() => t.update(...n)); })); }, [ t, c, o ]), f = (0, U.useCallback)(({ data: e }) => { o.execute(() => { let { point: t } = y(e); o.add({ x: t.x, y: t.y }), o.select(o.points.length - 1), l(); }); }, [o, l]); (0, U.useEffect)(() => { let n = t.renderer; if (!(!e || !n)) return r.current = t.scale, o.execute(() => { o.restore(), l(); }), n.events.addEventListener("pointer:click", f), n.events.addEventListener("viewport:ptscale", d), window.addEventListener("keyup", u), () => { window.removeEventListener("keyup", u), n.events.removeEventListener("pointer:click", f), n.events.removeEventListener("viewport:ptscale", d), s.current.destroy(); }; }, [ e, t, o, l, f, d, u ]); } //#endregion //#region src/components/Map/traffic/useManageTraffic.ts var K = 2, tt = K * 3.5, q = K * 12, nt = q * .7, rt = 8, it = "transport_locations", at = 150, J = "#a4aab6", ot = 1e3, st = 2e4, ct = 500; function lt({ permission: e, rendererService: n, dataJsonUrl: r, websocketUrl: i }) { let o = (0, U.useRef)(window.devicePixelRatio), s = (0, U.useRef)(/* @__PURE__ */ new Map()), c = (0, U.useRef)(/* @__PURE__ */ new Map()), l = (0, U.useRef)(), u = (0, U.useRef)(), d = (0, U.useRef)(performance.now()), f = (0, U.useRef)(1), m = (0, U.useRef)(new We()), h = (0, U.useRef)(/* @__PURE__ */ new Map()), _ = (0, U.useRef)(), v = (0, U.useRef)(ot), y = (0, U.useRef)(/* @__PURE__ */ new Map()), b = (0, U.useRef)(); (0, U.useEffect)(() => { let S; async function C() { if (!(!e || !n.scene)) try { let e; try { let t = await fetch(r, { method: "GET", headers: { "Content-Type": "application/json" } }); if (!t.ok || t.status === 204) return; e = await t.json(); } catch (e) { console.warn("useManageTraffic failed to get JSON", e); } if (!e || e != null && e.disabled || e != null && e.error) return; o.current = ut(n.scale); let i = new Map(e.routes.map(({ id: e, color: t }) => [e, t])), l = n.scene.rootLayer.children, v = /* @__PURE__ */ new Map(); i.forEach((e) => { v.set(e, pt({ radius: tt, color: e, scale: window.devicePixelRatio })); }); let b = ge(), C = l.filter((e) => b.test(e.name)), E = _e(), O = l.filter((e) => E.test(e.name)); e.routes.slice(0, C.length).forEach(({ id: e, color: t, path: r, stops: i, hiddenPoints: a }, s) => { h.current.set(e, r); let c = C[s]; if (c) { var l; let e = new Map((l = a == null ? void 0 : a.map((e) => [xt(e), e])) == null ? [] : l); for (let n = 1; n < r.length; n++) { let i = r[n - 1], a = r[n]; e.has(xt(i)) || e.has(xt(a)) || c.children.push({ points: [i, a], color: t, width: K }); } c.children.length && m.current.add(() => n.update(c)); } let u = O[s]; if (u && i != null && i.length) { let e = v.get(t); i.forEach((t) => { u.children.push({ source: e, bounds: p(x(t.x, t.y, e.width, e.height, o.current)) }); }), u.children.length && m.current.add(() => n.update(u)); } }); let k = l.find((e) => e.name === le), A = /* @__PURE__ */ new Map(); _.current = (e) => { try { let { ptScale: t, sceneId: r } = dt(e); if (!g(r)) return; o.current = ut(t); let i = []; for (let e of O) { let t = e.children; for (let e of t) e.bounds = p(x(e.bounds.center.x, e.bounds.center.y, e.source.width, e.source.height, o.current, e.bounds.rotation)), i.push(e); } let a = [...s.current.values()]; for (let e of a) e.bounds = p(x(e.bounds.center.x, e.bounds.center.y, e.source.width, e.source.height, o.current, e.bounds.rotation)); m.current.add(() => n.update(...i, ...a)); } catch (e) { console.error("ptscale", e); } }, n.renderer.events.addEventListener("viewport:ptscale", _.current), S = requestAnimationFrame(() => { var e; (e = _.current) == null || e.call(_, n.scale); }), i.forEach((e, t) => { A.set(t, mt({ id: t, width: q, height: q, color: e, scale: window.devicePixelRatio })); }), A.set(J, mt({ id: "orphan", width: q, height: q, color: J, scale: window.devicePixelRatio })); let j = null; try { j = w(await a(`${t}icons/bus-white.svg`), nt, nt, window.devicePixelRatio); } catch (e) { console.error(e); } u.current = (e) => { try { var t; let r = JSON.parse(e.data); if (r.type !== it) return; let i = e.timeStamp || performance.now(); f.current = Math.round(i - d.current), d.current = i; let a = Math.max((t = f.current) == null ? ct : t, ct), l = c.current, u = s.current, g = k.children, _ = m.current, v = !1; r.data.forEach(({ id: e, x: t, y: r, route_id: i, hidden: s }) => { if (l.has(e)) { var c; (c = l.get(e)) == null || c(), l.delete(e); } if (s && u.has(e) && u.has(Y(e))) { let t = u.get(e); t.hidden = !0; let r = u.get(Y(e)); r.hidden = !0, _.add(() => n.update(t, r)); return; } if (y.current.set(e, performance.now()), !u.has(e)) { let n = A.get(i) || A.get(J), a = { id: e, source: n, bounds: p(x(t, r, n.width, n.height, o.current, 0)) }; if (u.set(e, a), j) { let n = Y(e), i = { id: n, source: j, bounds: p(x(t, r, j.width, j.height, o.current, 0)) }; j.setAttribute("id", n), u.set(n, i), g.push(a, i); } else g.push(a); v = !0; return; } let d = u.get(e), f = u.get(Y(e)), m = d.bounds.center, b = yt(m, { x: t, y: r }, h.current.get(i)); if (b.reduce((e, t, n) => n === 0 ? e : e + ht(b[n - 1], t), 0) >= at || document.hidden) gt({ rendererService: n, updateQueue: _, vehicle: d, vehicleFinery: f, x: t, y: r, scale: o.current, angle: ft(d.bounds.center, { x: t, y: r }) }); else { let t = bt(b, a, (e) => { gt({ rendererService: n, updateQueue: _, vehicle: d, vehicleFinery: f, x: e.x, y: e.y, scale: o.current, angle: e.angle }); }); l.set(e, t); } }), v && _.add(() => n.update(k)); } catch (e) { console.error("handleSocketMessage", e); } }, T(), D(e.config ? (Number(e.config.vehicle_inactive_interval) || 20) * 1e3 : st); } catch (e) { console.warn(e); } } C(); function T() { var e, t; ((e = l.current) == null ? void 0 : e.readyState) === WebSocket.OPEN || ((t = l.current) == null ? void 0 : t.readyState) === WebSocket.CONNECTING || (l.current = new WebSocket(i), l.current.onmessage = u.current, l.current.onopen = () => { v.current = ot; }, l.current.onclose = () => { navigator.onLine && (setTimeout(T, v.current), v.current = Math.min(v.current * 2, 3e4)); }); } function E() { T(); } window.addEventListener("online", E); function D(e) { clearInterval(b.current), b.current = window.setInterval(() => { let t = performance.now(), r = [], i = []; y.current.forEach((n, a) => { if (t - n < e) return; let o = s.current.get(a); o && (o.hidden = !0, i.push(o), r.push(a)); let c = Y(a), l = s.current.get(c); l && (l.hidden = !0, i.push(l), r.push(c)); }), i.length && m.current.add(() => n.update(...i)), r.forEach((e) => y.current.delete(e)); }, e); } return () => { _.current && n.renderer && n.renderer.events.removeEventListener("viewport:ptscale", _.current), S !== void 0 && cancelAnimationFrame(S), c.current.forEach((e) => e == null ? void 0 : e()), c.current.clear(), s.current.clear(), m.current.destroy(), window.removeEventListener("online", E), clearInterval(b.current); }; }, [ e, n, r, i ]); } function ut(e) { return Math.min(e || window.devicePixelRatio, rt); } function dt(e) { return typeof e == "number" ? { ptScale: e } : e; } function ft(e, t) { return z(e, t); } function pt({ radius: e, scale: t, color: n }) { let r = document.createElement("canvas"), i = r.getContext("2d"); i.imageSmoothingEnabled = !1; let a = Math.ceil(e * 2 * t), o = a / 2, s = e * .78, c = e * .33; return r.width = a, r.height = a, i.translate(o, o), i.scale(t, t), i.beginPath(), i.arc(0, 0, e, 0, 2 * Math.PI), i.fillStyle = "#FFFFFF", i.fill(), i.beginPath(), i.arc(0, 0, s, 0, 2 * Math.PI), i.fillStyle = n, i.fill(), i.beginPath(), i.arc(0, 0, c, 0, 2 * Math.PI), i.fillStyle = "#FFFFFF", i.fill(), r; } function mt({ id: e, width: t, height: n, color: r, scale: i }) { let a = 2 * i, o = t / 2 * i, s = n * i, c = .01, l = s * .6, u = s, d = 8 * i, f = u + a + l / 2 + d * 2, p = o * 2 + l + a + d * 2, m = document.createElement("canvas"); m.setAttribute("id", e), m.width = f, m.height = p; let h = m.getContext("2d"), g = f / 2, _ = p / 2; h.save(), h.translate(g, _), h.rotate(-Math.PI / 2), h.translate(-g, -_); let v = g, y = _ - u / 2 + o, b = y + l; return h.shadowColor = "rgba(16, 24, 40, 0.2)", h.shadowBlur = d / 2, h.beginPath(), h.arc(v, y, o, Math.PI, 0, !1), h.bezierCurveTo(v + o, y + s * .3, v + c * o, b, v, b), h.bezierCurveTo(v - c * o, b, v - o, y + s * .3, v - o, y), h.closePath(), h.fillStyle = r, h.fill(), h.strokeStyle = "#FFFFFF", h.lineWidth = a, h.stroke(), h.restore(), m; } function ht(e, t) { return M(e, t); } function Y(e) { return `${e}_finery`; } function gt({ rendererService: e, updateQueue: t, vehicle: n, vehicleFinery: r, x: i, y: a, scale: o, angle: s }) { n.bounds = p(x(i, a, n.source.width, n.source.height, o, s)), n.hidden = !1, r ? (r.bounds = p(x(i, a, r.source.width, r.source.height, o, B(e.angle))), r.hidden = !1, t.add(() => e.update(r, n))) : t.add(() => e.update(n)); } function X(e, t, n) { return { x: e.x + (t.x - e.x) * n, y: e.y + (t.y - e.y) * n }; } function _t(e, t) { let n = Infinity, r = { index: 0, t: 0 }; for (let i = 0; i < t.length - 1; i++) { let a = t[i], o = t[i + 1], s = o.x - a.x, c = o.y - a.y, l = s * s + c * c, u = l ? ((e.x - a.x) * s + (e.y - a.y) * c) / l : 0, d = Math.max(0, Math.min(1, u)), f = ht(e, X(a, o, d)); f < n && (n = f, r = { index: i, t: d }); } return r; } function vt(e, t, n) { let r = ht(e, t), i = Math.max(2, Math.ceil(r / n) + 1), a = []; for (let n = 0; n < i; n++) { let r = X(e, t, n / (i - 1)); a.push(r); } return a; } function yt(e, t, n) { if (!n || !n.length) return vt(e, t, 10); let r = _t(e, n), i = _t(t, n), a = [], o = (e) => a.push(e); r.index + 1 < n.length ? o(X(n[r.index], n[r.index + 1], r.t)) : o(n[r.index]); for (let e = r.index + 1; e <= i.index && e < n.length; e++) o(n[e]); return i.index + 1 < n.length ? o(X(n[i.index], n[i.index + 1], i.t)) : o(n[i.index]), a; } function bt(e, t, n, r) { if (e.length < 2) return () => {}; let i = null, a, o = [], s = 0; for (let t = 0; t < e.length - 1; t++) { let n = M(e[t], e[t + 1]); o.push(n), s += n; } let c = (l) => { i || (i = l); let u = l - i, d = Math.min(u / t, 1), f = d * s, p = 0, m = 0; for (; m < o.length && p + o[m] < f;) p += o[m], m++; m >= o.length && (m = o.length - 1); let h = e[m], g = e[Math.min(m + 1, e.length - 1)], _ = o[m] || 0, v = _ === 0 ? 0 : (f - p) / _; n({ x: h.x + (g.x - h.x) * v, y: h.y + (g.y - h.y) * v, angle: z(h, g) }), d < 1 ? a = requestAnimationFrame(c) : r && r(); }; return a = requestAnimationFrame(c), () => { a && cancelAnimationFrame(a); }; } function xt(e) { return `${e.x},${e.y}`; } //#endregion //#region src/utils/dimming.ts var St = .5, Ct = "cubic"; function wt(e, t) { let n = e.scene; if (!n) return; let r = n.rootLayer; r.dim !== t && (r.dim = t, e.update(n.rootLayer)); } function Tt(e, t = 300, n = Ct) { let r = null, i = 0, a = 0, o = 0, s = 0, c = Math.max(t, 0); function l() { r === null || typeof cancelAnimationFrame != "function" || (cancelAnimationFrame(r), r = null); } function u(t) { l(), i = t, e(i); } function d(t) { let l = t - s, u = Math.min(l / c, 1), f = Et(u, n); if (i = a + (o - a) * f, e(i), u < 1) { r = requestAnimationFrame(d); return; } r = null, i = o, e(i); } return { getValue() { return i; }, setTarget(e, t = {}) { let n = +!!e; if (!(!t.immediate && n === o && r === null)) { if (o = n, t.immediate || c === 0 || typeof requestAnimationFrame != "function") { u(o); return; } l(), a = i, s = typeof performance > "u" ? Date.now() : performance.now(), r = requestAnimationFrame(d); } }, stop() { l(); } }; } function Et(e, t) { return t === "linear" ? e : Dt(e); } function Dt(e) { return e < .5 ? 4 * e * e * e : 1 - (-2 * e + 2) ** 3 / 2; } //#endregion //#region src/components/Map/booth-by-xy.ts var Z = [], Q = /* @__PURE__ */ new Map(), $ = null, Ot = []; function kt() { let e = re.booths.filter((e) => e.visible && e.rect && e.rect.size.width > 0 && e.rect.size.height > 0); if (Z = [], $ = null, Q = /* @__PURE__ */ new Map(), Ot = e.filter((e) => e.paths), !e.length) return; let t = [], n = Infinity, r = Infinity, a = -Infinity, o = -Infinity; for (let i of e) { let e = i.rotate ? new ne(i.rect.center, i.rect.size, i.rotate) : null, s = e ? e.bounds : i.rect; t.push({ booth: i, shape: e == null ? i.rect : e, bounds: s }), s.min.x < n && (n = s.min.x), s.min.y < r && (r = s.min.y), s.max.x > a && (a = s.max.x), s.max.y > o && (o = s.max.y); } let s = j.fromMinMax({ x: n, y: r }, { x: a, y: o }), c = Math.ceil(s.size.width / 2), l = Math.ceil(s.size.height / 2); for (let e = 0; e < 2; e++) for (let n = 0; n < 2; n++) { let r = new j(s.min.x + e * c, s.min.y + n * l, c, l); Z.push(r), Q.set(r, t.filter((e) => r.intersects(e.bounds))); } i.log("hover segmentToHitAreas", Q); } n(() => [ re.booths, E.loaded, E.visible ], () => kt()); function At(e, t) { let n = { x: e, y: t }, r; r = $ && $.containsPoint(n) ? $ : Z.find((e) => e.containsPoint(n)), r && ($ = r); let i = r ? Q.get(r) : void 0; if (i) { let e = i.filter((e) => e.booth.visible && e.shape.containsPoint(n)); if (e.length) return (e.length > 1 ? e.sort((e, t) => e.booth.rect.area - t.booth.rect.area)[0] : e[0]).booth; } for (let e of Ot) if (e.visible) for (let t of e.paths) for (let r of D(t.index, E.mode === I.Default ? "" : e.layer.name)) { let t = r.map((e) => ({ x: e[0], y: e[1] })); if (N.fromConvexRing(t).containsPoint(n)) return e; } return null; } function jt(e, t) { return At(e, t); } //#endregion export { lt as a, Be as c, Tt as i, Ve as l, St as n, et as o, wt as r, Ue as s, jt as t };