@umituz/web-canvas 1.1.0 → 1.1.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.
|
@@ -615,6 +615,7 @@ function useFreehandCanvas(options = {}) {
|
|
|
615
615
|
const canvasRef = useRef4(null);
|
|
616
616
|
const strokesRef = useRef4([]);
|
|
617
617
|
const activeStrokeRef = useRef4(null);
|
|
618
|
+
const activePointerIdRef = useRef4(null);
|
|
618
619
|
const dprRef = useRef4(1);
|
|
619
620
|
const [strokeCount, setStrokeCount] = useState4(0);
|
|
620
621
|
const redraw = useCallback4(() => {
|
|
@@ -702,8 +703,10 @@ function useFreehandCanvas(options = {}) {
|
|
|
702
703
|
}
|
|
703
704
|
function onPointerDown(event) {
|
|
704
705
|
if (event.button !== 0 && event.pointerType === "mouse") return;
|
|
706
|
+
if (activeStrokeRef.current != null) return;
|
|
705
707
|
event.preventDefault();
|
|
706
708
|
el.setPointerCapture(event.pointerId);
|
|
709
|
+
activePointerIdRef.current = event.pointerId;
|
|
707
710
|
const { brushSize: size, color: ink, pressureEnabled: dynamic } = optionsRef.current;
|
|
708
711
|
const stroke = {
|
|
709
712
|
size,
|
|
@@ -716,7 +719,7 @@ function useFreehandCanvas(options = {}) {
|
|
|
716
719
|
}
|
|
717
720
|
function onPointerMove(event) {
|
|
718
721
|
const stroke = activeStrokeRef.current;
|
|
719
|
-
if (!stroke) return;
|
|
722
|
+
if (!stroke || event.pointerId !== activePointerIdRef.current) return;
|
|
720
723
|
event.preventDefault();
|
|
721
724
|
const point = pointFrom(event);
|
|
722
725
|
const previous = stroke.points[stroke.points.length - 1];
|
|
@@ -725,8 +728,9 @@ function useFreehandCanvas(options = {}) {
|
|
|
725
728
|
}
|
|
726
729
|
function commit(event) {
|
|
727
730
|
const stroke = activeStrokeRef.current;
|
|
728
|
-
if (!stroke) return;
|
|
731
|
+
if (!stroke || event.pointerId !== activePointerIdRef.current) return;
|
|
729
732
|
activeStrokeRef.current = null;
|
|
733
|
+
activePointerIdRef.current = null;
|
|
730
734
|
if (el.hasPointerCapture(event.pointerId)) {
|
|
731
735
|
el.releasePointerCapture(event.pointerId);
|
|
732
736
|
}
|
package/dist/index.js
CHANGED
|
@@ -1755,6 +1755,7 @@ function useFreehandCanvas(options = {}) {
|
|
|
1755
1755
|
const canvasRef = (0, import_react4.useRef)(null);
|
|
1756
1756
|
const strokesRef = (0, import_react4.useRef)([]);
|
|
1757
1757
|
const activeStrokeRef = (0, import_react4.useRef)(null);
|
|
1758
|
+
const activePointerIdRef = (0, import_react4.useRef)(null);
|
|
1758
1759
|
const dprRef = (0, import_react4.useRef)(1);
|
|
1759
1760
|
const [strokeCount, setStrokeCount] = (0, import_react4.useState)(0);
|
|
1760
1761
|
const redraw = (0, import_react4.useCallback)(() => {
|
|
@@ -1842,8 +1843,10 @@ function useFreehandCanvas(options = {}) {
|
|
|
1842
1843
|
}
|
|
1843
1844
|
function onPointerDown(event) {
|
|
1844
1845
|
if (event.button !== 0 && event.pointerType === "mouse") return;
|
|
1846
|
+
if (activeStrokeRef.current != null) return;
|
|
1845
1847
|
event.preventDefault();
|
|
1846
1848
|
el.setPointerCapture(event.pointerId);
|
|
1849
|
+
activePointerIdRef.current = event.pointerId;
|
|
1847
1850
|
const { brushSize: size, color: ink, pressureEnabled: dynamic } = optionsRef.current;
|
|
1848
1851
|
const stroke = {
|
|
1849
1852
|
size,
|
|
@@ -1856,7 +1859,7 @@ function useFreehandCanvas(options = {}) {
|
|
|
1856
1859
|
}
|
|
1857
1860
|
function onPointerMove(event) {
|
|
1858
1861
|
const stroke = activeStrokeRef.current;
|
|
1859
|
-
if (!stroke) return;
|
|
1862
|
+
if (!stroke || event.pointerId !== activePointerIdRef.current) return;
|
|
1860
1863
|
event.preventDefault();
|
|
1861
1864
|
const point = pointFrom(event);
|
|
1862
1865
|
const previous = stroke.points[stroke.points.length - 1];
|
|
@@ -1865,8 +1868,9 @@ function useFreehandCanvas(options = {}) {
|
|
|
1865
1868
|
}
|
|
1866
1869
|
function commit(event) {
|
|
1867
1870
|
const stroke = activeStrokeRef.current;
|
|
1868
|
-
if (!stroke) return;
|
|
1871
|
+
if (!stroke || event.pointerId !== activePointerIdRef.current) return;
|
|
1869
1872
|
activeStrokeRef.current = null;
|
|
1873
|
+
activePointerIdRef.current = null;
|
|
1870
1874
|
if (el.hasPointerCapture(event.pointerId)) {
|
|
1871
1875
|
el.releasePointerCapture(event.pointerId);
|
|
1872
1876
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1749,6 +1749,7 @@ function useFreehandCanvas(options = {}) {
|
|
|
1749
1749
|
const canvasRef = (0, import_react4.useRef)(null);
|
|
1750
1750
|
const strokesRef = (0, import_react4.useRef)([]);
|
|
1751
1751
|
const activeStrokeRef = (0, import_react4.useRef)(null);
|
|
1752
|
+
const activePointerIdRef = (0, import_react4.useRef)(null);
|
|
1752
1753
|
const dprRef = (0, import_react4.useRef)(1);
|
|
1753
1754
|
const [strokeCount, setStrokeCount] = (0, import_react4.useState)(0);
|
|
1754
1755
|
const redraw = (0, import_react4.useCallback)(() => {
|
|
@@ -1836,8 +1837,10 @@ function useFreehandCanvas(options = {}) {
|
|
|
1836
1837
|
}
|
|
1837
1838
|
function onPointerDown(event) {
|
|
1838
1839
|
if (event.button !== 0 && event.pointerType === "mouse") return;
|
|
1840
|
+
if (activeStrokeRef.current != null) return;
|
|
1839
1841
|
event.preventDefault();
|
|
1840
1842
|
el.setPointerCapture(event.pointerId);
|
|
1843
|
+
activePointerIdRef.current = event.pointerId;
|
|
1841
1844
|
const { brushSize: size, color: ink, pressureEnabled: dynamic } = optionsRef.current;
|
|
1842
1845
|
const stroke = {
|
|
1843
1846
|
size,
|
|
@@ -1850,7 +1853,7 @@ function useFreehandCanvas(options = {}) {
|
|
|
1850
1853
|
}
|
|
1851
1854
|
function onPointerMove(event) {
|
|
1852
1855
|
const stroke = activeStrokeRef.current;
|
|
1853
|
-
if (!stroke) return;
|
|
1856
|
+
if (!stroke || event.pointerId !== activePointerIdRef.current) return;
|
|
1854
1857
|
event.preventDefault();
|
|
1855
1858
|
const point = pointFrom(event);
|
|
1856
1859
|
const previous = stroke.points[stroke.points.length - 1];
|
|
@@ -1859,8 +1862,9 @@ function useFreehandCanvas(options = {}) {
|
|
|
1859
1862
|
}
|
|
1860
1863
|
function commit(event) {
|
|
1861
1864
|
const stroke = activeStrokeRef.current;
|
|
1862
|
-
if (!stroke) return;
|
|
1865
|
+
if (!stroke || event.pointerId !== activePointerIdRef.current) return;
|
|
1863
1866
|
activeStrokeRef.current = null;
|
|
1867
|
+
activePointerIdRef.current = null;
|
|
1864
1868
|
if (el.hasPointerCapture(event.pointerId)) {
|
|
1865
1869
|
el.releasePointerCapture(event.pointerId);
|
|
1866
1870
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/web-canvas",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Comprehensive canvas and screenshot generation library with device frames, patterns, and PDF export",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -100,4 +100,4 @@
|
|
|
100
100
|
"jszip": "^3.10.1",
|
|
101
101
|
"xlsx": "^0.18.5"
|
|
102
102
|
}
|
|
103
|
-
}
|
|
103
|
+
}
|
|
@@ -64,6 +64,7 @@ export function useFreehandCanvas(
|
|
|
64
64
|
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
|
65
65
|
const strokesRef = useRef<FreehandStroke[]>([]);
|
|
66
66
|
const activeStrokeRef = useRef<FreehandStroke | null>(null);
|
|
67
|
+
const activePointerIdRef = useRef<number | null>(null);
|
|
67
68
|
const dprRef = useRef(1);
|
|
68
69
|
|
|
69
70
|
const [strokeCount, setStrokeCount] = useState(0);
|
|
@@ -168,8 +169,12 @@ export function useFreehandCanvas(
|
|
|
168
169
|
|
|
169
170
|
function onPointerDown(event: PointerEvent): void {
|
|
170
171
|
if (event.button !== 0 && event.pointerType === 'mouse') return;
|
|
172
|
+
// Only one stroke at a time: a resting palm or second finger touching
|
|
173
|
+
// mid-stroke must not hijack or corrupt the active stroke.
|
|
174
|
+
if (activeStrokeRef.current != null) return;
|
|
171
175
|
event.preventDefault();
|
|
172
176
|
el.setPointerCapture(event.pointerId);
|
|
177
|
+
activePointerIdRef.current = event.pointerId;
|
|
173
178
|
const { brushSize: size, color: ink, pressureEnabled: dynamic } = optionsRef.current;
|
|
174
179
|
const stroke: FreehandStroke = {
|
|
175
180
|
size,
|
|
@@ -183,7 +188,7 @@ export function useFreehandCanvas(
|
|
|
183
188
|
|
|
184
189
|
function onPointerMove(event: PointerEvent): void {
|
|
185
190
|
const stroke = activeStrokeRef.current;
|
|
186
|
-
if (!stroke) return;
|
|
191
|
+
if (!stroke || event.pointerId !== activePointerIdRef.current) return;
|
|
187
192
|
event.preventDefault();
|
|
188
193
|
const point = pointFrom(event);
|
|
189
194
|
const previous = stroke.points[stroke.points.length - 1];
|
|
@@ -193,8 +198,9 @@ export function useFreehandCanvas(
|
|
|
193
198
|
|
|
194
199
|
function commit(event: PointerEvent): void {
|
|
195
200
|
const stroke = activeStrokeRef.current;
|
|
196
|
-
if (!stroke) return;
|
|
201
|
+
if (!stroke || event.pointerId !== activePointerIdRef.current) return;
|
|
197
202
|
activeStrokeRef.current = null;
|
|
203
|
+
activePointerIdRef.current = null;
|
|
198
204
|
if (el.hasPointerCapture(event.pointerId)) {
|
|
199
205
|
el.releasePointerCapture(event.pointerId);
|
|
200
206
|
}
|