angular-grab 0.1.0 → 0.1.2
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/README.md +215 -0
- package/examples/angular-19-app/.editorconfig +17 -0
- package/examples/angular-19-app/.vscode/extensions.json +4 -0
- package/examples/angular-19-app/.vscode/launch.json +20 -0
- package/examples/angular-19-app/.vscode/mcp.json +9 -0
- package/examples/angular-19-app/.vscode/tasks.json +42 -0
- package/examples/angular-19-app/README.md +59 -0
- package/examples/angular-19-app/angular.json +74 -0
- package/examples/angular-19-app/package.json +44 -0
- package/examples/angular-19-app/public/favicon.ico +0 -0
- package/examples/angular-19-app/src/app/app.config.ts +13 -0
- package/examples/angular-19-app/src/app/app.css +37 -0
- package/examples/angular-19-app/src/app/app.html +25 -0
- package/examples/angular-19-app/src/app/app.routes.ts +3 -0
- package/examples/angular-19-app/src/app/app.spec.ts +23 -0
- package/examples/angular-19-app/src/app/app.ts +12 -0
- package/examples/angular-19-app/src/app/button/button.component.ts +25 -0
- package/examples/angular-19-app/src/app/card/card.component.ts +33 -0
- package/examples/angular-19-app/src/app/header/header.component.ts +31 -0
- package/examples/angular-19-app/src/app/popover/popover.component.ts +133 -0
- package/examples/angular-19-app/src/index.html +13 -0
- package/examples/angular-19-app/src/main.ts +6 -0
- package/examples/angular-19-app/src/styles.css +1 -0
- package/examples/angular-19-app/tsconfig.app.json +15 -0
- package/examples/angular-19-app/tsconfig.json +33 -0
- package/examples/angular-19-app/tsconfig.spec.json +15 -0
- package/package.json +14 -111
- package/packages/angular-grab/package.json +96 -0
- package/packages/angular-grab/src/angular/__tests__/context-builder.test.ts +216 -0
- package/packages/angular-grab/src/angular/angular-grab.service.ts +62 -0
- package/packages/angular-grab/src/angular/index.ts +13 -0
- package/packages/angular-grab/src/angular/provide-angular-grab.ts +22 -0
- package/packages/angular-grab/src/angular/resolvers/component-resolver.ts +71 -0
- package/packages/angular-grab/src/angular/resolvers/context-builder.ts +86 -0
- package/packages/angular-grab/src/angular/resolvers/ng-utils.ts +14 -0
- package/packages/angular-grab/src/angular/resolvers/source-resolver.ts +61 -0
- package/packages/angular-grab/src/builder/__tests__/builder.test.ts +72 -0
- package/packages/angular-grab/src/builder/builders/application/index.ts +13 -0
- package/packages/angular-grab/src/builder/builders/dev-server/index.ts +9 -0
- package/packages/angular-grab/src/builder/index.ts +3 -0
- package/packages/angular-grab/src/cli/__tests__/cli.test.ts +239 -0
- package/packages/angular-grab/src/cli/commands/init.ts +106 -0
- package/packages/angular-grab/src/cli/index.ts +15 -0
- package/packages/angular-grab/src/cli/utils/detect-project.ts +78 -0
- package/packages/angular-grab/src/cli/utils/modify-angular-json.ts +42 -0
- package/packages/angular-grab/src/cli/utils/modify-app-config.ts +42 -0
- package/packages/angular-grab/src/core/__tests__/generate-snippet.test.ts +149 -0
- package/packages/angular-grab/src/core/__tests__/plugin-registry.test.ts +286 -0
- package/packages/angular-grab/src/core/__tests__/store.test.ts +118 -0
- package/packages/angular-grab/src/core/__tests__/utils.test.ts +85 -0
- package/packages/angular-grab/src/core/clipboard/copy.ts +104 -0
- package/packages/angular-grab/src/core/clipboard/generate-snippet.ts +38 -0
- package/packages/angular-grab/src/core/constants.ts +10 -0
- package/packages/angular-grab/src/core/grab.ts +596 -0
- package/packages/angular-grab/src/core/index.global.ts +13 -0
- package/packages/angular-grab/src/core/index.ts +19 -0
- package/packages/angular-grab/src/core/keyboard/keyboard-handler.ts +163 -0
- package/packages/angular-grab/src/core/overlay/crosshair.ts +107 -0
- package/packages/angular-grab/src/core/overlay/freeze-overlay.ts +239 -0
- package/packages/angular-grab/src/core/overlay/overlay-renderer.ts +180 -0
- package/packages/angular-grab/src/core/overlay/select-feedback.ts +108 -0
- package/packages/angular-grab/src/core/overlay/toast.ts +175 -0
- package/packages/angular-grab/src/core/picker/element-picker.ts +114 -0
- package/packages/angular-grab/src/core/plugins/plugin-registry.ts +83 -0
- package/packages/angular-grab/src/core/store.ts +52 -0
- package/packages/angular-grab/src/core/toolbar/actions-menu.ts +178 -0
- package/packages/angular-grab/src/core/toolbar/comment-popover.ts +235 -0
- package/packages/angular-grab/src/core/toolbar/copy-actions.ts +98 -0
- package/packages/angular-grab/src/core/toolbar/history-popover.ts +245 -0
- package/packages/angular-grab/src/core/toolbar/theme-manager.ts +188 -0
- package/packages/angular-grab/src/core/toolbar/toolbar-icons.ts +29 -0
- package/packages/angular-grab/src/core/toolbar/toolbar-renderer.ts +239 -0
- package/packages/angular-grab/src/core/types.ts +139 -0
- package/packages/angular-grab/src/core/utils.ts +16 -0
- package/packages/angular-grab/src/esbuild-plugin/__tests__/transform.test.ts +174 -0
- package/packages/angular-grab/src/esbuild-plugin/index.ts +3 -0
- package/packages/angular-grab/src/esbuild-plugin/plugin.ts +29 -0
- package/packages/angular-grab/src/esbuild-plugin/scan.ts +105 -0
- package/packages/angular-grab/src/esbuild-plugin/transform.ts +152 -0
- package/packages/angular-grab/src/vite-plugin/__tests__/plugin.test.ts +84 -0
- package/packages/angular-grab/src/vite-plugin/index.ts +19 -0
- package/packages/angular-grab/src/webpack-plugin/__tests__/plugin.test.ts +72 -0
- package/packages/angular-grab/src/webpack-plugin/index.ts +2 -0
- package/packages/angular-grab/src/webpack-plugin/loader.ts +15 -0
- package/packages/angular-grab/src/webpack-plugin/plugin.ts +20 -0
- package/packages/angular-grab/tsconfig.json +15 -0
- package/packages/angular-grab/tsup.config.ts +119 -0
- package/pnpm-workspace.yaml +3 -0
- package/turbo.json +21 -0
- package/dist/angular/index.d.ts +0 -151
- package/dist/angular/index.js +0 -2811
- package/dist/angular/index.js.map +0 -1
- package/dist/builder/builders/application/index.js +0 -143
- package/dist/builder/builders/application/index.js.map +0 -1
- package/dist/builder/builders/dev-server/index.js +0 -139
- package/dist/builder/builders/dev-server/index.js.map +0 -1
- package/dist/builder/index.js +0 -2
- package/dist/builder/index.js.map +0 -1
- package/dist/builder/package.json +0 -1
- package/dist/cli/index.js +0 -223
- package/dist/cli/index.js.map +0 -1
- package/dist/core/index.cjs +0 -2589
- package/dist/core/index.cjs.map +0 -1
- package/dist/core/index.d.cts +0 -139
- package/dist/core/index.d.ts +0 -139
- package/dist/core/index.global.js +0 -542
- package/dist/core/index.js +0 -2560
- package/dist/core/index.js.map +0 -1
- package/dist/esbuild-plugin/index.cjs +0 -239
- package/dist/esbuild-plugin/index.cjs.map +0 -1
- package/dist/esbuild-plugin/index.d.cts +0 -26
- package/dist/esbuild-plugin/index.d.ts +0 -26
- package/dist/esbuild-plugin/index.js +0 -200
- package/dist/esbuild-plugin/index.js.map +0 -1
- package/dist/vite-plugin/index.d.ts +0 -7
- package/dist/vite-plugin/index.js +0 -128
- package/dist/vite-plugin/index.js.map +0 -1
- package/dist/webpack-plugin/index.cjs +0 -54
- package/dist/webpack-plugin/index.cjs.map +0 -1
- package/dist/webpack-plugin/index.d.cts +0 -5
- package/dist/webpack-plugin/index.d.ts +0 -5
- package/dist/webpack-plugin/index.js +0 -23
- package/dist/webpack-plugin/index.js.map +0 -1
- package/dist/webpack-plugin/loader.cjs +0 -155
- package/dist/webpack-plugin/loader.cjs.map +0 -1
- package/dist/webpack-plugin/loader.d.cts +0 -3
- package/dist/webpack-plugin/loader.d.ts +0 -3
- package/dist/webpack-plugin/loader.js +0 -122
- package/dist/webpack-plugin/loader.js.map +0 -1
- /package/{builders.json → packages/angular-grab/builders.json} +0 -0
- /package/{dist → packages/angular-grab/src}/builder/builders/application/schema.json +0 -0
- /package/{dist → packages/angular-grab/src}/builder/builders/dev-server/schema.json +0 -0
package/dist/angular/index.js
DELETED
|
@@ -1,2811 +0,0 @@
|
|
|
1
|
-
// src/angular/resolvers/ng-utils.ts
|
|
2
|
-
function getNgApi() {
|
|
3
|
-
if (typeof window === "undefined") return null;
|
|
4
|
-
return window.ng || null;
|
|
5
|
-
}
|
|
6
|
-
function cleanComponentName(name) {
|
|
7
|
-
return name.startsWith("_") ? name.slice(1) : name;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// src/angular/resolvers/component-resolver.ts
|
|
11
|
-
function resolveComponent(element) {
|
|
12
|
-
const ng = getNgApi();
|
|
13
|
-
if (!ng) return { name: null, hostElement: null, stack: [] };
|
|
14
|
-
const stack = [];
|
|
15
|
-
const seen = /* @__PURE__ */ new Set();
|
|
16
|
-
let current = element;
|
|
17
|
-
while (current) {
|
|
18
|
-
const comp = ng.getComponent(current);
|
|
19
|
-
if (comp && !seen.has(comp)) {
|
|
20
|
-
seen.add(comp);
|
|
21
|
-
stack.push({
|
|
22
|
-
name: cleanComponentName(comp.constructor.name),
|
|
23
|
-
hostElement: current
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
current = current.parentElement;
|
|
27
|
-
}
|
|
28
|
-
if (stack.length === 0) {
|
|
29
|
-
let walk = element;
|
|
30
|
-
while (walk) {
|
|
31
|
-
const owning = ng.getOwningComponent(walk);
|
|
32
|
-
if (owning && !seen.has(owning)) {
|
|
33
|
-
seen.add(owning);
|
|
34
|
-
let host = walk.parentElement;
|
|
35
|
-
while (host) {
|
|
36
|
-
if (ng.getComponent(host) === owning) break;
|
|
37
|
-
host = host.parentElement;
|
|
38
|
-
}
|
|
39
|
-
stack.push({
|
|
40
|
-
name: cleanComponentName(owning.constructor.name),
|
|
41
|
-
hostElement: host ?? walk.parentElement
|
|
42
|
-
});
|
|
43
|
-
current = host?.parentElement ?? walk.parentElement?.parentElement ?? null;
|
|
44
|
-
while (current) {
|
|
45
|
-
const comp = ng.getComponent(current);
|
|
46
|
-
if (comp && !seen.has(comp)) {
|
|
47
|
-
seen.add(comp);
|
|
48
|
-
stack.push({
|
|
49
|
-
name: cleanComponentName(comp.constructor.name),
|
|
50
|
-
hostElement: current
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
current = current.parentElement;
|
|
54
|
-
}
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
walk = walk.parentElement;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
const closest = stack.length > 0 ? stack[0] : { name: null, hostElement: null };
|
|
61
|
-
return {
|
|
62
|
-
name: closest.name,
|
|
63
|
-
hostElement: closest.hostElement,
|
|
64
|
-
stack
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// src/angular/resolvers/source-resolver.ts
|
|
69
|
-
function getSourceMap() {
|
|
70
|
-
return globalThis.__ANGULAR_GRAB_SOURCE_MAP__ ?? null;
|
|
71
|
-
}
|
|
72
|
-
function resolveSource(element) {
|
|
73
|
-
const sourceMap = getSourceMap();
|
|
74
|
-
if (!sourceMap) return { filePath: null, line: null, column: null };
|
|
75
|
-
const ng = getNgApi();
|
|
76
|
-
if (!ng) return { filePath: null, line: null, column: null };
|
|
77
|
-
const componentName = findComponentName(element, ng);
|
|
78
|
-
if (!componentName) return { filePath: null, line: null, column: null };
|
|
79
|
-
const entry = sourceMap[componentName];
|
|
80
|
-
if (!entry) return { filePath: null, line: null, column: null };
|
|
81
|
-
return { filePath: entry.file, line: entry.line, column: null };
|
|
82
|
-
}
|
|
83
|
-
function resolveSourceForComponent(componentName) {
|
|
84
|
-
const sourceMap = getSourceMap();
|
|
85
|
-
if (!sourceMap) return { filePath: null, line: null, column: null };
|
|
86
|
-
const entry = sourceMap[componentName];
|
|
87
|
-
if (!entry) return { filePath: null, line: null, column: null };
|
|
88
|
-
return { filePath: entry.file, line: entry.line, column: null };
|
|
89
|
-
}
|
|
90
|
-
function findComponentName(element, ng) {
|
|
91
|
-
const direct = ng.getComponent(element);
|
|
92
|
-
if (direct) return cleanComponentName(direct.constructor.name);
|
|
93
|
-
let current = element;
|
|
94
|
-
while (current) {
|
|
95
|
-
const owning = ng.getOwningComponent(current);
|
|
96
|
-
if (owning) return cleanComponentName(owning.constructor.name);
|
|
97
|
-
current = current.parentElement;
|
|
98
|
-
}
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// src/core/store.ts
|
|
103
|
-
function createStore(initialOptions) {
|
|
104
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
105
|
-
const raw = {
|
|
106
|
-
active: false,
|
|
107
|
-
frozen: false,
|
|
108
|
-
hoveredElement: null,
|
|
109
|
-
options: initialOptions,
|
|
110
|
-
toolbar: {
|
|
111
|
-
visible: initialOptions.showToolbar,
|
|
112
|
-
themeMode: initialOptions.themeMode,
|
|
113
|
-
history: [],
|
|
114
|
-
pendingAction: null
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
const state = new Proxy(raw, {
|
|
118
|
-
set(target, prop, value) {
|
|
119
|
-
const key = prop;
|
|
120
|
-
if (target[key] === value) return true;
|
|
121
|
-
Reflect.set(target, key, value);
|
|
122
|
-
listeners.forEach((fn) => fn(state, key));
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
return {
|
|
127
|
-
state,
|
|
128
|
-
subscribe(listener) {
|
|
129
|
-
listeners.add(listener);
|
|
130
|
-
return () => listeners.delete(listener);
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// src/core/constants.ts
|
|
136
|
-
var Z_INDEX_FREEZE = 2147483644;
|
|
137
|
-
var Z_INDEX_CROSSHAIR = 2147483645;
|
|
138
|
-
var Z_INDEX_OVERLAY = 2147483646;
|
|
139
|
-
var Z_INDEX_LABEL = 2147483647;
|
|
140
|
-
var Z_INDEX_TOOLBAR = 2147483646;
|
|
141
|
-
var Z_INDEX_TOAST = 2147483647;
|
|
142
|
-
var Z_INDEX_POPOVER = 2147483647;
|
|
143
|
-
var TOOLBAR_TOAST_OFFSET = "72px";
|
|
144
|
-
var TOOLBAR_POPOVER_OFFSET = "68px";
|
|
145
|
-
|
|
146
|
-
// src/core/overlay/overlay-renderer.ts
|
|
147
|
-
var OVERLAY_ID = "__ag-overlay__";
|
|
148
|
-
var LABEL_ID = "__ag-label__";
|
|
149
|
-
var STYLE_ID = "__ag-styles__";
|
|
150
|
-
function createOverlayRenderer() {
|
|
151
|
-
let overlay = null;
|
|
152
|
-
let label = null;
|
|
153
|
-
let rafId = null;
|
|
154
|
-
let currentElement = null;
|
|
155
|
-
let currentComponentName = null;
|
|
156
|
-
let currentSourcePath = null;
|
|
157
|
-
let currentCssClasses = [];
|
|
158
|
-
function injectStyles2() {
|
|
159
|
-
if (document.getElementById(STYLE_ID)) return;
|
|
160
|
-
const style = document.createElement("style");
|
|
161
|
-
style.id = STYLE_ID;
|
|
162
|
-
style.textContent = `
|
|
163
|
-
#${OVERLAY_ID} {
|
|
164
|
-
position: fixed;
|
|
165
|
-
pointer-events: none;
|
|
166
|
-
z-index: ${Z_INDEX_OVERLAY};
|
|
167
|
-
border: 2px solid var(--ag-overlay-border, #3b82f6);
|
|
168
|
-
background: var(--ag-overlay-bg, rgba(59, 130, 246, 0.1));
|
|
169
|
-
transition: top 0.05s ease, left 0.05s ease, width 0.05s ease, height 0.05s ease;
|
|
170
|
-
box-sizing: border-box;
|
|
171
|
-
}
|
|
172
|
-
#${LABEL_ID} {
|
|
173
|
-
position: fixed;
|
|
174
|
-
pointer-events: none;
|
|
175
|
-
z-index: ${Z_INDEX_LABEL};
|
|
176
|
-
background: var(--ag-label-bg, #3b82f6);
|
|
177
|
-
color: var(--ag-label-text, #fff);
|
|
178
|
-
font: 11px/1.4 monospace;
|
|
179
|
-
padding: 2px 6px;
|
|
180
|
-
border-radius: 3px;
|
|
181
|
-
white-space: nowrap;
|
|
182
|
-
box-sizing: border-box;
|
|
183
|
-
max-width: 100vw;
|
|
184
|
-
overflow: hidden;
|
|
185
|
-
text-overflow: ellipsis;
|
|
186
|
-
}
|
|
187
|
-
`;
|
|
188
|
-
document.head.appendChild(style);
|
|
189
|
-
}
|
|
190
|
-
function ensureElements() {
|
|
191
|
-
if (!overlay) {
|
|
192
|
-
injectStyles2();
|
|
193
|
-
overlay = document.createElement("div");
|
|
194
|
-
overlay.id = OVERLAY_ID;
|
|
195
|
-
document.body.appendChild(overlay);
|
|
196
|
-
}
|
|
197
|
-
if (!label) {
|
|
198
|
-
label = document.createElement("div");
|
|
199
|
-
label.id = LABEL_ID;
|
|
200
|
-
document.body.appendChild(label);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
function positionOverlay() {
|
|
204
|
-
if (!currentElement || !overlay || !label) return;
|
|
205
|
-
const rect = currentElement.getBoundingClientRect();
|
|
206
|
-
if (rect.width === 0 && rect.height === 0 && !currentElement.isConnected) {
|
|
207
|
-
overlay.style.display = "none";
|
|
208
|
-
label.style.display = "none";
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
overlay.style.top = `${rect.top}px`;
|
|
212
|
-
overlay.style.left = `${rect.left}px`;
|
|
213
|
-
overlay.style.width = `${rect.width}px`;
|
|
214
|
-
overlay.style.height = `${rect.height}px`;
|
|
215
|
-
overlay.style.display = "block";
|
|
216
|
-
const tag = currentElement.tagName.toLowerCase();
|
|
217
|
-
let labelText = `<${tag}>`;
|
|
218
|
-
if (currentCssClasses.length > 0) {
|
|
219
|
-
labelText += ` .${currentCssClasses.join(".")}`;
|
|
220
|
-
}
|
|
221
|
-
if (currentComponentName) {
|
|
222
|
-
labelText += ` in ${currentComponentName}`;
|
|
223
|
-
}
|
|
224
|
-
if (currentSourcePath) {
|
|
225
|
-
labelText += ` \u2014 ${currentSourcePath}`;
|
|
226
|
-
}
|
|
227
|
-
label.textContent = labelText;
|
|
228
|
-
const labelHeight = 20;
|
|
229
|
-
const gap = 4;
|
|
230
|
-
let labelTop = rect.top - labelHeight - gap;
|
|
231
|
-
if (labelTop < 0) {
|
|
232
|
-
labelTop = rect.bottom + gap;
|
|
233
|
-
}
|
|
234
|
-
let labelLeft = rect.left;
|
|
235
|
-
label.style.top = `${labelTop}px`;
|
|
236
|
-
label.style.left = `${labelLeft}px`;
|
|
237
|
-
label.style.display = "block";
|
|
238
|
-
const labelRect = label.getBoundingClientRect();
|
|
239
|
-
const viewportWidth = document.documentElement.clientWidth;
|
|
240
|
-
if (labelRect.right > viewportWidth) {
|
|
241
|
-
labelLeft = Math.max(0, viewportWidth - labelRect.width);
|
|
242
|
-
label.style.left = `${labelLeft}px`;
|
|
243
|
-
}
|
|
244
|
-
if (labelLeft < 0) {
|
|
245
|
-
label.style.left = "0px";
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
function trackPosition() {
|
|
249
|
-
positionOverlay();
|
|
250
|
-
rafId = requestAnimationFrame(trackPosition);
|
|
251
|
-
}
|
|
252
|
-
function stopTracking() {
|
|
253
|
-
if (rafId !== null) {
|
|
254
|
-
cancelAnimationFrame(rafId);
|
|
255
|
-
rafId = null;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
return {
|
|
259
|
-
show(element, componentName, sourcePath, cssClasses) {
|
|
260
|
-
ensureElements();
|
|
261
|
-
currentElement = element;
|
|
262
|
-
currentComponentName = componentName;
|
|
263
|
-
currentSourcePath = sourcePath ?? null;
|
|
264
|
-
currentCssClasses = cssClasses ?? [];
|
|
265
|
-
stopTracking();
|
|
266
|
-
trackPosition();
|
|
267
|
-
},
|
|
268
|
-
hide() {
|
|
269
|
-
stopTracking();
|
|
270
|
-
currentElement = null;
|
|
271
|
-
currentComponentName = null;
|
|
272
|
-
currentSourcePath = null;
|
|
273
|
-
currentCssClasses = [];
|
|
274
|
-
if (overlay) overlay.style.display = "none";
|
|
275
|
-
if (label) label.style.display = "none";
|
|
276
|
-
},
|
|
277
|
-
isOverlayElement(el) {
|
|
278
|
-
return el === overlay || el === label || el.id === OVERLAY_ID || el.id === LABEL_ID;
|
|
279
|
-
},
|
|
280
|
-
dispose() {
|
|
281
|
-
stopTracking();
|
|
282
|
-
currentElement = null;
|
|
283
|
-
currentComponentName = null;
|
|
284
|
-
currentSourcePath = null;
|
|
285
|
-
currentCssClasses = [];
|
|
286
|
-
overlay?.remove();
|
|
287
|
-
label?.remove();
|
|
288
|
-
document.getElementById(STYLE_ID)?.remove();
|
|
289
|
-
overlay = null;
|
|
290
|
-
label = null;
|
|
291
|
-
}
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// src/core/overlay/crosshair.ts
|
|
296
|
-
var CROSSHAIR_STYLE_ID = "__ag-crosshair-styles__";
|
|
297
|
-
var H_LINE_ID = "__ag-crosshair-h__";
|
|
298
|
-
var V_LINE_ID = "__ag-crosshair-v__";
|
|
299
|
-
function createCrosshair() {
|
|
300
|
-
let hLine = null;
|
|
301
|
-
let vLine = null;
|
|
302
|
-
let listening = false;
|
|
303
|
-
function injectStyles2() {
|
|
304
|
-
if (document.getElementById(CROSSHAIR_STYLE_ID)) return;
|
|
305
|
-
const style = document.createElement("style");
|
|
306
|
-
style.id = CROSSHAIR_STYLE_ID;
|
|
307
|
-
style.textContent = `
|
|
308
|
-
.ag-crosshair-line {
|
|
309
|
-
position: fixed;
|
|
310
|
-
pointer-events: none;
|
|
311
|
-
z-index: ${Z_INDEX_CROSSHAIR};
|
|
312
|
-
background: var(--ag-accent, #3b82f6);
|
|
313
|
-
opacity: 0.25;
|
|
314
|
-
transition: none;
|
|
315
|
-
}
|
|
316
|
-
#${H_LINE_ID} {
|
|
317
|
-
left: 0;
|
|
318
|
-
right: 0;
|
|
319
|
-
height: 1px;
|
|
320
|
-
}
|
|
321
|
-
#${V_LINE_ID} {
|
|
322
|
-
top: 0;
|
|
323
|
-
bottom: 0;
|
|
324
|
-
width: 1px;
|
|
325
|
-
}
|
|
326
|
-
body.ag-crosshair-active {
|
|
327
|
-
cursor: crosshair !important;
|
|
328
|
-
}
|
|
329
|
-
`;
|
|
330
|
-
document.head.appendChild(style);
|
|
331
|
-
}
|
|
332
|
-
function ensureElements() {
|
|
333
|
-
if (!hLine) {
|
|
334
|
-
injectStyles2();
|
|
335
|
-
hLine = document.createElement("div");
|
|
336
|
-
hLine.id = H_LINE_ID;
|
|
337
|
-
hLine.className = "ag-crosshair-line";
|
|
338
|
-
document.body.appendChild(hLine);
|
|
339
|
-
}
|
|
340
|
-
if (!vLine) {
|
|
341
|
-
vLine = document.createElement("div");
|
|
342
|
-
vLine.id = V_LINE_ID;
|
|
343
|
-
vLine.className = "ag-crosshair-line";
|
|
344
|
-
document.body.appendChild(vLine);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
function handleMouseMove(e) {
|
|
348
|
-
if (hLine) {
|
|
349
|
-
hLine.style.top = `${e.clientY}px`;
|
|
350
|
-
}
|
|
351
|
-
if (vLine) {
|
|
352
|
-
vLine.style.left = `${e.clientX}px`;
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
return {
|
|
356
|
-
activate() {
|
|
357
|
-
if (listening) return;
|
|
358
|
-
listening = true;
|
|
359
|
-
ensureElements();
|
|
360
|
-
document.body.classList.add("ag-crosshair-active");
|
|
361
|
-
document.addEventListener("mousemove", handleMouseMove, true);
|
|
362
|
-
},
|
|
363
|
-
deactivate() {
|
|
364
|
-
if (!listening) return;
|
|
365
|
-
listening = false;
|
|
366
|
-
document.body.classList.remove("ag-crosshair-active");
|
|
367
|
-
document.removeEventListener("mousemove", handleMouseMove, true);
|
|
368
|
-
if (hLine) hLine.style.top = "-10px";
|
|
369
|
-
if (vLine) vLine.style.left = "-10px";
|
|
370
|
-
},
|
|
371
|
-
isCrosshairElement(el) {
|
|
372
|
-
return el === hLine || el === vLine || el.id === H_LINE_ID || el.id === V_LINE_ID;
|
|
373
|
-
},
|
|
374
|
-
dispose() {
|
|
375
|
-
this.deactivate();
|
|
376
|
-
hLine?.remove();
|
|
377
|
-
vLine?.remove();
|
|
378
|
-
document.getElementById(CROSSHAIR_STYLE_ID)?.remove();
|
|
379
|
-
hLine = null;
|
|
380
|
-
vLine = null;
|
|
381
|
-
}
|
|
382
|
-
};
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
// src/core/utils.ts
|
|
386
|
-
function escapeHtml(text) {
|
|
387
|
-
const div = document.createElement("div");
|
|
388
|
-
div.textContent = text;
|
|
389
|
-
return div.innerHTML;
|
|
390
|
-
}
|
|
391
|
-
function filterAngularClasses(classList) {
|
|
392
|
-
return Array.from(classList).filter((c) => !c.startsWith("ng-") && !c.startsWith("_ng"));
|
|
393
|
-
}
|
|
394
|
-
var NG_ATTR_RE = /\s_ng(host|content)-[a-z0-9-]+="[^"]*"/gi;
|
|
395
|
-
var NG_ATTR_EMPTY_RE = /\s_ng(host|content)-[a-z0-9-]+/gi;
|
|
396
|
-
function cleanAngularAttrs(html) {
|
|
397
|
-
return html.replace(NG_ATTR_RE, "").replace(NG_ATTR_EMPTY_RE, "");
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
// src/core/overlay/toast.ts
|
|
401
|
-
var TOAST_ID = "__ag-toast__";
|
|
402
|
-
var TOAST_STYLE_ID = "__ag-toast-styles__";
|
|
403
|
-
var activeTimer = null;
|
|
404
|
-
function injectToastStyles() {
|
|
405
|
-
if (document.getElementById(TOAST_STYLE_ID)) return;
|
|
406
|
-
const style = document.createElement("style");
|
|
407
|
-
style.id = TOAST_STYLE_ID;
|
|
408
|
-
style.textContent = `
|
|
409
|
-
#${TOAST_ID} {
|
|
410
|
-
position: fixed;
|
|
411
|
-
bottom: var(--ag-toast-bottom, 24px);
|
|
412
|
-
left: 50%;
|
|
413
|
-
transform: translateX(-50%) translateY(100%);
|
|
414
|
-
z-index: ${Z_INDEX_TOAST};
|
|
415
|
-
background: var(--ag-toast-bg, #0f172a);
|
|
416
|
-
color: var(--ag-toast-text, #e2e8f0);
|
|
417
|
-
font: 500 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
418
|
-
padding: 12px 18px;
|
|
419
|
-
border-radius: 10px;
|
|
420
|
-
box-shadow: 0 8px 24px var(--ag-toast-shadow, rgba(0, 0, 0, 0.4));
|
|
421
|
-
pointer-events: none;
|
|
422
|
-
opacity: 0;
|
|
423
|
-
transition: transform 0.25s ease, opacity 0.25s ease;
|
|
424
|
-
letter-spacing: 0.01em;
|
|
425
|
-
max-width: 480px;
|
|
426
|
-
min-width: 260px;
|
|
427
|
-
}
|
|
428
|
-
#${TOAST_ID}.ag-toast-visible {
|
|
429
|
-
transform: translateX(-50%) translateY(0);
|
|
430
|
-
opacity: 1;
|
|
431
|
-
}
|
|
432
|
-
#${TOAST_ID} .ag-toast-header {
|
|
433
|
-
display: flex;
|
|
434
|
-
align-items: center;
|
|
435
|
-
gap: 8px;
|
|
436
|
-
margin-bottom: 0;
|
|
437
|
-
}
|
|
438
|
-
#${TOAST_ID} .ag-toast-icon {
|
|
439
|
-
flex-shrink: 0;
|
|
440
|
-
width: 16px;
|
|
441
|
-
height: 16px;
|
|
442
|
-
}
|
|
443
|
-
#${TOAST_ID} .ag-toast-title {
|
|
444
|
-
font-weight: 600;
|
|
445
|
-
color: var(--ag-toast-title, #fff);
|
|
446
|
-
}
|
|
447
|
-
#${TOAST_ID} .ag-toast-details {
|
|
448
|
-
margin-top: 8px;
|
|
449
|
-
display: flex;
|
|
450
|
-
flex-direction: column;
|
|
451
|
-
gap: 4px;
|
|
452
|
-
font-size: 12px;
|
|
453
|
-
font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
|
|
454
|
-
}
|
|
455
|
-
#${TOAST_ID} .ag-toast-row {
|
|
456
|
-
display: flex;
|
|
457
|
-
gap: 8px;
|
|
458
|
-
align-items: baseline;
|
|
459
|
-
}
|
|
460
|
-
#${TOAST_ID} .ag-toast-label {
|
|
461
|
-
color: var(--ag-toast-label, #64748b);
|
|
462
|
-
flex-shrink: 0;
|
|
463
|
-
min-width: 72px;
|
|
464
|
-
}
|
|
465
|
-
#${TOAST_ID} .ag-toast-value {
|
|
466
|
-
color: var(--ag-toast-text, #e2e8f0);
|
|
467
|
-
overflow: hidden;
|
|
468
|
-
text-overflow: ellipsis;
|
|
469
|
-
white-space: nowrap;
|
|
470
|
-
}
|
|
471
|
-
#${TOAST_ID} .ag-toast-file-link {
|
|
472
|
-
color: var(--ag-toast-text, #e2e8f0);
|
|
473
|
-
text-decoration: none;
|
|
474
|
-
overflow: hidden;
|
|
475
|
-
text-overflow: ellipsis;
|
|
476
|
-
white-space: nowrap;
|
|
477
|
-
pointer-events: auto;
|
|
478
|
-
cursor: pointer;
|
|
479
|
-
}
|
|
480
|
-
#${TOAST_ID} .ag-toast-file-link:hover {
|
|
481
|
-
text-decoration: underline;
|
|
482
|
-
color: var(--ag-accent, #3b82f6);
|
|
483
|
-
}
|
|
484
|
-
`;
|
|
485
|
-
document.head.appendChild(style);
|
|
486
|
-
}
|
|
487
|
-
function getOrCreateToast() {
|
|
488
|
-
let toast = document.getElementById(TOAST_ID);
|
|
489
|
-
if (!toast) {
|
|
490
|
-
injectToastStyles();
|
|
491
|
-
toast = document.createElement("div");
|
|
492
|
-
toast.id = TOAST_ID;
|
|
493
|
-
document.body.appendChild(toast);
|
|
494
|
-
}
|
|
495
|
-
return toast;
|
|
496
|
-
}
|
|
497
|
-
var CHECKMARK_SVG = `<svg class="ag-toast-icon" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="8" cy="8" r="7" fill="#22c55e"/><path d="M5 8l2 2 4-4" stroke="#fff" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
|
|
498
|
-
function showToast(message, detail, durationMs = 3500) {
|
|
499
|
-
const toast = getOrCreateToast();
|
|
500
|
-
let html = `<div class="ag-toast-header">${CHECKMARK_SVG}<span class="ag-toast-title">${escapeHtml(message)}</span></div>`;
|
|
501
|
-
if (detail) {
|
|
502
|
-
html += '<div class="ag-toast-details">';
|
|
503
|
-
if (detail.componentName) {
|
|
504
|
-
html += `<div class="ag-toast-row"><span class="ag-toast-label">Component</span><span class="ag-toast-value">${escapeHtml(detail.componentName)}</span></div>`;
|
|
505
|
-
}
|
|
506
|
-
if (detail.filePath) {
|
|
507
|
-
let loc = detail.filePath;
|
|
508
|
-
if (detail.line != null) loc += `:${detail.line}`;
|
|
509
|
-
let vsCodeUri = `vscode://file/${encodeURI(detail.filePath)}`;
|
|
510
|
-
if (detail.line != null) vsCodeUri += `:${detail.line}`;
|
|
511
|
-
if (detail.line != null && detail.column != null) vsCodeUri += `:${detail.column}`;
|
|
512
|
-
html += `<div class="ag-toast-row"><span class="ag-toast-label">File</span>`;
|
|
513
|
-
html += `<a class="ag-toast-file-link" href="${escapeHtml(vsCodeUri)}" title="Open in VS Code">${escapeHtml(loc)}</a>`;
|
|
514
|
-
html += `</div>`;
|
|
515
|
-
}
|
|
516
|
-
if (detail.cssClasses && detail.cssClasses.length > 0) {
|
|
517
|
-
const classes = detail.cssClasses.map((c) => `.${escapeHtml(c)}`).join(" ");
|
|
518
|
-
html += `<div class="ag-toast-row"><span class="ag-toast-label">Classes</span><span class="ag-toast-value">${classes}</span></div>`;
|
|
519
|
-
}
|
|
520
|
-
html += "</div>";
|
|
521
|
-
}
|
|
522
|
-
toast.innerHTML = html;
|
|
523
|
-
if (activeTimer) {
|
|
524
|
-
clearTimeout(activeTimer);
|
|
525
|
-
activeTimer = null;
|
|
526
|
-
}
|
|
527
|
-
toast.classList.remove("ag-toast-visible");
|
|
528
|
-
void toast.offsetHeight;
|
|
529
|
-
toast.classList.add("ag-toast-visible");
|
|
530
|
-
activeTimer = setTimeout(() => {
|
|
531
|
-
toast.classList.remove("ag-toast-visible");
|
|
532
|
-
activeTimer = null;
|
|
533
|
-
}, durationMs);
|
|
534
|
-
}
|
|
535
|
-
function disposeToast() {
|
|
536
|
-
if (activeTimer) {
|
|
537
|
-
clearTimeout(activeTimer);
|
|
538
|
-
activeTimer = null;
|
|
539
|
-
}
|
|
540
|
-
document.getElementById(TOAST_ID)?.remove();
|
|
541
|
-
document.getElementById(TOAST_STYLE_ID)?.remove();
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
// src/core/picker/element-picker.ts
|
|
545
|
-
function createElementPicker(deps) {
|
|
546
|
-
let hoveredElement = null;
|
|
547
|
-
let listening = false;
|
|
548
|
-
function resolveComponentName(el) {
|
|
549
|
-
const resolver = deps.getComponentResolver();
|
|
550
|
-
if (!resolver) return null;
|
|
551
|
-
const result = resolver(el);
|
|
552
|
-
return result?.name ?? null;
|
|
553
|
-
}
|
|
554
|
-
function resolveSourcePath(el) {
|
|
555
|
-
const resolver = deps.getSourceResolver();
|
|
556
|
-
if (!resolver) return null;
|
|
557
|
-
const result = resolver(el);
|
|
558
|
-
if (!result?.filePath) return null;
|
|
559
|
-
let path = result.filePath;
|
|
560
|
-
if (result.line != null) {
|
|
561
|
-
path += `:${result.line}`;
|
|
562
|
-
}
|
|
563
|
-
return path;
|
|
564
|
-
}
|
|
565
|
-
function elementAtPoint(x, y) {
|
|
566
|
-
const freezeEl = deps.getFreezeElement?.();
|
|
567
|
-
if (freezeEl) freezeEl.style.pointerEvents = "none";
|
|
568
|
-
const target = document.elementFromPoint(x, y);
|
|
569
|
-
if (freezeEl) freezeEl.style.pointerEvents = "auto";
|
|
570
|
-
return target;
|
|
571
|
-
}
|
|
572
|
-
function handleMouseMove(e) {
|
|
573
|
-
const target = elementAtPoint(e.clientX, e.clientY);
|
|
574
|
-
if (!target || deps.overlay.isOverlayElement(target)) return;
|
|
575
|
-
if (deps.crosshair.isCrosshairElement(target)) return;
|
|
576
|
-
if (deps.isToolbarElement?.(target)) return;
|
|
577
|
-
if (target === hoveredElement) return;
|
|
578
|
-
hoveredElement = target;
|
|
579
|
-
const componentName = resolveComponentName(target);
|
|
580
|
-
const sourcePath = resolveSourcePath(target);
|
|
581
|
-
const cssClasses = filterAngularClasses(target.classList);
|
|
582
|
-
deps.overlay.show(target, componentName, sourcePath, cssClasses);
|
|
583
|
-
deps.onHover(target);
|
|
584
|
-
}
|
|
585
|
-
function handleClick(e) {
|
|
586
|
-
const target = elementAtPoint(e.clientX, e.clientY);
|
|
587
|
-
if (target && (deps.isToolbarElement?.(target) || deps.crosshair.isCrosshairElement(target))) return;
|
|
588
|
-
e.preventDefault();
|
|
589
|
-
e.stopPropagation();
|
|
590
|
-
if (hoveredElement) {
|
|
591
|
-
deps.onSelect(hoveredElement);
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
return {
|
|
595
|
-
activate() {
|
|
596
|
-
if (listening) return;
|
|
597
|
-
listening = true;
|
|
598
|
-
deps.crosshair.activate();
|
|
599
|
-
document.addEventListener("mousemove", handleMouseMove, true);
|
|
600
|
-
document.addEventListener("click", handleClick, true);
|
|
601
|
-
},
|
|
602
|
-
deactivate() {
|
|
603
|
-
if (!listening) return;
|
|
604
|
-
listening = false;
|
|
605
|
-
hoveredElement = null;
|
|
606
|
-
deps.crosshair.deactivate();
|
|
607
|
-
document.removeEventListener("mousemove", handleMouseMove, true);
|
|
608
|
-
document.removeEventListener("click", handleClick, true);
|
|
609
|
-
deps.overlay.hide();
|
|
610
|
-
deps.onHover(null);
|
|
611
|
-
},
|
|
612
|
-
getHoveredElement() {
|
|
613
|
-
return hoveredElement;
|
|
614
|
-
},
|
|
615
|
-
dispose() {
|
|
616
|
-
this.deactivate();
|
|
617
|
-
}
|
|
618
|
-
};
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
// src/core/keyboard/keyboard-handler.ts
|
|
622
|
-
function isMac() {
|
|
623
|
-
if (typeof navigator === "undefined") return false;
|
|
624
|
-
const uaData = navigator.userAgentData;
|
|
625
|
-
if (uaData?.platform) return /mac/i.test(uaData.platform);
|
|
626
|
-
return /Mac|iPhone|iPad|iPod/i.test(navigator.userAgent);
|
|
627
|
-
}
|
|
628
|
-
function parseKeyCombo(combo) {
|
|
629
|
-
const parts = combo.split("+").map((s) => s.trim());
|
|
630
|
-
const result = {
|
|
631
|
-
key: "",
|
|
632
|
-
meta: false,
|
|
633
|
-
ctrl: false,
|
|
634
|
-
shift: false,
|
|
635
|
-
alt: false
|
|
636
|
-
};
|
|
637
|
-
for (const part of parts) {
|
|
638
|
-
const lower = part.toLowerCase();
|
|
639
|
-
if (lower === "meta" || lower === "cmd" || lower === "command") {
|
|
640
|
-
result.meta = true;
|
|
641
|
-
} else if (lower === "ctrl" || lower === "control") {
|
|
642
|
-
result.ctrl = true;
|
|
643
|
-
} else if (lower === "shift") {
|
|
644
|
-
result.shift = true;
|
|
645
|
-
} else if (lower === "alt" || lower === "option") {
|
|
646
|
-
result.alt = true;
|
|
647
|
-
} else {
|
|
648
|
-
result.key = lower;
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
return result;
|
|
652
|
-
}
|
|
653
|
-
function matchesCombo(e, parsed) {
|
|
654
|
-
if (parsed.meta && !e.metaKey) return false;
|
|
655
|
-
if (parsed.ctrl && !e.ctrlKey) return false;
|
|
656
|
-
if (parsed.shift && !e.shiftKey) return false;
|
|
657
|
-
if (parsed.alt && !e.altKey) return false;
|
|
658
|
-
return e.key.toLowerCase() === parsed.key;
|
|
659
|
-
}
|
|
660
|
-
function isInputElement(el) {
|
|
661
|
-
if (!el || !(el instanceof HTMLElement)) return false;
|
|
662
|
-
const tag = el.tagName;
|
|
663
|
-
return tag === "INPUT" || tag === "TEXTAREA" || el.isContentEditable;
|
|
664
|
-
}
|
|
665
|
-
function createKeyboardHandler(deps) {
|
|
666
|
-
let holdTimer = null;
|
|
667
|
-
let holdActivated = false;
|
|
668
|
-
let listening = false;
|
|
669
|
-
function handleKeyDown(e) {
|
|
670
|
-
if (!deps.getEnableInInputs() && isInputElement(e.target)) return;
|
|
671
|
-
const parsed = parseKeyCombo(deps.getActivationKey());
|
|
672
|
-
if (!matchesCombo(e, parsed)) return;
|
|
673
|
-
const mode = deps.getActivationMode();
|
|
674
|
-
const holdDuration = deps.getKeyHoldDuration();
|
|
675
|
-
if (mode === "hold") {
|
|
676
|
-
e.preventDefault();
|
|
677
|
-
if (holdActivated) return;
|
|
678
|
-
if (holdDuration > 0) {
|
|
679
|
-
if (holdTimer) return;
|
|
680
|
-
holdTimer = setTimeout(() => {
|
|
681
|
-
holdActivated = true;
|
|
682
|
-
deps.onActivate();
|
|
683
|
-
}, holdDuration);
|
|
684
|
-
} else {
|
|
685
|
-
holdActivated = true;
|
|
686
|
-
deps.onActivate();
|
|
687
|
-
}
|
|
688
|
-
} else {
|
|
689
|
-
e.preventDefault();
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
function handleKeyUp(e) {
|
|
693
|
-
const parsed = parseKeyCombo(deps.getActivationKey());
|
|
694
|
-
if (e.key.toLowerCase() !== parsed.key) return;
|
|
695
|
-
const mode = deps.getActivationMode();
|
|
696
|
-
if (mode === "hold") {
|
|
697
|
-
if (holdTimer) {
|
|
698
|
-
clearTimeout(holdTimer);
|
|
699
|
-
holdTimer = null;
|
|
700
|
-
}
|
|
701
|
-
if (holdActivated) {
|
|
702
|
-
holdActivated = false;
|
|
703
|
-
deps.onDeactivate();
|
|
704
|
-
}
|
|
705
|
-
} else {
|
|
706
|
-
if (deps.isActive()) {
|
|
707
|
-
deps.onDeactivate();
|
|
708
|
-
} else {
|
|
709
|
-
deps.onActivate();
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
return {
|
|
714
|
-
start() {
|
|
715
|
-
if (listening) return;
|
|
716
|
-
listening = true;
|
|
717
|
-
document.addEventListener("keydown", handleKeyDown, true);
|
|
718
|
-
document.addEventListener("keyup", handleKeyUp, true);
|
|
719
|
-
},
|
|
720
|
-
stop() {
|
|
721
|
-
if (!listening) return;
|
|
722
|
-
listening = false;
|
|
723
|
-
if (holdTimer) {
|
|
724
|
-
clearTimeout(holdTimer);
|
|
725
|
-
holdTimer = null;
|
|
726
|
-
}
|
|
727
|
-
holdActivated = false;
|
|
728
|
-
document.removeEventListener("keydown", handleKeyDown, true);
|
|
729
|
-
document.removeEventListener("keyup", handleKeyUp, true);
|
|
730
|
-
},
|
|
731
|
-
dispose() {
|
|
732
|
-
this.stop();
|
|
733
|
-
}
|
|
734
|
-
};
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
// src/core/clipboard/generate-snippet.ts
|
|
738
|
-
function truncateHtml(html, maxLines) {
|
|
739
|
-
const lines = html.split("\n");
|
|
740
|
-
if (lines.length <= maxLines) return html;
|
|
741
|
-
return lines.slice(0, maxLines).join("\n") + "\n ...";
|
|
742
|
-
}
|
|
743
|
-
function formatLocation(name, filePath, line, column) {
|
|
744
|
-
let locationLine = "";
|
|
745
|
-
if (name) locationLine += `in ${name}`;
|
|
746
|
-
if (filePath) {
|
|
747
|
-
const loc = filePath + (line != null ? `:${line}` : "") + (line != null && column != null ? `:${column}` : "");
|
|
748
|
-
locationLine += locationLine ? ` at ${loc}` : `at ${loc}`;
|
|
749
|
-
}
|
|
750
|
-
return locationLine;
|
|
751
|
-
}
|
|
752
|
-
function generateSnippet(context, maxContextLines) {
|
|
753
|
-
const cleaned = cleanAngularAttrs(context.html);
|
|
754
|
-
const truncated = truncateHtml(cleaned, maxContextLines);
|
|
755
|
-
const parts = [truncated];
|
|
756
|
-
if (context.componentStack.length > 0) {
|
|
757
|
-
for (const entry of context.componentStack) {
|
|
758
|
-
parts.push(formatLocation(entry.name, entry.filePath, entry.line, entry.column));
|
|
759
|
-
}
|
|
760
|
-
} else if (context.componentName || context.filePath) {
|
|
761
|
-
parts.push(formatLocation(context.componentName, context.filePath, context.line, context.column));
|
|
762
|
-
}
|
|
763
|
-
return parts.join("\n");
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
// src/core/clipboard/copy.ts
|
|
767
|
-
function buildSelector(el) {
|
|
768
|
-
const tag = el.tagName.toLowerCase();
|
|
769
|
-
const id = el.id ? `#${el.id}` : "";
|
|
770
|
-
const classes = filterAngularClasses(el.classList).map((c) => `.${c}`).join("");
|
|
771
|
-
return `${tag}${id}${classes}`;
|
|
772
|
-
}
|
|
773
|
-
function getCssClasses(el) {
|
|
774
|
-
return filterAngularClasses(el.classList);
|
|
775
|
-
}
|
|
776
|
-
function buildElementContext(element, componentResolver, sourceResolver) {
|
|
777
|
-
const compResult = componentResolver?.(element);
|
|
778
|
-
const srcResult = sourceResolver?.(element);
|
|
779
|
-
const componentStack = [];
|
|
780
|
-
if (compResult?.stack) {
|
|
781
|
-
for (const entry of compResult.stack) {
|
|
782
|
-
let filePath = null;
|
|
783
|
-
let line = null;
|
|
784
|
-
let column = null;
|
|
785
|
-
if (entry.hostElement && sourceResolver) {
|
|
786
|
-
const src = sourceResolver(entry.hostElement);
|
|
787
|
-
if (src) {
|
|
788
|
-
filePath = src.filePath;
|
|
789
|
-
line = src.line;
|
|
790
|
-
column = src.column;
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
componentStack.push({ name: entry.name, filePath, line, column });
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
return {
|
|
797
|
-
element,
|
|
798
|
-
html: element.outerHTML,
|
|
799
|
-
componentName: compResult?.name ?? null,
|
|
800
|
-
filePath: srcResult?.filePath ?? null,
|
|
801
|
-
line: srcResult?.line ?? null,
|
|
802
|
-
column: srcResult?.column ?? null,
|
|
803
|
-
componentStack,
|
|
804
|
-
selector: buildSelector(element),
|
|
805
|
-
cssClasses: getCssClasses(element)
|
|
806
|
-
};
|
|
807
|
-
}
|
|
808
|
-
async function copyElement(element, deps) {
|
|
809
|
-
const context = buildElementContext(
|
|
810
|
-
element,
|
|
811
|
-
deps.getComponentResolver(),
|
|
812
|
-
deps.getSourceResolver()
|
|
813
|
-
);
|
|
814
|
-
deps.pluginRegistry.callHook("onElementSelect", context);
|
|
815
|
-
deps.pluginRegistry.callHook("onBeforeCopy", context);
|
|
816
|
-
let snippet = generateSnippet(context, deps.getMaxContextLines());
|
|
817
|
-
snippet = deps.pluginRegistry.callTransformHook(snippet, context);
|
|
818
|
-
try {
|
|
819
|
-
await navigator.clipboard.writeText(snippet);
|
|
820
|
-
const detail = {
|
|
821
|
-
componentName: context.componentName,
|
|
822
|
-
filePath: context.filePath,
|
|
823
|
-
line: context.line,
|
|
824
|
-
column: context.column,
|
|
825
|
-
cssClasses: context.cssClasses
|
|
826
|
-
};
|
|
827
|
-
showToast("Copied to clipboard", detail);
|
|
828
|
-
deps.pluginRegistry.callHook("onCopySuccess", snippet, context, void 0);
|
|
829
|
-
return { context, snippet };
|
|
830
|
-
} catch (err) {
|
|
831
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
832
|
-
deps.pluginRegistry.callHook("onCopyError", error);
|
|
833
|
-
return null;
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
// src/core/plugins/plugin-registry.ts
|
|
838
|
-
function createPluginRegistry() {
|
|
839
|
-
const plugins = /* @__PURE__ */ new Map();
|
|
840
|
-
const cleanups = /* @__PURE__ */ new Map();
|
|
841
|
-
return {
|
|
842
|
-
register(plugin, api) {
|
|
843
|
-
if (plugins.has(plugin.name)) {
|
|
844
|
-
this.unregister(plugin.name);
|
|
845
|
-
}
|
|
846
|
-
plugins.set(plugin.name, plugin);
|
|
847
|
-
if (plugin.setup) {
|
|
848
|
-
const cleanup = plugin.setup(api);
|
|
849
|
-
if (cleanup) {
|
|
850
|
-
cleanups.set(plugin.name, cleanup);
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
},
|
|
854
|
-
unregister(name) {
|
|
855
|
-
const cleanup = cleanups.get(name);
|
|
856
|
-
if (cleanup) {
|
|
857
|
-
cleanup();
|
|
858
|
-
cleanups.delete(name);
|
|
859
|
-
}
|
|
860
|
-
plugins.delete(name);
|
|
861
|
-
},
|
|
862
|
-
callHook(hookName, ...args) {
|
|
863
|
-
for (const plugin of plugins.values()) {
|
|
864
|
-
const hook = plugin.hooks?.[hookName];
|
|
865
|
-
if (hook) {
|
|
866
|
-
try {
|
|
867
|
-
hook(...args);
|
|
868
|
-
} catch (err) {
|
|
869
|
-
console.warn(`[angular-grab] Plugin "${plugin.name}" hook "${hookName}" threw:`, err);
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
},
|
|
874
|
-
callTransformHook(text, context) {
|
|
875
|
-
let result = text;
|
|
876
|
-
for (const plugin of plugins.values()) {
|
|
877
|
-
const transform = plugin.hooks?.transformCopyContent;
|
|
878
|
-
if (transform) {
|
|
879
|
-
try {
|
|
880
|
-
result = transform(result, context);
|
|
881
|
-
} catch (err) {
|
|
882
|
-
console.warn(`[angular-grab] Plugin "${plugin.name}" transformCopyContent threw:`, err);
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
return result;
|
|
887
|
-
},
|
|
888
|
-
getPlugins() {
|
|
889
|
-
return Array.from(plugins.values());
|
|
890
|
-
},
|
|
891
|
-
dispose() {
|
|
892
|
-
for (const [name] of plugins) {
|
|
893
|
-
const cleanup = cleanups.get(name);
|
|
894
|
-
if (cleanup) {
|
|
895
|
-
try {
|
|
896
|
-
cleanup();
|
|
897
|
-
} catch {
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
cleanups.clear();
|
|
902
|
-
plugins.clear();
|
|
903
|
-
}
|
|
904
|
-
};
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
// src/core/toolbar/theme-manager.ts
|
|
908
|
-
var STYLE_ID2 = "__ag-theme-vars__";
|
|
909
|
-
var OVERRIDE_STYLE_ID = "__ag-theme-overrides__";
|
|
910
|
-
var DARK_VARS = `
|
|
911
|
-
:root {
|
|
912
|
-
--ag-bg: #0f172a;
|
|
913
|
-
--ag-text: #e2e8f0;
|
|
914
|
-
--ag-text-muted: #64748b;
|
|
915
|
-
--ag-accent: #3b82f6;
|
|
916
|
-
--ag-accent-hover: #2563eb;
|
|
917
|
-
--ag-surface: #1e293b;
|
|
918
|
-
--ag-border: #334155;
|
|
919
|
-
--ag-overlay-border: #3b82f6;
|
|
920
|
-
--ag-overlay-bg: rgba(59, 130, 246, 0.1);
|
|
921
|
-
--ag-label-bg: #3b82f6;
|
|
922
|
-
--ag-label-text: #fff;
|
|
923
|
-
--ag-toast-bg: #0f172a;
|
|
924
|
-
--ag-toast-text: #e2e8f0;
|
|
925
|
-
--ag-toast-title: #fff;
|
|
926
|
-
--ag-toast-label: #64748b;
|
|
927
|
-
--ag-toast-shadow: rgba(0, 0, 0, 0.4);
|
|
928
|
-
--ag-toolbar-bg: #0f172a;
|
|
929
|
-
--ag-toolbar-text: #94a3b8;
|
|
930
|
-
--ag-toolbar-hover: #1e293b;
|
|
931
|
-
--ag-toolbar-active: #3b82f6;
|
|
932
|
-
--ag-toolbar-border: #1e293b;
|
|
933
|
-
--ag-toolbar-shadow: rgba(0, 0, 0, 0.5);
|
|
934
|
-
--ag-popover-bg: #0f172a;
|
|
935
|
-
--ag-popover-text: #e2e8f0;
|
|
936
|
-
--ag-popover-border: #1e293b;
|
|
937
|
-
--ag-popover-hover: #1e293b;
|
|
938
|
-
--ag-popover-shadow: rgba(0, 0, 0, 0.5);
|
|
939
|
-
}
|
|
940
|
-
`;
|
|
941
|
-
var LIGHT_VARS = `
|
|
942
|
-
:root {
|
|
943
|
-
--ag-bg: #ffffff;
|
|
944
|
-
--ag-text: #334155;
|
|
945
|
-
--ag-text-muted: #94a3b8;
|
|
946
|
-
--ag-accent: #2563eb;
|
|
947
|
-
--ag-accent-hover: #1d4ed8;
|
|
948
|
-
--ag-surface: #f1f5f9;
|
|
949
|
-
--ag-border: #e2e8f0;
|
|
950
|
-
--ag-overlay-border: #2563eb;
|
|
951
|
-
--ag-overlay-bg: rgba(37, 99, 235, 0.08);
|
|
952
|
-
--ag-label-bg: #2563eb;
|
|
953
|
-
--ag-label-text: #fff;
|
|
954
|
-
--ag-toast-bg: #ffffff;
|
|
955
|
-
--ag-toast-text: #334155;
|
|
956
|
-
--ag-toast-title: #0f172a;
|
|
957
|
-
--ag-toast-label: #94a3b8;
|
|
958
|
-
--ag-toast-shadow: rgba(0, 0, 0, 0.12);
|
|
959
|
-
--ag-toolbar-bg: #ffffff;
|
|
960
|
-
--ag-toolbar-text: #64748b;
|
|
961
|
-
--ag-toolbar-hover: #f1f5f9;
|
|
962
|
-
--ag-toolbar-active: #2563eb;
|
|
963
|
-
--ag-toolbar-border: #e2e8f0;
|
|
964
|
-
--ag-toolbar-shadow: rgba(0, 0, 0, 0.12);
|
|
965
|
-
--ag-popover-bg: #ffffff;
|
|
966
|
-
--ag-popover-text: #334155;
|
|
967
|
-
--ag-popover-border: #e2e8f0;
|
|
968
|
-
--ag-popover-hover: #f1f5f9;
|
|
969
|
-
--ag-popover-shadow: rgba(0, 0, 0, 0.12);
|
|
970
|
-
}
|
|
971
|
-
`;
|
|
972
|
-
var THEME_TO_VAR = {
|
|
973
|
-
overlayBorderColor: "--ag-overlay-border",
|
|
974
|
-
overlayBgColor: "--ag-overlay-bg",
|
|
975
|
-
labelBgColor: "--ag-label-bg",
|
|
976
|
-
labelTextColor: "--ag-label-text",
|
|
977
|
-
toastBgColor: "--ag-toast-bg",
|
|
978
|
-
toastTextColor: "--ag-toast-text",
|
|
979
|
-
toolbarBgColor: "--ag-toolbar-bg",
|
|
980
|
-
toolbarTextColor: "--ag-toolbar-text",
|
|
981
|
-
toolbarAccentColor: "--ag-toolbar-active",
|
|
982
|
-
popoverBgColor: "--ag-popover-bg",
|
|
983
|
-
popoverTextColor: "--ag-popover-text",
|
|
984
|
-
popoverBorderColor: "--ag-popover-border"
|
|
985
|
-
};
|
|
986
|
-
function createThemeManager() {
|
|
987
|
-
let styleEl = null;
|
|
988
|
-
let overrideEl = null;
|
|
989
|
-
let currentMode = "dark";
|
|
990
|
-
let mediaQuery = null;
|
|
991
|
-
let mediaHandler = null;
|
|
992
|
-
function getOrCreateStyle() {
|
|
993
|
-
if (styleEl) return styleEl;
|
|
994
|
-
const existing = document.getElementById(STYLE_ID2);
|
|
995
|
-
if (existing) {
|
|
996
|
-
styleEl = existing;
|
|
997
|
-
return styleEl;
|
|
998
|
-
}
|
|
999
|
-
styleEl = document.createElement("style");
|
|
1000
|
-
styleEl.id = STYLE_ID2;
|
|
1001
|
-
document.head.appendChild(styleEl);
|
|
1002
|
-
return styleEl;
|
|
1003
|
-
}
|
|
1004
|
-
function getOrCreateOverrideStyle() {
|
|
1005
|
-
if (overrideEl) return overrideEl;
|
|
1006
|
-
overrideEl = document.createElement("style");
|
|
1007
|
-
overrideEl.id = OVERRIDE_STYLE_ID;
|
|
1008
|
-
document.head.appendChild(overrideEl);
|
|
1009
|
-
return overrideEl;
|
|
1010
|
-
}
|
|
1011
|
-
function resolveMode(mode) {
|
|
1012
|
-
if (mode !== "system") return mode;
|
|
1013
|
-
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
1014
|
-
}
|
|
1015
|
-
function applyResolved(resolved) {
|
|
1016
|
-
const el = getOrCreateStyle();
|
|
1017
|
-
el.textContent = resolved === "dark" ? DARK_VARS : LIGHT_VARS;
|
|
1018
|
-
}
|
|
1019
|
-
function detachMediaListener() {
|
|
1020
|
-
if (mediaQuery && mediaHandler) {
|
|
1021
|
-
mediaQuery.removeEventListener("change", mediaHandler);
|
|
1022
|
-
}
|
|
1023
|
-
mediaQuery = null;
|
|
1024
|
-
mediaHandler = null;
|
|
1025
|
-
}
|
|
1026
|
-
return {
|
|
1027
|
-
apply(mode) {
|
|
1028
|
-
currentMode = mode;
|
|
1029
|
-
detachMediaListener();
|
|
1030
|
-
applyResolved(resolveMode(mode));
|
|
1031
|
-
if (mode === "system") {
|
|
1032
|
-
mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
|
1033
|
-
mediaHandler = () => applyResolved(resolveMode("system"));
|
|
1034
|
-
mediaQuery.addEventListener("change", mediaHandler);
|
|
1035
|
-
}
|
|
1036
|
-
},
|
|
1037
|
-
applyOverrides(theme) {
|
|
1038
|
-
const vars = [];
|
|
1039
|
-
for (const [key, varName] of Object.entries(THEME_TO_VAR)) {
|
|
1040
|
-
const value = theme[key];
|
|
1041
|
-
if (value) {
|
|
1042
|
-
vars.push(` ${varName}: ${value};`);
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
if (vars.length === 0) {
|
|
1046
|
-
this.clearOverrides();
|
|
1047
|
-
return;
|
|
1048
|
-
}
|
|
1049
|
-
const el = getOrCreateOverrideStyle();
|
|
1050
|
-
el.textContent = ` :root {
|
|
1051
|
-
${vars.join("\n")}
|
|
1052
|
-
}`;
|
|
1053
|
-
},
|
|
1054
|
-
clearOverrides() {
|
|
1055
|
-
overrideEl?.remove();
|
|
1056
|
-
document.getElementById(OVERRIDE_STYLE_ID)?.remove();
|
|
1057
|
-
overrideEl = null;
|
|
1058
|
-
},
|
|
1059
|
-
dispose() {
|
|
1060
|
-
detachMediaListener();
|
|
1061
|
-
styleEl?.remove();
|
|
1062
|
-
document.getElementById(STYLE_ID2)?.remove();
|
|
1063
|
-
styleEl = null;
|
|
1064
|
-
this.clearOverrides();
|
|
1065
|
-
}
|
|
1066
|
-
};
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
// src/core/toolbar/toolbar-icons.ts
|
|
1070
|
-
var ICON_GRAB = `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><path d="M5.5 7V3.5a1 1 0 0 1 2 0V7"/><path d="M7.5 6.5V2.5a1 1 0 0 1 2 0v4"/><path d="M9.5 7V3.5a1 1 0 0 1 2 0V8"/><path d="M5.5 7V5.5a1 1 0 0 0-2 0V9a4 4 0 0 0 4 4h1.5a4 4 0 0 0 4-4V6a1 1 0 0 0-2 0"/></svg>`;
|
|
1071
|
-
var ICON_HISTORY = `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><circle cx="8" cy="8" r="6"/><path d="M8 4.5V8l2.5 1.5"/></svg>`;
|
|
1072
|
-
var ICON_ELLIPSIS = `<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><circle cx="4" cy="8" r="1.25"/><circle cx="8" cy="8" r="1.25"/><circle cx="12" cy="8" r="1.25"/></svg>`;
|
|
1073
|
-
var ICON_SUN = `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" xmlns="http://www.w3.org/2000/svg"><circle cx="8" cy="8" r="3"/><path d="M8 1.5v1M8 13.5v1M1.5 8h1M13.5 8h1M3.4 3.4l.7.7M11.9 11.9l.7.7M3.4 12.6l.7-.7M11.9 4.1l.7-.7"/></svg>`;
|
|
1074
|
-
var ICON_MOON = `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><path d="M13.5 8.5a5.5 5.5 0 0 1-7-7 5.5 5.5 0 1 0 7 7z"/></svg>`;
|
|
1075
|
-
var ICON_SYSTEM = `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><rect x="2" y="2" width="12" height="9" rx="1"/><path d="M5.5 14h5"/><path d="M8 11v3"/></svg>`;
|
|
1076
|
-
var ICON_POWER = `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><path d="M8 2v5"/><path d="M4.5 4a5.5 5.5 0 1 0 7 0"/></svg>`;
|
|
1077
|
-
var ICON_DISMISS = `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" xmlns="http://www.w3.org/2000/svg"><path d="M4 4l8 8M12 4l-8 8"/></svg>`;
|
|
1078
|
-
var ICON_COPY = `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><rect x="5.5" y="5.5" width="7" height="8" rx="1"/><path d="M3.5 10.5v-7a1 1 0 0 1 1-1h5"/></svg>`;
|
|
1079
|
-
var ICON_STYLES = `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><path d="M13 1.5l-1.3 4.3a1 1 0 0 1-.7.7L6.7 7.8a1 1 0 0 0-.7.7L4.7 12.8a1 1 0 0 1-.7.7L1.5 14"/><path d="M7.5 5.5l3 3"/></svg>`;
|
|
1080
|
-
var ICON_CODE = `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><path d="M5 4.5L1.5 8 5 11.5"/><path d="M11 4.5l3.5 3.5-3.5 3.5"/><path d="M9.5 2.5l-3 11"/></svg>`;
|
|
1081
|
-
var ICON_COMMENT = `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><path d="M2 3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v7a1 1 0 0 1-1 1H5l-3 3V3z"/></svg>`;
|
|
1082
|
-
var ICON_TRASH = `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><path d="M2.5 4.5h11"/><path d="M5.5 4.5V3a1 1 0 0 1 1-1h3a1 1 0 0 1 1 1v1.5"/><path d="M4 4.5l.5 8.5a1 1 0 0 0 1 1h5a1 1 0 0 0 1-1l.5-8.5"/></svg>`;
|
|
1083
|
-
var ICON_FREEZE = `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><path d="M8 1v14"/><path d="M1 8h14"/><path d="M8 1l2 2M8 1L6 3"/><path d="M8 15l2-2M8 15l-2-2"/><path d="M1 8l2 2M1 8l2-2"/><path d="M15 8l-2 2M15 8l-2-2"/></svg>`;
|
|
1084
|
-
|
|
1085
|
-
// src/core/toolbar/toolbar-renderer.ts
|
|
1086
|
-
var TOOLBAR_ID = "__ag-toolbar__";
|
|
1087
|
-
var STYLE_ID3 = "__ag-toolbar-styles__";
|
|
1088
|
-
function createToolbarRenderer(callbacks) {
|
|
1089
|
-
let container = null;
|
|
1090
|
-
let leftGroup = null;
|
|
1091
|
-
let buttons = {};
|
|
1092
|
-
let allElements = /* @__PURE__ */ new Set();
|
|
1093
|
-
function injectStyles2() {
|
|
1094
|
-
if (document.getElementById(STYLE_ID3)) return;
|
|
1095
|
-
const style = document.createElement("style");
|
|
1096
|
-
style.id = STYLE_ID3;
|
|
1097
|
-
style.textContent = `
|
|
1098
|
-
#${TOOLBAR_ID} {
|
|
1099
|
-
position: fixed;
|
|
1100
|
-
bottom: 20px;
|
|
1101
|
-
left: 50%;
|
|
1102
|
-
transform: translateX(-50%);
|
|
1103
|
-
z-index: ${Z_INDEX_TOOLBAR};
|
|
1104
|
-
display: flex;
|
|
1105
|
-
align-items: center;
|
|
1106
|
-
gap: 2px;
|
|
1107
|
-
padding: 4px 6px;
|
|
1108
|
-
background: var(--ag-toolbar-bg, #0f172a);
|
|
1109
|
-
border: 1px solid var(--ag-toolbar-border, #1e293b);
|
|
1110
|
-
border-radius: 24px;
|
|
1111
|
-
box-shadow: 0 4px 16px var(--ag-toolbar-shadow, rgba(0, 0, 0, 0.5));
|
|
1112
|
-
pointer-events: auto;
|
|
1113
|
-
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
1114
|
-
transition: opacity 0.2s ease, transform 0.2s ease;
|
|
1115
|
-
}
|
|
1116
|
-
#${TOOLBAR_ID}.ag-toolbar-hidden {
|
|
1117
|
-
opacity: 0;
|
|
1118
|
-
transform: translateX(-50%) translateY(20px);
|
|
1119
|
-
pointer-events: none;
|
|
1120
|
-
}
|
|
1121
|
-
#${TOOLBAR_ID} button {
|
|
1122
|
-
display: flex;
|
|
1123
|
-
align-items: center;
|
|
1124
|
-
justify-content: center;
|
|
1125
|
-
width: 32px;
|
|
1126
|
-
height: 32px;
|
|
1127
|
-
border: none;
|
|
1128
|
-
border-radius: 8px;
|
|
1129
|
-
background: transparent;
|
|
1130
|
-
color: var(--ag-toolbar-text, #94a3b8);
|
|
1131
|
-
cursor: pointer;
|
|
1132
|
-
padding: 0;
|
|
1133
|
-
transition: background 0.15s ease, color 0.15s ease;
|
|
1134
|
-
}
|
|
1135
|
-
#${TOOLBAR_ID} button:hover {
|
|
1136
|
-
background: var(--ag-toolbar-hover, #1e293b);
|
|
1137
|
-
color: var(--ag-accent, #3b82f6);
|
|
1138
|
-
}
|
|
1139
|
-
#${TOOLBAR_ID} button.ag-btn-active {
|
|
1140
|
-
color: var(--ag-toolbar-active, #3b82f6);
|
|
1141
|
-
}
|
|
1142
|
-
#${TOOLBAR_ID} button.ag-btn-disabled {
|
|
1143
|
-
opacity: 0.4;
|
|
1144
|
-
color: var(--ag-toolbar-text, #94a3b8);
|
|
1145
|
-
}
|
|
1146
|
-
#${TOOLBAR_ID} .ag-toolbar-divider {
|
|
1147
|
-
width: 1px;
|
|
1148
|
-
height: 20px;
|
|
1149
|
-
background: var(--ag-toolbar-border, #1e293b);
|
|
1150
|
-
margin: 0 4px;
|
|
1151
|
-
flex-shrink: 0;
|
|
1152
|
-
}
|
|
1153
|
-
#${TOOLBAR_ID} .ag-toolbar-left {
|
|
1154
|
-
display: flex;
|
|
1155
|
-
align-items: center;
|
|
1156
|
-
gap: 2px;
|
|
1157
|
-
overflow: hidden;
|
|
1158
|
-
max-width: 240px;
|
|
1159
|
-
opacity: 1;
|
|
1160
|
-
transition: max-width 0.25s ease, opacity 0.2s ease, margin 0.25s ease;
|
|
1161
|
-
}
|
|
1162
|
-
#${TOOLBAR_ID} .ag-toolbar-left.ag-toolbar-left-hidden {
|
|
1163
|
-
max-width: 0;
|
|
1164
|
-
opacity: 0;
|
|
1165
|
-
pointer-events: none;
|
|
1166
|
-
}
|
|
1167
|
-
`;
|
|
1168
|
-
document.head.appendChild(style);
|
|
1169
|
-
}
|
|
1170
|
-
function createButton(name, icon, title, onClick) {
|
|
1171
|
-
const btn = document.createElement("button");
|
|
1172
|
-
btn.innerHTML = icon;
|
|
1173
|
-
btn.title = title;
|
|
1174
|
-
btn.setAttribute("aria-label", title);
|
|
1175
|
-
btn.setAttribute("data-ag-btn", name);
|
|
1176
|
-
btn.addEventListener("click", (e) => {
|
|
1177
|
-
e.preventDefault();
|
|
1178
|
-
e.stopPropagation();
|
|
1179
|
-
onClick();
|
|
1180
|
-
});
|
|
1181
|
-
return btn;
|
|
1182
|
-
}
|
|
1183
|
-
function ensureContainer() {
|
|
1184
|
-
if (container) return;
|
|
1185
|
-
injectStyles2();
|
|
1186
|
-
container = document.createElement("div");
|
|
1187
|
-
container.id = TOOLBAR_ID;
|
|
1188
|
-
container.setAttribute("role", "toolbar");
|
|
1189
|
-
container.setAttribute("aria-label", "Angular Grab toolbar");
|
|
1190
|
-
buttons.selection = createButton("selection", ICON_GRAB, "Selection mode", callbacks.onSelectionMode);
|
|
1191
|
-
buttons.history = createButton("history", ICON_HISTORY, "History", callbacks.onHistory);
|
|
1192
|
-
buttons.actions = createButton("actions", ICON_ELLIPSIS, "Actions", callbacks.onActions);
|
|
1193
|
-
buttons.freeze = createButton("freeze", ICON_FREEZE, "Freeze page (F)", callbacks.onFreeze);
|
|
1194
|
-
buttons.theme = createButton("theme", ICON_SUN, "Toggle theme", callbacks.onThemeToggle);
|
|
1195
|
-
buttons.enable = createButton("enable", ICON_POWER, "Enable/Disable", callbacks.onEnableToggle);
|
|
1196
|
-
buttons.dismiss = createButton("dismiss", ICON_DISMISS, "Dismiss toolbar", callbacks.onDismiss);
|
|
1197
|
-
const divider = document.createElement("span");
|
|
1198
|
-
divider.className = "ag-toolbar-divider";
|
|
1199
|
-
leftGroup = document.createElement("div");
|
|
1200
|
-
leftGroup.className = "ag-toolbar-left";
|
|
1201
|
-
leftGroup.appendChild(buttons.selection);
|
|
1202
|
-
leftGroup.appendChild(buttons.history);
|
|
1203
|
-
leftGroup.appendChild(buttons.actions);
|
|
1204
|
-
leftGroup.appendChild(buttons.freeze);
|
|
1205
|
-
leftGroup.appendChild(divider);
|
|
1206
|
-
container.appendChild(leftGroup);
|
|
1207
|
-
container.appendChild(buttons.theme);
|
|
1208
|
-
container.appendChild(buttons.enable);
|
|
1209
|
-
container.appendChild(buttons.dismiss);
|
|
1210
|
-
document.body.appendChild(container);
|
|
1211
|
-
allElements.clear();
|
|
1212
|
-
allElements.add(container);
|
|
1213
|
-
allElements.add(leftGroup);
|
|
1214
|
-
allElements.add(divider);
|
|
1215
|
-
for (const btn of Object.values(buttons)) {
|
|
1216
|
-
allElements.add(btn);
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
return {
|
|
1220
|
-
show() {
|
|
1221
|
-
ensureContainer();
|
|
1222
|
-
container.classList.remove("ag-toolbar-hidden");
|
|
1223
|
-
},
|
|
1224
|
-
hide() {
|
|
1225
|
-
if (container) {
|
|
1226
|
-
container.classList.add("ag-toolbar-hidden");
|
|
1227
|
-
}
|
|
1228
|
-
},
|
|
1229
|
-
update(state) {
|
|
1230
|
-
if (!container) return;
|
|
1231
|
-
if (state.active) {
|
|
1232
|
-
buttons.selection.classList.add("ag-btn-active");
|
|
1233
|
-
} else {
|
|
1234
|
-
buttons.selection.classList.remove("ag-btn-active");
|
|
1235
|
-
}
|
|
1236
|
-
const mode = state.toolbar.themeMode;
|
|
1237
|
-
const themeIcon = mode === "dark" ? ICON_SUN : mode === "light" ? ICON_MOON : ICON_SYSTEM;
|
|
1238
|
-
const themeLabel = mode === "dark" ? "Switch to light mode" : mode === "light" ? "Switch to system theme" : "Switch to dark mode";
|
|
1239
|
-
buttons.theme.innerHTML = themeIcon;
|
|
1240
|
-
buttons.theme.title = themeLabel;
|
|
1241
|
-
buttons.theme.setAttribute("aria-label", themeLabel);
|
|
1242
|
-
if (state.frozen) {
|
|
1243
|
-
buttons.freeze.classList.add("ag-btn-active");
|
|
1244
|
-
} else {
|
|
1245
|
-
buttons.freeze.classList.remove("ag-btn-active");
|
|
1246
|
-
}
|
|
1247
|
-
if (state.options.enabled) {
|
|
1248
|
-
buttons.enable.classList.add("ag-btn-active");
|
|
1249
|
-
leftGroup?.classList.remove("ag-toolbar-left-hidden");
|
|
1250
|
-
} else {
|
|
1251
|
-
buttons.enable.classList.remove("ag-btn-active");
|
|
1252
|
-
leftGroup?.classList.add("ag-toolbar-left-hidden");
|
|
1253
|
-
}
|
|
1254
|
-
},
|
|
1255
|
-
isToolbarElement(el) {
|
|
1256
|
-
if (allElements.has(el)) return true;
|
|
1257
|
-
let current = el;
|
|
1258
|
-
while (current) {
|
|
1259
|
-
if (current === container) return true;
|
|
1260
|
-
if (current.id === TOOLBAR_ID) return true;
|
|
1261
|
-
current = current.parentElement;
|
|
1262
|
-
}
|
|
1263
|
-
return false;
|
|
1264
|
-
},
|
|
1265
|
-
dispose() {
|
|
1266
|
-
container?.remove();
|
|
1267
|
-
document.getElementById(STYLE_ID3)?.remove();
|
|
1268
|
-
container = null;
|
|
1269
|
-
leftGroup = null;
|
|
1270
|
-
buttons = {};
|
|
1271
|
-
allElements.clear();
|
|
1272
|
-
}
|
|
1273
|
-
};
|
|
1274
|
-
}
|
|
1275
|
-
|
|
1276
|
-
// src/core/toolbar/history-popover.ts
|
|
1277
|
-
var POPOVER_ID = "__ag-history-popover__";
|
|
1278
|
-
var STYLE_ID4 = "__ag-history-styles__";
|
|
1279
|
-
function formatRelativeTime(timestamp) {
|
|
1280
|
-
const diff = Date.now() - timestamp;
|
|
1281
|
-
const seconds = Math.floor(diff / 1e3);
|
|
1282
|
-
if (seconds < 60) return "just now";
|
|
1283
|
-
const minutes = Math.floor(seconds / 60);
|
|
1284
|
-
if (minutes < 60) return `${minutes}m ago`;
|
|
1285
|
-
const hours = Math.floor(minutes / 60);
|
|
1286
|
-
if (hours < 24) return `${hours}h ago`;
|
|
1287
|
-
const days = Math.floor(hours / 24);
|
|
1288
|
-
return `${days}d ago`;
|
|
1289
|
-
}
|
|
1290
|
-
function shortPath(filePath) {
|
|
1291
|
-
const parts = filePath.split("/");
|
|
1292
|
-
return parts[parts.length - 1];
|
|
1293
|
-
}
|
|
1294
|
-
function buildVsCodeUri(filePath, line, column) {
|
|
1295
|
-
let uri = `vscode://file/${encodeURI(filePath)}`;
|
|
1296
|
-
if (line != null) uri += `:${line}`;
|
|
1297
|
-
if (line != null && column != null) uri += `:${column}`;
|
|
1298
|
-
return uri;
|
|
1299
|
-
}
|
|
1300
|
-
function createHistoryPopover(callbacks) {
|
|
1301
|
-
let popover = null;
|
|
1302
|
-
let visible = false;
|
|
1303
|
-
function injectStyles2() {
|
|
1304
|
-
if (document.getElementById(STYLE_ID4)) return;
|
|
1305
|
-
const style = document.createElement("style");
|
|
1306
|
-
style.id = STYLE_ID4;
|
|
1307
|
-
style.textContent = `
|
|
1308
|
-
#${POPOVER_ID} {
|
|
1309
|
-
position: fixed;
|
|
1310
|
-
bottom: ${TOOLBAR_POPOVER_OFFSET};
|
|
1311
|
-
left: 50%;
|
|
1312
|
-
transform: translateX(-50%);
|
|
1313
|
-
z-index: ${Z_INDEX_POPOVER};
|
|
1314
|
-
background: var(--ag-popover-bg, #0f172a);
|
|
1315
|
-
border: 1px solid var(--ag-popover-border, #1e293b);
|
|
1316
|
-
border-radius: 12px;
|
|
1317
|
-
box-shadow: 0 8px 24px var(--ag-popover-shadow, rgba(0, 0, 0, 0.5));
|
|
1318
|
-
min-width: 320px;
|
|
1319
|
-
max-width: 420px;
|
|
1320
|
-
max-height: 360px;
|
|
1321
|
-
overflow-y: auto;
|
|
1322
|
-
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
1323
|
-
opacity: 0;
|
|
1324
|
-
visibility: hidden;
|
|
1325
|
-
transition: opacity 0.15s ease, visibility 0.15s ease;
|
|
1326
|
-
pointer-events: auto;
|
|
1327
|
-
}
|
|
1328
|
-
#${POPOVER_ID}.ag-popover-visible {
|
|
1329
|
-
opacity: 1;
|
|
1330
|
-
visibility: visible;
|
|
1331
|
-
}
|
|
1332
|
-
#${POPOVER_ID} .ag-history-header {
|
|
1333
|
-
padding: 10px 14px 8px;
|
|
1334
|
-
font-size: 11px;
|
|
1335
|
-
font-weight: 600;
|
|
1336
|
-
text-transform: uppercase;
|
|
1337
|
-
letter-spacing: 0.05em;
|
|
1338
|
-
color: var(--ag-text-muted, #64748b);
|
|
1339
|
-
border-bottom: 1px solid var(--ag-popover-border, #1e293b);
|
|
1340
|
-
}
|
|
1341
|
-
#${POPOVER_ID} .ag-history-empty {
|
|
1342
|
-
padding: 24px 14px;
|
|
1343
|
-
text-align: center;
|
|
1344
|
-
color: var(--ag-text-muted, #64748b);
|
|
1345
|
-
font-size: 13px;
|
|
1346
|
-
}
|
|
1347
|
-
#${POPOVER_ID} .ag-history-item {
|
|
1348
|
-
display: flex;
|
|
1349
|
-
align-items: center;
|
|
1350
|
-
justify-content: space-between;
|
|
1351
|
-
gap: 12px;
|
|
1352
|
-
padding: 8px 14px;
|
|
1353
|
-
cursor: pointer;
|
|
1354
|
-
border: none;
|
|
1355
|
-
border-bottom: 1px solid var(--ag-popover-border, #1e293b);
|
|
1356
|
-
background: transparent;
|
|
1357
|
-
width: 100%;
|
|
1358
|
-
text-align: left;
|
|
1359
|
-
font: inherit;
|
|
1360
|
-
color: inherit;
|
|
1361
|
-
transition: background 0.1s ease;
|
|
1362
|
-
}
|
|
1363
|
-
#${POPOVER_ID} .ag-history-item:last-child {
|
|
1364
|
-
border-bottom: none;
|
|
1365
|
-
}
|
|
1366
|
-
#${POPOVER_ID} .ag-history-item:hover {
|
|
1367
|
-
background: var(--ag-popover-hover, #1e293b);
|
|
1368
|
-
}
|
|
1369
|
-
#${POPOVER_ID} .ag-history-info {
|
|
1370
|
-
flex: 1;
|
|
1371
|
-
min-width: 0;
|
|
1372
|
-
}
|
|
1373
|
-
#${POPOVER_ID} .ag-history-selector {
|
|
1374
|
-
font: 12px/1.3 ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
|
|
1375
|
-
color: var(--ag-popover-text, #e2e8f0);
|
|
1376
|
-
overflow: hidden;
|
|
1377
|
-
text-overflow: ellipsis;
|
|
1378
|
-
white-space: nowrap;
|
|
1379
|
-
}
|
|
1380
|
-
#${POPOVER_ID} .ag-history-meta {
|
|
1381
|
-
font-size: 11px;
|
|
1382
|
-
color: var(--ag-text-muted, #64748b);
|
|
1383
|
-
margin-top: 2px;
|
|
1384
|
-
overflow: hidden;
|
|
1385
|
-
text-overflow: ellipsis;
|
|
1386
|
-
white-space: nowrap;
|
|
1387
|
-
}
|
|
1388
|
-
#${POPOVER_ID} .ag-history-time {
|
|
1389
|
-
font-size: 11px;
|
|
1390
|
-
color: var(--ag-text-muted, #64748b);
|
|
1391
|
-
flex-shrink: 0;
|
|
1392
|
-
}
|
|
1393
|
-
#${POPOVER_ID} .ag-history-file-link {
|
|
1394
|
-
color: var(--ag-text-muted, #64748b);
|
|
1395
|
-
text-decoration: none;
|
|
1396
|
-
}
|
|
1397
|
-
#${POPOVER_ID} .ag-history-file-link:hover {
|
|
1398
|
-
text-decoration: underline;
|
|
1399
|
-
color: var(--ag-accent, #3b82f6);
|
|
1400
|
-
}
|
|
1401
|
-
`;
|
|
1402
|
-
document.head.appendChild(style);
|
|
1403
|
-
}
|
|
1404
|
-
function ensurePopover() {
|
|
1405
|
-
if (popover) return popover;
|
|
1406
|
-
injectStyles2();
|
|
1407
|
-
popover = document.createElement("div");
|
|
1408
|
-
popover.id = POPOVER_ID;
|
|
1409
|
-
popover.setAttribute("role", "dialog");
|
|
1410
|
-
popover.setAttribute("aria-label", "Grab history");
|
|
1411
|
-
document.body.appendChild(popover);
|
|
1412
|
-
return popover;
|
|
1413
|
-
}
|
|
1414
|
-
function render(entries) {
|
|
1415
|
-
const el = ensurePopover();
|
|
1416
|
-
let html = '<div class="ag-history-header">History</div>';
|
|
1417
|
-
if (entries.length === 0) {
|
|
1418
|
-
html += '<div class="ag-history-empty">No elements grabbed yet</div>';
|
|
1419
|
-
} else {
|
|
1420
|
-
for (const entry of entries) {
|
|
1421
|
-
const selector = escapeHtml(entry.context.selector);
|
|
1422
|
-
const comp = entry.context.componentName ? escapeHtml(entry.context.componentName) : "";
|
|
1423
|
-
const time = formatRelativeTime(entry.timestamp);
|
|
1424
|
-
let meta = comp ? `in ${comp}` : "";
|
|
1425
|
-
if (entry.context.filePath) {
|
|
1426
|
-
const uri = buildVsCodeUri(entry.context.filePath, entry.context.line, entry.context.column);
|
|
1427
|
-
const fileName = escapeHtml(shortPath(entry.context.filePath));
|
|
1428
|
-
const sep = meta ? " \u2014 " : "";
|
|
1429
|
-
meta += `${sep}<a class="ag-history-file-link" href="${escapeHtml(uri)}" title="Open in VS Code">${fileName}</a>`;
|
|
1430
|
-
}
|
|
1431
|
-
html += `<button class="ag-history-item" data-ag-history-id="${escapeHtml(entry.id)}" aria-label="Re-copy ${selector}">`;
|
|
1432
|
-
html += `<div class="ag-history-info">`;
|
|
1433
|
-
html += `<div class="ag-history-selector">${selector}</div>`;
|
|
1434
|
-
if (meta) html += `<div class="ag-history-meta">${meta}</div>`;
|
|
1435
|
-
html += `</div>`;
|
|
1436
|
-
html += `<span class="ag-history-time">${time}</span>`;
|
|
1437
|
-
html += `</button>`;
|
|
1438
|
-
}
|
|
1439
|
-
}
|
|
1440
|
-
el.innerHTML = html;
|
|
1441
|
-
const items = el.querySelectorAll(".ag-history-item");
|
|
1442
|
-
items.forEach((item) => {
|
|
1443
|
-
item.addEventListener("click", (e) => {
|
|
1444
|
-
e.stopPropagation();
|
|
1445
|
-
const id = item.dataset.agHistoryId;
|
|
1446
|
-
const entry = entries.find((ent) => ent.id === id);
|
|
1447
|
-
if (entry) {
|
|
1448
|
-
callbacks.onEntryClick(entry);
|
|
1449
|
-
}
|
|
1450
|
-
});
|
|
1451
|
-
});
|
|
1452
|
-
}
|
|
1453
|
-
return {
|
|
1454
|
-
show(entries) {
|
|
1455
|
-
render(entries);
|
|
1456
|
-
visible = true;
|
|
1457
|
-
void ensurePopover().offsetHeight;
|
|
1458
|
-
ensurePopover().classList.add("ag-popover-visible");
|
|
1459
|
-
},
|
|
1460
|
-
hide() {
|
|
1461
|
-
visible = false;
|
|
1462
|
-
popover?.classList.remove("ag-popover-visible");
|
|
1463
|
-
},
|
|
1464
|
-
isVisible() {
|
|
1465
|
-
return visible;
|
|
1466
|
-
},
|
|
1467
|
-
isPopoverElement(el) {
|
|
1468
|
-
if (!popover) return false;
|
|
1469
|
-
let current = el;
|
|
1470
|
-
while (current) {
|
|
1471
|
-
if (current === popover || current.id === POPOVER_ID) return true;
|
|
1472
|
-
current = current.parentElement;
|
|
1473
|
-
}
|
|
1474
|
-
return false;
|
|
1475
|
-
},
|
|
1476
|
-
dispose() {
|
|
1477
|
-
popover?.remove();
|
|
1478
|
-
document.getElementById(STYLE_ID4)?.remove();
|
|
1479
|
-
popover = null;
|
|
1480
|
-
visible = false;
|
|
1481
|
-
}
|
|
1482
|
-
};
|
|
1483
|
-
}
|
|
1484
|
-
|
|
1485
|
-
// src/core/toolbar/actions-menu.ts
|
|
1486
|
-
var MENU_ID = "__ag-actions-menu__";
|
|
1487
|
-
var STYLE_ID5 = "__ag-actions-styles__";
|
|
1488
|
-
function createActionsMenu(callbacks) {
|
|
1489
|
-
let menu = null;
|
|
1490
|
-
let visible = false;
|
|
1491
|
-
const items = [
|
|
1492
|
-
{ icon: ICON_COPY, label: "Copy Element", action: callbacks.onCopyElement },
|
|
1493
|
-
{ icon: ICON_STYLES, label: "Copy Styles", action: callbacks.onCopyStyles },
|
|
1494
|
-
{ icon: ICON_CODE, label: "Copy HTML", action: callbacks.onCopyHtml },
|
|
1495
|
-
{ icon: ICON_COMMENT, label: "Comment", action: callbacks.onComment },
|
|
1496
|
-
{ separator: true },
|
|
1497
|
-
{ icon: ICON_TRASH, label: "Clear History", action: callbacks.onClearHistory }
|
|
1498
|
-
];
|
|
1499
|
-
function injectStyles2() {
|
|
1500
|
-
if (document.getElementById(STYLE_ID5)) return;
|
|
1501
|
-
const style = document.createElement("style");
|
|
1502
|
-
style.id = STYLE_ID5;
|
|
1503
|
-
style.textContent = `
|
|
1504
|
-
#${MENU_ID} {
|
|
1505
|
-
position: fixed;
|
|
1506
|
-
bottom: ${TOOLBAR_POPOVER_OFFSET};
|
|
1507
|
-
left: 50%;
|
|
1508
|
-
transform: translateX(-50%);
|
|
1509
|
-
z-index: ${Z_INDEX_POPOVER};
|
|
1510
|
-
background: var(--ag-popover-bg, #0f172a);
|
|
1511
|
-
border: 1px solid var(--ag-popover-border, #1e293b);
|
|
1512
|
-
border-radius: 10px;
|
|
1513
|
-
box-shadow: 0 8px 24px var(--ag-popover-shadow, rgba(0, 0, 0, 0.5));
|
|
1514
|
-
min-width: 200px;
|
|
1515
|
-
padding: 4px;
|
|
1516
|
-
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
1517
|
-
opacity: 0;
|
|
1518
|
-
visibility: hidden;
|
|
1519
|
-
transition: opacity 0.15s ease, visibility 0.15s ease;
|
|
1520
|
-
pointer-events: auto;
|
|
1521
|
-
}
|
|
1522
|
-
#${MENU_ID}.ag-menu-visible {
|
|
1523
|
-
opacity: 1;
|
|
1524
|
-
visibility: visible;
|
|
1525
|
-
}
|
|
1526
|
-
#${MENU_ID} .ag-menu-item {
|
|
1527
|
-
display: flex;
|
|
1528
|
-
align-items: center;
|
|
1529
|
-
gap: 10px;
|
|
1530
|
-
padding: 8px 12px;
|
|
1531
|
-
border: none;
|
|
1532
|
-
border-radius: 6px;
|
|
1533
|
-
background: transparent;
|
|
1534
|
-
color: var(--ag-popover-text, #e2e8f0);
|
|
1535
|
-
font-size: 13px;
|
|
1536
|
-
cursor: pointer;
|
|
1537
|
-
width: 100%;
|
|
1538
|
-
text-align: left;
|
|
1539
|
-
transition: background 0.1s ease;
|
|
1540
|
-
}
|
|
1541
|
-
#${MENU_ID} .ag-menu-item:hover {
|
|
1542
|
-
background: var(--ag-popover-hover, #1e293b);
|
|
1543
|
-
}
|
|
1544
|
-
#${MENU_ID} .ag-menu-item svg {
|
|
1545
|
-
flex-shrink: 0;
|
|
1546
|
-
opacity: 0.7;
|
|
1547
|
-
}
|
|
1548
|
-
#${MENU_ID} .ag-menu-sep {
|
|
1549
|
-
height: 1px;
|
|
1550
|
-
background: var(--ag-popover-border, #1e293b);
|
|
1551
|
-
margin: 4px 8px;
|
|
1552
|
-
}
|
|
1553
|
-
`;
|
|
1554
|
-
document.head.appendChild(style);
|
|
1555
|
-
}
|
|
1556
|
-
function ensureMenu() {
|
|
1557
|
-
if (menu) return menu;
|
|
1558
|
-
injectStyles2();
|
|
1559
|
-
menu = document.createElement("div");
|
|
1560
|
-
menu.id = MENU_ID;
|
|
1561
|
-
menu.setAttribute("role", "menu");
|
|
1562
|
-
menu.setAttribute("aria-label", "Actions");
|
|
1563
|
-
for (const entry of items) {
|
|
1564
|
-
if (entry.separator) {
|
|
1565
|
-
const sep = document.createElement("div");
|
|
1566
|
-
sep.className = "ag-menu-sep";
|
|
1567
|
-
menu.appendChild(sep);
|
|
1568
|
-
continue;
|
|
1569
|
-
}
|
|
1570
|
-
const btn = document.createElement("button");
|
|
1571
|
-
btn.className = "ag-menu-item";
|
|
1572
|
-
btn.setAttribute("role", "menuitem");
|
|
1573
|
-
btn.innerHTML = `${entry.icon}<span>${escapeHtml(entry.label)}</span>`;
|
|
1574
|
-
btn.addEventListener("click", (e) => {
|
|
1575
|
-
e.preventDefault();
|
|
1576
|
-
e.stopPropagation();
|
|
1577
|
-
visible = false;
|
|
1578
|
-
menu?.classList.remove("ag-menu-visible");
|
|
1579
|
-
entry.action();
|
|
1580
|
-
});
|
|
1581
|
-
menu.appendChild(btn);
|
|
1582
|
-
}
|
|
1583
|
-
document.body.appendChild(menu);
|
|
1584
|
-
return menu;
|
|
1585
|
-
}
|
|
1586
|
-
return {
|
|
1587
|
-
show() {
|
|
1588
|
-
const el = ensureMenu();
|
|
1589
|
-
visible = true;
|
|
1590
|
-
void el.offsetHeight;
|
|
1591
|
-
el.classList.add("ag-menu-visible");
|
|
1592
|
-
},
|
|
1593
|
-
hide() {
|
|
1594
|
-
visible = false;
|
|
1595
|
-
menu?.classList.remove("ag-menu-visible");
|
|
1596
|
-
},
|
|
1597
|
-
isVisible() {
|
|
1598
|
-
return visible;
|
|
1599
|
-
},
|
|
1600
|
-
isMenuElement(el) {
|
|
1601
|
-
if (!menu) return false;
|
|
1602
|
-
let current = el;
|
|
1603
|
-
while (current) {
|
|
1604
|
-
if (current === menu || current.id === MENU_ID) return true;
|
|
1605
|
-
current = current.parentElement;
|
|
1606
|
-
}
|
|
1607
|
-
return false;
|
|
1608
|
-
},
|
|
1609
|
-
dispose() {
|
|
1610
|
-
menu?.remove();
|
|
1611
|
-
document.getElementById(STYLE_ID5)?.remove();
|
|
1612
|
-
menu = null;
|
|
1613
|
-
visible = false;
|
|
1614
|
-
}
|
|
1615
|
-
};
|
|
1616
|
-
}
|
|
1617
|
-
|
|
1618
|
-
// src/core/toolbar/comment-popover.ts
|
|
1619
|
-
var POPOVER_ID2 = "__ag-comment-popover__";
|
|
1620
|
-
var STYLE_ID6 = "__ag-comment-styles__";
|
|
1621
|
-
function createCommentPopover(callbacks) {
|
|
1622
|
-
let popover = null;
|
|
1623
|
-
let textarea = null;
|
|
1624
|
-
let visible = false;
|
|
1625
|
-
let keydownHandler = null;
|
|
1626
|
-
function injectStyles2() {
|
|
1627
|
-
if (document.getElementById(STYLE_ID6)) return;
|
|
1628
|
-
const style = document.createElement("style");
|
|
1629
|
-
style.id = STYLE_ID6;
|
|
1630
|
-
style.textContent = `
|
|
1631
|
-
#${POPOVER_ID2} {
|
|
1632
|
-
position: fixed;
|
|
1633
|
-
bottom: ${TOOLBAR_POPOVER_OFFSET};
|
|
1634
|
-
left: 50%;
|
|
1635
|
-
transform: translateX(-50%);
|
|
1636
|
-
z-index: ${Z_INDEX_POPOVER};
|
|
1637
|
-
background: var(--ag-popover-bg, #0f172a);
|
|
1638
|
-
border: 1px solid var(--ag-popover-border, #1e293b);
|
|
1639
|
-
border-radius: 12px;
|
|
1640
|
-
box-shadow: 0 8px 24px var(--ag-popover-shadow, rgba(0, 0, 0, 0.5));
|
|
1641
|
-
width: 340px;
|
|
1642
|
-
padding: 14px;
|
|
1643
|
-
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
1644
|
-
opacity: 0;
|
|
1645
|
-
visibility: hidden;
|
|
1646
|
-
transition: opacity 0.15s ease, visibility 0.15s ease;
|
|
1647
|
-
pointer-events: auto;
|
|
1648
|
-
}
|
|
1649
|
-
#${POPOVER_ID2}.ag-comment-visible {
|
|
1650
|
-
opacity: 1;
|
|
1651
|
-
visibility: visible;
|
|
1652
|
-
}
|
|
1653
|
-
#${POPOVER_ID2} textarea {
|
|
1654
|
-
width: 100%;
|
|
1655
|
-
min-height: 80px;
|
|
1656
|
-
padding: 8px 10px;
|
|
1657
|
-
border: 1px solid var(--ag-popover-border, #1e293b);
|
|
1658
|
-
border-radius: 8px;
|
|
1659
|
-
background: var(--ag-surface, #1e293b);
|
|
1660
|
-
color: var(--ag-popover-text, #e2e8f0);
|
|
1661
|
-
font: 13px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
1662
|
-
resize: vertical;
|
|
1663
|
-
outline: none;
|
|
1664
|
-
box-sizing: border-box;
|
|
1665
|
-
}
|
|
1666
|
-
#${POPOVER_ID2} textarea:focus {
|
|
1667
|
-
border-color: var(--ag-accent, #3b82f6);
|
|
1668
|
-
}
|
|
1669
|
-
#${POPOVER_ID2} textarea::placeholder {
|
|
1670
|
-
color: var(--ag-text-muted, #64748b);
|
|
1671
|
-
}
|
|
1672
|
-
#${POPOVER_ID2} .ag-comment-footer {
|
|
1673
|
-
display: flex;
|
|
1674
|
-
justify-content: flex-end;
|
|
1675
|
-
gap: 8px;
|
|
1676
|
-
margin-top: 10px;
|
|
1677
|
-
}
|
|
1678
|
-
#${POPOVER_ID2} .ag-comment-btn {
|
|
1679
|
-
padding: 6px 14px;
|
|
1680
|
-
border: none;
|
|
1681
|
-
border-radius: 6px;
|
|
1682
|
-
font-size: 13px;
|
|
1683
|
-
font-weight: 500;
|
|
1684
|
-
cursor: pointer;
|
|
1685
|
-
transition: background 0.15s ease;
|
|
1686
|
-
}
|
|
1687
|
-
#${POPOVER_ID2} .ag-comment-cancel {
|
|
1688
|
-
background: transparent;
|
|
1689
|
-
color: var(--ag-text-muted, #64748b);
|
|
1690
|
-
}
|
|
1691
|
-
#${POPOVER_ID2} .ag-comment-cancel:hover {
|
|
1692
|
-
background: var(--ag-popover-hover, #1e293b);
|
|
1693
|
-
color: var(--ag-popover-text, #e2e8f0);
|
|
1694
|
-
}
|
|
1695
|
-
#${POPOVER_ID2} .ag-comment-submit {
|
|
1696
|
-
background: var(--ag-accent, #3b82f6);
|
|
1697
|
-
color: #fff;
|
|
1698
|
-
}
|
|
1699
|
-
#${POPOVER_ID2} .ag-comment-submit:hover {
|
|
1700
|
-
background: var(--ag-accent-hover, #2563eb);
|
|
1701
|
-
}
|
|
1702
|
-
`;
|
|
1703
|
-
document.head.appendChild(style);
|
|
1704
|
-
}
|
|
1705
|
-
function ensurePopover() {
|
|
1706
|
-
if (popover) return popover;
|
|
1707
|
-
injectStyles2();
|
|
1708
|
-
popover = document.createElement("div");
|
|
1709
|
-
popover.id = POPOVER_ID2;
|
|
1710
|
-
popover.setAttribute("role", "dialog");
|
|
1711
|
-
popover.setAttribute("aria-label", "Add comment");
|
|
1712
|
-
textarea = document.createElement("textarea");
|
|
1713
|
-
textarea.placeholder = "Add a comment...";
|
|
1714
|
-
textarea.rows = 3;
|
|
1715
|
-
const footer = document.createElement("div");
|
|
1716
|
-
footer.className = "ag-comment-footer";
|
|
1717
|
-
const cancelBtn = document.createElement("button");
|
|
1718
|
-
cancelBtn.className = "ag-comment-btn ag-comment-cancel";
|
|
1719
|
-
cancelBtn.textContent = "Cancel";
|
|
1720
|
-
cancelBtn.addEventListener("click", (e) => {
|
|
1721
|
-
e.preventDefault();
|
|
1722
|
-
e.stopPropagation();
|
|
1723
|
-
doHide();
|
|
1724
|
-
callbacks.onCancel();
|
|
1725
|
-
});
|
|
1726
|
-
const submitBtn = document.createElement("button");
|
|
1727
|
-
submitBtn.className = "ag-comment-btn ag-comment-submit";
|
|
1728
|
-
submitBtn.textContent = "Copy with Comment";
|
|
1729
|
-
submitBtn.addEventListener("click", (e) => {
|
|
1730
|
-
e.preventDefault();
|
|
1731
|
-
e.stopPropagation();
|
|
1732
|
-
const comment = textarea.value.trim();
|
|
1733
|
-
if (comment) {
|
|
1734
|
-
doHide();
|
|
1735
|
-
callbacks.onSubmit(comment);
|
|
1736
|
-
} else {
|
|
1737
|
-
textarea.style.borderColor = "var(--ag-accent, #3b82f6)";
|
|
1738
|
-
textarea.setAttribute("placeholder", "Please enter a comment...");
|
|
1739
|
-
textarea.focus();
|
|
1740
|
-
setTimeout(() => {
|
|
1741
|
-
if (textarea) {
|
|
1742
|
-
textarea.style.borderColor = "";
|
|
1743
|
-
textarea.setAttribute("placeholder", "Add a comment...");
|
|
1744
|
-
}
|
|
1745
|
-
}, 2e3);
|
|
1746
|
-
}
|
|
1747
|
-
});
|
|
1748
|
-
footer.appendChild(cancelBtn);
|
|
1749
|
-
footer.appendChild(submitBtn);
|
|
1750
|
-
popover.appendChild(textarea);
|
|
1751
|
-
popover.appendChild(footer);
|
|
1752
|
-
document.body.appendChild(popover);
|
|
1753
|
-
return popover;
|
|
1754
|
-
}
|
|
1755
|
-
function attachKeydownInterceptor() {
|
|
1756
|
-
if (keydownHandler) return;
|
|
1757
|
-
keydownHandler = (e) => {
|
|
1758
|
-
if (textarea && document.activeElement === textarea) {
|
|
1759
|
-
e.stopImmediatePropagation();
|
|
1760
|
-
if (e.key === "Escape") {
|
|
1761
|
-
doHide();
|
|
1762
|
-
callbacks.onCancel();
|
|
1763
|
-
}
|
|
1764
|
-
}
|
|
1765
|
-
};
|
|
1766
|
-
document.addEventListener("keydown", keydownHandler, true);
|
|
1767
|
-
}
|
|
1768
|
-
function detachKeydownInterceptor() {
|
|
1769
|
-
if (keydownHandler) {
|
|
1770
|
-
document.removeEventListener("keydown", keydownHandler, true);
|
|
1771
|
-
keydownHandler = null;
|
|
1772
|
-
}
|
|
1773
|
-
}
|
|
1774
|
-
function doHide() {
|
|
1775
|
-
visible = false;
|
|
1776
|
-
popover?.classList.remove("ag-comment-visible");
|
|
1777
|
-
detachKeydownInterceptor();
|
|
1778
|
-
}
|
|
1779
|
-
return {
|
|
1780
|
-
show() {
|
|
1781
|
-
const el = ensurePopover();
|
|
1782
|
-
textarea.value = "";
|
|
1783
|
-
visible = true;
|
|
1784
|
-
void el.offsetHeight;
|
|
1785
|
-
el.classList.add("ag-comment-visible");
|
|
1786
|
-
attachKeydownInterceptor();
|
|
1787
|
-
requestAnimationFrame(() => textarea?.focus());
|
|
1788
|
-
},
|
|
1789
|
-
hide() {
|
|
1790
|
-
doHide();
|
|
1791
|
-
},
|
|
1792
|
-
isVisible() {
|
|
1793
|
-
return visible;
|
|
1794
|
-
},
|
|
1795
|
-
isPopoverElement(el) {
|
|
1796
|
-
if (!popover) return false;
|
|
1797
|
-
let current = el;
|
|
1798
|
-
while (current) {
|
|
1799
|
-
if (current === popover || current.id === POPOVER_ID2) return true;
|
|
1800
|
-
current = current.parentElement;
|
|
1801
|
-
}
|
|
1802
|
-
return false;
|
|
1803
|
-
},
|
|
1804
|
-
dispose() {
|
|
1805
|
-
detachKeydownInterceptor();
|
|
1806
|
-
popover?.remove();
|
|
1807
|
-
document.getElementById(STYLE_ID6)?.remove();
|
|
1808
|
-
popover = null;
|
|
1809
|
-
textarea = null;
|
|
1810
|
-
visible = false;
|
|
1811
|
-
}
|
|
1812
|
-
};
|
|
1813
|
-
}
|
|
1814
|
-
|
|
1815
|
-
// src/core/toolbar/copy-actions.ts
|
|
1816
|
-
async function copyElementSnippet(context, maxLines, pluginRegistry) {
|
|
1817
|
-
let snippet = generateSnippet(context, maxLines);
|
|
1818
|
-
if (pluginRegistry) {
|
|
1819
|
-
snippet = pluginRegistry.callTransformHook(snippet, context);
|
|
1820
|
-
}
|
|
1821
|
-
const ok = await writeAndToast(snippet, "Copied to clipboard", context);
|
|
1822
|
-
if (ok) pluginRegistry?.callHook("onCopySuccess", snippet, context, void 0);
|
|
1823
|
-
return ok;
|
|
1824
|
-
}
|
|
1825
|
-
async function copyElementHtml(context, pluginRegistry) {
|
|
1826
|
-
const cleaned = cleanAngularAttrs(context.html);
|
|
1827
|
-
const ok = await writeAndToast(cleaned, "HTML copied to clipboard", context);
|
|
1828
|
-
if (ok) pluginRegistry?.callHook("onCopySuccess", cleaned, context, void 0);
|
|
1829
|
-
return ok;
|
|
1830
|
-
}
|
|
1831
|
-
async function copyElementStyles(element) {
|
|
1832
|
-
if (!element.isConnected) {
|
|
1833
|
-
showToast("Element is no longer on the page");
|
|
1834
|
-
return false;
|
|
1835
|
-
}
|
|
1836
|
-
const computed = window.getComputedStyle(element);
|
|
1837
|
-
const tag = element.tagName.toLowerCase();
|
|
1838
|
-
const lines = [`/* Computed styles for <${tag}> */`, `${tag} {`];
|
|
1839
|
-
const props = [
|
|
1840
|
-
"display",
|
|
1841
|
-
"position",
|
|
1842
|
-
"top",
|
|
1843
|
-
"right",
|
|
1844
|
-
"bottom",
|
|
1845
|
-
"left",
|
|
1846
|
-
"width",
|
|
1847
|
-
"height",
|
|
1848
|
-
"min-width",
|
|
1849
|
-
"min-height",
|
|
1850
|
-
"max-width",
|
|
1851
|
-
"max-height",
|
|
1852
|
-
"margin",
|
|
1853
|
-
"padding",
|
|
1854
|
-
"border",
|
|
1855
|
-
"border-radius",
|
|
1856
|
-
"background",
|
|
1857
|
-
"background-color",
|
|
1858
|
-
"color",
|
|
1859
|
-
"font",
|
|
1860
|
-
"font-size",
|
|
1861
|
-
"font-weight",
|
|
1862
|
-
"font-family",
|
|
1863
|
-
"line-height",
|
|
1864
|
-
"text-align",
|
|
1865
|
-
"text-decoration",
|
|
1866
|
-
"text-transform",
|
|
1867
|
-
"opacity",
|
|
1868
|
-
"overflow",
|
|
1869
|
-
"z-index",
|
|
1870
|
-
"flex-direction",
|
|
1871
|
-
"justify-content",
|
|
1872
|
-
"align-items",
|
|
1873
|
-
"gap",
|
|
1874
|
-
"grid-template-columns",
|
|
1875
|
-
"grid-template-rows",
|
|
1876
|
-
"box-shadow",
|
|
1877
|
-
"cursor",
|
|
1878
|
-
"transition",
|
|
1879
|
-
"transform"
|
|
1880
|
-
];
|
|
1881
|
-
for (const prop of props) {
|
|
1882
|
-
const value = computed.getPropertyValue(prop);
|
|
1883
|
-
if (value && value !== "none" && value !== "normal" && value !== "auto" && value !== "0px" && value !== "visible") {
|
|
1884
|
-
lines.push(` ${prop}: ${value};`);
|
|
1885
|
-
}
|
|
1886
|
-
}
|
|
1887
|
-
lines.push("}");
|
|
1888
|
-
const css = lines.join("\n");
|
|
1889
|
-
return writeAndToast(css, "Styles copied to clipboard");
|
|
1890
|
-
}
|
|
1891
|
-
async function copyWithComment(context, comment, maxLines, pluginRegistry) {
|
|
1892
|
-
let snippet = generateSnippet(context, maxLines);
|
|
1893
|
-
if (pluginRegistry) {
|
|
1894
|
-
snippet = pluginRegistry.callTransformHook(snippet, context);
|
|
1895
|
-
}
|
|
1896
|
-
const full = `${snippet}
|
|
1897
|
-
|
|
1898
|
-
/* Comment: ${comment} */`;
|
|
1899
|
-
const ok = await writeAndToast(full, "Copied with comment", context);
|
|
1900
|
-
if (ok) pluginRegistry?.callHook("onCopySuccess", full, context, comment);
|
|
1901
|
-
return ok;
|
|
1902
|
-
}
|
|
1903
|
-
async function writeAndToast(text, message, context) {
|
|
1904
|
-
try {
|
|
1905
|
-
await navigator.clipboard.writeText(text);
|
|
1906
|
-
showToast(message, context ? {
|
|
1907
|
-
componentName: context.componentName,
|
|
1908
|
-
filePath: context.filePath,
|
|
1909
|
-
line: context.line,
|
|
1910
|
-
column: context.column,
|
|
1911
|
-
cssClasses: context.cssClasses
|
|
1912
|
-
} : void 0);
|
|
1913
|
-
return true;
|
|
1914
|
-
} catch {
|
|
1915
|
-
return false;
|
|
1916
|
-
}
|
|
1917
|
-
}
|
|
1918
|
-
|
|
1919
|
-
// src/core/overlay/freeze-overlay.ts
|
|
1920
|
-
var FREEZE_ID = "__ag-freeze-overlay__";
|
|
1921
|
-
var FREEZE_STYLE_ID = "__ag-freeze-styles__";
|
|
1922
|
-
var HOVER_STYLE_ID = "__ag-freeze-hover-styles__";
|
|
1923
|
-
var ANIM_STYLE_ID = "__ag-freeze-anim-styles__";
|
|
1924
|
-
var HOVER_ATTR = "data-ag-hover";
|
|
1925
|
-
var MOUSE_EVENTS_TO_BLOCK = [
|
|
1926
|
-
"mouseenter",
|
|
1927
|
-
"mouseleave",
|
|
1928
|
-
"mouseover",
|
|
1929
|
-
"mouseout",
|
|
1930
|
-
"pointerenter",
|
|
1931
|
-
"pointerleave",
|
|
1932
|
-
"pointerover",
|
|
1933
|
-
"pointerout"
|
|
1934
|
-
];
|
|
1935
|
-
var FOCUS_EVENTS_TO_BLOCK = ["focus", "blur", "focusin", "focusout"];
|
|
1936
|
-
function createFreezeOverlay() {
|
|
1937
|
-
let overlay = null;
|
|
1938
|
-
let visible = false;
|
|
1939
|
-
let hoverStyleEl = null;
|
|
1940
|
-
let animStyleEl = null;
|
|
1941
|
-
let markedElements = [];
|
|
1942
|
-
function injectStyles2() {
|
|
1943
|
-
if (document.getElementById(FREEZE_STYLE_ID)) return;
|
|
1944
|
-
const style = document.createElement("style");
|
|
1945
|
-
style.id = FREEZE_STYLE_ID;
|
|
1946
|
-
style.textContent = `
|
|
1947
|
-
#${FREEZE_ID} {
|
|
1948
|
-
position: fixed;
|
|
1949
|
-
top: 0;
|
|
1950
|
-
left: 0;
|
|
1951
|
-
width: 100vw;
|
|
1952
|
-
height: 100vh;
|
|
1953
|
-
z-index: ${Z_INDEX_FREEZE};
|
|
1954
|
-
pointer-events: auto;
|
|
1955
|
-
background: transparent;
|
|
1956
|
-
}
|
|
1957
|
-
`;
|
|
1958
|
-
document.head.appendChild(style);
|
|
1959
|
-
}
|
|
1960
|
-
function ensureOverlay() {
|
|
1961
|
-
if (overlay) return overlay;
|
|
1962
|
-
injectStyles2();
|
|
1963
|
-
overlay = document.createElement("div");
|
|
1964
|
-
overlay.id = FREEZE_ID;
|
|
1965
|
-
overlay.style.display = "none";
|
|
1966
|
-
document.body.appendChild(overlay);
|
|
1967
|
-
return overlay;
|
|
1968
|
-
}
|
|
1969
|
-
const stopEvent = (e) => {
|
|
1970
|
-
e.stopImmediatePropagation();
|
|
1971
|
-
};
|
|
1972
|
-
const preventFocusChange = (e) => {
|
|
1973
|
-
e.preventDefault();
|
|
1974
|
-
e.stopImmediatePropagation();
|
|
1975
|
-
};
|
|
1976
|
-
function blockEvents() {
|
|
1977
|
-
for (const type of MOUSE_EVENTS_TO_BLOCK) {
|
|
1978
|
-
document.addEventListener(type, stopEvent, true);
|
|
1979
|
-
}
|
|
1980
|
-
for (const type of FOCUS_EVENTS_TO_BLOCK) {
|
|
1981
|
-
document.addEventListener(type, preventFocusChange, true);
|
|
1982
|
-
}
|
|
1983
|
-
}
|
|
1984
|
-
function unblockEvents() {
|
|
1985
|
-
for (const type of MOUSE_EVENTS_TO_BLOCK) {
|
|
1986
|
-
document.removeEventListener(type, stopEvent, true);
|
|
1987
|
-
}
|
|
1988
|
-
for (const type of FOCUS_EVENTS_TO_BLOCK) {
|
|
1989
|
-
document.removeEventListener(type, preventFocusChange, true);
|
|
1990
|
-
}
|
|
1991
|
-
}
|
|
1992
|
-
function markHoverChain(element) {
|
|
1993
|
-
let current = element;
|
|
1994
|
-
while (current && current !== document.documentElement) {
|
|
1995
|
-
current.setAttribute(HOVER_ATTR, "");
|
|
1996
|
-
markedElements.push(current);
|
|
1997
|
-
current = current.parentElement;
|
|
1998
|
-
}
|
|
1999
|
-
}
|
|
2000
|
-
function clearHoverMarks() {
|
|
2001
|
-
for (const el of markedElements) {
|
|
2002
|
-
el.removeAttribute(HOVER_ATTR);
|
|
2003
|
-
}
|
|
2004
|
-
markedElements = [];
|
|
2005
|
-
}
|
|
2006
|
-
function injectHoverRules() {
|
|
2007
|
-
if (hoverStyleEl) return;
|
|
2008
|
-
const cloned = [];
|
|
2009
|
-
for (const sheet of Array.from(document.styleSheets)) {
|
|
2010
|
-
let rules;
|
|
2011
|
-
try {
|
|
2012
|
-
rules = sheet.cssRules;
|
|
2013
|
-
} catch {
|
|
2014
|
-
continue;
|
|
2015
|
-
}
|
|
2016
|
-
collectHoverRules(rules, cloned);
|
|
2017
|
-
}
|
|
2018
|
-
if (cloned.length === 0) return;
|
|
2019
|
-
hoverStyleEl = document.createElement("style");
|
|
2020
|
-
hoverStyleEl.id = HOVER_STYLE_ID;
|
|
2021
|
-
hoverStyleEl.textContent = cloned.join("\n");
|
|
2022
|
-
document.head.appendChild(hoverStyleEl);
|
|
2023
|
-
}
|
|
2024
|
-
function collectHoverRules(rules, out) {
|
|
2025
|
-
for (const rule of Array.from(rules)) {
|
|
2026
|
-
if (rule instanceof CSSStyleRule) {
|
|
2027
|
-
if (rule.selectorText.includes(":hover")) {
|
|
2028
|
-
const newSelector = rule.selectorText.replace(/:hover/g, `[${HOVER_ATTR}]`);
|
|
2029
|
-
out.push(`${newSelector} { ${rule.style.cssText} }`);
|
|
2030
|
-
}
|
|
2031
|
-
} else if (rule instanceof CSSMediaRule) {
|
|
2032
|
-
const inner = [];
|
|
2033
|
-
collectHoverRules(rule.cssRules, inner);
|
|
2034
|
-
if (inner.length > 0) {
|
|
2035
|
-
out.push(`@media ${rule.conditionText} { ${inner.join("\n")} }`);
|
|
2036
|
-
}
|
|
2037
|
-
}
|
|
2038
|
-
}
|
|
2039
|
-
}
|
|
2040
|
-
function removeHoverRules() {
|
|
2041
|
-
hoverStyleEl?.remove();
|
|
2042
|
-
hoverStyleEl = null;
|
|
2043
|
-
}
|
|
2044
|
-
function freezeAnimations() {
|
|
2045
|
-
if (animStyleEl) return;
|
|
2046
|
-
animStyleEl = document.createElement("style");
|
|
2047
|
-
animStyleEl.id = ANIM_STYLE_ID;
|
|
2048
|
-
animStyleEl.textContent = `
|
|
2049
|
-
*, *::before, *::after {
|
|
2050
|
-
animation-play-state: paused !important;
|
|
2051
|
-
transition: none !important;
|
|
2052
|
-
}
|
|
2053
|
-
`;
|
|
2054
|
-
document.head.appendChild(animStyleEl);
|
|
2055
|
-
}
|
|
2056
|
-
function unfreezeAnimations() {
|
|
2057
|
-
animStyleEl?.remove();
|
|
2058
|
-
animStyleEl = null;
|
|
2059
|
-
}
|
|
2060
|
-
return {
|
|
2061
|
-
show(hoveredElement) {
|
|
2062
|
-
blockEvents();
|
|
2063
|
-
if (hoveredElement) {
|
|
2064
|
-
markHoverChain(hoveredElement);
|
|
2065
|
-
injectHoverRules();
|
|
2066
|
-
}
|
|
2067
|
-
freezeAnimations();
|
|
2068
|
-
const el = ensureOverlay();
|
|
2069
|
-
el.style.display = "block";
|
|
2070
|
-
visible = true;
|
|
2071
|
-
},
|
|
2072
|
-
hide() {
|
|
2073
|
-
if (overlay) overlay.style.display = "none";
|
|
2074
|
-
visible = false;
|
|
2075
|
-
clearHoverMarks();
|
|
2076
|
-
removeHoverRules();
|
|
2077
|
-
unfreezeAnimations();
|
|
2078
|
-
unblockEvents();
|
|
2079
|
-
},
|
|
2080
|
-
isVisible() {
|
|
2081
|
-
return visible;
|
|
2082
|
-
},
|
|
2083
|
-
isFreezeElement(el) {
|
|
2084
|
-
return el === overlay || el.id === FREEZE_ID;
|
|
2085
|
-
},
|
|
2086
|
-
getElement() {
|
|
2087
|
-
return overlay;
|
|
2088
|
-
},
|
|
2089
|
-
dispose() {
|
|
2090
|
-
clearHoverMarks();
|
|
2091
|
-
removeHoverRules();
|
|
2092
|
-
unfreezeAnimations();
|
|
2093
|
-
unblockEvents();
|
|
2094
|
-
overlay?.remove();
|
|
2095
|
-
document.getElementById(FREEZE_STYLE_ID)?.remove();
|
|
2096
|
-
overlay = null;
|
|
2097
|
-
visible = false;
|
|
2098
|
-
}
|
|
2099
|
-
};
|
|
2100
|
-
}
|
|
2101
|
-
|
|
2102
|
-
// src/core/overlay/select-feedback.ts
|
|
2103
|
-
var STYLE_ID7 = "__ag-feedback-styles__";
|
|
2104
|
-
function injectStyles() {
|
|
2105
|
-
if (document.getElementById(STYLE_ID7)) return;
|
|
2106
|
-
const style = document.createElement("style");
|
|
2107
|
-
style.id = STYLE_ID7;
|
|
2108
|
-
style.textContent = `
|
|
2109
|
-
@keyframes ag-flash {
|
|
2110
|
-
0% { opacity: 1; }
|
|
2111
|
-
100% { opacity: 0; transform: scale(1.02); }
|
|
2112
|
-
}
|
|
2113
|
-
@keyframes ag-pill-in {
|
|
2114
|
-
0% { opacity: 0; transform: translateY(4px) scale(0.9); }
|
|
2115
|
-
30% { opacity: 1; transform: translateY(0) scale(1); }
|
|
2116
|
-
70% { opacity: 1; transform: translateY(0) scale(1); }
|
|
2117
|
-
100% { opacity: 0; transform: translateY(-8px) scale(0.95); }
|
|
2118
|
-
}
|
|
2119
|
-
.ag-select-flash {
|
|
2120
|
-
position: fixed;
|
|
2121
|
-
pointer-events: none;
|
|
2122
|
-
z-index: ${Z_INDEX_OVERLAY};
|
|
2123
|
-
border: 2px solid #22c55e;
|
|
2124
|
-
background: rgba(34, 197, 94, 0.12);
|
|
2125
|
-
border-radius: 3px;
|
|
2126
|
-
box-sizing: border-box;
|
|
2127
|
-
animation: ag-flash 0.45s ease-out forwards;
|
|
2128
|
-
}
|
|
2129
|
-
.ag-select-pill {
|
|
2130
|
-
position: fixed;
|
|
2131
|
-
pointer-events: none;
|
|
2132
|
-
z-index: ${Z_INDEX_LABEL};
|
|
2133
|
-
display: flex;
|
|
2134
|
-
align-items: center;
|
|
2135
|
-
gap: 4px;
|
|
2136
|
-
background: #22c55e;
|
|
2137
|
-
color: #fff;
|
|
2138
|
-
font: 600 10px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
2139
|
-
padding: 3px 8px;
|
|
2140
|
-
border-radius: 10px;
|
|
2141
|
-
white-space: nowrap;
|
|
2142
|
-
letter-spacing: 0.03em;
|
|
2143
|
-
text-transform: uppercase;
|
|
2144
|
-
box-shadow: 0 2px 8px rgba(34, 197, 94, 0.35);
|
|
2145
|
-
animation: ag-pill-in 0.9s ease-out forwards;
|
|
2146
|
-
}
|
|
2147
|
-
.ag-select-pill svg {
|
|
2148
|
-
width: 10px;
|
|
2149
|
-
height: 10px;
|
|
2150
|
-
flex-shrink: 0;
|
|
2151
|
-
}
|
|
2152
|
-
`;
|
|
2153
|
-
document.head.appendChild(style);
|
|
2154
|
-
}
|
|
2155
|
-
var CHECK_SVG = `<svg viewBox="0 0 10 10" fill="none"><path d="M2 5.5l2 2 4-4" stroke="#fff" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
|
|
2156
|
-
function showSelectFeedback(element) {
|
|
2157
|
-
injectStyles();
|
|
2158
|
-
const rect = element.getBoundingClientRect();
|
|
2159
|
-
const flash = document.createElement("div");
|
|
2160
|
-
flash.className = "ag-select-flash";
|
|
2161
|
-
flash.style.top = `${rect.top}px`;
|
|
2162
|
-
flash.style.left = `${rect.left}px`;
|
|
2163
|
-
flash.style.width = `${rect.width}px`;
|
|
2164
|
-
flash.style.height = `${rect.height}px`;
|
|
2165
|
-
document.body.appendChild(flash);
|
|
2166
|
-
const pill = document.createElement("div");
|
|
2167
|
-
pill.className = "ag-select-pill";
|
|
2168
|
-
pill.innerHTML = `${CHECK_SVG} Copied`;
|
|
2169
|
-
document.body.appendChild(pill);
|
|
2170
|
-
const pillWidth = 70;
|
|
2171
|
-
let pillLeft = rect.left + rect.width / 2 - pillWidth / 2;
|
|
2172
|
-
let pillTop = rect.top - 24;
|
|
2173
|
-
if (pillTop < 4) {
|
|
2174
|
-
pillTop = rect.bottom + 6;
|
|
2175
|
-
}
|
|
2176
|
-
const vw = document.documentElement.clientWidth;
|
|
2177
|
-
if (pillLeft + pillWidth > vw - 4) pillLeft = vw - pillWidth - 4;
|
|
2178
|
-
if (pillLeft < 4) pillLeft = 4;
|
|
2179
|
-
pill.style.top = `${pillTop}px`;
|
|
2180
|
-
pill.style.left = `${pillLeft}px`;
|
|
2181
|
-
const cleanup = () => {
|
|
2182
|
-
flash.remove();
|
|
2183
|
-
pill.remove();
|
|
2184
|
-
};
|
|
2185
|
-
pill.addEventListener("animationend", cleanup);
|
|
2186
|
-
setTimeout(cleanup, 1200);
|
|
2187
|
-
}
|
|
2188
|
-
function disposeFeedbackStyles() {
|
|
2189
|
-
document.getElementById(STYLE_ID7)?.remove();
|
|
2190
|
-
}
|
|
2191
|
-
|
|
2192
|
-
// src/core/grab.ts
|
|
2193
|
-
var MAX_HISTORY = 50;
|
|
2194
|
-
function toHistoryContext(ctx) {
|
|
2195
|
-
return {
|
|
2196
|
-
html: ctx.html,
|
|
2197
|
-
componentName: ctx.componentName,
|
|
2198
|
-
filePath: ctx.filePath,
|
|
2199
|
-
line: ctx.line,
|
|
2200
|
-
column: ctx.column,
|
|
2201
|
-
componentStack: ctx.componentStack,
|
|
2202
|
-
selector: ctx.selector,
|
|
2203
|
-
cssClasses: ctx.cssClasses
|
|
2204
|
-
};
|
|
2205
|
-
}
|
|
2206
|
-
function getDefaultOptions() {
|
|
2207
|
-
return {
|
|
2208
|
-
activationKey: isMac() ? "Meta+C" : "Ctrl+C",
|
|
2209
|
-
activationMode: "hold",
|
|
2210
|
-
keyHoldDuration: 0,
|
|
2211
|
-
maxContextLines: 20,
|
|
2212
|
-
enabled: true,
|
|
2213
|
-
enableInInputs: false,
|
|
2214
|
-
devOnly: true,
|
|
2215
|
-
showToolbar: true,
|
|
2216
|
-
themeMode: "dark"
|
|
2217
|
-
};
|
|
2218
|
-
}
|
|
2219
|
-
function init(options) {
|
|
2220
|
-
return createGrabInstance(options);
|
|
2221
|
-
}
|
|
2222
|
-
function isDevMode() {
|
|
2223
|
-
try {
|
|
2224
|
-
const ng = globalThis.ngDevMode;
|
|
2225
|
-
return typeof ng === "undefined" || !!ng;
|
|
2226
|
-
} catch {
|
|
2227
|
-
return true;
|
|
2228
|
-
}
|
|
2229
|
-
}
|
|
2230
|
-
function createNoopApi() {
|
|
2231
|
-
const noop = () => {
|
|
2232
|
-
};
|
|
2233
|
-
return {
|
|
2234
|
-
activate: noop,
|
|
2235
|
-
deactivate: noop,
|
|
2236
|
-
toggle: noop,
|
|
2237
|
-
isActive: () => false,
|
|
2238
|
-
setOptions: noop,
|
|
2239
|
-
registerPlugin: noop,
|
|
2240
|
-
unregisterPlugin: noop,
|
|
2241
|
-
setComponentResolver: noop,
|
|
2242
|
-
setSourceResolver: noop,
|
|
2243
|
-
showToolbar: noop,
|
|
2244
|
-
hideToolbar: noop,
|
|
2245
|
-
setThemeMode: noop,
|
|
2246
|
-
getHistory: () => [],
|
|
2247
|
-
clearHistory: noop,
|
|
2248
|
-
dispose: noop
|
|
2249
|
-
};
|
|
2250
|
-
}
|
|
2251
|
-
function createGrabInstance(options) {
|
|
2252
|
-
const defaults = getDefaultOptions();
|
|
2253
|
-
const merged = { ...defaults, ...options };
|
|
2254
|
-
if (merged.devOnly && !isDevMode()) {
|
|
2255
|
-
return createNoopApi();
|
|
2256
|
-
}
|
|
2257
|
-
const store = createStore(merged);
|
|
2258
|
-
const overlay = createOverlayRenderer();
|
|
2259
|
-
const crosshair = createCrosshair();
|
|
2260
|
-
const freezeOverlay = createFreezeOverlay();
|
|
2261
|
-
const pluginRegistry = createPluginRegistry();
|
|
2262
|
-
const themeManager = createThemeManager();
|
|
2263
|
-
let componentResolver = null;
|
|
2264
|
-
let sourceResolver = null;
|
|
2265
|
-
let lastSelectedElement = null;
|
|
2266
|
-
let lastSelectedContext = null;
|
|
2267
|
-
let idCounter = 0;
|
|
2268
|
-
function nextId() {
|
|
2269
|
-
return `ag-${++idCounter}-${Date.now()}`;
|
|
2270
|
-
}
|
|
2271
|
-
themeManager.apply(store.state.toolbar.themeMode);
|
|
2272
|
-
updateToastOffset();
|
|
2273
|
-
function isAnyToolbarElement(el) {
|
|
2274
|
-
return toolbar.isToolbarElement(el) || historyPopover.isPopoverElement(el) || actionsMenu.isMenuElement(el) || commentPopover.isPopoverElement(el) || freezeOverlay.isFreezeElement(el);
|
|
2275
|
-
}
|
|
2276
|
-
function addHistoryEntry(context, snippet) {
|
|
2277
|
-
const entry = {
|
|
2278
|
-
id: nextId(),
|
|
2279
|
-
context: toHistoryContext(context),
|
|
2280
|
-
snippet,
|
|
2281
|
-
timestamp: Date.now()
|
|
2282
|
-
};
|
|
2283
|
-
lastSelectedElement = new WeakRef(context.element);
|
|
2284
|
-
lastSelectedContext = context;
|
|
2285
|
-
const history = [entry, ...store.state.toolbar.history].slice(0, MAX_HISTORY);
|
|
2286
|
-
store.state.toolbar = { ...store.state.toolbar, history };
|
|
2287
|
-
}
|
|
2288
|
-
function getLastSelectedElement() {
|
|
2289
|
-
const el = lastSelectedElement?.deref() ?? null;
|
|
2290
|
-
if (el && !el.isConnected) {
|
|
2291
|
-
lastSelectedElement = null;
|
|
2292
|
-
lastSelectedContext = null;
|
|
2293
|
-
return null;
|
|
2294
|
-
}
|
|
2295
|
-
return el;
|
|
2296
|
-
}
|
|
2297
|
-
function closeAllPopovers() {
|
|
2298
|
-
historyPopover.hide();
|
|
2299
|
-
actionsMenu.hide();
|
|
2300
|
-
commentPopover.hide();
|
|
2301
|
-
}
|
|
2302
|
-
async function executePendingAction(pending, element) {
|
|
2303
|
-
const context = buildElementContext(element, componentResolver, sourceResolver);
|
|
2304
|
-
const maxLines = store.state.options.maxContextLines;
|
|
2305
|
-
lastSelectedElement = new WeakRef(element);
|
|
2306
|
-
lastSelectedContext = context;
|
|
2307
|
-
store.state.toolbar = { ...store.state.toolbar, pendingAction: null };
|
|
2308
|
-
switch (pending.type) {
|
|
2309
|
-
case "copy-element": {
|
|
2310
|
-
const ok = await copyElementSnippet(context, maxLines, pluginRegistry);
|
|
2311
|
-
if (ok) {
|
|
2312
|
-
showSelectFeedback(element);
|
|
2313
|
-
addHistoryEntry(context, "");
|
|
2314
|
-
}
|
|
2315
|
-
break;
|
|
2316
|
-
}
|
|
2317
|
-
case "copy-styles":
|
|
2318
|
-
await copyElementStyles(element);
|
|
2319
|
-
break;
|
|
2320
|
-
case "copy-html":
|
|
2321
|
-
await copyElementHtml(context, pluginRegistry);
|
|
2322
|
-
break;
|
|
2323
|
-
case "comment":
|
|
2324
|
-
commentPopover.show();
|
|
2325
|
-
return;
|
|
2326
|
-
}
|
|
2327
|
-
}
|
|
2328
|
-
const picker = createElementPicker({
|
|
2329
|
-
overlay,
|
|
2330
|
-
crosshair,
|
|
2331
|
-
getComponentResolver: () => componentResolver,
|
|
2332
|
-
getSourceResolver: () => sourceResolver,
|
|
2333
|
-
isToolbarElement: isAnyToolbarElement,
|
|
2334
|
-
getFreezeElement: () => freezeOverlay.getElement(),
|
|
2335
|
-
onHover(element) {
|
|
2336
|
-
store.state.hoveredElement = element;
|
|
2337
|
-
if (element) {
|
|
2338
|
-
pluginRegistry.callHook("onElementHover", element);
|
|
2339
|
-
}
|
|
2340
|
-
},
|
|
2341
|
-
async onSelect(element) {
|
|
2342
|
-
const pending = store.state.toolbar.pendingAction;
|
|
2343
|
-
if (pending) {
|
|
2344
|
-
await executePendingAction(pending, element);
|
|
2345
|
-
if (pending.type !== "comment") {
|
|
2346
|
-
doDeactivate();
|
|
2347
|
-
}
|
|
2348
|
-
return;
|
|
2349
|
-
}
|
|
2350
|
-
const result = await copyElement(element, {
|
|
2351
|
-
getComponentResolver: () => componentResolver,
|
|
2352
|
-
getSourceResolver: () => sourceResolver,
|
|
2353
|
-
getMaxContextLines: () => store.state.options.maxContextLines,
|
|
2354
|
-
pluginRegistry
|
|
2355
|
-
});
|
|
2356
|
-
if (result) {
|
|
2357
|
-
showSelectFeedback(element);
|
|
2358
|
-
addHistoryEntry(result.context, result.snippet);
|
|
2359
|
-
}
|
|
2360
|
-
}
|
|
2361
|
-
});
|
|
2362
|
-
function doActivate() {
|
|
2363
|
-
if (!store.state.options.enabled) return;
|
|
2364
|
-
if (store.state.active) return;
|
|
2365
|
-
if (store.state.toolbar.visible === false && store.state.options.showToolbar) {
|
|
2366
|
-
store.state.toolbar = { ...store.state.toolbar, visible: true };
|
|
2367
|
-
toolbar.show();
|
|
2368
|
-
toolbar.update(store.state);
|
|
2369
|
-
}
|
|
2370
|
-
store.state.active = true;
|
|
2371
|
-
picker.activate();
|
|
2372
|
-
pluginRegistry.callHook("onActivate");
|
|
2373
|
-
toolbar.update(store.state);
|
|
2374
|
-
}
|
|
2375
|
-
function doDeactivate() {
|
|
2376
|
-
if (!store.state.active) return;
|
|
2377
|
-
store.state.active = false;
|
|
2378
|
-
store.state.frozen = false;
|
|
2379
|
-
freezeOverlay.hide();
|
|
2380
|
-
store.state.toolbar = { ...store.state.toolbar, pendingAction: null };
|
|
2381
|
-
picker.deactivate();
|
|
2382
|
-
pluginRegistry.callHook("onDeactivate");
|
|
2383
|
-
toolbar.update(store.state);
|
|
2384
|
-
}
|
|
2385
|
-
function toggleFreeze() {
|
|
2386
|
-
store.state.frozen = !store.state.frozen;
|
|
2387
|
-
if (store.state.frozen) {
|
|
2388
|
-
freezeOverlay.show(store.state.hoveredElement);
|
|
2389
|
-
} else {
|
|
2390
|
-
freezeOverlay.hide();
|
|
2391
|
-
}
|
|
2392
|
-
toolbar.update(store.state);
|
|
2393
|
-
}
|
|
2394
|
-
const toolbar = createToolbarRenderer({
|
|
2395
|
-
onSelectionMode() {
|
|
2396
|
-
closeAllPopovers();
|
|
2397
|
-
if (store.state.active) {
|
|
2398
|
-
doDeactivate();
|
|
2399
|
-
} else {
|
|
2400
|
-
doActivate();
|
|
2401
|
-
}
|
|
2402
|
-
},
|
|
2403
|
-
onHistory() {
|
|
2404
|
-
actionsMenu.hide();
|
|
2405
|
-
commentPopover.hide();
|
|
2406
|
-
if (historyPopover.isVisible()) {
|
|
2407
|
-
historyPopover.hide();
|
|
2408
|
-
} else {
|
|
2409
|
-
historyPopover.show([...store.state.toolbar.history]);
|
|
2410
|
-
}
|
|
2411
|
-
},
|
|
2412
|
-
onActions() {
|
|
2413
|
-
historyPopover.hide();
|
|
2414
|
-
commentPopover.hide();
|
|
2415
|
-
if (actionsMenu.isVisible()) {
|
|
2416
|
-
actionsMenu.hide();
|
|
2417
|
-
} else {
|
|
2418
|
-
actionsMenu.show();
|
|
2419
|
-
}
|
|
2420
|
-
},
|
|
2421
|
-
onFreeze() {
|
|
2422
|
-
closeAllPopovers();
|
|
2423
|
-
if (!store.state.active) {
|
|
2424
|
-
doActivate();
|
|
2425
|
-
}
|
|
2426
|
-
toggleFreeze();
|
|
2427
|
-
},
|
|
2428
|
-
onThemeToggle() {
|
|
2429
|
-
const current = store.state.toolbar.themeMode;
|
|
2430
|
-
const newMode = current === "dark" ? "light" : current === "light" ? "system" : "dark";
|
|
2431
|
-
store.state.toolbar = { ...store.state.toolbar, themeMode: newMode };
|
|
2432
|
-
themeManager.apply(newMode);
|
|
2433
|
-
toolbar.update(store.state);
|
|
2434
|
-
},
|
|
2435
|
-
onEnableToggle() {
|
|
2436
|
-
closeAllPopovers();
|
|
2437
|
-
const newEnabled = !store.state.options.enabled;
|
|
2438
|
-
store.state.options = { ...store.state.options, enabled: newEnabled };
|
|
2439
|
-
if (!newEnabled) {
|
|
2440
|
-
doDeactivate();
|
|
2441
|
-
}
|
|
2442
|
-
toolbar.update(store.state);
|
|
2443
|
-
},
|
|
2444
|
-
onDismiss() {
|
|
2445
|
-
closeAllPopovers();
|
|
2446
|
-
doDeactivate();
|
|
2447
|
-
store.state.toolbar = { ...store.state.toolbar, visible: false };
|
|
2448
|
-
toolbar.hide();
|
|
2449
|
-
}
|
|
2450
|
-
});
|
|
2451
|
-
const historyPopover = createHistoryPopover({
|
|
2452
|
-
async onEntryClick(entry) {
|
|
2453
|
-
historyPopover.hide();
|
|
2454
|
-
try {
|
|
2455
|
-
await navigator.clipboard.writeText(entry.snippet);
|
|
2456
|
-
showToast("Re-copied to clipboard", {
|
|
2457
|
-
componentName: entry.context.componentName,
|
|
2458
|
-
filePath: entry.context.filePath,
|
|
2459
|
-
line: entry.context.line,
|
|
2460
|
-
column: entry.context.column,
|
|
2461
|
-
cssClasses: entry.context.cssClasses
|
|
2462
|
-
});
|
|
2463
|
-
} catch {
|
|
2464
|
-
}
|
|
2465
|
-
}
|
|
2466
|
-
});
|
|
2467
|
-
const actionsMenu = createActionsMenu({
|
|
2468
|
-
onCopyElement() {
|
|
2469
|
-
if (lastSelectedContext) {
|
|
2470
|
-
copyElementSnippet(lastSelectedContext, store.state.options.maxContextLines, pluginRegistry);
|
|
2471
|
-
} else {
|
|
2472
|
-
store.state.toolbar = { ...store.state.toolbar, pendingAction: { type: "copy-element" } };
|
|
2473
|
-
doActivate();
|
|
2474
|
-
}
|
|
2475
|
-
},
|
|
2476
|
-
onCopyStyles() {
|
|
2477
|
-
const el = getLastSelectedElement();
|
|
2478
|
-
if (el) {
|
|
2479
|
-
copyElementStyles(el);
|
|
2480
|
-
} else {
|
|
2481
|
-
store.state.toolbar = { ...store.state.toolbar, pendingAction: { type: "copy-styles" } };
|
|
2482
|
-
doActivate();
|
|
2483
|
-
}
|
|
2484
|
-
},
|
|
2485
|
-
onCopyHtml() {
|
|
2486
|
-
if (lastSelectedContext) {
|
|
2487
|
-
copyElementHtml(lastSelectedContext, pluginRegistry);
|
|
2488
|
-
} else {
|
|
2489
|
-
store.state.toolbar = { ...store.state.toolbar, pendingAction: { type: "copy-html" } };
|
|
2490
|
-
doActivate();
|
|
2491
|
-
}
|
|
2492
|
-
},
|
|
2493
|
-
onComment() {
|
|
2494
|
-
if (lastSelectedContext) {
|
|
2495
|
-
commentPopover.show();
|
|
2496
|
-
} else {
|
|
2497
|
-
store.state.toolbar = { ...store.state.toolbar, pendingAction: { type: "comment" } };
|
|
2498
|
-
doActivate();
|
|
2499
|
-
}
|
|
2500
|
-
},
|
|
2501
|
-
onClearHistory() {
|
|
2502
|
-
lastSelectedContext = null;
|
|
2503
|
-
lastSelectedElement = null;
|
|
2504
|
-
store.state.toolbar = { ...store.state.toolbar, history: [] };
|
|
2505
|
-
}
|
|
2506
|
-
});
|
|
2507
|
-
const commentPopover = createCommentPopover({
|
|
2508
|
-
async onSubmit(comment) {
|
|
2509
|
-
if (lastSelectedContext) {
|
|
2510
|
-
await copyWithComment(lastSelectedContext, comment, store.state.options.maxContextLines, pluginRegistry);
|
|
2511
|
-
}
|
|
2512
|
-
if (store.state.active) {
|
|
2513
|
-
doDeactivate();
|
|
2514
|
-
}
|
|
2515
|
-
},
|
|
2516
|
-
onCancel() {
|
|
2517
|
-
if (store.state.active) {
|
|
2518
|
-
doDeactivate();
|
|
2519
|
-
}
|
|
2520
|
-
}
|
|
2521
|
-
});
|
|
2522
|
-
function handleDocumentClick(e) {
|
|
2523
|
-
const target = e.target;
|
|
2524
|
-
if (!target) return;
|
|
2525
|
-
if (isAnyToolbarElement(target)) return;
|
|
2526
|
-
if (historyPopover.isVisible() || actionsMenu.isVisible() || commentPopover.isVisible()) {
|
|
2527
|
-
closeAllPopovers();
|
|
2528
|
-
}
|
|
2529
|
-
}
|
|
2530
|
-
document.addEventListener("click", handleDocumentClick);
|
|
2531
|
-
function updateToastOffset() {
|
|
2532
|
-
if (store.state.toolbar.visible) {
|
|
2533
|
-
document.documentElement.style.setProperty("--ag-toast-bottom", TOOLBAR_TOAST_OFFSET);
|
|
2534
|
-
} else {
|
|
2535
|
-
document.documentElement.style.removeProperty("--ag-toast-bottom");
|
|
2536
|
-
}
|
|
2537
|
-
}
|
|
2538
|
-
function handleFreezeKey(e) {
|
|
2539
|
-
if (!store.state.active) return;
|
|
2540
|
-
if (e.key.toLowerCase() !== "f") return;
|
|
2541
|
-
const tag = e.target?.tagName;
|
|
2542
|
-
if (tag === "INPUT" || tag === "TEXTAREA") return;
|
|
2543
|
-
if (e.target?.isContentEditable) return;
|
|
2544
|
-
e.preventDefault();
|
|
2545
|
-
toggleFreeze();
|
|
2546
|
-
}
|
|
2547
|
-
document.addEventListener("keydown", handleFreezeKey, true);
|
|
2548
|
-
const keyboard = createKeyboardHandler({
|
|
2549
|
-
getActivationKey: () => store.state.options.activationKey,
|
|
2550
|
-
getActivationMode: () => store.state.options.activationMode,
|
|
2551
|
-
getKeyHoldDuration: () => store.state.options.keyHoldDuration,
|
|
2552
|
-
getEnableInInputs: () => store.state.options.enableInInputs,
|
|
2553
|
-
onActivate: doActivate,
|
|
2554
|
-
onDeactivate: doDeactivate,
|
|
2555
|
-
isActive: () => store.state.active
|
|
2556
|
-
});
|
|
2557
|
-
const api = {
|
|
2558
|
-
activate: doActivate,
|
|
2559
|
-
deactivate: doDeactivate,
|
|
2560
|
-
toggle() {
|
|
2561
|
-
if (store.state.active) {
|
|
2562
|
-
doDeactivate();
|
|
2563
|
-
} else {
|
|
2564
|
-
doActivate();
|
|
2565
|
-
}
|
|
2566
|
-
},
|
|
2567
|
-
isActive() {
|
|
2568
|
-
return store.state.active;
|
|
2569
|
-
},
|
|
2570
|
-
setOptions(opts) {
|
|
2571
|
-
store.state.options = { ...store.state.options, ...opts };
|
|
2572
|
-
},
|
|
2573
|
-
registerPlugin(plugin) {
|
|
2574
|
-
if (plugin.options) {
|
|
2575
|
-
store.state.options = { ...store.state.options, ...plugin.options };
|
|
2576
|
-
}
|
|
2577
|
-
if (plugin.theme) {
|
|
2578
|
-
themeManager.applyOverrides(plugin.theme);
|
|
2579
|
-
}
|
|
2580
|
-
pluginRegistry.register(plugin, api);
|
|
2581
|
-
},
|
|
2582
|
-
unregisterPlugin(name) {
|
|
2583
|
-
pluginRegistry.unregister(name);
|
|
2584
|
-
},
|
|
2585
|
-
setComponentResolver(resolver) {
|
|
2586
|
-
componentResolver = resolver;
|
|
2587
|
-
},
|
|
2588
|
-
setSourceResolver(resolver) {
|
|
2589
|
-
sourceResolver = resolver;
|
|
2590
|
-
},
|
|
2591
|
-
showToolbar() {
|
|
2592
|
-
store.state.toolbar = { ...store.state.toolbar, visible: true };
|
|
2593
|
-
toolbar.show();
|
|
2594
|
-
toolbar.update(store.state);
|
|
2595
|
-
updateToastOffset();
|
|
2596
|
-
},
|
|
2597
|
-
hideToolbar() {
|
|
2598
|
-
closeAllPopovers();
|
|
2599
|
-
store.state.toolbar = { ...store.state.toolbar, visible: false };
|
|
2600
|
-
toolbar.hide();
|
|
2601
|
-
updateToastOffset();
|
|
2602
|
-
},
|
|
2603
|
-
setThemeMode(mode) {
|
|
2604
|
-
store.state.toolbar = { ...store.state.toolbar, themeMode: mode };
|
|
2605
|
-
themeManager.apply(mode);
|
|
2606
|
-
toolbar.update(store.state);
|
|
2607
|
-
},
|
|
2608
|
-
getHistory() {
|
|
2609
|
-
return [...store.state.toolbar.history];
|
|
2610
|
-
},
|
|
2611
|
-
clearHistory() {
|
|
2612
|
-
lastSelectedContext = null;
|
|
2613
|
-
lastSelectedElement = null;
|
|
2614
|
-
store.state.toolbar = { ...store.state.toolbar, history: [] };
|
|
2615
|
-
},
|
|
2616
|
-
dispose() {
|
|
2617
|
-
doDeactivate();
|
|
2618
|
-
document.removeEventListener("click", handleDocumentClick);
|
|
2619
|
-
document.removeEventListener("keydown", handleFreezeKey, true);
|
|
2620
|
-
keyboard.dispose();
|
|
2621
|
-
picker.dispose();
|
|
2622
|
-
overlay.dispose();
|
|
2623
|
-
crosshair.dispose();
|
|
2624
|
-
freezeOverlay.dispose();
|
|
2625
|
-
disposeToast();
|
|
2626
|
-
disposeFeedbackStyles();
|
|
2627
|
-
pluginRegistry.dispose();
|
|
2628
|
-
closeAllPopovers();
|
|
2629
|
-
toolbar.dispose();
|
|
2630
|
-
historyPopover.dispose();
|
|
2631
|
-
actionsMenu.dispose();
|
|
2632
|
-
commentPopover.dispose();
|
|
2633
|
-
themeManager.dispose();
|
|
2634
|
-
document.documentElement.style.removeProperty("--ag-toast-bottom");
|
|
2635
|
-
}
|
|
2636
|
-
};
|
|
2637
|
-
if (store.state.options.enabled) {
|
|
2638
|
-
keyboard.start();
|
|
2639
|
-
}
|
|
2640
|
-
store.state.toolbar = { ...store.state.toolbar, visible: false };
|
|
2641
|
-
store.subscribe((state, key) => {
|
|
2642
|
-
if (key === "options") {
|
|
2643
|
-
if (state.options.enabled) {
|
|
2644
|
-
keyboard.start();
|
|
2645
|
-
} else {
|
|
2646
|
-
keyboard.stop();
|
|
2647
|
-
doDeactivate();
|
|
2648
|
-
}
|
|
2649
|
-
}
|
|
2650
|
-
if (key === "toolbar") {
|
|
2651
|
-
updateToastOffset();
|
|
2652
|
-
}
|
|
2653
|
-
});
|
|
2654
|
-
return api;
|
|
2655
|
-
}
|
|
2656
|
-
|
|
2657
|
-
// src/angular/resolvers/context-builder.ts
|
|
2658
|
-
var MAX_HTML_LENGTH = 2e3;
|
|
2659
|
-
function buildContext(element) {
|
|
2660
|
-
const compResult = resolveComponent(element);
|
|
2661
|
-
const { filePath, line, column } = resolveSource(element);
|
|
2662
|
-
const html = extractHtml(element);
|
|
2663
|
-
const selector = generateSelector(element);
|
|
2664
|
-
const cssClasses = filterAngularClasses(element.classList);
|
|
2665
|
-
const componentStack = compResult.stack.map((entry) => {
|
|
2666
|
-
const src = resolveSourceForComponent(entry.name);
|
|
2667
|
-
return {
|
|
2668
|
-
name: entry.name,
|
|
2669
|
-
filePath: src.filePath,
|
|
2670
|
-
line: src.line,
|
|
2671
|
-
column: src.column
|
|
2672
|
-
};
|
|
2673
|
-
});
|
|
2674
|
-
return {
|
|
2675
|
-
element,
|
|
2676
|
-
html,
|
|
2677
|
-
componentName: compResult.name,
|
|
2678
|
-
filePath,
|
|
2679
|
-
line,
|
|
2680
|
-
column,
|
|
2681
|
-
componentStack,
|
|
2682
|
-
selector,
|
|
2683
|
-
cssClasses
|
|
2684
|
-
};
|
|
2685
|
-
}
|
|
2686
|
-
function extractHtml(element) {
|
|
2687
|
-
const html = element.outerHTML;
|
|
2688
|
-
if (html.length <= MAX_HTML_LENGTH) return html;
|
|
2689
|
-
return html.slice(0, MAX_HTML_LENGTH) + "<!-- truncated -->";
|
|
2690
|
-
}
|
|
2691
|
-
function generateSelector(element) {
|
|
2692
|
-
const parts = [];
|
|
2693
|
-
let current = element;
|
|
2694
|
-
while (current && current !== document.documentElement) {
|
|
2695
|
-
let selector = current.tagName.toLowerCase();
|
|
2696
|
-
if (current.id) {
|
|
2697
|
-
selector += `#${current.id}`;
|
|
2698
|
-
parts.unshift(selector);
|
|
2699
|
-
break;
|
|
2700
|
-
}
|
|
2701
|
-
const className = current.getAttribute("class");
|
|
2702
|
-
if (className) {
|
|
2703
|
-
const classes = className.trim().split(/\s+/).filter(Boolean).slice(0, 3);
|
|
2704
|
-
if (classes.length > 0) {
|
|
2705
|
-
selector += "." + classes.join(".");
|
|
2706
|
-
}
|
|
2707
|
-
}
|
|
2708
|
-
const parent = current.parentElement;
|
|
2709
|
-
if (parent) {
|
|
2710
|
-
const siblings = Array.from(parent.children).filter(
|
|
2711
|
-
(s) => s.tagName === current.tagName
|
|
2712
|
-
);
|
|
2713
|
-
if (siblings.length > 1) {
|
|
2714
|
-
const index = siblings.indexOf(current) + 1;
|
|
2715
|
-
selector += `:nth-of-type(${index})`;
|
|
2716
|
-
}
|
|
2717
|
-
}
|
|
2718
|
-
parts.unshift(selector);
|
|
2719
|
-
current = current.parentElement;
|
|
2720
|
-
}
|
|
2721
|
-
return parts.join(" > ");
|
|
2722
|
-
}
|
|
2723
|
-
|
|
2724
|
-
// src/angular/angular-grab.service.ts
|
|
2725
|
-
var instance = null;
|
|
2726
|
-
function initAngularGrab(options) {
|
|
2727
|
-
if (instance) return instance;
|
|
2728
|
-
if (options?.devOnly !== false && typeof ngDevMode !== "undefined" && !ngDevMode) {
|
|
2729
|
-
instance = createNoOpApi();
|
|
2730
|
-
return instance;
|
|
2731
|
-
}
|
|
2732
|
-
instance = init(options);
|
|
2733
|
-
instance.setComponentResolver((el) => resolveComponent(el));
|
|
2734
|
-
instance.setSourceResolver((el) => resolveSource(el));
|
|
2735
|
-
return instance;
|
|
2736
|
-
}
|
|
2737
|
-
function getAngularGrabApi() {
|
|
2738
|
-
return instance;
|
|
2739
|
-
}
|
|
2740
|
-
function registerAngularGrabPlugin(plugin) {
|
|
2741
|
-
instance?.registerPlugin(plugin);
|
|
2742
|
-
}
|
|
2743
|
-
function disposeAngularGrab() {
|
|
2744
|
-
instance?.dispose();
|
|
2745
|
-
instance = null;
|
|
2746
|
-
}
|
|
2747
|
-
function createNoOpApi() {
|
|
2748
|
-
return {
|
|
2749
|
-
activate() {
|
|
2750
|
-
},
|
|
2751
|
-
deactivate() {
|
|
2752
|
-
},
|
|
2753
|
-
toggle() {
|
|
2754
|
-
},
|
|
2755
|
-
isActive() {
|
|
2756
|
-
return false;
|
|
2757
|
-
},
|
|
2758
|
-
setOptions() {
|
|
2759
|
-
},
|
|
2760
|
-
registerPlugin() {
|
|
2761
|
-
},
|
|
2762
|
-
unregisterPlugin() {
|
|
2763
|
-
},
|
|
2764
|
-
setComponentResolver() {
|
|
2765
|
-
},
|
|
2766
|
-
setSourceResolver() {
|
|
2767
|
-
},
|
|
2768
|
-
showToolbar() {
|
|
2769
|
-
},
|
|
2770
|
-
hideToolbar() {
|
|
2771
|
-
},
|
|
2772
|
-
setThemeMode() {
|
|
2773
|
-
},
|
|
2774
|
-
getHistory() {
|
|
2775
|
-
return [];
|
|
2776
|
-
},
|
|
2777
|
-
clearHistory() {
|
|
2778
|
-
},
|
|
2779
|
-
dispose() {
|
|
2780
|
-
}
|
|
2781
|
-
};
|
|
2782
|
-
}
|
|
2783
|
-
|
|
2784
|
-
// src/angular/provide-angular-grab.ts
|
|
2785
|
-
import {
|
|
2786
|
-
InjectionToken,
|
|
2787
|
-
makeEnvironmentProviders,
|
|
2788
|
-
provideEnvironmentInitializer
|
|
2789
|
-
} from "@angular/core";
|
|
2790
|
-
var ANGULAR_GRAB_API = new InjectionToken("ANGULAR_GRAB_API");
|
|
2791
|
-
function provideAngularGrab(options) {
|
|
2792
|
-
return makeEnvironmentProviders([
|
|
2793
|
-
{
|
|
2794
|
-
provide: ANGULAR_GRAB_API,
|
|
2795
|
-
useFactory: () => initAngularGrab(options)
|
|
2796
|
-
},
|
|
2797
|
-
provideEnvironmentInitializer(() => initAngularGrab(options))
|
|
2798
|
-
]);
|
|
2799
|
-
}
|
|
2800
|
-
export {
|
|
2801
|
-
ANGULAR_GRAB_API,
|
|
2802
|
-
buildContext,
|
|
2803
|
-
disposeAngularGrab,
|
|
2804
|
-
getAngularGrabApi,
|
|
2805
|
-
initAngularGrab,
|
|
2806
|
-
provideAngularGrab,
|
|
2807
|
-
registerAngularGrabPlugin,
|
|
2808
|
-
resolveComponent,
|
|
2809
|
-
resolveSource
|
|
2810
|
-
};
|
|
2811
|
-
//# sourceMappingURL=index.js.map
|