@maxhealth.tech/prefab 0.3.11 → 0.3.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/CHANGELOG.md +25 -3
  2. package/dist/a2ui/catalog.js +1 -1
  3. package/dist/a2ui/catalog.js.map +1 -1
  4. package/dist/a2ui.min.js +1 -1
  5. package/dist/auto/comparison.d.ts.map +1 -1
  6. package/dist/auto/comparison.js +1 -7
  7. package/dist/auto/comparison.js.map +1 -1
  8. package/dist/auto/form.d.ts.map +1 -1
  9. package/dist/auto/form.js +8 -9
  10. package/dist/auto/form.js.map +1 -1
  11. package/dist/auto/index.d.ts +2 -0
  12. package/dist/auto/index.d.ts.map +1 -1
  13. package/dist/auto/index.js +5 -11
  14. package/dist/auto/index.js.map +1 -1
  15. package/dist/auto/schema.d.ts +84 -0
  16. package/dist/auto/schema.d.ts.map +1 -0
  17. package/dist/auto/schema.js +227 -0
  18. package/dist/auto/schema.js.map +1 -0
  19. package/dist/components/form/index.d.ts +7 -3
  20. package/dist/components/form/index.d.ts.map +1 -1
  21. package/dist/components/form/index.js +8 -3
  22. package/dist/components/form/index.js.map +1 -1
  23. package/dist/core/component.d.ts +11 -1
  24. package/dist/core/component.d.ts.map +1 -1
  25. package/dist/core/component.js +4 -1
  26. package/dist/core/component.js.map +1 -1
  27. package/dist/core/humanize.d.ts +20 -0
  28. package/dist/core/humanize.d.ts.map +1 -0
  29. package/dist/core/humanize.js +28 -0
  30. package/dist/core/humanize.js.map +1 -0
  31. package/dist/core/index.d.ts +1 -0
  32. package/dist/core/index.d.ts.map +1 -1
  33. package/dist/core/index.js +1 -0
  34. package/dist/core/index.js.map +1 -1
  35. package/dist/core/version.d.ts +1 -1
  36. package/dist/core/version.js +1 -1
  37. package/dist/index.d.ts +2 -0
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +1 -0
  40. package/dist/index.js.map +1 -1
  41. package/dist/renderer/components/choice.d.ts +10 -0
  42. package/dist/renderer/components/choice.d.ts.map +1 -0
  43. package/dist/renderer/components/choice.js +261 -0
  44. package/dist/renderer/components/choice.js.map +1 -0
  45. package/dist/renderer/components/form.d.ts +24 -1
  46. package/dist/renderer/components/form.d.ts.map +1 -1
  47. package/dist/renderer/components/form.js +36 -239
  48. package/dist/renderer/components/form.js.map +1 -1
  49. package/dist/renderer/components/index.d.ts.map +1 -1
  50. package/dist/renderer/components/index.js +2 -0
  51. package/dist/renderer/components/index.js.map +1 -1
  52. package/dist/renderer.auto.min.js +10 -10
  53. package/dist/renderer.min.js +10 -10
  54. package/package.json +1 -1
