showai-reader 0.10.0-reader.7ttebdmo → 0.10.0-reader.bp6rg7sq

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  The [ShowAI](https://showai.renaissancemind.ai) page reader, built from ShowAI 0.10.0 as code-split ES modules. Inline conversation pages written by `render-artifact --cdn` import it and load each component's code only when the page uses it.
4
4
 
5
5
  ```js
6
- const { mount } = await import("https://cdn.jsdelivr.net/npm/showai-reader@0.10.0-reader.7ttebdmo/index.js");
6
+ const { mount } = await import("https://cdn.jsdelivr.net/npm/showai-reader@0.10.0-reader.bp6rg7sq/index.js");
7
7
  mount(document.getElementById("page"), { artifact });
8
8
  ```
9
9
 
package/index.js CHANGED
@@ -1 +1 @@
1
- export * from "./reader-7TTEBDMO.js";
1
+ export * from "./reader-BP6RG7SQ.js";
package/manifest.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "format": "showai-cdn-reader",
3
3
  "name": "showai-reader",
4
- "version": "0.10.0-reader.7ttebdmo",
5
- "entry": "reader-7TTEBDMO.js",
6
- "integrity": "sha256-dKliFf5NUlvC6smvALPsxs+xoxvbqbnIW6O537bzDcY=",
4
+ "version": "0.10.0-reader.bp6rg7sq",
5
+ "entry": "reader-BP6RG7SQ.js",
6
+ "integrity": "sha256-lseMZDxSrLgLKloIdkxO7JOTl9s7kBC9cuoJ1I0VPnE=",
7
7
  "files": 49,
8
- "bytes": 13472864
8
+ "bytes": 13472874
9
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "showai-reader",
3
- "version": "0.10.0-reader.7ttebdmo",
3
+ "version": "0.10.0-reader.bp6rg7sq",
4
4
  "description": "ShowAI page reader as code-split ES modules, for inline pages loaded from a CDN.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -19,7 +19,7 @@ Error generating stack: `+n.message+`
19
19
  .showai-icon-tooltip::backdrop { pointer-events: none; }
20
20
  @media print { .showai-icon-tooltip { display: none !important; } }
21
21
  `;let r=t.createElement("div");r.className="showai-icon-tooltip",r.id=`showai-icon-tooltip-${a.crypto.randomUUID()}`,r.setAttribute("role","tooltip"),r.setAttribute("popover","manual"),n.append(o,r);let i=null,l=null,s=0,c=0,d=!1,u=null,p=null,g=C=>C.getAttribute("data-icon-tooltip")?.trim()||(C===i?l:C.getAttribute("title"))?.trim()||C.getAttribute("aria-label")?.trim()||[...(C.getAttribute("aria-labelledby")||"").split(/\s+/)].map(N=>e.getElementById(N)?.textContent||"").join(" ").trim()||C.textContent?.trim(),y=C=>{let N=C.composedPath(),z=N.find(A=>A?.matches&&A.getRootNode()===e&&A.matches("button, summary, a, [role='button']"));if(z)return g(z)?z:null;for(let A of N)if(!(!A?.matches||A.getRootNode()!==e)){if(A===r)return r;if(A.matches("[data-icon-tooltip], svg[aria-label], [role='img'][aria-label]"))return g(A)?A:null}return null},b=()=>{if(a.clearTimeout(s),i){let C=(i.getAttribute("aria-describedby")||"").split(/\s+/).filter(N=>N&&N!==r.id);C.length?i.setAttribute("aria-describedby",C.join(" ")):i.removeAttribute("aria-describedby"),l!==null&&!i.hasAttribute("title")&&i.setAttribute("title",l)}r.hidePopover(),i=null,l=null},x=C=>{let N=t.createTreeWalker(C,a.NodeFilter.SHOW_TEXT);for(let z=N.nextNode();z;z=N.nextNode()){if(!/[\p{L}\p{N}]/u.test(z.textContent))continue;let A=z.parentElement;if(A.closest("svg, [hidden]")||a.getComputedStyle(A).visibility!=="visible")continue;let P=t.createRange();if(P.selectNodeContents(z),[...P.getClientRects()].some(Z=>Z.width>1&&Z.height>1))return!0}return!1},f=()=>{let C=i;if(!C)return;if(!C.isConnected||!C.getClientRects().length)return b();if(x(C)){r.hidePopover();let ee=(C.getAttribute("aria-describedby")||"").split(/\s+/).filter(j=>j&&j!==r.id);ee.length?C.setAttribute("aria-describedby",ee.join(" ")):C.removeAttribute("aria-describedby");return}r.textContent=g(C),r.showPopover();let N=C.getBoundingClientRect(),z=r.getBoundingClientRect(),A=t.documentElement.clientWidth,q=t.documentElement.clientHeight,P=N.bottom+6,Z=P+z.height<=q-8?P:N.top-z.height-6;r.style.left=`${Math.max(8,Math.min(N.left+(N.width-z.width)/2,A-z.width-8))}px`,r.style.top=`${Math.max(8,Math.min(Z,q-z.height-8))}px`;let F=(C.getAttribute("aria-describedby")||"").split(/\s+/).filter(Boolean);C.setAttribute("aria-describedby",[...new Set([...F,r.id])].join(" "))},m=C=>{a.clearTimeout(s),C!==i&&(b(),!(!C||C===r)&&(i=C,l=C.getAttribute("title"),C.removeAttribute("title"),f()))},v=()=>{a.clearTimeout(s),s=a.setTimeout(()=>{u!==r&&m(u||p)},90)},T=C=>{C.pointerType!=="touch"&&(u=y(C),u===r?a.clearTimeout(s):m(u||p))},w=C=>{i?.contains(C.relatedTarget)||r.contains(C.relatedTarget)||(u=null,v())},E=C=>{d||(p=y(C),m(p))},L=()=>{p=null,v()},H=C=>{C.key==="Escape"&&b()},S=()=>{u=null,p=null,b()},k=()=>{S(),d=!0,a.clearTimeout(c),c=a.setTimeout(()=>{d=!1},0)},M=new a.MutationObserver(()=>{i&&(i.hasAttribute("title")&&(l=i.getAttribute("title"),i.removeAttribute("title")),!i.isConnected||!i.getClientRects().length?b():x(i)?f():r.matches(":popover-open")?r.textContent!==g(i)&&(r.textContent=g(i)):f())});M.observe(n,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["aria-label","title","data-icon-tooltip","hidden","class","style"]});let O=[["pointerover",T],["pointerout",w],["focusin",E],["focusout",L],["keydown",H],["pointerdown",k],["contextmenu",S],["wheel",S],["scroll",S]];for(let[C,N]of O)e.addEventListener(C,N,!0);return a.addEventListener("resize",S),a.addEventListener("blur",S),()=>{a.clearTimeout(c),b(),M.disconnect();for(let[C,N]of O)e.removeEventListener(C,N,!0);a.removeEventListener("resize",S),a.removeEventListener("blur",S),r.remove(),o.remove()}}var ew=U(h2(),1);function jt(e){let t=new Map,a=(n,o)=>{n.attrs?.id&&t.set(n.attrs.id,{node:n,parent:o});for(let r of n.content??[])a(r,n)};return a(e,null),t}function y2(e,t){let a=e.attrs.points,n=e.attrs.extent;return[a[0],a.at(-1)].map(o=>d0(t,{x:o.x/n[0],y:o.y/n[1]}))}function M1(e,t,a,n){let o=y2(e,t),r=a.get(e.attrs.id)?.parent;for(let[i,l]of["start","end"].entries()){let s=e.attrs.bindings?.[l],c=s&&a.get(s.targetId),d=s&&n[s.targetId];c&&Ho(r,n)&&c.parent===r&&d&&$n(c.node).bindTarget&&(o[i]=d0(d,s.anchor))}return o}function I1(e,t,a,n=e.attrs.bindings){let o=jl(a),r=Math.max(4,e.attrs.strokeWidth*2),i=o.x-r,l=o.y-r,s=o.width+r*2,c=o.height+r*2,d={...e.attrs,extent:[s,c],points:a.map(p=>({x:p.x-i,y:p.y-l}))};n&&Object.keys(n).length?d.bindings=n:delete d.bindings;let u={...t,x:i,y:l,width:s,height:c};return delete u.rotation,{node:{...e,attrs:d},frame:u}}function fl(e){let t=jt(e.content),a=new Map,n=e.layout;for(let[r,{node:i,parent:l}]of t){if(i.type!=="drawing"||i.attrs.tool!=="arrow"||!i.attrs.bindings||!n?.[r])continue;let s={};for(let d of["start","end"]){let u=i.attrs.bindings[d],p=u&&t.get(u.targetId);p&&Ho(l,n)&&p.parent===l&&n[u.targetId]&&$n(p.node).bindTarget&&(s[d]=u)}let c=I1(i,n[r],M1(i,n[r],t,n),s);(JSON.stringify(c.node.attrs)!==JSON.stringify(i.attrs)||JSON.stringify(c.frame)!==JSON.stringify(n[r]))&&(a.set(r,c.node),n===e.layout&&(n={...n}),n[r]=c.frame)}if(!a.size)return e;let o=r=>{if(a.has(r.attrs?.id))return a.get(r.attrs.id);if(!r.content)return r;let i=r.content.map(o);return i.some((l,s)=>l!==r.content[s])?{...r,content:i}:r};return e.content=o(e.content),e.layout=n,e}function v2(e,t,a,n=0,o=new Set){let r=jt(e.content),i=r.get(t)?.node;if(!Ho(i,e.layout))return null;let l=(i?.content??[]).flatMap(c=>{let d=c.attrs?.id,u=e.layout?.[d];return u&&!o.has(d)&&$n(c).bindTarget?[{id:d,node:c,frame:u,point:a,tolerance:n,scale:1}]:[]}),s=m0(l);return s?{targetId:s.id,anchor:s.node.type==="surface"&&s.node.attrs?.kind==="page"?rp(s.frame,a):mC(s.frame,a)}:null}function mC(e,t,a=16){let n=rp(e,t),o=e.width,r=jo(e);if(!o||!r)return n;let i={x:n.x*o,y:n.y*r},l=[{x:.5,y:0},{x:1,y:.5},{x:.5,y:1},{x:0,y:.5}],s=u=>Math.hypot(u.x*o-i.x,u.y*r-i.y),c=l.reduce((u,p)=>s(p)<s(u)?p:u),d=Math.min(i.x,o-i.x,i.y,r-i.y);return s(c)<=a||d>a?c:n}function P9(e,t){return Object.fromEntries(Object.entries(e??{}).filter(([,a])=>t.has(a.targetId)))}var fC=(e,t)=>Object.hasOwn(e,t),pm=e=>e!==null&&typeof e=="object",gC=(e,t,a)=>Object.defineProperty(e,t,{value:a,enumerable:!0,writable:!0,configurable:!0});var mm=e=>pm(e)&&!Array.isArray(e)?typeof e.attrs?.id=="string"&&e.attrs.id?e.attrs.id:typeof e.id=="string"&&e.id?e.id:null:null;function B9(e){if(!e.length||!mm(e[0]))return null;let t=new Map;for(let a of e){let n=mm(a);if(!n||t.has(n))return null;t.set(n,a)}return t}function fm(e,t){if(!pm(e)||!pm(t)||Array.isArray(e)!==Array.isArray(t))return e===t?e:t;let a=Object.keys(e),n=Object.keys(t),o=a.length===n.length&&(!Array.isArray(t)||e.length===t.length),r=Array.isArray(t)&&B9(t)?B9(e):null,i=t;for(let l of n){let s=fC(e,l),c=r?mm(t[l]):null,d=r?r.has(c):s,u=r?r.get(c):e[l],p=d?fm(u,t[l]):t[l];(!s||p!==e[l])&&(o=!1),p!==t[l]&&(i===t&&(i=Array.isArray(t)?t.slice():Object.fromEntries(Object.entries(t))),gC(i,l,p))}return o?e:i}var bC=new Set(["__proto__","prototype","constructor"]),gl=e=>e&&typeof e=="object"&&!Array.isArray(e),gm=(e,t=200)=>typeof e=="string"&&e.length>0&&e.length<=t&&!bC.has(e),bm=e=>e.text??(e.content??[]).map(bm).join("");function j9(){return{version:1,enabled:!0,source:{mode:"headings",maxLevel:3},initialState:"auto",placement:"auto",width:220}}function hm(e){let t=new Map;function a(n){n.attrs?.id&&t.set(n.attrs.id,n),!["surface","widget","stepper"].includes(n.type)&&n.content?.forEach(a)}return e.content?.forEach(a),t}function x2(e,t){let a=o=>{throw new Error(`Page outline: ${o}`)};if((t.type!=="surface"||t.attrs?.kind!=="page")&&a("only Page can have an outline."),(!gl(e)||e.version!==1||typeof e.enabled!="boolean")&&a("requires version 1 and enabled."),["auto","expanded","collapsed"].includes(e.initialState)||a("invalid initialState."),["auto","floating","docked"].includes(e.placement)||a("invalid placement."),(!Number.isFinite(e.width)||e.width<180||e.width>480)&&a("width must be 180\u2013480."),e.renderer!==void 0){let o=e.renderer;(!gl(o)||typeof o.componentId!="string"||typeof o.version!="string"||typeof o.integrity!="string"||!/^[a-z][a-z0-9-]{0,79}$/.test(o.componentId)||!/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[\w.-]+)?$/.test(o.version)||!/^sha256-[a-f0-9]{64}$/.test(o.integrity)||!gl(o.props))&&a("renderer requires an exact component revision and props."),o.scope!==void 0&&!["builtin","project","global","published"].includes(o.scope)&&a("invalid renderer scope.")}let n=e.source;if(gl(n)||a("source is required."),n.mode==="headings"){if((!Number.isInteger(n.maxLevel)||n.maxLevel<1||n.maxLevel>6)&&a("maxLevel must be 1\u20136."),n.overrides!==void 0){gl(n.overrides)||a("overrides must be an object.");for(let[o,r]of Object.entries(n.overrides))(!gm(o)||!gl(r)||r.title!==void 0&&(typeof r.title!="string"||r.title.length>2e3)||r.hidden!==void 0&&typeof r.hidden!="boolean")&&a("invalid heading override.")}}else if(n.mode==="manual"){let o=new Set,r=0,i=(l,s=0)=>{(!Array.isArray(l)||s>24)&&a("manual entries must be a tree up to 24 levels.");for(let c of l)(++r>3e3||!gl(c)||!gm(c.id,240)||o.has(c.id))&&a("manual entries require unique IDs (at most 3000)."),o.add(c.id),c.title!==void 0&&(typeof c.title!="string"||c.title.length>2e3)&&a("invalid entry title."),c.nodeId!==void 0&&!gm(c.nodeId)&&a("invalid entry target."),!c.nodeId&&!c.title?.trim()&&a("groups require a title."),c.children!==void 0&&i(c.children,s+1)};i(n.entries)}else a("source mode must be headings or manual.");return e}function qs(e,t=e.attrs?.outline){if(!t||e.attrs?.kind!=="page")return{items:[],targets:new Map,missing:[]};let a=hm(e),n=new Map,o=[],r=c=>(bm(c).trim()||c.attrs?.name||c.type||"").slice(0,2e3);if(t.source.mode==="manual"){let c=(d,u)=>d.flatMap(p=>{let g=p.nodeId?a.get(p.nodeId):void 0;p.nodeId&&!g&&o.push(p.id);let y=!!p.nodeId&&!g&&!p.title?.trim(),b=c(p.children??[],y?u:u+1);return y?b:!g&&!b.length?[]:(g&&n.set(p.id,p.nodeId),[{id:p.id,navigable:!!g,title:p.title?.trim()||(g?r(g):""),level:u,children:b}])});return{items:c(t.source.entries,1),targets:n,missing:o}}let i=[],l=[];for(let[c,d]of a){if(d.type!=="heading"||d.attrs.level>t.source.maxLevel)continue;let u=t.source.overrides?.[c],p=(u?.title??bm(d)).trim(),g=!!u?.hidden||!p,y={id:`heading:${c}`,navigable:!0,hidden:g,title:p.slice(0,2e3),level:d.attrs.level,children:[]};for(;l.length&&l.at(-1).level>=y.level;)l.pop();(l.at(-1)?.children??i).push(y),l.push(y),g||n.set(y.id,c)}let s=c=>c.flatMap(({hidden:d,...u})=>{let p=s(u.children);return d?p:[{...u,children:p}]});return{items:s(i),targets:n,missing:o}}function ym(e){return e.flatMap(t=>[t,...ym(t.children)])}function H9(e,t,a){let n=structuredClone(e);if(n.source.mode==="headings"&&n.source.overrides)n.source.overrides=Object.fromEntries(Object.entries(n.source.overrides).flatMap(([o,r])=>t.has(o)?[[t.get(o),r]]:[]));else if(n.source.mode==="manual"){let o=r=>r.flatMap(i=>{let l=o(i.children??[]),s=i.nodeId?t.get(i.nodeId):void 0;return i.nodeId&&!s&&!l.length?[]:[{id:a?a():i.id,...i.title!==void 0?{title:i.title}:i.nodeId&&!s?{title:i.nodeId}:{},...s?{nodeId:s}:{},...l.length?{children:l}:{}}]});n.source.entries=o(n.source.entries)}return n}function _9({width:e,gutter:t,panelWidth:a,widthMode:n,preferred:o="auto",pinned:r=!1,previous:i}){return e<640||(r||o==="docked")&&e-a<560?"drawer":r||o==="docked"?"docked":o==="floating"||n==="full"?"floating":t>=a+16+(i==="margin"?0:24)?"margin":"floating"}var Fs=e=>e.content?.type==="surface",vm=e=>Ua(e)?3:Fs(e)?2:1;function Et(e,t,a=null){t(e,a),Array.isArray(e.content)&&e.content.forEach(n=>Et(n,t,e))}function U9(e){let t=2166136261;for(let a of e)t=Math.imul(t^a.charCodeAt(0),16777619);return`node-${(t>>>0).toString(16)}`}function yi(e,{repairLegacy:t=!1}={}){let a=new Set;Et(e.content,i=>{i.attrs?.id&&a.add(i.attrs.id)});let n=new Set,o=new Set(["__proto__","prototype","constructor"]),r=(i,l)=>{let s=i.attrs?.id;if((!["surface","doc","text"].includes(i.type)||i.type==="surface"&&Ua(e))&&(!s||t&&(n.has(s)||o.has(s)))){let c=U9(`${e.id}:${l}`);for(;a.has(c);)c+="-copy";a.add(c),i.attrs={...i.attrs,id:c}}i.attrs?.id&&n.add(i.attrs.id),Array.isArray(i.content)&&i.content.forEach((c,d)=>r(c,`${l}/${d}`))};return r(e.content,""),e}function Ke(e,t){let a;return Et(e.content,(n,o)=>{n.attrs?.id===t&&(a={node:n,parent:o})}),a}function w2(e){if(Ua(e))return vi(e);if(!Fs(e))return e;e.layout??={};let t=a=>{let n=0;for(let o of a.content??[]){let r=o.attrs?.id,i=a.type==="surface"||a.type==="region"&&e.layout[a.attrs.id]?.mode==="free";r&&(i||o.type==="region")&&(Object.hasOwn(e.layout,r)||(e.layout[r]={x:n,y:0,width:o.type==="region"?920:360,...o.type==="region"?{mode:"flow",columns:2,gap:24}:{}}),n=Math.max(n,e.layout[r].x+e.layout[r].width+64)),o.type==="region"&&t(o)}};return t(e.content),e.views??={initial:null,saved:[],readingOrder:(e.content.content??[]).map(a=>a.attrs.id)},e}function k2(e,{includeTitle:t=!0}={}){let a=structuredClone(e);if(Fs(a))return w2(yi(a));yi(a,{repairLegacy:!0});let n=a.content.content??[],o=n.filter(c=>!c.attrs?.canvas),r=new Set;Et(a.content,c=>{c.attrs?.id&&r.add(c.attrs.id)});let i=c=>{let d=U9(`${a.id}:${c}`);for(;r.has(d);)d+="-copy";return r.add(d),d},l=[],s={};if(o.length||t&&a.title){let c=i("initial-region");t&&a.title&&o.unshift({type:"heading",attrs:{id:i("legacy-title"),level:1},content:[{type:"text",text:a.title}]}),l.push({type:"region",attrs:{id:c,name:t&&a.title?a.title.slice(0,200):"\u5185\u5BB9\u533A\u57DF"},content:o}),s[c]={x:0,y:0,width:1e3,mode:"flow",columns:2,gap:24}}for(let c of n.filter(d=>d.attrs?.canvas)){let d=c.attrs.id;l.push({type:"region",attrs:{id:d,name:"\u5185\u5BB9\u533A\u57DF"},content:c.content??[]}),s[d]={...c.attrs.canvas,mode:"flow",columns:2,gap:24}}return a.content={type:"surface",content:l},a.layout=s,a.views={initial:null,saved:[],readingOrder:l.map(c=>c.attrs.id)},a}var hC=new WeakSet;function Ia(e,t={}){if(t.shareWith&&t.clone===!1)throw new TypeError("Structural sharing requires an independent normalization clone");let a=yC(e,t),n=t.shareWith?fm(t.shareWith,a):a;return hC.add(n),n}function yC(e,{clone:t=!0}={}){let a=w2(yi(t?structuredClone(e):e));if(Ua(a))return wm(a);if(!Fs(a))return a;let n=new Set,o=new Set;Et(a.content,s=>{s.attrs?.id&&n.add(s.attrs.id),s.type==="region"&&o.add(s.attrs.id)});for(let s of Object.keys(a.layout))if(!n.has(s))delete a.layout[s];else if(!o.has(s)){let{mode:c,columns:d,gap:u,...p}=a.layout[s];(c!==void 0||d!==void 0||u!==void 0)&&(a.layout[s]=p)}let r=(a.content.content??[]).map(s=>s.attrs.id),i=new Set(r),l=a.views.saved.map(s=>({...s,targets:s.targets.filter(c=>n.has(c))})).filter(s=>s.targets.length);return a.views={initial:l.some(s=>s.id===a.views.initial)?a.views.initial:null,saved:l,readingOrder:[...new Set([...a.views.readingOrder.filter(s=>i.has(s)),...r])]},a}function V9(e){if(Ua(e))return Ws(e);if(!Fs(e))return e.content.content??[];let t=e.content.content??[],a=e.views?.readingOrder??[],n=new Map(t.map(r=>[r.attrs?.id,r])),o=new Set(a);return[...a.map(r=>n.get(r)).filter(Boolean),...t.filter(r=>!o.has(r.attrs.id))]}function xm(e,t=()=>crypto.randomUUID()){let a=structuredClone(e),n=new Map;if(Et(a.content,o=>{if(["doc","text"].includes(o.type)||o.type==="surface"&&!Ua(a))return;let r=o.attrs?.id,i=t();r&&n.set(r,i),o.attrs={...o.attrs,id:i}}),Et(a.content,o=>{if(o.attrs?.outline&&(o.attrs.outline=H9(o.attrs.outline,n,t)),!o.attrs?.bindings)return;let r={};for(let i of["start","end"]){let l=o.attrs.bindings[i],s=l&&n.get(l.targetId);s&&(r[i]={...l,targetId:s})}Object.keys(r).length?o.attrs.bindings=r:delete o.attrs.bindings}),Fs(a)){if(a.layout=Object.fromEntries(Object.entries(a.layout??{}).map(([i,l])=>[n.get(i)??i,l])),Ua(a))return a.surfaceViews=Object.fromEntries(Object.entries(a.surfaceViews??{}).map(([i,l])=>{let s=new Map(l.saved.map(c=>[c.id,t()]));return[n.get(i),{initial:s.get(l.initial)??null,saved:l.saved.map(c=>({...c,id:s.get(c.id),targets:c.targets.map(d=>n.get(d))})),readingOrder:l.readingOrder.map(c=>n.get(c))}]})),a;let o=a.views??{initial:null,saved:[],readingOrder:[]},r=new Map(o.saved.map(i=>[i.id,t()]));a.views={initial:r.get(o.initial)??null,saved:o.saved.map(i=>({...i,id:r.get(i.id),targets:i.targets.map(l=>n.get(l)??l)})),readingOrder:o.readingOrder.map(i=>n.get(i)??i)}}return a}function S2(e){let t={},a=(n,o)=>{n.attrs?.id&&(t[n.attrs.id]=o);let r=n.attrs?.id?[...o,n.attrs.id]:o;n.content?.forEach(i=>a(i,r))};return a(e.content,[]),t}var Ua=e=>e.content?.type==="surface"&&["page","board"].includes(e.content.attrs?.kind),ta=e=>e.attrs?.kind==="board"?"board":"page",Z9=(e=[])=>({initial:null,saved:[],readingOrder:e.map(t=>t.attrs.id)}),km=(e,t=e.content)=>e.surfaceViews?.[t.attrs?.id]??e.views??Z9(t.content);function C2(e="page",t=e==="page"?"Page":"Board",a=crypto.randomUUID()){if(!["page","board"].includes(e))throw new Error("Surface kind must be page or board.");return{type:"surface",attrs:{id:a,kind:e,name:t},content:e==="page"?[{type:"richText",attrs:{id:crypto.randomUUID(),name:"\u5BCC\u6587\u672C"},content:[{type:"paragraph",attrs:{id:crypto.randomUUID()}}]}]:[]}}function Ws(e,t=e.content){let a=t.content??[];if(ta(t)==="page"||t.type!=="surface")return a;let n=km(e,t).readingOrder,o=new Map(a.map(i=>[i.attrs?.id,i])),r=new Set(n);return[...n.map(i=>o.get(i)).filter(Boolean),...a.filter(i=>!r.has(i.attrs.id))]}function vi(e){return Ua(e)&&(yi(e),e.layout={...e.layout??{}},e.surfaceViews={...e.surfaceViews??{}},e.views===void 0&&delete e.views,Et(e.content,t=>{if(!["surface","region"].includes(t.type))return;t.type==="surface"&&!Object.hasOwn(e.surfaceViews,t.attrs.id)&&(e.surfaceViews[t.attrs.id]=Z9(t.content));let a=0;for(let n of t.content??[]){if(!n.attrs?.id)continue;let o=t.type==="surface"?ta(t)==="board":e.layout[t.attrs.id]?.mode==="free";if(o||["surface","region"].includes(n.type)){Object.hasOwn(e.layout,n.attrs.id)||(e.layout[n.attrs.id]={x:a,y:0,width:n.type==="surface"?760:n.type==="region"?920:360,...n.type==="surface"?{height:460,heightMode:ta(n)==="page"&&!o?"auto":"fixed"}:{},...n.type==="region"?{mode:"flow",columns:2,gap:24}:{}});let r=e.layout[n.attrs.id];a=Math.max(a,r.x+r.width+48)}}})),e}function N1(e,{includeTitle:t=!0}={}){let a=structuredClone(e);if(Ua(a))return vi(a);let n=(()=>{let o=new Set;Et(a.content,s=>{s.attrs?.id&&o.add(s.attrs.id)});let r=`surface-${a.id.slice(0,150)}`,i=r,l=0;for(;o.has(i);)i=`${r}-${++l}`;return i})();if(a.content.type==="doc"){yi(a,{repairLegacy:!0});let o={},r=new Set;Et(a.content,l=>{l.attrs?.id&&r.add(l.attrs.id)});let i=(a.content.content??[]).map(l=>{if(!l.attrs?.canvas)return l;let s=l.attrs.canvas,c=`${l.attrs.id.slice(0,170)}-board`;for(;r.has(c);)c+="-copy";r.add(c);let d={type:"region",attrs:{id:l.attrs.id,name:"\u5185\u5BB9\u533A\u57DF"},content:l.content??[]};return o[d.attrs.id]={x:s.x??0,y:s.y??0,width:s.width??1e3,mode:"flow",columns:2,gap:24},o[c]={x:0,y:0,width:s.width??760,height:s.height??460,heightMode:"fixed"},{type:"surface",attrs:{id:c,kind:"board",name:"Board"},content:[d]}});a.content={type:"surface",attrs:{id:n,kind:"page",name:t&&a.title?a.title.slice(0,200):"Page"},content:i},a.layout=o,a.surfaceViews={}}else{let o=k2(a,{includeTitle:t});Object.assign(a,o);let r=a.content.content??[];if(r.length===1&&r[0].type==="region"&&(a.layout[r[0].attrs.id]?.mode??"flow")==="flow")return a.content.attrs={id:n,kind:"page",name:t&&a.title?a.title.slice(0,200):"Page"},a.surfaceViews={[n]:a.views},delete a.views,vi(a);let i=new Set;Et(a.content,s=>{s.attrs?.id&&i.add(s.attrs.id)});let l=`${n}-board`;for(;i.has(l);)l+="-copy";a.content.attrs={id:l,kind:"board",name:"Board"},a.surfaceViews={[l]:a.views},a.content={type:"surface",attrs:{id:n,kind:"page",name:t&&a.title?a.title.slice(0,200):"Page"},content:[a.content]},a.layout[l]={x:0,y:0,width:920,height:520,heightMode:"fixed"}}return delete a.views,vi(a)}function wm(e){vi(e);let t=new Map,a=new Map;Et(e.content,(n,o)=>{n.attrs?.id&&(t.set(n.attrs.id,n),a.set(n.attrs.id,o))});for(let[n,o]of Object.entries(e.layout)){let r=t.get(n);if(!r||r===e.content){delete e.layout[n];continue}let i={...o};Ho(a.get(n),e.layout)||delete i.rotation,r.type!=="region"&&(delete i.mode,delete i.columns,delete i.gap),r.type!=="surface"&&delete i.heightMode,(r.type==="drawing"||r.type==="surface"&&i.heightMode!=="auto")&&delete i.contentSize,JSON.stringify(o)!==JSON.stringify(i)&&(e.layout[n]=i)}for(let n of Object.keys(e.surfaceViews)){let o=t.get(n);if(o?.type!=="surface"){delete e.surfaceViews[n];continue}let r=new Set;Et(o,d=>{d.attrs?.id&&r.add(d.attrs.id)});let i=(o.content??[]).map(d=>d.attrs.id),l=new Set(i),s=e.surfaceViews[n],c=s.saved.map(d=>({...d,targets:d.targets.filter(u=>r.has(u)&&u!==n)})).filter(d=>d.targets.length);e.surfaceViews[n]={initial:c.some(d=>d.id===s.initial)?s.initial:null,saved:c,readingOrder:[...new Set([...s.readingOrder.filter(d=>l.has(d)),...i])]}}return fl(e)}function G9(e,t,a){let n=N1(e),o=Ke(n,t);if(o?.node.type!=="surface")throw new Error("Only a Page or Board can be wrapped.");o.node===n.content&&n.title&&["Page","Board"].includes(o.node.attrs.name)&&(o.node.attrs.name=n.title.slice(0,200));let r=C2(a);if(r.content=[o.node],o.parent){o.parent.content[o.parent.content.indexOf(o.node)]=r;let i=n.layout[t];i&&(n.layout[r.attrs.id]={...i,...a==="board"?{heightMode:"fixed",height:i.height??460}:{}})}else n.content=r;return n.layout[t]={x:0,y:0,width:760,height:520,heightMode:a==="page"&&ta(o.node)==="page"?"auto":"fixed"},wm(n)}var xi=(e,t,a)=>typeof e=="number"&&Number.isFinite(e)&&e>=t&&e<=a,wi=e=>{throw new Error(`Invalid logical ink source: ${e}`)};function Sm(e,t){if(t!==void 0){Bl(e),(!Array.isArray(t)||t.length>1024)&&wi("fragment list");for(let a of t){Bl(a);for(let n of["brushVersion","brush","width","opacity","extent","transform"])JSON.stringify(a[n])!==JSON.stringify(e[n])&&wi(`fragment ${n} must match its logical stroke`)}}}function Cm(e,t,a=[]){if(e===void 0)return;(!e||e.format!=="showai-input-v1"||typeof e.sourceID!="string"||!e.sourceID||e.sourceID.length>256||e.composite!=="single-opacity-coverage"||e.fragmentCount!==1+a.length||e.compositeOpacity!==t?.opacity)&&wi("source identity, fragment count or opacity"),Object.keys(e).some(i=>!["format","sourceID","configuration","raw","curves","fragmentCount","compositeOpacity","composite"].includes(i))&&wi("unknown source field");let n={width:[.5,40],creationZoom:[.001,1024],fitTolerance:[1e-6,1e4],flattenTolerance:[1e-6,1e4],positionWindow:[0,1],jitterWindow:[0,1],forceBackward:[0,1e4],forceForward:[0,1e4],forceTime:[0,1],minimumFraction:[0,10],maximumFraction:[0,10],curveBlend:[0,1],estimateTimeout:[0,10]},o=e.configuration;(!o||o.version!==1||![0,1,2].includes(o.mode)||Object.keys(o).some(i=>!["version","mode",...Object.keys(n)].includes(i))||Object.entries(n).some(([i,[l,s]])=>!xi(o[i],l,s))||o.maximumFraction<o.minimumFraction||o.width!==t.width)&&wi("input configuration"),(!Array.isArray(e.raw)||!e.raw.length||e.raw.length>1e6||!Array.isArray(e.curves)||e.curves.length>1e6)&&wi("raw input/curve count");let r=-1/0;for(let i of e.raw)(!Array.isArray(i)||i.length!==10||!xi(i[0],-1e6,1e6)||!xi(i[1],-1e6,1e6)||!xi(i[2],0,1e6)||i[2]<r||!xi(i[3],0,100)||!xi(i[4],-100,100)||!xi(i[5],-100,100)||i.slice(6,9).some(l=>!Number.isInteger(l)||l<0||l>4294967295)||![0,1].includes(i[9]))&&wi("raw actual point"),r=i[2];for(let i of e.curves)(!i||Object.keys(i).some(l=>!["points","firstRaw","lastRaw","steps"].includes(l))||!Array.isArray(i.points)||i.points.length!==8||i.points.some(l=>!xi(l,-1e6,1e6))||!Number.isInteger(i.firstRaw)||!Number.isInteger(i.lastRaw)||i.firstRaw<0||i.lastRaw<i.firstRaw||i.lastRaw>=e.raw.length||!Number.isInteger(i.steps)||i.steps<1||i.steps>1e7)&&wi("fitted curve provenance")}var Tm=["ink","inkFragments","color","strokeWidth","pressure"],vC=[...Tm,"node","layout","placement"],xC=(e,t)=>Object.hasOwn(e,t),wC=(e,t)=>e<t?-1:e>t?1:0,bl=e=>typeof e=="number"&&Number.isFinite(e),T2=e=>typeof e=="string"&&e.length>0&&e.length<=256&&!/[\u0000-\u001f]/.test(e),nr=e=>{throw new Error(`Invalid ink operation: ${e}`)};function D1(e){return e===null||typeof e=="string"||typeof e=="boolean"||bl(e)?JSON.stringify(e):Array.isArray(e)?`[${e.map(D1).join(",")}]`:e&&typeof e=="object"&&[Object.prototype,null].includes(Object.getPrototypeOf(e))?`{${Object.keys(e).sort(wC).map(t=>`${JSON.stringify(t)}:${D1(e[t])}`).join(",")}}`:nr("only finite JSON values are supported")}var $9=null,kC=e=>((typeof e!="string"||!/^[a-f0-9]{64}$/.test(e))&&nr("SHA-256 provider must return 64 lowercase hexadecimal characters synchronously"),e);function q9(e){let t=typeof e=="string"?e:D1(e);return $9?kC($9(t)):SC(t)}function SC(e){let t=[];for(let s of e){let c=s.codePointAt(0),d=c>=55296&&c<=57343?65533:c;d<128?t.push(d):d<2048?t.push(192|d>>6,128|d&63):d<65536?t.push(224|d>>12,128|d>>6&63,128|d&63):t.push(240|d>>18,128|d>>12&63,128|d>>6&63,128|d&63)}let a=t.length*8;for(t.push(128);t.length%64!==56;)t.push(0);for(let s=7;s>=0;--s)t.push(Math.floor(a/2**(s*8))&255);let n=[],o=[];for(let s=2;n.length<64;++s){let c=!0;for(let d=2;d*d<=s;++d)if(s%d===0){c=!1;break}c&&(o.length<8&&o.push(Math.floor(Math.sqrt(s)*2**32)>>>0),n.push(Math.floor(Math.cbrt(s)*2**32)>>>0))}let r=(s,c)=>s>>>c|s<<32-c,i=new Int32Array(64),l=o;for(let s=0;s<t.length;s+=64){for(let f=0;f<16;++f)i[f]=t[s+f*4]<<24|t[s+f*4+1]<<16|t[s+f*4+2]<<8|t[s+f*4+3];for(let f=16;f<64;++f){let m=i[f-15],v=i[f-2];i[f]=i[f-16]+(r(m,7)^r(m,18)^m>>>3)+i[f-7]+(r(v,17)^r(v,19)^v>>>10)}let[c,d,u,p,g,y,b,x]=l;for(let f=0;f<64;++f){let m=x+(r(g,6)^r(g,11)^r(g,25))+(g&y^~g&b)+n[f]+i[f],v=(r(c,2)^r(c,13)^r(c,22))+(c&d^c&u^d&u);x=b,b=y,y=g,g=p+m|0,p=u,u=d,d=c,c=m+v|0}[c,d,u,p,g,y,b,x].forEach((f,m)=>{l[m]=l[m]+f>>>0})}return l.map(s=>s.toString(16).padStart(8,"0")).join("")}function CC(e){(!e||!bl(e.x)||!bl(e.y)||!bl(e.width)||e.width<=0||e.height!==void 0&&(!bl(e.height)||e.height<=0)||e.rotation!==void 0&&!bl(e.rotation))&&nr("invalid stroke layout")}function F9(e,t){return[...vC,"alive"].includes(e)||nr("unsupported field"),TC(e,t)}function TC(e,t){Tm.includes(e)&&t===null||(e==="ink"?Bl(t):e==="inkFragments"?((!Array.isArray(t)||t.length>1024)&&nr("invalid ink fragments"),t.forEach(Bl)):e==="placement"&&(!t||!T2(t.parentId)||![t.after,t.before].every(a=>a===null||T2(a)))?nr("invalid stroke placement"):e==="node"&&(!t?.attrs||!T2(t.attrs.id)||Tm.some(a=>xC(t.attrs,a)))?nr("node metadata must exclude mutable ink attributes"):e==="layout"?CC(t):e==="color"&&(!T2(t)||t.length>128)?nr("invalid color"):e==="strokeWidth"&&(!bl(t)||t<.5||t>40)?nr("invalid stroke width"):e==="pressure"&&typeof t!="boolean"&&nr("invalid pressure flag"))}var EC="showai-ink-state-v1",zm=class extends Error{constructor(t){super(`Ink causal state: ${t}`),this.name="InkWireError",this.code="INK_CAUSAL_CONFLICT"}},Em=["node","ink","inkFragments","color","strokeWidth","pressure","layout","placement","alive"],E2=(e,t)=>Object.hasOwn(e,t);var Mm=e=>q9(e??null);var Va=e=>{throw new zm(e)},zC=/^([a-zA-Z0-9][a-zA-Z0-9_-]{0,95}):([1-9][0-9]*)$/;function Am(e){let t=zC.exec(e);return(!t||!Number.isSafeInteger(Number(t[2])))&&Va("invalid edit dot"),[t[1],Number(t[2])]}var AC=(e,t)=>{let[a,n]=Am(t);return(e[a]??0)>=n};var MC=Mm(!0),K9=Mm(!1),IC=e=>e?.fields?.alive?.some(([,t])=>t===K9)??!1;function W9(e){(!e||typeof e!="object"||Array.isArray(e)||Object.keys(e).length>512)&&Va("invalid causal clock");for(let[t,a]of Object.entries(e))(!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,95}$/.test(t)||!Number.isSafeInteger(a)||a<1)&&Va("invalid causal clock entry")}function Y9(e){D1(e),(e?.format!==EC||!Number.isSafeInteger(e.level)||e.level<0||!e.strokes||!e.contexts||Object.keys(e.strokes).length>1e5)&&Va("unsupported format or excessive state"),W9(e.clock);for(let[t,a]of Object.entries(e.contexts))Am(t),W9(a),(!AC(a,t)||Object.entries(a).some(([n,o])=>(e.clock[n]??0)<o))&&Va("context exceeds its causal clock");for(let[t,a]of Object.entries(e.levels??{}))(!E2(e.contexts,t)||!Number.isSafeInteger(a)||a<1)&&Va("invalid event level");for(let[t,a]of Object.entries(e.digests??{}))(!E2(e.contexts,t)||!/^[a-f0-9]{64}$/.test(a))&&Va("invalid event digest");for(let[t,a]of Object.entries(e.eventDigests??{}))(!E2(e.contexts,t)||!/^[a-f0-9]{64}$/.test(a))&&Va("invalid snapshot edit digest");for(let[t,a]of Object.entries(e.strokes)){(!t||["__proto__","prototype","constructor"].includes(t)||!Array.isArray(a.born)||a.born.length!==3||!Number.isSafeInteger(a.born[0])||a.born[0]<1||!Number.isSafeInteger(a.born[2])||a.born[2]<0)&&Va("invalid stroke identity"),Am(a.born[1]),a.unplaced!==void 0&&a.unplaced!==!0&&Va("invalid placement conflict marker"),a.fields?.alive?.length||Va("missing liveness heads");for(let[n,o]of Object.entries(a.fields)){(!Em.includes(n)||!Array.isArray(o)||!o.length||o.length>64)&&Va("invalid field heads");let r=new Set;for(let i of o)(!Array.isArray(i)||i.length!==2||!E2(e.contexts,i[0])||!/^[a-f0-9]{64}$/.test(i[1])||r.has(i[0]))&&Va("invalid head reference"),r.add(i[0]),n==="alive"&&![MC,K9].includes(i[1])&&Va("invalid liveness digest")}!IC(a)&&Em.filter(n=>n!=="inkFragments").some(n=>!a.fields[n]?.length)&&Va("visible stroke is missing field heads");for(let[n,o]of Object.entries(a.variants??{})){(!Em.includes(n)||!o||Array.isArray(o))&&Va("invalid conflict variants");for(let[r,i]of Object.entries(o))(Mm(i)!==r||!a.fields[n]?.some(([,l])=>r===l))&&Va("variant digest differs from its head"),n!=="alive"&&F9(n,i)}}return e}var NC=["rectangle","ellipse","arrow"];var J9=[14,16,22,30];function io(e){return e?.type==="drawing"&&NC.includes(e.attrs?.tool)&&!e.attrs?.ink}function z2(e,t=2){return e==="arrow"?4:Math.max(8,t+6)}function X9(e,t,a,n=2){let o=z2(e,n);if(e==="ellipse"){let r=(1-Math.SQRT1_2)/2;return{x:t*r+o/2,y:a*r+o/2,width:Math.max(1,t*Math.SQRT1_2-o),height:Math.max(1,a*Math.SQRT1_2-o)}}return{x:o,y:o,width:Math.max(1,t-o*2),height:Math.max(1,a-o*2)}}var DC=/[\u1100-\u115f\u2e80-\u303e\u3041-\u33ff\u3400-\u4dbf\u4e00-\u9fff\ua000-\ua4cf\uac00-\ud7a3\uf900-\ufaff\ufe30-\ufe4f\uff00-\uff60\uffe0-\uffe6]/;function OC(e){return DC.test(e)?1:e===" "?.3:/[A-Z0-9MW@#%&]/.test(e)?.64:.54}function Im(e,t=16,a){let n=0,o=0;for(let r of String(e).split(`
22
- `)){let i=0,l=1;for(let s of r){let c=OC(s)*t;a&&i+c>a&&i>0?(o=Math.max(o,i),i=c,l++):i+=c}o=Math.max(o,i),n+=l}return{width:Math.ceil(o),height:Math.ceil(n*t*1.3)}}function Q9(e,t,a=16,n,o=2){let r=z2(e,o),i=e==="ellipse"?Math.SQRT2:1,l=Im(t,a,n/i-r*2);return Math.ceil((l.height+r*2)*i)}var Nm=new Set(["__proto__","constructor","prototype"]),lo=(e,t)=>{if(!e||typeof e!="object"||Array.isArray(e))throw new Error(`${t} must be an object.`)},$t=(e,t,a,n)=>{if(typeof e!="number"||!Number.isFinite(e)||e<t||e>a)throw new Error(`${n} must be between ${t} and ${a}.`)};function th(e){if(Ua(e))return LC(e);let t=new Set,a=new Map;Et(e.content,n=>{if(["surface","text"].includes(n.type))return;let o=n.attrs?.id;if(typeof o!="string"||!o.trim()||o.length>200||Nm.has(o)||t.has(o))throw new Error("Whiteboard nodes require unique, non-reserved ids.");if(t.add(o),a.set(o,n),n.attrs?.canvas!=null)throw new Error("Whiteboard positions belong in layout, not attrs.canvas.")}),e.layout!==void 0&&lo(e.layout,"layout"),w2(e);for(let[n,o]of Object.entries(e.layout)){if(!t.has(n))throw new Error(`Layout references an unknown node: ${n}.`);if(lo(o,`layout.${n}`),Object.keys(o).some(r=>!["x","y","width","height","mode","columns","gap"].includes(r)))throw new Error(`Unsupported layout field for ${n}.`);if(o.rotation!==void 0){let r=a.get(n);if(!$n(r).rotate)throw new Error(`Rotation is not supported for ${n}.`);$t(o.rotation,-360,360,`layout.${n}.rotation`)}if($t(o.x,-1e6,1e6,`layout.${n}.x`),$t(o.y,-1e6,1e6,`layout.${n}.y`),$t(o.width,120,1e4,`layout.${n}.width`),o.height!==void 0&&$t(o.height,40,1e6,`layout.${n}.height`),o.mode!==void 0&&(a.get(n).type!=="region"||!["flow","grid","free"].includes(o.mode)))throw new Error(`Invalid region layout: ${n}.`);if(a.get(n).type!=="region"&&(o.columns!==void 0||o.gap!==void 0))throw new Error(`Only regions can define columns and gap: ${n}.`);if(o.columns!==void 0&&($t(o.columns,1,12,`layout.${n}.columns`),!Number.isInteger(o.columns)))throw new Error("Grid columns must be an integer.");o.gap!==void 0&&$t(o.gap,0,160,`layout.${n}.gap`)}ah(e.views,t,(e.content.content??[]).map(n=>n.attrs.id))}function ah(e,t,a){if(lo(e,"views"),Object.keys(e).some(i=>!["initial","saved","readingOrder"].includes(i)))throw new Error("Unsupported view configuration.");let{saved:n,readingOrder:o}=e;if(!Array.isArray(n)||n.length>100)throw new Error("At most 100 saved views are supported.");let r=new Set;for(let i of n){if(lo(i,"view"),Object.keys(i).some(l=>!["id","name","targets"].includes(l)))throw new Error("Unsupported saved view field.");if(typeof i.id!="string"||!i.id.trim()||i.id.length>200||Nm.has(i.id)||r.has(i.id))throw new Error("Saved views require unique ids.");if(r.add(i.id),typeof i.name!="string"||!i.name.trim()||i.name.length>200)throw new Error("Saved views require a name of at most 200 characters.");if(!Array.isArray(i.targets)||!i.targets.length||i.targets.length>1e3||new Set(i.targets).size!==i.targets.length||i.targets.some(l=>!t.has(l)))throw new Error("Saved view targets must reference existing nodes.")}if(e.initial??=null,e.initial!==null&&!r.has(e.initial))throw new Error("The initial view does not exist.");if(!Array.isArray(o)||new Set(o).size!==o.length||o.some(i=>!a.includes(i)))throw new Error("Reading order must contain unique root node ids.");e.readingOrder=[...o,...a.filter(i=>!o.includes(i))]}function LC(e){let t=new Set,a=new Map,n=new Map,o=new Map,r=(i,l,s)=>{if(i.type==="text")return;let c=i.attrs?.id;if(typeof c!="string"||!c.trim()||c.length>200||Nm.has(c)||t.has(c))throw new Error("Container nodes require unique, non-reserved ids.");if(t.add(c),a.set(c,i),n.set(c,l),o.set(c,s),i.attrs?.outline!==void 0&&x2(i.attrs.outline,i),i.attrs?.canvas!=null)throw new Error("Positions belong in layout.");if(c0(i),i.type==="surface"){if(!["page","board"].includes(i.attrs.kind))throw new Error("Surface kind must be page or board.");if(i.attrs.inkState!==void 0){if(i.attrs.kind!=="board")throw new Error("Causal ink metadata requires a Board.");Y9(i.attrs.inkState)}if(i.attrs.widthMode!==void 0&&(i.attrs.kind!=="page"||!["standard","wide","full"].includes(i.attrs.widthMode)))throw new Error("Page width mode must be standard, wide or full.");if(l&&!["surface","region"].includes(l.type))throw new Error("A surface requires a container parent.");if(i.attrs.frameless!==void 0&&(i.attrs.kind!=="page"||typeof i.attrs.frameless!="boolean"))throw new Error("Only Pages support the boolean frameless setting.");s=i}if(i.type==="drawing"){if(Sm(i.attrs.ink,i.attrs.inkFragments),Cm(i.attrs.inkInput,i.attrs.ink,i.attrs.inkFragments),i.attrs.ink!==void 0&&(l6(i.attrs.ink),i.attrs.tool!=="pen"&&!(yc(i.attrs.ink)&&i.attrs.tool==="highlighter")))throw new Error("Native ink uses the pen drawing tool.");if(s?.attrs.kind!=="board")throw new Error("Drawings belong inside a Board.");if(!["pen","highlighter","rectangle","ellipse","arrow"].includes(i.attrs.tool))throw new Error("Unknown drawing tool.");if(!(i.attrs.color==="none"&&["rectangle","ellipse"].includes(i.attrs.tool))&&!/^#[0-9a-fA-F]{6}$/.test(i.attrs.color))throw new Error("Drawing color must be a six-digit hex value, or none for a rectangle or ellipse.");if(i.attrs.fillColor!==void 0&&i.attrs.fillColor!=="none"&&!/^#[0-9a-fA-F]{6}$/.test(i.attrs.fillColor))throw new Error("Drawing fill must be none or a six-digit hex value.");if(!Array.isArray(i.attrs.extent)||i.attrs.extent.length!==2)throw new Error("Drawing extent requires width and height.");if(i.attrs.extent.forEach(d=>$t(d,1,1e6,"drawing.extent")),$t(i.attrs.strokeWidth,.5,40,"drawing.strokeWidth"),i.attrs.pressure!==void 0&&typeof i.attrs.pressure!="boolean")throw new Error("drawing.pressure must be boolean.");if(!Array.isArray(i.attrs.points)||i.attrs.points.length<2||i.attrs.points.length>2e4)throw new Error("A drawing needs 2\u201320000 points.");for(let d of i.attrs.points)lo(d,"drawing point"),$t(d.x,-1e6,1e6,"point.x"),$t(d.y,-1e6,1e6,"point.y"),d.pressure!==void 0&&$t(d.pressure,0,1,"point.pressure");if((i.attrs.label!==void 0||i.attrs.labelSize!==void 0)&&!io(i))throw new Error("Only rectangle, ellipse and arrow drawings can have a label.");if(i.attrs.label!==void 0&&(typeof i.attrs.label!="string"||!i.attrs.label.trim()||i.attrs.label.length>2e3))throw new Error(`drawing.label must be non-empty text of at most ${2e3} characters.`);i.attrs.labelSize!==void 0&&$t(i.attrs.labelSize,8,160,"drawing.labelSize")}for(let d of i.content??[])r(d,i,s)};r(e.content,null,null);for(let[i,l]of a)if(l.attrs?.bindings!==void 0){if(l.type!=="drawing"||l.attrs.tool!=="arrow")throw new Error("Only arrows can define endpoint bindings.");lo(l.attrs.bindings,"bindings");for(let[s,c]of Object.entries(l.attrs.bindings)){if(!["start","end"].includes(s))throw new Error("Unknown arrow endpoint.");if(lo(c,"binding"),Object.keys(c).some(u=>!["targetId","anchor"].includes(u)))throw new Error("Unsupported binding field.");let d=a.get(c.targetId);if(!d||n.get(i)!==n.get(c.targetId)||!$n(d).bindTarget)throw new Error("Arrow bindings require a non-arrow sibling target.");if(lo(c.anchor,"binding.anchor"),Object.keys(c.anchor).some(u=>!["x","y"].includes(u)))throw new Error("Unsupported anchor field.");$t(c.anchor.x,0,1,"binding.anchor.x"),$t(c.anchor.y,0,1,"binding.anchor.y")}}if(e.views!==void 0)throw new Error("Version 3 stores views per surface in surfaceViews.");e.layout!==void 0&&lo(e.layout,"layout"),e.surfaceViews!==void 0&&lo(e.surfaceViews,"surfaceViews"),vi(e);for(let[i,l]of a){let s=Object.values(l.attrs?.bindings??{});if(s.length&&(!Ho(n.get(i),e.layout)||!e.layout[i]||s.some(c=>!e.layout[c.targetId])))throw new Error("Arrow bindings require framed siblings in a Board or free-layout region.")}for(let[i,l]of Object.entries(e.layout)){let s=a.get(i),c=n.get(i);if(!s||!c||!["surface","region"].includes(c.type))throw new Error(`Layout requires a direct container child: ${i}.`);if(lo(l,`layout.${i}`),go(s)&&(l.mode!=="free"||!(l.height>0)||l.contentSize!==void 0))throw new Error("inkArchiveGroup requires a fixed free-layout frame.");if(Object.keys(l).some(d=>!["x","y","width","height","heightMode","rotation","contentSize","mode","columns","gap","locked"].includes(d)))throw new Error("Unsupported layout field.");if(l.locked!==void 0&&l.locked!==!0)throw new Error("layout.locked must be true when present.");if(l.contentSize!==void 0){if(lo(l.contentSize,"layout.contentSize"),s.type==="drawing"||s.type==="surface"&&l.heightMode!=="auto")throw new Error("Content size hints require content-sized objects.");if(Object.keys(l.contentSize).some(d=>!["width","height"].includes(d)))throw new Error("Unsupported content size hint.");$t(l.contentSize.width,1,1e4,"contentSize.width"),$t(l.contentSize.height,1,1e6,"contentSize.height")}if(l.rotation!==void 0){let d=a.get(i);if(!$n(d).rotate||l.rotation!==0&&!Ho(c,e.layout))throw new Error(`Rotation is not supported for ${i}.`);$t(l.rotation,-360,360,`layout.${i}.rotation`)}if($t(l.x,-1e6,1e6,`layout.${i}.x`),$t(l.y,-1e6,1e6,`layout.${i}.y`),$t(l.width,s.type==="drawing"||go(s)||(s.attrs?.nativeInk??s.attrs?.data?.nativeInk)?1:120,go(s)||s.attrs?.ink||(s.attrs?.nativeInk??s.attrs?.data?.nativeInk)?1e6:1e4,`layout.${i}.width`),l.height!==void 0&&$t(l.height,s.type==="drawing"||go(s)||(s.attrs?.nativeInk??s.attrs?.data?.nativeInk)?1:40,1e6,`layout.${i}.height`),l.heightMode!==void 0&&(s.type!=="surface"||!["fixed","auto"].includes(l.heightMode)||ta(s)==="board"&&l.heightMode==="auto"))throw new Error("Only embedded Pages support auto height; Boards use a fixed viewport.");if(s.type!=="region"&&["mode","columns","gap"].some(d=>l[d]!==void 0))throw new Error("Only regions can define mode, columns and gap.");if(l.mode!==void 0&&!["flow","grid","free"].includes(l.mode))throw new Error("Unknown region layout.");if(l.columns!==void 0&&($t(l.columns,1,12,"columns"),!Number.isInteger(l.columns)))throw new Error("Columns must be an integer.");l.gap!==void 0&&$t(l.gap,0,160,"gap")}for(let[i,l]of Object.entries(e.surfaceViews)){let s=a.get(i);if(s?.type!=="surface")throw new Error("View owner must be an existing surface.");let c=new Set;Et(s,d=>{d!==s&&d.attrs?.id&&c.add(d.attrs.id)}),ah(l,c,(s.content??[]).map(d=>d.attrs.id))}}var Da=e=>{throw new Error(e)},Om=e=>!!e&&typeof e=="object"&&!Array.isArray(e);function Na(e,t){(typeof e!="string"||!e.trim())&&Da(`${t} must be non-empty text.`)}function So(e,t){e!==void 0&&Na(e,t)}function Ks(e,t,a,n=0){return(!Array.isArray(e)||e.length<n||e.length>a)&&Da(`${t} must be an array of ${n} to ${a} items.`),e.forEach((o,r)=>{Om(o)||Da(`${t}[${r}] must be an object.`)}),e}function Dm(e,t,a){return e===void 0?[]:Ks(e,t,a)}function M2(e,t,a){Na(t,a),e.has(t)&&Da(`${a} duplicates id ${t}.`),e.add(t)}function A2(e,t,a){e.has(t)||Da(`${a} must name an existing part.`)}var nh=["new","changed","retired","kept"],oh=["input","action","result","note"],so={parts:6,steps:10,actions:12,entries:24,fields:8,blocks:8,callouts:6,details:10,sources:8};function RC(e,t,a,n){let o=`steps[${t}]`;M2(n,e.id,`${o}.id`),Na(e.label,`${o}.label`),Na(e.takeaway,`${o}.takeaway`),So(e.actionsHeading,`${o}.actionsHeading`),Ks(e.actions,`${o}.actions`,so.actions,1).forEach((l,s)=>{let c=`${o}.actions[${s}]`;Na(l.actor,`${c}.actor`),Na(l.text,`${c}.text`),So(l.code,`${c}.code`),l.kind!==void 0&&!oh.includes(l.kind)&&Da(`${c}.kind must be one of ${oh.join(", ")}.`),l.illustrative!==void 0&&typeof l.illustrative!="boolean"&&Da(`${c}.illustrative must be true or false.`)});let r=new Set;Dm(e.entries,`${o}.entries`,so.entries).forEach((l,s)=>{let c=`${o}.entries[${s}]`;M2(r,l.id,`${c}.id`),A2(a,l.partId,`${c}.partId`),Na(l.title,`${c}.title`),nh.includes(l.status)||Da(`${c}.status must be one of ${nh.join(", ")}.`),So(l.statusLabel,`${c}.statusLabel`),So(l.note,`${c}.note`),Ks(l.fields,`${c}.fields`,so.fields,1).forEach((d,u)=>{Na(d.label,`${c}.fields[${u}].label`),Na(d.value,`${c}.fields[${u}].value`),d.mono!==void 0&&typeof d.mono!="boolean"&&Da(`${c}.fields[${u}].mono must be true or false.`)})});let i=new Set;if(Dm(e.partNotes,`${o}.partNotes`,so.parts).forEach((l,s)=>{A2(a,l.partId,`${o}.partNotes[${s}].partId`),i.has(l.partId)&&Da(`${o}.partNotes has more than one note for ${l.partId}.`),i.add(l.partId),Na(l.text,`${o}.partNotes[${s}].text`)}),e.output!==void 0){let l=e.output;Om(l)||Da(`${o}.output must be an object.`),Na(l.heading,`${o}.output.heading`);let s=new Set,c=Ks(l.blocks,`${o}.output.blocks`,so.blocks,1);c.forEach((d,u)=>{let p=`${o}.output.blocks[${u}]`;M2(s,d.id,`${p}.id`),d.partId!==void 0&&A2(a,d.partId,`${p}.partId`),Na(d.label,`${p}.label`),Na(d.text,`${p}.text`),d.callouts!==void 0&&((!Array.isArray(d.callouts)||d.callouts.length>so.callouts)&&Da(`${p}.callouts must be an array of at most ${so.callouts} items.`),d.callouts.forEach((g,y)=>Na(g,`${p}.callouts[${y}]`)))}),l.hidePartId!==void 0&&(A2(a,l.hidePartId,`${o}.output.hidePartId`),c.some(d=>d.partId===l.hidePartId)||Da(`${o}.output.hidePartId must match the part of at least one block.`)),So(l.hideLabel,`${o}.output.hideLabel`),So(l.hideNote,`${o}.output.hideNote`)}e.details!==void 0&&((!Array.isArray(e.details)||e.details.length>so.details)&&Da(`${o}.details must be an array of at most ${so.details} items.`),e.details.forEach((l,s)=>Na(l,`${o}.details[${s}]`))),Dm(e.sources,`${o}.sources`,so.sources).forEach((l,s)=>{Na(l.label,`${o}.sources[${s}].label`),(typeof l.url!="string"||!/^https?:\/\//i.test(l.url))&&Da(`${o}.sources[${s}].url must be an http(s) URL.`)})}function I2(e){Om(e)||Da("Step walkthrough data must be an object."),Na(e.title,"title"),So(e.question,"question"),So(e.note,"note"),So(e.stateHeading,"stateHeading");let t=new Set;Ks(e.parts,"parts",so.parts,1).forEach((n,o)=>{M2(t,n.id,`parts[${o}].id`),Na(n.label,`parts[${o}].label`),So(n.plain,`parts[${o}].plain`),So(n.how,`parts[${o}].how`),n.tone!==void 0&&!kc.includes(n.tone)&&Da(`parts[${o}].tone must be one of ${kc.join(", ")}.`)});let a=new Set;return Ks(e.steps,"steps",so.steps,1).forEach((n,o)=>RC(n,o,t,a)),e.initialStep!==void 0&&!a.has(e.initialStep)&&Da("initialStep must name an existing step."),e}var ze=e=>{throw new Error(e)},Si=e=>!!e&&typeof e=="object"&&!Array.isArray(e),O1=e=>typeof e=="number"&&Number.isFinite(e),rh=["sum","product","average"],ih=["slider","stepper","toggle","choice"],Co={inputs:30,options:8,formulas:60,outputs:6,breakdown:12,presets:8,criteria:8,rankingItems:30,expression:500,depth:48},PC=/^[A-Za-z_][A-Za-z0-9_]*$/,Rm={min:[1,16],max:[1,16],round:[1,2],floor:[1,1],ceil:[1,1],abs:[1,1],sqrt:[1,1],clamp:[3,3],if:[3,3]},pA=Object.keys(Rm),BC=["<","<=",">",">=","==","!="];function jC(e){let t=[],a=0;for(;a<e.length;){let n=e.slice(a),o=/^\s+/.exec(n);if(o){a+=o[0].length;continue}let r=/^(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?/.exec(n);if(r){t.push({type:"num",value:Number(r[0]),at:a}),a+=r[0].length;continue}let i=/^[A-Za-z_][A-Za-z0-9_]*/.exec(n);if(i){t.push({type:"id",value:i[0],at:a}),a+=i[0].length;continue}let l=/^(?:<=|>=|==|!=|[-+*/^(),<>])/.exec(n);l||ze(`Unexpected character "${n[0]}" at position ${a+1}.`),t.push({type:"op",value:l[0],at:a}),a+=l[0].length}return t}function HC(e){(typeof e!="string"||!e.trim())&&ze("Expression must be non-empty text."),e.length>Co.expression&&ze(`Expression must be at most ${Co.expression} characters.`);let t=jC(e),a=0,n=0,o=()=>t[a],r=()=>o()?`position ${o().at+1}`:"the end of the expression",i=x=>o()?.type==="op"&&o().value===x,l=x=>{i(x)||ze(`Expected "${x}" at ${r()}.`),a+=1},s=x=>{n+=1,n>Co.depth&&ze("Expression is nested too deeply.");let f=x();return n-=1,f};function c(){let x=d();for(;o()?.type==="op"&&BC.includes(o().value);)x={type:"binary",op:t[a++].value,left:x,right:d()};return x}function d(){let x=u();for(;i("+")||i("-");)x={type:"binary",op:t[a++].value,left:x,right:u()};return x}function u(){let x=p();for(;i("*")||i("/");)x={type:"binary",op:t[a++].value,left:x,right:p()};return x}function p(){if(i("-")||i("+")){let x=t[a++].value;return s(()=>({type:"unary",op:x,arg:p()}))}return g()}function g(){let x=y();return i("^")?(a+=1,{type:"binary",op:"^",left:x,right:s(p)}):x}function y(){let x=o();if(x||ze("Expression ended unexpectedly."),x.type==="num")return a+=1,{type:"num",value:x.value};if(x.type==="id"){if(a+=1,!i("("))return{type:"ref",id:x.value};let f=Rm[x.value];f||ze(`Unknown function "${x.value}".`),a+=1;let m=[];if(!i(")"))for(m.push(s(c));i(",");)a+=1,m.push(s(c));return l(")"),(m.length<f[0]||m.length>f[1])&&ze(`${x.value}() takes ${f[0]===f[1]?f[0]:`${f[0]} to ${f[1]}`} argument(s).`),{type:"call",name:x.value,args:m}}if(x.value==="("){a+=1;let f=s(c);return l(")"),f}ze(`Unexpected "${x.value}" at ${r()}.`)}let b=c();return a<t.length&&ze(`Unexpected "${o().value}" at ${r()}.`),b}function lh(e){let t=new Set,a=n=>{n.type==="ref"?t.add(n.id):n.type==="unary"?a(n.arg):n.type==="binary"?(a(n.left),a(n.right)):n.type==="call"&&n.args.forEach(a)};return a(e),[...t]}function _C(e,t){let a=n=>{switch(n.type){case"num":return n.value;case"ref":{let o=t[n.id];return typeof o!="number"&&ze(`Unknown id "${n.id}".`),o}case"unary":return n.op==="-"?-a(n.arg):a(n.arg);case"binary":{let o=a(n.left),r=a(n.right);switch(n.op){case"+":return o+r;case"-":return o-r;case"*":return o*r;case"/":return o/r;case"^":return o**r;case"<":return o<r?1:0;case"<=":return o<=r?1:0;case">":return o>r?1:0;case">=":return o>=r?1:0;case"==":return o===r?1:0;default:return o!==r?1:0}}default:{if(n.name==="if")return a(n.args[0])?a(n.args[1]):a(n.args[2]);let o=n.args.map(a);switch(n.name){case"min":return Math.min(...o);case"max":return Math.max(...o);case"round":{let r=10**Math.max(0,Math.min(10,Math.round(o[1]??0)));return Math.round(o[0]*r)/r}case"floor":return Math.floor(o[0]);case"ceil":return Math.ceil(o[0]);case"abs":return Math.abs(o[0]);case"sqrt":return Math.sqrt(o[0]);default:return Math.min(Math.max(o[0],o[1]),o[2])}}}};return a(e)}var Ci=e=>e.type??"slider";function D2(e){let t=Ci(e);return t==="toggle"?e.value?1:0:t==="choice"?O1(e.value)?e.value:e.options[0].value:O1(e.value)?e.value:0}function O2(e,t){let a=Ci(e);return a==="toggle"?t?1:0:a==="choice"?e.options.some(n=>n.value===t)?t:D2(e):Math.min(e.max,Math.max(e.min,t))}function sh(e){return e.formulas===void 0&&e.outputs===void 0&&(e.operation!==void 0||e.ranking===void 0)}function ch(e,t){let a=new Map;e.forEach((i,l)=>{try{a.set(i.id,HC(i.expr))}catch(s){ze(`formulas[${l}].expr: ${s.message}`)}}),e.forEach((i,l)=>{for(let s of lh(a.get(i.id)))!t.has(s)&&!a.has(s)&&ze(`formulas[${l}].expr references unknown id "${s}".`)});let n=[],o=new Map,r=(i,l)=>{if(o.get(i)!=="done"){o.get(i)==="active"&&ze(`formulas contain a cycle: ${[...l.slice(l.indexOf(i)),i].join(" -> ")}.`),o.set(i,"active");for(let s of lh(a.get(i)))a.has(s)&&r(s,[...l,i]);o.set(i,"done"),n.push({id:i,tree:a.get(i)})}};for(let i of e)r(i.id,[]);return n}function Pm(e){let t=Array.isArray(e.inputs)?e.inputs:[];return ch(Array.isArray(e.formulas)?e.formulas:[],new Set(t.map(a=>a.id)))}function dh(e,t={},a=Pm(e)){let n=Object.create(null);for(let o of Array.isArray(e.inputs)?e.inputs:[])n[o.id]=O2(o,t[o.id]??D2(o));for(let{id:o,tree:r}of a)n[o]=_C(r,n);return n}function uh(e,t){let n=(e.breakdown?.items??[]).map(r=>({...r,value:t[r.formula]})),o=n.reduce((r,i)=>r+(Number.isFinite(i.value)?Math.abs(i.value):0),0);return n.map(r=>({...r,share:o&&Number.isFinite(r.value)?Math.abs(r.value)/o:0}))}function ph(e,t){let a=e.scale??10,n=e.criteria.map(r=>{let i=typeof r.weight=="string"?t[r.weight]:r.weight??1;return Number.isFinite(i)?Math.max(0,i):0}),o=n.reduce((r,i)=>r+i,0);return e.items.map((r,i)=>{let l=e.criteria.map((s,c)=>({id:s.id,value:o?n[c]*(r.scores[s.id]??0)*100/(o*a):0}));return{item:r,index:i,parts:l,score:l.reduce((s,c)=>s+c.value,0)}}).sort((r,i)=>i.score-r.score||r.index-i.index)}function mh(e,t={},a){if(!Number.isFinite(e))return"";let n=e/(t.divisor??1),o=t.decimals===void 0?{maximumFractionDigits:2}:{minimumFractionDigits:t.decimals,maximumFractionDigits:t.decimals},r=new Intl.NumberFormat(a,o).format(Math.abs(n)),i=Number(r.replace(/[^\d.]/g,""))===0;return`${n<0&&!i?"\u2212":t.signed?i?"\xB1":"+":""}${t.prefix??""}${r}${t.suffix??""}`}function fh(e,t,a=1e3){(typeof e!="string"||e.length>a)&&ze(`${t} must be text of at most ${a} characters.`)}function Jt(e,t,a){e!==void 0&&fh(e,t,a)}function N2(e,t){(typeof e!="string"||!e.trim()||e.length>200)&&ze(`${t} must be non-empty text of at most 200 characters.`)}function Ir(e,t){O1(e)||ze(`${t} must be a finite number.`)}function ki(e,t,a,n=0){return(!Array.isArray(e)||e.length<n||e.length>a)&&ze(`${t} must be an array of ${n} to ${a} items.`),e.forEach((o,r)=>{Si(o)||ze(`${t}[${r}] must be an object.`)}),e}function gh(e,t){e!==void 0&&!/^#[0-9a-fA-F]{6}$/.test(e)&&ze(`${t} must be a six-digit hex color.`)}function Lm(e,t){e!==void 0&&(Si(e)||ze(`${t} must be an object.`),Jt(e.prefix,`${t}.prefix`,20),Jt(e.suffix,`${t}.suffix`,20),e.decimals!==void 0&&(!Number.isInteger(e.decimals)||e.decimals<0||e.decimals>6)&&ze(`${t}.decimals must be an integer from 0 to 6.`),e.divisor!==void 0&&(!O1(e.divisor)||e.divisor<=0)&&ze(`${t}.divisor must be a positive number.`),e.signed!==void 0&&typeof e.signed!="boolean"&&ze(`${t}.signed must be true or false.`))}function UC(e,t){(typeof e.id!="string"||!e.id)&&ze(`${t}.id must be non-empty text.`),fh(e.label,`${t}.label`),Jt(e.unit,`${t}.unit`,40),Jt(e.hint,`${t}.hint`);let a=Ci(e);if(ih.includes(a)||ze(`${t}.type must be one of ${ih.join(", ")}.`),(a==="slider"||a==="stepper")&&(Ir(e.min,`${t}.min`),Ir(e.max,`${t}.max`),Ir(e.value,`${t}.value`),e.min>=e.max&&ze(`${t}.max must be greater than min.`),(a==="slider"||e.step!==void 0)&&(Ir(e.step,`${t}.step`),e.step<=0&&ze(`${t}.step must be greater than 0.`))),a==="toggle"&&e.value!==void 0&&e.value!==0&&e.value!==1&&ze(`${t}.value must be 0 or 1.`),a==="choice"){let n=ki(e.options,`${t}.options`,Co.options,2),o=new Set;n.forEach((r,i)=>{N2(r.label,`${t}.options[${i}].label`),Ir(r.value,`${t}.options[${i}].value`),Jt(r.note,`${t}.options[${i}].note`,200),o.has(r.value)&&ze(`${t}.options contains duplicate value ${r.value}.`),o.add(r.value)}),e.value!==void 0&&!o.has(e.value)&&ze(`${t}.value must equal one of the option values.`)}}function VC(e,t,a){Ir(t,a);let n=Ci(e);n==="toggle"&&t!==0&&t!==1&&ze(`${a} must be 0 or 1.`),n==="choice"&&!e.options.some(o=>o.value===t)&&ze(`${a} must equal one of the option values.`),(n==="slider"||n==="stepper")&&(t<e.min||t>e.max)&&ze(`${a} must be within ${e.min} to ${e.max}.`)}function ZC(e,t,a){Si(e)||ze(`${t} must be an object.`),typeof e.value=="string"?a.has(e.value)||ze(`${t}.value references unknown id "${e.value}".`):Ir(e.value,`${t}.value`),Jt(e.label,`${t}.label`,200),Jt(e.above,`${t}.above`,200),Jt(e.below,`${t}.below`,200)}function GC(e,t){Si(e)||ze("ranking must be an object."),Jt(e.title,"ranking.title",200),e.scale!==void 0&&(!O1(e.scale)||e.scale<=0)&&ze("ranking.scale must be a positive number.");let a=e.scale??10;e.decimals!==void 0&&(!Number.isInteger(e.decimals)||e.decimals<0||e.decimals>2)&&ze("ranking.decimals must be an integer from 0 to 2.");let n=ki(e.criteria,"ranking.criteria",Co.criteria,1),o=new Set;n.forEach((l,s)=>{let c=`ranking.criteria[${s}]`;(typeof l.id!="string"||!l.id)&&ze(`${c}.id must be non-empty text.`),o.has(l.id)&&ze(`ranking.criteria contains duplicate id ${l.id}.`),o.add(l.id),N2(l.label,`${c}.label`),Jt(l.hint,`${c}.hint`,200),gh(l.color,`${c}.color`),typeof l.weight=="string"?t.has(l.weight)||ze(`${c}.weight references unknown id "${l.weight}".`):l.weight!==void 0&&(Ir(l.weight,`${c}.weight`),l.weight<0&&ze(`${c}.weight must not be negative.`))});let r=ki(e.items,"ranking.items",Co.rankingItems,1),i=new Set;r.forEach((l,s)=>{let c=`ranking.items[${s}]`;(typeof l.id!="string"||!l.id)&&ze(`${c}.id must be non-empty text.`),i.has(l.id)&&ze(`ranking.items contains duplicate id ${l.id}.`),i.add(l.id),N2(l.label,`${c}.label`),Jt(l.note,`${c}.note`,300),Si(l.scores)||ze(`${c}.scores must be an object.`);for(let[d,u]of Object.entries(l.scores))o.has(d)||ze(`${c}.scores.${d} does not match a criterion id.`),Ir(u,`${c}.scores.${d}`),(u<0||u>a)&&ze(`${c}.scores.${d} must be within 0 to ${a}.`)})}function Ys(e){Si(e)||ze("Playground data must be an object."),Jt(e.title,"title",200),Jt(e.description,"description",2e3),Jt(e.resultLabel,"resultLabel",200),Jt(e.unit,"unit",40),Jt(e.note,"note",1e3),e.operation!==void 0&&!rh.includes(e.operation)&&ze(`operation must be one of ${rh.join(", ")}.`);let t=ki(e.inputs,"inputs",Co.inputs),a=new Set;if(t.forEach((n,o)=>{UC(n,`inputs[${o}]`),a.has(n.id)&&ze(`inputs contains duplicate id ${n.id}.`),a.add(n.id)}),e.formulas!==void 0){let n=ki(e.formulas,"formulas",Co.formulas);n.forEach((o,r)=>{let i=`formulas[${r}]`;(typeof o.id!="string"||!PC.test(o.id))&&ze(`${i}.id must start with a letter or _ and use only letters, digits and _.`),Rm[o.id]&&ze(`${i}.id "${o.id}" is a reserved function name.`),a.has(o.id)&&ze(`${i}.id ${o.id} duplicates another id.`),a.add(o.id),Jt(o.label,`${i}.label`,200),Jt(o.unit,`${i}.unit`,40),Lm(o.format,`${i}.format`),typeof o.expr!="string"&&ze(`${i}.expr must be text.`)}),ch(n,new Set(t.map(o=>o.id)))}if(e.outputs!==void 0&&ki(e.outputs,"outputs",Co.outputs,1).forEach((o,r)=>{let i=`outputs[${r}]`;a.has(o.formula)||ze(`${i}.formula references unknown id "${o.formula}".`),Jt(o.label,`${i}.label`,200),Jt(o.unit,`${i}.unit`,40),Jt(o.hint,`${i}.hint`,300),Lm(o.format,`${i}.format`),o.target!==void 0&&ZC(o.target,`${i}.target`,a)}),e.breakdown!==void 0){Si(e.breakdown)||ze("breakdown must be an object."),Jt(e.breakdown.title,"breakdown.title",200),Lm(e.breakdown.format,"breakdown.format");let n=ki(e.breakdown.items,"breakdown.items",Co.breakdown,1),o=new Set;n.forEach((r,i)=>{let l=`breakdown.items[${i}]`;a.has(r.formula)||ze(`${l}.formula references unknown id "${r.formula}".`),o.has(r.formula)&&ze(`breakdown.items repeats ${r.formula}.`),o.add(r.formula),Jt(r.label,`${l}.label`,200),gh(r.color,`${l}.color`)})}if(e.presets!==void 0){let n=ki(e.presets,"presets",Co.presets,1),o=new Map(t.map(r=>[r.id,r]));n.forEach((r,i)=>{let l=`presets[${i}]`;N2(r.label,`${l}.label`),(!Si(r.values)||!Object.keys(r.values).length)&&ze(`${l}.values must be an object with at least one input value.`);for(let[s,c]of Object.entries(r.values)){let d=o.get(s);d||ze(`${l}.values.${s} does not match an input id.`),VC(d,c,`${l}.values.${s}`)}})}return e.ranking!==void 0&&GC(e.ranking,a),e}var Vt=e=>{throw new Error(e)},Bm=e=>!!e&&typeof e=="object"&&!Array.isArray(e),$C=new Set(["id","__proto__","prototype","constructor"]),bh=["text","number","select","checkbox","url","date"],hh=["table","board","calendar"],yh=["month","week","heatmap"],L2=53,qC=366,R2=864e5;function Ti(e){if(typeof e!="string")return null;let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!t)return null;let[a,n,o]=t.slice(1).map(Number),r=Date.UTC(a,n-1,o),i=new Date(r);return i.getUTCMonth()!==n-1||i.getUTCDate()!==o?null:Math.round(r/R2)}function P2(e){return new Date(e*R2).toISOString().slice(0,10)}function xh(e=new Date){return Math.round(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate())/R2)}function FC(e){return new Date(e*R2).getUTCDay()}function hl(e,t=1){return e-(FC(e)-t+7)%7}function wh(e){if(typeof e!="string")return"";let t=/^\s*(\d{4})[-/.](\d{1,2})[-/.](\d{1,2})/.exec(e);if(!t)return"";let a=`${t[1]}-${t[2].padStart(2,"0")}-${t[3].padStart(2,"0")}`;return Ti(a)===null?"":a}function vh(e){if(typeof e!="string")return null;let t=/^(\d{1,2}):(\d{2})$/.exec(e.trim());if(!t)return null;let a=Number(t[1])*60+Number(t[2]);return Number(t[2])<60&&a<=1440?a:null}function WC(e,t){Bm(e)||Vt("calendar must be an object.");let a=(n,o)=>{let r=e[n];if(r===void 0)return;typeof r!="string"&&Vt(`calendar.${n} must be a column id string.`);let i=t.find(l=>l.id===r);i||Vt(`calendar.${n} refers to missing column ${r}.`),o.includes(i.type)||Vt(`calendar.${n} must refer to a ${o.join(" or ")} column.`)};a("dateColumn",["date"]),a("endDateColumn",["date"]),a("startTimeColumn",["text"]),a("endTimeColumn",["text"]),a("colorColumn",["select"]),a("doneColumn",["checkbox"]),e.endDateColumn!==void 0&&e.endDateColumn===e.dateColumn&&Vt("calendar.endDateColumn must differ from calendar.dateColumn."),e.endTimeColumn!==void 0&&!e.startTimeColumn&&Vt("calendar.endTimeColumn requires calendar.startTimeColumn."),e.mode!==void 0&&!yh.includes(e.mode)&&Vt(`calendar.mode must be one of ${yh.join(", ")}.`),e.initialDate!==void 0&&Ti(e.initialDate)===null&&Vt("calendar.initialDate must be a YYYY-MM-DD date."),e.weekStartsOn!==void 0&&![0,1].includes(e.weekStartsOn)&&Vt("calendar.weekStartsOn must be 0 (Sunday) or 1 (Monday)."),e.weeks!==void 0&&(!Number.isInteger(e.weeks)||e.weeks<1||e.weeks>L2)&&Vt(`calendar.weeks must be an integer from 1 to ${L2}.`);for(let n of Object.keys(e))["dateColumn","endDateColumn","startTimeColumn","endTimeColumn","colorColumn","doneColumn","mode","initialDate","weekStartsOn","weeks"].includes(n)||Vt(`calendar.${n} is not a supported setting.`)}function B2(e){Bm(e)||Vt("Component data must be an object.");for(let o of["title","description","groupBy"])e[o]!==void 0&&(typeof e[o]!="string"||e[o].length>1e4)&&Vt(`${o} must be text, at most 10000 characters.`);let t=(o,r)=>{if(e[o]===void 0)return[];(!Array.isArray(e[o])||e[o].length>r)&&Vt(`${o} must be an array of at most ${r} items.`);let i=new Set;for(let[l,s]of e[o].entries())Bm(s)||Vt(`${o}[${l}] must be an object.`),(typeof s.id!="string"||!s.id||s.id.length>200)&&Vt(`${o}[${l}].id must be non-empty text.`),i.has(s.id)&&Vt(`${o} contains duplicate id ${s.id}.`),$C.has(s.id)&&(o==="columns"||s.id!=="id")&&Vt(`${o}[${l}].id cannot use the reserved name ${s.id}.`),i.add(s.id);return e[o]},a=t("columns",50);for(let[o,r]of a.entries()){let i=`columns[${o}]`;(typeof r.name!="string"||r.name.length>1e3)&&Vt(`${i}.name must be text, at most 1000 characters.`),bh.includes(r.type)||Vt(`${i}.type must be one of ${bh.join(", ")}.`),r.options!==void 0&&(!Array.isArray(r.options)||r.options.length>200||!r.options.every(l=>typeof l=="string"))&&Vt(`${i}.options must be an array of at most 200 texts.`)}let n=a.filter(o=>o.type==="date");for(let[o,r]of t("rows",5e3).entries()){for(let[i,l]of Object.entries(r))["string","number","boolean"].includes(typeof l)||Vt(`rows[${o}].${i} must be text, a number or a boolean.`);for(let i of n){let l=r[i.id];l!==void 0&&l!==""&&Ti(l)===null&&Vt(`rows[${o}].${i.id} must be a YYYY-MM-DD date or empty.`)}}return e.view!==void 0&&!hh.includes(e.view)&&Vt(`view must be one of ${hh.join(", ")}.`),e.calendar!==void 0&&WC(e.calendar,a),e.view==="calendar"&&!n.length&&Vt("view calendar requires a date column."),e}function kh(e,t){let a=[];for(let n of e){let o=Ti(n[t.dateColumn]);if(o===null)continue;let r=t.endDateColumn?Ti(n[t.endDateColumn]):null;(r===null||r<o||r-o>=qC)&&(r=o);let i=t.startTimeColumn?vh(n[t.startTimeColumn]):null,l=i!==null&&t.endTimeColumn?vh(n[t.endTimeColumn]):null;l!==null&&l<=i&&(l=null),a.push({row:n,start:o,end:r,startMinute:i,endMinute:l,done:t.doneColumn?n[t.doneColumn]===!0:!1})}return a.sort((n,o)=>n.start-o.start||(n.startMinute??-1)-(o.startMinute??-1)||o.end-n.end)}function jm(e,t,a){let n=new Map;for(let o=t;o<=a;o+=1)n.set(o,[]);for(let o of e)for(let r=Math.max(t,o.start);r<=Math.min(a,o.end);r+=1)n.get(r).push(o);return n}function Sh(e){let t=[];return{placed:e.filter(n=>n.startMinute!==null).map(n=>{let o=n.endMinute??Math.min(1440,n.startMinute+60),r=t.findIndex(i=>i<=n.startMinute);return r<0?r=t.push(o)-1:t[r]=o,{entry:n,lane:r,end:o}}),laneCount:Math.max(1,t.length)}}function Ch(e,t){let a=t.weekStartsOn??1,n=t.weeks??12,o=hl(t.endDay,a)-(n-1)*7,r=o+n*7-1,i=t.countDone?e.filter(x=>x.done):e,l=jm(i,o,r),s=[],c=0;for(let x=o;x<=r;x+=1){let f=l.get(x).length;c=Math.max(c,f),s.push({day:x,count:f})}for(let x of s)x.level=x.count?Math.max(1,Math.ceil(x.count/c*4)):0;let d=Math.min(r,t.today),u=0,p=0,g=0;for(let x=o;x<=d;x+=1){let f=l.get(x).length>0;f&&(g+=1),p=f?p+1:0,u=Math.max(u,p)}let y=0,b=d;for(b>=o&&b===t.today&&!l.get(b).length&&(b-=1);b>=o&&l.get(b).length;b-=1)y+=1;return{from:o,to:r,cells:s,max:c,current:y,longest:u,activeDays:g,elapsedDays:Math.max(0,d-o+1)}}var j2={video:["video/mp4","video/webm","video/ogg","video/quicktime"],audio:["audio/mpeg","audio/mp4","audio/wav","audio/x-wav","audio/ogg","audio/webm","audio/flac","audio/aac"],pdf:["application/pdf"]},Th=Lt.resourceBytes;function KC(e,t){let a=typeof t=="string"&&t.match(/^data:([^;,]+);base64,[a-z\d+/=\s]+$/i);return a&&j2[e]?.includes(a[1].toLowerCase())?a[1].toLowerCase():void 0}function Ei(e,t){if(!(typeof t!="string"||/^[\u0000-\u0020]|[\u0000-\u001f]/.test(t))){if(KC(e,t))return t;try{let a=new URL(t);if(["http:","https:"].includes(a.protocol))return a.href}catch{}}}function Eh(e,t){let n={mp4:"video/mp4",webm:e==="audio"?"audio/webm":"video/webm",ogv:"video/ogg",mov:"video/quicktime",mp3:"audio/mpeg",m4a:"audio/mp4",wav:"audio/wav",oga:"audio/ogg",ogg:e==="video"?"video/ogg":"audio/ogg",flac:"audio/flac",aac:"audio/aac",pdf:"application/pdf"}[t.name.split(".").pop()?.toLowerCase()];return n&&j2[e]?.includes(n)?n:j2[e]?.includes(t.type)?t.type:void 0}function Hm(e){let t=e.doi?.trim().replace(/^https?:\/\/(?:dx\.)?doi\.org\//i,""),a=e.url||(t?`https://doi.org/${t}`:"");return Ei("pdf",a)}function To(e,t){if(!t||typeof t!="object"||Array.isArray(t))throw new Error("\u7EC4\u4EF6\u6570\u636E\u5FC5\u987B\u662F\u5BF9\u8C61\u3002");let a=(n,o,r=1e4)=>{if(n!==void 0&&(typeof n!="string"||n.length>r))throw new Error(`${o}\u5FC5\u987B\u662F\u6587\u5B57\uFF0C\u957F\u5EA6\u4E0D\u8D85\u8FC7 ${r}\u3002`)};if(["title","description","caption","fileName"].forEach(n=>a(t[n],n)),e==="references"){if(!Array.isArray(t.items)||t.items.length>500)throw new Error("\u53C2\u8003\u6587\u732E\u6700\u591A\u652F\u6301 500 \u6761\u3002");let n=new Set;for(let o of t.items){if(!o||typeof o!="object"||Array.isArray(o))throw new Error("\u53C2\u8003\u6587\u732E\u6761\u76EE\u5FC5\u987B\u662F\u5BF9\u8C61\u3002");if(typeof o.id!="string"||!o.id.trim()||n.has(o.id)||["__proto__","constructor","prototype"].includes(o.id))throw new Error("\u53C2\u8003\u6587\u732E\u9700\u8981\u4E0D\u91CD\u590D\u7684 id\u3002");if(n.add(o.id),typeof o.title!="string"||!o.title.trim())throw new Error("\u53C2\u8003\u6587\u732E\u9700\u8981\u6807\u9898\u3002");for(let r of["id","title","authors","year","venue","doi","url","note"])a(o[r],r);if(o.url&&!Ei("pdf",o.url))throw new Error("\u6587\u732E\u94FE\u63A5\u9700\u8981 http \u6216 https \u7F51\u5740\u3002");if(o.doi&&!/^10\.\d{4,9}\/\S+$/i.test(o.doi.replace(/^https?:\/\/(?:dx\.)?doi\.org\//i,"")))throw new Error("DOI \u683C\u5F0F\u5E94\u4E3A 10.xxxx/\u2026\u3002")}return}if(!j2[e])throw new Error(`\u672A\u77E5\u7684\u6587\u4EF6\u7EC4\u4EF6\uFF1A${e}`);if(t.src!==void 0&&t.src!==""&&!Ei(e,t.src))throw new Error("\u6587\u4EF6\u9700\u8981 http\u3001https \u6216\u5339\u914D\u6587\u4EF6\u7C7B\u578B\u7684\u5185\u5D4C\u5730\u5740\u3002");if(t.poster&&!(Ei("pdf",t.poster)||/^data:image\/(png|jpeg|gif|webp|avif);base64,[a-z\d+/=\s]+$/i.test(t.poster)))throw new Error("\u5C01\u9762\u9700\u8981\u6709\u6548\u56FE\u7247\u5730\u5740\u3002");if(t.page!==void 0&&(!Number.isInteger(t.page)||t.page<1||t.page>1e5))throw new Error("\u521D\u59CB\u9875\u7801\u5FC5\u987B\u662F\u6B63\u6574\u6570\u3002");if(t.height!==void 0&&(typeof t.height!="number"||!Number.isFinite(t.height)||t.height<240||t.height>1200))throw new Error("\u9605\u8BFB\u533A\u9AD8\u5EA6\u9700\u8981\u5728 240 \u5230 1200 \u4E4B\u95F4\u3002");if(t.aspectRatio!==void 0&&!["16:9","4:3","1:1","9:16"].includes(t.aspectRatio))throw new Error("\u753B\u9762\u6BD4\u4F8B\u4E0D\u53D7\u652F\u6301\u3002");for(let n of["loop","muted"])if(t[n]!==void 0&&typeof t[n]!="boolean")throw new Error(`${n}\u5FC5\u987B\u662F\u5E03\u5C14\u503C\u3002`)}var zh=Lt.publicationBytes,_m=/^sha256-[a-f0-9]{64}$/,YC=/^[a-z][a-z0-9-]{0,79}$/,JC=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[a-zA-Z0-9.-]+)?$/;function H2(e){return`${e.kind}:${e.id}@${e.version}#${e.integrity}`}function Um(e,t){if(!e||typeof e!="object"||Array.isArray(e)||!["component","template"].includes(e.kind)||t&&e.kind!==t||typeof e.id!="string"||typeof e.version!="string"||typeof e.integrity!="string"||!YC.test(e.id)||!JC.test(e.version)||!_m.test(e.integrity))throw new Error("A publication requires an exact kind/id/version/integrity reference.");if(e.scope!==void 0&&!["project","global","published","builtin"].includes(e.scope))throw new Error("Invalid publication reference scope.");if(e.projectId!==void 0&&(typeof e.projectId!="string"||!/^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/.test(e.projectId)))throw new Error("Invalid publication project reference.");return{kind:e.kind,id:e.id,version:e.version,integrity:e.integrity,...e.scope?{scope:e.scope}:{},...e.projectId?{projectId:e.projectId}:{}}}function Vm(e){if(typeof e!="string"||e.length>8192)throw new Error("Publication URL must be an HTTPS URL or a loopback HTTP URL.");let t=new URL(e),a=t.hostname.split("."),n=t.hostname==="localhost"||t.hostname==="[::1]"||a.length===4&&a[0]==="127"&&a.every(o=>/^\d+$/.test(o)&&Number(o)<=255);if(t.username||t.password||t.hash||t.protocol!=="https:"&&!(t.protocol==="http:"&&n))throw new Error("Publications require HTTPS; HTTP is allowed only on loopback. Credentials, fragments and file URLs are forbidden.");return t.href}function _2(e){if(!Array.isArray(e)||e.length>100)throw new Error("remoteComponents must contain at most 100 locked locators.");let t=new Set;return e.map(a=>{if(!a||typeof a!="object"||Array.isArray(a))throw new Error("Invalid published component locator.");let n=Um(a.ref,"component"),o=H2(n);if(t.has(o))throw new Error(`Duplicate remote component: ${o}`);if(t.add(o),!_m.test(a.sha256)||!_m.test(a.manifestIntegrity)||!Number.isSafeInteger(a.bytes)||a.bytes<1||a.bytes>zh||typeof a.verifiedAt!="string"||!Number.isFinite(Date.parse(a.verifiedAt)))throw new Error("Remote components require verified byte length, SHA-256 and publication metadata.");return{ref:n,bundleRef:Um(a.bundleRef),url:Vm(a.url),sha256:a.sha256,bytes:a.bytes,manifestUrl:Vm(a.manifestUrl),manifestIntegrity:a.manifestIntegrity,verifiedAt:a.verifiedAt}})}async function XC(e){if(!globalThis.crypto?.subtle)throw Object.assign(new Error("\u7EC4\u4EF6\u5B8C\u6574\u6027\u6821\u9A8C\u9700\u8981 HTTPS \u6216\u5728\u672C\u673A\u6253\u5F00\u9875\u9762\u3002"),{code:"INTEGRITY_UNAVAILABLE"});let t=await globalThis.crypto.subtle.digest("SHA-256",e);return"sha256-"+[...new Uint8Array(t)].map(a=>a.toString(16).padStart(2,"0")).join("")}async function QC(e,t={}){let a=Vm(e),n=await fetch(a,{credentials:"omit",mode:"cors",redirect:"error",cache:"no-store",referrerPolicy:"no-referrer",headers:{Accept:"application/json"},signal:t.signal?AbortSignal.any([t.signal,AbortSignal.timeout(15e3)]):AbortSignal.timeout(15e3)});if(!n.ok)throw new Error(`Published component request failed (${n.status}): ${a}`);if(t.requireCors&&n.headers.get("access-control-allow-origin")!=="*")throw new Error(`Publication must serve Access-Control-Allow-Origin: * so portable readers can load it: ${a}`);let o=t.maxBytes??zh;if(!n.body)throw new Error("Published bundle response has no body.");let r=n.body.getReader(),i=[],l=0;for(;;){let{value:d,done:u}=await r.read();if(u)break;if(l+=d.byteLength,l>o)throw await r.cancel(),new Error("Published bundle exceeds its size limit.");i.push(d)}let s=new Uint8Array(l),c=0;for(let d of i)s.set(d,c),c+=d.byteLength;return{bytes:s,text:new TextDecoder("utf-8",{fatal:!0}).decode(s),sha256:await XC(s),cors:n.headers.get("access-control-allow-origin")}}async function Ah(e,t={}){let a=_2(e),n=new Map,o=0,r=[];for(let i of a){let l=`${i.url}#${i.sha256}`,s=n.get(l);if(!s){let d;try{d=await QC(i.url,{signal:t.signal,maxBytes:i.bytes})}catch(u){throw Object.assign(new Error(`\u65E0\u6CD5\u52A0\u8F7D\u7EC4\u4EF6 ${i.ref.id}@${i.ref.version}\uFF1A${u instanceof Error?u.message:"\u7F51\u7EDC\u8BF7\u6C42\u5931\u8D25"}\u3002\u8BF7\u68C0\u67E5\u7F51\u7EDC\u548C\u53D1\u5E03\u670D\u52A1\u5668\u7684 CORS \u8BBE\u7F6E\u3002`,{cause:u}),{code:"COMPONENT_FETCH_FAILED",params:{component:`${i.ref.id}@${i.ref.version}`,reason:u instanceof Error?u.message:""}})}if(d.bytes.byteLength!==i.bytes||d.sha256!==i.sha256)throw Object.assign(new Error(`\u7EC4\u4EF6 ${i.ref.id}@${i.ref.version} \u7684\u6587\u4EF6\u6821\u9A8C\u5931\u8D25\uFF08SHA-256 \u6216\u5B57\u8282\u6570\u4E0D\u4E00\u81F4\uFF09\u3002`),{code:"COMPONENT_CHECKSUM_FAILED",params:{component:`${i.ref.id}@${i.ref.version}`}});if(o+=d.bytes.byteLength,o>Lt.publicationTransferBytes)throw new Error("Remote component downloads exceed the 512 MiB limit.");if(s=JSON.parse(d.text),s?.format!=="showai-catalog-bundle"||s.version!==1||!Array.isArray(s.components))throw new Error("Unsupported published component bundle.");n.set(l,s)}if(H2(Um(s.root))!==H2(i.bundleRef))throw new Error(`Published bundle revision does not match ${i.ref.id}@${i.ref.version}.`);let c=s.components.map(d=>d?.component).find(d=>d?.id===i.ref.id&&d?.version===i.ref.version&&d?.integrity===i.ref.integrity);if(!c||typeof c.html!="string"||!c.html.includes("<!--SHOWAI_COMPONENT_DATA-->")||c.schema===void 0||typeof c.name!="string")throw new Error(`Published bundle does not contain the exact component revision ${H2(i.ref)}.`);r.push(c)}return r}var ZA=Lt.artifactBytes;var Gm=12e3,Ih=48,Nh=new Set(["__proto__","prototype","constructor"]),tT=new Set(["doc","surface","drawing","region","richText","paragraph","text","heading","blockquote","bulletList","orderedList","listItem","taskList","taskItem","codeBlock","hardBreak","mathInline","mathBlock","horizontalRule","image","table","tableRow","tableCell","tableHeader","callout","toggle","stepper","step","widget"]),aT=new Set(["bold","italic","strike","code","underline","link","highlight","textStyle","annotation"]),Zm=new Set(["id","level","textAlign","align","type","start","checked","language","src","alt","title","width","height","colspan","rowspan","colwidth","backgroundColor","open","summary","icon","tone","kind","data","canvas","name","frameless","latex","display","componentStyle","caption","fit","nativeInk"]),nT=new Set(["href","title","target","rel","class","color","backgroundColor","fontFamily","fontSize","mode","note"]);function Za(e,t){if(e===null||typeof e!="object"||Array.isArray(e))throw new Error(`${t} must be an object.`);return e}function Xt(e,t,a=1e6){if(typeof e!="string"||e.length>a)throw new Error(`${t} must be text, at most ${a} characters.`);return e}function zi(e,t=!1){if(typeof e!="string")return!1;if(t&&/^data:image\/(?:png|jpeg|gif|webp|avif);base64,[a-z\d+/=\s]+$/i.test(e)||!t&&e.startsWith("#"))return!0;if(/^[\u0000-\u0020]|[\u0000-\u001f]/.test(e))return!1;try{let a=new URL(e);return(t?["http:","https:"]:["http:","https:","mailto:","tel:"]).includes(a.protocol)}catch{return!1}}function U2(e,t,a=0){if(a>Ih)throw new Error(`${t} is nested too deeply.`);if(!(e===null||typeof e=="boolean")){if(typeof e=="number"){if(!Number.isFinite(e))throw new Error(`${t} must be a finite number.`);return}if(typeof e=="string"){Xt(e,t,Lt.authoringRequestBytes);return}if(Array.isArray(e)){if(e.length>Gm)throw new Error(`${t} contains too many items.`);e.forEach((n,o)=>U2(n,`${t}[${o}]`,a+1));return}if(Za(e,t),Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw new Error(`${t} must contain plain JSON objects.`);for(let[n,o]of Object.entries(e)){if(Nh.has(n))throw new Error(`${t} contains a reserved key.`);U2(o,`${t}.${n}`,a+1)}}}function Mh(e,t,a,n=!1){Za(e,t);for(let[o,r]of Object.entries(e)){if(!a.has(o))throw new Error(`Unsupported attribute ${t}.${o}.`);if(r!=null){if(o==="href"&&!zi(r))throw new Error(`${t}.href must be a safe web, email, or anchor URL.`);if(o==="src"&&r!==""&&!zi(r,!0))throw new Error(`${t}.src must be a web URL or embedded raster image.`);if(["textAlign","align"].includes(o)&&!["left","center","right","justify"].includes(r))throw new Error(`${t}.${o} is not supported.`);if(o==="level"&&![1,2,3,4,5,6].includes(r))throw new Error(`${t}.level must be 1 through 6.`);if(o==="type"&&!["1","a","A","i","I"].includes(r))throw new Error(`${t}.type must be an ordered-list marker style.`);if(["open","checked"].includes(o)&&typeof r!="boolean")throw new Error(`${t}.${o} must be true or false.`);if(["colspan","rowspan","start"].includes(o)&&(!Number.isInteger(r)||r<1||r>1e4))throw new Error(`${t}.${o} must be a positive integer.`);if(["id","language","alt","title","summary","icon","tone","kind","target","rel","class"].includes(o)&&Xt(r,`${t}.${o}`,o==="icon"&&n?1e6:1e4),["width","height"].includes(o)&&!(typeof r=="number"&&Number.isFinite(r)&&r>0&&r<=1e4)&&!(typeof r=="string"&&/^\d{1,5}(?:px|%)?$/.test(r)))throw new Error(`${t}.${o} must be a positive image dimension.`);if(o==="colwidth"&&(!Array.isArray(r)||r.length>100||!r.every(i=>Number.isInteger(i)&&i>=0&&i<=1e4)))throw new Error(`${t}.colwidth must contain non-negative column widths.`);if(["color","backgroundColor"].includes(o)&&(typeof r!="string"||!/^(?:#[a-f\d]{3,8}|[a-z]{1,24}|rgba?\([\d\s.,%]+\)|hsla?\([\d\s.,%]+\))$/i.test(r)))throw new Error(`${t}.${o} must be a CSS color.`)}}}function oT(e,t,a){if(Object.hasOwn(f6,e)){x0(e,t);return}if(e==="step-walkthrough"){I2(t);return}if(["comparison-matrix","status-tree","experiment-tracker"].includes(e)){Zl(e,t);return}if(e==="custom"&&bo(t.props,"Component instance data",Lt.componentPropsBytes),["video","audio","pdf","references"].includes(e)){To(e,t);return}if(e.startsWith("g2-")){w0(t);return}if(e==="mindmap"){y0(t);return}if(e==="flowchart"){v0(t);return}if(e==="scene-3d"){k0(t);return}if(e==="sequence-diagram"||e==="layer-diagram"){Sc(e,t);return}if(e==="step-guide"||e==="command-reference"){Cc(e,t);return}if(e==="structure-browser"||e==="card-grid"){Tc(e,t);return}if(e==="roadmap"||e==="waterfall"){Ec(e,t);return}if(e==="event-timeline"){S0(t);return}if(e==="playground"){Ys(t);return}if(e==="database"){B2(t);return}if(["text","image","table","callout","toggle","stepper","divider","code"].includes(e)){if(pr(e,t),(e==="text"&&typeof t.content=="object"||t.document)&&$m(t.document??t.content,`${a}.content`,{count:0,surface:!1,resource:!1}),e==="image"&&t.src&&!zi(t.src,!0))throw new Error(`${a}.src must be a safe raster image URL.`);return}if(!["chart","database","metrics","playground","gallery","bookmark"].includes(e))return;let n=(i,l)=>{if(t[i]===void 0)return[];if(!Array.isArray(t[i])||t[i].length>l)throw new Error(`${a}.${i} must be an array of at most ${l} items.`);return t[i]},o=(i,l)=>{i!==void 0&&Xt(i,`${a}.${l}`,1e4)},r=(i,l=!1)=>{let s=new Set;for(let[c,d]of i.entries())if(Za(d,`${a}[${c}]`),l){if(Xt(d.id,`${a}[${c}].id`,200),!d.id||s.has(d.id)||Nh.has(d.id))throw new Error(`${a} requires unique, non-reserved IDs.`);s.add(d.id)}return i};if(o(t.title,"title"),o(t.description,"description"),e==="chart"){let i=n("labels",500),l=r(n("series",20));for(let s of i)Xt(s,`${a}.labels`,1e3);if(t.type!==void 0&&!["line","bar"].includes(t.type))throw new Error(`${a}.type must be line or bar.`);for(let s of l){if(Xt(s.name,`${a}.series.name`,1e3),!Array.isArray(s.values)||s.values.length!==i.length||!s.values.every(c=>typeof c=="number"&&Number.isFinite(c)))throw new Error(`${a}.series values must be finite numbers matching labels.`);if(s.color!==void 0&&(typeof s.color!="string"||!/^#(?:[a-f\d]{3}|[a-f\d]{4}|[a-f\d]{6}|[a-f\d]{8})$/i.test(s.color)))throw new Error(`${a}.series color must be a hex color.`)}o(t.unit,"unit")}if(e==="metrics")for(let i of r(n("items",100))){if(Xt(i.label,`${a}.item.label`,1e3),!["string","number"].includes(typeof i.value))throw new Error(`${a}.item.value must be text or a number.`);if(o(i.unit,"item.unit"),o(i.detail,"item.detail"),i.trend!==void 0&&(typeof i.trend!="number"||!Number.isFinite(i.trend)))throw new Error(`${a}.item.trend must be a finite number.`)}if(e==="gallery"){if(t.columns!==void 0&&![1,2,3].includes(t.columns))throw new Error(`${a}.columns must be 1, 2, or 3.`);for(let i of r(n("images",100),!0)){if(i.src!==""&&!zi(i.src,!0))throw new Error(`${a}.image.src must be a safe raster image URL.`);o(i.alt,"image.alt"),o(i.caption,"image.caption")}}if(e==="bookmark"){if(t.url!==void 0&&t.url!==""&&!zi(t.url))throw new Error(`${a}.url must be a safe URL.`);if(t.image!==void 0&&t.image!==""&&!zi(t.image,!0))throw new Error(`${a}.image must be a safe raster image URL.`)}}function $m(e,t,a,n=0,o=null){if(++a.count>Gm)throw new Error(`Document exceeds ${Gm} nodes.`);if(n>Ih)throw new Error("Document is nested too deeply.");let r=Za(e,t);if(!a.resource&&r.type==="surface"&&r.attrs&&Object.keys(r.attrs).length)throw new Error("Whiteboard root metadata belongs on the page, not the content node.");if(r.attrs?.name!==void 0&&(typeof r.attrs.name!="string"||r.attrs.name.length>200))throw new Error("Content names must contain at most 200 characters.");if(!a.resource&&r.type==="surface"&&n!==0)throw new Error("A whiteboard root cannot be nested.");if(r.type==="region"&&(!["surface","region"].includes(o)||!a.surface))throw new Error(`${r.type} requires a whiteboard or region parent.`);if(a.surface&&r.attrs?.canvas!=null)throw new Error("Whiteboard layout must be stored outside content.");if(!tT.has(r.type))throw new Error(`Unsupported block type at ${t}: ${String(r.type)}.`);for(let c of Object.keys(r))if(!["type","attrs","content","marks","text"].includes(c))throw new Error(`Unsupported node field ${t}.${c}.`);if(r.type==="text"){if(Xt(r.text,`${t}.text`),!r.text.length)throw new Error(`${t}.text cannot be empty.`)}else if(r.text!==void 0)throw new Error(`Only text nodes can have a text field: ${t}.`);if(r.attrs!==void 0&&Mh(r.attrs,`${t}.attrs`,r.type==="drawing"?new Set(["id","name","tool","color","fillColor","strokeWidth","pressure","extent","points","bindings","ink","inkFragments","inkInput","label","labelSize"]):r.type==="surface"?new Set([...Zm,"widthMode","inkState","outline"]):r.type==="region"?new Set([...Zm,"inkArchiveGroup"]):Zm,r.type==="surface"),c0(r),r.attrs?.frameless!==void 0&&(r.type!=="surface"||r.attrs.kind!=="page"||typeof r.attrs.frameless!="boolean"))throw new Error(`${t}.attrs.frameless requires a Page and a boolean.`);if(r.type==="surface"&&r.attrs?.icon!==void 0&&zc(r.attrs.icon,`${t}.attrs.icon`),r.attrs?.canvas!=null){if(n!==1||r.type!=="callout")throw new Error(`${t}.attrs.canvas is only supported on top-level callouts.`);if(Xt(r.attrs.id,`${t}.attrs.id`,200),!r.attrs.id.trim())throw new Error(`${t} needs a stable canvas id.`);let c=Za(r.attrs.canvas,`${t}.attrs.canvas`);if(Object.keys(c).some(d=>!["x","y","width"].includes(d)))throw new Error(`${t}.attrs.canvas contains an unsupported field.`);for(let d of["x","y"])if(typeof c[d]!="number"||!Number.isFinite(c[d])||Math.abs(c[d])>1e6)throw new Error(`${t}.attrs.canvas.${d} must be finite and within \xB11000000.`);if(typeof c.width!="number"||!Number.isFinite(c.width)||c.width<240||c.width>1600)throw new Error(`${t}.attrs.canvas.width must be between 240 and 1600.`)}if(r.type==="image"&&r.attrs?.src!==""&&!zi(r.attrs?.src,!0))throw new Error(`${t} requires a safe image src.`);if(r.type==="image"&&pr("image",Object.fromEntries(Object.entries({...r.attrs.componentStyle,...r.attrs}).filter(([c,d])=>d!=null&&!["width","height"].includes(c)))),r.attrs?.nativeInk!=null&&r.type!=="image")throw new Error(`${t}.nativeInk requires an image node.`);if(r.attrs?.componentStyle&&(Za(r.attrs.componentStyle,`${t}.componentStyle`),pr("divider",r.attrs.componentStyle)),r.type==="richText"&&pr("text",{...r.attrs?.data,content:{type:"doc",content:r.content??[]},format:"richtext"}),r.type==="widget"){if(Xt(r.attrs?.kind,`${t}.attrs.kind`,80),!/^[a-z][a-z0-9-]*$/.test(r.attrs.kind))throw new Error("Widget kind must use lowercase letters, numbers, and hyphens.");Za(r.attrs?.data,`${t}.attrs.data`),oT(r.attrs.kind,r.attrs.data,`${t}.attrs.data`)}if(r.marks!==void 0){if(!["text","hardBreak"].includes(r.type))throw new Error(`${t} cannot have inline marks.`);if(!Array.isArray(r.marks))throw new Error(`${t}.marks must be an array.`);for(let[c,d]of r.marks.entries()){Za(d,`${t}.marks[${c}]`);for(let u of Object.keys(d))if(!["type","attrs"].includes(u))throw new Error(`Unsupported mark field: ${u}.`);if(!aT.has(d.type))throw new Error(`Unsupported text mark: ${String(d.type)}.`);if(d.attrs!==void 0&&Mh(d.attrs,`${t}.marks[${c}].attrs`,nT),d.attrs?.mode!=null&&(d.type!=="highlight"||!["lower","full"].includes(d.attrs.mode)))throw new Error("Highlight mode must be lower or full.");if(d.type==="link"&&!zi(d.attrs?.href))throw new Error("Links require a safe href.");if(c6(d))throw new Error(`Annotations require a note of 1\u2013${1e3} characters.`)}}if(r.content!==void 0){if(!Array.isArray(r.content))throw new Error(`${t}.content must be an array.`);if(["text","image","widget","drawing","hardBreak","horizontalRule"].includes(r.type))throw new Error(`${t} cannot contain child blocks.`);r.content.forEach((c,d)=>$m(c,`${t}.content[${d}]`,a,n+1,r.type))}let i=r.content??[],l=["richText","paragraph","heading","mathBlock","blockquote","bulletList","orderedList","taskList","codeBlock","horizontalRule","image","table","callout","toggle","stepper","widget"],s={doc:l,surface:[...l,"region","richText",...a.resource?["surface","drawing"]:[]],region:[...l,"region","richText",...a.resource?["surface","drawing"]:[]],richText:l,paragraph:["text","hardBreak","mathInline"],heading:["text","hardBreak","mathInline"],codeBlock:["text"],blockquote:l,callout:l,toggle:l,stepper:["step"],step:l,bulletList:["listItem"],orderedList:["listItem"],listItem:l,taskList:["taskItem"],taskItem:l,table:["tableRow"],tableRow:["tableCell","tableHeader"],tableCell:l,tableHeader:l}[r.type];if(s&&i.some(c=>!s.includes(c.type)))throw new Error(`${t} contains an invalid child block.`);if(r.type==="stepper"&&i.length>pp)throw new Error(`${t} must contain at most ${pp} steps.`);if(["blockquote","callout","toggle","stepper","step","bulletList","orderedList","listItem","taskList","taskItem","table","tableRow","tableCell","tableHeader"].includes(r.type)&&!i.length)throw new Error(`${t} must contain at least one child block.`);if(["listItem","taskItem"].includes(r.type)&&i[0]?.type!=="paragraph")throw new Error(`${t} must start with a paragraph.`);if(r.type==="codeBlock"&&i.some(c=>c.marks?.length))throw new Error(`${t} cannot contain formatted code.`)}function V2(e){U2(e,"document"),bo(e);let t=structuredClone(Za(e,"document")),a;if(t.templateContext!==void 0){let s=Za(t.templateContext,"document.templateContext");if(s.format!==1||!Array.isArray(s.templates)||s.templates.length>8)throw new Error("Invalid page template context.");let c=p=>{let g=Za(p,"Template reference");if(g.kind!=="template"||typeof g.id!="string"||!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,99}$/.test(g.id)||typeof g.version!="string"||!/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/.test(g.version)||!/^sha256-[a-f0-9]{64}$/.test(g.integrity)||g.scope!==void 0&&!["builtin","project","global","published"].includes(g.scope))throw new Error("Page template references require exact id/version/integrity.");return{kind:"template",id:g.id,version:g.version,integrity:g.integrity,...g.scope?{scope:g.scope}:{}}},d=c(s.system),u=s.templates.map(c);if(d.id!=="system-presentation"||d.scope!=="builtin"||new Set(u.map(p=>p.id)).size!==u.length)throw new Error("Page template context requires the builtin system baseline and distinct templates.");a={format:1,system:d,templates:u}}if(Xt(t.id,"document.id",200),Xt(t.title,"document.title",1e3),!t.id)throw new Error("Document id is required.");if(!["doc","surface"].includes(t.content?.type))throw new Error("Page content must be a doc or surface node.");let n=t.content.type==="surface",o=Ua(t);if(n)yi(t);else if(t.layout!==void 0||t.views!==void 0||t.surfaceViews!==void 0)throw new Error("Layout and views require a surface root.");$m(t.content,"document.content",{count:0,surface:n,resource:o}),n&&th(t);let r=new Set((t.content.content??[]).filter(s=>s.attrs?.canvas!=null).map(s=>s.attrs.id));if(r.size){let s=new Set,c=d=>{let u=d.attrs?.id;if(r.has(u)){if(s.has(u))throw new Error(`Duplicate canvas id: ${u}.`);s.add(u)}d.content?.forEach(c)};c(t.content)}let i=new Date().toISOString();for(let s of["createdAt","updatedAt"])if(t[s]!==void 0&&(typeof t[s]!="string"||!Number.isFinite(Date.parse(t[s]))))throw new Error(`document.${s} must be an ISO date string.`);t.parentId!=null&&Xt(t.parentId,"document.parentId",200);for(let s of["favorite","archived"])if(t[s]!==void 0&&typeof t[s]!="boolean")throw new Error(`document.${s} must be true or false.`);if(t.comments!==void 0&&!Array.isArray(t.comments))throw new Error("document.comments must be an array.");let l=(t.comments??[]).map((s,c)=>{if(Za(s,`comments[${c}]`),Xt(s.id,"comment.id",200),Xt(s.text,"comment.text",1e4),typeof s.createdAt!="string"||!Number.isFinite(Date.parse(s.createdAt)))throw new Error("comment.createdAt must be an ISO date string.");if(typeof s.resolved!="boolean")throw new Error("comment.resolved must be true or false.");return{id:s.id,text:s.text,createdAt:s.createdAt,resolved:s.resolved}});return{id:t.id,title:t.title,icon:t.icon===void 0?"\u2726":zc(t.icon,"document.icon"),cover:t.cover===void 0?"none":Xt(t.cover,"document.cover",2e3),parentId:t.parentId??null,favorite:t.favorite??!1,archived:t.archived??!1,createdAt:t.createdAt??i,updatedAt:t.updatedAt??i,content:t.content,...o?{layout:t.layout,surfaceViews:t.surfaceViews}:n?{layout:t.layout,views:t.views}:{},comments:l,...a?{templateContext:a}:{}}}function Dh(e){if(e===void 0)return;if(!Array.isArray(e)||e.length>100)throw new Error("components must be an array of at most 100 packages.");U2(e,"components"),wc("Embedded components JSON",b0(e).jsonBytes,Lt.artifactBytes);let t=new Set;return e.map((a,n)=>{if(Za(a,`components[${n}]`),Xt(a.id,"component.id",80),Xt(a.name,"component.name",200),Xt(a.version,"component.version",80),Xt(a.html,"component.html",Lt.authoringRequestBytes),Xt(a.integrity,"component.integrity",200),!/^[a-z][a-z0-9-]*$/.test(a.id)||!/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/.test(a.version))throw new Error("Invalid component identity.");let o=`${a.id}@${a.version}#${a.integrity}`;if(t.has(o))throw new Error(`Duplicate embedded component: ${o}`);return t.add(o),typeof a.schema!="boolean"&&Za(a.schema,"component.schema"),a.inline!==void 0&&(Za(a.inline,"component.inline"),Xt(a.inline.script,"component.inline.script",Lt.authoringRequestBytes),Xt(a.inline.styles,"component.inline.styles",Lt.authoringRequestBytes)),i6(a),structuredClone(a)})}function Oh(e,t){Za(e,"selection");let a=new Set,n=r=>{r.attrs?.id&&!["doc","text"].includes(r.type)&&a.add(r.attrs.id),r.content?.forEach(n)};n(t.content);let o=e.blockIds;if(!Array.isArray(o)||!o.length||o.some(r=>typeof r!="string"||!a.has(r))||new Set(o).size!==o.length)throw new Error("Artifact selection must reference unique existing block ids.");return{blockIds:[...o]}}function Lh(e){wc("Artifact JSON",typeof e=="string"?dp(e):b0(e).jsonBytes,Lt.artifactBytes);let t=Za(typeof e=="string"?JSON.parse(e):e,"artifact");if(t.format!=="showai"||![1,2,3].includes(t.version))throw new Error('Expected a ShowAI artifact with format "showai" and version 1, 2 or 3.');if(t.presentation!==void 0&&!["spatial","reading"].includes(t.presentation))throw new Error("Unknown page presentation.");let a=V2(t.document);if(t.version!==vm(a))throw new Error("Artifact version does not match its page model.");return{format:"showai",version:t.version,document:a,...t.presentation?{presentation:t.presentation}:{},...t.selection===void 0?{}:{selection:Oh(t.selection,a)},...t.components===void 0?{}:{components:Dh(t.components)},...t.remoteComponents===void 0?{}:{remoteComponents:_2(t.remoteComponents)}}}function Rh(e,t,a,n,o){if(n!==void 0&&!["spatial","reading"].includes(n))throw new Error("Unknown page presentation.");let r={format:"showai",version:vm(e),document:V2(e),...n?{presentation:n}:{},...o?{selection:Oh(o,e)}:{},...t?.length?{components:Dh(t)}:{},...a?.length?{remoteComponents:_2(a)}:{}};wc("Artifact JSON",b0(r).prettyJsonBytes,Lt.artifactBytes);let i=JSON.stringify(r,null,2);return wc("Artifact JSON",dp(i),Lt.artifactBytes),i}var $x=U(Ne(),1);var Ft=U(Ne(),1);var Js="default-src 'none'; script-src 'unsafe-inline' 'wasm-unsafe-eval'; style-src 'unsafe-inline'; img-src data: blob:; media-src data:; font-src data:; connect-src 'none'; object-src 'none'; frame-src about:; base-uri 'none'; form-action 'none'";var Ph=U(Ne(),1);function rT(){let e=document.documentElement.dataset.theme;if(e==="light"||e==="dark")return e;let t=localStorage.getItem("showai:appearance");return t==="dark"||!t&&matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function iT(e){let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>t.disconnect()}function Z2(){return(0,Ph.useSyncExternalStore)(iT,rT,()=>"light")}function G2(e,t,a){let n=(o,r)=>{document.documentElement.dataset.theme=o,document.documentElement.style.colorScheme=o;for(let[i,l]of Object.entries(r))i.startsWith("--")&&document.documentElement.style.setProperty(i,l)};n(t,a),window.addEventListener("message",o=>{o.source===parent&&o.data?.channel===e&&o.data.type==="showai:theme"&&(o.data.theme==="light"||o.data.theme==="dark")&&n(o.data.theme,o.data.tokens??{})})}function Xs(){let e=getComputedStyle(document.documentElement);return Object.fromEntries([...e].filter(t=>t.startsWith("--")).map(t=>[t,e.getPropertyValue(t)]))}var ot=U(Ne(),1);var lT=/^[a-z][a-z0-9-]{0,79}$/,sT=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[a-zA-Z0-9.-]+)?$/,Bh="<!--SHOWAI_COMPONENT_DATA-->";function Qs(e,t){if(!e.includes(Bh))throw new Error("\u7EC4\u4EF6\u7F3A\u5C11\u8FD0\u884C\u5165\u53E3\u3002");return e.replace(Bh,()=>t)}function $2(e,t=0){if(t>40)throw new Error("Component data is nested too deeply.");if(!(e===null||typeof e=="string"||typeof e=="boolean")&&!(typeof e=="number"&&Number.isFinite(e))){if(Array.isArray(e)){e.forEach(a=>$2(a,t+1));return}if(e&&typeof e=="object"&&Object.getPrototypeOf(e)===Object.prototype){for(let[a,n]of Object.entries(e)){if(["__proto__","prototype","constructor"].includes(a))throw new Error("Component data contains a reserved property.");$2(n,t+1)}return}throw new Error("Component data must contain only JSON values.")}}function jh(e,t=e.defaultData){return $2(t),bo(t,"Component instance data",Lt.componentPropsBytes),{...Ai({componentId:e.id,version:e.version,integrity:e.integrity,props:structuredClone(t)})}}function Ai(e){if(!e||typeof e!="object"||Array.isArray(e))throw new Error("Custom block data must be an object.");let t=e;if(typeof t.componentId!="string"||!lT.test(t.componentId))throw new Error("A custom block needs a valid componentId.");if(typeof t.version!="string"||!sT.test(t.version))throw new Error("A custom block needs an exact component version.");if(t.integrity!==void 0&&(typeof t.integrity!="string"||!/^sha256-[a-f0-9]{64}$/.test(t.integrity)))throw new Error("Invalid component integrity hash.");if(t.scope!==void 0&&!["project","global","published","builtin"].includes(String(t.scope)))throw new Error("Invalid component scope.");if(!t.props||typeof t.props!="object"||Array.isArray(t.props))throw new Error("Custom block props must be an object.");return $2(t.props),bo(t.props,"Component instance data",Lt.componentPropsBytes),{componentId:t.componentId,version:t.version,props:t.props,...t.integrity?{integrity:t.integrity}:{},...t.scope?{scope:t.scope}:{}}}var dT=U(Ne(),1),uT=U(Gn(),1),pT=U(h2(),1),mT=U(pe(),1),fT=U(Uh(),1),zo=U(Ne(),1);var Eo=rt("customComponents",{"zh-CN":{notInstalled:"\u7EC4\u4EF6\u5C1A\u672A\u5B89\u88C5",notInstalledError:"\u7EC4\u4EF6\u5C1A\u672A\u5B89\u88C5\u3002",installRequired:"\u9700\u8981\u5B89\u88C5\u7EC4\u4EF6 {component}\u3002\u9875\u9762\u6570\u636E\u5DF2\u4FDD\u7559\u3002",installRequiredIntegrity:"\u9700\u8981\u5B89\u88C5\u7EC4\u4EF6 {component}\uFF08{integrity}\uFF09\u3002\u9875\u9762\u6570\u636E\u5DF2\u4FDD\u7559\u3002",ambiguousVersion:"\u7EC4\u4EF6 {component} \u6709\u591A\u4E2A\u4E0D\u540C\u5185\u5BB9\u7248\u672C\uFF0C\u8BF7\u6307\u5B9A\u5B8C\u6574\u6027\u6307\u7EB9\u3002",invalidJson:"JSON \u683C\u5F0F\u4E0D\u6B63\u786E\u3002",notJsonObject:"\u7EC4\u4EF6\u6570\u636E\u5FC5\u987B\u662F\u6709\u6548\u7684 JSON \u5BF9\u8C61\u3002",dataTooLarge:"\u7EC4\u4EF6\u6570\u636E\u8D85\u9650\u3002",dataChanged:"\u7EC4\u4EF6\u6570\u636E\u5DF2\u66F4\u65B0\uFF0C\u8BF7\u91CD\u65B0\u6253\u5F00\u7F16\u8F91\u540E\u518D\u4FEE\u6539\u3002",validationTimeout:"\u7EC4\u4EF6\u672A\u54CD\u5E94\u6570\u636E\u6821\u9A8C\uFF0C\u8BF7\u91CD\u65B0\u52A0\u8F7D\u7EC4\u4EF6\u540E\u518D\u8BD5\u3002",cannotDisplay:"\u7EC4\u4EF6\u65E0\u6CD5\u663E\u793A\u3002",viewportLockFailed:"\u65E0\u6CD5\u4FDD\u5B58\u9605\u8BFB\u9501\u72B6\u6001\uFF1A{error}",invalidProps:"\u6570\u636E\u4E0D\u7B26\u5408\u7EC4\u4EF6\u7684\u5C5E\u6027\u8981\u6C42\u3002",editData:"\u7F16\u8F91\u7EC4\u4EF6\u6570\u636E",data:"\u7EC4\u4EF6\u6570\u636E",propsJson:"\u7EC4\u4EF6\u5C5E\u6027 JSON",validating:"\u6821\u9A8C\u4E2D\u2026",apply:"\u5E94\u7528",inlineOnlyInConversation:"\u6B64\u8FD0\u884C\u65B9\u5F0F\u4EC5\u7528\u4E8E\u5BF9\u8BDD\u5185\u7684\u72EC\u7ACB\u9875\u9762\u3002",inlineUnavailable:"\u7EC4\u4EF6 {component} \u5C1A\u65E0\u5BF9\u8BDD\u5185\u8FD0\u884C\u7248\u672C\uFF0C\u8BF7\u4ECE\u6E90\u7801\u5BFC\u5165\u65B0\u7248\u672C\u540E\u91CD\u65B0\u5BFC\u51FA\u3002",inlineBlocked:"\u5BBF\u4E3B\u672A\u5141\u8BB8\u6B64\u7EC4\u4EF6\u8FD0\u884C\u3002","media.title":"\u672C\u673A\u6587\u4EF6","media.close":"\u5173\u95ED","media.loading":"\u6B63\u5728\u6253\u5F00\u2026","media.unsupported":"\u8FD9\u4E2A\u6587\u4EF6\u4E0D\u80FD\u5728 ShowAI \u91CC\u9884\u89C8\uFF0C\u53EF\u4EE5\u5728\u6587\u4EF6\u5939\u4E2D\u6253\u5F00\u3002","media.unavailable":"\u8FD9\u91CC\u4E0D\u80FD\u6253\u5F00\u672C\u673A\u6587\u4EF6\u3002\u8BF7\u5728 ShowAI \u684C\u9762\u7248\u6216\u672C\u673A\u6D4F\u89C8\u5668\u7248\u4E2D\u67E5\u770B\u3002","media.failed":"\u65E0\u6CD5\u6253\u5F00\u6587\u4EF6\uFF1A{error}","media.notFound":"\u627E\u4E0D\u5230\u8FD9\u4E2A\u6587\u4EF6\uFF0C\u53EF\u80FD\u5DF2\u7ECF\u79FB\u52A8\u6216\u5220\u9664\u3002","media.playFailed":"\u65E0\u6CD5\u64AD\u653E\u8FD9\u4E2A\u6587\u4EF6\uFF0C\u53EF\u80FD\u662F\u7F16\u7801\u683C\u5F0F\u4E0D\u53D7\u652F\u6301\u3002","media.copyPath":"\u590D\u5236\u4F4D\u7F6E","media.copied":"\u5DF2\u590D\u5236","media.reveal":"\u5728\u6587\u4EF6\u5939\u4E2D\u663E\u793A"},en:{notInstalled:"Component not installed",notInstalledError:"This component isn't installed.",installRequired:"Install component {component} to show this block. The page data is kept.",installRequiredIntegrity:"Install component {component} ({integrity}) to show this block. The page data is kept.",ambiguousVersion:"Component {component} has several versions with different content. Specify its integrity fingerprint.",invalidJson:"The JSON is malformed.",notJsonObject:"Component data must be a valid JSON object.",dataTooLarge:"The component data is too large.",dataChanged:"The component data has changed. Reopen the editor before making changes.",validationTimeout:"The component didn't respond to data validation. Reload the component and try again.",cannotDisplay:"This component can't be displayed.",viewportLockFailed:"Couldn't save the reading lock state: {error}",invalidProps:"The data doesn't match the component's property rules.",editData:"Edit component data",data:"Component data",propsJson:"Component properties JSON",validating:"Validating\u2026",apply:"Apply",inlineOnlyInConversation:"This mode only runs in standalone pages inside a conversation.",inlineUnavailable:"Component {component} has no in-conversation build yet. Import a new version from source and export again.",inlineBlocked:"The host didn't allow this component to run.","media.title":"Local file","media.close":"Close","media.loading":"Opening\u2026","media.unsupported":"ShowAI can't preview this file. Open it from its folder instead.","media.unavailable":"Local files can't be opened here. View this page in the ShowAI desktop app or local browser mode.","media.failed":"Couldn't open the file: {error}","media.notFound":"This file can't be found. It may have been moved or deleted.","media.playFailed":"Couldn't play this file. Its format may not be supported.","media.copyPath":"Copy location","media.copied":"Copied","media.reveal":"Show in folder"}});var eM=Object.freeze({modelBytes:8192,totalBytes:16384,labelChars:80,depth:20,perMessage:6});function q2(e,t={modelBytes:8192,totalBytes:16384,labelChars:80,depth:20}){let a=i=>!!i&&typeof i=="object"&&!Array.isArray(i)&&[Object.prototype,null].includes(Object.getPrototypeOf(i)),n=(i,l)=>l>t.depth?!1:i===null||["string","boolean"].includes(typeof i)?!0:typeof i=="number"?Number.isFinite(i):Array.isArray(i)?i.every(s=>n(s,l+1)):a(i)&&Object.entries(i).every(([s,c])=>!["__proto__","constructor","prototype"].includes(s)&&n(c,l+1)),o=i=>new TextEncoder().encode(JSON.stringify(i)).byteLength;if(!a(e))return"The snapshot must be an object.";let r=Object.keys(e).filter(i=>!["model","private","label"].includes(i));return r.length?`Unknown snapshot fields: ${r.join(", ")}.`:e.model===void 0||e.model===null?"model is required.":n(e.model,1)?e.private!==void 0&&!n(e.private,1)?"private must contain only JSON values.":e.label!==void 0&&(typeof e.label!="string"||!e.label.trim()||e.label.length>t.labelChars)?`label must be non-empty text of at most ${t.labelChars} characters.`:o(e.model)>t.modelBytes?`model exceeds ${t.modelBytes} bytes of JSON.`:o(e)>t.totalBytes?`The snapshot exceeds ${t.totalBytes} bytes of JSON.`:"":"model must contain only JSON values."}var L1=U(pe(),1),gT="showai:conversation-context",Vh=new Map;function F2({component:e,data:t,host:a,outline:n,onError:o}){let r=(0,zo.useRef)(null),i=(0,zo.useRef)(null),l=(0,zo.useRef)(t),[s,c]=(0,zo.useState)(""),d=ue(Eo);l.current=t;let u=(0,zo.useRef)(n);return u.current=n,(0,zo.useEffect)(()=>o?.(s),[s,o]),(0,zo.useEffect)(()=>{if(!r.current||!a.hasAttribute("data-showai-inline-root")||!a.contains(r.current)||window.showai){c(d("inlineOnlyInConversation"));return}if(!e.inline){c(d("inlineUnavailable",{component:`${e.id}@${e.version}`}));return}let p=r.current.shadowRoot??r.current.attachShadow({mode:"open"}),g=document.createElement("style");g.textContent=":host{display:block;font:14px/1.6 system-ui,sans-serif;color:inherit}*{box-sizing:border-box}button,input,select,textarea{font:inherit}.component-root{display:flow-root;overflow-wrap:anywhere}"+e.inline.styles.replace(/:root\b|(?<![\w-])(?:html|body)(?=\s*[{,])/g,":host");let y=document.createElement("div");y.className="component-root",p.replaceChildren(g,y);let b=Kl(p),x=globalThis,f=x.__SHOWAI_COMPONENT_HOST__,m=`__showai_mount_${crypto.randomUUID().replaceAll("-","")}`;x.__SHOWAI_COMPONENT_HOST__={react:dT,client:pT,dom:uT,jsx:mT,jsxDev:fT};let v=r.current.closest("[data-block-id],[data-surface-id]"),T=v?.dataset.blockId??v?.dataset.surfaceId,w=!!T&&!!a.closest("[data-showai-conversation]"),E=H=>{let S=q2(H);if(S)throw new Error(`onContext: ${S}`);if(navigator.userActivation&&!navigator.userActivation.isActive)return!1;let k=JSON.parse(JSON.stringify(H));return Vh.set(T,k),r.current?.dispatchEvent(new CustomEvent(gT,{bubbles:!0,composed:!0,detail:{blockId:T,componentId:e.id,name:e.name,snapshot:k}})),!0};x[m]=H=>{i.current=H.mount(y,{data:l.current,outline:u.current,onError:c,...w?{onContext:E,context:Vh.get(T)}:{}})};let L=document.createElement("script");L.textContent=`(()=>{${e.inline.script}
22
+ `)){let i=0,l=1;for(let s of r){let c=OC(s)*t;a&&i+c>a&&i>0?(o=Math.max(o,i),i=c,l++):i+=c}o=Math.max(o,i),n+=l}return{width:Math.ceil(o),height:Math.ceil(n*t*1.3)}}function Q9(e,t,a=16,n,o=2){let r=z2(e,o),i=e==="ellipse"?Math.SQRT2:1,l=Im(t,a,n/i-r*2);return Math.ceil((l.height+r*2)*i)}var Nm=new Set(["__proto__","constructor","prototype"]),lo=(e,t)=>{if(!e||typeof e!="object"||Array.isArray(e))throw new Error(`${t} must be an object.`)},$t=(e,t,a,n)=>{if(typeof e!="number"||!Number.isFinite(e)||e<t||e>a)throw new Error(`${n} must be between ${t} and ${a}.`)};function th(e){if(Ua(e))return LC(e);let t=new Set,a=new Map;Et(e.content,n=>{if(["surface","text"].includes(n.type))return;let o=n.attrs?.id;if(typeof o!="string"||!o.trim()||o.length>200||Nm.has(o)||t.has(o))throw new Error("Whiteboard nodes require unique, non-reserved ids.");if(t.add(o),a.set(o,n),n.attrs?.canvas!=null)throw new Error("Whiteboard positions belong in layout, not attrs.canvas.")}),e.layout!==void 0&&lo(e.layout,"layout"),w2(e);for(let[n,o]of Object.entries(e.layout)){if(!t.has(n))throw new Error(`Layout references an unknown node: ${n}.`);if(lo(o,`layout.${n}`),Object.keys(o).some(r=>!["x","y","width","height","mode","columns","gap"].includes(r)))throw new Error(`Unsupported layout field for ${n}.`);if(o.rotation!==void 0){let r=a.get(n);if(!$n(r).rotate)throw new Error(`Rotation is not supported for ${n}.`);$t(o.rotation,-360,360,`layout.${n}.rotation`)}if($t(o.x,-1e6,1e6,`layout.${n}.x`),$t(o.y,-1e6,1e6,`layout.${n}.y`),$t(o.width,120,1e4,`layout.${n}.width`),o.height!==void 0&&$t(o.height,40,1e6,`layout.${n}.height`),o.mode!==void 0&&(a.get(n).type!=="region"||!["flow","grid","free"].includes(o.mode)))throw new Error(`Invalid region layout: ${n}.`);if(a.get(n).type!=="region"&&(o.columns!==void 0||o.gap!==void 0))throw new Error(`Only regions can define columns and gap: ${n}.`);if(o.columns!==void 0&&($t(o.columns,1,12,`layout.${n}.columns`),!Number.isInteger(o.columns)))throw new Error("Grid columns must be an integer.");o.gap!==void 0&&$t(o.gap,0,160,`layout.${n}.gap`)}ah(e.views,t,(e.content.content??[]).map(n=>n.attrs.id))}function ah(e,t,a){if(lo(e,"views"),Object.keys(e).some(i=>!["initial","saved","readingOrder"].includes(i)))throw new Error("Unsupported view configuration.");let{saved:n,readingOrder:o}=e;if(!Array.isArray(n)||n.length>100)throw new Error("At most 100 saved views are supported.");let r=new Set;for(let i of n){if(lo(i,"view"),Object.keys(i).some(l=>!["id","name","targets"].includes(l)))throw new Error("Unsupported saved view field.");if(typeof i.id!="string"||!i.id.trim()||i.id.length>200||Nm.has(i.id)||r.has(i.id))throw new Error("Saved views require unique ids.");if(r.add(i.id),typeof i.name!="string"||!i.name.trim()||i.name.length>200)throw new Error("Saved views require a name of at most 200 characters.");if(!Array.isArray(i.targets)||!i.targets.length||i.targets.length>1e3||new Set(i.targets).size!==i.targets.length||i.targets.some(l=>!t.has(l)))throw new Error("Saved view targets must reference existing nodes.")}if(e.initial??=null,e.initial!==null&&!r.has(e.initial))throw new Error("The initial view does not exist.");if(!Array.isArray(o)||new Set(o).size!==o.length||o.some(i=>!a.includes(i)))throw new Error("Reading order must contain unique root node ids.");e.readingOrder=[...o,...a.filter(i=>!o.includes(i))]}function LC(e){let t=new Set,a=new Map,n=new Map,o=new Map,r=(i,l,s)=>{if(i.type==="text")return;let c=i.attrs?.id;if(typeof c!="string"||!c.trim()||c.length>200||Nm.has(c)||t.has(c))throw new Error("Container nodes require unique, non-reserved ids.");if(t.add(c),a.set(c,i),n.set(c,l),o.set(c,s),i.attrs?.outline!==void 0&&x2(i.attrs.outline,i),i.attrs?.canvas!=null)throw new Error("Positions belong in layout.");if(c0(i),i.type==="surface"){if(!["page","board"].includes(i.attrs.kind))throw new Error("Surface kind must be page or board.");if(i.attrs.inkState!==void 0){if(i.attrs.kind!=="board")throw new Error("Causal ink metadata requires a Board.");Y9(i.attrs.inkState)}if(i.attrs.widthMode!==void 0&&(i.attrs.kind!=="page"||!["standard","wide","full"].includes(i.attrs.widthMode)))throw new Error("Page width mode must be standard, wide or full.");if(l&&!["surface","region"].includes(l.type))throw new Error("A surface requires a container parent.");if(i.attrs.frameless!==void 0&&(i.attrs.kind!=="page"||typeof i.attrs.frameless!="boolean"))throw new Error("Only Pages support the boolean frameless setting.");s=i}if(i.type==="drawing"){if(Sm(i.attrs.ink,i.attrs.inkFragments),Cm(i.attrs.inkInput,i.attrs.ink,i.attrs.inkFragments),i.attrs.ink!==void 0&&(l6(i.attrs.ink),i.attrs.tool!=="pen"&&!(yc(i.attrs.ink)&&i.attrs.tool==="highlighter")))throw new Error("Native ink uses the pen drawing tool.");if(s?.attrs.kind!=="board")throw new Error("Drawings belong inside a Board.");if(!["pen","highlighter","rectangle","ellipse","arrow"].includes(i.attrs.tool))throw new Error("Unknown drawing tool.");if(!(i.attrs.color==="none"&&["rectangle","ellipse"].includes(i.attrs.tool))&&!/^#[0-9a-fA-F]{6}$/.test(i.attrs.color))throw new Error("Drawing color must be a six-digit hex value, or none for a rectangle or ellipse.");if(i.attrs.fillColor!==void 0&&i.attrs.fillColor!=="none"&&!/^#[0-9a-fA-F]{6}$/.test(i.attrs.fillColor))throw new Error("Drawing fill must be none or a six-digit hex value.");if(!Array.isArray(i.attrs.extent)||i.attrs.extent.length!==2)throw new Error("Drawing extent requires width and height.");if(i.attrs.extent.forEach(d=>$t(d,1,1e6,"drawing.extent")),$t(i.attrs.strokeWidth,.5,40,"drawing.strokeWidth"),i.attrs.pressure!==void 0&&typeof i.attrs.pressure!="boolean")throw new Error("drawing.pressure must be boolean.");if(!Array.isArray(i.attrs.points)||i.attrs.points.length<2||i.attrs.points.length>2e4)throw new Error("A drawing needs 2\u201320000 points.");for(let d of i.attrs.points)lo(d,"drawing point"),$t(d.x,-1e6,1e6,"point.x"),$t(d.y,-1e6,1e6,"point.y"),d.pressure!==void 0&&$t(d.pressure,0,1,"point.pressure");if((i.attrs.label!==void 0||i.attrs.labelSize!==void 0)&&!io(i))throw new Error("Only rectangle, ellipse and arrow drawings can have a label.");if(i.attrs.label!==void 0&&(typeof i.attrs.label!="string"||!i.attrs.label.trim()||i.attrs.label.length>2e3))throw new Error(`drawing.label must be non-empty text of at most ${2e3} characters.`);i.attrs.labelSize!==void 0&&$t(i.attrs.labelSize,8,160,"drawing.labelSize")}for(let d of i.content??[])r(d,i,s)};r(e.content,null,null);for(let[i,l]of a)if(l.attrs?.bindings!==void 0){if(l.type!=="drawing"||l.attrs.tool!=="arrow")throw new Error("Only arrows can define endpoint bindings.");lo(l.attrs.bindings,"bindings");for(let[s,c]of Object.entries(l.attrs.bindings)){if(!["start","end"].includes(s))throw new Error("Unknown arrow endpoint.");if(lo(c,"binding"),Object.keys(c).some(u=>!["targetId","anchor"].includes(u)))throw new Error("Unsupported binding field.");let d=a.get(c.targetId);if(!d||n.get(i)!==n.get(c.targetId)||!$n(d).bindTarget)throw new Error("Arrow bindings require a non-arrow sibling target.");if(lo(c.anchor,"binding.anchor"),Object.keys(c.anchor).some(u=>!["x","y"].includes(u)))throw new Error("Unsupported anchor field.");$t(c.anchor.x,0,1,"binding.anchor.x"),$t(c.anchor.y,0,1,"binding.anchor.y")}}if(e.views!==void 0)throw new Error("Version 3 stores views per surface in surfaceViews.");e.layout!==void 0&&lo(e.layout,"layout"),e.surfaceViews!==void 0&&lo(e.surfaceViews,"surfaceViews"),vi(e);for(let[i,l]of a){let s=Object.values(l.attrs?.bindings??{});if(s.length&&(!Ho(n.get(i),e.layout)||!e.layout[i]||s.some(c=>!e.layout[c.targetId])))throw new Error("Arrow bindings require framed siblings in a Board or free-layout region.")}for(let[i,l]of Object.entries(e.layout)){let s=a.get(i),c=n.get(i);if(!s||!c||!["surface","region"].includes(c.type))throw new Error(`Layout requires a direct container child: ${i}.`);if(lo(l,`layout.${i}`),go(s)&&(l.mode!=="free"||!(l.height>0)||l.contentSize!==void 0))throw new Error("inkArchiveGroup requires a fixed free-layout frame.");if(Object.keys(l).some(d=>!["x","y","width","height","heightMode","rotation","contentSize","mode","columns","gap","locked"].includes(d)))throw new Error("Unsupported layout field.");if(l.locked!==void 0&&l.locked!==!0)throw new Error("layout.locked must be true when present.");if(l.contentSize!==void 0){if(lo(l.contentSize,"layout.contentSize"),s.type==="drawing"||s.type==="surface"&&l.heightMode!=="auto")throw new Error("Content size hints require content-sized objects.");if(Object.keys(l.contentSize).some(d=>!["width","height"].includes(d)))throw new Error("Unsupported content size hint.");$t(l.contentSize.width,1,1e4,"contentSize.width"),$t(l.contentSize.height,1,1e6,"contentSize.height")}if(l.rotation!==void 0){let d=a.get(i);if(!$n(d).rotate||l.rotation!==0&&!Ho(c,e.layout))throw new Error(`Rotation is not supported for ${i}.`);$t(l.rotation,-360,360,`layout.${i}.rotation`)}if($t(l.x,-1e6,1e6,`layout.${i}.x`),$t(l.y,-1e6,1e6,`layout.${i}.y`),$t(l.width,s.type==="drawing"||go(s)||(s.attrs?.nativeInk??s.attrs?.data?.nativeInk)?1:120,go(s)||s.attrs?.ink||(s.attrs?.nativeInk??s.attrs?.data?.nativeInk)?1e6:1e4,`layout.${i}.width`),l.height!==void 0&&$t(l.height,s.type==="drawing"||go(s)||(s.attrs?.nativeInk??s.attrs?.data?.nativeInk)?1:40,1e6,`layout.${i}.height`),l.heightMode!==void 0&&(s.type!=="surface"||!["fixed","auto"].includes(l.heightMode)||ta(s)==="board"&&l.heightMode==="auto"))throw new Error("Only embedded Pages support auto height; Boards use a fixed viewport.");if(s.type!=="region"&&["mode","columns","gap"].some(d=>l[d]!==void 0))throw new Error("Only regions can define mode, columns and gap.");if(l.mode!==void 0&&!["flow","grid","free"].includes(l.mode))throw new Error("Unknown region layout.");if(l.columns!==void 0&&($t(l.columns,1,12,"columns"),!Number.isInteger(l.columns)))throw new Error("Columns must be an integer.");l.gap!==void 0&&$t(l.gap,0,160,"gap")}for(let[i,l]of Object.entries(e.surfaceViews)){let s=a.get(i);if(s?.type!=="surface")throw new Error("View owner must be an existing surface.");let c=new Set;Et(s,d=>{d!==s&&d.attrs?.id&&c.add(d.attrs.id)}),ah(l,c,(s.content??[]).map(d=>d.attrs.id))}}var Da=e=>{throw new Error(e)},Om=e=>!!e&&typeof e=="object"&&!Array.isArray(e);function Na(e,t){(typeof e!="string"||!e.trim())&&Da(`${t} must be non-empty text.`)}function So(e,t){e!==void 0&&Na(e,t)}function Ks(e,t,a,n=0){return(!Array.isArray(e)||e.length<n||e.length>a)&&Da(`${t} must be an array of ${n} to ${a} items.`),e.forEach((o,r)=>{Om(o)||Da(`${t}[${r}] must be an object.`)}),e}function Dm(e,t,a){return e===void 0?[]:Ks(e,t,a)}function M2(e,t,a){Na(t,a),e.has(t)&&Da(`${a} duplicates id ${t}.`),e.add(t)}function A2(e,t,a){e.has(t)||Da(`${a} must name an existing part.`)}var nh=["new","changed","retired","kept"],oh=["input","action","result","note"],so={parts:6,steps:10,actions:12,entries:24,fields:8,blocks:8,callouts:6,details:10,sources:8};function RC(e,t,a,n){let o=`steps[${t}]`;M2(n,e.id,`${o}.id`),Na(e.label,`${o}.label`),Na(e.takeaway,`${o}.takeaway`),So(e.actionsHeading,`${o}.actionsHeading`),Ks(e.actions,`${o}.actions`,so.actions,1).forEach((l,s)=>{let c=`${o}.actions[${s}]`;Na(l.actor,`${c}.actor`),Na(l.text,`${c}.text`),So(l.code,`${c}.code`),l.kind!==void 0&&!oh.includes(l.kind)&&Da(`${c}.kind must be one of ${oh.join(", ")}.`),l.illustrative!==void 0&&typeof l.illustrative!="boolean"&&Da(`${c}.illustrative must be true or false.`)});let r=new Set;Dm(e.entries,`${o}.entries`,so.entries).forEach((l,s)=>{let c=`${o}.entries[${s}]`;M2(r,l.id,`${c}.id`),A2(a,l.partId,`${c}.partId`),Na(l.title,`${c}.title`),nh.includes(l.status)||Da(`${c}.status must be one of ${nh.join(", ")}.`),So(l.statusLabel,`${c}.statusLabel`),So(l.note,`${c}.note`),Ks(l.fields,`${c}.fields`,so.fields,1).forEach((d,u)=>{Na(d.label,`${c}.fields[${u}].label`),Na(d.value,`${c}.fields[${u}].value`),d.mono!==void 0&&typeof d.mono!="boolean"&&Da(`${c}.fields[${u}].mono must be true or false.`)})});let i=new Set;if(Dm(e.partNotes,`${o}.partNotes`,so.parts).forEach((l,s)=>{A2(a,l.partId,`${o}.partNotes[${s}].partId`),i.has(l.partId)&&Da(`${o}.partNotes has more than one note for ${l.partId}.`),i.add(l.partId),Na(l.text,`${o}.partNotes[${s}].text`)}),e.output!==void 0){let l=e.output;Om(l)||Da(`${o}.output must be an object.`),Na(l.heading,`${o}.output.heading`);let s=new Set,c=Ks(l.blocks,`${o}.output.blocks`,so.blocks,1);c.forEach((d,u)=>{let p=`${o}.output.blocks[${u}]`;M2(s,d.id,`${p}.id`),d.partId!==void 0&&A2(a,d.partId,`${p}.partId`),Na(d.label,`${p}.label`),Na(d.text,`${p}.text`),d.callouts!==void 0&&((!Array.isArray(d.callouts)||d.callouts.length>so.callouts)&&Da(`${p}.callouts must be an array of at most ${so.callouts} items.`),d.callouts.forEach((g,y)=>Na(g,`${p}.callouts[${y}]`)))}),l.hidePartId!==void 0&&(A2(a,l.hidePartId,`${o}.output.hidePartId`),c.some(d=>d.partId===l.hidePartId)||Da(`${o}.output.hidePartId must match the part of at least one block.`)),So(l.hideLabel,`${o}.output.hideLabel`),So(l.hideNote,`${o}.output.hideNote`)}e.details!==void 0&&((!Array.isArray(e.details)||e.details.length>so.details)&&Da(`${o}.details must be an array of at most ${so.details} items.`),e.details.forEach((l,s)=>Na(l,`${o}.details[${s}]`))),Dm(e.sources,`${o}.sources`,so.sources).forEach((l,s)=>{Na(l.label,`${o}.sources[${s}].label`),(typeof l.url!="string"||!/^https?:\/\//i.test(l.url))&&Da(`${o}.sources[${s}].url must be an http(s) URL.`)})}function I2(e){Om(e)||Da("Step walkthrough data must be an object."),Na(e.title,"title"),So(e.question,"question"),So(e.note,"note"),So(e.stateHeading,"stateHeading");let t=new Set;Ks(e.parts,"parts",so.parts,1).forEach((n,o)=>{M2(t,n.id,`parts[${o}].id`),Na(n.label,`parts[${o}].label`),So(n.plain,`parts[${o}].plain`),So(n.how,`parts[${o}].how`),n.tone!==void 0&&!kc.includes(n.tone)&&Da(`parts[${o}].tone must be one of ${kc.join(", ")}.`)});let a=new Set;return Ks(e.steps,"steps",so.steps,1).forEach((n,o)=>RC(n,o,t,a)),e.initialStep!==void 0&&!a.has(e.initialStep)&&Da("initialStep must name an existing step."),e}var ze=e=>{throw new Error(e)},Si=e=>!!e&&typeof e=="object"&&!Array.isArray(e),O1=e=>typeof e=="number"&&Number.isFinite(e),rh=["sum","product","average"],ih=["slider","stepper","toggle","choice"],Co={inputs:30,options:8,formulas:60,outputs:6,breakdown:12,presets:8,criteria:8,rankingItems:30,expression:500,depth:48},PC=/^[A-Za-z_][A-Za-z0-9_]*$/,Rm={min:[1,16],max:[1,16],round:[1,2],floor:[1,1],ceil:[1,1],abs:[1,1],sqrt:[1,1],clamp:[3,3],if:[3,3]},pA=Object.keys(Rm),BC=["<","<=",">",">=","==","!="];function jC(e){let t=[],a=0;for(;a<e.length;){let n=e.slice(a),o=/^\s+/.exec(n);if(o){a+=o[0].length;continue}let r=/^(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?/.exec(n);if(r){t.push({type:"num",value:Number(r[0]),at:a}),a+=r[0].length;continue}let i=/^[A-Za-z_][A-Za-z0-9_]*/.exec(n);if(i){t.push({type:"id",value:i[0],at:a}),a+=i[0].length;continue}let l=/^(?:<=|>=|==|!=|[-+*/^(),<>])/.exec(n);l||ze(`Unexpected character "${n[0]}" at position ${a+1}.`),t.push({type:"op",value:l[0],at:a}),a+=l[0].length}return t}function HC(e){(typeof e!="string"||!e.trim())&&ze("Expression must be non-empty text."),e.length>Co.expression&&ze(`Expression must be at most ${Co.expression} characters.`);let t=jC(e),a=0,n=0,o=()=>t[a],r=()=>o()?`position ${o().at+1}`:"the end of the expression",i=x=>o()?.type==="op"&&o().value===x,l=x=>{i(x)||ze(`Expected "${x}" at ${r()}.`),a+=1},s=x=>{n+=1,n>Co.depth&&ze("Expression is nested too deeply.");let f=x();return n-=1,f};function c(){let x=d();for(;o()?.type==="op"&&BC.includes(o().value);)x={type:"binary",op:t[a++].value,left:x,right:d()};return x}function d(){let x=u();for(;i("+")||i("-");)x={type:"binary",op:t[a++].value,left:x,right:u()};return x}function u(){let x=p();for(;i("*")||i("/");)x={type:"binary",op:t[a++].value,left:x,right:p()};return x}function p(){if(i("-")||i("+")){let x=t[a++].value;return s(()=>({type:"unary",op:x,arg:p()}))}return g()}function g(){let x=y();return i("^")?(a+=1,{type:"binary",op:"^",left:x,right:s(p)}):x}function y(){let x=o();if(x||ze("Expression ended unexpectedly."),x.type==="num")return a+=1,{type:"num",value:x.value};if(x.type==="id"){if(a+=1,!i("("))return{type:"ref",id:x.value};let f=Rm[x.value];f||ze(`Unknown function "${x.value}".`),a+=1;let m=[];if(!i(")"))for(m.push(s(c));i(",");)a+=1,m.push(s(c));return l(")"),(m.length<f[0]||m.length>f[1])&&ze(`${x.value}() takes ${f[0]===f[1]?f[0]:`${f[0]} to ${f[1]}`} argument(s).`),{type:"call",name:x.value,args:m}}if(x.value==="("){a+=1;let f=s(c);return l(")"),f}ze(`Unexpected "${x.value}" at ${r()}.`)}let b=c();return a<t.length&&ze(`Unexpected "${o().value}" at ${r()}.`),b}function lh(e){let t=new Set,a=n=>{n.type==="ref"?t.add(n.id):n.type==="unary"?a(n.arg):n.type==="binary"?(a(n.left),a(n.right)):n.type==="call"&&n.args.forEach(a)};return a(e),[...t]}function _C(e,t){let a=n=>{switch(n.type){case"num":return n.value;case"ref":{let o=t[n.id];return typeof o!="number"&&ze(`Unknown id "${n.id}".`),o}case"unary":return n.op==="-"?-a(n.arg):a(n.arg);case"binary":{let o=a(n.left),r=a(n.right);switch(n.op){case"+":return o+r;case"-":return o-r;case"*":return o*r;case"/":return o/r;case"^":return o**r;case"<":return o<r?1:0;case"<=":return o<=r?1:0;case">":return o>r?1:0;case">=":return o>=r?1:0;case"==":return o===r?1:0;default:return o!==r?1:0}}default:{if(n.name==="if")return a(n.args[0])?a(n.args[1]):a(n.args[2]);let o=n.args.map(a);switch(n.name){case"min":return Math.min(...o);case"max":return Math.max(...o);case"round":{let r=10**Math.max(0,Math.min(10,Math.round(o[1]??0)));return Math.round(o[0]*r)/r}case"floor":return Math.floor(o[0]);case"ceil":return Math.ceil(o[0]);case"abs":return Math.abs(o[0]);case"sqrt":return Math.sqrt(o[0]);default:return Math.min(Math.max(o[0],o[1]),o[2])}}}};return a(e)}var Ci=e=>e.type??"slider";function D2(e){let t=Ci(e);return t==="toggle"?e.value?1:0:t==="choice"?O1(e.value)?e.value:e.options[0].value:O1(e.value)?e.value:0}function O2(e,t){let a=Ci(e);return a==="toggle"?t?1:0:a==="choice"?e.options.some(n=>n.value===t)?t:D2(e):Math.min(e.max,Math.max(e.min,t))}function sh(e){return e.formulas===void 0&&e.outputs===void 0&&(e.operation!==void 0||e.ranking===void 0)}function ch(e,t){let a=new Map;e.forEach((i,l)=>{try{a.set(i.id,HC(i.expr))}catch(s){ze(`formulas[${l}].expr: ${s.message}`)}}),e.forEach((i,l)=>{for(let s of lh(a.get(i.id)))!t.has(s)&&!a.has(s)&&ze(`formulas[${l}].expr references unknown id "${s}".`)});let n=[],o=new Map,r=(i,l)=>{if(o.get(i)!=="done"){o.get(i)==="active"&&ze(`formulas contain a cycle: ${[...l.slice(l.indexOf(i)),i].join(" -> ")}.`),o.set(i,"active");for(let s of lh(a.get(i)))a.has(s)&&r(s,[...l,i]);o.set(i,"done"),n.push({id:i,tree:a.get(i)})}};for(let i of e)r(i.id,[]);return n}function Pm(e){let t=Array.isArray(e.inputs)?e.inputs:[];return ch(Array.isArray(e.formulas)?e.formulas:[],new Set(t.map(a=>a.id)))}function dh(e,t={},a=Pm(e)){let n=Object.create(null);for(let o of Array.isArray(e.inputs)?e.inputs:[])n[o.id]=O2(o,t[o.id]??D2(o));for(let{id:o,tree:r}of a)n[o]=_C(r,n);return n}function uh(e,t){let n=(e.breakdown?.items??[]).map(r=>({...r,value:t[r.formula]})),o=n.reduce((r,i)=>r+(Number.isFinite(i.value)?Math.abs(i.value):0),0);return n.map(r=>({...r,share:o&&Number.isFinite(r.value)?Math.abs(r.value)/o:0}))}function ph(e,t){let a=e.scale??10,n=e.criteria.map(r=>{let i=typeof r.weight=="string"?t[r.weight]:r.weight??1;return Number.isFinite(i)?Math.max(0,i):0}),o=n.reduce((r,i)=>r+i,0);return e.items.map((r,i)=>{let l=e.criteria.map((s,c)=>({id:s.id,value:o?n[c]*(r.scores[s.id]??0)*100/(o*a):0}));return{item:r,index:i,parts:l,score:l.reduce((s,c)=>s+c.value,0)}}).sort((r,i)=>i.score-r.score||r.index-i.index)}function mh(e,t={},a){if(!Number.isFinite(e))return"";let n=e/(t.divisor??1),o=t.decimals===void 0?{maximumFractionDigits:2}:{minimumFractionDigits:t.decimals,maximumFractionDigits:t.decimals},r=new Intl.NumberFormat(a,o).format(Math.abs(n)),i=Number(r.replace(/[^\d.]/g,""))===0;return`${n<0&&!i?"\u2212":t.signed?i?"\xB1":"+":""}${t.prefix??""}${r}${t.suffix??""}`}function fh(e,t,a=1e3){(typeof e!="string"||e.length>a)&&ze(`${t} must be text of at most ${a} characters.`)}function Jt(e,t,a){e!==void 0&&fh(e,t,a)}function N2(e,t){(typeof e!="string"||!e.trim()||e.length>200)&&ze(`${t} must be non-empty text of at most 200 characters.`)}function Ir(e,t){O1(e)||ze(`${t} must be a finite number.`)}function ki(e,t,a,n=0){return(!Array.isArray(e)||e.length<n||e.length>a)&&ze(`${t} must be an array of ${n} to ${a} items.`),e.forEach((o,r)=>{Si(o)||ze(`${t}[${r}] must be an object.`)}),e}function gh(e,t){e!==void 0&&!/^#[0-9a-fA-F]{6}$/.test(e)&&ze(`${t} must be a six-digit hex color.`)}function Lm(e,t){e!==void 0&&(Si(e)||ze(`${t} must be an object.`),Jt(e.prefix,`${t}.prefix`,20),Jt(e.suffix,`${t}.suffix`,20),e.decimals!==void 0&&(!Number.isInteger(e.decimals)||e.decimals<0||e.decimals>6)&&ze(`${t}.decimals must be an integer from 0 to 6.`),e.divisor!==void 0&&(!O1(e.divisor)||e.divisor<=0)&&ze(`${t}.divisor must be a positive number.`),e.signed!==void 0&&typeof e.signed!="boolean"&&ze(`${t}.signed must be true or false.`))}function UC(e,t){(typeof e.id!="string"||!e.id)&&ze(`${t}.id must be non-empty text.`),fh(e.label,`${t}.label`),Jt(e.unit,`${t}.unit`,40),Jt(e.hint,`${t}.hint`);let a=Ci(e);if(ih.includes(a)||ze(`${t}.type must be one of ${ih.join(", ")}.`),(a==="slider"||a==="stepper")&&(Ir(e.min,`${t}.min`),Ir(e.max,`${t}.max`),Ir(e.value,`${t}.value`),e.min>=e.max&&ze(`${t}.max must be greater than min.`),(a==="slider"||e.step!==void 0)&&(Ir(e.step,`${t}.step`),e.step<=0&&ze(`${t}.step must be greater than 0.`))),a==="toggle"&&e.value!==void 0&&e.value!==0&&e.value!==1&&ze(`${t}.value must be 0 or 1.`),a==="choice"){let n=ki(e.options,`${t}.options`,Co.options,2),o=new Set;n.forEach((r,i)=>{N2(r.label,`${t}.options[${i}].label`),Ir(r.value,`${t}.options[${i}].value`),Jt(r.note,`${t}.options[${i}].note`,200),o.has(r.value)&&ze(`${t}.options contains duplicate value ${r.value}.`),o.add(r.value)}),e.value!==void 0&&!o.has(e.value)&&ze(`${t}.value must equal one of the option values.`)}}function VC(e,t,a){Ir(t,a);let n=Ci(e);n==="toggle"&&t!==0&&t!==1&&ze(`${a} must be 0 or 1.`),n==="choice"&&!e.options.some(o=>o.value===t)&&ze(`${a} must equal one of the option values.`),(n==="slider"||n==="stepper")&&(t<e.min||t>e.max)&&ze(`${a} must be within ${e.min} to ${e.max}.`)}function ZC(e,t,a){Si(e)||ze(`${t} must be an object.`),typeof e.value=="string"?a.has(e.value)||ze(`${t}.value references unknown id "${e.value}".`):Ir(e.value,`${t}.value`),Jt(e.label,`${t}.label`,200),Jt(e.above,`${t}.above`,200),Jt(e.below,`${t}.below`,200)}function GC(e,t){Si(e)||ze("ranking must be an object."),Jt(e.title,"ranking.title",200),e.scale!==void 0&&(!O1(e.scale)||e.scale<=0)&&ze("ranking.scale must be a positive number.");let a=e.scale??10;e.decimals!==void 0&&(!Number.isInteger(e.decimals)||e.decimals<0||e.decimals>2)&&ze("ranking.decimals must be an integer from 0 to 2.");let n=ki(e.criteria,"ranking.criteria",Co.criteria,1),o=new Set;n.forEach((l,s)=>{let c=`ranking.criteria[${s}]`;(typeof l.id!="string"||!l.id)&&ze(`${c}.id must be non-empty text.`),o.has(l.id)&&ze(`ranking.criteria contains duplicate id ${l.id}.`),o.add(l.id),N2(l.label,`${c}.label`),Jt(l.hint,`${c}.hint`,200),gh(l.color,`${c}.color`),typeof l.weight=="string"?t.has(l.weight)||ze(`${c}.weight references unknown id "${l.weight}".`):l.weight!==void 0&&(Ir(l.weight,`${c}.weight`),l.weight<0&&ze(`${c}.weight must not be negative.`))});let r=ki(e.items,"ranking.items",Co.rankingItems,1),i=new Set;r.forEach((l,s)=>{let c=`ranking.items[${s}]`;(typeof l.id!="string"||!l.id)&&ze(`${c}.id must be non-empty text.`),i.has(l.id)&&ze(`ranking.items contains duplicate id ${l.id}.`),i.add(l.id),N2(l.label,`${c}.label`),Jt(l.note,`${c}.note`,300),Si(l.scores)||ze(`${c}.scores must be an object.`);for(let[d,u]of Object.entries(l.scores))o.has(d)||ze(`${c}.scores.${d} does not match a criterion id.`),Ir(u,`${c}.scores.${d}`),(u<0||u>a)&&ze(`${c}.scores.${d} must be within 0 to ${a}.`)})}function Ys(e){Si(e)||ze("Playground data must be an object."),Jt(e.title,"title",200),Jt(e.description,"description",2e3),Jt(e.resultLabel,"resultLabel",200),Jt(e.unit,"unit",40),Jt(e.note,"note",1e3),e.operation!==void 0&&!rh.includes(e.operation)&&ze(`operation must be one of ${rh.join(", ")}.`);let t=ki(e.inputs,"inputs",Co.inputs),a=new Set;if(t.forEach((n,o)=>{UC(n,`inputs[${o}]`),a.has(n.id)&&ze(`inputs contains duplicate id ${n.id}.`),a.add(n.id)}),e.formulas!==void 0){let n=ki(e.formulas,"formulas",Co.formulas);n.forEach((o,r)=>{let i=`formulas[${r}]`;(typeof o.id!="string"||!PC.test(o.id))&&ze(`${i}.id must start with a letter or _ and use only letters, digits and _.`),Rm[o.id]&&ze(`${i}.id "${o.id}" is a reserved function name.`),a.has(o.id)&&ze(`${i}.id ${o.id} duplicates another id.`),a.add(o.id),Jt(o.label,`${i}.label`,200),Jt(o.unit,`${i}.unit`,40),Lm(o.format,`${i}.format`),typeof o.expr!="string"&&ze(`${i}.expr must be text.`)}),ch(n,new Set(t.map(o=>o.id)))}if(e.outputs!==void 0&&ki(e.outputs,"outputs",Co.outputs,1).forEach((o,r)=>{let i=`outputs[${r}]`;a.has(o.formula)||ze(`${i}.formula references unknown id "${o.formula}".`),Jt(o.label,`${i}.label`,200),Jt(o.unit,`${i}.unit`,40),Jt(o.hint,`${i}.hint`,300),Lm(o.format,`${i}.format`),o.target!==void 0&&ZC(o.target,`${i}.target`,a)}),e.breakdown!==void 0){Si(e.breakdown)||ze("breakdown must be an object."),Jt(e.breakdown.title,"breakdown.title",200),Lm(e.breakdown.format,"breakdown.format");let n=ki(e.breakdown.items,"breakdown.items",Co.breakdown,1),o=new Set;n.forEach((r,i)=>{let l=`breakdown.items[${i}]`;a.has(r.formula)||ze(`${l}.formula references unknown id "${r.formula}".`),o.has(r.formula)&&ze(`breakdown.items repeats ${r.formula}.`),o.add(r.formula),Jt(r.label,`${l}.label`,200),gh(r.color,`${l}.color`)})}if(e.presets!==void 0){let n=ki(e.presets,"presets",Co.presets,1),o=new Map(t.map(r=>[r.id,r]));n.forEach((r,i)=>{let l=`presets[${i}]`;N2(r.label,`${l}.label`),(!Si(r.values)||!Object.keys(r.values).length)&&ze(`${l}.values must be an object with at least one input value.`);for(let[s,c]of Object.entries(r.values)){let d=o.get(s);d||ze(`${l}.values.${s} does not match an input id.`),VC(d,c,`${l}.values.${s}`)}})}return e.ranking!==void 0&&GC(e.ranking,a),e}var Vt=e=>{throw new Error(e)},Bm=e=>!!e&&typeof e=="object"&&!Array.isArray(e),$C=new Set(["id","__proto__","prototype","constructor"]),bh=["text","number","select","checkbox","url","date"],hh=["table","board","calendar"],yh=["month","week","heatmap"],L2=53,qC=366,R2=864e5;function Ti(e){if(typeof e!="string")return null;let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!t)return null;let[a,n,o]=t.slice(1).map(Number),r=Date.UTC(a,n-1,o),i=new Date(r);return i.getUTCMonth()!==n-1||i.getUTCDate()!==o?null:Math.round(r/R2)}function P2(e){return new Date(e*R2).toISOString().slice(0,10)}function xh(e=new Date){return Math.round(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate())/R2)}function FC(e){return new Date(e*R2).getUTCDay()}function hl(e,t=1){return e-(FC(e)-t+7)%7}function wh(e){if(typeof e!="string")return"";let t=/^\s*(\d{4})[-/.](\d{1,2})[-/.](\d{1,2})/.exec(e);if(!t)return"";let a=`${t[1]}-${t[2].padStart(2,"0")}-${t[3].padStart(2,"0")}`;return Ti(a)===null?"":a}function vh(e){if(typeof e!="string")return null;let t=/^(\d{1,2}):(\d{2})$/.exec(e.trim());if(!t)return null;let a=Number(t[1])*60+Number(t[2]);return Number(t[2])<60&&a<=1440?a:null}function WC(e,t){Bm(e)||Vt("calendar must be an object.");let a=(n,o)=>{let r=e[n];if(r===void 0)return;typeof r!="string"&&Vt(`calendar.${n} must be a column id string.`);let i=t.find(l=>l.id===r);i||Vt(`calendar.${n} refers to missing column ${r}.`),o.includes(i.type)||Vt(`calendar.${n} must refer to a ${o.join(" or ")} column.`)};a("dateColumn",["date"]),a("endDateColumn",["date"]),a("startTimeColumn",["text"]),a("endTimeColumn",["text"]),a("colorColumn",["select"]),a("doneColumn",["checkbox"]),e.endDateColumn!==void 0&&e.endDateColumn===e.dateColumn&&Vt("calendar.endDateColumn must differ from calendar.dateColumn."),e.endTimeColumn!==void 0&&!e.startTimeColumn&&Vt("calendar.endTimeColumn requires calendar.startTimeColumn."),e.mode!==void 0&&!yh.includes(e.mode)&&Vt(`calendar.mode must be one of ${yh.join(", ")}.`),e.initialDate!==void 0&&Ti(e.initialDate)===null&&Vt("calendar.initialDate must be a YYYY-MM-DD date."),e.weekStartsOn!==void 0&&![0,1].includes(e.weekStartsOn)&&Vt("calendar.weekStartsOn must be 0 (Sunday) or 1 (Monday)."),e.weeks!==void 0&&(!Number.isInteger(e.weeks)||e.weeks<1||e.weeks>L2)&&Vt(`calendar.weeks must be an integer from 1 to ${L2}.`);for(let n of Object.keys(e))["dateColumn","endDateColumn","startTimeColumn","endTimeColumn","colorColumn","doneColumn","mode","initialDate","weekStartsOn","weeks"].includes(n)||Vt(`calendar.${n} is not a supported setting.`)}function B2(e){Bm(e)||Vt("Component data must be an object.");for(let o of["title","description","groupBy"])e[o]!==void 0&&(typeof e[o]!="string"||e[o].length>1e4)&&Vt(`${o} must be text, at most 10000 characters.`);let t=(o,r)=>{if(e[o]===void 0)return[];(!Array.isArray(e[o])||e[o].length>r)&&Vt(`${o} must be an array of at most ${r} items.`);let i=new Set;for(let[l,s]of e[o].entries())Bm(s)||Vt(`${o}[${l}] must be an object.`),(typeof s.id!="string"||!s.id||s.id.length>200)&&Vt(`${o}[${l}].id must be non-empty text.`),i.has(s.id)&&Vt(`${o} contains duplicate id ${s.id}.`),$C.has(s.id)&&(o==="columns"||s.id!=="id")&&Vt(`${o}[${l}].id cannot use the reserved name ${s.id}.`),i.add(s.id);return e[o]},a=t("columns",50);for(let[o,r]of a.entries()){let i=`columns[${o}]`;(typeof r.name!="string"||r.name.length>1e3)&&Vt(`${i}.name must be text, at most 1000 characters.`),bh.includes(r.type)||Vt(`${i}.type must be one of ${bh.join(", ")}.`),r.options!==void 0&&(!Array.isArray(r.options)||r.options.length>200||!r.options.every(l=>typeof l=="string"))&&Vt(`${i}.options must be an array of at most 200 texts.`)}let n=a.filter(o=>o.type==="date");for(let[o,r]of t("rows",5e3).entries()){for(let[i,l]of Object.entries(r))["string","number","boolean"].includes(typeof l)||Vt(`rows[${o}].${i} must be text, a number or a boolean.`);for(let i of n){let l=r[i.id];l!==void 0&&l!==""&&Ti(l)===null&&Vt(`rows[${o}].${i.id} must be a YYYY-MM-DD date or empty.`)}}return e.view!==void 0&&!hh.includes(e.view)&&Vt(`view must be one of ${hh.join(", ")}.`),e.calendar!==void 0&&WC(e.calendar,a),e.view==="calendar"&&!n.length&&Vt("view calendar requires a date column."),e}function kh(e,t){let a=[];for(let n of e){let o=Ti(n[t.dateColumn]);if(o===null)continue;let r=t.endDateColumn?Ti(n[t.endDateColumn]):null;(r===null||r<o||r-o>=qC)&&(r=o);let i=t.startTimeColumn?vh(n[t.startTimeColumn]):null,l=i!==null&&t.endTimeColumn?vh(n[t.endTimeColumn]):null;l!==null&&l<=i&&(l=null),a.push({row:n,start:o,end:r,startMinute:i,endMinute:l,done:t.doneColumn?n[t.doneColumn]===!0:!1})}return a.sort((n,o)=>n.start-o.start||(n.startMinute??-1)-(o.startMinute??-1)||o.end-n.end)}function jm(e,t,a){let n=new Map;for(let o=t;o<=a;o+=1)n.set(o,[]);for(let o of e)for(let r=Math.max(t,o.start);r<=Math.min(a,o.end);r+=1)n.get(r).push(o);return n}function Sh(e){let t=[];return{placed:e.filter(n=>n.startMinute!==null).map(n=>{let o=n.endMinute??Math.min(1440,n.startMinute+60),r=t.findIndex(i=>i<=n.startMinute);return r<0?r=t.push(o)-1:t[r]=o,{entry:n,lane:r,end:o}}),laneCount:Math.max(1,t.length)}}function Ch(e,t){let a=t.weekStartsOn??1,n=t.weeks??12,o=hl(t.endDay,a)-(n-1)*7,r=o+n*7-1,i=t.countDone?e.filter(x=>x.done):e,l=jm(i,o,r),s=[],c=0;for(let x=o;x<=r;x+=1){let f=l.get(x).length;c=Math.max(c,f),s.push({day:x,count:f})}for(let x of s)x.level=x.count?Math.max(1,Math.ceil(x.count/c*4)):0;let d=Math.min(r,t.today),u=0,p=0,g=0;for(let x=o;x<=d;x+=1){let f=l.get(x).length>0;f&&(g+=1),p=f?p+1:0,u=Math.max(u,p)}let y=0,b=d;for(b>=o&&b===t.today&&!l.get(b).length&&(b-=1);b>=o&&l.get(b).length;b-=1)y+=1;return{from:o,to:r,cells:s,max:c,current:y,longest:u,activeDays:g,elapsedDays:Math.max(0,d-o+1)}}var j2={video:["video/mp4","video/webm","video/ogg","video/quicktime"],audio:["audio/mpeg","audio/mp4","audio/wav","audio/x-wav","audio/ogg","audio/webm","audio/flac","audio/aac"],pdf:["application/pdf"]},Th=Lt.resourceBytes;function KC(e,t){let a=typeof t=="string"&&t.match(/^data:([^;,]+);base64,[a-z\d+/=\s]+$/i);return a&&j2[e]?.includes(a[1].toLowerCase())?a[1].toLowerCase():void 0}function Ei(e,t){if(!(typeof t!="string"||/^[\u0000-\u0020]|[\u0000-\u001f]/.test(t))){if(KC(e,t))return t;try{let a=new URL(t);if(["http:","https:"].includes(a.protocol))return a.href}catch{}}}function Eh(e,t){let n={mp4:"video/mp4",webm:e==="audio"?"audio/webm":"video/webm",ogv:"video/ogg",mov:"video/quicktime",mp3:"audio/mpeg",m4a:"audio/mp4",wav:"audio/wav",oga:"audio/ogg",ogg:e==="video"?"video/ogg":"audio/ogg",flac:"audio/flac",aac:"audio/aac",pdf:"application/pdf"}[t.name.split(".").pop()?.toLowerCase()];return n&&j2[e]?.includes(n)?n:j2[e]?.includes(t.type)?t.type:void 0}function Hm(e){let t=e.doi?.trim().replace(/^https?:\/\/(?:dx\.)?doi\.org\//i,""),a=e.url||(t?`https://doi.org/${t}`:"");return Ei("pdf",a)}function To(e,t){if(!t||typeof t!="object"||Array.isArray(t))throw new Error("\u7EC4\u4EF6\u6570\u636E\u5FC5\u987B\u662F\u5BF9\u8C61\u3002");let a=(n,o,r=1e4)=>{if(n!==void 0&&(typeof n!="string"||n.length>r))throw new Error(`${o}\u5FC5\u987B\u662F\u6587\u5B57\uFF0C\u957F\u5EA6\u4E0D\u8D85\u8FC7 ${r}\u3002`)};if(["title","description","caption","fileName"].forEach(n=>a(t[n],n)),e==="references"){if(!Array.isArray(t.items)||t.items.length>500)throw new Error("\u53C2\u8003\u6587\u732E\u6700\u591A\u652F\u6301 500 \u6761\u3002");let n=new Set;for(let o of t.items){if(!o||typeof o!="object"||Array.isArray(o))throw new Error("\u53C2\u8003\u6587\u732E\u6761\u76EE\u5FC5\u987B\u662F\u5BF9\u8C61\u3002");if(typeof o.id!="string"||!o.id.trim()||n.has(o.id)||["__proto__","constructor","prototype"].includes(o.id))throw new Error("\u53C2\u8003\u6587\u732E\u9700\u8981\u4E0D\u91CD\u590D\u7684 id\u3002");if(n.add(o.id),typeof o.title!="string"||!o.title.trim())throw new Error("\u53C2\u8003\u6587\u732E\u9700\u8981\u6807\u9898\u3002");for(let r of["id","title","authors","year","venue","doi","url","note"])a(o[r],r);if(o.url&&!Ei("pdf",o.url))throw new Error("\u6587\u732E\u94FE\u63A5\u9700\u8981 http \u6216 https \u7F51\u5740\u3002");if(o.doi&&!/^10\.\d{4,9}\/\S+$/i.test(o.doi.replace(/^https?:\/\/(?:dx\.)?doi\.org\//i,"")))throw new Error("DOI \u683C\u5F0F\u5E94\u4E3A 10.xxxx/\u2026\u3002")}return}if(!j2[e])throw new Error(`\u672A\u77E5\u7684\u6587\u4EF6\u7EC4\u4EF6\uFF1A${e}`);if(t.src!==void 0&&t.src!==""&&!Ei(e,t.src))throw new Error("\u6587\u4EF6\u9700\u8981 http\u3001https \u6216\u5339\u914D\u6587\u4EF6\u7C7B\u578B\u7684\u5185\u5D4C\u5730\u5740\u3002");if(t.poster&&!(Ei("pdf",t.poster)||/^data:image\/(png|jpeg|gif|webp|avif);base64,[a-z\d+/=\s]+$/i.test(t.poster)))throw new Error("\u5C01\u9762\u9700\u8981\u6709\u6548\u56FE\u7247\u5730\u5740\u3002");if(t.page!==void 0&&(!Number.isInteger(t.page)||t.page<1||t.page>1e5))throw new Error("\u521D\u59CB\u9875\u7801\u5FC5\u987B\u662F\u6B63\u6574\u6570\u3002");if(t.height!==void 0&&(typeof t.height!="number"||!Number.isFinite(t.height)||t.height<240||t.height>1200))throw new Error("\u9605\u8BFB\u533A\u9AD8\u5EA6\u9700\u8981\u5728 240 \u5230 1200 \u4E4B\u95F4\u3002");if(t.aspectRatio!==void 0&&!["16:9","4:3","1:1","9:16"].includes(t.aspectRatio))throw new Error("\u753B\u9762\u6BD4\u4F8B\u4E0D\u53D7\u652F\u6301\u3002");for(let n of["loop","muted"])if(t[n]!==void 0&&typeof t[n]!="boolean")throw new Error(`${n}\u5FC5\u987B\u662F\u5E03\u5C14\u503C\u3002`)}var zh=Lt.publicationBytes,_m=/^sha256-[a-f0-9]{64}$/,YC=/^[a-z][a-z0-9-]{0,79}$/,JC=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[a-zA-Z0-9.-]+)?$/;function H2(e){return`${e.kind}:${e.id}@${e.version}#${e.integrity}`}function Um(e,t){if(!e||typeof e!="object"||Array.isArray(e)||!["component","template"].includes(e.kind)||t&&e.kind!==t||typeof e.id!="string"||typeof e.version!="string"||typeof e.integrity!="string"||!YC.test(e.id)||!JC.test(e.version)||!_m.test(e.integrity))throw new Error("A publication requires an exact kind/id/version/integrity reference.");if(e.scope!==void 0&&!["project","global","published","builtin"].includes(e.scope))throw new Error("Invalid publication reference scope.");if(e.projectId!==void 0&&(typeof e.projectId!="string"||!/^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/.test(e.projectId)))throw new Error("Invalid publication project reference.");return{kind:e.kind,id:e.id,version:e.version,integrity:e.integrity,...e.scope?{scope:e.scope}:{},...e.projectId?{projectId:e.projectId}:{}}}function Vm(e){if(typeof e!="string"||e.length>8192)throw new Error("Publication URL must be an HTTPS URL or a loopback HTTP URL.");let t=new URL(e),a=t.hostname.split("."),n=t.hostname==="localhost"||t.hostname==="[::1]"||a.length===4&&a[0]==="127"&&a.every(o=>/^\d+$/.test(o)&&Number(o)<=255);if(t.username||t.password||t.hash||t.protocol!=="https:"&&!(t.protocol==="http:"&&n))throw new Error("Publications require HTTPS; HTTP is allowed only on loopback. Credentials, fragments and file URLs are forbidden.");return t.href}function _2(e){if(!Array.isArray(e)||e.length>100)throw new Error("remoteComponents must contain at most 100 locked locators.");let t=new Set;return e.map(a=>{if(!a||typeof a!="object"||Array.isArray(a))throw new Error("Invalid published component locator.");let n=Um(a.ref,"component"),o=H2(n);if(t.has(o))throw new Error(`Duplicate remote component: ${o}`);if(t.add(o),!_m.test(a.sha256)||!_m.test(a.manifestIntegrity)||!Number.isSafeInteger(a.bytes)||a.bytes<1||a.bytes>zh||typeof a.verifiedAt!="string"||!Number.isFinite(Date.parse(a.verifiedAt)))throw new Error("Remote components require verified byte length, SHA-256 and publication metadata.");return{ref:n,bundleRef:Um(a.bundleRef),url:Vm(a.url),sha256:a.sha256,bytes:a.bytes,manifestUrl:Vm(a.manifestUrl),manifestIntegrity:a.manifestIntegrity,verifiedAt:a.verifiedAt}})}async function XC(e){if(!globalThis.crypto?.subtle)throw Object.assign(new Error("\u7EC4\u4EF6\u5B8C\u6574\u6027\u6821\u9A8C\u9700\u8981 HTTPS \u6216\u5728\u672C\u673A\u6253\u5F00\u9875\u9762\u3002"),{code:"INTEGRITY_UNAVAILABLE"});let t=await globalThis.crypto.subtle.digest("SHA-256",e);return"sha256-"+[...new Uint8Array(t)].map(a=>a.toString(16).padStart(2,"0")).join("")}async function QC(e,t={}){let a=Vm(e),n=await fetch(a,{credentials:"omit",mode:"cors",redirect:"error",cache:"no-store",referrerPolicy:"no-referrer",headers:{Accept:"application/json"},signal:t.signal?AbortSignal.any([t.signal,AbortSignal.timeout(15e3)]):AbortSignal.timeout(15e3)});if(!n.ok)throw new Error(`Published component request failed (${n.status}): ${a}`);if(t.requireCors&&n.headers.get("access-control-allow-origin")!=="*")throw new Error(`Publication must serve Access-Control-Allow-Origin: * so portable readers can load it: ${a}`);let o=t.maxBytes??zh;if(!n.body)throw new Error("Published bundle response has no body.");let r=n.body.getReader(),i=[],l=0;for(;;){let{value:d,done:u}=await r.read();if(u)break;if(l+=d.byteLength,l>o)throw await r.cancel(),new Error("Published bundle exceeds its size limit.");i.push(d)}let s=new Uint8Array(l),c=0;for(let d of i)s.set(d,c),c+=d.byteLength;return{bytes:s,text:new TextDecoder("utf-8",{fatal:!0}).decode(s),sha256:await XC(s),cors:n.headers.get("access-control-allow-origin")}}async function Ah(e,t={}){let a=_2(e),n=new Map,o=0,r=[];for(let i of a){let l=`${i.url}#${i.sha256}`,s=n.get(l);if(!s){let d;try{d=await QC(i.url,{signal:t.signal,maxBytes:i.bytes})}catch(u){throw Object.assign(new Error(`\u65E0\u6CD5\u52A0\u8F7D\u7EC4\u4EF6 ${i.ref.id}@${i.ref.version}\uFF1A${u instanceof Error?u.message:"\u7F51\u7EDC\u8BF7\u6C42\u5931\u8D25"}\u3002\u8BF7\u68C0\u67E5\u7F51\u7EDC\u548C\u53D1\u5E03\u670D\u52A1\u5668\u7684 CORS \u8BBE\u7F6E\u3002`,{cause:u}),{code:"COMPONENT_FETCH_FAILED",params:{component:`${i.ref.id}@${i.ref.version}`,reason:u instanceof Error?u.message:""}})}if(d.bytes.byteLength!==i.bytes||d.sha256!==i.sha256)throw Object.assign(new Error(`\u7EC4\u4EF6 ${i.ref.id}@${i.ref.version} \u7684\u6587\u4EF6\u6821\u9A8C\u5931\u8D25\uFF08SHA-256 \u6216\u5B57\u8282\u6570\u4E0D\u4E00\u81F4\uFF09\u3002`),{code:"COMPONENT_CHECKSUM_FAILED",params:{component:`${i.ref.id}@${i.ref.version}`}});if(o+=d.bytes.byteLength,o>Lt.publicationTransferBytes)throw new Error("Remote component downloads exceed the 512 MiB limit.");if(s=JSON.parse(d.text),s?.format!=="showai-catalog-bundle"||s.version!==1||!Array.isArray(s.components))throw new Error("Unsupported published component bundle.");n.set(l,s)}if(H2(Um(s.root))!==H2(i.bundleRef))throw new Error(`Published bundle revision does not match ${i.ref.id}@${i.ref.version}.`);let c=s.components.map(d=>d?.component).find(d=>d?.id===i.ref.id&&d?.version===i.ref.version&&d?.integrity===i.ref.integrity);if(!c||typeof c.html!="string"||!c.html.includes("<!--SHOWAI_COMPONENT_DATA-->")||c.schema===void 0||typeof c.name!="string")throw new Error(`Published bundle does not contain the exact component revision ${H2(i.ref)}.`);r.push(c)}return r}var ZA=Lt.artifactBytes;var Gm=12e3,Ih=48,Nh=new Set(["__proto__","prototype","constructor"]),tT=new Set(["doc","surface","drawing","region","richText","paragraph","text","heading","blockquote","bulletList","orderedList","listItem","taskList","taskItem","codeBlock","hardBreak","mathInline","mathBlock","horizontalRule","image","table","tableRow","tableCell","tableHeader","callout","toggle","stepper","step","widget"]),aT=new Set(["bold","italic","strike","code","underline","link","highlight","textStyle","annotation"]),Zm=new Set(["id","level","textAlign","align","type","start","checked","language","src","alt","title","width","height","colspan","rowspan","colwidth","backgroundColor","open","summary","icon","tone","kind","data","canvas","name","frameless","latex","display","componentStyle","caption","fit","nativeInk"]),nT=new Set(["href","title","target","rel","class","color","backgroundColor","fontFamily","fontSize","mode","note"]);function Za(e,t){if(e===null||typeof e!="object"||Array.isArray(e))throw new Error(`${t} must be an object.`);return e}function Xt(e,t,a=1e6){if(typeof e!="string"||e.length>a)throw new Error(`${t} must be text, at most ${a} characters.`);return e}function zi(e,t=!1){if(typeof e!="string")return!1;if(t&&/^data:image\/(?:png|jpeg|gif|webp|avif);base64,[a-z\d+/=\s]+$/i.test(e)||!t&&e.startsWith("#"))return!0;if(/^[\u0000-\u0020]|[\u0000-\u001f]/.test(e))return!1;try{let a=new URL(e);return(t?["http:","https:"]:["http:","https:","mailto:","tel:"]).includes(a.protocol)}catch{return!1}}function U2(e,t,a=0){if(a>Ih)throw new Error(`${t} is nested too deeply.`);if(!(e===null||typeof e=="boolean")){if(typeof e=="number"){if(!Number.isFinite(e))throw new Error(`${t} must be a finite number.`);return}if(typeof e=="string"){Xt(e,t,Lt.authoringRequestBytes);return}if(Array.isArray(e)){if(e.length>Gm)throw new Error(`${t} contains too many items.`);e.forEach((n,o)=>U2(n,`${t}[${o}]`,a+1));return}if(Za(e,t),Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw new Error(`${t} must contain plain JSON objects.`);for(let[n,o]of Object.entries(e)){if(Nh.has(n))throw new Error(`${t} contains a reserved key.`);U2(o,`${t}.${n}`,a+1)}}}function Mh(e,t,a,n=!1){Za(e,t);for(let[o,r]of Object.entries(e)){if(!a.has(o))throw new Error(`Unsupported attribute ${t}.${o}.`);if(r!=null){if(o==="href"&&!zi(r))throw new Error(`${t}.href must be a safe web, email, or anchor URL.`);if(o==="src"&&r!==""&&!zi(r,!0))throw new Error(`${t}.src must be a web URL or embedded raster image.`);if(["textAlign","align"].includes(o)&&!["left","center","right","justify"].includes(r))throw new Error(`${t}.${o} is not supported.`);if(o==="level"&&![1,2,3,4,5,6].includes(r))throw new Error(`${t}.level must be 1 through 6.`);if(o==="type"&&!["1","a","A","i","I"].includes(r))throw new Error(`${t}.type must be an ordered-list marker style.`);if(["open","checked"].includes(o)&&typeof r!="boolean")throw new Error(`${t}.${o} must be true or false.`);if(["colspan","rowspan","start"].includes(o)&&(!Number.isInteger(r)||r<1||r>1e4))throw new Error(`${t}.${o} must be a positive integer.`);if(["id","language","alt","title","summary","icon","tone","kind","target","rel","class"].includes(o)&&Xt(r,`${t}.${o}`,o==="icon"&&n?1e6:1e4),["width","height"].includes(o)&&!(typeof r=="number"&&Number.isFinite(r)&&r>0&&r<=1e4)&&!(typeof r=="string"&&/^\d{1,5}(?:px|%)?$/.test(r)))throw new Error(`${t}.${o} must be a positive image dimension.`);if(o==="colwidth"&&(!Array.isArray(r)||r.length>100||!r.every(i=>Number.isInteger(i)&&i>=0&&i<=1e4)))throw new Error(`${t}.colwidth must contain non-negative column widths.`);if(["color","backgroundColor"].includes(o)&&(typeof r!="string"||!/^(?:#[a-f\d]{3,8}|[a-z]{1,24}|rgba?\([\d\s.,%]+\)|hsla?\([\d\s.,%]+\))$/i.test(r)))throw new Error(`${t}.${o} must be a CSS color.`)}}}function oT(e,t,a){if(Object.hasOwn(f6,e)){x0(e,t);return}if(e==="step-walkthrough"){I2(t);return}if(["comparison-matrix","status-tree","experiment-tracker"].includes(e)){Zl(e,t);return}if(e==="custom"&&bo(t.props,"Component instance data",Lt.componentPropsBytes),["video","audio","pdf","references"].includes(e)){To(e,t);return}if(e.startsWith("g2-")){w0(t);return}if(e==="mindmap"){y0(t);return}if(e==="flowchart"){v0(t);return}if(e==="scene-3d"){k0(t);return}if(e==="sequence-diagram"||e==="layer-diagram"){Sc(e,t);return}if(e==="step-guide"||e==="command-reference"){Cc(e,t);return}if(e==="structure-browser"||e==="card-grid"){Tc(e,t);return}if(e==="roadmap"||e==="waterfall"){Ec(e,t);return}if(e==="event-timeline"){S0(t);return}if(e==="playground"){Ys(t);return}if(e==="database"){B2(t);return}if(["text","image","table","callout","toggle","stepper","divider","code"].includes(e)){if(pr(e,t),(e==="text"&&typeof t.content=="object"||t.document)&&$m(t.document??t.content,`${a}.content`,{count:0,surface:!1,resource:!1}),e==="image"&&t.src&&!zi(t.src,!0))throw new Error(`${a}.src must be a safe raster image URL.`);return}if(!["chart","database","metrics","playground","gallery","bookmark"].includes(e))return;let n=(i,l)=>{if(t[i]===void 0)return[];if(!Array.isArray(t[i])||t[i].length>l)throw new Error(`${a}.${i} must be an array of at most ${l} items.`);return t[i]},o=(i,l)=>{i!==void 0&&Xt(i,`${a}.${l}`,1e4)},r=(i,l=!1)=>{let s=new Set;for(let[c,d]of i.entries())if(Za(d,`${a}[${c}]`),l){if(Xt(d.id,`${a}[${c}].id`,200),!d.id||s.has(d.id)||Nh.has(d.id))throw new Error(`${a} requires unique, non-reserved IDs.`);s.add(d.id)}return i};if(o(t.title,"title"),o(t.description,"description"),e==="chart"){let i=n("labels",500),l=r(n("series",20));for(let s of i)Xt(s,`${a}.labels`,1e3);if(t.type!==void 0&&!["line","bar"].includes(t.type))throw new Error(`${a}.type must be line or bar.`);for(let s of l){if(Xt(s.name,`${a}.series.name`,1e3),!Array.isArray(s.values)||s.values.length!==i.length||!s.values.every(c=>typeof c=="number"&&Number.isFinite(c)))throw new Error(`${a}.series values must be finite numbers matching labels.`);if(s.color!==void 0&&(typeof s.color!="string"||!/^#(?:[a-f\d]{3}|[a-f\d]{4}|[a-f\d]{6}|[a-f\d]{8})$/i.test(s.color)))throw new Error(`${a}.series color must be a hex color.`)}o(t.unit,"unit")}if(e==="metrics")for(let i of r(n("items",100))){if(Xt(i.label,`${a}.item.label`,1e3),!["string","number"].includes(typeof i.value))throw new Error(`${a}.item.value must be text or a number.`);if(o(i.unit,"item.unit"),o(i.detail,"item.detail"),i.trend!==void 0&&(typeof i.trend!="number"||!Number.isFinite(i.trend)))throw new Error(`${a}.item.trend must be a finite number.`)}if(e==="gallery"){if(t.columns!==void 0&&![1,2,3].includes(t.columns))throw new Error(`${a}.columns must be 1, 2, or 3.`);for(let i of r(n("images",100),!0)){if(i.src!==""&&!zi(i.src,!0))throw new Error(`${a}.image.src must be a safe raster image URL.`);o(i.alt,"image.alt"),o(i.caption,"image.caption")}}if(e==="bookmark"){if(t.url!==void 0&&t.url!==""&&!zi(t.url))throw new Error(`${a}.url must be a safe URL.`);if(t.image!==void 0&&t.image!==""&&!zi(t.image,!0))throw new Error(`${a}.image must be a safe raster image URL.`)}}function $m(e,t,a,n=0,o=null){if(++a.count>Gm)throw new Error(`Document exceeds ${Gm} nodes.`);if(n>Ih)throw new Error("Document is nested too deeply.");let r=Za(e,t);if(!a.resource&&r.type==="surface"&&r.attrs&&Object.keys(r.attrs).length)throw new Error("Whiteboard root metadata belongs on the page, not the content node.");if(r.attrs?.name!==void 0&&(typeof r.attrs.name!="string"||r.attrs.name.length>200))throw new Error("Content names must contain at most 200 characters.");if(!a.resource&&r.type==="surface"&&n!==0)throw new Error("A whiteboard root cannot be nested.");if(r.type==="region"&&(!["surface","region"].includes(o)||!a.surface))throw new Error(`${r.type} requires a whiteboard or region parent.`);if(a.surface&&r.attrs?.canvas!=null)throw new Error("Whiteboard layout must be stored outside content.");if(!tT.has(r.type))throw new Error(`Unsupported block type at ${t}: ${String(r.type)}.`);for(let c of Object.keys(r))if(!["type","attrs","content","marks","text"].includes(c))throw new Error(`Unsupported node field ${t}.${c}.`);if(r.type==="text"){if(Xt(r.text,`${t}.text`),!r.text.length)throw new Error(`${t}.text cannot be empty.`)}else if(r.text!==void 0)throw new Error(`Only text nodes can have a text field: ${t}.`);if(r.attrs!==void 0&&Mh(r.attrs,`${t}.attrs`,r.type==="drawing"?new Set(["id","name","tool","color","fillColor","strokeWidth","pressure","extent","points","bindings","ink","inkFragments","inkInput","label","labelSize"]):r.type==="surface"?new Set([...Zm,"widthMode","inkState","outline"]):r.type==="region"?new Set([...Zm,"inkArchiveGroup"]):Zm,r.type==="surface"),c0(r),r.attrs?.frameless!==void 0&&(r.type!=="surface"||r.attrs.kind!=="page"||typeof r.attrs.frameless!="boolean"))throw new Error(`${t}.attrs.frameless requires a Page and a boolean.`);if(r.type==="surface"&&r.attrs?.icon!==void 0&&zc(r.attrs.icon,`${t}.attrs.icon`),r.attrs?.canvas!=null){if(n!==1||r.type!=="callout")throw new Error(`${t}.attrs.canvas is only supported on top-level callouts.`);if(Xt(r.attrs.id,`${t}.attrs.id`,200),!r.attrs.id.trim())throw new Error(`${t} needs a stable canvas id.`);let c=Za(r.attrs.canvas,`${t}.attrs.canvas`);if(Object.keys(c).some(d=>!["x","y","width"].includes(d)))throw new Error(`${t}.attrs.canvas contains an unsupported field.`);for(let d of["x","y"])if(typeof c[d]!="number"||!Number.isFinite(c[d])||Math.abs(c[d])>1e6)throw new Error(`${t}.attrs.canvas.${d} must be finite and within \xB11000000.`);if(typeof c.width!="number"||!Number.isFinite(c.width)||c.width<240||c.width>1600)throw new Error(`${t}.attrs.canvas.width must be between 240 and 1600.`)}if(r.type==="image"&&r.attrs?.src!==""&&!zi(r.attrs?.src,!0))throw new Error(`${t} requires a safe image src.`);if(r.type==="image"&&pr("image",Object.fromEntries(Object.entries({...r.attrs.componentStyle,...r.attrs}).filter(([c,d])=>d!=null&&!["width","height"].includes(c)))),r.attrs?.nativeInk!=null&&r.type!=="image")throw new Error(`${t}.nativeInk requires an image node.`);if(r.attrs?.componentStyle&&(Za(r.attrs.componentStyle,`${t}.componentStyle`),pr("divider",r.attrs.componentStyle)),r.type==="richText"&&pr("text",{...r.attrs?.data,content:{type:"doc",content:r.content??[]},format:"richtext"}),r.type==="widget"){if(Xt(r.attrs?.kind,`${t}.attrs.kind`,80),!/^[a-z][a-z0-9-]*$/.test(r.attrs.kind))throw new Error("Widget kind must use lowercase letters, numbers, and hyphens.");Za(r.attrs?.data,`${t}.attrs.data`),oT(r.attrs.kind,r.attrs.data,`${t}.attrs.data`)}if(r.marks!==void 0){if(!["text","hardBreak"].includes(r.type))throw new Error(`${t} cannot have inline marks.`);if(!Array.isArray(r.marks))throw new Error(`${t}.marks must be an array.`);for(let[c,d]of r.marks.entries()){Za(d,`${t}.marks[${c}]`);for(let u of Object.keys(d))if(!["type","attrs"].includes(u))throw new Error(`Unsupported mark field: ${u}.`);if(!aT.has(d.type))throw new Error(`Unsupported text mark: ${String(d.type)}.`);if(d.attrs!==void 0&&Mh(d.attrs,`${t}.marks[${c}].attrs`,nT),d.attrs?.mode!=null&&(d.type!=="highlight"||!["lower","full"].includes(d.attrs.mode)))throw new Error("Highlight mode must be lower or full.");if(d.type==="link"&&!zi(d.attrs?.href))throw new Error("Links require a safe href.");if(c6(d))throw new Error(`Annotations require a note of 1\u2013${1e3} characters.`)}}if(r.content!==void 0){if(!Array.isArray(r.content))throw new Error(`${t}.content must be an array.`);if(["text","image","widget","drawing","hardBreak","horizontalRule"].includes(r.type))throw new Error(`${t} cannot contain child blocks.`);r.content.forEach((c,d)=>$m(c,`${t}.content[${d}]`,a,n+1,r.type))}let i=r.content??[],l=["richText","paragraph","heading","mathBlock","blockquote","bulletList","orderedList","taskList","codeBlock","horizontalRule","image","table","callout","toggle","stepper","widget"],s={doc:l,surface:[...l,"region","richText",...a.resource?["surface","drawing"]:[]],region:[...l,"region","richText",...a.resource?["surface","drawing"]:[]],richText:l,paragraph:["text","hardBreak","mathInline"],heading:["text","hardBreak","mathInline"],codeBlock:["text"],blockquote:l,callout:l,toggle:l,stepper:["step"],step:l,bulletList:["listItem"],orderedList:["listItem"],listItem:l,taskList:["taskItem"],taskItem:l,table:["tableRow"],tableRow:["tableCell","tableHeader"],tableCell:l,tableHeader:l}[r.type];if(s&&i.some(c=>!s.includes(c.type)))throw new Error(`${t} contains an invalid child block.`);if(r.type==="stepper"&&i.length>pp)throw new Error(`${t} must contain at most ${pp} steps.`);if(["blockquote","callout","toggle","stepper","step","bulletList","orderedList","listItem","taskList","taskItem","table","tableRow","tableCell","tableHeader"].includes(r.type)&&!i.length)throw new Error(`${t} must contain at least one child block.`);if(["listItem","taskItem"].includes(r.type)&&i[0]?.type!=="paragraph")throw new Error(`${t} must start with a paragraph.`);if(r.type==="codeBlock"&&i.some(c=>c.marks?.length))throw new Error(`${t} cannot contain formatted code.`)}function V2(e){U2(e,"document"),bo(e);let t=structuredClone(Za(e,"document")),a;if(t.templateContext!==void 0){let s=Za(t.templateContext,"document.templateContext");if(s.format!==1||!Array.isArray(s.templates)||s.templates.length>8)throw new Error("Invalid page template context.");let c=p=>{let g=Za(p,"Template reference");if(g.kind!=="template"||typeof g.id!="string"||!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,99}$/.test(g.id)||typeof g.version!="string"||!/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/.test(g.version)||!/^sha256-[a-f0-9]{64}$/.test(g.integrity)||g.scope!==void 0&&!["builtin","project","global","published"].includes(g.scope))throw new Error("Page template references require exact id/version/integrity.");return{kind:"template",id:g.id,version:g.version,integrity:g.integrity,...g.scope?{scope:g.scope}:{}}},d=c(s.system),u=s.templates.map(c);if(d.id!=="system-presentation"||d.scope!=="builtin"||new Set(u.map(p=>p.id)).size!==u.length)throw new Error("Page template context requires the builtin system baseline and distinct templates.");a={format:1,system:d,templates:u}}if(Xt(t.id,"document.id",200),Xt(t.title,"document.title",1e3),!t.id)throw new Error("Document id is required.");if(!["doc","surface"].includes(t.content?.type))throw new Error("Page content must be a doc or surface node.");let n=t.content.type==="surface",o=Ua(t);if(n)yi(t);else if(t.layout!==void 0||t.views!==void 0||t.surfaceViews!==void 0)throw new Error("Layout and views require a surface root.");$m(t.content,"document.content",{count:0,surface:n,resource:o}),n&&th(t);let r=new Set((t.content.content??[]).filter(s=>s.attrs?.canvas!=null).map(s=>s.attrs.id));if(r.size){let s=new Set,c=d=>{let u=d.attrs?.id;if(r.has(u)){if(s.has(u))throw new Error(`Duplicate canvas id: ${u}.`);s.add(u)}d.content?.forEach(c)};c(t.content)}let i=new Date().toISOString();for(let s of["createdAt","updatedAt"])if(t[s]!==void 0&&(typeof t[s]!="string"||!Number.isFinite(Date.parse(t[s]))))throw new Error(`document.${s} must be an ISO date string.`);t.parentId!=null&&Xt(t.parentId,"document.parentId",200);for(let s of["favorite","archived"])if(t[s]!==void 0&&typeof t[s]!="boolean")throw new Error(`document.${s} must be true or false.`);if(t.comments!==void 0&&!Array.isArray(t.comments))throw new Error("document.comments must be an array.");let l=(t.comments??[]).map((s,c)=>{if(Za(s,`comments[${c}]`),Xt(s.id,"comment.id",200),Xt(s.text,"comment.text",1e4),typeof s.createdAt!="string"||!Number.isFinite(Date.parse(s.createdAt)))throw new Error("comment.createdAt must be an ISO date string.");if(typeof s.resolved!="boolean")throw new Error("comment.resolved must be true or false.");return{...s,id:s.id,text:s.text,createdAt:s.createdAt,resolved:s.resolved}});return{...t,id:t.id,title:t.title,icon:t.icon===void 0?"\u2726":zc(t.icon,"document.icon"),cover:t.cover===void 0?"none":Xt(t.cover,"document.cover",2e3),parentId:t.parentId??null,favorite:t.favorite??!1,archived:t.archived??!1,createdAt:t.createdAt??i,updatedAt:t.updatedAt??i,content:t.content,...o?{layout:t.layout,surfaceViews:t.surfaceViews}:n?{layout:t.layout,views:t.views}:{},comments:l,...a?{templateContext:a}:{}}}function Dh(e){if(e===void 0)return;if(!Array.isArray(e)||e.length>100)throw new Error("components must be an array of at most 100 packages.");U2(e,"components"),wc("Embedded components JSON",b0(e).jsonBytes,Lt.artifactBytes);let t=new Set;return e.map((a,n)=>{if(Za(a,`components[${n}]`),Xt(a.id,"component.id",80),Xt(a.name,"component.name",200),Xt(a.version,"component.version",80),Xt(a.html,"component.html",Lt.authoringRequestBytes),Xt(a.integrity,"component.integrity",200),!/^[a-z][a-z0-9-]*$/.test(a.id)||!/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?$/.test(a.version))throw new Error("Invalid component identity.");let o=`${a.id}@${a.version}#${a.integrity}`;if(t.has(o))throw new Error(`Duplicate embedded component: ${o}`);return t.add(o),typeof a.schema!="boolean"&&Za(a.schema,"component.schema"),a.inline!==void 0&&(Za(a.inline,"component.inline"),Xt(a.inline.script,"component.inline.script",Lt.authoringRequestBytes),Xt(a.inline.styles,"component.inline.styles",Lt.authoringRequestBytes)),i6(a),structuredClone(a)})}function Oh(e,t){Za(e,"selection");let a=new Set,n=r=>{r.attrs?.id&&!["doc","text"].includes(r.type)&&a.add(r.attrs.id),r.content?.forEach(n)};n(t.content);let o=e.blockIds;if(!Array.isArray(o)||!o.length||o.some(r=>typeof r!="string"||!a.has(r))||new Set(o).size!==o.length)throw new Error("Artifact selection must reference unique existing block ids.");return{blockIds:[...o]}}function Lh(e){wc("Artifact JSON",typeof e=="string"?dp(e):b0(e).jsonBytes,Lt.artifactBytes);let t=Za(typeof e=="string"?JSON.parse(e):e,"artifact");if(t.format!=="showai"||![1,2,3].includes(t.version))throw new Error('Expected a ShowAI artifact with format "showai" and version 1, 2 or 3.');if(t.presentation!==void 0&&!["spatial","reading"].includes(t.presentation))throw new Error("Unknown page presentation.");let a=V2(t.document);if(t.version!==vm(a))throw new Error("Artifact version does not match its page model.");return{format:"showai",version:t.version,document:a,...t.presentation?{presentation:t.presentation}:{},...t.selection===void 0?{}:{selection:Oh(t.selection,a)},...t.components===void 0?{}:{components:Dh(t.components)},...t.remoteComponents===void 0?{}:{remoteComponents:_2(t.remoteComponents)}}}function Rh(e,t,a,n,o){if(n!==void 0&&!["spatial","reading"].includes(n))throw new Error("Unknown page presentation.");let r={format:"showai",version:vm(e),document:V2(e),...n?{presentation:n}:{},...o?{selection:Oh(o,e)}:{},...t?.length?{components:Dh(t)}:{},...a?.length?{remoteComponents:_2(a)}:{}};wc("Artifact JSON",b0(r).prettyJsonBytes,Lt.artifactBytes);let i=JSON.stringify(r,null,2);return wc("Artifact JSON",dp(i),Lt.artifactBytes),i}var $x=U(Ne(),1);var Ft=U(Ne(),1);var Js="default-src 'none'; script-src 'unsafe-inline' 'wasm-unsafe-eval'; style-src 'unsafe-inline'; img-src data: blob:; media-src data:; font-src data:; connect-src 'none'; object-src 'none'; frame-src about:; base-uri 'none'; form-action 'none'";var Ph=U(Ne(),1);function rT(){let e=document.documentElement.dataset.theme;if(e==="light"||e==="dark")return e;let t=localStorage.getItem("showai:appearance");return t==="dark"||!t&&matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function iT(e){let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>t.disconnect()}function Z2(){return(0,Ph.useSyncExternalStore)(iT,rT,()=>"light")}function G2(e,t,a){let n=(o,r)=>{document.documentElement.dataset.theme=o,document.documentElement.style.colorScheme=o;for(let[i,l]of Object.entries(r))i.startsWith("--")&&document.documentElement.style.setProperty(i,l)};n(t,a),window.addEventListener("message",o=>{o.source===parent&&o.data?.channel===e&&o.data.type==="showai:theme"&&(o.data.theme==="light"||o.data.theme==="dark")&&n(o.data.theme,o.data.tokens??{})})}function Xs(){let e=getComputedStyle(document.documentElement);return Object.fromEntries([...e].filter(t=>t.startsWith("--")).map(t=>[t,e.getPropertyValue(t)]))}var ot=U(Ne(),1);var lT=/^[a-z][a-z0-9-]{0,79}$/,sT=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[a-zA-Z0-9.-]+)?$/,Bh="<!--SHOWAI_COMPONENT_DATA-->";function Qs(e,t){if(!e.includes(Bh))throw new Error("\u7EC4\u4EF6\u7F3A\u5C11\u8FD0\u884C\u5165\u53E3\u3002");return e.replace(Bh,()=>t)}function $2(e,t=0){if(t>40)throw new Error("Component data is nested too deeply.");if(!(e===null||typeof e=="string"||typeof e=="boolean")&&!(typeof e=="number"&&Number.isFinite(e))){if(Array.isArray(e)){e.forEach(a=>$2(a,t+1));return}if(e&&typeof e=="object"&&Object.getPrototypeOf(e)===Object.prototype){for(let[a,n]of Object.entries(e)){if(["__proto__","prototype","constructor"].includes(a))throw new Error("Component data contains a reserved property.");$2(n,t+1)}return}throw new Error("Component data must contain only JSON values.")}}function jh(e,t=e.defaultData){return $2(t),bo(t,"Component instance data",Lt.componentPropsBytes),{...Ai({componentId:e.id,version:e.version,integrity:e.integrity,props:structuredClone(t)})}}function Ai(e){if(!e||typeof e!="object"||Array.isArray(e))throw new Error("Custom block data must be an object.");let t=e;if(typeof t.componentId!="string"||!lT.test(t.componentId))throw new Error("A custom block needs a valid componentId.");if(typeof t.version!="string"||!sT.test(t.version))throw new Error("A custom block needs an exact component version.");if(t.integrity!==void 0&&(typeof t.integrity!="string"||!/^sha256-[a-f0-9]{64}$/.test(t.integrity)))throw new Error("Invalid component integrity hash.");if(t.scope!==void 0&&!["project","global","published","builtin"].includes(String(t.scope)))throw new Error("Invalid component scope.");if(!t.props||typeof t.props!="object"||Array.isArray(t.props))throw new Error("Custom block props must be an object.");return $2(t.props),bo(t.props,"Component instance data",Lt.componentPropsBytes),{componentId:t.componentId,version:t.version,props:t.props,...t.integrity?{integrity:t.integrity}:{},...t.scope?{scope:t.scope}:{}}}var dT=U(Ne(),1),uT=U(Gn(),1),pT=U(h2(),1),mT=U(pe(),1),fT=U(Uh(),1),zo=U(Ne(),1);var Eo=rt("customComponents",{"zh-CN":{notInstalled:"\u7EC4\u4EF6\u5C1A\u672A\u5B89\u88C5",notInstalledError:"\u7EC4\u4EF6\u5C1A\u672A\u5B89\u88C5\u3002",installRequired:"\u9700\u8981\u5B89\u88C5\u7EC4\u4EF6 {component}\u3002\u9875\u9762\u6570\u636E\u5DF2\u4FDD\u7559\u3002",installRequiredIntegrity:"\u9700\u8981\u5B89\u88C5\u7EC4\u4EF6 {component}\uFF08{integrity}\uFF09\u3002\u9875\u9762\u6570\u636E\u5DF2\u4FDD\u7559\u3002",ambiguousVersion:"\u7EC4\u4EF6 {component} \u6709\u591A\u4E2A\u4E0D\u540C\u5185\u5BB9\u7248\u672C\uFF0C\u8BF7\u6307\u5B9A\u5B8C\u6574\u6027\u6307\u7EB9\u3002",invalidJson:"JSON \u683C\u5F0F\u4E0D\u6B63\u786E\u3002",notJsonObject:"\u7EC4\u4EF6\u6570\u636E\u5FC5\u987B\u662F\u6709\u6548\u7684 JSON \u5BF9\u8C61\u3002",dataTooLarge:"\u7EC4\u4EF6\u6570\u636E\u8D85\u9650\u3002",dataChanged:"\u7EC4\u4EF6\u6570\u636E\u5DF2\u66F4\u65B0\uFF0C\u8BF7\u91CD\u65B0\u6253\u5F00\u7F16\u8F91\u540E\u518D\u4FEE\u6539\u3002",validationTimeout:"\u7EC4\u4EF6\u672A\u54CD\u5E94\u6570\u636E\u6821\u9A8C\uFF0C\u8BF7\u91CD\u65B0\u52A0\u8F7D\u7EC4\u4EF6\u540E\u518D\u8BD5\u3002",cannotDisplay:"\u7EC4\u4EF6\u65E0\u6CD5\u663E\u793A\u3002",viewportLockFailed:"\u65E0\u6CD5\u4FDD\u5B58\u9605\u8BFB\u9501\u72B6\u6001\uFF1A{error}",invalidProps:"\u6570\u636E\u4E0D\u7B26\u5408\u7EC4\u4EF6\u7684\u5C5E\u6027\u8981\u6C42\u3002",editData:"\u7F16\u8F91\u7EC4\u4EF6\u6570\u636E",data:"\u7EC4\u4EF6\u6570\u636E",propsJson:"\u7EC4\u4EF6\u5C5E\u6027 JSON",validating:"\u6821\u9A8C\u4E2D\u2026",apply:"\u5E94\u7528",inlineOnlyInConversation:"\u6B64\u8FD0\u884C\u65B9\u5F0F\u4EC5\u7528\u4E8E\u5BF9\u8BDD\u5185\u7684\u72EC\u7ACB\u9875\u9762\u3002",inlineUnavailable:"\u7EC4\u4EF6 {component} \u5C1A\u65E0\u5BF9\u8BDD\u5185\u8FD0\u884C\u7248\u672C\uFF0C\u8BF7\u4ECE\u6E90\u7801\u5BFC\u5165\u65B0\u7248\u672C\u540E\u91CD\u65B0\u5BFC\u51FA\u3002",inlineBlocked:"\u5BBF\u4E3B\u672A\u5141\u8BB8\u6B64\u7EC4\u4EF6\u8FD0\u884C\u3002","media.title":"\u672C\u673A\u6587\u4EF6","media.close":"\u5173\u95ED","media.loading":"\u6B63\u5728\u6253\u5F00\u2026","media.unsupported":"\u8FD9\u4E2A\u6587\u4EF6\u4E0D\u80FD\u5728 ShowAI \u91CC\u9884\u89C8\uFF0C\u53EF\u4EE5\u5728\u6587\u4EF6\u5939\u4E2D\u6253\u5F00\u3002","media.unavailable":"\u8FD9\u91CC\u4E0D\u80FD\u6253\u5F00\u672C\u673A\u6587\u4EF6\u3002\u8BF7\u5728 ShowAI \u684C\u9762\u7248\u6216\u672C\u673A\u6D4F\u89C8\u5668\u7248\u4E2D\u67E5\u770B\u3002","media.failed":"\u65E0\u6CD5\u6253\u5F00\u6587\u4EF6\uFF1A{error}","media.notFound":"\u627E\u4E0D\u5230\u8FD9\u4E2A\u6587\u4EF6\uFF0C\u53EF\u80FD\u5DF2\u7ECF\u79FB\u52A8\u6216\u5220\u9664\u3002","media.playFailed":"\u65E0\u6CD5\u64AD\u653E\u8FD9\u4E2A\u6587\u4EF6\uFF0C\u53EF\u80FD\u662F\u7F16\u7801\u683C\u5F0F\u4E0D\u53D7\u652F\u6301\u3002","media.copyPath":"\u590D\u5236\u4F4D\u7F6E","media.copied":"\u5DF2\u590D\u5236","media.reveal":"\u5728\u6587\u4EF6\u5939\u4E2D\u663E\u793A"},en:{notInstalled:"Component not installed",notInstalledError:"This component isn't installed.",installRequired:"Install component {component} to show this block. The page data is kept.",installRequiredIntegrity:"Install component {component} ({integrity}) to show this block. The page data is kept.",ambiguousVersion:"Component {component} has several versions with different content. Specify its integrity fingerprint.",invalidJson:"The JSON is malformed.",notJsonObject:"Component data must be a valid JSON object.",dataTooLarge:"The component data is too large.",dataChanged:"The component data has changed. Reopen the editor before making changes.",validationTimeout:"The component didn't respond to data validation. Reload the component and try again.",cannotDisplay:"This component can't be displayed.",viewportLockFailed:"Couldn't save the reading lock state: {error}",invalidProps:"The data doesn't match the component's property rules.",editData:"Edit component data",data:"Component data",propsJson:"Component properties JSON",validating:"Validating\u2026",apply:"Apply",inlineOnlyInConversation:"This mode only runs in standalone pages inside a conversation.",inlineUnavailable:"Component {component} has no in-conversation build yet. Import a new version from source and export again.",inlineBlocked:"The host didn't allow this component to run.","media.title":"Local file","media.close":"Close","media.loading":"Opening\u2026","media.unsupported":"ShowAI can't preview this file. Open it from its folder instead.","media.unavailable":"Local files can't be opened here. View this page in the ShowAI desktop app or local browser mode.","media.failed":"Couldn't open the file: {error}","media.notFound":"This file can't be found. It may have been moved or deleted.","media.playFailed":"Couldn't play this file. Its format may not be supported.","media.copyPath":"Copy location","media.copied":"Copied","media.reveal":"Show in folder"}});var eM=Object.freeze({modelBytes:8192,totalBytes:16384,labelChars:80,depth:20,perMessage:6});function q2(e,t={modelBytes:8192,totalBytes:16384,labelChars:80,depth:20}){let a=i=>!!i&&typeof i=="object"&&!Array.isArray(i)&&[Object.prototype,null].includes(Object.getPrototypeOf(i)),n=(i,l)=>l>t.depth?!1:i===null||["string","boolean"].includes(typeof i)?!0:typeof i=="number"?Number.isFinite(i):Array.isArray(i)?i.every(s=>n(s,l+1)):a(i)&&Object.entries(i).every(([s,c])=>!["__proto__","constructor","prototype"].includes(s)&&n(c,l+1)),o=i=>new TextEncoder().encode(JSON.stringify(i)).byteLength;if(!a(e))return"The snapshot must be an object.";let r=Object.keys(e).filter(i=>!["model","private","label"].includes(i));return r.length?`Unknown snapshot fields: ${r.join(", ")}.`:e.model===void 0||e.model===null?"model is required.":n(e.model,1)?e.private!==void 0&&!n(e.private,1)?"private must contain only JSON values.":e.label!==void 0&&(typeof e.label!="string"||!e.label.trim()||e.label.length>t.labelChars)?`label must be non-empty text of at most ${t.labelChars} characters.`:o(e.model)>t.modelBytes?`model exceeds ${t.modelBytes} bytes of JSON.`:o(e)>t.totalBytes?`The snapshot exceeds ${t.totalBytes} bytes of JSON.`:"":"model must contain only JSON values."}var L1=U(pe(),1),gT="showai:conversation-context",Vh=new Map;function F2({component:e,data:t,host:a,outline:n,onError:o}){let r=(0,zo.useRef)(null),i=(0,zo.useRef)(null),l=(0,zo.useRef)(t),[s,c]=(0,zo.useState)(""),d=ue(Eo);l.current=t;let u=(0,zo.useRef)(n);return u.current=n,(0,zo.useEffect)(()=>o?.(s),[s,o]),(0,zo.useEffect)(()=>{if(!r.current||!a.hasAttribute("data-showai-inline-root")||!a.contains(r.current)||window.showai){c(d("inlineOnlyInConversation"));return}if(!e.inline){c(d("inlineUnavailable",{component:`${e.id}@${e.version}`}));return}let p=r.current.shadowRoot??r.current.attachShadow({mode:"open"}),g=document.createElement("style");g.textContent=":host{display:block;font:14px/1.6 system-ui,sans-serif;color:inherit}*{box-sizing:border-box}button,input,select,textarea{font:inherit}.component-root{display:flow-root;overflow-wrap:anywhere}"+e.inline.styles.replace(/:root\b|(?<![\w-])(?:html|body)(?=\s*[{,])/g,":host");let y=document.createElement("div");y.className="component-root",p.replaceChildren(g,y);let b=Kl(p),x=globalThis,f=x.__SHOWAI_COMPONENT_HOST__,m=`__showai_mount_${crypto.randomUUID().replaceAll("-","")}`;x.__SHOWAI_COMPONENT_HOST__={react:dT,client:pT,dom:uT,jsx:mT,jsxDev:fT};let v=r.current.closest("[data-block-id],[data-surface-id]"),T=v?.dataset.blockId??v?.dataset.surfaceId,w=!!T&&!!a.closest("[data-showai-conversation]"),E=H=>{let S=q2(H);if(S)throw new Error(`onContext: ${S}`);if(navigator.userActivation&&!navigator.userActivation.isActive)return!1;let k=JSON.parse(JSON.stringify(H));return Vh.set(T,k),r.current?.dispatchEvent(new CustomEvent(gT,{bubbles:!0,composed:!0,detail:{blockId:T,componentId:e.id,name:e.name,snapshot:k}})),!0};x[m]=H=>{i.current=H.mount(y,{data:l.current,outline:u.current,onError:c,...w?{onContext:E,context:Vh.get(T)}:{}})};let L=document.createElement("script");L.textContent=`(()=>{${e.inline.script}
23
23
  globalThis[${JSON.stringify(m)}](ShowAIInlineComponent);})();`;try{a.appendChild(L),i.current||c(d("inlineBlocked"))}finally{L.remove(),delete x[m],f===void 0?delete x.__SHOWAI_COMPONENT_HOST__:x.__SHOWAI_COMPONENT_HOST__=f}return()=>{b();let H=i.current;i.current=null,queueMicrotask(()=>H?.destroy())}},[e.integrity,a]),(0,zo.useEffect)(()=>i.current?.update(t,n),[t,n]),(0,L1.jsxs)("section",{"aria-label":e.name,style:{margin:"18px 0"},children:[(0,L1.jsx)("div",{ref:r}),s&&(0,L1.jsx)("p",{role:"alert",className:"custom-props-error",children:s})]})}var bT=vt(Eo),Zh=(e,t,a)=>`${e}@${t}#${a}`;function Gh(e){let t=new Map;for(let a of e){let n=Zh(a.id,a.version,a.integrity),o=t.get(n);if(o&&(o.html!==a.html||JSON.stringify(o.schema)!==JSON.stringify(a.schema)||JSON.stringify(o.inline)!==JSON.stringify(a.inline)))throw new Error(`Conflicting component payloads claim the same fingerprint: ${n}.`);o||t.set(n,a)}return t}function $h(e,t){if(t.integrity)return e.get(Zh(t.componentId,t.version,t.integrity));let a=[...e.values()].filter(n=>n.id===t.componentId&&n.version===t.version&&(!t.scope||n.scope===t.scope));if(a.length>1)throw new Error(bT("ambiguousVersion",{component:`${t.componentId}@${t.version}`}));return a[0]}function hT(e){if(!(typeof e!="string"||e.length>8192))return Fn(e)}function qh(e){document.addEventListener("click",t=>{if(!t.isTrusted||t.defaultPrevented||t.button!==0)return;let a=t.composedPath().find(o=>o instanceof HTMLAnchorElement&&o.hasAttribute("href"));if(!a||a.hasAttribute("download"))return;let n=a.getAttribute("href")??"";if(/^file:/i.test(n)){t.preventDefault(),parent.postMessage({channel:e,type:"showai:open-media",url:n},"*");return}/^https?:\/\//i.test(n)&&(t.preventDefault(),parent.postMessage({channel:e,type:"showai:open-url",url:n},"*"))})}function Fh(e){let t=hT(e);if(!t||navigator.userActivation?.isActive!==!0)return!1;let a=document.createElement("a");return a.href=t,a.target="_blank",a.rel="noopener noreferrer",a.referrerPolicy="no-referrer",a.click(),!0}var Nr=U(Ne(),1),Jh=U(h2(),1);var yT="showai-media";function Wh(e){return typeof e=="string"&&e.length<=4096&&/^file:/i.test(e)}function Kh(e){return window.__SHOWAI_LOCAL__?`/api/media/${e}`:`${yT}://media/${e}`}ct(`.showai-custom-block{position:relative}.custom-props-trigger{position:absolute;right:8px;top:-13px;z-index:2;width:28px;height:26px;display:grid;place-items:center;padding:0;border:1px solid var(--border, #dfe6df);border-radius:6px;color:var(--text-secondary, #657465);background:var(--surface, #fff);cursor:pointer;opacity:0;transition:opacity .12s ease}.showai-custom-block:hover>.custom-props-trigger,.showai-custom-block:focus-within>.custom-props-trigger{opacity:1}.custom-props-trigger:focus-visible{outline:2px solid var(--accent, #547c63);outline-offset:3px}.custom-props-editor{padding:14px;margin-bottom:12px;border:1px solid var(--border, #dfe6df);border-radius:9px;background:var(--surface, #fff);color:var(--text, #292d29);font:13px/1.5 system-ui,sans-serif}.custom-props-editor>label{display:block;font-weight:600;margin-bottom:8px}.custom-props-editor textarea{display:block;width:100%;resize:vertical;min-height:110px;max-height:400px;padding:10px;border:1px solid var(--border, #dfe6df);border-radius:6px;background:var(--bg, #fff);color:inherit;font:12px/1.65 ui-monospace,monospace}.custom-props-error{color:#ae3c3c;margin:9px 0 0;font-size:12px;overflow-wrap:anywhere}.custom-props-actions{display:flex;justify-content:flex-end;gap:8px;margin-top:10px}.custom-props-actions button{padding:5px 12px;border:1px solid var(--border, #dfe6df);border-radius:6px;font:inherit;color:inherit;background:transparent;cursor:pointer}.custom-props-actions button:last-child{color:#fff;background:var(--accent, #547c63);border-color:transparent}.custom-props-actions button:disabled{opacity:.5;cursor:default}@media(hover:none){.custom-props-trigger{opacity:1}}@media print{.custom-props-trigger,.custom-props-editor{display:none!important}}@media(prefers-reduced-motion:reduce){.custom-props-trigger{transition:none}}.showai-local-media{position:fixed;inset:0;z-index:500;display:flex;align-items:center;justify-content:center;padding:50px 65px;background:#101611f2;backdrop-filter:blur(12px);color:#f1f5ee;font:13px/1.5 Avenir Next,PingFang SC,system-ui,sans-serif}.showai-local-media figure{margin:0;min-width:0;max-width:100%;max-height:100%;display:flex;flex-direction:column;align-items:center}.showai-local-media video,.showai-local-media img{max-width:100%;max-height:calc(100dvh - 190px);object-fit:contain;display:block;background:#000;border-radius:6px}.showai-local-media audio{width:min(560px,80vw)}.showai-local-media figcaption{font-size:12px;line-height:1.8;text-align:center;padding:15px 0 0;overflow-wrap:anywhere}.showai-local-media figcaption>span{display:block;color:#a8b2a7;font-size:10px;padding-top:5px}.showai-local-media-close{position:absolute;top:20px;right:22px;width:39px;height:39px;display:flex;align-items:center;justify-content:center;border:1px solid #ffffff15;border-radius:50%;background:#ffffff0b;color:#f1f5ee;cursor:pointer}.showai-local-media-close:hover{background:#ffffff20}.showai-local-media-note{margin:0 0 12px;font-size:14px;text-align:center}.showai-local-media-path{user-select:all;font-family:ui-monospace,Menlo,monospace}.showai-local-media figcaption>.showai-local-media-actions{display:flex;justify-content:center;gap:8px;padding-top:10px}.showai-local-media-actions>button{display:inline-flex;align-items:center;gap:5px;padding:4px 10px;border:1px solid #ffffff26;border-radius:999px;background:#ffffff0f;color:#f1f5ee;font:inherit;font-size:12px;cursor:pointer}.showai-local-media-actions>button:hover{background:#ffffff20}.showai-local-media-close:focus-visible,.showai-local-media-actions>button:focus-visible{outline:2px solid #b8ceba;outline-offset:3px}@media(prefers-reduced-motion:reduce){.showai-local-media{backdrop-filter:none}}
