@rickcedwhat/playwright-smart-vision 0.1.0-next.a2f44fc → 0.1.0-next.aab35ec

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.
@@ -11,10 +11,10 @@ interface GlobalConfig {
11
11
  export declare function getGlobalConfig(): GlobalConfig;
12
12
  /**
13
13
  * Configure storage root and optional devtools FAB.
14
- * Pass `page` as the second argument to inject the FAB immediately (QA Wolf / non-fixture usage).
14
+ * Pass `page` to inject the FAB immediately (QA Wolf / non-fixture usage).
15
15
  * In fixture-based Playwright tests the FAB is injected automatically by the ocrScreen fixture.
16
16
  *
17
- * await configure({ storage: { root: process.env.TEAM_STORAGE_DIR + '/screens' }, devtools: true }, page);
17
+ * await configure({ storage: { root: process.env.TEAM_STORAGE_DIR + '/screens' }, devtools: true, page });
18
18
  */
19
19
  export declare function configure(config: GlobalConfig): Promise<void>;
20
20
  /**
package/dist/configure.js CHANGED
@@ -6,10 +6,10 @@ export function getGlobalConfig() {
6
6
  }
7
7
  /**
8
8
  * Configure storage root and optional devtools FAB.
9
- * Pass `page` as the second argument to inject the FAB immediately (QA Wolf / non-fixture usage).
9
+ * Pass `page` to inject the FAB immediately (QA Wolf / non-fixture usage).
10
10
  * In fixture-based Playwright tests the FAB is injected automatically by the ocrScreen fixture.
11
11
  *
12
- * await configure({ storage: { root: process.env.TEAM_STORAGE_DIR + '/screens' }, devtools: true }, page);
12
+ * await configure({ storage: { root: process.env.TEAM_STORAGE_DIR + '/screens' }, devtools: true, page });
13
13
  */
14
14
  export async function configure(config) {
15
15
  const { page, ...rest } = config;
@@ -1 +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"}
1
+ {"version":3,"file":"devtools.d.ts","sourceRoot":"","sources":["../src/devtools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAyN7C,wBAAsB,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAW9D"}
package/dist/devtools.js CHANGED
@@ -3,223 +3,213 @@ const FAB_SCRIPT = `(function () {
3
3
  if (window.__ocrDevtools) return;
4
4
  window.__ocrDevtools = true;
5
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>
6
+ function init() {
7
+ if (document.getElementById('__ocr-fab')) return;
8
+
9
+ const style = document.createElement('style');
10
+ style.textContent = \`
11
+ #__ocr-fab {
12
+ position: fixed;
13
+ bottom: 20px;
14
+ right: 20px;
15
+ z-index: 2147483647;
16
+ font-family: system-ui, sans-serif;
17
+ }
18
+ #__ocr-fab-btn {
19
+ width: 48px;
20
+ height: 48px;
21
+ border-radius: 50%;
22
+ background: #1a1a2e;
23
+ border: 2px solid #4f46e5;
24
+ color: #fff;
25
+ font-size: 20px;
26
+ cursor: pointer;
27
+ display: flex;
28
+ align-items: center;
29
+ justify-content: center;
30
+ box-shadow: 0 4px 12px rgba(0,0,0,0.4);
31
+ transition: transform 0.15s;
32
+ }
33
+ #__ocr-fab-btn:hover { transform: scale(1.1); }
34
+ #__ocr-fab-menu {
35
+ position: absolute;
36
+ bottom: 56px;
37
+ right: 0;
38
+ background: #1a1a2e;
39
+ border: 1px solid #4f46e5;
40
+ border-radius: 8px;
41
+ overflow: hidden;
42
+ box-shadow: 0 4px 16px rgba(0,0,0,0.5);
43
+ display: none;
44
+ }
45
+ #__ocr-fab-menu.open { display: block; }
46
+ #__ocr-fab-menu button {
47
+ display: block;
48
+ width: 100%;
49
+ padding: 10px 16px;
50
+ background: none;
51
+ border: none;
52
+ color: #e2e8f0;
53
+ font-size: 13px;
54
+ cursor: pointer;
55
+ white-space: nowrap;
56
+ text-align: left;
57
+ }
58
+ #__ocr-fab-menu button:hover { background: #2d2d4e; }
59
+ #__ocr-modal-backdrop {
60
+ position: fixed;
61
+ inset: 0;
62
+ background: rgba(0,0,0,0.6);
63
+ z-index: 2147483646;
64
+ display: flex;
65
+ align-items: center;
66
+ justify-content: center;
67
+ }
68
+ #__ocr-modal {
69
+ background: #1a1a2e;
70
+ border: 1px solid #4f46e5;
71
+ border-radius: 12px;
72
+ padding: 20px;
73
+ width: 480px;
74
+ max-width: 90vw;
75
+ box-shadow: 0 8px 32px rgba(0,0,0,0.6);
76
+ font-family: system-ui, sans-serif;
77
+ }
78
+ #__ocr-modal h3 { margin: 0 0 12px; color: #e2e8f0; font-size: 15px; }
79
+ #__ocr-modal img { width: 100%; border-radius: 6px; border: 1px solid #4f46e5; margin-bottom: 12px; }
80
+ #__ocr-modal input {
81
+ width: 100%;
82
+ box-sizing: border-box;
83
+ padding: 8px 10px;
84
+ border-radius: 6px;
85
+ border: 1px solid #4f46e5;
86
+ background: #0f0f1a;
87
+ color: #e2e8f0;
88
+ font-size: 13px;
89
+ margin-bottom: 12px;
90
+ outline: none;
91
+ }
92
+ #__ocr-modal input:focus { border-color: #818cf8; }
93
+ #__ocr-modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
94
+ #__ocr-modal-actions button { padding: 7px 16px; border-radius: 6px; border: none; font-size: 13px; cursor: pointer; }
95
+ #__ocr-modal-save { background: #4f46e5; color: #fff; }
96
+ #__ocr-modal-save:hover { background: #6366f1; }
97
+ #__ocr-modal-save:disabled { opacity: 0.5; cursor: default; }
98
+ #__ocr-modal-cancel { background: #2d2d4e; color: #e2e8f0; }
99
+ #__ocr-modal-cancel:hover { background: #3d3d5e; }
100
+ #__ocr-toast {
101
+ position: fixed;
102
+ bottom: 80px;
103
+ right: 20px;
104
+ z-index: 2147483647;
105
+ background: #16a34a;
106
+ color: #fff;
107
+ padding: 8px 14px;
108
+ border-radius: 6px;
109
+ font-size: 13px;
110
+ font-family: system-ui, sans-serif;
111
+ box-shadow: 0 4px 12px rgba(0,0,0,0.4);
112
+ transition: opacity 0.3s;
113
+ }
114
+ \`;
115
+ (document.head || document.documentElement).appendChild(style);
116
+
117
+ const fab = document.createElement('div');
118
+ fab.id = '__ocr-fab';
119
+ fab.innerHTML = \`
120
+ <div id="__ocr-fab-menu">
121
+ <button id="__ocr-capture-btn">\u{1F4F7} Capture Screen</button>
182
122
  </div>
123
+ <button id="__ocr-fab-btn" title="OCR Devtools">\u{1F441}</button>
183
124
  \`;
184
- document.body.appendChild(backdrop);
185
125
 
186
- const input = document.getElementById('__ocr-name-input');
187
- const saveBtn = document.getElementById('__ocr-modal-save');
188
- const cancelBtn = document.getElementById('__ocr-modal-cancel');
126
+ fab.addEventListener('mousedown', (e) => e.stopPropagation());
127
+ fab.addEventListener('mouseup', (e) => e.stopPropagation());
128
+ fab.addEventListener('click', (e) => e.stopPropagation());
189
129
 
190
- input.focus();
130
+ (document.body || document.documentElement).appendChild(fab);
191
131
 
192
- cancelBtn.addEventListener('click', () => backdrop.remove());
193
- backdrop.addEventListener('click', (e) => { if (e.target === backdrop) backdrop.remove(); });
132
+ const fabBtn = fab.querySelector('#__ocr-fab-btn');
133
+ const menu = fab.querySelector('#__ocr-fab-menu');
134
+ const captureBtn = fab.querySelector('#__ocr-capture-btn');
194
135
 
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…';
136
+ fabBtn.addEventListener('click', (e) => { e.stopPropagation(); menu.classList.toggle('open'); });
137
+ document.addEventListener('click', (e) => {
138
+ if (!fab.contains(e.target)) menu.classList.remove('open');
139
+ });
140
+
141
+ captureBtn.addEventListener('click', async () => {
142
+ menu.classList.remove('open');
143
+ fab.style.display = 'none';
144
+ let b64;
200
145
  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);
146
+ b64 = await window.__ocrCapture();
147
+ } finally {
148
+ fab.style.display = '';
208
149
  }
150
+ showModal(b64);
209
151
  });
210
152
 
211
- input.addEventListener('keydown', (e) => {
212
- if (e.key === 'Enter') saveBtn.click();
213
- if (e.key === 'Escape') backdrop.remove();
214
- });
153
+ function showModal(b64) {
154
+ const backdrop = document.createElement('div');
155
+ backdrop.id = '__ocr-modal-backdrop';
156
+ backdrop.innerHTML = \`
157
+ <div id="__ocr-modal">
158
+ <h3>Captured Screen</h3>
159
+ <img src="data:image/png;base64,\${b64}" />
160
+ <input id="__ocr-name-input" type="text" placeholder="Screen name (e.g. desktop, customer-info)" />
161
+ <div id="__ocr-modal-actions">
162
+ <button id="__ocr-modal-cancel">Cancel</button>
163
+ <button id="__ocr-modal-save">Save</button>
164
+ </div>
165
+ </div>
166
+ \`;
167
+ document.body.appendChild(backdrop);
168
+
169
+ const input = backdrop.querySelector('#__ocr-name-input');
170
+ const saveBtn = backdrop.querySelector('#__ocr-modal-save');
171
+ const cancelBtn = backdrop.querySelector('#__ocr-modal-cancel');
172
+
173
+ input.focus();
174
+
175
+ cancelBtn.addEventListener('click', () => backdrop.remove());
176
+ backdrop.addEventListener('click', (e) => { if (e.target === backdrop) backdrop.remove(); });
177
+
178
+ saveBtn.addEventListener('click', async () => {
179
+ const name = input.value.trim();
180
+ if (!name) { input.focus(); return; }
181
+ saveBtn.disabled = true;
182
+ saveBtn.textContent = 'Saving…';
183
+ try {
184
+ await window.__ocrSave(name, b64);
185
+ backdrop.remove();
186
+ showToast('Saved: ' + name);
187
+ } catch (err) {
188
+ saveBtn.disabled = false;
189
+ saveBtn.textContent = 'Save';
190
+ alert('Save failed: ' + err.message);
191
+ }
192
+ });
193
+
194
+ input.addEventListener('keydown', (e) => {
195
+ if (e.key === 'Enter') saveBtn.click();
196
+ if (e.key === 'Escape') backdrop.remove();
197
+ });
198
+ }
199
+
200
+ function showToast(msg) {
201
+ const t = document.createElement('div');
202
+ t.id = '__ocr-toast';
203
+ t.textContent = msg;
204
+ document.body.appendChild(t);
205
+ setTimeout(() => { t.style.opacity = '0'; setTimeout(() => t.remove(), 300); }, 2500);
206
+ }
215
207
  }
216
208
 
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);
209
+ if (document.readyState === 'loading') {
210
+ document.addEventListener('DOMContentLoaded', init);
211
+ } else {
212
+ init();
223
213
  }
224
214
  })();`;
225
215
  export async function injectDevtools(page) {
@@ -1 +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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rickcedwhat/playwright-smart-vision",
3
- "version": "0.1.0-next.a2f44fc",
3
+ "version": "0.1.0-next.aab35ec",
4
4
  "description": "Computer-vision and OCR-based element assertions for Playwright — local, fast, no GPT Vision required",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -55,6 +55,11 @@
55
55
  "peerDependencies": {
56
56
  "@playwright/test": ">=1.50.0"
57
57
  },
58
+ "peerDependenciesMeta": {
59
+ "@playwright/test": {
60
+ "optional": true
61
+ }
62
+ },
58
63
  "dependencies": {
59
64
  "@techstark/opencv-js": "^5.0.0-release.1",
60
65
  "pixelmatch": "^7.2.0",