@mapled/vanilla 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/mapled.js +17 -17
- package/dist/mapled.js.sha384 +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
<html lang="en">
|
|
14
14
|
<head>
|
|
15
15
|
<title data-mapled-bind="home.headline">Studio Nord</title>
|
|
16
|
-
<script src="https://cdn.jsdelivr.net/npm/@mapled/vanilla@0.2.
|
|
16
|
+
<script src="https://cdn.jsdelivr.net/npm/@mapled/vanilla@0.2.2/dist/mapled.js" data-mapled-key="mk_live_…" defer></script>
|
|
17
17
|
</head>
|
|
18
18
|
<body>
|
|
19
19
|
<h1 data-mapled-bind="home.headline">Websites, built by hand</h1>
|
package/dist/mapled.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
/*! @mapled/vanilla 0.2.
|
|
2
|
-
"use strict";(()=>{var Ct=Object.defineProperty;var Lt=(e,t,n)=>t in e?Ct(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var be=(e,t,n)=>Lt(e,typeof t!="symbol"?t+"":t,n);var we="mapled-preview",ie="mapled:preview",Nt=/^mpv_[A-Za-z0-9]{16,96}$/,Ze=/^mps_[A-Za-z0-9]{16,96}$/,Ve=new WeakMap,Ut=4e3;function ke(){if(typeof window>"u"||typeof document>"u")return null;try{let e=window.sessionStorage,t=Ve.get(window);return t||Ve.set(window,t={memory:null,exchanging:null,epoch:0}),{location:window.location,history:window.history,sessionStorage:e,page:t}}catch{return null}}function It(e){try{let t=e.getItem(ie);if(!t)return null;let n=JSON.parse(t),r=typeof n?.expiresAt=="string"?Date.parse(n.expiresAt):NaN;return typeof n?.draftToken!="string"||!Ze.test(n.draftToken)||!(r>Date.now())?(e.removeItem(ie),null):{draftToken:n.draftToken,expiresAt:n.expiresAt}}catch{return null}}function K(e){let t=It(e.sessionStorage);if(t)return t;let n=e.page.memory;return n&&Date.parse(n.expiresAt)>Date.now()?n:(e.page.memory=null,null)}function B(){let e=ke();return e?K(e):null}function Ye(e){let t;try{t=new URL(e.location.href)}catch{return null}let n=t.searchParams.get(we);if(n===null)return null;t.searchParams.delete(we);try{e.history.replaceState(e.history.state,"",`${t.pathname}${t.search}${t.hash}`)}catch{}return n}function Se(){let e=ke();if(e){e.page.memory=null,e.page.epoch++,e.page.exchanging=null,Ye(e);try{e.sessionStorage.removeItem(ie)}catch{}}}function Je(e={}){let t=ke();if(!t)return Promise.resolve(null);let n=Ye(t);if(n===null)return t.page.exchanging?t.page.exchanging.done:Promise.resolve(K(t));if(!Nt.test(n))return Promise.resolve(K(t));if(t.page.exchanging?.token===n)return t.page.exchanging.done;let r=(e.apiUrl??"https://api.mapled.io").replace(/\/+$/,""),s=(e.appUrl??"https://app.mapled.io").replace(/\/+$/,""),o=e.fetch??fetch,c=++t.page.epoch,a=(async()=>{try{let i=await o(`${r}/v1/delivery/preview/exchange`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({token:n}),cache:"no-store"});if(i.ok){let p=await i.json();if(typeof p.draftToken!="string"||typeof p.expiresAt!="string"||!Ze.test(p.draftToken)||!(Date.parse(p.expiresAt)>Date.now())||t.page.epoch!==c)return K(t);let d={draftToken:p.draftToken,expiresAt:p.expiresAt};t.page.memory=d;try{t.sessionStorage.setItem(ie,JSON.stringify(d))}catch{}return d}if(i.status===401&&t.page.epoch===c){let p=await i.json().catch(()=>null),d=p?.error?.projectId;if(t.page.epoch===c&&p?.error?.code==="PREVIEW_EXPIRED"&&typeof d=="string"&&/^[0-9a-f-]{8,64}$/i.test(d))return t.location.assign(`${s}/preview/expired?project=${encodeURIComponent(d)}`),await new Promise(l=>setTimeout(l,Ut)),K(t)}return K(t)}catch{return K(t)}})(),f={token:n,done:a};return t.page.exchanging=f,a.then(()=>{t.page.exchanging===f&&(t.page.exchanging=null)}),a}async function Qe(e){return(await Je(e))?.draftToken??null}function Ae(e){if(!e||typeof e!="object")return;let{release:t,publishedAt:n}=e;if(t===null)return n===null?null:void 0;if(!(!Number.isInteger(t)||t<1||typeof n!="string"))return{release:t,publishedAt:n}}var Dt=1e4;function Ft(e,t){let n=typeof document>"u"?void 0:globalThis.performance?.timeOrigin;if(n===void 0)return!1;let r=Date.parse(t.get("date")??""),s=Number.isNaN(r)?0:r+(Number(t.get("age"))||0)*1e3-Date.now();return Date.parse(e)>n+s-Dt}function et(e,t){return(n,r)=>{if(e!==void 0)return e;let s=t?.();return s!==void 0?s:Ft(n.publishedAt,r)?null:n.release}}function tt(e,t,n){let r=typeof e.key=="string"&&e.key.length>0;if(!r&&!e.endpoint)throw new Error("Mapled: watchRelease needs an endpoint or a delivery key.");let s=r?`${(e.apiUrl??"https://api.mapled.io").replace(/\/+$/,"")}/v1/delivery/release`:e.endpoint,o=r?{accept:"application/json","x-mapled-key":e.key}:{accept:"application/json"},c=(r?Math.max(15,e.interval??60):Math.max(2,e.interval??10))*1e3,a=e.fetch??fetch,f=typeof document>"u"?null:document,i,p=null,d=0,l=null,g=0,S=!1,x,P=null,b=()=>!f||f.visibilityState!=="hidden",C=()=>{S||!b()||(x=setTimeout(L,Math.min(c*2**g,3e5)))};async function L(){if(S||P)return;let N=new AbortController;P=N;let U=null;try{let G=await a(s,{cache:"no-cache",headers:o,signal:N.signal}),O=G.ok?Ae(await G.json()):void 0;if(S)return;O===void 0?g+=1:(g=0,i===void 0&&(i=O?t(O,G.headers):null),O&&O.release>(p?.release??0)&&(p=O),O&&O.release>(i??0)?(U={next:O,previous:i},i=O.release,d=O.release,l=null):O&&l!==null&&typeof i=="number"&&O.release>=i&&i>d&&(U={next:O,previous:l},d=i,l=null))}catch{if(S)return;g+=1}finally{P===N&&(P=null)}C(),U&&e.onPublish(U.next,U.previous)}let $=()=>{clearTimeout(x),b()&&L()};f?.addEventListener("visibilitychange",$);let z=n?.(N=>{if(S||typeof i!="number"||N>=i||i<=d||(l=l===null?N:Math.min(l,N),p===null||p.release<i))return;d=i;let U=l;l=null,e.onPublish(p,U)});return b()&&L(),()=>{S=!0,clearTimeout(x),P?.abort(),z?.(),f?.removeEventListener("visibilitychange",$)}}function nt(e){let t={};return e.forEach((n,r)=>{typeof n!="string"||r in t||(t[r]=n)}),t}async function ve(e,t,n){if(!n?.key)throw new Error("Mapled: a delivery key is required.");let r=(n.apiUrl??"https://api.mapled.io").replace(/\/+$/,""),s=typeof HTMLFormElement<"u"&&t instanceof HTMLFormElement?nt(new FormData(t)):typeof FormData<"u"&&t instanceof FormData?nt(t):{...t},o=n.page??(typeof window<"u"&&typeof document<"u"?window.location.pathname:void 0),c={...s};n.consent&&(c._consent=n.consent),o&&c._page===void 0&&(c._page=o),n.test&&(c._test=!0);let a=B()?.draftToken,f={"content-type":"application/json","x-mapled-key":n.key};a&&(f["x-mapled-draft"]=a);let i;try{i=await(n.fetch??fetch)(`${r}/v1/delivery/forms/${encodeURIComponent(e)}`,{method:"POST",headers:f,body:JSON.stringify(c)})}catch{return{ok:!1,status:0,code:"NETWORK",message:"Mapled couldn't be reached. Try again in a minute."}}if(i.ok)return{ok:!0};let p=`The submission wasn't accepted (${i.status}).`,d;try{let l=await i.json();l.error?.message&&(p=l.error.message),typeof l.error?.code=="string"&&(d=l.error.code)}catch{}return{ok:!1,status:i.status,code:d,message:p}}var Re=/^[a-z0-9][a-z0-9-]{0,63}$/,rt=new Set;function _t(e){if(typeof process<"u")return;let t=e?.aliases;if(!(!t||typeof t!="object")){for(let[n,r]of Object.entries(t))if(!(!r||typeof r!="object"||!Re.test(n)))for(let[s,o]of Object.entries(r)){if(typeof o!="string"||!Re.test(s)||!Re.test(o))continue;let c=`${n}.${s}`;rt.has(c)||(rt.add(c),console.warn(`[mapled] \u201C${s}\u201D in \u201C${n}\u201D was renamed to \u201C${o}\u201D. The old key keeps working until its alias is removed in Mapled \u2014 use \u201C${o}\u201D instead.`))}}}function it(e,t={}){let n=(t.apiUrl??"https://api.mapled.io").replace(/\/+$/,""),r=new URLSearchParams;t.width&&r.set("w",String(t.width)),t.height&&r.set("h",String(t.height)),t.fit&&r.set("fit",t.fit),t.format&&r.set("fmt",t.format),t.quality&&r.set("q",String(t.quality));let s=r.toString();return`${n}/files/${encodeURIComponent(e)}${s?`?${s}`:""}`}var W=class extends Error{constructor(n,r,s){super(r);be(this,"status");be(this,"code");this.name="MapledError",this.status=n,this.code=s}},st=e=>Number.isInteger(e)&&e>=1,ot=()=>new Error("Mapled: release must be a positive whole number.");function at(e){let t=(e.apiUrl??"https://api.mapled.io").replace(/\/+$/,"");if(!e.key)throw new Error("Mapled: a delivery key is required.");if(e.release!==void 0&&!st(e.release))throw ot();let n=(d,l)=>(e.fetch??fetch)(d,l),r,s=new Set;async function o(){return e.draft===null?null:typeof e.draft=="string"?e.draft||null:typeof e.draft=="function"?await e.draft()||null:Qe({apiUrl:t,appUrl:e.appUrl,fetch:e.fetch})}async function c(d){let l=`Mapled request failed (${d.status}).`,g;try{let S=await d.json();S.error?.message&&(l=S.error.message),typeof S.error?.code=="string"&&(g=S.error.code)}catch{}return new W(d.status,l,g)}async function a(d,l,g){let S=await o(),x=g.release??e.release;if(x!==void 0&&!st(x))throw ot();x!==void 0&&!S&&l.set("release",String(x));let P=g.locale||e.locale;P&&l.set("locale",P);let b=l.toString(),C=await n(`${t}${d}${b?`?${b}`:""}`,{headers:S?{"x-mapled-key":e.key,"x-mapled-draft":S}:{"x-mapled-key":e.key},...S?{cache:"no-store"}:{},...g.signal?{signal:g.signal}:{}});if(!C.ok)throw await c(C);let L=await C.json();if(!S){let $=Number(C.headers.get("x-mapled-release"));if(Number.isInteger($)&&$>=1){r=r===void 0?$:Math.min(r,$);for(let z of s)Promise.resolve().then(()=>z($))}}return _t(L),L}let f=(d,l)=>(l.expand?.length&&d.set("expand",l.expand.join(",")),l.fields?.length&&d.set("fields",l.fields.join(",")),d),i=async(d,l)=>{try{return(await a(d,f(new URLSearchParams,l),l)).record}catch(g){if(g instanceof W&&g.status===404&&g.code!=="RELEASE_NOT_FOUND")return null;throw g}};return{async getRecords(d,l={}){let g=new URLSearchParams;for(let[S,x]of Object.entries(l.filter??{}))if(x!==null&&typeof x=="object")for(let[P,b]of Object.entries(x))b!==void 0&&g.set(`filter[${S}][${P}]`,Array.isArray(b)?b.join(","):String(b));else g.set(`filter[${S}]`,String(x));return l.sort&&g.set("sort",l.sort),l.limit!==void 0&&g.set("limit",String(l.limit)),l.offset!==void 0&&g.set("offset",String(l.offset)),f(g,l),a(`/v1/delivery/collections/${encodeURIComponent(d)}/records`,g,l)},getRecord(d,l,g={}){return i(`/v1/delivery/collections/${encodeURIComponent(d)}/records/${encodeURIComponent(l)}`,g)},getRecordBySlug(d,l,g={}){return i(`/v1/delivery/collections/${encodeURIComponent(d)}/records/by-slug/${encodeURIComponent(l)}`,g)},getSingle(d,l={}){return i(`/v1/delivery/singles/${encodeURIComponent(d)}`,l)},async isPreview(){return await o()!==null},watch(d,l={}){return tt({key:e.key,apiUrl:t,interval:l.interval,onPublish:d,fetch:e.fetch},et(l.from,()=>r),g=>(s.add(g),()=>{s.delete(g)}))},async getRelease(d={}){let l=await n(`${t}/v1/delivery/release`,{headers:{"x-mapled-key":e.key},cache:"no-cache",...d.signal?{signal:d.signal}:{}});if(!l.ok)throw await c(l);let g=Ae(await l.json());if(g===void 0)throw new Error("Mapled: the release pointer didn't come back as one \u2014 check the API origin.");return g}}}var jt=/^[a-z0-9][a-z0-9_-]{0,63}$/;function Z(e){if(typeof e!="string")return null;let t=e.trim().split(".");if(t.length>8)return null;for(let n of t)if(!jt.test(n))return null;return t}var ae=(e,t)=>e!==null&&typeof e=="object"&&!Array.isArray(e)&&Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0;function Te(e,t){let n=e.data,r=e.expanded;for(let s=0;s<t.length;s++){let o=t[s],c=s<t.length-1?ae(r,o):void 0;if(c!==void 0){if(c===null||Array.isArray(c))return;n=ae(c,"data"),r=ae(c,"expanded");continue}if(n=ae(n,o),r=void 0,n===void 0)return}return n}var Y=e=>e==null||e===""||Array.isArray(e)&&e.length===0;function Ee(e){return typeof e=="string"?e:typeof e=="number"&&Number.isFinite(e)?String(e):typeof e=="boolean"?e?"true":"false":Array.isArray(e)&&e.every(t=>typeof t=="string"||typeof t=="number")?e.join(", "):null}var Kt=new Set(["http:","https:","mailto:","tel:"]),Bt=new Set(["http:","https:"]),Ht=2048;function H(e,t,n){if(typeof e!="string"||e.length>Ht)return null;let r;try{r=new URL(e,t)}catch{return null}return!(n==="link"?Kt:Bt).has(r.protocol)||r.username!==""||r.password!==""?null:r.href}var qt=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,lt=e=>typeof e=="string"&&qt.test(e);function ut(e,t,n){let r=[],s=e.replace(/\{([^{}]*)\}/g,(c,a)=>{let f=Z(a);if(!f)return r.push({ok:!1,reason:"bad-path",path:a.trim().slice(0,80)}),"";let i=n(f);if(typeof i!="string"&&typeof i!="number"||i==="")return r.push({ok:!1,reason:"empty",path:f.join(".")}),"";try{return encodeURIComponent(String(i))}catch{return r.push({ok:!1,reason:"unsafe-url",path:f.join(".")}),""}});if(r[0])return r[0];let o=H(s,t,"link");return o===null?{ok:!1,reason:"unsafe-url",path:e.slice(0,80)}:{ok:!0,url:o}}var zt=1e5,dt=8,ft=2048,Wt="!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",ct={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:"\xA0",copy:"\xA9",reg:"\xAE",trade:"\u2122",mdash:"\u2014",ndash:"\u2013",hellip:"\u2026",laquo:"\xAB",raquo:"\xBB"};function pt(e,t,n){let r=t.createDocumentFragment();if(typeof e!="string"||e==="")return r;let s=e.replace(/\r\n?/g,`
|
|
3
|
-
`).replace(/\t/g," ").replace(/\u0000/g,"\uFFFD"),o={doc:t,base:n};if(s.length>zt){for(let c of s.split(/\n{2,}/))c.trim()!==""&&(
|
|
4
|
-
`),r,0),r}function
|
|
5
|
-
`).trim();o!==""&&(
|
|
1
|
+
/*! @mapled/vanilla 0.2.2 | MIT | https://mapled.io */
|
|
2
|
+
"use strict";(()=>{var $t=Object.defineProperty;var Lt=(e,t,n)=>t in e?$t(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var be=(e,t,n)=>Lt(e,typeof t!="symbol"?t+"":t,n);var we="mapled-preview",ie="mapled:preview",Ut=/^mpv_[A-Za-z0-9]{16,96}$/,Ze=/^mps_[A-Za-z0-9]{16,96}$/,Ve=new WeakMap,Nt=4e3;function ke(){if(typeof window>"u"||typeof document>"u")return null;try{let e=window.sessionStorage,t=Ve.get(window);return t||Ve.set(window,t={memory:null,exchanging:null,epoch:0}),{location:window.location,history:window.history,sessionStorage:e,page:t}}catch{return null}}function It(e){try{let t=e.getItem(ie);if(!t)return null;let n=JSON.parse(t),r=typeof n?.expiresAt=="string"?Date.parse(n.expiresAt):NaN;return typeof n?.draftToken!="string"||!Ze.test(n.draftToken)||!(r>Date.now())?(e.removeItem(ie),null):{draftToken:n.draftToken,expiresAt:n.expiresAt}}catch{return null}}function K(e){let t=It(e.sessionStorage);if(t)return t;let n=e.page.memory;return n&&Date.parse(n.expiresAt)>Date.now()?n:(e.page.memory=null,null)}function B(){let e=ke();return e?K(e):null}function Ye(e){let t;try{t=new URL(e.location.href)}catch{return null}let n=t.searchParams.get(we);if(n===null)return null;t.searchParams.delete(we);try{e.history.replaceState(e.history.state,"",`${t.pathname}${t.search}${t.hash}`)}catch{}return n}function Se(){let e=ke();if(e){e.page.memory=null,e.page.epoch++,e.page.exchanging=null,Ye(e);try{e.sessionStorage.removeItem(ie)}catch{}}}function Je(e={}){let t=ke();if(!t)return Promise.resolve(null);let n=Ye(t);if(n===null)return t.page.exchanging?t.page.exchanging.done:Promise.resolve(K(t));if(!Ut.test(n))return Promise.resolve(K(t));if(t.page.exchanging?.token===n)return t.page.exchanging.done;let r=(e.apiUrl??"https://api.mapled.io").replace(/\/+$/,""),s=(e.appUrl??"https://app.mapled.io").replace(/\/+$/,""),o=e.fetch??fetch,c=++t.page.epoch,l=(async()=>{try{let i=await o(`${r}/v1/delivery/preview/exchange`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({token:n}),cache:"no-store"});if(i.ok){let p=await i.json();if(typeof p.draftToken!="string"||typeof p.expiresAt!="string"||!Ze.test(p.draftToken)||!(Date.parse(p.expiresAt)>Date.now())||t.page.epoch!==c)return K(t);let d={draftToken:p.draftToken,expiresAt:p.expiresAt};t.page.memory=d;try{t.sessionStorage.setItem(ie,JSON.stringify(d))}catch{}return d}if(i.status===401&&t.page.epoch===c){let p=await i.json().catch(()=>null),d=p?.error?.projectId;if(t.page.epoch===c&&p?.error?.code==="PREVIEW_EXPIRED"&&typeof d=="string"&&/^[0-9a-f-]{8,64}$/i.test(d))return t.location.assign(`${s}/preview/expired?project=${encodeURIComponent(d)}`),await new Promise(a=>setTimeout(a,Nt)),K(t)}return K(t)}catch{return K(t)}})(),f={token:n,done:l};return t.page.exchanging=f,l.then(()=>{t.page.exchanging===f&&(t.page.exchanging=null)}),l}async function Qe(e){return(await Je(e))?.draftToken??null}function Ae(e){if(!e||typeof e!="object")return;let{release:t,publishedAt:n}=e;if(t===null)return n===null?null:void 0;if(!(!Number.isInteger(t)||t<1||typeof n!="string"))return{release:t,publishedAt:n}}var Ft=1e4;function Dt(e,t){let n=typeof document>"u"?void 0:globalThis.performance?.timeOrigin;if(n===void 0)return!1;let r=Date.parse(t.get("date")??""),s=Number.isNaN(r)?0:r+(Number(t.get("age"))||0)*1e3-Date.now();return Date.parse(e)>n+s-Ft}function et(e,t){return(n,r)=>{if(e!==void 0)return e;let s=t?.();return s!==void 0?s:Dt(n.publishedAt,r)?null:n.release}}function tt(e,t,n){let r=typeof e.key=="string"&&e.key.length>0;if(!r&&!e.endpoint)throw new Error("Mapled: watchRelease needs an endpoint or a delivery key.");let s=r?`${(e.apiUrl??"https://api.mapled.io").replace(/\/+$/,"")}/v1/delivery/release`:e.endpoint,o=r?{accept:"application/json","x-mapled-key":e.key}:{accept:"application/json"},c=(r?Math.max(15,e.interval??60):Math.max(2,e.interval??10))*1e3,l=e.fetch??fetch,f=typeof document>"u"?null:document,i,p=null,d=0,a=null,g=0,S=!1,E,M=null,b=()=>!f||f.visibilityState!=="hidden",$=()=>{S||!b()||(E=setTimeout(L,Math.min(c*2**g,3e5)))};async function L(){if(S||M)return;let U=new AbortController;M=U;let N=null;try{let X=await l(s,{cache:"no-cache",headers:o,signal:U.signal}),O=X.ok?Ae(await X.json()):void 0;if(S)return;O===void 0?g+=1:(g=0,i===void 0&&(i=O?t(O,X.headers):null),O&&O.release>(p?.release??0)&&(p=O),O&&O.release>(i??0)?(N={next:O,previous:i},i=O.release,d=O.release,a=null):O&&a!==null&&typeof i=="number"&&O.release>=i&&i>d&&(N={next:O,previous:a},d=i,a=null))}catch{if(S)return;g+=1}finally{M===U&&(M=null)}$(),N&&e.onPublish(N.next,N.previous)}let C=()=>{clearTimeout(E),b()&&L()};f?.addEventListener("visibilitychange",C);let z=n?.(U=>{if(S||typeof i!="number"||U>=i||i<=d||(a=a===null?U:Math.min(a,U),p===null||p.release<i))return;d=i;let N=a;a=null,e.onPublish(p,N)});return b()&&L(),()=>{S=!0,clearTimeout(E),M?.abort(),z?.(),f?.removeEventListener("visibilitychange",C)}}function nt(e){let t={};return e.forEach((n,r)=>{typeof n!="string"||r in t||(t[r]=n)}),t}async function Re(e,t,n){if(!n?.key)throw new Error("Mapled: a delivery key is required.");let r=(n.apiUrl??"https://api.mapled.io").replace(/\/+$/,""),s=typeof HTMLFormElement<"u"&&t instanceof HTMLFormElement?nt(new FormData(t)):typeof FormData<"u"&&t instanceof FormData?nt(t):{...t},o=n.page??(typeof window<"u"&&typeof document<"u"?window.location.pathname:void 0),c={...s};n.consent&&(c._consent=n.consent),o&&c._page===void 0&&(c._page=o),n.test&&(c._test=!0);let l=B()?.draftToken,f={"content-type":"application/json","x-mapled-key":n.key};l&&(f["x-mapled-draft"]=l);let i;try{i=await(n.fetch??fetch)(`${r}/v1/delivery/forms/${encodeURIComponent(e)}`,{method:"POST",headers:f,body:JSON.stringify(c)})}catch{return{ok:!1,status:0,code:"NETWORK",message:"Mapled couldn't be reached. Try again in a minute."}}if(i.ok)return{ok:!0};let p=`The submission wasn't accepted (${i.status}).`,d;try{let a=await i.json();a.error?.message&&(p=a.error.message),typeof a.error?.code=="string"&&(d=a.error.code)}catch{}return{ok:!1,status:i.status,code:d,message:p}}var ve=/^[a-z0-9][a-z0-9-]{0,63}$/,rt=new Set;function _t(e){if(typeof process<"u")return;let t=e?.aliases;if(!(!t||typeof t!="object")){for(let[n,r]of Object.entries(t))if(!(!r||typeof r!="object"||!ve.test(n)))for(let[s,o]of Object.entries(r)){if(typeof o!="string"||!ve.test(s)||!ve.test(o))continue;let c=`${n}.${s}`;rt.has(c)||(rt.add(c),console.warn(`[mapled] \u201C${s}\u201D in \u201C${n}\u201D was renamed to \u201C${o}\u201D. The old key keeps working until its alias is removed in Mapled \u2014 use \u201C${o}\u201D instead.`))}}}function it(e,t={}){let n=new URLSearchParams;t.width&&n.set("w",String(t.width)),t.height&&n.set("h",String(t.height)),t.fit&&n.set("fit",t.fit),t.format&&n.set("fmt",t.format),t.quality&&n.set("q",String(t.quality));let r=n.toString(),s=t.files?(t.files[e]??t.files[e.toLowerCase()])?.url:void 0;return typeof s=="string"&&s?r?`${s}${s.includes("?")?"&":"?"}${r}`:s:`${(t.apiUrl??"https://api.mapled.io").replace(/\/+$/,"")}/files/${encodeURIComponent(e)}${r?`?${r}`:""}`}var W=class extends Error{constructor(n,r,s){super(r);be(this,"status");be(this,"code");this.name="MapledError",this.status=n,this.code=s}},st=e=>Number.isInteger(e)&&e>=1,ot=()=>new Error("Mapled: release must be a positive whole number.");function lt(e){let t=(e.apiUrl??"https://api.mapled.io").replace(/\/+$/,"");if(!e.key)throw new Error("Mapled: a delivery key is required.");if(e.release!==void 0&&!st(e.release))throw ot();let n=(d,a)=>(e.fetch??fetch)(d,a),r,s=new Set;async function o(){return e.draft===null?null:typeof e.draft=="string"?e.draft||null:typeof e.draft=="function"?await e.draft()||null:Qe({apiUrl:t,appUrl:e.appUrl,fetch:e.fetch})}async function c(d){let a=`Mapled request failed (${d.status}).`,g;try{let S=await d.json();S.error?.message&&(a=S.error.message),typeof S.error?.code=="string"&&(g=S.error.code)}catch{}return new W(d.status,a,g)}async function l(d,a,g){let S=await o(),E=g.release??e.release;if(E!==void 0&&!st(E))throw ot();E!==void 0&&!S&&a.set("release",String(E));let M=g.locale||e.locale;M&&a.set("locale",M);let b=a.toString(),$=await n(`${t}${d}${b?`?${b}`:""}`,{headers:S?{"x-mapled-key":e.key,"x-mapled-draft":S}:{"x-mapled-key":e.key},...S?{cache:"no-store"}:{},...g.signal?{signal:g.signal}:{}});if(!$.ok)throw await c($);let L=await $.json();if(!S){let C=Number($.headers.get("x-mapled-release"));if(Number.isInteger(C)&&C>=1){r=r===void 0?C:Math.min(r,C);for(let z of s)Promise.resolve().then(()=>z(C))}}return _t(L),L}let f=(d,a)=>(a.expand?.length&&d.set("expand",a.expand.join(",")),a.fields?.length&&d.set("fields",a.fields.join(",")),d),i=async(d,a)=>{try{return(await l(d,f(new URLSearchParams,a),a)).record}catch(g){if(g instanceof W&&g.status===404&&g.code!=="RELEASE_NOT_FOUND")return null;throw g}};return{async getRecords(d,a={}){let g=new URLSearchParams;for(let[S,E]of Object.entries(a.filter??{}))if(E!==null&&typeof E=="object")for(let[M,b]of Object.entries(E))b!==void 0&&g.set(`filter[${S}][${M}]`,Array.isArray(b)?b.join(","):String(b));else g.set(`filter[${S}]`,String(E));return a.sort&&g.set("sort",a.sort),a.limit!==void 0&&g.set("limit",String(a.limit)),a.offset!==void 0&&g.set("offset",String(a.offset)),f(g,a),l(`/v1/delivery/collections/${encodeURIComponent(d)}/records`,g,a)},getRecord(d,a,g={}){return i(`/v1/delivery/collections/${encodeURIComponent(d)}/records/${encodeURIComponent(a)}`,g)},getRecordBySlug(d,a,g={}){return i(`/v1/delivery/collections/${encodeURIComponent(d)}/records/by-slug/${encodeURIComponent(a)}`,g)},getSingle(d,a={}){return i(`/v1/delivery/singles/${encodeURIComponent(d)}`,a)},async isPreview(){return await o()!==null},watch(d,a={}){return tt({key:e.key,apiUrl:t,interval:a.interval,onPublish:d,fetch:e.fetch},et(a.from,()=>r),g=>(s.add(g),()=>{s.delete(g)}))},async getRelease(d={}){let a=await n(`${t}/v1/delivery/release`,{headers:{"x-mapled-key":e.key},cache:"no-cache",...d.signal?{signal:d.signal}:{}});if(!a.ok)throw await c(a);let g=Ae(await a.json());if(g===void 0)throw new Error("Mapled: the release pointer didn't come back as one \u2014 check the API origin.");return g}}}var jt=/^[a-z0-9][a-z0-9_-]{0,63}$/;function Z(e){if(typeof e!="string")return null;let t=e.trim().split(".");if(t.length>8)return null;for(let n of t)if(!jt.test(n))return null;return t}var le=(e,t)=>e!==null&&typeof e=="object"&&!Array.isArray(e)&&Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0;function Te(e,t){let n=e.data,r=e.expanded;for(let s=0;s<t.length;s++){let o=t[s],c=s<t.length-1?le(r,o):void 0;if(c!==void 0){if(c===null||Array.isArray(c))return;n=le(c,"data"),r=le(c,"expanded");continue}if(n=le(n,o),r=void 0,n===void 0)return}return n}var Y=e=>e==null||e===""||Array.isArray(e)&&e.length===0;function xe(e){return typeof e=="string"?e:typeof e=="number"&&Number.isFinite(e)?String(e):typeof e=="boolean"?e?"true":"false":Array.isArray(e)&&e.every(t=>typeof t=="string"||typeof t=="number")?e.join(", "):null}var Kt=new Set(["http:","https:","mailto:","tel:"]),Bt=new Set(["http:","https:"]),Ht=2048;function H(e,t,n){if(typeof e!="string"||e.length>Ht)return null;let r;try{r=new URL(e,t)}catch{return null}return!(n==="link"?Kt:Bt).has(r.protocol)||r.username!==""||r.password!==""?null:r.href}var qt=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,at=e=>typeof e=="string"&&qt.test(e);function ut(e,t,n){let r=[],s=e.replace(/\{([^{}]*)\}/g,(c,l)=>{let f=Z(l);if(!f)return r.push({ok:!1,reason:"bad-path",path:l.trim().slice(0,80)}),"";let i=n(f);if(typeof i!="string"&&typeof i!="number"||i==="")return r.push({ok:!1,reason:"empty",path:f.join(".")}),"";try{return encodeURIComponent(String(i))}catch{return r.push({ok:!1,reason:"unsafe-url",path:f.join(".")}),""}});if(r[0])return r[0];let o=H(s,t,"link");return o===null?{ok:!1,reason:"unsafe-url",path:e.slice(0,80)}:{ok:!0,url:o}}var zt=1e5,dt=8,ft=2048,Wt="!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",ct={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:"\xA0",copy:"\xA9",reg:"\xAE",trade:"\u2122",mdash:"\u2014",ndash:"\u2013",hellip:"\u2026",laquo:"\xAB",raquo:"\xBB"};function pt(e,t,n){let r=t.createDocumentFragment();if(typeof e!="string"||e==="")return r;let s=e.replace(/\r\n?/g,`
|
|
3
|
+
`).replace(/\t/g," ").replace(/\u0000/g,"\uFFFD"),o={doc:t,base:n};if(s.length>zt){for(let c of s.split(/\n{2,}/))c.trim()!==""&&(P(o,"p",r).textContent=c.trim());return r}return $e(o,s.split(`
|
|
4
|
+
`),r,0),r}function P(e,t,n){let r=e.doc.createElement(t);return n.appendChild(r),r}var Ee=e=>e.trim()==="",Q=e=>e.length-e.trimStart().length;function mt(e){let t=Q(e);if(t>3)return null;let n=0;for(;n<7&&e[t+n]==="#";)n++;if(n===0||n>6)return null;let r=e[t+n];if(r!==void 0&&r!==" ")return null;let s=e.slice(t+n).trim(),o=s.length;for(;o>0&&s[o-1]==="#";)o--;return o<s.length&&(o===0||s[o-1]===" ")&&(s=s.slice(0,o).trim()),{level:n,text:s}}function Ce(e){if(Q(e)>3)return!1;let t=e.replace(/ /g,""),n=t[0];if(t.length<3||n!=="-"&&n!=="*"&&n!=="_")return!1;for(let r of t)if(r!==n)return!1;return!0}function Me(e){let t=/^ {0,3}(`{3,}|~{3,})/.exec(e);if(!t)return null;let n=t[1][0];return n==="`"&&e.slice(t[0].length).includes("`")?null:{mark:n,size:t[1].length}}function J(e){let t=/^( {0,3})([-*+]|\d{1,9}[.)])( +|$)/.exec(e);if(!t)return null;let n=t[2],r=t[3].length,s=n.length>1||/\d/.test(n);return{indent:t[1].length,width:n.length+(r>=1&&r<=4?r:1),ordered:s,start:s?parseInt(n,10):1,rest:e.slice(t[0].length)}}var Pe=e=>/^ {0,3}>/.test(e);function Gt(e){if(mt(e)!==null||Me(e)!==null||Pe(e)||Ce(e))return!0;let t=J(e);return t!==null&&t.rest!==""&&(!t.ordered||t.start===1)}function $e(e,t,n,r){if(r>=dt){let o=t.join(`
|
|
5
|
+
`).trim();o!==""&&(P(e,"p",n).textContent=o);return}let s=0;for(;s<t.length;){let o=t[s];if(Ee(o)){s++;continue}let c=Me(o);if(c){let p=[],d=Q(o);for(s++;s<t.length;){let a=t[s],g=Me(a);if(g&&g.mark===c.mark&&g.size>=c.size&&a.trim().length===g.size)break;p.push(a.slice(Math.min(d,Q(a)))),s++}s++,P(e,"code",P(e,"pre",n)).textContent=p.length>0?`${p.join(`
|
|
6
6
|
`)}
|
|
7
|
-
`:"";continue}let
|
|
8
|
-
`),
|
|
9
|
-
`,gt=e=>e!==void 0&&/[\p{L}\p{N}]/u.test(e);function
|
|
10
|
-
&`);if(n===-1)return null;let r=e.slice(t+1,n);if(r[0]==="#"){let o=r[1]==="x"||r[1]==="X",c=r.slice(o?2:1);if(!(o?/^[0-9a-fA-F]{1,6}$/:/^[0-9]{1,7}$/).test(c))return null;let
|
|
11
|
-
<`);if(c===-1)return null;s=e.slice(r+1,c),r=c+1}else{let c=r,
|
|
12
|
-
`)break;if(f==="("&&
|
|
13
|
-
`);)r++;let o=e[r];if(o==='"'||o==="'"||o==="("){let c=
|
|
14
|
-
`);)r++}return e[r]!==")"?null:{address:bt(s),end:r+1}}function Oe(e,t,n=!1){let r=t+1;for(;r<e.length;){let o=ht(e,r);if(o!==-1){r=o;continue}if(!n&&e[r]==="!"&&e[r+1]==="["){let c=Oe(e,r+1,!0);if(!c)return null;r=c.end;continue}if(e[r]==="[")return null;if(e[r]==="]")break;r++}if(r>=e.length)return null;let s=Yt(e,r+1);return s?{label:e.slice(t+1,r),address:s.address,end:s.end}:null}var Jt=/^(?:[a-z][a-z0-9+.-]{1,31}:[^\s<>]*|[^\s<>@]+@[^\s<>@]+\.[^\s<>@]+)$/i;function ue(e,t,n,r){if(r>=dt){n.appendChild(e.doc.createTextNode(t));return}let s="",o=()=>{s!==""&&n.appendChild(e.doc.createTextNode(s)),s=""},c=new Set,
|
|
15
|
-
`)for(o(),
|
|
16
|
-
`){let i=s.endsWith(" "),p=s.length;for(;p>0&&s[p-1]===" ";)p--;for(s=s.slice(0,p),i?(o(),
|
|
17
|
-
`,
|
|
18
|
-
<`),p=i===-1?null:t.slice(a+1,i);if(p!==null&&Jt.test(p)){let d=H(p.includes(":")?p:`mailto:${p}`,e.base,"link");if(d!==null){o();let l=M(e,"a",n);l.setAttribute("href",d),l.textContent=p,a=i+1;continue}}}if(f==="&"){let i=Zt(t,a);if(i){s+=i.char,a=i.end;continue}}if(f==="*"||f==="_"||f==="~"){let i=ee(t,a,f),p=i-a,d=!Le(t[i])&&(f!=="_"||!gt(t[a-1])),l=f==="~"?p>=2?[["~~",["del"]]]:[]:[...p>=3?[[f.repeat(3),["em","strong"]]]:[],...p>=2?[[f.repeat(2),["strong"]]]:[],[f,["em"]]],g=!1;if(d)for(let[S,x]of l){if(c.has(S))continue;let P=a+S.length,b=Vt(t,P,S);if(b===-1){c.add(S);continue}if(b===P)continue;o();let C=n;for(let L of x)C=M(e,L,C);ue(e,t.slice(P,b),C,r+1),a=b+S.length,g=!0;break}g||(s+=t.slice(a,i),a=i);continue}s+=f,a++}o()}var Qt="http://www.w3.org/1999/xhtml",en=new Set(["script","style","iframe","frame","frameset","object","embed","applet","base","link","meta","template","noscript"]),ce={href:{on:["a","area"],holds:"link"},src:{on:["img","video","audio","source"],holds:"media"},alt:{on:["img","area"],holds:"text"},title:{on:null,holds:"text"},"aria-label":{on:null,holds:"text"},placeholder:{on:["input","textarea"],holds:"text"},datetime:{on:["time","del","ins"],holds:"text"}},de=e=>e.namespaceURI===Qt,te=e=>!en.has(e.localName.toLowerCase());function Ne(e,t){if(!te(e))return"refused-element";let n=Ee(t);return n===null?"type":(e.textContent=n,null)}function wt(e,t,n){return!te(e)||!de(e)?"refused-element":typeof t!="string"?"type":(e.replaceChildren(pt(t,e.ownerDocument,n.base)),null)}function kt(e,t,n){return typeof e!="string"?null:lt(e)?it(e,{...t.apiUrl?{apiUrl:t.apiUrl}:{},...n?{width:n}:{}}):H(e,t.base,"media")}function St(e,t,n,r){if(!de(e)||e.localName!=="img")return"refused-element";if(typeof t!="string")return"type";let s=kt(t,n,r);return s===null?"unsafe-url":(e.removeAttribute("srcset"),e.setAttribute("src",s),null)}function At(e,t,n,r,s){let o=t.toLowerCase(),c=Object.prototype.hasOwnProperty.call(ce,o)?ce[o]:void 0;if(!c)return"unsupported";if(!te(e)||!de(e))return"refused-element";if(c.on!==null&&!c.on.includes(e.localName))return"unsupported";if(c.holds==="text"){let f=Ee(n);return f===null?"type":(e.setAttribute(o,f),null)}if(typeof n!="string")return"type";let a=c.holds==="media"?kt(n,r,e.localName==="img"?s:void 0):H(n,r.base,"link");return a===null?"unsafe-url":(e.setAttribute(o,a),null)}function vt(e,t){return!de(e)||e.localName!=="a"&&e.localName!=="area"?"unsupported":(e.setAttribute("href",t),null)}function X(e,t){t?e.removeAttribute("hidden"):e.setAttribute("hidden","")}var Rt=["text","markdown","date","datetime","number"],tn=/^\d{4}-\d{2}-\d{2}$/,nn=/^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/;function Tt(e,t,n){let r=n&&/^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*$/.test(n)?n:void 0;try{if(t==="number"){let c=typeof e=="number"?e:typeof e=="string"&&e.trim()!==""?Number(e):NaN;return Number.isFinite(c)?new Intl.NumberFormat(r).format(c):null}if(typeof e!="string"||!nn.test(e))return null;let s=new Date(e);if(Number.isNaN(s.getTime()))return null;let o=tn.test(e);return new Intl.DateTimeFormat(r,{dateStyle:"long",...t==="datetime"&&!o?{timeStyle:"short"}:{},...o?{timeZone:"UTC"}:{}}).format(s)}catch{return null}}var A="data-mapled-",rn=new Set(["bind","format","width","show","hide","link","list","each","record","slug","slug-param","sort","limit","filter","expand","empty","form","form-state","form-sent","form-failed","consent","end-preview","state","preview","key","api","live","locale"]),Ie=/^[a-z0-9][a-z0-9_-]{0,63}$/,sn=/^mk_[A-Za-z0-9_]{8,128}$/,on=4,an=100,ln=2;function re(e,t=0){if(e===null||typeof e!="object"||Array.isArray(e))return!1;let{data:n,expanded:r}=e;if(n===null||typeof n!="object"||Array.isArray(n))return!1;if(r===void 0)return!0;if(r===null||typeof r!="object"||Array.isArray(r))return!1;let s=Object.values(r);return t>=ln?s.length===0:s.every(o=>o===null||(Array.isArray(o)?o.every(c=>re(c,t+1)):re(o,t+1)))}var un=e=>Array.isArray(e)&&e.every(t=>re(t));function _(e){let t=e.getAttribute("id");return`${e.localName}${t&&/^[\w-]{1,40}$/.test(t)?`#${t}`:""}`}var pe=e=>(e??"").split(",").map(t=>t.trim()).filter(t=>/^[a-z0-9][a-z0-9_.-]{0,127}$/.test(t)),Et=e=>Array.from(e.children).find(t=>t.localName==="template")??null;function Ue(e,t){let n=null,r=()=>n??(n={format:"text",attrs:[],expand:[]});for(let a of Array.from(e.attributes)){if(!a.name.startsWith(A))continue;let f=a.name.slice(A.length);if(f==="bind")r().bind=a.value;else if(f.startsWith("bind-")){let i=f.slice(5);Object.prototype.hasOwnProperty.call(ce,i)?r().attrs.push([i,a.value]):t.push({path:a.value.slice(0,80),reason:"unsupported",on:`${_(e)}[${a.name.slice(0,60)}]`})}else f==="show"?r().show=a.value:f==="hide"?r().hide=a.value:f==="link"?r().link=a.value:rn.has(f)||t.push({path:a.value.slice(0,80),reason:"unsupported",on:`${_(e)}[${a.name.slice(0,60)}]`})}if(!n)return null;let s=n,o=e.getAttribute(`${A}format`);o!==null&&(Rt.includes(o)?s.format=o:t.push({path:o.slice(0,80),reason:"bad-path",on:`${_(e)}[${A}format]`}));let c=parseInt(e.getAttribute(`${A}width`)??"",10);return c>=16&&c<=4096&&(s.width=c),s.expand=pe(e.getAttribute(`${A}expand`)),s}function cn(e,t){let n={},r=e.getAttribute(`${A}sort`);r!==null&&(/^-?[a-z0-9][a-z0-9_-]{0,63}$/.test(r.trim())?n.sort=r.trim():t.push({path:r.slice(0,80),reason:"bad-path",on:`${_(e)}[${A}sort]`}));let s=parseInt(e.getAttribute(`${A}limit`)??"",10);s>=1&&s<=100&&(n.limit=s);let o=e.getAttribute(`${A}filter`);if(o!==null)for(let a of o.split(";")){if(a.trim()==="")continue;let f=a.indexOf("="),i=f===-1?"":a.slice(0,f).trim(),p=f===-1?"":a.slice(f+1).trim();Ie.test(i)&&p!==""&&p.length<=200?(n.filter??(n.filter={}))[i]=p:t.push({path:a.trim().slice(0,80),reason:"bad-path",on:`${_(e)}[${A}filter]`})}let c=pe(e.getAttribute(`${A}expand`));return c.length>0&&(n.expand=c),n}function fe(e,t){let n={bound:[],eaches:[],lists:[],records:[],issues:[]},r=s=>{if(s.hasAttributes()){let o=s.getAttribute(`${A}list`),c=s.getAttribute(`${A}record`),a=s.getAttribute(`${A}each`);if(o!==null||c!==null){let i=(o??c??"").trim();if(!t)n.issues.push({path:i.slice(0,80),reason:"unsupported",on:_(s)});else if(!Ie.test(i))n.issues.push({path:i.slice(0,80),reason:"bad-path",on:_(s)});else if(o!==null)n.lists.push({el:s,collection:i,options:cn(s,n.issues)});else{let p=s.getAttribute(`${A}slug-param`),d=s.getAttribute(`${A}slug`)??(p===null?null:new URLSearchParams(s.ownerDocument.location?.search??"").get(p)),l=fe(s,!0);for(let S of l.records)n.issues.push({path:S.collection,reason:"unsupported",on:_(S.el)});n.lists.push(...l.lists),n.issues.push(...l.issues);let g=Ue(s,n.issues);g&&l.bound.unshift({el:s,d:g}),n.records.push({el:s,collection:i,slug:d!==null&&d.trim()!==""&&d.length<=200?d.trim():null,expand:pe(s.getAttribute(`${A}expand`)),block:{...l,lists:[],records:[],issues:[]}})}return}if(a!==null){n.eaches.push({el:s,path:a});return}let f=Ue(s,n.issues);f&&n.bound.push({el:s,d:f})}for(let o of Array.from(s.children))r(o)};for(let s of Array.from(e.children))r(s);return n}function xt(e){let t=new Map,n=(r,s=[])=>{let o=Z(r)?.[0];if(!o)return;let c=t.get(o)??new Set;for(let a of s)c.add(a);t.set(o,c)};for(let{d:r}of e.bound){n(r.bind,r.expand);for(let[,s]of r.attrs)n(s,r.expand);n(r.show,r.expand),n(r.hide,r.expand);for(let s of(r.link??"").matchAll(/\{([^{}]*)\}/g))n(s[1],r.expand)}for(let r of e.eaches)n(r.path,pe(r.el.getAttribute(`${A}expand`)));return t}function ne(e,t){let n=Z(t);if(!n)return{status:"bad-path"};if(e.kind==="record")return{status:"value",value:Te(e.source,n)};if(n.length<2)return{status:"bad-path"};let r=e.singles.get(n[0]);return!r||r.status!=="ok"?{status:r?.status==="failed"?"failed":"missing"}:{status:"value",value:Te(r.value,n.slice(1))}}function De(e){if(typeof e?.key!="string"||!sn.test(e.key))throw new Error("Mapled: data-mapled-key takes the delivery key (mk_\u2026) \u2014 the one key that is safe in a page. A server key or a secret never goes into HTML.");if(typeof document>"u")throw new Error("Mapled: @mapled/vanilla fills a page \u2014 it runs in a browser. On a server read with @mapled/client.");let t=e.root??document.documentElement,n=t.ownerDocument,r=at({key:e.key,apiUrl:e.apiUrl,appUrl:e.appUrl,fetch:e.fetch,...e.locale?{locale:e.locale}:{}}),s={apiUrl:e.apiUrl,base:n.baseURI},o=new Map,c=u=>{let m=o.get(u);return m||o.set(u,m={attrs:new Map}),m},a=u=>{let m=c(u);m.nodes??(m.nodes=Array.from(u.childNodes))},f=(u,m)=>{let v=c(u);v.attrs.has(m)||v.attrs.set(m,u.getAttribute(m))},i=()=>{for(let[u,m]of o){m.nodes&&u.replaceChildren(...m.nodes);for(let[v,h]of m.attrs)h===null?u.removeAttribute(v):u.setAttribute(v,h)}o.clear()},p=[],d=0,l=(u,m,v)=>p.push({path:(m??"").trim().slice(0,120),reason:v,on:_(u)});function g(u,m,v){if(m.bind!==void 0){let h=ne(v,m.bind);if(h.status!=="value")l(u,m.bind,h.status);else if(!te(u))l(u,m.bind,"refused-element");else{let w=u.localName==="img";if(w?(f(u,"src"),f(u,"srcset"),f(u,"hidden")):a(u),Y(h.value))w?X(u,!1):u.textContent="",l(u,m.bind,"empty");else{let k;if(w)k=St(u,h.value,s,m.width);else if(m.format==="markdown")k=wt(u,h.value,s);else if(m.format==="text")k=Ne(u,h.value);else{let R=Tt(h.value,m.format,u.closest("[lang]")?.getAttribute("lang")??void 0);k=R===null?"type":Ne(u,R)}k?l(u,m.bind,k):d++}}}for(let[h,w]of m.attrs){let k=ne(v,w);if(k.status!=="value"){l(u,w,k.status);continue}if(f(u,h),Y(k.value)){h==="alt"?u.setAttribute("alt",""):u.removeAttribute(h),l(u,w,"empty");continue}let R=u.getAttribute(h),T=At(u,h,k.value,s,m.width);T?(R===null&&u.removeAttribute(h),l(u,w,T)):d++}for(let[h,w]of[[m.show,!0],[m.hide,!1]]){if(h===void 0)continue;let k=ne(v,h);if(k.status!=="value"){l(u,h,k.status);continue}f(u,"hidden");let R=!Y(k.value)&&k.value!==!1;X(u,R===w),d++}if(m.link!==void 0){let h=[],w=ut(m.link,s.base,k=>{let R=ne(v,k.join("."));if(R.status==="value")return R.value;h.push(R.status)});if(h[0])l(u,m.link,h[0]);else if(!w.ok)l(u,w.path,w.reason);else{f(u,"href");let k=vt(u,w.url);k?l(u,m.link,k):d++}}}function S(u,m,v){let h=Et(u);if(!h){l(u,"template","unsupported");return}a(u);let w=[h];for(let R of Array.from(u.children))R.hasAttribute(`${A}empty`)&&(f(R,"hidden"),X(R,m.length===0),w.push(R));let k=[];for(let R of m.slice(0,an)){let T=h.content.cloneNode(!0);x(fe(T,!1),{kind:"record",source:R},v+1),k.push(...Array.from(T.childNodes))}u.replaceChildren(...w,...k),d++}function x(u,m,v){p.push(...u.issues);for(let{el:h,d:w}of u.bound)g(h,w,m);for(let h of u.eaches){let w=ne(m,h.path);if(w.status!=="value"){l(h.el,h.path,w.status);continue}if(v>=on){l(h.el,h.path,"unsupported");continue}let k=w.value,R=Array.isArray(k)?k:Y(k)?[]:[k];if(R.some(T=>T===null||typeof T!="object"||Array.isArray(T))){l(h.el,h.path,"type");continue}R.length===0&&l(h.el,h.path,"empty"),S(h.el,R.map(T=>({data:T})),v)}}async function P(u,m){try{let v=await u();return v===null?{status:"missing"}:m(v)?{status:"ok",value:v}:{status:"failed",answered:!0}}catch(v){return v instanceof W&&v.status===404&&v.code!=="RELEASE_NOT_FOUND"?{status:"missing"}:{status:"failed"}}}let b=null,C="",L=null,$,z=!1,N=0,U=-1,G=3,O=typeof e.live=="number"?e.live:void 0;function Fe(){i(),b={state:"fallback",release:null,preview:!1,bound:0,issues:[]},t.setAttribute(`${A}state`,"fallback"),t.removeAttribute(`${A}preview`)}function _e(){N++,clearTimeout($),b?.preview&&Fe()}function Ot(){clearTimeout($);let u=B();if(!u||z)return;let m=Date.parse(u.expiresAt)-Date.now();$=setTimeout(()=>{B()===null&&_e(),ge()},Math.min(Math.max(m,0)+1,2147483647))}async function je(u,m=1){let v=b===null;v&&t.setAttribute(`${A}state`,"loading");let h=N,w=await r.isPreview().catch(()=>!1),k=w?B()?.draftToken??null:null;if(b!==null&&b.preview&&!w&&Fe(),!w&&u!==void 0&&b!==null&&b.state==="ready"&&!b.preview&&b.release!==null&&u<=b.release)return b;let R=y=>{b=y,U=h,t.setAttribute(`${A}state`,y.state),t.toggleAttribute(`${A}preview`,y.preview);let E=y.issues.filter(F=>F.reason!=="empty"),I=E.map(F=>`${F.path} (${F.reason}) on ${F.on}`).join("; ");return I!==C&&(C=I,E.length>0&&console.warn(`[mapled] ${E.length===1?"1 place":`${E.length} places`} couldn't be filled: ${I}`)),n.dispatchEvent(new CustomEvent(v?"mapled:ready":"mapled:update",{detail:y})),y.preview?Ot():(clearTimeout($),e.live&&L===null&&(L=r.watch(F=>{ge(F.release)},{interval:O,from:y.state==="ready"?y.release:null}))),y},T=null;if(!w)if(u!==void 0)T=u;else try{let y=await r.getRelease();if(y===null)return i(),R({state:"unpublished",release:null,preview:w,bound:0,issues:[]});T=y.release}catch{return b!==null&&b.state==="ready"?b:R({state:"fallback",release:null,preview:w,bound:0,issues:[]})}let D=T===null?{}:{release:T},j=fe(t,!0),We=Ue(t,j.issues);We&&j.bound.unshift({el:t,d:We});let he=new Map,ye=new Map,se=new Map,oe=[];for(let[y,E]of xt(j))oe.push(P(()=>r.getSingle(y,{...D,...E.size>0?{expand:[...E]}:{}}),re).then(I=>he.set(y,I)));for(let y of j.lists){let E=Et(y.el),I=E?[...xt(fe(E.content,!1)).keys()]:[];oe.push(P(async()=>(await r.getRecords(y.collection,{...y.options,...D,...I.length>0?{fields:I}:{}})).records,un).then(F=>ye.set(y,F)))}for(let y of j.records){if(y.slug===null){se.set(y,{status:"missing"});continue}let E=y.slug;oe.push(P(()=>r.getRecordBySlug(y.collection,E,{...D,...y.expand.length>0?{expand:y.expand}:{}}),re).then(I=>se.set(y,I)))}await Promise.all(oe);let Xe=await r.isPreview().catch(()=>!1)?B()?.draftToken??null:null;if(h!==N||Xe!==k)return m<G?je(u,m+1):(i(),R({state:"fallback",release:null,preview:Xe!==null,bound:0,issues:[]}));let Ge=[...he.values(),...ye.values(),...se.values()];if(Ge.length>0&&Ge.every(y=>y.status==="failed"&&!y.answered))return b!==null&&b.state==="ready"?b:R({state:"fallback",release:T,preview:w,bound:0,issues:[]});i(),p=[],d=0,x(j,{kind:"page",singles:he},0);for(let y of j.lists){let E=ye.get(y);E?.status==="ok"?S(y.el,E.value,0):l(y.el,y.collection,E?.status??"failed")}for(let y of j.records){let E=se.get(y);E?.status==="ok"?x(y.block,{kind:"record",source:E.value},0):l(y.el,y.collection,E?.status??"failed")}return He(),R({state:"ready",release:T,preview:w,bound:d,issues:p})}let Ke=new WeakSet,Be=new WeakSet;function He(){for(let u of Array.from(t.querySelectorAll(`form[${A}form]`)))Ke.has(u)||(Ke.add(u),u.addEventListener("submit",m=>{m.preventDefault(),$t(u)}))}async function $t(u){if(u.getAttribute(`${A}form-state`)==="sending")return;let m=(u.getAttribute(`${A}form`)??"").trim(),v=u.querySelector(`[${A}form-sent]`),h=u.querySelector(`[${A}form-failed]`),w=Array.from(u.querySelectorAll("button, input[type=submit]")).filter(D=>!D.disabled);u.setAttribute(`${A}form-state`,"sending");for(let D of w)D.disabled=!0;let k=u.querySelector(`input[type=checkbox][${A}consent]`),R=k?.checked?(k.labels?.[0]?.textContent??k.closest("label")?.textContent??"").trim().slice(0,500):"",T=Ie.test(m)?await ve(m,u,{key:e.key,apiUrl:e.apiUrl,fetch:e.fetch,...R?{consent:R}:{}}):{ok:!1,status:0,code:"BAD_FORM",message:"This form isn't set up yet."};for(let D of w)D.disabled=!1;u.setAttribute(`${A}form-state`,T.ok?"sent":"failed"),T.ok&&u.reset(),v&&X(v,T.ok),h&&(!T.ok&&(Be.has(h)||(h.textContent??"").trim()==="")&&(Be.add(h),h.textContent=T.message),X(h,!T.ok)),n.dispatchEvent(new CustomEvent("mapled:form",{detail:T.ok?{form:m,ok:!0}:{form:m,ok:!1,status:T.status,code:T.code}}))}He();let me=async u=>{try{return await je(u)}catch(m){return console.error(`[mapled] ${m instanceof Error?m.message:"The page couldn't be filled."}`),b??{state:"fallback",release:null,preview:!1,bound:0,issues:[]}}},V=me(),ge=u=>V=V.then(()=>me(u)),qe=()=>{Se(),_e();let u=N;return V=V.then(()=>U>=u&&b!==null?b:me())},ze=u=>{u.target?.closest?.(`[${A}end-preview]`)&&(u.preventDefault(),qe())};return n.addEventListener("click",ze),{ready:V,get report(){return b},refresh:()=>ge(),endPreview:qe,stop:()=>{z=!0,L?.(),L=()=>{},clearTimeout($),n.removeEventListener("click",ze)},client:r}}var Pt="0.2.1";var Mt={version:Pt,mount:De,page:null};window.Mapled=Mt;var q=document.currentScript;if(q instanceof HTMLScriptElement&&q.hasAttribute("data-mapled-key")){let e=q.getAttribute("data-mapled-live"),t=e===null?NaN:parseInt(e,10),n=()=>{try{Mt.page=De({key:q.getAttribute("data-mapled-key")??"",...q.getAttribute("data-mapled-api")?{apiUrl:q.getAttribute("data-mapled-api")}:{},...q.getAttribute("data-mapled-locale")?{locale:q.getAttribute("data-mapled-locale")}:{},...e===null?{}:{live:Number.isFinite(t)?t:!0}})}catch(r){console.error(r instanceof Error?r.message:"Mapled couldn't start.")}};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",n,{once:!0}):n()}})();
|
|
7
|
+
`:"";continue}let l=mt(o);if(l){ue(e,l.text,P(e,`h${l.level}`,n),r),s++;continue}if(Ce(o)){P(e,"hr",n),s++;continue}if(Pe(o)){let p=[];for(;s<t.length&&Pe(t[s]);)p.push(t[s].replace(/^ {0,3}> ?/,"")),s++;$e(e,p,P(e,"blockquote",n),r+1);continue}let f=J(o);if(f){s=Xt(e,t,s,f,n,r);continue}let i=[o.trimStart()];for(s++;s<t.length&&!Ee(t[s])&&!Gt(t[s]);)i.push(t[s].trimStart()),s++;ue(e,i.join(`
|
|
8
|
+
`),P(e,"p",n),r)}}function Xt(e,t,n,r,s,o){let c=P(e,r.ordered?"ol":"ul",s);r.ordered&&r.start!==1&&c.setAttribute("start",String(r.start));let l=[],f=!1;for(;n<t.length;){let i=J(t[n]);if(!i||i.ordered!==r.ordered||i.indent!==r.indent||Ce(t[n]))break;let p=i.indent+i.width,d=[i.rest];n++;let a=!1;for(;n<t.length;){let g=t[n];if(Ee(g)){a=!0,d.push(""),n++;continue}if(Q(g)<p)break;a&&d.some(S=>S!=="")&&!J(g.slice(p))&&(f=!0),a=!1,d.push(g.slice(p)),n++}for(;d.length>0&&d[d.length-1]==="";)d.pop();if(a&&n<t.length){let g=J(t[n]);g&&g.ordered===r.ordered&&g.indent===r.indent&&(f=!0)}l.push({lines:d,el:P(e,"li",c)})}for(let i of l)if($e(e,i.lines,i.el,o+1),!f){for(let p of Array.from(i.el.childNodes))if(p.nodeName==="P"){for(;p.firstChild;)i.el.insertBefore(p.firstChild,p);i.el.removeChild(p)}}return n}var Le=e=>e===void 0||e===" "||e===`
|
|
9
|
+
`,gt=e=>e!==void 0&&/[\p{L}\p{N}]/u.test(e);function ae(e,t,n,r,s=""){let o=Math.min(e.length,r);for(let c=n;c<o;c++){if(e[c]===t)return c;if(s.includes(e[c]))return-1}return-1}function ee(e,t,n){let r=t;for(;e[r]===n;)r++;return r}function ht(e,t){if(e[t]==="\\")return t+2;if(e[t]==="`"){let n=ee(e,t,"`"),r=yt(e,n,n-t);return r===-1?n:r+(n-t)}return-1}function yt(e,t,n){let r=e.indexOf("`",t);for(;r!==-1;){let s=ee(e,r,"`");if(s-r===n)return r;r=e.indexOf("`",s)}return-1}function Vt(e,t,n){let r=n[0],s=t;for(;s<e.length;){let o=ht(e,s);if(o!==-1){s=o;continue}if(e[s]!==r){s++;continue}let c=ee(e,s,r),l=c-s;if((n.length===1?l===1||l>=3:l>=n.length)&&s>t&&!Le(e[s-1])&&(r!=="_"||!gt(e[c])))return c-n.length;s=c}return-1}function Zt(e,t){let n=ae(e,";",t+1,t+34,`
|
|
10
|
+
&`);if(n===-1)return null;let r=e.slice(t+1,n);if(r[0]==="#"){let o=r[1]==="x"||r[1]==="X",c=r.slice(o?2:1);if(!(o?/^[0-9a-fA-F]{1,6}$/:/^[0-9]{1,7}$/).test(c))return null;let l=parseInt(c,o?16:10);return{char:l>0&&l<=1114111&&!(l>=55296&&l<=57343)?String.fromCodePoint(l):"\uFFFD",end:n+1}}let s=Object.prototype.hasOwnProperty.call(ct,r)?ct[r]:void 0;return s===void 0?null:{char:s,end:n+1}}var bt=e=>e.replace(/\\([!-/:-@[-`{-~])/g,"$1");function Yt(e,t){if(e[t]!=="(")return null;let n=Math.min(e.length,t+ft+1024),r=t+1;for(;r<n&&Le(e[r])&&e[r]!==void 0;)r++;let s="";if(e[r]==="<"){let c=ae(e,">",r+1,n,`
|
|
11
|
+
<`);if(c===-1)return null;s=e.slice(r+1,c),r=c+1}else{let c=r,l=0;for(;r<n;){let f=e[r];if(f==="\\"&&r+1<n){r+=2;continue}if(f===" "||f===`
|
|
12
|
+
`)break;if(f==="("&&l++,f===")"){if(l===0)break;l--}r++}s=e.slice(c,r)}for(;r<n&&(e[r]===" "||e[r]===`
|
|
13
|
+
`);)r++;let o=e[r];if(o==='"'||o==="'"||o==="("){let c=ae(e,o==="("?")":o,r+1,n);if(c===-1)return null;for(r=c+1;r<n&&(e[r]===" "||e[r]===`
|
|
14
|
+
`);)r++}return e[r]!==")"?null:{address:bt(s),end:r+1}}function Oe(e,t,n=!1){let r=t+1;for(;r<e.length;){let o=ht(e,r);if(o!==-1){r=o;continue}if(!n&&e[r]==="!"&&e[r+1]==="["){let c=Oe(e,r+1,!0);if(!c)return null;r=c.end;continue}if(e[r]==="[")return null;if(e[r]==="]")break;r++}if(r>=e.length)return null;let s=Yt(e,r+1);return s?{label:e.slice(t+1,r),address:s.address,end:s.end}:null}var Jt=/^(?:[a-z][a-z0-9+.-]{1,31}:[^\s<>]*|[^\s<>@]+@[^\s<>@]+\.[^\s<>@]+)$/i;function ue(e,t,n,r){if(r>=dt){n.appendChild(e.doc.createTextNode(t));return}let s="",o=()=>{s!==""&&n.appendChild(e.doc.createTextNode(s)),s=""},c=new Set,l=0;for(;l<t.length;){let f=t[l];if(f==="\\"){let i=t[l+1];if(i===`
|
|
15
|
+
`)for(o(),P(e,"br",n),l+=2;t[l]===" ";)l++;else i!==void 0&&Wt.includes(i)?(s+=i,l+=2):(s+=f,l++);continue}if(f===`
|
|
16
|
+
`){let i=s.endsWith(" "),p=s.length;for(;p>0&&s[p-1]===" ";)p--;for(s=s.slice(0,p),i?(o(),P(e,"br",n)):s+=`
|
|
17
|
+
`,l++;t[l]===" ";)l++;continue}if(f==="`"){let i=ee(t,l,"`"),p=yt(t,i,i-l);if(p===-1){s+=t.slice(l,i),l=i;continue}let d=t.slice(i,p).replace(/\n/g," ");d.length>1&&d.startsWith(" ")&&d.endsWith(" ")&&d.trim()!==""&&(d=d.slice(1,-1)),o(),P(e,"code",n).textContent=d,l=p+(i-l);continue}if(f==="!"&&t[l+1]==="["){let i=Oe(t,l+1);if(i){let p=bt(i.label),d=H(i.address.trim(),e.base,"media");if(d===null)s+=p;else{o();let a=P(e,"img",n);a.setAttribute("src",d),a.setAttribute("alt",p),a.setAttribute("loading","lazy")}l=i.end;continue}}if(f==="["){let i=Oe(t,l);if(i){let p=H(i.address.trim(),e.base,"link");o();let d=p===null?n:P(e,"a",n);p!==null&&d.setAttribute("href",p),ue(e,i.label,d,r+1),l=i.end;continue}}if(f==="<"){let i=ae(t,">",l+1,l+ft,`
|
|
18
|
+
<`),p=i===-1?null:t.slice(l+1,i);if(p!==null&&Jt.test(p)){let d=H(p.includes(":")?p:`mailto:${p}`,e.base,"link");if(d!==null){o();let a=P(e,"a",n);a.setAttribute("href",d),a.textContent=p,l=i+1;continue}}}if(f==="&"){let i=Zt(t,l);if(i){s+=i.char,l=i.end;continue}}if(f==="*"||f==="_"||f==="~"){let i=ee(t,l,f),p=i-l,d=!Le(t[i])&&(f!=="_"||!gt(t[l-1])),a=f==="~"?p>=2?[["~~",["del"]]]:[]:[...p>=3?[[f.repeat(3),["em","strong"]]]:[],...p>=2?[[f.repeat(2),["strong"]]]:[],[f,["em"]]],g=!1;if(d)for(let[S,E]of a){if(c.has(S))continue;let M=l+S.length,b=Vt(t,M,S);if(b===-1){c.add(S);continue}if(b===M)continue;o();let $=n;for(let L of E)$=P(e,L,$);ue(e,t.slice(M,b),$,r+1),l=b+S.length,g=!0;break}g||(s+=t.slice(l,i),l=i);continue}s+=f,l++}o()}var Qt="http://www.w3.org/1999/xhtml",en=new Set(["script","style","iframe","frame","frameset","object","embed","applet","base","link","meta","template","noscript"]),ce={href:{on:["a","area"],holds:"link"},src:{on:["img","video","audio","source"],holds:"media"},alt:{on:["img","area"],holds:"text"},title:{on:null,holds:"text"},"aria-label":{on:null,holds:"text"},placeholder:{on:["input","textarea"],holds:"text"},datetime:{on:["time","del","ins"],holds:"text"}},de=e=>e.namespaceURI===Qt,te=e=>!en.has(e.localName.toLowerCase());function Ue(e,t){if(!te(e))return"refused-element";let n=xe(t);return n===null?"type":(e.textContent=n,null)}function wt(e,t,n){return!te(e)||!de(e)?"refused-element":typeof t!="string"?"type":(e.replaceChildren(pt(t,e.ownerDocument,n.base)),null)}function kt(e,t,n){return typeof e!="string"?null:at(e)?it(e,{...t.apiUrl?{apiUrl:t.apiUrl}:{},...n?{width:n}:{}}):H(e,t.base,"media")}function St(e,t,n,r){if(!de(e)||e.localName!=="img")return"refused-element";if(typeof t!="string")return"type";let s=kt(t,n,r);return s===null?"unsafe-url":(e.removeAttribute("srcset"),e.setAttribute("src",s),null)}function At(e,t,n,r,s){let o=t.toLowerCase(),c=Object.prototype.hasOwnProperty.call(ce,o)?ce[o]:void 0;if(!c)return"unsupported";if(!te(e)||!de(e))return"refused-element";if(c.on!==null&&!c.on.includes(e.localName))return"unsupported";if(c.holds==="text"){let f=xe(n);return f===null?"type":(e.setAttribute(o,f),null)}if(typeof n!="string")return"type";let l=c.holds==="media"?kt(n,r,e.localName==="img"?s:void 0):H(n,r.base,"link");return l===null?"unsafe-url":(e.setAttribute(o,l),null)}function Rt(e,t){return!de(e)||e.localName!=="a"&&e.localName!=="area"?"unsupported":(e.setAttribute("href",t),null)}function G(e,t){t?e.removeAttribute("hidden"):e.setAttribute("hidden","")}var vt=["text","markdown","date","datetime","number"],tn=/^\d{4}-\d{2}-\d{2}$/,nn=/^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/;function Tt(e,t,n){let r=n&&/^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*$/.test(n)?n:void 0;try{if(t==="number"){let c=typeof e=="number"?e:typeof e=="string"&&e.trim()!==""?Number(e):NaN;return Number.isFinite(c)?new Intl.NumberFormat(r).format(c):null}if(typeof e!="string"||!nn.test(e))return null;let s=new Date(e);if(Number.isNaN(s.getTime()))return null;let o=tn.test(e);return new Intl.DateTimeFormat(r,{dateStyle:"long",...t==="datetime"&&!o?{timeStyle:"short"}:{},...o?{timeZone:"UTC"}:{}}).format(s)}catch{return null}}var A="data-mapled-",rn=new Set(["bind","format","width","show","hide","link","list","each","record","slug","slug-param","sort","limit","filter","expand","empty","form","form-state","form-sent","form-failed","consent","end-preview","state","preview","key","api","live","locale"]),Ie=/^[a-z0-9][a-z0-9_-]{0,63}$/,sn=/^mk_[A-Za-z0-9_]{8,128}$/,on=4,ln=100,an=2;function re(e,t=0){if(e===null||typeof e!="object"||Array.isArray(e))return!1;let{data:n,expanded:r}=e;if(n===null||typeof n!="object"||Array.isArray(n))return!1;if(r===void 0)return!0;if(r===null||typeof r!="object"||Array.isArray(r))return!1;let s=Object.values(r);return t>=an?s.length===0:s.every(o=>o===null||(Array.isArray(o)?o.every(c=>re(c,t+1)):re(o,t+1)))}var un=e=>Array.isArray(e)&&e.every(t=>re(t));function _(e){let t=e.getAttribute("id");return`${e.localName}${t&&/^[\w-]{1,40}$/.test(t)?`#${t}`:""}`}var pe=e=>(e??"").split(",").map(t=>t.trim()).filter(t=>/^[a-z0-9][a-z0-9_.-]{0,127}$/.test(t)),xt=e=>Array.from(e.children).find(t=>t.localName==="template")??null;function Ne(e,t){let n=null,r=()=>n??(n={format:"text",attrs:[],expand:[]});for(let l of Array.from(e.attributes)){if(!l.name.startsWith(A))continue;let f=l.name.slice(A.length);if(f==="bind")r().bind=l.value;else if(f.startsWith("bind-")){let i=f.slice(5);Object.prototype.hasOwnProperty.call(ce,i)?r().attrs.push([i,l.value]):t.push({path:l.value.slice(0,80),reason:"unsupported",on:`${_(e)}[${l.name.slice(0,60)}]`})}else f==="show"?r().show=l.value:f==="hide"?r().hide=l.value:f==="link"?r().link=l.value:rn.has(f)||t.push({path:l.value.slice(0,80),reason:"unsupported",on:`${_(e)}[${l.name.slice(0,60)}]`})}if(!n)return null;let s=n,o=e.getAttribute(`${A}format`);o!==null&&(vt.includes(o)?s.format=o:t.push({path:o.slice(0,80),reason:"bad-path",on:`${_(e)}[${A}format]`}));let c=parseInt(e.getAttribute(`${A}width`)??"",10);return c>=16&&c<=4096&&(s.width=c),s.expand=pe(e.getAttribute(`${A}expand`)),s}function cn(e,t){let n={},r=e.getAttribute(`${A}sort`);r!==null&&(/^-?[a-z0-9][a-z0-9_-]{0,63}$/.test(r.trim())?n.sort=r.trim():t.push({path:r.slice(0,80),reason:"bad-path",on:`${_(e)}[${A}sort]`}));let s=parseInt(e.getAttribute(`${A}limit`)??"",10);s>=1&&s<=100&&(n.limit=s);let o=e.getAttribute(`${A}filter`);if(o!==null)for(let l of o.split(";")){if(l.trim()==="")continue;let f=l.indexOf("="),i=f===-1?"":l.slice(0,f).trim(),p=f===-1?"":l.slice(f+1).trim();Ie.test(i)&&p!==""&&p.length<=200?(n.filter??(n.filter={}))[i]=p:t.push({path:l.trim().slice(0,80),reason:"bad-path",on:`${_(e)}[${A}filter]`})}let c=pe(e.getAttribute(`${A}expand`));return c.length>0&&(n.expand=c),n}function fe(e,t){let n={bound:[],eaches:[],lists:[],records:[],issues:[]},r=s=>{if(s.hasAttributes()){let o=s.getAttribute(`${A}list`),c=s.getAttribute(`${A}record`),l=s.getAttribute(`${A}each`);if(o!==null||c!==null){let i=(o??c??"").trim();if(!t)n.issues.push({path:i.slice(0,80),reason:"unsupported",on:_(s)});else if(!Ie.test(i))n.issues.push({path:i.slice(0,80),reason:"bad-path",on:_(s)});else if(o!==null)n.lists.push({el:s,collection:i,options:cn(s,n.issues)});else{let p=s.getAttribute(`${A}slug-param`),d=s.getAttribute(`${A}slug`)??(p===null?null:new URLSearchParams(s.ownerDocument.location?.search??"").get(p)),a=fe(s,!0);for(let S of a.records)n.issues.push({path:S.collection,reason:"unsupported",on:_(S.el)});n.lists.push(...a.lists),n.issues.push(...a.issues);let g=Ne(s,n.issues);g&&a.bound.unshift({el:s,d:g}),n.records.push({el:s,collection:i,slug:d!==null&&d.trim()!==""&&d.length<=200?d.trim():null,expand:pe(s.getAttribute(`${A}expand`)),block:{...a,lists:[],records:[],issues:[]}})}return}if(l!==null){n.eaches.push({el:s,path:l});return}let f=Ne(s,n.issues);f&&n.bound.push({el:s,d:f})}for(let o of Array.from(s.children))r(o)};for(let s of Array.from(e.children))r(s);return n}function Et(e){let t=new Map,n=(r,s=[])=>{let o=Z(r)?.[0];if(!o)return;let c=t.get(o)??new Set;for(let l of s)c.add(l);t.set(o,c)};for(let{d:r}of e.bound){n(r.bind,r.expand);for(let[,s]of r.attrs)n(s,r.expand);n(r.show,r.expand),n(r.hide,r.expand);for(let s of(r.link??"").matchAll(/\{([^{}]*)\}/g))n(s[1],r.expand)}for(let r of e.eaches)n(r.path,pe(r.el.getAttribute(`${A}expand`)));return t}function ne(e,t){let n=Z(t);if(!n)return{status:"bad-path"};if(e.kind==="record")return{status:"value",value:Te(e.source,n)};if(n.length<2)return{status:"bad-path"};let r=e.singles.get(n[0]);return!r||r.status!=="ok"?{status:r?.status==="failed"?"failed":"missing"}:{status:"value",value:Te(r.value,n.slice(1))}}function Fe(e){if(typeof e?.key!="string"||!sn.test(e.key))throw new Error("Mapled: data-mapled-key takes the delivery key (mk_\u2026) \u2014 the one key that is safe in a page. A server key or a secret never goes into HTML.");if(typeof document>"u")throw new Error("Mapled: @mapled/vanilla fills a page \u2014 it runs in a browser. On a server read with @mapled/client.");let t=e.root??document.documentElement,n=t.ownerDocument,r=lt({key:e.key,apiUrl:e.apiUrl,appUrl:e.appUrl,fetch:e.fetch,...e.locale?{locale:e.locale}:{}}),s={apiUrl:e.apiUrl,base:n.baseURI},o=new Map,c=u=>{let m=o.get(u);return m||o.set(u,m={attrs:new Map}),m},l=u=>{let m=c(u);m.nodes??(m.nodes=Array.from(u.childNodes))},f=(u,m)=>{let R=c(u);R.attrs.has(m)||R.attrs.set(m,u.getAttribute(m))},i=()=>{for(let[u,m]of o){m.nodes&&u.replaceChildren(...m.nodes);for(let[R,h]of m.attrs)h===null?u.removeAttribute(R):u.setAttribute(R,h)}o.clear()},p=[],d=0,a=(u,m,R)=>p.push({path:(m??"").trim().slice(0,120),reason:R,on:_(u)});function g(u,m,R){if(m.bind!==void 0){let h=ne(R,m.bind);if(h.status!=="value")a(u,m.bind,h.status);else if(!te(u))a(u,m.bind,"refused-element");else{let w=u.localName==="img";if(w?(f(u,"src"),f(u,"srcset"),f(u,"hidden")):l(u),Y(h.value))w?G(u,!1):u.textContent="",a(u,m.bind,"empty");else{let k;if(w)k=St(u,h.value,s,m.width);else if(m.format==="markdown")k=wt(u,h.value,s);else if(m.format==="text")k=Ue(u,h.value);else{let v=Tt(h.value,m.format,u.closest("[lang]")?.getAttribute("lang")??void 0);k=v===null?"type":Ue(u,v)}k?a(u,m.bind,k):d++}}}for(let[h,w]of m.attrs){let k=ne(R,w);if(k.status!=="value"){a(u,w,k.status);continue}if(f(u,h),Y(k.value)){h==="alt"?u.setAttribute("alt",""):u.removeAttribute(h),a(u,w,"empty");continue}let v=u.getAttribute(h),T=At(u,h,k.value,s,m.width);T?(v===null&&u.removeAttribute(h),a(u,w,T)):d++}for(let[h,w]of[[m.show,!0],[m.hide,!1]]){if(h===void 0)continue;let k=ne(R,h);if(k.status!=="value"){a(u,h,k.status);continue}f(u,"hidden");let v=!Y(k.value)&&k.value!==!1;G(u,v===w),d++}if(m.link!==void 0){let h=[],w=ut(m.link,s.base,k=>{let v=ne(R,k.join("."));if(v.status==="value")return v.value;h.push(v.status)});if(h[0])a(u,m.link,h[0]);else if(!w.ok)a(u,w.path,w.reason);else{f(u,"href");let k=Rt(u,w.url);k?a(u,m.link,k):d++}}}function S(u,m,R){let h=xt(u);if(!h){a(u,"template","unsupported");return}l(u);let w=[h];for(let v of Array.from(u.children))v.hasAttribute(`${A}empty`)&&(f(v,"hidden"),G(v,m.length===0),w.push(v));let k=[];for(let v of m.slice(0,ln)){let T=h.content.cloneNode(!0);E(fe(T,!1),{kind:"record",source:v},R+1),k.push(...Array.from(T.childNodes))}u.replaceChildren(...w,...k),d++}function E(u,m,R){p.push(...u.issues);for(let{el:h,d:w}of u.bound)g(h,w,m);for(let h of u.eaches){let w=ne(m,h.path);if(w.status!=="value"){a(h.el,h.path,w.status);continue}if(R>=on){a(h.el,h.path,"unsupported");continue}let k=w.value,v=Array.isArray(k)?k:Y(k)?[]:[k];if(v.some(T=>T===null||typeof T!="object"||Array.isArray(T))){a(h.el,h.path,"type");continue}v.length===0&&a(h.el,h.path,"empty"),S(h.el,v.map(T=>({data:T})),R)}}async function M(u,m){try{let R=await u();return R===null?{status:"missing"}:m(R)?{status:"ok",value:R}:{status:"failed",answered:!0}}catch(R){return R instanceof W&&R.status===404&&R.code!=="RELEASE_NOT_FOUND"?{status:"missing"}:{status:"failed"}}}let b=null,$="",L=null,C,z=!1,U=0,N=-1,X=3,O=typeof e.live=="number"?e.live:void 0;function De(){i(),b={state:"fallback",release:null,preview:!1,bound:0,issues:[]},t.setAttribute(`${A}state`,"fallback"),t.removeAttribute(`${A}preview`)}function _e(){U++,clearTimeout(C),b?.preview&&De()}function Ot(){clearTimeout(C);let u=B();if(!u||z)return;let m=Date.parse(u.expiresAt)-Date.now();C=setTimeout(()=>{B()===null&&_e(),ge()},Math.min(Math.max(m,0)+1,2147483647))}async function je(u,m=1){let R=b===null;R&&t.setAttribute(`${A}state`,"loading");let h=U,w=await r.isPreview().catch(()=>!1),k=w?B()?.draftToken??null:null;if(b!==null&&b.preview&&!w&&De(),!w&&u!==void 0&&b!==null&&b.state==="ready"&&!b.preview&&b.release!==null&&u<=b.release)return b;let v=y=>{b=y,N=h,t.setAttribute(`${A}state`,y.state),t.toggleAttribute(`${A}preview`,y.preview);let x=y.issues.filter(D=>D.reason!=="empty"),I=x.map(D=>`${D.path} (${D.reason}) on ${D.on}`).join("; ");return I!==$&&($=I,x.length>0&&console.warn(`[mapled] ${x.length===1?"1 place":`${x.length} places`} couldn't be filled: ${I}`)),n.dispatchEvent(new CustomEvent(R?"mapled:ready":"mapled:update",{detail:y})),y.preview?Ot():(clearTimeout(C),e.live&&L===null&&(L=r.watch(D=>{ge(D.release)},{interval:O,from:y.state==="ready"?y.release:null}))),y},T=null;if(!w)if(u!==void 0)T=u;else try{let y=await r.getRelease();if(y===null)return i(),v({state:"unpublished",release:null,preview:w,bound:0,issues:[]});T=y.release}catch{return b!==null&&b.state==="ready"?b:v({state:"fallback",release:null,preview:w,bound:0,issues:[]})}let F=T===null?{}:{release:T},j=fe(t,!0),We=Ne(t,j.issues);We&&j.bound.unshift({el:t,d:We});let he=new Map,ye=new Map,se=new Map,oe=[];for(let[y,x]of Et(j))oe.push(M(()=>r.getSingle(y,{...F,...x.size>0?{expand:[...x]}:{}}),re).then(I=>he.set(y,I)));for(let y of j.lists){let x=xt(y.el),I=x?[...Et(fe(x.content,!1)).keys()]:[];oe.push(M(async()=>(await r.getRecords(y.collection,{...y.options,...F,...I.length>0?{fields:I}:{}})).records,un).then(D=>ye.set(y,D)))}for(let y of j.records){if(y.slug===null){se.set(y,{status:"missing"});continue}let x=y.slug;oe.push(M(()=>r.getRecordBySlug(y.collection,x,{...F,...y.expand.length>0?{expand:y.expand}:{}}),re).then(I=>se.set(y,I)))}await Promise.all(oe);let Ge=await r.isPreview().catch(()=>!1)?B()?.draftToken??null:null;if(h!==U||Ge!==k)return m<X?je(u,m+1):(i(),v({state:"fallback",release:null,preview:Ge!==null,bound:0,issues:[]}));let Xe=[...he.values(),...ye.values(),...se.values()];if(Xe.length>0&&Xe.every(y=>y.status==="failed"&&!y.answered))return b!==null&&b.state==="ready"?b:v({state:"fallback",release:T,preview:w,bound:0,issues:[]});i(),p=[],d=0,E(j,{kind:"page",singles:he},0);for(let y of j.lists){let x=ye.get(y);x?.status==="ok"?S(y.el,x.value,0):a(y.el,y.collection,x?.status??"failed")}for(let y of j.records){let x=se.get(y);x?.status==="ok"?E(y.block,{kind:"record",source:x.value},0):a(y.el,y.collection,x?.status??"failed")}return He(),v({state:"ready",release:T,preview:w,bound:d,issues:p})}let Ke=new WeakSet,Be=new WeakSet;function He(){for(let u of Array.from(t.querySelectorAll(`form[${A}form]`)))Ke.has(u)||(Ke.add(u),u.addEventListener("submit",m=>{m.preventDefault(),Ct(u)}))}async function Ct(u){if(u.getAttribute(`${A}form-state`)==="sending")return;let m=(u.getAttribute(`${A}form`)??"").trim(),R=u.querySelector(`[${A}form-sent]`),h=u.querySelector(`[${A}form-failed]`),w=Array.from(u.querySelectorAll("button, input[type=submit]")).filter(F=>!F.disabled);u.setAttribute(`${A}form-state`,"sending");for(let F of w)F.disabled=!0;let k=u.querySelector(`input[type=checkbox][${A}consent]`),v=k?.checked?(k.labels?.[0]?.textContent??k.closest("label")?.textContent??"").trim().slice(0,500):"",T=Ie.test(m)?await Re(m,u,{key:e.key,apiUrl:e.apiUrl,fetch:e.fetch,...v?{consent:v}:{}}):{ok:!1,status:0,code:"BAD_FORM",message:"This form isn't set up yet."};for(let F of w)F.disabled=!1;u.setAttribute(`${A}form-state`,T.ok?"sent":"failed"),T.ok&&u.reset(),R&&G(R,T.ok),h&&(!T.ok&&(Be.has(h)||(h.textContent??"").trim()==="")&&(Be.add(h),h.textContent=T.message),G(h,!T.ok)),n.dispatchEvent(new CustomEvent("mapled:form",{detail:T.ok?{form:m,ok:!0}:{form:m,ok:!1,status:T.status,code:T.code}}))}He();let me=async u=>{try{return await je(u)}catch(m){return console.error(`[mapled] ${m instanceof Error?m.message:"The page couldn't be filled."}`),b??{state:"fallback",release:null,preview:!1,bound:0,issues:[]}}},V=me(),ge=u=>V=V.then(()=>me(u)),qe=()=>{Se(),_e();let u=U;return V=V.then(()=>N>=u&&b!==null?b:me())},ze=u=>{u.target?.closest?.(`[${A}end-preview]`)&&(u.preventDefault(),qe())};return n.addEventListener("click",ze),{ready:V,get report(){return b},refresh:()=>ge(),endPreview:qe,stop:()=>{z=!0,L?.(),L=()=>{},clearTimeout(C),n.removeEventListener("click",ze)},client:r}}var Mt="0.2.2";var Pt={version:Mt,mount:Fe,page:null};window.Mapled=Pt;var q=document.currentScript;if(q instanceof HTMLScriptElement&&q.hasAttribute("data-mapled-key")){let e=q.getAttribute("data-mapled-live"),t=e===null?NaN:parseInt(e,10),n=()=>{try{Pt.page=Fe({key:q.getAttribute("data-mapled-key")??"",...q.getAttribute("data-mapled-api")?{apiUrl:q.getAttribute("data-mapled-api")}:{},...q.getAttribute("data-mapled-locale")?{locale:q.getAttribute("data-mapled-locale")}:{},...e===null?{}:{live:Number.isFinite(t)?t:!0}})}catch(r){console.error(r instanceof Error?r.message:"Mapled couldn't start.")}};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",n,{once:!0}):n()}})();
|
package/dist/mapled.js.sha384
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
sha384-
|
|
1
|
+
sha384-lfhwQoPUtrbLcD2HXSLr2o1z+aUAjotB62i3LFMGxzBlK5lfCQPQPLOoWL+1DBMc
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapled/vanilla",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "The browser runtime of Mapled, the hosted headless CMS for sites built with AI — published content in a plain HTML site: one script tag and data-mapled attributes, no framework and no build step.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://mapled.io",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@mapled/client": "^0.
|
|
44
|
+
"@mapled/client": "^0.3.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"esbuild": "^0.28.2",
|