react-floor-mapper 0.1.6 → 0.1.7

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.
@@ -1,10 +1,35 @@
1
- import * as React2 from 'react';
2
- import { useRef, useState, useEffect, useMemo } from 'react';
3
- import { jsx, jsxs } from 'react/jsx-runtime';
4
- import { Stage, Layer, Image as Image$1, Line, Group, Circle } from 'react-konva';
5
- import useImage from 'use-image';
6
- import { ZoomIn, ZoomOut } from 'lucide-react';
7
- import styled from 'styled-components';
1
+ 'use strict';
2
+
3
+ var React2 = require('react');
4
+ var jsxRuntime = require('react/jsx-runtime');
5
+ var reactKonva = require('react-konva');
6
+ var useImage = require('use-image');
7
+ var lucideReact = require('lucide-react');
8
+ var styled = require('styled-components');
9
+
10
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
+
12
+ function _interopNamespace(e) {
13
+ if (e && e.__esModule) return e;
14
+ var n = Object.create(null);
15
+ if (e) {
16
+ Object.keys(e).forEach(function (k) {
17
+ if (k !== 'default') {
18
+ var d = Object.getOwnPropertyDescriptor(e, k);
19
+ Object.defineProperty(n, k, d.get ? d : {
20
+ enumerable: true,
21
+ get: function () { return e[k]; }
22
+ });
23
+ }
24
+ });
25
+ }
26
+ n.default = e;
27
+ return Object.freeze(n);
28
+ }
29
+
30
+ var React2__namespace = /*#__PURE__*/_interopNamespace(React2);
31
+ var useImage__default = /*#__PURE__*/_interopDefault(useImage);
32
+ var styled__default = /*#__PURE__*/_interopDefault(styled);
8
33
 
9
34
  // src/components/ImageWithPoints.tsx
10
35
 
