@rickcedwhat/playwright-smart-vision 0.2.0-next.ea65044 → 0.3.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.
@@ -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;AAoQ7C,wBAAsB,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAa9D"}
1
+ {"version":3,"file":"devtools.d.ts","sourceRoot":"","sources":["../src/devtools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AA2P7C,wBAAsB,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAe9D"}
package/dist/devtools.js CHANGED
@@ -1,18 +1,41 @@
1
1
  import { writeScreenBuffer } from './configure.js';
2
- const FAB_SCRIPT = `(function () {
3
- if (!window.__ocrKeyboardShield) {
4
- window.__ocrKeyboardShield = true;
5
- const shield = (e) => {
6
- const backdrop = document.getElementById('__ocr-modal-backdrop');
7
- if (backdrop && backdrop.contains(e.target)) {
8
- e.stopImmediatePropagation();
2
+ /** First document-capture listener: type into the name field before Guacamole can steal keys. */
3
+ const NAME_INPUT_SHIELD = `(function () {
4
+ if (window.__ocrNameInputShield) return;
5
+ window.__ocrNameInputShield = true;
6
+
7
+ document.addEventListener('keydown', (e) => {
8
+ const input = document.getElementById('__ocr-name-input');
9
+ if (!input || e.target !== input) return;
10
+ if (e.ctrlKey || e.metaKey || e.altKey) return;
11
+
12
+ const start = input.selectionStart ?? input.value.length;
13
+ const end = input.selectionEnd ?? input.value.length;
14
+
15
+ if (e.key.length === 1) {
16
+ input.value = input.value.slice(0, start) + e.key + input.value.slice(end);
17
+ input.setSelectionRange(start + 1, start + 1);
18
+ } else if (e.key === 'Backspace') {
19
+ if (start !== end) {
20
+ input.value = input.value.slice(0, start) + input.value.slice(end);
21
+ input.setSelectionRange(start, start);
22
+ } else if (start > 0) {
23
+ input.value = input.value.slice(0, start - 1) + input.value.slice(end);
24
+ input.setSelectionRange(start - 1, start - 1);
9
25
  }
10
- };
11
- for (const type of ['keydown', 'keyup', 'keypress']) {
12
- document.addEventListener(type, shield, true);
26
+ } else if (e.key === 'Enter') {
27
+ document.getElementById('__ocr-modal-save')?.click();
28
+ } else if (e.key === 'Escape') {
29
+ document.getElementById('__ocr-modal-backdrop')?.remove();
30
+ } else {
31
+ return;
13
32
  }
14
- }
15
33
 
34
+ e.preventDefault();
35
+ e.stopImmediatePropagation();
36
+ }, true);
37
+ })();`;
38
+ const FAB_SCRIPT = `(function () {
16
39
  if (window.__ocrDevtools) return;
17
40
  window.__ocrDevtools = true;
18
41
 
@@ -30,17 +53,18 @@ const FAB_SCRIPT = `(function () {
30
53
  right: 20px;
31
54
  z-index: 2147483647;
32
55
  font-family: system-ui, sans-serif;
33
- display: block;
34
- line-height: 0;
35
56
  }
36
57
  #__ocr-fab-btn {
37
58
  width: 48px;
38
59
  height: 48px;
39
60
  min-width: 48px;
40
61
  min-height: 48px;
62
+ max-width: 48px;
63
+ max-height: 48px;
41
64
  padding: 0;
42
65
  margin: 0;
43
66
  box-sizing: border-box;
67
+ overflow: hidden;
44
68
  border-radius: 50%;
45
69
  background: #1a1a2e;
46
70
  border: 2px solid #4f46e5;
@@ -59,31 +83,6 @@ const FAB_SCRIPT = `(function () {
59
83
  transition: transform 0.15s;
60
84
  }
61
85
  #__ocr-fab-btn:hover { transform: scale(1.1); }
62
- #__ocr-fab-menu {
63
- position: absolute;
64
- bottom: 56px;
65
- right: 0;
66
- background: #1a1a2e;
67
- border: 1px solid #4f46e5;
68
- border-radius: 8px;
69
- overflow: hidden;
70
- box-shadow: 0 4px 16px rgba(0,0,0,0.5);
71
- display: none;
72
- }
73
- #__ocr-fab-menu.open { display: block; }
74
- #__ocr-fab-menu button {
75
- display: block;
76
- width: 100%;
77
- padding: 10px 16px;
78
- background: none;
79
- border: none;
80
- color: #e2e8f0;
81
- font-size: 13px;
82
- cursor: pointer;
83
- white-space: nowrap;
84
- text-align: left;
85
- }
86
- #__ocr-fab-menu button:hover { background: #2d2d4e; }
87
86
  #__ocr-modal-backdrop {
88
87
  position: fixed;
89
88
  inset: 0;
@@ -150,10 +149,7 @@ const FAB_SCRIPT = `(function () {
150
149
  const fab = document.createElement('div');
151
150
  fab.id = '__ocr-fab';
152
151
  fab.innerHTML = \`
153
- <div id="__ocr-fab-menu">
154
- <button id="__ocr-capture-btn">\u{1F4F7} Capture Screen</button>
155
- </div>
156
- <button id="__ocr-fab-btn" title="OCR Devtools">\u{1F441}</button>
152
+ <button id="__ocr-fab-btn" title="Capture screen">\u{1F441}</button>
157
153
  \`;
158
154
 
159
155
  function isolateFromPage(el) {
@@ -163,21 +159,15 @@ const FAB_SCRIPT = `(function () {
163
159
  }
164
160
  }
165
161
 
166
- isolateFromPage(fab);
162
+ fab.addEventListener('mousedown', (e) => e.stopPropagation());
163
+ fab.addEventListener('mouseup', (e) => e.stopPropagation());
164
+ fab.addEventListener('click', (e) => e.stopPropagation());
167
165
 
168
166
  (document.body || document.documentElement).appendChild(fab);
169
167
 
170
168
  const fabBtn = fab.querySelector('#__ocr-fab-btn');
171
- const menu = fab.querySelector('#__ocr-fab-menu');
172
- const captureBtn = fab.querySelector('#__ocr-capture-btn');
173
-
174
- fabBtn.addEventListener('click', (e) => { e.stopPropagation(); menu.classList.toggle('open'); });
175
- document.addEventListener('click', (e) => {
176
- if (!fab.contains(e.target)) menu.classList.remove('open');
177
- });
178
169
 
179
- captureBtn.addEventListener('click', async () => {
180
- menu.classList.remove('open');
170
+ fabBtn.addEventListener('click', async () => {
181
171
  fab.style.display = 'none';
182
172
  let b64;
183
173
  try {
@@ -264,7 +254,9 @@ export async function injectDevtools(page) {
264
254
  writeScreenBuffer(name, Buffer.from(b64, 'base64'));
265
255
  });
266
256
  // addInitScript covers future navigations; evaluate covers the already-loaded page.
257
+ await page.addInitScript(NAME_INPUT_SHIELD);
267
258
  await page.addInitScript(FAB_SCRIPT);
259
+ await page.evaluate(NAME_INPUT_SHIELD);
268
260
  await page.evaluate(FAB_SCRIPT);
269
261
  }
270
262
  //# sourceMappingURL=devtools.js.map
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MA+Pb,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,oFAAoF;IACpF,MAAM,IAAI,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AAC;IACrC,MAAM,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC;IACvC,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;AAClC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rickcedwhat/playwright-smart-vision",
3
- "version": "0.2.0-next.ea65044",
3
+ "version": "0.3.0",
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",