@vpxa/aikit 0.1.259 → 0.1.260

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vpxa/aikit",
3
- "version": "0.1.259",
3
+ "version": "0.1.260",
4
4
  "type": "module",
5
5
  "description": "Local-first AI developer toolkit — knowledge base, code analysis, context management, and developer tools for LLM agents",
6
6
  "license": "MIT",
@@ -1806,8 +1806,8 @@ main > * {
1806
1806
 
1807
1807
  `)}function Or(e){return e.length===0?``:e.map(e=>{let t=e.initScript?` <script>\n${e.initScript}\n <\/script>\n`:``;if(e.inlineSource)return`${t} <script>${e.inlineSource.replace(/<\/script/gi,`<\\/script`)}${e.onload?`\n;${e.onload}`:``}<\/script>`;if(!e.src)return t.trimEnd();let r=e.onload?` onload="${e.onload}"`:``;if(!e.fallback)return`${t} <script src="${n(e.src)}"${r}><\/script>`;let i=e.onload?`f.onload=function(){${e.onload}};`:``;return`${t} <script src="${n(e.src)}"${r} onerror="(function(el){var f=document.createElement('script');f.src='${n(e.fallback)}';${i}document.head.appendChild(f);el.remove()})(this)"><\/script>`}).join(`
1808
1808
  `)}function kr(e){let t=JSON.stringify(e),n=Ar(),r=jr();return[` <script>`,` (() => {`,` const preferredTheme = ${t};`,` const storageKey = "aikit-theme-mode";`,` const html = document.documentElement;`,` const toolbox = {`,` container: () => document.querySelector(".aikit-toolbox"),`,` button: () => document.querySelector(".aikit-toolbox-toggle"),`,` menu: () => document.querySelector(".aikit-toolbox-menu"),`,` firstItem: () => document.querySelector(".aikit-toolbox-item"),`,` };`,` const systemTheme = () =>`,` window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches`,` ? "dark"`,` : "light";`,` const readStoredTheme = () => {`,` try {`,` const stored = localStorage.getItem("aikit-theme-mode");`,` return stored === "light" || stored === "dark" ? stored : null;`,` } catch (_error) {`,` return null;`,` }`,` };`,` const resolvedTheme = () => html.getAttribute("data-theme") || readStoredTheme() || systemTheme();`,` const setToolboxOpen = (open, options = {}) => {`,` const button = toolbox.button();`,` const menu = toolbox.menu();`,` if (!button || !menu) return;`,` menu.hidden = !open;`,` button.setAttribute("aria-expanded", String(open));`,` if (open) {`,` if (options.focusItem) toolbox.firstItem()?.focus();`,` } else if (options.restoreFocus) {`,` button.focus();`,` }`,` };`,` const inlineComputedStyles = (source, clone) => {`,` if (!(source instanceof Element) || !(clone instanceof Element)) return;`,` const computed = window.getComputedStyle(source);`,` const cssText = Array.from(computed)`,` .map((name) => {`,` const value = computed.getPropertyValue(name);`,` const priority = computed.getPropertyPriority(name);`,' return `${name}:${value}${priority ? " !important" : ""};`;',` })`,` .join("");`,` clone.setAttribute("style", cssText);`,` for (let index = 0; index < source.children.length; index += 1) {`,` inlineComputedStyles(source.children[index], clone.children[index]);`,` }`,` };`,n,` const updateToggle = (theme) => {`,` const button = document.querySelector(".aikit-theme-toggle");`,` const nextTheme = theme === "dark" ? "light" : "dark";`,` if (button) {`,` button.setAttribute("aria-label", "Switch to " + nextTheme + " theme");`,` button.setAttribute("aria-pressed", String(theme === "dark"));`,` }`,` };`,` const applyTheme = (theme, persist = true) => {`,` html.setAttribute("data-theme", theme);`,` if (persist) {`,` try {`,` localStorage.setItem("aikit-theme-mode", theme);`,` } catch (_error) {`,` // Ignore storage failures.`,` }`,` }`,` updateToggle(theme);`,` };`,` if (preferredTheme === "light" || preferredTheme === "dark") {`,` applyTheme(preferredTheme, false);`,` } else {`,` applyTheme(readStoredTheme() || systemTheme(), false);`,` }`,` window.toggleTheme = () => {`,` applyTheme(resolvedTheme() === "dark" ? "light" : "dark");`,` };`,r,` document.addEventListener("click", (event) => {`,` const container = toolbox.container();`,` if (!container) return;`,` const target = event.target;`,` if (target instanceof Node && container.contains(target)) return;`,` setToolboxOpen(false);`,` });`,` document.addEventListener("keydown", (event) => {`,` if (event.key === "Escape") {`,` setToolboxOpen(false, { restoreFocus: true });`,` return;`,` }`,` if ((event.key === "ArrowDown" || event.key === "Enter" || event.key === " ") && event.target === toolbox.button()) {`,` event.preventDefault();`,` setToolboxOpen(true, { focusItem: true });`,` }`,` });`,` if (preferredTheme === "auto" && window.matchMedia) {`,` const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");`,` mediaQuery.addEventListener("change", () => {`,` if (readStoredTheme()) return;`,` applyTheme(systemTheme(), false);`,` });`,` }`,` })();`,` <\/script>`].join(`
1809
- `)}function Ar(){return[` const captureDocumentAsPng = async () => {`,` const width = Math.max(`,` document.documentElement.scrollWidth,`,` document.documentElement.clientWidth,`,` document.body ? document.body.scrollWidth : 0,`,` );`,` const height = Math.max(`,` document.documentElement.scrollHeight,`,` document.documentElement.clientHeight,`,` document.body ? document.body.scrollHeight : 0,`,` );`,` const scale = window.devicePixelRatio || 1;`,` const canvas = document.createElement("canvas");`,` canvas.width = Math.max(1, Math.ceil(width * scale));`,` canvas.height = Math.max(1, Math.ceil(height * scale));`,` const context = canvas.getContext("2d");`,` if (!context) throw new Error("Canvas context unavailable");`,` context.scale(scale, scale);`,` const clone = document.documentElement.cloneNode(true);`,` if (!(clone instanceof Element)) throw new Error("Document clone failed");`,` clone.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");`,` clone.querySelectorAll("script").forEach((node) => node.remove());`,` inlineComputedStyles(document.documentElement, clone);`,' const svgMarkup = [`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">`, `<foreignObject width="100%" height="100%">${new XMLSerializer().serializeToString(clone)}</foreignObject>`, "</svg>"].join("");',` const svgBlob = new Blob([svgMarkup], { type: "image/svg+xml;charset=utf-8" });`,` const objectUrl = URL.createObjectURL(svgBlob);`,` try {`,` await new Promise((resolve, reject) => {`,` const image = new Image();`,` image.onload = () => {`,` context.drawImage(image, 0, 0, width, height);`,` resolve(undefined);`,` };`,` image.onerror = () => reject(new Error("ForeignObject render failed"));`,` image.src = objectUrl;`,` });`,` } finally {`,` URL.revokeObjectURL(objectUrl);`,` }`,` const blob = await new Promise((resolve) => canvas.toBlob(resolve, "image/png"));`,` if (!blob) throw new Error("PNG export failed");`,` const downloadUrl = URL.createObjectURL(blob);`,` const link = document.createElement("a");`,` const timestamp = new Date().toISOString().replace(/[.:]/g, "-");`,` link.href = downloadUrl;`," link.download = `aikit-screenshot-${timestamp}.png`;",` document.body.appendChild(link);`,` link.click();`,` link.remove();`,` URL.revokeObjectURL(downloadUrl);`,` };`].join(`
1810
- `)}function jr(){return[` window.toggleToolbox = () => {`,` const menu = toolbox.menu();`,` setToolboxOpen(Boolean(menu?.hidden), { focusItem: Boolean(menu?.hidden) });`,` };`,` window.screenshotPage = async () => {`,` const scrollX = window.scrollX;`,` const scrollY = window.scrollY;`,` setToolboxOpen(false);`,` window.scrollTo(0, 0);`,` await new Promise((resolve) => window.requestAnimationFrame(() => resolve(undefined)));`,` try {`,` await captureDocumentAsPng();`,` } catch (_error) {`,` window.print();`,` } finally {`,` window.scrollTo(scrollX, scrollY);`,` }`,` };`].join(`
1809
+ `)}function Ar(){return[` const captureDocumentAsPng = async () => {`,` const width = Math.max(`,` document.documentElement.scrollWidth,`,` document.documentElement.clientWidth,`,` document.body ? document.body.scrollWidth : 0,`,` );`,` const height = Math.max(`,` document.documentElement.scrollHeight,`,` document.documentElement.clientHeight,`,` document.body ? document.body.scrollHeight : 0,`,` );`,` const scale = window.devicePixelRatio || 1;`,` const canvas = document.createElement("canvas");`,` canvas.width = Math.max(1, Math.ceil(width * scale));`,` canvas.height = Math.max(1, Math.ceil(height * scale));`,` const context = canvas.getContext("2d");`,` if (!context) throw new Error("Canvas context unavailable");`,` context.scale(scale, scale);`,` const clone = document.documentElement.cloneNode(true);`,` if (!(clone instanceof Element)) throw new Error("Document clone failed");`,` clone.setAttribute("xmlns", "http://www.w3.org/1999/xhtml");`,` clone.querySelectorAll("script").forEach((node) => node.remove());`,` inlineComputedStyles(document.documentElement, clone);`,' const svgMarkup = [`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">`, `<foreignObject width="100%" height="100%">${new XMLSerializer().serializeToString(clone)}</foreignObject>`, "</svg>"].join("");',` const svgBlob = new Blob([svgMarkup], { type: "image/svg+xml;charset=utf-8" });`,` const objectUrl = URL.createObjectURL(svgBlob);`,` try {`,` await new Promise((resolve, reject) => {`,` const image = new Image();`,` image.onload = () => {`,` context.drawImage(image, 0, 0, width, height);`,` resolve(undefined);`,` };`,` image.onerror = () => reject(new Error("ForeignObject render failed"));`,` image.src = objectUrl;`,` });`,` } finally {`,` URL.revokeObjectURL(objectUrl);`,` }`,` const blob = await new Promise((resolve) => canvas.toBlob(resolve, "image/png"));`,` if (!blob) throw new Error("PNG export failed");`,` return blob;`,` };`,` const triggerDownload = (blob) => {`,` const downloadUrl = URL.createObjectURL(blob);`,` const link = document.createElement("a");`,` const timestamp = new Date().toISOString().replace(/[.:]/g, "-");`,` link.href = downloadUrl;`," link.download = `aikit-screenshot-${timestamp}.png`;",` document.body.appendChild(link);`,` link.click();`,` link.remove();`,` URL.revokeObjectURL(downloadUrl);`,` };`].join(`
1810
+ `)}function jr(){return[` window.toggleToolbox = () => {`,` const menu = toolbox.menu();`,` setToolboxOpen(Boolean(menu?.hidden), { focusItem: Boolean(menu?.hidden) });`,` };`,` window.screenshotPage = async () => {`,` const scrollX = window.scrollX;`,` const scrollY = window.scrollY;`,` setToolboxOpen(false);`,` window.scrollTo(0, 0);`,` await new Promise((resolve) => window.requestAnimationFrame(() => resolve(undefined)));`,` try {`,` const blob = await captureDocumentAsPng();`,` try {`,` if (!navigator.clipboard?.write || typeof ClipboardItem === "undefined") {`,` throw new Error("Clipboard write unavailable");`,` }`,` await navigator.clipboard.write([new ClipboardItem({ [blob.type]: blob })]);`,` } catch (_error) {`,` triggerDownload(blob);`,` }`,` } finally {`,` window.scrollTo(scrollX, scrollY);`,` }`,` };`].join(`
1811
1811
  `)}function Mr(e,t){if(t!==`local-interactive`)return``;let r=new Set,i=[];for(let t of e)r.has(t.entry)||(r.add(t.entry),i.push(` <script type="module" src="${n(t.entry)}"><\/script>`));return i.length>0&&i.push(` <script type="module">`,` import { hydrateAsync } from "/@aikit/blocks-interactive/dist/index.mjs";`,` const boot = () => {`,` void hydrateAsync();`,` };`,` if (document.readyState === "loading") {`,` document.addEventListener("DOMContentLoaded", boot, { once: true });`,` } else {`,` boot();`,` }`,` <\/script>`),i.join(`
1812
1812
  `)}function Nr(e){let t=n(e.lang??`en`),r=n(e.dir??`ltr`),i=e.colorScheme??`auto`,a=e.generatedAt??new Date().toISOString(),o=[`lang="${t}"`,`dir="${r}"`];i!==`auto`&&o.push(`data-theme="${i}"`);let s=Dr(e.tokenCss??qt(`light`)),c=Or(e.headScripts??[]),l=e.islands.length>0&&e.payload?` <script type="application/json" id="surface-payload">${Tr(e.payload)}<\/script>`:``,u=Mr(e.islands,e.exportPolicy),d=[kr(i),l,u].filter(Boolean).join(`
1813
1813
  `);return[`<!DOCTYPE html>`,`<html ${o.join(` `)}>`,`<head>`,` <meta charset="utf-8">`,` <meta name="viewport" content="width=device-width, initial-scale=1">`,` <title>${n(e.title)}</title>`,Er(s,e.css),c,`</head>`,`<body data-surface-nonce="${n(e.nonce)}">`,N({title:e.title,subtitle:e.subtitle,transport:e.transport}),` <main>${e.html}</main>`,P({generatedAt:a,contentHtml:e.footerContentHtml}),d,`</body>`,`</html>`].filter(Boolean).join(`
@@ -2117,7 +2117,7 @@ container holding the app. Specify either width or maxWidth, and either height o
2117
2117
  .drag-handle { font-size: 18px; color: var(--aikit-muted, #858585); cursor: grab; user-select: none; }
2118
2118
  .sort-label { flex: 1; color: var(--aikit-text, #ccc); }
2119
2119
  .sort-pos { font-size: 12px; color: var(--aikit-muted, #858585); font-variant-numeric: tabular-nums; }
2120
- `,Cw={name:`list-sort`,label:`Sortable List`,detect(e){if(typeof e!=`object`||!e||Array.isArray(e))return 0;let t=e;return t.items&&Array.isArray(t.items)&&!t.categories?.8:0},render(e,t,n){let r=t,i=Q(`div`,`block tpl-list-sort`);XC(`tpl-list-sort`,Sw);function a(e){i.innerHTML=``;let t=Q(`ul`,`sort-list`),r=-1;for(let i=0;i<e.length;i++){let o=e[i],s=document.createElement(`li`);s.className=`sort-item`,s.draggable=!0,s.dataset.idx=String(i);let c=Q(`span`,`drag-handle`,`⠿`),l=Q(`span`,`sort-label`,o.label),u=Q(`span`,`sort-pos`,`#${i+1}`);s.appendChild(c),s.appendChild(l),s.appendChild(u),s.addEventListener(`dragstart`,()=>{r=Number(s.dataset.idx),s.classList.add(`dragging`)}),s.addEventListener(`dragend`,()=>{s.classList.remove(`dragging`)}),s.addEventListener(`dragenter`,e=>{e.preventDefault()}),s.addEventListener(`dragover`,e=>{e.preventDefault(),s.classList.add(`drag-over`)}),s.addEventListener(`dragleave`,()=>{s.classList.remove(`drag-over`)}),s.addEventListener(`drop`,t=>{t.preventDefault(),s.classList.remove(`drag-over`);let i=Number(s.dataset.idx);if(r>=0&&r!==i){let t=[...e],[o]=t.splice(r,1);t.splice(i,0,o),a(t),n.emitAction({type:`button`,id:`reorder`,label:`Reorder`},JSON.stringify(t.map(e=>e.id)))}}),t.appendChild(s)}i.appendChild(t)}a([...r.items??[]]),e.appendChild(i)},styles(){return Sw}},ww=document.getElementById(`app`);if(!ww)throw Error(`Missing #app element`);var $=ww,Tw=KC(),Ew=Tw?void 0:new uC({name:`AI Kit Present`,version:`1.0.0`}),Dw=new sw;Dw.register(Cw),Dw.register(yw),Dw.register(gw),Dw.register(xw);var Ow=VC(Ew),kw={app:Ew,data:qC(Ew),emitAction:Ow},Aw=new mw,jw=new ew,Mw=Ew?new JC(Ew):void 0,Nw=null,Pw=!!Tw;function Fw(){Nw?.(),Nw=null,Kw?.destroy&&Kw.destroy(),Kw=null}function Iw(e,t){let n=new Map,r=e=>{n.set(o(e.id),e)};for(let e of t??[])r(e);for(let t of e)if(!(t.type!==`actions`||!Array.isArray(t.value)))for(let e of t.value)e&&typeof e==`object`&&`id`in e&&r(e);return n}function Lw(e,t,n){let r=Iw(t,n);Nw=BC(e,t,(e,t)=>{Ow(r.get(e)??{type:t===void 0?`button`:`select`,id:e,label:e},t)})}function Rw(e,t,n){let r=document.documentElement.dir,i=WC(e,t,{colorScheme:Aw.getTheme(),lang:document.documentElement.lang||void 0,dir:r===`ltr`||r===`rtl`||r===`auto`?r:void 0});return i?{blocks:i.blocks,actions:n.actions}:null}var zw;function Bw(e){Fw(),$.innerHTML=``;let t=ow(e);if(e.title){let t=Q(`div`,`header`);t.appendChild(Q(`h1`,``,e.title)),t.appendChild(Q(`span`,`badge streaming`,`⟳`)),$.appendChild(t)}let n=Q(`div`,`content`);Lw(n,t.blocks??[]),$.appendChild(n)}function Vw(){return`aikit-screenshot-${new Date().toISOString().replace(/[.:]/g,`-`)}.png`}async function Hw(){let e=Math.max(document.documentElement.scrollWidth,document.documentElement.clientWidth,document.body?document.body.scrollWidth:0),t=Math.max(document.documentElement.scrollHeight,document.documentElement.clientHeight,document.body?document.body.scrollHeight:0),n=window.devicePixelRatio||1,r=document.createElement(`canvas`);r.width=Math.max(1,Math.ceil(e*n)),r.height=Math.max(1,Math.ceil(t*n));let i=r.getContext(`2d`);if(!i)throw Error(`Canvas context unavailable`);i.scale(n,n);let a=document.documentElement.cloneNode(!0);if(!(a instanceof Element))throw Error(`Document clone failed`);a.setAttribute(`xmlns`,`http://www.w3.org/1999/xhtml`),a.querySelectorAll(`script`).forEach(e=>{e.remove()});let o=[`<svg xmlns="http://www.w3.org/2000/svg" width="${e}" height="${t}" viewBox="0 0 ${e} ${t}">`,`<foreignObject width="100%" height="100%">${new XMLSerializer().serializeToString(a)}</foreignObject>`,`</svg>`].join(``),s=new Blob([o],{type:`image/svg+xml;charset=utf-8`}),c=URL.createObjectURL(s);try{await new Promise((n,r)=>{let a=new Image;a.onload=()=>{i.drawImage(a,0,0,e,t),n(void 0)},a.onerror=()=>r(Error(`ForeignObject render failed`)),a.src=c})}finally{URL.revokeObjectURL(c)}let l=await new Promise(e=>r.toBlob(e,`image/png`));if(!l)throw Error(`PNG export failed`);return l}function Uw(e){let t=URL.createObjectURL(e),n=document.createElement(`a`);return n.href=t,n.download=Vw(),document.body.appendChild(n),n.click(),n.remove(),setTimeout(()=>URL.revokeObjectURL(t),0),t}function Ww(e,t){let n=$.querySelector(`.host-message`);if(n||(n=Q(`div`,`host-message`),$.prepend(n)),n.replaceChildren(),n.appendChild(Q(`span`,``,e)),t){let e=Q(`a`,`host-message-link`,`Download image`);e.href=t,e.download=Vw(),n.appendChild(e)}}function Gw(){if(!Pw)return;let e=window;e.toggleToolbox=()=>{let e=document.getElementById(`aikit-toolbox-menu`);e&&(e.hidden=!e.hidden)},e.screenshotPage=async()=>{try{let e=await Hw(),t=navigator.clipboard;if(t?.write&&`ClipboardItem`in window){await t.write([new ClipboardItem({"image/png":e})]),Ww(`Copied image to clipboard.`);return}throw Error(`Clipboard unavailable`)}catch{Ww(`Clipboard write blocked. Downloaded image instead.`,Uw(await Hw()))}}}var Kw=null;function qw(e,t){$.innerHTML=``;let n=Q(`div`,`error-panel`);n.appendChild(Q(`h3`,``,`⚠ ${e}`)),n.appendChild(Q(`pre`,``,t instanceof Error?t.message:String(t))),$.appendChild(n)}function Jw(e){Fw(),$.innerHTML=``;let t=ow(e),n=t.data;if(n==null){$.innerHTML=`<p class="no-data">No content data received.</p>`;return}if(e.title&&!Pw){let t=Q(`div`,`header`);t.appendChild(Q(`h1`,``,e.title)),t.appendChild(Q(`span`,`badge`,`AI KIT`)),$.appendChild(t)}let r=t.template?Dw.get(t.template):Dw.detect(n),i=Q(`div`,`content`);if(r)Kw=r,r.render(i,n,kw);else if(t.template){let r=Rw(t.template,n,e);r?Lw(i,r.blocks,r.actions):Lw(i,t.blocks??[],e.actions)}else Lw(i,t.blocks??[],e.actions);if($.appendChild(i),e.actions?.length){let t=Q(`div`,`actions-shell`),n=BC(t,[{type:`actions`,value:e.actions}],(t,n)=>{Ow(e.actions?.find(e=>o(e.id)===t)??{type:n===void 0?`button`:`select`,id:t,label:t},n)}),r=Nw;Nw=()=>{r?.(),n()},$.appendChild(t)}let a=Q(`div`,`footer`);a.innerHTML=`<span class="footer-brand">Powered by <strong>AI Kit</strong></span>`,$.appendChild(a)}Ew?(Ew.connect().then(()=>{let e=Ew.getHostContext();e&&(Aw.apply(e),jw.apply(e),Mw?.apply(e))}),Ew.onhostcontextchanged=e=>{Aw.apply(e),jw.apply(e),Mw?.apply(e),Kw?.onThemeChange&&Kw.onThemeChange(Aw.getTheme())},Ew.ontoolinputpartial=e=>{let t=e.arguments;t&&($.dataset.streaming=`true`,clearTimeout(zw),zw=setTimeout(()=>{try{let e=t.content??t.data??t.blocks;if(e==null)return;Bw({schemaVersion:t.schemaVersion===1?1:void 0,title:t.title,template:t.template,content:e,data:t.data,blocks:Array.isArray(t.blocks)?t.blocks:void 0})}catch{}},80))},Ew.ontoolinput=()=>{clearTimeout(zw),delete $.dataset.streaming},Ew.ontoolresult=e=>{if(clearTimeout(zw),delete $.dataset.streaming,e.structuredContent)try{Jw(e.structuredContent);return}catch(e){qw(`Render error`,e);return}let t=e.content?.find(e=>e.type===`text`)?.text;if(!t){$.innerHTML=`<p>No data received.</p>`;return}try{Jw(JSON.parse(t))}catch{Jw({content:t})}}):Tw&&(document.documentElement.dataset.theme=`dark`,Gw(),Jw(Tw));</script>
2120
+ `,Cw={name:`list-sort`,label:`Sortable List`,detect(e){if(typeof e!=`object`||!e||Array.isArray(e))return 0;let t=e;return t.items&&Array.isArray(t.items)&&!t.categories?.8:0},render(e,t,n){let r=t,i=Q(`div`,`block tpl-list-sort`);XC(`tpl-list-sort`,Sw);function a(e){i.innerHTML=``;let t=Q(`ul`,`sort-list`),r=-1;for(let i=0;i<e.length;i++){let o=e[i],s=document.createElement(`li`);s.className=`sort-item`,s.draggable=!0,s.dataset.idx=String(i);let c=Q(`span`,`drag-handle`,`⠿`),l=Q(`span`,`sort-label`,o.label),u=Q(`span`,`sort-pos`,`#${i+1}`);s.appendChild(c),s.appendChild(l),s.appendChild(u),s.addEventListener(`dragstart`,()=>{r=Number(s.dataset.idx),s.classList.add(`dragging`)}),s.addEventListener(`dragend`,()=>{s.classList.remove(`dragging`)}),s.addEventListener(`dragenter`,e=>{e.preventDefault()}),s.addEventListener(`dragover`,e=>{e.preventDefault(),s.classList.add(`drag-over`)}),s.addEventListener(`dragleave`,()=>{s.classList.remove(`drag-over`)}),s.addEventListener(`drop`,t=>{t.preventDefault(),s.classList.remove(`drag-over`);let i=Number(s.dataset.idx);if(r>=0&&r!==i){let t=[...e],[o]=t.splice(r,1);t.splice(i,0,o),a(t),n.emitAction({type:`button`,id:`reorder`,label:`Reorder`},JSON.stringify(t.map(e=>e.id)))}}),t.appendChild(s)}i.appendChild(t)}a([...r.items??[]]),e.appendChild(i)},styles(){return Sw}},ww=document.getElementById(`app`);if(!ww)throw Error(`Missing #app element`);var $=ww,Tw=KC(),Ew=Tw?void 0:new uC({name:`AI Kit Present`,version:`1.0.0`}),Dw=new sw;Dw.register(Cw),Dw.register(yw),Dw.register(gw),Dw.register(xw);var Ow=VC(Ew),kw={app:Ew,data:qC(Ew),emitAction:Ow},Aw=new mw,jw=new ew,Mw=Ew?new JC(Ew):void 0,Nw=null,Pw=!!Tw;function Fw(){Nw?.(),Nw=null,Jw?.destroy&&Jw.destroy(),Jw=null}function Iw(e,t){let n=new Map,r=e=>{n.set(o(e.id),e)};for(let e of t??[])r(e);for(let t of e)if(!(t.type!==`actions`||!Array.isArray(t.value)))for(let e of t.value)e&&typeof e==`object`&&`id`in e&&r(e);return n}function Lw(e,t,n){let r=Iw(t,n);Nw=BC(e,t,(e,t)=>{Ow(r.get(e)??{type:t===void 0?`button`:`select`,id:e,label:e},t)})}function Rw(e,t,n){let r=document.documentElement.dir,i=WC(e,t,{colorScheme:Aw.getTheme(),lang:document.documentElement.lang||void 0,dir:r===`ltr`||r===`rtl`||r===`auto`?r:void 0});return i?{blocks:i.blocks,actions:n.actions}:null}var zw;function Bw(e){Fw(),$.innerHTML=``;let t=ow(e);if(e.title){let t=Q(`div`,`header`);t.appendChild(Q(`h1`,``,e.title)),t.appendChild(Q(`span`,`badge streaming`,`⟳`));let n=Q(`button`,`badge header-copy-image`,`Copy image`);n.type=`button`,n.addEventListener(`click`,()=>{Vw()}),t.appendChild(n),$.appendChild(t)}let n=Q(`div`,`content`);Lw(n,t.blocks??[]),$.appendChild(n)}async function Vw(){let e=await Ww(),t=navigator.clipboard;try{if(t?.write&&`ClipboardItem`in window){await t.write([new ClipboardItem({"image/png":e})]),Kw(`Copied image to clipboard.`);return}throw Error(`Clipboard unavailable`)}catch{Kw(`Clipboard write blocked. Downloaded image instead.`,Gw(e))}}async function Hw(){await Vw()}function Uw(){return`aikit-screenshot-${new Date().toISOString().replace(/[.:]/g,`-`)}.png`}async function Ww(){let e=Math.max(document.documentElement.scrollWidth,document.documentElement.clientWidth,document.body?document.body.scrollWidth:0),t=Math.max(document.documentElement.scrollHeight,document.documentElement.clientHeight,document.body?document.body.scrollHeight:0),n=window.devicePixelRatio||1,r=document.createElement(`canvas`);r.width=Math.max(1,Math.ceil(e*n)),r.height=Math.max(1,Math.ceil(t*n));let i=r.getContext(`2d`);if(!i)throw Error(`Canvas context unavailable`);i.scale(n,n);let a=document.documentElement.cloneNode(!0);if(!(a instanceof Element))throw Error(`Document clone failed`);a.setAttribute(`xmlns`,`http://www.w3.org/1999/xhtml`),a.querySelectorAll(`script`).forEach(e=>{e.remove()});let o=[`<svg xmlns="http://www.w3.org/2000/svg" width="${e}" height="${t}" viewBox="0 0 ${e} ${t}">`,`<foreignObject width="100%" height="100%">${new XMLSerializer().serializeToString(a)}</foreignObject>`,`</svg>`].join(``),s=new Blob([o],{type:`image/svg+xml;charset=utf-8`}),c=URL.createObjectURL(s);try{await new Promise((n,r)=>{let a=new Image;a.onload=()=>{i.drawImage(a,0,0,e,t),n(void 0)},a.onerror=()=>r(Error(`ForeignObject render failed`)),a.src=c})}finally{URL.revokeObjectURL(c)}let l=await new Promise(e=>r.toBlob(e,`image/png`));if(!l)throw Error(`PNG export failed`);return l}function Gw(e){let t=URL.createObjectURL(e),n=document.createElement(`a`);return n.href=t,n.download=Uw(),document.body.appendChild(n),n.click(),n.remove(),setTimeout(()=>URL.revokeObjectURL(t),0),t}function Kw(e,t){let n=$.querySelector(`.host-message`);if(n||(n=Q(`div`,`host-message`),$.prepend(n)),n.replaceChildren(),n.appendChild(Q(`span`,``,e)),t){let e=Q(`a`,`host-message-link`,`Download image`);e.href=t,e.download=Uw(),n.appendChild(e)}}function qw(){if(!Pw)return;let e=window;e.toggleToolbox=()=>{let e=document.getElementById(`aikit-toolbox-menu`);e&&(e.hidden=!e.hidden)},e.screenshotPage||=Vw}var Jw=null;function Yw(e,t){$.innerHTML=``;let n=Q(`div`,`error-panel`);n.appendChild(Q(`h3`,``,`⚠ ${e}`)),n.appendChild(Q(`pre`,``,t instanceof Error?t.message:String(t))),$.appendChild(n)}function Xw(e){Fw(),$.innerHTML=``;let t=ow(e),n=t.data;if(n==null){$.innerHTML=`<p class="no-data">No content data received.</p>`;return}if(e.title&&!Pw){let t=Q(`div`,`header`);t.appendChild(Q(`h1`,``,e.title)),t.appendChild(Q(`span`,`badge`,`AI KIT`));let n=Q(`button`,`badge header-copy-image`,`Copy image`);n.type=`button`,n.addEventListener(`click`,()=>{Hw()}),t.appendChild(n),$.appendChild(t)}let r=t.template?Dw.get(t.template):Dw.detect(n),i=Q(`div`,`content`);if(r)Jw=r,r.render(i,n,kw);else if(t.template){let r=Rw(t.template,n,e);r?Lw(i,r.blocks,r.actions):Lw(i,t.blocks??[],e.actions)}else Lw(i,t.blocks??[],e.actions);if($.appendChild(i),e.actions?.length){let t=Q(`div`,`actions-shell`),n=BC(t,[{type:`actions`,value:e.actions}],(t,n)=>{Ow(e.actions?.find(e=>o(e.id)===t)??{type:n===void 0?`button`:`select`,id:t,label:t},n)}),r=Nw;Nw=()=>{r?.(),n()},$.appendChild(t)}let a=Q(`div`,`footer`);a.innerHTML=`<span class="footer-brand">Powered by <strong>AI Kit</strong></span>`,$.appendChild(a)}Ew?(Ew.connect().then(()=>{let e=Ew.getHostContext();e&&(Aw.apply(e),jw.apply(e),Mw?.apply(e))}),Ew.onhostcontextchanged=e=>{Aw.apply(e),jw.apply(e),Mw?.apply(e),Jw?.onThemeChange&&Jw.onThemeChange(Aw.getTheme())},Ew.ontoolinputpartial=e=>{let t=e.arguments;t&&($.dataset.streaming=`true`,clearTimeout(zw),zw=setTimeout(()=>{try{let e=t.content??t.data??t.blocks;if(e==null)return;Bw({schemaVersion:t.schemaVersion===1?1:void 0,title:t.title,template:t.template,content:e,data:t.data,blocks:Array.isArray(t.blocks)?t.blocks:void 0})}catch{}},80))},Ew.ontoolinput=()=>{clearTimeout(zw),delete $.dataset.streaming},Ew.ontoolresult=e=>{if(clearTimeout(zw),delete $.dataset.streaming,e.structuredContent)try{Xw(e.structuredContent);return}catch(e){Yw(`Render error`,e);return}let t=e.content?.find(e=>e.type===`text`)?.text;if(!t){$.innerHTML=`<p>No data received.</p>`;return}try{Xw(JSON.parse(t))}catch{Xw({content:t})}}):Tw&&(document.documentElement.dataset.theme=`dark`,qw(),Xw(Tw));</script>
2121
2121
  </head>
2122
2122
  <body>
2123
2123
  <div id="app">