@nice2dev/ui-graphics 1.2.2 → 1.3.1
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/CHANGELOG.md +429 -0
- package/dist/cjs/font/NiceFontEditor.js +1 -1
- package/dist/cjs/game/GameAsset2dEditor.js +9 -9
- package/dist/cjs/photo/PhotoEditorLeftPanel.js +3 -3
- package/dist/cjs/pixel/PixelEditorRightPanel.js +3 -3
- package/dist/cjs/pixel/PixelEditorTimeline.js +1 -1
- package/dist/cjs/texture/Nice3DTexturePainter.js +1 -1
- package/dist/cjs/ui/NiceUIDesigner.js +2 -2
- package/dist/cjs/vector/VectorEditorRightPanel.js +2 -2
- package/dist/cjs/vector/useVectorEditor.js +26 -16
- package/dist/esm/font/NiceFontEditor.js +2 -2
- package/dist/esm/game/GameAsset2dEditor.js +10 -10
- package/dist/esm/photo/PhotoEditorLeftPanel.js +4 -4
- package/dist/esm/pixel/PixelEditorRightPanel.js +4 -4
- package/dist/esm/pixel/PixelEditorTimeline.js +2 -2
- package/dist/esm/texture/Nice3DTexturePainter.js +2 -2
- package/dist/esm/ui/NiceUIDesigner.js +3 -3
- package/dist/esm/vector/VectorEditorRightPanel.js +3 -3
- package/dist/esm/vector/useVectorEditor.js +26 -16
- package/package.json +4 -4
|
@@ -92,8 +92,12 @@ function useVectorEditor({ artW, artH, onSaveToLibrary }) {
|
|
|
92
92
|
if (!r) {
|
|
93
93
|
return { x: 0, y: 0 };
|
|
94
94
|
}
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
// The <svg> fills the box and its viewBox fits the artboard into it (xMidYMid meet), so one
|
|
96
|
+
// art unit is `fit` screen px before the zoom. Dividing by the zoom alone put every shape
|
|
97
|
+
// closer to the centre than the pointer — off by half in the 900×520 showcase demo.
|
|
98
|
+
const fit = Math.min(r.width / artW, r.height / artH) || 1;
|
|
99
|
+
let x = (cx - r.left - r.width / 2 - px) / (zoom * fit) + artW / 2;
|
|
100
|
+
let y = (cy - r.top - r.height / 2 - py) / (zoom * fit) + artH / 2;
|
|
97
101
|
if (snapGrid) {
|
|
98
102
|
x = snapToGrid(x, gridSize);
|
|
99
103
|
y = snapToGrid(y, gridSize);
|
|
@@ -331,32 +335,37 @@ function useVectorEditor({ artW, artH, onSaveToLibrary }) {
|
|
|
331
335
|
}));
|
|
332
336
|
return;
|
|
333
337
|
}
|
|
334
|
-
|
|
338
|
+
const pending = pendingShape.current;
|
|
339
|
+
if (!pending) {
|
|
335
340
|
return;
|
|
336
341
|
}
|
|
337
|
-
|
|
342
|
+
// The pending shape's ref follows the drag as well. onUp sizes the result from the ref,
|
|
343
|
+
// which kept the 0×0 shape of the press — so every dragged rectangle, ellipse, line and
|
|
344
|
+
// arrow counted as "tiny" and was deleted on release: nothing appeared on the canvas.
|
|
345
|
+
const resize = (patch) => {
|
|
346
|
+
pendingShape.current = { ...pending, ...patch };
|
|
347
|
+
setShapes((prev) => prev.map((s) => (s.id === pending.id ? { ...s, ...patch } : s)));
|
|
348
|
+
};
|
|
349
|
+
const t = pending.type;
|
|
338
350
|
if (t === 'polygon' || t === 'star') {
|
|
339
351
|
const cx = startPt.current.x;
|
|
340
352
|
const cy = startPt.current.y;
|
|
341
353
|
const dx = p.x - cx;
|
|
342
354
|
const dy = p.y - cy;
|
|
343
355
|
const r2 = Math.sqrt(dx * dx + dy * dy);
|
|
344
|
-
|
|
345
|
-
? { ...s, x: cx - r2, y: cy - r2, w: r2 * 2, h: r2 * 2 }
|
|
346
|
-
: s));
|
|
356
|
+
resize({ x: cx - r2, y: cy - r2, w: r2 * 2, h: r2 * 2 });
|
|
347
357
|
return;
|
|
348
358
|
}
|
|
349
359
|
if (t === 'rect' || t === 'roundrect' || t === 'ellipse') {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
360
|
+
resize({
|
|
361
|
+
x: Math.min(startPt.current.x, p.x),
|
|
362
|
+
y: Math.min(startPt.current.y, p.y),
|
|
363
|
+
w: Math.abs(p.x - startPt.current.x),
|
|
364
|
+
h: Math.abs(p.y - startPt.current.y),
|
|
365
|
+
});
|
|
355
366
|
}
|
|
356
367
|
else if (t === 'line' || t === 'arrow') {
|
|
357
|
-
|
|
358
|
-
? { ...s, w: Math.abs(p.x - s.x), h: Math.abs(p.y - s.y), x2: p.x, y2: p.y }
|
|
359
|
-
: s));
|
|
368
|
+
resize({ w: Math.abs(p.x - pending.x), h: Math.abs(p.y - pending.y), x2: p.x, y2: p.y });
|
|
360
369
|
}
|
|
361
370
|
}, [tool, scr2art, selId]);
|
|
362
371
|
const onUp = useCallback(() => {
|
|
@@ -406,7 +415,8 @@ function useVectorEditor({ artW, artH, onSaveToLibrary }) {
|
|
|
406
415
|
dragStarted.current = false;
|
|
407
416
|
return;
|
|
408
417
|
}
|
|
409
|
-
|
|
418
|
+
// the ref holds the final geometry even when the last move has not rendered yet
|
|
419
|
+
snap(shapesRef.current.map((s) => (s.id === ps.id ? ps : s)));
|
|
410
420
|
setSelId(ps.id);
|
|
411
421
|
pendingShape.current = null;
|
|
412
422
|
dragStarted.current = false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nice2dev/ui-graphics",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Nice2Dev Graphics Editors — Pixel, Vector, Photo and Animation editors for React",
|
|
5
5
|
"author": "NiceToDev <contact@nicetodev.com>",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -64,15 +64,15 @@
|
|
|
64
64
|
"nicetodev"
|
|
65
65
|
],
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"@nice2dev/ui-core": "^1.
|
|
67
|
+
"@nice2dev/ui-core": "^1.3.0",
|
|
68
68
|
"@nice2dev/ui": "^1.2.0",
|
|
69
69
|
"framer-motion": ">=10.0.0",
|
|
70
70
|
"react": ">=17.0.0",
|
|
71
71
|
"react-dom": ">=17.0.0"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"@nice2dev/ui": "^1.
|
|
75
|
-
"@nice2dev/ui-core": "^1.
|
|
74
|
+
"@nice2dev/ui": "^1.3.1",
|
|
75
|
+
"@nice2dev/ui-core": "^1.3.1",
|
|
76
76
|
"@rollup/plugin-commonjs": "^29.0.3",
|
|
77
77
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
78
78
|
"@rollup/plugin-typescript": "^12.3.0",
|