agentation-vue 0.2.3 → 0.2.4

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,108 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useMultiSelect = useMultiSelect;
7
- var _vueDemi = require("vue-demi");
8
- var _constants = require("../constants");
9
- const LEAF_TAGS = /* @__PURE__ */new Set(["button", "a", "input", "img"]);
10
- function useMultiSelect(mode, transitionFn) {
11
- const selectionRect = (0, _vueDemi.ref)(null);
12
- const selectedElements = (0, _vueDemi.ref)([]);
13
- let startX = 0;
14
- let startY = 0;
15
- let cachedElements = [];
16
- let rafId = null;
17
- function cacheElements() {
18
- cachedElements = [];
19
- for (const el of document.querySelectorAll("body *")) {
20
- if (el.closest(_constants.VA_DATA_ATTR_SELECTOR)) continue;
21
- const rect = el.getBoundingClientRect();
22
- if (rect.width === 0 || rect.height === 0) continue;
23
- const isLeaf = el.children.length === 0 || LEAF_TAGS.has(el.tagName.toLowerCase());
24
- if (isLeaf) {
25
- cachedElements.push({
26
- el,
27
- rect,
28
- isLeaf
29
- });
30
- }
31
- }
32
- }
33
- function onMouseDown(e) {
34
- if (mode.value !== "inspect" || !e.shiftKey) return false;
35
- e.preventDefault();
36
- document.documentElement.style.userSelect = "none";
37
- startX = e.clientX;
38
- startY = e.clientY;
39
- selectionRect.value = {
40
- x: startX,
41
- y: startY,
42
- width: 0,
43
- height: 0
44
- };
45
- transitionFn("multi-selecting");
46
- cacheElements();
47
- return true;
48
- }
49
- function onMouseMove(e) {
50
- if (mode.value !== "multi-selecting") return;
51
- const x = Math.min(startX, e.clientX);
52
- const y = Math.min(startY, e.clientY);
53
- const width = Math.abs(e.clientX - startX);
54
- const height = Math.abs(e.clientY - startY);
55
- selectionRect.value = {
56
- x,
57
- y,
58
- width,
59
- height
60
- };
61
- if (rafId !== null) return;
62
- rafId = requestAnimationFrame(() => {
63
- rafId = null;
64
- collectIntersectedElements();
65
- });
66
- }
67
- function onMouseUp() {
68
- if (mode.value !== "multi-selecting") return;
69
- document.documentElement.style.userSelect = "";
70
- if (rafId !== null) {
71
- cancelAnimationFrame(rafId);
72
- rafId = null;
73
- }
74
- collectIntersectedElements();
75
- }
76
- function collectIntersectedElements() {
77
- if (!selectionRect.value) return;
78
- const rect = selectionRect.value;
79
- const intersected = [];
80
- for (const {
81
- el,
82
- rect: elRect
83
- } of cachedElements) {
84
- if (elRect.left < rect.x + rect.width && elRect.right > rect.x && elRect.top < rect.y + rect.height && elRect.bottom > rect.y) {
85
- intersected.push(el);
86
- }
87
- }
88
- selectedElements.value = intersected;
89
- }
90
- function reset() {
91
- selectionRect.value = null;
92
- selectedElements.value = [];
93
- cachedElements = [];
94
- document.documentElement.style.userSelect = "";
95
- if (rafId !== null) {
96
- cancelAnimationFrame(rafId);
97
- rafId = null;
98
- }
99
- }
100
- return {
101
- selectionRect,
102
- selectedElements,
103
- onMouseDown,
104
- onMouseMove,
105
- onMouseUp,
106
- reset
107
- };
108
- }
@@ -1,100 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.formatAnnotations = formatAnnotations;
7
- exports.useOutputFormatter = useOutputFormatter;
8
- function formatAnnotations(annotations, detail, pageUrl) {
9
- const shortUrl = pageUrl.replace(/^https?:\/\//, "");
10
- const lines = [];
11
- lines.push(`## Feedback \u2014 ${shortUrl}`);
12
- lines.push("");
13
- if (detail === "forensic") {
14
- const viewport = typeof window !== "undefined" ? `${window.innerWidth}x${window.innerHeight}` : "unknown";
15
- const userAgent = typeof navigator !== "undefined" ? navigator.userAgent : "unknown";
16
- const dpr = typeof window !== "undefined" ? String(window.devicePixelRatio) : "unknown";
17
- lines.push("### Environment");
18
- lines.push(`- **Viewport:** ${viewport}`);
19
- lines.push(`- **URL:** ${pageUrl}`);
20
- lines.push(`- **User Agent:** ${userAgent}`);
21
- lines.push(`- **Timestamp:** ${(/* @__PURE__ */new Date()).toISOString()}`);
22
- lines.push(`- **Device Pixel Ratio:** ${dpr}`);
23
- lines.push("");
24
- }
25
- for (let i = 0; i < annotations.length; i++) {
26
- const ann = annotations[i];
27
- const num = i + 1;
28
- if (ann.selectedText) {
29
- lines.push(`### ${num}. "${ann.selectedText}" (selected text)`);
30
- } else if (ann.isMultiSelect) {
31
- lines.push(`### ${num}. Multi-selection (${ann.elements?.length || 0} elements)`);
32
- } else if (ann.isAreaSelect) {
33
- lines.push(`### ${num}. Area selection`);
34
- } else {
35
- lines.push(`### ${num}. \`${ann.element}\` \u2014 ${ann.elementPath}`);
36
- }
37
- lines.push(`- **Comment:** ${ann.comment}`);
38
- if (ann.selectedText) {
39
- lines.push(`- **In element:** \`${ann.element}\` \u2014 ${ann.elementPath}`);
40
- }
41
- if (ann.isMultiSelect && ann.elements) {
42
- lines.push(`- **Elements:**`);
43
- for (const el of ann.elements) {
44
- lines.push(` - \`${el.element}\` \u2014 ${el.elementPath}`);
45
- }
46
- }
47
- if (ann.isAreaSelect && ann.area) {
48
- lines.push(`- **Area:** x: ${Math.round(ann.area.x)}, y: ${Math.round(ann.area.y)}, width: ${Math.round(ann.area.width)}, height: ${Math.round(ann.area.height)}`);
49
- }
50
- if ((ann.isAreaSelect || ann.isMultiSelect) && ann.elementPath) {
51
- lines.push(`- **Selection path:** ${ann.elementPath}`);
52
- }
53
- if ((ann.isAreaSelect || ann.isMultiSelect) && ann.boundingBox) {
54
- const b = ann.boundingBox;
55
- lines.push(`- **Selection box:** x: ${Math.round(b.x)}, y: ${Math.round(b.y)}, width: ${Math.round(b.width)}, height: ${Math.round(b.height)}`);
56
- }
57
- if (ann.vueComponents) {
58
- lines.push(`- **Components:** ${ann.vueComponents}`);
59
- }
60
- if (!ann.isMultiSelect && !ann.isAreaSelect && !ann.selectedText) {
61
- if (ann.elementPath) {
62
- lines.push(`- **Path:** ${ann.elementPath}`);
63
- }
64
- }
65
- if (ann.nearbyElements) {
66
- lines.push(`- **Nearby:** ${ann.nearbyElements}`);
67
- }
68
- if (ann.nearbyText && !ann.selectedText) {
69
- lines.push(`- **Context:** ${ann.nearbyText}`);
70
- }
71
- if (detail === "forensic") {
72
- if (ann.fullPath) {
73
- lines.push(`- **Full path:** ${ann.fullPath}`);
74
- }
75
- if (ann.cssClasses) {
76
- lines.push(`- **CSS classes:** ${ann.cssClasses}`);
77
- }
78
- if (ann.boundingBox) {
79
- const b = ann.boundingBox;
80
- lines.push(`- **Bounding box:** x: ${Math.round(b.x)}, y: ${Math.round(b.y)}, width: ${Math.round(b.width)}, height: ${Math.round(b.height)}`);
81
- }
82
- if (ann.computedStyles) {
83
- lines.push(`- **Computed styles:**`);
84
- for (const line of ann.computedStyles.split("\n")) {
85
- lines.push(` - ${line}`);
86
- }
87
- }
88
- if (ann.accessibility) {
89
- lines.push(`- **Accessibility:** ${ann.accessibility}`);
90
- }
91
- }
92
- lines.push("");
93
- }
94
- return lines.join("\n");
95
- }
96
- function useOutputFormatter() {
97
- return {
98
- formatAnnotations
99
- };
100
- }
@@ -1,48 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useSettings = useSettings;
7
- var _vueDemi = require("vue-demi");
8
- const STORAGE_KEY = "agentation-vue-settings";
9
- const defaults = {
10
- outputDetail: "standard",
11
- markerColor: "#42B883",
12
- blockPageInteractions: false,
13
- autoHideToolbar: false,
14
- toolbarPlacement: "bottom-right",
15
- clearAfterCopy: false,
16
- showComponentTree: true,
17
- theme: "auto",
18
- activationKey: "Shift"
19
- };
20
- function loadSettings() {
21
- try {
22
- const stored = localStorage.getItem(STORAGE_KEY);
23
- if (stored) return {
24
- ...defaults,
25
- ...JSON.parse(stored)
26
- };
27
- } catch {}
28
- return {
29
- ...defaults
30
- };
31
- }
32
- const settings = (0, _vueDemi.reactive)(loadSettings());
33
- (0, _vueDemi.watch)(() => ({
34
- ...settings
35
- }), val => {
36
- try {
37
- localStorage.setItem(STORAGE_KEY, JSON.stringify(val));
38
- } catch {}
39
- });
40
- function useSettings() {
41
- function resetSettings() {
42
- Object.assign(settings, defaults);
43
- }
44
- return {
45
- settings,
46
- resetSettings
47
- };
48
- }
@@ -1,33 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useTextSelection = useTextSelection;
7
- function useTextSelection(mode) {
8
- function checkTextSelection(e) {
9
- if (mode.value !== "inspect") return null;
10
- if (e.shiftKey || e.altKey) return null;
11
- const selection = window.getSelection();
12
- const selectedText = selection?.toString().trim() ?? "";
13
- if (selectedText.length >= 2 && selection?.rangeCount) {
14
- const range = selection.getRangeAt(0);
15
- const rect = range.getBoundingClientRect();
16
- if (rect.width > 5) {
17
- const anchorElement = range.commonAncestorContainer instanceof Element ? range.commonAncestorContainer : range.commonAncestorContainer.parentElement;
18
- if (anchorElement) {
19
- return {
20
- selectedText,
21
- range,
22
- rect,
23
- anchorElement
24
- };
25
- }
26
- }
27
- }
28
- return null;
29
- }
30
- return {
31
- checkTextSelection
32
- };
33
- }
@@ -1,270 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useToolbarAutoHide = useToolbarAutoHide;
7
- var _vueDemi = require("vue-demi");
8
- const EDGE_OFFSET = 20;
9
- const DEFAULT_TOOLBAR_SIZE = 42;
10
- const ACTIVATION_EDGE_DEPTH = 16;
11
- const ACTIVATION_INLINE_PAD = 30;
12
- const ACTIVATION_CORNER_SIZE = 32;
13
- const KEEP_ALIVE_PADDING = 56;
14
- const HIDE_DELAY_MS = 140;
15
- const ENTER_LOCK_MS = 220;
16
- const CLICK_LOCK_MS = 320;
17
- function useToolbarAutoHide(options) {
18
- const {
19
- enabled,
20
- expanded,
21
- isDragging,
22
- placement,
23
- toolbarEl
24
- } = options;
25
- const isAutoHideRevealed = (0, _vueDemi.ref)(false);
26
- const isAutoHideActive = (0, _vueDemi.computed)(() => enabled.value && !expanded.value && !isDragging.value);
27
- let hideTimer = null;
28
- let revealLockUntil = 0;
29
- let listenersAttached = false;
30
- function clearHideTimer() {
31
- if (!hideTimer) {
32
- return;
33
- }
34
- clearTimeout(hideTimer);
35
- hideTimer = null;
36
- }
37
- function reveal() {
38
- isAutoHideRevealed.value = true;
39
- clearHideTimer();
40
- }
41
- function lockReveal(durationMs) {
42
- revealLockUntil = Math.max(revealLockUntil, Date.now() + durationMs);
43
- reveal();
44
- }
45
- function hideNow() {
46
- clearHideTimer();
47
- revealLockUntil = 0;
48
- isAutoHideRevealed.value = false;
49
- }
50
- function scheduleHide() {
51
- clearHideTimer();
52
- hideTimer = setTimeout(() => {
53
- if (Date.now() < revealLockUntil) {
54
- scheduleHide();
55
- return;
56
- }
57
- isAutoHideRevealed.value = false;
58
- hideTimer = null;
59
- }, HIDE_DELAY_MS);
60
- }
61
- function getToolbarSize() {
62
- const el = toolbarEl.value;
63
- return {
64
- width: el?.offsetWidth ?? DEFAULT_TOOLBAR_SIZE,
65
- height: el?.offsetHeight ?? DEFAULT_TOOLBAR_SIZE
66
- };
67
- }
68
- function getCollapsedRect(anchor, size) {
69
- const left = EDGE_OFFSET;
70
- const top = EDGE_OFFSET;
71
- const right = window.innerWidth - EDGE_OFFSET - size.width;
72
- const bottom = window.innerHeight - EDGE_OFFSET - size.height;
73
- const centerX = (window.innerWidth - size.width) / 2;
74
- switch (anchor) {
75
- case "top-left":
76
- return {
77
- left,
78
- top,
79
- right: left + size.width,
80
- bottom: top + size.height
81
- };
82
- case "top-center":
83
- return {
84
- left: centerX,
85
- top,
86
- right: centerX + size.width,
87
- bottom: top + size.height
88
- };
89
- case "top-right":
90
- return {
91
- left: right,
92
- top,
93
- right: right + size.width,
94
- bottom: top + size.height
95
- };
96
- case "bottom-left":
97
- return {
98
- left,
99
- top: bottom,
100
- right: left + size.width,
101
- bottom: bottom + size.height
102
- };
103
- case "bottom-center":
104
- return {
105
- left: centerX,
106
- top: bottom,
107
- right: centerX + size.width,
108
- bottom: bottom + size.height
109
- };
110
- case "bottom-right":
111
- default:
112
- return {
113
- left: right,
114
- top: bottom,
115
- right: right + size.width,
116
- bottom: bottom + size.height
117
- };
118
- }
119
- }
120
- function getActivationRect(anchor, size) {
121
- const W = window.innerWidth;
122
- const H = window.innerHeight;
123
- const centerX = W / 2;
124
- switch (anchor) {
125
- case "top-left":
126
- return {
127
- left: 0,
128
- top: 0,
129
- right: ACTIVATION_CORNER_SIZE,
130
- bottom: ACTIVATION_CORNER_SIZE
131
- };
132
- case "top-center":
133
- return {
134
- left: centerX - size.width / 2 - ACTIVATION_INLINE_PAD,
135
- top: 0,
136
- right: centerX + size.width / 2 + ACTIVATION_INLINE_PAD,
137
- bottom: ACTIVATION_EDGE_DEPTH
138
- };
139
- case "top-right":
140
- return {
141
- left: W - ACTIVATION_CORNER_SIZE,
142
- top: 0,
143
- right: W,
144
- bottom: ACTIVATION_CORNER_SIZE
145
- };
146
- case "bottom-left":
147
- return {
148
- left: 0,
149
- top: H - ACTIVATION_CORNER_SIZE,
150
- right: ACTIVATION_CORNER_SIZE,
151
- bottom: H
152
- };
153
- case "bottom-center":
154
- return {
155
- left: centerX - size.width / 2 - ACTIVATION_INLINE_PAD,
156
- top: H - ACTIVATION_EDGE_DEPTH,
157
- right: centerX + size.width / 2 + ACTIVATION_INLINE_PAD,
158
- bottom: H
159
- };
160
- case "bottom-right":
161
- default:
162
- return {
163
- left: W - ACTIVATION_CORNER_SIZE,
164
- top: H - ACTIVATION_CORNER_SIZE,
165
- right: W,
166
- bottom: H
167
- };
168
- }
169
- }
170
- function inflateRect(rect, padding) {
171
- return {
172
- left: rect.left - padding,
173
- top: rect.top - padding,
174
- right: rect.right + padding,
175
- bottom: rect.bottom + padding
176
- };
177
- }
178
- function isInside(point, rect) {
179
- return point.x >= rect.left && point.x <= rect.right && point.y >= rect.top && point.y <= rect.bottom;
180
- }
181
- function isInActivationZone(point, anchor, size) {
182
- return isInside(point, getActivationRect(anchor, size));
183
- }
184
- function onGlobalPointerMove(e) {
185
- if (!isAutoHideActive.value) {
186
- return;
187
- }
188
- const size = getToolbarSize();
189
- const point = {
190
- x: e.clientX,
191
- y: e.clientY
192
- };
193
- const keepAliveRect = inflateRect(getCollapsedRect(placement.value, size), KEEP_ALIVE_PADDING);
194
- if (isInActivationZone(point, placement.value, size) || isAutoHideRevealed.value && isInside(point, keepAliveRect)) {
195
- reveal();
196
- return;
197
- }
198
- scheduleHide();
199
- }
200
- function onWindowBlur() {
201
- if (isAutoHideActive.value) {
202
- hideNow();
203
- }
204
- }
205
- function addGlobalListeners() {
206
- if (listenersAttached || typeof window === "undefined") {
207
- return;
208
- }
209
- listenersAttached = true;
210
- window.addEventListener("pointermove", onGlobalPointerMove, true);
211
- window.addEventListener("blur", onWindowBlur);
212
- }
213
- function removeGlobalListeners() {
214
- if (!listenersAttached || typeof window === "undefined") {
215
- return;
216
- }
217
- listenersAttached = false;
218
- window.removeEventListener("pointermove", onGlobalPointerMove, true);
219
- window.removeEventListener("blur", onWindowBlur);
220
- }
221
- function onToolbarPointerEnter() {
222
- if (!isAutoHideActive.value) {
223
- return;
224
- }
225
- lockReveal(ENTER_LOCK_MS);
226
- }
227
- function onToolbarPointerLeave() {}
228
- function onToolbarPointerDown() {
229
- if (!isAutoHideActive.value) {
230
- return;
231
- }
232
- lockReveal(CLICK_LOCK_MS);
233
- }
234
- function onToolbarFocusIn() {
235
- if (!isAutoHideActive.value) {
236
- return;
237
- }
238
- lockReveal(CLICK_LOCK_MS);
239
- }
240
- function onToolbarFocusOut() {
241
- if (!isAutoHideActive.value) {
242
- return;
243
- }
244
- scheduleHide();
245
- }
246
- (0, _vueDemi.watch)(isAutoHideActive, active => {
247
- if (!active) {
248
- removeGlobalListeners();
249
- hideNow();
250
- return;
251
- }
252
- addGlobalListeners();
253
- isAutoHideRevealed.value = false;
254
- }, {
255
- immediate: true
256
- });
257
- (0, _vueDemi.onBeforeUnmount)(() => {
258
- removeGlobalListeners();
259
- clearHideTimer();
260
- });
261
- return {
262
- isAutoHideActive,
263
- isAutoHideRevealed,
264
- onToolbarPointerEnter,
265
- onToolbarPointerLeave,
266
- onToolbarPointerDown,
267
- onToolbarFocusIn,
268
- onToolbarFocusOut
269
- };
270
- }