@rickcedwhat/playwright-smart-vision 0.1.0-next.3463e4f

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.
Files changed (69) hide show
  1. package/dist/configure.d.ts +32 -0
  2. package/dist/configure.d.ts.map +1 -0
  3. package/dist/configure.js +105 -0
  4. package/dist/configure.js.map +1 -0
  5. package/dist/devtools.d.ts +3 -0
  6. package/dist/devtools.d.ts.map +1 -0
  7. package/dist/devtools.js +235 -0
  8. package/dist/devtools.js.map +1 -0
  9. package/dist/element.d.ts +177 -0
  10. package/dist/element.d.ts.map +1 -0
  11. package/dist/element.js +433 -0
  12. package/dist/element.js.map +1 -0
  13. package/dist/element.test.d.ts +2 -0
  14. package/dist/element.test.d.ts.map +1 -0
  15. package/dist/element.test.js +207 -0
  16. package/dist/element.test.js.map +1 -0
  17. package/dist/field-extractor.d.ts +63 -0
  18. package/dist/field-extractor.d.ts.map +1 -0
  19. package/dist/field-extractor.js +438 -0
  20. package/dist/field-extractor.js.map +1 -0
  21. package/dist/index.d.ts +14 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +8 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/ocr-overlay.d.ts +21 -0
  26. package/dist/ocr-overlay.d.ts.map +1 -0
  27. package/dist/ocr-overlay.js +102 -0
  28. package/dist/ocr-overlay.js.map +1 -0
  29. package/dist/ocr-step.d.ts +9 -0
  30. package/dist/ocr-step.d.ts.map +1 -0
  31. package/dist/ocr-step.js +52 -0
  32. package/dist/ocr-step.js.map +1 -0
  33. package/dist/ocr-test.d.ts +11 -0
  34. package/dist/ocr-test.d.ts.map +1 -0
  35. package/dist/ocr-test.js +38 -0
  36. package/dist/ocr-test.js.map +1 -0
  37. package/dist/playwright-helper.d.ts +64 -0
  38. package/dist/playwright-helper.d.ts.map +1 -0
  39. package/dist/playwright-helper.js +142 -0
  40. package/dist/playwright-helper.js.map +1 -0
  41. package/dist/screen-config.d.ts +91 -0
  42. package/dist/screen-config.d.ts.map +1 -0
  43. package/dist/screen-config.js +203 -0
  44. package/dist/screen-config.js.map +1 -0
  45. package/dist/screen-result.d.ts +103 -0
  46. package/dist/screen-result.d.ts.map +1 -0
  47. package/dist/screen-result.js +313 -0
  48. package/dist/screen-result.js.map +1 -0
  49. package/dist/typed-screen.d.ts +44 -0
  50. package/dist/typed-screen.d.ts.map +1 -0
  51. package/dist/typed-screen.js +72 -0
  52. package/dist/typed-screen.js.map +1 -0
  53. package/dist/types.d.ts +204 -0
  54. package/dist/types.d.ts.map +1 -0
  55. package/dist/types.js +19 -0
  56. package/dist/types.js.map +1 -0
  57. package/dist/utils/ocr.d.ts +52 -0
  58. package/dist/utils/ocr.d.ts.map +1 -0
  59. package/dist/utils/ocr.js +252 -0
  60. package/dist/utils/ocr.js.map +1 -0
  61. package/dist/utils/ocr.test.d.ts +2 -0
  62. package/dist/utils/ocr.test.d.ts.map +1 -0
  63. package/dist/utils/ocr.test.js +145 -0
  64. package/dist/utils/ocr.test.js.map +1 -0
  65. package/dist/utils/vision.d.ts +116 -0
  66. package/dist/utils/vision.d.ts.map +1 -0
  67. package/dist/utils/vision.js +340 -0
  68. package/dist/utils/vision.js.map +1 -0
  69. package/package.json +76 -0
