@cube-nl/dmp-sdk 1.1.0-rc.1 → 1.1.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cube-sdk.js CHANGED
@@ -1,5 +1,5 @@
1
- /*! @cube-nl/dmp-sdk 1.1.0-rc.1 cube-sdk.js (window.CubeApp) | MIT */
2
- "use strict";(()=>{var Nr=Object.defineProperty;var jr=(e,n,t)=>n in e?Nr(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var b=(e,n,t)=>jr(e,typeof n!="symbol"?n+"":n,t);var L=class extends Error{constructor(t,o,a){let i=a!==null&&typeof a=="object"?a:{},r=ee(i.detail)??ee(i.error_description);super(r??`HTTP ${t}`);b(this,"status");b(this,"code");b(this,"reason");b(this,"type");b(this,"title");b(this,"detail");b(this,"errors");b(this,"retryAfter");b(this,"recordVersion");b(this,"allow");b(this,"headers");b(this,"body");this.name="DmpError",this.status=t,this.code=ee(i.code)??ee(i.error),this.reason=ee(i.reason),this.type=ee(i.type),this.title=ee(i.title),this.detail=r,this.errors=Ir(i.errors)?i.errors:null,this.retryAfter=Br(o.get("Retry-After")),this.recordVersion=o.get("X-Dmp-Record-Version"),this.allow=o.has("Allow")?(o.get("Allow")??"").split(",").map(s=>s.trim()).filter(s=>s!==""):null,this.headers=o,this.body=a}get isProblem(){return this.code!==null}};function F(e){return e instanceof L}function ee(e){return typeof e=="string"?e:null}function Ir(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Br(e){if(e===null||e.trim()==="")return null;let n=Number(e);if(Number.isFinite(n))return n;let t=Date.parse(e);return Number.isNaN(t)?null:Math.max(0,Math.ceil((t-Date.now())/1e3))}function Wt(e){return{async getAccessToken(){let n=typeof e=="function"?await e():e;return n===void 0||n===""?null:n}}}var Fe="cube-dmp-sdk.pending-login";function Qt(e){let n=e.fetch??globalThis.fetch.bind(globalThis),t=e.tokenStore??_e(),o=e.pendingStore??Vr(),a=(e.refreshLeewaySeconds??30)*1e3,i=typeof e.scopes=="string"?e.scopes:e.scopes.join(" "),r=e.metadata??{},s=Ur(r)?Promise.resolve({...r,issuer:r.issuer??e.issuer}):null,l=null,u=()=>(s??(s=Hr(e.issuer,n).then(m=>({...m,...r}),m=>{throw s=null,m})),s),c=async(m,d)=>{let{token_endpoint:g}=await u(),w=new URLSearchParams(m);e.clientSecret!==void 0&&w.set("client_secret",e.clientSecret);let v=await n(g,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/x-www-form-urlencoded"},body:w.toString()}),k=await Jt(v);if(!v.ok||k===null||typeof k!="object"||typeof k.access_token!="string")throw new L(v.status,v.headers,k);let x={accessToken:k.access_token,refreshToken:typeof k.refresh_token=="string"?k.refresh_token:null,expiresAt:typeof k.expires_in=="number"?Date.now()+k.expires_in*1e3:null,scope:typeof k.scope=="string"?k.scope:d};return await t.set(x),x},p=()=>(l??(l=(async()=>{let m=await t.get();if(m?.refreshToken==null)throw new TypeError("No refresh token: sign in again.");try{return await c({grant_type:"refresh_token",refresh_token:m.refreshToken,client_id:e.clientId},m.scope)}catch(d){throw d instanceof L&&d.status>=400&&d.status<500&&await t.set(null),d}})().finally(()=>{l=null})),l),f=async(m={})=>{let d=await u();if(!(d.code_challenge_methods_supported??[]).includes("S256"))throw new TypeError("The authorization server does not offer PKCE S256; this SDK will not sign in without it.");let g=Gt(64),w=m.state??Gt(32),v=Yt(await crypto.subtle.digest("SHA-256",new TextEncoder().encode(g))),k={verifier:g,state:w,redirectUri:e.redirectUri,clientId:e.clientId};o.setItem(Fe,JSON.stringify(k));let x=new URL(d.authorization_endpoint);return x.search=new URLSearchParams({...m.extraParams,response_type:"code",client_id:e.clientId,redirect_uri:e.redirectUri,scope:i,state:w,code_challenge:v,code_challenge_method:"S256"}).toString(),x.toString()};return{discover:u,authorizationUrl:f,async signIn(m={}){let d=qt();if(d===null)throw new TypeError("signIn() needs a browser; use authorizationUrl() and redirect yourself.");d.assign(await f(m))},async handleCallback(m){let d=m??qt()?.href;if(d===void 0)throw new TypeError("handleCallback() needs the callback URL outside a browser.");let g=new URL(d),w=new URLSearchParams(g.search);if(!Kr(g,e.redirectUri)||!w.has("code")&&!w.has("error"))return null;if(m===void 0){for(let k of["code","state","error","error_description","iss"])g.searchParams.delete(k);globalThis.history?.replaceState(null,"",g.pathname+g.search+g.hash)}let v=qr(o.getItem(Fe));if(v===null||w.get("state")!==v.state)throw new TypeError("The state does not match: this callback does not belong to a sign-in started here.");if(o.removeItem(Fe),w.has("error"))throw new L(400,new Headers,{error:w.get("error")??"access_denied",error_description:w.get("error_description")??void 0});return c({grant_type:"authorization_code",code:w.get("code")??"",redirect_uri:v.redirectUri,client_id:v.clientId,code_verifier:v.verifier},i)},refresh:p,async getTokens(){return t.get()},async setTokens(m){await t.set(m)},async signOut(){await t.set(null),o.removeItem(Fe)},async getAccessToken(){let m=await t.get();if(m===null)return null;if(m.expiresAt!==null&&m.expiresAt-a<=Date.now()&&m.refreshToken!==null)try{return(await p()).accessToken}catch{return(await t.get())?.accessToken??null}return m.accessToken},async onUnauthorized(){if((await t.get())?.refreshToken==null)return!1;try{return await p(),!0}catch{return!1}}}}function Ur(e){return typeof e.authorization_endpoint=="string"&&typeof e.token_endpoint=="string"}async function Hr(e,n=globalThis.fetch.bind(globalThis)){let t=`${e.replace(/\/+$/,"")}/.well-known/oauth-authorization-server`,o=await n(t,{headers:{Accept:"application/json"}}),a=await Jt(o);if(!o.ok||a===null||typeof a!="object")throw new L(o.status,o.headers,a);return a}function _e(e=null){let n=e;return{get:()=>n,set:t=>{n=t}}}function zr(){let e=new Map;return{getItem:n=>e.get(n)??null,setItem:(n,t)=>{e.set(n,t)},removeItem:n=>{e.delete(n)}}}function Vr(){try{let e=globalThis.sessionStorage;if(e!==void 0)return e}catch{}return zr()}function qt(){let e=globalThis.location;return e!==void 0&&typeof e.assign=="function"?e:null}function Kr(e,n){let t=new URL(n),o=a=>a.replace(/\/+$/,"")||"/";return e.origin===t.origin&&o(e.pathname)===o(t.pathname)}function qr(e){if(e===null)return null;try{let n=JSON.parse(e);return typeof n.verifier=="string"&&typeof n.state=="string"&&typeof n.redirectUri=="string"&&typeof n.clientId=="string"?n:null}catch{return null}}async function Jt(e){let n=await e.text();if(n==="")return null;try{return JSON.parse(n)}catch{return n}}function Gt(e){return Yt(crypto.getRandomValues(new Uint8Array(e)))}function Yt(e){let n=e instanceof Uint8Array?e:new Uint8Array(e),t="";for(let o of n)t+=String.fromCharCode(o);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}var Gr=new Set(["in","between"]);function te(e,n={}){let t=new URLSearchParams;Wr(t,e,n.fields),Qr(t,n.filter),be(t,"sort",n.sort),be(t,"include",n.include),be(t,"with_count",n.withCount),Yr(t,n.has),be(t,"fn",n.fn),be(t,"group",n.group),n.page?.size!==void 0&&t.append("page[size]",String(n.page.size)),n.page?.number!==void 0&&t.append("page[number]",String(n.page.number));for(let[o,a]of Object.entries(n.params??{}))t.append(o,a);return t.toString().replace(/%5B/gi,"[").replace(/%5D/gi,"]").replace(/%2C/gi,",").replace(/%28/gi,"(").replace(/%29/gi,")")}function Wr(e,n,t){if(t===void 0)return;let o=Xr(t)?{[n]:t}:t;for(let[a,i]of Object.entries(o))i.length>0&&e.append(`fields[${a}]`,i.join(","))}function Qr(e,n){for(let[t,o]of Object.entries(n??{})){if(Array.isArray(o))throw new TypeError(`filter.${t}: a bare list names no operator and cube/api refuses it. Write { in: [...] } (or { between: [from, to] }).`);if(o==null)throw new TypeError(`filter.${t}: write { is: 'null' } or { is: 'not_null' } to filter on null.`);if(typeof o!="object"){e.append(`filter[${t}]`,dt(o));continue}for(let[a,i]of Object.entries(o))i!==void 0&&e.append(`filter[${t}][${a}]`,Jr(t,a,i))}}function Jr(e,n,t){if(t===null){if(n!=="is")throw new TypeError(`filter.${e}.${n}: null is only meaningful under 'is'.`);return"null"}if(Array.isArray(t)){if(!Gr.has(n))throw new TypeError(`filter.${e}.${n}: takes one value; only 'in' and 'between' take a list.`);return t.map(dt).join(",")}return dt(t)}function Yr(e,n){for(let[t,o]of Object.entries(n??{}))o===!0?e.append(`has[${t}]`,"1"):typeof o=="number"?e.append(`has[${t}][min]`,String(o)):(o.min!==void 0&&e.append(`has[${t}][min]`,String(o.min)),o.max!==void 0&&e.append(`has[${t}][max]`,String(o.max)))}function be(e,n,t){if(t===void 0)return;let o=typeof t=="string"?t:t.filter(a=>a!=="").join(",");o!==""&&e.append(n,o)}function dt(e){return typeof e=="boolean"?e?"1":"0":String(e)}function Xr(e){return Array.isArray(e)}var Zr=/^[a-z][a-z0-9_]*$/;function Zt(e){let n=e.baseUrl.replace(/\/+$/,""),t=e.fetch??globalThis.fetch.bind(globalThis),o=e.auth===void 0?null:typeof e.auth=="string"||typeof e.auth=="function"?Wt(e.auth):e.auth,a=e.cache??(typeof document<"u"?"no-cache":void 0),i=async(s,l,{query:u,body:c,headers:p={},signal:f}={})=>{let m=`${n}${l.startsWith("/")?l:`/${l}`}${u?`?${u}`:""}`,d=async()=>{let k=o===null?null:await o.getAccessToken(),x={method:s,headers:{Accept:"application/json",...e.headers,...k!==null?{Authorization:`Bearer ${k}`}:{},...c!==void 0?{"Content-Type":"application/json"}:{},...p}};c!==void 0&&(x.body=JSON.stringify(c)),a!==void 0&&(x.cache=a),f!==void 0&&(x.signal=f);let P=Date.now(),A=await t(m,x);return e.onResponse?.({method:s,url:m,status:A.status,ms:Date.now()-P}),A},g=await d();g.status===401&&o?.onUnauthorized!==void 0&&await o.onUnauthorized()&&(await g.body?.cancel().catch(()=>{}),g=await d());let w=await to(g);if(!g.ok)throw new L(g.status,g.headers,w);let v=no(w)?w:null;return{status:g.status,data:v!==null?v.data:w,meta:v?.meta??null,headers:g.headers,etag:g.headers.get("ETag"),recordVersion:g.headers.get("X-Dmp-Record-Version"),location:g.headers.get("Location"),replayed:g.headers.get("Idempotency-Replayed")==="true",rateLimit:ro(g.headers)}};return{async capabilities(s={}){let l=(await i("GET","/_capabilities",Oe({},s))).data;return{...l,resources:l.resources.map(eo)}},resources:s=>{if(!Zr.test(s))throw new TypeError(`'${s}' is not a resource name: cube/api names match [a-z][a-z0-9_]*.`);let l=`/${s}`,u=d=>{let g=String(d);if(g==="")throw new TypeError(`${s}: an empty id would address the collection, not a record.`);if(tn(g))throw new TypeError(`${s}: '${g}' is not an id: it would address another path, not a record.`);return`${l}/${encodeURIComponent(g)}`},c=d=>d===void 0?"":te(s,{fields:d}),p=async(d={},g={})=>await i("GET",l,Oe({query:te(s,d)},g)),f=async function*(d={},g={}){let w=d.page?.number??1;for(;;){let v=await p({...d,page:{...d.page,number:w}},g);yield v;let k=v.meta.page;if(k==null||k.number>=k.pages||v.data.length===0)return;w=k.number+1}},m=async(d,g,w)=>{let v=await i("POST",d,{query:c(w.fields),body:g??{},headers:$e(w)});return{...v,data:v.status===204?null:v.data,accepted:v.status===202}};return{name:s,list:p,pages:f,async*all(d={},g={}){for await(let w of f(d,g))yield*w.data},get:(d,g={},w={})=>i("GET",u(d),Oe({query:te(s,g)},w)),aggregate:(d,g={})=>i("GET",`${l}/_aggregate`,Oe({query:te(s,d)},g)),create:(d,g={})=>i("POST",l,{query:c(g.fields),body:d,headers:$e(g)}),update:(d,g,w={})=>i("PATCH",u(d),{query:c(w.fields),body:g,headers:$e(w)}),delete:async(d,g={})=>({...await i("DELETE",u(d),{headers:$e(g)}),data:null}),operation:(d,g,w,v={})=>m(`${u(d)}/${encodeURIComponent(Xt(g))}`,w,v),collectionOperation:(d,g,w={})=>m(`${l}/_operations/${encodeURIComponent(Xt(d))}`,g,w)}},request:i}}function eo(e){return{...e,operations:(e.operations??[]).map(n=>({...n,input:pt(n.input)})),aggregatable:pt(e.aggregatable),relations:pt(e.relations)}}function pt(e){return Array.isArray(e)||e===void 0||e===null?{}:e}function en(){return crypto.randomUUID()}function Xt(e){if(e===""||e.startsWith("_"))throw new TypeError(`'${e}' is not an operation name: the '_' namespace is reserved by the API.`);if(tn(e))throw new TypeError(`'${e}' is not an operation name: it would address another path.`);return e}function tn(e){return e==="."||e===".."}function $e(e){let n={};if(e.idempotencyKey!==void 0&&(n["Idempotency-Key"]=e.idempotencyKey),e.ifMatch!==void 0){if(e.ifMatch.startsWith("W/"))throw new TypeError("ifMatch takes recordVersion (X-Dmp-Record-Version), not the weak ETag.");n["If-Match"]=e.ifMatch}return n}function Oe(e,n){return n.signal===void 0?e:{...e,signal:n.signal}}async function to(e){let n=await e.text();if(n==="")return null;try{return JSON.parse(n)}catch{return n}}function no(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)&&"data"in e}function ro(e){let n=t=>{let o=e.get(t);return o===null||o===""||!Number.isFinite(Number(o))?null:Number(o)};return{limit:n("X-RateLimit-Limit"),remaining:n("X-RateLimit-Remaining"),reset:n("X-RateLimit-Reset")}}var nn=/^[a-z][a-z0-9_]*$/,rn=["eq","neq","gt","gte","lt","lte","in","like","ilike","is","between"],oo=[[">=","gte"],["<=","lte"],["<>","neq"],[">","gt"],["<","lt"],["=","eq"]],yt=["count","sum","avg","min","max"],on=["day","week","month","quarter","year"],mt=20,ft=5,sn=1e3,gt=200,io=50,ht=200,so="1.0",J=class{constructor(n,t=null,o=()=>{}){b(this,"manifest",t);b(this,"guard",o);b(this,"tables",new Map);for(let[a,i]of Object.entries(ao(n))){if(typeof i!="object"||i===null||Array.isArray(i))continue;let r=typeof i.schema?.name=="string"&&i.schema.name!==""?i.schema.name:a;nn.test(r)&&this.tables.set(r,lo(r,i))}}rows(n){return this.tables.get(n)?.rows??[]}resourceNames(){return[...this.tables.keys()]}describe(n){let t=this.tables.get(n);return t===void 0?null:{name:n,actions:[...t.actions],fields:[...t.fields.values()].map(o=>{let a=t.choices.get(o.name);return{name:o.name,type:o.types.join("|"),format:o.format,nullable:o.nullable,readonly:!t.writable.has(o.name),enum:a===void 0?null:a.map(String),description:o.description}}),summary:[...t.summary],filterable:[...t.filterable],sortable:[...t.fields.keys()],groupable:[...t.groupable],aggregatable:Object.fromEntries([...t.aggregatable].map(([o,a])=>[o,a.filter(i=>i!=="count")]))}}resource(n){if(!nn.test(n))throw new TypeError(`'${n}' is not a resource name: cube/api names match [a-z][a-z0-9_]*.`);let t=(i,r)=>Promise.resolve().then(()=>r(this.authorize(n,i))),o=(i={})=>t("list",r=>co(r,i)),a=async function*(i={}){let r=i.page?.number??1;for(;;){let s=await o({...i,page:{...i.page,number:r}});if(yield s,s.meta.page.number>=s.meta.page.pages||s.data.length===0)return;r=s.meta.page.number+1}};return{name:n,list:o,pages:a,async*all(i={}){for await(let r of a(i))yield*r.data},get:(i,r={})=>t("get",s=>po(s,i,r)),aggregate:i=>t("aggregate",r=>yo(r,i)),create:(i,r={})=>t("create",s=>So(s,i,r)),update:(i,r,s={})=>t("update",l=>xo(l,i,r,s)),delete:(i,r={})=>t("delete",s=>To(s,i,r)),operation:(i,r,s,l)=>t("get",u=>{throw Ne(u,i),un(r)}),collectionOperation:i=>t("list",()=>{throw un(i)})}}authorize(n,t){this.guard();let o=this.tables.get(n);if(o===void 0)throw R(404,"not_found",`Unknown API resource [${n}].`);let a=this.manifest?.uses;if(a!==void 0&&!(a[n]??[]).includes(t))throw R(403,"client_scope_exceeded",`This app may not ${t} '${n}': add it to "uses" in cube-app.json.`);return o}};function ao(e){let n=e.resources;return Object.keys(e).length===1&&ye(n)&&!("rows"in n)&&!("schema"in n)?n:e}function lo(e,n){let t=n.schema??{},o=(n.rows??[]).map(p=>vt(p)),a=new Map,i=Array.isArray(t.fields)?t.fields.map(p=>[p.name,p]):Object.entries(t.fields??{});for(let[p,f]of i)a.set(p,uo(p,f));for(let p of a.size===0?o:[])for(let f of Object.keys(p))a.has(f)||a.set(f,{name:f,types:[],nullable:!0,format:null,description:null});let r=[...a.keys()],s=(ye(t.choices)?Object.entries(t.choices):[]).filter(p=>ye(p[1])&&Array.isArray(p[1].values)),l=new Set(["id",...t.readonly??[],...i.filter(([,p])=>p.readonly===!0).map(([p])=>p),...s.filter(([,p])=>p.writable===!1).map(([p])=>p)]),u=new Map;for(let[p,f]of i)Array.isArray(f.enum)&&u.set(p,f.enum);for(let[p,f]of s)u.set(p,f.values);let c=p=>Array.isArray(p)?p.filter(f=>typeof f=="string"&&a.has(f)):null;return{name:e,actions:Array.isArray(t.actions)?t.actions.filter(p=>typeof p=="string"):["list","get","create","update","delete"],fields:a,filterable:c(t.filters)??r,groupable:c(t.groupable)??r,aggregatable:new Map(ye(t.aggregatable)?Object.entries(t.aggregatable).filter(([p,f])=>a.has(p)&&Array.isArray(f)).map(([p,f])=>[p,[...f]]):r.map(p=>[p,[...yt]])),choices:u,writable:new Set(r.filter(p=>!l.has(p))),summary:(c(t.summary_fields)??[]).length>0?c(t.summary_fields):r,rows:o,versions:new Map(o.map(p=>[K(p.id),1])),replays:new Map}}function uo(e,n){let t=n.type,o=typeof t=="string"?t.split("|"):Array.isArray(t)?[...t]:[];return{name:e,types:o.filter(a=>a!=="null"&&a!==""),nullable:n.nullable===!0||o.includes("null"),format:typeof n.format=="string"?n.format:null,description:typeof n.description=="string"?n.description:null}}function we(e,n){return new URLSearchParams(te(e.name,n))}function co(e,n){let t=we(e,n),o=Pe(e,t),a=dn(e,t),i=ho(e,t),{size:r,number:s}=bo(t),l=cn(e,t),u=e.rows.filter(m=>a.every(d=>pn(e,m,d)));i.length>0&&(u=[...u].sort((m,d)=>{for(let{field:g,descending:w}of i){let v=B(m[g],d[g]);if(v!==0)return w?-v:v}return 0}));let c=u.length,p=u.slice((s-1)*r,s*r).map(m=>je(m,o)),f={size:r,number:s,total:c,pages:Math.max(1,Math.ceil(c/r))};return{...ie(200,p,oe(e,f,l)),meta:{...oe(e,f,l),page:f}}}function po(e,n,t){let o=we(e,t),a=Pe(e,o),i=cn(e,o),r=Ne(e,n);return ie(200,je(r,a),oe(e,null,i),Ie(e,r))}function Pe(e,n){let t=`fields[${e.name}]`,o=n.get(t);if(o===null||o==="")return e.summary;let a=o.split(",").map(r=>r.trim()),i=a.filter(r=>!e.fields.has(r));if(i.length>0)throw R(422,"query_invalid",`Unknown ${t}: ${i.join(", ")}.`,{[t]:[`Allowed values: ${[...e.fields.keys()].join(", ")}.`]});return a}function cn(e,n){let t=o=>(n.get(o)??"").split(",").filter(a=>a!=="");return[...new Set([...t("include"),...t("with_count")])]}function dn(e,n){let t=[],o=[];n.forEach((a,i)=>o.push([i,a]));for(let[a,i]of o){let r=/^filter\[([^\]]+)\](?:\[([^\]]+)\])?$/.exec(a);if(r===null)continue;let s=r[1];if(!e.filterable.includes(s))throw R(422,"query_invalid",`Unknown filter: ${s}.`,{filter:[`Allowed values: ${e.filterable.join(", ")}.`]},"not_filterable");t.push(r[2]===void 0?mo(s,i):fo(s,r[2],i))}if(t.length>mt)throw R(422,"query_invalid",`A query takes at most ${mt} filters.`,{filter:[`Sent ${t.length}; the limit is ${mt}.`]});return t}function mo(e,n){for(let[t,o]of oo)if(n.startsWith(t))return{field:e,operator:o,value:n.slice(t.length)};return{field:e,operator:"eq",value:n}}function fo(e,n,t){if(!rn.includes(n))throw R(422,"query_invalid",`Unknown filter operator: ${n}.`,{filter:[`Allowed operators: ${rn.join(", ")}.`]});if(n==="between"&&t.split(",").length!==2)throw R(422,"query_invalid",`filter[${e}][between] takes exactly 2 values.`,{filter:[`Write filter[${e}][between]=low,high. Received ${t.split(",").length} value(s).`]});if(n==="in"&&t.split(",").length>gt)throw R(422,"query_invalid",`filter[${e}][in] takes at most ${gt} values.`,{filter:[`Sent ${t.split(",").length}; the limit is ${gt}.`]});if(n==="is"&&t!=="null"&&t!=="not_null")throw R(422,"query_invalid",`filter[${e}][is] takes null or not_null.`,{filter:[`Received: ${t}.`]});return{field:e,operator:n,value:t}}function pn(e,n,t){let o=n[t.field],a=i=>Eo(e.fields.get(t.field),i.trim());switch(t.operator){case"eq":return bt(o,a(t.value));case"neq":return o!=null&&!bt(o,a(t.value));case"gt":return o!=null&&B(o,a(t.value))>0;case"gte":return o!=null&&B(o,a(t.value))>=0;case"lt":return o!=null&&B(o,a(t.value))<0;case"lte":return o!=null&&B(o,a(t.value))<=0;case"in":return t.value.split(",").some(i=>bt(o,a(i)));case"between":{let[i,r]=t.value.split(",").map(a);return o!=null&&B(o,i)>=0&&B(o,r)<=0}case"like":case"ilike":return typeof o=="string"&&go(o,t.value);case"is":return t.value==="null"?o==null:o!=null;default:return!1}}function go(e,n){let t=n.split("%").map(o=>o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join(".*");return new RegExp(t,"iu").test(e)}function ho(e,n){let t=n.get("sort");if(t===null||t==="")return[];let o=t.split(",").map(i=>i.trim()).filter(i=>i!=="").map(i=>({field:i.replace(/^[-+]/,""),descending:i.startsWith("-")})),a=o.map(i=>i.field).filter(i=>!e.fields.has(i));if(a.length>0)throw R(422,"query_invalid",`Unknown sort: ${a.join(", ")}.`,{sort:[`Allowed values: ${[...e.fields.keys()].join(", ")}.`]},"not_sortable");return o}function bo(e){let n=o=>{let a=e.get(o);if(a===null||a==="")return null;if(!/^\d+$/.test(a))throw R(422,"query_invalid",`${o} must be a positive integer.`,{[o]:["Expected a positive integer."]});return Number(a)},t=n("page[size]")??io;if(t>ht)throw R(422,"cardinality_exceeded",`page[size] may not exceed ${ht}.`,{"page.size":[`The maximum page size is ${ht}.`]});return{size:Math.max(1,t),number:Math.max(1,n("page[number]")??1)}}function yo(e,n){let t=we(e,n),o=(t.get("fn")??"").trim();if(o==="")throw R(422,"query_invalid","fn is required: name at least one aggregation function.",{fn:[`Expected e.g. fn=count or fn=sum(field). ${wt(e)}`]});let a=o.split(",").map(m=>m.trim()),i=a.map(m=>wo(e,m));an(a,"fn");let r=(t.get("group")??"").trim(),s=r===""?[]:r.split(",").map(m=>m.trim());if(s.length>ft)throw R(422,"cardinality_exceeded",`group may not exceed ${ft} dimensions, ${s.length} given.`,{group:[`Use at most ${ft} dimensions.`]});let l=s.map(m=>vo(e,m));an(s,"group");let u=dn(e,t),c=new Map;for(let m of e.rows.filter(d=>u.every(g=>pn(e,d,g)))){let d={};for(let[v,k]of s.entries())d[k]=l[v](m);let g=JSON.stringify(Object.values(d)),w=c.get(g)??{key:d,rows:[]};w.rows.push(m),c.set(g,w)}if(s.length===0&&c.size===0&&c.set("[]",{key:{},rows:[]}),c.size>sn)throw R(422,"cardinality_exceeded","The grouping produces more groups than the configured maximum.",{groepen:["The grouping produces more groups than the configured maximum.",`Allowed values: groepeer grover, of filter eerst; maximaal ${sn} groepen.`]},"too_many_groups");let f=[...c.values()].sort((m,d)=>{for(let g of s){let w=B(m.key[g],d.key[g]);if(w!==0)return w}return 0}).map(({key:m,rows:d})=>{let g={...m};for(let[w,v]of a.entries())g[v]=i[w](d);return g});return ie(200,f,{...oe(e,null,[]),groups:f.length})}function an(e,n){let t=[...new Set(e.filter((o,a)=>e.indexOf(o)!==a))];if(t.length>0)throw R(422,"query_invalid",`Duplicate ${n} entry: ${t.join(", ")}.`,{[n]:[`List each ${n} entry once.`]})}function wt(e){return e.aggregatable.size===0?"This resource has no aggregatable fields; only bare count is available.":`Aggregatable fields: ${[...e.aggregatable.keys()].join(", ")}.`}function wo(e,n){let t=/^([a-z]+)\(([a-z0-9_]+)\)$/.exec(n);if(t===null&&!/^[a-z]+$/.test(n))throw R(422,"query_invalid",`Unparseable fn entry: ${n}.`,{fn:["Expected `count` or `function(field)`, e.g. sum(field)."]});let o=t===null?n:t[1],a=t===null?null:t[2];if(!yt.includes(o))throw R(422,"query_invalid",`Unknown aggregation function: ${o}.`,{fn:[`Allowed values: ${yt.join(", ")}.`]});if(a===null){if(o!=="count")throw R(422,"query_invalid",`${o} must be applied to a field, e.g. ${o}(field).`,{fn:[wt(e)]});return r=>r.length}let i=e.aggregatable.get(a);if(i===void 0)throw R(422,"query_invalid",`Unknown aggregatable field: ${a}.`,{fn:[wt(e)]});if(!i.includes(o))throw R(422,"query_invalid",`${o} is not allowed on ${a}.`,{fn:[`Allowed functions for ${a}: ${i.join(", ")}.`]});return r=>{let s=r.map(u=>u[a]).filter(u=>u!=null),l=s.map(Number).filter(u=>Number.isFinite(u));switch(o){case"count":return r.length;case"sum":return l.length===0?null:l.reduce((u,c)=>u+c,0);case"avg":return l.length===0?null:l.reduce((u,c)=>u+c,0)/l.length;case"min":return s.length===0?null:s.reduce((u,c)=>B(c,u)<0?c:u);default:return s.length===0?null:s.reduce((u,c)=>B(c,u)>0?c:u)}}}function vo(e,n){let t=n.split(".");if(t.length>2)throw R(422,"query_invalid",`Unparseable group entry: ${n}.`,{group:["Expected `field` or `field.unit`, e.g. published_at.month."]});let[o,a]=t;if(!e.groupable.includes(o))throw R(422,"query_invalid",`Unknown group: ${o}.`,{group:[`Allowed values: ${e.groupable.join(", ")}.`]},"not_groupable");if(a===void 0)return i=>i[o]??null;if(!on.includes(a))throw R(422,"query_invalid",`Unknown truncation unit: ${a}.`,{group:[`Allowed values: ${on.join(", ")}.`]});return i=>ko(i[o],a)}function ko(e,n){let t=typeof e=="string"?/^(\d{4})-(\d{2})-(\d{2})/.exec(e):null;if(t===null)return null;let[o,a,i]=[Number(t[1]),Number(t[2]),Number(t[3])],r=new Date(Date.UTC(o,a-1,i));if(r.getUTCFullYear()!==o||r.getUTCMonth()!==a-1||r.getUTCDate()!==i)return null;switch(n){case"day":return t[0];case"week":{let s=new Date(r.getTime()+(3-(r.getUTCDay()+6)%7)*864e5),l=s.getUTCFullYear(),u=1+Math.floor((s.getTime()-Date.UTC(l,0,1))/(7*864e5));return`${l}-W${String(u).padStart(2,"0")}`}case"month":return t[0].slice(0,7);case"quarter":return`${t[1]}-Q${Math.ceil(a/3)}`;case"year":return t[1];default:return null}}function So(e,n,t){let o=t.fields===void 0?e.summary:Pe(e,we(e,{fields:t.fields})),a=JSON.stringify([n,t.fields??null]);if(t.idempotencyKey!==void 0){let l=e.replays.get(t.idempotencyKey);if(l!==void 0){if(l.body!==a)throw R(422,"validation_failed","This Idempotency-Key was already used with a different request body. Use a new key, or resend the original body.");return{...l.response,replayed:!0}}}let i=mn(e,n),r={id:Ao(e),...i};for(let l of e.fields.keys())l in r||(r[l]=null);e.rows.push(r),e.versions.set(K(r.id),1);let s=ie(201,je(r,o),oe(e,null,[]),Ie(e,r));return t.idempotencyKey!==void 0&&e.replays.set(t.idempotencyKey,{body:a,response:s}),s}function xo(e,n,t,o){let a=o.fields===void 0?e.summary:Pe(e,we(e,{fields:o.fields})),i=Ne(e,n);return fn(e,i,o.ifMatch),Object.assign(i,mn(e,t)),e.versions.set(K(i.id),(e.versions.get(K(i.id))??1)+1),ie(200,je(i,a),oe(e,null,[]),Ie(e,i))}function To(e,n,t){let o=Ne(e,n);return fn(e,o,t.ifMatch),e.rows.splice(e.rows.indexOf(o),1),e.versions.delete(K(o.id)),ie(204,null,null)}function mn(e,n){let t=[...e.writable],o=t.length===0?"This resource declares no writable fields.":`Writable fields: ${t.join(", ")}.`;if(!ye(n)||Object.keys(n).length===0)throw R(422,"validation_failed","The request body must be a JSON object naming at least one writable field.",{body:[o]});let a=Object.keys(n).filter(r=>!e.writable.has(r));if(a.length>0)throw R(422,"query_invalid",`Unknown or read-only fields: ${a.join(", ")}.`,Object.fromEntries(a.map(r=>[r,[o]])));let i={};for(let[r,s]of Object.entries(n)){let l=e.fields.get(r),u=Co(l,s)??Ro(e,l,r,s);u!==null&&(i[r]=[u])}if(Object.keys(i).length>0)throw R(422,"validation_failed","The request body failed validation.",i);return vt(n)}function Ro(e,n,t,o){let a=e.choices.get(t);return a===void 0||o===null&&n?.nullable===!0||a.includes(o)?null:`The selected ${t.replace(/_/g," ")} is invalid.`}function Co(e,n){return e===void 0||e.types.length!==1?null:n===null?e.nullable?null:ln(e):(()=>{switch(e.types[0]){case"string":return typeof n=="string";case"integer":return typeof n=="number"&&Number.isInteger(n)||typeof n=="string"&&/^[+-]?\d+$/.test(n.trim());case"number":return typeof n=="number"&&Number.isFinite(n)||typeof n=="string"&&n.trim()!==""&&Number.isFinite(Number(n));case"boolean":return[!0,!1,0,1,"0","1"].includes(n);case"array":case"object":return typeof n=="object";default:return!0}})()?null:ln(e)}function ln(e){return`The ${e.name.replace(/_/g," ")} field must be ${{string:"a string",integer:"an integer",number:"a number",boolean:"true or false",array:"an array",object:"an array"}[e.types[0]]??"valid"}.`}function fn(e,n,t){if(t===void 0)return;if(t.startsWith("W/"))throw new TypeError("ifMatch takes recordVersion (X-Dmp-Record-Version), not the weak ETag.");let o=Ie(e,n);if(t!==o)throw R(409,"conflict","The record changed since the version you sent.",void 0,void 0,{"X-Dmp-Record-Version":o})}function Ao(e){let n=e.rows.map(t=>t.id);return n.length>0&&n.every(t=>typeof t=="string")&&n.some(t=>!/^\d+$/.test(t))?crypto.randomUUID():n.reduce((t,o)=>Math.max(t,Number(o)||0),0)+1}function Ne(e,n){let t=K(n);if(t===""||t==="."||t==="..")throw new TypeError(`${e.name}: '${t}' is not an id.`);let o=e.rows.find(a=>K(a.id)===t);if(o===void 0)throw R(404,"not_found",`No such ${e.name} record.`);return o}function un(e){return R(404,"not_found",`No such operation [${e}]. The preview runs no custom operations.`)}function je(e,n){let t={};for(let o of n)t[o]=o in e?vt(e[o]):null;return t}function Ie(e,n){return`"preview-${K(n.id)}-${e.versions.get(K(n.id))??1}"`}function oe(e,n,t){return{resource:e.name,contract:so,page:n,groups:null,omitted:t,pruned:[],forbidden_fields:[]}}function ie(e,n,t,o=null){let a=new Headers({"X-Dmp-Preview":"true"});return o!==null&&a.set("X-Dmp-Record-Version",o),{status:e,data:n,meta:t,headers:a,etag:null,recordVersion:o,location:null,replayed:!1,rateLimit:{limit:null,remaining:null,reset:null}}}function R(e,n,t,o,a,i={}){return new L(e,new Headers({"Content-Type":"application/problem+json",...i}),{type:`https://docs.cube.nl/dmp-api/problems/${n}`,title:n.replace(/_/g," "),status:e,code:n,...a!==void 0?{reason:a}:{},detail:t,...o!==void 0?{errors:o}:{}})}function Eo(e,n){let t=e?.types[0];if((t==="integer"||t==="number")&&n!==""&&Number.isFinite(Number(n)))return Number(n);if(t==="boolean"){if(n==="1"||n==="true")return!0;if(n==="0"||n==="false")return!1}return n}function bt(e,n){return e==null?!1:typeof e=="boolean"&&typeof n!="boolean"?(e?"1":"0")===String(n)||String(e)===String(n):typeof e=="number"&&typeof n=="string"?String(e)===n:e===n||typeof e!="object"&&String(e)===String(n)}function B(e,n){if(e==null||n==null)return e==null?n==null?0:-1:1;if(typeof e=="number"&&typeof n=="number")return e-n;if(typeof e=="boolean"||typeof n=="boolean")return+(e===!0||e===1||e==="1")-+(n===!0||n===1||n==="1");let t=String(e),o=String(n);return t<o?-1:t>o?1:0}function K(e){return e==null?"":String(e)}function ye(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function vt(e){return e===void 0?e:JSON.parse(JSON.stringify(e))}function gn(e){return{name:e.name,actions:[...e.actions],fields:e.fields.map(n=>({name:n.name,type:n.type,format:null,nullable:n.nullable,readonly:n.readonly,enum:null,description:n.description??null})),summary:[...e.summary],filterable:[...e.filterable],sortable:[...e.sortable],groupable:[...e.groupable],aggregatable:Object.fromEntries(Object.entries(e.aggregatable).map(([n,t])=>[n,[...t]]))}}var kt="Voorbeeldgebruiker",se={invalidPrimary:"De hoofdkleur is geen geldige hexkleur; de neutrale standaardkleur wordt gebruikt.",invalidAccent:"De accentkleur is geen geldige hexkleur; er wordt een accentkleur afgeleid.",primaryLight:"De hoofdkleur is erg licht; witte tekst erop heeft weinig contrast.",primaryDarkened:"De hoofdkleur is voor tekst donkerder gemaakt om voldoende contrast te houden."},y={loading:"Laden\u2026",empty:"Er is hier nog niets te tonen.",error:"Er ging iets mis bij het laden.",retry:"Opnieuw proberen",forbidden:"Je hebt geen toegang tot deze gegevens.",signedOut:"Je bent niet ingelogd.",signIn:"Inloggen",signOut:"Uitloggen",signedIn:"Ingelogd",previewUser:kt,pages:"Pagina's",yes:"Ja",no:"Nee",emptyValue:"\u2014",quarter:(e,n)=>`K${e} ${n}`,week:(e,n)=>`week ${e}, ${n}`,monthYear:(e,n)=>`${e} '${n.slice(-2)}`,period:{label:"Periode","this-month":"Deze maand","12m":"Laatste 12 maanden","this-year":"Dit jaar",custom:"Zelf kiezen",from:"Van",to:"Tot en met",invalidRange:"De einddatum ligt v\xF3\xF3r de begindatum.",incompleteDate:"Vul bij Van en Tot en met een volledige datum in."},noData:"geen gegevens",comparedTo:"t.o.v. vorige periode",newValue:"nieuw",higher:"hoger",lower:"lager",incomplete:"Mogelijk niet compleet: er zijn meer groepen dan de DMP in \xE9\xE9n keer teruggeeft.",asTable:"Gegevens van de grafiek",tooManyGroups:"Te veel groepen om te tonen (meer dan 1000). Kies een kortere periode of een filter.",points:e=>`${e} ${e===1?"punt":"punten"}`,change:(e,n)=>`${e} procent ${n} dan de vorige periode`,search:"Zoeken",all:"Alle",min:"Vanaf",max:"Tot en met",previous:"Vorige",next:"Volgende",pageOf:(e,n,t)=>`Pagina ${e} van ${n} \xB7 ${t} rijen`,exportCsv:"Exporteren (CSV)",exporting:e=>`${e} rijen opgehaald\u2026`,chooseRow:"Kies een rij om de details te zien.",edit:"Bewerken",save:"Opslaan",cancel:"Annuleren",saved:"Opgeslagen.",formSaved:"Opgeslagen. Dank je wel!",another:"Nog een invullen",required:"Vul dit veld in.",requiredMark:" (verplicht)",notANumber:"Vul een getal in.",notAnInteger:"Vul een geheel getal in.",conflict:"Iemand anders heeft deze rij intussen gewijzigd. Laad de nieuwste versie en probeer het opnieuw.",reload:"Opnieuw laden",saveFailed:"Opslaan is niet gelukt. Probeer het opnieuw.",exportFailed:"Exporteren is niet gelukt. Probeer het opnieuw.",formInvalid:"Niet alles is goed ingevuld.",noWritableFields:"Dit formulier heeft geen invulbare velden.",calcFailed:"De berekening lukt niet met deze invoer.",moveTo:e=>`Verplaats naar ${e}`,moveFailed:"Verplaatsen lukte niet.",tryAgain:"Probeer het opnieuw.",changedMeanwhile:"Iemand anders heeft dit intussen gewijzigd; de nieuwste stand is geladen.",more:e=>`en nog ${e}`,noColumns:'Geef de kolommen op met <cube-column value="\u2026">.',emptyColumn:"Leeg",range:(e,n)=>`Kies een waarde van ${e} tot en met ${n}.`,atLeast:e=>`Kies een waarde van ${e} of meer.`,atMost:e=>`Kies een waarde van ten hoogste ${e}.`,step:e=>`Kies een waarde in stappen van ${e}.`,example:"Voorbeeld",exampleMissing:"Voorbeeld \u2014 bestaat nog niet",exampleNotSaved:"Voorbeeld \u2014 wordt niet opgeslagen",gaps:{screen:"Scherm",what:"Wat ontbreekt",type:"Soort gegeven",why:"Waarom",none:"Er ontbreekt niets: alles in dit voorstel bestaat al in de DMP.",types:{tekst:"Tekst",getal:"Getal",bedrag:"Bedrag",datum:"Datum",keuze:"Keuze","ja/nee":"Ja/nee"}},invalid:{json:(e,n)=>`${e}: ${n} is geen geldige JSON`,number:(e,n)=>`${e}: ${n} is geen geldig getal`,attribute:e=>`${e} mag geen attribuut zijn: geen inline stijl of script`,measure:e=>`"${e}" is geen geldige meting: gebruik count of count/sum/avg/min/max(veld)`,missing:(e,n)=>`${e}: ${n} ontbreekt`,value:(e,n,t)=>`${e}: ${n} "${t}" is geen geldige waarde`,formula:"cube-calc: formula moet een functie zijn",calcSingle:"cube-calc: formula gaf \xE9\xE9n waarde, maar er zijn meer cube-results; geef een object met hun namen",dateField:e=>`${e}: date-field ontbreekt bij period`,compare:e=>`${e}: compare werkt alleen samen met period`,periodSource:e=>`Geen periodekiezer gevonden voor "${e}"`,periodEnd:e=>`"${e}" is geen geldige einddatum van de periode`,notFilterable:(e,n,t)=>`${e}: ${n} noemt "${t}", maar daarop kan niet gefilterd worden`,selector:(e,n,t)=>`${e}: ${n} "${t}" is geen geldige selector`,lookup:e=>`"${e}" is geen geldige opzoeking: gebruik resource.veld`,dimension:e=>`"${e}" is geen geldige indeling: gebruik veld of veld.day/week/month/quarter/year`},theme:se};var Sn=["color-primary","color-primary-hover","color-primary-subtle","color-primary-text","color-on-primary","color-accent","color-on-accent","color-text","color-text-muted","color-bg","color-surface","color-border","color-focus","color-danger","color-success","color-warning","color-example-bg","color-example-text","color-series-1","color-series-2","color-series-3","color-series-4","color-series-5","color-series-6","radius","radius-small","font-family"],xn={primary_colour:"#475467",corners:"normaal",font:"system"},ve={inter:{family:"Inter",files:[{file:"inter.woff2",weight:"100 900",style:"normal"}]},"albert-sans":{family:"Albert Sans",files:[{file:"albert-sans.woff2",weight:"100 900",style:"normal"}]},"source-sans-3":{family:"Source Sans 3",files:[{file:"source-sans-3.woff2",weight:"200 900",style:"normal"}]},"nunito-sans":{family:"Nunito Sans",files:[{file:"nunito-sans.woff2",weight:"200 1000",style:"normal"}]},"ibm-plex-sans":{family:"IBM Plex Sans",files:[{file:"ibm-plex-sans.woff2",weight:"100 700",style:"normal"}]}},hn='system-ui, -apple-system, "Segoe UI", Roboto, sans-serif',bn="#f6f8fa";function ae(e){if(typeof e!="string")return null;let n=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e);if(!n||n[1]===void 0)return null;let t=n[1].toLowerCase();return t.length===3&&(t=[...t].map(o=>o+o).join("")),[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}function Rt(e){return"#"+e.map(n=>Math.max(0,Math.min(255,n)).toString(16).padStart(2,"0")).join("")}function yn(e){let[n,t,o]=e.map(a=>{let i=a/255;return i<=.03928?i/12.92:((i+.055)/1.055)**2.4});return .2126*n+.7152*t+.0722*o}function ke(e,n){let t=ae(e),o=ae(n);if(!t||!o)return 1;let a=yn(t),i=yn(o);return(Math.max(a,i)+.05)/(Math.min(a,i)+.05)}function St(e,n,t){let o=ae(e),a=ae(n);return Rt(o.map((i,r)=>Math.round(i*(1-t)+a[r]*t)))}function wn(e){return ke(e,"#ffffff")>=ke(e,"#000000")?"#ffffff":"#000000"}function Mo(e,n){let[t,o,a]=ae(e).map(k=>k/255),i=Math.max(t,o,a),r=Math.min(t,o,a),s=(i+r)/2,l=i-r,u=0,c=0;l!==0&&(c=l/(1-Math.abs(2*s-1)),i===t?u=(o-a)/l%6:i===o?u=(a-t)/l+2:u=(t-o)/l+4,u*=60),u=((u+n)%360+360)%360;let p=(1-Math.abs(2*s-1))*c,f=p*(1-Math.abs(u/60%2-1)),m=s-p/2,d=Math.floor(u/60)%6,[g,w,v]=[[p,f,0],[f,p,0],[0,p,f],[0,f,p],[f,0,p],[p,0,f]][d];return Rt([g,w,v].map(k=>Math.round((k+m)*255)))}function xt(e){let n=ae(e);return n?Rt(n):null}function Do(e){let n=[],t=xt(e.primary_colour);t===null&&(t=xt(xn.primary_colour),n.push({code:"invalid-primary",message:se.invalidPrimary}));let o=null;e.accent_colour!==void 0&&e.accent_colour!==null&&(o=xt(e.accent_colour),o===null&&n.push({code:"invalid-accent",message:se.invalidAccent})),o??(o=Mo(t,330)),ke(t,"#ffffff")<3&&n.push({code:"primary-light",message:se.primaryLight});let a=St(t,"#ffffff",.9),i=t;for(let d=0;d<=20&&(i=St(t,"#000000",d/20),!(ke(i,bn)>=4.5&&ke(i,a)>=4.5));d++);i!==t&&n.push({code:"primary-darkened-for-text",message:se.primaryDarkened});let r=wn(t),s={scherp:["0px","0px"],normaal:["6px","4px"],rond:["12px","8px"]},l=typeof e.corners=="string"&&Object.hasOwn(s,e.corners)?e.corners:"normaal",[u,c]=s[l],p=typeof e.font=="string"&&Object.hasOwn(ve,e.font)?e.font:"system",f=p==="system"?hn:`"${ve[p].family}", ${hn}`;return{tokens:{"color-primary":t,"color-primary-hover":St(t,r==="#ffffff"?"#000000":"#ffffff",.15),"color-primary-subtle":a,"color-primary-text":i,"color-on-primary":r,"color-accent":o,"color-on-accent":wn(o),"color-text":"#1f2328","color-text-muted":"#59636e","color-bg":"#ffffff","color-surface":bn,"color-border":"#d1d9e0","color-focus":i,"color-danger":"#b42318","color-success":"#067647","color-warning":"#b54708","color-example-bg":"#fef0c7","color-example-text":"#7a2e0e","color-series-1":t,"color-series-2":o,"color-series-3":"#0e9384","color-series-4":"#dc6803","color-series-5":"#7a5af8","color-series-6":"#475467",radius:u,"radius-small":c,"font-family":f},warnings:n}}var Lo=/^#[0-9a-f]{6}$/i,Fo=/^\d+(\.\d+)?(px|rem)$/,_o=/^data:image\/(svg\+xml|png);/,$o=/[;{}<>\\\u0000-\u001f]|\/\*/,vn=/["'()\\\s]/,kn=String.raw`(?:\s*"[^"]*"\s*|\s*'[^']*'\s*|[^"',]+)`,Oo=new RegExp(`^${kn}(?:,${kn})*$`);function Be(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Po(e,n){return typeof n!="string"?!1:e.startsWith("color-")?Lo.test(n):e.startsWith("radius")?Fo.test(n):n.length>0&&n.length<=200&&!$o.test(n)&&Oo.test(n)}function Ue(e,n,t){if(typeof e!="string"||e==="")return null;if(t&&_o.test(e))return vn.test(e)?null:e;try{let o=new URL(n),a=new URL(e,o);if((a.protocol==="https:"||a.protocol==="http:")&&a.origin===o.origin&&!vn.test(a.href))return a.href}catch{}return null}function No(e,n){let t=[];for(let o of Array.isArray(e)?e:[]){if(!Be(o))continue;let a=Ue(o.src,n,!1);if(a===null)continue;let i=typeof o.weight=="string"&&/^\d{1,4}( \d{1,4})?$/.test(o.weight)?o.weight:"400";t.push({src:a,weight:i,style:o.style==="italic"?"italic":"normal"})}return t}function ne(e,n){let t=e,o=xn,a=null,i=null;Be(t)&&(Object.hasOwn(t,"source")&&Be(t.source)?(o=t.source,a=Object.hasOwn(t,"tokens")?t.tokens:null,i=Object.hasOwn(t,"font_files")?t.font_files:null):Object.hasOwn(t,"primary_colour")&&(o=t));let{tokens:r,warnings:s}=Do(o);if(Be(a))for(let c of Sn)Object.hasOwn(a,c)&&Po(c,a[c])&&(r[c]=a[c]);let l=typeof o.font=="string"&&Object.hasOwn(ve,o.font)?o.font:null,u=No(i,n);return l!==null&&u.length===0&&!Array.isArray(i)&&(u=ve[l].files.flatMap(c=>{let p=Ue("cube-theme/"+c.file,n,!1);return p===null?[]:[{src:p,weight:c.weight,style:c.style}]})),{tokens:r,logo:Ue(o.logo,n,!0),logoDark:Ue(o.logo_dark,n,!0),fontFamily:l===null?null:ve[l].family,fontFiles:u,warnings:s}}function Tn(e){return":where(:root){"+Sn.map(n=>`--cube-${n}:${e.tokens[n]}`).join(";")+"}"}var He=null,Tt=new Set;function ze(){return He??(He=ne(null,"http://localhost/")),He}function Ct(e){He=e;for(let n of[...Tt])n(e)}function Ve(e){return Tt.add(e),()=>{Tt.delete(e)}}var Rn="1.1.0-rc.1";var Y=["number","integer","currency","percent"],Mn="nl-NL",jo=["day","week","month","quarter","year"],Ke=/^(\d{4})-(\d{2})-(\d{2})$/,Io=/^\s*-?(\d+\.?\d*|\.\d+)(e[+-]?\d+)?\s*$/i,Bo=/^(count|sum|avg|min|max)(?:\(([A-Za-z_][A-Za-z0-9_]*)\))?$/,Uo=/^([A-Za-z_][A-Za-z0-9_]*)(?:\.([a-z]+))?$/,Cn=new Map,An=new Map;function At(e){let n=JSON.stringify(e),t=Cn.get(n);return t===void 0&&(t=new Intl.NumberFormat(Mn,e),Cn.set(n,t)),t}function Et(e){let n=JSON.stringify(e),t=An.get(n);return t===void 0&&(t=new Intl.DateTimeFormat(Mn,e),An.set(n,t)),t}function Se(e){return typeof e=="number"?Number.isFinite(e)?e:null:typeof e=="bigint"||typeof e=="string"&&Io.test(e)?Number(e):null}function Ho(e){return e instanceof Date?Number.isNaN(e.getTime())?null:e:typeof e=="number"?Number.isFinite(e)?new Date(e):null:typeof e=="string"?$(e):null}function _(e,n,t={}){if(e==null||e==="")return y.emptyValue;switch(n){case"number":case"integer":case"currency":case"percent":{let o=Se(e);if(o===null)return String(e);let a=t.compact===!0?{notation:"compact"}:{};if(n==="currency")return At({style:"currency",currency:t.currency??"EUR",...a}).format(o);if(n==="percent")return At({style:"percent",maximumFractionDigits:1}).format(o);let i=n==="integer"?0:t.compact===!0?1:2;return At({maximumFractionDigits:i,...a}).format(o)}case"date":case"datetime":{let o=Ho(e);if(o===null)return String(e);let a={day:"numeric",month:"short",year:"numeric"};n==="datetime"&&Object.assign(a,{hour:"2-digit",minute:"2-digit"});let i=typeof e=="string"&&Ke.test(e);return t.timeZone!==void 0&&!i&&(a.timeZone=t.timeZone),Et(a).format(o)}case"boolean":return e===!0||e==="true"||e===1?y.yes:e===!1||e==="false"||e===0?y.no:String(e);default:return Array.isArray(e)?e.map(o=>_(o,"text")).join(", "):typeof e=="object"?JSON.stringify(e):String(e)}}function Mt(e,n,t={}){switch(n){case"year":return e;case"quarter":{let o=/^(\d{4})-Q([1-4])$/.exec(e);return o?.[1]!==void 0&&o[2]!==void 0?y.quarter(o[2],o[1]):e}case"week":{let o=/^(\d{4})-W(\d{2})$/.exec(e);return o?.[1]!==void 0&&o[2]!==void 0?y.week(Number(o[2]),o[1]):e}case"month":{let o=/^(\d{4})-(\d{2})$/.exec(e);if(o?.[1]===void 0||o[2]===void 0)return e;let a=Fn(Number(o[1]),Number(o[2])-1,1);return Et(t.short===!0?{month:"short"}:{month:"short",year:"numeric"}).format(a)}case"day":{let o=Ke.test(e)?$(e):null;return o===null?e:Et({day:"numeric",month:"short"}).format(o)}default:return e}}function Dn(e){let n=Bo.exec(e.trim()),t=n?.[1];if(t===void 0||t!=="count"&&n?.[2]===void 0)throw new TypeError(y.invalid.measure(e));return{fn:t,field:n?.[2]??null}}function qe(e){let n=Uo.exec(e.trim()),t=n?.[1],o=n?.[2];if(t===void 0||o!==void 0&&!jo.includes(o))throw new TypeError(y.invalid.dimension(e));return{field:t,truncation:o??null}}function Ln(e,n){if(e?.format==="date")return"date";if(e?.format==="date-time")return"datetime";if(e?.format==="currency")return"currency";switch(e?.type){case"integer":return"integer";case"number":return"number";case"boolean":return"boolean";case"string":return En(n)??"text"}return typeof n=="boolean"?"boolean":typeof n=="number"?Number.isInteger(n)?"integer":"number":En(n)??"text"}function En(e){return typeof e!="string"?null:Ke.test(e)?$(e)===null?null:"date":/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(e)&&!Number.isNaN(Date.parse(e))?"datetime":null}function U(e){let n=e.replace(/_id$/,"").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[_\-.]+/g," ").trim().toLowerCase();return n===""?e:n.charAt(0).toUpperCase()+n.slice(1)}function $(e){let n=Ke.exec(e);if(n?.[1]!==void 0&&n[2]!==void 0&&n[3]!==void 0){let o=Fn(Number(n[1]),Number(n[2])-1,Number(n[3]));return o.getMonth()===Number(n[2])-1?o:null}let t=Date.parse(e);return Number.isNaN(t)?null:new Date(t)}function Fn(e,n,t){let o=new Date(2e3,0,1);return o.setFullYear(e,n,t),o}function O(e){let n=t=>String(t).padStart(2,"0");return`${String(e.getFullYear()).padStart(4,"0")}-${n(e.getMonth()+1)}-${n(e.getDate())}`}var On={tekst:"text",getal:"number",bedrag:"currency",datum:"date",keuze:"text","ja/nee":"boolean"},Dt=e=>typeof e=="string"&&e!=="",Ft=(e,n)=>Object.prototype.hasOwnProperty.call(e,n);function _n(e){if(typeof e!="object"||e===null)return!1;let n=e,t=n.waarden;return typeof n.resource=="string"&&/^[a-z][a-z0-9_]*$/.test(n.resource)&&(n.veld===void 0||Dt(n.veld))&&typeof n.type=="string"&&Ft(On,n.type)&&(t===void 0||Array.isArray(t)&&t.every(o=>typeof o=="string"))&&(n.type!=="keuze"||Array.isArray(t)&&t.length>0)&&Dt(n.scherm)&&Dt(n.reden)}function Pn(e){if(!Array.isArray(e))return[];let n=e.filter(_n),t=e.filter(o=>!_n(o));return t.length>0&&console.warn(`cube-app.json ontbreekt: ${t.length} malformed entries ignored`,t),n}function $n(e){return On[e]}function Ge(e,n){if(e===null)return null;let t=i=>{let r=$n(i);return r==="date"||r==="currency"?r:null},o=n.flatMap(({resource:i,veld:r,type:s,waarden:l,reden:u})=>{if(i!==e.name||r===void 0||e.fields.some(p=>p.name===r))return[];let c=$n(s);return[{name:r,type:c==="boolean"?c:c==="number"||c==="currency"?"number":"string",format:t(s),nullable:!0,readonly:!1,enum:l??null,description:u}]}),a=o.map(i=>i.name);return{...e,fields:[...e.fields.map(i=>{let r=n.find(({resource:s,veld:l})=>s===e.name&&l===i.name);return r!==void 0&&i.format==null?{...i,format:t(r.type)}:i}),...o],summary:e.summary.length>0?[...e.summary,...a]:e.summary,filterable:[...e.filterable,...a],sortable:[...e.sortable,...a]}}function zo(e){let n=2166136261;for(let t=0;t<e.length;t++)n=Math.imul(n^e.charCodeAt(t),16777619)>>>0;return n}function Vo(e,n,t){let{veld:o,type:a,waarden:i}=e,r=zo(`${e.resource}.${o}.${String(n)}`);if(o!==void 0){let s=t.filter(l=>Ft(l,o)&&l[o]!==void 0);if(s.length>0)return s[r%s.length]?.[o]}switch(a){case"tekst":return`Voorbeeld ${r%100+1}`;case"getal":return r%1e3;case"bedrag":return r%1e5/100;case"datum":return O(new Date(2026,0,1+r%365));case"keuze":return i!==void 0&&i.length>0?i[r%i.length]:null;case"ja/nee":return r%2===0}}function Nn(e,n){let t=e?.fields;return Array.isArray(t)?t:t?.[n]}async function Lt(e,n,{filter:t={},sort:o=[]}){let a=[o].flat().join(",").split(",").map(u=>u.replace(/^[-+]/,"")),i=Object.fromEntries([...n.flatMap(Object.keys),...Object.keys(t),...a].filter(u=>u!=="").map(u=>[u,{type:typeof n.find(c=>c[u]!=null)?.[u]}])),r=new Map(n.map(u=>[String(u.id),u])),s=new J({[e]:{schema:{fields:i},rows:n}}),{data:l}=await s.resource(e).list({filter:t,sort:o,page:{size:200}});return l.map(u=>r.get(String(u.id)))}function _t(e,n,t,o){let{name:a}=e,i=new Map(n.filter(f=>f.resource===a&&f.veld!==void 0).map(f=>[f.veld,f])),r=f=>f.split(/[-+(),.]/).some(m=>i.has(m)),s=(f={})=>{let m=Nn(f,a),d=m?.filter(k=>!i.has(k)),g=Object.entries(f.filter??{}),w=[f.sort??[]].flat(),v=k=>({filter:Object.fromEntries(g.filter(([x])=>i.has(x)===k)),sort:w.filter(x=>r(x)===k)});return{live:{...f,...d&&{fields:d.includes("id")?d:[...d,"id"]},...v(!1)},local:v(!0),shown:k=>m===void 0||m.includes(k)}},l=(f,m,d=!1)=>{for(let[g,w]of i)(d||m(g))&&(!Ft(f,g)||f[g]==null)&&(f[g]=Vo(w,f.id,o))},u=async(f,{local:m,shown:d})=>{let g=f.data;g.forEach(w=>l(w,d,!0)),g.length>0&&(m.sort.length>0||Object.keys(m.filter).length>0)&&(g=await Lt(a,g,m));for(let w of g)for(let v of i.keys())d(v)||delete w[v];return{...f,data:g}},c=async(f,m)=>{let d=s(f);return u(await e.list(d.live,m),d)},p=async function*(f,m){let d=s(f);for await(let g of e.pages(d.live,m))yield await u(g,d)};return{...e,list:c,pages:p,async*all(f,m){for await(let d of p(f,m))yield*d.data},async get(f,m,d){let g=s(m),w=await e.get(f,g.live,d);return l(w.data,g.shown),w},aggregate:(f,m)=>[f.fn,f.group??[],Object.keys(f.filter??{})].flat().some(r)?t.resource(a).aggregate(f):e.aggregate(f,m)}}function jn(e,n){let t=d=>String(d.id),o=new Map,a=new Map,i=new Set,r=0,s=(d,g)=>({status:d,data:g,meta:null,headers:new Headers,etag:null,recordVersion:null,location:null,replayed:!1,rateLimit:{limit:null,remaining:null,reset:null}}),l=(d,g)=>{let w=Nn(g,n);return Object.fromEntries(Object.entries(d).filter(([v])=>w?.includes(v)??!0))},u=async(d,g={})=>{let{page:w}=d.meta,v=o.size>0?await Lt(n,[...o.values()].reverse(),g):[],k=new Set(v.map(t)),x=new Set(a.size>0?(await Lt(n,[...a.values()],g)).map(t):[]),P=new Set(d.data.map(t)),A=d.data.filter(E=>!i.has(t(E))&&(!o.has(t(E))||k.has(t(E)))).map(E=>o.get(t(E))??E),D=v.filter(E=>!x.has(t(E))&&!P.has(t(E))),S=w.total-[...x].filter(E=>!k.has(E)).length+D.length;return{...d,data:(w.number===1?[...D,...A]:A).map(E=>l(E,g)),meta:{...d.meta,page:{...w,total:S}}}},c=async(d,g,w)=>{let v=o.get(String(d));if(i.has(String(d))){let k=`No such ${n} record.`;throw new L(404,new Headers,{status:404,code:"not_found",detail:k})}return v===void 0?e.get(d,g,w):s(200,l(v,g))},p=async d=>{let{data:g}=await c(d);return o.has(String(d))||a.set(String(d),g),g},f=async()=>({...s(202,null),accepted:!0}),m=async function*(d,g){for await(let w of e.pages(d,g))yield await u(w,d)};return{...e,get:c,pages:m,operation:f,collectionOperation:f,list:async(d,g)=>u(await e.list(d,g),d),async*all(d,g){for await(let w of m(d,g))yield*w.data},async create(d){let g={...d,id:`voorbeeld-${++r}`};return o.set(g.id,g),s(201,{...g})},async update(d,g){let w=await p(d),v={...w,...g,id:w.id};return o.set(String(d),v),s(200,{...v})},async delete(d){return await p(d),o.delete(String(d)),i.add(String(d)),s(204,null)}}}var qo="./cube-app.config.json",Go="./cube-mock.json",Wo="./cube-app.json",Qo="./cube-theme.json",Jo={id:"preview",name:kt,scopes:[]},Bn=null,Un=null,H=null,$t=null,We=null,In=0;function Hn(e={}){let n=H!==null&&H===$t,t=++In,o=ei(e,()=>t===In);return H=o,$t=null,o.then(()=>{n&&H===o&&Zo()},()=>{H===o&&(H=null)}),o}function Yo(){return H!==null?H:(We??(We=Xo().then(()=>{if(We=null,H!==null)return H;let e=Hn();return $t=e,e})),We)}function Xo(){let e=globalThis;return new Promise(n=>{let t=()=>{setTimeout(n,0)};e.document===void 0||e.document.readyState==="complete"||e.addEventListener===void 0?t():e.addEventListener("load",t,{once:!0})})}function Zo(){let e=globalThis.document;if(e===void 0)return;let n=e.defaultView?.CustomEvent??CustomEvent;e.dispatchEvent(new n("cube-session-change"))}async function ei(e,n){let t=e.fetch??globalThis.fetch.bind(globalThis),o=e.pageUrl??qn(),[a,i]=await Promise.all([Qe(t,xe(qo,o)),ti(e,t,o)]);return n()&&Ct(i),a===null?ni(e,t,o):ri(si(a),e,t,o)}async function ti(e,n,t){try{if(e.theme===!1)return ne(null,t);let o=e.theme??Un;if(o!==null)return ne(o,t);let a=await Qe(n,xe(Qo,t));if(a!==null&&(a.theme!==1||typeof a.source!="object"||a.source===null))throw new TypeError("cube-theme.json is not a theme file.");return ne(a,t)}catch(o){return console.warn(`cube-theme.json could not be used, the neutral theme applies: ${String(o)}`),ne(null,t)}}async function zn(e,n,t){let o=e.mock??Bn??await Qe(n,xe(Go,t))??{},a=e.manifest===!1?null:e.manifest??await Qe(n,xe(Wo,t));return[o,a]}function Vn(e,n){let t=e==="wireframe",o=t?Pn(n?.ontbreekt):[];return{soort:e??null,gaps:o,simulatesWrites:t,isExample:(a,i)=>o.some(r=>r.resource===a&&(r.veld===void 0||r.veld===i))}}function Kn(e,n){let t=new Map;return e?a=>{let i=t.get(a)??jn(n(a),a);return t.set(a,i),i}:n}async function ni(e,n,t){let[o,a]=await zn(e,n,t),i=!0,r=()=>{if(!i)throw new L(401,new Headers({"Content-Type":"application/problem+json"}),{type:"https://docs.cube.nl/dmp-api/problems/token_invalid",title:"token invalid",status:401,code:"token_invalid",detail:"Unauthenticated."})},s=Vn(a?.soort,a),l=new J(o,a,r),u=new J(o,null,r),c=p=>s.isExample(p)?u:l;return{...s,mode:"preview",signInError:null,user:()=>i?{...Jo}:null,async signIn(){i=!0},async signOut(){i=!1},resource:Kn(s.simulatesWrites,p=>{let f=c(p),m=f.resource(p),d=f.describe(p)?.fields??[],g=s.gaps.filter(({resource:w,veld:v})=>w===p&&v!==void 0&&!d.some(k=>k.name===v));return g.length>0?_t(m,g,u,u.rows(p)):m}),schema:async p=>Ge(c(p).describe(p),s.gaps)}}async function ri(e,n,t,o){let a=e.dmpUrl.replace(/\/+$/,""),i=null,r=ai(n.tokenStorage==="memory"?_e():li(`cube-app.tokens.${e.clientId}`),g=>{i=g}),s=Qt({issuer:e.issuer??a,clientId:e.clientId,redirectUri:xe(e.redirectUri,o),scopes:e.scopes,fetch:t,tokenStore:r,...e.metadata!==void 0?{metadata:e.metadata}:{}}),l=Zt({baseUrl:e.apiUrl??`${a}/apps/api/v1`,auth:s,fetch:t}),u=null,c=null,[p,f]=e.soort==="wireframe"?await zn(n,t,o):[{},null],m=Vn(e.soort,f),d=new J(p);i=await r.get();try{await s.handleCallback()}catch(g){u=g instanceof Error?g:new Error(String(g))}return i===null&&u===null&&n.autoSignIn===!0&&await s.signIn(),{...m,mode:"live",get signInError(){return u},user:()=>i===null?null:oi(i),async signIn(){u=null,await s.signIn()},async signOut(){await s.signOut()},resource:Kn(m.simulatesWrites,g=>m.isExample(g)?d.resource(g):m.gaps.some(w=>w.resource===g)?_t(l.resources(g),m.gaps,d,d.rows(g)):l.resources(g)),async schema(g){if(m.isExample(g))return Ge(d.describe(g),m.gaps);c??(c=l.capabilities());try{let w=(await c).resources.find(v=>v.name===g);return w===void 0?null:Ge(gn(w),m.gaps)}catch(w){throw c=null,w}}}}function oi(e){let n=ii(e.accessToken),t=n?.sub,o=Array.isArray(n?.scopes)?n.scopes.map(String):null;return{id:typeof t=="string"||typeof t=="number"?String(t):null,name:null,scopes:o??(e.scope??"").split(" ").filter(a=>a!=="")}}function ii(e){let n=e.split(".")[1];if(n===void 0)return null;try{let t=n.replace(/-/g,"+").replace(/_/g,"/"),o=atob(t.padEnd(t.length+(4-t.length%4)%4,"=")),a=new TextDecoder().decode(Uint8Array.from(o,r=>r.charCodeAt(0))),i=JSON.parse(a);return i!==null&&typeof i=="object"?i:null}catch{return null}}function si(e){let n=["dmpUrl","clientId","redirectUri"].filter(o=>typeof e[o]!="string"||e[o]===""),t=e.scopes;if(typeof t=="string"||Array.isArray(t)&&t.every(o=>typeof o=="string")||n.push("scopes"),n.length>0)throw new TypeError(`cube-app.config.json is incomplete: ${n.join(", ")} missing or not a string.`);return e}async function Qe(e,n){let t;try{t=await e(n,{headers:{Accept:"application/json"},...typeof document<"u"?{cache:"no-store"}:{}})}catch{return null}if(t.status===404||t.status===410)return null;if(!t.ok)throw new Error(`${n} answered ${t.status}.`);try{let o=JSON.parse(await t.text());return o!==null&&typeof o=="object"&&!Array.isArray(o)?o:null}catch{return null}}function ai(e,n){return{async get(){let t=await e.get();return n(t),t},async set(t){await e.set(t),n(t)}}}function li(e){let n=(()=>{try{return globalThis.sessionStorage??null}catch{return null}})();return n===null?_e():{get(){try{let t=n.getItem(e);return t===null?null:JSON.parse(t)}catch{return null}},set(t){try{t===null?n.removeItem(e):n.setItem(e,JSON.stringify(t))}catch{}}}}function qn(){let e=globalThis;return e.document?.baseURI??e.location?.href??"http://localhost/"}function xe(e,n){return new URL(e,n).href}function ui(e){Bn=e}function ci(e){Un=e,Ct(ne(e,qn()))}var Je=Object.freeze({connect:Hn,ready:Yo,mock:ui,theme:ci,version:Rn,sdk:"1"});var Gn={"cube-state":["kind","message","retry"],"cube-app-shell":["name","logo","logo-alt"],"cube-page":["name","label"],"cube-field":["name","label","format","multiline","options","hidden"],"cube-period-picker":["default","label","today"],"cube-kpi":["resource","measure","label","format","currency","filter","period","date-field","compare"],"cube-chart":["resource","measure","by","kind","label","format","currency","filter","period","date-field","lookup","height","limit"],"cube-top":["resource","measure","by","limit","order","label","format","currency","filter","period","date-field","lookup"],"cube-table":["resource","fields","search","filters","sort","page-size","export","detail","filter","period","date-field"],"cube-detail":["resource","record-id","fields","editable"],"cube-form":["resource","fields","submit-label","success-text"],"cube-calc":["label"],"cube-input":["name","label","type","value","min","max","step","options"],"cube-result":["name","label","format","currency","emphasis"],"cube-board":["resource","status-field","title-field","fields","sort","filter","page-size"],"cube-column":["value","label"],"cube-gap-list":["scherm"]};var di="http://www.w3.org/2000/svg";function h(e,n,t={},...o){let a=e.createElement(n);for(let[i,r]of Object.entries(t))Wn(i,r===!0||typeof r=="string"),typeof r=="function"?a.addEventListener(i.replace(/^on/,""),r):r===!0?a.setAttribute(i,""):typeof r=="string"&&a.setAttribute(i,r);return Qn(e,a,o),a}function N(e,n,t={},...o){let a=e.createElementNS(di,n);for(let[i,r]of Object.entries(t))Wn(i,!0),a.setAttribute(i,String(r));return Qn(e,a,o),a}function Wn(e,n){let t=e.toLowerCase();if(t==="style"||n&&t.startsWith("on"))throw new TypeError(y.invalid.attribute(e))}function T(e){for(;e.firstChild!==null;)e.removeChild(e.firstChild)}function Qn(e,n,t){for(let o of t)typeof o=="string"?n.appendChild(e.createTextNode(o)):o!=null&&o!==!1&&n.appendChild(o)}var Ot=`
1
+ /*! @cube-nl/dmp-sdk 1.1.0-rc.3 cube-sdk.js (window.CubeApp) | MIT */
2
+ "use strict";(()=>{var to=Object.defineProperty;var no=(e,n,t)=>n in e?to(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var b=(e,n,t)=>no(e,typeof n!="symbol"?n+"":n,t);var P=class extends Error{constructor(t,o,a){let i=a!==null&&typeof a=="object"?a:{},r=oe(i.detail)??oe(i.error_description);super(r??`HTTP ${t}`);b(this,"status");b(this,"code");b(this,"reason");b(this,"type");b(this,"title");b(this,"detail");b(this,"errors");b(this,"retryAfter");b(this,"recordVersion");b(this,"allow");b(this,"headers");b(this,"body");this.name="DmpError",this.status=t,this.code=oe(i.code)??oe(i.error),this.reason=oe(i.reason),this.type=oe(i.type),this.title=oe(i.title),this.detail=r,this.errors=ro(i.errors)?i.errors:null,this.retryAfter=oo(o.get("Retry-After")),this.recordVersion=o.get("X-Dmp-Record-Version"),this.allow=o.has("Allow")?(o.get("Allow")??"").split(",").map(s=>s.trim()).filter(s=>s!==""):null,this.headers=o,this.body=a}get isProblem(){return this.code!==null}};function N(e){return e instanceof P}function oe(e){return typeof e=="string"?e:null}function ro(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function oo(e){if(e===null||e.trim()==="")return null;let n=Number(e);if(Number.isFinite(n))return n;let t=Date.parse(e);return Number.isNaN(t)?null:Math.max(0,Math.ceil((t-Date.now())/1e3))}function on(e){return{async getAccessToken(){let n=typeof e=="function"?await e():e;return n===void 0||n===""?null:n}}}var Ne="cube-dmp-sdk.pending-login";function sn(e){let n=e.fetch??globalThis.fetch.bind(globalThis),t=e.tokenStore??je(),o=e.pendingStore??lo(),a=(e.refreshLeewaySeconds??30)*1e3,i=typeof e.scopes=="string"?e.scopes:e.scopes.join(" "),r=e.metadata??{},s=io(r)?Promise.resolve({...r,issuer:r.issuer??e.issuer}):null,l=null,u=()=>(s??(s=so(e.issuer,n).then(f=>({...f,...r}),f=>{throw s=null,f})),s),c=async(f,d)=>{let{token_endpoint:g}=await u(),w=new URLSearchParams(f);e.clientSecret!==void 0&&w.set("client_secret",e.clientSecret);let v=await n(g,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/x-www-form-urlencoded"},body:w.toString()}),k=await an(v);if(!v.ok||k===null||typeof k!="object"||typeof k.access_token!="string")throw new P(v.status,v.headers,k);let S={accessToken:k.access_token,refreshToken:typeof k.refresh_token=="string"?k.refresh_token:null,expiresAt:typeof k.expires_in=="number"?Date.now()+k.expires_in*1e3:null,scope:typeof k.scope=="string"?k.scope:d};return await t.set(S),S},p=()=>(l??(l=(async()=>{let f=await t.get();if(f?.refreshToken==null)throw new TypeError("No refresh token: sign in again.");try{return await c({grant_type:"refresh_token",refresh_token:f.refreshToken,client_id:e.clientId},f.scope)}catch(d){throw d instanceof P&&d.status>=400&&d.status<500&&await t.set(null),d}})().finally(()=>{l=null})),l),m=async(f={})=>{let d=await u();if(!(d.code_challenge_methods_supported??[]).includes("S256"))throw new TypeError("The authorization server does not offer PKCE S256; this SDK will not sign in without it.");let g=rn(64),w=f.state??rn(32),v=ln(await crypto.subtle.digest("SHA-256",new TextEncoder().encode(g))),k={verifier:g,state:w,redirectUri:e.redirectUri,clientId:e.clientId};o.setItem(Ne,JSON.stringify(k));let S=new URL(d.authorization_endpoint);return S.search=new URLSearchParams({...f.extraParams,response_type:"code",client_id:e.clientId,redirect_uri:e.redirectUri,scope:i,state:w,code_challenge:v,code_challenge_method:"S256"}).toString(),S.toString()};return{discover:u,authorizationUrl:m,async signIn(f={}){let d=nn();if(d===null)throw new TypeError("signIn() needs a browser; use authorizationUrl() and redirect yourself.");d.assign(await m(f))},async handleCallback(f){let d=f??nn()?.href;if(d===void 0)throw new TypeError("handleCallback() needs the callback URL outside a browser.");let g=new URL(d),w=new URLSearchParams(g.search);if(!uo(g,e.redirectUri)||!w.has("code")&&!w.has("error"))return null;if(f===void 0){for(let k of["code","state","error","error_description","iss"])g.searchParams.delete(k);globalThis.history?.replaceState(null,"",g.pathname+g.search+g.hash)}let v=co(o.getItem(Ne));if(v===null||w.get("state")!==v.state)throw new TypeError("The state does not match: this callback does not belong to a sign-in started here.");if(o.removeItem(Ne),w.has("error"))throw new P(400,new Headers,{error:w.get("error")??"access_denied",error_description:w.get("error_description")??void 0});return c({grant_type:"authorization_code",code:w.get("code")??"",redirect_uri:v.redirectUri,client_id:v.clientId,code_verifier:v.verifier},i)},refresh:p,async getTokens(){return t.get()},async setTokens(f){await t.set(f)},async signOut(){await t.set(null),o.removeItem(Ne)},async getAccessToken(){let f=await t.get();if(f===null)return null;if(f.expiresAt!==null&&f.expiresAt-a<=Date.now()&&f.refreshToken!==null)try{return(await p()).accessToken}catch{return(await t.get())?.accessToken??null}return f.accessToken},async onUnauthorized(){if((await t.get())?.refreshToken==null)return!1;try{return await p(),!0}catch{return!1}}}}function io(e){return typeof e.authorization_endpoint=="string"&&typeof e.token_endpoint=="string"}async function so(e,n=globalThis.fetch.bind(globalThis)){let t=`${e.replace(/\/+$/,"")}/.well-known/oauth-authorization-server`,o=await n(t,{headers:{Accept:"application/json"}}),a=await an(o);if(!o.ok||a===null||typeof a!="object")throw new P(o.status,o.headers,a);return a}function je(e=null){let n=e;return{get:()=>n,set:t=>{n=t}}}function ao(){let e=new Map;return{getItem:n=>e.get(n)??null,setItem:(n,t)=>{e.set(n,t)},removeItem:n=>{e.delete(n)}}}function lo(){try{let e=globalThis.sessionStorage;if(e!==void 0)return e}catch{}return ao()}function nn(){let e=globalThis.location;return e!==void 0&&typeof e.assign=="function"?e:null}function uo(e,n){let t=new URL(n),o=a=>a.replace(/\/+$/,"")||"/";return e.origin===t.origin&&o(e.pathname)===o(t.pathname)}function co(e){if(e===null)return null;try{let n=JSON.parse(e);return typeof n.verifier=="string"&&typeof n.state=="string"&&typeof n.redirectUri=="string"&&typeof n.clientId=="string"?n:null}catch{return null}}async function an(e){let n=await e.text();if(n==="")return null;try{return JSON.parse(n)}catch{return n}}function rn(e){return ln(crypto.getRandomValues(new Uint8Array(e)))}function ln(e){let n=e instanceof Uint8Array?e:new Uint8Array(e),t="";for(let o of n)t+=String.fromCharCode(o);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}var po=new Set(["in","between"]);function ie(e,n={}){let t=new URLSearchParams;mo(t,e,n.fields),fo(t,n.filter),xe(t,"sort",n.sort),xe(t,"include",n.include),xe(t,"with_count",n.withCount),ho(t,n.has),xe(t,"fn",n.fn),xe(t,"group",n.group),n.page?.size!==void 0&&t.append("page[size]",String(n.page.size)),n.page?.number!==void 0&&t.append("page[number]",String(n.page.number));for(let[o,a]of Object.entries(n.params??{}))t.append(o,a);return t.toString().replace(/%5B/gi,"[").replace(/%5D/gi,"]").replace(/%2C/gi,",").replace(/%28/gi,"(").replace(/%29/gi,")")}function mo(e,n,t){if(t===void 0)return;let o=bo(t)?{[n]:t}:t;for(let[a,i]of Object.entries(o))i.length>0&&e.append(`fields[${a}]`,i.join(","))}function fo(e,n){for(let[t,o]of Object.entries(n??{})){if(Array.isArray(o))throw new TypeError(`filter.${t}: a bare list names no operator and cube/api refuses it. Write { in: [...] } (or { between: [from, to] }).`);if(o==null)throw new TypeError(`filter.${t}: write { is: 'null' } or { is: 'not_null' } to filter on null.`);if(typeof o!="object"){e.append(`filter[${t}]`,vt(o));continue}for(let[a,i]of Object.entries(o))i!==void 0&&e.append(`filter[${t}][${a}]`,go(t,a,i))}}function go(e,n,t){if(t===null){if(n!=="is")throw new TypeError(`filter.${e}.${n}: null is only meaningful under 'is'.`);return"null"}if(Array.isArray(t)){if(!po.has(n))throw new TypeError(`filter.${e}.${n}: takes one value; only 'in' and 'between' take a list.`);return t.map(vt).join(",")}return vt(t)}function ho(e,n){for(let[t,o]of Object.entries(n??{}))o===!0?e.append(`has[${t}]`,"1"):typeof o=="number"?e.append(`has[${t}][min]`,String(o)):(o.min!==void 0&&e.append(`has[${t}][min]`,String(o.min)),o.max!==void 0&&e.append(`has[${t}][max]`,String(o.max)))}function xe(e,n,t){if(t===void 0)return;let o=typeof t=="string"?t:t.filter(a=>a!=="").join(",");o!==""&&e.append(n,o)}function vt(e){return typeof e=="boolean"?e?"1":"0":String(e)}function bo(e){return Array.isArray(e)}var yo=/^[a-z][a-z0-9_]*$/;function St(e){let n=e.baseUrl.replace(/\/+$/,""),t=e.fetch??globalThis.fetch.bind(globalThis),o=e.auth===void 0?null:typeof e.auth=="string"||typeof e.auth=="function"?on(e.auth):e.auth,a=e.cache??(typeof document<"u"?"no-cache":void 0),i=async(s,l,{query:u,body:c,headers:p={},signal:m}={})=>{let f=`${n}${l.startsWith("/")?l:`/${l}`}${u?`?${u}`:""}`,d=async()=>{let k=o===null?null:await o.getAccessToken(),S={method:s,headers:{Accept:"application/json",...e.headers,...k!==null?{Authorization:`Bearer ${k}`}:{},...c!==void 0?{"Content-Type":"application/json"}:{},...p}};c!==void 0&&(S.body=JSON.stringify(c)),a!==void 0&&(S.cache=a),m!==void 0&&(S.signal=m);let R=Date.now(),L=await t(f,S);return e.onResponse?.({method:s,url:f,status:L.status,ms:Date.now()-R}),L},g=await d();g.status===401&&o?.onUnauthorized!==void 0&&await o.onUnauthorized()&&(await g.body?.cancel().catch(()=>{}),g=await d());let w=await vo(g);if(!g.ok)throw new P(g.status,g.headers,w);let v=ko(w)?w:null;return{status:g.status,data:v!==null?v.data:w,meta:v?.meta??null,headers:g.headers,etag:g.headers.get("ETag"),recordVersion:g.headers.get("X-Dmp-Record-Version"),location:g.headers.get("Location"),replayed:g.headers.get("Idempotency-Replayed")==="true",rateLimit:So(g.headers)}};return{async capabilities(s={}){let l=(await i("GET","/_capabilities",Be({},s))).data;return{...l,resources:l.resources.map(wo)}},resources:s=>{if(!yo.test(s))throw new TypeError(`'${s}' is not a resource name: cube/api names match [a-z][a-z0-9_]*.`);let l=`/${s}`,u=d=>{let g=String(d);if(g==="")throw new TypeError(`${s}: an empty id would address the collection, not a record.`);if(dn(g))throw new TypeError(`${s}: '${g}' is not an id: it would address another path, not a record.`);return`${l}/${encodeURIComponent(g)}`},c=d=>d===void 0?"":ie(s,{fields:d}),p=async(d={},g={})=>await i("GET",l,Be({query:ie(s,d)},g)),m=async function*(d={},g={}){let w=d.page?.number??1;for(;;){let v=await p({...d,page:{...d.page,number:w}},g);yield v;let k=v.meta.page;if(k==null||k.number>=k.pages||v.data.length===0)return;w=k.number+1}},f=async(d,g,w)=>{let v=await i("POST",d,{query:c(w.fields),body:g??{},headers:Ie(w)});return{...v,data:v.status===204?null:v.data,accepted:v.status===202}};return{name:s,list:p,pages:m,async*all(d={},g={}){for await(let w of m(d,g))yield*w.data},get:(d,g={},w={})=>i("GET",u(d),Be({query:ie(s,g)},w)),aggregate:(d,g={})=>i("GET",`${l}/_aggregate`,Be({query:ie(s,d)},g)),create:(d,g={})=>i("POST",l,{query:c(g.fields),body:d,headers:Ie(g)}),update:(d,g,w={})=>i("PATCH",u(d),{query:c(w.fields),body:g,headers:Ie(w)}),delete:async(d,g={})=>({...await i("DELETE",u(d),{headers:Ie(g)}),data:null}),operation:(d,g,w,v={})=>f(`${u(d)}/${encodeURIComponent(un(g))}`,w,v),collectionOperation:(d,g,w={})=>f(`${l}/_operations/${encodeURIComponent(un(d))}`,g,w)}},request:i}}function wo(e){return{...e,operations:(e.operations??[]).map(n=>({...n,input:kt(n.input)})),aggregatable:kt(e.aggregatable),relations:kt(e.relations)}}function kt(e){return Array.isArray(e)||e===void 0||e===null?{}:e}function cn(){return crypto.randomUUID()}function un(e){if(e===""||e.startsWith("_"))throw new TypeError(`'${e}' is not an operation name: the '_' namespace is reserved by the API.`);if(dn(e))throw new TypeError(`'${e}' is not an operation name: it would address another path.`);return e}function dn(e){return e==="."||e===".."}function Ie(e){let n={};if(e.idempotencyKey!==void 0&&(n["Idempotency-Key"]=e.idempotencyKey),e.ifMatch!==void 0){if(e.ifMatch.startsWith("W/"))throw new TypeError("ifMatch takes recordVersion (X-Dmp-Record-Version), not the weak ETag.");n["If-Match"]=e.ifMatch}return n}function Be(e,n){return n.signal===void 0?e:{...e,signal:n.signal}}async function vo(e){let n=await e.text();if(n==="")return null;try{return JSON.parse(n)}catch{return n}}function ko(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)&&"data"in e}function So(e){let n=t=>{let o=e.get(t);return o===null||o===""||!Number.isFinite(Number(o))?null:Number(o)};return{limit:n("X-RateLimit-Limit"),remaining:n("X-RateLimit-Remaining"),reset:n("X-RateLimit-Reset")}}var pn=/^[a-z][a-z0-9_]*$/,mn=["eq","neq","gt","gte","lt","lte","in","like","ilike","is","between"],xo=[[">=","gte"],["<=","lte"],["<>","neq"],[">","gt"],["<","lt"],["=","eq"]],Et=["count","sum","avg","min","max"],fn=["day","week","month","quarter","year"],xt=20,Tt=5,gn=1e3,Ct=200,To=50,At=200,Co="1.0",te=class{constructor(n,t=null,o=()=>{}){b(this,"manifest",t);b(this,"guard",o);b(this,"tables",new Map);for(let[a,i]of Object.entries(Ao(n))){if(typeof i!="object"||i===null||Array.isArray(i))continue;let r=typeof i.schema?.name=="string"&&i.schema.name!==""?i.schema.name:a;pn.test(r)&&this.tables.set(r,Ro(r,i))}}rows(n){return this.tables.get(n)?.rows??[]}resourceNames(){return[...this.tables.keys()]}describe(n){let t=this.tables.get(n);return t===void 0?null:{name:n,actions:[...t.actions],fields:[...t.fields.values()].map(o=>{let a=t.choices.get(o.name);return{name:o.name,type:o.types.join("|"),format:o.format,nullable:o.nullable,readonly:!t.writable.has(o.name),enum:a===void 0?null:a.map(String),description:o.description}}),summary:[...t.summary],filterable:[...t.filterable],sortable:[...t.fields.keys()],groupable:[...t.groupable],aggregatable:Object.fromEntries([...t.aggregatable].map(([o,a])=>[o,a.filter(i=>i!=="count")]))}}resource(n){if(!pn.test(n))throw new TypeError(`'${n}' is not a resource name: cube/api names match [a-z][a-z0-9_]*.`);let t=(i,r)=>Promise.resolve().then(()=>r(this.authorize(n,i))),o=(i={})=>t("list",r=>Do(r,i)),a=async function*(i={}){let r=i.page?.number??1;for(;;){let s=await o({...i,page:{...i.page,number:r}});if(yield s,s.meta.page.number>=s.meta.page.pages||s.data.length===0)return;r=s.meta.page.number+1}};return{name:n,list:o,pages:a,async*all(i={}){for await(let r of a(i))yield*r.data},get:(i,r={})=>t("get",s=>Mo(s,i,r)),aggregate:i=>t("aggregate",r=>Po(r,i)),create:(i,r={})=>t("create",s=>Bo(s,i,r)),update:(i,r,s={})=>t("update",l=>Uo(l,i,r,s)),delete:(i,r={})=>t("delete",s=>Ho(s,i,r)),operation:(i,r,s,l)=>t("get",u=>{throw He(u,i),yn(r)}),collectionOperation:i=>t("list",()=>{throw yn(i)})}}authorize(n,t){this.guard();let o=this.tables.get(n);if(o===void 0)throw M(404,"not_found",`Unknown API resource [${n}].`);let a=this.manifest?.uses;if(a!==void 0&&!(a[n]??[]).includes(t))throw M(403,"client_scope_exceeded",`This app may not ${t} '${n}': add it to "uses" in cube-app.json.`);return o}};function Ao(e){let n=e.resources;return Object.keys(e).length===1&&Te(n)&&!("rows"in n)&&!("schema"in n)?n:e}function Ro(e,n){let t=n.schema??{},o=(n.rows??[]).map(p=>Mt(p)),a=new Map,i=Array.isArray(t.fields)?t.fields.map(p=>[p.name,p]):Object.entries(t.fields??{});for(let[p,m]of i)a.set(p,Eo(p,m));for(let p of a.size===0?o:[])for(let m of Object.keys(p))a.has(m)||a.set(m,{name:m,types:[],nullable:!0,format:null,description:null});let r=[...a.keys()],s=(Te(t.choices)?Object.entries(t.choices):[]).filter(p=>Te(p[1])&&Array.isArray(p[1].values)),l=new Set(["id",...t.readonly??[],...i.filter(([,p])=>p.readonly===!0).map(([p])=>p),...s.filter(([,p])=>p.writable===!1).map(([p])=>p)]),u=new Map;for(let[p,m]of i)Array.isArray(m.enum)&&u.set(p,m.enum);for(let[p,m]of s)u.set(p,m.values);let c=p=>Array.isArray(p)?p.filter(m=>typeof m=="string"&&a.has(m)):null;return{name:e,actions:Array.isArray(t.actions)?t.actions.filter(p=>typeof p=="string"):["list","get","create","update","delete"],fields:a,filterable:c(t.filters)??r,groupable:c(t.groupable)??r,aggregatable:new Map(Te(t.aggregatable)?Object.entries(t.aggregatable).filter(([p,m])=>a.has(p)&&Array.isArray(m)).map(([p,m])=>[p,[...m]]):r.map(p=>[p,[...Et]])),choices:u,writable:new Set(r.filter(p=>!l.has(p))),summary:(c(t.summary_fields)??[]).length>0?c(t.summary_fields):r,rows:o,versions:new Map(o.map(p=>[Q(p.id),1])),replays:new Map}}function Eo(e,n){let t=n.type,o=typeof t=="string"?t.split("|"):Array.isArray(t)?[...t]:[];return{name:e,types:o.filter(a=>a!=="null"&&a!==""),nullable:n.nullable===!0||o.includes("null"),format:typeof n.format=="string"?n.format:null,description:typeof n.description=="string"?n.description:null}}function Ce(e,n){return new URLSearchParams(ie(e.name,n))}function Do(e,n){let t=Ce(e,n),o=Ue(e,t),a=vn(e,t),i=Oo(e,t),{size:r,number:s}=$o(t),l=wn(e,t),u=e.rows.filter(f=>a.every(d=>kn(e,f,d)));i.length>0&&(u=[...u].sort((f,d)=>{for(let{field:g,descending:w}of i){let v=V(f[g],d[g]);if(v!==0)return w?-v:v}return 0}));let c=u.length,p=u.slice((s-1)*r,s*r).map(f=>ze(f,o)),m={size:r,number:s,total:c,pages:Math.max(1,Math.ceil(c/r))};return{...de(200,p,ce(e,m,l)),meta:{...ce(e,m,l),page:m}}}function Mo(e,n,t){let o=Ce(e,t),a=Ue(e,o),i=wn(e,o),r=He(e,n);return de(200,ze(r,a),ce(e,null,i),Ve(e,r))}function Ue(e,n){let t=`fields[${e.name}]`,o=n.get(t);if(o===null||o==="")return e.summary;let a=o.split(",").map(r=>r.trim()),i=a.filter(r=>!e.fields.has(r));if(i.length>0)throw M(422,"query_invalid",`Unknown ${t}: ${i.join(", ")}.`,{[t]:[`Allowed values: ${[...e.fields.keys()].join(", ")}.`]});return a}function wn(e,n){let t=o=>(n.get(o)??"").split(",").filter(a=>a!=="");return[...new Set([...t("include"),...t("with_count")])]}function vn(e,n){let t=[],o=[];n.forEach((a,i)=>o.push([i,a]));for(let[a,i]of o){let r=/^filter\[([^\]]+)\](?:\[([^\]]+)\])?$/.exec(a);if(r===null)continue;let s=r[1];if(!e.filterable.includes(s))throw M(422,"query_invalid",`Unknown filter: ${s}.`,{filter:[`Allowed values: ${e.filterable.join(", ")}.`]},"not_filterable");t.push(r[2]===void 0?Lo(s,i):Fo(s,r[2],i))}if(t.length>xt)throw M(422,"query_invalid",`A query takes at most ${xt} filters.`,{filter:[`Sent ${t.length}; the limit is ${xt}.`]});return t}function Lo(e,n){for(let[t,o]of xo)if(n.startsWith(t))return{field:e,operator:o,value:n.slice(t.length)};return{field:e,operator:"eq",value:n}}function Fo(e,n,t){if(!mn.includes(n))throw M(422,"query_invalid",`Unknown filter operator: ${n}.`,{filter:[`Allowed operators: ${mn.join(", ")}.`]});if(n==="between"&&t.split(",").length!==2)throw M(422,"query_invalid",`filter[${e}][between] takes exactly 2 values.`,{filter:[`Write filter[${e}][between]=low,high. Received ${t.split(",").length} value(s).`]});if(n==="in"&&t.split(",").length>Ct)throw M(422,"query_invalid",`filter[${e}][in] takes at most ${Ct} values.`,{filter:[`Sent ${t.split(",").length}; the limit is ${Ct}.`]});if(n==="is"&&t!=="null"&&t!=="not_null")throw M(422,"query_invalid",`filter[${e}][is] takes null or not_null.`,{filter:[`Received: ${t}.`]});return{field:e,operator:n,value:t}}function kn(e,n,t){let o=n[t.field],a=i=>qo(e.fields.get(t.field),i.trim());switch(t.operator){case"eq":return Rt(o,a(t.value));case"neq":return o!=null&&!Rt(o,a(t.value));case"gt":return o!=null&&V(o,a(t.value))>0;case"gte":return o!=null&&V(o,a(t.value))>=0;case"lt":return o!=null&&V(o,a(t.value))<0;case"lte":return o!=null&&V(o,a(t.value))<=0;case"in":return t.value.split(",").some(i=>Rt(o,a(i)));case"between":{let[i,r]=t.value.split(",").map(a);return o!=null&&V(o,i)>=0&&V(o,r)<=0}case"like":case"ilike":return typeof o=="string"&&_o(o,t.value);case"is":return t.value==="null"?o==null:o!=null;default:return!1}}function _o(e,n){let t=n.split("%").map(o=>o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join(".*");return new RegExp(t,"iu").test(e)}function Oo(e,n){let t=n.get("sort");if(t===null||t==="")return[];let o=t.split(",").map(i=>i.trim()).filter(i=>i!=="").map(i=>({field:i.replace(/^[-+]/,""),descending:i.startsWith("-")})),a=o.map(i=>i.field).filter(i=>!e.fields.has(i));if(a.length>0)throw M(422,"query_invalid",`Unknown sort: ${a.join(", ")}.`,{sort:[`Allowed values: ${[...e.fields.keys()].join(", ")}.`]},"not_sortable");return o}function $o(e){let n=o=>{let a=e.get(o);if(a===null||a==="")return null;if(!/^\d+$/.test(a))throw M(422,"query_invalid",`${o} must be a positive integer.`,{[o]:["Expected a positive integer."]});return Number(a)},t=n("page[size]")??To;if(t>At)throw M(422,"cardinality_exceeded",`page[size] may not exceed ${At}.`,{"page.size":[`The maximum page size is ${At}.`]});return{size:Math.max(1,t),number:Math.max(1,n("page[number]")??1)}}function Po(e,n){let t=Ce(e,n),o=(t.get("fn")??"").trim();if(o==="")throw M(422,"query_invalid","fn is required: name at least one aggregation function.",{fn:[`Expected e.g. fn=count or fn=sum(field). ${Dt(e)}`]});let a=o.split(",").map(f=>f.trim()),i=a.map(f=>No(e,f));hn(a,"fn");let r=(t.get("group")??"").trim(),s=r===""?[]:r.split(",").map(f=>f.trim());if(s.length>Tt)throw M(422,"cardinality_exceeded",`group may not exceed ${Tt} dimensions, ${s.length} given.`,{group:[`Use at most ${Tt} dimensions.`]});let l=s.map(f=>jo(e,f));hn(s,"group");let u=vn(e,t),c=new Map;for(let f of e.rows.filter(d=>u.every(g=>kn(e,d,g)))){let d={};for(let[v,k]of s.entries())d[k]=l[v](f);let g=JSON.stringify(Object.values(d)),w=c.get(g)??{key:d,rows:[]};w.rows.push(f),c.set(g,w)}if(s.length===0&&c.size===0&&c.set("[]",{key:{},rows:[]}),c.size>gn)throw M(422,"cardinality_exceeded","The grouping produces more groups than the configured maximum.",{groepen:["The grouping produces more groups than the configured maximum.",`Allowed values: groepeer grover, of filter eerst; maximaal ${gn} groepen.`]},"too_many_groups");let m=[...c.values()].sort((f,d)=>{for(let g of s){let w=V(f.key[g],d.key[g]);if(w!==0)return w}return 0}).map(({key:f,rows:d})=>{let g={...f};for(let[w,v]of a.entries())g[v]=i[w](d);return g});return de(200,m,{...ce(e,null,[]),groups:m.length})}function hn(e,n){let t=[...new Set(e.filter((o,a)=>e.indexOf(o)!==a))];if(t.length>0)throw M(422,"query_invalid",`Duplicate ${n} entry: ${t.join(", ")}.`,{[n]:[`List each ${n} entry once.`]})}function Dt(e){return e.aggregatable.size===0?"This resource has no aggregatable fields; only bare count is available.":`Aggregatable fields: ${[...e.aggregatable.keys()].join(", ")}.`}function No(e,n){let t=/^([a-z]+)\(([a-z0-9_]+)\)$/.exec(n);if(t===null&&!/^[a-z]+$/.test(n))throw M(422,"query_invalid",`Unparseable fn entry: ${n}.`,{fn:["Expected `count` or `function(field)`, e.g. sum(field)."]});let o=t===null?n:t[1],a=t===null?null:t[2];if(!Et.includes(o))throw M(422,"query_invalid",`Unknown aggregation function: ${o}.`,{fn:[`Allowed values: ${Et.join(", ")}.`]});if(a===null){if(o!=="count")throw M(422,"query_invalid",`${o} must be applied to a field, e.g. ${o}(field).`,{fn:[Dt(e)]});return r=>r.length}let i=e.aggregatable.get(a);if(i===void 0)throw M(422,"query_invalid",`Unknown aggregatable field: ${a}.`,{fn:[Dt(e)]});if(!i.includes(o))throw M(422,"query_invalid",`${o} is not allowed on ${a}.`,{fn:[`Allowed functions for ${a}: ${i.join(", ")}.`]});return r=>{let s=r.map(u=>u[a]).filter(u=>u!=null),l=s.map(Number).filter(u=>Number.isFinite(u));switch(o){case"count":return r.length;case"sum":return l.length===0?null:l.reduce((u,c)=>u+c,0);case"avg":return l.length===0?null:l.reduce((u,c)=>u+c,0)/l.length;case"min":return s.length===0?null:s.reduce((u,c)=>V(c,u)<0?c:u);default:return s.length===0?null:s.reduce((u,c)=>V(c,u)>0?c:u)}}}function jo(e,n){let t=n.split(".");if(t.length>2)throw M(422,"query_invalid",`Unparseable group entry: ${n}.`,{group:["Expected `field` or `field.unit`, e.g. published_at.month."]});let[o,a]=t;if(!e.groupable.includes(o))throw M(422,"query_invalid",`Unknown group: ${o}.`,{group:[`Allowed values: ${e.groupable.join(", ")}.`]},"not_groupable");if(a===void 0)return i=>i[o]??null;if(!fn.includes(a))throw M(422,"query_invalid",`Unknown truncation unit: ${a}.`,{group:[`Allowed values: ${fn.join(", ")}.`]});return i=>Io(i[o],a)}function Io(e,n){let t=typeof e=="string"?/^(\d{4})-(\d{2})-(\d{2})/.exec(e):null;if(t===null)return null;let[o,a,i]=[Number(t[1]),Number(t[2]),Number(t[3])],r=new Date(Date.UTC(o,a-1,i));if(r.getUTCFullYear()!==o||r.getUTCMonth()!==a-1||r.getUTCDate()!==i)return null;switch(n){case"day":return t[0];case"week":{let s=new Date(r.getTime()+(3-(r.getUTCDay()+6)%7)*864e5),l=s.getUTCFullYear(),u=1+Math.floor((s.getTime()-Date.UTC(l,0,1))/(7*864e5));return`${l}-W${String(u).padStart(2,"0")}`}case"month":return t[0].slice(0,7);case"quarter":return`${t[1]}-Q${Math.ceil(a/3)}`;case"year":return t[1];default:return null}}function Bo(e,n,t){let o=t.fields===void 0?e.summary:Ue(e,Ce(e,{fields:t.fields})),a=JSON.stringify([n,t.fields??null]);if(t.idempotencyKey!==void 0){let l=e.replays.get(t.idempotencyKey);if(l!==void 0){if(l.body!==a)throw M(422,"validation_failed","This Idempotency-Key was already used with a different request body. Use a new key, or resend the original body.");return{...l.response,replayed:!0}}}let i=Sn(e,n),r={id:Ko(e),...i};for(let l of e.fields.keys())l in r||(r[l]=null);e.rows.push(r),e.versions.set(Q(r.id),1);let s=de(201,ze(r,o),ce(e,null,[]),Ve(e,r));return t.idempotencyKey!==void 0&&e.replays.set(t.idempotencyKey,{body:a,response:s}),s}function Uo(e,n,t,o){let a=o.fields===void 0?e.summary:Ue(e,Ce(e,{fields:o.fields})),i=He(e,n);return xn(e,i,o.ifMatch),Object.assign(i,Sn(e,t)),e.versions.set(Q(i.id),(e.versions.get(Q(i.id))??1)+1),de(200,ze(i,a),ce(e,null,[]),Ve(e,i))}function Ho(e,n,t){let o=He(e,n);return xn(e,o,t.ifMatch),e.rows.splice(e.rows.indexOf(o),1),e.versions.delete(Q(o.id)),de(204,null,null)}function Sn(e,n){let t=[...e.writable],o=t.length===0?"This resource declares no writable fields.":`Writable fields: ${t.join(", ")}.`;if(!Te(n)||Object.keys(n).length===0)throw M(422,"validation_failed","The request body must be a JSON object naming at least one writable field.",{body:[o]});let a=Object.keys(n).filter(r=>!e.writable.has(r));if(a.length>0)throw M(422,"query_invalid",`Unknown or read-only fields: ${a.join(", ")}.`,Object.fromEntries(a.map(r=>[r,[o]])));let i={};for(let[r,s]of Object.entries(n)){let l=e.fields.get(r),u=Vo(l,s)??zo(e,l,r,s);u!==null&&(i[r]=[u])}if(Object.keys(i).length>0)throw M(422,"validation_failed","The request body failed validation.",i);return Mt(n)}function zo(e,n,t,o){let a=e.choices.get(t);return a===void 0||o===null&&n?.nullable===!0||a.includes(o)?null:`The selected ${t.replace(/_/g," ")} is invalid.`}function Vo(e,n){return e===void 0||e.types.length!==1?null:n===null?e.nullable?null:bn(e):(()=>{switch(e.types[0]){case"string":return typeof n=="string";case"integer":return typeof n=="number"&&Number.isInteger(n)||typeof n=="string"&&/^[+-]?\d+$/.test(n.trim());case"number":return typeof n=="number"&&Number.isFinite(n)||typeof n=="string"&&n.trim()!==""&&Number.isFinite(Number(n));case"boolean":return[!0,!1,0,1,"0","1"].includes(n);case"array":case"object":return typeof n=="object";default:return!0}})()?null:bn(e)}function bn(e){return`The ${e.name.replace(/_/g," ")} field must be ${{string:"a string",integer:"an integer",number:"a number",boolean:"true or false",array:"an array",object:"an array"}[e.types[0]]??"valid"}.`}function xn(e,n,t){if(t===void 0)return;if(t.startsWith("W/"))throw new TypeError("ifMatch takes recordVersion (X-Dmp-Record-Version), not the weak ETag.");let o=Ve(e,n);if(t!==o)throw M(409,"conflict","The record changed since the version you sent.",void 0,void 0,{"X-Dmp-Record-Version":o})}function Ko(e){let n=e.rows.map(t=>t.id);return n.length>0&&n.every(t=>typeof t=="string")&&n.some(t=>!/^\d+$/.test(t))?crypto.randomUUID():n.reduce((t,o)=>Math.max(t,Number(o)||0),0)+1}function He(e,n){let t=Q(n);if(t===""||t==="."||t==="..")throw new TypeError(`${e.name}: '${t}' is not an id.`);let o=e.rows.find(a=>Q(a.id)===t);if(o===void 0)throw M(404,"not_found",`No such ${e.name} record.`);return o}function yn(e){return M(404,"not_found",`No such operation [${e}]. The preview runs no custom operations.`)}function ze(e,n){let t={};for(let o of n)t[o]=o in e?Mt(e[o]):null;return t}function Ve(e,n){return`"preview-${Q(n.id)}-${e.versions.get(Q(n.id))??1}"`}function ce(e,n,t){return{resource:e.name,contract:Co,page:n,groups:null,omitted:t,pruned:[],forbidden_fields:[]}}function de(e,n,t,o=null){let a=new Headers({"X-Dmp-Preview":"true"});return o!==null&&a.set("X-Dmp-Record-Version",o),{status:e,data:n,meta:t,headers:a,etag:null,recordVersion:o,location:null,replayed:!1,rateLimit:{limit:null,remaining:null,reset:null}}}function M(e,n,t,o,a,i={}){return new P(e,new Headers({"Content-Type":"application/problem+json",...i}),{type:`https://docs.cube.nl/dmp-api/problems/${n}`,title:n.replace(/_/g," "),status:e,code:n,...a!==void 0?{reason:a}:{},detail:t,...o!==void 0?{errors:o}:{}})}function qo(e,n){let t=e?.types[0];if((t==="integer"||t==="number")&&n!==""&&Number.isFinite(Number(n)))return Number(n);if(t==="boolean"){if(n==="1"||n==="true")return!0;if(n==="0"||n==="false")return!1}return n}function Rt(e,n){return e==null?!1:typeof e=="boolean"&&typeof n!="boolean"?(e?"1":"0")===String(n)||String(e)===String(n):typeof e=="number"&&typeof n=="string"?String(e)===n:e===n||typeof e!="object"&&String(e)===String(n)}function V(e,n){if(e==null||n==null)return e==null?n==null?0:-1:1;if(typeof e=="number"&&typeof n=="number")return e-n;if(typeof e=="boolean"||typeof n=="boolean")return+(e===!0||e===1||e==="1")-+(n===!0||n===1||n==="1");let t=String(e),o=String(n);return t<o?-1:t>o?1:0}function Q(e){return e==null?"":String(e)}function Te(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Mt(e){return e===void 0?e:JSON.parse(JSON.stringify(e))}function Tn(e){return{name:e.name,actions:[...e.actions],fields:e.fields.map(n=>({name:n.name,type:n.type,format:null,nullable:n.nullable,readonly:n.readonly,enum:null,description:n.description??null})),summary:[...e.summary],filterable:[...e.filterable],sortable:[...e.sortable],groupable:[...e.groupable],aggregatable:Object.fromEntries(Object.entries(e.aggregatable).map(([n,t])=>[n,[...t]]))}}var Lt="Voorbeeldgebruiker",pe={invalidPrimary:"De hoofdkleur is geen geldige hexkleur; de neutrale standaardkleur wordt gebruikt.",invalidAccent:"De accentkleur is geen geldige hexkleur; er wordt een accentkleur afgeleid.",primaryLight:"De hoofdkleur is erg licht; witte tekst erop heeft weinig contrast.",primaryDarkened:"De hoofdkleur is voor tekst donkerder gemaakt om voldoende contrast te houden."},y={loading:"Laden\u2026",empty:"Er is hier nog niets te tonen.",error:"Er ging iets mis bij het laden.",retry:"Opnieuw proberen",forbidden:"Je hebt geen toegang tot deze gegevens.",signedOut:"Je bent niet ingelogd.",signIn:"Inloggen",signOut:"Uitloggen",signedIn:"Ingelogd",previewUser:Lt,pages:"Pagina's",yes:"Ja",no:"Nee",emptyValue:"\u2014",quarter:(e,n)=>`K${e} ${n}`,week:(e,n)=>`week ${e}, ${n}`,monthYear:(e,n)=>`${e} '${n.slice(-2)}`,period:{label:"Periode","this-month":"Deze maand","12m":"Laatste 12 maanden","this-year":"Dit jaar",custom:"Zelf kiezen",from:"Van",to:"Tot en met",invalidRange:"De einddatum ligt v\xF3\xF3r de begindatum.",incompleteDate:"Vul bij Van en Tot en met een volledige datum in."},noData:"geen gegevens",comparedTo:"t.o.v. vorige periode",newValue:"nieuw",higher:"hoger",lower:"lager",incomplete:"Mogelijk niet compleet: er zijn meer groepen dan de DMP in \xE9\xE9n keer teruggeeft.",asTable:"Gegevens van de grafiek",tooManyGroups:"Te veel groepen om te tonen (meer dan 1000). Kies een kortere periode of een filter.",points:e=>`${e} ${e===1?"punt":"punten"}`,change:(e,n)=>`${e} procent ${n} dan de vorige periode`,search:"Zoeken",all:"Alle",min:"Vanaf",max:"Tot en met",previous:"Vorige",next:"Volgende",pageOf:(e,n,t)=>`Pagina ${e} van ${n} \xB7 ${t} rijen`,exportCsv:"Exporteren (CSV)",exporting:e=>`${e} rijen opgehaald\u2026`,chooseRow:"Kies een rij om de details te zien.",edit:"Bewerken",save:"Opslaan",cancel:"Annuleren",saved:"Opgeslagen.",formSaved:"Opgeslagen. Dank je wel!",another:"Nog een invullen",required:"Vul dit veld in.",requiredMark:" (verplicht)",notANumber:"Vul een getal in.",notAnInteger:"Vul een geheel getal in.",conflict:"Iemand anders heeft deze rij intussen gewijzigd. Laad de nieuwste versie en probeer het opnieuw.",reload:"Opnieuw laden",saveFailed:"Opslaan is niet gelukt. Probeer het opnieuw.",exportFailed:"Exporteren is niet gelukt. Probeer het opnieuw.",formInvalid:"Niet alles is goed ingevuld.",noWritableFields:"Dit formulier heeft geen invulbare velden.",calcFailed:"De berekening lukt niet met deze invoer.",moveTo:e=>`Verplaats naar ${e}`,moveFailed:"Verplaatsen lukte niet.",tryAgain:"Probeer het opnieuw.",changedMeanwhile:"Iemand anders heeft dit intussen gewijzigd; de nieuwste stand is geladen.",more:e=>`en nog ${e}`,noColumns:'Geef de kolommen op met <cube-column value="\u2026">.',emptyColumn:"Leeg",range:(e,n)=>`Kies een waarde van ${e} tot en met ${n}.`,atLeast:e=>`Kies een waarde van ${e} of meer.`,atMost:e=>`Kies een waarde van ten hoogste ${e}.`,step:e=>`Kies een waarde in stappen van ${e}.`,example:"Voorbeeld",exampleMissing:"Voorbeeld \u2014 bestaat nog niet",exampleNotSaved:"Voorbeeld \u2014 wordt niet opgeslagen",gaps:{screen:"Scherm",what:"Wat ontbreekt",type:"Soort gegeven",why:"Waarom",none:"Er ontbreekt niets: alles in dit voorstel bestaat al in de DMP.",types:{tekst:"Tekst",getal:"Getal",bedrag:"Bedrag",datum:"Datum",keuze:"Keuze","ja/nee":"Ja/nee"}},trial:{banner:(e,n)=>["Proefversie","alleen jij","alleen lezen"].concat(e===null?[]:[`verloopt om ${e}`]).concat(n.length===0?[]:[`leest: ${n.join(", ")}`]).concat("Plak geen gegevens uit deze proefversie in je AI-gesprek.").join(" \xB7 "),expired:"Deze proefversie is verlopen. Vraag in je gesprek om een nieuwe.",closed:"Deze proefversie is gesloten.",refreshing:"Nieuwe versie wordt geladen\u2026",wider:"Er is een nieuwe versie die meer gegevens leest.",load:"Laden",elsewhere:"Laad de pagina opnieuw.",reload:"Opnieuw laden"},invalid:{json:(e,n)=>`${e}: ${n} is geen geldige JSON`,number:(e,n)=>`${e}: ${n} is geen geldig getal`,attribute:e=>`${e} mag geen attribuut zijn: geen inline stijl of script`,measure:e=>`"${e}" is geen geldige meting: gebruik count of count/sum/avg/min/max(veld)`,missing:(e,n)=>`${e}: ${n} ontbreekt`,value:(e,n,t)=>`${e}: ${n} "${t}" is geen geldige waarde`,formula:"cube-calc: formula moet een functie zijn",calcSingle:"cube-calc: formula gaf \xE9\xE9n waarde, maar er zijn meer cube-results; geef een object met hun namen",duplicate:(e,n)=>`${e}: name "${n}" komt twee keer voor`,calcAsync:"cube-calc: formula gaf een Promise; geef de uitkomst direct terug, niet async",dateField:e=>`${e}: date-field ontbreekt bij period`,compare:e=>`${e}: compare werkt alleen samen met period`,periodSource:e=>`Geen periodekiezer gevonden voor "${e}"`,periodEnd:e=>`"${e}" is geen geldige einddatum van de periode`,notFilterable:(e,n,t)=>`${e}: ${n} noemt "${t}", maar daarop kan niet gefilterd worden`,selector:(e,n,t)=>`${e}: ${n} "${t}" is geen geldige selector`,lookup:e=>`"${e}" is geen geldige opzoeking: gebruik resource.veld`,dimension:e=>`"${e}" is geen geldige indeling: gebruik veld of veld.day/week/month/quarter/year`},theme:pe};var Ln=["color-primary","color-primary-hover","color-primary-subtle","color-primary-text","color-on-primary","color-accent","color-on-accent","color-text","color-text-muted","color-bg","color-surface","color-border","color-focus","color-danger","color-success","color-warning","color-example-bg","color-example-text","color-series-1","color-series-2","color-series-3","color-series-4","color-series-5","color-series-6","radius","radius-small","font-family"],Fn={primary_colour:"#475467",corners:"normaal",font:"system"},Ae={inter:{family:"Inter",files:[{file:"inter.woff2",weight:"100 900",style:"normal"}]},"albert-sans":{family:"Albert Sans",files:[{file:"albert-sans.woff2",weight:"100 900",style:"normal"}]},"source-sans-3":{family:"Source Sans 3",files:[{file:"source-sans-3.woff2",weight:"200 900",style:"normal"}]},"nunito-sans":{family:"Nunito Sans",files:[{file:"nunito-sans.woff2",weight:"200 1000",style:"normal"}]},"ibm-plex-sans":{family:"IBM Plex Sans",files:[{file:"ibm-plex-sans.woff2",weight:"100 700",style:"normal"}]}},Cn='system-ui, -apple-system, "Segoe UI", Roboto, sans-serif',An="#f6f8fa";function me(e){if(typeof e!="string")return null;let n=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e);if(!n||n[1]===void 0)return null;let t=n[1].toLowerCase();return t.length===3&&(t=[...t].map(o=>o+o).join("")),[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}function $t(e){return"#"+e.map(n=>Math.max(0,Math.min(255,n)).toString(16).padStart(2,"0")).join("")}function Rn(e){let[n,t,o]=e.map(a=>{let i=a/255;return i<=.03928?i/12.92:((i+.055)/1.055)**2.4});return .2126*n+.7152*t+.0722*o}function Re(e,n){let t=me(e),o=me(n);if(!t||!o)return 1;let a=Rn(t),i=Rn(o);return(Math.max(a,i)+.05)/(Math.min(a,i)+.05)}function Ft(e,n,t){let o=me(e),a=me(n);return $t(o.map((i,r)=>Math.round(i*(1-t)+a[r]*t)))}function En(e){return Re(e,"#ffffff")>=Re(e,"#000000")?"#ffffff":"#000000"}function Go(e,n){let[t,o,a]=me(e).map(k=>k/255),i=Math.max(t,o,a),r=Math.min(t,o,a),s=(i+r)/2,l=i-r,u=0,c=0;l!==0&&(c=l/(1-Math.abs(2*s-1)),i===t?u=(o-a)/l%6:i===o?u=(a-t)/l+2:u=(t-o)/l+4,u*=60),u=((u+n)%360+360)%360;let p=(1-Math.abs(2*s-1))*c,m=p*(1-Math.abs(u/60%2-1)),f=s-p/2,d=Math.floor(u/60)%6,[g,w,v]=[[p,m,0],[m,p,0],[0,p,m],[0,m,p],[m,0,p],[p,0,m]][d];return $t([g,w,v].map(k=>Math.round((k+f)*255)))}function _t(e){let n=me(e);return n?$t(n):null}function Wo(e){let n=[],t=_t(e.primary_colour);t===null&&(t=_t(Fn.primary_colour),n.push({code:"invalid-primary",message:pe.invalidPrimary}));let o=null;e.accent_colour!==void 0&&e.accent_colour!==null&&(o=_t(e.accent_colour),o===null&&n.push({code:"invalid-accent",message:pe.invalidAccent})),o??(o=Go(t,330)),Re(t,"#ffffff")<3&&n.push({code:"primary-light",message:pe.primaryLight});let a=Ft(t,"#ffffff",.9),i=t;for(let d=0;d<=20&&(i=Ft(t,"#000000",d/20),!(Re(i,An)>=4.5&&Re(i,a)>=4.5));d++);i!==t&&n.push({code:"primary-darkened-for-text",message:pe.primaryDarkened});let r=En(t),s={scherp:["0px","0px"],normaal:["6px","4px"],rond:["12px","8px"]},l=typeof e.corners=="string"&&Object.hasOwn(s,e.corners)?e.corners:"normaal",[u,c]=s[l],p=typeof e.font=="string"&&Object.hasOwn(Ae,e.font)?e.font:"system",m=p==="system"?Cn:`"${Ae[p].family}", ${Cn}`;return{tokens:{"color-primary":t,"color-primary-hover":Ft(t,r==="#ffffff"?"#000000":"#ffffff",.15),"color-primary-subtle":a,"color-primary-text":i,"color-on-primary":r,"color-accent":o,"color-on-accent":En(o),"color-text":"#1f2328","color-text-muted":"#59636e","color-bg":"#ffffff","color-surface":An,"color-border":"#d1d9e0","color-focus":i,"color-danger":"#b42318","color-success":"#067647","color-warning":"#b54708","color-example-bg":"#fef0c7","color-example-text":"#7a2e0e","color-series-1":t,"color-series-2":o,"color-series-3":"#0e9384","color-series-4":"#dc6803","color-series-5":"#7a5af8","color-series-6":"#475467",radius:u,"radius-small":c,"font-family":m},warnings:n}}var Qo=/^#[0-9a-f]{6}$/i,Jo=/^\d+(\.\d+)?(px|rem)$/,Yo=/^data:image\/(svg\+xml|png);/,Xo=/[;{}<>\\\u0000-\u001f]|\/\*/,Dn=/["'()\\\s]/,Mn=String.raw`(?:\s*"[^"]*"\s*|\s*'[^']*'\s*|[^"',]+)`,Zo=new RegExp(`^${Mn}(?:,${Mn})*$`);function Ke(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function ei(e,n){return typeof n!="string"?!1:e.startsWith("color-")?Qo.test(n):e.startsWith("radius")?Jo.test(n):n.length>0&&n.length<=200&&!Xo.test(n)&&Zo.test(n)}function qe(e,n,t){if(typeof e!="string"||e==="")return null;if(t&&Yo.test(e))return Dn.test(e)?null:e;try{let o=new URL(n),a=new URL(e,o);if((a.protocol==="https:"||a.protocol==="http:")&&a.origin===o.origin&&!Dn.test(a.href))return a.href}catch{}return null}function ti(e,n){let t=[];for(let o of Array.isArray(e)?e:[]){if(!Ke(o))continue;let a=qe(o.src,n,!1);if(a===null)continue;let i=typeof o.weight=="string"&&/^\d{1,4}( \d{1,4})?$/.test(o.weight)?o.weight:"400";t.push({src:a,weight:i,style:o.style==="italic"?"italic":"normal"})}return t}function se(e,n){let t=e,o=Fn,a=null,i=null;Ke(t)&&(Object.hasOwn(t,"source")&&Ke(t.source)?(o=t.source,a=Object.hasOwn(t,"tokens")?t.tokens:null,i=Object.hasOwn(t,"font_files")?t.font_files:null):Object.hasOwn(t,"primary_colour")&&(o=t));let{tokens:r,warnings:s}=Wo(o);if(Ke(a))for(let c of Ln)Object.hasOwn(a,c)&&ei(c,a[c])&&(r[c]=a[c]);let l=typeof o.font=="string"&&Object.hasOwn(Ae,o.font)?o.font:null,u=ti(i,n);return l!==null&&u.length===0&&!Array.isArray(i)&&(u=Ae[l].files.flatMap(c=>{let p=qe("cube-theme/"+c.file,n,!1);return p===null?[]:[{src:p,weight:c.weight,style:c.style}]})),{tokens:r,logo:qe(o.logo,n,!0),logoDark:qe(o.logo_dark,n,!0),fontFamily:l===null?null:Ae[l].family,fontFiles:u,warnings:s}}function _n(e){return":where(:root){"+Ln.map(n=>`--cube-${n}:${e.tokens[n]}`).join(";")+"}"}var Ge=null,Ot=new Set;function We(){return Ge??(Ge=se(null,"http://localhost/")),Ge}function Pt(e){Ge=e;for(let n of[...Ot])n(e)}function Qe(e){return Ot.add(e),()=>{Ot.delete(e)}}var On="cube-trial-config",ni=["dmpUrl","apiUrl","token","expiresAt","statusUrl"],Je=null;function ri(e){let n=e?.getElementById(On)??null;if(n===null)return null;Je=null,n.remove();let t=null;try{let i=JSON.parse(n.textContent??"");t=i!==null&&typeof i=="object"&&!Array.isArray(i)?i:null}catch{}if(t?.mode!=="trial"||ni.some(i=>typeof t[i]!="string"||t[i]===""))return console.warn(`#${On} is not a complete trial config; the app starts without it.`),null;let o=i=>typeof t[i]=="string"?t[i]:null,a=t.leest;return Je={mode:"trial",dmpUrl:t.dmpUrl,apiUrl:t.apiUrl,token:t.token,expiresAt:t.expiresAt,statusUrl:t.statusUrl,version:o("version"),soort:o("soort"),userId:o("userId"),leest:Array.isArray(a)?a.filter(i=>typeof i=="string"):[]},Je}function Ye(){return Je}typeof document<"u"&&ri(document);var $n="1.1.0-rc.3";var A=class extends TypeError{};var ne=["number","integer","currency","percent"],In="nl-NL",oi=["day","week","month","quarter","year"],Xe=/^(\d{4})-(\d{2})-(\d{2})$/,ii=/^\s*-?(\d+\.?\d*|\.\d+)(e[+-]?\d+)?\s*$/i,si=/^(count|sum|avg|min|max)(?:\(([A-Za-z_][A-Za-z0-9_]*)\))?$/,ai=/^([A-Za-z_][A-Za-z0-9_]*)(?:\.([a-z]+))?$/,Pn=new Map,Nn=new Map;function Nt(e){let n=JSON.stringify(e),t=Pn.get(n);return t===void 0&&(t=new Intl.NumberFormat(In,e),Pn.set(n,t)),t}function jt(e){let n=JSON.stringify(e),t=Nn.get(n);return t===void 0&&(t=new Intl.DateTimeFormat(In,e),Nn.set(n,t)),t}function ae(e){return typeof e=="number"?Number.isFinite(e)?e:null:typeof e=="bigint"||typeof e=="string"&&ii.test(e)?Number(e):null}function li(e){return e instanceof Date?Number.isNaN(e.getTime())?null:e:typeof e=="number"?Number.isFinite(e)?new Date(e):null:typeof e=="string"?B(e):null}function I(e,n,t={}){if(e==null||e==="")return y.emptyValue;switch(n){case"number":case"integer":case"currency":case"percent":{let o=ae(e);if(o===null)return String(e);let a=t.compact===!0?{notation:"compact"}:{};if(n==="currency")return Nt({style:"currency",currency:t.currency??"EUR",...a}).format(o);if(n==="percent")return Nt({style:"percent",maximumFractionDigits:1}).format(o);let i=n==="integer"?0:t.compact===!0?1:2;return Nt({maximumFractionDigits:i,...a}).format(o)}case"date":case"datetime":{let o=li(e);if(o===null)return String(e);let a={day:"numeric",month:"short",year:"numeric"};n==="datetime"&&Object.assign(a,{hour:"2-digit",minute:"2-digit"});let i=typeof e=="string"&&Xe.test(e);return t.timeZone!==void 0&&!i&&(a.timeZone=t.timeZone),jt(a).format(o)}case"boolean":return e===!0||e==="true"||e===1?y.yes:e===!1||e==="false"||e===0?y.no:String(e);default:return Array.isArray(e)?e.map(o=>I(o,"text")).join(", "):typeof e=="object"?JSON.stringify(e):String(e)}}function It(e,n,t={}){switch(n){case"year":return e;case"quarter":{let o=/^(\d{4})-Q([1-4])$/.exec(e);return o?.[1]!==void 0&&o[2]!==void 0?y.quarter(o[2],o[1]):e}case"week":{let o=/^(\d{4})-W(\d{2})$/.exec(e);return o?.[1]!==void 0&&o[2]!==void 0?y.week(Number(o[2]),o[1]):e}case"month":{let o=/^(\d{4})-(\d{2})$/.exec(e);if(o?.[1]===void 0||o[2]===void 0)return e;let a=Hn(Number(o[1]),Number(o[2])-1,1);return jt(t.short===!0?{month:"short"}:{month:"short",year:"numeric"}).format(a)}case"day":{let o=Xe.test(e)?B(e):null;return o===null?e:jt({day:"numeric",month:"short"}).format(o)}default:return e}}function Bn(e){let n=si.exec(e.trim()),t=n?.[1];if(t===void 0||t!=="count"&&n?.[2]===void 0)throw new A(y.invalid.measure(e));return{fn:t,field:n?.[2]??null}}function Ze(e){let n=ai.exec(e.trim()),t=n?.[1],o=n?.[2];if(t===void 0||o!==void 0&&!oi.includes(o))throw new A(y.invalid.dimension(e));return{field:t,truncation:o??null}}function Un(e,n){if(e?.format==="date")return"date";if(e?.format==="date-time")return"datetime";if(e?.format==="currency")return"currency";switch(e?.type){case"integer":return"integer";case"number":return"number";case"boolean":return"boolean";case"string":return jn(n)??"text"}return typeof n=="boolean"?"boolean":typeof n=="number"?Number.isInteger(n)?"integer":"number":jn(n)??"text"}function jn(e){return typeof e!="string"?null:Xe.test(e)?B(e)===null?null:"date":/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(e)&&!Number.isNaN(Date.parse(e))?"datetime":null}function K(e){let n=e.replace(/_id$/,"").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[_\-.]+/g," ").trim().toLowerCase();return n===""?e:n.charAt(0).toUpperCase()+n.slice(1)}function B(e){let n=Xe.exec(e);if(n?.[1]!==void 0&&n[2]!==void 0&&n[3]!==void 0){let o=Hn(Number(n[1]),Number(n[2])-1,Number(n[3]));return o.getMonth()===Number(n[2])-1?o:null}let t=Date.parse(e);return Number.isNaN(t)?null:new Date(t)}function Hn(e,n,t){let o=new Date(2e3,0,1);return o.setFullYear(e,n,t),o}function U(e){let n=t=>String(t).padStart(2,"0");return`${String(e.getFullYear()).padStart(4,"0")}-${n(e.getMonth()+1)}-${n(e.getDate())}`}var Vn={tekst:"text",getal:"number",bedrag:"currency",datum:"date",keuze:"text","ja/nee":"boolean"},Bt=e=>typeof e=="string"&&e!=="",tt=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),et=(e=[])=>[e].flat().join(",").split(",").map(n=>n.trim());function ui(e){if(typeof e!="object"||e===null)return!1;let n=e,t=n.waarden;return typeof n.resource=="string"&&/^[a-z][a-z0-9_]*$/.test(n.resource)&&(n.veld===void 0||Bt(n.veld))&&typeof n.type=="string"&&tt(Vn,n.type)&&(t===void 0||Array.isArray(t)&&t.every(o=>typeof o=="string"))&&(n.type!=="keuze"||Array.isArray(t)&&t.length>0)&&Bt(n.scherm)&&Bt(n.reden)}function Kn(e){let n=[],t=[];for(let o of Array.isArray(e)?e:e==null?[]:[e])(ui(o)?n:t).push(o);return t.length>0&&console.warn(`cube-app.json ontbreekt: ${t.length} malformed entries ignored`,t),n}function zn(e){return Vn[e]}function nt(e,n){if(e===null)return null;let t=i=>{let r=zn(i);return r==="date"||r==="currency"?r:null},o=n.flatMap(({resource:i,veld:r,type:s,waarden:l,reden:u})=>{if(i!==e.name||r===void 0||e.fields.some(p=>p.name===r))return[];let c=zn(s);return[{name:r,type:c==="boolean"?c:c==="number"||c==="currency"?"number":"string",format:t(s),nullable:!0,readonly:!1,enum:l??null,description:u}]}),a=o.map(i=>i.name);return{...e,fields:[...e.fields.map(i=>n.find(({resource:s,veld:l})=>s===e.name&&l===i.name)?.type==="bedrag"&&i.format==null?{...i,format:"currency"}:i),...o],summary:e.summary.length>0?[...e.summary,...a]:e.summary,filterable:[...e.filterable,...a],sortable:[...e.sortable,...a]}}function ci(e){let n=2166136261;for(let t=0;t<e.length;t++)n=Math.imul(n^e.charCodeAt(t),16777619)>>>0;return n}function di(e,n,t){let{veld:o,type:a,waarden:i}=e,r=ci(`${e.resource}.${o}.${String(n)}`);if(o!==void 0){let s=t.filter(l=>tt(l,o)&&l[o]!==void 0);if(s.length>0)return s[r%s.length]?.[o]}switch(a){case"tekst":return`Voorbeeld ${r%100+1}`;case"getal":return r%1e3;case"bedrag":return r%1e5/100;case"datum":return U(new Date(2026,0,1+r%365));case"keuze":return i!==void 0&&i.length>0?i[r%i.length]:null;case"ja/nee":return r%2===0}}function qn(e,n){let t=e?.fields;return Array.isArray(t)?t:t?.[n]}async function Ut(e,n,{filter:t={},sort:o=[]}){let a=[o].flat().join(",").split(",").map(u=>u.replace(/^[-+]/,"")),i=Object.fromEntries([...n.flatMap(Object.keys),...Object.keys(t),...a].filter(u=>u!=="").map(u=>[u,{type:typeof n.find(c=>c[u]!=null)?.[u]}])),r=new Map(n.map(u=>[String(u.id),u])),s=new te({[e]:{schema:{fields:i},rows:n}}),{data:l}=await s.resource(e).list({filter:t,sort:o,page:{size:200}});return l.map(u=>r.get(String(u.id)))}function Ht(e,n,t,o){let{name:a}=e,i=new Map(n.filter(m=>m.resource===a&&m.veld!==void 0).map(m=>[m.veld,m])),r=m=>i.has(/^[-+]?(?:\w+\()?([^.()]*)/.exec(m)?.[1]??""),s=(m={})=>{let f=qn(m,a),d=f?.filter(k=>!i.has(k)),g=Object.entries(m.filter??{}),w=et(m.sort).filter(k=>k!==""),v=k=>({filter:Object.fromEntries(g.filter(([S])=>i.has(S)===k)),sort:w.filter(S=>r(S)===k)});return{live:{...m,...d&&{fields:d.includes("id")?d:[...d,"id"]},...v(!1)},local:v(!0),shown:k=>f===void 0||f.includes(k)}},l=(m,f,d=!1)=>{for(let[g,w]of i)(d||f(g))&&(!tt(m,g)||m[g]==null)&&(m[g]=di(w,m.id,o))},u=async(m,{local:f,shown:d})=>{let g=m.data;g.forEach(v=>l(v,d,!0)),g.length>0&&(f.sort.length>0||Object.keys(f.filter).length>0)&&(g=await Ut(a,g,f));for(let v of g)for(let k of i.keys())d(k)||delete v[k];let{meta:w}=m;return{...m,data:g,meta:Object.keys(f.filter).length>0?{...w,page:{...w.page,total:g.length,pages:w.page.number}}:w}},c=async(m,f)=>{let d=s(m);return u(await e.list(d.live,f),d)},p=async function*(m,f){let d=s(m);for await(let g of e.pages(d.live,f))yield await u(g,d)};return{...e,list:c,pages:p,async*all(m,f){for await(let d of p(m,f))yield*d.data},async get(m,f,d){let g=s(f),w=await e.get(m,g.live,d);return l(w.data,g.shown),g.shown("id")||delete w.data.id,w},aggregate:(m,f)=>[et(m.fn).map(d=>d.replace(/^\w+$/,"")),et(m.group),Object.keys(m.filter??{})].flat().some(r)?t.resource(a).aggregate(m):e.aggregate(m,f)}}function Gn(e,n){let t=d=>String(d.id),o=new Map,a=new Map,i=new Set,r=0,s=(d,g)=>({status:d,data:g,meta:null,headers:new Headers,etag:null,recordVersion:null,location:null,replayed:!1,rateLimit:{limit:null,remaining:null,reset:null}}),l=(d,g)=>{let w=qn(g,n);return Object.fromEntries(Object.entries(d).filter(([v])=>w?.includes(v)??!0))},u=async(d,g={})=>{let{page:w}=d.meta,v=o.size>0?await Ut(n,[...o.values()].reverse(),g):[],k=new Set(v.map(t)),S=new Set(a.size>0?(await Ut(n,[...a.values()],g)).map(t):[]),R=new Set(d.data.map(t)),L=d.data.filter(D=>!i.has(t(D))&&(!o.has(t(D))||k.has(t(D)))).map(D=>o.get(t(D))??D),j=v.filter(D=>!S.has(t(D))&&!R.has(t(D))),x=w.total-[...S].filter(D=>!k.has(D)).length+j.length,F=w.number===1?[...j,...L]:L,T=et(g.sort).map(D=>[D.replace(/^[-+]/,""),D.startsWith("-")?-1:1]),E=D=>o.has(t(D))&&(!R.has(t(D))||T.some(([$])=>a.get(t(D))?.[$]!==D[$])),z=F.filter(D=>!E(D));if(T.every(([D])=>z.every($=>tt($,D)))){for(let D of F.filter(E)){let $=z.findIndex(Xr=>T.reduce((Zr,[tn,eo])=>Zr||eo*V(D[tn],Xr[tn]),0)<0);z.splice($>>>0,0,D)}F=z}return{...d,data:F.map(D=>l(D,g)),meta:{...d.meta,page:{...w,total:x}}}},c=async(d,g,w)=>{let v=o.get(String(d));if(i.has(String(d))){let k=`No such ${n} record.`;throw new P(404,new Headers,{status:404,code:"not_found",detail:k})}return v===void 0?e.get(d,g,w):s(200,l(v,g))},p=async d=>{let{data:g}=await c(d);return o.has(String(d))||a.set(String(d),g),g},m=async()=>({...s(202,null),accepted:!0}),f=async function*(d,g){for await(let w of e.pages(d,g))yield await u(w,d)};return{...e,get:c,pages:f,operation:m,collectionOperation:m,list:async(d,g)=>u(await e.list(d,g),d),async*all(d,g){for await(let w of f(d,g))yield*w.data},async create(d){let g={...d,id:`voorbeeld-${++r}`};return o.set(g.id,g),s(201,{...g})},async update(d,g){let w=await p(d),v={...w,...g,id:w.id};return o.set(String(d),v),s(200,{...v})},async delete(d){return await p(d),o.delete(String(d)),i.add(String(d)),s(204,null)}}}var mi="./cube-app.config.json",fi="./cube-mock.json",gi="./cube-app.json",hi="./cube-theme.json",bi={id:"preview",name:Lt,scopes:[]},Qn=null,Jn=null,q=null,zt=null,rt=null,Wn=0;function Yn(e={}){let n=q!==null&&q===zt,t=++Wn,o=ki(e,()=>t===Wn);return q=o,zt=null,o.then(()=>{n&&q===o&&vi()},()=>{q===o&&(q=null)}),o}function yi(){return q!==null?q:(rt??(rt=wi().then(()=>{if(rt=null,q!==null)return q;let e=Yn();return zt=e,e})),rt)}function wi(){let e=globalThis;return new Promise(n=>{let t=()=>{setTimeout(n,0)};e.document===void 0||e.document.readyState==="complete"||e.addEventListener===void 0?t():e.addEventListener("load",t,{once:!0})})}function vi(){let e=globalThis.document;if(e===void 0)return;let n=e.defaultView?.CustomEvent??CustomEvent;e.dispatchEvent(new n("cube-session-change"))}async function ki(e,n){let t=e.fetch??globalThis.fetch.bind(globalThis),o=e.pageUrl??rr(),a=Ye(),[i,r]=await Promise.all([a===null?ot(t,Ee(mi,o)):null,Si(e,t,o)]);return n()&&Pt(r),a!==null?Ai(a,e,t,o):i===null?xi(e,t,o):Ti(Di(i),e,t,o)}async function Si(e,n,t){try{if(e.theme===!1)return se(null,t);let o=e.theme??Jn;if(o!==null)return se(o,t);let a=await ot(n,Ee(hi,t));if(a!==null&&(a.theme!==1||typeof a.source!="object"||a.source===null))throw new TypeError("cube-theme.json is not a theme file.");return se(a,t)}catch(o){return console.warn(`cube-theme.json could not be used, the neutral theme applies: ${String(o)}`),se(null,t)}}async function Xn(e,n,t){let o=e.mock??Qn??await ot(n,Ee(fi,t))??{},a=e.manifest===!1?null:e.manifest??await ot(n,Ee(gi,t));return[o,a]}function Zn(e,n){let t=e==="wireframe",o=t?Kn(n?.ontbreekt):[];return{soort:e??null,gaps:o,simulatesWrites:t,isExample:(a,i)=>o.some(r=>r.resource===a&&(r.veld===void 0||r.veld===i))}}function er(e,n){let t=new Map;return e?a=>{let i=t.get(a)??Gn(n(a),a);return t.set(a,i),i}:n}async function xi(e,n,t){let[o,a]=await Xn(e,n,t),i=!0,r=()=>{if(!i)throw new P(401,new Headers({"Content-Type":"application/problem+json"}),{type:"https://docs.cube.nl/dmp-api/problems/token_invalid",title:"token invalid",status:401,code:"token_invalid",detail:"Unauthenticated."})},s=Zn(a?.soort,a),l=new te(o,a,r),u=new te(o,null,r),c=p=>s.isExample(p)?u:l;return{...s,mode:"preview",signInError:null,user:()=>i?{...bi}:null,async signIn(){i=!0},async signOut(){i=!1},resource:er(s.simulatesWrites,p=>{let m=c(p),f=m.resource(p),d=m.describe(p)?.fields??[],g=s.gaps.filter(({resource:w,veld:v})=>w===p&&v!==void 0&&!d.some(k=>k.name===v));return g.length>0?Ht(f,g,u,u.rows(p)):f}),schema:async p=>nt(c(p).describe(p),s.gaps)}}async function tr(e,n,t,o){let[a,i]=e==="wireframe"?await Xn(n,t,o):[{},null];return{marked:Zn(e,i),examples:new te(a)}}function nr(e,{marked:n,examples:t}){let{client:o}=e,a=null;return{...n,mode:e.mode,get signInError(){return e.signInError()},user:e.user,signIn:e.signIn,signOut:e.signOut,resource:er(n.simulatesWrites,i=>n.isExample(i)?t.resource(i):n.gaps.some(r=>r.resource===i)?Ht(o.resources(i),n.gaps,t,t.rows(i)):o.resources(i)),async schema(i){if(n.isExample(i))return nt(t.describe(i),n.gaps);a??(a=o.capabilities());try{let r=(await a).resources.find(s=>s.name===i);return r===void 0?null:nt(Tn(r),n.gaps)}catch(r){throw a=null,r}}}}async function Ti(e,n,t,o){let a=e.dmpUrl.replace(/\/+$/,""),i=null,r=Mi(n.tokenStorage==="memory"?je():Li(`cube-app.tokens.${e.clientId}`),p=>{i=p}),s=sn({issuer:e.issuer??a,clientId:e.clientId,redirectUri:Ee(e.redirectUri,o),scopes:e.scopes,fetch:t,tokenStore:r,...e.metadata!==void 0?{metadata:e.metadata}:{}}),l=St({baseUrl:e.apiUrl??`${a}/apps/api/v1`,auth:s,fetch:t}),u=null,c=await tr(e.soort,n,t,o);i=await r.get();try{await s.handleCallback()}catch(p){u=p instanceof Error?p:new Error(String(p))}return i===null&&u===null&&n.autoSignIn===!0&&await s.signIn(),nr({mode:"live",client:l,signInError:()=>u,user:()=>i===null?null:Ri(i),async signIn(){u=null,await s.signIn()},async signOut(){await s.signOut()}},c)}function Ci(e){return async(n,t)=>{let o=(t?.method??"GET").toUpperCase();return o==="GET"||o==="HEAD"?e(n,t):new Response(JSON.stringify({status:403,code:"insufficient_scope"}),{status:403,headers:{"Content-Type":"application/problem+json"}})}}async function Ai(e,n,t,o){let a=e.token,i=St({baseUrl:e.apiUrl,auth:()=>a,fetch:Ci(t)}),r=await tr(e.soort??void 0,n,t,o);return nr({mode:"trial",client:i,signInError:()=>null,user:()=>a===null?null:{id:e.userId,name:null,scopes:["api:read"]},async signIn(){globalThis.location?.reload()},async signOut(){a=null}},r)}function Ri(e){let n=Ei(e.accessToken),t=n?.sub,o=Array.isArray(n?.scopes)?n.scopes.map(String):null;return{id:typeof t=="string"||typeof t=="number"?String(t):null,name:null,scopes:o??(e.scope??"").split(" ").filter(a=>a!=="")}}function Ei(e){let n=e.split(".")[1];if(n===void 0)return null;try{let t=n.replace(/-/g,"+").replace(/_/g,"/"),o=atob(t.padEnd(t.length+(4-t.length%4)%4,"=")),a=new TextDecoder().decode(Uint8Array.from(o,r=>r.charCodeAt(0))),i=JSON.parse(a);return i!==null&&typeof i=="object"?i:null}catch{return null}}function Di(e){let n=["dmpUrl","clientId","redirectUri"].filter(o=>typeof e[o]!="string"||e[o]===""),t=e.scopes;if(typeof t=="string"||Array.isArray(t)&&t.every(o=>typeof o=="string")||n.push("scopes"),n.length>0)throw new TypeError(`cube-app.config.json is incomplete: ${n.join(", ")} missing or not a string.`);return e}async function ot(e,n){let t;try{t=await e(n,{headers:{Accept:"application/json"},...typeof document<"u"?{cache:"no-store"}:{}})}catch{return null}if(t.status===404||t.status===410)return null;if(!t.ok)throw new Error(`${n} answered ${t.status}.`);try{let o=JSON.parse(await t.text());return o!==null&&typeof o=="object"&&!Array.isArray(o)?o:null}catch{return null}}function Mi(e,n){return{async get(){let t=await e.get();return n(t),t},async set(t){await e.set(t),n(t)}}}function Li(e){let n=(()=>{try{return globalThis.sessionStorage??null}catch{return null}})();return n===null?je():{get(){try{let t=n.getItem(e);return t===null?null:JSON.parse(t)}catch{return null}},set(t){try{t===null?n.removeItem(e):n.setItem(e,JSON.stringify(t))}catch{}}}}function rr(){let e=globalThis;return e.document?.baseURI??e.location?.href??"http://localhost/"}function Ee(e,n){return new URL(e,n).href}function Fi(e){Qn=e}function _i(e){Jn=e,Pt(se(e,rr()))}var it=Object.freeze({connect:Yn,ready:yi,mock:Fi,theme:_i,version:$n,sdk:"1"});var or={"cube-state":["kind","message","retry"],"cube-app-shell":["name","logo","logo-alt"],"cube-page":["name","label"],"cube-field":["name","label","format","multiline","options","hidden"],"cube-period-picker":["default","label","today"],"cube-kpi":["resource","measure","label","format","currency","filter","period","date-field","compare"],"cube-chart":["resource","measure","by","kind","label","format","currency","filter","period","date-field","lookup","height","limit"],"cube-top":["resource","measure","by","limit","order","label","format","currency","filter","period","date-field","lookup"],"cube-table":["resource","fields","search","filters","sort","page-size","export","detail","filter","period","date-field"],"cube-detail":["resource","record-id","fields","editable"],"cube-form":["resource","fields","submit-label","success-text"],"cube-calc":["label"],"cube-input":["name","label","type","value","min","max","step","options"],"cube-result":["name","label","format","currency","emphasis"],"cube-board":["resource","status-field","title-field","fields","sort","filter","page-size","detail"],"cube-column":["value","label"],"cube-gap-list":["scherm"]};var Oi="http://www.w3.org/2000/svg";function h(e,n,t={},...o){let a=e.createElement(n);for(let[i,r]of Object.entries(t))ir(i,r===!0||typeof r=="string"),typeof r=="function"?a.addEventListener(i.replace(/^on/,""),r):r===!0?a.setAttribute(i,""):typeof r=="string"&&a.setAttribute(i,r);return sr(e,a,o),a}function H(e,n,t={},...o){let a=e.createElementNS(Oi,n);for(let[i,r]of Object.entries(t))ir(i,!0),a.setAttribute(i,String(r));return sr(e,a,o),a}function ir(e,n){let t=e.toLowerCase();if(t==="style"||n&&t.startsWith("on"))throw new A(y.invalid.attribute(e))}function C(e){for(;e.firstChild!==null;)e.removeChild(e.firstChild)}function sr(e,n,t){for(let o of t)typeof o=="string"?n.appendChild(e.createTextNode(o)):o!=null&&o!==!1&&n.appendChild(o)}var De=`
3
3
  :host{display:block;box-sizing:border-box;min-width:0;font-family:var(--cube-font-family,system-ui,sans-serif);
4
4
  color:var(--cube-color-text,#1f2328);font-size:1rem;line-height:1.5}
5
5
  :host([hidden]){display:none}
@@ -29,7 +29,7 @@ td.example,dd.example{text-decoration:underline dashed;text-underline-offset:.25
29
29
  font-weight:600}
30
30
  .row{display:flex;flex-wrap:wrap;align-items:center;gap:.75rem}
31
31
  @media (max-width:640px){.row{flex-direction:column;align-items:stretch}.row>button{width:100%}}
32
- `,Jn=new WeakMap;function Ye(e,n){let t=Jn.get(e);t===void 0&&(t=new Map,Jn.set(e,t));let o=t.get(n);return o===void 0&&(o=new e.CSSStyleSheet,o.replaceSync(n),t.set(n,o)),o}var q=class extends Error{constructor(t){super(t.detail??t.kind);b(this,"state");this.state=t}};function X(e){if(e instanceof q)return e.state;if(F(e)){if(e.status===401)return{kind:"signed-out",detail:null};if(e.status===403)return{kind:"forbidden",detail:null}}return e instanceof TypeError?{kind:"error",detail:e.message}:{kind:"error",detail:null}}function pi(e){return new Promise(n=>{e.readyState==="loading"?e.addEventListener("DOMContentLoaded",()=>n(),{once:!0}):(e.defaultView?.setTimeout??setTimeout)(n,0)})}function Xe(e){return h(e,"span",{class:"badge example"},y.example,h(e,"span",{class:"sr-only"},y.exampleMissing.slice(y.example.length)))}function mi(e){return e!==null&&typeof e=="object"&&e.name==="AbortError"}function Yn(e,n={}){let t=n.session??(()=>Je.ready());class o extends e.HTMLElement{constructor(){super();b(this,"body");b(this,"current",Promise.resolve());b(this,"scheduled",!1);b(this,"controller",null);b(this,"badge",null);b(this,"onSessionChange",()=>this.schedule());b(this,"onDataChange",r=>{let s=r.detail?.resource,l=this.getAttribute("resource")?.trim()??"";typeof s=="string"&&l!==""&&s.trim()===l&&this.schedule()});let r=this.constructor,s=this.attachShadow({mode:"open"});s.adoptedStyleSheets=r.css===""?[Ye(e,Ot)]:[Ye(e,Ot),Ye(e,r.css)],this.body=h(e.document,"div",{class:"cube-body",part:"body"}),s.appendChild(this.body),s.addEventListener("cube-retry",l=>{l.stopPropagation(),this.schedule()})}static get observedAttributes(){return[...Gn[this.tag]??[]]}get updateComplete(){return(async()=>{let r;do r=this.current,await r;while(r!==this.current)})()}connectedCallback(){this.ownerDocument.addEventListener("cube-session-change",this.onSessionChange),this.ownerDocument.addEventListener("cube-data-change",this.onDataChange),this.schedule()}disconnectedCallback(){this.ownerDocument.removeEventListener("cube-session-change",this.onSessionChange),this.ownerDocument.removeEventListener("cube-data-change",this.onDataChange),this.controller?.abort(),this.controller=null,this.removeAttribute("aria-busy")}attributeChangedCallback(r,s,l){s!==l&&this.schedule()}refresh(){if(!this.isConnected)return this.current;this.controller?.abort();let r=new AbortController;this.controller=r;let s=this.run(r.signal);return this.current=s,s}schedule(){this.scheduled||!this.isConnected||(this.scheduled=!0,this.current=new Promise(r=>{queueMicrotask(()=>{this.scheduled=!1,r(this.isConnected?this.refresh():void 0)})}))}async run(r){let s=this.constructor;this.showState("loading");try{if(await pi(this.ownerDocument),r.aborted)return;let l=s.needsSession?await this.session():null;if(r.aborted)return;await this.load(r,l),r.aborted||this.mark(l)}catch(l){if(r.aborted||mi(l))return;this.badge?.remove(),this.showState(X(l))}finally{r.aborted||this.removeAttribute("aria-busy")}}session(){return t()}shownFields(){return[]}exampleField(r,s,l){return r.isExample?.(s,l)===!0&&!r.isExample(s)}notSaved(r){return r.simulatesWrites===!0?h(this.ownerDocument,"p",{class:"note not-saved"},y.exampleNotSaved):null}mark(r){let s=this.getAttribute("resource")?.trim()??"";if(!(r?.isExample!==void 0&&s!==""&&(r.isExample(s)||this.shownFields().some(u=>r.isExample(s,u))))){this.badge?.remove();return}this.badge??(this.badge=h(this.ownerDocument,"p",{class:"badge example",role:"note"},y.exampleMissing)),this.shadowRoot?.insertBefore(this.badge,this.body)}showState(r,s=null){let{kind:l,detail:u,retry:c}=typeof r=="string"?{kind:r,detail:s}:r;l==="loading"&&this.setAttribute("aria-busy","true"),T(this.body),this.body.appendChild(h(this.ownerDocument,"cube-state",{kind:l,message:u,retry:c===!1?"false":null}))}attr(r){return this.getAttribute(r)}flag(r){return this.hasAttribute(r)&&this.getAttribute(r)!=="false"}num(r,s){let l=this.getAttribute(r);if(l===null||l.trim()==="")return s;let u=Number(l);if(!Number.isFinite(u))throw new TypeError(y.invalid.number(this.localName,r));return u}json(r){let s=this.getAttribute(r);if(s===null||s.trim()==="")return null;try{return JSON.parse(s)}catch{throw new TypeError(y.invalid.json(this.localName,r))}}emit(r,s=null){let l=this.ownerDocument.defaultView?.CustomEvent??CustomEvent;return this.dispatchEvent(new l(r,{detail:s,bubbles:!0,composed:!0}))}}return b(o,"tag",""),b(o,"css",""),b(o,"needsSession",!0),o}var fi=`
32
+ `,ar=new WeakMap;function st(e,n){let t=ar.get(e);t===void 0&&(t=new Map,ar.set(e,t));let o=t.get(n);return o===void 0&&(o=new e.CSSStyleSheet,o.replaceSync(n),t.set(n,o)),o}var J=class extends Error{constructor(t){super(t.detail??t.kind);b(this,"state");this.state=t}};function Y(e){if(e instanceof J)return e.state;if(N(e)){if(e.status===401)return{kind:"signed-out",detail:null};if(e.status===403)return{kind:"forbidden",detail:null}}return e instanceof A?{kind:"error",detail:e.message}:{kind:"error",detail:null}}function $i(e){return new Promise(n=>{e.readyState==="loading"?e.addEventListener("DOMContentLoaded",()=>n(),{once:!0}):(e.defaultView?.setTimeout??setTimeout)(n,0)})}function at(e){return h(e,"span",{class:"badge example"},y.example,h(e,"span",{class:"sr-only"},y.exampleMissing.slice(y.example.length)))}function Pi(e){return e!==null&&typeof e=="object"&&e.name==="AbortError"}function lr(e,n={}){let t=n.session??(()=>it.ready());class o extends e.HTMLElement{constructor(){super();b(this,"body");b(this,"current",Promise.resolve());b(this,"scheduled",!1);b(this,"controller",null);b(this,"badge",null);b(this,"onSessionChange",()=>this.schedule());b(this,"onDataChange",r=>{if(r.composedPath()[0]===this&&!this.constructor.reloadsOnOwnChange)return;let s=r.detail?.resource,l=this.getAttribute("resource")?.trim()??"";typeof s=="string"&&l!==""&&s.trim()===l&&this.schedule()});let r=this.constructor,s=this.attachShadow({mode:"open"});s.adoptedStyleSheets=r.css===""?[st(e,De)]:[st(e,De),st(e,r.css)],this.body=h(e.document,"div",{class:"cube-body",part:"body"}),s.appendChild(this.body),s.addEventListener("cube-retry",l=>{l.stopPropagation(),this.schedule()})}static get observedAttributes(){return[...or[this.tag]??[]]}get updateComplete(){return(async()=>{let r;do r=this.current,await r;while(r!==this.current)})()}connectedCallback(){this.ownerDocument.addEventListener("cube-session-change",this.onSessionChange),this.ownerDocument.addEventListener("cube-data-change",this.onDataChange),this.schedule()}disconnectedCallback(){this.ownerDocument.removeEventListener("cube-session-change",this.onSessionChange),this.ownerDocument.removeEventListener("cube-data-change",this.onDataChange),this.controller?.abort(),this.controller=null,this.removeAttribute("aria-busy")}attributeChangedCallback(r,s,l){s!==l&&this.schedule()}refresh(){if(!this.isConnected)return this.current;this.controller?.abort();let r=new AbortController;this.controller=r;let s=this.run(r.signal);return this.current=s,s}schedule(){this.scheduled||!this.isConnected||(this.scheduled=!0,this.current=new Promise(r=>{queueMicrotask(()=>{this.scheduled=!1,r(this.isConnected?this.refresh():void 0)})}))}async run(r){let s=this.constructor;this.showState("loading");try{if(await $i(this.ownerDocument),r.aborted)return;let l=s.needsSession?await this.session():null;if(r.aborted)return;await this.load(r,l),r.aborted||this.mark(l)}catch(l){if(r.aborted||Pi(l))return;this.badge?.remove(),this.showState(Y(l)),l instanceof TypeError&&!(l instanceof A)&&console.warn(`${this.localName}:`,l)}finally{r.aborted||this.removeAttribute("aria-busy")}}session(){return t()}shownFields(){return[]}exampleField(r,s,l){return r.isExample?.(s,l)===!0&&!r.isExample(s)}notSaved(r){return r.simulatesWrites===!0?h(this.ownerDocument,"p",{class:"note not-saved"},y.exampleNotSaved):null}mark(r){let s=this.getAttribute("resource")?.trim()??"";if(!(r?.isExample!==void 0&&s!==""&&(r.isExample(s)||this.shownFields().some(u=>r.isExample(s,u))))){this.badge?.remove();return}this.badge??(this.badge=h(this.ownerDocument,"p",{class:"badge example",role:"note"},y.exampleMissing)),this.shadowRoot?.insertBefore(this.badge,this.body)}showState(r,s=null){let{kind:l,detail:u,retry:c}=typeof r=="string"?{kind:r,detail:s}:r;l==="loading"&&this.setAttribute("aria-busy","true"),C(this.body),this.body.appendChild(h(this.ownerDocument,"cube-state",{kind:l,message:u,retry:c===!1?"false":null}))}attr(r){return this.getAttribute(r)}flag(r){return this.hasAttribute(r)&&this.getAttribute(r)!=="false"}num(r,s){let l=this.getAttribute(r);if(l===null||l.trim()==="")return s;let u=Number(l);if(!Number.isFinite(u))throw new A(y.invalid.number(this.localName,r));return u}json(r){let s=this.getAttribute(r);if(s===null||s.trim()==="")return null;try{return JSON.parse(s)}catch{throw new A(y.invalid.json(this.localName,r))}}emit(r,s=null){let l=this.ownerDocument.defaultView?.CustomEvent??CustomEvent;return this.dispatchEvent(new l(r,{detail:s,bubbles:!0,composed:!0}))}}return b(o,"tag",""),b(o,"css",""),b(o,"needsSession",!0),b(o,"reloadsOnOwnChange",!0),o}var Ni=`
33
33
  :host{background:var(--cube-color-bg)}
34
34
  header{display:flex;flex-wrap:wrap;align-items:center;gap:.75rem 1rem;padding:.75rem 1.5rem;
35
35
  border-bottom:1px solid var(--cube-color-border);background:var(--cube-color-surface)}
@@ -46,12 +46,12 @@ border-bottom-color:var(--cube-color-primary)}
46
46
  main{padding:1.5rem}
47
47
  ::slotted(cube-page:not([hidden])){display:flex;flex-direction:column;gap:1.5rem}
48
48
  @media (max-width:640px){header{padding:.75rem 1rem}nav{padding:0}main{padding:1rem}}
49
- `,Pt="#/";function Xn(e,n){class t extends e{constructor(){super();b(this,"header");b(this,"heading");b(this,"user");b(this,"nav");b(this,"list");b(this,"main");b(this,"built","");b(this,"stopTheme",null);b(this,"onHash",()=>this.updatePages());let i=n.document;this.heading=h(i,"h1"),this.user=h(i,"div",{class:"user"}),this.header=h(i,"header",{},this.heading,this.user),this.list=h(i,"ul"),this.nav=h(i,"nav",{"aria-label":y.pages},this.list);let r=h(i,"slot",{onslotchange:()=>this.updatePages()});this.main=h(i,"main",{},r),this.body.append(this.header,this.main),this.renderHeader()}connectedCallback(){super.connectedCallback(),this.ownerDocument.defaultView?.addEventListener("hashchange",this.onHash),this.stopTheme?.(),this.stopTheme=Ve(()=>this.renderHeader()),this.renderHeader(),this.updatePages()}disconnectedCallback(){super.disconnectedCallback(),this.ownerDocument.defaultView?.removeEventListener("hashchange",this.onHash),this.stopTheme?.(),this.stopTheme=null}async load(i,r){this.renderHeader(),this.updatePages(),r!==null&&this.renderUser(r)}showState(i){let r=typeof i=="string"?i:i.kind;T(this.user),r==="signed-out"&&this.user.appendChild(this.signInButton())}renderHeader(){let i=this.attr("name")??"",r=this.attr("logo")??ze().logo,s=this.header.querySelector(".logo");if(this.heading.textContent=i,r===null||r===""){s?.remove();return}let l=h(n.document,"img",{class:"logo",src:r,alt:this.attr("logo-alt")??i});s===null?this.header.prepend(l):s.replaceWith(l)}renderUser(i){let r=n.document,s=i.user();if(T(this.user),s===null){this.user.appendChild(this.signInButton());return}this.user.append(h(r,"span",{},s.name!==null&&s.name!==""?s.name:y.signedIn),h(r,"button",{type:"button",class:"secondary",onclick:()=>{this.change(l=>l.signOut())}},y.signOut))}signInButton(){return h(n.document,"button",{type:"button",onclick:()=>{this.change(i=>i.signIn())}},y.signIn)}async change(i){try{await i(await this.session())}catch{this.refresh();return}let r=this.ownerDocument.defaultView?.CustomEvent??CustomEvent;this.ownerDocument.dispatchEvent(new r("cube-session-change"))}pages(){return Array.from(this.children).filter(i=>i.localName==="cube-page")}updatePages(){let i=this.pages(),s=(n.location??this.ownerDocument.defaultView?.location)?.hash??"",l="";if(s.startsWith(Pt))try{l=decodeURIComponent(s.slice(Pt.length))}catch{l=""}let u=i.find(p=>p.getAttribute("name")===l)??i[0];for(let p of i)p.hidden=p!==u;if(i.length<2){this.nav.remove(),T(this.list),this.built="";return}this.nav.parentNode!==this.body&&this.body.insertBefore(this.nav,this.main);let c=JSON.stringify(i.map(p=>[p.getAttribute("name"),p.getAttribute("label")]));if(c!==this.built){T(this.list);for(let p of i){let f=p.getAttribute("name")??"",m=Pt+encodeURIComponent(f),d=h(n.document,"a",{href:m},p.getAttribute("label")??f);this.list.appendChild(h(n.document,"li",{},d))}this.built=c}Array.from(this.list.querySelectorAll("a")).forEach((p,f)=>{i[f]===u?p.setAttribute("aria-current","page"):p.removeAttribute("aria-current")})}}return b(t,"tag","cube-app-shell"),b(t,"css",fi),t}var gi=/^([a-z][a-z0-9_]*)\.([A-Za-z_][A-Za-z0-9_]*)$/,Nt=200;function le(e){let n=e.getAttribute("filter");if(n===null||n.trim()==="")return{};let t;try{t=JSON.parse(n)}catch{t=null}if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(y.invalid.json(e.localName,"filter"));return t}function hi(e){let n=e;return typeof n?.from=="string"&&typeof n.to=="string"&&typeof n.previous?.from=="string"&&typeof n.previous.to=="string"}function Ze(e,n){let t=$(n.to);if(t===null)throw new TypeError(y.invalid.periodEnd(n.to));return t.setDate(t.getDate()+1),{[e]:{gte:n.from,lt:O(t)}}}async function et(e,n){if(n===null||n==="")return null;let t=e.ownerDocument.querySelector(n),o=(e.ownerDocument.defaultView??window).customElements;if(t===null||o.get(t.localName)===void 0)throw new TypeError(y.invalid.periodSource(n));let a=t;if(await a.updateComplete,!hi(a.value))throw new TypeError(y.invalid.periodSource(n));return a}function tt(e,n,t){if(e!==null&&e!=="")return e;if(n!==null&&n!==""){let o=qe(n);if(o.truncation!==null)return o.field}throw new TypeError(y.invalid.dateField(t))}async function Zn(e,n,t,o){let a=gi.exec(n),i=a?.[1],r=a?.[2];if(i===void 0||r===void 0)throw new TypeError(y.invalid.lookup(n));let s=[...new Set(t.filter(u=>u!=null).map(u=>u))],l=new Map;for(let u=0;u<s.length;u+=Nt){o.throwIfAborted();let c=s.slice(u,u+Nt),p;try{let f={filter:{id:{in:c}},fields:["id",r],page:{size:Nt}};({data:p}=await e.resource(i).list(f,{signal:o}))}catch(f){if(o.aborted||f?.name==="AbortError")throw f;continue}for(let f of p){let m=f[r];m!=null&&l.set(String(f.id),String(m))}}return l}var bi=["number","integer","currency","percent"],M=`
49
+ `,Vt="#/";function ur(e,n){class t extends e{constructor(){super();b(this,"header");b(this,"heading");b(this,"user");b(this,"nav");b(this,"list");b(this,"main");b(this,"built","");b(this,"stopTheme",null);b(this,"onHash",()=>this.updatePages());let i=n.document;this.heading=h(i,"h1"),this.user=h(i,"div",{class:"user"}),this.header=h(i,"header",{},this.heading,this.user),this.list=h(i,"ul"),this.nav=h(i,"nav",{"aria-label":y.pages},this.list);let r=h(i,"slot",{onslotchange:()=>this.updatePages()});this.main=h(i,"main",{},r),this.body.append(this.header,this.main),this.renderHeader()}connectedCallback(){super.connectedCallback(),this.ownerDocument.defaultView?.addEventListener("hashchange",this.onHash),this.stopTheme?.(),this.stopTheme=Qe(()=>this.renderHeader()),this.renderHeader(),this.updatePages()}disconnectedCallback(){super.disconnectedCallback(),this.ownerDocument.defaultView?.removeEventListener("hashchange",this.onHash),this.stopTheme?.(),this.stopTheme=null}async load(i,r){this.renderHeader(),this.updatePages(),r!==null&&this.renderUser(r)}showState(i){let r=typeof i=="string"?i:i.kind;C(this.user),r==="signed-out"&&this.user.appendChild(this.signInButton())}renderHeader(){let i=this.attr("name")??"",r=this.attr("logo")??We().logo,s=this.header.querySelector(".logo");if(this.heading.textContent=i,r===null||r===""){s?.remove();return}let l=h(n.document,"img",{class:"logo",src:r,alt:this.attr("logo-alt")??i});s===null?this.header.prepend(l):s.replaceWith(l)}renderUser(i){let r=n.document,s=i.user();if(C(this.user),s===null){this.user.appendChild(this.signInButton());return}this.user.append(h(r,"span",{},s.name!==null&&s.name!==""?s.name:y.signedIn),h(r,"button",{type:"button",class:"secondary",onclick:()=>{this.change(l=>l.signOut())}},y.signOut))}signInButton(){return h(n.document,"button",{type:"button",onclick:()=>{this.change(i=>i.signIn())}},y.signIn)}async change(i){try{await i(await this.session())}catch{this.refresh();return}let r=this.ownerDocument.defaultView?.CustomEvent??CustomEvent;this.ownerDocument.dispatchEvent(new r("cube-session-change"))}pages(){return Array.from(this.children).filter(i=>i.localName==="cube-page")}updatePages(){let i=this.pages(),s=(n.location??this.ownerDocument.defaultView?.location)?.hash??"",l="";if(s.startsWith(Vt))try{l=decodeURIComponent(s.slice(Vt.length).split("?")[0]??"")}catch{l=""}let u=i.find(p=>p.getAttribute("name")===l)??i[0];for(let p of i)p.hidden=p!==u;if(i.length<2){this.nav.remove(),C(this.list),this.built="";return}this.nav.parentNode!==this.body&&this.body.insertBefore(this.nav,this.main);let c=JSON.stringify(i.map(p=>[p.getAttribute("name"),p.getAttribute("label")]));if(c!==this.built){C(this.list);for(let p of i){let m=p.getAttribute("name")??"",f=Vt+encodeURIComponent(m),d=h(n.document,"a",{href:f},p.getAttribute("label")??m);this.list.appendChild(h(n.document,"li",{},d))}this.built=c}Array.from(this.list.querySelectorAll("a")).forEach((p,m)=>{i[m]===u?p.setAttribute("aria-current","page"):p.removeAttribute("aria-current")})}}return b(t,"tag","cube-app-shell"),b(t,"css",Ni),t}var ji=/^([a-z][a-z0-9_]*)\.([A-Za-z_][A-Za-z0-9_]*)$/,Kt=200;function fe(e){let n=e.getAttribute("filter");if(n===null||n.trim()==="")return{};let t;try{t=JSON.parse(n)}catch{t=null}if(t===null||typeof t!="object"||Array.isArray(t))throw new A(y.invalid.json(e.localName,"filter"));return t}function Ii(e){let n=e;return typeof n?.from=="string"&&typeof n.to=="string"&&typeof n.previous?.from=="string"&&typeof n.previous.to=="string"}function lt(e,n){let t=B(n.to);if(t===null)throw new A(y.invalid.periodEnd(n.to));return t.setDate(t.getDate()+1),{[e]:{gte:n.from,lt:U(t)}}}async function ut(e,n){if(n===null||n==="")return null;let t=e.ownerDocument.querySelector(n),o=(e.ownerDocument.defaultView??window).customElements;if(t===null||o.get(t.localName)===void 0)throw new A(y.invalid.periodSource(n));let a=t;if(await a.updateComplete,!Ii(a.value))throw new A(y.invalid.periodSource(n));return a}function ct(e,n,t){if(e!==null&&e!=="")return e;if(n!==null&&n!==""){let o=Ze(n);if(o.truncation!==null)return o.field}throw new A(y.invalid.dateField(t))}async function cr(e,n,t,o){let a=ji.exec(n),i=a?.[1],r=a?.[2];if(i===void 0||r===void 0)throw new A(y.invalid.lookup(n));let s=[...new Set(t.filter(u=>u!=null).map(u=>u))],l=new Map;for(let u=0;u<s.length;u+=Kt){o.throwIfAborted();let c=s.slice(u,u+Kt),p;try{let m={filter:{id:{in:c}},fields:["id",r],page:{size:Kt}};({data:p}=await e.resource(i).list(m,{signal:o}))}catch(m){if(o.aborted||m?.name==="AbortError")throw m;continue}for(let m of p){let f=m[r];f!=null&&l.set(String(m.id),String(f))}}return l}var Bi=["number","integer","currency","percent"],O=`
50
50
  .card{padding:1rem 1.25rem;border:1px solid var(--cube-color-border);border-radius:var(--cube-radius);
51
51
  background:var(--cube-color-surface)}
52
- `,ue=`
52
+ `,ge=`
53
53
  .label{margin:0 0 .5rem;font-weight:600}
54
- `;function C(e,n){let t=e.getAttribute(n)?.trim()??"";if(t==="")throw new TypeError(y.invalid.missing(e.localName,n));return t}function ce(e){let n=/\(([^)]+)\)/.exec(e.getAttribute("measure")??"")?.[1]?.trim(),t=e.getAttribute("by")?.split(".")[0];return[n,t,e.getAttribute("date-field")].filter(o=>!!o)}function Te(e){if(typeof e=="string"&&e.trim()==="")return null;let n=typeof e=="number"||typeof e=="string"?Number(e):NaN;return Number.isFinite(n)?n:null}var z=class{constructor(n){b(this,"block",n);b(this,"source",null);b(this,"onChange",()=>{this.block.isConnected?this.block.refresh():this.follow(null)})}follow(n){n!==this.source&&(this.source?.removeEventListener("cube-change",this.onChange),this.source=n,n?.addEventListener("cube-change",this.onChange))}};async function de(e,n,t,o=null){let a=Dn(C(e,"measure")),i=le(e),r=e.getAttribute("period"),s=r===null||r===""?null:tt(e.getAttribute("date-field"),o,e.localName),l=await et(e,r);return t.aborted?null:(n.follow(l),{fn:a.field===null?a.fn:`${a.fn}(${a.field})`,field:a.field,count:a.fn==="count",period:l?.value??null,filterFor:u=>u===null||s===null?i:{...i,...Ze(s,u)}})}async function nt(e,n,t,o,a){try{return await e.resource(n).aggregate({fn:o.fn,group:t,filter:o.filterFor(o.period)},{signal:a})}catch(i){throw F(i)&&i.status===422&&(i.reason==="too_many_groups"||i.code==="cardinality_exceeded")?new q({kind:"error",detail:y.tooManyGroups,retry:!1}):i}}function G(e,n,t,o){let a=e.getAttribute(n),i=a===null||a.trim()===""?NaN:Number(a);return Number.isFinite(i)&&i>=t?Math.floor(i):o}async function rt(e,n,t,o,a,i){let r=a.descending?-1:1,s=t.filter(c=>c[o.by]!==null&&c[o.by]!==void 0).map(c=>({key:String(c[o.by]),value:Te(c[o.fn])})).filter(c=>c.value!==null).sort((c,p)=>r*(c.value-p.value)).slice(0,a.limit),l=e.getAttribute("lookup"),u=l===null||l===""||s.length===0?null:await Zn(n,l,s.map(c=>c.key),i);return i.aborted?null:s.map(c=>({...c,label:u===null?c.key:u.get(c.key)??`#${c.key}`}))}function pe(e,n){let t=e.getAttribute("format"),o=t!==null&&bi.includes(t)?t:n?"integer":"number",a=e.getAttribute("currency")||"EUR";return(i,r)=>_(i,o,{currency:a,compact:r===!0})}var Re=Symbol("cube-field hidden");function er(e){var n,t;return class extends(t=e.HTMLElement,n=Re,t){constructor(){super(...arguments);b(this,n)}connectedCallback(){this[Re]===void 0&&(this[Re]=this.hasAttribute("hidden")),this.hidden=!0}}}function ot(e){let n=e.field?.enum??null;return e.config?.options??(n===null?null:n.map(t=>({value:t,label:t})))}var yi=["text","number","integer","currency","percent","date","datetime","boolean"];function W(e){let n=(e??"").split(",").map(t=>t.trim()).filter(t=>t!=="");return n.length>0?n:null}function jt(e){if(e===null)return null;let n=e.split(",").map(t=>{let o=t.indexOf("="),a=(o<0?t:t.slice(0,o)).trim(),i=o<0?a:t.slice(o+1).trim();return{value:a,label:i===""?a:i}}).filter(t=>t.value!=="");return n.length>0?n:null}function V(e){let n=new Map;for(let t of Array.from(e.children)){let o=t.getAttribute("name")?.trim()??"";if(t.localName!=="cube-field"||o==="")continue;let a=t.getAttribute("format"),i=t[Re];n.set(o,{name:o,label:t.getAttribute("label"),format:a!==null&&yi.includes(a)?a:null,multiline:t.hasAttribute("multiline"),options:jt(t.getAttribute("options")),hidden:i??t.hasAttribute("hidden")})}return n}function Ce(e,n){return e.get(n)?.label??U(n)}function Q(e,n,t,o){let a=e!==null&&e.summary.length>0?e.summary:null;return(n??a??(o===void 0?[]:Object.keys(o))).filter(r=>t.get(r)?.hidden!==!0).map(r=>{let s=e?.fields.find(u=>u.name===r),l=t.get(r);return{name:r,label:Ce(t,r),format:l?.format??Ln(s,o?.[r]),field:s,config:l}})}var me=`
54
+ `;function _(e,n){let t=e.getAttribute(n)?.trim()??"";if(t==="")throw new A(y.invalid.missing(e.localName,n));return t}function he(e){let n=/\(([^)]+)\)/.exec(e.getAttribute("measure")??"")?.[1]?.trim(),t=e.getAttribute("by")?.split(".")[0];return[n,t,e.getAttribute("date-field")].filter(o=>!!o)}function Me(e){if(typeof e=="string"&&e.trim()==="")return null;let n=typeof e=="number"||typeof e=="string"?Number(e):NaN;return Number.isFinite(n)?n:null}var G=class{constructor(n){b(this,"block",n);b(this,"source",null);b(this,"onChange",()=>{this.block.isConnected?this.block.refresh():this.follow(null)})}follow(n){n!==this.source&&(this.source?.removeEventListener("cube-change",this.onChange),this.source=n,n?.addEventListener("cube-change",this.onChange))}};async function be(e,n,t,o=null){let a=Bn(_(e,"measure")),i=fe(e),r=e.getAttribute("period"),s=r===null||r===""?null:ct(e.getAttribute("date-field"),o,e.localName),l=await ut(e,r);return t.aborted?null:(n.follow(l),{fn:a.field===null?a.fn:`${a.fn}(${a.field})`,field:a.field,count:a.fn==="count",period:l?.value??null,filterFor:u=>u===null||s===null?i:{...i,...lt(s,u)}})}async function dt(e,n,t,o,a){try{return await e.resource(n).aggregate({fn:o.fn,group:t,filter:o.filterFor(o.period)},{signal:a})}catch(i){throw N(i)&&i.status===422&&(i.reason==="too_many_groups"||i.code==="cardinality_exceeded")?new J({kind:"error",detail:y.tooManyGroups,retry:!1}):i}}function X(e,n,t,o){let a=e.getAttribute(n),i=a===null||a.trim()===""?NaN:Number(a);return Number.isFinite(i)&&i>=t?Math.floor(i):o}async function pt(e,n,t,o,a,i){let r=a.descending?-1:1,s=t.filter(c=>c[o.by]!==null&&c[o.by]!==void 0).map(c=>({key:String(c[o.by]),value:Me(c[o.fn])})).filter(c=>c.value!==null).sort((c,p)=>r*(c.value-p.value)).slice(0,a.limit),l=e.getAttribute("lookup"),u=l===null||l===""||s.length===0?null:await cr(n,l,s.map(c=>c.key),i);return i.aborted?null:s.map(c=>({...c,label:u===null?c.key:u.get(c.key)??`#${c.key}`}))}function ye(e,n){let t=e.getAttribute("format"),o=t!==null&&Bi.includes(t)?t:n?"integer":"number",a=e.getAttribute("currency")||"EUR";return(i,r)=>I(i,o,{currency:a,compact:r===!0})}var Le=Symbol("cube-field hidden");function dr(e){var n,t;return class extends(t=e.HTMLElement,n=Le,t){constructor(){super(...arguments);b(this,n)}connectedCallback(){this[Le]===void 0&&(this[Le]=this.hasAttribute("hidden")),this.hidden=!0}}}function mt(e){let n=e.field?.enum??null;return e.config?.options??(n===null?null:n.map(t=>({value:t,label:t})))}var Ui=["text","number","integer","currency","percent","date","datetime","boolean"];function Z(e){let n=(e??"").split(",").map(t=>t.trim()).filter(t=>t!=="");return n.length>0?n:null}function qt(e){if(e===null)return null;let n=e.split(",").map(t=>{let o=t.indexOf("="),a=(o<0?t:t.slice(0,o)).trim(),i=o<0?a:t.slice(o+1).trim();return{value:a,label:i===""?a:i}}).filter(t=>t.value!=="");return n.length>0?n:null}function W(e){let n=new Map;for(let t of Array.from(e.children)){let o=t.getAttribute("name")?.trim()??"";if(t.localName!=="cube-field"||o==="")continue;let a=t.getAttribute("format"),i=t[Le];n.set(o,{name:o,label:t.getAttribute("label"),format:a!==null&&Ui.includes(a)?a:null,multiline:t.hasAttribute("multiline"),options:qt(t.getAttribute("options")),hidden:i??t.hasAttribute("hidden")})}return n}function Fe(e,n){return e.get(n)?.label??K(n)}function ee(e,n,t,o){let a=e!==null&&e.summary.length>0?e.summary:null;return(n??a??(o===void 0?[]:Object.keys(o))).filter(r=>t.get(r)?.hidden!==!0).map(r=>{let s=e?.fields.find(u=>u.name===r),l=t.get(r);return{name:r,label:Fe(t,r),format:l?.format??Un(s,o?.[r]),field:s,config:l}})}var we=`
55
55
  .field{display:flex;flex-direction:column;gap:.25rem;min-width:0}
56
56
  .field label{font-weight:600}
57
57
  .field .required{font-weight:400;color:var(--cube-color-text-muted)}
@@ -59,7 +59,7 @@ background:var(--cube-color-surface)}
59
59
  .field.check input{min-height:auto;width:1.25rem;height:1.25rem}
60
60
  .field [aria-invalid=true]{border-color:var(--cube-color-danger,#b42318)}
61
61
  .field-error{margin:0;color:var(--cube-color-danger,#b42318);font-size:.875rem}
62
- `,wi=/^-?(\d{1,3}(\.\d{3})+|\d*)(,\d+)?$/,vi=/^-?[1-9]\d{0,2}(\.\d{3})+$/,ki=/^-?(\d+\.?\d*|\.\d+)$/,Si=0;function xi(e){return e.includes(",")?wi.test(e)&&/\d/.test(e)?Number(e.replace(/\./g,"").replace(",",".")):null:vi.test(e)?Number(e.replace(/\./g,"")):ki.test(e)?Number(e):null}var tr=e=>Number(e.toPrecision(12));function Ae(e,n){if(e.trim()==="")return{value:null};if(Y.includes(n)){let t=xi(e.replace(/[\s €%]/g,""));return t===null||!Number.isFinite(t)?{error:y.notANumber}:n==="integer"&&!Number.isInteger(t)?{error:y.notAnInteger}:{value:n==="percent"?tr(t/100):t}}if(n==="boolean")return{value:e==="true"||e==="1"};if(n==="datetime"){let t=Date.parse(e);return{value:Number.isNaN(t)?e:new Date(t).toISOString()}}return{value:e}}function nr(e){if(!F(e)||e.status!==422||e.errors===null)return null;let n={};for(let[t,o]of Object.entries(e.errors)){let a=Array.isArray(o)?o.find(i=>typeof i=="string"):void 0;a!==void 0&&(n[t]=a)}return Object.keys(n).length>0?n:null}function Ti(e,n){if(e==null)return"";if(Y.includes(n)){let t=typeof e=="number"?e:Number(e);return typeof e=="boolean"||!Number.isFinite(t)?String(e):String(n==="percent"?tr(t*100):t).replace(".",",")}if(n==="date"&&typeof e=="string")return e.slice(0,10);if(n==="datetime"&&typeof e=="string"){let t=Date.parse(e);if(Number.isNaN(t))return e;let o=new Date(t),a=i=>String(i).padStart(2,"0");return`${O(o)}T${a(o.getHours())}:${a(o.getMinutes())}`}return typeof e=="object"?JSON.stringify(e):String(e)}function Ri(e,n,t,o){let a=ot(n),i=Ti(t,n.format);if(a!==null){let u=a.some(f=>f.value===i),c=i===""||u?a:[...a,{value:i,label:i}],p=h(e,"select",{id:o,name:n.name},h(e,"option",{value:""},y.emptyValue),...c.map(f=>h(e,"option",{value:f.value},f.label)));return p.value=i,p}if(n.format==="text"&&n.config?.multiline===!0){let u=h(e,"textarea",{id:o,name:n.name,rows:"4"});return u.value=i,u}let r=Y.includes(n.format),s=n.format==="date"?"date":n.format==="datetime"?"datetime-local":"text",l=h(e,"input",{id:o,name:n.name,type:n.format==="boolean"?"checkbox":s,inputmode:r?"decimal":null});return n.format==="boolean"?l.checked=t===!0||t==="true"||t===1:l.value=i,l}function fe(e,n,t,o){let a=`cube-input-${++Si}`,i=Ri(e,n,t,a),r=i.getAttribute("type")==="checkbox";o&&!r&&i.setAttribute("aria-required","true");let s=o&&!r?h(e,"span",{class:"required","aria-hidden":"true"},y.requiredMark):null,l=h(e,"label",{for:a},n.label,s),u=h(e,"p",{id:`${a}-error`,class:"field-error",hidden:!0});return{element:h(e,"div",{class:r?"field check":"field"},...r?[i,l]:[l,i],u),name:n.name,read(){return r?{value:i.checked}:o&&i.value.trim()===""?{error:y.required}:Ae(i.value,n.format)},setError(p){u.textContent=p??"",u.hidden=p===null,p===null?(i.removeAttribute("aria-invalid"),i.removeAttribute("aria-describedby")):(i.setAttribute("aria-invalid","true"),i.setAttribute("aria-describedby",u.id))}}}var ge=`
62
+ `,Hi=/^-?(\d{1,3}(\.\d{3})+|\d*)(,\d+)?$/,zi=/^-?[1-9]\d{0,2}(\.\d{3})+$/,Vi=/^-?(\d+\.?\d*|\.\d+)$/,Ki=0;function qi(e){return e.includes(",")?Hi.test(e)&&/\d/.test(e)?Number(e.replace(/\./g,"").replace(",",".")):null:zi.test(e)?Number(e.replace(/\./g,"")):Vi.test(e)?Number(e):null}var pr=e=>Number(e.toPrecision(12));function _e(e,n){if(e.trim()==="")return{value:null};if(ne.includes(n)){let t=qi(e.replace(/[\s €%]/g,""));return t===null||!Number.isFinite(t)?{error:y.notANumber}:n==="integer"&&!Number.isInteger(t)?{error:y.notAnInteger}:{value:n==="percent"?pr(t/100):t}}if(n==="boolean")return{value:e==="true"||e==="1"};if(n==="datetime"){let t=Date.parse(e);return{value:Number.isNaN(t)?e:new Date(t).toISOString()}}return{value:e}}function mr(e){if(!N(e)||e.status!==422||e.errors===null)return null;let n={};for(let[t,o]of Object.entries(e.errors)){let a=Array.isArray(o)?o.find(i=>typeof i=="string"):void 0;a!==void 0&&(n[t]=a)}return Object.keys(n).length>0?n:null}function Gi(e,n){if(e==null)return"";if(ne.includes(n)){let t=typeof e=="number"?e:Number(e);return typeof e=="boolean"||!Number.isFinite(t)?String(e):String(n==="percent"?pr(t*100):t).replace(".",",")}if(n==="date"&&typeof e=="string")return e.slice(0,10);if(n==="datetime"&&typeof e=="string"){let t=Date.parse(e);if(Number.isNaN(t))return e;let o=new Date(t),a=i=>String(i).padStart(2,"0");return`${U(o)}T${a(o.getHours())}:${a(o.getMinutes())}`}return typeof e=="object"?JSON.stringify(e):String(e)}function Wi(e,n,t,o){let a=mt(n),i=Gi(t,n.format);if(a!==null){let u=a.some(m=>m.value===i),c=i===""||u?a:[...a,{value:i,label:i}],p=h(e,"select",{id:o,name:n.name},h(e,"option",{value:""},y.emptyValue),...c.map(m=>h(e,"option",{value:m.value},m.label)));return p.value=i,p}if(n.format==="text"&&n.config?.multiline===!0){let u=h(e,"textarea",{id:o,name:n.name,rows:"4"});return u.value=i,u}let r=ne.includes(n.format),s=n.format==="date"?"date":n.format==="datetime"?"datetime-local":"text",l=h(e,"input",{id:o,name:n.name,type:n.format==="boolean"?"checkbox":s,inputmode:r?"decimal":null});return n.format==="boolean"?l.checked=t===!0||t==="true"||t===1:l.value=i,l}function ve(e,n,t,o){let a=`cube-input-${++Ki}`,i=Wi(e,n,t,a),r=i.getAttribute("type")==="checkbox";o&&!r&&i.setAttribute("aria-required","true");let s=o&&!r?h(e,"span",{class:"required","aria-hidden":"true"},y.requiredMark):null,l=h(e,"label",{for:a},n.label,s),u=h(e,"p",{id:`${a}-error`,class:"field-error",hidden:!0});return{element:h(e,"div",{class:r?"field check":"field"},...r?[i,l]:[l,i],u),name:n.name,read(){return r?{value:i.checked}:o&&i.value.trim()===""?{error:y.required}:_e(i.value,n.format)},setError(p){u.textContent=p??"",u.hidden=p===null,p===null?(i.removeAttribute("aria-invalid"),i.removeAttribute("aria-describedby")):(i.setAttribute("aria-invalid","true"),i.setAttribute("aria-describedby",u.id))}}}var ke=`
63
63
  form{display:flex;flex-direction:column;gap:1rem}
64
64
  .actions{display:flex;flex-wrap:wrap;gap:.5rem;margin-top:1rem}
65
65
  .alert{margin:0 0 1rem;padding:.75rem 1rem;border:1px solid var(--cube-color-danger,#b42318);
@@ -69,15 +69,18 @@ border-radius:var(--cube-radius-small)}
69
69
  .alert button{margin-top:.5rem}
70
70
  .status{margin:.5rem 0 0}
71
71
  .status:empty{margin:0}
72
- `;function he(e,n){return e?.body===n?e:{key:en(),body:n}}function Ee(e,n,t,o){T(n),n.append(h(e,"p",{},t),...o==null?[]:[o]),n.hidden=!1,n.focus()}function it(e,n,t,o,a){let i=nr(t);if(i!==null){for(let u of o)u.setError(i[u.name]??null);let s=Object.entries(i).filter(([u])=>!o.some(c=>c.name===u)),l=s.length===0?null:h(e,"ul",{},...s.map(([u,c])=>h(e,"li",{},`${a(u)}: ${c}`)));Ee(e,n,y.formInvalid,l);return}let r=X(t).kind;Ee(e,n,r==="forbidden"?y.forbidden:r==="signed-out"?y.signedOut:y.saveFailed)}function re(e){let n=e?.user()??null;return n===null?null:String(n.id)}var Ci=`${M}${ge}
72
+ `;function Se(e,n){return e?.body===n?e:{key:cn(),body:n}}function Oe(e,n,t,o){C(n),n.append(h(e,"p",{},t),...o==null?[]:[o]),n.hidden=!1,n.focus()}function ft(e,n,t,o,a){let i=mr(t);if(i!==null){for(let u of o)u.setError(i[u.name]??null);let s=Object.entries(i).filter(([u])=>!o.some(c=>c.name===u)),l=s.length===0?null:h(e,"ul",{},...s.map(([u,c])=>h(e,"li",{},`${a(u)}: ${c}`)));Oe(e,n,y.formInvalid,l);return}let r=Y(t).kind;Oe(e,n,r==="forbidden"?y.forbidden:r==="signed-out"?y.signedOut:y.saveFailed)}function le(e){let n=e?.user()??null;return n===null?null:String(n.id)}var Qi=`${O}${ke}
73
73
  .board{display:grid;grid-auto-flow:column;grid-auto-columns:minmax(14rem,1fr);gap:1rem;
74
74
  position:relative;overflow-x:auto}
75
75
  @media (max-width:640px){.board{grid-auto-flow:row;grid-auto-columns:auto}}
76
76
  section{min-width:0}
77
77
  h3{margin:0 0 .5rem;font-size:1rem}
78
78
  article{margin-top:.5rem;padding:.75rem;border:1px solid var(--cube-color-border);
79
- border-radius:var(--cube-radius-small);background:var(--cube-color-bg);overflow-wrap:anywhere}
79
+ border-radius:var(--cube-radius-small);background:var(--cube-color-bg);overflow-wrap:anywhere;
80
+ cursor:pointer}
80
81
  article[draggable=true]{cursor:grab}
82
+ article.chosen{border-color:var(--cube-color-primary);background:var(--cube-color-primary-subtle);
83
+ box-shadow:inset 4px 0 0 var(--cube-color-primary)}
81
84
  .title{margin:0;font-weight:600}
82
85
  dl{display:grid;grid-template-columns:auto 1fr;gap:0 .5rem;margin:.25rem 0 0;font-size:.875rem}
83
86
  dd{margin:0;min-width:0}
@@ -86,7 +89,7 @@ dd{margin:0;min-width:0}
86
89
  .moves button::before{content:"\\2192 "}
87
90
  .muted{margin:.5rem 0 0}
88
91
  .not-saved{display:inline-block;margin-bottom:.75rem}
89
- `,st=e=>String(e.id);function Ai(e){if(F(e)&&(e.status===409||e.status===412))return y.changedMeanwhile;let n=X(e).kind;return n==="forbidden"?y.forbidden:n==="signed-out"?y.signedOut:y.tryAgain}function rr(e,n){let t=n.document;class o extends e{constructor(){super();b(this,"alert",h(t,"div",{class:"alert",role:"alert",hidden:!0}));b(this,"loaded",null);b(this,"tracks",new Map);b(this,"pending",0);b(this,"stale",!1);b(this,"own",!1);b(this,"dragged",null);b(this,"focusKey",null);b(this,"attempt",null);b(this,"ids",0);this.shadowRoot?.insertBefore(this.alert,this.body)}shownFields(){let r=this.loaded;return r===null?[]:[r.status,r.title,...r.fields.map(s=>s.name)]}refresh(){if(this.own)return Promise.resolve();if(this.pending>0)return this.stale=!0,Promise.resolve();this.stale=!1;let r=this.shadowRoot?.activeElement?.closest("article")?.getAttribute("data-id");return r!=null&&(this.focusKey=r),super.refresh()}async load(r,s){if(s===null)return;this.loaded=null;let l=C(this,"resource"),u=C(this,"status-field"),c=C(this,"title-field"),p=le(this),f=Math.min(G(this,"page-size",1,50),200),m=this.attr("sort")?.trim()??"",d=await s.schema(l);if(r.aborted)return;let g=d?.fields.find(D=>D.name===u),w=W(this.attr("fields")),v=w===null?[]:Q(d,w,V(this)),k={fields:[...new Set(["id",c,u,...v.map(D=>D.name)])],page:{size:f}};m!==""&&(k.sort=m);let x=s.resource(l),P=await Promise.all(this.columnValues(g?.enum??null).map(async D=>{let{data:S,meta:E}=await x.list({...k,filter:{...p,[u]:D.value}},{signal:r});return{...D,rows:[...S],total:E.page?.total??S.length}}));if(r.aborted)return;let A={session:s,user:re(s),resource:l,status:u,title:c,fields:v,columns:P,canMove:d!==null&&d.actions.includes("update")&&g?.readonly===!1};this.loaded=A,this.tracks.clear(),this.render(A)}columnValues(r){let s=Array.from(this.children).filter(u=>u.localName==="cube-column"),l=s.length>0?s.map(u=>{let c=C(u,"value");return{value:c,label:u.getAttribute("label")?.trim()||U(c)}}):(r??[]).map(u=>({value:u,label:U(u)}));if(l.length===0)throw new q({kind:"error",detail:y.noColumns,retry:!1});return l}render(r){let s=new Map;T(this.body),this.body.append(...[r.canMove&&this.notSaved(r.session),h(t,"div",{class:"board"},...r.columns.map(u=>this.column(r,u,s)))].filter(u=>!!u));let l=this.focusKey;this.focusKey=null,l!==null&&s.get(l)?.focus()}column(r,s,l){let u=`b${++this.ids}`,c=s.total-s.rows.length;return h(t,"section",{class:"card","aria-labelledby":u,ondragover:p=>{r.canMove&&this.dragged!==null&&p.preventDefault()},ondrop:p=>{p.preventDefault();let f=this.dragged;this.dragged=null,f!==null&&this.move(r,f,s.value)}},h(t,"h3",{id:u},s.label," ",h(t,"span",{class:"badge"},`${s.total}`)),...s.rows.length===0?[h(t,"p",{class:"muted"},y.emptyColumn)]:s.rows.map(p=>this.card(r,s,p,l)),c>0?h(t,"p",{class:"muted"},y.more(c)):null)}card(r,s,l,u){let c=st(l),p=`b${++this.ids}`,f=h(t,"article",{tabindex:"0",draggable:r.canMove?"true":"false","data-id":c,"aria-labelledby":p,ondragstart:m=>{this.dragged=c,m.dataTransfer?.setData("text/plain",c)},ondragend:()=>{this.dragged=null}},h(t,"p",{class:"title",id:p},_(l[r.title],"text")),r.fields.length===0?null:h(t,"dl",{},...r.fields.flatMap(m=>[h(t,"dt",{},m.label),h(t,"dd",{},_(l[m.name],m.format))])),r.canMove?h(t,"div",{class:"moves"},...r.columns.filter(m=>m!==s).map(m=>h(t,"button",{type:"button",class:"secondary","aria-label":y.moveTo(m.label),"aria-describedby":p,onclick:()=>this.move(r,c,m.value)},m.label))):null);return u.set(c,f),f}place(r,s,l){let u=r.columns.find(c=>c.value===l);for(let c of r.columns){let p=c.rows.findIndex(m=>st(m)===s),f=c.rows[p];if(!(f===void 0||u===void 0))return c.rows.splice(p,1),c.total--,u.rows.unshift(f),u.total++,{row:f,from:c.value}}return null}move(r,s,l){let u=r.columns.find(w=>w.rows.some(v=>st(v)===s));if(!r.canMove||this.loaded!==r||u===void 0||u.value===l)return;let c=this.place(r,s,l);if(c===null)return;let{row:p,from:f}=c;this.alert.hidden=!0,this.focusKey=s,this.render(r);let m=this.tracks.get(s);m===void 0&&(m={confirmed:f,tail:Promise.resolve(),generation:0},this.tracks.set(s,m));let d=m,g=d.generation;this.pending++,d.tail=d.tail.then(()=>g===d.generation?this.send(r,d,p,f,l):void 0).finally(()=>{--this.pending===0&&this.stale&&this.refresh()})}async send(r,s,l,u,c){let p=st(l),f={[r.status]:c},m=he(this.attempt,JSON.stringify([r.resource,p,f]));this.attempt=m;try{let d=await this.session();if(re(d)!==r.user){s.generation++,this.stale=!0;return}await d.resource(r.resource).update(l.id,f,{idempotencyKey:m.key}),this.attempt===m&&(this.attempt=null),s.confirmed=c,this.emit("cube-move",{resource:r.resource,id:l.id,from:u,to:c}),this.own=!0,this.emit("cube-data-change",{resource:r.resource}),queueMicrotask(()=>{this.own=!1})}catch(d){if(F(d)&&this.attempt===m&&(this.attempt=null),s.generation++,F(d)&&(d.status===409||d.status===412)&&(this.stale=!0),this.loaded!==r)return;this.place(r,p,s.confirmed),this.focusKey=p,this.render(r),T(this.alert),this.alert.append(`${y.moveFailed} ${Ai(d)}`),this.alert.hidden=!1}}}return b(o,"tag","cube-board"),b(o,"css",Ci),o}var Ei=`${M}${ue}${me}
92
+ `,gt=e=>String(e.id);function Ji(e){return e.split(",").map(n=>n.trim()).filter(n=>n!=="").map(n=>({field:n.replace(/^[-+]/,""),descending:n.startsWith("-")}))}function Yi(e,n){if(e==null||n==null)return e==null?n==null?0:-1:1;if(typeof e=="number"&&typeof n=="number")return e-n;if(typeof e=="boolean"||typeof n=="boolean")return+(e===!0||e===1||e==="1")-+(n===!0||n===1||n==="1");let t=String(e),o=String(n);return t<o?-1:t>o?1:0}function Xi(e,n,t){for(let{field:o,descending:a}of e){let i=Yi(n[o],t[o]);if(i!==0)return a?-i:i}return 0}function fr(e,n){return e.numeric&&Number.isFinite(Number(n))?Number(n):n}function Zi(e){if(N(e)&&(e.status===409||e.status===412))return y.changedMeanwhile;let n=Y(e).kind;return n==="forbidden"?y.forbidden:n==="signed-out"?y.signedOut:y.tryAgain}function gr(e,n){let t=n.document;class o extends e{constructor(){super();b(this,"alert",h(t,"div",{class:"alert",role:"alert",hidden:!0}));b(this,"loaded",null);b(this,"tracks",new Map);b(this,"pending",0);b(this,"stale",!1);b(this,"dragged",null);b(this,"focusKey",null);b(this,"attempt",null);b(this,"ids",0);b(this,"shownResource",null);b(this,"chosen",null);this.shadowRoot?.insertBefore(this.alert,this.body)}shownFields(){let r=this.loaded;return r===null?[]:[r.status,r.title,...r.fields.map(s=>s.name)]}refresh(){if(this.pending>0)return this.stale=!0,Promise.resolve();this.stale=!1;let r=this.shadowRoot?.activeElement?.closest("article")?.getAttribute("data-id");return r!=null&&(this.focusKey=r),super.refresh()}async load(r,s){if(s===null)return;this.loaded=null;let l=_(this,"resource"),u=_(this,"status-field"),c=_(this,"title-field");l!==this.shownResource&&(this.chosen=null,this.shownResource=l),this.detailTarget();let p=fe(this),m=Math.min(X(this,"page-size",1,50),200),f=this.attr("sort")?.trim()??"",d=Ji(f),g=await s.schema(l);if(r.aborted)return;let w=g?.fields.find(F=>F.name===u),v=g===null||g.fields.some(F=>F.name==="id"),k=Z(this.attr("fields")),S=k===null?[]:ee(g,k,W(this)),R={fields:[...new Set([...v?["id"]:[],c,u,...S.map(F=>F.name),...d.map(F=>F.field)])],page:{size:m}};f!==""&&(R.sort=f);let L=s.resource(l),j=await Promise.all(this.columnValues(w?.enum??null).map(async F=>{let{data:T,meta:E}=await L.list({...R,filter:{...p,[u]:F.value}},{signal:r});return{...F,rows:[...T],total:E.page?.total??T.length}}));if(r.aborted)return;let x={session:s,user:le(s),resource:l,status:u,title:c,fields:S,columns:j,canMove:v&&g!==null&&g.actions.includes("update")&&w?.readonly===!1,order:d,numeric:w?.type==="integer"||w?.type==="number"};this.loaded=x,this.tracks.clear(),this.render(x)}columnValues(r){let s=Array.from(this.children).filter(u=>u.localName==="cube-column"),l=s.length>0?s.map(u=>{let c=_(u,"value");return{value:c,label:u.getAttribute("label")?.trim()||K(c)}}):(r??[]).map(u=>({value:u,label:K(u)}));if(l.length===0)throw new J({kind:"error",detail:y.noColumns,retry:!1});return l}render(r){let s=new Map;C(this.body),this.body.append(...[r.canMove&&this.notSaved(r.session),h(t,"div",{class:"board"},...r.columns.map(u=>this.column(r,u,s)))].filter(u=>!!u));let l=this.focusKey;this.focusKey=null,l!==null&&s.get(l)?.focus()}column(r,s,l){let u=`b${++this.ids}`,c=s.total-s.rows.length;return h(t,"section",{class:"card",role:"group","aria-labelledby":u,ondragover:p=>{r.canMove&&this.dragged!==null&&p.preventDefault()},ondrop:p=>{p.preventDefault();let m=this.dragged;this.dragged=null,m!==null&&this.move(r,m,s.value)}},h(t,"h3",{id:u},s.label," ",h(t,"span",{class:"badge"},`${s.total}`)),...s.rows.length===0?[h(t,"p",{class:"muted"},y.emptyColumn)]:s.rows.map(p=>this.card(r,s,p,l)),c>0?h(t,"p",{class:"muted"},y.more(c)):null)}card(r,s,l,u){let c=gt(l),p=`b${++this.ids}`,m=l.id!=null&&c===this.chosen,f=h(t,"article",{tabindex:"0",draggable:r.canMove?"true":"false","data-id":c,"aria-labelledby":p,class:m?"chosen":null,"aria-current":m?"true":null,onclick:d=>{d.target.closest("button")===null&&this.select(r,l)},onkeydown:(d=>{d.target!==f||d.altKey||d.ctrlKey||d.metaKey||d.key!=="Enter"&&d.key!==" "||(d.preventDefault(),this.select(r,l))}),ondragstart:d=>{this.dragged=c,d.dataTransfer?.setData("text/plain",c)},ondragend:()=>{this.dragged=null}},h(t,"p",{class:"title",id:p},I(l[r.title],"text")),r.fields.length===0?null:h(t,"dl",{},...r.fields.flatMap(d=>[h(t,"dt",{},d.label),h(t,"dd",{},I(l[d.name],d.format))])),r.canMove?h(t,"div",{class:"moves"},...r.columns.filter(d=>d!==s).map(d=>h(t,"button",{type:"button",class:"secondary","aria-label":y.moveTo(d.label),"aria-describedby":p,onclick:()=>this.move(r,c,d.value)},d.label))):null);return u.set(c,f),f}detailTarget(){let r=this.attr("detail")?.trim()??"";if(r==="")return null;try{return t.querySelector(r)}catch{throw new A(y.invalid.selector(this.localName,"detail",r))}}select(r,s){let l=s.id??null;this.chosen=l===null?null:String(l);for(let c of Array.from(this.body.querySelectorAll("article"))){let p=c.getAttribute("data-id")===this.chosen;c.classList.toggle("chosen",p),p?c.setAttribute("aria-current","true"):c.removeAttribute("aria-current")}if(this.emit("cube-select",{resource:r.resource,id:l,row:s}),l===null)return;let u=null;try{u=this.detailTarget()}catch(c){this.showState(Y(c));return}u?.setAttribute("record-id",String(l))}place(r,s,l){let u=r.columns.find(c=>c.value===l);for(let c of r.columns){let p=c.rows.findIndex(f=>gt(f)===s),m=c.rows[p];if(!(m===void 0||u===void 0)){if(c.rows.splice(p,1),c.total--,m[r.status]=fr(r,l),r.order.length===0)u.rows.unshift(m);else{let f=u.rows.findIndex(d=>Xi(r.order,d,m)>0);u.rows.splice(f===-1?u.rows.length:f,0,m)}return u.total++,{row:m,from:c.value}}}return null}move(r,s,l){let u=r.columns.find(w=>w.rows.some(v=>gt(v)===s));if(!r.canMove||this.loaded!==r||u===void 0||u.value===l)return;let c=this.place(r,s,l);if(c===null)return;let{row:p,from:m}=c;this.alert.hidden=!0,this.focusKey=s,this.render(r);let f=this.tracks.get(s);f===void 0&&(f={confirmed:m,tail:Promise.resolve(),generation:0},this.tracks.set(s,f));let d=f,g=d.generation;this.pending++,d.tail=d.tail.then(()=>g===d.generation?this.send(r,d,p,m,l):void 0).finally(()=>{--this.pending===0&&this.stale&&this.refresh()})}async send(r,s,l,u,c){let p=gt(l),m={[r.status]:fr(r,c)},f=Se(this.attempt,JSON.stringify([r.resource,p,m]));this.attempt=f;try{let d=await this.session();if(le(d)!==r.user){s.generation++,this.stale=!0;return}await d.resource(r.resource).update(l.id,m,{idempotencyKey:f.key}),this.attempt===f&&(this.attempt=null),s.confirmed=c,this.emit("cube-move",{resource:r.resource,id:l.id,from:u,to:c}),this.emit("cube-data-change",{resource:r.resource})}catch(d){if(N(d)&&this.attempt===f&&(this.attempt=null),s.generation++,N(d)&&(d.status===409||d.status===412)&&(this.stale=!0),this.loaded!==r)return;this.place(r,p,s.confirmed),this.focusKey=p,this.render(r),C(this.alert),this.alert.append(`${y.moveFailed} ${Zi(d)}`),this.alert.hidden=!1}}}return b(o,"tag","cube-board"),b(o,"css",Qi),b(o,"reloadsOnOwnChange",!1),o}var es=`${O}${ge}${we}
90
93
  .inputs{display:grid;gap:1rem;grid-template-columns:repeat(auto-fit,minmax(12rem,1fr))}
91
94
  .inputs:empty{display:none}
92
95
  .results{display:flex;flex-wrap:wrap;gap:1rem 2rem;margin-top:1.25rem;padding-top:1rem;
@@ -97,7 +100,8 @@ border-top:1px solid var(--cube-color-border)}
97
100
  .result output{font-size:1.25rem;font-weight:600;font-variant-numeric:tabular-nums;overflow-wrap:anywhere}
98
101
  .result.emphasis output{font-size:2rem;font-weight:700;line-height:1.2}
99
102
  .alert{margin:1rem 0 0;color:var(--cube-color-danger,#b42318)}
100
- `,Mi=["number","integer","currency","percent","text","select","checkbox"],Di=["number","integer","currency","percent","text"],or=0;function ir(e,n,t){let o=e.getAttribute(n)?.trim()??"",a=o===""?t[0]:o;if(!t.includes(a))throw new TypeError(y.invalid.value(e.localName,n,a));return a}function It(e,n){let t=e.getAttribute(n)?.trim()??"";if(t==="")return null;let o=Number(t);if(!Number.isFinite(o)||n==="step"&&o<=0)throw new TypeError(y.invalid.number(e.localName,n));return o}var Me=e=>_(e,"number");function sr(e){let n=e.editor.read();if("error"in n||typeof n.value!="number")return n;let t=e.format==="percent"?Number((n.value*100).toPrecision(12)):n.value,{min:o,max:a,step:i}=e;if(o!==null&&t<o||a!==null&&t>a)return{error:o===null?y.atMost(Me(a)):a===null?y.atLeast(Me(o)):y.range(Me(o),Me(a))};if(i!==null){let r=(t-(o??0))/i;if(Math.abs(r-Math.round(r))>1e-9)return{error:y.step(Me(i))}}return n}function ar(e,n){let t=n.document;class o extends e{constructor(){super();b(this,"fn",null);b(this,"drawn",null);b(this,"shownValues",{});b(this,"shownResults",{});let l=Object.getOwnPropertyDescriptor(this,"formula");l!==void 0&&(delete this.formula,this.fn=l.value)}get formula(){return typeof this.fn=="function"?this.fn:null}set formula(l){this.fn=l,this.drawn!==null&&(l===null||typeof l=="function")?this.calculate(!0):(this.drawn=null,this.refresh())}get values(){return{...this.shownValues}}get results(){return{...this.shownResults}}refresh(){return this.drawn!==null&&this.drawn.label===this.attr("label")?Promise.resolve():(this.drawn=null,super.refresh())}async load(){if(this.drawn=null,this.fn!==null&&typeof this.fn!="function")throw new q({kind:"error",detail:y.invalid.formula,retry:!1});let l=Array.from(this.children),u=l.filter(g=>g.localName==="cube-input").map(a),c=l.filter(g=>g.localName==="cube-result").map(i);if(c.length===0)throw new TypeError(y.invalid.missing(this.localName,"cube-result"));let p=this.attr("label"),f=p===null||p.trim()===""?null:h(t,"p",{class:"label",id:`cube-calc-${++or}`},p),m=h(t,"p",{class:"alert",role:"alert",hidden:!0}),d=h(t,"form",{novalidate:!0,"aria-labelledby":f?.id??null},h(t,"div",{class:"inputs"},...u.map(g=>g.editor.element)),h(t,"div",{class:"results","aria-live":"polite"},...c.map(g=>g.element)),m);d.addEventListener("submit",g=>g.preventDefault()),d.addEventListener("input",()=>this.calculate(!0)),d.addEventListener("change",()=>this.showErrors()),T(this.body),this.body.appendChild(h(t,"div",{class:"card"},f,d)),this.drawn={label:p,inputs:u,results:c,alert:m},this.showErrors(),this.calculate(!1)}showErrors(){for(let l of this.drawn?.inputs??[]){let u=sr(l);l.shown="error"in u,l.editor.setError("error"in u?u.error:null)}}calculate(l){let u=this.drawn;if(u===null)return;let c={};for(let m of u.inputs){let d=sr(m);c[m.editor.name]="error"in d?null:d.value,m.shown&&(m.shown="error"in d,m.editor.setError("error"in d?d.error:null))}let p={},f=!1;try{let m=this.formula,d=m===null?null:m({...c}),g=d===null||typeof d!="object";if(g&&d!==null&&d!==void 0&&u.results.length>1){this.drawn=null,this.showState({kind:"error",detail:y.invalid.calcSingle,retry:!1});return}for(let w of u.results){let v=g?d:d[w.name],k=typeof v=="number"&&!Number.isFinite(v);f||(f=k),p[w.name]=k||v===void 0?null:v}}catch{f=!0;for(let m of u.results)p[m.name]=null}for(let m of u.results)m.output.textContent=_(p[m.name],m.format,{currency:m.currency});f&&u.alert.hidden&&(u.alert.textContent=y.calcFailed),f||(u.alert.textContent=""),u.alert.hidden=!f,this.shownValues=c,this.shownResults=p,l&&this.emit("cube-change",{values:{...c},results:{...p}})}}b(o,"tag","cube-calc"),b(o,"css",Ei),b(o,"needsSession",!1);function a(r){let s=C(r,"name"),l=C(r,"label"),u=ir(r,"type",Mi),c=u==="select"?"text":u==="checkbox"?"boolean":u,p=u==="checkbox"?null:jt(r.getAttribute("options"));if(u==="select"&&p===null)throw new TypeError(y.invalid.missing(r.localName,"options"));let f=r.getAttribute("value"),m=f===null?{value:null}:Ae(f,c);return{editor:fe(t,{name:s,label:l,format:c,field:void 0,config:{name:s,label:l,format:c,multiline:!1,options:p,hidden:!1}},"error"in m?f:m.value,!1),format:c,min:It(r,"min"),max:It(r,"max"),step:It(r,"step"),shown:!1}}function i(r){let s=C(r,"name"),l=C(r,"label"),u=ir(r,"format",Di),c=r.getAttribute("currency")?.trim().toUpperCase()||"EUR";try{_(0,"currency",{currency:c})}catch{throw new TypeError(y.invalid.value(r.localName,"currency",c))}let p=`cube-result-${++or}`,f=h(t,"output",{id:p,name:s}),m=r.hasAttribute("emphasis")&&r.getAttribute("emphasis")!=="false",d=h(t,"div",{class:m?"result emphasis":"result"},h(t,"label",{for:p},l),f);return{name:s,format:u,currency:c,element:d,output:f}}return o}var De=56,Bt=8,lr=8,Li=24,Ut=7,ur=8;function Fi(e,n,t=4){let o=Math.min(e,0),a=Math.max(n,0);if(a<=o)return[0,1];let i=(a-o)/t,r=10**Math.floor(Math.log10(i)),s=i/r,l=(s<=1?1:s<=2?2:s<=5?5:10)*r,u=[];for(let c=Math.floor(o/l);c<=Math.ceil(a/l);c++)u.push(Number((c*l).toPrecision(12)));return u}function _i(e,n,t,o){let a=Math.max(1,Math.floor(t/Ut)),i=n.length<=a?n:`${n.slice(0,a-1)}\u2026`,r=i.length*Ut/2,s=Math.min(Math.max(o.x,o.left+r),o.right-r),l=N(e,"text",{class:"x",x:s,y:o.y},i);return i!==n&&l.append(N(e,"title",{},n)),l}function cr(e,n,t,o){let{width:a,height:i}=t,r=n.points.map(S=>S.value??0),s=Fi(Math.min(...r),Math.max(...r)),l=s[0]??0,u=(s.at(-1)??1)-l||1,c=i-lr-Li,p=Math.max(a-De-Bt,1),f=n.points.length,m=p/Math.max(f,1),d=S=>lr+c*(1-(S-l)/u),g=S=>De+m*(S+.5),w=N(e,"svg",{viewBox:`0 0 ${a} ${i}`,width:"100%",height:i,role:"img","aria-label":`${n.label}, ${y.points(f)}`});for(let S of s)w.append(N(e,"line",{class:"grid",x1:De,x2:a-Bt,y1:d(S),y2:d(S)}),N(e,"text",{class:"tick",x:De-6,y:d(S)+4},o(S,!0)));let v=n.points.map(S=>S.tick??S.label),k=Math.max(1,...v.map(S=>S.length)),x=n.categories===!0?1:Math.ceil(f/Math.max(1,Math.floor(p/(k*Ut+ur)))),P=n.points.map((S,E)=>E).filter(S=>S%x===0),A=m*x-ur/2;for(let S of P){let E={x:g(S),y:i-6,left:De,right:a-Bt};w.append(_i(e,v[S]??"",A,E))}return{root:w,band:m,x:g,y:d,title:S=>N(e,"title",{},`${S.label}: ${S.value===null?y.emptyValue:o(S.value)}`)}}function dr(e,n,t,o){let{root:a,x:i,y:r,title:s}=cr(e,n,t,o),l="",u="M";return n.points.forEach((c,p)=>{if(c.value===null){u="M";return}l+=`${u}${i(p).toFixed(1)} ${r(c.value).toFixed(1)}`,u="L"}),a.append(N(e,"path",{class:"s1",d:l})),n.points.forEach((c,p)=>{c.value!==null&&a.append(N(e,"circle",{class:"s1",cx:i(p),cy:r(c.value),r:3},s(c)))}),a}function pr(e,n,t,o){let{root:a,band:i,x:r,y:s,title:l}=cr(e,n,t,o),u=i*.7;return n.points.forEach((c,p)=>{let f=s(Math.max(c.value??0,0)),m=s(Math.min(c.value??0,0));a.append(N(e,"rect",{class:"s1",x:r(p)-u/2,y:f,width:u,height:m-f},l(c)))}),a}var Ht=864e5,$i=600,Oi=["line","bar"],Pi=`${M}${ue}
103
+ .alert:empty{margin:0}
104
+ `,ts=["number","integer","currency","percent","text","select","checkbox"],ns=["number","integer","currency","percent","text"],hr=0;function br(e,n,t){let o=e.getAttribute(n)?.trim()??"",a=o===""?t[0]:o;if(!t.includes(a))throw new A(y.invalid.value(e.localName,n,a));return a}function Gt(e,n){let t=e.getAttribute(n)?.trim()??"";if(t==="")return null;let o=Number(t);if(!Number.isFinite(o)||n==="step"&&o<=0)throw new A(y.invalid.number(e.localName,n));return o}var $e=e=>I(e,"number");function yr(e){let n=e.editor.read();if("error"in n||typeof n.value!="number")return n;let t=e.format==="percent"?Number((n.value*100).toPrecision(12)):n.value,{min:o,max:a,step:i}=e;if(o!==null&&t<o||a!==null&&t>a)return{error:o===null?y.atMost($e(a)):a===null?y.atLeast($e(o)):y.range($e(o),$e(a))};if(i!==null){let r=(t-(o??0))/i;if(Math.abs(r-Math.round(r))>1e-9)return{error:y.step($e(i))}}return n}function wr(e,n){let t=n.document;class o extends e{constructor(){super();b(this,"fn",null);b(this,"drawn",null);b(this,"shownValues",{});b(this,"shownResults",{});let u=Object.getOwnPropertyDescriptor(this,"formula");u!==void 0&&(delete this.formula,this.fn=u.value)}get formula(){return typeof this.fn=="function"?this.fn:null}set formula(u){this.fn=u,this.drawn!==null&&(u===null||typeof u=="function")?this.calculate(!0):(this.drawn=null,this.refresh())}get values(){return{...this.shownValues}}get results(){return{...this.shownResults}}refresh(){return this.drawn!==null&&this.drawn.label===this.attr("label")?Promise.resolve():(this.drawn=null,super.refresh())}async load(){if(this.drawn=null,this.fn!==null&&typeof this.fn!="function")throw new J({kind:"error",detail:y.invalid.formula,retry:!1});let u=Array.from(this.children),c=u.filter(w=>w.localName==="cube-input").map(i),p=u.filter(w=>w.localName==="cube-result").map(r);if(p.length===0)throw new A(y.invalid.missing(this.localName,"cube-result"));a("cube-input",c.map(w=>w.editor.name)),a("cube-result",p.map(w=>w.name));let m=this.attr("label"),f=m===null||m.trim()===""?null:h(t,"p",{class:"label",id:`cube-calc-${++hr}`},m),d=h(t,"p",{class:"alert",role:"alert"}),g=h(t,"form",{novalidate:!0,"aria-labelledby":f?.id??null},h(t,"div",{class:"inputs"},...c.map(w=>w.editor.element)),h(t,"div",{class:"results","aria-live":"polite"},...p.map(w=>w.element)),d);g.addEventListener("submit",w=>w.preventDefault()),g.addEventListener("input",()=>this.calculate(!0,!0)),g.addEventListener("change",()=>this.showErrors()),C(this.body),this.body.appendChild(h(t,"div",{class:"card"},f,g)),this.drawn={label:m,inputs:c,results:p,alert:d},this.showErrors(),this.calculate(!1)}showErrors(){for(let u of this.drawn?.inputs??[]){let c=yr(u);u.shown="error"in c,u.editor.setError("error"in c?c.error:null)}}calculate(u,c=!1){let p=this.drawn;if(p===null)return;let m={};for(let g of p.inputs){let w=yr(g);m[g.editor.name]="error"in w?null:w.value,g.shown&&(g.shown="error"in w,g.editor.setError("error"in w?w.error:null))}let f={},d=!1;try{let g=this.formula,w=g===null?null:g({...m});if((typeof w=="object"||typeof w=="function")&&w!==null&&typeof w.then=="function"){this.drawn=null,this.showState({kind:"error",detail:y.invalid.calcAsync,retry:!1});return}let v=w===null||typeof w!="object";if(v&&w!==null&&w!==void 0&&p.results.length>1){if(c)throw new A(y.invalid.calcSingle);this.drawn=null,this.showState({kind:"error",detail:y.invalid.calcSingle,retry:!1});return}for(let k of p.results){let S=v?w:w[k.name],R=typeof S=="number"&&!Number.isFinite(S)||k.format!=="text"&&typeof S=="object"&&S!==null;d||(d=R),f[k.name]=R||S===void 0?null:S}}catch(g){p.alert.textContent===""&&console.warn(g),d=!0;for(let w of p.results)f[w.name]=null}for(let g of p.results)g.output.textContent=I(f[g.name],g.format,{currency:g.currency});d&&p.alert.textContent===""&&(p.alert.textContent=y.calcFailed),d||(p.alert.textContent=""),this.shownValues=m,this.shownResults=f,u&&this.emit("cube-change",{values:{...m},results:{...f}})}}b(o,"tag","cube-calc"),b(o,"css",es),b(o,"needsSession",!1);function a(s,l){let u=l.find((c,p)=>l.indexOf(c)!==p);if(u!==void 0)throw new A(y.invalid.duplicate(s,u))}function i(s){let l=_(s,"name"),u=_(s,"label"),c=br(s,"type",ts),p=c==="select"?"text":c==="checkbox"?"boolean":c,m=c==="checkbox"?null:qt(s.getAttribute("options"));if(c==="select"&&m===null)throw new A(y.invalid.missing(s.localName,"options"));let f=s.getAttribute("value"),d=f===null?{value:null}:_e(f,p);return{editor:ve(t,{name:l,label:u,format:p,field:void 0,config:{name:l,label:u,format:p,multiline:!1,options:m,hidden:!1}},"error"in d?f:d.value,!1),format:p,min:Gt(s,"min"),max:Gt(s,"max"),step:Gt(s,"step"),shown:!1}}function r(s){let l=_(s,"name"),u=_(s,"label"),c=br(s,"format",ns),p=s.getAttribute("currency")?.trim().toUpperCase()||"EUR";try{I(0,"currency",{currency:p})}catch{throw new A(y.invalid.value(s.localName,"currency",p))}let m=`cube-result-${++hr}`,f=h(t,"output",{id:m,name:l}),d=s.hasAttribute("emphasis")&&s.getAttribute("emphasis")!=="false",g=h(t,"div",{class:d?"result emphasis":"result"},h(t,"label",{for:m},u),f);return{name:l,format:c,currency:p,element:g,output:f}}return o}var Pe=56,Wt=8,vr=8,rs=24,Qt=7,kr=8;function os(e,n,t=4){let o=Math.min(e,0),a=Math.max(n,0);if(a<=o)return[0,1];let i=(a-o)/t,r=10**Math.floor(Math.log10(i)),s=i/r,l=(s<=1?1:s<=2?2:s<=5?5:10)*r,u=[];for(let c=Math.floor(o/l);c<=Math.ceil(a/l);c++)u.push(Number((c*l).toPrecision(12)));return u}function is(e,n,t,o){let a=Math.max(1,Math.floor(t/Qt)),i=n.length<=a?n:`${n.slice(0,a-1)}\u2026`,r=i.length*Qt/2,s=Math.min(Math.max(o.x,o.left+r),o.right-r),l=H(e,"text",{class:"x",x:s,y:o.y},i);return i!==n&&l.append(H(e,"title",{},n)),l}function Sr(e,n,t,o){let{width:a,height:i}=t,r=n.points.map(x=>x.value??0),s=os(Math.min(...r),Math.max(...r)),l=s[0]??0,u=(s.at(-1)??1)-l||1,c=i-vr-rs,p=Math.max(a-Pe-Wt,1),m=n.points.length,f=p/Math.max(m,1),d=x=>vr+c*(1-(x-l)/u),g=x=>Pe+f*(x+.5),w=H(e,"svg",{viewBox:`0 0 ${a} ${i}`,width:"100%",height:i,role:"img","aria-label":`${n.label}, ${y.points(m)}`});for(let x of s)w.append(H(e,"line",{class:"grid",x1:Pe,x2:a-Wt,y1:d(x),y2:d(x)}),H(e,"text",{class:"tick",x:Pe-6,y:d(x)+4},o(x,!0)));let v=n.points.map(x=>x.tick??x.label),k=Math.max(1,...v.map(x=>x.length)),S=n.categories===!0?1:Math.ceil(m/Math.max(1,Math.floor(p/(k*Qt+kr)))),R=n.points.map((x,F)=>F).filter(x=>x%S===0),L=f*S-kr/2;for(let x of R){let F={x:g(x),y:i-6,left:Pe,right:a-Wt};w.append(is(e,v[x]??"",L,F))}return{root:w,band:f,x:g,y:d,title:x=>H(e,"title",{},`${x.label}: ${x.value===null?y.emptyValue:o(x.value)}`)}}function xr(e,n,t,o){let{root:a,x:i,y:r,title:s}=Sr(e,n,t,o),l="",u="M";return n.points.forEach((c,p)=>{if(c.value===null){u="M";return}l+=`${u}${i(p).toFixed(1)} ${r(c.value).toFixed(1)}`,u="L"}),a.append(H(e,"path",{class:"s1",d:l})),n.points.forEach((c,p)=>{c.value!==null&&a.append(H(e,"circle",{class:"s1",cx:i(p),cy:r(c.value),r:3},s(c)))}),a}function Tr(e,n,t,o){let{root:a,band:i,x:r,y:s,title:l}=Sr(e,n,t,o),u=i*.7;return n.points.forEach((c,p)=>{let m=s(Math.max(c.value??0,0)),f=s(Math.min(c.value??0,0));a.append(H(e,"rect",{class:"s1",x:r(p)-u/2,y:m,width:u,height:f-m},l(c)))}),a}var Jt=864e5,ss=600,as=["line","bar"],ls=`${O}${ge}
101
105
  svg{display:block;overflow:visible}
102
106
  .grid{stroke:var(--cube-color-border)}
103
107
  .tick,.x{font-size:12px;fill:var(--cube-color-text-muted)}
@@ -105,11 +109,11 @@ svg{display:block;overflow:visible}
105
109
  .x{text-anchor:middle}
106
110
  rect.s1,circle.s1{fill:var(--cube-color-series-1)}
107
111
  path.s1{fill:none;stroke:var(--cube-color-series-1);stroke-width:2}
108
- `;function Ni(e,n){let t=e.toISOString().slice(0,10);switch(n){case"day":return t;case"week":{let o=new Date(e.getTime()+(3-(e.getUTCDay()+6)%7)*Ht),a=o.getUTCFullYear(),i=1+Math.floor((o.getTime()-Date.UTC(a,0,1))/(7*Ht));return`${a}-W${String(i).padStart(2,"0")}`}case"month":return t.slice(0,7);case"quarter":return`${t.slice(0,4)}-Q${Math.ceil((e.getUTCMonth()+1)/3)}`;case"year":return t.slice(0,4)}}function ji(e,n){let t=Mt(e,"month",{short:!0});return n||e.endsWith("-01")?y.monthYear(t,e.slice(0,4)):t}function mr(e,n,t){let o=new Set,a=Date.parse(`${n}T00:00:00Z`);for(let i=Date.parse(`${e}T00:00:00Z`);i<=a;i+=Ht)o.add(Ni(new Date(i),t));return[...o]}function fr(e,n){class t extends e{constructor(){super(...arguments);b(this,"period",new z(this));b(this,"plot",h(n.document,"div",{class:"plot"}));b(this,"observer",null);b(this,"observed",0);b(this,"drawn",0);b(this,"drawing",null)}shownFields(){return ce(this)}connectedCallback(){super.connectedCallback(),!(this.observer!==null||n.ResizeObserver===void 0)&&(this.observer=new n.ResizeObserver(i=>{let r=Math.round(i.at(-1)?.contentRect.width??0);r<=0||(this.observed=r,r!==this.drawn&&this.draw())}),this.observer.observe(this.plot))}disconnectedCallback(){super.disconnectedCallback(),this.observer?.disconnect(),this.observer=null}async load(i,r){if(r===null)return;let s=C(this,"resource"),l=C(this,"by"),{field:u,truncation:c}=qe(l),p=G(this,"height",80,240),f=G(this,"limit",1,12),m=await de(this,this.period,i,l);if(m===null)return;let{fn:d,period:g}=m,{data:w}=await nt(r,s,l,m,i);if(i.aborted)return;let v=w.filter(A=>A[l]!==null&&A[l]!==void 0);if(v.length===0){this.showState("empty");return}let k;if(c!==null){let A=new Map(v.map(j=>[String(j[l]),Te(j[d])])),D=g===null?[...A.keys()].sort():mr(g.from,g.to,c),S=g?.today??g?.to??"",E=g===null||S<g.from?new Set:new Set(mr(g.from,S<g.to?S:g.to,c));k=D.map((j,I)=>({key:j,label:Mt(j,c),...c==="month"?{tick:ji(j,I===0)}:{},value:g===null||!E.has(j)?A.get(j)??null:A.get(j)??0}))}else{let A=await rt(this,r,v,{by:l,fn:d},{descending:!0,limit:f},i);if(A===null)return;if(A.length===0){this.showState("empty");return}k=A}let x=this.attr("label")??U(m.field??d),P=this.attr("kind");this.render({label:x,points:k,categories:c===null},p,{line:Oi.includes(P??"")?P==="line":c!==null,format:pe(this,m.count),byLabel:U(u)})}render(i,r,s){let l=n.document;this.drawing={series:i,height:r,line:s.line,format:s.format};let u=c=>c===null?y.emptyValue:s.format(c);T(this.body),this.body.appendChild(h(l,"div",{class:"card"},this.attr("label")===null?"":h(l,"p",{class:"label","aria-hidden":"true"},i.label),this.plot,h(l,"div",{class:"sr-only"},h(l,"table",{},h(l,"caption",{},y.asTable),h(l,"thead",{},h(l,"tr",{},h(l,"th",{scope:"col"},s.byLabel),h(l,"th",{scope:"col"},i.label))),h(l,"tbody",{},...i.points.map(c=>h(l,"tr",{},h(l,"th",{scope:"row"},c.label),h(l,"td",{},u(c.value))))))))),this.draw()}draw(){if(this.drawing===null)return;let{series:i,height:r,line:s,format:l}=this.drawing,u=this.observed||Math.round(this.plot.clientWidth)||$i;this.drawn=u,T(this.plot),this.plot.appendChild((s?dr:pr)(n.document,i,{width:u,height:r},l))}}return b(t,"tag","cube-chart"),b(t,"css",Pi),t}var Ii=`${M}${me}${ge}
112
+ `;function us(e,n){let t=e.toISOString().slice(0,10);switch(n){case"day":return t;case"week":{let o=new Date(e.getTime()+(3-(e.getUTCDay()+6)%7)*Jt),a=o.getUTCFullYear(),i=1+Math.floor((o.getTime()-Date.UTC(a,0,1))/(7*Jt));return`${a}-W${String(i).padStart(2,"0")}`}case"month":return t.slice(0,7);case"quarter":return`${t.slice(0,4)}-Q${Math.ceil((e.getUTCMonth()+1)/3)}`;case"year":return t.slice(0,4)}}function cs(e,n){let t=It(e,"month",{short:!0});return n||e.endsWith("-01")?y.monthYear(t,e.slice(0,4)):t}function Cr(e,n,t){let o=new Set,a=Date.parse(`${n}T00:00:00Z`);for(let i=Date.parse(`${e}T00:00:00Z`);i<=a;i+=Jt)o.add(us(new Date(i),t));return[...o]}function Ar(e,n){class t extends e{constructor(){super(...arguments);b(this,"period",new G(this));b(this,"plot",h(n.document,"div",{class:"plot"}));b(this,"observer",null);b(this,"observed",0);b(this,"drawn",0);b(this,"drawing",null)}shownFields(){return he(this)}connectedCallback(){super.connectedCallback(),!(this.observer!==null||n.ResizeObserver===void 0)&&(this.observer=new n.ResizeObserver(i=>{let r=Math.round(i.at(-1)?.contentRect.width??0);r<=0||(this.observed=r,r!==this.drawn&&this.draw())}),this.observer.observe(this.plot))}disconnectedCallback(){super.disconnectedCallback(),this.observer?.disconnect(),this.observer=null}async load(i,r){if(r===null)return;let s=_(this,"resource"),l=_(this,"by"),{field:u,truncation:c}=Ze(l),p=X(this,"height",80,240),m=X(this,"limit",1,12),f=await be(this,this.period,i,l);if(f===null)return;let{fn:d,period:g}=f,{data:w}=await dt(r,s,l,f,i);if(i.aborted)return;let v=w.filter(L=>L[l]!==null&&L[l]!==void 0);if(v.length===0){this.showState("empty");return}let k;if(c!==null){let L=new Map(v.map(T=>[String(T[l]),Me(T[d])])),j=g===null?[...L.keys()].sort():Cr(g.from,g.to,c),x=g?.today??g?.to??"",F=g===null||x<g.from?new Set:new Set(Cr(g.from,x<g.to?x:g.to,c));k=j.map((T,E)=>({key:T,label:It(T,c),...c==="month"?{tick:cs(T,E===0)}:{},value:g===null||!F.has(T)?L.get(T)??null:L.get(T)??0}))}else{let L=await pt(this,r,v,{by:l,fn:d},{descending:!0,limit:m},i);if(L===null)return;if(L.length===0){this.showState("empty");return}k=L}let S=this.attr("label")??K(f.field??d),R=this.attr("kind");this.render({label:S,points:k,categories:c===null},p,{line:as.includes(R??"")?R==="line":c!==null,format:ye(this,f.count),byLabel:K(u)})}render(i,r,s){let l=n.document;this.drawing={series:i,height:r,line:s.line,format:s.format};let u=c=>c===null?y.emptyValue:s.format(c);C(this.body),this.body.appendChild(h(l,"div",{class:"card"},this.attr("label")===null?"":h(l,"p",{class:"label","aria-hidden":"true"},i.label),this.plot,h(l,"div",{class:"sr-only"},h(l,"table",{},h(l,"caption",{},y.asTable),h(l,"thead",{},h(l,"tr",{},h(l,"th",{scope:"col"},s.byLabel),h(l,"th",{scope:"col"},i.label))),h(l,"tbody",{},...i.points.map(c=>h(l,"tr",{},h(l,"th",{scope:"row"},c.label),h(l,"td",{},u(c.value))))))))),this.draw()}draw(){if(this.drawing===null)return;let{series:i,height:r,line:s,format:l}=this.drawing,u=this.observed||Math.round(this.plot.clientWidth)||ss;this.drawn=u,C(this.plot),this.plot.appendChild((s?xr:Tr)(n.document,i,{width:u,height:r},l))}}return b(t,"tag","cube-chart"),b(t,"css",ls),t}var ds=`${O}${we}${ke}
109
113
  dl{display:grid;grid-template-columns:minmax(8rem,max-content) 1fr;gap:.5rem 1rem;margin:0}
110
114
  dt{font-weight:600}
111
115
  dd{margin:0;min-width:0;overflow-wrap:anywhere}
112
- `,gr=e=>e.field!==void 0&&!e.field.readonly;function Bi(e,n,t){let o=n===void 0||n===""?null:n;if(o===t||o===null&&t===!1&&e.format==="boolean")return!0;if(o===null||t===null)return!1;if(e.format==="date"&&typeof o=="string"&&typeof t=="string")return o.slice(0,10)===t;if(typeof t=="number"&&typeof o=="string")return Number(o)===t;if(typeof t=="string"&&typeof o=="number")return String(o)===t;if(e.format==="datetime"&&typeof o=="string"&&typeof t=="string"){let a=i=>Math.floor(Date.parse(i)/6e4);return a(o)===a(t)}return typeof o=="object"&&JSON.stringify(o)===JSON.stringify(t)}function hr(e,n){let t=n.document;class o extends e{constructor(){super();b(this,"status",h(t,"p",{class:"status",role:"status"}));b(this,"loaded",null);b(this,"editing",null);b(this,"attempt",null);b(this,"saved",null);b(this,"edit",null);this.shadowRoot?.appendChild(this.status)}disconnectedCallback(){super.disconnectedCallback(),this.editing=null}refresh(){let r=this.editing;return r!==null&&r.resource===this.attr("resource")?.trim()&&r.id===this.recordId()&&r.user===re(this.loaded?.session)?Promise.resolve():(this.editing=null,super.refresh())}shownFields(){return this.loaded?.columns.map(r=>r.name)??[]}recordId(){let r=this.attr("record-id")?.trim()??"";return r===""?null:r}async load(r,s){if(s===null)return;this.loaded=null;let l=C(this,"resource"),u=this.recordId(),c=this.saved!==null&&this.saved.resource===l&&this.saved.id===u;if(this.saved=null,c||(this.status.textContent=""),u===null){this.showState("empty",y.chooseRow);return}let p=await s.schema(l);if(r.aborted)return;let f=W(this.attr("fields")),m=await s.resource(l).get(u,f===null?{}:{fields:f},{signal:r});if(r.aborted)return;let d=m.data,g={session:s,resource:l,id:u,columns:Q(p,f,V(this),d),row:d,version:m.recordVersion,canEdit:this.flag("editable")&&this.allowsUpdate(p)};this.loaded=g,this.renderView(g),c&&this.edit?.focus()}allowsUpdate(r){return r!==null&&r.actions.includes("update")}renderView(r){this.edit=r.canEdit&&r.columns.some(gr)?h(t,"button",{type:"button",onclick:()=>this.startEditing(r)},y.edit):null,T(this.body),this.body.appendChild(h(t,"div",{class:"card"},h(t,"dl",{},...r.columns.flatMap(s=>this.pair(r,s))),this.edit===null?null:h(t,"div",{class:"actions"},this.edit,this.notSaved(r.session))))}pair(r,s){let l=this.exampleField(r.session,r.resource,s.name);return[h(t,"dt",{},s.label,...l?[" ",Xe(t)]:[]),h(t,"dd",{class:l?"example":null},_(r.row[s.name],s.format))]}startEditing(r){this.editing={resource:r.resource,id:r.id,user:re(r.session)},this.status.textContent="";let s=[],l=r.columns.map(m=>{if(!gr(m))return h(t,"dl",{},...this.pair(r,m));let d=fe(t,m,r.row[m.name],m.field?.nullable===!1);return s.push(d),d.element}),u=h(t,"div",{class:"alert",role:"alert",tabindex:"-1",hidden:!0}),c=h(t,"button",{type:"submit"},y.save),p=h(t,"button",{type:"button",class:"secondary",onclick:()=>{this.editing=null,this.attempt=null,this.renderView(r),this.edit?.focus()}},y.cancel),f=h(t,"form",{novalidate:!0},u,...l,h(t,"div",{class:"actions"},c,p,this.notSaved(r.session)));f.addEventListener("submit",m=>{m.preventDefault(),this.save(r,s,{alert:u,save:c,cancel:p})}),T(this.body),this.body.appendChild(h(t,"div",{class:"card"},f)),s[0]?.element.querySelector("input,select,textarea")?.focus()}async save(r,s,l){if(l.save.disabled)return;let u={},c=!1;for(let m of s){let d=m.read(),g=r.columns.find(w=>w.name===m.name);if("error"in d){m.setError(d.error),c=!0;continue}m.setError(null),Bi(g,r.row[m.name],d.value)||(u[m.name]=d.value)}if(c){Ee(t,l.alert,y.formInvalid);return}if(Object.keys(u).length===0){this.editing=null,this.renderView(r),this.edit?.focus();return}let p=JSON.stringify([r.resource,r.id,u]);this.attempt=he(this.attempt,p);let f={idempotencyKey:this.attempt.key};r.version!==null&&(f.ifMatch=r.version),l.save.disabled=!0,l.cancel.disabled=!0,l.alert.hidden=!0;try{let m=await this.session();if(this.editing!==null&&this.editing.user!==re(m)){this.editing=null,this.refresh();return}let d=await m.resource(r.resource).update(r.id,u,f);this.attempt=null;let g=d.data;if(this.loaded===r&&this.editing!==null){this.editing=null;let w={...r.row,...u,...g},v={...r,row:w,version:d.recordVersion};this.loaded=v,this.saved={resource:r.resource,id:r.id},this.renderView(v),this.status.textContent=y.saved,this.edit?.focus()}this.emit("cube-saved",{resource:r.resource,id:g.id??r.id,row:g}),this.emit("cube-data-change",{resource:r.resource})}catch(m){if(this.loaded!==r||this.editing===null)return;l.cancel.disabled=!1,this.failed(m,s,l)}}failed(r,s,l){if(F(r)&&(this.attempt=null),F(r)&&(r.status===409||r.status===412)){let u=h(t,"button",{type:"button",class:"secondary",onclick:()=>{this.editing=null,this.refresh()}},y.reload);Ee(t,l.alert,y.conflict,u);return}l.save.disabled=!1,it(t,l.alert,r,s,u=>Ce(V(this),u))}}return b(o,"tag","cube-detail"),b(o,"css",Ii),o}var Ui=`${M}${me}${ge}`,Hi=["resource","fields","submit-label","success-text"];function yr(e,n){let t=n.document;class o extends e{constructor(){super();b(this,"status",h(t,"p",{class:"status",role:"status"}));b(this,"drawn",null);b(this,"shown",null);b(this,"attempt",null);this.shadowRoot?.appendChild(this.status)}shownFields(){return this.drawn?.columns.map(r=>r.name)??[]}key(){let r=this.drawn?.session.user()?.id??null;return JSON.stringify([...Hi.map(s=>this.attr(s)),r])}text(r,s){let l=this.attr(r)?.trim()??"";return l===""?s:l}refresh(){return this.shown===this.key()?Promise.resolve():(this.shown=null,super.refresh())}async load(r,s){if(s===null)return;this.drawn=null,this.attempt=null;let l=C(this,"resource"),u=await s.schema(l);if(r.aborted)return;if(u===null||!u.actions.includes("create")){this.showState({kind:"forbidden",detail:null,retry:!1});return}let c=u.fields.filter(d=>!d.readonly&&d.name!=="id"),f=(W(this.attr("fields"))??c.map(d=>d.name)).filter(d=>c.some(g=>g.name===d)),m=Q(u,f,V(this));if(m.length===0){this.showState({kind:"error",detail:y.noWritableFields,retry:!1});return}this.drawn={session:s,resource:l,columns:m},this.shown=this.key(),this.renderForm(!1)}renderForm(r){let s=this.drawn;this.status.textContent="";let l=s.columns.map(f=>fe(t,f,null,f.field?.nullable===!1&&f.format!=="boolean")),u=h(t,"div",{class:"alert",role:"alert",tabindex:"-1",hidden:!0}),c=h(t,"button",{type:"submit"},this.text("submit-label",y.save)),p=h(t,"form",{novalidate:!0},u,...l.map(f=>f.element),h(t,"div",{class:"actions"},c,this.notSaved(s.session)));p.addEventListener("submit",f=>{f.preventDefault(),this.submit(s,l,u,c)}),T(this.body),this.body.appendChild(h(t,"div",{class:"card"},p)),r&&br(l[0])?.focus()}async submit(r,s,l,u){if(u.disabled)return;let c={},p=null;for(let m of s){let d=m.read();m.setError("error"in d?d.error:null),"error"in d?p??(p=m):d.value!==null&&(c[m.name]=d.value)}if(p!==null){l.hidden=!0,br(p)?.focus();return}this.attempt=he(this.attempt,JSON.stringify([r.resource,c]));let f=this.attempt.key;u.disabled=!0,l.hidden=!0;try{let d=await(await this.session()).resource(r.resource).create(c,{idempotencyKey:f});this.attempt=null;let g=d.data;this.drawn===r&&this.done(),this.emit("cube-created",{resource:r.resource,row:g}),this.emit("cube-data-change",{resource:r.resource})}catch(m){if(F(m)&&(this.attempt=null),this.drawn!==r)return;u.disabled=!1,it(t,l,m,s,d=>Ce(V(this),d))}}done(){let r=h(t,"button",{type:"button",onclick:()=>this.renderForm(!0)},y.another);T(this.body);let s=this.drawn===null?null:this.notSaved(this.drawn.session);this.body.appendChild(h(t,"div",{class:"card"},h(t,"div",{class:"actions"},r,s))),this.status.textContent=this.text("success-text",y.formSaved),n.setTimeout(()=>{r.isConnected&&r.focus()},0)}}return b(o,"tag","cube-form"),b(o,"css",Ui),o}function br(e){return e?.element.querySelector("input,select,textarea")??null}var zi=`${M}
116
+ `,Rr=e=>e.field!==void 0&&!e.field.readonly;function ps(e,n,t){let o=n===void 0||n===""?null:n;if(o===t||o===null&&t===!1&&e.format==="boolean")return!0;if(o===null||t===null)return!1;if(e.format==="date"&&typeof o=="string"&&typeof t=="string")return o.slice(0,10)===t;if(typeof t=="number"&&typeof o=="string")return Number(o)===t;if(typeof t=="string"&&typeof o=="number")return String(o)===t;if(e.format==="datetime"&&typeof o=="string"&&typeof t=="string"){let a=i=>Math.floor(Date.parse(i)/6e4);return a(o)===a(t)}return typeof o=="object"&&JSON.stringify(o)===JSON.stringify(t)}function Er(e,n){let t=n.document;class o extends e{constructor(){super();b(this,"status",h(t,"p",{class:"status",role:"status"}));b(this,"loaded",null);b(this,"editing",null);b(this,"attempt",null);b(this,"saved",null);b(this,"edit",null);this.shadowRoot?.appendChild(this.status)}disconnectedCallback(){super.disconnectedCallback(),this.editing=null}refresh(){let r=this.editing;return r!==null&&r.resource===this.attr("resource")?.trim()&&r.id===this.recordId()&&r.user===le(this.loaded?.session)?Promise.resolve():(this.editing=null,super.refresh())}shownFields(){return this.loaded?.columns.map(r=>r.name)??[]}recordId(){let r=this.attr("record-id")?.trim()??"";return r===""?null:r}async load(r,s){if(s===null)return;this.loaded=null;let l=_(this,"resource"),u=this.recordId(),c=this.saved!==null&&this.saved.resource===l&&this.saved.id===u;if(this.saved=null,c||(this.status.textContent=""),u===null){this.showState("empty",y.chooseRow);return}let p=await s.schema(l);if(r.aborted)return;let m=Z(this.attr("fields")),f=await s.resource(l).get(u,m===null?{}:{fields:m},{signal:r});if(r.aborted)return;let d=f.data,g={session:s,resource:l,id:u,columns:ee(p,m,W(this),d),row:d,version:f.recordVersion,canEdit:this.flag("editable")&&this.allowsUpdate(p)};this.loaded=g,this.renderView(g),c&&this.edit?.focus()}allowsUpdate(r){return r!==null&&r.actions.includes("update")}renderView(r){this.edit=r.canEdit&&r.columns.some(Rr)?h(t,"button",{type:"button",onclick:()=>this.startEditing(r)},y.edit):null,C(this.body),this.body.appendChild(h(t,"div",{class:"card"},h(t,"dl",{},...r.columns.flatMap(s=>this.pair(r,s))),this.edit===null?null:h(t,"div",{class:"actions"},this.edit,this.notSaved(r.session))))}pair(r,s){let l=this.exampleField(r.session,r.resource,s.name);return[h(t,"dt",{},s.label,...l?[" ",at(t)]:[]),h(t,"dd",{class:l?"example":null},I(r.row[s.name],s.format))]}startEditing(r){this.editing={resource:r.resource,id:r.id,user:le(r.session)},this.status.textContent="";let s=[],l=r.columns.map(f=>{if(!Rr(f))return h(t,"dl",{},...this.pair(r,f));let d=ve(t,f,r.row[f.name],f.field?.nullable===!1);return s.push(d),d.element}),u=h(t,"div",{class:"alert",role:"alert",tabindex:"-1",hidden:!0}),c=h(t,"button",{type:"submit"},y.save),p=h(t,"button",{type:"button",class:"secondary",onclick:()=>{this.editing=null,this.attempt=null,this.renderView(r),this.edit?.focus()}},y.cancel),m=h(t,"form",{novalidate:!0},u,...l,h(t,"div",{class:"actions"},c,p,this.notSaved(r.session)));m.addEventListener("submit",f=>{f.preventDefault(),this.save(r,s,{alert:u,save:c,cancel:p})}),C(this.body),this.body.appendChild(h(t,"div",{class:"card"},m)),s[0]?.element.querySelector("input,select,textarea")?.focus()}async save(r,s,l){if(l.save.disabled)return;let u={},c=!1;for(let f of s){let d=f.read(),g=r.columns.find(w=>w.name===f.name);if("error"in d){f.setError(d.error),c=!0;continue}f.setError(null),ps(g,r.row[f.name],d.value)||(u[f.name]=d.value)}if(c){Oe(t,l.alert,y.formInvalid);return}if(Object.keys(u).length===0){this.editing=null,this.renderView(r),this.edit?.focus();return}let p=JSON.stringify([r.resource,r.id,u]);this.attempt=Se(this.attempt,p);let m={idempotencyKey:this.attempt.key};r.version!==null&&(m.ifMatch=r.version),l.save.disabled=!0,l.cancel.disabled=!0,l.alert.hidden=!0;try{let f=await this.session();if(this.editing!==null&&this.editing.user!==le(f)){this.editing=null,this.refresh();return}let d=await f.resource(r.resource).update(r.id,u,m);this.attempt=null;let g=d.data;if(this.loaded===r&&this.editing!==null){this.editing=null;let w={...r.row,...u,...g},v={...r,row:w,version:d.recordVersion};this.loaded=v,this.saved={resource:r.resource,id:r.id},this.renderView(v),this.status.textContent=y.saved,this.edit?.focus()}this.emit("cube-saved",{resource:r.resource,id:g.id??r.id,row:g}),this.emit("cube-data-change",{resource:r.resource})}catch(f){if(this.loaded!==r||this.editing===null)return;l.cancel.disabled=!1,this.failed(f,s,l)}}failed(r,s,l){if(N(r)&&(this.attempt=null),N(r)&&(r.status===409||r.status===412)){let u=h(t,"button",{type:"button",class:"secondary",onclick:()=>{this.editing=null,this.refresh()}},y.reload);Oe(t,l.alert,y.conflict,u);return}l.save.disabled=!1,ft(t,l.alert,r,s,u=>Fe(W(this),u))}}return b(o,"tag","cube-detail"),b(o,"css",ds),o}var ms=`${O}${we}${ke}`,fs=["resource","fields","submit-label","success-text"];function Mr(e,n){let t=n.document;class o extends e{constructor(){super();b(this,"status",h(t,"p",{class:"status",role:"status"}));b(this,"drawn",null);b(this,"shown",null);b(this,"attempt",null);this.shadowRoot?.appendChild(this.status)}shownFields(){return this.drawn?.columns.map(r=>r.name)??[]}key(){let r=this.drawn?.session.user()?.id??null;return JSON.stringify([...fs.map(s=>this.attr(s)),r])}text(r,s){let l=this.attr(r)?.trim()??"";return l===""?s:l}refresh(){return this.shown===this.key()?Promise.resolve():(this.shown=null,super.refresh())}async load(r,s){if(s===null)return;this.drawn=null,this.attempt=null;let l=_(this,"resource"),u=await s.schema(l);if(r.aborted)return;if(u===null||!u.actions.includes("create")){this.showState({kind:"forbidden",detail:null,retry:!1});return}let c=u.fields.filter(d=>!d.readonly&&d.name!=="id"),m=(Z(this.attr("fields"))??c.map(d=>d.name)).filter(d=>c.some(g=>g.name===d)),f=ee(u,m,W(this));if(f.length===0){this.showState({kind:"error",detail:y.noWritableFields,retry:!1});return}this.drawn={session:s,resource:l,columns:f},this.shown=this.key(),this.renderForm(!1)}renderForm(r){let s=this.drawn;this.status.textContent="";let l=s.columns.map(m=>ve(t,m,null,m.field?.nullable===!1&&m.format!=="boolean")),u=h(t,"div",{class:"alert",role:"alert",tabindex:"-1",hidden:!0}),c=h(t,"button",{type:"submit"},this.text("submit-label",y.save)),p=h(t,"form",{novalidate:!0},u,...l.map(m=>m.element),h(t,"div",{class:"actions"},c,this.notSaved(s.session)));p.addEventListener("submit",m=>{m.preventDefault(),this.submit(s,l,u,c)}),C(this.body),this.body.appendChild(h(t,"div",{class:"card"},p)),r&&Dr(l[0])?.focus()}async submit(r,s,l,u){if(u.disabled)return;let c={},p=null;for(let f of s){let d=f.read();f.setError("error"in d?d.error:null),"error"in d?p??(p=f):d.value!==null&&(c[f.name]=d.value)}if(p!==null){l.hidden=!0,Dr(p)?.focus();return}this.attempt=Se(this.attempt,JSON.stringify([r.resource,c]));let m=this.attempt.key;u.disabled=!0,l.hidden=!0;try{let d=await(await this.session()).resource(r.resource).create(c,{idempotencyKey:m});this.attempt=null;let g=d.data;this.drawn===r&&this.done(),this.emit("cube-created",{resource:r.resource,row:g}),this.emit("cube-data-change",{resource:r.resource})}catch(f){if(N(f)&&(this.attempt=null),this.drawn!==r)return;u.disabled=!1,ft(t,l,f,s,d=>Fe(W(this),d))}}done(){let r=h(t,"button",{type:"button",onclick:()=>this.renderForm(!0)},y.another);C(this.body);let s=this.drawn===null?null:this.notSaved(this.drawn.session);this.body.appendChild(h(t,"div",{class:"card"},h(t,"div",{class:"actions"},r,s))),this.status.textContent=this.text("success-text",y.formSaved),n.setTimeout(()=>{r.isConnected&&r.focus()},0)}}return b(o,"tag","cube-form"),b(o,"css",ms),o}function Dr(e){return e?.element.querySelector("input,select,textarea")??null}var gs=`${O}
113
117
  ul{list-style:none;margin:0;padding:0;display:grid;gap:.75rem}
114
118
  h3{margin:0 0 .5rem;font-size:1rem;overflow-wrap:anywhere}
115
119
  dl{margin:0;display:grid;gap:.375rem}
@@ -117,14 +121,14 @@ dl div{display:flex;flex-wrap:wrap;gap:0 .75rem}
117
121
  dt{flex:0 0 8rem;font-weight:600}
118
122
  dd{flex:1 1 12rem;margin:0;min-width:0;overflow-wrap:break-word}
119
123
  p{margin:0}
120
- `;function wr(e,n){let t=n.document;class o extends e{async load(i,r){if(r===null||i.aborted)return;let s=this.attr("scherm")?.trim()??"",l=(r.gaps??[]).filter(c=>s===""||c.scherm===s),u=(c,p)=>h(t,"div",{},h(t,"dt",{},c),h(t,"dd",{},p));T(this.body),this.body.appendChild(l.length===0?h(t,"div",{class:"card"},h(t,"p",{},y.gaps.none)):h(t,"ul",{role:"list","aria-label":y.gaps.what},...l.map(c=>h(t,"li",{class:"card"},h(t,"h3",{},c.veld===void 0?c.resource:`${c.resource}.${c.veld}`),h(t,"dl",{},u(y.gaps.screen,c.scherm),u(y.gaps.type,c.type==="keuze"?`${y.gaps.types.keuze}: ${(c.waarden??[]).join(", ")}`:y.gaps.types[c.type]),u(y.gaps.why,c.reden))))))}}return b(o,"tag","cube-gap-list"),b(o,"css",zi),o}var vr=new Intl.NumberFormat("nl-NL",{minimumFractionDigits:1,maximumFractionDigits:1}),Vi=`${M}
124
+ `;function Lr(e,n){let t=n.document;class o extends e{async load(i,r){if(r===null||i.aborted)return;let s=this.attr("scherm")?.trim()??"",l=(r.gaps??[]).filter(c=>s===""||c.scherm===s),u=(c,p)=>h(t,"div",{},h(t,"dt",{},c),h(t,"dd",{},p));C(this.body),this.body.appendChild(l.length===0?h(t,"div",{class:"card"},h(t,"p",{},y.gaps.none)):h(t,"ul",{role:"list","aria-label":y.gaps.what},...l.map(c=>h(t,"li",{class:"card"},h(t,"h3",{},c.veld===void 0?c.resource:`${c.resource}.${c.veld}`),h(t,"dl",{},u(y.gaps.screen,c.scherm),u(y.gaps.type,c.type==="keuze"?`${y.gaps.types.keuze}: ${(c.waarden??[]).join(", ")}`:y.gaps.types[c.type]),u(y.gaps.why,c.reden))))))}}return b(o,"tag","cube-gap-list"),b(o,"css",gs),o}var Fr=new Intl.NumberFormat("nl-NL",{minimumFractionDigits:1,maximumFractionDigits:1}),hs=`${O}
121
125
  .kpi{display:flex;flex-direction:column;gap:.25rem}
122
126
  .label{margin:0;font-size:.875rem;font-weight:600;color:var(--cube-color-text-muted)}
123
127
  .value{margin:0;font-size:2rem;font-weight:700;line-height:1.2;overflow-wrap:anywhere}
124
128
  .compare{margin:0;font-size:.875rem;color:var(--cube-color-text-muted)}
125
129
  .compare.up{color:var(--cube-color-success)}
126
130
  .compare.down{color:var(--cube-color-danger)}
127
- `;function kr(e,n){class t extends e{constructor(){super(...arguments);b(this,"period",new z(this))}shownFields(){return ce(this)}async load(i,r){if(r===null)return;let s=C(this,"resource");if(this.flag("compare")&&!this.attr("period"))throw new TypeError(y.invalid.compare(this.localName));let l=await de(this,this.period,i);if(l===null)return;let{fn:u,period:c}=l,p=r.resource(s),f=async w=>{let{data:v}=await p.aggregate({fn:u,filter:l.filterFor(w)},{signal:i});return Te(v[0]?.[u])},m=this.flag("compare")?c?.previous??null:null,[d,g]=await Promise.all([f(c),m===null?null:f(m)]);i.aborted||this.render(d,m===null?void 0:g,l.count)}render(i,r,s){let l=n.document,u=pe(this,s),c=this.attr("label"),p=i===null?h(l,"p",{class:"value"},h(l,"span",{"aria-hidden":"true"},y.emptyValue),h(l,"span",{class:"sr-only"},y.noData)):h(l,"p",{class:"value"},h(l,"data",{value:String(i)},u(i)));T(this.body),this.body.appendChild(h(l,"div",{class:"card kpi"},c===null||c===""?null:h(l,"p",{class:"label"},c),p,r===void 0||i===null?null:this.compareLine(i,r)))}compareLine(i,r){let s=n.document;if(r===null||r===0)return h(s,"p",{class:"compare new"},y.newValue);let l=(i-r)/Math.abs(r),u=vr.format(Math.abs(l)*100);if(u===vr.format(0))return h(s,"p",{class:"compare same"},`${u}% ${y.comparedTo}`);let c=l>0;return h(s,"p",{class:c?"compare up":"compare down",role:"img","aria-label":y.change(u,c?y.higher:y.lower)},`${c?"\u25B2":"\u25BC"} ${u}% ${y.comparedTo}`)}}return b(t,"tag","cube-kpi"),b(t,"css",Vi),t}var Ki=864e5;function Z(e,n,t){let o=new Date(2e3,0,1);return o.setFullYear(e,n,t),o}function lt(e,n){return{from:O(e),to:O(n)}}function at(e,n,t){let o=e.getFullYear(),a=e.getMonth()+n;return lt(Z(o,a,1),Z(o,a+t,0))}function qi(e,n){return Math.round((Date.UTC(n.getFullYear(),n.getMonth(),n.getDate())-Date.UTC(e.getFullYear(),e.getMonth(),e.getDate()))/Ki)+1}function zt(e,n,t){switch(e){case"this-month":return{key:e,...at(n,0,1),previous:at(n,-1,1)};case"12m":return{key:e,...at(n,-11,12),previous:at(n,-23,12)};case"this-year":{let o=n.getFullYear();return{key:e,...lt(Z(o,0,1),Z(o,11,31)),previous:lt(Z(o-1,0,1),Z(o-1,11,31))}}case"custom":{let o=t===void 0?null:$(t.from),a=t===void 0?null:$(t.to);if(t===void 0||o===null||a===null||a<o)throw new TypeError("A custom period needs a valid from and to, from not after to.");let i=qi(o,a);return{key:e,from:t.from,to:t.to,previous:lt(Z(o.getFullYear(),o.getMonth(),o.getDate()-i),Z(o.getFullYear(),o.getMonth(),o.getDate()-1))}}}}var Vt=["this-month","12m","this-year","custom"],Sr="12m",Gi=`
131
+ `;function _r(e,n){class t extends e{constructor(){super(...arguments);b(this,"period",new G(this))}shownFields(){return he(this)}async load(i,r){if(r===null)return;let s=_(this,"resource");if(this.flag("compare")&&!this.attr("period"))throw new A(y.invalid.compare(this.localName));let l=await be(this,this.period,i);if(l===null)return;let{fn:u,period:c}=l,p=r.resource(s),m=async w=>{let{data:v}=await p.aggregate({fn:u,filter:l.filterFor(w)},{signal:i});return Me(v[0]?.[u])},f=this.flag("compare")?c?.previous??null:null,[d,g]=await Promise.all([m(c),f===null?null:m(f)]);i.aborted||this.render(d,f===null?void 0:g,l.count)}render(i,r,s){let l=n.document,u=ye(this,s),c=this.attr("label"),p=i===null?h(l,"p",{class:"value"},h(l,"span",{"aria-hidden":"true"},y.emptyValue),h(l,"span",{class:"sr-only"},y.noData)):h(l,"p",{class:"value"},h(l,"data",{value:String(i)},u(i)));C(this.body),this.body.appendChild(h(l,"div",{class:"card kpi"},c===null||c===""?null:h(l,"p",{class:"label"},c),p,r===void 0||i===null?null:this.compareLine(i,r)))}compareLine(i,r){let s=n.document;if(r===null||r===0)return h(s,"p",{class:"compare new"},y.newValue);let l=(i-r)/Math.abs(r),u=Fr.format(Math.abs(l)*100);if(u===Fr.format(0))return h(s,"p",{class:"compare same"},`${u}% ${y.comparedTo}`);let c=l>0;return h(s,"p",{class:c?"compare up":"compare down",role:"img","aria-label":y.change(u,c?y.higher:y.lower)},`${c?"\u25B2":"\u25BC"} ${u}% ${y.comparedTo}`)}}return b(t,"tag","cube-kpi"),b(t,"css",hs),t}var bs=864e5;function re(e,n,t){let o=new Date(2e3,0,1);return o.setFullYear(e,n,t),o}function bt(e,n){return{from:U(e),to:U(n)}}function ht(e,n,t){let o=e.getFullYear(),a=e.getMonth()+n;return bt(re(o,a,1),re(o,a+t,0))}function ys(e,n){return Math.round((Date.UTC(n.getFullYear(),n.getMonth(),n.getDate())-Date.UTC(e.getFullYear(),e.getMonth(),e.getDate()))/bs)+1}function Yt(e,n,t){switch(e){case"this-month":return{key:e,...ht(n,0,1),previous:ht(n,-1,1)};case"12m":return{key:e,...ht(n,-11,12),previous:ht(n,-23,12)};case"this-year":{let o=n.getFullYear();return{key:e,...bt(re(o,0,1),re(o,11,31)),previous:bt(re(o-1,0,1),re(o-1,11,31))}}case"custom":{let o=t===void 0?null:B(t.from),a=t===void 0?null:B(t.to);if(t===void 0||o===null||a===null||a<o)throw new TypeError("A custom period needs a valid from and to, from not after to.");let i=ys(o,a);return{key:e,from:t.from,to:t.to,previous:bt(re(o.getFullYear(),o.getMonth(),o.getDate()-i),re(o.getFullYear(),o.getMonth(),o.getDate()-1))}}}}var Xt=["this-month","12m","this-year","custom"],Or="12m",ws=`
128
132
  .picker{display:flex;flex-wrap:wrap;align-items:flex-end;gap:.75rem}
129
133
  .field{display:flex;flex-direction:column;gap:.25rem;min-width:0}
130
134
  label{font-weight:600;font-size:.875rem}
@@ -134,15 +138,15 @@ label{font-weight:600;font-size:.875rem}
134
138
  .custom .error:empty{flex-basis:0}
135
139
  input[aria-invalid=true]{border:2px solid var(--cube-color-danger)}
136
140
  @media (max-width:640px){.picker,.custom{flex-direction:column;align-items:stretch}}
137
- `;function xr(e,n,t,o){return h(e,"div",{class:"field"},h(e,"label",{for:n},t),o)}function Tr(e,n){class t extends e{constructor(){super();b(this,"select");b(this,"label");b(this,"custom");b(this,"from");b(this,"to");b(this,"error");b(this,"chosen",null);b(this,"range",null);b(this,"announced",null);let i=n.document;this.select=h(i,"select",{id:"period",onchange:()=>this.onSelect()},...Vt.map(l=>h(i,"option",{value:l},y.period[l]))),this.label=h(i,"label",{for:"period"});let r=l=>h(i,"input",{type:"date",id:l,onchange:()=>this.onDates()});this.from=r("from"),this.to=r("to"),this.error=h(i,"p",{id:"range-error",class:"error","aria-live":"polite"}),this.custom=h(i,"div",{class:"custom",hidden:!0},xr(i,"from",y.period.from,this.from),xr(i,"to",y.period.to,this.to),this.error);let s=h(i,"div",{class:"field"},this.label,this.select);this.body.appendChild(h(i,"div",{class:"picker"},s,this.custom))}get value(){let i=this.key(),r=this.today();return{...i==="custom"&&this.range!==null?zt("custom",r,this.range):zt(i==="custom"?Sr:i,r),today:O(r)}}refresh(){return this.render(),this.changed(),Promise.resolve()}async load(){this.render()}showState(){this.render()}key(){if(this.chosen!==null)return this.chosen;let i=this.attr("default");return Vt.includes(i)?i:Sr}today(){let i=this.attr("today");return(i===null?null:$(i))??new Date}render(){let i=this.key();this.label.textContent=this.attr("label")??y.period.label,this.select.value=i,this.custom.hidden=i!=="custom",i==="custom"&&this.range===null&&this.fillDates()}fillDates(){let{from:i,to:r}=this.value;this.range={from:i,to:r},this.from.value=i,this.to.value=r,this.explain(null)}onSelect(){let i=this.select.value;Vt.includes(i)&&(i==="custom"&&this.key()!=="custom"&&(this.range=null,this.fillDates()),this.chosen=i,this.render(),this.changed())}onDates(){let i={from:this.from.value,to:this.to.value},r=$(i.from),s=$(i.to);if(r===null||s===null){this.explain(y.period.incompleteDate);return}if(s<r){this.explain(y.period.invalidRange);return}this.explain(null),this.range=i,this.changed()}changed(){let i=this.value,r=JSON.stringify(i),s=this.announced;this.announced=r,s!==null&&s!==r&&this.emit("cube-change",i)}explain(i){this.error.textContent=i??"";for(let r of[this.from,this.to])i===null?(r.removeAttribute("aria-invalid"),r.removeAttribute("aria-describedby")):(r.setAttribute("aria-invalid","true"),r.setAttribute("aria-describedby",this.error.id))}}return b(t,"tag","cube-period-picker"),b(t,"css",Gi),b(t,"needsSession",!1),t}var Wi=["loading","empty","error","forbidden","signed-out"],Qi={loading:y.loading,empty:y.empty,error:y.error,forbidden:y.forbidden,"signed-out":y.signedOut},Ji=`
141
+ `;function $r(e,n,t,o){return h(e,"div",{class:"field"},h(e,"label",{for:n},t),o)}function Pr(e,n){class t extends e{constructor(){super();b(this,"select");b(this,"label");b(this,"custom");b(this,"from");b(this,"to");b(this,"error");b(this,"chosen",null);b(this,"range",null);b(this,"announced",null);let i=n.document;this.select=h(i,"select",{id:"period",onchange:()=>this.onSelect()},...Xt.map(l=>h(i,"option",{value:l},y.period[l]))),this.label=h(i,"label",{for:"period"});let r=l=>h(i,"input",{type:"date",id:l,onchange:()=>this.onDates()});this.from=r("from"),this.to=r("to"),this.error=h(i,"p",{id:"range-error",class:"error","aria-live":"polite"}),this.custom=h(i,"div",{class:"custom",hidden:!0},$r(i,"from",y.period.from,this.from),$r(i,"to",y.period.to,this.to),this.error);let s=h(i,"div",{class:"field"},this.label,this.select);this.body.appendChild(h(i,"div",{class:"picker"},s,this.custom))}get value(){let i=this.key(),r=this.today();return{...i==="custom"&&this.range!==null?Yt("custom",r,this.range):Yt(i==="custom"?Or:i,r),today:U(r)}}refresh(){return this.render(),this.changed(),Promise.resolve()}async load(){this.render()}showState(){this.render()}key(){if(this.chosen!==null)return this.chosen;let i=this.attr("default");return Xt.includes(i)?i:Or}today(){let i=this.attr("today");return(i===null?null:B(i))??new Date}render(){let i=this.key();this.label.textContent=this.attr("label")??y.period.label,this.select.value=i,this.custom.hidden=i!=="custom",i==="custom"&&this.range===null&&this.fillDates()}fillDates(){let{from:i,to:r}=this.value;this.range={from:i,to:r},this.from.value=i,this.to.value=r,this.explain(null)}onSelect(){let i=this.select.value;Xt.includes(i)&&(i==="custom"&&this.key()!=="custom"&&(this.range=null,this.fillDates()),this.chosen=i,this.render(),this.changed())}onDates(){let i={from:this.from.value,to:this.to.value},r=B(i.from),s=B(i.to);if(r===null||s===null){this.explain(y.period.incompleteDate);return}if(s<r){this.explain(y.period.invalidRange);return}this.explain(null),this.range=i,this.changed()}changed(){let i=this.value,r=JSON.stringify(i),s=this.announced;this.announced=r,s!==null&&s!==r&&this.emit("cube-change",i)}explain(i){this.error.textContent=i??"";for(let r of[this.from,this.to])i===null?(r.removeAttribute("aria-invalid"),r.removeAttribute("aria-describedby")):(r.setAttribute("aria-invalid","true"),r.setAttribute("aria-describedby",this.error.id))}}return b(t,"tag","cube-period-picker"),b(t,"css",ws),b(t,"needsSession",!1),t}var vs=["loading","empty","error","forbidden","signed-out"],ks={loading:y.loading,empty:y.empty,error:y.error,forbidden:y.forbidden,"signed-out":y.signedOut},Ss=`
138
142
  .state{display:flex;flex-wrap:wrap;align-items:center;gap:.75rem;padding:1rem;border:1px solid var(--cube-color-border);
139
143
  border-radius:var(--cube-radius);background:var(--cube-color-surface)}
140
144
  .state[data-kind=error]{border-left:4px solid var(--cube-color-danger)}
141
145
  .state[data-kind=forbidden],.state[data-kind=signed-out]{border-left:4px solid var(--cube-color-warning)}
142
146
  .state p{margin:0;flex:1 1 12rem}
143
147
  .state[data-kind=loading] p,.state[data-kind=empty] p{color:var(--cube-color-text-muted)}
144
- `,Rr=["error","forbidden","signed-out"],ut=new WeakMap;function Cr(e,n){class t extends e{constructor(){super();b(this,"failed",!1);b(this,"kind","loading");b(this,"region");b(this,"message");b(this,"action",null);b(this,"announce",null);this.message=h(n.document,"p"),this.region=h(n.document,"div",{class:"state"},this.message)}disconnectedCallback(){super.disconnectedCallback(),ut.get(this.ownerDocument)===this&&ut.delete(this.ownerDocument),this.announce!==null&&n.clearTimeout(this.announce),this.announce=null}refresh(){return this.failed=!1,this.render(),Promise.resolve()}async load(){this.render()}showState(){this.render()}render(){let i=this.attr("kind"),r=this.failed?"error":Wi.includes(i)?i:"loading",s=this.ownerDocument;this.kind=r;let l=Rr.includes(r)&&this.claimAlert();this.action?.remove(),this.action=null,r==="signed-out"?this.action=h(s,"button",{type:"button",onclick:()=>{this.signIn()}},y.signIn):r==="error"&&(this.failed||this.attr("retry")!=="false")&&(this.action=h(s,"button",{type:"button",class:"secondary",onclick:()=>{this.emit("cube-retry")}},y.retry)),this.region.setAttribute("data-kind",r),r==="loading"?this.region.removeAttribute("role"):this.region.setAttribute("role",l?"alert":"status"),l?this.region.removeAttribute("aria-live"):this.region.setAttribute("aria-live",r==="loading"?"off":"polite"),this.action!==null&&this.region.appendChild(this.action),this.region.parentNode!==this.body&&(T(this.body),this.body.appendChild(this.region));let u=this.failed?y.error:this.attr("message")??Qi[r];if(this.announce!==null&&n.clearTimeout(this.announce),this.announce=null,this.message.textContent!==u){if(r==="loading"){this.message.textContent=u;return}this.message.textContent="",this.announce=n.setTimeout(()=>{this.announce=null,this.message.textContent=u},0)}}claimAlert(){let i=this.ownerDocument,r=ut.get(i);return r!==void 0&&r!==this&&r.isConnected&&Rr.includes(r.kind)?!1:(ut.set(i,this),!0)}async signIn(){try{await(await this.session()).signIn()}catch{this.failed=!0,this.render();return}let i=this.ownerDocument.defaultView?.CustomEvent??CustomEvent;this.ownerDocument.dispatchEvent(new i("cube-session-change"))}}return b(t,"tag","cube-state"),b(t,"css",Ji),b(t,"needsSession",!1),t}var Yi=/^[=+\-@\t\r]/,Xi=/[;"\r\n]/;function Ar(e,n){if(e==null)return"";let t=Y.includes(n)?Se(e):null,o;return t!==null?o=(String(t).includes("e")?t.toLocaleString("en-US",{useGrouping:!1,maximumFractionDigits:20}):String(t)).replace(".",","):(typeof e=="boolean"?o=e?y.yes.toLowerCase():y.no.toLowerCase():typeof e=="object"?o=JSON.stringify(e):o=String(e),Yi.test(o)&&(o=`'${o}`)),Xi.test(o)?`"${o.replace(/"/g,'""')}"`:o}function Er(e,n){return`\uFEFF${[e.map(o=>Ar(o.label,"text")),...n.map(o=>e.map(a=>Ar(o[a.name],a.format)))].map(o=>`${o.join(";")}\r
145
- `).join("")}`}function Mr(e,n,t){let o=e.defaultView,a=new(o?.Blob??Blob)([t],{type:"text/csv;charset=utf-8"}),i=(o?.URL??URL).createObjectURL(a),r=h(e,"a",{href:i,download:n,hidden:!0});e.body.appendChild(r),r.click(),r.remove(),(o?.setTimeout??setTimeout)(()=>(o?.URL??URL).revokeObjectURL(i),0)}var Zi=`${M}
148
+ `,Nr=["error","forbidden","signed-out"],yt=new WeakMap;function jr(e,n){class t extends e{constructor(){super();b(this,"failed",!1);b(this,"kind","loading");b(this,"region");b(this,"message");b(this,"action",null);b(this,"announce",null);this.message=h(n.document,"p"),this.region=h(n.document,"div",{class:"state"},this.message)}disconnectedCallback(){super.disconnectedCallback(),yt.get(this.ownerDocument)===this&&yt.delete(this.ownerDocument),this.announce!==null&&n.clearTimeout(this.announce),this.announce=null}refresh(){return this.failed=!1,this.render(),Promise.resolve()}async load(){this.render()}showState(){this.render()}render(){let i=this.attr("kind"),r=this.failed?"error":vs.includes(i)?i:"loading",s=this.ownerDocument;this.kind=r;let l=Nr.includes(r)&&this.claimAlert();this.action?.remove(),this.action=null,r==="signed-out"?this.action=h(s,"button",{type:"button",onclick:()=>{this.signIn()}},y.signIn):r==="error"&&(this.failed||this.attr("retry")!=="false")&&(this.action=h(s,"button",{type:"button",class:"secondary",onclick:()=>{this.emit("cube-retry")}},y.retry)),this.region.setAttribute("data-kind",r),r==="loading"?this.region.removeAttribute("role"):this.region.setAttribute("role",l?"alert":"status"),l?this.region.removeAttribute("aria-live"):this.region.setAttribute("aria-live",r==="loading"?"off":"polite"),this.action!==null&&this.region.appendChild(this.action),this.region.parentNode!==this.body&&(C(this.body),this.body.appendChild(this.region));let u=this.failed?y.error:this.attr("message")??ks[r];if(this.announce!==null&&n.clearTimeout(this.announce),this.announce=null,this.message.textContent!==u){if(r==="loading"){this.message.textContent=u;return}this.message.textContent="",this.announce=n.setTimeout(()=>{this.announce=null,this.message.textContent=u},0)}}claimAlert(){let i=this.ownerDocument,r=yt.get(i);return r!==void 0&&r!==this&&r.isConnected&&Nr.includes(r.kind)?!1:(yt.set(i,this),!0)}async signIn(){try{await(await this.session()).signIn()}catch{this.failed=!0,this.render();return}let i=this.ownerDocument.defaultView?.CustomEvent??CustomEvent;this.ownerDocument.dispatchEvent(new i("cube-session-change"))}}return b(t,"tag","cube-state"),b(t,"css",Ss),b(t,"needsSession",!1),t}var xs=/^[=+\-@\t\r]/,Ts=/[;"\r\n]/;function Ir(e,n){if(e==null)return"";let t=ne.includes(n)?ae(e):null,o;return t!==null?o=(String(t).includes("e")?t.toLocaleString("en-US",{useGrouping:!1,maximumFractionDigits:20}):String(t)).replace(".",","):(typeof e=="boolean"?o=e?y.yes.toLowerCase():y.no.toLowerCase():typeof e=="object"?o=JSON.stringify(e):o=String(e),xs.test(o)&&(o=`'${o}`)),Ts.test(o)?`"${o.replace(/"/g,'""')}"`:o}function Br(e,n){return`\uFEFF${[e.map(o=>Ir(o.label,"text")),...n.map(o=>e.map(a=>Ir(o[a.name],a.format)))].map(o=>`${o.join(";")}\r
149
+ `).join("")}`}function Ur(e,n,t){let o=e.defaultView,a=new(o?.Blob??Blob)([t],{type:"text/csv;charset=utf-8"}),i=(o?.URL??URL).createObjectURL(a),r=h(e,"a",{href:i,download:n,hidden:!0});e.body.appendChild(r),r.click(),r.remove(),(o?.setTimeout??setTimeout)(()=>(o?.URL??URL).revokeObjectURL(i),0)}var Cs=`${O}
146
150
  .tools{display:flex;flex-wrap:wrap;align-items:flex-end;gap:.75rem;margin-bottom:.75rem}
147
151
  .control{display:flex;flex-direction:column;gap:.25rem;min-width:0;max-width:100%}
148
152
  .control>label,legend{font-weight:600}
@@ -155,8 +159,8 @@ th,td{padding:.5rem .75rem;text-align:start;border-bottom:1px solid var(--cube-c
155
159
  th{font-weight:600;white-space:nowrap}
156
160
  th button{min-height:auto;padding:0;border:0;background:none;color:inherit;font:inherit;font-weight:600}
157
161
  th button:hover{background:none;text-decoration:underline}
158
- th[aria-sort=ascending] button::after{content:" \u25B2";content:" \u25B2"/""}
159
- th[aria-sort=descending] button::after{content:" \u25BC";content:" \u25BC"/""}
162
+ th[aria-sort=ascending] .arrow::after{content:" \u25B2"}
163
+ th[aria-sort=descending] .arrow::after{content:" \u25BC"}
160
164
  .num{text-align:end;white-space:nowrap}
161
165
  tbody tr{cursor:pointer}
162
166
  tbody tr:hover{background:var(--cube-color-primary-subtle)}
@@ -165,7 +169,7 @@ tbody tr.chosen{background:var(--cube-color-primary-subtle);box-shadow:inset 4px
165
169
  .pager{display:flex;flex-wrap:wrap;align-items:center;gap:.5rem;margin-top:.75rem}
166
170
  .pager p,.export-status{margin:0;color:var(--cube-color-text-muted)}
167
171
  .pager p{margin-inline-end:auto}
168
- `,ct=Y,Dr=200,es=50,ts=300,Lr=" search";function ns(e){let n=$(e.slice(0,10));return n===null?null:(n.setDate(n.getDate()+1),O(n))}var Le=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);function Fr(e,n,t){let o=e[n];e[n]=Le(o)&&Le(t)?{...o,...t}:t}function rs(e,n){if(typeof e=="number"&&typeof n=="number")return Math.sign(e-n);let t=String(e),o=String(n);return t<o?-1:t>o?1:0}function os(e,n){if(!Le(e)||!Le(n))return e;let t={...n,...e};for(let[o,a]of[["gte",1],["gt",1],["lte",-1],["lt",-1]]){let i=e[o],r=n[o];i!=null&&r!==void 0&&r!==null&&(t[o]=rs(r,i)===a?r:i)}return t}function _r(e,n){let t=n.document;class o extends e{constructor(){super(...arguments);b(this,"period",new z(this));b(this,"context",null);b(this,"parts",new Map);b(this,"values",new Map);b(this,"sortBy",null);b(this,"page",1);b(this,"requests",0);b(this,"rowsController",null);b(this,"debounce",null);b(this,"exporting",null);b(this,"headers",new Map);b(this,"frame",null);b(this,"table",null);b(this,"pagerText",null);b(this,"previous",null);b(this,"next",null);b(this,"pager",null);b(this,"exportButton",null);b(this,"exportStatus",null);b(this,"shownResource",null);b(this,"chosen",null);b(this,"shownIds",null);b(this,"updates",0)}shownFields(){return this.context?.columns.map(r=>r.name)??[]}disconnectedCallback(){super.disconnectedCallback(),this.stopDebounce(),this.rowsController?.abort(),this.exporting?.abort(),this.exporting=null}async load(r,s){if(s===null)return;this.stopDebounce(),this.context=null,this.rowsController?.abort();let l=C(this,"resource");++this.updates,l!==this.shownResource&&(this.values.clear(),this.sortBy=null,this.page=1,this.chosen=null,this.shownIds=null,this.shownResource=l),this.detailTarget();let u=this.attr("period"),c=u===null||u===""?null:tt(this.attr("date-field"),null,this.localName),p=le(this),f=await et(this,u);if(r.aborted)return;this.period.follow(f);let m=f===null||c===null?p:{...p,...Ze(c,f.value)},d=await s.schema(l);if(r.aborted)return;let g=W(this.attr("fields")),w=d===null||d.fields.some(I=>I.name==="id"),v={session:s,resource:l,columns:[],base:m,fields:g===null?void 0:[...new Set([...w?["id"]:[],...g])],size:Math.min(G(this,"page-size",1,25),Dr)};this.exporting?.abort(),this.exporting=null,r.addEventListener("abort",()=>this.rowsController?.abort(),{once:!0});let k=W(this.attr("filters"))??[];this.checkFilterable(d,k);let x=k.filter(I=>!(I in p)||Le(p[I]));for(let I of[...this.parts.keys()])x.includes(I)||this.parts.delete(I);let P=V(this);this.context=v;let A=await this.fetchRows(v,this.query(v,v.size,this.page)),D=A===null?null:await this.lastPageIfPast(v,A);if(D===null||r.aborted)return;let S=D.data[0];v.columns=Q(d,g,P,S);let E=new Map([...P].map(([I,Pr])=>[I,{...Pr,hidden:!1}])),j=Q(d,x,E,S);this.build(v,d,j),this.renderRows(v,D)}checkFilterable(r,s){if(r===null)return;let l=this.attr("search")?.trim()??"",u=s.map(c=>["filters",c]);l!==""&&u.push(["search",l]);for(let[c,p]of u)if(!r.filterable.includes(p))throw new TypeError(y.invalid.notFilterable(this.localName,c,p))}detailTarget(){let r=this.attr("detail")?.trim()??"";if(r==="")return null;try{return t.querySelector(r)}catch{throw new TypeError(y.invalid.selector(this.localName,"detail",r))}}query(r,s,l){let u={},c=this.attr("search")?.trim()??"",p=this.values.get(Lr)?.trim()??"";c!==""&&p!==""&&Fr(u,c,{ilike:`%${p}%`});for(let[g,w]of this.parts){let v=w();v!==null&&Fr(u,g,v)}let f={...r.base};for(let[g,w]of Object.entries(u)){let v=f[g];f[g]=v===void 0?w:os(v,w)}let m=this.sortBy??(this.attr("sort")?.trim()||null),d={filter:f,page:{size:s,number:l}};return m!==null&&(d.sort=m),r.fields!==void 0&&(d.fields=r.fields),d}async fetchRows(r,s){let l=++this.requests;this.rowsController?.abort();let u=new AbortController;this.rowsController=u,this.setAttribute("aria-busy","true");try{let c=await r.session.resource(r.resource).list(s,{signal:u.signal});return l===this.requests&&!u.signal.aborted?c:null}finally{l===this.requests&&this.removeAttribute("aria-busy")}}async lastPageIfPast(r,s){let l=s.meta.page;return s.data.length>0||this.page<=1||l===void 0||l===null||l.total===0?s:(this.page=Math.max(1,l.pages),this.fetchRows(r,this.query(r,r.size,this.page)))}async update(r){let s=this.context;if(s===null||!this.isConnected)return;r&&(this.page=1);let l=++this.updates;try{let u=await this.fetchRows(s,this.query(s,s.size,this.page)),c=u===null?null:await this.lastPageIfPast(s,u);c!==null&&this.renderRows(s,c)}catch(u){if(l!==this.updates||u?.name==="AbortError")return;this.showRowsState(ss(u))}}later(r){this.stopDebounce(),this.debounce=n.setTimeout(()=>{this.debounce=null,this.update(r)},ts)}stopDebounce(){this.debounce!==null&&n.clearTimeout(this.debounce),this.debounce=null}build(r,s,l){this.parts=new Map;let u=[];if((this.attr("search")?.trim()??"")!==""){let f=h(t,"input",{type:"search"});u.push(this.control(f,Lr,y.search,!0))}for(let f of l)u.push(this.filterControl(f));this.flag("export")?(this.exportButton=h(t,"button",{type:"button",class:"secondary",onclick:()=>this.toggleExport()},y.exportCsv),this.exportStatus=h(t,"p",{class:"export-status",role:"status"}),u.push(this.exportButton,this.exportStatus)):(this.exportButton=null,this.exportStatus=null),this.headers=new Map,this.frame=h(t,"div",{class:"scroll"}),this.pagerText=h(t,"p",{"aria-live":"polite"}),this.previous=h(t,"button",{type:"button",class:"secondary",onclick:()=>this.go(-1)},y.previous),this.next=h(t,"button",{type:"button",class:"secondary",onclick:()=>this.go(1)},y.next),this.pager=h(t,"div",{class:"pager"},this.pagerText,this.previous,this.next);let p=h(t,"thead",{},h(t,"tr",{},...r.columns.map(f=>{let m=s?.sortable.includes(f.name)===!0,d=h(t,"th",{scope:"col",class:ct.includes(f.format)?"num":null},m?h(t,"button",{type:"button",onclick:()=>this.sortOn(f.name)},f.label):f.label,...this.exampleField(r.session,r.resource,f.name)?[" ",Xe(t)]:[]);return m&&this.headers.set(f.name,d),d})));this.table=h(t,"table",{},h(t,"caption",{class:"sr-only"},U(r.resource)),p,h(t,"tbody")),this.markSort(),T(this.body),this.body.appendChild(h(t,"div",{class:"card"},u.length>0?h(t,"div",{class:"tools"},...u):null,this.frame,this.pager))}control(r,s,l,u,c){let p=`cube-table-${++is}`;return r.id=p,r.value=this.values.get(s)??"",c?.(r),r.addEventListener(u?"input":"change",()=>{this.values.set(s,r.value),c?.(r),u?this.later(!0):this.update(!0)}),h(t,"div",{class:"control"},h(t,"label",{for:p},l),r)}filterControl(r){let s=r.name,l=w=>this.values.get(w)?.trim()??"",u=ot(r),c=u===null&&r.format==="boolean";if(u!==null||c){let w=u??[{value:"true",label:y.yes},{value:"false",label:y.no}],v=h(t,"select",{},h(t,"option",{value:""},y.all),...w.map(x=>h(t,"option",{value:x.value},x.label))),k=ct.includes(r.format);return this.parts.set(s,()=>{let x=l(s);return x===""?null:c?x==="true":k?Se(x)??x:x}),this.control(v,s,r.label,!1)}let p=r.format==="date"||r.format==="datetime";if(!p&&!ct.includes(r.format))return this.parts.set(s,()=>l(s)===""?null:{ilike:`%${l(s)}%`}),this.control(h(t,"input",{type:"text"}),s,r.label,!0);let f=w=>{let v=Ae(l(w),r.format);return"value"in v&&typeof v.value=="number"?v.value:null},m=w=>v=>{l(w)!==""&&f(w)===null?v.setAttribute("aria-invalid","true"):v.removeAttribute("aria-invalid")},d=w=>{let v=`${s}:${w}`,k=h(t,"input",{type:p?"date":"text",inputmode:p?null:"decimal","aria-label":`${y[w]} (${r.label})`});return this.control(k,v,y[w],!p,p?void 0:m(v))};this.parts.set(s,()=>{let w={},v=p?l(`${s}:min`)||null:f(`${s}:min`),k=p?ns(l(`${s}:max`)):f(`${s}:max`);return v!==null&&(w.gte=v),k!==null&&(w[p?"lt":"lte"]=k),Object.keys(w).length>0?w:null});let g=h(t,"legend",{},r.label);return h(t,"fieldset",{class:"control"},g,d("min"),d("max"))}sortOn(r){let s=this.sortBy??(this.attr("sort")?.trim()||null);this.sortBy=s===r?`-${r}`:r,this.markSort(),this.update(!0)}markSort(){let r=this.sortBy??(this.attr("sort")?.trim()||""),s=r.replace(/^-/,"");for(let[l,u]of this.headers)l===s?u.setAttribute("aria-sort",r.startsWith("-")?"descending":"ascending"):u.removeAttribute("aria-sort")}go(r){this.page=Math.max(1,this.page+r),this.update(!1)}renderRows(r,s){let l=this.frame,u=this.table;if(l===null||u===null)return;let c=s.meta.page,p=c?.total??s.data.length,f=Math.max(1,c?.pages??1);this.page=c?.number??this.page,T(l);let m=JSON.stringify(s.data.map(g=>g.id??null));if(m!==this.shownIds&&(this.chosen=null),this.shownIds=m,s.data.length===0){this.showRowsState({kind:"empty",detail:null});return}let d=h(t,"tbody",{},...s.data.map(g=>this.row(r,g)));u.replaceChild(d,u.querySelector("tbody")),l.appendChild(u),this.pager!==null&&(this.pager.hidden=!1),this.pagerText!==null&&(this.pagerText.textContent=y.pageOf(this.page,f,p)),this.previous!==null&&(this.previous.disabled=this.page<=1),this.next!==null&&(this.next.disabled=this.page>=f)}showRowsState(r){this.frame!==null&&(T(this.frame),this.frame.appendChild(h(t,"cube-state",{kind:r.kind,message:r.detail,retry:r.retry===!1?"false":null})),this.pager!==null&&(this.pager.hidden=!0))}row(r,s){let l=()=>this.select(r,s,p),u=f=>this.exampleField(r.session,r.resource,f.name),c=this.chosen!==null&&String(s.id??"")===this.chosen,p=h(t,"tr",{tabindex:"0",class:c?"chosen":null,"aria-current":c?"true":null,onclick:l,onkeydown:(f=>{f.key!=="Enter"&&f.key!==" "||(f.preventDefault(),l())})},...r.columns.map(f=>{let m=[ct.includes(f.format)&&"num",u(f)&&"example"];return h(t,"td",{class:m.filter(Boolean).join(" ")||null},_(s[f.name],f.format))}));return p}select(r,s,l){let u=s.id??null;this.chosen=u===null?null:String(u);for(let p of Array.from(l.parentElement?.children??[]))p.classList.toggle("chosen",p===l),p===l?p.setAttribute("aria-current","true"):p.removeAttribute("aria-current");if(this.emit("cube-select",{resource:r.resource,id:u,row:s}),u===null)return;let c=null;try{c=this.detailTarget()}catch(p){this.showState(X(p));return}c?.setAttribute("record-id",String(u))}toggleExport(){if(this.exporting!==null){this.exporting.abort(),this.exporting=null,this.exportButton!==null&&(this.exportButton.textContent=y.exportCsv),this.exportStatus!==null&&(this.exportStatus.textContent="");return}this.runExport()}async runExport(){let r=this.context,s=this.exportButton,l=this.exportStatus;if(r===null||s===null||l===null)return;let u=new AbortController;this.exporting=u;let{signal:c}=u;s.textContent=y.cancel,l.textContent=y.exporting(0);let p=[],f="";try{let m=0,d=this.query(r,Dr,1);for await(let g of r.session.resource(r.resource).pages(d,{signal:c}))if(c.aborted||(p.push(...g.data),l.textContent=y.exporting(p.length),++m>=es))break;c.aborted||Mr(t,`${r.resource}-${O(new Date)}.csv`,Er(r.columns,p))}catch(m){!c.aborted&&m?.name!=="AbortError"&&(f=y.exportFailed)}finally{this.exporting===u&&(this.exporting=null,s.textContent=y.exportCsv,l.textContent=f)}}}return b(o,"tag","cube-table"),b(o,"css",Zi),o}var is=0;function ss(e){return e instanceof TypeError?{kind:"error",detail:null}:X(e)}var as=`${M}${ue}
172
+ `,wt=ne,Hr=200,As=50,Rs=300,zr=" search";function Es(e){let n=B(e.slice(0,10));return n===null?null:(n.setDate(n.getDate()+1),U(n))}var ue=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);function Vr(e,n,t){let o=e[n];e[n]=ue(o)&&ue(t)?{...o,...t}:t}function Ds(e,n){let t=ae(e),o=ae(n);if(t!==null&&o!==null)return Math.sign(t-o);let a=String(e),i=String(n);return a<i?-1:a>i?1:0}function Kr(e){return e!==void 0&&(!ue(e)||"ilike"in e)}function Ms(e,n){if(!ue(e)||!ue(n))return e;let t={...n,...e};for(let[o,a]of[["gte",1],["gt",1],["lte",-1],["lt",-1]]){let i=e[o],r=n[o];i!=null&&r!==void 0&&r!==null&&(t[o]=Ds(r,i)===a?r:i)}return t}function qr(e,n){let t=n.document;class o extends e{constructor(){super(...arguments);b(this,"period",new G(this));b(this,"context",null);b(this,"parts",new Map);b(this,"values",new Map);b(this,"sortBy",null);b(this,"page",1);b(this,"requests",0);b(this,"rowsController",null);b(this,"debounce",null);b(this,"exporting",null);b(this,"headers",new Map);b(this,"frame",null);b(this,"table",null);b(this,"pagerText",null);b(this,"previous",null);b(this,"next",null);b(this,"pager",null);b(this,"exportButton",null);b(this,"exportStatus",null);b(this,"shownResource",null);b(this,"chosen",null);b(this,"shownIds",null);b(this,"updates",0);b(this,"warned",new Set)}shownFields(){return this.context?.columns.map(r=>r.name)??[]}disconnectedCallback(){super.disconnectedCallback(),this.stopDebounce(),this.rowsController?.abort(),this.exporting?.abort(),this.exporting=null}async load(r,s){if(s===null)return;this.stopDebounce(),this.context=null,this.rowsController?.abort();let l=_(this,"resource");++this.updates,l!==this.shownResource&&(this.values.clear(),this.sortBy=null,this.page=1,this.chosen=null,this.shownIds=null,this.shownResource=l),this.detailTarget();let u=this.attr("period"),c=u===null||u===""?null:ct(this.attr("date-field"),null,this.localName),p=fe(this),m=await ut(this,u);if(r.aborted)return;this.period.follow(m);let f=m===null||c===null?p:{...p,...lt(c,m.value)},d=await s.schema(l);if(r.aborted)return;let g=Z(this.attr("fields")),w=d===null||d.fields.some(E=>E.name==="id"),v={session:s,resource:l,columns:[],base:f,fields:g===null?void 0:[...new Set([...w?["id"]:[],...g])],size:Math.min(X(this,"page-size",1,25),Hr)};this.exporting?.abort(),this.exporting=null,r.addEventListener("abort",()=>this.rowsController?.abort(),{once:!0});let k=Z(this.attr("filters"))??[];this.checkFilterable(d,k);let S=k.filter(E=>!(E in p)||ue(p[E]));for(let E of[...this.parts.keys()])S.includes(E)||this.parts.delete(E);let R=W(this);this.context=v;let L=await this.fetchRows(v,this.query(v,v.size,this.page)),j=L===null?null:await this.lastPageIfPast(v,L);if(j===null||r.aborted)return;let x=j.data[0];v.columns=ee(d,g,R,x);let F=new Map([...R].map(([E,z])=>[E,{...z,hidden:!1}])),T=ee(d,S,F,x);this.build(v,d,T),this.renderRows(v,j)}checkFilterable(r,s){if(r===null)return;let l=this.attr("search")?.trim()??"",u=s.map(c=>["filters",c]);l!==""&&u.push(["search",l]);for(let[c,p]of u)if(!r.filterable.includes(p))throw new A(y.invalid.notFilterable(this.localName,c,p))}detailTarget(){let r=this.attr("detail")?.trim()??"";if(r==="")return null;try{return t.querySelector(r)}catch{throw new A(y.invalid.selector(this.localName,"detail",r))}}query(r,s,l){let u={},c=this.attr("search")?.trim()??"",p=this.values.get(zr)?.trim()??"";c!==""&&p!==""&&Vr(u,c,{ilike:`%${p}%`});for(let[g,w]of this.parts){let v=w();v!==null&&Vr(u,g,v)}let m={...r.base};for(let[g,w]of Object.entries(u)){let v=m[g];m[g]=v===void 0?w:Ms(v,w)}let f=this.sortBy??(this.attr("sort")?.trim()||null),d={filter:m,page:{size:s,number:l}};return f!==null&&(d.sort=f),r.fields!==void 0&&(d.fields=r.fields),d}async fetchRows(r,s){let l=++this.requests;this.rowsController?.abort();let u=new AbortController;this.rowsController=u,this.setAttribute("aria-busy","true");try{let c=await r.session.resource(r.resource).list(s,{signal:u.signal});return l===this.requests&&!u.signal.aborted?c:null}finally{l===this.requests&&this.removeAttribute("aria-busy")}}async lastPageIfPast(r,s){let l=s.meta.page;return s.data.length>0||this.page<=1||l===void 0||l===null||l.total===0?s:(this.page=Math.max(1,l.pages),this.fetchRows(r,this.query(r,r.size,this.page)))}async update(r){let s=this.context;if(s===null||!this.isConnected)return;r&&(this.page=1);let l=++this.updates;try{let u=await this.fetchRows(s,this.query(s,s.size,this.page)),c=u===null?null:await this.lastPageIfPast(s,u);c!==null&&this.renderRows(s,c)}catch(u){if(l!==this.updates||u?.name==="AbortError")return;this.showRowsState(Y(u))}}later(r){this.stopDebounce(),this.debounce=n.setTimeout(()=>{this.debounce=null,this.update(r)},Rs)}stopDebounce(){this.debounce!==null&&n.clearTimeout(this.debounce),this.debounce=null}build(r,s,l){this.parts=new Map;let u=[],c=this.attr("search")?.trim()??"";if(c!==""){Kr(r.base[c])&&this.warnFixed("search",c);let m=h(t,"input",{type:"search"});u.push(this.control(m,zr,y.search,!0))}for(let m of l)u.push(this.filterControl(m,r.base[m.name]));this.flag("export")?(this.exportButton=h(t,"button",{type:"button",class:"secondary",onclick:()=>this.toggleExport()},y.exportCsv),this.exportStatus=h(t,"p",{class:"export-status",role:"status"}),u.push(this.exportButton,this.exportStatus)):(this.exportButton=null,this.exportStatus=null),this.headers=new Map,this.frame=h(t,"div",{class:"scroll"}),this.pagerText=h(t,"p",{"aria-live":"polite"}),this.previous=h(t,"button",{type:"button",class:"secondary",onclick:()=>this.go(-1)},y.previous),this.next=h(t,"button",{type:"button",class:"secondary",onclick:()=>this.go(1)},y.next),this.pager=h(t,"div",{class:"pager"},this.pagerText,this.previous,this.next);let p=h(t,"thead",{},h(t,"tr",{},...r.columns.map(m=>{let f=s?.sortable.includes(m.name)===!0,d=h(t,"th",{scope:"col",class:wt.includes(m.format)?"num":null},f?h(t,"button",{type:"button",onclick:()=>this.sortOn(m.name)},m.label,h(t,"span",{class:"arrow","aria-hidden":"true"})):m.label,...this.exampleField(r.session,r.resource,m.name)?[" ",at(t)]:[]);return f&&this.headers.set(m.name,d),d})));this.table=h(t,"table",{},h(t,"caption",{class:"sr-only"},K(r.resource)),p,h(t,"tbody")),this.markSort(),C(this.body),this.body.appendChild(h(t,"div",{class:"card"},u.length>0?h(t,"div",{class:"tools"},...u):null,this.frame,this.pager))}control(r,s,l,u,c){let p=`cube-table-${++Ls}`;return r.id=p,r.value=this.values.get(s)??"",c?.(r),r.addEventListener(u?"input":"change",()=>{this.values.set(s,r.value),c?.(r),u?this.later(!0):this.update(!0)}),h(t,"div",{class:"control"},h(t,"label",{for:p},l),r)}warnFixed(r,s){let u=`${this.localName}: filter already fixes "${s}", so ${r} on it changes nothing.`;this.warned.has(u)||(this.warned.add(u),console.warn(u))}filterControl(r,s){let l=r.name,u=v=>this.values.get(v)?.trim()??"",c=mt(r),p=c===null&&r.format==="boolean";if(c!==null||p){ue(s)&&this.warnFixed("filters",l);let v=c??[{value:"true",label:y.yes},{value:"false",label:y.no}],k=h(t,"select",{},h(t,"option",{value:""},y.all),...v.map(R=>h(t,"option",{value:R.value},R.label))),S=wt.includes(r.format);return this.parts.set(l,()=>{let R=u(l);return R===""?null:p?R==="true":S?ae(R)??R:R}),this.control(k,l,r.label,!1)}let m=r.format==="date"||r.format==="datetime";if(!m&&!wt.includes(r.format))return Kr(s)&&this.warnFixed("filters",l),this.parts.set(l,()=>u(l)===""?null:{ilike:`%${u(l)}%`}),this.control(h(t,"input",{type:"text"}),l,r.label,!0);let f=v=>{let k=_e(u(v),r.format);return"value"in k&&typeof k.value=="number"?k.value:null},d=v=>k=>{u(v)!==""&&f(v)===null?k.setAttribute("aria-invalid","true"):k.removeAttribute("aria-invalid")},g=v=>{let k=`${l}:${v}`,S=h(t,"input",{type:m?"date":"text",inputmode:m?null:"decimal","aria-label":`${y[v]} (${r.label})`});return this.control(S,k,y[v],!m,m?void 0:d(k))};this.parts.set(l,()=>{let v={},k=m?u(`${l}:min`)||null:f(`${l}:min`),S=m?Es(u(`${l}:max`)):f(`${l}:max`);return k!==null&&(v.gte=k),S!==null&&(v[m?"lt":"lte"]=S),Object.keys(v).length>0?v:null});let w=h(t,"legend",{},r.label);return h(t,"fieldset",{class:"control"},w,g("min"),g("max"))}sortOn(r){let s=this.sortBy??(this.attr("sort")?.trim()||null);this.sortBy=s===r?`-${r}`:r,this.markSort(),this.update(!0)}markSort(){let r=this.sortBy??(this.attr("sort")?.trim()||""),s=r.replace(/^-/,"");for(let[l,u]of this.headers)l===s?u.setAttribute("aria-sort",r.startsWith("-")?"descending":"ascending"):u.removeAttribute("aria-sort")}go(r){this.page=Math.max(1,this.page+r),this.update(!1)}renderRows(r,s){let l=this.frame,u=this.table;if(l===null||u===null)return;let c=s.meta.page,p=c?.total??s.data.length,m=Math.max(1,c?.pages??1);this.page=c?.number??this.page,C(l);let f=JSON.stringify(s.data.map(g=>g.id??null));if(f!==this.shownIds&&(this.chosen=null),this.shownIds=f,s.data.length===0){this.showRowsState({kind:"empty",detail:null});return}let d=h(t,"tbody",{},...s.data.map(g=>this.row(r,g)));d.querySelector('tr[tabindex="0"]')===null&&d.firstElementChild?.setAttribute("tabindex","0"),u.replaceChild(d,u.querySelector("tbody")),l.appendChild(u),this.pager!==null&&(this.pager.hidden=!1),this.pagerText!==null&&(this.pagerText.textContent=y.pageOf(this.page,m,p)),this.previous!==null&&(this.previous.disabled=this.page<=1),this.next!==null&&(this.next.disabled=this.page>=m)}showRowsState(r){this.frame!==null&&(C(this.frame),this.frame.appendChild(h(t,"cube-state",{kind:r.kind,message:r.detail,retry:r.retry===!1?"false":null})),this.pager!==null&&(this.pager.hidden=!0))}row(r,s){let l=()=>this.select(r,s,p),u=m=>this.exampleField(r.session,r.resource,m.name),c=this.chosen!==null&&String(s.id??"")===this.chosen,p=h(t,"tr",{tabindex:c?"0":"-1",class:c?"chosen":null,"aria-current":c?"true":null,onclick:l,onkeydown:(m=>{if(m.altKey||m.ctrlKey||m.metaKey)return;if(m.key==="Enter"||m.key===" "){m.preventDefault(),l();return}let f=this.rowFor(p,m.key);f!==void 0&&(m.preventDefault(),f!==null&&(p.setAttribute("tabindex","-1"),f.setAttribute("tabindex","0"),f.focus()))})},...r.columns.map(m=>{let f=[wt.includes(m.format)&&"num",u(m)&&"example"];return h(t,"td",{class:f.filter(Boolean).join(" ")||null},I(s[m.name],m.format))}));return p}rowFor(r,s){let l=r.parentElement;switch(s){case"ArrowDown":return r.nextElementSibling;case"ArrowUp":return r.previousElementSibling;case"Home":return l?.firstElementChild;case"End":return l?.lastElementChild;default:return}}select(r,s,l){let u=s.id??null;this.chosen=u===null?null:String(u);for(let p of Array.from(l.parentElement?.children??[]))p.classList.toggle("chosen",p===l),p.setAttribute("tabindex",p===l?"0":"-1"),p===l?p.setAttribute("aria-current","true"):p.removeAttribute("aria-current");if(this.emit("cube-select",{resource:r.resource,id:u,row:s}),u===null)return;let c=null;try{c=this.detailTarget()}catch(p){this.showState(Y(p));return}c?.setAttribute("record-id",String(u))}toggleExport(){if(this.exporting!==null){this.exporting.abort(),this.exporting=null,this.exportButton!==null&&(this.exportButton.textContent=y.exportCsv),this.exportStatus!==null&&(this.exportStatus.textContent="");return}this.runExport()}async runExport(){let r=this.context,s=this.exportButton,l=this.exportStatus;if(r===null||s===null||l===null)return;let u=new AbortController;this.exporting=u;let{signal:c}=u;s.textContent=y.cancel,l.textContent=y.exporting(0);let p=[],m="";try{let f=0,d=this.query(r,Hr,1);for await(let g of r.session.resource(r.resource).pages(d,{signal:c}))if(c.aborted||(p.push(...g.data),l.textContent=y.exporting(p.length),++f>=As))break;c.aborted||Ur(t,`${r.resource}-${U(new Date)}.csv`,Br(r.columns,p))}catch(f){!c.aborted&&f?.name!=="AbortError"&&(m=y.exportFailed)}finally{this.exporting===u&&(this.exporting=null,s.textContent=y.exportCsv,l.textContent=m)}}}return b(o,"tag","cube-table"),b(o,"css",Cs),o}var Ls=0;var Fs=`${O}${ge}
169
173
  ol{margin:0;padding:0;list-style:none;display:flex;flex-direction:column;gap:.25rem}
170
174
  button{display:grid;grid-template-columns:1fr auto;gap:.125rem .75rem;width:100%;padding:.5rem .75rem;
171
175
  border:0;border-radius:var(--cube-radius);background:none;color:inherit;font:inherit;text-align:start;cursor:pointer}
@@ -176,4 +180,10 @@ button:focus-visible{outline:2px solid var(--cube-color-focus);outline-offset:2p
176
180
  svg{grid-column:1/-1;display:block;width:100%;height:.5rem}
177
181
  rect.bar{fill:var(--cube-color-series-1)}
178
182
  .note{margin:.5rem 0 0;font-size:.875rem;color:var(--cube-color-text-muted)}
179
- `;function $r(e,n){class t extends e{constructor(){super(...arguments);b(this,"period",new z(this))}shownFields(){return ce(this)}async load(i,r){if(r===null)return;let s=C(this,"resource"),l=C(this,"by"),u=G(this,"limit",1,5),c=await de(this,this.period,i,l);if(c===null)return;let{data:p,meta:f}=await nt(r,s,l,c,i);if(i.aborted)return;let m={descending:this.attr("order")!=="asc",limit:u},d=await rt(this,r,p,{by:l,fn:c.fn},m,i);if(d===null)return;if(d.length===0){this.showState("empty");return}let g=(f?.groups??0)>p.length;this.render(d,l,pe(this,c.count),g)}render(i,r,s,l){let u=n.document,c=Math.max(...i.map(m=>m.value)),p=this.attr("label"),f={};p!==null&&p!==""&&(f["aria-label"]=p),l&&(f["aria-describedby"]="incomplete"),T(this.body),this.body.appendChild(h(u,"div",{class:"card"},...p===null||p===""?[]:[h(u,"p",{class:"label"},p)],h(u,"ol",f,...i.map(m=>h(u,"li",{},h(u,"button",{type:"button",onclick:()=>{this.emit("cube-select",{by:r,key:m.key})}},h(u,"span",{class:"name"},m.label)," ",h(u,"span",{class:"value"},s(m.value)),this.bar(m.value,c))))),...l?[h(u,"p",{class:"note",id:"incomplete",role:"note"},y.incomplete)]:[]))}bar(i,r){let s=r>0&&i>0?i/r*100:0;return N(n.document,"svg",{viewBox:"0 0 100 4",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},N(n.document,"rect",{class:"bar",x:0,y:0,width:s,height:4}))}}return b(t,"tag","cube-top"),b(t,"css",as),t}var ls=[["cube-state",Cr],["cube-app-shell",Xn],["cube-period-picker",Tr],["cube-kpi",kr],["cube-chart",fr],["cube-top",$r],["cube-table",_r],["cube-detail",hr],["cube-form",yr],["cube-calc",ar],["cube-board",rr],["cube-gap-list",wr]],Or=new WeakMap;function us(e){return class extends e.HTMLElement{}}function cs(e,n,t){let o=e.document.fonts;if(!(n.fontFamily===null||e.FontFace===void 0||o===void 0))for(let a of n.fontFiles){let i=`${n.fontFamily}|${a.src}|${a.weight??""}|${a.style??""}`;if(!t.has(i)){t.add(i);try{let r={style:a.style??"normal"};a.weight!==void 0&&(r.weight=a.weight);let s=new e.FontFace(n.fontFamily,`url("${a.src}")`,r);o.add(s),s.load().catch(()=>{})}catch{}}}}function ds(e){let n=e.document,t=Or.get(n);t?.stop();let o=new e.CSSStyleSheet,a=t?.fonts??new Set,i=r=>{try{o.replaceSync(Tn(r)),cs(e,r,a)}catch{}};i(ze()),n.adoptedStyleSheets=[...n.adoptedStyleSheets.filter(r=>r!==t?.sheet),o],Or.set(n,{sheet:o,stop:Ve(i),fonts:a})}function Kt(e,n={}){let t=e??globalThis;if(t.customElements===void 0||t.HTMLElement===void 0||t.document===void 0)return;let o=t,a=o.customElements;ds(o);let i=Yn(o,n);for(let[r,s]of ls)a.get(r)===void 0&&a.define(r,s(i,o));a.get("cube-page")===void 0&&a.define("cube-page",us(o));for(let r of["cube-field","cube-input","cube-result","cube-column"])a.get(r)===void 0&&a.define(r,er(o))}var ps=Object.freeze({...Je,defineBlocks:Kt});globalThis.CubeApp=ps;typeof customElements<"u"&&Kt();})();
183
+ `;function Gr(e,n){class t extends e{constructor(){super(...arguments);b(this,"period",new G(this))}shownFields(){return he(this)}async load(i,r){if(r===null)return;let s=_(this,"resource"),l=_(this,"by"),u=X(this,"limit",1,5),c=await be(this,this.period,i,l);if(c===null)return;let{data:p,meta:m}=await dt(r,s,l,c,i);if(i.aborted)return;let f={descending:this.attr("order")!=="asc",limit:u},d=await pt(this,r,p,{by:l,fn:c.fn},f,i);if(d===null)return;if(d.length===0){this.showState("empty");return}let g=(m?.groups??0)>p.length;this.render(d,l,ye(this,c.count),g)}render(i,r,s,l){let u=n.document,c=Math.max(...i.map(f=>f.value)),p=this.attr("label"),m={};p!==null&&p!==""&&(m["aria-label"]=p),l&&(m["aria-describedby"]="incomplete"),C(this.body),this.body.appendChild(h(u,"div",{class:"card"},...p===null||p===""?[]:[h(u,"p",{class:"label"},p)],h(u,"ol",m,...i.map(f=>h(u,"li",{},h(u,"button",{type:"button",onclick:()=>{this.emit("cube-select",{by:r,key:f.key})}},h(u,"span",{class:"name"},f.label)," ",h(u,"span",{class:"value"},s(f.value)),this.bar(f.value,c))))),...l?[h(u,"p",{class:"note",id:"incomplete",role:"note"},y.incomplete)]:[]))}bar(i,r){let s=r>0&&i>0?i/r*100:0;return H(n.document,"svg",{viewBox:"0 0 100 4",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},H(n.document,"rect",{class:"bar",x:0,y:0,width:s,height:4}))}}return b(t,"tag","cube-top"),b(t,"css",Fs),t}var _s=[["cube-state",jr],["cube-app-shell",ur],["cube-period-picker",Pr],["cube-kpi",_r],["cube-chart",Ar],["cube-top",Gr],["cube-table",qr],["cube-detail",Er],["cube-form",Mr],["cube-calc",wr],["cube-board",gr],["cube-gap-list",Lr]],Wr=new WeakMap;function Os(e){return class extends e.HTMLElement{}}function $s(e,n,t){let o=e.document.fonts;if(!(n.fontFamily===null||e.FontFace===void 0||o===void 0))for(let a of n.fontFiles){let i=`${n.fontFamily}|${a.src}|${a.weight??""}|${a.style??""}`;if(!t.has(i)){t.add(i);try{let r={style:a.style??"normal"};a.weight!==void 0&&(r.weight=a.weight);let s=new e.FontFace(n.fontFamily,`url("${a.src}")`,r);o.add(s),s.load().catch(()=>{})}catch{}}}}function Ps(e){let n=e.document,t=Wr.get(n);t?.stop();let o=new e.CSSStyleSheet,a=t?.fonts??new Set,i=r=>{try{o.replaceSync(_n(r)),$s(e,r,a)}catch{}};i(We()),n.adoptedStyleSheets=[...n.adoptedStyleSheets.filter(r=>r!==t?.sheet),o],Wr.set(n,{sheet:o,stop:Qe(i),fonts:a})}function Zt(e,n={}){let t=e??globalThis;if(t.customElements===void 0||t.HTMLElement===void 0||t.document===void 0)return;let o=t,a=o.customElements;Ps(o);let i=lr(o,n);for(let[r,s]of _s)a.get(r)===void 0&&a.define(r,s(i,o));a.get("cube-page")===void 0&&a.define("cube-page",Os(o));for(let r of["cube-field","cube-input","cube-result","cube-column"])a.get(r)===void 0&&a.define(r,dr(o))}var Ns=5e3,js=6e4,Qr=6e4,Is=1e4,Bs=`
184
+ .banner{display:flex;flex-wrap:wrap;align-items:center;gap:.75rem;padding:.5rem 1rem;
185
+ border-bottom:1px solid var(--cube-color-border);border-left:4px solid var(--cube-color-warning);
186
+ background:var(--cube-color-surface);font-size:.875rem}
187
+ .banner p{margin:0;flex:1 1 16rem}
188
+ .banner[data-state=expired],.banner[data-state=closed]{border-left-color:var(--cube-color-danger)}
189
+ `;function Jr(e,n){let t=e.document,o=e.now??Date.now,a=Date.parse(n.expiresAt),i=Number.isFinite(a),r=i?new Intl.DateTimeFormat("nl-NL",{hour:"2-digit",minute:"2-digit",timeZoneName:"short"}).format(new Date(a)):null,s=t.createElement("cube-trial-banner"),l=s.attachShadow({mode:"open"}),u=[De,Bs].map(T=>{let E=new e.CSSStyleSheet;return E.replaceSync(T),E}),c=h(t,"p",{},y.trial.banner(r,n.leest)),p=h(t,"div",{class:"banner",role:"status","aria-live":"polite"},c),m=null,f=!1,d=!1,g=null,w=0;l.adoptedStyleSheets=u,l.appendChild(p);let v=()=>{t.body.insertBefore(s,t.body.firstChild)},k=()=>t.visibilityState!=="hidden",S=()=>{f=!0,g?.abort(),m!==null&&e.clearTimeout(m),m=null,t.removeEventListener("visibilitychange",F)},R=(T,E)=>{S(),!s.isConnected&&t.body!==null&&v(),p.setAttribute("data-state",T),C(c),c.appendChild(t.createTextNode(y.trial[T])),E!==void 0&&p.appendChild(h(t,"button",{type:"button",onclick:E[1]},E[0]))},L=(T=k()?Ns:js)=>{if(f)return;m!==null&&e.clearTimeout(m);let E=Math.max(T,Math.min(Qr,w-o()));m=e.setTimeout(j,i?Math.max(0,Math.min(E,a-o())):E)},j=async()=>{if(m=null,f)return;if(i&&o()>=a){R("expired");return}w=0,d=!0;let T=e.AbortController===void 0?null:new e.AbortController;g=T;let E=T===null?null:e.setTimeout(()=>T.abort(),Is);try{let z=await e.fetch(n.statusUrl,{headers:{Accept:"application/json",Authorization:`Bearer ${n.token}`},cache:"no-store",...T===null?{}:{signal:T.signal}});await x(z)}catch{L()}finally{d=!1,g=null,E!==null&&e.clearTimeout(E)}},x=async T=>{if(f)return;if(T.ok&&(w=0),T.status===429){let $=(T.headers.get("Retry-After")??"").trim();/^\d+$/.test($)&&(w=o()+Math.min(Qr,Number($)*1e3))}if(T.ok||T.status===429||T.status>=500){L();return}let E={};try{let $=await T.json();$!==null&&typeof $=="object"&&(E=$)}catch{}let z=E.code,D=null;if(z==="trial_expired")R("expired");else if(z==="trial_elsewhere")R("elsewhere",[y.trial.reload,()=>e.location.reload()]);else if(z==="trial_replaced"&&(D=Us(E.newer,n.dmpUrl))!==null){let $=D.href;E.wider===!1?(R("refreshing"),e.location.assign($)):R("wider",[y.trial.load,()=>e.location.assign($)])}else R("closed")};function F(){if(!(f||d)){if(!k()){L();return}if(w>o()){L(0);return}m!==null&&e.clearTimeout(m),j()}}return t.addEventListener("visibilitychange",F),t.body===null?t.addEventListener("DOMContentLoaded",v,{once:!0}):v(),L(),S}function Us(e,n){if(typeof e!="string")return null;try{let t=new URL(e);return t.origin===new URL(n).origin&&t.pathname.startsWith("/apps/proef/")?t:null}catch{return null}}var Hs=Object.freeze({...it,defineBlocks:Zt});globalThis.CubeApp=Hs;typeof customElements<"u"&&Zt();var Yr=Ye(),en=globalThis;Yr!==null&&en.document!==void 0&&en.CSSStyleSheet!==void 0&&Jr(en,Yr);})();