rune-grab 0.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/LICENSE +21 -0
- package/README.md +77 -0
- package/dist/cli.js +350 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.cts +84 -0
- package/dist/index.d.ts +84 -0
- package/dist/react.cjs +1796 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +62 -0
- package/dist/react.d.ts +62 -0
- package/dist/react.js +1778 -0
- package/dist/react.js.map +1 -0
- package/dist/rune-grab.cjs +1684 -0
- package/dist/rune-grab.cjs.map +1 -0
- package/dist/rune-grab.iife.global.js +66 -0
- package/dist/rune-grab.iife.global.js.map +1 -0
- package/dist/rune-grab.js +1640 -0
- package/dist/rune-grab.js.map +1 -0
- package/dist/vite.cjs +57 -0
- package/dist/vite.cjs.map +1 -0
- package/dist/vite.d.cts +16 -0
- package/dist/vite.d.ts +16 -0
- package/dist/vite.js +36 -0
- package/dist/vite.js.map +1 -0
- package/package.json +162 -0
package/dist/react.js
ADDED
|
@@ -0,0 +1,1778 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __esm = (fn, res) => function __init() {
|
|
4
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
5
|
+
};
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// src/core/screenshot.ts
|
|
12
|
+
async function getStream() {
|
|
13
|
+
if (activeStream) {
|
|
14
|
+
const tracks = activeStream.getVideoTracks();
|
|
15
|
+
if (tracks.length > 0 && tracks[0].readyState === "live") {
|
|
16
|
+
return activeStream;
|
|
17
|
+
}
|
|
18
|
+
activeStream = null;
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
activeStream = await navigator.mediaDevices.getDisplayMedia({
|
|
22
|
+
video: {
|
|
23
|
+
preferCurrentTab: true
|
|
24
|
+
},
|
|
25
|
+
audio: false
|
|
26
|
+
});
|
|
27
|
+
activeStream.getVideoTracks()[0].addEventListener("ended", () => {
|
|
28
|
+
activeStream = null;
|
|
29
|
+
});
|
|
30
|
+
return activeStream;
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function captureFromStream(stream, rect, format, quality) {
|
|
36
|
+
const video = document.createElement("video");
|
|
37
|
+
video.srcObject = stream;
|
|
38
|
+
video.muted = true;
|
|
39
|
+
video.playsInline = true;
|
|
40
|
+
await new Promise((resolve, reject) => {
|
|
41
|
+
video.onloadedmetadata = () => {
|
|
42
|
+
video.play().then(resolve).catch(reject);
|
|
43
|
+
};
|
|
44
|
+
video.onerror = reject;
|
|
45
|
+
});
|
|
46
|
+
await new Promise((r) => requestAnimationFrame(r));
|
|
47
|
+
await new Promise((r) => requestAnimationFrame(r));
|
|
48
|
+
const track = stream.getVideoTracks()[0];
|
|
49
|
+
const settings = track.getSettings();
|
|
50
|
+
const videoW = settings.width || video.videoWidth;
|
|
51
|
+
const videoH = settings.height || video.videoHeight;
|
|
52
|
+
const scaleX = videoW / window.innerWidth;
|
|
53
|
+
const scaleY = videoH / window.innerHeight;
|
|
54
|
+
const sx = rect.left * scaleX;
|
|
55
|
+
const sy = rect.top * scaleY;
|
|
56
|
+
const sw = rect.width * scaleX;
|
|
57
|
+
const sh = rect.height * scaleY;
|
|
58
|
+
const dpr = window.devicePixelRatio || 1;
|
|
59
|
+
const canvas = document.createElement("canvas");
|
|
60
|
+
canvas.width = rect.width * dpr;
|
|
61
|
+
canvas.height = rect.height * dpr;
|
|
62
|
+
const ctx = canvas.getContext("2d");
|
|
63
|
+
ctx.drawImage(video, sx, sy, sw, sh, 0, 0, canvas.width, canvas.height);
|
|
64
|
+
video.pause();
|
|
65
|
+
video.srcObject = null;
|
|
66
|
+
return canvas.toDataURL(format, quality);
|
|
67
|
+
}
|
|
68
|
+
async function captureRect(rect, format = "image/png", quality = 0.92) {
|
|
69
|
+
if (rect.width === 0 || rect.height === 0) return null;
|
|
70
|
+
try {
|
|
71
|
+
const domRect = new DOMRect(rect.x, rect.y, rect.width, rect.height);
|
|
72
|
+
if (customProvider) {
|
|
73
|
+
return await customProvider(domRect);
|
|
74
|
+
}
|
|
75
|
+
const stream = await getStream();
|
|
76
|
+
if (stream) {
|
|
77
|
+
return await captureFromStream(stream, domRect, format, quality);
|
|
78
|
+
}
|
|
79
|
+
console.warn("[rune-grab] No screenshot method available. Use setCaptureProvider() for Electron apps.");
|
|
80
|
+
return null;
|
|
81
|
+
} catch (err) {
|
|
82
|
+
console.warn("[rune-grab] Screenshot capture failed:", err);
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function releaseStream() {
|
|
87
|
+
if (activeStream) {
|
|
88
|
+
activeStream.getTracks().forEach((t) => t.stop());
|
|
89
|
+
activeStream = null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
var customProvider, activeStream;
|
|
93
|
+
var init_screenshot = __esm({
|
|
94
|
+
"src/core/screenshot.ts"() {
|
|
95
|
+
"use strict";
|
|
96
|
+
customProvider = null;
|
|
97
|
+
activeStream = null;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// src/targets/clipboard.ts
|
|
102
|
+
async function copyToClipboard(result) {
|
|
103
|
+
try {
|
|
104
|
+
const items = {};
|
|
105
|
+
items["text/plain"] = new Blob([result.text], { type: "text/plain" });
|
|
106
|
+
if (result.image) {
|
|
107
|
+
const response = await fetch(result.image);
|
|
108
|
+
const imageBlob = await response.blob();
|
|
109
|
+
items["image/png"] = imageBlob;
|
|
110
|
+
}
|
|
111
|
+
await navigator.clipboard.write([
|
|
112
|
+
new ClipboardItem(items)
|
|
113
|
+
]);
|
|
114
|
+
return true;
|
|
115
|
+
} catch {
|
|
116
|
+
try {
|
|
117
|
+
const textarea = document.createElement("textarea");
|
|
118
|
+
textarea.value = result.text;
|
|
119
|
+
textarea.style.position = "fixed";
|
|
120
|
+
textarea.style.opacity = "0";
|
|
121
|
+
document.body.appendChild(textarea);
|
|
122
|
+
textarea.select();
|
|
123
|
+
document.execCommand("copy");
|
|
124
|
+
document.body.removeChild(textarea);
|
|
125
|
+
return true;
|
|
126
|
+
} catch {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
var init_clipboard = __esm({
|
|
132
|
+
"src/targets/clipboard.ts"() {
|
|
133
|
+
"use strict";
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// src/targets/app.ts
|
|
138
|
+
async function isHelperRunning() {
|
|
139
|
+
try {
|
|
140
|
+
const ac = new AbortController();
|
|
141
|
+
const timer = setTimeout(() => ac.abort(), 500);
|
|
142
|
+
const res = await fetch(`http://127.0.0.1:${HELPER_PORT}/health`, {
|
|
143
|
+
signal: ac.signal
|
|
144
|
+
});
|
|
145
|
+
clearTimeout(timer);
|
|
146
|
+
return res.ok;
|
|
147
|
+
} catch {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async function sendToHelper(target, result) {
|
|
152
|
+
try {
|
|
153
|
+
const res = await fetch(`http://127.0.0.1:${HELPER_PORT}/paste`, {
|
|
154
|
+
method: "POST",
|
|
155
|
+
headers: { "Content-Type": "application/json" },
|
|
156
|
+
body: JSON.stringify({
|
|
157
|
+
target,
|
|
158
|
+
text: result.text,
|
|
159
|
+
image: result.image ?? null,
|
|
160
|
+
label: result.label
|
|
161
|
+
})
|
|
162
|
+
});
|
|
163
|
+
return res.ok;
|
|
164
|
+
} catch {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async function sendToApp(target, result) {
|
|
169
|
+
await copyToClipboard(result);
|
|
170
|
+
if (target === "clipboard") {
|
|
171
|
+
return { success: true, method: "clipboard" };
|
|
172
|
+
}
|
|
173
|
+
const helperUp = await isHelperRunning();
|
|
174
|
+
if (helperUp) {
|
|
175
|
+
const ok = await sendToHelper(target, result);
|
|
176
|
+
if (ok) return { success: true, method: "auto" };
|
|
177
|
+
}
|
|
178
|
+
return { success: true, method: "clipboard" };
|
|
179
|
+
}
|
|
180
|
+
var HELPER_PORT;
|
|
181
|
+
var init_app = __esm({
|
|
182
|
+
"src/targets/app.ts"() {
|
|
183
|
+
"use strict";
|
|
184
|
+
init_clipboard();
|
|
185
|
+
HELPER_PORT = 19274;
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// src/core/state.ts
|
|
190
|
+
var isMac, DEFAULTS, s;
|
|
191
|
+
var init_state = __esm({
|
|
192
|
+
"src/core/state.ts"() {
|
|
193
|
+
"use strict";
|
|
194
|
+
isMac = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform);
|
|
195
|
+
DEFAULTS = {
|
|
196
|
+
shortcut: isMac ? "Meta+Shift+G" : "Ctrl+Shift+G",
|
|
197
|
+
target: "clipboard",
|
|
198
|
+
accentColor: "#f5f5f5",
|
|
199
|
+
maxStackDepth: 3,
|
|
200
|
+
onGrab: () => {
|
|
201
|
+
},
|
|
202
|
+
onToggle: () => {
|
|
203
|
+
},
|
|
204
|
+
showTargetPicker: true,
|
|
205
|
+
skipComponents: []
|
|
206
|
+
};
|
|
207
|
+
s = {
|
|
208
|
+
initialized: false,
|
|
209
|
+
active: false,
|
|
210
|
+
locked: false,
|
|
211
|
+
promptMode: false,
|
|
212
|
+
menuExpanded: false,
|
|
213
|
+
targetsExpanded: false,
|
|
214
|
+
grabType: "screenshot",
|
|
215
|
+
autoPasteEnabled: false,
|
|
216
|
+
helperAvailable: false,
|
|
217
|
+
helperChecking: false,
|
|
218
|
+
dockedEdge: null,
|
|
219
|
+
selectedElement: null,
|
|
220
|
+
mmRAF: 0,
|
|
221
|
+
config: { ...DEFAULTS },
|
|
222
|
+
customSkipSet: void 0,
|
|
223
|
+
miniMenu: null,
|
|
224
|
+
overlay: null,
|
|
225
|
+
label: null,
|
|
226
|
+
toolbar: null,
|
|
227
|
+
cursorStyle: null,
|
|
228
|
+
selectionBox: null,
|
|
229
|
+
ssDrawing: false,
|
|
230
|
+
ssStartX: 0,
|
|
231
|
+
ssStartY: 0,
|
|
232
|
+
lastMouseX: 0,
|
|
233
|
+
lastMouseY: 0,
|
|
234
|
+
dragging: false,
|
|
235
|
+
dragPending: false,
|
|
236
|
+
dragStartX: 0,
|
|
237
|
+
dragStartY: 0,
|
|
238
|
+
hasDragged: false,
|
|
239
|
+
dragW: 0,
|
|
240
|
+
dragH: 0,
|
|
241
|
+
dragBaseX: 0,
|
|
242
|
+
dragBaseY: 0,
|
|
243
|
+
dragPointerId: -1,
|
|
244
|
+
dragLastX: 0,
|
|
245
|
+
dragLastY: 0
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
// src/core/constants.ts
|
|
251
|
+
function isLibraryFile(filePath) {
|
|
252
|
+
return filePath.includes("node_modules");
|
|
253
|
+
}
|
|
254
|
+
function isSourceFile(filePath) {
|
|
255
|
+
if (!filePath) return false;
|
|
256
|
+
if (isLibraryFile(filePath)) return false;
|
|
257
|
+
if (filePath.startsWith("webpack-internal:///node_modules/")) return false;
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
var SKIP_PREFIXES, STYLE_PROPS, STYLE_DEFAULTS, KEEP_ATTRS, Z_OVERLAY, Z_TOOLBAR, OWN_IDS, DRAG_THRESHOLD_PX, HELPER_PORT2, HEALTH_CHECK_TIMEOUT_MS, FLASH_VISIBLE_MS, FLASH_REMOVE_MS, LS_KEY;
|
|
261
|
+
var init_constants = __esm({
|
|
262
|
+
"src/core/constants.ts"() {
|
|
263
|
+
"use strict";
|
|
264
|
+
SKIP_PREFIXES = ["_", "$", "Styled(", "motion(", "chakra(", "withRouter(", "connect(", "styled.", "styled(", "tw.", "rc-", "__"];
|
|
265
|
+
STYLE_PROPS = [
|
|
266
|
+
"display",
|
|
267
|
+
"position",
|
|
268
|
+
"overflow",
|
|
269
|
+
"width",
|
|
270
|
+
"height",
|
|
271
|
+
"minWidth",
|
|
272
|
+
"minHeight",
|
|
273
|
+
"maxWidth",
|
|
274
|
+
"maxHeight",
|
|
275
|
+
"flexDirection",
|
|
276
|
+
"flexWrap",
|
|
277
|
+
"justifyContent",
|
|
278
|
+
"alignItems",
|
|
279
|
+
"alignSelf",
|
|
280
|
+
"gap",
|
|
281
|
+
"gridTemplateColumns",
|
|
282
|
+
"gridTemplateRows",
|
|
283
|
+
"padding",
|
|
284
|
+
"margin",
|
|
285
|
+
"fontSize",
|
|
286
|
+
"fontWeight",
|
|
287
|
+
"fontFamily",
|
|
288
|
+
"lineHeight",
|
|
289
|
+
"letterSpacing",
|
|
290
|
+
"textAlign",
|
|
291
|
+
"textTransform",
|
|
292
|
+
"color",
|
|
293
|
+
"backgroundColor",
|
|
294
|
+
"backgroundImage",
|
|
295
|
+
"borderRadius",
|
|
296
|
+
"boxShadow",
|
|
297
|
+
"borderWidth",
|
|
298
|
+
"borderStyle",
|
|
299
|
+
"borderColor",
|
|
300
|
+
"opacity",
|
|
301
|
+
"transform",
|
|
302
|
+
"filter",
|
|
303
|
+
"backdropFilter",
|
|
304
|
+
"objectFit"
|
|
305
|
+
];
|
|
306
|
+
STYLE_DEFAULTS = /* @__PURE__ */ new Set([
|
|
307
|
+
"block",
|
|
308
|
+
"inline",
|
|
309
|
+
"none",
|
|
310
|
+
"normal",
|
|
311
|
+
"auto",
|
|
312
|
+
"0px",
|
|
313
|
+
"transparent",
|
|
314
|
+
"rgba(0, 0, 0, 0)",
|
|
315
|
+
"start",
|
|
316
|
+
"visible",
|
|
317
|
+
"static",
|
|
318
|
+
"row",
|
|
319
|
+
"stretch",
|
|
320
|
+
"0px 0px 0px 0px",
|
|
321
|
+
"baseline"
|
|
322
|
+
]);
|
|
323
|
+
KEEP_ATTRS = ["type", "href", "src", "alt", "role", "aria-label", "placeholder", "name", "id", "data-testid"];
|
|
324
|
+
Z_OVERLAY = 2147483640;
|
|
325
|
+
Z_TOOLBAR = 2147483641;
|
|
326
|
+
OWN_IDS = ["__rune-grab-overlay__", "__rune-grab-label__", "__rune-grab-toolbar__", "__rune-grab-menu__", "__rune-grab-selection__"];
|
|
327
|
+
DRAG_THRESHOLD_PX = 4;
|
|
328
|
+
HELPER_PORT2 = 19274;
|
|
329
|
+
HEALTH_CHECK_TIMEOUT_MS = 800;
|
|
330
|
+
FLASH_VISIBLE_MS = 1e3;
|
|
331
|
+
FLASH_REMOVE_MS = 1200;
|
|
332
|
+
LS_KEY = "__rune-grab-autopaste__";
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
// src/ui/styles.ts
|
|
337
|
+
var FONT, MONO, M_BG, M_FG, M_FG_DIM, M_BORDER, M_HOVER, M_ACTIVE_BG, M_ACTIVE_FG, ICON_SS, ICON_REF, ICON_X, ICON_CHEVRON_RIGHT, ICON_CHEVRON_LEFT, ICON_SEND, ICON_GRIP, TARGET_LABELS, TARGETS_CLIPBOARD, TARGETS_APPS;
|
|
338
|
+
var init_styles = __esm({
|
|
339
|
+
"src/ui/styles.ts"() {
|
|
340
|
+
"use strict";
|
|
341
|
+
FONT = `-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif`;
|
|
342
|
+
MONO = `ui-monospace,SFMono-Regular,Menlo,monospace`;
|
|
343
|
+
M_BG = "#f5f5f5";
|
|
344
|
+
M_FG = "#171717";
|
|
345
|
+
M_FG_DIM = "#737373";
|
|
346
|
+
M_BORDER = "#e5e5e5";
|
|
347
|
+
M_HOVER = "#ebebeb";
|
|
348
|
+
M_ACTIVE_BG = "#171717";
|
|
349
|
+
M_ACTIVE_FG = "#f5f5f5";
|
|
350
|
+
ICON_SS = `<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>`;
|
|
351
|
+
ICON_REF = `<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>`;
|
|
352
|
+
ICON_X = `<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>`;
|
|
353
|
+
ICON_CHEVRON_RIGHT = `<svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"/></svg>`;
|
|
354
|
+
ICON_CHEVRON_LEFT = `<svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg>`;
|
|
355
|
+
ICON_SEND = '<svg width="10" height="10" viewBox="0 0 448 512" fill="currentColor"><path d="M34.9 289.5l-22.2-22.2c-9.4-9.4-9.4-24.6 0-33.9L207 39c9.4-9.4 24.6-9.4 33.9 0l194.3 194.3c9.4 9.4 9.4 24.6 0 33.9L413 289.4c-9.5 9.5-25 9.3-34.3-.4L264.5 168.6V456c0 13.3-10.7 24-24 24h-32c-13.3 0-24-10.7-24-24V168.6L70.2 289.1c-9.3 9.8-24.8 10-34.3.4z"/></svg>';
|
|
356
|
+
ICON_GRIP = `<svg width="6" height="10" viewBox="0 0 6 10" fill="currentColor"><circle cx="1" cy="1" r="1"/><circle cx="5" cy="1" r="1"/><circle cx="1" cy="5" r="1"/><circle cx="5" cy="5" r="1"/><circle cx="1" cy="9" r="1"/><circle cx="5" cy="9" r="1"/></svg>`;
|
|
357
|
+
TARGET_LABELS = {
|
|
358
|
+
clipboard: "Clipboard",
|
|
359
|
+
claude: "Claude",
|
|
360
|
+
cursor: "Cursor",
|
|
361
|
+
codex: "Codex",
|
|
362
|
+
"claude-code": "CLI"
|
|
363
|
+
};
|
|
364
|
+
TARGETS_CLIPBOARD = ["clipboard"];
|
|
365
|
+
TARGETS_APPS = ["claude", "cursor", "codex", "claude-code"];
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
// src/ui/menu.ts
|
|
370
|
+
function setMenuCallbacks(activate2, deactivate2) {
|
|
371
|
+
_activate = activate2;
|
|
372
|
+
_deactivate = deactivate2;
|
|
373
|
+
}
|
|
374
|
+
function loadAutoPastePref() {
|
|
375
|
+
try {
|
|
376
|
+
return localStorage.getItem(LS_KEY) === "1";
|
|
377
|
+
} catch {
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
function saveAutoPastePref(v) {
|
|
382
|
+
try {
|
|
383
|
+
localStorage.setItem(LS_KEY, v ? "1" : "0");
|
|
384
|
+
} catch {
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
async function checkHelper() {
|
|
388
|
+
try {
|
|
389
|
+
const ac = new AbortController();
|
|
390
|
+
const timer = setTimeout(() => ac.abort(), HEALTH_CHECK_TIMEOUT_MS);
|
|
391
|
+
const res = await fetch(`http://127.0.0.1:${HELPER_PORT2}/health`, {
|
|
392
|
+
signal: ac.signal
|
|
393
|
+
});
|
|
394
|
+
clearTimeout(timer);
|
|
395
|
+
return res.ok;
|
|
396
|
+
} catch {
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
async function onAutoPasteToggle(enabled) {
|
|
401
|
+
s.autoPasteEnabled = enabled;
|
|
402
|
+
saveAutoPastePref(enabled);
|
|
403
|
+
if (enabled) {
|
|
404
|
+
s.helperChecking = true;
|
|
405
|
+
renderMiniMenu();
|
|
406
|
+
s.helperAvailable = await checkHelper();
|
|
407
|
+
s.helperChecking = false;
|
|
408
|
+
if (!s.helperAvailable) {
|
|
409
|
+
s.config.target = "clipboard";
|
|
410
|
+
}
|
|
411
|
+
} else {
|
|
412
|
+
s.helperAvailable = false;
|
|
413
|
+
s.config.target = "clipboard";
|
|
414
|
+
}
|
|
415
|
+
renderMiniMenu();
|
|
416
|
+
}
|
|
417
|
+
function buildToggle(on, onChange) {
|
|
418
|
+
const wrap = document.createElement("div");
|
|
419
|
+
wrap.style.cssText = `display:inline-flex;align-items:center;flex-shrink:0;`;
|
|
420
|
+
const track = document.createElement("div");
|
|
421
|
+
track.style.cssText = `
|
|
422
|
+
width:28px;height:16px;border-radius:8px;cursor:pointer;
|
|
423
|
+
transition:background 0.15s;position:relative;
|
|
424
|
+
background:${on ? M_ACTIVE_BG : "#d4d4d4"};
|
|
425
|
+
`;
|
|
426
|
+
const thumb = document.createElement("div");
|
|
427
|
+
thumb.style.cssText = `
|
|
428
|
+
width:12px;height:12px;border-radius:50%;
|
|
429
|
+
background:${on ? M_ACTIVE_FG : "#fff"};
|
|
430
|
+
position:absolute;top:2px;transition:left 0.15s;
|
|
431
|
+
left:${on ? "14px" : "2px"};
|
|
432
|
+
box-shadow:0 1px 2px rgba(0,0,0,0.15);
|
|
433
|
+
`;
|
|
434
|
+
track.appendChild(thumb);
|
|
435
|
+
track.addEventListener("click", (e) => {
|
|
436
|
+
e.stopPropagation();
|
|
437
|
+
onChange(!on);
|
|
438
|
+
});
|
|
439
|
+
wrap.appendChild(track);
|
|
440
|
+
return wrap;
|
|
441
|
+
}
|
|
442
|
+
function grabIconBtn(icon, isActive2, onClick) {
|
|
443
|
+
const btn = document.createElement("button");
|
|
444
|
+
btn.innerHTML = icon;
|
|
445
|
+
btn.style.cssText = `
|
|
446
|
+
width:28px;height:28px;border:none;border-radius:6px;cursor:pointer;
|
|
447
|
+
display:flex;align-items:center;justify-content:center;padding:0;
|
|
448
|
+
transition:all 0.15s;
|
|
449
|
+
background:${isActive2 ? M_ACTIVE_BG : "transparent"};
|
|
450
|
+
color:${isActive2 ? M_ACTIVE_FG : M_FG_DIM};
|
|
451
|
+
`;
|
|
452
|
+
btn.addEventListener("mouseenter", () => {
|
|
453
|
+
if (!isActive2) {
|
|
454
|
+
btn.style.background = M_HOVER;
|
|
455
|
+
btn.style.color = M_FG;
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
btn.addEventListener("mouseleave", () => {
|
|
459
|
+
if (!isActive2) {
|
|
460
|
+
btn.style.background = "transparent";
|
|
461
|
+
btn.style.color = M_FG_DIM;
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
btn.addEventListener("click", (e) => {
|
|
465
|
+
e.stopPropagation();
|
|
466
|
+
e.preventDefault();
|
|
467
|
+
onClick();
|
|
468
|
+
});
|
|
469
|
+
return btn;
|
|
470
|
+
}
|
|
471
|
+
function sep() {
|
|
472
|
+
const d = document.createElement("div");
|
|
473
|
+
d.style.cssText = `width:1px;height:16px;background:${M_BORDER};margin:0 2px;flex-shrink:0;`;
|
|
474
|
+
return d;
|
|
475
|
+
}
|
|
476
|
+
function onGripPointerDown(e) {
|
|
477
|
+
if (e.button !== 0 || !s.menuExpanded || !s.miniMenu) return;
|
|
478
|
+
e.preventDefault();
|
|
479
|
+
const grip = e.currentTarget;
|
|
480
|
+
grip.setPointerCapture(e.pointerId);
|
|
481
|
+
s.dragPointerId = e.pointerId;
|
|
482
|
+
s.dragStartX = e.clientX;
|
|
483
|
+
s.dragStartY = e.clientY;
|
|
484
|
+
s.dragPending = true;
|
|
485
|
+
s.dragging = false;
|
|
486
|
+
const rect = s.miniMenu.getBoundingClientRect();
|
|
487
|
+
s.dragW = rect.width;
|
|
488
|
+
s.dragH = rect.height;
|
|
489
|
+
if (!s.hasDragged) {
|
|
490
|
+
s.miniMenu.style.top = rect.top + "px";
|
|
491
|
+
s.miniMenu.style.left = rect.left + "px";
|
|
492
|
+
s.miniMenu.style.bottom = "auto";
|
|
493
|
+
s.miniMenu.style.right = "auto";
|
|
494
|
+
s.hasDragged = true;
|
|
495
|
+
}
|
|
496
|
+
s.dragBaseX = parseFloat(s.miniMenu.style.left) || rect.left;
|
|
497
|
+
s.dragBaseY = parseFloat(s.miniMenu.style.top) || rect.top;
|
|
498
|
+
s.dragLastX = s.dragBaseX;
|
|
499
|
+
s.dragLastY = s.dragBaseY;
|
|
500
|
+
}
|
|
501
|
+
function onGripPointerMove(e) {
|
|
502
|
+
if (e.pointerId !== s.dragPointerId || !s.miniMenu) return;
|
|
503
|
+
if (!s.dragPending && !s.dragging) return;
|
|
504
|
+
const dx = e.clientX - s.dragStartX;
|
|
505
|
+
const dy = e.clientY - s.dragStartY;
|
|
506
|
+
if (s.dragPending && !s.dragging) {
|
|
507
|
+
if (Math.abs(dx) < DRAG_THRESHOLD_PX && Math.abs(dy) < DRAG_THRESHOLD_PX) return;
|
|
508
|
+
s.dragging = true;
|
|
509
|
+
s.dragPending = false;
|
|
510
|
+
s.miniMenu.style.transition = "none";
|
|
511
|
+
s.miniMenu.style.willChange = "left, top";
|
|
512
|
+
document.body.style.cursor = "grabbing";
|
|
513
|
+
document.body.style.userSelect = "none";
|
|
514
|
+
}
|
|
515
|
+
if (s.dragging) {
|
|
516
|
+
const vw = document.documentElement.clientWidth;
|
|
517
|
+
const vh = document.documentElement.clientHeight;
|
|
518
|
+
s.dragLastX = Math.max(0, Math.min(s.dragBaseX + dx, vw - s.dragW));
|
|
519
|
+
s.dragLastY = Math.max(0, Math.min(s.dragBaseY + dy, vh - s.dragH));
|
|
520
|
+
s.miniMenu.style.left = s.dragLastX + "px";
|
|
521
|
+
s.miniMenu.style.top = s.dragLastY + "px";
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
function onGripPointerUp(e) {
|
|
525
|
+
if (e.pointerId !== s.dragPointerId || !s.miniMenu) return;
|
|
526
|
+
s.dragPointerId = -1;
|
|
527
|
+
document.body.style.cursor = "";
|
|
528
|
+
document.body.style.userSelect = "";
|
|
529
|
+
if (s.dragging) {
|
|
530
|
+
s.dragging = false;
|
|
531
|
+
s.miniMenu.style.willChange = "";
|
|
532
|
+
s.miniMenu.style.transition = "left 0.15s ease, top 0.15s ease";
|
|
533
|
+
s.miniMenu.style.pointerEvents = "none";
|
|
534
|
+
requestAnimationFrame(() => {
|
|
535
|
+
if (s.miniMenu) s.miniMenu.style.pointerEvents = "";
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
s.dragPending = false;
|
|
539
|
+
}
|
|
540
|
+
function snapToNearestEdge() {
|
|
541
|
+
if (!s.miniMenu) return;
|
|
542
|
+
const rect = s.miniMenu.getBoundingClientRect();
|
|
543
|
+
const cx = rect.left + rect.width / 2;
|
|
544
|
+
const cy = rect.top + rect.height / 2;
|
|
545
|
+
const vw = document.documentElement.clientWidth;
|
|
546
|
+
const vh = document.documentElement.clientHeight;
|
|
547
|
+
const distTop = cy;
|
|
548
|
+
const distBottom = vh - cy;
|
|
549
|
+
const distLeft = cx;
|
|
550
|
+
const distRight = vw - cx;
|
|
551
|
+
const minDist = Math.min(distTop, distBottom, distLeft, distRight);
|
|
552
|
+
if (minDist === distTop) s.dockedEdge = "top";
|
|
553
|
+
else if (minDist === distBottom) s.dockedEdge = "bottom";
|
|
554
|
+
else if (minDist === distLeft) s.dockedEdge = "left";
|
|
555
|
+
else s.dockedEdge = "right";
|
|
556
|
+
s.miniMenu.style.transition = "none";
|
|
557
|
+
renderMiniMenu();
|
|
558
|
+
requestAnimationFrame(() => {
|
|
559
|
+
if (!s.miniMenu) return;
|
|
560
|
+
const tabRect = s.miniMenu.getBoundingClientRect();
|
|
561
|
+
const tw = tabRect.width;
|
|
562
|
+
const th = tabRect.height;
|
|
563
|
+
let targetX = parseFloat(s.miniMenu.style.left) || 0;
|
|
564
|
+
let targetY = parseFloat(s.miniMenu.style.top) || 0;
|
|
565
|
+
if (s.dockedEdge === "top") targetY = 0;
|
|
566
|
+
else if (s.dockedEdge === "bottom") targetY = vh - th;
|
|
567
|
+
else if (s.dockedEdge === "left") targetX = 0;
|
|
568
|
+
else if (s.dockedEdge === "right") targetX = vw - tw;
|
|
569
|
+
targetX = Math.max(0, Math.min(targetX, vw - tw));
|
|
570
|
+
targetY = Math.max(0, Math.min(targetY, vh - th));
|
|
571
|
+
s.miniMenu.style.transition = "left 0.25s ease, top 0.25s ease";
|
|
572
|
+
s.miniMenu.style.left = targetX + "px";
|
|
573
|
+
s.miniMenu.style.top = targetY + "px";
|
|
574
|
+
setTimeout(() => {
|
|
575
|
+
if (s.miniMenu) s.miniMenu.style.transition = "left 0.15s ease, top 0.15s ease";
|
|
576
|
+
}, 270);
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
function clampToViewport() {
|
|
580
|
+
if (!s.miniMenu || !s.hasDragged) return;
|
|
581
|
+
const rect = s.miniMenu.getBoundingClientRect();
|
|
582
|
+
let x = rect.left;
|
|
583
|
+
let y = rect.top;
|
|
584
|
+
let clamped = false;
|
|
585
|
+
const vw = document.documentElement.clientWidth;
|
|
586
|
+
const vh = document.documentElement.clientHeight;
|
|
587
|
+
if (x + rect.width > vw) {
|
|
588
|
+
x = vw - rect.width;
|
|
589
|
+
clamped = true;
|
|
590
|
+
}
|
|
591
|
+
if (x < 0) {
|
|
592
|
+
x = 0;
|
|
593
|
+
clamped = true;
|
|
594
|
+
}
|
|
595
|
+
if (y + rect.height > vh) {
|
|
596
|
+
y = vh - rect.height;
|
|
597
|
+
clamped = true;
|
|
598
|
+
}
|
|
599
|
+
if (y < 0) {
|
|
600
|
+
y = 0;
|
|
601
|
+
clamped = true;
|
|
602
|
+
}
|
|
603
|
+
if (clamped) {
|
|
604
|
+
s.miniMenu.style.transition = "left 0.2s ease, top 0.2s ease";
|
|
605
|
+
s.miniMenu.style.left = x + "px";
|
|
606
|
+
s.miniMenu.style.top = y + "px";
|
|
607
|
+
setTimeout(() => {
|
|
608
|
+
if (s.miniMenu) s.miniMenu.style.transition = "left 0.15s ease, top 0.15s ease";
|
|
609
|
+
}, 220);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
function createMiniMenu() {
|
|
613
|
+
s.miniMenu = document.createElement("div");
|
|
614
|
+
s.miniMenu.id = "__rune-grab-menu__";
|
|
615
|
+
s.dockedEdge = "bottom";
|
|
616
|
+
s.menuExpanded = false;
|
|
617
|
+
s.miniMenu.style.cssText = `
|
|
618
|
+
position:fixed;z-index:${Z_TOOLBAR + 2};
|
|
619
|
+
background:transparent;border:none;
|
|
620
|
+
border-radius:9px;font-family:${FONT};
|
|
621
|
+
box-shadow:none;
|
|
622
|
+
transition:left 0.15s ease, top 0.15s ease;
|
|
623
|
+
user-select:none;
|
|
624
|
+
bottom:0px;right:16px;
|
|
625
|
+
`;
|
|
626
|
+
document.addEventListener("mousemove", (e) => {
|
|
627
|
+
s.lastMouseX = e.clientX;
|
|
628
|
+
s.lastMouseY = e.clientY;
|
|
629
|
+
}, { passive: true });
|
|
630
|
+
document.body.appendChild(s.miniMenu);
|
|
631
|
+
renderMiniMenu();
|
|
632
|
+
}
|
|
633
|
+
function renderMiniMenu() {
|
|
634
|
+
if (!s.miniMenu) return;
|
|
635
|
+
const frag = document.createDocumentFragment();
|
|
636
|
+
if (!s.menuExpanded) {
|
|
637
|
+
s.miniMenu.style.padding = "0";
|
|
638
|
+
s.miniMenu.style.border = "none";
|
|
639
|
+
s.miniMenu.style.boxShadow = "none";
|
|
640
|
+
s.miniMenu.style.background = "transparent";
|
|
641
|
+
let chevronSvg;
|
|
642
|
+
let tabW;
|
|
643
|
+
let tabH;
|
|
644
|
+
let borderRadius;
|
|
645
|
+
const edge = s.dockedEdge || "bottom";
|
|
646
|
+
if (edge === "bottom") {
|
|
647
|
+
chevronSvg = `<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="${M_FG}" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="18 15 12 9 6 15"/></svg>`;
|
|
648
|
+
tabW = 40;
|
|
649
|
+
tabH = 28;
|
|
650
|
+
borderRadius = "10px 10px 0 0";
|
|
651
|
+
} else if (edge === "top") {
|
|
652
|
+
chevronSvg = `<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="${M_FG}" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg>`;
|
|
653
|
+
tabW = 40;
|
|
654
|
+
tabH = 28;
|
|
655
|
+
borderRadius = "0 0 10px 10px";
|
|
656
|
+
} else if (edge === "left") {
|
|
657
|
+
chevronSvg = `<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="${M_FG}" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"/></svg>`;
|
|
658
|
+
tabW = 28;
|
|
659
|
+
tabH = 40;
|
|
660
|
+
borderRadius = "0 10px 10px 0";
|
|
661
|
+
} else {
|
|
662
|
+
chevronSvg = `<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="${M_FG}" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg>`;
|
|
663
|
+
tabW = 28;
|
|
664
|
+
tabH = 40;
|
|
665
|
+
borderRadius = "10px 0 0 10px";
|
|
666
|
+
}
|
|
667
|
+
const tab = document.createElement("button");
|
|
668
|
+
tab.title = "Rune Grab";
|
|
669
|
+
tab.innerHTML = chevronSvg;
|
|
670
|
+
tab.style.cssText = `
|
|
671
|
+
width:${tabW}px;height:${tabH}px;border:none;cursor:pointer;
|
|
672
|
+
display:flex;align-items:center;justify-content:center;
|
|
673
|
+
background:${M_BG};color:${M_FG};
|
|
674
|
+
border-radius:${borderRadius};
|
|
675
|
+
box-shadow:0 2px 8px rgba(0,0,0,0.08),0 0 0 1px rgba(0,0,0,0.04);
|
|
676
|
+
transition:background 0.12s;padding:0;
|
|
677
|
+
`;
|
|
678
|
+
tab.addEventListener("mouseenter", () => {
|
|
679
|
+
tab.style.background = M_HOVER;
|
|
680
|
+
});
|
|
681
|
+
tab.addEventListener("mouseleave", () => {
|
|
682
|
+
tab.style.background = M_BG;
|
|
683
|
+
});
|
|
684
|
+
tab.addEventListener("click", (e) => {
|
|
685
|
+
e.stopPropagation();
|
|
686
|
+
if (!s.miniMenu) return;
|
|
687
|
+
const rect = s.miniMenu.getBoundingClientRect();
|
|
688
|
+
s.miniMenu.style.bottom = "auto";
|
|
689
|
+
s.miniMenu.style.right = "auto";
|
|
690
|
+
s.miniMenu.style.top = rect.top + "px";
|
|
691
|
+
s.miniMenu.style.left = rect.left + "px";
|
|
692
|
+
s.hasDragged = true;
|
|
693
|
+
s.menuExpanded = true;
|
|
694
|
+
s.dockedEdge = null;
|
|
695
|
+
s.miniMenu.style.background = M_BG;
|
|
696
|
+
s.miniMenu.style.border = `1px solid ${M_BORDER}`;
|
|
697
|
+
s.miniMenu.style.boxShadow = "0 2px 8px rgba(0,0,0,0.08),0 0 0 1px rgba(0,0,0,0.04)";
|
|
698
|
+
s.miniMenu.style.borderRadius = "9px";
|
|
699
|
+
s.miniMenu.style.transition = "none";
|
|
700
|
+
renderMiniMenu();
|
|
701
|
+
s.miniMenu.offsetWidth;
|
|
702
|
+
clampToViewport();
|
|
703
|
+
});
|
|
704
|
+
frag.appendChild(tab);
|
|
705
|
+
s.miniMenu.textContent = "";
|
|
706
|
+
s.miniMenu.appendChild(frag);
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
s.miniMenu.style.padding = "3px";
|
|
710
|
+
const bar = document.createElement("div");
|
|
711
|
+
bar.style.cssText = "display:flex;align-items:center;gap:2px;";
|
|
712
|
+
const grip = document.createElement("div");
|
|
713
|
+
grip.style.cssText = `
|
|
714
|
+
width:12px;height:28px;cursor:grab;display:flex;align-items:center;justify-content:center;
|
|
715
|
+
flex-shrink:0;border-radius:4px;color:${M_FG_DIM};transition:color 0.12s;
|
|
716
|
+
`;
|
|
717
|
+
grip.innerHTML = ICON_GRIP;
|
|
718
|
+
grip.addEventListener("mouseenter", () => {
|
|
719
|
+
grip.style.color = M_FG;
|
|
720
|
+
});
|
|
721
|
+
grip.addEventListener("mouseleave", () => {
|
|
722
|
+
if (!s.dragging) grip.style.color = M_FG_DIM;
|
|
723
|
+
});
|
|
724
|
+
grip.addEventListener("pointerdown", onGripPointerDown);
|
|
725
|
+
grip.addEventListener("pointermove", onGripPointerMove);
|
|
726
|
+
grip.addEventListener("pointerup", onGripPointerUp);
|
|
727
|
+
grip.style.touchAction = "none";
|
|
728
|
+
bar.appendChild(grip);
|
|
729
|
+
const ssActive = s.active && s.grabType === "screenshot";
|
|
730
|
+
bar.appendChild(grabIconBtn(ICON_SS, ssActive, () => {
|
|
731
|
+
if (ssActive) {
|
|
732
|
+
_deactivate();
|
|
733
|
+
} else {
|
|
734
|
+
if (s.active) _deactivate();
|
|
735
|
+
s.grabType = "screenshot";
|
|
736
|
+
_activate();
|
|
737
|
+
}
|
|
738
|
+
renderMiniMenu();
|
|
739
|
+
}));
|
|
740
|
+
const refActive = s.active && s.grabType === "reference";
|
|
741
|
+
bar.appendChild(grabIconBtn(ICON_REF, refActive, () => {
|
|
742
|
+
if (refActive) {
|
|
743
|
+
_deactivate();
|
|
744
|
+
} else {
|
|
745
|
+
if (s.active) _deactivate();
|
|
746
|
+
s.grabType = "reference";
|
|
747
|
+
_activate();
|
|
748
|
+
}
|
|
749
|
+
renderMiniMenu();
|
|
750
|
+
}));
|
|
751
|
+
bar.appendChild(sep());
|
|
752
|
+
const visibleTargets = s.autoPasteEnabled && s.helperAvailable ? [...TARGETS_CLIPBOARD, ...TARGETS_APPS] : TARGETS_CLIPBOARD;
|
|
753
|
+
const toggleBtn = document.createElement("button");
|
|
754
|
+
toggleBtn.innerHTML = s.targetsExpanded ? ICON_CHEVRON_RIGHT : ICON_CHEVRON_LEFT;
|
|
755
|
+
toggleBtn.title = s.targetsExpanded ? "Collapse targets" : "Send to\u2026";
|
|
756
|
+
toggleBtn.style.cssText = `
|
|
757
|
+
width:24px;height:28px;border:none;background:transparent;cursor:pointer;
|
|
758
|
+
display:flex;align-items:center;justify-content:center;border-radius:6px;
|
|
759
|
+
color:${M_FG_DIM};transition:all 0.12s;padding:0;flex-shrink:0;
|
|
760
|
+
`;
|
|
761
|
+
toggleBtn.addEventListener("mouseenter", () => {
|
|
762
|
+
toggleBtn.style.background = M_HOVER;
|
|
763
|
+
toggleBtn.style.color = M_FG;
|
|
764
|
+
});
|
|
765
|
+
toggleBtn.addEventListener("mouseleave", () => {
|
|
766
|
+
toggleBtn.style.background = "transparent";
|
|
767
|
+
toggleBtn.style.color = M_FG_DIM;
|
|
768
|
+
});
|
|
769
|
+
toggleBtn.addEventListener("click", (e) => {
|
|
770
|
+
e.stopPropagation();
|
|
771
|
+
s.targetsExpanded = !s.targetsExpanded;
|
|
772
|
+
if (targetsWrap) {
|
|
773
|
+
if (s.targetsExpanded) {
|
|
774
|
+
targetsWrap.style.width = "auto";
|
|
775
|
+
const naturalW = targetsWrap.scrollWidth;
|
|
776
|
+
targetsWrap.style.width = "0px";
|
|
777
|
+
targetsWrap.offsetWidth;
|
|
778
|
+
targetsWrap.style.width = naturalW + "px";
|
|
779
|
+
targetsWrap.style.opacity = "1";
|
|
780
|
+
setTimeout(() => {
|
|
781
|
+
if (targetsWrap) targetsWrap.style.width = "auto";
|
|
782
|
+
clampToViewport();
|
|
783
|
+
}, 200);
|
|
784
|
+
} else {
|
|
785
|
+
const currentW = targetsWrap.scrollWidth;
|
|
786
|
+
targetsWrap.style.width = currentW + "px";
|
|
787
|
+
targetsWrap.offsetWidth;
|
|
788
|
+
targetsWrap.style.width = "0px";
|
|
789
|
+
targetsWrap.style.opacity = "0";
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
toggleBtn.innerHTML = s.targetsExpanded ? ICON_CHEVRON_RIGHT : ICON_CHEVRON_LEFT;
|
|
793
|
+
toggleBtn.title = s.targetsExpanded ? "Collapse targets" : "Send to\u2026";
|
|
794
|
+
});
|
|
795
|
+
bar.appendChild(toggleBtn);
|
|
796
|
+
const targetsWrap = document.createElement("div");
|
|
797
|
+
targetsWrap.style.cssText = `
|
|
798
|
+
display:flex;align-items:center;gap:2px;
|
|
799
|
+
overflow:hidden;white-space:nowrap;
|
|
800
|
+
transition:width 0.2s ease, opacity 0.15s ease;
|
|
801
|
+
${s.targetsExpanded ? "opacity:1;" : "width:0px;opacity:0;"}
|
|
802
|
+
`;
|
|
803
|
+
for (const t of visibleTargets) {
|
|
804
|
+
const isCurrent = t === s.config.target;
|
|
805
|
+
const btn = document.createElement("button");
|
|
806
|
+
btn.textContent = TARGET_LABELS[t];
|
|
807
|
+
btn.style.cssText = `
|
|
808
|
+
height:28px;padding:0 8px;border:none;border-radius:6px;cursor:pointer;
|
|
809
|
+
font-size:11px;font-weight:${isCurrent ? "600" : "500"};font-family:${FONT};
|
|
810
|
+
transition:all 0.12s;flex-shrink:0;
|
|
811
|
+
background:${isCurrent ? M_ACTIVE_BG : "transparent"};
|
|
812
|
+
color:${isCurrent ? M_ACTIVE_FG : M_FG_DIM};
|
|
813
|
+
`;
|
|
814
|
+
btn.addEventListener("mouseenter", () => {
|
|
815
|
+
if (!isCurrent) btn.style.background = M_HOVER;
|
|
816
|
+
});
|
|
817
|
+
btn.addEventListener("mouseleave", () => {
|
|
818
|
+
if (!isCurrent) btn.style.background = "transparent";
|
|
819
|
+
});
|
|
820
|
+
btn.addEventListener("click", (e) => {
|
|
821
|
+
e.stopPropagation();
|
|
822
|
+
s.config.target = t;
|
|
823
|
+
renderMiniMenu();
|
|
824
|
+
});
|
|
825
|
+
targetsWrap.appendChild(btn);
|
|
826
|
+
}
|
|
827
|
+
bar.appendChild(targetsWrap);
|
|
828
|
+
if (s.targetsExpanded) bar.appendChild(sep());
|
|
829
|
+
bar.appendChild(buildToggle(s.autoPasteEnabled, onAutoPasteToggle));
|
|
830
|
+
if (s.autoPasteEnabled && !s.helperAvailable && !s.helperChecking) {
|
|
831
|
+
bar.appendChild(sep());
|
|
832
|
+
const hint = document.createElement("div");
|
|
833
|
+
hint.style.cssText = `
|
|
834
|
+
font-size:8px;font-family:${MONO};color:${M_FG_DIM};
|
|
835
|
+
padding:0 6px;white-space:nowrap;flex-shrink:0;line-height:1.3;
|
|
836
|
+
`;
|
|
837
|
+
hint.innerHTML = `To enable auto pasting: add <br><span style="color:${M_FG};font-weight:600;">rune-grab serve</span> to your dev script.`;
|
|
838
|
+
bar.appendChild(hint);
|
|
839
|
+
}
|
|
840
|
+
if (s.helperChecking) {
|
|
841
|
+
bar.appendChild(sep());
|
|
842
|
+
const checking = document.createElement("span");
|
|
843
|
+
checking.textContent = "Connecting\u2026";
|
|
844
|
+
checking.style.cssText = `font-size:10px;font-family:${FONT};color:${M_FG_DIM};padding:0 4px;flex-shrink:0;`;
|
|
845
|
+
bar.appendChild(checking);
|
|
846
|
+
}
|
|
847
|
+
const closeBtn = document.createElement("button");
|
|
848
|
+
closeBtn.innerHTML = ICON_X;
|
|
849
|
+
closeBtn.style.cssText = `
|
|
850
|
+
width:28px;height:28px;border:none;background:transparent;cursor:pointer;
|
|
851
|
+
display:flex;align-items:center;justify-content:center;border-radius:6px;
|
|
852
|
+
color:${M_FG_DIM};transition:all 0.12s;padding:0;
|
|
853
|
+
`;
|
|
854
|
+
closeBtn.addEventListener("mouseenter", () => {
|
|
855
|
+
closeBtn.style.background = M_HOVER;
|
|
856
|
+
closeBtn.style.color = M_FG;
|
|
857
|
+
});
|
|
858
|
+
closeBtn.addEventListener("mouseleave", () => {
|
|
859
|
+
closeBtn.style.background = "transparent";
|
|
860
|
+
closeBtn.style.color = M_FG_DIM;
|
|
861
|
+
});
|
|
862
|
+
closeBtn.addEventListener("click", (e) => {
|
|
863
|
+
e.stopPropagation();
|
|
864
|
+
s.menuExpanded = false;
|
|
865
|
+
if (!s.hasDragged && s.miniMenu) {
|
|
866
|
+
const r = s.miniMenu.getBoundingClientRect();
|
|
867
|
+
s.miniMenu.style.top = r.top + "px";
|
|
868
|
+
s.miniMenu.style.left = r.left + "px";
|
|
869
|
+
s.miniMenu.style.bottom = "auto";
|
|
870
|
+
s.miniMenu.style.right = "auto";
|
|
871
|
+
s.hasDragged = true;
|
|
872
|
+
}
|
|
873
|
+
snapToNearestEdge();
|
|
874
|
+
});
|
|
875
|
+
bar.appendChild(closeBtn);
|
|
876
|
+
frag.appendChild(bar);
|
|
877
|
+
s.miniMenu.textContent = "";
|
|
878
|
+
s.miniMenu.appendChild(frag);
|
|
879
|
+
}
|
|
880
|
+
var _activate, _deactivate;
|
|
881
|
+
var init_menu = __esm({
|
|
882
|
+
"src/ui/menu.ts"() {
|
|
883
|
+
"use strict";
|
|
884
|
+
init_constants();
|
|
885
|
+
init_state();
|
|
886
|
+
init_styles();
|
|
887
|
+
}
|
|
888
|
+
});
|
|
889
|
+
|
|
890
|
+
// src/core/frameworks.ts
|
|
891
|
+
function isUsefulName(name, filePath, customSkip) {
|
|
892
|
+
if (!name || name.length <= 1) return false;
|
|
893
|
+
if (customSkip?.has(name)) return false;
|
|
894
|
+
if (name[0] !== name[0].toUpperCase()) return false;
|
|
895
|
+
for (const pfx of SKIP_PREFIXES) {
|
|
896
|
+
if (name.startsWith(pfx)) return false;
|
|
897
|
+
}
|
|
898
|
+
if (/^[A-Z][a-zA-Z]+\d+$/.test(name)) return false;
|
|
899
|
+
if (filePath && !isSourceFile(filePath)) return false;
|
|
900
|
+
return true;
|
|
901
|
+
}
|
|
902
|
+
function getReactFiber(el) {
|
|
903
|
+
const keys = Object.keys(el);
|
|
904
|
+
for (const key of keys) {
|
|
905
|
+
if (key.startsWith("__reactFiber$") || key.startsWith("__reactInternalInstance$")) {
|
|
906
|
+
return el[key];
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
return null;
|
|
910
|
+
}
|
|
911
|
+
function getReactComponentInfo(el, customSkip) {
|
|
912
|
+
const fiber = getReactFiber(el);
|
|
913
|
+
if (!fiber) return null;
|
|
914
|
+
let cur = fiber;
|
|
915
|
+
while (cur) {
|
|
916
|
+
if (cur.type && typeof cur.type === "function") {
|
|
917
|
+
const name = cur.type.displayName || cur.type.name;
|
|
918
|
+
const src = cur._debugSource;
|
|
919
|
+
const filePath = src?.fileName ?? null;
|
|
920
|
+
if (name && isUsefulName(name, filePath, customSkip)) {
|
|
921
|
+
return {
|
|
922
|
+
name,
|
|
923
|
+
filePath,
|
|
924
|
+
line: src?.lineNumber ?? null,
|
|
925
|
+
column: src?.columnNumber ?? null
|
|
926
|
+
};
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
if (cur.type?.$$typeof) {
|
|
930
|
+
const inner = cur.type.render || cur.type.type;
|
|
931
|
+
if (inner && typeof inner === "function") {
|
|
932
|
+
const name = inner.displayName || inner.name;
|
|
933
|
+
const src = cur._debugSource;
|
|
934
|
+
const filePath = src?.fileName ?? null;
|
|
935
|
+
if (name && isUsefulName(name, filePath, customSkip)) {
|
|
936
|
+
return {
|
|
937
|
+
name,
|
|
938
|
+
filePath,
|
|
939
|
+
line: src?.lineNumber ?? null,
|
|
940
|
+
column: src?.columnNumber ?? null
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
cur = cur.return;
|
|
946
|
+
}
|
|
947
|
+
return null;
|
|
948
|
+
}
|
|
949
|
+
function getReactComponentStack(el, maxDepth = 6, customSkip) {
|
|
950
|
+
const fiber = getReactFiber(el);
|
|
951
|
+
if (!fiber) return [];
|
|
952
|
+
const stack = [];
|
|
953
|
+
const seen = /* @__PURE__ */ new Set();
|
|
954
|
+
let cur = fiber;
|
|
955
|
+
while (cur && stack.length < maxDepth) {
|
|
956
|
+
let name = null;
|
|
957
|
+
let src = null;
|
|
958
|
+
if (cur.type && typeof cur.type === "function") {
|
|
959
|
+
name = cur.type.displayName || cur.type.name;
|
|
960
|
+
src = cur._debugSource;
|
|
961
|
+
} else if (cur.type?.$$typeof) {
|
|
962
|
+
const inner = cur.type.render || cur.type.type;
|
|
963
|
+
if (inner && typeof inner === "function") {
|
|
964
|
+
name = inner.displayName || inner.name;
|
|
965
|
+
src = cur._debugSource;
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
let filePath = src?.fileName ?? null;
|
|
969
|
+
if (name && isUsefulName(name, filePath, customSkip) && !seen.has(name)) {
|
|
970
|
+
seen.add(name);
|
|
971
|
+
const line = src?.lineNumber ?? null;
|
|
972
|
+
if (filePath) {
|
|
973
|
+
filePath = filePath.replace(/^(webpack-internal:\/\/\/|\/app\/)/, "").replace(/^\.\//, "");
|
|
974
|
+
}
|
|
975
|
+
stack.push({ name, filePath, line });
|
|
976
|
+
}
|
|
977
|
+
cur = cur.return;
|
|
978
|
+
}
|
|
979
|
+
return stack;
|
|
980
|
+
}
|
|
981
|
+
function getVueComponentInfo(el) {
|
|
982
|
+
const vueInstance = el.__vueParentComponent;
|
|
983
|
+
if (vueInstance) {
|
|
984
|
+
const name = vueInstance.type?.name || vueInstance.type?.__name;
|
|
985
|
+
if (name) {
|
|
986
|
+
const file = vueInstance.type?.__file ?? null;
|
|
987
|
+
return { name, filePath: file, line: null, column: null };
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
const vue2 = el.__vue__;
|
|
991
|
+
if (vue2) {
|
|
992
|
+
const name = vue2.$options?.name || vue2.$options?._componentTag;
|
|
993
|
+
if (name) {
|
|
994
|
+
const file = vue2.$options?.__file ?? null;
|
|
995
|
+
return { name, filePath: file, line: null, column: null };
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
return null;
|
|
999
|
+
}
|
|
1000
|
+
function getSvelteComponentInfo(el) {
|
|
1001
|
+
const meta = el.__svelte_meta;
|
|
1002
|
+
if (meta?.loc) {
|
|
1003
|
+
const file = meta.loc.file;
|
|
1004
|
+
const name = file ? file.split("/").pop()?.replace(/\.svelte$/, "") : null;
|
|
1005
|
+
if (name) {
|
|
1006
|
+
return { name, filePath: file, line: meta.loc.line ?? null, column: meta.loc.column ?? null };
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
const keys = Object.keys(el);
|
|
1010
|
+
for (const key of keys) {
|
|
1011
|
+
if (key.startsWith("__svelte")) {
|
|
1012
|
+
return { name: "SvelteComponent", filePath: null, line: null, column: null };
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
return null;
|
|
1016
|
+
}
|
|
1017
|
+
function detectComponent(el, customSkip) {
|
|
1018
|
+
return getReactComponentInfo(el, customSkip) || getVueComponentInfo(el) || getSvelteComponentInfo(el) || null;
|
|
1019
|
+
}
|
|
1020
|
+
function detectComponentStack(el, maxDepth = 6, customSkip) {
|
|
1021
|
+
const reactStack = getReactComponentStack(el, maxDepth, customSkip);
|
|
1022
|
+
if (reactStack.length > 0) return reactStack;
|
|
1023
|
+
const info = getVueComponentInfo(el) || getSvelteComponentInfo(el);
|
|
1024
|
+
if (info) {
|
|
1025
|
+
return [{ name: info.name, filePath: info.filePath, line: info.line }];
|
|
1026
|
+
}
|
|
1027
|
+
return [];
|
|
1028
|
+
}
|
|
1029
|
+
var init_frameworks = __esm({
|
|
1030
|
+
"src/core/frameworks.ts"() {
|
|
1031
|
+
"use strict";
|
|
1032
|
+
init_constants();
|
|
1033
|
+
}
|
|
1034
|
+
});
|
|
1035
|
+
|
|
1036
|
+
// src/core/extract.ts
|
|
1037
|
+
function isLocalhost() {
|
|
1038
|
+
const h = location.hostname;
|
|
1039
|
+
return h === "localhost" || h === "127.0.0.1" || h === "0.0.0.0" || h.endsWith(".local");
|
|
1040
|
+
}
|
|
1041
|
+
function getVisibleText(el) {
|
|
1042
|
+
let text = "";
|
|
1043
|
+
function walk(node) {
|
|
1044
|
+
if (node.nodeType === 3) {
|
|
1045
|
+
const t = (node.textContent || "").trim();
|
|
1046
|
+
if (t) text += (text ? " " : "") + t;
|
|
1047
|
+
} else if (node.nodeType === 1) {
|
|
1048
|
+
for (let i = 0; i < node.childNodes.length; i++) walk(node.childNodes[i]);
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
walk(el);
|
|
1052
|
+
if (!text) {
|
|
1053
|
+
text = el.getAttribute("value") || el.getAttribute("alt") || el.getAttribute("aria-label") || el.placeholder || "";
|
|
1054
|
+
}
|
|
1055
|
+
if (text.length > 80) text = text.slice(0, 80) + "...";
|
|
1056
|
+
return text;
|
|
1057
|
+
}
|
|
1058
|
+
function getTagDisplay(el) {
|
|
1059
|
+
let tag = el.tagName.toLowerCase();
|
|
1060
|
+
if (el.id) tag += "#" + el.id;
|
|
1061
|
+
const cls = Array.from(el.classList).filter((c) => !c.startsWith("__rune-grab")).slice(0, 3);
|
|
1062
|
+
if (cls.length) tag += "." + cls.join(".");
|
|
1063
|
+
return tag;
|
|
1064
|
+
}
|
|
1065
|
+
function getKeyStyles(el) {
|
|
1066
|
+
const cs = window.getComputedStyle(el);
|
|
1067
|
+
const out = [];
|
|
1068
|
+
for (const prop of STYLE_PROPS) {
|
|
1069
|
+
const cssProp = prop.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
|
|
1070
|
+
const v = cs.getPropertyValue(cssProp);
|
|
1071
|
+
if (!v || STYLE_DEFAULTS.has(v)) continue;
|
|
1072
|
+
if (prop === "fontSize" && v === "16px") continue;
|
|
1073
|
+
if (prop === "fontWeight" && (v === "400" || v === "normal")) continue;
|
|
1074
|
+
if (prop === "color" && v === "rgb(0, 0, 0)") continue;
|
|
1075
|
+
if (prop === "lineHeight" && v === "normal") continue;
|
|
1076
|
+
if (prop === "letterSpacing" && v === "normal") continue;
|
|
1077
|
+
if (prop === "textAlign" && v === "start") continue;
|
|
1078
|
+
if (prop === "opacity" && v === "1") continue;
|
|
1079
|
+
if (prop === "borderWidth" && v === "0px") continue;
|
|
1080
|
+
if ((prop === "padding" || prop === "margin") && (v === "0px" || /^0px(\s+0px)*$/.test(v))) continue;
|
|
1081
|
+
if (prop === "fontFamily") {
|
|
1082
|
+
const first = v.split(",")[0].trim().replace(/^["']+|["']+$/g, "");
|
|
1083
|
+
if (!first || ["system-ui", "sans-serif", "serif", "monospace", "-apple-system"].includes(first)) continue;
|
|
1084
|
+
out.push("fontFamily: " + first);
|
|
1085
|
+
continue;
|
|
1086
|
+
}
|
|
1087
|
+
out.push(prop + ": " + v);
|
|
1088
|
+
}
|
|
1089
|
+
return out.join("; ");
|
|
1090
|
+
}
|
|
1091
|
+
function cleanHTML(el) {
|
|
1092
|
+
const tag = el.tagName.toLowerCase();
|
|
1093
|
+
const attrs = [];
|
|
1094
|
+
for (const attr of KEEP_ATTRS) {
|
|
1095
|
+
const v = el.getAttribute(attr);
|
|
1096
|
+
if (v) attrs.push(`${attr}="${v}"`);
|
|
1097
|
+
}
|
|
1098
|
+
const cls = Array.from(el.classList).filter((c) => !/^(css-|chakra-|__rune)/.test(c));
|
|
1099
|
+
if (cls.length) attrs.push(`class="${cls.join(" ")}"`);
|
|
1100
|
+
const open = `<${tag}${attrs.length ? " " + attrs.join(" ") : ""}>`;
|
|
1101
|
+
const close = `</${tag}>`;
|
|
1102
|
+
let text = "";
|
|
1103
|
+
el.childNodes.forEach((n) => {
|
|
1104
|
+
if (n.nodeType === 3) text += (n.textContent || "").trim();
|
|
1105
|
+
});
|
|
1106
|
+
const childCount = el.children.length;
|
|
1107
|
+
let inner = text;
|
|
1108
|
+
if (childCount > 0) {
|
|
1109
|
+
inner = (text ? text + " " : "") + `[${childCount} child element${childCount > 1 ? "s" : ""}]`;
|
|
1110
|
+
}
|
|
1111
|
+
if (inner.length > 200) inner = inner.slice(0, 200) + "...";
|
|
1112
|
+
return open + inner + close;
|
|
1113
|
+
}
|
|
1114
|
+
function extractElementMeta(el, customSkip) {
|
|
1115
|
+
const local = isLocalhost();
|
|
1116
|
+
const component = detectComponent(el, customSkip);
|
|
1117
|
+
const tag = getTagDisplay(el);
|
|
1118
|
+
const visibleText = getVisibleText(el);
|
|
1119
|
+
const html = cleanHTML(el);
|
|
1120
|
+
const meta = {
|
|
1121
|
+
tag,
|
|
1122
|
+
visibleText,
|
|
1123
|
+
html,
|
|
1124
|
+
attrs: {
|
|
1125
|
+
role: el.getAttribute("role") || void 0,
|
|
1126
|
+
ariaLabel: el.getAttribute("aria-label") || void 0,
|
|
1127
|
+
alt: el.getAttribute("alt") || void 0,
|
|
1128
|
+
placeholder: el.placeholder || void 0,
|
|
1129
|
+
type: el.getAttribute("type") || void 0,
|
|
1130
|
+
href: el.getAttribute("href") || void 0,
|
|
1131
|
+
id: el.id || void 0,
|
|
1132
|
+
testId: el.getAttribute("data-testid") || void 0
|
|
1133
|
+
},
|
|
1134
|
+
component: component || void 0,
|
|
1135
|
+
isLocal: local
|
|
1136
|
+
};
|
|
1137
|
+
if (local) {
|
|
1138
|
+
meta.componentStack = detectComponentStack(el, 3, customSkip);
|
|
1139
|
+
} else {
|
|
1140
|
+
meta.styles = getKeyStyles(el);
|
|
1141
|
+
}
|
|
1142
|
+
return meta;
|
|
1143
|
+
}
|
|
1144
|
+
function buildLabel(meta) {
|
|
1145
|
+
const textPart = meta.visibleText ? `"${meta.visibleText.slice(0, 30)}"` : "";
|
|
1146
|
+
const tagPart = meta.tag.split(".")[0].split("#")[0];
|
|
1147
|
+
let elType = tagPart;
|
|
1148
|
+
if (tagPart === "button" || meta.attrs.role === "button") elType = "button";
|
|
1149
|
+
else if (tagPart === "a") elType = "link";
|
|
1150
|
+
else if (tagPart === "input") elType = `${meta.attrs.type || "text"} input`;
|
|
1151
|
+
else if (tagPart === "img") elType = "image";
|
|
1152
|
+
else if (tagPart === "textarea") elType = "textarea";
|
|
1153
|
+
let label = textPart ? `${textPart} ${elType}` : elType;
|
|
1154
|
+
if (meta.component?.filePath) {
|
|
1155
|
+
const parts = meta.component.filePath.split("/");
|
|
1156
|
+
const file = parts[parts.length - 1];
|
|
1157
|
+
label += ` in ${file}`;
|
|
1158
|
+
if (meta.component.line) label += `:${meta.component.line}`;
|
|
1159
|
+
} else if (meta.component?.name) {
|
|
1160
|
+
label += ` in <${meta.component.name}>`;
|
|
1161
|
+
}
|
|
1162
|
+
if (label.length > 80) label = label.slice(0, 77) + "...";
|
|
1163
|
+
return label;
|
|
1164
|
+
}
|
|
1165
|
+
function buildContextText(meta, prompt) {
|
|
1166
|
+
const parts = [];
|
|
1167
|
+
if (prompt) parts.push(prompt);
|
|
1168
|
+
if (meta.isLocal && meta.componentStack?.length) {
|
|
1169
|
+
for (const frame of meta.componentStack) {
|
|
1170
|
+
let line = frame.name;
|
|
1171
|
+
if (frame.filePath) {
|
|
1172
|
+
line += ` at ${frame.filePath}`;
|
|
1173
|
+
if (frame.line) line += `:${frame.line}`;
|
|
1174
|
+
}
|
|
1175
|
+
parts.push(line);
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
parts.push(`Element: ${meta.html}`);
|
|
1179
|
+
if (meta.visibleText) parts.push(`Text: "${meta.visibleText}"`);
|
|
1180
|
+
const attrs = Object.entries(meta.attrs).filter(([, v]) => v).map(([k, v]) => `${k}="${v}"`).join(" ");
|
|
1181
|
+
if (attrs) parts.push(`Attributes: ${attrs}`);
|
|
1182
|
+
if (meta.styles) parts.push(`Styles: ${meta.styles}`);
|
|
1183
|
+
return parts.join("\n");
|
|
1184
|
+
}
|
|
1185
|
+
var init_extract = __esm({
|
|
1186
|
+
"src/core/extract.ts"() {
|
|
1187
|
+
"use strict";
|
|
1188
|
+
init_constants();
|
|
1189
|
+
init_frameworks();
|
|
1190
|
+
}
|
|
1191
|
+
});
|
|
1192
|
+
|
|
1193
|
+
// src/ui/overlay.ts
|
|
1194
|
+
function isOwnElement(el) {
|
|
1195
|
+
if (!el) return false;
|
|
1196
|
+
let cur = el;
|
|
1197
|
+
while (cur) {
|
|
1198
|
+
if (cur.id && OWN_IDS.includes(cur.id)) return true;
|
|
1199
|
+
cur = cur.parentElement;
|
|
1200
|
+
}
|
|
1201
|
+
return false;
|
|
1202
|
+
}
|
|
1203
|
+
function getToolbarBase() {
|
|
1204
|
+
return `position:fixed;z-index:${Z_TOOLBAR};background:${M_BG};border:1px solid ${M_BORDER};border-radius:9px;box-shadow:0 2px 8px rgba(0,0,0,0.08),0 0 0 1px rgba(0,0,0,0.04);display:none;flex-direction:row;align-items:center;top:0;left:0;font-family:${FONT};`;
|
|
1205
|
+
}
|
|
1206
|
+
function createGrabOverlay() {
|
|
1207
|
+
if (s.overlay) return;
|
|
1208
|
+
s.overlay = document.createElement("div");
|
|
1209
|
+
s.overlay.id = "__rune-grab-overlay__";
|
|
1210
|
+
s.overlay.style.cssText = `position:fixed;pointer-events:none;z-index:${Z_OVERLAY};border:1px dashed ${M_BG};background:transparent;border-radius:3px;transition:all 0.08s ease-out;display:none;top:0;left:0;width:0;height:0;`;
|
|
1211
|
+
s.label = document.createElement("div");
|
|
1212
|
+
s.label.id = "__rune-grab-label__";
|
|
1213
|
+
s.label.style.cssText = `position:fixed;pointer-events:none;z-index:${Z_TOOLBAR};background:${M_BG};border:1px solid ${M_BORDER};color:${M_FG};font-size:10px;font-family:${MONO};padding:2px 6px;border-radius:5px;white-space:nowrap;display:none;top:0;left:0;line-height:1.4;font-weight:500;letter-spacing:0.01em;box-shadow:0 2px 8px rgba(0,0,0,0.08);`;
|
|
1214
|
+
s.toolbar = document.createElement("div");
|
|
1215
|
+
s.toolbar.id = "__rune-grab-toolbar__";
|
|
1216
|
+
s.toolbar.style.cssText = getToolbarBase() + "padding:4px;gap:2px;";
|
|
1217
|
+
s.cursorStyle = document.createElement("style");
|
|
1218
|
+
s.cursorStyle.id = "__rune-grab-cursor__";
|
|
1219
|
+
s.cursorStyle.textContent = ".__rune-grab-active__ *{cursor:crosshair !important;}.__rune-grab-active__{cursor:crosshair !important;}";
|
|
1220
|
+
document.head.appendChild(s.cursorStyle);
|
|
1221
|
+
document.body.appendChild(s.overlay);
|
|
1222
|
+
document.body.appendChild(s.label);
|
|
1223
|
+
document.body.appendChild(s.toolbar);
|
|
1224
|
+
}
|
|
1225
|
+
function removeGrabOverlay() {
|
|
1226
|
+
s.overlay?.remove();
|
|
1227
|
+
s.label?.remove();
|
|
1228
|
+
s.toolbar?.remove();
|
|
1229
|
+
s.cursorStyle?.remove();
|
|
1230
|
+
s.overlay = null;
|
|
1231
|
+
s.label = null;
|
|
1232
|
+
s.toolbar = null;
|
|
1233
|
+
s.cursorStyle = null;
|
|
1234
|
+
}
|
|
1235
|
+
function createSelectionBox() {
|
|
1236
|
+
if (s.selectionBox) return;
|
|
1237
|
+
s.selectionBox = document.createElement("div");
|
|
1238
|
+
s.selectionBox.id = "__rune-grab-selection__";
|
|
1239
|
+
s.selectionBox.style.cssText = `
|
|
1240
|
+
position:fixed;z-index:${Z_OVERLAY};
|
|
1241
|
+
border:1px dashed ${M_BG};
|
|
1242
|
+
background:transparent;
|
|
1243
|
+
border-radius:2px;display:none;
|
|
1244
|
+
pointer-events:none;
|
|
1245
|
+
top:0;left:0;width:0;height:0;
|
|
1246
|
+
`;
|
|
1247
|
+
document.body.appendChild(s.selectionBox);
|
|
1248
|
+
}
|
|
1249
|
+
function removeSelectionBox() {
|
|
1250
|
+
s.selectionBox?.remove();
|
|
1251
|
+
s.selectionBox = null;
|
|
1252
|
+
}
|
|
1253
|
+
function doHighlight(el) {
|
|
1254
|
+
if (!s.overlay || !s.label) return;
|
|
1255
|
+
const r = el.getBoundingClientRect();
|
|
1256
|
+
s.overlay.style.top = r.top + "px";
|
|
1257
|
+
s.overlay.style.left = r.left + "px";
|
|
1258
|
+
s.overlay.style.width = r.width + "px";
|
|
1259
|
+
s.overlay.style.height = r.height + "px";
|
|
1260
|
+
s.overlay.style.display = "block";
|
|
1261
|
+
const meta = extractElementMeta(el, s.customSkipSet);
|
|
1262
|
+
let displayName;
|
|
1263
|
+
if (isLocalhost() && meta.component) {
|
|
1264
|
+
displayName = meta.component.name;
|
|
1265
|
+
if (meta.component.filePath) {
|
|
1266
|
+
const parts = meta.component.filePath.split("/");
|
|
1267
|
+
displayName += ` \xB7 ${parts[parts.length - 1]}`;
|
|
1268
|
+
if (meta.component.line) displayName += `:${meta.component.line}`;
|
|
1269
|
+
}
|
|
1270
|
+
} else {
|
|
1271
|
+
displayName = meta.component ? `<${meta.component.name}>` : `<${meta.tag}>`;
|
|
1272
|
+
}
|
|
1273
|
+
s.label.textContent = displayName;
|
|
1274
|
+
s.label.style.display = "block";
|
|
1275
|
+
let lt = r.top - 22;
|
|
1276
|
+
if (lt < 4) lt = r.bottom + 4;
|
|
1277
|
+
s.label.style.top = lt + "px";
|
|
1278
|
+
s.label.style.left = r.left + "px";
|
|
1279
|
+
}
|
|
1280
|
+
function hideHighlight() {
|
|
1281
|
+
if (s.overlay) s.overlay.style.display = "none";
|
|
1282
|
+
if (s.label) s.label.style.display = "none";
|
|
1283
|
+
}
|
|
1284
|
+
function hideToolbar() {
|
|
1285
|
+
if (s.toolbar) s.toolbar.style.display = "none";
|
|
1286
|
+
}
|
|
1287
|
+
function flash(msg) {
|
|
1288
|
+
if (!document.body) return;
|
|
1289
|
+
const f = document.createElement("div");
|
|
1290
|
+
f.textContent = msg;
|
|
1291
|
+
let x = s.lastMouseX + 12;
|
|
1292
|
+
let y = s.lastMouseY - 30;
|
|
1293
|
+
if (x + 150 > window.innerWidth) x = s.lastMouseX - 150;
|
|
1294
|
+
if (y < 4) y = s.lastMouseY + 16;
|
|
1295
|
+
f.style.cssText = `position:fixed;z-index:${Z_TOOLBAR + 3};top:${y}px;left:${x}px;background:${M_BG};color:${M_FG};font-size:11px;font-family:${FONT};padding:5px 12px;border-radius:7px;font-weight:500;pointer-events:none;opacity:1;transition:opacity 0.3s ease-out;box-shadow:0 2px 8px rgba(0,0,0,0.08),0 0 0 1px rgba(0,0,0,0.04);border:1px solid ${M_BORDER};`;
|
|
1296
|
+
document.body.appendChild(f);
|
|
1297
|
+
setTimeout(() => f.style.opacity = "0", FLASH_VISIBLE_MS);
|
|
1298
|
+
setTimeout(() => f.remove(), FLASH_REMOVE_MS);
|
|
1299
|
+
}
|
|
1300
|
+
function showPromptInput(onSubmit) {
|
|
1301
|
+
if (!s.toolbar) return;
|
|
1302
|
+
s.promptMode = true;
|
|
1303
|
+
const prevTop = s.toolbar.style.top;
|
|
1304
|
+
const prevLeft = s.toolbar.style.left;
|
|
1305
|
+
s.toolbar.innerHTML = "";
|
|
1306
|
+
s.toolbar.style.cssText = getToolbarBase() + "padding:3px 4px 3px 10px;gap:6px;";
|
|
1307
|
+
s.toolbar.style.top = prevTop;
|
|
1308
|
+
s.toolbar.style.left = prevLeft;
|
|
1309
|
+
const input = document.createElement("input");
|
|
1310
|
+
input.type = "text";
|
|
1311
|
+
input.placeholder = "Comment (Enter \u21B5 send, Esc cancel)";
|
|
1312
|
+
input.style.cssText = `background:transparent;border:none;outline:none;color:${M_FG};font-size:12px;font-family:${FONT};width:230px;padding:2px 0;caret-color:${M_FG};`;
|
|
1313
|
+
const sendBtn = document.createElement("button");
|
|
1314
|
+
sendBtn.innerHTML = ICON_SEND;
|
|
1315
|
+
sendBtn.style.cssText = `width:22px;height:22px;border:1px solid ${M_BORDER};background:${M_ACTIVE_BG};color:${M_ACTIVE_FG};border-radius:50%;cursor:pointer;display:flex;align-items:center;justify-content:center;flex-shrink:0;transition:all 0.15s;`;
|
|
1316
|
+
function submit() {
|
|
1317
|
+
let prompt = input.value.trim();
|
|
1318
|
+
if (prompt && !prompt.endsWith(":")) prompt += ":";
|
|
1319
|
+
s.promptMode = false;
|
|
1320
|
+
onSubmit(prompt);
|
|
1321
|
+
}
|
|
1322
|
+
function cancel() {
|
|
1323
|
+
s.promptMode = false;
|
|
1324
|
+
s.locked = false;
|
|
1325
|
+
hideToolbar();
|
|
1326
|
+
hideHighlight();
|
|
1327
|
+
s.selectedElement = null;
|
|
1328
|
+
}
|
|
1329
|
+
sendBtn.addEventListener("click", (e) => {
|
|
1330
|
+
e.stopPropagation();
|
|
1331
|
+
e.preventDefault();
|
|
1332
|
+
submit();
|
|
1333
|
+
});
|
|
1334
|
+
input.addEventListener("keydown", (e) => {
|
|
1335
|
+
e.stopPropagation();
|
|
1336
|
+
if (e.key === "Enter") {
|
|
1337
|
+
e.preventDefault();
|
|
1338
|
+
submit();
|
|
1339
|
+
}
|
|
1340
|
+
if (e.key === "Escape") {
|
|
1341
|
+
e.preventDefault();
|
|
1342
|
+
cancel();
|
|
1343
|
+
}
|
|
1344
|
+
});
|
|
1345
|
+
input.addEventListener("click", (e) => e.stopPropagation());
|
|
1346
|
+
s.toolbar.appendChild(input);
|
|
1347
|
+
s.toolbar.appendChild(sendBtn);
|
|
1348
|
+
const tw = 270;
|
|
1349
|
+
const curLeft = parseFloat(s.toolbar.style.left);
|
|
1350
|
+
if (curLeft + tw > window.innerWidth - 8) {
|
|
1351
|
+
s.toolbar.style.left = Math.max(8, window.innerWidth - tw - 8) + "px";
|
|
1352
|
+
}
|
|
1353
|
+
s.toolbar.style.display = "flex";
|
|
1354
|
+
setTimeout(() => input.focus(), 0);
|
|
1355
|
+
}
|
|
1356
|
+
var init_overlay = __esm({
|
|
1357
|
+
"src/ui/overlay.ts"() {
|
|
1358
|
+
"use strict";
|
|
1359
|
+
init_constants();
|
|
1360
|
+
init_extract();
|
|
1361
|
+
init_extract();
|
|
1362
|
+
init_state();
|
|
1363
|
+
init_styles();
|
|
1364
|
+
}
|
|
1365
|
+
});
|
|
1366
|
+
|
|
1367
|
+
// src/handlers/keyboard.ts
|
|
1368
|
+
function parseShortcut(shortcut) {
|
|
1369
|
+
const parts = shortcut.split("+");
|
|
1370
|
+
return {
|
|
1371
|
+
key: parts[parts.length - 1].toLowerCase(),
|
|
1372
|
+
meta: parts.some((p) => /^(meta|cmd)$/i.test(p)),
|
|
1373
|
+
ctrl: parts.some((p) => /^(ctrl|control)$/i.test(p)),
|
|
1374
|
+
shift: parts.some((p) => /^shift$/i.test(p)),
|
|
1375
|
+
alt: parts.some((p) => /^(alt|option)$/i.test(p))
|
|
1376
|
+
};
|
|
1377
|
+
}
|
|
1378
|
+
function setKeyboardCallbacks(toggle2, renderMiniMenu2) {
|
|
1379
|
+
_toggle = toggle2;
|
|
1380
|
+
_renderMiniMenu = renderMiniMenu2;
|
|
1381
|
+
}
|
|
1382
|
+
function onShortcut(e) {
|
|
1383
|
+
const sc = parseShortcut(s.config.shortcut);
|
|
1384
|
+
if (e.key.toLowerCase() === sc.key && e.metaKey === sc.meta && e.ctrlKey === sc.ctrl && e.shiftKey === sc.shift && e.altKey === sc.alt) {
|
|
1385
|
+
e.preventDefault();
|
|
1386
|
+
_toggle();
|
|
1387
|
+
_renderMiniMenu();
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
var _toggle, _renderMiniMenu;
|
|
1391
|
+
var init_keyboard = __esm({
|
|
1392
|
+
"src/handlers/keyboard.ts"() {
|
|
1393
|
+
"use strict";
|
|
1394
|
+
init_state();
|
|
1395
|
+
}
|
|
1396
|
+
});
|
|
1397
|
+
|
|
1398
|
+
// src/handlers/inspect.ts
|
|
1399
|
+
function setReferenceCallbacks(dispatch, deactivate2, renderMiniMenu2) {
|
|
1400
|
+
_dispatch = dispatch;
|
|
1401
|
+
_deactivate2 = deactivate2;
|
|
1402
|
+
_renderMiniMenu2 = renderMiniMenu2;
|
|
1403
|
+
}
|
|
1404
|
+
async function executeReferenceGrab(el, prompt) {
|
|
1405
|
+
const meta = extractElementMeta(el, s.customSkipSet);
|
|
1406
|
+
const labelText = buildLabel(meta);
|
|
1407
|
+
const contextText = buildContextText(meta, prompt);
|
|
1408
|
+
const result = {
|
|
1409
|
+
type: "reference",
|
|
1410
|
+
label: labelText,
|
|
1411
|
+
text: contextText,
|
|
1412
|
+
prompt,
|
|
1413
|
+
meta
|
|
1414
|
+
};
|
|
1415
|
+
await _dispatch(result);
|
|
1416
|
+
flash(`Sent to ${TARGET_LABELS[s.config.target]}`);
|
|
1417
|
+
s.locked = false;
|
|
1418
|
+
hideToolbar();
|
|
1419
|
+
hideHighlight();
|
|
1420
|
+
s.selectedElement = null;
|
|
1421
|
+
}
|
|
1422
|
+
function showPromptForGrab(el) {
|
|
1423
|
+
if (!s.toolbar) return;
|
|
1424
|
+
const r = el.getBoundingClientRect();
|
|
1425
|
+
const tw = 270;
|
|
1426
|
+
const th = 34;
|
|
1427
|
+
let top = r.bottom + 6;
|
|
1428
|
+
let left = r.left + r.width / 2 - tw / 2;
|
|
1429
|
+
if (top + th > window.innerHeight - 8) top = r.top - th - 6;
|
|
1430
|
+
if (left < 8) left = 8;
|
|
1431
|
+
if (left + tw > window.innerWidth - 8) left = window.innerWidth - tw - 8;
|
|
1432
|
+
s.toolbar.style.top = top + "px";
|
|
1433
|
+
s.toolbar.style.left = left + "px";
|
|
1434
|
+
showPromptInput(async (prompt) => {
|
|
1435
|
+
await executeReferenceGrab(el, prompt);
|
|
1436
|
+
});
|
|
1437
|
+
}
|
|
1438
|
+
function onRefMouseMove(e) {
|
|
1439
|
+
if (s.locked || s.mmRAF) return;
|
|
1440
|
+
s.mmRAF = requestAnimationFrame(() => {
|
|
1441
|
+
s.mmRAF = 0;
|
|
1442
|
+
const el = document.elementFromPoint(e.clientX, e.clientY);
|
|
1443
|
+
if (!el || isOwnElement(el) || el === document.body || el === document.documentElement) {
|
|
1444
|
+
hideHighlight();
|
|
1445
|
+
s.selectedElement = null;
|
|
1446
|
+
return;
|
|
1447
|
+
}
|
|
1448
|
+
s.selectedElement = el;
|
|
1449
|
+
doHighlight(el);
|
|
1450
|
+
});
|
|
1451
|
+
}
|
|
1452
|
+
function onRefClick(e) {
|
|
1453
|
+
if (isOwnElement(e.target)) return;
|
|
1454
|
+
if (s.promptMode) return;
|
|
1455
|
+
e.preventDefault();
|
|
1456
|
+
e.stopPropagation();
|
|
1457
|
+
e.stopImmediatePropagation();
|
|
1458
|
+
if (s.locked) {
|
|
1459
|
+
s.locked = false;
|
|
1460
|
+
hideToolbar();
|
|
1461
|
+
return;
|
|
1462
|
+
}
|
|
1463
|
+
if (s.selectedElement) {
|
|
1464
|
+
s.locked = true;
|
|
1465
|
+
doHighlight(s.selectedElement);
|
|
1466
|
+
showPromptForGrab(s.selectedElement);
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
function onRefKeyDown(e) {
|
|
1470
|
+
if (s.promptMode) return;
|
|
1471
|
+
if (e.key === "Escape") {
|
|
1472
|
+
if (s.locked) {
|
|
1473
|
+
s.locked = false;
|
|
1474
|
+
hideToolbar();
|
|
1475
|
+
s.selectedElement = null;
|
|
1476
|
+
hideHighlight();
|
|
1477
|
+
} else {
|
|
1478
|
+
_deactivate2();
|
|
1479
|
+
_renderMiniMenu2();
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
function onRefScroll() {
|
|
1484
|
+
if (s.promptMode) return;
|
|
1485
|
+
if (s.locked) {
|
|
1486
|
+
s.locked = false;
|
|
1487
|
+
hideToolbar();
|
|
1488
|
+
s.selectedElement = null;
|
|
1489
|
+
hideHighlight();
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
var _dispatch, _deactivate2, _renderMiniMenu2;
|
|
1493
|
+
var init_inspect = __esm({
|
|
1494
|
+
"src/handlers/inspect.ts"() {
|
|
1495
|
+
"use strict";
|
|
1496
|
+
init_extract();
|
|
1497
|
+
init_state();
|
|
1498
|
+
init_overlay();
|
|
1499
|
+
init_styles();
|
|
1500
|
+
}
|
|
1501
|
+
});
|
|
1502
|
+
|
|
1503
|
+
// src/handlers/capture.ts
|
|
1504
|
+
function setScreenshotCallbacks(dispatch, deactivate2, renderMiniMenu2) {
|
|
1505
|
+
_dispatch2 = dispatch;
|
|
1506
|
+
_deactivate3 = deactivate2;
|
|
1507
|
+
_renderMiniMenu3 = renderMiniMenu2;
|
|
1508
|
+
}
|
|
1509
|
+
function onSSMouseDown(e) {
|
|
1510
|
+
if (e.button !== 0) return;
|
|
1511
|
+
if (isOwnElement(e.target)) return;
|
|
1512
|
+
e.preventDefault();
|
|
1513
|
+
e.stopPropagation();
|
|
1514
|
+
s.ssDrawing = true;
|
|
1515
|
+
s.ssStartX = e.clientX;
|
|
1516
|
+
s.ssStartY = e.clientY;
|
|
1517
|
+
if (s.selectionBox) {
|
|
1518
|
+
s.selectionBox.style.left = s.ssStartX + "px";
|
|
1519
|
+
s.selectionBox.style.top = s.ssStartY + "px";
|
|
1520
|
+
s.selectionBox.style.width = "0px";
|
|
1521
|
+
s.selectionBox.style.height = "0px";
|
|
1522
|
+
s.selectionBox.style.display = "block";
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
function onSSMouseMove(e) {
|
|
1526
|
+
if (!s.ssDrawing || !s.selectionBox) return;
|
|
1527
|
+
e.preventDefault();
|
|
1528
|
+
const x = Math.min(e.clientX, s.ssStartX);
|
|
1529
|
+
const y = Math.min(e.clientY, s.ssStartY);
|
|
1530
|
+
const w = Math.abs(e.clientX - s.ssStartX);
|
|
1531
|
+
const h = Math.abs(e.clientY - s.ssStartY);
|
|
1532
|
+
s.selectionBox.style.left = x + "px";
|
|
1533
|
+
s.selectionBox.style.top = y + "px";
|
|
1534
|
+
s.selectionBox.style.width = w + "px";
|
|
1535
|
+
s.selectionBox.style.height = h + "px";
|
|
1536
|
+
}
|
|
1537
|
+
async function onSSMouseUp(e) {
|
|
1538
|
+
if (!s.ssDrawing) return;
|
|
1539
|
+
s.ssDrawing = false;
|
|
1540
|
+
e.preventDefault();
|
|
1541
|
+
e.stopPropagation();
|
|
1542
|
+
const x = Math.min(e.clientX, s.ssStartX);
|
|
1543
|
+
const y = Math.min(e.clientY, s.ssStartY);
|
|
1544
|
+
const w = Math.abs(e.clientX - s.ssStartX);
|
|
1545
|
+
const h = Math.abs(e.clientY - s.ssStartY);
|
|
1546
|
+
const selBox = s.selectionBox;
|
|
1547
|
+
if (selBox) selBox.remove();
|
|
1548
|
+
s.selectionBox = null;
|
|
1549
|
+
if (s.miniMenu) s.miniMenu.style.display = "none";
|
|
1550
|
+
if (s.cursorStyle) s.cursorStyle.disabled = true;
|
|
1551
|
+
await new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)));
|
|
1552
|
+
if (w >= 10 && h >= 10) {
|
|
1553
|
+
const image = await captureRect({ x, y, width: w, height: h });
|
|
1554
|
+
if (s.miniMenu) s.miniMenu.style.display = "";
|
|
1555
|
+
if (s.cursorStyle) s.cursorStyle.disabled = false;
|
|
1556
|
+
createSelectionBox();
|
|
1557
|
+
if (image) {
|
|
1558
|
+
const result = {
|
|
1559
|
+
type: "screenshot",
|
|
1560
|
+
label: `Region ${w}\xD7${h}`,
|
|
1561
|
+
text: `Screenshot region: ${w}\xD7${h} at (${Math.round(x)}, ${Math.round(y)})`,
|
|
1562
|
+
prompt: "",
|
|
1563
|
+
image,
|
|
1564
|
+
meta: { tag: "region", visibleText: "", html: "", attrs: {}, isLocal: isLocalhost() }
|
|
1565
|
+
};
|
|
1566
|
+
await _dispatch2(result);
|
|
1567
|
+
flash("Screenshot captured");
|
|
1568
|
+
}
|
|
1569
|
+
} else {
|
|
1570
|
+
if (s.miniMenu) s.miniMenu.style.display = "";
|
|
1571
|
+
if (s.cursorStyle) s.cursorStyle.disabled = false;
|
|
1572
|
+
createSelectionBox();
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
function onSSKeyDown(e) {
|
|
1576
|
+
if (e.key === "Escape") {
|
|
1577
|
+
if (s.ssDrawing) {
|
|
1578
|
+
s.ssDrawing = false;
|
|
1579
|
+
if (s.selectionBox) s.selectionBox.style.display = "none";
|
|
1580
|
+
} else {
|
|
1581
|
+
_deactivate3();
|
|
1582
|
+
_renderMiniMenu3();
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
var _dispatch2, _deactivate3, _renderMiniMenu3;
|
|
1587
|
+
var init_capture = __esm({
|
|
1588
|
+
"src/handlers/capture.ts"() {
|
|
1589
|
+
"use strict";
|
|
1590
|
+
init_screenshot();
|
|
1591
|
+
init_extract();
|
|
1592
|
+
init_state();
|
|
1593
|
+
init_overlay();
|
|
1594
|
+
}
|
|
1595
|
+
});
|
|
1596
|
+
|
|
1597
|
+
// src/core/engine.ts
|
|
1598
|
+
var engine_exports = {};
|
|
1599
|
+
__export(engine_exports, {
|
|
1600
|
+
activate: () => activate,
|
|
1601
|
+
deactivate: () => deactivate,
|
|
1602
|
+
getTarget: () => getTarget,
|
|
1603
|
+
init: () => init,
|
|
1604
|
+
isActive: () => isActive,
|
|
1605
|
+
setTarget: () => setTarget,
|
|
1606
|
+
toggle: () => toggle
|
|
1607
|
+
});
|
|
1608
|
+
async function dispatchResult(result) {
|
|
1609
|
+
s.config.onGrab(result);
|
|
1610
|
+
window.dispatchEvent(new CustomEvent("rune:grab", { detail: result }));
|
|
1611
|
+
if (s.config.target === "clipboard") {
|
|
1612
|
+
await copyToClipboard(result);
|
|
1613
|
+
} else {
|
|
1614
|
+
await sendToApp(s.config.target, result);
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
function activate() {
|
|
1618
|
+
if (s.active) return;
|
|
1619
|
+
if (!document.body || !document.head) return;
|
|
1620
|
+
s.active = true;
|
|
1621
|
+
document.documentElement.classList.add("__rune-grab-active__");
|
|
1622
|
+
if (s.grabType === "screenshot") {
|
|
1623
|
+
createGrabOverlay();
|
|
1624
|
+
createSelectionBox();
|
|
1625
|
+
document.addEventListener("mousedown", onSSMouseDown, true);
|
|
1626
|
+
document.addEventListener("mousemove", onSSMouseMove, true);
|
|
1627
|
+
document.addEventListener("mouseup", onSSMouseUp, true);
|
|
1628
|
+
document.addEventListener("keydown", onSSKeyDown, true);
|
|
1629
|
+
} else {
|
|
1630
|
+
createGrabOverlay();
|
|
1631
|
+
document.addEventListener("mousemove", onRefMouseMove, true);
|
|
1632
|
+
document.addEventListener("click", onRefClick, true);
|
|
1633
|
+
document.addEventListener("keydown", onRefKeyDown, true);
|
|
1634
|
+
document.addEventListener("scroll", onRefScroll, true);
|
|
1635
|
+
}
|
|
1636
|
+
s.config.onToggle(true);
|
|
1637
|
+
}
|
|
1638
|
+
function deactivate() {
|
|
1639
|
+
if (!s.active) return;
|
|
1640
|
+
s.active = false;
|
|
1641
|
+
s.locked = false;
|
|
1642
|
+
s.promptMode = false;
|
|
1643
|
+
s.ssDrawing = false;
|
|
1644
|
+
s.selectedElement = null;
|
|
1645
|
+
if (s.mmRAF) {
|
|
1646
|
+
cancelAnimationFrame(s.mmRAF);
|
|
1647
|
+
s.mmRAF = 0;
|
|
1648
|
+
}
|
|
1649
|
+
document.removeEventListener("mousedown", onSSMouseDown, true);
|
|
1650
|
+
document.removeEventListener("mousemove", onSSMouseMove, true);
|
|
1651
|
+
document.removeEventListener("mouseup", onSSMouseUp, true);
|
|
1652
|
+
document.removeEventListener("keydown", onSSKeyDown, true);
|
|
1653
|
+
document.removeEventListener("mousemove", onRefMouseMove, true);
|
|
1654
|
+
document.removeEventListener("click", onRefClick, true);
|
|
1655
|
+
document.removeEventListener("keydown", onRefKeyDown, true);
|
|
1656
|
+
document.removeEventListener("scroll", onRefScroll, true);
|
|
1657
|
+
removeGrabOverlay();
|
|
1658
|
+
removeSelectionBox();
|
|
1659
|
+
document.documentElement.classList.remove("__rune-grab-active__");
|
|
1660
|
+
s.config.onToggle(false);
|
|
1661
|
+
}
|
|
1662
|
+
function toggle() {
|
|
1663
|
+
if (s.active) deactivate();
|
|
1664
|
+
else activate();
|
|
1665
|
+
}
|
|
1666
|
+
function isActive() {
|
|
1667
|
+
return s.active;
|
|
1668
|
+
}
|
|
1669
|
+
function setTarget(target) {
|
|
1670
|
+
s.config.target = target;
|
|
1671
|
+
if (s.menuExpanded) renderMiniMenu();
|
|
1672
|
+
}
|
|
1673
|
+
function getTarget() {
|
|
1674
|
+
return s.config.target;
|
|
1675
|
+
}
|
|
1676
|
+
function init(userConfig = {}) {
|
|
1677
|
+
if (s.initialized) return () => {
|
|
1678
|
+
};
|
|
1679
|
+
s.config = { ...DEFAULTS, ...userConfig };
|
|
1680
|
+
s.initialized = true;
|
|
1681
|
+
if (userConfig.skipComponents?.length) {
|
|
1682
|
+
s.customSkipSet = new Set(userConfig.skipComponents);
|
|
1683
|
+
}
|
|
1684
|
+
setMenuCallbacks(activate, deactivate);
|
|
1685
|
+
setKeyboardCallbacks(toggle, renderMiniMenu);
|
|
1686
|
+
setReferenceCallbacks(dispatchResult, deactivate, renderMiniMenu);
|
|
1687
|
+
setScreenshotCallbacks(dispatchResult, deactivate, renderMiniMenu);
|
|
1688
|
+
const savedAutoPaste = loadAutoPastePref();
|
|
1689
|
+
if (savedAutoPaste) {
|
|
1690
|
+
s.autoPasteEnabled = true;
|
|
1691
|
+
checkHelper().then((ok) => {
|
|
1692
|
+
s.helperAvailable = ok;
|
|
1693
|
+
if (!ok) s.config.target = "clipboard";
|
|
1694
|
+
if (s.menuExpanded) renderMiniMenu();
|
|
1695
|
+
});
|
|
1696
|
+
}
|
|
1697
|
+
const setup = () => {
|
|
1698
|
+
createMiniMenu();
|
|
1699
|
+
document.addEventListener("keydown", onShortcut, true);
|
|
1700
|
+
};
|
|
1701
|
+
if (document.readyState === "loading") {
|
|
1702
|
+
document.addEventListener("DOMContentLoaded", setup, { once: true });
|
|
1703
|
+
} else {
|
|
1704
|
+
setup();
|
|
1705
|
+
}
|
|
1706
|
+
return () => {
|
|
1707
|
+
deactivate();
|
|
1708
|
+
releaseStream();
|
|
1709
|
+
s.miniMenu?.remove();
|
|
1710
|
+
document.removeEventListener("keydown", onShortcut, true);
|
|
1711
|
+
s.initialized = false;
|
|
1712
|
+
s.hasDragged = false;
|
|
1713
|
+
};
|
|
1714
|
+
}
|
|
1715
|
+
var init_engine = __esm({
|
|
1716
|
+
"src/core/engine.ts"() {
|
|
1717
|
+
"use strict";
|
|
1718
|
+
init_screenshot();
|
|
1719
|
+
init_app();
|
|
1720
|
+
init_clipboard();
|
|
1721
|
+
init_state();
|
|
1722
|
+
init_menu();
|
|
1723
|
+
init_overlay();
|
|
1724
|
+
init_keyboard();
|
|
1725
|
+
init_inspect();
|
|
1726
|
+
init_capture();
|
|
1727
|
+
}
|
|
1728
|
+
});
|
|
1729
|
+
|
|
1730
|
+
// src/hooks/react.ts
|
|
1731
|
+
import { useEffect, useState, useCallback, useRef } from "react";
|
|
1732
|
+
function useRuneGrab(config = {}) {
|
|
1733
|
+
const [active, setActive] = useState(false);
|
|
1734
|
+
const [target, setTargetState] = useState(config.target ?? "clipboard");
|
|
1735
|
+
const [lastGrab, setLastGrab] = useState(null);
|
|
1736
|
+
const cleanupRef = useRef(null);
|
|
1737
|
+
const engineRef = useRef(null);
|
|
1738
|
+
useEffect(() => {
|
|
1739
|
+
let mounted = true;
|
|
1740
|
+
Promise.resolve().then(() => (init_engine(), engine_exports)).then((engine) => {
|
|
1741
|
+
if (!mounted) return;
|
|
1742
|
+
engineRef.current = engine;
|
|
1743
|
+
cleanupRef.current = engine.init({
|
|
1744
|
+
...config,
|
|
1745
|
+
onGrab: (result) => {
|
|
1746
|
+
setLastGrab(result);
|
|
1747
|
+
config.onGrab?.(result);
|
|
1748
|
+
},
|
|
1749
|
+
onToggle: (isActive2) => {
|
|
1750
|
+
setActive(isActive2);
|
|
1751
|
+
config.onToggle?.(isActive2);
|
|
1752
|
+
}
|
|
1753
|
+
});
|
|
1754
|
+
});
|
|
1755
|
+
return () => {
|
|
1756
|
+
mounted = false;
|
|
1757
|
+
cleanupRef.current?.();
|
|
1758
|
+
};
|
|
1759
|
+
}, []);
|
|
1760
|
+
const toggle2 = useCallback(() => {
|
|
1761
|
+
engineRef.current?.toggle();
|
|
1762
|
+
}, []);
|
|
1763
|
+
const activate2 = useCallback(() => {
|
|
1764
|
+
engineRef.current?.activate();
|
|
1765
|
+
}, []);
|
|
1766
|
+
const deactivate2 = useCallback(() => {
|
|
1767
|
+
engineRef.current?.deactivate();
|
|
1768
|
+
}, []);
|
|
1769
|
+
const setTarget2 = useCallback((t) => {
|
|
1770
|
+
setTargetState(t);
|
|
1771
|
+
engineRef.current?.setTarget(t);
|
|
1772
|
+
}, []);
|
|
1773
|
+
return { active, toggle: toggle2, activate: activate2, deactivate: deactivate2, setTarget: setTarget2, target, lastGrab };
|
|
1774
|
+
}
|
|
1775
|
+
export {
|
|
1776
|
+
useRuneGrab
|
|
1777
|
+
};
|
|
1778
|
+
//# sourceMappingURL=react.js.map
|