annotask 0.0.6 → 0.0.8

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 @@
1
+ {"version":3,"sources":["../src/plugin/bridge-client.ts"],"sourcesContent":["/**\n * Client bridge script injected into the user's app.\n * Communicates with the Annotask shell via postMessage.\n * Handles all DOM interactions: hover, click, style reads/writes,\n * element resolution, layout scanning, etc.\n *\n * Returned as an inline string (same pattern as toggle-button.ts).\n */\nexport function bridgeClientScript(): string {\n return `\n(function() {\n // Don't run inside the Annotask shell\n if (window.location.pathname.startsWith('/__annotask')) return;\n // Don't run if already initialized\n if (window.__ANNOTASK_BRIDGE__) return;\n window.__ANNOTASK_BRIDGE__ = true;\n\n // ── Element Registry ──────────────────────────────────\n var eidCounter = 0;\n var eidMap = new Map(); // eid string → WeakRef<Element>\n var elToEid = new WeakMap(); // Element → eid string\n\n function getEid(el) {\n if (!el) return null;\n var existing = elToEid.get(el);\n if (existing) return existing;\n eidCounter++;\n var eid = 'e-' + eidCounter;\n eidMap.set(eid, new WeakRef(el));\n elToEid.set(el, eid);\n return eid;\n }\n\n function getEl(eid) {\n var ref = eidMap.get(eid);\n return ref ? ref.deref() || null : null;\n }\n\n // ── PostMessage Helpers ───────────────────────────────\n var shellOrigin = '*'; // Will be tightened on first shell message\n\n function sendToShell(type, payload, id) {\n var msg = { type: type, payload: payload || {}, source: 'annotask-client' };\n if (id) msg.id = id;\n window.parent.postMessage(msg, shellOrigin);\n }\n\n function respond(id, payload) {\n sendToShell(null, payload, id);\n // type is not needed for responses — shell matches by id\n }\n\n // ── Source Element Resolution ─────────────────────────\n function hasSourceAttr(el) {\n return el.hasAttribute && (el.hasAttribute('data-annotask-file') || el.hasAttribute('data-astro-source-file'));\n }\n\n function findSourceElement(el) {\n var c = el;\n while (c) {\n if (hasSourceAttr(c)) return { sourceEl: c, targetEl: el };\n c = c.parentElement;\n }\n return { sourceEl: el, targetEl: el };\n }\n\n function getSourceData(el) {\n // Prefer data-annotask-* attributes, fall back to data-astro-source-* (Astro framework)\n var file = el.getAttribute('data-annotask-file') || '';\n var line = el.getAttribute('data-annotask-line') || '';\n var component = el.getAttribute('data-annotask-component') || '';\n\n if (!file && el.getAttribute('data-astro-source-file')) {\n var astroFile = el.getAttribute('data-astro-source-file') || '';\n // Convert absolute path to project-relative by finding src/ prefix\n var srcIdx = astroFile.indexOf('/src/');\n file = srcIdx !== -1 ? astroFile.slice(srcIdx + 1) : astroFile;\n }\n if ((!line || line === '0') && el.getAttribute('data-astro-source-loc')) {\n // data-astro-source-loc format: \"line:col\"\n line = (el.getAttribute('data-astro-source-loc') || '').split(':')[0];\n }\n if (!component && file) {\n // Derive component name from file path\n var parts = file.split('/');\n var fileName = parts[parts.length - 1] || '';\n component = fileName.replace(/\\.[^.]+$/, '');\n }\n\n var mfe = el.getAttribute('data-annotask-mfe') || '';\n\n return { file: file, line: line, component: component, mfe: mfe };\n }\n\n function getRect(el) {\n var r = el.getBoundingClientRect();\n return { x: r.x, y: r.y, width: r.width, height: r.height };\n }\n\n // ── Interaction Mode ──────────────────────────────────\n var storedMode = '';\n try { storedMode = localStorage.getItem('annotask:mode') || ''; } catch(e) {}\n var currentMode = storedMode || 'select';\n var inspectModes = { select: true, pin: true };\n\n // ── Event Handlers ────────────────────────────────────\n var lastHoverEid = null;\n var rafPending = false;\n var pendingHoverData = null;\n\n function onMouseOver(e) {\n if (!inspectModes[currentMode]) return;\n var el = e.target;\n if (!el || el === document.documentElement || el === document.body) return;\n var eid = getEid(el);\n if (eid === lastHoverEid) return;\n lastHoverEid = eid;\n\n var source = findSourceElement(el);\n var data = getSourceData(source.sourceEl);\n\n pendingHoverData = {\n eid: eid,\n tag: el.tagName.toLowerCase(),\n file: data.file,\n component: data.component,\n rect: getRect(el)\n };\n\n if (!rafPending) {\n rafPending = true;\n requestAnimationFrame(function() {\n rafPending = false;\n if (pendingHoverData) sendToShell('hover:enter', pendingHoverData);\n });\n }\n }\n\n function onMouseOut(e) {\n if (!inspectModes[currentMode]) return;\n // Only fire leave when truly leaving all elements\n if (e.relatedTarget && e.relatedTarget !== document.documentElement) return;\n lastHoverEid = null;\n pendingHoverData = null;\n sendToShell('hover:leave', {});\n }\n\n function onClick(e) {\n if (!inspectModes[currentMode]) return;\n e.preventDefault();\n e.stopPropagation();\n\n var el = e.target;\n if (!el) return;\n\n var source = findSourceElement(el);\n var data = getSourceData(source.sourceEl);\n var targetEl = source.targetEl;\n var classes = typeof targetEl.className === 'string' ? targetEl.className : '';\n\n sendToShell('click:element', {\n eid: getEid(targetEl),\n sourceEid: getEid(source.sourceEl),\n file: data.file,\n line: data.line,\n component: data.component,\n mfe: data.mfe,\n tag: targetEl.tagName.toLowerCase(),\n classes: classes,\n rect: getRect(targetEl),\n shiftKey: e.shiftKey,\n clientX: e.clientX,\n clientY: e.clientY\n });\n }\n\n function onMouseDown(e) {\n if (!inspectModes[currentMode]) return;\n e.stopPropagation();\n }\n\n function onMouseUp(e) {\n if (currentMode !== 'highlight') return;\n var sel = document.getSelection();\n var text = sel ? sel.toString().trim() : '';\n if (!text || text.length < 2) return;\n var anchorEl = sel.anchorNode ? sel.anchorNode.parentElement : null;\n if (!anchorEl) return;\n var source = findSourceElement(anchorEl);\n var data = getSourceData(source.sourceEl);\n\n sendToShell('selection:text', {\n text: text,\n eid: getEid(anchorEl),\n file: data.file,\n line: parseInt(data.line) || 0,\n component: data.component,\n mfe: data.mfe,\n tag: anchorEl.tagName.toLowerCase()\n });\n }\n\n function onContextMenu(e) {\n if (currentMode === 'interact') return;\n e.preventDefault();\n var el = e.target;\n if (!el) return;\n var source = findSourceElement(el);\n var data = getSourceData(source.sourceEl);\n var targetEl = source.targetEl;\n var classes = typeof targetEl.className === 'string' ? targetEl.className : '';\n\n sendToShell('contextmenu:element', {\n eid: getEid(targetEl),\n sourceEid: getEid(source.sourceEl),\n file: data.file,\n line: data.line,\n component: data.component,\n mfe: data.mfe,\n tag: targetEl.tagName.toLowerCase(),\n classes: classes,\n rect: getRect(targetEl),\n shiftKey: false,\n clientX: e.clientX,\n clientY: e.clientY\n });\n }\n\n function onKeyDown(e) {\n if ((e.ctrlKey || e.metaKey) && e.key === 'z' && !e.shiftKey) {\n e.preventDefault();\n sendToShell('keydown', { key: e.key, ctrlKey: e.ctrlKey, metaKey: e.metaKey, shiftKey: e.shiftKey });\n }\n }\n\n // Install event listeners\n document.addEventListener('mouseover', onMouseOver, { capture: true });\n document.addEventListener('mouseout', onMouseOut, { capture: true });\n document.addEventListener('mousedown', onMouseDown, { capture: true });\n document.addEventListener('click', onClick, { capture: true });\n document.addEventListener('mouseup', onMouseUp, { capture: true });\n document.addEventListener('keydown', onKeyDown, { capture: true });\n document.addEventListener('contextmenu', onContextMenu, { capture: true });\n\n // ── User Action Tracking (interact mode) ───────────────\n // Tracks meaningful page actions (link/button clicks) so the LLM\n // can understand what the user did to reach the current state.\n\n var lastActionTs = 0;\n function onUserAction(e) {\n var el = e.target;\n if (!el || !el.closest) return;\n\n // Debounce — ignore clicks within 50ms (same gesture)\n var now = Date.now();\n if (now - lastActionTs < 50) return;\n lastActionTs = now;\n\n // Find the best description of what was clicked\n var actionEl = el.closest('a, button, [role=\"button\"], [role=\"tab\"], [role=\"menuitem\"], [role=\"link\"], [type=\"submit\"], tr[class*=\"row\"], [data-pc-section=\"bodyrow\"]');\n var descEl = actionEl || el;\n\n var tag = descEl.tagName.toLowerCase();\n // Get concise text: prefer innerText of the immediate target, fall back to closest actionable\n var text = '';\n if (el.innerText) text = el.innerText.trim();\n if (!text && descEl.innerText) text = descEl.innerText.trim();\n text = text.split(String.fromCharCode(10))[0].substring(0, 60);\n\n var href = '';\n if (tag === 'a') href = descEl.getAttribute('href') || '';\n else if (el.closest('a')) href = el.closest('a').getAttribute('href') || '';\n\n // Get component context if available\n var source = findSourceElement(descEl);\n var data = getSourceData(source.sourceEl);\n\n sendToShell('user:action', {\n tag: tag,\n text: text,\n href: href,\n component: data.component || '',\n });\n }\n\n document.addEventListener('click', onUserAction, { capture: true });\n\n // ── Route Tracking ────────────────────────────────────\n var lastRoute = window.location.pathname;\n\n function checkRoute() {\n var path = window.location.pathname;\n if (path !== lastRoute) {\n lastRoute = path;\n sendToShell('route:changed', { path: path });\n }\n }\n\n window.addEventListener('popstate', checkRoute);\n window.addEventListener('hashchange', checkRoute);\n setInterval(checkRoute, 2000); // safety net for pushState\n\n // ── Message Handler ───────────────────────────────────\n window.addEventListener('message', function(event) {\n var msg = event.data;\n if (!msg || msg.source !== 'annotask-shell') return;\n // Tighten origin on first shell message\n if (shellOrigin === '*' && event.origin) shellOrigin = event.origin;\n\n var type = msg.type;\n var payload = msg.payload || {};\n var id = msg.id;\n\n // ── Mode ──\n if (type === 'mode:set') {\n currentMode = payload.mode || 'select';\n try { localStorage.setItem('annotask:mode', currentMode); } catch(e) {}\n return;\n }\n\n // ── Ping ──\n if (type === 'bridge:ping') {\n respond(id, {});\n return;\n }\n\n // ── Element Resolution ──\n if (type === 'resolve:at-point') {\n var el = document.elementFromPoint(payload.x, payload.y);\n if (!el || el === document.documentElement || el === document.body) {\n respond(id, null);\n return;\n }\n var src = findSourceElement(el);\n var srcData = getSourceData(src.sourceEl);\n respond(id, {\n eid: getEid(src.targetEl),\n file: srcData.file,\n line: srcData.line,\n component: srcData.component,\n mfe: srcData.mfe,\n tag: src.sourceEl.tagName.toLowerCase(),\n rect: getRect(src.sourceEl),\n classes: typeof src.targetEl.className === 'string' ? src.targetEl.className : ''\n });\n return;\n }\n\n if (type === 'resolve:template-group') {\n var all = document.querySelectorAll(\n '[data-annotask-file=\"' + payload.file + '\"][data-annotask-line=\"' + payload.line + '\"]'\n );\n // Also check Astro source attributes\n if (all.length === 0 && payload.file && payload.line) {\n // Try matching by astro source attributes (absolute path ends with file, loc starts with line)\n var astroAll = document.querySelectorAll('[data-astro-source-file]');\n var matched = [];\n for (var ai = 0; ai < astroAll.length; ai++) {\n var af = astroAll[ai].getAttribute('data-astro-source-file') || '';\n var al = (astroAll[ai].getAttribute('data-astro-source-loc') || '').split(':')[0];\n if (af.endsWith('/' + payload.file) && al === payload.line) matched.push(astroAll[ai]);\n }\n if (matched.length > 0) all = matched;\n }\n var eids = [];\n var rects = [];\n for (var i = 0; i < all.length; i++) {\n if (all[i].tagName.toLowerCase() === payload.tagName) {\n eids.push(getEid(all[i]));\n rects.push(getRect(all[i]));\n }\n }\n respond(id, { eids: eids, rects: rects });\n return;\n }\n\n if (type === 'resolve:rect') {\n var rEl = getEl(payload.eid);\n respond(id, rEl ? { rect: getRect(rEl) } : null);\n return;\n }\n\n if (type === 'resolve:rects') {\n var results = [];\n for (var j = 0; j < payload.eids.length; j++) {\n var re = getEl(payload.eids[j]);\n results.push(re ? getRect(re) : null);\n }\n respond(id, { rects: results });\n return;\n }\n\n // ── Style Operations ──\n if (type === 'style:get-computed') {\n var sEl = getEl(payload.eid);\n if (!sEl) { respond(id, { styles: {} }); return; }\n var cs = window.getComputedStyle(sEl);\n var styles = {};\n for (var k = 0; k < payload.properties.length; k++) {\n styles[payload.properties[k]] = cs.getPropertyValue(payload.properties[k]);\n }\n respond(id, { styles: styles });\n return;\n }\n\n if (type === 'style:apply') {\n var aEl = getEl(payload.eid);\n if (!aEl) { respond(id, { before: '' }); return; }\n var before = window.getComputedStyle(aEl).getPropertyValue(payload.property);\n aEl.style.setProperty(payload.property, payload.value);\n respond(id, { before: before });\n return;\n }\n\n if (type === 'style:apply-batch') {\n var befores = [];\n for (var m = 0; m < payload.eids.length; m++) {\n var bEl = getEl(payload.eids[m]);\n if (bEl) {\n befores.push(window.getComputedStyle(bEl).getPropertyValue(payload.property));\n bEl.style.setProperty(payload.property, payload.value);\n } else {\n befores.push('');\n }\n }\n respond(id, { befores: befores });\n return;\n }\n\n if (type === 'style:undo') {\n var uEl = getEl(payload.eid);\n if (uEl) {\n if (payload.value) uEl.style.setProperty(payload.property, payload.value);\n else uEl.style.removeProperty(payload.property);\n }\n respond(id, {});\n return;\n }\n\n if (type === 'class:get') {\n var cEl = getEl(payload.eid);\n respond(id, { classes: cEl ? (typeof cEl.className === 'string' ? cEl.className : '') : '' });\n return;\n }\n\n if (type === 'class:set') {\n var csEl = getEl(payload.eid);\n if (!csEl) { respond(id, { before: '' }); return; }\n var classBefore = typeof csEl.className === 'string' ? csEl.className : '';\n csEl.className = payload.classes;\n respond(id, { before: classBefore });\n return;\n }\n\n if (type === 'class:set-batch') {\n var classBefores = [];\n for (var n = 0; n < payload.eids.length; n++) {\n var cbEl = getEl(payload.eids[n]);\n if (cbEl) {\n classBefores.push(typeof cbEl.className === 'string' ? cbEl.className : '');\n cbEl.className = payload.classes;\n } else {\n classBefores.push('');\n }\n }\n respond(id, { befores: classBefores });\n return;\n }\n\n if (type === 'class:undo') {\n var cuEl = getEl(payload.eid);\n if (cuEl) cuEl.className = payload.classes;\n respond(id, {});\n return;\n }\n\n // ── Classification ──\n if (type === 'classify:element') {\n var clEl = getEl(payload.eid);\n if (!clEl) { respond(id, null); return; }\n var tag = clEl.tagName.toLowerCase();\n var clCs = window.getComputedStyle(clEl);\n var display = clCs.display;\n var childCount = clEl.children.length;\n var isFlex = display.includes('flex');\n var isGrid = display.includes('grid');\n var semanticContainers = ['section','main','aside','nav','header','footer','article'];\n var role = 'content';\n if (clEl.hasAttribute('data-annotask-component')) {\n var comp = clEl.getAttribute('data-annotask-component') || '';\n if (comp && comp[0] === comp[0].toUpperCase() && comp[0] !== comp[0].toLowerCase()) {\n role = 'component';\n }\n }\n if (role !== 'component' && (isFlex || isGrid) && childCount > 0) role = 'container';\n if (role !== 'component' && role !== 'container' && semanticContainers.indexOf(tag) >= 0 && childCount > 0) role = 'container';\n\n respond(id, {\n role: role,\n display: display,\n isFlexContainer: isFlex,\n isGridContainer: isGrid,\n flexDirection: isFlex ? clCs.flexDirection : undefined,\n childCount: childCount,\n isComponentUnit: role === 'component'\n });\n return;\n }\n\n if (type === 'resolve:element-context') {\n var ctxEl = getEl(payload.eid);\n if (!ctxEl) { respond(id, null); return; }\n\n // Ancestors: walk up 3 levels, capture layout-relevant styles\n var ancestors = [];\n var cur = ctxEl.parentElement;\n for (var ai = 0; ai < 3 && cur && cur !== document.body && cur !== document.documentElement; ai++) {\n var aCs = window.getComputedStyle(cur);\n var aTag = cur.tagName.toLowerCase();\n var aClasses = typeof cur.className === 'string' ? cur.className.trim() : '';\n var aData = getSourceData(cur);\n var ancestor = { tag: aTag, display: aCs.display };\n if (aClasses) ancestor.classes = aClasses;\n if (aData.component) ancestor.component = aData.component;\n if (aCs.display.includes('flex')) {\n ancestor.flexDirection = aCs.flexDirection;\n if (aCs.gap && aCs.gap !== 'normal') ancestor.gap = aCs.gap;\n ancestor.childCount = cur.children.length;\n }\n if (aCs.display.includes('grid')) {\n ancestor.gridTemplateColumns = aCs.gridTemplateColumns;\n ancestor.gridTemplateRows = aCs.gridTemplateRows;\n if (aCs.gap && aCs.gap !== 'normal') ancestor.gap = aCs.gap;\n ancestor.childCount = cur.children.length;\n }\n if (aCs.overflow && aCs.overflow !== 'visible') ancestor.overflow = aCs.overflow;\n ancestors.push(ancestor);\n cur = cur.parentElement;\n }\n\n // Subtree: simplified HTML of the element and its children (3 levels deep)\n function describeEl(el, depth) {\n var t = el.tagName.toLowerCase();\n var cl = typeof el.className === 'string' ? el.className.trim() : '';\n var txt = '';\n // Only get direct text (not from children)\n for (var ci = 0; ci < el.childNodes.length; ci++) {\n if (el.childNodes[ci].nodeType === 3) {\n var nt = el.childNodes[ci].textContent.trim();\n if (nt) { txt = nt.substring(0, 40); break; }\n }\n }\n var node = { tag: t };\n if (cl) node.classes = cl;\n if (txt) node.text = txt;\n if (depth < 3 && el.children.length > 0) {\n var kids = [];\n for (var ki = 0; ki < el.children.length && ki < 10; ki++) {\n kids.push(describeEl(el.children[ki], depth + 1));\n }\n node.children = kids;\n if (el.children.length > 10) node.childrenTruncated = el.children.length;\n }\n return node;\n }\n\n respond(id, {\n ancestors: ancestors,\n subtree: describeEl(ctxEl, 0)\n });\n return;\n }\n\n // ── Accessibility Scan ──\n if (type === 'a11y:scan') {\n var a11yEid = payload.eid;\n var a11yEl = a11yEid ? getEl(a11yEid) : document.body;\n if (!a11yEl) { respond(id, { violations: [] }); return; }\n\n function runAxeScan(target) {\n if (!window.axe) { respond(id, { violations: [], error: 'axe not loaded' }); return; }\n window.axe.run(target, { resultTypes: ['violations'] }, function(err, results) {\n if (err) { respond(id, { violations: [], error: err.message }); return; }\n var violations = [];\n for (var vi = 0; vi < results.violations.length; vi++) {\n var v = results.violations[vi];\n var nodeDetails = [];\n for (var ni = 0; ni < v.nodes.length && ni < 5; ni++) {\n var node = v.nodes[ni];\n var detail = {\n html: (node.html || '').substring(0, 200),\n target: node.target ? node.target[0] : '',\n failureSummary: node.failureSummary || ''\n };\n // Try to resolve annotask source for this element\n var selector = node.target ? node.target[0] : null;\n if (selector) {\n try {\n var domEl = document.querySelector(selector);\n if (domEl) {\n var src = findSourceElement(domEl);\n var srcData = getSourceData(src.sourceEl);\n if (srcData.file) {\n detail.file = srcData.file;\n detail.line = srcData.line;\n detail.component = srcData.component;\n }\n }\n } catch(e) {}\n }\n nodeDetails.push(detail);\n }\n violations.push({\n id: v.id,\n impact: v.impact,\n description: v.description,\n help: v.help,\n helpUrl: v.helpUrl,\n nodes: v.nodes.length,\n elements: nodeDetails\n });\n }\n respond(id, { violations: violations });\n });\n }\n\n if (window.axe) {\n runAxeScan(a11yEl);\n } else {\n var script = document.createElement('script');\n script.src = '/__annotask/vendor/axe-core.min.js';\n script.onload = function() { runAxeScan(a11yEl); };\n script.onerror = function() { respond(id, { violations: [], error: 'failed to load axe-core — run: pnpm build:vendor' }); };\n document.head.appendChild(script);\n }\n return;\n }\n\n // ── Screenshot Capture ──\n if (type === 'screenshot:capture') {\n var clipRect = payload.rect;\n\n function doCapture(clip) {\n if (!window.html2canvas) {\n respond(id, { error: 'html2canvas not loaded' });\n return;\n }\n var opts = { useCORS: true, logging: false, allowTaint: true };\n if (clip) {\n opts.x = clip.x;\n opts.y = clip.y;\n opts.width = clip.width;\n opts.height = clip.height;\n }\n window.html2canvas(document.body, opts).then(function(canvas) {\n var dataUrl = canvas.toDataURL('image/png');\n respond(id, { dataUrl: dataUrl });\n }).catch(function(err) {\n respond(id, { error: err.message || 'capture failed' });\n });\n }\n\n if (window.html2canvas) {\n doCapture(clipRect);\n } else {\n var h2cScript = document.createElement('script');\n h2cScript.src = '/__annotask/vendor/html2canvas.min.js';\n h2cScript.onload = function() { doCapture(clipRect); };\n h2cScript.onerror = function() { respond(id, { error: 'failed to load html2canvas — run: pnpm build:vendor' }); };\n document.head.appendChild(h2cScript);\n }\n return;\n }\n\n // ── Layout Scan ──\n if (type === 'layout:scan') {\n var layoutResults = [];\n var allEls = document.querySelectorAll('*');\n for (var li = 0; li < allEls.length; li++) {\n var lEl = allEls[li];\n if (lEl.nodeType !== 1) continue;\n var lCs = window.getComputedStyle(lEl);\n var lDisplay = lCs.display;\n if (!lDisplay.includes('flex') && !lDisplay.includes('grid')) continue;\n var lRect = lEl.getBoundingClientRect();\n if (lRect.width < 20 || lRect.height < 20) continue;\n var lIsGrid = lDisplay.includes('grid');\n var entry = {\n eid: getEid(lEl),\n display: lIsGrid ? 'grid' : 'flex',\n direction: lIsGrid ? 'grid' : lCs.flexDirection,\n rect: { x: lRect.x, y: lRect.y, width: lRect.width, height: lRect.height },\n columnGap: parseFloat(lCs.columnGap) || 0,\n rowGap: parseFloat(lCs.rowGap) || 0\n };\n if (lIsGrid) {\n var cols = lCs.gridTemplateColumns;\n var rows = lCs.gridTemplateRows;\n entry.templateColumns = cols;\n entry.templateRows = rows;\n if (cols && cols !== 'none') {\n entry.columns = cols.split(/\\\\s+/).map(function(s) { return parseFloat(s) || 0; }).filter(function(v) { return v > 0; });\n }\n if (rows && rows !== 'none') {\n entry.rows = rows.split(/\\\\s+/).map(function(s) { return parseFloat(s) || 0; }).filter(function(v) { return v > 0; });\n }\n }\n layoutResults.push(entry);\n }\n respond(id, { containers: layoutResults });\n return;\n }\n\n if (type === 'layout:add-track') {\n var ltEl = getEl(payload.eid);\n if (!ltEl) { respond(id, { property: '', before: '', after: '' }); return; }\n var ltCs = window.getComputedStyle(ltEl);\n var cssProp = payload.axis === 'col' ? 'grid-template-columns' : 'grid-template-rows';\n var ltBefore = ltCs.getPropertyValue(cssProp) || '';\n var ltAfter = ltBefore && ltBefore !== 'none' ? ltBefore + ' 1fr' : '1fr';\n ltEl.style.setProperty(cssProp, ltAfter);\n respond(id, { property: cssProp, before: ltBefore, after: ltAfter });\n return;\n }\n\n if (type === 'layout:add-child') {\n var lcEl = getEl(payload.eid);\n if (!lcEl) { respond(id, { childEid: '' }); return; }\n var child = document.createElement('div');\n child.style.minWidth = '60px';\n child.style.minHeight = '40px';\n child.style.border = '2px dashed #a855f7';\n child.style.borderRadius = '4px';\n child.style.background = 'rgba(168,85,247,0.05)';\n child.setAttribute('data-annotask-placeholder', 'true');\n lcEl.appendChild(child);\n respond(id, { childEid: getEid(child) });\n return;\n }\n\n // ── Theme ──\n if (type === 'theme:inject-css') {\n var existing = document.getElementById(payload.styleId);\n if (existing) {\n existing.textContent = payload.css;\n } else {\n var style = document.createElement('style');\n style.id = payload.styleId;\n style.textContent = payload.css;\n document.head.appendChild(style);\n }\n respond(id, {});\n return;\n }\n\n if (type === 'theme:remove-css') {\n var toRemove = document.getElementById(payload.styleId);\n if (toRemove) toRemove.remove();\n respond(id, {});\n return;\n }\n\n // ── Color Palette ──\n if (type === 'palette:scan-vars') {\n var swatches = [];\n try {\n var rootStyles = window.getComputedStyle(document.documentElement);\n var sheets = document.styleSheets;\n for (var si = 0; si < sheets.length; si++) {\n try {\n var rules = sheets[si].cssRules;\n for (var ri = 0; ri < rules.length; ri++) {\n var rule = rules[ri];\n if (rule.selectorText === ':root' || rule.selectorText === ':root, :host') {\n for (var pi = 0; pi < rule.style.length; pi++) {\n var prop = rule.style[pi];\n if (prop.startsWith('--')) {\n var val = rootStyles.getPropertyValue(prop).trim();\n if (val && isColor(val)) {\n swatches.push({ name: prop, value: val });\n }\n }\n }\n }\n }\n } catch(e) { /* cross-origin stylesheet */ }\n }\n } catch(e) {}\n respond(id, { swatches: swatches });\n return;\n }\n\n // ── Source Mapping Check ──\n if (type === 'check:source-mapping') {\n respond(id, { hasMapping: !!(document.querySelector('[data-annotask-file]') || document.querySelector('[data-astro-source-file]')) });\n return;\n }\n\n // ── Insert Placeholder ──\n if (type === 'insert:placeholder') {\n var ipTarget = getEl(payload.targetEid);\n if (!ipTarget) { respond(id, { placeholderEid: '' }); return; }\n var ipEl = createPlaceholder(payload);\n var ipRef = ipTarget;\n switch (payload.position) {\n case 'before': ipRef.parentElement && ipRef.parentElement.insertBefore(ipEl, ipRef); break;\n case 'after': ipRef.parentElement && ipRef.parentElement.insertBefore(ipEl, ipRef.nextSibling); break;\n case 'append': ipRef.appendChild(ipEl); break;\n case 'prepend': ipRef.insertBefore(ipEl, ipRef.firstChild); break;\n }\n // Match sibling sizes in flex/grid\n var insertParent = (payload.position === 'append' || payload.position === 'prepend') ? ipRef : ipRef.parentElement;\n if (insertParent) {\n var pCs = window.getComputedStyle(insertParent);\n if (pCs.display.includes('flex') || pCs.display.includes('grid')) {\n if (!ipEl.style.width) {\n var isRow = pCs.flexDirection === 'row' || pCs.flexDirection === 'row-reverse' || pCs.display.includes('grid');\n if (isRow) ipEl.style.flex = '1';\n }\n }\n }\n respond(id, { placeholderEid: getEid(ipEl) });\n return;\n }\n\n if (type === 'insert:remove') {\n var irEl = getEl(payload.eid);\n if (irEl) {\n var unmount = irEl.__annotask_unmount;\n if (unmount) unmount();\n irEl.remove();\n }\n respond(id, {});\n return;\n }\n\n if (type === 'move:element') {\n var meEl = getEl(payload.eid);\n var meTarget = getEl(payload.targetEid);\n if (meEl && meTarget) {\n switch (payload.position) {\n case 'before': meTarget.parentElement && meTarget.parentElement.insertBefore(meEl, meTarget); break;\n case 'after': meTarget.parentElement && meTarget.parentElement.insertBefore(meEl, meTarget.nextSibling); break;\n case 'append': meTarget.appendChild(meEl); break;\n case 'prepend': meTarget.insertBefore(meEl, meTarget.firstChild); break;\n }\n }\n respond(id, {});\n return;\n }\n\n if (type === 'insert:vue-component' || type === 'insert:component') {\n var vcTarget = getEl(payload.targetEid);\n if (!vcTarget) { respond(id, { eid: '', mounted: false }); return; }\n var vcContainer = document.createElement('div');\n vcContainer.setAttribute('data-annotask-placeholder', 'true');\n switch (payload.position) {\n case 'before': vcTarget.parentElement && vcTarget.parentElement.insertBefore(vcContainer, vcTarget); break;\n case 'after': vcTarget.parentElement && vcTarget.parentElement.insertBefore(vcContainer, vcTarget.nextSibling); break;\n case 'append': vcTarget.appendChild(vcContainer); break;\n case 'prepend': vcTarget.insertBefore(vcContainer, vcTarget.firstChild); break;\n }\n var mounted = tryMountComponent(vcContainer, payload.componentName, payload.props);\n respond(id, { eid: getEid(vcContainer), mounted: mounted });\n return;\n }\n\n // ── Get source data for an eid ──\n if (type === 'resolve:source') {\n var rsEl = getEl(payload.eid);\n if (!rsEl) { respond(id, null); return; }\n var rsSrc = findSourceElement(rsEl);\n var rsData = getSourceData(rsSrc.sourceEl);\n respond(id, {\n sourceEid: getEid(rsSrc.sourceEl),\n file: rsData.file,\n line: rsData.line,\n component: rsData.component,\n tag: rsSrc.sourceEl.tagName.toLowerCase()\n });\n return;\n }\n\n // ── Route ──\n if (type === 'route:current') {\n respond(id, { path: window.location.pathname });\n return;\n }\n });\n\n // ── Helpers ───────────────────────────────────────────\n function isColor(val) {\n if (val.startsWith('#') || val.startsWith('rgb') || val.startsWith('hsl')) return true;\n // Named colors — quick check with canvas\n try {\n var ctx = document.createElement('canvas').getContext('2d');\n ctx.fillStyle = '#000000';\n ctx.fillStyle = val;\n return ctx.fillStyle !== '#000000' || val === 'black' || val === '#000000';\n } catch(e) { return false; }\n }\n\n function createPlaceholder(payload) {\n var el = document.createElement(payload.tag);\n el.setAttribute('data-annotask-placeholder', 'true');\n if (payload.classes) el.className = payload.classes;\n var tag = payload.tag.toLowerCase();\n var isComponent = payload.tag.includes('-') || (payload.tag[0] === payload.tag[0].toUpperCase() && payload.tag[0] !== payload.tag[0].toLowerCase());\n\n if (tag === 'button') {\n el.textContent = payload.textContent || 'Button';\n 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;';\n } else if (tag === 'input') {\n el.type = 'text'; el.placeholder = 'Input field...';\n 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;';\n } else if (tag === 'textarea') {\n el.placeholder = 'Text area...';\n 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;';\n } else if (tag === 'img') {\n el.style.cssText = 'width:200px;height:120px;background:#e5e7eb;border-radius:8px;display:flex;align-items:center;justify-content:center;';\n } else if (['h1','h2','h3','h4','h5','h6'].indexOf(tag) >= 0) {\n el.textContent = payload.textContent || 'Heading';\n var sizes = { h1:'2em', h2:'1.5em', h3:'1.25em', h4:'1.1em', h5:'1em', h6:'0.9em' };\n el.style.cssText = 'font-size:' + (sizes[tag]||'1em') + ';font-weight:700;margin:0.5em 0;';\n } else if (tag === 'p') {\n el.textContent = payload.textContent || 'Paragraph text goes here.';\n el.style.cssText = 'margin:0.5em 0;line-height:1.5;';\n } else if (tag === 'a') {\n el.textContent = payload.textContent || 'Link';\n el.style.cssText = 'color:var(--accent,#3b82f6);text-decoration:underline;cursor:pointer;';\n } else if (tag === 'section' || tag === 'div' || tag === 'nav' || tag === 'header' || tag === 'footer' || tag === 'aside' || tag === 'main') {\n if (!payload.classes && !payload.textContent) {\n 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);';\n } else if (payload.textContent) {\n el.textContent = payload.textContent;\n }\n if (payload.category === 'layout-preset') {\n el.style.minHeight = '60px';\n el.style.padding = el.style.padding || '12px';\n el.style.border = '1.5px dashed rgba(34,197,94,0.3)';\n el.style.borderRadius = '6px';\n el.style.background = 'rgba(34,197,94,0.03)';\n }\n } else if (isComponent) {\n var vcMounted = tryMountComponent(el, payload.tag, payload.defaultProps);\n if (!vcMounted) {\n 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;';\n var hdr = document.createElement('div');\n hdr.style.cssText = 'display:flex;align-items:center;gap:6px;margin-bottom:4px;';\n var dot = document.createElement('span');\n dot.style.cssText = 'width:6px;height:6px;border-radius:50%;background:#a855f7;';\n hdr.appendChild(dot);\n var tagLabel = document.createElement('span');\n tagLabel.style.cssText = 'font-size:11px;font-weight:600;color:#a855f7;';\n tagLabel.textContent = payload.tag;\n hdr.appendChild(tagLabel);\n el.appendChild(hdr);\n }\n } else {\n el.textContent = payload.textContent || '';\n }\n return el;\n }\n\n function tryMountComponent(container, componentName, props) {\n // Try Vue\n if (window.__ANNOTASK_VUE__) {\n var mounted = tryMountVueComponent(container, componentName, props);\n if (mounted) return true;\n }\n // Try React\n if (window.__ANNOTASK_REACT__) {\n var mounted = tryMountReactComponent(container, componentName, props);\n if (mounted) return true;\n }\n // Try Svelte\n if (window.__ANNOTASK_SVELTE__) {\n var mounted = tryMountSvelteComponent(container, componentName, props);\n if (mounted) return true;\n }\n return false;\n }\n\n function tryMountVueComponent(container, componentName, props) {\n try {\n var appEl = document.querySelector('#app');\n var vueApp = appEl && appEl.__vue_app__;\n if (!vueApp) return false;\n var annotaskVue = window.__ANNOTASK_VUE__;\n if (!annotaskVue || !annotaskVue.createApp || !annotaskVue.h) return false;\n var component = vueApp._context.components[componentName] || (window.__ANNOTASK_COMPONENTS__ && window.__ANNOTASK_COMPONENTS__[componentName]);\n if (!component) return false;\n var mountPoint = document.createElement('div');\n container.appendChild(mountPoint);\n var miniApp = annotaskVue.createApp({\n render: function() { return annotaskVue.h(component, props || {}); }\n });\n miniApp._context = vueApp._context;\n miniApp.mount(mountPoint);\n container.setAttribute('data-annotask-mounted', 'true');\n container.__annotask_unmount = function() { try { miniApp.unmount(); } catch(e) {} };\n return true;\n } catch(e) { return false; }\n }\n\n function tryMountReactComponent(container, componentName, props) {\n try {\n var annotaskReact = window.__ANNOTASK_REACT__;\n if (!annotaskReact || !annotaskReact.createElement || !annotaskReact.createRoot) return false;\n var component = window.__ANNOTASK_COMPONENTS__ && window.__ANNOTASK_COMPONENTS__[componentName];\n if (!component) return false;\n var mountPoint = document.createElement('div');\n container.appendChild(mountPoint);\n var root = annotaskReact.createRoot(mountPoint);\n root.render(annotaskReact.createElement(component, props || {}));\n container.setAttribute('data-annotask-mounted', 'true');\n container.__annotask_unmount = function() { try { root.unmount(); } catch(e) {} };\n return true;\n } catch(e) { return false; }\n }\n\n function tryMountSvelteComponent(container, componentName, props) {\n try {\n var annotaskSvelte = window.__ANNOTASK_SVELTE__;\n if (!annotaskSvelte || !annotaskSvelte.mount) return false;\n var component = window.__ANNOTASK_COMPONENTS__ && window.__ANNOTASK_COMPONENTS__[componentName];\n if (!component) return false;\n var mountPoint = document.createElement('div');\n container.appendChild(mountPoint);\n var instance = annotaskSvelte.mount(component, { target: mountPoint, props: props || {} });\n container.setAttribute('data-annotask-mounted', 'true');\n container.__annotask_unmount = function() {\n try {\n if (annotaskSvelte.unmount) annotaskSvelte.unmount(instance);\n } catch(e) {}\n };\n return true;\n } catch(e) { return false; }\n }\n\n // ── Ready ─────────────────────────────────────────────\n sendToShell('bridge:ready', { version: '1.0' });\n})();\n`.trim()\n}\n"],"mappings":";AAQO,SAAS,qBAA6B;AAC3C,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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chunk-DQBM2VFQ.js";
8
+
9
+ // src/server/standalone.ts
10
+ import http from "http";
11
+ async function startStandaloneServer(options) {
12
+ const port = options.port || 24678;
13
+ const uiServer = createAnnotaskServer({ projectRoot: options.projectRoot });
14
+ const httpServer = http.createServer((req, res) => {
15
+ uiServer.middleware(req, res, () => {
16
+ res.statusCode = 404;
17
+ res.end("Not found");
18
+ });
19
+ });
20
+ httpServer.on("upgrade", (req, socket, head) => {
21
+ if (req.url === "/__annotask/ws") {
22
+ uiServer.handleUpgrade(req, socket, head);
23
+ }
24
+ });
25
+ return new Promise((resolve, reject) => {
26
+ httpServer.on("error", (err) => {
27
+ if (err.code === "EADDRINUSE") {
28
+ httpServer.listen(0, () => {
29
+ const addr = httpServer.address();
30
+ writeServerInfo(options.projectRoot, addr.port);
31
+ resolve({
32
+ port: addr.port,
33
+ close: () => {
34
+ removeServerInfo(options.projectRoot);
35
+ uiServer.dispose();
36
+ httpServer.close();
37
+ }
38
+ });
39
+ });
40
+ } else {
41
+ reject(err);
42
+ }
43
+ });
44
+ httpServer.listen(port, () => {
45
+ writeServerInfo(options.projectRoot, port);
46
+ resolve({
47
+ port,
48
+ close: () => {
49
+ removeServerInfo(options.projectRoot);
50
+ uiServer.dispose();
51
+ httpServer.close();
52
+ }
53
+ });
54
+ });
55
+ });
56
+ }
57
+
58
+ export {
59
+ startStandaloneServer
60
+ };
61
+ //# sourceMappingURL=chunk-4J7F2BC5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server/standalone.ts"],"sourcesContent":["import http from 'node:http'\nimport { createAnnotaskServer } from './index.js'\nimport { writeServerInfo, removeServerInfo } from './discovery.js'\n\nexport interface StandaloneServerOptions {\n projectRoot: string\n port?: number\n}\n\nexport async function startStandaloneServer(options: StandaloneServerOptions): Promise<{\n port: number\n close: () => void\n}> {\n const port = options.port || 24678\n const uiServer = createAnnotaskServer({ projectRoot: options.projectRoot })\n\n const httpServer = http.createServer((req, res) => {\n uiServer.middleware(req, res, () => {\n res.statusCode = 404\n res.end('Not found')\n })\n })\n\n httpServer.on('upgrade', (req, socket, head) => {\n if (req.url === '/__annotask/ws') {\n uiServer.handleUpgrade(req, socket, head)\n }\n })\n\n return new Promise((resolve, reject) => {\n httpServer.on('error', (err: NodeJS.ErrnoException) => {\n if (err.code === 'EADDRINUSE') {\n httpServer.listen(0, () => {\n const addr = httpServer.address() as { port: number }\n writeServerInfo(options.projectRoot, addr.port)\n resolve({\n port: addr.port,\n close: () => { removeServerInfo(options.projectRoot); uiServer.dispose(); httpServer.close() },\n })\n })\n } else {\n reject(err)\n }\n })\n\n httpServer.listen(port, () => {\n writeServerInfo(options.projectRoot, port)\n resolve({\n port,\n close: () => { removeServerInfo(options.projectRoot); uiServer.dispose(); httpServer.close() },\n })\n })\n })\n}\n"],"mappings":";;;;;;;;;AAAA,OAAO,UAAU;AASjB,eAAsB,sBAAsB,SAGzC;AACD,QAAM,OAAO,QAAQ,QAAQ;AAC7B,QAAM,WAAW,qBAAqB,EAAE,aAAa,QAAQ,YAAY,CAAC;AAE1E,QAAM,aAAa,KAAK,aAAa,CAAC,KAAK,QAAQ;AACjD,aAAS,WAAW,KAAK,KAAK,MAAM;AAClC,UAAI,aAAa;AACjB,UAAI,IAAI,WAAW;AAAA,IACrB,CAAC;AAAA,EACH,CAAC;AAED,aAAW,GAAG,WAAW,CAAC,KAAK,QAAQ,SAAS;AAC9C,QAAI,IAAI,QAAQ,kBAAkB;AAChC,eAAS,cAAc,KAAK,QAAQ,IAAI;AAAA,IAC1C;AAAA,EACF,CAAC;AAED,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,eAAW,GAAG,SAAS,CAAC,QAA+B;AACrD,UAAI,IAAI,SAAS,cAAc;AAC7B,mBAAW,OAAO,GAAG,MAAM;AACzB,gBAAM,OAAO,WAAW,QAAQ;AAChC,0BAAgB,QAAQ,aAAa,KAAK,IAAI;AAC9C,kBAAQ;AAAA,YACN,MAAM,KAAK;AAAA,YACX,OAAO,MAAM;AAAE,+BAAiB,QAAQ,WAAW;AAAG,uBAAS,QAAQ;AAAG,yBAAW,MAAM;AAAA,YAAE;AAAA,UAC/F,CAAC;AAAA,QACH,CAAC;AAAA,MACH,OAAO;AACL,eAAO,GAAG;AAAA,MACZ;AAAA,IACF,CAAC;AAED,eAAW,OAAO,MAAM,MAAM;AAC5B,sBAAgB,QAAQ,aAAa,IAAI;AACzC,cAAQ;AAAA,QACN;AAAA,QACA,OAAO,MAAM;AAAE,2BAAiB,QAAQ,WAAW;AAAG,mBAAS,QAAQ;AAAG,qBAAW,MAAM;AAAA,QAAE;AAAA,MAC/F,CAAC;AAAA,IACH,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
@@ -0,0 +1,61 @@
1
+ import {
2
+ removeServerInfo,
3
+ writeServerInfo
4
+ } from "./chunk-XLNGAH3S.js";
5
+ import {
6
+ createAnnotaskServer
7
+ } from "./chunk-LGNV6UH3.js";
8
+
9
+ // src/server/standalone.ts
10
+ import http from "http";
11
+ async function startStandaloneServer(options) {
12
+ const port = options.port || 24678;
13
+ const uiServer = createAnnotaskServer({ projectRoot: options.projectRoot });
14
+ const httpServer = http.createServer((req, res) => {
15
+ uiServer.middleware(req, res, () => {
16
+ res.statusCode = 404;
17
+ res.end("Not found");
18
+ });
19
+ });
20
+ httpServer.on("upgrade", (req, socket, head) => {
21
+ if (req.url === "/__annotask/ws") {
22
+ uiServer.handleUpgrade(req, socket, head);
23
+ }
24
+ });
25
+ return new Promise((resolve, reject) => {
26
+ httpServer.on("error", (err) => {
27
+ if (err.code === "EADDRINUSE") {
28
+ httpServer.listen(0, () => {
29
+ const addr = httpServer.address();
30
+ writeServerInfo(options.projectRoot, addr.port);
31
+ resolve({
32
+ port: addr.port,
33
+ close: () => {
34
+ removeServerInfo(options.projectRoot);
35
+ uiServer.dispose();
36
+ httpServer.close();
37
+ }
38
+ });
39
+ });
40
+ } else {
41
+ reject(err);
42
+ }
43
+ });
44
+ httpServer.listen(port, () => {
45
+ writeServerInfo(options.projectRoot, port);
46
+ resolve({
47
+ port,
48
+ close: () => {
49
+ removeServerInfo(options.projectRoot);
50
+ uiServer.dispose();
51
+ httpServer.close();
52
+ }
53
+ });
54
+ });
55
+ });
56
+ }
57
+
58
+ export {
59
+ startStandaloneServer
60
+ };
61
+ //# sourceMappingURL=chunk-DPJXWLPB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server/standalone.ts"],"sourcesContent":["import http from 'node:http'\nimport { createAnnotaskServer } from './index.js'\nimport { writeServerInfo, removeServerInfo } from './discovery.js'\n\nexport interface StandaloneServerOptions {\n projectRoot: string\n port?: number\n}\n\nexport async function startStandaloneServer(options: StandaloneServerOptions): Promise<{\n port: number\n close: () => void\n}> {\n const port = options.port || 24678\n const uiServer = createAnnotaskServer({ projectRoot: options.projectRoot })\n\n const httpServer = http.createServer((req, res) => {\n uiServer.middleware(req, res, () => {\n res.statusCode = 404\n res.end('Not found')\n })\n })\n\n httpServer.on('upgrade', (req, socket, head) => {\n if (req.url === '/__annotask/ws') {\n uiServer.handleUpgrade(req, socket, head)\n }\n })\n\n return new Promise((resolve, reject) => {\n httpServer.on('error', (err: NodeJS.ErrnoException) => {\n if (err.code === 'EADDRINUSE') {\n httpServer.listen(0, () => {\n const addr = httpServer.address() as { port: number }\n writeServerInfo(options.projectRoot, addr.port)\n resolve({\n port: addr.port,\n close: () => { removeServerInfo(options.projectRoot); uiServer.dispose(); httpServer.close() },\n })\n })\n } else {\n reject(err)\n }\n })\n\n httpServer.listen(port, () => {\n writeServerInfo(options.projectRoot, port)\n resolve({\n port,\n close: () => { removeServerInfo(options.projectRoot); uiServer.dispose(); httpServer.close() },\n })\n })\n })\n}\n"],"mappings":";;;;;;;;;AAAA,OAAO,UAAU;AASjB,eAAsB,sBAAsB,SAGzC;AACD,QAAM,OAAO,QAAQ,QAAQ;AAC7B,QAAM,WAAW,qBAAqB,EAAE,aAAa,QAAQ,YAAY,CAAC;AAE1E,QAAM,aAAa,KAA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