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