-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch.cjs
More file actions
83 lines (70 loc) · 2.58 KB
/
Copy pathpatch.cjs
File metadata and controls
83 lines (70 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const fs = require('fs');
let code = fs.readFileSync('src/components/SVGPathEditor.tsx', 'utf8');
code = code.replace(
` if (e.touches.length === 1) {
const coords = getEventCoords(e, rect);
if (!coords) return;
// Single finger panning is active only if we are in Brush and holding down without drawing active,
// or we are simply navigating. To make it seamless: if drawTool is active we draw, if not we pan.
if (drawTool === 'brush') {`,
` if (e.touches.length === 1) {
const coords = getEventCoords(e, rect);
if (!coords) return;
if (editorMode === 'coordinate') {
setIsPanning(true);
setPanStart({ x: coords.clientX - panOffset.x, y: coords.clientY - panOffset.y });
return;
}
if (drawTool === 'brush') {`
);
code = code.replace(
` if (e.touches.length === 1 && isDrawing && drawTool === 'brush') {
e.preventDefault();
const coords = getEventCoords(e, rect);
if (!coords) return;
const lastPoint = brushPoints[brushPoints.length - 1];
if (!lastPoint || Math.abs(lastPoint.x - coords.x) > 1.5 || Math.abs(lastPoint.y - coords.y) > 1.5) {
setBrushPoints((prev) => [...prev, { x: coords.x, y: coords.y }]);
}
}`,
` if (e.touches.length === 1) {
if (isPanning) {
e.preventDefault();
setPanOffset({
x: e.touches[0].clientX - panStart.x,
y: e.touches[0].clientY - panStart.y
});
return;
}
if (isDrawing && drawTool === 'brush') {
e.preventDefault();
const coords = getEventCoords(e, rect);
if (!coords) return;
const lastPoint = brushPoints[brushPoints.length - 1];
if (!lastPoint || Math.abs(lastPoint.x - coords.x) > 1.5 || Math.abs(lastPoint.y - coords.y) > 1.5) {
setBrushPoints((prev) => [...prev, { x: coords.x, y: coords.y }]);
}
}
}`
);
code = code.replace(
` // Handle Touch ends
const handleTouchEnd = (e: React.TouchEvent<HTMLDivElement>) => {
if (e.touches.length < 2) {
setInitialDistance(null);
setSwipeStartX(null);
}
if (drawTool === 'brush' && isDrawing && brushPoints.length > 1) {`,
` // Handle Touch ends
const handleTouchEnd = (e: React.TouchEvent<HTMLDivElement>) => {
if (e.touches.length < 2) {
setInitialDistance(null);
setSwipeStartX(null);
}
if (isPanning) {
setIsPanning(false);
return;
}
if (drawTool === 'brush' && isDrawing && brushPoints.length > 1) {`
);
fs.writeFileSync('src/components/SVGPathEditor.tsx', code);