dytools-capture-engine 1.0.1 → 1.1.0

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,6 +27,212 @@ __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
236
  var CapturePublicEventType = {
31
237
  // These are events based on the state of the zone that is handled by the zone itself.
32
238
  ZonePositionChanged: "zone:position_changed",
@@ -64,7 +270,8 @@ var CapturePublicEventType = {
64
270
  // any errors
65
271
  CaptureBackgroundChanged: "capture:background_changed",
66
272
  CaptureRenderStarted: "capture:render_started",
67
- CaptureRenderCompleted: "capture:render_completed"
273
+ CaptureRenderCompleted: "capture:render_completed",
274
+ CaptureModeChanged: "capture:mode_changed"
68
275
  };
69
276
  var CaptureZoneEventType = {
70
277
  // These are events that originate and end inside the zone itself.
@@ -377,7 +584,7 @@ var CaptureZoneBase = class {
377
584
  this.emitZoneEvent(CaptureZoneEventType.ZoneOutputRegexChanged, { oldOutputRegex, newOutputRegex: value });
378
585
  }
379
586
  get outputReplacement() {
380
- return this._outputRegex ?? null;
587
+ return this._outputReplacement ?? null;
381
588
  }
382
589
  set outputReplacement(value) {
383
590
  if (value === this._outputReplacement) return;
@@ -597,7 +804,7 @@ var AnchorChildZone = class extends SimpleZone {
597
804
  toExternalChild(docWidth, docHeight, parentAnchor) {
598
805
  let external = this.toExternal(docWidth, docHeight);
599
806
  external.Type = "TemplateAnchorZoneChild";
600
- const parentAnchorPercent = new import_dytools_canvas_engine.Point(parentAnchor.x / docWidth, parentAnchor.y / docHeight);
807
+ const parentAnchorPercent = new Point(parentAnchor.x / docWidth, parentAnchor.y / docHeight);
601
808
  external.X = this.rect.origin.x / docWidth - parentAnchorPercent.x;
602
809
  external.Y = this.rect.origin.y / docHeight - parentAnchorPercent.y;
603
810
  external.XAbsolute = this.rect.origin.x;
@@ -752,7 +959,7 @@ var AnchorZone = class extends CaptureZoneBase {
752
959
  } else {
753
960
  for (const child of this.children) {
754
961
  if (child.hidden == false) {
755
- let vector = this.currentAnchorPoint ? match.anchorPointAbsolute.getDeltaFromPoint(this.currentAnchorPoint) : new import_dytools_canvas_engine.Vector(0, 0);
962
+ let vector = this.currentAnchorPoint ? match.anchorPointAbsolute.getDeltaFromPoint(this.currentAnchorPoint) : new Vector(0, 0);
756
963
  let color = "rgba(" + cycle + ", 128, 255, 0.5)";
757
964
  const polygon = child.rect.move(vector).toPolygon().points;
758
965
  this.ocrOverlayIds.push(this.canvasManager?.addPolygon(polygon, color, false));
@@ -834,7 +1041,7 @@ var AnchorZone = class extends CaptureZoneBase {
834
1041
  if (!isFirstMatch) {
835
1042
  for (const child of this.children) {
836
1043
  if (child.hidden == false) {
837
- let vector = this.currentAnchorPoint ? match.anchorPointAbsolute.getDeltaFromPoint(this.currentAnchorPoint) : new import_dytools_canvas_engine.Vector(0, 0);
1044
+ let vector = this.currentAnchorPoint ? match.anchorPointAbsolute.getDeltaFromPoint(this.currentAnchorPoint) : new Vector(0, 0);
838
1045
  let color = "rgba(128, 128, 255, 0.5)";
839
1046
  const polygon = child.rect.move(vector).toPolygon().points;
840
1047
  this.ocrOverlayIds.push(canvas.addPolygon(polygon, color, false));
@@ -1117,6 +1324,12 @@ var CaptureEngine = class {
1117
1324
  this.engine.on(import_dytools_canvas_engine.EngineEventType.EngineRenderCompleted, () => {
1118
1325
  this.emitExternal(CapturePublicEventType.CaptureRenderCompleted, {});
1119
1326
  });
1327
+ this.engine.on(import_dytools_canvas_engine.EngineEventType.EngineModeChanged, ({ oldMode, newMode }) => {
1328
+ this.emitExternal(CapturePublicEventType.CaptureModeChanged, {
1329
+ oldMode,
1330
+ newMode
1331
+ });
1332
+ });
1120
1333
  }
1121
1334
  /* --- PUBLIC/EXTERNAL EVENT METHODS --- */
1122
1335
  on(event, handler, options) {
@@ -1348,7 +1561,7 @@ var CaptureEngine = class {
1348
1561
  }
1349
1562
  // --- in CaptureEngine.ts (or a new file) ---
1350
1563
  rectFromExternal(z, docW, docH) {
1351
- return new import_dytools_canvas_engine.Rectangle(
1564
+ return new Rectangle(
1352
1565
  z.X * docW,
1353
1566
  z.Y * docH,
1354
1567
  z.Width * docW,
@@ -1382,7 +1595,7 @@ var CaptureEngine = class {
1382
1595
  if (parentAnchorAbs) {
1383
1596
  const absX = parentAnchorAbs.x / docW + z.X;
1384
1597
  const absY = parentAnchorAbs.y / docH + z.Y;
1385
- const childRect = new import_dytools_canvas_engine.Rectangle(
1598
+ const childRect = new Rectangle(
1386
1599
  absX * docW,
1387
1600
  absY * docH,
1388
1601
  z.Width * docW,
@@ -1529,10 +1742,10 @@ var CaptureEngine = class {
1529
1742
  }
1530
1743
  if (patch.rect) {
1531
1744
  const b = patch.rect;
1532
- if (b instanceof import_dytools_canvas_engine.Rectangle) {
1745
+ if (b instanceof Rectangle) {
1533
1746
  zone.rect = b.clone();
1534
1747
  } else if (b.origin && b.size) {
1535
- zone.rect = new import_dytools_canvas_engine.Rectangle(
1748
+ zone.rect = new Rectangle(
1536
1749
  b.origin.x,
1537
1750
  b.origin.y,
1538
1751
  b.size.width,
@@ -1695,7 +1908,7 @@ var CaptureEngine = class {
1695
1908
  (p) => (
1696
1909
  //(typeof (p as any).clone === 'function')
1697
1910
  //? (p as any).clone() :
1698
- new import_dytools_canvas_engine.Point(p.x * this.width, p.y * this.height)
1911
+ new Point(p.x * this.width, p.y * this.height)
1699
1912
  )
1700
1913
  );
1701
1914
  const overlayId = `ocr-${word.ocrTextResultId}`;
@@ -1746,11 +1959,11 @@ var CaptureEngine = class {
1746
1959
  processedText: m.processedText,
1747
1960
  polygonPercent: m.polygonPercent,
1748
1961
  anchorPointPercent: m.anchorPoint,
1749
- polygonAbsolute: new import_dytools_canvas_engine.Polygon(m.polygonPercent.points.map(
1750
- (p) => new import_dytools_canvas_engine.Point(p.x * this.engine.width, p.y * this.engine.height)
1962
+ polygonAbsolute: new Polygon(m.polygonPercent.points.map(
1963
+ (p) => new Point(p.x * this.engine.width, p.y * this.engine.height)
1751
1964
  // TODO: This will need to be updated when the background changes.
1752
1965
  )),
1753
- anchorPointAbsolute: m.anchorPoint ? new import_dytools_canvas_engine.Point(m.anchorPoint.x * this.engine.width, m.anchorPoint.y * this.engine.height) : null
1966
+ anchorPointAbsolute: m.anchorPoint ? new Point(m.anchorPoint.x * this.engine.width, m.anchorPoint.y * this.engine.height) : null
1754
1967
  }));
1755
1968
  this.zoneOcrMatches = absoluteMatches;
1756
1969
  this.allZonesFlattened.forEach((e) => {
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
- import { Rectangle, InteractiveObject, Size, Point, Polygon, Vector } from 'dytools-canvas-engine';
1
+ import { InteractiveObject } from 'dytools-canvas-engine';
2
+ import { Rectangle, Size, Point, Polygon, Vector } from 'dytools-geometry';
2
3
  import { Result } from 'dytools-result';
3
4
 
4
5
  type ExternalZoneType = "TemplateSimpleZone" | "TemplateAnchorZone" | "TemplateAnchorZoneChild";
@@ -58,6 +59,7 @@ declare const CapturePublicEventType: {
58
59
  readonly CaptureBackgroundChanged: "capture:background_changed";
59
60
  readonly CaptureRenderStarted: "capture:render_started";
60
61
  readonly CaptureRenderCompleted: "capture:render_completed";
62
+ readonly CaptureModeChanged: "capture:mode_changed";
61
63
  };
62
64
  type CapturePublicEventType = typeof CapturePublicEventType[keyof typeof CapturePublicEventType];
63
65
  interface CapturePublicEventPayloads {
@@ -150,6 +152,10 @@ interface CapturePublicEventPayloads {
150
152
  };
151
153
  [CapturePublicEventType.CaptureRenderStarted]: {};
152
154
  [CapturePublicEventType.CaptureRenderCompleted]: {};
155
+ [CapturePublicEventType.CaptureModeChanged]: {
156
+ oldMode: string;
157
+ newMode: string;
158
+ };
153
159
  }
154
160
  declare const CaptureZoneEventType: {
155
161
  readonly ZoneCanvasManagerSet: "zone_internal:canvas_manager_set";
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { Rectangle, InteractiveObject, Size, Point, Polygon, Vector } from 'dytools-canvas-engine';
1
+ import { InteractiveObject } from 'dytools-canvas-engine';
2
+ import { Rectangle, Size, Point, Polygon, Vector } from 'dytools-geometry';
2
3
  import { Result } from 'dytools-result';
3
4
 
4
5
  type ExternalZoneType = "TemplateSimpleZone" | "TemplateAnchorZone" | "TemplateAnchorZoneChild";
@@ -58,6 +59,7 @@ declare const CapturePublicEventType: {
58
59
  readonly CaptureBackgroundChanged: "capture:background_changed";
59
60
  readonly CaptureRenderStarted: "capture:render_started";
60
61
  readonly CaptureRenderCompleted: "capture:render_completed";
62
+ readonly CaptureModeChanged: "capture:mode_changed";
61
63
  };
62
64
  type CapturePublicEventType = typeof CapturePublicEventType[keyof typeof CapturePublicEventType];
63
65
  interface CapturePublicEventPayloads {
@@ -150,6 +152,10 @@ interface CapturePublicEventPayloads {
150
152
  };
151
153
  [CapturePublicEventType.CaptureRenderStarted]: {};
152
154
  [CapturePublicEventType.CaptureRenderCompleted]: {};
155
+ [CapturePublicEventType.CaptureModeChanged]: {
156
+ oldMode: string;
157
+ newMode: string;
158
+ };
153
159
  }
154
160
  declare const CaptureZoneEventType: {
155
161
  readonly ZoneCanvasManagerSet: "zone_internal:canvas_manager_set";
package/dist/index.js CHANGED
@@ -2,14 +2,216 @@
2
2
  import {
3
3
  CanvasEngine,
4
4
  Zone,
5
- Rectangle,
6
- Polygon,
7
- Point,
8
5
  PolygonObject,
9
- Vector,
10
6
  EngineEventType,
11
7
  CircleObject
12
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
13
215
  var CapturePublicEventType = {
14
216
  // These are events based on the state of the zone that is handled by the zone itself.
15
217
  ZonePositionChanged: "zone:position_changed",
@@ -47,7 +249,8 @@ var CapturePublicEventType = {
47
249
  // any errors
48
250
  CaptureBackgroundChanged: "capture:background_changed",
49
251
  CaptureRenderStarted: "capture:render_started",
50
- CaptureRenderCompleted: "capture:render_completed"
252
+ CaptureRenderCompleted: "capture:render_completed",
253
+ CaptureModeChanged: "capture:mode_changed"
51
254
  };
52
255
  var CaptureZoneEventType = {
53
256
  // These are events that originate and end inside the zone itself.
@@ -360,7 +563,7 @@ var CaptureZoneBase = class {
360
563
  this.emitZoneEvent(CaptureZoneEventType.ZoneOutputRegexChanged, { oldOutputRegex, newOutputRegex: value });
361
564
  }
362
565
  get outputReplacement() {
363
- return this._outputRegex ?? null;
566
+ return this._outputReplacement ?? null;
364
567
  }
365
568
  set outputReplacement(value) {
366
569
  if (value === this._outputReplacement) return;
@@ -1100,6 +1303,12 @@ var CaptureEngine = class {
1100
1303
  this.engine.on(EngineEventType.EngineRenderCompleted, () => {
1101
1304
  this.emitExternal(CapturePublicEventType.CaptureRenderCompleted, {});
1102
1305
  });
1306
+ this.engine.on(EngineEventType.EngineModeChanged, ({ oldMode, newMode }) => {
1307
+ this.emitExternal(CapturePublicEventType.CaptureModeChanged, {
1308
+ oldMode,
1309
+ newMode
1310
+ });
1311
+ });
1103
1312
  }
1104
1313
  /* --- PUBLIC/EXTERNAL EVENT METHODS --- */
1105
1314
  on(event, handler, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dytools-capture-engine",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "An editor allowing the creation of templates for ocr capture.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -24,7 +24,7 @@
24
24
  "typescript": "^5.9.3"
25
25
  },
26
26
  "dependencies": {
27
- "dytools-canvas-engine": "^1.1.0",
27
+ "dytools-canvas-engine": "^1.1.1",
28
28
  "dytools-result": "^1.0.1"
29
29
  }
30
30
  }