@loafacto/ui 0.16.4 → 0.18.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.
package/dist/map3d.js ADDED
@@ -0,0 +1,1173 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ import { defineComponent, ref, shallowRef, computed, onMounted, onBeforeUnmount, watch, openBlock, createElementBlock, createElementVNode, createBlock, createCommentVNode, createVNode } from "vue";
5
+ import { f as LfSelect, e as LfSegmented, c as LfIconButton, _ as _export_sfc } from "./LfSegmented-C35GdK7N.js";
6
+ import { WebGLRenderer, LinearSRGBColorSpace, PCFSoftShadowMap, Vector3, Scene, OrthographicCamera, PerspectiveCamera, HemisphereLight, DirectionalLight, Group, MeshBasicMaterial, LineBasicMaterial, MeshStandardMaterial, DoubleSide, RingGeometry, MOUSE, TOUCH, Box3, LineSegments, LineLoop, Mesh, BoxGeometry, EdgesGeometry, BufferGeometry, Float32BufferAttribute, Vector2, Shape, ShapeGeometry, Raycaster, Color } from "three";
7
+ import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
8
+ import { mergeGeometries } from "three/examples/jsm/utils/BufferGeometryUtils.js";
9
+ function parseColor(value) {
10
+ const v = value.trim();
11
+ const hex = /^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(v);
12
+ if (hex) {
13
+ let h = hex[1];
14
+ if (h.length === 3) h = [...h].map((c) => c + c).join("");
15
+ return { r: parseInt(h.slice(0, 2), 16), g: parseInt(h.slice(2, 4), 16), b: parseInt(h.slice(4, 6), 16), a: h.length === 8 ? parseInt(h.slice(6), 16) / 255 : 1 };
16
+ }
17
+ const fn = /^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)\s*(?:[/,]\s*([\d.]+)(%?)\s*)?\)$/i.exec(v);
18
+ if (fn) {
19
+ let a = fn[4] === void 0 ? 1 : Number(fn[4]);
20
+ if (fn[5] === "%") a /= 100;
21
+ const c = (x) => Math.max(0, Math.min(255, Math.round(Number(x))));
22
+ return { r: c(fn[1]), g: c(fn[2]), b: c(fn[3]), a: Math.max(0, Math.min(1, a)) };
23
+ }
24
+ return null;
25
+ }
26
+ const toHex = (c) => c.r << 16 | c.g << 8 | c.b;
27
+ function over(c, bg) {
28
+ return { r: Math.round(c.r * c.a + bg.r * (1 - c.a)), g: Math.round(c.g * c.a + bg.g * (1 - c.a)), b: Math.round(c.b * c.a + bg.b * (1 - c.a)), a: 1 };
29
+ }
30
+ function mix(a, b, k) {
31
+ const ch = (c, s) => c >> s & 255;
32
+ const m = (s) => Math.round(ch(a, s) + (ch(b, s) - ch(a, s)) * k) << s;
33
+ return m(16) | m(8) | m(0);
34
+ }
35
+ const luminance = (c) => (0.2126 * (c >> 16 & 255) + 0.7152 * (c >> 8 & 255) + 0.0722 * (c & 255)) / 255;
36
+ function readMapTheme(el = document.documentElement) {
37
+ const style = getComputedStyle(el);
38
+ const raw = (name) => parseColor(style.getPropertyValue(name));
39
+ const bgC = raw("--map3d-bg") ?? raw("--admin-bg-color") ?? { r: 248, g: 250, b: 252 };
40
+ const bg = toHex(bgC);
41
+ const dark = luminance(bg) < 0.45;
42
+ const tok = (names, fallback) => {
43
+ for (const n of names) {
44
+ const c = raw(n);
45
+ if (c) return toHex(over(c, bgC));
46
+ }
47
+ return fallback;
48
+ };
49
+ const text = tok(["--admin-text-body"], dark ? 15067115 : 2042167);
50
+ const accent = tok(["--admin-accent"], 292951);
51
+ const status = (name, fallback) => tok([`--admin-status-${name}`], fallback);
52
+ return {
53
+ dark,
54
+ bg,
55
+ // 바닥판은 바탕보다 한 톤 떠 있게 — 라이트는 조금 어둡게, 다크는 조금 밝게
56
+ floor: tok(["--map3d-floor"], mix(bg, dark ? 16777215 : 6583435, dark ? 0.07 : 0.1)),
57
+ grid: tok(["--map3d-grid"], mix(bg, text, dark ? 0.14 : 0.12)),
58
+ lane: tok(["--map3d-lane"], status("warning", 16096779)),
59
+ wall: tok(["--map3d-wall"], mix(bg, text, dark ? 0.35 : 0.3)),
60
+ object: tok(["--map3d-object"], mix(bg, dark ? 13358561 : 14870768, dark ? 0.55 : 0.9)),
61
+ select: tok(["--map3d-select"], accent),
62
+ edge: tok(["--map3d-edge"], dark ? 132631 : 3359061),
63
+ tones: {
64
+ neutral: status("neutral", 10265519),
65
+ info: status("info", 3900150),
66
+ success: status("success", 1096065),
67
+ warning: status("warning", 16096779),
68
+ error: status("error", 15680580),
69
+ accent,
70
+ purple: status("purple", 11032055),
71
+ teal: status("teal", 1357990)
72
+ }
73
+ };
74
+ }
75
+ function colorOf(theme, item, fallback) {
76
+ const c = item.color ? parseColor(item.color) : null;
77
+ if (c) return toHex(c);
78
+ return item.tone ? theme.tones[item.tone] : fallback;
79
+ }
80
+ const ISO_ELEVATION = Math.asin(1 / Math.sqrt(3));
81
+ const UP = new Vector3(0, 1, 0);
82
+ const SLAB = 0.14;
83
+ const WALL_CUT = 0.5;
84
+ const MOVER_SIZE = { w: 0.9, h: 0.7, height: 0.45 };
85
+ const dirFrom = (az, el) => new Vector3(Math.cos(el) * Math.sin(az), Math.sin(el), Math.cos(el) * Math.cos(az));
86
+ const ease = (k) => k < 0.5 ? 4 * k * k * k : 1 - Math.pow(-2 * k + 2, 3) / 2;
87
+ const toWorld = (x, y, elevation = 0) => new Vector3(x, elevation, -y);
88
+ const col = (hex) => new Color().setHex(hex, LinearSRGBColorSpace);
89
+ function strip(out, ax, az, bx, bz, half, y) {
90
+ const len = Math.hypot(bx - ax, bz - az);
91
+ if (len < 1e-3) return;
92
+ const nx = -(bz - az) / len * half;
93
+ const nz = (bx - ax) / len * half;
94
+ const q = [[ax + nx, az + nz], [ax - nx, az - nz], [bx - nx, bz - nz], [bx + nx, bz + nz]];
95
+ for (const i of [0, 1, 2, 0, 2, 3]) out.push(q[i][0], y, q[i][1]);
96
+ }
97
+ function arrowHead(out, cx, cz, ux, uz, y) {
98
+ const half = 0.35;
99
+ const w = 0.28;
100
+ const pts = [[cx + ux * half, cz + uz * half], [cx - ux * half - uz * w, cz - uz * half + ux * w], [cx - ux * half + uz * w, cz - uz * half - ux * w]];
101
+ for (const p of pts) out.push(p[0], y, p[1]);
102
+ }
103
+ function flat(points) {
104
+ const g = new BufferGeometry();
105
+ g.setAttribute("position", new Float32BufferAttribute(points, 3));
106
+ g.computeVertexNormals();
107
+ return g;
108
+ }
109
+ function pickHolder(o) {
110
+ for (let p = o; p; p = p.parent) if (p.userData.pick) return p;
111
+ return null;
112
+ }
113
+ function visible(o) {
114
+ for (let p = o; p; p = p.parent) if (!p.visible) return false;
115
+ return true;
116
+ }
117
+ class MapScene {
118
+ constructor(canvas, labelLayer, theme, opts = {}) {
119
+ __publicField(this, "scene", new Scene());
120
+ __publicField(this, "ortho", new OrthographicCamera(-1, 1, 1, -1, 0.1, 2e3));
121
+ __publicField(this, "persp", new PerspectiveCamera(38, 1, 0.1, 2e3));
122
+ /** 눌러 고른 것(빈 곳이면 null) · 누른 화면 좌표 */
123
+ __publicField(this, "onPick", () => void 0);
124
+ /** 끌어 카메라를 가져가 따라가기가 끝났다 */
125
+ __publicField(this, "onUnfollow", () => void 0);
126
+ __publicField(this, "labelMode");
127
+ __publicField(this, "renderer");
128
+ __publicField(this, "controls");
129
+ __publicField(this, "cam", this.ortho);
130
+ __publicField(this, "mode", "iso");
131
+ __publicField(this, "hemi", new HemisphereLight("#ffffff", "#8b9299", 1));
132
+ __publicField(this, "sun", new DirectionalLight("#ffffff", 1));
133
+ __publicField(this, "root", new Group());
134
+ __publicField(this, "routeGroup", new Group());
135
+ __publicField(this, "moverGroup", new Group());
136
+ __publicField(this, "floors", /* @__PURE__ */ new Map());
137
+ __publicField(this, "zones", /* @__PURE__ */ new Map());
138
+ __publicField(this, "objects", /* @__PURE__ */ new Map());
139
+ __publicField(this, "movers", /* @__PURE__ */ new Map());
140
+ __publicField(this, "owned", []);
141
+ __publicField(this, "routeOwned", []);
142
+ __publicField(this, "doc", null);
143
+ __publicField(this, "routes", []);
144
+ __publicField(this, "shownFloor", null);
145
+ __publicField(this, "selected", null);
146
+ __publicField(this, "selectMark", null);
147
+ __publicField(this, "follow", null);
148
+ __publicField(this, "grid", true);
149
+ __publicField(this, "theme");
150
+ __publicField(this, "tween", null);
151
+ __publicField(this, "viewH", 50);
152
+ __publicField(this, "raf", 0);
153
+ __publicField(this, "clock", performance.now());
154
+ __publicField(this, "wheelAt", 0);
155
+ __publicField(this, "down", null);
156
+ __publicField(this, "pointer", null);
157
+ __publicField(this, "hovered", null);
158
+ __publicField(this, "hoverFrame", 0);
159
+ __publicField(this, "hoverTag");
160
+ __publicField(this, "reduce", typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches);
161
+ __publicField(this, "mats", {
162
+ floor: new MeshStandardMaterial({ roughness: 0.95, metalness: 0 }),
163
+ grid: new LineBasicMaterial({ transparent: true }),
164
+ lane: new MeshBasicMaterial({ side: DoubleSide }),
165
+ wall: new MeshStandardMaterial({ roughness: 0.8, metalness: 0 }),
166
+ edge: new LineBasicMaterial({ transparent: true, opacity: 0.3 }),
167
+ select: new LineBasicMaterial({ depthTest: false, transparent: true }),
168
+ ring: new MeshBasicMaterial({ side: DoubleSide, transparent: true, opacity: 0.9, depthWrite: false })
169
+ });
170
+ __publicField(this, "objectMats", /* @__PURE__ */ new Map());
171
+ __publicField(this, "ringGeo", new RingGeometry(0.62, 0.78, 40).rotateX(-Math.PI / 2));
172
+ // --- 고르기 ---------------------------------------------------------------------------------------------------------
173
+ __publicField(this, "onWheel", () => {
174
+ this.wheelAt = performance.now();
175
+ });
176
+ __publicField(this, "onDown", (e) => {
177
+ this.down = new Vector2(e.clientX, e.clientY);
178
+ });
179
+ __publicField(this, "onUp", (e) => {
180
+ if (!this.down || this.down.distanceTo(new Vector2(e.clientX, e.clientY)) > 5) return;
181
+ this.down = null;
182
+ this.onPick(this.pickAt(e.clientX, e.clientY), { x: e.clientX, y: e.clientY });
183
+ });
184
+ __publicField(this, "onMove", (e) => {
185
+ this.pointer = e.buttons ? null : { x: e.clientX, y: e.clientY };
186
+ });
187
+ __publicField(this, "onLeave", () => {
188
+ this.pointer = null;
189
+ });
190
+ __publicField(this, "loop", () => {
191
+ this.raf = requestAnimationFrame(this.loop);
192
+ const now = performance.now();
193
+ const dt = Math.min(0.1, (now - this.clock) / 1e3);
194
+ this.clock = now;
195
+ this.stepMovers(dt);
196
+ if (this.tween) this.tween(now);
197
+ else {
198
+ if (this.follow) {
199
+ const m = this.movers.get(this.follow);
200
+ if (m) {
201
+ const delta = m.at.clone().setY(m.at.y + m.height / 2).sub(this.controls.target);
202
+ this.controls.target.add(delta);
203
+ this.cam.position.add(delta);
204
+ }
205
+ }
206
+ this.controls.update();
207
+ }
208
+ this.renderer.render(this.scene, this.cam);
209
+ this.updateHover();
210
+ this.updateLabels();
211
+ });
212
+ this.canvas = canvas;
213
+ this.labelLayer = labelLayer;
214
+ this.theme = theme;
215
+ this.labelMode = opts.labels ?? "auto";
216
+ this.renderer = new WebGLRenderer({ canvas, antialias: true, alpha: true, powerPreference: "high-performance" });
217
+ this.renderer.outputColorSpace = LinearSRGBColorSpace;
218
+ this.renderer.shadowMap.enabled = true;
219
+ this.renderer.shadowMap.type = PCFSoftShadowMap;
220
+ this.renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 1.5));
221
+ this.sun.castShadow = true;
222
+ this.sun.shadow.mapSize.set(2048, 2048);
223
+ this.sun.shadow.bias = -5e-4;
224
+ this.sun.shadow.normalBias = 0.02;
225
+ this.scene.add(this.root, this.routeGroup, this.moverGroup, this.hemi, this.sun, this.sun.target);
226
+ this.hoverTag = document.createElement("div");
227
+ this.hoverTag.className = "lf-map3d__tag lf-map3d__tag--hover";
228
+ this.hoverTag.hidden = true;
229
+ labelLayer.appendChild(this.hoverTag);
230
+ this.setupControls(new Vector3());
231
+ canvas.addEventListener("pointerdown", this.onDown);
232
+ canvas.addEventListener("pointerup", this.onUp);
233
+ canvas.addEventListener("pointermove", this.onMove);
234
+ canvas.addEventListener("pointerleave", this.onLeave);
235
+ canvas.addEventListener("wheel", this.onWheel, { capture: true, passive: true });
236
+ this.setTheme(theme);
237
+ this.resize();
238
+ this.loop();
239
+ }
240
+ // --- 데이터 ------------------------------------------------------------------------------------------------------
241
+ /** 레이아웃을 새로 그린다. keepView 면 카메라를 그대로 둔다(같은 맵을 고쳐 다시 줄 때). */
242
+ setDoc(doc, keepView = false) {
243
+ this.clearSite();
244
+ this.doc = doc;
245
+ for (const f of doc.floors) this.buildFloor(f);
246
+ if (this.shownFloor && !this.floors.has(this.shownFloor)) this.shownFloor = null;
247
+ this.applyFloors();
248
+ this.drawRoutes();
249
+ for (const m of this.movers.values()) this.placeMover(m, true);
250
+ if (!keepView) this.overview(true);
251
+ else this.fitFrustum();
252
+ if (this.selected) this.select(this.selected);
253
+ }
254
+ /** 표식을 바꾼다 — 같은 id 는 새 자리로 옮겨 가고, 빠진 id 는 지운다. */
255
+ setMovers(list) {
256
+ const seen = /* @__PURE__ */ new Set();
257
+ for (const m of list) {
258
+ seen.add(m.id);
259
+ const v = this.movers.get(m.id);
260
+ if (v) {
261
+ const sizeChanged = JSON.stringify(v.mover.size ?? null) !== JSON.stringify(m.size ?? null);
262
+ v.mover = m;
263
+ if (sizeChanged) this.shapeMover(v);
264
+ this.paintMover(v);
265
+ v.tag.textContent = m.label ?? m.id;
266
+ } else {
267
+ this.movers.set(m.id, this.makeMover(m));
268
+ }
269
+ }
270
+ for (const [id, v] of this.movers) {
271
+ if (seen.has(id)) continue;
272
+ this.moverGroup.remove(v.group);
273
+ v.body.geometry.dispose();
274
+ v.body.material.dispose();
275
+ v.stripe.geometry.dispose();
276
+ v.stripe.material.dispose();
277
+ v.tag.remove();
278
+ this.movers.delete(id);
279
+ if (this.selected === id) this.select(null);
280
+ }
281
+ }
282
+ setRoutes(list) {
283
+ this.routes = list;
284
+ this.drawRoutes();
285
+ }
286
+ // --- 카메라 -------------------------------------------------------------------------------------------------------
287
+ get viewMode() {
288
+ return this.mode;
289
+ }
290
+ setupControls(target) {
291
+ var _a;
292
+ (_a = this.controls) == null ? void 0 : _a.dispose();
293
+ const c = new OrbitControls(this.cam, this.canvas);
294
+ c.target.copy(target);
295
+ c.enableDamping = true;
296
+ c.dampingFactor = 0.12;
297
+ c.screenSpacePanning = false;
298
+ if (this.mode === "iso") {
299
+ c.enableRotate = false;
300
+ c.mouseButtons = { LEFT: MOUSE.PAN, MIDDLE: MOUSE.DOLLY, RIGHT: MOUSE.PAN };
301
+ c.touches = { ONE: TOUCH.PAN, TWO: TOUCH.DOLLY_PAN };
302
+ c.minZoom = 0.5;
303
+ c.maxZoom = Math.max(4, this.viewH / 3);
304
+ } else {
305
+ c.enableRotate = true;
306
+ c.mouseButtons = { LEFT: MOUSE.ROTATE, MIDDLE: MOUSE.DOLLY, RIGHT: MOUSE.PAN };
307
+ c.touches = { ONE: TOUCH.ROTATE, TWO: TOUCH.DOLLY_PAN };
308
+ c.minDistance = 2.5;
309
+ c.maxDistance = this.viewH * 3;
310
+ c.maxPolarAngle = 1.42;
311
+ }
312
+ c.addEventListener("start", () => {
313
+ if (performance.now() - this.wheelAt < 80) return;
314
+ if (this.follow) this.onUnfollow();
315
+ this.follow = null;
316
+ this.tween = null;
317
+ });
318
+ c.update();
319
+ this.controls = c;
320
+ }
321
+ /** 보이는 층(없으면 전부)의 범위 */
322
+ box() {
323
+ const b = new Box3();
324
+ for (const [id, f] of this.floors) {
325
+ if (this.shownFloor && id !== this.shownFloor) continue;
326
+ b.expandByPoint(toWorld(-0.5, -0.5, f.elevation - SLAB));
327
+ b.expandByPoint(toWorld(f.floor.size.w + 0.5, f.floor.size.h + 0.5, f.elevation + 1));
328
+ }
329
+ if (b.isEmpty()) b.set(new Vector3(-10, 0, -10), new Vector3(10, 1, 10));
330
+ return b;
331
+ }
332
+ /** 정투영 시야를 확대 1 에서 보이는 층 전체가 들어오게 맞춘다(지금 방위 그대로). */
333
+ fitFrustum() {
334
+ const { min, max } = this.box();
335
+ const centre = min.clone().add(max).multiplyScalar(0.5);
336
+ const off = this.ortho.position.clone().sub(this.controls.target);
337
+ const probe = this.ortho.clone();
338
+ probe.position.copy(centre).add(off.lengthSq() > 1e-6 ? off : dirFrom(Math.PI / 4, ISO_ELEVATION));
339
+ probe.lookAt(centre);
340
+ probe.updateMatrixWorld(true);
341
+ const inv = probe.matrixWorldInverse;
342
+ let hx = 0;
343
+ let hy = 0;
344
+ for (const x of [min.x, max.x]) for (const y of [min.y, max.y]) for (const z of [min.z, max.z]) {
345
+ const p = new Vector3(x, y, z).applyMatrix4(inv);
346
+ hx = Math.max(hx, Math.abs(p.x));
347
+ hy = Math.max(hy, Math.abs(p.y));
348
+ }
349
+ this.viewH = Math.max(2 * hy, 2 * hx / this.aspect()) * 1.12;
350
+ this.applyFrustum();
351
+ this.controls.maxZoom = Math.max(4, this.viewH / 3);
352
+ if (this.mode === "free") this.controls.maxDistance = this.viewH * 3;
353
+ }
354
+ applyFrustum() {
355
+ const a = this.aspect();
356
+ Object.assign(this.ortho, { left: -this.viewH * a / 2, right: this.viewH * a / 2, top: this.viewH / 2, bottom: -this.viewH / 2 });
357
+ this.ortho.updateProjectionMatrix();
358
+ this.persp.aspect = a;
359
+ this.persp.updateProjectionMatrix();
360
+ }
361
+ aspect() {
362
+ return (this.canvas.clientWidth || 1) / (this.canvas.clientHeight || 1);
363
+ }
364
+ /** 부드럽게 옮기기(바라보는 점 · 확대 또는 거리 · 수직축 둘레 돌기) */
365
+ tweenTo(o, instant = false) {
366
+ const cam = this.cam;
367
+ const dur = instant || this.reduce ? 1 : 600;
368
+ const t0 = performance.now();
369
+ const fT = this.controls.target.clone();
370
+ const fOff = cam.position.clone().sub(fT);
371
+ const fZ = cam.zoom;
372
+ const fL = fOff.length();
373
+ const tT = o.target ? o.target.clone() : fT;
374
+ const tZ = o.zoom ?? fZ;
375
+ const tL = o.dist ?? fL;
376
+ const rot = o.rotate ?? 0;
377
+ this.controls.enabled = false;
378
+ this.tween = (now) => {
379
+ const k = Math.min(1, (now - t0) / dur);
380
+ const e = ease(k);
381
+ const tt = fT.clone().lerp(tT, e);
382
+ const off = fOff.clone().applyAxisAngle(UP, rot * e).setLength(fL + (tL - fL) * e);
383
+ this.controls.target.copy(tt);
384
+ cam.position.copy(tt).add(off);
385
+ cam.lookAt(tt);
386
+ if (cam instanceof OrthographicCamera) {
387
+ cam.zoom = fZ + (tZ - fZ) * e;
388
+ cam.updateProjectionMatrix();
389
+ }
390
+ if (k >= 1) {
391
+ this.tween = null;
392
+ this.controls.enabled = true;
393
+ this.controls.update();
394
+ }
395
+ };
396
+ if (instant) this.tween(t0 + dur);
397
+ }
398
+ /** 보이는 층 전체를 한눈에 */
399
+ overview(instant = false) {
400
+ this.follow = null;
401
+ const { min, max } = this.box();
402
+ const centre = min.clone().add(max).multiplyScalar(0.5);
403
+ const size = Math.max(max.x - min.x, max.z - min.z, 1);
404
+ const far = Math.max(2e3, size * 6);
405
+ if (this.ortho.far !== far) {
406
+ this.ortho.far = far;
407
+ this.persp.far = far;
408
+ this.applyFrustum();
409
+ }
410
+ if (this.mode === "iso") {
411
+ if (instant) {
412
+ const off = this.ortho.position.clone().sub(this.controls.target);
413
+ const dir = off.lengthSq() > 1e-6 ? off.normalize() : dirFrom(Math.PI / 4, ISO_ELEVATION);
414
+ this.controls.target.copy(centre);
415
+ this.ortho.position.copy(centre).add(dir.multiplyScalar(size * 2));
416
+ this.ortho.lookAt(centre);
417
+ }
418
+ this.fitFrustum();
419
+ this.tweenTo({ target: centre, zoom: 1, dist: size * 2 }, instant);
420
+ } else {
421
+ this.fitFrustum();
422
+ this.tweenTo({ target: centre, dist: size * 1.1 }, instant);
423
+ }
424
+ this.updateSun(centre, size);
425
+ }
426
+ /** 90° 돌린다(+1 = 오른쪽으로) */
427
+ rotate(dir) {
428
+ this.tweenTo({ rotate: dir * Math.PI / 2 });
429
+ }
430
+ setMode(m) {
431
+ if (m === this.mode) return;
432
+ const tg = this.controls.target.clone();
433
+ const off = this.cam.position.clone().sub(tg);
434
+ let az = Math.atan2(off.x, off.z);
435
+ this.mode = m;
436
+ this.tween = null;
437
+ if (m === "free") {
438
+ const zoomed = this.ortho.zoom;
439
+ this.cam = this.persp;
440
+ this.persp.position.copy(tg).add(dirFrom(az, 0.62).multiplyScalar(this.viewH * 1.1 / Math.max(0.8, zoomed)));
441
+ this.persp.lookAt(tg);
442
+ } else {
443
+ az = Math.round((az - Math.PI / 4) / (Math.PI / 2)) * (Math.PI / 2) + Math.PI / 4;
444
+ this.cam = this.ortho;
445
+ this.ortho.position.copy(tg).add(dirFrom(az, ISO_ELEVATION).multiplyScalar(this.viewH * 2));
446
+ this.ortho.lookAt(tg);
447
+ }
448
+ this.setupControls(tg);
449
+ this.fitFrustum();
450
+ }
451
+ /** 표식 · 설비 · 구역으로 다가간다(표식이면 따라간다). */
452
+ focus(id) {
453
+ var _a, _b, _c;
454
+ const m = this.movers.get(id);
455
+ if (m) {
456
+ if (this.shownFloor && this.shownFloor !== m.mover.floorId) this.setFloor(m.mover.floorId);
457
+ this.follow = id;
458
+ this.zoomTo(m.at.clone().setY(m.at.y + m.height / 2), 8);
459
+ return;
460
+ }
461
+ const target = ((_a = this.objects.get(id)) == null ? void 0 : _a.group) ?? ((_b = this.zones.get(id)) == null ? void 0 : _b.face);
462
+ if (!target) return;
463
+ const floorId = ((_c = this.objects.get(id)) == null ? void 0 : _c.floorId) ?? this.zones.get(id).floorId;
464
+ if (this.shownFloor && this.shownFloor !== floorId) this.setFloor(floorId);
465
+ const b = new Box3().setFromObject(target);
466
+ const c = b.getCenter(new Vector3());
467
+ const s = b.getSize(new Vector3());
468
+ this.follow = null;
469
+ this.zoomTo(c, Math.max(8, s.x * 2.2, s.z * 2.2));
470
+ }
471
+ /** 따라가기만 그친다(카메라는 그 자리) */
472
+ unfollow() {
473
+ this.follow = null;
474
+ }
475
+ zoomTo(point, span, instant = false) {
476
+ if (this.mode === "iso") this.tweenTo({ target: point, zoom: Math.min(this.controls.maxZoom, Math.max(1, this.viewH / span)) }, instant);
477
+ else this.tweenTo({ target: point, dist: Math.max(4, span * 1.2) }, instant);
478
+ }
479
+ // --- 층 · 보기 ---------------------------------------------------------------------------------------------------
480
+ /** null = 모든 층(높이대로 쌓아서) */
481
+ setFloor(floorId) {
482
+ this.shownFloor = floorId && this.floors.has(floorId) ? floorId : null;
483
+ this.applyFloors();
484
+ this.drawRoutes();
485
+ this.overview();
486
+ }
487
+ get floor() {
488
+ return this.shownFloor;
489
+ }
490
+ applyFloors() {
491
+ for (const [id, f] of this.floors) {
492
+ f.group.visible = !this.shownFloor || this.shownFloor === id;
493
+ f.group.position.y = this.shownFloor ? 0 : f.elevation;
494
+ }
495
+ for (const m of this.movers.values()) this.placeMover(m, true);
496
+ }
497
+ elevationOf(floorId) {
498
+ var _a;
499
+ if (this.shownFloor) return 0;
500
+ return ((_a = this.floors.get(floorId)) == null ? void 0 : _a.elevation) ?? 0;
501
+ }
502
+ floorShown(floorId) {
503
+ return this.floors.has(floorId) && (!this.shownFloor || this.shownFloor === floorId);
504
+ }
505
+ setGrid(on) {
506
+ this.grid = on;
507
+ for (const f of this.floors.values()) {
508
+ const g = f.group.getObjectByName("grid");
509
+ if (g) g.visible = on;
510
+ }
511
+ }
512
+ setLabels(mode) {
513
+ this.labelMode = mode;
514
+ }
515
+ /** 고르기(표식 · 설비 · 구역 id) — 고른 것에 표시를 단다. null 이면 풀기. */
516
+ select(id) {
517
+ this.selected = id;
518
+ if (!id) this.follow = null;
519
+ if (this.selectMark) {
520
+ this.selectMark.removeFromParent();
521
+ if (this.selectMark instanceof LineSegments || this.selectMark instanceof LineLoop) this.selectMark.geometry.dispose();
522
+ this.selectMark = null;
523
+ }
524
+ for (const z of this.zones.values()) this.paintZone(z);
525
+ if (!id) return;
526
+ const m = this.movers.get(id);
527
+ if (m) {
528
+ const ring = new Mesh(this.ringGeo, this.mats.ring);
529
+ ring.position.y = 0.02;
530
+ ring.raycast = () => void 0;
531
+ m.group.add(ring);
532
+ this.selectMark = ring;
533
+ return;
534
+ }
535
+ const o = this.objects.get(id);
536
+ if (o) {
537
+ const solid = new BoxGeometry(o.w + 0.12, o.height + 0.12, o.h + 0.12).translate(0, o.height / 2, 0);
538
+ const geo = new EdgesGeometry(solid);
539
+ solid.dispose();
540
+ const box = new LineSegments(geo, this.mats.select);
541
+ box.renderOrder = 10;
542
+ box.raycast = () => void 0;
543
+ o.group.add(box);
544
+ this.selectMark = box;
545
+ }
546
+ }
547
+ get selection() {
548
+ return this.selected;
549
+ }
550
+ setTheme(theme) {
551
+ this.theme = theme;
552
+ this.scene.background = null;
553
+ this.hemi.intensity = (theme.dark ? 0.62 : 0.78) * Math.PI;
554
+ this.sun.intensity = (theme.dark ? 0.75 : 0.85) * Math.PI;
555
+ this.mats.floor.color = col(theme.floor);
556
+ this.mats.grid.color = col(theme.grid);
557
+ this.mats.grid.opacity = theme.dark ? 0.55 : 0.75;
558
+ this.mats.lane.color = col(theme.lane);
559
+ this.mats.wall.color = col(theme.wall);
560
+ this.mats.edge.color = col(theme.edge);
561
+ this.mats.edge.opacity = theme.dark ? 0.5 : 0.28;
562
+ this.mats.select.color = col(theme.select);
563
+ this.mats.ring.color = col(theme.select);
564
+ for (const m of this.objectMats.values()) m.dispose();
565
+ this.objectMats.clear();
566
+ if (this.doc) this.setDoc(this.doc, true);
567
+ for (const m of this.movers.values()) this.paintMover(m);
568
+ }
569
+ resize() {
570
+ const w = this.canvas.clientWidth || 1;
571
+ const h = this.canvas.clientHeight || 1;
572
+ this.renderer.setSize(w, h, false);
573
+ this.fitFrustum();
574
+ }
575
+ // --- 그리기: 층 ---------------------------------------------------------------------------------------------------
576
+ own(o) {
577
+ this.owned.push(o);
578
+ return o;
579
+ }
580
+ clearSite() {
581
+ if (this.selectMark) {
582
+ this.selectMark.removeFromParent();
583
+ if (this.selectMark instanceof LineSegments) this.selectMark.geometry.dispose();
584
+ this.selectMark = null;
585
+ }
586
+ for (const f of this.floors.values()) this.root.remove(f.group);
587
+ this.owned.forEach((o) => o.dispose());
588
+ this.owned = [];
589
+ this.floors.clear();
590
+ this.zones.clear();
591
+ this.objects.clear();
592
+ }
593
+ objectMat(hex) {
594
+ let m = this.objectMats.get(hex);
595
+ if (!m) {
596
+ m = new MeshStandardMaterial({ color: col(hex), roughness: 0.7, metalness: 0.05 });
597
+ this.objectMats.set(hex, m);
598
+ }
599
+ return m;
600
+ }
601
+ outline(geo) {
602
+ const e = new LineSegments(this.own(new EdgesGeometry(geo, 30)), this.mats.edge);
603
+ e.raycast = () => void 0;
604
+ return e;
605
+ }
606
+ buildFloor(f) {
607
+ const g = new Group();
608
+ g.name = `floor:${f.id}`;
609
+ const elevation = f.elevation ?? 0;
610
+ this.floors.set(f.id, { floor: f, group: g, elevation });
611
+ this.root.add(g);
612
+ const { w, h } = f.size;
613
+ const slabGeo = this.own(new BoxGeometry(w + 1, SLAB, h + 1).translate(w / 2, -SLAB / 2, -h / 2));
614
+ const slab = new Mesh(slabGeo, this.mats.floor);
615
+ slab.receiveShadow = true;
616
+ slab.add(this.outline(slabGeo));
617
+ g.add(slab);
618
+ const step = Math.max(w, h) > 300 ? 10 : 1;
619
+ const gp = [];
620
+ for (let x = 0; x <= w + 1e-6; x += step) gp.push(x, 2e-3, 0, x, 2e-3, -h);
621
+ for (let y = 0; y <= h + 1e-6; y += step) gp.push(0, 2e-3, -y, w, 2e-3, -y);
622
+ const gg = this.own(new BufferGeometry());
623
+ gg.setAttribute("position", new Float32BufferAttribute(gp, 3));
624
+ const grid = new LineSegments(gg, this.mats.grid);
625
+ grid.name = "grid";
626
+ grid.visible = this.grid;
627
+ grid.raycast = () => void 0;
628
+ g.add(grid);
629
+ const nodes = new Map((f.nodes ?? []).map((n) => [n.id, n]));
630
+ const lp = [];
631
+ for (const e of f.edges ?? []) {
632
+ const a = nodes.get(e.from);
633
+ const b = nodes.get(e.to);
634
+ if (!a || !b) continue;
635
+ const A = toWorld(a.x, a.y);
636
+ const B = toWorld(b.x, b.y);
637
+ const len = Math.hypot(B.x - A.x, B.z - A.z);
638
+ if (len < 0.05) continue;
639
+ const ux = (B.x - A.x) / len;
640
+ const uz = (B.z - A.z) / len;
641
+ if (e.oneWay) {
642
+ for (let s = Math.min(2, len / 2); s <= len - 0.4; s += 6) arrowHead(lp, A.x + ux * s, A.z + uz * s, ux, uz, 4e-3);
643
+ } else {
644
+ for (let s = 0.3; s + 1 <= len - 0.2; s += 1.6) strip(lp, A.x + ux * s, A.z + uz * s, A.x + ux * (s + 1), A.z + uz * (s + 1), 0.05, 4e-3);
645
+ }
646
+ if ((e.width ?? 0) >= 1.5) {
647
+ const off = e.width / 2;
648
+ for (const side of [-1, 1]) strip(lp, A.x - uz * off * side, A.z + ux * off * side, B.x - uz * off * side, B.z + ux * off * side, 0.05, 4e-3);
649
+ }
650
+ }
651
+ if (lp.length) {
652
+ const lanes = new Mesh(this.own(flat(lp)), this.mats.lane);
653
+ lanes.raycast = () => void 0;
654
+ g.add(lanes);
655
+ }
656
+ const wallGeos = [];
657
+ for (const wall of f.walls ?? []) {
658
+ const pts = wall.points.map((p) => new Vector2(p[0], p[1]));
659
+ if (wall.closed && pts.length > 2) pts.push(pts[0].clone());
660
+ const height = Math.min(WALL_CUT, wall.height ?? WALL_CUT);
661
+ const thick = Math.max(0.12, wall.thickness ?? 0.2);
662
+ for (let i = 0; i + 1 < pts.length; i++) {
663
+ const a = pts[i];
664
+ const b = pts[i + 1];
665
+ const len = a.distanceTo(b);
666
+ if (len < 0.01) continue;
667
+ const mid = toWorld((a.x + b.x) / 2, (a.y + b.y) / 2);
668
+ const geo = new BoxGeometry(len + thick, height, thick).translate(0, height / 2, 0);
669
+ geo.rotateY(Math.atan2(b.y - a.y, b.x - a.x));
670
+ geo.translate(mid.x, 0, mid.z);
671
+ wallGeos.push(geo);
672
+ }
673
+ }
674
+ if (wallGeos.length) {
675
+ const wg = this.own(mergeGeometries(wallGeos, false));
676
+ wallGeos.forEach((x) => x.dispose());
677
+ const walls = new Mesh(wg, this.mats.wall);
678
+ walls.castShadow = true;
679
+ walls.receiveShadow = true;
680
+ walls.raycast = () => void 0;
681
+ walls.add(this.outline(wg));
682
+ g.add(walls);
683
+ }
684
+ for (const z of f.zones ?? []) this.buildZone(g, f.id, z);
685
+ for (const o of f.objects ?? []) {
686
+ const height = o.height ?? 1;
687
+ const holder = new Group();
688
+ holder.userData.pick = { kind: "object", id: o.id, name: o.name };
689
+ const p = toWorld(o.x, o.y);
690
+ holder.position.set(p.x, 0, p.z);
691
+ holder.rotation.y = (o.rotation ?? 0) * Math.PI / 180;
692
+ const geo = this.own(new BoxGeometry(o.w, height, o.h).translate(0, height / 2, 0));
693
+ const box = new Mesh(geo, this.objectMat(colorOf(this.theme, o, this.theme.object)));
694
+ box.castShadow = true;
695
+ box.receiveShadow = true;
696
+ box.add(this.outline(geo));
697
+ holder.add(box);
698
+ g.add(holder);
699
+ this.objects.set(o.id, { group: holder, floorId: f.id, w: o.w, h: o.h, height });
700
+ }
701
+ }
702
+ buildZone(g, floorId, z) {
703
+ if (z.polygon.length < 3) return;
704
+ const shape = new Shape(z.polygon.map(([x, y]) => new Vector2(x, y)));
705
+ const geo = this.own(new ShapeGeometry(shape));
706
+ geo.rotateX(-Math.PI / 2);
707
+ const face = new Mesh(geo, this.own(new MeshBasicMaterial({ transparent: true, depthWrite: false, side: DoubleSide })));
708
+ face.position.y = 6e-3;
709
+ face.renderOrder = 1;
710
+ face.userData.pick = { kind: "zone", id: z.id, name: z.name };
711
+ const pts = z.polygon.map(([x, y]) => toWorld(x, y, 0.012));
712
+ const line = new LineLoop(this.own(new BufferGeometry().setFromPoints(pts)), this.own(new LineBasicMaterial({ transparent: true })));
713
+ line.raycast = () => void 0;
714
+ g.add(face, line);
715
+ const v = { zone: z, face, line, floorId };
716
+ this.zones.set(z.id, v);
717
+ this.paintZone(v);
718
+ }
719
+ paintZone(v) {
720
+ const on = this.selected === v.zone.id;
721
+ const c = col(colorOf(this.theme, v.zone, this.theme.tones.info));
722
+ v.face.material.color = c;
723
+ v.face.material.opacity = on ? 0.32 : 0.16;
724
+ v.line.material.color = on ? col(this.theme.select) : c;
725
+ v.line.material.opacity = on ? 1 : 0.75;
726
+ }
727
+ // --- 그리기: 표식 · 경로 --------------------------------------------------------------------------------------------
728
+ makeMover(m) {
729
+ const group = new Group();
730
+ group.userData.pick = { kind: "mover", id: m.id, name: m.label };
731
+ const body = new Mesh(new BufferGeometry(), new MeshStandardMaterial({ roughness: 0.55, metalness: 0.08 }));
732
+ const stripe = new Mesh(new BufferGeometry(), new MeshStandardMaterial({ roughness: 0.4, metalness: 0.1 }));
733
+ body.castShadow = true;
734
+ group.add(body, stripe);
735
+ const tag = document.createElement("div");
736
+ tag.className = "lf-map3d__tag";
737
+ tag.textContent = m.label ?? m.id;
738
+ tag.hidden = true;
739
+ tag.addEventListener("click", () => this.onPick({ kind: "mover", id: m.id, name: m.label }, { x: 0, y: 0 }));
740
+ this.labelLayer.appendChild(tag);
741
+ const v = { mover: m, group, body, stripe, at: new Vector3(), yaw: 0, height: MOVER_SIZE.height, tag };
742
+ this.shapeMover(v);
743
+ this.paintMover(v);
744
+ this.moverGroup.add(group);
745
+ this.placeMover(v, true);
746
+ return v;
747
+ }
748
+ /** 몸통(모서리 둥근 느낌의 상자) + 앞쪽을 알리는 윗면 띠 */
749
+ shapeMover(v) {
750
+ const s = v.mover.size ?? MOVER_SIZE;
751
+ v.height = s.height;
752
+ v.body.geometry.dispose();
753
+ v.stripe.geometry.dispose();
754
+ v.body.geometry = new BoxGeometry(s.w, s.height, s.h).translate(0, s.height / 2 + 0.04, 0);
755
+ v.stripe.geometry = new BoxGeometry(s.w * 0.28, 0.05, s.h * 0.86).translate(s.w * 0.3, s.height + 0.065, 0);
756
+ }
757
+ paintMover(v) {
758
+ const c = colorOf(this.theme, v.mover, this.theme.tones.info);
759
+ v.body.material.color = col(this.theme.dark ? 3359061 : 16317180);
760
+ v.stripe.material.color = col(c);
761
+ v.tag.style.setProperty("--lf-map3d-tag-dot", `#${c.toString(16).padStart(6, "0")}`);
762
+ }
763
+ /** 표식의 목표 자리. instant 면 바로 그 자리로(처음 · 층 바꿈). */
764
+ placeMover(v, instant = false) {
765
+ const target = toWorld(v.mover.x, v.mover.y, this.elevationOf(v.mover.floorId));
766
+ const yaw = (v.mover.heading ?? 0) * Math.PI / 180;
767
+ v.group.visible = this.floorShown(v.mover.floorId);
768
+ if (instant || this.reduce || v.at.distanceTo(target) > 30) {
769
+ v.at.copy(target);
770
+ v.yaw = yaw;
771
+ }
772
+ v.group.position.copy(v.at);
773
+ v.group.rotation.y = v.yaw;
774
+ }
775
+ /** 프레임마다 목표 쪽으로 — 지수 감쇠라 위치가 띄엄띄엄 와도 미끄러지듯 */
776
+ stepMovers(dt) {
777
+ const k = 1 - Math.exp(-dt * 7);
778
+ for (const v of this.movers.values()) {
779
+ const target = toWorld(v.mover.x, v.mover.y, this.elevationOf(v.mover.floorId));
780
+ v.group.visible = this.floorShown(v.mover.floorId);
781
+ v.at.lerp(target, k);
782
+ const want = (v.mover.heading ?? 0) * Math.PI / 180;
783
+ let d = (want - v.yaw) % (2 * Math.PI);
784
+ if (d > Math.PI) d -= 2 * Math.PI;
785
+ if (d < -Math.PI) d += 2 * Math.PI;
786
+ v.yaw += d * k;
787
+ v.group.position.copy(v.at);
788
+ v.group.rotation.y = v.yaw;
789
+ }
790
+ }
791
+ drawRoutes() {
792
+ this.routeGroup.clear();
793
+ this.routeOwned.forEach((o) => o.dispose());
794
+ this.routeOwned = [];
795
+ for (const r of this.routes) {
796
+ const half = (r.width ?? 0.28) / 2;
797
+ const out = [];
798
+ for (let i = 0; i + 1 < r.points.length; i++) {
799
+ const a = r.points[i];
800
+ const b = r.points[i + 1];
801
+ if (a.floorId !== b.floorId || !this.floorShown(a.floorId)) continue;
802
+ const y = this.elevationOf(a.floorId) + 0.02;
803
+ const A = toWorld(a.x, a.y);
804
+ const B = toWorld(b.x, b.y);
805
+ if (!r.dashed) {
806
+ strip(out, A.x, A.z, B.x, B.z, half, y);
807
+ continue;
808
+ }
809
+ const len = Math.hypot(B.x - A.x, B.z - A.z);
810
+ const ux = (B.x - A.x) / (len || 1);
811
+ const uz = (B.z - A.z) / (len || 1);
812
+ for (let s = 0; s < len; s += 0.9) {
813
+ const e = Math.min(len, s + 0.5);
814
+ strip(out, A.x + ux * s, A.z + uz * s, A.x + ux * e, A.z + uz * e, half, y);
815
+ }
816
+ }
817
+ if (!out.length) continue;
818
+ const geo = flat(out);
819
+ const mat = new MeshBasicMaterial({ color: col(colorOf(this.theme, r, this.theme.select)), transparent: true, opacity: r.dashed ? 0.55 : 0.75, side: DoubleSide, depthWrite: false });
820
+ this.routeOwned.push(geo, mat);
821
+ const mesh = new Mesh(geo, mat);
822
+ mesh.renderOrder = 2;
823
+ mesh.raycast = () => void 0;
824
+ this.routeGroup.add(mesh);
825
+ }
826
+ }
827
+ updateSun(centre, size) {
828
+ this.sun.position.copy(centre).add(new Vector3(5, 11, 6).normalize().multiplyScalar(size));
829
+ this.sun.target.position.copy(centre);
830
+ const cam = this.sun.shadow.camera;
831
+ cam.left = cam.bottom = -size * 0.65;
832
+ cam.right = cam.top = size * 0.65;
833
+ cam.near = 1;
834
+ cam.far = size * 2.5;
835
+ cam.updateProjectionMatrix();
836
+ }
837
+ /** 화면 점(client px) 아래의 것 — 표식, 설비, 구역 차례 */
838
+ pickAt(clientX, clientY) {
839
+ var _a;
840
+ return ((_a = this.hitAt(clientX, clientY)) == null ? void 0 : _a.pick) ?? null;
841
+ }
842
+ hitAt(clientX, clientY) {
843
+ const r = this.canvas.getBoundingClientRect();
844
+ const ray = new Raycaster();
845
+ ray.setFromCamera(new Vector2((clientX - r.left) / r.width * 2 - 1, -((clientY - r.top) / r.height) * 2 + 1), this.cam);
846
+ const rank = (k) => k === "mover" ? 0 : k === "object" ? 1 : 2;
847
+ let best = null;
848
+ for (const h of ray.intersectObjects([this.moverGroup, this.root], true)) {
849
+ if (!visible(h.object)) continue;
850
+ const o = pickHolder(h.object);
851
+ if (!o) continue;
852
+ const pick = o.userData.pick;
853
+ if (!best || rank(pick.kind) < rank(best.pick.kind)) best = { pick, object: o };
854
+ }
855
+ return best;
856
+ }
857
+ updateHover() {
858
+ var _a;
859
+ if (++this.hoverFrame % 2) return;
860
+ const hit = this.pointer ? this.hitAt(this.pointer.x, this.pointer.y) : null;
861
+ this.canvas.style.cursor = hit ? "pointer" : "";
862
+ if (!hit) {
863
+ this.hovered = null;
864
+ return;
865
+ }
866
+ if (((_a = this.hovered) == null ? void 0 : _a.pick.id) !== hit.pick.id) {
867
+ let top = null;
868
+ if (hit.pick.kind !== "mover") {
869
+ const b = new Box3().setFromObject(hit.object);
870
+ if (!b.isEmpty()) top = new Vector3((b.min.x + b.max.x) / 2, b.max.y + 0.2, (b.min.z + b.max.z) / 2);
871
+ }
872
+ this.hovered = { pick: hit.pick, top };
873
+ }
874
+ }
875
+ // --- 이름표 · 돌기 ------------------------------------------------------------------------------------------------
876
+ /** 화면에서 1 m 가 몇 px 인가(이름표를 가까이 볼 때만 띄운다) */
877
+ pxPerMetre() {
878
+ const h = this.canvas.clientHeight || 1;
879
+ if (this.cam instanceof OrthographicCamera) return h * this.cam.zoom / this.viewH;
880
+ const d = this.cam.position.distanceTo(this.controls.target);
881
+ return h / (2 * d * Math.tan(this.persp.fov * Math.PI / 360));
882
+ }
883
+ screen(p, w, h) {
884
+ const v = p.clone().project(this.cam);
885
+ return { x: (v.x + 1) / 2 * w, y: (1 - v.y) / 2 * h, on: v.z > -1 && v.z < 1 && Math.abs(v.x) <= 1.05 && Math.abs(v.y) <= 1.05 };
886
+ }
887
+ updateLabels() {
888
+ var _a;
889
+ const w = this.canvas.clientWidth;
890
+ const h = this.canvas.clientHeight;
891
+ const near = this.pxPerMetre() >= 22;
892
+ const hoverId = ((_a = this.hovered) == null ? void 0 : _a.pick.kind) === "mover" ? this.hovered.pick.id : null;
893
+ for (const v of this.movers.values()) {
894
+ const mine = v.mover.id === this.selected || v.mover.id === hoverId;
895
+ const show = v.group.visible && (mine || this.labelMode === "always" || this.labelMode === "auto" && near);
896
+ if (!show) {
897
+ v.tag.hidden = true;
898
+ continue;
899
+ }
900
+ const s = this.screen(v.at.clone().setY(v.at.y + v.height + 0.35), w, h);
901
+ v.tag.hidden = !s.on;
902
+ v.tag.style.transform = `translate(${s.x}px, ${s.y}px) translate(-50%, -100%)`;
903
+ v.tag.classList.toggle("lf-map3d__tag--on", v.mover.id === this.selected);
904
+ }
905
+ const hov = this.hovered;
906
+ if (hov && hov.pick.kind !== "mover" && hov.top) {
907
+ const s = this.screen(hov.top, w, h);
908
+ this.hoverTag.textContent = hov.pick.name ? `${hov.pick.name} · ${hov.pick.id}` : hov.pick.id;
909
+ this.hoverTag.hidden = !s.on;
910
+ this.hoverTag.style.transform = `translate(${s.x}px, ${s.y}px) translate(-50%, -100%)`;
911
+ } else this.hoverTag.hidden = true;
912
+ }
913
+ dispose() {
914
+ cancelAnimationFrame(this.raf);
915
+ this.canvas.removeEventListener("pointerdown", this.onDown);
916
+ this.canvas.removeEventListener("pointerup", this.onUp);
917
+ this.canvas.removeEventListener("pointermove", this.onMove);
918
+ this.canvas.removeEventListener("pointerleave", this.onLeave);
919
+ this.canvas.removeEventListener("wheel", this.onWheel, { capture: true });
920
+ this.controls.dispose();
921
+ this.setMovers([]);
922
+ this.clearSite();
923
+ this.routeOwned.forEach((o) => o.dispose());
924
+ for (const m of Object.values(this.mats)) m.dispose();
925
+ for (const m of this.objectMats.values()) m.dispose();
926
+ this.ringGeo.dispose();
927
+ this.hoverTag.remove();
928
+ this.renderer.dispose();
929
+ }
930
+ }
931
+ const _hoisted_1 = {
932
+ key: 0,
933
+ class: "lf-map3d__bar"
934
+ };
935
+ const ICON_ROTATE_LEFT = "M13,4.07V1L8.45,5.55L13,10V6.09C15.84,6.57 18,9.03 18,12C18,14.97 15.84,17.43 13,17.91V19.93C16.95,19.44 20,16.08 20,12C20,7.92 16.95,4.56 13,4.07M7.1,18.32C8.26,19.22 9.61,19.76 11,19.93V17.9C10.13,17.75 9.29,17.41 8.54,16.87L7.1,18.32M6.09,13H4.07C4.24,14.39 4.79,15.73 5.69,16.89L7.1,15.47C6.58,14.72 6.23,13.88 6.09,13M7.11,8.53L5.7,7.11C4.8,8.27 4.24,9.61 4.07,11H6.09C6.23,10.13 6.58,9.28 7.11,8.53Z";
936
+ const ICON_ROTATE_RIGHT = "M16.89,15.5L18.31,16.89C19.21,15.73 19.76,14.39 19.93,13H17.91C17.77,13.87 17.43,14.72 16.89,15.5M13,17.9V19.92C14.39,19.75 15.74,19.21 16.9,18.31L15.46,16.87C14.71,17.41 13.87,17.76 13,17.9M19.93,11C19.76,9.61 19.21,8.27 18.31,7.11L16.89,8.53C17.43,9.28 17.77,10.13 17.91,11M15.55,5.55L11,1V4.07C7.06,4.56 4,7.92 4,12C4,16.08 7.05,19.44 11,19.93V17.91C8.16,17.43 6,14.97 6,12C6,9.03 8.16,6.57 11,6.09V10L15.55,5.55Z";
937
+ const ICON_FIT = "M5,5H10V7H7V10H5V5M14,5H19V10H17V7H14V5M17,14H19V19H14V17H17V14M10,17V19H5V14H7V17H10Z";
938
+ const ALL = "__all__";
939
+ const _sfc_main = /* @__PURE__ */ defineComponent({
940
+ __name: "LfMap3d",
941
+ props: {
942
+ doc: {},
943
+ movers: { default: () => [] },
944
+ routes: { default: () => [] },
945
+ selected: { default: null },
946
+ floor: { default: null },
947
+ mode: { default: "iso" },
948
+ grid: { type: Boolean, default: true },
949
+ labels: { default: "auto" },
950
+ followSelected: { type: Boolean, default: true },
951
+ controls: { type: Boolean, default: true },
952
+ allFloorsLabel: { default: "모든 층" },
953
+ labelsText: { default: () => ({}) }
954
+ },
955
+ emits: ["update:selected", "update:floor", "update:mode", "pick"],
956
+ setup(__props, { expose: __expose, emit: __emit }) {
957
+ const props = __props;
958
+ const emit = __emit;
959
+ const root = ref();
960
+ const canvas = ref();
961
+ const labels = ref();
962
+ const scene = shallowRef(null);
963
+ const floorLocal = ref(props.floor);
964
+ const modeLocal = ref(props.mode);
965
+ const floorOptions = computed(() => [
966
+ { value: ALL, label: props.allFloorsLabel },
967
+ ...props.doc.floors.map((f) => ({ value: f.id, label: f.name ?? f.id }))
968
+ ]);
969
+ const floorValue = computed(() => floorLocal.value ?? ALL);
970
+ const modeValue = computed(() => modeLocal.value);
971
+ const t = computed(() => ({
972
+ floor: "층",
973
+ view: "시점",
974
+ iso: "아이소",
975
+ free: "자유",
976
+ rotateLeft: "왼쪽으로 돌리기",
977
+ rotateRight: "오른쪽으로 돌리기",
978
+ fit: "전체 보기",
979
+ ...props.labelsText
980
+ }));
981
+ const modeOptions = computed(() => [
982
+ { value: "iso", label: t.value.iso },
983
+ { value: "free", label: t.value.free }
984
+ ]);
985
+ function setFloorValue(v) {
986
+ var _a;
987
+ const id = v === ALL || v == null ? null : String(v);
988
+ floorLocal.value = id;
989
+ (_a = scene.value) == null ? void 0 : _a.setFloor(id);
990
+ emit("update:floor", id);
991
+ }
992
+ function setModeValue(v) {
993
+ var _a;
994
+ const m = v === "free" ? "free" : "iso";
995
+ modeLocal.value = m;
996
+ (_a = scene.value) == null ? void 0 : _a.setMode(m);
997
+ emit("update:mode", m);
998
+ }
999
+ let resizeObs = null;
1000
+ let themeObs = null;
1001
+ let themeFrame = 0;
1002
+ onMounted(() => {
1003
+ const s = new MapScene(canvas.value, labels.value, readMapTheme(root.value), { labels: props.labels });
1004
+ s.onPick = (p, at) => {
1005
+ const id = (p == null ? void 0 : p.id) ?? null;
1006
+ s.select(id);
1007
+ if ((p == null ? void 0 : p.kind) === "mover" && props.followSelected) s.focus(p.id);
1008
+ emit("update:selected", id);
1009
+ emit("pick", p, at);
1010
+ };
1011
+ s.setDoc(props.doc);
1012
+ s.setMovers(props.movers);
1013
+ s.setRoutes(props.routes);
1014
+ s.setGrid(props.grid);
1015
+ if (props.mode !== "iso") s.setMode(props.mode);
1016
+ if (props.floor) s.setFloor(props.floor);
1017
+ if (props.selected) s.select(props.selected);
1018
+ scene.value = s;
1019
+ resizeObs = new ResizeObserver(() => s.resize());
1020
+ resizeObs.observe(root.value);
1021
+ themeObs = new MutationObserver(() => {
1022
+ cancelAnimationFrame(themeFrame);
1023
+ themeFrame = requestAnimationFrame(() => s.setTheme(readMapTheme(root.value)));
1024
+ });
1025
+ themeObs.observe(document.documentElement, { attributes: true, attributeFilter: ["style", "class", "data-theme"] });
1026
+ });
1027
+ onBeforeUnmount(() => {
1028
+ var _a;
1029
+ resizeObs == null ? void 0 : resizeObs.disconnect();
1030
+ themeObs == null ? void 0 : themeObs.disconnect();
1031
+ cancelAnimationFrame(themeFrame);
1032
+ (_a = scene.value) == null ? void 0 : _a.dispose();
1033
+ scene.value = null;
1034
+ });
1035
+ watch(() => props.doc, (d) => {
1036
+ var _a;
1037
+ return (_a = scene.value) == null ? void 0 : _a.setDoc(d, true);
1038
+ });
1039
+ watch(() => props.movers, (m) => {
1040
+ var _a;
1041
+ return (_a = scene.value) == null ? void 0 : _a.setMovers(m);
1042
+ }, { deep: true });
1043
+ watch(() => props.routes, (r) => {
1044
+ var _a;
1045
+ return (_a = scene.value) == null ? void 0 : _a.setRoutes(r);
1046
+ }, { deep: true });
1047
+ watch(() => props.grid, (g) => {
1048
+ var _a;
1049
+ return (_a = scene.value) == null ? void 0 : _a.setGrid(g);
1050
+ });
1051
+ watch(() => props.labels, (l) => {
1052
+ var _a;
1053
+ return (_a = scene.value) == null ? void 0 : _a.setLabels(l);
1054
+ });
1055
+ watch(() => props.floor, (f) => {
1056
+ var _a;
1057
+ if (f === floorLocal.value) return;
1058
+ floorLocal.value = f;
1059
+ (_a = scene.value) == null ? void 0 : _a.setFloor(f);
1060
+ });
1061
+ watch(() => props.mode, (m) => {
1062
+ var _a;
1063
+ if (m === modeLocal.value) return;
1064
+ modeLocal.value = m;
1065
+ (_a = scene.value) == null ? void 0 : _a.setMode(m);
1066
+ });
1067
+ watch(() => props.selected, (id) => {
1068
+ const s = scene.value;
1069
+ if (!s || id === s.selection) return;
1070
+ s.select(id);
1071
+ if (id && props.followSelected && props.movers.some((m) => m.id === id)) s.focus(id);
1072
+ });
1073
+ __expose({
1074
+ /** 보이는 층 전체를 한눈에 */
1075
+ overview: () => {
1076
+ var _a;
1077
+ return (_a = scene.value) == null ? void 0 : _a.overview();
1078
+ },
1079
+ /** 표식 · 설비 · 구역으로 다가간다(표식이면 따라간다) */
1080
+ focus: (id) => {
1081
+ var _a;
1082
+ return (_a = scene.value) == null ? void 0 : _a.focus(id);
1083
+ },
1084
+ /** 90° 돌리기(아이소 시점) */
1085
+ rotate: (dir) => {
1086
+ var _a;
1087
+ return (_a = scene.value) == null ? void 0 : _a.rotate(dir);
1088
+ },
1089
+ /** 화면 점 아래의 것 */
1090
+ pickAt: (x, y) => {
1091
+ var _a;
1092
+ return ((_a = scene.value) == null ? void 0 : _a.pickAt(x, y)) ?? null;
1093
+ },
1094
+ scene
1095
+ });
1096
+ return (_ctx, _cache) => {
1097
+ return openBlock(), createElementBlock("div", {
1098
+ ref_key: "root",
1099
+ ref: root,
1100
+ class: "lf-map3d"
1101
+ }, [
1102
+ createElementVNode("canvas", {
1103
+ ref_key: "canvas",
1104
+ ref: canvas,
1105
+ class: "lf-map3d__canvas"
1106
+ }, null, 512),
1107
+ createElementVNode("div", {
1108
+ ref_key: "labels",
1109
+ ref: labels,
1110
+ class: "lf-map3d__labels",
1111
+ "aria-hidden": "true"
1112
+ }, null, 512),
1113
+ __props.controls ? (openBlock(), createElementBlock("div", _hoisted_1, [
1114
+ floorOptions.value.length > 1 ? (openBlock(), createBlock(LfSelect, {
1115
+ key: 0,
1116
+ "model-value": floorValue.value,
1117
+ options: floorOptions.value,
1118
+ size: "sm",
1119
+ class: "lf-map3d__floor",
1120
+ "aria-label": t.value.floor,
1121
+ "onUpdate:modelValue": setFloorValue
1122
+ }, null, 8, ["model-value", "options", "aria-label"])) : createCommentVNode("", true),
1123
+ createVNode(LfSegmented, {
1124
+ "model-value": modeValue.value,
1125
+ options: modeOptions.value,
1126
+ size: "sm",
1127
+ "aria-label": t.value.view,
1128
+ "onUpdate:modelValue": setModeValue
1129
+ }, null, 8, ["model-value", "options", "aria-label"]),
1130
+ createVNode(LfIconButton, {
1131
+ "icon-path": ICON_ROTATE_LEFT,
1132
+ label: t.value.rotateLeft,
1133
+ size: "sm",
1134
+ disabled: modeValue.value !== "iso",
1135
+ onClick: _cache[0] || (_cache[0] = ($event) => {
1136
+ var _a;
1137
+ return (_a = scene.value) == null ? void 0 : _a.rotate(-1);
1138
+ })
1139
+ }, null, 8, ["label", "disabled"]),
1140
+ createVNode(LfIconButton, {
1141
+ "icon-path": ICON_ROTATE_RIGHT,
1142
+ label: t.value.rotateRight,
1143
+ size: "sm",
1144
+ disabled: modeValue.value !== "iso",
1145
+ onClick: _cache[1] || (_cache[1] = ($event) => {
1146
+ var _a;
1147
+ return (_a = scene.value) == null ? void 0 : _a.rotate(1);
1148
+ })
1149
+ }, null, 8, ["label", "disabled"]),
1150
+ createVNode(LfIconButton, {
1151
+ "icon-path": ICON_FIT,
1152
+ label: t.value.fit,
1153
+ size: "sm",
1154
+ onClick: _cache[2] || (_cache[2] = ($event) => {
1155
+ var _a;
1156
+ return (_a = scene.value) == null ? void 0 : _a.overview();
1157
+ })
1158
+ }, null, 8, ["label"])
1159
+ ])) : createCommentVNode("", true)
1160
+ ], 512);
1161
+ };
1162
+ }
1163
+ });
1164
+ const LfMap3d = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-bf869e20"]]);
1165
+ export {
1166
+ ISO_ELEVATION,
1167
+ LfMap3d,
1168
+ MapScene,
1169
+ colorOf,
1170
+ parseColor,
1171
+ readMapTheme
1172
+ };
1173
+ //# sourceMappingURL=map3d.js.map