@panphora/hyper-cms 0.6.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- var hypercms=(()=>{var bt=Object.defineProperty;var vn=Object.getOwnPropertyDescriptor;var xn=Object.getOwnPropertyNames;var wn=Object.prototype.hasOwnProperty;var kt=(e,t)=>{for(var r in t)bt(e,r,{get:t[r],enumerable:!0})},_n=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of xn(t))!wn.call(e,i)&&i!==r&&bt(e,i,{get:()=>t[i],enumerable:!(n=vn(t,i))||n.enumerable});return e};var An=e=>_n(bt({},"__esModule",{value:!0}),e);var Ko={};kt(Ko,{cms:()=>Vo,default:()=>Wo});var nr={includeClasses:!0,includeAttributes:["href","src","name","type","role","aria-label","alt","title"],excludeAttributePrefixes:["data-morph-","data-hyper-","data-im-"],textHintLength:64,excludeIds:!0,maxPathDepth:4,landmarks:["HEADER","NAV","MAIN","ASIDE","FOOTER","SECTION","ARTICLE"],weights:{signature:100,pathSegment:10,textMatch:20,textMismatch:25,uniqueCandidate:50,positionPenalty:1,maxDriftPenalty:19,slotMatch:30},minConfidence:101,maxScoredCandidates:16};function En(e){let t=5381;for(let r=0;r<e.length;r++)t=(t<<5)+t^e.charCodeAt(r);return Math.abs(t).toString(36)}function Cn(e){if(e.classList&&e.classList.length>0)return Array.from(e.classList).sort().join(" ");let t=e.getAttribute?.("class");return t?t.split(/\s+/).filter(Boolean).sort().join(" "):""}function Rn(e,t){let r=[];for(let n of e.attributes||[]){let i=n.name;i==="id"||i==="class"||t.excludeAttributePrefixes.some(o=>i.startsWith(o))||t.includeAttributes.includes(i)&&r.push(`${i}=${n.value}`)}return r.sort().join("|")}function Tn(e,t){return(e.textContent||"").replace(/\s+/g," ").trim().slice(0,t.textHintLength)}function On(e,t){let r=[e.tagName];return t.includeClasses&&r.push(Cn(e)),r.push(Rn(e,t)),En(r.join("|"))}function Mn(e){let t=e.tagName,r=1,n=e.previousElementSibling;for(;n;)n.tagName===t&&r++,n=n.previousElementSibling;return r}function Nn(e,t){return e.getAttribute?.("id")||e.getAttribute?.("role")?!0:t.landmarks.includes(e.tagName)}function In(e){let t=e.getAttribute?.("id");if(t)return`#${t}`;let r=e.getAttribute?.("role");return r?`@${r}`:e.tagName}function Ln(e,t){let r=[],n=e;for(;n&&n.tagName&&r.length<t.maxPathDepth;){let i=`${n.tagName}:${Mn(n)}`;if(r.unshift(i),n!==e&&Nn(n,t)){r.unshift(In(n));break}n=n.parentElement}return r}function jn(e,t){let r=0,n=e.length-1,i=t.length-1;for(;n>=0&&i>=0&&e[n]===t[i];)r++,n--,i--;return r}function J(e,t,r){if(r.has(e))return r.get(e);let n={signature:On(e,t),path:Ln(e,t),textHint:Tn(e,t)};return r.set(e,n),n}function ar(e,t,r,n){if(n.has(e))return n.get(e);let i=new Map,o=e.querySelectorAll("*"),a=0;for(let s of o){let l=J(s,t,r);l.domIndex=a++,!t.shouldIgnore?.(s)&&(i.has(l.signature)||i.set(l.signature,[]),i.get(l.signature).push(s))}return n.set(e,i),i}function Fn(e,t,r){r.delete(e),t.delete(e);let n=e.querySelectorAll("*");for(let i of n)t.delete(i)}function yt(e,t,r,n,i){let o=J(e,r,n),a=J(t,r,n),s=r.weights,l={},c=0;if(o.signature!==a.signature)return{score:0,breakdown:{rejected:"signature mismatch"}};c+=s.signature,l.signature=s.signature;let d=jn(o.path,a.path)*s.pathSegment;c+=d,l.path=d;let h=!0;if(o.textHint&&a.textHint?o.textHint===a.textHint?(c+=s.textMatch,l.text=s.textMatch):(c-=s.textMismatch,l.text=-s.textMismatch,h=!1):o.textHint!==a.textHint&&(c-=s.textMismatch,l.text=-s.textMismatch,h=!1),i.candidateCount===1&&h&&(c+=s.uniqueCandidate,l.unique=s.uniqueCandidate),typeof o.domIndex=="number"&&typeof a.domIndex=="number"){let f=Math.abs(o.domIndex-a.domIndex),k=Math.min(f*s.positionPenalty,s.maxDriftPenalty);c-=k,l.drift=-k}return{score:c,breakdown:l}}function ir(e,t,r,n,i){if(r.excludeIds&&e.getAttribute("id"))return null;let o=ar(t,r,n,i),a=J(e,r,n);if(typeof a.domIndex!="number"){let h=0,f=e.previousElementSibling;for(;f;)h++,f=f.previousElementSibling;a.domIndex=h}let s=o.get(a.signature)||[],l=r.excludeIds?s.filter(h=>!h.getAttribute("id")):s;if(l.length===0)return null;let c=null,m=0,d=null;for(let h of l){let{score:f,breakdown:k}=yt(e,h,r,n,{candidateCount:l.length});f>m&&(m=f,c=h,d=k)}return m<r.minConfidence?null:{element:c,confidence:m,breakdown:d}}function qn(e,t,r,n){let i=[],o=r.weights.signature+r.weights.slotMatch,a={slot:o};function s(d){if(d.children)return d.children;let h=d.childNodes;if(!h)return[];let f=[];for(let k=0;k<h.length;k++)h[k].nodeType===1&&f.push(h[k]);return f}function l(d,h){let f=s(d),k=s(h);if(f.length===k.length)for(let C=0;C<f.length;C++){let N=f[C],D=k[C];if(r.shouldIgnore?.(N)||r.shouldIgnore?.(D)||r.excludeIds&&(N.getAttribute("id")||D.getAttribute("id"))||N.tagName!==D.tagName)continue;let K=J(N,r,n).signature,F=J(D,r,n).signature;K!==F&&i.push({newEl:N,oldEl:D,score:o,breakdown:a}),l(N,D)}}function c(d,h){for(;;){if(d.tagName===h.tagName)return[d,h];let f=s(d);if(!d.tagName&&f.length===1){d=f[0];continue}let k=s(h);if(k.length===1&&k[0].tagName===d.tagName){h=k[0];continue}return null}}let m=c(e,t);return m&&l(m[0],m[1]),i}function or(e,t,r,n,i){let o=t.querySelectorAll("*"),a=ar(e,r,n,i),s=0;for(let f of o){let k=J(f,r,n);k.domIndex=s++}let l=[],c=new Map;function m(f,k,C){let N=new Set;if(f.textHint){let L=c.get(f.signature);if(!L){L=new Map;for(let X of k){let pe=J(X,r,n).textHint,le=L.get(pe);le||(le=[],L.set(pe,le)),le.push(X)}c.set(f.signature,L)}let V=L.get(f.textHint);if(V)for(let X=0;X<V.length&&X<C;X++)N.add(V[X])}let D=0,K=k.length;for(;D<K;){let L=D+K>>1;J(k[L],r,n).domIndex<f.domIndex?D=L+1:K=L}let F=Math.max(0,Math.min(D-(C>>1),k.length-C)),z=Math.min(F+C,k.length);for(let L=F;L<z;L++)N.add(k[L]);return[...N]}for(let f of o){if(r.shouldIgnore?.(f)||r.excludeIds&&f.getAttribute("id"))continue;let k=J(f,r,n),C=a.get(k.signature)||[],N=r.excludeIds?C.filter(F=>!F.getAttribute("id")):C,D=r.maxScoredCandidates,K=D&&N.length>D?m(k,N,D):N;for(let F of K){let{score:z,breakdown:L}=yt(f,F,r,n,{candidateCount:N.length});z>=r.minConfidence&&l.push({newEl:f,oldEl:F,score:z,breakdown:L})}}if(r.weights.slotMatch>0){let f=qn(t,e,r,n);for(let k of f)l.push(k)}l.sort((f,k)=>k.score-f.score);let d=new Map,h=new Set;for(let{newEl:f,oldEl:k}of l)d.has(f)||h.has(k)||(d.set(f,k),h.add(k));return d}function sr(e,t,r,n){let i=J(e,r,n),o=J(t,r,n),{score:a,breakdown:s}=yt(e,t,r,n,{candidateCount:1});return{matches:a>=r.minConfidence,score:a,breakdown:s,newMeta:{signature:i.signature,path:i.path,textHint:i.textHint},oldMeta:{signature:o.signature,path:o.path,textHint:o.textHint}}}function lr(e={}){let t={...nr,...e,weights:{...nr.weights,...e.weights}},r=new WeakMap,n=new WeakMap;return{findMatch:(i,o)=>ir(i,o,t,r,n),computeMatches:(i,o)=>or(i,o,t,r,n),explain:(i,o)=>sr(i,o,t,r),invalidate:i=>Fn(i,r,n),session:()=>{let i=new WeakMap,o=new WeakMap;return{findMatch:(a,s)=>ir(a,s,t,i,o),computeMatches:(a,s)=>or(a,s,t,i,o),explain:(a,s)=>sr(a,s,t,i)}},getConfig:()=>({...t})}}function vt(e,t){for(;;){for(;t<e.length&&/\s/.test(e[t]);)t++;if(e[t]==="/"&&e[t+1]==="/"){for(;t<e.length&&e[t]!==`
2
- `;)t++;continue}if(e[t]==="/"&&e[t+1]==="*"){let r=e.indexOf("*/",t+2);if(r===-1)return e.length;t=r+2;continue}return t}}function cr(e){return e.replace(/\\'/g,"'").replace(/(\\*)"/g,(t,r)=>r.length%2===0?r+'\\"':t)}var Dn=/^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/,$n=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function He(e){try{return JSON.parse(e)}catch{return JSON.parse(Bn(e))}}function Bn(e){let t="",r=0,n=(i,o)=>{throw new Error(`Invalid relaxed JSON: ${i} at position ${o}`)};for(;r<e.length&&(r=vt(e,r),!(r>=e.length));){let i=e[r];if("{}[]:".includes(i)){t+=i,r++;continue}if(i===","){let s=vt(e,r+1);if(e[s]==="}"||e[s]==="]"){r++;continue}t+=i,r++;continue}if(i==='"'||i==="'"){let s=r+1;for(;s<e.length&&e[s]!==i;)e[s]==="\\"&&s++,s++;s>=e.length&&n("unterminated string",r);let l=e.slice(r+1,s);i==="'"&&(l=cr(l)),t+='"'+l+'"',r=s+1;continue}let o=r;for(;o<e.length&&/[A-Za-z0-9_$.+\-]/.test(e[o]);)o++;o===r&&n("unexpected character "+JSON.stringify(i),r);let a=e.slice(r,o);if(a==="true"||a==="false"||a==="null"||Dn.test(a)){t+=a,r=o;continue}if($n.test(a)){if(e[vt(e,o)]===":"){t+='"'+a+'"',r=o;continue}n("unquoted value "+JSON.stringify(a),r)}n("invalid token "+JSON.stringify(a),r)}return t}function dr(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function r(i){let o=[],a=0;for(;a<i.length;){let s=i[a];if(/\s/.test(s)){a++;continue}if("{}".includes(s)){o.push({type:s,value:s}),a++;continue}if(s==="["){let d=!1,h=a+1;for(;h<i.length&&/\s/.test(i[h]);)h++;if(h<i.length&&/[a-zA-Z_]/.test(i[h])&&(d=!0),!d){o.push({type:s,value:s}),a++;continue}}if(s==="]"){o.push({type:s,value:s}),a++;continue}if(s===":"){o.push({type:t.COLON,value:s}),a++;continue}if(s===","){o.push({type:t.COMMA,value:s}),a++;continue}if(s==='"'||s==="'"){let d=s,h=a+1;for(;h<i.length&&i[h]!==d;)i[h]==="\\"&&h++,h++;o.push({type:t.STRING,value:i.substring(a+1,h),quoted:!0,sourceQuote:d}),a=h+1;continue}let l=a,c;for(;l<i.length&&!/[{},]/.test(i[l]);)if(i[l]===":"){let d=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],h=!1;for(let f of d){let k=f.substring(1);if(i.substring(l+1,l+1+k.length)===k){h=!0,l+=k.length;break}}if(!h)break}else if(i[l]==="["){for(l++;l<i.length&&i[l]!=="]";){if(i[l]==='"'||i[l]==="'"){let d=i[l];for(l++;l<i.length&&i[l]!==d;)i[l]==="\\"&&l++,l++}l++}l<i.length&&i[l]==="]"&&l++}else l++;c=i.substring(a,l);let m=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(c)?m=t.NUMBER:c==="true"||c==="false"||c==="null"?m=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(c)&&(m=t.SELECTOR),o.push({type:m,value:c,quoted:!1}),a=l}return o}function n(i){let o="";for(let a=0;a<i.length;a++){let s=i[a];if("{}".includes(s.type)||"[]".includes(s.type)){o+=s.value;continue}if(s.type===t.COLON){o+=s.value;continue}if(s.type===t.COMMA){let l=i[a+1];if(l&&(l.type==="}"||l.type==="]"))continue;o+=s.value;continue}if(s.type===t.STRING){let l=s.value;s.sourceQuote==="'"&&(l=cr(l)),o+=`"${l}"`;continue}if(s.type===t.NUMBER||s.type===t.BOOLEAN){o+=s.value;continue}o+=`"${s.value}"`}return o}try{let i=r(e),o=n(i);return JSON.parse(o)}catch(i){throw new Error("Invalid extraction rules syntax: "+i.message)}}var B=Symbol("hyper-morph-json-merge:missing"),mr=["id","_id","uuid","key","slug","code","name"];function ge(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Oe(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function zn(e,t,r){Object.defineProperty(e,t,{value:r,enumerable:!0,writable:!0,configurable:!0})}function ie(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!ie(e[r],t[r]))return!1;return!0}if(ge(e)&&ge(t)){let r=Object.keys(e);if(r.length!==Object.keys(t).length)return!1;for(let n of r)if(!Oe(t,n)||!ie(e[n],t[n]))return!1;return!0}return!1}function ur(e,t,r,n){return ie(t,r)?t:ie(t,e)?r:ie(r,e)?t:ge(t)&&ge(r)?Pn(ge(e)?e:{},t,r,n):Array.isArray(t)&&Array.isArray(r)?Wn(Array.isArray(e)?e:[],t,r,n):r}function hr(e,t,r,n){return t===B&&r===B?B:t===B?e===B?r:ie(r,e)?B:r:r===B?e===B?t:B:ur(e,t,r,n)}function Pn(e,t,r,n){let i={},o=new Set([...Object.keys(e),...Object.keys(t),...Object.keys(r)]);for(let a of o){let s=hr(Oe(e,a)?e[a]:B,Oe(t,a)?t[a]:B,Oe(r,a)?r[a]:B,n);s!==B&&zn(i,a,s)}return i}function Un(e){return e===null||typeof e!="object"}function Ve(e){return typeof e+":"+String(e)}function Hn(e,t){for(let r of t){let n=new Set;for(let i of r){if(!Oe(i,e))return!1;let o=i[e];if(typeof o!="string"&&typeof o!="number")return!1;let a=Ve(o);if(n.has(a))return!1;n.add(a)}}return!0}function Vn(e,t,r,n){let i=[e,t,r],o=!0;for(let a of i)for(let s of a)ge(s)||(o=!1);if(o){for(let a of n.keyCandidates)if(Hn(a,i))return{kind:"keyed",field:a};return null}for(let a of i){let s=new Set;for(let l of a){if(!Un(l))return null;let c=Ve(l);if(s.has(c))return null;s.add(c)}}return{kind:"self"}}function Wn(e,t,r,n){let i=Vn(e,t,r,n);if(!i)return r;let o=i.kind==="self"?Ve:f=>Ve(f[i.field]),a=f=>{let k=new Map;for(let C of f)k.set(o(C),C);return k},s=a(e),l=a(t),c=a(r),m=new Map,d=new Set([...s.keys(),...l.keys(),...c.keys()]);for(let f of d){let k=hr(s.has(f)?s.get(f):B,l.has(f)?l.get(f):B,c.has(f)?c.get(f):B,n);k!==B&&m.set(f,k)}let h=[];for(let f of r){let k=o(f);m.has(k)&&h.push(k)}for(let f=0;f<t.length;f++){let k=o(t[f]);if(!m.has(k)||h.includes(k))continue;let C=0;for(let N=f-1;N>=0;N--){let D=h.indexOf(o(t[N]));if(D!==-1){C=D+1;break}}h.splice(C,0,k)}return h.map(f=>m.get(f))}function xt(e,t,r,n={}){let i=n.keyCandidates?[...n.keyCandidates,...mr]:mr;return ur(e===void 0?B:e,t,r,{keyCandidates:i})}function wt(e,t,r,n={}){let i=n.parse||He,o=[],a=(d,h)=>{if(typeof d!="string")return B;try{return i(d)}catch(f){return o.push(`${h} side is not valid JSON (${f.message})`),B}},s=a(t,"local"),l=a(r,"remote");if(s===B)return{text:r,warnings:o};if(l===B)return{text:t,warnings:o};let c=a(e,"base"),m=xt(c===B?void 0:c,s,l,n);return ie(m,l)?{text:r,warnings:o}:ie(m,s)?{text:t,warnings:o}:{text:JSON.stringify(m,null,2),warnings:o}}var _t=(function(){"use strict";let e=()=>{},t='[save-ignore],[snapshot-remove],[no-snapshot],[no-save],[save-remove],[freeze],[save-freeze],[clay~="no-save"],[clay~="no-snapshot"],[clay~="freeze"]';function r(v){if(!(v instanceof Element))return!1;if(v.matches(t))return!0;if(v.tagName==="LINK"||v.tagName==="SCRIPT"){let E=v.getAttribute("src")||v.getAttribute("href")||"";if(E.startsWith("chrome-extension://")||E.startsWith("moz-extension://")||E.startsWith("safari-web-extension://"))return!0}return!1}function n(v){return v instanceof Element?v.closest(t)?!0:r(v):!1}let i=lr({shouldIgnore:n});function o(v,E,S){if(S){let M=S.identityOf(v);if(M&&!S.disabled.has(M.key))return"hm-merge:"+M.key}if(E!=="smart")return v.outerHTML;let O=v.getAttribute("src"),R=v.getAttribute("type")||"text/javascript";if(O)try{let M=new URL(O,window.location.href);return`ext:${R}:${M.origin}${M.pathname}${M.search}`}catch{return`ext:${R}:${O}`}else{let M=v.textContent.trim(),y=5381;for(let A=0;A<M.length;A++)y=(y<<5)+y^M.charCodeAt(A);return`inline:${R}:${Math.abs(y).toString(36)}`}}let a="http://www.w3.org/1999/xhtml";function s(v){return v instanceof Element&&v.tagName==="SCRIPT"&&v.namespaceURI===a}function l(v){let E=document.createElement("div");E.innerHTML="<script><\/script>";let S=E.firstChild;for(let O of v.attributes)S.setAttribute(O.name,O.value);return S.textContent=v.textContent,S}function c(v){if(s(v))return l(v);if(v instanceof Element)for(let E of v.querySelectorAll("script"))s(E)&&E.replaceWith(l(E));return v}function m(v){let E=(v.getAttribute("type")||"").split(";")[0].trim().toLowerCase();return E==="application/json"||E.endsWith("+json")}let d={match:v=>v.hasAttribute("merge"),identity:v=>v.getAttribute("merge")};function h(v,E,S){if(S.merge===!1)return null;let O=[d,...S.mergeTags||[]],R=new WeakMap,M=g=>{if(R.has(g))return R.get(g);let w=null;if(s(g)&&!g.getAttribute("src")&&!n(g)){let _=g;for(let T=0;T<O.length;T++)if(O[T].match(_)){if(!m(_))console.warn("[hyper-morph] merge ignored: script type is not JSON",_);else{let j=O[T].identity(_);j!=null&&j!==""&&(w={key:T+":"+j,raw:j,recognizer:O[T]})}break}}return R.set(g,w),w},y=new Set,A=g=>{let w=new Map,_=T=>{let j=M(T);j&&(w.has(j.key)?(y.add(j.key),console.warn(`[hyper-morph] merge disabled for duplicate identity "${j.raw}"`)):w.set(j.key,T))};s(g)&&_(g);for(let T of g.querySelectorAll("script"))_(T);return w},b=A(v),p=A(E.__hyperMorphRoot||E);if(b.size===0&&p.size===0)return null;let u=null;return{identityOf:M,disabled:y,oldByKey:b,newByKey:p,baseTexts:()=>{if(u)return u;u=new Map;let g=S.mergeBase;if(!g)return u;let w;typeof g=="string"?w=new DOMParser().parseFromString(g,"text/html").documentElement:g instanceof Document?w=g.documentElement:w=g;let _=T=>{let j=M(T);j&&!u.has(j.key)&&u.set(j.key,T.textContent)};s(w)&&_(w);for(let T of w.querySelectorAll("script"))_(T);return u}}}function f(v,E,S){let O=v.merge;if(!O)return!1;let R=O.identityOf(E);if(!R||O.disabled.has(R.key))return!1;let M=O.identityOf(S);if(!M||M.key!==R.key)return!1;let y=E,A=S,b=A.getAttribute("merge-key")||y.getAttribute("merge-key"),{text:p,warnings:u}=wt(O.baseTexts().get(R.key),y.textContent,A.textContent,{parse:R.recognizer.parse,keyCandidates:b?b.split(/[\s,]+/).filter(Boolean):void 0});for(let x of u)console.warn(`[hyper-morph] merge "${R.raw}": ${x}`);return y.textContent!==p&&(y.textContent=p),!0}let k={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:e,afterNodeAdded:e,beforeNodeMorphed:e,afterNodeMorphed:e,beforeNodeRemoved:e,afterNodeRemoved:e,beforeAttributeUpdated:e},head:{style:"merge",shouldPreserve:v=>v.getAttribute("im-preserve")==="true",shouldReAppend:v=>v.getAttribute("im-re-append")==="true",shouldRemove:e,afterHeadMorphed:e},scripts:{handle:!0,matchMode:"outerHTML",shouldPreserve:v=>v.getAttribute("im-preserve")==="true",shouldReAppend:v=>v.getAttribute("im-re-append")==="true",shouldRemove:e,afterScriptsHandled:e},restoreFocus:!0},C={computeMatches(v,E){let{computeMatches:S}=i.session();return S(v,E)}};function N(v,E,S={}){v=yn(v);let O=Xt(E),R=kn(v,O,S),M=R.scripts.handle?new Set(Array.from(v.querySelectorAll("script")).map(p=>o(p,R.scripts.matchMode,R.merge))):null,y=F(R),A=X(R,v,O,p=>p.morphStyle==="innerHTML"?(L(p,v,O),Array.from(v.childNodes)):K(p,v,O)),b=p=>{y&&z(R,y),D(R);let u=M?bn(p,M,R):[];return u.length>0?Promise.all(u).then(()=>p):p};return A instanceof Promise?A.then(b):b(A)}function D(v){for(let E of Array.from(v.pantry.childNodes))v.callbacks.beforeNodeRemoved(E)!==!1&&v.callbacks.afterNodeRemoved(E);v.pantry.remove()}function K(v,E,S){let O=Xt(E);return L(v,O,S,E,E.nextSibling),Array.from(O.childNodes)}function F(v){if(!v.config.restoreFocus)return null;let E=document.activeElement;if(!(E instanceof HTMLInputElement||E instanceof HTMLTextAreaElement))return null;let{id:S,selectionStart:O,selectionEnd:R}=E;return{element:E,id:S,selectionStart:O,selectionEnd:R}}function z(v,E){let S=E.element;if(E.id&&E.id!==document.activeElement?.getAttribute("id")&&(S=v.target.querySelector(`[id="${CSS.escape(E.id)}"]`),S?.focus()),S&&!S.selectionEnd&&E.selectionEnd!=null)try{S.setSelectionRange(E.selectionStart,E.selectionEnd)}catch{}}let L=(function(){function v(p,u,x,g=null,w=null){u instanceof HTMLTemplateElement&&x instanceof HTMLTemplateElement&&(u=u.content,x=x.content),g||=u.firstChild;for(let _ of x.childNodes){if(r(_))continue;if(g&&g!=w){let j=S(p,_,g,w);if(j){j!==g&&R(p,g,j),V(j,_,p),g=j.nextSibling;continue}}if(_ instanceof Element){let j=_.getAttribute("id");if(p.persistentIds.has(j)){let $=M(u,j,g,p);V($,_,p),g=$.nextSibling;continue}if(!p.idMap.has(_)){let $=p.hyperMatches.get(_);if($&&!p.idMap.has($)&&!b($,u)){A(u,$,g),V($,_,p),g=$.nextSibling;continue}}}let T=E(u,_,g,p);T&&(g=T.nextSibling)}for(;g&&g!=w;){let _=g;g=g.nextSibling,r(_)||O(p,_)}}function E(p,u,x,g){if(g.callbacks.beforeNodeAdded(u)===!1)return null;if(g.idMap.has(u)){let w=u,_=document.createElementNS(w.namespaceURI,w.localName);return p.insertBefore(_,x),V(_,u,g),g.callbacks.afterNodeAdded(_),_}else{let w=c(document.importNode(u,!0));return p.insertBefore(w,x),g.callbacks.afterNodeAdded(w),w}}let S=(function(){function p(g,w,_,T){let j=w instanceof Element&&!g.idMap.has(w)?g.hyperMatches.get(w):null,$=null,H=w.nextSibling,Q=0,q=_;for(;q&&q!=T;){if(r(q)){q=q.nextSibling;continue}if(x(q,w)){if(u(g,q,w)||q===j&&!g.idMap.has(q))return q;if($===null){let G=q instanceof Element&&g.hyperMatchedOldElements.has(q);!g.idMap.has(q)&&!G&&($=q)}}if($===null&&H&&x(q,H)&&(Q++,H=H.nextSibling,Q>=2&&($=void 0)),g.activeElementAndParents.includes(q))break;q=q.nextSibling}return $||null}function u(g,w,_){let T=g.idMap.get(w),j=g.idMap.get(_);if(!j||!T)return!1;for(let $ of T)if(j.has($))return!0;return!1}function x(g,w){let _=g,T=w;return _.nodeType===T.nodeType&&_.tagName===T.tagName&&(!_.getAttribute?.("id")||_.getAttribute?.("id")===T.getAttribute?.("id"))}return p})();function O(p,u){let x=u instanceof Element&&p.hyperMatchedOldElements.has(u)&&!p.idMap.has(u);if(p.idMap.has(u)||x)A(p.pantry,u,null);else{if(p.callbacks.beforeNodeRemoved(u)===!1)return;u.parentNode?.removeChild(u),p.callbacks.afterNodeRemoved(u)}}function R(p,u,x){let g=u;for(;g&&g!==x;){let w=g;g=g.nextSibling,r(w)||O(p,w)}return g}function M(p,u,x,g){let w=g.target.getAttribute?.("id")===u&&g.target||g.target.querySelector(`[id="${CSS.escape(u)}"]`)||g.pantry.querySelector(`[id="${CSS.escape(u)}"]`);return y(w,g),A(p,w,x),w}function y(p,u){let x=p.getAttribute("id");for(;p=p.parentNode;){let g=u.idMap.get(p);g&&(g.delete(x),g.size||u.idMap.delete(p))}}function A(p,u,x){if(p.moveBefore)try{p.moveBefore(u,x)}catch{p.insertBefore(u,x)}else p.insertBefore(u,x)}function b(p,u){let x=u instanceof Element?u:u.realParentNode;return!!x&&p.contains(x)}return v})(),V=(function(){function v(y,A,b){return b.ignoreActive&&y===document.activeElement?null:(b.callbacks.beforeNodeMorphed(y,A)===!1||(y instanceof HTMLHeadElement&&b.head.ignore||(y instanceof HTMLHeadElement&&b.head.style!=="morph"?le(y,A,b):(E(y,A,b),f(b,y,A)||M(y,b)||L(b,y,A))),b.callbacks.afterNodeMorphed(y,A)),y)}function E(y,A,b){let p=A.nodeType;if(p===1){let u=y,x=A,g=u.attributes,w=x.attributes;for(let _ of w)R(_.name,u,"update",b)||u.getAttribute(_.name)!==_.value&&u.setAttribute(_.name,_.value);for(let _=g.length-1;0<=_;_--){let T=g[_];if(T&&!x.hasAttribute(T.name)){if(R(T.name,u,"remove",b))continue;u.removeAttribute(T.name)}}M(u,b)||S(u,x,b)}(p===8||p===3)&&y.nodeValue!==A.nodeValue&&(y.nodeValue=A.nodeValue)}function S(y,A,b){if(y instanceof HTMLInputElement&&A instanceof HTMLInputElement&&A.type!=="file"){let p=A.value,u=y.value;O(y,A,"checked",b),O(y,A,"disabled",b),b.formStateSync==="property"&&y.indeterminate!==A.indeterminate&&(y.indeterminate=A.indeterminate),b.formStateSync==="property"?u!==p&&(R("value",y,"update",b)||(y.value=p)):A.hasAttribute("value")?u!==p&&(R("value",y,"update",b)||(y.setAttribute("value",p),y.value=p)):R("value",y,"remove",b)||(y.value="",y.removeAttribute("value"))}else if(y instanceof HTMLOptionElement&&A instanceof HTMLOptionElement)O(y,A,"selected",b);else if(y instanceof HTMLTextAreaElement&&A instanceof HTMLTextAreaElement){let p=A.value,u=y.value;if(R("value",y,"update",b)||(p!==u&&(y.value=p),b.formStateSync==="property"))return;y.firstChild&&y.firstChild.nodeValue!==p&&(y.firstChild.nodeValue=p)}}function O(y,A,b,p){let u=A[b],x=y[b];if(u!==x){let g=R(b,y,"update",p);if(g||(y[b]=A[b]),p.formStateSync==="property")return;u?g||y.setAttribute(b,""):R(b,y,"remove",p)||y.removeAttribute(b)}}function R(y,A,b,p){return y==="value"&&p.ignoreActiveValue&&A===document.activeElement?!0:p.callbacks.beforeAttributeUpdated(y,A,b)===!1}function M(y,A){return!!A.ignoreActiveValue&&y===document.activeElement&&y!==document.body}return v})();function X(v,E,S,O){if(v.head.block){let R=E.querySelector("head"),M=S.querySelector("head");if(R&&M){let y=le(R,M,v);return Promise.all(y).then(()=>(v.head.block=!1,v.head.ignore=!0,O(v)))}}return O(v)}function pe(v){return v.tagName==="SCRIPT"?!!v.getAttribute("src"):v.tagName==="LINK"?(v.getAttribute("rel")||"").toLowerCase().split(/\s+/).includes("stylesheet")&&!!v.getAttribute("href"):!1}function le(v,E,S){let O=[],R=[],M=[],y=[],A=S.scripts.matchMode,b=x=>{if(x.tagName==="SCRIPT")return o(x,A,S.merge);if(x.tagName==="LINK"&&A==="smart"){let g=x.getAttribute("href");if(g)try{let w=new URL(g,window.location.href);return`link:${x.getAttribute("rel")||""}:${w.origin}${w.pathname}${w.search}`}catch{}}return x.outerHTML},p=new Map;for(let x of E.children){if(r(x))continue;let g=b(x),w=p.get(g);w||(w=[],p.set(g,w)),w.push(x)}for(let x of v.children){let g=b(x),w=p.get(g),_=!!(w&&w.length),T=S.head.shouldReAppend(x),j=S.head.shouldPreserve(x);if(_||j)if(T)R.push(x);else{if(w&&w.length){let $=w.pop();w.length||p.delete(g),f(S,x,$)}M.push(x)}else S.head.style==="append"?T&&(R.push(x),y.push(x)):S.head.shouldRemove(x)!==!1&&!r(x)&&R.push(x)}for(let x of p.values())y.push(...x);let u=[];for(let x of y){let g=document.createRange().createContextualFragment(x.outerHTML).firstChild;if(S.callbacks.beforeNodeAdded(g)!==!1){if(g instanceof Element&&pe(g)){let w,_=new Promise(function(T){w=T});g.addEventListener("load",function(){w()}),g.addEventListener("error",function(){w()}),u.push(_)}v.appendChild(g),S.callbacks.afterNodeAdded(g),O.push(g)}}for(let x of R)S.callbacks.beforeNodeRemoved(x)!==!1&&(v.removeChild(x),S.callbacks.afterNodeRemoved(x));return S.head.afterHeadMorphed(v,{added:O,kept:M,removed:R}),u}function bn(v,E,S){if(!S.scripts.handle)return[];let O=[],R=[],M=[],y=[],A=S.scripts.matchMode,b=[];for(let u of v)if(u instanceof Element){s(u)&&b.push(u);for(let x of u.querySelectorAll("script"))s(x)&&b.push(x)}for(let u of b){if(u.closest("head")||n(u))continue;let x=o(u,A,S.merge),g=E.has(x),w=S.scripts.shouldPreserve(u),_=S.scripts.shouldReAppend(u);g||w?_?(R.push(u),y.push(u)):M.push(u):y.push(u)}let p=[];for(let u of y){if(S.callbacks.beforeNodeAdded(u)===!1)continue;let x=document.createElement("script");for(let g of u.attributes)x.setAttribute(g.name,g.value);if(x.textContent=u.textContent,x.src){let g,w=new Promise(function(_){g=_});x.addEventListener("load",function(){g()}),x.addEventListener("error",function(){g()}),p.push(w)}u.replaceWith(x),S.callbacks.afterNodeAdded(x),O.push(x)}return S.scripts.afterScriptsHandled(S.target,{added:O,kept:M,removed:R}),p}let kn=(function(){function v(b,p,u){let{persistentIds:x,idMap:g}=y(b,p),w=C.computeMatches(b,p);if(typeof u.key=="function"){let H=new Map,Q=new Set,q=P=>{let U=u.key(P);U!=null&&(H.has(U)?Q.add(U):H.set(U,P))};b instanceof Element&&q(b);for(let P of b.querySelectorAll("*"))q(P);for(let P of Q)H.delete(P);let G=new Map;for(let[P,U]of w)G.set(U,P);let ce=p.__hyperMorphRoot||p,ne=new Map,Qt=new Set,er=P=>{let U=u.key(P);U!=null&&(ne.has(U)?Qt.add(U):ne.set(U,P))};ce instanceof Element&&er(ce);for(let P of ce.querySelectorAll("*"))er(P);for(let P of Qt)ne.delete(P);for(let[P,U]of ne){let fe=H.get(P);if(!fe||fe.tagName!==U.tagName)continue;let ft=G.get(fe);ft&&ft!==U&&w.delete(ft);let gt=w.get(U);gt&&gt!==fe&&G.delete(gt),w.set(U,fe),G.set(fe,U)}}let _=E(u),T=h(b,p,_.scripts);if(T){let H=new Map;for(let[Q,q]of w)H.set(q,Q);for(let[Q,q]of T.newByKey){if(T.disabled.has(Q))continue;let G=T.oldByKey.get(Q);if(!G)continue;let ce=H.get(G);ce&&ce!==q&&w.delete(ce);let ne=w.get(q);ne&&ne!==G&&H.delete(ne),w.set(q,G),H.set(G,q)}}let j=new Set;for(let H of w.values())j.add(H);let $=_.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes($))throw new Error(`Do not understand how to morph style ${$}`);return{target:b,newContent:p,config:_,morphStyle:$,ignoreActive:_.ignoreActive,ignoreActiveValue:_.ignoreActiveValue,restoreFocus:_.restoreFocus,formStateSync:_.formStateSync||"attribute",idMap:g,persistentIds:x,hyperMatches:w,hyperMatchedOldElements:j,merge:T,pantry:S(),activeElementAndParents:O(b),callbacks:_.callbacks,head:_.head,scripts:_.scripts}}function E(b){let p=Object.assign({},k);return Object.assign(p,b),p.callbacks=Object.assign({},k.callbacks,b.callbacks),p.head=Object.assign({},k.head,b.head),p.scripts=Object.assign({},k.scripts,b.scripts),p}function S(){let b=document.createElement("div");return b.hidden=!0,document.body.insertAdjacentElement("afterend",b),b}function O(b){let p=[],u=document.activeElement;if(u?.tagName!=="BODY"&&b.contains(u))for(;u&&(p.push(u),u!==b);)u=u.parentElement;return p}function R(b){let p=Array.from(b.querySelectorAll("[id]"));return b.getAttribute?.("id")&&p.push(b),p}function M(b,p,u,x){for(let g of x){let w=g.getAttribute("id");if(p.has(w)){let _=g;for(;_;){let T=b.get(_);if(T==null&&(T=new Set,b.set(_,T)),T.add(w),_===u)break;_=_.parentElement}}}}function y(b,p){let u=R(b),x=R(p),g=A(u,x),w=new Map;M(w,g,b,u);let _=p.__hyperMorphRoot||p;return M(w,g,_,x),{persistentIds:g,idMap:w}}function A(b,p){let u=new Set,x=new Map;for(let w of b){let _=w.getAttribute("id");x.has(_)?u.add(_):x.set(_,w.tagName)}let g=new Set;for(let w of p){let _=w.getAttribute("id");g.has(_)?u.add(_):x.get(_)===w.tagName&&g.add(_)}for(let w of u)g.delete(w);return g}return v})(),{normalizeElement:yn,normalizeParent:Xt}=(function(){let v=new WeakSet;function E(y){return y instanceof Document?y.documentElement:y}function S(y){if(y==null)return document.createElement("div");if(typeof y=="string")return S(M(y));if(v.has(y))return y;if(y instanceof Node){if(y.parentNode)return new O(y);{let A=document.createElement("div");return A.append(y),A}}else{let A=document.createElement("div");for(let b of[...y])A.append(b);return A}}class O{constructor(A){this.originalNode=A,this.realParentNode=A.parentNode,this.previousSibling=A.previousSibling,this.nextSibling=A.nextSibling}get childNodes(){let A=[],b=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;for(;b&&b!=this.nextSibling;)A.push(b),b=b.nextSibling;return A}querySelectorAll(A){return this.childNodes.reduce((b,p)=>{if(p instanceof Element){p.matches(A)&&b.push(p);let u=p.querySelectorAll(A);for(let x=0;x<u.length;x++)b.push(u[x])}return b},[])}insertBefore(A,b){return this.realParentNode.insertBefore(A,b)}moveBefore(A,b){return this.realParentNode.moveBefore(A,b)}get __hyperMorphRoot(){return this.originalNode}}function R(y){let A=x=>`<${x}(?:\\s(?:[^>"']|"[^"]*"|'[^']*')*)?>`,b=y.replace(/<!--[\s\S]*?-->/g,"");for(let x of["script","style","textarea","title"])b=b.replace(new RegExp(`${A(x)}[\\s\\S]*?</${x}\\s*>`,"gi"),"");let p=new RegExp(`${A("svg")}[\\s\\S]*?</svg\\s*>`,"gi"),u;do u=b,b=b.replace(p,"");while(b!==u);return b}function M(y){let A=new DOMParser,b=R(y);if(b.match(/<\/html>/)||b.match(/<\/head>/)||b.match(/<\/body>/)){let p=A.parseFromString(y,"text/html");if(b.match(/<\/html>/))return v.add(p),p;{let u=p.firstChild;return u&&v.add(u),u}}else{let u=A.parseFromString("<body><template>"+y+"</template></body>","text/html").body.querySelector("template").content;return v.add(u),u}}return{normalizeElement:E,normalizeParent:S}})();return{morph:N,defaults:k,mergeJson:xt,mergeScriptText:wt,parseJsonRelaxed:He,parseRulesRelaxed:dr}})();var hs=_t.morph,ps=_t.defaults;var At=_t;var We=["textContent","innerText","innerHTML","outerHTML","value","checked","selected","disabled","readOnly","type","tagName","nodeName","nodeType","nodeValue","childElementCount","id","className","classList","baseURI","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","dataset","currentSrc","duration","paused","title","documentURI","contentType"],St=new Set(We),pr=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),fr=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var Ke={};kt(Ke,{EmptyListInsert:()=>Ne,MAX_RULE_DEPTH:()=>ye,MaxRuleDepthExceeded:()=>de,RuleTargetReadOnly:()=>Ie,RulesParseError:()=>be,ShapeMismatch:()=>Me,UnknownRulesVersion:()=>ke});var be=class extends Error{constructor(t,r){super(t),this.name="RulesParseError",this.cause=r}},ke=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},ye=20,de=class extends Error{constructor(t){super(`rule depth exceeded ${ye} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},Me=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},Ne=class extends Error{constructor(t){super(`cannot add items to empty list at "${t.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=t}},Ie=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}};function oe(e,t,r,n={}){return Et(e,t,r,{depth:0,path:[]},n)}function Et(e,t,r,n,i){if(n.depth>ye)throw new de(n.path);if(typeof r=="string")return Zn(e,t,r,i);if(Array.isArray(r)){let[o,a]=r;return e.find(t,o,i).map((l,c)=>Et(e,l,a,{depth:n.depth+1,path:[...n.path,c]},i))}if(typeof r=="object"&&r!==null){let o={};for(let[a,s]of Object.entries(r))o[a]=Et(e,t,s,{depth:n.depth+1,path:[...n.path,a]},i);return o}return null}function Zn(e,t,r,n){if(r.endsWith("[]")){let o=r.slice(0,-2);return e.find(t,o,n).map(a=>e.text(a))}if(r.startsWith("@"))return gr(e,t,r.slice(1));if(r.includes("@")){let o=r.lastIndexOf("@"),a=r.slice(0,o),s=r.slice(o+1),l=a?e.find(t,a,n):[t];return l.length===0?null:gr(e,l[0],s)}if(r===".")return e.text(t);let i=e.find(t,r,n);return i.length===0?null:e.text(i[0])}function gr(e,t,r){if(St.has(r)){let i=e.prop(t,r);return i==null?null:String(i)}let n=e.attr(t,r);return n||null}function Xn(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function Qn(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var ei={find(e,t,r={}){let n=Qn(e);if(!n||!n.querySelectorAll)return[];let i=Array.from(n.querySelectorAll(t));r.includeRulesTag||(i=i.filter(s=>!Xn(s)));let o=[];r.skip&&o.push(r.skip);let a=r.templateAttr===null?null:r.templateAttr||"cms-template";if(a&&o.push("["+a+"]"),o.length){let s=o.join(", ");i=i.filter(l=>!l.closest||!l.closest(s))}return i},parent(e){return e?e.parentElement:null},children(e){return e?Array.from(e.children):[]},text(e,t){if(t===void 0)return(e.textContent||"").trim();e.textContent=t},attr(e,t,r){if(r===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,r)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t)},prop(e,t,r){if(r===void 0){let n=e?e[t]:void 0;return n!==void 0?n:null}e[t]=r},clone(e){return e.cloneNode(!0)},insertAt(e,t,r){let n=e.children[r]||null;e.insertBefore(t,n)},remove(e){e&&e.parentNode&&e.parentNode.removeChild(e)},replaceWith(e,t){if(!e||!e.parentNode)throw new Error("dom.replaceWith: node has no parent");let n=e.ownerDocument.createElement("template");n.innerHTML=t;let i=n.content.firstElementChild;if(!i)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(i,e),i},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(n=>{n.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}},se=ei;function Ct(e){try{return JSON.parse(e)}catch(t){throw new be(`Invalid strict JSON: ${t.message}`,t)}}function ve(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function r(i){let o=[],a=0;for(;a<i.length;){let s=i[a];if(/\s/.test(s)){a++;continue}if("{}".includes(s)){o.push({type:s,value:s}),a++;continue}if(s==="["){let d=!1,h=a+1;for(;h<i.length&&/\s/.test(i[h]);)h++;if(h<i.length&&/[a-zA-Z_]/.test(i[h])&&(d=!0),!d){o.push({type:s,value:s}),a++;continue}}if(s==="]"){o.push({type:s,value:s}),a++;continue}if(s===":"){o.push({type:t.COLON,value:s}),a++;continue}if(s===","){o.push({type:t.COMMA,value:s}),a++;continue}if(s==='"'||s==="'"){let d=s,h=a+1;for(;h<i.length&&i[h]!==d;)i[h]==="\\"&&h++,h++;o.push({type:t.STRING,value:i.substring(a+1,h),quoted:!0,sourceQuote:d}),a=h+1;continue}let l=a,c;for(;l<i.length&&!/[{},]/.test(i[l]);)if(i[l]===":"){let d=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],h=!1;for(let f of d){let k=f.substring(1);if(i.substring(l+1,l+1+k.length)===k){h=!0,l+=k.length;break}}if(!h)break}else if(i[l]==="["){for(l++;l<i.length&&i[l]!=="]";){if(i[l]==='"'||i[l]==="'"){let d=i[l];for(l++;l<i.length&&i[l]!==d;)i[l]==="\\"&&l++,l++}l++}l<i.length&&i[l]==="]"&&l++}else l++;c=i.substring(a,l);let m=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(c)?m=t.NUMBER:c==="true"||c==="false"||c==="null"?m=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(c)&&(m=t.SELECTOR),o.push({type:m,value:c,quoted:!1}),a=l}return o}function n(i){let o="";for(let a=0;a<i.length;a++){let s=i[a];if("{}".includes(s.type)||"[]".includes(s.type)){o+=s.value;continue}if(s.type===t.COLON){o+=s.value;continue}if(s.type===t.COMMA){let l=i[a+1];if(l&&(l.type==="}"||l.type==="]"))continue;o+=s.value;continue}if(s.type===t.STRING&&s.quoted){let l=s.value;s.sourceQuote==="'"&&(l=l.replace(/\\'/g,"'"),l=l.replace(/(\\*)"/g,(c,m)=>m.length%2===0?m+'\\"':c)),o+=`"${l}"`;continue}if(s.type===t.NUMBER||s.type===t.BOOLEAN){o+=s.value;continue}if(s.type===t.SELECTOR||s.type===t.IDENTIFIER){o+=`"${s.value}"`;continue}o+=`"${s.value}"`}return o}try{let i=r(e),o=n(i);return JSON.parse(o)}catch(i){throw new be("Invalid extraction rules syntax: "+i.message,i)}}var kr="1",br=/^[a-zA-Z0-9_-]+$/;function Le(e,t,r){let n;if(r===void 0)n="script[data-rules-name]";else{if(typeof r!="string"||!br.test(r))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(r)} (must match ${br})`);n=`script[data-rules-name~="${r}"]`}let i=e.find(t,n,{includeRulesTag:!0});if(i.length===0)return null;r!==void 0&&i.length>1&&console.warn(`hyper-html-api: ${i.length} rules tags match data-rules-name~="${r}"; using the first.`);let o=i[0],a=e.attr(o,"data-rules-version");if(a!==kr)throw new ke(a);return{rules:ve(e.text(o)),tagNode:o}}var Hs=new Function("url","return import(url)");var ri=.5;function Rt(e,t,r,n,i,o,a,s={}){let l=e.find(t,r,s);if(i.length===0){l.forEach(F=>e.remove(F));return}let c=i.length>l.length,m=l[0]||null;if(c&&!m&&(m=ai(e,t,r,s),!m))throw new Ne(o.path);let d=l.map(F=>ni(e,F,n,s)),h=null;if(m){h=e.clone(m),s.templateAttr&&e.removeAttr(h,s.templateAttr);let F=e.stripIds(h);F>0&&console.warn(`[hyper-html-api] stripped ${F} id attribute(s) from cloned template at "${o.path.join(".")||"(root)"}"`)}let f=ii(i,d,n),k=l[0]||m,C=e.parent(k),N=l.length>0?si(e,C,k):0,D=new Set,K=i.map((F,z)=>{let L=f[z];if(L>=0)return D.add(L),l[L];let V=e.clone(h);return e.stripIds(V),V});l.forEach((F,z)=>{D.has(z)||e.remove(F)}),K.forEach((F,z)=>{let L=N+z;e.children(C).findIndex(pe=>e.sameNode(pe,F))!==L&&e.insertAt(C,F,L)}),K.forEach((F,z)=>{if(n===null){let L=i[z],V=L==null?"":String(L);e.text(F)!==V&&e.text(F,V)}else{let L=a(e,F,n,i[z],{depth:o.depth+1,path:[...o.path,z]},s);L&&L!==F&&(K[z]=L)}})}function ni(e,t,r,n){return r===null?e.text(t):oe(e,t,r,n)}function ii(e,t,r){let n=new Array(e.length).fill(-1),i=new Set;return e.forEach((o,a)=>{let s=-1,l=-1;t.forEach((c,m)=>{if(i.has(m))return;let d=oi(o,c,r),h=d===l&&s>=0?Math.abs(m-a)<Math.abs(s-a):!1;(d>l||h)&&(l=d,s=m)}),l>=ri&&(n[a]=s,i.add(s))}),n}function oi(e,t,r){if(r===null)return e===t?1:0;let n=Object.keys(r||{});if(n.length===0)return 0;let i=0;for(let o of n)JSON.stringify(e?.[o])===JSON.stringify(t?.[o])&&i++;return i/n.length}function si(e,t,r){let n=e.children(t);for(let i=0;i<n.length;i++)if(e.sameNode(n[i],r))return i;return-1}function ai(e,t,r,n){if(!n.templateAttr)return null;let i=t;for(;i;){let o=e.find(i,r,{includeRulesTag:!1,templateAttr:null});for(let a of o)if(e.attr(a,n.templateAttr)!=null)return a;i=e.parent(i)}return null}var wr=new Set(["checked","selected","disabled","readOnly","paused"]);function xe(e,t,r,n,i={}){let o=[];if(Tt(r,n,[],o),o.length)throw new Me(o);Ge(e,t,r,n,{depth:0,path:[]},i)}function Ge(e,t,r,n,i,o={}){if(i.depth>ye)throw new de(i.path);if(n===void 0)return t;if(typeof r=="string")return li(e,t,r,n,i,o);if(Array.isArray(r)){let[a,s]=r;return Rt(e,t,a,s,n,i,Ge,o),t}if(typeof r=="object"&&r!==null){for(let[a,s]of Object.entries(r)){let l=Ge(e,t,s,n==null?n:n[a],{depth:i.depth+1,path:[...i.path,a]},o);l&&l!==t&&(t=l)}return t}return t}function li(e,t,r,n,i,o){if(r.endsWith("[]")){let s=r.slice(0,-2);return Rt(e,t,s,null,n,i,Ge,o),t}if(r.startsWith("@"))return _r(e,t,r.slice(1),n);if(r.includes("@")){let s=r.lastIndexOf("@"),l=r.slice(0,s),c=r.slice(s+1),m=l?e.find(t,l,o):[t];return m.length===0||_r(e,m[0],c,n),t}if(r===".")return e.text(t,n==null?"":String(n)),t;let a=e.find(t,r,o);return a.length===0||e.text(a[0],n==null?"":String(n)),t}function _r(e,t,r,n){if(fr.has(r))throw new Ie(r);if(r==="outerHTML"){let i=n==null?"":String(n);return e.replaceWith(t,i)}return pr.has(r)?(e.prop(t,r,ci(r,n)),t):(e.attr(t,r,n==null?"":String(n)),t)}function ci(e,t){return t==null?wr.has(e)?!1:"":wr.has(e)?!!t:t}function Tt(e,t,r,n){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((i,o)=>{typeof i=="object"&&i!==null&&n.push({path:Fe([...r,o]),expected:"scalar",got:je(i)})}):n.push({path:Fe(r),expected:"array",got:je(t)});return}t!==null&&typeof t=="object"&&n.push({path:Fe(r),expected:"scalar",got:je(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){n.push({path:Fe(r),expected:"array",got:je(t)});return}let i=e[1];t.forEach((o,a)=>Tt(i,o,[...r,a],n));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){n.push({path:Fe(r),expected:"object",got:je(t)});return}for(let[i,o]of Object.entries(e))Tt(o,t[i],[...r,i],n)}}}function je(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function Fe(e){return e.join(".")}function Ot(e,t,r){if(r&&typeof r=="object")return{rules:r,tagNode:null};if(typeof r=="string"){let n=t&&t.ownerDocument?t.ownerDocument:t;return Le(e,n,r)}return null}function Sr(e,t,r,n){let i=Ot(e,t,r);if(!i){let s=typeof r=="string"?`data-rules-name~="${r}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${s}`)}let{rules:o,tagNode:a}=i;return{rules:o,tagNode:a,get:()=>oe(e,t,o,n),set:s=>xe(e,t,o,s,n)}}var W={extract:(e,t,r)=>oe(se,e,t,r),apply:(e,t,r,n)=>xe(se,e,t,r,n),findRulesIn:(e,t)=>Le(se,e,t),findRules:(e,t)=>Ot(se,e,t),bind:(e,t,r)=>Sr(se,e,t,r),parseStrict:Ct,parseRelaxed:ve,errors:Ke,DOM_PROPERTIES:We};var Nt={};kt(Nt,{fromString:()=>te,getRuleAtPath:()=>me,getValueAtPath:()=>_i,setAtPath:()=>Mt,toString:()=>wi});function wi(e){return e.map(String).join(".")}function te(e){return e===""?[]:e.split(".").map(t=>/^\d+$/.test(t)?Number(t):t)}function me(e,t){let r=e;for(let n of t){if(r==null)return;if(typeof r=="string"){if(r.endsWith("[]")&&(typeof n=="number"||n==="*")){r=r.slice(0,-2);continue}return}if(Array.isArray(r)){if(typeof n!="number"&&n!=="*")return;r=r[1];continue}if(typeof r=="object"){if(typeof n=="number"||!(n in r))return;r=r[n];continue}return}return r}function _i(e,t){let r=e;for(let n of t){if(r==null)return;r=r[n]}return r}function Mt(e,t,r){if(t.length===0)return r;let[n,...i]=t;if(typeof n=="number"){let o=Array.isArray(e)?[...e]:[];return o[n]=Mt(o[n],i,r),o}return{...e&&typeof e=="object"?e:{},[n]:Mt((e||{})[n],i,r)}}function qe(e){if(typeof e=="string")return e.endsWith("[]")?[]:"";if(Array.isArray(e))return[];if(typeof e=="object"&&e!==null){let t={};for(let[r,n]of Object.entries(e))t[r]=qe(n);return t}return""}function Je(e,t,{ignoreActiveValue:r=!0}={}){At.morph(e,t,{morphStyle:"innerHTML",ignoreActiveValue:r,restoreFocus:!0,formStateSync:"property"})}function Ze(e){return e.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1 $2").replace(/[-_]/g," ").replace(/\s+/g," ").trim().replace(/^./,t=>t.toUpperCase())}var Ai='<div class="hcms-drag-handle mirk-sortable__grip" aria-hidden="true"><div class="mirk-sortable__dots"><span class="mirk-sortable__dot"></span><span class="mirk-sortable__dot"></span><span class="mirk-sortable__dot"></span><span class="mirk-sortable__dot"></span><span class="mirk-sortable__dot"></span><span class="mirk-sortable__dot"></span><span class="mirk-sortable__dot"></span><span class="mirk-sortable__dot"></span></div></div>',It='<svg class="hcms-x" viewBox="0 0 16 16" shape-rendering="crispEdges" aria-hidden="true"><path d="M4 4 L12 12 M12 4 L4 12" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="square"></path></svg>',Rr={"@scalar":`
1
+ var hypercms=(()=>{var wt=Object.defineProperty;var Nn=Object.getOwnPropertyDescriptor;var In=Object.getOwnPropertyNames;var jn=Object.prototype.hasOwnProperty;var _t=(e,t)=>{for(var r in t)wt(e,r,{get:t[r],enumerable:!0})},Ln=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of In(t))!jn.call(e,i)&&i!==r&&wt(e,i,{get:()=>t[i],enumerable:!(n=Nn(t,i))||n.enumerable});return e};var Fn=e=>Ln(wt({},"__esModule",{value:!0}),e);var us={};_t(us,{cms:()=>ds,default:()=>ms});var mr={includeClasses:!0,includeAttributes:["href","src","name","type","role","aria-label","alt","title"],excludeAttributePrefixes:["data-morph-","data-hyper-","data-im-"],textHintLength:64,excludeIds:!0,maxPathDepth:4,landmarks:["HEADER","NAV","MAIN","ASIDE","FOOTER","SECTION","ARTICLE"],weights:{signature:100,pathSegment:10,textMatch:20,textMismatch:25,uniqueCandidate:50,positionPenalty:1,maxDriftPenalty:19,slotMatch:30},minConfidence:101,maxScoredCandidates:16};function Dn(e){let t=5381;for(let r=0;r<e.length;r++)t=(t<<5)+t^e.charCodeAt(r);return Math.abs(t).toString(36)}function $n(e){if(e.classList&&e.classList.length>0)return Array.from(e.classList).sort().join(" ");let t=e.getAttribute?.("class");return t?t.split(/\s+/).filter(Boolean).sort().join(" "):""}function Bn(e,t){let r=[];for(let n of e.attributes||[]){let i=n.name;i==="id"||i==="class"||t.excludeAttributePrefixes.some(o=>i.startsWith(o))||t.includeAttributes.includes(i)&&r.push(`${i}=${n.value}`)}return r.sort().join("|")}function Pn(e,t){return(e.textContent||"").replace(/\s+/g," ").trim().slice(0,t.textHintLength)}function zn(e,t){let r=[e.tagName];return t.includeClasses&&r.push($n(e)),r.push(Bn(e,t)),Dn(r.join("|"))}function Un(e){let t=e.tagName,r=1,n=e.previousElementSibling;for(;n;)n.tagName===t&&r++,n=n.previousElementSibling;return r}function Hn(e,t){return e.getAttribute?.("id")||e.getAttribute?.("role")?!0:t.landmarks.includes(e.tagName)}function Vn(e){let t=e.getAttribute?.("id");if(t)return`#${t}`;let r=e.getAttribute?.("role");return r?`@${r}`:e.tagName}function Wn(e,t){let r=[],n=e;for(;n&&n.tagName&&r.length<t.maxPathDepth;){let i=`${n.tagName}:${Un(n)}`;if(r.unshift(i),n!==e&&Hn(n,t)){r.unshift(Vn(n));break}n=n.parentElement}return r}function Kn(e,t){let r=0,n=e.length-1,i=t.length-1;for(;n>=0&&i>=0&&e[n]===t[i];)r++,n--,i--;return r}function Y(e,t,r){if(r.has(e))return r.get(e);let n={signature:zn(e,t),path:Wn(e,t),textHint:Pn(e,t)};return r.set(e,n),n}function fr(e,t,r,n){if(n.has(e))return n.get(e);let i=new Map,o=e.querySelectorAll("*"),a=0;for(let s of o){let l=Y(s,t,r);l.domIndex=a++,!t.shouldIgnore?.(s)&&(i.has(l.signature)||i.set(l.signature,[]),i.get(l.signature).push(s))}return n.set(e,i),i}function Gn(e,t,r){r.delete(e),t.delete(e);let n=e.querySelectorAll("*");for(let i of n)t.delete(i)}function At(e,t,r,n,i){let o=Y(e,r,n),a=Y(t,r,n),s=r.weights,l={},c=0;if(o.signature!==a.signature)return{score:0,breakdown:{rejected:"signature mismatch"}};c+=s.signature,l.signature=s.signature;let p=Kn(o.path,a.path)*s.pathSegment;c+=p,l.path=p;let d=!0;if(o.textHint&&a.textHint?o.textHint===a.textHint?(c+=s.textMatch,l.text=s.textMatch):(c-=s.textMismatch,l.text=-s.textMismatch,d=!1):o.textHint!==a.textHint&&(c-=s.textMismatch,l.text=-s.textMismatch,d=!1),i.candidateCount===1&&d&&(c+=s.uniqueCandidate,l.unique=s.uniqueCandidate),typeof o.domIndex=="number"&&typeof a.domIndex=="number"){let f=Math.abs(o.domIndex-a.domIndex),k=Math.min(f*s.positionPenalty,s.maxDriftPenalty);c-=k,l.drift=-k}return{score:c,breakdown:l}}function ur(e,t,r,n,i){if(r.excludeIds&&e.getAttribute("id"))return null;let o=fr(t,r,n,i),a=Y(e,r,n);if(typeof a.domIndex!="number"){let d=0,f=e.previousElementSibling;for(;f;)d++,f=f.previousElementSibling;a.domIndex=d}let s=o.get(a.signature)||[],l=r.excludeIds?s.filter(d=>!d.getAttribute("id")):s;if(l.length===0)return null;let c=null,u=0,p=null;for(let d of l){let{score:f,breakdown:k}=At(e,d,r,n,{candidateCount:l.length});f>u&&(u=f,c=d,p=k)}return u<r.minConfidence?null:{element:c,confidence:u,breakdown:p}}function Jn(e,t,r,n){let i=[],o=r.weights.signature+r.weights.slotMatch,a={slot:o};function s(p){if(p.children)return p.children;let d=p.childNodes;if(!d)return[];let f=[];for(let k=0;k<d.length;k++)d[k].nodeType===1&&f.push(d[k]);return f}function l(p,d){let f=s(p),k=s(d);if(f.length===k.length)for(let T=0;T<f.length;T++){let M=f[T],F=k[T];if(r.shouldIgnore?.(M)||r.shouldIgnore?.(F)||r.excludeIds&&(M.getAttribute("id")||F.getAttribute("id"))||M.tagName!==F.tagName)continue;let G=Y(M,r,n).signature,q=Y(F,r,n).signature;G!==q&&i.push({newEl:M,oldEl:F,score:o,breakdown:a}),l(M,F)}}function c(p,d){for(;;){if(p.tagName===d.tagName)return[p,d];let f=s(p);if(!p.tagName&&f.length===1){p=f[0];continue}let k=s(d);if(k.length===1&&k[0].tagName===p.tagName){d=k[0];continue}return null}}let u=c(e,t);return u&&l(u[0],u[1]),i}function hr(e,t,r,n,i){let o=t.querySelectorAll("*"),a=fr(e,r,n,i),s=0;for(let f of o){let k=Y(f,r,n);k.domIndex=s++}let l=[],c=new Map;function u(f,k,T){let M=new Set;if(f.textHint){let j=c.get(f.signature);if(!j){j=new Map;for(let Q of k){let fe=Y(Q,r,n).textHint,ce=j.get(fe);ce||(ce=[],j.set(fe,ce)),ce.push(Q)}c.set(f.signature,j)}let V=j.get(f.textHint);if(V)for(let Q=0;Q<V.length&&Q<T;Q++)M.add(V[Q])}let F=0,G=k.length;for(;F<G;){let j=F+G>>1;Y(k[j],r,n).domIndex<f.domIndex?F=j+1:G=j}let q=Math.max(0,Math.min(F-(T>>1),k.length-T)),P=Math.min(q+T,k.length);for(let j=q;j<P;j++)M.add(k[j]);return[...M]}for(let f of o){if(r.shouldIgnore?.(f)||r.excludeIds&&f.getAttribute("id"))continue;let k=Y(f,r,n),T=a.get(k.signature)||[],M=r.excludeIds?T.filter(q=>!q.getAttribute("id")):T,F=r.maxScoredCandidates,G=F&&M.length>F?u(k,M,F):M;for(let q of G){let{score:P,breakdown:j}=At(f,q,r,n,{candidateCount:M.length});P>=r.minConfidence&&l.push({newEl:f,oldEl:q,score:P,breakdown:j})}}if(r.weights.slotMatch>0){let f=Jn(t,e,r,n);for(let k of f)l.push(k)}l.sort((f,k)=>k.score-f.score);let p=new Map,d=new Set;for(let{newEl:f,oldEl:k}of l)p.has(f)||d.has(k)||(p.set(f,k),d.add(k));return p}function pr(e,t,r,n){let i=Y(e,r,n),o=Y(t,r,n),{score:a,breakdown:s}=At(e,t,r,n,{candidateCount:1});return{matches:a>=r.minConfidence,score:a,breakdown:s,newMeta:{signature:i.signature,path:i.path,textHint:i.textHint},oldMeta:{signature:o.signature,path:o.path,textHint:o.textHint}}}function gr(e={}){let t={...mr,...e,weights:{...mr.weights,...e.weights}},r=new WeakMap,n=new WeakMap;return{findMatch:(i,o)=>ur(i,o,t,r,n),computeMatches:(i,o)=>hr(i,o,t,r,n),explain:(i,o)=>pr(i,o,t,r),invalidate:i=>Gn(i,r,n),session:()=>{let i=new WeakMap,o=new WeakMap;return{findMatch:(a,s)=>ur(a,s,t,i,o),computeMatches:(a,s)=>hr(a,s,t,i,o),explain:(a,s)=>pr(a,s,t,i)}},getConfig:()=>({...t})}}function St(e,t){for(;;){for(;t<e.length&&/\s/.test(e[t]);)t++;if(e[t]==="/"&&e[t+1]==="/"){for(;t<e.length&&e[t]!==`
2
+ `;)t++;continue}if(e[t]==="/"&&e[t+1]==="*"){let r=e.indexOf("*/",t+2);if(r===-1)return e.length;t=r+2;continue}return t}}function br(e){return e.replace(/\\'/g,"'").replace(/(\\*)"/g,(t,r)=>r.length%2===0?r+'\\"':t)}var Yn=/^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/,Xn=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function We(e){try{return JSON.parse(e)}catch{return JSON.parse(Zn(e))}}function Zn(e){let t="",r=0,n=(i,o)=>{throw new Error(`Invalid relaxed JSON: ${i} at position ${o}`)};for(;r<e.length&&(r=St(e,r),!(r>=e.length));){let i=e[r];if("{}[]:".includes(i)){t+=i,r++;continue}if(i===","){let s=St(e,r+1);if(e[s]==="}"||e[s]==="]"){r++;continue}t+=i,r++;continue}if(i==='"'||i==="'"){let s=r+1;for(;s<e.length&&e[s]!==i;)e[s]==="\\"&&s++,s++;s>=e.length&&n("unterminated string",r);let l=e.slice(r+1,s);i==="'"&&(l=br(l)),t+='"'+l+'"',r=s+1;continue}let o=r;for(;o<e.length&&/[A-Za-z0-9_$.+\-]/.test(e[o]);)o++;o===r&&n("unexpected character "+JSON.stringify(i),r);let a=e.slice(r,o);if(a==="true"||a==="false"||a==="null"||Yn.test(a)){t+=a,r=o;continue}if(Xn.test(a)){if(e[St(e,o)]===":"){t+='"'+a+'"',r=o;continue}n("unquoted value "+JSON.stringify(a),r)}n("invalid token "+JSON.stringify(a),r)}return t}function kr(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function r(i){let o=[],a=0;for(;a<i.length;){let s=i[a];if(/\s/.test(s)){a++;continue}if("{}".includes(s)){o.push({type:s,value:s}),a++;continue}if(s==="["){let p=!1,d=a+1;for(;d<i.length&&/\s/.test(i[d]);)d++;if(d<i.length&&/[a-zA-Z_]/.test(i[d])&&(p=!0),!p){o.push({type:s,value:s}),a++;continue}}if(s==="]"){o.push({type:s,value:s}),a++;continue}if(s===":"){o.push({type:t.COLON,value:s}),a++;continue}if(s===","){o.push({type:t.COMMA,value:s}),a++;continue}if(s==='"'||s==="'"){let p=s,d=a+1;for(;d<i.length&&i[d]!==p;)i[d]==="\\"&&d++,d++;o.push({type:t.STRING,value:i.substring(a+1,d),quoted:!0,sourceQuote:p}),a=d+1;continue}let l=a,c;for(;l<i.length&&!/[{},]/.test(i[l]);)if(i[l]===":"){let p=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],d=!1;for(let f of p){let k=f.substring(1);if(i.substring(l+1,l+1+k.length)===k){d=!0,l+=k.length;break}}if(!d)break}else if(i[l]==="["){for(l++;l<i.length&&i[l]!=="]";){if(i[l]==='"'||i[l]==="'"){let p=i[l];for(l++;l<i.length&&i[l]!==p;)i[l]==="\\"&&l++,l++}l++}l<i.length&&i[l]==="]"&&l++}else l++;c=i.substring(a,l);let u=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(c)?u=t.NUMBER:c==="true"||c==="false"||c==="null"?u=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(c)&&(u=t.SELECTOR),o.push({type:u,value:c,quoted:!1}),a=l}return o}function n(i){let o="";for(let a=0;a<i.length;a++){let s=i[a];if("{}".includes(s.type)||"[]".includes(s.type)){o+=s.value;continue}if(s.type===t.COLON){o+=s.value;continue}if(s.type===t.COMMA){let l=i[a+1];if(l&&(l.type==="}"||l.type==="]"))continue;o+=s.value;continue}if(s.type===t.STRING){let l=s.value;s.sourceQuote==="'"&&(l=br(l)),o+=`"${l}"`;continue}if(s.type===t.NUMBER||s.type===t.BOOLEAN){o+=s.value;continue}o+=`"${s.value}"`}return o}try{let i=r(e),o=n(i);return JSON.parse(o)}catch(i){throw new Error("Invalid extraction rules syntax: "+i.message)}}var B=Symbol("hyper-morph-json-merge:missing"),yr=["id","_id","uuid","key","slug","code","name"];function be(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Me(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Qn(e,t,r){Object.defineProperty(e,t,{value:r,enumerable:!0,writable:!0,configurable:!0})}function se(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!se(e[r],t[r]))return!1;return!0}if(be(e)&&be(t)){let r=Object.keys(e);if(r.length!==Object.keys(t).length)return!1;for(let n of r)if(!Me(t,n)||!se(e[n],t[n]))return!1;return!0}return!1}function vr(e,t,r,n){return se(t,r)?t:se(t,e)?r:se(r,e)?t:be(t)&&be(r)?ei(be(e)?e:{},t,r,n):Array.isArray(t)&&Array.isArray(r)?ii(Array.isArray(e)?e:[],t,r,n):r}function xr(e,t,r,n){return t===B&&r===B?B:t===B?e===B?r:se(r,e)?B:r:r===B?e===B?t:B:vr(e,t,r,n)}function ei(e,t,r,n){let i={},o=new Set([...Object.keys(e),...Object.keys(t),...Object.keys(r)]);for(let a of o){let s=xr(Me(e,a)?e[a]:B,Me(t,a)?t[a]:B,Me(r,a)?r[a]:B,n);s!==B&&Qn(i,a,s)}return i}function ti(e){return e===null||typeof e!="object"}function Ke(e){return typeof e+":"+String(e)}function ri(e,t){for(let r of t){let n=new Set;for(let i of r){if(!Me(i,e))return!1;let o=i[e];if(typeof o!="string"&&typeof o!="number")return!1;let a=Ke(o);if(n.has(a))return!1;n.add(a)}}return!0}function ni(e,t,r,n){let i=[e,t,r],o=!0;for(let a of i)for(let s of a)be(s)||(o=!1);if(o){for(let a of n.keyCandidates)if(ri(a,i))return{kind:"keyed",field:a};return null}for(let a of i){let s=new Set;for(let l of a){if(!ti(l))return null;let c=Ke(l);if(s.has(c))return null;s.add(c)}}return{kind:"self"}}function ii(e,t,r,n){let i=ni(e,t,r,n);if(!i)return r;let o=i.kind==="self"?Ke:f=>Ke(f[i.field]),a=f=>{let k=new Map;for(let T of f)k.set(o(T),T);return k},s=a(e),l=a(t),c=a(r),u=new Map,p=new Set([...s.keys(),...l.keys(),...c.keys()]);for(let f of p){let k=xr(s.has(f)?s.get(f):B,l.has(f)?l.get(f):B,c.has(f)?c.get(f):B,n);k!==B&&u.set(f,k)}let d=[];for(let f of r){let k=o(f);u.has(k)&&d.push(k)}for(let f=0;f<t.length;f++){let k=o(t[f]);if(!u.has(k)||d.includes(k))continue;let T=0;for(let M=f-1;M>=0;M--){let F=d.indexOf(o(t[M]));if(F!==-1){T=F+1;break}}d.splice(T,0,k)}return d.map(f=>u.get(f))}function Et(e,t,r,n={}){let i=n.keyCandidates?[...n.keyCandidates,...yr]:yr;return vr(e===void 0?B:e,t,r,{keyCandidates:i})}function Ct(e,t,r,n={}){let i=n.parse||We,o=[],a=(p,d)=>{if(typeof p!="string")return B;try{return i(p)}catch(f){return o.push(`${d} side is not valid JSON (${f.message})`),B}},s=a(t,"local"),l=a(r,"remote");if(s===B)return{text:r,warnings:o};if(l===B)return{text:t,warnings:o};let c=a(e,"base"),u=Et(c===B?void 0:c,s,l,n);return se(u,l)?{text:r,warnings:o}:se(u,s)?{text:t,warnings:o}:{text:JSON.stringify(u,null,2),warnings:o}}var Tt=(function(){"use strict";let e=()=>{},t='[save-ignore],[snapshot-remove],[no-snapshot],[no-save],[save-remove],[freeze],[save-freeze],[clay~="no-save"],[clay~="no-snapshot"],[clay~="freeze"]';function r(v){if(!(v instanceof Element))return!1;if(v.matches(t))return!0;if(v.tagName==="LINK"||v.tagName==="SCRIPT"){let E=v.getAttribute("src")||v.getAttribute("href")||"";if(E.startsWith("chrome-extension://")||E.startsWith("moz-extension://")||E.startsWith("safari-web-extension://"))return!0}return!1}function n(v){return v instanceof Element?v.closest(t)?!0:r(v):!1}let i=gr({shouldIgnore:n});function o(v,E,S){if(S){let N=S.identityOf(v);if(N&&!S.disabled.has(N.key))return"hm-merge:"+N.key}if(E!=="smart")return v.outerHTML;let O=v.getAttribute("src"),C=v.getAttribute("type")||"text/javascript";if(O)try{let N=new URL(O,window.location.href);return`ext:${C}:${N.origin}${N.pathname}${N.search}`}catch{return`ext:${C}:${O}`}else{let N=v.textContent.trim(),y=5381;for(let A=0;A<N.length;A++)y=(y<<5)+y^N.charCodeAt(A);return`inline:${C}:${Math.abs(y).toString(36)}`}}let a="http://www.w3.org/1999/xhtml";function s(v){return v instanceof Element&&v.tagName==="SCRIPT"&&v.namespaceURI===a}function l(v){let E=document.createElement("div");E.innerHTML="<script><\/script>";let S=E.firstChild;for(let O of v.attributes)S.setAttribute(O.name,O.value);return S.textContent=v.textContent,S}function c(v){if(s(v))return l(v);if(v instanceof Element)for(let E of v.querySelectorAll("script"))s(E)&&E.replaceWith(l(E));return v}function u(v){let E=(v.getAttribute("type")||"").split(";")[0].trim().toLowerCase();return E==="application/json"||E.endsWith("+json")}let p={match:v=>v.hasAttribute("merge"),identity:v=>v.getAttribute("merge")};function d(v,E,S){if(S.merge===!1)return null;let O=[p,...S.mergeTags||[]],C=new WeakMap,N=g=>{if(C.has(g))return C.get(g);let w=null;if(s(g)&&!g.getAttribute("src")&&!n(g)){let _=g;for(let R=0;R<O.length;R++)if(O[R].match(_)){if(!u(_))console.warn("[hyper-morph] merge ignored: script type is not JSON",_);else{let L=O[R].identity(_);L!=null&&L!==""&&(w={key:R+":"+L,raw:L,recognizer:O[R]})}break}}return C.set(g,w),w},y=new Set,A=g=>{let w=new Map,_=R=>{let L=N(R);L&&(w.has(L.key)?(y.add(L.key),console.warn(`[hyper-morph] merge disabled for duplicate identity "${L.raw}"`)):w.set(L.key,R))};s(g)&&_(g);for(let R of g.querySelectorAll("script"))_(R);return w},b=A(v),h=A(E.__hyperMorphRoot||E);if(b.size===0&&h.size===0)return null;let m=null;return{identityOf:N,disabled:y,oldByKey:b,newByKey:h,baseTexts:()=>{if(m)return m;m=new Map;let g=S.mergeBase;if(!g)return m;let w;typeof g=="string"?w=new DOMParser().parseFromString(g,"text/html").documentElement:g instanceof Document?w=g.documentElement:w=g;let _=R=>{let L=N(R);L&&!m.has(L.key)&&m.set(L.key,R.textContent)};s(w)&&_(w);for(let R of w.querySelectorAll("script"))_(R);return m}}}function f(v,E,S){let O=v.merge;if(!O)return!1;let C=O.identityOf(E);if(!C||O.disabled.has(C.key))return!1;let N=O.identityOf(S);if(!N||N.key!==C.key)return!1;let y=E,A=S,b=A.getAttribute("merge-key")||y.getAttribute("merge-key"),{text:h,warnings:m}=Ct(O.baseTexts().get(C.key),y.textContent,A.textContent,{parse:C.recognizer.parse,keyCandidates:b?b.split(/[\s,]+/).filter(Boolean):void 0});for(let x of m)console.warn(`[hyper-morph] merge "${C.raw}": ${x}`);return y.textContent!==h&&(y.textContent=h),!0}let k={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:e,afterNodeAdded:e,beforeNodeMorphed:e,afterNodeMorphed:e,beforeNodeRemoved:e,afterNodeRemoved:e,beforeAttributeUpdated:e},head:{style:"merge",shouldPreserve:v=>v.getAttribute("im-preserve")==="true",shouldReAppend:v=>v.getAttribute("im-re-append")==="true",shouldRemove:e,afterHeadMorphed:e},scripts:{handle:!0,matchMode:"outerHTML",shouldPreserve:v=>v.getAttribute("im-preserve")==="true",shouldReAppend:v=>v.getAttribute("im-re-append")==="true",shouldRemove:e,afterScriptsHandled:e},restoreFocus:!0},T={computeMatches(v,E){let{computeMatches:S}=i.session();return S(v,E)}};function M(v,E,S={}){v=Mn(v);let O=sr(E),C=On(v,O,S),N=C.scripts.handle?new Set(Array.from(v.querySelectorAll("script")).map(h=>o(h,C.scripts.matchMode,C.merge))):null,y=q(C),A=Q(C,v,O,h=>h.morphStyle==="innerHTML"?(j(h,v,O),Array.from(v.childNodes)):G(h,v,O)),b=h=>{y&&P(C,y),F(C);let m=N?Rn(h,N,C):[];return m.length>0?Promise.all(m).then(()=>h):h};return A instanceof Promise?A.then(b):b(A)}function F(v){for(let E of Array.from(v.pantry.childNodes))v.callbacks.beforeNodeRemoved(E)!==!1&&v.callbacks.afterNodeRemoved(E);v.pantry.remove()}function G(v,E,S){let O=sr(E);return j(v,O,S,E,E.nextSibling),Array.from(O.childNodes)}function q(v){if(!v.config.restoreFocus)return null;let E=document.activeElement;if(!(E instanceof HTMLInputElement||E instanceof HTMLTextAreaElement))return null;let{id:S,selectionStart:O,selectionEnd:C}=E;return{element:E,id:S,selectionStart:O,selectionEnd:C}}function P(v,E){let S=E.element;if(E.id&&E.id!==document.activeElement?.getAttribute("id")&&(S=v.target.querySelector(`[id="${CSS.escape(E.id)}"]`),S?.focus()),S&&!S.selectionEnd&&E.selectionEnd!=null)try{S.setSelectionRange(E.selectionStart,E.selectionEnd)}catch{}}let j=(function(){function v(h,m,x,g=null,w=null){m instanceof HTMLTemplateElement&&x instanceof HTMLTemplateElement&&(m=m.content,x=x.content),g||=m.firstChild;for(let _ of x.childNodes){if(r(_))continue;if(g&&g!=w){let L=S(h,_,g,w);if(L){L!==g&&C(h,g,L),V(L,_,h),g=L.nextSibling;continue}}if(_ instanceof Element){let L=_.getAttribute("id");if(h.persistentIds.has(L)){let $=N(m,L,g,h);V($,_,h),g=$.nextSibling;continue}if(!h.idMap.has(_)){let $=h.hyperMatches.get(_);if($&&!h.idMap.has($)&&!b($,m)){A(m,$,g),V($,_,h),g=$.nextSibling;continue}}}let R=E(m,_,g,h);R&&(g=R.nextSibling)}for(;g&&g!=w;){let _=g;g=g.nextSibling,r(_)||O(h,_)}}function E(h,m,x,g){if(g.callbacks.beforeNodeAdded(m)===!1)return null;if(g.idMap.has(m)){let w=m,_=document.createElementNS(w.namespaceURI,w.localName);return h.insertBefore(_,x),V(_,m,g),g.callbacks.afterNodeAdded(_),_}else{let w=c(document.importNode(m,!0));return h.insertBefore(w,x),g.callbacks.afterNodeAdded(w),w}}let S=(function(){function h(g,w,_,R){let L=w instanceof Element&&!g.idMap.has(w)?g.hyperMatches.get(w):null,$=null,H=w.nextSibling,ee=0,D=_;for(;D&&D!=R;){if(r(D)){D=D.nextSibling;continue}if(x(D,w)){if(m(g,D,w)||D===L&&!g.idMap.has(D))return D;if($===null){let J=D instanceof Element&&g.hyperMatchedOldElements.has(D);!g.idMap.has(D)&&!J&&($=D)}}if($===null&&H&&x(D,H)&&(ee++,H=H.nextSibling,ee>=2&&($=void 0)),g.activeElementAndParents.includes(D))break;D=D.nextSibling}return $||null}function m(g,w,_){let R=g.idMap.get(w),L=g.idMap.get(_);if(!L||!R)return!1;for(let $ of R)if(L.has($))return!0;return!1}function x(g,w){let _=g,R=w;return _.nodeType===R.nodeType&&_.tagName===R.tagName&&(!_.getAttribute?.("id")||_.getAttribute?.("id")===R.getAttribute?.("id"))}return h})();function O(h,m){let x=m instanceof Element&&h.hyperMatchedOldElements.has(m)&&!h.idMap.has(m);if(h.idMap.has(m)||x)A(h.pantry,m,null);else{if(h.callbacks.beforeNodeRemoved(m)===!1)return;m.parentNode?.removeChild(m),h.callbacks.afterNodeRemoved(m)}}function C(h,m,x){let g=m;for(;g&&g!==x;){let w=g;g=g.nextSibling,r(w)||O(h,w)}return g}function N(h,m,x,g){let w=g.target.getAttribute?.("id")===m&&g.target||g.target.querySelector(`[id="${CSS.escape(m)}"]`)||g.pantry.querySelector(`[id="${CSS.escape(m)}"]`);return y(w,g),A(h,w,x),w}function y(h,m){let x=h.getAttribute("id");for(;h=h.parentNode;){let g=m.idMap.get(h);g&&(g.delete(x),g.size||m.idMap.delete(h))}}function A(h,m,x){if(h.moveBefore)try{h.moveBefore(m,x)}catch{h.insertBefore(m,x)}else h.insertBefore(m,x)}function b(h,m){let x=m instanceof Element?m:m.realParentNode;return!!x&&h.contains(x)}return v})(),V=(function(){function v(y,A,b){return b.ignoreActive&&y===document.activeElement?null:(b.callbacks.beforeNodeMorphed(y,A)===!1||(y instanceof HTMLHeadElement&&b.head.ignore||(y instanceof HTMLHeadElement&&b.head.style!=="morph"?ce(y,A,b):(E(y,A,b),f(b,y,A)||N(y,b)||j(b,y,A))),b.callbacks.afterNodeMorphed(y,A)),y)}function E(y,A,b){let h=A.nodeType;if(h===1){let m=y,x=A,g=m.attributes,w=x.attributes;for(let _ of w)C(_.name,m,"update",b)||m.getAttribute(_.name)!==_.value&&m.setAttribute(_.name,_.value);for(let _=g.length-1;0<=_;_--){let R=g[_];if(R&&!x.hasAttribute(R.name)){if(C(R.name,m,"remove",b))continue;m.removeAttribute(R.name)}}N(m,b)||S(m,x,b)}(h===8||h===3)&&y.nodeValue!==A.nodeValue&&(y.nodeValue=A.nodeValue)}function S(y,A,b){if(y instanceof HTMLInputElement&&A instanceof HTMLInputElement&&A.type!=="file"){let h=A.value,m=y.value;O(y,A,"checked",b),O(y,A,"disabled",b),b.formStateSync==="property"&&y.indeterminate!==A.indeterminate&&(y.indeterminate=A.indeterminate),b.formStateSync==="property"?m!==h&&(C("value",y,"update",b)||(y.value=h)):A.hasAttribute("value")?m!==h&&(C("value",y,"update",b)||(y.setAttribute("value",h),y.value=h)):C("value",y,"remove",b)||(y.value="",y.removeAttribute("value"))}else if(y instanceof HTMLOptionElement&&A instanceof HTMLOptionElement)O(y,A,"selected",b);else if(y instanceof HTMLTextAreaElement&&A instanceof HTMLTextAreaElement){let h=A.value,m=y.value;if(C("value",y,"update",b)||(h!==m&&(y.value=h),b.formStateSync==="property"))return;y.firstChild&&y.firstChild.nodeValue!==h&&(y.firstChild.nodeValue=h)}}function O(y,A,b,h){let m=A[b],x=y[b];if(m!==x){let g=C(b,y,"update",h);if(g||(y[b]=A[b]),h.formStateSync==="property")return;m?g||y.setAttribute(b,""):C(b,y,"remove",h)||y.removeAttribute(b)}}function C(y,A,b,h){return y==="value"&&h.ignoreActiveValue&&A===document.activeElement?!0:h.callbacks.beforeAttributeUpdated(y,A,b)===!1}function N(y,A){return!!A.ignoreActiveValue&&y===document.activeElement&&y!==document.body}return v})();function Q(v,E,S,O){if(v.head.block){let C=E.querySelector("head"),N=S.querySelector("head");if(C&&N){let y=ce(C,N,v);return Promise.all(y).then(()=>(v.head.block=!1,v.head.ignore=!0,O(v)))}}return O(v)}function fe(v){return v.tagName==="SCRIPT"?!!v.getAttribute("src"):v.tagName==="LINK"?(v.getAttribute("rel")||"").toLowerCase().split(/\s+/).includes("stylesheet")&&!!v.getAttribute("href"):!1}function ce(v,E,S){let O=[],C=[],N=[],y=[],A=S.scripts.matchMode,b=x=>{if(x.tagName==="SCRIPT")return o(x,A,S.merge);if(x.tagName==="LINK"&&A==="smart"){let g=x.getAttribute("href");if(g)try{let w=new URL(g,window.location.href);return`link:${x.getAttribute("rel")||""}:${w.origin}${w.pathname}${w.search}`}catch{}}return x.outerHTML},h=new Map;for(let x of E.children){if(r(x))continue;let g=b(x),w=h.get(g);w||(w=[],h.set(g,w)),w.push(x)}for(let x of v.children){let g=b(x),w=h.get(g),_=!!(w&&w.length),R=S.head.shouldReAppend(x),L=S.head.shouldPreserve(x);if(_||L)if(R)C.push(x);else{if(w&&w.length){let $=w.pop();w.length||h.delete(g),f(S,x,$)}N.push(x)}else S.head.style==="append"?R&&(C.push(x),y.push(x)):S.head.shouldRemove(x)!==!1&&!r(x)&&C.push(x)}for(let x of h.values())y.push(...x);let m=[];for(let x of y){let g=document.createRange().createContextualFragment(x.outerHTML).firstChild;if(S.callbacks.beforeNodeAdded(g)!==!1){if(g instanceof Element&&fe(g)){let w,_=new Promise(function(R){w=R});g.addEventListener("load",function(){w()}),g.addEventListener("error",function(){w()}),m.push(_)}v.appendChild(g),S.callbacks.afterNodeAdded(g),O.push(g)}}for(let x of C)S.callbacks.beforeNodeRemoved(x)!==!1&&(v.removeChild(x),S.callbacks.afterNodeRemoved(x));return S.head.afterHeadMorphed(v,{added:O,kept:N,removed:C}),m}function Rn(v,E,S){if(!S.scripts.handle)return[];let O=[],C=[],N=[],y=[],A=S.scripts.matchMode,b=[];for(let m of v)if(m instanceof Element){s(m)&&b.push(m);for(let x of m.querySelectorAll("script"))s(x)&&b.push(x)}for(let m of b){if(m.closest("head")||n(m))continue;let x=o(m,A,S.merge),g=E.has(x),w=S.scripts.shouldPreserve(m),_=S.scripts.shouldReAppend(m);g||w?_?(C.push(m),y.push(m)):N.push(m):y.push(m)}let h=[];for(let m of y){if(S.callbacks.beforeNodeAdded(m)===!1)continue;let x=document.createElement("script");for(let g of m.attributes)x.setAttribute(g.name,g.value);if(x.textContent=m.textContent,x.src){let g,w=new Promise(function(_){g=_});x.addEventListener("load",function(){g()}),x.addEventListener("error",function(){g()}),h.push(w)}m.replaceWith(x),S.callbacks.afterNodeAdded(x),O.push(x)}return S.scripts.afterScriptsHandled(S.target,{added:O,kept:N,removed:C}),h}let On=(function(){function v(b,h,m){let{persistentIds:x,idMap:g}=y(b,h),w=T.computeMatches(b,h);if(typeof m.key=="function"){let H=new Map,ee=new Set,D=z=>{let U=m.key(z);U!=null&&(H.has(U)?ee.add(U):H.set(U,z))};b instanceof Element&&D(b);for(let z of b.querySelectorAll("*"))D(z);for(let z of ee)H.delete(z);let J=new Map;for(let[z,U]of w)J.set(U,z);let de=h.__hyperMorphRoot||h,oe=new Map,ar=new Set,lr=z=>{let U=m.key(z);U!=null&&(oe.has(U)?ar.add(U):oe.set(U,z))};de instanceof Element&&lr(de);for(let z of de.querySelectorAll("*"))lr(z);for(let z of ar)oe.delete(z);for(let[z,U]of oe){let ge=H.get(z);if(!ge||ge.tagName!==U.tagName)continue;let vt=J.get(ge);vt&&vt!==U&&w.delete(vt);let xt=w.get(U);xt&&xt!==ge&&J.delete(xt),w.set(U,ge),J.set(ge,U)}}let _=E(m),R=d(b,h,_.scripts);if(R){let H=new Map;for(let[ee,D]of w)H.set(D,ee);for(let[ee,D]of R.newByKey){if(R.disabled.has(ee))continue;let J=R.oldByKey.get(ee);if(!J)continue;let de=H.get(J);de&&de!==D&&w.delete(de);let oe=w.get(D);oe&&oe!==J&&H.delete(oe),w.set(D,J),H.set(J,D)}}let L=new Set;for(let H of w.values())L.add(H);let $=_.morphStyle||"outerHTML";if(!["innerHTML","outerHTML"].includes($))throw new Error(`Do not understand how to morph style ${$}`);return{target:b,newContent:h,config:_,morphStyle:$,ignoreActive:_.ignoreActive,ignoreActiveValue:_.ignoreActiveValue,restoreFocus:_.restoreFocus,formStateSync:_.formStateSync||"attribute",idMap:g,persistentIds:x,hyperMatches:w,hyperMatchedOldElements:L,merge:R,pantry:S(),activeElementAndParents:O(b),callbacks:_.callbacks,head:_.head,scripts:_.scripts}}function E(b){let h=Object.assign({},k);return Object.assign(h,b),h.callbacks=Object.assign({},k.callbacks,b.callbacks),h.head=Object.assign({},k.head,b.head),h.scripts=Object.assign({},k.scripts,b.scripts),h}function S(){let b=document.createElement("div");return b.hidden=!0,document.body.insertAdjacentElement("afterend",b),b}function O(b){let h=[],m=document.activeElement;if(m?.tagName!=="BODY"&&b.contains(m))for(;m&&(h.push(m),m!==b);)m=m.parentElement;return h}function C(b){let h=Array.from(b.querySelectorAll("[id]"));return b.getAttribute?.("id")&&h.push(b),h}function N(b,h,m,x){for(let g of x){let w=g.getAttribute("id");if(h.has(w)){let _=g;for(;_;){let R=b.get(_);if(R==null&&(R=new Set,b.set(_,R)),R.add(w),_===m)break;_=_.parentElement}}}}function y(b,h){let m=C(b),x=C(h),g=A(m,x),w=new Map;N(w,g,b,m);let _=h.__hyperMorphRoot||h;return N(w,g,_,x),{persistentIds:g,idMap:w}}function A(b,h){let m=new Set,x=new Map;for(let w of b){let _=w.getAttribute("id");x.has(_)?m.add(_):x.set(_,w.tagName)}let g=new Set;for(let w of h){let _=w.getAttribute("id");g.has(_)?m.add(_):x.get(_)===w.tagName&&g.add(_)}for(let w of m)g.delete(w);return g}return v})(),{normalizeElement:Mn,normalizeParent:sr}=(function(){let v=new WeakSet;function E(y){return y instanceof Document?y.documentElement:y}function S(y){if(y==null)return document.createElement("div");if(typeof y=="string")return S(N(y));if(v.has(y))return y;if(y instanceof Node){if(y.parentNode)return new O(y);{let A=document.createElement("div");return A.append(y),A}}else{let A=document.createElement("div");for(let b of[...y])A.append(b);return A}}class O{constructor(A){this.originalNode=A,this.realParentNode=A.parentNode,this.previousSibling=A.previousSibling,this.nextSibling=A.nextSibling}get childNodes(){let A=[],b=this.previousSibling?this.previousSibling.nextSibling:this.realParentNode.firstChild;for(;b&&b!=this.nextSibling;)A.push(b),b=b.nextSibling;return A}querySelectorAll(A){return this.childNodes.reduce((b,h)=>{if(h instanceof Element){h.matches(A)&&b.push(h);let m=h.querySelectorAll(A);for(let x=0;x<m.length;x++)b.push(m[x])}return b},[])}insertBefore(A,b){return this.realParentNode.insertBefore(A,b)}moveBefore(A,b){return this.realParentNode.moveBefore(A,b)}get __hyperMorphRoot(){return this.originalNode}}function C(y){let A=x=>`<${x}(?:\\s(?:[^>"']|"[^"]*"|'[^']*')*)?>`,b=y.replace(/<!--[\s\S]*?-->/g,"");for(let x of["script","style","textarea","title"])b=b.replace(new RegExp(`${A(x)}[\\s\\S]*?</${x}\\s*>`,"gi"),"");let h=new RegExp(`${A("svg")}[\\s\\S]*?</svg\\s*>`,"gi"),m;do m=b,b=b.replace(h,"");while(b!==m);return b}function N(y){let A=new DOMParser,b=C(y);if(b.match(/<\/html>/)||b.match(/<\/head>/)||b.match(/<\/body>/)){let h=A.parseFromString(y,"text/html");if(b.match(/<\/html>/))return v.add(h),h;{let m=h.firstChild;return m&&v.add(m),m}}else{let m=A.parseFromString("<body><template>"+y+"</template></body>","text/html").body.querySelector("template").content;return v.add(m),m}}return{normalizeElement:E,normalizeParent:S}})();return{morph:M,defaults:k,mergeJson:Et,mergeScriptText:Ct,parseJsonRelaxed:We,parseRulesRelaxed:kr}})();var Ns=Tt.morph,Is=Tt.defaults;var Rt=Tt;var Ge=["textContent","innerText","innerHTML","outerHTML","value","checked","selected","disabled","readOnly","type","tagName","nodeName","nodeType","nodeValue","childElementCount","id","className","classList","baseURI","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","dataset","currentSrc","duration","paused","title","documentURI","contentType"],Ot=new Set(Ge),wr=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),_r=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]);var Je={};_t(Je,{EmptyListInsert:()=>Ie,MAX_RULE_DEPTH:()=>ve,MaxRuleDepthExceeded:()=>me,RuleTargetReadOnly:()=>je,RulesParseError:()=>ke,ShapeMismatch:()=>Ne,UnknownRulesVersion:()=>ye});var ke=class extends Error{constructor(t,r){super(t),this.name="RulesParseError",this.cause=r}},ye=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},ve=20,me=class extends Error{constructor(t){super(`rule depth exceeded ${ve} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},Ne=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},Ie=class extends Error{constructor(t){super(`cannot add items to empty list at "${t.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=t}},je=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}};function ae(e,t,r,n={}){return Mt(e,t,r,{depth:0,path:[]},n)}function Mt(e,t,r,n,i){if(n.depth>ve)throw new me(n.path);if(typeof r=="string")return ci(e,t,r,i);if(Array.isArray(r)){let[o,a]=r;return e.find(t,o,i).map((l,c)=>Mt(e,l,a,{depth:n.depth+1,path:[...n.path,c]},i))}if(typeof r=="object"&&r!==null){let o={};for(let[a,s]of Object.entries(r))o[a]=Mt(e,t,s,{depth:n.depth+1,path:[...n.path,a]},i);return o}return null}function ci(e,t,r,n){if(r.endsWith("[]")){let o=r.slice(0,-2);return e.find(t,o,n).map(a=>e.text(a))}if(r.startsWith("@"))return Ar(e,t,r.slice(1));if(r.includes("@")){let o=r.lastIndexOf("@"),a=r.slice(0,o),s=r.slice(o+1),l=a?e.find(t,a,n):[t];return l.length===0?null:Ar(e,l[0],s)}if(r===".")return e.text(t);let i=e.find(t,r,n);return i.length===0?null:e.text(i[0])}function Ar(e,t,r){if(Ot.has(r)){let i=e.prop(t,r);return i==null?null:String(i)}let n=e.attr(t,r);return n||null}function di(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function mi(e){return e?(e.nodeType===9||e.nodeType===11,e):null}var ui={find(e,t,r={}){let n=mi(e);if(!n||!n.querySelectorAll)return[];let i=Array.from(n.querySelectorAll(t));r.includeRulesTag||(i=i.filter(s=>!di(s)));let o=[];r.skip&&o.push(r.skip);let a=r.templateAttr===null?null:r.templateAttr||"cms-template";if(a&&o.push("["+a+"]"),o.length){let s=o.join(", ");i=i.filter(l=>!l.closest||!l.closest(s))}return i},parent(e){return e?e.parentElement:null},children(e){return e?Array.from(e.children):[]},text(e,t){if(t===void 0)return(e.textContent||"").trim();e.textContent=t},attr(e,t,r){if(r===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,r)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t)},prop(e,t,r){if(r===void 0){let n=e?e[t]:void 0;return n!==void 0?n:null}e[t]=r},clone(e){return e.cloneNode(!0)},insertAt(e,t,r){let n=e.children[r]||null;e.insertBefore(t,n)},remove(e){e&&e.parentNode&&e.parentNode.removeChild(e)},replaceWith(e,t){if(!e||!e.parentNode)throw new Error("dom.replaceWith: node has no parent");let n=e.ownerDocument.createElement("template");n.innerHTML=t;let i=n.content.firstElementChild;if(!i)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(i,e),i},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(n=>{n.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}},te=ui;function Nt(e){try{return JSON.parse(e)}catch(t){throw new ke(`Invalid strict JSON: ${t.message}`,t)}}function xe(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function r(i){let o=[],a=0;for(;a<i.length;){let s=i[a];if(/\s/.test(s)){a++;continue}if("{}".includes(s)){o.push({type:s,value:s}),a++;continue}if(s==="["){let p=!1,d=a+1;for(;d<i.length&&/\s/.test(i[d]);)d++;if(d<i.length&&/[a-zA-Z_]/.test(i[d])&&(p=!0),!p){o.push({type:s,value:s}),a++;continue}}if(s==="]"){o.push({type:s,value:s}),a++;continue}if(s===":"){o.push({type:t.COLON,value:s}),a++;continue}if(s===","){o.push({type:t.COMMA,value:s}),a++;continue}if(s==='"'||s==="'"){let p=s,d=a+1;for(;d<i.length&&i[d]!==p;)i[d]==="\\"&&d++,d++;o.push({type:t.STRING,value:i.substring(a+1,d),quoted:!0,sourceQuote:p}),a=d+1;continue}let l=a,c;for(;l<i.length&&!/[{},]/.test(i[l]);)if(i[l]===":"){let p=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],d=!1;for(let f of p){let k=f.substring(1);if(i.substring(l+1,l+1+k.length)===k){d=!0,l+=k.length;break}}if(!d)break}else if(i[l]==="["){for(l++;l<i.length&&i[l]!=="]";){if(i[l]==='"'||i[l]==="'"){let p=i[l];for(l++;l<i.length&&i[l]!==p;)i[l]==="\\"&&l++,l++}l++}l<i.length&&i[l]==="]"&&l++}else l++;c=i.substring(a,l);let u=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(c)?u=t.NUMBER:c==="true"||c==="false"||c==="null"?u=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(c)&&(u=t.SELECTOR),o.push({type:u,value:c,quoted:!1}),a=l}return o}function n(i){let o="";for(let a=0;a<i.length;a++){let s=i[a];if("{}".includes(s.type)||"[]".includes(s.type)){o+=s.value;continue}if(s.type===t.COLON){o+=s.value;continue}if(s.type===t.COMMA){let l=i[a+1];if(l&&(l.type==="}"||l.type==="]"))continue;o+=s.value;continue}if(s.type===t.STRING&&s.quoted){let l=s.value;s.sourceQuote==="'"&&(l=l.replace(/\\'/g,"'"),l=l.replace(/(\\*)"/g,(c,u)=>u.length%2===0?u+'\\"':c)),o+=`"${l}"`;continue}if(s.type===t.NUMBER||s.type===t.BOOLEAN){o+=s.value;continue}if(s.type===t.SELECTOR||s.type===t.IDENTIFIER){o+=`"${s.value}"`;continue}o+=`"${s.value}"`}return o}try{let i=r(e),o=n(i);return JSON.parse(o)}catch(i){throw new ke("Invalid extraction rules syntax: "+i.message,i)}}var Er="1",Sr=/^[a-zA-Z0-9_-]+$/;function Le(e,t,r){let n;if(r===void 0)n="script[data-rules-name]";else{if(typeof r!="string"||!Sr.test(r))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(r)} (must match ${Sr})`);n=`script[data-rules-name~="${r}"]`}let i=e.find(t,n,{includeRulesTag:!0});if(i.length===0)return null;r!==void 0&&i.length>1&&console.warn(`hyper-html-api: ${i.length} rules tags match data-rules-name~="${r}"; using the first.`);let o=i[0],a=e.attr(o,"data-rules-version");if(a!==Er)throw new ye(a);return{rules:xe(e.text(o)),tagNode:o}}var ca=new Function("url","return import(url)");var pi=.5;function It(e,t,r,n,i,o,a,s={}){let l=e.find(t,r,s);if(i.length===0){l.forEach(q=>e.remove(q));return}let c=i.length>l.length,u=l[0]||null;if(c&&!u&&(u=yi(e,t,r,s),!u))throw new Ie(o.path);let p=l.map(q=>fi(e,q,n,s)),d=null;if(u){d=e.clone(u),s.templateAttr&&e.removeAttr(d,s.templateAttr);let q=e.stripIds(d);q>0&&console.warn(`[hyper-html-api] stripped ${q} id attribute(s) from cloned template at "${o.path.join(".")||"(root)"}"`)}let f=gi(i,p,n),k=l[0]||u,T=e.parent(k),M=l.length>0?ki(e,T,k):0,F=new Set,G=i.map((q,P)=>{let j=f[P];if(j>=0)return F.add(j),l[j];let V=e.clone(d);return e.stripIds(V),V});l.forEach((q,P)=>{F.has(P)||e.remove(q)}),G.forEach((q,P)=>{let j=M+P;e.children(T).findIndex(fe=>e.sameNode(fe,q))!==j&&e.insertAt(T,q,j)}),G.forEach((q,P)=>{if(n===null){let j=i[P],V=j==null?"":String(j);e.text(q)!==V&&e.text(q,V)}else{let j=a(e,q,n,i[P],{depth:o.depth+1,path:[...o.path,P]},s);j&&j!==q&&(G[P]=j)}})}function fi(e,t,r,n){return r===null?e.text(t):ae(e,t,r,n)}function gi(e,t,r){let n=new Array(e.length).fill(-1),i=new Set;return e.forEach((o,a)=>{let s=-1,l=-1;t.forEach((c,u)=>{if(i.has(u))return;let p=bi(o,c,r),d=p===l&&s>=0?Math.abs(u-a)<Math.abs(s-a):!1;(p>l||d)&&(l=p,s=u)}),l>=pi&&(n[a]=s,i.add(s))}),n}function bi(e,t,r){if(r===null)return e===t?1:0;let n=Object.keys(r||{});if(n.length===0)return 0;let i=0;for(let o of n)JSON.stringify(e?.[o])===JSON.stringify(t?.[o])&&i++;return i/n.length}function ki(e,t,r){let n=e.children(t);for(let i=0;i<n.length;i++)if(e.sameNode(n[i],r))return i;return-1}function yi(e,t,r,n){if(!n.templateAttr)return null;let i=t;for(;i;){let o=e.find(i,r,{includeRulesTag:!1,templateAttr:null});for(let a of o)if(e.attr(a,n.templateAttr)!=null)return a;i=e.parent(i)}return null}var Or=new Set(["checked","selected","disabled","readOnly","paused"]);function we(e,t,r,n,i={}){let o=[];if(jt(r,n,[],o),o.length)throw new Ne(o);Ye(e,t,r,n,{depth:0,path:[]},i)}function Ye(e,t,r,n,i,o={}){if(i.depth>ve)throw new me(i.path);if(n===void 0)return t;if(typeof r=="string")return vi(e,t,r,n,i,o);if(Array.isArray(r)){let[a,s]=r;return It(e,t,a,s,n,i,Ye,o),t}if(typeof r=="object"&&r!==null){for(let[a,s]of Object.entries(r)){let l=Ye(e,t,s,n==null?n:n[a],{depth:i.depth+1,path:[...i.path,a]},o);l&&l!==t&&(t=l)}return t}return t}function vi(e,t,r,n,i,o){if(r.endsWith("[]")){let s=r.slice(0,-2);return It(e,t,s,null,n,i,Ye,o),t}if(r.startsWith("@"))return Mr(e,t,r.slice(1),n);if(r.includes("@")){let s=r.lastIndexOf("@"),l=r.slice(0,s),c=r.slice(s+1),u=l?e.find(t,l,o):[t];return u.length===0||Mr(e,u[0],c,n),t}if(r===".")return e.text(t,n==null?"":String(n)),t;let a=e.find(t,r,o);return a.length===0||e.text(a[0],n==null?"":String(n)),t}function Mr(e,t,r,n){if(_r.has(r))throw new je(r);if(r==="outerHTML"){let i=n==null?"":String(n);return e.replaceWith(t,i)}return wr.has(r)?(e.prop(t,r,xi(r,n)),t):(e.attr(t,r,n==null?"":String(n)),t)}function xi(e,t){return t==null?Or.has(e)?!1:"":Or.has(e)?!!t:t}function jt(e,t,r,n){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((i,o)=>{typeof i=="object"&&i!==null&&n.push({path:qe([...r,o]),expected:"scalar",got:Fe(i)})}):n.push({path:qe(r),expected:"array",got:Fe(t)});return}t!==null&&typeof t=="object"&&n.push({path:qe(r),expected:"scalar",got:Fe(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){n.push({path:qe(r),expected:"array",got:Fe(t)});return}let i=e[1];t.forEach((o,a)=>jt(i,o,[...r,a],n));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){n.push({path:qe(r),expected:"object",got:Fe(t)});return}for(let[i,o]of Object.entries(e))jt(o,t[i],[...r,i],n)}}}function Fe(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function qe(e){return e.join(".")}function Lt(e,t,r){if(r&&typeof r=="object")return{rules:r,tagNode:null};if(typeof r=="string"){let n=t&&t.ownerDocument?t.ownerDocument:t;return Le(e,n,r)}return null}function Ir(e,t,r,n){let i=Lt(e,t,r);if(!i){let s=typeof r=="string"?`data-rules-name~="${r}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${s}`)}let{rules:o,tagNode:a}=i;return{rules:o,tagNode:a,get:()=>ae(e,t,o,n),set:s=>we(e,t,o,s,n)}}var K={extract:(e,t,r)=>ae(te,e,t,r),apply:(e,t,r,n)=>we(te,e,t,r,n),findRulesIn:(e,t)=>Le(te,e,t),findRules:(e,t)=>Lt(te,e,t),bind:(e,t,r)=>Ir(te,e,t,r),parseStrict:Nt,parseRelaxed:xe,errors:Je,DOM_PROPERTIES:Ge};var qt={};_t(qt,{fromString:()=>ne,getRuleAtPath:()=>ue,getValueAtPath:()=>Li,setAtPath:()=>Ft,toString:()=>ji});function ji(e){return e.map(String).join(".")}function ne(e){return e===""?[]:e.split(".").map(t=>/^\d+$/.test(t)?Number(t):t)}function ue(e,t){let r=e;for(let n of t){if(r==null)return;if(typeof r=="string"){if(r.endsWith("[]")&&(typeof n=="number"||n==="*")){r=r.slice(0,-2);continue}return}if(Array.isArray(r)){if(typeof n!="number"&&n!=="*")return;r=r[1];continue}if(typeof r=="object"){if(typeof n=="number"||!(n in r))return;r=r[n];continue}return}return r}function Li(e,t){let r=e;for(let n of t){if(r==null)return;r=r[n]}return r}function Ft(e,t,r){if(t.length===0)return r;let[n,...i]=t;if(typeof n=="number"){let o=Array.isArray(e)?[...e]:[];return o[n]=Ft(o[n],i,r),o}return{...e&&typeof e=="object"?e:{},[n]:Ft((e||{})[n],i,r)}}function De(e){if(typeof e=="string")return e.endsWith("[]")?[]:"";if(Array.isArray(e))return[];if(typeof e=="object"&&e!==null){let t={};for(let[r,n]of Object.entries(e))t[r]=De(n);return t}return""}function Xe(e,t,{ignoreActiveValue:r=!0}={}){Rt.morph(e,t,{morphStyle:"innerHTML",ignoreActiveValue:r,restoreFocus:!0,formStateSync:"property"})}function Qe(e){return e.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1 $2").replace(/[-_]/g," ").replace(/\s+/g," ").trim().replace(/^./,t=>t.toUpperCase())}var Fi='<div class="hcms-drag-handle mirk-sortable__grip" aria-hidden="true"><div class="mirk-sortable__dots"><span class="mirk-sortable__dot"></span><span class="mirk-sortable__dot"></span><span class="mirk-sortable__dot"></span><span class="mirk-sortable__dot"></span><span class="mirk-sortable__dot"></span><span class="mirk-sortable__dot"></span><span class="mirk-sortable__dot"></span><span class="mirk-sortable__dot"></span></div></div>',Dt='<svg class="hcms-x" viewBox="0 0 16 16" shape-rendering="crispEdges" aria-hidden="true"><path d="M4 4 L12 12 M12 4 L4 12" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="square"></path></svg>',Fr={"@scalar":`
3
3
  <label class="hcms-field" data-hcms-shape="scalar">
4
4
  <span class="hcms-label" data-hcms-label></span>
5
5
  <textarea class="mirk-textarea" rows="1" data-hcms-field></textarea>
@@ -39,13 +39,13 @@ var hypercms=(()=>{var bt=Object.defineProperty;var vn=Object.getOwnPropertyDesc
39
39
  </section>
40
40
  `,"@object-array-item":`
41
41
  <article class="hcms-card mirk-sortable__item" draggable="true">
42
- ${Ai}
42
+ ${Fi}
43
43
  <div class="hcms-card-body mirk-sortable__body">
44
44
  <div class="hcms-card-fields"></div>
45
45
  <div class="hcms-card-controls">
46
46
  <button type="button" class="hcms-move hcms-move-up hcms-sr-only" data-hcms-action="move-up" aria-label="Move up">\u2191</button>
47
47
  <button type="button" class="hcms-move hcms-move-down hcms-sr-only" data-hcms-action="move-down" aria-label="Move down">\u2193</button>
48
- <button type="button" class="hcms-remove hcms-remove--card" data-hcms-action="remove" aria-label="Remove">${It}</button>
48
+ <button type="button" class="hcms-remove hcms-remove--card" data-hcms-action="remove" aria-label="Remove">${Dt}</button>
49
49
  </div>
50
50
  </div>
51
51
  <div class="hcms-error" hidden></div>
@@ -59,7 +59,7 @@ var hypercms=(()=>{var bt=Object.defineProperty;var vn=Object.getOwnPropertyDesc
59
59
  <span class="mirk-button__label">Choose</span>
60
60
  </label>
61
61
  <a class="mirk-file__name" data-hcms-field></a>
62
- <button type="button" class="hcms-upload-clear" data-hcms-action="clear-upload" aria-label="Remove file">${It}</button>
62
+ <button type="button" class="hcms-upload-clear" data-hcms-action="clear-upload" aria-label="Remove file">${Dt}</button>
63
63
  </div>
64
64
  <div class="hcms-error" hidden></div>
65
65
  </div>
@@ -73,7 +73,7 @@ var hypercms=(()=>{var bt=Object.defineProperty;var vn=Object.getOwnPropertyDesc
73
73
  </label>
74
74
  <figure class="mirk-image__thumb">
75
75
  <span class="mirk-image__frame"><img class="mirk-image__preview" data-hcms-field alt="" /></span>
76
- <button type="button" class="hcms-upload-clear hcms-upload-clear--badge" data-hcms-action="clear-upload" aria-label="Remove image">${It}</button>
76
+ <button type="button" class="hcms-upload-clear hcms-upload-clear--badge" data-hcms-action="clear-upload" aria-label="Remove image">${Dt}</button>
77
77
  </figure>
78
78
  </div>
79
79
  <div class="hcms-error" hidden></div>
@@ -147,11 +147,11 @@ var hypercms=(()=>{var bt=Object.defineProperty;var vn=Object.getOwnPropertyDesc
147
147
  <input class="hcms-chip-field" data-hcms-field aria-label="Item" placeholder="\u2026" />
148
148
  <button type="button" class="hcms-remove" data-hcms-action="remove" aria-label="Remove">\xD7</button>
149
149
  </span>
150
- `},Si=["@scalar","@object","@scalar-array","@scalar-array-item","@object-array","@object-array-item"];function Xe(e){let t=e.head||e.documentElement;if(t)for(let r of Si)Nr(e,t,r)}function Lt(e,t){if(!Rr[t])return null;let r=e&&(e.head||e.documentElement);return r?Nr(e,r,t):null}var Er={src:"@image",checked:"@checkbox",innerHTML:"@richtext"},Ye={image:"@image",file:"@file",checkbox:"@checkbox",toggle:"@toggle",select:"@select",radio:"@radio",textarea:"@textarea",number:"@number",richtext:"@richtext"},Ei=new Set([...Object.values(Ye),"@chips","@chips-item"]);function De(e,t,r){if(typeof e!="string")return"@scalar";let n=e.lastIndexOf("@"),i=tt($e(e,n),t,"data-hcms-component");if(i&&Ye[i]){let o=Ye[i],a=Array.isArray(r)&&r.some(s=>s==="*"||typeof s=="number");return o==="@number"&&!Cr(e,n,t,a).every(Ri)||(o==="@checkbox"||o==="@toggle")&&(n<0||e.slice(n+1)!=="checked")&&!Cr(e,n,t,a).every(Ti)?"@scalar":o}if(n>=0){let o=e.slice(n+1);if(Er[o])return Er[o]}return"@scalar"}function Tr(e,t){if(typeof e!="string")return null;let r=e.lastIndexOf("@"),n=tt($e(e,r),t,"data-hcms-component");return n&&Ye[n]||null}var Ci=/^-?\d+(\.\d+)?([eE][+-]?\d+)?$/;function Ri(e){return e==null||e===""?!0:Ci.test(String(e))}function Ti(e){return e==null||e===""||e==="true"||e==="false"}function Cr(e,t,r,n){if(!r||!r.querySelectorAll)return[];let i=$e(e,t);if(!i||i===".")return[];let o=null;try{o=r.querySelectorAll(i)}catch{return[]}let a=t>=0?e.slice(t+1):null,s=[];for(let l of o)if(!(l.closest&&l.closest("[cms-template], [data-hcms-shell]"))&&(a?a==="value"&&"value"in l?s.push(l.value):s.push(l.getAttribute?l.getAttribute(a):null):s.push((l.textContent||"").trim()),!n))break;return s}function Qe(e,t){if(typeof e!="string"||!e.endsWith("[]")||!t||!t.querySelector)return null;let r=e.slice(0,-2).trim();if(!r)return null;let n=null;try{n=t.querySelector(r)}catch{return null}let i=n&&n.closest?n.closest("[data-hcms-component]"):null;return(i&&i.getAttribute?i.getAttribute("data-hcms-component"):null)==="chips"?{array:"@chips",item:"@chips-item"}:null}function we(e,t,r){let n=e.join("."),i=e.map(o=>typeof o=="number"?"*":o).join(".");return n&&Z(r,n)||i&&i!==n&&Z(r,i)||Z(r,t)}function et(e,t,r){let n=Qe(e,r);if(!n)return null;let i=we(t,n.array,r);return i&&i.getAttribute("data-hcms-tpl")===n.array?n:null}function Or(e,t){if(typeof e!="string")return null;let r=e.lastIndexOf("@"),n=tt($e(e,r),t,"data-hcms-options");if(n==null)return null;let i=n.trim().split(/\s+/).filter(Boolean);return i.length?i:null}function Mr(e,t){if(typeof e!="string")return null;let r=e.lastIndexOf("@");return tt($e(e,r),t,"data-hcms-crop")}function $e(e,t){return t>=0?e.slice(0,t):e}function tt(e,t,r){if(!t||!t.querySelector||!e||e===".")return null;let n=null;try{n=t.querySelector(e)}catch{return null}return n&&n.getAttribute?n.getAttribute(r):null}function rt(e,t){if(!e||t==null)return;r(t);function r(n){let i=ue(n);if(i==="scalar"){let o=De(n,e);Ei.has(o)&&Lt(e,o);return}if(i==="scalar-array"){let o=Qe(n,e);o&&(Lt(e,o.array),Lt(e,o.item));return}if(i==="object"){for(let o of Object.values(n))r(o);return}if(i==="object-array"){let o=n[1];if(o&&typeof o=="object"&&!Array.isArray(o))for(let a of Object.values(o))r(a);else r(o)}}}function Nr(e,t,r){let n=Z(e,r);if(n)return n;let i=e.createElement("template");return i.setAttribute("data-hcms-tpl",r),i.setAttribute("save-remove",""),i.innerHTML=Rr[r].trim(),t.appendChild(i),i}function Z(e,t){return!e||!e.querySelector?null:e.querySelector(`template[data-hcms-tpl="${Oi(t)}"]`)}function Oi(e){return typeof CSS<"u"&&CSS.escape?CSS.escape(e):String(e).replace(/[^a-zA-Z0-9_\-.*]/g,t=>"\\"+t)}function ue(e){return typeof e=="string"?e.endsWith("[]")?"scalar-array":"scalar":Array.isArray(e)?"object-array":typeof e=="object"&&e!==null?"object":"scalar"}function Be(e){return e?!!(e.content||e).querySelector("[data-hcms-field]"):!1}var Ir={IMG:"src",A:"href"};function nt(e){if(!e)return"value";let t=(e.tagName||"").toUpperCase();return t==="INPUT"?(e.getAttribute("type")||"text").toLowerCase()==="checkbox"?"checked":"value":t==="TEXTAREA"||t==="SELECT"?"value":Ir[t]?Ir[t]:e.hasAttribute&&e.hasAttribute("contenteditable")?"innerHTML":null}function Lr(e,t){let r=(e.tagName||"").toUpperCase(),n=(e.getAttribute&&e.getAttribute("type")||"").toLowerCase(),i=nt(e),a=`${Fr(r,n)}[data-hcms-field="${_e(t)}"]`;return r==="INPUT"&&n==="radio"?`${a}:checked@value`:i?`${a}@${i}`:a}function Mi(e){let t=(e.tagName||"").toUpperCase(),r=(e.getAttribute&&e.getAttribute("type")||"").toLowerCase(),n=nt(e),o=`${Fr(t,r)}[data-hcms-field]`;return t==="INPUT"&&r==="radio"?`${o}:checked@value`:n?`${o}@${n}`:o}function Fr(e,t){return e==="INPUT"?t?`input[type="${t}"]`:"input":e==="TEXTAREA"?"textarea":e==="SELECT"?"select":e==="IMG"?"img":e==="A"?"a":':not([data-hcms-shape="scalar"]):not([data-hcms-shape="object"]):not([data-hcms-shape="object-array"]):not([data-hcms-shape="scalar-array"])'}function _e(e){return typeof CSS<"u"&&CSS.escape?CSS.escape(e):String(e).replace(/[^a-zA-Z0-9_\-.*]/g,t=>"\\"+t)}var jr=new Set(["__proto__","constructor","prototype"]);function it(e,t){return r(e,[]);function r(c,m){let d=ue(c);if(d==="scalar")return n(c,m);if(d==="scalar-array")return i(c,m);if(d==="object-array")return o(c,m);if(d==="object"){let h=Object.create(null);for(let[f,k]of Object.entries(c)){if(jr.has(f))throw new Error(`hypercms: rule key "${f}" is forbidden at "${m.join(".")||"<root>"}"`);h[f]=r(k,[...m,f])}return h}return null}function n(c,m){let d=m.length?m[m.length-1]:null,h=typeof d=="string"?d:"__value",f=l(m,h);if(f)return Lr(f,h);let k=s(De(c,t,m),h);return k?Lr(k,h):`input[data-hcms-field="${_e(h)}"]@value`}function i(c,m){let d=et(c,m,t),h=d&&s(d.item,null)||s("@scalar-array-item",null),f=h?Mi(h):"input[data-hcms-field]@value";return[a(m,"[data-hcms-array-item]"),f]}function o(c,m){let[,d]=c,h=[...m,"*"],f=a(m,"[data-hcms-card]");if(d&&typeof d=="object"&&!Array.isArray(d)){let k=Object.create(null);for(let[C,N]of Object.entries(d)){if(jr.has(C))throw new Error(`hypercms: rule key "${C}" is forbidden at "${h.join(".")}"`);k[C]=r(N,[...h,C])}return[f,k]}return[f,r(d,[...h,0])]}function a(c,m){let d=c.length?c[c.length-1]:"",h=c.some(C=>C==="*"),f=c.join(".");return`${h?`[data-hcms-field="${_e(d)}"]`:`[data-hcms-path="${_e(f)}"]`} > .hcms-array-items > ${m}`}function s(c,m){if(!t)return null;let d=Z(t,c);if(!d)return null;let h=d.content||d;if(m){let f=h.querySelector(`[data-hcms-field="${_e(m)}"]`);if(f)return f}return h.querySelector("[data-hcms-field]")}function l(c,m){if(!t)return null;let d=c.map(k=>typeof k=="number"?"*":k).join("."),f=[c.join("."),d];for(let k=c.length-1;k>=0;k--){let C=c.slice(0,k).map(N=>typeof N=="number"?"*":N);C.push("*"),f.push(C.join("."))}for(let k of f){if(!k)continue;let C=Z(t,k);if(!C||!Be(C))continue;let N=C.content||C,D=N.querySelector(`[data-hcms-field="${_e(m)}"]`)||N.querySelector("[data-hcms-field]");if(D)return D}return null}}function jt(e){if(!e)return"";let t=String(e).split(/[?#]/)[0],r=t.split("/").pop()||t;try{return decodeURIComponent(r)}catch{return r}}function ot({pageRules:e,formRules:t,data:r,doc:n}){let i=n.createDocumentFragment(),o=Ft(e,[],r,n);return o&&i.appendChild(o),i}function Dr({shape:e,itemShape:t,pathArr:r,data:n,doc:i,itemKey:o}){if(e==="object-array-item")return Br(t,r,n,i);if(e==="scalar-array-item")return zr(r,n,i,o||null);throw new Error(`hypercms: buildItem called with unknown shape "${e}"`)}function Ft(e,t,r,n){let i=ue(e);return i==="scalar"?Ni(e,t,r,n):i==="object"?Fi(e,t,r,n):i==="object-array"?qi(e,t,r,n):i==="scalar-array"?Di(e,t,r,n):null}function Ni(e,t,r,n){let i=De(e,n,t),o=we(t,i,n);if(!o)throw new Error(`hypercms: missing template for scalar at "${t.join(".")}"`);let a=Tr(e,n);a==="@number"&&i==="@scalar"&&console.info(`[hypercms] field "${t.join(".")}" declares component "@number" but its value isn't a plain number; rendering a text input so the value is preserved`),(a==="@checkbox"||a==="@toggle")&&i==="@scalar"&&console.info(`[hypercms] field "${t.join(".")}" declares component "${a}" but its value isn't true/false; rendering a text input so the value is preserved`),$r(o,a===i?a:null,t);let s=Ae(o,n);Se(s,t);let l=o.getAttribute?.("data-hcms-tpl");if((i==="@select"||i==="@radio")&&l===i&&Ii(s,e,t,r,n,i),i==="@image"&&l==="@image"){let c=Mr(e,n);c!=null&&!s.hasAttribute("data-hcms-crop")&&s.setAttribute("data-hcms-crop",c)}return $i(s,re(t)),st(s,re(t)),at(s,re(t)),Wr(s,r),i==="@file"&&ji(s),s}function $r(e,t,r){if(!t)return;let n=e.getAttribute?.("data-hcms-tpl");n&&n!==t&&console.info(`[hypercms] field "${r.join(".")}" declares component "${t}" but custom template "${n}" wins`)}function Ii(e,t,r,n,i,o){let a=Or(t,i),s=a?[...a]:[],l=n==null?"":String(n);if(l!==""&&!s.includes(l)&&s.unshift(l),!a&&(Li(e,"data-hcms-options required (space-separated values)"),s.length===0)){e.querySelector(".mirk-radio")?.remove();return}if(o==="@select"){let d=e.querySelector("select[data-hcms-field]");if(!d)return;for(let h of s){let f=i.createElement("option");f.value=h,f.textContent=Ze(h),d.appendChild(f)}return}let c=e.querySelector(".mirk-radio");if(!c||!c.parentNode)return;let m=qt(r.join("."));for(let d of s){let h=c.cloneNode(!0),f=h.querySelector('input[type="radio"]');f&&(f.value=d,f.name=m);let k=h.querySelector(".mirk-radio__label");k&&(k.textContent=Ze(d)),c.parentNode.insertBefore(h,c)}c.remove()}function qt(e){return"hcms-"+String(e).replace(/[^A-Za-z0-9_-]/g,"-")}function Li(e,t){let r=e.querySelector?e.querySelector(".hcms-error"):null;r&&(r.textContent=t,r.hidden=!1)}function ji(e){let t=e.querySelector?e.querySelector("a.mirk-file__name[data-hcms-field]"):null;t&&(t.textContent=jt(t.getAttribute("href")))}function Fi(e,t,r,n){let i=we(t,"@object",n);if(!i)throw new Error(`hypercms: missing template for object at "${t.join(".")}"`);let o=Ae(i,n);if(Se(o,t),st(o,re(t)),at(o,re(t)),Be(i))return Gr(o,e,t),Kr(o,e,r),o;let a=lt(o,".hcms-object-fields",i,t);for(let[s,l]of Object.entries(e)){let c=r==null?null:r[s],m=Ft(l,[...t,s],c,n);m&&a.appendChild(m)}return o}function qi(e,t,r,n){let i=we(t,"@object-array",n);if(!i)throw new Error(`hypercms: missing template for object-array at "${t.join(".")}"`);let o=Ae(i,n);Se(o,t),st(o,re(t)),at(o,re(t)),Ur(o,i),Vr(o,i,t);let a=lt(o,".hcms-array-items",i,t),[,s]=e;return(Array.isArray(r)?r:[]).forEach((c,m)=>{let d=Br(s,[...t,m],c,n);d&&a.appendChild(d)}),Hr(o),o}function Br(e,t,r,n){let i=Pr(t,"object-array-item",n);if(!i)throw new Error(`hypercms: missing item template for "${t.join(".")}"`);let o=Ae(i,n);if(o.setAttribute("data-hcms-card",""),o.classList.contains("hcms-card")||o.classList.add("hcms-card"),Se(o,t),Be(i))return e&&typeof e=="object"&&!Array.isArray(e)&&(Gr(o,e,t),Kr(o,e,r)),o;let a=lt(o,".hcms-card-fields",i,t);if(e&&typeof e=="object"&&!Array.isArray(e))for(let[s,l]of Object.entries(e)){let c=r==null?null:r[s],m=Ft(l,[...t,s],c,n);m&&a.appendChild(m)}return o}function Di(e,t,r,n){let i=Qe(e,n),o=et(e,t,n),a=i?i.array:"@scalar-array",s=we(t,a,n);if(!s)throw new Error(`hypercms: missing template for scalar-array at "${t.join(".")}"`);$r(s,i?i.array:null,t);let l=Ae(s,n);Se(l,t),st(l,re(t)),at(l,re(t)),Ur(l,s),Vr(l,s,t),o&&l.setAttribute("data-hcms-item-tpl",o.item);let c=lt(l,".hcms-array-items",s,t);return(Array.isArray(r)?r:[]).forEach((d,h)=>{let f=zr([...t,h],d,n,o?o.item:null);f&&c.appendChild(f)}),Hr(l),l}function zr(e,t,r,n){let i=Pr(e,"scalar-array-item",r,n);if(!i)throw new Error(`hypercms: missing item template for "${e.join(".")}"`);let o=Ae(i,r);return o.setAttribute("data-hcms-array-item",""),o.classList.contains("hcms-array-item")||o.classList.add("hcms-array-item"),Se(o,e),Wr(o,t),o}function Pr(e,t,r,n){let i=e.map(o=>typeof o=="number"?"*":o).join(".");return Z(r,i)||n&&Z(r,n)||Z(r,"@"+t)}function Ae(e,t){let r=e.content||e,n=t.createElement("div");return n.appendChild(r.cloneNode(!0)),n.firstElementChild||n}function Se(e,t){e.setAttribute("data-hcms-path",t.join("."))}function $i(e,t){let r=t==null?"":String(t);if(e.matches&&e.matches("[data-hcms-field]")){e.getAttribute("data-hcms-field")||e.setAttribute("data-hcms-field",r);return}(e.querySelectorAll?e.querySelectorAll("[data-hcms-field]"):[]).forEach(i=>{i.getAttribute("data-hcms-field")||i.setAttribute("data-hcms-field",r)})}function st(e,t){t==null||t===""||!e.setAttribute||e.hasAttribute?.("data-hcms-field")||e.setAttribute("data-hcms-field",String(t))}function at(e,t){if(t==null||t==="")return;(e.querySelectorAll?e.querySelectorAll("[data-hcms-label]"):[]).forEach(n=>{(n.textContent||"").trim()===""&&(n.textContent=Ze(String(t)))})}function Ur(e,t){["data-hcms-no-add","data-hcms-no-remove","data-hcms-no-reorder"].forEach(r=>{t.hasAttribute(r)&&e.setAttribute(r,"")}),["data-hcms-min-items","data-hcms-max-items"].forEach(r=>{t.hasAttribute(r)&&e.setAttribute(r,t.getAttribute(r))})}function Hr(e){let t=e.querySelector?e.querySelector(".hcms-array-items"):null;if(!t)return;let r=Array.from(t.querySelectorAll(":scope > [data-hcms-card], :scope > [data-hcms-array-item]")),n=r.length,i=qr(e,"data-hcms-max-items"),o=qr(e,"data-hcms-min-items"),a=e.hasAttribute("data-hcms-no-add"),s=e.hasAttribute("data-hcms-no-remove"),l=e.hasAttribute("data-hcms-no-reorder"),c=e.querySelector('[data-hcms-action="add"]');c&&(c.hidden=a||i!=null&&n>=i),r.forEach((m,d)=>{let h=m.querySelector('[data-hcms-action="remove"]');h&&(h.hidden=s||o!=null&&n<=o);let f=m.querySelector('[data-hcms-action="move-up"]');f&&(f.hidden=l||d===0);let k=m.querySelector('[data-hcms-action="move-down"]');k&&(k.hidden=l||d===n-1)})}function qr(e,t){if(!e||!e.hasAttribute(t))return null;let r=parseInt(e.getAttribute(t),10);return Number.isFinite(r)?r:null}function Vr(e,t,r){if(e.hasAttribute("data-hcms-no-reorder")||t.hasAttribute("data-hcms-no-reorder"))return;let n=e.querySelector(".hcms-array-items");if(!n)return;let i="hcms-"+r.join(".");n.setAttribute("sortable",i),n.setAttribute("onsorted","hypercmsCommit && hypercmsCommit()")}function re(e){return e.length?e[e.length-1]:null}function Wr(e,t){let r=Bi(e);if(r.length!==0)for(let n of r)Jr(n,t)}function Bi(e){if(!e)return[];let t=[];return e.matches?.("[data-hcms-field]")&&zi(e)&&t.push(e),(e.querySelectorAll?e.querySelectorAll("input[data-hcms-field], textarea[data-hcms-field], select[data-hcms-field], img[data-hcms-field], a[data-hcms-field], [contenteditable][data-hcms-field]"):[]).forEach(n=>t.push(n)),t}function zi(e){let t=(e.tagName||"").toUpperCase();return!!(t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||t==="IMG"||t==="A"||e.hasAttribute?.("contenteditable"))}function Kr(e,t,r){(e.querySelectorAll?e.querySelectorAll("[data-hcms-field]"):[]).forEach(i=>{let o=i.getAttribute("data-hcms-field");if(!o)return;if(!t||typeof t!="object"||!(o in t)){console.warn(`[hypercms] inline template field "${o}" is not in the rule shape; ignoring`);return}let a=r==null?null:r[o];Jr(i,a)})}function Gr(e,t,r){if(!e.querySelectorAll)return;e.querySelectorAll("[data-hcms-field]").forEach(i=>{let o=i.getAttribute("data-hcms-field");if(!o||t&&typeof t=="object"&&!(o in t))return;let a=[...r,o].join(".");i.setAttribute("data-hcms-path",a)})}function lt(e,t,r,n){if(!e.querySelector)return e;let i=e.querySelector(t);if(i)return i;let o=r?.getAttribute?.("data-hcms-tpl")||n.join(".");throw new Error(`hypercms: template "${o}" is in slotted mode but has no ${t} element`)}function Jr(e,t){let r=nt(e),n=(e.tagName||"").toUpperCase(),i=(e.getAttribute("type")||"").toLowerCase();if(n==="INPUT"&&i==="radio"){e.checked=e.value!=null&&String(e.value)===String(t??"");return}if(r==="checked"){e.checked=t===!0||t==="true";return}if(r){e[r]=t==null?"":String(t);return}e.textContent=t==null?"":String(t)}var Yr={skip:"[data-hcms-shell]",templateAttr:"cms-template"};function Zr(e,t,r,n={}){let{observerHandle:i,shellRoot:o,structural:a,structuralPath:s}=n;i?.pause?.();try{if(!a)try{return W.apply(e,t,r,Yr),{ok:!0}}catch(d){return{ok:!1,error:d}}let l=Pi(e,t,s),c=l?Hi(l):null,m=l?null:Wi(e,o);try{return W.apply(e,t,r,Yr),{ok:!0}}catch(d){return c?Vi(l,c):m&&Ki(e,o,m),{ok:!1,error:d}}}finally{i?.resume?.()}}function Pi(e,t,r){if(!r||!e)return null;let n=te(r),i=[],o=t;for(let a of n){if(typeof o=="string"||o==null||Array.isArray(o))break;if(typeof o=="object"&&a in o){if(i.push(a),o=o[a],Array.isArray(o)||typeof o=="string"&&o.endsWith("[]"))break}else return null}return!Array.isArray(o)&&!(typeof o=="string"&&o.endsWith("[]"))?null:Ui(e,t,i)}function Ui(e,t,r){if(r.length===0)return null;let n=e,i=t;for(let o=0;o<r.length;o++){let a=r[o];if(!i||typeof i!="object"||Array.isArray(i))return null;let s=i[a];if(s==null)return null;if(o===r.length-1){if(Array.isArray(s)){let[l]=s;return n.querySelector?.(l)?.parentElement||null}if(typeof s=="string"&&s.endsWith("[]")){let l=s.slice(0,-2);return n.querySelector?.(l)?.parentElement||null}return null}i=s}return null}function Hi(e){let t=[];for(let r of Array.from(e.childNodes))t.push(r.cloneNode(!0));return t}function Vi(e,t){for(;e.firstChild;)e.removeChild(e.firstChild);for(let r of t)e.appendChild(r)}function Wi(e,t){let r=[];for(let n of Array.from(e.childNodes))n===t||t&&n.contains?.(t)||r.push(n.cloneNode(!0));return r}function Ki(e,t,r){for(let i of Array.from(e.childNodes))i===t||t&&i.contains?.(t)||e.removeChild(i);let n=Gi(e,t);for(let i of r)e.insertBefore(i,n||null)}function Gi(e,t){if(!t)return null;for(let r of Array.from(e.childNodes))if(r===t||r.contains?.(t))return r;return null}function ct(e,t){if(!t||e==null)return e;return r(e);function r(n){if(typeof n=="string"){if(n.endsWith("[]")||n.lastIndexOf("@")>=0)return n;let i=null;try{i=t.querySelector(n)}catch{return n}return i&&i.children.length>0?n+"@innerHTML":n}if(Array.isArray(n))return n;if(n&&typeof n=="object"){let i=Object.create(null);for(let[o,a]of Object.entries(n))i[o]=r(a);return i}return n}}function Dt(e){if(!e||e.tagName!=="TEXTAREA")return;let t=e.ownerDocument.defaultView||(typeof window<"u"?window:null);t&&t.CSS&&t.CSS.supports&&t.CSS.supports("field-sizing: content")||(e.style.height="auto",e.style.height=e.scrollHeight+"px")}function Ee(e,t){if(!e||!e.querySelectorAll)return;e.querySelectorAll("textarea[data-hcms-field]").forEach(Dt);let r=t&&t.defaultView||(typeof window<"u"?window:null),n=r&&r.richclay&&r.richclay.RichClay||r&&r.hyperclay&&r.hyperclay.RichClay||(r&&typeof r.RichClay=="function"?r.RichClay:null);n&&e.querySelectorAll("[contenteditable][data-hcms-field]").forEach(i=>{if(i.__hcmsRichclay)return;let o;try{o=new n(i,{inline:!0,hyperclay:!1,toolbar:["bold","italic","link","undo","redo"]})}catch(s){console.warn("[hypercms] richclay activation failed; field stays plain contenteditable",s);return}i.__hcmsRichclay=o;let a=o&&o.squire;a&&typeof a.addEventListener=="function"&&a.addEventListener("input",()=>{let s=r&&r.Event||Event;i.dispatchEvent(new s("input",{bubbles:!0}))})})}var $t=new WeakSet;function Re(e,t){let r=typeof window<"u"&&window.hyperclay&&window.hyperclay.undo||null;if(!r)return t();r.pause();try{let n=t();return n&&n.ok?r.commitCaptured(e):r.discardCaptured(),n}finally{r.resume()}}function ut(e){let t=typeof window<"u"&&window.hyperclay&&window.hyperclay.undo||null;if(!t)return e();t.pause();try{return e()}finally{t.discardCaptured(),t.resume()}}function en(e){let{formRoot:t}=e;if(!t||$t.has(t))return;$t.add(t);let r=a=>{let s=a.target;!s||!s.closest||s.closest("[data-hcms-form-root]")&&s.matches("input, textarea, select, [contenteditable][data-hcms-field]")&&(s.tagName==="TEXTAREA"&&Dt(s),!s.matches('input[type="file"]')&&(!s.closest("[data-hcms-field]")&&!s.hasAttribute?.("data-hcms-field")||Xr(s,e)))},n=a=>{let s=a.target;if(!(!s||!s.closest)&&s.closest("[data-hcms-form-root]")){if(s.matches('input[type="file"][data-hcms-upload]')){to(s,e);return}s.matches('input[type="checkbox"], input[type="radio"], select')&&Xr(s,e)}},i=a=>{let s=a.target;if(!s||!s.closest)return;let l=s.closest("[data-hcms-action]");if(!l)return;let c=l.getAttribute("data-hcms-action");if(c==="add"||c==="remove"||c==="move-up"||c==="move-down"||c==="clear-upload"){if(!l.closest("[data-hcms-form-root]"))return}else if(c==="close"&&!l.closest("[data-hcms-shell]"))return;if(c==="add"){let m=l.closest("[data-hcms-path]");if(!m)return;let d=m.getAttribute("data-hcms-path");Bt(d,e)}else if(c==="remove"){let m=l.closest("[data-hcms-card], [data-hcms-array-item]");if(!m)return;ao(m,e)}else if(c==="move-up"||c==="move-down"){let m=l.closest("[data-hcms-card], [data-hcms-array-item]");if(!m)return;oo(m,c==="move-up"?-1:1,e)}else c==="clear-upload"?ro(l,e):c==="close"&&e.onCloseRequested?.()},o=t.ownerDocument;o.addEventListener("input",r,!0),o.addEventListener("change",n,!0),o.addEventListener("click",i,!0),e.detachEvents=()=>{o.removeEventListener("input",r,!0),o.removeEventListener("change",n,!0),o.removeEventListener("click",i,!0),$t.delete(t)}}var Ji=new Set(["value","checked"]);function Yi(e,t){if(!t)return null;let r=te(t);if(r.some(l=>typeof l=="number"||l==="*"))return null;let n=me(e.pageRules,r);if(typeof n!="string")return null;let i=n.lastIndexOf("@");if(i===-1)return null;let o=n.slice(i+1);if(!Ji.has(o))return null;let a=n.slice(0,i),s=a?e.pageRoot.querySelector(a):e.pageRoot;return s?{el:s,prop:o,oldValue:s[o]}:null}function Xr(e,t){let n=(e.closest("[data-hcms-field]")||e).closest("[data-hcms-path]")?.getAttribute("data-hcms-path")||"",i=Yi(t,n);if(ee(Y(t),{path:n,structural:!1},t),i){let o=typeof window<"u"&&window.hyperclay&&window.hyperclay.undo||null;o&&typeof o.recordValue=="function"&&o.recordValue(i.el,{prop:i.prop,oldValue:i.oldValue,newValue:i.el[i.prop]})}}var Zi={type:"image/webp",quality:.85,maxWidth:2048,maxHeight:2048};async function Xi(e,t){let r=t&&t.getAttribute?t.getAttribute("data-hcms-crop"):null;if(r==null)return{file:e};let n=typeof window<"u"&&window.hyperclay&&window.hyperclay.quickcrop||null;if(typeof n!="function")return{file:e};try{let i=await n(e,{aspect:Qi(r),...Zi});return i===null?null:{file:eo(i.blob,e.name),dataURL:i.dataURL}}catch(i){return ze(t,i&&i.message||"Crop failed"),null}}function Qi(e){let t=String(e??"").trim().toLowerCase();if(t===""||t==="free")return null;let r=t.match(/^(\d+(?:\.\d+)?)\s*[:/]\s*(\d+(?:\.\d+)?)$/);if(!r)return null;let n=parseFloat(r[1]),i=parseFloat(r[2]);return!n||!i?null:n/i}function eo(e,t){let r=e.type==="image/webp"?".webp":e.type==="image/jpeg"?".jpg":".png",n=String(t||"image").replace(/\.[^.]+$/,"");try{return new File([e],n+r,{type:e.type})}catch{return e}}async function to(e,t){let r=e.files&&e.files[0];if(!r)return;let n=e.closest("[data-hcms-path]");if(!n)return;let i=n.getAttribute("data-hcms-path")||"";ze(n,null);let o=await Xi(r,n);if(!o||t.closed){he(e);return}let a=o.file,s=o.dataURL||null,l=typeof window<"u"&&window.hyperclay&&window.hyperclay.uploadFileBasic||null,c=null;if(typeof l=="function")try{let m=await l(a);c=m&&m.uploads&&m.uploads[0]&&m.uploads[0].url}catch(m){if(t.closed){he(e);return}ze(n,m&&m.message||"Upload failed"),t.dispatch?.("hcms:error",{error:m,path:i}),he(e);return}if(t.closed){he(e);return}if(c||(c=s||io(a)),!c){he(e);return}ze(n,null),tn(n,c,a.name),ee(Y(t),{path:i,structural:!1},t),he(e)}function ro(e,t){let r=e.closest("[data-hcms-path]");if(!r)return;let n=r.getAttribute("data-hcms-path")||"";tn(r,"","");let i=r.querySelector('input[type="file"][data-hcms-upload]');i&&he(i),ze(r,null),ee(Y(t),{path:n,structural:!1},t)}function no(e){return e.querySelector?e.querySelector("img[data-hcms-field], a[data-hcms-field]"):null}function tn(e,t,r){let n=no(e);if(!n)return;let i=(n.tagName||"").toUpperCase();i==="IMG"?n.src=t||"":i==="A"&&(n.href=t||"",n.textContent=t?r||jt(t):"")}function he(e){try{e.value=""}catch{}}function io(e){let t=typeof URL<"u"&&URL.createObjectURL?URL:null;if(!t)return"";try{return t.createObjectURL(e)}catch{return""}}function ze(e,t){let r=e.querySelector?e.querySelector(":scope > .hcms-error"):null;r&&(t?(r.textContent=t,r.hidden=!1):(r.textContent="",r.hidden=!0))}function Bt(e,t){let{formRoot:r,pageRules:n}=t,i=r.querySelector(`[data-hcms-path="${fo(e)}"]`);if(!i)throw new Error(`hypercms: no element at path "${e}"`);let o=i.querySelector(".hcms-array-items");if(!o)throw new Error(`hypercms: array container missing .hcms-array-items at "${e}"`);let a=te(e),s=uo(n,a),l=Array.isArray(s),c=typeof s=="string"&&s.endsWith("[]");if(!l&&!c)throw new Error(`hypercms: path "${e}" is not an array`);let m=mt(i,"data-hcms-max-items"),d=o.querySelectorAll(":scope > [data-hcms-card], :scope > [data-hcms-array-item]");if(i.hasAttribute("data-hcms-no-add")||m!=null&&d.length>=m)return;let h=d.length,f=l?s[1]:s.replace(/\[\]$/,""),k=qe(l?f:"string"),C=Dr({shape:l?"object-array-item":"scalar-array-item",itemShape:f,pathArr:[...a,h],data:k,doc:t.doc,itemKey:i.getAttribute("data-hcms-item-tpl")||null});return o.appendChild(C),Ee(C,t.doc),Pt(i),Re(`Add ${e}`,()=>ee(Y(t),{path:e,structural:!0},t))}function oo(e,t,r){let n=e.closest('[data-hcms-shape="object-array"], [data-hcms-shape="scalar-array"]');if(!n||n.hasAttribute("data-hcms-no-reorder"))return;let i=n.querySelector(".hcms-array-items");if(!i)return;let o=Array.from(i.querySelectorAll(":scope > [data-hcms-card], :scope > [data-hcms-array-item]")),a=o.indexOf(e);if(a<0)return;let s=a+t;if(s<0||s>=o.length)return;let l=e.querySelector(`[data-hcms-action="${t<0?"move-up":"move-down"}"]`);return t<0?i.insertBefore(e,o[s]):i.insertBefore(e,o[s].nextSibling),Ht(i),Pt(n),l&&typeof l.focus=="function"&&e.querySelector(`[data-hcms-action="${t<0?"move-up":"move-down"}"]`)?.focus?.(),Re(`Reorder ${n.getAttribute("data-hcms-path")||""}`,()=>ee(Y(r),{path:n.getAttribute("data-hcms-path")||"",structural:!0},r))}var dt="Delete this item?";function so(e,t){let r=e&&e.getAttribute("data-hcms-confirm-remove");if(r!=null)return/^(off|false|no|0)$/i.test(r.trim())?null:r||dt;let n=t&&t.confirmRemove;return n===!1?null:typeof n=="string"?n||dt:n===!0||e&&e.getAttribute("data-hcms-shape")==="object-array"?dt:null}function ao(e,t){let r=e.closest('[data-hcms-shape="object-array"], [data-hcms-shape="scalar-array"]'),n=so(r,t);if(n==null)return Ce(e,t);let i=typeof window<"u"&&(window.hyperclay?.consent||window.consent);typeof i=="function"?Promise.resolve(i(n)).then(()=>Ce(e,t),()=>{}):typeof window<"u"&&typeof window.confirm=="function"?window.confirm(n)&&Ce(e,t):Ce(e,t)}function Ce(e,t){let r=e.getAttribute("data-hcms-path")||"",n=e.parentElement,i=e.closest('[data-hcms-shape="object-array"], [data-hcms-shape="scalar-array"]');if(!i?.hasAttribute("data-hcms-no-remove")){if(i){let o=mt(i,"data-hcms-min-items"),a=i.querySelector(".hcms-array-items"),s=a?a.querySelectorAll(":scope > [data-hcms-card], :scope > [data-hcms-array-item]").length:0;if(o!=null&&s<=o)return}return e.remove(),n&&Ht(n),i&&Pt(i),Re(`Remove ${r}`,()=>ee(Y(t),{path:r,structural:!0},t))}}function ee(e,t,r){let n=Pe(e);if(n===r.lastFingerprint)return{ok:!0,skipped:!0};let i=Zr(r.pageRoot,r.pageRules,e,{observerHandle:r.observerHandle,shellRoot:r.shellRoot,structural:!!t.structural,structuralPath:t.path||null});return i.ok?(r.lastFingerprint=n,r.lastData=e,Qr(r,null),r.dispatch?.("hcms:change",{data:e,path:t.path,structural:!!t.structural}),r.onChange?.(e,t)):(Qr(r,mo(i.error,t.path)),r.dispatch?.("hcms:error",{error:i.error,attemptedData:e}),r.onError?.(i.error)),i}function Y(e){let t=W.extract(e.formRoot,e.formRules);return ae(t,e.formRules)}function ae(e,t){if(t==null||e==null)return e;if(typeof t=="string")return t.endsWith("@checked")?e===!0||e==="true":e;if(Array.isArray(t)){if(!Array.isArray(e))return e;let[,r]=t;return e.map(n=>ae(n,r))}if(typeof t=="object"){if(typeof e!="object"||Array.isArray(e))return e;let r={};for(let[n,i]of Object.entries(t))r[n]=ae(e[n],i);return r}return e}function Qr(e,t){e.lastErrors=t&&t.length?t:null,zt(e)}function zt(e){if(lo(e),e.errorEl&&(e.errorEl.textContent="",e.errorEl.hidden=!0),!e.lastErrors)return;let t=[];for(let{message:r,path:n}of e.lastErrors){if(n!=null&&n!==""){let i=co(e.formRoot,n);if(i){i.textContent=i.textContent?`${i.textContent}
150
+ `},qi=["@scalar","@object","@scalar-array","@scalar-array-item","@object-array","@object-array-item"];function et(e){let t=e.head||e.documentElement;if(t)for(let r of qi)Br(e,t,r)}function $t(e,t){if(!Fr[t])return null;let r=e&&(e.head||e.documentElement);return r?Br(e,r,t):null}var jr={src:"@image",checked:"@checkbox",innerHTML:"@richtext"},Ze={image:"@image",file:"@file",checkbox:"@checkbox",toggle:"@toggle",select:"@select",radio:"@radio",textarea:"@textarea",number:"@number",richtext:"@richtext"},Di=new Set([...Object.values(Ze),"@chips","@chips-item"]);function $e(e,t,r){if(typeof e!="string")return"@scalar";let n=e.lastIndexOf("@"),i=nt(Be(e,n),t,"data-hcms-component");if(i&&Ze[i]){let o=Ze[i],a=Array.isArray(r)&&r.some(s=>s==="*"||typeof s=="number");return o==="@number"&&!Lr(e,n,t,a).every(Bi)||(o==="@checkbox"||o==="@toggle")&&(n<0||e.slice(n+1)!=="checked")&&!Lr(e,n,t,a).every(Pi)?"@scalar":o}if(n>=0){let o=e.slice(n+1);if(jr[o])return jr[o]}return"@scalar"}function qr(e,t){if(typeof e!="string")return null;let r=e.lastIndexOf("@"),n=nt(Be(e,r),t,"data-hcms-component");return n&&Ze[n]||null}var $i=/^-?\d+(\.\d+)?([eE][+-]?\d+)?$/;function Bi(e){return e==null||e===""?!0:$i.test(String(e))}function Pi(e){return e==null||e===""||e==="true"||e==="false"}function Lr(e,t,r,n){if(!r||!r.querySelectorAll)return[];let i=Be(e,t);if(!i||i===".")return[];let o=null;try{o=r.querySelectorAll(i)}catch{return[]}let a=t>=0?e.slice(t+1):null,s=[];for(let l of o)if(!(l.closest&&l.closest("[cms-template], [data-hcms-shell]"))&&(a?a==="value"&&"value"in l?s.push(l.value):s.push(l.getAttribute?l.getAttribute(a):null):s.push((l.textContent||"").trim()),!n))break;return s}function tt(e,t){if(typeof e!="string"||!e.endsWith("[]")||!t||!t.querySelector)return null;let r=e.slice(0,-2).trim();if(!r)return null;let n=null;try{n=t.querySelector(r)}catch{return null}let i=n&&n.closest?n.closest("[data-hcms-component]"):null;return(i&&i.getAttribute?i.getAttribute("data-hcms-component"):null)==="chips"?{array:"@chips",item:"@chips-item"}:null}function _e(e,t,r){let n=e.join("."),i=e.map(o=>typeof o=="number"?"*":o).join(".");return n&&Z(r,n)||i&&i!==n&&Z(r,i)||Z(r,t)}function rt(e,t,r){let n=tt(e,r);if(!n)return null;let i=_e(t,n.array,r);return i&&i.getAttribute("data-hcms-tpl")===n.array?n:null}function Dr(e,t){if(typeof e!="string")return null;let r=e.lastIndexOf("@"),n=nt(Be(e,r),t,"data-hcms-options");if(n==null)return null;let i=n.trim().split(/\s+/).filter(Boolean);return i.length?i:null}function $r(e,t){if(typeof e!="string")return null;let r=e.lastIndexOf("@");return nt(Be(e,r),t,"data-hcms-crop")}function Be(e,t){return t>=0?e.slice(0,t):e}function nt(e,t,r){if(!t||!t.querySelector||!e||e===".")return null;let n=null;try{n=t.querySelector(e)}catch{return null}return n&&n.getAttribute?n.getAttribute(r):null}function it(e,t){if(!e||t==null)return;r(t);function r(n){let i=he(n);if(i==="scalar"){let o=$e(n,e);Di.has(o)&&$t(e,o);return}if(i==="scalar-array"){let o=tt(n,e);o&&($t(e,o.array),$t(e,o.item));return}if(i==="object"){for(let o of Object.values(n))r(o);return}if(i==="object-array"){let o=n[1];if(o&&typeof o=="object"&&!Array.isArray(o))for(let a of Object.values(o))r(a);else r(o)}}}function Br(e,t,r){let n=Z(e,r);if(n)return n;let i=e.createElement("template");return i.setAttribute("data-hcms-tpl",r),i.setAttribute("save-remove",""),i.innerHTML=Fr[r].trim(),t.appendChild(i),i}function Z(e,t){return!e||!e.querySelector?null:e.querySelector(`template[data-hcms-tpl="${zi(t)}"]`)}function zi(e){return typeof CSS<"u"&&CSS.escape?CSS.escape(e):String(e).replace(/[^a-zA-Z0-9_\-.*]/g,t=>"\\"+t)}function he(e){return typeof e=="string"?e.endsWith("[]")?"scalar-array":"scalar":Array.isArray(e)?"object-array":typeof e=="object"&&e!==null?"object":"scalar"}function Pe(e){return e?!!(e.content||e).querySelector("[data-hcms-field]"):!1}var Pr={IMG:"src",A:"href"};function ot(e){if(!e)return"value";let t=(e.tagName||"").toUpperCase();return t==="INPUT"?(e.getAttribute("type")||"text").toLowerCase()==="checkbox"?"checked":"value":t==="TEXTAREA"||t==="SELECT"?"value":Pr[t]?Pr[t]:e.hasAttribute&&e.hasAttribute("contenteditable")?"innerHTML":null}function zr(e,t){let r=(e.tagName||"").toUpperCase(),n=(e.getAttribute&&e.getAttribute("type")||"").toLowerCase(),i=ot(e),a=`${Hr(r,n)}[data-hcms-field="${Ae(t)}"]`;return r==="INPUT"&&n==="radio"?`${a}:checked@value`:i?`${a}@${i}`:a}function Ui(e){let t=(e.tagName||"").toUpperCase(),r=(e.getAttribute&&e.getAttribute("type")||"").toLowerCase(),n=ot(e),o=`${Hr(t,r)}[data-hcms-field]`;return t==="INPUT"&&r==="radio"?`${o}:checked@value`:n?`${o}@${n}`:o}function Hr(e,t){return e==="INPUT"?t?`input[type="${t}"]`:"input":e==="TEXTAREA"?"textarea":e==="SELECT"?"select":e==="IMG"?"img":e==="A"?"a":':not([data-hcms-shape="scalar"]):not([data-hcms-shape="object"]):not([data-hcms-shape="object-array"]):not([data-hcms-shape="scalar-array"])'}function Ae(e){return typeof CSS<"u"&&CSS.escape?CSS.escape(e):String(e).replace(/[^a-zA-Z0-9_\-.*]/g,t=>"\\"+t)}var Ur=new Set(["__proto__","constructor","prototype"]);function st(e,t){return r(e,[]);function r(c,u){let p=he(c);if(p==="scalar")return n(c,u);if(p==="scalar-array")return i(c,u);if(p==="object-array")return o(c,u);if(p==="object"){let d=Object.create(null);for(let[f,k]of Object.entries(c)){if(Ur.has(f))throw new Error(`hypercms: rule key "${f}" is forbidden at "${u.join(".")||"<root>"}"`);d[f]=r(k,[...u,f])}return d}return null}function n(c,u){let p=u.length?u[u.length-1]:null,d=typeof p=="string"?p:"__value",f=l(u,d);if(f)return zr(f,d);let k=s($e(c,t,u),d);return k?zr(k,d):`input[data-hcms-field="${Ae(d)}"]@value`}function i(c,u){let p=rt(c,u,t),d=p&&s(p.item,null)||s("@scalar-array-item",null),f=d?Ui(d):"input[data-hcms-field]@value";return[a(u,"[data-hcms-array-item]"),f]}function o(c,u){let[,p]=c,d=[...u,"*"],f=a(u,"[data-hcms-card]");if(p&&typeof p=="object"&&!Array.isArray(p)){let k=Object.create(null);for(let[T,M]of Object.entries(p)){if(Ur.has(T))throw new Error(`hypercms: rule key "${T}" is forbidden at "${d.join(".")}"`);k[T]=r(M,[...d,T])}return[f,k]}return[f,r(p,[...d,0])]}function a(c,u){let p=c.length?c[c.length-1]:"",d=c.some(T=>T==="*"),f=c.join(".");return`${d?`[data-hcms-field="${Ae(p)}"]`:`[data-hcms-path="${Ae(f)}"]`} > .hcms-array-items > ${u}`}function s(c,u){if(!t)return null;let p=Z(t,c);if(!p)return null;let d=p.content||p;if(u){let f=d.querySelector(`[data-hcms-field="${Ae(u)}"]`);if(f)return f}return d.querySelector("[data-hcms-field]")}function l(c,u){if(!t)return null;let p=c.map(k=>typeof k=="number"?"*":k).join("."),f=[c.join("."),p];for(let k=c.length-1;k>=0;k--){let T=c.slice(0,k).map(M=>typeof M=="number"?"*":M);T.push("*"),f.push(T.join("."))}for(let k of f){if(!k)continue;let T=Z(t,k);if(!T||!Pe(T))continue;let M=T.content||T,F=M.querySelector(`[data-hcms-field="${Ae(u)}"]`)||M.querySelector("[data-hcms-field]");if(F)return F}return null}}function Bt(e){if(!e)return"";let t=String(e).split(/[?#]/)[0],r=t.split("/").pop()||t;try{return decodeURIComponent(r)}catch{return r}}function at({pageRules:e,formRules:t,data:r,doc:n}){let i=n.createDocumentFragment(),o=Pt(e,[],r,n);return o&&i.appendChild(o),i}function Wr({shape:e,itemShape:t,pathArr:r,data:n,doc:i,itemKey:o}){if(e==="object-array-item")return Gr(t,r,n,i);if(e==="scalar-array-item")return Jr(r,n,i,o||null);throw new Error(`hypercms: buildItem called with unknown shape "${e}"`)}function Pt(e,t,r,n){let i=he(e);return i==="scalar"?Hi(e,t,r,n):i==="object"?Gi(e,t,r,n):i==="object-array"?Ji(e,t,r,n):i==="scalar-array"?Yi(e,t,r,n):null}function Hi(e,t,r,n){let i=$e(e,n,t),o=_e(t,i,n);if(!o)throw new Error(`hypercms: missing template for scalar at "${t.join(".")}"`);let a=qr(e,n);a==="@number"&&i==="@scalar"&&console.info(`[hypercms] field "${t.join(".")}" declares component "@number" but its value isn't a plain number; rendering a text input so the value is preserved`),(a==="@checkbox"||a==="@toggle")&&i==="@scalar"&&console.info(`[hypercms] field "${t.join(".")}" declares component "${a}" but its value isn't true/false; rendering a text input so the value is preserved`),Kr(o,a===i?a:null,t);let s=Se(o,n);Ee(s,t);let l=o.getAttribute?.("data-hcms-tpl");if((i==="@select"||i==="@radio")&&l===i&&Vi(s,e,t,r,n,i),i==="@image"&&l==="@image"){let c=$r(e,n);c!=null&&!s.hasAttribute("data-hcms-crop")&&s.setAttribute("data-hcms-crop",c)}return Xi(s,ie(t)),lt(s,ie(t)),ct(s,ie(t)),en(s,r),i==="@file"&&Ki(s),s}function Kr(e,t,r){if(!t)return;let n=e.getAttribute?.("data-hcms-tpl");n&&n!==t&&console.info(`[hypercms] field "${r.join(".")}" declares component "${t}" but custom template "${n}" wins`)}function Vi(e,t,r,n,i,o){let a=Dr(t,i),s=a?[...a]:[],l=n==null?"":String(n);if(l!==""&&!s.includes(l)&&s.unshift(l),!a&&(Wi(e,"data-hcms-options required (space-separated values)"),s.length===0)){e.querySelector(".mirk-radio")?.remove();return}if(o==="@select"){let p=e.querySelector("select[data-hcms-field]");if(!p)return;for(let d of s){let f=i.createElement("option");f.value=d,f.textContent=Qe(d),p.appendChild(f)}return}let c=e.querySelector(".mirk-radio");if(!c||!c.parentNode)return;let u=zt(r.join("."));for(let p of s){let d=c.cloneNode(!0),f=d.querySelector('input[type="radio"]');f&&(f.value=p,f.name=u);let k=d.querySelector(".mirk-radio__label");k&&(k.textContent=Qe(p)),c.parentNode.insertBefore(d,c)}c.remove()}function zt(e){return"hcms-"+String(e).replace(/[^A-Za-z0-9_-]/g,"-")}function Wi(e,t){let r=e.querySelector?e.querySelector(".hcms-error"):null;r&&(r.textContent=t,r.hidden=!1)}function Ki(e){let t=e.querySelector?e.querySelector("a.mirk-file__name[data-hcms-field]"):null;t&&(t.textContent=Bt(t.getAttribute("href")))}function Gi(e,t,r,n){let i=_e(t,"@object",n);if(!i)throw new Error(`hypercms: missing template for object at "${t.join(".")}"`);let o=Se(i,n);if(Ee(o,t),lt(o,ie(t)),ct(o,ie(t)),Pe(i))return rn(o,e,t),tn(o,e,r),o;let a=dt(o,".hcms-object-fields",i,t);for(let[s,l]of Object.entries(e)){let c=r==null?null:r[s],u=Pt(l,[...t,s],c,n);u&&a.appendChild(u)}return o}function Ji(e,t,r,n){let i=_e(t,"@object-array",n);if(!i)throw new Error(`hypercms: missing template for object-array at "${t.join(".")}"`);let o=Se(i,n);Ee(o,t),lt(o,ie(t)),ct(o,ie(t)),Xr(o,i),Qr(o,i,t);let a=dt(o,".hcms-array-items",i,t),[,s]=e;return(Array.isArray(r)?r:[]).forEach((c,u)=>{let p=Gr(s,[...t,u],c,n);p&&a.appendChild(p)}),Zr(o),o}function Gr(e,t,r,n){let i=Yr(t,"object-array-item",n);if(!i)throw new Error(`hypercms: missing item template for "${t.join(".")}"`);let o=Se(i,n);if(o.setAttribute("data-hcms-card",""),o.classList.contains("hcms-card")||o.classList.add("hcms-card"),Ee(o,t),Pe(i))return e&&typeof e=="object"&&!Array.isArray(e)&&(rn(o,e,t),tn(o,e,r)),o;let a=dt(o,".hcms-card-fields",i,t);if(e&&typeof e=="object"&&!Array.isArray(e))for(let[s,l]of Object.entries(e)){let c=r==null?null:r[s],u=Pt(l,[...t,s],c,n);u&&a.appendChild(u)}return o}function Yi(e,t,r,n){let i=tt(e,n),o=rt(e,t,n),a=i?i.array:"@scalar-array",s=_e(t,a,n);if(!s)throw new Error(`hypercms: missing template for scalar-array at "${t.join(".")}"`);Kr(s,i?i.array:null,t);let l=Se(s,n);Ee(l,t),lt(l,ie(t)),ct(l,ie(t)),Xr(l,s),Qr(l,s,t),o&&l.setAttribute("data-hcms-item-tpl",o.item);let c=dt(l,".hcms-array-items",s,t);return(Array.isArray(r)?r:[]).forEach((p,d)=>{let f=Jr([...t,d],p,n,o?o.item:null);f&&c.appendChild(f)}),Zr(l),l}function Jr(e,t,r,n){let i=Yr(e,"scalar-array-item",r,n);if(!i)throw new Error(`hypercms: missing item template for "${e.join(".")}"`);let o=Se(i,r);return o.setAttribute("data-hcms-array-item",""),o.classList.contains("hcms-array-item")||o.classList.add("hcms-array-item"),Ee(o,e),en(o,t),o}function Yr(e,t,r,n){let i=e.map(o=>typeof o=="number"?"*":o).join(".");return Z(r,i)||n&&Z(r,n)||Z(r,"@"+t)}function Se(e,t){let r=e.content||e,n=t.createElement("div");return n.appendChild(r.cloneNode(!0)),n.firstElementChild||n}function Ee(e,t){e.setAttribute("data-hcms-path",t.join("."))}function Xi(e,t){let r=t==null?"":String(t);if(e.matches&&e.matches("[data-hcms-field]")){e.getAttribute("data-hcms-field")||e.setAttribute("data-hcms-field",r);return}(e.querySelectorAll?e.querySelectorAll("[data-hcms-field]"):[]).forEach(i=>{i.getAttribute("data-hcms-field")||i.setAttribute("data-hcms-field",r)})}function lt(e,t){t==null||t===""||!e.setAttribute||e.hasAttribute?.("data-hcms-field")||e.setAttribute("data-hcms-field",String(t))}function ct(e,t){if(t==null||t==="")return;(e.querySelectorAll?e.querySelectorAll("[data-hcms-label]"):[]).forEach(n=>{(n.textContent||"").trim()===""&&(n.textContent=Qe(String(t)))})}function Xr(e,t){["data-hcms-no-add","data-hcms-no-remove","data-hcms-no-reorder"].forEach(r=>{t.hasAttribute(r)&&e.setAttribute(r,"")}),["data-hcms-min-items","data-hcms-max-items"].forEach(r=>{t.hasAttribute(r)&&e.setAttribute(r,t.getAttribute(r))})}function Zr(e){let t=e.querySelector?e.querySelector(".hcms-array-items"):null;if(!t)return;let r=Array.from(t.querySelectorAll(":scope > [data-hcms-card], :scope > [data-hcms-array-item]")),n=r.length,i=Vr(e,"data-hcms-max-items"),o=Vr(e,"data-hcms-min-items"),a=e.hasAttribute("data-hcms-no-add"),s=e.hasAttribute("data-hcms-no-remove"),l=e.hasAttribute("data-hcms-no-reorder"),c=e.querySelector('[data-hcms-action="add"]');c&&(c.hidden=a||i!=null&&n>=i),r.forEach((u,p)=>{let d=u.querySelector('[data-hcms-action="remove"]');d&&(d.hidden=s||o!=null&&n<=o);let f=u.querySelector('[data-hcms-action="move-up"]');f&&(f.hidden=l||p===0);let k=u.querySelector('[data-hcms-action="move-down"]');k&&(k.hidden=l||p===n-1)})}function Vr(e,t){if(!e||!e.hasAttribute(t))return null;let r=parseInt(e.getAttribute(t),10);return Number.isFinite(r)?r:null}function Qr(e,t,r){if(e.hasAttribute("data-hcms-no-reorder")||t.hasAttribute("data-hcms-no-reorder"))return;let n=e.querySelector(".hcms-array-items");if(!n)return;let i="hcms-"+r.join(".");n.setAttribute("sortable",i),n.setAttribute("onsorted","hypercmsCommit && hypercmsCommit()")}function ie(e){return e.length?e[e.length-1]:null}function en(e,t){let r=Zi(e);if(r.length!==0)for(let n of r)nn(n,t)}function Zi(e){if(!e)return[];let t=[];return e.matches?.("[data-hcms-field]")&&Qi(e)&&t.push(e),(e.querySelectorAll?e.querySelectorAll("input[data-hcms-field], textarea[data-hcms-field], select[data-hcms-field], img[data-hcms-field], a[data-hcms-field], [contenteditable][data-hcms-field]"):[]).forEach(n=>t.push(n)),t}function Qi(e){let t=(e.tagName||"").toUpperCase();return!!(t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||t==="IMG"||t==="A"||e.hasAttribute?.("contenteditable"))}function tn(e,t,r){(e.querySelectorAll?e.querySelectorAll("[data-hcms-field]"):[]).forEach(i=>{let o=i.getAttribute("data-hcms-field");if(!o)return;if(!t||typeof t!="object"||!(o in t)){console.warn(`[hypercms] inline template field "${o}" is not in the rule shape; ignoring`);return}let a=r==null?null:r[o];nn(i,a)})}function rn(e,t,r){if(!e.querySelectorAll)return;e.querySelectorAll("[data-hcms-field]").forEach(i=>{let o=i.getAttribute("data-hcms-field");if(!o||t&&typeof t=="object"&&!(o in t))return;let a=[...r,o].join(".");i.setAttribute("data-hcms-path",a)})}function dt(e,t,r,n){if(!e.querySelector)return e;let i=e.querySelector(t);if(i)return i;let o=r?.getAttribute?.("data-hcms-tpl")||n.join(".");throw new Error(`hypercms: template "${o}" is in slotted mode but has no ${t} element`)}function nn(e,t){let r=ot(e),n=(e.tagName||"").toUpperCase(),i=(e.getAttribute("type")||"").toLowerCase();if(n==="INPUT"&&i==="radio"){e.checked=e.value!=null&&String(e.value)===String(t??"");return}if(r==="checked"){e.checked=t===!0||t==="true";return}if(r){e[r]=t==null?"":String(t);return}e.textContent=t==null?"":String(t)}var on={skip:"[data-hcms-shell]",templateAttr:"cms-template"};function sn(e,t,r,n={}){let{observerHandle:i,shellRoot:o,structural:a,structuralPath:s}=n;i?.pause?.();try{if(!a)try{return K.apply(e,t,r,on),{ok:!0}}catch(p){return{ok:!1,error:p}}let l=eo(e,t,s),c=l?ro(l):null,u=l?null:io(e,o);try{return K.apply(e,t,r,on),{ok:!0}}catch(p){return c?no(l,c):u&&oo(e,o,u),{ok:!1,error:p}}}finally{i?.resume?.()}}function eo(e,t,r){if(!r||!e)return null;let n=ne(r),i=[],o=t;for(let a of n){if(typeof o=="string"||o==null||Array.isArray(o))break;if(typeof o=="object"&&a in o){if(i.push(a),o=o[a],Array.isArray(o)||typeof o=="string"&&o.endsWith("[]"))break}else return null}return!Array.isArray(o)&&!(typeof o=="string"&&o.endsWith("[]"))?null:to(e,t,i)}function to(e,t,r){if(r.length===0)return null;let n=e,i=t;for(let o=0;o<r.length;o++){let a=r[o];if(!i||typeof i!="object"||Array.isArray(i))return null;let s=i[a];if(s==null)return null;if(o===r.length-1){if(Array.isArray(s)){let[l]=s;return n.querySelector?.(l)?.parentElement||null}if(typeof s=="string"&&s.endsWith("[]")){let l=s.slice(0,-2);return n.querySelector?.(l)?.parentElement||null}return null}i=s}return null}function ro(e){let t=[];for(let r of Array.from(e.childNodes))t.push(r.cloneNode(!0));return t}function no(e,t){for(;e.firstChild;)e.removeChild(e.firstChild);for(let r of t)e.appendChild(r)}function io(e,t){let r=[];for(let n of Array.from(e.childNodes))n===t||t&&n.contains?.(t)||r.push(n.cloneNode(!0));return r}function oo(e,t,r){for(let i of Array.from(e.childNodes))i===t||t&&i.contains?.(t)||e.removeChild(i);let n=so(e,t);for(let i of r)e.insertBefore(i,n||null)}function so(e,t){if(!t)return null;for(let r of Array.from(e.childNodes))if(r===t||r.contains?.(t))return r;return null}var ao={Mutation:(e,t)=>e?.Mutation??t?.Mutation,undo:(e,t)=>e?.undo??t?.undo,onPrepareForSave:(e,t)=>e?.addDocumentTransform??t?.onPrepareForSave,consent:(e,t)=>e?.confirm??t?.consent,RichClay:(e,t)=>e?.RichClay??t?.RichClay,quickcrop:(e,t)=>e?.quickcrop??t?.quickcrop,uploadFileBasic:(e,t)=>e?.uploadFileBasic??t?.uploadFileBasic};function W(e,t){let r=ao[e];if(!r)throw new Error(`hypercms: unknown platform capability "${e}"`);let n=t||(typeof window<"u"?window:null);return n&&r(n.clay,n.hyperclay)||null}var an=["clay:mutation-ready","hyperclay:mutation-ready"],ln=["clay:sync-applied","hyperclay:livesync-applied"];function Ut(e,t,r){let n=null,i=o=>{n!==null&&n!==o.type||(n=o.type,queueMicrotask(()=>{n=null}),r(o))};for(let o of t)e.addEventListener(o,i);return()=>{for(let o of t)e.removeEventListener(o,i)}}function mt(e,t){if(!t||e==null)return e;return r(e);function r(n){if(typeof n=="string"){if(n.endsWith("[]")||n.lastIndexOf("@")>=0)return n;let i=null;try{i=t.querySelector(n)}catch{return n}return i&&i.children.length>0?n+"@innerHTML":n}if(Array.isArray(n))return n;if(n&&typeof n=="object"){let i=Object.create(null);for(let[o,a]of Object.entries(n))i[o]=r(a);return i}return n}}function Ht(e){if(!e||e.tagName!=="TEXTAREA")return;let t=e.ownerDocument.defaultView||(typeof window<"u"?window:null);t&&t.CSS&&t.CSS.supports&&t.CSS.supports("field-sizing: content")||(e.style.height="auto",e.style.height=e.scrollHeight+"px")}function Ce(e,t){if(!e||!e.querySelectorAll)return;e.querySelectorAll("textarea[data-hcms-field]").forEach(Ht);let r=t&&t.defaultView||(typeof window<"u"?window:null),n=r&&r.richclay&&r.richclay.RichClay||W("RichClay",r)||(r&&typeof r.RichClay=="function"?r.RichClay:null);n&&e.querySelectorAll("[contenteditable][data-hcms-field]").forEach(i=>{if(i.__hcmsRichclay)return;let o;try{o=new n(i,{inline:!0,hyperclay:!1,toolbar:["bold","italic","link","undo","redo"]})}catch(s){console.warn("[hypercms] richclay activation failed; field stays plain contenteditable",s);return}i.__hcmsRichclay=o;let a=o&&o.squire;a&&typeof a.addEventListener=="function"&&a.addEventListener("input",()=>{let s=r&&r.Event||Event;i.dispatchEvent(new s("input",{bubbles:!0}))})})}var Vt=new WeakSet;function Re(e,t){let r=W("undo");if(!r)return t();r.pause();try{let n=t();return n&&n.ok?r.commitCaptured(e):r.discardCaptured(),n}finally{r.resume()}}function pt(e){let t=W("undo");if(!t)return e();t.pause();try{return e()}finally{t.discardCaptured(),t.resume()}}function mn(e){let{formRoot:t}=e;if(!t||Vt.has(t))return;Vt.add(t);let r=a=>{let s=a.target;!s||!s.closest||s.closest("[data-hcms-form-root]")&&s.matches("input, textarea, select, [contenteditable][data-hcms-field]")&&(s.tagName==="TEXTAREA"&&Ht(s),!s.matches('input[type="file"]')&&(!s.closest("[data-hcms-field]")&&!s.hasAttribute?.("data-hcms-field")||cn(s,e)))},n=a=>{let s=a.target;if(!(!s||!s.closest)&&s.closest("[data-hcms-form-root]")){if(s.matches('input[type="file"][data-hcms-upload]')){fo(s,e);return}s.matches('input[type="checkbox"], input[type="radio"], select')&&cn(s,e)}},i=a=>{let s=a.target;if(!s||!s.closest)return;let l=s.closest("[data-hcms-action]");if(!l)return;let c=l.getAttribute("data-hcms-action");if(c==="add"||c==="remove"||c==="move-up"||c==="move-down"||c==="clear-upload"){if(!l.closest("[data-hcms-form-root]"))return}else if(c==="close"&&!l.closest("[data-hcms-shell]"))return;if(c==="add"){let u=l.closest("[data-hcms-path]");if(!u)return;let p=u.getAttribute("data-hcms-path");Wt(p,e)}else if(c==="remove"){let u=l.closest("[data-hcms-card], [data-hcms-array-item]");if(!u)return;xo(u,e)}else if(c==="move-up"||c==="move-down"){let u=l.closest("[data-hcms-card], [data-hcms-array-item]");if(!u)return;yo(u,c==="move-up"?-1:1,e)}else c==="clear-upload"?go(l,e):c==="close"&&e.onCloseRequested?.()},o=t.ownerDocument;o.addEventListener("input",r,!0),o.addEventListener("change",n,!0),o.addEventListener("click",i,!0),e.detachEvents=()=>{o.removeEventListener("input",r,!0),o.removeEventListener("change",n,!0),o.removeEventListener("click",i,!0),Vt.delete(t)}}var lo=new Set(["value","checked"]);function co(e,t){if(!t)return null;let r=ne(t);if(r.some(l=>typeof l=="number"||l==="*"))return null;let n=ue(e.pageRules,r);if(typeof n!="string")return null;let i=n.lastIndexOf("@");if(i===-1)return null;let o=n.slice(i+1);if(!lo.has(o))return null;let a=n.slice(0,i),s=a?e.pageRoot.querySelector(a):e.pageRoot;return s?{el:s,prop:o,oldValue:s[o]}:null}function cn(e,t){let n=(e.closest("[data-hcms-field]")||e).closest("[data-hcms-path]")?.getAttribute("data-hcms-path")||"",i=co(t,n);if(re(X(t),{path:n,structural:!1},t),i){let o=W("undo");o&&typeof o.recordValue=="function"&&o.recordValue(i.el,{prop:i.prop,oldValue:i.oldValue,newValue:i.el[i.prop]})}}var mo={type:"image/webp",quality:.85,maxWidth:2048,maxHeight:2048};async function uo(e,t){let r=t&&t.getAttribute?t.getAttribute("data-hcms-crop"):null;if(r==null)return{file:e};let n=W("quickcrop");if(typeof n!="function")return{file:e};try{let i=await n(e,{aspect:ho(r),...mo});return i===null?null:{file:po(i.blob,e.name),dataURL:i.dataURL}}catch(i){return ze(t,i&&i.message||"Crop failed"),null}}function ho(e){let t=String(e??"").trim().toLowerCase();if(t===""||t==="free")return null;let r=t.match(/^(\d+(?:\.\d+)?)\s*[:/]\s*(\d+(?:\.\d+)?)$/);if(!r)return null;let n=parseFloat(r[1]),i=parseFloat(r[2]);return!n||!i?null:n/i}function po(e,t){let r=e.type==="image/webp"?".webp":e.type==="image/jpeg"?".jpg":".png",n=String(t||"image").replace(/\.[^.]+$/,"");try{return new File([e],n+r,{type:e.type})}catch{return e}}async function fo(e,t){let r=e.files&&e.files[0];if(!r)return;let n=e.closest("[data-hcms-path]");if(!n)return;let i=n.getAttribute("data-hcms-path")||"";ze(n,null);let o=await uo(r,n);if(!o||t.closed){pe(e);return}let a=o.file,s=o.dataURL||null,l=W("uploadFileBasic"),c=null;if(typeof l=="function")try{let u=await l(a);c=u&&u.uploads&&u.uploads[0]&&u.uploads[0].url}catch(u){if(t.closed){pe(e);return}ze(n,u&&u.message||"Upload failed"),t.dispatch?.("hcms:error",{error:u,path:i}),pe(e);return}if(t.closed){pe(e);return}if(c||(c=s||ko(a)),!c){pe(e);return}ze(n,null),un(n,c,a.name),re(X(t),{path:i,structural:!1},t),pe(e)}function go(e,t){let r=e.closest("[data-hcms-path]");if(!r)return;let n=r.getAttribute("data-hcms-path")||"";un(r,"","");let i=r.querySelector('input[type="file"][data-hcms-upload]');i&&pe(i),ze(r,null),re(X(t),{path:n,structural:!1},t)}function bo(e){return e.querySelector?e.querySelector("img[data-hcms-field], a[data-hcms-field]"):null}function un(e,t,r){let n=bo(e);if(!n)return;let i=(n.tagName||"").toUpperCase();i==="IMG"?n.src=t||"":i==="A"&&(n.href=t||"",n.textContent=t?r||Bt(t):"")}function pe(e){try{e.value=""}catch{}}function ko(e){let t=typeof URL<"u"&&URL.createObjectURL?URL:null;if(!t)return"";try{return t.createObjectURL(e)}catch{return""}}function ze(e,t){let r=e.querySelector?e.querySelector(":scope > .hcms-error"):null;r&&(t?(r.textContent=t,r.hidden=!1):(r.textContent="",r.hidden=!0))}function Wt(e,t){let{formRoot:r,pageRules:n}=t,i=r.querySelector(`[data-hcms-path="${To(e)}"]`);if(!i)throw new Error(`hypercms: no element at path "${e}"`);let o=i.querySelector(".hcms-array-items");if(!o)throw new Error(`hypercms: array container missing .hcms-array-items at "${e}"`);let a=ne(e),s=So(n,a),l=Array.isArray(s),c=typeof s=="string"&&s.endsWith("[]");if(!l&&!c)throw new Error(`hypercms: path "${e}" is not an array`);let u=ht(i,"data-hcms-max-items"),p=o.querySelectorAll(":scope > [data-hcms-card], :scope > [data-hcms-array-item]");if(i.hasAttribute("data-hcms-no-add")||u!=null&&p.length>=u)return;let d=p.length,f=l?s[1]:s.replace(/\[\]$/,""),k=De(l?f:"string"),T=Wr({shape:l?"object-array-item":"scalar-array-item",itemShape:f,pathArr:[...a,d],data:k,doc:t.doc,itemKey:i.getAttribute("data-hcms-item-tpl")||null});return o.appendChild(T),Ce(T,t.doc),Gt(i),Re(`Add ${e}`,()=>re(X(t),{path:e,structural:!0},t))}function yo(e,t,r){let n=e.closest('[data-hcms-shape="object-array"], [data-hcms-shape="scalar-array"]');if(!n||n.hasAttribute("data-hcms-no-reorder"))return;let i=n.querySelector(".hcms-array-items");if(!i)return;let o=Array.from(i.querySelectorAll(":scope > [data-hcms-card], :scope > [data-hcms-array-item]")),a=o.indexOf(e);if(a<0)return;let s=a+t;if(s<0||s>=o.length)return;let l=e.querySelector(`[data-hcms-action="${t<0?"move-up":"move-down"}"]`);return t<0?i.insertBefore(e,o[s]):i.insertBefore(e,o[s].nextSibling),Yt(i),Gt(n),l&&typeof l.focus=="function"&&e.querySelector(`[data-hcms-action="${t<0?"move-up":"move-down"}"]`)?.focus?.(),Re(`Reorder ${n.getAttribute("data-hcms-path")||""}`,()=>re(X(r),{path:n.getAttribute("data-hcms-path")||"",structural:!0},r))}var ut="Delete this item?";function vo(e,t){let r=e&&e.getAttribute("data-hcms-confirm-remove");if(r!=null)return/^(off|false|no|0)$/i.test(r.trim())?null:r||ut;let n=t&&t.confirmRemove;return n===!1?null:typeof n=="string"?n||ut:n===!0||e&&e.getAttribute("data-hcms-shape")==="object-array"?ut:null}function xo(e,t){let r=e.closest('[data-hcms-shape="object-array"], [data-hcms-shape="scalar-array"]'),n=vo(r,t);if(n==null)return Te(e,t);let i=W("consent")||typeof window<"u"&&window.consent;typeof i=="function"?Promise.resolve(i(n)).then(()=>Te(e,t),()=>{}):typeof window<"u"&&typeof window.confirm=="function"?window.confirm(n)&&Te(e,t):Te(e,t)}function Te(e,t){let r=e.getAttribute("data-hcms-path")||"",n=e.parentElement,i=e.closest('[data-hcms-shape="object-array"], [data-hcms-shape="scalar-array"]');if(!i?.hasAttribute("data-hcms-no-remove")){if(i){let o=ht(i,"data-hcms-min-items"),a=i.querySelector(".hcms-array-items"),s=a?a.querySelectorAll(":scope > [data-hcms-card], :scope > [data-hcms-array-item]").length:0;if(o!=null&&s<=o)return}return e.remove(),n&&Yt(n),i&&Gt(i),Re(`Remove ${r}`,()=>re(X(t),{path:r,structural:!0},t))}}function re(e,t,r){let n=Ue(e);if(n===r.lastFingerprint)return{ok:!0,skipped:!0};let i=sn(r.pageRoot,r.pageRules,e,{observerHandle:r.observerHandle,shellRoot:r.shellRoot,structural:!!t.structural,structuralPath:t.path||null});return i.ok?(r.lastFingerprint=n,r.lastData=e,dn(r,null),r.dispatch?.("hcms:change",{data:e,path:t.path,structural:!!t.structural}),r.onChange?.(e,t)):(dn(r,Ao(i.error,t.path)),r.dispatch?.("hcms:error",{error:i.error,attemptedData:e}),r.onError?.(i.error)),i}function X(e){let t=K.extract(e.formRoot,e.formRules);return le(t,e.formRules)}function le(e,t){if(t==null||e==null)return e;if(typeof t=="string")return t.endsWith("@checked")?e===!0||e==="true":e;if(Array.isArray(t)){if(!Array.isArray(e))return e;let[,r]=t;return e.map(n=>le(n,r))}if(typeof t=="object"){if(typeof e!="object"||Array.isArray(e))return e;let r={};for(let[n,i]of Object.entries(t))r[n]=le(e[n],i);return r}return e}function dn(e,t){e.lastErrors=t&&t.length?t:null,Kt(e)}function Kt(e){if(wo(e),e.errorEl&&(e.errorEl.textContent="",e.errorEl.hidden=!0),!e.lastErrors)return;let t=[];for(let{message:r,path:n}of e.lastErrors){if(n!=null&&n!==""){let i=_o(e.formRoot,n);if(i){i.textContent=i.textContent?`${i.textContent}
151
151
  ${r}`:r,i.hidden=!1;continue}}t.push(r)}t.length&&e.errorEl&&(e.errorEl.textContent=t.join(`
152
- `),e.errorEl.hidden=!1)}function lo(e){if(e.formRoot)for(let t of e.formRoot.querySelectorAll(".hcms-error"))t.textContent="",t.hidden=!0}function co(e,t){if(!e)return null;let r=t.split(".");for(;r.length>0;){let n=r.join("."),i=typeof CSS<"u"&&CSS.escape?CSS.escape(n):n.replace(/[^a-zA-Z0-9_\-.*]/g,a=>"\\"+a),o=e.querySelector(`[data-hcms-path="${i}"]`);if(o){for(let a of o.children)if(a.classList&&a.classList.contains("hcms-error"))return a}r.pop()}return null}function mo(e,t){return e?e.name==="EmptyListInsert"?[{message:"Add a seed item in HTML first.",path:t}]:e.name==="ShapeMismatch"&&Array.isArray(e.mismatches)&&e.mismatches.length?e.mismatches.map(r=>({message:`Shape mismatch: expected ${r.expected}, got ${r.got}`,path:r.path})):[{message:e.message||String(e),path:t}]:[{message:"unknown error",path:t}]}function uo(e,t){let r=e;for(let n of t){if(r==null||typeof r=="string")return;if(Array.isArray(r)){if(typeof n!="number"&&n!=="*")return;r=r[1];continue}if(typeof r=="object"){if(typeof n=="number"||!(n in r))return;r=r[n];continue}return}return r}function mt(e,t){if(!e||!e.hasAttribute(t))return null;let r=parseInt(e.getAttribute(t),10);return Number.isFinite(r)?r:null}function Pt(e){if(!e)return;let t=e.querySelector(".hcms-array-items");if(!t)return;let r=Array.from(t.querySelectorAll(":scope > [data-hcms-card], :scope > [data-hcms-array-item]")),n=r.length,i=mt(e,"data-hcms-max-items"),o=mt(e,"data-hcms-min-items"),a=e.hasAttribute("data-hcms-no-add"),s=e.hasAttribute("data-hcms-no-remove"),l=e.hasAttribute("data-hcms-no-reorder"),c=e.querySelector(':scope > .hcms-add, :scope > * > .hcms-add, :scope > [data-hcms-action="add"]');c&&(c.hidden=a||i!=null&&n>=i),r.forEach((m,d)=>{let h=m.querySelector('[data-hcms-action="remove"]');h&&(h.hidden=s||o!=null&&n<=o);let f=m.querySelector('[data-hcms-action="move-up"]');f&&(f.hidden=l||d===0);let k=m.querySelector('[data-hcms-action="move-down"]');k&&(k.hidden=l||d===n-1)})}function Ut(e){!e||!e.querySelectorAll||e.querySelectorAll(".hcms-array-items").forEach(t=>Ht(t))}function Ht(e){let t=e.querySelectorAll?Array.from(e.querySelectorAll('input[type="radio"][data-hcms-field]'),n=>[n,n.checked]):[],r=0;for(let n of e.children){if(!n.matches?.("[data-hcms-card], [data-hcms-array-item]"))continue;let i=n.getAttribute("data-hcms-path");if(!i)continue;let o=i.split(".");o[o.length-1]=String(r);let a=o.join(".");a!==i&&ho(n,i,a),r++}for(let[n,i]of t)n.checked!==i&&(n.checked=i)}function ho(e,t,r){let n=e.querySelectorAll("[data-hcms-path]");e.setAttribute("data-hcms-path",r);for(let i of n){let o=i.getAttribute("data-hcms-path");o===t?i.setAttribute("data-hcms-path",r):o&&o.startsWith(t+".")&&i.setAttribute("data-hcms-path",r+o.slice(t.length))}po(e)}function po(e){for(let t of e.querySelectorAll('input[type="radio"][data-hcms-field]')){if(!t.name||!t.name.startsWith("hcms-"))continue;let r=t.closest("[data-hcms-path]");r&&(t.name=qt(r.getAttribute("data-hcms-path")))}}function Pe(e){return JSON.stringify(e,(t,r)=>{if(r&&typeof r=="object"&&!Array.isArray(r)){let n=Object.create(null);for(let i of Object.keys(r).sort())n[i]=r[i];return n}return r})}function fo(e){return typeof CSS<"u"&&CSS.escape?CSS.escape(e):String(e).replace(/[^a-zA-Z0-9_\-.*]/g,t=>"\\"+t)}var wo={},ht="hcms-shell-styles",go="hcms-bundled-styles-installed",bo='a[href], area[href], button:not([disabled]), input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])',Te=new WeakSet,Vt="";function nn(e){Vt=e}var ko=0;function rn(e){return String(e).replace(/[&<>"]/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[t])}function on({mountTo:e,side:t="right",overlay:r=!1,showSaveButton:n=!1,title:i="Page content",eyebrow:o="Edit",theme:a=null,doc:s}){sn(s);let l=`hcms-shell-title-${++ko}`,c=s.createElement("div");c.setAttribute("data-hcms-shell",""),c.setAttribute("save-remove",""),c.setAttribute("save-ignore",""),c.setAttribute("tabindex","-1"),c.setAttribute("role","dialog"),c.setAttribute("aria-modal","true"),c.setAttribute("aria-labelledby",l);let m=a==="dark"?" dark":a==="light"?" light":"";c.className="hcms-shell pixel-quiet hcms-side-"+t+(r?" hcms-overlay":"")+m;let d=rn(i),h=rn(o);c.innerHTML=`
152
+ `),e.errorEl.hidden=!1)}function wo(e){if(e.formRoot)for(let t of e.formRoot.querySelectorAll(".hcms-error"))t.textContent="",t.hidden=!0}function _o(e,t){if(!e)return null;let r=t.split(".");for(;r.length>0;){let n=r.join("."),i=typeof CSS<"u"&&CSS.escape?CSS.escape(n):n.replace(/[^a-zA-Z0-9_\-.*]/g,a=>"\\"+a),o=e.querySelector(`[data-hcms-path="${i}"]`);if(o){for(let a of o.children)if(a.classList&&a.classList.contains("hcms-error"))return a}r.pop()}return null}function Ao(e,t){return e?e.name==="EmptyListInsert"?[{message:"Add a seed item in HTML first.",path:t}]:e.name==="ShapeMismatch"&&Array.isArray(e.mismatches)&&e.mismatches.length?e.mismatches.map(r=>({message:`Shape mismatch: expected ${r.expected}, got ${r.got}`,path:r.path})):[{message:e.message||String(e),path:t}]:[{message:"unknown error",path:t}]}function So(e,t){let r=e;for(let n of t){if(r==null||typeof r=="string")return;if(Array.isArray(r)){if(typeof n!="number"&&n!=="*")return;r=r[1];continue}if(typeof r=="object"){if(typeof n=="number"||!(n in r))return;r=r[n];continue}return}return r}function ht(e,t){if(!e||!e.hasAttribute(t))return null;let r=parseInt(e.getAttribute(t),10);return Number.isFinite(r)?r:null}function Gt(e){if(!e)return;let t=e.querySelector(".hcms-array-items");if(!t)return;let r=Array.from(t.querySelectorAll(":scope > [data-hcms-card], :scope > [data-hcms-array-item]")),n=r.length,i=ht(e,"data-hcms-max-items"),o=ht(e,"data-hcms-min-items"),a=e.hasAttribute("data-hcms-no-add"),s=e.hasAttribute("data-hcms-no-remove"),l=e.hasAttribute("data-hcms-no-reorder"),c=e.querySelector(':scope > .hcms-add, :scope > * > .hcms-add, :scope > [data-hcms-action="add"]');c&&(c.hidden=a||i!=null&&n>=i),r.forEach((u,p)=>{let d=u.querySelector('[data-hcms-action="remove"]');d&&(d.hidden=s||o!=null&&n<=o);let f=u.querySelector('[data-hcms-action="move-up"]');f&&(f.hidden=l||p===0);let k=u.querySelector('[data-hcms-action="move-down"]');k&&(k.hidden=l||p===n-1)})}function Jt(e){!e||!e.querySelectorAll||e.querySelectorAll(".hcms-array-items").forEach(t=>Yt(t))}function Yt(e){let t=e.querySelectorAll?Array.from(e.querySelectorAll('input[type="radio"][data-hcms-field]'),n=>[n,n.checked]):[],r=0;for(let n of e.children){if(!n.matches?.("[data-hcms-card], [data-hcms-array-item]"))continue;let i=n.getAttribute("data-hcms-path");if(!i)continue;let o=i.split(".");o[o.length-1]=String(r);let a=o.join(".");a!==i&&Eo(n,i,a),r++}for(let[n,i]of t)n.checked!==i&&(n.checked=i)}function Eo(e,t,r){let n=e.querySelectorAll("[data-hcms-path]");e.setAttribute("data-hcms-path",r);for(let i of n){let o=i.getAttribute("data-hcms-path");o===t?i.setAttribute("data-hcms-path",r):o&&o.startsWith(t+".")&&i.setAttribute("data-hcms-path",r+o.slice(t.length))}Co(e)}function Co(e){for(let t of e.querySelectorAll('input[type="radio"][data-hcms-field]')){if(!t.name||!t.name.startsWith("hcms-"))continue;let r=t.closest("[data-hcms-path]");r&&(t.name=zt(r.getAttribute("data-hcms-path")))}}function Ue(e){return JSON.stringify(e,(t,r)=>{if(r&&typeof r=="object"&&!Array.isArray(r)){let n=Object.create(null);for(let i of Object.keys(r).sort())n[i]=r[i];return n}return r})}function To(e){return typeof CSS<"u"&&CSS.escape?CSS.escape(e):String(e).replace(/[^a-zA-Z0-9_\-.*]/g,t=>"\\"+t)}var Lo={},ft="hcms-shell-styles",Ro="hcms-bundled-styles-installed",Oo='a[href], area[href], button:not([disabled]), input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])',Oe=new WeakSet,Xt="";function pn(e){Xt=e}var Mo=0;function hn(e){return String(e).replace(/[&<>"]/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[t])}function fn({mountTo:e,side:t="right",overlay:r=!1,showSaveButton:n=!1,title:i="Page content",eyebrow:o="Edit",theme:a=null,doc:s}){gn(s);let l=`hcms-shell-title-${++Mo}`,c=s.createElement("div");c.setAttribute("data-hcms-shell",""),c.setAttribute("save-remove",""),c.setAttribute("save-ignore",""),c.setAttribute("tabindex","-1"),c.setAttribute("role","dialog"),c.setAttribute("aria-modal","true"),c.setAttribute("aria-labelledby",l);let u=a==="dark"?" dark":a==="light"?" light":"";c.className="hcms-shell pixel-quiet hcms-side-"+t+(r?" hcms-overlay":"")+u;let p=hn(i),d=hn(o);c.innerHTML=`
153
153
  <div class="hcms-shell-minibar" aria-hidden="true">
154
- <span class="hcms-shell-minibar-title">${d}</span>
154
+ <span class="hcms-shell-minibar-title">${p}</span>
155
155
  <button type="button" class="hcms-shell-close mirk-button mirk-button--small" data-hcms-action="close" aria-label="Close">
156
156
  <span class="mirk-button__label">\xD7</span>
157
157
  </button>
@@ -159,13 +159,14 @@ ${r}`:r,i.hidden=!1;continue}}t.push(r)}t.length&&e.errorEl&&(e.errorEl.textCont
159
159
  <div class="hcms-shell-body">
160
160
  <header class="hcms-shell-header">
161
161
  <div class="hcms-shell-heading">
162
- <div class="hcms-shell-eyebrow">${h}</div>
163
- <h2 class="hcms-shell-title" id="${l}">${d}</h2>
162
+ <div class="hcms-shell-eyebrow">${d}</div>
163
+ <h2 class="hcms-shell-title" id="${l}">${p}</h2>
164
164
  </div>
165
165
  <button type="button" class="hcms-shell-close mirk-button mirk-button--small" data-hcms-action="close" aria-label="Close">
166
166
  <span class="mirk-button__label">\xD7</span>
167
167
  </button>
168
168
  </header>
169
+ <div class="hcms-shell-notice" role="status" hidden></div>
169
170
  <div class="hcms-shell-error" role="alert" hidden></div>
170
171
  <div data-hcms-form-root class="hcms-form"></div>
171
172
  <footer class="hcms-shell-footer"${n?"":" hidden"}>
@@ -174,7 +175,7 @@ ${r}`:r,i.hidden=!1;continue}}t.push(r)}t.length&&e.errorEl&&(e.errorEl.textCont
174
175
  </button>
175
176
  </footer>
176
177
  </div>
177
- `,(e||s.body).appendChild(c);let k=s.body;k.classList.add("hcms-open"),r&&k.classList.add("hcms-overlay"),t==="left"&&k.classList.add("hcms-side-left");let C=xo(c,s),N=vo(c);return{root:c,formRoot:c.querySelector("[data-hcms-form-root]"),errorEl:c.querySelector(".hcms-shell-error"),saveButton:c.querySelector(".hcms-shell-save"),destroy(){C.detach(),N.detach(),c.remove(),k.classList.remove("hcms-open","hcms-overlay","hcms-side-left")},restoreChrome(){yo(s),k.classList.add("hcms-open"),r&&k.classList.add("hcms-overlay"),t==="left"&&k.classList.add("hcms-side-left")}}}function yo(e){e&&(e.getElementById(ht)||e.querySelector("style[data-hcms-bundled-styles]")||(Te.delete(e),sn(e)))}function sn(e){if(e&&!Te.has(e)){if(e[go]){Te.add(e);return}if(e.getElementById(ht)||e.querySelector("style[data-hcms-bundled-styles]")){Te.add(e);return}if(Vt){let t=e.createElement("style");t.id=ht,t.setAttribute("save-remove",""),t.setAttribute("save-ignore",""),t.textContent=Vt,(e.head||e.documentElement).appendChild(t),Te.add(e);return}try{let t=new URL("./theme.generated.css",wo.url).href,r=e.createElement("link");r.rel="stylesheet",r.id=ht,r.setAttribute("save-remove",""),r.setAttribute("save-ignore",""),r.href=t,(e.head||e.documentElement).appendChild(r),Te.add(e)}catch{console.warn("hypercms: shell stylesheet not applied \u2014 cssText is empty and the co-located theme fallback is unavailable. Call installStyles(themeText) before opening the CMS.")}}}function vo(e){let t=e.querySelector(".hcms-shell-body"),r=e.querySelector(".hcms-shell-header");if(!t||!r||typeof t.addEventListener!="function")return{detach(){}};let n=()=>{let i=(r.offsetHeight||0)-12;e.classList.toggle("is-condensed",t.scrollTop>i)};return t.addEventListener("scroll",n,{passive:!0}),n(),{detach(){t.removeEventListener("scroll",n)}}}function xo(e,t){function r(n){if(n.key!=="Tab"||!e.contains(t.activeElement))return;let i=Array.from(e.querySelectorAll(bo));if(i.length===0)return;let o=i[0],a=i[i.length-1];n.shiftKey&&t.activeElement===o?(n.preventDefault(),a.focus()):!n.shiftKey&&t.activeElement===a&&(n.preventDefault(),o.focus())}return t.addEventListener("keydown",r),{detach:()=>t.removeEventListener("keydown",r)}}var _o={skip:"[data-hcms-shell]",templateAttr:"cms-template"};function pt(e,{ignoreActiveValue:t}={}){let r=W.findRules(e.doc,e.rulesSource||"cms");r&&(e.pageRules=e.richText?ct(r.rules,e.pageRoot):r.rules,e.rulesTagNode=r.tagNode),Xe(e.doc),rt(e.doc,e.pageRules),e.formRules=it(e.pageRules,e.doc);let n=ae(W.extract(e.pageRoot,e.pageRules,_o),e.pageRules),i=ot({pageRules:e.pageRules,formRules:e.formRules,data:n,doc:e.doc});Je(e.formRoot,i,{ignoreActiveValue:t}),Ee(e.formRoot,e.doc),zt(e),e.updateFingerprint&&e.updateFingerprint()}function an({debounce:e=100,onRefresh:t}){let r=typeof window<"u"&&window.hyperclay&&window.hyperclay.Mutation||null;if(!r||typeof r.onAnyChange!="function")throw new Error("hypercms: window.hyperclay.Mutation is required. Load hyperclayjs (or just the mutation utility) before initializing hypercms.");let n=0,i=r.onAnyChange({debounce:e},()=>{n>0||t()});return{unsubscribe:typeof i=="function"?i:()=>{},pause(){n++},resume(){n=Math.max(0,n-1)}}}var Ao="[hypercms]";function ln(e,t){if(!e||!e.querySelectorAll||!t)return;let r=So(t);e.querySelectorAll("template[data-hcms-tpl]").forEach(i=>{let o=i.getAttribute("data-hcms-tpl");o&&(o.startsWith("@")||r.has(o)||console.warn(`${Ao} template "${o}" doesn't match any rule path; ignored`))})}function So(e){let t=new Set;return r([],e),t;function r(n,i){let o=n.join("."),a=n.map(l=>typeof l=="number"?"*":l).join(".");o&&t.add(o),a&&t.add(a);let s=ue(i);if(s==="object")for(let[l,c]of Object.entries(i))r([...n,l],c);else if(s==="object-array"||s==="scalar-array"){let l=[...n,"*"],c=l.map(m=>typeof m=="number"?"*":m).join(".");if(t.add(c),s==="object-array"){let m=i[1];if(m&&typeof m=="object"&&!Array.isArray(m))for(let[d,h]of Object.entries(m))r([...l,d],h)}}}}var cn="hcms-toggle",dn="hcms-toggle-style",Eo=`
178
+ `,(e||s.body).appendChild(c);let k=s.body;k.classList.add("hcms-open"),r&&k.classList.add("hcms-overlay"),t==="left"&&k.classList.add("hcms-side-left");let T=jo(c,s),M=Io(c);return{root:c,formRoot:c.querySelector("[data-hcms-form-root]"),noticeEl:c.querySelector(".hcms-shell-notice"),errorEl:c.querySelector(".hcms-shell-error"),saveButton:c.querySelector(".hcms-shell-save"),destroy(){T.detach(),M.detach(),c.remove(),k.classList.remove("hcms-open","hcms-overlay","hcms-side-left")},restoreChrome(){No(s),k.classList.add("hcms-open"),r&&k.classList.add("hcms-overlay"),t==="left"&&k.classList.add("hcms-side-left")}}}function No(e){e&&(e.getElementById(ft)||e.querySelector("style[data-hcms-bundled-styles]")||(Oe.delete(e),gn(e)))}function gn(e){if(e&&!Oe.has(e)){if(e[Ro]){Oe.add(e);return}if(e.getElementById(ft)||e.querySelector("style[data-hcms-bundled-styles]")){Oe.add(e);return}if(Xt){let t=e.createElement("style");t.id=ft,t.setAttribute("save-remove",""),t.setAttribute("save-ignore",""),t.textContent=Xt,(e.head||e.documentElement).appendChild(t),Oe.add(e);return}try{let t=new URL("./theme.generated.css",Lo.url).href,r=e.createElement("link");r.rel="stylesheet",r.id=ft,r.setAttribute("save-remove",""),r.setAttribute("save-ignore",""),r.href=t,(e.head||e.documentElement).appendChild(r),Oe.add(e)}catch{console.warn("hypercms: shell stylesheet not applied \u2014 cssText is empty and the co-located theme fallback is unavailable. Call installStyles(themeText) before opening the CMS.")}}}function Io(e){let t=e.querySelector(".hcms-shell-body"),r=e.querySelector(".hcms-shell-header");if(!t||!r||typeof t.addEventListener!="function")return{detach(){}};let n=()=>{let i=(r.offsetHeight||0)-12;e.classList.toggle("is-condensed",t.scrollTop>i)};return t.addEventListener("scroll",n,{passive:!0}),n(),{detach(){t.removeEventListener("scroll",n)}}}function jo(e,t){function r(n){if(n.key!=="Tab"||!e.contains(t.activeElement))return;let i=Array.from(e.querySelectorAll(Oo));if(i.length===0)return;let o=i[0],a=i[i.length-1];n.shiftKey&&t.activeElement===o?(n.preventDefault(),a.focus()):!n.shiftKey&&t.activeElement===a&&(n.preventDefault(),o.focus())}return t.addEventListener("keydown",r),{detach:()=>t.removeEventListener("keydown",r)}}var Fo="[hypercms]",bn={skip:"[data-hcms-shell]",templateAttr:"cms-template"},kn={skip:"[data-hcms-shell]",templateAttr:null},Zt=class extends Error{constructor(t,r,n){super(`hypercms: rule at "${t}" has an invalid CSS selector: "${r}"`),this.name="InvalidRuleSelector",this.path=t,this.selector=r,this.cause=n}};function bt(e,t){let r=[],n=[];return Qt(e,t,[],r,n),{missing:Bo(r),twins:Po(n)}}function Qt(e,t,r,n,i){if(typeof t=="string"){let o=qo(t);if(!o)return;let a=gt(e,o,bn,r);if(t.endsWith("[]")){a.length===0&&gt(e,o,kn,r).length===0&&n.push(He(r));return}a.length===0?n.push(He(r)):a.length>1&&i.push({path:He(r),count:a.length});return}if(Array.isArray(t)){let[o,a]=t;if(typeof o!="string"||!o)return;let s=gt(e,o,bn,r);if(s.length===0){gt(e,o,kn,r).length===0&&n.push(He(r));return}for(let l of s)Qt(l,a,[...r,"*"],n,i);return}if(t&&typeof t=="object")for(let[o,a]of Object.entries(t))Qt(e,a,[...r,o],n,i)}function gt(e,t,r,n){try{return te.find(e,t,r)}catch(i){throw new Zt(He(n),t,i)}}function qo(e){if(e==="."||e.startsWith("@"))return null;if(e.endsWith("[]"))return e.slice(0,-2)||null;let t=e.lastIndexOf("@");return(t===-1?e:e.slice(0,t))||null}function kt(e){Do(e),$o(e)}function Do(e){let t=e.noticeEl;if(!t)return;let r=e.unresolved&&e.unresolved.missing||[];if(r.length===0){t.textContent="",t.hidden=!0;return}let n=r.length===1?"1 field no longer matches this page":`${r.length} fields no longer match this page`;t.textContent=`${n}: ${r.join(", ")}`,t.hidden=!1}function $o(e){let t=e.unresolved&&e.unresolved.twins||[],r=t.map(n=>`${n.path}:${n.count}`).join("|");if(r!==e.lastTwinSignature){e.lastTwinSignature=r;for(let{path:n,count:i}of t)console.warn(`${Fo} "${n}" matches ${i} elements; edits go to the first one.`)}}function Bo(e){return[...new Set(e)]}function Po(e){let t=new Map;for(let r of e){let n=t.get(r.path);(!n||r.count>n.count)&&t.set(r.path,r)}return[...t.values()]}function He(e){return e.length?e.join("."):"(whole page)"}var zo={skip:"[data-hcms-shell]",templateAttr:"cms-template"};function yt(e,{ignoreActiveValue:t}={}){let r=K.findRules(e.doc,e.rulesSource||"cms");r&&(e.pageRules=e.richText?mt(r.rules,e.pageRoot):r.rules,e.rulesTagNode=r.tagNode),et(e.doc),it(e.doc,e.pageRules),e.formRules=st(e.pageRules,e.doc),e.unresolved=bt(e.pageRoot,e.pageRules);let n=le(K.extract(e.pageRoot,e.pageRules,zo),e.pageRules),i=at({pageRules:e.pageRules,formRules:e.formRules,data:n,doc:e.doc});Xe(e.formRoot,i,{ignoreActiveValue:t}),Ce(e.formRoot,e.doc),Kt(e),kt(e),e.updateFingerprint&&e.updateFingerprint()}function yn({debounce:e=100,onRefresh:t}){let r=W("Mutation");if(!r||typeof r.onAnyChange!="function")throw new Error("hypercms: a mutation hub is required (clay.Mutation or hyperclay.Mutation). Load clayjs or hyperclayjs, or just the mutation utility, before initializing hypercms.");let n=0,i=r.onAnyChange({debounce:e},()=>{n>0||t()});return{unsubscribe:typeof i=="function"?i:()=>{},pause(){n++},resume(){n=Math.max(0,n-1)}}}var Uo="[hypercms]";function vn(e,t){if(!e||!e.querySelectorAll||!t)return;let r=Ho(t);e.querySelectorAll("template[data-hcms-tpl]").forEach(i=>{let o=i.getAttribute("data-hcms-tpl");o&&(o.startsWith("@")||r.has(o)||console.warn(`${Uo} template "${o}" doesn't match any rule path; ignored`))})}function Ho(e){let t=new Set;return r([],e),t;function r(n,i){let o=n.join("."),a=n.map(l=>typeof l=="number"?"*":l).join(".");o&&t.add(o),a&&t.add(a);let s=he(i);if(s==="object")for(let[l,c]of Object.entries(i))r([...n,l],c);else if(s==="object-array"||s==="scalar-array"){let l=[...n,"*"],c=l.map(u=>typeof u=="number"?"*":u).join(".");if(t.add(c),s==="object-array"){let u=i[1];if(u&&typeof u=="object"&&!Array.isArray(u))for(let[p,d]of Object.entries(u))r([...l,p],d)}}}}var xn="hcms-toggle",wn="hcms-toggle-style",Vo=`
178
179
  #hcms-toggle {
179
180
  position: fixed; right: 16px; bottom: 16px; z-index: 2147482900;
180
181
  display: inline-flex; align-items: center; gap: 7px; padding: 9px 14px;
@@ -188,7 +189,7 @@ body.hcms-open #hcms-toggle .hcms-toggle__open { display: none; }
188
189
  body.hcms-open #hcms-toggle .hcms-toggle__close { display: inline; }
189
190
  body.hcms-open:not(.hcms-overlay):not(.hcms-side-left) #hcms-toggle { right: calc(380px + 16px); }
190
191
  body.hcms-open.hcms-overlay #hcms-toggle { display: none; }
191
- `;function Co({search:e="",cookie:t="",forced:r=null}={}){let n=typeof e=="string"?e:"",i=n.indexOf("?"),o=i===-1?n:n.slice(i+1),a=new URLSearchParams(o).get("editmode");return a?a==="true":r!=null?!!r:/(?:^|;\s*)isAdminOfCurrentResource=[^;]/.test(t)}function Ro({open:e,close:t,isOpen:r},n=document){let i=n.getElementById(cn);if(i)return i;if(!n.getElementById(dn)){let a=n.createElement("style");a.id=dn,a.setAttribute("snapshot-remove",""),a.textContent=Eo,n.head.appendChild(a)}let o=n.createElement("button");return o.type="button",o.id=cn,o.setAttribute("no-save",""),o.setAttribute("snapshot-remove",""),o.setAttribute("save-ignore",""),o.setAttribute("aria-label","Toggle content editor"),o.innerHTML='<span class="hcms-toggle__open">Edit content</span><span class="hcms-toggle__close">Close editor</span>',o.addEventListener("click",async()=>{try{r()?t():await e()}catch(a){console.warn("hypercms: toggle failed to open the CMS",a)}}),n.body.appendChild(o),o}function mn(e){if(typeof window>"u"||typeof document>"u")return;let t=window.__hyperclayEditMode!=null?window.__hyperclayEditMode:null;if(!Co({search:window.location.search,cookie:document.cookie,forced:t}))return;let r=()=>{document.body&&e.hasRules(document)&&Ro(e)};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",r,{once:!0}):r()}function pn(e){nn(e)}var I={isOpen:!1,ctx:null,shell:null,opts:null};function un(e,t){if(I.ctx!==e)return;let r=t==="livesync";t==="livesync"&&I.shell?.restoreChrome?.(),pt(e,{ignoreActiveValue:r})}var hn=!1;function To(){if(hn)return;let e=typeof window<"u"&&window.hyperclay&&window.hyperclay.onPrepareForSave||null;typeof e=="function"&&(e(t=>{let r=t&&t.querySelector&&t.querySelector("body");r&&r.classList.remove("hcms-open","hcms-overlay","hcms-side-left")}),hn=!0)}function Gt(e={}){if(I.isOpen){console.warn("cms.open() called while already open; ignoring");return}To();let t=e.pageRoot||(typeof document<"u"?document.body:null);if(!t)throw new Error("hypercms: no pageRoot available");let r=t.ownerDocument||(typeof document<"u"?document:null);if(!r)throw new Error("hypercms: no document available");let n=e.rules!==void 0?e.rules:"cms",i=W.findRules(r,n);if(!i){let h=typeof n=="string"?`data-rules-name~="${n}"`:"the provided rules object";throw new Error(`hypercms: no rules found for ${h}`)}let o=e.richText!==!1,a=o?ct(i.rules,t):i.rules,s=i.tagNode;Xe(r),rt(r,a),ln(r,a);let l=it(a,r),c=ae(W.extract(t,a,{skip:"[data-hcms-shell]",templateAttr:"cms-template"}),a),m=ut(()=>on({mountTo:e.mountTo||r.body,side:e.side||"right",overlay:!!e.overlay,showSaveButton:!!e.showSaveButton,title:e.title,eyebrow:e.eyebrow,theme:e.theme,doc:r})),d={doc:r,pageRoot:t,pageRules:a,formRules:l,rulesTagNode:s,rulesSource:n,richText:o,formRoot:m.formRoot,shellRoot:m.root,errorEl:m.errorEl,lastFingerprint:null,lastData:null,observerHandle:null,undoUnsub:null,livesyncUnsub:null,onChange:e.onChange,onError:e.onError,confirmRemove:e.confirmRemove,previouslyFocused:r.activeElement,dispatch(h,f){let k=r.defaultView&&r.defaultView.CustomEvent||(typeof CustomEvent<"u"?CustomEvent:null);if(!k)return;let C=new k(h,{bubbles:!0,cancelable:h==="hcms:change",detail:f});m.root.dispatchEvent(C)},onCloseRequested(){Jt()}};d.updateFingerprint=()=>{d.lastFingerprint=Pe(Y(d))};try{let h=ot({pageRules:a,formRules:l,data:c,doc:r});m.formRoot.appendChild(h),Ee(m.formRoot,r),en(d),d.updateFingerprint(),d.observerHandle=an({onRefresh:()=>pt(d)});let f=typeof window<"u"&&window.hyperclay&&window.hyperclay.undo||null;if(f&&typeof f.on=="function"){let C=()=>{if(I.ctx!==d)return;un(d,"undo");let N=ae(W.extract(d.pageRoot,d.pageRules,{skip:"[data-hcms-shell]",templateAttr:"cms-template"}),d.pageRules);Pe(N)!==Pe(d.lastData)&&(d.lastData=N,d.onChange?.(N,{path:"",structural:!1}))};f.on("undo",C),f.on("redo",C),d.undoUnsub=()=>{f.off("undo",C),f.off("redo",C)}}let k=()=>un(d,"livesync");r.addEventListener("hyperclay:livesync-applied",k),d.livesyncUnsub=()=>r.removeEventListener("hyperclay:livesync-applied",k),Ue.ctx=d,Mo(r),Oo(m.root),I.isOpen=!0,I.ctx=d,I.shell=m,I.opts=e,d.dispatch("hcms:open",{pageRoot:t})}catch(h){throw d.observerHandle?.unsubscribe?.(),d.undoUnsub?.(),d.livesyncUnsub?.(),d.detachEvents?.(),Ue.ctx===d&&(Ue.ctx=null),ut(()=>m.destroy()),I.isOpen=!1,I.ctx=null,I.shell=null,I.opts=null,h}}function Oo(e){let r=e.querySelector('input:not([disabled]):not([type="hidden"]), textarea:not([disabled]), select:not([disabled]), button:not([disabled]), [tabindex]:not([tabindex="-1"])');r&&typeof r.focus=="function"&&r.focus()}var Ue={ctx:null};function Mo(e){let t=e.defaultView||(typeof globalThis<"u"?globalThis:null);if(!t)return;let r=function(){let i=Ue.ctx;if(i)return Ut(i.formRoot),Re("Reorder",()=>ee(Y(i),{path:"",structural:!0},i))};typeof t.hypercmsCommit!="function"&&(t.hypercmsCommit=r),typeof globalThis<"u"&&typeof globalThis.hypercmsCommit!="function"&&(globalThis.hypercmsCommit=r)}var Kt="cms";function No(e){let t=typeof e=="string"?e:"",r=t.indexOf("?"),n=r===-1?t:t.slice(r+1);if(!n)return t;let i=new URLSearchParams(n);return i.get(Kt)!=="true"?t:(i.set(Kt,"false"),"?"+i.toString())}function Io(e){let t=typeof e=="string"?e:"",r=t.indexOf("?"),n=r===-1?t:t.slice(r+1);return n?new URLSearchParams(n).get(Kt)==="true":!1}function Lo(){if(typeof window>"u"||!window.location||!window.history||typeof window.history.replaceState!="function")return;let e=window.location.search,t=No(e);t!==e&&window.history.replaceState(window.history.state,"",t+window.location.hash)}function Jt(){if(!I.isOpen)return;let{ctx:e,shell:t}=I;e.closed=!0;let r=e.previouslyFocused;if(e.dispatch("hcms:close",null),Lo(),e.observerHandle?.unsubscribe?.(),e.undoUnsub?.(),e.livesyncUnsub?.(),e.detachEvents?.(),ut(()=>t.destroy()),I.isOpen=!1,I.ctx=null,I.shell=null,I.opts=null,Ue.ctx=null,r&&typeof r.focus=="function")try{r.focus()}catch{}}function fn(){I.isOpen&&pt(I.ctx)}function jo(){return I.isOpen}var Fo={getData(){return I.isOpen?Y(I.ctx):null},setValue(e,t){if(!I.isOpen)throw new Error("hypercms: cms is not open");let r=I.ctx,n=te(e),i=me(r.pageRules,n);if(i===void 0)throw new Error(`hypercms: no rule at path "${e}"`);if(typeof i!="string"||i.endsWith("[]"))throw new Error(`hypercms: setValue requires a leaf scalar path; "${e}" is not a leaf`);let o=qo(r.formRoot,e);if(!o)throw new Error(`hypercms: no field element at path "${e}"`);Do(o,t,r.formRoot,e),ee(Y(r),{path:e,structural:!1},r)},addItem(e){if(!I.isOpen)throw new Error("hypercms: cms is not open");Bt(e,I.ctx)},removeItem(e){if(!I.isOpen)throw new Error("hypercms: cms is not open");let t=I.ctx,r=te(e);if(typeof r[r.length-1]!="number")throw new Error(`hypercms: removeItem requires an item path; "${e}" is not an array index`);let i=me(t.pageRules,r.slice(0,-1));if(!(Array.isArray(i)||typeof i=="string"&&i.endsWith("[]")))throw new Error(`hypercms: removeItem requires an item path; parent of "${e}" is not an array`);let a=t.formRoot.querySelector(`[data-hcms-path="${Zt(e)}"]`);if(!a)throw new Error(`hypercms: no element at path "${e}"`);Ce(a,t)},refresh:fn,_commit(){if(!I.isOpen)return;let e=I.ctx;return Ut(e.formRoot),Re("Update",()=>ee(Y(e),{path:"",structural:!0},e))}};function qo(e,t){let r=Zt(t),n=`[data-hcms-path="${r}"] input[data-hcms-field], [data-hcms-path="${r}"] textarea[data-hcms-field], [data-hcms-path="${r}"] select[data-hcms-field], [data-hcms-path="${r}"] img[data-hcms-field], [data-hcms-path="${r}"] a[data-hcms-field], [data-hcms-path="${r}"] [contenteditable][data-hcms-field], input[data-hcms-path="${r}"][data-hcms-field], textarea[data-hcms-path="${r}"][data-hcms-field], select[data-hcms-path="${r}"][data-hcms-field], img[data-hcms-path="${r}"][data-hcms-field], a[data-hcms-path="${r}"][data-hcms-field], [contenteditable][data-hcms-path="${r}"][data-hcms-field]`;return e.querySelector(n)}function Do(e,t,r,n){let i=(e.tagName||"").toUpperCase(),o=(e.getAttribute("type")||"").toLowerCase();if(i==="INPUT"&&o==="checkbox"){e.checked=t===!0||t==="true";return}if(i==="INPUT"&&o==="radio"){let a=Zt(n),s=r.querySelectorAll(`[data-hcms-path="${a}"][data-hcms-field][type="radio"], [data-hcms-path="${a}"] [data-hcms-field][type="radio"]`);s.length?s.forEach(l=>{l.checked=String(l.value)===String(t??"")}):e.checked=String(e.value)===String(t??"");return}if(i==="IMG"){e.src=t==null?"":String(t);return}if(i==="A"){e.href=t==null?"":String(t);return}if(e.hasAttribute&&e.hasAttribute("contenteditable")){e.innerHTML=t==null?"":String(t);return}if("value"in e){e.value=t==null?"":String(t);return}e.textContent=t==null?"":String(t)}var $o=250,Bo=1e4;function zo(){typeof window>"u"||typeof document>"u"||Io(window.location?window.location.search:"")&&(I.isOpen||Po(()=>{if(!I.isOpen)try{Gt()}catch(e){console.warn("hypercms: auto-open failed",e)}}))}function Wt(){return!!document.body&&!!(window.hyperclay&&window.hyperclay.Mutation)}function Po(e){if(Wt()){queueMicrotask(e);return}let t=Date.now()+Bo,r=!1,n=null,i=()=>{r||(r=!0,n!==null&&clearInterval(n),document.removeEventListener("hyperclay:mutation-ready",o))};function o(){if(I.isOpen){i();return}Wt()&&(i(),e())}document.addEventListener("hyperclay:mutation-ready",o,{once:!0}),n=setInterval(()=>{if(I.isOpen){i();return}if(Wt()){i(),e();return}Date.now()>=t&&(i(),console.warn("hypercms: ?cms=true auto-open gave up \u2014 window.hyperclay.Mutation never appeared. Load hyperclayjs (or the mutation utility) so the CMS can initialize."))},$o)}zo();mn({open:Gt,close:Jt,isOpen:jo,hasRules:e=>!!W.findRules(e,"cms")});var Yt={open:Gt,close:Jt,refresh:fn,api:Fo,get isOpen(){return I.isOpen},path:Nt,scaffold:qe,morphForm:Je};function Zt(e){return typeof CSS<"u"&&CSS.escape?CSS.escape(e):String(e).replace(/[^a-zA-Z0-9_\-.*]/g,t=>"\\"+t)}var gn=`/* GENERATED by scripts/build-theme.js from mirk-interface/mirk.css \u2014 DO NOT EDIT.
192
+ `;function Wo({search:e="",cookie:t="",forced:r=null}={}){let n=typeof e=="string"?e:"",i=n.indexOf("?"),o=i===-1?n:n.slice(i+1),a=new URLSearchParams(o).get("editmode");return a?a==="true":r!=null?!!r:/(?:^|;\s*)isAdminOfCurrentResource=[^;]/.test(t)}function Ko({open:e,close:t,isOpen:r},n=document){let i=n.getElementById(xn);if(i)return i;if(!n.getElementById(wn)){let a=n.createElement("style");a.id=wn,a.setAttribute("snapshot-remove",""),a.textContent=Vo,n.head.appendChild(a)}let o=n.createElement("button");return o.type="button",o.id=xn,o.setAttribute("no-save",""),o.setAttribute("snapshot-remove",""),o.setAttribute("save-ignore",""),o.setAttribute("aria-label","Toggle content editor"),o.innerHTML='<span class="hcms-toggle__open">Edit content</span><span class="hcms-toggle__close">Close editor</span>',o.addEventListener("click",async()=>{try{r()?t():await e()}catch(a){console.warn("hypercms: toggle failed to open the CMS",a)}}),n.body.appendChild(o),o}function _n(e){if(typeof window>"u"||typeof document>"u")return;let t=window.__hyperclayEditMode!=null?window.__hyperclayEditMode:null;if(!Wo({search:window.location.search,cookie:document.cookie,forced:t}))return;let r=()=>{document.body&&e.hasRules(document)&&Ko(e)};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",r,{once:!0}):r()}function En(e){pn(e)}var I={isOpen:!1,ctx:null,shell:null,opts:null};function An(e,t){if(I.ctx!==e)return;let r=t==="livesync";t==="livesync"&&I.shell?.restoreChrome?.(),yt(e,{ignoreActiveValue:r})}var Sn=!1;function Go(){if(Sn)return;let e=W("onPrepareForSave");typeof e=="function"&&(e(t=>{let r=t&&t.querySelector&&t.querySelector("body");r&&r.classList.remove("hcms-open","hcms-overlay","hcms-side-left")}),Sn=!0)}function rr(e={}){if(I.isOpen){console.warn("cms.open() called while already open; ignoring");return}Go();let t=e.pageRoot||(typeof document<"u"?document.body:null);if(!t)throw new Error("hypercms: no pageRoot available");let r=t.ownerDocument||(typeof document<"u"?document:null);if(!r)throw new Error("hypercms: no document available");let n=e.rules!==void 0?e.rules:"cms",i=K.findRules(r,n);if(!i){let f=typeof n=="string"?`data-rules-name~="${n}"`:"the provided rules object";throw new Error(`hypercms: no rules found for ${f}`)}let o=e.richText!==!1,a=o?mt(i.rules,t):i.rules,s=i.tagNode;et(r),it(r,a),vn(r,a);let l=st(a,r),c=bt(t,a),u=le(K.extract(t,a,{skip:"[data-hcms-shell]",templateAttr:"cms-template"}),a),p=pt(()=>fn({mountTo:e.mountTo||r.body,side:e.side||"right",overlay:!!e.overlay,showSaveButton:!!e.showSaveButton,title:e.title,eyebrow:e.eyebrow,theme:e.theme,doc:r})),d={doc:r,pageRoot:t,pageRules:a,formRules:l,rulesTagNode:s,rulesSource:n,richText:o,formRoot:p.formRoot,shellRoot:p.root,errorEl:p.errorEl,noticeEl:p.noticeEl,unresolved:c,lastTwinSignature:null,lastFingerprint:null,lastData:null,observerHandle:null,undoUnsub:null,livesyncUnsub:null,onChange:e.onChange,onError:e.onError,confirmRemove:e.confirmRemove,previouslyFocused:r.activeElement,dispatch(f,k){let T=r.defaultView&&r.defaultView.CustomEvent||(typeof CustomEvent<"u"?CustomEvent:null);if(!T)return;let M=new T(f,{bubbles:!0,cancelable:f==="hcms:change",detail:k});p.root.dispatchEvent(M)},onCloseRequested(){nr()}};d.updateFingerprint=()=>{d.lastFingerprint=Ue(X(d))};try{let f=at({pageRules:a,formRules:l,data:u,doc:r});p.formRoot.appendChild(f),Ce(p.formRoot,r),kt(d),mn(d),d.updateFingerprint(),d.observerHandle=yn({onRefresh:()=>yt(d)});let k=W("undo");if(k&&typeof k.on=="function"){let M=()=>{if(I.ctx!==d)return;An(d,"undo");let F=le(K.extract(d.pageRoot,d.pageRules,{skip:"[data-hcms-shell]",templateAttr:"cms-template"}),d.pageRules);Ue(F)!==Ue(d.lastData)&&(d.lastData=F,d.onChange?.(F,{path:"",structural:!1}))};k.on("undo",M),k.on("redo",M),d.undoUnsub=()=>{k.off("undo",M),k.off("redo",M)}}let T=()=>An(d,"livesync");d.livesyncUnsub=Ut(r,ln,T),Ve.ctx=d,Yo(r),Jo(p.root),I.isOpen=!0,I.ctx=d,I.shell=p,I.opts=e,d.dispatch("hcms:open",{pageRoot:t})}catch(f){throw d.observerHandle?.unsubscribe?.(),d.undoUnsub?.(),d.livesyncUnsub?.(),d.detachEvents?.(),Ve.ctx===d&&(Ve.ctx=null),pt(()=>p.destroy()),I.isOpen=!1,I.ctx=null,I.shell=null,I.opts=null,f}}function Jo(e){let r=e.querySelector('input:not([disabled]):not([type="hidden"]), textarea:not([disabled]), select:not([disabled]), button:not([disabled]), [tabindex]:not([tabindex="-1"])');r&&typeof r.focus=="function"&&r.focus()}var Ve={ctx:null};function Yo(e){let t=e.defaultView||(typeof globalThis<"u"?globalThis:null);if(!t)return;let r=function(){let i=Ve.ctx;if(i)return Jt(i.formRoot),Re("Reorder",()=>re(X(i),{path:"",structural:!0},i))};typeof t.hypercmsCommit!="function"&&(t.hypercmsCommit=r),typeof globalThis<"u"&&typeof globalThis.hypercmsCommit!="function"&&(globalThis.hypercmsCommit=r)}var tr="cms";function Xo(e){let t=typeof e=="string"?e:"",r=t.indexOf("?"),n=r===-1?t:t.slice(r+1);if(!n)return t;let i=new URLSearchParams(n);return i.get(tr)!=="true"?t:(i.set(tr,"false"),"?"+i.toString())}function Zo(e){let t=typeof e=="string"?e:"",r=t.indexOf("?"),n=r===-1?t:t.slice(r+1);return n?new URLSearchParams(n).get(tr)==="true":!1}function Qo(){if(typeof window>"u"||!window.location||!window.history||typeof window.history.replaceState!="function")return;let e=window.location.search,t=Xo(e);t!==e&&window.history.replaceState(window.history.state,"",t+window.location.hash)}function nr(){if(!I.isOpen)return;let{ctx:e,shell:t}=I;e.closed=!0;let r=e.previouslyFocused;if(e.dispatch("hcms:close",null),Qo(),e.observerHandle?.unsubscribe?.(),e.undoUnsub?.(),e.livesyncUnsub?.(),e.detachEvents?.(),pt(()=>t.destroy()),I.isOpen=!1,I.ctx=null,I.shell=null,I.opts=null,Ve.ctx=null,r&&typeof r.focus=="function")try{r.focus()}catch{}}function Cn(){I.isOpen&&yt(I.ctx)}function es(){return I.isOpen}var ts={getData(){return I.isOpen?X(I.ctx):null},setValue(e,t){if(!I.isOpen)throw new Error("hypercms: cms is not open");let r=I.ctx,n=ne(e),i=ue(r.pageRules,n);if(i===void 0)throw new Error(`hypercms: no rule at path "${e}"`);if(typeof i!="string"||i.endsWith("[]"))throw new Error(`hypercms: setValue requires a leaf scalar path; "${e}" is not a leaf`);let o=rs(r.formRoot,e);if(!o)throw new Error(`hypercms: no field element at path "${e}"`);ns(o,t,r.formRoot,e),re(X(r),{path:e,structural:!1},r)},addItem(e){if(!I.isOpen)throw new Error("hypercms: cms is not open");Wt(e,I.ctx)},removeItem(e){if(!I.isOpen)throw new Error("hypercms: cms is not open");let t=I.ctx,r=ne(e);if(typeof r[r.length-1]!="number")throw new Error(`hypercms: removeItem requires an item path; "${e}" is not an array index`);let i=ue(t.pageRules,r.slice(0,-1));if(!(Array.isArray(i)||typeof i=="string"&&i.endsWith("[]")))throw new Error(`hypercms: removeItem requires an item path; parent of "${e}" is not an array`);let a=t.formRoot.querySelector(`[data-hcms-path="${or(e)}"]`);if(!a)throw new Error(`hypercms: no element at path "${e}"`);Te(a,t)},refresh:Cn,_commit(){if(!I.isOpen)return;let e=I.ctx;return Jt(e.formRoot),Re("Update",()=>re(X(e),{path:"",structural:!0},e))}};function rs(e,t){let r=or(t),n=`[data-hcms-path="${r}"] input[data-hcms-field], [data-hcms-path="${r}"] textarea[data-hcms-field], [data-hcms-path="${r}"] select[data-hcms-field], [data-hcms-path="${r}"] img[data-hcms-field], [data-hcms-path="${r}"] a[data-hcms-field], [data-hcms-path="${r}"] [contenteditable][data-hcms-field], input[data-hcms-path="${r}"][data-hcms-field], textarea[data-hcms-path="${r}"][data-hcms-field], select[data-hcms-path="${r}"][data-hcms-field], img[data-hcms-path="${r}"][data-hcms-field], a[data-hcms-path="${r}"][data-hcms-field], [contenteditable][data-hcms-path="${r}"][data-hcms-field]`;return e.querySelector(n)}function ns(e,t,r,n){let i=(e.tagName||"").toUpperCase(),o=(e.getAttribute("type")||"").toLowerCase();if(i==="INPUT"&&o==="checkbox"){e.checked=t===!0||t==="true";return}if(i==="INPUT"&&o==="radio"){let a=or(n),s=r.querySelectorAll(`[data-hcms-path="${a}"][data-hcms-field][type="radio"], [data-hcms-path="${a}"] [data-hcms-field][type="radio"]`);s.length?s.forEach(l=>{l.checked=String(l.value)===String(t??"")}):e.checked=String(e.value)===String(t??"");return}if(i==="IMG"){e.src=t==null?"":String(t);return}if(i==="A"){e.href=t==null?"":String(t);return}if(e.hasAttribute&&e.hasAttribute("contenteditable")){e.innerHTML=t==null?"":String(t);return}if("value"in e){e.value=t==null?"":String(t);return}e.textContent=t==null?"":String(t)}var is=250,os=1e4;function ss(){typeof window>"u"||typeof document>"u"||Zo(window.location?window.location.search:"")&&(I.isOpen||as(()=>{if(!I.isOpen)try{rr()}catch(e){console.warn("hypercms: auto-open failed",e)}}))}function er(){return!!document.body&&!!W("Mutation")}function as(e){if(er()){queueMicrotask(e);return}let t=Date.now()+os,r=!1,n=null,i=null,o=()=>{r||(r=!0,n!==null&&clearInterval(n),i&&i())};function a(){if(I.isOpen){o();return}er()&&(o(),e())}i=Ut(document,an,a),n=setInterval(()=>{if(I.isOpen){o();return}if(er()){o(),e();return}Date.now()>=t&&(o(),console.warn("hypercms: ?cms=true auto-open gave up \u2014 no mutation hub appeared. Load clayjs or hyperclayjs (or just the mutation utility) so the CMS can initialize."))},is)}ss();_n({open:rr,close:nr,isOpen:es,hasRules:e=>!!K.findRules(e,"cms")});var ir={open:rr,close:nr,refresh:Cn,api:ts,get isOpen(){return I.isOpen},path:qt,scaffold:De,morphForm:Xe};function or(e){return typeof CSS<"u"&&CSS.escape?CSS.escape(e):String(e).replace(/[^a-zA-Z0-9_\-.*]/g,t=>"\\"+t)}var Tn=`/* GENERATED by scripts/build-theme.js from mirk-interface/mirk.css \u2014 DO NOT EDIT.
192
193
  Source of truth: mirk-interface/mirk.css + src/theme/pixel-quiet.overrides.css.
193
194
  Regenerate with: npm run build:theme */
194
195
 
@@ -1685,6 +1686,18 @@ body.hcms-open.hcms-overlay { overflow: hidden; }
1685
1686
  .hcms-upload-clear--badge:hover { color: var(--mirk-destructive); border-color: var(--mirk-destructive); }
1686
1687
  .hcms-upload-clear--badge .hcms-x { width: 10px; height: 10px; }
1687
1688
 
1689
+ /* ---------- UNRESOLVED-FIELDS NOTICE ---------- */
1690
+ .hcms-shell-notice {
1691
+ font-size: 12px;
1692
+ line-height: 1.45;
1693
+ color: var(--mirk-mark-fg);
1694
+ background: var(--mirk-bevel-bg);
1695
+ border: 1px solid var(--mirk-input-border);
1696
+ padding: 8px 12px;
1697
+ margin: 0 24px 8px;
1698
+ }
1699
+ .hcms-shell-notice[hidden] { display: none; }
1700
+
1688
1701
  /* ---------- ERROR BANNER + inline errors ---------- */
1689
1702
  .hcms-shell-error,
1690
1703
  .hcms-error {
@@ -1736,4 +1749,4 @@ body.hcms-open.hcms-overlay { overflow: hidden; }
1736
1749
  cursor: pointer;
1737
1750
  }
1738
1751
  .hcms-sr-only[hidden] { display: none; }
1739
- `;typeof window<"u"&&typeof document<"u"&&(function(){if(window.__mirk)return;window.__mirk=!0;let e='<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M4 4 12 12M12 4 4 12" stroke="currentColor" stroke-width="2" stroke-linecap="square" fill="none"/></svg>';document.addEventListener("click",r=>{let n=r.target.closest(".mirk-number__step");if(!n)return;let i=n.closest(".mirk-number").querySelector("input[type=number]");i&&(n.dataset.step==="up"?i.stepUp():i.stepDown(),i.dispatchEvent(new Event("change",{bubbles:!0})))}),document.addEventListener("input",r=>{let n=r.target.closest(".mirk-slider__input");n&&n.closest(".mirk-slider").style.setProperty("--mirk-value",`${n.value}%`)}),document.addEventListener("change",r=>{let n=r.target.closest(".mirk-file__input");if(!n||!n.files.length)return;let i=n.closest(".mirk-file"),o=i.querySelector(".mirk-file__name");if(!o)return;let a=n.files[0],s=document.createElement("a");if(s.className="mirk-file__name",s.dataset.filled="",s.href=URL.createObjectURL(a),s.target="_blank",s.rel="noopener",s.textContent=a.name,o.replaceWith(s),!i.querySelector(".mirk-file__remove")){let l=document.createElement("button");l.type="button",l.className="mirk-file__remove",l.setAttribute("aria-label","Remove file"),l.innerHTML=e,s.after(l)}}),document.addEventListener("change",r=>{let n=r.target.closest(".mirk-image__input");if(!n||!n.files.length)return;let i=n.closest(".mirk-image"),o=i.querySelector(".mirk-image__preview");if(!o)return;let a=i.querySelector(".mirk-image__placeholder"),s=new FileReader;s.onload=l=>{o.src=l.target.result,o.removeAttribute("hidden"),a&&a.setAttribute("hidden",""),i.querySelector(".mirk-image__thumb")?.removeAttribute("hidden"),i.querySelector(".mirk-image__upload")?.setAttribute("hidden","")},s.readAsDataURL(n.files[0])}),document.addEventListener("click",r=>{let n=r.target.closest(".mirk-file__remove");if(n){let o=n.closest(".mirk-file"),a=o?.querySelector(".mirk-file__input"),s=o?.querySelector(".mirk-file__name");if(a&&(a.value=""),s){let l=document.createElement("span");l.className="mirk-file__name",l.textContent="No file chosen",s.replaceWith(l)}n.remove();return}let i=r.target.closest(".mirk-image__remove");if(i){let o=i.closest(".mirk-image"),a=o?.querySelector(".mirk-image__input"),s=o?.querySelector(".mirk-image__preview");a&&(a.value=""),s&&(s.removeAttribute("src"),s.setAttribute("hidden","")),o?.querySelector(".mirk-image__thumb")?.setAttribute("hidden",""),o?.querySelector(".mirk-image__upload")?.removeAttribute("hidden")}});function t(r,n){let i=document.createElement("span");i.textContent=r;let o=document.createElement("input");o.type="hidden",o.name="tags[]",o.value=r;let a=document.createElement("button");a.type="button",a.className="mirk-tags__remove",a.textContent="\xD7";let s=document.createElement("span");if(s.className="mirk-tags__chip",n){let l=document.createElement("span");l.className="mirk-tags__chip-inner",l.append(i,o,a),s.append(l)}else s.append(i,o,a);return s}document.addEventListener("keydown",r=>{let n=r.target.closest(".mirk-tags__input");if(!n)return;let i=n.closest(".mirk-tags");if(r.key==="Enter"||r.key===","){let o=n.value.trim();if(!o)return;r.preventDefault(),n.before(t(o,i.classList.contains("mirk-tags--round"))),n.value=""}else if(r.key==="Backspace"&&!n.value){let o=i.querySelectorAll(".mirk-tags__chip");o[o.length-1]?.remove()}}),document.addEventListener("click",r=>{let n=r.target.closest(".mirk-tags__remove");if(n){n.closest(".mirk-tags__chip").remove();return}let i=r.target.closest(".mirk-tags");i&&r.target===i&&i.querySelector(".mirk-tags__input")?.focus()}),document.addEventListener("click",r=>{let n=r.target.closest("[data-mirk-chip]");if(!n)return;let i=n.getAttribute("data-mirk-chip");if(i==="open")n.closest(".mirk-chip")?.classList.add("mirk-chip--open");else if(i==="collapse")n.closest(".mirk-chip")?.classList.remove("mirk-chip--open");else if(i==="changes"){let o=n.closest(".mirk-chip__panel")?.classList.toggle("is-changes");n.textContent=o?"(hide changes)":"(view changes)"}}),document.addEventListener("click",r=>{let n=r.target.closest("[data-copy-btn]");if(!n)return;let i=n.closest("[data-copy]");if(!i)return;let o=i.cloneNode(!0);o.querySelectorAll("[data-copy-btn]").forEach(l=>l.remove());let s=i.getAttribute("data-copy")==="text"?o.textContent.replace(/^\s+|\s+$/g,""):o.innerHTML.replace(/\s+data-copy(="[^"]*")?/g,"").replace(/^\s*\n/gm,"").trim();navigator.clipboard.writeText(s).then(()=>{let l=n.textContent;n.textContent="copied",n.dataset.copied="",setTimeout(()=>{n.textContent=l,delete n.dataset.copied},1200)}).catch(()=>{n.textContent="error",setTimeout(()=>{n.textContent="copy"},1200)})})})();pn(gn);var Vo=Yt,Wo={cms:Yt};return An(Ko);})();
1752
+ `;typeof window<"u"&&typeof document<"u"&&(function(){if(window.__mirk)return;window.__mirk=!0;let e='<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M4 4 12 12M12 4 4 12" stroke="currentColor" stroke-width="2" stroke-linecap="square" fill="none"/></svg>';document.addEventListener("click",r=>{let n=r.target.closest(".mirk-number__step");if(!n)return;let i=n.closest(".mirk-number").querySelector("input[type=number]");i&&(n.dataset.step==="up"?i.stepUp():i.stepDown(),i.dispatchEvent(new Event("change",{bubbles:!0})))}),document.addEventListener("input",r=>{let n=r.target.closest(".mirk-slider__input");n&&n.closest(".mirk-slider").style.setProperty("--mirk-value",`${n.value}%`)}),document.addEventListener("change",r=>{let n=r.target.closest(".mirk-file__input");if(!n||!n.files.length)return;let i=n.closest(".mirk-file"),o=i.querySelector(".mirk-file__name");if(!o)return;let a=n.files[0],s=document.createElement("a");if(s.className="mirk-file__name",s.dataset.filled="",s.href=URL.createObjectURL(a),s.target="_blank",s.rel="noopener",s.textContent=a.name,o.replaceWith(s),!i.querySelector(".mirk-file__remove")){let l=document.createElement("button");l.type="button",l.className="mirk-file__remove",l.setAttribute("aria-label","Remove file"),l.innerHTML=e,s.after(l)}}),document.addEventListener("change",r=>{let n=r.target.closest(".mirk-image__input");if(!n||!n.files.length)return;let i=n.closest(".mirk-image"),o=i.querySelector(".mirk-image__preview");if(!o)return;let a=i.querySelector(".mirk-image__placeholder"),s=new FileReader;s.onload=l=>{o.src=l.target.result,o.removeAttribute("hidden"),a&&a.setAttribute("hidden",""),i.querySelector(".mirk-image__thumb")?.removeAttribute("hidden"),i.querySelector(".mirk-image__upload")?.setAttribute("hidden","")},s.readAsDataURL(n.files[0])}),document.addEventListener("click",r=>{let n=r.target.closest(".mirk-file__remove");if(n){let o=n.closest(".mirk-file"),a=o?.querySelector(".mirk-file__input"),s=o?.querySelector(".mirk-file__name");if(a&&(a.value=""),s){let l=document.createElement("span");l.className="mirk-file__name",l.textContent="No file chosen",s.replaceWith(l)}n.remove();return}let i=r.target.closest(".mirk-image__remove");if(i){let o=i.closest(".mirk-image"),a=o?.querySelector(".mirk-image__input"),s=o?.querySelector(".mirk-image__preview");a&&(a.value=""),s&&(s.removeAttribute("src"),s.setAttribute("hidden","")),o?.querySelector(".mirk-image__thumb")?.setAttribute("hidden",""),o?.querySelector(".mirk-image__upload")?.removeAttribute("hidden")}});function t(r,n){let i=document.createElement("span");i.textContent=r;let o=document.createElement("input");o.type="hidden",o.name="tags[]",o.value=r;let a=document.createElement("button");a.type="button",a.className="mirk-tags__remove",a.textContent="\xD7";let s=document.createElement("span");if(s.className="mirk-tags__chip",n){let l=document.createElement("span");l.className="mirk-tags__chip-inner",l.append(i,o,a),s.append(l)}else s.append(i,o,a);return s}document.addEventListener("keydown",r=>{let n=r.target.closest(".mirk-tags__input");if(!n)return;let i=n.closest(".mirk-tags");if(r.key==="Enter"||r.key===","){let o=n.value.trim();if(!o)return;r.preventDefault(),n.before(t(o,i.classList.contains("mirk-tags--round"))),n.value=""}else if(r.key==="Backspace"&&!n.value){let o=i.querySelectorAll(".mirk-tags__chip");o[o.length-1]?.remove()}}),document.addEventListener("click",r=>{let n=r.target.closest(".mirk-tags__remove");if(n){n.closest(".mirk-tags__chip").remove();return}let i=r.target.closest(".mirk-tags");i&&r.target===i&&i.querySelector(".mirk-tags__input")?.focus()}),document.addEventListener("click",r=>{let n=r.target.closest("[data-mirk-chip]");if(!n)return;let i=n.getAttribute("data-mirk-chip");if(i==="open")n.closest(".mirk-chip")?.classList.add("mirk-chip--open");else if(i==="collapse")n.closest(".mirk-chip")?.classList.remove("mirk-chip--open");else if(i==="changes"){let o=n.closest(".mirk-chip__panel")?.classList.toggle("is-changes");n.textContent=o?"(hide changes)":"(view changes)"}}),document.addEventListener("click",r=>{let n=r.target.closest("[data-copy-btn]");if(!n)return;let i=n.closest("[data-copy]");if(!i)return;let o=i.cloneNode(!0);o.querySelectorAll("[data-copy-btn]").forEach(l=>l.remove());let s=i.getAttribute("data-copy")==="text"?o.textContent.replace(/^\s+|\s+$/g,""):o.innerHTML.replace(/\s+data-copy(="[^"]*")?/g,"").replace(/^\s*\n/gm,"").trim();navigator.clipboard.writeText(s).then(()=>{let l=n.textContent;n.textContent="copied",n.dataset.copied="",setTimeout(()=>{n.textContent=l,delete n.dataset.copied},1200)}).catch(()=>{n.textContent="error",setTimeout(()=>{n.textContent="copy"},1200)})})})();En(Tn);var ds=ir,ms={cms:ir};return Fn(us);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panphora/hyper-cms",
3
- "version": "0.6.2",
3
+ "version": "0.7.0",
4
4
  "description": "Live edit-in-place CMS sidebar for HTML pages with a hyper-html-api rules tag",
5
5
  "keywords": [
6
6
  "HTML",
@@ -35,6 +35,7 @@
35
35
  "build": "npm run build:theme && npx esbuild src/hypercms-bundle.js --bundle --minify --format=iife --global-name=hypercms --loader:.css=text --outfile=dist/hypercms.min.js",
36
36
  "prepublishOnly": "npm run build",
37
37
  "copy-to-hyperclayjs": "npm run build && node scripts/copy-to-hyperclayjs.js",
38
+ "copy-to-clayjs": "npm run build && node scripts/copy-to-clayjs.js",
38
39
  "test:node": "node --test 'test-node/**/*.test.js'",
39
40
  "test": "npm run test:node",
40
41
  "demo": "http-server . -p 5694 -c-1 -o /demo/",
package/src/enhance.js CHANGED
@@ -9,6 +9,8 @@
9
9
  // whose element holds only text are left untouched. Hosts opt out with
10
10
  // cms.open({ richText: false }).
11
11
 
12
+ import { platform } from './platform.js'
13
+
12
14
  export function upgradeRichTextRules(rules, pageRoot) {
13
15
  if (!pageRoot || rules == null) return rules
14
16
  return walk(rules)
@@ -61,7 +63,7 @@ export function enhanceFields(root, doc) {
61
63
  const win = (doc && doc.defaultView) || (typeof window !== 'undefined' ? window : null)
62
64
  const RichClay =
63
65
  (win && win.richclay && win.richclay.RichClay) ||
64
- (win && win.hyperclay && win.hyperclay.RichClay) ||
66
+ platform('RichClay', win) ||
65
67
  (win && typeof win.RichClay === 'function' ? win.RichClay : null)
66
68
  if (!RichClay) return
67
69
 
package/src/events.js CHANGED
@@ -4,6 +4,7 @@ import { fromString as pathFromString, getRuleAtPath } from './path.js'
4
4
  import { buildItem, fileNameFromUrl, radioGroupName } from './form-builder.js'
5
5
  import { scaffold } from './scaffold.js'
6
6
  import { autosizeTextarea, enhanceFields } from './enhance.js'
7
+ import { platform } from './platform.js'
7
8
 
8
9
  const BOUND = new WeakSet()
9
10
 
@@ -15,7 +16,7 @@ const BOUND = new WeakSet()
15
16
  //
16
17
  // No-op pass-through when window.hyperclay.undo isn't loaded.
17
18
  export function commitWithUndo(label, fn) {
18
- const u = (typeof window !== 'undefined' && window.hyperclay && window.hyperclay.undo) || null
19
+ const u = platform('undo')
19
20
  if (!u) return fn()
20
21
  u.pause()
21
22
  try {
@@ -36,7 +37,7 @@ export function commitWithUndo(label, fn) {
36
37
  // on mount/unmount) never enter the undo stack. No-op pass-through when undo
37
38
  // isn't loaded.
38
39
  export function suppressUndo(fn) {
39
- const u = (typeof window !== 'undefined' && window.hyperclay && window.hyperclay.undo) || null
40
+ const u = platform('undo')
40
41
  if (!u) return fn()
41
42
  u.pause()
42
43
  try {
@@ -167,7 +168,7 @@ export function onScalarChange(target, ctx) {
167
168
  const proj = resolveUnobservedProjection(ctx, pathStr)
168
169
  commit(extractFormData(ctx), { path: pathStr, structural: false }, ctx)
169
170
  if (proj) {
170
- const u = (typeof window !== 'undefined' && window.hyperclay && window.hyperclay.undo) || null
171
+ const u = platform('undo')
171
172
  if (u && typeof u.recordValue === 'function') {
172
173
  u.recordValue(proj.el, { prop: proj.prop, oldValue: proj.oldValue, newValue: proj.el[proj.prop] })
173
174
  }
@@ -186,7 +187,7 @@ const CROP_OUTPUT = { type: 'image/webp', quality: 0.85, maxWidth: 2048, maxHeig
186
187
  async function maybeCrop(file, fieldEl) {
187
188
  const attr = fieldEl && fieldEl.getAttribute ? fieldEl.getAttribute('data-hcms-crop') : null
188
189
  if (attr == null) return { file }
189
- const crop = (typeof window !== 'undefined' && window.hyperclay && window.hyperclay.quickcrop) || null
190
+ const crop = platform('quickcrop')
190
191
  if (typeof crop !== 'function') return { file }
191
192
  try {
192
193
  const r = await crop(file, { aspect: parseCropAspect(attr), ...CROP_OUTPUT })
@@ -245,7 +246,7 @@ export async function onUploadChange(inputEl, ctx) {
245
246
  const fileLike = cropped.file
246
247
  const previewDataUrl = cropped.dataURL || null
247
248
 
248
- const upload = (typeof window !== 'undefined' && window.hyperclay && window.hyperclay.uploadFileBasic) || null
249
+ const upload = platform('uploadFileBasic')
249
250
  let url = null
250
251
  if (typeof upload === 'function') {
251
252
  try {
@@ -440,7 +441,7 @@ export function requestRemove(itemEl, ctx) {
440
441
  const arrayEl = itemEl.closest('[data-hcms-shape="object-array"], [data-hcms-shape="scalar-array"]')
441
442
  const message = resolveRemoveConfirm(arrayEl, ctx)
442
443
  if (message == null) return onRemove(itemEl, ctx)
443
- const consent = typeof window !== 'undefined' && (window.hyperclay?.consent || window.consent)
444
+ const consent = platform('consent') || (typeof window !== 'undefined' && window.consent)
444
445
  if (typeof consent === 'function') {
445
446
  Promise.resolve(consent(message)).then(() => onRemove(itemEl, ctx), () => {})
446
447
  } else if (typeof window !== 'undefined' && typeof window.confirm === 'function') {
package/src/hypercms.js CHANGED
@@ -20,8 +20,10 @@ import {
20
20
  import { mountShell, setShellStyles, markStylesBundled } from './shell.js'
21
21
  import { refreshForm, installObserver } from './refresh.js'
22
22
  import { warnUnmatchedTemplates } from './diagnostics.js'
23
+ import { findUnresolved, applyUnresolvedState } from './unresolved.js'
23
24
  import { enhanceFields, upgradeRichTextRules } from './enhance.js'
24
25
  import { maybeInjectToggle } from './toggle.js'
26
+ import { platform, onPlatformEvent, MUTATION_READY, LIVESYNC_APPLIED } from './platform.js'
25
27
 
26
28
  export function installStyles(text) {
27
29
  setShellStyles(text)
@@ -72,8 +74,7 @@ function resyncForm(ctx, reason) {
72
74
  let prepareHookInstalled = false
73
75
  function installSavePrepareHook() {
74
76
  if (prepareHookInstalled) return
75
- const onPrepareForSave =
76
- (typeof window !== 'undefined' && window.hyperclay && window.hyperclay.onPrepareForSave) || null
77
+ const onPrepareForSave = platform('onPrepareForSave')
77
78
  if (typeof onPrepareForSave !== 'function') return
78
79
  onPrepareForSave((clonedDocEl) => {
79
80
  const b = clonedDocEl && clonedDocEl.querySelector && clonedDocEl.querySelector('body')
@@ -114,6 +115,9 @@ export function open(opts = {}) {
114
115
  injectComponents(doc, pageRules)
115
116
  warnUnmatchedTemplates(doc, pageRules)
116
117
  const formRules = deriveFormRules(pageRules, doc)
118
+ // Runs before the first extract so a rule with invalid CSS names its field
119
+ // instead of throwing a bare SyntaxError out of querySelectorAll.
120
+ const unresolved = findUnresolved(pageRoot, pageRules)
117
121
  const data = coerceBooleans(engine.extract(pageRoot, pageRules, { skip: '[data-hcms-shell]', templateAttr: 'cms-template' }), pageRules)
118
122
 
119
123
  // Suppress undo around mountShell: it toggles chrome-only classes on
@@ -141,6 +145,9 @@ export function open(opts = {}) {
141
145
  formRoot: shell.formRoot,
142
146
  shellRoot: shell.root,
143
147
  errorEl: shell.errorEl,
148
+ noticeEl: shell.noticeEl,
149
+ unresolved,
150
+ lastTwinSignature: null,
144
151
  lastFingerprint: null,
145
152
  lastData: null,
146
153
  observerHandle: null,
@@ -174,6 +181,7 @@ export function open(opts = {}) {
174
181
  const fragment = buildForm({ pageRules, formRules, data, doc })
175
182
  shell.formRoot.appendChild(fragment)
176
183
  enhanceFields(shell.formRoot, doc)
184
+ applyUnresolvedState(ctx)
177
185
 
178
186
  bindEvents(ctx)
179
187
  ctx.updateFingerprint()
@@ -187,7 +195,7 @@ export function open(opts = {}) {
187
195
  // is source-blind, so subscribe to the undo scope and force a non-ignoring refresh.
188
196
  // Fires synchronously before the debounced observer refresh, which then no-ops on
189
197
  // the active field. Guarded so it degrades to today's behavior when undo isn't loaded.
190
- const u = (typeof window !== 'undefined' && window.hyperclay && window.hyperclay.undo) || null
198
+ const u = platform('undo')
191
199
  if (u && typeof u.on === 'function') {
192
200
  const onRevert = () => {
193
201
  if (state.ctx !== ctx) return
@@ -222,8 +230,7 @@ export function open(opts = {}) {
222
230
  // with ignoreActiveValue:true (preserve the user's in-progress field). Same
223
231
  // document live-sync dispatches on; unsubscribed in close().
224
232
  const onLivesync = () => resyncForm(ctx, 'livesync')
225
- doc.addEventListener('hyperclay:livesync-applied', onLivesync)
226
- ctx.livesyncUnsub = () => doc.removeEventListener('hyperclay:livesync-applied', onLivesync)
233
+ ctx.livesyncUnsub = onPlatformEvent(doc, LIVESYNC_APPLIED, onLivesync)
227
234
 
228
235
  // Wire global sortable callback to current ctx (replaced by close()).
229
236
  globalCommitTarget.ctx = ctx
@@ -507,17 +514,19 @@ export function maybeAutoOpen() {
507
514
  // Auto-open is ready only once <body> is parsed AND window.hyperclay.Mutation is
508
515
  // installed (open() needs both). NEVER throw out of module scope.
509
516
  function autoOpenReady() {
510
- return !!document.body && !!(window.hyperclay && window.hyperclay.Mutation)
517
+ return !!document.body && !!platform('Mutation')
511
518
  }
512
519
 
513
520
  // Three layers, in order of preference:
514
521
  // 1. Sync fast-path: if <body> and Mutation are already here, fire now.
515
- // 2. Event: hyperclayjs's mutation.js dispatches 'hyperclay:mutation-ready' the
516
- // instant it installs window.hyperclay.Mutation. On loader pages this is
517
- // moot — the loader's first wave evaluates mutation before hypercms, so the
518
- // fast-path wins — but the event catches any late install (the deferred
519
- // `await import()` ordering). The body gate is re-checked in the handler
520
- // because the event can land before <body> is parsed.
522
+ // 2. Event: both clients dispatch a mutation-ready signal the instant they
523
+ // install the mutation hub, under two spellings ('clay:mutation-ready' and
524
+ // 'hyperclay:mutation-ready'), so hypercms listens for both and dedups. On
525
+ // loader pages this is moot — the loader's first wave evaluates mutation
526
+ // before hypercms, so the fast-path wins — but the event catches any late
527
+ // install (the deferred `await import()` ordering). The body gate is
528
+ // re-checked in the handler because the event can land before <body> is
529
+ // parsed.
521
530
  // 3. Backstop: a slow self-cancelling 250ms poll for exotic hosts that hand-roll
522
531
  // window.hyperclay.Mutation by direct assignment WITHOUT dispatching the
523
532
  // event. It cancels the moment the event fires, open succeeds, or the
@@ -536,11 +545,12 @@ function whenReady(fn) {
536
545
  const deadline = Date.now() + AUTO_OPEN_DEADLINE_MS
537
546
  let done = false
538
547
  let timer = null
548
+ let offMutationReady = null
539
549
  const finish = () => {
540
550
  if (done) return
541
551
  done = true
542
552
  if (timer !== null) clearInterval(timer)
543
- document.removeEventListener('hyperclay:mutation-ready', onMutationReady)
553
+ if (offMutationReady) offMutationReady()
544
554
  }
545
555
  function onMutationReady() {
546
556
  if (state.isOpen) {
@@ -551,10 +561,11 @@ function whenReady(fn) {
551
561
  finish()
552
562
  fn()
553
563
  }
554
- // Body may still be pending — the one-shot listener is already consumed,
555
- // so only the backstop remains to catch it once body arrives.
564
+ // Body may still be pending. Unlike the old one-shot listener this stays
565
+ // subscribed, so a later dispatch is still caught and the backstop is no
566
+ // longer the only remaining path.
556
567
  }
557
- document.addEventListener('hyperclay:mutation-ready', onMutationReady, { once: true })
568
+ offMutationReady = onPlatformEvent(document, MUTATION_READY, onMutationReady)
558
569
  timer = setInterval(() => {
559
570
  if (state.isOpen) {
560
571
  finish()
@@ -568,8 +579,8 @@ function whenReady(fn) {
568
579
  if (Date.now() >= deadline) {
569
580
  finish()
570
581
  console.warn(
571
- 'hypercms: ?cms=true auto-open gave up — window.hyperclay.Mutation never appeared. ' +
572
- 'Load hyperclayjs (or the mutation utility) so the CMS can initialize.'
582
+ 'hypercms: ?cms=true auto-open gave up — no mutation hub appeared. ' +
583
+ 'Load clayjs or hyperclayjs (or just the mutation utility) so the CMS can initialize.'
573
584
  )
574
585
  }
575
586
  }, SAFETY_POLL_MS)
@@ -0,0 +1,66 @@
1
+ // The optional platform hypercms rides: the mutation hub, undo, the save-prepare
2
+ // hook, rich text, and the two upload helpers. Every one degrades to null, so the
3
+ // CMS still runs in a bare HTML file with no client at all.
4
+ //
5
+ // TWO clients provide this and they disagree on names. hyperclayjs owns
6
+ // window.hyperclay; clayjs owns window.clay and renamed things on the way past
7
+ // (onPrepareForSave -> addDocumentTransform, consent -> confirm) while leaving RichClay and
8
+ // both upload helpers off its namespace entirely. So this is a capability table
9
+ // rather than a namespace pointer: `window.clay ?? window.hyperclay` would resolve
10
+ // to clay, find no onPrepareForSave, and silently stop stripping the CMS's own
11
+ // chrome out of every save.
12
+ //
13
+ // Reads happen per call, never cached. A client can install a capability after
14
+ // hypercms evaluates — that is the whole reason whenReady() below exists.
15
+ const CAPABILITIES = {
16
+ Mutation: (clay, hyperclay) => clay?.Mutation ?? hyperclay?.Mutation,
17
+ undo: (clay, hyperclay) => clay?.undo ?? hyperclay?.undo,
18
+ onPrepareForSave: (clay, hyperclay) => clay?.addDocumentTransform ?? hyperclay?.onPrepareForSave,
19
+ consent: (clay, hyperclay) => clay?.confirm ?? hyperclay?.consent,
20
+ RichClay: (clay, hyperclay) => clay?.RichClay ?? hyperclay?.RichClay,
21
+ quickcrop: (clay, hyperclay) => clay?.quickcrop ?? hyperclay?.quickcrop,
22
+ uploadFileBasic: (clay, hyperclay) => clay?.uploadFileBasic ?? hyperclay?.uploadFileBasic,
23
+ }
24
+
25
+ // Pass `win` when the caller already holds a realm (a doc.defaultView from a form
26
+ // mounted into another document); it defaults to the ambient one.
27
+ export function platform(name, win) {
28
+ const read = CAPABILITIES[name]
29
+ if (!read) throw new Error(`hypercms: unknown platform capability "${name}"`)
30
+ const scope = win || (typeof window !== 'undefined' ? window : null)
31
+ if (!scope) return null
32
+ return read(scope.clay, scope.hyperclay) || null
33
+ }
34
+
35
+ // Both spellings of the same signal. clayjs dispatches its own name and mirrors the
36
+ // legacy one; it will stop mirroring when it drops the window.hyperclay shim, and
37
+ // hyperclayjs only ever dispatches the legacy one. Listening for both is what makes
38
+ // this survive that change without a flag day.
39
+ export const MUTATION_READY = ['clay:mutation-ready', 'hyperclay:mutation-ready']
40
+ export const LIVESYNC_APPLIED = ['clay:sync-applied', 'hyperclay:livesync-applied']
41
+
42
+ // Subscribe to every spelling of one signal, delivering the handler ONCE per
43
+ // occurrence. clayjs dispatches the pair back to back in the same tick, so a plain
44
+ // listener on each name fires the handler twice for one event: two form
45
+ // re-extracts, or two open() calls.
46
+ //
47
+ // The first name to arrive claims the tick, and only a DIFFERENT name is suppressed
48
+ // while it holds the claim. That distinction is what makes this exact rather than a
49
+ // heuristic: no client dispatches one name twice for one occurrence, so a repeat of
50
+ // the claiming name is always a second occurrence and always gets through — even
51
+ // when it lands in the same tick, which is precisely what a caller doing two
52
+ // synchronous applies looks like. Guarding on "have I run at all this tick" would
53
+ // swallow that.
54
+ //
55
+ // Returns an unsubscribe that removes every name.
56
+ export function onPlatformEvent(target, names, handler) {
57
+ let claimedBy = null
58
+ const wrapped = (event) => {
59
+ if (claimedBy !== null && claimedBy !== event.type) return
60
+ claimedBy = event.type
61
+ queueMicrotask(() => { claimedBy = null })
62
+ handler(event)
63
+ }
64
+ for (const name of names) target.addEventListener(name, wrapped)
65
+ return () => { for (const name of names) target.removeEventListener(name, wrapped) }
66
+ }
package/src/refresh.js CHANGED
@@ -4,7 +4,9 @@ import { morphForm } from './morph.js'
4
4
  import { injectDefaults, injectComponents } from './templates.js'
5
5
  import { deriveFormRules } from './form-rules.js'
6
6
  import { coerceBooleans, applyErrorState } from './events.js'
7
+ import { findUnresolved, applyUnresolvedState } from './unresolved.js'
7
8
  import { enhanceFields, upgradeRichTextRules } from './enhance.js'
9
+ import { platform } from './platform.js'
8
10
 
9
11
  const ENGINE_OPTS = { skip: '[data-hcms-shell]', templateAttr: 'cms-template' }
10
12
 
@@ -24,6 +26,8 @@ export function refreshForm(ctx, { ignoreActiveValue } = {}) {
24
26
  injectDefaults(ctx.doc)
25
27
  injectComponents(ctx.doc, ctx.pageRules)
26
28
  ctx.formRules = deriveFormRules(ctx.pageRules, ctx.doc)
29
+ // Before the extract below, for the same readable-failure reason as open().
30
+ ctx.unresolved = findUnresolved(ctx.pageRoot, ctx.pageRules)
27
31
 
28
32
  const newData = coerceBooleans(
29
33
  engine.extract(ctx.pageRoot, ctx.pageRules, ENGINE_OPTS),
@@ -43,14 +47,15 @@ export function refreshForm(ctx, { ignoreActiveValue } = {}) {
43
47
  // the last error state so error messages survive across observer-driven refreshes
44
48
  // (e.g., the rollback after a failed add).
45
49
  applyErrorState(ctx)
50
+ applyUnresolvedState(ctx)
46
51
  // Update fingerprint so subsequent commits against the new page state compare correctly.
47
52
  if (ctx.updateFingerprint) ctx.updateFingerprint()
48
53
  }
49
54
 
50
55
  export function installObserver({ debounce = 100, onRefresh }) {
51
- const M = (typeof window !== 'undefined' && window.hyperclay && window.hyperclay.Mutation) || null
56
+ const M = platform('Mutation')
52
57
  if (!M || typeof M.onAnyChange !== 'function') {
53
- throw new Error('hypercms: window.hyperclay.Mutation is required. Load hyperclayjs (or just the mutation utility) before initializing hypercms.')
58
+ throw new Error('hypercms: a mutation hub is required (clay.Mutation or hyperclay.Mutation). Load clayjs or hyperclayjs, or just the mutation utility, before initializing hypercms.')
54
59
  }
55
60
  let paused = 0
56
61
  const unsub = M.onAnyChange({ debounce }, () => {
package/src/shell.js CHANGED
@@ -79,6 +79,7 @@ export function mountShell({
79
79
  <span class="mirk-button__label">×</span>
80
80
  </button>
81
81
  </header>
82
+ <div class="hcms-shell-notice" role="status" hidden></div>
82
83
  <div class="hcms-shell-error" role="alert" hidden></div>
83
84
  <div data-hcms-form-root class="hcms-form"></div>
84
85
  <footer class="hcms-shell-footer"${showSaveButton ? '' : ' hidden'}>
@@ -106,6 +107,7 @@ export function mountShell({
106
107
  return {
107
108
  root,
108
109
  formRoot: root.querySelector('[data-hcms-form-root]'),
110
+ noticeEl: root.querySelector('.hcms-shell-notice'),
109
111
  errorEl: root.querySelector('.hcms-shell-error'),
110
112
  saveButton: root.querySelector('.hcms-shell-save'),
111
113
  destroy() {
@@ -484,6 +484,18 @@ body.hcms-open.hcms-overlay { overflow: hidden; }
484
484
  .hcms-upload-clear--badge:hover { color: var(--mirk-destructive); border-color: var(--mirk-destructive); }
485
485
  .hcms-upload-clear--badge .hcms-x { width: 10px; height: 10px; }
486
486
 
487
+ /* ---------- UNRESOLVED-FIELDS NOTICE ---------- */
488
+ .hcms-shell-notice {
489
+ font-size: 12px;
490
+ line-height: 1.45;
491
+ color: var(--mirk-mark-fg);
492
+ background: var(--mirk-bevel-bg);
493
+ border: 1px solid var(--mirk-input-border);
494
+ padding: 8px 12px;
495
+ margin: 0 24px 8px;
496
+ }
497
+ .hcms-shell-notice[hidden] { display: none; }
498
+
487
499
  /* ---------- ERROR BANNER + inline errors ---------- */
488
500
  .hcms-shell-error,
489
501
  .hcms-error {
@@ -1495,6 +1495,18 @@ body.hcms-open.hcms-overlay { overflow: hidden; }
1495
1495
  .hcms-upload-clear--badge:hover { color: var(--mirk-destructive); border-color: var(--mirk-destructive); }
1496
1496
  .hcms-upload-clear--badge .hcms-x { width: 10px; height: 10px; }
1497
1497
 
1498
+ /* ---------- UNRESOLVED-FIELDS NOTICE ---------- */
1499
+ .hcms-shell-notice {
1500
+ font-size: 12px;
1501
+ line-height: 1.45;
1502
+ color: var(--mirk-mark-fg);
1503
+ background: var(--mirk-bevel-bg);
1504
+ border: 1px solid var(--mirk-input-border);
1505
+ padding: 8px 12px;
1506
+ margin: 0 24px 8px;
1507
+ }
1508
+ .hcms-shell-notice[hidden] { display: none; }
1509
+
1498
1510
  /* ---------- ERROR BANNER + inline errors ---------- */
1499
1511
  .hcms-shell-error,
1500
1512
  .hcms-error {
@@ -0,0 +1,140 @@
1
+ import domAdapter from 'hyper-html-api/dom'
2
+
3
+ const PREFIX = '[hypercms]'
4
+
5
+ // The opts every other engine call in hypercms uses: never traverse into the
6
+ // sidebar's own form, never count a [cms-template] seed as content.
7
+ const FIND_OPTS = { skip: '[data-hcms-shell]', templateAttr: 'cms-template' }
8
+ // templateAttr:null includes seeds. An empty list still holding its seed can be
9
+ // grown back from it, so it is not dead.
10
+ const SEED_OPTS = { skip: '[data-hcms-shell]', templateAttr: null }
11
+
12
+ export class InvalidRuleSelector extends Error {
13
+ constructor(path, selector, cause) {
14
+ super(`hypercms: rule at "${path}" has an invalid CSS selector: "${selector}"`)
15
+ this.name = 'InvalidRuleSelector'
16
+ this.path = path
17
+ this.selector = selector
18
+ this.cause = cause
19
+ }
20
+ }
21
+
22
+ // Report a field only when writing to it would be silently discarded, which is
23
+ // exactly when apply() finds no element and returns having done nothing.
24
+ // An extracted null is NOT that test: a present-but-empty attribute reads null
25
+ // too (extract.js readPropOrAttr), and that field saves perfectly. So this
26
+ // resolves each rule's selector and counts matches instead of reading values.
27
+ export function findUnresolved(root, rules) {
28
+ const missing = []
29
+ const twins = []
30
+ walk(root, rules, [], missing, twins)
31
+ return { missing: unique(missing), twins: uniqueTwins(twins) }
32
+ }
33
+
34
+ function walk(ctx, rule, path, missing, twins) {
35
+ if (typeof rule === 'string') {
36
+ const selector = selectorOf(rule)
37
+ if (!selector) return
38
+ const matches = find(ctx, selector, FIND_OPTS, path)
39
+ if (rule.endsWith('[]')) {
40
+ if (matches.length === 0 && find(ctx, selector, SEED_OPTS, path).length === 0) {
41
+ missing.push(pathStr(path))
42
+ }
43
+ return
44
+ }
45
+ if (matches.length === 0) missing.push(pathStr(path))
46
+ else if (matches.length > 1) twins.push({ path: pathStr(path), count: matches.length })
47
+ return
48
+ }
49
+
50
+ if (Array.isArray(rule)) {
51
+ const [selector, shape] = rule
52
+ if (typeof selector !== 'string' || !selector) return
53
+ const matches = find(ctx, selector, FIND_OPTS, path)
54
+ if (matches.length === 0) {
55
+ if (find(ctx, selector, SEED_OPTS, path).length === 0) missing.push(pathStr(path))
56
+ return
57
+ }
58
+ // Rows collapse to one '*' segment, so a field broken on every row is
59
+ // reported once rather than once per row.
60
+ for (const node of matches) walk(node, shape, [...path, '*'], missing, twins)
61
+ return
62
+ }
63
+
64
+ if (rule && typeof rule === 'object') {
65
+ for (const [key, sub] of Object.entries(rule)) walk(ctx, sub, [...path, key], missing, twins)
66
+ }
67
+ }
68
+
69
+ function find(ctx, selector, opts, path) {
70
+ try {
71
+ return domAdapter.find(ctx, selector, opts)
72
+ } catch (err) {
73
+ throw new InvalidRuleSelector(pathStr(path), selector, err)
74
+ }
75
+ }
76
+
77
+ // Mirrors the engine's scalar parsing: a trailing [] strips, "." and a leading
78
+ // @ read the context node itself so they can never fail to resolve, and
79
+ // otherwise the selector is the part before the LAST @.
80
+ function selectorOf(rule) {
81
+ if (rule === '.' || rule.startsWith('@')) return null
82
+ if (rule.endsWith('[]')) return rule.slice(0, -2) || null
83
+ const at = rule.lastIndexOf('@')
84
+ return (at === -1 ? rule : rule.slice(0, at)) || null
85
+ }
86
+
87
+ export function applyUnresolvedState(ctx) {
88
+ renderNotice(ctx)
89
+ warnTwins(ctx)
90
+ }
91
+
92
+ // States the fact and stops. Regenerating a CMS replaces the rules tag
93
+ // wholesale, so a notice that reads as a repair prompt would walk anyone with a
94
+ // hand-edited config into losing it.
95
+ function renderNotice(ctx) {
96
+ const el = ctx.noticeEl
97
+ if (!el) return
98
+ const missing = (ctx.unresolved && ctx.unresolved.missing) || []
99
+ if (missing.length === 0) {
100
+ el.textContent = ''
101
+ el.hidden = true
102
+ return
103
+ }
104
+ const count = missing.length === 1
105
+ ? '1 field no longer matches this page'
106
+ : `${missing.length} fields no longer match this page`
107
+ el.textContent = `${count}: ${missing.join(', ')}`
108
+ el.hidden = false
109
+ }
110
+
111
+ // Two elements matching one scalar rule still works, since the write lands on
112
+ // the first, so this is a console note rather than a notice. Runtime duplicates
113
+ // (a carousel cloning slides, a dialog holding a second copy) are ordinary.
114
+ // Signature-gated because the walk reruns on every refresh.
115
+ function warnTwins(ctx) {
116
+ const twins = (ctx.unresolved && ctx.unresolved.twins) || []
117
+ const signature = twins.map((t) => `${t.path}:${t.count}`).join('|')
118
+ if (signature === ctx.lastTwinSignature) return
119
+ ctx.lastTwinSignature = signature
120
+ for (const { path, count } of twins) {
121
+ console.warn(`${PREFIX} "${path}" matches ${count} elements; edits go to the first one.`)
122
+ }
123
+ }
124
+
125
+ function unique(list) {
126
+ return [...new Set(list)]
127
+ }
128
+
129
+ function uniqueTwins(list) {
130
+ const byPath = new Map()
131
+ for (const twin of list) {
132
+ const seen = byPath.get(twin.path)
133
+ if (!seen || twin.count > seen.count) byPath.set(twin.path, twin)
134
+ }
135
+ return [...byPath.values()]
136
+ }
137
+
138
+ function pathStr(path) {
139
+ return path.length ? path.join('.') : '(whole page)'
140
+ }