dytools-capture-engine 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.
package/dist/index.cjs CHANGED
@@ -27,212 +27,7 @@ __export(index_exports, {
27
27
  });
28
28
  module.exports = __toCommonJS(index_exports);
29
29
  var import_dytools_canvas_engine = require("dytools-canvas-engine");
30
-
31
- // node_modules/dytools-geometry/dist/index.js
32
- var Point = class _Point {
33
- constructor(x, y) {
34
- this.x = x;
35
- this.y = y;
36
- }
37
- equals(other) {
38
- return this.x === other.x && this.y === other.y;
39
- }
40
- static equals(a, b) {
41
- return a.x === b.x && a.y === b.y;
42
- }
43
- getDeltaFromPoint(other) {
44
- return new Vector(this.x - other.x, this.y - other.y);
45
- }
46
- getDeltaToPoint(other) {
47
- return new Vector(this.x + other.x, this.y + other.y);
48
- }
49
- add(vector) {
50
- return new _Point(this.x + vector.x, this.y + vector.y);
51
- }
52
- asVector() {
53
- return new Vector(this.x, this.y);
54
- }
55
- subtract(vector) {
56
- return new _Point(this.x - vector.x, this.y - vector.y);
57
- }
58
- isInside(rect) {
59
- return rect.contains(this);
60
- }
61
- clone() {
62
- return new _Point(this.x, this.y);
63
- }
64
- isInPolygon(poly) {
65
- return poly.containsPoint(this);
66
- }
67
- toString() {
68
- return `Point(${this.x}, ${this.y})`;
69
- }
70
- };
71
- var Size = class _Size {
72
- constructor(width, height) {
73
- this.width = width;
74
- this.height = height;
75
- }
76
- equals(other) {
77
- return this.width === other.width && this.height === other.height;
78
- }
79
- static equals(a, b) {
80
- return a.width === b.width && a.height === b.height;
81
- }
82
- clone() {
83
- return new _Size(this.width, this.height);
84
- }
85
- toString() {
86
- return `Size(${this.width}, ${this.height})`;
87
- }
88
- };
89
- var Rectangle = class _Rectangle {
90
- constructor(originOrX, sizeOrY, width, height) {
91
- const origin = typeof originOrX === "number" && typeof sizeOrY === "number" ? new Point(originOrX, sizeOrY) : originOrX;
92
- const size = typeof sizeOrY === "number" && typeof width === "number" && typeof height === "number" ? new Size(width, height) : sizeOrY;
93
- this.origin = origin;
94
- this.size = size;
95
- }
96
- equals(other) {
97
- return this.origin.equals(other.origin) && this.size.equals(other.size);
98
- }
99
- static equals(a, b) {
100
- return a.origin.equals(b.origin) && a.size.equals(b.size);
101
- }
102
- contains(point) {
103
- return point.x >= this.origin.x && point.x <= this.origin.x + this.size.width && point.y >= this.origin.y && point.y <= this.origin.y + this.size.height;
104
- }
105
- clone() {
106
- return new _Rectangle(new Point(this.origin.x, this.origin.y), new Size(this.size.width, this.size.height));
107
- }
108
- center() {
109
- return new Point(
110
- this.origin.x + this.size.width / 2,
111
- this.origin.y + this.size.height / 2
112
- );
113
- }
114
- normalized() {
115
- if (this.isNormalized()) {
116
- return this;
117
- }
118
- const normalized = this.clone();
119
- normalized.normalize();
120
- return normalized;
121
- }
122
- isNormalized() {
123
- return this.size.width >= 0 && this.size.height >= 0;
124
- }
125
- normalize() {
126
- if (this.size.width < 0) {
127
- this.origin.x += this.size.width;
128
- this.size.width = -this.size.width;
129
- }
130
- if (this.size.height < 0) {
131
- this.origin.y += this.size.height;
132
- this.size.height = -this.size.height;
133
- }
134
- }
135
- expand(rect) {
136
- const newOrigin = new Point(
137
- Math.min(this.origin.x, rect.origin.x),
138
- Math.min(this.origin.y, rect.origin.y)
139
- );
140
- const newWidth = Math.max(this.origin.x + this.size.width, rect.origin.x + rect.size.width) - newOrigin.x;
141
- const newHeight = Math.max(this.origin.y + this.size.height, rect.origin.y + rect.size.height) - newOrigin.y;
142
- return new _Rectangle(newOrigin, new Size(newWidth, newHeight));
143
- }
144
- move(vector) {
145
- return new _Rectangle(
146
- new Point(this.origin.x + vector.x, this.origin.y + vector.y),
147
- new Size(this.size.width, this.size.height)
148
- );
149
- }
150
- toPolygon() {
151
- return new Polygon([
152
- new Point(this.origin.x, this.origin.y),
153
- new Point(this.origin.x + this.size.width, this.origin.y),
154
- new Point(this.origin.x + this.size.width, this.origin.y + this.size.height),
155
- new Point(this.origin.x, this.origin.y + this.size.height)
156
- ]);
157
- }
158
- toString() {
159
- return `Rectangle(${this.origin}, ${this.size})`;
160
- }
161
- };
162
- var Vector = class _Vector {
163
- constructor(x, y) {
164
- this.x = x;
165
- this.y = y;
166
- }
167
- equals(other) {
168
- return this.x === other.x && this.y === other.y;
169
- }
170
- static equals(a, b) {
171
- return a.x === b.x && a.y === b.y;
172
- }
173
- add(other) {
174
- return new _Vector(this.x + other.x, this.y + other.y);
175
- }
176
- subtract(other) {
177
- return new _Vector(this.x - other.x, this.y - other.y);
178
- }
179
- scale(factor) {
180
- return new _Vector(this.x * factor, this.y * factor);
181
- }
182
- length() {
183
- return Math.hypot(this.x, this.y);
184
- }
185
- normalize() {
186
- const len = this.length();
187
- return len === 0 ? new _Vector(0, 0) : new _Vector(this.x / len, this.y / len);
188
- }
189
- clone() {
190
- return new _Vector(this.x, this.y);
191
- }
192
- toString() {
193
- return `Vector(${this.x}, ${this.y})`;
194
- }
195
- };
196
- var Polygon = class {
197
- constructor(points) {
198
- this.points = points;
199
- }
200
- equals(other) {
201
- if (this.points.length !== other.points.length) return false;
202
- for (let i = 0; i < this.points.length; i++) {
203
- if (!this.points[i].equals(other.points[i])) return false;
204
- }
205
- return true;
206
- }
207
- static equals(a, b) {
208
- return a.equals(b);
209
- }
210
- containsPoint(pt) {
211
- let vs = this.points;
212
- let inside = false;
213
- for (let i = 0, j = vs.length - 1; i < vs.length; j = i++) {
214
- const xi = vs[i].x, yi = vs[i].y;
215
- const xj = vs[j].x, yj = vs[j].y;
216
- const intersect = yi > pt.y !== yj > pt.y && pt.x < (xj - xi) * (pt.y - yi) / (yj - yi) + xi;
217
- if (intersect) inside = !inside;
218
- }
219
- return inside;
220
- }
221
- containsRect(rect) {
222
- return this.containsPoint(rect.origin) && this.containsPoint(
223
- new Point(rect.origin.x + rect.size.width, rect.origin.y + rect.size.height)
224
- ) && this.containsPoint(
225
- new Point(rect.origin.x + rect.size.width, rect.origin.y)
226
- ) && this.containsPoint(
227
- new Point(rect.origin.x, rect.origin.y + rect.size.height)
228
- );
229
- }
230
- toString() {
231
- return `Polygon(${this.points.join(",")})`;
232
- }
233
- };
234
-
235
- // src/index.ts
30
+ var import_dytools_geometry = require("dytools-geometry");
236
31
  var CapturePublicEventType = {
237
32
  // These are events based on the state of the zone that is handled by the zone itself.
238
33
  ZonePositionChanged: "zone:position_changed",
@@ -804,7 +599,7 @@ var AnchorChildZone = class extends SimpleZone {
804
599
  toExternalChild(docWidth, docHeight, parentAnchor) {
805
600
  let external = this.toExternal(docWidth, docHeight);
806
601
  external.Type = "TemplateAnchorZoneChild";
807
- const parentAnchorPercent = new Point(parentAnchor.x / docWidth, parentAnchor.y / docHeight);
602
+ const parentAnchorPercent = new import_dytools_geometry.Point(parentAnchor.x / docWidth, parentAnchor.y / docHeight);
808
603
  external.X = this.rect.origin.x / docWidth - parentAnchorPercent.x;
809
604
  external.Y = this.rect.origin.y / docHeight - parentAnchorPercent.y;
810
605
  external.XAbsolute = this.rect.origin.x;
@@ -959,7 +754,7 @@ var AnchorZone = class extends CaptureZoneBase {
959
754
  } else {
960
755
  for (const child of this.children) {
961
756
  if (child.hidden == false) {
962
- let vector = this.currentAnchorPoint ? match.anchorPointAbsolute.getDeltaFromPoint(this.currentAnchorPoint) : new Vector(0, 0);
757
+ let vector = this.currentAnchorPoint ? match.anchorPointAbsolute.getDeltaFromPoint(this.currentAnchorPoint) : new import_dytools_geometry.Vector(0, 0);
963
758
  let color = "rgba(" + cycle + ", 128, 255, 0.5)";
964
759
  const polygon = child.rect.move(vector).toPolygon().points;
965
760
  this.ocrOverlayIds.push(this.canvasManager?.addPolygon(polygon, color, false));
@@ -1041,7 +836,7 @@ var AnchorZone = class extends CaptureZoneBase {
1041
836
  if (!isFirstMatch) {
1042
837
  for (const child of this.children) {
1043
838
  if (child.hidden == false) {
1044
- let vector = this.currentAnchorPoint ? match.anchorPointAbsolute.getDeltaFromPoint(this.currentAnchorPoint) : new Vector(0, 0);
839
+ let vector = this.currentAnchorPoint ? match.anchorPointAbsolute.getDeltaFromPoint(this.currentAnchorPoint) : new import_dytools_geometry.Vector(0, 0);
1045
840
  let color = "rgba(128, 128, 255, 0.5)";
1046
841
  const polygon = child.rect.move(vector).toPolygon().points;
1047
842
  this.ocrOverlayIds.push(canvas.addPolygon(polygon, color, false));
@@ -1561,7 +1356,7 @@ var CaptureEngine = class {
1561
1356
  }
1562
1357
  // --- in CaptureEngine.ts (or a new file) ---
1563
1358
  rectFromExternal(z, docW, docH) {
1564
- return new Rectangle(
1359
+ return new import_dytools_geometry.Rectangle(
1565
1360
  z.X * docW,
1566
1361
  z.Y * docH,
1567
1362
  z.Width * docW,
@@ -1595,7 +1390,7 @@ var CaptureEngine = class {
1595
1390
  if (parentAnchorAbs) {
1596
1391
  const absX = parentAnchorAbs.x / docW + z.X;
1597
1392
  const absY = parentAnchorAbs.y / docH + z.Y;
1598
- const childRect = new Rectangle(
1393
+ const childRect = new import_dytools_geometry.Rectangle(
1599
1394
  absX * docW,
1600
1395
  absY * docH,
1601
1396
  z.Width * docW,
@@ -1742,10 +1537,10 @@ var CaptureEngine = class {
1742
1537
  }
1743
1538
  if (patch.rect) {
1744
1539
  const b = patch.rect;
1745
- if (b instanceof Rectangle) {
1540
+ if (b instanceof import_dytools_geometry.Rectangle) {
1746
1541
  zone.rect = b.clone();
1747
1542
  } else if (b.origin && b.size) {
1748
- zone.rect = new Rectangle(
1543
+ zone.rect = new import_dytools_geometry.Rectangle(
1749
1544
  b.origin.x,
1750
1545
  b.origin.y,
1751
1546
  b.size.width,
@@ -1908,7 +1703,7 @@ var CaptureEngine = class {
1908
1703
  (p) => (
1909
1704
  //(typeof (p as any).clone === 'function')
1910
1705
  //? (p as any).clone() :
1911
- new Point(p.x * this.width, p.y * this.height)
1706
+ new import_dytools_geometry.Point(p.x * this.width, p.y * this.height)
1912
1707
  )
1913
1708
  );
1914
1709
  const overlayId = `ocr-${word.ocrTextResultId}`;
@@ -1959,11 +1754,11 @@ var CaptureEngine = class {
1959
1754
  processedText: m.processedText,
1960
1755
  polygonPercent: m.polygonPercent,
1961
1756
  anchorPointPercent: m.anchorPoint,
1962
- polygonAbsolute: new Polygon(m.polygonPercent.points.map(
1963
- (p) => new Point(p.x * this.engine.width, p.y * this.engine.height)
1757
+ polygonAbsolute: new import_dytools_geometry.Polygon(m.polygonPercent.points.map(
1758
+ (p) => new import_dytools_geometry.Point(p.x * this.engine.width, p.y * this.engine.height)
1964
1759
  // TODO: This will need to be updated when the background changes.
1965
1760
  )),
1966
- anchorPointAbsolute: m.anchorPoint ? new Point(m.anchorPoint.x * this.engine.width, m.anchorPoint.y * this.engine.height) : null
1761
+ anchorPointAbsolute: m.anchorPoint ? new import_dytools_geometry.Point(m.anchorPoint.x * this.engine.width, m.anchorPoint.y * this.engine.height) : null
1967
1762
  }));
1968
1763
  this.zoneOcrMatches = absoluteMatches;
1969
1764
  this.allZonesFlattened.forEach((e) => {
package/dist/index.js CHANGED
@@ -6,212 +6,12 @@ import {
6
6
  EngineEventType,
7
7
  CircleObject
8
8
  } from "dytools-canvas-engine";
9
-
10
- // node_modules/dytools-geometry/dist/index.js
11
- var Point = class _Point {
12
- constructor(x, y) {
13
- this.x = x;
14
- this.y = y;
15
- }
16
- equals(other) {
17
- return this.x === other.x && this.y === other.y;
18
- }
19
- static equals(a, b) {
20
- return a.x === b.x && a.y === b.y;
21
- }
22
- getDeltaFromPoint(other) {
23
- return new Vector(this.x - other.x, this.y - other.y);
24
- }
25
- getDeltaToPoint(other) {
26
- return new Vector(this.x + other.x, this.y + other.y);
27
- }
28
- add(vector) {
29
- return new _Point(this.x + vector.x, this.y + vector.y);
30
- }
31
- asVector() {
32
- return new Vector(this.x, this.y);
33
- }
34
- subtract(vector) {
35
- return new _Point(this.x - vector.x, this.y - vector.y);
36
- }
37
- isInside(rect) {
38
- return rect.contains(this);
39
- }
40
- clone() {
41
- return new _Point(this.x, this.y);
42
- }
43
- isInPolygon(poly) {
44
- return poly.containsPoint(this);
45
- }
46
- toString() {
47
- return `Point(${this.x}, ${this.y})`;
48
- }
49
- };
50
- var Size = class _Size {
51
- constructor(width, height) {
52
- this.width = width;
53
- this.height = height;
54
- }
55
- equals(other) {
56
- return this.width === other.width && this.height === other.height;
57
- }
58
- static equals(a, b) {
59
- return a.width === b.width && a.height === b.height;
60
- }
61
- clone() {
62
- return new _Size(this.width, this.height);
63
- }
64
- toString() {
65
- return `Size(${this.width}, ${this.height})`;
66
- }
67
- };
68
- var Rectangle = class _Rectangle {
69
- constructor(originOrX, sizeOrY, width, height) {
70
- const origin = typeof originOrX === "number" && typeof sizeOrY === "number" ? new Point(originOrX, sizeOrY) : originOrX;
71
- const size = typeof sizeOrY === "number" && typeof width === "number" && typeof height === "number" ? new Size(width, height) : sizeOrY;
72
- this.origin = origin;
73
- this.size = size;
74
- }
75
- equals(other) {
76
- return this.origin.equals(other.origin) && this.size.equals(other.size);
77
- }
78
- static equals(a, b) {
79
- return a.origin.equals(b.origin) && a.size.equals(b.size);
80
- }
81
- contains(point) {
82
- return point.x >= this.origin.x && point.x <= this.origin.x + this.size.width && point.y >= this.origin.y && point.y <= this.origin.y + this.size.height;
83
- }
84
- clone() {
85
- return new _Rectangle(new Point(this.origin.x, this.origin.y), new Size(this.size.width, this.size.height));
86
- }
87
- center() {
88
- return new Point(
89
- this.origin.x + this.size.width / 2,
90
- this.origin.y + this.size.height / 2
91
- );
92
- }
93
- normalized() {
94
- if (this.isNormalized()) {
95
- return this;
96
- }
97
- const normalized = this.clone();
98
- normalized.normalize();
99
- return normalized;
100
- }
101
- isNormalized() {
102
- return this.size.width >= 0 && this.size.height >= 0;
103
- }
104
- normalize() {
105
- if (this.size.width < 0) {
106
- this.origin.x += this.size.width;
107
- this.size.width = -this.size.width;
108
- }
109
- if (this.size.height < 0) {
110
- this.origin.y += this.size.height;
111
- this.size.height = -this.size.height;
112
- }
113
- }
114
- expand(rect) {
115
- const newOrigin = new Point(
116
- Math.min(this.origin.x, rect.origin.x),
117
- Math.min(this.origin.y, rect.origin.y)
118
- );
119
- const newWidth = Math.max(this.origin.x + this.size.width, rect.origin.x + rect.size.width) - newOrigin.x;
120
- const newHeight = Math.max(this.origin.y + this.size.height, rect.origin.y + rect.size.height) - newOrigin.y;
121
- return new _Rectangle(newOrigin, new Size(newWidth, newHeight));
122
- }
123
- move(vector) {
124
- return new _Rectangle(
125
- new Point(this.origin.x + vector.x, this.origin.y + vector.y),
126
- new Size(this.size.width, this.size.height)
127
- );
128
- }
129
- toPolygon() {
130
- return new Polygon([
131
- new Point(this.origin.x, this.origin.y),
132
- new Point(this.origin.x + this.size.width, this.origin.y),
133
- new Point(this.origin.x + this.size.width, this.origin.y + this.size.height),
134
- new Point(this.origin.x, this.origin.y + this.size.height)
135
- ]);
136
- }
137
- toString() {
138
- return `Rectangle(${this.origin}, ${this.size})`;
139
- }
140
- };
141
- var Vector = class _Vector {
142
- constructor(x, y) {
143
- this.x = x;
144
- this.y = y;
145
- }
146
- equals(other) {
147
- return this.x === other.x && this.y === other.y;
148
- }
149
- static equals(a, b) {
150
- return a.x === b.x && a.y === b.y;
151
- }
152
- add(other) {
153
- return new _Vector(this.x + other.x, this.y + other.y);
154
- }
155
- subtract(other) {
156
- return new _Vector(this.x - other.x, this.y - other.y);
157
- }
158
- scale(factor) {
159
- return new _Vector(this.x * factor, this.y * factor);
160
- }
161
- length() {
162
- return Math.hypot(this.x, this.y);
163
- }
164
- normalize() {
165
- const len = this.length();
166
- return len === 0 ? new _Vector(0, 0) : new _Vector(this.x / len, this.y / len);
167
- }
168
- clone() {
169
- return new _Vector(this.x, this.y);
170
- }
171
- toString() {
172
- return `Vector(${this.x}, ${this.y})`;
173
- }
174
- };
175
- var Polygon = class {
176
- constructor(points) {
177
- this.points = points;
178
- }
179
- equals(other) {
180
- if (this.points.length !== other.points.length) return false;
181
- for (let i = 0; i < this.points.length; i++) {
182
- if (!this.points[i].equals(other.points[i])) return false;
183
- }
184
- return true;
185
- }
186
- static equals(a, b) {
187
- return a.equals(b);
188
- }
189
- containsPoint(pt) {
190
- let vs = this.points;
191
- let inside = false;
192
- for (let i = 0, j = vs.length - 1; i < vs.length; j = i++) {
193
- const xi = vs[i].x, yi = vs[i].y;
194
- const xj = vs[j].x, yj = vs[j].y;
195
- const intersect = yi > pt.y !== yj > pt.y && pt.x < (xj - xi) * (pt.y - yi) / (yj - yi) + xi;
196
- if (intersect) inside = !inside;
197
- }
198
- return inside;
199
- }
200
- containsRect(rect) {
201
- return this.containsPoint(rect.origin) && this.containsPoint(
202
- new Point(rect.origin.x + rect.size.width, rect.origin.y + rect.size.height)
203
- ) && this.containsPoint(
204
- new Point(rect.origin.x + rect.size.width, rect.origin.y)
205
- ) && this.containsPoint(
206
- new Point(rect.origin.x, rect.origin.y + rect.size.height)
207
- );
208
- }
209
- toString() {
210
- return `Polygon(${this.points.join(",")})`;
211
- }
212
- };
213
-
214
- // src/index.ts
9
+ import {
10
+ Rectangle,
11
+ Polygon,
12
+ Point,
13
+ Vector
14
+ } from "dytools-geometry";
215
15
  var CapturePublicEventType = {
216
16
  // These are events based on the state of the zone that is handled by the zone itself.
217
17
  ZonePositionChanged: "zone:position_changed",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dytools-capture-engine",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "An editor allowing the creation of templates for ocr capture.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -25,6 +25,7 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "dytools-canvas-engine": "^1.1.1",
28
+ "dytools-geometry": "^1.0.0",
28
29
  "dytools-result": "^1.0.1"
29
30
  }
30
31
  }