annotask 0.0.0

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