@rickcedwhat/playwright-smart-vision 0.2.0 → 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.
- package/dist/devtools.d.ts.map +1 -1
- package/dist/devtools.js +75 -38
- package/dist/devtools.js.map +1 -1
- package/package.json +1 -1
package/dist/devtools.d.ts.map
CHANGED
|
@@ -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;
|
|
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,10 +1,49 @@
|
|
|
1
1
|
import { writeScreenBuffer } from './configure.js';
|
|
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);
|
|
25
|
+
}
|
|
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;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
e.preventDefault();
|
|
35
|
+
e.stopImmediatePropagation();
|
|
36
|
+
}, true);
|
|
37
|
+
})();`;
|
|
2
38
|
const FAB_SCRIPT = `(function () {
|
|
3
39
|
if (window.__ocrDevtools) return;
|
|
4
40
|
window.__ocrDevtools = true;
|
|
5
41
|
|
|
42
|
+
console.log('[OCR devtools] script loaded, readyState:', document.readyState);
|
|
43
|
+
|
|
6
44
|
function init() {
|
|
7
45
|
if (document.getElementById('__ocr-fab')) return;
|
|
46
|
+
console.log('[OCR devtools] mounting FAB');
|
|
8
47
|
|
|
9
48
|
const style = document.createElement('style');
|
|
10
49
|
style.textContent = \`
|
|
@@ -18,44 +57,32 @@ const FAB_SCRIPT = `(function () {
|
|
|
18
57
|
#__ocr-fab-btn {
|
|
19
58
|
width: 48px;
|
|
20
59
|
height: 48px;
|
|
60
|
+
min-width: 48px;
|
|
61
|
+
min-height: 48px;
|
|
62
|
+
max-width: 48px;
|
|
63
|
+
max-height: 48px;
|
|
64
|
+
padding: 0;
|
|
65
|
+
margin: 0;
|
|
66
|
+
box-sizing: border-box;
|
|
67
|
+
overflow: hidden;
|
|
21
68
|
border-radius: 50%;
|
|
22
69
|
background: #1a1a2e;
|
|
23
70
|
border: 2px solid #4f46e5;
|
|
24
71
|
color: #fff;
|
|
25
72
|
font-size: 20px;
|
|
73
|
+
line-height: 1;
|
|
26
74
|
cursor: pointer;
|
|
27
75
|
display: flex;
|
|
28
76
|
align-items: center;
|
|
29
77
|
justify-content: center;
|
|
78
|
+
flex-shrink: 0;
|
|
79
|
+
aspect-ratio: 1;
|
|
80
|
+
appearance: none;
|
|
81
|
+
-webkit-appearance: none;
|
|
30
82
|
box-shadow: 0 4px 12px rgba(0,0,0,0.4);
|
|
31
83
|
transition: transform 0.15s;
|
|
32
84
|
}
|
|
33
85
|
#__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
86
|
#__ocr-modal-backdrop {
|
|
60
87
|
position: fixed;
|
|
61
88
|
inset: 0;
|
|
@@ -64,6 +91,7 @@ const FAB_SCRIPT = `(function () {
|
|
|
64
91
|
display: flex;
|
|
65
92
|
align-items: center;
|
|
66
93
|
justify-content: center;
|
|
94
|
+
font-family: system-ui, sans-serif;
|
|
67
95
|
}
|
|
68
96
|
#__ocr-modal {
|
|
69
97
|
background: #1a1a2e;
|
|
@@ -74,6 +102,7 @@ const FAB_SCRIPT = `(function () {
|
|
|
74
102
|
max-width: 90vw;
|
|
75
103
|
box-shadow: 0 8px 32px rgba(0,0,0,0.6);
|
|
76
104
|
font-family: system-ui, sans-serif;
|
|
105
|
+
line-height: normal;
|
|
77
106
|
}
|
|
78
107
|
#__ocr-modal h3 { margin: 0 0 12px; color: #e2e8f0; font-size: 15px; }
|
|
79
108
|
#__ocr-modal img { width: 100%; border-radius: 6px; border: 1px solid #4f46e5; margin-bottom: 12px; }
|
|
@@ -88,6 +117,9 @@ const FAB_SCRIPT = `(function () {
|
|
|
88
117
|
font-size: 13px;
|
|
89
118
|
margin-bottom: 12px;
|
|
90
119
|
outline: none;
|
|
120
|
+
pointer-events: auto;
|
|
121
|
+
user-select: text;
|
|
122
|
+
-webkit-user-select: text;
|
|
91
123
|
}
|
|
92
124
|
#__ocr-modal input:focus { border-color: #818cf8; }
|
|
93
125
|
#__ocr-modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
|
|
@@ -117,12 +149,16 @@ const FAB_SCRIPT = `(function () {
|
|
|
117
149
|
const fab = document.createElement('div');
|
|
118
150
|
fab.id = '__ocr-fab';
|
|
119
151
|
fab.innerHTML = \`
|
|
120
|
-
<
|
|
121
|
-
<button id="__ocr-capture-btn">\u{1F4F7} Capture Screen</button>
|
|
122
|
-
</div>
|
|
123
|
-
<button id="__ocr-fab-btn" title="OCR Devtools">\u{1F441}</button>
|
|
152
|
+
<button id="__ocr-fab-btn" title="Capture screen">\u{1F441}</button>
|
|
124
153
|
\`;
|
|
125
154
|
|
|
155
|
+
function isolateFromPage(el) {
|
|
156
|
+
const types = ['mousedown', 'mouseup', 'click', 'dblclick', 'keydown', 'keyup', 'keypress', 'input', 'compositionstart', 'compositionupdate', 'compositionend'];
|
|
157
|
+
for (const type of types) {
|
|
158
|
+
el.addEventListener(type, (e) => e.stopPropagation());
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
126
162
|
fab.addEventListener('mousedown', (e) => e.stopPropagation());
|
|
127
163
|
fab.addEventListener('mouseup', (e) => e.stopPropagation());
|
|
128
164
|
fab.addEventListener('click', (e) => e.stopPropagation());
|
|
@@ -130,16 +166,8 @@ const FAB_SCRIPT = `(function () {
|
|
|
130
166
|
(document.body || document.documentElement).appendChild(fab);
|
|
131
167
|
|
|
132
168
|
const fabBtn = fab.querySelector('#__ocr-fab-btn');
|
|
133
|
-
const menu = fab.querySelector('#__ocr-fab-menu');
|
|
134
|
-
const captureBtn = fab.querySelector('#__ocr-capture-btn');
|
|
135
169
|
|
|
136
|
-
fabBtn.addEventListener('click', (
|
|
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');
|
|
170
|
+
fabBtn.addEventListener('click', async () => {
|
|
143
171
|
fab.style.display = 'none';
|
|
144
172
|
let b64;
|
|
145
173
|
try {
|
|
@@ -166,10 +194,15 @@ const FAB_SCRIPT = `(function () {
|
|
|
166
194
|
\`;
|
|
167
195
|
document.body.appendChild(backdrop);
|
|
168
196
|
|
|
197
|
+
const modal = backdrop.querySelector('#__ocr-modal');
|
|
169
198
|
const input = backdrop.querySelector('#__ocr-name-input');
|
|
170
199
|
const saveBtn = backdrop.querySelector('#__ocr-modal-save');
|
|
171
200
|
const cancelBtn = backdrop.querySelector('#__ocr-modal-cancel');
|
|
172
201
|
|
|
202
|
+
isolateFromPage(backdrop);
|
|
203
|
+
isolateFromPage(modal);
|
|
204
|
+
isolateFromPage(input);
|
|
205
|
+
|
|
173
206
|
input.focus();
|
|
174
207
|
|
|
175
208
|
cancelBtn.addEventListener('click', () => backdrop.remove());
|
|
@@ -220,6 +253,10 @@ export async function injectDevtools(page) {
|
|
|
220
253
|
await page.exposeFunction('__ocrSave', async (name, b64) => {
|
|
221
254
|
writeScreenBuffer(name, Buffer.from(b64, 'base64'));
|
|
222
255
|
});
|
|
256
|
+
// addInitScript covers future navigations; evaluate covers the already-loaded page.
|
|
257
|
+
await page.addInitScript(NAME_INPUT_SHIELD);
|
|
223
258
|
await page.addInitScript(FAB_SCRIPT);
|
|
259
|
+
await page.evaluate(NAME_INPUT_SHIELD);
|
|
260
|
+
await page.evaluate(FAB_SCRIPT);
|
|
224
261
|
}
|
|
225
262
|
//# sourceMappingURL=devtools.js.map
|
package/dist/devtools.js.map
CHANGED
|
@@ -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
|
|
1
|
+
{"version":3,"file":"devtools.js","sourceRoot":"","sources":["../src/devtools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,iGAAiG;AACjG,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAkCpB,CAAC;AAEP,MAAM,UAAU,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAiNb,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,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC;IAC5C,MAAM,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IACrC,MAAM,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC;IACvC,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;AAClC,CAAC"}
|
package/package.json
CHANGED