wicked-studio 0.16.14 → 0.16.15

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.
@@ -1 +1 @@
1
- var wickedAppsStandalone=(function(he){"use strict";var on=Object.defineProperty;var sn=(he,ie,Re)=>ie in he?on(he,ie,{enumerable:!0,configurable:!0,writable:!0,value:Re}):he[ie]=Re;var Te=(he,ie,Re)=>sn(he,typeof ie!="symbol"?ie+"":ie,Re);const ie="wicked.editor";function $t(u,d,m){return{editor:u,version:d,protocol:[1,2],surfaces:m}}function Lt(u,d){const m=document.querySelector('meta[name="wicked-editor-version"]')?.getAttribute("content")??"0.0.0";parent.postMessage({p:ie,v:1,type:"plugin.ready",payload:$t(u,m,d)},"*")}const St=/^[A-Z]{3}$/u;function ye(u,d,m){if(u==null)return"";if(typeof u=="boolean")return u?"yes":"no";const y=typeof d?.decimals=="number"&&Number.isInteger(d.decimals)?Math.min(10,Math.max(0,d.decimals)):void 0,h=typeof u=="number"?u:typeof u=="string"&&u.trim()!==""&&Number.isFinite(Number(u))?Number(u):null;try{switch(d?.kind){case"currency":if(h===null||!St.test(d.currency))break;return new Intl.NumberFormat(m,{style:"currency",currency:d.currency,...y!==void 0?{minimumFractionDigits:y,maximumFractionDigits:y}:{}}).format(h);case"percent":if(h===null)break;return new Intl.NumberFormat(m,{style:"percent",maximumFractionDigits:y??1}).format(h);case"number":if(h===null)break;return new Intl.NumberFormat(m,y!==void 0?{minimumFractionDigits:y,maximumFractionDigits:y}:{}).format(h);case"date":case"datetime":{const N=new Date(typeof u=="number"?u:String(u));if(Number.isNaN(N.getTime()))break;return new Intl.DateTimeFormat(m,d.kind==="date"?{dateStyle:"medium",timeZone:"UTC"}:{dateStyle:"medium",timeStyle:"short"}).format(N)}case"duration":{if(h===null)break;const N=Math.abs(Math.round(h)),k=Math.floor(N/86400),M=Math.floor(N%86400/3600),Y=Math.floor(N%3600/60);return k>0?`${k}d ${M}h`:M>0?`${M}h ${Y}m`:`${Y}m`}default:break}}catch{}return typeof u=="number"?Number.isInteger(u)?String(u):new Intl.NumberFormat(m,{maximumFractionDigits:6}).format(u):String(u)}function F(u,d=200){return typeof u=="string"?u.replace(/[\u0000-\u001f\u007f]+/gu," ").slice(0,d):""}const Nt="http://www.w3.org/2000/svg";function ne(u,d,m){const y=document.createElementNS(Nt,u);for(const[h,N]of Object.entries(d))y.setAttribute(h,String(N));return m!==void 0&&y.setAttribute("class",m),y}function He(u,d,m,y,h="start"){const N=ne("text",{x:u,y:d,"text-anchor":h},y);return N.textContent=m,N}function xe(u){return typeof u=="number"?Number.isFinite(u)?u:0:typeof u=="string"&&u.trim()!==""&&Number.isFinite(Number(u))?Number(u):0}const W=u=>Math.round(u*10)/10;function Ve(u,d){const m=document.createElement("ul");m.className="wk-legend",d.forEach((y,h)=>{const N=document.createElement("li"),k=document.createElement("span");k.className=`wk-swatch wk-series-${h%12}`,N.append(k,document.createTextNode(y)),m.append(N)}),u.append(m)}function Pt(u,d,m,y){const h=g=>m.columns.findIndex(x=>x.name===g),N=h(d.x),k=d.series.slice(0,d.chart==="pie"?1:12).map(g=>({label:F(g.label??g.column,60),i:h(g.column)})).filter(g=>g.i>=0),M=m.rows.slice(0,500);if(N<0||k.length===0||M.length===0){const g=document.createElement("p");g.className="wk-empty",g.textContent=M.length===0?"No rows":"This chart’s columns are not in its query’s rows",u.append(g);return}const Y=M.map(g=>ye(g[N],void 0,y));if(d.chart==="bar"){const g=d.stacked===!0&&k.length>1,x=M.map(_=>k.map(P=>xe(_[P.i])));let L=0,E=0;for(const _ of x)if(g)E=Math.max(E,_.filter(P=>P>0).reduce((P,K)=>P+K,0)),L=Math.min(L,_.filter(P=>P<0).reduce((P,K)=>P+K,0));else for(const P of _)E=Math.max(E,P),L=Math.min(L,P);E===L&&(E=L+1);const O=130,S=k.length>1?250:220,$=_=>O+(_-L)/(E-L)*S,R=$(0),D=g||k.length===1?26:Math.max(26,k.length*10+10),A=ne("svg",{viewBox:`0 0 400 ${M.length*D+4}`,role:"img","aria-label":F(d.title??"bar chart",120)},"wk-chart wk-chart--bar");L<0&&A.append(ne("line",{x1:W(R),x2:W(R),y1:0,y2:M.length*D+4},"wk-grid-line")),M.forEach((_,P)=>{const K=P*D+2;if(A.append(He(0,W(K+D/2+4),Y[P].slice(0,22),"wk-axis")),g){let Se=0,ce=0;k.forEach((ue,we)=>{const oe=x[P][we],We=oe>=0?Se:ce+oe,Q=oe>=0?Se+oe:ce;oe>=0?Se+=oe:ce+=oe,A.append(ne("rect",{x:W($(We)),y:K+4,width:W(Math.max(1,$(Q)-$(We))),height:D-10},`wk-series-${we%12}`))});return}const de=(D-8)/k.length;k.forEach((Se,ce)=>{const ue=x[P][ce],we=Math.min($(ue),R),oe=Math.max(1,Math.abs($(ue)-R));A.append(ne("rect",{x:W(we),y:W(K+4+ce*de),width:W(oe),height:W(Math.max(2,de-2)),rx:2},`wk-series-${ce%12}`)),k.length===1&&A.append(He(W(ue<0?we-6:we+oe+6),W(K+D/2+4),ye(_[Se.i],void 0,y),"wk-value",ue<0?"end":"start"))})}),u.append(A),k.length>1&&Ve(u,k.map(_=>_.label));return}if(d.chart==="pie"){const g=k[0],x=M.reduce((O,S)=>O+Math.max(0,xe(S[g.i])),0)||1,L=ne("svg",{viewBox:"0 0 240 240",role:"img","aria-label":F(d.title??"pie chart",120)},"wk-chart wk-chart--pie");let E=-Math.PI/2;M.forEach((O,S)=>{const $=Math.max(0,xe(O[g.i]))/x,R=E+$*Math.PI*2,D=R-E>Math.PI?1:0,A=P=>`${W(120+100*Math.cos(P))} ${W(120+100*Math.sin(P))}`,_=$>=.9999?"M 120 20 A 100 100 0 1 1 119.9 20 Z":`M 120 120 L ${A(E)} A 100 100 0 ${D} 1 ${A(R)} Z`;L.append(ne("path",{d:_},`wk-series-${S%12}`)),E=R}),u.append(L),Ve(u,Y.slice(0,12));return}const Ee=600,ge=220,V=36,Me=24,ae=d.chart==="area"&&d.stacked===!0&&k.length>1,j=[],I=new Map;M.forEach((g,x)=>{if(j.push(x),!ae||x+1>=M.length)return;const L=new Map;k.forEach((E,O)=>{const S=xe(M[x][E.i]),$=xe(M[x+1][E.i]);if(S>0&&$<0||S<0&&$>0){const R=S/(S-$);L.set(R,[...L.get(R)??[],O])}});for(const E of[...L.keys()].sort((O,S)=>O-S))I.set(j.length,new Set(L.get(E))),j.push(x+E)});const Ae=(g,x)=>{if(I.get(x)?.has(g)===!0)return 0;const L=j[x],E=Math.floor(L),O=L-E,S=xe(M[E][k[g].i]);return O===0||E+1>=M.length?S:S+(xe(M[E+1][k[g].i])-S)*O},X=k.map(()=>[]),z=k.map(()=>[]);let G=0,me=1;const be=g=>{g<G&&(G=g),g>me&&(me=g)};j.forEach((g,x)=>{let L=0,E=0;k.forEach((O,S)=>{const $=Ae(S,x);if(!ae){X[S][x]=[0,$],z[S][x]=[0,0],be($);return}const R=Math.max(0,$),D=Math.min(0,$);X[S][x]=[L,L+R],z[S][x]=[E+D,E],L+=R,E+=D,be(L),be(E)})});const Oe=me,te=G,$e=g=>V+(M.length===1?0:g/(M.length-1)*(Ee-V-8)),Le=g=>ge-Me-(g-te)/(Oe-te||1)*(ge-Me-10),re=ne("svg",{viewBox:`0 0 ${Ee} ${ge}`,role:"img","aria-label":F(d.title??`${d.chart} chart`,120)},`wk-chart wk-chart--${d.chart}`);for(let g=0;g<=3;g+=1){const x=te+(Oe-te)*g/3;re.append(ne("line",{x1:V,x2:Ee-8,y1:W(Le(x)),y2:W(Le(x))},"wk-grid-line")),re.append(He(V-6,W(Le(x)+4),ye(Math.round(x*10)/10,void 0,y),"wk-axis","end"))}const Fe=M.length<=4?M.map((g,x)=>x):[0,Math.floor((M.length-1)/3),Math.floor((M.length-1)*2/3),M.length-1];for(const g of Fe)re.append(He(W($e(g)),ge-6,Y[g].slice(0,14),"wk-axis",g===0?"start":g===M.length-1?"end":"middle"));k.forEach((g,x)=>{const L=(D,A)=>`${W($e(j[D]))},${W(Le(A))}`;if(d.chart==="area"){const D=A=>{const _=j.map((K,de)=>L(de,A[de][1])),P=j.map((K,de)=>L(de,A[de][0])).reverse();return`M ${_.join(" L ")} L ${P.join(" L ")} Z`};re.append(ne("path",{d:D(X[x])},`wk-area wk-series-${x}`)),ae&&z[x].some(([A,_])=>A!==_)&&re.append(ne("path",{d:D(z[x])},`wk-area wk-area--neg wk-series-${x}`))}if(!ae){re.append(ne("polyline",{points:j.map((D,A)=>L(A,Ae(x,A))).join(" "),fill:"none"},`wk-stroke wk-series-${x}`));return}const E=[];let O=null,S=0,$=[];const R=(D,A)=>D<0?L(A,z[x][A][0]):L(A,X[x][A][1]);j.forEach((D,A)=>{const _=Ae(x,A);if(I.get(A)?.has(x)===!0||_===0){O!==null&&O.push(R(S,A)),$.push(A);return}const P=_>0?1:-1;if(O===null)O=$.map(K=>R(P,K)),E.push(O),S=P;else if(P!==S){const K=$[$.length-1];O=K!==void 0?[R(P,K)]:[],E.push(O),S=P}O.push(R(P,A)),$=[]}),O===null&&$.length>1&&E.push($.map(D=>R(1,D)));for(const D of E)D.length>1&&re.append(ne("polyline",{points:D.join(" "),fill:"none"},`wk-stroke wk-series-${x}`))}),u.append(re),k.length>1&&Ve(u,k.map(g=>g.label))}const qt=/^#[0-9a-fA-F]{6}$/u,it=/^(?::root|\.wk-c\d{1,4}(?: \.wk-[a-z]+)?)$/u,Ot=/^(?:--[a-z0-9-]{1,40}|[a-z-]{1,40})$/u,Dt="(max-width: 639px)";function je(u){return typeof u=="string"&&qt.test(u)?u.toLowerCase():null}function qe(u,d,m,y){return Number.isInteger(u)?Math.min(m,Math.max(d,u)):y}function Ct(u){return typeof u=="string"&&u.length<=200&&!/url\(|[;{}]|\/\*|\\/iu.test(u)?u:null}class Tt{constructor(d){Te(this,"sheet");Te(this,"base");Te(this,"rules",new Map);Te(this,"phone",null);Te(this,"phoneRules",new Map);if(d.sheet===null)throw new Error("the runtime stylesheet did not load");this.sheet=d.sheet,this.base=this.sheet.cssRules.length}reset(){for(;this.sheet.cssRules.length>this.base;)this.sheet.deleteRule(this.sheet.cssRules.length-1);this.rules.clear(),this.phoneRules.clear(),this.phone=null}rule(d){if(!it.test(d))throw new Error("a selector outside the runtime’s vocabulary");const m=this.rules.get(d);if(m!==void 0)return m;const y=this.sheet.insertRule(`${d} {}`,this.sheet.cssRules.length),h=this.sheet.cssRules[y];return this.rules.set(d,h),h}phoneRule(d){if(!it.test(d))throw new Error("a selector outside the runtime’s vocabulary");const m=this.phoneRules.get(d);if(m!==void 0)return m;if(this.phone===null){const N=this.sheet.insertRule(`@media ${Dt} {}`,this.sheet.cssRules.length);this.phone=this.sheet.cssRules[N]}const y=this.phone.insertRule(`${d} {}`,this.phone.cssRules.length),h=this.phone.cssRules[y];return this.phoneRules.set(d,h),h}set(d,m,y){Ot.test(m)&&d.style.setProperty(m,y)}theme(d,m){const y=this.rule(":root");for(const[k,M]of Object.entries(d)){const Y=Ct(M);/^--[a-z0-9-]{1,40}$/u.test(k)&&Y!==null&&this.set(y,k,Y)}const h=je(m.accent);h!==null&&this.set(y,"--app-accent",h),m.density==="compact"&&(this.set(y,"--row","36px"),this.set(y,"--gap","8px"));const N=Array.isArray(m.palette)?m.palette:[];for(let k=0;k<12;k+=1){const M=je(N[k]);M!==null&&this.set(y,`--s${k}`,M)}}place(d,m){const y=this.rule(`.wk-c${d}`),h=qe(m.x,0,11,0),N=qe(m.w,1,12-h,1),k=qe(m.y,0,999,0),M=qe(m.h,1,50,1);this.set(y,"grid-column",`${h+1} / span ${N}`),this.set(y,"grid-row",`${k+1} / span ${M}`)}phoneOrder(d,m,y){const h=this.phoneRule(`.wk-c${d}`);this.set(h,"order",String(qe(m,0,9999,0))),y?this.set(h,"display","none"):h.style.removeProperty("display")}seriesColour(d,m,y){const h=je(y);h!==null&&this.set(this.rule(`.wk-c${d}`),`--c${qe(m,0,11,0)}`,h)}}const Rt={comfortable:44,compact:36},at={comfortable:12,compact:8},It=450,rt=500,Ft=/^[A-Za-z_][A-Za-z0-9_]{0,63}$/u,Ie=()=>Object.create(null);function zt(u,d){if(u===void 0||d===null||d===void 0)return d;if((u.type==="number"||u.type==="integer")&&typeof d=="string"&&d.trim()!==""){const m=Number(d);return Number.isFinite(m)&&(u.type==="number"||Number.isInteger(m))?m:d}return u.type==="boolean"&&typeof d=="string"&&(d==="true"||d==="false")?d==="true":u.type==="string"&&(typeof d=="number"||typeof d=="boolean")?String(d):d}const ee=u=>typeof u=="object"&&u!==null&&!Array.isArray(u),_t=/^data:image\/(?:png|jpeg|gif|webp);base64,[A-Za-z0-9+/]+={0,2}$/u,lt={table:{w:12,h:5},chart:{w:6,h:5},kpi:{w:3,h:2},text:{w:6,h:1},filter:{w:3,h:1},form:{w:4,h:6},button:{w:2,h:1},image:{w:3,h:3},link:{w:2,h:1}},Bt=[{type:"table",label:"Table"},{type:"chart",label:"Chart"},{type:"kpi",label:"KPI"},{type:"filter",label:"Filter"},{type:"form",label:"Form"},{type:"button",label:"Button"},{type:"text",label:"Text"},{type:"link",label:"Link"}];function p(u,d,m){const y=document.createElement(u);return d!==void 0&&(y.className=d),m!==void 0&&(y.textContent=m),y}function pt(u){return u.toISOString().slice(0,10)}function Ht(u,d){Wt({editor:"wicked-apps",surfaces:{}},{port:u,hello:d})}function Wt(u,d){const m=document.getElementById("wk-apps-sheet")??(d===void 0?null:document.querySelector('link[rel="stylesheet"], style'));if(!(m instanceof HTMLStyleElement)&&!(m instanceof HTMLLinkElement))return;const y=new Tt(m),h=p("div","wk-app");h.setAttribute("data-testid","apps-runtime"),document.body.append(h);let N=null,k=new Set,M=!0,Y=!1,Ee=!1,ge=!1,V="preview",Me="full",ae="en",j=0,I=null,Ae=!1,X=null,z=null;const G=Ie(),me=new Map,be=Ie(),Oe=Ie(),te=new Map,$e=new Map,Le=new Map,re=new Map,Fe=new Map;let g=0,x=0;const L=new Map;let E=null;const O=new Map;let S=!1,$=null,R=null;const D=e=>{N?.postMessage({p:ie,v:1,...e})},A=(e,t)=>{x+=1;const n=`a${x}`;return D({type:e,id:n,payload:t}),new Promise(i=>L.set(n,i))},_=(e,t)=>D({type:e,payload:t}),P=e=>{const t=e.data;if(!ee(t)||t.p!==ie||t.v!==1)return;const n=ee(t.payload)?t.payload:{};if(typeof t.re=="string"){const i=L.get(t.re);if(i===void 0)return;L.delete(t.re);const s=ee(t.error)?t.error:{};i(t.ok===!0?{ok:!0,payload:n}:{ok:!1,code:String(s.code??"unavailable"),message:F(s.message,300),payload:n});return}if(!S)switch(t.type){case"host.ping":typeof t.id=="string"&&D({re:t.id,ok:!0,payload:{}});return;case"host.theme":ee(n.theme)&&(K=n.theme),U();return;case"artifact.changed":ue();return;case"app.mode":(n.mode==="edit"||n.mode==="preview")&&(V=n.mode,V==="preview"&&(z=null),U());return;case"data.invalidate":Ne();return;case"host.surface":(n.surface==="card"||n.surface==="full")&&(Me=n.surface,U());return;case"selection.cleared":z=null,U();return;case"host.teardown":S=!0;for(const i of O.values())clearInterval(i);O.clear(),document.removeEventListener("keydown",Mt),N?.close(),N=null,h.replaceChildren(p("p","wk-empty","Closed"));return;default:return}};let K={};const de=e=>{ee(e)&&(K=e),y.theme(K,{accent:I?.theme?.accent,palette:I?.theme?.palette,density:I?.theme?.density})},Se=()=>I?.theme?.density==="compact"?"compact":"comfortable",ce=(e,t)=>{N=e,N.onmessage=P,k=new Set(Array.isArray(t.grants)?t.grants.filter(s=>typeof s=="string"):[]);const n=ee(t.app)?t.app:{};if(M=n.framed!==!1,Y=n.tile===!0,Ee=Y&&n.rows===!0,ge=n.propsHost===!0,V=n.mode==="edit"?"edit":"preview",Me=t.surface==="card"||t.size==="inline"?"card":"full",ee(n.url))for(const[s,l]of Object.entries(n.url).slice(0,30))Ft.test(s)&&typeof l=="string"&&l.length<=1e3&&(Oe[s]=l);const i=ee(t.prefs)?t.prefs:{};ae=typeof i.locale=="string"&&/^[A-Za-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/u.test(i.locale)?i.locale:"en",de(t.theme),ue()};d===void 0&&window.addEventListener("message",e=>{const t=e.data;N!==null||e.source!==parent||!ee(t)||t.p!==ie||t.type!=="host.hello"||e.ports[0]===void 0||ce(e.ports[0],ee(t.payload)?t.payload:{})});const ue=async()=>{const e=await A("artifact.read",{});if(!e.ok){E=e.message,U();return}const t=ee(e.payload.content)?e.payload.content:{};if(t.type!=="app"||!ee(t.spec)){E="This is not an app",U();return}const n=j;j=typeof e.payload.version=="number"?e.payload.version:0,I=t.spec,Ae=t.readonly===!0,(X===null||!I.pages.some(s=>s.id===X))&&(X=I.pages[0]?.id??null),z!==null&&!Q().some(s=>s.id===z)&&(z=null),E=null,Ge();const i=we();U(),(n!==j||i||te.size===0)&&Ne()},we=()=>{const e=new Map;for(const n of I?.pages??[])for(const i of n.components){const s=Je(i);s!==null&&e.set(i.id,oe(s))}let t=!1;for(const n of[...te.keys()])$e.get(n)!==e.get(n)&&(te.delete(n),$e.delete(n),t=!0);return t},oe=e=>`${e.query}\0${JSON.stringify(e.params)}`,We=()=>I?.pages.find(e=>e.id===X)??null,Q=()=>We()?.components??[],Kt=(e,t)=>{const n=G[e];if(n!==void 0)return typeof n=="string"?t===void 0?n:void 0:t==="from"?n.from:t==="to"?n.to:void 0},Ke=(e,t,n)=>{const i={},s=n?.properties??{};for(const[l,a]of Object.entries(e??{})){const[r,o,f]=a.split(".");let v;if(r==="filter"&&o!==void 0)v=Kt(o,f);else if(r==="row"&&o!==void 0&&t.row!==void 0&&Object.hasOwn(t.row,o))v=t.row[o];else if(r==="form"&&o!==void 0&&t.form!==void 0){const b=be[t.form];v=b!==void 0&&Object.hasOwn(b,o)?b[o]:void 0}else r==="url"&&o!==void 0&&(v=Oe[o]);v!==void 0&&v!==""&&(i[l]=zt(Object.hasOwn(s,l)?s[l]:void 0,v))}return i},Ge=()=>{for(const e of I?.pages??[])for(const t of e.components)if(!(t.type!=="filter"||G[t.id]!==void 0))if(t.filter==="date-range"){const n=ee(t.default)&&Number.isInteger(t.default.lastDays)?Math.min(3650,Math.max(1,t.default.lastDays)):30,i=new Date;G[t.id]={from:pt(new Date(i.getTime()-n*864e5)),to:pt(i)}}else G[t.id]=typeof t.default=="string"?t.default:""},dt=e=>I?.queries.find(t=>t.id===e)?.params,Je=e=>e.type==="table"||e.type==="chart"||e.type==="kpi"?{query:e.data.query,params:Ke(e.data.params,{},dt(e.data.query))}:e.type==="filter"&&e.filter==="select"&&e.options?.kind==="query"?{query:e.options.query.query,params:Ke(e.options.query.params,{},dt(e.options.query.query))}:null,Ne=(e,t=!1)=>{if(S||!k.has("data.read")||I===null||Y&&!Ee)return;Ge(),g+=1;const n=g,i=new Map;for(const s of Q()){const l=Je(s);if(l===null||e!==void 0&&l.query!==e||t&&te.has(s.id))continue;const a=oe(l);let r=i.get(a);r===void 0&&(r=A("data.query",{query:l.query,params:l.params}).then(o=>{if(!o.ok)return{state:"error",message:o.message};const f=Array.isArray(o.payload.columns)?o.payload.columns:[],v=Array.isArray(o.payload.rows)?o.payload.rows.filter(Array.isArray):[];return{state:"rows",rows:{columns:f,rows:v,sample:o.payload.sample===!0,hasMore:o.payload.hasMore===!0,truncated:o.payload.truncated===!0}}}),i.set(a,r)),te.has(s.id)||(te.set(s.id,{state:"loading"}),$e.set(s.id,a)),Le.set(s.id,n),r.then(o=>{!S&&Le.get(s.id)===n&&(te.set(s.id,o),$e.set(s.id,a),ze(s.id))})}e===void 0&&Zt()},Zt=()=>{const e=new Map;for(const t of Q()){const n=Je(t),i=n===null?void 0:I?.queries.find(s=>s.id===n.query);i?.refresh?.mode==="every"&&e.set(i.id,Math.max(15,i.refresh.seconds))}for(const[t,n]of[...O]){const[i,s]=t.split("\0");e.get(i)!==Number(s)&&(clearInterval(n),O.delete(t))}for(const[t,n]of e){const i=`${t}\0${n}`;O.has(i)||O.set(i,setInterval(()=>{document.visibilityState==="visible"&&Ne(t)},n*1e3))}},Xt=async(e,t,n)=>{if(M||V!=="preview"||!k.has("data.write"))return;const i=Q().find(o=>o.id===e)?.type!=="button",s=o=>{i?(re.set(e,o),ze(e)):ft(`${F(t.label,60)}: ${o}`)};s("Waiting for you in studio…");const l=await A("data.action",{action:t.action,params:Ke(t.params,n,I?.actions.find(o=>o.id===t.action)?.params)}),a=l.ok?String(l.payload.state):"refused",r=l.ok?F(l.payload.reason,200):l.message;s(a==="succeeded"?`Done${r!==""?`: ${r}`:""}`:a==="cancelled"?"Not run":a==="unknown"?`Not known whether it ran: ${r}`:`Not run: ${r}`)},Qe=(e,t,n,i="wk-btn wk-btn--sm")=>{if(M)return p("span","wk-muted","Open to make changes");const s=p("button",i,F(t.label,60));return s.type="button",s.setAttribute("data-action",t.action),Y||V!=="preview"||!k.has("data.write")?(s.setAttribute("aria-disabled","true"),s.title=Y?"":V==="edit"?"Actions run in Preview":"This app may not ask to run actions here"):s.addEventListener("click",l=>{l.stopPropagation(),Xt(e,t,n)}),s},et=new Map;let se=null,tt=null;const nt=new Map,Ze=new WeakSet,ot=new WeakSet;let Xe=null;const Yt=()=>{const e=document.activeElement;if(!(e instanceof HTMLInputElement)||e.type!=="search"||e.closest(".wk-filter-options")===null)return null;const t=e.closest("[data-component]")?.getAttribute("data-component");return t==null?null:{id:t,el:e,range:[e.selectionStart,e.selectionEnd,e.selectionDirection]}},ct=e=>{if(e===null)return;const t=[...h.querySelectorAll("[data-component]")].find(n=>n.getAttribute("data-component")===e.id)?.querySelector('.wk-filter-options input[type="search"]');t==null||t===e.el||(t.focus({preventScroll:!0}),t.setSelectionRange(e.range[0],e.range[1],e.range[2]??void 0))},ut=(e,t)=>{const n=t.querySelector('.wk-filter-options input[type="search"]'),i=n!==null&&document.activeElement===n;if(i&&Ze.has(n)){ot.add(n);return}const s=i?[n.selectionStart,n.selectionEnd,n.selectionDirection]:null;if(i&&me.set(e.id,n.value),Vt(e,t),Ut(e,t),s!==null){const l=t.querySelector('.wk-filter-options input[type="search"]');l?.focus({preventScroll:!0}),l?.setSelectionRange(s[0],s[1],s[2]??void 0)}},Ut=(e,t)=>{if(!H())return;const n=(i,s)=>{i!==null&&(i.setAttribute("data-inline",s),i.classList.add("wk-editable"),i.setAttribute("title","Double-click to edit"))};e.type==="text"&&n(t.querySelector(".wk-text"),"text"),e.type==="button"&&n(t.querySelector("button[data-action]"),"label"),e.type==="link"&&n(t.querySelector(".wk-link"),"label"),e.type==="filter"&&n(t.querySelector(".wk-filter-label"),"label")},Vt=(e,t)=>{t.replaceChildren();const n=te.get(e.id);if(e.type==="table"||e.type==="chart"||e.type==="kpi"){if(Y&&!Ee){t.append(p("div",`wk-skeleton wk-skeleton--${e.type}`));return}if(!k.has("data.read")){t.append(p("p","wk-muted","Live rows are not shown here"));return}if(n===void 0||n.state==="loading"){t.append(p("p","wk-muted","Loading…"));return}if(n.state==="error"){t.append(p("p","wk-error",`${"data"in e?e.data.query:""}: ${n.message}`));return}}const s=n?.state==="rows"?n.rows:null;switch(e.type){case"kpi":{const l=o=>o===void 0?-1:s.columns.findIndex(f=>f.name===o),a=s.rows[0];t.append(p("div","wk-kpi-value",a===void 0?"—":ye(a[l(e.value)],e.format,ae)));const r=p("div","wk-kpi-caption");if(a!==void 0&&e.delta!==void 0&&l(e.delta)>=0){const o=a[l(e.delta)],f=typeof o=="number"&&o<0||typeof o=="string"&&o.trim().startsWith("-");r.append(p("span",f?"wk-delta wk-delta--down":"wk-delta wk-delta--up",`${f?"▼":"▲"} ${ye(o,void 0,ae).replace(/^\s*-/u,"")}`)),r.append(document.createTextNode(" "))}e.caption!==void 0&&r.append(document.createTextNode(F(e.caption,120))),t.append(r);return}case"chart":Pt(t,e,s,ae),(s.truncated||s.rows.length>rt)&&t.append(p("p","wk-muted",s.truncated?"Only part of the source’s rows: the answer was cut at the app’s limit":`The first ${rt} of ${s.rows.length} rows`));return;case"table":{jt(e,t,s);return}case"text":t.append(p(e.style==="heading"?"h2":"p",`wk-text wk-text--${e.style??"body"}`,e.text.slice(0,4e3)));return;case"filter":{Gt(e,t);return}case"form":{Jt(e,t);return}case"button":t.append(Qe(e.id,e.action,{},"wk-btn"));return;case"image":{if(!_t.test(e.src)){t.append(p("p","wk-muted","This image is not one the app can show"));return}const l=p("img","wk-image");l.alt=F(e.alt,300),l.src=e.src,t.append(l);return}case"link":{const l=p("button","wk-link",F(e.label,120));if(l.type="button",e.to.kind==="page"){const a=e.to;l.addEventListener("click",()=>{if(V==="preview"){E=null;for(const[r,o]of Object.entries(Ke(a.params,{})))Oe[r]=String(o);I?.pages.some(r=>r.id===a.page)&&(X=a.page,z=null,U(),Ne())}})}else{const a=e.to.href;l.title=a.slice(0,300),l.addEventListener("click",async()=>{if(V!=="preview")return;const r=await A("link.open",{href:a});r.ok||ft(`${F(e.label,60)} not opened: ${r.message}`)})}t.append(l);return}}},jt=(e,t,n)=>{const i=c=>n.columns.findIndex(w=>w.name===c),s=(e.columns??n.columns.map(c=>({column:c.name}))).filter(c=>i(c.column)>=0),l=Math.min(500,Math.max(5,e.pageSize??10)),a=Math.max(1,Math.ceil(n.rows.length/l)),r=Math.min(Fe.get(e.id)??0,a-1),o=p("table","wk-table"),f=p("tr");for(const c of s)f.append(p("th",void 0,F(c.label??c.column,80)));(e.rowActions??[]).length>0&&f.append(p("th","wk-th-actions","")),o.append(p("thead")),o.tHead.append(f);const v=p("tbody");for(const c of n.rows.slice(r*l,r*l+l)){const w=p("tr"),C=Ie();n.columns.forEach((B,T)=>{C[B.name]=c[T]??null});for(const B of s){const T=c[i(B.column)],Z=ye(T,B.format,ae),fe=/^\S+$/u.test(Z),Ue=typeof T=="number"?"wk-num":fe?Z.length>64?"wk-token wk-token--long":"wk-token":"wk-prose",Ce=p("td",Ue,Z);fe&&Z.length>64&&(Ce.title=Z),w.append(Ce)}if((e.rowActions??[]).length>0){const B=p("td","wk-td-actions");for(const T of(e.rowActions??[]).slice(0,4))B.append(Qe(e.id,T,{row:C}));w.append(B)}v.append(w)}o.append(v);const b=p("div","wk-table-scroll");b.tabIndex=0,b.setAttribute("role","region"),b.setAttribute("aria-label",`${F(e.title??"Table",80)}, scrolls sideways`),b.append(o),t.append(b),n.rows.length===0&&t.append(p("p","wk-muted","No rows"));const q=p("div","wk-table-foot");if(a>1){const c=p("button","wk-btn wk-btn--sm","Previous"),w=p("button","wk-btn wk-btn--sm","Next");c.type="button",w.type="button",c.disabled=r===0,w.disabled=r>=a-1,c.addEventListener("click",()=>{Fe.set(e.id,r-1),ze(e.id)}),w.addEventListener("click",()=>{Fe.set(e.id,r+1),ze(e.id)}),q.append(c,p("span","wk-muted",`${r+1} of ${a}`),w)}n.truncated?q.append(p("span","wk-muted",`Only the first ${n.rows.length} rows: the answer was cut at the app’s limit`)):n.hasMore&&q.append(p("span","wk-muted","First page of the source’s rows"));const J=re.get(e.id);J!==void 0&&q.append(p("span","wk-status",J)),q.childNodes.length>0&&t.append(q)},Gt=(e,t)=>{const n=p("label","wk-filter"),i=F(e.label??(e.filter==="search"?"Search":e.filter==="date-range"?"Dates":"Filter"),60),s=p("span","wk-filter-label",i);s.title=i,n.append(s);const l=()=>{Ne()};if(e.filter==="search"){const a=p("input","wk-input");a.type="search",a.value=typeof G[e.id]=="string"?G[e.id]:"";let r=null;a.addEventListener("input",()=>{G[e.id]=a.value.slice(0,200),r!==null&&clearTimeout(r),r=setTimeout(l,300)}),n.append(a)}else if(e.filter==="select"){const a=p("select","wk-input"),r=[];let o=!1;if(e.options?.kind==="values")for(const w of e.options.values)r.push({value:F(w.value,200),label:F(w.label??w.value,200)});if(e.options?.kind==="query"){const w=te.get(e.id);if(w?.state==="rows"){o=w.rows.hasMore||w.rows.truncated;const C=w.rows.columns.findIndex(T=>T.name===e.options.value),B=w.rows.columns.findIndex(T=>T.name===(e.options.label??""));for(const T of w.rows.rows)C>=0&&r.push({value:ye(T[C],void 0,ae),label:ye(T[B>=0?B:C],void 0,ae)})}}const f=p("div","wk-filter-select"),v=p("div","wk-filter-options"),b=p("input","wk-input");b.type="search",b.placeholder="Search",b.setAttribute("aria-label",`Search ${F(e.label??"Filter",60)} options`),b.value=me.get(e.id)??"";const q=p("span","wk-muted");q.setAttribute("aria-live","polite");const J=r.length>200||o,c=()=>{const w=J?b.value.toLowerCase():"",C=r.filter(pe=>pe.label.toLowerCase().includes(w)),B=C.slice(0,200),T=typeof G[e.id]=="string"?G[e.id]:"",Z=T===""?void 0:r.find(pe=>pe.value===T);Z!==void 0&&!B.includes(Z)&&(B.length===200&&B.pop(),B.push(Z)),a.replaceChildren();for(const pe of[{value:"",label:"All"},...B]){const At=p("option",void 0,pe.label);At.value=pe.value,a.append(At)}const fe=B.filter(pe=>C.includes(pe)).length,Ue=w===""?`${fe} of ${r.length}${o?"+":""}`:`${fe}${fe<C.length?` of ${C.length}`:""} matches`,Ce=`Showing ${Ue}${w!==""&&o?" in fetched rows":""}`;if(q.textContent=Ue,q.title=Ce,q.setAttribute("aria-label",Ce),fe<C.length||o){const pe=p("option",void 0,`${Ce}: search to narrow`);pe.disabled=!0,pe.value="",a.append(pe)}a.value=T};b.addEventListener("input",()=>{me.set(e.id,b.value),c()}),b.addEventListener("compositionstart",()=>{Ze.add(b)}),b.addEventListener("compositionend",()=>{if(Ze.delete(b),me.set(e.id,b.value),Xe!==null){const w=Xe;Xe=null,ot.delete(b),U(w)}else ot.delete(b)&&ze(e.id)}),c(),a.addEventListener("change",()=>{G[e.id]=a.value,c(),l()}),n.append(a),f.append(n),J&&(f.classList.add("wk-filter-select--search"),v.append(b,q),f.append(v)),t.append(f);return}else{const a=G[e.id]??{from:"",to:""},r=p("input","wk-input wk-input--date"),o=p("input","wk-input wk-input--date");r.type="date",o.type="date",r.value=a.from,o.value=a.to;const f=()=>{G[e.id]={from:r.value,to:o.value},l()};r.addEventListener("change",f),o.addEventListener("change",f),n.append(r,p("span","wk-muted","–"),o)}t.append(n)},Jt=(e,t)=>{var r;const n=be[r=e.id]??(be[r]=Ie()),i=I?.actions.find(o=>o.id===e.submit.action)?.params?.properties??{};for(const o of e.fields){if(Object.hasOwn(n,o.name))continue;const f=e.submit.params===void 0?void 0:Object.entries(e.submit.params).find(([,b])=>b===`form.${o.name}`)?.[0],v=f!==void 0&&Object.hasOwn(i,f)?i[f].default:void 0;o.input==="checkbox"?n[o.name]=v===!0:v!==void 0&&(n[o.name]=String(v))}const s=p("div","wk-form");for(const o of e.fields.slice(0,30)){const f=p("label","wk-field");f.append(p("span","wk-filter-label",F(o.label??o.name,80)));let v;if(o.input==="textarea")v=p("textarea","wk-input");else if(o.input==="select"){v=p("select","wk-input");for(const b of o.options??[]){const q=p("option",void 0,F(b.label??b.value,200));q.value=F(b.value,200),v.append(q)}}else v=p("input","wk-input"),v.type=o.input==="number"?"number":o.input==="date"?"date":o.input==="checkbox"?"checkbox":"text";v instanceof HTMLInputElement&&v.type==="checkbox"?(v.checked=n[o.name]===!0,v.addEventListener("change",()=>{n[o.name]=v.checked})):(v.value=typeof n[o.name]=="string"?n[o.name]:"",v.addEventListener("input",()=>{n[o.name]=v.value.slice(0,1e3)})),v.disabled=V!=="preview",f.append(v),s.append(f)}const l=p("div","wk-form-foot");l.append(Qe(e.id,e.submit,{form:e.id},"wk-btn"));const a=re.get(e.id);l.append(p("span","wk-muted",a??(M?"":"Studio asks before it writes"))),s.append(l),t.append(s)};let ve=null;const ft=e=>{E=e,ve!==null?(ve.textContent=e,ve.hidden=!1):U()},ze=e=>{if($!==null&&$.id===e)return;const t=Q().find(i=>i.id===e),n=nt.get(e);t!==void 0&&n!==void 0&&ut(t,n)},H=()=>V==="edit"&&Me==="full"&&!Ae&&k.has("artifact.write");let ke=null;const ht=()=>{const e=ke.getBoundingClientRect(),t=Se();return{col:(e.width+at[t])/12,row:Rt[t]+at[t],left:e.left,top:e.top}},Qt=(e,t)=>{const n=ht();return{x:Math.min(11,Math.max(0,Math.floor((e-n.left)/n.col))),y:Math.min(999,Math.max(0,Math.floor((t-n.top)/n.row)))}},le=async(e,t={})=>{const n=await A("spec.edit",{base:j,ops:e});if(!n.ok)return E=n.code==="head_moved"?"The app changed meanwhile: showing the newest version":`Not changed: ${n.message}`,n.code==="head_moved"?await ue():U(),null;ee(n.payload.spec)&&(I=n.payload.spec),E=null,Ge(),we();const i=Array.isArray(n.payload.added)?n.payload.added.filter(s=>typeof s=="string"):[];return i[0]!==void 0&&De(i[0]),U({keepProps:t.typed===!0&&i.length===0}),Ne(void 0,!0),i},De=e=>{const t=z;z=e,e!==null&&k.has("selection.chip")?_("selection.set",{anchors:[{kind:"element",id:e}]}):e===null&&t!==null&&k.has("selection.chip")&&_("selection.set",{anchors:[]})},mt=(e,t,n,i)=>{if(!H()||e.button!==0)return;e.preventDefault(),e.stopPropagation(),(i.closest(".wk-cell")??i).focus({preventScroll:!0});const s=et.get(t.id),l=ht(),a={x:e.clientX,y:e.clientY};let r={...t.box},o=!1;const f=n==="move"?e.target?.closest?.("[data-inline]"):null;i.setPointerCapture(e.pointerId),i.classList.add("is-dragging");const v=q=>{const J=Math.round((q.clientX-a.x)/l.col),c=Math.round((q.clientY-a.y)/l.row);J===0&&c===0&&!o||(o=!0,r=n==="move"?{...t.box,x:Math.min(12-t.box.w,Math.max(0,t.box.x+J)),y:Math.max(0,t.box.y+c)}:{...t.box,w:Math.min(12-t.box.x,Math.max(1,t.box.w+J)),h:Math.min(50,Math.max(1,t.box.h+c))},y.place(s,r))},b=()=>{i.removeEventListener("pointermove",v),i.removeEventListener("pointerup",b),i.removeEventListener("pointercancel",b),i.classList.remove("is-dragging");const q=n==="move"?r.x!==t.box.x||r.y!==t.box.y:r.w!==t.box.w||r.h!==t.box.h;if(!o||!q){y.place(s,t.box),o||(De(t.id),vt(),kt(t.id,f));return}le([n==="move"?{op:"component-move",id:t.id,x:r.x,y:r.y}:{op:"component-resize",id:t.id,w:r.w,h:r.h}])};i.addEventListener("pointermove",v),i.addEventListener("pointerup",b),i.addEventListener("pointercancel",b)},wt=()=>Q().reduce((e,t)=>Math.max(e,t.box.y+t.box.h),0),en=(e,t,n)=>{if(!H()||e.button!==0||ke===null||X===null)return;e.preventDefault(),n.focus({preventScroll:!0});const i=lt[t],s=p("div","wk-drop wk-c9999");s.setAttribute("data-testid","apps-drop-target");let l=null;n.setPointerCapture(e.pointerId);const a=o=>{const f=ke.getBoundingClientRect();if(o.clientX<f.left||o.clientX>f.right||o.clientY<f.top){s.remove(),l=null;return}l=Qt(o.clientX,o.clientY),l.x=Math.min(l.x,12-i.w),y.place(9999,{x:l.x,y:l.y,w:i.w,h:i.h}),s.parentNode===null&&ke.append(s)},r=o=>{if(n.removeEventListener("pointermove",a),n.removeEventListener("pointerup",r),n.removeEventListener("pointercancel",r),s.remove(),Math.abs(o.clientX-e.clientX)+Math.abs(o.clientY-e.clientY)>6&&l===null)return;const v=l??{x:0,y:wt()};le([{op:"component-add",page:X,type:t,box:{x:v.x,y:v.y,w:Math.min(i.w,12-v.x),h:i.h}}])};n.addEventListener("pointermove",a),n.addEventListener("pointerup",r),n.addEventListener("pointercancel",r)},st=(e,t,n=!1,i)=>{let s=e.value,l=null;const a=()=>{if(e.value===s)return;s=e.value;const o=t();if(o===void 0)return;const f=Promise.resolve(o);l=f,f.finally(()=>{l===f&&(l=null)})};let r=!1;e.addEventListener("compositionstart",()=>{r=!0}),e.addEventListener("compositionend",()=>{r=!1,a()}),e.addEventListener("input",o=>{!r&&o.isComposing!==!0&&a()}),i!==void 0&&e.addEventListener("blur",()=>{const o=()=>{if(document.activeElement===e)return;const f=i();e.value!==f&&(e.value=f,s=f)};l!==null?l.then(o,o):o()}),e.addEventListener("change",()=>{r||a()}),e.addEventListener("keydown",o=>{const f=o;r||f.isComposing||f.keyCode===229||f.key==="Enter"&&(!n||f.metaKey||f.ctrlKey)&&(f.preventDefault(),a())})},_e=(e,t)=>{const n=p("label","wk-prop");return n.append(p("span","wk-prop-label",e),t),n},Pe=(e,t,n,i,s,l=!1)=>{const a=p(l?"textarea":"input","wk-input");return a.value=i??"",a.maxLength=s,a.setAttribute("data-prop",n),st(a,()=>le([{op:"component-set",id:e.id,prop:n,value:a.value}],{typed:!0}),l,()=>{const r=Q().find(f=>f.id===e.id),o=n==="label"&&r?.type==="button"?r.action?.label:r?.[n];return typeof o=="string"?o:""}),_e(t,a)},Be=(e,t,n,i,s,l="set")=>{const a=p("select","wk-input");for(const r of s){const o=p("option",void 0,r);o.value=r,a.append(o)}return a.value=i,a.setAttribute("data-prop",n),a.addEventListener("change",()=>{le([l==="bind"?{op:"bind",id:e.id,query:a.value}:{op:"component-set",id:e.id,prop:n,value:a.value}])}),_e(t,a)},yt=(e,t,n,i)=>{const s=p("input","wk-check");return s.type="checkbox",s.checked=i,s.setAttribute("data-prop",n),s.addEventListener("change",()=>{le([{op:"component-set",id:e.id,prop:n,value:s.checked}])}),_e(t,s)},Ye=(e,t,n,i,s)=>{const l=p("input","wk-input wk-input--num");l.type="number",l.min=String(i),l.max=String(s),l.value=String(n==="x"?e.box.x+1:n==="y"?e.box.y+1:e.box[n]),l.setAttribute("data-prop",`box-${n}`);const a=()=>Q().find(o=>o.id===e.id)?.box??e.box,r=o=>String(n==="x"?o.x+1:n==="y"?o.y+1:o[n]);return st(l,()=>{if(l.value.trim()==="")return;const o=Math.round(Number(l.value));if(!Number.isFinite(o))return;const f=a();if(n==="x"||n==="y"){const q=n==="x"?Math.min(12-f.w,Math.max(0,o-1)):f.x,J=n==="y"?Math.max(0,o-1):f.y;return le([{op:"component-move",id:e.id,x:q,y:J}],{typed:!0})}const v=n==="w"?Math.min(12-f.x,Math.max(1,o)):f.w,b=n==="h"?Math.min(50,Math.max(1,o)):f.h;return le([{op:"component-resize",id:e.id,w:v,h:b}],{typed:!0})},!1,()=>r(a())),_e(t,l)},gt=e=>{const t=p("aside","wk-props");t.setAttribute("aria-label","Properties"),t.setAttribute("data-testid","apps-properties"),t.append(p("h3","wk-props-title","Properties")),t.append(p("p","wk-muted",`${e.type==="chart"?`${e.chart} chart`:e.type} · ${e.id}`)),t.append(Pe(e,"Title","title",e.title,120));const n=(I?.queries??[]).map(a=>a.id),i=a=>I?.queries.find(r=>r.id===a)?.output.map(r=>r.name)??[];if((e.type==="table"||e.type==="chart"||e.type==="kpi")&&t.append(Be(e,"Data","query",e.data.query,n,"bind")),e.type==="table"){const a=p("input","wk-input wk-input--num");a.type="number",a.min="5",a.max="500",a.value=String(e.pageSize??10),a.setAttribute("data-prop","pageSize"),st(a,()=>{if(a.value.trim()==="")return;const r=Math.round(Number(a.value));return Number.isFinite(r)?le([{op:"component-set",id:e.id,prop:"pageSize",value:Math.min(500,Math.max(5,r))}],{typed:!0}):void 0},!1,()=>String(Q().find(r=>r.id===e.id)?.pageSize??10)),t.append(_e("Rows per page",a))}e.type==="chart"&&(t.append(Be(e,"Chart","chart",e.chart,["bar","line","area","pie"])),t.append(Be(e,"Category","x",e.x,i(e.data.query))),(e.chart==="bar"||e.chart==="area")&&t.append(yt(e,"Stacked","stacked",e.stacked===!0))),e.type==="kpi"&&(t.append(Be(e,"Figure","value",e.value,i(e.data.query))),t.append(Pe(e,"Caption","caption",e.caption,120))),e.type==="text"&&(t.append(Pe(e,"Text","text",e.text,4e3,!0)),t.append(Be(e,"Style","style",e.style??"body",["heading","body","caption"]))),e.type==="filter"&&t.append(Pe(e,"Label","label",e.label,120)),e.type==="button"&&t.append(Pe(e,"Label","label",e.action.label,60)),e.type==="link"&&t.append(Pe(e,"Label","label",e.label,120)),e.type==="image"&&t.append(Pe(e,"Description","alt",e.alt,300));const s=p("div","wk-prop-box");s.append(Ye(e,"Column","x",1,12),Ye(e,"Row","y",1,1e3),Ye(e,"Width","w",1,12),Ye(e,"Height","h",1,50)),t.append(s),t.append(yt(e,"Hide on phones","hideOnPhone",e.hideOnPhone===!0));const l=p("button","wk-btn wk-btn--danger","Delete this component");return l.type="button",l.setAttribute("data-testid","apps-remove"),l.addEventListener("click",()=>{const a=e.id;z=null,le([{op:"component-remove",id:a}])}),t.append(l),t},bt=()=>{const e=p("aside","wk-props wk-props--empty");return e.setAttribute("aria-label","Properties"),e.setAttribute("data-testid","apps-properties-empty"),e.append(p("h3","wk-props-title","Properties")),e.append(p("p","wk-muted","Select a component to change it here. Double-click its words to edit them in place.")),e},tn=()=>{const e=p("aside","wk-palette");e.setAttribute("aria-label","Components"),e.append(p("h3","wk-props-title","Components")),e.append(p("p","wk-muted","Drag onto the canvas, or click to add"));const t=p("div","wk-tiles");for(const n of Bt){const i=p("button","wk-tile",n.label);i.type="button",i.setAttribute("data-palette",n.type),i.addEventListener("pointerdown",s=>en(s,n.type,i)),i.addEventListener("click",s=>{if(s.detail!==0||!H()||X===null)return;const l=lt[n.type];le([{op:"component-add",page:X,type:n.type,box:{x:0,y:wt(),w:l.w,h:l.h}}])}),t.append(i)}return e.append(t),e},U=(e={})=>{const t=$;let n=!1;if(t!==null){const i=H()?Q().find(s=>s.id===t.id):void 0;if(n=i!==void 0&&xt(i,t.prop)===t.before,n&&t.composing()){t.defer();return}n?t.hold():t.drop()}nn(e),n&&t!==null&&$===t&&t.place()},nn=e=>{const t=h.querySelector(".wk-pages"),n=t?.scrollLeft??0,i=e.focusPage===!0||(t?.contains(document.activeElement)??!1),s=Yt();if(s!==null&&Ze.has(s.el)){Xe=e;return}s!==null&&me.set(s.id,s.el.value);const l=document.activeElement instanceof HTMLElement&&h.contains(document.activeElement)?document.activeElement.getAttribute("data-prop"):null;if(nt.clear(),et.clear(),y.reset(),de(void 0),h.setAttribute("data-mode",H()?"edit":"preview"),h.setAttribute("data-tile",Y?"true":"false"),h.setAttribute("data-surface",Me),I===null){h.replaceChildren(p("p","wk-empty",E??"Loading the app…")),se=null;return}const a=[];H()&&a.push(tn());const r=p("main","wk-main"),o=p("nav","wk-pages");o.setAttribute("aria-label","Pages");for(const c of I.pages){const w=p("button",c.id===X?"wk-page is-on":"wk-page",F(c.title,80));w.type="button",w.setAttribute("aria-current",c.id===X?"page":"false"),w.addEventListener("click",()=>{X!==c.id&&(X=c.id,De(null),U({focusPage:!0}),Ne())}),o.append(w)}r.append(o),ve=p("p","wk-notice",E??""),ve.setAttribute("data-testid","apps-notice"),ve.setAttribute("aria-live","polite"),ve.hidden=E===null,r.append(ve),Ae&&V==="edit"&&r.append(p("p","wk-notice","A chat turn is changing this app: it is read-only until the turn ends")),ke=p("div","wk-grid");const f=Q(),v=[...f].sort((c,w)=>c.box.y-w.box.y||c.box.x-w.box.x);f.forEach((c,w)=>{et.set(c.id,w),y.place(w,c.box),y.phoneOrder(w,v.indexOf(c),c.hideOnPhone===!0),c.type==="chart"&&c.series.slice(0,12).forEach((T,Z)=>y.seriesColour(w,Z,T.color));const C=p("section",`wk-cell wk-cell--${c.type} wk-c${w}${c.id===z&&H()?" is-selected":""}`);if(C.setAttribute("data-component",c.id),c.title!==void 0&&c.type!=="text"){const T=p("h3","wk-cell-title",F(c.title,120));H()&&(T.setAttribute("data-inline","title"),T.classList.add("wk-editable"),T.setAttribute("title","Double-click to edit")),C.append(T)}const B=p("div","wk-cell-body");if(nt.set(c.id,B),ut(c,B),C.append(B),H()){C.classList.add("is-editable"),C.tabIndex=0,C.setAttribute("aria-label",`${c.type==="chart"?`${c.chart} chart`:c.type} ${F(c.title??c.id,80)}: Enter to select`),C.append(p("span","wk-tag",`${c.type==="chart"?`${c.chart} chart`:c.type}${"data"in c&&c.data!==void 0?` · ${c.data.query}`:""}`));const T=p("span","wk-handle");T.setAttribute("aria-hidden","true"),T.addEventListener("pointerdown",Z=>mt(Z,c,"resize",T)),C.append(T),C.addEventListener("pointerdown",Z=>{Z.target.closest("input, select, textarea, button, .wk-handle")===null&&mt(Z,c,"move",C)}),C.addEventListener("pointerup",Z=>{const fe=Z.target.closest?.("button[data-inline]");fe!==null&&Z.button===0&&kt(c.id,fe)})}ke.append(C)}),f.length===0&&ke.append(p("p","wk-empty",H()?"Drag a component here from the palette":"This page is empty")),r.append(ke),a.push(r);const b=H()&&z!==null?f.find(c=>c.id===z):void 0,q=()=>{o.scrollLeft=n;const c=o.querySelector(".is-on");i&&c?.focus({preventScroll:!0}),c?.scrollIntoView?.({block:"nearest",inline:"nearest"})};if(e.keepProps===!0&&b!==void 0&&se!==null&&tt===b.id&&se.parentNode===h){for(const c of[...h.childNodes])c!==se&&c.remove();for(const c of a)h.insertBefore(c,se);q(),ct(s);return}se=ge?null:b!==void 0?gt(b):H()?bt():null,tt=b?.id??null,h.replaceChildren(...a,...se!==null?[se]:[]),q(),ct(s),l!==null&&[...h.querySelectorAll("[data-prop]")].find(c=>c.getAttribute("data-prop")===l)?.focus({preventScroll:!0})},vt=()=>{for(const n of h.querySelectorAll("[data-component]"))n.classList.toggle("is-selected",H()&&n.getAttribute("data-component")===z);const e=H()&&z!==null?Q().find(n=>n.id===z):void 0,t=ge?null:e!==void 0?gt(e):H()?bt():null;se!==null&&t!==null&&se.parentNode===h?se.replaceWith(t):(se?.remove(),t!==null&&h.append(t)),se=t,tt=e?.id??null},kt=(e,t)=>{const n=t?.getAttribute("data-inline")??null,i=Date.now();n!==null&&t!==null&&R!==null&&R.id===e&&R.prop===n&&i-R.at<It?(R=null,t.isConnected&&Et(e,t)):R=n!==null?{id:e,prop:n,at:i}:null},xt=(e,t)=>{if(t==="title")return e.title??"";if(t==="text"&&e.type==="text")return e.text;if(t==="label"){if(e.type==="button")return e.action.label;if(e.type==="link")return e.label;if(e.type==="filter")return e.label??""}return""},Et=(e,t)=>{const n=Q().find(c=>c.id===e),i=t.getAttribute("data-inline");if(n===void 0||i===null||!H()||$!==null)return;const s=xt(n,i),l=i==="text",a=l?p("textarea","wk-inline-input wk-inline-input--multi"):p("input","wk-inline-input");a.value=s,a.maxLength=l?4e3:n.type==="button"?60:120,a.setAttribute("data-testid","apps-inline"),a.setAttribute("aria-label",`Edit the ${i==="text"?"text":i}`),t.replaceWith(a),a.closest("[data-component]")?.classList.add("is-inline"),a.focus(),a.select();let r=!1,o=!1,f=!1,v=!1,b=[null,null,"none"];const q={id:e,prop:i,before:s,drop:()=>{r=!0,f=!1,$===q&&($=null)},hold:()=>{f=!0,b=[a.selectionStart,a.selectionEnd,a.selectionDirection??"none"]},composing:()=>o,defer:()=>{v=!0},place:()=>{const c=[...h.querySelectorAll("[data-component]")].find(C=>C.getAttribute("data-component")===e),w=c===void 0?void 0:[...c.querySelectorAll("[data-inline]")].find(C=>C.getAttribute("data-inline")===i);if(w===void 0){q.drop();return}w.replaceWith(a),c.classList.add("is-inline"),a.focus(),b[0]!==null&&b[1]!==null&&a.setSelectionRange(b[0],b[1],b[2]),f=!1}};$=q;const J=c=>{r||(q.drop(),c&&a.value!==s?le([{op:"component-set",id:e,prop:i,value:a.value}]):U())};a.addEventListener("compositionstart",()=>{o=!0}),a.addEventListener("compositionend",()=>{o=!1,v&&(v=!1,r||U())}),a.addEventListener("keydown",c=>{const w=c;if(!(o||w.isComposing||w.keyCode===229)){if(w.key==="Escape"){w.preventDefault(),w.stopPropagation(),J(!1);return}w.key==="Enter"&&!(l&&w.shiftKey)&&(w.preventDefault(),w.stopPropagation(),J(!0))}}),a.addEventListener("blur",()=>{f||(a.isConnected?J(!0):q.drop())})};h.addEventListener("dblclick",e=>{if(!H()||$!==null)return;const n=((typeof document.elementFromPoint=="function"?document.elementFromPoint(e.clientX,e.clientY):null)??e.target)?.closest("[data-inline]"),i=n?.closest("[data-component]");n==null||i===null||i===void 0||(e.preventDefault(),Et(i.getAttribute("data-component"),n))});function Mt(e){if(N===null||I===null)return;const t=e.target?.closest?.(".wk-cell.is-editable");if(t!==null&&(e.key==="Enter"||e.key===" ")&&e.target===t){e.preventDefault();const s=t.getAttribute("data-component");s!==null&&(De(s),vt(),h.querySelector(".wk-props input, .wk-props select")?.focus());return}const n=e.target?.closest("input, textarea, select")!=null;if((e.metaKey||e.ctrlKey)&&!e.altKey&&e.key.toLowerCase()==="z"&&!n&&H()){e.preventDefault(),A("app.history",{move:e.shiftKey?"redo":"undo",base:j}).then(s=>{s.ok||(E=s.message,s.code==="head_moved"?ue():U())});return}if((e.key==="Delete"||e.key==="Backspace")&&!n&&H()&&z!==null){e.preventDefault();const s=z;De(null),le([{op:"component-remove",id:s}]);return}e.key==="Escape"&&z!==null&&!n&&(De(null),U())}document.addEventListener("keydown",Mt),h.append(p("p","wk-empty","Loading the app…")),d===void 0?Lt(u.editor,u.surfaces):ce(d.port,d.hello)}return he.boot=Ht,Object.defineProperty(he,Symbol.toStringTag,{value:"Module"}),he})({});
1
+ var wickedAppsStandalone=(function(ue){"use strict";var fn=Object.defineProperty;var hn=(ue,fe,qe)=>fe in ue?fn(ue,fe,{enumerable:!0,configurable:!0,writable:!0,value:qe}):ue[fe]=qe;var Re=(ue,fe,qe)=>hn(ue,typeof fe!="symbol"?fe+"":fe,qe);const fe={"Alt+J":{verb:"navigate",what:"next card or row"},"Alt+K":{verb:"navigate",what:"previous card or row"},"Alt+/":{verb:"navigate",what:"the keyboard shortcuts overlay"},"Alt+P":{verb:"navigate",what:"peek at the top item that needs you"},"Alt+G":{verb:"navigate",what:"jump to the top item that needs you"},"Alt+B":{verb:"navigate",what:"back to where you were"},"Alt+T":{verb:"navigate",what:"the run’s evidence timeline"},"Alt+U":{verb:"navigate",what:"the run’s unit list"},"Alt+A":{verb:"approve",what:"approve the open gate"},"Alt+R":{verb:"decide",what:"reject the open gate"},"Alt+X":{verb:"decide",what:"select a gate for batch resolution"},"Alt+N":{verb:"compose",what:"compose a steer note"}},qe=new Set(["Escape","Mod+K","Tab","Shift+Tab"]);function Pt(a){if(qe.has(a))return!0;const l=fe[qt(a)];return l!==void 0&&l.verb==="navigate"}function qt(a){const l=/^alt\+(.)$/i.exec(a);return l===null?a:`Alt+${l[1].toUpperCase()}`}function Ot(a){if(a===""||/[\u0000-\u001f\u007f]/.test(a))return!1;const l=Intl.Segmenter;return l!==void 0?Array.from(new l(void 0,{granularity:"grapheme"}).segment(a)).length===1:Array.from(a).length===1}const He="wicked.editor",Ge=1;function Tt(a,l,m){return{editor:a,version:l,protocol:[1,2],surfaces:m}}function Dt(a,l){const m=document.querySelector('meta[name="wicked-editor-version"]')?.getAttribute("content")??"0.0.0";parent.postMessage({p:He,v:Ge,type:"plugin.ready",payload:Tt(a,m,l)},"*")}function lt(a){return Array.from(a.querySelectorAll("button, a[href], input, select, textarea, summary, [tabindex]")).filter(l=>l.tabIndex>=0&&!l.matches(":disabled")&&l.closest("[hidden]")===null)}function Ct(a,l,m){const w=a.metaKey||a.ctrlKey;let f=null;if(a.key==="Escape")f="Escape";else if(w&&!a.altKey&&a.key.toLowerCase()==="k")f="Mod+K";else if(a.altKey&&!w&&/^Key[A-Z]$/.test(a.code)&&Pt(`Alt+${a.code.slice(3)}`))f=`Alt+${a.code.slice(3)}`;else if(a.key==="Tab"){const $=lt(l),b=$.indexOf(a.target);(a.shiftKey?b<=0:b===-1||b===$.length-1)&&(f=a.shiftKey?"Shift+Tab":"Tab")}return f===null?!1:(a.preventDefault(),a.stopPropagation(),m(f),!0)}function Rt(a,l,m){if(a.defaultPrevented)return!1;const w=a.target;if(a.key==="Tab"&&!(w instanceof HTMLElement&&lt(l).includes(w)))return!1;if(Ct(a,l,$=>m("ui.key",{key:$})))return!0;if(a.metaKey||a.ctrlKey||a.altKey||!Ot(a.key))return!1;const f=w?.closest("[contenteditable]");return w?.closest("input,textarea,select")||f&&f.getAttribute("contenteditable")!=="false"||a.key===" "&&w?.closest('button,summary,a[href],[role="button"],[tabindex]:not([tabindex="-1"])')?!1:(a.preventDefault(),a.stopPropagation(),m("ui.typed",{grapheme:a.key}),!0)}const It=/^[A-Z]{3}$/u;function we(a,l,m){if(a==null)return"";if(typeof a=="boolean")return a?"yes":"no";const w=typeof l?.decimals=="number"&&Number.isInteger(l.decimals)?Math.min(10,Math.max(0,l.decimals)):void 0,f=typeof a=="number"?a:typeof a=="string"&&a.trim()!==""&&Number.isFinite(Number(a))?Number(a):null;try{switch(l?.kind){case"currency":if(f===null||!It.test(l.currency))break;return new Intl.NumberFormat(m,{style:"currency",currency:l.currency,...w!==void 0?{minimumFractionDigits:w,maximumFractionDigits:w}:{}}).format(f);case"percent":if(f===null)break;return new Intl.NumberFormat(m,{style:"percent",maximumFractionDigits:w??1}).format(f);case"number":if(f===null)break;return new Intl.NumberFormat(m,w!==void 0?{minimumFractionDigits:w,maximumFractionDigits:w}:{}).format(f);case"date":case"datetime":{const $=new Date(typeof a=="number"?a:String(a));if(Number.isNaN($.getTime()))break;return new Intl.DateTimeFormat(m,l.kind==="date"?{dateStyle:"medium",timeZone:"UTC"}:{dateStyle:"medium",timeStyle:"short"}).format($)}case"duration":{if(f===null)break;const $=Math.abs(Math.round(f)),b=Math.floor($/86400),E=Math.floor($%86400/3600),X=Math.floor($%3600/60);return b>0?`${b}d ${E}h`:E>0?`${E}h ${X}m`:`${X}m`}default:break}}catch{}return typeof a=="number"?Number.isInteger(a)?String(a):new Intl.NumberFormat(m,{maximumFractionDigits:6}).format(a):String(a)}function z(a,l=200){return typeof a=="string"?a.replace(/[\u0000-\u001f\u007f]+/gu," ").slice(0,l):""}const Ft="http://www.w3.org/2000/svg";function te(a,l,m){const w=document.createElementNS(Ft,a);for(const[f,$]of Object.entries(l))w.setAttribute(f,String($));return m!==void 0&&w.setAttribute("class",m),w}function We(a,l,m,w,f="start"){const $=te("text",{x:a,y:l,"text-anchor":f},w);return $.textContent=m,$}function Ae(a){return typeof a=="number"?Number.isFinite(a)?a:0:typeof a=="string"&&a.trim()!==""&&Number.isFinite(Number(a))?Number(a):0}const H=a=>Math.round(a*10)/10;function Ve(a,l){const m=document.createElement("ul");m.className="wk-legend",l.forEach((w,f)=>{const $=document.createElement("li"),b=document.createElement("span");b.className=`wk-swatch wk-series-${f%12}`,$.append(b,document.createTextNode(w)),m.append($)}),a.append(m)}function zt(a,l,m,w){const f=g=>m.columns.findIndex(x=>x.name===g),$=f(l.x),b=l.series.slice(0,l.chart==="pie"?1:12).map(g=>({label:z(g.label??g.column,60),i:f(g.column)})).filter(g=>g.i>=0),E=m.rows.slice(0,500);if($<0||b.length===0||E.length===0){const g=document.createElement("p");g.className="wk-empty",g.textContent=E.length===0?"No rows":"This chart’s columns are not in its query’s rows",a.append(g);return}const X=E.map(g=>we(g[$],void 0,w));if(l.chart==="bar"){const g=l.stacked===!0&&b.length>1,x=E.map(K=>b.map(P=>Ae(K[P.i])));let S=0,A=0;for(const K of x)if(g)A=Math.max(A,K.filter(P=>P>0).reduce((P,U)=>P+U,0)),S=Math.min(S,K.filter(P=>P<0).reduce((P,U)=>P+U,0));else for(const P of K)A=Math.max(A,P),S=Math.min(S,P);A===S&&(A=S+1);const O=130,N=b.length>1?250:220,L=K=>O+(K-S)/(A-S)*N,R=L(0),T=g||b.length===1?26:Math.max(26,b.length*10+10),M=te("svg",{viewBox:`0 0 400 ${E.length*T+4}`,role:"img","aria-label":z(l.title??"bar chart",120)},"wk-chart wk-chart--bar");S<0&&M.append(te("line",{x1:H(R),x2:H(R),y1:0,y2:E.length*T+4},"wk-grid-line")),E.forEach((K,P)=>{const U=P*T+2;if(M.append(We(0,H(U+T/2+4),X[P].slice(0,22),"wk-axis")),g){let ge=0,me=0;b.forEach((ve,pe)=>{const ne=x[P][pe],ze=ne>=0?ge:me+ne,Qe=ne>=0?ge+ne:me;ne>=0?ge+=ne:me+=ne,M.append(te("rect",{x:H(L(ze)),y:U+4,width:H(Math.max(1,L(Qe)-L(ze))),height:T-10},`wk-series-${pe%12}`))});return}const re=(T-8)/b.length;b.forEach((ge,me)=>{const ve=x[P][me],pe=Math.min(L(ve),R),ne=Math.max(1,Math.abs(L(ve)-R));M.append(te("rect",{x:H(pe),y:H(U+4+me*re),width:H(ne),height:H(Math.max(2,re-2)),rx:2},`wk-series-${me%12}`)),b.length===1&&M.append(We(H(ve<0?pe-6:pe+ne+6),H(U+T/2+4),we(K[ge.i],void 0,w),"wk-value",ve<0?"end":"start"))})}),a.append(M),b.length>1&&Ve(a,b.map(K=>K.label));return}if(l.chart==="pie"){const g=b[0],x=E.reduce((O,N)=>O+Math.max(0,Ae(N[g.i])),0)||1,S=te("svg",{viewBox:"0 0 240 240",role:"img","aria-label":z(l.title??"pie chart",120)},"wk-chart wk-chart--pie");let A=-Math.PI/2;E.forEach((O,N)=>{const L=Math.max(0,Ae(O[g.i]))/x,R=A+L*Math.PI*2,T=R-A>Math.PI?1:0,M=P=>`${H(120+100*Math.cos(P))} ${H(120+100*Math.sin(P))}`,K=L>=.9999?"M 120 20 A 100 100 0 1 1 119.9 20 Z":`M 120 120 L ${M(A)} A 100 100 0 ${T} 1 ${M(R)} Z`;S.append(te("path",{d:K},`wk-series-${N%12}`)),A=R}),a.append(S),Ve(a,X.slice(0,12));return}const Ee=600,ye=220,j=36,Me=24,ae=l.chart==="area"&&l.stacked===!0&&b.length>1,G=[],I=new Map;E.forEach((g,x)=>{if(G.push(x),!ae||x+1>=E.length)return;const S=new Map;b.forEach((A,O)=>{const N=Ae(E[x][A.i]),L=Ae(E[x+1][A.i]);if(N>0&&L<0||N<0&&L>0){const R=N/(N-L);S.set(R,[...S.get(R)??[],O])}});for(const A of[...S.keys()].sort((O,N)=>O-N))I.set(G.length,new Set(S.get(A))),G.push(x+A)});const $e=(g,x)=>{if(I.get(x)?.has(g)===!0)return 0;const S=G[x],A=Math.floor(S),O=S-A,N=Ae(E[A][b[g].i]);return O===0||A+1>=E.length?N:N+(Ae(E[A+1][b[g].i])-N)*O},Z=b.map(()=>[]),F=b.map(()=>[]);let V=0,he=1;const be=g=>{g<V&&(V=g),g>he&&(he=g)};G.forEach((g,x)=>{let S=0,A=0;b.forEach((O,N)=>{const L=$e(N,x);if(!ae){Z[N][x]=[0,L],F[N][x]=[0,0],be(L);return}const R=Math.max(0,L),T=Math.min(0,L);Z[N][x]=[S,S+R],F[N][x]=[A+T,A],S+=R,A+=T,be(S),be(A)})});const Te=he,ee=V,Le=g=>j+(E.length===1?0:g/(E.length-1)*(Ee-j-8)),Se=g=>ye-Me-(g-ee)/(Te-ee||1)*(ye-Me-10),ie=te("svg",{viewBox:`0 0 ${Ee} ${ye}`,role:"img","aria-label":z(l.title??`${l.chart} chart`,120)},`wk-chart wk-chart--${l.chart}`);for(let g=0;g<=3;g+=1){const x=ee+(Te-ee)*g/3;ie.append(te("line",{x1:j,x2:Ee-8,y1:H(Se(x)),y2:H(Se(x))},"wk-grid-line")),ie.append(We(j-6,H(Se(x)+4),we(Math.round(x*10)/10,void 0,w),"wk-axis","end"))}const Fe=E.length<=4?E.map((g,x)=>x):[0,Math.floor((E.length-1)/3),Math.floor((E.length-1)*2/3),E.length-1];for(const g of Fe)ie.append(We(H(Le(g)),ye-6,X[g].slice(0,14),"wk-axis",g===0?"start":g===E.length-1?"end":"middle"));b.forEach((g,x)=>{const S=(T,M)=>`${H(Le(G[T]))},${H(Se(M))}`;if(l.chart==="area"){const T=M=>{const K=G.map((U,re)=>S(re,M[re][1])),P=G.map((U,re)=>S(re,M[re][0])).reverse();return`M ${K.join(" L ")} L ${P.join(" L ")} Z`};ie.append(te("path",{d:T(Z[x])},`wk-area wk-series-${x}`)),ae&&F[x].some(([M,K])=>M!==K)&&ie.append(te("path",{d:T(F[x])},`wk-area wk-area--neg wk-series-${x}`))}if(!ae){ie.append(te("polyline",{points:G.map((T,M)=>S(M,$e(x,M))).join(" "),fill:"none"},`wk-stroke wk-series-${x}`));return}const A=[];let O=null,N=0,L=[];const R=(T,M)=>T<0?S(M,F[x][M][0]):S(M,Z[x][M][1]);G.forEach((T,M)=>{const K=$e(x,M);if(I.get(M)?.has(x)===!0||K===0){O!==null&&O.push(R(N,M)),L.push(M);return}const P=K>0?1:-1;if(O===null)O=L.map(U=>R(P,U)),A.push(O),N=P;else if(P!==N){const U=L[L.length-1];O=U!==void 0?[R(P,U)]:[],A.push(O),N=P}O.push(R(P,M)),L=[]}),O===null&&L.length>1&&A.push(L.map(T=>R(1,T)));for(const T of A)T.length>1&&ie.append(te("polyline",{points:T.join(" "),fill:"none"},`wk-stroke wk-series-${x}`))}),a.append(ie),b.length>1&&Ve(a,b.map(g=>g.label))}const Kt=/^#[0-9a-fA-F]{6}$/u,dt=/^(?::root|\.wk-c\d{1,4}(?: \.wk-[a-z]+)?)$/u,_t=/^(?:--[a-z0-9-]{1,40}|[a-z-]{1,40})$/u,Bt="(max-width: 639px)";function Je(a){return typeof a=="string"&&Kt.test(a)?a.toLowerCase():null}function Oe(a,l,m,w){return Number.isInteger(a)?Math.min(m,Math.max(l,a)):w}function Ht(a){return typeof a=="string"&&a.length<=200&&!/url\(|[;{}]|\/\*|\\/iu.test(a)?a:null}class Wt{constructor(l){Re(this,"sheet");Re(this,"base");Re(this,"rules",new Map);Re(this,"phone",null);Re(this,"phoneRules",new Map);if(l.sheet===null)throw new Error("the runtime stylesheet did not load");this.sheet=l.sheet,this.base=this.sheet.cssRules.length}reset(){for(;this.sheet.cssRules.length>this.base;)this.sheet.deleteRule(this.sheet.cssRules.length-1);this.rules.clear(),this.phoneRules.clear(),this.phone=null}rule(l){if(!dt.test(l))throw new Error("a selector outside the runtime’s vocabulary");const m=this.rules.get(l);if(m!==void 0)return m;const w=this.sheet.insertRule(`${l} {}`,this.sheet.cssRules.length),f=this.sheet.cssRules[w];return this.rules.set(l,f),f}phoneRule(l){if(!dt.test(l))throw new Error("a selector outside the runtime’s vocabulary");const m=this.phoneRules.get(l);if(m!==void 0)return m;if(this.phone===null){const $=this.sheet.insertRule(`@media ${Bt} {}`,this.sheet.cssRules.length);this.phone=this.sheet.cssRules[$]}const w=this.phone.insertRule(`${l} {}`,this.phone.cssRules.length),f=this.phone.cssRules[w];return this.phoneRules.set(l,f),f}set(l,m,w){_t.test(m)&&l.style.setProperty(m,w)}theme(l,m){const w=this.rule(":root");for(const[b,E]of Object.entries(l)){const X=Ht(E);/^--[a-z0-9-]{1,40}$/u.test(b)&&X!==null&&this.set(w,b,X)}const f=Je(m.accent);f!==null&&this.set(w,"--app-accent",f),m.density==="compact"&&(this.set(w,"--row","36px"),this.set(w,"--gap","8px"));const $=Array.isArray(m.palette)?m.palette:[];for(let b=0;b<12;b+=1){const E=Je($[b]);E!==null&&this.set(w,`--s${b}`,E)}}place(l,m){const w=this.rule(`.wk-c${l}`),f=Oe(m.x,0,11,0),$=Oe(m.w,1,12-f,1),b=Oe(m.y,0,999,0),E=Oe(m.h,1,50,1);this.set(w,"grid-column",`${f+1} / span ${$}`),this.set(w,"grid-row",`${b+1} / span ${E}`)}phoneOrder(l,m,w){const f=this.phoneRule(`.wk-c${l}`);this.set(f,"order",String(Oe(m,0,9999,0))),w?this.set(f,"display","none"):f.style.removeProperty("display")}seriesColour(l,m,w){const f=Je(w);f!==null&&this.set(this.rule(`.wk-c${l}`),`--c${Oe(m,0,11,0)}`,f)}}const Zt={comfortable:44,compact:36},pt={comfortable:12,compact:8},Xt=450,ct=500,Ut=/^[A-Za-z_][A-Za-z0-9_]{0,63}$/u,Ie=()=>Object.create(null);function Yt(a,l){if(a===void 0||l===null||l===void 0)return l;if((a.type==="number"||a.type==="integer")&&typeof l=="string"&&l.trim()!==""){const m=Number(l);return Number.isFinite(m)&&(a.type==="number"||Number.isInteger(m))?m:l}return a.type==="boolean"&&typeof l=="string"&&(l==="true"||l==="false")?l==="true":a.type==="string"&&(typeof l=="number"||typeof l=="boolean")?String(l):l}const Q=a=>typeof a=="object"&&a!==null&&!Array.isArray(a),jt=/^data:image\/(?:png|jpeg|gif|webp);base64,[A-Za-z0-9+/]+={0,2}$/u,ut={table:{w:12,h:5},chart:{w:6,h:5},kpi:{w:3,h:2},text:{w:6,h:1},filter:{w:3,h:1},form:{w:4,h:6},button:{w:2,h:1},image:{w:3,h:3},link:{w:2,h:1}},Gt=[{type:"table",label:"Table"},{type:"chart",label:"Chart"},{type:"kpi",label:"KPI"},{type:"filter",label:"Filter"},{type:"form",label:"Form"},{type:"button",label:"Button"},{type:"text",label:"Text"},{type:"link",label:"Link"}];function c(a,l,m){const w=document.createElement(a);return l!==void 0&&(w.className=l),m!==void 0&&(w.textContent=m),w}function ft(a){return a.toISOString().slice(0,10)}function Vt(a,l){Jt({editor:"wicked-apps",surfaces:{}},{port:a,hello:l})}function Jt(a,l){const m=document.getElementById("wk-apps-sheet")??(l===void 0?null:document.querySelector('link[rel="stylesheet"], style'));if(!(m instanceof HTMLStyleElement)&&!(m instanceof HTMLLinkElement))return;const w=new Wt(m),f=c("div","wk-app");f.setAttribute("data-testid","apps-runtime"),document.body.append(f);let $=null,b=new Set,E=!0,X=!1,Ee=!1,ye=!1,j="preview",Me="full",ae="en",G=0,I=null,$e=!1,Z=null,F=null;const V=Ie(),he=new Map,be=Ie(),Te=Ie(),ee=new Map,Le=new Map,Se=new Map,ie=new Map,Fe=new Map;let g=0,x=0;const S=new Map;let A=null;const O=new Map;let N=!1,L=null,R=null;const T=e=>{$?.postMessage({p:He,v:Ge,...e})},M=(e,t)=>{x+=1;const n=`a${x}`;return T({type:e,id:n,payload:t}),new Promise(i=>S.set(n,i))},K=(e,t)=>T({type:e,payload:t}),P=e=>{e.key==="Escape"&&F!==null&&!e.target.closest?.("input,textarea,select")||Rt(e,f,K)};document.addEventListener("keydown",P);const U=e=>{const t=e.data;if(!Q(t)||t.p!==He||t.v!==Ge)return;const n=Q(t.payload)?t.payload:{};if(typeof t.re=="string"){const i=S.get(t.re);if(i===void 0)return;S.delete(t.re);const s=Q(t.error)?t.error:{};i(t.ok===!0?{ok:!0,payload:n}:{ok:!1,code:String(s.code??"unavailable"),message:z(s.message,300),payload:n});return}if(!N)switch(t.type){case"host.ping":typeof t.id=="string"&&T({re:t.id,ok:!0,payload:{}});return;case"host.theme":Q(n.theme)&&(re=n.theme),Y();return;case"artifact.changed":pe();return;case"app.mode":(n.mode==="edit"||n.mode==="preview")&&(j=n.mode,j==="preview"&&(F=null),Y());return;case"data.invalidate":Ne();return;case"host.surface":(n.surface==="card"||n.surface==="full")&&(Me=n.surface,Y());return;case"selection.cleared":F=null,Y();return;case"host.teardown":N=!0;for(const i of O.values())clearInterval(i);O.clear(),document.removeEventListener("keydown",St),document.removeEventListener("keydown",P),$?.close(),$=null,f.replaceChildren(c("p","wk-empty","Closed"));return;default:return}};let re={};const ge=e=>{Q(e)&&(re=e),w.theme(re,{accent:I?.theme?.accent,palette:I?.theme?.palette,density:I?.theme?.density})},me=()=>I?.theme?.density==="compact"?"compact":"comfortable",ve=(e,t)=>{$=e,$.onmessage=U,b=new Set(Array.isArray(t.grants)?t.grants.filter(s=>typeof s=="string"):[]);const n=Q(t.app)?t.app:{};if(E=n.framed!==!1,X=n.tile===!0,Ee=X&&n.rows===!0,ye=n.propsHost===!0,j=n.mode==="edit"?"edit":"preview",Me=t.surface==="card"||t.size==="inline"?"card":"full",Q(n.url))for(const[s,p]of Object.entries(n.url).slice(0,30))Ut.test(s)&&typeof p=="string"&&p.length<=1e3&&(Te[s]=p);const i=Q(t.prefs)?t.prefs:{};ae=typeof i.locale=="string"&&/^[A-Za-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/u.test(i.locale)?i.locale:"en",ge(t.theme),pe()};l===void 0&&window.addEventListener("message",e=>{const t=e.data;$!==null||e.source!==parent||!Q(t)||t.p!==He||t.type!=="host.hello"||e.ports[0]===void 0||ve(e.ports[0],Q(t.payload)?t.payload:{})});const pe=async()=>{const e=await M("artifact.read",{});if(!e.ok){A=e.message,Y();return}const t=Q(e.payload.content)?e.payload.content:{};if(t.type!=="app"||!Q(t.spec)){A="This is not an app",Y();return}const n=G;G=typeof e.payload.version=="number"?e.payload.version:0,I=t.spec,$e=t.readonly===!0,(Z===null||!I.pages.some(s=>s.id===Z))&&(Z=I.pages[0]?.id??null),F!==null&&!oe().some(s=>s.id===F)&&(F=null),A=null,et();const i=ne();Y(),(n!==G||i||ee.size===0)&&Ne()},ne=()=>{const e=new Map;for(const n of I?.pages??[])for(const i of n.components){const s=tt(i);s!==null&&e.set(i.id,ze(s))}let t=!1;for(const n of[...ee.keys()])Le.get(n)!==e.get(n)&&(ee.delete(n),Le.delete(n),t=!0);return t},ze=e=>`${e.query}\0${JSON.stringify(e.params)}`,Qe=()=>I?.pages.find(e=>e.id===Z)??null,oe=()=>Qe()?.components??[],Qt=(e,t)=>{const n=V[e];if(n!==void 0)return typeof n=="string"?t===void 0?n:void 0:t==="from"?n.from:t==="to"?n.to:void 0},Ze=(e,t,n)=>{const i={},s=n?.properties??{};for(const[p,r]of Object.entries(e??{})){const[d,o,h]=r.split(".");let k;if(d==="filter"&&o!==void 0)k=Qt(o,h);else if(d==="row"&&o!==void 0&&t.row!==void 0&&Object.hasOwn(t.row,o))k=t.row[o];else if(d==="form"&&o!==void 0&&t.form!==void 0){const v=be[t.form];k=v!==void 0&&Object.hasOwn(v,o)?v[o]:void 0}else d==="url"&&o!==void 0&&(k=Te[o]);k!==void 0&&k!==""&&(i[p]=Yt(Object.hasOwn(s,p)?s[p]:void 0,k))}return i},et=()=>{for(const e of I?.pages??[])for(const t of e.components)if(!(t.type!=="filter"||V[t.id]!==void 0))if(t.filter==="date-range"){const n=Q(t.default)&&Number.isInteger(t.default.lastDays)?Math.min(3650,Math.max(1,t.default.lastDays)):30,i=new Date;V[t.id]={from:ft(new Date(i.getTime()-n*864e5)),to:ft(i)}}else V[t.id]=typeof t.default=="string"?t.default:""},ht=e=>I?.queries.find(t=>t.id===e)?.params,tt=e=>e.type==="table"||e.type==="chart"||e.type==="kpi"?{query:e.data.query,params:Ze(e.data.params,{},ht(e.data.query))}:e.type==="filter"&&e.filter==="select"&&e.options?.kind==="query"?{query:e.options.query.query,params:Ze(e.options.query.params,{},ht(e.options.query.query))}:null,Ne=(e,t=!1)=>{if(N||!b.has("data.read")||I===null||X&&!Ee)return;et(),g+=1;const n=g,i=new Map;for(const s of oe()){const p=tt(s);if(p===null||e!==void 0&&p.query!==e||t&&ee.has(s.id))continue;const r=ze(p);let d=i.get(r);d===void 0&&(d=M("data.query",{query:p.query,params:p.params}).then(o=>{if(!o.ok)return{state:"error",message:o.message};const h=Array.isArray(o.payload.columns)?o.payload.columns:[],k=Array.isArray(o.payload.rows)?o.payload.rows.filter(Array.isArray):[];return{state:"rows",rows:{columns:h,rows:k,sample:o.payload.sample===!0,hasMore:o.payload.hasMore===!0,truncated:o.payload.truncated===!0}}}),i.set(r,d)),ee.has(s.id)||(ee.set(s.id,{state:"loading"}),Le.set(s.id,r)),Se.set(s.id,n),d.then(o=>{!N&&Se.get(s.id)===n&&(ee.set(s.id,o),Le.set(s.id,r),Ke(s.id))})}e===void 0&&en()},en=()=>{const e=new Map;for(const t of oe()){const n=tt(t),i=n===null?void 0:I?.queries.find(s=>s.id===n.query);i?.refresh?.mode==="every"&&e.set(i.id,Math.max(15,i.refresh.seconds))}for(const[t,n]of[...O]){const[i,s]=t.split("\0");e.get(i)!==Number(s)&&(clearInterval(n),O.delete(t))}for(const[t,n]of e){const i=`${t}\0${n}`;O.has(i)||O.set(i,setInterval(()=>{document.visibilityState==="visible"&&Ne(t)},n*1e3))}},tn=async(e,t,n)=>{if(E||j!=="preview"||!b.has("data.write"))return;const i=oe().find(o=>o.id===e)?.type!=="button",s=o=>{i?(ie.set(e,o),Ke(e)):yt(`${z(t.label,60)}: ${o}`)};s("Waiting for you in studio…");const p=await M("data.action",{action:t.action,params:Ze(t.params,n,I?.actions.find(o=>o.id===t.action)?.params)}),r=p.ok?String(p.payload.state):"refused",d=p.ok?z(p.payload.reason,200):p.message;s(r==="succeeded"?`Done${d!==""?`: ${d}`:""}`:r==="cancelled"?"Not run":r==="unknown"?`Not known whether it ran: ${d}`:`Not run: ${d}`)},nt=(e,t,n,i="wk-btn wk-btn--sm")=>{if(E)return c("span","wk-muted","Open to make changes");const s=c("button",i,z(t.label,60));return s.type="button",s.setAttribute("data-action",t.action),X||j!=="preview"||!b.has("data.write")?(s.setAttribute("aria-disabled","true"),s.title=X?"":j==="edit"?"Actions run in Preview":"This app may not ask to run actions here"):s.addEventListener("click",p=>{p.stopPropagation(),tn(e,t,n)}),s},ot=new Map;let se=null,st=null;const at=new Map,Xe=new WeakSet,it=new WeakSet;let Ue=null;const nn=()=>{const e=document.activeElement;if(!(e instanceof HTMLInputElement)||e.type!=="search"||e.closest(".wk-filter-options")===null)return null;const t=e.closest("[data-component]")?.getAttribute("data-component");return t==null?null:{id:t,el:e,range:[e.selectionStart,e.selectionEnd,e.selectionDirection]}},mt=e=>{if(e===null)return;const t=[...f.querySelectorAll("[data-component]")].find(n=>n.getAttribute("data-component")===e.id)?.querySelector('.wk-filter-options input[type="search"]');t==null||t===e.el||(t.focus({preventScroll:!0}),t.setSelectionRange(e.range[0],e.range[1],e.range[2]??void 0))},wt=(e,t)=>{const n=t.querySelector('.wk-filter-options input[type="search"]'),i=n!==null&&document.activeElement===n;if(i&&Xe.has(n)){it.add(n);return}const s=i?[n.selectionStart,n.selectionEnd,n.selectionDirection]:null;if(i&&he.set(e.id,n.value),sn(e,t),on(e,t),s!==null){const p=t.querySelector('.wk-filter-options input[type="search"]');p?.focus({preventScroll:!0}),p?.setSelectionRange(s[0],s[1],s[2]??void 0)}},on=(e,t)=>{if(!B())return;const n=(i,s)=>{i!==null&&(i.setAttribute("data-inline",s),i.classList.add("wk-editable"),i.setAttribute("title","Double-click to edit"))};e.type==="text"&&n(t.querySelector(".wk-text"),"text"),e.type==="button"&&n(t.querySelector("button[data-action]"),"label"),e.type==="link"&&n(t.querySelector(".wk-link"),"label"),e.type==="filter"&&n(t.querySelector(".wk-filter-label"),"label")},sn=(e,t)=>{t.replaceChildren();const n=ee.get(e.id);if(e.type==="table"||e.type==="chart"||e.type==="kpi"){if(X&&!Ee){t.append(c("div",`wk-skeleton wk-skeleton--${e.type}`));return}if(!b.has("data.read")){t.append(c("p","wk-muted","Live rows are not shown here"));return}if(n===void 0||n.state==="loading"){t.append(c("p","wk-muted","Loading…"));return}if(n.state==="error"){t.append(c("p","wk-error",`${"data"in e?e.data.query:""}: ${n.message}`));return}}const s=n?.state==="rows"?n.rows:null;switch(e.type){case"kpi":{const p=o=>o===void 0?-1:s.columns.findIndex(h=>h.name===o),r=s.rows[0];t.append(c("div","wk-kpi-value",r===void 0?"—":we(r[p(e.value)],e.format,ae)));const d=c("div","wk-kpi-caption");if(r!==void 0&&e.delta!==void 0&&p(e.delta)>=0){const o=r[p(e.delta)],h=typeof o=="number"&&o<0||typeof o=="string"&&o.trim().startsWith("-");d.append(c("span",h?"wk-delta wk-delta--down":"wk-delta wk-delta--up",`${h?"▼":"▲"} ${we(o,void 0,ae).replace(/^\s*-/u,"")}`)),d.append(document.createTextNode(" "))}e.caption!==void 0&&d.append(document.createTextNode(z(e.caption,120))),t.append(d);return}case"chart":zt(t,e,s,ae),(s.truncated||s.rows.length>ct)&&t.append(c("p","wk-muted",s.truncated?"Only part of the source’s rows: the answer was cut at the app’s limit":`The first ${ct} of ${s.rows.length} rows`));return;case"table":{an(e,t,s);return}case"text":t.append(c(e.style==="heading"?"h2":"p",`wk-text wk-text--${e.style??"body"}`,e.text.slice(0,4e3)));return;case"filter":{rn(e,t);return}case"form":{ln(e,t);return}case"button":t.append(nt(e.id,e.action,{},"wk-btn"));return;case"image":{if(!jt.test(e.src)){t.append(c("p","wk-muted","This image is not one the app can show"));return}const p=c("img","wk-image");p.alt=z(e.alt,300),p.src=e.src,t.append(p);return}case"link":{const p=c("button","wk-link",z(e.label,120));if(p.type="button",e.to.kind==="page"){const r=e.to;p.addEventListener("click",()=>{if(j==="preview"){A=null;for(const[d,o]of Object.entries(Ze(r.params,{})))Te[d]=String(o);I?.pages.some(d=>d.id===r.page)&&(Z=r.page,F=null,Y(),Ne())}})}else{const r=e.to.href;p.title=r.slice(0,300),p.addEventListener("click",async()=>{if(j!=="preview")return;const d=await M("link.open",{href:r});d.ok||yt(`${z(e.label,60)} not opened: ${d.message}`)})}t.append(p);return}}},an=(e,t,n)=>{const i=u=>n.columns.findIndex(y=>y.name===u),s=(e.columns??n.columns.map(u=>({column:u.name}))).filter(u=>i(u.column)>=0),p=Math.min(500,Math.max(5,e.pageSize??10)),r=Math.max(1,Math.ceil(n.rows.length/p)),d=Math.min(Fe.get(e.id)??0,r-1),o=c("table","wk-table"),h=c("tr");for(const u of s)h.append(c("th",void 0,z(u.label??u.column,80)));(e.rowActions??[]).length>0&&h.append(c("th","wk-th-actions","")),o.append(c("thead")),o.tHead.append(h);const k=c("tbody");for(const u of n.rows.slice(d*p,d*p+p)){const y=c("tr"),D=Ie();n.columns.forEach((_,C)=>{D[_.name]=u[C]??null});for(const _ of s){const C=u[i(_.column)],W=we(C,_.format,ae),ce=/^\S+$/u.test(W),je=typeof C=="number"?"wk-num":ce?W.length>64?"wk-token wk-token--long":"wk-token":"wk-prose",Ce=c("td",je,W);ce&&W.length>64&&(Ce.title=W),y.append(Ce)}if((e.rowActions??[]).length>0){const _=c("td","wk-td-actions");for(const C of(e.rowActions??[]).slice(0,4))_.append(nt(e.id,C,{row:D}));y.append(_)}k.append(y)}o.append(k);const v=c("div","wk-table-scroll");v.tabIndex=0,v.setAttribute("role","region"),v.setAttribute("aria-label",`${z(e.title??"Table",80)}, scrolls sideways`),v.append(o),t.append(v),n.rows.length===0&&t.append(c("p","wk-muted","No rows"));const q=c("div","wk-table-foot");if(r>1){const u=c("button","wk-btn wk-btn--sm","Previous"),y=c("button","wk-btn wk-btn--sm","Next");u.type="button",y.type="button",u.disabled=d===0,y.disabled=d>=r-1,u.addEventListener("click",()=>{Fe.set(e.id,d-1),Ke(e.id)}),y.addEventListener("click",()=>{Fe.set(e.id,d+1),Ke(e.id)}),q.append(u,c("span","wk-muted",`${d+1} of ${r}`),y)}n.truncated?q.append(c("span","wk-muted",`Only the first ${n.rows.length} rows: the answer was cut at the app’s limit`)):n.hasMore&&q.append(c("span","wk-muted","First page of the source’s rows"));const J=ie.get(e.id);J!==void 0&&q.append(c("span","wk-status",J)),q.childNodes.length>0&&t.append(q)},rn=(e,t)=>{const n=c("label","wk-filter"),i=z(e.label??(e.filter==="search"?"Search":e.filter==="date-range"?"Dates":"Filter"),60),s=c("span","wk-filter-label",i);s.title=i,n.append(s);const p=()=>{Ne()};if(e.filter==="search"){const r=c("input","wk-input");r.type="search",r.value=typeof V[e.id]=="string"?V[e.id]:"";let d=null;r.addEventListener("input",()=>{V[e.id]=r.value.slice(0,200),d!==null&&clearTimeout(d),d=setTimeout(p,300)}),n.append(r)}else if(e.filter==="select"){const r=c("select","wk-input"),d=[];let o=!1;if(e.options?.kind==="values")for(const y of e.options.values)d.push({value:z(y.value,200),label:z(y.label??y.value,200)});if(e.options?.kind==="query"){const y=ee.get(e.id);if(y?.state==="rows"){o=y.rows.hasMore||y.rows.truncated;const D=y.rows.columns.findIndex(C=>C.name===e.options.value),_=y.rows.columns.findIndex(C=>C.name===(e.options.label??""));for(const C of y.rows.rows)D>=0&&d.push({value:we(C[D],void 0,ae),label:we(C[_>=0?_:D],void 0,ae)})}}const h=c("div","wk-filter-select"),k=c("div","wk-filter-options"),v=c("input","wk-input");v.type="search",v.placeholder="Search",v.setAttribute("aria-label",`Search ${z(e.label??"Filter",60)} options`),v.value=he.get(e.id)??"";const q=c("span","wk-muted");q.setAttribute("aria-live","polite");const J=d.length>200||o,u=()=>{const y=J?v.value.toLowerCase():"",D=d.filter(de=>de.label.toLowerCase().includes(y)),_=D.slice(0,200),C=typeof V[e.id]=="string"?V[e.id]:"",W=C===""?void 0:d.find(de=>de.value===C);W!==void 0&&!_.includes(W)&&(_.length===200&&_.pop(),_.push(W)),r.replaceChildren();for(const de of[{value:"",label:"All"},..._]){const Nt=c("option",void 0,de.label);Nt.value=de.value,r.append(Nt)}const ce=_.filter(de=>D.includes(de)).length,je=y===""?`${ce} of ${d.length}${o?"+":""}`:`${ce}${ce<D.length?` of ${D.length}`:""} matches`,Ce=`Showing ${je}${y!==""&&o?" in fetched rows":""}`;if(q.textContent=je,q.title=Ce,q.setAttribute("aria-label",Ce),ce<D.length||o){const de=c("option",void 0,`${Ce}: search to narrow`);de.disabled=!0,de.value="",r.append(de)}r.value=C};v.addEventListener("input",()=>{he.set(e.id,v.value),u()}),v.addEventListener("compositionstart",()=>{Xe.add(v)}),v.addEventListener("compositionend",()=>{if(Xe.delete(v),he.set(e.id,v.value),Ue!==null){const y=Ue;Ue=null,it.delete(v),Y(y)}else it.delete(v)&&Ke(e.id)}),u(),r.addEventListener("change",()=>{V[e.id]=r.value,u(),p()}),n.append(r),h.append(n),J&&(h.classList.add("wk-filter-select--search"),k.append(v,q),h.append(k)),t.append(h);return}else{const r=V[e.id]??{from:"",to:""},d=c("input","wk-input wk-input--date"),o=c("input","wk-input wk-input--date");d.type="date",o.type="date",d.value=r.from,o.value=r.to;const h=()=>{V[e.id]={from:d.value,to:o.value},p()};d.addEventListener("change",h),o.addEventListener("change",h),n.append(d,c("span","wk-muted","–"),o)}t.append(n)},ln=(e,t)=>{var d;const n=be[d=e.id]??(be[d]=Ie()),i=I?.actions.find(o=>o.id===e.submit.action)?.params?.properties??{};for(const o of e.fields){if(Object.hasOwn(n,o.name))continue;const h=e.submit.params===void 0?void 0:Object.entries(e.submit.params).find(([,v])=>v===`form.${o.name}`)?.[0],k=h!==void 0&&Object.hasOwn(i,h)?i[h].default:void 0;o.input==="checkbox"?n[o.name]=k===!0:k!==void 0&&(n[o.name]=String(k))}const s=c("div","wk-form");for(const o of e.fields.slice(0,30)){const h=c("label","wk-field");h.append(c("span","wk-filter-label",z(o.label??o.name,80)));let k;if(o.input==="textarea")k=c("textarea","wk-input");else if(o.input==="select"){k=c("select","wk-input");for(const v of o.options??[]){const q=c("option",void 0,z(v.label??v.value,200));q.value=z(v.value,200),k.append(q)}}else k=c("input","wk-input"),k.type=o.input==="number"?"number":o.input==="date"?"date":o.input==="checkbox"?"checkbox":"text";k instanceof HTMLInputElement&&k.type==="checkbox"?(k.checked=n[o.name]===!0,k.addEventListener("change",()=>{n[o.name]=k.checked})):(k.value=typeof n[o.name]=="string"?n[o.name]:"",k.addEventListener("input",()=>{n[o.name]=k.value.slice(0,1e3)})),k.disabled=j!=="preview",h.append(k),s.append(h)}const p=c("div","wk-form-foot");p.append(nt(e.id,e.submit,{form:e.id},"wk-btn"));const r=ie.get(e.id);p.append(c("span","wk-muted",r??(E?"":"Studio asks before it writes"))),s.append(p),t.append(s)};let ke=null;const yt=e=>{A=e,ke!==null?(ke.textContent=e,ke.hidden=!1):Y()},Ke=e=>{if(L!==null&&L.id===e)return;const t=oe().find(i=>i.id===e),n=at.get(e);t!==void 0&&n!==void 0&&wt(t,n)},B=()=>j==="edit"&&Me==="full"&&!$e&&b.has("artifact.write");let xe=null;const bt=()=>{const e=xe.getBoundingClientRect(),t=me();return{col:(e.width+pt[t])/12,row:Zt[t]+pt[t],left:e.left,top:e.top}},dn=(e,t)=>{const n=bt();return{x:Math.min(11,Math.max(0,Math.floor((e-n.left)/n.col))),y:Math.min(999,Math.max(0,Math.floor((t-n.top)/n.row)))}},le=async(e,t={})=>{const n=await M("spec.edit",{base:G,ops:e});if(!n.ok)return A=n.code==="head_moved"?"The app changed meanwhile: showing the newest version":`Not changed: ${n.message}`,n.code==="head_moved"?await pe():Y(),null;Q(n.payload.spec)&&(I=n.payload.spec),A=null,et(),ne();const i=Array.isArray(n.payload.added)?n.payload.added.filter(s=>typeof s=="string"):[];return i[0]!==void 0&&De(i[0]),Y({keepProps:t.typed===!0&&i.length===0}),Ne(void 0,!0),i},De=e=>{const t=F;F=e,e!==null&&b.has("selection.chip")?K("selection.set",{anchors:[{kind:"element",id:e}]}):e===null&&t!==null&&b.has("selection.chip")&&K("selection.set",{anchors:[]})},gt=(e,t,n,i)=>{if(!B()||e.button!==0)return;e.preventDefault(),e.stopPropagation(),(i.closest(".wk-cell")??i).focus({preventScroll:!0});const s=ot.get(t.id),p=bt(),r={x:e.clientX,y:e.clientY};let d={...t.box},o=!1;const h=n==="move"?e.target?.closest?.("[data-inline]"):null;i.setPointerCapture(e.pointerId),i.classList.add("is-dragging");const k=q=>{const J=Math.round((q.clientX-r.x)/p.col),u=Math.round((q.clientY-r.y)/p.row);J===0&&u===0&&!o||(o=!0,d=n==="move"?{...t.box,x:Math.min(12-t.box.w,Math.max(0,t.box.x+J)),y:Math.max(0,t.box.y+u)}:{...t.box,w:Math.min(12-t.box.x,Math.max(1,t.box.w+J)),h:Math.min(50,Math.max(1,t.box.h+u))},w.place(s,d))},v=()=>{i.removeEventListener("pointermove",k),i.removeEventListener("pointerup",v),i.removeEventListener("pointercancel",v),i.classList.remove("is-dragging");const q=n==="move"?d.x!==t.box.x||d.y!==t.box.y:d.w!==t.box.w||d.h!==t.box.h;if(!o||!q){w.place(s,t.box),o||(De(t.id),Et(),Mt(t.id,h));return}le([n==="move"?{op:"component-move",id:t.id,x:d.x,y:d.y}:{op:"component-resize",id:t.id,w:d.w,h:d.h}])};i.addEventListener("pointermove",k),i.addEventListener("pointerup",v),i.addEventListener("pointercancel",v)},vt=()=>oe().reduce((e,t)=>Math.max(e,t.box.y+t.box.h),0),pn=(e,t,n)=>{if(!B()||e.button!==0||xe===null||Z===null)return;e.preventDefault(),n.focus({preventScroll:!0});const i=ut[t],s=c("div","wk-drop wk-c9999");s.setAttribute("data-testid","apps-drop-target");let p=null;n.setPointerCapture(e.pointerId);const r=o=>{const h=xe.getBoundingClientRect();if(o.clientX<h.left||o.clientX>h.right||o.clientY<h.top){s.remove(),p=null;return}p=dn(o.clientX,o.clientY),p.x=Math.min(p.x,12-i.w),w.place(9999,{x:p.x,y:p.y,w:i.w,h:i.h}),s.parentNode===null&&xe.append(s)},d=o=>{if(n.removeEventListener("pointermove",r),n.removeEventListener("pointerup",d),n.removeEventListener("pointercancel",d),s.remove(),Math.abs(o.clientX-e.clientX)+Math.abs(o.clientY-e.clientY)>6&&p===null)return;const k=p??{x:0,y:vt()};le([{op:"component-add",page:Z,type:t,box:{x:k.x,y:k.y,w:Math.min(i.w,12-k.x),h:i.h}}])};n.addEventListener("pointermove",r),n.addEventListener("pointerup",d),n.addEventListener("pointercancel",d)},rt=(e,t,n=!1,i)=>{let s=e.value,p=null;const r=()=>{if(e.value===s)return;s=e.value;const o=t();if(o===void 0)return;const h=Promise.resolve(o);p=h,h.finally(()=>{p===h&&(p=null)})};let d=!1;e.addEventListener("compositionstart",()=>{d=!0}),e.addEventListener("compositionend",()=>{d=!1,r()}),e.addEventListener("input",o=>{!d&&o.isComposing!==!0&&r()}),i!==void 0&&e.addEventListener("blur",()=>{const o=()=>{if(document.activeElement===e)return;const h=i();e.value!==h&&(e.value=h,s=h)};p!==null?p.then(o,o):o()}),e.addEventListener("change",()=>{d||r()}),e.addEventListener("keydown",o=>{const h=o;d||h.isComposing||h.keyCode===229||h.key==="Enter"&&(!n||h.metaKey||h.ctrlKey)&&(h.preventDefault(),r())})},_e=(e,t)=>{const n=c("label","wk-prop");return n.append(c("span","wk-prop-label",e),t),n},Pe=(e,t,n,i,s,p=!1)=>{const r=c(p?"textarea":"input","wk-input");return r.value=i??"",r.maxLength=s,r.setAttribute("data-prop",n),rt(r,()=>le([{op:"component-set",id:e.id,prop:n,value:r.value}],{typed:!0}),p,()=>{const d=oe().find(h=>h.id===e.id),o=n==="label"&&d?.type==="button"?d.action?.label:d?.[n];return typeof o=="string"?o:""}),_e(t,r)},Be=(e,t,n,i,s,p="set")=>{const r=c("select","wk-input");for(const d of s){const o=c("option",void 0,d);o.value=d,r.append(o)}return r.value=i,r.setAttribute("data-prop",n),r.addEventListener("change",()=>{le([p==="bind"?{op:"bind",id:e.id,query:r.value}:{op:"component-set",id:e.id,prop:n,value:r.value}])}),_e(t,r)},kt=(e,t,n,i)=>{const s=c("input","wk-check");return s.type="checkbox",s.checked=i,s.setAttribute("data-prop",n),s.addEventListener("change",()=>{le([{op:"component-set",id:e.id,prop:n,value:s.checked}])}),_e(t,s)},Ye=(e,t,n,i,s)=>{const p=c("input","wk-input wk-input--num");p.type="number",p.min=String(i),p.max=String(s),p.value=String(n==="x"?e.box.x+1:n==="y"?e.box.y+1:e.box[n]),p.setAttribute("data-prop",`box-${n}`);const r=()=>oe().find(o=>o.id===e.id)?.box??e.box,d=o=>String(n==="x"?o.x+1:n==="y"?o.y+1:o[n]);return rt(p,()=>{if(p.value.trim()==="")return;const o=Math.round(Number(p.value));if(!Number.isFinite(o))return;const h=r();if(n==="x"||n==="y"){const q=n==="x"?Math.min(12-h.w,Math.max(0,o-1)):h.x,J=n==="y"?Math.max(0,o-1):h.y;return le([{op:"component-move",id:e.id,x:q,y:J}],{typed:!0})}const k=n==="w"?Math.min(12-h.x,Math.max(1,o)):h.w,v=n==="h"?Math.min(50,Math.max(1,o)):h.h;return le([{op:"component-resize",id:e.id,w:k,h:v}],{typed:!0})},!1,()=>d(r())),_e(t,p)},xt=e=>{const t=c("aside","wk-props");t.setAttribute("aria-label","Properties"),t.setAttribute("data-testid","apps-properties"),t.append(c("h3","wk-props-title","Properties")),t.append(c("p","wk-muted",`${e.type==="chart"?`${e.chart} chart`:e.type} · ${e.id}`)),t.append(Pe(e,"Title","title",e.title,120));const n=(I?.queries??[]).map(r=>r.id),i=r=>I?.queries.find(d=>d.id===r)?.output.map(d=>d.name)??[];if((e.type==="table"||e.type==="chart"||e.type==="kpi")&&t.append(Be(e,"Data","query",e.data.query,n,"bind")),e.type==="table"){const r=c("input","wk-input wk-input--num");r.type="number",r.min="5",r.max="500",r.value=String(e.pageSize??10),r.setAttribute("data-prop","pageSize"),rt(r,()=>{if(r.value.trim()==="")return;const d=Math.round(Number(r.value));return Number.isFinite(d)?le([{op:"component-set",id:e.id,prop:"pageSize",value:Math.min(500,Math.max(5,d))}],{typed:!0}):void 0},!1,()=>String(oe().find(d=>d.id===e.id)?.pageSize??10)),t.append(_e("Rows per page",r))}e.type==="chart"&&(t.append(Be(e,"Chart","chart",e.chart,["bar","line","area","pie"])),t.append(Be(e,"Category","x",e.x,i(e.data.query))),(e.chart==="bar"||e.chart==="area")&&t.append(kt(e,"Stacked","stacked",e.stacked===!0))),e.type==="kpi"&&(t.append(Be(e,"Figure","value",e.value,i(e.data.query))),t.append(Pe(e,"Caption","caption",e.caption,120))),e.type==="text"&&(t.append(Pe(e,"Text","text",e.text,4e3,!0)),t.append(Be(e,"Style","style",e.style??"body",["heading","body","caption"]))),e.type==="filter"&&t.append(Pe(e,"Label","label",e.label,120)),e.type==="button"&&t.append(Pe(e,"Label","label",e.action.label,60)),e.type==="link"&&t.append(Pe(e,"Label","label",e.label,120)),e.type==="image"&&t.append(Pe(e,"Description","alt",e.alt,300));const s=c("div","wk-prop-box");s.append(Ye(e,"Column","x",1,12),Ye(e,"Row","y",1,1e3),Ye(e,"Width","w",1,12),Ye(e,"Height","h",1,50)),t.append(s),t.append(kt(e,"Hide on phones","hideOnPhone",e.hideOnPhone===!0));const p=c("button","wk-btn wk-btn--danger","Delete this component");return p.type="button",p.setAttribute("data-testid","apps-remove"),p.addEventListener("click",()=>{const r=e.id;F=null,le([{op:"component-remove",id:r}])}),t.append(p),t},At=()=>{const e=c("aside","wk-props wk-props--empty");return e.setAttribute("aria-label","Properties"),e.setAttribute("data-testid","apps-properties-empty"),e.append(c("h3","wk-props-title","Properties")),e.append(c("p","wk-muted","Select a component to change it here. Double-click its words to edit them in place.")),e},cn=()=>{const e=c("aside","wk-palette");e.setAttribute("aria-label","Components"),e.append(c("h3","wk-props-title","Components")),e.append(c("p","wk-muted","Drag onto the canvas, or click to add"));const t=c("div","wk-tiles");for(const n of Gt){const i=c("button","wk-tile",n.label);i.type="button",i.setAttribute("data-palette",n.type),i.addEventListener("pointerdown",s=>pn(s,n.type,i)),i.addEventListener("click",s=>{if(s.detail!==0||!B()||Z===null)return;const p=ut[n.type];le([{op:"component-add",page:Z,type:n.type,box:{x:0,y:vt(),w:p.w,h:p.h}}])}),t.append(i)}return e.append(t),e},Y=(e={})=>{const t=L;let n=!1;if(t!==null){const i=B()?oe().find(s=>s.id===t.id):void 0;if(n=i!==void 0&&$t(i,t.prop)===t.before,n&&t.composing()){t.defer();return}n?t.hold():t.drop()}un(e),n&&t!==null&&L===t&&t.place()},un=e=>{const t=f.querySelector(".wk-pages"),n=t?.scrollLeft??0,i=e.focusPage===!0||(t?.contains(document.activeElement)??!1),s=nn();if(s!==null&&Xe.has(s.el)){Ue=e;return}s!==null&&he.set(s.id,s.el.value);const p=document.activeElement instanceof HTMLElement&&f.contains(document.activeElement)?document.activeElement.getAttribute("data-prop"):null;if(at.clear(),ot.clear(),w.reset(),ge(void 0),f.setAttribute("data-mode",B()?"edit":"preview"),f.setAttribute("data-tile",X?"true":"false"),f.setAttribute("data-surface",Me),I===null){f.replaceChildren(c("p","wk-empty",A??"Loading the app…")),se=null;return}const r=[];B()&&r.push(cn());const d=c("main","wk-main"),o=c("nav","wk-pages");o.setAttribute("aria-label","Pages");for(const u of I.pages){const y=c("button",u.id===Z?"wk-page is-on":"wk-page",z(u.title,80));y.type="button",y.setAttribute("aria-current",u.id===Z?"page":"false"),y.addEventListener("click",()=>{Z!==u.id&&(Z=u.id,De(null),Y({focusPage:!0}),Ne())}),o.append(y)}d.append(o),ke=c("p","wk-notice",A??""),ke.setAttribute("data-testid","apps-notice"),ke.setAttribute("aria-live","polite"),ke.hidden=A===null,d.append(ke),$e&&j==="edit"&&d.append(c("p","wk-notice","A chat turn is changing this app: it is read-only until the turn ends")),xe=c("div","wk-grid");const h=oe(),k=[...h].sort((u,y)=>u.box.y-y.box.y||u.box.x-y.box.x);h.forEach((u,y)=>{ot.set(u.id,y),w.place(y,u.box),w.phoneOrder(y,k.indexOf(u),u.hideOnPhone===!0),u.type==="chart"&&u.series.slice(0,12).forEach((C,W)=>w.seriesColour(y,W,C.color));const D=c("section",`wk-cell wk-cell--${u.type} wk-c${y}${u.id===F&&B()?" is-selected":""}`);if(D.setAttribute("data-component",u.id),u.title!==void 0&&u.type!=="text"){const C=c("h3","wk-cell-title",z(u.title,120));B()&&(C.setAttribute("data-inline","title"),C.classList.add("wk-editable"),C.setAttribute("title","Double-click to edit")),D.append(C)}const _=c("div","wk-cell-body");if(at.set(u.id,_),wt(u,_),D.append(_),B()){D.classList.add("is-editable"),D.tabIndex=0,D.setAttribute("aria-label",`${u.type==="chart"?`${u.chart} chart`:u.type} ${z(u.title??u.id,80)}: Enter to select`),D.append(c("span","wk-tag",`${u.type==="chart"?`${u.chart} chart`:u.type}${"data"in u&&u.data!==void 0?` · ${u.data.query}`:""}`));const C=c("span","wk-handle");C.setAttribute("aria-hidden","true"),C.addEventListener("pointerdown",W=>gt(W,u,"resize",C)),D.append(C),D.addEventListener("pointerdown",W=>{W.target.closest("input, select, textarea, button, .wk-handle")===null&&gt(W,u,"move",D)}),D.addEventListener("pointerup",W=>{const ce=W.target.closest?.("button[data-inline]");ce!==null&&W.button===0&&Mt(u.id,ce)})}xe.append(D)}),h.length===0&&xe.append(c("p","wk-empty",B()?"Drag a component here from the palette":"This page is empty")),d.append(xe),r.push(d);const v=B()&&F!==null?h.find(u=>u.id===F):void 0,q=()=>{o.scrollLeft=n;const u=o.querySelector(".is-on");i&&u?.focus({preventScroll:!0}),u?.scrollIntoView?.({block:"nearest",inline:"nearest"})};if(e.keepProps===!0&&v!==void 0&&se!==null&&st===v.id&&se.parentNode===f){for(const u of[...f.childNodes])u!==se&&u.remove();for(const u of r)f.insertBefore(u,se);q(),mt(s);return}se=ye?null:v!==void 0?xt(v):B()?At():null,st=v?.id??null,f.replaceChildren(...r,...se!==null?[se]:[]),q(),mt(s),p!==null&&[...f.querySelectorAll("[data-prop]")].find(u=>u.getAttribute("data-prop")===p)?.focus({preventScroll:!0})},Et=()=>{for(const n of f.querySelectorAll("[data-component]"))n.classList.toggle("is-selected",B()&&n.getAttribute("data-component")===F);const e=B()&&F!==null?oe().find(n=>n.id===F):void 0,t=ye?null:e!==void 0?xt(e):B()?At():null;se!==null&&t!==null&&se.parentNode===f?se.replaceWith(t):(se?.remove(),t!==null&&f.append(t)),se=t,st=e?.id??null},Mt=(e,t)=>{const n=t?.getAttribute("data-inline")??null,i=Date.now();n!==null&&t!==null&&R!==null&&R.id===e&&R.prop===n&&i-R.at<Xt?(R=null,t.isConnected&&Lt(e,t)):R=n!==null?{id:e,prop:n,at:i}:null},$t=(e,t)=>{if(t==="title")return e.title??"";if(t==="text"&&e.type==="text")return e.text;if(t==="label"){if(e.type==="button")return e.action.label;if(e.type==="link")return e.label;if(e.type==="filter")return e.label??""}return""},Lt=(e,t)=>{const n=oe().find(u=>u.id===e),i=t.getAttribute("data-inline");if(n===void 0||i===null||!B()||L!==null)return;const s=$t(n,i),p=i==="text",r=p?c("textarea","wk-inline-input wk-inline-input--multi"):c("input","wk-inline-input");r.value=s,r.maxLength=p?4e3:n.type==="button"?60:120,r.setAttribute("data-testid","apps-inline"),r.setAttribute("aria-label",`Edit the ${i==="text"?"text":i}`),t.replaceWith(r),r.closest("[data-component]")?.classList.add("is-inline"),r.focus(),r.select();let d=!1,o=!1,h=!1,k=!1,v=[null,null,"none"];const q={id:e,prop:i,before:s,drop:()=>{d=!0,h=!1,L===q&&(L=null)},hold:()=>{h=!0,v=[r.selectionStart,r.selectionEnd,r.selectionDirection??"none"]},composing:()=>o,defer:()=>{k=!0},place:()=>{const u=[...f.querySelectorAll("[data-component]")].find(D=>D.getAttribute("data-component")===e),y=u===void 0?void 0:[...u.querySelectorAll("[data-inline]")].find(D=>D.getAttribute("data-inline")===i);if(y===void 0){q.drop();return}y.replaceWith(r),u.classList.add("is-inline"),r.focus(),v[0]!==null&&v[1]!==null&&r.setSelectionRange(v[0],v[1],v[2]),h=!1}};L=q;const J=u=>{d||(q.drop(),u&&r.value!==s?le([{op:"component-set",id:e,prop:i,value:r.value}]):Y())};r.addEventListener("compositionstart",()=>{o=!0}),r.addEventListener("compositionend",()=>{o=!1,k&&(k=!1,d||Y())}),r.addEventListener("keydown",u=>{const y=u;if(!(o||y.isComposing||y.keyCode===229)){if(y.key==="Escape"){y.preventDefault(),y.stopPropagation(),J(!1);return}y.key==="Enter"&&!(p&&y.shiftKey)&&(y.preventDefault(),y.stopPropagation(),J(!0))}}),r.addEventListener("blur",()=>{h||(r.isConnected?J(!0):q.drop())})};f.addEventListener("dblclick",e=>{if(!B()||L!==null)return;const n=((typeof document.elementFromPoint=="function"?document.elementFromPoint(e.clientX,e.clientY):null)??e.target)?.closest("[data-inline]"),i=n?.closest("[data-component]");n==null||i===null||i===void 0||(e.preventDefault(),Lt(i.getAttribute("data-component"),n))});function St(e){if($===null||I===null)return;const t=e.target?.closest?.(".wk-cell.is-editable");if(t!==null&&(e.key==="Enter"||e.key===" ")&&e.target===t){e.preventDefault();const s=t.getAttribute("data-component");s!==null&&(De(s),Et(),f.querySelector(".wk-props input, .wk-props select")?.focus());return}const n=e.target?.closest("input, textarea, select")!=null;if((e.metaKey||e.ctrlKey)&&!e.altKey&&e.key.toLowerCase()==="z"&&!n&&B()){e.preventDefault(),M("app.history",{move:e.shiftKey?"redo":"undo",base:G}).then(s=>{s.ok||(A=s.message,s.code==="head_moved"?pe():Y())});return}if((e.key==="Delete"||e.key==="Backspace")&&!n&&B()&&F!==null){e.preventDefault();const s=F;De(null),le([{op:"component-remove",id:s}]);return}e.key==="Escape"&&F!==null&&!n&&(De(null),Y())}document.addEventListener("keydown",St),f.append(c("p","wk-empty","Loading the app…")),l===void 0?Dt(a.editor,a.surfaces):ve(l.port,l.hello)}return ue.boot=Vt,Object.defineProperty(ue,Symbol.toStringTag,{value:"Module"}),ue})({});
@@ -1 +1 @@
1
- import{r as c,a as t,c as k,j as y,f as m}from"./index-pq0QeOmo.js";k.use(m);const w={source:"--status-gate",table:"--accent-dim",shape:"--accent",code:"--status-run",repo:"--ink-muted",knowledge:"--ink-muted",tracker:"--ink-high",project:"--kn-project",issue:"--kn-issue",run:"--kn-run",pr:"--kn-pr"},b={source:"round-rectangle",table:"rectangle",shape:"diamond",code:"ellipse",repo:"hexagon",knowledge:"triangle",tracker:"tag",project:"barrel",issue:"round-pentagon",run:"cut-rectangle",pr:"rhomboid"},f={source:34,table:24,shape:26,code:22,repo:30,knowledge:18,tracker:30,project:36,issue:22,run:24,pr:24},p=new Set(["describes","joins","governed_by","measures","tracked_in","addresses","closes"]);function E({nodes:l,edges:i,onSelect:d}){const n=c.useRef(null),a=c.useRef(d);return a.current=d,c.useEffect(()=>{if(n.current===null)return;const s=new Map(l.map((e,r)=>[e.key,`n${r}`])),u=t("--ink-high"),g=t("--ink-dim"),h=[...l.map(e=>({group:"nodes",data:{id:s.get(e.key),label:e.label,color:t(w[e.kind]),shape:b[e.kind],size:f[e.kind],kind:e.kind,raw:e}})),...i.filter(e=>s.has(e.from)&&s.has(e.to)).map((e,r)=>({group:"edges",data:{id:`e${r}`,source:s.get(e.from),target:s.get(e.to),rel:e.rel,label:p.has(e.rel)?e.rel.replace("_"," "):""},classes:p.has(e.rel)?`typed rel-${e.rel}`:"quiet"}))],o=k({container:n.current,elements:h,style:[{selector:"node",style:{"background-color":"data(color)",shape:"data(shape)",width:"data(size)",height:"data(size)",label:"data(label)","font-size":11,"font-family":"ui-sans-serif, system-ui, sans-serif",color:u,"text-valign":"bottom","text-halign":"center","text-margin-y":4,"text-max-width":"140px","text-wrap":"ellipsis","text-background-color":t("--surface-base"),"text-background-opacity":.85,"text-background-padding":"2px"}},{selector:"node:selected",style:{"border-width":3,"border-color":t("--accent")}},{selector:"edge",style:{width:1,"curve-style":"bezier","line-color":g,"target-arrow-color":g,"target-arrow-shape":"none",opacity:.45}},{selector:"edge.typed",style:{width:2,opacity:.95,"target-arrow-shape":"triangle","arrow-scale":.8,label:"data(label)","font-size":10,color:u,"text-rotation":"autorotate","text-background-color":t("--surface-base"),"text-background-opacity":.9,"text-background-padding":"2px"}},{selector:"edge.rel-joins",style:{"line-color":t("--accent"),"target-arrow-color":t("--accent"),"line-style":"solid"}},{selector:"edge.rel-describes",style:{"line-color":t("--status-run"),"target-arrow-color":t("--status-run"),"line-style":"dashed"}},{selector:"edge.rel-governed_by",style:{"line-color":t("--status-gate"),"target-arrow-color":t("--status-gate"),"line-style":"dotted",width:3}},{selector:"edge.rel-tracked_in",style:{"line-color":t("--ink-muted"),"target-arrow-color":t("--ink-muted"),"line-style":"solid"}},{selector:"edge.rel-addresses, edge.rel-closes",style:{"line-color":t("--status-warn"),"target-arrow-color":t("--status-warn"),"line-style":"dashed"}}],layout:{name:"fcose",animate:!1,randomize:!0,quality:"default",idealEdgeLength:140,nodeRepulsion:2e4,numIter:2500,nodeSeparation:100},wheelSensitivity:.3,minZoom:.2,maxZoom:3});return o.on("tap","node",e=>{var r;return(r=a.current)==null?void 0:r.call(a,e.target.data("raw"))}),o.on("tap",e=>{var r;e.target===o&&((r=a.current)==null||r.call(a,null))}),o.ready(()=>{o.destroyed()||o.fit(void 0,32)}),()=>o.destroy()},[l,i]),y.jsx("div",{ref:n,className:"wk-know-graph","data-testid":"knowledge-graph-canvas",role:"img","aria-label":"The knowledge map: sources, tables, repositories, code, data shapes, and trackers with the projects and repositories they are tracked in"})}export{E as KnowledgeGraph,p as NAMED_RELS};
1
+ import{r as c,a as t,c as k,j as y,f as m}from"./index-CrNY3d06.js";k.use(m);const w={source:"--status-gate",table:"--accent-dim",shape:"--accent",code:"--status-run",repo:"--ink-muted",knowledge:"--ink-muted",tracker:"--ink-high",project:"--kn-project",issue:"--kn-issue",run:"--kn-run",pr:"--kn-pr"},b={source:"round-rectangle",table:"rectangle",shape:"diamond",code:"ellipse",repo:"hexagon",knowledge:"triangle",tracker:"tag",project:"barrel",issue:"round-pentagon",run:"cut-rectangle",pr:"rhomboid"},f={source:34,table:24,shape:26,code:22,repo:30,knowledge:18,tracker:30,project:36,issue:22,run:24,pr:24},p=new Set(["describes","joins","governed_by","measures","tracked_in","addresses","closes"]);function E({nodes:l,edges:i,onSelect:d}){const n=c.useRef(null),a=c.useRef(d);return a.current=d,c.useEffect(()=>{if(n.current===null)return;const s=new Map(l.map((e,r)=>[e.key,`n${r}`])),u=t("--ink-high"),g=t("--ink-dim"),h=[...l.map(e=>({group:"nodes",data:{id:s.get(e.key),label:e.label,color:t(w[e.kind]),shape:b[e.kind],size:f[e.kind],kind:e.kind,raw:e}})),...i.filter(e=>s.has(e.from)&&s.has(e.to)).map((e,r)=>({group:"edges",data:{id:`e${r}`,source:s.get(e.from),target:s.get(e.to),rel:e.rel,label:p.has(e.rel)?e.rel.replace("_"," "):""},classes:p.has(e.rel)?`typed rel-${e.rel}`:"quiet"}))],o=k({container:n.current,elements:h,style:[{selector:"node",style:{"background-color":"data(color)",shape:"data(shape)",width:"data(size)",height:"data(size)",label:"data(label)","font-size":11,"font-family":"ui-sans-serif, system-ui, sans-serif",color:u,"text-valign":"bottom","text-halign":"center","text-margin-y":4,"text-max-width":"140px","text-wrap":"ellipsis","text-background-color":t("--surface-base"),"text-background-opacity":.85,"text-background-padding":"2px"}},{selector:"node:selected",style:{"border-width":3,"border-color":t("--accent")}},{selector:"edge",style:{width:1,"curve-style":"bezier","line-color":g,"target-arrow-color":g,"target-arrow-shape":"none",opacity:.45}},{selector:"edge.typed",style:{width:2,opacity:.95,"target-arrow-shape":"triangle","arrow-scale":.8,label:"data(label)","font-size":10,color:u,"text-rotation":"autorotate","text-background-color":t("--surface-base"),"text-background-opacity":.9,"text-background-padding":"2px"}},{selector:"edge.rel-joins",style:{"line-color":t("--accent"),"target-arrow-color":t("--accent"),"line-style":"solid"}},{selector:"edge.rel-describes",style:{"line-color":t("--status-run"),"target-arrow-color":t("--status-run"),"line-style":"dashed"}},{selector:"edge.rel-governed_by",style:{"line-color":t("--status-gate"),"target-arrow-color":t("--status-gate"),"line-style":"dotted",width:3}},{selector:"edge.rel-tracked_in",style:{"line-color":t("--ink-muted"),"target-arrow-color":t("--ink-muted"),"line-style":"solid"}},{selector:"edge.rel-addresses, edge.rel-closes",style:{"line-color":t("--status-warn"),"target-arrow-color":t("--status-warn"),"line-style":"dashed"}}],layout:{name:"fcose",animate:!1,randomize:!0,quality:"default",idealEdgeLength:140,nodeRepulsion:2e4,numIter:2500,nodeSeparation:100},wheelSensitivity:.3,minZoom:.2,maxZoom:3});return o.on("tap","node",e=>{var r;return(r=a.current)==null?void 0:r.call(a,e.target.data("raw"))}),o.on("tap",e=>{var r;e.target===o&&((r=a.current)==null||r.call(a,null))}),o.ready(()=>{o.destroyed()||o.fit(void 0,32)}),()=>o.destroy()},[l,i]),y.jsx("div",{ref:n,className:"wk-know-graph","data-testid":"knowledge-graph-canvas",role:"img","aria-label":"The knowledge map: sources, tables, repositories, code, data shapes, and trackers with the projects and repositories they are tracked in"})}export{E as KnowledgeGraph,p as NAMED_RELS};