@@ -1,16 +1,16 @@
1
- (()=>{var Mt={silent:0,error:1,warn:2,info:3,debug:4},Lt="warn";function Ht(e){Lt=e}function qe(e){let t=e?`[prefab:${e}]`:"[prefab]",n=(r,o,i)=>{if(Mt[r]>Mt[Lt])return;console[r](`${t} ${o}`,...i)};return{error:(r,...o)=>n("error",r,o),warn:(r,...o)=>n("warn",r,o),info:(r,...o)=>n("info",r,o),debug:(r,...o)=>n("debug",r,o)}}var O=qe();class ye{data={};subscribers=new Map;globalSubscribers=new Set;generation=0;constructor(e){if(e)this.data=structuredClone(e)}get(e){return Jn(this.data,e)}getAll(){return this.data}set(e,t){Pt(this.data,e,t),this.notify(e)}toggle(e){let t=this.get(e),n=t==null||t===!1||t===0||t==="";this.set(e,n)}append(e,t,n){let r=this.get(e);if(!Array.isArray(r)){this.set(e,[t]);return}if(n!==void 0)r.splice(n,0,t);else r.push(t);this.notify(e)}pop(e,t){let n=this.get(e);if(!Array.isArray(n))return;if(typeof t==="number")n.splice(t,1);else{let r=n.indexOf(t);if(r>=0)n.splice(r,1)}this.notify(e)}merge(e){for(let[t,n]of Object.entries(e))Pt(this.data,t,n);for(let t of Object.keys(e))this.notify(t)}subscribe(e,t){if(!this.subscribers.has(e))this.subscribers.set(e,new Set);return this.subscribers.get(e)?.add(t),()=>this.subscribers.get(e)?.delete(t)}subscribeAll(e){return this.globalSubscribers.add(e),()=>this.globalSubscribers.delete(e)}notify(e){this.generation++;let t=e.split(".");for(let n=1;n<=t.length;n++){let r=t.slice(0,n).join("."),o=this.subscribers.get(r);if(o)o.forEach((i)=>i())}this.globalSubscribers.forEach((n)=>n())}}function Jn(e,t){let n=t.split("."),r=e;for(let o of n){if(r==null||typeof r!=="object")return;r=r[o]}return r}var zn=new Set(["__proto__","constructor","prototype"]);function Pt(e,t,n){let r=t.split(".");if(r.some((i)=>zn.has(i))){O.warn(`Blocked prototype pollution attempt: ${t}`);return}let o=e;for(let i=0;i<r.length-1;i++){let s=r[i];if(o[s]==null||typeof o[s]!=="object")o[s]={};o=o[s]}o[r[r.length-1]]=n}var me=new Map;function Ue(e,t){if(me.has(e)&&me.get(e)!==t)O.warn(`pipe "${e}" re-registered`);me.set(e,t)}function Xe(e){return me.delete(e)}function $t(){return[...me.keys()]}function ke(e){return me.get(e)}function P(e){if(e==null)return"";if(typeof e==="string")return e;if(typeof e==="number"||typeof e==="boolean"||typeof e==="bigint")return String(e);if(typeof e==="symbol")return e.description??"";if(typeof e==="function")return e.name;if(e instanceof Date)return Number.isNaN(e.getTime())?"":e.toISOString();if(Array.isArray(e))return e.map(P).join(", ");try{return JSON.stringify(e)??""}catch{return""}}var Ot=-1,Ye=new Map,Wn=/\{\{\s*(.+?)\s*\}\}/g;function Q(e){return typeof e==="string"&&e.includes("{{")&&e.includes("}}")}function ee(e,t,n){let r=e.trim();if(r.startsWith("{{")&&r.endsWith("}}")&&Xn(r,"{{")===1){let o=r.slice(2,-2).trim();return Dt(o,t,n)}return e.replace(Wn,(o,i)=>{let s=Dt(i.trim(),t,n);return P(s)})}function Dt(e,t,n){let[r,...o]=Un(e),i=Y(r.trim(),t,n);for(let s of o)i=_n(s.trim(),i,t,n);return i}function Y(e,t,n){let r=Gn(e);if(r>=0){let s=e.slice(0,r).trim(),a=e.slice(r+1),l=qn(a);if(l>=0){let c=a.slice(0,l).trim(),u=a.slice(l+1).trim(),d=Y(s,t,n);return d!==null&&d!==void 0&&d!==!1&&d!==0&&d!==""?Y(c,t,n):Y(u,t,n)}}let o=Se(e,"||");if(o>=0){let s=Y(e.slice(0,o).trim(),t,n);return s!==null&&s!==void 0&&s!==!1&&s!==0&&s!==""?s:Y(e.slice(o+2).trim(),t,n)}let i=Se(e,"&&");if(i>=0){let s=Y(e.slice(0,i).trim(),t,n);if(s===null||s===void 0||s===!1||s===0||s==="")return s;return Y(e.slice(i+2).trim(),t,n)}for(let[s,a]of Vn){let l=Se(e,s);if(l>=0){let c=Y(e.slice(0,l).trim(),t,n),u=Y(e.slice(l+s.length).trim(),t,n);return a(c,u)}}if(e.startsWith("!")){let s=Y(e.slice(1).trim(),t,n);return s===null||s===void 0||s===!1||s===0||s===""}for(let[s,a]of Kn){let l=Se(e,s);if(l>=0){let c=Y(e.slice(0,l).trim(),t,n),u=Y(e.slice(l+s.length).trim(),t,n);return a(Number(c),Number(u))}}if(e==="true")return!0;if(e==="false")return!1;if(e==="null"||e==="undefined")return null;if(/^-?\d+(\.\d+)?$/.test(e))return Number(e);if(e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"'))return e.slice(1,-1);if(n&&e.startsWith("$")){let s=e.indexOf(".");if(s>=0){let a=e.slice(0,s),l=e.slice(s+1),c=n[a];return Ee(c,l)}return n[e]}if(n){let s=e.split(".")[0];if(s in n)return Ee(n[s],e.includes(".")?e.slice(s.length+1):"")}return t.get(e)}function _n(e,t,n,r){let o=e.indexOf(":"),i=o>=0?e.slice(0,o).trim():e,s=o>=0?e.slice(o+1).trim():void 0,a=s?Ze(s):void 0;switch(i){case"find":{if(!Array.isArray(t)||!s)return;let l=jt(s);if(l.length<2)return;let c=Ze(l[0]),u=l[1].trim(),d;if(u.startsWith("'")&&u.endsWith("'")||u.startsWith('"')&&u.endsWith('"'))d=u.slice(1,-1);else if(n){if(r&&u.startsWith("$")){let f=u.indexOf(".");if(f>=0){let b=u.slice(0,f);if(b in r)d=Ee(r[b],u.slice(f+1))}else if(u in r)d=r[u]}if(d===void 0&&!(r&&u.startsWith("$")))if(r){let f=u.split(".")[0];d=f in r?Ee(r[f],u.includes(".")?u.slice(f.length+1):""):n.get(u)}else d=n.get(u)}else d=u;if(d==null)return;let g=n?.generation??0;if(g!==Ot)Ye=new Map,Ot=g;let h=Ye.get(t);if(!h)h=new Map,Ye.set(t,h);let y=h.get(c);if(!y){y=new Map;for(let f of t)if(f!=null&&typeof f==="object"){let b=f[c];if(b!=null)y.set(P(b),f)}h.set(c,y)}return y.get(P(d))}case"dot":{if(t==null||typeof t!=="object"||typeof a!=="string")return;return t[a]}case"length":return Array.isArray(t)?t.length:typeof t==="string"?t.length:0;case"upper":return typeof t==="string"?t.toUpperCase():t;case"lower":return typeof t==="string"?t.toLowerCase():t;case"truncate":if(typeof t==="string"&&typeof a==="number")return t.slice(0,a);return t;case"join":return Array.isArray(t)?t.join(typeof a==="string"?a:", "):t;case"first":return Array.isArray(t)?t[0]:t;case"last":return Array.isArray(t)?t[t.length-1]:t;case"abs":return Math.abs(Number(t));case"round":return typeof a==="number"?Number(Number(t).toFixed(a)):Math.round(Number(t));case"number":return typeof a==="number"?Number(Number(t).toFixed(a)):Number(t);case"currency":{let l=typeof a==="string"?a:"USD";try{return new Intl.NumberFormat("en-US",{style:"currency",currency:l}).format(Number(t))}catch{return t}}case"percent":return typeof a==="number"?`${(Number(t)*100).toFixed(a)}%`:`${Math.round(Number(t)*100)}%`;case"compact":{let l=typeof a==="number"?a:1;try{return new Intl.NumberFormat("en-US",{notation:"compact",maximumFractionDigits:l}).format(Number(t))}catch{return t}}case"date":try{return new Date(t).toLocaleDateString()}catch{return t}case"time":try{return new Date(t).toLocaleTimeString()}catch{return t}case"datetime":try{return new Date(t).toLocaleString()}catch{return t}case"pluralize":{let l=Number(t),c=typeof a==="string"?a:"";return l===1?c:`${c}s`}case"default":return t==null||t===""?a:t;case"selectattr":return Array.isArray(t)&&typeof a==="string"?t.filter((l)=>l!=null&&typeof l==="object"&&Boolean(l[a])):t;case"rejectattr":return Array.isArray(t)&&typeof a==="string"?t.filter((l)=>{if(l==null||typeof l!=="object")return!1;let c=l[a];return c==null||c===!1||c===0||c===""}):t;default:{let l=ke(i);if(l){let c=s?jt(s).map(Ze):[];return l(t,...c)}return t}}}var Vn=[["!==",(e,t)=>e!==t],["===",(e,t)=>e===t],["!=",(e,t)=>e!=t],["==",(e,t)=>e==t],[">=",(e,t)=>Number(e)>=Number(t)],["<=",(e,t)=>Number(e)<=Number(t)],[">",(e,t)=>Number(e)>Number(t)],["<",(e,t)=>Number(e)<Number(t)]],Kn=[[" + ",(e,t)=>e+t],[" - ",(e,t)=>e-t],[" * ",(e,t)=>e*t],[" / ",(e,t)=>t!==0?e/t:0],[" % ",(e,t)=>t!==0?e%t:0]];function Se(e,t){let n=null;for(let r=0;r<e.length;r++){let o=e[r];if(o==="'"||o==='"')n=n===o?null:n??o;if(!n&&e.slice(r,r+t.length)===t)return r}return-1}function Gn(e){let t=0,n=null;for(let r=0;r<e.length;r++){let o=e[r];if(o==="'"||o==='"')n=n===o?null:n??o;if(!n){if(o==="(")t++;else if(o===")")t--;else if(o==="?"&&t===0)return r}}return-1}function qn(e){let t=0,n=null;for(let r=0;r<e.length;r++){let o=e[r];if(o==="'"||o==='"')n=n===o?null:n??o;if(!n){if(o==="?"||o==="(")t++;else if(o===")")t--;else if(o===":"&&t===0)return r}}return-1}function Un(e){let t=[],n="",r=null;for(let o=0;o<e.length;o++){let i=e[o];if(i==="'"||i==='"')r=r===i?null:r??i;if(i==="|"&&!r)if(e[o+1]==="|")n+="||",o++;else t.push(n),n="";else n+=i}return t.push(n),t}function Ze(e){let t=e.replace(/^['"]|['"]$/g,"");if(t==="true")return!0;if(t==="false")return!1;let n=Number(t);return isNaN(n)?t:n}function jt(e){let t=[],n="",r=null;for(let o of e){if(o==="'"||o==='"')r=r===o?null:r??o;if(o===","&&!r)t.push(n),n="";else n+=o}return t.push(n),t}function Ee(e,t){if(!t)return e;let n=t.split("."),r=e;for(let o of n){if(r==null||typeof r!=="object")return;r=r[o]}return r}function Xn(e,t){let n=0,r=0;while((r=e.indexOf(t,r))!==-1)n++,r+=t.length;return n}function Ae(e){return e.replace(/_([a-z])/g,(t,n)=>n.toUpperCase())}function et(e){let t={};for(let[n,r]of Object.entries(e)){let o=n.startsWith("$")?n:Ae(n);if(Array.isArray(r))t[o]=r.map((i)=>i!=null&&typeof i==="object"&&!Array.isArray(i)?et(i):i);else if(r!=null&&typeof r==="object"&&!Array.isArray(r))t[o]=et(r);else t[o]=r}return t}async function j(e,t){let n=Array.isArray(e)?e:[e];for(let r of n)await Yn(r,t)}function F(e,t){e.catch((n)=>O.error(`${t} failed:`,n))}async function Ne(e,t,n,r){if(n!=null)O.debug(`${e} failed:`,t),await de(n,r,{$error:t});else O.warn(`${e} failed:`,t)}async function Yn(e,t){let n=et(e),r=n.action;switch(r){case"setState":{Zn(n,t);return}case"toggleState":{Qn(n,t);return}case"appendState":{er(n,t);return}case"popState":{tr(n,t);return}case"showToast":{nr(n,t);return}case"closeOverlay":{rr(n,t);return}case"openLink":{or(n);return}case"setInterval":{sr(n,t);return}case"toolCall":case"callTool":return ar(n,t);case"sendMessage":return lr(n,t);case"updateContext":{dr(n,t);return}case"fetch":return cr(n,t);case"openFilePicker":{pr(n,t);return}case"callHandler":return ur(n,t);case"requestDisplayMode":{fr(n,t);return}case"subscribe":{hr(n,t);return}case"unsubscribe":{br(n);return}default:O.warn(`Unknown action: ${r}`)}}function Zn(e,t){let{key:n,value:r}=e;if(Q(r))r=ee(r,t.store,t.scope);t.store.set(n,r),t.rerender(),de(e.onSuccess,t)}function Qn(e,t){t.store.toggle(e.key),t.rerender()}function er(e,t){let n=e.value??e.item;if(Q(n))n=ee(n,t.store,t.scope);t.store.append(e.key,n,e.index),t.rerender()}function tr(e,t){t.store.pop(e.key,e.index),t.rerender()}function nr(e,t){t.onToast?.({message:Te(e.message,t),description:e.description!=null?Te(e.description,t):void 0,variant:e.variant,duration:e.duration})}function rr(e,t){if(typeof document<"u")document.dispatchEvent(new CustomEvent("prefab:close-overlay"))}function or(e){if(typeof window<"u"){let t=e.url;if(!t){O.warn("openLink: missing url");return}if(!Jt(t)){O.warn(`Blocked unsafe URL scheme: ${t}`);return}window.open(t,e.target??"_blank")}}var Re=new Set,ir=20,It=100;function sr(e,t){let n=Math.max(e.intervalMs,It),r=e.onTick;if(typeof globalThis.setInterval!=="function")return;if(Re.size>=ir){O.warn("Max intervals reached, ignoring new setInterval");return}let o=globalThis.setInterval(()=>F(j(r,t),"interval action"),n);Re.add(o)}function Ft(){for(let e of Re)globalThis.clearInterval(e);Re.clear()}async function ar(e,t){if(!t.transport){O.warn("No MCP transport configured for toolCall");return}let n=e.tool,r=tt(e.arguments,t);try{let o=await t.transport.callTool(n,r);if(e.resultKey!=null)t.store.set(e.resultKey,o);let i=Me(o);if(i&&t.remount)t.remount(i);else Le(o,t),t.rerender();await de(e.onSuccess,t,{$result:o})}catch(o){await Ne("toolCall",o,e.onError,t)}}async function lr(e,t){if(!t.transport){O.warn("No MCP transport configured for sendMessage");return}await t.transport.sendMessage(Te(e.message,t))}function dr(e,t){let n=e.context;if(n!=null)t.store.merge(n),t.rerender()}async function cr(e,t){let n=Te(e.url,t);if(!Jt(n)){O.warn(`Blocked unsafe URL in fetch: ${n}`);return}let r=e.method??"GET",o=e.headers,i=e.body!==void 0?JSON.stringify(e.body):void 0;try{let s=await globalThis.fetch(n,{method:r,headers:{"Content-Type":"application/json",...o},...i&&{body:i}}),a=await s.json().catch(()=>s.text());if(e.resultKey!=null)t.store.set(e.resultKey,a);let l=Me(a);if(l&&t.remount)t.remount(l);else Le(a,t),t.rerender();await de(e.onSuccess,t,{$result:a})}catch(s){await Ne("fetch",s,e.onError,t)}}function pr(e,t){if(typeof document>"u")return;let n=document.createElement("input");if(n.type="file",e.accept!=null)n.accept=e.accept;if(e.multiple===!0)n.multiple=!0;n.addEventListener("change",()=>{let r=Array.from(n.files??[]);if(e.resultKey!=null)t.store.set(e.resultKey,r);t.rerender(),de(e.onSuccess,t,{$result:r})}),n.click()}async function ur(e,t){let n=e.handler,r=tt(e.arguments,t);if(!t.transport){O.warn(`No transport configured for callHandler: ${n}`);return}try{let o=await t.transport.callTool(n,r);if(e.resultKey!=null)t.store.set(e.resultKey,o);let i=Me(o);if(i&&t.remount)t.remount(i);else Le(o,t),t.rerender();await de(e.onSuccess,t,{$result:o})}catch(o){await Ne("callHandler",o,e.onError,t)}}function fr(e,t){if(typeof document<"u")document.dispatchEvent(new CustomEvent("prefab:request-display-mode",{detail:{mode:e.mode}}))}var ie=new Map,mr=50,gr=2000;function hr(e,t){let{uri:n,stateKey:r}=e;if(!n||!r){O.warn("subscribe: missing uri or stateKey");return}if(ie.has(n))return;if(ie.size>=mr){O.warn("Max subscriptions reached, ignoring new subscribe");return}let o=(d)=>{let g=Me(d);if(g&&t.remount)t.remount(g);else{if(!Le(d,t))t.store.set(r,d);t.rerender()}de(e.onData,t,{$data:d})};if(t.transport?.subscribe&&t.transport.capabilities?.subscriptions){let d=t.transport.subscribe(n,o);ie.set(n,d);return}let i=e.fallbackTool,s=e.fallbackInterval??gr;if(!i){O.warn("subscribe: host lacks subscriptions and no fallbackTool specified");return}if(!t.transport){O.warn("No MCP transport configured for subscribe fallback");return}let a=e.fallbackArgs??{},l=Math.max(s,It),c=t.transport,u=globalThis.setInterval(()=>{(async()=>{try{let d=tt(a,t),g=await c.callTool(i,d);o(g)}catch(d){Ne("subscribe",d,e.onError,t)}})()},l);ie.set(n,()=>globalThis.clearInterval(u))}function br(e){let t=e.uri;if(!t){O.warn("unsubscribe: missing uri");return}let n=ie.get(t);if(n)n(),ie.delete(t)}function Bt(){for(let[e,t]of ie)try{t()}catch(n){O.warn(`Error cleaning up subscription '${e}':`,n)}ie.clear()}function Me(e){if(e==null||typeof e!=="object")return null;let t=e;if("$prefab"in t&&"view"in t)return t;if("structuredContent"in t){let n=t.structuredContent;if(n!=null&&typeof n==="object"){let r=n;if("$prefab"in r&&"view"in r)return r}}if("content"in t&&Array.isArray(t.content)){for(let n of t.content)if(n.type==="text"&&typeof n.text==="string")try{let r=JSON.parse(n.text);if(r!=null&&typeof r==="object"){let o=r;if("$prefab"in o&&"view"in o)return o}}catch{}}return null}function yr(e){if(e==null||typeof e!=="object")return null;let t=e;if(Qe(t))return t;if("structuredContent"in t){let n=t.structuredContent;if(n!=null&&typeof n==="object"&&Qe(n))return n}if("content"in t&&Array.isArray(t.content)){for(let n of t.content)if(n.type==="text"&&typeof n.text==="string")try{let r=JSON.parse(n.text);if(r!=null&&typeof r==="object"&&Qe(r))return r}catch{}}return null}function Qe(e){if(!("$prefab"in e)||!("update"in e))return!1;let t=e.update;return t!=null&&typeof t==="object"&&"state"in t}function Le(e,t){let n=yr(e);if(!n)return!1;let r=n.update;if(t.store.merge(r.state),r.actions!=null)F(j(r.actions,t),"update action");return!0}var Cr=/^\s*(javascript|vbscript|data):/i;function Jt(e){return!Cr.test(e)}function Te(e,t){if(Q(e)){let n=ee(e,t.store,t.scope);return P(n)}return P(e)}function tt(e,t){if(!e)return{};let n={};for(let[r,o]of Object.entries(e))n[r]=Q(o)?ee(o,t.store,t.scope):o;return n}async function de(e,t,n){if(e==null)return;let r={...t.scope,...n};await j(e,{...t,scope:r})}function rt(e){let t={};for(let[n,r]of Object.entries(e)){let o=n.startsWith("$")?n:Ae(n);if(Array.isArray(r))t[o]=r.map((i)=>i!=null&&typeof i==="object"&&!Array.isArray(i)?rt(i):i);else if(r!=null&&typeof r==="object"&&!Array.isArray(r))t[o]=rt(r);else t[o]=r}return t}class ot{callbacks=[];track(e){this.callbacks.push(e)}flush(){for(let e of this.callbacks)try{e()}catch(t){O.warn("destroy callback error:",t)}this.callbacks=[]}get size(){return this.callbacks.length}}function vr(e){return typeof e==="object"&&"element"in e}var He=new Map;function p(e,t){if(He.has(e))O.warn(`overriding existing renderer for "${e}"`);He.set(e,t)}function it(){return[...He.keys()].sort()}var zt=new Set;function _t(e){zt.clear();for(let t of e)zt.add(t)}function J(e,t){let n=rt(e);if(t.defs?.[n.type]){let i={...t.defs[n.type],...n,type:t.defs[n.type].type};return J(i,t)}let r=He.get(n.type),o;if(r){let i=r(n,t);if(vr(i))o=i.element,t.destroyRegistry?.track(i.destroy);else o=i}else if(o=document.createElement("div"),o.setAttribute("data-prefab-type",n.type),n.children)for(let i of n.children)o.appendChild(J(i,t));if(o instanceof HTMLElement){if(n.id)o.id=n.id;if(n.cssClass){let i=C(n.cssClass,t);if(i)o.className=(o.className?o.className+" ":"")+i}if(n.onClick!=null){if(o.addEventListener("click",()=>{F(j(n.onClick,V(t)),"onClick")}),o.tagName!=="BUTTON"&&o.tagName!=="A")o.setAttribute("role","button"),o.setAttribute("tabindex","0"),o.addEventListener("keydown",(i)=>{let s=i.key;if(s==="Enter"||s===" ")i.preventDefault(),F(j(n.onClick,V(t)),"onClick")})}}if(n.onMount){let i=n.onMount,s=V(t);queueMicrotask(()=>F(j(i,s),"onMount"))}return o}function H(e,t,n){if(!e.children)return;se(e.children,t,n)}function se(e,t,n){let r=0;while(r<e.length){let o=e[r];if(o.type==="If")r=wr(e,r,t,n);else if(o.type==="Elif"||o.type==="Else")r++;else t.appendChild(J(o,n)),r++}}function wr(e,t,n,r){let o=!1,i=t,s=e[i];if(Wt(s.condition,r))nt(s,n,r),o=!0;i++;while(i<e.length){let a=e[i];if(a.type==="Elif"){if(!o&&Wt(a.condition,r))nt(a,n,r),o=!0;i++}else if(a.type==="Else"){if(!o)nt(a,n,r);i++;break}else break}return i}function Wt(e,t){if(!e)return!1;if(Q(e))return Boolean(ee(e,t.store,t.scope));return Boolean(t.store.get(e))}function nt(e,t,n){if(!e.children)return;se(e.children,t,n)}function C(e,t){if(Q(e)){let n=ee(e,t.store,t.scope);return P(n)}return P(e)}function K(e,t){if(Q(e))return ee(e,t.store,t.scope);return e}function V(e){return{store:e.store,transport:e.transport,scope:e.scope,rerender:e.rerender,onToast:e.onToast,remount:e.remount}}function m(e,t){let n=document.createElement(e);if(t)n.className=t;return n}function st(e,t){return e.textContent=t,e}function qt(){p("Column",xr),p("Row",kr),p("Grid",Vt),p("GridItem",Kt),p("Container",Sr),p("Div",Gt),p("Span",Er),p("Dashboard",Vt),p("DashboardItem",Kt),p("Pages",Ar),p("Page",Gt),p("Detail",Rr),p("MasterDetail",Tr)}function xr(e,t){let n=m("div","pf-column");n.style.display="flex",n.style.flexDirection="column";let r=Pe(e);if(r!=null)n.style.gap=`${r*4}px`;if(e.align!=null)n.style.alignItems=Ut(e.align);if(e.justify!=null)n.style.justifyContent=Xt(e.justify);return H(e,n,t),n}function kr(e,t){let n=m("div","pf-row");n.style.display="flex",n.style.flexDirection="row";let r=Pe(e);if(r!=null)n.style.gap=`${r*4}px`;if(e.align!=null)n.style.alignItems=Ut(e.align);if(e.justify!=null)n.style.justifyContent=Xt(e.justify);if(e.wrap===!0)n.style.flexWrap="wrap";return H(e,n,t),n}function Vt(e,t){let n=m("div","pf-grid");n.style.display="grid";let r=e.columns??3;n.style.gridTemplateColumns=`repeat(${r}, 1fr)`;let o=Pe(e);if(o!=null)n.style.gap=`${o*4}px`;return H(e,n,t),n}function Kt(e,t){let n=m("div","pf-grid-item");if(e.colSpan!=null)n.style.gridColumn=`span ${e.colSpan}`;if(e.rowSpan!=null)n.style.gridRow=`span ${e.rowSpan}`;return H(e,n,t),n}function Sr(e,t){let n=m("div","pf-container");if(n.style.maxWidth=e.maxWidth??"1200px",n.style.margin="0 auto",e.padding!=null)n.style.padding=`${e.padding*4}px`;return H(e,n,t),n}function Gt(e,t){let n=m("div","pf-div");return H(e,n,t),n}function Er(e,t){let n=m("span","pf-span");return H(e,n,t),n}function Ar(e,t){let n=m("div","pf-pages");return H(e,n,t),n}function Rr(e,t){let n=m("div","pf-detail"),r=e.of!=null?K(e.of,t):void 0;if(r!=null&&r!==""&&r!==!1&&r!==0)H(e,n,t);else if(e.empty!=null){let o=e.empty;n.appendChild(J(o,t))}return n}function Tr(e,t){let n=m("div","pf-master-detail");n.style.display="flex",n.style.flexDirection="row";let r=Pe(e);if(r!=null)n.style.gap=`${r*4}px`;let o=e.masterWidth??"33%",i=e.children??[];if(i.length>0){let s=m("div","pf-master-detail-master");s.style.width=o,s.style.flexShrink="0",s.style.overflow="auto",s.appendChild(J(i[0],t)),n.appendChild(s)}if(i.length>1){let s=m("div","pf-master-detail-detail");s.style.flex="1",s.style.overflow="auto",s.appendChild(J(i[1],t)),n.appendChild(s)}return n}var Nr=/\bgap-(\d+)\b/;function Pe(e){if(e.gap!=null)return e.gap;if(typeof e.cssClass==="string"){let t=Nr.exec(e.cssClass);if(t)return Number(t[1])}return null}function Ut(e){return{start:"flex-start",end:"flex-end",center:"center",stretch:"stretch",baseline:"baseline"}[e]??e}function Xt(e){return{start:"flex-start",end:"flex-end",center:"center",between:"space-between",around:"space-around",evenly:"space-evenly"}[e]??e}var Mr={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function Ce(e){return e.replace(/[&<>"']/g,(t)=>Mr[t]??t)}function Zt(){p("Heading",Lr),p("H1",(e,t)=>$e(e,t,"h1")),p("H2",(e,t)=>$e(e,t,"h2")),p("H3",(e,t)=>$e(e,t,"h3")),p("H4",(e,t)=>$e(e,t,"h4")),p("Text",Hr),p("P",Pr),p("Lead",(e,t)=>ge(e,t,"p","pf-lead")),p("Large",(e,t)=>ge(e,t,"span","pf-large")),p("Small",(e,t)=>ge(e,t,"small","pf-small")),p("Muted",(e,t)=>ge(e,t,"p","pf-muted")),p("BlockQuote",(e,t)=>ge(e,t,"blockquote","pf-blockquote")),p("Label",(e,t)=>ge(e,t,"label","pf-label")),p("Link",Or),p("Code",Dr),p("Markdown",jr),p("Kbd",Ir)}function Lr(e,t){let n=e.level??2,r=`h${Math.min(Math.max(n,1),6)}`,o=document.createElement(r);return o.className=`pf-heading pf-${r}`,o.textContent=C(e.content,t),o}function $e(e,t,n){let r=document.createElement(n);return r.className=`pf-heading pf-${n}`,r.textContent=C(e.content,t),r}function Hr(e,t){return st(m("span","pf-text"),C(e.content,t))}function Pr(e,t){return st(m("p","pf-p"),C(e.content,t))}function ge(e,t,n,r){let o=document.createElement(n);return o.className=r,o.textContent=C(e.content,t),o}var $r=/^\s*(javascript|vbscript|data):/i;function Or(e,t){let n=document.createElement("a");if(n.className="pf-link",n.textContent=C(e.content,t),e.href!=null){let r=C(e.href,t);if(!$r.test(r))n.href=r}if(e.target!=null)n.target=C(e.target,t);return n}function Dr(e,t){let n=m("pre","pf-code"),r=m("code");if(r.textContent=C(e.content,t),e.language!=null)r.setAttribute("data-language",e.language);return n.appendChild(r),n}function jr(e,t){let n=m("div","pf-markdown"),r=C(e.content,t);return n.innerHTML=Qt(r),n.setAttribute("data-markdown","true"),n}var Yt=/^\s*(javascript|vbscript|data):/i;function Oe(e){let t=Ce(e),n=[];return t=t.replace(/`([^`]+)`/g,(r,o)=>(n.push(`<code>${o}</code>`),`﷐CODE${n.length-1}﷐`)),t=t.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(r,o,i)=>{if(Yt.test(i))return Ce(o);return`<img src="${i}" alt="${o}" />`}),t=t.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(r,o,i)=>{if(Yt.test(i))return o;return`<a href="${i}">${o}</a>`}),t=t.replace(/\*{3}(.+?)\*{3}/g,"<strong><em>$1</em></strong>"),t=t.replace(/_{3}(.+?)_{3}/g,"<strong><em>$1</em></strong>"),t=t.replace(/\*{2}(.+?)\*{2}/g,"<strong>$1</strong>"),t=t.replace(/_{2}(.+?)_{2}/g,"<strong>$1</strong>"),t=t.replace(/\*(.+?)\*/g,"<em>$1</em>"),t=t.replace(/(?<!\w)_(.+?)_(?!\w)/g,"<em>$1</em>"),t=t.replace(/~~(.+?)~~/g,"<del>$1</del>"),t=t.replace(/\uFDD0CODE(\d+)\uFDD0/g,(r,o)=>n[parseInt(o)]),t}function Qt(e){let t=e.replace(/\r\n?/g,`
1
+ (()=>{var Ht={silent:0,error:1,warn:2,info:3,debug:4},Pt="warn";function Ot(e){Pt=e}function Xe(e){let t=e?`[prefab:${e}]`:"[prefab]",n=(r,o,i)=>{if(Ht[r]>Ht[Pt])return;console[r](`${t} ${o}`,...i)};return{error:(r,...o)=>n("error",r,o),warn:(r,...o)=>n("warn",r,o),info:(r,...o)=>n("info",r,o),debug:(r,...o)=>n("debug",r,o)}}var O=Xe();class we{data={};subscribers=new Map;globalSubscribers=new Set;generation=0;constructor(e){if(e)this.data=structuredClone(e)}get(e){return Vn(this.data,e)}getAll(){return this.data}set(e,t){$t(this.data,e,t),this.notify(e)}toggle(e){let t=this.get(e),n=t==null||t===!1||t===0||t==="";this.set(e,n)}append(e,t,n){let r=this.get(e);if(!Array.isArray(r)){this.set(e,[t]);return}if(n!==void 0)r.splice(n,0,t);else r.push(t);this.notify(e)}pop(e,t){let n=this.get(e);if(!Array.isArray(n))return;if(typeof t==="number")n.splice(t,1);else{let r=n.indexOf(t);if(r>=0)n.splice(r,1)}this.notify(e)}merge(e){for(let[t,n]of Object.entries(e))$t(this.data,t,n);for(let t of Object.keys(e))this.notify(t)}subscribe(e,t){if(!this.subscribers.has(e))this.subscribers.set(e,new Set);return this.subscribers.get(e)?.add(t),()=>this.subscribers.get(e)?.delete(t)}subscribeAll(e){return this.globalSubscribers.add(e),()=>this.globalSubscribers.delete(e)}notify(e){this.generation++;let t=e.split(".");for(let n=1;n<=t.length;n++){let r=t.slice(0,n).join("."),o=this.subscribers.get(r);if(o)o.forEach((i)=>i())}this.globalSubscribers.forEach((n)=>n())}}function Vn(e,t){let n=t.split("."),r=e;for(let o of n){if(r==null||typeof r!=="object")return;r=r[o]}return r}var Wn=new Set(["__proto__","constructor","prototype"]);function $t(e,t,n){let r=t.split(".");if(r.some((i)=>Wn.has(i))){O.warn(`Blocked prototype pollution attempt: ${t}`);return}let o=e;for(let i=0;i<r.length-1;i++){let s=r[i];if(o[s]==null||typeof o[s]!=="object")o[s]={};o=o[s]}o[r[r.length-1]]=n}var ge=new Map;function Ye(e,t){if(ge.has(e)&&ge.get(e)!==t)O.warn(`pipe "${e}" re-registered`);ge.set(e,t)}function Ze(e){return ge.delete(e)}function Dt(){return[...ge.keys()]}function Ae(e){return ge.get(e)}function L(e){if(e==null)return"";if(typeof e==="string")return e;if(typeof e==="number"||typeof e==="boolean"||typeof e==="bigint")return String(e);if(typeof e==="symbol")return e.description??"";if(typeof e==="function")return e.name;if(e instanceof Date)return Number.isNaN(e.getTime())?"":e.toISOString();if(Array.isArray(e))return e.map(L).join(", ");try{return JSON.stringify(e)??""}catch{return""}}var jt=-1,Qe=new Map,_n=/\{\{\s*(.+?)\s*\}\}/g;function Q(e){return typeof e==="string"&&e.includes("{{")&&e.includes("}}")}function ee(e,t,n){let r=e.trim();if(r.startsWith("{{")&&r.endsWith("}}")&&Zn(r,"{{")===1){let o=r.slice(2,-2).trim();return It(o,t,n)}return e.replace(_n,(o,i)=>{let s=It(i.trim(),t,n);return L(s)})}function It(e,t,n){let[r,...o]=Yn(e),i=Y(r.trim(),t,n);for(let s of o)i=Kn(s.trim(),i,t,n);return i}function Y(e,t,n){let r=Un(e);if(r>=0){let s=e.slice(0,r).trim(),a=e.slice(r+1),l=Xn(a);if(l>=0){let d=a.slice(0,l).trim(),u=a.slice(l+1).trim(),c=Y(s,t,n);return c!==null&&c!==void 0&&c!==!1&&c!==0&&c!==""?Y(d,t,n):Y(u,t,n)}}let o=Ee(e,"||");if(o>=0){let s=Y(e.slice(0,o).trim(),t,n);return s!==null&&s!==void 0&&s!==!1&&s!==0&&s!==""?s:Y(e.slice(o+2).trim(),t,n)}let i=Ee(e,"&&");if(i>=0){let s=Y(e.slice(0,i).trim(),t,n);if(s===null||s===void 0||s===!1||s===0||s==="")return s;return Y(e.slice(i+2).trim(),t,n)}for(let[s,a]of Gn){let l=Ee(e,s);if(l>=0){let d=Y(e.slice(0,l).trim(),t,n),u=Y(e.slice(l+s.length).trim(),t,n);return a(d,u)}}if(e.startsWith("!")){let s=Y(e.slice(1).trim(),t,n);return s===null||s===void 0||s===!1||s===0||s===""}for(let[s,a]of qn){let l=Ee(e,s);if(l>=0){let d=Y(e.slice(0,l).trim(),t,n),u=Y(e.slice(l+s.length).trim(),t,n);return a(Number(d),Number(u))}}if(e==="true")return!0;if(e==="false")return!1;if(e==="null"||e==="undefined")return null;if(/^-?\d+(\.\d+)?$/.test(e))return Number(e);if(e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"'))return e.slice(1,-1);if(n&&e.startsWith("$")){let s=e.indexOf(".");if(s>=0){let a=e.slice(0,s),l=e.slice(s+1),d=n[a];return Re(d,l)}return n[e]}if(n){let s=e.split(".")[0];if(s in n)return Re(n[s],e.includes(".")?e.slice(s.length+1):"")}return t.get(e)}function Kn(e,t,n,r){let o=e.indexOf(":"),i=o>=0?e.slice(0,o).trim():e,s=o>=0?e.slice(o+1).trim():void 0,a=s?et(s):void 0;switch(i){case"find":{if(!Array.isArray(t)||!s)return;let l=Ft(s);if(l.length<2)return;let d=et(l[0]),u=l[1].trim(),c;if(u.startsWith("'")&&u.endsWith("'")||u.startsWith('"')&&u.endsWith('"'))c=u.slice(1,-1);else if(n){if(r&&u.startsWith("$")){let f=u.indexOf(".");if(f>=0){let b=u.slice(0,f);if(b in r)c=Re(r[b],u.slice(f+1))}else if(u in r)c=r[u]}if(c===void 0&&!(r&&u.startsWith("$")))if(r){let f=u.split(".")[0];c=f in r?Re(r[f],u.includes(".")?u.slice(f.length+1):""):n.get(u)}else c=n.get(u)}else c=u;if(c==null)return;let g=n?.generation??0;if(g!==jt)Qe=new Map,jt=g;let h=Qe.get(t);if(!h)h=new Map,Qe.set(t,h);let y=h.get(d);if(!y){y=new Map;for(let f of t)if(f!=null&&typeof f==="object"){let b=f[d];if(b!=null)y.set(L(b),f)}h.set(d,y)}return y.get(L(c))}case"dot":{if(t==null||typeof t!=="object"||typeof a!=="string")return;return t[a]}case"length":return Array.isArray(t)?t.length:typeof t==="string"?t.length:0;case"upper":return typeof t==="string"?t.toUpperCase():t;case"lower":return typeof t==="string"?t.toLowerCase():t;case"truncate":if(typeof t==="string"&&typeof a==="number")return t.slice(0,a);return t;case"join":return Array.isArray(t)?t.join(typeof a==="string"?a:", "):t;case"first":return Array.isArray(t)?t[0]:t;case"last":return Array.isArray(t)?t[t.length-1]:t;case"abs":return Math.abs(Number(t));case"round":return typeof a==="number"?Number(Number(t).toFixed(a)):Math.round(Number(t));case"number":return typeof a==="number"?Number(Number(t).toFixed(a)):Number(t);case"currency":{let l=typeof a==="string"?a:"USD";try{return new Intl.NumberFormat("en-US",{style:"currency",currency:l}).format(Number(t))}catch{return t}}case"percent":return typeof a==="number"?`${(Number(t)*100).toFixed(a)}%`:`${Math.round(Number(t)*100)}%`;case"compact":{let l=typeof a==="number"?a:1;try{return new Intl.NumberFormat("en-US",{notation:"compact",maximumFractionDigits:l}).format(Number(t))}catch{return t}}case"date":try{return new Date(t).toLocaleDateString()}catch{return t}case"time":try{return new Date(t).toLocaleTimeString()}catch{return t}case"datetime":try{return new Date(t).toLocaleString()}catch{return t}case"pluralize":{let l=Number(t),d=typeof a==="string"?a:"";return l===1?d:`${d}s`}case"default":return t==null||t===""?a:t;case"selectattr":return Array.isArray(t)&&typeof a==="string"?t.filter((l)=>l!=null&&typeof l==="object"&&Boolean(l[a])):t;case"rejectattr":return Array.isArray(t)&&typeof a==="string"?t.filter((l)=>{if(l==null||typeof l!=="object")return!1;let d=l[a];return d==null||d===!1||d===0||d===""}):t;default:{let l=Ae(i);if(l){let d=s?Ft(s).map(et):[];return l(t,...d)}return t}}}var Gn=[["!==",(e,t)=>e!==t],["===",(e,t)=>e===t],["!=",(e,t)=>e!=t],["==",(e,t)=>e==t],[">=",(e,t)=>Number(e)>=Number(t)],["<=",(e,t)=>Number(e)<=Number(t)],[">",(e,t)=>Number(e)>Number(t)],["<",(e,t)=>Number(e)<Number(t)]],qn=[[" + ",(e,t)=>e+t],[" - ",(e,t)=>e-t],[" * ",(e,t)=>e*t],[" / ",(e,t)=>t!==0?e/t:0],[" % ",(e,t)=>t!==0?e%t:0]];function Ee(e,t){let n=null;for(let r=0;r<e.length;r++){let o=e[r];if(o==="'"||o==='"')n=n===o?null:n??o;if(!n&&e.slice(r,r+t.length)===t)return r}return-1}function Un(e){let t=0,n=null;for(let r=0;r<e.length;r++){let o=e[r];if(o==="'"||o==='"')n=n===o?null:n??o;if(!n){if(o==="(")t++;else if(o===")")t--;else if(o==="?"&&t===0)return r}}return-1}function Xn(e){let t=0,n=null;for(let r=0;r<e.length;r++){let o=e[r];if(o==="'"||o==='"')n=n===o?null:n??o;if(!n){if(o==="?"||o==="(")t++;else if(o===")")t--;else if(o===":"&&t===0)return r}}return-1}function Yn(e){let t=[],n="",r=null;for(let o=0;o<e.length;o++){let i=e[o];if(i==="'"||i==='"')r=r===i?null:r??i;if(i==="|"&&!r)if(e[o+1]==="|")n+="||",o++;else t.push(n),n="";else n+=i}return t.push(n),t}function et(e){let t=e.replace(/^['"]|['"]$/g,"");if(t==="true")return!0;if(t==="false")return!1;let n=Number(t);return isNaN(n)?t:n}function Ft(e){let t=[],n="",r=null;for(let o of e){if(o==="'"||o==='"')r=r===o?null:r??o;if(o===","&&!r)t.push(n),n="";else n+=o}return t.push(n),t}function Re(e,t){if(!t)return e;let n=t.split("."),r=e;for(let o of n){if(r==null||typeof r!=="object")return;r=r[o]}return r}function Zn(e,t){let n=0,r=0;while((r=e.indexOf(t,r))!==-1)n++,r+=t.length;return n}function Te(e){return e.replace(/_([a-z])/g,(t,n)=>n.toUpperCase())}function nt(e){let t={};for(let[n,r]of Object.entries(e)){let o=n.startsWith("$")?n:Te(n);if(Array.isArray(r))t[o]=r.map((i)=>i!=null&&typeof i==="object"&&!Array.isArray(i)?nt(i):i);else if(r!=null&&typeof r==="object"&&!Array.isArray(r))t[o]=nt(r);else t[o]=r}return t}async function j(e,t){let n=Array.isArray(e)?e:[e];for(let r of n)await Qn(r,t)}function I(e,t){e.catch((n)=>O.error(`${t} failed:`,n))}async function Le(e,t,n,r){if(n!=null)O.debug(`${e} failed:`,t),await ce(n,r,{$error:t});else O.warn(`${e} failed:`,t)}async function Qn(e,t){let n=nt(e),r=n.action;switch(r){case"setState":{er(n,t);return}case"toggleState":{tr(n,t);return}case"appendState":{nr(n,t);return}case"popState":{rr(n,t);return}case"showToast":{or(n,t);return}case"closeOverlay":{ir(n,t);return}case"openLink":{sr(n);return}case"setInterval":{lr(n,t);return}case"toolCall":case"callTool":return dr(n,t);case"sendMessage":return cr(n,t);case"updateContext":{pr(n,t);return}case"fetch":return ur(n,t);case"openFilePicker":{fr(n,t);return}case"callHandler":return mr(n,t);case"requestDisplayMode":{gr(n,t);return}case"subscribe":{yr(n,t);return}case"unsubscribe":{Cr(n);return}default:O.warn(`Unknown action: ${r}`)}}function er(e,t){let{key:n,value:r}=e;if(Q(r))r=ee(r,t.store,t.scope);t.store.set(n,r),t.rerender(),ce(e.onSuccess,t)}function tr(e,t){t.store.toggle(e.key),t.rerender()}function nr(e,t){let n=e.value??e.item;if(Q(n))n=ee(n,t.store,t.scope);t.store.append(e.key,n,e.index),t.rerender()}function rr(e,t){t.store.pop(e.key,e.index),t.rerender()}function or(e,t){t.onToast?.({message:Me(e.message,t),description:e.description!=null?Me(e.description,t):void 0,variant:e.variant,duration:e.duration})}function ir(e,t){if(typeof document<"u")document.dispatchEvent(new CustomEvent("prefab:close-overlay"))}function sr(e){if(typeof window<"u"){let t=e.url;if(!t){O.warn("openLink: missing url");return}if(!Vt(t)){O.warn(`Blocked unsafe URL scheme: ${t}`);return}window.open(t,e.target??"_blank")}}var Ne=new Set,ar=20,Bt=100;function lr(e,t){let n=Math.max(e.intervalMs,Bt),r=e.onTick;if(typeof globalThis.setInterval!=="function")return;if(Ne.size>=ar){O.warn("Max intervals reached, ignoring new setInterval");return}let o=globalThis.setInterval(()=>I(j(r,t),"interval action"),n);Ne.add(o)}function Jt(){for(let e of Ne)globalThis.clearInterval(e);Ne.clear()}async function dr(e,t){if(!t.transport){O.warn("No MCP transport configured for toolCall");return}let n=e.tool,r=rt(e.arguments,t);try{let o=await t.transport.callTool(n,r);if(e.resultKey!=null)t.store.set(e.resultKey,o);let i=He(o);if(i&&t.remount)t.remount(i);else Pe(o,t),t.rerender();await ce(e.onSuccess,t,{$result:o})}catch(o){await Le("toolCall",o,e.onError,t)}}async function cr(e,t){if(!t.transport){O.warn("No MCP transport configured for sendMessage");return}await t.transport.sendMessage(Me(e.message,t))}function pr(e,t){let n=e.context;if(n!=null)t.store.merge(n),t.rerender()}async function ur(e,t){let n=Me(e.url,t);if(!Vt(n)){O.warn(`Blocked unsafe URL in fetch: ${n}`);return}let r=e.method??"GET",o=e.headers,i=e.body!==void 0?JSON.stringify(e.body):void 0;try{let s=await globalThis.fetch(n,{method:r,headers:{"Content-Type":"application/json",...o},...i&&{body:i}}),a=await s.json().catch(()=>s.text());if(e.resultKey!=null)t.store.set(e.resultKey,a);let l=He(a);if(l&&t.remount)t.remount(l);else Pe(a,t),t.rerender();await ce(e.onSuccess,t,{$result:a})}catch(s){await Le("fetch",s,e.onError,t)}}function fr(e,t){if(typeof document>"u")return;let n=document.createElement("input");if(n.type="file",e.accept!=null)n.accept=e.accept;if(e.multiple===!0)n.multiple=!0;n.addEventListener("change",()=>{let r=Array.from(n.files??[]);if(e.resultKey!=null)t.store.set(e.resultKey,r);t.rerender(),ce(e.onSuccess,t,{$result:r})}),n.click()}async function mr(e,t){let n=e.handler,r=rt(e.arguments,t);if(!t.transport){O.warn(`No transport configured for callHandler: ${n}`);return}try{let o=await t.transport.callTool(n,r);if(e.resultKey!=null)t.store.set(e.resultKey,o);let i=He(o);if(i&&t.remount)t.remount(i);else Pe(o,t),t.rerender();await ce(e.onSuccess,t,{$result:o})}catch(o){await Le("callHandler",o,e.onError,t)}}function gr(e,t){if(typeof document<"u")document.dispatchEvent(new CustomEvent("prefab:request-display-mode",{detail:{mode:e.mode}}))}var ie=new Map,hr=50,br=2000;function yr(e,t){let{uri:n,stateKey:r}=e;if(!n||!r){O.warn("subscribe: missing uri or stateKey");return}if(ie.has(n))return;if(ie.size>=hr){O.warn("Max subscriptions reached, ignoring new subscribe");return}let o=(c)=>{let g=He(c);if(g&&t.remount)t.remount(g);else{if(!Pe(c,t))t.store.set(r,c);t.rerender()}ce(e.onData,t,{$data:c})};if(t.transport?.subscribe&&t.transport.capabilities?.subscriptions){let c=t.transport.subscribe(n,o);ie.set(n,c);return}let i=e.fallbackTool,s=e.fallbackInterval??br;if(!i){O.warn("subscribe: host lacks subscriptions and no fallbackTool specified");return}if(!t.transport){O.warn("No MCP transport configured for subscribe fallback");return}let a=e.fallbackArgs??{},l=Math.max(s,Bt),d=t.transport,u=globalThis.setInterval(()=>{(async()=>{try{let c=rt(a,t),g=await d.callTool(i,c);o(g)}catch(c){Le("subscribe",c,e.onError,t)}})()},l);ie.set(n,()=>globalThis.clearInterval(u))}function Cr(e){let t=e.uri;if(!t){O.warn("unsubscribe: missing uri");return}let n=ie.get(t);if(n)n(),ie.delete(t)}function zt(){for(let[e,t]of ie)try{t()}catch(n){O.warn(`Error cleaning up subscription '${e}':`,n)}ie.clear()}function He(e){if(e==null||typeof e!=="object")return null;let t=e;if("$prefab"in t&&"view"in t)return t;if("structuredContent"in t){let n=t.structuredContent;if(n!=null&&typeof n==="object"){let r=n;if("$prefab"in r&&"view"in r)return r}}if("content"in t&&Array.isArray(t.content)){for(let n of t.content)if(n.type==="text"&&typeof n.text==="string")try{let r=JSON.parse(n.text);if(r!=null&&typeof r==="object"){let o=r;if("$prefab"in o&&"view"in o)return o}}catch{}}return null}function vr(e){if(e==null||typeof e!=="object")return null;let t=e;if(tt(t))return t;if("structuredContent"in t){let n=t.structuredContent;if(n!=null&&typeof n==="object"&&tt(n))return n}if("content"in t&&Array.isArray(t.content)){for(let n of t.content)if(n.type==="text"&&typeof n.text==="string")try{let r=JSON.parse(n.text);if(r!=null&&typeof r==="object"&&tt(r))return r}catch{}}return null}function tt(e){if(!("$prefab"in e)||!("update"in e))return!1;let t=e.update;return t!=null&&typeof t==="object"&&"state"in t}function Pe(e,t){let n=vr(e);if(!n)return!1;let r=n.update;if(t.store.merge(r.state),r.actions!=null)I(j(r.actions,t),"update action");return!0}var wr=/^\s*(javascript|vbscript|data):/i;function Vt(e){return!wr.test(e)}function Me(e,t){if(Q(e)){let n=ee(e,t.store,t.scope);return L(n)}return L(e)}function rt(e,t){if(!e)return{};let n={};for(let[r,o]of Object.entries(e))n[r]=Q(o)?ee(o,t.store,t.scope):o;return n}async function ce(e,t,n){if(e==null)return;let r={...t.scope,...n};await j(e,{...t,scope:r})}function it(e){let t={};for(let[n,r]of Object.entries(e)){let o=n.startsWith("$")?n:Te(n);if(Array.isArray(r))t[o]=r.map((i)=>i!=null&&typeof i==="object"&&!Array.isArray(i)?it(i):i);else if(r!=null&&typeof r==="object"&&!Array.isArray(r))t[o]=it(r);else t[o]=r}return t}class st{callbacks=[];track(e){this.callbacks.push(e)}flush(){for(let e of this.callbacks)try{e()}catch(t){O.warn("destroy callback error:",t)}this.callbacks=[]}get size(){return this.callbacks.length}}function xr(e){return typeof e==="object"&&"element"in e}var Oe=new Map;function p(e,t){if(Oe.has(e))O.warn(`overriding existing renderer for "${e}"`);Oe.set(e,t)}function at(){return[...Oe.keys()].sort()}var Wt=new Set;function Kt(e){Wt.clear();for(let t of e)Wt.add(t)}function J(e,t){let n=it(e);if(t.defs?.[n.type]){let i={...t.defs[n.type],...n,type:t.defs[n.type].type};return J(i,t)}let r=Oe.get(n.type),o;if(r){let i=r(n,t);if(xr(i))o=i.element,t.destroyRegistry?.track(i.destroy);else o=i}else if(o=document.createElement("div"),o.setAttribute("data-prefab-type",n.type),n.children)for(let i of n.children)o.appendChild(J(i,t));if(o instanceof HTMLElement){if(n.id)o.id=n.id;if(n.cssClass){let i=C(n.cssClass,t);if(i)o.className=(o.className?o.className+" ":"")+i}if(n.onClick!=null){if(o.addEventListener("click",()=>{I(j(n.onClick,_(t)),"onClick")}),o.tagName!=="BUTTON"&&o.tagName!=="A")o.setAttribute("role","button"),o.setAttribute("tabindex","0"),o.addEventListener("keydown",(i)=>{let s=i.key;if(s==="Enter"||s===" ")i.preventDefault(),I(j(n.onClick,_(t)),"onClick")})}}if(n.onMount){let i=n.onMount,s=_(t);queueMicrotask(()=>I(j(i,s),"onMount"))}return o}function H(e,t,n){if(!e.children)return;se(e.children,t,n)}function se(e,t,n){let r=0;while(r<e.length){let o=e[r];if(o.type==="If")r=kr(e,r,t,n);else if(o.type==="Elif"||o.type==="Else")r++;else t.appendChild(J(o,n)),r++}}function kr(e,t,n,r){let o=!1,i=t,s=e[i];if(_t(s.condition,r))ot(s,n,r),o=!0;i++;while(i<e.length){let a=e[i];if(a.type==="Elif"){if(!o&&_t(a.condition,r))ot(a,n,r),o=!0;i++}else if(a.type==="Else"){if(!o)ot(a,n,r);i++;break}else break}return i}function _t(e,t){if(!e)return!1;if(Q(e))return Boolean(ee(e,t.store,t.scope));return Boolean(t.store.get(e))}function ot(e,t,n){if(!e.children)return;se(e.children,t,n)}function C(e,t){if(Q(e)){let n=ee(e,t.store,t.scope);return L(n)}return L(e)}function K(e,t){if(Q(e))return ee(e,t.store,t.scope);return e}function _(e){return{store:e.store,transport:e.transport,scope:e.scope,rerender:e.rerender,onToast:e.onToast,remount:e.remount}}function m(e,t){let n=document.createElement(e);if(t)n.className=t;return n}function lt(e,t){return e.textContent=t,e}function Xt(){p("Column",Sr),p("Row",Ar),p("Grid",Gt),p("GridItem",qt),p("Container",Er),p("Div",Ut),p("Span",Rr),p("Dashboard",Gt),p("DashboardItem",qt),p("Pages",Tr),p("Page",Ut),p("Detail",Nr),p("MasterDetail",Mr)}function Sr(e,t){let n=m("div","pf-column");n.style.display="flex",n.style.flexDirection="column";let r=$e(e);if(r!=null)n.style.gap=`${r*4}px`;if(e.align!=null)n.style.alignItems=Yt(e.align);if(e.justify!=null)n.style.justifyContent=Zt(e.justify);return H(e,n,t),n}function Ar(e,t){let n=m("div","pf-row");n.style.display="flex",n.style.flexDirection="row";let r=$e(e);if(r!=null)n.style.gap=`${r*4}px`;if(e.align!=null)n.style.alignItems=Yt(e.align);if(e.justify!=null)n.style.justifyContent=Zt(e.justify);if(e.wrap===!0)n.style.flexWrap="wrap";return H(e,n,t),n}function Gt(e,t){let n=m("div","pf-grid");n.style.display="grid";let r=e.columns??3;n.style.gridTemplateColumns=`repeat(${r}, 1fr)`;let o=$e(e);if(o!=null)n.style.gap=`${o*4}px`;return H(e,n,t),n}function qt(e,t){let n=m("div","pf-grid-item");if(e.colSpan!=null)n.style.gridColumn=`span ${e.colSpan}`;if(e.rowSpan!=null)n.style.gridRow=`span ${e.rowSpan}`;return H(e,n,t),n}function Er(e,t){let n=m("div","pf-container");if(n.style.maxWidth=e.maxWidth??"1200px",n.style.margin="0 auto",e.padding!=null)n.style.padding=`${e.padding*4}px`;return H(e,n,t),n}function Ut(e,t){let n=m("div","pf-div");return H(e,n,t),n}function Rr(e,t){let n=m("span","pf-span");return H(e,n,t),n}function Tr(e,t){let n=m("div","pf-pages");return H(e,n,t),n}function Nr(e,t){let n=m("div","pf-detail"),r=e.of!=null?K(e.of,t):void 0;if(r!=null&&r!==""&&r!==!1&&r!==0)H(e,n,t);else if(e.empty!=null){let o=e.empty;n.appendChild(J(o,t))}return n}function Mr(e,t){let n=m("div","pf-master-detail");n.style.display="flex",n.style.flexDirection="row";let r=$e(e);if(r!=null)n.style.gap=`${r*4}px`;let o=e.masterWidth??"33%",i=e.children??[];if(i.length>0){let s=m("div","pf-master-detail-master");s.style.width=o,s.style.flexShrink="0",s.style.overflow="auto",s.appendChild(J(i[0],t)),n.appendChild(s)}if(i.length>1){let s=m("div","pf-master-detail-detail");s.style.flex="1",s.style.overflow="auto",s.appendChild(J(i[1],t)),n.appendChild(s)}return n}var Lr=/\bgap-(\d+)\b/;function $e(e){if(e.gap!=null)return e.gap;if(typeof e.cssClass==="string"){let t=Lr.exec(e.cssClass);if(t)return Number(t[1])}return null}function Yt(e){return{start:"flex-start",end:"flex-end",center:"center",stretch:"stretch",baseline:"baseline"}[e]??e}function Zt(e){return{start:"flex-start",end:"flex-end",center:"center",between:"space-between",around:"space-around",evenly:"space-evenly"}[e]??e}var Hr={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function xe(e){return e.replace(/[&<>"']/g,(t)=>Hr[t]??t)}function en(){p("Heading",Pr),p("H1",(e,t)=>De(e,t,"h1")),p("H2",(e,t)=>De(e,t,"h2")),p("H3",(e,t)=>De(e,t,"h3")),p("H4",(e,t)=>De(e,t,"h4")),p("Text",Or),p("P",$r),p("Lead",(e,t)=>he(e,t,"p","pf-lead")),p("Large",(e,t)=>he(e,t,"span","pf-large")),p("Small",(e,t)=>he(e,t,"small","pf-small")),p("Muted",(e,t)=>he(e,t,"p","pf-muted")),p("BlockQuote",(e,t)=>he(e,t,"blockquote","pf-blockquote")),p("Label",(e,t)=>he(e,t,"label","pf-label")),p("Link",jr),p("Code",Ir),p("Markdown",Fr),p("Kbd",Br)}function Pr(e,t){let n=e.level??2,r=`h${Math.min(Math.max(n,1),6)}`,o=document.createElement(r);return o.className=`pf-heading pf-${r}`,o.textContent=C(e.content,t),o}function De(e,t,n){let r=document.createElement(n);return r.className=`pf-heading pf-${n}`,r.textContent=C(e.content,t),r}function Or(e,t){return lt(m("span","pf-text"),C(e.content,t))}function $r(e,t){return lt(m("p","pf-p"),C(e.content,t))}function he(e,t,n,r){let o=document.createElement(n);return o.className=r,o.textContent=C(e.content,t),o}var Dr=/^\s*(javascript|vbscript|data):/i;function jr(e,t){let n=document.createElement("a");if(n.className="pf-link",n.textContent=C(e.content,t),e.href!=null){let r=C(e.href,t);if(!Dr.test(r))n.href=r}if(e.target!=null)n.target=C(e.target,t);return n}function Ir(e,t){let n=m("pre","pf-code"),r=m("code");if(r.textContent=C(e.content,t),e.language!=null)r.setAttribute("data-language",e.language);return n.appendChild(r),n}function Fr(e,t){let n=m("div","pf-markdown"),r=C(e.content,t);return n.innerHTML=tn(r),n.setAttribute("data-markdown","true"),n}var Qt=/^\s*(javascript|vbscript|data):/i;function je(e){let t=xe(e),n=[];return t=t.replace(/`([^`]+)`/g,(r,o)=>(n.push(`<code>${o}</code>`),`﷐CODE${n.length-1}﷐`)),t=t.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,(r,o,i)=>{if(Qt.test(i))return xe(o);return`<img src="${i}" alt="${o}" />`}),t=t.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(r,o,i)=>{if(Qt.test(i))return o;return`<a href="${i}">${o}</a>`}),t=t.replace(/\*{3}(.+?)\*{3}/g,"<strong><em>$1</em></strong>"),t=t.replace(/_{3}(.+?)_{3}/g,"<strong><em>$1</em></strong>"),t=t.replace(/\*{2}(.+?)\*{2}/g,"<strong>$1</strong>"),t=t.replace(/_{2}(.+?)_{2}/g,"<strong>$1</strong>"),t=t.replace(/\*(.+?)\*/g,"<em>$1</em>"),t=t.replace(/(?<!\w)_(.+?)_(?!\w)/g,"<em>$1</em>"),t=t.replace(/~~(.+?)~~/g,"<del>$1</del>"),t=t.replace(/\uFDD0CODE(\d+)\uFDD0/g,(r,o)=>n[parseInt(o)]),t}function tn(e){let t=e.replace(/\r\n?/g,`
2
2
  `).split(`
3
- `),n=[],r=0;while(r<t.length){let o=t[r];if(o.trimStart().startsWith("```")){let a=o.trimStart().slice(3).trim(),l=[];r++;while(r<t.length&&!t[r].trimStart().startsWith("```"))l.push(Ce(t[r])),r++;r++;let c=a?` data-language="${Ce(a)}"`:"";n.push(`<pre class="pf-code"><code${c}>${l.join(`
4
- `)}</code></pre>`);continue}if(/^(\s*[-*_]\s*){3,}$/.test(o)){n.push("<hr />"),r++;continue}let i=/^(#{1,6})\s+(.+)$/.exec(o);if(i){let a=i[1].length;n.push(`<h${a}>${Oe(i[2])}</h${a}>`),r++;continue}if(o.startsWith("> ")||o===">"){let a=[];while(r<t.length&&(t[r].startsWith("> ")||t[r]===">"))a.push(t[r].replace(/^>\s?/,"")),r++;n.push(`<blockquote>${Qt(a.join(`
5
- `))}</blockquote>`);continue}if(/^[\s]*[-*+]\s+/.test(o)){n.push("<ul>");while(r<t.length&&/^[\s]*[-*+]\s+/.test(t[r]))n.push(`<li>${Oe(t[r].replace(/^[\s]*[-*+]\s+/,""))}</li>`),r++;n.push("</ul>");continue}if(/^[\s]*\d+\.\s+/.test(o)){n.push("<ol>");while(r<t.length&&/^[\s]*\d+\.\s+/.test(t[r]))n.push(`<li>${Oe(t[r].replace(/^[\s]*\d+\.\s+/,""))}</li>`),r++;n.push("</ol>");continue}if(o.trim()===""){r++;continue}let s=[];while(r<t.length&&t[r].trim()!==""&&!/^#{1,6}\s/.test(t[r])&&!/^[-*+]\s/.test(t[r])&&!/^\d+\.\s/.test(t[r])&&!t[r].startsWith("> ")&&!t[r].trimStart().startsWith("```")&&!/^(\s*[-*_]\s*){3,}$/.test(t[r]))s.push(t[r]),r++;n.push(`<p>${s.map(Oe).join("<br />")}</p>`)}return n.join(`
6
- `)}function Ir(e,t){let n=document.createElement("kbd");return n.className="pf-kbd",n.textContent=C(e.content,t),n}function tn(){p("Card",Fr),p("CardHeader",at("pf-card-header")),p("CardTitle",en("pf-card-title","h3")),p("CardDescription",en("pf-card-description","p")),p("CardContent",at("pf-card-content")),p("CardFooter",at("pf-card-footer"))}function Fr(e,t){let n=m("div","pf-card");return n.style.overflow="hidden",H(e,n,t),n}function at(e){return(t,n)=>{let r=m("div",e);return r.style.padding="16px 24px",H(t,r,n),r}}function en(e,t){return(n,r)=>{let o=document.createElement(t);return o.className=e,o.textContent=C(n.content,r),o}}function nn(){p("DataTable",Br),p("Badge",Jr),p("Dot",zr),p("Metric",Wr),p("Ring",_r),p("Progress",Vr),p("Separator",Kr),p("Loader",Gr),p("Icon",qr),p("Sparkline",Ur)}function Br(e,t){let n=m("div","pf-datatable-wrapper"),r=document.createElement("table");r.className="pf-datatable",r.style.width="100%",r.style.borderCollapse="collapse";let o=e.columns??[],i=K(e.rows,t),s=e.rowKey,a=e.selected,l=document.createElement("thead"),c=document.createElement("tr");for(let d of o){let g=document.createElement("th");g.className="pf-datatable-th",g.textContent=d.header??d.key,g.style.padding="8px 12px",g.style.textAlign="left",c.appendChild(g)}l.appendChild(c),r.appendChild(l);let u=document.createElement("tbody");if(Array.isArray(i)){let d=a!=null?K(a,t):void 0;for(let g of i){let h=document.createElement("tr");h.className="pf-datatable-row";let y=g,f=g===null||typeof g!=="object";if(s&&d!=null&&y[s]!=null&&P(y[s])===P(d))h.classList.add("pf-datatable-row-selected");if(e.onRowClick!=null&&s)h.style.cursor="pointer",h.addEventListener("click",()=>{let b={...t.scope,$item:y,$index:i.indexOf(g)},w=V({...t,scope:b});F(j(e.onRowClick,w),"onRowClick")});for(let b of o){let w=document.createElement("td");w.className="pf-datatable-td";let S;if(b.accessor)S=K(`{{ $item.${b.accessor} }}`,{...t,scope:{...t.scope,$item:y}});else if(S=f?g:y[b.key],b.format&&S!=null)S=K(`{{ __fmtVal | ${b.format} }}`,{...t,scope:{...t.scope,__fmtVal:S}});w.textContent=P(S),w.style.padding="8px 12px",h.appendChild(w)}u.appendChild(h)}}if(r.appendChild(u),e.search===!0){let d=document.createElement("input");d.type="text",d.placeholder="Search...",d.className="pf-datatable-search",d.style.marginBottom="8px",d.style.padding="6px 12px",d.style.width="100%",d.style.boxSizing="border-box",d.addEventListener("input",()=>{let g=d.value.toLowerCase(),h=Array.from(u.querySelectorAll("tr"));for(let y of h){let f=(y.textContent??"").toLowerCase();y.style.display=f.includes(g)?"":"none"}}),n.appendChild(d)}return n.appendChild(r),n}function Jr(e,t){let n=m("span","pf-badge"),r=e.variant??"default";return n.setAttribute("data-variant",r),n.style.alignItems="center",n.style.padding="2px 10px",n.style.borderRadius="9999px",n.style.fontSize="12px",n.style.fontWeight="500",n.textContent=C(e.label??e.content,t),Xr(n,r),n}function zr(e,t){let n=m("span","pf-dot"),r=e.color??"gray";return n.style.display="inline-block",n.style.width="8px",n.style.height="8px",n.style.borderRadius="50%",n.style.backgroundColor=r,n}function Wr(e,t){let n=m("div","pf-metric"),r=m("div","pf-metric-label");r.textContent=C(e.label,t),r.style.fontSize="14px",n.appendChild(r);let o=m("div","pf-metric-value");if(o.textContent=C(e.value,t),o.style.fontSize="28px",o.style.fontWeight="700",n.appendChild(o),e.delta!=null){let i=m("span","pf-metric-delta");i.textContent=C(e.delta,t);let s=e.trend??"",a=e.trendSentiment??"neutral";if(i.style.fontSize="14px",i.style.color=a==="positive"?"green":a==="negative"?"red":"inherit",s==="up")i.textContent="↑ "+i.textContent;else if(s==="down")i.textContent="↓ "+i.textContent;n.appendChild(i)}if(e.description!=null){let i=m("div","pf-metric-desc");i.textContent=C(e.description,t),i.style.fontSize="12px",n.appendChild(i)}return n}function _r(e,t){let n=m("div","pf-ring"),r=e.size??80,o=e.thickness??8,i=Number(K(e.value,t)??0),s=Math.max(0,Math.min(100,i)),a=(r-o)/2,l=2*Math.PI*a,c=l*(1-s/100),u=document.createElementNS("http://www.w3.org/2000/svg","svg");u.setAttribute("width",String(r)),u.setAttribute("height",String(r)),u.setAttribute("viewBox",`0 0 ${r} ${r}`);let d=document.createElementNS("http://www.w3.org/2000/svg","circle");d.setAttribute("cx",String(r/2)),d.setAttribute("cy",String(r/2)),d.setAttribute("r",String(a)),d.setAttribute("fill","none"),d.setAttribute("stroke","var(--muted, #e5e7eb)"),d.setAttribute("stroke-width",String(o));let g=document.createElementNS("http://www.w3.org/2000/svg","circle");if(g.setAttribute("cx",String(r/2)),g.setAttribute("cy",String(r/2)),g.setAttribute("r",String(a)),g.setAttribute("fill","none"),g.setAttribute("stroke","var(--primary, #3b82f6)"),g.setAttribute("stroke-width",String(o)),g.setAttribute("stroke-dasharray",String(l)),g.setAttribute("stroke-dashoffset",String(c)),g.setAttribute("stroke-linecap","round"),g.style.transform="rotate(-90deg)",g.style.transformOrigin="center",u.appendChild(d),u.appendChild(g),n.appendChild(u),e.label!=null){let h=m("div","pf-ring-label");h.textContent=C(e.label,t),h.style.textAlign="center",h.style.fontSize="12px",n.appendChild(h)}return n}function Vr(e,t){let n=m("div","pf-progress");n.setAttribute("role","progressbar");let r=Number(K(e.value,t)??0),o=e.max??100,i=o>0?Math.max(0,Math.min(100,r/o*100)):0;n.setAttribute("aria-valuenow",String(r)),n.setAttribute("aria-valuemin","0"),n.setAttribute("aria-valuemax",String(o)),n.style.height="8px",n.style.borderRadius="4px",n.style.overflow="hidden";let s=m("div","pf-progress-fill");return s.style.height="100%",s.style.width=`${i}%`,s.style.borderRadius="4px",s.style.transition="width 0.3s ease",n.appendChild(s),n}function Kr(e,t){let n=document.createElement("hr");return n.className="pf-separator",n.style.border="none",n.style.margin="8px 0",n}function Gr(e,t){let n=m("div","pf-loader");return n.textContent="⏳",n.style.display="flex",n.style.justifyContent="center",n.style.padding="16px",n}function qr(e,t){let n=m("span","pf-icon");return n.setAttribute("data-icon",C(e.name??e.content,t)),n}function Ur(e,t){let n=m("div","pf-sparkline"),r=e.data??[];if(r.length===0)return n;let o=e.width??120,i=e.height??32,s=Math.max(...r),a=Math.min(...r),l=s-a||1,c=document.createElementNS("http://www.w3.org/2000/svg","svg");c.setAttribute("width",String(o)),c.setAttribute("height",String(i)),c.setAttribute("viewBox",`0 0 ${o} ${i}`);let u=r.length>1?r.length-1:1,d=r.map((h,y)=>{let f=y/u*o,b=i-(h-a)/l*(i-4)-2;return`${f},${b}`}).join(" "),g=document.createElementNS("http://www.w3.org/2000/svg","polyline");return g.setAttribute("points",d),g.setAttribute("fill","none"),g.setAttribute("stroke","var(--primary, #3b82f6)"),g.setAttribute("stroke-width","1.5"),c.appendChild(g),n.appendChild(c),n}function Xr(e,t){let r={success:{bg:"#10b981",fg:"#fff"},warning:{bg:"#f59e0b",fg:"#fff"},info:{bg:"#3b82f6",fg:"#fff"}}[t];if(r)e.style.backgroundColor=r.bg,e.style.color=r.fg}function on(){p("Form",Yr),p("Input",Zr),p("Textarea",ve(Qr)),p("Button",eo),p("ButtonGroup",to),p("Select",ve(no)),p("SelectOption",ro),p("SelectGroup",De("pf-select-group")),p("SelectLabel",we("pf-select-label")),p("SelectSeparator",rn),p("Checkbox",oo),p("Switch",io),p("Slider",ve(so)),p("Radio",lo),p("RadioGroup",co),p("Combobox",ve(po)),p("ComboboxOption",uo),p("ComboboxGroup",De("pf-combobox-group")),p("ComboboxLabel",we("pf-combobox-label")),p("ComboboxSeparator",rn),p("Calendar",fo),p("DatePicker",ve(mo)),p("Field",De("pf-field")),p("FieldTitle",we("pf-field-title")),p("FieldDescription",we("pf-field-description")),p("FieldContent",De("pf-field-content")),p("FieldError",we("pf-field-error")),p("ChoiceCard",go)}function Yr(e,t){let n=document.createElement("form");return n.className="pf-form",n.addEventListener("submit",(r)=>{r.preventDefault();let o=new FormData(n),i={};if(o.forEach((s,a)=>{i[a]=s}),t.store.merge(i),e.onSubmit!=null){let s=V(t);s.scope={...t.scope,...i},F(j(e.onSubmit,s),"onSubmit")}}),H(e,n,t),n}function sn(e,t,n){if(t.label==null)return;let r=document.createElement("label");if(r.className="pf-input-label",r.textContent=C(t.label,n),t.name!=null)r.htmlFor=t.name;r.style.fontSize="14px",r.style.fontWeight="500",e.insertBefore(r,e.firstChild)}function ve(e){return(t,n)=>{let r=e(t,n);return r.style.display="flex",r.style.flexDirection="column",r.style.gap="4px",sn(r,t,n),r}}function Zr(e,t){let n=m("div","pf-input-wrapper");n.style.display="flex",n.style.flexDirection="column",n.style.gap="4px",sn(n,e,t);let r=document.createElement("input");if(r.className="pf-input",r.type=e.inputType??"text",e.name!=null)r.name=e.name;if(e.name!=null)r.id=`pf-input-${e.name}`;if(e.placeholder!=null)r.placeholder=C(e.placeholder,t);if(e.required===!0)r.required=!0,r.setAttribute("aria-required","true");if(e.error!=null)r.setAttribute("aria-invalid","true");let o=e.name;if(o){let i=t.store.get(o);if(i!=null)r.value=P(i);r.addEventListener("input",()=>{if(t.store.set(o,r.value),e.onChange!=null)F(j(e.onChange,{...V(t),scope:{...t.scope,$event:r.value}}),"onChange")})}return lt(r),n.appendChild(r),n}function Qr(e,t){let n=m("div","pf-textarea-wrapper"),r=document.createElement("textarea");if(r.className="pf-textarea",e.name!=null)r.name=e.name;if(e.name!=null)r.id=`pf-textarea-${e.name}`;if(e.placeholder!=null)r.placeholder=C(e.placeholder,t);if(e.rows!=null)r.rows=e.rows;if(e.required===!0)r.setAttribute("aria-required","true");let o=e.name;if(o!=null){let i=t.store.get(o);if(i!=null)r.value=P(i);r.addEventListener("input",()=>{if(t.store.set(o,r.value),e.onChange!=null)F(j(e.onChange,{...V(t),scope:{...t.scope,$event:r.value}}),"onChange")})}return lt(r),n.appendChild(r),n}function eo(e,t){let n=document.createElement("button");n.className="pf-button",n.type=e.submit===!0?"submit":"button",n.textContent=C(e.label,t);let r=e.variant??"default";if(n.setAttribute("data-variant",r),ao(n,r),e.size!=null)n.setAttribute("data-size",e.size);if(e.disabled===!0)n.disabled=!0;return n}function to(e,t){let n=m("div","pf-button-group");return n.style.display="flex",n.style.gap="8px",H(e,n,t),n}function no(e,t){let n=m("div","pf-select-wrapper"),r=document.createElement("select");if(r.className="pf-select",e.name!=null)r.name=e.name;if(lt(r),e.placeholder!=null){let s=document.createElement("option");s.value="",s.textContent=C(e.placeholder,t),s.disabled=!0,s.selected=!0,s.hidden=!0,r.appendChild(s)}let o=e.options;if(Array.isArray(o))for(let s of o){let a=document.createElement("option");a.value=s.value??"",a.textContent=s.label??a.value,r.appendChild(a)}if(e.children)for(let s of e.children)if(s.type==="SelectOption"){let a=document.createElement("option");a.value=s.value??"",a.textContent=s.label??a.value,r.appendChild(a)}else r.appendChild(J(s,t));let i=e.name;if(i){let s=t.store.get(i);if(s!=null)r.value=P(s);r.addEventListener("change",()=>{if(t.store.set(i,r.value),e.onChange!=null)F(j(e.onChange,{...V(t),scope:{...t.scope,$event:r.value}}),"onChange")})}return n.appendChild(r),n}function ro(e,t){return m("span")}function oo(e,t){let n=m("label","pf-checkbox-wrapper");n.style.display="flex",n.style.alignItems="center",n.style.gap="8px",n.style.cursor="pointer";let r=document.createElement("input");if(r.type="checkbox",r.className="pf-checkbox",e.name!=null)r.name=e.name;if(e.checked===!0)r.checked=!0;let o=e.name;if(o){let i=t.store.get(o);if(typeof i==="boolean")r.checked=i;r.addEventListener("change",()=>{if(t.store.set(o,r.checked),e.onChange!=null)F(j(e.onChange,{...V(t),scope:{...t.scope,$event:r.checked}}),"onChange")})}if(n.appendChild(r),e.label!=null){let i=m("span");i.textContent=C(e.label,t),n.appendChild(i)}return n}function io(e,t){let n=m("label","pf-switch-wrapper");n.style.display="flex",n.style.alignItems="center",n.style.gap="8px",n.style.cursor="pointer";let r=document.createElement("input");if(r.type="checkbox",r.className="pf-switch",r.setAttribute("role","switch"),e.name!=null)r.name=e.name;let o=e.name;if(o){let i=t.store.get(o);if(typeof i==="boolean")r.checked=i;r.addEventListener("change",()=>{if(t.store.set(o,r.checked),e.onChange!=null)F(j(e.onChange,{...V(t),scope:{...t.scope,$event:r.checked}}),"onChange")})}if(n.appendChild(r),e.label!=null){let i=m("span");i.textContent=C(e.label,t),n.appendChild(i)}return n}function so(e,t){let n=m("div","pf-slider-wrapper"),r=document.createElement("input");if(r.type="range",r.className="pf-slider",e.name!=null)r.name=e.name;if(e.min!=null)r.min=P(e.min);if(e.max!=null)r.max=P(e.max);if(e.step!=null)r.step=P(e.step);let o=e.name;if(o){let i=t.store.get(o);if(i!=null)r.value=P(i);r.addEventListener("input",()=>{if(t.store.set(o,Number(r.value)),e.onChange!=null)F(j(e.onChange,{...V(t),scope:{...t.scope,$event:Number(r.value)}}),"onChange")})}return n.appendChild(r),n}function lt(e){e.style.padding="8px 12px",e.style.fontSize="14px",e.style.width="100%",e.style.boxSizing="border-box"}function ao(e,t){if(e.style.padding="8px 16px",e.style.fontSize="14px",e.style.fontWeight="500",e.style.cursor="pointer",e.style.border="none",t==="ghost")e.style.backgroundColor="transparent",e.style.color="inherit"}function De(e){return(t,n)=>{let r=m("div",e);return H(t,r,n),r}}function we(e){return(t,n)=>{let r=m("span",e);return r.textContent=C(t.content,n),r}}function rn(){let e=document.createElement("hr");return e.className="pf-separator",e.style.border="none",e.style.margin="4px 0",e}function lo(e,t){let n=m("label","pf-radio");n.style.display="flex",n.style.alignItems="center",n.style.gap="8px",n.style.cursor="pointer";let r=document.createElement("input");if(r.type="radio",r.value=C(e.value,t),n.appendChild(r),e.label!=null){let o=m("span","pf-radio-label");o.textContent=C(e.label,t),n.appendChild(o)}return n}function co(e,t){let n=m("fieldset","pf-radio-group");if(n.style.border="none",n.style.padding="0",n.style.display="flex",n.style.flexDirection="column",n.style.gap="8px",e.label!=null){let i=document.createElement("legend");i.textContent=C(e.label,t),i.style.fontWeight="500",i.style.marginBottom="4px",n.appendChild(i)}H(e,n,t);let r=C(e.name,t),o=t.store.get(r);for(let i of Array.from(n.querySelectorAll('input[type="radio"]')))if(i.name=r,o!=null&&i.value===P(o))i.checked=!0;return n.addEventListener("change",(i)=>{let s=i.target;if(s.type==="radio"){if(t.store.set(r,s.value),e.onChange!=null)F(j(e.onChange,V(t)),"onChange")}}),n}function po(e,t){let n=m("div","pf-combobox"),r=document.createElement("input");if(r.className="pf-combobox-input",r.type="text",r.name=C(e.name,t),e.placeholder!=null)r.placeholder=C(e.placeholder,t);if(e.value!==void 0)r.value=C(e.value,t);let o=r.name,i=t.store.get(o);if(i!=null)r.value=P(i);r.style.padding="6px 12px",r.style.borderRadius="6px",r.style.width="100%",r.style.boxSizing="border-box";let s=m("div","pf-combobox-dropdown");if(s.style.display="none",s.style.position="absolute",s.style.borderRadius="6px",s.style.maxHeight="200px",s.style.overflowY="auto",s.style.zIndex="50",H(e,s,t),r.addEventListener("focus",()=>{s.style.display="block"}),r.addEventListener("blur",()=>{setTimeout(()=>{s.style.display="none"},150)}),e.searchable!==!1)r.addEventListener("input",()=>{let a=r.value.toLowerCase();for(let l of Array.from(s.querySelectorAll(".pf-combobox-option"))){let c=(l.textContent??"").toLowerCase();l.style.display=c.includes(a)?"":"none"}});if(e.onChange!=null)n.addEventListener("pf-combobox-select",()=>{F(j(e.onChange,{...V(t),scope:{...t.scope,$event:r.value}}),"onChange")});return n.style.position="relative",n.appendChild(r),n.appendChild(s),n}function uo(e,t){let n=m("div","pf-combobox-option");return n.style.padding="6px 12px",n.style.cursor="pointer",n.textContent=C(e.label??e.value,t),n.dataset.value=C(e.value,t),n.addEventListener("mousedown",()=>{let r=n.closest(".pf-combobox"),o=r?.querySelector("input");if(o)o.value=n.dataset.value??"",t.store.set(o.name,o.value),r?.dispatchEvent(new CustomEvent("pf-combobox-select",{bubbles:!1}))}),n}function fo(e,t){let n=m("div","pf-calendar"),r=document.createElement("input");if(r.type="date",r.name=C(e.name,t),e.value!==void 0)r.value=C(e.value,t);let o=r.name,i=t.store.get(o);if(i!=null)r.value=P(i);if(e.minDate!=null)r.min=C(e.minDate,t);if(e.maxDate!=null)r.max=C(e.maxDate,t);return r.style.padding="6px 12px",r.style.borderRadius="6px",r.addEventListener("change",()=>{if(t.store.set(r.name,r.value),e.onChange!=null)F(j(e.onChange,V(t)),"onChange")}),n.appendChild(r),n}function mo(e,t){let n=m("div","pf-datepicker"),r=document.createElement("input");if(r.type="date",r.name=C(e.name,t),e.placeholder!=null)r.placeholder=C(e.placeholder,t);if(e.value!==void 0)r.value=C(e.value,t);let o=r.name,i=t.store.get(o);if(i!=null)r.value=P(i);if(e.minDate!=null)r.min=C(e.minDate,t);if(e.maxDate!=null)r.max=C(e.maxDate,t);return r.style.padding="6px 12px",r.style.borderRadius="6px",r.style.width="100%",r.style.boxSizing="border-box",r.addEventListener("change",()=>{if(t.store.set(r.name,r.value),e.onChange!=null)F(j(e.onChange,V(t)),"onChange")}),n.appendChild(r),n}function go(e,t){let n=m("div","pf-choice-card");if(n.style.padding="16px",n.style.cursor="pointer",n.style.transition="border-color 0.2s",n.dataset.value=C(e.value,t),e.selected===!0)n.dataset.selected="true";if(e.label!=null){let r=m("div","pf-choice-card-label");r.textContent=C(e.label,t),r.style.fontWeight="600",n.appendChild(r)}if(e.description!=null){let r=m("div","pf-choice-card-description");r.textContent=C(e.description,t),r.style.fontSize="14px",n.appendChild(r)}return H(e,n,t),n}function an(){p("Tabs",ho),p("Tab",bo),p("Accordion",yo),p("AccordionItem",Co),p("Dialog",vo),p("Popover",wo),p("Tooltip",xo),p("HoverCard",ko),p("Carousel",So)}function ho(e,t){let n=m("div","pf-tabs"),r=m("div","pf-tabs-bar");r.setAttribute("role","tablist"),r.style.display="flex",r.style.gap="4px",r.style.marginBottom="12px";let o=[],i=[],s=e.children??[],a=(()=>{let c=e.defaultTab;if(typeof c==="number")return c>=0&&c<s.length?c:0;if(typeof c==="string"){let u=s.findIndex((d)=>d.title===c);return u>=0?u:0}return 0})();if(e.children)for(let c=0;c<e.children.length;c++){let u=e.children[c],d=`pf-tab-${Math.random().toString(36).slice(2,8)}`,g=`pf-panel-${Math.random().toString(36).slice(2,8)}`,h=document.createElement("button");h.type="button",h.className="pf-tab-trigger",h.textContent=u.title??`Tab ${c+1}`,h.setAttribute("role","tab"),h.setAttribute("aria-selected",c===a?"true":"false"),h.setAttribute("aria-controls",g),h.id=d,h.tabIndex=c===a?0:-1,h.style.padding="8px 16px",h.style.border="none",h.style.background="none",h.style.cursor="pointer",h.style.borderBottom="2px solid transparent",h.style.marginBottom="-2px",h.style.fontSize="14px";let y=m("div","pf-tab-panel");if(y.style.display=c===a?"block":"none",y.setAttribute("role","tabpanel"),y.setAttribute("aria-labelledby",d),y.id=g,y.tabIndex=0,H(u,y,t),h.addEventListener("click",()=>{l(c)}),c===a)h.classList.add("pf-tab-active"),h.style.fontWeight="600";i.push(h),o.push(y),r.appendChild(h)}function l(c){o.forEach((u)=>u.style.display="none"),i.forEach((u)=>{u.style.borderBottomColor="transparent",u.style.fontWeight="normal",u.classList.remove("pf-tab-active"),u.setAttribute("aria-selected","false"),u.tabIndex=-1}),o[c].style.display="block",i[c].classList.add("pf-tab-active"),i[c].style.fontWeight="600",i[c].setAttribute("aria-selected","true"),i[c].tabIndex=0,i[c].focus()}r.addEventListener("keydown",(c)=>{let u=i.indexOf(c.target);if(u<0)return;let d;if(c.key==="ArrowRight")d=(u+1)%i.length;else if(c.key==="ArrowLeft")d=(u-1+i.length)%i.length;else if(c.key==="Home")d=0;else if(c.key==="End")d=i.length-1;else return;c.preventDefault(),l(d)}),n.appendChild(r);for(let c of o)n.appendChild(c);return n}function bo(e,t){let n=m("div","pf-tab");return H(e,n,t),n}function yo(e,t){let n=m("div","pf-accordion");return H(e,n,t),n}function Co(e,t){let n=m("div","pf-accordion-item"),r=`pf-acc-${Math.random().toString(36).slice(2,8)}`,o=document.createElement("button");o.type="button",o.className="pf-accordion-trigger",o.textContent=e.title??"",o.setAttribute("aria-expanded","false"),o.setAttribute("aria-controls",r),o.style.width="100%",o.style.textAlign="left",o.style.padding="12px 0",o.style.border="none",o.style.background="none",o.style.cursor="pointer",o.style.fontSize="14px",o.style.fontWeight="500";let i=m("div","pf-accordion-content");return i.id=r,i.setAttribute("role","region"),i.setAttribute("aria-labelledby",o.id),i.style.display="none",i.style.paddingBottom="12px",H(e,i,t),o.addEventListener("click",()=>{let s=i.style.display!=="none";i.style.display=s?"none":"block",o.setAttribute("aria-expanded",s?"false":"true")}),n.appendChild(o),n.appendChild(i),n}function vo(e,t){let n=m("div","pf-dialog-wrapper");if(e.trigger!=null){let i=J(e.trigger,t);i.addEventListener("click",()=>{r.showModal()}),n.appendChild(i)}let r=document.createElement("dialog");if(r.className="pf-dialog",r.setAttribute("aria-modal","true"),r.style.maxWidth="500px",r.style.width="100%",r.style.padding="24px",e.title!=null){let i=m("h2","pf-dialog-title");i.textContent=C(e.title,t),i.id=`pf-dialog-title-${Math.random().toString(36).slice(2,8)}`,r.setAttribute("aria-labelledby",i.id),r.appendChild(i)}if(e.description!=null){let i=m("p","pf-dialog-desc");i.textContent=C(e.description,t),r.appendChild(i)}let o=m("div","pf-dialog-body");if(H(e,o,t),r.appendChild(o),e.dismissible!==!1)r.addEventListener("click",(i)=>{if(i.target===r)r.close()});return document.addEventListener("prefab:close-overlay",()=>r.close()),n.appendChild(r),n}function wo(e,t){let n=m("div","pf-popover");n.style.position="relative",n.style.display="inline-block";let r=m("div","pf-popover-content");if(r.style.display="none",r.style.position="absolute",r.style.zIndex="50",r.style.padding="12px",r.style.boxShadow="0 4px 6px -1px rgb(0 0 0 / 0.1)",e.title!=null){let i=m("div","pf-popover-title");i.textContent=C(e.title,t),i.style.fontWeight="600",i.style.marginBottom="4px",r.appendChild(i)}H(e,r,t);let o=()=>{r.style.display=r.style.display==="none"?"block":"none"};if(e.trigger!=null){let i=J(e.trigger,t);i.addEventListener("click",(s)=>{s.stopPropagation(),o()}),n.appendChild(i)}else n.addEventListener("click",(i)=>{if(r.contains(i.target)&&r.style.display!=="none")return;o()});return n.appendChild(r),n}function xo(e,t){let n=m("div","pf-tooltip");n.style.position="relative",n.style.display="inline-block";let r=`pf-tip-${Math.random().toString(36).slice(2,8)}`,o=m("div","pf-tooltip-content");return o.id=r,o.setAttribute("role","tooltip"),o.textContent=C(e.content??"",t),o.style.display="none",o.style.position="absolute",o.style.bottom="100%",o.style.left="50%",o.style.transform="translateX(-50%)",o.style.padding="4px 8px",o.style.borderRadius="4px",o.style.color="#fff",o.style.fontSize="12px",o.style.whiteSpace="nowrap",o.style.zIndex="50",H(e,n,t),n.setAttribute("aria-describedby",r),n.addEventListener("mouseenter",()=>{o.style.display="block"}),n.addEventListener("mouseleave",()=>{o.style.display="none"}),n.addEventListener("focus",()=>{o.style.display="block"},!0),n.addEventListener("blur",()=>{o.style.display="none"},!0),n.appendChild(o),n}function ko(e,t){let n=m("div","pf-hover-card");n.style.position="relative",n.style.display="inline-block";let r=m("div","pf-hover-card-content");if(r.style.display="none",r.style.position="absolute",r.style.zIndex="50",r.style.padding="16px",r.style.boxShadow="0 4px 6px -1px rgb(0 0 0 / 0.1)",r.style.minWidth="200px",e.trigger!=null)n.appendChild(J(e.trigger,t));return H(e,r,t),n.addEventListener("mouseenter",()=>{r.style.display="block"}),n.addEventListener("mouseleave",()=>{r.style.display="none"}),n.appendChild(r),n}function So(e,t){let n=m("div","pf-carousel");n.style.position="relative",n.style.overflow="hidden",n.setAttribute("role","region"),n.setAttribute("aria-roledescription","carousel"),n.setAttribute("aria-label",C(e.label??"Carousel",t));let r=m("div","pf-carousel-track");r.style.display="flex",r.style.transition="transform 0.3s ease",H(e,r,t);let o=0,i=e.children?.length??0,s=document.createElement("button");s.type="button",s.textContent="‹",s.className="pf-carousel-prev",s.setAttribute("aria-label","Previous slide"),s.style.position="absolute",s.style.left="4px",s.style.top="50%",s.style.transform="translateY(-50%)",s.style.zIndex="10";let a=document.createElement("button");a.type="button",a.textContent="›",a.className="pf-carousel-next",a.setAttribute("aria-label","Next slide"),a.style.position="absolute",a.style.right="4px",a.style.top="50%",a.style.transform="translateY(-50%)",a.style.zIndex="10";let l=()=>{r.style.transform=`translateX(-${o*100}%)`};return s.addEventListener("click",()=>{if(i===0)return;o=Math.max(0,o-1),l()}),a.addEventListener("click",()=>{if(i===0)return;o=Math.min(i-1,o+1),l()}),n.appendChild(r),n.appendChild(s),n.appendChild(a),n}function ln(){p("ForEach",Eo),p("If",dn),p("Elif",Ao),p("Else",Ro),p("Condition",To),p("Define",No),p("Use",Mo),p("Slot",Lo)}function Eo(e,t){let n=document.createDocumentFragment(),r=e.expression;if(!r)return n;let o;if(Q(r)){let s=ee(r,t.store,t.scope);o=Array.isArray(s)?s:[]}else{let s=t.store.get(r);o=Array.isArray(s)?s:[]}let i=e.let??{};for(let s=0;s<o.length;s++){let a=o[s],l={...t.scope,$item:a,$index:s,...i},c={...t,scope:l};if(e.children)se(e.children,n,c)}return n}function dn(e,t){if(cn(e.condition,t)){let r=document.createDocumentFragment();if(e.children)se(e.children,r,t);return r}return document.createDocumentFragment()}function Ao(e,t){return dn(e,t)}function Ro(e,t){let n=document.createDocumentFragment();if(e.children)se(e.children,n,t);return n}function cn(e,t){if(!e)return!1;if(Q(e))return Boolean(ee(e,t.store,t.scope));return Boolean(t.store.get(e))}function To(e,t){let n=document.createDocumentFragment(),r=e.cases,o=e.else;if(r){for(let i of r)if(cn(i.when,t)){if(i.children)se(i.children,n,t);return n}}if(o)se(o,n,t);return n}function No(e,t){let n=e.name;if(n&&e.children)t.templates=t.templates??{},t.templates[n]=e.children;return document.createDocumentFragment()}function Mo(e,t){let n=document.createDocumentFragment(),r=e.def??e.name,o=t.templates?.[r];if(!o)return n;let i=e.overrides??{},s={...t.scope,...i},a={...t.slots??{},...e.slots??{}};if(Array.isArray(e.children))a.default=e.children;let l={...t,scope:s,slots:a};for(let c of o)n.appendChild(J(c,l));return n}function Lo(e,t){let n=document.createDocumentFragment(),r=e.name??"default",i=t.slots?.[r]??e.children;if(i)for(let s of i)n.appendChild(J(s,t));return n}function pn(){p("Alert",Ho),p("AlertTitle",Po),p("AlertDescription",$o)}function Ho(e,t){let n=m("div","pf-alert");n.setAttribute("role","alert");let r=e.variant??"default";if(n.setAttribute("data-variant",r),n.style.padding="12px 16px",e.icon!=null){let o=m("span","pf-alert-icon");o.setAttribute("data-icon",e.icon),o.style.marginRight="8px",n.appendChild(o)}return H(e,n,t),n}function Po(e,t){let n=m("h5","pf-alert-title");return n.textContent=C(e.content,t),n.style.fontWeight="600",n.style.marginBottom="4px",n}function $o(e,t){let n=m("p","pf-alert-description");return n.textContent=C(e.content,t),n.style.fontSize="14px",n}function un(){p("Image",Oo),p("Audio",Do),p("Video",jo),p("Embed",Io),p("Svg",Bo),p("DropZone",zo),p("Mermaid",Wo)}function Oo(e,t){let n=document.createElement("img");if(n.className="pf-image",n.src=C(e.src,t),e.alt!=null)n.alt=C(e.alt,t);if(e.width!=null)n.width=e.width;if(e.height!=null)n.height=e.height;return n.style.maxWidth="100%",n}function Do(e,t){let n=document.createElement("audio");return n.className="pf-audio",n.src=C(e.src,t),n.controls=!0,n}function jo(e,t){let n=document.createElement("video");if(n.className="pf-video",n.src=C(e.src,t),n.controls=!0,e.width!=null)n.width=e.width;if(e.height!=null)n.height=e.height;return n.style.maxWidth="100%",n}function Io(e,t){let n=m("div","pf-embed"),r=document.createElement("iframe");return r.src=C(e.src,t),r.style.width="100%",r.style.height=e.height!=null?`${e.height}px`:"400px",r.style.border="none",r.setAttribute("sandbox","allow-scripts"),n.appendChild(r),n}var Fo=new Set(["svg","g","path","rect","circle","ellipse","line","polyline","polygon","text","tspan","textpath","defs","use","symbol","clippath","mask","pattern","lineargradient","radialgradient","stop","filter","fegaussianblur","feoffset","femerge","femergenode","fecolormatrix","feblend","title","desc"]);function Bo(e,t){let n=m("div","pf-svg"),r=C(e.content,t);if(!r.includes("<svg"))return n;if(!/<svg[^>]*\sxmlns\s*=/.test(r))r=r.replace(/<svg\b/,'<svg xmlns="http://www.w3.org/2000/svg"');let i=new DOMParser().parseFromString(r,"image/svg+xml").querySelector("svg");if(!i)return n;return fn(i),n.appendChild(document.importNode(i,!0)),n}function fn(e){let t=Array.from(e.children);for(let n of t){if(!Fo.has(n.tagName.toLowerCase())){n.remove();continue}for(let r of Array.from(n.attributes)){let o=r.name.toLowerCase();if(o.startsWith("on")||o==="href"&&r.value.trim().toLowerCase().startsWith("javascript:"))n.removeAttribute(r.name)}fn(n)}}function Jo(e,t){let n=(t??"").split(",").map((i)=>i.trim().toLowerCase()).filter(Boolean);if(n.length===0)return!0;let r=e.name.toLowerCase(),o=e.type.toLowerCase();return n.some((i)=>{if(i.startsWith("."))return r.endsWith(i);if(i.endsWith("/*"))return o.startsWith(i.slice(0,-1));return o===i})}function zo(e,t){let n=m("div","pf-dropzone");n.style.padding="32px",n.style.textAlign="center",n.style.cursor="pointer",n.textContent=C(e.label??"Drop files here",t);let r=document.createElement("input");if(r.type="file",r.style.display="none",e.accept!=null)r.accept=e.accept;if(e.multiple===!0)r.multiple=!0;n.appendChild(r),n.setAttribute("role","button"),n.tabIndex=0;function o(s){let a=Array.from(s??[]).filter((l)=>Jo(l,e.accept));return e.multiple===!0?a:a.slice(0,1)}function i(s){if(s.length===0)return;if(e.resultKey!=null)t.store.set(e.resultKey,s),t.rerender();if(e.onDrop!=null)F(j(e.onDrop,{...V(t),scope:{...t.scope,$result:s}}),"onDrop")}return r.addEventListener("change",()=>{i(o(r.files)),r.value=""}),n.addEventListener("click",()=>r.click()),n.addEventListener("keydown",(s)=>{if(s.key==="Enter"||s.key===" ")s.preventDefault(),r.click()}),n.addEventListener("dragover",(s)=>{s.preventDefault(),n.classList.add("pf-dropzone-active")}),n.addEventListener("dragleave",()=>{n.classList.remove("pf-dropzone-active")}),n.addEventListener("drop",(s)=>{s.preventDefault(),n.classList.remove("pf-dropzone-active"),i(o(s.dataTransfer?.files??null))}),n}function Wo(e,t){let n=m("div","pf-mermaid");n.setAttribute("data-mermaid","true");let r=C(e.content,t);if(n.textContent=r,typeof globalThis.mermaid<"u")n.classList.add("mermaid"),n.textContent=r;return n}var _o="https://cdn.jsdelivr.net/npm/pdfjs-dist@4.9/build/pdf.min.mjs",Vo="https://cdn.jsdelivr.net/npm/pdfjs-dist@4.9/build/pdf.worker.min.mjs",dt=null,je=null;async function Ko(){if(dt)return dt;if(je)return je;return je=import(_o).then((e)=>{let t=e;return t.GlobalWorkerOptions.workerSrc=Vo,dt=t,t}),je}function gn(){p("PdfViewer",Go)}function Go(e,t){let n=m("div","pf-pdf-viewer"),r=e.src!=null?C(e.src,t):void 0,o=e.data,i=e.page!=null?e.page:1,s=e.zoom!=null?e.zoom:"fit-width",a=e.toolbar!==!1,l=e.height!=null?e.height:600;n.style.height=`${l}px`,n.style.display="flex",n.style.flexDirection="column",n.style.overflow="hidden",n.style.border="1px solid var(--color-border-primary, #e5e7eb)",n.style.borderRadius="var(--border-radius-md, 0.375rem)",n.style.background="var(--color-background-secondary, #f9fafb)";let c=m("div","pf-pdf-loading");return c.textContent="Loading PDF…",c.style.display="flex",c.style.alignItems="center",c.style.justifyContent="center",c.style.flex="1",c.style.color="var(--color-text-secondary, #6b7280)",n.appendChild(c),qo(n,c,{src:r,data:o,initialPage:i,zoom:s,showToolbar:a}),n}async function qo(e,t,n){try{let r=await Ko(),o;if(n.src)o={url:n.src};else if(n.data){let g=atob(n.data),h=new Uint8Array(g.length);for(let y=0;y<g.length;y++)h[y]=g.charCodeAt(y);o={data:h}}else{t.textContent="Error: No PDF source provided";return}let i=await r.getDocument(o).promise;t.remove();let s=Math.max(1,Math.min(n.initialPage,i.numPages)),a=null,l=null;if(n.showToolbar){let g=Uo(i.numPages,s,{onPrev:()=>{if(s>1)s--,d()},onNext:()=>{if(s<i.numPages)s++,d()},onPageChange:(h)=>{let y=Math.max(1,Math.min(h,i.numPages));if(y!==s)s=y,d()}});a=g.pageInput,l=g.pageCount,e.insertBefore(g.el,e.firstChild)}let c=m("div","pf-pdf-canvas-container");c.style.flex="1",c.style.overflow="auto",c.style.display="flex",c.style.justifyContent="center",c.style.padding="8px",e.appendChild(c);let u=document.createElement("canvas");u.style.display="block",u.style.boxShadow="var(--shadow-md, 0 4px 6px -1px rgba(0,0,0,.1))",c.appendChild(u);async function d(){let g=await i.getPage(s),h=c.clientWidth-16,y,f=g.getViewport({scale:1});if(n.zoom==="fit-width")y=h/f.width;else if(n.zoom==="fit-page"){let S=c.clientHeight-16,N=h/f.width,k=S/f.height;y=Math.min(N,k)}else y=typeof n.zoom==="number"?n.zoom:1;let b=g.getViewport({scale:y});u.width=b.width,u.height=b.height,u.style.width=`${b.width}px`,u.style.height=`${b.height}px`;let w=u.getContext("2d");if(!w)return;if(await g.render({canvasContext:w,viewport:b}).promise,a)a.value=String(s);if(l)l.textContent=`/ ${i.numPages}`}await d()}catch(r){t.textContent=`PDF Error: ${r instanceof Error?r.message:String(r)}`,t.style.color="var(--color-text-danger, #dc2626)"}}function Uo(e,t,n){let r=m("div","pf-pdf-toolbar");r.style.display="flex",r.style.alignItems="center",r.style.gap="8px",r.style.padding="6px 12px",r.style.borderBottom="1px solid var(--color-border-primary, #e5e7eb)",r.style.background="var(--color-background-primary, #fff)",r.style.flexShrink="0",r.style.fontSize="13px";let o=document.createElement("button");o.textContent="‹",o.title="Previous page",o.className="pf-pdf-btn",mn(o),o.addEventListener("click",n.onPrev);let i=document.createElement("button");i.textContent="›",i.title="Next page",i.className="pf-pdf-btn",mn(i),i.addEventListener("click",n.onNext);let s=document.createElement("input");s.type="number",s.min="1",s.max=String(e),s.value=String(t),s.style.width="48px",s.style.textAlign="center",s.style.border="1px solid var(--color-border-primary, #e5e7eb)",s.style.borderRadius="4px",s.style.padding="2px 4px",s.style.fontSize="13px",s.addEventListener("change",()=>{let l=parseInt(s.value,10);if(!isNaN(l))n.onPageChange(l)});let a=document.createElement("span");return a.textContent=`/ ${e}`,a.style.color="var(--color-text-secondary, #6b7280)",r.appendChild(o),r.appendChild(s),r.appendChild(a),r.appendChild(i),{el:r,pageInput:s,pageCount:a}}function mn(e){e.style.border="1px solid var(--color-border-primary, #e5e7eb)",e.style.borderRadius="4px",e.style.background="var(--color-background-primary, #fff)",e.style.cursor="pointer",e.style.padding="2px 8px",e.style.fontSize="16px",e.style.lineHeight="1"}var Fe=["#3b82f6","#10b981","#f59e0b","#ef4444","#8b5cf6","#ec4899"];function ce(e,t){let n=document.createElement("div");return n.className="pf-chart-tooltip",e.appendChild(n),e.addEventListener("mouseleave",()=>{n.classList.remove("pf-visible")}),{wrapper:e,tooltip:n,svgEl:t}}function te(e,t,n,r,o){let{tooltip:i,svgEl:s,wrapper:a}=e;if(o.length===0)return;let l="";if(r)l+=`<div class="pf-chart-tooltip-label">${Ie(r)}</div>`;for(let b of o)l+='<div class="pf-chart-tooltip-row">',l+=`<span class="pf-chart-tooltip-dot" style="background:${Ie(b.color)}"></span>`,l+=`<span>${Ie(b.label)}:</span> <strong>${Ie(String(b.value))}</strong>`,l+="</div>";i.innerHTML=l;let c=s.getBoundingClientRect(),u=a.getBoundingClientRect(),d=s.viewBox.baseVal,g=c.width/(d.width||1),h=c.left-u.left+t*g,y=i.offsetWidth||100,f=h+12;if(f+y>u.width)f=h-y-12;i.style.left=`${Math.max(0,f)}px`,i.style.top="4px",i.classList.add("pf-visible")}function Ie(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function hn(e,t,n,r,o,i,s,a){let l=o.plotWidth/n.length;for(let c=0;c<n.length;c++){let u=o.plotLeft+c*l,d=document.createElementNS("http://www.w3.org/2000/svg","rect");d.setAttribute("x",String(u)),d.setAttribute("y",String(o.plotTop)),d.setAttribute("width",String(l)),d.setAttribute("height",String(o.plotHeight)),d.setAttribute("fill","transparent"),d.style.cursor="default";let g=i?n[c][i]:void 0,h=g!=null?a?a(g):P(g):void 0,y=r.map((S,N)=>({label:S.label??S.dataKey,value:s(n[c][S.dataKey],S,N),color:S.color??Fe[N%Fe.length]})),f=u+l/2,b=()=>te(e,f,o.plotTop,h,y),w=()=>e.tooltip.classList.remove("pf-visible");d.addEventListener("mouseenter",b),d.addEventListener("mouseleave",w),d.addEventListener("touchstart",b,{passive:!0}),d.addEventListener("touchend",w,{passive:!0}),t.appendChild(d)}}function bn(e,t,n,r,o,i,s,a,l,c){let u=n.length===1?o.plotWidth:o.plotWidth/(n.length-1);for(let d=0;d<n.length;d++){let g=n.length===1?(o.plotLeft+o.plotRight)/2:o.plotLeft+d/(n.length-1)*o.plotWidth,h=n.length===1?o.plotLeft:g-u/2,y=n.length===1?o.plotWidth:u,f=document.createElementNS("http://www.w3.org/2000/svg","rect");f.setAttribute("x",String(Math.max(o.plotLeft,h))),f.setAttribute("y",String(o.plotTop)),f.setAttribute("width",String(Math.min(y,o.plotRight-Math.max(o.plotLeft,h)))),f.setAttribute("height",String(o.plotHeight)),f.setAttribute("fill","transparent"),f.style.cursor="default";let b=i?n[d][i]:void 0,w=b!=null?c?c(b):P(b):void 0,S=r.map((R,L)=>({label:R.label??R.dataKey,value:s(n[d][R.dataKey],R,L),color:R.color??Fe[L%Fe.length]})),N=()=>{if(te(e,g,o.plotTop,w,S),a)a.setAttribute("x1",String(g)),a.setAttribute("x2",String(g)),a.setAttribute("opacity","1");if(l)for(let R of l){for(let L of R)L.setAttribute("data-visible","false");R[d]?.setAttribute("data-visible","true")}},k=()=>{if(e.tooltip.classList.remove("pf-visible"),a)a.setAttribute("opacity","0");if(l)for(let R of l)for(let L of R)L.setAttribute("data-visible","false")};f.addEventListener("mouseenter",N),f.addEventListener("mouseleave",k),f.addEventListener("touchstart",N,{passive:!0}),f.addEventListener("touchend",k,{passive:!0}),t.appendChild(f)}}var q=["#3b82f6","#10b981","#f59e0b","#ef4444","#8b5cf6","#ec4899"],re="var(--muted-foreground, #6b7280)",he="var(--border, #e5e7eb)",pe="10";function Be(e,t,n,r=!1){let o=n?44:0,i=e-(r?44:0),s=10,a=t-24;return{plotLeft:o,plotRight:i,plotTop:10,plotBottom:a,plotWidth:i-o,plotHeight:a-10}}function yn(e,t=5){if(e<=0)return[0];let n=e/t,r=Math.pow(10,Math.floor(Math.log10(n))),o=n/r,i=o<=1.5?r:o<=3?2*r:o<=7?5*r:10*r,s=[];for(let a=0;a<=e+i*0.01;a+=i)s.push(Math.round(a*1000)/1000);return s}function ct(e,t,n,r,o){let i=yn(n);for(let s of i){let a=t.plotBottom-(n>0?s/n*t.plotHeight:0),l=U("text",{x:t.plotLeft-6,y:a+3,"text-anchor":"end","font-size":pe,fill:re});if(l.textContent=ft(s,o),e.appendChild(l),r&&s>0)e.appendChild(U("line",{x1:t.plotLeft,y1:a,x2:t.plotRight,y2:a,stroke:he,"stroke-width":1,"stroke-dasharray":"4 3"}))}}function pt(e,t,n,r){let o=yn(n);for(let i of o){let s=t.plotBottom-(n>0?i/n*t.plotHeight:0),a=U("text",{x:t.plotRight+6,y:s+3,"text-anchor":"start","font-size":pe,fill:re});a.textContent=ft(i,r),e.appendChild(a)}}function ut(e,t,n,r,o,i){for(let s=0;s<t.length;s++){let a=t[s][n],l=U("text",{x:r(s),y:o+14,"text-anchor":"middle","font-size":pe,fill:re});l.textContent=a==null?"":i?i(a):P(a),e.appendChild(l)}}function Je(e,t){e.appendChild(U("line",{x1:t.plotLeft,y1:t.plotBottom,x2:t.plotRight,y2:t.plotBottom,stroke:re,"stroke-width":1}))}function ne(e,t,n){if(e==null)return"";let r=K(`{{ __v | ${t} }}`,{...n,scope:{...n.scope,__v:e}});return P(r??e)}function ft(e,t){if(t==="currency")return`$${e.toLocaleString()}`;if(t==="percent")return`${e}%`;if(e>=1e6)return`${(e/1e6).toFixed(1)}M`;if(e>=1000)return`${(e/1000).toFixed(1)}K`;return String(e)}function oe(e){let t=e.yAxisFormat??e.valueFormat;return t&&t!=="auto"?t:void 0}function mt(e,t,n){return(r,o)=>{if(r===null||r===void 0)return"—";if(o.tooltipFormat)return ne(r,o.tooltipFormat,e);let i=o.yAxisId==="right"?n:t;return ft(Number(r),i)}}function ae(e,t,n){let r=document.createElementNS("http://www.w3.org/2000/svg","svg");if(r.setAttribute("width","100%"),r.setAttribute("height",String(t)),r.setAttribute("viewBox",`0 0 ${e} ${t}`),r.setAttribute("role","img"),n)r.setAttribute("aria-label",`${n} chart`);return r.style.overflow="visible",r}function U(e,t){let n=document.createElementNS("http://www.w3.org/2000/svg",e);for(let[r,o]of Object.entries(t))n.setAttribute(r,String(o));return n}function ze(e,t){let n=U("text",e);return n.textContent=t,n}function ue(e,t,n,r){let o=r*Math.PI/180;return{x:e+n*Math.cos(o),y:t-n*Math.sin(o)}}function gt(e,t,n,r,o){let i=Math.max(2,Math.ceil(Math.abs(o-r)/4)),s=[];for(let a=0;a<=i;a++){let l=ue(e,t,n,r+(o-r)*a/i);s.push(`${a===0?"M":"L"} ${l.x.toFixed(2)} ${l.y.toFixed(2)}`)}return s.join(" ")}function fe(e,t,n){if(n===!1||t.length<=1)return;let r=m("div","pf-chart-legend");r.style.display="flex",r.style.gap="12px",r.style.fontSize="12px",r.style.marginBottom="8px";for(let o=0;o<t.length;o++){let i=m("div","pf-chart-legend-item");i.style.display="flex",i.style.alignItems="center",i.style.gap="4px";let s=m("span");s.style.width="8px",s.style.height="8px",s.style.borderRadius="50%",s.style.backgroundColor=t[o].color??q[o%q.length];let a=m("span");a.textContent=t[o].label??t[o].dataKey,i.appendChild(s),i.appendChild(a),r.appendChild(i)}e.appendChild(r)}function vn(){p("BarChart",Xo),p("LineChart",Cn),p("AreaChart",Cn),p("PieChart",Yo),p("RadarChart",ei),p("ScatterChart",Zo),p("RadialChart",Qo),p("Histogram",ti)}function Xo(e,t){let n=m("div","pf-chart pf-bar-chart"),r=K(e.data,t)??[],o=e.series??[],i=e.height??300;if(r.length===0||o.length===0)return n.textContent="No chart data",n;let s=e.showYAxis!==!1,a=e.showGrid===!0,l=e.showYAxisRight===!0,c=e.showTooltip!==!1,u=e.xAxis,d=e.tooltipXKey,g=e.xAxisFormat,h=e.tooltipXFormat,y=o.filter((x)=>x.yAxisId!=="right"),f=o.filter((x)=>x.yAxisId==="right"),b=l&&f.length>0,w=y.length>0?Math.max(...r.flatMap((x)=>y.map((v)=>Number(x[v.dataKey]??0))),1):1,S=b?Math.max(...r.flatMap((x)=>f.map((v)=>Number(x[v.dataKey]??0))),1):1,N=400,k=Be(N,i,s,b),R=ae(N,i,"Bar");if(s)ct(R,k,w,a,oe(e));if(b)pt(R,k,S,e.yAxisRightFormat);Je(R,k);let L=k.plotWidth/r.length,M=L/(o.length+1);for(let x=0;x<r.length;x++)for(let v=0;v<o.length;v++){let T=o[v],D=r[x][T.dataKey];if(D===null||D===void 0)continue;let G=T.yAxisId==="right"?S:w,B=Number(D),E=Math.max(0,B/G*k.plotHeight),W=k.plotLeft+x*L+v*M+M/2,A=document.createElementNS("http://www.w3.org/2000/svg","rect");A.setAttribute("x",String(W)),A.setAttribute("y",String(k.plotBottom-E)),A.setAttribute("width",String(M*0.8)),A.setAttribute("height",String(E)),A.setAttribute("fill",T.color??q[v%q.length]),A.setAttribute("rx","2"),R.appendChild(A)}if(u){let x=g?(v)=>ne(v,g,t):void 0;ut(R,r,u,(v)=>k.plotLeft+v*L+L/2,k.plotBottom,x)}if(c){let x=ce(n,R),v=mt(t,oe(e),e.yAxisRightFormat);hn(x,R,r,o,k,d??u,v,h?(D)=>ne(D,h,t):void 0)}return fe(n,o,e.showLegend),n.appendChild(R),n}function Cn(e,t){let n=m("div",`pf-chart pf-${e.type.toLowerCase()}-chart`),r=K(e.data,t)??[],o=e.series??[],i=e.height??300;if(r.length===0||o.length===0)return n.textContent="No chart data",n;let s=e.showYAxis!==!1,a=e.showGrid===!0,l=e.showYAxisRight===!0,c=e.showTooltip!==!1,u=e.xAxis,d=e.tooltipXKey,g=e.xAxisFormat,h=e.tooltipXFormat,y=o.filter((v)=>v.yAxisId!=="right"),f=o.filter((v)=>v.yAxisId==="right"),b=l&&f.length>0,w=y.length>0?Math.max(...r.flatMap((v)=>y.map((T)=>Number(v[T.dataKey]??0))),1):1,S=b?Math.max(...r.flatMap((v)=>f.map((T)=>Number(v[T.dataKey]??0))),1):1,N=400,k=Be(N,i,s,b),R=ae(N,i,e.type==="AreaChart"?"Area":"Line"),L=e.type==="AreaChart";if(s)ct(R,k,w,a,oe(e));if(b)pt(R,k,S,e.yAxisRightFormat);Je(R,k);let M=[];for(let v=0;v<o.length;v++){let T=o[v],D=T.yAxisId==="right",z=D?S:w,G=T.color??q[v%q.length],B=r.map((A,I)=>{let _=A[T.dataKey],X=_===null||_===void 0,le=r.length===1?(k.plotLeft+k.plotRight)/2:k.plotLeft+I/(r.length-1)*k.plotWidth,Bn=X?k.plotBottom:k.plotBottom-Number(_)/z*k.plotHeight;return{x:le,y:Bn,isNull:X}});if(L){let A=[],I=()=>{if(A.length<2){A=[];return}let _=`M ${A[0].x},${k.plotBottom} `+A.map((le)=>`L ${le.x},${le.y}`).join(" ")+` L ${A[A.length-1].x},${k.plotBottom} Z`,X=document.createElementNS("http://www.w3.org/2000/svg","path");X.setAttribute("d",_),X.setAttribute("fill",G),X.setAttribute("opacity","0.15"),R.appendChild(X),A=[]};for(let _ of B){if(_.isNull){I();continue}A.push(_)}I()}let E="";for(let A of B){if(A.isNull)continue;let I=B.indexOf(A),_=I===0||B[I-1].isNull;E+=`${_?"M":"L"} ${A.x},${A.y} `}if(E){let A=document.createElementNS("http://www.w3.org/2000/svg","path");if(A.setAttribute("d",E.trim()),A.setAttribute("fill","none"),A.setAttribute("stroke",G),A.setAttribute("stroke-width","2"),D)A.setAttribute("stroke-dasharray","6 3");R.appendChild(A)}let W=[];for(let A of B){let I=document.createElementNS("http://www.w3.org/2000/svg","circle");if(I.setAttribute("cx",String(A.x)),I.setAttribute("cy",String(A.y)),I.setAttribute("r","4"),I.setAttribute("fill",G),I.setAttribute("class","pf-data-dot"),I.setAttribute("data-visible","false"),I.style.pointerEvents="none",A.isNull)I.style.display="none";R.appendChild(I),W.push(I)}M.push(W)}let x=document.createElementNS("http://www.w3.org/2000/svg","line");if(x.setAttribute("class","pf-crosshair"),x.setAttribute("x1",String(k.plotLeft)),x.setAttribute("x2",String(k.plotLeft)),x.setAttribute("y1",String(k.plotTop)),x.setAttribute("y2",String(k.plotBottom)),x.setAttribute("stroke",re),x.setAttribute("stroke-width","1"),x.setAttribute("stroke-dasharray","3 3"),x.setAttribute("opacity","0"),R.appendChild(x),u){let v=g?(T)=>ne(T,g,t):void 0;ut(R,r,u,(T)=>r.length===1?(k.plotLeft+k.plotRight)/2:k.plotLeft+T/(r.length-1)*k.plotWidth,k.plotBottom,v)}if(c){let v=ce(n,R),T=mt(t,oe(e),e.yAxisRightFormat);bn(v,R,r,o,k,d??u,T,x,M,h?(z)=>ne(z,h,t):void 0)}return fe(n,o,e.showLegend),n.appendChild(R),n}function Yo(e,t){let n=m("div","pf-chart pf-pie-chart"),r=K(e.data,t)??[],o=e.series??[],i=e.height??300,s=Math.min(i,300),a=e.showTooltip!==!1,l=e.dataKey??o[0]?.dataKey,c=e.nameKey??e.tooltipXKey??e.xAxis,u=o.length>0?o:l?[{dataKey:l,label:l}]:[];if(r.length===0||!l)return n.textContent="No chart data",n;let d=ae(s,s,"Pie"),g=s/2,h=s/2,y=s/2-10,f=e.tooltipXFormat,b=oe(e),w=(L)=>b?ne(L,b,t):String(L),S=r.map((L)=>Number(L[l]??0)),N=S.reduce((L,M)=>L+M,0);if(N===0)return n.textContent="No chart data",n.appendChild(d),n;let k=a?ce(n,d):void 0,R=-Math.PI/2;for(let L=0;L<S.length;L++){let M=S[L]/N*2*Math.PI,x=R+M,v=M>Math.PI?1:0,T=g+y*Math.cos(R),D=h+y*Math.sin(R),z=g+y*Math.cos(x),G=h+y*Math.sin(x),B=q[L%q.length],E=document.createElementNS("http://www.w3.org/2000/svg","path");if(E.setAttribute("d",`M ${g},${h} L ${T},${D} A ${y},${y} 0 ${v} 1 ${z},${G} Z`),E.setAttribute("fill",B),E.style.cursor="default",k){let W=c?r[L][c]:void 0,A=W!=null?f?ne(W,f,t):P(W):`Slice ${L+1}`,I=`${(S[L]/N*100).toFixed(1)}%`,_=R+M/2,X=g+y*0.6*Math.cos(_);E.addEventListener("mouseenter",()=>{te(k,X,h,A,[{label:u[0].label??l,value:`${w(S[L])} (${I})`,color:B}])}),E.addEventListener("mouseleave",()=>{k.tooltip.classList.remove("pf-visible")}),E.addEventListener("touchstart",()=>{te(k,X,h,A,[{label:u[0].label??l,value:`${w(S[L])} (${I})`,color:B}])},{passive:!0}),E.addEventListener("touchend",()=>{k.tooltip.classList.remove("pf-visible")},{passive:!0})}d.appendChild(E),R=x}return fe(n,u,e.showLegend),n.appendChild(d),n}function Zo(e,t){let n=m("div","pf-chart pf-scatter-chart"),r=K(e.data,t)??[],o=e.xAxis,i=e.yAxis,s=e.zAxis,a=e.series??[],l=e.height??300;if(r.length===0||!o||!i)return n.textContent="No chart data",n;let c=e.showGrid!==!1,u=e.showTooltip!==!1,d=a[0]?.color??q[0],g=oe(e),h=(E)=>g?ne(E,g,t):String(Math.round(E*100)/100),y=r.map((E)=>Number(E[o]??0)),f=r.map((E)=>Number(E[i]??0)),b=Math.min(...y),w=Math.max(...y),S=Math.min(...f),N=Math.max(...f),k=w-b||1,R=N-S||1,L=s?r.map((E)=>Number(E[s]??0)):[],M=s?Math.max(...L,1):1,x=400,v=Be(x,l,!0),T=ae(x,l,"Scatter"),D=(E)=>v.plotLeft+(E-b)/k*v.plotWidth,z=(E)=>v.plotBottom-(E-S)/R*v.plotHeight,G=4;for(let E=0;E<=G;E++){let W=S+R*E/G,A=z(W);if(T.appendChild(ze({x:v.plotLeft-6,y:A+3,"text-anchor":"end","font-size":pe,fill:re},h(W))),c&&E>0)T.appendChild(U("line",{x1:v.plotLeft,y1:A,x2:v.plotRight,y2:A,stroke:he,"stroke-width":1,"stroke-dasharray":"4 3"}))}Je(T,v);for(let E of[b,(b+w)/2,w])T.appendChild(ze({x:D(E),y:v.plotBottom+14,"text-anchor":"middle","font-size":pe,fill:re},String(Math.round(E*100)/100)));let B=u?ce(n,T):void 0;for(let E=0;E<r.length;E++){let W=D(y[E]),A=z(f[E]),I=s?4+Math.sqrt(L[E]/M)*14:4,_=U("circle",{cx:W,cy:A,r:I,fill:d,"fill-opacity":s?0.6:0.85});if(B){let X=[{label:o,value:h(y[E]),color:d},{label:i,value:h(f[E]),color:d},...s?[{label:s,value:h(L[E]),color:d}]:[]],le=a[0]?.label??"Point";_.addEventListener("mouseenter",()=>te(B,W,A,le,X)),_.addEventListener("mouseleave",()=>B.tooltip.classList.remove("pf-visible")),_.addEventListener("touchstart",()=>te(B,W,A,le,X),{passive:!0}),_.addEventListener("touchend",()=>B.tooltip.classList.remove("pf-visible"),{passive:!0})}T.appendChild(_)}return fe(n,a,e.showLegend),n.appendChild(T),n}function Qo(e,t){let n=m("div","pf-chart pf-radial-chart"),r=K(e.data,t)??[],o=e.series??[],i=e.dataKey??o[0]?.dataKey,s=e.nameKey??e.tooltipXKey??e.xAxis,a=e.height??300;if(r.length===0||!i)return n.textContent="No chart data",n;let l=Math.min(a,300),c=l/2,u=l/2,d=l/2-10,g=Math.max(0,Math.min(e.innerRadius??30,d-10)),h=e.startAngle??180,y=e.endAngle??0,f=e.showTooltip!==!1,b=r.map((v)=>Number(v[i]??0)),w=Math.max(...b,1),S=ae(l,l,"Radial"),N=(d-g)/r.length,k=Math.max(2,N*0.7),R=oe(e),L=(v)=>R?ne(v,R,t):String(v),M=f?ce(n,S):void 0,x=[];for(let v=0;v<r.length;v++){let T=d-N*v-N/2,D=o[v]?.color??q[v%q.length],z=b[v]/w,G=h+z*(y-h),B=s?r[v][s]:null,E=B!=null?P(B):o[v]?.label??i;x.push({dataKey:E||i,label:E||i,color:D}),S.appendChild(U("path",{d:gt(c,u,T,h,y),fill:"none",stroke:he,"stroke-width":k,"stroke-linecap":"round"}));let W=U("path",{d:gt(c,u,T,h,G),fill:"none",stroke:D,"stroke-width":k,"stroke-linecap":"round"});if(M){let A=ue(c,u,T,(h+G)/2),I=[{label:i,value:L(b[v]),color:D}],_=E||i;W.addEventListener("mouseenter",()=>te(M,A.x,A.y,_,I)),W.addEventListener("mouseleave",()=>M.tooltip.classList.remove("pf-visible")),W.addEventListener("touchstart",()=>te(M,A.x,A.y,_,I),{passive:!0}),W.addEventListener("touchend",()=>M.tooltip.classList.remove("pf-visible"),{passive:!0})}S.appendChild(W)}return fe(n,x,e.showLegend),n.appendChild(S),n}function ei(e,t){let n=m("div","pf-chart pf-radar-chart"),r=K(e.data,t)??[],o=e.series??[],i=e.axisKey??e.xAxis,s=e.height??300;if(r.length===0||o.length===0)return n.textContent="No chart data",n;let a=e.filled!==!1,l=e.showDots===!0,c=e.showGrid!==!1,u=e.showTooltip!==!1,d=Math.min(s,320),g=d/2,h=d/2,y=d/2-24,f=r.length,b=Math.max(...r.flatMap((M)=>o.map((x)=>Number(M[x.dataKey]??0))),1),w=(M)=>90-360*M/f,S=(M)=>M.map((x)=>`${x.x.toFixed(1)},${x.y.toFixed(1)}`).join(" "),N=ae(d,d,"Radar");if(c){for(let x=1;x<=4;x++){let v=y*x/4,T=Array.from({length:f},(D,z)=>ue(g,h,v,w(z)));N.appendChild(U("polygon",{points:S(T),fill:"none",stroke:he,"stroke-width":1}))}for(let x=0;x<f;x++){let v=ue(g,h,y,w(x));N.appendChild(U("line",{x1:g,y1:h,x2:v.x,y2:v.y,stroke:he,"stroke-width":1}))}}for(let M=0;M<f;M++){let x=ue(g,h,y+12,w(M)),v=i?r[M][i]:null;N.appendChild(ze({x:x.x,y:x.y+3,"text-anchor":"middle","font-size":pe,fill:re},v!=null?String(v):""))}let k=u?ce(n,N):void 0,R=oe(e),L=(M)=>R?ne(M,R,t):String(M);for(let M=0;M<o.length;M++){let x=o[M],v=x.color??q[M%q.length],T=r.map((D,z)=>ue(g,h,Number(D[x.dataKey]??0)/b*y,w(z)));if(N.appendChild(U("polygon",{points:S(T),fill:a?v:"none","fill-opacity":a?0.2:0,stroke:v,"stroke-width":2})),l||k)for(let D=0;D<T.length;D++){let z=U("circle",{cx:T[D].x,cy:T[D].y,r:l?3:6,fill:l?v:"transparent","fill-opacity":l?1:0});if(k){let G=i?r[D][i]:null,B=G!=null?P(G):x.label??x.dataKey,E=[{label:x.label??x.dataKey,value:L(Number(r[D][x.dataKey]??0)),color:v}];z.addEventListener("mouseenter",()=>te(k,T[D].x,T[D].y,B,E)),z.addEventListener("mouseleave",()=>k.tooltip.classList.remove("pf-visible")),z.addEventListener("touchstart",()=>te(k,T[D].x,T[D].y,B,E),{passive:!0}),z.addEventListener("touchend",()=>k.tooltip.classList.remove("pf-visible"),{passive:!0})}N.appendChild(z)}}return fe(n,o,e.showLegend),n.appendChild(N),n}function ti(e,t){let n=m("div","pf-chart pf-histogram"),r=K(e.data,t);if(!r||r.length===0)return n.textContent="No data",n;let o=r,i=e.bins??10,s=e.height??200,a=e.color??q[0],l=Math.min(...o),u=(Math.max(...o)-l)/i||1,d=Array(i).fill(0);for(let w of o){let S=Math.min(Math.floor((w-l)/u),i-1);d[S]++}let g=Math.max(...d),h=300,y=s,f=h/i,b=ae(h,y,"Histogram");for(let w=0;w<i;w++){let S=g>0?d[w]/g*y:0,N=document.createElementNS("http://www.w3.org/2000/svg","rect");N.setAttribute("x",String(w*f)),N.setAttribute("y",String(y-S)),N.setAttribute("width",String(f-1)),N.setAttribute("height",String(S)),N.setAttribute("fill",a),b.appendChild(N)}return n.appendChild(b),n}function wn(){p("Table",ni),p("TableHead",ht("thead")),p("TableBody",ht("tbody")),p("TableFooter",ht("tfoot")),p("TableRow",ri),p("TableHeader",oi),p("TableCell",ii),p("TableCaption",si),p("ExpandableRow",ai)}function ni(e,t){let n=document.createElement("table");return n.className=e.striped===!0?"pf-table pf-table-striped":"pf-table",n.style.width="100%",n.style.borderCollapse="collapse",H(e,n,t),n}function ht(e){return(t,n)=>{let r=document.createElement(e);return r.className=`pf-${e}`,H(t,r,n),r}}function ri(e,t){let n=document.createElement("tr");return n.className="pf-table-row",H(e,n,t),n}function oi(e,t){let n=document.createElement("th");return n.className="pf-table-header",n.style.textAlign="left",n.style.padding="8px 12px",n.style.fontWeight="600",n.textContent=C(e.content,t),n}function ii(e,t){let n=document.createElement("td");if(n.className="pf-table-cell",n.style.padding="8px 12px",e.colSpan!=null)n.colSpan=e.colSpan;if(e.rowSpan!=null)n.rowSpan=e.rowSpan;return H(e,n,t),n}function si(e,t){let n=document.createElement("caption");return n.className="pf-table-caption",n.style.padding="8px",n.style.fontSize="14px",n.textContent=C(e.content,t),n}function ai(e,t){let n=m("div","pf-expandable-row"),r=m("div","pf-expandable-row-summary");r.style.cursor="pointer",r.style.display="flex",r.style.alignItems="center",r.style.gap="8px";let o=m("span","pf-expandable-arrow");o.textContent="▶",o.style.transition="transform 0.2s",o.style.fontSize="10px",r.appendChild(o);let i=e.summary;if(i)for(let l of i)r.appendChild(J(l,t));let s=m("div","pf-expandable-row-detail");s.style.display="none",s.style.paddingLeft="24px",H(e,s,t);let a=!1;return r.addEventListener("click",()=>{a=!a,s.style.display=a?"block":"none",o.style.transform=a?"rotate(90deg)":""}),n.appendChild(r),n.appendChild(s),n}var xn=!1;function We(){if(xn)return;xn=!0;let e=new Set(it());qt(),Zt(),tn(),nn(),on(),an(),ln(),pn(),un(),gn(),vn(),wn(),_t(it().filter((t)=>!e.has(t)))}function yt(e){return e.replace(/[^a-zA-Z0-9_-]/g,"")}function Ct(e){return e.replace(/[{}<>;]/g,"").replace(/\b(url|expression)\s*\(/gi,"")}function bt(e,t=" "){return Object.entries(e).map(([n,r])=>`${t}--${yt(n)}: ${Ct(r)};`).join(`
7
- `)}function kn(e){if(!e)return"";let t=[];if(e.light&&Object.keys(e.light).length>0)t.push(`:root {
8
- ${bt(e.light)}
9
- }`);if(e.dark&&Object.keys(e.dark).length>0){let n=bt(e.dark);t.push(`.dark, [data-theme="dark"] {
3
+ `),n=[],r=0;while(r<t.length){let o=t[r];if(o.trimStart().startsWith("```")){let a=o.trimStart().slice(3).trim(),l=[];r++;while(r<t.length&&!t[r].trimStart().startsWith("```"))l.push(xe(t[r])),r++;r++;let d=a?` data-language="${xe(a)}"`:"";n.push(`<pre class="pf-code"><code${d}>${l.join(`
4
+ `)}</code></pre>`);continue}if(/^(\s*[-*_]\s*){3,}$/.test(o)){n.push("<hr />"),r++;continue}let i=/^(#{1,6})\s+(.+)$/.exec(o);if(i){let a=i[1].length;n.push(`<h${a}>${je(i[2])}</h${a}>`),r++;continue}if(o.startsWith("> ")||o===">"){let a=[];while(r<t.length&&(t[r].startsWith("> ")||t[r]===">"))a.push(t[r].replace(/^>\s?/,"")),r++;n.push(`<blockquote>${tn(a.join(`
5
+ `))}</blockquote>`);continue}if(/^[\s]*[-*+]\s+/.test(o)){n.push("<ul>");while(r<t.length&&/^[\s]*[-*+]\s+/.test(t[r]))n.push(`<li>${je(t[r].replace(/^[\s]*[-*+]\s+/,""))}</li>`),r++;n.push("</ul>");continue}if(/^[\s]*\d+\.\s+/.test(o)){n.push("<ol>");while(r<t.length&&/^[\s]*\d+\.\s+/.test(t[r]))n.push(`<li>${je(t[r].replace(/^[\s]*\d+\.\s+/,""))}</li>`),r++;n.push("</ol>");continue}if(o.trim()===""){r++;continue}let s=[];while(r<t.length&&t[r].trim()!==""&&!/^#{1,6}\s/.test(t[r])&&!/^[-*+]\s/.test(t[r])&&!/^\d+\.\s/.test(t[r])&&!t[r].startsWith("> ")&&!t[r].trimStart().startsWith("```")&&!/^(\s*[-*_]\s*){3,}$/.test(t[r]))s.push(t[r]),r++;n.push(`<p>${s.map(je).join("<br />")}</p>`)}return n.join(`
6
+ `)}function Br(e,t){let n=document.createElement("kbd");return n.className="pf-kbd",n.textContent=C(e.content,t),n}function rn(){p("Card",Jr),p("CardHeader",dt("pf-card-header")),p("CardTitle",nn("pf-card-title","h3")),p("CardDescription",nn("pf-card-description","p")),p("CardContent",dt("pf-card-content")),p("CardFooter",dt("pf-card-footer"))}function Jr(e,t){let n=m("div","pf-card");return n.style.overflow="hidden",H(e,n,t),n}function dt(e){return(t,n)=>{let r=m("div",e);return r.style.padding="16px 24px",H(t,r,n),r}}function nn(e,t){return(n,r)=>{let o=document.createElement(t);return o.className=e,o.textContent=C(n.content,r),o}}function on(){p("DataTable",zr),p("Badge",Vr),p("Dot",Wr),p("Metric",_r),p("Ring",Kr),p("Progress",Gr),p("Separator",qr),p("Loader",Ur),p("Icon",Xr),p("Sparkline",Yr)}function zr(e,t){let n=m("div","pf-datatable-wrapper"),r=document.createElement("table");r.className="pf-datatable",r.style.width="100%",r.style.borderCollapse="collapse";let o=e.columns??[],i=K(e.rows,t),s=e.rowKey,a=e.selected,l=document.createElement("thead"),d=document.createElement("tr");for(let c of o){let g=document.createElement("th");g.className="pf-datatable-th",g.textContent=c.header??c.key,g.style.padding="8px 12px",g.style.textAlign="left",d.appendChild(g)}l.appendChild(d),r.appendChild(l);let u=document.createElement("tbody");if(Array.isArray(i)){let c=a!=null?K(a,t):void 0;for(let g of i){let h=document.createElement("tr");h.className="pf-datatable-row";let y=g,f=g===null||typeof g!=="object";if(s&&c!=null&&y[s]!=null&&L(y[s])===L(c))h.classList.add("pf-datatable-row-selected");if(e.onRowClick!=null&&s)h.style.cursor="pointer",h.addEventListener("click",()=>{let b={...t.scope,$item:y,$index:i.indexOf(g)},w=_({...t,scope:b});I(j(e.onRowClick,w),"onRowClick")});for(let b of o){let w=document.createElement("td");w.className="pf-datatable-td";let S;if(b.accessor)S=K(`{{ $item.${b.accessor} }}`,{...t,scope:{...t.scope,$item:y}});else if(S=f?g:y[b.key],b.format&&S!=null)S=K(`{{ __fmtVal | ${b.format} }}`,{...t,scope:{...t.scope,__fmtVal:S}});w.textContent=L(S),w.style.padding="8px 12px",h.appendChild(w)}u.appendChild(h)}}if(r.appendChild(u),e.search===!0){let c=document.createElement("input");c.type="text",c.placeholder="Search...",c.className="pf-datatable-search",c.style.marginBottom="8px",c.style.padding="6px 12px",c.style.width="100%",c.style.boxSizing="border-box",c.addEventListener("input",()=>{let g=c.value.toLowerCase(),h=Array.from(u.querySelectorAll("tr"));for(let y of h){let f=(y.textContent??"").toLowerCase();y.style.display=f.includes(g)?"":"none"}}),n.appendChild(c)}return n.appendChild(r),n}function Vr(e,t){let n=m("span","pf-badge"),r=e.variant??"default";return n.setAttribute("data-variant",r),n.style.alignItems="center",n.style.padding="2px 10px",n.style.borderRadius="9999px",n.style.fontSize="12px",n.style.fontWeight="500",n.textContent=C(e.label??e.content,t),Zr(n,r),n}function Wr(e,t){let n=m("span","pf-dot"),r=e.color??"gray";return n.style.display="inline-block",n.style.width="8px",n.style.height="8px",n.style.borderRadius="50%",n.style.backgroundColor=r,n}function _r(e,t){let n=m("div","pf-metric"),r=m("div","pf-metric-label");r.textContent=C(e.label,t),r.style.fontSize="14px",n.appendChild(r);let o=m("div","pf-metric-value");if(o.textContent=C(e.value,t),o.style.fontSize="28px",o.style.fontWeight="700",n.appendChild(o),e.delta!=null){let i=m("span","pf-metric-delta");i.textContent=C(e.delta,t);let s=e.trend??"",a=e.trendSentiment??"neutral";if(i.style.fontSize="14px",i.style.color=a==="positive"?"green":a==="negative"?"red":"inherit",s==="up")i.textContent="↑ "+i.textContent;else if(s==="down")i.textContent="↓ "+i.textContent;n.appendChild(i)}if(e.description!=null){let i=m("div","pf-metric-desc");i.textContent=C(e.description,t),i.style.fontSize="12px",n.appendChild(i)}return n}function Kr(e,t){let n=m("div","pf-ring"),r=e.size??80,o=e.thickness??8,i=Number(K(e.value,t)??0),s=Math.max(0,Math.min(100,i)),a=(r-o)/2,l=2*Math.PI*a,d=l*(1-s/100),u=document.createElementNS("http://www.w3.org/2000/svg","svg");u.setAttribute("width",String(r)),u.setAttribute("height",String(r)),u.setAttribute("viewBox",`0 0 ${r} ${r}`);let c=document.createElementNS("http://www.w3.org/2000/svg","circle");c.setAttribute("cx",String(r/2)),c.setAttribute("cy",String(r/2)),c.setAttribute("r",String(a)),c.setAttribute("fill","none"),c.setAttribute("stroke","var(--muted, #e5e7eb)"),c.setAttribute("stroke-width",String(o));let g=document.createElementNS("http://www.w3.org/2000/svg","circle");if(g.setAttribute("cx",String(r/2)),g.setAttribute("cy",String(r/2)),g.setAttribute("r",String(a)),g.setAttribute("fill","none"),g.setAttribute("stroke","var(--primary, #3b82f6)"),g.setAttribute("stroke-width",String(o)),g.setAttribute("stroke-dasharray",String(l)),g.setAttribute("stroke-dashoffset",String(d)),g.setAttribute("stroke-linecap","round"),g.style.transform="rotate(-90deg)",g.style.transformOrigin="center",u.appendChild(c),u.appendChild(g),n.appendChild(u),e.label!=null){let h=m("div","pf-ring-label");h.textContent=C(e.label,t),h.style.textAlign="center",h.style.fontSize="12px",n.appendChild(h)}return n}function Gr(e,t){let n=m("div","pf-progress");n.setAttribute("role","progressbar");let r=Number(K(e.value,t)??0),o=e.max??100,i=o>0?Math.max(0,Math.min(100,r/o*100)):0;n.setAttribute("aria-valuenow",String(r)),n.setAttribute("aria-valuemin","0"),n.setAttribute("aria-valuemax",String(o)),n.style.height="8px",n.style.borderRadius="4px",n.style.overflow="hidden";let s=m("div","pf-progress-fill");return s.style.height="100%",s.style.width=`${i}%`,s.style.borderRadius="4px",s.style.transition="width 0.3s ease",n.appendChild(s),n}function qr(e,t){let n=document.createElement("hr");return n.className="pf-separator",n.style.border="none",n.style.margin="8px 0",n}function Ur(e,t){let n=m("div","pf-loader");return n.textContent="⏳",n.style.display="flex",n.style.justifyContent="center",n.style.padding="16px",n}function Xr(e,t){let n=m("span","pf-icon");return n.setAttribute("data-icon",C(e.name??e.content,t)),n}function Yr(e,t){let n=m("div","pf-sparkline"),r=e.data??[];if(r.length===0)return n;let o=e.width??120,i=e.height??32,s=Math.max(...r),a=Math.min(...r),l=s-a||1,d=document.createElementNS("http://www.w3.org/2000/svg","svg");d.setAttribute("width",String(o)),d.setAttribute("height",String(i)),d.setAttribute("viewBox",`0 0 ${o} ${i}`);let u=r.length>1?r.length-1:1,c=r.map((h,y)=>{let f=y/u*o,b=i-(h-a)/l*(i-4)-2;return`${f},${b}`}).join(" "),g=document.createElementNS("http://www.w3.org/2000/svg","polyline");return g.setAttribute("points",c),g.setAttribute("fill","none"),g.setAttribute("stroke","var(--primary, #3b82f6)"),g.setAttribute("stroke-width","1.5"),d.appendChild(g),n.appendChild(d),n}function Zr(e,t){let r={success:{bg:"#10b981",fg:"#fff"},warning:{bg:"#f59e0b",fg:"#fff"},info:{bg:"#3b82f6",fg:"#fff"}}[t];if(r)e.style.backgroundColor=r.bg,e.style.color=r.fg}function sn(){p("Form",Qr),p("Input",eo),p("Textarea",be(to)),p("Button",no),p("ButtonGroup",ro),p("Checkbox",oo),p("Switch",io),p("Slider",be(so)),p("Calendar",lo),p("DatePicker",be(co)),p("Field",ke("pf-field")),p("FieldTitle",ye("pf-field-title")),p("FieldDescription",ye("pf-field-description")),p("FieldContent",ke("pf-field-content")),p("FieldError",ye("pf-field-error"))}function Qr(e,t){let n=document.createElement("form");return n.className="pf-form",n.addEventListener("submit",(r)=>{r.preventDefault();let o=new FormData(n),i={};for(let s of new Set(o.keys())){let a=o.getAll(s),l=n.elements.namedItem(s),d=l instanceof HTMLSelectElement&&l.multiple||a.length>1;i[s]=d?a:a[0]}if(t.store.merge(i),e.onSubmit!=null){let s=_(t);s.scope={...t.scope,...i},I(j(e.onSubmit,s),"onSubmit")}}),H(e,n,t),n}function an(e,t,n){if(t.label==null)return;let r=document.createElement("label");if(r.className="pf-input-label",r.textContent=C(t.label,n),t.name!=null)r.htmlFor=t.name;r.style.fontSize="14px",r.style.fontWeight="500",e.insertBefore(r,e.firstChild)}function be(e){return(t,n)=>{let r=e(t,n);return r.style.display="flex",r.style.flexDirection="column",r.style.gap="4px",an(r,t,n),r}}function ae(e,t){if(t.required!==!0)return;if("required"in e)e.required=!0;e.setAttribute("aria-required","true")}function eo(e,t){let n=m("div","pf-input-wrapper");n.style.display="flex",n.style.flexDirection="column",n.style.gap="4px",an(n,e,t);let r=document.createElement("input");if(r.className="pf-input",r.type=e.inputType??"text",e.name!=null)r.name=e.name;if(e.name!=null)r.id=`pf-input-${e.name}`;if(e.placeholder!=null)r.placeholder=C(e.placeholder,t);if(ae(r,e),e.error!=null)r.setAttribute("aria-invalid","true");let o=e.name;if(o){let i=t.store.get(o);if(i!=null)r.value=L(i);r.addEventListener("input",()=>{if(t.store.set(o,r.value),e.onChange!=null)I(j(e.onChange,{..._(t),scope:{...t.scope,$event:r.value}}),"onChange")})}return Ie(r),n.appendChild(r),n}function to(e,t){let n=m("div","pf-textarea-wrapper"),r=document.createElement("textarea");if(r.className="pf-textarea",e.name!=null)r.name=e.name;if(e.name!=null)r.id=`pf-textarea-${e.name}`;if(e.placeholder!=null)r.placeholder=C(e.placeholder,t);if(e.rows!=null)r.rows=e.rows;ae(r,e);let o=e.name;if(o!=null){let i=t.store.get(o);if(i!=null)r.value=L(i);r.addEventListener("input",()=>{if(t.store.set(o,r.value),e.onChange!=null)I(j(e.onChange,{..._(t),scope:{...t.scope,$event:r.value}}),"onChange")})}return Ie(r),n.appendChild(r),n}function no(e,t){let n=document.createElement("button");n.className="pf-button",n.type=e.submit===!0?"submit":"button",n.textContent=C(e.label,t);let r=e.variant??"default";if(n.setAttribute("data-variant",r),ao(n,r),e.size!=null)n.setAttribute("data-size",e.size);if(e.disabled===!0)n.disabled=!0;return n}function ro(e,t){let n=m("div","pf-button-group");return n.style.display="flex",n.style.gap="8px",H(e,n,t),n}function oo(e,t){let n=m("label","pf-checkbox-wrapper");n.style.display="flex",n.style.alignItems="center",n.style.gap="8px",n.style.cursor="pointer";let r=document.createElement("input");if(r.type="checkbox",r.className="pf-checkbox",e.name!=null)r.name=e.name;if(e.checked===!0)r.checked=!0;let o=e.name;if(o){let i=t.store.get(o);if(typeof i==="boolean")r.checked=i;r.addEventListener("change",()=>{if(t.store.set(o,r.checked),e.onChange!=null)I(j(e.onChange,{..._(t),scope:{...t.scope,$event:r.checked}}),"onChange")})}if(n.appendChild(r),e.label!=null){let i=m("span");i.textContent=C(e.label,t),n.appendChild(i)}return n}function io(e,t){let n=m("label","pf-switch-wrapper");n.style.display="flex",n.style.alignItems="center",n.style.gap="8px",n.style.cursor="pointer";let r=document.createElement("input");if(r.type="checkbox",r.className="pf-switch",r.setAttribute("role","switch"),e.name!=null)r.name=e.name;let o=e.name;if(o){let i=t.store.get(o);if(typeof i==="boolean")r.checked=i;r.addEventListener("change",()=>{if(t.store.set(o,r.checked),e.onChange!=null)I(j(e.onChange,{..._(t),scope:{...t.scope,$event:r.checked}}),"onChange")})}if(n.appendChild(r),e.label!=null){let i=m("span");i.textContent=C(e.label,t),n.appendChild(i)}return n}function so(e,t){let n=m("div","pf-slider-wrapper"),r=document.createElement("input");if(r.type="range",r.className="pf-slider",e.name!=null)r.name=e.name;if(e.min!=null)r.min=L(e.min);if(e.max!=null)r.max=L(e.max);if(e.step!=null)r.step=L(e.step);let o=e.name;if(o){let i=t.store.get(o);if(i!=null)r.value=L(i);r.addEventListener("input",()=>{if(t.store.set(o,Number(r.value)),e.onChange!=null)I(j(e.onChange,{..._(t),scope:{...t.scope,$event:Number(r.value)}}),"onChange")})}return n.appendChild(r),n}function Ie(e){e.style.padding="8px 12px",e.style.fontSize="14px",e.style.width="100%",e.style.boxSizing="border-box"}function ao(e,t){if(e.style.padding="8px 16px",e.style.fontSize="14px",e.style.fontWeight="500",e.style.cursor="pointer",e.style.border="none",t==="ghost")e.style.backgroundColor="transparent",e.style.color="inherit"}function ke(e){return(t,n)=>{let r=m("div",e);return H(t,r,n),r}}function ye(e){return(t,n)=>{let r=m("span",e);return r.textContent=C(t.content,n),r}}function ct(){let e=document.createElement("hr");return e.className="pf-separator",e.style.border="none",e.style.margin="4px 0",e}function lo(e,t){let n=m("div","pf-calendar"),r=document.createElement("input");if(r.type="date",r.name=C(e.name,t),ae(r,e),e.value!==void 0)r.value=C(e.value,t);let o=r.name,i=t.store.get(o);if(i!=null)r.value=L(i);if(e.minDate!=null)r.min=C(e.minDate,t);if(e.maxDate!=null)r.max=C(e.maxDate,t);return r.style.padding="6px 12px",r.style.borderRadius="6px",r.addEventListener("change",()=>{if(t.store.set(r.name,r.value),e.onChange!=null)I(j(e.onChange,_(t)),"onChange")}),n.appendChild(r),n}function co(e,t){let n=m("div","pf-datepicker"),r=document.createElement("input");if(r.type="date",r.name=C(e.name,t),ae(r,e),e.placeholder!=null)r.placeholder=C(e.placeholder,t);if(e.value!==void 0)r.value=C(e.value,t);let o=r.name,i=t.store.get(o);if(i!=null)r.value=L(i);if(e.minDate!=null)r.min=C(e.minDate,t);if(e.maxDate!=null)r.max=C(e.maxDate,t);return r.style.padding="6px 12px",r.style.borderRadius="6px",r.style.width="100%",r.style.boxSizing="border-box",r.addEventListener("change",()=>{if(t.store.set(r.name,r.value),e.onChange!=null)I(j(e.onChange,_(t)),"onChange")}),n.appendChild(r),n}function ln(){p("Select",be(po)),p("SelectOption",mo),p("SelectGroup",ke("pf-select-group")),p("SelectLabel",ye("pf-select-label")),p("SelectSeparator",ct),p("Radio",go),p("RadioGroup",ho),p("Combobox",be(bo)),p("ComboboxOption",yo),p("ComboboxGroup",ke("pf-combobox-group")),p("ComboboxLabel",ye("pf-combobox-label")),p("ComboboxSeparator",ct),p("ChoiceCard",Co)}function po(e,t){let n=m("div","pf-select-wrapper"),r=document.createElement("select");if(r.className="pf-select",e.name!=null)r.name=e.name;if(e.multiple===!0)r.multiple=!0;if(ae(r,e),Ie(r),e.placeholder!=null){let s=document.createElement("option");s.value="",s.textContent=C(e.placeholder,t),s.disabled=!0,s.selected=!0,s.hidden=!0,r.appendChild(s)}let o=e.options;if(Array.isArray(o))for(let s of o){let a=document.createElement("option");a.value=s.value??"",a.textContent=s.label??a.value,r.appendChild(a)}if(e.children)for(let s of e.children)if(s.type==="SelectOption"){let a=document.createElement("option");a.value=s.value??"",a.textContent=s.label??a.value,r.appendChild(a)}else r.appendChild(J(s,t));let i=e.name;if(i){let s=t.store.get(i);if(s!=null)fo(r,s);r.addEventListener("change",()=>{let a=uo(r);if(t.store.set(i,a),e.onChange!=null)I(j(e.onChange,{..._(t),scope:{...t.scope,$event:a}}),"onChange")})}return n.appendChild(r),n}function uo(e){if(!e.multiple)return e.value;return Array.from(e.selectedOptions,(t)=>t.value)}function fo(e,t){if(!e.multiple){e.value=L(t);return}let n=new Set((Array.isArray(t)?t:[t]).map((r)=>L(r)));for(let r of e.options)r.selected=n.has(r.value)}function mo(e,t){return m("span")}function go(e,t){let n=m("label","pf-radio");n.style.display="flex",n.style.alignItems="center",n.style.gap="8px",n.style.cursor="pointer";let r=document.createElement("input");if(r.type="radio",r.value=C(e.value,t),n.appendChild(r),e.label!=null){let o=m("span","pf-radio-label");o.textContent=C(e.label,t),n.appendChild(o)}return n}function ho(e,t){let n=m("fieldset","pf-radio-group");if(ae(n,e),n.style.border="none",n.style.padding="0",n.style.display="flex",n.style.flexDirection="column",n.style.gap="8px",e.label!=null){let i=document.createElement("legend");i.textContent=C(e.label,t),i.style.fontWeight="500",i.style.marginBottom="4px",n.appendChild(i)}H(e,n,t);let r=C(e.name,t),o=t.store.get(r);for(let i of Array.from(n.querySelectorAll('input[type="radio"]')))if(i.name=r,o!=null&&i.value===L(o))i.checked=!0;return n.addEventListener("change",(i)=>{let s=i.target;if(s.type==="radio"){if(t.store.set(r,s.value),e.onChange!=null)I(j(e.onChange,_(t)),"onChange")}}),n}function bo(e,t){let n=m("div","pf-combobox"),r=document.createElement("input");if(r.className="pf-combobox-input",r.type="text",r.name=C(e.name,t),ae(r,e),e.placeholder!=null)r.placeholder=C(e.placeholder,t);if(e.value!==void 0)r.value=C(e.value,t);let o=r.name,i=t.store.get(o);if(i!=null)r.value=L(i);r.style.padding="6px 12px",r.style.borderRadius="6px",r.style.width="100%",r.style.boxSizing="border-box";let s=m("div","pf-combobox-dropdown");if(s.style.display="none",s.style.position="absolute",s.style.borderRadius="6px",s.style.maxHeight="200px",s.style.overflowY="auto",s.style.zIndex="50",H(e,s,t),r.addEventListener("focus",()=>{s.style.display="block"}),r.addEventListener("blur",()=>{setTimeout(()=>{s.style.display="none"},150)}),e.searchable!==!1)r.addEventListener("input",()=>{let a=r.value.toLowerCase();for(let l of Array.from(s.querySelectorAll(".pf-combobox-option"))){let d=(l.textContent??"").toLowerCase();l.style.display=d.includes(a)?"":"none"}});if(e.onChange!=null)n.addEventListener("pf-combobox-select",()=>{I(j(e.onChange,{..._(t),scope:{...t.scope,$event:r.value}}),"onChange")});return n.style.position="relative",n.appendChild(r),n.appendChild(s),n}function yo(e,t){let n=m("div","pf-combobox-option");return n.style.padding="6px 12px",n.style.cursor="pointer",n.textContent=C(e.label??e.value,t),n.dataset.value=C(e.value,t),n.addEventListener("mousedown",()=>{let r=n.closest(".pf-combobox"),o=r?.querySelector("input");if(o)o.value=n.dataset.value??"",t.store.set(o.name,o.value),r?.dispatchEvent(new CustomEvent("pf-combobox-select",{bubbles:!1}))}),n}function Co(e,t){let n=m("div","pf-choice-card");if(n.style.padding="16px",n.style.cursor="pointer",n.style.transition="border-color 0.2s",n.dataset.value=C(e.value,t),e.selected===!0)n.dataset.selected="true";if(e.label!=null){let r=m("div","pf-choice-card-label");r.textContent=C(e.label,t),r.style.fontWeight="600",n.appendChild(r)}if(e.description!=null){let r=m("div","pf-choice-card-description");r.textContent=C(e.description,t),r.style.fontSize="14px",n.appendChild(r)}return H(e,n,t),n}function dn(){p("Tabs",vo),p("Tab",wo),p("Accordion",xo),p("AccordionItem",ko),p("Dialog",So),p("Popover",Ao),p("Tooltip",Eo),p("HoverCard",Ro),p("Carousel",To)}function vo(e,t){let n=m("div","pf-tabs"),r=m("div","pf-tabs-bar");r.setAttribute("role","tablist"),r.style.display="flex",r.style.gap="4px",r.style.marginBottom="12px";let o=[],i=[],s=e.children??[],a=(()=>{let d=e.defaultTab;if(typeof d==="number")return d>=0&&d<s.length?d:0;if(typeof d==="string"){let u=s.findIndex((c)=>c.title===d);return u>=0?u:0}return 0})();if(e.children)for(let d=0;d<e.children.length;d++){let u=e.children[d],c=`pf-tab-${Math.random().toString(36).slice(2,8)}`,g=`pf-panel-${Math.random().toString(36).slice(2,8)}`,h=document.createElement("button");h.type="button",h.className="pf-tab-trigger",h.textContent=u.title??`Tab ${d+1}`,h.setAttribute("role","tab"),h.setAttribute("aria-selected",d===a?"true":"false"),h.setAttribute("aria-controls",g),h.id=c,h.tabIndex=d===a?0:-1,h.style.padding="8px 16px",h.style.border="none",h.style.background="none",h.style.cursor="pointer",h.style.borderBottom="2px solid transparent",h.style.marginBottom="-2px",h.style.fontSize="14px";let y=m("div","pf-tab-panel");if(y.style.display=d===a?"block":"none",y.setAttribute("role","tabpanel"),y.setAttribute("aria-labelledby",c),y.id=g,y.tabIndex=0,H(u,y,t),h.addEventListener("click",()=>{l(d)}),d===a)h.classList.add("pf-tab-active"),h.style.fontWeight="600";i.push(h),o.push(y),r.appendChild(h)}function l(d){o.forEach((u)=>u.style.display="none"),i.forEach((u)=>{u.style.borderBottomColor="transparent",u.style.fontWeight="normal",u.classList.remove("pf-tab-active"),u.setAttribute("aria-selected","false"),u.tabIndex=-1}),o[d].style.display="block",i[d].classList.add("pf-tab-active"),i[d].style.fontWeight="600",i[d].setAttribute("aria-selected","true"),i[d].tabIndex=0,i[d].focus()}r.addEventListener("keydown",(d)=>{let u=i.indexOf(d.target);if(u<0)return;let c;if(d.key==="ArrowRight")c=(u+1)%i.length;else if(d.key==="ArrowLeft")c=(u-1+i.length)%i.length;else if(d.key==="Home")c=0;else if(d.key==="End")c=i.length-1;else return;d.preventDefault(),l(c)}),n.appendChild(r);for(let d of o)n.appendChild(d);return n}function wo(e,t){let n=m("div","pf-tab");return H(e,n,t),n}function xo(e,t){let n=m("div","pf-accordion");return H(e,n,t),n}function ko(e,t){let n=m("div","pf-accordion-item"),r=`pf-acc-${Math.random().toString(36).slice(2,8)}`,o=document.createElement("button");o.type="button",o.className="pf-accordion-trigger",o.textContent=e.title??"",o.setAttribute("aria-expanded","false"),o.setAttribute("aria-controls",r),o.style.width="100%",o.style.textAlign="left",o.style.padding="12px 0",o.style.border="none",o.style.background="none",o.style.cursor="pointer",o.style.fontSize="14px",o.style.fontWeight="500";let i=m("div","pf-accordion-content");return i.id=r,i.setAttribute("role","region"),i.setAttribute("aria-labelledby",o.id),i.style.display="none",i.style.paddingBottom="12px",H(e,i,t),o.addEventListener("click",()=>{let s=i.style.display!=="none";i.style.display=s?"none":"block",o.setAttribute("aria-expanded",s?"false":"true")}),n.appendChild(o),n.appendChild(i),n}function So(e,t){let n=m("div","pf-dialog-wrapper");if(e.trigger!=null){let i=J(e.trigger,t);i.addEventListener("click",()=>{r.showModal()}),n.appendChild(i)}let r=document.createElement("dialog");if(r.className="pf-dialog",r.setAttribute("aria-modal","true"),r.style.maxWidth="500px",r.style.width="100%",r.style.padding="24px",e.title!=null){let i=m("h2","pf-dialog-title");i.textContent=C(e.title,t),i.id=`pf-dialog-title-${Math.random().toString(36).slice(2,8)}`,r.setAttribute("aria-labelledby",i.id),r.appendChild(i)}if(e.description!=null){let i=m("p","pf-dialog-desc");i.textContent=C(e.description,t),r.appendChild(i)}let o=m("div","pf-dialog-body");if(H(e,o,t),r.appendChild(o),e.dismissible!==!1)r.addEventListener("click",(i)=>{if(i.target===r)r.close()});return document.addEventListener("prefab:close-overlay",()=>r.close()),n.appendChild(r),n}function Ao(e,t){let n=m("div","pf-popover");n.style.position="relative",n.style.display="inline-block";let r=m("div","pf-popover-content");if(r.style.display="none",r.style.position="absolute",r.style.zIndex="50",r.style.padding="12px",r.style.boxShadow="0 4px 6px -1px rgb(0 0 0 / 0.1)",e.title!=null){let i=m("div","pf-popover-title");i.textContent=C(e.title,t),i.style.fontWeight="600",i.style.marginBottom="4px",r.appendChild(i)}H(e,r,t);let o=()=>{r.style.display=r.style.display==="none"?"block":"none"};if(e.trigger!=null){let i=J(e.trigger,t);i.addEventListener("click",(s)=>{s.stopPropagation(),o()}),n.appendChild(i)}else n.addEventListener("click",(i)=>{if(r.contains(i.target)&&r.style.display!=="none")return;o()});return n.appendChild(r),n}function Eo(e,t){let n=m("div","pf-tooltip");n.style.position="relative",n.style.display="inline-block";let r=`pf-tip-${Math.random().toString(36).slice(2,8)}`,o=m("div","pf-tooltip-content");return o.id=r,o.setAttribute("role","tooltip"),o.textContent=C(e.content??"",t),o.style.display="none",o.style.position="absolute",o.style.bottom="100%",o.style.left="50%",o.style.transform="translateX(-50%)",o.style.padding="4px 8px",o.style.borderRadius="4px",o.style.color="#fff",o.style.fontSize="12px",o.style.whiteSpace="nowrap",o.style.zIndex="50",H(e,n,t),n.setAttribute("aria-describedby",r),n.addEventListener("mouseenter",()=>{o.style.display="block"}),n.addEventListener("mouseleave",()=>{o.style.display="none"}),n.addEventListener("focus",()=>{o.style.display="block"},!0),n.addEventListener("blur",()=>{o.style.display="none"},!0),n.appendChild(o),n}function Ro(e,t){let n=m("div","pf-hover-card");n.style.position="relative",n.style.display="inline-block";let r=m("div","pf-hover-card-content");if(r.style.display="none",r.style.position="absolute",r.style.zIndex="50",r.style.padding="16px",r.style.boxShadow="0 4px 6px -1px rgb(0 0 0 / 0.1)",r.style.minWidth="200px",e.trigger!=null)n.appendChild(J(e.trigger,t));return H(e,r,t),n.addEventListener("mouseenter",()=>{r.style.display="block"}),n.addEventListener("mouseleave",()=>{r.style.display="none"}),n.appendChild(r),n}function To(e,t){let n=m("div","pf-carousel");n.style.position="relative",n.style.overflow="hidden",n.setAttribute("role","region"),n.setAttribute("aria-roledescription","carousel"),n.setAttribute("aria-label",C(e.label??"Carousel",t));let r=m("div","pf-carousel-track");r.style.display="flex",r.style.transition="transform 0.3s ease",H(e,r,t);let o=0,i=e.children?.length??0,s=document.createElement("button");s.type="button",s.textContent="‹",s.className="pf-carousel-prev",s.setAttribute("aria-label","Previous slide"),s.style.position="absolute",s.style.left="4px",s.style.top="50%",s.style.transform="translateY(-50%)",s.style.zIndex="10";let a=document.createElement("button");a.type="button",a.textContent="›",a.className="pf-carousel-next",a.setAttribute("aria-label","Next slide"),a.style.position="absolute",a.style.right="4px",a.style.top="50%",a.style.transform="translateY(-50%)",a.style.zIndex="10";let l=()=>{r.style.transform=`translateX(-${o*100}%)`};return s.addEventListener("click",()=>{if(i===0)return;o=Math.max(0,o-1),l()}),a.addEventListener("click",()=>{if(i===0)return;o=Math.min(i-1,o+1),l()}),n.appendChild(r),n.appendChild(s),n.appendChild(a),n}function cn(){p("ForEach",No),p("If",pn),p("Elif",Mo),p("Else",Lo),p("Condition",Ho),p("Define",Po),p("Use",Oo),p("Slot",$o)}function No(e,t){let n=document.createDocumentFragment(),r=e.expression;if(!r)return n;let o;if(Q(r)){let s=ee(r,t.store,t.scope);o=Array.isArray(s)?s:[]}else{let s=t.store.get(r);o=Array.isArray(s)?s:[]}let i=e.let??{};for(let s=0;s<o.length;s++){let a=o[s],l={...t.scope,$item:a,$index:s,...i},d={...t,scope:l};if(e.children)se(e.children,n,d)}return n}function pn(e,t){if(un(e.condition,t)){let r=document.createDocumentFragment();if(e.children)se(e.children,r,t);return r}return document.createDocumentFragment()}function Mo(e,t){return pn(e,t)}function Lo(e,t){let n=document.createDocumentFragment();if(e.children)se(e.children,n,t);return n}function un(e,t){if(!e)return!1;if(Q(e))return Boolean(ee(e,t.store,t.scope));return Boolean(t.store.get(e))}function Ho(e,t){let n=document.createDocumentFragment(),r=e.cases,o=e.else;if(r){for(let i of r)if(un(i.when,t)){if(i.children)se(i.children,n,t);return n}}if(o)se(o,n,t);return n}function Po(e,t){let n=e.name;if(n&&e.children)t.templates=t.templates??{},t.templates[n]=e.children;return document.createDocumentFragment()}function Oo(e,t){let n=document.createDocumentFragment(),r=e.def??e.name,o=t.templates?.[r];if(!o)return n;let i=e.overrides??{},s={...t.scope,...i},a={...t.slots??{},...e.slots??{}};if(Array.isArray(e.children))a.default=e.children;let l={...t,scope:s,slots:a};for(let d of o)n.appendChild(J(d,l));return n}function $o(e,t){let n=document.createDocumentFragment(),r=e.name??"default",i=t.slots?.[r]??e.children;if(i)for(let s of i)n.appendChild(J(s,t));return n}function fn(){p("Alert",Do),p("AlertTitle",jo),p("AlertDescription",Io)}function Do(e,t){let n=m("div","pf-alert");n.setAttribute("role","alert");let r=e.variant??"default";if(n.setAttribute("data-variant",r),n.style.padding="12px 16px",e.icon!=null){let o=m("span","pf-alert-icon");o.setAttribute("data-icon",e.icon),o.style.marginRight="8px",n.appendChild(o)}return H(e,n,t),n}function jo(e,t){let n=m("h5","pf-alert-title");return n.textContent=C(e.content,t),n.style.fontWeight="600",n.style.marginBottom="4px",n}function Io(e,t){let n=m("p","pf-alert-description");return n.textContent=C(e.content,t),n.style.fontSize="14px",n}function mn(){p("Image",Fo),p("Audio",Bo),p("Video",Jo),p("Embed",zo),p("Svg",Wo),p("DropZone",Ko),p("Mermaid",Go)}function Fo(e,t){let n=document.createElement("img");if(n.className="pf-image",n.src=C(e.src,t),e.alt!=null)n.alt=C(e.alt,t);if(e.width!=null)n.width=e.width;if(e.height!=null)n.height=e.height;return n.style.maxWidth="100%",n}function Bo(e,t){let n=document.createElement("audio");return n.className="pf-audio",n.src=C(e.src,t),n.controls=!0,n}function Jo(e,t){let n=document.createElement("video");if(n.className="pf-video",n.src=C(e.src,t),n.controls=!0,e.width!=null)n.width=e.width;if(e.height!=null)n.height=e.height;return n.style.maxWidth="100%",n}function zo(e,t){let n=m("div","pf-embed"),r=document.createElement("iframe");return r.src=C(e.src,t),r.style.width="100%",r.style.height=e.height!=null?`${e.height}px`:"400px",r.style.border="none",r.setAttribute("sandbox","allow-scripts"),n.appendChild(r),n}var Vo=new Set(["svg","g","path","rect","circle","ellipse","line","polyline","polygon","text","tspan","textpath","defs","use","symbol","clippath","mask","pattern","lineargradient","radialgradient","stop","filter","fegaussianblur","feoffset","femerge","femergenode","fecolormatrix","feblend","title","desc"]);function Wo(e,t){let n=m("div","pf-svg"),r=C(e.content,t);if(!r.includes("<svg"))return n;if(!/<svg[^>]*\sxmlns\s*=/.test(r))r=r.replace(/<svg\b/,'<svg xmlns="http://www.w3.org/2000/svg"');let i=new DOMParser().parseFromString(r,"image/svg+xml").querySelector("svg");if(!i)return n;return gn(i),n.appendChild(document.importNode(i,!0)),n}function gn(e){let t=Array.from(e.children);for(let n of t){if(!Vo.has(n.tagName.toLowerCase())){n.remove();continue}for(let r of Array.from(n.attributes)){let o=r.name.toLowerCase();if(o.startsWith("on")||o==="href"&&r.value.trim().toLowerCase().startsWith("javascript:"))n.removeAttribute(r.name)}gn(n)}}function _o(e,t){let n=(t??"").split(",").map((i)=>i.trim().toLowerCase()).filter(Boolean);if(n.length===0)return!0;let r=e.name.toLowerCase(),o=e.type.toLowerCase();return n.some((i)=>{if(i.startsWith("."))return r.endsWith(i);if(i.endsWith("/*"))return o.startsWith(i.slice(0,-1));return o===i})}function Ko(e,t){let n=m("div","pf-dropzone");n.style.padding="32px",n.style.textAlign="center",n.style.cursor="pointer",n.textContent=C(e.label??"Drop files here",t);let r=document.createElement("input");if(r.type="file",r.style.display="none",e.accept!=null)r.accept=e.accept;if(e.multiple===!0)r.multiple=!0;n.appendChild(r),n.setAttribute("role","button"),n.tabIndex=0;function o(s){let a=Array.from(s??[]).filter((l)=>_o(l,e.accept));return e.multiple===!0?a:a.slice(0,1)}function i(s){if(s.length===0)return;if(e.resultKey!=null)t.store.set(e.resultKey,s),t.rerender();if(e.onDrop!=null)I(j(e.onDrop,{..._(t),scope:{...t.scope,$result:s}}),"onDrop")}return r.addEventListener("change",()=>{i(o(r.files)),r.value=""}),n.addEventListener("click",()=>r.click()),n.addEventListener("keydown",(s)=>{if(s.key==="Enter"||s.key===" ")s.preventDefault(),r.click()}),n.addEventListener("dragover",(s)=>{s.preventDefault(),n.classList.add("pf-dropzone-active")}),n.addEventListener("dragleave",()=>{n.classList.remove("pf-dropzone-active")}),n.addEventListener("drop",(s)=>{s.preventDefault(),n.classList.remove("pf-dropzone-active"),i(o(s.dataTransfer?.files??null))}),n}function Go(e,t){let n=m("div","pf-mermaid");n.setAttribute("data-mermaid","true");let r=C(e.content,t);if(n.textContent=r,typeof globalThis.mermaid<"u")n.classList.add("mermaid"),n.textContent=r;return n}var qo="https://cdn.jsdelivr.net/npm/pdfjs-dist@4.9/build/pdf.min.mjs",Uo="https://cdn.jsdelivr.net/npm/pdfjs-dist@4.9/build/pdf.worker.min.mjs",pt=null,Fe=null;async function Xo(){if(pt)return pt;if(Fe)return Fe;return Fe=import(qo).then((e)=>{let t=e;return t.GlobalWorkerOptions.workerSrc=Uo,pt=t,t}),Fe}function bn(){p("PdfViewer",Yo)}function Yo(e,t){let n=m("div","pf-pdf-viewer"),r=e.src!=null?C(e.src,t):void 0,o=e.data,i=e.page!=null?e.page:1,s=e.zoom!=null?e.zoom:"fit-width",a=e.toolbar!==!1,l=e.height!=null?e.height:600;n.style.height=`${l}px`,n.style.display="flex",n.style.flexDirection="column",n.style.overflow="hidden",n.style.border="1px solid var(--color-border-primary, #e5e7eb)",n.style.borderRadius="var(--border-radius-md, 0.375rem)",n.style.background="var(--color-background-secondary, #f9fafb)";let d=m("div","pf-pdf-loading");return d.textContent="Loading PDF…",d.style.display="flex",d.style.alignItems="center",d.style.justifyContent="center",d.style.flex="1",d.style.color="var(--color-text-secondary, #6b7280)",n.appendChild(d),Zo(n,d,{src:r,data:o,initialPage:i,zoom:s,showToolbar:a}),n}async function Zo(e,t,n){try{let r=await Xo(),o;if(n.src)o={url:n.src};else if(n.data){let g=atob(n.data),h=new Uint8Array(g.length);for(let y=0;y<g.length;y++)h[y]=g.charCodeAt(y);o={data:h}}else{t.textContent="Error: No PDF source provided";return}let i=await r.getDocument(o).promise;t.remove();let s=Math.max(1,Math.min(n.initialPage,i.numPages)),a=null,l=null;if(n.showToolbar){let g=Qo(i.numPages,s,{onPrev:()=>{if(s>1)s--,c()},onNext:()=>{if(s<i.numPages)s++,c()},onPageChange:(h)=>{let y=Math.max(1,Math.min(h,i.numPages));if(y!==s)s=y,c()}});a=g.pageInput,l=g.pageCount,e.insertBefore(g.el,e.firstChild)}let d=m("div","pf-pdf-canvas-container");d.style.flex="1",d.style.overflow="auto",d.style.display="flex",d.style.justifyContent="center",d.style.padding="8px",e.appendChild(d);let u=document.createElement("canvas");u.style.display="block",u.style.boxShadow="var(--shadow-md, 0 4px 6px -1px rgba(0,0,0,.1))",d.appendChild(u);async function c(){let g=await i.getPage(s),h=d.clientWidth-16,y,f=g.getViewport({scale:1});if(n.zoom==="fit-width")y=h/f.width;else if(n.zoom==="fit-page"){let S=d.clientHeight-16,N=h/f.width,k=S/f.height;y=Math.min(N,k)}else y=typeof n.zoom==="number"?n.zoom:1;let b=g.getViewport({scale:y});u.width=b.width,u.height=b.height,u.style.width=`${b.width}px`,u.style.height=`${b.height}px`;let w=u.getContext("2d");if(!w)return;if(await g.render({canvasContext:w,viewport:b}).promise,a)a.value=String(s);if(l)l.textContent=`/ ${i.numPages}`}await c()}catch(r){t.textContent=`PDF Error: ${r instanceof Error?r.message:String(r)}`,t.style.color="var(--color-text-danger, #dc2626)"}}function Qo(e,t,n){let r=m("div","pf-pdf-toolbar");r.style.display="flex",r.style.alignItems="center",r.style.gap="8px",r.style.padding="6px 12px",r.style.borderBottom="1px solid var(--color-border-primary, #e5e7eb)",r.style.background="var(--color-background-primary, #fff)",r.style.flexShrink="0",r.style.fontSize="13px";let o=document.createElement("button");o.textContent="‹",o.title="Previous page",o.className="pf-pdf-btn",hn(o),o.addEventListener("click",n.onPrev);let i=document.createElement("button");i.textContent="›",i.title="Next page",i.className="pf-pdf-btn",hn(i),i.addEventListener("click",n.onNext);let s=document.createElement("input");s.type="number",s.min="1",s.max=String(e),s.value=String(t),s.style.width="48px",s.style.textAlign="center",s.style.border="1px solid var(--color-border-primary, #e5e7eb)",s.style.borderRadius="4px",s.style.padding="2px 4px",s.style.fontSize="13px",s.addEventListener("change",()=>{let l=parseInt(s.value,10);if(!isNaN(l))n.onPageChange(l)});let a=document.createElement("span");return a.textContent=`/ ${e}`,a.style.color="var(--color-text-secondary, #6b7280)",r.appendChild(o),r.appendChild(s),r.appendChild(a),r.appendChild(i),{el:r,pageInput:s,pageCount:a}}function hn(e){e.style.border="1px solid var(--color-border-primary, #e5e7eb)",e.style.borderRadius="4px",e.style.background="var(--color-background-primary, #fff)",e.style.cursor="pointer",e.style.padding="2px 8px",e.style.fontSize="16px",e.style.lineHeight="1"}var Je=["#3b82f6","#10b981","#f59e0b","#ef4444","#8b5cf6","#ec4899"];function pe(e,t){let n=document.createElement("div");return n.className="pf-chart-tooltip",e.appendChild(n),e.addEventListener("mouseleave",()=>{n.classList.remove("pf-visible")}),{wrapper:e,tooltip:n,svgEl:t}}function te(e,t,n,r,o){let{tooltip:i,svgEl:s,wrapper:a}=e;if(o.length===0)return;let l="";if(r)l+=`<div class="pf-chart-tooltip-label">${Be(r)}</div>`;for(let b of o)l+='<div class="pf-chart-tooltip-row">',l+=`<span class="pf-chart-tooltip-dot" style="background:${Be(b.color)}"></span>`,l+=`<span>${Be(b.label)}:</span> <strong>${Be(String(b.value))}</strong>`,l+="</div>";i.innerHTML=l;let d=s.getBoundingClientRect(),u=a.getBoundingClientRect(),c=s.viewBox.baseVal,g=d.width/(c.width||1),h=d.left-u.left+t*g,y=i.offsetWidth||100,f=h+12;if(f+y>u.width)f=h-y-12;i.style.left=`${Math.max(0,f)}px`,i.style.top="4px",i.classList.add("pf-visible")}function Be(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function yn(e,t,n,r,o,i,s,a){let l=o.plotWidth/n.length;for(let d=0;d<n.length;d++){let u=o.plotLeft+d*l,c=document.createElementNS("http://www.w3.org/2000/svg","rect");c.setAttribute("x",String(u)),c.setAttribute("y",String(o.plotTop)),c.setAttribute("width",String(l)),c.setAttribute("height",String(o.plotHeight)),c.setAttribute("fill","transparent"),c.style.cursor="default";let g=i?n[d][i]:void 0,h=g!=null?a?a(g):L(g):void 0,y=r.map((S,N)=>({label:S.label??S.dataKey,value:s(n[d][S.dataKey],S,N),color:S.color??Je[N%Je.length]})),f=u+l/2,b=()=>te(e,f,o.plotTop,h,y),w=()=>e.tooltip.classList.remove("pf-visible");c.addEventListener("mouseenter",b),c.addEventListener("mouseleave",w),c.addEventListener("touchstart",b,{passive:!0}),c.addEventListener("touchend",w,{passive:!0}),t.appendChild(c)}}function Cn(e,t,n,r,o,i,s,a,l,d){let u=n.length===1?o.plotWidth:o.plotWidth/(n.length-1);for(let c=0;c<n.length;c++){let g=n.length===1?(o.plotLeft+o.plotRight)/2:o.plotLeft+c/(n.length-1)*o.plotWidth,h=n.length===1?o.plotLeft:g-u/2,y=n.length===1?o.plotWidth:u,f=document.createElementNS("http://www.w3.org/2000/svg","rect");f.setAttribute("x",String(Math.max(o.plotLeft,h))),f.setAttribute("y",String(o.plotTop)),f.setAttribute("width",String(Math.min(y,o.plotRight-Math.max(o.plotLeft,h)))),f.setAttribute("height",String(o.plotHeight)),f.setAttribute("fill","transparent"),f.style.cursor="default";let b=i?n[c][i]:void 0,w=b!=null?d?d(b):L(b):void 0,S=r.map((R,P)=>({label:R.label??R.dataKey,value:s(n[c][R.dataKey],R,P),color:R.color??Je[P%Je.length]})),N=()=>{if(te(e,g,o.plotTop,w,S),a)a.setAttribute("x1",String(g)),a.setAttribute("x2",String(g)),a.setAttribute("opacity","1");if(l)for(let R of l){for(let P of R)P.setAttribute("data-visible","false");R[c]?.setAttribute("data-visible","true")}},k=()=>{if(e.tooltip.classList.remove("pf-visible"),a)a.setAttribute("opacity","0");if(l)for(let R of l)for(let P of R)P.setAttribute("data-visible","false")};f.addEventListener("mouseenter",N),f.addEventListener("mouseleave",k),f.addEventListener("touchstart",N,{passive:!0}),f.addEventListener("touchend",k,{passive:!0}),t.appendChild(f)}}var q=["#3b82f6","#10b981","#f59e0b","#ef4444","#8b5cf6","#ec4899"],re="var(--muted-foreground, #6b7280)",Ce="var(--border, #e5e7eb)",ue="10";function ze(e,t,n,r=!1){let o=n?44:0,i=e-(r?44:0),s=10,a=t-24;return{plotLeft:o,plotRight:i,plotTop:10,plotBottom:a,plotWidth:i-o,plotHeight:a-10}}function vn(e,t=5){if(e<=0)return[0];let n=e/t,r=Math.pow(10,Math.floor(Math.log10(n))),o=n/r,i=o<=1.5?r:o<=3?2*r:o<=7?5*r:10*r,s=[];for(let a=0;a<=e+i*0.01;a+=i)s.push(Math.round(a*1000)/1000);return s}function ut(e,t,n,r,o){let i=vn(n);for(let s of i){let a=t.plotBottom-(n>0?s/n*t.plotHeight:0),l=U("text",{x:t.plotLeft-6,y:a+3,"text-anchor":"end","font-size":ue,fill:re});if(l.textContent=gt(s,o),e.appendChild(l),r&&s>0)e.appendChild(U("line",{x1:t.plotLeft,y1:a,x2:t.plotRight,y2:a,stroke:Ce,"stroke-width":1,"stroke-dasharray":"4 3"}))}}function ft(e,t,n,r){let o=vn(n);for(let i of o){let s=t.plotBottom-(n>0?i/n*t.plotHeight:0),a=U("text",{x:t.plotRight+6,y:s+3,"text-anchor":"start","font-size":ue,fill:re});a.textContent=gt(i,r),e.appendChild(a)}}function mt(e,t,n,r,o,i){for(let s=0;s<t.length;s++){let a=t[s][n],l=U("text",{x:r(s),y:o+14,"text-anchor":"middle","font-size":ue,fill:re});l.textContent=a==null?"":i?i(a):L(a),e.appendChild(l)}}function Ve(e,t){e.appendChild(U("line",{x1:t.plotLeft,y1:t.plotBottom,x2:t.plotRight,y2:t.plotBottom,stroke:re,"stroke-width":1}))}function ne(e,t,n){if(e==null)return"";let r=K(`{{ __v | ${t} }}`,{...n,scope:{...n.scope,__v:e}});return L(r??e)}function gt(e,t){if(t==="currency")return`$${e.toLocaleString()}`;if(t==="percent")return`${e}%`;if(e>=1e6)return`${(e/1e6).toFixed(1)}M`;if(e>=1000)return`${(e/1000).toFixed(1)}K`;return String(e)}function oe(e){let t=e.yAxisFormat??e.valueFormat;return t&&t!=="auto"?t:void 0}function ht(e,t,n){return(r,o)=>{if(r===null||r===void 0)return"—";if(o.tooltipFormat)return ne(r,o.tooltipFormat,e);let i=o.yAxisId==="right"?n:t;return gt(Number(r),i)}}function le(e,t,n){let r=document.createElementNS("http://www.w3.org/2000/svg","svg");if(r.setAttribute("width","100%"),r.setAttribute("height",String(t)),r.setAttribute("viewBox",`0 0 ${e} ${t}`),r.setAttribute("role","img"),n)r.setAttribute("aria-label",`${n} chart`);return r.style.overflow="visible",r}function U(e,t){let n=document.createElementNS("http://www.w3.org/2000/svg",e);for(let[r,o]of Object.entries(t))n.setAttribute(r,String(o));return n}function We(e,t){let n=U("text",e);return n.textContent=t,n}function fe(e,t,n,r){let o=r*Math.PI/180;return{x:e+n*Math.cos(o),y:t-n*Math.sin(o)}}function bt(e,t,n,r,o){let i=Math.max(2,Math.ceil(Math.abs(o-r)/4)),s=[];for(let a=0;a<=i;a++){let l=fe(e,t,n,r+(o-r)*a/i);s.push(`${a===0?"M":"L"} ${l.x.toFixed(2)} ${l.y.toFixed(2)}`)}return s.join(" ")}function me(e,t,n){if(n===!1||t.length<=1)return;let r=m("div","pf-chart-legend");r.style.display="flex",r.style.gap="12px",r.style.fontSize="12px",r.style.marginBottom="8px";for(let o=0;o<t.length;o++){let i=m("div","pf-chart-legend-item");i.style.display="flex",i.style.alignItems="center",i.style.gap="4px";let s=m("span");s.style.width="8px",s.style.height="8px",s.style.borderRadius="50%",s.style.backgroundColor=t[o].color??q[o%q.length];let a=m("span");a.textContent=t[o].label??t[o].dataKey,i.appendChild(s),i.appendChild(a),r.appendChild(i)}e.appendChild(r)}function xn(){p("BarChart",ei),p("LineChart",wn),p("AreaChart",wn),p("PieChart",ti),p("RadarChart",oi),p("ScatterChart",ni),p("RadialChart",ri),p("Histogram",ii)}function ei(e,t){let n=m("div","pf-chart pf-bar-chart"),r=K(e.data,t)??[],o=e.series??[],i=e.height??300;if(r.length===0||o.length===0)return n.textContent="No chart data",n;let s=e.showYAxis!==!1,a=e.showGrid===!0,l=e.showYAxisRight===!0,d=e.showTooltip!==!1,u=e.xAxis,c=e.tooltipXKey,g=e.xAxisFormat,h=e.tooltipXFormat,y=o.filter((x)=>x.yAxisId!=="right"),f=o.filter((x)=>x.yAxisId==="right"),b=l&&f.length>0,w=y.length>0?Math.max(...r.flatMap((x)=>y.map((v)=>Number(x[v.dataKey]??0))),1):1,S=b?Math.max(...r.flatMap((x)=>f.map((v)=>Number(x[v.dataKey]??0))),1):1,N=400,k=ze(N,i,s,b),R=le(N,i,"Bar");if(s)ut(R,k,w,a,oe(e));if(b)ft(R,k,S,e.yAxisRightFormat);Ve(R,k);let P=k.plotWidth/r.length,M=P/(o.length+1);for(let x=0;x<r.length;x++)for(let v=0;v<o.length;v++){let T=o[v],D=r[x][T.dataKey];if(D===null||D===void 0)continue;let G=T.yAxisId==="right"?S:w,B=Number(D),A=Math.max(0,B/G*k.plotHeight),V=k.plotLeft+x*P+v*M+M/2,E=document.createElementNS("http://www.w3.org/2000/svg","rect");E.setAttribute("x",String(V)),E.setAttribute("y",String(k.plotBottom-A)),E.setAttribute("width",String(M*0.8)),E.setAttribute("height",String(A)),E.setAttribute("fill",T.color??q[v%q.length]),E.setAttribute("rx","2"),R.appendChild(E)}if(u){let x=g?(v)=>ne(v,g,t):void 0;mt(R,r,u,(v)=>k.plotLeft+v*P+P/2,k.plotBottom,x)}if(d){let x=pe(n,R),v=ht(t,oe(e),e.yAxisRightFormat);yn(x,R,r,o,k,c??u,v,h?(D)=>ne(D,h,t):void 0)}return me(n,o,e.showLegend),n.appendChild(R),n}function wn(e,t){let n=m("div",`pf-chart pf-${e.type.toLowerCase()}-chart`),r=K(e.data,t)??[],o=e.series??[],i=e.height??300;if(r.length===0||o.length===0)return n.textContent="No chart data",n;let s=e.showYAxis!==!1,a=e.showGrid===!0,l=e.showYAxisRight===!0,d=e.showTooltip!==!1,u=e.xAxis,c=e.tooltipXKey,g=e.xAxisFormat,h=e.tooltipXFormat,y=o.filter((v)=>v.yAxisId!=="right"),f=o.filter((v)=>v.yAxisId==="right"),b=l&&f.length>0,w=y.length>0?Math.max(...r.flatMap((v)=>y.map((T)=>Number(v[T.dataKey]??0))),1):1,S=b?Math.max(...r.flatMap((v)=>f.map((T)=>Number(v[T.dataKey]??0))),1):1,N=400,k=ze(N,i,s,b),R=le(N,i,e.type==="AreaChart"?"Area":"Line"),P=e.type==="AreaChart";if(s)ut(R,k,w,a,oe(e));if(b)ft(R,k,S,e.yAxisRightFormat);Ve(R,k);let M=[];for(let v=0;v<o.length;v++){let T=o[v],D=T.yAxisId==="right",z=D?S:w,G=T.color??q[v%q.length],B=r.map((E,F)=>{let W=E[T.dataKey],X=W===null||W===void 0,de=r.length===1?(k.plotLeft+k.plotRight)/2:k.plotLeft+F/(r.length-1)*k.plotWidth,zn=X?k.plotBottom:k.plotBottom-Number(W)/z*k.plotHeight;return{x:de,y:zn,isNull:X}});if(P){let E=[],F=()=>{if(E.length<2){E=[];return}let W=`M ${E[0].x},${k.plotBottom} `+E.map((de)=>`L ${de.x},${de.y}`).join(" ")+` L ${E[E.length-1].x},${k.plotBottom} Z`,X=document.createElementNS("http://www.w3.org/2000/svg","path");X.setAttribute("d",W),X.setAttribute("fill",G),X.setAttribute("opacity","0.15"),R.appendChild(X),E=[]};for(let W of B){if(W.isNull){F();continue}E.push(W)}F()}let A="";for(let E of B){if(E.isNull)continue;let F=B.indexOf(E),W=F===0||B[F-1].isNull;A+=`${W?"M":"L"} ${E.x},${E.y} `}if(A){let E=document.createElementNS("http://www.w3.org/2000/svg","path");if(E.setAttribute("d",A.trim()),E.setAttribute("fill","none"),E.setAttribute("stroke",G),E.setAttribute("stroke-width","2"),D)E.setAttribute("stroke-dasharray","6 3");R.appendChild(E)}let V=[];for(let E of B){let F=document.createElementNS("http://www.w3.org/2000/svg","circle");if(F.setAttribute("cx",String(E.x)),F.setAttribute("cy",String(E.y)),F.setAttribute("r","4"),F.setAttribute("fill",G),F.setAttribute("class","pf-data-dot"),F.setAttribute("data-visible","false"),F.style.pointerEvents="none",E.isNull)F.style.display="none";R.appendChild(F),V.push(F)}M.push(V)}let x=document.createElementNS("http://www.w3.org/2000/svg","line");if(x.setAttribute("class","pf-crosshair"),x.setAttribute("x1",String(k.plotLeft)),x.setAttribute("x2",String(k.plotLeft)),x.setAttribute("y1",String(k.plotTop)),x.setAttribute("y2",String(k.plotBottom)),x.setAttribute("stroke",re),x.setAttribute("stroke-width","1"),x.setAttribute("stroke-dasharray","3 3"),x.setAttribute("opacity","0"),R.appendChild(x),u){let v=g?(T)=>ne(T,g,t):void 0;mt(R,r,u,(T)=>r.length===1?(k.plotLeft+k.plotRight)/2:k.plotLeft+T/(r.length-1)*k.plotWidth,k.plotBottom,v)}if(d){let v=pe(n,R),T=ht(t,oe(e),e.yAxisRightFormat);Cn(v,R,r,o,k,c??u,T,x,M,h?(z)=>ne(z,h,t):void 0)}return me(n,o,e.showLegend),n.appendChild(R),n}function ti(e,t){let n=m("div","pf-chart pf-pie-chart"),r=K(e.data,t)??[],o=e.series??[],i=e.height??300,s=Math.min(i,300),a=e.showTooltip!==!1,l=e.dataKey??o[0]?.dataKey,d=e.nameKey??e.tooltipXKey??e.xAxis,u=o.length>0?o:l?[{dataKey:l,label:l}]:[];if(r.length===0||!l)return n.textContent="No chart data",n;let c=le(s,s,"Pie"),g=s/2,h=s/2,y=s/2-10,f=e.tooltipXFormat,b=oe(e),w=(P)=>b?ne(P,b,t):String(P),S=r.map((P)=>Number(P[l]??0)),N=S.reduce((P,M)=>P+M,0);if(N===0)return n.textContent="No chart data",n.appendChild(c),n;let k=a?pe(n,c):void 0,R=-Math.PI/2;for(let P=0;P<S.length;P++){let M=S[P]/N*2*Math.PI,x=R+M,v=M>Math.PI?1:0,T=g+y*Math.cos(R),D=h+y*Math.sin(R),z=g+y*Math.cos(x),G=h+y*Math.sin(x),B=q[P%q.length],A=document.createElementNS("http://www.w3.org/2000/svg","path");if(A.setAttribute("d",`M ${g},${h} L ${T},${D} A ${y},${y} 0 ${v} 1 ${z},${G} Z`),A.setAttribute("fill",B),A.style.cursor="default",k){let V=d?r[P][d]:void 0,E=V!=null?f?ne(V,f,t):L(V):`Slice ${P+1}`,F=`${(S[P]/N*100).toFixed(1)}%`,W=R+M/2,X=g+y*0.6*Math.cos(W);A.addEventListener("mouseenter",()=>{te(k,X,h,E,[{label:u[0].label??l,value:`${w(S[P])} (${F})`,color:B}])}),A.addEventListener("mouseleave",()=>{k.tooltip.classList.remove("pf-visible")}),A.addEventListener("touchstart",()=>{te(k,X,h,E,[{label:u[0].label??l,value:`${w(S[P])} (${F})`,color:B}])},{passive:!0}),A.addEventListener("touchend",()=>{k.tooltip.classList.remove("pf-visible")},{passive:!0})}c.appendChild(A),R=x}return me(n,u,e.showLegend),n.appendChild(c),n}function ni(e,t){let n=m("div","pf-chart pf-scatter-chart"),r=K(e.data,t)??[],o=e.xAxis,i=e.yAxis,s=e.zAxis,a=e.series??[],l=e.height??300;if(r.length===0||!o||!i)return n.textContent="No chart data",n;let d=e.showGrid!==!1,u=e.showTooltip!==!1,c=a[0]?.color??q[0],g=oe(e),h=(A)=>g?ne(A,g,t):String(Math.round(A*100)/100),y=r.map((A)=>Number(A[o]??0)),f=r.map((A)=>Number(A[i]??0)),b=Math.min(...y),w=Math.max(...y),S=Math.min(...f),N=Math.max(...f),k=w-b||1,R=N-S||1,P=s?r.map((A)=>Number(A[s]??0)):[],M=s?Math.max(...P,1):1,x=400,v=ze(x,l,!0),T=le(x,l,"Scatter"),D=(A)=>v.plotLeft+(A-b)/k*v.plotWidth,z=(A)=>v.plotBottom-(A-S)/R*v.plotHeight,G=4;for(let A=0;A<=G;A++){let V=S+R*A/G,E=z(V);if(T.appendChild(We({x:v.plotLeft-6,y:E+3,"text-anchor":"end","font-size":ue,fill:re},h(V))),d&&A>0)T.appendChild(U("line",{x1:v.plotLeft,y1:E,x2:v.plotRight,y2:E,stroke:Ce,"stroke-width":1,"stroke-dasharray":"4 3"}))}Ve(T,v);for(let A of[b,(b+w)/2,w])T.appendChild(We({x:D(A),y:v.plotBottom+14,"text-anchor":"middle","font-size":ue,fill:re},String(Math.round(A*100)/100)));let B=u?pe(n,T):void 0;for(let A=0;A<r.length;A++){let V=D(y[A]),E=z(f[A]),F=s?4+Math.sqrt(P[A]/M)*14:4,W=U("circle",{cx:V,cy:E,r:F,fill:c,"fill-opacity":s?0.6:0.85});if(B){let X=[{label:o,value:h(y[A]),color:c},{label:i,value:h(f[A]),color:c},...s?[{label:s,value:h(P[A]),color:c}]:[]],de=a[0]?.label??"Point";W.addEventListener("mouseenter",()=>te(B,V,E,de,X)),W.addEventListener("mouseleave",()=>B.tooltip.classList.remove("pf-visible")),W.addEventListener("touchstart",()=>te(B,V,E,de,X),{passive:!0}),W.addEventListener("touchend",()=>B.tooltip.classList.remove("pf-visible"),{passive:!0})}T.appendChild(W)}return me(n,a,e.showLegend),n.appendChild(T),n}function ri(e,t){let n=m("div","pf-chart pf-radial-chart"),r=K(e.data,t)??[],o=e.series??[],i=e.dataKey??o[0]?.dataKey,s=e.nameKey??e.tooltipXKey??e.xAxis,a=e.height??300;if(r.length===0||!i)return n.textContent="No chart data",n;let l=Math.min(a,300),d=l/2,u=l/2,c=l/2-10,g=Math.max(0,Math.min(e.innerRadius??30,c-10)),h=e.startAngle??180,y=e.endAngle??0,f=e.showTooltip!==!1,b=r.map((v)=>Number(v[i]??0)),w=Math.max(...b,1),S=le(l,l,"Radial"),N=(c-g)/r.length,k=Math.max(2,N*0.7),R=oe(e),P=(v)=>R?ne(v,R,t):String(v),M=f?pe(n,S):void 0,x=[];for(let v=0;v<r.length;v++){let T=c-N*v-N/2,D=o[v]?.color??q[v%q.length],z=b[v]/w,G=h+z*(y-h),B=s?r[v][s]:null,A=B!=null?L(B):o[v]?.label??i;x.push({dataKey:A||i,label:A||i,color:D}),S.appendChild(U("path",{d:bt(d,u,T,h,y),fill:"none",stroke:Ce,"stroke-width":k,"stroke-linecap":"round"}));let V=U("path",{d:bt(d,u,T,h,G),fill:"none",stroke:D,"stroke-width":k,"stroke-linecap":"round"});if(M){let E=fe(d,u,T,(h+G)/2),F=[{label:i,value:P(b[v]),color:D}],W=A||i;V.addEventListener("mouseenter",()=>te(M,E.x,E.y,W,F)),V.addEventListener("mouseleave",()=>M.tooltip.classList.remove("pf-visible")),V.addEventListener("touchstart",()=>te(M,E.x,E.y,W,F),{passive:!0}),V.addEventListener("touchend",()=>M.tooltip.classList.remove("pf-visible"),{passive:!0})}S.appendChild(V)}return me(n,x,e.showLegend),n.appendChild(S),n}function oi(e,t){let n=m("div","pf-chart pf-radar-chart"),r=K(e.data,t)??[],o=e.series??[],i=e.axisKey??e.xAxis,s=e.height??300;if(r.length===0||o.length===0)return n.textContent="No chart data",n;let a=e.filled!==!1,l=e.showDots===!0,d=e.showGrid!==!1,u=e.showTooltip!==!1,c=Math.min(s,320),g=c/2,h=c/2,y=c/2-24,f=r.length,b=Math.max(...r.flatMap((M)=>o.map((x)=>Number(M[x.dataKey]??0))),1),w=(M)=>90-360*M/f,S=(M)=>M.map((x)=>`${x.x.toFixed(1)},${x.y.toFixed(1)}`).join(" "),N=le(c,c,"Radar");if(d){for(let x=1;x<=4;x++){let v=y*x/4,T=Array.from({length:f},(D,z)=>fe(g,h,v,w(z)));N.appendChild(U("polygon",{points:S(T),fill:"none",stroke:Ce,"stroke-width":1}))}for(let x=0;x<f;x++){let v=fe(g,h,y,w(x));N.appendChild(U("line",{x1:g,y1:h,x2:v.x,y2:v.y,stroke:Ce,"stroke-width":1}))}}for(let M=0;M<f;M++){let x=fe(g,h,y+12,w(M)),v=i?r[M][i]:null;N.appendChild(We({x:x.x,y:x.y+3,"text-anchor":"middle","font-size":ue,fill:re},v!=null?String(v):""))}let k=u?pe(n,N):void 0,R=oe(e),P=(M)=>R?ne(M,R,t):String(M);for(let M=0;M<o.length;M++){let x=o[M],v=x.color??q[M%q.length],T=r.map((D,z)=>fe(g,h,Number(D[x.dataKey]??0)/b*y,w(z)));if(N.appendChild(U("polygon",{points:S(T),fill:a?v:"none","fill-opacity":a?0.2:0,stroke:v,"stroke-width":2})),l||k)for(let D=0;D<T.length;D++){let z=U("circle",{cx:T[D].x,cy:T[D].y,r:l?3:6,fill:l?v:"transparent","fill-opacity":l?1:0});if(k){let G=i?r[D][i]:null,B=G!=null?L(G):x.label??x.dataKey,A=[{label:x.label??x.dataKey,value:P(Number(r[D][x.dataKey]??0)),color:v}];z.addEventListener("mouseenter",()=>te(k,T[D].x,T[D].y,B,A)),z.addEventListener("mouseleave",()=>k.tooltip.classList.remove("pf-visible")),z.addEventListener("touchstart",()=>te(k,T[D].x,T[D].y,B,A),{passive:!0}),z.addEventListener("touchend",()=>k.tooltip.classList.remove("pf-visible"),{passive:!0})}N.appendChild(z)}}return me(n,o,e.showLegend),n.appendChild(N),n}function ii(e,t){let n=m("div","pf-chart pf-histogram"),r=K(e.data,t);if(!r||r.length===0)return n.textContent="No data",n;let o=r,i=e.bins??10,s=e.height??200,a=e.color??q[0],l=Math.min(...o),u=(Math.max(...o)-l)/i||1,c=Array(i).fill(0);for(let w of o){let S=Math.min(Math.floor((w-l)/u),i-1);c[S]++}let g=Math.max(...c),h=300,y=s,f=h/i,b=le(h,y,"Histogram");for(let w=0;w<i;w++){let S=g>0?c[w]/g*y:0,N=document.createElementNS("http://www.w3.org/2000/svg","rect");N.setAttribute("x",String(w*f)),N.setAttribute("y",String(y-S)),N.setAttribute("width",String(f-1)),N.setAttribute("height",String(S)),N.setAttribute("fill",a),b.appendChild(N)}return n.appendChild(b),n}function kn(){p("Table",si),p("TableHead",yt("thead")),p("TableBody",yt("tbody")),p("TableFooter",yt("tfoot")),p("TableRow",ai),p("TableHeader",li),p("TableCell",di),p("TableCaption",ci),p("ExpandableRow",pi)}function si(e,t){let n=document.createElement("table");return n.className=e.striped===!0?"pf-table pf-table-striped":"pf-table",n.style.width="100%",n.style.borderCollapse="collapse",H(e,n,t),n}function yt(e){return(t,n)=>{let r=document.createElement(e);return r.className=`pf-${e}`,H(t,r,n),r}}function ai(e,t){let n=document.createElement("tr");return n.className="pf-table-row",H(e,n,t),n}function li(e,t){let n=document.createElement("th");return n.className="pf-table-header",n.style.textAlign="left",n.style.padding="8px 12px",n.style.fontWeight="600",n.textContent=C(e.content,t),n}function di(e,t){let n=document.createElement("td");if(n.className="pf-table-cell",n.style.padding="8px 12px",e.colSpan!=null)n.colSpan=e.colSpan;if(e.rowSpan!=null)n.rowSpan=e.rowSpan;return H(e,n,t),n}function ci(e,t){let n=document.createElement("caption");return n.className="pf-table-caption",n.style.padding="8px",n.style.fontSize="14px",n.textContent=C(e.content,t),n}function pi(e,t){let n=m("div","pf-expandable-row"),r=m("div","pf-expandable-row-summary");r.style.cursor="pointer",r.style.display="flex",r.style.alignItems="center",r.style.gap="8px";let o=m("span","pf-expandable-arrow");o.textContent="▶",o.style.transition="transform 0.2s",o.style.fontSize="10px",r.appendChild(o);let i=e.summary;if(i)for(let l of i)r.appendChild(J(l,t));let s=m("div","pf-expandable-row-detail");s.style.display="none",s.style.paddingLeft="24px",H(e,s,t);let a=!1;return r.addEventListener("click",()=>{a=!a,s.style.display=a?"block":"none",o.style.transform=a?"rotate(90deg)":""}),n.appendChild(r),n.appendChild(s),n}var Sn=!1;function _e(){if(Sn)return;Sn=!0;let e=new Set(at());Xt(),en(),rn(),on(),sn(),ln(),dn(),cn(),fn(),mn(),bn(),xn(),kn(),Kt(at().filter((t)=>!e.has(t)))}function vt(e){return e.replace(/[^a-zA-Z0-9_-]/g,"")}function wt(e){return e.replace(/[{}<>;]/g,"").replace(/\b(url|expression)\s*\(/gi,"")}function Ct(e,t=" "){return Object.entries(e).map(([n,r])=>`${t}--${vt(n)}: ${wt(r)};`).join(`
7
+ `)}function An(e){if(!e)return"";let t=[];if(e.light&&Object.keys(e.light).length>0)t.push(`:root {
8
+ ${Ct(e.light)}
9
+ }`);if(e.dark&&Object.keys(e.dark).length>0){let n=Ct(e.dark);t.push(`.dark, [data-theme="dark"] {
10
10
  ${n}
11
11
  }`),t.push(`@media (prefers-color-scheme: dark) {
12
12
  :root:not([data-theme="light"]):not(.light) {
13
- ${bt(e.dark," ")}
13
+ ${Ct(e.dark," ")}
14
14
  }
15
15
  }`)}return t.join(`
16
- `)}function be(e,t){e.setAttribute("data-theme",t),e.classList.toggle("dark",t==="dark"),e.classList.toggle("light",t==="light")}function vt(e,t){if(!t)return;if(t.light)for(let[n,r]of Object.entries(t.light))e.style.setProperty(`--${yt(n)}`,Ct(r));if(t.dark){let r=document.getElementById("prefab-dark-theme");if(!r)r=document.createElement("style"),r.id="prefab-dark-theme",document.head.appendChild(r);r.textContent=kn({dark:t.dark})}}function wt(e,t){if(!e||typeof document>"u")return;let n=(r)=>{for(let[o,i]of Object.entries(e))if(li(o,r))r.preventDefault(),t(i)};return document.addEventListener("keydown",n),()=>document.removeEventListener("keydown",n)}function li(e,t){let n=e.toLowerCase().split("+").map((i)=>i.trim()),r=n[n.length-1],o=new Set(n.slice(0,-1));if(o.has("ctrl")!==(t.ctrlKey||t.metaKey))return!1;if(o.has("shift")!==t.shiftKey)return!1;if(o.has("alt")!==t.altKey)return!1;return t.key.toLowerCase()===r}var Sn='<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M12 3v2.25m6.364.386-1.591 1.591M21 12h-2.25m-.386 6.364-1.591-1.591M12 18.75V21m-4.773-4.227-1.591 1.591M5.25 12H3m4.227-4.773L5.636 5.636M15.75 12a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0Z"/></svg>',En='<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M21.752 15.002A9.72 9.72 0 0 1 18 15.75c-5.385 0-9.75-4.365-9.75-9.75 0-1.33.266-2.597.748-3.752A9.753 9.753 0 0 0 3 11.25C3 16.635 7.365 21 12.75 21a9.753 9.753 0 0 0 9.002-5.998Z"/></svg>',An={"top-right":"top: 8px; right: 8px;","top-left":"top: 8px; left: 8px;","bottom-right":"bottom: 8px; right: 8px;","bottom-left":"bottom: 8px; left: 8px;"};function di(e,t){try{let r=localStorage.getItem(t);if(r==="light"||r==="dark")return r}catch{}let n=e.getAttribute("data-theme")??document.documentElement.getAttribute("data-theme");if(n==="light"||n==="dark")return n;if(typeof window<"u"&&window.matchMedia("(prefers-color-scheme: light)").matches)return"light";return"dark"}function xt(e,t){if(typeof document>"u")return()=>{};let n=t?.position??"top-right",r=t?.storageKey??"prefab-theme",o=t?.syncDocument??!0,i=getComputedStyle(e).position;if(i==="static"||i==="")e.style.position="relative";let s=document.createElement("button");s.className="pf-theme-toggle",s.setAttribute("aria-label","Toggle theme"),s.setAttribute("title","Toggle light/dark"),Object.assign(s.style,{position:"absolute",zIndex:"100",width:"28px",height:"28px",border:"1px solid var(--border, #e5e7eb)",borderRadius:"6px",background:"var(--card, rgba(255,255,255,0.8))",color:"var(--foreground, #333)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",padding:"0",opacity:"0.7",transition:"opacity 0.15s, border-color 0.15s"});let a=An[n]??An["top-right"];for(let d of a.split(";")){let[g,h]=d.split(":").map((y)=>y.trim());if(g&&h)s.style.setProperty(g,h)}s.addEventListener("mouseenter",()=>{s.style.opacity="1"}),s.addEventListener("mouseleave",()=>{s.style.opacity="0.7"});function l(d){if(be(e,d),o)be(document.documentElement,d);s.innerHTML=d==="dark"?En:Sn;try{localStorage.setItem(r,d)}catch{}}let c=di(e,r);l(c),s.addEventListener("click",()=>{let d=e.getAttribute("data-theme")??"dark";l(d==="dark"?"light":"dark")}),e.appendChild(s);let u;if(o)u=new MutationObserver((d)=>{for(let g of d)if(g.type==="attributes"&&g.attributeName==="data-theme"){let h=document.documentElement.getAttribute("data-theme");if((h==="light"||h==="dark")&&h!==e.getAttribute("data-theme")){be(e,h),s.innerHTML=h==="dark"?En:Sn;try{localStorage.setItem(r,h)}catch{}}}}),u.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});return()=>{u?.disconnect(),s.remove()}}function _e(e){let t=e?.baseUrl??(typeof window<"u"?window.location.origin:""),n={"Content-Type":"application/json",...e?.headers},r=e?.fetch??globalThis.fetch.bind(globalThis);return{async callTool(o,i){let s=await r(`${t}/mcp/tools/call`,{method:"POST",headers:n,body:JSON.stringify({jsonrpc:"2.0",method:"tools/call",params:{name:o,arguments:i}})});if(!s.ok)throw Error(`MCP tool call failed: ${s.status} ${s.statusText}`);let a=await s.json();if(a.error)throw Error(a.error.message??"MCP tool call returned error");let l=a.result?.content??a.content??[];for(let c of l)if(c.type==="text"&&c.text!==void 0){try{let u=JSON.parse(c.text);if(typeof u==="object"&&u!==null&&"$prefab"in u)return u;return u}catch{}return c.text}return a.result??a},async sendMessage(o){await r(`${t}/mcp/messages`,{method:"POST",headers:n,body:JSON.stringify({message:o})})}}}function Ve(){return{callTool(e){return O.warn(`No MCP transport: callTool('${e}') ignored`),Promise.resolve(null)},sendMessage(e){return O.warn("No MCP transport: sendMessage ignored",e),Promise.resolve()}}}var Rn="0.3.11";function ci(e){return e!==null&&typeof e==="object"&&e.jsonrpc==="2.0"}class xe{hostOrigin;listeners=new Map;protocol="prefab";cleanup;pending=new Map;callIdCounter=0;rpcPending=new Map;rpcIdCounter=0;sentRpcIds=new Set;postFn;_hostSupportsSubscriptions=!1;constructor(e="*"){this.hostOrigin=e}connect(){if(typeof window>"u")return;let e=fi();if(e)this.postFn=(n)=>e.postMessage(n);let t=(n)=>{if(this.hostOrigin!=="*"&&n.origin!==this.hostOrigin)return;let r=n.data;if(ci(r)){this.handleJsonRpc(r);return}let o=r;if(!o?.type.startsWith("prefab:"))return;if(o.type==="prefab:tool-call-response"&&o.id){let s=this.pending.get(o.id);if(s){if(this.pending.delete(o.id),o.payload?.error!=null)s.reject(Error(o.payload.error));else s.resolve(o.payload?.result);return}}let i=this.listeners.get(o.type);if(i)for(let s of i)s(o.payload??{})};window.addEventListener("message",t),this.cleanup=()=>window.removeEventListener("message",t)}async initialize(e){try{return await Promise.any([this.initPrefab(e),this.initJsonRpc(e)])}catch(t){let n=t instanceof AggregateError?t.errors.map((r)=>r.message).join("; "):String(t);throw Error(`Bridge init failed — no host responded. Tried: ${n}`,{cause:t})}}createTransport(){if(this.protocol==="jsonrpc")return this.createJsonRpcTransport();return this.createPrefabTransport()}requestMode(e){if(this.protocol==="jsonrpc")this.sendRpcRequest("ui/request-display-mode",{mode:e});else this.sendPrefab("prefab:request-mode",{mode:e})}openLink(e,t){if(this.protocol==="jsonrpc")this.sendRpcRequest("ui/open-link",{url:e,target:t});else this.sendPrefab("prefab:open-link",{url:e,target:t})}updateContext(e){if(this.protocol==="jsonrpc")this.sendRpcRequest("ui/update-model-context",{structuredContent:e});else this.sendPrefab("prefab:update-context",{context:e})}setupAutoResize(e){if(typeof ResizeObserver>"u")return pi;let t=-1,n=-1,r=(s,a)=>{if(s===t&&a===n)return;if(t=s,n=a,this.protocol==="jsonrpc")this.sendRpcNotification("ui/notifications/size-changed",{width:s,height:a});else this.sendPrefab("prefab:size-changed",{width:s,height:a})},o=new ResizeObserver((s)=>{for(let a of s)if(a.borderBoxSize.length){let l=a.borderBoxSize[0];r(Math.ceil(l.inlineSize),Math.ceil(l.blockSize))}else{let l=a.target.getBoundingClientRect();r(Math.ceil(l.width),Math.ceil(l.height))}});o.observe(e);let i=e.getBoundingClientRect();return r(Math.ceil(i.width),Math.ceil(i.height)),()=>o.disconnect()}notifyPreferredSize(e){if(this.protocol==="jsonrpc")this.sendRpcNotification("ui/notifications/preferred-size",e);else this.sendPrefab("prefab:preferred-size",e)}subscribe(e,t){let n=(r)=>{if(r.uri!==e)return;t(r.contents??r.data??r)};if(this.protocol==="jsonrpc")this.on("prefab:resource-updated",n),this.sendRpcRequest("resources/subscribe",{uri:e});else this.on("prefab:resource-updated",n),this.sendPrefab("prefab:subscribe",{uri:e});return()=>{if(this.off("prefab:resource-updated",n),this.protocol==="jsonrpc")this.sendRpcRequest("resources/unsubscribe",{uri:e});else this.sendPrefab("prefab:unsubscribe",{uri:e})}}get supportsSubscriptions(){return this._hostSupportsSubscriptions}on(e,t){if(!this.listeners.has(e))this.listeners.set(e,new Set);let n=this.listeners.get(e);if(n)n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}disconnect(){this.cleanup?.(),this.listeners.clear();for(let[,e]of this.pending)e.reject(Error("Bridge disconnected"));this.pending.clear();for(let[,e]of this.rpcPending)e.reject(Error("Bridge disconnected"));this.rpcPending.clear(),this.sentRpcIds.clear()}get activeProtocol(){return this.protocol}initPrefab(e){return new Promise((t,n)=>{let r=!1,o=(i)=>{if(r)return;r=!0,this.off("prefab:init-response",o),this.protocol="prefab";let s=i.capabilities;this._hostSupportsSubscriptions=s?.subscriptions===!0,t(i)};this.on("prefab:init-response",o),this.sendPrefab("prefab:init",{capabilities:e}),setTimeout(()=>{if(!r)r=!0,this.off("prefab:init-response",o),n(Error("prefab:init timeout"))},2000)})}createPrefabTransport(){return{callTool:(e,t)=>{let n=`tc-${++this.callIdCounter}`;return new Promise((r,o)=>{this.pending.set(n,{resolve:r,reject:o}),this.sendPrefab("prefab:tool-call",{tool:e,arguments:t},n),setTimeout(()=>{if(this.pending.has(n))this.pending.delete(n),o(Error(`Tool call '${e}' timed out`))},30000)})},sendMessage:(e)=>(this.sendPrefab("prefab:send-message",{message:e}),Promise.resolve()),subscribe:(e,t)=>this.subscribe(e,t),capabilities:{subscriptions:this._hostSupportsSubscriptions}}}sendPrefab(e,t,n){if(typeof window>"u")return;let r=window.parent!==window?window.parent:window,o={type:e,payload:t,id:n};r.postMessage(o,this.hostOrigin)}handleJsonRpc(e){if(!("method"in e)){let r=this.rpcPending.get(e.id);if(r)if(this.rpcPending.delete(e.id),e.error)r.reject(Error(e.error.message));else r.resolve(e.result);return}let t=e.method,n=e.params??{};if(e.id!=null&&this.sentRpcIds.delete(e.id))return;if(e.id!=null)this.postJsonRpc({jsonrpc:"2.0",id:e.id,result:{}});switch(t){case"ui/notifications/tool-input":this.dispatch("prefab:tool-input",{args:n.arguments??n});break;case"ui/notifications/tool-input-partial":this.dispatch("prefab:tool-input-partial",{args:n.arguments??n});break;case"ui/notifications/tool-result":this.dispatch("prefab:tool-result",{result:n});break;case"ui/notifications/tool-cancelled":this.dispatch("prefab:tool-cancelled",n);break;case"ui/notifications/host-context-changed":{let r={};if(typeof n.theme==="string")r.colorScheme=n.theme;if(typeof n.styles==="object"&&n.styles!==null){let o=n.styles;if(o.variables)r.variables=o.variables;if(typeof o.css?.fonts==="string")r.fontCss=o.css.fonts}this.dispatch("prefab:theme-update",r),this.dispatch("prefab:host-context-changed",n);break}case"ui/resource-teardown":this.dispatch("prefab:teardown",n);break;case"ui/notifications/resource-updated":case"notifications/resources/updated":this.dispatch("prefab:resource-updated",n);break}}initJsonRpc(e){return new Promise((t,n)=>{let r=++this.rpcIdCounter,o=!1;this.rpcPending.set(r,{resolve:(i)=>{if(o)return;o=!0,this.protocol="jsonrpc";let s=i??{},a=s.hostInfo??{},l=s.hostContext??{},c=s.hostCapabilities??{},u;if(typeof l.theme==="string"||typeof l.styles==="object"){if(u={},typeof l.theme==="string")u.colorScheme=l.theme;if(typeof l.styles==="object"&&l.styles!==null){let g=l.styles;if(g.variables)u.variables=g.variables;if(typeof g.css?.fonts==="string")u.fontCss=g.css.fonts}}this.postJsonRpc({jsonrpc:"2.0",method:"ui/notifications/initialized",params:{}});let d=c.resources;this._hostSupportsSubscriptions=c.subscriptions===!0||d?.subscribe===!0,t({hostName:a.name,hostVersion:a.version,capabilities:{toast:!0,navigation:c.openLinks!=null,messaging:!0,displayModes:l.availableDisplayModes??[]},theme:u,toolInput:void 0,meta:l})},reject:(i)=>{if(o)return;o=!0,n(i)}}),this.postJsonRpc({jsonrpc:"2.0",id:r,method:"ui/initialize",params:{protocolVersion:"2026-01-26",appInfo:{name:"prefab",version:Rn},appCapabilities:{...e.displayModes&&{availableDisplayModes:e.displayModes}}}}),setTimeout(()=>{if(!o)o=!0,this.rpcPending.delete(r),n(Error("ui/initialize timeout"))},2000)})}createJsonRpcTransport(){return{callTool:(e,t)=>this.sendRpcRequest("tools/call",{name:e,arguments:t}),sendMessage:(e)=>this.sendRpcRequest("ui/message",{role:"user",content:{type:"text",text:e}}),subscribe:(e,t)=>this.subscribe(e,t),capabilities:{subscriptions:this._hostSupportsSubscriptions}}}sendRpcRequest(e,t){let n=++this.rpcIdCounter;return new Promise((r,o)=>{this.rpcPending.set(n,{resolve:r,reject:o}),this.postJsonRpc({jsonrpc:"2.0",id:n,method:e,params:t}),setTimeout(()=>{if(this.rpcPending.has(n))this.rpcPending.delete(n),o(Error(`JSON-RPC '${e}' timed out`))},30000)})}sendRpcNotification(e,t){this.postJsonRpc({jsonrpc:"2.0",method:e,params:t})}postJsonRpc(e){if(typeof window>"u")return;if(e.id!=null&&typeof e.method==="string")this.sentRpcIds.add(e.id);if(this.postFn)this.postFn(e);else(window.parent!==window?window.parent:window).postMessage(e,this.hostOrigin)}dispatch(e,t){let n=this.listeners.get(e);if(n)for(let r of n)r(t)}}var pi=()=>{};function kt(e,t){if(t.variables)for(let[n,r]of Object.entries(t.variables))e.style.setProperty(n.startsWith("--")?n:`--${n}`,r);if(t.colorScheme&&t.colorScheme!=="auto")e.setAttribute("data-theme",t.colorScheme);if(t.fontCss)ui(t.fontCss)}function ui(e){if(document.getElementById("__prefab-host-fonts"))return;let n=document.createElement("style");n.id="__prefab-host-fonts",n.textContent=e,document.head.appendChild(n)}function Ke(){if(typeof window>"u")return!1;try{return window.self!==window.top}catch{return!0}}function fi(){if(typeof window>"u")return;let e=window;if(typeof e.acquireVsCodeApi==="function")try{let t=e.acquireVsCodeApi();if(t!==null&&typeof t==="object"&&"postMessage"in t)return t}catch{return}return}var Tn=["Accordion","AccordionItem","Alert","AlertDescription","AlertTitle","AreaChart","Audio","Badge","BarChart","BlockQuote","Button","ButtonGroup","Calendar","Card","CardContent","CardDescription","CardFooter","CardHeader","CardTitle","Carousel","Checkbox","ChoiceCard","Code","Column","Combobox","ComboboxGroup","ComboboxLabel","ComboboxOption","ComboboxSeparator","Condition","Container","Dashboard","DashboardItem","DataTable","DatePicker","Define","Detail","Dialog","Div","Dot","DropZone","Elif","Else","Embed","ExpandableRow","Field","FieldContent","FieldDescription","FieldError","FieldTitle","ForEach","Form","Grid","GridItem","H1","H2","H3","H4","Heading","Histogram","HoverCard","Icon","If","Image","Input","Kbd","Label","Large","Lead","LineChart","Link","Loader","Markdown","MasterDetail","Mermaid","Metric","Muted","P","Page","Pages","PdfViewer","PieChart","Popover","Progress","RadarChart","RadialChart","Radio","RadioGroup","Ring","Row","ScatterChart","Select","SelectGroup","SelectLabel","SelectOption","SelectSeparator","Separator","Slider","Slot","Small","Span","Sparkline","Svg","Switch","Tab","Table","TableBody","TableCaption","TableCell","TableFooter","TableHead","TableHeader","TableRow","Tabs","Text","Textarea","Tooltip","Use","Video"];var Ln=new Set(Tn);function Et(e,t={}){let n=[],r=t.strict??!1;if(e==null||typeof e!=="object")return n.push({path:"$",message:"Wire data must be a non-null object"}),{valid:!1,errors:n};let o=e;if(o.$prefab==null||typeof o.$prefab!=="object")n.push({path:"$.$prefab",message:"Missing or invalid $prefab header"});else if(typeof o.$prefab.version!=="string")n.push({path:"$.$prefab.version",message:"version must be a string"});if(o.view==null)n.push({path:"$.view",message:'Missing required "view" field'});else St(o.view,"$.view",n,r);if(o.state!==void 0){if(o.state===null||typeof o.state!=="object"||Array.isArray(o.state))n.push({path:"$.state",message:"state must be a plain object"})}if(o.theme!==void 0)gi(o.theme,n);if(o.css!==void 0)Mn(o.css,"$.css",n);if(o.stylesheets!==void 0)Mn(o.stylesheets,"$.stylesheets",n);if(o.mode!==void 0&&o.mode!=="light"&&o.mode!=="dark")n.push({path:"$.mode",message:'mode must be "light" or "dark"'});if(o.defs!==void 0)if(o.defs===null||typeof o.defs!=="object"||Array.isArray(o.defs))n.push({path:"$.defs",message:"defs must be a plain object"});else for(let[i,s]of Object.entries(o.defs))St(s,`$.defs.${i}`,n,r);if(o.keyBindings!==void 0)if(o.keyBindings===null||typeof o.keyBindings!=="object"||Array.isArray(o.keyBindings))n.push({path:"$.keyBindings",message:"keyBindings must be a plain object"});else for(let[i,s]of Object.entries(o.keyBindings))At(s,`$.keyBindings.${i}`,n);return{valid:n.length===0,errors:n}}function St(e,t,n,r){if(e==null||typeof e!=="object"||Array.isArray(e)){n.push({path:t,message:"Component must be a plain object"});return}let o=e;if(typeof o.type!=="string"||o.type.length===0){n.push({path:`${t}.type`,message:'Component must have a non-empty "type" string'});return}if(r&&!Ln.has(o.type))n.push({path:`${t}.type`,message:`Unknown component type: "${o.type}"`});if(o.children!==void 0)if(!Array.isArray(o.children))n.push({path:`${t}.children`,message:"children must be an array"});else for(let s=0;s<o.children.length;s++)St(o.children[s],`${t}.children[${s}]`,n,r);let i=["onClick","on_click","onChange","on_change","onSubmit","on_submit","onMount","on_mount","onClose","on_close"];for(let s of i)if(o[s]!==void 0)At(o[s],`${t}.${s}`,n);for(let[s,a]of Object.entries(o)){if(s==="type"||mi.has(s)||i.includes(s))continue;if(Nn(a)||Array.isArray(a)&&a.some(Nn))n.push({path:`${t}.${s}`,message:`Components under "${s}" are ignored by the renderer; move them into "children"`})}}var mi=new Set(["children","fallback","trigger","empty","else","summary"]);function Nn(e){if(e==null||typeof e!=="object"||Array.isArray(e))return!1;let t=e.type;return typeof t==="string"&&Ln.has(t)}function At(e,t,n){if(Array.isArray(e)){for(let a=0;a<e.length;a++)At(e[a],`${t}[${a}]`,n);return}if(e==null||typeof e!=="object"){n.push({path:t,message:"Action must be an object or array of objects"});return}let r=e,o=typeof r.type==="string"&&r.type.length>0,i=typeof r.action==="string"&&r.action.length>0;if(!o&&!i){n.push({path:`${t}.type`,message:'Action must have a non-empty "type" or "action" string'});return}if((i?r.action:r.type).toLowerCase()==="showtoast"){if(typeof r.message!=="string"||r.message.length===0)n.push({path:`${t}.message`,message:'showToast requires a non-empty "message" string'})}}function Mn(e,t,n){if(!Array.isArray(e)){n.push({path:t,message:`${t} must be an array of strings`});return}for(let r=0;r<e.length;r++)if(typeof e[r]!=="string")n.push({path:`${t}[${r}]`,message:"must be a string"})}function gi(e,t){if(e===null||typeof e!=="object"||Array.isArray(e)){t.push({path:"$.theme",message:"theme must be a plain object"});return}let n=e;for(let r of["light","dark"])if(n[r]!==void 0){if(n[r]===null||typeof n[r]!=="object"||Array.isArray(n[r]))t.push({path:`$.theme.${r}`,message:`theme.${r} must be a plain object`})}}var Z={mount(e,t,n){if(We(),n?.validate!==!1)for(let b of Et(t).errors)O.warn(`wire validation ${b.path}: ${b.message}`);let r=t,o={tracked:[],evalBlocked:!1};if(r.pipes)for(let[b,w]of Object.entries(r.pipes))Hn(b,w,o);let i=new ye(r.state),s;if(n?.transport&&"callTool"in n.transport)s=n.transport;else if(n?.transport)s=_e(n.transport);else s=Ve();let a=n?.onToast??yi,l=new ot;function c(b){let w=b;if(r=w,w.state)i.merge(w.state);if(w.defs)u.defs=w.defs;if(w.theme)vt(e,w.theme);if(w.mode)Pn(e,w.mode);if(w.pipes)for(let[S,N]of Object.entries(w.pipes))Hn(S,N,o);for(let S of d)S.remove();if(d.length=0,d.push(...$n(w.css,w.stylesheets)),On(e,w.layout),g?.(),g=void 0,w.keyBindings)g=wt(w.keyBindings,(S)=>{F(j(S,{store:i,transport:s,scope:{},rerender:()=>f(),remount:c,onToast:a}),"keyBinding")});f()}let u={store:i,scope:{},transport:s,rerender:()=>f(),remount:c,onToast:a,defs:r.defs,destroyRegistry:l};if(vt(e,r.theme),r.mode)Pn(e,r.mode);On(e,r.layout);let d=$n(r.css,r.stylesheets),g;if(r.keyBindings)g=wt(r.keyBindings,(b)=>{F(j(b,{store:i,transport:s,scope:{},rerender:()=>f(),remount:c,onToast:a}),"keyBinding")});let h,y=n?.themeToggle??!0;if(y!==!1)h=xt(e,typeof y==="object"?y:void 0);function f(){l.flush();let b=e.querySelector(".pf-theme-toggle");e.innerHTML="";let w=J(r.view,u);if(e.appendChild(w),b)e.appendChild(b)}return f(),{rerender:()=>f(),update(b){if(i.merge(b.update.state),f(),b.update.actions!=null)F(j(b.update.actions,u),"update action")},store:i,destroy(){l.flush(),h?.(),g?.(),Ft(),Bt();for(let b of d)b.remove();for(let b of o.tracked)Xe(b);e.innerHTML=""}}},isPrefabData(e){return e!=null&&typeof e==="object"&&"$prefab"in e},isPrefabUpdate(e){return e!=null&&typeof e==="object"&&"$prefab"in e&&"update"in e}},hi=new Set(["find","dot","length","upper","lower","truncate","join","first","last","abs","round","number","currency","percent","compact","date","time","datetime","pluralize","default","selectattr","rejectattr"]);function bi(e){if(e instanceof EvalError)return!0;return e instanceof Error&&/unsafe-eval|Content Security Policy|call to Function/i.test(e.message)}function Hn(e,t,n){if(hi.has(e)){O.warn(`wire pipe "${e}" ignored — shadows built-in`);return}if(ke(e)!=null){O.debug(`wire pipe "${e}" — already registered, keeping local implementation`);return}if(n.evalBlocked)return;try{let r=Function("return ("+t+")")();if(typeof r!=="function"){O.warn(`wire pipe "${e}" — source did not evaluate to a function`);return}Ue(e,r),n.tracked.push(e)}catch(r){if(bi(r)){n.evalBlocked=!0,O.warn("wire pipes cannot be hydrated — this host's CSP forbids eval. Pre-register them with "+"prefab.registerPipe() from a companion script (rendererHtml({ scripts })) and they are used as-is.");return}O.warn(`wire pipe "${e}" — failed to hydrate:`,r)}}function yi(e){if(typeof document>"u")return;let t=vi(),n=document.createElement("div"),r=e.variant??"default";n.className=`pf-toast${r!=="default"?` pf-toast--${r}`:""}`,n.setAttribute("data-variant",r),n.style.marginBottom="8px",n.style.transition="opacity 0.3s ease";let o=document.createElement("div");if(o.textContent=e.message,o.style.fontWeight="500",n.appendChild(o),e.description){let s=document.createElement("div");s.textContent=e.description,s.style.fontSize="14px",s.style.color="var(--muted-foreground, #6b7280)",n.appendChild(s)}t.appendChild(n);let i=e.duration??4000;setTimeout(()=>{n.style.opacity="0",setTimeout(()=>n.remove(),300)},i)}function Pn(e,t){if(be(e,t),typeof document<"u")be(document.documentElement,t)}function Ci(e){let t=e.trim();if(t.includes("{")||t.includes("}"))return!1;return/^(https?:)?\/\//i.test(t)||t.startsWith("/")||/\.css(\?|#|$)/i.test(t)}function $n(e,t){let n=[];if(typeof document>"u")return n;for(let r of e??[]){let o=document.createElement("style");o.textContent=r,o.dataset.prefab="injected",document.head.appendChild(o),n.push(o)}for(let r of t??[])if(Ci(r)){let o=document.createElement("link");o.rel="stylesheet",o.href=r,o.dataset.prefab="injected",document.head.appendChild(o),n.push(o)}else{let o=document.createElement("style");o.textContent=r,o.dataset.prefab="injected",document.head.appendChild(o),n.push(o)}return n}function On(e,t){if(e.style.height="",e.style.minHeight="",e.style.maxHeight="",e.style.overflow="",!t)return;if(t.preferredHeight!=null)e.style.height=`${t.preferredHeight}px`;if(t.minHeight!=null)e.style.minHeight=`${t.minHeight}px`;if(t.maxHeight!=null)e.style.maxHeight=`${t.maxHeight}px`,e.style.overflow="auto"}function vi(){let t=document.getElementById("prefab-toast-container");if(!t)t=document.createElement("div"),t.id="prefab-toast-container",t.style.position="fixed",t.style.bottom="16px",t.style.right="16px",t.style.zIndex="9999",t.style.maxWidth="400px",document.body.appendChild(t);return t}if(typeof window<"u"){let e=window;e.PrefabRenderer=Z,e.prefab={app:Ge,mount:Z.mount.bind(Z),isPrefabData:Z.isPrefabData.bind(Z),isPrefabUpdate:Z.isPrefabUpdate.bind(Z),Bridge:xe,isIframe:Ke,registerPipe:Ue,unregisterPipe:Xe,listPipes:$t,registerComponent:p,createThemeToggle:xt,validateWireFormat:Et,setLogLevel:Ht};let t=e.__PREFAB_DATA__;if(t!=null){let n=document.getElementById("prefab-root");if(n)Z.mount(n,t)}}async function Ge(e){We();let t=e?.mode??"auto",n=t==="bridge"||t==="auto"&&Ke(),r,o,i={capabilities:{}};if(n)o=new xe(e?.hostOrigin),o.connect(),i=await o.initialize(e?.capabilities??{toolInput:!0}),r=o.createTransport();else if(e?.transport)r=_e(e.transport);else r=Ve();if(i.theme&&typeof document<"u")kt(document.documentElement,i.theme);if(typeof document<"u"&&!o)xi();let s,a,l,c,u,d=i.toolInput,g;if(o)o.on("prefab:tool-input",(f)=>{let b=f.args??f;if(s)s(b);else d=b}),o.on("prefab:tool-result",(f)=>{let b=f.result??f;if(a)a(b);else g=b}),o.on("prefab:tool-cancelled",()=>{l?.()}),o.on("prefab:tool-input-partial",(f)=>{c?.(f.args??f)}),o.on("prefab:theme-update",(f)=>{if(typeof document<"u")kt(document.documentElement,f)}),o.on("prefab:host-context-changed",(f)=>{u?.(f)});function h(f,...b){let w=Rt(f),S=new ye,N={store:S,scope:{},transport:r,rerender:()=>k(),onToast:void 0};function k(){w.innerHTML="";for(let R of b)w.appendChild(J(R,N))}return k(),{rerender:k,store:S,destroy:()=>{w.innerHTML=""}}}return{callTool:(f,b={})=>r.callTool(f,b),sendMessage:(f)=>r.sendMessage(f),onToolInput:(f)=>{if(s=f,d){let b=d;d=void 0,queueMicrotask(()=>f(b))}},onToolResult:(f)=>{if(a=f,g!==void 0){let b=g;g=void 0,queueMicrotask(()=>f(b))}},onToolCancelled:(f)=>{l=f},onToolInputPartial:(f)=>{c=f},onHostContextChanged:(f)=>{u=f},render:h,mount:(f,b,w)=>{let S=Rt(f);return Z.mount(S,b,{transport:r,...w})},requestMode:(f)=>o?.requestMode(f),openLink:(f,b)=>{if(o)o.openLink(f,b);else if(typeof window<"u")window.open(f,b??"_blank")},updateContext:(f)=>{if(o)o.updateContext(f)},setupAutoResize:(f)=>{if(!o)return wi;let b=typeof f==="string"?Rt(f):f;return o.setupAutoResize(b)},notifyPreferredSize:(f)=>{if(o)o.notifyPreferredSize(f)},host:i,capabilities:i.capabilities,theme:i.theme,transport:r,destroy:()=>o?.disconnect()}}var wi=()=>{};function Rt(e){if(typeof e==="string"){if(typeof document>"u")throw Error("Cannot resolve selector outside browser");let t=document.querySelector(e);if(!t)throw Error(`Element not found: ${e}`);return t}return e}function xi(){function e(){let n=document.body.getAttribute("data-vscode-theme-kind");if(!n)return;let r=n.includes("light")?"light":"dark";document.documentElement.setAttribute("data-theme",r)}e(),new MutationObserver(e).observe(document.body,{attributes:!0,attributeFilter:["data-vscode-theme-kind"]})}var Nt=qe("auto"),Dn="#root";function Tt(e){return Z.isPrefabData(e)}function jn(e){return Z.isPrefabUpdate(e)}function In(e){if(Tt(e))return e;if(e!==null&&typeof e==="object"){let t=e;if(Tt(t.structuredContent))return t.structuredContent;if(Array.isArray(t.content))for(let n of t.content){let r=n;if(r.type==="text"&&typeof r.text==="string")try{let o=JSON.parse(r.text);if(Tt(o))return o}catch{}}}return null}async function Fn(){let e=document.querySelector(Dn);if(!e){Nt.error(`Mount target "${Dn}" not found`);return}let t=e,n=await Ge();n.setupAutoResize(t);let r;function o(i){if(r)r.destroy();if(r=n.mount(t,i),i.layout)n.notifyPreferredSize(i.layout)}n.onToolResult((i)=>{let s=In(i);if(s)o(s);else if(jn(i)&&r)r.update(i)}),n.onToolInput((i)=>{let s=In(i);if(s)o(s);else if(jn(i)&&r)r.update(i)})}function ki(){if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",()=>{Fn().catch((e)=>{Nt.error("Boot failed:",e)})},{once:!0});else queueMicrotask(()=>{Fn().catch((e)=>{Nt.error("Boot failed:",e)})})}ki();})();
16
+ `)}function ve(e,t){e.setAttribute("data-theme",t),e.classList.toggle("dark",t==="dark"),e.classList.toggle("light",t==="light")}function xt(e,t){if(!t)return;if(t.light)for(let[n,r]of Object.entries(t.light))e.style.setProperty(`--${vt(n)}`,wt(r));if(t.dark){let r=document.getElementById("prefab-dark-theme");if(!r)r=document.createElement("style"),r.id="prefab-dark-theme",document.head.appendChild(r);r.textContent=An({dark:t.dark})}}function kt(e,t){if(!e||typeof document>"u")return;let n=(r)=>{for(let[o,i]of Object.entries(e))if(ui(o,r))r.preventDefault(),t(i)};return document.addEventListener("keydown",n),()=>document.removeEventListener("keydown",n)}function ui(e,t){let n=e.toLowerCase().split("+").map((i)=>i.trim()),r=n[n.length-1],o=new Set(n.slice(0,-1));if(o.has("ctrl")!==(t.ctrlKey||t.metaKey))return!1;if(o.has("shift")!==t.shiftKey)return!1;if(o.has("alt")!==t.altKey)return!1;return t.key.toLowerCase()===r}var En='<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M12 3v2.25m6.364.386-1.591 1.591M21 12h-2.25m-.386 6.364-1.591-1.591M12 18.75V21m-4.773-4.227-1.591 1.591M5.25 12H3m4.227-4.773L5.636 5.636M15.75 12a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0Z"/></svg>',Rn='<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M21.752 15.002A9.72 9.72 0 0 1 18 15.75c-5.385 0-9.75-4.365-9.75-9.75 0-1.33.266-2.597.748-3.752A9.753 9.753 0 0 0 3 11.25C3 16.635 7.365 21 12.75 21a9.753 9.753 0 0 0 9.002-5.998Z"/></svg>',Tn={"top-right":"top: 8px; right: 8px;","top-left":"top: 8px; left: 8px;","bottom-right":"bottom: 8px; right: 8px;","bottom-left":"bottom: 8px; left: 8px;"};function fi(e,t){try{let r=localStorage.getItem(t);if(r==="light"||r==="dark")return r}catch{}let n=e.getAttribute("data-theme")??document.documentElement.getAttribute("data-theme");if(n==="light"||n==="dark")return n;if(typeof window<"u"&&window.matchMedia("(prefers-color-scheme: light)").matches)return"light";return"dark"}function St(e,t){if(typeof document>"u")return()=>{};let n=t?.position??"top-right",r=t?.storageKey??"prefab-theme",o=t?.syncDocument??!0,i=getComputedStyle(e).position;if(i==="static"||i==="")e.style.position="relative";let s=document.createElement("button");s.className="pf-theme-toggle",s.setAttribute("aria-label","Toggle theme"),s.setAttribute("title","Toggle light/dark"),Object.assign(s.style,{position:"absolute",zIndex:"100",width:"28px",height:"28px",border:"1px solid var(--border, #e5e7eb)",borderRadius:"6px",background:"var(--card, rgba(255,255,255,0.8))",color:"var(--foreground, #333)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",padding:"0",opacity:"0.7",transition:"opacity 0.15s, border-color 0.15s"});let a=Tn[n]??Tn["top-right"];for(let c of a.split(";")){let[g,h]=c.split(":").map((y)=>y.trim());if(g&&h)s.style.setProperty(g,h)}s.addEventListener("mouseenter",()=>{s.style.opacity="1"}),s.addEventListener("mouseleave",()=>{s.style.opacity="0.7"});function l(c){if(ve(e,c),o)ve(document.documentElement,c);s.innerHTML=c==="dark"?Rn:En;try{localStorage.setItem(r,c)}catch{}}let d=fi(e,r);l(d),s.addEventListener("click",()=>{let c=e.getAttribute("data-theme")??"dark";l(c==="dark"?"light":"dark")}),e.appendChild(s);let u;if(o)u=new MutationObserver((c)=>{for(let g of c)if(g.type==="attributes"&&g.attributeName==="data-theme"){let h=document.documentElement.getAttribute("data-theme");if((h==="light"||h==="dark")&&h!==e.getAttribute("data-theme")){ve(e,h),s.innerHTML=h==="dark"?Rn:En;try{localStorage.setItem(r,h)}catch{}}}}),u.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});return()=>{u?.disconnect(),s.remove()}}function Ke(e){let t=e?.baseUrl??(typeof window<"u"?window.location.origin:""),n={"Content-Type":"application/json",...e?.headers},r=e?.fetch??globalThis.fetch.bind(globalThis);return{async callTool(o,i){let s=await r(`${t}/mcp/tools/call`,{method:"POST",headers:n,body:JSON.stringify({jsonrpc:"2.0",method:"tools/call",params:{name:o,arguments:i}})});if(!s.ok)throw Error(`MCP tool call failed: ${s.status} ${s.statusText}`);let a=await s.json();if(a.error)throw Error(a.error.message??"MCP tool call returned error");let l=a.result?.content??a.content??[];for(let d of l)if(d.type==="text"&&d.text!==void 0){try{let u=JSON.parse(d.text);if(typeof u==="object"&&u!==null&&"$prefab"in u)return u;return u}catch{}return d.text}return a.result??a},async sendMessage(o){await r(`${t}/mcp/messages`,{method:"POST",headers:n,body:JSON.stringify({message:o})})}}}function Ge(){return{callTool(e){return O.warn(`No MCP transport: callTool('${e}') ignored`),Promise.resolve(null)},sendMessage(e){return O.warn("No MCP transport: sendMessage ignored",e),Promise.resolve()}}}var Nn="0.3.13";function mi(e){return e!==null&&typeof e==="object"&&e.jsonrpc==="2.0"}class Se{hostOrigin;listeners=new Map;protocol="prefab";cleanup;pending=new Map;callIdCounter=0;rpcPending=new Map;rpcIdCounter=0;sentRpcIds=new Set;postFn;_hostSupportsSubscriptions=!1;constructor(e="*"){this.hostOrigin=e}connect(){if(typeof window>"u")return;let e=bi();if(e)this.postFn=(n)=>e.postMessage(n);let t=(n)=>{if(this.hostOrigin!=="*"&&n.origin!==this.hostOrigin)return;let r=n.data;if(mi(r)){this.handleJsonRpc(r);return}let o=r;if(!o?.type.startsWith("prefab:"))return;if(o.type==="prefab:tool-call-response"&&o.id){let s=this.pending.get(o.id);if(s){if(this.pending.delete(o.id),o.payload?.error!=null)s.reject(Error(o.payload.error));else s.resolve(o.payload?.result);return}}let i=this.listeners.get(o.type);if(i)for(let s of i)s(o.payload??{})};window.addEventListener("message",t),this.cleanup=()=>window.removeEventListener("message",t)}async initialize(e){try{return await Promise.any([this.initPrefab(e),this.initJsonRpc(e)])}catch(t){let n=t instanceof AggregateError?t.errors.map((r)=>r.message).join("; "):String(t);throw Error(`Bridge init failed — no host responded. Tried: ${n}`,{cause:t})}}createTransport(){if(this.protocol==="jsonrpc")return this.createJsonRpcTransport();return this.createPrefabTransport()}requestMode(e){if(this.protocol==="jsonrpc")this.sendRpcRequest("ui/request-display-mode",{mode:e});else this.sendPrefab("prefab:request-mode",{mode:e})}openLink(e,t){if(this.protocol==="jsonrpc")this.sendRpcRequest("ui/open-link",{url:e,target:t});else this.sendPrefab("prefab:open-link",{url:e,target:t})}updateContext(e){if(this.protocol==="jsonrpc")this.sendRpcRequest("ui/update-model-context",{structuredContent:e});else this.sendPrefab("prefab:update-context",{context:e})}setupAutoResize(e){if(typeof ResizeObserver>"u")return gi;let t=-1,n=-1,r=(s,a)=>{if(s===t&&a===n)return;if(t=s,n=a,this.protocol==="jsonrpc")this.sendRpcNotification("ui/notifications/size-changed",{width:s,height:a});else this.sendPrefab("prefab:size-changed",{width:s,height:a})},o=new ResizeObserver((s)=>{for(let a of s)if(a.borderBoxSize.length){let l=a.borderBoxSize[0];r(Math.ceil(l.inlineSize),Math.ceil(l.blockSize))}else{let l=a.target.getBoundingClientRect();r(Math.ceil(l.width),Math.ceil(l.height))}});o.observe(e);let i=e.getBoundingClientRect();return r(Math.ceil(i.width),Math.ceil(i.height)),()=>o.disconnect()}notifyPreferredSize(e){if(this.protocol==="jsonrpc")this.sendRpcNotification("ui/notifications/preferred-size",e);else this.sendPrefab("prefab:preferred-size",e)}subscribe(e,t){let n=(r)=>{if(r.uri!==e)return;t(r.contents??r.data??r)};if(this.protocol==="jsonrpc")this.on("prefab:resource-updated",n),this.sendRpcRequest("resources/subscribe",{uri:e});else this.on("prefab:resource-updated",n),this.sendPrefab("prefab:subscribe",{uri:e});return()=>{if(this.off("prefab:resource-updated",n),this.protocol==="jsonrpc")this.sendRpcRequest("resources/unsubscribe",{uri:e});else this.sendPrefab("prefab:unsubscribe",{uri:e})}}get supportsSubscriptions(){return this._hostSupportsSubscriptions}on(e,t){if(!this.listeners.has(e))this.listeners.set(e,new Set);let n=this.listeners.get(e);if(n)n.add(t)}off(e,t){this.listeners.get(e)?.delete(t)}disconnect(){this.cleanup?.(),this.listeners.clear();for(let[,e]of this.pending)e.reject(Error("Bridge disconnected"));this.pending.clear();for(let[,e]of this.rpcPending)e.reject(Error("Bridge disconnected"));this.rpcPending.clear(),this.sentRpcIds.clear()}get activeProtocol(){return this.protocol}initPrefab(e){return new Promise((t,n)=>{let r=!1,o=(i)=>{if(r)return;r=!0,this.off("prefab:init-response",o),this.protocol="prefab";let s=i.capabilities;this._hostSupportsSubscriptions=s?.subscriptions===!0,t(i)};this.on("prefab:init-response",o),this.sendPrefab("prefab:init",{capabilities:e}),setTimeout(()=>{if(!r)r=!0,this.off("prefab:init-response",o),n(Error("prefab:init timeout"))},2000)})}createPrefabTransport(){return{callTool:(e,t)=>{let n=`tc-${++this.callIdCounter}`;return new Promise((r,o)=>{this.pending.set(n,{resolve:r,reject:o}),this.sendPrefab("prefab:tool-call",{tool:e,arguments:t},n),setTimeout(()=>{if(this.pending.has(n))this.pending.delete(n),o(Error(`Tool call '${e}' timed out`))},30000)})},sendMessage:(e)=>(this.sendPrefab("prefab:send-message",{message:e}),Promise.resolve()),subscribe:(e,t)=>this.subscribe(e,t),capabilities:{subscriptions:this._hostSupportsSubscriptions}}}sendPrefab(e,t,n){if(typeof window>"u")return;let r=window.parent!==window?window.parent:window,o={type:e,payload:t,id:n};r.postMessage(o,this.hostOrigin)}handleJsonRpc(e){if(!("method"in e)){let r=this.rpcPending.get(e.id);if(r)if(this.rpcPending.delete(e.id),e.error)r.reject(Error(e.error.message));else r.resolve(e.result);return}let t=e.method,n=e.params??{};if(e.id!=null&&this.sentRpcIds.delete(e.id))return;if(e.id!=null)this.postJsonRpc({jsonrpc:"2.0",id:e.id,result:{}});switch(t){case"ui/notifications/tool-input":this.dispatch("prefab:tool-input",{args:n.arguments??n});break;case"ui/notifications/tool-input-partial":this.dispatch("prefab:tool-input-partial",{args:n.arguments??n});break;case"ui/notifications/tool-result":this.dispatch("prefab:tool-result",{result:n});break;case"ui/notifications/tool-cancelled":this.dispatch("prefab:tool-cancelled",n);break;case"ui/notifications/host-context-changed":{let r={};if(typeof n.theme==="string")r.colorScheme=n.theme;if(typeof n.styles==="object"&&n.styles!==null){let o=n.styles;if(o.variables)r.variables=o.variables;if(typeof o.css?.fonts==="string")r.fontCss=o.css.fonts}this.dispatch("prefab:theme-update",r),this.dispatch("prefab:host-context-changed",n);break}case"ui/resource-teardown":this.dispatch("prefab:teardown",n);break;case"ui/notifications/resource-updated":case"notifications/resources/updated":this.dispatch("prefab:resource-updated",n);break}}initJsonRpc(e){return new Promise((t,n)=>{let r=++this.rpcIdCounter,o=!1;this.rpcPending.set(r,{resolve:(i)=>{if(o)return;o=!0,this.protocol="jsonrpc";let s=i??{},a=s.hostInfo??{},l=s.hostContext??{},d=s.hostCapabilities??{},u;if(typeof l.theme==="string"||typeof l.styles==="object"){if(u={},typeof l.theme==="string")u.colorScheme=l.theme;if(typeof l.styles==="object"&&l.styles!==null){let g=l.styles;if(g.variables)u.variables=g.variables;if(typeof g.css?.fonts==="string")u.fontCss=g.css.fonts}}this.postJsonRpc({jsonrpc:"2.0",method:"ui/notifications/initialized",params:{}});let c=d.resources;this._hostSupportsSubscriptions=d.subscriptions===!0||c?.subscribe===!0,t({hostName:a.name,hostVersion:a.version,capabilities:{toast:!0,navigation:d.openLinks!=null,messaging:!0,displayModes:l.availableDisplayModes??[]},theme:u,toolInput:void 0,meta:l})},reject:(i)=>{if(o)return;o=!0,n(i)}}),this.postJsonRpc({jsonrpc:"2.0",id:r,method:"ui/initialize",params:{protocolVersion:"2026-01-26",appInfo:{name:"prefab",version:Nn},appCapabilities:{...e.displayModes&&{availableDisplayModes:e.displayModes}}}}),setTimeout(()=>{if(!o)o=!0,this.rpcPending.delete(r),n(Error("ui/initialize timeout"))},2000)})}createJsonRpcTransport(){return{callTool:(e,t)=>this.sendRpcRequest("tools/call",{name:e,arguments:t}),sendMessage:(e)=>this.sendRpcRequest("ui/message",{role:"user",content:{type:"text",text:e}}),subscribe:(e,t)=>this.subscribe(e,t),capabilities:{subscriptions:this._hostSupportsSubscriptions}}}sendRpcRequest(e,t){let n=++this.rpcIdCounter;return new Promise((r,o)=>{this.rpcPending.set(n,{resolve:r,reject:o}),this.postJsonRpc({jsonrpc:"2.0",id:n,method:e,params:t}),setTimeout(()=>{if(this.rpcPending.has(n))this.rpcPending.delete(n),o(Error(`JSON-RPC '${e}' timed out`))},30000)})}sendRpcNotification(e,t){this.postJsonRpc({jsonrpc:"2.0",method:e,params:t})}postJsonRpc(e){if(typeof window>"u")return;if(e.id!=null&&typeof e.method==="string")this.sentRpcIds.add(e.id);if(this.postFn)this.postFn(e);else(window.parent!==window?window.parent:window).postMessage(e,this.hostOrigin)}dispatch(e,t){let n=this.listeners.get(e);if(n)for(let r of n)r(t)}}var gi=()=>{};function At(e,t){if(t.variables)for(let[n,r]of Object.entries(t.variables))e.style.setProperty(n.startsWith("--")?n:`--${n}`,r);if(t.colorScheme&&t.colorScheme!=="auto")e.setAttribute("data-theme",t.colorScheme);if(t.fontCss)hi(t.fontCss)}function hi(e){if(document.getElementById("__prefab-host-fonts"))return;let n=document.createElement("style");n.id="__prefab-host-fonts",n.textContent=e,document.head.appendChild(n)}function qe(){if(typeof window>"u")return!1;try{return window.self!==window.top}catch{return!0}}function bi(){if(typeof window>"u")return;let e=window;if(typeof e.acquireVsCodeApi==="function")try{let t=e.acquireVsCodeApi();if(t!==null&&typeof t==="object"&&"postMessage"in t)return t}catch{return}return}var Mn=["Accordion","AccordionItem","Alert","AlertDescription","AlertTitle","AreaChart","Audio","Badge","BarChart","BlockQuote","Button","ButtonGroup","Calendar","Card","CardContent","CardDescription","CardFooter","CardHeader","CardTitle","Carousel","Checkbox","ChoiceCard","Code","Column","Combobox","ComboboxGroup","ComboboxLabel","ComboboxOption","ComboboxSeparator","Condition","Container","Dashboard","DashboardItem","DataTable","DatePicker","Define","Detail","Dialog","Div","Dot","DropZone","Elif","Else","Embed","ExpandableRow","Field","FieldContent","FieldDescription","FieldError","FieldTitle","ForEach","Form","Grid","GridItem","H1","H2","H3","H4","Heading","Histogram","HoverCard","Icon","If","Image","Input","Kbd","Label","Large","Lead","LineChart","Link","Loader","Markdown","MasterDetail","Mermaid","Metric","Muted","P","Page","Pages","PdfViewer","PieChart","Popover","Progress","RadarChart","RadialChart","Radio","RadioGroup","Ring","Row","ScatterChart","Select","SelectGroup","SelectLabel","SelectOption","SelectSeparator","Separator","Slider","Slot","Small","Span","Sparkline","Svg","Switch","Tab","Table","TableBody","TableCaption","TableCell","TableFooter","TableHead","TableHeader","TableRow","Tabs","Text","Textarea","Tooltip","Use","Video"];var Pn=new Set(Mn);function Rt(e,t={}){let n=[],r=t.strict??!1;if(e==null||typeof e!=="object")return n.push({path:"$",message:"Wire data must be a non-null object"}),{valid:!1,errors:n};let o=e;if(o.$prefab==null||typeof o.$prefab!=="object")n.push({path:"$.$prefab",message:"Missing or invalid $prefab header"});else if(typeof o.$prefab.version!=="string")n.push({path:"$.$prefab.version",message:"version must be a string"});if(o.view==null)n.push({path:"$.view",message:'Missing required "view" field'});else Et(o.view,"$.view",n,r);if(o.state!==void 0){if(o.state===null||typeof o.state!=="object"||Array.isArray(o.state))n.push({path:"$.state",message:"state must be a plain object"})}if(o.theme!==void 0)Ci(o.theme,n);if(o.css!==void 0)Hn(o.css,"$.css",n);if(o.stylesheets!==void 0)Hn(o.stylesheets,"$.stylesheets",n);if(o.mode!==void 0&&o.mode!=="light"&&o.mode!=="dark")n.push({path:"$.mode",message:'mode must be "light" or "dark"'});if(o.defs!==void 0)if(o.defs===null||typeof o.defs!=="object"||Array.isArray(o.defs))n.push({path:"$.defs",message:"defs must be a plain object"});else for(let[i,s]of Object.entries(o.defs))Et(s,`$.defs.${i}`,n,r);if(o.keyBindings!==void 0)if(o.keyBindings===null||typeof o.keyBindings!=="object"||Array.isArray(o.keyBindings))n.push({path:"$.keyBindings",message:"keyBindings must be a plain object"});else for(let[i,s]of Object.entries(o.keyBindings))Tt(s,`$.keyBindings.${i}`,n);return{valid:n.length===0,errors:n}}function Et(e,t,n,r){if(e==null||typeof e!=="object"||Array.isArray(e)){n.push({path:t,message:"Component must be a plain object"});return}let o=e;if(typeof o.type!=="string"||o.type.length===0){n.push({path:`${t}.type`,message:'Component must have a non-empty "type" string'});return}if(r&&!Pn.has(o.type))n.push({path:`${t}.type`,message:`Unknown component type: "${o.type}"`});if(o.children!==void 0)if(!Array.isArray(o.children))n.push({path:`${t}.children`,message:"children must be an array"});else for(let s=0;s<o.children.length;s++)Et(o.children[s],`${t}.children[${s}]`,n,r);let i=["onClick","on_click","onChange","on_change","onSubmit","on_submit","onMount","on_mount","onClose","on_close"];for(let s of i)if(o[s]!==void 0)Tt(o[s],`${t}.${s}`,n);for(let[s,a]of Object.entries(o)){if(s==="type"||yi.has(s)||i.includes(s))continue;if(Ln(a)||Array.isArray(a)&&a.some(Ln))n.push({path:`${t}.${s}`,message:`Components under "${s}" are ignored by the renderer; move them into "children"`})}}var yi=new Set(["children","fallback","trigger","empty","else","summary"]);function Ln(e){if(e==null||typeof e!=="object"||Array.isArray(e))return!1;let t=e.type;return typeof t==="string"&&Pn.has(t)}function Tt(e,t,n){if(Array.isArray(e)){for(let a=0;a<e.length;a++)Tt(e[a],`${t}[${a}]`,n);return}if(e==null||typeof e!=="object"){n.push({path:t,message:"Action must be an object or array of objects"});return}let r=e,o=typeof r.type==="string"&&r.type.length>0,i=typeof r.action==="string"&&r.action.length>0;if(!o&&!i){n.push({path:`${t}.type`,message:'Action must have a non-empty "type" or "action" string'});return}if((i?r.action:r.type).toLowerCase()==="showtoast"){if(typeof r.message!=="string"||r.message.length===0)n.push({path:`${t}.message`,message:'showToast requires a non-empty "message" string'})}}function Hn(e,t,n){if(!Array.isArray(e)){n.push({path:t,message:`${t} must be an array of strings`});return}for(let r=0;r<e.length;r++)if(typeof e[r]!=="string")n.push({path:`${t}[${r}]`,message:"must be a string"})}function Ci(e,t){if(e===null||typeof e!=="object"||Array.isArray(e)){t.push({path:"$.theme",message:"theme must be a plain object"});return}let n=e;for(let r of["light","dark"])if(n[r]!==void 0){if(n[r]===null||typeof n[r]!=="object"||Array.isArray(n[r]))t.push({path:`$.theme.${r}`,message:`theme.${r} must be a plain object`})}}var Z={mount(e,t,n){if(_e(),n?.validate!==!1)for(let b of Rt(t).errors)O.warn(`wire validation ${b.path}: ${b.message}`);let r=t,o={tracked:[],evalBlocked:!1};if(r.pipes)for(let[b,w]of Object.entries(r.pipes))On(b,w,o);let i=new we(r.state),s;if(n?.transport&&"callTool"in n.transport)s=n.transport;else if(n?.transport)s=Ke(n.transport);else s=Ge();let a=n?.onToast??xi,l=new st;function d(b){let w=b;if(r=w,w.state)i.merge(w.state);if(w.defs)u.defs=w.defs;if(w.theme)xt(e,w.theme);if(w.mode)$n(e,w.mode);if(w.pipes)for(let[S,N]of Object.entries(w.pipes))On(S,N,o);for(let S of c)S.remove();if(c.length=0,c.push(...Dn(w.css,w.stylesheets)),jn(e,w.layout),g?.(),g=void 0,w.keyBindings)g=kt(w.keyBindings,(S)=>{I(j(S,{store:i,transport:s,scope:{},rerender:()=>f(),remount:d,onToast:a}),"keyBinding")});f()}let u={store:i,scope:{},transport:s,rerender:()=>f(),remount:d,onToast:a,defs:r.defs,destroyRegistry:l};if(xt(e,r.theme),r.mode)$n(e,r.mode);jn(e,r.layout);let c=Dn(r.css,r.stylesheets),g;if(r.keyBindings)g=kt(r.keyBindings,(b)=>{I(j(b,{store:i,transport:s,scope:{},rerender:()=>f(),remount:d,onToast:a}),"keyBinding")});let h,y=n?.themeToggle??!0;if(y!==!1)h=St(e,typeof y==="object"?y:void 0);function f(){l.flush();let b=e.querySelector(".pf-theme-toggle");e.innerHTML="";let w=J(r.view,u);if(e.appendChild(w),b)e.appendChild(b)}return f(),{rerender:()=>f(),update(b){if(i.merge(b.update.state),f(),b.update.actions!=null)I(j(b.update.actions,u),"update action")},store:i,destroy(){l.flush(),h?.(),g?.(),Jt(),zt();for(let b of c)b.remove();for(let b of o.tracked)Ze(b);e.innerHTML=""}}},isPrefabData(e){return e!=null&&typeof e==="object"&&"$prefab"in e},isPrefabUpdate(e){return e!=null&&typeof e==="object"&&"$prefab"in e&&"update"in e}},vi=new Set(["find","dot","length","upper","lower","truncate","join","first","last","abs","round","number","currency","percent","compact","date","time","datetime","pluralize","default","selectattr","rejectattr"]);function wi(e){if(e instanceof EvalError)return!0;return e instanceof Error&&/unsafe-eval|Content Security Policy|call to Function/i.test(e.message)}function On(e,t,n){if(vi.has(e)){O.warn(`wire pipe "${e}" ignored — shadows built-in`);return}if(Ae(e)!=null){O.debug(`wire pipe "${e}" — already registered, keeping local implementation`);return}if(n.evalBlocked)return;try{let r=Function("return ("+t+")")();if(typeof r!=="function"){O.warn(`wire pipe "${e}" — source did not evaluate to a function`);return}Ye(e,r),n.tracked.push(e)}catch(r){if(wi(r)){n.evalBlocked=!0,O.warn("wire pipes cannot be hydrated — this host's CSP forbids eval. Pre-register them with "+"prefab.registerPipe() from a companion script (rendererHtml({ scripts })) and they are used as-is.");return}O.warn(`wire pipe "${e}" — failed to hydrate:`,r)}}function xi(e){if(typeof document>"u")return;let t=Si(),n=document.createElement("div"),r=e.variant??"default";n.className=`pf-toast${r!=="default"?` pf-toast--${r}`:""}`,n.setAttribute("data-variant",r),n.style.marginBottom="8px",n.style.transition="opacity 0.3s ease";let o=document.createElement("div");if(o.textContent=e.message,o.style.fontWeight="500",n.appendChild(o),e.description){let s=document.createElement("div");s.textContent=e.description,s.style.fontSize="14px",s.style.color="var(--muted-foreground, #6b7280)",n.appendChild(s)}t.appendChild(n);let i=e.duration??4000;setTimeout(()=>{n.style.opacity="0",setTimeout(()=>n.remove(),300)},i)}function $n(e,t){if(ve(e,t),typeof document<"u")ve(document.documentElement,t)}function ki(e){let t=e.trim();if(t.includes("{")||t.includes("}"))return!1;return/^(https?:)?\/\//i.test(t)||t.startsWith("/")||/\.css(\?|#|$)/i.test(t)}function Dn(e,t){let n=[];if(typeof document>"u")return n;for(let r of e??[]){let o=document.createElement("style");o.textContent=r,o.dataset.prefab="injected",document.head.appendChild(o),n.push(o)}for(let r of t??[])if(ki(r)){let o=document.createElement("link");o.rel="stylesheet",o.href=r,o.dataset.prefab="injected",document.head.appendChild(o),n.push(o)}else{let o=document.createElement("style");o.textContent=r,o.dataset.prefab="injected",document.head.appendChild(o),n.push(o)}return n}function jn(e,t){if(e.style.height="",e.style.minHeight="",e.style.maxHeight="",e.style.overflow="",!t)return;if(t.preferredHeight!=null)e.style.height=`${t.preferredHeight}px`;if(t.minHeight!=null)e.style.minHeight=`${t.minHeight}px`;if(t.maxHeight!=null)e.style.maxHeight=`${t.maxHeight}px`,e.style.overflow="auto"}function Si(){let t=document.getElementById("prefab-toast-container");if(!t)t=document.createElement("div"),t.id="prefab-toast-container",t.style.position="fixed",t.style.bottom="16px",t.style.right="16px",t.style.zIndex="9999",t.style.maxWidth="400px",document.body.appendChild(t);return t}if(typeof window<"u"){let e=window;e.PrefabRenderer=Z,e.prefab={app:Ue,mount:Z.mount.bind(Z),isPrefabData:Z.isPrefabData.bind(Z),isPrefabUpdate:Z.isPrefabUpdate.bind(Z),Bridge:Se,isIframe:qe,registerPipe:Ye,unregisterPipe:Ze,listPipes:Dt,registerComponent:p,createThemeToggle:St,validateWireFormat:Rt,setLogLevel:Ot};let t=e.__PREFAB_DATA__;if(t!=null){let n=document.getElementById("prefab-root");if(n)Z.mount(n,t)}}async function Ue(e){_e();let t=e?.mode??"auto",n=t==="bridge"||t==="auto"&&qe(),r,o,i={capabilities:{}};if(n)o=new Se(e?.hostOrigin),o.connect(),i=await o.initialize(e?.capabilities??{toolInput:!0}),r=o.createTransport();else if(e?.transport)r=Ke(e.transport);else r=Ge();if(i.theme&&typeof document<"u")At(document.documentElement,i.theme);if(typeof document<"u"&&!o)Ei();let s,a,l,d,u,c=i.toolInput,g;if(o)o.on("prefab:tool-input",(f)=>{let b=f.args??f;if(s)s(b);else c=b}),o.on("prefab:tool-result",(f)=>{let b=f.result??f;if(a)a(b);else g=b}),o.on("prefab:tool-cancelled",()=>{l?.()}),o.on("prefab:tool-input-partial",(f)=>{d?.(f.args??f)}),o.on("prefab:theme-update",(f)=>{if(typeof document<"u")At(document.documentElement,f)}),o.on("prefab:host-context-changed",(f)=>{u?.(f)});function h(f,...b){let w=Nt(f),S=new we,N={store:S,scope:{},transport:r,rerender:()=>k(),onToast:void 0};function k(){w.innerHTML="";for(let R of b)w.appendChild(J(R,N))}return k(),{rerender:k,store:S,destroy:()=>{w.innerHTML=""}}}return{callTool:(f,b={})=>r.callTool(f,b),sendMessage:(f)=>r.sendMessage(f),onToolInput:(f)=>{if(s=f,c){let b=c;c=void 0,queueMicrotask(()=>f(b))}},onToolResult:(f)=>{if(a=f,g!==void 0){let b=g;g=void 0,queueMicrotask(()=>f(b))}},onToolCancelled:(f)=>{l=f},onToolInputPartial:(f)=>{d=f},onHostContextChanged:(f)=>{u=f},render:h,mount:(f,b,w)=>{let S=Nt(f);return Z.mount(S,b,{transport:r,...w})},requestMode:(f)=>o?.requestMode(f),openLink:(f,b)=>{if(o)o.openLink(f,b);else if(typeof window<"u")window.open(f,b??"_blank")},updateContext:(f)=>{if(o)o.updateContext(f)},setupAutoResize:(f)=>{if(!o)return Ai;let b=typeof f==="string"?Nt(f):f;return o.setupAutoResize(b)},notifyPreferredSize:(f)=>{if(o)o.notifyPreferredSize(f)},host:i,capabilities:i.capabilities,theme:i.theme,transport:r,destroy:()=>o?.disconnect()}}var Ai=()=>{};function Nt(e){if(typeof e==="string"){if(typeof document>"u")throw Error("Cannot resolve selector outside browser");let t=document.querySelector(e);if(!t)throw Error(`Element not found: ${e}`);return t}return e}function Ei(){function e(){let n=document.body.getAttribute("data-vscode-theme-kind");if(!n)return;let r=n.includes("light")?"light":"dark";document.documentElement.setAttribute("data-theme",r)}e(),new MutationObserver(e).observe(document.body,{attributes:!0,attributeFilter:["data-vscode-theme-kind"]})}var Lt=Xe("auto"),In="#root";function Mt(e){return Z.isPrefabData(e)}function Fn(e){return Z.isPrefabUpdate(e)}function Bn(e){if(Mt(e))return e;if(e!==null&&typeof e==="object"){let t=e;if(Mt(t.structuredContent))return t.structuredContent;if(Array.isArray(t.content))for(let n of t.content){let r=n;if(r.type==="text"&&typeof r.text==="string")try{let o=JSON.parse(r.text);if(Mt(o))return o}catch{}}}return null}async function Jn(){let e=document.querySelector(In);if(!e){Lt.error(`Mount target "${In}" not found`);return}let t=e,n=await Ue();n.setupAutoResize(t);let r;function o(i){if(r)r.destroy();if(r=n.mount(t,i),i.layout)n.notifyPreferredSize(i.layout)}n.onToolResult((i)=>{let s=Bn(i);if(s)o(s);else if(Fn(i)&&r)r.update(i)}),n.onToolInput((i)=>{let s=Bn(i);if(s)o(s);else if(Fn(i)&&r)r.update(i)})}function Ri(){if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",()=>{Jn().catch((e)=>{Lt.error("Boot failed:",e)})},{once:!0});else queueMicrotask(()=>{Jn().catch((e)=>{Lt.error("Boot failed:",e)})})}Ri();})();