24
24
  `);var aa=U(pe(),1),W2=null;function Xh(e){if(!Wh(e)||navigator.userActivation?.isActive!==!0)return!1;W2?.();let t=document.createElement("div");document.body.append(t);let a=(0,Jh.createRoot)(t),n=()=>{W2===n&&(W2=null,a.unmount(),t.remove())};return W2=n,a.render((0,aa.jsx)(vT,{link:e,onClose:n})),!0}function vT({link:e,onClose:t}){let a=vt(Eo),[n,o]=(0,Nr.useState)({status:"loading"}),[r,i]=(0,Nr.useState)(!1),[l,s]=(0,Nr.useState)(""),[c,d]=(0,Nr.useState)(!1),u=(0,Nr.useRef)(null),p=window.showai;(0,Nr.useEffect)(()=>{let f=document.activeElement;return u.current?.focus(),p?p.invoke("media:open",{path:e}).then(m=>o({status:"ready",grant:m})).catch(m=>o({status:"error",message:m?.code==="NOT_FOUND"?a("media.notFound"):a("media.failed",{error:Yh(m)})})):o({status:"error",message:a("media.unavailable")}),()=>f?.focus({preventScroll:!0})},[]);let g=n.status==="ready"?n.grant:void 0,y=g?.path??xT(e),b=async()=>{try{await navigator.clipboard.writeText(y)}catch{await p?.invoke("clipboard:write",{text:y})}i(!0)},x=g?.kind?Kh(g.token):void 0;return(0,aa.jsxs)("div",{className:"showai-local-media",role:"dialog","aria-modal":"true","aria-label":g?.name??a("media.title"),onClick:f=>{f.target===f.currentTarget&&t()},onKeyDown:f=>{if(f.key==="Escape"&&(f.stopPropagation(),t()),f.key==="Tab"){let m=Array.from(f.currentTarget.querySelectorAll("button,video,audio")),v=m[0],T=m.at(-1);f.shiftKey&&document.activeElement===v&&(f.preventDefault(),T?.focus()),!f.shiftKey&&document.activeElement===T&&(f.preventDefault(),v?.focus())}},children:[(0,aa.jsx)("button",{ref:u,type:"button",className:"showai-local-media-close","aria-label":a("media.close"),onClick:t,children:(0,aa.jsx)(on,{size:24})}),(0,aa.jsxs)("figure",{children:[n.status==="loading"&&(0,aa.jsx)("p",{className:"showai-local-media-note",children:a("media.loading")}),n.status==="error"&&(0,aa.jsx)("p",{className:"showai-local-media-note",role:"alert",children:n.message}),g&&!g.kind&&(0,aa.jsx)("p",{className:"showai-local-media-note",children:a("media.unsupported")}),x&&c&&(0,aa.jsx)("p",{className:"showai-local-media-note",role:"alert",children:a("media.playFailed")}),x&&g?.kind==="video"&&!c&&(0,aa.jsx)("video",{src:x,controls:!0,autoPlay:!0,playsInline:!0,onError:()=>d(!0)}),x&&g?.kind==="audio"&&!c&&(0,aa.jsx)("audio",{src:x,controls:!0,autoPlay:!0,onError:()=>d(!0)}),x&&g?.kind==="image"&&!c&&(0,aa.jsx)("img",{src:x,alt:g.name,onError:()=>d(!0)}),(0,aa.jsxs)("figcaption",{children:[g?.name??y.split("/").at(-1),(0,aa.jsx)("span",{className:"showai-local-media-path",children:y}),(0,aa.jsxs)("span",{className:"showai-local-media-actions",children:[(0,aa.jsxs)("button",{type:"button",onClick:()=>{b()},children:[(0,aa.jsx)(Q1,{size:13}),a(r?"media.copied":"media.copyPath")]}),g&&p&&(0,aa.jsxs)("button",{type:"button",onClick:()=>{p.invoke("media:reveal",{token:g.token}).catch(f=>s(a("media.failed",{error:Yh(f)})))},children:[(0,aa.jsx)(t0,{size:13}),a("media.reveal")]})]}),l&&(0,aa.jsx)("span",{role:"alert",children:l})]})]})]})}function xT(e){let t=e.replace(/^file:(\/\/(localhost)?)?/i,"");try{return decodeURIComponent(t)}catch{return t}}function Yh(e){let t=e?.message;return typeof t=="string"?t:String(e)}function Qh(e){let t=!0,a=window.requestAnimationFrame.bind(window),n=window.cancelAnimationFrame.bind(window),o=window.setInterval.bind(window),r=new Map,i=l=>{let s=r.get(l);s&&(s.native=a(c=>{s.native=null,t&&(r.delete(l),s.callback(c))}))};window.requestAnimationFrame=l=>{let s=0,c=a(d=>{let u=r.get(s);u&&(u.native=null,t&&(r.delete(s),l(d)))});return s=c,r.set(s,{callback:l,native:t?c:null}),t||n(c),s},window.cancelAnimationFrame=l=>{let s=r.get(l);s?.native!==null&&s?.native!==void 0?n(s.native):n(l),r.delete(l)},window.setInterval=((l,s,...c)=>typeof l=="function"?o(()=>{t&&l.apply(window,c)},s):o(l,s,...c)),window.addEventListener("message",l=>{if(!(l.source!==window.parent||l.data?.channel!==e||l.data?.type!=="showai:activity"||typeof l.data.active!="boolean")&&t!==l.data.active){t=l.data.active;for(let[s,c]of r)!t&&c.native!==null?(n(c.native),c.native=null):t&&c.native===null&&i(s)}})}var Xa=rt("common",{"zh-CN":{cancel:"\u53D6\u6D88",close:"\u5173\u95ED",confirm:"\u786E\u8BA4",save:"\u4FDD\u5B58",delete:"\u5220\u9664",remove:"\u79FB\u9664",rename:"\u91CD\u547D\u540D",edit:"\u7F16\u8F91",done:"\u5B8C\u6210",retry:"\u91CD\u8BD5",open:"\u6253\u5F00",copy:"\u590D\u5236",copied:"\u5DF2\u590D\u5236",create:"\u521B\u5EFA",add:"\u6DFB\u52A0",back:"\u8FD4\u56DE",next:"\u4E0B\u4E00\u6B65",continue:"\u7EE7\u7EED",search:"\u641C\u7D22",loading:"\u6B63\u5728\u52A0\u8F7D\u2026",opening:"\u6B63\u5728\u6253\u5F00\u2026",reading:"\u6B63\u5728\u8BFB\u53D6\u2026",saving:"\u6B63\u5728\u4FDD\u5B58\u2026",saved:"\u5DF2\u4FDD\u5B58",untitled:"\u65E0\u6807\u9898",untitledPage:"\u672A\u547D\u540D\u9875\u9762",more:"\u66F4\u591A",options:"\u9009\u9879",settings:"\u8BBE\u7F6E",refresh:"\u5237\u65B0",import:"\u5BFC\u5165",export:"\u5BFC\u51FA",preview:"\u9884\u89C8",details:"\u8BE6\u60C5",unknownError:"\u672A\u77E5\u9519\u8BEF",lightAppearance:"\u6D45\u8272\u5916\u89C2",darkAppearance:"\u6DF1\u8272\u5916\u89C2",pageOptions:"\u9875\u9762\u9009\u9879",downloadSource:"\u4E0B\u8F7D\u6E90\u6587\u4EF6",print:"\u6253\u5370",dismissNotice:"\u5173\u95ED\u63D0\u793A"},en:{cancel:"Cancel",close:"Close",confirm:"Confirm",save:"Save",delete:"Delete",remove:"Remove",rename:"Rename",edit:"Edit",done:"Done",retry:"Retry",open:"Open",copy:"Copy",copied:"Copied",create:"Create",add:"Add",back:"Back",next:"Next",continue:"Continue",search:"Search",loading:"Loading\u2026",opening:"Opening\u2026",reading:"Reading\u2026",saving:"Saving\u2026",saved:"Saved",untitled:"Untitled",untitledPage:"Untitled page",more:"More",options:"Options",settings:"Settings",refresh:"Refresh",import:"Import",export:"Export",preview:"Preview",details:"Details",unknownError:"Unknown error",lightAppearance:"Light appearance",darkAppearance:"Dark appearance",pageOptions:"Page options",downloadSource:"Download source file",print:"Print",dismissNotice:"Dismiss notice"}});var ey=U(Ne(),1),ec=(0,ey.createContext)(null);var qt=U(pe(),1),K2=(0,ot.createContext)(new Map),Y2=(0,ot.createContext)(null),ay=()=>(0,ot.useContext)(Y2);function Fm({components:e,children:t,inlineHost:a=null}){let n=(0,ot.useMemo)(()=>Gh(e),[e]);return(0,qt.jsx)(K2.Provider,{value:n,children:(0,qt.jsx)(Y2.Provider,{value:a,children:t})})}function tc(){let e=(0,ot.useContext)(K2);return(0,ot.useMemo)(()=>[...e.values()],[e])}function ny({components:e,children:t}){let a=(0,ot.useContext)(K2),n=(0,ot.useContext)(Y2),o=(0,ot.useMemo)(()=>[...a.values(),...e],[a,e]);return(0,qt.jsx)(Fm,{components:o,inlineHost:n,children:t})}function yl(e){return JSON.stringify(e).replace(/</g,"\\u003c").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}function ty(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;let t=(a,n=0)=>n>40?!1:a===null||typeof a=="boolean"||typeof a=="string"?!0:typeof a=="number"?Number.isFinite(a):Array.isArray(a)?a.every(o=>t(o,n+1)):!!a&&typeof a=="object"&&Object.getPrototypeOf(a)===Object.prototype&&Object.entries(a).every(([o,r])=>!["__proto__","constructor","prototype"].includes(o)&&t(r,n+1));return t(e)}function oy({data:e,onChange:t,readOnly:a}){let n=Ai(e),o=(0,ot.useContext)(K2),r=(0,ot.useContext)(Y2),i=$h(o,n),l=ue(Eo),s=`${n.componentId}@${n.version}`;return i&&r?(0,qt.jsx)(F2,{component:i,data:n.props,host:r},i.integrity):i?(0,qt.jsx)(wT,{component:i,data:e,onChange:t,readOnly:a},i.integrity):(0,qt.jsx)("section",{className:"sb-block sb-unavailable","aria-label":l("notInstalled"),children:(0,qt.jsxs)("div",{style:{padding:18},children:[(0,qt.jsx)("strong",{children:n.componentId}),(0,qt.jsx)("p",{children:n.integrity?l("installRequiredIntegrity",{component:s,integrity:n.integrity.slice(7,19)}):l("installRequired",{component:s})})]})})}function wT({component:e,data:t,onChange:a,readOnly:n}){let o=Ai(t),r=(0,ot.useRef)(null),i=Z2(),l=ue(Eo),s=ue(Xa),c=$l(),d=(0,ot.useRef)(i),[u]=(0,ot.useState)(()=>crypto.randomUUID());y6(r,u);let[p,g]=(0,ot.useState)(180),[y,b]=(0,ot.useState)(""),[x,f]=(0,ot.useState)(!1),[m,v]=(0,ot.useState)(""),[T,w]=(0,ot.useState)(""),[E,L]=(0,ot.useState)(!1),H=(0,ot.useRef)(""),S=(0,ot.useRef)(null),k=(0,ot.useRef)(null),M=(0,ot.useContext)(ec),O=(0,ot.useRef)({data:t,parsed:o,onChange:a,readOnly:n,assistant:M}),C=(0,ot.useRef)({props:o.props,readOnly:!!n||!a});O.current={data:t,parsed:o,onChange:a,readOnly:n,assistant:M};let N=()=>{let j=r.current?.closest("[data-block-id],[data-surface-id]");return j?.dataset.blockId??j?.dataset.surfaceId},z=!!a&&!n,A=()=>{k.current&&window.clearTimeout(k.current.timeout),k.current=null,L(!1)},q=()=>{A(),f(!1),requestAnimationFrame(()=>S.current?.focus())},P=()=>{H.current=JSON.stringify(O.current.parsed.props),v(JSON.stringify(O.current.parsed.props,null,2)),w(""),f(!0)},Z=()=>{let j;try{j=JSON.parse(m)}catch($){w($ instanceof Error?$.message:l("invalidJson"));return}if(!ty(j)){w(l("notJsonObject"));return}try{bo(j,"Component instance data",Lt.componentPropsBytes)}catch($){w($ instanceof Error?$.message:l("dataTooLarge"));return}if(JSON.stringify(O.current.parsed.props)!==H.current){w(l("dataChanged"));return}A(),w("");let K=crypto.randomUUID(),_=window.setTimeout(()=>{k.current=null,L(!1),w(l("validationTimeout"))},5e3);k.current={id:K,props:j,timeout:_},L(!0),r.current?.contentWindow?.postMessage({channel:u,type:"showai:validate",requestId:K,props:j},"*")},F=(0,ot.useMemo)(()=>`<!doctype html><meta http-equiv="Content-Security-Policy" content="${Js}">`+Qs(e.html,`<style>body{color:var(--text)}</style><script>document.documentElement.lang=document.documentElement.dataset.showaiLocale=${yl(c)};(${Qh.toString()})(${yl(u)});(${G2.toString()})(${yl(u)},${yl(d.current)},${yl(Xs())});<\/script><script id="showai-component-data" type="application/json">${yl({channel:u,...C.current})}<\/script>`)+`<script>${g6(u)}(${Kl.toString()})(document);(${qh.toString()})(${yl(u)});<\/script>`,[e.html,u,c]),ee=()=>{let j=O.current;r.current?.contentWindow?.postMessage({channel:u,type:"showai:props",props:j.parsed.props,readOnly:!!j.readOnly||!j.onChange,context:!!j.assistant&&!!N()},"*")};return(0,ot.useEffect)(()=>{let j=r.current,K=()=>j?.contentWindow?.postMessage({channel:u,type:"showai:activity",active:!0},"*");return K(),j?.addEventListener("load",K),()=>{j?.removeEventListener("load",K),j?.contentWindow?.postMessage({channel:u,type:"showai:activity",active:!1},"*")}},[u]),(0,ot.useEffect)(()=>{let j=K=>{if(K.source!==r.current?.contentWindow||!K.data||K.data.channel!==u)return;if(K.data.type==="showai:ready"){ee();let D=N(),V=D?O.current.assistant?.pendingComponentContext(D):void 0;V&&r.current?.contentWindow?.postMessage({channel:u,type:"showai:context-restore",snapshot:V},"*")}if(K.data.type==="showai:context"){let D=K.data.snapshot,V=N();if(!V||q2(D))return;O.current.assistant?.componentContext({...D,blockId:V,componentId:O.current.parsed.componentId,name:e.name});return}if(K.data.type==="showai:open-url"){let D=new CustomEvent("showai:component-link",{bubbles:!0,cancelable:!0,detail:{url:K.data.url}});r.current?.dispatchEvent(D)!==!1&&Fh(K.data.url);return}if(K.data.type==="showai:open-media"){Xh(K.data.url);return}if(K.data.type==="showai:height"&&typeof K.data.height=="number"&&Number.isFinite(K.data.height)&&g(Math.min(4e3,Math.max(48,Math.ceil(K.data.height)))),K.data.type==="showai:error"&&b(String(K.data.message||l("cannotDisplay")).slice(0,500)),K.data.type==="showai:valid"&&b(""),["showai:viewport-lock-get","showai:viewport-lock-set"].includes(K.data.type)&&typeof K.data.scope=="string"&&/^[a-z0-9-]+:\d{1,4}$/.test(K.data.scope)){let D=K.data.scope,V=w6(r.current,D),B=!0,de="";try{K.data.type==="showai:viewport-lock-set"&&typeof K.data.locked=="boolean"&&S6(V,K.data.locked),B=k6(V)}catch(he){de=l("viewportLockFailed",{error:String(he)})}r.current?.contentWindow?.postMessage({channel:u,type:"showai:viewport-lock-state",scope:D,locked:B,error:de},"*")}if(K.data.type==="showai:reading-wheel"&&[K.data.deltaX,K.data.deltaY,K.data.deltaMode].every(Number.isFinite)){let D=r.current,V=new WheelEvent("wheel",{bubbles:!0,cancelable:!0,deltaX:K.data.deltaX,deltaY:K.data.deltaY,deltaMode:K.data.deltaMode,ctrlKey:K.data.ctrlKey===!0,metaKey:K.data.metaKey===!0,shiftKey:K.data.shiftKey===!0});if(D.dispatchEvent(V)&&!V.ctrlKey&&!V.metaKey){let B=V.deltaY*(V.deltaMode===1?16:V.deltaMode===2?D.clientHeight:1);for(let de=D.parentElement;de&&B;de=de.parentElement){if(!/auto|scroll/.test(getComputedStyle(de).overflowY))continue;let he=de.scrollTop;de.scrollTop+=B,B-=de.scrollTop-he}}}let _=O.current,$=k.current;if(K.data.type==="showai:validation"&&$&&$.id===K.data.requestId&&(A(),K.data.valid!==!0?w(String(K.data.message||l("invalidProps")).slice(0,1e3)):JSON.stringify(_.parsed.props)!==H.current?w(l("dataChanged")):!_.readOnly&&_.onChange&&(_.onChange({..._.data,props:$.props}),q())),K.data.type==="showai:change"&&!_.readOnly&&_.onChange&&ty(K.data.props)){try{bo(K.data.props,"Component instance data",Lt.componentPropsBytes)}catch(D){w(D instanceof Error?D.message:l("dataTooLarge"));return}_.onChange({..._.data,props:K.data.props})}};return window.addEventListener("message",j),()=>{window.removeEventListener("message",j),k.current&&window.clearTimeout(k.current.timeout)}},[u]),(0,ot.useEffect)(ee,[o.props,n,z,u,!!M]),(0,ot.useEffect)(()=>{let j=()=>r.current?.contentWindow?.postMessage({channel:u,type:"showai:theme",theme:i,tokens:Xs()},"*"),K=r.current;return K?.addEventListener("load",j),j(),()=>K?.removeEventListener("load",j)},[i,u]),(0,qt.jsxs)("section",{className:"showai-custom-block","aria-label":e.name,style:{margin:"18px 0"},children:[z&&!x&&(0,qt.jsx)("button",{ref:S,type:"button",className:"custom-props-trigger","aria-label":l("editData"),title:l("editData"),onClick:P,children:(0,qt.jsx)(Rl,{size:15})}),z&&x&&(0,qt.jsxs)("div",{className:"custom-props-editor",onKeyDown:j=>{j.key==="Escape"&&(j.stopPropagation(),q())},children:[(0,qt.jsx)("label",{htmlFor:`${u}-props`,children:l("data")}),(0,qt.jsx)("textarea",{id:`${u}-props`,"aria-label":l("propsJson"),value:m,spellCheck:!1,rows:Math.max(5,Math.min(14,m.split(`
