@exponential_app/eui-element 0.15.3 → 0.15.4

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.
@@ -20,7 +20,7 @@ Source of truth: packages/exponential-ui/themes/*.theme.json, themes/exponential
20
20
  `);if(i<0)return n;this.skipping=!1,r=i+1}let o=t.indexOf(`
21
21
  `,r);for(;o>=0;){const i=t.slice(r,o),s=this.bytes+Ec(i)>Rr;n.push(s?null:this.parts.length?this.parts.join("")+i:i),this.parts=[],this.bytes=0,r=o+1,o=t.indexOf(`
22
22
  `,r)}if(r<t.length){const i=t.slice(r);this.parts.push(i),this.bytes+=Ec(i)}return this.bytes>Rr&&(n.push(null),this.parts=[],this.bytes=0,this.skipping=!0),n}end(){const t=this.skipping,n=this.parts.join("");return this.parts=[],this.bytes=0,this.skipping=!1,t?null:n}}const Ng=(e,t)=>({at:e,message:`${t} ${e}: ${$n.messageBytes}`});class Lg{lines=new zg;line=0;push(t){const n={messages:[],issues:[]};for(const r of this.lines.push(t))this.line+=1,r===null?n.issues.push(Ng(this.line,"line")):Dp(r,this.line,n);return n}end(){const t={messages:[],issues:[]},n=this.lines.end();return n!==null&&n.trim()&&(this.line+=1,Dp(n,this.line,t)),t}}function jg(e){const t=e.trim();if(t.startsWith("["))try{const i=JSON.parse(t);if(Array.isArray(i))return{messages:i,issues:[]}}catch{}const n=new Lg,r=n.push(e),o=n.end();return{messages:[...r.messages,...o.messages],issues:[...r.issues,...o.issues]}}class cS{retryMs;lines=new zg;data=[];dataBytes=0;oversized=!1;event="";count=0;push(t){const n={messages:[],issues:[]};for(const r of this.lines.push(t))r===null?this.dropData():this.line(r.endsWith("\r")?r.slice(0,-1):r,n);return n}end(){const t={messages:[],issues:[]},n=this.lines.end();return n===null?this.dropData():n&&this.line(n,t),this.dispatch(t),t}dropData(){this.data=[],this.dataBytes=0,this.oversized=!0}line(t,n){if(t==="")return this.dispatch(n);if(t.startsWith(":"))return;const r=t.indexOf(":"),o=r<0?t:t.slice(0,r);let i=r<0?"":t.slice(r+1);if(i.startsWith(" ")&&(i=i.slice(1)),o==="data"){if(this.oversized)return;if(this.dataBytes+=Ec(i)+1,this.dataBytes>Rr)return this.dropData();this.data.push(i)}else o==="event"?this.event=i:o==="retry"&&/^\d+$/.test(i)&&(this.retryMs=Number(i))}dispatch(t){if(this.dataBytes=0,this.oversized){this.oversized=!1,this.count+=1,this.data=[],this.event="",t.issues.push(Ng(this.count,"event"));return}if(!this.data.length){this.event="";return}this.count+=1;const n=this.event||"message",r=this.data.join(`
23
- `);if(this.data=[],this.event="",!U2.includes(n))return;const o=jg(r);t.messages.push(...o.messages),o.issues.length&&t.issues.push({at:this.count,message:`event ${this.count} is not JSON`})}}const Ic=/^[a-z][a-z0-9_]{0,31}$/,uS=["id","createdAt","updatedAt","createdBy","authorId","author"],Rp=["string","number","integer","boolean","array"],Fp=["string","number","integer","boolean"],ws=["date","date-time","time","attachment"],dS=/^\/api\/attachments\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/,Zt=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Fl=e=>Array.isArray(e)&&e.every(t=>typeof t=="string");function Bg(e,t){const n=[];if(!Zt(e)||e.type!=="object"||!Zt(e.properties))return[{path:t,message:'a record schema is {type: "object", properties}'}];for(const r of Object.keys(e.properties).sort()){const o=e.properties[r],i=`${t}/properties/${r}`;if(uS.includes(r)&&n.push({path:i,message:`${r} is a reserved record key`}),!Zt(o)||typeof o.type!="string"||!Rp.includes(o.type)){n.push({path:i,message:`a field is {type: ${Rp.join("|")}}`});continue}if(o.enum!==void 0&&(!Fl(o.enum)||!o.enum.length||o.type!=="string")&&n.push({path:`${i}/enum`,message:"enum is a non-empty list of strings on a string field"}),o.type==="array"){const s=o.items;!Zt(s)||typeof s.type!="string"||!Fp.includes(s.type)?n.push({path:`${i}/items`,message:`items is {type: ${Fp.join("|")}}`}):(s.enum!==void 0&&(!Fl(s.enum)||!s.enum.length||s.type!=="string")&&n.push({path:`${i}/items/enum`,message:"enum is a non-empty list of strings on a string item"}),s.format!==void 0&&(typeof s.format!="string"||!ws.includes(s.format)||s.type!=="string")&&n.push({path:`${i}/items/format`,message:`format is ${ws.join("|")} on a string item`}))}else o.items!==void 0&&n.push({path:`${i}/items`,message:"items belongs to an array field"});o.format!==void 0&&(typeof o.format!="string"||!ws.includes(o.format)||o.type!=="string")&&n.push({path:`${i}/format`,message:`format is ${ws.join("|")} on a string field`});for(const s of["maxLength","minimum","maximum"])o[s]!==void 0&&typeof o[s]!="number"&&n.push({path:`${i}/${s}`,message:`${s} is a number`})}return e.required!==void 0&&(Fl(e.required)?e.required.forEach((r,o)=>{Object.prototype.hasOwnProperty.call(e.properties,r)||n.push({path:`${t}/required/${o}`,message:`${r} is not a declared field`})}):n.push({path:`${t}/required`,message:"required is a list of field names"})),e.additionalProperties!==void 0&&typeof e.additionalProperties!="boolean"&&n.push({path:`${t}/additionalProperties`,message:"additionalProperties is a boolean"}),n}const pS=/^\d{4}-\d{2}-\d{2}$/,fS=/^\d{2}:\d{2}(:\d{2})?$/,hS=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/;function zp(e,t,n,r){const o=[];switch(e){case"string":return typeof t!="string"?[{path:n,message:"a string"}]:(r.enum&&!r.enum.includes(t)&&o.push({path:n,message:`one of ${r.enum.join("|")}`}),r.maxLength!==void 0&&[...t].length>r.maxLength&&o.push({path:n,message:`at most ${r.maxLength} characters`}),r.format==="date"&&!pS.test(t)&&o.push({path:n,message:"a date (YYYY-MM-DD)"}),r.format==="date-time"&&!hS.test(t)&&o.push({path:n,message:"a date-time (ISO 8601)"}),r.format==="time"&&!fS.test(t)&&o.push({path:n,message:"a time (HH:MM)"}),r.format==="attachment"&&!dS.test(t)&&o.push({path:n,message:"an attachment (/api/attachments/<id>)"}),o);case"number":case"integer":return typeof t!="number"||!Number.isFinite(t)?[{path:n,message:"a number"}]:e==="integer"&&!Number.isInteger(t)?[{path:n,message:"an integer"}]:(r.minimum!==void 0&&t<r.minimum&&o.push({path:n,message:`at least ${r.minimum}`}),r.maximum!==void 0&&t>r.maximum&&o.push({path:n,message:`at most ${r.maximum}`}),o);case"boolean":return typeof t=="boolean"?[]:[{path:n,message:"a boolean"}];default:return[]}}function Di(e,t){if(!Zt(t))return[{path:"",message:"a record is an object"}];const n=[],r=new Set(e.required??[]);for(const o of Object.keys(e.properties).sort()){const i=e.properties[o],s=t[o];if(s==null){r.has(o)&&n.push({path:`/${o}`,message:"required"});continue}if(i.type==="array"){if(!Array.isArray(s)){n.push({path:`/${o}`,message:"a list"});continue}i.maxLength!==void 0&&s.length>i.maxLength&&n.push({path:`/${o}`,message:`at most ${i.maxLength} items`});const a=i.items??{type:"string"};s.forEach((l,c)=>n.push(...zp(a.type,l,`/${o}/${c}`,{enum:a.enum,format:a.format})));continue}n.push(...zp(i.type,s,`/${o}`,i))}if(e.additionalProperties!==!0)for(const o of Object.keys(t).sort())Object.prototype.hasOwnProperty.call(e.properties,o)||n.push({path:`/${o}`,message:"not in the schema"});return n}function mS(e,t,n){if(!Zt(e)||e.refs===void 0)return[];const r=e.refs;if(!Zt(r))return[{path:`${t}/refs`,message:'refs is {field: {kind} | "issue" | "member"}'}];const o=Zt(e.schema)&&Zt(e.schema.properties)?e.schema.properties:{},i=[];for(const s of Object.keys(r).sort()){const a=`${t}/refs/${s}`,l=r[s],c=Object.prototype.hasOwnProperty.call(o,s)?o[s]:void 0;if(Zt(c)?c.type!=="string"&&i.push({path:a,message:"a ref is a string field"}):i.push({path:a,message:`${s} is not a declared field`}),!(l==="issue"||l==="member")){if(!Zt(l)||Object.keys(l).length!==1||typeof l.kind!="string"||!l.kind){i.push({path:a,message:'a ref is {kind}, "issue" or "member"'});continue}(!Zt(n)||!Object.prototype.hasOwnProperty.call(n,l.kind))&&i.push({path:`${a}/kind`,message:`records:${l.kind} names no declared kind`})}}return i}const Wg=["read","create","update","delete"],Hg=["member","author","owners"],gS={read:"member",create:"member",update:"author",delete:"author"},ks={none:"You have no access to this app",readOnly:"You have read-only access to this app",author:{read:"Only the record's author or a team owner can read it",update:"Only the record's author or a team owner can change it",delete:"Only the record's author or a team owner can change it"},owners:{read:"Only team owners can read these records",create:"Only team owners can add these records",update:"Only team owners can change these records",delete:"Only team owners can change these records"}},Pc=e=>!!e&&typeof e=="object"&&!Array.isArray(e),qg=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);function yS(e,t){if(!Pc(e))return[{path:t,message:"policy is {read?, create?, update?, delete?}"}];const n=[];for(const r of Object.keys(e).sort()){const o=e[r];Wg.includes(r)?r==="create"&&o==="author"?n.push({path:`${t}/create`,message:"create is member or owners: a new record has no author yet"}):(typeof o!="string"||!Hg.includes(o))&&n.push({path:`${t}/${r}`,message:`${r} is member, author or owners`}):n.push({path:`${t}/${r}`,message:`unknown policy op ${r}: read, create, update or delete`})}return n}function Dc(e){const t={...gS},n=Pc(e)&&Pc(e.policy)?e.policy:null;if(!n)return t;for(const r of Wg){const o=qg(n,r)?n[r]:void 0;typeof o=="string"&&Hg.includes(o)&&!(r==="create"&&o==="author")&&(t[r]=o)}return t}const Ug=e=>e?.authorId??e?.createdBy??null;function Rc(e,t,n,r){const o=n.access??"write";if(n.id===null||n.role===null||o==="none")return ks.none;if(o==="read"&&t!=="read")return ks.readOnly;if(n.role==="owner")return null;const i=e[t];if(i==="member")return null;if(i==="owners"||t==="create")return ks.owners[t];const s=Ug(r);return s!==null&&s===n.id?null:ks.author[t]}const bS=(e,t,n,r)=>Rc(e,t,n,r)===null;function Np(e,t,n){const r=new Map,o=i=>{let s=r.get(i);return s||r.set(i,s=Dc(t&&qg(t,i)?t[i]:void 0)),s};return e.filter(i=>bS(o(i.kind),"read",n,i))}const Ns="transitions",vS=["member","author","owners"],$S=["field","initial","from","who"],ga="->",Dt=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Er=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Fc=e=>Array.isArray(e)&&e.every(t=>typeof t=="string");function xS(e){const t=Dt(e)?e.transitions:void 0;if(!Dt(t)||typeof t.field!="string"||!t.field||!Dt(t.from))return null;const n={};for(const o of Object.keys(t.from))Fc(t.from[o])&&(n[o]=t.from[o]);const r={};if(Dt(t.who))for(const o of Object.keys(t.who))typeof t.who[o]=="string"&&(r[o]=t.who[o]);return{field:t.field,...Fc(t.initial)?{initial:t.initial}:{},from:n,who:r}}function wS(e){if(e.initial)return[...e.initial];const t=Object.keys(e.from).sort(),n=new Set(Object.values(e.from).flat()),r=t.filter(o=>!n.has(o));return r.length?r:t}const Vg=(e,t)=>{const n=e?.[t];return typeof n=="string"&&n!==""?n:null};function kS(e,t,n){const r=e.who??{};return Er(r,`${t}${ga}${n}`)?r[`${t}${ga}${n}`]:Er(r,n)?r[n]:"member"}function SS(e,t,n,r,o,i){if(e==="member"||r.role==="owner")return null;if(e==="owners")return`Only team owners can move ${t} to ${n}`;if(e==="author"){const s=Ug(i);return s!==null&&s===r.id?null:`Only the record's author or a team owner can move ${t} to ${n}`}if(e.startsWith("role:")){const s=e.slice(5),a=Vg(o,s);return a!==null&&a===r.id?null:`Only the record's ${s} or a team owner can move ${t} to ${n}`}return`Nobody can move ${t} to ${n}`}function CS(e,t,n,r){if(!e)return[];const o=Vg(t,e.field);if(o===null)return wS(e);const i=Er(e.from,o)?e.from[o]:[];return n?i.filter(s=>SS(kS(e,o,s),e.field,s,n,t,r)===null):[...i]}function AS(e,t,n){if(!Dt(e)||e.transitions===void 0)return[];const r=e.transitions,o=`${t}/transitions`;if(!Dt(r))return[{path:o,message:"transitions is {field, from, initial?, who?}"}];const i=[];for(const p of Object.keys(r).sort())$S.includes(p)||i.push({path:`${o}/${p}`,message:`unknown key ${p}`});const s=Dt(e.schema)&&Dt(e.schema.properties)?e.schema.properties:{},a=typeof r.field=="string"?r.field:null,l=a!==null&&Er(s,a)?s[a]:void 0;let c=null;a===null||!a?i.push({path:`${o}/field`,message:"field is the name of an enum field"}):Dt(l)?l.type!=="string"||!Fc(l.enum)?i.push({path:`${o}/field`,message:`${a} is not an enum field`}):c=l.enum:i.push({path:`${o}/field`,message:`${a} is not a declared field`});const u=(p,h)=>{typeof p!="string"?i.push({path:h,message:"a state is a string"}):c&&!c.includes(p)&&i.push({path:h,message:`${p} is not a state of ${a}`})};if(!Dt(r.from))i.push({path:`${o}/from`,message:"from is {state: [next state…]}"});else for(const p of Object.keys(r.from).sort()){u(p,`${o}/from/${p}`);const h=r.from[p];Array.isArray(h)?h.forEach((f,y)=>u(f,`${o}/from/${p}/${y}`)):i.push({path:`${o}/from/${p}`,message:"the next states are a list"})}if(r.initial!==void 0&&(!Array.isArray(r.initial)||!r.initial.length?i.push({path:`${o}/initial`,message:"initial is a non-empty list of states"}):r.initial.forEach((p,h)=>u(p,`${o}/initial/${h}`))),r.who!==void 0)if(!Dt(r.who))i.push({path:`${o}/who`,message:'who is {"a->b" | state: level}'});else{const p=Dt(e.refs)?e.refs:{};for(const h of Object.keys(r.who).sort()){const f=`${o}/who/${h}`,y=h.indexOf(ga);if(y>=0){const v=h.slice(0,y),m=h.slice(y+ga.length);Dt(r.from)&&Array.isArray(r.from[v])&&r.from[v].includes(m)||i.push({path:f,message:`${v} → ${m} is not a declared transition`})}else u(h,f);const g=r.who[h];if(typeof g=="string"&&g.startsWith("role:")){const v=g.slice(5);Er(p,v)&&p[v]==="member"||i.push({path:f,message:`${g}: ${v} is not a member ref of ${n}`})}else(typeof g!="string"||!vS.includes(g))&&i.push({path:f,message:"a level is member, author, owners or role:<field>"})}}const d=Dt(e.computed)?e.computed:{};return(Er(s,Ns)||Er(d,Ns))&&i.push({path:o,message:`a kind with transitions declares no field ${Ns} (its rows carry the next states there)`}),i}const Lp=64,jp=32,Kg=["rename","default","drop","map","renameKind"],lr=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Bp=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),_S=/^(0|[1-9]\d*|x|\*)(?:\.(0|[1-9]\d*|x|\*))?(?:\.(0|[1-9]\d*|x|\*))?$/,OS=/^(>=|<=|>|<|=|\^|~)?(.+)$/,TS=/^(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?(?:\.(0|[1-9]\d*))?$/,MS=e=>{const t=TS.exec(e);return t?[Number(t[1]),Number(t[2]??0),Number(t[3]??0)]:null},ES=(e,t)=>e[0]-t[0]||e[1]-t[1]||e[2]-t[2];function IS(e,t){const n=OS.exec(e);if(!n)return null;const r=n[1]??"",o=n[2];if(r===""||r==="="){const a=_S.exec(o);return a?[a[1],a[2],a[3]].every((c,u)=>c===void 0||c==="x"||c==="*"||Number(c)===t[u]):null}const i=MS(o);if(!i)return null;const s=ES(t,i);return r===">="?s>=0:r===">"?s>0:r==="<="?s<=0:r==="<"?s<0:r==="~"?t[0]===i[0]&&t[1]===i[1]&&s>=0:i[0]>0?t[0]===i[0]&&s>=0:i[1]>0?t[0]===0&&t[1]===i[1]&&s>=0:s===0}function PS(e){if(typeof e!="string"||!e.trim())return null;const t=e.split("||").map(n=>n.trim().split(/\s+/).filter(Boolean));if(t.some(n=>!n.length))return null;for(const n of t)for(const r of n)if(IS(r,[0,0,0])===null)return null;return t}const DS=e=>PS(e)!==null,RS=e=>{if(!lr(e))return null;const t=Object.keys(e);return t.length===1&&Kg.includes(t[0])?t[0]:null};function FS(e){if(!lr(e)||e.migrations===void 0)return[];const t=e.migrations;if(!Array.isArray(t))return[{path:"/migrations",message:"migrations is a list of {from, kind, ops}"}];const n=[];t.length>Lp&&n.push({path:"/migrations",message:`at most ${Lp} migrations`});const r=lr(e.records)?e.records:{},o=i=>typeof i=="string"&&i.length>0;return t.forEach((i,s)=>{const a=`/migrations/${s}`;if(!lr(i))return void n.push({path:a,message:"a migration is {from, kind, ops}"});for(const c of Object.keys(i).sort())["from","kind","ops"].includes(c)||n.push({path:`${a}/${c}`,message:`unknown key ${c}`});(typeof i.from!="string"||!DS(i.from))&&n.push({path:`${a}/from`,message:"from is a version or a range (1.2.3, 1.x, ^1.2.0, >=1.0.0 <2.0.0)"});let l=typeof i.kind=="string"&&Ic.test(i.kind)?i.kind:null;if(l===null&&n.push({path:`${a}/kind`,message:"kind is a kind name"}),!Array.isArray(i.ops))return void n.push({path:`${a}/ops`,message:"ops is a list"});i.ops.length>jp&&n.push({path:`${a}/ops`,message:`at most ${jp} ops`}),i.ops.forEach((c,u)=>{const d=`${a}/ops/${u}`,p=RS(c);if(!p)return void n.push({path:d,message:`an op is one of ${Kg.join(", ")}`});const h=c[p],f=y=>n.push({path:`${d}/${p}`,message:`${p} is ${y}`});if(p==="rename"&&!(lr(h)&&o(h.from)&&o(h.to)&&Object.keys(h).length===2))f("{from, to}");else if(p==="default"&&!(lr(h)&&o(h.field)&&Bp(h,"value")&&Object.keys(h).length===2))f("{field, value}");else if(p==="drop"&&!(lr(h)&&o(h.field)&&Object.keys(h).length===1))f("{field}");else if(p==="map")if(!(lr(h)&&o(h.field)&&typeof h.expr=="string"&&Object.keys(h).length===2))f("{field, expr}");else{const y=Wo(h.expr);"error"in y&&n.push({path:`${d}/map/expr`,message:y.error})}else p==="renameKind"&&(typeof h!="string"||!Ic.test(h)?f("a kind name"):l=h)}),l!==null&&!Bp(r,l)&&n.push({path:`${a}/kind`,message:`the migration ends in ${l}, which the package does not declare`})}),n}const Gg=3,Yg=8,Xg=12,Zg=52,zc=["week","month","quarter"],zS=["chart1","chart2","chart3","chart4","chart5","chart6","chart7","chart8"],NS=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],Wp=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],zr=["January","February","March","April","May","June","July","August","September","October","November","December"];function dr(e){const t=Xi(e);return t?bn(t.y,t.m,t.d):null}function LS(e,t){const n=dr(e);if(n===null)return null;const r=t===null?null:dr(t);return{start:n,end:r!==null&&r>=n?r:n}}const Tt=e=>Zi(vt(e)),Jg=e=>((e+3)%7+7)%7,Yu=e=>e-Jg(e);function jS(e){const t=[...new Set(e.filter(r=>r!==""&&!/^[1-8]$/.test(r)))].sort((r,o)=>r<o?-1:r>o?1:0),n=new Map(t.map((r,o)=>[r,o]));return e.map(r=>/^[1-8]$/.test(r)?`chart${r}`:r===""?"chart1":zS[n.get(r)%8])}function Qg(e,t,n){return e.filter(r=>r.end>=t&&r.start<=n).sort((r,o)=>Math.max(r.start,t)-Math.max(o.start,t)||Math.min(o.end,n)-Math.max(o.start,t)-(Math.min(r.end,n)-Math.max(r.start,t))||r.order-o.order)}function ey(e,t,n,r){for(let o=0;o<r;o++){const i=e[o]??=[];let s=!0;for(let a=t;a<=n;a++)i[a]&&(s=!1);if(s){for(let a=t;a<=n;a++)i[a]=!0;return o}}return null}function ty(e,t,n){const r=e+6,o=Qg(t,e,r),i=[],s=[0,0,0,0,0,0,0],a=[];for(const c of o){const u=Math.max(c.start,e)-e,d=Math.min(c.end,r)-e,p=ey(i,u,d,n.lanes);if(p===null){for(let h=u;h<=d;h++)s[h]+=1;continue}a.push({id:c.id,col:u+1,span:d-u+1,lane:p,contL:c.start<e,contR:c.end>r,tone:c.tone,more:0,row:c.value})}s.forEach((c,u)=>{c>0&&a.push({id:`more:${Tt(e+u)}`,col:u+1,span:1,lane:n.lanes,contL:!1,contR:!1,tone:null,more:c,row:null})});const l=[];for(let c=0;c<7;c++){const u=e+c,d=vt(u),p=o.filter(h=>h.start<=u&&h.end>=u);l.push({date:Zi(d),day:d.d,weekday:Wp[c],initial:Wp[c].slice(0,1),inMonth:n.month===null||d.m===n.month,weekend:c>=5,today:u===n.today,selected:u===n.selected,total:p.length,dots:p.slice(0,3).map(h=>({tone:h.tone}))})}return{key:Tt(e),days:l,segments:a}}function ny(e,t){const n=vt(e),r=vt(t),o=`${r.d} ${zr[r.m-1]} ${r.y}`;return n.y!==r.y?`${n.d} ${zr[n.m-1]} ${n.y} – ${o}`:n.m!==r.m?`${n.d} ${zr[n.m-1]} – ${o}`:`${n.d} – ${o}`}function BS(e){const t=vt(e);return`${NS[Jg(e)]}, ${t.d} ${zr[t.m-1]}`}function WS(e,t,n,r,o){const i=bn(e,t,1),s=bn(e,t,n),a=o.day===null?null:dr(o.day),l=a!==null&&a>=i&&a<=s?a:o.today>=i&&o.today<=s?o.today:i,c=[];for(let d=Yu(i);d<=s;d+=7)c.push(ty(d,r,{lanes:o.lanes,today:o.today,selected:l,month:t}));const u=Qg(r,l,l).map(d=>({id:d.id,tone:d.tone,start:Tt(d.start),end:Tt(d.end),days:d.end-d.start+1,row:d.value}));return{weeks:c,day:Tt(l),agenda:{date:Tt(l),label:BS(l),count:u.length,items:u}}}function HS(e,t,n){const r=Yu(e),o=ty(r,t,{lanes:n.lanes,today:n.today,selected:null,month:null});return{key:o.key,label:ny(r,r+6),prev:Tt(r-7),next:Tt(r+7),today:Tt(n.today),days:o.days,segments:o.segments}}function Nc(e,t){if(t==="week")return Yu(e);const n=vt(e);return bn(n.y,t==="month"?n.m:Math.floor((n.m-1)/3)*3+1,1)}function Lc(e,t,n){if(t==="week")return e+7*n;const r=vt(e),o=r.y*12+(r.m-1)+n*(t==="month"?1:3);return bn(Math.floor(o/12),(o%12+12)%12+1,1)}function qS(e,t){const n=zr[e.m-1].slice(0,3);return t==="week"?`${e.d} ${n}`:t==="month"?n:`Q${Math.floor((e.m-1)/3)+1}`}function US(e,t,n){const r=Nc(e,n.scale),o=[];for(let h=0;h<=n.columns;h++)o.push(Lc(r,n.scale,h));const i=o[n.columns]-1,s=h=>{let f=0;for(;f+1<n.columns&&o[f+1]<=h;)f++;return f},a=vt(r).y,l=o.slice(0,n.columns).map((h,f)=>({key:Tt(h),label:qS(vt(h),n.scale),end:Tt(o[f+1]-1),today:n.today>=h&&n.today<o[f+1]})),c=[];o.slice(0,n.columns).forEach((h,f)=>{const y=vt(h),g=n.scale==="week"?y.y===a?zr[y.m-1]:`${zr[y.m-1]} ${y.y}`:String(y.y),v=c[c.length-1];v&&v.label===g?v.span+=1:c.push({label:g,col:f+1,span:1})});const u=[],d=new Map;for(const h of[...t].sort((f,y)=>f.order-y.order)){if(h.end<r||h.start>i)continue;const f=h.rowKey??h.id,y=d.get(f);y?y.push(h):d.set(f,[h])}for(const[h,f]of d){const y=u.length,g=[],v=[],m=f.map(b=>({s:b,first:s(Math.max(b.start,r)),last:s(Math.min(b.end,i))})).sort((b,x)=>b.first-x.first||x.last-x.first-(b.last-b.first)||b.s.order-x.s.order);for(const{s:b,first:x,last:$}of m){const S=ey(g,x,$,Number.MAX_SAFE_INTEGER);v.push({id:b.id,rowIndex:y,col:x+1,span:$-x+1,lane:S,contL:b.start<r,contR:b.end>i,tone:b.tone,row:b.value})}u.push({key:h,index:y,lanes:Math.max(1,g.length),count:v.length,items:v})}let p=null;if(n.today>=r&&n.today<=i){const h=s(n.today),f=(n.today-o[h])/(o[h+1]-o[h]);p={col:h+1,percent:Math.round((h+f)/n.columns*1e4)/100}}return{scale:n.scale,key:Tt(r),label:ny(r,i),prev:Tt(Lc(r,n.scale,-n.columns)),next:Tt(o[n.columns]),today:Tt(n.today),columns:l,bands:c,rows:u,now:p}}const VS=e=>!!e&&typeof e=="object"&&!Array.isArray(e);function Wr(e){if(e===null||typeof e=="boolean"||typeof e=="string")return JSON.stringify(e);if(typeof e=="number"){if(!Number.isFinite(e))throw new Error(`canonicalJson: ${e} has no JSON form`);return JSON.stringify(e)}if(Array.isArray(e))return`[${e.map(t=>t===void 0?"null":Wr(t)).join(",")}]`;if(VS(e))return`{${Object.keys(e).filter(n=>e[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${Wr(e[n])}`).join(",")}}`;throw new Error(`canonicalJson: a ${typeof e} has no JSON form`)}Uint8Array.from([48,46,2,1,0,48,5,6,3,43,101,112,4,34,4,32]);const Hr="records",Hn={sortDefault:"createdAt",orderDefault:"desc",limitDefault:100,limitMax:500},KS=["app","before","by","columns","day","expand","lanes","limit","mine","month","order","q","query","row","scale","sort","start","sum","tone","until","user","view"],GS=["id","createdAt","updatedAt","createdBy","authorId","author"],YS=["eq","gt","gte","lt","lte","in","between"],XS={"=":"eq","==":"eq",">":"gt",">=":"gte","<":"lt","<=":"lte"},Hp=["sum","avg","min","max","count","countDistinct","first","last"],qp=["sum","count","avg","min","max"],ZS=["count","sum","running","rows"],JS=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],QS=["January","February","March","April","May","June","July","August","September","October","November","December"],ry=/^\d{4}-(0[1-9]|1[0-2])$/,eC=["gt","gte","lt","lte","in","between"],tC=["in","between"],Rt=e=>e?.trim()||null,ko=e=>typeof e=="string"&&e.length===10&&Xi(e)?e:null,jc=(e,t)=>{const n=typeof e=="number"?e:typeof e=="string"&&e.trim()?Number(e):NaN;return Number.isInteger(n)&&n>=1&&n<=t?n:null},bt=e=>!!e&&typeof e=="object"&&!Array.isArray(e),mr=(e,t)=>e<t?-1:e>t?1:0;function oy(e,t){const n=Rt(t);if(e.q!==void 0&&e.q.trim()){let d=null;try{d=JSON.parse(e.q)}catch{d=null}return Xu(bt(d)?d:{},n).query}const r=Number(e.limit),o=[];for(const d of Object.keys(e).sort()){if(KS.includes(d)||!d)continue;const p=d.lastIndexOf("."),h=p>=0?d.slice(p+1):"",f=e[d];p>0&&eC.includes(h)?o.push({field:d.slice(0,p),op:h,value:tC.includes(h)?f.split(","):f}):o.push({field:d,op:"eq",value:f})}o.sort((d,p)=>mr(d.field,p.field)||mr(d.op,p.op));const i=Rt(e.by),s=Rt(e.before),a=e.view==="week"||e.view==="timeline"?e.view:"month",l=Rt(e.until),c=Rt(e.tone),u=jc(e.lanes,Yg)??Gg;return{from:n,app:Rt(e.app),mine:e.mine==="1"||e.mine==="true",user:Rt(e.user),where:o,or:[],sort:[{field:Rt(e.sort)??Hn.sortDefault,order:e.order==="asc"?"asc":e.order==="desc"?"desc":Hn.orderDefault}],limit:Number.isInteger(r)&&r>0?Math.min(r,Hn.limitMax):Hn.limitDefault,sum:Rt(e.sum),month:i&&a==="month"?{field:i,key:e.month&&ry.test(e.month)?e.month:null,until:l,day:ko(e.day),lanes:u,tone:c}:null,week:i&&a==="week"?{field:i,key:ko(e.day),until:l,lanes:u,tone:c}:null,timeline:i&&a==="timeline"?{field:i,until:l,row:Rt(e.row),scale:zc.includes(e.scale)?e.scale:"week",start:ko(e.start),columns:jc(e.columns,Zg)??Xg,tone:c}:null,group:[],aggregate:[],running:[],before:s?{field:i??Hn.sortDefault,date:s}:null,expand:[...new Set((e.expand??"").split(",").map(d=>d.trim()).filter(Boolean))]}}function iy(e){return e.scheme===Hr?oy(e.params,e.name):null}function Up(e){return e===null?"":typeof e=="string"?e:typeof e=="boolean"?e?"true":"false":typeof e=="number"&&Number.isFinite(e)?String(e):null}function Vp(e,t,n){if(!Array.isArray(e)||e.length<3)return n.push({path:t,message:"a condition is [field, op, value]"}),null;const[r,o,...i]=e;if(typeof r!="string"||!r.trim())return n.push({path:`${t}/0`,message:"a condition's field is a non-empty string"}),null;const s=typeof o=="string"?XS[o]??(YS.includes(o)?o:null):null;if(!s)return n.push({path:`${t}/1`,message:`unknown operator ${String(o)}`}),null;const a=r.trim();if(s==="in"){const c=i.length===1&&Array.isArray(i[0])?i[0].map(Up):null;return!c||c.some(u=>u===null)?(n.push({path:`${t}/2`,message:"in takes one list of values"}),null):{field:a,op:s,value:c}}const l=i.map(Up);return l.some(c=>c===null)||l.length!==(s==="between"?2:1)?(n.push({path:`${t}/2`,message:s==="between"?"between takes a low and a high value":`${s} takes one value`}),null):{field:a,op:s,value:s==="between"?l:l[0]}}const nC=["from","app","mine","user","where","sort","limit","sum","month","week","timeline","group","aggregate","running","before","expand"],Kp={month:["field","key","until","day","lanes","tone"],week:["field","key","until","lanes","tone"],timeline:["field","until","row","scale","start","columns","tone"]};function rC(e,t,n){if(!bt(t)||typeof t.field!="string"||!t.field.trim())return n.push({path:`/${e}`,message:`${e} is {${Kp[e].map(o=>o==="field"?o:`${o}?`).join(", ")}}`}),null;const r={field:t.field.trim()};for(const o of Object.keys(t).sort()){if(o==="field")continue;const i=t[o],s=`/${e}/${o}`;if(!Kp[e].includes(o))n.push({path:s,message:`unknown key ${o}`});else{if(i==null)continue;if(o==="lanes"||o==="columns"){const a=o==="lanes"?Yg:Zg,l=jc(i,a);l===null?n.push({path:s,message:`${o} is an integer 1–${a}`}):r[o]=l}else o==="scale"?zc.includes(i)?r[o]=i:n.push({path:s,message:`scale is ${zc.join("|")}`}):typeof i!="string"?n.push({path:s,message:`${o} is a string`}):r[o]=i.trim()||null}}return r}function Xu(e,t){const n=[],r=oy({},null);if(r.sort=[{field:Hn.sortDefault,order:Hn.orderDefault}],!bt(e))return n.push({path:"",message:"a query is an object"}),r.from=Rt(t),{query:r,issues:n};for(const i of Object.keys(e).sort())!nC.includes(i)&&!i.startsWith("$")&&n.push({path:`/${i}`,message:`unknown key ${i}`});const o=i=>{const s=e[i];return s==null?null:typeof s!="string"?(n.push({path:`/${i}`,message:`${i} is a string`}),null):Rt(s)};if(r.from=Rt(t)??o("from"),r.app=o("app"),r.user=o("user"),r.sum=o("sum"),e.mine!==void 0&&(typeof e.mine!="boolean"?n.push({path:"/mine",message:"mine is a boolean"}):r.mine=e.mine),e.where!==void 0&&(Array.isArray(e.where)?e.where.forEach((i,s)=>{const a=`/where/${s}`;if(bt(i)){if(Object.keys(i).length!==1||!Array.isArray(i.or))return void n.push({path:a,message:"an alternative is {or: [[condition…]…]}"});if(r.or.length)return void n.push({path:a,message:"one or per query"});i.or.forEach((c,u)=>{if(!Array.isArray(c))return void n.push({path:`${a}/or/${u}`,message:"an alternative is a list of conditions"});const d=[];c.forEach((p,h)=>{const f=Vp(p,`${a}/or/${u}/${h}`,n);f&&d.push(f)}),r.or.push(d)});return}const l=Vp(i,a,n);l&&r.where.push(l)}):n.push({path:"/where",message:"where is a list of conditions"})),e.sort!==void 0){const i=typeof e.sort=="string"?[e.sort]:Array.isArray(e.sort)?e.sort:null;if(!i)n.push({path:"/sort",message:"sort is a field or a list of [field, order]"});else{const s=[];i.forEach((a,l)=>{const[c,u]=typeof a=="string"?[a,"asc"]:Array.isArray(a)?[a[0],a.length>1?a[1]:"asc"]:[null,null];if(typeof c!="string"||!c.trim()||u!=="asc"&&u!=="desc")return void n.push({path:typeof e.sort=="string"?"/sort":`/sort/${l}`,message:"a sort key is field or [field, asc|desc]"});s.push({field:c.trim(),order:u})}),s.length&&(r.sort=s)}}if(e.limit!==void 0){const i=typeof e.limit=="number"?e.limit:typeof e.limit=="string"&&e.limit.trim()?Number(e.limit):NaN;!Number.isInteger(i)||i<1?n.push({path:"/limit",message:"limit is a positive integer"}):r.limit=Math.min(i,Hn.limitMax)}for(const i of["month","week","timeline"]){if(e[i]===void 0||e[i]===null)continue;if(r.month||r.week||r.timeline){n.push({path:`/${i}`,message:"one calendar view per query"});continue}const s=rC(i,e[i],n);if(!s)continue;const a=c=>typeof s[c]=="string"?s[c]:null,l=typeof s.lanes=="number"?s.lanes:Gg;i==="month"?r.month={field:s.field,key:a("key")&&ry.test(a("key"))?a("key"):null,until:a("until"),day:ko(a("day")),lanes:l,tone:a("tone")}:i==="week"?r.week={field:s.field,key:ko(a("key")),until:a("until"),lanes:l,tone:a("tone")}:r.timeline={field:s.field,until:a("until"),row:a("row"),scale:a("scale")??"week",start:ko(a("start")),columns:typeof s.columns=="number"?s.columns:Xg,tone:a("tone")}}if(e.group!==void 0&&(Array.isArray(e.group)?e.group.forEach((i,s)=>{const a=`/group/${s}`;let l=null;if(typeof i=="string"&&i.trim()?l={field:i.trim(),bucket:null}:bt(i)&&typeof i.bucket=="string"&&i.bucket.trim()&&Gd.includes(i.by)&&Object.keys(i).length===2&&(l={field:i.bucket.trim(),bucket:i.by}),!l)return void n.push({path:a,message:`a group key is a field or {bucket: field, by: ${Gd.join("|")}}`});if(r.group.some(c=>c.field===l.field||l.field==="author"&&c.field==="authorId"||l.field==="authorId"&&c.field==="author"))return void n.push({path:a,message:`duplicate group ${l.field}`});r.group.push(l)}):n.push({path:"/group",message:"group is a list of keys"})),e.aggregate!==void 0)if(!bt(e.aggregate))n.push({path:"/aggregate",message:"aggregate is {name: [op, field?]}"});else for(const i of Object.keys(e.aggregate).sort()){const s=e.aggregate[i],a=`/aggregate/${i}`;if(!i.trim()||ZS.includes(i)||r.group.some(u=>u.field===i||u.field==="author"&&i==="authorId")){n.push({path:a,message:`the name ${i} is taken`});continue}const l=Array.isArray(s)&&Hp.includes(s[0])?s[0]:null,c=Array.isArray(s)&&s.length>1&&typeof s[1]=="string"&&s[1].trim()?s[1].trim():null;if(!l||!Array.isArray(s)||s.length>2||s.length>1&&!c||l!=="count"&&!c){n.push({path:a,message:`an aggregate is [${Hp.join("|")}, field] (count: the field is optional)`});continue}r.aggregate.push({name:i,op:l,field:c})}if(e.running!==void 0)if(!bt(e.running))n.push({path:"/running",message:"running is {field: op}"});else for(const i of Object.keys(e.running).sort()){const s=e.running[i];if(!i.trim()||!qp.includes(s)){n.push({path:`/running/${i}`,message:`a running value is {field: ${qp.join("|")}}`});continue}r.running.push({field:i,op:s})}if(e.before!==void 0&&e.before!==null){const i=e.before,s=r.group.find(a=>a.bucket!==null)?.field??r.month?.field??r.week?.field??r.timeline?.field??Hn.sortDefault;typeof i=="string"?r.before=Rt(i)?{field:s,date:i.trim()}:null:bt(i)&&typeof i.field=="string"&&i.field.trim()&&typeof i.date=="string"?r.before=i.date.trim()?{field:i.field.trim(),date:i.date.trim()}:null:n.push({path:"/before",message:"before is a date or {field, date}"})}return e.expand!==void 0&&(Array.isArray(e.expand)?e.expand.forEach((i,s)=>{if(typeof i!="string"||!i.trim())return void n.push({path:`/expand/${s}`,message:"an expanded field is a non-empty string"});if(r.expand.includes(i.trim()))return void n.push({path:`/expand/${s}`,message:`duplicate expand ${i.trim()}`});r.expand.push(i.trim())}):n.push({path:"/expand",message:"expand is a list of ref fields"})),{query:r,issues:n}}function Bc(e,t){return typeof e=="string"?e.replace(/\$\{([^}]*)\}/g,(n,r)=>t[r.trim()]??""):Array.isArray(e)?e.map(n=>Bc(n,t)):bt(e)?Object.fromEntries(Object.keys(e).map(n=>[n,Bc(e[n],t)])):e}function Zu(e,t){const n=Qt(e),r=n?.params.query;if(!n||r===void 0||!bt(t)||!Object.prototype.hasOwnProperty.call(t,r))return e;const{query:o,...i}=n.params,s=t[r],a=Bc(s,i),l=e.trim(),c=l.includes("?")?l.slice(0,l.indexOf("?")):l;return Gu(c,{q:Wr(a)})}const In=e=>{if(typeof e=="number")return Number.isFinite(e)?e:null;if(typeof e=="string"&&e.trim()!==""){const t=Number(e);return Number.isFinite(t)?t:null}return null},tt=e=>e==null?"":typeof e=="string"?e:typeof e=="object"?Wr(e):String(e);function ya(e,t){const n=In(e),r=In(t);return n!==null&&r!==null?n<r?-1:n>r?1:0:mr(tt(e),tt(t))}const Ri=e=>{const t=In(e);return{n:t,t:t===null?tt(e):""}};function fi(e,t,n,r){return e.n!==null&&t.n!==null?e.n<t.n?-1:e.n>t.n?1:0:mr(e.n===null?e.t:tt(n),t.n===null?t.t:tt(r))}function Gp(e){const t=Array.isArray(e.value)?e.value:[e.value],n=e.op==="between"?t.length===2?t:[]:t.length===1?t:[tt(e.value)];return{filter:e,list:t,eq:tt(e.value),bounds:n.map(r=>({key:Ri(r),v:r}))}}function Yp(e,t){const n=e.filter.op;if(n==="eq")return tt(t)===e.eq;if(n==="in")return e.list.includes(tt(t));const r=Ri(t);if(n==="between")return e.bounds.length===2&&fi(r,e.bounds[0].key,t,e.bounds[0].v)>=0&&fi(r,e.bounds[1].key,t,e.bounds[1].v)<=0;const o=e.bounds[0],i=fi(r,o.key,t,o.v);return n==="gt"?i>0:n==="gte"?i>=0:n==="lt"?i<0:i<=0}function Xp(e,t){const n=t.map(o=>{const i=e.map(l=>_n(l,o.field)),s=i.map(Ri),a=o.order==="asc"?1:-1;if(s.every(l=>l.n!==null)){const l=Float64Array.from(s,c=>c.n);return(c,u)=>a*(l[c]<l[u]?-1:l[c]>l[u]?1:0)}if(s.every(l=>l.n===null)){const l=[...new Set(s.map(d=>d.t))].sort(mr),c=new Map(l.map((d,p)=>[d,p])),u=Uint32Array.from(s,d=>c.get(d.t));return(d,p)=>a*(u[d]-u[p])}return(l,c)=>a*fi(s[l],s[c],i[l],i[c])}),r=e.map((o,i)=>i);return r.sort((o,i)=>{for(const s of n){const a=s(o,i);if(a!==0)return a}return mr(e[o].id,e[i].id)}),r.map(o=>e[o])}function Vo(e){return e.authorId??e.createdBy??null}function _n(e,t){return t==="createdAt"?e.createdAt:t==="updatedAt"?e.updatedAt:t==="id"?e.id:t==="createdBy"?e.createdBy:t==="authorId"?Vo(e):e.data[t]}function Zp(e,t){const[n,r]=e.split("-").map(Number),o=n*12+(r-1)+t;return`${Math.floor(o/12)}-${String((o%12+12)%12+1).padStart(2,"0")}`}function oC(e){const[t,n]=e.split("-").map(Number);return`${QS[n-1]} ${t}`}function iC(e){const[t,n]=e.split("-").map(Number),r=[];for(let o=1;o<=Io(t,n);o++)r.push({date:`${e}-${String(o).padStart(2,"0")}`,day:o,weekday:JS[Yi(t,n,o)],count:0,sum:0});return r}function qr(e){return Math.round(e*1e6)/1e6}const Wc=e=>e===void 0?null:e;function sC(e,t){const n=e.field===null?[]:t.map(r=>_n(r,e.field));switch(e.op){case"count":return e.field===null?t.length:n.filter(r=>tt(r)!=="").length;case"sum":return qr(n.reduce((r,o)=>r+(In(o)??0),0));case"avg":{const r=n.map(In).filter(o=>o!==null);return r.length?qr(r.reduce((o,i)=>o+i,0)/r.length):null}case"min":case"max":{let r;for(const o of n)tt(o)!==""&&(r===void 0||(e.op==="min"?ya(o,r)<0:ya(o,r)>0))&&(r=o);return r===void 0?null:In(r)??tt(r)}case"countDistinct":return new Set(n.map(tt).filter(r=>r!=="")).size;case"first":return t.length?Wc(n[0]):null;case"last":return t.length?Wc(n[n.length-1]):null}}function zl(e,t){const n={count:t.length};e.sum!==null&&(n.sum=qr(t.reduce((r,o)=>r+(In(o.data[e.sum])??0),0)));for(const r of e.aggregate)n[r.name]=sC(r,t);return n}class aC{constructor(t){this.list=t,this.acc=t.map(()=>({sum:0,count:0,nums:0,min:null,max:null}))}list;acc;add(t){this.list.forEach((n,r)=>{const o=this.acc[r],i=In(_n(t,n.field));o.count+=1,i!==null&&(o.sum+=i,o.nums+=1,o.min=o.min===null||i<o.min?i:o.min,o.max=o.max===null||i>o.max?i:o.max)})}read(){const t={};return this.list.forEach((n,r)=>{const o=this.acc[r];t[n.field]=n.op==="sum"?qr(o.sum):n.op==="count"?o.count:n.op==="avg"?o.nums?qr(o.sum/o.nums):null:n.op==="min"?o.min:o.max}),t}}function lC(e,t){if(e.field==="author")return Vo(t)??"";const n=_n(t,e.field);return e.bucket!==null?_m(tt(n),e.bucket)??"":tt(n)}function cC(e,t,n,r){if(e.field==="author"){const i=Vo(t);r.author=i&&n?.[i]||"",r.authorId=i;return}const o=_n(t,e.field);r[e.field]=e.bucket!==null?_m(tt(o),e.bucket):Wc(o)}const Jp=16,uC=["id","createdAt","updatedAt","createdBy","authorId"];function dC(e,t){const n=t&&bt(e)&&Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0;if(!bt(n)||!bt(n.computed))return;const r={};for(const[o,i]of Object.entries(n.computed))typeof i=="string"&&(r[o]=i);return Object.keys(r).length?r:void 0}function pC(e,t){const n=t&&bt(e)&&Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0;if(!bt(n)||!bt(n.refs))return;const r={};for(const[o,i]of Object.entries(n.refs))i==="issue"||i==="member"?r[o]=i:bt(i)&&typeof i.kind=="string"&&i.kind&&(r[o]={kind:i.kind});return Object.keys(r).length?r:void 0}function sy(e,t){const n=Vo(e);return{...e.data,id:e.id,createdAt:e.createdAt,updatedAt:e.updatedAt,createdBy:e.createdBy,authorId:n,author:n&&t?.[n]||""}}function fC(e,t,n,r){const o=typeof t=="string"?t:typeof t=="number"?String(t):"";if(!o)return null;if(e==="issue")return r.issues&&Object.prototype.hasOwnProperty.call(r.issues,o)?r.issues[o]:null;if(e==="member")return r.names&&Object.prototype.hasOwnProperty.call(r.names,o)?{id:o,name:r.names[o]}:null;const i=n().get(o);return i&&i.kind===e.kind?sy(i,r.names):null}function hC(e,t,n,r){const o=n?Object.keys(n).sort(mr):[];if(!o.length)return e;const i=o.map(a=>{const l=Wo(n[a]);return{name:a,ast:"ast"in l?l.ast:null,reads:"ast"in l?Fm(l.ast):[]}}),s={now:(r?qa(r):null)??0};return e.map(a=>{if(a.kind!==t)return a;const l={...a.data,id:a.id,createdAt:a.createdAt,updatedAt:a.updatedAt,createdBy:a.createdBy,authorId:Vo(a)},c={...a.data};for(const u of i){for(const p of u.reads)Object.prototype.hasOwnProperty.call(l,p)||(l[p]=null);const d=u.ast?Iu(u.ast,l,s):null;c[u.name]=d&&"value"in d?d.value:null}return{...a,data:c}})}function mC(e,t,n){if(!t.from)return null;const r=n.now??new Date().toISOString(),o=e;e=hC(e,t.from,n.computed,r);const i=t.expand.flatMap(_=>n.refs&&Object.prototype.hasOwnProperty.call(n.refs,_)?[{name:_,target:n.refs[_]}]:[]);let s=null;const a=()=>s??=new Map(o.map(_=>[_.id,_])),l=t.month,c=n.today&&/^\d{4}-\d{2}-\d{2}$/.test(n.today)?n.today:r.slice(0,10),u=l?l.key??c.slice(0,7):null,d=dr(c)??0,p=t.month??t.week??t.timeline;let h=null;if(l&&l.until!==null&&u!==null){const[_,M]=u.split("-").map(Number);h=[dr(`${u}-01`),dr(`${u}-${String(Io(_,M)).padStart(2,"0")}`)]}else if(t.week){const _=Nc((t.week.key?dr(t.week.key):null)??d,"week");h=[_,_+6]}else if(t.timeline){const _=t.timeline,M=Nc((_.start?dr(_.start):null)??d,_.scale);h=[M,Lc(M,_.scale,_.columns)-1]}const f=_=>p?LS(tt(_.data[p.field]),p.until!==null?tt(_.data[p.until]):null):null,y=t.where.map(Gp),g=t.or.map(_=>_.map(Gp)),v=t.before?Ri(t.before.date):null,m=[],b=Xp(e.filter(_=>{if(_.kind!==t.from)return!1;const M=Vo(_);if(t.mine&&(n.me===null||M!==n.me)||t.user!==null&&M!==t.user||!y.every(O=>Yp(O,_n(_,O.filter.field)))||g.length&&!g.some(O=>O.every(E=>Yp(E,_n(_,E.filter.field)))))return!1;if(t.before){const O=tt(_n(_,t.before.field));if(O!==""&&fi(Ri(O),v,O,t.before.date)<0)return m.push(_),!1}if(h){const O=f(_);if(!O||O.end<h[0]||O.start>h[1])return!1}else if(l&&u!==null&&!tt(_.data[l.field]).startsWith(u))return!1;return!0}),t.sort),x=Xp(m,t.sort),$=()=>{const _=new aC(t.running);for(const M of x)_.add(M);return _},S=t.running.length&&!t.group.length?$():null,A=_=>{const M=sy(_,n.names);for(const O of i)M[O.name]=fC(O.target,_.data[O.name],a,n);return n.transitions&&(M[Ns]=CS(n.transitions,_.data,{id:n.me,role:n.role??null},_)),M},C={rows:b.slice(0,t.limit).map(_=>{const M=A(_);return S&&(S.add(_),M.running=S.read()),M}),count:b.length};if(t.sum!==null&&(C.sum=qr(b.reduce((_,M)=>_+(In(M.data[t.sum])??0),0))),l&&u!==null){const _=iC(u),M=new Map(_.map(E=>[E.date,E])),O=new Map;for(const E of b){const R=tt(E.data[l.field]).slice(0,10),z=M.get(R);if(!z)continue;z.count+=1,t.sum!==null&&(z.sum=qr(z.sum+(In(E.data[t.sum])??0)));const Z=O.get(R);Z?Z.push(E):O.set(R,[E])}if(t.running.length){const E=$();for(const R of _){for(const z of O.get(R.date)??[])E.add(z);R.running=E.read()}}C.month={key:u,label:oC(u),prev:Zp(u,-1),next:Zp(u,1),today:c,days:_,labels:_.map(E=>String(E.day)),counts:_.map(E=>E.count),sums:_.map(E=>E.sum)}}if(p){const _=b.flatMap((E,R)=>{const z=f(E);return z?[{row:E,order:R,...z}]:[]}),M=jS(_.map(E=>p.tone!==null?tt(_n(E.row,p.tone)):"")),O=_.map((E,R)=>({id:E.row.id,start:E.start,end:E.end,tone:M[R],value:A(E.row),order:E.order,rowKey:t.timeline?.row?tt(_n(E.row,t.timeline.row)):null}));if(l&&C.month){const[E,R]=C.month.key.split("-").map(Number);Object.assign(C.month,WS(E,R,Io(E,R),O,{lanes:l.lanes,today:d,day:l.day}))}else t.week?C.week=HS(h[0],O,{lanes:t.week.lanes,today:d}):t.timeline&&(C.timeline=US(h[0],O,{scale:t.timeline.scale,columns:t.timeline.columns,today:d}))}if(t.group.length){const _=new Map,M=t.group.length===1;for(const z of b){const Z=t.group.map(L=>lC(L,z)),N=M?Z[0]:Z.some(L=>L.includes("\0"))?JSON.stringify(Z):Z.join("\0"),I=_.get(N);if(I)I.rows.push(z);else{const L={};for(const V of t.group)cC(V,z,n.names,L);_.set(N,{parts:Z,rows:[z],out:L})}}const O=[..._.values()];for(const z of O)Object.assign(z.out,zl(t,z.rows));const E=new Set([...t.group.flatMap(z=>z.field==="author"?["author","authorId"]:[z.field]),"count",...t.sum!==null?["sum"]:[],...t.aggregate.map(z=>z.name)]),R=t.sort.filter(z=>E.has(z.field));if(O.sort((z,Z)=>{for(const N of R){const I=ya(z.out[N.field],Z.out[N.field]);if(I!==0)return N.order==="asc"?I:-I}for(const N of t.group){const I=ya(z.out[N.field],Z.out[N.field]);if(I!==0)return I}for(let N=0;N<z.parts.length;N++){const I=mr(z.parts[N],Z.parts[N]);if(I!==0)return I}return 0}),t.running.length){const z=$();for(const Z of O){for(const N of Z.rows)z.add(N);Z.out.running=z.read()}}C.groups=O.map(z=>z.out)}return t.aggregate.length&&(C.totals=zl(t,b)),t.before&&(C.before=zl(t,x)),C}const gC=/^[a-z][a-z0-9_-]{0,31}$/,yC=["mcp","script"],bC=/^[A-Za-z_][A-Za-z0-9_]*$/,Qp=e=>!!e&&typeof e=="object"&&!Array.isArray(e),ef=e=>Array.isArray(e)&&e.every(t=>typeof t=="string");function vC(e){try{const t=new URL(e);return(t.protocol==="https:"||t.protocol==="http:")&&!!t.host}catch{return!1}}function $C(e){if(!Qp(e))return[{path:"/tools",message:"tools is an object of tools"}];const t=[];for(const n of Object.keys(e).sort()){const r=e[n],o=`/tools/${n}`;if(gC.test(n)||t.push({path:o,message:"a tool id is lowercase letters, digits, - and _"}),!Qp(r)){t.push({path:o,message:"a tool is {kind, title, url | command}"});continue}(typeof r.kind!="string"||!yC.includes(r.kind))&&t.push({path:`${o}/kind`,message:"kind is mcp or script"}),(typeof r.title!="string"||!r.title.trim())&&t.push({path:`${o}/title`,message:"title is a required string"}),r.description!==void 0&&typeof r.description!="string"&&t.push({path:`${o}/description`,message:"description is a string"});const i=r.url!==void 0,s=r.command!==void 0;r.kind==="mcp"&&i===s&&t.push({path:o,message:"an mcp tool has a url or a command"}),r.kind==="script"&&i&&t.push({path:`${o}/url`,message:"a script runs a command, not a url"}),r.kind==="script"&&!s&&t.push({path:`${o}/command`,message:"command is a non-empty string"}),i&&(typeof r.url!="string"||!vC(r.url))&&t.push({path:`${o}/url`,message:"url is an absolute http(s) url"}),s&&(typeof r.command!="string"||!r.command.trim())&&t.push({path:`${o}/command`,message:"command is a non-empty string"}),r.args!==void 0&&(!ef(r.args)||i)&&t.push({path:`${o}/args`,message:"args is a list of strings beside a command"}),r.env!==void 0&&(!ef(r.env)||r.env.some(a=>!bC.test(a))||i)&&t.push({path:`${o}/env`,message:"env is a list of variable names beside a command"})}return t}const dn=St.package.exposes.limits,xC=St.package.exposes.runKinds,tf=St.package.exposes.recordOps,wC=St.package.exposes.readRecordOps,kC=St.package.exposes.readOpWords,SC=St.package.exposes.destructiveWords,po=St.package.exposes.agent,CC=new RegExp(po.slugPattern),Nn=e=>!!e&&typeof e=="object"&&!Array.isArray(e),AC=new RegExp(dn.namePattern),_C=new RegExp(St.package.exposes.actionPattern),OC=/\$\{input\.([A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*)\}/g;function TC(e){const t=[],n=r=>{if(typeof r=="string")for(const o of r.matchAll(OC))t.push(o[1]);else Array.isArray(r)?r.forEach(n):Nn(r)&&Object.values(r).forEach(n)};return n(e),t}const ay=e=>e.toLowerCase().split(/[^a-z]+/).filter(Boolean);function MC(e){const t=ay(e.split(".").at(-1)??"").at(-1);return t!==void 0&&kC.includes(t)?"read":"write"}function nf(e){return ay(e).some(t=>SC.includes(t))}function EC(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t!==""):[]}function IC(e){if(!Array.isArray(e)||e.some(n=>typeof n!="string"||n===""))return[{path:"/upstreams",message:"upstreams is a list of MCP server names"}];const t=[];return e.forEach((n,r)=>{e.indexOf(n)!==r&&t.push({path:`/upstreams/${r}`,message:`duplicate upstream ${n}`})}),t}function PC(e,t,n){if(!Array.isArray(e))return[{index:null,code:"run",path:"/exposes",message:"exposes is a list of tools"}];const r=[];e.length>dn.maxTools&&r.push({index:null,code:"tooMany",path:"/exposes",message:`exposes lists at most ${dn.maxTools} tools`});const o=Nn(t)?Object.keys(t):[],i=EC(n),s=new Set;return e.forEach((a,l)=>{const c=`/exposes/${l}`,u=(g,v,m)=>{r.push({index:l,code:g,path:`${c}${v}`,message:m})};if(!Nn(a))return u("run","","a tool is {name, title, description, input, access, run}");const d=a.name;typeof d!="string"||!AC.test(d)||d.length>dn.nameMax||d.includes(dn.separator)?u("name","/name",`name is lowercase letters, digits and _ (at most ${dn.nameMax}, no ${dn.separator})`):s.has(d)?u("duplicate","/name",`duplicate tool ${d}`):s.add(d),(typeof a.title!="string"||!a.title.trim()||a.title.length>dn.titleMax)&&u("title","/title",`title is a non-blank string of at most ${dn.titleMax} characters`),(typeof a.description!="string"||!a.description.trim()||a.description.length>dn.descriptionMax)&&u("description","/description",`description is a non-blank string of at most ${dn.descriptionMax} characters`);const p=a.input;(!Nn(p)||p.type!=="object"||p.properties!==void 0&&!Nn(p.properties))&&u("input","/input","input is a JSON Schema of type object"),a.access!=="read"&&a.access!=="write"&&u("access","/access","access is read or write");const h=Nn(p)&&Nn(p.properties)?p.properties:{},f=a.run;if(!Nn(f)||xC.filter(g=>g in f).length!==1)return u("run","/run","run holds exactly one of records, action, upstream, agent");for(const g of TC(f))Object.prototype.hasOwnProperty.call(h,g.split(".")[0])||u("template","/run",`\${input.${g}} names no input property`);let y;if("records"in f){const g=f.records,v=Nn(g)?g.op:void 0;if(typeof v!="string"||!tf.includes(v))return v==="delete"?u("destructive","/run/records/op","a records delete is destructive: never exposed"):u("run","/run/records/op",`op is ${tf.join(", ")}`);(typeof g.kind!="string"||!o.includes(g.kind))&&u("kind","/run/records/kind","kind names no declared record kind"),y=wC.includes(v)?"read":"write"}else if("action"in f){const g=f.action;if(typeof g!="string"||!_C.test(g))return u("action","/run/action","action is a function name like namespace.function");if(nf(g))return u("destructive","/run/action","a destructive action is never exposed");y=MC(g)}else if("agent"in f)(typeof f.agent!="string"||!CC.test(f.agent)||f.agent.length>po.slugMax)&&u("agent","/run/agent","agent is an agent slug (lowercase words joined by -)"),(typeof f.prompt!="string"||f.prompt.trim()===""||f.prompt.length>po.promptMax)&&u("prompt","/run/prompt",`prompt is non-blank text of at most ${po.promptMax} characters`),f.device!==void 0&&!po.devices.includes(f.device)&&u("run","/run/device",`device is ${po.devices.join(", ")}`),y="write";else return(typeof f.upstream!="string"||!i.includes(f.upstream))&&u("upstream","/run/upstream","upstream names none of the package's upstreams"),typeof f.tool!="string"||f.tool===""?u("run","/run/tool","tool is a non-empty string"):nf(f.tool)?u("destructive","/run/tool","a destructive tool is never exposed"):void 0;a.access==="read"&&y==="write"&&u("accessTooLow","/access","the run writes: access is write")}),r}function DC(e,t,n){return PC(e,t,n).map(({path:r,message:o})=>({path:r,message:o}))}const je=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),hi=e=>e.replace(/~/g,"~0").replace(/\//g,"~1"),Nr=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);function Ur(e){if(!je(e))return"dyn";const t=Array.isArray(e.type)?e.type.filter(r=>r!=="null"):[e.type],n=t.length===1?t[0]:void 0;return n==="number"||n==="integer"?"number":n==="boolean"?"bool":n==="string"?e.format==="date"?"date":e.format==="date-time"?"timestamp":"string":n==="array"?[Ur(e.items)]:n==="object"?je(e.properties)?el(e.properties,e.required):"map":"dyn"}function el(e,t){const n=Array.isArray(t)?t:[],r={};for(const[o,i]of Object.entries(e))r[o]=n.includes(o)?Ur(i):Ze(Ur(i));return r}function ly(e){const t=je(e)&&je(e.schema)?e.schema:{},n=je(t.properties)?t.properties:{},r={...el(n,t.required),id:"string",createdAt:"timestamp",updatedAt:"timestamp",createdBy:"string",authorId:"string",author:"string"},o=je(e)&&je(e.computed)?e.computed:{},i=cy(e);for(const s of Object.keys(o).sort()){if(Nr(r,s))continue;const a=o[s],l=typeof a=="string"?Ua(a,i):null;r[s]=l&&"type"in l?l.type:Ze("dyn")}return r}function cy(e){const t=je(e)&&je(e.schema)?e.schema:{},n=je(t.properties)?t.properties:{},r={...el(n,t.required)};for(const o of uC)r[o]=o==="createdAt"||o==="updatedAt"?"timestamp":"string";return r}function RC(e,t){if(!je(e)||e.computed===void 0)return[];const n=e.computed;if(!je(n))return[{path:`${t}/computed`,message:"computed is {name: expression}"}];const r=[],o=Object.keys(n).sort();o.length>Jp&&r.push({path:`${t}/computed`,message:`at most ${Jp} computed fields per kind`});const i=je(e.schema)?e.schema:{},s=je(i.properties)?i.properties:{},a=cy(e);for(const l of o){const c=`${t}/computed/${hi(l)}`,u=n[l];if(Nr(s,l))r.push({path:c,message:`${l} shadows a field of the schema`});else if(GS.includes(l))r.push({path:c,message:`${l} is a reserved record key`});else if(typeof u!="string")r.push({path:c,message:"a computed field is an expression (a string)"});else{const d=Wo(u),p="ast"in d?Fm(d.ast).filter(h=>Nr(n,h)&&!Nr(s,h)):[];if(p.length)r.push({path:c,message:`a computed field reads no computed field: ${p.join(", ")}`});else{const h=Ua(u,a);"error"in h&&r.push({path:c,message:h.error})}}}return r}const uy={date:"date",day:"number",weekday:"string",initial:"string",inMonth:"bool",weekend:"bool",today:"bool",selected:"bool",total:"number",dots:[{tone:"string"}]},dy=e=>({id:"string",col:"number",span:"number",lane:"number",contL:"bool",contR:"bool",tone:Ze("string"),more:"number",row:Ze(e)}),FC=e=>({key:"string",label:"string",prev:"string",next:"string",today:"date",days:[{date:"date",day:"number",weekday:"string",count:"number",sum:"number",running:Ze("map")}],labels:["string"],counts:["number"],sums:["number"],weeks:[{key:"date",days:[uy],segments:[dy(e)]}],day:"date",agenda:{date:"date",label:"string",count:"number",items:[{id:"string",tone:"string",start:"date",end:"date",days:"number",row:e}]}}),zC=e=>({key:"date",label:"string",prev:"date",next:"date",today:"date",days:[uy],segments:[dy(e)]}),NC=e=>({scale:"string",key:"date",label:"string",prev:"date",next:"date",today:"date",columns:[{key:"date",label:"string",end:"date",today:"bool"}],bands:[{label:"string",col:"number",span:"number"}],rows:[{key:"string",index:"number",lanes:"number",count:"number",items:[{id:"string",rowIndex:"number",col:"number",span:"number",lane:"number",contL:"bool",contR:"bool",tone:"string",row:e}]}],now:Ze({col:"number",percent:"number"})});function LC(e,t){const n=(o,i)=>o?i:Ze(i),r=ly(e);return{rows:[t?.running.length&&!t.group.length?{...r,running:"map"}:r],count:"number",sum:n(t?t.sum!==null:void 0,"number"),groups:n(t?t.group.length>0:void 0,["map"]),totals:n(t?t.aggregate.length>0:void 0,"map"),before:n(t?t.before!==null:void 0,"map"),month:n(t?t.month!==null:void 0,FC(r)),week:n(t?t.week!==null:void 0,zC(r)),timeline:n(t?t.timeline!==null:void 0,NC(r))}}function Fi(e){if(Array.isArray(e)){const t=e.map(Fi);return t.length===0?["dyn"]:[t.every(n=>JSON.stringify(n)===JSON.stringify(t[0]))?t[0]:"dyn"]}if(je(e)){const t={};for(const[n,r]of Object.entries(e))t[n]=Fi(r);return t}return We(e)}function py(e,t,n){let r=e,o=!1;for(const i of t)if(Ot(r)&&(o=!0,r=r["?"]),Array.isArray(r)){if(!/^\d+$/.test(i))return{type:"dyn"};r=r[0],o=!0}else if(r==="map")r="dyn",o=!0;else if(typeof r=="object"){if(!Nr(r,i))return n?{unknown:i}:{type:"dyn"};r=r[i]}else return{type:"dyn"};return{type:o?Ze(r):r}}const Hc=e=>e.replace(/~1/g,"/").replace(/~0/g,"~");function jC(e,t,n,r){if(!e.startsWith("/"))return{type:"dyn"};const o=Array.isArray(t.bindings)?t.bindings:[];for(const s of o){if(!je(s)||typeof s.path!="string"||typeof s.source!="string"||e!==s.path&&!e.startsWith(`${s.path}/`))continue;const a=Qt(s.source),l=a?.scheme===Hr?a.name:void 0;if(!l||!je(n)||!Nr(n,l))return{type:"dyn"};const c=e.slice(s.path.length).split("/").filter((h,f)=>f>0||h!==""),u=BC(n[l]),d=Qt(Zu(s.source,je(r)?r:void 0)),p=d?iy(d):null;return{...py(LC(n[l],p),c.map(Hc),u),strict:u}}let i=t.data;for(const s of e==="/"?[]:e.slice(1).split("/").map(Hc))if(Array.isArray(i)&&/^\d+$/.test(s))i=i[Number(s)];else if(je(i)&&Nr(i,s))i=i[s];else return{type:"dyn"};return{type:i===void 0?"dyn":Fi(i)}}function BC(e){return(je(e)&&je(e.schema)?e.schema:{}).additionalProperties!==!0}function fy(e,t,n,r,o){return e.startsWith("/")?jC(e,n,r,o):t?{...py(t.type,e.split("/").filter(i=>i!=="").map(Hc),t.strict),strict:t.strict}:{type:"dyn"}}function WC(e,t,n){const r=new Map;for(const s of Array.isArray(e.components)?e.components:[])je(s)&&typeof s.id=="string"&&!r.has(s.id)&&r.set(s.id,s);const o=new Map,i=(s,a)=>{const l=r.get(s);if(!(!l||o.has(s))){if(o.set(s,a),Array.isArray(l.children))for(const c of l.children)typeof c=="string"&&i(c,a);if(je(l.children)&&typeof l.children.componentId=="string"&&typeof l.children.path=="string"){const c=fy(l.children.path,a,e,t,n),u="type"in c?Pt(c.type):"dyn";i(l.children.componentId,{type:Array.isArray(u)?u[0]:"dyn",strict:Array.isArray(u)&&c.strict===!0})}if(je(l.slots))for(const c of Object.values(l.slots))typeof c=="string"&&i(c,a)}};return i("root",null),o}function qc(e,t,n,r,o,i,s){if(Wa(e)){const a=fy(e.path,n,r,o,i);return"unknown"in a?(s.push({path:`${t}/path`,message:`unknown field ${a.unknown} in ${e.path}`}),Ze("dyn")):a.type==="dyn"?Ze(a.type):a.type}if(jo(e))return Ze("dyn");if(Array.isArray(e)){const a=e.map((l,c)=>qc(l,`${t}/${c}`,n,r,o,i,s));return a.length===0?["dyn"]:[a.every(l=>JSON.stringify(l)===JSON.stringify(a[0]))?a[0]:"dyn"]}if(je(e)){const a={};for(const[l,c]of Object.entries(e))a[l]=qc(c,`${t}/${hi(l)}`,n,r,o,i,s);return a}return We(e)}function HC(e){const t=[];if(!je(e.templates))return t;for(const[n,r]of Object.entries(e.templates)){if(!je(r)||!Array.isArray(r.components))continue;let o=null;const i=(a,l)=>{if(Array.isArray(a))return a.forEach((c,u)=>i(c,`${l}/${u}`));if(je(a)){if(a.call==="expr"&&je(a.args)){const c=a.args,u=`${l}/args`;if(Object.prototype.hasOwnProperty.call(c,"default")||t.push({path:`${u}/default`,message:"an expression binding needs a default, shown when it fails"}),typeof c.expr!="string")t.push({path:`${u}/expr`,message:"expr is a string"});else if(c.vars!==void 0&&!je(c.vars))t.push({path:`${u}/vars`,message:"vars is an object"});else{const d={},p=[];for(const[f,y]of Object.entries(c.vars??{}))d[f]=qc(y,`${u}/vars/${hi(f)}`,o,r,e.records,e.queries,p);t.push(...p);const h=p.length?null:Ua(c.expr,d);h&&"error"in h&&t.push({path:`${u}/expr`,message:h.error})}}for(const[c,u]of Object.entries(a))i(u,`${l}/${hi(c)}`)}},s=WC(r,e.records,e.queries);r.components.forEach((a,l)=>{o=je(a)&&typeof a.id=="string"?s.get(a.id)??null:null,i(a,`/templates/${hi(n)}/components/${l}`)})}return t}const rf=5,of=32,sf=200,So="app.navigate",rt=e=>!!e&&typeof e=="object"&&!Array.isArray(e),qC=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),UC=new Set(lm),VC=["template","title","icon","params","nav","exposed"],KC=["description","params"],GC=["required","description"],YC=/^[A-Za-z0-9_]+$/,pr=e=>e.replace(/~/g,"~0").replace(/\//g,"~1");function XC(e){if(e.screens===void 0)return[];const t=e.screens;if(!Array.isArray(t)||!t.length)return[{path:"/screens",message:"screens is a non-empty list of {template, title, icon?, params?, nav?, exposed?}"}];const n=[],r=t.filter(s=>!rt(s)||s.nav!==!1).length;r>rf&&n.push({path:"/screens",message:`at most ${rf} screens in the navigation, got ${r}`}),r||n.push({path:"/screens",message:"at least one screen is in the navigation (not nav: false)"});const o=rt(e.templates)?e.templates:{},i=new Set;return t.forEach((s,a)=>{const l=`/screens/${a}`;if(!rt(s))return void n.push({path:l,message:"a screen is {template, title, icon?, params?, nav?, exposed?}"});for(const c of Object.keys(s).sort())VC.includes(c)||n.push({path:`${l}/${pr(c)}`,message:`unknown screen key ${c}`});if(typeof s.template!="string"||!s.template?n.push({path:`${l}/template`,message:"template is a required string"}):qC(o,s.template)?i.has(s.template)?n.push({path:`${l}/template`,message:`duplicate screen ${s.template}`}):i.add(s.template):n.push({path:`${l}/template`,message:`template ${s.template} names no package template`}),typeof s.title!="string"||!s.title.trim()?n.push({path:`${l}/title`,message:"title is a required string"}):[...s.title].length>of&&n.push({path:`${l}/title`,message:`title is at most ${of} characters`}),s.icon!==void 0&&(typeof s.icon!="string"||!UC.has(s.icon))&&n.push({path:`${l}/icon`,message:`icon ${typeof s.icon=="string"?s.icon:JSON.stringify(s.icon)} is not an Exponential UI icon`}),s.params!==void 0)if(!rt(s.params))n.push({path:`${l}/params`,message:"params is an object of strings"});else for(const c of Object.keys(s.params).sort())typeof s.params[c]!="string"&&n.push({path:`${l}/params/${pr(c)}`,message:`params.${c} is a string`});s.nav!==void 0&&s.nav!==!1&&n.push({path:`${l}/nav`,message:"nav is false or absent"}),s.exposed!==void 0&&n.push(...ZC(s.exposed,`${l}/exposed`))}),n.push(...QC(e,i)),n}function ZC(e,t){if(!rt(e))return[{path:t,message:"exposed is {description, params?}"}];const n=[];for(const r of Object.keys(e).sort())KC.includes(r)||n.push({path:`${t}/${pr(r)}`,message:`unknown exposed key ${r}`});if(typeof e.description!="string"||!e.description.trim()?n.push({path:`${t}/description`,message:"description is a required string"}):[...e.description].length>sf&&n.push({path:`${t}/description`,message:`description is at most ${sf} characters`}),e.params===void 0)return n;if(!rt(e.params))return[...n,{path:`${t}/params`,message:"params is an object of {required?, description?}"}];for(const r of Object.keys(e.params).sort()){const o=e.params[r],i=`${t}/params/${pr(r)}`;if(YC.test(r)||n.push({path:i,message:`param ${r} is letters, digits and _`}),!rt(o)){n.push({path:i,message:"a param is {required?, description?}"});continue}for(const s of Object.keys(o).sort())GC.includes(s)||n.push({path:`${i}/${pr(s)}`,message:`unknown param key ${s}`});o.required!==void 0&&typeof o.required!="boolean"&&n.push({path:`${i}/required`,message:"required is a boolean"}),o.description!==void 0&&typeof o.description!="string"&&n.push({path:`${i}/description`,message:"description is a string"})}return n}function JC(e){if(typeof e!="string")return null;const t=/^\s*(?:'([^'\\]*)'|"([^"\\]*)")\s*$/.exec(e);return t?t[1]??t[2]??"":null}function QC(e,t){const n=[],r=(o,i)=>{o!==null&&!t.has(o)&&n.push({path:i,message:`navigate: ${o} is not a screen`})};if(rt(e.templates))for(const o of Object.keys(e.templates).sort()){const i=e.templates[o];!rt(i)||!Array.isArray(i.components)||i.components.forEach((s,a)=>{if(!(!rt(s)||!rt(s.on)))for(const l of Object.keys(s.on).sort()){const c=s.on[l],u=rt(c)&&rt(c.functionCall)?c.functionCall:null;if(!u||u.call!==So)continue;const d=`/templates/${pr(o)}/components/${a}/on/${pr(l)}/functionCall/args`,p=u.args;rt(p)?typeof p.screen=="string"&&r(p.screen,`${d}/screen`):n.push({path:d,message:"navigate takes {screen, params?}"})}})}if(rt(e.actions))for(const o of Object.keys(e.actions).sort()){const i=e.actions[o];(rt(i)&&Array.isArray(i.steps)?i.steps:[]).forEach((a,l)=>{if(!rt(a)||a.call!==So)return;const c=`/actions/${pr(o)}/steps/${l}/args`;rt(a.args)?r(JC(a.args.screen),`${c}/screen`):n.push({path:c,message:"navigate takes {screen, params?}"})})}return n}function eA(e){return Array.isArray(e.screens)?e.screens.filter(t=>rt(t)&&typeof t.template=="string"):[]}function tA(e,t){if(!rt(t))return{error:"navigate takes {screen, params?}"};if(typeof t.screen!="string"||!t.screen)return{error:"navigate: screen is a required string"};if(!eA(e).some(r=>r.template===t.screen))return{error:`navigate: ${t.screen} is not a screen`};const n={};if(t.params!==void 0&&t.params!==null){if(!rt(t.params))return{error:"navigate: params is an object of strings"};for(const r of Object.keys(t.params).sort()){const o=t.params[r];if(typeof o!="string")return{error:`navigate: params.${r} is a string`};n[r]=o}}return{screen:t.screen,params:n}}function nA(e,t){return!rt(t)||!e.includes("${params.")?e:e.replace(/\$\{params\.([A-Za-z0-9_]+)\}/g,(n,r)=>{const o=t[r];return typeof o=="string"?encodeURIComponent(o):""})}const zi={actions:32,steps:64,maxSteps:1e5},Ju=["require","records.upsert","records.delete","set","call"],rA=/^[a-z][A-Za-z0-9_]{0,31}$/,af="actions.",Nl="records.batch",we=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),nn=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),fn=e=>e.replace(/~/g,"~0").replace(/\//g,"~1"),hy=/^(\/([^/~]|~[01])*)*$/;function tl(e){return e.startsWith(af)?e.slice(af.length):null}function my(e){if(!we(e))return null;const t=Object.keys(e).filter(n=>Ju.includes(n));return t.length===1?t[0]:null}function oA(e){const t=we(e.params)?e.params:{};return{params:el(we(t.properties)?t.properties:{},t.required),data:Ze("dyn"),me:Ze("string")}}function Co(e,t){if(Ot(t))return Ot(e)&&Co(e["?"],t["?"]);if(Ot(e))return Co(e["?"],t);if(e==="dyn"||t==="dyn"||t==="null")return!0;const n=r=>r==="string"||r==="date"||r==="timestamp";return n(e)?n(t):Be(e)===Be(t)}function iA(e){const t=[],n=e.actions;if(n!==void 0)if(!we(n))t.push({path:"/actions",message:"actions is an object of named actions"});else{const r=Object.keys(n).sort();r.length>zi.actions&&t.push({path:"/actions",message:`at most ${zi.actions} actions`});for(const o of r)t.push(...sA(e,o,n[o],`/actions/${fn(o)}`))}return t}function sA(e,t,n,r){const o=[];if(rA.test(t)||o.push({path:r,message:"an action name is a letter, then letters, digits and underscores"}),!we(n))return[...o,{path:r,message:"an action is {params?, steps}"}];if(n.params!==void 0&&o.push(...Bg(n.params,`${r}/params`)),!Array.isArray(n.steps)||n.steps.length===0)return[...o,{path:`${r}/steps`,message:"steps is a non-empty array"}];n.steps.length>zi.steps&&o.push({path:`${r}/steps`,message:`at most ${zi.steps} steps`});const i=oA(n),s=we(e.records)?e.records:{},a=Array.isArray(e.functions)?e.functions.filter(l=>typeof l=="string"):null;return n.steps.forEach((l,c)=>o.push(...aA(l,`${r}/steps/${c}`,i,s,a))),o}function oo(e,t,n,r){if(typeof e!="string")return Fi(e);const o=Ua(e,n);return"error"in o?(r.push({path:t,message:o.error}),null):o.type}function aA(e,t,n,r,o){const i=[],s=my(e);if(s===null||!we(e))return[{path:t,message:`a step is one of ${Ju.join(", ")}`}];const a=e[s],l=`${t}/${fn(s)}`;switch(s){case"require":{if(typeof a!="string")i.push({path:l,message:"require is an expression"});else{const c=oo(a,l,n,i);c!==null&&c!=="bool"&&c!=="dyn"&&i.push({path:l,message:`require needs a bool, got ${Be(c)}`})}return(typeof e.message!="string"||!e.message)&&i.push({path:`${t}/message`,message:"message is the text shown when the requirement fails"}),i}case"records.upsert":{if(!we(a))return[{path:l,message:"records.upsert is {kind, data, id?}"}];const c=typeof a.kind=="string"?a.kind:"",u=nn(r,c)&&we(r[c])?r[c]:null;if(u||i.push({path:`${l}/kind`,message:`records:${c} names no declared kind`}),a.id!==void 0){const h=oo(a.id,`${l}/id`,n,i);h!==null&&!Co("string",h)&&i.push({path:`${l}/id`,message:`id is a string, got ${Be(h)}`})}if(!we(a.data))return[...i,{path:`${l}/data`,message:"data is an object of field expressions"}];const d=u&&we(u.schema)?u.schema:null,p=d&&we(d.properties)?d.properties:{};for(const h of Object.keys(a.data).sort()){const f=`${l}/data/${fn(h)}`,y=oo(a.data[h],f,n,i);if(!d)continue;if(!nn(p,h)){d.additionalProperties!==!0&&i.push({path:f,message:`${h} is not in the schema of ${c}`});continue}const v=Array.isArray(d.required)&&d.required.includes(h)?Ur(p[h]):Ze(Ur(p[h]));y!==null&&!Co(v,y)&&i.push({path:f,message:`${h} is ${Be(v)}, got ${Be(y)}`})}if(d&&a.id===void 0&&Array.isArray(d.required))for(const h of d.required)typeof h=="string"&&!nn(a.data,h)&&i.push({path:`${l}/data`,message:`${h} is required by ${c}`});return i}case"records.delete":{if(!we(a)||a.id===void 0)return[{path:l,message:"records.delete is {id}"}];const c=oo(a.id,`${l}/id`,n,i);return c!==null&&!Co("string",c)&&i.push({path:`${l}/id`,message:`id is a string, got ${Be(c)}`}),i}case"set":return(!we(a)||typeof a.path!="string"||!hy.test(a.path))&&i.push({path:`${l}/path`,message:"path is a JSON pointer"}),we(a)&&oo(a.value??null,`${l}/value`,n,i),i;case"call":{if(typeof a!="string"||!a)return[{path:l,message:"call names a host function"}];const c=Si(a);if(c==="write"?i.push({path:l,message:`${na(a,c)}: use a records.upsert, records.delete or set step`}):c==="pure"?i.push({path:l,message:`${a} is pure: compute it in an expression`}):tl(a)!==null?i.push({path:l,message:"an action never runs another action"}):a!==So&&o!==null&&!o.some(u=>u===a||u.endsWith("*")&&a.startsWith(u.slice(0,-1)))&&i.push({path:l,message:`${a} is not in the package's functions`}),e.args!==void 0)if(!we(e.args))i.push({path:`${t}/args`,message:"args is an object of expressions"});else for(const u of Object.keys(e.args).sort())oo(e.args[u],`${t}/args/${fn(u)}`,n,i);return i}}return i}function lA(e){const t=[];if(!we(e.templates))return t;const n=we(e.actions)?e.actions:{},r=(o,i)=>{if(Array.isArray(o))return o.forEach((s,a)=>r(s,`${i}/${a}`));if(we(o)){if(typeof o.call=="string"){const s=Si(o.call);s!=="pure"&&t.push({path:`${i}/call`,message:`${na(o.call,s)}: a binding is pure, name an action in on.press`})}for(const[s,a]of Object.entries(o))r(a,`${i}/${fn(s)}`)}};for(const[o,i]of Object.entries(e.templates))!we(i)||!Array.isArray(i.components)||i.components.forEach((s,a)=>{if(!we(s))return;const l=`/templates/${fn(o)}/components/${a}`;for(const[c,u]of Object.entries(s)){if(c!=="on"){r(u,`${l}/${fn(c)}`);continue}if(we(u))for(const[d,p]of Object.entries(u)){const h=`${l}/on/${fn(d)}`;if(we(p))for(const[f,y]of Object.entries(p)){if(f!=="functionCall"||!we(y)){r(y,`${h}/${fn(f)}`);continue}const g=typeof y.call=="string"?y.call:"",v=tl(g);v!==null&&!nn(n,v)&&t.push({path:`${h}/functionCall/call`,message:`action ${v} names no package action`}),v!==null&&nn(n,v)&&we(n[v])&&t.push(...cA(v,n[v],y.args,`${h}/functionCall/args`)),g==="bind"&&t.push(...uA(e,y.args,`${h}/functionCall/args`));for(const[m,b]of Object.entries(y))m!=="call"&&r(b,`${h}/functionCall/${fn(m)}`)}}}});return t}function cA(e,t,n,r){if(n!==void 0&&!we(n))return[{path:r,message:`args is an object of action ${e}'s params`}];const o=[],i=we(t.params)?t.params:{},s=we(i.properties)?i.properties:{},a=Array.isArray(i.required)?i.required.filter(c=>typeof c=="string"):[],l=we(n)?n:{};for(const c of Object.keys(l).sort()){const u=`${r}/${fn(c)}`;if(!nn(s,c)){i.additionalProperties!==!0&&o.push({path:u,message:`${c} is not a param of action ${e}`});continue}const d=l[c];if(typeof d!="string"&&typeof d!="number"&&typeof d!="boolean")continue;const p=a.includes(c)?Ur(s[c]):Ze(Ur(s[c])),h=Fi(d);Co(p,h)||o.push({path:u,message:`${c} is ${Be(p)}, got ${Be(h)}`})}for(const c of a)nn(l,c)||o.push({path:r,message:`${c} is required by action ${e}`});return o}function uA(e,t,n){if(!we(t)||typeof t.source!="string")return[];const r=t.source,o=`${n}/source`,i=Qt(r);if(!i)return[{path:o,message:"source is a scheme:name URI"}];const s=[];if(Array.isArray(e.sources)&&e.sources.every(a=>typeof a=="string")&&!nl(e.sources,r)&&s.push({path:o,message:`source ${r} is not in the package's sources`}),i.scheme===Hr){(!we(e.records)||!nn(e.records,i.name))&&s.push({path:o,message:`records:${i.name} names no declared kind`});const a=i.params.query;a!==void 0&&(!we(e.queries)||!nn(e.queries,a))&&s.push({path:o,message:`query ${a} names no package query`})}return s}class gy extends Error{}const At=e=>{throw new gy(e)},ba=e=>e.map(t=>`${t.path||"/"} ${t.message}`).join("; ");function yy(e,t,n,r={}){const o=we(e.actions)?e.actions:{},i=nn(o,t)&&we(o[t])?o[t]:null;if(!i||!Array.isArray(i.steps))return{error:`no action ${t}`};const s=n??{};if(!we(s))return{error:"params is an object"};if(we(i.params)){const d=Di(i.params,s);if(d.length)return{error:`params: ${ba(d)}`}}const a={params:s,data:r.data??null,me:r.me??null},l=we(e.records)?e.records:{};let c=r.maxSteps??zi.maxSteps;const u={writes:[],sets:[],calls:[]};try{i.steps.forEach((d,p)=>{const h=`step ${p}`,f=m=>{c-=m,c<0&&At(`${h}: action step limit exceeded`)};f(1);const y=m=>{if(typeof m!="string")return m;const b=Wo(m);if("error"in b)return At(`${h}: ${b.error}`);const x=Math.min(Po.maxSteps,c),{result:$,steps:S}=wx(b.ast,a,{now:r.now,offset:r.offset,maxSteps:x});return"error"in $&&($.error==="step limit exceeded"&&x===c&&At(`${h}: action step limit exceeded`),At(`${h}: ${$.error}`)),f(S),$.value},g=my(d);if(g===null||!we(d))return At(`${h}: a step is one of ${Ju.join(", ")}`);const v=d[g];switch(g){case"require":{const m=y(v);typeof m!="boolean"&&At(`${h}: require needs a bool, got ${We(m)}`),m||At(typeof d.message=="string"&&d.message?d.message:`${h}: requirement failed`);return}case"records.upsert":{if(!we(v)||!we(v.data))return At(`${h}: records.upsert is {kind, data, id?}`);const m=typeof v.kind=="string"?v.kind:"",b=nn(l,m)&&we(l[m])?l[m]:null;if(!b||!we(b.schema))return At(`${h}: records: no kind ${m}`);let x;if(v.id!==void 0){const C=y(v.id);(typeof C!="string"||!C)&&At(`${h}: id is a string, got ${We(C)}`),x=C}const $={};for(const C of Object.keys(v.data).sort())$[C]=y(v.data[C]);const S=b.schema,A=Di(x===void 0?S:{...S,required:[]},$);A.length&&At(`${h}: records: ${ba(A)}`),u.writes.push(x===void 0?{op:"upsert",kind:m,data:$}:{op:"upsert",kind:m,data:$,id:x});return}case"records.delete":{if(!we(v))return At(`${h}: records.delete is {id}`);const m=y(v.id);(typeof m!="string"||!m)&&At(`${h}: id is a string, got ${We(m)}`),u.writes.push({op:"delete",id:m});return}case"set":{if(!we(v)||typeof v.path!="string"||!hy.test(v.path))return At(`${h}: path is a JSON pointer`);u.sets.push({path:v.path,value:y(v.value??null)});return}case"call":{if(typeof v!="string"||Si(v)!=="host"||tl(v)!==null)return At(`${h}: call names a host function`);const m={};if(we(d.args))for(const b of Object.keys(d.args).sort())m[b]=y(d.args[b]);u.calls.push({name:v,args:m});return}}})}catch(d){if(d instanceof gy)return{error:d.message};throw d}return{plan:u}}function dA(e,t,n){let r=[...e];const o=[];let i=0;for(const[s,a]of t.entries()){const l=`write ${s}`,c={id:n.me??null,role:n.role??null,access:n.access},u=(v,m,b)=>n.role===void 0?null:Rc(Dc(n.records?.[v]),m,c,b),d=v=>r.find(m=>m.id===v&&(n.role===void 0||Rc(Dc(n.records?.[m.kind]),"read",c,m)===null));if(a.op==="delete"){const v=d(a.id);if(!v)return{error:`${l}: record ${a.id} not found`};const m=u(v.kind,"delete",v);if(m)return{error:`${l}: ${m}`};r=r.filter(b=>b.id!==a.id),o.push(a.id);continue}const p=n.records&&nn(n.records,a.kind)&&we(n.records[a.kind])?n.records[a.kind]:null;if(!p||!we(p.schema))return{error:`${l}: records: no kind ${a.kind}`};const h=p.schema;if(a.id!==void 0){const v=d(a.id);if(!v)return{error:`${l}: record ${a.id} not found`};if(v.kind!==a.kind)return{error:`${l}: record ${a.id} is not of kind ${a.kind}`};const m=u(a.kind,"update",v);if(m)return{error:`${l}: ${m}`};const b={...v.data,...a.data},x=Di(h,b);if(x.length)return{error:`${l}: records: ${ba(x)}`};r=r.map($=>$.id===a.id?{...$,data:b,updatedAt:n.now}:$),o.push(a.id);continue}const f=u(a.kind,"create");if(f)return{error:`${l}: ${f}`};const y=Di(h,a.data);if(y.length)return{error:`${l}: records: ${ba(y)}`};const g=n.newId(i++);r.push({id:g,kind:a.kind,data:{...a.data},createdBy:n.me??null,authorId:n.me??null,createdAt:n.now,updatedAt:n.now}),o.push(g)}return{rows:r,ids:o}}const va={tests:50,gotMax:300},Ll={now:"2026-01-01T00:00:00.000Z",as:"member",role:"member"},pA=["member","owner"],lf=["expr","query","action"],Ke=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),ai=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),fA=e=>e.replace(/~/g,"~0").replace(/\//g,"~1"),by=["id","author"];function Uc(e,t){return Ke(e)?Ke(t)&&Object.keys(e).every(n=>Uc(e[n],ai(t,n)?t[n]:null)):Array.isArray(e)?Array.isArray(t)&&t.length===e.length&&e.every((n,r)=>Uc(n,t[r])):(e??null)===(t??null)}function vy(e){const t=e.tests;if(t===void 0)return[];if(!Array.isArray(t))return[{path:"/tests",message:"tests is a list of {name, expr | query | action, expect}"}];const n=[];t.length>va.tests&&n.push({path:"/tests",message:`at most ${va.tests} tests`});const r=Ke(e.records)?e.records:{},o=Ke(e.queries)?e.queries:{},i=Ke(e.actions)?e.actions:{};return t.forEach((s,a)=>{const l=`/tests/${a}`;if(!Ke(s))return void n.push({path:l,message:"a test is {name, expr | query | action, expect}"});(typeof s.name!="string"||!s.name.trim())&&n.push({path:`${l}/name`,message:"name is a non-empty string"});const c=lf.filter(h=>s[h]!==void 0);if(c.length!==1&&n.push({path:l,message:`a test runs one of ${lf.join(", ")}`}),ai(s,"expect")||n.push({path:`${l}/expect`,message:"expect is required"}),s.now!==void 0&&(typeof s.now!="string"||qa(s.now)===null)&&n.push({path:`${l}/now`,message:"now is an ISO timestamp"}),s.as!==void 0&&(typeof s.as!="string"||!s.as)&&n.push({path:`${l}/as`,message:"as is a member id"}),s.role!==void 0&&!pA.includes(s.role)&&n.push({path:`${l}/role`,message:"role is member or owner"}),s.records!==void 0)if(!Ke(s.records))n.push({path:`${l}/records`,message:"records is {<kind>: [rows]}"});else for(const h of Object.keys(s.records).sort()){const f=`${l}/records/${fA(h)}`,y=ai(r,h)&&Ke(r[h])?r[h]:null;if(!y||!Ke(y.schema)){n.push({path:f,message:`records:${h} names no declared kind`});continue}const g=s.records[h];if(!Array.isArray(g)){n.push({path:f,message:"a kind's sample is a list of rows"});continue}g.forEach((v,m)=>{if(!Ke(v))return void n.push({path:`${f}/${m}`,message:"a row is an object"});for(const b of by)v[b]!==void 0&&(typeof v[b]!="string"||!v[b])&&n.push({path:`${f}/${m}/${b}`,message:`${b} is a non-empty string`});for(const b of Di(y.schema,$y(v)))n.push({path:`${f}/${m}${b.path}`,message:b.message})})}if(c.length!==1)return;const u=c[0],d=s[u],p=`${l}/${u}`;if(u==="expr")!Ke(d)||typeof d.expr!="string"?n.push({path:`${p}/expr`,message:"expr is a string"}):d.vars!==void 0&&!Ke(d.vars)&&n.push({path:`${p}/vars`,message:"vars is an object"});else if(u==="query"){const h=Ke(d)&&typeof d.name=="string"?d.name:"";ai(o,h)||n.push({path:`${p}/name`,message:`query ${h} names no package query`}),Ke(d)&&d.params!==void 0&&!Ke(d.params)&&n.push({path:`${p}/params`,message:"params is an object"})}else{const h=Ke(d)&&typeof d.name=="string"?d.name:"";ai(i,h)||n.push({path:`${p}/name`,message:`action ${h} names no package action`})}}),n}function $y(e){const t={};for(const[n,r]of Object.entries(e))by.includes(n)||(t[n]=r);return t}function hA(e,t,n){const r=[];if(!Ke(e))return r;for(const o of Object.keys(e).sort()){const i=e[o];Array.isArray(i)&&i.forEach((s,a)=>{if(!Ke(s))return;const l=typeof s.author=="string"?s.author:t;r.push({id:typeof s.id=="string"?s.id:`${o}-${a+1}`,kind:o,data:$y(s),createdBy:l,authorId:l,createdAt:n,updatedAt:n})})}return r}function mA(e,t,n,r,o){return!Ke(e)||Object.keys(e).length!==1||typeof e.source!="string"?e:xy(e.source,t,n,r,o)}function xy(e,t,n,r,o){const i=Zu(e,Ke(t.queries)?t.queries:void 0),s=Qt(i),a=s?.scheme===Hr?iy(s):null;return a?mC(n,a,{me:r,now:o,computed:a.app===null?dC(t.records,a.from):void 0,refs:a.app===null?pC(t.records,a.from):void 0,transitions:a.app===null&&a.from&&Ke(t.records)?xS(t.records[a.from]):null})??null:{error:`${e} is not a records source`}}function gA(e,t){const n=typeof t.now=="string"?t.now:Ll.now,r=qa(n),o=typeof t.as=="string"?t.as:Ll.as,i=typeof t.role=="string"?t.role:Ll.role,s=Ke(e.records)?e.records:void 0,a=hA(t.records,o,n),l=Np(a,s,{id:o,role:i});if(Ke(t.expr)){const h={};if(Ke(t.expr.vars))for(const[y,g]of Object.entries(t.expr.vars))h[y]=mA(g,e,l,o,n);const f=Iu(t.expr.expr,h,{now:r});return"error"in f?{error:f.error}:f.value}if(Ke(t.query)){const h=t.query.name,f=e.queries[h],y=Ke(f)&&typeof f.from=="string"?f.from:"",g={};if(Ke(t.query.params))for(const[v,m]of Object.entries(t.query.params))g[v]=typeof m=="string"?m:Wr(m);return xy(Gu(`${Hr}:${y}`,{query:h,...g}),e,l,o,n)}const c=t.action,u=yy(e,c.name,c.params,{data:c.data,me:o,now:r});if("error"in u)return{error:u.error};const d=dA(a,u.plan.writes,{records:s,me:o,role:i,now:n,newId:h=>`new-${h+1}`});if("error"in d)return{error:d.error};const p={};for(const h of Np(d.rows,s,{id:o,role:i}))(p[h.kind]??=[]).push({...h.data,id:h.id,author:h.authorId??h.createdBy});return{records:p,sets:u.plan.sets,calls:u.plan.calls}}function yA(e){return!Array.isArray(e.tests)||vy(e).length?[]:e.tests.map(t=>{const n=gA(e,t);return{name:t.name,pass:Uc(t.expect,n),got:n}})}function bA(e,t,n){const r=Array.from(Wr(n??null)),o=r.length>va.gotMax?`${r.slice(0,va.gotMax).join("")}…`:r.join("");return`${e}: expected ${Wr(t??null)}, got ${o}`}function vA(e){const t=Array.isArray(e.tests)?e.tests:[];return yA(e).flatMap((n,r)=>n.pass?[]:[{path:`/tests/${r}`,message:bA(n.name,t[r].expect,n.got)}])}const cf={date:104,time:64,"date-time":152,number:64,integer:64,boolean:56},$A=136,xA=80,wA=200,kA="/recordForm",SA="/recordTable",Qu=e=>!!e&&typeof e=="object"&&!Array.isArray(e);function ed(e){const t=e.replace(/_/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").trim().toLowerCase();return t?t[0].toUpperCase()+t.slice(1):e}function td(e){const t=Object.keys(e.schema.properties),n=(e.schema.required??[]).filter((r,o,i)=>t.includes(r)&&i.indexOf(r)===o);return[...n,...t.filter(r=>!n.includes(r)).sort()]}const nd=e=>e.format==="attachment"||e.type==="array"&&e.items?.format==="attachment";function uf(e,t){const n=e.schema.required??[],r=e.refs??{};return td(e).flatMap(o=>{const i=e.schema.properties[o];if(nd(i))return[];const s={path:`${t}/${o}`},a={name:o,label:ed(o),widget:"text",required:n.includes(o),wide:!1,value:s};i.description&&(a.placeholder=i.description);const l=r[o];l==="member"?Object.assign(a,{widget:"select",source:"exp:members",searchable:!0}):l==="issue"?Object.assign(a,{widget:"select",source:"exp:issues",searchable:!0}):i.type==="boolean"?a.widget="switch":i.type==="number"||i.type==="integer"?(a.widget="number",i.minimum!==void 0&&(a.min=i.minimum),i.maximum!==void 0&&(a.max=i.maximum),i.type==="integer"&&Object.assign(a,{step:1,precision:0})):i.type==="array"?(i.items?.enum?Object.assign(a,{widget:"select",multiple:!0,options:i.items.enum.map(u=>({label:u,value:u}))}):a.widget="chips",i.maxLength!==void 0&&(a.max=i.maxLength),a.wide=!0):i.enum?Object.assign(a,{widget:"select",options:i.enum.map(u=>({label:u,value:u}))}):i.format==="date"?a.widget="date":i.format==="time"?a.widget="time":i.format==="date-time"?a.placeholder??="YYYY-MM-DDTHH:MM":(i.maxLength===void 0||i.maxLength>wA)&&Object.assign(a,{widget:"textarea",wide:!0});const c=[];return a.required&&a.widget!=="switch"&&c.push({condition:{call:"required",args:{value:s}},message:"$string.required"}),i.type==="string"&&i.maxLength!==void 0&&!i.enum&&a.widget!=="select"&&c.push({condition:{call:"length",args:{value:s,max:i.maxLength}},message:"$string.invalidValue"}),(i.type==="number"||i.type==="integer")&&(i.minimum!==void 0||i.maximum!==void 0)&&c.push({condition:{call:"numeric",args:{value:s,...i.minimum!==void 0?{min:i.minimum}:{},...i.maximum!==void 0?{max:i.maximum}:{}}},message:"$string.invalidValue"}),c.length&&(a.checks=c),[a]})}function CA(e,t,n){const o=(t??td(e)).filter(i=>e.schema.properties[i]&&!nd(e.schema.properties[i])).map(i=>{const s=e.schema.properties[i],a={key:i,label:ed(i),sortable:!0};s.type==="number"||s.type==="integer"?Object.assign(a,{type:"number",align:"end"}):s.type==="boolean"?a.type="boolean":s.format==="date"&&(a.type="date");const l=s.type==="string"?s.format?cf[s.format]:void 0:cf[s.type];return l!==void 0?a.width=l:a.truncate=!0,a});return o.push({key:"updatedAt",label:"Updated",type:"relativeTime",width:$A,sortable:!0}),n&&o.push({key:"menu",label:"",type:"slot",slot:"menu",width:xA}),o}const io=(e,t)=>({functionCall:{call:"set",args:{path:e,value:t}}}),sr=(e,t,n)=>{const r=e.on=Qu(e.on)?{...e.on}:{};r[t]===void 0&&(r[t]=n)};function df(e,t,n){const r={};for(const i of t)r[i.name]=i.value;const o={kind:e};return n!==void 0&&(o.id=n),o.data=r,{functionCall:{call:"records.upsert",args:o}}}function wy(e,t=[],n,r={}){const o=[],i=[],s=[...t];for(const a of e){if(!Qu(a)||a.component!=="RecordForm"&&a.component!=="RecordTable"){o.push(a);continue}const l={...a},c=String(l.id),u=typeof l.kind=="string"?l.kind:"",d=n&&Object.prototype.hasOwnProperty.call(n,u)?n[u]:void 0;if(!d){l.missing=!0,o.push(l);continue}if(l.component==="RecordForm"){const x=typeof l.path=="string"?l.path:`${kA}/${c}`,$=uf(d,x);l.path=x,l.fields=$,r.readOnly&&(l.readOnly=!0),sr(l,"submit",df(u,$,l.recordId)),o.push(l);continue}const p=`${SA}/${c}`,h=l.editable!==!1&&!r.readOnly,f=Array.isArray(l.columns)?l.columns.filter(x=>typeof x=="string"):void 0,y=`${p}/editor/draft`,g=uf(d,y);l.title=d.title??ed(u),l.cols=CA(d,f,h),l.rows={path:`${p}/rows/rows`},l.count={call:"fill",args:{template:"$string.recordCount",params:{count:{call:"coalesce",args:{values:[{path:`${p}/rows/count`},0]}}}}},l.loading={call:"not",args:{value:{path:`${p}/rows`}}},r.readOnly&&(l.add=!1),l.editable=h,l.children={componentId:`${c}__row`,path:`${p}/rows/rows`,key:"id"},h?(l.fields=g,l.path=y,l.editorOpen={path:`${p}/editor/open`},l.editorId={path:`${y}/id`},l.deleteOpen={path:`${p}/delete/open`},sr(l,"add",io(`${p}/editor`,{open:!0,draft:{}})),sr(l,"edit",io(`${p}/editor`,{open:!0,draft:{path:""}})),sr(l,"delete",io(`${p}/delete`,{open:!0,id:{path:"id"}})),sr(l,"submit",df(u,g,{path:`${y}/id`})),sr(l,"cancel",io(`${p}/editor/open`,!1)),sr(l,"confirm",{functionCall:{call:"records.delete",args:{id:{path:`${p}/delete/id`}}}}),sr(l,"cancelDelete",io(`${p}/delete/open`,!1))):l.add=!1,o.push(l);const v=(f??td(d)).filter(x=>d.schema.properties[x]&&!nd(d.schema.properties[x])),m={id:`${c}__row`,component:"Row",title:{call:"coalesce",args:{values:[{call:"text",args:{value:{path:v[0]??"id"}}},"—"]}}};v[1]&&(m.subtitle={call:"coalesce",args:{values:[{call:"text",args:{value:{path:v[1]}}},""]}}),m.meta={call:"formatRelativeTime",args:{value:{path:"updatedAt"}}},h&&(m.on={press:io(`${p}/editor`,{open:!0,draft:{path:""}})}),i.push(m);const b=typeof l.query=="string"&&l.query.trim()?l.query.trim().replace(/^\?/,""):"sort=updatedAt&order=desc";s.push({path:`${p}/rows`,source:`records:${u}?${b}`})}return{components:[...o,...i],bindings:s}}function ky(e){return e.some(t=>Qu(t)&&(t.component==="RecordForm"||t.component==="RecordTable"))}const hn=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Sy=e=>e.replace(/~/g,"~0").replace(/\//g,"~1"),AA=[jr,vu,ja];function _A(e,t){const n=[],r=e.children;if(r!=null){const o=Array.isArray(r)&&r.every(s=>typeof s=="string"),i=hn(r)&&typeof r.componentId=="string"&&typeof r.path=="string"&&(r.key===void 0||r.key===null||typeof r.key=="string");!o&&!i&&n.push({path:`${t}/children`,message:"children is a list of ids or {componentId, path, key?}"})}return e.slots!==void 0&&e.slots!==null&&(!hn(e.slots)||Object.values(e.slots).some(o=>typeof o!="string"))&&n.push({path:`${t}/slots`,message:"slots is an object of component ids"}),e.on!==void 0&&e.on!==null&&!hn(e.on)&&n.push({path:`${t}/on`,message:"on is an object of actions"}),e.style!==void 0&&e.style!==null&&!hn(e.style)&&n.push({path:`${t}/style`,message:"style is an object"}),n}function OA(e,t,n){const r=[];return e.forEach((o,i)=>{const s=`${n}/${i}`;if(Array.isArray(o.children)?o.children.forEach((a,l)=>a===t&&r.push(`${s}/children/${l}`)):hn(o.children)&&o.children.componentId===t&&r.push(`${s}/children/componentId`),hn(o.slots))for(const[a,l]of Object.entries(o.slots))l===t&&r.push(`${s}/slots/${Sy(a)}`)}),r}function TA(e,t,n=[]){const r=[],o=typeof e.catalogId=="string"?e.catalogId:"";if(!t.includes(o)||!hn(e.templates))return r;const i=c=>AA.includes(c)||n.some(u=>u.id===c),s=Array.isArray(e.extensions)?e.extensions.map(c=>hn(c)&&typeof c.id=="string"?c.id:""):[],a=!i(o)||s.some(c=>c&&!i(c)),l=i(o)?o:jr;for(const[c,u]of Object.entries(e.templates)){if(!hn(u)||!Array.isArray(u.components))continue;const d=`/templates/${Sy(c)}/components`,p=u.components,h=new Set;let f=p.length>0;for(const S of p)!hn(S)||typeof S.id!="string"||typeof S.component!="string"||h.has(S.id)?f=!1:h.add(S.id);if(!f||!h.has("root"))continue;const y=p,g=y.flatMap((S,A)=>_A(S,`${d}/${A}`));if(g.length){r.push(...g);continue}const v=new Map(y.map((S,A)=>[S.id,A])),m=hn(e.records)?e.records:void 0,b=ky(y)?wy(y,[],m).components:y;for(const S of b){const A=typeof S.id=="string"&&S.id.endsWith("__row")?v.get(S.id.slice(0,-5)):void 0;A!==void 0&&!v.has(S.id)&&v.set(S.id,A)}const x=new Set,$=(S,A)=>{const C=`${S}
23
+ `);if(this.data=[],this.event="",!U2.includes(n))return;const o=jg(r);t.messages.push(...o.messages),o.issues.length&&t.issues.push({at:this.count,message:`event ${this.count} is not JSON`})}}const Ic=/^[a-z][a-z0-9_]{0,31}$/,uS=["id","createdAt","updatedAt","createdBy","authorId","author"],Rp=["string","number","integer","boolean","array"],Fp=["string","number","integer","boolean"],ws=["date","date-time","time","attachment"],dS=/^\/api\/attachments\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/,Zt=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Fl=e=>Array.isArray(e)&&e.every(t=>typeof t=="string");function Bg(e,t){const n=[];if(!Zt(e)||e.type!=="object"||!Zt(e.properties))return[{path:t,message:'a record schema is {type: "object", properties}'}];for(const r of Object.keys(e.properties).sort()){const o=e.properties[r],i=`${t}/properties/${r}`;if(uS.includes(r)&&n.push({path:i,message:`${r} is a reserved record key`}),!Zt(o)||typeof o.type!="string"||!Rp.includes(o.type)){n.push({path:i,message:`a field is {type: ${Rp.join("|")}}`});continue}if(o.enum!==void 0&&(!Fl(o.enum)||!o.enum.length||o.type!=="string")&&n.push({path:`${i}/enum`,message:"enum is a non-empty list of strings on a string field"}),o.type==="array"){const s=o.items;!Zt(s)||typeof s.type!="string"||!Fp.includes(s.type)?n.push({path:`${i}/items`,message:`items is {type: ${Fp.join("|")}}`}):(s.enum!==void 0&&(!Fl(s.enum)||!s.enum.length||s.type!=="string")&&n.push({path:`${i}/items/enum`,message:"enum is a non-empty list of strings on a string item"}),s.format!==void 0&&(typeof s.format!="string"||!ws.includes(s.format)||s.type!=="string")&&n.push({path:`${i}/items/format`,message:`format is ${ws.join("|")} on a string item`}))}else o.items!==void 0&&n.push({path:`${i}/items`,message:"items belongs to an array field"});o.format!==void 0&&(typeof o.format!="string"||!ws.includes(o.format)||o.type!=="string")&&n.push({path:`${i}/format`,message:`format is ${ws.join("|")} on a string field`});for(const s of["maxLength","minimum","maximum"])o[s]!==void 0&&typeof o[s]!="number"&&n.push({path:`${i}/${s}`,message:`${s} is a number`})}return e.required!==void 0&&(Fl(e.required)?e.required.forEach((r,o)=>{Object.prototype.hasOwnProperty.call(e.properties,r)||n.push({path:`${t}/required/${o}`,message:`${r} is not a declared field`})}):n.push({path:`${t}/required`,message:"required is a list of field names"})),e.additionalProperties!==void 0&&typeof e.additionalProperties!="boolean"&&n.push({path:`${t}/additionalProperties`,message:"additionalProperties is a boolean"}),n}const pS=/^\d{4}-\d{2}-\d{2}$/,fS=/^\d{2}:\d{2}(:\d{2})?$/,hS=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/;function zp(e,t,n,r){const o=[];switch(e){case"string":return typeof t!="string"?[{path:n,message:"a string"}]:(r.enum&&!r.enum.includes(t)&&o.push({path:n,message:`one of ${r.enum.join("|")}`}),r.maxLength!==void 0&&[...t].length>r.maxLength&&o.push({path:n,message:`at most ${r.maxLength} characters`}),r.format==="date"&&!pS.test(t)&&o.push({path:n,message:"a date (YYYY-MM-DD)"}),r.format==="date-time"&&!hS.test(t)&&o.push({path:n,message:"a date-time (ISO 8601)"}),r.format==="time"&&!fS.test(t)&&o.push({path:n,message:"a time (HH:MM)"}),r.format==="attachment"&&!dS.test(t)&&o.push({path:n,message:"an attachment (/api/attachments/<id>)"}),o);case"number":case"integer":return typeof t!="number"||!Number.isFinite(t)?[{path:n,message:"a number"}]:e==="integer"&&!Number.isInteger(t)?[{path:n,message:"an integer"}]:(r.minimum!==void 0&&t<r.minimum&&o.push({path:n,message:`at least ${r.minimum}`}),r.maximum!==void 0&&t>r.maximum&&o.push({path:n,message:`at most ${r.maximum}`}),o);case"boolean":return typeof t=="boolean"?[]:[{path:n,message:"a boolean"}];default:return[]}}function Di(e,t){if(!Zt(t))return[{path:"",message:"a record is an object"}];const n=[],r=new Set(e.required??[]);for(const o of Object.keys(e.properties).sort()){const i=e.properties[o],s=t[o];if(s==null){r.has(o)&&n.push({path:`/${o}`,message:"required"});continue}if(i.type==="array"){if(!Array.isArray(s)){n.push({path:`/${o}`,message:"a list"});continue}i.maxLength!==void 0&&s.length>i.maxLength&&n.push({path:`/${o}`,message:`at most ${i.maxLength} items`});const a=i.items??{type:"string"};s.forEach((l,c)=>n.push(...zp(a.type,l,`/${o}/${c}`,{enum:a.enum,format:a.format})));continue}n.push(...zp(i.type,s,`/${o}`,i))}if(e.additionalProperties!==!0)for(const o of Object.keys(t).sort())Object.prototype.hasOwnProperty.call(e.properties,o)||n.push({path:`/${o}`,message:"not in the schema"});return n}function mS(e,t,n){if(!Zt(e)||e.refs===void 0)return[];const r=e.refs;if(!Zt(r))return[{path:`${t}/refs`,message:'refs is {field: {kind} | "issue" | "member"}'}];const o=Zt(e.schema)&&Zt(e.schema.properties)?e.schema.properties:{},i=[];for(const s of Object.keys(r).sort()){const a=`${t}/refs/${s}`,l=r[s],c=Object.prototype.hasOwnProperty.call(o,s)?o[s]:void 0;if(Zt(c)?c.type!=="string"&&i.push({path:a,message:"a ref is a string field"}):i.push({path:a,message:`${s} is not a declared field`}),!(l==="issue"||l==="member")){if(!Zt(l)||Object.keys(l).length!==1||typeof l.kind!="string"||!l.kind){i.push({path:a,message:'a ref is {kind}, "issue" or "member"'});continue}(!Zt(n)||!Object.prototype.hasOwnProperty.call(n,l.kind))&&i.push({path:`${a}/kind`,message:`records:${l.kind} names no declared kind`})}}return i}const Wg=["read","create","update","delete"],Hg=["member","author","owners"],gS={read:"member",create:"member",update:"author",delete:"author"},ks={none:"You have no access to this app",readOnly:"You have read-only access to this app",author:{read:"Only the record's author or a team owner can read it",update:"Only the record's author or a team owner can change it",delete:"Only the record's author or a team owner can change it"},owners:{read:"Only team owners can read these records",create:"Only team owners can add these records",update:"Only team owners can change these records",delete:"Only team owners can change these records"}},Pc=e=>!!e&&typeof e=="object"&&!Array.isArray(e),qg=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);function yS(e,t){if(!Pc(e))return[{path:t,message:"policy is {read?, create?, update?, delete?}"}];const n=[];for(const r of Object.keys(e).sort()){const o=e[r];Wg.includes(r)?r==="create"&&o==="author"?n.push({path:`${t}/create`,message:"create is member or owners: a new record has no author yet"}):(typeof o!="string"||!Hg.includes(o))&&n.push({path:`${t}/${r}`,message:`${r} is member, author or owners`}):n.push({path:`${t}/${r}`,message:`unknown policy op ${r}: read, create, update or delete`})}return n}function Dc(e){const t={...gS},n=Pc(e)&&Pc(e.policy)?e.policy:null;if(!n)return t;for(const r of Wg){const o=qg(n,r)?n[r]:void 0;typeof o=="string"&&Hg.includes(o)&&!(r==="create"&&o==="author")&&(t[r]=o)}return t}const Ug=e=>e?.authorId??e?.createdBy??null;function Rc(e,t,n,r){const o=n.access??"write";if(n.id===null||n.role===null||o==="none")return ks.none;if(o==="read"&&t!=="read")return ks.readOnly;if(n.role==="owner")return null;const i=e[t];if(i==="member")return null;if(i==="owners"||t==="create")return ks.owners[t];const s=Ug(r);return s!==null&&s===n.id?null:ks.author[t]}const bS=(e,t,n,r)=>Rc(e,t,n,r)===null;function Np(e,t,n){const r=new Map,o=i=>{let s=r.get(i);return s||r.set(i,s=Dc(t&&qg(t,i)?t[i]:void 0)),s};return e.filter(i=>bS(o(i.kind),"read",n,i))}const Ns="transitions",vS=["member","author","owners"],$S=["field","initial","from","who"],ga="->",Dt=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Er=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Fc=e=>Array.isArray(e)&&e.every(t=>typeof t=="string");function xS(e){const t=Dt(e)?e.transitions:void 0;if(!Dt(t)||typeof t.field!="string"||!t.field||!Dt(t.from))return null;const n={};for(const o of Object.keys(t.from))Fc(t.from[o])&&(n[o]=t.from[o]);const r={};if(Dt(t.who))for(const o of Object.keys(t.who))typeof t.who[o]=="string"&&(r[o]=t.who[o]);return{field:t.field,...Fc(t.initial)?{initial:t.initial}:{},from:n,who:r}}function wS(e){if(e.initial)return[...e.initial];const t=Object.keys(e.from).sort(),n=new Set(Object.values(e.from).flat()),r=t.filter(o=>!n.has(o));return r.length?r:t}const Vg=(e,t)=>{const n=e?.[t];return typeof n=="string"&&n!==""?n:null};function kS(e,t,n){const r=e.who??{};return Er(r,`${t}${ga}${n}`)?r[`${t}${ga}${n}`]:Er(r,n)?r[n]:"member"}function SS(e,t,n,r,o,i){if(e==="member"||r.role==="owner")return null;if(e==="owners")return`Only team owners can move ${t} to ${n}`;if(e==="author"){const s=Ug(i);return s!==null&&s===r.id?null:`Only the record's author or a team owner can move ${t} to ${n}`}if(e.startsWith("role:")){const s=e.slice(5),a=Vg(o,s);return a!==null&&a===r.id?null:`Only the record's ${s} or a team owner can move ${t} to ${n}`}return`Nobody can move ${t} to ${n}`}function CS(e,t,n,r){if(!e)return[];const o=Vg(t,e.field);if(o===null)return wS(e);const i=Er(e.from,o)?e.from[o]:[];return n?i.filter(s=>SS(kS(e,o,s),e.field,s,n,t,r)===null):[...i]}function AS(e,t,n){if(!Dt(e)||e.transitions===void 0)return[];const r=e.transitions,o=`${t}/transitions`;if(!Dt(r))return[{path:o,message:"transitions is {field, from, initial?, who?}"}];const i=[];for(const p of Object.keys(r).sort())$S.includes(p)||i.push({path:`${o}/${p}`,message:`unknown key ${p}`});const s=Dt(e.schema)&&Dt(e.schema.properties)?e.schema.properties:{},a=typeof r.field=="string"?r.field:null,l=a!==null&&Er(s,a)?s[a]:void 0;let c=null;a===null||!a?i.push({path:`${o}/field`,message:"field is the name of an enum field"}):Dt(l)?l.type!=="string"||!Fc(l.enum)?i.push({path:`${o}/field`,message:`${a} is not an enum field`}):c=l.enum:i.push({path:`${o}/field`,message:`${a} is not a declared field`});const u=(p,h)=>{typeof p!="string"?i.push({path:h,message:"a state is a string"}):c&&!c.includes(p)&&i.push({path:h,message:`${p} is not a state of ${a}`})};if(!Dt(r.from))i.push({path:`${o}/from`,message:"from is {state: [next state…]}"});else for(const p of Object.keys(r.from).sort()){u(p,`${o}/from/${p}`);const h=r.from[p];Array.isArray(h)?h.forEach((f,y)=>u(f,`${o}/from/${p}/${y}`)):i.push({path:`${o}/from/${p}`,message:"the next states are a list"})}if(r.initial!==void 0&&(!Array.isArray(r.initial)||!r.initial.length?i.push({path:`${o}/initial`,message:"initial is a non-empty list of states"}):r.initial.forEach((p,h)=>u(p,`${o}/initial/${h}`))),r.who!==void 0)if(!Dt(r.who))i.push({path:`${o}/who`,message:'who is {"a->b" | state: level}'});else{const p=Dt(e.refs)?e.refs:{};for(const h of Object.keys(r.who).sort()){const f=`${o}/who/${h}`,y=h.indexOf(ga);if(y>=0){const v=h.slice(0,y),m=h.slice(y+ga.length);Dt(r.from)&&Array.isArray(r.from[v])&&r.from[v].includes(m)||i.push({path:f,message:`${v} → ${m} is not a declared transition`})}else u(h,f);const g=r.who[h];if(typeof g=="string"&&g.startsWith("role:")){const v=g.slice(5);Er(p,v)&&p[v]==="member"||i.push({path:f,message:`${g}: ${v} is not a member ref of ${n}`})}else(typeof g!="string"||!vS.includes(g))&&i.push({path:f,message:"a level is member, author, owners or role:<field>"})}}const d=Dt(e.computed)?e.computed:{};return(Er(s,Ns)||Er(d,Ns))&&i.push({path:o,message:`a kind with transitions declares no field ${Ns} (its rows carry the next states there)`}),i}const Lp=64,jp=32,Kg=["rename","default","drop","map","renameKind"],lr=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Bp=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),_S=/^(0|[1-9]\d*|x|\*)(?:\.(0|[1-9]\d*|x|\*))?(?:\.(0|[1-9]\d*|x|\*))?$/,OS=/^(>=|<=|>|<|=|\^|~)?(.+)$/,TS=/^(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?(?:\.(0|[1-9]\d*))?$/,MS=e=>{const t=TS.exec(e);return t?[Number(t[1]),Number(t[2]??0),Number(t[3]??0)]:null},ES=(e,t)=>e[0]-t[0]||e[1]-t[1]||e[2]-t[2];function IS(e,t){const n=OS.exec(e);if(!n)return null;const r=n[1]??"",o=n[2];if(r===""||r==="="){const a=_S.exec(o);return a?[a[1],a[2],a[3]].every((c,u)=>c===void 0||c==="x"||c==="*"||Number(c)===t[u]):null}const i=MS(o);if(!i)return null;const s=ES(t,i);return r===">="?s>=0:r===">"?s>0:r==="<="?s<=0:r==="<"?s<0:r==="~"?t[0]===i[0]&&t[1]===i[1]&&s>=0:i[0]>0?t[0]===i[0]&&s>=0:i[1]>0?t[0]===0&&t[1]===i[1]&&s>=0:s===0}function PS(e){if(typeof e!="string"||!e.trim())return null;const t=e.split("||").map(n=>n.trim().split(/\s+/).filter(Boolean));if(t.some(n=>!n.length))return null;for(const n of t)for(const r of n)if(IS(r,[0,0,0])===null)return null;return t}const DS=e=>PS(e)!==null,RS=e=>{if(!lr(e))return null;const t=Object.keys(e);return t.length===1&&Kg.includes(t[0])?t[0]:null};function FS(e){if(!lr(e)||e.migrations===void 0)return[];const t=e.migrations;if(!Array.isArray(t))return[{path:"/migrations",message:"migrations is a list of {from, kind, ops}"}];const n=[];t.length>Lp&&n.push({path:"/migrations",message:`at most ${Lp} migrations`});const r=lr(e.records)?e.records:{},o=i=>typeof i=="string"&&i.length>0;return t.forEach((i,s)=>{const a=`/migrations/${s}`;if(!lr(i))return void n.push({path:a,message:"a migration is {from, kind, ops}"});for(const c of Object.keys(i).sort())["from","kind","ops"].includes(c)||n.push({path:`${a}/${c}`,message:`unknown key ${c}`});(typeof i.from!="string"||!DS(i.from))&&n.push({path:`${a}/from`,message:"from is a version or a range (1.2.3, 1.x, ^1.2.0, >=1.0.0 <2.0.0)"});let l=typeof i.kind=="string"&&Ic.test(i.kind)?i.kind:null;if(l===null&&n.push({path:`${a}/kind`,message:"kind is a kind name"}),!Array.isArray(i.ops))return void n.push({path:`${a}/ops`,message:"ops is a list"});i.ops.length>jp&&n.push({path:`${a}/ops`,message:`at most ${jp} ops`}),i.ops.forEach((c,u)=>{const d=`${a}/ops/${u}`,p=RS(c);if(!p)return void n.push({path:d,message:`an op is one of ${Kg.join(", ")}`});const h=c[p],f=y=>n.push({path:`${d}/${p}`,message:`${p} is ${y}`});if(p==="rename"&&!(lr(h)&&o(h.from)&&o(h.to)&&Object.keys(h).length===2))f("{from, to}");else if(p==="default"&&!(lr(h)&&o(h.field)&&Bp(h,"value")&&Object.keys(h).length===2))f("{field, value}");else if(p==="drop"&&!(lr(h)&&o(h.field)&&Object.keys(h).length===1))f("{field}");else if(p==="map")if(!(lr(h)&&o(h.field)&&typeof h.expr=="string"&&Object.keys(h).length===2))f("{field, expr}");else{const y=Wo(h.expr);"error"in y&&n.push({path:`${d}/map/expr`,message:y.error})}else p==="renameKind"&&(typeof h!="string"||!Ic.test(h)?f("a kind name"):l=h)}),l!==null&&!Bp(r,l)&&n.push({path:`${a}/kind`,message:`the migration ends in ${l}, which the package does not declare`})}),n}const Gg=3,Yg=8,Xg=12,Zg=52,zc=["week","month","quarter"],zS=["chart1","chart2","chart3","chart4","chart5","chart6","chart7","chart8"],NS=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],Wp=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],zr=["January","February","March","April","May","June","July","August","September","October","November","December"];function dr(e){const t=Xi(e);return t?bn(t.y,t.m,t.d):null}function LS(e,t){const n=dr(e);if(n===null)return null;const r=t===null?null:dr(t);return{start:n,end:r!==null&&r>=n?r:n}}const Tt=e=>Zi(vt(e)),Jg=e=>((e+3)%7+7)%7,Yu=e=>e-Jg(e);function jS(e){const t=[...new Set(e.filter(r=>r!==""&&!/^[1-8]$/.test(r)))].sort((r,o)=>r<o?-1:r>o?1:0),n=new Map(t.map((r,o)=>[r,o]));return e.map(r=>/^[1-8]$/.test(r)?`chart${r}`:r===""?"chart1":zS[n.get(r)%8])}function Qg(e,t,n){return e.filter(r=>r.end>=t&&r.start<=n).sort((r,o)=>Math.max(r.start,t)-Math.max(o.start,t)||Math.min(o.end,n)-Math.max(o.start,t)-(Math.min(r.end,n)-Math.max(r.start,t))||r.order-o.order)}function ey(e,t,n,r){for(let o=0;o<r;o++){const i=e[o]??=[];let s=!0;for(let a=t;a<=n;a++)i[a]&&(s=!1);if(s){for(let a=t;a<=n;a++)i[a]=!0;return o}}return null}function ty(e,t,n){const r=e+6,o=Qg(t,e,r),i=[],s=[0,0,0,0,0,0,0],a=[];for(const c of o){const u=Math.max(c.start,e)-e,d=Math.min(c.end,r)-e,p=ey(i,u,d,n.lanes);if(p===null){for(let h=u;h<=d;h++)s[h]+=1;continue}a.push({id:c.id,col:u+1,span:d-u+1,lane:p,contL:c.start<e,contR:c.end>r,tone:c.tone,more:0,row:c.value})}s.forEach((c,u)=>{c>0&&a.push({id:`more:${Tt(e+u)}`,col:u+1,span:1,lane:n.lanes,contL:!1,contR:!1,tone:null,more:c,row:null})});const l=[];for(let c=0;c<7;c++){const u=e+c,d=vt(u),p=o.filter(h=>h.start<=u&&h.end>=u);l.push({date:Zi(d),day:d.d,weekday:Wp[c],initial:Wp[c].slice(0,1),inMonth:n.month===null||d.m===n.month,weekend:c>=5,today:u===n.today,selected:u===n.selected,total:p.length,dots:p.slice(0,3).map(h=>({tone:h.tone}))})}return{key:Tt(e),days:l,segments:a}}function ny(e,t){const n=vt(e),r=vt(t),o=`${r.d} ${zr[r.m-1]} ${r.y}`;return n.y!==r.y?`${n.d} ${zr[n.m-1]} ${n.y} – ${o}`:n.m!==r.m?`${n.d} ${zr[n.m-1]} – ${o}`:`${n.d} – ${o}`}function BS(e){const t=vt(e);return`${NS[Jg(e)]}, ${t.d} ${zr[t.m-1]}`}function WS(e,t,n,r,o){const i=bn(e,t,1),s=bn(e,t,n),a=o.day===null?null:dr(o.day),l=a!==null&&a>=i&&a<=s?a:o.today>=i&&o.today<=s?o.today:i,c=[];for(let d=Yu(i);d<=s;d+=7)c.push(ty(d,r,{lanes:o.lanes,today:o.today,selected:l,month:t}));const u=Qg(r,l,l).map(d=>({id:d.id,tone:d.tone,start:Tt(d.start),end:Tt(d.end),days:d.end-d.start+1,row:d.value}));return{weeks:c,day:Tt(l),agenda:{date:Tt(l),label:BS(l),count:u.length,items:u}}}function HS(e,t,n){const r=Yu(e),o=ty(r,t,{lanes:n.lanes,today:n.today,selected:null,month:null});return{key:o.key,label:ny(r,r+6),prev:Tt(r-7),next:Tt(r+7),today:Tt(n.today),days:o.days,segments:o.segments}}function Nc(e,t){if(t==="week")return Yu(e);const n=vt(e);return bn(n.y,t==="month"?n.m:Math.floor((n.m-1)/3)*3+1,1)}function Lc(e,t,n){if(t==="week")return e+7*n;const r=vt(e),o=r.y*12+(r.m-1)+n*(t==="month"?1:3);return bn(Math.floor(o/12),(o%12+12)%12+1,1)}function qS(e,t){const n=zr[e.m-1].slice(0,3);return t==="week"?`${e.d} ${n}`:t==="month"?n:`Q${Math.floor((e.m-1)/3)+1}`}function US(e,t,n){const r=Nc(e,n.scale),o=[];for(let h=0;h<=n.columns;h++)o.push(Lc(r,n.scale,h));const i=o[n.columns]-1,s=h=>{let f=0;for(;f+1<n.columns&&o[f+1]<=h;)f++;return f},a=vt(r).y,l=o.slice(0,n.columns).map((h,f)=>({key:Tt(h),label:qS(vt(h),n.scale),end:Tt(o[f+1]-1),today:n.today>=h&&n.today<o[f+1]})),c=[];o.slice(0,n.columns).forEach((h,f)=>{const y=vt(h),g=n.scale==="week"?y.y===a?zr[y.m-1]:`${zr[y.m-1]} ${y.y}`:String(y.y),v=c[c.length-1];v&&v.label===g?v.span+=1:c.push({label:g,col:f+1,span:1})});const u=[],d=new Map;for(const h of[...t].sort((f,y)=>f.order-y.order)){if(h.end<r||h.start>i)continue;const f=h.rowKey??h.id,y=d.get(f);y?y.push(h):d.set(f,[h])}for(const[h,f]of d){const y=u.length,g=[],v=[],m=f.map(b=>({s:b,first:s(Math.max(b.start,r)),last:s(Math.min(b.end,i))})).sort((b,x)=>b.first-x.first||x.last-x.first-(b.last-b.first)||b.s.order-x.s.order);for(const{s:b,first:x,last:$}of m){const S=ey(g,x,$,Number.MAX_SAFE_INTEGER);v.push({id:b.id,rowIndex:y,col:x+1,span:$-x+1,lane:S,contL:b.start<r,contR:b.end>i,tone:b.tone,row:b.value})}u.push({key:h,index:y,lanes:Math.max(1,g.length),count:v.length,items:v})}let p=null;if(n.today>=r&&n.today<=i){const h=s(n.today),f=(n.today-o[h])/(o[h+1]-o[h]);p={col:h+1,percent:Math.round((h+f)/n.columns*1e4)/100}}return{scale:n.scale,key:Tt(r),label:ny(r,i),prev:Tt(Lc(r,n.scale,-n.columns)),next:Tt(o[n.columns]),today:Tt(n.today),columns:l,bands:c,rows:u,now:p}}const VS=e=>!!e&&typeof e=="object"&&!Array.isArray(e);function Wr(e){if(e===null||typeof e=="boolean"||typeof e=="string")return JSON.stringify(e);if(typeof e=="number"){if(!Number.isFinite(e))throw new Error(`canonicalJson: ${e} has no JSON form`);return JSON.stringify(e)}if(Array.isArray(e))return`[${e.map(t=>t===void 0?"null":Wr(t)).join(",")}]`;if(VS(e))return`{${Object.keys(e).filter(n=>e[n]!==void 0).sort().map(n=>`${JSON.stringify(n)}:${Wr(e[n])}`).join(",")}}`;throw new Error(`canonicalJson: a ${typeof e} has no JSON form`)}Uint8Array.from([48,46,2,1,0,48,5,6,3,43,101,112,4,34,4,32]);const Hr="records",Hn={sortDefault:"createdAt",orderDefault:"desc",limitDefault:100,limitMax:500},KS=["app","before","by","columns","day","expand","lanes","limit","mine","month","order","q","query","row","scale","sort","start","sum","tone","until","user","view"],GS=["id","createdAt","updatedAt","createdBy","authorId","author"],YS=["eq","gt","gte","lt","lte","in","between"],XS={"=":"eq","==":"eq",">":"gt",">=":"gte","<":"lt","<=":"lte"},Hp=["sum","avg","min","max","count","countDistinct","first","last"],qp=["sum","count","avg","min","max"],ZS=["count","sum","running","rows"],JS=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],QS=["January","February","March","April","May","June","July","August","September","October","November","December"],ry=/^\d{4}-(0[1-9]|1[0-2])$/,eC=["gt","gte","lt","lte","in","between"],tC=["in","between"],Rt=e=>e?.trim()||null,ko=e=>typeof e=="string"&&e.length===10&&Xi(e)?e:null,jc=(e,t)=>{const n=typeof e=="number"?e:typeof e=="string"&&e.trim()?Number(e):NaN;return Number.isInteger(n)&&n>=1&&n<=t?n:null},bt=e=>!!e&&typeof e=="object"&&!Array.isArray(e),mr=(e,t)=>e<t?-1:e>t?1:0;function oy(e,t){const n=Rt(t);if(e.q!==void 0&&e.q.trim()){let d=null;try{d=JSON.parse(e.q)}catch{d=null}return Xu(bt(d)?d:{},n).query}const r=Number(e.limit),o=[];for(const d of Object.keys(e).sort()){if(KS.includes(d)||!d)continue;const p=d.lastIndexOf("."),h=p>=0?d.slice(p+1):"",f=e[d];p>0&&eC.includes(h)?o.push({field:d.slice(0,p),op:h,value:tC.includes(h)?f.split(","):f}):o.push({field:d,op:"eq",value:f})}o.sort((d,p)=>mr(d.field,p.field)||mr(d.op,p.op));const i=Rt(e.by),s=Rt(e.before),a=e.view==="week"||e.view==="timeline"?e.view:"month",l=Rt(e.until),c=Rt(e.tone),u=jc(e.lanes,Yg)??Gg;return{from:n,app:Rt(e.app),mine:e.mine==="1"||e.mine==="true",user:Rt(e.user),where:o,or:[],sort:[{field:Rt(e.sort)??Hn.sortDefault,order:e.order==="asc"?"asc":e.order==="desc"?"desc":Hn.orderDefault}],limit:Number.isInteger(r)&&r>0?Math.min(r,Hn.limitMax):Hn.limitDefault,sum:Rt(e.sum),month:i&&a==="month"?{field:i,key:e.month&&ry.test(e.month)?e.month:null,until:l,day:ko(e.day),lanes:u,tone:c}:null,week:i&&a==="week"?{field:i,key:ko(e.day),until:l,lanes:u,tone:c}:null,timeline:i&&a==="timeline"?{field:i,until:l,row:Rt(e.row),scale:zc.includes(e.scale)?e.scale:"week",start:ko(e.start),columns:jc(e.columns,Zg)??Xg,tone:c}:null,group:[],aggregate:[],running:[],before:s?{field:i??Hn.sortDefault,date:s}:null,expand:[...new Set((e.expand??"").split(",").map(d=>d.trim()).filter(Boolean))]}}function iy(e){return e.scheme===Hr?oy(e.params,e.name):null}function Up(e){return e===null?"":typeof e=="string"?e:typeof e=="boolean"?e?"true":"false":typeof e=="number"&&Number.isFinite(e)?String(e):null}function Vp(e,t,n){if(!Array.isArray(e)||e.length<3)return n.push({path:t,message:"a condition is [field, op, value]"}),null;const[r,o,...i]=e;if(typeof r!="string"||!r.trim())return n.push({path:`${t}/0`,message:"a condition's field is a non-empty string"}),null;const s=typeof o=="string"?XS[o]??(YS.includes(o)?o:null):null;if(!s)return n.push({path:`${t}/1`,message:`unknown operator ${String(o)}`}),null;const a=r.trim();if(s==="in"){const c=i.length===1&&Array.isArray(i[0])?i[0].map(Up):null;return!c||c.some(u=>u===null)?(n.push({path:`${t}/2`,message:"in takes one list of values"}),null):{field:a,op:s,value:c}}const l=i.map(Up);return l.some(c=>c===null)||l.length!==(s==="between"?2:1)?(n.push({path:`${t}/2`,message:s==="between"?"between takes a low and a high value":`${s} takes one value`}),null):{field:a,op:s,value:s==="between"?l:l[0]}}const nC=["from","app","mine","user","where","sort","limit","sum","month","week","timeline","group","aggregate","running","before","expand"],Kp={month:["field","key","until","day","lanes","tone"],week:["field","key","until","lanes","tone"],timeline:["field","until","row","scale","start","columns","tone"]};function rC(e,t,n){if(!bt(t)||typeof t.field!="string"||!t.field.trim())return n.push({path:`/${e}`,message:`${e} is {${Kp[e].map(o=>o==="field"?o:`${o}?`).join(", ")}}`}),null;const r={field:t.field.trim()};for(const o of Object.keys(t).sort()){if(o==="field")continue;const i=t[o],s=`/${e}/${o}`;if(!Kp[e].includes(o))n.push({path:s,message:`unknown key ${o}`});else{if(i==null)continue;if(o==="lanes"||o==="columns"){const a=o==="lanes"?Yg:Zg,l=jc(i,a);l===null?n.push({path:s,message:`${o} is an integer 1–${a}`}):r[o]=l}else o==="scale"?zc.includes(i)?r[o]=i:n.push({path:s,message:`scale is ${zc.join("|")}`}):typeof i!="string"?n.push({path:s,message:`${o} is a string`}):r[o]=i.trim()||null}}return r}function Xu(e,t){const n=[],r=oy({},null);if(r.sort=[{field:Hn.sortDefault,order:Hn.orderDefault}],!bt(e))return n.push({path:"",message:"a query is an object"}),r.from=Rt(t),{query:r,issues:n};for(const i of Object.keys(e).sort())!nC.includes(i)&&!i.startsWith("$")&&n.push({path:`/${i}`,message:`unknown key ${i}`});const o=i=>{const s=e[i];return s==null?null:typeof s!="string"?(n.push({path:`/${i}`,message:`${i} is a string`}),null):Rt(s)};if(r.from=Rt(t)??o("from"),r.app=o("app"),r.user=o("user"),r.sum=o("sum"),e.mine!==void 0&&(typeof e.mine!="boolean"?n.push({path:"/mine",message:"mine is a boolean"}):r.mine=e.mine),e.where!==void 0&&(Array.isArray(e.where)?e.where.forEach((i,s)=>{const a=`/where/${s}`;if(bt(i)){if(Object.keys(i).length!==1||!Array.isArray(i.or))return void n.push({path:a,message:"an alternative is {or: [[condition…]…]}"});if(r.or.length)return void n.push({path:a,message:"one or per query"});i.or.forEach((c,u)=>{if(!Array.isArray(c))return void n.push({path:`${a}/or/${u}`,message:"an alternative is a list of conditions"});const d=[];c.forEach((p,h)=>{const f=Vp(p,`${a}/or/${u}/${h}`,n);f&&d.push(f)}),r.or.push(d)});return}const l=Vp(i,a,n);l&&r.where.push(l)}):n.push({path:"/where",message:"where is a list of conditions"})),e.sort!==void 0){const i=typeof e.sort=="string"?[e.sort]:Array.isArray(e.sort)?e.sort:null;if(!i)n.push({path:"/sort",message:"sort is a field or a list of [field, order]"});else{const s=[];i.forEach((a,l)=>{const[c,u]=typeof a=="string"?[a,"asc"]:Array.isArray(a)?[a[0],a.length>1?a[1]:"asc"]:[null,null];if(typeof c!="string"||!c.trim()||u!=="asc"&&u!=="desc")return void n.push({path:typeof e.sort=="string"?"/sort":`/sort/${l}`,message:"a sort key is field or [field, asc|desc]"});s.push({field:c.trim(),order:u})}),s.length&&(r.sort=s)}}if(e.limit!==void 0){const i=typeof e.limit=="number"?e.limit:typeof e.limit=="string"&&e.limit.trim()?Number(e.limit):NaN;!Number.isInteger(i)||i<1?n.push({path:"/limit",message:"limit is a positive integer"}):r.limit=Math.min(i,Hn.limitMax)}for(const i of["month","week","timeline"]){if(e[i]===void 0||e[i]===null)continue;if(r.month||r.week||r.timeline){n.push({path:`/${i}`,message:"one calendar view per query"});continue}const s=rC(i,e[i],n);if(!s)continue;const a=c=>typeof s[c]=="string"?s[c]:null,l=typeof s.lanes=="number"?s.lanes:Gg;i==="month"?r.month={field:s.field,key:a("key")&&ry.test(a("key"))?a("key"):null,until:a("until"),day:ko(a("day")),lanes:l,tone:a("tone")}:i==="week"?r.week={field:s.field,key:ko(a("key")),until:a("until"),lanes:l,tone:a("tone")}:r.timeline={field:s.field,until:a("until"),row:a("row"),scale:a("scale")??"week",start:ko(a("start")),columns:typeof s.columns=="number"?s.columns:Xg,tone:a("tone")}}if(e.group!==void 0&&(Array.isArray(e.group)?e.group.forEach((i,s)=>{const a=`/group/${s}`;let l=null;if(typeof i=="string"&&i.trim()?l={field:i.trim(),bucket:null}:bt(i)&&typeof i.bucket=="string"&&i.bucket.trim()&&Gd.includes(i.by)&&Object.keys(i).length===2&&(l={field:i.bucket.trim(),bucket:i.by}),!l)return void n.push({path:a,message:`a group key is a field or {bucket: field, by: ${Gd.join("|")}}`});if(r.group.some(c=>c.field===l.field||l.field==="author"&&c.field==="authorId"||l.field==="authorId"&&c.field==="author"))return void n.push({path:a,message:`duplicate group ${l.field}`});r.group.push(l)}):n.push({path:"/group",message:"group is a list of keys"})),e.aggregate!==void 0)if(!bt(e.aggregate))n.push({path:"/aggregate",message:"aggregate is {name: [op, field?]}"});else for(const i of Object.keys(e.aggregate).sort()){const s=e.aggregate[i],a=`/aggregate/${i}`;if(!i.trim()||ZS.includes(i)||r.group.some(u=>u.field===i||u.field==="author"&&i==="authorId")){n.push({path:a,message:`the name ${i} is taken`});continue}const l=Array.isArray(s)&&Hp.includes(s[0])?s[0]:null,c=Array.isArray(s)&&s.length>1&&typeof s[1]=="string"&&s[1].trim()?s[1].trim():null;if(!l||!Array.isArray(s)||s.length>2||s.length>1&&!c||l!=="count"&&!c){n.push({path:a,message:`an aggregate is [${Hp.join("|")}, field] (count: the field is optional)`});continue}r.aggregate.push({name:i,op:l,field:c})}if(e.running!==void 0)if(!bt(e.running))n.push({path:"/running",message:"running is {field: op}"});else for(const i of Object.keys(e.running).sort()){const s=e.running[i];if(!i.trim()||!qp.includes(s)){n.push({path:`/running/${i}`,message:`a running value is {field: ${qp.join("|")}}`});continue}r.running.push({field:i,op:s})}if(e.before!==void 0&&e.before!==null){const i=e.before,s=r.group.find(a=>a.bucket!==null)?.field??r.month?.field??r.week?.field??r.timeline?.field??Hn.sortDefault;typeof i=="string"?r.before=Rt(i)?{field:s,date:i.trim()}:null:bt(i)&&typeof i.field=="string"&&i.field.trim()&&typeof i.date=="string"?r.before=i.date.trim()?{field:i.field.trim(),date:i.date.trim()}:null:n.push({path:"/before",message:"before is a date or {field, date}"})}return e.expand!==void 0&&(Array.isArray(e.expand)?e.expand.forEach((i,s)=>{if(typeof i!="string"||!i.trim())return void n.push({path:`/expand/${s}`,message:"an expanded field is a non-empty string"});if(r.expand.includes(i.trim()))return void n.push({path:`/expand/${s}`,message:`duplicate expand ${i.trim()}`});r.expand.push(i.trim())}):n.push({path:"/expand",message:"expand is a list of ref fields"})),{query:r,issues:n}}function Bc(e,t){return typeof e=="string"?e.replace(/\$\{([^}]*)\}/g,(n,r)=>t[r.trim()]??""):Array.isArray(e)?e.map(n=>Bc(n,t)):bt(e)?Object.fromEntries(Object.keys(e).map(n=>[n,Bc(e[n],t)])):e}function Zu(e,t){const n=Qt(e),r=n?.params.query;if(!n||r===void 0||!bt(t)||!Object.prototype.hasOwnProperty.call(t,r))return e;const{query:o,...i}=n.params,s=t[r],a=Bc(s,i),l=e.trim(),c=l.includes("?")?l.slice(0,l.indexOf("?")):l;return Gu(c,{q:Wr(a)})}const In=e=>{if(typeof e=="number")return Number.isFinite(e)?e:null;if(typeof e=="string"&&e.trim()!==""){const t=Number(e);return Number.isFinite(t)?t:null}return null},tt=e=>e==null?"":typeof e=="string"?e:typeof e=="object"?Wr(e):String(e);function ya(e,t){const n=In(e),r=In(t);return n!==null&&r!==null?n<r?-1:n>r?1:0:mr(tt(e),tt(t))}const Ri=e=>{const t=In(e);return{n:t,t:t===null?tt(e):""}};function fi(e,t,n,r){return e.n!==null&&t.n!==null?e.n<t.n?-1:e.n>t.n?1:0:mr(e.n===null?e.t:tt(n),t.n===null?t.t:tt(r))}function Gp(e){const t=Array.isArray(e.value)?e.value:[e.value],n=e.op==="between"?t.length===2?t:[]:t.length===1?t:[tt(e.value)];return{filter:e,list:t,eq:tt(e.value),bounds:n.map(r=>({key:Ri(r),v:r}))}}function Yp(e,t){const n=e.filter.op;if(n==="eq")return tt(t)===e.eq;if(n==="in")return e.list.includes(tt(t));const r=Ri(t);if(n==="between")return e.bounds.length===2&&fi(r,e.bounds[0].key,t,e.bounds[0].v)>=0&&fi(r,e.bounds[1].key,t,e.bounds[1].v)<=0;const o=e.bounds[0],i=fi(r,o.key,t,o.v);return n==="gt"?i>0:n==="gte"?i>=0:n==="lt"?i<0:i<=0}function Xp(e,t){const n=t.map(o=>{const i=e.map(l=>_n(l,o.field)),s=i.map(Ri),a=o.order==="asc"?1:-1;if(s.every(l=>l.n!==null)){const l=Float64Array.from(s,c=>c.n);return(c,u)=>a*(l[c]<l[u]?-1:l[c]>l[u]?1:0)}if(s.every(l=>l.n===null)){const l=[...new Set(s.map(d=>d.t))].sort(mr),c=new Map(l.map((d,p)=>[d,p])),u=Uint32Array.from(s,d=>c.get(d.t));return(d,p)=>a*(u[d]-u[p])}return(l,c)=>a*fi(s[l],s[c],i[l],i[c])}),r=e.map((o,i)=>i);return r.sort((o,i)=>{for(const s of n){const a=s(o,i);if(a!==0)return a}return mr(e[o].id,e[i].id)}),r.map(o=>e[o])}function Vo(e){return e.authorId??e.createdBy??null}function _n(e,t){return t==="createdAt"?e.createdAt:t==="updatedAt"?e.updatedAt:t==="id"?e.id:t==="createdBy"?e.createdBy:t==="authorId"?Vo(e):e.data[t]}function Zp(e,t){const[n,r]=e.split("-").map(Number),o=n*12+(r-1)+t;return`${Math.floor(o/12)}-${String((o%12+12)%12+1).padStart(2,"0")}`}function oC(e){const[t,n]=e.split("-").map(Number);return`${QS[n-1]} ${t}`}function iC(e){const[t,n]=e.split("-").map(Number),r=[];for(let o=1;o<=Io(t,n);o++)r.push({date:`${e}-${String(o).padStart(2,"0")}`,day:o,weekday:JS[Yi(t,n,o)],count:0,sum:0});return r}function qr(e){return Math.round(e*1e6)/1e6}const Wc=e=>e===void 0?null:e;function sC(e,t){const n=e.field===null?[]:t.map(r=>_n(r,e.field));switch(e.op){case"count":return e.field===null?t.length:n.filter(r=>tt(r)!=="").length;case"sum":return qr(n.reduce((r,o)=>r+(In(o)??0),0));case"avg":{const r=n.map(In).filter(o=>o!==null);return r.length?qr(r.reduce((o,i)=>o+i,0)/r.length):null}case"min":case"max":{let r;for(const o of n)tt(o)!==""&&(r===void 0||(e.op==="min"?ya(o,r)<0:ya(o,r)>0))&&(r=o);return r===void 0?null:In(r)??tt(r)}case"countDistinct":return new Set(n.map(tt).filter(r=>r!=="")).size;case"first":return t.length?Wc(n[0]):null;case"last":return t.length?Wc(n[n.length-1]):null}}function zl(e,t){const n={count:t.length};e.sum!==null&&(n.sum=qr(t.reduce((r,o)=>r+(In(o.data[e.sum])??0),0)));for(const r of e.aggregate)n[r.name]=sC(r,t);return n}class aC{constructor(t){this.list=t,this.acc=t.map(()=>({sum:0,count:0,nums:0,min:null,max:null}))}list;acc;add(t){this.list.forEach((n,r)=>{const o=this.acc[r],i=In(_n(t,n.field));o.count+=1,i!==null&&(o.sum+=i,o.nums+=1,o.min=o.min===null||i<o.min?i:o.min,o.max=o.max===null||i>o.max?i:o.max)})}read(){const t={};return this.list.forEach((n,r)=>{const o=this.acc[r];t[n.field]=n.op==="sum"?qr(o.sum):n.op==="count"?o.count:n.op==="avg"?o.nums?qr(o.sum/o.nums):null:n.op==="min"?o.min:o.max}),t}}function lC(e,t){if(e.field==="author")return Vo(t)??"";const n=_n(t,e.field);return e.bucket!==null?_m(tt(n),e.bucket)??"":tt(n)}function cC(e,t,n,r){if(e.field==="author"){const i=Vo(t);r.author=i&&n?.[i]||"",r.authorId=i;return}const o=_n(t,e.field);r[e.field]=e.bucket!==null?_m(tt(o),e.bucket):Wc(o)}const Jp=16,uC=["id","createdAt","updatedAt","createdBy","authorId"];function dC(e,t){const n=t&&bt(e)&&Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0;if(!bt(n)||!bt(n.computed))return;const r={};for(const[o,i]of Object.entries(n.computed))typeof i=="string"&&(r[o]=i);return Object.keys(r).length?r:void 0}function pC(e,t){const n=t&&bt(e)&&Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0;if(!bt(n)||!bt(n.refs))return;const r={};for(const[o,i]of Object.entries(n.refs))i==="issue"||i==="member"?r[o]=i:bt(i)&&typeof i.kind=="string"&&i.kind&&(r[o]={kind:i.kind});return Object.keys(r).length?r:void 0}function sy(e,t){const n=Vo(e);return{...e.data,id:e.id,createdAt:e.createdAt,updatedAt:e.updatedAt,createdBy:e.createdBy,authorId:n,author:n&&t?.[n]||""}}function fC(e,t,n,r){const o=typeof t=="string"?t:typeof t=="number"?String(t):"";if(!o)return null;if(e==="issue")return r.issues&&Object.prototype.hasOwnProperty.call(r.issues,o)?r.issues[o]:null;if(e==="member")return r.names&&Object.prototype.hasOwnProperty.call(r.names,o)?{id:o,name:r.names[o]}:null;const i=n().get(o);return i&&i.kind===e.kind?sy(i,r.names):null}function hC(e,t,n,r){const o=n?Object.keys(n).sort(mr):[];if(!o.length)return e;const i=o.map(a=>{const l=Wo(n[a]);return{name:a,ast:"ast"in l?l.ast:null,reads:"ast"in l?Fm(l.ast):[]}}),s={now:(r?qa(r):null)??0};return e.map(a=>{if(a.kind!==t)return a;const l={...a.data,id:a.id,createdAt:a.createdAt,updatedAt:a.updatedAt,createdBy:a.createdBy,authorId:Vo(a)},c={...a.data};for(const u of i){for(const p of u.reads)Object.prototype.hasOwnProperty.call(l,p)||(l[p]=null);const d=u.ast?Iu(u.ast,l,s):null;c[u.name]=d&&"value"in d?d.value:null}return{...a,data:c}})}function mC(e,t,n){if(!t.from)return null;const r=n.now??new Date().toISOString(),o=e;e=hC(e,t.from,n.computed,r);const i=t.expand.flatMap(_=>n.refs&&Object.prototype.hasOwnProperty.call(n.refs,_)?[{name:_,target:n.refs[_]}]:[]);let s=null;const a=()=>s??=new Map(o.map(_=>[_.id,_])),l=t.month,c=n.today&&/^\d{4}-\d{2}-\d{2}$/.test(n.today)?n.today:r.slice(0,10),u=l?l.key??c.slice(0,7):null,d=dr(c)??0,p=t.month??t.week??t.timeline;let h=null;if(l&&l.until!==null&&u!==null){const[_,M]=u.split("-").map(Number);h=[dr(`${u}-01`),dr(`${u}-${String(Io(_,M)).padStart(2,"0")}`)]}else if(t.week){const _=Nc((t.week.key?dr(t.week.key):null)??d,"week");h=[_,_+6]}else if(t.timeline){const _=t.timeline,M=Nc((_.start?dr(_.start):null)??d,_.scale);h=[M,Lc(M,_.scale,_.columns)-1]}const f=_=>p?LS(tt(_.data[p.field]),p.until!==null?tt(_.data[p.until]):null):null,y=t.where.map(Gp),g=t.or.map(_=>_.map(Gp)),v=t.before?Ri(t.before.date):null,m=[],b=Xp(e.filter(_=>{if(_.kind!==t.from)return!1;const M=Vo(_);if(t.mine&&(n.me===null||M!==n.me)||t.user!==null&&M!==t.user||!y.every(O=>Yp(O,_n(_,O.filter.field)))||g.length&&!g.some(O=>O.every(E=>Yp(E,_n(_,E.filter.field)))))return!1;if(t.before){const O=tt(_n(_,t.before.field));if(O!==""&&fi(Ri(O),v,O,t.before.date)<0)return m.push(_),!1}if(h){const O=f(_);if(!O||O.end<h[0]||O.start>h[1])return!1}else if(l&&u!==null&&!tt(_.data[l.field]).startsWith(u))return!1;return!0}),t.sort),x=Xp(m,t.sort),$=()=>{const _=new aC(t.running);for(const M of x)_.add(M);return _},S=t.running.length&&!t.group.length?$():null,A=_=>{const M=sy(_,n.names);for(const O of i)M[O.name]=fC(O.target,_.data[O.name],a,n);return n.transitions&&(M[Ns]=CS(n.transitions,_.data,{id:n.me,role:n.role??null},_)),M},C={rows:b.slice(0,t.limit).map(_=>{const M=A(_);return S&&(S.add(_),M.running=S.read()),M}),count:b.length};if(t.sum!==null&&(C.sum=qr(b.reduce((_,M)=>_+(In(M.data[t.sum])??0),0))),l&&u!==null){const _=iC(u),M=new Map(_.map(E=>[E.date,E])),O=new Map;for(const E of b){const R=tt(E.data[l.field]).slice(0,10),z=M.get(R);if(!z)continue;z.count+=1,t.sum!==null&&(z.sum=qr(z.sum+(In(E.data[t.sum])??0)));const Z=O.get(R);Z?Z.push(E):O.set(R,[E])}if(t.running.length){const E=$();for(const R of _){for(const z of O.get(R.date)??[])E.add(z);R.running=E.read()}}C.month={key:u,label:oC(u),prev:Zp(u,-1),next:Zp(u,1),today:c,days:_,labels:_.map(E=>String(E.day)),counts:_.map(E=>E.count),sums:_.map(E=>E.sum)}}if(p){const _=b.flatMap((E,R)=>{const z=f(E);return z?[{row:E,order:R,...z}]:[]}),M=jS(_.map(E=>p.tone!==null?tt(_n(E.row,p.tone)):"")),O=_.map((E,R)=>({id:E.row.id,start:E.start,end:E.end,tone:M[R],value:A(E.row),order:E.order,rowKey:t.timeline?.row?tt(_n(E.row,t.timeline.row)):null}));if(l&&C.month){const[E,R]=C.month.key.split("-").map(Number);Object.assign(C.month,WS(E,R,Io(E,R),O,{lanes:l.lanes,today:d,day:l.day}))}else t.week?C.week=HS(h[0],O,{lanes:t.week.lanes,today:d}):t.timeline&&(C.timeline=US(h[0],O,{scale:t.timeline.scale,columns:t.timeline.columns,today:d}))}if(t.group.length){const _=new Map,M=t.group.length===1;for(const z of b){const Z=t.group.map(L=>lC(L,z)),N=M?Z[0]:Z.some(L=>L.includes("\0"))?JSON.stringify(Z):Z.join("\0"),I=_.get(N);if(I)I.rows.push(z);else{const L={};for(const V of t.group)cC(V,z,n.names,L);_.set(N,{parts:Z,rows:[z],out:L})}}const O=[..._.values()];for(const z of O)Object.assign(z.out,zl(t,z.rows));const E=new Set([...t.group.flatMap(z=>z.field==="author"?["author","authorId"]:[z.field]),"count",...t.sum!==null?["sum"]:[],...t.aggregate.map(z=>z.name)]),R=t.sort.filter(z=>E.has(z.field));if(O.sort((z,Z)=>{for(const N of R){const I=ya(z.out[N.field],Z.out[N.field]);if(I!==0)return N.order==="asc"?I:-I}for(const N of t.group){const I=ya(z.out[N.field],Z.out[N.field]);if(I!==0)return I}for(let N=0;N<z.parts.length;N++){const I=mr(z.parts[N],Z.parts[N]);if(I!==0)return I}return 0}),t.running.length){const z=$();for(const Z of O){for(const N of Z.rows)z.add(N);Z.out.running=z.read()}}C.groups=O.map(z=>z.out)}return t.aggregate.length&&(C.totals=zl(t,b)),t.before&&(C.before=zl(t,x)),C}const gC=/^[a-z][a-z0-9_-]{0,31}$/,yC=["mcp","script"],bC=/^[A-Za-z_][A-Za-z0-9_]*$/,Qp=e=>!!e&&typeof e=="object"&&!Array.isArray(e),ef=e=>Array.isArray(e)&&e.every(t=>typeof t=="string");function vC(e){try{const t=new URL(e);return(t.protocol==="https:"||t.protocol==="http:")&&!!t.host}catch{return!1}}function $C(e){if(!Qp(e))return[{path:"/tools",message:"tools is an object of tools"}];const t=[];for(const n of Object.keys(e).sort()){const r=e[n],o=`/tools/${n}`;if(gC.test(n)||t.push({path:o,message:"a tool id is lowercase letters, digits, - and _"}),!Qp(r)){t.push({path:o,message:"a tool is {kind, title, url | command}"});continue}(typeof r.kind!="string"||!yC.includes(r.kind))&&t.push({path:`${o}/kind`,message:"kind is mcp or script"}),(typeof r.title!="string"||!r.title.trim())&&t.push({path:`${o}/title`,message:"title is a required string"}),r.description!==void 0&&typeof r.description!="string"&&t.push({path:`${o}/description`,message:"description is a string"});const i=r.url!==void 0,s=r.command!==void 0;r.kind==="mcp"&&i===s&&t.push({path:o,message:"an mcp tool has a url or a command"}),r.kind==="script"&&i&&t.push({path:`${o}/url`,message:"a script runs a command, not a url"}),r.kind==="script"&&!s&&t.push({path:`${o}/command`,message:"command is a non-empty string"}),i&&(typeof r.url!="string"||!vC(r.url))&&t.push({path:`${o}/url`,message:"url is an absolute http(s) url"}),s&&(typeof r.command!="string"||!r.command.trim())&&t.push({path:`${o}/command`,message:"command is a non-empty string"}),r.args!==void 0&&(!ef(r.args)||i)&&t.push({path:`${o}/args`,message:"args is a list of strings beside a command"}),r.env!==void 0&&(!ef(r.env)||r.env.some(a=>!bC.test(a))||i)&&t.push({path:`${o}/env`,message:"env is a list of variable names beside a command"})}return t}const dn=St.package.exposes.limits,xC=St.package.exposes.runKinds,tf=St.package.exposes.recordOps,wC=St.package.exposes.readRecordOps,kC=St.package.exposes.readOpWords,SC=St.package.exposes.destructiveWords,po=St.package.exposes.agent,CC=new RegExp(po.slugPattern),Nn=e=>!!e&&typeof e=="object"&&!Array.isArray(e),AC=new RegExp(dn.namePattern),_C=new RegExp(St.package.exposes.actionPattern),OC=/\$\{input\.([A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*)\}/g;function TC(e){const t=[],n=r=>{if(typeof r=="string")for(const o of r.matchAll(OC))t.push(o[1]);else Array.isArray(r)?r.forEach(n):Nn(r)&&Object.values(r).forEach(n)};return n(e),t}const ay=e=>e.toLowerCase().split(/[^a-z]+/).filter(Boolean);function MC(e){const t=ay(e.split(".").at(-1)??"").at(-1);return t!==void 0&&kC.includes(t)?"read":"write"}function nf(e){return ay(e).some(t=>SC.includes(t))}function EC(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t!==""):[]}function IC(e){if(!Array.isArray(e)||e.some(n=>typeof n!="string"||n===""))return[{path:"/upstreams",message:"upstreams is a list of MCP server names"}];const t=[];return e.forEach((n,r)=>{e.indexOf(n)!==r&&t.push({path:`/upstreams/${r}`,message:`duplicate upstream ${n}`})}),t}function PC(e,t,n){if(!Array.isArray(e))return[{index:null,code:"run",path:"/exposes",message:"exposes is a list of tools"}];const r=[];e.length>dn.maxTools&&r.push({index:null,code:"tooMany",path:"/exposes",message:`exposes lists at most ${dn.maxTools} tools`});const o=Nn(t)?Object.keys(t):[],i=EC(n),s=new Set;return e.forEach((a,l)=>{const c=`/exposes/${l}`,u=(g,v,m)=>{r.push({index:l,code:g,path:`${c}${v}`,message:m})};if(!Nn(a))return u("run","","a tool is {name, title, description, input, access, run}");const d=a.name;typeof d!="string"||!AC.test(d)||d.length>dn.nameMax||d.includes(dn.separator)?u("name","/name",`name is lowercase letters, digits and _ (at most ${dn.nameMax}, no ${dn.separator})`):s.has(d)?u("duplicate","/name",`duplicate tool ${d}`):s.add(d),(typeof a.title!="string"||!a.title.trim()||a.title.length>dn.titleMax)&&u("title","/title",`title is a non-blank string of at most ${dn.titleMax} characters`),(typeof a.description!="string"||!a.description.trim()||a.description.length>dn.descriptionMax)&&u("description","/description",`description is a non-blank string of at most ${dn.descriptionMax} characters`);const p=a.input;(!Nn(p)||p.type!=="object"||p.properties!==void 0&&!Nn(p.properties))&&u("input","/input","input is a JSON Schema of type object"),a.access!=="read"&&a.access!=="write"&&u("access","/access","access is read or write");const h=Nn(p)&&Nn(p.properties)?p.properties:{},f=a.run;if(!Nn(f)||xC.filter(g=>g in f).length!==1)return u("run","/run","run holds exactly one of records, action, upstream, agent");for(const g of TC(f))Object.prototype.hasOwnProperty.call(h,g.split(".")[0])||u("template","/run",`\${input.${g}} names no input property`);let y;if("records"in f){const g=f.records,v=Nn(g)?g.op:void 0;if(typeof v!="string"||!tf.includes(v))return v==="delete"?u("destructive","/run/records/op","a records delete is destructive: never exposed"):u("run","/run/records/op",`op is ${tf.join(", ")}`);(typeof g.kind!="string"||!o.includes(g.kind))&&u("kind","/run/records/kind","kind names no declared record kind"),y=wC.includes(v)?"read":"write"}else if("action"in f){const g=f.action;if(typeof g!="string"||!_C.test(g))return u("action","/run/action","action is a function name like namespace.function");if(nf(g))return u("destructive","/run/action","a destructive action is never exposed");y=MC(g)}else if("agent"in f)(typeof f.agent!="string"||!CC.test(f.agent)||f.agent.length>po.slugMax)&&u("agent","/run/agent","agent is an agent slug (lowercase words joined by -)"),(typeof f.prompt!="string"||f.prompt.trim()===""||f.prompt.length>po.promptMax)&&u("prompt","/run/prompt",`prompt is non-blank text of at most ${po.promptMax} characters`),f.device!==void 0&&!po.devices.includes(f.device)&&u("run","/run/device",`device is ${po.devices.join(", ")}`),y="write";else return(typeof f.upstream!="string"||!i.includes(f.upstream))&&u("upstream","/run/upstream","upstream names none of the package's upstreams"),typeof f.tool!="string"||f.tool===""?u("run","/run/tool","tool is a non-empty string"):nf(f.tool)?u("destructive","/run/tool","a destructive tool is never exposed"):void 0;a.access==="read"&&y==="write"&&u("accessTooLow","/access","the run writes: access is write")}),r}function DC(e,t,n){return PC(e,t,n).map(({path:r,message:o})=>({path:r,message:o}))}const je=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),hi=e=>e.replace(/~/g,"~0").replace(/\//g,"~1"),Nr=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);function Ur(e){if(!je(e))return"dyn";const t=Array.isArray(e.type)?e.type.filter(r=>r!=="null"):[e.type],n=t.length===1?t[0]:void 0;return n==="number"||n==="integer"?"number":n==="boolean"?"bool":n==="string"?e.format==="date"?"date":e.format==="date-time"?"timestamp":"string":n==="array"?[Ur(e.items)]:n==="object"?je(e.properties)?el(e.properties,e.required):"map":"dyn"}function el(e,t){const n=Array.isArray(t)?t:[],r={};for(const[o,i]of Object.entries(e))r[o]=n.includes(o)?Ur(i):Ze(Ur(i));return r}function ly(e){const t=je(e)&&je(e.schema)?e.schema:{},n=je(t.properties)?t.properties:{},r={...el(n,t.required),id:"string",createdAt:"timestamp",updatedAt:"timestamp",createdBy:"string",authorId:"string",author:"string"},o=je(e)&&je(e.computed)?e.computed:{},i=cy(e);for(const s of Object.keys(o).sort()){if(Nr(r,s))continue;const a=o[s],l=typeof a=="string"?Ua(a,i):null;r[s]=l&&"type"in l?l.type:Ze("dyn")}return r}function cy(e){const t=je(e)&&je(e.schema)?e.schema:{},n=je(t.properties)?t.properties:{},r={...el(n,t.required)};for(const o of uC)r[o]=o==="createdAt"||o==="updatedAt"?"timestamp":"string";return r}function RC(e,t){if(!je(e)||e.computed===void 0)return[];const n=e.computed;if(!je(n))return[{path:`${t}/computed`,message:"computed is {name: expression}"}];const r=[],o=Object.keys(n).sort();o.length>Jp&&r.push({path:`${t}/computed`,message:`at most ${Jp} computed fields per kind`});const i=je(e.schema)?e.schema:{},s=je(i.properties)?i.properties:{},a=cy(e);for(const l of o){const c=`${t}/computed/${hi(l)}`,u=n[l];if(Nr(s,l))r.push({path:c,message:`${l} shadows a field of the schema`});else if(GS.includes(l))r.push({path:c,message:`${l} is a reserved record key`});else if(typeof u!="string")r.push({path:c,message:"a computed field is an expression (a string)"});else{const d=Wo(u),p="ast"in d?Fm(d.ast).filter(h=>Nr(n,h)&&!Nr(s,h)):[];if(p.length)r.push({path:c,message:`a computed field reads no computed field: ${p.join(", ")}`});else{const h=Ua(u,a);"error"in h&&r.push({path:c,message:h.error})}}}return r}const uy={date:"date",day:"number",weekday:"string",initial:"string",inMonth:"bool",weekend:"bool",today:"bool",selected:"bool",total:"number",dots:[{tone:"string"}]},dy=e=>({id:"string",col:"number",span:"number",lane:"number",contL:"bool",contR:"bool",tone:Ze("string"),more:"number",row:Ze(e)}),FC=e=>({key:"string",label:"string",prev:"string",next:"string",today:"date",days:[{date:"date",day:"number",weekday:"string",count:"number",sum:"number",running:Ze("map")}],labels:["string"],counts:["number"],sums:["number"],weeks:[{key:"date",days:[uy],segments:[dy(e)]}],day:"date",agenda:{date:"date",label:"string",count:"number",items:[{id:"string",tone:"string",start:"date",end:"date",days:"number",row:e}]}}),zC=e=>({key:"date",label:"string",prev:"date",next:"date",today:"date",days:[uy],segments:[dy(e)]}),NC=e=>({scale:"string",key:"date",label:"string",prev:"date",next:"date",today:"date",columns:[{key:"date",label:"string",end:"date",today:"bool"}],bands:[{label:"string",col:"number",span:"number"}],rows:[{key:"string",index:"number",lanes:"number",count:"number",items:[{id:"string",rowIndex:"number",col:"number",span:"number",lane:"number",contL:"bool",contR:"bool",tone:"string",row:e}]}],now:Ze({col:"number",percent:"number"})});function LC(e,t){const n=(o,i)=>o?i:Ze(i),r=ly(e);return{rows:[t?.running.length&&!t.group.length?{...r,running:"map"}:r],count:"number",sum:n(t?t.sum!==null:void 0,"number"),groups:n(t?t.group.length>0:void 0,["map"]),totals:n(t?t.aggregate.length>0:void 0,"map"),before:n(t?t.before!==null:void 0,"map"),month:n(t?t.month!==null:void 0,FC(r)),week:n(t?t.week!==null:void 0,zC(r)),timeline:n(t?t.timeline!==null:void 0,NC(r))}}function Fi(e){if(Array.isArray(e)){const t=e.map(Fi);return t.length===0?["dyn"]:[t.every(n=>JSON.stringify(n)===JSON.stringify(t[0]))?t[0]:"dyn"]}if(je(e)){const t={};for(const[n,r]of Object.entries(e))t[n]=Fi(r);return t}return We(e)}function py(e,t,n){let r=e,o=!1;for(const i of t)if(Ot(r)&&(o=!0,r=r["?"]),Array.isArray(r)){if(!/^\d+$/.test(i))return{type:"dyn"};r=r[0],o=!0}else if(r==="map")r="dyn",o=!0;else if(typeof r=="object"){if(!Nr(r,i))return n?{unknown:i}:{type:"dyn"};r=r[i]}else return{type:"dyn"};return{type:o?Ze(r):r}}const Hc=e=>e.replace(/~1/g,"/").replace(/~0/g,"~");function jC(e,t,n,r){if(!e.startsWith("/"))return{type:"dyn"};const o=Array.isArray(t.bindings)?t.bindings:[];for(const s of o){if(!je(s)||typeof s.path!="string"||typeof s.source!="string"||e!==s.path&&!e.startsWith(`${s.path}/`))continue;const a=Qt(s.source),l=a?.scheme===Hr?a.name:void 0;if(!l||!je(n)||!Nr(n,l))return{type:"dyn"};const c=e.slice(s.path.length).split("/").filter((h,f)=>f>0||h!==""),u=BC(n[l]),d=Qt(Zu(s.source,je(r)?r:void 0)),p=d?iy(d):null;return{...py(LC(n[l],p),c.map(Hc),u),strict:u}}let i=t.data;for(const s of e==="/"?[]:e.slice(1).split("/").map(Hc))if(Array.isArray(i)&&/^\d+$/.test(s))i=i[Number(s)];else if(je(i)&&Nr(i,s))i=i[s];else return{type:"dyn"};return{type:i===void 0?"dyn":Fi(i)}}function BC(e){return(je(e)&&je(e.schema)?e.schema:{}).additionalProperties!==!0}function fy(e,t,n,r,o){return e.startsWith("/")?jC(e,n,r,o):t?{...py(t.type,e.split("/").filter(i=>i!=="").map(Hc),t.strict),strict:t.strict}:{type:"dyn"}}function WC(e,t,n){const r=new Map;for(const s of Array.isArray(e.components)?e.components:[])je(s)&&typeof s.id=="string"&&!r.has(s.id)&&r.set(s.id,s);const o=new Map,i=(s,a)=>{const l=r.get(s);if(!(!l||o.has(s))){if(o.set(s,a),Array.isArray(l.children))for(const c of l.children)typeof c=="string"&&i(c,a);if(je(l.children)&&typeof l.children.componentId=="string"&&typeof l.children.path=="string"){const c=fy(l.children.path,a,e,t,n),u="type"in c?Pt(c.type):"dyn";i(l.children.componentId,{type:Array.isArray(u)?u[0]:"dyn",strict:Array.isArray(u)&&c.strict===!0})}if(je(l.slots))for(const c of Object.values(l.slots))typeof c=="string"&&i(c,a)}};return i("root",null),o}function qc(e,t,n,r,o,i,s){if(Wa(e)){const a=fy(e.path,n,r,o,i);return"unknown"in a?(s.push({path:`${t}/path`,message:`unknown field ${a.unknown} in ${e.path}`}),Ze("dyn")):a.type==="dyn"?Ze(a.type):a.type}if(jo(e))return Ze("dyn");if(Array.isArray(e)){const a=e.map((l,c)=>qc(l,`${t}/${c}`,n,r,o,i,s));return a.length===0?["dyn"]:[a.every(l=>JSON.stringify(l)===JSON.stringify(a[0]))?a[0]:"dyn"]}if(je(e)){const a={};for(const[l,c]of Object.entries(e))a[l]=qc(c,`${t}/${hi(l)}`,n,r,o,i,s);return a}return We(e)}function HC(e){const t=[];if(!je(e.templates))return t;for(const[n,r]of Object.entries(e.templates)){if(!je(r)||!Array.isArray(r.components))continue;let o=null;const i=(a,l)=>{if(Array.isArray(a))return a.forEach((c,u)=>i(c,`${l}/${u}`));if(je(a)){if(a.call==="expr"&&je(a.args)){const c=a.args,u=`${l}/args`;if(Object.prototype.hasOwnProperty.call(c,"default")||t.push({path:`${u}/default`,message:"an expression binding needs a default, shown when it fails"}),typeof c.expr!="string")t.push({path:`${u}/expr`,message:"expr is a string"});else if(c.vars!==void 0&&!je(c.vars))t.push({path:`${u}/vars`,message:"vars is an object"});else{const d={},p=[];for(const[f,y]of Object.entries(c.vars??{}))d[f]=qc(y,`${u}/vars/${hi(f)}`,o,r,e.records,e.queries,p);t.push(...p);const h=p.length?null:Ua(c.expr,d);h&&"error"in h&&t.push({path:`${u}/expr`,message:h.error})}}for(const[c,u]of Object.entries(a))i(u,`${l}/${hi(c)}`)}},s=WC(r,e.records,e.queries);r.components.forEach((a,l)=>{o=je(a)&&typeof a.id=="string"?s.get(a.id)??null:null,i(a,`/templates/${hi(n)}/components/${l}`)})}return t}const rf=5,of=32,sf=200,So="app.navigate",rt=e=>!!e&&typeof e=="object"&&!Array.isArray(e),qC=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),UC=new Set(lm),VC=["template","title","icon","params","nav","exposed"],KC=["description","params"],GC=["required","description"],YC=/^[A-Za-z0-9_]+$/,pr=e=>e.replace(/~/g,"~0").replace(/\//g,"~1");function XC(e){if(e.screens===void 0)return[];const t=e.screens;if(!Array.isArray(t)||!t.length)return[{path:"/screens",message:"screens is a non-empty list of {template, title, icon?, params?, nav?, exposed?}"}];const n=[],r=t.filter(s=>!rt(s)||s.nav!==!1).length;r>rf&&n.push({path:"/screens",message:`at most ${rf} screens in the navigation, got ${r}`}),r||n.push({path:"/screens",message:"at least one screen is in the navigation (not nav: false)"});const o=rt(e.templates)?e.templates:{},i=new Set;return t.forEach((s,a)=>{const l=`/screens/${a}`;if(!rt(s))return void n.push({path:l,message:"a screen is {template, title, icon?, params?, nav?, exposed?}"});for(const c of Object.keys(s).sort())VC.includes(c)||n.push({path:`${l}/${pr(c)}`,message:`unknown screen key ${c}`});if(typeof s.template!="string"||!s.template?n.push({path:`${l}/template`,message:"template is a required string"}):qC(o,s.template)?i.has(s.template)?n.push({path:`${l}/template`,message:`duplicate screen ${s.template}`}):i.add(s.template):n.push({path:`${l}/template`,message:`template ${s.template} names no package template`}),typeof s.title!="string"||!s.title.trim()?n.push({path:`${l}/title`,message:"title is a required string"}):[...s.title].length>of&&n.push({path:`${l}/title`,message:`title is at most ${of} characters`}),s.icon!==void 0&&(typeof s.icon!="string"||!UC.has(s.icon))&&n.push({path:`${l}/icon`,message:`icon ${typeof s.icon=="string"?s.icon:JSON.stringify(s.icon)} is not a genUI icon`}),s.params!==void 0)if(!rt(s.params))n.push({path:`${l}/params`,message:"params is an object of strings"});else for(const c of Object.keys(s.params).sort())typeof s.params[c]!="string"&&n.push({path:`${l}/params/${pr(c)}`,message:`params.${c} is a string`});s.nav!==void 0&&s.nav!==!1&&n.push({path:`${l}/nav`,message:"nav is false or absent"}),s.exposed!==void 0&&n.push(...ZC(s.exposed,`${l}/exposed`))}),n.push(...QC(e,i)),n}function ZC(e,t){if(!rt(e))return[{path:t,message:"exposed is {description, params?}"}];const n=[];for(const r of Object.keys(e).sort())KC.includes(r)||n.push({path:`${t}/${pr(r)}`,message:`unknown exposed key ${r}`});if(typeof e.description!="string"||!e.description.trim()?n.push({path:`${t}/description`,message:"description is a required string"}):[...e.description].length>sf&&n.push({path:`${t}/description`,message:`description is at most ${sf} characters`}),e.params===void 0)return n;if(!rt(e.params))return[...n,{path:`${t}/params`,message:"params is an object of {required?, description?}"}];for(const r of Object.keys(e.params).sort()){const o=e.params[r],i=`${t}/params/${pr(r)}`;if(YC.test(r)||n.push({path:i,message:`param ${r} is letters, digits and _`}),!rt(o)){n.push({path:i,message:"a param is {required?, description?}"});continue}for(const s of Object.keys(o).sort())GC.includes(s)||n.push({path:`${i}/${pr(s)}`,message:`unknown param key ${s}`});o.required!==void 0&&typeof o.required!="boolean"&&n.push({path:`${i}/required`,message:"required is a boolean"}),o.description!==void 0&&typeof o.description!="string"&&n.push({path:`${i}/description`,message:"description is a string"})}return n}function JC(e){if(typeof e!="string")return null;const t=/^\s*(?:'([^'\\]*)'|"([^"\\]*)")\s*$/.exec(e);return t?t[1]??t[2]??"":null}function QC(e,t){const n=[],r=(o,i)=>{o!==null&&!t.has(o)&&n.push({path:i,message:`navigate: ${o} is not a screen`})};if(rt(e.templates))for(const o of Object.keys(e.templates).sort()){const i=e.templates[o];!rt(i)||!Array.isArray(i.components)||i.components.forEach((s,a)=>{if(!(!rt(s)||!rt(s.on)))for(const l of Object.keys(s.on).sort()){const c=s.on[l],u=rt(c)&&rt(c.functionCall)?c.functionCall:null;if(!u||u.call!==So)continue;const d=`/templates/${pr(o)}/components/${a}/on/${pr(l)}/functionCall/args`,p=u.args;rt(p)?typeof p.screen=="string"&&r(p.screen,`${d}/screen`):n.push({path:d,message:"navigate takes {screen, params?}"})}})}if(rt(e.actions))for(const o of Object.keys(e.actions).sort()){const i=e.actions[o];(rt(i)&&Array.isArray(i.steps)?i.steps:[]).forEach((a,l)=>{if(!rt(a)||a.call!==So)return;const c=`/actions/${pr(o)}/steps/${l}/args`;rt(a.args)?r(JC(a.args.screen),`${c}/screen`):n.push({path:c,message:"navigate takes {screen, params?}"})})}return n}function eA(e){return Array.isArray(e.screens)?e.screens.filter(t=>rt(t)&&typeof t.template=="string"):[]}function tA(e,t){if(!rt(t))return{error:"navigate takes {screen, params?}"};if(typeof t.screen!="string"||!t.screen)return{error:"navigate: screen is a required string"};if(!eA(e).some(r=>r.template===t.screen))return{error:`navigate: ${t.screen} is not a screen`};const n={};if(t.params!==void 0&&t.params!==null){if(!rt(t.params))return{error:"navigate: params is an object of strings"};for(const r of Object.keys(t.params).sort()){const o=t.params[r];if(typeof o!="string")return{error:`navigate: params.${r} is a string`};n[r]=o}}return{screen:t.screen,params:n}}function nA(e,t){return!rt(t)||!e.includes("${params.")?e:e.replace(/\$\{params\.([A-Za-z0-9_]+)\}/g,(n,r)=>{const o=t[r];return typeof o=="string"?encodeURIComponent(o):""})}const zi={actions:32,steps:64,maxSteps:1e5},Ju=["require","records.upsert","records.delete","set","call"],rA=/^[a-z][A-Za-z0-9_]{0,31}$/,af="actions.",Nl="records.batch",we=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),nn=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),fn=e=>e.replace(/~/g,"~0").replace(/\//g,"~1"),hy=/^(\/([^/~]|~[01])*)*$/;function tl(e){return e.startsWith(af)?e.slice(af.length):null}function my(e){if(!we(e))return null;const t=Object.keys(e).filter(n=>Ju.includes(n));return t.length===1?t[0]:null}function oA(e){const t=we(e.params)?e.params:{};return{params:el(we(t.properties)?t.properties:{},t.required),data:Ze("dyn"),me:Ze("string")}}function Co(e,t){if(Ot(t))return Ot(e)&&Co(e["?"],t["?"]);if(Ot(e))return Co(e["?"],t);if(e==="dyn"||t==="dyn"||t==="null")return!0;const n=r=>r==="string"||r==="date"||r==="timestamp";return n(e)?n(t):Be(e)===Be(t)}function iA(e){const t=[],n=e.actions;if(n!==void 0)if(!we(n))t.push({path:"/actions",message:"actions is an object of named actions"});else{const r=Object.keys(n).sort();r.length>zi.actions&&t.push({path:"/actions",message:`at most ${zi.actions} actions`});for(const o of r)t.push(...sA(e,o,n[o],`/actions/${fn(o)}`))}return t}function sA(e,t,n,r){const o=[];if(rA.test(t)||o.push({path:r,message:"an action name is a letter, then letters, digits and underscores"}),!we(n))return[...o,{path:r,message:"an action is {params?, steps}"}];if(n.params!==void 0&&o.push(...Bg(n.params,`${r}/params`)),!Array.isArray(n.steps)||n.steps.length===0)return[...o,{path:`${r}/steps`,message:"steps is a non-empty array"}];n.steps.length>zi.steps&&o.push({path:`${r}/steps`,message:`at most ${zi.steps} steps`});const i=oA(n),s=we(e.records)?e.records:{},a=Array.isArray(e.functions)?e.functions.filter(l=>typeof l=="string"):null;return n.steps.forEach((l,c)=>o.push(...aA(l,`${r}/steps/${c}`,i,s,a))),o}function oo(e,t,n,r){if(typeof e!="string")return Fi(e);const o=Ua(e,n);return"error"in o?(r.push({path:t,message:o.error}),null):o.type}function aA(e,t,n,r,o){const i=[],s=my(e);if(s===null||!we(e))return[{path:t,message:`a step is one of ${Ju.join(", ")}`}];const a=e[s],l=`${t}/${fn(s)}`;switch(s){case"require":{if(typeof a!="string")i.push({path:l,message:"require is an expression"});else{const c=oo(a,l,n,i);c!==null&&c!=="bool"&&c!=="dyn"&&i.push({path:l,message:`require needs a bool, got ${Be(c)}`})}return(typeof e.message!="string"||!e.message)&&i.push({path:`${t}/message`,message:"message is the text shown when the requirement fails"}),i}case"records.upsert":{if(!we(a))return[{path:l,message:"records.upsert is {kind, data, id?}"}];const c=typeof a.kind=="string"?a.kind:"",u=nn(r,c)&&we(r[c])?r[c]:null;if(u||i.push({path:`${l}/kind`,message:`records:${c} names no declared kind`}),a.id!==void 0){const h=oo(a.id,`${l}/id`,n,i);h!==null&&!Co("string",h)&&i.push({path:`${l}/id`,message:`id is a string, got ${Be(h)}`})}if(!we(a.data))return[...i,{path:`${l}/data`,message:"data is an object of field expressions"}];const d=u&&we(u.schema)?u.schema:null,p=d&&we(d.properties)?d.properties:{};for(const h of Object.keys(a.data).sort()){const f=`${l}/data/${fn(h)}`,y=oo(a.data[h],f,n,i);if(!d)continue;if(!nn(p,h)){d.additionalProperties!==!0&&i.push({path:f,message:`${h} is not in the schema of ${c}`});continue}const v=Array.isArray(d.required)&&d.required.includes(h)?Ur(p[h]):Ze(Ur(p[h]));y!==null&&!Co(v,y)&&i.push({path:f,message:`${h} is ${Be(v)}, got ${Be(y)}`})}if(d&&a.id===void 0&&Array.isArray(d.required))for(const h of d.required)typeof h=="string"&&!nn(a.data,h)&&i.push({path:`${l}/data`,message:`${h} is required by ${c}`});return i}case"records.delete":{if(!we(a)||a.id===void 0)return[{path:l,message:"records.delete is {id}"}];const c=oo(a.id,`${l}/id`,n,i);return c!==null&&!Co("string",c)&&i.push({path:`${l}/id`,message:`id is a string, got ${Be(c)}`}),i}case"set":return(!we(a)||typeof a.path!="string"||!hy.test(a.path))&&i.push({path:`${l}/path`,message:"path is a JSON pointer"}),we(a)&&oo(a.value??null,`${l}/value`,n,i),i;case"call":{if(typeof a!="string"||!a)return[{path:l,message:"call names a host function"}];const c=Si(a);if(c==="write"?i.push({path:l,message:`${na(a,c)}: use a records.upsert, records.delete or set step`}):c==="pure"?i.push({path:l,message:`${a} is pure: compute it in an expression`}):tl(a)!==null?i.push({path:l,message:"an action never runs another action"}):a!==So&&o!==null&&!o.some(u=>u===a||u.endsWith("*")&&a.startsWith(u.slice(0,-1)))&&i.push({path:l,message:`${a} is not in the package's functions`}),e.args!==void 0)if(!we(e.args))i.push({path:`${t}/args`,message:"args is an object of expressions"});else for(const u of Object.keys(e.args).sort())oo(e.args[u],`${t}/args/${fn(u)}`,n,i);return i}}return i}function lA(e){const t=[];if(!we(e.templates))return t;const n=we(e.actions)?e.actions:{},r=(o,i)=>{if(Array.isArray(o))return o.forEach((s,a)=>r(s,`${i}/${a}`));if(we(o)){if(typeof o.call=="string"){const s=Si(o.call);s!=="pure"&&t.push({path:`${i}/call`,message:`${na(o.call,s)}: a binding is pure, name an action in on.press`})}for(const[s,a]of Object.entries(o))r(a,`${i}/${fn(s)}`)}};for(const[o,i]of Object.entries(e.templates))!we(i)||!Array.isArray(i.components)||i.components.forEach((s,a)=>{if(!we(s))return;const l=`/templates/${fn(o)}/components/${a}`;for(const[c,u]of Object.entries(s)){if(c!=="on"){r(u,`${l}/${fn(c)}`);continue}if(we(u))for(const[d,p]of Object.entries(u)){const h=`${l}/on/${fn(d)}`;if(we(p))for(const[f,y]of Object.entries(p)){if(f!=="functionCall"||!we(y)){r(y,`${h}/${fn(f)}`);continue}const g=typeof y.call=="string"?y.call:"",v=tl(g);v!==null&&!nn(n,v)&&t.push({path:`${h}/functionCall/call`,message:`action ${v} names no package action`}),v!==null&&nn(n,v)&&we(n[v])&&t.push(...cA(v,n[v],y.args,`${h}/functionCall/args`)),g==="bind"&&t.push(...uA(e,y.args,`${h}/functionCall/args`));for(const[m,b]of Object.entries(y))m!=="call"&&r(b,`${h}/functionCall/${fn(m)}`)}}}});return t}function cA(e,t,n,r){if(n!==void 0&&!we(n))return[{path:r,message:`args is an object of action ${e}'s params`}];const o=[],i=we(t.params)?t.params:{},s=we(i.properties)?i.properties:{},a=Array.isArray(i.required)?i.required.filter(c=>typeof c=="string"):[],l=we(n)?n:{};for(const c of Object.keys(l).sort()){const u=`${r}/${fn(c)}`;if(!nn(s,c)){i.additionalProperties!==!0&&o.push({path:u,message:`${c} is not a param of action ${e}`});continue}const d=l[c];if(typeof d!="string"&&typeof d!="number"&&typeof d!="boolean")continue;const p=a.includes(c)?Ur(s[c]):Ze(Ur(s[c])),h=Fi(d);Co(p,h)||o.push({path:u,message:`${c} is ${Be(p)}, got ${Be(h)}`})}for(const c of a)nn(l,c)||o.push({path:r,message:`${c} is required by action ${e}`});return o}function uA(e,t,n){if(!we(t)||typeof t.source!="string")return[];const r=t.source,o=`${n}/source`,i=Qt(r);if(!i)return[{path:o,message:"source is a scheme:name URI"}];const s=[];if(Array.isArray(e.sources)&&e.sources.every(a=>typeof a=="string")&&!nl(e.sources,r)&&s.push({path:o,message:`source ${r} is not in the package's sources`}),i.scheme===Hr){(!we(e.records)||!nn(e.records,i.name))&&s.push({path:o,message:`records:${i.name} names no declared kind`});const a=i.params.query;a!==void 0&&(!we(e.queries)||!nn(e.queries,a))&&s.push({path:o,message:`query ${a} names no package query`})}return s}class gy extends Error{}const At=e=>{throw new gy(e)},ba=e=>e.map(t=>`${t.path||"/"} ${t.message}`).join("; ");function yy(e,t,n,r={}){const o=we(e.actions)?e.actions:{},i=nn(o,t)&&we(o[t])?o[t]:null;if(!i||!Array.isArray(i.steps))return{error:`no action ${t}`};const s=n??{};if(!we(s))return{error:"params is an object"};if(we(i.params)){const d=Di(i.params,s);if(d.length)return{error:`params: ${ba(d)}`}}const a={params:s,data:r.data??null,me:r.me??null},l=we(e.records)?e.records:{};let c=r.maxSteps??zi.maxSteps;const u={writes:[],sets:[],calls:[]};try{i.steps.forEach((d,p)=>{const h=`step ${p}`,f=m=>{c-=m,c<0&&At(`${h}: action step limit exceeded`)};f(1);const y=m=>{if(typeof m!="string")return m;const b=Wo(m);if("error"in b)return At(`${h}: ${b.error}`);const x=Math.min(Po.maxSteps,c),{result:$,steps:S}=wx(b.ast,a,{now:r.now,offset:r.offset,maxSteps:x});return"error"in $&&($.error==="step limit exceeded"&&x===c&&At(`${h}: action step limit exceeded`),At(`${h}: ${$.error}`)),f(S),$.value},g=my(d);if(g===null||!we(d))return At(`${h}: a step is one of ${Ju.join(", ")}`);const v=d[g];switch(g){case"require":{const m=y(v);typeof m!="boolean"&&At(`${h}: require needs a bool, got ${We(m)}`),m||At(typeof d.message=="string"&&d.message?d.message:`${h}: requirement failed`);return}case"records.upsert":{if(!we(v)||!we(v.data))return At(`${h}: records.upsert is {kind, data, id?}`);const m=typeof v.kind=="string"?v.kind:"",b=nn(l,m)&&we(l[m])?l[m]:null;if(!b||!we(b.schema))return At(`${h}: records: no kind ${m}`);let x;if(v.id!==void 0){const C=y(v.id);(typeof C!="string"||!C)&&At(`${h}: id is a string, got ${We(C)}`),x=C}const $={};for(const C of Object.keys(v.data).sort())$[C]=y(v.data[C]);const S=b.schema,A=Di(x===void 0?S:{...S,required:[]},$);A.length&&At(`${h}: records: ${ba(A)}`),u.writes.push(x===void 0?{op:"upsert",kind:m,data:$}:{op:"upsert",kind:m,data:$,id:x});return}case"records.delete":{if(!we(v))return At(`${h}: records.delete is {id}`);const m=y(v.id);(typeof m!="string"||!m)&&At(`${h}: id is a string, got ${We(m)}`),u.writes.push({op:"delete",id:m});return}case"set":{if(!we(v)||typeof v.path!="string"||!hy.test(v.path))return At(`${h}: path is a JSON pointer`);u.sets.push({path:v.path,value:y(v.value??null)});return}case"call":{if(typeof v!="string"||Si(v)!=="host"||tl(v)!==null)return At(`${h}: call names a host function`);const m={};if(we(d.args))for(const b of Object.keys(d.args).sort())m[b]=y(d.args[b]);u.calls.push({name:v,args:m});return}}})}catch(d){if(d instanceof gy)return{error:d.message};throw d}return{plan:u}}function dA(e,t,n){let r=[...e];const o=[];let i=0;for(const[s,a]of t.entries()){const l=`write ${s}`,c={id:n.me??null,role:n.role??null,access:n.access},u=(v,m,b)=>n.role===void 0?null:Rc(Dc(n.records?.[v]),m,c,b),d=v=>r.find(m=>m.id===v&&(n.role===void 0||Rc(Dc(n.records?.[m.kind]),"read",c,m)===null));if(a.op==="delete"){const v=d(a.id);if(!v)return{error:`${l}: record ${a.id} not found`};const m=u(v.kind,"delete",v);if(m)return{error:`${l}: ${m}`};r=r.filter(b=>b.id!==a.id),o.push(a.id);continue}const p=n.records&&nn(n.records,a.kind)&&we(n.records[a.kind])?n.records[a.kind]:null;if(!p||!we(p.schema))return{error:`${l}: records: no kind ${a.kind}`};const h=p.schema;if(a.id!==void 0){const v=d(a.id);if(!v)return{error:`${l}: record ${a.id} not found`};if(v.kind!==a.kind)return{error:`${l}: record ${a.id} is not of kind ${a.kind}`};const m=u(a.kind,"update",v);if(m)return{error:`${l}: ${m}`};const b={...v.data,...a.data},x=Di(h,b);if(x.length)return{error:`${l}: records: ${ba(x)}`};r=r.map($=>$.id===a.id?{...$,data:b,updatedAt:n.now}:$),o.push(a.id);continue}const f=u(a.kind,"create");if(f)return{error:`${l}: ${f}`};const y=Di(h,a.data);if(y.length)return{error:`${l}: records: ${ba(y)}`};const g=n.newId(i++);r.push({id:g,kind:a.kind,data:{...a.data},createdBy:n.me??null,authorId:n.me??null,createdAt:n.now,updatedAt:n.now}),o.push(g)}return{rows:r,ids:o}}const va={tests:50,gotMax:300},Ll={now:"2026-01-01T00:00:00.000Z",as:"member",role:"member"},pA=["member","owner"],lf=["expr","query","action"],Ke=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),ai=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),fA=e=>e.replace(/~/g,"~0").replace(/\//g,"~1"),by=["id","author"];function Uc(e,t){return Ke(e)?Ke(t)&&Object.keys(e).every(n=>Uc(e[n],ai(t,n)?t[n]:null)):Array.isArray(e)?Array.isArray(t)&&t.length===e.length&&e.every((n,r)=>Uc(n,t[r])):(e??null)===(t??null)}function vy(e){const t=e.tests;if(t===void 0)return[];if(!Array.isArray(t))return[{path:"/tests",message:"tests is a list of {name, expr | query | action, expect}"}];const n=[];t.length>va.tests&&n.push({path:"/tests",message:`at most ${va.tests} tests`});const r=Ke(e.records)?e.records:{},o=Ke(e.queries)?e.queries:{},i=Ke(e.actions)?e.actions:{};return t.forEach((s,a)=>{const l=`/tests/${a}`;if(!Ke(s))return void n.push({path:l,message:"a test is {name, expr | query | action, expect}"});(typeof s.name!="string"||!s.name.trim())&&n.push({path:`${l}/name`,message:"name is a non-empty string"});const c=lf.filter(h=>s[h]!==void 0);if(c.length!==1&&n.push({path:l,message:`a test runs one of ${lf.join(", ")}`}),ai(s,"expect")||n.push({path:`${l}/expect`,message:"expect is required"}),s.now!==void 0&&(typeof s.now!="string"||qa(s.now)===null)&&n.push({path:`${l}/now`,message:"now is an ISO timestamp"}),s.as!==void 0&&(typeof s.as!="string"||!s.as)&&n.push({path:`${l}/as`,message:"as is a member id"}),s.role!==void 0&&!pA.includes(s.role)&&n.push({path:`${l}/role`,message:"role is member or owner"}),s.records!==void 0)if(!Ke(s.records))n.push({path:`${l}/records`,message:"records is {<kind>: [rows]}"});else for(const h of Object.keys(s.records).sort()){const f=`${l}/records/${fA(h)}`,y=ai(r,h)&&Ke(r[h])?r[h]:null;if(!y||!Ke(y.schema)){n.push({path:f,message:`records:${h} names no declared kind`});continue}const g=s.records[h];if(!Array.isArray(g)){n.push({path:f,message:"a kind's sample is a list of rows"});continue}g.forEach((v,m)=>{if(!Ke(v))return void n.push({path:`${f}/${m}`,message:"a row is an object"});for(const b of by)v[b]!==void 0&&(typeof v[b]!="string"||!v[b])&&n.push({path:`${f}/${m}/${b}`,message:`${b} is a non-empty string`});for(const b of Di(y.schema,$y(v)))n.push({path:`${f}/${m}${b.path}`,message:b.message})})}if(c.length!==1)return;const u=c[0],d=s[u],p=`${l}/${u}`;if(u==="expr")!Ke(d)||typeof d.expr!="string"?n.push({path:`${p}/expr`,message:"expr is a string"}):d.vars!==void 0&&!Ke(d.vars)&&n.push({path:`${p}/vars`,message:"vars is an object"});else if(u==="query"){const h=Ke(d)&&typeof d.name=="string"?d.name:"";ai(o,h)||n.push({path:`${p}/name`,message:`query ${h} names no package query`}),Ke(d)&&d.params!==void 0&&!Ke(d.params)&&n.push({path:`${p}/params`,message:"params is an object"})}else{const h=Ke(d)&&typeof d.name=="string"?d.name:"";ai(i,h)||n.push({path:`${p}/name`,message:`action ${h} names no package action`})}}),n}function $y(e){const t={};for(const[n,r]of Object.entries(e))by.includes(n)||(t[n]=r);return t}function hA(e,t,n){const r=[];if(!Ke(e))return r;for(const o of Object.keys(e).sort()){const i=e[o];Array.isArray(i)&&i.forEach((s,a)=>{if(!Ke(s))return;const l=typeof s.author=="string"?s.author:t;r.push({id:typeof s.id=="string"?s.id:`${o}-${a+1}`,kind:o,data:$y(s),createdBy:l,authorId:l,createdAt:n,updatedAt:n})})}return r}function mA(e,t,n,r,o){return!Ke(e)||Object.keys(e).length!==1||typeof e.source!="string"?e:xy(e.source,t,n,r,o)}function xy(e,t,n,r,o){const i=Zu(e,Ke(t.queries)?t.queries:void 0),s=Qt(i),a=s?.scheme===Hr?iy(s):null;return a?mC(n,a,{me:r,now:o,computed:a.app===null?dC(t.records,a.from):void 0,refs:a.app===null?pC(t.records,a.from):void 0,transitions:a.app===null&&a.from&&Ke(t.records)?xS(t.records[a.from]):null})??null:{error:`${e} is not a records source`}}function gA(e,t){const n=typeof t.now=="string"?t.now:Ll.now,r=qa(n),o=typeof t.as=="string"?t.as:Ll.as,i=typeof t.role=="string"?t.role:Ll.role,s=Ke(e.records)?e.records:void 0,a=hA(t.records,o,n),l=Np(a,s,{id:o,role:i});if(Ke(t.expr)){const h={};if(Ke(t.expr.vars))for(const[y,g]of Object.entries(t.expr.vars))h[y]=mA(g,e,l,o,n);const f=Iu(t.expr.expr,h,{now:r});return"error"in f?{error:f.error}:f.value}if(Ke(t.query)){const h=t.query.name,f=e.queries[h],y=Ke(f)&&typeof f.from=="string"?f.from:"",g={};if(Ke(t.query.params))for(const[v,m]of Object.entries(t.query.params))g[v]=typeof m=="string"?m:Wr(m);return xy(Gu(`${Hr}:${y}`,{query:h,...g}),e,l,o,n)}const c=t.action,u=yy(e,c.name,c.params,{data:c.data,me:o,now:r});if("error"in u)return{error:u.error};const d=dA(a,u.plan.writes,{records:s,me:o,role:i,now:n,newId:h=>`new-${h+1}`});if("error"in d)return{error:d.error};const p={};for(const h of Np(d.rows,s,{id:o,role:i}))(p[h.kind]??=[]).push({...h.data,id:h.id,author:h.authorId??h.createdBy});return{records:p,sets:u.plan.sets,calls:u.plan.calls}}function yA(e){return!Array.isArray(e.tests)||vy(e).length?[]:e.tests.map(t=>{const n=gA(e,t);return{name:t.name,pass:Uc(t.expect,n),got:n}})}function bA(e,t,n){const r=Array.from(Wr(n??null)),o=r.length>va.gotMax?`${r.slice(0,va.gotMax).join("")}…`:r.join("");return`${e}: expected ${Wr(t??null)}, got ${o}`}function vA(e){const t=Array.isArray(e.tests)?e.tests:[];return yA(e).flatMap((n,r)=>n.pass?[]:[{path:`/tests/${r}`,message:bA(n.name,t[r].expect,n.got)}])}const cf={date:104,time:64,"date-time":152,number:64,integer:64,boolean:56},$A=136,xA=80,wA=200,kA="/recordForm",SA="/recordTable",Qu=e=>!!e&&typeof e=="object"&&!Array.isArray(e);function ed(e){const t=e.replace(/_/g," ").replace(/([a-z0-9])([A-Z])/g,"$1 $2").trim().toLowerCase();return t?t[0].toUpperCase()+t.slice(1):e}function td(e){const t=Object.keys(e.schema.properties),n=(e.schema.required??[]).filter((r,o,i)=>t.includes(r)&&i.indexOf(r)===o);return[...n,...t.filter(r=>!n.includes(r)).sort()]}const nd=e=>e.format==="attachment"||e.type==="array"&&e.items?.format==="attachment";function uf(e,t){const n=e.schema.required??[],r=e.refs??{};return td(e).flatMap(o=>{const i=e.schema.properties[o];if(nd(i))return[];const s={path:`${t}/${o}`},a={name:o,label:ed(o),widget:"text",required:n.includes(o),wide:!1,value:s};i.description&&(a.placeholder=i.description);const l=r[o];l==="member"?Object.assign(a,{widget:"select",source:"exp:members",searchable:!0}):l==="issue"?Object.assign(a,{widget:"select",source:"exp:issues",searchable:!0}):i.type==="boolean"?a.widget="switch":i.type==="number"||i.type==="integer"?(a.widget="number",i.minimum!==void 0&&(a.min=i.minimum),i.maximum!==void 0&&(a.max=i.maximum),i.type==="integer"&&Object.assign(a,{step:1,precision:0})):i.type==="array"?(i.items?.enum?Object.assign(a,{widget:"select",multiple:!0,options:i.items.enum.map(u=>({label:u,value:u}))}):a.widget="chips",i.maxLength!==void 0&&(a.max=i.maxLength),a.wide=!0):i.enum?Object.assign(a,{widget:"select",options:i.enum.map(u=>({label:u,value:u}))}):i.format==="date"?a.widget="date":i.format==="time"?a.widget="time":i.format==="date-time"?a.placeholder??="YYYY-MM-DDTHH:MM":(i.maxLength===void 0||i.maxLength>wA)&&Object.assign(a,{widget:"textarea",wide:!0});const c=[];return a.required&&a.widget!=="switch"&&c.push({condition:{call:"required",args:{value:s}},message:"$string.required"}),i.type==="string"&&i.maxLength!==void 0&&!i.enum&&a.widget!=="select"&&c.push({condition:{call:"length",args:{value:s,max:i.maxLength}},message:"$string.invalidValue"}),(i.type==="number"||i.type==="integer")&&(i.minimum!==void 0||i.maximum!==void 0)&&c.push({condition:{call:"numeric",args:{value:s,...i.minimum!==void 0?{min:i.minimum}:{},...i.maximum!==void 0?{max:i.maximum}:{}}},message:"$string.invalidValue"}),c.length&&(a.checks=c),[a]})}function CA(e,t,n){const o=(t??td(e)).filter(i=>e.schema.properties[i]&&!nd(e.schema.properties[i])).map(i=>{const s=e.schema.properties[i],a={key:i,label:ed(i),sortable:!0};s.type==="number"||s.type==="integer"?Object.assign(a,{type:"number",align:"end"}):s.type==="boolean"?a.type="boolean":s.format==="date"&&(a.type="date");const l=s.type==="string"?s.format?cf[s.format]:void 0:cf[s.type];return l!==void 0?a.width=l:a.truncate=!0,a});return o.push({key:"updatedAt",label:"Updated",type:"relativeTime",width:$A,sortable:!0}),n&&o.push({key:"menu",label:"",type:"slot",slot:"menu",width:xA}),o}const io=(e,t)=>({functionCall:{call:"set",args:{path:e,value:t}}}),sr=(e,t,n)=>{const r=e.on=Qu(e.on)?{...e.on}:{};r[t]===void 0&&(r[t]=n)};function df(e,t,n){const r={};for(const i of t)r[i.name]=i.value;const o={kind:e};return n!==void 0&&(o.id=n),o.data=r,{functionCall:{call:"records.upsert",args:o}}}function wy(e,t=[],n,r={}){const o=[],i=[],s=[...t];for(const a of e){if(!Qu(a)||a.component!=="RecordForm"&&a.component!=="RecordTable"){o.push(a);continue}const l={...a},c=String(l.id),u=typeof l.kind=="string"?l.kind:"",d=n&&Object.prototype.hasOwnProperty.call(n,u)?n[u]:void 0;if(!d){l.missing=!0,o.push(l);continue}if(l.component==="RecordForm"){const x=typeof l.path=="string"?l.path:`${kA}/${c}`,$=uf(d,x);l.path=x,l.fields=$,r.readOnly&&(l.readOnly=!0),sr(l,"submit",df(u,$,l.recordId)),o.push(l);continue}const p=`${SA}/${c}`,h=l.editable!==!1&&!r.readOnly,f=Array.isArray(l.columns)?l.columns.filter(x=>typeof x=="string"):void 0,y=`${p}/editor/draft`,g=uf(d,y);l.title=d.title??ed(u),l.cols=CA(d,f,h),l.rows={path:`${p}/rows/rows`},l.count={call:"fill",args:{template:"$string.recordCount",params:{count:{call:"coalesce",args:{values:[{path:`${p}/rows/count`},0]}}}}},l.loading={call:"not",args:{value:{path:`${p}/rows`}}},r.readOnly&&(l.add=!1),l.editable=h,l.children={componentId:`${c}__row`,path:`${p}/rows/rows`,key:"id"},h?(l.fields=g,l.path=y,l.editorOpen={path:`${p}/editor/open`},l.editorId={path:`${y}/id`},l.deleteOpen={path:`${p}/delete/open`},sr(l,"add",io(`${p}/editor`,{open:!0,draft:{}})),sr(l,"edit",io(`${p}/editor`,{open:!0,draft:{path:""}})),sr(l,"delete",io(`${p}/delete`,{open:!0,id:{path:"id"}})),sr(l,"submit",df(u,g,{path:`${y}/id`})),sr(l,"cancel",io(`${p}/editor/open`,!1)),sr(l,"confirm",{functionCall:{call:"records.delete",args:{id:{path:`${p}/delete/id`}}}}),sr(l,"cancelDelete",io(`${p}/delete/open`,!1))):l.add=!1,o.push(l);const v=(f??td(d)).filter(x=>d.schema.properties[x]&&!nd(d.schema.properties[x])),m={id:`${c}__row`,component:"Row",title:{call:"coalesce",args:{values:[{call:"text",args:{value:{path:v[0]??"id"}}},"—"]}}};v[1]&&(m.subtitle={call:"coalesce",args:{values:[{call:"text",args:{value:{path:v[1]}}},""]}}),m.meta={call:"formatRelativeTime",args:{value:{path:"updatedAt"}}},h&&(m.on={press:io(`${p}/editor`,{open:!0,draft:{path:""}})}),i.push(m);const b=typeof l.query=="string"&&l.query.trim()?l.query.trim().replace(/^\?/,""):"sort=updatedAt&order=desc";s.push({path:`${p}/rows`,source:`records:${u}?${b}`})}return{components:[...o,...i],bindings:s}}function ky(e){return e.some(t=>Qu(t)&&(t.component==="RecordForm"||t.component==="RecordTable"))}const hn=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Sy=e=>e.replace(/~/g,"~0").replace(/\//g,"~1"),AA=[jr,vu,ja];function _A(e,t){const n=[],r=e.children;if(r!=null){const o=Array.isArray(r)&&r.every(s=>typeof s=="string"),i=hn(r)&&typeof r.componentId=="string"&&typeof r.path=="string"&&(r.key===void 0||r.key===null||typeof r.key=="string");!o&&!i&&n.push({path:`${t}/children`,message:"children is a list of ids or {componentId, path, key?}"})}return e.slots!==void 0&&e.slots!==null&&(!hn(e.slots)||Object.values(e.slots).some(o=>typeof o!="string"))&&n.push({path:`${t}/slots`,message:"slots is an object of component ids"}),e.on!==void 0&&e.on!==null&&!hn(e.on)&&n.push({path:`${t}/on`,message:"on is an object of actions"}),e.style!==void 0&&e.style!==null&&!hn(e.style)&&n.push({path:`${t}/style`,message:"style is an object"}),n}function OA(e,t,n){const r=[];return e.forEach((o,i)=>{const s=`${n}/${i}`;if(Array.isArray(o.children)?o.children.forEach((a,l)=>a===t&&r.push(`${s}/children/${l}`)):hn(o.children)&&o.children.componentId===t&&r.push(`${s}/children/componentId`),hn(o.slots))for(const[a,l]of Object.entries(o.slots))l===t&&r.push(`${s}/slots/${Sy(a)}`)}),r}function TA(e,t,n=[]){const r=[],o=typeof e.catalogId=="string"?e.catalogId:"";if(!t.includes(o)||!hn(e.templates))return r;const i=c=>AA.includes(c)||n.some(u=>u.id===c),s=Array.isArray(e.extensions)?e.extensions.map(c=>hn(c)&&typeof c.id=="string"?c.id:""):[],a=!i(o)||s.some(c=>c&&!i(c)),l=i(o)?o:jr;for(const[c,u]of Object.entries(e.templates)){if(!hn(u)||!Array.isArray(u.components))continue;const d=`/templates/${Sy(c)}/components`,p=u.components,h=new Set;let f=p.length>0;for(const S of p)!hn(S)||typeof S.id!="string"||typeof S.component!="string"||h.has(S.id)?f=!1:h.add(S.id);if(!f||!h.has("root"))continue;const y=p,g=y.flatMap((S,A)=>_A(S,`${d}/${A}`));if(g.length){r.push(...g);continue}const v=new Map(y.map((S,A)=>[S.id,A])),m=hn(e.records)?e.records:void 0,b=ky(y)?wy(y,[],m).components:y;for(const S of b){const A=typeof S.id=="string"&&S.id.endsWith("__row")?v.get(S.id.slice(0,-5)):void 0;A!==void 0&&!v.has(S.id)&&v.set(S.id,A)}const x=new Set,$=(S,A)=>{const C=`${S}
24
24
  ${A}`;x.has(C)||(x.add(C),r.push({path:S,message:A}))};for(const S of Uu(b,{catalogId:l,extensions:n}).issues){if(a&&S.message.startsWith("unknown component "))continue;const A=v.get(S.id);if(A!==void 0){$(`${d}/${A}`,S.message);continue}const C=OA(y,S.id,d);C.length===0&&$(d,`${S.id}: ${S.message}`);for(const _ of C)$(_,`${S.id}: ${S.message}`)}}return r}const pf=5,MA=/^[a-z][a-z0-9_]{0,23}$/,EA=["submit","view"],ff=3650,IA=["name","mode","kind","fields","query","expires"],Ut=e=>!!e&&typeof e=="object"&&!Array.isArray(e),wr=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);function PA(e){if(e.share===void 0)return[];if(!Array.isArray(e.share))return[{path:"/share",message:"share is a list of {name, mode, kind, fields?, query?, expires?}"}];const t=[];e.share.length>pf&&t.push({path:"/share",message:`at most ${pf} public links, got ${e.share.length}`});const n=Ut(e.records)?e.records:{},r=Ut(e.queries)?e.queries:{},o=new Set;return e.share.forEach((i,s)=>{const a=`/share/${s}`;if(!Ut(i))return void t.push({path:a,message:"a public link is {name, mode, kind, fields?, query?, expires?}"});for(const f of Object.keys(i).sort())IA.includes(f)||t.push({path:`${a}/${f}`,message:`unknown public link key ${f}`});typeof i.name!="string"||!MA.test(i.name)?t.push({path:`${a}/name`,message:"a name is a lowercase letter, then lowercase letters, digits and underscores (24 at most)"}):o.has(i.name)?t.push({path:`${a}/name`,message:`duplicate public link ${i.name}`}):o.add(i.name),(typeof i.mode!="string"||!EA.includes(i.mode))&&t.push({path:`${a}/mode`,message:"mode is submit or view"});const l=typeof i.kind=="string"&&wr(n,i.kind)?n[i.kind]:void 0;Ut(l)||t.push({path:`${a}/kind`,message:`${String(i.kind)} names no declared kind`});const c=Ut(l)&&Ut(l.schema)?l.schema:{},u=Ut(c.properties)?c.properties:{},d=Array.isArray(c.required)?c.required:[],p=Ut(l)&&Ut(l.refs)?l.refs:{},h=f=>Ut(f)&&(f.format==="attachment"||Ut(f.items)&&f.items.format==="attachment");if(i.fields!==void 0){if(!Array.isArray(i.fields)||!i.fields.length||i.fields.some(f=>typeof f!="string"))t.push({path:`${a}/fields`,message:"fields is a non-empty list of field names"});else if(i.fields.forEach((f,y)=>{Ut(l)&&!wr(u,f)&&t.push({path:`${a}/fields/${y}`,message:`${f} is not a field of ${String(i.kind)}`});const g=wr(u,f)?u[f]:void 0;h(g)&&t.push({path:`${a}/fields/${y}`,message:`a public link cannot carry the file field ${f}`}),wr(p,f)&&t.push({path:`${a}/fields/${y}`,message:`a public link cannot carry the ref field ${f}`})}),i.mode==="submit")for(const f of d)i.fields.includes(f)||t.push({path:`${a}/fields`,message:`a submit link needs the required field ${String(f)}`})}if(i.mode==="submit"&&d.some(f=>typeof f=="string"&&wr(u,f)&&h(u[f]))&&t.push({path:`${a}/kind`,message:"a submit link cannot fill a required file field"}),i.mode==="submit"&&i.fields===void 0)for(const f of d)typeof f=="string"&&wr(p,f)&&t.push({path:`${a}/kind`,message:`a submit link cannot fill the required ref field ${f}`});if(i.query!==void 0)if(i.mode!=="view")t.push({path:`${a}/query`,message:"only a view link has a query"});else if(typeof i.query!="string"||!wr(r,i.query))t.push({path:`${a}/query`,message:`${String(i.query)} names no package query`});else{const f=r[i.query],y=Ut(f)&&typeof f.from=="string"?f.from.trim():"";y&&y!==i.kind&&t.push({path:`${a}/query`,message:`query ${i.query} reads records:${y}, the link's kind is ${String(i.kind)}`})}i.expires!==void 0&&(typeof i.expires!="number"||!Number.isInteger(i.expires)||i.expires<1||i.expires>ff)&&t.push({path:`${a}/expires`,message:`expires is a whole number of days, 1 to ${ff}`})}),t}const ei=4;function rd(e=[]){const t=[];for(const n of[jr,vu,ja,...e])t.includes(n)||t.push(n);return t}function DA(e=[]){return{"v0.9":{supportedCatalogIds:rd(e)}}}const RA=/^[a-z][A-Za-z0-9_]{0,31}$/;function hf(e){return e.map(t=>({id:t.id,...t.version?{version:t.version}:{},components:[...Object.keys(t.components),...Object.keys(t.macros??{})],def:t}))}const Vc=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;function FA(e,t){const n=Vc.exec(e),r=Vc.exec(t);if(!n||!r)return!1;const[o,i,s]=[Number(n[1]),Number(n[2]),Number(n[3])],[a,l,c]=[Number(r[1]),Number(r[2]),Number(r[3])];return o===a&&(i>l||i===l&&s>=c)}const Ie=e=>!!e&&typeof e=="object"&&!Array.isArray(e),zA=/^(\/([^/~]|~[01])*)*$/;function NA(e,t=rd(),n){const r=[];if(!Ie(e))return[{path:"",message:"a package is an object"}];e.formatVersion===void 0?r.push({path:"/formatVersion",message:`formatVersion is required (${ei})`}):typeof e.formatVersion!="number"||!Number.isInteger(e.formatVersion)||e.formatVersion<1?r.push({path:"/formatVersion",message:"formatVersion is a positive integer"}):e.formatVersion>ei?r.push({path:"/formatVersion",message:`format version ${e.formatVersion} is newer than this host (${ei})`}):e.formatVersion<ei&&r.push({path:"/formatVersion",message:`format version ${e.formatVersion} is no longer read: write ${ei}`});for(const o of["id","name","version","catalogId"])(typeof e[o]!="string"||!e[o])&&r.push({path:`/${o}`,message:`${o} is a required string`});if(typeof e.catalogId=="string"&&e.catalogId&&!t.includes(e.catalogId)&&r.push({path:"/catalogId",message:`unsupported catalog ${e.catalogId}`}),!Ie(e.templates)||!Object.keys(e.templates).length)r.push({path:"/templates",message:"templates is a non-empty object"});else for(const[o,i]of Object.entries(e.templates)){const s=`/templates/${o}`;if(!Ie(i)){r.push({path:s,message:"a template is an object"});continue}const a=i.components;if(!Array.isArray(a)||!a.length)r.push({path:`${s}/components`,message:"components is a non-empty array"});else{const l=new Set;a.forEach((c,u)=>{!Ie(c)||typeof c.id!="string"||typeof c.component!="string"?r.push({path:`${s}/components/${u}`,message:"a component needs an id and a component"}):l.has(c.id)?r.push({path:`${s}/components/${u}/id`,message:`duplicate id ${c.id}`}):l.add(c.id)}),l.has("root")||r.push({path:`${s}/components`,message:"no component has the id root"})}i.bindings!==void 0&&(Array.isArray(i.bindings)?i.bindings.forEach((l,c)=>{const u=`${s}/bindings/${c}`;(!Ie(l)||typeof l.path!="string"||!zA.test(l.path))&&r.push({path:`${u}/path`,message:"path is a JSON pointer"}),(!Ie(l)||typeof l.source!="string"||!Qt(l.source))&&r.push({path:`${u}/source`,message:"source is a scheme:name URI"})}):r.push({path:`${s}/bindings`,message:"bindings is an array"}))}if(e.functions!==void 0&&(!Array.isArray(e.functions)||e.functions.some(o=>typeof o!="string"||!o))&&r.push({path:"/functions",message:"functions is a list of names or prefix* patterns"}),e.records!==void 0)if(!Ie(e.records))r.push({path:"/records",message:"records is an object of kinds"});else for(const o of Object.keys(e.records).sort()){const i=e.records[o],s=`/records/${o}`;Ic.test(o)||r.push({path:s,message:"a kind is lowercase letters, digits and underscores"}),Ie(i)?(r.push(...Bg(i.schema,`${s}/schema`)),i.policy!==void 0&&r.push(...yS(i.policy,`${s}/policy`)),r.push(...RC(i,s)),r.push(...mS(i,s,e.records)),r.push(...AS(i,s,o))):r.push({path:s,message:"a kind is {schema, title?, policy?}"})}if(e.sources!==void 0&&(!Array.isArray(e.sources)||e.sources.some(o=>typeof o!="string"||!o)))r.push({path:"/sources",message:"sources is a list of scheme:name sources or prefix* patterns"});else if(Array.isArray(e.sources)&&Ie(e.templates))for(const[o,i]of Object.entries(e.templates))!Ie(i)||!Array.isArray(i.bindings)||i.bindings.forEach((s,a)=>{Ie(s)&&typeof s.source=="string"&&Qt(s.source)&&!nl(e.sources,s.source)&&r.push({path:`/templates/${o}/bindings/${a}/source`,message:`source ${s.source} is not in the package's sources`})});if(r.push(...FS(e)),Ie(e.templates))for(const[o,i]of Object.entries(e.templates))!Ie(i)||!Array.isArray(i.bindings)||i.bindings.forEach((s,a)=>{const l=Ie(s)&&typeof s.source=="string"?Qt(s.source):null;l?.scheme===Hr&&(!Ie(e.records)||!Object.prototype.hasOwnProperty.call(e.records,l.name))&&r.push({path:`/templates/${o}/bindings/${a}/source`,message:`records:${l.name} names no declared kind`})});if(e.queries!==void 0)if(!Ie(e.queries))r.push({path:"/queries",message:"queries is an object of named queries"});else for(const o of Object.keys(e.queries).sort()){const i=`/queries/${o}`;RA.test(o)||r.push({path:i,message:"a query name is a letter, then letters, digits and underscores"});const s=e.queries[o];for(const l of Xu(s).issues)r.push({path:`${i}${l.path}`,message:l.message});const a=Ie(s)&&typeof s.from=="string"?s.from.trim():"";a&&!a.includes("${")&&(!Ie(e.records)||!Object.prototype.hasOwnProperty.call(e.records,a))?r.push({path:`${i}/from`,message:`records:${a} names no declared kind`}):a&&!a.includes("${")&&Ie(s)&&r.push(...LA(s,a,e.records[a],i)),a&&Ie(s)&&Array.isArray(s.expand)&&Ie(e.records)&&Ie(e.records[a])&&s.expand.forEach((l,c)=>{const u=e.records[a].refs??{};typeof l=="string"&&l.trim()&&!(Ie(u)&&Object.prototype.hasOwnProperty.call(u,l.trim()))&&r.push({path:`${i}/expand/${c}`,message:`${l.trim()} is not a ref of ${a}`})})}if(Array.isArray(e.exposes)&&e.exposes.forEach((o,i)=>{const s=Ie(o)&&Ie(o.run)&&Ie(o.run.records)?o.run.records:null;if(!s||typeof s.query!="string")return;const a=`/exposes/${i}/run/records/query`,l=Ie(e.queries)&&Object.prototype.hasOwnProperty.call(e.queries,s.query)?e.queries[s.query]:void 0;if(l===void 0)return void r.push({path:a,message:`query ${s.query} names no package query`});const c=Ie(l)&&typeof l.from=="string"?l.from.trim():"";c&&!c.includes("${")&&typeof s.kind=="string"&&c!==s.kind&&r.push({path:a,message:`query ${s.query} reads records:${c}, the tool's kind is ${s.kind}`})}),Ie(e.templates))for(const[o,i]of Object.entries(e.templates))!Ie(i)||!Array.isArray(i.bindings)||i.bindings.forEach((s,a)=>{const l=Ie(s)&&typeof s.source=="string"?Qt(s.source):null,c=l?.params.query;!l||c===void 0||l.scheme!==Hr||(!Ie(e.queries)||!Object.prototype.hasOwnProperty.call(e.queries,c))&&r.push({path:`/templates/${o}/bindings/${a}/source`,message:`query ${c} names no package query`})});return r.push(...HA(e)),r.push(...TA(e,t,(n??[]).flatMap(o=>o.def?[o.def]:[]))),r.push(...HC(e)),r.push(...lA(e)),r.push(...iA(e)),r.push(...XC(e)),r.push(...PA(e)),e.tools!==void 0&&r.push(...$C(e.tools)),e.upstreams!==void 0&&r.push(...IC(e.upstreams)),e.exposes!==void 0&&r.push(...DC(e.exposes,e.records,e.upstreams)),e.extensions!==void 0&&r.push(...jA(e.extensions,t,n)),r.push(...vy(e)),r.length===0&&r.push(...vA(e)),r}function LA(e,t,n,r){const{query:o}=Xu(e,t),i=ly(n),s=p=>Object.prototype.hasOwnProperty.call(i,p),a=new Set(["count",...o.aggregate.map(p=>p.name),...o.group.map(p=>p.field)]),l=[],c=new Set,u=(p,h,f)=>{s(h)||f||c.has(`${p}\0${h}`)||(c.add(`${p}\0${h}`),l.push({path:`${r}/${p}`,message:`${h} is no field of records:${t}`}))},d=(p,h,f)=>{const y=s(f)?Pt(i[f]):"dyn";y!=="number"&&y!=="dyn"&&l.push({path:`${r}/${p}`,message:`${h} reads a number: ${f} is ${typeof y=="string"?y:Array.isArray(y)?"list":"map"}`})};for(const p of o.where)u("where",p.field);for(const p of o.or)for(const h of p)u("or",h.field);o.group.forEach((p,h)=>u(Array.isArray(e.group)?`group/${h}`:"group",p.field));for(const p of o.aggregate)p.field!==null&&(u(`aggregate/${p.name}`,p.field),(p.op==="sum"||p.op==="avg")&&s(p.field)&&d(`aggregate/${p.name}`,p.op,p.field));o.sum!==null&&(u("sum",o.sum),s(o.sum)&&d("sum","sum",o.sum)),o.month&&u("month",o.month.field),o.before&&u("before",o.before.field),o.sort.forEach((p,h)=>u(Array.isArray(e.sort)?`sort/${h}`:"sort",p.field,a.has(p.field)));for(const p of o.running)u(`running/${p.field}`,p.field,a.has(p.field));return l}function jA(e,t,n){if(!Array.isArray(e))return[{path:"/extensions",message:"extensions is a list of {id, version, components?}"}];const r=[],o=new Set;return e.forEach((i,s)=>{const a=`/extensions/${s}`;if(!Ie(i))return void r.push({path:a,message:"an extension is {id, version, components?}"});const l=typeof i.id=="string"&&i.id?i.id:null;l||r.push({path:`${a}/id`,message:"id is a required string"});const c=typeof i.version=="string"&&Vc.test(i.version)?i.version:null;c||r.push({path:`${a}/version`,message:"version is MAJOR.MINOR.PATCH"});const u=i.components===void 0?[]:Array.isArray(i.components)&&i.components.every(p=>typeof p=="string"&&p)?i.components:null;if(u||r.push({path:`${a}/components`,message:"components is a list of component names"}),!l)return;if(o.has(l))return void r.push({path:`${a}/id`,message:`duplicate extension ${l}`});o.add(l);const d=n?.find(p=>p.id===l);if(!t.includes(l)||n&&!d)return void r.push({path:`${a}/id`,message:`extension ${l} is not available on this host`});d&&(c&&d.version!==void 0&&!FA(d.version,c)&&r.push({path:`${a}/version`,message:`extension ${l} ${d.version} does not satisfy ^${c}`}),d.components&&(u??[]).forEach((p,h)=>{d.components.includes(p)||r.push({path:`${a}/components/${h}`,message:`extension ${l} has no component ${p}`})}))}),r}function nl(e,t){if(e===void 0)return!0;const n=Qt(t);if(!n)return!1;const r=`${n.scheme}:${n.name}`;return e.some(o=>ma(o,r)||ma(o,t))}function BA(e,t,n,r,o={}){const i=e.templates[t];if(!i)return null;const s=ky(i.components)?{...i,...wy(i.components,i.bindings??[],e.records,o)}:i,a=$u,l=[{version:a,createSurface:{surfaceId:n,catalogId:e.catalogId}},{version:a,updateComponents:{surfaceId:n,components:s.components}}],c=WA(s.data,r);c!==void 0&&l.push({version:a,updateDataModel:{surfaceId:n,path:"/",value:c}});const u=Ie(c)?c.params:void 0;for(const d of s.bindings??[])l.push({version:a,bindDataModel:{surfaceId:n,path:d.path,source:nA(d.source,u)}});return l}function WA(e,t){return t===void 0?e:Ie(e)&&Ie(t)?{...e,...t}:t}function HA(e){const t=[];if(!Ie(e.templates))return t;const n=Array.isArray(e.functions)?e.functions.filter(o=>typeof o=="string"):[],r=o=>n.some(i=>ma(i,o));for(const[o,i]of Object.entries(e.templates))!Ie(i)||!Array.isArray(i.components)||i.components.forEach((s,a)=>{if(!Ie(s)||s.component!=="RecordForm"&&s.component!=="RecordTable")return;const l=`/templates/${o}/components/${a}`,c=s.component==="RecordForm"?s.readOnly!==!0:s.editable!==!1;c&&!r("records.upsert")&&t.push({path:l,message:`${s.component} writes with records.upsert: list it in functions`}),s.component==="RecordTable"&&c&&!r("records.delete")&&t.push({path:l,message:"RecordTable deletes with records.delete: list it in functions"}),s.component==="RecordTable"&&typeof s.kind=="string"&&Array.isArray(e.sources)&&!nl(e.sources,`records:${s.kind}`)&&t.push({path:l,message:`RecordTable reads records:${s.kind}: list it in sources`})});return t}const Ls=e=>!!e&&typeof e=="object"&&!Array.isArray(e);class qA{extensionIds;surfaces=new Map;packages=new Map;extensions;constructor(t={}){this.extensionIds=[...t.extensionIds??[]],this.extensions=t.extensions?[...t.extensions]:void 0}get supportedCatalogIds(){return rd(this.extensionIds)}registerExtension(t,n){this.extensionIds.includes(t)||this.extensionIds.push(t),this.extensions&&!this.extensions.some(r=>r.id===t)&&this.extensions.push(n??{id:t})}installPackage(t){const n=NA(t,this.supportedCatalogIds,this.extensions);return n.length||this.packages.set(t.id,t),n}package(t){return this.packages.get(t)}surface(t){return this.surfaces.get(t)}surfaceIds(){return[...this.surfaces.keys()]}route(t){if(UA(t))return[this.invalid(Ls(t)?jl(t):"",$n.messageBytes)];if(!Ls(t))return[this.invalid("","a message is a JSON object")];if(t.version!==void 0&&t.version!==$u)return[this.invalid(jl(t),`unsupported version ${String(t.version)}`)];const n=Object.keys(t).filter(s=>s!=="version");if(n.length!==1||!Mp.includes(n[0]))return[this.invalid(jl(t),`expected exactly one of ${Mp.join(", ")}`)];const r=n[0],o=t[r];if(!Ls(o)||typeof o.surfaceId!="string"||!o.surfaceId)return[this.invalid("",`${r}.surfaceId is required`)];const i=o.surfaceId;switch(r){case"createSurface":{if(typeof o.catalogId!="string")return[this.invalid(i,"createSurface.catalogId is required")];if(!this.supportedCatalogIds.includes(o.catalogId))return[{op:"send",message:Ft("UNSUPPORTED_CATALOG",i,`catalog ${o.catalogId} is not supported`)}];this.surfaces.set(i,{surfaceId:i,catalogId:o.catalogId});const s={op:"create",surfaceId:i,catalogId:o.catalogId};return o.theme!==void 0&&(s.theme=o.theme),o.sendDataModel===!0&&(s.sendDataModel=!0),[s]}case"updateComponents":return Array.isArray(o.components)?this.surfaces.has(i)?[{op:"components",surfaceId:i,components:o.components}]:[this.missing(i)]:[this.invalid(i,"updateComponents.components is required")];case"updateDataModel":{if(!this.surfaces.has(i))return[this.missing(i)];if(o.path!==void 0&&typeof o.path!="string")return[this.invalid(i,"updateDataModel.path is a string")];const s=Bl(o.path);return["value"in o?{op:"data",surfaceId:i,path:s,value:o.value}:{op:"data",surfaceId:i,path:s}]}case"deleteSurface":return this.surfaces.has(i)?(this.surfaces.delete(i),[{op:"delete",surfaceId:i}]):[this.missing(i)];case"bindDataModel":{const s=this.surfaces.get(i);if(!s)return[this.missing(i)];if(typeof o.path!="string"||typeof o.source!="string"||!Qt(o.source))return[this.invalid(i,"bindDataModel needs a path and a scheme:name source")];const a=s.packageId?this.packages.get(s.packageId):void 0;return a&&!nl(a.sources,o.source)?[{op:"send",message:Ft("SOURCE_DENIED",i,`source ${o.source} is not in package ${a.id}'s sources`,Bl(o.path)||"/")}]:[{op:"bind",surfaceId:i,path:Bl(o.path),source:a?Zu(o.source,a.queries):o.source}]}case"applyTemplate":{if(typeof o.templateId!="string")return[this.invalid(i,"applyTemplate.templateId is required")];const s=this.findPackage(o.templateId,typeof o.packageId=="string"?o.packageId:void 0);if(!s)return[{op:"send",message:Ft("TEMPLATE_NOT_FOUND",i,`no installed package has the template ${o.templateId}`)}];const a=[];for(const l of BA(s,o.templateId,i,o.data)??[]){a.push(...this.route(l));const c=this.surfaces.get(i);c&&(c.packageId=s.id)}return a}}return[this.invalid(i,"unknown message")]}findPackage(t,n){if(n!==void 0){const r=this.packages.get(n);return r&&r.templates[t]?r:void 0}for(const r of this.packages.values())if(r.templates[t])return r}invalid(t,n){return{op:"send",message:Ft("INVALID_MESSAGE",t,n)}}missing(t){return{op:"send",message:Ft("SURFACE_NOT_FOUND",t,`no surface ${t}; send createSurface first`)}}}function UA(e){let t;try{t=JSON.stringify(e)}catch{return!1}return t===void 0||t.length*3<=Rr?!1:t.length>Rr||new TextEncoder().encode(t).length>Rr}function jl(e){for(const t of Object.values(e))if(Ls(t)&&typeof t.surfaceId=="string")return t.surfaceId;return""}function Bl(e){return e===void 0||e==="/"?"":e}class VA extends Error{constructor(t,n){super(`exponential-ui: package ${t} is unusable: ${n.map(r=>`${r.path||"/"} ${r.message}`).join("; ")}`),this.packageId=t,this.issues=n,this.name="PackageError"}packageId;issues}const mf=100;function KA(e){if(typeof e=="string")return Pi.includes(e)?{theme:wo(e),issues:[]}:{theme:null,issues:[`unknown built-in theme "${e}"; known: ${Pi.join("|")}`]};const{theme:t,issues:n}=Ku(e,{themes:Ii});return{theme:t,issues:n.map(r=>r.path?`${r.path}: ${r.message}`:r.message)}}class GA{constructor(t,n,r){this.extensions=r,this.surfaceId=t,this.catalogId=n}extensions;surfaceId;catalogId;packageId;sendDataModel=!1;list=[];shared=!1;positions=new Map;data={};theme;reduced=null;listeners=new Set;version=0;get components(){return this.shared=!0,this.list}component(t){const n=this.positions.get(t);return n===void 0?void 0:this.list[n]}get root(){return this.reduce().root}get issues(){return this.reduce().issues}get templates(){return this.reduce().templates}reduce(){return this.reduced||(this.reduced=this.list.length?Uu(this.list,{catalogId:this.catalogId,extensions:this.extensions()}):{root:null,issues:[]}),this.reduced}setComponents(t){this.shared&&(this.list=this.list.slice(),this.shared=!1);for(const n of t){const r=this.positions.get(n.id);r===void 0?(this.positions.set(n.id,this.list.length),this.list.push(n)):this.list[r]=n}this.reduced=null,this.notify()}invalidate(){this.reduced=null,this.notify()}setData(t,n){const r=Pu(this.data,t,n);if(r.error)return r.error;this.data=r.data,this.notify()}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}notify(){this.version+=1;for(const t of[...this.listeners])t()}}class YA{constructor(t={}){this.options=t,this.extensions=[...t.extensions??[]],this.router=new qA({extensionIds:this.extensions.map(n=>n.id),extensions:hf(this.extensions)}),this.functions={...t.functions??{}},this.sources={...t.sources??{}};for(const n of t.packages??[]){const r=this.installPackage(n);if(r.length)throw new VA(typeof n?.id=="string"&&n.id?n.id:"?",r)}}options;router;stores=new Map;subscriptions=new Map;paintErrors=new Map;listeners=new Set;functions;sources;extensions;status="closed";statusDetail;unsupportedCatalog;issues=[];get hasTransport(){return this.options.transport!==void 0}get supportedCatalogIds(){return this.router.supportedCatalogIds}clientCapabilities(){return DA(this.extensions.map(t=>t.id))}get extensionDefs(){return this.extensions}registerExtension(t){if(!this.extensions.some(n=>n.id===t.id)){this.extensions.push(t),this.router.registerExtension(t.id,hf([t])[0]);for(const n of this.stores.values())n.invalidate()}}registerFunction(t,n){this.functions[t]=n}registerSource(t,n){this.sources[t.toLowerCase()]=n}installPackage(t){const n=this.router.installPackage(t),r=typeof t?.id=="string"?t.id:void 0;for(const o of n)this.report({code:"PACKAGE_INVALID",message:o.message,path:o.path,...r?{packageId:r}:{}});return n}report(t){const n=[...this.issues,t];this.issues=n.length>mf?n.slice(n.length-mf):n,this.options.onIssue?.(t),this.notify()}surface(t){return this.stores.get(t)}surfaceIds(){return[...this.stores.keys()]}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}notify(){for(const t of[...this.listeners])t()}connect(){const t=this.options.transport;t&&t.start(n=>this.receive(n),(n,r)=>{this.status=n,this.statusDetail=r,this.notify()})}close(){this.options.transport?.close();for(const t of this.surfaceIds())this.perform({op:"delete",surfaceId:t})}receive(t){const n=this.router.route(t);for(const r of n)this.perform(r);return n}send(t){if(this.options.transport?.send(t),this.options.onSend?.(t),"error"in t){const n=t.error;this.report({code:n.code,message:n.message,...n.surfaceId?{surfaceId:n.surfaceId}:{},...n.path!==void 0?{path:n.path}:{}})}}perform(t){switch(this.options.onOp?.(t),t.op){case"create":{this.unbind(t.surfaceId),this.forgetPaintErrors(t.surfaceId);const n=new GA(t.surfaceId,t.catalogId,()=>this.extensions);if(n.sendDataModel=t.sendDataModel===!0,n.packageId=this.router.surface(t.surfaceId)?.packageId,t.theme!==void 0&&t.theme!==null){const{theme:r,issues:o}=KA(t.theme);r?n.theme=r:this.send(Ft("VALIDATION_FAILED",t.surfaceId,`createSurface.theme is unusable: ${o.join("; ")}`,"/createSurface/theme"))}this.stores.set(t.surfaceId,n),this.notify();return}case"components":{const n=this.paintErrors.get(t.surfaceId);if(n)for(const r of t.components)n.delete(r.id);this.stores.get(t.surfaceId)?.setComponents(t.components);return}case"data":{const n=this.stores.get(t.surfaceId)?.setData(t.path,t.value);n&&this.send(Ft("VALIDATION_FAILED",t.surfaceId,n,t.path||"/"));return}case"bind":{const n=this.stores.get(t.surfaceId),r=Qt(t.source),o=r?this.sources[r.scheme]:void 0;if(!n||!r)return;if(!o){this.send(Ft("VALIDATION_FAILED",t.surfaceId,`no resolver for the source scheme ${r.scheme}`,t.path||"/"));return}const i=this.subscriptions.get(t.surfaceId)??[];for(const l of i)l.path===t.path&&l.cancel();const s=i.filter(l=>l.path!==t.path),a=o(r,l=>this.stores.get(t.surfaceId)?.setData(t.path,l));this.subscriptions.set(t.surfaceId,a?[...s,{path:t.path,cancel:a}]:s);return}case"delete":this.unbind(t.surfaceId),this.forgetPaintErrors(t.surfaceId),this.stores.delete(t.surfaceId),this.notify();return;case"send":{const n="error"in t.message?t.message.error:void 0;n?.code==="UNSUPPORTED_CATALOG"&&(this.unsupportedCatalog=n.message.replace(/^catalog (\S+).*$/,"$1"),this.notify()),this.send(t.message);return}}}unbind(t){for(const n of this.subscriptions.get(t)??[])n.cancel();this.subscriptions.delete(t)}action(t){const n=V2({name:t.name,surfaceId:t.surfaceId,sourceComponentId:t.componentId,timestamp:t.timestamp??new Date().toISOString(),context:t.context??{},payload:t.payload});return this.send(n),n}decide(t,n){const r=Object.prototype.hasOwnProperty.call(this.functions,n);let o=Ep(this.options.policy?.functions,n,r);const i=this.stores.get(t)?.packageId,s=i?this.router.package(i):void 0;return s&&(o=G2(o,Ep(Y2(s.functions),n,r))),o}async callFunction(t){if(t.name==="openUrl"){const o=typeof t.args.url=="string"?t.args.url:"";return{decision:this.openUrl(o)?"allow":"deny"}}if(t.name==="bind")return{decision:this.bind(t.surfaceId,t.args)?"allow":"deny"};if(t.name===So)return this.navigate(t);const n=tl(t.name);if(n!==null)return this.runPackageAction(t,n);const r=await this.gate(t);return r.decision!=="allow"?r:this.run(t)}async gate(t){if(t.name===So)return{decision:"allow"};let n=this.decide(t.surfaceId,t.name);if(n==="not_found")return this.send(Ft("FUNCTION_NOT_FOUND",t.surfaceId,`no function ${t.name}`)),{decision:n};let r;if(n==="ask"){let o=!1;try{o=await this.options.policy?.onFunctionCall?.(t)===!0}catch(i){r=i instanceof Error?i.message:String(i)}o||(n="deny")}return n==="deny"?(this.send(Ft("FUNCTION_DENIED",t.surfaceId,r===void 0?`${t.name} was not allowed`:`${t.name} was not allowed: the consent hook failed: ${r}`)),r===void 0?{decision:n}:{decision:n,error:r}):{decision:"allow"}}async run(t){if(t.name===So)return this.navigate(t);const n=Object.prototype.hasOwnProperty.call(this.functions,t.name)?this.functions[t.name]:void 0;if(!n)return{decision:"allow"};try{return{decision:"allow",result:await n(t.args,t)}}catch(r){return{decision:"allow",error:r instanceof Error?r.message:String(r)}}}async runPackageAction(t,n){const r=this.stores.get(t.surfaceId),o=r?.packageId?this.router.package(r.packageId):void 0,i=u=>(this.send(Ft("ACTION_FAILED",t.surfaceId,u)),this.options.onActionFailed?.({surfaceId:t.surfaceId,action:n,message:u}),{decision:"allow",error:u});if(!r||!o)return i(`no action ${n}`);const s=yy(o,n,t.args,{data:r.data,me:this.options.me??null,now:this.options.now?.(),offset:this.options.zone});if("error"in s)return i(s.error);const a=s.plan,l=a.calls.map(u=>({surfaceId:t.surfaceId,componentId:t.componentId,name:u.name,args:u.args}));for(const u of l){const d=await this.gate(u);if(d.decision!=="allow")return i(d.error??`${u.name} was not allowed`)}let c={ids:[]};if(a.writes.length){const u=Object.prototype.hasOwnProperty.call(this.functions,Nl)?this.functions[Nl]:void 0;if(!u)return i("this host keeps no records");try{c=await u({writes:a.writes},{...t,name:Nl,args:{writes:a.writes}})}catch(d){return i(d instanceof Error?d.message:String(d))}}for(const u of a.sets){const d=r.setData(u.path,u.value);d&&this.send(Ft("VALIDATION_FAILED",t.surfaceId,d,u.path||"/"))}for(const u of l){const d=await this.run(u);if(d.error!==void 0)return{decision:"allow",result:c,error:d.error}}return{decision:"allow",result:c}}navigate(t){const n=this.stores.get(t.surfaceId),r=n?.packageId?this.router.package(n.packageId):void 0,o=r?tA(r,t.args):{error:"navigate: the surface has no package"},i=a=>(this.send(Ft("FUNCTION_DENIED",t.surfaceId,a)),{decision:"deny",error:a});return"error"in o?i(o.error):this.options.navigate?this.options.navigate({surfaceId:t.surfaceId,packageId:r.id,screen:o.screen,params:o.params})===!1?i(`navigate: ${o.screen} was not opened`):{decision:"allow"}:i("navigate: this host has no screens")}bind(t,n){const r=typeof n.path=="string"?n.path:"",o=typeof n.source=="string"?n.source:"";if(!o||!this.stores.has(t))return!1;const i=n.params&&typeof n.params=="object"&&!Array.isArray(n.params)?n.params:void 0;return this.receive({version:$u,bindDataModel:{surfaceId:t,path:r,source:Gu(o,i)}}).some(a=>a.op==="bind")}urlPolicy(){return{baseUrl:this.options.policy?.media?.baseUrl,...this.options.policy?.urls}}openUrl(t){const n=rs(this.urlPolicy(),t);return!n.allowed||!n.url?!1:((this.options.policy?.openUrl??(o=>globalThis.window?.open(o,"_blank","noopener")))(n.url),!0)}textLinks(t){return this.options.policy?.textLinks?.(t)??null}paintError(t){const n=this.stores.get(t.surfaceId);let r=t.componentId;for(;n&&!n.component(r)&&r.includes(".");)r=r.slice(0,r.lastIndexOf("."));const o=n?.component(r);let i=this.paintErrors.get(t.surfaceId);i||this.paintErrors.set(t.surfaceId,i=new Map);let s=i.get(r);(!s||s.component!==o)&&i.set(r,s={component:o,ids:new Set}),!s.ids.has(t.componentId)&&(s.ids.add(t.componentId),this.send(Ft(q2,t.surfaceId,t.message,`/components/${t.componentId}`)))}forgetPaintErrors(t){this.paintErrors.delete(t)}mediaOptions(){return this.options.policy?.media}mediaRequest(t){return Dg(t,this.options.policy?.media)}}class Cy{constructor(t){this.options=t}options;controller;generation=0;start(t,n){this.controller?.abort();const r=++this.generation;this.run(r,t,n)}async run(t,n,r){const o=this.options.fetch??fetch,i=()=>t===this.generation;for(;i();){const s=new AbortController;this.controller=s,r("connecting");let a=this.options.reconnectMs??2e3;try{const l=await o(this.options.url,{headers:{accept:this.accept(),...this.options.headers},signal:s.signal});if(!i())return;if(!l.ok||!l.body)throw new Error(`HTTP ${l.status}`);r("open");const c=l.body.getReader(),u=new TextDecoder,d=this.decoder();for(;;){const{done:h,value:f}=await c.read();if(!i())return;if(h)break;d.push(u.decode(f,{stream:!0})).messages.forEach(n)}if(d.end().messages.forEach(n),r("closed"),!(this.options.resumable===!0||d.retryMs!==void 0)){i()&&(this.generation+=1);return}d.retryMs!==void 0&&this.options.reconnectMs===void 0&&(a=d.retryMs)}catch(l){if(!i())return;r("error",l instanceof Error?l.message:String(l))}if(!a||!i())return;await new Promise(l=>setTimeout(l,a))}}async send(t){await(this.options.fetch??fetch)(this.options.postUrl??this.options.url,{method:"POST",headers:{"content-type":"application/json",...this.options.headers},body:JSON.stringify(t)})}close(){this.generation+=1,this.controller?.abort()}}class XA extends Cy{decoder(){return new Lg}accept(){return"application/jsonl, application/x-ndjson"}}class ZA extends Cy{decoder(){return new cS}accept(){return"text/event-stream"}}class JA{constructor(t){this.options=t}options;socket;generation=0;start(t,n){const r=++this.generation,o=()=>r===this.generation,i=this.options.WebSocket??WebSocket;n("connecting");const s=new i(this.options.url,this.options.protocols);this.socket=s,s.onopen=()=>o()&&n("open"),s.onmessage=a=>{o()&&typeof a.data=="string"&&jg(a.data).messages.forEach(t)},s.onerror=()=>o()&&n("error","websocket error"),s.onclose=()=>{if(!o())return;n("closed");const a=this.options.reconnectMs??2e3;a&&setTimeout(()=>o()&&this.start(t,n),a)}}send(t){this.socket?.readyState===1&&this.socket.send(JSON.stringify(t))}close(){this.generation+=1,this.socket?.close()}}const QA="@layer xui-base, xui-recipe, xui-node, xui-part, xui-author;",e_=new Set(["flexGrow","flexShrink","opacity","fontWeight","aspectRatio","zIndex"]),Ay=e=>e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`);function t_(e){const t=nr(e);if(!t)return null;const{group:n,name:r}=t;return n==="type.family"?`--xui-font-${r}`:`--xui-${n.replace(/\./g,"-")}-${r}`}function Vr(e){const t=t_(e);return t?`var(${t})`:null}function n_(e){return`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`}const r_=new Set(["serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong"]);function _y(e,t){const n=t[e]?.fallback,r=r_.has(e)?e:n_(e);return n?`${r}, ${n}`:r}function js(e,t,n={}){if(t==null||typeof t=="boolean")return null;if(typeof t=="string"&&t.startsWith("var(--xd-"))return t;if(typeof t=="string"&&t.startsWith("$")){const r=Vr(t);if(r)return r}return e==="boxShadow"?Array.isArray(t)?Og(t):String(t):e==="fontFamily"?_y(String(t),n):e==="gridTemplateAreas"&&Array.isArray(t)?t.map(r=>`"${r}"`).join(" "):e==="backgroundGradient"?o_(t):e==="transitionEasing"?Array.isArray(t)?Tg(t):String(t):e==="transition"?typeof t=="number"?`${t}ms`:String(t):typeof t=="object"?null:typeof t=="number"?e_.has(e)?String(t):`${t}px`:(e==="overflow"||e==="overflowX"||e==="overflowY")&&t==="hidden"?"clip":String(t)}function o_(e){if(typeof e!="object"||e===null)return null;const t=e;if(!Array.isArray(t.stops)||t.stops.length<2)return null;const n=t.stops.map(r=>`${typeof r.color=="string"&&r.color.startsWith("$")?Vr(r.color)??r.color:String(r.color)} ${Math.round(Number(r.offset??0)*1e4)/100}%`);return`linear-gradient(${Number(t.angle??180)}deg, ${n.join(", ")})`}const i_={paddingHorizontal:["padding-left","padding-right"],paddingVertical:["padding-top","padding-bottom"],marginHorizontal:["margin-left","margin-right"],marginVertical:["margin-top","margin-bottom"],backgroundGradient:["background-image"],transition:["transition-property:all","transition-duration"],transitionEasing:["transition-timing-function"]},s_=["borderWidth","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth"];function Bs(e,t={},n){const r=[],o="animation"in e?e.animation:n?.animation,i=typeof o=="string"&&h1(o)&&("animation"in e||"opacity"in e);for(const[s,a]of Object.entries(e)){if(s==="native"||s.startsWith("@")||s.startsWith(":")||typeof a=="object"&&a!==null&&!Array.isArray(a)&&s!=="backgroundGradient")continue;if(s==="backdropBlur"){const c=js(s,a,t);c&&r.push(["-webkit-backdrop-filter",`blur(${c})`],["backdrop-filter",`blur(${c})`]);continue}if(s==="animation"){r.push(...a_(a,e.animationDuration));continue}if(s==="animationDuration"){const c=typeof a=="string"?Vr(a):null;c&&!("animation"in e)&&r.push(["animation-duration",`calc(${c} * var(--xui-anim-factor, 1))`]);continue}s==="position"&&a==="sticky"&&r.push(["z-index","1"]);const l=js(s,a,t);if(l!==null)for(const c of i_[s]??[Ay(s)]){const u=c.indexOf(":");u>0?r.push([c.slice(0,u),c.slice(u+1)]):r.push([c,l])}}if(i){const s=r.findIndex(([u])=>u==="opacity"),a="opacity"in e?e:n&&"opacity"in n?n:null,l=s>=0?r[s][1]:a?js("opacity",a.opacity,t):null,c=l===null?"var(--xui-a-opacity, 1)":`calc(${l} * var(--xui-a-opacity, 1))`;s>=0?r[s]=["opacity",c]:r.push(["opacity",c])}return!("borderStyle"in e)&&s_.some(s=>s in e)&&r.push(["border-style","solid"]),r}function a_(e,t){const n=typeof e=="string"?ts[e]:void 0;if(!n)return[["animation-name","none"]];const r=typeof t=="string"&&nr(t)?.group==="motion"?t:n.duration,o=n.easing==="linear"?"linear":Vr(n.easing)??"linear";return[["--xui-anim-factor",String(n.factor)],["animation-name",`xui-${e}`],["animation-duration",`calc(${Vr(r)??"0ms"} * ${n.factor})`],["animation-timing-function",o],["animation-iteration-count",n.iterations==="infinite"?"infinite":String(n.iterations)],["animation-fill-mode","both"]]}function Ws(e,t){if(t.animation!=="shimmer")return"";const n=ts.shimmer?.band,r=(n&&Vr(n.color))??"var(--xui-color-background)",o=(n?.stops??[{offset:0,alpha:0},{offset:.5,alpha:.5},{offset:1,alpha:0}]).map(s=>`color-mix(in srgb, ${r} ${Math.round(s.alpha*100)}%, transparent) calc(var(--xui-band, 1) * 100% + ${Math.round(s.offset*100)}%)`);return`${e.split(",").map(s=>`${s}::after`).join(",")}{content:"";position:absolute;inset:0;pointer-events:none;border-radius:inherit;background-image:linear-gradient(90deg, ${o.join(", ")})}`}const _r=(e,t)=>t.length===0?"":`${e}{${t.map(([n,r])=>`${n}:${r}`).join(";")}}`,l_={hover:[":hover",'[data-xs~="hover"]'],pressed:[":active",'[data-xs~="pressed"]'],focus:[":focus-visible:not([data-xui-quiet-focus])",'[data-xs~="focus"]'],disabled:[":disabled","[data-disabled]",'[aria-disabled="true"]','[data-xs~="disabled"]'],checked:['[data-state="checked"]','[data-xs~="checked"]'],open:['[data-state="open"]','[data-xs~="open"]'],selected:['[data-state="active"]','[data-state="on"]',"[data-highlighted]",'[data-xs~="selected"]'],invalid:['[aria-invalid="true"]','[data-xs~="invalid"]'],dragover:["[data-dragover]",'[data-xs~="dragover"]']};function c_(e){let t=[""];for(const n of e){const r=l_[n]??[`[data-xs~="${n}"]`];t=t.flatMap(o=>r.map(i=>o+i))}return t}const Ni=(e,t)=>`data-${e?"m":"r"}-${Ay(t)}`;function u_(e,t){if(!e)return[""];let n=[""];for(const[r,o]of Object.entries(e)){if(r==="state")continue;const i=Array.isArray(o)?o:[o];n=n.flatMap(s=>i.map(a=>`${s}[${Ni(t,r)}="${String(a)}"]`))}return n}function d_(e,t,n=!1){const r=t.when?.state===void 0?[]:Array.isArray(t.when.state)?t.when.state.map(String):[String(t.when.state)],o=u_(t.when,n),i=c_(r);return o.flatMap(s=>i.map(a=>`${e}${s}${a}`))}function p_(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function f_(e){return`xui-t-${e.id.replace(/[^a-z0-9-]/gi,"-")}-${p_(JSON.stringify(e))}`}const h_=[["--background","background"],["--foreground","foreground"],["--card","card"],["--card-foreground","cardForeground"],["--popover","popover"],["--popover-foreground","popoverForeground"],["--primary","primary"],["--primary-foreground","primaryForeground"],["--secondary","secondary"],["--secondary-foreground","secondaryForeground"],["--muted","muted"],["--muted-foreground","mutedForeground"],["--accent","accent"],["--accent-foreground","accentForeground"],["--destructive","destructive"],["--destructive-foreground","destructiveForeground"],["--success","success"],["--success-foreground","successForeground"],["--warning","warning"],["--warning-foreground","warningForeground"],["--info","info"],["--info-foreground","infoForeground"],["--border","border"],["--input","input"],["--ring","ring"],["--chart-1","chart1"],["--chart-2","chart2"],["--chart-3","chart3"],["--chart-4","chart4"],["--chart-5","chart5"],["--chart-6","chart6"],["--chart-7","chart7"],["--chart-8","chart8"],["--sidebar","background"],["--sidebar-foreground","foreground"],["--sidebar-primary","primary"],["--sidebar-primary-foreground","primaryForeground"],["--sidebar-accent","accent"],["--sidebar-accent-foreground","accentForeground"],["--sidebar-border","border"],["--sidebar-ring","ring"],["--glass-fill-section","muted"],["--glass-fill-row","muted"],["--glass-fill-card","card"],["--glass-fill-panel","popover"],["--glass-fill-active","accent"],["--glass-stroke-row","border"],["--glass-stroke-section","border"],["--glass-stroke-card","border"],["--glass-stroke-strong","input"],["--glass-stroke-active","ring"],["--glass-background-top","background"],["--glass-background-bottom","background"]];function m_(e){const t=[],n=e.tokens;for(const r of["spacing","radius","control","opacity","border","motion"])for(const[o,i]of Object.entries(n[r]??{})){const s=r==="opacity"?"":r==="motion"?"ms":"px";t.push([`--xui-${r}-${o}`,`${i}${s}`])}for(const[r,o]of Object.entries(e.tokens.blur??{}))t.push([`--xui-blur-${r}`,`${o}px`]);for(const[r,o]of Object.entries(e.tokens.scale??{}))t.push([`--xui-scale-${r}`,String(o)]);for(const[r,o]of Object.entries(e.tokens.ease??{}))t.push([`--xui-ease-${r}`,Tg(o)]);for(const[r,o]of Object.entries(e.tokens.breakpoint??{}))t.push([`--xui-breakpoint-${r}`,`${o}px`]);for(const[r,o]of Object.entries(e.tokens.type.size))t.push([`--xui-type-size-${r}`,`${o}px`]);for(const[r,o]of Object.entries(e.tokens.type.lineHeight))t.push([`--xui-type-lineHeight-${r}`,`${o}px`]);for(const[r,o]of Object.entries(e.tokens.type.weight))t.push([`--xui-type-weight-${r}`,String(o)]);for(const[r,o]of Object.entries(e.tokens.type.family))t.push([`--xui-font-${r}`,_y(o,e.fonts)]);return t.push(["--radius","var(--xui-radius-lg)"],["--font-sans","var(--xui-font-sans)"],["--font-mono","var(--xui-font-mono)"]),t.push(["--xui-duration-fast","var(--xui-motion-fast)"],["--xui-duration-standard","var(--xui-motion-standard)"]),t.map(([r,o])=>`${r}:${o}`).join(";")}function gf(e,t){const n=[];for(const[r,o]of Object.entries(e.modes[t].color))n.push([`--xui-color-${r}`,o]);for(const[r,o]of Object.entries(e.modes[t].shadow))n.push([`--xui-shadow-${r}`,Og(o)]);for(const[r,o]of h_)n.push([r,`var(--xui-color-${o})`]);return n.push(["color-scheme",t]),n.map(([r,o])=>`${r}:${o}`).join(";")}const g_=new Set(Object.entries(Lt.components).filter(([,e])=>e.kind==="macro").map(([e])=>e));function Oy(e,t=new Set){return g_.has(e)||t.has(e)}const Kr=(e,t)=>`xui-${e}-${t}`;function yf(e,t={}){const n=f_(e),r=`.xui-surface.${n}`,o=[QA];o.push(`${r}{${m_(e)}}`),o.push(`${r}[data-xui-mode="light"]{${gf(e,"light")}}`),o.push(`${r}[data-xui-mode="dark"]{${gf(e,"dark")}}`);const i=[],s=[];for(const[a,l]of Object.entries(e.recipes)){const c=Oy(a,t.extensionMacros),u=c?s:i;for(const[d,p]of Object.entries(l)){const h=`.${n}.${Kr(a,d)}`;for(const f of p){const y=Bs(f.style,e.fonts);if(y.length===0)continue;const g=d_(h,f,c).join(",");u.push(_r(g,y)+Ws(g,f.style))}}}return o.push(`@layer xui-recipe{${i.join("")}}`),o.push(`@layer xui-part{${s.join("")}}`),{scope:n,css:o.join(`
25
25
  `),theme:e}}const bf=new WeakMap;function y_(e,t){if(t?.extensionMacros&&t.extensionMacros.size>0)return yf(e,t);let n=bf.get(e);return n||(n=yf(e),bf.set(e,n)),n}function os(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.path=="string"&&Object.keys(e).length===1}function od(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e.call=="string"}function Ko(e,t=""){return e.startsWith("/")?e:t?e===""?t:`${t}/${e}`:`/${e}`}const is=Va;function Gr(e,t,n){return Pu(e,t,n).data}const $a="/$xuiRows";function b_(e){return e===void 0||e===$a||e.startsWith(`${$a}/`)?void 0:e}const ti=e=>typeof e=="number"?e:Number(e);function v_(e,t){return e.replace(/\$\{([^}]+)\}/g,(n,r)=>Eo(is(t.data,Ko(r.trim(),t.scope))))}function Ty(e,t=4096){const n=new Map,r=(i,s)=>{const a=n.get(i);if(a!==void 0)return a;const l=s();return n.size>=t&&n.clear(),n.set(i,l),l},o=i=>i instanceof Date?`t${i.getTime()}`:typeof i=="string"?`s${i}`:`${typeof i}${String(i)}`;return{locale:e.locale,number:(i,s)=>r(`n|${i}|${s?.decimals}|${s?.grouping}`,()=>e.number(i,s)),currency:(i,s,a)=>r(`c|${s}|${i}|${a?.decimals}|${a?.grouping}`,()=>e.currency(i,s,a)),percent:(i,s)=>r(`p|${i}|${s?.decimals}`,()=>e.percent(i,s)),date:(i,s)=>r(`d|${s?.format}|${s?.style}|${s?.time}|${o(i)}`,()=>e.date(i,s)),relativeTime:(i,s)=>e.relativeTime(i,s),plural:i=>r(`l|${i}`,()=>e.plural(i)),...e.offsetMinutes?{offsetMinutes:i=>e.offsetMinutes(i)}:{}}}const vf=new Map;function My(e){if(e.formatter)return e.formatter;const t=e.locale??sg;let n=vf.get(t);return n||vf.set(t,n=Ty(vm(t,"UTC"))),n}const $f=new WeakMap;function $_(e){return(t,n)=>{const r=My(n);let o=$f.get(r);return(!o||o.now!==n.now)&&$f.set(r,o={now:n.now,table:xm(r,n.now)}),o.table[e](t)}}const x_=Object.fromEntries($m.map(e=>[e,$_(e)])),w_=Object.fromEntries(Object.entries(X$).map(([e,t])=>[e,n=>t(n)])),k_=Object.fromEntries(_u.map(e=>[e,(t,n)=>{const r=My(n);return Pm(e,t,{...n.now?{now:n.now()}:{},...r.offsetMinutes?{offset:o=>r.offsetMinutes(o)}:{}})?.value}])),Ey={required:({value:e})=>On(e)&&!(Array.isArray(e)&&e.length===0),regex:({value:e,pattern:t})=>{try{return new RegExp(String(t)).test(String(e??""))}catch{return!1}},length:({value:e,min:t,max:n})=>{const r=String(e??"").length;return(t===void 0||r>=ti(t))&&(n===void 0||r<=ti(n))},numeric:({value:e,min:t,max:n})=>{const r=ti(e);return Number.isFinite(r)&&(t===void 0||r>=ti(t))&&(n===void 0||r<=ti(n))},email:({value:e})=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(String(e??"")),formatString:({value:e},t)=>v_(String(e??""),t),openUrl:({url:e},t)=>{typeof e=="string"&&t.openUrl?.(e)},and:({values:e})=>Array.isArray(e)?e.every(On):!1,or:({values:e})=>Array.isArray(e)?e.some(On):!1,not:({value:e})=>!On(e),...w_,...x_,...k_};function vn(e,t){if(os(e))return is(t.data,Ko(e.path,t.scope));if(od(e)){const n=t.functions?.[e.call]??Ey[e.call];if(!n)return;const r={};for(const[o,i]of Object.entries(e.args??{}))r[o]=vn(i,t);return n(r,t)}if(typeof e=="string")return t.strings&&e.startsWith("$string.")?C$(e,t.strings):e;if(Array.isArray(e))return e.map(n=>vn(n,t));if(typeof e=="object"&&e!==null){const n={};for(const[r,o]of Object.entries(e))n[r]=vn(o,t);return n}return e}function S_(e){return Gi(e)}const C_=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function Kc(e,t,n,r){if(os(e)||od(e))return vn(e,n);if(Du(t))return e;if(t?.type==="array"&&t.items&&Array.isArray(e))return e.map(i=>Kc(i,t.items,n,r));const o=t?.type==="object"&&t.shape?r[t.shape]:void 0;if(o&&C_(e)){const i={};for(const[s,a]of Object.entries(e))i[s]=Kc(a,o.properties[s],n,r);return i}return vn(e,n)}function A_(e,t,n,r){const o=S_(r),i=o.components[e],s={};for(const[a,l]of Object.entries(t)){const c=Kc(l,i?.props[a],n,o.defs);c!==void 0&&(s[a]=c)}return s}function Li(e,t,n=""){const r=e[t];return os(r)?Ko(r.path,n):void 0}function __(e,t){return e===void 0?!0:On(vn(e,t))}function Gc(e){return os(e)||od(e)?!0:Array.isArray(e)?e.some(Gc):typeof e=="object"&&e!==null?Object.values(e).some(Gc):!1}function O_(e,t){if(!e||typeof e!="object")return null;const n={};for(const[r,o]of Object.entries(vn(e,t)))o!==void 0&&(n[r]=o);return Object.keys(n).length?n:null}function T_(e){const t={};if(!e)return t;const n=e.role;n==="hidden"?t["aria-hidden"]="true":typeof n=="string"&&n!=="text"&&n!==""&&(t.role=n),e.label!==void 0&&e.label!==null&&e.label!==""&&(t["aria-label"]=String(e.label)),e.description!==void 0&&e.description!==null&&e.description!==""&&(t["aria-description"]=String(e.description)),(typeof e.level=="number"||typeof e.level=="string"&&e.level!=="")&&(t["aria-level"]=String(e.level));for(const[r,o]of[["expanded","aria-expanded"],["selected","aria-selected"],["pressed","aria-pressed"],["checked","aria-checked"]]){const i=e[r];(typeof i=="boolean"||i==="mixed")&&(t[o]=String(i))}e.current!==void 0&&e.current!==null&&e.current!==!1&&e.current!==""&&(t["aria-current"]=e.current===!0?"true":String(e.current));for(const[r,o]of[["valueNow","aria-valuenow"],["valueMin","aria-valuemin"],["valueMax","aria-valuemax"]]){const i=e[r];typeof i=="number"&&Number.isFinite(i)&&(t[o]=String(i))}return e.hidden===!0&&(t["aria-hidden"]="true"),e.autoFocus===!0&&(t["data-xui-autofocus"]=""),t}const rl=e=>`xui-n-${id(e)}`,Yc=e=>`xui-s-${id(e)}`;function id(e){return e.replace(/[^a-zA-Z0-9_-]/g,t=>`_${t.charCodeAt(0).toString(16)}_`)}function*xa(e){yield e;for(const t of Object.values(e.slots??{}))yield*xa(t);for(const t of e.children)yield*xa(t)}function Iy(e){const t=[];if(!e)return t;const n=(r,o)=>{for(const[i,s]of Object.entries(o))i.startsWith("@")||i.startsWith(":")||Gc(s)&&t.push({name:`--xd-${t.length}`,block:r,key:i,value:s})};n("",e);for(const[r,o]of Object.entries(e))(r.startsWith("@")||r.startsWith(":"))&&typeof o=="object"&&o!==null&&n(r,o);return t}function wa(e){return id(e.replace(/^@media \(|\)$/g,"").replace(/: /,"-"))}function Py(e,t){const n=Su(e);if(!n)return null;if(n.feature==="orientation"||n.feature==="form-factor"||n.feature==="hover"||n.feature==="prefers-reduced-motion")return e;const r=Zc(n.value,t);return r===null?null:`@media (${n.feature}: ${r}px)`}const Xc=e=>e==="ltr"||e==="rtl";function M_(e,t,n){if(!e)return;let r=Xc(e.direction)?e.direction:void 0;for(const[o,i]of Object.entries(e)){if(!o.startsWith("@")||typeof i!="object"||i===null)continue;const s=i.direction;if(!Xc(s))continue;const a=Py(o,t);a&&n(a)&&(r=s)}return r}function Zc(e,t){const n=nr(e);if(n){if(n.group!=="breakpoint")return null;const o=t?.tokens.breakpoint?.[n.name];return typeof o=="number"?o:null}const r=parseFloat(e);return Number.isFinite(r)?r:null}const Dy="\0";function Ry(e){const t=[],n=[];for(const r of e){const o=r.indexOf(Dy);o<0?t.push(r):(t.push(r.slice(0,o)),n.push(r.slice(o+1)))}return`@layer xui-node{${t.join("")}}${n.length?`@layer xui-author{${n.join("")}}`:""}`}const xf=new WeakMap;function E_(e,t,n,r,o){const i=xf.get(e);if(i&&i.scope===n&&i.theme===r&&i.fonts===o)return i.chunk;const s=new Set,a=Iy(t),l=(f,y)=>{const g=a.filter(m=>m.block===f&&m.key in y);if(g.length===0)return y;const v={...y};for(const m of g)v[m.key]=`var(${m.name})`;return v},c=rl(e.id),u=l("",t);let d=wf(t,u,l,n,c,r,o,s);const p=e.recipe?.authored;if(p?.length){const f={};for(const g of p)g in t&&(f[g]=t[g]);const y=wf(f,u,l,n,c,r,o,s);y&&(d+=Dy+y)}const h={css:d,queries:[...s]};return xf.set(e,{scope:n,theme:r,fonts:o,chunk:h}),h}function wf(e,t,n,r,o,i,s,a){const l=`${r} .${o}`,c=[],u=Bs(n("",e),s,t);u.length&&c.push(_r(l,u)+Ws(l,e));for(const[p,h]of Object.entries(e)){if(!p.startsWith("@")||typeof h!="object"||h===null)continue;const f=Bs(n(p,h),s,t);if(f.length===0)continue;const y=Su(p);if(!y)continue;if(Xc(h.direction)){const v=Py(p,i);v&&a.add(v)}const g=v=>Ws(v,h);switch(y.feature){case"min-width":case"max-width":{const m=Zc(y.value,i);if(m===null)break;const b=y.feature==="min-width"?">=":"<";c.push(`@container xui (width ${b} ${m}px){${_r(l,f)}${g(l)}}`);break}case"min-height":case"max-height":{const m=Zc(y.value,i);if(m===null)break;const b=`@media (${y.feature}: ${m}px)`;a.add(b);const x=`${r}:where([data-xq~="${wa(b)}"]) .${o}`;c.push(_r(x,f)+g(x));break}case"orientation":case"form-factor":a.add(p);const v=`${r}:where([data-xq~="${wa(p)}"]) .${o}`;c.push(_r(v,f)+g(v));break;case"hover":case"prefers-reduced-motion":c.push(`@media (${y.feature}: ${y.value}){${_r(l,f)}${g(l)}}`);break}}const d=[[":hover",`${l}:hover,${l}[data-xs~="hover"]`],[":focus-visible",`${l}:focus-visible,${l}[data-xs~="focus-visible"]`],[":pressed",`${l}:active,${l}[data-xs~="pressed"]`]];for(const[p,h]of d){const f=e[p];if(typeof f!="object"||f===null)continue;const y=Bs(n(p,f),s,t);y.length&&c.push(_r(h,y)+Ws(h,f))}return c.join("")}function I_(e,t,n,r=n?.fonts??{}){const o=`.${Yc(t)}`,i=new Map,s=new Set,a=new Set;for(const l of e)for(const c of xa(l)){const u=c.style;if(!u||a.has(c.id))continue;a.add(c.id);const d=E_(c,u,o,n,r);d.css&&i.set(c.id,d.css);for(const p of d.queries)s.add(p)}return{css:Ry(i.values()),queries:[...s],chunks:i}}const Wl=e=>({chunks:e,css:Ry(e.values())});function P_(e,t){const n=[],r=new Set;for(const i of e){let s=!1;for(const[l,c]of i.chunks)r.add(l),t.get(l)!==c&&(s=!0);if(!s){n.push(i);continue}const a=new Map;for(const l of i.chunks.keys()){const c=t.get(l);c!==void 0&&a.set(l,c)}a.size&&n.push(Wl(a))}const o=new Map;for(const[i,s]of t)r.has(i)||o.set(i,s);for(o.size&&n.push(Wl(o));n.length>1&&n[n.length-1].chunks.size>=n[n.length-2].chunks.size;){const i=n.pop(),s=n.pop();n.push(Wl(new Map([...s.chunks,...i.chunks])))}return n}const Qe=on.qrScanner;function D_(e,t,n,r){const o=J1(e,t),i=Ei(n),s=Ei(r),a=i!==null&&s!==null&&gp(i)<gp(s),l=a?r:n,c=a?n:r;if(!o)return{matrix:null,modules:0,path:"",plate:l,module:c};const u=j1.quietZone;let d="";return o.rows.forEach((p,h)=>{let f=0;for(;f<p.length;){if(p[f]!=="1"){f+=1;continue}let y=f;for(;y<p.length&&p[y]==="1";)y+=1;d+=`M${f+u} ${h+u}h${y-f}v1h${f-y}z`,f=y}}),{matrix:o,modules:o.size+2*u,path:d,plate:l,module:c}}function R_(e){let t=null;return n=>{typeof n!="string"||n===""||n===t||(t=n,e(n))}}const F_=["tl","tr","bl","br"];function z_(e,t){const n=Qe.cornerLength,r=Qe.cornerStroke/2,o=Math.max(0,Math.min(n-r,(Number.isFinite(t)?t:0)-r)),i=c=>e==="tr"||e==="br"?n-c:c,s=c=>e==="bl"||e==="br"?n-c:c,a=e==="tl"||e==="br"?1:0,l=c=>Math.round(c*100)/100;return`M${l(i(r))} ${l(s(n))}V${l(s(r+o))}A${l(o)} ${l(o)} 0 0 ${a} ${l(i(r+o))} ${l(s(r))}H${l(i(n))}`}function N_(e){const t=Ei(e);return t?`rgba(${t.r}, ${t.g}, ${t.b}, ${Math.round(t.a*Qe.feedAlpha*1e3)/1e3})`:`color-mix(in srgb, ${e} ${Qe.feedAlpha*100}%, transparent)`}function L_(e){const t=Array.isArray(e)?e.filter(n=>typeof n=="string"&&n!==""):[];return t.length?t:["qr"]}function Jc(e){const t=typeof e=="number"?e:typeof e=="string"&&e.trim()!==""?Number(e):NaN;if(!Number.isFinite(t)||t<=0)return null;const n=Math.floor(t);return n<=0?null:n>99?"99+":String(n)}const j_=24;function kf(e,t,n,r=j_){return t>=e.left-r&&t<=e.right+r&&n>=e.top-r&&n<=e.bottom+r}class B_{constructor(t,n,r){this.fire=t,this.pressed=n,this.disabled=r}fire;pressed;disabled;by=null;pointerId=null;get active(){return this.by!==null}start(t,n=null){return this.by!==null||this.disabled()?!1:(this.by=t,this.pointerId=n,this.pressed(!0),this.fire("holdStart"),!0)}finish(t){return this.by===null?!1:(this.by=null,this.pointerId=null,this.pressed(!1),this.fire(t),!0)}pointerDown(t=null){return this.start("pointer",t)}pointerMove(t,n,r,o=null){this.by!=="pointer"||!this.samePointer(o)||kf(t,n,r)||this.finish("holdCancel")}pointerUp(t,n,r,o=null){this.by!=="pointer"||!this.samePointer(o)||this.finish(kf(t,n,r)?"holdEnd":"holdCancel")}pointerCancel(t=null){this.by==="pointer"&&this.samePointer(t)&&this.finish("holdCancel")}keyDown(t,n=!1){return t==="Escape"?this.finish("holdCancel"):t!==" "&&t!=="Enter"?!1:n||this.by!==null?this.by!==null:this.start(t)}keyUp(t){return this.by===null||this.by!==t?t===" "||t==="Enter":this.finish("holdEnd")}blur(){this.finish("holdCancel")}reset(){this.by!==null&&(this.by=null,this.pointerId=null,this.pressed(!1))}samePointer(t){return this.pointerId===null||t===null||t===this.pointerId}}const kr=I1,W_=`@keyframes xui-shimmer{from{background-position:100% 0}to{background-position:0 0}}
26
26
  [data-xui-shimmer]{--_spread:${kr.spreadPx}px;--_base:currentColor;--_highlight:oklch(from currentColor l c h / calc(alpha * ${kr.lightAlphaFactor}));background-image:linear-gradient(calc(90deg + ${kr.angleDeg}deg),var(--_base) calc(50% - var(--_spread)),color-mix(in oklab,var(--_highlight),var(--_base) 50%) calc(50% - var(--_spread) * .5),var(--_highlight) 50%,color-mix(in oklab,var(--_highlight),var(--_base) 50%) calc(50% + var(--_spread) * .5),var(--_base) calc(50% + var(--_spread)));background-repeat:no-repeat;background-size:calc(200% + var(--_spread) * 2) 100%;background-position:0 0;-webkit-background-clip:text;background-clip:text;-webkit-text-fill-color:transparent;animation:xui-shimmer ${kr.durationMs}ms linear infinite}