@@ -0,0 +1,32 @@
1
+ import type { Page } from '@playwright/test';
2
+ import type { ScreenConfig } from './screen-config.js';
3
+ interface StorageConfig {
4
+ root: string;
5
+ }
6
+ interface GlobalConfig {
7
+ storage?: StorageConfig;
8
+ devtools?: boolean;
9
+ page?: Page;
10
+ }
11
+ export declare function getGlobalConfig(): GlobalConfig;
12
+ /**
13
+ * Configure storage root and optional devtools FAB.
14
+ * Pass `page` to inject the FAB immediately (QA Wolf / non-fixture usage).
15
+ * In fixture-based Playwright tests the FAB is injected automatically by the ocrScreen fixture.
16
+ *
17
+ * await configure({ storage: { root: process.env.TEAM_STORAGE_DIR + '/screens' }, devtools: true, page });
18
+ */
19
+ export declare function configure(config: GlobalConfig): Promise<void>;
20
+ /**
21
+ * Take a screenshot of the current page and save it as blank.png
22
+ * under {storage.root}/{name}/. Creates the directory if needed.
23
+ */
24
+ export declare function saveScreen(page: Page, name: string): Promise<string>;
25
+ export declare function writeScreenBuffer(name: string, buffer: Buffer): string;
26
+ /**
27
+ * Load a ScreenConfig by name from the configured storage root.
28
+ * Reads {root}/{name}/index.json, blank.png, and templates/.
29
+ */
30
+ export declare function loadScreen(name: string): ScreenConfig;
31
+ export {};
32
+ //# sourceMappingURL=configure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../src/configure.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGvD,UAAU,aAAa;IACrB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,YAAY;IACpB,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,IAAI,CAAC;CACb;AAID,wBAAgB,eAAe,IAAI,YAAY,CAE9C;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAOnE;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAM1E;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAStE;AAuBD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAwDrD"}
@@ -0,0 +1,105 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ let globalConfig = {};
4
+ export function getGlobalConfig() {
5
+ return globalConfig;
6
+ }
7
+ /**
8
+ * Configure storage root and optional devtools FAB.
9
+ * Pass `page` to inject the FAB immediately (QA Wolf / non-fixture usage).
10
+ * In fixture-based Playwright tests the FAB is injected automatically by the ocrScreen fixture.
11
+ *
12
+ * await configure({ storage: { root: process.env.TEAM_STORAGE_DIR + '/screens' }, devtools: true, page });
13
+ */
14
+ export async function configure(config) {
15
+ const { page, ...rest } = config;
16
+ globalConfig = { ...globalConfig, ...rest };
17
+ if (rest.devtools && page) {
18
+ const { injectDevtools } = await import('./devtools.js');
19
+ await injectDevtools(page);
20
+ }
21
+ }
22
+ /**
23
+ * Take a screenshot of the current page and save it as blank.png
24
+ * under {storage.root}/{name}/. Creates the directory if needed.
25
+ */
26
+ export async function saveScreen(page, name) {
27
+ if (!globalConfig.storage) {
28
+ throw new Error(`saveScreen('${name}'): call configure({ storage: { root } }) first`);
29
+ }
30
+ const buffer = await page.screenshot({ timeout: 5_000 });
31
+ return writeScreenBuffer(name, buffer);
32
+ }
33
+ export function writeScreenBuffer(name, buffer) {
34
+ if (!globalConfig.storage) {
35
+ throw new Error(`saveScreen('${name}'): call configure({ storage: { root } }) first`);
36
+ }
37
+ const dir = path.join(globalConfig.storage.root, name);
38
+ fs.mkdirSync(dir, { recursive: true });
39
+ const blankPath = path.join(dir, 'blank.png');
40
+ fs.writeFileSync(blankPath, buffer);
41
+ return blankPath;
42
+ }
43
+ /**
44
+ * Load a ScreenConfig by name from the configured storage root.
45
+ * Reads {root}/{name}/index.json, blank.png, and templates/.
46
+ */
47
+ export function loadScreen(name) {
48
+ if (!globalConfig.storage) {
49
+ throw new Error(`ocrScreen('${name}'): call configure({ storage: { root } }) before using string screen names`);
50
+ }
51
+ const dir = path.join(globalConfig.storage.root, name);
52
+ const indexPath = path.join(dir, 'index.json');
53
+ let raw;
54
+ try {
55
+ raw = JSON.parse(fs.readFileSync(indexPath, 'utf8'));
56
+ }
57
+ catch {
58
+ throw new Error(`ocrScreen('${name}'): could not read ${indexPath}`);
59
+ }
60
+ const elementConfigs = raw.elements.map((el) => {
61
+ const cfg = { name: el.name };
62
+ if (el.type)
63
+ cfg.type = el.type;
64
+ if (el.filename)
65
+ cfg.templatePath = path.join(dir, 'templates', el.filename);
66
+ if (el.section)
67
+ cfg.sectionTemplatePath = path.join(dir, 'templates', el.section);
68
+ if (el.animated)
69
+ cfg.animated = el.animated;
70
+ if (el.ocrRect)
71
+ cfg.ocrRect = el.ocrRect;
72
+ if (el.charset)
73
+ cfg.charset = el.charset;
74
+ if (el.options?.length)
75
+ cfg.options = el.options;
76
+ if (el.overflow)
77
+ cfg.overflow = el.overflow;
78
+ if (el.swaps)
79
+ cfg.swaps = el.swaps;
80
+ if (el.parts?.length) {
81
+ cfg.parts = el.parts.map((p) => ({
82
+ name: p.name ?? '',
83
+ x: p.x,
84
+ y: p.y,
85
+ width: p.width,
86
+ height: p.height,
87
+ charset: p.charset,
88
+ }));
89
+ }
90
+ if (el.variants) {
91
+ cfg.variants = Object.fromEntries(Object.entries(el.variants).map(([k, v]) => [
92
+ k,
93
+ { template: path.join(dir, 'templates', v.filename) },
94
+ ]));
95
+ }
96
+ return cfg;
97
+ });
98
+ return {
99
+ name,
100
+ blankScreenPath: path.join(dir, 'blank.png'),
101
+ ready: raw.ready,
102
+ elementConfigs,
103
+ };
104
+ }
105
+ //# sourceMappingURL=configure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configure.js","sourceRoot":"","sources":["../src/configure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAe7B,IAAI,YAAY,GAAiB,EAAE,CAAC;AAEpC,MAAM,UAAU,eAAe;IAC7B,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,MAAoB;IAClD,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IACjC,Y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AAe,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC;QAC5C,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,cAAc;KACf,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Page } from '@playwright/test';
2
+ export declare function injectDevtools(page: Page): Promise<void>;
3
+ //# sourceMappingURL=devtools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"devtools.d.ts","sourceRoot":"","sources":["../src/devtools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAmO7C,wBAAsB,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAW9D"}
@@ -0,0 +1,235 @@
1
+ import { writeScreenBuffer } from './configure.js';
2
+ const FAB_SCRIPT = `(function () {
3
+ if (window.__ocrDevtools) return;
4
+ window.__ocrDevtools = true;
5
+
6
+ const style = document.createElement('style');
7
+ style.textContent = \`
8
+ #__ocr-fab {
9
+ position: fixed;
10
+ bottom: 20px;
11
+ right: 20px;
12
+ z-index: 2147483647;
13
+ font-family: system-ui, sans-serif;
14
+ }
15
+ #__ocr-fab-btn {
16
+ width: 48px;
17
+ height: 48px;
18
+ border-radius: 50%;
19
+ background: #1a1a2e;
20
+ border: 2px solid #4f46e5;
21
+ color: #fff;
22
+ font-size: 20px;
23
+ cursor: pointer;
24
+ display: flex;
25
+ align-items: center;
26
+ justify-content: center;
27
+ box-shadow: 0 4px 12px rgba(0,0,0,0.4);
28
+ transition: transform 0.15s;
29
+ }
30
+ #__ocr-fab-btn:hover { transform: scale(1.1); }
31
+ #__ocr-fab-menu {
32
+ position: absolute;
33
+ bottom: 56px;
34
+ right: 0;
35
+ background: #1a1a2e;
36
+ border: 1px solid #4f46e5;
37
+ border-radius: 8px;
38
+ overflow: hidden;
39
+ box-shadow: 0 4px 16px rgba(0,0,0,0.5);
40
+ display: none;
41
+ }
42
+ #__ocr-fab-menu.open { display: block; }
43
+ #__ocr-fab-menu button {
44
+ display: block;
45
+ width: 100%;
46
+ padding: 10px 16px;
47
+ background: none;
48
+ border: none;
49
+ color: #e2e8f0;
50
+ font-size: 13px;
51
+ cursor: pointer;
52
+ white-space: nowrap;
53
+ text-align: left;
54
+ }
55
+ #__ocr-fab-menu button:hover { background: #2d2d4e; }
56
+ #__ocr-modal-backdrop {
57
+ position: fixed;
58
+ inset: 0;
59
+ background: rgba(0,0,0,0.6);
60
+ z-index: 2147483646;
61
+ display: flex;
62
+ align-items: center;
63
+ justify-content: center;
64
+ }
65
+ #__ocr-modal {
66
+ background: #1a1a2e;
67
+ border: 1px solid #4f46e5;
68
+ border-radius: 12px;
69
+ padding: 20px;
70
+ width: 480px;
71
+ max-width: 90vw;
72
+ box-shadow: 0 8px 32px rgba(0,0,0,0.6);
73
+ font-family: system-ui, sans-serif;
74
+ }
75
+ #__ocr-modal h3 {
76
+ margin: 0 0 12px;
77
+ color: #e2e8f0;
78
+ font-size: 15px;
79
+ }
80
+ #__ocr-modal img {
81
+ width: 100%;
82
+ border-radius: 6px;
83
+ border: 1px solid #4f46e5;
84
+ margin-bottom: 12px;
85
+ }
86
+ #__ocr-modal input {
87
+ width: 100%;
88
+ box-sizing: border-box;
89
+ padding: 8px 10px;
90
+ border-radius: 6px;
91
+ border: 1px solid #4f46e5;
92
+ background: #0f0f1a;
93
+ color: #e2e8f0;
94
+ font-size: 13px;
95
+ margin-bottom: 12px;
96
+ outline: none;
97
+ }
98
+ #__ocr-modal input:focus { border-color: #818cf8; }
99
+ #__ocr-modal-actions {
100
+ display: flex;
101
+ gap: 8px;
102
+ justify-content: flex-end;
103
+ }
104
+ #__ocr-modal-actions button {
105
+ padding: 7px 16px;
106
+ border-radius: 6px;
107
+ border: none;
108
+ font-size: 13px;
109
+ cursor: pointer;
110
+ }
111
+ #__ocr-modal-save {
112
+ background: #4f46e5;
113
+ color: #fff;
114
+ }
115
+ #__ocr-modal-save:hover { background: #6366f1; }
116
+ #__ocr-modal-save:disabled { opacity: 0.5; cursor: default; }
117
+ #__ocr-modal-cancel {
118
+ background: #2d2d4e;
119
+ color: #e2e8f0;
120
+ }
121
+ #__ocr-modal-cancel:hover { background: #3d3d5e; }
122
+ #__ocr-toast {
123
+ position: fixed;
124
+ bottom: 80px;
125
+ right: 20px;
126
+ z-index: 2147483647;
127
+ background: #16a34a;
128
+ color: #fff;
129
+ padding: 8px 14px;
130
+ border-radius: 6px;
131
+ font-size: 13px;
132
+ font-family: system-ui, sans-serif;
133
+ box-shadow: 0 4px 12px rgba(0,0,0,0.4);
134
+ transition: opacity 0.3s;
135
+ }
136
+ \`;
137
+ document.head.appendChild(style);
138
+
139
+ const fab = document.createElement('div');
140
+ fab.id = '__ocr-fab';
141
+ fab.innerHTML = \`
142
+ <div id="__ocr-fab-menu">
143
+ <button id="__ocr-capture-btn">📷 Capture Screen</button>
144
+ </div>
145
+ <button id="__ocr-fab-btn" title="OCR Devtools">👁</button>
146
+ \`;
147
+ document.body.appendChild(fab);
148
+
149
+ const fabBtn = document.getElementById('__ocr-fab-btn');
150
+ const menu = document.getElementById('__ocr-fab-menu');
151
+ const captureBtn = document.getElementById('__ocr-capture-btn');
152
+
153
+ fabBtn.addEventListener('click', () => menu.classList.toggle('open'));
154
+ document.addEventListener('click', (e) => {
155
+ if (!fab.contains(e.target)) menu.classList.remove('open');
156
+ });
157
+
158
+ captureBtn.addEventListener('click', async () => {
159
+ menu.classList.remove('open');
160
+ fab.style.display = 'none';
161
+ let b64;
162
+ try {
163
+ b64 = await window.__ocrCapture();
164
+ } finally {
165
+ fab.style.display = '';
166
+ }
167
+ showModal(b64);
168
+ });
169
+
170
+ function showModal(b64) {
171
+ const backdrop = document.createElement('div');
172
+ backdrop.id = '__ocr-modal-backdrop';
173
+ backdrop.innerHTML = \`
174
+ <div id="__ocr-modal">
175
+ <h3>Captured Screen</h3>
176
+ <img src="data:image/png;base64,\${b64}" />
177
+ <input id="__ocr-name-input" type="text" placeholder="Screen name (e.g. desktop, customer-info)" />
178
+ <div id="__ocr-modal-actions">
179
+ <button id="__ocr-modal-cancel">Cancel</button>
180
+ <button id="__ocr-modal-save">Save</button>
181
+ </div>
182
+ </div>
183
+ \`;
184
+ document.body.appendChild(backdrop);
185
+
186
+ const input = document.getElementById('__ocr-name-input');
187
+ const saveBtn = document.getElementById('__ocr-modal-save');
188
+ const cancelBtn = document.getElementById('__ocr-modal-cancel');
189
+
190
+ input.focus();
191
+
192
+ cancelBtn.addEventListener('click', () => backdrop.remove());
193
+ backdrop.addEventListener('click', (e) => { if (e.target === backdrop) backdrop.remove(); });
194
+
195
+ saveBtn.addEventListener('click', async () => {
196
+ const name = input.value.trim();
197
+ if (!name) { input.focus(); return; }
198
+ saveBtn.disabled = true;
199
+ saveBtn.textContent = 'Saving…';
200
+ try {
201
+ await window.__ocrSave(name, b64);
202
+ backdrop.remove();
203
+ showToast('Saved: ' + name);
204
+ } catch (err) {
205
+ saveBtn.disabled = false;
206
+ saveBtn.textContent = 'Save';
207
+ alert('Save failed: ' + err.message);
208
+ }
209
+ });
210
+
211
+ input.addEventListener('keydown', (e) => {
212
+ if (e.key === 'Enter') saveBtn.click();
213
+ if (e.key === 'Escape') backdrop.remove();
214
+ });
215
+ }
216
+
217
+ function showToast(msg) {
218
+ const t = document.createElement('div');
219
+ t.id = '__ocr-toast';
220
+ t.textContent = msg;
221
+ document.body.appendChild(t);
222
+ setTimeout(() => { t.style.opacity = '0'; setTimeout(() => t.remove(), 300); }, 2500);
223
+ }
224
+ })();`;
225
+ export async function injectDevtools(page) {
226
+ await page.exposeFunction('__ocrCapture', async () => {
227
+ const buffer = await page.screenshot({ timeout: 5_000 });
228
+ return buffer.toString('base64');
229
+ });
230
+ await page.exposeFunction('__ocrSave', async (name, b64) => {
231
+ writeScreenBuffer(name, Buffer.from(b64, 'base64'));
232
+ });
233
+ await page.addInitScript(FAB_SCRIPT);
234
+ }
235
+ //# sourceMappingURL=devtools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"devtools.js","sourceRoot":"","sources":["../src/devtools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,MAAM,UAAU,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MA8Nb,CAAC;AAEP,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAAU;IAC7C,MAAM,IAAI,CAAC,cAAc,CAAC,cAAc,EAAE,KAAK,IAAqB,EAAE;QACpE,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;QACzD,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,MAAM,IAAI,CAAC,cAAc,CAAC,WAAW,EAAE,KAAK,EAAE,IAAY,EAAE,GAAW,EAAiB,EAAE;QACxF,iBAAiB,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;IAEH,MAAM,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;AACvC,CAAC"}
@@ -0,0 +1,177 @@
1
+ import type { ElementResult, Rect, ElementType } from './types.js';
2
+ import type { Page } from '@playwright/test';
3
+ import { type FieldRead, type OcrOverflow, type OcrSwaps } from './utils/ocr.js';
4
+ export declare const VISIBLE_CONFIDENCE = 0.7;
5
+ export type MatchOptions = {
6
+ swaps?: OcrSwaps;
7
+ overflow?: OcrOverflow;
8
+ read?: FieldRead;
9
+ };
10
+ export type HaveTextOptions = {
11
+ timeout?: number;
12
+ /** Expected glyph → OCR glyphs allowed in its place, e.g. `{ '@': ['Q', 'C'], '5': 'S' }`. */
13
+ swaps?: OcrSwaps;
14
+ /** Clip handling. Prefer setting this on the screen config. */
15
+ overflow?: OcrOverflow;
16
+ overflowSlop?: number;
17
+ /** Override config `read`. `clipboard` is click / select-all / copy. */
18
+ read?: FieldRead;
19
+ };
20
+ export type WaitForOptions = {
21
+ visible?: boolean;
22
+ timeout?: number;
23
+ };
24
+ export type LiveScreen = {
25
+ waitForElement(name: string, options?: WaitForOptions): Promise<void>;
26
+ elementResult(name: string, partName?: string): ElementResult | undefined;
27
+ matchOptions(name: string, partName?: string): MatchOptions;
28
+ markDirty(): void;
29
+ ensureFresh(): Promise<void>;
30
+ paintOverlay(result: ElementResult, label?: string): Promise<void>;
31
+ hideOverlay(): Promise<void>;
32
+ };
33
+ /**
34
+ * Playwright-style element wrapper with chainable assertions
35
+ * Includes built-in retry logic similar to Playwright's auto-waiting
36
+ */
37
+ export declare class ScreenElement {
38
+ private result;
39
+ private page?;
40
+ private live?;
41
+ private readonly parentName?;
42
+ constructor(result: ElementResult, page?: Page | undefined, live?: LiveScreen | undefined, parentName?: string | undefined);
43
+ private get label();
44
+ private get rootName();
45
+ private get partName();
46
+ /**
47
+ * Get the element's current value
48
+ */
49
+ value(): string;
50
+ /**
51
+ * OCR for one inner box on a shared-label row.
52
+ */
53
+ part(name: string): ScreenElement;
54
+ /**
55
+ * Get the element's location on screen
56
+ */
57
+ location(): Rect;
58
+ /**
59
+ * Get the element's match confidence
60
+ */
61
+ confidence(): number | undefined;
62
+ /**
63
+ * Get the element's type
64
+ */
65
+ type(): ElementType | undefined;
66
+ /**
67
+ * Get the active variant (if element has variants)
68
+ */
69
+ variant(): string | undefined;
70
+ /**
71
+ * Wait until this element's template matches the live screenshot.
72
+ */
73
+ waitFor(options?: WaitForOptions): Promise<void>;
74
+ /**
75
+ * Assert element is filled/has content
76
+ * @throws if element is empty after timeout
77
+ */
78
+ toBeFilled(options?: {
79
+ timeout?: number;
80
+ }): Promise<void>;
81
+ /**
82
+ * Assert element is empty/has no content
83
+ * @throws if element is filled after timeout
84
+ */
85
+ toBeEmpty(options?: {
86
+ timeout?: number;
87
+ }): Promise<void>;
88
+ /**
89
+ * Assert element is visible (found with confidence > threshold).
90
+ * When bound to a live page, waits until the template matches.
91
+ */
92
+ toBeVisible(options?: {
93
+ timeout?: number;
94
+ }): Promise<void>;
95
+ /**
96
+ * Assert element has specific text/value
97
+ * @throws if text doesn't match after timeout
98
+ */
99
+ toHaveText(expected: string | RegExp, options?: HaveTextOptions): Promise<void>;
100
+ /**
101
+ * Assert element has exact text/value
102
+ * @throws if text doesn't match exactly after timeout
103
+ */
104
+ toHaveValue(expected: string, options?: HaveTextOptions): Promise<void>;
105
+ /**
106
+ * Assert checkbox/toggle is checked
107
+ * @throws if not checked after timeout
108
+ */
109
+ toBeChecked(options?: {
110
+ timeout?: number;
111
+ }): Promise<void>;
112
+ /**
113
+ * Assert checkbox/toggle is unchecked
114
+ * @throws if checked after timeout
115
+ */
116
+ toBeUnchecked(options?: {
117
+ timeout?: number;
118
+ }): Promise<void>;
119
+ /**
120
+ * Assert element is in specific variant state
121
+ * @throws if variant doesn't match after timeout
122
+ */
123
+ toHaveVariant(expected: string, options?: {
124
+ timeout?: number;
125
+ }): Promise<void>;
126
+ /**
127
+ * Assert element matches with high confidence
128
+ * @throws if confidence below threshold after timeout
129
+ */
130
+ toHaveConfidence(threshold: number, options?: {
131
+ timeout?: number;
132
+ }): Promise<void>;
133
+ /**
134
+ * Click the element at its center
135
+ * Requires page to be provided
136
+ */
137
+ click(options?: {
138
+ timeout?: number;
139
+ }): Promise<void>;
140
+ /**
141
+ * Type text into the element.
142
+ * Clicks the value box (ocrRect), not the label crop, then types.
143
+ * Requires page to be provided
144
+ */
145
+ fill(text: string, options?: {
146
+ timeout?: number;
147
+ }): Promise<void>;
148
+ private clickRect;
149
+ /**
150
+ * Get custom metadata from custom matcher
151
+ * Returns undefined if no metadata available
152
+ */
153
+ metadata(): Record<string, any> | undefined;
154
+ /**
155
+ * Get a specific metadata value
156
+ */
157
+ getMetadata<T = any>(key: string): T | undefined;
158
+ /**
159
+ * Get element info for debugging
160
+ */
161
+ info(): ElementResult;
162
+ private syncResult;
163
+ private highlight;
164
+ private withOverlay;
165
+ private isLocated;
166
+ private ensureLocated;
167
+ private waitUntil;
168
+ private resolvedMatch;
169
+ /**
170
+ * Retry a synchronous assertion check until it passes or the deadline is reached.
171
+ * `check` returns an error message string on failure, or undefined on success.
172
+ * When timeout is 0 or there is no live screen, the check runs exactly once.
173
+ */
174
+ private retryAssertion;
175
+ private copyFromField;
176
+ }
177
+ //# sourceMappingURL=element.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../src/element.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,QAAQ,EACd,MAAM,gBAAgB,CAAC;AAGxB,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAEtC,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,QAAQ,CAAC,EAAE,WAAW,CAAC;IACvB,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8FAA8F;IAC9F,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,WAAW,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,wEAAwE;IACxE,IA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