25
25
  `).length)),autoFocus:!0,onChange:j=>{v(j.target.value),w("")},disabled:E}),T&&(0,qt.jsx)("p",{role:"alert",className:"custom-props-error",children:T}),(0,qt.jsxs)("div",{className:"custom-props-actions",children:[(0,qt.jsx)("button",{type:"button",onClick:q,children:s("cancel")}),(0,qt.jsx)("button",{type:"button",disabled:E,onClick:Z,children:l(E?"validating":"apply")})]})]}),!x&&T&&(0,qt.jsx)("p",{role:"alert",className:"custom-props-error",children:T}),(0,qt.jsx)("iframe",{ref:r,title:e.name,srcDoc:F,sandbox:"allow-scripts allow-forms allow-downloads",referrerPolicy:"no-referrer",onLoad:ee,allow:"camera 'none'; microphone 'none'; geolocation 'none'; clipboard-read 'none'; clipboard-write 'none'",style:{width:"100%",height:p,border:0,display:"block",background:"transparent"}}),y&&(0,qt.jsx)("p",{role:"alert",style:{color:"#ae3c3c",fontSize:12},children:y})]})}var or=rt("pageOutline",{"zh-CN":{entryTitle:"\u663E\u793A\u540D\u79F0",entryTarget:"\u8DF3\u8F6C\u76EE\u6807",group:"\u65B0\u5206\u7EC4",missingTarget:"\u76EE\u6807\u5DF2\u5220\u9664",up:"\u4E0A\u79FB",down:"\u4E0B\u79FB",indent:"\u964D\u4F4E\u5C42\u7EA7",outdent:"\u63D0\u5347\u5C42\u7EA7",removeEntry:"\u79FB\u9664\u6761\u76EE",addEntry:"\u6DFB\u52A0\u76EE\u5F55\u6761\u76EE",title:"\u672C\u9875\u76EE\u5F55",settings:"\u76EE\u5F55\u8BBE\u7F6E",enable:"\u542F\u7528\u672C\u9875\u76EE\u5F55",expand:"\u5C55\u5F00\u76EE\u5F55",collapse:"\u6536\u8D77\u76EE\u5F55",pin:"\u56FA\u5B9A\u76EE\u5F55",unpin:"\u53D6\u6D88\u56FA\u5B9A",close:"\u5173\u95ED",apply:"\u5E94\u7528",renderer:"\u76EE\u5F55\u7EC4\u4EF6",builtin:"\u9605\u8BFB\u7D22\u5F15\uFF08\u5185\u7F6E\uFF09",loading:"\u6B63\u5728\u52A0\u8F7D\u76EE\u5F55\u7EC4\u4EF6\u2026",unavailable:"\u76EE\u5F55\u7EC4\u4EF6\u4E0D\u53EF\u7528\uFF0C\u5DF2\u663E\u793A\u57FA\u7840\u76EE\u5F55\u3002",empty:"\u6DFB\u52A0\u6B63\u6587\u6807\u9898\u6216\u76EE\u5F55\u6761\u76EE\u540E\u5373\u53EF\u5BFC\u822A\u3002",source:"\u76EE\u5F55\u5185\u5BB9",headings:"\u6B63\u6587\u6807\u9898",manual:"\u624B\u52A8\u76EE\u5F55",depth:"\u6536\u5F55\u6807\u9898\u6DF1\u5EA6",config:"\u7ED3\u6784\u914D\u7F6E\uFF08JSON\uFF09",props:"\u7EC4\u4EF6\u53C2\u6570\uFF08JSON\uFF09",initial:"\u521D\u59CB\u72B6\u6001",auto:"\u81EA\u52A8",expanded:"\u5C55\u5F00",collapsed:"\u6536\u8D77",placement:"\u76EE\u5F55\u4F4D\u7F6E",floating:"\u6D6E\u52A8",docked:"\u56FA\u5B9A\u4FA7\u680F",width:"\u76EE\u5F55\u5BBD\u5EA6\uFF08px\uFF09",missing:"\u6709 {count} \u4E2A\u76EE\u6807\u5DF2\u5931\u6548\uFF0C\u8BF7\u4FEE\u6539\u624B\u52A8\u76EE\u5F55\u3002",remove:"\u79FB\u9664\u76EE\u5F55\u914D\u7F6E",invalidJson:"\u8BF7\u8F93\u5165\u6709\u6548\u7684 JSON\u3002",errorChanged:"\u9875\u9762\u76EE\u5F55\u5DF2\u88AB\u4FEE\u6539\uFF0C\u8BF7\u91CD\u65B0\u6253\u5F00\u8BBE\u7F6E\u3002",rendererChanged:"\u8BF7\u5148\u5E94\u7528\u5F53\u524D\u7EC4\u4EF6\u9009\u62E9\uFF0C\u518D\u4FEE\u6539\u7EC4\u4EF6\u53C2\u6570\u3002",manualHint:"\u6761\u76EE\u4F7F\u7528 id\u3001title\u3001nodeId\u3001children\uFF1B\u5206\u7EC4\u53EF\u7701\u7565 nodeId\u3002",headingsHint:"\u4EE5\u6807\u9898\u8282\u70B9 ID \u4E3A\u952E\u8BBE\u7F6E title \u6216 hidden\u3002",sourceCode:"\u76EE\u5F55\u7EC4\u4EF6\u53EF\u5728\u7EC4\u4EF6\u5E93\u7684\u201C\u9875\u9762\u76EE\u5F55\u201D\u5206\u7C7B\u4E2D\u7F16\u8F91\u3002",rendererError:"\u76EE\u5F55\u7EC4\u4EF6\uFF1A{error}",errorMissingTarget:"\u76EE\u6807\u4E0D\u5B58\u5728\u6216\u4E0D\u5C5E\u4E8E\u5F53\u524D Page\u3002"},en:{entryTitle:"Display title",entryTarget:"Navigation target",group:"New group",missingTarget:"Target removed",up:"Move up",down:"Move down",indent:"Indent",outdent:"Outdent",removeEntry:"Remove entry",addEntry:"Add outline entry",title:"On this page",settings:"Outline settings",enable:"Enable page outline",expand:"Expand outline",collapse:"Collapse outline",pin:"Pin outline",unpin:"Unpin outline",close:"Close",apply:"Apply",renderer:"Outline component",builtin:"Reading index (built in)",loading:"Loading outline component\u2026",unavailable:"Outline component unavailable. Showing the basic outline.",empty:"Add headings or outline entries to start navigating.",source:"Outline content",headings:"Page headings",manual:"Manual outline",depth:"Heading depth",config:"Structure configuration (JSON)",props:"Component parameters (JSON)",initial:"Initial state",auto:"Automatic",expanded:"Expanded",collapsed:"Collapsed",placement:"Placement",floating:"Floating",docked:"Docked sidebar",width:"Outline width (px)",missing:"{count} targets are unavailable. Update the manual outline.",remove:"Remove outline configuration",invalidJson:"Enter valid JSON.",errorChanged:"The outline has changed. Reopen settings.",rendererChanged:"Apply the component selection before editing its parameters.",manualHint:"Entries use id, title, nodeId and children. Groups may omit nodeId.",headingsHint:"Use heading node IDs as keys with title or hidden overrides.",sourceCode:"Edit outline components in the Page outlines category of the component library.",rendererError:"Outline component: {error}",errorMissingTarget:"Target is missing or outside this Page."}});var co=U(Ne(),1);var P1=U(pe(),1),R1=e=>JSON.stringify(e).replace(/</g,"\\u003c").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029");function ry({component:e,contract:t,onError:a}){let n=ay();return(0,P1.jsx)(Wm,{onError:a,children:n?(0,P1.jsx)(F2,{component:e,data:t.props,outline:t,host:n,onError:a}):(0,P1.jsx)(kT,{component:e,contract:t,onError:a})})}var Wm=class extends co.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(t){this.props.onError(String(t?.message??t??"Outline renderer failed.").slice(0,500))}render(){return this.state.failed?null:this.props.children}};function kT({component:e,contract:t,onError:a}){let n=(0,co.useRef)(null),[o]=(0,co.useState)(()=>crypto.randomUUID()),r=(0,co.useRef)({contract:t,onError:a});r.current={contract:t,onError:a};let i=(0,co.useMemo)(()=>`<!doctype html><meta http-equiv="Content-Security-Policy" content="${Js}">`+Qs(e.html,`<script>(${G2.toString()})(${R1(o)},${R1(t.outline.theme)},${R1(Xs())});window.addEventListener('keydown',event=>{if(event.key==='Escape'){event.preventDefault();parent.postMessage({channel:${R1(o)},type:'showai:outline-action',action:'collapse'},'*');}},true);<\/script><script id="showai-component-data" type="application/json">${R1({channel:o,props:t.props,readOnly:!0,outline:t.outline})}<\/script>`),[e.html,o]),l=()=>{let s=r.current.contract;n.current?.contentWindow?.postMessage({channel:o,type:"showai:props",props:s.props,readOnly:!0},"*"),n.current?.contentWindow?.postMessage({channel:o,type:"showai:outline",outline:s.outline},"*"),n.current?.contentWindow?.postMessage({channel:o,type:"showai:theme",theme:s.outline.theme,tokens:Xs()},"*")};return(0,co.useEffect)(()=>{let s=window.setTimeout(()=>r.current.onError("Outline component did not become ready."),8e3),c=d=>{if(d.source!==n.current?.contentWindow||d.data?.channel!==o)return;let u=d.data,p=r.current.contract;u.type==="showai:ready"&&(clearTimeout(s),l()),u.type==="showai:error"&&r.current.onError(String(u.message).slice(0,500)),u.type==="showai:outline-action"&&(u.action==="collapse"&&p.collapse(),u.action==="navigate"&&typeof u.itemId=="string"&&p.navigate(u.itemId),u.action==="branch"&&typeof u.itemId=="string"&&typeof u.expanded=="boolean"&&p.setBranchExpanded(u.itemId,u.expanded))};return window.addEventListener("message",c),()=>{clearTimeout(s),window.removeEventListener("message",c)}},[o]),(0,co.useEffect)(l,[t,o]),(0,P1.jsx)("iframe",{ref:n,className:"page-outline-frame",title:e.name,sandbox:"allow-scripts",srcDoc:i,onLoad:l})}ct(`.page-outline-shell{position:relative;height:100%;min-height:0}.page-outline-shell[data-outline-docked=true]>.container-page{width:calc(100% - var(--page-outline-width) - 24px)}.page-outline-panel{position:absolute;inset:var(--page-outline-top, 16px) 12px 16px auto;z-index:35;display:flex;flex-direction:column;max-width:calc(100% - 24px);border-radius:9px;background:var(--paper, var(--bg));color:var(--text);overflow:hidden}.page-outline-panel[hidden],.page-outline-rail[hidden]{display:none}.page-outline-panel[data-placement=floating],.page-outline-panel[data-placement=drawer]{border:1px solid var(--line);box-shadow:0 8px 32px #00000020}.page-outline-panel[data-placement=docked]{border-left:1px solid var(--line);border-radius:0}.page-outline-panel>header{display:flex;align-items:center;gap:3px;flex-shrink:0;padding:9px 8px 12px}.page-outline-panel>header strong{flex:1;min-width:0;font-size:12px;font-weight:600}.page-outline-panel>header button{background:transparent;border:0;border-radius:5px;padding:6px;color:var(--muted);display:flex;cursor:pointer}.page-outline-panel>header button:hover{background:var(--hover);color:var(--text)}.page-outline-panel>header button[aria-pressed=true]{color:var(--accent);background:var(--hover)}.page-outline-content{flex:1;min-height:0;overflow:auto;padding:0 10px 14px;scrollbar-width:thin}.page-outline-content ol{list-style:none;margin:0;padding:0}.page-outline-content ol ol{margin-left:15px}.page-outline-row{display:flex;align-items:baseline;gap:3px}.page-outline-item{text-align:left;min-width:0;overflow-wrap:anywhere;flex:1;padding:7px 6px;font-size:12px!important;line-height:1.6;border:0;background:transparent;color:var(--muted);border-radius:5px;cursor:pointer}.page-outline-item:hover{background:var(--hover);color:var(--text)}.page-outline-item[aria-current=location]{color:var(--accent);background:var(--hover);font-weight:600}.page-outline-branch{padding:6px 0;flex-shrink:0;border:0;background:transparent;color:var(--muted);cursor:pointer}.page-outline-branch[aria-expanded=true] svg{transform:rotate(90deg)}.page-outline-rail{position:absolute;right:12px;top:var(--page-outline-top, 20px);z-index:35;display:flex;flex-direction:column;align-items:center;gap:9px;border:1px solid var(--line);background:var(--paper, var(--bg));color:var(--muted);padding:10px 8px;border-radius:8px;cursor:pointer}.page-outline-rail span{writing-mode:vertical-rl;font-size:11px;letter-spacing:2px}.page-outline-backdrop{position:absolute;inset:0;z-index:34;border:0;padding:0;background:#00000020}.page-outline-frame{display:block;width:100%;height:100%;min-height:150px;border:0;background:transparent}.page-outline-content:has(>.page-outline-frame){overflow:hidden;padding:0}.page-outline-empty,.page-outline-error{font-size:12px;color:var(--muted);padding:8px;line-height:1.7;overflow-wrap:anywhere}.page-outline-error span{display:block}.page-outline-settings{max-width:560px}.page-outline-settings-body{padding:4px 22px 22px;overflow:auto}.page-outline-settings-body label{display:flex;flex-direction:column;gap:7px;font-size:12px;margin:14px 0}.page-outline-settings-body label.page-outline-enable{flex-direction:row;align-items:center;font-size:14px}.page-outline-fields{display:grid;grid-template-columns:1fr 1fr;gap:15px}.page-outline-settings-body select,.page-outline-settings-body input[type=number],.page-outline-settings-body textarea{width:100%;padding:8px;border:1px solid var(--line);border-radius:6px;background:var(--paper, var(--bg));color:var(--text);font:inherit}.page-outline-settings-body textarea{resize:vertical;font-family:var(--font-mono, monospace)}.page-outline-settings-body details{font-size:12px;margin-top:12px}.page-outline-hint{font-size:12px;color:var(--muted);line-height:1.7;margin:8px 0}.page-outline-settings-body footer{display:flex;justify-content:flex-end;gap:10px;margin-top:18px}.page-outline-settings-body footer button{border:1px solid var(--line);background:var(--paper, var(--bg));color:var(--text);border-radius:6px;padding:8px 12px;cursor:pointer}.page-outline-settings-body footer .page-outline-apply{background:var(--accent);color:var(--paper, var(--bg))}@media(pointer:coarse){.page-outline-panel>header button,.page-outline-branch,.page-outline-item{min-height:44px}.page-outline-branch{min-width:28px}}@media print{.page-outline-rail,.page-outline-backdrop,.page-outline-panel{display:none!important}.page-outline-shell,.page-outline-shell>.container-page{display:contents}}.portable-app>.container-workspace>.container-main>.page-outline-shell{--page-outline-top: 68px}.outline-manual-editor ol{list-style:none;margin:0;padding:0}.outline-manual-editor ol ol{margin-left:18px;border-left:1px solid var(--line);padding-left:9px}.outline-manual-row{display:grid;grid-template-columns:1fr 1fr;gap:6px;margin:8px 0}.outline-manual-row input{min-width:0;width:100%;padding:7px;background:var(--paper);border:1px solid var(--line);border-radius:5px;color:var(--text);font:inherit}.outline-manual-row select{min-width:0}.outline-manual-actions{display:flex;grid-column:1/-1;justify-content:flex-end}.outline-manual-actions button,.outline-manual-add{display:inline-flex;gap:6px;align-items:center;border:0;background:transparent;color:var(--muted);padding:6px;cursor:pointer}.outline-manual-actions button:hover,.outline-manual-add:hover{background:var(--hover)}.outline-manual-actions button:disabled{opacity:.35;cursor:default}.page-outline-print{display:none}@media print{.page-outline-print{display:block;margin:20px 0 30px;break-inside:avoid}.page-outline-print ol{list-style:decimal;margin-left:20px;padding-left:10px}}.page-outline-content[data-custom=true]{padding:0;overflow:hidden}.page-outline-content[data-custom=true]>section{height:100%;margin:0!important;overflow:auto}.outline-manual-editor{max-height:360px;overflow:auto;margin:12px 0}
@@ -49,4 +49,4 @@ ${JSON.stringify(e)}`}var mc=rt("reader",{"zh-CN":{draftNote:"\u4EA4\u4E92\u9884
49
49
  `);ct(`:root,.studio,.studio.settings-view,.studio-modal-shade,.studio-context-menu,[data-showai-inline-root]{--font-sans: "Airbnb Cereal VF", "Circular", -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;--font-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;--brand: #120a8f;--action: #120a8f;--action-hover: #0d076b;--text: #222222;--muted: #6a6a6a;--subtle: #929292;--paper: #ffffff;--surface: #fafafa;--line: #dddddd;--hover: #f7f7f7;--accent: var(--action);--accent-soft: #eeedf9;--brand-accent: var(--brand);--danger: #c13515;--selected: #f2f2f2;--bg: var(--paper);--border: var(--line);--text-secondary: var(--muted);--editor-bg: var(--paper);--radius-control: 8px;--radius-card: 16px;--radius-panel: 20px;--radius-pill: 999px;--space-unit: 8px;--shadow: 0 0 0 1px #00000005, 0 2px 6px #0000000a, 0 4px 8px #00000014;--shadow-dialog: 0 16px 64px #00000024;--studio-topbar-height: 56px;font-family:var(--font-sans);font-weight:500;font-synthesis:none;color-scheme:light;color:var(--text);letter-spacing:0;-webkit-font-smoothing:antialiased;text-rendering:optimizeLegibility}:root[data-theme=dark],:root[data-theme=dark] .studio,:root[data-theme=dark] .studio.settings-view,:root[data-theme=dark] .studio-modal-shade,:root[data-theme=dark] .studio-context-menu,[data-showai-inline-root][data-theme=dark]{--text: #f7f7f7;--muted: #b0b0b0;--subtle: #929292;--paper: #181818;--surface: #222222;--line: #414141;--hover: #2c2c2c;--accent: #aaa4ff;--brand-accent: #aaa4ff;--accent-soft: #25233f;--selected: #2c2c2c;--danger: #ff9c86;--shadow: 0 0 0 1px #ffffff08, 0 2px 6px #00000030, 0 4px 8px #00000040;--shadow-dialog: 0 16px 64px #00000066;color-scheme:dark}:root,[data-showai-inline-root]{--ease-out: cubic-bezier(.23, 1, .32, 1);--ease-in-out: cubic-bezier(.77, 0, .175, 1);--duration-fast: .14s;--duration-base: .2s;--duration-slow: .32s}@keyframes showai-fade-in{0%{opacity:0}}@keyframes showai-pop-in{0%{opacity:0;scale:.96}}@keyframes showai-rise-in{0%{opacity:0;translate:0 8px}}@keyframes showai-shimmer{0%{background-position:100% 0}to{background-position:-100% 0}}.showai-text-shimmer{color:transparent;background:linear-gradient(90deg,var(--muted) 0%,var(--muted) 35%,var(--text) 50%,var(--muted) 65%,var(--muted) 100%) 0 0 / 200% 100%;-webkit-background-clip:text;background-clip:text;animation:showai-shimmer 2s linear infinite}button,input,textarea,select{font-family:inherit}button{transition:background-color .15s ease,color .15s ease,border-color .15s ease,transform .15s ease}button:focus-visible,a:focus-visible,summary:focus-visible{outline:2px solid var(--text);outline-offset:3px}input:is([type=checkbox],[type=radio],[type=range],[type=color],[type=file],[type=button],[type=submit],[type=reset]):focus-visible,select:focus-visible{outline:2px solid var(--text);outline-offset:2px}input:not([type=checkbox],[type=radio],[type=range],[type=color],[type=file],[type=button],[type=submit],[type=reset]):focus,textarea:focus{outline:none}input::placeholder,textarea::placeholder{color:var(--subtle)}::selection{background:var(--accent-soft);color:var(--text)}@media(prefers-reduced-motion:reduce){*,*:before,*:after{animation:none!important;transition:none!important;scroll-behavior:auto!important}}
50
50
  `);ct(`:root{--reading-text: #494650;--reading-heading: #383042;--reading-accent: #120a8f;--reading-highlight: #e6e1fc;--reading-code: #f0eef9}:root[data-theme=dark]{--reading-text: #d4d1dd;--reading-heading: #e4dfec;--reading-accent: #bbb3ff;--reading-highlight: #37304f;--reading-code: #29243a}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-text){font-family:var(--font-sans);font-size:16px;font-weight:400;line-height:1.8;letter-spacing:0;color:var(--reading-text)}.sb-text>.sb-rich-text{font:inherit;line-height:inherit}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) :is(h1,h2,h3,h4,h5,h6){color:var(--reading-heading);font-weight:600;letter-spacing:-.3px;scroll-margin-top:80px}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) h1{font-size:28px;line-height:1.35;margin:40px 0 14px}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) h2{font-size:22px;line-height:1.4;margin:34px 0 12px}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) h3{font-size:18px;line-height:1.45;margin:26px 0 8px}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) :is(h4,h5,h6){font-size:16px;line-height:1.5;margin:20px 0 6px}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) :is(h1,h2,h3,h4,h5,h6)+:is(h2,h3,h4,h5,h6){margin-top:14px}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) p{margin:0 0 14px}:is(.document-content,.portable-editor .tiptap,.portable-content) mark:not(:where(.sb-block *,.showai-custom-block *)),.sb-text .sb-rich-text mark{--showai-highlight-start: 43%;color:inherit;background:linear-gradient(transparent var(--showai-highlight-start),var(--showai-highlight-color, var(--reading-highlight)) var(--showai-highlight-start));box-decoration-break:clone;-webkit-box-decoration-break:clone;padding:0 1px;border-radius:0}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) mark[data-highlight-mode=full]{--showai-highlight-start: 0%}:is(.document-content,.portable-editor .tiptap,.portable-content) strong:not(:where(.sb-block *,.showai-custom-block *)),.sb-text .sb-rich-text strong{font-weight:600}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) mark{background-color:transparent!important}:root[data-theme=dark] :is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) mark{background-image:linear-gradient(transparent var(--showai-highlight-start, 43%),color-mix(in srgb,var(--showai-highlight-color, var(--reading-highlight)) 22%,transparent) var(--showai-highlight-start, 43%))}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) em{color:var(--reading-accent);font-style:normal;font-weight:550}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) a{color:var(--reading-accent);text-decoration:underline;text-underline-offset:4px;text-decoration-thickness:1px}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) blockquote{border-left:3px solid color-mix(in srgb,var(--reading-accent) 45%,transparent);background:none;color:var(--reading-text);padding:2px 0 2px 16px;margin:18px 0;border-radius:0}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) blockquote p{margin:0 0 8px}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) :is(ul,ol){padding-left:1.5em;margin:0 0 14px}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) li{margin:4px 0;padding-left:.2em}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) li>p{margin:0}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) li>:is(ul,ol){margin:4px 0 0}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) ol{font-variant-numeric:tabular-nums}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) :is(ul[data-type=taskList],.portable-task-list){list-style:none;padding-left:0}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) :is(ul[data-type=taskList],.portable-task-list)>li{display:flex;align-items:flex-start;gap:10px;padding-left:0}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) :is(ul[data-type=taskList],.portable-task-list)>li>label{flex:0 0 auto;display:inline-flex;align-items:center;height:1.8em}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) :is(ul[data-type=taskList],.portable-task-list) input[type=checkbox]{appearance:none;-webkit-appearance:none;flex:0 0 auto;width:15px;height:15px;margin:0;border:1.5px solid color-mix(in srgb,var(--reading-text) 40%,transparent);border-radius:4px;background:transparent;cursor:pointer;--task-tick: #ffffff}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) :is(ul[data-type=taskList],.portable-task-list) input[type=checkbox]:checked{border-color:var(--reading-accent);background-color:var(--reading-accent)}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) :is(ul[data-type=taskList],.portable-task-list) input[type=checkbox]:checked:before{content:"";display:block;width:4px;height:8px;margin:1px 0 0 4px;border:solid var(--task-tick);border-width:0 2px 2px 0;transform:rotate(45deg)}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) :is(ul[data-type=taskList],.portable-task-list) input[type=checkbox]:disabled{cursor:default}:root[data-theme=dark] :is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) :is(ul[data-type=taskList],.portable-task-list) input[type=checkbox]:checked{--task-tick: #201c2e}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) :is(ul[data-type=taskList],.portable-task-list) input[type=checkbox]:focus-visible{outline:2px solid var(--reading-accent);outline-offset:2px}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) .portable-task-list>li>input[type=checkbox]{margin-top:calc(.9em - 7.5px)}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) :is(ul[data-type=taskList],.portable-task-list)>li>div{flex:1;min-width:0}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) :is(ul[data-type=taskList],.portable-task-list)>li>div>p{margin:0}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) :is(ul[data-type=taskList],.portable-task-list)>li[data-checked=true]>div>p{color:var(--muted);text-decoration:line-through}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) li::marker{color:var(--reading-accent)}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) code{font-family:var(--font-mono);font-size:.875em;color:var(--reading-accent);background:var(--reading-code);border-radius:4px;padding:.1em .35em}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) pre,.sb-code pre{border:1px solid var(--line);border-radius:10px;background:var(--surface);color:var(--reading-text);padding:16px 20px;margin:18px 0;font:13.5px/1.7 var(--font-mono);white-space:pre;tab-size:2;overflow-x:auto}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) pre code{font:inherit;color:inherit;background:transparent;padding:0;border-radius:0}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) hr{border:0;border-top:1px solid var(--line);margin:28px 0}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text)>:first-child{margin-top:0}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text)>:last-child{margin-bottom:0}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) :is(blockquote,li,th,td,.callout-content>div,.toggle-body>div>div,.portable-callout>div,.portable-toggle-body)>:last-child{margin-bottom:0}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) :is(blockquote,li,th,td,.callout-content>div,.toggle-body>div>div,.portable-callout>div,.portable-toggle-body)>:first-child{margin-top:0}.document-content .document-image,.portable-editor .document-image,.portable-image,.sb-rich-text img,.sb-image img{border-radius:14px}:is(.document-content,.portable-editor .tiptap,.portable-content) :is(.tableWrapper,.portable-table-scroll):not(.sb-block *){overflow-x:auto;margin:18px 0}:is(.document-content,.portable-editor .tiptap,.portable-content) table:not(.sb-block table),.sb-rich-text table{border-collapse:collapse;width:100%;font-size:15px;line-height:1.6}:is(.document-content,.portable-editor .tiptap,.portable-content) :is(th,td):not(.sb-block :is(th,td)),.sb-rich-text :is(th,td){padding:8px 12px;border:1px solid var(--line);vertical-align:top;text-align:start}:is(.document-content,.portable-editor .tiptap,.portable-content) th:not(.sb-block th),.sb-rich-text th{background:var(--surface);color:var(--reading-heading);font-weight:600}:is(.document-content,.portable-editor .tiptap,.portable-content) :is(th,td):not(.sb-block :is(th,td))>p,.sb-rich-text :is(th,td)>p{margin:0}:is(.document-content,.portable-editor .tiptap,.portable-content) :is(th,td):not(.sb-block :is(th,td))>p+p,.sb-rich-text :is(th,td)>p+p{margin-top:6px}.sb-table table{font-size:inherit;line-height:inherit}.sb-table :is(th,td){padding:12px 16px;border-color:var(--line)}.sb-table th{background:var(--surface);font-weight:600}.sb-primitive{font-family:var(--font-sans)}.sb-image figcaption,.sb-primitive-editor{color:var(--muted);font-size:13px;line-height:1.5}.sb-image-empty{border-radius:14px;background:var(--surface);color:var(--muted)}.sb-primitive-editor :is(input,textarea){border:1px solid var(--line);border-radius:8px;padding:12px;background:var(--paper);color:var(--text)}.sb-code textarea{font-family:var(--font-mono);background:var(--paper);color:var(--text);border:1px solid var(--line);border-radius:8px;padding:12px}.sb-block{font-family:var(--font-sans);font-size:14px;font-weight:500;line-height:1.6;border-radius:16px}.sb-header{padding:20px 24px 16px}.sb-title{font-size:16px;font-weight:600}.sb-description{font-size:14px;line-height:1.6}.sb-block :is(.sb-button,.sb-icon-button){border-radius:8px}.sb-block .sb-button{min-height:36px;font-size:14px}.sb-metric-value{font-weight:700;letter-spacing:-.02em}.sb-bookmark-copy>strong{font-size:16px;line-height:1.4;font-weight:600}.sb-bookmark-copy>p{font-size:14px;line-height:1.6}.portable-document{max-width:1000px;padding:80px 64px 96px}.portable-title{font-size:32px;font-weight:700;letter-spacing:-.02em;line-height:1.25;margin-bottom:32px}.portable-options-trigger{border-radius:50%;width:40px;height:40px}.portable-options-menu{border-radius:16px;box-shadow:var(--shadow);padding:8px}.portable-options-menu button{border-radius:8px;min-height:40px;font-size:14px}.portable-toggle summary{font-weight:600}@media(max-width:700px){.portable-document{padding:76px 24px 64px}.portable-title{font-size:28px}.sb-header{padding:16px}:is(.document-content,.portable-editor .tiptap,.portable-content,.sb-rich-text) pre,.sb-code pre{padding:16px}}@media print{.portable-document{max-width:none;padding:0}.sb-block{--sb-accent: #222222}}.document-content .page-document-flow>:first-child:not(.document-content :not(:first-child) *){margin-top:0}.document-content .page-document-flow>:last-child:not(.document-content :not(:last-child) *){margin-bottom:0}
51
51
  `);var pt=U(pe(),1),zl=vt(mc);function uz(e){let{code:t,params:a}=e??{},n=a?.component??"";return t==="INTEGRITY_UNAVAILABLE"?zl("integrityUnavailable"):t==="COMPONENT_FETCH_FAILED"?zl("componentFetchFailed",{component:n,reason:a?.reason||zl("networkFailed")}):t==="COMPONENT_CHECKSUM_FAILED"?zl("componentChecksumFailed",{component:n}):e instanceof Error?e.message:zl("remoteLoadFailed")}function pz(e,t,a,n,o){let r=URL.createObjectURL(new Blob([Rh(e,t,a,n,o)],{type:"application/json"})),i=window.document.createElement("a");i.href=r,i.download=`${e.title.replace(/[^\p{L}\p{N} _-]/gu,"").trim()||"page"}.showai.json`,i.click(),setTimeout(()=>URL.revokeObjectURL(r),1e3)}function mz({artifact:e,host:t}){let{inlineHost:a}=t,n=ue(mc),o=ue(Xa),{document:r}=e,i=(0,ra.useMemo)(()=>{let E=t.readOptions();return E?JSON.parse(E).draft===!0:!1},[t]),[l,s]=(0,ra.useState)(()=>{let E=t.readOptions();return E?JSON.parse(E).theme==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}),[c,d]=(0,ra.useState)(!1),u=(0,ra.useRef)(null),p=(0,ra.useRef)(null),g=(0,ra.useMemo)(()=>Xx(t.readOptions()),[t]),y=Qx(p,r,g),b=(0,ra.useRef)(null),[x,f]=(0,ra.useState)([]),[m,v]=(0,ra.useState)(""),[T,w]=(0,ra.useState)(!!e.remoteComponents?.length);return(0,ra.useEffect)(()=>{if(!e.remoteComponents?.length)return;if(a){v(n("remoteInlineBlocked")),w(!1);return}let E=new AbortController,L=!0;return w(!0),Ah(e.remoteComponents,{signal:E.signal}).then(H=>{L&&(f(H),v(""))}).catch(H=>{L&&v(uz(H))}).finally(()=>{L&&w(!1)}),()=>{L=!1,E.abort()}},[e.remoteComponents]),(0,ra.useEffect)(()=>{t.setTheme(l?"dark":"light")},[l,t]),(0,ra.useEffect)(()=>{if(!c)return;let E=H=>{u.current?.contains(H.target)||d(!1)},L=H=>{H.key==="Escape"&&(d(!1),b.current?.focus())};return window.document.addEventListener("pointerdown",E),window.document.addEventListener("keydown",L),()=>{window.document.removeEventListener("pointerdown",E),window.document.removeEventListener("keydown",L)}},[c]),(0,pt.jsxs)("div",{ref:p,className:`portable-app${e.selection?" portable-partial":""}`,children:[i&&(0,pt.jsx)("div",{className:"portable-draft-note",role:"status",children:n("draftNote")}),(0,pt.jsxs)("div",{className:"portable-options",ref:u,children:[(0,pt.jsx)("button",{ref:b,className:"portable-options-trigger","aria-label":o("pageOptions"),"aria-expanded":c,"aria-controls":"page-options",onClick:()=>d(!c),children:(0,pt.jsx)(e0,{size:19})}),c&&(0,pt.jsxs)("div",{className:"portable-options-menu",id:"page-options",children:[(0,pt.jsxs)("button",{onClick:()=>{pz(r,e.components,e.remoteComponents,e.presentation,e.selection),d(!1)},children:[(0,pt.jsx)(Ur,{size:15})," ",i?n("downloadOriginalSource"):o("downloadSource")]}),(0,pt.jsxs)("button",{onClick:()=>{s(!l),d(!1)},children:[l?(0,pt.jsx)(qf,{size:15}):(0,pt.jsx)(Lf,{size:15}),o(l?"lightAppearance":"darkAppearance")]}),(0,pt.jsxs)("button",{onClick:()=>{d(!1),window.print()},children:[(0,pt.jsx)(Hf,{size:15})," ",o("print")]})]})]}),y.contextMenu,y.status,(0,pt.jsx)(Fm,{components:[...e.components??[],...x],inlineHost:a,children:(0,pt.jsx)(qx,{document:r,presentation:e.presentation,partial:!!e.selection,heading:(0,pt.jsxs)(pt.Fragment,{children:[!a&&!e.selection&&(r.icon||r.title)&&(0,pt.jsxs)("div",{className:"portable-page-heading",children:[r.icon&&(0,pt.jsx)("div",{className:"portable-page-icon",children:(0,pt.jsx)(Kn,{value:r.icon,size:48})}),r.title&&(0,pt.jsx)("h1",{className:"portable-title",children:r.title})]}),!!e.remoteComponents?.length&&(0,pt.jsx)("p",{className:"portable-network-note",children:n(T?"remoteLoading":"remoteRequired")}),m&&(0,pt.jsx)("p",{role:"alert",className:"portable-network-error",children:m})]})})})]})}function fz({host:e}){let t=ue(mc);(0,ra.useLayoutEffect)(()=>Kl(window.document),[]);let a=(0,ra.useMemo)(()=>{let n=e.readArtifact();if(!n||n.trim()==="null")return{error:zl("emptyPage")};try{return{artifact:Lh(n)}}catch(o){return{error:o instanceof Error?o.message:zl("unreadablePage")}}},[e]);return a.artifact?(0,pt.jsx)(mz,{artifact:a.artifact,host:e}):(0,pt.jsxs)("main",{className:"portable-error",children:[(0,pt.jsx)("h1",{children:t("openFailed")}),(0,pt.jsx)("p",{children:a.error})]})}function tw(e,t){x6(v6(t.inlineHost?.lang||window.document.documentElement.lang||navigator.language));let a=(0,ew.createRoot)(e);return a.render((0,pt.jsx)(ra.StrictMode,{children:(0,pt.jsx)(fz,{host:t})})),()=>a.unmount()}var gz=0;function P_(e,{artifact:t,options:a,standalone:n=!1}){if(e.id||(e.id=`showai-cdn-${++gz}`),!/^[A-Za-z][\w-]*$/.test(e.id))throw new Error("The ShowAI root needs a simple id.");n||e.setAttribute("data-showai-inline-root",""),e.querySelectorAll(":scope > [data-showai-placeholder]").forEach(c=>c.remove());let o=e.ownerDocument.createElement("div");o.id=`${e.id}-root`,e.append(o);let r=rf(e,{scoped:!n}),i=typeof t=="string"?t:JSON.stringify(t),l=a?JSON.stringify(a):null,s=tw(o,{inlineHost:n?null:e,readArtifact:()=>i,readOptions:()=>l,setTheme:c=>{(n?e.ownerDocument.documentElement:e).dataset.theme=c}});return()=>{s(),r(),o.remove()}}export{P_ as mount};
52
- /*! For license information please see reader-7TTEBDMO.js.LEGAL.txt */
52
+ /*! For license information please see reader-BP6RG7SQ.js.LEGAL.txt */