annotask 0.0.0 → 0.0.1
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 +40 -2
- package/dist/chunk-GHDLRMQG.js +61 -0
- package/dist/chunk-GHDLRMQG.js.map +1 -0
- package/dist/chunk-JLOSPIJ4.js +340 -0
- package/dist/chunk-JLOSPIJ4.js.map +1 -0
- package/dist/chunk-JPNMDGZN.js +61 -0
- package/dist/chunk-JPNMDGZN.js.map +1 -0
- package/dist/chunk-R6P4MMZW.js +340 -0
- package/dist/chunk-R6P4MMZW.js.map +1 -0
- package/dist/chunk-VI4NPM6C.js +888 -0
- package/dist/chunk-VI4NPM6C.js.map +1 -0
- package/dist/chunk-VU7Z7EZA.js +362 -0
- package/dist/chunk-VU7Z7EZA.js.map +1 -0
- package/dist/chunk-XLNGAH3S.js +29 -0
- package/dist/chunk-XLNGAH3S.js.map +1 -0
- package/dist/cli.js +38 -10
- package/dist/index.d.ts +11 -0
- package/dist/index.js +17 -6
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +4 -1
- package/dist/server.js +1 -1
- package/dist/shell/assets/{index-BD3nZNWX.js → index-BcsdXOsJ.js} +25 -25
- package/dist/shell/index.html +1 -1
- package/dist/standalone.js +3 -3
- package/dist/webpack-loader.js +1 -1
- package/dist/webpack.js +4 -4
- package/package.json +2 -1
- package/skills/annotask-apply/SKILL.md +8 -0
- package/skills/annotask-watch/SKILL.md +1 -1
|
@@ -0,0 +1,888 @@
|
|
|
1
|
+
// src/plugin/toggle-button.ts
|
|
2
|
+
function toggleButtonScript(serverUrl) {
|
|
3
|
+
const annotaskUrl = serverUrl ? `${serverUrl}/__annotask/` : "/__annotask/";
|
|
4
|
+
return `
|
|
5
|
+
(function() {
|
|
6
|
+
// Don't inject inside the Annotask shell itself
|
|
7
|
+
if (window.location.pathname.startsWith('/__annotask')) return;
|
|
8
|
+
|
|
9
|
+
const btn = document.createElement('button');
|
|
10
|
+
btn.innerHTML = \`<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M3 9h18"/><path d="M9 21V9"/></svg>\`;
|
|
11
|
+
btn.title = 'Open Annotask';
|
|
12
|
+
btn.setAttribute('aria-label', 'Open Annotask design tool');
|
|
13
|
+
|
|
14
|
+
Object.assign(btn.style, {
|
|
15
|
+
position: 'fixed',
|
|
16
|
+
bottom: '16px',
|
|
17
|
+
right: '16px',
|
|
18
|
+
zIndex: '2147483647',
|
|
19
|
+
width: '40px',
|
|
20
|
+
height: '40px',
|
|
21
|
+
borderRadius: '10px',
|
|
22
|
+
border: 'none',
|
|
23
|
+
background: '#18181b',
|
|
24
|
+
color: '#fafafa',
|
|
25
|
+
cursor: 'pointer',
|
|
26
|
+
display: 'flex',
|
|
27
|
+
alignItems: 'center',
|
|
28
|
+
justifyContent: 'center',
|
|
29
|
+
boxShadow: '0 2px 8px rgba(0,0,0,0.3)',
|
|
30
|
+
transition: 'transform 0.15s, box-shadow 0.15s',
|
|
31
|
+
opacity: '0.8',
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
btn.addEventListener('mouseenter', () => {
|
|
35
|
+
btn.style.transform = 'scale(1.1)';
|
|
36
|
+
btn.style.opacity = '1';
|
|
37
|
+
btn.style.boxShadow = '0 4px 16px rgba(0,0,0,0.4)';
|
|
38
|
+
});
|
|
39
|
+
btn.addEventListener('mouseleave', () => {
|
|
40
|
+
btn.style.transform = 'scale(1)';
|
|
41
|
+
btn.style.opacity = '0.8';
|
|
42
|
+
btn.style.boxShadow = '0 2px 8px rgba(0,0,0,0.3)';
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
btn.addEventListener('click', () => {
|
|
46
|
+
var appOrigin = window.location.origin;
|
|
47
|
+
var url = '${annotaskUrl}' + '?appUrl=' + encodeURIComponent(appOrigin + '/');
|
|
48
|
+
window.open(url, '_blank');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
document.body.appendChild(btn);
|
|
52
|
+
})();
|
|
53
|
+
`.trim();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/plugin/bridge-client.ts
|
|
57
|
+
function bridgeClientScript() {
|
|
58
|
+
return `
|
|
59
|
+
(function() {
|
|
60
|
+
// Don't run inside the Annotask shell
|
|
61
|
+
if (window.location.pathname.startsWith('/__annotask')) return;
|
|
62
|
+
// Don't run if already initialized
|
|
63
|
+
if (window.__ANNOTASK_BRIDGE__) return;
|
|
64
|
+
window.__ANNOTASK_BRIDGE__ = true;
|
|
65
|
+
|
|
66
|
+
// \u2500\u2500 Element Registry \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
67
|
+
var eidCounter = 0;
|
|
68
|
+
var eidMap = new Map(); // eid string \u2192 WeakRef<Element>
|
|
69
|
+
var elToEid = new WeakMap(); // Element \u2192 eid string
|
|
70
|
+
|
|
71
|
+
function getEid(el) {
|
|
72
|
+
if (!el) return null;
|
|
73
|
+
var existing = elToEid.get(el);
|
|
74
|
+
if (existing) return existing;
|
|
75
|
+
eidCounter++;
|
|
76
|
+
var eid = 'e-' + eidCounter;
|
|
77
|
+
eidMap.set(eid, new WeakRef(el));
|
|
78
|
+
elToEid.set(el, eid);
|
|
79
|
+
return eid;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function getEl(eid) {
|
|
83
|
+
var ref = eidMap.get(eid);
|
|
84
|
+
return ref ? ref.deref() || null : null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// \u2500\u2500 PostMessage Helpers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
88
|
+
var shellOrigin = '*'; // Will be tightened on first shell message
|
|
89
|
+
|
|
90
|
+
function sendToShell(type, payload, id) {
|
|
91
|
+
var msg = { type: type, payload: payload || {}, source: 'annotask-client' };
|
|
92
|
+
if (id) msg.id = id;
|
|
93
|
+
window.parent.postMessage(msg, shellOrigin);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function respond(id, payload) {
|
|
97
|
+
sendToShell(null, payload, id);
|
|
98
|
+
// type is not needed for responses \u2014 shell matches by id
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// \u2500\u2500 Source Element Resolution \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
102
|
+
function hasSourceAttr(el) {
|
|
103
|
+
return el.hasAttribute && (el.hasAttribute('data-annotask-file') || el.hasAttribute('data-astro-source-file'));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function findSourceElement(el) {
|
|
107
|
+
var c = el;
|
|
108
|
+
while (c) {
|
|
109
|
+
if (hasSourceAttr(c)) return { sourceEl: c, targetEl: el };
|
|
110
|
+
c = c.parentElement;
|
|
111
|
+
}
|
|
112
|
+
return { sourceEl: el, targetEl: el };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function getSourceData(el) {
|
|
116
|
+
// Prefer data-annotask-* attributes, fall back to data-astro-source-* (Astro framework)
|
|
117
|
+
var file = el.getAttribute('data-annotask-file') || '';
|
|
118
|
+
var line = el.getAttribute('data-annotask-line') || '';
|
|
119
|
+
var component = el.getAttribute('data-annotask-component') || '';
|
|
120
|
+
|
|
121
|
+
if (!file && el.getAttribute('data-astro-source-file')) {
|
|
122
|
+
var astroFile = el.getAttribute('data-astro-source-file') || '';
|
|
123
|
+
// Convert absolute path to project-relative by finding src/ prefix
|
|
124
|
+
var srcIdx = astroFile.indexOf('/src/');
|
|
125
|
+
file = srcIdx !== -1 ? astroFile.slice(srcIdx + 1) : astroFile;
|
|
126
|
+
}
|
|
127
|
+
if ((!line || line === '0') && el.getAttribute('data-astro-source-loc')) {
|
|
128
|
+
// data-astro-source-loc format: "line:col"
|
|
129
|
+
line = (el.getAttribute('data-astro-source-loc') || '').split(':')[0];
|
|
130
|
+
}
|
|
131
|
+
if (!component && file) {
|
|
132
|
+
// Derive component name from file path
|
|
133
|
+
var parts = file.split('/');
|
|
134
|
+
var fileName = parts[parts.length - 1] || '';
|
|
135
|
+
component = fileName.replace(/.[^.]+$/, '');
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
var mfe = el.getAttribute('data-annotask-mfe') || '';
|
|
139
|
+
|
|
140
|
+
return { file: file, line: line, component: component, mfe: mfe };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function getRect(el) {
|
|
144
|
+
var r = el.getBoundingClientRect();
|
|
145
|
+
return { x: r.x, y: r.y, width: r.width, height: r.height };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// \u2500\u2500 Interaction Mode \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
149
|
+
var currentMode = 'select';
|
|
150
|
+
var inspectModes = { select: true, pin: true };
|
|
151
|
+
|
|
152
|
+
// \u2500\u2500 Event Handlers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
153
|
+
var lastHoverEid = null;
|
|
154
|
+
var rafPending = false;
|
|
155
|
+
var pendingHoverData = null;
|
|
156
|
+
|
|
157
|
+
function onMouseOver(e) {
|
|
158
|
+
if (!inspectModes[currentMode]) return;
|
|
159
|
+
var el = e.target;
|
|
160
|
+
if (!el || el === document.documentElement || el === document.body) return;
|
|
161
|
+
var eid = getEid(el);
|
|
162
|
+
if (eid === lastHoverEid) return;
|
|
163
|
+
lastHoverEid = eid;
|
|
164
|
+
|
|
165
|
+
var source = findSourceElement(el);
|
|
166
|
+
var data = getSourceData(source.sourceEl);
|
|
167
|
+
|
|
168
|
+
pendingHoverData = {
|
|
169
|
+
eid: eid,
|
|
170
|
+
tag: el.tagName.toLowerCase(),
|
|
171
|
+
file: data.file,
|
|
172
|
+
component: data.component,
|
|
173
|
+
rect: getRect(el)
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
if (!rafPending) {
|
|
177
|
+
rafPending = true;
|
|
178
|
+
requestAnimationFrame(function() {
|
|
179
|
+
rafPending = false;
|
|
180
|
+
if (pendingHoverData) sendToShell('hover:enter', pendingHoverData);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function onMouseOut(e) {
|
|
186
|
+
if (!inspectModes[currentMode]) return;
|
|
187
|
+
// Only fire leave when truly leaving all elements
|
|
188
|
+
if (e.relatedTarget && e.relatedTarget !== document.documentElement) return;
|
|
189
|
+
lastHoverEid = null;
|
|
190
|
+
pendingHoverData = null;
|
|
191
|
+
sendToShell('hover:leave', {});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function onClick(e) {
|
|
195
|
+
if (!inspectModes[currentMode]) return;
|
|
196
|
+
e.preventDefault();
|
|
197
|
+
e.stopPropagation();
|
|
198
|
+
|
|
199
|
+
var el = e.target;
|
|
200
|
+
if (!el) return;
|
|
201
|
+
|
|
202
|
+
var source = findSourceElement(el);
|
|
203
|
+
var data = getSourceData(source.sourceEl);
|
|
204
|
+
var targetEl = source.targetEl;
|
|
205
|
+
var classes = typeof targetEl.className === 'string' ? targetEl.className : '';
|
|
206
|
+
|
|
207
|
+
sendToShell('click:element', {
|
|
208
|
+
eid: getEid(targetEl),
|
|
209
|
+
sourceEid: getEid(source.sourceEl),
|
|
210
|
+
file: data.file,
|
|
211
|
+
line: data.line,
|
|
212
|
+
component: data.component,
|
|
213
|
+
mfe: data.mfe,
|
|
214
|
+
tag: targetEl.tagName.toLowerCase(),
|
|
215
|
+
classes: classes,
|
|
216
|
+
rect: getRect(targetEl),
|
|
217
|
+
shiftKey: e.shiftKey,
|
|
218
|
+
clientX: e.clientX,
|
|
219
|
+
clientY: e.clientY
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function onMouseDown(e) {
|
|
224
|
+
if (!inspectModes[currentMode]) return;
|
|
225
|
+
e.stopPropagation();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function onMouseUp(e) {
|
|
229
|
+
if (currentMode !== 'highlight') return;
|
|
230
|
+
var sel = document.getSelection();
|
|
231
|
+
var text = sel ? sel.toString().trim() : '';
|
|
232
|
+
if (!text || text.length < 2) return;
|
|
233
|
+
var anchorEl = sel.anchorNode ? sel.anchorNode.parentElement : null;
|
|
234
|
+
if (!anchorEl) return;
|
|
235
|
+
var source = findSourceElement(anchorEl);
|
|
236
|
+
var data = getSourceData(source.sourceEl);
|
|
237
|
+
|
|
238
|
+
sendToShell('selection:text', {
|
|
239
|
+
text: text,
|
|
240
|
+
eid: getEid(anchorEl),
|
|
241
|
+
file: data.file,
|
|
242
|
+
line: parseInt(data.line) || 0,
|
|
243
|
+
component: data.component,
|
|
244
|
+
mfe: data.mfe,
|
|
245
|
+
tag: anchorEl.tagName.toLowerCase()
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function onContextMenu(e) {
|
|
250
|
+
if (currentMode === 'interact') return;
|
|
251
|
+
e.preventDefault();
|
|
252
|
+
var el = e.target;
|
|
253
|
+
if (!el) return;
|
|
254
|
+
var source = findSourceElement(el);
|
|
255
|
+
var data = getSourceData(source.sourceEl);
|
|
256
|
+
var targetEl = source.targetEl;
|
|
257
|
+
var classes = typeof targetEl.className === 'string' ? targetEl.className : '';
|
|
258
|
+
|
|
259
|
+
sendToShell('contextmenu:element', {
|
|
260
|
+
eid: getEid(targetEl),
|
|
261
|
+
sourceEid: getEid(source.sourceEl),
|
|
262
|
+
file: data.file,
|
|
263
|
+
line: data.line,
|
|
264
|
+
component: data.component,
|
|
265
|
+
mfe: data.mfe,
|
|
266
|
+
tag: targetEl.tagName.toLowerCase(),
|
|
267
|
+
classes: classes,
|
|
268
|
+
rect: getRect(targetEl),
|
|
269
|
+
shiftKey: false,
|
|
270
|
+
clientX: e.clientX,
|
|
271
|
+
clientY: e.clientY
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function onKeyDown(e) {
|
|
276
|
+
if ((e.ctrlKey || e.metaKey) && e.key === 'z' && !e.shiftKey) {
|
|
277
|
+
e.preventDefault();
|
|
278
|
+
sendToShell('keydown', { key: e.key, ctrlKey: e.ctrlKey, metaKey: e.metaKey, shiftKey: e.shiftKey });
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Install event listeners
|
|
283
|
+
document.addEventListener('mouseover', onMouseOver, { capture: true });
|
|
284
|
+
document.addEventListener('mouseout', onMouseOut, { capture: true });
|
|
285
|
+
document.addEventListener('mousedown', onMouseDown, { capture: true });
|
|
286
|
+
document.addEventListener('click', onClick, { capture: true });
|
|
287
|
+
document.addEventListener('mouseup', onMouseUp, { capture: true });
|
|
288
|
+
document.addEventListener('keydown', onKeyDown, { capture: true });
|
|
289
|
+
document.addEventListener('contextmenu', onContextMenu, { capture: true });
|
|
290
|
+
|
|
291
|
+
// \u2500\u2500 Route Tracking \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
292
|
+
var lastRoute = window.location.pathname;
|
|
293
|
+
|
|
294
|
+
function checkRoute() {
|
|
295
|
+
var path = window.location.pathname;
|
|
296
|
+
if (path !== lastRoute) {
|
|
297
|
+
lastRoute = path;
|
|
298
|
+
sendToShell('route:changed', { path: path });
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
window.addEventListener('popstate', checkRoute);
|
|
303
|
+
window.addEventListener('hashchange', checkRoute);
|
|
304
|
+
setInterval(checkRoute, 2000); // safety net for pushState
|
|
305
|
+
|
|
306
|
+
// \u2500\u2500 Message Handler \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
307
|
+
window.addEventListener('message', function(event) {
|
|
308
|
+
var msg = event.data;
|
|
309
|
+
if (!msg || msg.source !== 'annotask-shell') return;
|
|
310
|
+
// Tighten origin on first shell message
|
|
311
|
+
if (shellOrigin === '*' && event.origin) shellOrigin = event.origin;
|
|
312
|
+
|
|
313
|
+
var type = msg.type;
|
|
314
|
+
var payload = msg.payload || {};
|
|
315
|
+
var id = msg.id;
|
|
316
|
+
|
|
317
|
+
// \u2500\u2500 Mode \u2500\u2500
|
|
318
|
+
if (type === 'mode:set') {
|
|
319
|
+
currentMode = payload.mode || 'select';
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// \u2500\u2500 Ping \u2500\u2500
|
|
324
|
+
if (type === 'bridge:ping') {
|
|
325
|
+
respond(id, {});
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// \u2500\u2500 Element Resolution \u2500\u2500
|
|
330
|
+
if (type === 'resolve:at-point') {
|
|
331
|
+
var el = document.elementFromPoint(payload.x, payload.y);
|
|
332
|
+
if (!el || el === document.documentElement || el === document.body) {
|
|
333
|
+
respond(id, null);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
var src = findSourceElement(el);
|
|
337
|
+
var srcData = getSourceData(src.sourceEl);
|
|
338
|
+
respond(id, {
|
|
339
|
+
eid: getEid(src.targetEl),
|
|
340
|
+
file: srcData.file,
|
|
341
|
+
line: srcData.line,
|
|
342
|
+
component: srcData.component,
|
|
343
|
+
mfe: srcData.mfe,
|
|
344
|
+
tag: src.sourceEl.tagName.toLowerCase(),
|
|
345
|
+
rect: getRect(src.sourceEl),
|
|
346
|
+
classes: typeof src.targetEl.className === 'string' ? src.targetEl.className : ''
|
|
347
|
+
});
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (type === 'resolve:template-group') {
|
|
352
|
+
var all = document.querySelectorAll(
|
|
353
|
+
'[data-annotask-file="' + payload.file + '"][data-annotask-line="' + payload.line + '"]'
|
|
354
|
+
);
|
|
355
|
+
// Also check Astro source attributes
|
|
356
|
+
if (all.length === 0 && payload.file && payload.line) {
|
|
357
|
+
// Try matching by astro source attributes (absolute path ends with file, loc starts with line)
|
|
358
|
+
var astroAll = document.querySelectorAll('[data-astro-source-file]');
|
|
359
|
+
var matched = [];
|
|
360
|
+
for (var ai = 0; ai < astroAll.length; ai++) {
|
|
361
|
+
var af = astroAll[ai].getAttribute('data-astro-source-file') || '';
|
|
362
|
+
var al = (astroAll[ai].getAttribute('data-astro-source-loc') || '').split(':')[0];
|
|
363
|
+
if (af.endsWith('/' + payload.file) && al === payload.line) matched.push(astroAll[ai]);
|
|
364
|
+
}
|
|
365
|
+
if (matched.length > 0) all = matched;
|
|
366
|
+
}
|
|
367
|
+
var eids = [];
|
|
368
|
+
var rects = [];
|
|
369
|
+
for (var i = 0; i < all.length; i++) {
|
|
370
|
+
if (all[i].tagName.toLowerCase() === payload.tagName) {
|
|
371
|
+
eids.push(getEid(all[i]));
|
|
372
|
+
rects.push(getRect(all[i]));
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
respond(id, { eids: eids, rects: rects });
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (type === 'resolve:rect') {
|
|
380
|
+
var rEl = getEl(payload.eid);
|
|
381
|
+
respond(id, rEl ? { rect: getRect(rEl) } : null);
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (type === 'resolve:rects') {
|
|
386
|
+
var results = [];
|
|
387
|
+
for (var j = 0; j < payload.eids.length; j++) {
|
|
388
|
+
var re = getEl(payload.eids[j]);
|
|
389
|
+
results.push(re ? getRect(re) : null);
|
|
390
|
+
}
|
|
391
|
+
respond(id, { rects: results });
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// \u2500\u2500 Style Operations \u2500\u2500
|
|
396
|
+
if (type === 'style:get-computed') {
|
|
397
|
+
var sEl = getEl(payload.eid);
|
|
398
|
+
if (!sEl) { respond(id, { styles: {} }); return; }
|
|
399
|
+
var cs = window.getComputedStyle(sEl);
|
|
400
|
+
var styles = {};
|
|
401
|
+
for (var k = 0; k < payload.properties.length; k++) {
|
|
402
|
+
styles[payload.properties[k]] = cs.getPropertyValue(payload.properties[k]);
|
|
403
|
+
}
|
|
404
|
+
respond(id, { styles: styles });
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (type === 'style:apply') {
|
|
409
|
+
var aEl = getEl(payload.eid);
|
|
410
|
+
if (!aEl) { respond(id, { before: '' }); return; }
|
|
411
|
+
var before = window.getComputedStyle(aEl).getPropertyValue(payload.property);
|
|
412
|
+
aEl.style.setProperty(payload.property, payload.value);
|
|
413
|
+
respond(id, { before: before });
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
if (type === 'style:apply-batch') {
|
|
418
|
+
var befores = [];
|
|
419
|
+
for (var m = 0; m < payload.eids.length; m++) {
|
|
420
|
+
var bEl = getEl(payload.eids[m]);
|
|
421
|
+
if (bEl) {
|
|
422
|
+
befores.push(window.getComputedStyle(bEl).getPropertyValue(payload.property));
|
|
423
|
+
bEl.style.setProperty(payload.property, payload.value);
|
|
424
|
+
} else {
|
|
425
|
+
befores.push('');
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
respond(id, { befores: befores });
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
if (type === 'style:undo') {
|
|
433
|
+
var uEl = getEl(payload.eid);
|
|
434
|
+
if (uEl) {
|
|
435
|
+
if (payload.value) uEl.style.setProperty(payload.property, payload.value);
|
|
436
|
+
else uEl.style.removeProperty(payload.property);
|
|
437
|
+
}
|
|
438
|
+
respond(id, {});
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
if (type === 'class:get') {
|
|
443
|
+
var cEl = getEl(payload.eid);
|
|
444
|
+
respond(id, { classes: cEl ? (typeof cEl.className === 'string' ? cEl.className : '') : '' });
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
if (type === 'class:set') {
|
|
449
|
+
var csEl = getEl(payload.eid);
|
|
450
|
+
if (!csEl) { respond(id, { before: '' }); return; }
|
|
451
|
+
var classBefore = typeof csEl.className === 'string' ? csEl.className : '';
|
|
452
|
+
csEl.className = payload.classes;
|
|
453
|
+
respond(id, { before: classBefore });
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
if (type === 'class:set-batch') {
|
|
458
|
+
var classBefores = [];
|
|
459
|
+
for (var n = 0; n < payload.eids.length; n++) {
|
|
460
|
+
var cbEl = getEl(payload.eids[n]);
|
|
461
|
+
if (cbEl) {
|
|
462
|
+
classBefores.push(typeof cbEl.className === 'string' ? cbEl.className : '');
|
|
463
|
+
cbEl.className = payload.classes;
|
|
464
|
+
} else {
|
|
465
|
+
classBefores.push('');
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
respond(id, { befores: classBefores });
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
if (type === 'class:undo') {
|
|
473
|
+
var cuEl = getEl(payload.eid);
|
|
474
|
+
if (cuEl) cuEl.className = payload.classes;
|
|
475
|
+
respond(id, {});
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// \u2500\u2500 Classification \u2500\u2500
|
|
480
|
+
if (type === 'classify:element') {
|
|
481
|
+
var clEl = getEl(payload.eid);
|
|
482
|
+
if (!clEl) { respond(id, null); return; }
|
|
483
|
+
var tag = clEl.tagName.toLowerCase();
|
|
484
|
+
var clCs = window.getComputedStyle(clEl);
|
|
485
|
+
var display = clCs.display;
|
|
486
|
+
var childCount = clEl.children.length;
|
|
487
|
+
var isFlex = display.includes('flex');
|
|
488
|
+
var isGrid = display.includes('grid');
|
|
489
|
+
var semanticContainers = ['section','main','aside','nav','header','footer','article'];
|
|
490
|
+
var role = 'content';
|
|
491
|
+
if (clEl.hasAttribute('data-annotask-component')) {
|
|
492
|
+
var comp = clEl.getAttribute('data-annotask-component') || '';
|
|
493
|
+
if (comp && comp[0] === comp[0].toUpperCase() && comp[0] !== comp[0].toLowerCase()) {
|
|
494
|
+
role = 'component';
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
if (role !== 'component' && (isFlex || isGrid) && childCount > 0) role = 'container';
|
|
498
|
+
if (role !== 'component' && role !== 'container' && semanticContainers.indexOf(tag) >= 0 && childCount > 0) role = 'container';
|
|
499
|
+
|
|
500
|
+
respond(id, {
|
|
501
|
+
role: role,
|
|
502
|
+
display: display,
|
|
503
|
+
isFlexContainer: isFlex,
|
|
504
|
+
isGridContainer: isGrid,
|
|
505
|
+
flexDirection: isFlex ? clCs.flexDirection : undefined,
|
|
506
|
+
childCount: childCount,
|
|
507
|
+
isComponentUnit: role === 'component'
|
|
508
|
+
});
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// \u2500\u2500 Layout Scan \u2500\u2500
|
|
513
|
+
if (type === 'layout:scan') {
|
|
514
|
+
var layoutResults = [];
|
|
515
|
+
var allEls = document.querySelectorAll('*');
|
|
516
|
+
for (var li = 0; li < allEls.length; li++) {
|
|
517
|
+
var lEl = allEls[li];
|
|
518
|
+
if (lEl.nodeType !== 1) continue;
|
|
519
|
+
var lCs = window.getComputedStyle(lEl);
|
|
520
|
+
var lDisplay = lCs.display;
|
|
521
|
+
if (!lDisplay.includes('flex') && !lDisplay.includes('grid')) continue;
|
|
522
|
+
var lRect = lEl.getBoundingClientRect();
|
|
523
|
+
if (lRect.width < 20 || lRect.height < 20) continue;
|
|
524
|
+
var lIsGrid = lDisplay.includes('grid');
|
|
525
|
+
var entry = {
|
|
526
|
+
eid: getEid(lEl),
|
|
527
|
+
display: lIsGrid ? 'grid' : 'flex',
|
|
528
|
+
direction: lIsGrid ? 'grid' : lCs.flexDirection,
|
|
529
|
+
rect: { x: lRect.x, y: lRect.y, width: lRect.width, height: lRect.height },
|
|
530
|
+
columnGap: parseFloat(lCs.columnGap) || 0,
|
|
531
|
+
rowGap: parseFloat(lCs.rowGap) || 0
|
|
532
|
+
};
|
|
533
|
+
if (lIsGrid) {
|
|
534
|
+
var cols = lCs.gridTemplateColumns;
|
|
535
|
+
var rows = lCs.gridTemplateRows;
|
|
536
|
+
entry.templateColumns = cols;
|
|
537
|
+
entry.templateRows = rows;
|
|
538
|
+
if (cols && cols !== 'none') {
|
|
539
|
+
entry.columns = cols.split(/\\s+/).map(function(s) { return parseFloat(s) || 0; }).filter(function(v) { return v > 0; });
|
|
540
|
+
}
|
|
541
|
+
if (rows && rows !== 'none') {
|
|
542
|
+
entry.rows = rows.split(/\\s+/).map(function(s) { return parseFloat(s) || 0; }).filter(function(v) { return v > 0; });
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
layoutResults.push(entry);
|
|
546
|
+
}
|
|
547
|
+
respond(id, { containers: layoutResults });
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
if (type === 'layout:add-track') {
|
|
552
|
+
var ltEl = getEl(payload.eid);
|
|
553
|
+
if (!ltEl) { respond(id, { property: '', before: '', after: '' }); return; }
|
|
554
|
+
var ltCs = window.getComputedStyle(ltEl);
|
|
555
|
+
var cssProp = payload.axis === 'col' ? 'grid-template-columns' : 'grid-template-rows';
|
|
556
|
+
var ltBefore = ltCs.getPropertyValue(cssProp) || '';
|
|
557
|
+
var ltAfter = ltBefore && ltBefore !== 'none' ? ltBefore + ' 1fr' : '1fr';
|
|
558
|
+
ltEl.style.setProperty(cssProp, ltAfter);
|
|
559
|
+
respond(id, { property: cssProp, before: ltBefore, after: ltAfter });
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
if (type === 'layout:add-child') {
|
|
564
|
+
var lcEl = getEl(payload.eid);
|
|
565
|
+
if (!lcEl) { respond(id, { childEid: '' }); return; }
|
|
566
|
+
var child = document.createElement('div');
|
|
567
|
+
child.style.minWidth = '60px';
|
|
568
|
+
child.style.minHeight = '40px';
|
|
569
|
+
child.style.border = '2px dashed #a855f7';
|
|
570
|
+
child.style.borderRadius = '4px';
|
|
571
|
+
child.style.background = 'rgba(168,85,247,0.05)';
|
|
572
|
+
child.setAttribute('data-annotask-placeholder', 'true');
|
|
573
|
+
lcEl.appendChild(child);
|
|
574
|
+
respond(id, { childEid: getEid(child) });
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// \u2500\u2500 Theme \u2500\u2500
|
|
579
|
+
if (type === 'theme:inject-css') {
|
|
580
|
+
var existing = document.getElementById(payload.styleId);
|
|
581
|
+
if (existing) {
|
|
582
|
+
existing.textContent = payload.css;
|
|
583
|
+
} else {
|
|
584
|
+
var style = document.createElement('style');
|
|
585
|
+
style.id = payload.styleId;
|
|
586
|
+
style.textContent = payload.css;
|
|
587
|
+
document.head.appendChild(style);
|
|
588
|
+
}
|
|
589
|
+
respond(id, {});
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
if (type === 'theme:remove-css') {
|
|
594
|
+
var toRemove = document.getElementById(payload.styleId);
|
|
595
|
+
if (toRemove) toRemove.remove();
|
|
596
|
+
respond(id, {});
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// \u2500\u2500 Color Palette \u2500\u2500
|
|
601
|
+
if (type === 'palette:scan-vars') {
|
|
602
|
+
var swatches = [];
|
|
603
|
+
try {
|
|
604
|
+
var rootStyles = window.getComputedStyle(document.documentElement);
|
|
605
|
+
var sheets = document.styleSheets;
|
|
606
|
+
for (var si = 0; si < sheets.length; si++) {
|
|
607
|
+
try {
|
|
608
|
+
var rules = sheets[si].cssRules;
|
|
609
|
+
for (var ri = 0; ri < rules.length; ri++) {
|
|
610
|
+
var rule = rules[ri];
|
|
611
|
+
if (rule.selectorText === ':root' || rule.selectorText === ':root, :host') {
|
|
612
|
+
for (var pi = 0; pi < rule.style.length; pi++) {
|
|
613
|
+
var prop = rule.style[pi];
|
|
614
|
+
if (prop.startsWith('--')) {
|
|
615
|
+
var val = rootStyles.getPropertyValue(prop).trim();
|
|
616
|
+
if (val && isColor(val)) {
|
|
617
|
+
swatches.push({ name: prop, value: val });
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
} catch(e) { /* cross-origin stylesheet */ }
|
|
624
|
+
}
|
|
625
|
+
} catch(e) {}
|
|
626
|
+
respond(id, { swatches: swatches });
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// \u2500\u2500 Source Mapping Check \u2500\u2500
|
|
631
|
+
if (type === 'check:source-mapping') {
|
|
632
|
+
respond(id, { hasMapping: !!(document.querySelector('[data-annotask-file]') || document.querySelector('[data-astro-source-file]')) });
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// \u2500\u2500 Insert Placeholder \u2500\u2500
|
|
637
|
+
if (type === 'insert:placeholder') {
|
|
638
|
+
var ipTarget = getEl(payload.targetEid);
|
|
639
|
+
if (!ipTarget) { respond(id, { placeholderEid: '' }); return; }
|
|
640
|
+
var ipEl = createPlaceholder(payload);
|
|
641
|
+
var ipRef = ipTarget;
|
|
642
|
+
switch (payload.position) {
|
|
643
|
+
case 'before': ipRef.parentElement && ipRef.parentElement.insertBefore(ipEl, ipRef); break;
|
|
644
|
+
case 'after': ipRef.parentElement && ipRef.parentElement.insertBefore(ipEl, ipRef.nextSibling); break;
|
|
645
|
+
case 'append': ipRef.appendChild(ipEl); break;
|
|
646
|
+
case 'prepend': ipRef.insertBefore(ipEl, ipRef.firstChild); break;
|
|
647
|
+
}
|
|
648
|
+
// Match sibling sizes in flex/grid
|
|
649
|
+
var insertParent = (payload.position === 'append' || payload.position === 'prepend') ? ipRef : ipRef.parentElement;
|
|
650
|
+
if (insertParent) {
|
|
651
|
+
var pCs = window.getComputedStyle(insertParent);
|
|
652
|
+
if (pCs.display.includes('flex') || pCs.display.includes('grid')) {
|
|
653
|
+
if (!ipEl.style.width) {
|
|
654
|
+
var isRow = pCs.flexDirection === 'row' || pCs.flexDirection === 'row-reverse' || pCs.display.includes('grid');
|
|
655
|
+
if (isRow) ipEl.style.flex = '1';
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
respond(id, { placeholderEid: getEid(ipEl) });
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
if (type === 'insert:remove') {
|
|
664
|
+
var irEl = getEl(payload.eid);
|
|
665
|
+
if (irEl) {
|
|
666
|
+
var unmount = irEl.__annotask_unmount;
|
|
667
|
+
if (unmount) unmount();
|
|
668
|
+
irEl.remove();
|
|
669
|
+
}
|
|
670
|
+
respond(id, {});
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
if (type === 'move:element') {
|
|
675
|
+
var meEl = getEl(payload.eid);
|
|
676
|
+
var meTarget = getEl(payload.targetEid);
|
|
677
|
+
if (meEl && meTarget) {
|
|
678
|
+
switch (payload.position) {
|
|
679
|
+
case 'before': meTarget.parentElement && meTarget.parentElement.insertBefore(meEl, meTarget); break;
|
|
680
|
+
case 'after': meTarget.parentElement && meTarget.parentElement.insertBefore(meEl, meTarget.nextSibling); break;
|
|
681
|
+
case 'append': meTarget.appendChild(meEl); break;
|
|
682
|
+
case 'prepend': meTarget.insertBefore(meEl, meTarget.firstChild); break;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
respond(id, {});
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
if (type === 'insert:vue-component' || type === 'insert:component') {
|
|
690
|
+
var vcTarget = getEl(payload.targetEid);
|
|
691
|
+
if (!vcTarget) { respond(id, { eid: '', mounted: false }); return; }
|
|
692
|
+
var vcContainer = document.createElement('div');
|
|
693
|
+
vcContainer.setAttribute('data-annotask-placeholder', 'true');
|
|
694
|
+
switch (payload.position) {
|
|
695
|
+
case 'before': vcTarget.parentElement && vcTarget.parentElement.insertBefore(vcContainer, vcTarget); break;
|
|
696
|
+
case 'after': vcTarget.parentElement && vcTarget.parentElement.insertBefore(vcContainer, vcTarget.nextSibling); break;
|
|
697
|
+
case 'append': vcTarget.appendChild(vcContainer); break;
|
|
698
|
+
case 'prepend': vcTarget.insertBefore(vcContainer, vcTarget.firstChild); break;
|
|
699
|
+
}
|
|
700
|
+
var mounted = tryMountComponent(vcContainer, payload.componentName, payload.props);
|
|
701
|
+
respond(id, { eid: getEid(vcContainer), mounted: mounted });
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
// \u2500\u2500 Get source data for an eid \u2500\u2500
|
|
706
|
+
if (type === 'resolve:source') {
|
|
707
|
+
var rsEl = getEl(payload.eid);
|
|
708
|
+
if (!rsEl) { respond(id, null); return; }
|
|
709
|
+
var rsSrc = findSourceElement(rsEl);
|
|
710
|
+
var rsData = getSourceData(rsSrc.sourceEl);
|
|
711
|
+
respond(id, {
|
|
712
|
+
sourceEid: getEid(rsSrc.sourceEl),
|
|
713
|
+
file: rsData.file,
|
|
714
|
+
line: rsData.line,
|
|
715
|
+
component: rsData.component,
|
|
716
|
+
tag: rsSrc.sourceEl.tagName.toLowerCase()
|
|
717
|
+
});
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
// \u2500\u2500 Route \u2500\u2500
|
|
722
|
+
if (type === 'route:current') {
|
|
723
|
+
respond(id, { path: window.location.pathname });
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
});
|
|
727
|
+
|
|
728
|
+
// \u2500\u2500 Helpers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
729
|
+
function isColor(val) {
|
|
730
|
+
if (val.startsWith('#') || val.startsWith('rgb') || val.startsWith('hsl')) return true;
|
|
731
|
+
// Named colors \u2014 quick check with canvas
|
|
732
|
+
try {
|
|
733
|
+
var ctx = document.createElement('canvas').getContext('2d');
|
|
734
|
+
ctx.fillStyle = '#000000';
|
|
735
|
+
ctx.fillStyle = val;
|
|
736
|
+
return ctx.fillStyle !== '#000000' || val === 'black' || val === '#000000';
|
|
737
|
+
} catch(e) { return false; }
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
function createPlaceholder(payload) {
|
|
741
|
+
var el = document.createElement(payload.tag);
|
|
742
|
+
el.setAttribute('data-annotask-placeholder', 'true');
|
|
743
|
+
if (payload.classes) el.className = payload.classes;
|
|
744
|
+
var tag = payload.tag.toLowerCase();
|
|
745
|
+
var isComponent = payload.tag.includes('-') || (payload.tag[0] === payload.tag[0].toUpperCase() && payload.tag[0] !== payload.tag[0].toLowerCase());
|
|
746
|
+
|
|
747
|
+
if (tag === 'button') {
|
|
748
|
+
el.textContent = payload.textContent || 'Button';
|
|
749
|
+
el.style.cssText = 'padding:8px 16px;border-radius:6px;font-size:14px;font-weight:500;cursor:pointer;border:1px solid currentColor;background:var(--accent,#3b82f6);color:white;';
|
|
750
|
+
} else if (tag === 'input') {
|
|
751
|
+
el.type = 'text'; el.placeholder = 'Input field...';
|
|
752
|
+
el.style.cssText = 'padding:8px 12px;border:1px solid #ccc;border-radius:6px;font-size:14px;width:100%;max-width:300px;background:white;color:#333;';
|
|
753
|
+
} else if (tag === 'textarea') {
|
|
754
|
+
el.placeholder = 'Text area...';
|
|
755
|
+
el.style.cssText = 'padding:8px 12px;border:1px solid #ccc;border-radius:6px;font-size:14px;width:100%;min-height:60px;background:white;color:#333;resize:vertical;';
|
|
756
|
+
} else if (tag === 'img') {
|
|
757
|
+
el.style.cssText = 'width:200px;height:120px;background:#e5e7eb;border-radius:8px;display:flex;align-items:center;justify-content:center;';
|
|
758
|
+
} else if (['h1','h2','h3','h4','h5','h6'].indexOf(tag) >= 0) {
|
|
759
|
+
el.textContent = payload.textContent || 'Heading';
|
|
760
|
+
var sizes = { h1:'2em', h2:'1.5em', h3:'1.25em', h4:'1.1em', h5:'1em', h6:'0.9em' };
|
|
761
|
+
el.style.cssText = 'font-size:' + (sizes[tag]||'1em') + ';font-weight:700;margin:0.5em 0;';
|
|
762
|
+
} else if (tag === 'p') {
|
|
763
|
+
el.textContent = payload.textContent || 'Paragraph text goes here.';
|
|
764
|
+
el.style.cssText = 'margin:0.5em 0;line-height:1.5;';
|
|
765
|
+
} else if (tag === 'a') {
|
|
766
|
+
el.textContent = payload.textContent || 'Link';
|
|
767
|
+
el.style.cssText = 'color:var(--accent,#3b82f6);text-decoration:underline;cursor:pointer;';
|
|
768
|
+
} else if (tag === 'section' || tag === 'div' || tag === 'nav' || tag === 'header' || tag === 'footer' || tag === 'aside' || tag === 'main') {
|
|
769
|
+
if (!payload.classes && !payload.textContent) {
|
|
770
|
+
el.style.cssText = 'min-height:40px;padding:12px;border:1.5px dashed rgba(59,130,246,0.3);border-radius:6px;background:rgba(59,130,246,0.03);';
|
|
771
|
+
} else if (payload.textContent) {
|
|
772
|
+
el.textContent = payload.textContent;
|
|
773
|
+
}
|
|
774
|
+
if (payload.category === 'layout-preset') {
|
|
775
|
+
el.style.minHeight = '60px';
|
|
776
|
+
el.style.padding = el.style.padding || '12px';
|
|
777
|
+
el.style.border = '1.5px dashed rgba(34,197,94,0.3)';
|
|
778
|
+
el.style.borderRadius = '6px';
|
|
779
|
+
el.style.background = 'rgba(34,197,94,0.03)';
|
|
780
|
+
}
|
|
781
|
+
} else if (isComponent) {
|
|
782
|
+
var vcMounted = tryMountComponent(el, payload.tag, payload.defaultProps);
|
|
783
|
+
if (!vcMounted) {
|
|
784
|
+
el.style.cssText = 'min-height:80px;padding:16px;border:1px solid rgba(168,85,247,0.2);border-radius:8px;background:rgba(168,85,247,0.03);display:flex;flex-direction:column;gap:8px;overflow:hidden;';
|
|
785
|
+
var hdr = document.createElement('div');
|
|
786
|
+
hdr.style.cssText = 'display:flex;align-items:center;gap:6px;margin-bottom:4px;';
|
|
787
|
+
var dot = document.createElement('span');
|
|
788
|
+
dot.style.cssText = 'width:6px;height:6px;border-radius:50%;background:#a855f7;';
|
|
789
|
+
hdr.appendChild(dot);
|
|
790
|
+
var tagLabel = document.createElement('span');
|
|
791
|
+
tagLabel.style.cssText = 'font-size:11px;font-weight:600;color:#a855f7;';
|
|
792
|
+
tagLabel.textContent = payload.tag;
|
|
793
|
+
hdr.appendChild(tagLabel);
|
|
794
|
+
el.appendChild(hdr);
|
|
795
|
+
}
|
|
796
|
+
} else {
|
|
797
|
+
el.textContent = payload.textContent || '';
|
|
798
|
+
}
|
|
799
|
+
return el;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
function tryMountComponent(container, componentName, props) {
|
|
803
|
+
// Try Vue
|
|
804
|
+
if (window.__ANNOTASK_VUE__) {
|
|
805
|
+
var mounted = tryMountVueComponent(container, componentName, props);
|
|
806
|
+
if (mounted) return true;
|
|
807
|
+
}
|
|
808
|
+
// Try React
|
|
809
|
+
if (window.__ANNOTASK_REACT__) {
|
|
810
|
+
var mounted = tryMountReactComponent(container, componentName, props);
|
|
811
|
+
if (mounted) return true;
|
|
812
|
+
}
|
|
813
|
+
// Try Svelte
|
|
814
|
+
if (window.__ANNOTASK_SVELTE__) {
|
|
815
|
+
var mounted = tryMountSvelteComponent(container, componentName, props);
|
|
816
|
+
if (mounted) return true;
|
|
817
|
+
}
|
|
818
|
+
return false;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
function tryMountVueComponent(container, componentName, props) {
|
|
822
|
+
try {
|
|
823
|
+
var appEl = document.querySelector('#app');
|
|
824
|
+
var vueApp = appEl && appEl.__vue_app__;
|
|
825
|
+
if (!vueApp) return false;
|
|
826
|
+
var annotaskVue = window.__ANNOTASK_VUE__;
|
|
827
|
+
if (!annotaskVue || !annotaskVue.createApp || !annotaskVue.h) return false;
|
|
828
|
+
var component = vueApp._context.components[componentName] || (window.__ANNOTASK_COMPONENTS__ && window.__ANNOTASK_COMPONENTS__[componentName]);
|
|
829
|
+
if (!component) return false;
|
|
830
|
+
var mountPoint = document.createElement('div');
|
|
831
|
+
container.appendChild(mountPoint);
|
|
832
|
+
var miniApp = annotaskVue.createApp({
|
|
833
|
+
render: function() { return annotaskVue.h(component, props || {}); }
|
|
834
|
+
});
|
|
835
|
+
miniApp._context = vueApp._context;
|
|
836
|
+
miniApp.mount(mountPoint);
|
|
837
|
+
container.setAttribute('data-annotask-mounted', 'true');
|
|
838
|
+
container.__annotask_unmount = function() { try { miniApp.unmount(); } catch(e) {} };
|
|
839
|
+
return true;
|
|
840
|
+
} catch(e) { return false; }
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
function tryMountReactComponent(container, componentName, props) {
|
|
844
|
+
try {
|
|
845
|
+
var annotaskReact = window.__ANNOTASK_REACT__;
|
|
846
|
+
if (!annotaskReact || !annotaskReact.createElement || !annotaskReact.createRoot) return false;
|
|
847
|
+
var component = window.__ANNOTASK_COMPONENTS__ && window.__ANNOTASK_COMPONENTS__[componentName];
|
|
848
|
+
if (!component) return false;
|
|
849
|
+
var mountPoint = document.createElement('div');
|
|
850
|
+
container.appendChild(mountPoint);
|
|
851
|
+
var root = annotaskReact.createRoot(mountPoint);
|
|
852
|
+
root.render(annotaskReact.createElement(component, props || {}));
|
|
853
|
+
container.setAttribute('data-annotask-mounted', 'true');
|
|
854
|
+
container.__annotask_unmount = function() { try { root.unmount(); } catch(e) {} };
|
|
855
|
+
return true;
|
|
856
|
+
} catch(e) { return false; }
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
function tryMountSvelteComponent(container, componentName, props) {
|
|
860
|
+
try {
|
|
861
|
+
var annotaskSvelte = window.__ANNOTASK_SVELTE__;
|
|
862
|
+
if (!annotaskSvelte || !annotaskSvelte.mount) return false;
|
|
863
|
+
var component = window.__ANNOTASK_COMPONENTS__ && window.__ANNOTASK_COMPONENTS__[componentName];
|
|
864
|
+
if (!component) return false;
|
|
865
|
+
var mountPoint = document.createElement('div');
|
|
866
|
+
container.appendChild(mountPoint);
|
|
867
|
+
var instance = annotaskSvelte.mount(component, { target: mountPoint, props: props || {} });
|
|
868
|
+
container.setAttribute('data-annotask-mounted', 'true');
|
|
869
|
+
container.__annotask_unmount = function() {
|
|
870
|
+
try {
|
|
871
|
+
if (annotaskSvelte.unmount) annotaskSvelte.unmount(instance);
|
|
872
|
+
} catch(e) {}
|
|
873
|
+
};
|
|
874
|
+
return true;
|
|
875
|
+
} catch(e) { return false; }
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
// \u2500\u2500 Ready \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
879
|
+
sendToShell('bridge:ready', { version: '1.0' });
|
|
880
|
+
})();
|
|
881
|
+
`.trim();
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
export {
|
|
885
|
+
toggleButtonScript,
|
|
886
|
+
bridgeClientScript
|
|
887
|
+
};
|
|
888
|
+
//# sourceMappingURL=chunk-VI4NPM6C.js.map
|