@expofp/floorplan
Version:
Interactive floor plan library for expos and events
1,148 lines (1,147 loc) • 34.2 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.39.1" };
var t = new e.Error().stack;
t && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[t] = "2625f088-ed85-4ae2-84e2-7c34c42fa851", e._sentryDebugIdIdentifier = "sentry-dbid-2625f088-ed85-4ae2-84e2-7c34c42fa851");
} catch {}
})();
import { r as e } from "./rolldown-runtime-BOCG9HEF.js";
import { j as t, v as n } from "./i18n-BVE2kS7w.js";
import { t as r } from "./react-CM7l092i.js";
import { t as i } from "./loadImage-B-6VhOfG.js";
import { r as a } from "./debug-context-CxXzVYRx.js";
import { $t as o, A as s, An as c, Ct as l, Dn as u, En as d, Fn as f, Ft as p, In as m, It as h, Kt as g, Mn as _, Nn as v, On as y, Ot as b, Pn as x, Pt as S, Qt as C, Ut as w, Xt as T, Yt as E, Zt as D, a as O, bt as k, c as A, en as j, in as M, jn as N, kt as P, l as F, on as ee, pn as I, qt as L, t as te, tn as R, vt as z, wn as B, wt as ne, x as re, xn as ie, z as V } from "./store-CARxK2Ft.js";
import { i as ae, n as oe } from "./viewport-CN0fRYhD.js";
//#region src/components/Map/traffic/trafficLayers.ts
var se = "traffic_route", ce = "traffic_route_stop", H = "traffic_vehicles", le = "build_route_lines", ue = "build_route_dots", de = 5;
function fe() {
let e = [];
for (let t = 0; t < de; t++) e.push({
name: pe(t),
children: []
}), e.push({
name: me(t),
children: []
});
return e.push({
name: H,
children: []
}), e.push({
name: le,
children: []
}), e.push({
name: ue,
children: []
}), e;
}
function pe(e) {
return `${se}_${e + 1}`;
}
function me(e) {
return `${ce}_${e + 1}`;
}
function he() {
return RegExp(`^${se}_\\d+$`);
}
function ge() {
return RegExp(`^${ce}_\\d+$`);
}
//#endregion
//#region src/components/Map/drawing/config/config-booth-badge-eligibility.ts
var _e = /* @__PURE__ */ e(u(), 1);
function ve(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 ye = .5, be = .3, xe = 15, Se = 24, Ce = 30, we = 12, Te = .8, Ee = document.createElement("canvas").getContext("2d");
function De(e) {
return e.length <= xe ? e : e.slice(0, xe - 1) + "…";
}
function Oe(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 ie(t.index, r)) i.push(e);
return i;
}
function ke(e) {
let t = Oe(e);
return t.length ? c.fromPoints(t.flat().map(([e, t]) => ({
x: e,
y: t
}))) : null;
}
function Ae(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 v(t, n);
}
function U(e, t, n) {
return n.containsPoint({
x: e,
y: t
});
}
function je(e, t, n, r, i, a, o, s) {
if (!e.length || !U(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;
[
f({
x: n + o,
y: r
}, s, c),
f({
x: n,
y: r + d
}, s, c),
f({
x: n + o,
y: r + d
}, s, c)
].every((e) => U(e.x, e.y, t)) ? l = e : u = e;
}
return l;
}
function Me(e) {
var t;
return (t = ke(e)) == null ? e.rect : t;
}
function Ne(e, t, n, r, i, a) {
var o;
if (t.length) {
let o = Me(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 (U(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 ? f({
x: s,
y: c
}, l, e.rect.center) : {
x: s,
y: c
};
}
function W(e) {
return e && e !== "none" ? e : void 0;
}
function Pe(e) {
var t;
let n = W(e.borderColor) || W(B.boothBorderColor) || B.colors.booths.default;
return ((t = e.paths) == null ? void 0 : t.length) > 1 && W(e.paths[e.paths.length - 1].color) || n;
}
function Fe(e) {
var t;
let r = De(e.title || e.name), i = Pe(e), a = re((0, _e.default)(i).hex()), o = l();
Ee.font = ee(Ce, o);
let s = Ee.measureText(r).width, c = Math.ceil(s + we * 2), u = (e.borderWidth || te.borderWidth) / 2, d = c * Te, m = 54 * Te, h = e.rect.size.width, g = e.rect.size.height, v = (e) => {
let t = e ? g : h, n = e ? h : g;
return Math.min(t > 0 ? t * ye / d : Infinity, n > 0 ? n * be / m : Infinity);
}, y = Oe(e), b = Ae(y), x = (t = e.rotate) == null ? 0 : t, O = 0, k = 0, A = 0, j = 0, M = () => {
let t = Ne(e, y, b, u, O === 0 || O === 3 ? 1 : -1, O === 0 || O === 1 ? 1 : -1);
k = t.x, A = t.y;
let n = v(O === 1 || O === 3);
j = je(y, b, k, A, d, m, n, x);
};
M();
let N = (t, n) => {
let r = t / 2, i = n / 2;
return new _(f({
x: k + r,
y: A + i
}, x, {
x: k,
y: A
}), {
x: t,
y: n
}, x, e.elevation);
}, P = ne(o, C()), I = E(N(1, 1), i);
I.hidden = !0, I.dim = e.skipDim ? 0 : void 0;
let L = T(D([[r], []], a, 0, [P, P]), N(1, 1), [0, 0], {
horizontal: "center",
vertical: "center"
});
L.hidden = !0, L.dim = e.skipDim ? 0 : void 0;
let R = {
booth: e,
anchor: {
x: k,
y: A
},
source: {
x: d,
y: m
},
rotation: x,
maxScale: j,
bg: I,
text: L
}, z = new Ie(R);
I.onScale = ({ pixelSize: e }) => z.layOutBg(e), L.onScale = ({ pixelSize: e }) => z.layOutText(e);
let B = [];
return B.push(n(() => e.skipDim, (e) => {
I.dim = e ? 0 : void 0, L.dim = e ? 0 : void 0, w(I, L);
})), B.push(n(() => {
var t, n;
return (t = (n = e.layer) == null ? void 0 : n.visible) == null || t;
}, (e) => {
I.hidden = !e, L.hidden = !e, w(I, L);
})), B.push(n(() => F.mapSettings, ({ roll: e }) => {
p(e == null ? 0 : e) && (I.onRoll = ({ roll: e, pixelSize: t }) => {
let n = S(e, x);
if (n !== 0) return x += n * Math.PI / 2, O = ((O + n) % 4 + 4) % 4, M(), R.anchor.x = k, R.anchor.y = A, R.rotation = x, R.maxScale = j, [...z.layOutBg(t), ...z.layOutText(t)];
});
}, { fireImmediately: !0 })), {
bg: I,
text: L,
dispose: () => {
B.forEach((e) => e()), B.length = 0;
}
};
}
var Ie = class {
constructor(e) {
this.placement = e;
}
layOutBg(e) {
let { bg: t } = this.placement;
return t.shape = this.rectScaled(e), t.hidden = this.isHidden(), t.hidden ? [] : [t];
}
layOutText(e) {
let { text: t, maxScale: n } = this.placement;
return t.lines[0].fontSize = Se * Math.min(e, n), t.bounds = this.rectScaled(e), t.hidden = this.isHidden(), t.hidden ? [] : [t];
}
rectScaled(e) {
let { anchor: t, booth: n, source: r, rotation: i, maxScale: a } = this.placement, o = Math.min(e, a), s = r.x * o, c = r.y * o;
return new _(f({
x: t.x + s / 2,
y: t.y + c / 2
}, i, t), {
x: s,
y: c
}, i, n.elevation);
}
isHidden() {
let { booth: e } = this.placement;
return !!(e.layer && !e.layer.visible);
}
};
function Le(e, t) {
let n = [], r = [], i = [];
for (let e of t) if (e instanceof I && ve({
hideExhibitorBoothNumber: d.hideExhibitorBoothNumber,
hideBoothBadges: d.hideBoothBadges,
hideLogoInBooth: F.hideLogoInBooth,
noLabels: e.noLabels,
hasExhibitors: e.exhibitors.length > 0,
hasLogoInBooth: e.exhibitors.some((e) => e.logoInBooth && e.logo)
})) {
let { bg: t, text: a, dispose: o } = Fe(e);
n.push(t), r.push(a), i.push(o);
}
let a = () => {
i.forEach((e) => e()), i.length = 0;
};
return n.length ? {
layer: {
name: `${e}:badges`,
children: [{
name: `${e}:badgeBgs`,
children: n
}, {
name: `${e}:badgeTexts`,
children: r
}]
},
cleanup: a
} : {
layer: null,
cleanup: a
};
}
//#endregion
//#region src/components/Map/drawing/config/config-markers.ts
var Re = "_selected", ze = "markers";
function Be(e, t) {
let { center: n, rotation: r, elevation: i } = e.bounds, { width: a, height: o } = e.source;
return e.bounds = j(n.x, n.y, a, o, t, r, i), [e];
}
function Ve(e) {
Ke = e;
}
function He(e) {
let { scene: t } = e, r = [], i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = [], s = t.rootLayer.children.find((e) => e.name === ze);
s.onScale = ({ pixelSize: e }) => Ve(e), b(Ue), w(s);
async function c(e) {
let t = [];
e.forEach((e) => {
let { name: n, content: r, width: a, height: o, scale: s } = e;
if (i.has(n)) return;
let c = new Image(), l = new Promise((e, t) => {
c.onload = () => {
i.set(n, {
img: c,
width: a,
height: o,
scale: s
}), e();
}, c.onerror = (e) => {
t(e);
};
});
t.push(l), c.src = r, c.crossOrigin = "anonymous";
}), await Promise.all(t);
}
let l = (e) => {
e.onScale = ({ pixelSize: t }) => Be(e, t);
}, u = (e) => {
e.screenSpace || (e.onRoll = ({ roll: t }) => {
if (t !== e.bounds.rotation) return e.bounds.rotate(t - e.bounds.rotation, e.bounds), [e];
});
};
function d(e, t, n) {
let r = a.get(e);
if (r) return r;
let i = M(t.img, t.width, t.height, n);
return a.set(e, i), i;
}
function f() {
let e = A.routeStore.markersData.markers;
if (!e.length) return;
o = [];
let t = F.is3DView;
e.forEach((e) => {
var n, r;
let a = i.get(e.icon);
if (!a) return;
let s = i.get(e.selectedIcon);
if (!s) return;
let c = a.scale || window.devicePixelRatio, l = d(e.icon, a, c), u = d(e.selectedIcon, s, c), f = (n = (r = O.findLayer(e.z)) == null ? void 0 : r.visible) == null || n, p = j(e.x, e.y, l.width, l.height, 1, 0), m = j(e.x, e.y, u.width, u.height, 1, 0), h;
switch (e.position) {
case "lefttop":
h = [0, 0];
break;
case "centertop":
h = [.5, 0];
break;
case "centerbottom":
h = [.5, 1];
break;
default: h = [.5, .5];
}
let _ = {
...g(l, p, {
hidden: !f,
origin: h
}),
id: e.id,
scale: c,
screenSpace: t
}, v = {
...g(u, m, {
hidden: !(f && e.active),
origin: h
}),
id: `${e.id}${Re}`,
scale: c,
screenSpace: t
};
o.push(_, v);
}), s.children = o, o.forEach((e) => {
l(e), u(e);
});
}
function p() {
s.children = [], o = [];
}
function m() {
let e = A.routeStore.markersData.markers;
e.length && e.forEach((e) => {
var t, n;
let r = o.find((t) => t.id === e.id), i = o.find((t) => t.id === `${e.id}${Re}`);
if (!r || !i) return;
let a = (t = (n = O.findLayer(e.z)) == null ? void 0 : n.visible) == null || t;
e.active ? (r.hidden = !0, i.hidden = !(a && e.active)) : (r.hidden = !a, i.hidden = !0);
});
}
return r.push(n(() => [A.routeStore.selectedMarkers, A.layerStore.visible], () => {
if (!A.routeStore.markersData.markers.length) {
p(), w(s);
return;
}
m(), w(...o);
})), r.push(n(() => A.routeStore.markersData.markers, () => {
c(A.routeStore.markersData.icons).then(() => {
f(), w(s);
});
}, { fireImmediately: !0 })), function() {
r.forEach((e) => e()), r.length = 0, s.onScale = void 0, b(), w(s);
};
}
function Ue(e, t) {
return We(e, t, Ke);
}
function We(e, t, n) {
for (let r of A.routeStore.markersData.markers) {
let i = A.routeStore.markersData.icons.find((e) => e.name === r.icon);
if (!i) continue;
let a = i.width * n * devicePixelRatio, o = i.height * n * devicePixelRatio;
if (Ge(e, t, r.x, r.y, a, o)) {
let e = A.layerStore.findLayer(r.z);
if (!e || e && e.visible) return r;
}
}
return null;
}
function Ge(e, t, n, r, i, a) {
return c.fromCenter({
x: n,
y: r
}, {
x: 2 * i,
y: 2 * a
}).containsPoint({
x: e,
y: t
});
}
var Ke = 1;
//#endregion
//#region src/components/Map/drawing/config/config-all.ts
function qe() {
let { defaultLayer: e } = A.layerStore, { layers: t } = A.layerStore;
if (e) {
let n = [...t], r = t.indexOf(e);
n.splice(r, 1), t = [e, ...n];
}
let n = t.filter((e) => !e.rootParent).map((e) => k(e));
return Promise.all(n).then((e) => {
let t = L(ze, []);
t.overlay = F.is3DView;
let n = s({ overlay: F.is3DView }), r = [], i = [];
for (let t of e.flat()) R(t.name) ? (t.dim = 0, i.push(t)) : r.push(t);
let { layer: a, cleanup: o } = Le("root", te.booths);
return {
layers: [
...r,
...a ? [a] : [],
...i,
...fe(),
t,
n
],
cleanup: o
};
});
}
//#endregion
//#region src/components/Map/MapCursorCoords.tsx
var G = /* @__PURE__ */ e(r(), 1), Je = 2;
function Ye(e) {
let { canvas: t } = e, n = h(), r = a(), i = (0, G.useCallback)(() => r("cursor", void 0), [r]), o = (0, G.useEffectEvent)((e) => {
if (!e.isPrimary) return;
let t = n.canvasToPlan({
x: e.offsetX,
y: e.offsetY
});
r("cursor", t ? Ze(t, Xe()) : void 0);
});
return (0, G.useEffect)(() => {
let e = t.current;
if (!e) return;
let n = (e) => o(e), r = () => i();
return e.addEventListener("pointermove", n), e.addEventListener("pointerleave", r), () => {
e.removeEventListener("pointermove", n), e.removeEventListener("pointerleave", r);
};
}, [t, i]), null;
}
function Xe() {
let e = A.layerStore.layers.find((e) => e.visible && (e.mode === z.TurnedOn || e.mode === z.TurnedOff));
return (e == null ? void 0 : e.name) || null;
}
function Ze(e, t) {
let n = `[${e.x.toFixed(Je)}, ${e.y.toFixed(Je)}]`;
return t ? `${n} · layer ${t}` : n;
}
//#endregion
//#region src/components/Map/MapViewport.tsx
function Qe() {
let e = h(), t = (0, G.useRef)({ api: e }), [n] = (0, G.useState)(() => oe(t));
return (0, G.useLayoutEffect)(() => {
t.current = { api: e };
}), (0, G.useEffect)(() => (ae(n), () => ae(void 0)), [n]), null;
}
//#endregion
//#region src/components/Map/traffic/UpdateQueue.ts
var $e = 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;
}
}, K = 49, et = `hsl(257, 76%, ${K}%)`, tt = `hsl(339.903, 82%, ${K}%)`, nt = `hsl(257, 76%, ${Math.round(K * 1.82)}%)`, q = 4, rt = q, it = "U", at = "R", ot = "S", st = "P", ct = 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 ${at}.
Apply Simplification: Press ${ot}.
Undo: Press ${it}.
Enable/Disable Preview: Press ${st}.
`, 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 = N({
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 lt({ enabled: e, scene: t }) {
let n = (0, G.useRef)(!1), r = (0, G.useRef)(), i = (0, G.useMemo)(() => o(q, et), []), a = (0, G.useMemo)(() => o(q, tt), []), s = (0, G.useMemo)(() => new ct(), []), c = (0, G.useRef)(new $e()), l = (0, G.useMemo)(() => {
if (!t) return {};
let e = t.rootLayer.children;
return {
linesLayer: e.find((e) => e.name === le),
pointsLayer: e.find((e) => e.name === ue)
};
}, [t]), u = (0, G.useCallback)(() => {
if (!l || !i || !a) return;
let { linesLayer: e, pointsLayer: t } = l;
if (!e || !t) return;
let o = s.points, u = n.current;
u ? t.children.length = 0 : t.children = o.map(({ x: e, y: t }, n) => {
let o = n == s.selected ? a : i;
return {
source: o,
bounds: j(e, t, o.width, o.height, r.current)
};
});
let d = [];
for (let e = 1; e < o.length; e++) {
let t = o[e - 1], n = o[e];
d.push({
points: {
p0: t,
p1: n
},
color: u ? et : nt,
width: rt
});
}
d.length ? e.children = d : e.children.length = 0, c.current.add(() => w(t, e)), s.instruct(), s.log(JSON.stringify(s.points));
}, [
s,
l,
i,
a
]), d = (0, G.useCallback)((e) => {
let t = e.key.toUpperCase();
s.execute(() => {
switch (t) {
case it:
e.preventDefault(), s.undo(), n.current = !1, u();
break;
case at:
e.preventDefault(), s.applySmoothing(), n.current = !1, u();
break;
case ot:
e.preventDefault(), s.applySimplification(), n.current = !1, u();
break;
case st:
e.preventDefault(), n.current = !n.current, u();
break;
}
});
}, [s, u]), f = (0, G.useCallback)((e) => {
r.current = e;
let { pointsLayer: t } = l;
if (!t) return [];
let n = [];
return s.execute(() => {
let e = t.children;
for (let t of e) t.bounds = j(t.bounds.center.x, t.bounds.center.y, t.source.width, t.source.height, r.current), n.push(t);
}), n;
}, [l, s]), p = (0, G.useCallback)((e) => {
s.execute(() => {
s.add({
x: e.x,
y: e.y
}), s.select(s.points.length - 1), u();
});
}, [s, u]);
(0, G.useEffect)(() => {
var t, n;
if (!e || !(l != null && l.pointsLayer)) return;
let { pointsLayer: i } = l;
return r.current = (t = (n = V()) == null ? void 0 : n.state().pixelSize) == null ? 1 : t, s.execute(() => {
s.restore(), u();
}), i.onScale = ({ pixelSize: e }) => f(e), c.current.add(() => w(i)), P(p), window.addEventListener("keyup", d), () => {
window.removeEventListener("keyup", d), P(), i.onScale = void 0, c.current.destroy();
};
}, [
e,
l,
s,
u,
p,
f,
d
]);
}
//#endregion
//#region src/components/Map/traffic/useManageTraffic.ts
var J = 2, ut = J * 3.5, Y = J * 12, dt = Y * .7, ft = 8, pt = "transport_locations", mt = 150, ht = "#a4aab6", gt = 1e3, _t = 2e4, vt = 500;
function yt({ permission: e, scene: n, dataJsonUrl: r, websocketUrl: a }) {
let o = (0, G.useRef)(window.devicePixelRatio), s = (0, G.useRef)(/* @__PURE__ */ new Map()), c = (0, G.useRef)(/* @__PURE__ */ new Map()), l = (0, G.useRef)(null), u = (0, G.useRef)(null), d = (0, G.useRef)(0), f = (0, G.useRef)(1), p = (0, G.useRef)(new $e()), m = (0, G.useRef)(/* @__PURE__ */ new Map()), h = (0, G.useRef)(gt), g = (0, G.useRef)(/* @__PURE__ */ new Map()), _ = (0, G.useRef)(void 0);
(0, G.useEffect)(() => {
if (!e || !n) return;
let v = !1, y, b = n.rootLayer.children, x = c.current, S = s.current, C = p.current;
async function T() {
try {
var e, n;
let a;
try {
let e = await fetch(r, {
method: "GET",
headers: { "Content-Type": "application/json" }
});
if (!e.ok || e.status === 204) return;
a = await e.json();
} catch (e) {
console.warn("useManageTraffic failed to get JSON", e);
}
if (!a || a.disabled || a.error) return;
o.current = bt((e = (n = V()) == null ? void 0 : n.state().pixelSize) == null ? window.devicePixelRatio : e);
let c = new Map(a.routes.map(({ id: e, color: t }) => [e, t])), l = /* @__PURE__ */ new Map();
c.forEach((e) => {
l.set(e, St({
radius: ut,
color: e,
scale: window.devicePixelRatio
}));
});
let p = he(), h = b.filter((e) => p.test(e.name)), _ = ge(), v = b.filter((e) => _.test(e.name));
a.routes.slice(0, h.length).forEach(({ id: e, color: t, path: n, stops: r, hiddenPoints: i }, a) => {
m.current.set(e, n);
let s = h[a];
if (s) {
var c;
let e = new Map((c = i == null ? void 0 : i.map((e) => [$(e), e])) == null ? [] : c);
for (let r = 1; r < n.length; r++) {
let i = n[r - 1], a = n[r];
e.has($(i)) || e.has($(a)) || s.children.push({
points: {
p0: i,
p1: a
},
color: t,
width: J
});
}
s.children.length && C.add(() => w(s));
}
let u = v[a], d = l.get(t);
u && d && r != null && r.length && (r.forEach((e) => {
u.children.push({
source: d,
bounds: j(e.x, e.y, d.width, d.height, o.current)
});
}), u.children.length && C.add(() => w(u)));
});
let y = b.find((e) => e.name === H);
if (!y) {
console.warn(`useManageTraffic: the scene has no "${H}" layer`);
return;
}
let T = /* @__PURE__ */ new Map();
y.onScale = ({ pixelSize: e }) => {
o.current = bt(e);
let t = [];
for (let e of v) {
let n = e.children;
for (let e of n) {
let n = e.source;
e.bounds = j(e.bounds.center.x, e.bounds.center.y, n.width, n.height, o.current, e.bounds.rotation), t.push(e);
}
}
for (let e of s.current.values()) {
let n = e.source;
e.bounds = j(e.bounds.center.x, e.bounds.center.y, n.width, n.height, o.current, e.bounds.rotation), t.push(e);
}
return t;
}, C.add(() => w(y)), c.forEach((e, t) => {
T.set(t, Ct({
id: t,
width: Y,
height: Y,
color: e,
scale: window.devicePixelRatio
}));
});
let k = Ct({
id: "orphan",
width: Y,
height: Y,
color: ht,
scale: window.devicePixelRatio
}), A = null;
try {
A = M(await i(`${t}icons/bus-white.svg`), dt, dt, window.devicePixelRatio);
} catch (e) {
console.error(e);
}
u.current = (e) => {
try {
var t;
let n = JSON.parse(e.data);
if (n.type !== pt) return;
let r = e.timeStamp || performance.now();
f.current = Math.round(r - d.current), d.current = r;
let i = Math.max((t = f.current) == null ? vt : t, vt), a = y.children, s = !1;
n.data.forEach(({ id: e, x: t, y: n, route_id: r, hidden: c }) => {
var l;
if (x.has(e)) {
var u;
(u = x.get(e)) == null || u(), x.delete(e);
}
let d = S.get(e), f = (l = S.get(Z(e))) == null ? null : l;
if (c && d && f) {
d.hidden = !0, f.hidden = !0, C.add(() => w(d, f));
return;
}
if (g.current.set(e, performance.now()), !d) {
var p;
let i = (p = T.get(r)) == null ? k : p, c = {
source: i,
bounds: j(t, n, i.width, i.height, o.current, 0)
};
if (S.set(e, c), A) {
let r = Z(e), i = {
source: A,
bounds: j(t, n, A.width, A.height, o.current, 0)
};
A.setAttribute("id", r), S.set(r, i), a.push(c, i);
} else a.push(c);
s = !0;
return;
}
let h = d.bounds.center, _ = Dt(h, {
x: t,
y: n
}, m.current.get(r));
if (_.reduce((e, t, n) => n === 0 ? e : e + X(_[n - 1], t), 0) >= mt || document.hidden) wt({
updateQueue: C,
vehicle: d,
vehicleFinery: f,
x: t,
y: n,
scale: o.current,
angle: xt(d.bounds.center, {
x: t,
y: n
})
});
else {
let t = Ot(_, i, (e) => {
wt({
updateQueue: C,
vehicle: d,
vehicleFinery: f,
x: e.x,
y: e.y,
scale: o.current,
angle: e.angle
});
});
x.set(e, t);
}
}), s && C.add(() => w(y));
} catch (e) {
console.error("handleSocketMessage", e);
}
}, d.current = performance.now(), E(), window.addEventListener("online", D), O(a.config ? (Number(a.config.vehicle_inactive_interval) || 20) * 1e3 : _t);
} catch (e) {
console.warn(e);
}
}
T();
function E() {
var e, t;
v || ((e = l.current) == null ? void 0 : e.readyState) === WebSocket.OPEN || ((t = l.current) == null ? void 0 : t.readyState) === WebSocket.CONNECTING || (l.current = new WebSocket(a), l.current.onmessage = u.current, l.current.onopen = () => {
h.current = gt;
}, l.current.onclose = () => {
v || !navigator.onLine || (y = window.setTimeout(E, h.current), h.current = Math.min(h.current * 2, 3e4));
});
}
function D() {
E();
}
function O(e) {
clearInterval(_.current), _.current = window.setInterval(() => {
let t = performance.now(), n = [], r = [];
g.current.forEach((i, a) => {
if (t - i < e) return;
let o = S.get(a);
o && (o.hidden = !0, r.push(o), n.push(a));
let s = Z(a), c = S.get(s);
c && (c.hidden = !0, r.push(c), n.push(s));
}), r.length && C.add(() => w(...r)), n.forEach((e) => g.current.delete(e));
}, e);
}
return () => {
var e;
v = !0, clearTimeout(y), (e = l.current) == null || e.close(), l.current = null;
let t = b.find((e) => e.name === H);
t && (t.onScale = void 0), x.forEach((e) => e == null ? void 0 : e()), x.clear(), S.clear(), C.destroy(), window.removeEventListener("online", D), clearInterval(_.current);
};
}, [
e,
n,
r,
a
]);
}
function bt(e) {
return Math.min(e || window.devicePixelRatio, ft);
}
function xt(e, t) {
return y(e, t);
}
function St({ 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 Ct({ 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 X(e, t) {
return x(e, t);
}
function Z(e) {
return `${e}_finery`;
}
function wt({ updateQueue: e, vehicle: t, vehicleFinery: n, x: r, y: i, scale: a, angle: o }) {
let s = t.source;
if (t.bounds = j(r, i, s.width, s.height, a, o), t.hidden = !1, n) {
var c, l;
let o = (c = (l = V()) == null ? void 0 : l.state().roll) == null ? 0 : c, s = n.source;
n.bounds = j(r, i, s.width, s.height, a, m(o)), n.hidden = !1, e.add(() => w(n, t));
} else e.add(() => w(t));
}
function Q(e, t, n) {
return {
x: e.x + (t.x - e.x) * n,
y: e.y + (t.y - e.y) * n
};
}
function Tt(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 = X(e, Q(a, o, d));
f < n && (n = f, r = {
index: i,
t: d
});
}
return r;
}
function Et(e, t, n) {
let r = X(e, t), i = Math.max(2, Math.ceil(r / n) + 1), a = [];
for (let n = 0; n < i; n++) {
let r = Q(e, t, n / (i - 1));
a.push(r);
}
return a;
}
function Dt(e, t, n) {
if (!n || !n.length) return Et(e, t, 10);
let r = Tt(e, n), i = Tt(t, n), a = [], o = (e) => a.push(e);
r.index + 1 < n.length ? o(Q(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(Q(n[i.index], n[i.index + 1], i.t)) : o(n[i.index]), a;
}
function Ot(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 = x(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: y(h, g)
}), d < 1 ? a = requestAnimationFrame(c) : r && r();
};
return a = requestAnimationFrame(c), () => {
a && cancelAnimationFrame(a);
};
}
function $(e) {
return `${e.x},${e.y}`;
}
//#endregion
//#region src/utils/dimming.ts
var kt = .5, At = "cubic";
function jt(e, t) {
return !e || e.rootLayer.dim === t ? !1 : (e.rootLayer.dim = t, !0);
}
function Mt(e, t = 300, n = At) {
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 = Nt(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 Nt(e, t) {
return t === "linear" ? e : Pt(e);
}
function Pt(e) {
return e < .5 ? 4 * e * e * e : 1 - (-2 * e + 2) ** 3 / 2;
}
//#endregion
export { lt as a, qe as c, yt as i, He as l, jt as n, Qe as o, Mt as r, Ye as s, kt as t };