react-floor-mapper 0.1.6 → 0.1.8
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/{index.mjs → index.cjs} +156 -127
- package/dist/index.cjs.map +1 -0
- package/dist/{index.d.mts → index.d.cts} +7 -19
- package/dist/index.d.ts +7 -19
- package/dist/index.js +127 -152
- package/dist/index.js.map +1 -1
- package/dist/lite.cjs +480 -0
- package/dist/lite.cjs.map +1 -0
- package/dist/lite.d.cts +16 -0
- package/dist/lite.d.ts +16 -0
- package/dist/lite.js +473 -0
- package/dist/lite.js.map +1 -0
- package/package.json +7 -5
- package/dist/index.mjs.map +0 -1
package/dist/lite.js
ADDED
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
import { useRef, useState, useEffect, useMemo } from 'react';
|
|
2
|
+
import { Stage, Layer, Image, Line, Group, Circle } from 'react-konva';
|
|
3
|
+
import useImage from 'use-image';
|
|
4
|
+
import { ZoomIn, ZoomOut } from 'lucide-react';
|
|
5
|
+
import styled from 'styled-components';
|
|
6
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
7
|
+
|
|
8
|
+
// src/components/MapperEditor/Mapper.tsx
|
|
9
|
+
|
|
10
|
+
// src/utils/closest-segment-point.ts
|
|
11
|
+
var getClosestPointOnSegment = (px, py, x1, y1, x2, y2) => {
|
|
12
|
+
const dx = x2 - x1;
|
|
13
|
+
const dy = y2 - y1;
|
|
14
|
+
const lengthSquared = dx * dx + dy * dy;
|
|
15
|
+
if (lengthSquared === 0) return { x: x1, y: y1, t: 0 };
|
|
16
|
+
let t = ((px - x1) * dx + (py - y1) * dy) / lengthSquared;
|
|
17
|
+
t = Math.max(0, Math.min(1, t));
|
|
18
|
+
return {
|
|
19
|
+
x: x1 + t * dx,
|
|
20
|
+
y: y1 + t * dy,
|
|
21
|
+
t
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
var usePoints = (initialPoints) => {
|
|
25
|
+
const [points, setPoints] = useState(
|
|
26
|
+
() => initialPoints.map((p, i) => ({ id: i + 1, x: p.x, y: p.y }))
|
|
27
|
+
);
|
|
28
|
+
return { points, setPoints };
|
|
29
|
+
};
|
|
30
|
+
var useZoom = (stage) => {
|
|
31
|
+
const MIN_SCALE = 0.5;
|
|
32
|
+
const MAX_SCALE = 5;
|
|
33
|
+
const DEFAULT_SCALE = 1;
|
|
34
|
+
const [stageScale, setStageScale] = useState(DEFAULT_SCALE);
|
|
35
|
+
return {
|
|
36
|
+
stageScale,
|
|
37
|
+
setStageScale,
|
|
38
|
+
MIN_SCALE,
|
|
39
|
+
MAX_SCALE
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
var Container = styled.div`
|
|
43
|
+
overflow: hidden;
|
|
44
|
+
width:1200px;
|
|
45
|
+
height:1200px;
|
|
46
|
+
display: flex;
|
|
47
|
+
align-items: stretch;
|
|
48
|
+
border:1px solid #ccc;
|
|
49
|
+
border-radius:4px;
|
|
50
|
+
`;
|
|
51
|
+
var NavContainer = styled.div`
|
|
52
|
+
width:80px;
|
|
53
|
+
height:100%;
|
|
54
|
+
background:red;
|
|
55
|
+
flex-shrink:0;
|
|
56
|
+
display: flex;
|
|
57
|
+
justify-content: flex-start;
|
|
58
|
+
align-items: center;
|
|
59
|
+
flex-direction:column;
|
|
60
|
+
gap:20px;
|
|
61
|
+
padding:20px 0;
|
|
62
|
+
background:#ebebeb;
|
|
63
|
+
border-left:1px solid #ccc;
|
|
64
|
+
`;
|
|
65
|
+
var CanvasContainer = styled.div`
|
|
66
|
+
width:calc(100% - 80px);
|
|
67
|
+
height:100%;
|
|
68
|
+
overflow: hidden;
|
|
69
|
+
`;
|
|
70
|
+
var ButtonBase = styled.button`
|
|
71
|
+
padding:2px;
|
|
72
|
+
background:white;
|
|
73
|
+
border:none;
|
|
74
|
+
border-radius:8px;
|
|
75
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
76
|
+
cursor: pointer;
|
|
77
|
+
display: flex;
|
|
78
|
+
justify-content: center;
|
|
79
|
+
align-items: center;
|
|
80
|
+
font-size:12px;
|
|
81
|
+
min-width:50px;
|
|
82
|
+
min-height:50px;
|
|
83
|
+
border-left:1px solid #ccc;
|
|
84
|
+
&:disabled:{
|
|
85
|
+
opacity:0.5;
|
|
86
|
+
cursor:not-allowed;
|
|
87
|
+
}
|
|
88
|
+
`;
|
|
89
|
+
var Button = styled(ButtonBase)``;
|
|
90
|
+
var Mapper = ({
|
|
91
|
+
src = "https://konvajs.org/assets/line-building.png",
|
|
92
|
+
initialPoints = [],
|
|
93
|
+
maxWidth = 1200
|
|
94
|
+
}) => {
|
|
95
|
+
const stageRef = useRef(null);
|
|
96
|
+
const { points, setPoints } = usePoints(initialPoints);
|
|
97
|
+
const { stageScale, setStageScale, MAX_SCALE, MIN_SCALE } = useZoom(stageRef == null ? void 0 : stageRef.current);
|
|
98
|
+
const SCALE_BY = 1.2;
|
|
99
|
+
const [closed, setClosed] = useState(initialPoints.length >= 3);
|
|
100
|
+
const [hoveringFirst, setHoveringFirst] = useState(false);
|
|
101
|
+
const [stagePosition, setStagePosition] = useState({ x: 0, y: 0 });
|
|
102
|
+
const [dragStart, setDragStart] = useState(null);
|
|
103
|
+
const [isDraggingPoint, setIsDraggingPoint] = useState(false);
|
|
104
|
+
const [image] = useImage(src, "anonymous");
|
|
105
|
+
const imgW = (image == null ? void 0 : image.width) || 1;
|
|
106
|
+
const imgH = (image == null ? void 0 : image.height) || 1;
|
|
107
|
+
const scale = maxWidth / imgW;
|
|
108
|
+
const stageSize = { width: maxWidth, height: imgH * scale };
|
|
109
|
+
const DRAG_THRESHOLD = 5;
|
|
110
|
+
const LINE_HIT_THRESHOLD = 10;
|
|
111
|
+
const handleZoomIn = () => {
|
|
112
|
+
const stage = stageRef.current;
|
|
113
|
+
if (!stage) return;
|
|
114
|
+
const oldScale = stageScale;
|
|
115
|
+
const newScale = Math.min(oldScale * SCALE_BY, MAX_SCALE);
|
|
116
|
+
if (newScale === oldScale) return;
|
|
117
|
+
const centerX = stage.width() / 2;
|
|
118
|
+
const centerY = stage.height() / 2;
|
|
119
|
+
const pointTo = {
|
|
120
|
+
x: (centerX - stagePosition.x) / oldScale,
|
|
121
|
+
y: (centerY - stagePosition.y) / oldScale
|
|
122
|
+
};
|
|
123
|
+
const newPos = {
|
|
124
|
+
x: centerX - pointTo.x * newScale,
|
|
125
|
+
y: centerY - pointTo.y * newScale
|
|
126
|
+
};
|
|
127
|
+
const constrainedPos = getConstrainedPosition(newPos, newScale);
|
|
128
|
+
setStageScale(newScale);
|
|
129
|
+
setStagePosition(constrainedPos);
|
|
130
|
+
};
|
|
131
|
+
const handleZoomOut = () => {
|
|
132
|
+
const stage = stageRef.current;
|
|
133
|
+
if (!stage) return;
|
|
134
|
+
const oldScale = stageScale;
|
|
135
|
+
const newScale = Math.max(oldScale / SCALE_BY, MIN_SCALE);
|
|
136
|
+
if (newScale === oldScale) return;
|
|
137
|
+
const centerX = stage.width() / 2;
|
|
138
|
+
const centerY = stage.height() / 2;
|
|
139
|
+
const pointTo = {
|
|
140
|
+
x: (centerX - stagePosition.x) / oldScale,
|
|
141
|
+
y: (centerY - stagePosition.y) / oldScale
|
|
142
|
+
};
|
|
143
|
+
const newPos = {
|
|
144
|
+
x: centerX - pointTo.x * newScale,
|
|
145
|
+
y: centerY - pointTo.y * newScale
|
|
146
|
+
};
|
|
147
|
+
const constrainedPos = getConstrainedPosition(newPos, newScale);
|
|
148
|
+
setStageScale(newScale);
|
|
149
|
+
setStagePosition(constrainedPos);
|
|
150
|
+
};
|
|
151
|
+
const handleResetZoom = () => {
|
|
152
|
+
const newScale = 1;
|
|
153
|
+
const constrainedPos = getConstrainedPosition({ x: 0, y: 0 }, newScale);
|
|
154
|
+
setStageScale(newScale);
|
|
155
|
+
setStagePosition(constrainedPos);
|
|
156
|
+
};
|
|
157
|
+
const handleWheel = (e) => {
|
|
158
|
+
e.evt.preventDefault();
|
|
159
|
+
const stage = stageRef.current;
|
|
160
|
+
if (!stage) return;
|
|
161
|
+
const oldScale = stageScale;
|
|
162
|
+
const pointer = stage.getPointerPosition();
|
|
163
|
+
if (!pointer) return;
|
|
164
|
+
const mousePointTo = {
|
|
165
|
+
x: (pointer.x - stagePosition.x) / oldScale,
|
|
166
|
+
y: (pointer.y - stagePosition.y) / oldScale
|
|
167
|
+
};
|
|
168
|
+
const direction = e.evt.deltaY > 0 ? -1 : 1;
|
|
169
|
+
const newScale = direction > 0 ? Math.min(oldScale * SCALE_BY, MAX_SCALE) : Math.max(oldScale / SCALE_BY, MIN_SCALE);
|
|
170
|
+
if (newScale === oldScale) return;
|
|
171
|
+
const newPos = {
|
|
172
|
+
x: pointer.x - mousePointTo.x * newScale,
|
|
173
|
+
y: pointer.y - mousePointTo.y * newScale
|
|
174
|
+
};
|
|
175
|
+
const constrainedPos = getConstrainedPosition(newPos, newScale);
|
|
176
|
+
setStageScale(newScale);
|
|
177
|
+
setStagePosition(constrainedPos);
|
|
178
|
+
};
|
|
179
|
+
const getConstrainedPosition = (pos, currentScale) => {
|
|
180
|
+
const stage = stageRef.current;
|
|
181
|
+
if (!stage) return pos;
|
|
182
|
+
const stageWidth = stage.width();
|
|
183
|
+
const stageHeight = stage.height();
|
|
184
|
+
const imageWidth = stageSize.width * currentScale;
|
|
185
|
+
const imageHeight = stageSize.height * currentScale;
|
|
186
|
+
let newX = pos.x;
|
|
187
|
+
let newY = pos.y;
|
|
188
|
+
if (imageWidth > stageWidth) {
|
|
189
|
+
if (newX > 0) newX = 0;
|
|
190
|
+
if (newX < stageWidth - imageWidth) newX = stageWidth - imageWidth;
|
|
191
|
+
} else {
|
|
192
|
+
newX = (stageWidth - imageWidth) / 2;
|
|
193
|
+
}
|
|
194
|
+
if (imageHeight > stageHeight) {
|
|
195
|
+
if (newY > 0) newY = 0;
|
|
196
|
+
if (newY < stageHeight - imageHeight) newY = stageHeight - imageHeight;
|
|
197
|
+
} else {
|
|
198
|
+
newY = (stageHeight - imageHeight) / 2;
|
|
199
|
+
}
|
|
200
|
+
return { x: newX, y: newY };
|
|
201
|
+
};
|
|
202
|
+
const findLineSegmentNearClick = (clickX, clickY) => {
|
|
203
|
+
if (points.length < 2) return null;
|
|
204
|
+
const threshold = LINE_HIT_THRESHOLD / (scale * stageScale);
|
|
205
|
+
const segments = [];
|
|
206
|
+
for (let i = 0; i < points.length - 1; i++) {
|
|
207
|
+
segments.push({ start: i, end: i + 1 });
|
|
208
|
+
}
|
|
209
|
+
if (closed) {
|
|
210
|
+
segments.push({ start: points.length - 1, end: 0 });
|
|
211
|
+
}
|
|
212
|
+
for (const segment of segments) {
|
|
213
|
+
const p1 = points[segment.start];
|
|
214
|
+
const p2 = points[segment.end];
|
|
215
|
+
const closest = getClosestPointOnSegment(clickX, clickY, p1.x, p1.y, p2.x, p2.y);
|
|
216
|
+
const distance = Math.hypot(closest.x - clickX, closest.y - clickY);
|
|
217
|
+
if (distance < threshold) {
|
|
218
|
+
return {
|
|
219
|
+
segmentIndex: segment.start,
|
|
220
|
+
insertPosition: closest.t,
|
|
221
|
+
point: { x: closest.x, y: closest.y }
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return null;
|
|
226
|
+
};
|
|
227
|
+
useEffect(() => {
|
|
228
|
+
if (image) {
|
|
229
|
+
const initialPos = getConstrainedPosition({ x: 0, y: 0 }, 1);
|
|
230
|
+
setStagePosition(initialPos);
|
|
231
|
+
}
|
|
232
|
+
}, [image]);
|
|
233
|
+
useEffect(() => {
|
|
234
|
+
const handleKeyDown = (e) => {
|
|
235
|
+
if (e.ctrlKey || e.metaKey) {
|
|
236
|
+
if (e.key === "=" || e.key === "+") {
|
|
237
|
+
e.preventDefault();
|
|
238
|
+
handleZoomIn();
|
|
239
|
+
} else if (e.key === "-") {
|
|
240
|
+
e.preventDefault();
|
|
241
|
+
handleZoomOut();
|
|
242
|
+
} else if (e.key === "0") {
|
|
243
|
+
e.preventDefault();
|
|
244
|
+
handleResetZoom();
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
249
|
+
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
250
|
+
}, [stageScale, stagePosition]);
|
|
251
|
+
const handleStageDragStart = (e) => {
|
|
252
|
+
const clickedShape = e.target;
|
|
253
|
+
if (clickedShape && clickedShape.name() === "point") {
|
|
254
|
+
e.target.stopDrag();
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const stage = e.target.getStage();
|
|
258
|
+
if (!stage) return;
|
|
259
|
+
const pos = stage.getPointerPosition();
|
|
260
|
+
if (pos) {
|
|
261
|
+
setDragStart(pos);
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
const handleStageDragEnd = (e) => {
|
|
265
|
+
const newPos = {
|
|
266
|
+
x: e.target.x(),
|
|
267
|
+
y: e.target.y()
|
|
268
|
+
};
|
|
269
|
+
const constrainedPos = getConstrainedPosition(newPos, stageScale);
|
|
270
|
+
setStagePosition(constrainedPos);
|
|
271
|
+
setDragStart(null);
|
|
272
|
+
};
|
|
273
|
+
const toImageCoords = (stage) => {
|
|
274
|
+
if (!stage) return { x: 0, y: 0 };
|
|
275
|
+
const pos = stage.getPointerPosition();
|
|
276
|
+
if (!pos) return { x: 0, y: 0 };
|
|
277
|
+
const x = (pos.x - stagePosition.x) / (scale * stageScale);
|
|
278
|
+
const y = (pos.y - stagePosition.y) / (scale * stageScale);
|
|
279
|
+
return { x, y };
|
|
280
|
+
};
|
|
281
|
+
const linePointsScaled = useMemo(() => {
|
|
282
|
+
const flat = points.flatMap((p) => [p.x * scale, p.y * scale]);
|
|
283
|
+
return flat;
|
|
284
|
+
}, [points, scale]);
|
|
285
|
+
const commit = (nextPoints) => {
|
|
286
|
+
setPoints(nextPoints);
|
|
287
|
+
};
|
|
288
|
+
const handlePointDragStart = (e) => {
|
|
289
|
+
e.cancelBubble = true;
|
|
290
|
+
setIsDraggingPoint(true);
|
|
291
|
+
};
|
|
292
|
+
const handlePointDragMove = (id, e) => {
|
|
293
|
+
const newX = e.target.x() / scale;
|
|
294
|
+
const newY = e.target.y() / scale;
|
|
295
|
+
const updatedPoints = points.map(
|
|
296
|
+
(p) => p.id === id ? { ...p, x: newX, y: newY } : p
|
|
297
|
+
);
|
|
298
|
+
setPoints(updatedPoints);
|
|
299
|
+
};
|
|
300
|
+
const handlePointDragEnd = (e) => {
|
|
301
|
+
e.cancelBubble = true;
|
|
302
|
+
setIsDraggingPoint(false);
|
|
303
|
+
};
|
|
304
|
+
const handleStageMouseDown = (e) => {
|
|
305
|
+
if (!image) return;
|
|
306
|
+
const clickedShape = e.target;
|
|
307
|
+
if (clickedShape && clickedShape.name() === "point") {
|
|
308
|
+
if (!closed) {
|
|
309
|
+
const clickedIndex = points.findIndex(
|
|
310
|
+
(p) => Math.abs(p.x * scale - clickedShape.x()) < 1 && Math.abs(p.y * scale - clickedShape.y()) < 1
|
|
311
|
+
);
|
|
312
|
+
if (clickedIndex === 0 && points.length >= 3) {
|
|
313
|
+
setClosed(true);
|
|
314
|
+
setHoveringFirst(false);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
const stage = e.target.getStage();
|
|
320
|
+
if (!stage) return;
|
|
321
|
+
const pos = stage.getPointerPosition();
|
|
322
|
+
if (pos) {
|
|
323
|
+
setDragStart(pos);
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
const handleStageMouseUp = (e) => {
|
|
327
|
+
if (!image || isDraggingPoint) return;
|
|
328
|
+
const clickedShape = e.target;
|
|
329
|
+
if (clickedShape && clickedShape.name() === "point") {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
if (dragStart) {
|
|
333
|
+
const stage = e.target.getStage();
|
|
334
|
+
if (!stage) return;
|
|
335
|
+
const currentPos = stage.getPointerPosition();
|
|
336
|
+
if (currentPos) {
|
|
337
|
+
const dx = currentPos.x - dragStart.x;
|
|
338
|
+
const dy = currentPos.y - dragStart.y;
|
|
339
|
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
340
|
+
if (distance < DRAG_THRESHOLD) {
|
|
341
|
+
const p = toImageCoords(stage);
|
|
342
|
+
const lineHit = findLineSegmentNearClick(p.x, p.y);
|
|
343
|
+
if (lineHit) {
|
|
344
|
+
const newPoint = {
|
|
345
|
+
id: Date.now(),
|
|
346
|
+
x: lineHit.point.x,
|
|
347
|
+
y: lineHit.point.y
|
|
348
|
+
};
|
|
349
|
+
const newPoints = [...points];
|
|
350
|
+
newPoints.splice(lineHit.segmentIndex + 1, 0, newPoint);
|
|
351
|
+
commit(newPoints);
|
|
352
|
+
} else if (!closed) {
|
|
353
|
+
const next = [...points, { id: Date.now(), x: p.x, y: p.y }];
|
|
354
|
+
commit(next);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
setDragStart(null);
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
const handleMouseMove = (e) => {
|
|
362
|
+
if (closed || points.length < 3) {
|
|
363
|
+
setHoveringFirst(false);
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
const stage = e.target.getStage();
|
|
367
|
+
const p = toImageCoords(stage);
|
|
368
|
+
const fp = points[0];
|
|
369
|
+
const dx = (p.x - fp.x) * scale * stageScale;
|
|
370
|
+
const dy = (p.y - fp.y) * scale * stageScale;
|
|
371
|
+
const dist = Math.hypot(dx, dy);
|
|
372
|
+
setHoveringFirst(dist < 15);
|
|
373
|
+
};
|
|
374
|
+
return /* @__PURE__ */ jsxs(Container, { children: [
|
|
375
|
+
/* @__PURE__ */ jsx(CanvasContainer, { children: /* @__PURE__ */ jsx(
|
|
376
|
+
Stage,
|
|
377
|
+
{
|
|
378
|
+
ref: stageRef,
|
|
379
|
+
width: 1200,
|
|
380
|
+
height: 1200,
|
|
381
|
+
onMouseDown: handleStageMouseDown,
|
|
382
|
+
onMouseUp: handleStageMouseUp,
|
|
383
|
+
onMouseMove: handleMouseMove,
|
|
384
|
+
onWheel: handleWheel,
|
|
385
|
+
scaleX: stageScale,
|
|
386
|
+
scaleY: stageScale,
|
|
387
|
+
x: stagePosition.x,
|
|
388
|
+
y: stagePosition.y,
|
|
389
|
+
draggable: !isDraggingPoint,
|
|
390
|
+
onDragStart: handleStageDragStart,
|
|
391
|
+
onDragEnd: handleStageDragEnd,
|
|
392
|
+
dragBoundFunc: (pos) => getConstrainedPosition(pos, stageScale),
|
|
393
|
+
children: /* @__PURE__ */ jsxs(Layer, { children: [
|
|
394
|
+
/* @__PURE__ */ jsx(
|
|
395
|
+
Image,
|
|
396
|
+
{
|
|
397
|
+
image,
|
|
398
|
+
width: stageSize.width,
|
|
399
|
+
height: stageSize.height,
|
|
400
|
+
listening: false
|
|
401
|
+
}
|
|
402
|
+
),
|
|
403
|
+
points.length >= 2 && /* @__PURE__ */ jsx(
|
|
404
|
+
Line,
|
|
405
|
+
{
|
|
406
|
+
points: linePointsScaled,
|
|
407
|
+
closed,
|
|
408
|
+
stroke: "#2563eb",
|
|
409
|
+
strokeWidth: 2 / stageScale,
|
|
410
|
+
lineCap: "round",
|
|
411
|
+
lineJoin: "round",
|
|
412
|
+
tension: 0,
|
|
413
|
+
fill: closed ? "rgba(37, 99, 235, 0.3)" : void 0,
|
|
414
|
+
hitStrokeWidth: LINE_HIT_THRESHOLD / stageScale
|
|
415
|
+
}
|
|
416
|
+
),
|
|
417
|
+
/* @__PURE__ */ jsx(Group, { children: points.map((p, i) => /* @__PURE__ */ jsx(
|
|
418
|
+
Circle,
|
|
419
|
+
{
|
|
420
|
+
name: "point",
|
|
421
|
+
x: p.x * scale,
|
|
422
|
+
y: p.y * scale,
|
|
423
|
+
radius: (i === 0 && hoveringFirst ? 10 : 6) / stageScale,
|
|
424
|
+
fill: i === 0 ? "#ef4444" : "#7e9de1",
|
|
425
|
+
stroke: i === 0 && hoveringFirst ? "#fbbf24" : void 0,
|
|
426
|
+
strokeWidth: i === 0 && hoveringFirst ? 2 / stageScale : 0,
|
|
427
|
+
draggable: true,
|
|
428
|
+
onDragStart: handlePointDragStart,
|
|
429
|
+
onDragMove: (e) => handlePointDragMove(p.id, e),
|
|
430
|
+
onDragEnd: handlePointDragEnd
|
|
431
|
+
},
|
|
432
|
+
p.id
|
|
433
|
+
)) })
|
|
434
|
+
] })
|
|
435
|
+
}
|
|
436
|
+
) }),
|
|
437
|
+
/* @__PURE__ */ jsxs(NavContainer, { children: [
|
|
438
|
+
/* @__PURE__ */ jsx(
|
|
439
|
+
Button,
|
|
440
|
+
{
|
|
441
|
+
onClick: handleZoomIn,
|
|
442
|
+
disabled: stageScale >= MAX_SCALE,
|
|
443
|
+
title: "Zoom In (Ctrl/Cmd + +)",
|
|
444
|
+
children: /* @__PURE__ */ jsx(ZoomIn, { style: { width: "20px", height: "20px" } })
|
|
445
|
+
}
|
|
446
|
+
),
|
|
447
|
+
/* @__PURE__ */ jsx(
|
|
448
|
+
Button,
|
|
449
|
+
{
|
|
450
|
+
onClick: handleZoomOut,
|
|
451
|
+
disabled: stageScale <= MIN_SCALE,
|
|
452
|
+
title: "Zoom Out (Ctrl/Cmd + -)",
|
|
453
|
+
children: /* @__PURE__ */ jsx(ZoomOut, { style: { width: "20px", height: "20px" } })
|
|
454
|
+
}
|
|
455
|
+
),
|
|
456
|
+
/* @__PURE__ */ jsxs(
|
|
457
|
+
Button,
|
|
458
|
+
{
|
|
459
|
+
onClick: handleResetZoom,
|
|
460
|
+
title: "Reset Zoom (Ctrl/Cmd + 0)",
|
|
461
|
+
children: [
|
|
462
|
+
Math.round(stageScale * 100),
|
|
463
|
+
"%"
|
|
464
|
+
]
|
|
465
|
+
}
|
|
466
|
+
)
|
|
467
|
+
] })
|
|
468
|
+
] });
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
export { Mapper };
|
|
472
|
+
//# sourceMappingURL=lite.js.map
|
|
473
|
+
//# sourceMappingURL=lite.js.map
|
package/dist/lite.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/closest-segment-point.ts","../src/components/MapperEditor/hooks/usePoints.ts","../src/components/MapperEditor/hooks/useZoom.ts","../src/components/MapperEditor/Mapper.style.tsx","../src/components/MapperEditor/Mapper.tsx"],"names":["useState","KonvaImage"],"mappings":";;;;;;;;;;AAAO,IAAM,2BAA2B,CAChC,EAAA,EAAY,IACZ,EAAA,EAAY,EAAA,EACZ,IAAY,EAAA,KACf;AACD,EAAA,MAAM,KAAK,EAAA,GAAK,EAAA;AAChB,EAAA,MAAM,KAAK,EAAA,GAAK,EAAA;AAChB,EAAA,MAAM,aAAA,GAAgB,EAAA,GAAK,EAAA,GAAK,EAAA,GAAK,EAAA;AAErC,EAAA,IAAI,aAAA,KAAkB,GAAG,OAAO,EAAE,GAAG,EAAA,EAAI,CAAA,EAAG,EAAA,EAAI,CAAA,EAAG,CAAA,EAAE;AAErD,EAAA,IAAI,MAAM,EAAA,GAAK,EAAA,IAAM,EAAA,GAAA,CAAM,EAAA,GAAK,MAAM,EAAA,IAAM,aAAA;AAC5C,EAAA,CAAA,GAAI,KAAK,GAAA,CAAI,CAAA,EAAG,KAAK,GAAA,CAAI,CAAA,EAAG,CAAC,CAAC,CAAA;AAE9B,EAAA,OAAO;AAAA,IACH,CAAA,EAAG,KAAK,CAAA,GAAI,EAAA;AAAA,IACZ,CAAA,EAAG,KAAK,CAAA,GAAI,EAAA;AAAA,IACZ;AAAA,GACJ;AACJ,CAAA;AChBO,IAAM,SAAA,GAAY,CAAC,aAAA,KAAuC;AAC7D,EAAA,MAAM,CAAC,MAAA,EAAQ,SAAS,CAAA,GAAI,QAAA;AAAA,IAAiB,MACzC,aAAA,CAAc,GAAA,CAAI,CAAC,CAAA,EAAG,OAAO,EAAE,EAAA,EAAI,CAAA,GAAI,CAAA,EAAG,GAAG,CAAA,CAAE,CAAA,EAAG,CAAA,EAAG,CAAA,CAAE,GAAE,CAAE;AAAA,GAC/D;AAEA,EAAA,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E,OAAO,MAAA,EAAQ,MAAA,EAAQ,QAAO,EAAG;AAAA;AAAA,OACrD;AAAA,sBACA,IAAA;AAAA,QAAC,MAAA;AAAA,QAAA;AAAA,UACC,OAAA,EAAS,eAAA;AAAA,UACT,KAAA,EAAM,2BAAA;AAAA,UAEL,QAAA,EAAA;AAAA,YAAA,IAAA,CAAK,KAAA,CAAM,aAAa,GAAG,CAAA;AAAA,YAAE;AAAA;AAAA;AAAA;AAChC,KAAA,EACF;AAAA,GAAA,EACF,CAAA;AAEJ","file":"lite.js","sourcesContent":["export const getClosestPointOnSegment = (\n px: number, py: number,\n x1: number, y1: number,\n x2: number, y2: number\n) => {\n const dx = x2 - x1;\n const dy = y2 - y1;\n const lengthSquared = dx * dx + dy * dy;\n \n if (lengthSquared === 0) return { x: x1, y: y1, t: 0 };\n \n let t = ((px - x1) * dx + (py - y1) * dy) / lengthSquared;\n t = Math.max(0, Math.min(1, t));\n \n return {\n x: x1 + t * dx,\n y: y1 + t * dy,\n t\n };\n};","import { useState } from \"react\";\nimport { Point, Points } from \"../../../types/points.type\";\n\nexport const usePoints = (initialPoints: Omit<Point, \"id\">[]) => {\n const [points, setPoints] = useState<Points>(() =>\n initialPoints.map((p, i) => ({ id: i + 1, x: p.x, y: p.y }))\n );\n\n return { points, setPoints };\n}","import Konva from \"konva\";\nimport { KonvaEventObject } from \"konva/lib/Node\";\nimport { useState } from \"react\";\n\nexport const useZoom = (stage:Konva.Stage | null) => {\n const MIN_SCALE = 0.5;\n const MAX_SCALE = 5;\n const DEFAULT_SCALE = 1;\n \n const [stageScale, setStageScale] = useState(DEFAULT_SCALE);\n\n return{\n stageScale,\n setStageScale,\n MIN_SCALE,\n MAX_SCALE,\n }\n}","import styled from \"styled-components\";\n\nexport const Container = styled.div`\n overflow: hidden;\n width:1200px;\n height:1200px;\n display: flex;\n align-items: stretch;\n border:1px solid #ccc;\n border-radius:4px;\n`;\n\nexport const NavContainer = styled.div`\n width:80px;\n height:100%;\n background:red;\n flex-shrink:0;\n display: flex;\n justify-content: flex-start;\n align-items: center;\n flex-direction:column;\n gap:20px;\n padding:20px 0;\n background:#ebebeb;\n border-left:1px solid #ccc;\n`\n\nexport const CanvasContainer = styled.div`\n width:calc(100% - 80px);\n height:100%;\n overflow: hidden;\n`\n\nexport const ButtonBase = styled.button`\n padding:2px;\n background:white;\n border:none;\n border-radius:8px;\n box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);\n cursor: pointer;\n display: flex;\n justify-content: center;\n align-items: center;\n font-size:12px;\n min-width:50px;\n min-height:50px;\n border-left:1px solid #ccc;\n &:disabled:{\n opacity:0.5;\n cursor:not-allowed;\n }\n`\n\nexport const Button = styled(ButtonBase)``;","import { KonvaEventObject } from \"konva/lib/Node\";\nimport React, { useMemo, useState, useRef, useEffect } from \"react\";\nimport { Stage, Layer, Image as KonvaImage, Circle, Line, Group } from \"react-konva\";\nimport useImage from \"use-image\";\nimport Konva from \"konva\";\nimport { ZoomIn, ZoomOut } from \"lucide-react\";\nimport { getClosestPointOnSegment } from \"../../utils/closest-segment-point\";\nimport { usePoints } from \"./hooks/usePoints\";\nimport { Point, Points } from \"../../types/points.type\";\nimport { useZoom } from \"./hooks/useZoom\";\nimport { Button, CanvasContainer, Container, NavContainer } from \"./Mapper.style\";\n\nexport interface MapperProps {\n src?: string;\n initialPoints?: Omit<Point, \"id\">[];\n maxWidth?: number;\n}\n\nexport const Mapper = ({\n src = \"https://konvajs.org/assets/line-building.png\",\n initialPoints = [], \n maxWidth = 1200,\n}: MapperProps) => {\n const stageRef = useRef<Konva.Stage>(null);\n const { points, setPoints } = usePoints(initialPoints);\n const { stageScale, setStageScale, MAX_SCALE, MIN_SCALE } = useZoom(stageRef?.current);\n const SCALE_BY = 1.2;\n\n const [closed, setClosed] = useState(initialPoints.length >= 3);\n \n const [hoveringFirst, setHoveringFirst] = useState(false);\n const [stagePosition, setStagePosition] = useState({ x: 0, y: 0 });\n const [dragStart, setDragStart] = useState<{ x: number; y: number } | null>(null);\n const [isDraggingPoint, setIsDraggingPoint] = useState(false);\n \n \n const [image] = useImage(src, \"anonymous\");\n const imgW = image?.width || 1;\n const imgH = image?.height || 1;\n const scale = maxWidth / imgW;\n const stageSize = { width: maxWidth, height: imgH * scale } ;\n\n \n const DRAG_THRESHOLD = 5;\n const LINE_HIT_THRESHOLD = 10;\n\n const handleZoomIn = () => {\n const stage = stageRef.current;\n if (!stage) return;\n\n const oldScale = stageScale;\n const newScale = Math.min(oldScale * SCALE_BY, MAX_SCALE);\n\n if (newScale === oldScale) return;\n\n const centerX = stage.width() / 2;\n const centerY = stage.height() / 2;\n\n const pointTo = {\n x: (centerX - stagePosition.x) / oldScale,\n y: (centerY - stagePosition.y) / oldScale,\n };\n\n const newPos = {\n x: centerX - pointTo.x * newScale,\n y: centerY - pointTo.y * newScale,\n };\n\n const constrainedPos = getConstrainedPosition(newPos, newScale);\n setStageScale(newScale);\n setStagePosition(constrainedPos);\n };\n \n const handleZoomOut = () => {\n const stage = stageRef.current;\n if (!stage) return;\n \n const oldScale = stageScale;\n const newScale = Math.max(oldScale / SCALE_BY, MIN_SCALE);\n \n if (newScale === oldScale) return;\n \n const centerX = stage.width() / 2;\n const centerY = stage.height() / 2;\n \n const pointTo = {\n x: (centerX - stagePosition.x) / oldScale,\n y: (centerY - stagePosition.y) / oldScale,\n };\n \n const newPos = {\n x: centerX - pointTo.x * newScale,\n y: centerY - pointTo.y * newScale,\n };\n \n const constrainedPos = getConstrainedPosition(newPos, newScale);\n setStageScale(newScale);\n setStagePosition(constrainedPos);\n };\n \n const handleResetZoom = () => {\n const newScale = 1;\n const constrainedPos = getConstrainedPosition({ x: 0, y: 0 }, newScale);\n setStageScale(newScale);\n setStagePosition(constrainedPos);\n };\n \n const handleWheel = (e: KonvaEventObject<WheelEvent>) => {\n e.evt.preventDefault();\n \n const stage = stageRef.current;\n if (!stage) return;\n \n const oldScale = stageScale;\n const pointer = stage.getPointerPosition();\n if (!pointer) return;\n \n const mousePointTo = {\n x: (pointer.x - stagePosition.x) / oldScale,\n y: (pointer.y - stagePosition.y) / oldScale,\n };\n \n const direction = e.evt.deltaY > 0 ? -1 : 1;\n const newScale = direction > 0 \n ? Math.min(oldScale * SCALE_BY, MAX_SCALE)\n : Math.max(oldScale / SCALE_BY, MIN_SCALE);\n \n if (newScale === oldScale) return;\n \n const newPos = {\n x: pointer.x - mousePointTo.x * newScale,\n y: pointer.y - mousePointTo.y * newScale,\n };\n \n const constrainedPos = getConstrainedPosition(newPos, newScale);\n setStageScale(newScale);\n setStagePosition(constrainedPos);\n };\n\n // Function to constrain position within bounds\n const getConstrainedPosition = (pos: { x: number; y: number }, currentScale: number) => {\n const stage = stageRef.current;\n if (!stage) return pos;\n\n const stageWidth = stage.width();\n const stageHeight = stage.height();\n const imageWidth = stageSize.width * currentScale;\n const imageHeight = stageSize.height * currentScale;\n\n let newX = pos.x;\n let newY = pos.y;\n\n // Constrain X axis\n if (imageWidth > stageWidth) {\n if (newX > 0) newX = 0;\n if (newX < stageWidth - imageWidth) newX = stageWidth - imageWidth;\n } else {\n newX = (stageWidth - imageWidth) / 2;\n }\n\n // Constrain Y axis\n if (imageHeight > stageHeight) {\n if (newY > 0) newY = 0;\n if (newY < stageHeight - imageHeight) newY = stageHeight - imageHeight;\n } else {\n newY = (stageHeight - imageHeight) / 2;\n }\n\n return { x: newX, y: newY };\n };\n\n\n // Function to check if click is near a line segment\n const findLineSegmentNearClick = (clickX: number, clickY: number) => {\n if (points.length < 2) return null;\n\n const threshold = LINE_HIT_THRESHOLD / (scale * stageScale);\n \n const segments = [];\n for (let i = 0; i < points.length - 1; i++) {\n segments.push({ start: i, end: i + 1 });\n }\n \n // If closed, add segment from last to first\n if (closed) {\n segments.push({ start: points.length - 1, end: 0 });\n }\n\n for (const segment of segments) {\n const p1 = points[segment.start];\n const p2 = points[segment.end];\n \n const closest = getClosestPointOnSegment(clickX, clickY, p1.x, p1.y, p2.x, p2.y);\n const distance = Math.hypot(closest.x - clickX, closest.y - clickY);\n \n if (distance < threshold) {\n return {\n segmentIndex: segment.start,\n insertPosition: closest.t,\n point: { x: closest.x, y: closest.y }\n };\n }\n }\n \n return null;\n };\n\n // Initialize position on image load\n useEffect(() => {\n if (image) {\n const initialPos = getConstrainedPosition({ x: 0, y: 0 }, 1);\n setStagePosition(initialPos);\n }\n }, [image]);\n\n // Keyboard shortcuts\n useEffect(() => {\n const handleKeyDown = (e: KeyboardEvent) => {\n if (e.ctrlKey || e.metaKey) {\n if (e.key === \"=\" || e.key === \"+\") {\n e.preventDefault();\n handleZoomIn();\n } else if (e.key === \"-\") {\n e.preventDefault();\n handleZoomOut();\n } else if (e.key === \"0\") {\n e.preventDefault();\n handleResetZoom();\n }\n }\n };\n\n window.addEventListener(\"keydown\", handleKeyDown);\n return () => window.removeEventListener(\"keydown\", handleKeyDown);\n }, [stageScale, stagePosition]);\n\n const handleStageDragStart = (e: KonvaEventObject<MouseEvent>) => {\n // Only allow stage dragging if not clicking on a point\n const clickedShape = e.target;\n if (clickedShape && clickedShape.name() === \"point\") {\n e.target.stopDrag();\n return;\n }\n\n const stage = e.target.getStage();\n if (!stage) return;\n \n const pos = stage.getPointerPosition();\n if (pos) {\n setDragStart(pos);\n }\n };\n\n const handleStageDragEnd = (e: KonvaEventObject<DragEvent>) => {\n const newPos = {\n x: e.target.x(),\n y: e.target.y(),\n };\n const constrainedPos = getConstrainedPosition(newPos, stageScale);\n setStagePosition(constrainedPos);\n setDragStart(null);\n };\n\n const toImageCoords = (stage: Konva.Stage | null): { x: number; y: number } => {\n if (!stage) return { x: 0, y: 0 };\n const pos = stage.getPointerPosition();\n if (!pos) return { x: 0, y: 0 };\n \n const x = (pos.x - stagePosition.x) / (scale * stageScale);\n const y = (pos.y - stagePosition.y) / (scale * stageScale);\n \n return { x, y };\n };\n\n const linePointsScaled = useMemo(() => {\n const flat = points.flatMap((p) => [p.x * scale, p.y * scale]);\n return flat;\n }, [points, scale]);\n\n const commit = (nextPoints: Points) => {\n setPoints(nextPoints);\n };\n\n const handlePointDragStart = (e: KonvaEventObject<DragEvent>) => {\n e.cancelBubble = true; // Prevent stage from dragging\n setIsDraggingPoint(true);\n };\n\n const handlePointDragMove = (id: number, e: KonvaEventObject<DragEvent>) => {\n const newX = e.target.x() / scale;\n const newY = e.target.y() / scale;\n \n const updatedPoints = points.map((p) => \n p.id === id ? { ...p, x: newX, y: newY } : p\n );\n \n setPoints(updatedPoints);\n };\n\n const handlePointDragEnd = (e: KonvaEventObject<DragEvent>) => {\n e.cancelBubble = true; // Prevent stage from processing this event\n setIsDraggingPoint(false);\n };\n\n const handleStageMouseDown = (e: KonvaEventObject<MouseEvent>) => {\n if (!image) return;\n\n const clickedShape = e.target;\n \n // Check if we clicked on a point\n if (clickedShape && clickedShape.name() === \"point\") {\n if (!closed) {\n const clickedIndex = points.findIndex((p) => \n Math.abs(p.x * scale - clickedShape.x()) < 1 && \n Math.abs(p.y * scale - clickedShape.y()) < 1\n );\n \n if (clickedIndex === 0 && points.length >= 3) {\n setClosed(true);\n setHoveringFirst(false);\n }\n }\n return;\n }\n\n // Track drag start for stage\n const stage = e.target.getStage();\n if (!stage) return;\n \n const pos = stage.getPointerPosition();\n if (pos) {\n setDragStart(pos);\n }\n };\n\n const handleStageMouseUp = (e: KonvaEventObject<MouseEvent>) => {\n if (!image || isDraggingPoint) return;\n\n const clickedShape = e.target;\n \n // Don't add point if clicked on a point\n if (clickedShape && clickedShape.name() === \"point\") {\n return;\n }\n\n // Check if this was a drag or a click\n if (dragStart) {\n const stage = e.target.getStage();\n if (!stage) return;\n \n const currentPos = stage.getPointerPosition();\n if (currentPos) {\n const dx = currentPos.x - dragStart.x;\n const dy = currentPos.y - dragStart.y;\n const distance = Math.sqrt(dx * dx + dy * dy);\n \n // If moved less than threshold, it's a click\n if (distance < DRAG_THRESHOLD) {\n const p = toImageCoords(stage);\n \n // Check if click is near an existing line\n const lineHit = findLineSegmentNearClick(p.x, p.y);\n \n if (lineHit) {\n // Insert point into the line\n const newPoint = {\n id: Date.now(),\n x: lineHit.point.x,\n y: lineHit.point.y\n };\n \n const newPoints = [...points];\n newPoints.splice(lineHit.segmentIndex + 1, 0, newPoint);\n commit(newPoints);\n } else if (!closed) {\n // Add point to the end (only if not closed)\n const next = [...points, { id: Date.now(), x: p.x, y: p.y }];\n commit(next);\n }\n }\n }\n \n setDragStart(null);\n }\n };\n\n const handleMouseMove = (e: KonvaEventObject<MouseEvent>) => {\n if (closed || points.length < 3) {\n setHoveringFirst(false);\n return;\n }\n\n const stage = e.target.getStage();\n const p = toImageCoords(stage);\n const fp = points[0];\n const dx = (p.x - fp.x) * scale * stageScale;\n const dy = (p.y - fp.y) * scale * stageScale;\n const dist = Math.hypot(dx, dy);\n\n setHoveringFirst(dist < 15);\n };\n\n return (\n <Container>\n <CanvasContainer>\n <Stage\n ref={stageRef}\n width={1200}\n height={1200}\n onMouseDown={handleStageMouseDown}\n onMouseUp={handleStageMouseUp}\n onMouseMove={handleMouseMove}\n onWheel={handleWheel}\n scaleX={stageScale}\n scaleY={stageScale}\n x={stagePosition.x}\n y={stagePosition.y}\n draggable={!isDraggingPoint}\n onDragStart={handleStageDragStart}\n onDragEnd={handleStageDragEnd}\n dragBoundFunc={(pos) => getConstrainedPosition(pos, stageScale)}\n >\n <Layer>\n <KonvaImage \n image={image} \n width={stageSize.width} \n height={stageSize.height} \n listening={false} \n />\n\n {points.length >= 2 && (\n <Line\n points={linePointsScaled}\n closed={closed}\n stroke=\"#2563eb\"\n strokeWidth={2 / stageScale}\n lineCap=\"round\"\n lineJoin=\"round\"\n tension={0}\n fill={closed ? \"rgba(37, 99, 235, 0.3)\" : undefined}\n hitStrokeWidth={LINE_HIT_THRESHOLD / stageScale}\n />\n )}\n\n <Group>\n {points.map((p, i) => (\n <Circle\n key={p.id}\n name=\"point\"\n x={p.x * scale}\n y={p.y * scale}\n radius={(i === 0 && hoveringFirst ? 10 : 6) / stageScale}\n fill={i === 0 ? \"#ef4444\" : \"#7e9de1\"}\n stroke={i === 0 && hoveringFirst ? \"#fbbf24\" : undefined}\n strokeWidth={i === 0 && hoveringFirst ? 2 / stageScale : 0}\n draggable={true}\n onDragStart={handlePointDragStart}\n onDragMove={(e) => handlePointDragMove(p.id, e)}\n onDragEnd={handlePointDragEnd}\n />\n ))}\n </Group>\n </Layer>\n </Stage>\n </CanvasContainer>\n <NavContainer>\n <Button\n onClick={handleZoomIn}\n disabled={stageScale >= MAX_SCALE}\n title=\"Zoom In (Ctrl/Cmd + +)\"\n >\n <ZoomIn style={{ width: '20px', height: '20px' }} />\n </Button>\n <Button\n onClick={handleZoomOut}\n disabled={stageScale <= MIN_SCALE}\n title=\"Zoom Out (Ctrl/Cmd + -)\"\n >\n <ZoomOut style={{ width: '20px', height: '20px' }} />\n </Button>\n <Button\n onClick={handleResetZoom}\n title=\"Reset Zoom (Ctrl/Cmd + 0)\"\n >\n {Math.round(stageScale * 100)}%\n </Button>\n </NavContainer>\n </Container>\n );\n};"]}
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-floor-mapper",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Interactive image overlay (points/lines) with pan & zoom for React/Next.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
5
9
|
"main": "./dist/index.cjs",
|
|
6
10
|
"module": "./dist/index.mjs",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
8
12
|
"exports": {
|
|
9
13
|
".": {
|
|
10
14
|
"types": "./dist/index.d.ts",
|
|
@@ -17,12 +21,10 @@
|
|
|
17
21
|
"require": "./dist/lite.cjs"
|
|
18
22
|
}
|
|
19
23
|
},
|
|
20
|
-
"files": [
|
|
21
|
-
"dist"
|
|
22
|
-
],
|
|
23
24
|
"sideEffects": false,
|
|
24
25
|
"scripts": {
|
|
25
26
|
"build": "tsup",
|
|
27
|
+
"prepublishOnly": "npm run build",
|
|
26
28
|
"dev": "tsup --watch",
|
|
27
29
|
"test": "vitest",
|
|
28
30
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|