@annotorious/annotorious 3.6.2 → 3.6.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@annotorious/annotorious",
3
- "version": "3.6.2",
3
+ "version": "3.6.4",
4
4
  "description": "Add image annotation functionality to any web page with a few lines of JavaScript",
5
5
  "author": "Rainer Simon",
6
6
  "license": "BSD-3-Clause",
@@ -49,7 +49,7 @@
49
49
  "vitest": "^3.2.4"
50
50
  },
51
51
  "dependencies": {
52
- "@annotorious/core": "3.6.2",
52
+ "@annotorious/core": "3.6.4",
53
53
  "dequal": "^2.0.3",
54
54
  "rbush": "^4.0.1",
55
55
  "simplify-js": "^1.2.4",
@@ -52,6 +52,9 @@
52
52
  cx={x}
53
53
  cy={y}
54
54
  r={handleRadius + (6 / scale)}
55
+ role="button"
56
+ tabindex="0"
57
+ on:dblclick
55
58
  on:pointerenter
56
59
  on:pointerleave
57
60
  on:pointerdown
@@ -60,10 +60,26 @@ export const svgPathToMultiPolygonElement = (d: string): MultiPolygonElement | u
60
60
  }
61
61
  }
62
62
 
63
+ const areHandlesSymmetrical = (pt: PolylinePoint) => {
64
+ // Check if all three points are on a straight line (with a bit of tolerance)
65
+ const { point, inHandle, outHandle } = pt;
66
+
67
+ if (!inHandle || !outHandle) return false;
68
+
69
+ const dx1 = inHandle[0] - point[0];
70
+ const dy1 = inHandle[1] - point[1];
71
+ const dx2 = outHandle[0] - point[0];
72
+ const dy2 = outHandle[1] - point[1];
73
+
74
+ const cross = dx1 * dy2 - dy1 * dx2;
75
+
76
+ return Math.abs(cross) < 0.01;
77
+ }
78
+
63
79
  export const svgPathToPolyline = (d: string): PolylineGeometry => {
64
80
  const commands = parsePathCommands(d);
65
81
 
66
- const points: PolylinePoint[] = [];
82
+ let points: PolylinePoint[] = [];
67
83
 
68
84
  let currentPoint: [number, number] = [0, 0];
69
85
  let closed = false;
@@ -125,6 +141,7 @@ export const svgPathToPolyline = (d: string): PolylineGeometry => {
125
141
  }
126
142
  }
127
143
 
144
+ points = points.map(pt => areHandlesSymmetrical(pt) ? {...pt, locked: true } : pt);
128
145
  const bounds = boundsFromPoints(approximateAsPolygon(points, closed));
129
146
 
130
147
  return {