@@ -32,8 +57,8 @@ function ImageWithPoints({
32
57
  children,
33
58
  points
34
59
  }) {
35
- const [size, setSize] = React2.useState(naturalSize ?? null);
36
- React2.useEffect(() => {
60
+ const [size, setSize] = React2__namespace.useState(naturalSize != null ? naturalSize : null);
61
+ React2__namespace.useEffect(() => {
37
62
  let alive = true;
38
63
  (async () => {
39
64
  if (!naturalSize && image.type === "img") {
@@ -50,9 +75,9 @@ function ImageWithPoints({
50
75
  alive = false;
51
76
  };
52
77
  }, [image, naturalSize]);
53
- if (!size) return /* @__PURE__ */ jsx("div", { className, style: { ...style, aspectRatio: "16/9", background: "#f6f8fa" } });
78
+ if (!size) return /* @__PURE__ */ jsxRuntime.jsx("div", { className, style: { ...style, aspectRatio: "16/9", background: "#f6f8fa" } });
54
79
  const { width, height } = size;
55
- return /* @__PURE__ */ jsxs(
80
+ return /* @__PURE__ */ jsxRuntime.jsxs(
56
81
  "svg",
57
82
  {
58
83
  className,
@@ -62,16 +87,16 @@ function ImageWithPoints({
62
87
  "aria-label": title,
63
88
  xmlns: "http://www.w3.org/2000/svg",
64
89
  children: [
65
- title && /* @__PURE__ */ jsx("title", { children: title }),
66
- desc && /* @__PURE__ */ jsx("desc", { children: desc }),
67
- /* @__PURE__ */ jsx("image", { href: image.src, x: 0, y: 0, width, height, preserveAspectRatio: "none" }),
68
- /* @__PURE__ */ jsx("g", { stroke: lineStroke, strokeWidth: lineWidth, strokeLinecap: "round", children: edges.map((e) => {
90
+ title && /* @__PURE__ */ jsxRuntime.jsx("title", { children: title }),
91
+ desc && /* @__PURE__ */ jsxRuntime.jsx("desc", { children: desc }),
92
+ /* @__PURE__ */ jsxRuntime.jsx("image", { href: image.src, x: 0, y: 0, width, height, preserveAspectRatio: "none" }),
93
+ /* @__PURE__ */ jsxRuntime.jsx("g", { stroke: lineStroke, strokeWidth: lineWidth, strokeLinecap: "round", children: edges.map((e) => {
69
94
  const a = points.find((p) => p.id === e.from);
70
95
  const b = points.find((p) => p.id === e.to);
71
96
  if (!a || !b) return null;
72
- return /* @__PURE__ */ jsx("line", { x1: a.x, y1: a.y, x2: b.x, y2: b.y }, e.id);
97
+ return /* @__PURE__ */ jsxRuntime.jsx("line", { x1: a.x, y1: a.y, x2: b.x, y2: b.y }, e.id);
73
98
  }) }),
74
- /* @__PURE__ */ jsx("g", { fill: pointFill, children: points.map((p) => /* @__PURE__ */ jsx("circle", { cx: p.x, cy: p.y, r: pointRadius }, p.id)) }),
99
+ /* @__PURE__ */ jsxRuntime.jsx("g", { fill: pointFill, children: points.map((p) => /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: p.x, cy: p.y, r: pointRadius }, p.id)) }),
75
100
  children
76
101
  ]
77
102
  }
@@ -108,24 +133,24 @@ function FloorMapDrawer(props) {
108
133
  title,
109
134
  desc
110
135
  } = props;
111
- const wrapperRef = React2.useRef(null);
112
- const svgRef = React2.useRef(null);
113
- const [size, setSize] = React2.useState(naturalSize ?? null);
136
+ const wrapperRef = React2__namespace.useRef(null);
137
+ const svgRef = React2__namespace.useRef(null);
138
+ const [size, setSize] = React2__namespace.useState(naturalSize != null ? naturalSize : null);
114
139
  const isControlled = points !== void 0 || edges !== void 0;
115
- const [localPoints, setLocalPoints] = React2.useState(defaultPoints);
116
- const [localEdges, setLocalEdges] = React2.useState(defaultEdges);
117
- const pts = points ?? localPoints;
118
- const eds = edges ?? localEdges;
119
- const [scale, setScale] = React2.useState(1);
120
- const [tx, setTx] = React2.useState(0);
121
- const [ty, setTy] = React2.useState(0);
122
- const [mode, setMode] = React2.useState(initialMode);
123
- const [hoverId, setHoverId] = React2.useState(null);
124
- const [drag, setDrag] = React2.useState(null);
125
- const spacePanningRef = React2.useRef(false);
126
- const [undoStack, setUndoStack] = React2.useState([]);
127
- const [redoStack, setRedoStack] = React2.useState([]);
128
- React2.useEffect(() => {
140
+ const [localPoints, setLocalPoints] = React2__namespace.useState(defaultPoints);
141
+ const [localEdges, setLocalEdges] = React2__namespace.useState(defaultEdges);
142
+ const pts = points != null ? points : localPoints;
143
+ const eds = edges != null ? edges : localEdges;
144
+ const [scale, setScale] = React2__namespace.useState(1);
145
+ const [tx, setTx] = React2__namespace.useState(0);
146
+ const [ty, setTy] = React2__namespace.useState(0);
147
+ const [mode, setMode] = React2__namespace.useState(initialMode);
148
+ const [hoverId, setHoverId] = React2__namespace.useState(null);
149
+ const [drag, setDrag] = React2__namespace.useState(null);
150
+ const spacePanningRef = React2__namespace.useRef(false);
151
+ const [undoStack, setUndoStack] = React2__namespace.useState([]);
152
+ const [redoStack, setRedoStack] = React2__namespace.useState([]);
153
+ React2__namespace.useEffect(() => {
129
154
  let alive = true;
130
155
  (async () => {
131
156
  if (!naturalSize && image.type === "img") {
@@ -142,12 +167,12 @@ function FloorMapDrawer(props) {
142
167
  alive = false;
143
168
  };
144
169
  }, [image, naturalSize]);
145
- const clamp = React2.useCallback((n, a, b) => Math.max(a, Math.min(b, n)), []);
146
- const cryptoRandomId = React2.useCallback(
170
+ const clamp = React2__namespace.useCallback((n, a, b) => Math.max(a, Math.min(b, n)), []);
171
+ const cryptoRandomId = React2__namespace.useCallback(
147
172
  () => typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : Math.random().toString(36).slice(2),
148
173
  []
149
174
  );
150
- const screenToImage = React2.useCallback((clientX, clientY) => {
175
+ const screenToImage = React2__namespace.useCallback((clientX, clientY) => {
151
176
  const svg = svgRef.current;
152
177
  if (!svg || !size) return null;
153
178
  const rect = svg.getBoundingClientRect();
@@ -157,12 +182,12 @@ function FloorMapDrawer(props) {
157
182
  const y = (cy - ty) / scale;
158
183
  return { x, y };
159
184
  }, [size, tx, ty, scale]);
160
- const pushHistory = React2.useCallback((entry) => {
185
+ const pushHistory = React2__namespace.useCallback((entry) => {
161
186
  if (isControlled) return;
162
187
  setUndoStack((s) => [...s, entry]);
163
188
  setRedoStack([]);
164
189
  }, [isControlled]);
165
- const undo = React2.useCallback(() => {
190
+ const undo = React2__namespace.useCallback(() => {
166
191
  if (isControlled) return;
167
192
  setUndoStack((s) => {
168
193
  if (s.length === 0) return s;
@@ -173,11 +198,11 @@ function FloorMapDrawer(props) {
173
198
  }, ...r]);
174
199
  setLocalPoints(prev.points);
175
200
  setLocalEdges(prev.edges);
176
- onChange?.({ points: prev.points, edges: prev.edges });
201
+ onChange == null ? void 0 : onChange({ points: prev.points, edges: prev.edges });
177
202
  return s.slice(0, -1);
178
203
  });
179
204
  }, [isControlled, localPoints, localEdges, onChange]);
180
- const redo = React2.useCallback(() => {
205
+ const redo = React2__namespace.useCallback(() => {
181
206
  if (isControlled) return;
182
207
  setRedoStack((r) => {
183
208
  if (r.length === 0) return r;
@@ -188,31 +213,32 @@ function FloorMapDrawer(props) {
188
213
  }]);
189
214
  setLocalPoints(next.points);
190
215
  setLocalEdges(next.edges);
191
- onChange?.({ points: next.points, edges: next.edges });
216
+ onChange == null ? void 0 : onChange({ points: next.points, edges: next.edges });
192
217
  return r.slice(1);
193
218
  });
194
219
  }, [isControlled, localPoints, localEdges, onChange]);
195
- const setAndEmitMode = React2.useCallback((m) => {
220
+ const setAndEmitMode = React2__namespace.useCallback((m) => {
196
221
  setMode(m);
197
- onModeChange?.(m);
222
+ onModeChange == null ? void 0 : onModeChange(m);
198
223
  }, [onModeChange]);
199
- const update = React2.useCallback((next) => {
200
- const newPoints = next.points ?? pts;
201
- const newEdges = next.edges ?? eds;
224
+ const update = React2__namespace.useCallback((next) => {
225
+ var _a, _b;
226
+ const newPoints = (_a = next.points) != null ? _a : pts;
227
+ const newEdges = (_b = next.edges) != null ? _b : eds;
202
228
  if (!isControlled) {
203
229
  pushHistory({ points: pts, edges: eds });
204
230
  if (next.points) setLocalPoints(newPoints);
205
231
  if (next.edges) setLocalEdges(newEdges);
206
232
  }
207
- onChange?.({ points: newPoints, edges: newEdges });
233
+ onChange == null ? void 0 : onChange({ points: newPoints, edges: newEdges });
208
234
  }, [isControlled, pts, eds, onChange, pushHistory]);
209
- const removePoint = React2.useCallback((id) => {
235
+ const removePoint = React2__namespace.useCallback((id) => {
210
236
  update({
211
237
  points: pts.filter((p) => p.id !== id),
212
238
  edges: eds.filter((e) => e.from !== id && e.to !== id)
213
239
  });
214
240
  }, [pts, eds, update]);
215
- const addPointAt = React2.useCallback((clientX, clientY) => {
241
+ const addPointAt = React2__namespace.useCallback((clientX, clientY) => {
216
242
  const img = screenToImage(clientX, clientY);
217
243
  if (!img || !size) return;
218
244
  const x = clamp(img.x, 0, size.width);
@@ -232,12 +258,12 @@ function FloorMapDrawer(props) {
232
258
  }
233
259
  update({ points: newPoints, edges: newEdges });
234
260
  }, [screenToImage, size, clamp, cryptoRandomId, pts, eds, connectSequential, update]);
235
- const resetZoom = React2.useCallback(() => {
261
+ const resetZoom = React2__namespace.useCallback(() => {
236
262
  setScale(1);
237
263
  setTx(0);
238
264
  setTy(0);
239
265
  }, []);
240
- const fitToContainer = React2.useCallback(() => {
266
+ const fitToContainer = React2__namespace.useCallback(() => {
241
267
  if (!wrapperRef.current || !size) return;
242
268
  const rect = wrapperRef.current.getBoundingClientRect();
243
269
  const pad = 16;
@@ -248,7 +274,7 @@ function FloorMapDrawer(props) {
248
274
  setTx((rect.width - size.width * s) / 2);
249
275
  setTy((rect.height - size.height * s) / 2);
250
276
  }, [size]);
251
- React2.useEffect(() => {
277
+ React2__namespace.useEffect(() => {
252
278
  const onKeyDown = (e) => {
253
279
  if (e.code === "Space") spacePanningRef.current = true;
254
280
  if (e.target && e.target.tagName === "INPUT") return;
@@ -297,7 +323,7 @@ function FloorMapDrawer(props) {
297
323
  if (!size) return;
298
324
  if (mode === "add") addPointAt(e.clientX, e.clientY);
299
325
  };
300
- const wantPan = React2.useCallback(
326
+ const wantPan = React2__namespace.useCallback(
301
327
  () => panEnabled && (mode === "pan" || spacePanningRef.current),
302
328
  [panEnabled, mode]
303
329
  );
@@ -306,7 +332,7 @@ function FloorMapDrawer(props) {
306
332
  e.target.setPointerCapture(e.pointerId);
307
333
  setDrag({ kind: "panning", lastX: e.clientX, lastY: e.clientY });
308
334
  };
309
- const onPointPointerDown = React2.useCallback((p) => (e) => {
335
+ const onPointPointerDown = React2__namespace.useCallback((p) => (e) => {
310
336
  if (mode === "erase") {
311
337
  e.stopPropagation();
312
338
  removePoint(p.id);
@@ -336,8 +362,9 @@ function FloorMapDrawer(props) {
336
362
  }
337
363
  };
338
364
  const onPointerUp = (e) => {
365
+ var _a, _b;
339
366
  if (drag) {
340
- e.target.releasePointerCapture?.(e.pointerId);
367
+ (_b = (_a = e.target).releasePointerCapture) == null ? void 0 : _b.call(_a, e.pointerId);
341
368
  }
342
369
  setDrag(null);
343
370
  };
@@ -358,17 +385,17 @@ function FloorMapDrawer(props) {
358
385
  setTx(cx - imgX * newScale);
359
386
  setTy(cy - imgY * newScale);
360
387
  };
361
- React2.useEffect(() => {
388
+ React2__namespace.useEffect(() => {
362
389
  if (!size || !wrapperRef.current) return;
363
390
  const id = requestAnimationFrame(() => fitToContainer());
364
391
  return () => cancelAnimationFrame(id);
365
- }, [size?.width, size?.height, fitToContainer]);
392
+ }, [size == null ? void 0 : size.width, size == null ? void 0 : size.height, fitToContainer]);
366
393
  if (!size) {
367
- return /* @__PURE__ */ jsx("div", { ref: wrapperRef, className, style: { position: "relative", ...style }, children: /* @__PURE__ */ jsx("div", { style: { aspectRatio: "16/9", background: "#f6f8fa", width: "100%" } }) });
394
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { ref: wrapperRef, className, style: { position: "relative", ...style }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: { aspectRatio: "16/9", background: "#f6f8fa", width: "100%" } }) });
368
395
  }
369
396
  const { width, height } = size;
370
- return /* @__PURE__ */ jsxs("div", { ref: wrapperRef, className, style: { position: "relative", ...style }, children: [
371
- showToolbar && /* @__PURE__ */ jsx(
397
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: wrapperRef, className, style: { position: "relative", ...style }, children: [
398
+ showToolbar && /* @__PURE__ */ jsxRuntime.jsx(
372
399
  Toolbar,
373
400
  {
374
401
  mode,
@@ -381,7 +408,7 @@ function FloorMapDrawer(props) {
381
408
  canRedo: !isControlled && redoStack.length > 0
382
409
  }
383
410
  ),
384
- /* @__PURE__ */ jsxs(
411
+ /* @__PURE__ */ jsxRuntime.jsxs(
385
412
  "svg",
386
413
  {
387
414
  ref: svgRef,
@@ -396,9 +423,9 @@ function FloorMapDrawer(props) {
396
423
  role: "img",
397
424
  "aria-label": title,
398
425
  children: [
399
- title && /* @__PURE__ */ jsx("title", { children: title }),
400
- desc && /* @__PURE__ */ jsx("desc", { children: desc }),
401
- /* @__PURE__ */ jsx(
426
+ title && /* @__PURE__ */ jsxRuntime.jsx("title", { children: title }),
427
+ desc && /* @__PURE__ */ jsxRuntime.jsx("desc", { children: desc }),
428
+ /* @__PURE__ */ jsxRuntime.jsx(
402
429
  "rect",
403
430
  {
404
431
  x: 0,
@@ -410,18 +437,18 @@ function FloorMapDrawer(props) {
410
437
  style: { cursor: wantPan() ? "grab" : mode === "add" ? "crosshair" : "default" }
411
438
  }
412
439
  ),
413
- /* @__PURE__ */ jsxs("g", { transform: `matrix(${scale},0,0,${scale},${tx},${ty})`, children: [
414
- /* @__PURE__ */ jsx("image", { href: image.src, x: 0, y: 0, width, height, preserveAspectRatio: "none" }),
415
- /* @__PURE__ */ jsx("g", { stroke: lineStroke, strokeWidth: lineWidth, strokeLinecap: "round", children: eds.map((e) => {
440
+ /* @__PURE__ */ jsxRuntime.jsxs("g", { transform: `matrix(${scale},0,0,${scale},${tx},${ty})`, children: [
441
+ /* @__PURE__ */ jsxRuntime.jsx("image", { href: image.src, x: 0, y: 0, width, height, preserveAspectRatio: "none" }),
442
+ /* @__PURE__ */ jsxRuntime.jsx("g", { stroke: lineStroke, strokeWidth: lineWidth, strokeLinecap: "round", children: eds.map((e) => {
416
443
  const a = pts.find((p) => p.id === e.from);
417
444
  const b = pts.find((p) => p.id === e.to);
418
445
  if (!a || !b) return null;
419
- return /* @__PURE__ */ jsx("line", { x1: a.x, y1: a.y, x2: b.x, y2: b.y }, e.id);
446
+ return /* @__PURE__ */ jsxRuntime.jsx("line", { x1: a.x, y1: a.y, x2: b.x, y2: b.y }, e.id);
420
447
  }) }),
421
- /* @__PURE__ */ jsx("g", { children: pts.map((p) => {
448
+ /* @__PURE__ */ jsxRuntime.jsx("g", { children: pts.map((p) => {
422
449
  const active = hoverId === p.id;
423
450
  const showDelete = mode === "erase" && active;
424
- return /* @__PURE__ */ jsxs(
451
+ return /* @__PURE__ */ jsxRuntime.jsxs(
425
452
  "g",
426
453
  {
427
454
  onPointerDown: onPointPointerDown(p),
@@ -429,7 +456,7 @@ function FloorMapDrawer(props) {
429
456
  onMouseLeave: () => setHoverId((curr) => curr === p.id ? null : curr),
430
457
  style: { cursor: mode === "move" ? "grab" : mode === "erase" ? "pointer" : "default" },
431
458
  children: [
432
- /* @__PURE__ */ jsx(
459
+ /* @__PURE__ */ jsxRuntime.jsx(
433
460
  "circle",
434
461
  {
435
462
  cx: p.x,
@@ -438,7 +465,7 @@ function FloorMapDrawer(props) {
438
465
  fill: active ? activePointFill : pointFill
439
466
  }
440
467
  ),
441
- showDelete && /* @__PURE__ */ jsxs(
468
+ showDelete && /* @__PURE__ */ jsxRuntime.jsxs(
442
469
  "g",
443
470
  {
444
471
  onClick: (e) => {
@@ -447,7 +474,7 @@ function FloorMapDrawer(props) {
447
474
  },
448
475
  style: { cursor: "pointer" },
449
476
  children: [
450
- /* @__PURE__ */ jsx(
477
+ /* @__PURE__ */ jsxRuntime.jsx(
451
478
  "rect",
452
479
  {
453
480
  x: p.x + 8,
@@ -459,7 +486,7 @@ function FloorMapDrawer(props) {
459
486
  stroke: "#d0d7de"
460
487
  }
461
488
  ),
462
- /* @__PURE__ */ jsx(
489
+ /* @__PURE__ */ jsxRuntime.jsx(
463
490
  "text",
464
491
  {
465
492
  x: p.x + 17,
@@ -486,7 +513,7 @@ function FloorMapDrawer(props) {
486
513
  ] });
487
514
  }
488
515
  function Toolbar(props) {
489
- const Btn = ({ children, ...rest }) => /* @__PURE__ */ jsx(
516
+ const Btn = ({ children, ...rest }) => /* @__PURE__ */ jsxRuntime.jsx(
490
517
  "button",
491
518
  {
492
519
  ...rest,
@@ -503,7 +530,7 @@ function Toolbar(props) {
503
530
  children
504
531
  }
505
532
  );
506
- const Tab = ({ active, onClick, children }) => /* @__PURE__ */ jsx(
533
+ const Tab = ({ active, onClick, children }) => /* @__PURE__ */ jsxRuntime.jsx(
507
534
  "button",
508
535
  {
509
536
  onClick,
@@ -518,7 +545,7 @@ function Toolbar(props) {
518
545
  children
519
546
  }
520
547
  );
521
- return /* @__PURE__ */ jsxs(
548
+ return /* @__PURE__ */ jsxRuntime.jsxs(
522
549
  "div",
523
550
  {
524
551
  style: {
@@ -536,16 +563,16 @@ function Toolbar(props) {
536
563
  zIndex: 10
537
564
  },
538
565
  children: [
539
- /* @__PURE__ */ jsx(Tab, { active: props.mode === "pan", onClick: () => props.onModeChange("pan"), children: "Pan" }),
540
- /* @__PURE__ */ jsx(Tab, { active: props.mode === "add", onClick: () => props.onModeChange("add"), children: "Add" }),
541
- /* @__PURE__ */ jsx(Tab, { active: props.mode === "move", onClick: () => props.onModeChange("move"), children: "Move" }),
542
- /* @__PURE__ */ jsx(Tab, { active: props.mode === "erase", onClick: () => props.onModeChange("erase"), children: "Erase" }),
543
- /* @__PURE__ */ jsx("div", { style: { width: 1, height: 22, background: "#d0d7de", margin: "0 6px" } }),
544
- /* @__PURE__ */ jsx(Btn, { onClick: props.onFit, title: "Fit (F)", children: "Fit" }),
545
- /* @__PURE__ */ jsx(Btn, { onClick: props.onReset, title: "1:1 (1)", children: "1:1" }),
546
- /* @__PURE__ */ jsx("div", { style: { width: 1, height: 22, background: "#d0d7de", margin: "0 6px" } }),
547
- /* @__PURE__ */ jsx(Btn, { onClick: props.onUndo, disabled: !props.canUndo, title: "Undo (Ctrl/Cmd+Z)", children: "Undo" }),
548
- /* @__PURE__ */ jsx(Btn, { onClick: props.onRedo, disabled: !props.canRedo, title: "Redo (Shift+Ctrl/Cmd+Z)", children: "Redo" })
566
+ /* @__PURE__ */ jsxRuntime.jsx(Tab, { active: props.mode === "pan", onClick: () => props.onModeChange("pan"), children: "Pan" }),
567
+ /* @__PURE__ */ jsxRuntime.jsx(Tab, { active: props.mode === "add", onClick: () => props.onModeChange("add"), children: "Add" }),
568
+ /* @__PURE__ */ jsxRuntime.jsx(Tab, { active: props.mode === "move", onClick: () => props.onModeChange("move"), children: "Move" }),
569
+ /* @__PURE__ */ jsxRuntime.jsx(Tab, { active: props.mode === "erase", onClick: () => props.onModeChange("erase"), children: "Erase" }),
570
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { width: 1, height: 22, background: "#d0d7de", margin: "0 6px" } }),
571
+ /* @__PURE__ */ jsxRuntime.jsx(Btn, { onClick: props.onFit, title: "Fit (F)", children: "Fit" }),
572
+ /* @__PURE__ */ jsxRuntime.jsx(Btn, { onClick: props.onReset, title: "1:1 (1)", children: "1:1" }),
573
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { width: 1, height: 22, background: "#d0d7de", margin: "0 6px" } }),
574
+ /* @__PURE__ */ jsxRuntime.jsx(Btn, { onClick: props.onUndo, disabled: !props.canUndo, title: "Undo (Ctrl/Cmd+Z)", children: "Undo" }),
575
+ /* @__PURE__ */ jsxRuntime.jsx(Btn, { onClick: props.onRedo, disabled: !props.canRedo, title: "Redo (Shift+Ctrl/Cmd+Z)", children: "Redo" })
549
576
  ]
550
577
  }
551
578
  );
@@ -566,7 +593,7 @@ var getClosestPointOnSegment = (px, py, x1, y1, x2, y2) => {
566
593
  };
567
594
  };
568
595
  var usePoints = (initialPoints) => {
569
- const [points, setPoints] = useState(
596
+ const [points, setPoints] = React2.useState(
570
597
  () => initialPoints.map((p, i) => ({ id: i + 1, x: p.x, y: p.y }))
571
598
  );
572
599
  return { points, setPoints };
@@ -575,7 +602,7 @@ var useZoom = (stage) => {
575
602
  const MIN_SCALE = 0.5;
576
603
  const MAX_SCALE = 5;
577
604
  const DEFAULT_SCALE = 1;
578
- const [stageScale, setStageScale] = useState(DEFAULT_SCALE);
605
+ const [stageScale, setStageScale] = React2.useState(DEFAULT_SCALE);
579
606
  return {
580
607
  stageScale,
581
608
  setStageScale,
@@ -583,7 +610,7 @@ var useZoom = (stage) => {
583
610
  MAX_SCALE
584
611
  };
585
612
  };
586
- var Container = styled.div`
613
+ var Container = styled__default.default.div`
587
614
  overflow: hidden;
588
615
  width:1200px;
589
616
  height:1200px;
@@ -592,7 +619,7 @@ var Container = styled.div`
592
619
  border:1px solid #ccc;
593
620
  border-radius:4px;
594
621
  `;
595
- var NavContainer = styled.div`
622
+ var NavContainer = styled__default.default.div`
596
623
  width:80px;
597
624
  height:100%;
598
625
  background:red;
@@ -606,12 +633,12 @@ var NavContainer = styled.div`
606
633
  background:#ebebeb;
607
634
  border-left:1px solid #ccc;
608
635
  `;
609
- var CanvasContainer = styled.div`
636
+ var CanvasContainer = styled__default.default.div`
610
637
  width:calc(100% - 80px);
611
638
  height:100%;
612
639
  overflow: hidden;
613
640
  `;
614
- var ButtonBase = styled.button`
641
+ var ButtonBase = styled__default.default.button`
615
642
  padding:2px;
616
643
  background:white;
617
644
  border:none;
@@ -630,24 +657,24 @@ var ButtonBase = styled.button`
630
657
  cursor:not-allowed;
631
658
  }
632
659
  `;
633
- var Button = styled(ButtonBase)``;
660
+ var Button = styled__default.default(ButtonBase)``;
634
661
  var Mapper = ({
635
662
  src = "https://konvajs.org/assets/line-building.png",
636
663
  initialPoints = [],
637
664
  maxWidth = 1200
638
665
  }) => {
639
- const stageRef = useRef(null);
666
+ const stageRef = React2.useRef(null);
640
667
  const { points, setPoints } = usePoints(initialPoints);
641
- const { stageScale, setStageScale, MAX_SCALE, MIN_SCALE } = useZoom(stageRef?.current);
668
+ const { stageScale, setStageScale, MAX_SCALE, MIN_SCALE } = useZoom(stageRef == null ? void 0 : stageRef.current);
642
669
  const SCALE_BY = 1.2;
643
- const [closed, setClosed] = useState(initialPoints.length >= 3);
644
- const [hoveringFirst, setHoveringFirst] = useState(false);
645
- const [stagePosition, setStagePosition] = useState({ x: 0, y: 0 });
646
- const [dragStart, setDragStart] = useState(null);
647
- const [isDraggingPoint, setIsDraggingPoint] = useState(false);
648
- const [image] = useImage(src, "anonymous");
649
- const imgW = image?.width || 1;
650
- const imgH = image?.height || 1;
670
+ const [closed, setClosed] = React2.useState(initialPoints.length >= 3);
671
+ const [hoveringFirst, setHoveringFirst] = React2.useState(false);
672
+ const [stagePosition, setStagePosition] = React2.useState({ x: 0, y: 0 });
673
+ const [dragStart, setDragStart] = React2.useState(null);
674
+ const [isDraggingPoint, setIsDraggingPoint] = React2.useState(false);
675
+ const [image] = useImage__default.default(src, "anonymous");
676
+ const imgW = (image == null ? void 0 : image.width) || 1;
677
+ const imgH = (image == null ? void 0 : image.height) || 1;
651
678
  const scale = maxWidth / imgW;
652
679
  const stageSize = { width: maxWidth, height: imgH * scale };
653
680
  const DRAG_THRESHOLD = 5;
@@ -768,13 +795,13 @@ var Mapper = ({
768
795
  }
769
796
  return null;
770
797
  };
771
- useEffect(() => {
798
+ React2.useEffect(() => {
772
799
  if (image) {
773
800
  const initialPos = getConstrainedPosition({ x: 0, y: 0 }, 1);
774
801
  setStagePosition(initialPos);
775
802
  }
776
803
  }, [image]);
777
- useEffect(() => {
804
+ React2.useEffect(() => {
778
805
  const handleKeyDown = (e) => {
779
806
  if (e.ctrlKey || e.metaKey) {
780
807
  if (e.key === "=" || e.key === "+") {
@@ -822,7 +849,7 @@ var Mapper = ({
822
849
  const y = (pos.y - stagePosition.y) / (scale * stageScale);
823
850
  return { x, y };
824
851
  };
825
- const linePointsScaled = useMemo(() => {
852
+ const linePointsScaled = React2.useMemo(() => {
826
853
  const flat = points.flatMap((p) => [p.x * scale, p.y * scale]);
827
854
  return flat;
828
855
  }, [points, scale]);
@@ -915,9 +942,9 @@ var Mapper = ({
915
942
  const dist = Math.hypot(dx, dy);
916
943
  setHoveringFirst(dist < 15);
917
944
  };
918
- return /* @__PURE__ */ jsxs(Container, { children: [
919
- /* @__PURE__ */ jsx(CanvasContainer, { children: /* @__PURE__ */ jsx(
920
- Stage,
945
+ return /* @__PURE__ */ jsxRuntime.jsxs(Container, { children: [
946
+ /* @__PURE__ */ jsxRuntime.jsx(CanvasContainer, { children: /* @__PURE__ */ jsxRuntime.jsx(
947
+ reactKonva.Stage,
921
948
  {
922
949
  ref: stageRef,
923
950
  width: 1200,
@@ -934,9 +961,9 @@ var Mapper = ({
934
961
  onDragStart: handleStageDragStart,
935
962
  onDragEnd: handleStageDragEnd,
936
963
  dragBoundFunc: (pos) => getConstrainedPosition(pos, stageScale),
937
- children: /* @__PURE__ */ jsxs(Layer, { children: [
938
- /* @__PURE__ */ jsx(
939
- Image$1,
964
+ children: /* @__PURE__ */ jsxRuntime.jsxs(reactKonva.Layer, { children: [
965
+ /* @__PURE__ */ jsxRuntime.jsx(
966
+ reactKonva.Image,
940
967
  {
941
968
  image,
942
969
  width: stageSize.width,
@@ -944,8 +971,8 @@ var Mapper = ({
944
971
  listening: false
945
972
  }
946
973
  ),
947
- points.length >= 2 && /* @__PURE__ */ jsx(
948
- Line,
974
+ points.length >= 2 && /* @__PURE__ */ jsxRuntime.jsx(
975
+ reactKonva.Line,
949
976
  {
950
977
  points: linePointsScaled,
951
978
  closed,
@@ -958,8 +985,8 @@ var Mapper = ({
958
985
  hitStrokeWidth: LINE_HIT_THRESHOLD / stageScale
959
986
  }
960
987
  ),
961
- /* @__PURE__ */ jsx(Group, { children: points.map((p, i) => /* @__PURE__ */ jsx(
962
- Circle,
988
+ /* @__PURE__ */ jsxRuntime.jsx(reactKonva.Group, { children: points.map((p, i) => /* @__PURE__ */ jsxRuntime.jsx(
989
+ reactKonva.Circle,
963
990
  {
964
991
  name: "point",
965
992
  x: p.x * scale,
@@ -978,26 +1005,26 @@ var Mapper = ({
978
1005
  ] })
979
1006
  }
980
1007
  ) }),
981
- /* @__PURE__ */ jsxs(NavContainer, { children: [
982
- /* @__PURE__ */ jsx(
1008
+ /* @__PURE__ */ jsxRuntime.jsxs(NavContainer, { children: [
1009
+ /* @__PURE__ */ jsxRuntime.jsx(
983
1010
  Button,
984
1011
  {
985
1012
  onClick: handleZoomIn,
986
1013
  disabled: stageScale >= MAX_SCALE,
987
1014
  title: "Zoom In (Ctrl/Cmd + +)",
988
- children: /* @__PURE__ */ jsx(ZoomIn, { style: { width: "20px", height: "20px" } })
1015
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ZoomIn, { style: { width: "20px", height: "20px" } })
989
1016
  }
990
1017
  ),
991
- /* @__PURE__ */ jsx(
1018
+ /* @__PURE__ */ jsxRuntime.jsx(
992
1019
  Button,
993
1020
  {
994
1021
  onClick: handleZoomOut,
995
1022
  disabled: stageScale <= MIN_SCALE,
996
1023
  title: "Zoom Out (Ctrl/Cmd + -)",
997
- children: /* @__PURE__ */ jsx(ZoomOut, { style: { width: "20px", height: "20px" } })
1024
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ZoomOut, { style: { width: "20px", height: "20px" } })
998
1025
  }
999
1026
  ),
1000
- /* @__PURE__ */ jsxs(
1027
+ /* @__PURE__ */ jsxRuntime.jsxs(
1001
1028
  Button,
1002
1029
  {
1003
1030
  onClick: handleResetZoom,
@@ -1012,6 +1039,8 @@ var Mapper = ({
1012
1039
  ] });
1013
1040
  };
1014
1041
 
1015
- export { FloorMapDrawer, ImageWithPoints, Mapper };
1016
- //# sourceMappingURL=index.mjs.map
1017
- //# sourceMappingURL=index.mjs.map
1042
+ exports.FloorMapDrawer = FloorMapDrawer;
1043
+ exports.ImageWithPoints = ImageWithPoints;
1044
+ exports.Mapper = Mapper;
1045
+ //# sourceMappingURL=index.cjs.map
1046
+ //# sourceMappingURL=index.cjs.map