mnfst 0.5.319 → 0.5.321
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/manifest.appwrite.data.js +1 -1
- package/lib/manifest.data.js +1 -1
- package/lib/manifest.data.min.js +1 -1
- package/lib/manifest.edit.js +235 -16
- package/lib/manifest.edit.min.js +1 -1
- package/lib/manifest.edit.min.js.map +1 -1
- package/lib/manifest.integrity.json +10 -10
- package/lib/manifest.js +2 -2
- package/lib/manifest.min.js +1 -1
- package/lib/manifest.modules.integrity.json +7 -7
- package/lib/manifest.sw.js +1 -1
- package/lib/manifest.sw.min.js +1 -1
- package/package.json +1 -1
package/lib/manifest.edit.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(){const t=t=>"mnfst-edit-log:"+(t||location.pathname);let e=location.pathname;const n=["text","move","size","data"],r=["text","move"],o=["move","remove","duplicate","text","attrs","size"],i={sort:".move",authoring:"nothing (visuals are on by default; use .bare to hide them, .persist to keep edits)",style:"$edit.classes / $edit.attr",none:".lock"};let s=null,a=0,l=[],c=0;const d={},u=new WeakSet,f=["x-html","x-text","x-markdown","x-icon","x-svg","x-code","x-code-group","x-chart","x-anchors","x-carousel","x-color","x-colorpicker","x-combobox","x-date","x-defer","x-virtual","x-import"],m=t=>[...t.attributes].some(t=>{const e=t.name.toLowerCase();return f.some(t=>e===t||e.startsWith(t+"."))}),p=new Set(["SCRIPT","STYLE","TEXTAREA","TITLE","NOSCRIPT","TEMPLATE","XMP","IFRAME","NOEMBED","NOFRAMES"]),h=t=>[...t.children].find(t=>"TEMPLATE"===t.tagName&&t.hasAttribute("x-for"))||null;function g(t){if(m(t))return"";let e="";for(const n of t.childNodes)3===n.nodeType?e+=n.textContent:1!==n.nodeType||bt(n)||"TEMPLATE"===n.tagName||A(n)||n._manifestComponent||(e+=g(n));return e}const b=t=>t.tagName.toUpperCase()+":"+g(t).replace(/\s+/g," ").trim().slice(0,24),y=(t,e)=>"@"+encodeURIComponent(t)+"@"+e,v=t=>t&&"~"===t[0]?t.slice(t.indexOf("~",1)+1):t;let E=0;const w=()=>Date.now().toString(36)+(++E).toString(36)+Math.random().toString(36).slice(2,6);function A(t){for(let e=t.previousElementSibling;e;e=e.previousElementSibling){if("TEMPLATE"!==e.tagName)continue;if(e._x_currentIfEl===t)return!0;const n=e._x_lookup;if(n&&(n instanceof Map?[...n.values()]:Object.values(n)).includes(t))return!0}return!1}function k(t){const e=Object.create(null);return kt(t).map(t=>{const n=t.getAttribute("data-edit-host")||t.getAttribute("data-edit-key");if(n)return n;const r=b(t),o=e[r]=(e[r]||0)+1;return o>1?r+"#"+o:r})}let _=[];const x=new WeakSet,S=new Set([location.pathname]),T=e=>{if(l.length>400){const t=l.length-400;l.splice(0,t),c=Math.max(0,c-t)}const n=l.slice(0,c).filter(t=>u.has(t)),r=l.slice(c).filter(t=>u.has(t));S.add(e||location.pathname);const o=_.filter(t=>x.has(t));(e?[e]:[...S]).forEach(e=>{try{n.length||r.length||o.length?localStorage.setItem(t(e),JSON.stringify(Object.assign({v:8,log:[...n,...r],cursor:n.length},o.length?{conflicts:o}:{}))):localStorage.removeItem(t(e))}catch{}})},C=(t,e)=>JSON.stringify(t)===JSON.stringify(e);function O(t,e){for(let n=t;n&&1===n.nodeType;n=n.parentElement){const t=getComputedStyle(n).getPropertyValue(e).trim();if(t)return t}return""}function L(t,e,n){const r=O(t,e);return r?"none"===r&&"--edit-size"!==e?n??"":r:n??""}function M(t,e){if(!e&&!/--rich-text-/.test(t))return t;const n=document.createElement("div");n.setAttribute("style",t),e&&n.style.removeProperty("position");const r=[];for(let t=0;t<n.style.length;t++)r.push(n.style.item(t));return r.filter(t=>t.startsWith("--rich-text-")).forEach(t=>n.style.removeProperty(t)),n.getAttribute("style")||""}const P=t=>M(t.getAttribute("style")||"",!!t._editPos),R=t=>t?t.tagName.toLowerCase():"",j=new Set(["B","I","EM","STRONG","U","S","SMALL","CODE","MARK","SUB","SUP","BR","SPAN","A"]),$=t=>!!t&&1===t.nodeType&&t.hasAttribute("data-rich-text")&&!t._editRt,N=t=>window.ManifestRichText.sanitize(t,!1,!0);let B=!1;const H=t=>{const e=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT),n=[];for(let t=e.nextNode();t;t=e.nextNode())n.push(t);return n},q=(t,e)=>!(X(e.name,e.value,t.tagName)||"style"===e.name&&/expression|url\s*\(|javascript:|@import/i.test(e.value));function D(t){const e=Nt.interactive.join(","),n=!!t.closest("a, button");return[...t.querySelectorAll(e)].forEach(r=>{const o=r.parentElement&&r.parentElement.closest(e);(n||o&&t.contains(o))&&r.replaceWith(...r.childNodes)}),t.innerHTML.trim()}const W=(t,e)=>window.ManifestRichText?$(t)?window.ManifestRichText.sanitize(e,!0,!0):function(t,e){const n=document.createElement("template");n.innerHTML=String(null==t?"":t);const r=[],o="mnfst"+Math.random().toString(36).slice(2)+Date.now().toString(36),i=new RegExp("("+o+"\\d+_)");if(H(n.content).forEach(t=>{if(e=t.data,!/^-?>|-->|--!>|<!-$/.test(e))return t.replaceWith(o+r.length+"_"),void r.push(t.data);var e;t.remove(),B||(B=!0,console.warn("[edit] a comment that cannot be written back as it is was left out of edited text"))}),n.innerHTML=N(n.innerHTML),r.length){const t=document.createTreeWalker(n.content,NodeFilter.SHOW_TEXT),e=[];for(let n=t.nextNode();n;n=t.nextNode())n.nodeValue.includes(o)&&e.push(n);e.forEach(t=>t.replaceWith(...t.nodeValue.split(i).filter(Boolean).map(t=>i.test(t)&&t.startsWith(o)?document.createComment(r[parseInt(t.slice(o.length),10)]):document.createTextNode(t))))}!function(t){const e=t=>{let e=t.lastChild;for(;e&&8===e.nodeType;)e=e.previousSibling;return e};for(let n=0;n<1e3;n++){let n=e(t);for(;n&&1===n.nodeType&&"BR"!==n.tagName&&e(n);)n=e(n);if(!n||n===t)return;if(!(3===n.nodeType?!n.nodeValue.trim():"BR"===n.tagName||!e(n)&&!/^(IMG|WBR)$/.test(n.tagName)))return;n.remove()}}(n.content),n.content.querySelectorAll("*").forEach(t=>[...t.attributes].forEach(e=>{q(t,e)||t.removeAttribute(e.name)}));const s=Nt.interactive.join(","),a=!!(e&&e.closest&&e.closest("a, button"));return[...n.content.querySelectorAll(s)].forEach(t=>{(a||t.parentElement&&t.parentElement.closest(s))&&t.replaceWith(...t.childNodes)}),n.content.querySelectorAll("a").forEach(t=>{t.textContent.trim()||t.querySelector("img")||t.replaceWith(...t.childNodes)}),n.innerHTML.trim()}(e,t):function(t){const e=document.createElement("template");e.innerHTML=String(null==t?"":t);const n=t=>[...t.childNodes].forEach(t=>{if(8===t.nodeType)return t.remove();1===t.nodeType&&(j.has(t.tagName)?([...t.attributes].forEach(e=>{const n=e.name.toLowerCase();("A"!==t.tagName||"href"!==n||X("href",e.value,"A"))&&t.removeAttribute(e.name)}),n(t)):t.replaceWith(document.createTextNode(t.textContent)))});return n(e.content),e.innerHTML}(e);function I(t,e){const n=W(t,e);t.innerHTML===n||$(t)&&W(t,t.innerHTML.trim())===n||(t.innerHTML=n,t._rt&&"function"==typeof t._rt.settle&&t._rt.settle())}const z={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:" ",tab:"\t",newline:"\n",colon:":"},F=t=>String(t).replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);?/gi,(t,e)=>{if("#"===e[0]){const n=/^#x/i.test(e)?parseInt(e.slice(2),16):parseInt(e.slice(1),10);return n>=0&&n<1114112?String.fromCodePoint(n):t}const n=z[e.toLowerCase()];return void 0===n?t:n}),K={script:["src","type"],iframe:["src","srcdoc"],embed:["src","srcdoc"],object:["src","srcdoc","data"],frame:["src","srcdoc"],link:["href","rel"],base:["href","rel"],meta:["http-equiv","content"]},U=new Set(["set","animate","animatetransform","animatemotion"]),J=/^data:image\/(png|jpeg|gif|webp|avif)[;,]/;function X(t,e,n){const r=String(t||"").trim().toLowerCase(),o=String(n||"").toLowerCase();if(!r||!/^[a-z_][\w:.-]*$/i.test(r))return/^[@:]/.test(r)?"Alpine directive":"invalid name";if("text"===r)return"reserved name";if("action"===r||"formaction"===r)return"form target";if(r.startsWith("on"))return"event handler attribute";if(r.startsWith("x-"))return"Alpine directive";if(r.startsWith("data-edit-"))return"plugin attribute";if("srcdoc"===r)return"inline document";if(U.has(o)&&["attributename","to","values","from","by"].includes(r))return"SVG animation target";if(K[o]&&K[o].includes(r))return"loads or runs content";if(null==e)return null;for(const t of[String(e),F(e)]){const e=t.replace(/[\u0000-\u0020\u007f]/g,"").toLowerCase();if(/(^|[,(;'"=])(javascript|vbscript):/.test(e))return"script URL";const n=e.match(/(^|[,(;'"=])data:[^,)]*/g)||[];if(n.length&&("img"!==o&&"source"!==o||"src"!==r&&"srcset"!==r||!n.every(t=>J.test(t.replace(/^[,(;'"=]/,"")))))return"data URL"}return null}const V=new Set,Y={},G=new Set,Q=t=>{const e=ct(t);for(let n=t&&t.parentElement;n;n=n.parentElement){if(m(n))return!0;if(n===e)break}return!1},Z=f.filter(t=>"x-code-group"!==t&&"x-carousel"!==t&&"x-defer"!==t);function tt(t){for(let e=t&&t.parentElement;e;e=e.parentElement){if(1!==e.nodeType)continue;const t=[...e.attributes].map(t=>t.name.toLowerCase()).find(t=>Z.some(e=>t===e||t.startsWith(e+".")));if(t)return t.split(".")[0]}return null}function et(t,e,s){if(e.includes("cssvar"))return function(t,e,n){const r=(e||"").trim(),o=r.match(/^([\w-]+)\s*:\s*(--[\w-]+)$/);t._cssvar=o?{scope:o[1],var:o[2]}:{scope:null,var:r},t._cssvar.persist=!(!n||!n.includes("persist")),Lr.add(t)}(t,s,e);if(e.forEach(t=>{i[t]&&!G.has(t)&&(G.add(t),console.warn(`[edit] x-edit.${t} was removed — use ${i[t]}`))}),e.includes("grab"))return;if(e.includes("lock")){const n=e.filter(t=>o.includes(t));return void(t._editLock=new Set(n.length?n:["*"]))}const l=new Set(n.filter(t=>e.includes(t))),c=e.includes("theme"),d=(s||"").trim()||"area-"+ ++a;if(c&&(Y[d]=t),c&&!l.size)return void(e.includes("persist")&&(t._editPersist=!0));l.size||r.forEach(t=>l.add(t)),(s||"").trim()&&[...V].some(e=>e!==t&&e._edit&&e._edit.key===d)&&console.warn("[edit] duplicate x-edit key (deltas will mis-route):",d);const u=e.includes("bare");t._edit={key:d,caps:l,gated:e.includes("gated"),theme:c,persist:e.includes("persist"),bare:u,rendered:tt(t)},t.setAttribute("data-edit-area",u?"bare":""),V.add(t),ot()}let nt=null;const rt=()=>nt||(nt=[...V].filter(t=>{for(let e=t;e;e=e.parentElement){if(e!==t&&e._edit)return!1;if(e._manifestComponent||e!==t&&m(e))return!0}return!0})),ot=()=>{nt=null},it=t=>rt().find(e=>e._edit.key===t),st=t=>rt().filter(e=>e._edit.key===t._edit.key).length>1;function at(t){if(void 0!==t._editSrc)return t._editSrc;let e=null;for(let n=t;n;n=n.parentElement){if(!n._manifestComponent)continue;const r=n===t&&window.ManifestComponentsLoader&&window.ManifestComponentsLoader.cache[n._manifestComponent],o=new RegExp("\\sx-edit(?:\\.[\\w-]+)*\\s*=\\s*([\"'])"+t._edit.key.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\1");(n!==t||r&&o.test(r))&&(e=n._manifestComponent);break}return t._editSrc=e}const lt=t=>{const e=at(t);return e?function(t){const e=window.ManifestComponentsRegistry&&window.ManifestComponentsRegistry.manifest||{},n=[...e.preloadedComponents||[],...e.components||[]].find(e=>String(e).split("/").pop().replace(".html","")===t);return String(n||"components/"+t+".html").replace(/^\/+/,"")}(e):"index.html"},ct=t=>t&&rt().reduce((e,n)=>n!==t&&!n.contains(t)||e&&!e.contains(n)?e:n,null),dt=t=>t._edit.key,ut=(t,e)=>{const n=function(t){for(let e=t;e;e=e.parentElement)if(e._edit)return e._edit;return null}(t);return!!n&&n.caps.has(e)&&!ke(t,e)},ft=t=>{const e=null!=t&&it(t);return!(!e||!e._edit.persist)};function mt(t){return h(t)?"data":t.matches("[data-component]")&&!at(t)||pt(t)?"component":"static"}const pt=t=>{const e=At(t).filter(t=>"TEMPLATE"!==t.tagName),n=e[0];return 1!==e.length||!n.matches("[data-component]")||n._edit||n.querySelector("[data-edit-area]")?null:n};function ht(t){const e=h(t),n=e&&e.getAttribute("x-for").match(/\bin\s+(.+)$/);return n?n[1].trim():null}const gt=t=>{const e=ht(t),n=e&&e.match(/\$x\.(\w+)/);return n?n[1]:e||"source"},bt=t=>t.hasAttribute("data-edit-handle")||t.hasAttribute("data-edit-ghost"),yt=t=>t&&t._manifestHost&&t._manifestHost.roots&&t._manifestHost.roots[0]===t?t._manifestHost.roots.slice():[t],vt=t=>!!t._manifestHost&&!!t._manifestHost.roots&&t._manifestHost.roots[0]!==t,Et=t=>!!t&&1===t.nodeType&&t.hasAttribute("data-edit-host"),wt=t=>t.getAttribute("data-edit-host")||t.getAttribute("data-edit-key"),At=t=>Array.from(t.children).filter(t=>!bt(t)&&!vt(t)),kt=t=>At(t).filter(t=>"TEMPLATE"!==t.tagName);let _t=!1;function xt(t,e){const n=t.getAttribute("data-key");if(null!=n)return n;const r=h(e),o=r&&r._x_keyExpression;if(o)try{const e=window.Alpine.evaluate(t,o);if(null!=e)return String(e)}catch{}return _t||(_t=!0,console.warn("[edit] data area rows have no identity — add :key to the x-for or :data-key to the row, or the order cannot be stored")),null}const St=new Set(["P","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE","SPAN","A","LABEL","STRONG","EM","B","I","U","S","SMALL","CODE","MARK","SUB","SUP","Q","CITE","ABBR","TIME","DT","DD","FIGCAPTION","CAPTION","LEGEND","SUMMARY","BUTTON","OPTION"]),Tt=new Set(["AREA","BASE","BR","COL","EMBED","HR","IMG","INPUT","LINK","META","PARAM","SOURCE","TRACK","WBR","VIDEO","AUDIO","CANVAS","SVG","svg","IFRAME","OBJECT","SELECT","TEXTAREA","PICTURE","MATH","math","TEMPLATE","SCRIPT","STYLE","NOSCRIPT","TITLE","XMP"]),Ct=new Set([...St,"LI","TD","TH"]);function Ot(t){if(!window.ManifestRichText)return!1;const e=t.cloneNode(!0);return e.querySelectorAll("[data-edit-handle], [data-edit-ghost]").forEach(t=>t.remove()),H(e).forEach(t=>t.remove()),!e.children.length||(e.querySelectorAll("*").forEach(t=>[...t.attributes].forEach(e=>{e.name.startsWith("data-edit-")&&t.removeAttribute(e.name)})),N(e.innerHTML)===e.innerHTML&&[...e.querySelectorAll("*")].every(t=>[...t.attributes].every(e=>q(t,e))))}const Lt=t=>Ct.has(t.tagName)&&At(t).length>0&&!!t.textContent.trim()&&Ot(t),Mt=t=>{for(let e=t&&t.parentElement;e&&1===e.nodeType;e=e.parentElement){if(e._editRtFormat)return e;if(e._edit)break}return null};function Pt(t){return!(!t||1!==t.nodeType||Tt.has(t.tagName)||bt(t)||(t=>St.has(t.tagName)||t.hasAttribute("data-rich-text")||(t=>[...t.childNodes].some(t=>3===t.nodeType&&t.textContent.trim()))(t)||Lt(t))(t))}function Rt(t){const e=[];let n=t.previousSibling;for(;;){let t=null;if(n&&3===n.nodeType){if(!/^[ \t]*(\r?\n)?[ \t]*$/.test(n.textContent))break;t=n,n=n.previousSibling}if(!n||8!==n.nodeType)break;let r=n.previousSibling;for(;r&&3===r.nodeType&&!r.textContent.trim();)r=r.previousSibling;if(!r)break;e.unshift(n,...t?[t]:[]),n=n.previousSibling}return e}const jt=t=>t?Rt(t)[0]||t:null;function $t(t,e){const n=Rt(t),r=yt(t).slice(1);e(t),n.length&&t.before(...n),r.length&&t.after(...r)}const Nt={only:{table:["caption","colgroup","thead","tbody","tfoot","script","template","style"],thead:["tr","script","template"],tbody:["tr","script","template"],tfoot:["tr","script","template"],tr:["td","th","script","template"],colgroup:["col","template"],ul:["li","script","template"],ol:["li","script","template"],menu:["li","script","template"],dl:["dt","dd","div","script","template"],select:["option","optgroup","hr","script","template"],datalist:["option","script","template"],optgroup:["option","script","template"]},parent:{tr:["thead","tbody","tfoot"],td:["tr"],th:["tr"],caption:["table"],colgroup:["table"],col:["colgroup"],thead:["table"],tbody:["table"],tfoot:["table"],li:["ul","ol","menu"],dt:["dl","div"],dd:["dl","div"],option:["select","datalist","optgroup"],optgroup:["select"]},interactive:["a","button","input","select","textarea","details","label","iframe","embed","object","audio","video","keygen"],phrasingOnly:["p","h1","h2","h3","h4","h5","h6","pre"],block:["address","article","aside","blockquote","details","dialog","div","dl","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","hr","main","menu","nav","ol","p","pre","search","section","table","ul","li","dd","dt"]};function Bt(t,e){if(!t||!e)return!1;if(t.parentElement===e)return!0;const n=[];for(let t=e;t&&1===t.nodeType;t=t.parentElement)n.push(t.tagName.toLowerCase());const r=new Set,o=t=>[t,...t.querySelectorAll("*")].forEach(t=>{1===t.nodeType&&(r.add(t.tagName.toLowerCase()),"TEMPLATE"===t.tagName&&t.content&&[...t.content.children].forEach(o))});yt(t).forEach(o);const i=new Set;for(let t=e;t;t=t.parentElement)t._manifestComponent&&i.add(t._manifestComponent);return!(i.size&&yt(t).some(t=>[t,...t.querySelectorAll("*")].some(t=>t._manifestComponent&&i.has(t._manifestComponent)))||function(t,e,n,r){const o=Nt;return o.only[e]&&!o.only[e].includes(t)?`<${e}> takes only ${o.only[e].filter(t=>"script"!==t&&"template"!==t&&"style"!==t).join(", ")}`:o.parent[t]&&!o.parent[t].includes(e)?`<${t}> belongs in ${o.parent[t].join(" or ")}`:"dt"!==t&&"dd"!==t||"div"!==e||"dl"===n[1]?r.has("form")&&n.includes("form")?"a form cannot contain a form":(n.includes("a")||n.includes("button"))&&o.interactive.some(t=>r.has(t))?"interactive content cannot go inside a link or button":o.phrasingOnly.includes(e)&&o.block.some(t=>r.has(t))?`<${e}> takes only inline content`:null:`<${t}> belongs in a dl`}(t.tagName.toLowerCase(),e.tagName.toLowerCase(),n,r))}const Ht=t=>{const e=String(t||"").match(/[a-z%]+$/i);return e?e[0]:null};function qt(t,e,n,r,o){if("rem"===e)return+(t/parseFloat(getComputedStyle(document.documentElement).fontSize)).toFixed(2);if("em"===e)return+(t/parseFloat(getComputedStyle(n).fontSize)).toFixed(2);if("%"===e){const e=(r||n.parentElement).getBoundingClientRect(),i="w"===o?e.width:e.height;return i?+(t/i*100).toFixed(2):0}return Math.round(t)}function Dt(t,e,n){const r=parseFloat(t);if(isNaN(r))return null;const o=Ht(t)||"px";if("rem"===o)return r*parseFloat(getComputedStyle(document.documentElement).fontSize);if("em"===o)return r*parseFloat(getComputedStyle(e).fontSize);if("%"===o){const t=(e.parentElement||e).getBoundingClientRect();return r/100*("h"===n?t.height:t.width)}return r}const Wt=(t,e,n)=>Math.min(Math.max(t,e),n),It="∅revert";let zt=0;const Ft=new WeakMap;function Kt(t,e){return l.splice(c),l.push(t),c=l.length,zt++,void 0===e&&(e=function(t){return"data-splice"!==t.kind&&"show"!==t.kind&&("st-move"===t.kind?ft(t.from)&&ft(t.to):null!=t.region&&ft(t.region))}(t)),e&&u.add(t),T(),jo(),t}function Ut(t,e){return"data"===e?{source:gt(t),order:kt(t).map(e=>xt(e,t))}:{}}async function Jt(t,e,n){t&&n&&("data"===e&&Xt(t,n.order),Qr(t)&&Jr(t))}function Xt(t,e){const n=ht(t),r=h(t);try{const t=window.Alpine.evaluate(r,n);if(!Array.isArray(t))return;const o=new Map(t.map(t=>[String(t.id),t])),i=e.map(t=>o.get(String(t))).filter(Boolean);t.forEach(t=>{e.map(String).includes(String(t.id))||i.push(t)}),t.splice(0,t.length,...i)}catch{}}function Vt(){const t={},e={},n={},r={};for(let o=0;o<c;o++){const i=l[o];if("cmp-main"!==i.kind&&"cmp-inst"!==i.kind||i.sig&&(r[i.component+"|"+i.path]=i.sig),"cmp-main"===i.kind)t[i.component]=t[i.component]||{},(t[i.component][i.path]=t[i.component][i.path]||{})[i.prop]=i.value;else if("cmp-inst"===i.kind){const t=i.region;i.value===It?(n[t]=n[t]||new Set,"*"===i.path?(delete e[t],n[t]=new Set(["*"])):(e[t]&&delete e[t][i.path],n[t].add(i.path))):(e[t]=e[t]||{},(e[t][i.path]=e[t][i.path]||{})[i.prop]=i.value,n[t]&&(n[t].delete(i.path),n[t].delete("*")))}}return{main:t,inst:e,reverts:n,sigs:r}}const Yt=t=>[t,...t.querySelectorAll("*")].filter(t=>null!=t._editPath);function Gt(){const{main:t,inst:e,sigs:n}=Vt();rt().forEach(r=>{if("component"!==mt(r))return;const o=fr(r),i=dt(r),s=pt(r);s&&Yt(s).forEach(s=>{const a=s._editPath,l=n[o+"|"+a];if(l&&R(s)!==l)return void console.warn("[edit] skip stale node (structure changed):",o,a);const c=e[i]&&e[i][a]||{},d=t[o]&&t[o][a]||{},u=r._baseText||{},f=r._baseClass||{},m=r._baseStyle||{},p=(t,e)=>void 0!==c[t]?c[t]:void 0!==d[t]?d[t]:e,h=p("text",u[a]),g=p("class",f[a]),b=p("style",m[a]);void 0!==h&&I(s,h),void 0!==g&&wr(s,g),void 0!==b&&s.getAttribute("style")!==b&&(""===b?s.removeAttribute("style"):s.setAttribute("style",b))})})}function Qt(t,e,n,r,o){const i=e._editPath,s=t._editScope||"instance",a=fr(t),l=dt(t);if(null==i)return!1;if("text"===n&&(r=W(e,r)),void 0===o&&(o="text"===n?e._preEdit:"style"===n?e._preStyle:e._preClass),o===r||"text"===n&&null!=o&&W(e,o)===r)return!1;const c=R(e);return Kt("main"===s?{kind:"cmp-main",component:a,path:i,prop:n,value:r,before:o,sig:c,region:l}:{kind:"cmp-inst",component:a,region:l,path:i,prop:n,value:r,before:o,sig:c}),Gt(),!0}function Zt(){const t={},e={},n={},r={},o={},i={},s=(t,e,n,r,o)=>{if(!r)return;const i=t[e]=t[e]||{},s=n||"";o&&s in i||(i[s]=r.slice())};for(let t=0;t<l.length;t++){const e=l[t];if("st-children"===e.kind)e.html&&Object.assign(i,e.html),s(n,e.region,e.parent,e.before,!0);else if("st-order"===e.kind)s(n,e.region,e.parent,e.before,!0);else if("st-move"===e.kind)s(n,e.from,e.fromParent,e.fromBefore,!0),s(n,e.to,e.toParent,e.toBefore,!0);else if("st-node"===e.kind){const t=o[e.path]=o[e.path]||{};e.prop in t||(t[e.prop]=e.before),e.sig&&(r[e.path]=e.sig)}}const a=new Set;for(let n=0;n<c;n++){const r=l[n];"st-node"===r.kind?(t[r.path]=t[r.path]||{})[r.prop]=r.value:"st-order"===r.kind||"st-children"===r.kind?(s(e,r.region,r.parent,r.order),a.add(r.parent||"#"+r.region),r.copies&&Object.entries(r.copies).forEach(([e,n])=>{t[e]=Object.assign({},n,t[e])})):"st-move"===r.kind&&(s(e,r.from,r.fromParent,r.fromOrder),s(e,r.to,r.toParent,r.toOrder),a.add(r.fromParent||"#"+r.from),a.add(r.toParent||"#"+r.to))}return{node:t,order:e,orderBase:n,sigs:r,base:o,html:i,touched:a}}function te(t,e,n,r){Kt({kind:"data-splice",region:dt(t),source:gt(t),index:e,op:r,record:JSON.parse(JSON.stringify(n))}),setTimeout(()=>{d[dt(t)]=Ut(t,mt(t))},0)}const ee=(t,e)=>t===e?"":t.getAttribute("data-edit-key")||"";function ne(t,e,n,r,o){const i=k(e);if(C(n,i)&&!Object.keys(r||{}).length)return;const s={kind:"st-children",region:dt(t),parent:ee(e,t),order:i,before:n,html:r||{}};o&&Object.keys(o).length&&(s.copies=o),Kt(s)}const re=(t,e)=>{if(!t)return null;const n=document.createElement("template");n.innerHTML=t.trim();const r=n.content.firstElementChild;return r&&e&&r.setAttribute(/^[^@]*@[^@]*@X-[\w-]+:/.test(v(e))?"data-edit-host":"data-edit-key",e),r},oe=()=>rt().filter(t=>"static"===mt(t)&&!st(t)),ie=new Map;function se(t){const e=new Map;return t.forEach(t=>[t,...t.querySelectorAll("[data-edit-key]")].forEach(t=>{if(t.closest("[data-edit-ghost]"))return;const n=t.getAttribute("data-edit-key");null==n||e.has(n)||e.set(n,t)})),t.forEach(t=>t.querySelectorAll("[data-edit-host]").forEach(t=>{const n=t.getAttribute("data-edit-host");e.has(n)||e.set(n,t)})),e}function ae(t){const e=se(oe()),n=[],r=new Set(t.filter(t=>t._marked).map(dt)),o=t=>r.has(t)&&!!it(t)&&"static"===mt(it(t)),i=new Map,s=new Map,a=new Map,d=(t,e,n)=>{const r=JSON.stringify([t,e]);!i.has(r)&&o(t)&&i.set(r,[t,e,n||[]])};l.forEach(t=>{"st-order"!==t.kind&&"st-children"!==t.kind||d(t.region,t.parent,t.before),"st-move"===t.kind&&(d(t.from,t.fromParent,t.fromBefore),d(t.to,t.toParent,t.toBefore))});const u=t=>String(t).slice(String(t).indexOf("@",1)+1).split(":")[0],f=(t,e)=>{const n=new Set,r=(t,e)=>{e=e||[],(t=t||[]).forEach(t=>{e.includes(t)||n.add(t)}),e.forEach(e=>{t.includes(e)||n.add(e)});const r=e.filter(e=>t.includes(e)).map(e=>t.indexOf(e)),o=[],i=new Array(r.length).fill(-1);r.forEach((t,e)=>{let n=0,s=o.length;for(;n<s;){const e=n+s>>1;r[o[e]]<t?n=e+1:s=e}n>0&&(i[e]=o[n-1]),o[n]=e});const s=new Set;for(let t=o.length?o[o.length-1]:-1;t>=0;t=i[t])s.add(t);e.filter(e=>t.includes(e)).forEach((t,e)=>{s.has(e)||n.add(t)})};return l.forEach(o=>{"st-order"!==o.kind&&"st-children"!==o.kind||o.region!==t||(o.parent||"")!==e||r(o.before,o.order),"st-move"===o.kind&&(o.from===t&&(o.fromParent||"")===e&&(n.add(o.key),r(o.fromBefore,o.fromOrder)),o.to===t&&(o.toParent||"")===e&&(n.add(o.key),r(o.toBefore,o.toOrder)))}),n};i.forEach(([t,n,r])=>{let o=""===n?it(t):e.get(n),i=null;if(!o&&""!==n){const t=new Set(r.map(t=>e.get(t)).filter(Boolean).map(t=>t.parentElement));1===t.size&&(o=[...t][0],i=o.getAttribute("data-edit-key"))}const c=o?k(o):[];if(o&&c.join("\n")===r.join("\n")&&!i)return;const d=[];r.forEach((t,e)=>{c[e]!==t&&d.push({was:t,now:c[e]??null})}),c.slice(r.length).forEach(t=>d.push({was:null,now:t}));const m=f(t,n),p=!!o&&c.length===r.length&&r.every((t,e)=>u(t)===u(c[e])),h=new Set;l.forEach(t=>[t.before,t.order,t.fromBefore,t.toBefore,t.fromOrder,t.toOrder].forEach(t=>Array.isArray(t)&&t.forEach(t=>h.add(t))));const g=t=>{const e=t.cloneNode(!1);return[...e.attributes].forEach(t=>{/^(data-edit-|data-rich-text|contenteditable$|role$|aria-multiline$|tabindex$)/.test(t.name)&&e.removeAttribute(t.name)}),e.outerHTML.replace(/<\/[^>]+>$/,"")},b=t=>!!t.was&&!!t.now&&"@"===t.was[0]&&!e.has(t.was)&&!h.has(t.now)&&(()=>{const n=(t=>{for(const e of l)if("st-children"===e.kind&&e.html)for(const[n,r]of Object.entries(e.html))if("~"===n[0]&&v(n)===t){const t=document.createElement("template");t.innerHTML=r;const e=t.content.firstElementChild;if(e)return g(e)}return null})(t.was),r=e.get(t.now);return!n||!r||n===g(r)})();if(p&&d.every(t=>b(t)&&!m.has(t.was))){const e=a.get(t)||new Map;d.forEach(t=>e.set(t.was,t.now)),i&&i!==n&&e.set(n,i),a.set(t,e)}else s.set(t,[...s.get(t)||[],{container:n,changed:d.map(t=>({was:t.was&&u(t.was)&&t.was.slice(t.was.indexOf("@",1)+1),now:t.now&&t.now.slice(t.now.indexOf("@",1)+1)}))}])}),a.forEach((t,n)=>{if(s.has(n))return;const r=e=>"string"!=typeof e?e:t.has(e)?t.get(e):"~"===e[0]&&t.has(v(e))?e.slice(0,e.length-v(e).length)+t.get(v(e)):e,o=t=>Array.isArray(t)?t.map(r):t,i=t=>"string"==typeof t?t.replace(/data-edit-key="([^"]*)"/g,(t,e)=>`data-edit-key="${(t=>t.replace(/&/g,"&").replace(/"/g,"""))(r((t=>t.replace(/"/g,'"').replace(/&/g,"&"))(e)))}"`):t,a=(n,r)=>{if("~"!==n[0]||!t.has(v(n))||(t=>l.some(e=>"st-node"===e.kind&&e.path===t&&"text"===e.prop))(n))return i(r);const o=e.get(t.get(v(n)));if(!o)return i(r);const s=document.createElement("template");s.innerHTML=We(o,!0);const a=n.slice(0,n.length-v(n).length);return[s.content.firstElementChild,...s.content.firstElementChild.querySelectorAll("[data-edit-key]")].forEach(t=>{const e=t.getAttribute("data-edit-key");e&&"@"===e[0]&&t.setAttribute("data-edit-key",a+e)}),s.innerHTML};l.forEach(t=>{var e;"st-order"!==t.kind&&"st-children"!==t.kind||t.region!==n||(t.parent=r(t.parent),t.before=o(t.before),t.order=o(t.order),t.html&&(t.html=(e=t.html)&&"object"==typeof e?Object.fromEntries(Object.entries(e).map(([t,e])=>[r(t),a(t,e)])):e),t.copies&&(t.copies=Object.fromEntries(Object.entries(t.copies).map(([t,e])=>[r(t),e])))),"st-node"===t.kind&&t.region===n&&"string"==typeof t.path&&"~"===t.path[0]&&(t.path=r(t.path)),"st-move"!==t.kind||t.from!==n&&t.to!==n||(t.key=r(t.key),t.fromParent=r(t.fromParent),t.toParent=r(t.toParent),t.fromBefore=o(t.fromBefore),t.toBefore=o(t.toBefore),t.fromOrder=o(t.fromOrder),t.toOrder=o(t.toOrder)),"lock"===t.kind&&t.region===n&&(t.key=r(t.key))}),zt++});const m=t=>("st-order"===t.kind||"st-children"===t.kind)&&s.has(t.region)||"st-move"===t.kind&&(s.has(t.from)||s.has(t.to))||"st-node"===t.kind&&s.has(t.region)&&"string"==typeof t.path&&"~"===t.path[0],p=t=>"st-node"===t.kind&&"string"==typeof t.path&&"@"===t.path[0]&&o(t.region)&&!e.has(t.path)||m(t);if(l.forEach((t,e)=>{p(t)&&e<c&&"st-node"===t.kind&&"@"===t.path[0]&&n.push(t)}),!l.some(p))return a.size&&T(),[];const h=new Map;n.forEach(t=>h.set(t.path+"|"+t.prop,t));const g=t=>"string"==typeof t?v(t).slice(v(t).indexOf("@",1)+1):"",b=[...h.values()].map(t=>({region:t.region,key:t.path,element:g(t.path),prop:t.prop,value:t.value,before:t.before,reason:`${g(t.path)} changed in the source, so the ${"text"===t.prop?"text":t.prop} edited into it was not applied`}));s.forEach((t,e)=>{const n=l.filter((t,n)=>n<c&&m(t)&&(t.region===e||t.from===e||t.to===e)),r=new Set,o=[];n.forEach(t=>{"st-move"===t.kind&&r.add(t.key),"st-order"!==t.kind&&"st-children"!==t.kind||f(e,t.parent||"").forEach(t=>r.add(t)),"st-children"===t.kind&&t.html&&Object.entries(t.html).forEach(([t,e])=>{if("~"!==t[0])return;const n=document.createElement("template");n.innerHTML=e;const r=l.filter((e,n)=>n<c&&"st-node"===e.kind&&e.path===t&&"text"===e.prop).pop();o.push({of:g(t),html:e,text:r?r.value:n.content.textContent.trim()})})});const i=t.flatMap(t=>t.changed),s=[...new Set(i.map(t=>t.was||t.now))],a=[...new Set([...r].filter(t=>t&&"@"===t[0]).map(g))],d=[a.length&&`moved ${a.join(", ")}`,o.length&&`copied ${o.map(t=>`${t.of} ("${String(t.text).slice(0,40)}")`).join(", ")}`].filter(Boolean).join("; ");b.push({region:e,key:"",element:t.map(t=>t.container?g(t.container):e).join(", "),prop:"structure",value:{changed:i,moved:a,copies:o},before:null,reason:`${s.join(", ")} changed in the source where the layout was edited, so the layout edits (${d||"reordering"}) were not applied`})}),b.forEach(t=>{_.push(t),ft(t.region)&&x.add(t)});let y=0;return l=l.filter((t,e)=>{const n=!p(t);return n&&e<c&&y++,n}),c=y,zt++,T(),jo(),b.length&&(Vr&&(Vr.conflicts=_.slice()),console.warn("[edit] edits to elements that changed in the source were dropped:\n"+b.map(t=>" "+t.reason+("structure"===t.prop?"":`: "${String(t.value).slice(0,80)}"`)).join("\n")),document.dispatchEvent(new CustomEvent("edit:conflict",{detail:{conflicts:b}}))),b}function le(){const{node:t,order:e,orderBase:n,sigs:r,base:o,html:i}=Zt(),s=se(oe()),a=[];new Set([...Object.keys(n),...Object.keys(e)]).forEach(t=>{const r=Object.assign({},n[t]||{},e[t]||{});Object.entries(r).forEach(([e,n])=>a.push([t,e,n]))});const l=new Set;a.forEach(([,,t])=>t.forEach(t=>l.add(t)));const c=new Set,d=t=>{let e=s.get(t);return!e&&ie.has(t)&&(e=ie.get(t),ie.delete(t),s.set(t,e)),!e&&i[t]&&(e=re(i[t],t),e&&(s.set(t,e),e.querySelectorAll("[data-edit-key]").forEach(t=>{const e=t.getAttribute("data-edit-key");s.has(e)||s.set(e,t)}))),e};let u=!0;for(;a.length&&u;){u=!1;for(let t=0;t<a.length;t++){const[e,n,r]=a[t],o=n?s.get(n):it(e);if(!o||!o.isConnected)continue;a.splice(t--,1),u=!0;let f=kt(o);const m=r.map(d).filter(t=>t&&t!==o&&!t.contains(o)),p=f.filter(t=>!m.includes(t)&&!l.has(wt(t))&&!i[wt(t)]),h=[...m,...p].flatMap(yt);if(f=f.flatMap(yt),h.length===f.length&&h.every((t,e)=>t===f[e]))continue;const g=f.length?f[f.length-1].nextSibling:Array.from(o.children).find(bt)||null,b=new Map(h.map(t=>[t,t.isConnected?Rt(t):t._editLead||[]]));f.forEach(t=>{if(h.includes(t))return;t._editLead=Rt(t),t._editLead.forEach(t=>t.remove()),t.remove();const e=wt(t);e&&ie.set(e,t)}),h.forEach(t=>{const e=ct(t);e&&c.add(e),o.insertBefore(t,g&&g.parentNode===o?g:null);const n=b.get(t);n.length&&t.before(...n)});const y=ct(o);y&&c.add(y)}}c.size&&ot(),(c.size?se(oe()):s).forEach((e,n)=>{const i=t[n],s=o[n];if(!i&&!s)return;const a=r[n];a&&R(e)!==a?console.warn("[edit] skip stale static node",n):new Set([...Object.keys(i||{}),...Object.keys(s||{})]).forEach(t=>function(t,e,n){if(void 0!==n){if("text"===e)return I(t,n);if(!X(e,n,t.tagName))return"class"===e?wr(t,n):"style"===e?function(t,e){null==e||""===e?t.removeAttribute("style"):t.getAttribute("style")!==e&&t.setAttribute("style",e),t._editPos&&!t.style.position&&(t.style.position="relative")}(t,n):void(null!==n?t.getAttribute(e)!==n&&t.setAttribute(e,n):t.removeAttribute(e))}}(e,t,i&&void 0!==i[t]?i[t]:s&&s[t]))}),c.forEach(t=>{t.isConnected&&(zr(t),t._armed&&Qr(t)&&Jr(t))})}function ce(t,e,n,r,o={}){const i=dt(t),s=e.getAttribute("data-edit-key");if(!s||"!"===s[0])return!1;if("text"===n&&p.has(e.tagName))return!1;"text"===n&&(r=W(e,r));let a=o.before;if(void 0===a){const r="text"===n?t._baseText&&t._baseText[s]:"class"===n?t._baseClass&&t._baseClass[s]:"style"===n?t._baseStyle&&t._baseStyle[s]:e.getAttribute(n),o="text"===n?e._preEdit:"class"===n?e._preClass:"style"===n?e._preStyle:void 0;a=void 0!==o?o:r}if(a===r||"text"===n&&null!=a&&W(e,a)===r)return!1;"text"!==n||document.activeElement===e||$(e)||I(e,r);const d=l[c-1];if(o.coalesce&&d&&c===l.length&&"st-node"===d.kind&&d.region===i&&d.path===s&&d.prop===n&&Date.now()-(Ft.get(d)||0)<1e3)return d.before===r?(l.pop(),c--):(d.value=r,Ft.set(d,Date.now())),zt++,T(),jo(),!0;const u=Kt(Object.assign({kind:"st-node",region:i,path:s,prop:n,value:r,before:a,sig:R(e)},o.join?{join:!0}:{}));return o.coalesce&&Ft.set(u,Date.now()),!0}function de(){const t={};for(let e=0;e<c;e++){const n=l[e];"data-val"===n.kind&&(((t[n.source]=t[n.source]||{})[n.id]=t[n.source][n.id]||{})[n.field]=n.value)}return t}function ue(){const t=de(),e=new Map;l.forEach(t=>{if("data-val"===t.kind){const n=JSON.stringify([t.source,t.id,t.field]);e.has(n)||e.set(n,t)}}),e.forEach(e=>{const n=(t[e.source]=t[e.source]||{})[e.id]=t[e.source][e.id]||{};e.field in n||void 0===e.before||(n[e.field]=e.before)}),rt().forEach(e=>{if("data"!==mt(e))return;const n=gt(e),r=t[n];if(!r)return;const o=h(e),i=ht(e);try{const t=window.Alpine.evaluate(o,i);Array.isArray(t)&&Object.entries(r).forEach(([e,n])=>{const r=t.find(t=>String(t.id)===String(e));r&&Object.entries(n).forEach(([t,e])=>{r[t]!==e&&(r[t]=e)})})}catch{}Qr(e)&&setTimeout(()=>ur(e),0)})}function fe(t,e,n){const r=P(e),o=mt(t);return"component"===o?Qt(t,e,"style",r):"static"===o&&ce(t,e,"style",r,n)}function me(t,e,n){const r=k(e);return!C(n,r)&&(Kt({kind:"st-order",region:dt(t),parent:ee(e,t),order:r,before:n}),!0)}function pe(t,e,n,r,o,i,s={}){const a=n.parentElement,l={kind:"st-move",from:dt(t),to:dt(e),fromParent:ee(r,t),toParent:ee(a,e),key:wt(n),fromOrder:k(r),toOrder:k(a),fromBefore:o,toBefore:i};return s.join&&(l.join=!0),Kt(l),ot(),zr(e),Qr(t)&&Jr(t),e!==t&&Qr(e)&&Jr(e),l}const he=(t,e)=>/^[~@]/.test(e)?e:t+"|"+e;let ge=-1,be=new Map;function ye(){if(ge===zt)return be;be=new Map;for(let t=0;t<c;t++){const e=l[t];if("lock"!==e.kind)continue;const n=he(e.region,e.key),r=be.get(n)||new Map;be.set(n,r),(e.actions&&e.actions.length?e.actions:o).forEach(t=>r.set(t,e.value))}return ge=zt,be}const ve=()=>ye();function Ee(t,e){const n=mt(e);if("static"===n)return t.getAttribute("data-edit-key");if(t===e)return"";if("component"===n)return null!=t._editPath?"path:"+t._editPath:null;const r=h(e);if(r&&t.parentElement===r.parentElement){const n=xt(t,e);return null==n?null:"row:"+n}return null}const we=t=>"data"===t?"text":"class"===t?"attrs":t,Ae=t=>Et(t)?t:vt(t)?t._manifestHost.roots[0]:null;function ke(t,e){const n=we(e),r=t&&1===t.nodeType&&Ae(t);r&&(t=r);let o=r?Be(r):ct(t);const i=ye();for(let e=t;e&&1===e.nodeType;e=e.parentElement){let t;const s=Ae(e);if(s&&i.size){const e=i.get(s.getAttribute("data-edit-host"));e&&e.has(n)&&(t=e.get(n))}if(void 0===t&&o&&i.size&&(!s||e!==r)){const r=Ee(e,o),s=null!=r&&i.get(he(dt(o),r));s&&s.has(n)&&(t=s.get(n))}if(void 0===t&&e._editLock&&(t=e._editLock.has("*")||e._editLock.has(n)),t)return!0;if(e===o){if(s&&e!==r&&(o=Be(e),o))continue;break}}return!1}function _e(t,e,n){if(!t||1!==t.nodeType)return!1;const r=Ae(t),i=r?Be(r):ct(t);if(!i)return!1;if(null!=e&&!o.includes(e))return console.warn("[edit] unknown lock action:",e),!1;if(r)return Kt({kind:"lock",region:dt(i),key:r.getAttribute("data-edit-host"),actions:e?[e]:[],value:!!n}),xe(i),r._edit&&xe(r),!0;const s=Ee(t,i);return null==s?(console.warn("[edit] this element has no stable identity to lock"),!1):(Kt({kind:"lock",region:dt(i),key:s,actions:e?[e]:[],value:!!n}),xe(i),!0)}function xe(t){t&&t._armed&&(Xr(t),Qr(t)&&Jr(t))}const Se=t=>{"cmp-main"===t.kind||"cmp-inst"===t.kind?Gt():"data-val"===t.kind?ue():"theme"===t.kind?Dr():"lock"===t.kind?xe(it(t.region)):le()};function Te(t,e){if("show"===t.kind)return function(t,e){const n=it(t.region);if(!n)return;const r=""===t.key?n:[n,...n.querySelectorAll("[x-show]")].find(e=>Ee(e,n)===t.key);if(r)try{Vn(r,t.expr,e?t.before:t.value)}catch{}}(t,e),null;if("data-splice"===t.kind)!function(t,e){const n=it(t.region);if(!n)return;const r=h(n),o=ht(n);if(!r||!o)return;let i;try{i=window.Alpine.evaluate(r,o)}catch{return}Array.isArray(i)&&((e?"remove"===t.op:"insert"===t.op)?i.splice(Math.min(t.index,i.length),0,JSON.parse(JSON.stringify(t.record))):i.splice(t.index,1),setTimeout(()=>{d[t.region]=Ut(n,mt(n))},0))}(t,e);else{if("data"===t.kind){const n=e?t.before:t.after;return d[t.region]=n,Jt(it(t.region),t.kind,n)}Se(t)}return null}async function Ce(){if(0===c)return;let t;do{t=l[--c],zt++;const e=Te(t,!0);e&&await e}while(t.join&&c>0);Bo(),T(),jo()}async function Oe(){if(!(c>=l.length)){do{const t=l[c++];zt++;const e=Te(t,!1);e&&await e}while(c<l.length&&l[c].join);Bo(),T(),jo()}}function Le(){const t={};for(let e=0;e<c;e++){const n=l[e];"data"===n.kind&&(t[n.region]={kind:n.kind,snap:n.after})}return t}let Me=null,Pe=null;const Re=()=>{Vr&&(Vr.version=(Vr.version||0)+1)},je=t=>{Pe=t,Re()};function $e(t){t&&1!==t.nodeType&&(t=t.parentElement);const e=ct(t);if(Et(t)&&Be(t)&&"static"===mt(Be(t)))return t;if(!e||t===e)return null;const n=mt(e);if("data"===n){const n=h(e),r=n&&n.parentElement;for(let n=t;n&&n!==e;n=n.parentElement)if(n.parentElement===r)return n;return null}if("component"===n){for(let n=t;n&&n!==e;n=n.parentElement)if(null!=n._editPath)return n;return null}let r=null;for(let n=t;n&&n!==e;n=n.parentElement)(Et(n)||vt(n))&&(r=Et(n)?n:n._manifestHost.roots[0]);if(r)return r;for(let n=t;n&&n!==e;n=n.parentElement){if(bt(n))return null;if(Pt(n.parentElement))return n}return null}const Ne=t=>(t=>!!t&&1===t.nodeType&&$e(t)===t)(t)?t:$e(t),Be=t=>t&&ct(t.parentElement),He=t=>!!t&&(!!t._edit||t.hasAttribute("data-edit-area")),qe=t=>!!t&&!!t.parentElement&&!bt(t)&&!Q(t)&&ut(t.parentElement,"move")&&!ke(t,"move")&&"component"!==mt(ct(t.parentElement));function De(t){if(!t||1!==t.nodeType)return!1;const e=ct(t);if(!e||!Qr(e)||!Pt(t))return!1;for(let n=t;n&&n!==e;n=n.parentElement)if(n._manifestComponent)return!1;return ut(t,"move")}function We(t,e){const n=t.cloneNode(!0),r=[t,...t.querySelectorAll("*")];return[n,...n.querySelectorAll("*")].forEach((t,e)=>{sn.has(r[e])&&t.removeAttribute("tabindex")}),ar(t,n),n.querySelectorAll("[data-edit-handle], [data-edit-live], [data-edit-ghost]").forEach(t=>t.remove()),[n,...n.querySelectorAll("*")].forEach(t=>{[...t.attributes].forEach(n=>{!n.name.startsWith("data-edit-")||e&&"data-edit-key"===n.name||t.removeAttribute(n.name)}),t.removeAttribute("contenteditable"),t.removeAttribute("draggable")}),n.outerHTML}function Ie(t){const e=h(t),n=ht(t);if(!e||!n)return null;try{const t=window.Alpine.evaluate(e,n);return Array.isArray(t)?t:null}catch{return null}}const ze=(t,e)=>{const n=Ie(t);if(!n)return-1;const r=xt(e,t);return n.findIndex(t=>String(t&&null!=t.id?t.id:t)===String(r))};function Fe(t,e){const n=new Set(t.map(t=>String(t&&t.id)));if(!n.has(String(e)))return String(e);let r=2,o=`${e}-copy`;for(;n.has(o);)o=`${e}-copy-${r++}`;return o}const Ke=["move","remove","duplicate","text","attrs","class","size","copy","cut","paste"],Ue=t=>!(!t||!Me||"static"===mt(t)&&"static"!==Me.kind);function Je(t){const e=t?Ne(t):null;return e?De(e.parentElement)?e.parentElement:null:rt().find(t=>Qr(t)&&De(t))||null}function Xe(t,e){if(!Ke.includes(t))return!1;if("paste"===t){const t=Me&&Je(e);return!!t&&Ue(ct(t))}if(!e||1!==e.nodeType||Q(e))return!1;if(Et(e)&&("move"===t||"duplicate"===t||"remove"===t)){const n=Be(e);return!(!n||!Qr(n))&&("move"===t?qe(e):ut(e.parentElement,"move")&&!ke(e,t))}const n=ct(e);if(!n||!Qr(n))return!1;const r=mt(n);if("size"===t)return!!e._edit&&e._edit.caps.has("size")&&!ke(e,"size");if("text"===t)return ut(e,"text")&&!e.hasAttribute("x-text")&&!e.hasAttribute("x-html")&&("true"===e.getAttribute("contenteditable")||!!e._pieceMode||e.hasAttribute("data-rich-text")||null!=e._editField&&ut(e,"data"));if(("attrs"===t||"class"===t)&&"static"===r&&e._manifestComponent)return!1;if("attrs"===t||"class"===t){if("data"===r||ke(e,"attrs"))return!1;const n=Mt(e);if(n)return"attrs"===t&&ut(n,"text");if("component"===r)return"class"===t&&null!=e._editPath;const o=e.getAttribute("data-edit-key");return!!o&&"!"!==o[0]}if("component"===r)return!1;const o=Ne(e);if(!o)return!1;if("copy"===t)return!Et(o);if("cut"===t)return Xe("copy",o)&&Xe("remove",o);if("move"===t)return qe(o);const i="duplicate"===t?"duplicate":"remove";return ut(o.parentElement,"move")&&!ke(o,i)}function Ve(t){const e=Ne(void 0===t?Pe:t);if(!e)return!1;const n=Be(e);return!!n&&(Me={html:We(e,!0),ops:Ye(e),source:dt(n),kind:mt(n)},Re(),!0)}function Ye(t){const e=Zt(),n={};return[t,...t.querySelectorAll("[data-edit-key]")].forEach(t=>{const r=t.getAttribute("data-edit-key");r&&e.node[r]&&(n[r]=Object.assign({},e.node[r]))}),n}function Ge(t,e,n,r,o){const i=k(e),s=function(t,e){const n=w(),r={};return[t,...t.querySelectorAll("[data-edit-key]")].forEach(t=>{const o=t.getAttribute("data-edit-key");if(!o||"!"===o[0])return void t.setAttribute("data-edit-key","!"+w());const i="~"+n+"~"+v(o);t.setAttribute("data-edit-key",i),e&&e[o]&&(r[i]=Object.assign({},e[o]))}),r}(n,o);r?r.after(n):e.appendChild(n),zr(t),Jr(t),ne(t,e,i,{[n.getAttribute("data-edit-key")]:We(n,!0)},s)}function Qe(t){const e=Ne(void 0===t?Pe:t);if(!Xe("duplicate",e))return!1;const n=Be(e);if("data"===mt(n)){const t=Ie(n),r=ze(n,e);if(!t||r<0)return!1;const o=JSON.parse(JSON.stringify(t[r]));return o&&null!=o.id&&(o.id=Fe(t,o.id)),t.splice(r+1,0,o),te(n,r+1,o,"insert"),!0}if(Et(e))return function(t,e){const n=e.parentElement,r=k(n),o=yt(e),i=o.map(t=>re(We(t)));if(i.some(t=>!t))return!1;const s={roots:i},a="~"+w()+"~"+v(wt(e));return i.forEach(t=>{t._manifestComponent=e._manifestComponent,t._manifestHost=s,t.removeAttribute("data-component")}),i[0].setAttribute("data-edit-host",a),o[o.length-1].after(...i),zr(t),Jr(t),ne(t,n,r,{[a]:i[0].outerHTML}),!0}(n,e);const r=re(We(e,!0));return!!r&&(Ge(n,e.parentElement,r,e,Ye(e)),!0)}function Ze(t){const e=Ne(void 0===t?Pe:t);if(!Xe("remove",e))return!1;const n=Be(e);if("data"===mt(n)){const t=Ie(n),r=ze(n,e);if(!t||r<0)return!1;const o=t[r];return t.splice(r,1),te(n,r,o,"remove"),Pe===e&&je(null),!0}const r=e.parentElement,o=k(r),i=wt(e),s=Et(e)?e.outerHTML:We(e,!0);return e._editLead=Rt(e),e._editLead.forEach(t=>t.remove()),yt(e).slice(1).forEach(t=>t.remove()),e.remove(),ie.set(i,e),(Pe===e||Pe&&e.contains(Pe))&&je(null),ne(n,r,o,{[i]:s}),!0}const tn=t=>{const e=Ne(void 0===t?Pe:t);return Xe("remove",e)&&Ve(e)&&Ze(e)};function en(t){if(!Me)return!1;const e=Je(void 0===t?Pe:t);if(!e)return!1;const n=Ne(void 0===t?Pe:t),r=ct(e);if(!Ue(r))return!1;if("data"===mt(r)){const t=Ie(r);if(!t)return!1;const e=n?ze(r,n)+1:t.length,o=document.createElement("template");o.innerHTML=Me.html;const i={id:Fe(t,"pasted"),label:(o.content.textContent||"").trim()};return t.splice(e,0,i),te(r,e,i,"insert"),!0}if("static"!==mt(r))return!1;const o=re(Me.html);return!(!o||!Bt(o,e)||(Ge(r,e,o,n&&n.parentElement===e?n:null,Me.ops),0))}const nn=t=>t.target.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(t.target.tagName);function rn(t){const e=ct(t.target&&1===t.target.nodeType?t.target:t.target&&t.target.parentElement);e&&Qr(e)&&je($e(t.target))}const on=t=>{const e=getComputedStyle(t).position;return"absolute"===e||"fixed"===e},sn=new WeakSet;let an,ln=null;function cn(t){an&&an.isConnected||(an=document.createElement("div"),an.setAttribute("data-edit-live",""),an.setAttribute("aria-live","polite"),document.body.appendChild(an)),an.textContent=t}function dn(t){t.removeAttribute("data-edit-piece"),t.removeAttribute("data-edit-grabbable"),sn.has(t)&&(t.removeAttribute("tabindex"),sn.delete(t))}function un(t){const e=new Set(function(t){const e=mt(t);if("component"===e)return[];if("data"===e){const e=h(t);return e?kt(e.parentElement):[]}const n=[],r=t=>kt(t).forEach(t=>{t.closest("[data-edit-ghost], [x-edit\\.grab]")||(t._manifestComponent?Et(t)&&n.push(t):(n.push(t),Pt(t)&&!m(t)&&r(t)))});return Pt(t)&&r(t),n}(t).filter(qe));t.querySelectorAll("[data-edit-piece]").forEach(n=>{e.has(n)||ct(n.parentElement)!==t||dn(n)}),e.forEach(t=>{t.setAttribute("data-edit-piece",""),t.toggleAttribute("data-edit-grabbable",!!kn(t)),t.hasAttribute("tabindex")||(t.tabIndex=0,sn.add(t))})}const fn=t=>{const e=getComputedStyle(t);return/grid/.test(e.display)||/flex/.test(e.display)&&!String(e.flexDirection||"").startsWith("column")?"x":"y"};function mn(t,e,n,r){const o=t.getBoundingClientRect();let i=("x"===fn(r)?e<o.left+o.width/2:n<o.top+o.height/2)?t:yt(t).pop().nextElementSibling;for(;i&&(i===s||i.hasAttribute("data-edit-dragging"));)i=i.nextElementSibling;return{container:r,ref:i}}function pn(t,e,n,r){const o=e?t.left:t.top,i=e?t.width:t.height,s=e?n:r;if(!i)return!0;const a=Math.min(.25*i,24);return s>=o+a&&s<=o+i-a}const hn=(t,e,n,r)=>pn(t.getBoundingClientRect(),"x"===fn(r),e,n),gn=t=>!!t&&!!t._edit&&De(t)&&"static"===mt(t)&&(t=>!!t&&rt().includes(t))(t);function bn(t,e,n){if(n.dataList)return{container:n.home,ref:yn(n.home,t,e)};const r=n.nested;if(r&&r.el.isConnected&&n.ghost.parentElement===r.el&&t>=r.rect.left&&t<=r.rect.right&&e>=r.rect.top&&e<=r.rect.bottom&&pn(r.rect,r.horiz,t,e))return{container:r.el,ref:yn(r.el,t,e)};n.nested=null;const o=n.crossOK?function(t,e,n){const r=document.elementFromPoint?document.elementFromPoint(t,e):null;let o=r&&ct(r);if(o&&o!==n&&n.contains(o)&&(o=n),o&&gn(o))return o;const i=[n,...document.querySelectorAll("[data-edit-drop-target]")].filter((t,e,n)=>gn(t)&&n.indexOf(t)===e),s=(n,r)=>t>=n.left-r&&t<=n.right+r&&e>=n.top-r&&e<=n.bottom+r;let a=null,l=1/0;for(const n of i){const r=n.getBoundingClientRect(),o=Math.hypot(Math.max(r.left-t,0,t-r.right),Math.max(r.top-e,0,e-r.bottom)),c=Dt(L(n,"--edit-drop-reach",""),n,"w")??48,d=n.parentElement,u=d&&d!==document.body&&d!==document.documentElement&&!i.some(t=>t!==n&&d.contains(t))&&s(d.getBoundingClientRect(),0);(s(r,c)||u)&&o<l&&(a=n,l=o)}return a}(t,e,n.area):n.area;if(!o)return null;const i=document.elementFromPoint?document.elementFromPoint(t,e):null;if(i&&n.ghost&&(i===n.ghost||n.ghost.contains(i)))return null;if(i&&i!==o&&o.contains(i)){let r=i;for(let t=i;t&&t!==o;t=t.parentElement)(Et(t)||vt(t))&&(r=Et(t)?t:t._manifestHost.roots[0]);for(let i=r;i&&i!==o;i=i.parentElement){if(i===n.item||n.item.contains(i)||bt(i))continue;const r=i.parentElement;if(Pt(r))if(Et(i)){if(De(r)&&Bt(n.item,r)&&!n.item.contains(r))return mn(i,t,e,r)}else{if(n.ghost&&(i===n.home||i.contains(n.ghost))&&De(i)&&Bt(n.item,i))return{container:i,ref:yn(i,t,e)};if(Pt(i)&&De(i)&&Bt(n.item,i)&&hn(i,t,e,r))return n.ghost&&n.ghost.parentElement!==i&&(n.nested={el:i,rect:i.getBoundingClientRect(),horiz:"x"===fn(r)}),{container:i,ref:yn(i,t,e)};if(De(r)&&Bt(n.item,r)&&!n.item.contains(r))return mn(i,t,e,r)}}}if(!(n.crossOK||i&&o.contains(i))){const r=n.ghost.parentElement;return{container:r,ref:yn(r,t,e)}}return De(o)&&Bt(n.item,o)?{container:o,ref:yn(o,t,e)}:null}function yn(t,e,n){const r="y"===fn(t);for(const o of kt(t)){if(o===s||o.hasAttribute("data-edit-dragging")||ke(o,"move"))continue;const t=o.getBoundingClientRect(),i=t.left+t.width/2,a=t.top+t.height/2;if(r&&!/inline/.test(getComputedStyle(o).display)){if(a>n)return o;continue}const l=Math.abs(a-n)<t.height/2;if(a-n>t.height/2||l&&i>e)return o}return null}function vn(t,e,n,r){const o=t.offsetParent||t.parentElement,i=o.getBoundingClientRect();let s=e-r.grabX-i.left-(o.clientLeft||0)+(o.scrollLeft||0),a=n-r.grabY-i.top-(o.clientTop||0)+(o.scrollTop||0);const l=o.clientWidth-t.offsetWidth,c=o.clientHeight-t.offsetHeight;s=l>0?Wt(s,0,l):Math.max(0,s),a=c>0?Wt(a,0,c):Math.max(0,a),t.style.left=qt(s,r.lu,t,o,"w")+r.lu,t.style.top=qt(a,r.tu,t,o,"h")+r.tu}const En=t=>{t.style.removeProperty("left"),t.style.removeProperty("top"),t.getAttribute("style")||t.removeAttribute("style")},wn=(t,e)=>k(t).filter((n,r)=>kt(t)[r]!==e);function An(t){const e=this;if(!Qr(e)||"mouse"===t.pointerType&&0!==t.button||t._editDrag)return;const n=t.target;if(!n||1!==n.nodeType||n.hasAttribute("data-edit-handle"))return;if(n._pieceMode)return void gr(n);let r=null;for(let t=n;t&&t!==e;t=t.parentElement)if(t.hasAttribute("data-edit-piece")&&qe(t)){r=t;break}if(!r)return;const o=kn(r);if(o){if(!o.contains(n))return;t.preventDefault()}else if(_n(n))return;t._editDrag=!0,function(t,e,n){const r=e.parentElement,o=yt(e).pop().nextElementSibling,i=yt(e).slice(1),a="data"===mt(n),l={item:e,area:n,home:r,dataList:a,ghost:null,crossOK:!a&&"static"===mt(n)&&(Et(e)||!He(e)),homeBefore:a?null:k(r),lu:Ht(e.style.left)||"px",tu:Ht(e.style.top)||"px"},c=e.getBoundingClientRect(),d=e.getAttribute("style"),u=P(e),f=Rt(e);l.grabX=t.clientX-c.left,l.grabY=t.clientY-c.top;const m=t.clientX,p=t.clientY;let h=!1,g=0,b=m,y=p,v=null;const E=t=>{const r=document.activeElement;r&&e.contains(r)&&r.isContentEditable&&r.blur();try{window.getSelection().removeAllRanges()}catch{}l.crossOK&&rt().forEach(t=>{t!==n&&gn(t)&&t.setAttribute("data-edit-drop-target","")});const o=l.ghost=e.cloneNode(!0);ar(e,o),o.setAttribute("data-edit-ghost",""),o.setAttribute("x-ignore",""),o.removeAttribute("id"),o.querySelectorAll("[id]").forEach(t=>t.removeAttribute("id")),[o,...o.querySelectorAll("*")].forEach(t=>{[...t.attributes].forEach(e=>{e.name.startsWith("data-edit-")&&"data-edit-ghost"!==e.name&&t.removeAttribute(e.name)}),t.removeAttribute("contenteditable"),t.removeAttribute("tabindex"),t.removeAttribute("draggable")}),e.before(o),Object.assign(e.style,{position:"fixed",width:c.width+"px",height:c.height+"px",margin:"0",pointerEvents:"none"}),e.setAttribute("data-edit-dragging",""),s=o;try{e.setPointerCapture(t.pointerId)}catch{}},w=()=>{g=0,e.style.left=b-l.grabX+"px",e.style.top=y-l.grabY+"px"},A=t=>{const n=l.ghost,{container:o,ref:i}=t,s=v&&v.container===o&&v.ref===i;v=t,s||o.insertBefore(n,i&&i.parentElement===o?jt(i):null),on(n)?(s||(o===r&&e.parentElement===r?r.insertBefore(n,e):n.nextElementSibling&&o.appendChild(n)),vn(n,b,y,l)):(n.style.left||n.style.top)&&En(n)},_=t=>{if(b=t.clientX,y=t.clientY,!h){if(Math.hypot(b-m,y-p)<5)return;h=!0,E(t),w()}t.preventDefault();const e=bn(b,y,l);e&&A(e),g||(g=requestAnimationFrame(w))},x=t=>{if(document.removeEventListener("pointermove",_),document.removeEventListener("pointerup",S),document.removeEventListener("pointercancel",T),document.removeEventListener("keydown",C,!0),g&&cancelAnimationFrame(g),!h)return;document.querySelectorAll("[data-edit-drop-target]").forEach(t=>t.removeAttribute("data-edit-drop-target")),e.removeAttribute("data-edit-dragging"),t?l.ghost.remove():(l.ghost.replaceWith(e),f.length&&e.before(...f),i.length&&e.after(...i)),null==d?e.removeAttribute("style"):e.setAttribute("style",d),l.ghost=null,s=null;const a=()=>{o&&o.parentElement===r?r.insertBefore(e,jt(o)):r.appendChild(e),f.length&&e.before(...f),i.length&&e.after(...i)};if(t)return a(),void cn("Cancelled");const c=e.parentElement,m=ct(c);if(c!==r&&(l.dataList||!De(c)||!Bt(e,c)||!m||m!==n&&(!l.crossOK||!gn(m))))return a(),void cn("Cancelled");on(e)?vn(e,b,y,l):(e.style.left||e.style.top)&&En(e);const p=P(e)!==u;if(l.dataList)return xn(n,r),void cn("Dropped");let v=!1;c===r?v=me(n,r,l.homeBefore):(pe(n,m,e,r,l.homeBefore,wn(c,e)),v=!0),p&&fe(ct(e),e,{before:u,join:v}),cn(m!==n?"Moved to "+dt(m):"Dropped")},S=()=>x(!1),T=()=>x(!0),C=t=>{"Escape"===t.key&&(t.preventDefault(),t.stopPropagation(),x(!0))};document.addEventListener("pointermove",_),document.addEventListener("pointerup",S),document.addEventListener("pointercancel",T),document.addEventListener("keydown",C,!0)}(t,r,e)}const kn=t=>[...t.querySelectorAll("[x-edit\\.grab]")].find(e=>e.closest("[data-edit-piece]")===t)||null,_n=t=>{const e=document.activeElement;return!!e&&e!==document.body&&e.isContentEditable&&(e===t||e.contains(t))};function xn(t,e){return"data"===mt(t)&&(Xt(t,kt(e).map(e=>xt(e,t))),function(t){if(!t)return;const e=dt(t),n=mt(t),r=Ut(t,n),o=d[e];o&&C(o,r)||(Kt({region:e,kind:n,before:o??r,after:r}),d[e]=r)}(t),!0)}const Sn=(t,e)=>t.target!==e&&!!t.target.closest&&e.contains(t.target.closest('a[href], button, summary, [role="button"], [role="link"]')),Tn=t=>kt(t.parentElement).filter(e=>e===t||!ke(e,"move"));function Cn(t){if(document.activeElement!==t)try{t.focus()}catch{}}function On(t,e){if(t._editRow)return;const n=t.target;if("Enter"===t.key&&n.matches&&n.matches("a[href]")&&Gn(n,e))return;if(n._pieceMode&&"Enter"===t.key)return t._editRow=!0,t.preventDefault(),void gr(n,!0);let r=null;for(let t=n;t&&t!==e;t=t.parentElement)if(t.hasAttribute&&t.hasAttribute("data-edit-piece")&&qe(t)){r=t;break}if(!ln){const e=Ne(n);if(e&&function(t,e){if(nn(t))return!1;const n=t.metaKey||t.ctrlKey,r=(t.key||"").toLowerCase();return n&&"c"===r?Ve(e):n&&"x"===r?tn(e):n&&"v"===r?en(e):n&&"d"===r?Qe(e):!(n||"Delete"!==t.key&&"Backspace"!==t.key)&&Ze(e)}(t,e))return t._editRow=!0,t.preventDefault(),void t.stopPropagation()}if(!r)return;const o={ArrowUp:-1,ArrowDown:1}[t.key],i={ArrowLeft:-1,ArrowRight:1}[t.key],s=t.altKey&&!t.shiftKey&&!t.metaKey&&!t.ctrlKey;if(s&&null!=o&&(!ln||ln.item!==r))return t._editRow=!0,t.preventDefault(),void function(t,e){const n=Be(t),r=t.parentElement,o=Tn(t),i=o.indexOf(t),s=i+e;if(i<0||s<0||s>=o.length)return void cn(`Position ${i+1} of ${o.length}`);const a="data"===mt(n)?null:k(r),l=o[s],c=[];for(let n=e>0?t.nextElementSibling:t.previousElementSibling;n&&n!==l;n=e>0?n.nextElementSibling:n.previousElementSibling)c.push(n);const d=t=>[...Rt(t),...yt(t)];if(e>0){const e=jt(t);[l,...c].filter(t=>!vt(t)).forEach(t=>e.before(...d(t)))}else{let e=yt(t).pop();[...c.slice().reverse(),l].filter(t=>!vt(t)).forEach(t=>{e.after(...d(t)),e=yt(t).pop()})}const u=document.activeElement,f=window.getSelection&&window.getSelection(),m=f&&f.rangeCount?f.getRangeAt(0).cloneRange():null;if(a?me(n,r,a):xn(n,r),u&&u.isConnected&&document.activeElement!==u&&(u.focus(),m))try{f.removeAllRanges(),f.addRange(m)}catch{}cn(`Moved to position ${s+1} of ${o.length}`)}(r,o);if(s&&null!=i&&!nn(t))return t._editRow=!0,t.preventDefault(),void(i>0?Pn(r):Rn(r));if(!(" "!==t.key&&"Enter"!==t.key||nn(t)||Sn(t,r)||t.altKey||t.metaKey||t.ctrlKey))return t._editRow=!0,t.preventDefault(),void(ln&&ln.item===r?(function(){const t=ln;ln=null,t&&(t.item.removeAttribute("data-edit-dragging"),t.before?me(t.area,t.container,t.before):xn(t.area,t.container))}(),Cn(r),cn("Dropped")):(ln&&Ln(),ln={item:r,area:Be(r),container:r.parentElement,next:yt(r).pop().nextElementSibling,before:"data"===mt(Be(r))?null:k(r.parentElement)},r.setAttribute("data-edit-dragging","keyboard"),cn("Grabbed — arrow keys to move, Enter to drop")));if(ln&&ln.item===r){if("Escape"===t.key)return t._editRow=!0,t.preventDefault(),Ln(),Cn(r),void cn("Cancelled");const e=o??i;if(null==e)return;t._editRow=!0,t.preventDefault();const n=Tn(r),s=n.indexOf(r)+e;if(s<0||s>=n.length)return;return $t(r,t=>{e>0?yt(n[s]).pop().after(t):jt(n[s]).before(t)}),Cn(r),void cn(`Position ${s+1} of ${n.length}`)}n!==r||nn(t)||t.altKey||t.metaKey||t.ctrlKey||null==o&&null==i||!on(r)||(t._editRow=!0,function(t,e){const n={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]}[t.key];if(!n)return;t.preventDefault(),e._moveTimer||(e._preStyle=P(e));const r=t.shiftKey?16:4,o=getComputedStyle(e),i=e.offsetParent||e.parentElement,s=Ht(e.style.left)||"px",a=Ht(e.style.top)||"px",l=Math.max(0,i.clientWidth-e.offsetWidth),c=Math.max(0,i.clientHeight-e.offsetHeight),d=Math.max(0,(parseFloat(o.left)||0)+n[0]*r),u=Math.max(0,(parseFloat(o.top)||0)+n[1]*r);n[0]&&(e.style.left=qt(l?Math.min(l,d):d,s,e,i,"w")+s),n[1]&&(e.style.top=qt(c?Math.min(c,u):u,a,e,i,"h")+a),clearTimeout(e._moveTimer),e._moveTimer=setTimeout(()=>{e._moveTimer=null;const t=e.isConnected&&ct(e);t&&fe(t,e)},350)}(t,r))}function Ln(){const t=ln;ln=null,t&&(t.item.removeAttribute("data-edit-dragging"),$t(t.item,e=>{t.next&&t.next.parentElement===t.container?t.container.insertBefore(e,jt(t.next)):t.container.appendChild(e)}))}const Mn=t=>t===ct(t)?dt(t):t.tagName.toLowerCase();function Pn(t){const e=Be(t);if("static"!==mt(e))return cn("Records stay in their list"),!1;let n=t.previousElementSibling;for(;n&&(bt(n)||"TEMPLATE"===n.tagName||vt(n));)n=n.previousElementSibling;if(!n||Et(n)||!De(n)||!Bt(t,n))return cn("Nothing to nest into"),!1;const r=t.parentElement,o=k(r),i=k(n);return $t(t,t=>n.appendChild(t)),pe(e,e,t,r,o,i),Cn(t),cn("Nested in "+Mn(n)),!0}function Rn(t){const e=Be(t),n=t.parentElement;if("static"!==mt(e))return cn("Records stay in their list"),!1;const r=n&&n!==e?n.parentElement:null;if(!r||r!==e&&!e.contains(r)||!De(r))return cn("Already at the top level"),!1;if(!Bt(t,r))return cn("Cannot move out here"),!1;const o=k(n),i=k(r);return $t(t,t=>yt(n).pop().after(t)),pe(e,e,t,n,o,i),Cn(t),cn("Moved out to "+Mn(r)),!0}let jn;function $n(t,e){const n=t.getBoundingClientRect();t.dispatchEvent(new CustomEvent("edit:size",{bubbles:!0,detail:{width:n.width,height:n.height,css:{width:t.style.width,height:t.style.height},done:e}}))}const Nn=t=>"rtl"===getComputedStyle(t).direction;function Bn(t,e){const n=getComputedStyle(t).position;if("fixed"===n)return"w"===e?document.documentElement.clientWidth:document.documentElement.clientHeight;const r="absolute"===n&&t.offsetParent||t.parentElement;if(!r)return null;const o=getComputedStyle(r),i="w"===e,s=i?r.clientWidth:r.clientHeight;return"absolute"===n?s:i||function(t){for(let e=t,n=0;e&&n<32;e=e.parentElement,n++){if(e===document.documentElement)return!0;const t=getComputedStyle(e).position;if("absolute"===t||"fixed"===t)return!0;let n;if(e.computedStyleMap)try{n=String(e.computedStyleMap().get("height")).trim()}catch{}if(null==n&&(n=(e.style&&e.style.height||"").trim()||"auto"),"auto"===n||""===n)return!1;if(!n.endsWith("%"))return!0}return!1}(r)?s-(parseFloat(i?o.paddingLeft:o.paddingTop)||0)-(parseFloat(i?o.paddingRight:o.paddingBottom)||0):null}function Hn(t,e,n,r){if(!(t=String(t||"").trim())||"none"===t||"auto"===t)return r;if(/^-?[\d.]+%$/.test(t)){const o=Bn(e,n);return null==o?r:parseFloat(t)/100*o}const o=Dt(t,e,n);return null==o?r:o}function qn(t,e){const n=Hn(e.minWidth,t,"w",0),r=Hn(e.minHeight,t,"h",0);return{minW:n,minH:r,maxW:Math.max(n,Hn(e.maxWidth,t,"w",1/0)),maxH:Math.max(r,Hn(e.maxHeight,t,"h",1/0))}}const Dn=t=>"x"===t?["left","right"]:"y"===t?["top","bottom"]:["top","right","bottom","left","top-left","top-right","bottom-left","bottom-right"];function Wn(t){const e=L(t,"--edit-size","both");if("none"===e)return;if(t._sizeBound)return;t._sizeBound=!0;const n=getComputedStyle(t).position;n&&"static"!==n||(t.style.position="relative",t._editPos=!0),(L(t,"--edit-size-edges","")||Dn(e).join(" ")).split(/\s+/).filter(Boolean).forEach(e=>{const n=function(t,e){const n=Nn(e);return t.replace(/start/g,n?"right":"left").replace(/end/g,n?"left":"right")}(e,t),r=document.createElement("span");r.setAttribute("data-edit-handle",e),r.tabIndex=0,r.setAttribute("role","slider"),r.setAttribute("aria-label",`Resize ${e}`),r.addEventListener("pointerdown",e=>function(t,e,n){const r=ct(e);if(!Qr(r)||"mouse"===t.pointerType&&0!==t.button||t.button>0)return;t.preventDefault(),t.stopPropagation();const o=e.getAttribute("style");e._preStyle=P(e);const i=getComputedStyle(e),s=e.getBoundingClientRect(),a=Ht(e.style.width)||"px",l=Ht(e.style.height)||"px",c=parseFloat(i.width)||s.width,d=parseFloat(i.height)||s.height,u=t.clientX,f=t.clientY,{minW:m,maxW:p,minH:h,maxH:g}=qn(e,i),b=n.includes("right"),y=n.includes("left"),v=n.includes("bottom"),E=n.includes("top"),w=Kn(e,"--edit-size-snap-distance","x","w"),A=Kn(e,"--edit-size-snap-distance","y","h"),k=zn(e,"x","w"),_=zn(e,"y","h"),x=Kn(e,"--edit-size-close","x","w"),S=Kn(e,"--edit-size-close","y","h"),T=null!=x||null!=S?function(t){const e=t.getAttribute("x-show");return null==e?null:Un.test(e)?e:(Jn.has(t)||(Jn.add(t),console.warn('[edit] --edit-size-close needs an assignable x-show expression (e.g. x-show="open"); close is off here:',e)),null)}(e):null;let C;if(T)try{C=Xn(window.Alpine.evaluate(e,T))}catch{}const O=t.target;try{O.setPointerCapture&&O.setPointerCapture(t.pointerId)}catch{}O.setAttribute("data-edit-resizing",""),jn||(jn=document.createElement("div"),jn.setAttribute("data-edit-overlay",""),document.body.appendChild(jn)),jn.style.display="block";let L=c,M=d,R=!1;const j=()=>(b||y)&&null!=x&&L<x||(E||v)&&null!=S&&M<S,$=t=>{if(t!==R&&T){R=t;try{Vn(e,T,!t&&C)}catch{}}},N=t=>{const n=t.clientX-u,r=t.clientY-f;(b||y)&&(L=c+(b?n:-n)),(E||v)&&(M=d+(v?r:-r)),$(j());let o=!1;if(b||y){const t=Wt(L,m,p),n=Fn(t,k,w);o=o||k.length>0&&n!==t,e.style.width=qt(n,a,e,e.parentElement,"w")+a}if(E||v){const t=Wt(M,h,g),n=Fn(t,_,A);o=o||_.length>0&&n!==t,e.style.height=qt(n,l,e,e.parentElement,"h")+l}e.toggleAttribute("data-edit-snapped",o&&!R),O.toggleAttribute("data-edit-snapped",o&&!R),$n(e,!1)},B=()=>{document.removeEventListener("pointermove",N),document.removeEventListener("pointerup",D),document.removeEventListener("pointercancel",q),jn&&(jn.style.display="none"),["data-edit-snapped","data-edit-resizing"].forEach(t=>O.removeAttribute(t)),e.removeAttribute("data-edit-snapped")},H=()=>{null==o?e.removeAttribute("style"):e.setAttribute("style",o)},q=()=>{B(),$(!1),H(),$n(e,!0)},D=()=>{B();const t=(b||y)&&null!=x&&L<x,n=(E||v)&&null!=S&&M<S;if((t||n)&&T){const o=(t?m:0)>0||(n?h:0)>0,i=e.style.display;H(),o&&(t&&m>0&&(e.style.width=qt(m,a,e,e.parentElement,"w")+a),n&&h>0&&(e.style.height=qt(h,l,e,e.parentElement,"h")+l));const s=fe(r,e);return $n(e,!0),"none"===i&&(e.style.display="none"),void function(t,e,n,r,o){let i=o;try{void 0===i&&(i=Xn(window.Alpine.evaluate(e,n))),Vn(e,n,!1)}catch(t){return console.warn("[edit] could not close via x-show:",t),!1}const s=Ee(e,t);null!=s&&Kt(Object.assign({kind:"show",region:dt(t),key:s,expr:n,before:i,value:!1},r?{join:!0}:{}))}(r,e,T,s,C)}if(t||n)return H(),void $n(e,!0);fe(r,e),$n(e,!0)};document.addEventListener("pointermove",N),document.addEventListener("pointerup",D),document.addEventListener("pointercancel",q)}(e,t,n)),r.addEventListener("keydown",e=>function(t,e,n){const r={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]};if(!r[t.key])return;const o=ct(e);if(!Qr(o))return;t.preventDefault(),t.stopPropagation(),e._keyTimer||(e._preStyle=P(e));const[i,s]=r[t.key],a=t.shiftKey?32:8,l=getComputedStyle(e),c=n.includes("right"),d=n.includes("left"),u=n.includes("top"),f=n.includes("bottom"),m=Ht(e.style.width)||"px",p=Ht(e.style.height)||"px",{minW:h,maxW:g,minH:b,maxH:y}=qn(e,l);if((c||d)&&i){const t=Wt((parseFloat(l.width)||0)+i*a*(c?1:-1),h,g);e.style.width=qt(t,m,e,e.parentElement,"w")+m}if((u||f)&&s){const t=Wt((parseFloat(l.height)||0)+s*a*(f?1:-1),b,y);e.style.height=qt(t,p,e,e.parentElement,"h")+p}$n(e,!1),clearTimeout(e._keyTimer),e._keyTimer=setTimeout(()=>{e._keyTimer=null;const t=e.isConnected&&ct(e);t&&(fe(t,e),$n(e,!0))},350)}(e,t,n)),t.appendChild(r)})}function In(t,e,n){const r=O(t,`${e}-${n}`);if(r)return"none"===r?"":r;const o=O(t,e);return"none"===o?"":o}function zn(t,e,n){return In(t,"--edit-size-snap",e).split(/\s+/).filter(Boolean).map(e=>Dt(e,t,n)).filter(t=>null!=t)}function Fn(t,e,n){if(!e.length)return t;let r=t,o=1/0;for(const n of e){const e=Math.abs(t-n);e<o&&(o=e,r=n)}return null==n||o<=n?r:t}const Kn=(t,e,n,r)=>{const o=In(t,e,n);return o?Dt(o,t,r):null},Un=/^\s*[A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*|\s*\[\s*(?:'[^'\\]*'|"[^"\\]*"|\d+)\s*\])*\s*$/,Jn=new WeakSet,Xn=t=>{try{return void 0===JSON.stringify(t)||JSON.parse(JSON.stringify(t))}catch{return!0}};function Vn(t,e,n){window.Alpine.evaluate(t,`${e} = ${JSON.stringify(n)}`)}function Yn(t){requestAnimationFrame(()=>{if(!s&&!ln&&document.activeElement===t)try{const e=document.createRange();e.selectNodeContents(t);const n=window.getSelection();n.removeAllRanges(),n.addRange(e)}catch{}})}function Gn(t,e){const n=t.closest('[contenteditable="false"]');return!!n&&e.contains(n)&&!n.hasAttribute("data-edit-piece-mode")}function Qn(t){const e=t.target&&t.target.closest&&t.target.closest("a[href]"),n=e&&ct(e);n&&Qr(n)&&!Gn(e,n)&&t.preventDefault()}const Zn=new Set;let tr=!1;function er(t,e){if(t._editRtFormat=e,t._editRt||t._pieceMode)return;const n=function(){const t=window.ManifestRichText;return t&&"function"==typeof t.attach?t:(tr||(tr=!0,console.warn("[edit] Rich Text is not loaded; text leaves fall back to plain contenteditable")),null)}();t._editRtPrior=["role","aria-multiline"].map(e=>[e,t.getAttribute(e)]);const r=n&&n.attach(t,{mode:"inline",breaks:!0,enter:"break",all:!1,format:e,onChange:()=>{}});r?(t._editRt=r,t.setAttribute("data-edit-text",""),Zn.add(t)):t.setAttribute("contenteditable","true")}function nr(t){const e=t._editRt;e&&(t._editRt=null,Zn.delete(t),t.removeAttribute("data-edit-text"),e.detach())}const rr=t=>Zn.forEach(e=>{(!e.isConnected||t&&t.contains(e))&&nr(e)}),or=t=>{const e=t._editRt;e&&(e.value=e.value)};function ir(t){const e=this,n=e._editRt,r=Ho(t);if(!n||!r)return;if(n.can(r))return t.preventDefault(),t.stopImmediatePropagation(),void n[r]();const o=ct(e);"undo"===r&&o&&Qr(o)&&!No(e)&&function(t){const e=t._editRt;if(!e||!e.can("redo")||!t._commitText)return;const n=function(t){const e=t._editRt.newest();if(!t._editField||t._editRich)return e.trim();const n=document.createElement("template");return n.innerHTML=e,n.content.textContent}(t);t._commitText(n)&&Ce()}(e),qo(t),t.defaultPrevented&&t.stopImmediatePropagation()}function sr(t){t.addEventListener("drop",e=>{const n=ct(t);n&&Qr(n)&&(e.preventDefault(),e.stopImmediatePropagation())})}function ar(t,e){const n=[t,...t.querySelectorAll("*")],r=[e,...e.querySelectorAll("*")];r.forEach(t=>{const e=t.getAttribute("style");if(e&&/--rich-text-/.test(e)){const n=M(e);n?t.setAttribute("style",n):t.removeAttribute("style")}}),n.forEach((t,e)=>{t._editRt&&r[e]&&([...r[e].attributes].forEach(t=>{t.name.startsWith("data-rich-text")&&r[e].removeAttribute(t.name)}),(t._editRtPrior||[]).forEach(([t,n])=>null==n?r[e].removeAttribute(t):r[e].setAttribute(t,n)))})}function lr(t,e,n){t._textBound||(t._textBound=!0,t._commitText=e,t.addEventListener("focus",()=>{or(t),t._preEdit=$o(t),Yn(t)}),t.addEventListener("keydown",e=>{t.isContentEditable&&("Escape"===e.key?(e.preventDefault(),e.stopImmediatePropagation(),t.blur()):"Enter"!==e.key||!e.altKey||e.shiftKey||e.metaKey||e.ctrlKey||(e.preventDefault(),e.stopImmediatePropagation(),function(t){t.blur();const e=[t,...hr(t)].find(t=>t.hasAttribute&&t.hasAttribute("data-edit-piece"));if(e){e.isContentEditable&&(e._pieceMode=!0,e.setAttribute("data-edit-piece-mode",""),nr(e),e.setAttribute("contenteditable","false"),e.addEventListener("focusout",()=>gr(e),{once:!0}));try{e.focus()}catch{}}}(t)))}),t.addEventListener("keydown",ir),sr(t),n&&t.addEventListener("input",n),t.addEventListener("blur",()=>e()))}const cr=t=>{const e=t.closest("[data-rich-text]");return!(!e||e===t&&t._editRt)};function dr(t){t.querySelectorAll("[data-rich-text]:not([data-rich-text-bound])").forEach(e=>{!e._editRt&&ut(e,"text")&&/^[@~]/.test(e.getAttribute("data-edit-key")||"")&&(e._richBound||(e._richBound=!0,e.addEventListener("focusin",()=>{e._preEdit=$o(e)}),e.addEventListener("blur",()=>{const n=ct(e)||t;("component"===mt(n)?Qt:ce)(n,e,"text",e.innerHTML.trim())},!0)))})}function ur(t){const e=h(t);if(!e)return;const n=(e.getAttribute("x-for").match(/^\s*([\w$]+)\s+in\b/)||[])[1];if(!n)return;const r=gt(t),o=new RegExp("^\\s*"+n+"\\.([\\w$]+)\\s*$");kt(t).forEach(e=>{let i=e.getAttribute("data-key");if(null==i){let t=null;try{t=window.Alpine.$data(e)[n]}catch{}t&&null!=t.id&&(i=String(t.id))}null!=i&&[e,...e.querySelectorAll("*")].forEach(e=>{const n=e.hasAttribute("x-html");if(e.children.length&&(!n||!Ot(e))||e.hasAttribute("data-edit-handle"))return;const s=e.getAttribute("x-text")||e.getAttribute("x-html");if(!s)return;const a=s.match(o);if(!a)return;const l=a[1];if(e._editField=l,e._editRich=n,!e._dvBound){e._dvBound=!0;const o=()=>n?D(e):e.textContent;e._commitText=n=>function(t,e,n,r,o,i){o=String(o),i&&i._editRich&&(o=W(i,o));const s=i?i._preEdit:void 0;return!(s===o||i&&i._editRich&&null!=s&&W(i,s)===o||(Kt({kind:"data-val",region:dt(t),source:e,id:n,field:r,value:o,before:s}),ue(),0))}(t,r,i,l,n??o(),e),e.addEventListener("focus",()=>{or(e),e._preEdit=$o(e),$(e)||Yn(e)}),e.addEventListener("focusin",()=>{e._preEdit=$o(e)}),e.addEventListener("keydown",ir),sr(e),e.addEventListener("blur",()=>e._commitText(),!0)}$(e)||er(e,n?"html":"plain")})})}const fr=t=>{const e=pt(t);return(e?.getAttribute("data-component")||"").replace(/-\d+$/,"")};function mr(t,e,n,r){if("main"!==(t._editScope||"instance"))return;const o=fr(t),i=e._editPath,{inst:s}=Vt();rt().forEach(t=>{if("component"!==mt(t)||fr(t)!==o)return;const a=pt(t);if(!a)return;const l=""===i?a:function(t,e){let n=t;for(const t of e.split(".").map(Number))if(n=At(n)[t],!n)return null;return n}(a,i);l&&l!==e&&void 0===(s[dt(t)]&&s[dt(t)][i]||{})[n]&&("class"===n?wr(l,r):l.innerHTML!==r&&(l.innerHTML=r))})}function pr(t){const e=pt(t);if(!e)return;t._editScope||(t._editScope="instance"),t._baseText=t._baseText||{},t._baseClass=t._baseClass||{},t._baseStyle=t._baseStyle||{};const n=n=>{const r=function(t,e){const n=[];let r=t;for(;r&&r!==e&&r.parentElement;)n.unshift(At(r.parentElement).indexOf(r)),r=r.parentElement;return n.join(".")}(n,e);n._editPath=r,r in t._baseClass||(t._baseClass[r]=n.getAttribute("class")||""),r in t._baseStyle||(t._baseStyle[r]=n.getAttribute("style")||"")};n(e),e.querySelectorAll("*").forEach(t=>{t.hasAttribute("data-edit-handle")||n(t)}),dr(t),Yt(e).forEach(e=>{if(e.children.length&&!Lt(e)||!e.textContent.trim()||!ut(e,"text"))return;if(cr(e))return;const n=e._editPath;n in t._baseText||(t._baseText[n]=e.innerHTML.trim()),lr(e,n=>Qt(t,e,"text",n??D(e)),()=>mr(t,e,"text",e.innerHTML)),er(e,"html")})}const hr=t=>{const e=[],n=ct(t);for(let r=t.parentElement;r&&r!==n;r=r.parentElement)e.push(r);return e};function gr(t,e){if(t._pieceMode&&(t._pieceMode=!1,t.removeAttribute("data-edit-piece-mode"),"false"===t.getAttribute("contenteditable")&&(t.removeAttribute("contenteditable"),er(t,t._editRtFormat||"html")),e)){try{t.focus()}catch{}Yn(t)}}const br=(t,e)=>t.getAttribute(":"+e)??t.getAttribute("x-bind:"+e);function yr(t){const e=br(t,"class");if(null==e)return[];let n;try{n=window.Alpine.evaluate(t,e)}catch{return[]}const r=[],o=t=>String(t).split(/\s+/).filter(Boolean).forEach(t=>r.push(t));return"string"==typeof n?o(n):Array.isArray(n)?n.flat(1/0).filter(Boolean).forEach(o):n&&"object"==typeof n&&Object.entries(n).forEach(([t,e])=>{e&&o(t)}),r}const vr=t=>String(t||"").split(/\s+/).filter(Boolean);function Er(t){const e=new Set(yr(t));return vr(t.getAttribute("class")).filter(t=>!e.has(t)).join(" ")}function wr(t,e){const n=yr(t),r=[...new Set([...vr(e),...n])].join(" ");r?t.getAttribute("class")!==r&&t.setAttribute("class",r):t.hasAttribute("class")&&t.removeAttribute("class")}function Ar(t){if(null==t&&(t=Pe),!t||1!==t.nodeType)return null;const e=ct(t);if(!e||!Qr(e))return null;const n=mt(e);return"static"===n&&t._manifestComponent?null:{el:t,area:e,kind:n}}function kr(t,e,n){const r=Ar(n);if(!r)return!1;t=String(t||"").trim().toLowerCase();const o=!0===e?"":!1===e||null==e?null:String(e),i=X(t,o,r.el.tagName);if(i)return console.warn(`[edit] attribute refused (${i}):`,t),!1;if(ke(r.el,"attrs"))return!1;const s="data"!==r.kind&&Mt(r.el);if(s)return function(t,e,n,r){if(ke(e,"text")||t.el.getAttribute(n)===r)return!1;const o=document.activeElement===e,i=o&&void 0!==e._preEdit?e._preEdit:$o(e),s=t.el.getAttribute(n),a=$o(e),l=e=>null===e?t.el.removeAttribute(n):t.el.setAttribute(n,e);if(l(r),$o(e)===a)return l(s),console.warn(`[edit] ${n} is not kept inside text`),!1;const c=D(e),d="component"===t.kind?Qt(t.area,e,"text",c,i):ce(ct(e),e,"text",c,{before:i});return o&&(or(e),e._preEdit=$o(e)),d}(r,s,t,o);if("class"===t)return _r(r,o||"");if("data"===r.kind)return console.warn("[edit] list rows are rendered from data; attributes on them are not editable"),!1;if("component"===r.kind)return console.warn("[edit] component nodes take class changes only"),!1;if(!/^[@~]/.test(r.el.getAttribute("data-edit-key")||""))return!1;null!=br(r.el,t)&&console.warn(`[edit] ${t} is bound on this element; the binding will override the edited value`);const a=r.el.getAttribute(t);return a!==o&&(null===o?r.el.removeAttribute(t):r.el.setAttribute(t,o),ce(r.area,r.el,t,o,{before:a,coalesce:!0}))}function _r(t,e){if("data"===t.kind)return console.warn("[edit] list rows are rendered from data; attributes on them are not editable"),!1;if(Mt(t.el))return console.warn("[edit] class is not kept inside text"),!1;const n=Er(t.el);return n!==(e=vr(e).join(" "))&&(wr(t.el,e),"component"===t.kind?null!=t.el._editPath&&(mr(t.area,t.el,"class",t.el.getAttribute("class")||""),Qt(t.area,t.el,"class",e,n)):!!/^[@~]/.test(t.el.getAttribute("data-edit-key")||"")&&ce(t.area,t.el,"class",e,{before:n,coalesce:!0}))}function xr(t,e){const n=Ar(t);if(!n)return!1;if(ke(n.el,"attrs"))return!1;const r=e(vr(Er(n.el)));return!!r&&_r(n,r.join(" "))}const Sr={add(t,e){const n=vr(t);return xr(e,t=>[...t,...n.filter(e=>!t.includes(e))])},remove(t,e){const n=new Set(vr(t));return xr(e,t=>t.filter(t=>!n.has(t)))},toggle(t,e,n){const r=Ar(e);if(!r)return!1;const o=vr(t);return n??!o.every(t=>r.el.classList.contains(t))?Sr.add(t,r.el):Sr.remove(t,r.el)},set(t,e){const n=Ar(e);return!!n&&!ke(n.el,"attrs")&&_r(n,t||"")},has(t,e){Vr&&Vr.version;const n=null==e?Pe:e;return!!n&&1===n.nodeType&&vr(t).every(t=>n.classList.contains(t))},list(t){Vr&&Vr.version;const e=null==t?Pe:t;return e&&1===e.nodeType?vr(Er(e)):[]}},Tr=t=>{const e=t&&ct(t);return e&&"component"===mt(e)?e:null};function Cr(t){const e=Tr(null==t?Pe:t);return e?e._editScope||"instance":null}function Or(t){null==t&&(t=Pe);const e=Tr(t);if(!e)return!1;if(t===e)Kt({kind:"cmp-inst",component:fr(n=e),region:dt(n),path:"*",prop:"*",value:It}),Gt();else{if(null==t._editPath)return!1;!function(t,e){Kt({kind:"cmp-inst",component:fr(t),region:dt(t),path:e._editPath,prop:"*",value:It}),Gt()}(e,t)}var n;return!0}const Lr=new Set,Mr={},Pr=new Set,Rr=(t,e)=>(t||"")+"|"+e,jr=t=>t&&Y[t]||document.documentElement,$r=t=>t.value+(t.dataset.unit||"");let Nr=null;function Br(t){const e=t._cssvar;if(!e||!("value"in t))return;const n=getComputedStyle(jr(e.scope)).getPropertyValue(e.var).trim();if(!n)return;const r="color"===t.type?function(t){if(/^#[0-9a-f]{6}$/i.test(t))return t.toLowerCase();try{Nr=Nr||document.createElement("canvas");const e=Nr.getContext&&Nr.getContext("2d",{willReadFrequently:!0});if(!e)return null;const n=document.createElement("i");return n.style.color=t,n.style.color?(e.clearRect(0,0,1,1),e.fillStyle="#000",e.fillStyle=t,e.fillRect(0,0,1,1),"#"+[...e.getImageData(0,0,1,1).data.slice(0,3)].map(t=>t.toString(16).padStart(2,"0")).join("")):null}catch{return null}}(n):t.dataset.unit?String(parseFloat(n)):n;null!=r&&t.value!==r&&(t.value=r)}function Hr(t){const e=t._cssvar;if(!e||!e.var)return;const n=Rr(e.scope,e.var);n in Mr||(Mr[n]=jr(e.scope).style.getPropertyValue(e.var)),Br(t),t._cvBound||(t._cvBound=!0,t.addEventListener("input",()=>jr(e.scope).style.setProperty(e.var,$r(t))),t.addEventListener("change",()=>{return function(t,e,n,r){if(!/^--[\w-]+$/.test(e||""))return void console.warn("[edit] x-edit.cssvar needs a custom property name (--name):",e);const o=function(t){const e=String(null==t?"":t);if(!e.trim())return"empty";if(/expression\s*\(/i.test(e))return"expression()";const n=[];for(let t=0;t<e.length;t++){const r=e[t];if('"'===r||"'"===r){let n=t+1;for(;n<e.length&&e[n]!==r;n++)if("\\"===e[n])n++;else if("\n"===e[n])return"unbalanced quotes";if(n>=e.length)return"unbalanced quotes";t=n;continue}if(/^url\(/i.test(e.slice(t,t+4))&&!/[\w-]/.test(e[t-1]||"")){let n=t+4,r=null,o="";for(;n<e.length;n++){const t=e[n];if(r){if("\\"===t){o+=e[++n]||"";continue}if(t===r){r=null;continue}o+=t}else if('"'!==t&&"'"!==t){if(")"===t)break;o+=t}else r=t}if(n>=e.length)return"unterminated url()";const i=o.replace(/[\u0000-\u0020\u007f]/g,"").toLowerCase();if(/^(javascript|vbscript):/.test(i))return"script URL";if(i.startsWith("data:")&&!i.startsWith("data:image/"))return"data URL";t=n;continue}if(";"===r||"{"===r||"}"===r)return`contains ${r}`;if(e.startsWith("/*",t)||e.startsWith("\x3c!--",t)||e.startsWith("</",t))return"contains a comment or markup";if("("===r||"["===r)n.push(r);else if((")"===r||"]"===r)&&n.pop()!==(")"===r?"(":"["))return"unbalanced brackets"}return n.length?"unbalanced brackets":null}(n);if(o)return void console.warn(`[edit] theme value refused (${o}):`,n);const i=Rr(t,e);Pr.add(i),jr(t).style.setProperty(e,n);const s=qr()[i];s&&s.value===n||Kt({kind:"theme",scope:t||null,var:e,value:n},!!r)}(e.scope,e.var,$r(t),e.persist||!!(n=e.scope&&Y[e.scope])&&!!(n._editPersist||n._edit&&n._edit.persist));var n}))}function qr(){const t={};for(let e=0;e<c;e++){const n=l[e];"theme"===n.kind&&(t[Rr(n.scope,n.var)]=n)}return t}function Dr(){const t=qr();new Set([...Pr,...Object.keys(t)]).forEach(e=>{Pr.add(e);const n=e.indexOf("|"),r=e.slice(0,n)||null,o=e.slice(n+1),i=jr(r),s=t[e]?t[e].value:Mr[e];s?i.style.setProperty(o,s):i.style.removeProperty(o)}),Lr.forEach(Br)}function Wr(t){const e=t&&Y[t];if(!e||tt(e))return null;const n=ct(e),r=e.getAttribute("data-edit-key");if(n&&"static"===mt(n)&&!st(n)&&r&&/^[@~]/.test(r))return"area";if(n&&n!==e)return null;const o=it(t);return o&&o!==e?null:"own"}const Ir=new Map;function zr(t){const e=dt(t),n=!t._marked;t._marked=!0,t._baseClass=t._baseClass||{},t._baseStyle=t._baseStyle||{},t._baseText=t._baseText||{};const r=Object.create(null),o=t=>{for(const e of t.children){const t=b(e);r[t]=(r[t]||0)+1,o(e)}},i=(s,a)=>{if(((o,i)=>{let s=o.getAttribute("data-edit-key");if(!s){if(n){const t=b(o),n=r[t]=(r[t]||0)+1;s=y(e,n>1?t+"#"+n:t),Ir.set(s,i)}else s="!"+w();o.setAttribute("data-edit-key",s)}s in t._baseClass||(t._baseClass[s]=Er(o)),s in t._baseStyle||(t._baseStyle[s]=P(o)),s in t._baseText||o.children.length||(t._baseText[s]=o.innerHTML.trim())})(s,a),s!==t&&(t=>$(t)||m(t)||[...t.attributes].some(t=>t.name.startsWith("x-rich-text")))(s))return;if(s._editRt||(n||s._editRtFormat)&&Lt(s)&&ut(s,"text")&&!m(s))return void(n&&o(s));let l=0;for(const t of s.children){if(bt(t)||t.closest("[data-edit-ghost]")||A(t))continue;const o=""===a?String(l):a+"."+l;if(t._manifestComponent){if(vt(t))continue;if(!t.hasAttribute("data-edit-host")){const i=t.getAttribute("data-edit-key"),s=y(e,"X-"+t._manifestComponent.toUpperCase()+":");let a=i&&(i===s||i.startsWith(s+"#"))?i:"!"+w();if(n&&"!"===a[0]){const n="X-"+t._manifestComponent.toUpperCase()+":",i=r[n]=(r[n]||0)+1;a=y(e,i>1?n+"#"+i:n),Ir.set(a,o)}t.setAttribute("data-edit-host",a)}l++}else i(t,o),l++}};i(t,"")}const Fr=new Set,Kr=new Set,Ur=new Map;function Jr(t){const e=function(t){if("data"!==mt(t))return null;const e=(ht(t)||"").match(/\$x\.([\w$]+)/);if(!e)return"inline x-data list: mnfst-run writes data only to CSV/JSON/YAML sources declared in manifest.json";const n=window.ManifestComponentsRegistry&&window.ManifestComponentsRegistry.manifest;if(!n)return null;const r=(n.data||{})[e[1]];return null==r?`data source '${e[1]}' is not declared in manifest.json: mnfst-run writes data only to CSV/JSON/YAML files declared there`:"string"==typeof r?null:`data source '${e[1]}' is not a file (a cloud or remote source): save it with $x.${e[1]}.$update, not mnfst-run`}(t);e&&(Kr.add(dt(t)),Ur.set(dt(t),e),Fr.has(dt(t))||(Fr.add(dt(t)),console.warn(`[edit] x-edit="${dt(t)}": ${e}; its edits stay on the page (and reach onPublish)`))),t._edit.rendered&&Kr.add(dt(t)),t._edit.rendered&&!Fr.has(dt(t))&&(Fr.add(dt(t)),console.warn(`[edit] x-edit="${dt(t)}" is inside content ${t._edit.rendered} renders: it edits on the page (and reaches onPublish), but mnfst-run cannot write it to a source file`)),rr(null);const n=mt(t);"static"===n&&zr(t),un(t),[t,...t.querySelectorAll("[data-edit-area]")].forEach(t=>{var e,n;n="size",(e=t)._edit&&e._edit.caps.has(n)&&!ke(e,n)&&Wn(t)}),"component"===n?pr(t):"static"===n&&function(t){dr(t);const e=[...t.querySelectorAll("*")];At(t).length&&!Lt(t)||e.unshift(t),e.forEach(e=>{At(e).length&&!Lt(e)||!e.textContent.trim()||e.closest("template")||e.closest("[data-edit-handle], [x-edit\\.grab]")||e._manifestComponent&&e!==t||cr(e)||e.closest('[contenteditable="false"]:not([data-edit-piece-mode])')||!ut(e,"text")||m(e)||p.has(e.tagName)||/^[@~]/.test(e.getAttribute("data-edit-key")||"")&&(lr(e,n=>ce(ct(e)||t,e,"text",n??D(e))),er(e,"html"))})}(t),"data"===n&&ut(t,"data")&&ur(t),t._editBound||(t._editBound=!0,t.addEventListener("pointerdown",An),t.addEventListener("keydown",e=>{Qr(t)&&On(e,t)}),t.addEventListener("dragstart",e=>{Qr(t)&&e.preventDefault()}),t.addEventListener("drop",e=>{Qr(t)&&e.preventDefault()})),t._editObserver||(t._editObserver=new MutationObserver(e=>{s||t._rearmQueued||e.every(t=>t.target.isContentEditable)||(t._rearmQueued=!0,queueMicrotask(()=>{t._rearmQueued=!1,t._armed&&Qr(t)&&!s&&Jr(t)}))}),t._editObserver.observe(t,{childList:!0,subtree:!0}))}function Xr(t){[t,...t.querySelectorAll("[data-edit-area]")].forEach(t=>{t._editPos&&(t.style.removeProperty("position"),t._editPos=!1)}),t.querySelectorAll("[data-edit-handle]").forEach(t=>t.remove()),rr(t),[t,...t.querySelectorAll("[contenteditable]")].forEach(t=>{t.hasAttribute("contenteditable")&&t.removeAttribute("contenteditable"),t._pieceMode=!1,t.removeAttribute("data-edit-piece-mode")}),t.querySelectorAll("[data-edit-piece]").forEach(dn),[t,...t.querySelectorAll("[data-edit-area]")].forEach(t=>{t._sizeBound=!1}),ln&&t.contains(ln.item)&&Ln()}let Vr,Yr=!1,Gr=!1;const Qr=t=>!(!t||!t._edit||t._edit.gated&&(!Vr||!Vr.active)||st(t)),Zr=new Set;function to(){const t=[];rt().forEach(t=>{st(t)&&(Zr.has(dt(t))||(Zr.add(dt(t)),console.warn(`[edit] x-edit="${dt(t)}" is on the page more than once (a component used several times); it is not editable here`)),t._armed&&(Xr(t),t._armed=!1))}),rt().forEach(e=>{Qr(e)&&!e._armed&&(e._editBound||t.push(e),d[dt(e)]=Ut(e,mt(e)),Jr(e),e._armed=!0)}),Yr&&t.length&&(l.some(t=>/^st-/.test(t.kind))&&(ae(t),le()),l.some(t=>"cmp-main"===t.kind||"cmp-inst"===t.kind)&&Gt()),Lr.forEach(Hr),jo(),Yr=!0}function eo(t){const e=[],n=t=>t.edits||t.children||"~"===t.key[0],r=se(oe()),o=new Set(Object.values(qr()).filter(t=>t.scope&&"area"===Wr(t.scope)).map(t=>Y[t.scope]));oe().forEach(r=>{const i=dt(r),s=at(r),a=new Proxy({},{get:(t,e)=>{const n=v(String(e)),r=it(decodeURIComponent(n.slice(1,n.indexOf("@",1)))),o=so&&r&&so[lt(r)];return o?o[n]:void 0}}),l=(e,r)=>{const s=!r&&e.getAttribute("data-edit-host");if(s){if("!"===s[0])return null;const t={key:s},e=Ir.get(s);return null!=e&&(t.at=e),a&&a[s]&&(t.fp=a[s]),t}if(!r&&e._manifestComponent)return null;const c=e.getAttribute("data-edit-key");if(!c||"!"===c[0])return null;const d={key:c},u=Ir.get(v(c));null!=u&&(d.at=u),a&&a[v(c)]&&(d.fp=a[v(c)]);const f=(e=>{const n=t.node[e];if(!n)return null;const r={};return Object.entries(n).forEach(([t,e])=>{r[t]="class"!==t&&"style"!==t||""!==e?e:null}),Object.keys(r).length?r:null})(c);if(f&&(d.edits=f),o.has(e)&&(d.edits=Object.assign({},d.edits,{style:P(e)||null})),!(f&&"text"in f||m(e)||e.hasAttribute("data-rich-text"))){const o=(t=>At(t).filter(t=>!A(t)))(e).map(t=>l(t)).filter(Boolean),s=t.touched.has(r?"#"+i:c);if("~"===c[0]||s){d.children=o;const e=s&&"~"!==c[0]&&(e=>{const n=""===e?(t.orderBase[i]||{})[""]:Object.values(t.orderBase).map(t=>t[e]).find(Boolean);return n?n.filter(t=>"@"===t[0]).map(t=>{const e={key:t},n=Ir.get(t);return null!=n&&(e.at=n),a&&a[t]&&(e.fp=a[t]),e}):null})(r?"":c);e&&(d.base=e)}else o.some(n)&&(d.children=o.filter(n),d.path=!0)}return d},c=l(r,!0);c&&(c.edits||c.children)&&(delete c.at,delete c.fp,e.push(s?{kind:"static-tree",region:i,component:s,tree:c}:{kind:"static-tree",region:i,tree:c}))});const i=new Set;new Set([...Object.keys(t.orderBase),...Object.keys(t.order)]).forEach(e=>{Object.values(Object.assign({},t.orderBase[e]||{},t.order[e]||{})).forEach(t=>t.forEach(t=>i.add(t)))});const s=new Set;for(let t=0;t<c;t++){const e=l[t];"st-children"===e.kind&&e.before.forEach(t=>{!t||"@"!==t[0]||i.has(t)||r.has(t)||s.add(t)})}return s.forEach(t=>{const n=(t=>decodeURIComponent(t.slice(1,t.indexOf("@",1))))(t);let r=e.find(t=>t.region===n);if(!r){const t=it(n);if(!t||st(t))return;const o=at(t);r=o?{kind:"static-tree",region:n,component:o,tree:{key:""}}:{kind:"static-tree",region:n,tree:{key:""}},e.push(r)}(r.removed=r.removed||[]).push(t)}),e}function no(){const t=Object.entries(Le()).map(([t,e])=>{return n=t,r=e.kind,o=e.snap,{region:n,kind:r,op:"reorderData",source:o.source,order:o.order};var n,r,o});eo(Zt()).forEach(e=>t.push(e));const e=t=>{const e=[];return Object.entries(t).forEach(([t,n])=>Object.entries(n).forEach(([n,r])=>e.push({path:t,key:t,prop:n,value:r}))),e},n=de(),r={};l.slice(0,c).forEach(t=>{"data-val"===t.kind&&(r[t.source]=t.region)}),Object.entries(n).forEach(([e,n])=>Object.entries(n).forEach(([n,o])=>Object.entries(o).forEach(([o,i])=>t.push({kind:"data-val",region:r[e],source:e,id:n,field:o,value:i}))));const{main:o,inst:i,reverts:s}=Vt();return Object.entries(o).forEach(([n,r])=>{const o=e(r);o.length&&t.push({kind:"component",scope:"main",component:n,edits:o})}),new Set([...Object.keys(i),...Object.keys(s)]).forEach(n=>{const r=it(n);if(!r)return;const o=e(i[n]||{}),a=[...s[n]||[]];(o.length||a.length)&&t.push({kind:"component",scope:"instance",component:fr(r),region:n,edits:o,reverts:a})}),function(){const t=Object.values(qr()),e=[];return t.filter(t=>!Wr(t.scope)).forEach(t=>e.push({kind:"theme",scope:t.scope||null,var:t.var,value:t.value,file:null})),new Set(t.filter(t=>t.scope&&"own"===Wr(t.scope)).map(t=>t.scope)).forEach(t=>{const n=Y[t],r=(t=>{for(let e=t;e;e=e.parentElement)if(e._manifestComponent)return e._manifestComponent;return null})(n),o={key:"",edits:{style:P(n)||null}};e.push(r?{kind:"static-tree",region:t,component:r,tree:o}:{kind:"static-tree",region:t,tree:o})}),e}().forEach(e=>t.push(e)),t}function ro(t){const e=e=>"theme"===e.kind?!!t&&(t.has("theme|"+(e.scope||"")+"|"+e.var)||t.has(e.scope)):("st-move"===e.kind?[e.from,e.to]:[e.region]).some(e=>!(e=>null==e||!!it(e)&&!(t&&t.has(e)))(e)),n=[],r=ve();se(oe().filter(e=>!(t&&t.has(dt(e))))).forEach((t,e)=>{const o=r.get(e);o&&o.size&&n.push([t,new Map(o),e===t.getAttribute("data-edit-host")])});const i=l.slice(0,c).filter(t=>"lock"===t.kind&&!/^[~@]/.test(t.key)&&!e(t));let s=0;l=l.filter((t,n)=>{const r=e(t);return r&&n<c&&s++,r}),c=s,zt++,T();const a=t?[...Ir].filter(([e])=>t.has(decodeURIComponent(e.slice(1,e.indexOf("@",1))))):[];Ir.clear(),a.forEach(([t,e])=>Ir.set(t,e)),rt().forEach(e=>{if(t&&t.has(dt(e)))return;const n=mt(e);e._baseText={},e._baseClass={},e._baseStyle={},"static"===n&&([e,...e.querySelectorAll("[data-edit-key]")].forEach(t=>{ct(t)===e&&t.removeAttribute("data-edit-key")}),e.querySelectorAll("[data-edit-host]").forEach(t=>{ct(t.parentElement)===e&&t.removeAttribute("data-edit-host")}),e._marked=!1,zr(e)),"component"===n&&e._armed&&pr(e),d[dt(e)]=Ut(e,n)}),function(t){Object.keys(Mr).forEach(e=>{if(t&&t.has("theme|"+e))return;const n=e.indexOf("|");Mr[e]=jr(e.slice(0,n)||null).style.getPropertyValue(e.slice(n+1))}),[...Pr].forEach(e=>{t&&t.has("theme|"+e)||Pr.delete(e)})}(t),(()=>{const t=t=>{l.splice(c,0,t),c++,ft(t.region)&&u.add(t)};i.forEach(t),n.forEach(([e,n,r])=>{const i=r?Be(e):ct(e),s=e.getAttribute(r?"data-edit-host":"data-edit-key");i&&s&&[!0,!1].forEach(e=>{const r=[...n].filter(([,t])=>t===e).map(([t])=>t);r.length&&t({kind:"lock",region:dt(i),key:s,actions:r.length===o.length?[]:r,value:e})})}),zt++})(),T(),jo()}const oo=t=>!(t&&Array.isArray(t.results)&&t.results.some(t=>t&&"error"===t.status));let io=null,so=null;function ao(t){return/^https?:$/.test(location.protocol)&&"function"==typeof fetch?fetch("/__edit/base",{cache:"no-store"}).then(t=>t.ok?t.json():null).then(e=>(e&&e.files&&(io=e.files),e&&e.ids&&!t&&(so=e.ids),io)).catch(()=>null):Promise.resolve(null)}let lo=!1;window.addEventListener("manifest:source-change",t=>{const e=t.detail||{},n=/\.html?$/i.test(e.file||"");n&&!so&&(lo=!0),io&&e.file&&e.hash&&!n&&(io[e.file]=e.hash)});let co=null,uo=0,fo=[],mo=!1,po=null;const ho=t=>!mo&&!!co&&Date.now()<co.until&&t.length>0&&t.every(t=>t&&co.files[t.rel]&&co.files[t.rel]===t.hash);function go(t){const e=document.activeElement;if(!e||!e._commitText||void 0===e._preEdit||!e.isContentEditable||$o(e)===e._preEdit)return!0;const n=ct(e);return!(!n||!t&&!n._edit.persist||(e._commitText(),or(e),e._preEdit=$o(e),0))}function bo(t){const e=new Map;for(let n=!0;n;)n=!1,l.slice(0,c).forEach(r=>{if("st-move"!==r.kind||t.has(r.from)===t.has(r.to))return;const[o,i]=t.has(r.from)?[r.from,r.to]:[r.to,r.from];t.add(i),e.set(i,e.get(o)||o),n=!0});return t.via=e,t}const yo=t=>{if("string"!=typeof t)return null;const e=v(t);return"@"===e[0]?e.slice(1,e.indexOf("@",1)):null},vo=t=>Kr.has(t.region)||Kr.has(t.from)||Kr.has(t.to)||Kr.has(yo(t.path))||Kr.has(yo(t.key)),Eo=t=>[...new Set(t.flatMap(t=>[t.region,t.from,t.to]).filter(Boolean))],wo=()=>l.slice(0,c).filter(t=>"lock"!==t.kind&&!u.has(t));function Ao(){const t=document.activeElement,e=t&&t._commitText&&ct(t);return e?dt(e):null}function ko(){return!(!go(!1)&&!Kr.has(Ao()))&&wo().every(vo)}function _o(){const t=Ao(),e=Eo(wo().filter(vo));t&&Kr.has(t)&&!go(!1)&&!e.includes(t)&&e.push(t),e.length&&console.warn(`[edit] the source changed: reloading discards the unpublished edits of ${e.map(t=>`x-edit="${t}"`).join(", ")} that mnfst-run can't write (generated content, or a piece moved from it); .persist keeps them`)}function xo(){_o(),location.reload()}function So(){po&&ko()&&(po=null,xo())}function To(t){if(ko())return xo();po=t;const e=t.map(t=>t&&t.rel).filter(Boolean);Vr&&(Vr.stale=[...new Set([...Vr.stale||[],...e])]);const n=Eo(wo().filter(t=>!vo(t))).filter(t=>!Kr.has(t)),r=Ao();!r||Kr.has(r)||n.includes(r)||go(!1)||n.push(r);const o=bo(new Set(Kr)),i=n.filter(t=>o.has(t)),s=t=>t.map(t=>`x-edit="${t}"`).join(", ");console.warn(`[edit] the source changed, but a reload would lose unpublished edits${n.length?" to "+s(n):""}: publish (with rebase), then reload`+(i.length?`. ${s(i)} ${i.length>1?"are":"is"} tied by a move to ${s([...new Set(i.map(t=>o.via.get(t)))])}, which mnfst-run can't write: undo that move to publish ${i.length>1?"them":"it"}, or publish the rest`:"")),document.dispatchEvent(new CustomEvent("edit:stale",{detail:{files:e}}))}function Co(t,e){if(uo=Math.max(0,uo-1),t&&t.base&&(co={files:Object.assign({},t.base),until:Date.now()+3e3}),t&&Array.isArray(t.stale)&&t.stale.length&&(mo=!0),e&&oo(t)&&t.base&&(mo=!0,setTimeout(()=>{mo&&To(Object.keys(t.base).map(t=>({rel:t})))},1500)),uo)return;const n=fo;fo=[],n.some(t=>!ho(t))&&To(n.flat())}window.addEventListener("manifest:live-reload",t=>{const e=t.detail&&t.detail.files||[];if(uo)return t.preventDefault(),void fo.push(e);ho(e)?t.preventDefault():ko()?_o():(t.preventDefault(),To(e))});let Oo=Promise.resolve();function Lo(t){const e=Oo.then(()=>function(t){const e=(t,e,n)=>{t&&t.base&&io&&Object.entries(t.base).forEach(([t,e])=>{Mo&&/\.html?$/i.test(t)||(io[t]=e)}),t&&t.ids&&so&&(Mo?Object.entries(t.ids).forEach(([t,e])=>{so[t]=Object.assign({},so[t]),Object.entries(e||{}).forEach(([e,n])=>{String(n).includes(".")||(so[t][e]=n)})}):so=t.ids);const r=t&&Array.isArray(t.stale)?t.stale:[];return Vr&&(Vr.stale=r),r.length&&document.dispatchEvent(new CustomEvent("edit:stale",{detail:{files:r}})),oo(e?{results:t.results.filter(t=>!(t&&(e.has(t.region)||n&&n.has(t))))}:t)&&ro(e),So(),t},n=(t,e)=>{if(!t||!Array.isArray(t.results)||Array.isArray(t.stale)&&t.stale.length)return null;const n=new Set(t.results.filter(t=>t&&null!=t.failed).map(t=>t.failed)),r=new Set(e.filter((e,n)=>t.results[n]&&"error"===t.results[n].status&&null==t.results[n].failed&&"static-tree"!==e.kind));if(!n.size&&!r.size||t.results.some((t,o)=>t&&"error"===t.status&&!n.has(e[o]&&e[o].region)&&!r.has(e[o])))return null;bo(n);const o=t=>r.has(t)||null!=t.region&&n.has(t.region);return e.some(t=>!o(t))?Object.assign(n,{own:r,out:o}):null},r=t=>"theme"===t.kind?"theme|"+(t.scope||"")+"|"+t.var:t.region,o=t=>{const e=it(t);return e&&e._edit.rendered},i=t=>null!=t.region&&"theme"!==t.kind&&Kr.has(t.region),s=()=>{go(!0);const s=no();if(Vr&&"function"==typeof Vr.onPublish)return Promise.resolve(Vr.onPublish(s,{log:l,cursor:c})).then(e);if(!s.length)return So(),Promise.resolve({results:[]});const a=t=>(uo++,fetch("/__edit/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({patches:t,base:io})}).then(t=>t.json()).catch(t=>{throw Co(null),t})),d=bo(new Set(s.filter(i).map(t=>t.region))),u=t=>({region:t.region,status:"error",reason:Ur.has(t.region)&&i(t)?`x-edit="${t.region}": ${Ur.get(t.region)}`:o(t.region)&&i(t)?`x-edit="${t.region}" is inside content ${o(t.region)} renders, so mnfst-run can't write it to a source file`:`not published: tied by a move to x-edit="${d.via.get(t.region)}", which mnfst-run can't write`}),f=s.filter(t=>!d.has(t.region)),m=(n,o,i)=>{const a=new Set([...d,...o||[],...o?i.filter(o.out).map(r):[]]),l=new Set,c=s.map(t=>{if(d.has(t.region)){const e=u(t);return l.add(e),e}const e=n.results[i.indexOf(t)];return o&&o.out(t)&&l.add(e),e}),f=e(Object.assign({},n,{results:c}),a.size?a:void 0,l);return Co(n,!(!t||!t.rebase)),f};if(!f.length){const t=e({results:s.map(u)},d);return Promise.resolve(t)}return a(f).then(t=>{const e=n(t,f);if(!e)return m(t,null,f);Co(t,!1);const r=f.filter(t=>!e.out(t));return a(r).then(n=>{const o=f.map((o,i)=>e.out(o)?t.results[i]&&"error"===t.results[i].status?t.results[i]:{region:o.region,status:"error",reason:`not published: tied by a move to x-edit="${e.via.get(o.region)||[...e].find(t=>!e.via.has(t))}", which failed`}:n.results[r.indexOf(o)]);return m(Object.assign({},n,{results:o}),e,f)})})},a=t=>{const n=no();return n.length?e({results:n.map(e=>({region:e.region,status:"error",reason:t}))}):{results:[]}},d=Vr&&"function"==typeof Vr.onPublish||io&&so?Promise.resolve(null):lo?Promise.resolve("the source changed before this page could read its base from the dev server; reload to continue"):ao().then(()=>io&&so?null:"the dev server's base (/__edit/base) could not be read, so nothing can be checked against the source; nothing was published"),u=()=>{const t=Object.assign({},io);return ao(!0).then(()=>(Object.keys(io||{}).some(e=>/\.html?$/i.test(e)&&t[e]!==io[e])&&(Mo=!0),s()))};return d.then(e=>e?a(e):t&&t.rebase?u():s())}(t));return Oo=e.catch(()=>{}),e}let Mo=!1;function Po(){Vr&&(Vr.active=!0),to()}function Ro(){Vr&&(Vr.active=!1),rt().forEach(t=>{t._edit.gated&&t._armed&&(Xr(t),t._armed=!1)}),jo()}function jo(){Vr&&(Vr.canUndo=c>0,Vr.canRedo=c<l.length,Vr.version=(Vr.version||0)+1,po&&setTimeout(So,0))}const $o=t=>t._editField&&!t._editRich?t.textContent:W(t,t.innerHTML.trim()),No=t=>!!t.closest('[data-edit-hotkeys="off"]');function Bo(){const t=document.activeElement;if(!t||void 0===t._preEdit||!t.isContentEditable)return;const e=()=>{document.activeElement===t&&(or(t),t._preEdit=$o(t))};e(),setTimeout(e,0)}function Ho(t){if(t.altKey||!t.metaKey&&!t.ctrlKey)return null;const e=(t.key||"").toLowerCase();return"z"===e?t.shiftKey?"redo":"undo":"y"!==e||!t.ctrlKey||t.metaKey||t.shiftKey?null:"redo"}function qo(t){if(t.defaultPrevented||s)return;const e=Ho(t);if(!e)return;const n="redo"===e,r=t.target&&1===t.target.nodeType?t.target:document.body;if(/^(INPUT|TEXTAREA|SELECT)$/.test(r.tagName)||$(r.closest("[data-rich-text]")))return;const o=r.closest("[data-edit-area]");if(o){const t=ct(o);if(!t||!Qr(t)||No(o))return}else{if(r.isContentEditable)return;if(!rt().some(t=>Qr(t)&&!No(t)))return}r.isContentEditable&&void 0!==r._preEdit&&$o(r)!==r._preEdit||(n?c>=l.length:0===c)||(t.preventDefault(),n?Oe():Ce())}function Do(){if(l.length){!function(){const t=t=>("st-move"===t.kind?[t.from,t.to]:null!=t.region?[t.region]:[]).some(t=>{const e=it(t);return e&&!e._edit.persist});if(!l.some(t))return;let e=0;const n=l.filter((n,r)=>{const o=!t(n);return o&&r<c&&e++,o});l=n,c=e,zt++,T()}();for(const[t,e]of Object.entries(Le())){const n=it(t);n&&"data"===e.kind&&Wo(n,()=>Jt(n,"data",e.snap))}if(l.some(t=>/^st-/.test(t.kind))&&(ae(rt()),le()),l.some(t=>"cmp-main"===t.kind||"cmp-inst"===t.kind)&&Gt(),l.some(t=>"data-val"===t.kind)){const t=rt().find(t=>"data"===mt(t));t&&Wo(t,ue)}l.some(t=>"theme"===t.kind)&&Dr(),l.some(t=>"lock"===t.kind)&&rt().forEach(xe),jo()}}function Wo(t,e){const n=ht(t),r=h(t);let o=0;const i=setInterval(()=>{let t=!1;try{t=Array.isArray(window.Alpine.evaluate(r,n))}catch{}t?(clearInterval(i),e()):++o>100&&clearInterval(i)},50)}let Io=!1;function zo(){if(Io||!window.Alpine||!Alpine.directive)return;Io=!0,document.body&&!document.body.hasAttribute("x-data")&&document.body.setAttribute("x-data","{}"),Alpine.directive("edit",(t,{modifiers:e,expression:n},{cleanup:r})=>{et(t,e,n),Yr&&!Gr&&(Gr=!0,queueMicrotask(()=>{Gr=!1,to()})),r(()=>function(t){Object.keys(Y).forEach(e=>{Y[e]===t&&delete Y[e]}),Lr.delete(t),V.has(t)&&(t._armed&&(Xr(t),t._armed=!1),t._editObserver&&(t._editObserver.disconnect(),t._editObserver=null),V.delete(t),delete t._edit,ot(),t.removeAttribute("data-edit-area"),Pe&&(Pe===t||t.contains(Pe))&&je(null),jo())}(t))}),Alpine.store("edit",{active:!1,canUndo:!1,canRedo:!1,version:0,stale:[],conflicts:[],onPublish:null,toggle(){this.active?Ro():Po()},on(){Po()},off(){Ro()},undo:()=>Ce(),redo:()=>Oe(),publish:t=>Lo(t),patches:()=>no(),export:()=>JSON.parse(JSON.stringify({log:l,cursor:c})),get target(){return this.version,Pe},set target(t){(t=>{je(t&&1===t.nodeType?Ne(t)||t:null)})(t)},can(t,e){return this.version,Xe(t,void 0===e?Pe:e)},lock:(t,e)=>_e(void 0===t?Pe:t,e,!0),unlock:(t,e)=>_e(void 0===t?Pe:t,e,!1),copy:t=>Ve(t),cut:t=>tn(t),paste:t=>en(t),duplicate:t=>Qe(t),remove:t=>Ze(t),move:(t,e,n)=>function(t,e,n){const r=Ne(null==t?Pe:t);if(!r||!qe(r))return!1;const o=Be(r),i="string"==typeof e?it(e):e;if(!i||1!==i.nodeType||i===r||r.contains(i))return!1;const s=ct(i);if(!(o&&s&&Qr(o)&&Qr(s)&&De(i)))return!1;n&&n.parentElement!==i&&(n=null);const a=r.parentElement;if(!Bt(r,i))return!1;if("data"===mt(o))return i===a&&($t(r,t=>i.insertBefore(t,n?jt(n):null)),xn(o,i),!0);if("static"!==mt(o)||"static"!==mt(s))return!1;if(o!==s&&He(r)&&!Et(r))return!1;const l=k(a),c=k(i);return $t(r,t=>i.insertBefore(t,n?jt(n):null)),i===a?me(o,i,l):(pe(o,s,r,a,l,c),!0)}(t,e,n),nest(t){const e=Ne(void 0===t?Pe:t);return!!e&&qe(e)&&Pn(e)},unnest(t){const e=Ne(void 0===t?Pe:t);return!!e&&qe(e)&&Rn(e)},block:t=>$e(t),attr:(t,e,n)=>kr(t,e,n),classes:Sr,scope(t,e){return this.version,t&&1===t.nodeType?Cr(t):null==t?Cr(e):function(t,e){const n=Tr(null==e?Pe:e);return!(!n||"instance"!==t&&"main"!==t||(n._editScope=t,Re(),0))}(t,e)},revert:t=>Or(t),clearConflicts(){_=[],this.conflicts=[],T()}}),Vr=Alpine.store("edit");const n=()=>Alpine.store("edit");Alpine.magic("edit",n),window.__manifestEditMagic=n;const r=window.__manifestEditStubWrites;r&&Object.keys(r).forEach(t=>{try{Vr[t]=r[t]}catch{}delete r[t]}),window.__manifestEditStub&&setTimeout(()=>{window.__manifestEditStub.v++},0),(()=>{try{e=location.pathname;const n=JSON.parse(localStorage.getItem(t(e)));n&&8===n.v?(l=n.log||[],c=n.cursor??l.length,l.forEach(t=>u.add(t)),_=Array.isArray(n.conflicts)?n.conflicts:[],_.forEach(t=>x.add(t)),Vr&&(Vr.conflicts=_.slice())):n&&localStorage.removeItem(t(e))}catch{}})(),window.__mnfstEdit&&ao(),setTimeout(()=>{to(),Do()},450),document.addEventListener("keydown",qo),window.addEventListener("click",Qn,!0),window.addEventListener("auxclick",Qn,!0),document.addEventListener("contextmenu",rn,!0),document.addEventListener("dropdown:context",rn,!0),window.addEventListener("manifest:route-change",()=>{e!==location.pathname&&(e=location.pathname,T())}),function(){if(!window.__manifestAlpineStarted&&![...document.querySelectorAll("[x-data]")].some(t=>t._x_marker))return;const t=t=>/^x-edit(\.|$)/.test(t),e=[...document.querySelectorAll("*")].filter(e=>!e._edit&&[...e.attributes].some(e=>t(e.name)));e.forEach(e=>{e._x_marker&&[...e.attributes].filter(e=>t(e.name)).forEach(t=>e.setAttribute(t.name,t.value))}),e.some(t=>!t._x_marker)&&Alpine.initTree(document.body)}()}document.addEventListener("alpine:init",zo),window.Alpine&&Alpine.directive&&setTimeout(zo,0)}();
|
|
1
|
+
!function(){const e=e=>"mnfst-edit-log:"+(e||location.pathname);let t=location.pathname;const n=["text","move","size","data"],r=["text","move"],o=["move","remove","duplicate","text","attrs","size"],i={sort:".move",authoring:"nothing (visuals are on by default; use .bare to hide them, .persist to keep edits)",style:"$edit.classes / $edit.attr",none:".lock"};let s=null,a=0,l=[],c=0;const d={},u=new WeakSet,f=["x-html","x-text","x-markdown","x-icon","x-svg","x-code","x-code-group","x-chart","x-anchors","x-carousel","x-color","x-colorpicker","x-combobox","x-date","x-defer","x-virtual","x-import"],m=e=>[...e.attributes].some(e=>{const t=e.name.toLowerCase();return f.some(e=>t===e||t.startsWith(e+"."))}),p=new Set(["SCRIPT","STYLE","TEXTAREA","TITLE","NOSCRIPT","TEMPLATE","XMP","IFRAME","NOEMBED","NOFRAMES"]),h=e=>[...e.children].find(e=>"TEMPLATE"===e.tagName&&e.hasAttribute("x-for"))||null;function g(e){if(m(e))return"";let t="";for(const n of e.childNodes)3===n.nodeType?t+=n.textContent:1!==n.nodeType||be(n)||"TEMPLATE"===n.tagName||k(n)||n._manifestComponent||(t+=g(n));return t}const b=e=>e.tagName.toUpperCase()+":"+g(e).replace(/\s+/g," ").trim().slice(0,24),y=(e,t)=>"@"+encodeURIComponent(e)+"@"+t,v=e=>e&&"~"===e[0]?e.slice(e.indexOf("~",1)+1):e;let E=0;const w=()=>Date.now().toString(36)+(++E).toString(36)+Math.random().toString(36).slice(2,6);function k(e){for(let t=e.previousElementSibling;t;t=t.previousElementSibling){if("TEMPLATE"!==t.tagName)continue;if(t._x_currentIfEl===e)return!0;const n=t._x_lookup;if(n&&(n instanceof Map?[...n.values()]:Object.values(n)).includes(e))return!0}return!1}function A(e){const t=Object.create(null);return Ae(e).map(e=>{const n=e.getAttribute("data-edit-host")||e.getAttribute("data-edit-key");if(n)return n;const r=b(e),o=t[r]=(t[r]||0)+1;return o>1?r+"#"+o:r})}let _=[];const x=new WeakSet,S=new Set([location.pathname]),T=t=>{if(l.length>400){const e=l.length-400;l.splice(0,e),c=Math.max(0,c-e)}const n=l.slice(0,c).filter(e=>u.has(e)),r=l.slice(c).filter(e=>u.has(e));S.add(t||location.pathname);const o=_.filter(e=>x.has(e));(t?[t]:[...S]).forEach(t=>{try{n.length||r.length||o.length?localStorage.setItem(e(t),JSON.stringify(Object.assign({v:8,log:[...n,...r],cursor:n.length},o.length?{conflicts:o}:{}))):localStorage.removeItem(e(t))}catch{}})},C=(e,t)=>JSON.stringify(e)===JSON.stringify(t);function O(e,t){for(let n=e;n&&1===n.nodeType;n=n.parentElement){const e=getComputedStyle(n).getPropertyValue(t).trim();if(e)return e}return""}function L(e,t,n){const r=O(e,t);return r?"none"===r&&"--edit-size"!==t?n??"":r:n??""}function M(e,t){if(!t&&!/--rich-text-/.test(e))return e;const n=document.createElement("div");n.setAttribute("style",e),t&&n.style.removeProperty("position");const r=[];for(let e=0;e<n.style.length;e++)r.push(n.style.item(e));return r.filter(e=>e.startsWith("--rich-text-")).forEach(e=>n.style.removeProperty(e)),n.getAttribute("style")||""}const j=e=>M(e.getAttribute("style")||"",!!e._editPos),P=e=>e?e.tagName.toLowerCase():"",R=new Set(["B","I","EM","STRONG","U","S","SMALL","CODE","MARK","SUB","SUP","BR","SPAN","A"]),$=e=>!!e&&1===e.nodeType&&e.hasAttribute("data-rich-text")&&!e._editRt,N=e=>window.ManifestRichText.sanitize(e,!1,!0);let B=!1;const H=e=>{const t=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT),n=[];for(let e=t.nextNode();e;e=t.nextNode())n.push(e);return n},q=(e,t)=>!(X(t.name,t.value,e.tagName)||"style"===t.name&&/expression|url\s*\(|javascript:|@import/i.test(t.value));function z(e){const t=Ne.interactive.join(","),n=!!e.closest("a, button");return[...e.querySelectorAll(t)].forEach(r=>{const o=r.parentElement&&r.parentElement.closest(t);(n||o&&e.contains(o))&&r.replaceWith(...r.childNodes)}),e.innerHTML.trim()}const I=(e,t)=>window.ManifestRichText?$(e)?window.ManifestRichText.sanitize(t,!0,!0):function(e,t){const n=document.createElement("template");n.innerHTML=String(null==e?"":e);const r=[],o="mnfst"+Math.random().toString(36).slice(2)+Date.now().toString(36),i=new RegExp("("+o+"\\d+_)");if(H(n.content).forEach(e=>{if(t=e.data,!/^-?>|-->|--!>|<!-$/.test(t))return e.replaceWith(o+r.length+"_"),void r.push(e.data);var t;e.remove(),B||(B=!0,console.warn("[edit] a comment that cannot be written back as it is was left out of edited text"))}),n.innerHTML=N(n.innerHTML),r.length){const e=document.createTreeWalker(n.content,NodeFilter.SHOW_TEXT),t=[];for(let n=e.nextNode();n;n=e.nextNode())n.nodeValue.includes(o)&&t.push(n);t.forEach(e=>e.replaceWith(...e.nodeValue.split(i).filter(Boolean).map(e=>i.test(e)&&e.startsWith(o)?document.createComment(r[parseInt(e.slice(o.length),10)]):document.createTextNode(e))))}!function(e){const t=e=>{let t=e.lastChild;for(;t&&8===t.nodeType;)t=t.previousSibling;return t};for(let n=0;n<1e3;n++){let n=t(e);for(;n&&1===n.nodeType&&"BR"!==n.tagName&&t(n);)n=t(n);if(!n||n===e)return;if(!(3===n.nodeType?!n.nodeValue.trim():"BR"===n.tagName||!t(n)&&!/^(IMG|WBR)$/.test(n.tagName)))return;n.remove()}}(n.content),n.content.querySelectorAll("*").forEach(e=>[...e.attributes].forEach(t=>{q(e,t)||e.removeAttribute(t.name)}));const s=Ne.interactive.join(","),a=!!(t&&t.closest&&t.closest("a, button"));return[...n.content.querySelectorAll(s)].forEach(e=>{(a||e.parentElement&&e.parentElement.closest(s))&&e.replaceWith(...e.childNodes)}),n.content.querySelectorAll("a").forEach(e=>{e.textContent.trim()||e.querySelector("img")||e.replaceWith(...e.childNodes)}),n.innerHTML.trim()}(t,e):function(e){const t=document.createElement("template");t.innerHTML=String(null==e?"":e);const n=e=>[...e.childNodes].forEach(e=>{if(8===e.nodeType)return e.remove();1===e.nodeType&&(R.has(e.tagName)?([...e.attributes].forEach(t=>{const n=t.name.toLowerCase();("A"!==e.tagName||"href"!==n||X("href",t.value,"A"))&&e.removeAttribute(t.name)}),n(e)):e.replaceWith(document.createTextNode(e.textContent)))});return n(t.content),t.innerHTML}(t);function D(e,t){const n=I(e,t);e.innerHTML===n||$(e)&&I(e,e.innerHTML.trim())===n||(e.innerHTML=n,e._rt&&"function"==typeof e._rt.settle&&e._rt.settle())}const W={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:" ",tab:"\t",newline:"\n",colon:":"},F=e=>String(e).replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);?/gi,(e,t)=>{if("#"===t[0]){const n=/^#x/i.test(t)?parseInt(t.slice(2),16):parseInt(t.slice(1),10);return n>=0&&n<1114112?String.fromCodePoint(n):e}const n=W[t.toLowerCase()];return void 0===n?e:n}),K={script:["src","type"],iframe:["src","srcdoc"],embed:["src","srcdoc"],object:["src","srcdoc","data"],frame:["src","srcdoc"],link:["href","rel"],base:["href","rel"],meta:["http-equiv","content"]},U=new Set(["set","animate","animatetransform","animatemotion"]),J=/^data:image\/(png|jpeg|gif|webp|avif)[;,]/;function X(e,t,n){const r=String(e||"").trim().toLowerCase(),o=String(n||"").toLowerCase();if(!r||!/^[a-z_][\w:.-]*$/i.test(r))return/^[@:]/.test(r)?"Alpine directive":"invalid name";if("text"===r)return"reserved name";if("action"===r||"formaction"===r)return"form target";if(r.startsWith("on"))return"event handler attribute";if(r.startsWith("x-"))return"Alpine directive";if(r.startsWith("data-edit-"))return"plugin attribute";if("srcdoc"===r)return"inline document";if(U.has(o)&&["attributename","to","values","from","by"].includes(r))return"SVG animation target";if(K[o]&&K[o].includes(r))return"loads or runs content";if(null==t)return null;for(const e of[String(t),F(t)]){const t=e.replace(/[\u0000-\u0020\u007f]/g,"").toLowerCase();if(/(^|[,(;'"=])(javascript|vbscript):/.test(t))return"script URL";const n=t.match(/(^|[,(;'"=])data:[^,)]*/g)||[];if(n.length&&("img"!==o&&"source"!==o||"src"!==r&&"srcset"!==r||!n.every(e=>J.test(e.replace(/^[,(;'"=]/,"")))))return"data URL"}return null}const V=new Set,Y={},G=new Set,Q=e=>{const t=ce(e);for(let n=e&&e.parentElement;n;n=n.parentElement){if(m(n))return!0;if(n===t)break}return!1},Z=f.filter(e=>"x-code-group"!==e&&"x-carousel"!==e&&"x-defer"!==e);function ee(e){for(let t=e&&e.parentElement;t;t=t.parentElement){if(1!==t.nodeType)continue;const e=[...t.attributes].map(e=>e.name.toLowerCase()).find(e=>Z.some(t=>e===t||e.startsWith(t+".")));if(e)return e.split(".")[0]}return null}function te(e,t,s){if(t.includes("cssvar"))return function(e,t,n){const r=(t||"").trim(),o=r.match(/^([\w-]+)\s*:\s*(--[\w-]+)$/);e._cssvar=o?{scope:o[1],var:o[2]}:{scope:null,var:r},e._cssvar.persist=!(!n||!n.includes("persist")),Br.add(e)}(e,s,t);if(t.forEach(e=>{i[e]&&!G.has(e)&&(G.add(e),console.warn(`[edit] x-edit.${e} was removed — use ${i[e]}`))}),t.includes("grab"))return;if(t.includes("lock")){const n=t.filter(e=>o.includes(e));return void(e._editLock=new Set(n.length?n:["*"]))}const l=new Set(n.filter(e=>t.includes(e))),c=t.includes("theme"),d=(s||"").trim()||"area-"+ ++a;if(c&&(Y[d]=e),c&&!l.size)return void(t.includes("persist")&&(e._editPersist=!0));l.size||r.forEach(e=>l.add(e)),(s||"").trim()&&[...V].some(t=>t!==e&&t._edit&&t._edit.key===d)&&console.warn("[edit] duplicate x-edit key (deltas will mis-route):",d);const u=t.includes("bare");e._edit={key:d,caps:l,gated:t.includes("gated"),theme:c,persist:t.includes("persist"),bare:u,rendered:ee(e)},e.setAttribute("data-edit-area",u?"bare":""),V.add(e),oe()}let ne=null;const re=()=>ne||(ne=[...V].filter(e=>{for(let t=e;t;t=t.parentElement){if(t!==e&&t._edit)return!1;if(t._manifestComponent||t!==e&&m(t))return!0}return!0})),oe=()=>{ne=null},ie=e=>re().find(t=>t._edit.key===e),se=e=>re().filter(t=>t._edit.key===e._edit.key).length>1;function ae(e){if(void 0!==e._editSrc)return e._editSrc;let t=null;for(let n=e;n;n=n.parentElement){if(!n._manifestComponent)continue;const r=n===e&&window.ManifestComponentsLoader&&window.ManifestComponentsLoader.cache[n._manifestComponent],o=new RegExp("\\sx-edit(?:\\.[\\w-]+)*\\s*=\\s*([\"'])"+e._edit.key.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\1");(n!==e||r&&o.test(r))&&(t=n._manifestComponent);break}return e._editSrc=t}const le=e=>{const t=ae(e);return t?function(e){const t=window.ManifestComponentsRegistry&&window.ManifestComponentsRegistry.manifest||{},n=[...t.preloadedComponents||[],...t.components||[]].find(t=>String(t).split("/").pop().replace(".html","")===e);return String(n||"components/"+e+".html").replace(/^\/+/,"")}(t):"index.html"},ce=e=>e&&re().reduce((t,n)=>n!==e&&!n.contains(e)||t&&!t.contains(n)?t:n,null),de=e=>e._edit.key,ue=(e,t)=>{const n=function(e){for(let t=e;t;t=t.parentElement)if(t._edit)return t._edit;return null}(e);return!!n&&n.caps.has(t)&&!Lt(e,t)},fe=e=>{const t=null!=e&&ie(e);return!(!t||!t._edit.persist)};function me(e){return h(e)?"data":e.matches("[data-component]")&&!ae(e)||pe(e)?"component":"static"}const pe=e=>{const t=ke(e).filter(e=>"TEMPLATE"!==e.tagName),n=t[0];return 1!==t.length||!n.matches("[data-component]")||n._edit||n.querySelector("[data-edit-area]")?null:n};function he(e){const t=h(e),n=t&&t.getAttribute("x-for").match(/\bin\s+(.+)$/);return n?n[1].trim():null}const ge=e=>{const t=he(e),n=t&&t.match(/\$x\.(\w+)/);return n?n[1]:t||"source"},be=e=>e.hasAttribute("data-edit-handle")||e.hasAttribute("data-edit-ghost"),ye=e=>e&&e._manifestHost&&e._manifestHost.roots&&e._manifestHost.roots[0]===e?e._manifestHost.roots.slice():[e],ve=e=>!!e._manifestHost&&!!e._manifestHost.roots&&e._manifestHost.roots[0]!==e,Ee=e=>!!e&&1===e.nodeType&&e.hasAttribute("data-edit-host"),we=e=>e.getAttribute("data-edit-host")||e.getAttribute("data-edit-key"),ke=e=>Array.from(e.children).filter(e=>!be(e)&&!ve(e)),Ae=e=>ke(e).filter(e=>"TEMPLATE"!==e.tagName);let _e=!1;function xe(e,t){const n=e.getAttribute("data-key");if(null!=n)return n;const r=h(t),o=r&&r._x_keyExpression;if(o)try{const t=window.Alpine.evaluate(e,o);if(null!=t)return String(t)}catch{}return _e||(_e=!0,console.warn("[edit] data area rows have no identity — add :key to the x-for or :data-key to the row, or the order cannot be stored")),null}const Se=new Set(["P","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE","SPAN","A","LABEL","STRONG","EM","B","I","U","S","SMALL","CODE","MARK","SUB","SUP","Q","CITE","ABBR","TIME","DT","DD","FIGCAPTION","CAPTION","LEGEND","SUMMARY","BUTTON","OPTION"]),Te=new Set(["AREA","BASE","BR","COL","EMBED","HR","IMG","INPUT","LINK","META","PARAM","SOURCE","TRACK","WBR","VIDEO","AUDIO","CANVAS","SVG","svg","IFRAME","OBJECT","SELECT","TEXTAREA","PICTURE","MATH","math","TEMPLATE","SCRIPT","STYLE","NOSCRIPT","TITLE","XMP"]),Ce=new Set([...Se,"LI","TD","TH"]);function Oe(e){if(!window.ManifestRichText)return!1;const t=e.cloneNode(!0);return t.querySelectorAll("[data-edit-handle], [data-edit-ghost]").forEach(e=>e.remove()),H(t).forEach(e=>e.remove()),!t.children.length||(t.querySelectorAll("*").forEach(e=>[...e.attributes].forEach(t=>{t.name.startsWith("data-edit-")&&e.removeAttribute(t.name)})),N(t.innerHTML)===t.innerHTML&&[...t.querySelectorAll("*")].every(e=>[...e.attributes].every(t=>q(e,t))))}const Le=e=>Ce.has(e.tagName)&&ke(e).length>0&&!!e.textContent.trim()&&Oe(e),Me=e=>{for(let t=e&&e.parentElement;t&&1===t.nodeType;t=t.parentElement){if(t._editRtFormat)return t;if(t._edit)break}return null};function je(e){return!(!e||1!==e.nodeType||Te.has(e.tagName)||be(e)||(e=>Se.has(e.tagName)||e.hasAttribute("data-rich-text")||(e=>[...e.childNodes].some(e=>3===e.nodeType&&e.textContent.trim()))(e)||Le(e))(e))}function Pe(e){const t=[];let n=e.previousSibling;for(;;){let e=null;if(n&&3===n.nodeType){if(!/^[ \t]*(\r?\n)?[ \t]*$/.test(n.textContent))break;e=n,n=n.previousSibling}if(!n||8!==n.nodeType)break;let r=n.previousSibling;for(;r&&3===r.nodeType&&!r.textContent.trim();)r=r.previousSibling;if(!r)break;t.unshift(n,...e?[e]:[]),n=n.previousSibling}return t}const Re=e=>e?Pe(e)[0]||e:null;function $e(e,t){const n=Pe(e),r=ye(e).slice(1);t(e),n.length&&e.before(...n),r.length&&e.after(...r)}const Ne={only:{table:["caption","colgroup","thead","tbody","tfoot","script","template","style"],thead:["tr","script","template"],tbody:["tr","script","template"],tfoot:["tr","script","template"],tr:["td","th","script","template"],colgroup:["col","template"],ul:["li","script","template"],ol:["li","script","template"],menu:["li","script","template"],dl:["dt","dd","div","script","template"],select:["option","optgroup","hr","script","template"],datalist:["option","script","template"],optgroup:["option","script","template"]},parent:{tr:["thead","tbody","tfoot"],td:["tr"],th:["tr"],caption:["table"],colgroup:["table"],col:["colgroup"],thead:["table"],tbody:["table"],tfoot:["table"],li:["ul","ol","menu"],dt:["dl","div"],dd:["dl","div"],option:["select","datalist","optgroup"],optgroup:["select"]},interactive:["a","button","input","select","textarea","details","label","iframe","embed","object","audio","video","keygen"],phrasingOnly:["p","h1","h2","h3","h4","h5","h6","pre"],block:["address","article","aside","blockquote","details","dialog","div","dl","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","hr","main","menu","nav","ol","p","pre","search","section","table","ul","li","dd","dt"]};function Be(e,t){if(!e||!t)return!1;if(e.parentElement===t)return!0;const n=[];for(let e=t;e&&1===e.nodeType;e=e.parentElement)n.push(e.tagName.toLowerCase());const r=new Set,o=e=>[e,...e.querySelectorAll("*")].forEach(e=>{1===e.nodeType&&(r.add(e.tagName.toLowerCase()),"TEMPLATE"===e.tagName&&e.content&&[...e.content.children].forEach(o))});ye(e).forEach(o);const i=new Set;for(let e=t;e;e=e.parentElement)e._manifestComponent&&i.add(e._manifestComponent);return!(i.size&&ye(e).some(e=>[e,...e.querySelectorAll("*")].some(e=>e._manifestComponent&&i.has(e._manifestComponent)))||function(e,t,n,r){const o=Ne;return o.only[t]&&!o.only[t].includes(e)?`<${t}> takes only ${o.only[t].filter(e=>"script"!==e&&"template"!==e&&"style"!==e).join(", ")}`:o.parent[e]&&!o.parent[e].includes(t)?`<${e}> belongs in ${o.parent[e].join(" or ")}`:"dt"!==e&&"dd"!==e||"div"!==t||"dl"===n[1]?r.has("form")&&n.includes("form")?"a form cannot contain a form":(n.includes("a")||n.includes("button"))&&o.interactive.some(e=>r.has(e))?"interactive content cannot go inside a link or button":o.phrasingOnly.includes(t)&&o.block.some(e=>r.has(e))?`<${t}> takes only inline content`:null:`<${e}> belongs in a dl`}(e.tagName.toLowerCase(),t.tagName.toLowerCase(),n,r))}const He=e=>{const t=String(e||"").match(/[a-z%]+$/i);return t?t[0]:null};function qe(e,t,n,r,o){if("rem"===t)return+(e/parseFloat(getComputedStyle(document.documentElement).fontSize)).toFixed(2);if("em"===t)return+(e/parseFloat(getComputedStyle(n).fontSize)).toFixed(2);if("%"===t){const t=(r||n.parentElement).getBoundingClientRect(),i="w"===o?t.width:t.height;return i?+(e/i*100).toFixed(2):0}return Math.round(e)}function ze(e,t,n){const r=parseFloat(e);if(isNaN(r))return null;const o=He(e)||"px";if("rem"===o)return r*parseFloat(getComputedStyle(document.documentElement).fontSize);if("em"===o)return r*parseFloat(getComputedStyle(t).fontSize);if("%"===o){const e=(t.parentElement||t).getBoundingClientRect();return r/100*("h"===n?e.height:e.width)}return r}const Ie=(e,t,n)=>Math.min(Math.max(e,t),n),De="∅revert";let We=0;const Fe=new WeakMap;function Ke(e,t){return l.splice(c),l.push(e),c=l.length,We++,void 0===t&&(t=function(e){return"data-splice"!==e.kind&&"show"!==e.kind&&("st-move"===e.kind?fe(e.from)&&fe(e.to):null!=e.region&&fe(e.region))}(e)),t&&u.add(e),T(),Ko(),e}function Ue(e,t){return"data"===t?{source:ge(e),order:Ae(e).map(t=>xe(t,e))}:{}}async function Je(e,t,n){e&&n&&("data"===t&&Xe(e,n.order),io(e)&&eo(e))}function Xe(e,t){const n=he(e),r=h(e);try{const e=window.Alpine.evaluate(r,n);if(!Array.isArray(e))return;const o=new Map(e.map(e=>[String(e.id),e])),i=t.map(e=>o.get(String(e))).filter(Boolean);e.forEach(e=>{t.map(String).includes(String(e.id))||i.push(e)}),e.splice(0,e.length,...i)}catch{}}function Ve(){const e={},t={},n={},r={};for(let o=0;o<c;o++){const i=l[o];if("cmp-main"!==i.kind&&"cmp-inst"!==i.kind||i.sig&&(r[i.component+"|"+i.path]=i.sig),"cmp-main"===i.kind)e[i.component]=e[i.component]||{},(e[i.component][i.path]=e[i.component][i.path]||{})[i.prop]=i.value;else if("cmp-inst"===i.kind){const e=i.region;i.value===De?(n[e]=n[e]||new Set,"*"===i.path?(delete t[e],n[e]=new Set(["*"])):(t[e]&&delete t[e][i.path],n[e].add(i.path))):(t[e]=t[e]||{},(t[e][i.path]=t[e][i.path]||{})[i.prop]=i.value,n[e]&&(n[e].delete(i.path),n[e].delete("*")))}}return{main:e,inst:t,reverts:n,sigs:r}}const Ye=e=>[e,...e.querySelectorAll("*")].filter(e=>null!=e._editPath);function Ge(){const{main:e,inst:t,sigs:n}=Ve();re().forEach(r=>{if("component"!==me(r))return;const o=vr(r),i=de(r),s=pe(r);s&&Ye(s).forEach(s=>{const a=s._editPath,l=n[o+"|"+a];if(l&&P(s)!==l)return void console.warn("[edit] skip stale node (structure changed):",o,a);const c=t[i]&&t[i][a]||{},d=e[o]&&e[o][a]||{},u=r._baseText||{},f=r._baseClass||{},m=r._baseStyle||{},p=(e,t)=>void 0!==c[e]?c[e]:void 0!==d[e]?d[e]:t,h=p("text",u[a]),g=p("class",f[a]),b=p("style",m[a]);void 0!==h&&D(s,h),void 0!==g&&Cr(s,g),void 0!==b&&s.getAttribute("style")!==b&&(""===b?s.removeAttribute("style"):s.setAttribute("style",b))})})}function Qe(e,t,n,r,o){const i=t._editPath,s=e._editScope||"instance",a=vr(e),l=de(e);if(null==i)return!1;if("text"===n&&(r=I(t,r)),void 0===o&&(o="text"===n?t._preEdit:"style"===n?t._preStyle:t._preClass),o===r||"text"===n&&null!=o&&I(t,o)===r)return!1;const c=P(t);return Ke("main"===s?{kind:"cmp-main",component:a,path:i,prop:n,value:r,before:o,sig:c,region:l}:{kind:"cmp-inst",component:a,region:l,path:i,prop:n,value:r,before:o,sig:c}),Ge(),!0}function Ze(){const e={},t={},n={},r={},o={},i={},s=(e,t,n,r,o)=>{if(!r)return;const i=e[t]=e[t]||{},s=n||"";o&&s in i||(i[s]=r.slice())};for(let e=0;e<l.length;e++){const t=l[e];if("st-children"===t.kind)t.html&&Object.assign(i,t.html),s(n,t.region,t.parent,t.before,!0);else if("st-order"===t.kind)s(n,t.region,t.parent,t.before,!0);else if("st-move"===t.kind)s(n,t.from,t.fromParent,t.fromBefore,!0),s(n,t.to,t.toParent,t.toBefore,!0);else if("st-node"===t.kind){const e=o[t.path]=o[t.path]||{};t.prop in e||(e[t.prop]=t.before),t.sig&&(r[t.path]=t.sig)}}const a=new Set;for(let n=0;n<c;n++){const r=l[n];"st-node"===r.kind?(e[r.path]=e[r.path]||{})[r.prop]=r.value:"st-order"===r.kind||"st-children"===r.kind?(s(t,r.region,r.parent,r.order),a.add(r.parent||"#"+r.region),r.copies&&Object.entries(r.copies).forEach(([t,n])=>{e[t]=Object.assign({},n,e[t])})):"st-move"===r.kind&&(s(t,r.from,r.fromParent,r.fromOrder),s(t,r.to,r.toParent,r.toOrder),a.add(r.fromParent||"#"+r.from),a.add(r.toParent||"#"+r.to))}return{node:e,order:t,orderBase:n,sigs:r,base:o,html:i,touched:a}}function et(e,t,n,r){Ke({kind:"data-splice",region:de(e),source:ge(e),index:t,op:r,record:JSON.parse(JSON.stringify(n))}),setTimeout(()=>{d[de(e)]=Ue(e,me(e))},0)}const tt=(e,t)=>e===t?"":e.getAttribute("data-edit-key")||"";function nt(e,t,n,r,o){const i=A(t);if(C(n,i)&&!Object.keys(r||{}).length)return;const s={kind:"st-children",region:de(e),parent:tt(t,e),order:i,before:n,html:r||{}};o&&Object.keys(o).length&&(s.copies=o),ct(s,[...n,...i.filter(e=>"~"===e[0]).map(v)]),Ke(s)}function rt(e,t){l.forEach(n=>{t&&!t(n)||(["before","order","fromBefore","toBefore","fromOrder","toOrder","unsure"].forEach(t=>{var r;n[t]&&(n[t]=(r=n[t],Array.isArray(r)?r.map(e):r))}),["parent","fromParent","toParent","key","path"].forEach(t=>{"string"==typeof n[t]&&(n[t]=e(n[t]))}),n.html&&(n.html=Object.fromEntries(Object.entries(n.html).map(([t,n])=>[e(t),"string"==typeof n?n.replace(/data-edit-key="([^"]*)"/g,(t,n)=>`data-edit-key="${(e=>e.replace(/&/g,"&").replace(/"/g,"""))(e((e=>e.replace(/"/g,'"').replace(/&/g,"&"))(n)))}"`):n]))),n.copies&&(n.copies=Object.fromEntries(Object.entries(n.copies).map(([t,n])=>[e(t),n]))))})}const ot=e=>String(e).replace(/#\d+$/,""),it=e=>{const t=/#(\d+)$/.exec(e);return t?+t[1]:1},st=(e,t)=>it(e)-it(t);function at(e,t,n){const r=e[n];if(null==r||null==t[n]||t[n]===r||e.some((e,t)=>t!==n&&e===r))return null;if(t.length===e.length)return t.map((e,t)=>t).filter(o=>o!==n&&t[o]===r&&t[o]!==e[o]);const o=[];for(let r=-n;r<t.length-n;r++){if(!r)continue;let i=!0;for(let o=n;o<e.length&&i;o++)i=o+r>=0&&o+r<t.length&&t[o+r]===e[o];i&&o.push(n+r)}return o}const lt=e=>"string"==typeof e&&"@"===e[0]&&(/#\d+$/.test(e)||mt(ut()).has(e+"#2"));function ct(e,t){const n={},r=new Set;return t.forEach(e=>{if(!lt(e)||n[e])return;const t=v(e),o=ie(decodeURIComponent(t.slice(1,t.indexOf("@",1)))),i=o&&le(o),s=ho&&i&&ho[i];bo.has(ot(t))?r.add(t):s&&Object.keys(s).forEach(e=>{ot(e)===ot(t)&&(n[e]=s[e])})}),Object.keys(n).length&&(e.ids=n),r.size&&(e.unsure=[...r]),e}const dt=(e,t)=>{if(!e)return null;const n=document.createElement("template");n.innerHTML=e.trim();const r=n.content.firstElementChild;return r&&t&&r.setAttribute(/^[^@]*@[^@]*@X-[\w-]+:/.test(v(t))?"data-edit-host":"data-edit-key",t),r},ut=()=>re().filter(e=>"static"===me(e)&&!se(e)),ft=new Map;function mt(e){const t=new Map;return e.forEach(e=>[e,...e.querySelectorAll("[data-edit-key]")].forEach(e=>{if(e.closest("[data-edit-ghost]"))return;const n=e.getAttribute("data-edit-key");null==n||t.has(n)||t.set(n,e)})),e.forEach(e=>e.querySelectorAll("[data-edit-host]").forEach(e=>{const n=e.getAttribute("data-edit-host");t.has(n)||t.set(n,e)})),t}function pt(e){const t=mt(ut()),n=[],r=new Set(e.filter(e=>e._marked).map(de)),o=e=>r.has(e)&&!!ie(e)&&"static"===me(ie(e)),i=new Map,s=new Map,a=new Map,d=[],u={},f=e=>"string"==typeof e&&/^[0-9a-f]{12}$/.test(e);l.forEach(e=>{e.ids&&Object.entries(e.ids).forEach(([e,t])=>{!(e in u)&&f(t)&&(u[e]=t)})});const m=ot,p=(e,t=u[e])=>{if(!f(t))return null;const n=Object.keys(u).filter(t=>m(t)===m(e)).sort(st),r=n.indexOf(e);if(r<0)return null;const o=ie(g(e)),i=ho&&o&&ho[le(o)],s=Object.keys(i||{}).filter(t=>m(t)===m(e)).sort(st),a=at(n.map(n=>n===e?t:u[n]),s.map(b),r);return a&&a.map(e=>s[e])},h=new Set;l.forEach(e=>(e.unsure||[]).forEach(e=>h.add(e)));const g=e=>decodeURIComponent(e.slice(1,e.indexOf("@",1))),b=e=>"string"==typeof e&&"@"===e[0]&&r.has(g(e))&&t.has(e)?yo(e):null,y=(e,t,n)=>{const r=JSON.stringify([e,t]);!i.has(r)&&o(e)&&i.set(r,[e,t,n||[]])};l.forEach(e=>{"st-order"!==e.kind&&"st-children"!==e.kind||y(e.region,e.parent,e.before),"st-move"===e.kind&&(y(e.from,e.fromParent,e.fromBefore),y(e.to,e.toParent,e.toBefore))});const E=e=>String(e).slice(String(e).indexOf("@",1)+1).split(":")[0],w=(e,t)=>{const n=new Set,r=(e,t)=>{t=t||[],(e=e||[]).forEach(e=>{t.includes(e)||n.add(e)}),t.forEach(t=>{e.includes(t)||n.add(t)});const r=t.filter(t=>e.includes(t)).map(t=>e.indexOf(t)),o=[],i=new Array(r.length).fill(-1);r.forEach((e,t)=>{let n=0,s=o.length;for(;n<s;){const t=n+s>>1;r[o[t]]<e?n=t+1:s=t}n>0&&(i[t]=o[n-1]),o[n]=t});const s=new Set;for(let e=o.length?o[o.length-1]:-1;e>=0;e=i[e])s.add(e);t.filter(t=>e.includes(t)).forEach((e,t)=>{s.has(t)||n.add(e)})};return l.forEach(o=>{"st-order"!==o.kind&&"st-children"!==o.kind||o.region!==e||(o.parent||"")!==t||r(o.before,o.order),"st-move"===o.kind&&(o.from===e&&(o.fromParent||"")===t&&(n.add(o.key),r(o.fromBefore,o.fromOrder)),o.to===e&&(o.toParent||"")===t&&(n.add(o.key),r(o.toBefore,o.toOrder)))}),n};i.forEach(([e,n,r])=>{let o=""===n?ie(e):t.get(n),i=null;if(!o&&""!==n){const e=new Set(r.map(e=>t.get(e)).filter(Boolean).map(e=>e.parentElement));1===e.size&&(o=[...e][0],i=o.getAttribute("data-edit-key"))}const c=o?A(o):[],f=[...w(e,n)].filter(e=>"string"==typeof e&&"@"===e[0]),g=f.filter(e=>h.has(e)),b=f.filter(e=>{const t=p(e);return t&&t.length});if(g.length||b.length){const t=Object.keys(u).filter(e=>m(e)&&r.includes(e)&&(p(e)||[]).length);let o=g.length||i||c.join("\n")!==r.join("\n")||!((e,t)=>l.every(n=>{if("st-move"===n.kind)return!(n.from===e&&(n.fromParent||"")===t||n.to===e&&(n.toParent||"")===t);if("st-order"!==n.kind&&"st-children"!==n.kind||n.region!==e||(n.parent||"")!==t)return!0;if("st-order"===n.kind||n.order.some(e=>"@"!==e[0]))return!1;let r=0;for(const e of n.before)e===n.order[r]&&r++;return r===n.order.length}))(e,n)?null:new Map;if(o)for(const e of t){const n=p(e).filter(e=>t.includes(e));if(1!==n.length){o=null;break}o.set(e,n[0])}return o&&new Set(o.values()).size===t.length?void d.push([e,n,c,o]):void s.set(e,[...s.get(e)||[],{container:n,changed:[...new Set([...b,...g])].map(e=>{const t=e.slice(e.indexOf("@",1)+1);return{was:t,now:t}})}])}if(o&&c.join("\n")===r.join("\n")&&!i)return;const y=[];r.forEach((e,t)=>{c[t]!==e&&y.push({was:e,now:c[t]??null})}),c.slice(r.length).forEach(e=>y.push({was:null,now:e}));const k=w(e,n),_=!!o&&c.length===r.length&&r.every((e,t)=>E(e)===E(c[t])),x=new Set;l.forEach(e=>[e.before,e.order,e.fromBefore,e.toBefore,e.fromOrder,e.toOrder].forEach(e=>Array.isArray(e)&&e.forEach(e=>x.add(e))));const S=e=>{const t=e.cloneNode(!1);return[...t.attributes].forEach(e=>{/^(data-edit-|data-rich-text|contenteditable$|role$|aria-multiline$|tabindex$)/.test(e.name)&&t.removeAttribute(e.name)}),t.outerHTML.replace(/<\/[^>]+>$/,"")},T=e=>!!e.was&&!!e.now&&"@"===e.was[0]&&!t.has(e.was)&&!x.has(e.now)&&(()=>{const n=(e=>{for(const t of l)if("st-children"===t.kind&&t.html)for(const[n,r]of Object.entries(t.html))if("~"===n[0]&&v(n)===e){const e=document.createElement("template");e.innerHTML=r;const t=e.content.firstElementChild;if(t)return S(t)}return null})(e.was),r=t.get(e.now);return!n||!r||n===S(r)})();if(_&&y.every(e=>T(e)&&!k.has(e.was))){const t=a.get(e)||new Map;y.forEach(e=>t.set(e.was,e.now)),i&&i!==n&&t.set(n,i),a.set(e,t)}else s.set(e,[...s.get(e)||[],{container:n,changed:y.map(e=>({was:e.was&&E(e.was)&&e.was.slice(e.was.indexOf("@",1)+1),now:e.now&&e.now.slice(e.now.indexOf("@",1)+1)}))}])});const k=new Map;l.forEach(e=>{const t="st-move"===e.kind?e.to:e.region;[e.order,e.toOrder,e.fromOrder,e.before,Object.keys(e.html||{})].forEach(e=>Array.isArray(e)&&e.forEach(e=>{if("string"!=typeof e||"~"!==e[0])return;const n=v(e);k.has(n)||k.set(n,new Set),k.get(n).add(t)}))});const S=new Map;k.forEach((e,n)=>{if(!r.has(g(n)))return;const i=h.has(n)?null:p(n);if(i&&!i.length)return;if(i&&1===i.length&&t.has(i[0]))return void S.set(n,i[0]);if(!i&&!h.has(n))return;const a=n.slice(n.indexOf("@",1)+1);e.forEach(e=>{o(e)&&s.set(e,[...s.get(e)||[],{container:"",changed:[{was:a,now:a}],copy:!0}])})}),S.size&&(rt(e=>"string"==typeof e&&"~"===e[0]&&S.has(v(e))?e.slice(0,e.length-v(e).length)+S.get(v(e)):e,e=>!s.has("st-move"===e.kind?e.to:e.region)),We++),d.forEach(([e,t,n,r])=>{if(s.has(e))return;const o=e=>"string"==typeof e&&r.has(e)?r.get(e):e;let i=n.slice();l.forEach(n=>{if("st-children"===n.kind&&n.region===e&&(n.parent||"")===t){const e=n.before.filter(e=>!n.order.includes(e)).map(o);n.before=i.slice(),i=i.filter(t=>!e.includes(t)),n.order=i.slice(),n.html&&(n.html=Object.fromEntries(Object.entries(n.html).map(([e,t])=>[o(e),"string"==typeof t?t.replace(/data-edit-key="([^"]*)"/g,(e,t)=>`data-edit-key="${(e=>e.replace(/&/g,"&").replace(/"/g,"""))(o((e=>e.replace(/"/g,'"').replace(/&/g,"&"))(t)))}"`):t])))}n.ids&&n.region===e&&(n.ids=Object.fromEntries(Object.entries(n.ids).map(([e,t])=>[o(e),t]))),"st-node"===n.kind&&n.region===e&&"string"==typeof n.path&&(n.path=o(n.path)),"lock"===n.kind&&n.region===e&&(n.key=o(n.key))}),We++}),a.forEach((e,n)=>{if(s.has(n))return;const r=t=>"string"!=typeof t?t:e.has(t)?e.get(t):"~"===t[0]&&e.has(v(t))?t.slice(0,t.length-v(t).length)+e.get(v(t)):t,o=e=>Array.isArray(e)?e.map(r):e,i=e=>"string"==typeof e?e.replace(/data-edit-key="([^"]*)"/g,(e,t)=>`data-edit-key="${(e=>e.replace(/&/g,"&").replace(/"/g,"""))(r((e=>e.replace(/"/g,'"').replace(/&/g,"&"))(t)))}"`):e,a=(n,r)=>{if("~"!==n[0]||!e.has(v(n))||(e=>l.some(t=>"st-node"===t.kind&&t.path===e&&"text"===t.prop))(n))return i(r);const o=t.get(e.get(v(n)));if(!o)return i(r);const s=document.createElement("template");s.innerHTML=Xt(o,!0);const a=n.slice(0,n.length-v(n).length);return[s.content.firstElementChild,...s.content.firstElementChild.querySelectorAll("[data-edit-key]")].forEach(e=>{const t=e.getAttribute("data-edit-key");t&&"@"===t[0]&&e.setAttribute("data-edit-key",a+t)}),s.innerHTML};l.forEach(e=>{var t;"st-order"!==e.kind&&"st-children"!==e.kind||e.region!==n||(e.parent=r(e.parent),e.before=o(e.before),e.order=o(e.order),e.html&&(e.html=(t=e.html)&&"object"==typeof t?Object.fromEntries(Object.entries(t).map(([e,t])=>[r(e),a(e,t)])):t),e.copies&&(e.copies=Object.fromEntries(Object.entries(e.copies).map(([e,t])=>[r(e),t])))),"st-node"===e.kind&&e.region===n&&"string"==typeof e.path&&"~"===e.path[0]&&(e.path=r(e.path)),"st-move"!==e.kind||e.from!==n&&e.to!==n||(e.key=r(e.key),e.fromParent=r(e.fromParent),e.toParent=r(e.toParent),e.fromBefore=o(e.fromBefore),e.toBefore=o(e.toBefore),e.fromOrder=o(e.fromOrder),e.toOrder=o(e.toOrder)),"lock"===e.kind&&e.region===n&&(e.key=r(e.key))}),We++});const C=e=>("st-order"===e.kind||"st-children"===e.kind)&&s.has(e.region)||"st-move"===e.kind&&(s.has(e.from)||s.has(e.to))||"st-node"===e.kind&&s.has(e.region)&&"string"==typeof e.path&&"~"===e.path[0],O=e=>"st-node"===e.kind&&"string"==typeof e.path&&"@"===e.path[0]&&o(e.region)&&(!t.has(e.path)||(e=>(e.unsure||[]).includes(e.path)||(p(e.path,e.id)||[]).length>0)(e))||C(e);l.forEach((e,t)=>{O(e)&&t<c&&"st-node"===e.kind&&"@"===e.path[0]&&n.push(e)});const L=()=>l.forEach(e=>{e.ids&&Object.keys(e.ids).forEach(t=>{const n=b(t);n&&(e.ids[t]=n)})});if(!l.some(O))return L(),(a.size||d.length||S.size||l.some(e=>e.ids))&&T(),[];const M=new Map;n.forEach(e=>M.set(e.path+"|"+e.prop,e));const j=e=>"string"==typeof e?v(e).slice(v(e).indexOf("@",1)+1):"",P=[...M.values()].map(e=>({region:e.region,key:e.path,element:j(e.path),prop:e.prop,value:e.value,before:e.before,reason:`${j(e.path)} changed in the source, so the ${"text"===e.prop?"text":e.prop} edited into it was not applied`}));s.forEach((e,t)=>{const n=l.filter((e,n)=>n<c&&C(e)&&(e.region===t||e.from===t||e.to===t)),r=new Set,o=new Set,i=[];n.forEach(e=>{"st-move"===e.kind&&r.add(e.key),"st-order"!==e.kind&&"st-children"!==e.kind||w(t,e.parent||"").forEach(e=>r.add(e)),"st-children"===e.kind&&e.before.forEach(t=>{"@"!==t[0]||e.order.includes(t)||o.add(t)}),"st-children"===e.kind&&e.html&&Object.entries(e.html).forEach(([e,t])=>{if("~"!==e[0])return;const n=document.createElement("template");n.innerHTML=t;const r=l.filter((t,n)=>n<c&&"st-node"===t.kind&&t.path===e&&"text"===t.prop).pop();i.push({of:j(e),html:t,text:r?r.value:n.content.textContent.trim()})})});const s=e.flatMap(e=>e.changed),a=e=>String(e).replace(/^([A-Za-z][\w-]*):(#\d+)?$/,(e,t,n)=>`<${t.toLowerCase()}>${n?" "+n:""}`),d=[...new Set(s.map(e=>a(e.was||e.now)))],u=[...new Set([...r].filter(e=>e&&"@"===e[0]&&!o.has(e)).map(e=>a(j(e))))],f=[...new Set([...o].map(e=>a(j(e))))],m=[f.length&&`deleted ${f.join(", ")}`,u.length&&`moved ${u.join(", ")}`,i.length&&`copied ${i.map(e=>`${a(e.of)} ("${String(e.text).slice(0,40)}")`).join(", ")}`].filter(Boolean).join("; ");P.push({region:t,key:"",element:e.map(e=>e.container?j(e.container):t).join(", "),prop:"structure",value:{changed:s,moved:u,copies:i},before:null,reason:e.some(e=>e.copy)&&s.every(e=>e.was===e.now)?`the copied element ${d.join(", ")} has identical twins that were reordered or replaced in the source, so the layout edits (${m||"reordering"}) were not applied`:s.every(e=>e.was===e.now)?`identical elements ${d.join(", ")} were reordered or replaced in the source where the layout was edited, so the layout edits (${m||"reordering"}) were not applied`:`${d.join(", ")} changed in the source where the layout was edited, so the layout edits (${m||"reordering"}) were not applied`})}),P.forEach(e=>{_.push(e),fe(e.region)&&x.add(e)});let R=0;return l=l.filter((e,t)=>{const n=!O(e);return n&&t<c&&R++,n}),c=R,We++,L(),T(),Ko(),P.length&&(no&&(no.conflicts=_.slice()),console.warn("[edit] edits to elements that changed in the source were dropped:\n"+P.map(e=>" "+e.reason+("structure"===e.prop?"":`: "${String(e.value).slice(0,80)}"`)).join("\n")),document.dispatchEvent(new CustomEvent("edit:conflict",{detail:{conflicts:P}}))),P}function ht(){const{node:e,order:t,orderBase:n,sigs:r,base:o,html:i}=Ze(),s=mt(ut()),a=[];new Set([...Object.keys(n),...Object.keys(t)]).forEach(e=>{const r=Object.assign({},n[e]||{},t[e]||{});Object.entries(r).forEach(([t,n])=>a.push([e,t,n]))});const l=new Set;a.forEach(([,,e])=>e.forEach(e=>l.add(e)));const c=new Set,d=e=>{let t=s.get(e);return!t&&ft.has(e)&&(t=ft.get(e),ft.delete(e),s.set(e,t)),!t&&i[e]&&(t=dt(i[e],e),t&&(s.set(e,t),t.querySelectorAll("[data-edit-key]").forEach(e=>{const t=e.getAttribute("data-edit-key");s.has(t)||s.set(t,e)}))),t};let u=!0;for(;a.length&&u;){u=!1;for(let e=0;e<a.length;e++){const[t,n,r]=a[e],o=n?s.get(n):ie(t);if(!o||!o.isConnected)continue;a.splice(e--,1),u=!0;let f=Ae(o);const m=r.map(d).filter(e=>e&&e!==o&&!e.contains(o)),p=f.filter(e=>!m.includes(e)&&!l.has(we(e))&&!i[we(e)]),h=[...m,...p].flatMap(ye);if(f=f.flatMap(ye),h.length===f.length&&h.every((e,t)=>e===f[t]))continue;const g=f.length?f[f.length-1].nextSibling:Array.from(o.children).find(be)||null,b=new Map(h.map(e=>[e,e.isConnected?Pe(e):e._editLead||[]]));f.forEach(e=>{if(h.includes(e))return;e._editLead=Pe(e),e._editLead.forEach(e=>e.remove()),e.remove();const t=we(e);t&&ft.set(t,e)}),h.forEach(e=>{const t=ce(e);t&&c.add(t),o.insertBefore(e,g&&g.parentNode===o?g:null);const n=b.get(e);n.length&&e.before(...n)});const y=ce(o);y&&c.add(y)}}c.size&&oe(),(c.size?mt(ut()):s).forEach((t,n)=>{const i=e[n],s=o[n];if(!i&&!s)return;const a=r[n];a&&P(t)!==a?console.warn("[edit] skip stale static node",n):new Set([...Object.keys(i||{}),...Object.keys(s||{})]).forEach(e=>function(e,t,n){if(void 0!==n){if("text"===t)return D(e,n);if(!X(t,n,e.tagName))return"class"===t?Cr(e,n):"style"===t?function(e,t){null==t||""===t?e.removeAttribute("style"):e.getAttribute("style")!==t&&e.setAttribute("style",t),e._editPos&&!e.style.position&&(e.style.position="relative")}(e,n):void(null!==n?e.getAttribute(t)!==n&&e.setAttribute(t,n):e.removeAttribute(t))}}(t,e,i&&void 0!==i[e]?i[e]:s&&s[e]))}),c.forEach(e=>{e.isConnected&&(Yr(e),e._armed&&io(e)&&eo(e))})}function gt(e,t,n,r,o={}){const i=de(e),s=t.getAttribute("data-edit-key");if(!s||"!"===s[0])return!1;if("text"===n&&p.has(t.tagName))return!1;"text"===n&&(r=I(t,r));let a=o.before;if(void 0===a){const r="text"===n?e._baseText&&e._baseText[s]:"class"===n?e._baseClass&&e._baseClass[s]:"style"===n?e._baseStyle&&e._baseStyle[s]:t.getAttribute(n),o="text"===n?t._preEdit:"class"===n?t._preClass:"style"===n?t._preStyle:void 0;a=void 0!==o?o:r}if(a===r||"text"===n&&null!=a&&I(t,a)===r)return!1;"text"!==n||document.activeElement===t||$(t)||D(t,r);const d=l[c-1];if(o.coalesce&&d&&c===l.length&&"st-node"===d.kind&&d.region===i&&d.path===s&&d.prop===n&&Date.now()-(Fe.get(d)||0)<1e3)return d.before===r?(l.pop(),c--):(d.value=r,Fe.set(d,Date.now())),We++,T(),Ko(),!0;const u=Ke(Object.assign({kind:"st-node",region:i,path:s,prop:n,value:r,before:a,sig:P(t)},lt(s)?(()=>{const e=ct({},[s]);return e.ids&&e.ids[s]&&(e.id=e.ids[s]),e})():{},o.join?{join:!0}:{}));return o.coalesce&&Fe.set(u,Date.now()),!0}function bt(){const e={};for(let t=0;t<c;t++){const n=l[t];"data-val"===n.kind&&(((e[n.source]=e[n.source]||{})[n.id]=e[n.source][n.id]||{})[n.field]=n.value)}return e}function yt(){const e=bt(),t=new Map;l.forEach(e=>{if("data-val"===e.kind){const n=JSON.stringify([e.source,e.id,e.field]);t.has(n)||t.set(n,e)}}),t.forEach(t=>{const n=(e[t.source]=e[t.source]||{})[t.id]=e[t.source][t.id]||{};t.field in n||void 0===t.before||(n[t.field]=t.before)}),re().forEach(t=>{if("data"!==me(t))return;const n=ge(t),r=e[n];if(!r)return;const o=h(t),i=he(t);try{const e=window.Alpine.evaluate(o,i);Array.isArray(e)&&Object.entries(r).forEach(([t,n])=>{const r=e.find(e=>String(e.id)===String(t));r&&Object.entries(n).forEach(([e,t])=>{r[e]!==t&&(r[e]=t)})})}catch{}io(t)&&setTimeout(()=>yr(t),0)})}function vt(e,t,n){const r=j(t),o=me(e);return"component"===o?Qe(e,t,"style",r):"static"===o&>(e,t,"style",r,n)}function Et(e,t,n){const r=A(t);return!C(n,r)&&(Ke(ct({kind:"st-order",region:de(e),parent:tt(t,e),order:r,before:n},n)),!0)}function wt(e,t,n,r,o,i,s={}){const a=n.parentElement,l={kind:"st-move",from:de(e),to:de(t),fromParent:tt(r,e),toParent:tt(a,t),key:we(n),fromOrder:A(r),toOrder:A(a),fromBefore:o,toBefore:i};return s.join&&(l.join=!0),ct(l,[v(l.key),...o,...i]),Ke(l),oe(),Yr(t),io(e)&&eo(e),t!==e&&io(t)&&eo(t),l}const kt=(e,t)=>/^[~@]/.test(t)?t:e+"|"+t;let At=-1,_t=new Map;function xt(){if(At===We)return _t;_t=new Map;for(let e=0;e<c;e++){const t=l[e];if("lock"!==t.kind)continue;const n=kt(t.region,t.key),r=_t.get(n)||new Map;_t.set(n,r),(t.actions&&t.actions.length?t.actions:o).forEach(e=>r.set(e,t.value))}return At=We,_t}const St=()=>xt();function Tt(e,t){const n=me(t);if("static"===n)return e.getAttribute("data-edit-key");if(e===t)return"";if("component"===n)return null!=e._editPath?"path:"+e._editPath:null;const r=h(t);if(r&&e.parentElement===r.parentElement){const n=xe(e,t);return null==n?null:"row:"+n}return null}const Ct=e=>"data"===e?"text":"class"===e?"attrs":e,Ot=e=>Ee(e)?e:ve(e)?e._manifestHost.roots[0]:null;function Lt(e,t){const n=Ct(t),r=e&&1===e.nodeType&&Ot(e);r&&(e=r);let o=r?Ft(r):ce(e);const i=xt();for(let t=e;t&&1===t.nodeType;t=t.parentElement){let e;const s=Ot(t);if(s&&i.size){const t=i.get(s.getAttribute("data-edit-host"));t&&t.has(n)&&(e=t.get(n))}if(void 0===e&&o&&i.size&&(!s||t!==r)){const r=Tt(t,o),s=null!=r&&i.get(kt(de(o),r));s&&s.has(n)&&(e=s.get(n))}if(void 0===e&&t._editLock&&(e=t._editLock.has("*")||t._editLock.has(n)),e)return!0;if(t===o){if(s&&t!==r&&(o=Ft(t),o))continue;break}}return!1}function Mt(e,t,n){if(!e||1!==e.nodeType)return!1;const r=Ot(e),i=r?Ft(r):ce(e);if(!i)return!1;if(null!=t&&!o.includes(t))return console.warn("[edit] unknown lock action:",t),!1;if(r)return Ke({kind:"lock",region:de(i),key:r.getAttribute("data-edit-host"),actions:t?[t]:[],value:!!n}),jt(i),r._edit&&jt(r),!0;const s=Tt(e,i);return null==s?(console.warn("[edit] this element has no stable identity to lock"),!1):(Ke({kind:"lock",region:de(i),key:s,actions:t?[t]:[],value:!!n}),jt(i),!0)}function jt(e){e&&e._armed&&(to(e),io(e)&&eo(e))}const Pt=e=>{"cmp-main"===e.kind||"cmp-inst"===e.kind?Ge():"data-val"===e.kind?yt():"theme"===e.kind?Jr():"lock"===e.kind?jt(ie(e.region)):ht()};function Rt(e,t){if("show"===e.kind)return function(e,t){const n=ie(e.region);if(!n)return;const r=""===e.key?n:[n,...n.querySelectorAll("[x-show]")].find(t=>Tt(t,n)===e.key);if(r)try{nr(r,e.expr,t?e.before:e.value)}catch{}}(e,t),null;if("data-splice"===e.kind)!function(e,t){const n=ie(e.region);if(!n)return;const r=h(n),o=he(n);if(!r||!o)return;let i;try{i=window.Alpine.evaluate(r,o)}catch{return}Array.isArray(i)&&((t?"remove"===e.op:"insert"===e.op)?i.splice(Math.min(e.index,i.length),0,JSON.parse(JSON.stringify(e.record))):i.splice(e.index,1),setTimeout(()=>{d[e.region]=Ue(n,me(n))},0))}(e,t);else{if("data"===e.kind){const n=t?e.before:e.after;return d[e.region]=n,Je(ie(e.region),e.kind,n)}Pt(e)}return null}async function $t(){if(0===c)return;let e;do{e=l[--c],We++;const t=Rt(e,!0);t&&await t}while(e.join&&c>0);Xo(),T(),Ko()}async function Nt(){if(!(c>=l.length)){do{const e=l[c++];We++;const t=Rt(e,!1);t&&await t}while(c<l.length&&l[c].join);Xo(),T(),Ko()}}function Bt(){const e={};for(let t=0;t<c;t++){const n=l[t];"data"===n.kind&&(e[n.region]={kind:n.kind,snap:n.after})}return e}let Ht=null,qt=null;const zt=()=>{no&&(no.version=(no.version||0)+1)},It=e=>{qt=e,zt()};function Dt(e){e&&1!==e.nodeType&&(e=e.parentElement);const t=ce(e);if(Ee(e)&&Ft(e)&&"static"===me(Ft(e)))return e;if(!t||e===t)return null;const n=me(t);if("data"===n){const n=h(t),r=n&&n.parentElement;for(let n=e;n&&n!==t;n=n.parentElement)if(n.parentElement===r)return n;return null}if("component"===n){for(let n=e;n&&n!==t;n=n.parentElement)if(null!=n._editPath)return n;return null}let r=null;for(let n=e;n&&n!==t;n=n.parentElement)(Ee(n)||ve(n))&&(r=Ee(n)?n:n._manifestHost.roots[0]);if(r)return r;for(let n=e;n&&n!==t;n=n.parentElement){if(be(n))return null;if(je(n.parentElement))return n}return null}const Wt=e=>(e=>!!e&&1===e.nodeType&&Dt(e)===e)(e)?e:Dt(e),Ft=e=>e&&ce(e.parentElement),Kt=e=>!!e&&(!!e._edit||e.hasAttribute("data-edit-area")),Ut=e=>!!e&&!!e.parentElement&&!be(e)&&!Q(e)&&ue(e.parentElement,"move")&&!Lt(e,"move")&&"component"!==me(ce(e.parentElement));function Jt(e){if(!e||1!==e.nodeType)return!1;const t=ce(e);if(!t||!io(t)||!je(e))return!1;for(let n=e;n&&n!==t;n=n.parentElement)if(n._manifestComponent)return!1;return ue(e,"move")}function Xt(e,t){const n=e.cloneNode(!0),r=[e,...e.querySelectorAll("*")],o=[n,...n.querySelectorAll("*")];o.forEach((e,t)=>{mn.has(r[t])&&e.removeAttribute("tabindex")});const i=o.filter((e,t)=>t>0&&k(r[t]));return pr(e,n),i.forEach(e=>e.remove()),n.querySelectorAll("[data-edit-handle], [data-edit-live], [data-edit-ghost]").forEach(e=>e.remove()),[n,...n.querySelectorAll("*")].forEach(e=>{[...e.attributes].forEach(n=>{!n.name.startsWith("data-edit-")||t&&"data-edit-key"===n.name||e.removeAttribute(n.name)}),e.removeAttribute("contenteditable"),e.removeAttribute("draggable")}),n.outerHTML}function Vt(e){const t=h(e),n=he(e);if(!t||!n)return null;try{const e=window.Alpine.evaluate(t,n);return Array.isArray(e)?e:null}catch{return null}}const Yt=(e,t)=>{const n=Vt(e);if(!n)return-1;const r=xe(t,e);return n.findIndex(e=>String(e&&null!=e.id?e.id:e)===String(r))};function Gt(e,t){const n=new Set(e.map(e=>String(e&&e.id)));if(!n.has(String(t)))return String(t);let r=2,o=`${t}-copy`;for(;n.has(o);)o=`${t}-copy-${r++}`;return o}const Qt=["move","remove","duplicate","text","attrs","class","size","copy","cut","paste"],Zt=e=>!(!e||!Ht||"static"===me(e)&&"static"!==Ht.kind);function en(e){const t=e?Wt(e):null;return t?Jt(t.parentElement)?t.parentElement:null:re().find(e=>io(e)&&Jt(e))||null}function tn(e,t){if(!Qt.includes(e))return!1;if("paste"===e){const e=Ht&&en(t);return!!e&&Zt(ce(e))}if(!t||1!==t.nodeType||Q(t))return!1;if(Ee(t)&&("move"===e||"duplicate"===e||"remove"===e)){const n=Ft(t);return!(!n||!io(n))&&("move"===e?Ut(t):ue(t.parentElement,"move")&&!Lt(t,e))}const n=ce(t);if(!n||!io(n))return!1;const r=me(n);if("size"===e)return!!t._edit&&t._edit.caps.has("size")&&!Lt(t,"size");if("text"===e)return ue(t,"text")&&!t.hasAttribute("x-text")&&!t.hasAttribute("x-html")&&("true"===t.getAttribute("contenteditable")||!!t._pieceMode||t.hasAttribute("data-rich-text")||null!=t._editField&&ue(t,"data"));if(("attrs"===e||"class"===e)&&"static"===r&&t._manifestComponent)return!1;if("attrs"===e||"class"===e){if("data"===r||Lt(t,"attrs"))return!1;const n=Me(t);if(n)return"attrs"===e&&ue(n,"text");if("component"===r)return"class"===e&&null!=t._editPath;const o=t.getAttribute("data-edit-key");return!!o&&"!"!==o[0]}if("component"===r)return!1;const o=Wt(t);if(!o)return!1;if("copy"===e)return!Ee(o);if("cut"===e)return tn("copy",o)&&tn("remove",o);if("move"===e)return Ut(o);const i="duplicate"===e?"duplicate":"remove";return ue(o.parentElement,"move")&&!Lt(o,i)}function nn(e){const t=Wt(void 0===e?qt:e);if(!t)return!1;const n=Ft(t);return!!n&&(Ht={html:Xt(t,!0),ops:rn(t),source:de(n),kind:me(n)},zt(),!0)}function rn(e){const t=Ze(),n={};return[e,...e.querySelectorAll("[data-edit-key]")].forEach(e=>{const r=e.getAttribute("data-edit-key");r&&t.node[r]&&(n[r]=Object.assign({},t.node[r]))}),n}function on(e,t,n,r,o){const i=A(t),s=function(e,t){const n=w(),r={};return[e,...e.querySelectorAll("[data-edit-key]")].forEach(e=>{const o=e.getAttribute("data-edit-key");if(!o||"!"===o[0])return void e.setAttribute("data-edit-key","!"+w());const i="~"+n+"~"+v(o);e.setAttribute("data-edit-key",i),t&&t[o]&&(r[i]=Object.assign({},t[o]))}),r}(n,o);r?r.after(n):t.appendChild(n),Yr(e),eo(e),nt(e,t,i,{[n.getAttribute("data-edit-key")]:Xt(n,!0)},s)}function sn(e){const t=Wt(void 0===e?qt:e);if(!tn("duplicate",t))return!1;const n=Ft(t);if("data"===me(n)){const e=Vt(n),r=Yt(n,t);if(!e||r<0)return!1;const o=JSON.parse(JSON.stringify(e[r]));return o&&null!=o.id&&(o.id=Gt(e,o.id)),e.splice(r+1,0,o),et(n,r+1,o,"insert"),!0}if(Ee(t))return function(e,t){const n=t.parentElement,r=A(n),o=ye(t),i=o.map(e=>dt(Xt(e)));if(i.some(e=>!e))return!1;const s={roots:i},a="~"+w()+"~"+v(we(t));return i.forEach(e=>{e._manifestComponent=t._manifestComponent,e._manifestHost=s,e.removeAttribute("data-component")}),i[0].setAttribute("data-edit-host",a),o[o.length-1].after(...i),Yr(e),eo(e),nt(e,n,r,{[a]:i[0].outerHTML}),!0}(n,t);const r=dt(Xt(t,!0));return!!r&&(on(n,t.parentElement,r,t,rn(t)),!0)}function an(e){const t=Wt(void 0===e?qt:e);if(!tn("remove",t))return!1;const n=Ft(t);if("data"===me(n)){const e=Vt(n),r=Yt(n,t);if(!e||r<0)return!1;const o=e[r];return e.splice(r,1),et(n,r,o,"remove"),qt===t&&It(null),!0}const r=t.parentElement,o=A(r),i=we(t),s=Ee(t)?t.outerHTML:Xt(t,!0);return t._editLead=Pe(t),t._editLead.forEach(e=>e.remove()),ye(t).slice(1).forEach(e=>e.remove()),t.remove(),ft.set(i,t),(qt===t||qt&&t.contains(qt))&&It(null),nt(n,r,o,{[i]:s}),!0}const ln=e=>{const t=Wt(void 0===e?qt:e);return tn("remove",t)&&nn(t)&&an(t)};function cn(e){if(!Ht)return!1;const t=en(void 0===e?qt:e);if(!t)return!1;const n=Wt(void 0===e?qt:e),r=ce(t);if(!Zt(r))return!1;if("data"===me(r)){const e=Vt(r);if(!e)return!1;const t=n?Yt(r,n)+1:e.length,o=document.createElement("template");o.innerHTML=Ht.html;const i={id:Gt(e,"pasted"),label:(o.content.textContent||"").trim()};return e.splice(t,0,i),et(r,t,i,"insert"),!0}if("static"!==me(r))return!1;const o=dt(Ht.html);return!(!o||!Be(o,t)||(on(r,t,o,n&&n.parentElement===t?n:null,Ht.ops),0))}const dn=e=>e.target.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.target.tagName);function un(e){const t=ce(e.target&&1===e.target.nodeType?e.target:e.target&&e.target.parentElement);t&&io(t)&&It(Dt(e.target))}const fn=e=>{const t=getComputedStyle(e).position;return"absolute"===t||"fixed"===t},mn=new WeakSet;let pn,hn=null;function gn(e){pn&&pn.isConnected||(pn=document.createElement("div"),pn.setAttribute("data-edit-live",""),pn.setAttribute("aria-live","polite"),document.body.appendChild(pn)),pn.textContent=e}function bn(e){e.removeAttribute("data-edit-piece"),e.removeAttribute("data-edit-grabbable"),mn.has(e)&&(e.removeAttribute("tabindex"),mn.delete(e))}function yn(e){const t=new Set(function(e){const t=me(e);if("component"===t)return[];if("data"===t){const t=h(e);return t?Ae(t.parentElement):[]}const n=[],r=e=>Ae(e).forEach(e=>{e.closest("[data-edit-ghost], [x-edit\\.grab]")||(e._manifestComponent?Ee(e)&&n.push(e):(n.push(e),je(e)&&!m(e)&&r(e)))});return je(e)&&r(e),n}(e).filter(Ut));e.querySelectorAll("[data-edit-piece]").forEach(n=>{t.has(n)||ce(n.parentElement)!==e||bn(n)}),t.forEach(e=>{e.setAttribute("data-edit-piece",""),e.toggleAttribute("data-edit-grabbable",!!Ln(e)),e.hasAttribute("tabindex")||(e.tabIndex=0,mn.add(e))})}const vn=e=>{const t=getComputedStyle(e);return/grid/.test(t.display)||/flex/.test(t.display)&&!String(t.flexDirection||"").startsWith("column")?"x":"y"};function En(e,t,n,r){const o=e.getBoundingClientRect();let i=("x"===vn(r)?t<o.left+o.width/2:n<o.top+o.height/2)?e:ye(e).pop().nextElementSibling;for(;i&&(i===s||i.hasAttribute("data-edit-dragging"));)i=i.nextElementSibling;return{container:r,ref:i}}function wn(e,t,n,r){const o=t?e.left:e.top,i=t?e.width:e.height,s=t?n:r;if(!i)return!0;const a=Math.min(.25*i,24);return s>=o+a&&s<=o+i-a}const kn=(e,t,n,r)=>wn(e.getBoundingClientRect(),"x"===vn(r),t,n),An=e=>!!e&&!!e._edit&&Jt(e)&&"static"===me(e)&&(e=>!!e&&re().includes(e))(e);function _n(e,t,n){if(n.dataList)return{container:n.home,ref:xn(n.home,e,t)};const r=n.nested;if(r&&r.el.isConnected&&n.ghost.parentElement===r.el&&e>=r.rect.left&&e<=r.rect.right&&t>=r.rect.top&&t<=r.rect.bottom&&wn(r.rect,r.horiz,e,t))return{container:r.el,ref:xn(r.el,e,t)};n.nested=null;const o=n.crossOK?function(e,t,n){const r=document.elementFromPoint?document.elementFromPoint(e,t):null;let o=r&&ce(r);if(o&&o!==n&&n.contains(o)&&(o=n),o&&An(o))return o;const i=[n,...document.querySelectorAll("[data-edit-drop-target]")].filter((e,t,n)=>An(e)&&n.indexOf(e)===t),s=(n,r)=>e>=n.left-r&&e<=n.right+r&&t>=n.top-r&&t<=n.bottom+r;let a=null,l=1/0;for(const n of i){const r=n.getBoundingClientRect(),o=Math.hypot(Math.max(r.left-e,0,e-r.right),Math.max(r.top-t,0,t-r.bottom)),c=ze(L(n,"--edit-drop-reach",""),n,"w")??48,d=n.parentElement,u=d&&d!==document.body&&d!==document.documentElement&&!i.some(e=>e!==n&&d.contains(e))&&s(d.getBoundingClientRect(),0);(s(r,c)||u)&&o<l&&(a=n,l=o)}return a}(e,t,n.area):n.area;if(!o)return null;const i=document.elementFromPoint?document.elementFromPoint(e,t):null;if(i&&n.ghost&&(i===n.ghost||n.ghost.contains(i)))return null;if(i&&i!==o&&o.contains(i)){let r=i;for(let e=i;e&&e!==o;e=e.parentElement)(Ee(e)||ve(e))&&(r=Ee(e)?e:e._manifestHost.roots[0]);for(let i=r;i&&i!==o;i=i.parentElement){if(i===n.item||n.item.contains(i)||be(i))continue;const r=i.parentElement;if(je(r))if(Ee(i)){if(Jt(r)&&Be(n.item,r)&&!n.item.contains(r))return En(i,e,t,r)}else{if(n.ghost&&(i===n.home||i.contains(n.ghost))&&Jt(i)&&Be(n.item,i))return{container:i,ref:xn(i,e,t)};if(je(i)&&Jt(i)&&Be(n.item,i)&&kn(i,e,t,r))return n.ghost&&n.ghost.parentElement!==i&&(n.nested={el:i,rect:i.getBoundingClientRect(),horiz:"x"===vn(r)}),{container:i,ref:xn(i,e,t)};if(Jt(r)&&Be(n.item,r)&&!n.item.contains(r))return En(i,e,t,r)}}}if(!(n.crossOK||i&&o.contains(i))){const r=n.ghost.parentElement;return{container:r,ref:xn(r,e,t)}}return Jt(o)&&Be(n.item,o)?{container:o,ref:xn(o,e,t)}:null}function xn(e,t,n){const r="y"===vn(e);for(const o of Ae(e)){if(o===s||o.hasAttribute("data-edit-dragging")||Lt(o,"move"))continue;const e=o.getBoundingClientRect(),i=e.left+e.width/2,a=e.top+e.height/2;if(r&&!/inline/.test(getComputedStyle(o).display)){if(a>n)return o;continue}const l=Math.abs(a-n)<e.height/2;if(a-n>e.height/2||l&&i>t)return o}return null}function Sn(e,t,n,r){const o=e.offsetParent||e.parentElement,i=o.getBoundingClientRect();let s=t-r.grabX-i.left-(o.clientLeft||0)+(o.scrollLeft||0),a=n-r.grabY-i.top-(o.clientTop||0)+(o.scrollTop||0);const l=o.clientWidth-e.offsetWidth,c=o.clientHeight-e.offsetHeight;s=l>0?Ie(s,0,l):Math.max(0,s),a=c>0?Ie(a,0,c):Math.max(0,a),e.style.left=qe(s,r.lu,e,o,"w")+r.lu,e.style.top=qe(a,r.tu,e,o,"h")+r.tu}const Tn=e=>{e.style.removeProperty("left"),e.style.removeProperty("top"),e.getAttribute("style")||e.removeAttribute("style")},Cn=(e,t)=>A(e).filter((n,r)=>Ae(e)[r]!==t);function On(e){const t=this;if(!io(t)||"mouse"===e.pointerType&&0!==e.button||e._editDrag)return;const n=e.target;if(!n||1!==n.nodeType||n.hasAttribute("data-edit-handle"))return;if(n._pieceMode)return void Ar(n);let r=null;for(let e=n;e&&e!==t;e=e.parentElement)if(e.hasAttribute("data-edit-piece")&&Ut(e)){r=e;break}if(!r)return;const o=Ln(r);if(o){if(!o.contains(n))return;e.preventDefault()}else if(Mn(n))return;e._editDrag=!0,function(e,t,n){const r=t.parentElement,o=ye(t).pop().nextElementSibling,i=ye(t).slice(1),a="data"===me(n),l={item:t,area:n,home:r,dataList:a,ghost:null,crossOK:!a&&"static"===me(n)&&(Ee(t)||!Kt(t)),homeBefore:a?null:A(r),lu:He(t.style.left)||"px",tu:He(t.style.top)||"px"},c=t.getBoundingClientRect(),d=t.getAttribute("style"),u=j(t),f=Pe(t);l.grabX=e.clientX-c.left,l.grabY=e.clientY-c.top;const m=e.clientX,p=e.clientY;let h=!1,g=0,b=m,y=p,v=null;const E=e=>{const r=document.activeElement;r&&t.contains(r)&&r.isContentEditable&&r.blur();try{window.getSelection().removeAllRanges()}catch{}l.crossOK&&re().forEach(e=>{e!==n&&An(e)&&e.setAttribute("data-edit-drop-target","")});const o=l.ghost=t.cloneNode(!0);pr(t,o),o.setAttribute("data-edit-ghost",""),o.setAttribute("x-ignore",""),o.removeAttribute("id"),o.querySelectorAll("[id]").forEach(e=>e.removeAttribute("id")),[o,...o.querySelectorAll("*")].forEach(e=>{[...e.attributes].forEach(t=>{t.name.startsWith("data-edit-")&&"data-edit-ghost"!==t.name&&e.removeAttribute(t.name)}),e.removeAttribute("contenteditable"),e.removeAttribute("tabindex"),e.removeAttribute("draggable")}),t.before(o),Object.assign(t.style,{position:"fixed",width:c.width+"px",height:c.height+"px",margin:"0",pointerEvents:"none"}),t.setAttribute("data-edit-dragging",""),s=o;try{t.setPointerCapture(e.pointerId)}catch{}},w=()=>{g=0,t.style.left=b-l.grabX+"px",t.style.top=y-l.grabY+"px"},k=e=>{const n=l.ghost,{container:o,ref:i}=e,s=v&&v.container===o&&v.ref===i;v=e,s||o.insertBefore(n,i&&i.parentElement===o?Re(i):null),fn(n)?(s||(o===r&&t.parentElement===r?r.insertBefore(n,t):n.nextElementSibling&&o.appendChild(n)),Sn(n,b,y,l)):(n.style.left||n.style.top)&&Tn(n)},_=e=>{if(b=e.clientX,y=e.clientY,!h){if(Math.hypot(b-m,y-p)<5)return;h=!0,E(e),w()}e.preventDefault();const t=_n(b,y,l);t&&k(t),g||(g=requestAnimationFrame(w))},x=e=>{if(document.removeEventListener("pointermove",_),document.removeEventListener("pointerup",S),document.removeEventListener("pointercancel",T),document.removeEventListener("keydown",C,!0),g&&cancelAnimationFrame(g),!h)return;document.querySelectorAll("[data-edit-drop-target]").forEach(e=>e.removeAttribute("data-edit-drop-target")),t.removeAttribute("data-edit-dragging"),e?l.ghost.remove():(l.ghost.replaceWith(t),f.length&&t.before(...f),i.length&&t.after(...i)),null==d?t.removeAttribute("style"):t.setAttribute("style",d),l.ghost=null,s=null;const a=()=>{o&&o.parentElement===r?r.insertBefore(t,Re(o)):r.appendChild(t),f.length&&t.before(...f),i.length&&t.after(...i)};if(e)return a(),void gn("Cancelled");const c=t.parentElement,m=ce(c);if(c!==r&&(l.dataList||!Jt(c)||!Be(t,c)||!m||m!==n&&(!l.crossOK||!An(m))))return a(),void gn("Cancelled");fn(t)?Sn(t,b,y,l):(t.style.left||t.style.top)&&Tn(t);const p=j(t)!==u;if(l.dataList)return jn(n,r),void gn("Dropped");let v=!1;c===r?v=Et(n,r,l.homeBefore):(wt(n,m,t,r,l.homeBefore,Cn(c,t)),v=!0),p&&vt(ce(t),t,{before:u,join:v}),gn(m!==n?"Moved to "+de(m):"Dropped")},S=()=>x(!1),T=()=>x(!0),C=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),x(!0))};document.addEventListener("pointermove",_),document.addEventListener("pointerup",S),document.addEventListener("pointercancel",T),document.addEventListener("keydown",C,!0)}(e,r,t)}const Ln=e=>[...e.querySelectorAll("[x-edit\\.grab]")].find(t=>t.closest("[data-edit-piece]")===e)||null,Mn=e=>{const t=document.activeElement;return!!t&&t!==document.body&&t.isContentEditable&&(t===e||t.contains(e))};function jn(e,t){return"data"===me(e)&&(Xe(e,Ae(t).map(t=>xe(t,e))),function(e){if(!e)return;const t=de(e),n=me(e),r=Ue(e,n),o=d[t];o&&C(o,r)||(Ke({region:t,kind:n,before:o??r,after:r}),d[t]=r)}(e),!0)}const Pn=(e,t)=>e.target!==t&&!!e.target.closest&&t.contains(e.target.closest('a[href], button, summary, [role="button"], [role="link"]')),Rn=e=>Ae(e.parentElement).filter(t=>t===e||!Lt(t,"move"));function $n(e){if(document.activeElement!==e)try{e.focus()}catch{}}function Nn(e,t){if(e._editRow)return;const n=e.target;if("Enter"===e.key&&n.matches&&n.matches("a[href]")&&or(n,t))return;if(n._pieceMode&&"Enter"===e.key)return e._editRow=!0,e.preventDefault(),void Ar(n,!0);let r=null;for(let e=n;e&&e!==t;e=e.parentElement)if(e.hasAttribute&&e.hasAttribute("data-edit-piece")&&Ut(e)){r=e;break}if(!hn){const t=Wt(n);if(t&&function(e,t){if(dn(e))return!1;const n=e.metaKey||e.ctrlKey,r=(e.key||"").toLowerCase();return n&&"c"===r?nn(t):n&&"x"===r?ln(t):n&&"v"===r?cn(t):n&&"d"===r?sn(t):!(n||"Delete"!==e.key&&"Backspace"!==e.key)&&an(t)}(e,t))return e._editRow=!0,e.preventDefault(),void e.stopPropagation()}if(!r)return;const o={ArrowUp:-1,ArrowDown:1}[e.key],i={ArrowLeft:-1,ArrowRight:1}[e.key],s=e.altKey&&!e.shiftKey&&!e.metaKey&&!e.ctrlKey;if(s&&null!=o&&(!hn||hn.item!==r))return e._editRow=!0,e.preventDefault(),void function(e,t){const n=Ft(e),r=e.parentElement,o=Rn(e),i=o.indexOf(e),s=i+t;if(i<0||s<0||s>=o.length)return void gn(`Position ${i+1} of ${o.length}`);const a="data"===me(n)?null:A(r),l=o[s],c=[];for(let n=t>0?e.nextElementSibling:e.previousElementSibling;n&&n!==l;n=t>0?n.nextElementSibling:n.previousElementSibling)c.push(n);const d=e=>[...Pe(e),...ye(e)];if(t>0){const t=Re(e);[l,...c].filter(e=>!ve(e)).forEach(e=>t.before(...d(e)))}else{let t=ye(e).pop();[...c.slice().reverse(),l].filter(e=>!ve(e)).forEach(e=>{t.after(...d(e)),t=ye(e).pop()})}const u=document.activeElement,f=window.getSelection&&window.getSelection(),m=f&&f.rangeCount?f.getRangeAt(0).cloneRange():null;if(a?Et(n,r,a):jn(n,r),u&&u.isConnected&&document.activeElement!==u&&(u.focus(),m))try{f.removeAllRanges(),f.addRange(m)}catch{}gn(`Moved to position ${s+1} of ${o.length}`)}(r,o);if(s&&null!=i&&!dn(e))return e._editRow=!0,e.preventDefault(),void(i>0?qn(r):zn(r));if(!(" "!==e.key&&"Enter"!==e.key||dn(e)||Pn(e,r)||e.altKey||e.metaKey||e.ctrlKey))return e._editRow=!0,e.preventDefault(),void(hn&&hn.item===r?(function(){const e=hn;hn=null,e&&(e.item.removeAttribute("data-edit-dragging"),e.before?Et(e.area,e.container,e.before):jn(e.area,e.container))}(),$n(r),gn("Dropped")):(hn&&Bn(),hn={item:r,area:Ft(r),container:r.parentElement,next:ye(r).pop().nextElementSibling,before:"data"===me(Ft(r))?null:A(r.parentElement)},r.setAttribute("data-edit-dragging","keyboard"),gn("Grabbed — arrow keys to move, Enter to drop")));if(hn&&hn.item===r){if("Escape"===e.key)return e._editRow=!0,e.preventDefault(),Bn(),$n(r),void gn("Cancelled");const t=o??i;if(null==t)return;e._editRow=!0,e.preventDefault();const n=Rn(r),s=n.indexOf(r)+t;if(s<0||s>=n.length)return;return $e(r,e=>{t>0?ye(n[s]).pop().after(e):Re(n[s]).before(e)}),$n(r),void gn(`Position ${s+1} of ${n.length}`)}n!==r||dn(e)||e.altKey||e.metaKey||e.ctrlKey||null==o&&null==i||!fn(r)||(e._editRow=!0,function(e,t){const n={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]}[e.key];if(!n)return;e.preventDefault(),t._moveTimer||(t._preStyle=j(t));const r=e.shiftKey?16:4,o=getComputedStyle(t),i=t.offsetParent||t.parentElement,s=He(t.style.left)||"px",a=He(t.style.top)||"px",l=Math.max(0,i.clientWidth-t.offsetWidth),c=Math.max(0,i.clientHeight-t.offsetHeight),d=Math.max(0,(parseFloat(o.left)||0)+n[0]*r),u=Math.max(0,(parseFloat(o.top)||0)+n[1]*r);n[0]&&(t.style.left=qe(l?Math.min(l,d):d,s,t,i,"w")+s),n[1]&&(t.style.top=qe(c?Math.min(c,u):u,a,t,i,"h")+a),clearTimeout(t._moveTimer),t._moveTimer=setTimeout(()=>{t._moveTimer=null;const e=t.isConnected&&ce(t);e&&vt(e,t)},350)}(e,r))}function Bn(){const e=hn;hn=null,e&&(e.item.removeAttribute("data-edit-dragging"),$e(e.item,t=>{e.next&&e.next.parentElement===e.container?e.container.insertBefore(t,Re(e.next)):e.container.appendChild(t)}))}const Hn=e=>e===ce(e)?de(e):e.tagName.toLowerCase();function qn(e){const t=Ft(e);if("static"!==me(t))return gn("Records stay in their list"),!1;let n=e.previousElementSibling;for(;n&&(be(n)||"TEMPLATE"===n.tagName||ve(n));)n=n.previousElementSibling;if(!n||Ee(n)||!Jt(n)||!Be(e,n))return gn("Nothing to nest into"),!1;const r=e.parentElement,o=A(r),i=A(n);return $e(e,e=>n.appendChild(e)),wt(t,t,e,r,o,i),$n(e),gn("Nested in "+Hn(n)),!0}function zn(e){const t=Ft(e),n=e.parentElement;if("static"!==me(t))return gn("Records stay in their list"),!1;const r=n&&n!==t?n.parentElement:null;if(!r||r!==t&&!t.contains(r)||!Jt(r))return gn("Already at the top level"),!1;if(!Be(e,r))return gn("Cannot move out here"),!1;const o=A(n),i=A(r);return $e(e,e=>ye(n).pop().after(e)),wt(t,t,e,n,o,i),$n(e),gn("Moved out to "+Hn(r)),!0}let In;function Dn(e,t){const n=e.getBoundingClientRect();e.dispatchEvent(new CustomEvent("edit:size",{bubbles:!0,detail:{width:n.width,height:n.height,css:{width:e.style.width,height:e.style.height},done:t}}))}const Wn=e=>"rtl"===getComputedStyle(e).direction;function Fn(e,t){const n=getComputedStyle(e).position;if("fixed"===n)return"w"===t?document.documentElement.clientWidth:document.documentElement.clientHeight;const r="absolute"===n&&e.offsetParent||e.parentElement;if(!r)return null;const o=getComputedStyle(r),i="w"===t,s=i?r.clientWidth:r.clientHeight;return"absolute"===n?s:i||function(e){for(let t=e,n=0;t&&n<32;t=t.parentElement,n++){if(t===document.documentElement)return!0;const e=getComputedStyle(t).position;if("absolute"===e||"fixed"===e)return!0;let n;if(t.computedStyleMap)try{n=String(t.computedStyleMap().get("height")).trim()}catch{}if(null==n&&(n=(t.style&&t.style.height||"").trim()||"auto"),"auto"===n||""===n)return!1;if(!n.endsWith("%"))return!0}return!1}(r)?s-(parseFloat(i?o.paddingLeft:o.paddingTop)||0)-(parseFloat(i?o.paddingRight:o.paddingBottom)||0):null}function Kn(e,t,n,r){if(!(e=String(e||"").trim())||"none"===e||"auto"===e)return r;if(/^-?[\d.]+%$/.test(e)){const o=Fn(t,n);return null==o?r:parseFloat(e)/100*o}const o=ze(e,t,n);return null==o?r:o}function Un(e,t){const n=Kn(t.minWidth,e,"w",0),r=Kn(t.minHeight,e,"h",0);return{minW:n,minH:r,maxW:Math.max(n,Kn(t.maxWidth,e,"w",1/0)),maxH:Math.max(r,Kn(t.maxHeight,e,"h",1/0))}}const Jn=e=>"x"===e?["left","right"]:"y"===e?["top","bottom"]:["top","right","bottom","left","top-left","top-right","bottom-left","bottom-right"];function Xn(e){const t=L(e,"--edit-size","both");if("none"===t)return;if(e._sizeBound)return;e._sizeBound=!0;const n=getComputedStyle(e).position;n&&"static"!==n||(e.style.position="relative",e._editPos=!0),(L(e,"--edit-size-edges","")||Jn(t).join(" ")).split(/\s+/).filter(Boolean).forEach(t=>{const n=function(e,t){const n=Wn(t);return e.replace(/start/g,n?"right":"left").replace(/end/g,n?"left":"right")}(t,e),r=document.createElement("span");r.setAttribute("data-edit-handle",t),r.tabIndex=0,r.setAttribute("role","slider"),r.setAttribute("aria-label",`Resize ${t}`),r.addEventListener("pointerdown",t=>function(e,t,n){const r=ce(t);if(!io(r)||"mouse"===e.pointerType&&0!==e.button||e.button>0)return;e.preventDefault(),e.stopPropagation();const o=t.getAttribute("style");t._preStyle=j(t);const i=getComputedStyle(t),s=t.getBoundingClientRect(),a=He(t.style.width)||"px",l=He(t.style.height)||"px",c=parseFloat(i.width)||s.width,d=parseFloat(i.height)||s.height,u=e.clientX,f=e.clientY,{minW:m,maxW:p,minH:h,maxH:g}=Un(t,i),b=n.includes("right"),y=n.includes("left"),v=n.includes("bottom"),E=n.includes("top"),w=Qn(t,"--edit-size-snap-distance","x","w"),k=Qn(t,"--edit-size-snap-distance","y","h"),A=Yn(t,"x","w"),_=Yn(t,"y","h"),x=Qn(t,"--edit-size-close","x","w"),S=Qn(t,"--edit-size-close","y","h"),T=null!=x||null!=S?function(e){const t=e.getAttribute("x-show");return null==t?null:Zn.test(t)?t:(er.has(e)||(er.add(e),console.warn('[edit] --edit-size-close needs an assignable x-show expression (e.g. x-show="open"); close is off here:',t)),null)}(t):null;let C;if(T)try{C=tr(window.Alpine.evaluate(t,T))}catch{}const O=e.target;try{O.setPointerCapture&&O.setPointerCapture(e.pointerId)}catch{}O.setAttribute("data-edit-resizing",""),In||(In=document.createElement("div"),In.setAttribute("data-edit-overlay",""),document.body.appendChild(In)),In.style.display="block";let L=c,M=d,P=!1;const R=()=>(b||y)&&null!=x&&L<x||(E||v)&&null!=S&&M<S,$=e=>{if(e!==P&&T){P=e;try{nr(t,T,!e&&C)}catch{}}},N=e=>{const n=e.clientX-u,r=e.clientY-f;(b||y)&&(L=c+(b?n:-n)),(E||v)&&(M=d+(v?r:-r)),$(R());let o=!1;if(b||y){const e=Ie(L,m,p),n=Gn(e,A,w);o=o||A.length>0&&n!==e,t.style.width=qe(n,a,t,t.parentElement,"w")+a}if(E||v){const e=Ie(M,h,g),n=Gn(e,_,k);o=o||_.length>0&&n!==e,t.style.height=qe(n,l,t,t.parentElement,"h")+l}t.toggleAttribute("data-edit-snapped",o&&!P),O.toggleAttribute("data-edit-snapped",o&&!P),Dn(t,!1)},B=()=>{document.removeEventListener("pointermove",N),document.removeEventListener("pointerup",z),document.removeEventListener("pointercancel",q),In&&(In.style.display="none"),["data-edit-snapped","data-edit-resizing"].forEach(e=>O.removeAttribute(e)),t.removeAttribute("data-edit-snapped")},H=()=>{null==o?t.removeAttribute("style"):t.setAttribute("style",o)},q=()=>{B(),$(!1),H(),Dn(t,!0)},z=()=>{B();const e=(b||y)&&null!=x&&L<x,n=(E||v)&&null!=S&&M<S;if((e||n)&&T){const o=(e?m:0)>0||(n?h:0)>0,i=t.style.display;H(),o&&(e&&m>0&&(t.style.width=qe(m,a,t,t.parentElement,"w")+a),n&&h>0&&(t.style.height=qe(h,l,t,t.parentElement,"h")+l));const s=vt(r,t);return Dn(t,!0),"none"===i&&(t.style.display="none"),void function(e,t,n,r,o){let i=o;try{void 0===i&&(i=tr(window.Alpine.evaluate(t,n))),nr(t,n,!1)}catch(e){return console.warn("[edit] could not close via x-show:",e),!1}const s=Tt(t,e);null!=s&&Ke(Object.assign({kind:"show",region:de(e),key:s,expr:n,before:i,value:!1},r?{join:!0}:{}))}(r,t,T,s,C)}if(e||n)return H(),void Dn(t,!0);vt(r,t),Dn(t,!0)};document.addEventListener("pointermove",N),document.addEventListener("pointerup",z),document.addEventListener("pointercancel",q)}(t,e,n)),r.addEventListener("keydown",t=>function(e,t,n){const r={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]};if(!r[e.key])return;const o=ce(t);if(!io(o))return;e.preventDefault(),e.stopPropagation(),t._keyTimer||(t._preStyle=j(t));const[i,s]=r[e.key],a=e.shiftKey?32:8,l=getComputedStyle(t),c=n.includes("right"),d=n.includes("left"),u=n.includes("top"),f=n.includes("bottom"),m=He(t.style.width)||"px",p=He(t.style.height)||"px",{minW:h,maxW:g,minH:b,maxH:y}=Un(t,l);if((c||d)&&i){const e=Ie((parseFloat(l.width)||0)+i*a*(c?1:-1),h,g);t.style.width=qe(e,m,t,t.parentElement,"w")+m}if((u||f)&&s){const e=Ie((parseFloat(l.height)||0)+s*a*(f?1:-1),b,y);t.style.height=qe(e,p,t,t.parentElement,"h")+p}Dn(t,!1),clearTimeout(t._keyTimer),t._keyTimer=setTimeout(()=>{t._keyTimer=null;const e=t.isConnected&&ce(t);e&&(vt(e,t),Dn(t,!0))},350)}(t,e,n)),e.appendChild(r)})}function Vn(e,t,n){const r=O(e,`${t}-${n}`);if(r)return"none"===r?"":r;const o=O(e,t);return"none"===o?"":o}function Yn(e,t,n){return Vn(e,"--edit-size-snap",t).split(/\s+/).filter(Boolean).map(t=>ze(t,e,n)).filter(e=>null!=e)}function Gn(e,t,n){if(!t.length)return e;let r=e,o=1/0;for(const n of t){const t=Math.abs(e-n);t<o&&(o=t,r=n)}return null==n||o<=n?r:e}const Qn=(e,t,n,r)=>{const o=Vn(e,t,n);return o?ze(o,e,r):null},Zn=/^\s*[A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*|\s*\[\s*(?:'[^'\\]*'|"[^"\\]*"|\d+)\s*\])*\s*$/,er=new WeakSet,tr=e=>{try{return void 0===JSON.stringify(e)||JSON.parse(JSON.stringify(e))}catch{return!0}};function nr(e,t,n){window.Alpine.evaluate(e,`${t} = ${JSON.stringify(n)}`)}function rr(e){requestAnimationFrame(()=>{if(!s&&!hn&&document.activeElement===e)try{const t=document.createRange();t.selectNodeContents(e);const n=window.getSelection();n.removeAllRanges(),n.addRange(t)}catch{}})}function or(e,t){const n=e.closest('[contenteditable="false"]');return!!n&&t.contains(n)&&!n.hasAttribute("data-edit-piece-mode")}function ir(e){const t=e.target&&e.target.closest&&e.target.closest("a[href]"),n=t&&ce(t);n&&io(n)&&!or(t,n)&&e.preventDefault()}const sr=new Set;let ar=!1;function lr(e,t){if(e._editRtFormat=t,e._editRt||e._pieceMode)return;const n=function(){const e=window.ManifestRichText;return e&&"function"==typeof e.attach?e:(ar||(ar=!0,console.warn("[edit] Rich Text is not loaded; text leaves fall back to plain contenteditable")),null)}();e._editRtPrior=["role","aria-multiline"].map(t=>[t,e.getAttribute(t)]);const r=n&&n.attach(e,{mode:"inline",breaks:!0,enter:"break",all:!1,format:t,onChange:()=>{}});r?(e._editRt=r,e.setAttribute("data-edit-text",""),sr.add(e)):e.setAttribute("contenteditable","true")}function cr(e){const t=e._editRt;t&&(e._editRt=null,sr.delete(e),e.removeAttribute("data-edit-text"),t.detach())}const dr=e=>sr.forEach(t=>{(!t.isConnected||e&&e.contains(t))&&cr(t)}),ur=e=>{const t=e._editRt;t&&(t.value=t.value)};function fr(e){const t=this,n=t._editRt,r=Vo(e);if(!n||!r)return;if(n.can(r))return e.preventDefault(),e.stopImmediatePropagation(),void n[r]();const o=ce(t);"undo"===r&&o&&io(o)&&!Jo(t)&&function(e){const t=e._editRt;if(!t||!t.can("redo")||!e._commitText)return;const n=function(e){const t=e._editRt.newest();if(!e._editField||e._editRich)return t.trim();const n=document.createElement("template");return n.innerHTML=t,n.content.textContent}(e);e._commitText(n)&&$t()}(t),Yo(e),e.defaultPrevented&&e.stopImmediatePropagation()}function mr(e){e.addEventListener("drop",t=>{const n=ce(e);n&&io(n)&&(t.preventDefault(),t.stopImmediatePropagation())})}function pr(e,t){const n=[e,...e.querySelectorAll("*")],r=[t,...t.querySelectorAll("*")];r.forEach(e=>{const t=e.getAttribute("style");if(t&&/--rich-text-/.test(t)){const n=M(t);n?e.setAttribute("style",n):e.removeAttribute("style")}}),n.forEach((e,t)=>{e._editRt&&r[t]&&([...r[t].attributes].forEach(e=>{e.name.startsWith("data-rich-text")&&r[t].removeAttribute(e.name)}),(e._editRtPrior||[]).forEach(([e,n])=>null==n?r[t].removeAttribute(e):r[t].setAttribute(e,n)))})}function hr(e,t,n){e._textBound||(e._textBound=!0,e._commitText=t,e.addEventListener("focus",()=>{ur(e),e._preEdit=Uo(e),rr(e)}),e.addEventListener("keydown",t=>{e.isContentEditable&&("Escape"===t.key?(t.preventDefault(),t.stopImmediatePropagation(),e.blur()):"Enter"!==t.key||!t.altKey||t.shiftKey||t.metaKey||t.ctrlKey||(t.preventDefault(),t.stopImmediatePropagation(),function(e){e.blur();const t=[e,...kr(e)].find(e=>e.hasAttribute&&e.hasAttribute("data-edit-piece"));if(t){t.isContentEditable&&(t._pieceMode=!0,t.setAttribute("data-edit-piece-mode",""),cr(t),t.setAttribute("contenteditable","false"),t.addEventListener("focusout",()=>Ar(t),{once:!0}));try{t.focus()}catch{}}}(e)))}),e.addEventListener("keydown",fr),mr(e),n&&e.addEventListener("input",n),e.addEventListener("blur",()=>t()))}const gr=e=>{const t=e.closest("[data-rich-text]");return!(!t||t===e&&e._editRt)};function br(e){e.querySelectorAll("[data-rich-text]:not([data-rich-text-bound])").forEach(t=>{!t._editRt&&ue(t,"text")&&/^[@~]/.test(t.getAttribute("data-edit-key")||"")&&(t._richBound||(t._richBound=!0,t.addEventListener("focusin",()=>{t._preEdit=Uo(t)}),t.addEventListener("blur",()=>{const n=ce(t)||e;("component"===me(n)?Qe:gt)(n,t,"text",t.innerHTML.trim())},!0)))})}function yr(e){const t=h(e);if(!t)return;const n=(t.getAttribute("x-for").match(/^\s*([\w$]+)\s+in\b/)||[])[1];if(!n)return;const r=ge(e),o=new RegExp("^\\s*"+n+"\\.([\\w$]+)\\s*$");Ae(e).forEach(t=>{let i=t.getAttribute("data-key");if(null==i){let e=null;try{e=window.Alpine.$data(t)[n]}catch{}e&&null!=e.id&&(i=String(e.id))}null!=i&&[t,...t.querySelectorAll("*")].forEach(t=>{const n=t.hasAttribute("x-html");if(t.children.length&&(!n||!Oe(t))||t.hasAttribute("data-edit-handle"))return;const s=t.getAttribute("x-text")||t.getAttribute("x-html");if(!s)return;const a=s.match(o);if(!a)return;const l=a[1];if(t._editField=l,t._editRich=n,!t._dvBound){t._dvBound=!0;const o=()=>n?z(t):t.textContent;t._commitText=n=>function(e,t,n,r,o,i){o=String(o),i&&i._editRich&&(o=I(i,o));const s=i?i._preEdit:void 0;return!(s===o||i&&i._editRich&&null!=s&&I(i,s)===o||(Ke({kind:"data-val",region:de(e),source:t,id:n,field:r,value:o,before:s}),yt(),0))}(e,r,i,l,n??o(),t),t.addEventListener("focus",()=>{ur(t),t._preEdit=Uo(t),$(t)||rr(t)}),t.addEventListener("focusin",()=>{t._preEdit=Uo(t)}),t.addEventListener("keydown",fr),mr(t),t.addEventListener("blur",()=>t._commitText(),!0)}$(t)||lr(t,n?"html":"plain")})})}const vr=e=>{const t=pe(e);return(t?.getAttribute("data-component")||"").replace(/-\d+$/,"")};function Er(e,t,n,r){if("main"!==(e._editScope||"instance"))return;const o=vr(e),i=t._editPath,{inst:s}=Ve();re().forEach(e=>{if("component"!==me(e)||vr(e)!==o)return;const a=pe(e);if(!a)return;const l=""===i?a:function(e,t){let n=e;for(const e of t.split(".").map(Number))if(n=ke(n)[e],!n)return null;return n}(a,i);l&&l!==t&&void 0===(s[de(e)]&&s[de(e)][i]||{})[n]&&("class"===n?Cr(l,r):l.innerHTML!==r&&(l.innerHTML=r))})}function wr(e){const t=pe(e);if(!t)return;e._editScope||(e._editScope="instance"),e._baseText=e._baseText||{},e._baseClass=e._baseClass||{},e._baseStyle=e._baseStyle||{};const n=n=>{const r=function(e,t){const n=[];let r=e;for(;r&&r!==t&&r.parentElement;)n.unshift(ke(r.parentElement).indexOf(r)),r=r.parentElement;return n.join(".")}(n,t);n._editPath=r,r in e._baseClass||(e._baseClass[r]=n.getAttribute("class")||""),r in e._baseStyle||(e._baseStyle[r]=n.getAttribute("style")||"")};n(t),t.querySelectorAll("*").forEach(e=>{e.hasAttribute("data-edit-handle")||n(e)}),br(e),Ye(t).forEach(t=>{if(t.children.length&&!Le(t)||!t.textContent.trim()||!ue(t,"text"))return;if(gr(t))return;const n=t._editPath;n in e._baseText||(e._baseText[n]=t.innerHTML.trim()),hr(t,n=>Qe(e,t,"text",n??z(t)),()=>Er(e,t,"text",t.innerHTML)),lr(t,"html")})}const kr=e=>{const t=[],n=ce(e);for(let r=e.parentElement;r&&r!==n;r=r.parentElement)t.push(r);return t};function Ar(e,t){if(e._pieceMode&&(e._pieceMode=!1,e.removeAttribute("data-edit-piece-mode"),"false"===e.getAttribute("contenteditable")&&(e.removeAttribute("contenteditable"),lr(e,e._editRtFormat||"html")),t)){try{e.focus()}catch{}rr(e)}}const _r=(e,t)=>e.getAttribute(":"+t)??e.getAttribute("x-bind:"+t);function xr(e){const t=_r(e,"class");if(null==t)return[];let n;try{n=window.Alpine.evaluate(e,t)}catch{return[]}const r=[],o=e=>String(e).split(/\s+/).filter(Boolean).forEach(e=>r.push(e));return"string"==typeof n?o(n):Array.isArray(n)?n.flat(1/0).filter(Boolean).forEach(o):n&&"object"==typeof n&&Object.entries(n).forEach(([e,t])=>{t&&o(e)}),r}const Sr=e=>String(e||"").split(/\s+/).filter(Boolean);function Tr(e){const t=new Set(xr(e));return Sr(e.getAttribute("class")).filter(e=>!t.has(e)).join(" ")}function Cr(e,t){const n=xr(e),r=[...new Set([...Sr(t),...n])].join(" ");r?e.getAttribute("class")!==r&&e.setAttribute("class",r):e.hasAttribute("class")&&e.removeAttribute("class")}function Or(e){if(null==e&&(e=qt),!e||1!==e.nodeType)return null;const t=ce(e);if(!t||!io(t))return null;const n=me(t);return"static"===n&&e._manifestComponent?null:{el:e,area:t,kind:n}}function Lr(e,t,n){const r=Or(n);if(!r)return!1;e=String(e||"").trim().toLowerCase();const o=!0===t?"":!1===t||null==t?null:String(t),i=X(e,o,r.el.tagName);if(i)return console.warn(`[edit] attribute refused (${i}):`,e),!1;if(Lt(r.el,"attrs"))return!1;const s="data"!==r.kind&&Me(r.el);if(s)return function(e,t,n,r){if(Lt(t,"text")||e.el.getAttribute(n)===r)return!1;const o=document.activeElement===t,i=o&&void 0!==t._preEdit?t._preEdit:Uo(t),s=e.el.getAttribute(n),a=Uo(t),l=t=>null===t?e.el.removeAttribute(n):e.el.setAttribute(n,t);if(l(r),Uo(t)===a)return l(s),console.warn(`[edit] ${n} is not kept inside text`),!1;const c=z(t),d="component"===e.kind?Qe(e.area,t,"text",c,i):gt(ce(t),t,"text",c,{before:i});return o&&(ur(t),t._preEdit=Uo(t)),d}(r,s,e,o);if("class"===e)return Mr(r,o||"");if("data"===r.kind)return console.warn("[edit] list rows are rendered from data; attributes on them are not editable"),!1;if("component"===r.kind)return console.warn("[edit] component nodes take class changes only"),!1;if(!/^[@~]/.test(r.el.getAttribute("data-edit-key")||""))return!1;null!=_r(r.el,e)&&console.warn(`[edit] ${e} is bound on this element; the binding will override the edited value`);const a=r.el.getAttribute(e);return a!==o&&(null===o?r.el.removeAttribute(e):r.el.setAttribute(e,o),gt(r.area,r.el,e,o,{before:a,coalesce:!0}))}function Mr(e,t){if("data"===e.kind)return console.warn("[edit] list rows are rendered from data; attributes on them are not editable"),!1;if(Me(e.el))return console.warn("[edit] class is not kept inside text"),!1;const n=Tr(e.el);return n!==(t=Sr(t).join(" "))&&(Cr(e.el,t),"component"===e.kind?null!=e.el._editPath&&(Er(e.area,e.el,"class",e.el.getAttribute("class")||""),Qe(e.area,e.el,"class",t,n)):!!/^[@~]/.test(e.el.getAttribute("data-edit-key")||"")&>(e.area,e.el,"class",t,{before:n,coalesce:!0}))}function jr(e,t){const n=Or(e);if(!n)return!1;if(Lt(n.el,"attrs"))return!1;const r=t(Sr(Tr(n.el)));return!!r&&Mr(n,r.join(" "))}const Pr={add(e,t){const n=Sr(e);return jr(t,e=>[...e,...n.filter(t=>!e.includes(t))])},remove(e,t){const n=new Set(Sr(e));return jr(t,e=>e.filter(e=>!n.has(e)))},toggle(e,t,n){const r=Or(t);if(!r)return!1;const o=Sr(e);return n??!o.every(e=>r.el.classList.contains(e))?Pr.add(e,r.el):Pr.remove(e,r.el)},set(e,t){const n=Or(t);return!!n&&!Lt(n.el,"attrs")&&Mr(n,e||"")},has(e,t){no&&no.version;const n=null==t?qt:t;return!!n&&1===n.nodeType&&Sr(e).every(e=>n.classList.contains(e))},list(e){no&&no.version;const t=null==e?qt:e;return t&&1===t.nodeType?Sr(Tr(t)):[]}},Rr=e=>{const t=e&&ce(e);return t&&"component"===me(t)?t:null};function $r(e){const t=Rr(null==e?qt:e);return t?t._editScope||"instance":null}function Nr(e){null==e&&(e=qt);const t=Rr(e);if(!t)return!1;if(e===t)Ke({kind:"cmp-inst",component:vr(n=t),region:de(n),path:"*",prop:"*",value:De}),Ge();else{if(null==e._editPath)return!1;!function(e,t){Ke({kind:"cmp-inst",component:vr(e),region:de(e),path:t._editPath,prop:"*",value:De}),Ge()}(t,e)}var n;return!0}const Br=new Set,Hr={},qr=new Set,zr=(e,t)=>(e||"")+"|"+t,Ir=e=>e&&Y[e]||document.documentElement,Dr=e=>e.value+(e.dataset.unit||"");let Wr=null;function Fr(e){const t=e._cssvar;if(!t||!("value"in e))return;const n=getComputedStyle(Ir(t.scope)).getPropertyValue(t.var).trim();if(!n)return;const r="color"===e.type?function(e){if(/^#[0-9a-f]{6}$/i.test(e))return e.toLowerCase();try{Wr=Wr||document.createElement("canvas");const t=Wr.getContext&&Wr.getContext("2d",{willReadFrequently:!0});if(!t)return null;const n=document.createElement("i");return n.style.color=e,n.style.color?(t.clearRect(0,0,1,1),t.fillStyle="#000",t.fillStyle=e,t.fillRect(0,0,1,1),"#"+[...t.getImageData(0,0,1,1).data.slice(0,3)].map(e=>e.toString(16).padStart(2,"0")).join("")):null}catch{return null}}(n):e.dataset.unit?String(parseFloat(n)):n;null!=r&&e.value!==r&&(e.value=r)}function Kr(e){const t=e._cssvar;if(!t||!t.var)return;const n=zr(t.scope,t.var);n in Hr||(Hr[n]=Ir(t.scope).style.getPropertyValue(t.var)),Fr(e),e._cvBound||(e._cvBound=!0,e.addEventListener("input",()=>Ir(t.scope).style.setProperty(t.var,Dr(e))),e.addEventListener("change",()=>{return function(e,t,n,r){if(!/^--[\w-]+$/.test(t||""))return void console.warn("[edit] x-edit.cssvar needs a custom property name (--name):",t);const o=function(e){const t=String(null==e?"":e);if(!t.trim())return"empty";if(/expression\s*\(/i.test(t))return"expression()";const n=[];for(let e=0;e<t.length;e++){const r=t[e];if('"'===r||"'"===r){let n=e+1;for(;n<t.length&&t[n]!==r;n++)if("\\"===t[n])n++;else if("\n"===t[n])return"unbalanced quotes";if(n>=t.length)return"unbalanced quotes";e=n;continue}if(/^url\(/i.test(t.slice(e,e+4))&&!/[\w-]/.test(t[e-1]||"")){let n=e+4,r=null,o="";for(;n<t.length;n++){const e=t[n];if(r){if("\\"===e){o+=t[++n]||"";continue}if(e===r){r=null;continue}o+=e}else if('"'!==e&&"'"!==e){if(")"===e)break;o+=e}else r=e}if(n>=t.length)return"unterminated url()";const i=o.replace(/[\u0000-\u0020\u007f]/g,"").toLowerCase();if(/^(javascript|vbscript):/.test(i))return"script URL";if(i.startsWith("data:")&&!i.startsWith("data:image/"))return"data URL";e=n;continue}if(";"===r||"{"===r||"}"===r)return`contains ${r}`;if(t.startsWith("/*",e)||t.startsWith("\x3c!--",e)||t.startsWith("</",e))return"contains a comment or markup";if("("===r||"["===r)n.push(r);else if((")"===r||"]"===r)&&n.pop()!==(")"===r?"(":"["))return"unbalanced brackets"}return n.length?"unbalanced brackets":null}(n);if(o)return void console.warn(`[edit] theme value refused (${o}):`,n);const i=zr(e,t);qr.add(i),Ir(e).style.setProperty(t,n);const s=Ur()[i];s&&s.value===n||Ke({kind:"theme",scope:e||null,var:t,value:n},!!r)}(t.scope,t.var,Dr(e),t.persist||!!(n=t.scope&&Y[t.scope])&&!!(n._editPersist||n._edit&&n._edit.persist));var n}))}function Ur(){const e={};for(let t=0;t<c;t++){const n=l[t];"theme"===n.kind&&(e[zr(n.scope,n.var)]=n)}return e}function Jr(){const e=Ur();new Set([...qr,...Object.keys(e)]).forEach(t=>{qr.add(t);const n=t.indexOf("|"),r=t.slice(0,n)||null,o=t.slice(n+1),i=Ir(r),s=e[t]?e[t].value:Hr[t];s?i.style.setProperty(o,s):i.style.removeProperty(o)}),Br.forEach(Fr)}function Xr(e){const t=e&&Y[e];if(!t||ee(t))return null;const n=ce(t),r=t.getAttribute("data-edit-key");if(n&&"static"===me(n)&&!se(n)&&r&&/^[@~]/.test(r))return"area";if(n&&n!==t)return null;const o=ie(e);return o&&o!==t?null:"own"}const Vr=new Map;function Yr(e){const t=de(e),n=!e._marked;e._marked=!0,e._baseClass=e._baseClass||{},e._baseStyle=e._baseStyle||{},e._baseText=e._baseText||{};const r=Object.create(null),o=e=>{for(const t of e.children){const e=b(t);r[e]=(r[e]||0)+1,o(t)}},i=(s,a)=>{if(((o,i)=>{let s=o.getAttribute("data-edit-key");if(!s){if(n){const e=b(o),n=r[e]=(r[e]||0)+1;s=y(t,n>1?e+"#"+n:e),Vr.set(s,i)}else s="!"+w();o.setAttribute("data-edit-key",s)}s in e._baseClass||(e._baseClass[s]=Tr(o)),s in e._baseStyle||(e._baseStyle[s]=j(o)),s in e._baseText||o.children.length||(e._baseText[s]=o.innerHTML.trim())})(s,a),s!==e&&(e=>$(e)||m(e)||[...e.attributes].some(e=>e.name.startsWith("x-rich-text")))(s))return;if(s._editRt||(n||s._editRtFormat)&&Le(s)&&ue(s,"text")&&!m(s))return void(n&&o(s));let l=0;for(const e of s.children){if(be(e)||e.closest("[data-edit-ghost]")||k(e))continue;const o=""===a?String(l):a+"."+l;if(e._manifestComponent){if(ve(e))continue;if(!e.hasAttribute("data-edit-host")){const i=e.getAttribute("data-edit-key"),s=y(t,"X-"+e._manifestComponent.toUpperCase()+":");let a=i&&(i===s||i.startsWith(s+"#"))?i:"!"+w();if(n&&"!"===a[0]){const n="X-"+e._manifestComponent.toUpperCase()+":",i=r[n]=(r[n]||0)+1;a=y(t,i>1?n+"#"+i:n),Vr.set(a,o)}e.setAttribute("data-edit-host",a)}l++}else i(e,o),l++}};i(e,"")}const Gr=new Set,Qr=new Set,Zr=new Map;function eo(e){const t=function(e){if("data"!==me(e))return null;const t=(he(e)||"").match(/\$x\.([\w$]+)/);if(!t)return"inline x-data list: mnfst-run writes data only to CSV/JSON/YAML sources declared in manifest.json";const n=window.ManifestComponentsRegistry&&window.ManifestComponentsRegistry.manifest;if(!n)return null;const r=(n.data||{})[t[1]];return null==r?`data source '${t[1]}' is not declared in manifest.json: mnfst-run writes data only to CSV/JSON/YAML files declared there`:"string"==typeof r?null:`data source '${t[1]}' is not a file (a cloud or remote source): save it with $x.${t[1]}.$update, not mnfst-run`}(e);t&&(Qr.add(de(e)),Zr.set(de(e),t),Gr.has(de(e))||(Gr.add(de(e)),console.warn(`[edit] x-edit="${de(e)}": ${t}; its edits stay on the page (and reach onPublish)`))),e._edit.rendered&&Qr.add(de(e)),e._edit.rendered&&!Gr.has(de(e))&&(Gr.add(de(e)),console.warn(`[edit] x-edit="${de(e)}" is inside content ${e._edit.rendered} renders: it edits on the page (and reaches onPublish), but mnfst-run cannot write it to a source file`)),dr(null);const n=me(e);"static"===n&&Yr(e),yn(e),[e,...e.querySelectorAll("[data-edit-area]")].forEach(e=>{var t,n;n="size",(t=e)._edit&&t._edit.caps.has(n)&&!Lt(t,n)&&Xn(e)}),"component"===n?wr(e):"static"===n&&function(e){br(e);const t=[...e.querySelectorAll("*")];ke(e).length&&!Le(e)||t.unshift(e),t.forEach(t=>{ke(t).length&&!Le(t)||!t.textContent.trim()||t.closest("template")||t.closest("[data-edit-handle], [x-edit\\.grab]")||t._manifestComponent&&t!==e||gr(t)||t.closest('[contenteditable="false"]:not([data-edit-piece-mode])')||!ue(t,"text")||m(t)||p.has(t.tagName)||/^[@~]/.test(t.getAttribute("data-edit-key")||"")&&(hr(t,n=>gt(ce(t)||e,t,"text",n??z(t))),lr(t,"html"))})}(e),"data"===n&&ue(e,"data")&&yr(e),e._editBound||(e._editBound=!0,e.addEventListener("pointerdown",On),e.addEventListener("keydown",t=>{io(e)&&Nn(t,e)}),e.addEventListener("dragstart",t=>{io(e)&&t.preventDefault()}),e.addEventListener("drop",t=>{io(e)&&t.preventDefault()})),e._editObserver||(e._editObserver=new MutationObserver(t=>{s||e._rearmQueued||t.every(e=>e.target.isContentEditable)||(e._rearmQueued=!0,queueMicrotask(()=>{e._rearmQueued=!1,e._armed&&io(e)&&!s&&eo(e)}))}),e._editObserver.observe(e,{childList:!0,subtree:!0}))}function to(e){[e,...e.querySelectorAll("[data-edit-area]")].forEach(e=>{e._editPos&&(e.style.removeProperty("position"),e._editPos=!1)}),e.querySelectorAll("[data-edit-handle]").forEach(e=>e.remove()),dr(e),[e,...e.querySelectorAll("[contenteditable]")].forEach(e=>{e.hasAttribute("contenteditable")&&e.removeAttribute("contenteditable"),e._pieceMode=!1,e.removeAttribute("data-edit-piece-mode")}),e.querySelectorAll("[data-edit-piece]").forEach(bn),[e,...e.querySelectorAll("[data-edit-area]")].forEach(e=>{e._sizeBound=!1}),hn&&e.contains(hn.item)&&Bn()}let no,ro=!1,oo=!1;const io=e=>!(!e||!e._edit||e._edit.gated&&(!no||!no.active)||se(e)),so=new Set;function ao(){const e=[];re().forEach(e=>{se(e)&&(so.has(de(e))||(so.add(de(e)),console.warn(`[edit] x-edit="${de(e)}" is on the page more than once (a component used several times); it is not editable here`)),e._armed&&(to(e),e._armed=!1))}),re().forEach(t=>{io(t)&&!t._armed&&(t._editBound||e.push(t),d[de(t)]=Ue(t,me(t)),eo(t),t._armed=!0)}),ro&&e.length&&(l.some(e=>/^st-/.test(e.kind))&&(pt(e),ht()),l.some(e=>"cmp-main"===e.kind||"cmp-inst"===e.kind)&&Ge()),Br.forEach(Kr),Ko(),ro=!0}function lo(e){const t=[],n=e=>e.edits||e.children||"~"===e.key[0],r=mt(ut()),o=new Set(Object.values(Ur()).filter(e=>e.scope&&"area"===Xr(e.scope)).map(e=>Y[e.scope]));ut().forEach(r=>{const i=de(r),s=ae(r),a=new Proxy({},{get:(e,t)=>{const n=v(String(t)),r=ie(decodeURIComponent(n.slice(1,n.indexOf("@",1)))),o=po&&r&&po[le(r)];return o?o[n]:void 0}}),l=(t,r)=>{const s=!r&&t.getAttribute("data-edit-host");if(s){if("!"===s[0])return null;const e={key:s},t=Vr.get(s);return null!=t&&(e.at=t),a&&a[s]&&(e.fp=a[s]),e}if(!r&&t._manifestComponent)return null;const c=t.getAttribute("data-edit-key");if(!c||"!"===c[0])return null;const d={key:c},u=Vr.get(v(c));null!=u&&(d.at=u),a&&a[v(c)]&&(d.fp=a[v(c)]);const f=(t=>{const n=e.node[t];if(!n)return null;const r={};return Object.entries(n).forEach(([e,t])=>{r[e]="class"!==e&&"style"!==e||""!==t?t:null}),Object.keys(r).length?r:null})(c);if(f&&(d.edits=f),o.has(t)&&(d.edits=Object.assign({},d.edits,{style:j(t)||null})),!(f&&"text"in f||m(t)||"TEMPLATE"===t.tagName||t.hasAttribute("data-rich-text"))){const o=(e=>ke(e).filter(e=>!k(e)))(t).map(e=>l(e)).filter(Boolean),s=e.touched.has(r?"#"+i:c);if("~"===c[0]||s){d.children=o;const t=s&&"~"!==c[0]&&(t=>{const n=""===t?(e.orderBase[i]||{})[""]:Object.values(e.orderBase).map(e=>e[t]).find(Boolean);return n?n.filter(e=>"@"===e[0]).map(e=>{const t={key:e},n=Vr.get(e);return null!=n&&(t.at=n),a&&a[e]&&(t.fp=a[e]),t}):null})(r?"":c);t&&(d.base=t)}else o.some(n)&&(d.children=o.filter(n),d.path=!0)}return d},c=l(r,!0);c&&(c.edits||c.children)&&(delete c.at,delete c.fp,t.push(s?{kind:"static-tree",region:i,component:s,tree:c}:{kind:"static-tree",region:i,tree:c}))});const i=new Set;new Set([...Object.keys(e.orderBase),...Object.keys(e.order)]).forEach(t=>{Object.values(Object.assign({},e.orderBase[t]||{},e.order[t]||{})).forEach(e=>e.forEach(e=>i.add(e)))});const s=new Set;for(let e=0;e<c;e++){const t=l[e];"st-children"===t.kind&&t.before.forEach(e=>{!e||"@"!==e[0]||i.has(e)||r.has(e)||s.add(e)})}return s.forEach(e=>{const n=(e=>decodeURIComponent(e.slice(1,e.indexOf("@",1))))(e);let r=t.find(e=>e.region===n);if(!r){const e=ie(n);if(!e||se(e))return;const o=ae(e);r=o?{kind:"static-tree",region:n,component:o,tree:{key:""}}:{kind:"static-tree",region:n,tree:{key:""}},t.push(r)}(r.removed=r.removed||[]).push(e)}),t}function co(){const e=Object.entries(Bt()).map(([e,t])=>{return n=e,r=t.kind,o=t.snap,{region:n,kind:r,op:"reorderData",source:o.source,order:o.order};var n,r,o});lo(Ze()).forEach(t=>e.push(t));const t=e=>{const t=[];return Object.entries(e).forEach(([e,n])=>Object.entries(n).forEach(([n,r])=>t.push({path:e,key:e,prop:n,value:r}))),t},n=bt(),r={};l.slice(0,c).forEach(e=>{"data-val"===e.kind&&(r[e.source]=e.region)}),Object.entries(n).forEach(([t,n])=>Object.entries(n).forEach(([n,o])=>Object.entries(o).forEach(([o,i])=>e.push({kind:"data-val",region:r[t],source:t,id:n,field:o,value:i}))));const{main:o,inst:i,reverts:s}=Ve();return Object.entries(o).forEach(([n,r])=>{const o=t(r);o.length&&e.push({kind:"component",scope:"main",component:n,edits:o})}),new Set([...Object.keys(i),...Object.keys(s)]).forEach(n=>{const r=ie(n);if(!r)return;const o=t(i[n]||{}),a=[...s[n]||[]];(o.length||a.length)&&e.push({kind:"component",scope:"instance",component:vr(r),region:n,edits:o,reverts:a})}),function(){const e=Object.values(Ur()),t=[];return e.filter(e=>!Xr(e.scope)).forEach(e=>t.push({kind:"theme",scope:e.scope||null,var:e.var,value:e.value,file:null})),new Set(e.filter(e=>e.scope&&"own"===Xr(e.scope)).map(e=>e.scope)).forEach(e=>{const n=Y[e],r=(e=>{for(let t=e;t;t=t.parentElement)if(t._manifestComponent)return t._manifestComponent;return null})(n),o={key:"",edits:{style:j(n)||null}};t.push(r?{kind:"static-tree",region:e,component:r,tree:o}:{kind:"static-tree",region:e,tree:o})}),t}().forEach(t=>e.push(t)),e}function uo(e){const t=t=>"theme"===t.kind?!!e&&(e.has("theme|"+(t.scope||"")+"|"+t.var)||e.has(t.scope)):("st-move"===t.kind?[t.from,t.to]:[t.region]).some(t=>!(t=>null==t||!!ie(t)&&!(e&&e.has(t)))(t)),n=[],r=St();mt(ut().filter(t=>!(e&&e.has(de(t))))).forEach((e,t)=>{const o=r.get(t);o&&o.size&&n.push([e,new Map(o),t===e.getAttribute("data-edit-host")])});const i=l.slice(0,c).filter(e=>"lock"===e.kind&&!/^[~@]/.test(e.key)&&!t(e));let s=0;l=l.filter((e,n)=>{const r=t(e);return r&&n<c&&s++,r}),c=s,We++,T();const a=e?[...Vr].filter(([t])=>e.has(decodeURIComponent(t.slice(1,t.indexOf("@",1))))):[];Vr.clear(),a.forEach(([e,t])=>Vr.set(e,t)),re().forEach(t=>{if(e&&e.has(de(t)))return;const n=me(t);t._baseText={},t._baseClass={},t._baseStyle={},"static"===n&&([t,...t.querySelectorAll("[data-edit-key]")].forEach(e=>{ce(e)===t&&e.removeAttribute("data-edit-key")}),t.querySelectorAll("[data-edit-host]").forEach(e=>{ce(e.parentElement)===t&&e.removeAttribute("data-edit-host")}),t._marked=!1,Yr(t)),"component"===n&&t._armed&&wr(t),d[de(t)]=Ue(t,n)}),function(e){Object.keys(Hr).forEach(t=>{if(e&&e.has("theme|"+t))return;const n=t.indexOf("|");Hr[t]=Ir(t.slice(0,n)||null).style.getPropertyValue(t.slice(n+1))}),[...qr].forEach(t=>{e&&e.has("theme|"+t)||qr.delete(t)})}(e),(()=>{const e=e=>{l.splice(c,0,e),c++,fe(e.region)&&u.add(e)};i.forEach(e),n.forEach(([t,n,r])=>{const i=r?Ft(t):ce(t),s=t.getAttribute(r?"data-edit-host":"data-edit-key");i&&s&&[!0,!1].forEach(t=>{const r=[...n].filter(([,e])=>e===t).map(([e])=>e);r.length&&e({kind:"lock",region:de(i),key:s,actions:r.length===o.length?[]:r,value:t})})}),We++})(),T(),Ko()}const fo=e=>!(e&&Array.isArray(e.results)&&e.results.some(e=>e&&"error"===e.status));let mo=null,po=null,ho=null,go=null;const bo=new Set,yo=e=>{const t=v(e);if("string"!=typeof t||"@"!==t[0])return null;const n=ie(decodeURIComponent(t.slice(1,t.indexOf("@",1)))),r=ho&&n&&ho[le(n)];return r&&r[t]||null};function vo(e){if(!/^https?:$/.test(location.protocol)||"function"!=typeof fetch)return Promise.resolve(null);const t=fetch("/__edit/base",{cache:"no-store"}).then(e=>e.ok?e.json():null).then(t=>(t&&t.files&&(mo=t.files),t&&t.ids&&!e&&(po=t.ids,ho=t.cids||null),mo)).catch(()=>null);return e||(go=t),t}let Eo=!1;window.addEventListener("manifest:source-change",e=>{const t=e.detail||{},n=/\.html?$/i.test(t.file||"");n&&!po&&(Eo=!0),mo&&t.file&&t.hash&&!n&&(mo[t.file]=t.hash)});let wo=null,ko=0,Ao=[],_o=!1,xo=null;const So=e=>!_o&&!!wo&&Date.now()<wo.until&&e.length>0&&e.every(e=>e&&wo.files[e.rel]&&wo.files[e.rel]===e.hash);function To(e){const t=document.activeElement;if(!t||!t._commitText||void 0===t._preEdit||!t.isContentEditable||Uo(t)===t._preEdit)return!0;const n=ce(t);return!(!n||!e&&!n._edit.persist||(t._commitText(),ur(t),t._preEdit=Uo(t),0))}function Co(e){const t=new Map;for(let n=!0;n;)n=!1,l.slice(0,c).forEach(r=>{if("st-move"!==r.kind||e.has(r.from)===e.has(r.to))return;const[o,i]=e.has(r.from)?[r.from,r.to]:[r.to,r.from];e.add(i),t.set(i,t.get(o)||o),n=!0});return e.via=t,e}const Oo=e=>{if("string"!=typeof e)return null;const t=v(e);return"@"===t[0]?t.slice(1,t.indexOf("@",1)):null},Lo=e=>Qr.has(e.region)||Qr.has(e.from)||Qr.has(e.to)||Qr.has(Oo(e.path))||Qr.has(Oo(e.key)),Mo=e=>[...new Set(e.flatMap(e=>[e.region,e.from,e.to]).filter(Boolean))],jo=()=>l.slice(0,c).filter(e=>"lock"!==e.kind&&!u.has(e));function Po(){const e=document.activeElement,t=e&&e._commitText&&ce(e);return t?de(t):null}function Ro(){return!(!To(!1)&&!Qr.has(Po()))&&jo().every(Lo)}function $o(){const e=Po(),t=Mo(jo().filter(Lo));e&&Qr.has(e)&&!To(!1)&&!t.includes(e)&&t.push(e),t.length&&console.warn(`[edit] the source changed: reloading discards the unpublished edits of ${t.map(e=>`x-edit="${e}"`).join(", ")} that mnfst-run can't write (generated content, or a piece moved from it); .persist keeps them`)}function No(){$o(),location.reload()}function Bo(){xo&&Ro()&&(xo=null,No())}function Ho(e){if(Ro())return No();xo=e;const t=e.map(e=>e&&e.rel).filter(Boolean);no&&(no.stale=[...new Set([...no.stale||[],...t])]);const n=Mo(jo().filter(e=>!Lo(e))).filter(e=>!Qr.has(e)),r=Po();!r||Qr.has(r)||n.includes(r)||To(!1)||n.push(r);const o=Co(new Set(Qr)),i=n.filter(e=>o.has(e)),s=e=>e.map(e=>`x-edit="${e}"`).join(", ");console.warn(`[edit] the source changed, but a reload would lose unpublished edits${n.length?" to "+s(n):""}: publish (with rebase), then reload`+(i.length?`. ${s(i)} ${i.length>1?"are":"is"} tied by a move to ${s([...new Set(i.map(e=>o.via.get(e)))])}, which mnfst-run can't write: undo that move to publish ${i.length>1?"them":"it"}, or publish the rest`:"")),document.dispatchEvent(new CustomEvent("edit:stale",{detail:{files:t}}))}function qo(e,t){if(ko=Math.max(0,ko-1),e&&e.base&&(wo={files:Object.assign({},e.base),until:Date.now()+3e3}),e&&Array.isArray(e.stale)&&e.stale.length&&(_o=!0),t&&fo(e)&&e.base&&(_o=!0,setTimeout(()=>{_o&&Ho(Object.keys(e.base).map(e=>({rel:e})))},1500)),ko)return;const n=Ao;Ao=[],n.some(e=>!So(e))&&Ho(n.flat())}window.addEventListener("manifest:live-reload",e=>{const t=e.detail&&e.detail.files||[];if(ko)return e.preventDefault(),void Ao.push(t);So(t)?e.preventDefault():Ro()?$o():(e.preventDefault(),Ho(t))});let zo=Promise.resolve();function Io(e){const t=zo.then(()=>function(e){const t=(e,t,n)=>{e&&e.base&&mo&&Object.entries(e.base).forEach(([e,t])=>{Do&&/\.html?$/i.test(e)||(mo[e]=t)}),e&&e.ids&&po&&(Do?Object.entries(e.ids).forEach(([e,t])=>{po[e]=Object.assign({},po[e]),Object.entries(t||{}).forEach(([t,n])=>{String(n).includes(".")||(po[e][t]=n)})}):po=e.ids,Do||(ho=e.cids||null,bo.clear()));const r=Do&&e&&e.cids&&ho?e.cids:null,o=r?function(){const e=l.slice(0,c),t=mt(ut()),n=new Map,r=new Set(e.filter(e=>"st-node"===e.kind).map(e=>e.path)),o=new Set;e.forEach(e=>{"st-children"!==e.kind&&"st-order"!==e.kind||o.add(e.parent),"st-move"===e.kind&&(o.add(e.fromParent),o.add(e.toParent))});const i=e=>!!e&&([e,...e.querySelectorAll("[data-edit-key]")].some(e=>r.has(e.getAttribute("data-edit-key")))||[...o].some(n=>{if(!n)return!1;const r=t.get(n);return!!r&&(r===e||e.contains(r))}));return t.forEach((e,o)=>{if("!"===o[0]||i(e))return n.set(e,null);if("~"===o[0]){const s=v(o);if(r.has(s)||[...r].some(e=>{const n=t.get(e),r=t.get(s);return n&&r&&r.contains(n)})||i(t.get(s)))return n.set(e,null)}n.set(e,yo(v(o)))}),n}():null,i=e&&Array.isArray(e.stale)?e.stale:[];return no&&(no.stale=i),i.length&&document.dispatchEvent(new CustomEvent("edit:stale",{detail:{files:i}})),fo(t?{results:e.results.filter(e=>!(e&&(t.has(e.region)||n&&n.has(e))))}:e)&&(uo(t),r&&function(e,t){const n=mt(ut());Object.entries(e).forEach(([e,r])=>{if(!/\.html?$/i.test(e))return;r=r||{};const o={};new Set(Object.keys(r).map(ot)).forEach(i=>{const s=Object.keys(r).filter(e=>ot(e)===i).sort(st),a=[...n.keys()].filter(t=>ot(t)===i&&(()=>{const r=ce(n.get(t));return r&&le(r)===e})()).sort(st).map(e=>t.has(n.get(e))?t.get(n.get(e)):null),l=s.map(e=>r[e]);!a.includes(null)&&a.some((e,t)=>(at(a,l,t)||[]).length)?bo.add(i):s.forEach(e=>{o[e]=r[e]})}),ho[e]=o})}(r,o)),Bo(),e},n=(e,t)=>{if(!e||!Array.isArray(e.results)||Array.isArray(e.stale)&&e.stale.length)return null;const n=new Set(e.results.filter(e=>e&&null!=e.failed).map(e=>e.failed)),r=new Set(t.filter((t,n)=>e.results[n]&&"error"===e.results[n].status&&null==e.results[n].failed&&"static-tree"!==t.kind));if(!n.size&&!r.size||e.results.some((e,o)=>e&&"error"===e.status&&!n.has(t[o]&&t[o].region)&&!r.has(t[o])))return null;Co(n);const o=e=>r.has(e)||null!=e.region&&n.has(e.region);return t.some(e=>!o(e))?Object.assign(n,{own:r,out:o}):null},r=e=>"theme"===e.kind?"theme|"+(e.scope||"")+"|"+e.var:e.region,o=e=>{const t=ie(e);return t&&t._edit.rendered},i=e=>null!=e.region&&"theme"!==e.kind&&Qr.has(e.region),s=()=>{To(!0);const s=co();if(no&&"function"==typeof no.onPublish)return Promise.resolve(no.onPublish(s,{log:l,cursor:c})).then(t);if(!s.length)return Bo(),Promise.resolve({results:[]});const a=e=>(ko++,fetch("/__edit/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({patches:e,base:mo})}).then(e=>e.json()).catch(e=>{throw qo(null),e})),d=Co(new Set(s.filter(i).map(e=>e.region))),u=e=>({region:e.region,status:"error",reason:Zr.has(e.region)&&i(e)?`x-edit="${e.region}": ${Zr.get(e.region)}`:o(e.region)&&i(e)?`x-edit="${e.region}" is inside content ${o(e.region)} renders, so mnfst-run can't write it to a source file`:`not published: tied by a move to x-edit="${d.via.get(e.region)}", which mnfst-run can't write`}),f=s.filter(e=>!d.has(e.region)),m=(n,o,i)=>{const a=new Set([...d,...o||[],...o?i.filter(o.out).map(r):[]]),l=new Set,c=s.map(e=>{if(d.has(e.region)){const t=u(e);return l.add(t),t}const t=n.results[i.indexOf(e)];return o&&o.out(e)&&l.add(t),t}),f=t(Object.assign({},n,{results:c}),a.size?a:void 0,l);return qo(n,!(!e||!e.rebase)),f};if(!f.length){const e=t({results:s.map(u)},d);return Promise.resolve(e)}return a(f).then(e=>{const t=n(e,f);if(!t)return m(e,null,f);qo(e,!1);const r=f.filter(e=>!t.out(e));return a(r).then(n=>{const o=f.map((o,i)=>t.out(o)?e.results[i]&&"error"===e.results[i].status?e.results[i]:{region:o.region,status:"error",reason:`not published: tied by a move to x-edit="${t.via.get(o.region)||[...t].find(e=>!t.via.has(e))}", which failed`}:n.results[r.indexOf(o)]);return m(Object.assign({},n,{results:o}),t,f)})})},a=e=>{const n=co();return n.length?t({results:n.map(t=>({region:t.region,status:"error",reason:e}))}):{results:[]}},d=no&&"function"==typeof no.onPublish||mo&&po?Promise.resolve(null):Eo?Promise.resolve("the source changed before this page could read its base from the dev server; reload to continue"):vo().then(()=>mo&&po?null:"the dev server's base (/__edit/base) could not be read, so nothing can be checked against the source; nothing was published"),u=()=>{const e=Object.assign({},mo);return vo(!0).then(()=>(Object.keys(mo||{}).some(t=>/\.html?$/i.test(t)&&e[t]!==mo[t])&&(Do=!0),s()))};return d.then(t=>t?a(t):e&&e.rebase?u():s())}(e));return zo=t.catch(()=>{}),t}let Do=!1;function Wo(){no&&(no.active=!0),ao()}function Fo(){no&&(no.active=!1),re().forEach(e=>{e._edit.gated&&e._armed&&(to(e),e._armed=!1)}),Ko()}function Ko(){no&&(no.canUndo=c>0,no.canRedo=c<l.length,no.version=(no.version||0)+1,xo&&setTimeout(Bo,0))}const Uo=e=>e._editField&&!e._editRich?e.textContent:I(e,e.innerHTML.trim()),Jo=e=>!!e.closest('[data-edit-hotkeys="off"]');function Xo(){const e=document.activeElement;if(!e||void 0===e._preEdit||!e.isContentEditable)return;const t=()=>{document.activeElement===e&&(ur(e),e._preEdit=Uo(e))};t(),setTimeout(t,0)}function Vo(e){if(e.altKey||!e.metaKey&&!e.ctrlKey)return null;const t=(e.key||"").toLowerCase();return"z"===t?e.shiftKey?"redo":"undo":"y"!==t||!e.ctrlKey||e.metaKey||e.shiftKey?null:"redo"}function Yo(e){if(e.defaultPrevented||s)return;const t=Vo(e);if(!t)return;const n="redo"===t,r=e.target&&1===e.target.nodeType?e.target:document.body;if(/^(INPUT|TEXTAREA|SELECT)$/.test(r.tagName)||$(r.closest("[data-rich-text]")))return;const o=r.closest("[data-edit-area]");if(o){const e=ce(o);if(!e||!io(e)||Jo(o))return}else{if(r.isContentEditable)return;if(!re().some(e=>io(e)&&!Jo(e)))return}r.isContentEditable&&void 0!==r._preEdit&&Uo(r)!==r._preEdit||(n?c>=l.length:0===c)||(e.preventDefault(),n?Nt():$t())}function Go(){if(l.length){if(!ho&&go&&l.some(e=>e.ids||e.id)){const e=go;return go=null,void Promise.race([e,new Promise(e=>setTimeout(e,4e3))]).then(Go,Go)}!function(){const e=e=>("st-move"===e.kind?[e.from,e.to]:null!=e.region?[e.region]:[]).some(e=>{const t=ie(e);return t&&!t._edit.persist});if(!l.some(e))return;let t=0;const n=l.filter((n,r)=>{const o=!e(n);return o&&r<c&&t++,o});l=n,c=t,We++,T()}();for(const[e,t]of Object.entries(Bt())){const n=ie(e);n&&"data"===t.kind&&Qo(n,()=>Je(n,"data",t.snap))}if(l.some(e=>/^st-/.test(e.kind))&&(pt(re()),ht()),l.some(e=>"cmp-main"===e.kind||"cmp-inst"===e.kind)&&Ge(),l.some(e=>"data-val"===e.kind)){const e=re().find(e=>"data"===me(e));e&&Qo(e,yt)}l.some(e=>"theme"===e.kind)&&Jr(),l.some(e=>"lock"===e.kind)&&re().forEach(jt),Ko()}}function Qo(e,t){const n=he(e),r=h(e);let o=0;const i=setInterval(()=>{let e=!1;try{e=Array.isArray(window.Alpine.evaluate(r,n))}catch{}e?(clearInterval(i),t()):++o>100&&clearInterval(i)},50)}let Zo=!1;function ei(){if(Zo||!window.Alpine||!Alpine.directive)return;Zo=!0,document.body&&!document.body.hasAttribute("x-data")&&document.body.setAttribute("x-data","{}"),Alpine.directive("edit",(e,{modifiers:t,expression:n},{cleanup:r})=>{te(e,t,n),ro&&!oo&&(oo=!0,queueMicrotask(()=>{oo=!1,ao()})),r(()=>function(e){Object.keys(Y).forEach(t=>{Y[t]===e&&delete Y[t]}),Br.delete(e),V.has(e)&&(e._armed&&(to(e),e._armed=!1),e._editObserver&&(e._editObserver.disconnect(),e._editObserver=null),V.delete(e),delete e._edit,oe(),e.removeAttribute("data-edit-area"),qt&&(qt===e||e.contains(qt))&&It(null),Ko())}(e))}),Alpine.store("edit",{active:!1,canUndo:!1,canRedo:!1,version:0,stale:[],conflicts:[],onPublish:null,toggle(){this.active?Fo():Wo()},on(){Wo()},off(){Fo()},undo:()=>$t(),redo:()=>Nt(),publish:e=>Io(e),patches:()=>co(),export:()=>JSON.parse(JSON.stringify({log:l,cursor:c})),get target(){return this.version,qt},set target(e){(e=>{It(e&&1===e.nodeType?Wt(e)||e:null)})(e)},can(e,t){return this.version,tn(e,void 0===t?qt:t)},lock:(e,t)=>Mt(void 0===e?qt:e,t,!0),unlock:(e,t)=>Mt(void 0===e?qt:e,t,!1),copy:e=>nn(e),cut:e=>ln(e),paste:e=>cn(e),duplicate:e=>sn(e),remove:e=>an(e),move:(e,t,n)=>function(e,t,n){const r=Wt(null==e?qt:e);if(!r||!Ut(r))return!1;const o=Ft(r),i="string"==typeof t?ie(t):t;if(!i||1!==i.nodeType||i===r||r.contains(i))return!1;const s=ce(i);if(!(o&&s&&io(o)&&io(s)&&Jt(i)))return!1;n&&n.parentElement!==i&&(n=null);const a=r.parentElement;if(!Be(r,i))return!1;if("data"===me(o))return i===a&&($e(r,e=>i.insertBefore(e,n?Re(n):null)),jn(o,i),!0);if("static"!==me(o)||"static"!==me(s))return!1;if(o!==s&&Kt(r)&&!Ee(r))return!1;const l=A(a),c=A(i);return $e(r,e=>i.insertBefore(e,n?Re(n):null)),i===a?Et(o,i,l):(wt(o,s,r,a,l,c),!0)}(e,t,n),nest(e){const t=Wt(void 0===e?qt:e);return!!t&&Ut(t)&&qn(t)},unnest(e){const t=Wt(void 0===e?qt:e);return!!t&&Ut(t)&&zn(t)},block:e=>Dt(e),attr:(e,t,n)=>Lr(e,t,n),classes:Pr,scope(e,t){return this.version,e&&1===e.nodeType?$r(e):null==e?$r(t):function(e,t){const n=Rr(null==t?qt:t);return!(!n||"instance"!==e&&"main"!==e||(n._editScope=e,zt(),0))}(e,t)},revert:e=>Nr(e),clearConflicts(){_=[],this.conflicts=[],T()}}),no=Alpine.store("edit");const n=()=>Alpine.store("edit");Alpine.magic("edit",n),window.__manifestEditMagic=n;const r=window.__manifestEditStubWrites;r&&Object.keys(r).forEach(e=>{try{no[e]=r[e]}catch{}delete r[e]}),window.__manifestEditStub&&setTimeout(()=>{window.__manifestEditStub.v++},0),(()=>{try{t=location.pathname;const n=JSON.parse(localStorage.getItem(e(t)));n&&8===n.v?(l=n.log||[],c=n.cursor??l.length,l.forEach(e=>u.add(e)),_=Array.isArray(n.conflicts)?n.conflicts:[],_.forEach(e=>x.add(e)),no&&(no.conflicts=_.slice())):n&&localStorage.removeItem(e(t))}catch{}})(),window.__mnfstEdit&&vo(),setTimeout(()=>{const e=()=>{ao(),Go()};if(!ho&&go&&l.some(e=>e.ids||e.id)){const t=go;go=null,Promise.race([t,new Promise(e=>setTimeout(e,4e3))]).then(e,e)}else e()},450),document.addEventListener("keydown",Yo),window.addEventListener("click",ir,!0),window.addEventListener("auxclick",ir,!0),document.addEventListener("contextmenu",un,!0),document.addEventListener("dropdown:context",un,!0),window.addEventListener("manifest:route-change",()=>{t!==location.pathname&&(t=location.pathname,T())}),function(){if(!window.__manifestAlpineStarted&&![...document.querySelectorAll("[x-data]")].some(e=>e._x_marker))return;const e=e=>/^x-edit(\.|$)/.test(e),t=[...document.querySelectorAll("*")].filter(t=>!t._edit&&[...t.attributes].some(t=>e(t.name)));t.forEach(t=>{t._x_marker&&[...t.attributes].filter(t=>e(t.name)).forEach(e=>t.setAttribute(e.name,e.value))}),t.some(e=>!e._x_marker)&&Alpine.initTree(document.body)}()}document.addEventListener("alpine:init",ei),window.Alpine&&Alpine.directive&&setTimeout(ei,0)}();
|
|
2
2
|
//# sourceMappingURL=manifest.edit.min.js.map
|