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