payload-live-preview 2.0.4 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.js CHANGED
@@ -1,2 +1,2 @@
1
- function detectInitialLocale(){return function(){if("undefined"==typeof document)return;const e=document.documentElement.getAttribute("lang");return null===e||0===e.length?void 0:e}()??function(){if("undefined"==typeof navigator)return;const e=navigator.language;return"string"==typeof e&&e.length>0?e:void 0}()??"en"}var e="payload-live-preview-a11y",t=/* @__PURE__ */new WeakMap;function n(e){null!==e.timer&&(clearTimeout(e.timer),e.timer=null),e.messageNode?.remove(),e.messageNode=null}var r=class{german;document;lease=null;constructor(e,t){const n=t??("undefined"==typeof document?null:document),r=n?.documentElement.getAttribute("lang")??"";this.german=function(e){return/^de(?:[-_]|$)/i.test(e)}(e??(r.length>0?r:detectInitialLocale())),this.document=n}mount(){const r=this.document;if(null==r?.body)return null;this.lease??=function(e){let n=t.get(e);return void 0===n&&(n={element:null,owned:!1,messageNode:null,refs:0,timer:null},t.set(e,n)),n.refs+=1,n}(r);const i=this.lease,o=i.element;if(o?.isConnected&&o.ownerDocument===r)return o;if(null!==o){const e=i.owned;n(i),e&&o.remove()}let s=r.getElementById(e);return i.owned=null===s,null===s&&(s=r.createElement("div"),s.id=e,s.setAttribute("role","status"),s.setAttribute("aria-live","polite"),s.setAttribute("aria-atomic","true"),s.setAttribute("style","position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);clip-path:inset(50%);white-space:nowrap;border:0"),r.body.appendChild(s)),i.element=s,s}announceConnected(){this.say(this.german?"Vorschau verbunden":"Live preview connected")}announceDisconnected(){this.say(this.german?"Vorschau getrennt":"Live preview disconnected")}announceUpdate(e){e<=0||this.say(this.german?`${String(e)} ${1===e?"Änderung":"Änderungen"} angewendet`:`${String(e)} ${1===e?"change":"changes"} applied`)}detach(){const e=this.lease,r=this.document;if(null===e||null===r)return;if(this.lease=null,e.refs-=1,e.refs>0)return;const i=e.element;null!==i&&n(e),e.owned&&i?.remove(),e.element=null,t.delete(r)}say(e){const t=this.mount(),r=this.lease;if(null===t||null===r)return;let i=r.messageNode;i?.parentNode!==t?(i?.remove(),i=t.ownerDocument.createTextNode(t.hasChildNodes()?` ${e}`:e),r.messageNode=i,t.appendChild(i)):i.data=null===i.previousSibling?e:` ${e}`,null!==r.timer&&clearTimeout(r.timer);const o=setTimeout(()=>{r.timer===o&&r.element===t&&n(r)},1500);r.timer=o}};function i(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){const e=o(n);e&&t.push(e)}return t}function o(e){if("object"!=typeof e||null===e)return;const t=e,n=t.name,r=t.type;if("string"!=typeof n||0===n.length)return;if("string"!=typeof r||0===r.length)return;const o=i(t.fields),s=function(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){if("object"!=typeof n||null===n)continue;const e=n,r=e.slug;if("string"!=typeof r||0===r.length)continue;const o=i(e.fields);t.push({...e,slug:r,fields:o})}return t}(t.blocks),a={...t,name:n,type:r};return o.length>0?a.fields=o:delete a.fields,s.length>0?a.blocks=s:delete a.blocks,a}function s(e,t){return void 0===e||t(e)}function a(e,t){return null==e||t(e)}function l(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||null===Object.getPrototypeOf(t)}var u=["data","fieldSchemaJSON","globalSlug","collectionSlug","locale","ready","previewToken","protocolVersion"],c={basic:{since:1},"schema-json":{since:2,observed:"schema"},locale:{since:2,observed:"locale"},"preview-token":{since:3,observed:"preview-token"},"nested-arrays":{since:4},"recursive-diffs":{since:4},"document-events":{since:4,observed:"document-event"},"relationship-events":{since:4,observed:"relationship-event"}},d=Object.keys(c);function negotiateProtocol(e,t=[]){const n="number"==typeof e&&Number.isFinite(e)&&e>=1?Math.floor(e):void 0,r=n??1,i=Math.min(4,r),o=new Set(t),s=/* @__PURE__ */new Set;for(const e of d)(i>=c[e].since||o.has(e))&&s.add(e);return{ours:4,...void 0!==n?{theirs:n}:{theirs:void 0},negotiated:i,capabilities:s,observed:o}}function h(e){return("object"==typeof e&&null!==e||"function"==typeof e)&&"function"==typeof e.then&&(Promise.resolve(e).catch(()=>{}),!0)}function f(e,t){return e.generation===t.generation&&e.revision===t.revision}var p=class{matcher;handlers;boundListener=void 0;attachedTarget=void 0;generation=0;revision=0;queueHead=void 0;queueTail=void 0;constructor(e,t){this.matcher=e,this.handlers=t}attach(e=window){if(void 0!==this.attachedTarget)return;let t=!1;const n=r=>{if(!t||this.boundListener!==n)return;const i=this.generation;try{this.receive(r,i,e)}catch{let e;try{e=r.origin}catch{e=""}this.reportInvalid("shape",e,i)}};this.generation+=1,this.resetQueue(),this.attachedTarget=e,this.boundListener=n;try{e.addEventListener("message",n)}catch(t){this.boundListener===n&&(this.attachedTarget=void 0,this.boundListener=void 0,this.resetQueue());try{e.removeEventListener("message",n)}catch{}throw t}if(this.boundListener===n)t=!0;else try{e.removeEventListener("message",n)}catch{}}detach(){const e=this.attachedTarget,t=this.boundListener;void 0!==e&&void 0!==t&&(this.attachedTarget=void 0,this.boundListener=void 0,this.resetQueue(),e.removeEventListener("message",t))}advanceGeneration(){return void 0!==this.attachedTarget&&(this.generation+=1,this.resetQueue(),!0)}static sendReady(e,t){const n={type:"payload-live-preview",ready:!0,protocolVersion:4};for(const r of e)for(const e of t)try{r.postMessage(n,e)}catch{}}receive(e,t,n){const r=e.origin;if(!this.matchesOrigin(r,t))return void this.reportInvalid("origin",r,t);if(!this.matchesSource(e,n))return void this.reportInvalid("source",r,t);const o=e.data;var c;if("object"==typeof(c=o)&&null!==c&&"type"in c&&"string"==typeof c.type)switch(o.type){case"payload-live-preview":return function(e){const t=e;return!(void 0!==t.data&&null!==t.data&&!l(t.data))&&a(t.fieldSchemaJSON,e=>Array.isArray(e))&&a(t.globalSlug,e=>"string"==typeof e)&&a(t.collectionSlug,e=>"string"==typeof e)&&a(t.locale,e=>"string"==typeof e)&&a(t.ready,e=>"boolean"==typeof e)&&a(t.previewToken,e=>"string"==typeof e)&&a(t.protocolVersion,e=>"number"==typeof e)}(o)?void this.dispatchUpdate(function(e){const t={...e};for(const e of u)null===Reflect.get(t,e)&&Reflect.deleteProperty(t,e);if(!Array.isArray(t.fieldSchemaJSON))return t;let n;try{n=i(t.fieldSchemaJSON)}catch{n=[]}return{...t,fieldSchemaJSON:n}}(o),r,t):void this.reportInvalid("shape",r,t);case"payload-document-event":return function(e){const t=e;return s(t.action,e=>"updated"===e||"created"===e||"deleted"===e)&&s(t.slug,e=>"string"==typeof e)&&s(t.id,e=>"string"==typeof e||Number.isFinite(e))}(o)?void this.invokeHandler(t,this.handlers.onDocumentEvent,o,r):void this.reportInvalid("shape",r,t);case"payload-live-preview-focus":{const e=function(e){const t=e.field;return"string"==typeof t&&t.length>0?t:void 0}(o);return void 0===e?void this.reportInvalid("shape",r,t):void this.invokeHandler(t,this.handlers.onFocusField,e,r)}default:this.reportInvalid("type",r,t)}else this.reportInvalid("shape",r,t)}dispatchUpdate(e,t,n){const r=l(e.data);if(!this.isCurrentGeneration(n))return;const i=r?{generation:n,revision:this.revision+=1}:void 0,o=this.handlers.validateToken;if(!this.isCurrentGeneration(n))return;if(void 0===o)return void this.commitUpdate(e,t,n,i);if(!0===e.ready&&void 0===e.data)return void this.commitUpdate(e,t,n,void 0);const s={generation:n,message:e,origin:t,messageRevision:i,verdict:void 0,next:void 0};let a;this.enqueue(s);try{a=o(e.previewToken,t)}catch{return void this.settleValidation(s,!1)}"boolean"!=typeof a?Promise.resolve(a).then(e=>{this.settleValidation(s,!0===e)},()=>{this.settleValidation(s,!1)}):this.settleValidation(s,a)}settleValidation(e,t){e.verdict=t,this.drainQueue(e.generation)}drainQueue(e){for(;this.isCurrentGeneration(e);){const t=this.queueHead;if(void 0===t)return;if(this.matchesOrigin(t.origin,e)){if(void 0===t.verdict)return;this.dequeue(t)&&(t.verdict?this.commitUpdate(t.message,t.origin,t.generation,t.messageRevision):this.reportInvalid("token",t.origin,t.generation))}else{if(!this.dequeue(t))continue;this.reportInvalid("origin",t.origin,t.generation)}}}commitUpdate(e,t,n,r){void 0===r?this.invokeHandler(n,this.handlers.onUpdate,e,t):this.invokeHandler(n,this.handlers.onUpdate,e,t,r)}reportInvalid(e,t,n){this.invokeHandler(n,this.handlers.onInvalid,e,t)}matchesSource(e,t){if("parent-or-opener"!==this.handlers.sourcePolicy)return!0;try{const n=e.source;if("object"!=typeof n||null===n)return!1;const r=t.parent;return r!==t&&n===r||n===t.opener}catch{return!1}}matchesOrigin(e,t){try{return!0===(this.isCurrentGeneration(t)&&this.matcher(e))&&this.isCurrentGeneration(t)}catch{return!1}}invokeHandler(e,t,...n){if(void 0!==t&&this.isCurrentGeneration(e))try{h(t(...n))}catch{}}isCurrentGeneration(e){return void 0!==this.attachedTarget&&this.generation===e}enqueue(e){void 0===this.queueTail?this.queueHead=e:this.queueTail.next=e,this.queueTail=e}dequeue(e){return this.queueHead===e&&(this.queueHead=e.next,void 0===this.queueHead&&(this.queueTail=void 0),!0)}resetQueue(){this.queueHead=void 0,this.queueTail=void 0}};function m(e){return(...t)=>{try{h(e(...t))}catch{}}}function g(){}var v=m((...e)=>console.error(...e)),y=m((...e)=>console.warn(...e)),b=m((...e)=>console.debug(...e)),w={"structural arrays":'data-payload-type="array" and keyed lists',"array templates":"data-payload-array-template","server-rendered fragments":"data-payload-fragment boundaries","route refreshes":'data-payload-strategy="route" and bindings in <head>',"screen-reader announcements":"the aria-live region","auto-binding":"autoBind: 'unique'"},S=/* @__PURE__ */new Set;function k(e){S.has(e)||(S.add(e),y(`[live-preview] LP0104: this page carries the lean runtime, which leaves out ${e} (${w[e]}). The elements are left as the server rendered them. Remove \`runtime: LEAN_RUNTIME\` to get the full runtime.`))}function A(e){return"undefined"!=typeof __LEAN_BUILD__&&__LEAN_BUILD__?function(e){return!1!==e.enableA11y&&k("screen-reader announcements"),null}(e):function(e){if(!1===e.enableA11y)return null;const t=e.root,n=void 0===t?void 0:function(e){return 9===e.nodeType}(t)?t:t.ownerDocument;return new r(e.a11yLocale,n)}(e)}function T(e){if("undefined"==typeof window)return;const t=[];window.parent!==window&&t.push(window.parent),window.opener instanceof Window&&t.push(window.opener),p.sendReady(t,e)}function C(e){const t={};for(const[n,r]of Object.entries(e))void 0!==r&&(t[n]=r);return t}var $=/* @__PURE__ */new Set(["tabs","row","collapsible"]);function R(e,t=""){const n=/* @__PURE__ */new Map;return N(e,t,n),n}function N(e,t,n){for(const r of e){if($.has(r.type)){r.fields&&N(r.fields,t,n);continue}const e=""===t?r.name:`${t}.${r.name}`;if(n.set(e,r),"group"===r.type)r.fields&&N(r.fields,e,n);else if("array"===r.type&&r.fields)N(r.fields,`${e}.*`,n);else if("blocks"===r.type&&r.blocks)for(const t of r.blocks)N(t.fields,`${e}.*.${t.slug}`,n)}}function P(e,t){if(e.has(t))return e.get(t);const n=t.replace(/\.\d+(?=\.|$)/g,".*");return e.has(n)?e.get(n):void 0}function L(e){if("object"!=typeof e||null===e)return;const t=e.id;return"string"==typeof t||"number"==typeof t?t:void 0}function F(e){if("object"!=typeof e||null===e)return;const t=e.blockType;return"string"==typeof t?t:void 0}function x(e,t){return t.every(e=>void 0!==L(e))?function(e,t){const n=[],r=/* @__PURE__ */new Map;for(let t=0;t<e.length;t+=1){const n=L(e[t]);void 0!==n&&r.set(n,t)}const i=/* @__PURE__ */new Set;for(let o=0;o<t.length;o+=1){const s=t[o],a=L(s);if(void 0===a){n.push({kind:"insert",index:o,value:s});continue}const l=r.get(a);if(void 0===l){n.push({kind:"insert",index:o,value:s});continue}i.add(l);const u=e[l];F(u)===F(s)?(l!==o&&n.push({kind:"move",from:l,to:o,value:s}),U(u,s)||n.push({kind:"update",index:o,value:s})):n.push({kind:"replace",index:o,oldValue:u,value:s})}for(let t=0;t<e.length;t+=1)i.has(t)||n.push({kind:"remove",index:t,value:e[t]});return n}(e,t):function(e,t){const n=[],r=Math.min(e.length,t.length);for(let i=0;i<r;i+=1)U(e[i],t[i])||n.push({kind:"update",index:i,value:t[i]});if(t.length>e.length)for(let r=e.length;r<t.length;r+=1)n.push({kind:"insert",index:r,value:t[r]});if(e.length>t.length)for(let r=t.length;r<e.length;r+=1)n.push({kind:"remove",index:r,value:e[r]});return n}(e,t)}function U(e,t){if(Object.is(e,t))return!0;if("object"!=typeof e||"object"!=typeof t||null===e||null===t)return!1;const n=e,r=t,i=Object.keys(n),o=Object.keys(r);if(i.length!==o.length)return!1;for(const e of i)if(!Object.is(n[e],r[e]))return!1;return!0}var M={text:"text",textarea:"textarea",richText:"richText",email:"email",number:"number",checkbox:"checkbox",date:"date",select:"select",radio:"radio",array:"array",blocks:"blocks",group:"text",tabs:"text",row:"text",collapsible:"text",relationship:"relationship",upload:"upload",point:"text",json:"text",code:"text",ui:"text"},E=/* @__PURE__ */new Set(["http:","https:","mailto:","tel:"]),I=/^\s*(?:javascript|data|vbscript|file|blob|about)\s*:/i,O=/^(?:\.{1,2}\/|[a-zA-Z0-9_-]+\/?)/,_=/^[\\/]{2}/,D=/[\t\n\r]/g;function isSafeUrl(e){if("string"!=typeof e)return!1;const t=e.trim().replace(D,"");if(0===t.length)return!1;if(I.test(t))return!1;if(t.startsWith("#")||t.startsWith("?"))return!0;if(_.test(t))return!0;if(t.startsWith("/"))return!0;try{const e=new URL(t);return E.has(e.protocol)}catch{return O.test(t)}}function isExternalHttpUrl(e){const t=e.trim().replace(D,"");return/^https?:\/\//i.test(t)||_.test(t)}var z=/* @__PURE__ */new Set(["style","srcdoc","formaction","form","id","name","is","srcset","imagesrcset"]),B=/* @__PURE__ */new Set(["href","src","poster","cite","action","xlink:href","data"]);function H(e){return!e.startsWith("on")&&!z.has(e)}function j(e){return e.onUnfaithfulPatch??("ignore"===e.onUnboundChange?"ignore":"escalate")}function W(e,t,n,r){if(t.reportedUnfaithful.has(n.element))return;t.reportedUnfaithful.add(n.element),t.unfaithfulCount+=1,t.unfaithfulFields.add(n.fieldName);const i=e.onUnfaithfulPatch;"ignore"!==i&&("warn"!==i?(e.log("LP0411",n.fieldName,r),t.unfaithfulPatches.push(n)):e.warn(`[live-preview] LP0411: "${n.fieldName}" ${r}`))}function q(e,t){return!e.unfaithfulFields.has(t)&&(e.unfaithfulFields.add(t),e.unfaithfulCount+=1,!0)}var V=/* @__PURE__ */new Set(["date","number","checkbox"]);function G(e){return"INPUT"===e.tagName||"TEXTAREA"===e.tagName?e.value:e.textContent}function K(e){const t=e.trim();return JSON.stringify(t.length>40?`${t.slice(0,40)}…`:t)}var J=/* @__PURE__ */new WeakSet;function Q(e){return J.add(e),e}function X(e){switch(typeof e){case"string":return e.length>65536?void 0:`s:${e}`;case"number":return`n:${Object.is(e,-0)?"-0":String(e)}`;case"boolean":return"b:"+(e?"1":"0");case"bigint":return`i:${String(e)}`;case"undefined":return"u";case"object":{if(null===e)return"z";let t;try{t=JSON.stringify(e)}catch{return}return t.length>65536?void 0:`o:${t}`}case"symbol":case"function":return}}var Z=class{previous=null;diff(e,t){const n=this.previous,r=null===n,i=/* @__PURE__ */new Map,o=/* @__PURE__ */new Set;for(const[t,r]of Object.entries(e)){const e=X(r);i.set(t,e),null!==n&&void 0!==e&&n.get(t)===e||o.add(t)}if(null!==n)for(const e of n.keys())i.has(e)||o.add(e);this.previous=i;const s=/* @__PURE__ */new Set;for(const[e,n]of Object.entries(t))if(o.has(e))for(const e of n)s.add(e);return{changed:o,invalidated:s,baseline:r}}reset(){this.previous=null}},Y="data-payload-fragment";function ee(e){return e.closest(`[${Y}]`)}function te(e){const t=e.getAttribute("data-payload-strategy");return null!==t&&t.length>0?"patch"===t||"fragment"===t||"route"===t?t:void 0:null!==ee(e)?"fragment":null!==e.closest("head")?"route":"patch"}function ne(e,t){return void 0===t||""===t?`collection:${e}`:`collection:${e}:${t}`}function re(e){return"string"==typeof e&&e.length>0}function ie(e,t){return null!==t&&void 0!==e&&t.includes(e)}function oe(e){const t=e.id;return"string"==typeof t&&t.length>0?t:"number"==typeof t&&Number.isFinite(t)?String(t):void 0}var se=/* @__PURE__ */new Set(["id","_id","createdAt","updatedAt","createdBy","updatedBy","_status","globalType","collection","locale","localized"]);function ae(e,t,n){const r=e.get(t);return void 0!==r&&(!1===n||r.some(e=>ie(e.owner,n)))}function le(e,t,n){const r=`${t}.`;for(const[t,i]of e.entries())if(t.startsWith(r)){if(!1===n)return!0;if(i.some(e=>ie(e.owner,n)))return!0}return!1}function ue(e,t){if(void 0===t||0===t.length)return e;const n=`_${t}`;return e.endsWith(n)?e.slice(0,-n.length):e}function ce(e,t,n){let r;return i=>{if(ae(e,i,n))return!0;const o=ue(i,t);return!(o===i||!ae(e,o,n))||!!le(e,i,n)||!(o===i||!le(e,o,n))||(r??=function(e,t){const n=/* @__PURE__ */new Set;for(const[r,i]of e.entries())for(const e of i)(!1===t||ie(e.owner,t))&&void 0!==e.locale&&n.add(`${r}_${e.locale}`);return n}(e,n),r.has(i))}}function de(e,t,n,r){const i=ce(e,n,r),o=[];for(const e of t)se.has(e)||i(e)||o.push(e);return o}var he=/* @__PURE__ */new Set(["text","textarea","email","number","checkbox","date","select","radio","point","code","json","ui","html"]),fe={},pe=class{rawChanges=new Z;resolved=null;queued=null;pending=null;timer=null;openUntil=0;decide(e,t){const n=t.message.data??{},{changed:r}=this.rawChanges.diff(n,fe);if(!function(e){const{cache:t,emitter:n}=e;if(t.islands.length>0)return!0;if(n.listenerCount("beforeUpdate")>0||n.listenerCount("afterUpdate")>0)return!0;for(const e of t.values()){if(ge(e)||e.fieldName.includes("."))return!0;if(ye(e.hrefField)||ye(e.srcField)||ye(e.altField))return!0}return void 0!==e.strategies.fragment&&null!==e.root.querySelector(`[${Y}]`)}(e))return{merge:!1,fields:n};const i=this.resolved;if(null===i)return this.resolved=n,{merge:!0,fields:n};const o={...i};let s=t.forceRender;for(const a of r){const r=n[a];if(se.has(a)){o[a]=r;continue}const l=me(a,i[a],r,e.cache,t.schemaIndex);"own"!==l&&(s=!0),"keep"!==l&&(o[a]=r)}return this.resolved=o,{merge:s,fields:o}}request(e,t,n){const r=Date.now();return r>=this.openUntil?(this.dropQueued(),this.openUntil=r+t,{leading:!0,result:e.merge(n)}):(this.queued=n,this.openUntil=r+t,this.pending??=function(){let e;return{promise:new Promise(t=>{e=t}),settle:e}}(),null!==this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.flush(e)},t),{leading:!1,result:this.pending.promise})}recordMerged(e){this.resolved=e}destroy(){this.dropQueued(),this.openUntil=0}dropQueued(){null!==this.timer&&clearTimeout(this.timer),this.timer=null,this.queued=null,this.pending?.settle({status:"superseded"}),this.pending=null}flush(e){const t=this.pending,n=this.queued;this.timer=null,this.pending=null,this.queued=null,null!==t&&null!==n&&e.merge(n).then(t.settle,()=>{t.settle({status:"unavailable"})})}};function me(e,t,n,r,i){return ve(n)?!ve(t)||function(e,t,n){const r=void 0===n?void 0:P(n,e);return void 0!==r&&!he.has(r.type)||!0===t.get(e)?.some(ge)||le(t,e,!1)}(e,r,i)?"keep":null==t?"ask":"own":"ask"}function ge(e){return!he.has(e.fieldType)}function ve(e){return null===e||"object"!=typeof e&&"function"!=typeof e}function ye(e){return!0===e?.includes(".")}var be=class{negotiation=negotiateProtocol(void 0);observed=/* @__PURE__ */new Set;observe(e,t){const n=e.filter(e=>!this.observed.has(e));if(0!==n.length){for(const e of n)this.observed.add(e);this.negotiation=negotiateProtocol(this.negotiation.theirs,this.observed),t("protocol",`observed=${n.join(",")}`)}}applyVersion(e,t){const n=this.negotiation;if(n.theirs===e)return;const r=negotiateProtocol(e,this.observed);this.negotiation=r,r.negotiated!==n.negotiated&&t("protocol","ours=4",`theirs=${e}`,`negotiated=${r.negotiated}`)}};function we(e){return null!==e&&e.forceRender&&!e.completed}var Se=class{lastIdentity=void 0;edit(e){const t=e.externallyUpdatedRelationship;if("object"!=typeof t||null===t)return null;const n=JSON.stringify([t.entitySlug,oe(t),t.updatedAt]),r=n!==this.lastIdentity;return this.lastIdentity=n,r&&function(e,t){const n=t.globalSlug??t.collectionSlug;if("string"!=typeof n||e.entitySlug!==n)return!0;const r=oe(e),i=oe(t.data??{});return void 0!==r&&void 0!==i&&r!==i}(t,e)?t:null}};function ke(e){try{return!0===e.matchMedia?.("(prefers-reduced-motion: reduce)").matches}catch{return!1}}var Ae=class{#e;reveal(e,t,n){return e===this.#e?"skipped-same":(this.#e=e,function(e,t){return function(e,t){const n=e.getBoundingClientRect(),r=n.bottom>0&&n.top<t.innerHeight,i=n.right>0&&n.left<t.innerWidth;return r&&i}(e,t)?"already-visible":(e.scrollIntoView({behavior:ke(t)?"auto":"smooth",block:"center"}),"revealed")}(t,n))}reset(){this.#e=void 0}},Te=class{seen=/* @__PURE__ */new Map;note(e,t,n){const r=X(n);if(void 0===r)return;const i=`${t.owner??""}\0${t.locale??""}\0${t.fieldName}`,o=this.seen.get(i);void 0!==o?o!==r&&(e.revealIdentities.push([i,r]),e.revealTarget??=t):this.seen.set(i,r)}commit(e){for(const[t,n]of e.revealIdentities)this.seen.set(t,n);e.revealIdentities=[];const t=e.revealTarget;return e.revealTarget=void 0,t}},Ce=class{started=!1;suspended=!1;deferredStart=null;hydration="idle";activeUpdate=null;locale=void 0;schema=void 0;schemaIndex=void 0;updateCount=0;supersededCount=0;completedCount=0;skippedUnchangedCount=0;lastFlush=null;absentFields=/* @__PURE__ */new Set;warnedOrphanFields=/* @__PURE__ */new Set;warnedStrategy=/* @__PURE__ */new WeakSet;warnedUnattributableMessage=!1;warnedVisibilityGate=!1;warnedFragmentFallback=!1;warnedEscalationUnavailable=!1;warnedProtocolShape=!1;reportedUnfaithful=/* @__PURE__ */new WeakSet;checkedServerFormat=/* @__PURE__ */new WeakSet;unfaithfulPatches=[];unfaithfulCount=0;escalatedCount=0;unfaithfulFields=/* @__PURE__ */new Set;autoBindSearchMs=void 0;autoBindGuesses=null;warnedForeignSource=!1;lastAppliedIdentity=/* @__PURE__ */new WeakMap;revealLedger=new Te;fragmentStats={rendered:0,failed:0,superseded:0};routeStats={refreshes:0,failed:0,refused:0,loopStopped:0};fragmentController=null;routeController=null;routeRetry=null;routeRefreshOwed=!1;readyTimers=[];revealer=new Ae;changes=new Z;merges=new pe;protocol=new be;relationships=new Se;isRunning(){return this.started}isCurrent(e){return this.started&&this.activeUpdate===e}complete(e){e.completed||(e.completed=!0,this.completedCount+=1)}abortStrategies(){null!==this.routeRetry&&(clearTimeout(this.routeRetry),this.routeRetry=null,this.routeRefreshOwed=!0);for(const e of["fragmentController","routeController"]){const t=this[e];null!==t&&(this[e]=null,t.abort())}}},$e=class{constructor(e,t){this.deps=e,this.state=t,this.instanceContext=C({renderRichText:e.renderRichText,sanitizerPolicy:e.sanitizerPolicy,reportUnfaithful:(n,r)=>{W(e,t,n,r)}})}deps;state;instanceContext;apply(e){const{deps:t,state:n}=this,r=n.activeUpdate;if(null===r||void 0===e.revision||!f(r.revision,e.revision)||!n.isCurrent(r))return!1;const{target:i,value:o}=e,s=void 0!==r.schemaIndex?P(r.schemaIndex,i.fieldName):void 0;let a,l=function(e,t){if(e.explicitFieldType)return e.fieldType;if(void 0!==t){const e=function(e){if(Object.prototype.hasOwnProperty.call(M,e))return M[e]}(t);if(void 0!==e)return e}return e.fieldType}(i,s?.type);"text"===l&&!0!==i.explicitFieldType&&function(e){if("object"!=typeof e||null===e||!("root"in e))return!1;const t=e.root;return"object"==typeof t&&null!==t&&Array.isArray(t.children)}(o)&&(l="richText");try{a=t.resolveRenderer(l,i)}catch(e){return this.fail(r,e)}if(!n.isCurrent(r))return!1;const u=t.emitter.listenerCount("elementUpdate")>0,c=u?"INPUT"===(d=i.element).tagName||"TEXTAREA"===d.tagName?d.value:"IMG"===d.tagName?d.src:d.textContent:void 0;var d;if(!n.isCurrent(r))return!1;const h={allFields:e.allFields,locale:i.locale??r.locale,schema:s,...this.instanceContext};!0===i.hidesWhenEmpty&&i.element.toggleAttribute("hidden",function(e){return null==e||("string"==typeof e?0===e.trim().length:Array.isArray(e)&&0===e.length)}(o));try{if(void 0!==i.targetAttribute){if("blocked"===function(e,t,n){const r=t.toLowerCase().trim();if(0===r.length)return"blocked";if(!H(r))return"blocked";if(null==n)return e.removeAttribute(r),"applied";if("string"!=typeof n&&"number"!=typeof n&&"boolean"!=typeof n)return"blocked";const i=String(n);return B.has(r)&&!isSafeUrl(i)?"blocked":(e.setAttribute(r,i),"applied")}(i.element,i.targetAttribute,o))return t.warn(`[live-preview] LP0401: refused to write "${i.fieldName}" into attribute "${i.targetAttribute}"`),!1}else{if(void 0===a)return t.log("no renderer for",l),W(t,n,i,`has no renderer for "${l}"`),!1;{const e=function(e,t,n,r){if("ignore"===e.onUnfaithfulPatch)return;if(void 0!==n.format||!V.has(r))return;if(t.checkedServerFormat.has(n.element))return;t.checkedServerFormat.add(n.element);const i=G(n.element);return i.trim().length>0?i:void 0}(t,n,i,l),r=function(e,t,n,r){return e.render(t,n,r)}(a,i,o,h);if(!1===r&&function(e){return J.has(e.render)}(a))return W(t,n,i,`is a value ${a.name} cannot render`),!1;void 0!==e&&function(e,t,n){const r=G(t.element);r!==n&&e.warn(`[live-preview] LP0412: "${t.fieldName}" showed ${K(n)}, the patch wrote ${K(r)} — either an edit that arrived before the preview connected, or a template that formats this value differently. Set data-payload-format to match it.`)}(t,i,e)}}}catch(e){return this.fail(r,e)}if(!n.isCurrent(r))return!1;u&&t.emitter.emitWhile("elementUpdate",{element:i.element,fieldName:i.fieldName,previousValue:c,nextValue:o,revision:r.revision.revision,receivedAt:r.receivedAt,source:"patch"},()=>n.isCurrent(r));const p=n.isCurrent(r);return p&&(void 0!==e.valueIdentity?n.lastAppliedIdentity.set(i.element,e.valueIdentity):n.lastAppliedIdentity.delete(i.element)),p}fail(e,t){if(!this.state.isCurrent(e))return!1;const n=t instanceof Error?t:new Error(String(t));return this.deps.emitter.emitWhile("error",{error:n,context:"renderer",code:"LP0603"},()=>this.state.isCurrent(e)),!1}};function Re(...e){const t=/* @__PURE__ */new Map;for(const n of e)for(const[e,r]of Object.entries(n)){let n=t.get(e);void 0===n&&(n=/* @__PURE__ */new Set,t.set(e,n));for(const e of r)n.add(e)}const n={};for(const[e,r]of t)n[e]=[...r];return n}function Ne(e,t){const n={};for(const r of t)r!==e&&(n[r]=[e]);return n}var Pe="data-payload-island",Le=`astro-island, [${Pe}]`;function Fe(e){return"patch"===e.getAttribute(Pe)}function xe(e){return function(e){return"astro-island"===e.tagName.toLowerCase()||e.hasAttribute(Pe)}(e)&&!Fe(e)}var Ue="data-payload-field",Me="data-payload-type",Ee="data-payload-attribute",Ie="data-payload-href",Oe="data-payload-src",_e="data-payload-alt",De="data-payload-array-template",ze="data-payload-array-separator",Be="data-payload-locale",He="data-payload-richtext",je="data-payload-html",We="data-payload-array",qe="data-payload-structural",Ve="data-payload-owner",Ge="data-payload-depends",Ke="data-payload-strategy",Je="data-payload-boundary",Qe="data-payload-guessed",Xe=[Ue,Me,Ee,Ie,Oe,_e,De,ze,Be,He,je,We,qe,Ve,Ge,Ke,Je,"type"],Ze=`[${Ue}]`,Ye=`[${Ve}]`;function et(e){const t=e.closest(Ye)?.getAttribute(Ve);return null==t||0===t.length?void 0:t}var tt=/^[a-z][a-z0-9-]*:[a-z][a-z0-9-]*$/i,nt=/* @__PURE__ */new Set(["text","textarea","richText","email","number","checkbox","date","select","radio","array","blocks","group","tabs","row","collapsible","relationship","upload","point","json","code","ui","html","url","image","structural-array"]);function rt(e){return nt.has(e)||tt.test(e)}var it=class{entriesByField=/* @__PURE__ */new Map;entryByElement=/* @__PURE__ */new WeakMap;filter;count=0;dependencies=null;islandRoots=[];constructor(e={}){this.filter=e.filter??st}dependencyMap(){if(null!==this.dependencies)return this.dependencies;const e=[];for(const t of this.values())void 0!==t.dependsOn&&e.push(Ne(t.fieldName,t.dependsOn));return this.dependencies=Re(...e),this.dependencies}get islands(){return this.islandRoots}buildFromRoot(e){const t=performance.now();this.clear();let n=0;for(const t of e.querySelectorAll(Ze))void 0!==this.add(t)&&(n+=1);return this.islandRoots=function(e){const t=[];for(const n of e.querySelectorAll(Le))Fe(n)||t.push(n);return t}(e),{elementCount:n,fieldCount:this.entriesByField.size,durationMs:performance.now()-t}}add(e){const t=this.filter(e)?this.resolveBinding(e):void 0,n=this.entryByElement.get(e);if(this.dependencies=null,void 0!==t)return void 0!==n&&this.replaceEntry(n,t)?(this.entryByElement.set(e,t),t):(void 0!==n&&this.removeEntry(e,n),this.append(t),this.entryByElement.set(e,t),t);void 0!==n&&this.removeEntry(e,n)}remove(e){const t=this.entryByElement.get(e);return!!t&&(this.dependencies=null,this.removeEntry(e,t))}get(e){return this.entriesByField.get(e)}getByElement(e){return this.entryByElement.get(e)}get fieldCount(){return this.entriesByField.size}get elementCount(){return this.count}entries(){return this.entriesByField.entries()}*values(){for(const e of this.entriesByField.values())yield*e}has(e){return this.entryByElement.has(e)}clear(){this.entriesByField.clear(),this.entryByElement=/* @__PURE__ */new WeakMap,this.count=0,this.dependencies=null,this.islandRoots=[]}replaceEntry(e,t){if(e.fieldName!==t.fieldName)return!1;const n=this.entriesByField.get(e.fieldName),r=void 0===n?-1:n.indexOf(e);return!(void 0===n||r<0||(n[r]=t,0))}removeEntry(e,t){this.entryByElement.delete(e);const n=this.entriesByField.get(t.fieldName),r=void 0===n?-1:n.indexOf(t);return!(void 0===n||r<0||(n.splice(r,1),0===n.length&&this.entriesByField.delete(t.fieldName),this.count-=1,0))}append(e){const t=this.entriesByField.get(e.fieldName);t?t.push(e):this.entriesByField.set(e.fieldName,[e]),this.count+=1}resolveBinding(e){const t=e.getAttribute(Ue);if(null===t||0===t.length)return;const n=e.getAttribute(Me),r=e.getAttribute(Ee),i=e.getAttribute(Ie),o=e.getAttribute(Oe),s=e.getAttribute(_e),a=e.getAttribute(De),l=e.getAttribute(ze),u=e.getAttribute(Be),c=e.getAttribute("data-payload-format"),d=et(e),h=function(e){if(null==e)return[];const t=/* @__PURE__ */new Set,n=[];for(const r of e.split(/[\s,]+/)){const e=r.trim();0===e.length||t.has(e)||(t.add(e),n.push(e))}return n}(e.getAttribute(Ge)),f=e.getAttribute(Ke),p=e.getAttribute(Qe),m=ee(e);return{element:e,fieldName:t,fieldType:ot(e),explicitFieldType:null!==n&&rt(n),strategyKind:te(e)??"unknown",...null!==m?{fragmentBoundary:m}:{},...null!==r&&r.length>0?{targetAttribute:r}:{},...null!==i&&i.length>0?{hrefField:i}:{},...null!==o&&o.length>0?{srcField:o}:{},...null!==s&&s.length>0?{altField:s}:{},...null!==a?{arrayTemplate:a}:{},...null!==l?{arraySeparator:l}:{},...null!==u&&u.length>0?{locale:u}:{},...null!==c&&c.length>0?{format:c}:{},...void 0!==d?{owner:d}:{},...h.length>0?{dependsOn:h}:{},...null!==f&&f.length>0?{strategy:f}:{},...e.hasAttribute(Je)?{hidesWhenEmpty:!0}:{},...null!==p?{guessed:p}:{}}}};function ot(e){const t=e.getAttribute(Me);if(null!==t&&rt(t))return t;if(e.hasAttribute(He))return"richText";if(e.hasAttribute(je))return"html";if(e.hasAttribute(qe))return"structural-array";if(e.hasAttribute(We))return"array";if("IMG"===e.tagName)return"image";if("A"===e.tagName)return"url";if("TIME"===e.tagName)return"date";if("INPUT"===e.tagName){const t=e.type;if("checkbox"===t)return"checkbox";if("number"===t)return"number";if("date"===t||"datetime-local"===t)return"date"}return"text"}function st(){return!0}function at(e,t){return e.length>0&&e.length<=t&&"."!==e&&".."!==e&&!e.includes("/")&&!e.includes("\\")&&!function(e){for(const t of e){const e=t.codePointAt(0)??0;if(e<=31||127===e)return!0}return!1}(e)}function lt(e){return at(e,128)&&!e.includes("?")&&!e.includes("#")}var ut=class{serverURL;apiRoute;depth;fetchFn;log;inflight=null;attempt=0;destroyDepth=0;constructor(e){this.serverURL=function(e){let t=e.length;for(;e.endsWith("/",t);)t-=1;return e.slice(0,t)}(e.serverURL);const t=e.apiRoute??"/api";this.apiRoute=t.startsWith("/")?t:`/${t}`,this.depth=e.depth??1,this.fetchFn=e.fetchFn,this.log=m(e.log??g)}canMerge(e){return null!==this.endpointOf(e)}endpointOf(e){try{const n=e.globalSlug;if(n)return lt(n)?`globals/${encodeURIComponent(n)}`:null;const r=e.collectionSlug??"",i=e.data.id;return lt(r)&&("number"==typeof(t=i)?Number.isFinite(t):"string"==typeof t&&at(t,512))?`${encodeURIComponent(r)}/${encodeURIComponent(String(i))}`:null}catch{return null}var t}async merge(e){if(this.destroyDepth>0)return{status:"superseded"};const t=this.attempt+=1,n=this.inflight;this.inflight=null;let r=null;const i=()=>this.attempt!==t;try{if(n?.abort(),i())return{status:"superseded"};const t=this.endpointOf(e);if(null===t)return i()?{status:"superseded"}:{status:"unavailable"};const o=this.fetchFn??("function"==typeof fetch?fetch:void 0);if(void 0===o)return{status:"unavailable"};r=new AbortController,this.inflight=r;const s=`${this.serverURL}${this.apiRoute}/${t}`,a=await o(s,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json","X-Payload-HTTP-Method-Override":"GET"},body:JSON.stringify({data:e.data,depth:this.depth,flattenLocales:!1,locale:e.locale}),signal:r.signal});if(i())return{status:"superseded"};if(!a.ok)return this.log("merge HTTP",a.status,s),{status:"unavailable"};const l=await a.json();return i()?{status:"superseded"}:null===l||"object"!=typeof l||Array.isArray(l)?(this.log("merge invalid",s),{status:"unavailable"}):{status:"merged",doc:l}}catch(e){return i()?{status:"superseded"}:(this.log("merge exception",e),{status:"unavailable"})}finally{this.inflight===r&&(this.inflight=null)}}destroy(){this.attempt+=1;const e=this.inflight;this.inflight=null,this.destroyDepth+=1;try{e?.abort()}finally{this.destroyDepth-=1}}},ct="2.0.4",dt={name:"payload-2",fieldTyping:"schema",populatesRelationships:"admin",documentEvents:!1},ht={name:"payload-3",fieldTyping:"heuristic",populatesRelationships:"server",documentEvents:!0},ft={name:"unknown",fieldTyping:"heuristic",populatesRelationships:"server",documentEvents:!1};function detectProtocolProfile(e){return e.has("schema-json")?dt:e.has("document-events")||e.has("relationship-events")?ht:ft}var pt=class{callbacks;debounceMs;rootMargin;visible=/* @__PURE__ */new Set;mutation=null;intersection=null;debounceTimer=null;generation=0;constructor(e,t={}){this.callbacks=e,this.debounceMs=t.mutationDebounceMs??100,this.rootMargin=t.intersectionRootMargin??"200px"}start(e){const t=this.generation;this.stop();const n=t+1;if(this.generation!==n)return;let r=null,i=null;try{r=new MutationObserver(e=>{this.handleMutations(e,n)}),i=new IntersectionObserver(e=>{this.handleIntersection(e,n)},{rootMargin:this.rootMargin,threshold:0}),r.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[...Xe]})}catch(e){throw r?.disconnect(),i?.disconnect(),e}if(this.generation!==n)return r.disconnect(),void i.disconnect();this.mutation=r,this.intersection=i}observeElement(e){this.intersection?.observe(e)}unobserveElement(e){this.intersection?.unobserve(e),this.visible.delete(e)}markVisible(e,t){t?this.visible.add(e):this.visible.delete(e)}isVisible(e){return this.visible.has(e)}stop(){this.generation+=1;const e=this.debounceTimer,t=this.mutation,n=this.intersection;this.debounceTimer=null,this.mutation=null,this.intersection=null,this.visible.clear(),null!==e&&clearTimeout(e);try{t?.disconnect()}finally{n?.disconnect()}}handleMutations(e,t){if(!this.isCurrentGeneration(t)||!function(e){for(const t of e){if("attributes"===t.type&&null!==t.attributeName&&Xe.includes(t.attributeName)&&(t.attributeName===Ue||t.attributeName===Ve||1===t.target.nodeType&&t.target.hasAttribute(Ue)))return!0;for(const e of t.addedNodes)if(mt(e))return!0;for(const e of t.removedNodes)if(mt(e))return!0}return!1}(e))return;null!==this.debounceTimer&&clearTimeout(this.debounceTimer);const n=setTimeout(()=>{this.isCurrentGeneration(t)&&this.debounceTimer===n&&(this.debounceTimer=null,this.callbacks.onStructuralChange())},this.debounceMs);this.debounceTimer=n}handleIntersection(e,t){for(const n of e){if(!this.isCurrentGeneration(t))return;const{target:e}=n;if(n.isIntersecting){if(this.visible.has(e))continue;this.visible.add(e),this.callbacks.onVisibilityChange(e,!0)}else this.visible.has(e)&&(this.visible.delete(e),this.callbacks.onVisibilityChange(e,!1))}}isCurrentGeneration(e){return this.generation===e&&null!==this.intersection}};function mt(e){if(1!==e.nodeType)return!1;const t=e;return t.hasAttribute(Ue)||null!==t.querySelector(`[${Ue}]`)}var gt="[data-payload-field]";function vt(){if("undefined"==typeof window)return;const e=window;return e.__livePreviewHydration??={armed:!1,committed:!1,commits:[],onCommit:void 0,waiters:[]}}function yt(){const e=vt();if(void 0===e||e.armed)return;e.armed=!0;const t=window,n=t.__REACT_DEVTOOLS_GLOBAL_HOOK__??=function(){const e=/* @__PURE__ */new Map;return{supportsFiber:!0,renderers:e,inject:t=>{const n=e.size+1;return e.set(n,t),n}}}(),r=n.onCommitFiberRoot;n.onCommitFiberRoot=function(t,n,...i){try{r?.call(this,t,n,...i)}catch{}const o=n?.containerInfo;void 0===e.onCommit?e.commits.push(o):e.onCommit(o)}}function bt(e){e.committed=!0;const t=e.waiters;e.waiters=[];for(const e of t)e()}function wt(e,t){const n=e.waiters.indexOf(t);n>=0&&e.waiters.splice(n,1)}function St(e,t,n){if(e.committed)return null;let r=null;const i=()=>{null!==r&&clearTimeout(r),r=null,t("committed")};return e.waiters.push(i),r=setTimeout(()=>{r=null,wt(e,i),t("timed-out")},n),()=>{null!==r&&clearTimeout(r),r=null,wt(e,i)}}var kt="__vue_app__";function At(){if("undefined"==typeof window)return;const e=window;return e.__livePreviewVueHydration??={armed:!1,committed:!1,waiters:[]}}function Tt(e){return Object.prototype.hasOwnProperty.call(e,kt)?e[kt]:void 0}function Ct(){const e=At();if(void 0===e||e.armed)return;e.armed=!0;const t=Element.prototype;void 0===Object.getOwnPropertyDescriptor(t,kt)&&Object.defineProperty(t,kt,{configurable:!0,get:()=>{},set(e){Object.defineProperty(this,kt,{value:e,writable:!0,configurable:!0,enumerable:!0});const t=At();void 0===t||t.committed||null===this.querySelector(gt)||function(e,t){const n=t?.$nuxt;!0!==n?.isHydrating||"function"!=typeof n.hook?bt(e):n.hook("app:suspense:resolve",()=>{e.committed||bt(e)})}(t,e)}})}function $t(e){if(void 0===e.hydration)return void e.startNow();const t=t=>{e.later(()=>{Rt(e,t)})},n="react"===e.hydration?function(e,t=5e3){yt();const n=vt();if(void 0===n)return null;if(void 0===n.onCommit){const e=e=>{!n.committed&&function(e){const t=e;return 9===t?.nodeType||null!=t?.querySelector?.(gt)}(e)&&bt(n)};n.onCommit=e;for(const t of n.commits.splice(0))e(t)}return St(n,e,t)}(t):function(e,t,n=5e3){Ct();const r=At();return void 0===r?null:(!r.committed&&function(e){for(let t=e.querySelector(gt);null!==t;t=t.parentElement)if(void 0!==Tt(t))return!0;return!1}(e)&&bt(r),St(r,t,n))}(e.root,t);null!==n?(e.defer(n),e.hydrated("waiting")):Rt(e,"committed")}function Rt(e,t){e.hydrated(t),"timed-out"===t&&e.warn(`[live-preview] LP0607: no ${"react"===e.hydration?"React commit":"Vue mount"} in ${String(5e3)} ms; started without waiting for hydration.`),e.startNow()}var Nt=class{timeoutMs;onTimeout;handle=null;lastKick=0;constructor(e){this.timeoutMs=e.timeoutMs??0,this.onTimeout=e.onTimeout}kick(){if(this.lastKick=Date.now(),this.timeoutMs<=0)return;null!==this.handle&&clearTimeout(this.handle);const e=setTimeout(()=>{this.handle===e&&(this.handle=null,this.onTimeout())},this.timeoutMs);this.handle=e}stop(){null!==this.handle&&(clearTimeout(this.handle),this.handle=null)}get lastKickAt(){return this.lastKick}get pending(){return null!==this.handle}},Pt=class{current="disconnected";get status(){return this.current}markConnected(){return this.transition("connected")}markDisconnected(){return this.transition("disconnected")}transition(e){return this.current!==e&&(this.current=e,!0)}},Lt=/* @__PURE__ */new Set(["true","false","yes","no","on","off"]),Ft=/^[\d\s.,:+/-]+$/u,xt=/^[a-z][a-z0-9_-]*$/u,Ut=/^[a-z]{2,3}(?:[-_][A-Za-z0-9]{2,8})*$/u,Mt=/* @__PURE__ */new Set(["SCRIPT","STYLE","TEMPLATE","TITLE","NOSCRIPT","TEXTAREA","SELECT","OPTION","INPUT","IFRAME"]);function Et(e,t=13){if("string"!=typeof e)return!1;const n=e.trim();return!(n.length<t||Ft.test(n)||Lt.has(n.toLowerCase())||xt.test(n)||Ut.test(n))}function It(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function Ot(e,t,n=13){const r=/* @__PURE__ */new Map,i=(e,t,n)=>{r.set(e,r.has(e)?null:{field:t,media:n})};for(const[r,o]of Object.entries(e)){if(se.has(r))continue;const e=ue(r,t);if(Et(o,n))i(o.trim(),e,!1);else if(It(o))if("string"==typeof o.url)i(o.url,e,!0);else if(!("id"in o)&&!("_id"in o))for(const[t,r]of Object.entries(o))!se.has(t)&&Et(r,n)&&i(r.trim(),`${e}.${t}`,!1)}return r}function _t(e){if("http://www.w3.org/1999/xhtml"!==e.namespaceURI||Mt.has(e.tagName))return!0;if(e.hasAttribute(Ue)||e.hasAttribute("data-payload-no-bind")||e.hasAttribute("data-payload-owned")||xe(e))return!0;const t=e.getAttribute("contenteditable");return null!==t&&"false"!==t}function Dt(e){let t;for(let n=e.firstChild;null!==n;n=n.nextSibling){if(1===n.nodeType)return;if(3!==n.nodeType)continue;const e=n.data.trim();if(0!==e.length){if(void 0!==t)return;t=e}}return t}function zt(e){return H(e)&&!e.startsWith("data-payload-")&&"value"!==e}function Bt(e,t,n){let r=e.byElement.get(t);void 0===r&&(r={attributes:/* @__PURE__ */new Map},e.byElement.set(t,r));let i=e.byField.get(n.field);return void 0===i&&(i=/* @__PURE__ */new Set,e.byField.set(n.field,i)),i.add(t),r}function Ht(e,t){for(let n=e.firstElementChild;null!==n;n=n.nextElementSibling){if(_t(n))continue;const e=Dt(n),r=void 0===e?void 0:t.values.get(e);null==r||r.media||(Bt(t,n,r).text=r.field);for(const e of n.getAttributeNames()){if(!zt(e))continue;const r=t.values.get(n.getAttribute(e)??"");null!=r&&(!r.media||"IMG"===n.tagName&&"src"===e)&&Bt(t,n,r).attributes.set(e,r)}Ht(n,t)}}function jt(e,t,n){const r=e.tagName;if(void 0!==t){const i={[Ue]:t};if("A"===r){const e=n.get("href");void 0===e?i[Me]="text":e!==t&&(i[Ie]=e)}return{element:e,fieldName:t,matched:Dt(e)??"",stamps:i}}if("IMG"===r){const t=n.get("src");if(void 0!==t){const r=n.get("alt");return{element:e,fieldName:t,matched:e.getAttribute("src")??"",attribute:"src",stamps:{[Ue]:t,...void 0!==r&&r!==t?{[_e]:r}:{}}}}}const i=n.entries().next();if(i.done)return;const[o,s]=i.value;return{element:e,fieldName:s,matched:e.getAttribute(o)??"",attribute:o,stamps:{[Ue]:s,[Ee]:o}}}function Wt(e,t){const n={values:t,byElement:/* @__PURE__ */new Map,byField:/* @__PURE__ */new Map};t.size>0&&!_t(e)&&Ht(e,n);const r=e=>1===n.byField.get(e)?.size,i=[];for(const[e,t]of n.byElement){const n=void 0!==t.text&&r(t.text)?t.text:void 0,o=/* @__PURE__ */new Map;for(const[e,n]of t.attributes)r(n.field)&&o.set(e,n.field);const s=jt(e,n,o);void 0!==s&&i.push(s)}return i}function qt(e){return 9===e.nodeType?e.body:e}function Vt(e,t,n,r){const i=[];for(const o of t){const{element:t}=o;if(!t.hasAttribute(Ue)&&(!1===n||ie(et(t),n))){for(const[e,n]of Object.entries(o.stamps))t.setAttribute(e,n);if(t.setAttribute(Qe,o.matched),void 0!==e.cache.add(t))e.observers.observeElement(t),e.log("autoBind",o.fieldName,"→",`<${t.tagName.toLowerCase()}>`,o.attribute??"text",JSON.stringify(o.matched),r),i.push(o);else{for(const e of Object.keys(o.stamps))t.removeAttribute(e);t.removeAttribute(Qe)}}}return i}var Gt=/* @__PURE__ */new Set(["__proto__","prototype","constructor"]);function Kt(e,t,n,r=!1){if(r&&void 0!==n){const r=Jt(e,`${t}_${n}`);if(void 0!==r)return r}const i=Jt(e,t);if(void 0!==i)return i;if(t.includes(".")){let n=e,r=!0;for(const e of t.split(".")){if(Gt.has(e)||null===n||"object"!=typeof n){r=!1;break}if(n=Jt(n,e),void 0===n){r=!1;break}}if(r)return n}return void 0===n?void 0:Jt(e,`${t}_${n}`)}function Jt(e,t){if(!Gt.has(t)&&Object.prototype.hasOwnProperty.call(e,t))return e[t]}function Qt(e,t,n,r){return Kt(e,n,t.locale??r,void 0!==t.locale)}function Xt(e,t,n,r){const i=X(t);if(void 0===i)return;const o=[e.hrefField,e.srcField,e.altField];let s=i;for(const t of o){if(void 0===t||0===t.length)continue;const i=X(Qt(n,e,t,r));if(void 0===i)return;s+=`|${t}=${i}`}return s}function Zt(e,t,n,r,i){const{warned:o,warn:s}=e;if(o.has(n)||t(n))return;o.add(n);const a=`data-payload-field="${ue(n,r)}"`;s(""!==i?`[live-preview] LP0203: field "${n}" has a value and no <… ${a}> on this page; editing it changes nothing here. Expected where the page shows part of the document: inspect().fidelity.fields lists these, onUnfaithfulPatch decides whether a server render is asked for.`:`[live-preview] LP0201: no <… ${a}> for the empty field "${n}"; render the anchor unconditionally so edits to an empty field have somewhere to land.`)}function Yt(e){const t=typeof e;return"string"===t||"number"===t||"boolean"===t||"bigint"===t}function en(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}var tn=/* @__PURE__ */Symbol.for("payload-live-preview.trusted-types");function nn(e){const t=function(){const e=function(){const e=globalThis,t=e[tn];if(void 0!==t)return t;const n={};return e[tn]=n,n}();if(void 0!==e.override)return e.override;if(void 0!==e.auto)return e.auto;const t=function(){const e=globalThis.trustedTypes;if("object"==typeof e&&null!==e)return"function"==typeof e.createPolicy?e:void 0}();try{e.auto=void 0===t?null:t.createPolicy("payload-live-preview",{createHTML:e=>e})}catch{e.auto=null}return e.auto}();return null===t?e:t.createHTML(e)}var rn=/* @__PURE__ */new Set(["open","value","checked","selected"]);function on(e,t){for(const n of t.keyAttributes){const t=e.getAttribute(n);if(null!==t&&t.length>0)return`${n}=${t}`}}function sn(e){if(e.tagName.toLowerCase().includes("-"))return!0;if(e.hasAttribute(Pe)||e.hasAttribute("data-payload-owned"))return!0;const t=e.getAttribute("contenteditable");return null!==t&&"false"!==t}function an(e,t,n){if(!function(e,t){return e.tagName===t.tagName&&e.namespaceURI===t.namespaceURI&&!sn(e)&&!sn(t)}(e,t))return t;const r=function(e){const t=e.ownerDocument.activeElement;if(!(t instanceof HTMLElement&&e.contains(t)))return null;return{element:t,selection:t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement?[t.selectionStart,t.selectionEnd]:null}}(e);return function(e,t){for(const n of Array.from(e.attributes))t.hasAttribute(n.name)||rn.has(n.name.toLowerCase())||e.removeAttribute(n.name);for(const n of Array.from(t.attributes))e.getAttribute(n.name)!==n.value&&e.setAttribute(n.name,n.value)}(e,t),!0!==n.retainChildrenOf?.(e,t)&&function(e,t,n){const r=function(e,t){const n=/* @__PURE__ */new Map;let r;for(const i of Array.from(e.children)){const e=on(i,t);void 0!==e&&(n.has(e)?r??=e.slice(e.indexOf("=")+1):n.set(e,i))}return void 0!==r&&t.onDuplicateKey?.(e,r),n}(e,n),i=new Set(r.values()),o=Array.from(e.childNodes).filter(e=>!i.has(e)),s=/* @__PURE__ */new Set,a=/* @__PURE__ */new Set,l=Array.from(t.childNodes);let u=e.firstChild,c=0;for(let t=0;t<l.length;t+=1){const i=l[t];let d=null,h=i instanceof Element?on(i,n):void 0;if(void 0!==h&&a.has(h)&&(h=void 0),void 0!==h){a.add(h);const e=r.get(h);if(void 0!==e&&!s.has(e)&&(d=ln(e,i,n)===e?e:null,null===d)){e.replaceWith(i),s.add(i),u=i.nextSibling;continue}}else{for(;c<o.length;){const r=o[c];if(c+=1,!s.has(r)){if(cn(r,i)){d=ln(r,i,n)===r?r:null,null===d&&(e.replaceChild(i,r),s.add(i),u=i.nextSibling);break}if(r instanceof Element){const n=l[t+1];if(!(i instanceof Element)||void 0!==n&&cn(r,n)){c-=1;break}e.replaceChild(i,r),s.add(i),u=i.nextSibling;break}if(!(i instanceof Element)){e.replaceChild(i,r),s.add(i),u=i.nextSibling;break}}}if(null===d&&s.has(i))continue}const f=d??i;for(s.add(f);null!==u&&u!==f&&!s.has(u)&&un(u);)u=u.nextSibling;f!==u&&e.insertBefore(f,u),u=f.nextSibling}for(const t of Array.from(e.childNodes))s.has(t)||t.remove()}(e,t,n),function(e){if(null===e)return;const{element:t,selection:n}=e;if(t.ownerDocument.activeElement!==t&&t.isConnected)try{t.focus({preventScroll:!0});const[e,r]=n??[null,null];null!==e&&null!==r&&t.setSelectionRange(e,r)}catch{}}(r),e}function ln(e,t,n){return e instanceof Element&&t instanceof Element?sn(e)&&sn(t)?e:an(e,t,n):(e.nodeValue!==t.nodeValue&&(e.nodeValue=t.nodeValue),e)}function un(e){return e.nodeType===Node.TEXT_NODE&&0===(e.nodeValue??"").trim().length}function cn(e,t){return e.nodeType===t.nodeType&&(!(e instanceof Element&&t instanceof Element)||e.tagName===t.tagName&&e.namespaceURI===t.namespaceURI)}var dn=/* @__PURE__ */new Set;function hn(e){dn.has(e)||(dn.add(e),function(e){try{console.warn(e)}catch{}}(`[live-preview] LP0409: the strict sanitizer removed \`${e}\` from written markup; the 1.x default (\`sanitizerPolicy: 'compat'\`) kept it. ${function(e){return e.startsWith("data-payload-")?"A binding inside CMS content is refused by design — an editor could otherwise aim a write at any element on the page (docs/security.md)":"id"===e||"name"===e?"CMS content that can name an element can shadow a global of that name — DOM clobbering, refused by design (docs/security.md)":"List it in `allowedDataAttributes` if the page needs it, or set `sanitizerPolicy: 'compat'` to keep every `data-*` as 1.x did"}(e)}.`))}var fn=/* @__PURE__ */new Set(["p","br","strong","b","em","i","u","s","strike","mark","small","h1","h2","h3","h4","h5","h6","ul","ol","li","dl","dt","dd","blockquote","code","pre","kbd","samp","var","a","span","div","section","article","aside","header","footer","nav","figure","figcaption","img","picture","source","audio","video","sub","sup","hr","time","abbr","cite","q","table","thead","tbody","tfoot","tr","th","td","caption","colgroup","col"]),pn=/* @__PURE__ */new Set(["input","button","textarea","select","option","label"]),mn=/* @__PURE__ */new Set(["script","style","iframe","object","embed","link","meta","base","form","input","button","select","textarea","svg","math","template","frame","frameset","noframes","noscript"]),gn=/* @__PURE__ */new Set(["id","class","lang","dir","title","role","tabindex"]),vn="aria-",yn="data-",bn={a:/* @__PURE__ */new Set(["href","target","rel","download","hreflang","type"]),img:/* @__PURE__ */new Set(["src","srcset","sizes","alt","width","height","loading","decoding"]),picture:/* @__PURE__ */new Set([]),source:/* @__PURE__ */new Set(["src","srcset","sizes","type","media"]),audio:/* @__PURE__ */new Set(["src","controls","autoplay","loop","muted","preload"]),video:/* @__PURE__ */new Set(["src","poster","controls","autoplay","loop","muted","preload","width","height","playsinline"]),time:/* @__PURE__ */new Set(["datetime"]),abbr:/* @__PURE__ */new Set(["title"]),q:/* @__PURE__ */new Set(["cite"]),blockquote:/* @__PURE__ */new Set(["cite"]),table:/* @__PURE__ */new Set(["summary"]),th:/* @__PURE__ */new Set(["colspan","rowspan","scope","headers","abbr"]),td:/* @__PURE__ */new Set(["colspan","rowspan","headers"]),col:/* @__PURE__ */new Set(["span"]),colgroup:/* @__PURE__ */new Set(["span"]),ol:/* @__PURE__ */new Set(["start","reversed","type"]),li:/* @__PURE__ */new Set(["value"]),code:/* @__PURE__ */new Set(["class"]),pre:/* @__PURE__ */new Set(["class"])},wn=/* @__PURE__ */new Set(["href","src","cite","poster"]),Sn=class extends Error{name="SanitizerEnvironmentError"},kn=/* @__PURE__ */new Set(["id","name","data-payload-key","data-payload-nested-key","data-payload-nested-template"]),An=/* @__PURE__ */Symbol.for("payload-live-preview.sanitizer-document");function Tn(e,t,n){const r=Cn();if(!r)throw"undefined"!=typeof __INLINE_BUILD__&&__INLINE_BUILD__?new Error("sanitizeHtml needs a DOM"):new Sn("sanitizeHtml needs a DOM; provide one with setSanitizerDocument() during SSR.");if(""===e)return"";const i=function(e,t){const n=e?.policy??t??"strict";if(!e){const e=/* @__PURE__ */new Map;for(const[t,n]of Object.entries(bn))e.set(t,n);return{allowedTags:fn,attrByTag:e,allowFormControls:!1,templateMode:!1,mode:n,allowedData:/* @__PURE__ */new Set}}const r=new Set(fn);if(e.additionalAllowedTags?.forEach(e=>r.add(e)),!0===e.allowFormControls)for(const e of pn)r.add(e);const i=/* @__PURE__ */new Map;for(const[e,t]of Object.entries(bn))i.set(e,t);for(const[t,n]of Object.entries(e.additionalAllowedAttributes??{})){const e=new Set(i.get(t));for(const t of n)e.add(t);i.set(t,e)}return{allowedTags:r,attrByTag:i,allowFormControls:!0===e.allowFormControls,templateMode:!0===e.templateMode,mode:n,allowedData:new Set(e.allowedDataAttributes?.map(e=>e.toLowerCase()))}}(n,t),o=r.createElement("template");return o.innerHTML=nn(e),$n(o.content,i),o.innerHTML}function Cn(){if("undefined"==typeof __INLINE_BUILD__||!__INLINE_BUILD__){const e=globalThis[An];if(e)return e}if("undefined"!=typeof document)return document}function $n(e,t){for(const n of Array.from(e.childNodes))1===n.nodeType?Rn(n,t):8===n.nodeType&&n.remove()}function Rn(e,t){const n=e.tagName.toLowerCase();if(!mn.has(n)||t.allowFormControls&&pn.has(n)){if(!t.allowedTags.has(n))return $n(e,t),void e.replaceWith(...e.childNodes);!function(e,t,n){const r=n.attrByTag.get(t);for(const t of Array.from(e.attributes)){const i=t.name.toLowerCase();if(i.startsWith("on")||"style"===i)e.removeAttribute(t.name);else{if("strict"===n.mode){if(n.templateMode&&kn.has(i))continue;if("id"===i||"name"===i||i.startsWith("data-payload-")){e.removeAttribute(t.name),"name"===i&&!0!==r?.has(i)||hn(i);continue}if(i.startsWith(yn)){n.allowedData.has(i)||(e.removeAttribute(t.name),hn(i));continue}if(gn.has(i)||i.startsWith(vn))continue}else if(gn.has(i)||i.startsWith(vn)||i.startsWith(yn))continue;r?.has(i)?wn.has(i)&&!isSafeUrl(t.value)?e.removeAttribute(t.name):"srcset"!==i||Nn(t.value)||e.removeAttribute(t.name):e.removeAttribute(t.name)}}}(e,n,t),"a"===n&&function(e){const t=e.getAttribute("href");null!==t&&isExternalHttpUrl(t)&&(e.setAttribute("rel","noopener noreferrer"),e.hasAttribute("target")||e.setAttribute("target","_blank"))}(e),$n(e,t)}else e.remove()}function Nn(e){for(const t of e.split(",")){const e=t.trim();if(0===e.length)continue;const[n=e]=e.split(/\s/,1);if(!isSafeUrl(n))return!1}return!0}var Pn=Object.freeze({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"}),Ln=/[&<>"'/`=]/g;function escapeHtml(e){return e.replace(Ln,e=>Pn[e])}var Fn=Object.freeze({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"}),xn=/[&<>"']/g;function escapeHtmlAttribute(e){return e.replace(xn,e=>Fn[e])}var Un=/\{\{([\s\S]*?)\}\}/g;function Mn(e){const t=/* @__PURE__ */new Set;for(const n of e)if("object"==typeof n&&null!==n)for(const e of Object.keys(n))t.add(e);return t}function En(e,t,n,r,i){const o="object"==typeof t&&null!==t?t:null;return e.replace(Un,(e,s)=>null!==o&&function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(o,s)?escapeHtml(r(Reflect.get(o,s))):null===o&&"value"===s?escapeHtml(r(t)):"index"===s?String(n):null!==o&&!0===i?.has(s)?"":e)}function In(e){const t=e.children,n=t[0];if(void 0===n)return[];const r=[];for(const{name:e,value:i}of Array.from(n.attributes)){if(!H(e)||e.startsWith("data-payload-"))continue;let n=!0;for(let r=1;r<t.length&&n;r+=1)n=t[r]?.getAttribute(e)===i;n&&r.push([e,i])}return r}function On(e,t){for(const[n,r]of t)e.hasAttribute(n)||e.setAttribute(n,r)}function _n(e){if(null==e)return"";if("string"==typeof e)return e;if("number"==typeof e||"boolean"==typeof e||"bigint"==typeof e)return String(e);try{return JSON.stringify(e)}catch{return""}}function Dn(e){return null==e||""===e}function zn(e,t){const n=e.get(t);return void 0!==n&&(e.delete(t),e.set(t,n)),n}function Bn(e,t,n,r){return e.set(t,n),function(e,t){for(const n of e.keys()){if(e.size<=t)break;e.delete(n)}}(e,r),n}var Hn=["input","textarea","select","option","button","label","details","summary","dialog","video","audio","progress","meter"],jn=["type","name","placeholder","open","disabled","readonly","required","checked","selected","value","min","max","step","rows","cols","for","controls","muted","loop","poster","src"],Wn=/<([a-z][a-z0-9]*(?:-[a-z0-9]+)+)\b/gi,qn=/* @__PURE__ */new Map;function Vn(e){const t=zn(qn,e);if(void 0!==t)return t;const n=new Set(Hn);for(const t of e.matchAll(Wn)){const e=t[1]?.toLowerCase();void 0!==e&&n.add(e)}const r={};for(const e of n)r[e]=jn;const i={additionalAllowedTags:[...n],additionalAllowedAttributes:r,allowFormControls:!0,templateMode:!0};return Bn(qn,e,i,64)}var Gn="data-payload-key",Kn="data-payload-nested-key",Jn="data-payload-nested-template";function Qn(e){const t=Zn(e.container,e.patches,e);return null===t?null:Yn(t,e.store,{morph:e.morph??!0,onDuplicateKey:e.onDuplicateKey})}function Xn(e,t){return t.hasAttribute(Kn)&&t.hasAttribute(Jn)}function Zn(e,t,n){const r=function(e,t,n){const{template:r,nextItems:i,forceRender:o=!1,store:s,sanitizerPolicy:a}=n,l=s.get(e),u=In(e),c=Mn(i),d=Array.from(e.children),h=sr(d,Gn),f=/* @__PURE__ */new Set,p=[];for(let s=0;s<i.length;s+=1){const m=i[s],g=or(m);let v=void 0===g?d[s]??null:ar(h,g)??null;null!==v&&f.has(v)&&(v=null),null!==v&&f.add(v);const y=t.replaces.has(s),b=o||t.renders.has(s)||null===v?lr(e.ownerDocument,r,m,s,a,u,c):void 0;if(null===b)return null;const w=void 0===b?[]:er(y?null:v,b,m,void 0===g?void 0:l?.get(g),n);if(null===w)return null;p.push([s,v,b,w,y])}return p}(e,function(e){const t=/* @__PURE__ */new Set,n=/* @__PURE__ */new Set;for(const r of e)"insert"===r.kind||"update"===r.kind?t.add(r.index):"replace"===r.kind&&(t.add(r.index),n.add(r.index));return{renders:t,replaces:n}}(t),n);return null===r?null:[e,r,n.nextItems]}function Yn(e,t,n){const[r,i,o]=e,s=/* @__PURE__ */new Set;let a=!1;for(const[e,o,l,u,c]of i){let i=o;if(void 0!==l){const e=!(!n.morph||c||null===o)&&an(o,l,{keyAttributes:[Gn,Kn],retainChildrenOf:Xn,...void 0!==n.onDuplicateKey?{onDuplicateKey:n.onDuplicateKey}:{}})===o;if(!e)for(const[e,t]of u)null!==e&&(nr(e,t),t.replaceWith(e));for(const[,,e]of u)void 0!==e&&Yn(e,t,n);e?a=!0:(null!==o&&(o.replaceWith(l),a=!0),i=l)}if(null===i)continue;const d=r.children[e]??null;i!==d&&(r.insertBefore(i,d),a=!0),s.add(i)}for(const e of Array.from(r.children))s.has(e)||(e.remove(),a=!0);const l=function(e,t){let n=t.get(e);return n||(n=/* @__PURE__ */new Map,t.set(e,n)),n}(r,t);l.clear();for(const e of o)ir(l,e);return a}function er(e,t,n,r,i){const o=sr(null===e?[]:tr(e),Kn),s=[];for(const e of tr(t)){const t=e.getAttribute(Kn);if(null===t)continue;const a=ar(o,t)??null,l=e.getAttribute(Jn),u=l?a:null,c=u?.getAttribute(Jn)??null;let d;if(l){const o=rr(n,t);if(void 0!==o||null!==u){const n=o??[],s=x(null===u?[]:rr(r,t)??[],n),a=null!==u&&c!==l;if((s.length>0||a)&&(d=Zn(u??e,s,{template:l,nextItems:n,forceRender:a,store:i.store,sanitizerPolicy:i.sanitizerPolicy})??void 0,void 0===d))return null}}s.push([u,e,d])}return s}function tr(e){return Array.from(e.querySelectorAll(`[${Kn}]`)).filter(t=>{let n=t.parentElement;for(;null!==n&&n!==e;){if(n.hasAttribute(Kn))return!1;n=n.parentElement}return n===e})}function nr(e,t){for(const n of Array.from(e.attributes))t.hasAttribute(n.name)||e.removeAttribute(n.name);for(const n of Array.from(t.attributes))e.getAttribute(n.name)!==n.value&&e.setAttribute(n.name,n.value)}function rr(e,t){if("object"!=typeof e||null===e)return;const n=e[t];return Array.isArray(n)?n:void 0}function ir(e,t){const n=or(t);void 0!==n&&e.set(n,t)}function or(e){if("object"!=typeof e||null===e)return;const t=e.id;return"string"==typeof t||"number"==typeof t?String(t):void 0}function sr(e,t){const n=/* @__PURE__ */new Map;for(let r=e.length-1;r>=0;r-=1){const i=e[r];if(void 0===i)continue;const o=i.getAttribute(t);if(null===o)continue;const s=n.get(o);void 0===s?n.set(o,[i]):s.push(i)}return n}function ar(e,t){return e.get(t)?.pop()}function lr(e,t,n,r,i,o,s){const a=Tn(En(t,n,r,_n,s),i,Vn(t)),l=e.createElement("template");l.innerHTML=nn(a);const u=l.content.firstElementChild;if(!u)return null;On(u,o);const c=or(n);return void 0!==c&&u.setAttribute(Gn,c),u}function ur(e,t,n){t.warnedFragmentFallback||(t.warnedFragmentFallback=!0,e.warn(`[live-preview] LP0806: "${n.fieldName}" asks for the fragment strategy but no handler is configured; patching instead`))}function cr(e,t,n){t.warnedStrategy.has(n.element)||(t.warnedStrategy.add(n.element),e.warn(`[live-preview] LP0407: "${n.fieldName}" asks for strategy "${String(n.strategy)}"; only patch, fragment and route exist`))}var dr=class{constructor(e,t,n){this.deps=e,this.state=t,this.host=n}deps;state;host;planFragments(e){const t=this.deps.strategies.fragment;return void 0===t?null:hr(t,t.plan(this.deps.root,e))}escalateUnfaithful(e,t,n){if(e.routeRefreshed)return;const{fragment:r,route:i}=this.deps.strategies,o=void 0===r?void 0:function(e){const t=[];for(const n of e){const e=n.fragmentBoundary;if(void 0===e)return;t.includes(e)||t.push(e)}return t}(n);if(void 0!==r&&void 0!==o)return this.state.escalatedCount+=n.length,e.pendingFragments+=o.length,void this.runFragments(e,t,hr(r,o));void 0!==i?(this.state.escalatedCount+=n.length,this.refreshRoute(e,t,i)):this.warnEscalationUnavailable(n.length)}warnEscalationUnavailable(e){const{deps:t,state:n}=this;n.warnedEscalationUnavailable||(n.warnedEscalationUnavailable=!0,t.warn(`[live-preview] LP0808: onUnfaithfulPatch: 'escalate' has nowhere to go: ${String(e)} field(s) fell short and no route or fragment strategy is configured. Set routeStrategy: true or fragments: { endpoint }, or onUnfaithfulPatch: 'warn' to keep the patch and say so.`))}hasUnboundChange(e,t){const{deps:n,state:r}=this;if(e.baseline||e.routeRefreshed)return!1;const i=de(n.cache,e.touched,e.locale,t);let o=0;for(const e of i)q(r,e)&&(o+=1);const[s]=i;return void 0!==s&&"escalate"===n.onUnfaithfulPatch&&(void 0===n.strategies.route?(this.warnEscalationUnavailable(i.length),!1):(n.log("route","LP0807",`field "${s}" has no binding; refreshing the route`),r.escalatedCount+=o,!0))}hasRouteBinding(e){for(const[t,n]of this.deps.cache.entries())if(e.has(t)&&n.some(e=>"route"===e.strategyKind))return!0;return!1}async runFragments(e,t,n){const{deps:r,state:i}=this,o=new AbortController;i.fragmentController=o;const s=()=>i.isCurrent(e)&&!o.signal.aborted,{emitter:a}=r,{message:l}=e,u=e.revision.revision,c=e.receivedAt,d={root:r.root,revision:u,receivedAt:c,fields:t.fields,locale:e.locale,collectionSlug:"string"==typeof l.collectionSlug?l.collectionSlug:void 0,globalSlug:"string"==typeof l.globalSlug?l.globalSlug:void 0,signal:o.signal,isCurrent:s,log:(e,t)=>{r.log("fragment",e,t)},morph:(e,t)=>{!function(e,t){const n=e.ownerDocument.createElement("template");n.innerHTML=nn(t);const r=e.cloneNode(!1);r.append(n.content),an(e,r,{keyAttributes:[Gn]})}(e,t)},patch:n=>{this.patchFallback(e,t,n)},rendered:(t,n,r)=>{e.pendingFragments-=1,a.emitWhile("fragmentRender",{element:t,id:n,key:r,status:"rendered",revision:u,receivedAt:c},s)},failed:(t,n,i,o,l)=>{e.pendingFragments-=1;const d=`fragment "${n}" fell back to patch: ${l}`;r.log("fragment",o,d),a.emitWhile("error",{error:new Error(d),context:"fragment",code:o},s),a.emitWhile("fragmentRender",{element:t,id:n,key:i,status:"failed",code:o,revision:u,receivedAt:c},s)}};let h={rendered:0,failed:0,superseded:0};try{h=await n.strategy.render(d,n.boundaries)}catch(i){if(r.log("fragment","LP0801",i),s()){for(const r of n.boundaries)this.patchFallback(e,t,r);h={rendered:0,failed:n.boundaries.length,superseded:0}}}i.fragmentStats.rendered+=h.rendered,i.fragmentStats.failed+=h.failed,i.fragmentStats.superseded+=h.superseded,s()&&(i.fragmentController===o&&(i.fragmentController=null),e.pendingFragments=0,h.rendered>0&&this.host.restoreGuesses(e,t),0===r.scheduler.pendingCount&&i.complete(e),this.host.revealPending(e),s()&&0!==h.rendered&&0!==a.listenerCount("afterUpdate")&&a.emitWhile("afterUpdate",{data:t,updatedCount:h.rendered,durationMs:Date.now()-c,revision:u,receivedAt:c,source:"fragment"},s))}async refreshRoute(e,t,n){const{deps:r,state:i}=this;if(e.routeRefreshed)return i.routeStats.loopStopped+=1,void r.log("route","LP0805",`revision ${String(e.revision.revision)} asked for a second refresh`);e.routeRefreshed=!0,await this.runRoute(e,t,n)}armRouteRetry(e,t,n,r){const{state:i}=this;null!==i.routeRetry&&clearTimeout(i.routeRetry),i.routeRetry=setTimeout(()=>{i.routeRetry=null,i.isCurrent(e)&&this.runRoute(e,t,n)},r)}async runRoute(e,t,n){const{deps:r,state:i}=this,o=i.routeStats,s=new AbortController;i.routeController=s;const a=()=>i.isCurrent(e)&&!s.signal.aborted;let l;try{l=await n.refresh({revision:e.revision.revision,receivedAt:e.receivedAt,signal:s.signal,isCurrent:a,log:(e,t)=>{r.log("route",e,t)},retryAfter:r=>{this.armRouteRetry(e,t,n,r)}})}catch(e){r.log("route","LP0801",e),l="failed"}if(a()){if(i.routeController===s&&(i.routeController=null),"refreshed"===l){if(o.refreshes+=1,i.lastAppliedIdentity=/* @__PURE__ */new WeakMap,this.host.restoreGuesses(e,t),this.host.rebuildCache(),!a())return;return this.host.reapply(e,t),void(r.emitter.listenerCount("afterUpdate")>0&&r.emitter.emitWhile("afterUpdate",{data:t,updatedCount:r.cache.elementCount,durationMs:Date.now()-e.receivedAt,revision:e.revision.revision,receivedAt:e.receivedAt,source:"route"},a))}"failed"===l?o.failed+=1:"refused"===l&&(o.refused+=1),this.host.reapply(e,t)}}warnFragmentFallback(e){ur(this.deps,this.state,e)}warnUnsupportedStrategy(e){cr(this.deps,this.state,e)}patchFallback(e,t,n){for(const[r,i]of this.deps.cache.entries())for(const o of i){if(o.fragmentBoundary!==n)continue;const i=Qt(t.fields,o,r,e.locale);void 0!==i&&this.deps.scheduler.schedule({target:o,value:this.host.transform(o,i,t.fields,()=>!0),allFields:t.fields,revision:e.revision,data:t})}}};function hr(e,t){const n=new Set(t);return{boundaries:t,strategy:e,covers:e=>void 0!==e.fragmentBoundary&&n.has(e.fragmentBoundary)}}function fr(e,t,n,r,i){const o=e.transformValue;if(void 0===o)return n;try{const e=o(t.fieldName,n,{element:t.element,allFields:r},i),s=h(e);if(!i())return n;if(s)throw new TypeError(`Transform for "${t.fieldName}" returned a thenable; transforms must be synchronous`);return e}catch(t){if(!i())return n;const r=t instanceof Error?t:new Error(String(t));return e.emitter.emit("error",{error:r,context:"transform",code:"LP0602"}),n}}var pr=/* @__PURE__ */new Set,mr=class{constructor(e,t,n){this.deps=e,this.state=t,this.strategies="undefined"!=typeof __LEAN_BUILD__&&__LEAN_BUILD__?function(e,t){return{planFragments:()=>null,escalateUnfaithful:()=>{},hasUnboundChange:(n,r)=>{if(n.baseline)return!1;const i=de(e.cache,n.touched,n.locale,r);for(const e of i)q(t,e);return!1},hasRouteBinding:()=>!1,runFragments:()=>Promise.resolve(),refreshRoute:()=>(k("route refreshes"),Promise.resolve()),warnFragmentFallback:n=>{k("server-rendered fragments"),ur(e,t,n)},warnUnsupportedStrategy:n=>{cr(e,t,n)}}}(e,t):new dr(e,t,{reapply:(e,t)=>{this.scheduleAllFields(e,t)},transform:(t,n,r,i)=>fr(e,t,n,r,i),rebuildCache:n,restoreGuesses:(e,t)=>{this.restoreGuesses(e,t)},revealPending:e=>{this.revealPending(e)}})}deps;state;strategies;handleUpdate(e,t,n){const{deps:r,state:i}=this;if(r.heartbeat.kick(),i.protocol.observe(function(e){const t=[];return Array.isArray(e.fieldSchemaJSON)&&t.push("schema-json"),"string"==typeof e.locale&&t.push("locale"),"string"==typeof e.previewToken&&t.push("preview-token"),"object"==typeof e.externallyUpdatedRelationship&&null!==e.externallyUpdatedRelationship&&t.push("relationship-events"),t}(e),r.log),void 0===e.data)return void(void 0!==e.protocolVersion&&i.protocol.applyVersion(e.protocolVersion,r.log));if(void 0===n)return;const o=i.relationships.edit(e);null!==o&&r.emitter.emit("relationshipUpdate",{detail:o,timestamp:Date.now()}),"string"==typeof e.locale&&(i.locale=e.locale),Array.isArray(e.fieldSchemaJSON)&&(i.schema=e.fieldSchemaJSON,i.schemaIndex=R(e.fieldSchemaJSON));const s={revision:n,message:e,locale:i.locale,schema:i.schema,schemaIndex:i.schemaIndex,receivedAt:Date.now(),forceRender:null!==o||we(i.activeUpdate),touched:/* @__PURE__ */new Set,baseline:!1,invalidated:/* @__PURE__ */new Set,revealTarget:void 0,revealIdentities:[],pendingFragments:0,routeRefreshed:!1,cancelled:!1,completed:!1},a=i.activeUpdate;if(i.abortStrategies(),null===a||a.completed||(i.supersededCount+=1),i.activeUpdate=s,r.scheduler.acceptRevision(n),i.updateCount+=1,void 0===e.protocolVersion||(i.protocol.applyVersion(e.protocolVersion,r.log),i.isCurrent(s))){if(r.connection.markConnected()){if(r.a11y?.announceConnected(),r.emitter.emit("connect",{origin:t,timestamp:Date.now()}),!i.isCurrent(s))return;if(r.log("connection","disconnected","→","connected"),!i.isCurrent(s))return}this.processUpdate(s).catch(e=>{r.log("update failed:",e)})}}async processUpdate(e){const{deps:t,state:n}=this,r=await this.resolveIncomingFields(e);if(null===r||!n.isCurrent(e))return;const i=this.dataFor(e,r);t.emitter.listenerCount("beforeUpdate")>0&&(!await t.emitter.emitWhile("beforeUpdate",{data:i,revision:e.revision.revision,receivedAt:e.receivedAt,source:"patch",cancel:()=>{e.cancelled=!0,t.scheduler.cancelRevision(e.revision)}},()=>!e.cancelled&&n.isCurrent(e))||e.cancelled||!n.isCurrent(e))||this.applyFields(e,i,!1)}dataFor(e,t){const{message:n}=e;return{fields:t,...void 0!==e.schema?{schema:e.schema}:{},..."string"==typeof n.globalSlug?{globalSlug:n.globalSlug}:{},..."string"==typeof n.collectionSlug?{collectionSlug:n.collectionSlug}:{},...void 0!==e.locale?{locale:e.locale}:{}}}applyFields(e,t,n){const{deps:r,state:i}=this,o=Re(r.dependencies,r.cache.dependencyMap()),s=i.changes.diff(t.fields,o);if(s.baseline&&!n&&"off"!==r.autoBind)if("undefined"!=typeof __LEAN_BUILD__&&__LEAN_BUILD__)k("auto-binding");else{const n=this.ownerKeysForUpdate(e,t.fields);!function(e,t,n,r,i){const o=performance.now(),s=qt(e.root),a=Ot(n,r),l=null===s?[]:Vt(e,Wt(s,a),i,"on the first message");t.autoBindGuesses=function(e,t){const n=/* @__PURE__ */new Set;for(const{fieldName:e,stamps:r}of t){n.add(e);for(const e of[Ie,_e]){const t=r[e];void 0!==t&&n.add(t)}}const r=/* @__PURE__ */new Map;for(const[t,i]of e)null!==i&&n.has(i.field)&&r.set(t,i);return{fields:n,values:r}}(a,l),t.autoBindSearchMs=performance.now()-o,l.length}(r,i,t.fields,e.locale,n)}e.baseline=s.baseline,e.invalidated=n?pr:s.invalidated,e.touched=n?pr:/* @__PURE__ */new Set([...s.changed,...s.invalidated]),this.scheduleAllFields(e,t)}async resolveIncomingFields(e){const{deps:t,state:n}=this,r=e.message.data??{};if(null===t.merger)return r;if("admin"===detectProtocolProfile(n.protocol.observed).populatesRelationships)return r;const i=n.merges.decide(t,e);if(!i.merge)return i.fields;const{message:o}=e,s=n.merges.request(t.merger,t.mergeWindowMs,{collectionSlug:o.collectionSlug,globalSlug:o.globalSlug,data:r,locale:e.locale});if(!s.leading)return this.applyMerged(e,s.result).catch(e=>{t.log("update failed:",e)}),i.fields;const a=await s.result;return n.isCurrent(e)?"merged"===a.status?(n.merges.recordMerged(a.doc),a.doc):"superseded"===a.status?null:i.fields:null}async applyMerged(e,t){const{state:n}=this,r=await t;"merged"===r.status&&n.isCurrent(e)&&(n.merges.recordMerged(r.doc),this.applyFields(e,this.dataFor(e,r.doc),!0))}scheduleAllFields(e,t){const{deps:n,state:r}=this;if(!r.isCurrent(e))return;const i=()=>r.isCurrent(e),o=this.ownerKeysForUpdate(e,t.fields),{touched:s}=e,a=n.strategies.route,l=this.strategies.hasUnboundChange(e,o),u=r.routeRefreshOwed;if(void 0!==a&&!e.routeRefreshed&&(l||u||a.plan(n.root,s)||this.strategies.hasRouteBinding(s)))return r.routeRefreshOwed=!1,void this.strategies.refreshRoute(e,t,a);const c=this.strategies.planFragments(s),d=n.skipUnchanged;let h=0;for(const[s,a]of n.cache.entries()){if(!i())return;for(const l of a){if(!1!==o&&!ie(l.owner,o))continue;if(!0===c?.covers(l)){if(n.revealEditedField){const n=Qt(t.fields,l,s,e.locale);r.revealLedger.note(e,l,n)}continue}const a=l.strategyKind??te(l.element)??"unknown";if("unknown"===a){this.strategies.warnUnsupportedStrategy(l);continue}"fragment"===a&&null===c&&this.strategies.warnFragmentFallback(l);const u=Qt(t.fields,l,s,e.locale);if(void 0===u){r.absentFields.add(s);continue}if(n.revealEditedField&&r.revealLedger.note(e,l,u),!i())return;const f=fr(n,l,u,t.fields,i);if(!i())return;const p=d?Xt(l,f,t.fields,e.locale):void 0,m=r.lastAppliedIdentity.get(l.element);if(!e.forceRender&&n.skipUnchanged&&void 0!==p&&m===p&&!e.invalidated.has(s)){r.skippedUnchangedCount+=1;continue}const g={target:l,value:f,allFields:t.fields,revision:e.revision,data:t,valueIdentity:p};n.scheduler.schedule(g),h+=1}}(function(e,t,n,r){const{cache:i}=e;if(0===i.fieldCount)return;if(!1!==r&&!function(e,t){for(const n of e.values())if(ie(n.owner,t))return!0;return!1}(i,r))return;const o=ce(i,n,r);for(const[r,i]of Object.entries(t)){if(se.has(r))continue;if(Yt(i)){Zt(e,o,r,n,i);continue}if(!en(i)||o(r))continue;const t=ue(r,n);for(const[r,s]of Object.entries(i))Yt(s)&&!se.has(r)&&Zt(e,o,`${t}.${r}`,n,s)}})({cache:n.cache,warned:r.warnedOrphanFields,warn:n.warn},t.fields,e.locale,o),null!==c&&c.boundaries.length>0&&(e.pendingFragments=c.boundaries.length,this.strategies.runFragments(e,t,c)),0===h&&0===e.pendingFragments&&(r.complete(e),this.revealPending(e),this.notifyIslands(e,t))}notifyIslands(e,t){0!==e.touched.size&&function(e,t){for(const n of e)n.dispatchEvent(new CustomEvent("payload-live-preview:update",{detail:t,bubbles:!1}));e.length}(this.deps.cache.islands,{fields:t.fields,revision:e.revision.revision,receivedAt:e.receivedAt,locale:e.locale})}restoreGuesses(e,t){const{deps:n,state:r}=this;if("off"!==n.autoBind&&null!==r.autoBindGuesses&&("undefined"==typeof __LEAN_BUILD__||!__LEAN_BUILD__)){const i=this.ownerKeysForUpdate(e,t.fields);!function(e,t,n,r,i){const o=t.autoBindGuesses,s=qt(e.root);if(null===o||0===o.fields.size||null===s)return 0;const a=new Map(o.values);for(const[e,t]of Ot(n,r)){if(null===t||!o.fields.has(t.field))continue;const n=a.get(e);void 0===n?a.set(e,t):n?.field!==t.field&&a.set(e,null)}Vt(e,Wt(s,a),i,"after a server render").length}(n,r,t.fields,e.locale,i)}}ownerKeysForUpdate(e,t){const{deps:n,state:r}=this;if(!n.scopeBindingsByOwner)return!1;const{message:i}=e,o=function(e){if(re(e.globalSlug))return[(t=e.globalSlug,`global:${t}`)];var t;if(!re(e.collectionSlug))return null;const n=ne(e.collectionSlug);return re(e.documentId)?[n,ne(e.collectionSlug,e.documentId)]:[n]}({globalSlug:"string"==typeof i.globalSlug?i.globalSlug:void 0,collectionSlug:"string"==typeof i.collectionSlug?i.collectionSlug:void 0,documentId:oe(t)});return null!==o||r.warnedUnattributableMessage||(r.warnedUnattributableMessage=!0,n.warn("[live-preview] LP0202: scopeBindingsByOwner: update names no document; nothing applied")),o}onFlush(e){const{deps:t,state:n}=this;n.lastFlush=e,e.deferred>0&&!n.warnedVisibilityGate&&(n.warnedVisibilityGate=!0,t.warn(`[live-preview] LP0301: visibility gate held ${String(e.deferred)} off-screen update(s) until scrolled into view; see visibilityGateThreshold`));const{revision:r,data:i}=e;if(void 0===r)return;const o=n.activeUpdate;if(null===o||!n.isCurrent(o)||!f(o.revision,r))return;0===o.pendingFragments&&n.complete(o);const s=()=>n.isCurrent(o)&&f(o.revision,r);if(this.revealPending(o),!s())return;const a=n.unfaithfulPatches;a.length>0&&(n.unfaithfulPatches=[],void 0!==i&&this.strategies.escalateUnfaithful(o,i,a),!s())||void 0!==i&&(e.applied>0&&t.a11y?.announceUpdate(e.applied),s()&&(this.notifyIslands(o,i),s()&&0!==e.applied&&0!==t.emitter.listenerCount("afterUpdate")&&t.emitter.emitWhile("afterUpdate",{data:i,updatedCount:e.applied,durationMs:e.durationMs,revision:r.revision,receivedAt:o.receivedAt,source:"patch"},s)))}revealPending(e){const t=this.state.revealLedger.commit(e);if(void 0!==t)try{this.revealBinding(t)}catch(e){this.deps.log("reveal",e)}}revealField(e){const t=this.deps.cache.get(e)?.[0];return void 0===t?"no-element":this.revealBinding(t)}revealBinding(e){const{element:t}=e,n=t.ownerDocument.defaultView;if(null===n)return"no-element";const r=`${e.owner??""} ${e.fieldName}`;return this.state.revealer.reveal(r,t,n)}},gr=class{apply;debounceMs;maxWaitMs;isVisible;gateThresholdValue;gateDisabled;getCacheSize;onFlush;scheduleFrame;cancelFrame;pending=/* @__PURE__ */new Map;replay=/* @__PURE__ */new Map;activeFlushes=/* @__PURE__ */new Set;debounceTimer=null;debounceToken=0;deadlineTimer=null;frameHandle=null;frameToken=0;windowUntil=0;activeRevision=null;activeRevisionCancelled=!1;constructor(e,t){this.apply=e,this.debounceMs=t.debounceMs??50,this.maxWaitMs=t.maxWaitMs??4*this.debounceMs,this.isVisible=t.isVisible,this.gateThresholdValue=t.visibilityGateThreshold??50,this.gateDisabled=t.disableVisibilityGate??!1,this.getCacheSize=t.getCacheSize,this.onFlush=t.onFlush,this.scheduleFrame=t.scheduleFrame??("function"==typeof requestAnimationFrame?requestAnimationFrame.bind(globalThis):e=>setTimeout(()=>{e(performance.now())},0)),this.cancelFrame=t.cancelFrame??("function"==typeof cancelAnimationFrame?cancelAnimationFrame.bind(globalThis):e=>{clearTimeout(e)})}schedule(e){if(void 0!==e.revision){if(this.activeRevisionCancelled)return;if(null===this.activeRevision||!f(e.revision,this.activeRevision))return}const t=this.pending.get(e.target.element);t?(t.value=e.value,t.allFields=e.allFields,t.revision=e.revision,t.data=e.data,t.valueIdentity=e.valueIdentity):this.pending.set(e.target.element,{target:e.target,value:e.value,allFields:e.allFields,revision:e.revision,data:e.data,valueIdentity:e.valueIdentity}),this.armDebounce()}acceptRevision(e){var t,n;null!==this.activeRevision&&f(e,this.activeRevision)||null!==this.activeRevision&&(t=e,n=this.activeRevision,(t.generation!==n.generation?t.generation-n.generation:t.revision-n.revision)<0)||(this.cancelScheduledWork(),this.clearWork(),this.activeRevision=e,this.activeRevisionCancelled=!1)}cancelRevision(e){null!==this.activeRevision&&f(e,this.activeRevision)&&(this.cancelScheduledWork(),this.clearWork(),this.activeRevisionCancelled=!0)}flushNow(){return this.cancelScheduledWork(),this.flush()}notifyVisible(e){const t=this.replay.get(e);if(!t)return;if(this.replay.delete(e),!this.isCurrent(t))return;const n=performance.now(),r=this.didApply(t)?1:0;this.onFlush?.(this.statsFor(t,r,0,performance.now()-n,1===r?[t.target.fieldName]:[]))}retarget(e){this.retargetBuffer(this.pending,e),this.retargetBuffer(this.replay,e);for(const t of this.activeFlushes)this.retargetBuffer(t,e)}forget(e){this.pending.delete(e),this.replay.delete(e);for(const t of this.activeFlushes)t.delete(e)}destroy(){this.cancelScheduledWork(),this.clearWork(),this.activeRevision=null,this.activeRevisionCancelled=!1,this.windowUntil=0}get pendingCount(){return this.pending.size}get replayCount(){return this.replay.size}get gateThreshold(){return this.gateThresholdValue}get gateActive(){return!this.gateDisabled&&this.getCacheSize()>this.gateThresholdValue}armDebounce(){const e=Date.now(),t=e>=this.windowUntil;if(this.windowUntil=e+this.debounceMs,t)return void this.requestFrame();const n=this.debounceToken+=1,r=this.debounceTimer;if(this.debounceTimer=null,null!==r&&clearTimeout(r),this.debounceToken!==n)return;const i=setTimeout(()=>{this.debounceToken===n&&(this.debounceTimer=null,this.pending.size>0&&this.requestFrame())},this.debounceMs);this.debounceToken===n&&(this.debounceTimer=i),null===this.deadlineTimer&&this.maxWaitMs>this.debounceMs&&(this.deadlineTimer=setTimeout(()=>{this.deadlineTimer=null,this.pending.size>0&&this.requestFrame()},this.maxWaitMs))}requestFrame(){const e=this.frameToken+=1,t=this.frameHandle;if(this.frameHandle=null,null!==t&&this.cancelFrame(t),this.frameToken!==e)return;let n=!1;const r=this.scheduleFrame(()=>{this.frameToken===e&&(n=!0,this.frameHandle=null,this.flush())});n||this.frameToken!==e||(this.frameHandle=r)}flush(){const e=performance.now();this.clearDeadline();const t=this.gateActive,n=this.pending;this.pending=/* @__PURE__ */new Map;let r=0;const i=[];let o,s=0;this.activeFlushes.add(n);try{for(const e of n.values()){if(!this.isCurrent(e))continue;const n=!t||this.isVisible(e.target.element);this.isCurrent(e)&&(o??=e,n?(this.replay.delete(e.target.element),this.didApply(e)&&(r+=1,i.push(e.target.fieldName))):(this.replay.set(e.target.element,e),s+=1))}}finally{this.activeFlushes.delete(n)}const a=this.statsFor(o,r,s,performance.now()-e,i);return this.onFlush?.(a),a}isCurrent(e){return void 0===e.revision||!this.activeRevisionCancelled&&null!==this.activeRevision&&f(e.revision,this.activeRevision)}didApply(e){return!1!==this.apply(e)||(t=this.apply,!J.has(t));var t}retargetBuffer(e,t){const n=e.get(t.element);void 0!==n&&(n.target.fieldName===t.fieldName&&n.target.locale===t.locale?n.target=t:e.delete(t.element))}clearWork(){this.pending.clear(),this.replay.clear();for(const e of this.activeFlushes)e.clear()}statsFor(e,t,n,r,i){return{applied:t,appliedFields:i,deferred:n,durationMs:r,...void 0!==e?.revision?{revision:e.revision}:{},...void 0!==e?.data?{data:e.data}:{}}}clearDeadline(){null!==this.deadlineTimer&&(clearTimeout(this.deadlineTimer),this.deadlineTimer=null)}cancelScheduledWork(){const e=this.debounceTimer,t=this.frameHandle;this.debounceToken+=1,this.frameToken+=1,this.debounceTimer=null,this.frameHandle=null,this.clearDeadline(),null!==e&&clearTimeout(e),null!==t&&this.cancelFrame(t)}},vr=[0,500,1e3,2e3],yr=class{deps;state=new Ce;pipeline;writer;rootSentinel=null;observedRoot=null;constructor(e){const{emitter:t,renderers:n}=e,r=void 0===e.log?g:m(e.log),i=void 0===e.warn?y:m(e.warn),o=e.root??("undefined"!=typeof document?document:void 0);if(void 0===o)throw new Error("LivePreviewRuntime: no document; pass options.root");const s=new it({filter:e=>!function isInsideIsland(e){let t=e;for(;null!==t;){if(xe(t))return!0;t=t.parentElement}return!1}(e)}),a=new pt({onStructuralChange:()=>{this.rebuildCache()},onVisibilityChange:(e,t)=>{t&&l.notifyVisible(e)}},void 0!==e.intersectionRootMargin?{intersectionRootMargin:e.intersectionRootMargin}:{}),l=new gr(Q(e=>this.writer.apply(e)),{...void 0!==e.debounceMs?{debounceMs:e.debounceMs}:{},...void 0!==e.disableVisibilityGate?{disableVisibilityGate:e.disableVisibilityGate}:{},...void 0!==e.visibilityGateThreshold?{visibilityGateThreshold:e.visibilityGateThreshold}:{},isVisible:e=>a.isVisible(e),getCacheSize:()=>s.elementCount,onFlush:e=>{this.pipeline.onFlush(e)}}),u=new p(e.originMatcher,{onUpdate:(e,t,n)=>{this.pipeline.handleUpdate(e,t,n)},onDocumentEvent:()=>{this.state.protocol.observe(["document-events"],r),t.emit("documentSave",{timestamp:Date.now()})},onFocusField:e=>{this.deps.revealEditedField&&this.pipeline.revealField(e)},onInvalid:(e,n)=>{if("token"===e){const e=new Error(`Preview token rejected (origin: ${n})`);t.emit("error",{error:e,context:"token",code:"LP0502"})}"shape"!==e&&"type"!==e||this.state.warnedProtocolShape||(this.state.warnedProtocolShape=!0,i(`[live-preview] LP0503: ${n} posted a message this runtime does not recognise (${"type"===e?"unknown message type":"unexpected shape"}); it was ignored. A newer Payload or a custom sender: check that the versions match.`)),"source"!==e||this.state.warnedForeignSource||(this.state.warnedForeignSource=!0,i(`[live-preview] LP0501: a message from ${n} was ignored because it did not come from the window that framed or opened this page. \`eventSourcePolicy\` is 'parent-or-opener' by default since 2.0, where 1.x accepted any window on a trusted origin. Set \`eventSourcePolicy: 'any'\` if the admin posts from elsewhere.`)),r("LP0501 message rejected:",e,n)},...void 0!==e.validateToken?{validateToken:e.validateToken}:{},...void 0!==e.eventSourcePolicy?{sourcePolicy:e.eventSourcePolicy}:{}}),c=e.dataMerge;this.deps={emitter:t,cache:s,observers:a,scheduler:l,bus:u,connection:new Pt,heartbeat:new Nt({...void 0!==e.heartbeatMs?{timeoutMs:e.heartbeatMs}:{},onTimeout:()=>{this.onHeartbeatTimeout()}}),renderers:n,resolveRenderer:e.resolveRenderer??(e=>n[e]),transformValue:e.transformValue,renderRichText:e.renderRichText,sanitizerPolicy:e.sanitizerPolicy,root:o,readyTargets:"function"==typeof e.readyTargets?e.readyTargets:/* @__PURE__ */(e=>()=>e)(e.readyTargets),sendReady:e.sendReady??T,onHeartbeatTimeout:e.onHeartbeatTimeout,log:r,warn:i,a11y:A(e),merger:void 0===c?null:new ut({serverURL:c.serverURL,...void 0!==c.apiRoute?{apiRoute:c.apiRoute}:{},...void 0!==c.depth?{depth:c.depth}:{},...void 0!==c.fetchFn?{fetchFn:c.fetchFn}:{},log:r}),mergeWindowMs:e.debounceMs??50,scopeBindingsByOwner:!0===e.scopeBindingsByOwner,lockedOrigin:e.lockedOrigin??(()=>{}),skipUnchanged:!0===e.skipUnchanged,dependencies:e.dependencies??{},strategies:e.strategies??{},revealEditedField:!0===e.revealEditedField,onUnfaithfulPatch:j(e),autoBind:e.autoBind??"off",hydration:e.hydration},this.writer=new $e(this.deps,this.state),this.pipeline=new mr(this.deps,this.state,()=>{this.rebuildCache()})}start(){const{state:e}=this;if(e.isRunning())return!1;e.started=!0,e.suspended=!1;try{return function(e){"react"===e.hydration?yt():"vue"===e.hydration&&Ct();const{root:t}=e;if(!function(e){return 9===e.nodeType}(t)||"loading"!==t.readyState)return void $t(e);const n=()=>{e.isRunning()&&e.later(()=>{$t(e)})};t.addEventListener("DOMContentLoaded",n,{once:!0}),e.defer(()=>{t.removeEventListener("DOMContentLoaded",n)})}(this.startupHost()),!0}catch(e){throw this.rollbackFailedStart(),e}}startupHost(){const{state:e,deps:t}=this;return{root:t.root,hydration:t.hydration,isRunning:()=>e.isRunning(),defer:t=>{e.deferredStart=t},later:t=>{e.deferredStart=null;try{t()}catch(e){this.rollbackFailedStart(),this.reportError(e,"startup","LP0605")}},hydrated:t=>{e.hydration=t},warn:t.warn,startNow:()=>{this.startNow()}}}startNow(){const{state:e,deps:t}=this;if(!e.isRunning())return;const n=br(t.root)?wr(t.root):t.root;if(null===n)throw new Error("LivePreviewRuntime: document.body unavailable");if(t.observers.start(n),this.observedRoot=n,this.watchRootReplacement(),this.buildCacheAndObserve(),e.isRunning()&&(t.bus.attach(),t.emitter.emitWhile("init",{timestamp:Date.now()},()=>e.isRunning()),e.isRunning()))for(const n of vr){if(!e.isRunning())return;0===n?t.sendReady(t.readyTargets()):e.readyTimers.push(setTimeout(()=>{e.isRunning()&&this.sendReadyAfterStart()},n))}}suspend(){if(!this.state.isRunning())return!1;const e=this.release();return this.state.suspended=!0,e&&this.deps.emitter.emit("disconnect",{reason:"unload",timestamp:Date.now()}),!0}destroy(){const{state:e,deps:t}=this;if(!e.isRunning()&&!e.suspended)return;const n=!!e.isRunning()&&this.release();e.suspended=!1,n&&t.emitter.emit("disconnect",{reason:"destroy",timestamp:Date.now()}),t.a11y?.detach(),t.emitter.emit("destroy",{timestamp:Date.now()})}release(){const{state:e,deps:t}=this;e.activeUpdate=null,e.started=!1;const n=e.deferredStart;e.deferredStart=null,null!==n&&this.runCleanup(n);for(const t of e.readyTimers)this.runCleanup(()=>{clearTimeout(t)});return e.readyTimers.length=0,this.runCleanup(()=>{t.heartbeat.stop()}),this.runCleanup(()=>{t.bus.detach()}),e.abortStrategies(),this.runCleanup(()=>{this.rootSentinel?.disconnect(),this.rootSentinel=null,this.observedRoot=null}),this.runCleanup(()=>{t.observers.stop()}),this.runCleanup(()=>{t.scheduler.destroy()}),this.runCleanup(()=>{t.merger?.destroy(),e.merges.destroy()}),t.cache.clear(),t.connection.markDisconnected()}rollbackFailedStart(){this.release(),this.runCleanup(()=>{this.deps.a11y?.detach()})}runCleanup(e){try{e()}catch(e){this.deps.log("cleanup failed:",e)}}refreshCache(){this.state.isRunning()&&(this.state.revealer.reset(),this.followReplacedRoot()||this.rebuildCache())}watchRootReplacement(){const{root:e}=this.deps;br(e)&&"undefined"!=typeof MutationObserver&&(this.rootSentinel?.disconnect(),this.rootSentinel=new MutationObserver(()=>{this.followReplacedRoot()}),this.rootSentinel.observe(e.documentElement,{childList:!0}))}followReplacedRoot(){const{root:e}=this.deps;if(!this.state.isRunning()||!br(e))return!1;const t=wr(e);return null!==t&&t!==this.observedRoot&&(this.observedRoot=t,this.deps.observers.start(t),this.rebuildCache(),!0)}get status(){return this.deps.connection.status}get cache(){return this.deps.cache}get updateCount(){return this.state.updateCount}get protocol(){return this.state.protocol.negotiation}inspect(){return function(e,t){const{cache:n,scheduler:r}=e,i=t.protocol.negotiation,o=t.activeUpdate,s=t.lastFlush,a=[],l=/* @__PURE__ */new Set,u=[];for(const[e,t]of n.entries()){a.push(e);for(const n of t)void 0!==n.owner&&l.add(n.owner),void 0!==n.guessed&&u.push({field:e,matched:n.guessed,attribute:n.targetAttribute??("IMG"===n.element.tagName?"src":void 0)})}return{version:ct,started:t.started,status:e.connection.status,origins:{trusted:[...e.readyTargets()],locked:e.lockedOrigin()},protocol:{ours:i.ours,theirs:i.theirs,negotiated:i.negotiated,capabilities:[...i.capabilities].sort(),observed:[...i.observed].sort(),profile:detectProtocolProfile(i.observed).name},revisions:{accepted:t.updateCount,superseded:t.supersededCount,completed:t.completedCount,skippedUnchanged:t.skippedUnchangedCount,active:null===o?void 0:o.revision.revision},bindings:{elements:n.elementCount,fields:n.fieldCount,fieldNames:a.sort(),absentFields:[...t.absentFields].sort(),orphanFields:[...t.warnedOrphanFields].sort(),ownerScoped:e.scopeBindingsByOwner,owners:[...l].sort(),guessed:u.sort((e,t)=>e.field.localeCompare(t.field)),autoBind:{mode:e.autoBind,searchMs:t.autoBindSearchMs}},route:{handler:void 0!==e.strategies.route,...t.routeStats},fidelity:{mode:e.onUnfaithfulPatch,canEscalate:void 0!==e.strategies.fragment||void 0!==e.strategies.route,unfaithful:t.unfaithfulCount,escalated:t.escalatedCount,fields:[...t.unfaithfulFields].sort()},hydration:{mode:e.hydration??"off",state:t.hydration},fragments:{handler:void 0!==e.strategies.fragment,inFlight:o?.pendingFragments??0,...t.fragmentStats},scheduler:{pending:r.pendingCount,deferred:r.replayCount,visibilityGateThreshold:r.gateThreshold,visibilityGateActive:r.gateActive,lastFlush:null===s?void 0:{applied:s.applied,appliedFields:s.appliedFields,deferred:s.deferred,durationMs:s.durationMs}},plugins:[],renderers:Object.keys(e.renderers).sort()}}(this.deps,this.state)}buildCacheAndObserve(){const{state:e,deps:t}=this;if(!e.isRunning())return;const n=t.cache.buildFromRoot(t.root);if(t.log("cache",n),e.isRunning()&&(t.emitter.emitWhile("cacheRefresh",n,()=>e.isRunning()),e.isRunning()))for(const n of t.cache.values()){if(!e.isRunning())return;t.observers.observeElement(n.element)}}rebuildCache(){const{state:e,deps:t}=this;if(!e.isRunning())return;const n=/* @__PURE__ */new Map;for(const e of t.cache.values())n.set(e.element,e),t.observers.unobserveElement(e.element);if(this.buildCacheAndObserve(),e.isRunning()){for(const e of t.cache.values()){const r=n.get(e.element);r?.fieldName===e.fieldName?t.scheduler.retarget(e):t.scheduler.forget(e.element),n.delete(e.element)}for(const e of n.values())t.scheduler.forget(e.element)}}onHeartbeatTimeout(){const{state:e,deps:t}=this;if(!e.isRunning())return;t.bus.advanceGeneration();const n=e.activeUpdate;e.activeUpdate=null,null!==n&&t.scheduler.cancelRevision(n.revision),t.merger?.destroy(),e.merges.destroy();const r=t.connection.markDisconnected();try{t.onHeartbeatTimeout?.()}catch(e){t.log("heartbeat:",e)}if(e.isRunning()){if(r&&this.isIdleDisconnected()){if(t.a11y?.announceDisconnected(),t.emitter.emitWhile("disconnect",{reason:"timeout",timestamp:Date.now()},()=>this.isIdleDisconnected()),!e.isRunning())return;if(this.isIdleDisconnected()&&t.log("connection","connected","→","disconnected"),!e.isRunning())return}this.sendReadyAfterStart()}}sendReadyAfterStart(){try{this.deps.sendReady(this.deps.readyTargets())}catch(e){this.reportError(e,"ready","LP0606")}}reportError(e,t,n){const r=e instanceof Error?e:new Error(String(e));this.deps.emitter.emit("error",{error:r,context:t,code:n})}isIdleDisconnected(){return this.state.isRunning()&&"disconnected"===this.deps.connection.status&&null===this.state.activeUpdate}};function br(e){return 9===e.nodeType}function wr(e){return e.body}var EventEmitter=class{#t=/* @__PURE__ */new Map;#n=/* @__PURE__ */new Map;on(e,t){return this.#r(this.#t,e,t)}once(e,t){return this.#r(this.#n,e,t)}off(e,t){this.#i(this.#t,e,t),this.#i(this.#n,e,t)}async emit(e,t){await this.#o(e,t)}async emitWhile(e,t,n){return this.#o(e,t,n)}async#o(e,t,n){const r=()=>n?.()??!0;if(!r())return!1;const i=this.#t.get(e);if(i)for(const n of[...i]){if(!r())return!1;if(await this.#s(n,t,e),!r())return!1}if(!r())return!1;const o=this.#n.get(e);if(o&&o.size>0){const n=[...o];this.#n.delete(e);for(const i of n){if(!r())return!1;if(await this.#s(i,t,e),!r())return!1}}return r()}listenerCount(e){return(this.#t.get(e)?.size??0)+(this.#n.get(e)?.size??0)}removeAllListeners(e){if(void 0===e)return this.#t.clear(),void this.#n.clear();this.#t.delete(e),this.#n.delete(e)}eventNames(){const e=/* @__PURE__ */new Set;for(const t of this.#t.keys())e.add(t);for(const t of this.#n.keys())e.add(t);return[...e]}#r(e,t,n){let r=e.get(t);return r||(r=/* @__PURE__ */new Set,e.set(t,r)),r.add(n),()=>{this.#i(e,t,n)}}#i(e,t,n){const r=e.get(t);void 0!==r&&(r.delete(n),0===r.size&&e.delete(t))}async#s(e,t,n){try{await e(t)}catch(e){const t="string"==typeof n||"number"==typeof n?String(n):"<event>";v(`[live-preview] LP0601: handler for "${t}" threw:`,e)}}};function isInIframe(){if("undefined"==typeof window)return!1;try{return window.self!==window.top}catch{return!0}}function isDevMode(){const e=function(){if("undefined"==typeof process)return;const e=process.env.NODE_ENV;return"string"==typeof e?e:void 0}();if(void 0!==e)return"production"!==e;if("undefined"!=typeof window){const e=window.location.hostname;return"localhost"===e||"127.0.0.1"===e}return!1}var Sr=/^https?:\/\/(localhost|127\.0\.0\.1)(?::\d+)?$/i,kr=/^https?:\/\/[^/?#\s]+$/i,Ar=[3e3,3001,3333,4e3,4321,5e3,5173,5174,8e3,8080,8888,9e3],OriginDetector=class{#a;constructor(e={}){const t=/* @__PURE__ */new Set;for(const n of e.additionalOrigins??[]){const e=Tr(n);void 0!==e&&t.add(e)}let n;if(e.enableReferrerDetection??1){const t=e.referrer??("undefined"!=typeof document?document.referrer:"");if(t.length>0)try{const e=new URL(t).origin;e&&"null"!==e&&(n=e)}catch{}}const r=(e.enableLocalhostMatching??!0)&&(e.forceDevMode??isDevMode());this.#a=[t,n,r,void 0!==n,void 0]}matches(e){return 0!==e.length&&"null"!==e&&(void 0!==this.#a[4]?e===this.#a[4]:!!this.#a[0].has(e)||0===this.#a[0].size&&void 0!==this.#a[1]&&e===this.#a[1]||!(!this.#a[2]||!Sr.test(e)))}lockOrigin(e){return!!this.matches(e)&&(this.#a[4]=e,!0)}unlockOrigin(){const e=this.#a[4];return this.#a[4]=void 0,e}get lockedOrigin(){return this.#a[4]}enumerate(){if(void 0!==this.#a[4])return[this.#a[4]];const e=new Set(this.#a[0]);if(0===this.#a[0].size&&void 0!==this.#a[1]&&e.add(this.#a[1]),this.#a[2])for(const t of Ar)e.add(`http://localhost:${String(t)}`),e.add(`http://127.0.0.1:${String(t)}`);return[...e]}get referrerWasAvailable(){return this.#a[3]}get isProductionUnconfigured(){return!(!isInIframe()||this.#a[0].size>0||this.#a[2]||void 0!==this.#a[1])}get isReferrerOnlyTrust(){return!(this.#a[0].size>0||this.#a[2]||void 0===this.#a[1])}};function Tr(e){const t=e.trim();if(0!==t.length)try{const e=new URL(t);if("http:"!==e.protocol&&"https:"!==e.protocol)return;if(!kr.test(e.origin))return;return e.origin}catch{return}}var Cr=()=>{},$r=class{#l;#u;#c=/* @__PURE__ */new Set;#a="staging";constructor(e,t){this.#l=e,this.#u=t}assertOpen(){if("closed"===this.#a)throw new Error(`Plugin context for "${this.#l}" is no longer active`)}get active(){return"active"===this.#a}eligible(){return"closed"!==this.#a}own(e){return this.assertOpen(),this.#d({kind:"cleanup",acquire:void 0,finalize:void 0,cleanup:e,disposed:!1})}stage(e,t,n){this.assertOpen();const r={kind:e,acquire:t,finalize:n,cleanup:void 0,disposed:!1},i=this.#d(r);if("active"===this.#a)try{this.#h(r)}catch(e){throw this.#f(r),e}return i}counts(){const e={transform:0,renderer:0,subscription:0,cleanup:0};for(const t of this.#c)e[t.kind]+=1;return e}commit(){if("staging"!==this.#a)throw new Error(`Plugin context for "${this.#l}" cannot be committed`);this.#a="committing";try{for(const e of this.#c)this.#h(e);this.#a="active"}catch(e){throw this.close(),e}}close(){if("closed"!==this.#a){this.#a="closed";for(const e of[...this.#c].reverse())this.#f(e);this.#c.clear()}}#d(e){return this.#c.add(e),()=>{this.#f(e)}}#h(e){if(e.disposed||void 0!==e.cleanup||void 0===e.acquire)return;const t=e.acquire();e.cleanup=t??Cr}#f(e){if(e.disposed)return;e.disposed=!0,this.#c.delete(e);const t=e.cleanup;if(e.cleanup=void 0,void 0!==t)try{h(t())&&this.#u(`plugin "${this.#l}" cleanup returned a Promise/thenable; cleanups must be synchronous`)}catch(e){this.#u(`plugin "${this.#l}" cleanup failed:`,e)}try{e.finalize?.()}catch(e){this.#u(`plugin "${this.#l}" cleanup failed:`,e)}}},Rr=class{#p;#m;#g=/* @__PURE__ */new Set;constructor(e,t){this.#p=e,this.#m=t}on(e,t){return this.#v("on",e,t)}once(e,t){return this.#v("once",e,t)}off(e,t){const n=t;for(const t of[...this.#g])t.event===e&&t.handler===n&&t.dispose()}emit(e,t){return this.#m.assertOpen(),this.#p.emit(e,t)}emitWhile(e,t,n){return this.#m.assertOpen(),this.#p.emitWhile(e,t,()=>{if(!this.#m.eligible())return!1;const e=n();return!!this.#m.eligible()&&e})}listenerCount(e){let t=0;for(const n of this.#g)n.event===e&&(t+=1);return t}removeAllListeners(e){for(const t of[...this.#g])void 0!==e&&t.event!==e||t.dispose()}eventNames(){const e=/* @__PURE__ */new Set;for(const t of this.#g)e.add(t.event);return[...e]}#v(e,t,n){this.#m.assertOpen();const r=n,i=[...this.#g].find(n=>n.kind===e&&n.event===t&&n.handler===r);if(void 0!==i)return i.dispose;let o=Cr,s=!0;const a=async t=>{this.#m.active&&s&&("once"===e&&o(),await n(t))},l={kind:e,event:t,handler:r,dispose:Cr};return o=this.#m.stage("subscription",()=>this.#p[e](t,a),()=>{s=!1,this.#g.delete(l)}),l.dispose=o,this.#g.add(l),o}},Nr=class{#p;#y;#b;#w;#u;#S=/* @__PURE__ */new Map;#k=/* @__PURE__ */new Map;#A=/* @__PURE__ */new Map;#T=/* @__PURE__ */new Set;#C=/* @__PURE__ */new Map;#$=Promise.resolve();#R=0;constructor(e){this.#p=e.events,this.#y=e.config,this.#b=e.registerFieldRenderer,this.#u=m(e.log);const t=e.onTransformError;this.#w=void 0===t?void 0:m((...e)=>{const n=e[0];try{return t(n)}catch(e){return void this.#u("transform error reporter failed:",e)}})}register(e){return this.#R>0?this.#N(e,!1):this.#P(()=>this.#N(e,!0))}unregister(e){return this.#R>0?this.#L(e,!1):this.#P(async()=>{await this.#L(e,!0)})}destroyAll(){return this.#R>0?this.#F(!1):this.#P(async()=>{await this.#F(!0)})}applyTransforms(e,t,n,r){const i=this.#C.get(e);if(void 0===i||0===i.length)return t;let o=t;for(const s of[...i]){if(!s.active)continue;const{transform:i}=s;if(!1===r?.())return t;try{o=i(o,{fieldName:e,element:n.element,allFields:n.allFields});const s=h(o);if(!1===r?.())return t;if(s)throw new TypeError(`Transform for "${e}" returned a Promise/thenable; transforms must be synchronous`)}catch(n){if(!1===r?.())return t;const i=n instanceof Error?n:new Error(String(n));return this.#u(`transform for "${e}" failed:`,i),this.#w?.(i),t}}return o}list(){return[...this.#S.keys()]}snapshot(){const e=[],t=(e,t,n,r)=>{const i=r.counts();return{name:e,version:t,state:n,registrations:{transforms:i.transform,renderers:i.renderer,subscriptions:i.subscription,cleanups:i.cleanup}}};for(const[n,r]of this.#k)e.push(t(n,void 0,"initializing",r.scope));for(const[n,r]of this.#S)e.push(t(n,r.plugin.version,"active",r.scope));for(const t of this.#A.keys())e.push({name:t,version:void 0,state:"tearing-down",registrations:{transforms:0,renderers:0,subscriptions:0,cleanups:0}});return e}get size(){return this.#S.size}async#N(e,t){if(this.#S.has(e.name)||this.#k.has(e.name)||this.#A.has(e.name))return void this.#u(`plugin "${e.name}" already registered`);const n=function(e,t){if(void 0!==e){if(void 0!==e.runtime&&!function(e,t){const n=function(e){const t=/^v?(\d+)\.(\d+)\.(\d+)/.exec(e.trim());if(null!==t)return[Number(t[1]),Number(t[2]),Number(t[3])]}(e);return void 0!==n&&t.split("||").some(e=>{const r=e.trim().split(/\s+/).filter(e=>e.length>0);return 0===r.length?""===e.trim()&&""===t.trim():r.every(e=>function(e,t){const n=t.trim();if(""===n||"*"===n)return!0;const r=/^(\^|~|>=|<=|>|<|=)?\s*v?(\d+)\.(\d+)\.(\d+)/.exec(n);if(null===r)return!1;const i=r[1]??"=",o=[Number(r[2]),Number(r[3]),Number(r[4])],s=function(e,t){for(let n=0;n<3;n+=1){const r=(e[n]??0)-(t[n]??0);if(0!==r)return r}return 0}(e,o);switch(i){case"=":return 0===s;case">":return s>0;case">=":return s>=0;case"<":return s<0;case"<=":return s<=0;case"~":return s>=0&&e[0]===o[0]&&e[1]===o[1];case"^":return!(s<0)&&(o[0]>0?e[0]===o[0]:o[1]>0?0===e[0]&&e[1]===o[1]:0===e[0]&&0===e[1]&&e[2]===o[2]);default:return!1}}(n,e))})}(t,e.runtime))return`declares runtime ${e.runtime}, this runtime is ${t}`;if(void 0!==e.protocol){if(!Number.isInteger(e.protocol)||e.protocol<1)return`declares an invalid protocol version ${String(e.protocol)}`;if(e.protocol<4)return`declares protocol ${String(e.protocol)}, this runtime speaks ${String(4)}`}}}(e.compat,ct);if(void 0!==n)return void this.#x(e.name,n);const r=new $r(e.name,this.#u),i=this.#U(e.name,r),o={scope:r,cancelled:!1};this.#k.set(e.name,o);try{if(await this.#M(()=>e.init(i),t),o.cancelled)return;r.commit()}catch(t){return r.close(),void(o.cancelled||this.#u(`plugin "${e.name}" init failed:`,t))}finally{this.#k.get(e.name)===o&&this.#k.delete(e.name)}this.#S.set(e.name,{plugin:e,scope:r}),this.#u(`plugin "${e.name}" registered`)}#x(e,t){const n=`plugin "${e}" refused: ${t}`;this.#u(n),this.#p.emit("error",{error:new Error(n),context:"plugin",code:"LP0103"})}#U(e,t){return{events:new Rr(this.#p,t),registerFieldRenderer:e=>{t.stage("renderer",()=>{const t=this.#b(e);return"function"==typeof t?t:void 0})},registerTransform:(e,n)=>{const r={transform:n,active:!1};t.stage("transform",()=>{r.active=!0;const t=this.#C.get(e);return void 0===t?this.#C.set(e,[r]):t.push(r),()=>{r.active=!1;const t=this.#C.get(e);if(void 0===t)return;const n=t.indexOf(r);n>=0&&t.splice(n,1),0===t.length&&this.#C.delete(e)}})},registerCleanup:e=>{t.own(e)},getConfig:()=>this.#y,log:(...t)=>{this.#u(`[${e}]`,...t)}}}#L(e,t){const n=this.#k.get(e);if(void 0!==n)return n.cancelled=!0,n.scope.close(),Promise.resolve();const r=this.#A.get(e);if(void 0!==r)return this.#T.has(e)?Promise.resolve():t?this.#E(r):r;const i=this.#S.get(e);if(void 0===i)return Promise.resolve();this.#S.delete(e),i.scope.close();const o=Promise.resolve().then(()=>this.#I(e,i.plugin,t));return this.#A.set(e,o),o.then(()=>{this.#A.get(e)===o&&this.#A.delete(e)}),o}async#I(e,t,n){if(void 0!==t.destroy){this.#T.add(e);try{await this.#M(()=>t.destroy?.(),n)}catch(t){this.#u(`plugin "${e}" destroy failed:`,t)}finally{this.#T.delete(e)}}}async#F(e){for(const e of this.#k.values())e.cancelled=!0,e.scope.close();const t=[...this.#S.keys()];for(const n of t)await this.#L(n,e)}async#M(e,t){t?await this.#E(Promise.resolve().then(e)):await e()}async#E(e){this.#R+=1;try{await e}finally{this.#R-=1}}#P(e){const t=this.#$.then(e);return this.#$=t.catch(e=>{this.#u("plugin manager mutation failed:",e)}),t}},Pr=class{#O;#_;#D=/* @__PURE__ */new Map;constructor(e){this.#O=e,this.#_={...e}}get renderers(){return this.#_}resolve(e){return this.#_[e]}register(e){const t=e.name,n={renderer:e},r=this.#D.get(t);void 0===r?this.#D.set(t,[n]):r.push(n),this.#_[t]=e;let i=!0;return()=>{if(!i)return;i=!1;const e=this.#D.get(t);if(void 0===e)return;const r=e.indexOf(n);if(r<0)return;const o=r===e.length-1;if(e.splice(r,1),0===e.length&&this.#D.delete(t),!o)return;const s=e.at(-1),a=s?.renderer??this.#O[t];void 0===a?Reflect.deleteProperty(this.#_,t):this.#_[t]=a}}},Lr={1:"left",2:"center",3:"right",4:"justify"},Fr=/* @__PURE__ */new Set(["left","center","right","justify","start","end"]);function xr(e){const t=e.format;return"string"==typeof t&&Fr.has(t)?t:"number"==typeof t?Lr[t]:void 0}function Ur(e){const t=e.indent;return"number"==typeof t&&t>0?t:0}function Mr(e){return"rtl"===e.direction?' dir="rtl"':"ltr"===e.direction?' dir="ltr"':""}function Er(e){const t=xr(e),n=Ur(e),r=[];return void 0!==t&&r.push(`lp-align-${t}`),n>0&&r.push(`lp-indent-${String(n)}`),0===r.length?"":` class="${r.join(" ")}"`}var Ir=/* @__PURE__ */new Set(["h1","h2","h3","h4","h5","h6"]);function Or(e){return"object"==typeof e&&null!==e?e:void 0}function _r(e){return Or(e)}function Dr(e){return e.replace(/[^a-zA-Z0-9_-]/g,"-").toLowerCase()}function zr(e){return"string"==typeof e&&e.length>0?e:void 0}function Br(e){const t=zr(e.title)??zr(e.name)??zr(e.slug);return void 0!==t?t:void 0===e.id?void 0:String(e.id)}var Hr=' target="_blank" rel="noopener noreferrer"',jr=(e,t)=>{const n=t.renderChildren(e.children??[]),r=Or(e.fields),i=function(e,t){if("internal"===t?.linkType)return function(e){const t=Or(Or(e)?.value),n=t?.url;if("string"==typeof n&&n.length>0)return n;const r=t?.slug;return"string"==typeof r&&r.length>0?`/${r}`:void 0}(t.doc);const n=t?.url??e.url;return"string"==typeof n&&n.length>0?n:void 0}(e,r);if(void 0===i||!isSafeUrl(i))return n;const o="string"==typeof e.title?` title="${escapeHtml(e.title)}"`:"";return`<a href="${escapeHtmlAttribute(i)}"${function(e,t,n){if(!0===t?.newTab||isExternalHttpUrl(n))return Hr;const r="string"==typeof e.target?e.target:"";return""===r?"":"_blank"===r?Hr:` target="${escapeHtml(r)}"`}(e,r,i)}${o}>${n}</a>`};function Wr(e){if("string"==typeof e.text)return e.text;if(!e.children)return"";let t="";for(const n of e.children)t+=Wr(n);return t}function qr(e){return`${"number"==typeof e.width?` width="${String(e.width)}"`:""}${"number"==typeof e.height?` height="${String(e.height)}"`:""}`}function Vr(e){return"string"==typeof e.mimeType?` type="${escapeHtmlAttribute(e.mimeType)}"`:""}var Gr=/* @__PURE__ */new Map;function Kr(e){return Gr.get(e)}var Jr=".lp-block:empty,.lp-inline-block:empty";function Qr(e,t,n,r){const i=Or(e.fields)??{},o="string"==typeof i.blockType?i.blockType:"",s=Dr(o),a=""===s?r:`${r} ${r}--${s}`;if(""!==o){const e=Kr(o)??Kr(s);if(e)return e(i,{renderChildren:t.renderChildren});t.onUnrenderedBlock?.(o,a)}return`<${n} class="${a}"></${n}>`}function Xr(e,t){return"number"==typeof t&&t>1?` ${e}="${String(t)}"`:""}var Zr={text:e=>{let t=escapeHtml("string"==typeof e.text?e.text:"");const n="number"==typeof e.format?e.format:0;return!!(16&n)&&(t=`<code>${t}</code>`),!!(1&n)&&(t=`<strong>${t}</strong>`),!!(2&n)&&(t=`<em>${t}</em>`),!!(8&n)&&(t=`<u>${t}</u>`),!!(4&n)&&(t=`<s>${t}</s>`),!!(32&n)&&(t=`<sub>${t}</sub>`),!!(64&n)&&(t=`<sup>${t}</sup>`),!!(128&n)&&(t=`<mark>${t}</mark>`),t},paragraph:(e,t)=>{const n=t.renderChildren(e.children??[]);return`<p${Mr(e)}${Er(e)}>${n}</p>`},heading:(e,t)=>{const n="string"==typeof e.tag?e.tag.toLowerCase():"h2",r=Ir.has(n)?n:"h2",i=t.renderChildren(e.children??[]);return`<${r}${Mr(e)}${Er(e)}>${i}</${r}>`},list:(e,t)=>{const n="string"==typeof e.listType?e.listType:"bullet",r="number"===n?"ol":"ul",i="number"===n&&"number"==typeof e.start&&e.start>1?` start="${String(e.start)}"`:"",o="check"===n?' role="list"':"",s=t.renderChildren(e.children??[]);return`<${r}${Mr(e)}${Er(e)}${i}${o}>${s}</${r}>`},listitem:(e,t)=>{const n=t.renderChildren(e.children??[]);if("boolean"==typeof e.checked)return`<li role="checkbox" aria-checked="${e.checked?"true":"false"}"${Er(e)}>${n}</li>`;const r="number"==typeof e.value?` value="${escapeHtml(String(e.value))}"`:"";return`<li${Mr(e)}${Er(e)}${r}>${n}</li>`},link:jr,autolink:jr,quote:(e,t)=>{const n=t.renderChildren(e.children??[]);return`<blockquote${Mr(e)}${Er(e)}>${n}</blockquote>`},code:e=>{const t=Dr("string"==typeof e.language?e.language:"");return`<pre><code${""===t?"":` class="language-${t}"`}>${escapeHtml(Wr(e))}</code></pre>`},"code-highlight":e=>{const t="string"==typeof e.text?e.text:"";return`<span${"string"==typeof e.highlightType?` class="token-${Dr(e.highlightType)}"`:""}>${escapeHtml(t)}</span>`},linebreak:()=>"<br>",horizontalrule:()=>"<hr>",tab:()=>"\t",upload:e=>{const t=_r(e.value);if(void 0===t)return"";const n=t.url;if("string"!=typeof n||!isSafeUrl(n))return"";const r="string"==typeof t.mimeType?t.mimeType:"";return r.startsWith("video/")?function(e,t){return`<video controls${qr(e)}><source src="${escapeHtmlAttribute(t)}"${Vr(e)}></video>`}(t,n):r.startsWith("audio/")?function(e,t){return`<audio controls><source src="${escapeHtmlAttribute(t)}"${Vr(e)}></audio>`}(t,n):""===r||r.startsWith("image/")?function(e,t){const n="string"==typeof e.alt?escapeHtml(e.alt):"";return`<img src="${escapeHtmlAttribute(t)}" alt="${n}"${qr(e)} loading="lazy" decoding="async">`}(t,n):function(e,t){const n="string"==typeof e.filename?escapeHtml(e.filename):escapeHtml(t);return`<a href="${escapeHtmlAttribute(t)}" target="_blank" rel="noopener noreferrer">${n}</a>`}(t,n)},relationship:e=>{const t="string"==typeof e.relationTo?e.relationTo:"",n=Or(e.value),r=escapeHtml((n&&Br(n))??`#${t}`),i=Dr(t),o=""===i?' class="lp-relation"':` class="lp-relation lp-relation--${i}"`,s=n?.url;return"string"==typeof s&&isSafeUrl(s)?`<a href="${escapeHtmlAttribute(s)}"${o}>${r}</a>`:`<span${o}>${r}</span>`},block:(e,t)=>Qr(e,t,"div","lp-block"),inlineBlock:(e,t)=>Qr(e,t,"span","lp-inline-block"),table:(e,t)=>`<table${Mr(e)}><tbody>${t.renderChildren(e.children??[])}</tbody></table>`,tablerow:(e,t)=>`<tr>${t.renderChildren(e.children??[])}</tr>`,tablecell:(e,t)=>{const n="number"==typeof e.headerState?e.headerState:0,r=3&n?"th":"td";return`<${r}${1===n?' scope="col"':2===n?' scope="row"':""}${Xr("colspan",e.colSpan)}${Xr("rowspan",e.rowSpan)}>${t.renderChildren(e.children??[])}</${r}>`}},Yr=/* @__PURE__ */new Map,ei=!1;function ti(e){if("object"!=typeof e||null===e)return!1;if(!("root"in e))return!1;const t=e.root;return"object"==typeof t&&null!==t&&"children"in t&&Array.isArray(t.children)}function ni(e,t){const n=(r=e.type,Yr.get(r)??Zr[r]);var r;return n?n(e,t):void 0!==e.children?t.renderChildren(e.children):""}function ri(e){if("string"==typeof e.text)return e.text;if("linebreak"===e.type)return"\n";if(void 0===e.children)return"";let t="";for(const n of e.children)t+=ri(n);return t}function ii(e="text"){const t=/* @__PURE__ */new WeakSet;return{name:e,render:/* @__PURE__ */Q((e,n)=>{const r=e.element,i=function(e){return null==e?"":ti(e)?ti(t=e)?t.root.children.map(ri).join("\n").trim():"":"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e?String(e):JSON.stringify(e);var t}(n);if("INPUT"!==r.tagName&&"TEXTAREA"!==r.tagName)return function(e){return null!==e.querySelector(":scope > :not(br)")}(r)&&!r.hasAttribute("data-payload-text")?(function(e,t,n){e.has(t)||(e.add(t),y(`[live-preview] LP0402: Skipping text update for "${n}": <${t.tagName.toLowerCase()}> has structured children. Move data-payload-field to the value element, or add data-payload-text to replace them.`))}(t,r,e.fieldName),!1):void(i.includes("\n")||i.includes("\r")?r.innerHTML=nn(function(e){return escapeHtml(e).replace(/\r\n|\r|\n/g,"<br>")}(i)):r.textContent=i);r.value=i})}}var oi=/* @__PURE__ */new Set,si=/* @__PURE__ */new Set,ai=/* @__PURE__ */new Set(["DIV","SECTION","ARTICLE"]),li={name:"richText",render:/* @__PURE__ */Q((e,t,n)=>{const r=e.element;if(Dn(t))return void(r.textContent="");const i=n.sanitizerPolicy;if(void 0!==n.renderRichText){const o=n.renderRichText(t,{fieldName:e.fieldName,element:r,locale:n.locale});return void(r.innerHTML=nn(Tn(o,i)))}if(ti(t)){const o=/* @__PURE__ */new Map,s=function(e,t){const n=e.cloneNode(!1);n.innerHTML=nn(t);const r=function(e,t){const n=e.firstElementChild;if(null!==n?.nextElementSibling||t.children.length<2)return null;if(!ai.has(n.tagName)||n.hasAttribute(Ue))return null;for(const e of t.children)if(e.tagName===n.tagName&&e.className===n.className)return null;return n}(e,n)??e,i=/* @__PURE__ */new Map,o=n.querySelectorAll(Jr);if(o.length>0&&null!==r.firstElementChild){const e=[];ui(r,n,e);for(const[t,n]of e)t.replaceWith(n),n.matches(Jr)||i.set(t.className,!1);for(const e of o)null!==e.parentNode&&i.set(e.className,!0)}return r.replaceChildren(...n.childNodes),i}(r,Tn(function(e,t={}){if(!ti(e))return"";const n=function(e){const t={renderChildren:e=>{let n="";for(const r of e)n+=ni(r,t);return n},resolveAlignment:xr,resolveIndent:Ur,onUnrenderedBlock:e};return t}(t.onUnrenderedBlock).renderChildren(e.root.children);return!1===t.sanitize?n:void 0!==Cn()?function sanitizeHtml(e,t){return Tn(e,void 0,t)}(n):(function(){if(!ei){ei=!0;try{console.warn('[live-preview] lexicalToHtml() has no sanitizer document and returned unsanitised HTML; call setSanitizerDocument() (linkedom/jsdom) for server rendering, see "HTML sanitization" in docs/security.md.')}catch{}}}(),n)}(t,{sanitize:!1,onUnrenderedBlock:(e,t)=>{o.set(t,e)}}),i));for(const[t,r]of s){const i=o.get(t);void 0!==i&&ci(e,n,i,r)}return}if("string"!=typeof t)return!1;r.innerHTML=nn(Tn(t,i))})};function ui(e,t,n){if(e.children.length!==t.children.length)return;let r=e.firstElementChild,i=t.firstElementChild;for(;null!==r&&null!==i;)i.matches(Jr)?n.push([i,r]):ui(r,i,n),r=r.nextElementSibling,i=i.nextElementSibling}function ci(e,t,n,r){r&&t.reportUnfaithful?.(e,`lost the markup the server drew for block "${n}"`);const i=r?si:oi;i.has(n)||(i.add(n),y(`[live-preview] ${r?`LP0413: no renderer for block "${n}", and the markup the server rendered for it is lost.`:`LP0410: no renderer for block "${n}"; keeping what the server rendered for it.`} Register one with registerBlockRenderer().`))}var di={name:"html",render(e,t,n){if(Dn(t))return void(e.element.textContent="");const r="string"==typeof t?t:_n(t);e.element.innerHTML=nn(Tn(r,n.sanitizerPolicy))}},hi=/* @__PURE__ */new WeakSet;function fi(e,t,n){return"string"!=typeof n||0===n.length?{kind:"none"}:isSafeUrl(n)?{kind:"safe",url:n}:(hi.has(e)||(hi.add(e),y(`[live-preview] LP0401: refused an unsafe URL for "${t}" on <${e.tagName.toLowerCase()}>; the attribute was cleared.`)),{kind:"unsafe"})}function pi(e,t=e=>e){return{name:e,render(e,n,r){const i=e.element;if(Dn(n))return void function(e){"INPUT"!==e.tagName&&"TEXTAREA"!==e.tagName?(e.removeAttribute("href"),e.textContent=""):e.value=""}(i);const o=_n(n);if("INPUT"!==i.tagName&&"TEXTAREA"!==i.tagName){if("A"===i.tagName){const n=e.hrefField,s=void 0===n||0===n.length?t(o):Kt(r.allFields,n,r.locale,void 0!==e.locale),a=fi(i,e.fieldName,s);"safe"===a.kind?i.setAttribute("href",a.url):"unsafe"===a.kind&&i.removeAttribute("href")}i.textContent=o}else i.value=o}}}var mi=pi("url"),gi=/^[a-zA-Z][a-zA-Z0-9+.-]*:/,vi=pi("email",function(e){const t=e.trim();return gi.test(t)||!t.includes("@")?t:`mailto:${t}`}),yi=["src","srcset","sizes"];function bi(e){for(const t of yi)e.removeAttribute(t)}function wi(e,t,n){e.src=t;const r=function(e){if(void 0===e?.sizes)return;const t=[];for(const n of Object.values(e.sizes))"string"==typeof n.url&&"number"==typeof n.width&&isSafeUrl(n.url)&&t.push(`${Si(n.url)} ${String(n.width)}w`);return 0!==t.length?("number"==typeof e.width&&"string"==typeof e.url&&isSafeUrl(e.url)&&t.push(`${Si(e.url)} ${String(e.width)}w`),t.join(", ")):void 0}(n);if(void 0===r)return e.removeAttribute("srcset"),void e.removeAttribute("sizes");e.setAttribute("srcset",r)}function Si(e){return e.replace(/[\s,]/g,encodeURIComponent)}var ki={name:"image",render:/* @__PURE__ */Q((e,t,n)=>{const r=e.element;if(Dn(t))return void Ai(r);const i=void 0!==e.locale,{media:o,candidate:s}=function(e,t,n,r){const i=void 0!==e.srcField&&e.srcField.length>0?Kt(n.allFields,e.srcField,n.locale,r):t,o=_r(i);return{media:o,candidate:void 0===o?i:o.url}}(e,t,n,i),a=fi(r,e.fieldName,s);if("none"===a.kind)return!1;if("unsafe"!==a.kind){if("IMG"===r.tagName){const t=r;wi(t,a.url,o);const s=function(e,t,n,r,i){if(void 0!==t&&t.length>0){const e=Kt(n,t,r,i);return"string"==typeof e?e:void 0}return e?.alt}(o,e.altField,n.allFields,n.locale,i);return void(void 0!==s&&(t.alt=s))}r.style.backgroundImage=`url('${function(e){return e.replace(/['"()\\]/g,"\\$&")}(a.url)}')`}else Ai(r)})};function Ai(e){"IMG"===e.tagName?bi(e):e.style.backgroundImage=""}var Ti={name:"upload",render:/* @__PURE__ */Q((e,t)=>{const n=e.element;if(Dn(t))return void Ci(n);const r=_r(t);if(void 0===r)return!1;const i=fi(n,e.fieldName,r.url);if("none"===i.kind)return!1;if("unsafe"===i.kind)return void Ci(n);const o=i.url;if("IMG"===n.tagName){const e=n;return wi(e,o,r),void(void 0!==r.alt&&(e.alt=r.alt))}if("A"===n.tagName)return n.setAttribute("href",o),void(n.textContent=r.filename??o);const s=escapeHtml(r.filename??o);n.innerHTML=nn(`<a href="${escapeHtmlAttribute(o)}">${s}</a>`)})};function Ci(e){"IMG"!==e.tagName?(e.removeAttribute("href"),e.textContent=""):bi(e)}var $i={name:"relationship",render(e,t){const n=e.element;if(Dn(t))return n.removeAttribute("href"),void(n.textContent="");if("A"===n.tagName&&!Array.isArray(t)){const r=fi(n,e.fieldName,Or(t)?.url);"safe"===r.kind?n.setAttribute("href",r.url):"unsafe"===r.kind&&n.removeAttribute("href")}n.textContent=Array.isArray(t)?t.map(Ri).join(", "):Ri(t)}};function Ri(e){const t=Or(e);return void 0===t?_n(e):Br(t)??""}var Ni={name:"select",render(e,t,n){const r=e.element,i=Dn(t)?[]:function(e){return Array.isArray(e)?e.map(_n):[_n(e)]}(t);if("SELECT"!==r.tagName){if("INPUT"===r.tagName&&"radio"===r.type){const e=r;return void(e.checked=i.includes(e.value))}r.textContent=i.map(e=>function(e,t){const n=t.schema?.options;if(!Array.isArray(n))return e;for(const t of n){const n=Or(t);if(void 0!==n&&_n(n.value)===e)return"string"==typeof n.label?n.label:e}return e}(e,n)).join(", ")}else!function(e,t){if(e.multiple)for(const n of Array.from(e.options))n.selected=t.includes(n.value);else e.value=t[0]??""}(r,i)}},Pi=/* @__PURE__ */new Set(["","false","0","off","no"]),Li={name:"checkbox",render(e,t){const n=e.element,r=function(e){return"boolean"==typeof e?e:"string"==typeof e?!Pi.has(e.trim().toLowerCase()):"number"==typeof e?0!==e:null!=e}(t);"INPUT"!==n.tagName||"checkbox"!==n.type?n.hasAttribute("aria-checked")?n.setAttribute("aria-checked",r?"true":"false"):n.textContent=r?"true":"false":n.checked=r}},Fi=/* @__PURE__ */new Map,xi=/* @__PURE__ */new Map;function Ui(e,t){const n=e??"";if(null==t)return n;const r=Mi(t);return"{}"===r?n:`${n}|${r}`}function Mi(e){if(null===e||"object"!=typeof e)return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(e=>Mi(e)).join(",")}]`;const t=e,n=Object.keys(t).sort(),r=[];for(const e of n){const n=t[e];void 0!==n&&r.push(`${JSON.stringify(e)}:${Mi(n)}`)}return`{${r.join(",")}}`}var Ei=/* @__PURE__ */new Set(["short","medium","long","full"]),Ii=/* @__PURE__ */new Set(["short","medium","long","full"]),Oi=/^[A-Za-z]{3}$/u,_i=/^[0-4]$/u;function Di(e){return{kind:"date",options:e}}function zi(e){return{kind:"number",options:e}}var Bi=/* @__PURE__ */new WeakSet;function Hi(e,t,n,r){if(void 0===t||""===t)return;const i=function(e){const t=e.indexOf(":"),n=-1===t?e:e.slice(0,t),r=-1===t?void 0:e.slice(t+1);switch(n){case"date":return void 0===r?Di({dateStyle:"medium"}):Ei.has(r)?Di({dateStyle:r}):void 0;case"time":return void 0===r?Di({timeStyle:"short"}):Ii.has(r)?Di({timeStyle:r}):void 0;case"datetime":return void 0===r?Di({dateStyle:"medium",timeStyle:"short"}):Ei.has(r)?Di({dateStyle:r,timeStyle:"short"===r?"short":"medium"}):void 0;case"number":if(void 0===r)return zi({});if(!_i.test(r))return;return zi({minimumFractionDigits:Number(r),maximumFractionDigits:Number(r)});case"currency":if(void 0===r||!Oi.test(r))return;return zi({style:"currency",currency:r.toUpperCase()});case"percent":return void 0===r?zi({style:"percent"}):void 0;default:return}}(t);if(void 0!==i){if(i.kind===e)return i.options}else!function(e,t,n){Bi.has(e)||(Bi.add(e),y(`[live-preview] LP0408: data-payload-format="${n}" on "${t}" is not a known format; the default formatting was used. Known: date, date:short|medium|long|full, time, datetime, number, number:0-4, currency:XXX, percent.`))}(n,r,t)}var ji={name:"date",render(e,t,n){const r=e.element;if(Dn(t))return void("INPUT"===r.tagName?r.value="":(r.removeAttribute("datetime"),r.textContent=""));const i="number"==typeof t?t:_n(t),o=new Date(i),s=!Number.isNaN(o.getTime()),a=String(i);"INPUT"!==r.tagName?("TIME"===r.tagName&&r.setAttribute("datetime",s?o.toISOString():a),r.textContent=s?function(e,t,n){const r=t.locale??n.locale??detectInitialLocale(),i=Hi("date",t.format,t.element,t.fieldName)??Wi;try{return function(e,t){const n=Ui(e,t);return zn(xi,n)??Bn(xi,n,new Intl.DateTimeFormat(e,t),64)}(r,i).format(e)}catch{return e.toISOString()}}(o,e,n):a):r.value=s?function(e,t){const n=`${String(t.getFullYear()).padStart(4,"0")}-${qi(t.getMonth()+1)}-${qi(t.getDate())}`,r=`${qi(t.getHours())}:${qi(t.getMinutes())}`;return"date"===e?n:"datetime-local"===e?`${n}T${r}`:"time"===e?r:t.toISOString()}(r.type,o):a}},Wi={dateStyle:"medium",timeStyle:"short"};function qi(e){return String(e).padStart(2,"0")}var Vi={name:"number",render(e,t,n){const r=e.element;if(Dn(t))return void("INPUT"===r.tagName?r.value="":r.textContent="");const i="number"==typeof t?t:Number(_n(t));Number.isNaN(i)?r.textContent=_n(t):"INPUT"!==r.tagName?r.textContent=function(e,t,n){const r=t.locale??n.locale??detectInitialLocale(),i=Hi("number",t.format,t.element,t.fieldName);try{return function(e,t){const n=Ui(e,t);return zn(Fi,n)??Bn(Fi,n,new Intl.NumberFormat(e,t),64)}(r,i).format(e)}catch{return String(e)}}(i,e,n):r.value=String(i)}},Gi={name:"array",render:/* @__PURE__ */Q((e,t,n)=>{const r=e.element;if(Dn(t))return void(r.textContent="");if(!Array.isArray(t))return!1;const i=e.arrayTemplate;if(void 0!==i&&i.length>0){const e=function(e,t){const n=Mn(t);let r="";for(let i=0;i<t.length;i+=1)r+=En(e,t[i],i,_n,n);return r}(i,t),o=n.sanitizerPolicy,s=Vn(i),a=In(r);r.innerHTML=nn(Tn(e,o,s));for(const e of Array.from(r.children))On(e,a);return}r.textContent=t.map(_n).join(e.arraySeparator??", ")})};function Ki(){const e=/* @__PURE__ */new WeakMap,t=/* @__PURE__ */new WeakSet,n=/* @__PURE__ */new WeakMap,r=/* @__PURE__ */new WeakMap;return{name:"structural-array",render:/* @__PURE__ */Q((i,o,s)=>{const a=Dn(o)?[]:o;if(!Array.isArray(a))return!1;const l=i.element,u=i.arrayTemplate;if(void 0===u||0===u.length)return function(e,t,n){e.has(t)||(e.add(t),y(`[live-preview] LP0403: Skipping structural update for "${n}": <${t.tagName.toLowerCase()} data-payload-structural> needs data-payload-array-template (for example "<li>{{label}}</li>").`))}(t,l,i.fieldName),!1;const c=e.get(l),d=Ji(l),h=x(c?.values??d.map((e,t)=>null===e?{__payloadDomPosition:t}:{id:e}),a),f=function(e,t,n){return void 0===e||e.template!==t||!function(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}(e.domSnapshot,n)}(c,u,d);if(0===h.length&&!f)return e.set(l,{values:a.slice(),template:u,domSnapshot:d}),!1;!function(e,t,n,r,i){const o=i.map(Qi),s=/* @__PURE__ */new Set,a=o.find(e=>!(void 0===e||!s.has(e)&&(s.add(e),1)));if(void 0!==a&&Xi(e,t,n,a),o.some(e=>void 0===e)&&Zi(e,t,"LP0404",`LP0404: an item of "${n}" has no id and pairs by position, so an insert re-renders every row after it. Give items a stable id.`),r?.length===i.length&&i.length>1){const i=new Set(r.map(Qi).filter(e=>void 0!==e)),s=o.some(e=>void 0!==e&&i.has(e));i.size>0&&!s&&Zi(e,t,"LP0406",`LP0406: every key of "${n}" changed at once; the source generates ids per message, so no item can be retained across updates.`)}}(n,l,i.fieldName,c?.values,a);const p=Qn({template:u,container:l,patches:h,nextItems:a,store:r,forceRender:f,sanitizerPolicy:s.sanitizerPolicy,onDuplicateKey:(e,t)=>{Xi(n,e,i.fieldName,t)}});return null!==p&&(e.set(l,{values:a.slice(),template:u,domSnapshot:Ji(l)}),!!p&&void 0)})}}function Ji(e){return Array.from(e.children,e=>e.getAttribute(Gn))}function Qi(e){if("object"!=typeof e||null===e)return;const t=e.id;return"string"==typeof t||"number"==typeof t?String(t):void 0}function Xi(e,t,n,r){Zi(e,t,"LP0405",`LP0405: two items of "${n}" share the key "${r}"; later ones pair by position. Make \`id\` unique per item.`)}function Zi(e,t,n,r){let i=e.get(t);void 0===i&&(i=/* @__PURE__ */new Set,e.set(t,i)),i.has(n)||(i.add(n),y(`[live-preview] ${r}`))}var Yi=/* @__PURE__ */new Map;function eo(e,t){return{name:e,render(){k(t)}}}var to=Object.freeze({disableReferrerDetection:!0,eventSourcePolicy:"parent-or-opener",skipUnchanged:!0,sanitizerPolicy:"strict"}),no=Object.freeze({disableReferrerDetection:!1,eventSourcePolicy:"any",skipUnchanged:!1,sanitizerPolicy:"compat"});function ro(e){return void 0===e?void 0:!e}var LivePreviewClient=class{#z=new EventEmitter;#B;#H;#j;#S;#u;#W=!1;#q=!1;#V=!1;#G=null;constructor(e={}){const t=function(e){const t="v1"===e.defaults?no:to;return{...e,skipUnchanged:e.skipUnchanged??t.skipUnchanged,disableReferrerDetection:e.disableReferrerDetection??t.disableReferrerDetection,eventSourcePolicy:e.eventSourcePolicy??t.eventSourcePolicy,sanitizerPolicy:e.sanitizerPolicy??t.sanitizerPolicy}}(e),n=t.serverURL??"";!function(e){if("v1"!==e.defaults&&""!==(e.serverURL??"")&&null==e.mergeDepth)throw new Error("payload-live-preview: `serverURL` needs an explicit `mergeDepth` under the 2.0 defaults — choose the population depth deliberately (0 for none), or pass `defaults: 'v1'` to keep the 1.x default of 1 while migrating (ADR 0007, entry 10).")}({defaults:e.defaults,serverURL:n,mergeDepth:t.mergeDepth});const r=t.debug??isDevMode();this.#u=r?(...e)=>{b("[live-preview]",...e)}:g,this.#B=new OriginDetector(C({additionalOrigins:t.allowedOrigins,enableReferrerDetection:ro(t.disableReferrerDetection),enableLocalhostMatching:ro(t.disableLocalhostMatching)})),this.#B.isProductionUnconfigured&&this.#u("no trusted origin could be detected — set allowedOrigins"),this.#H=new Pr(function(){const e=[li,di,mi,vi,ki,Ti,$i,Ni,{...Ni,name:"radio"},Li,ji,Vi,..."undefined"!=typeof __LEAN_BUILD__&&__LEAN_BUILD__?[eo("array","structural arrays"),eo("blocks","structural arrays")]:[Gi,{...Gi,name:"blocks"}]];return function(e=[]){const t={};for(const n of e)t[n.name]=n;for(const[e,n]of Yi)t[e]=n;return Object.freeze(t)}([ii("text"),ii("textarea"),...e,..."undefined"!=typeof __LEAN_BUILD__&&__LEAN_BUILD__?[]:[Ki()]])}()),this.#S=new Nr({events:this.#z,config:Object.freeze({...t}),registerFieldRenderer:e=>this.#H.register(e),onTransformError:e=>{this.#z.emit("error",{error:e,context:"transform",code:"LP0602"})},log:this.#u}),this.#j=new yr(C({root:t.root,renderers:this.#H.renderers,resolveRenderer:(e,n)=>t.resolveRenderer?.(e,n)??this.#H.resolve(e),renderRichText:t.renderRichText,sanitizerPolicy:t.sanitizerPolicy,transformValue:(e,t,n,r)=>this.#S.applyTransforms(e,t,n,r),originMatcher:e=>this.#B.matches(e),readyTargets:()=>this.#B.enumerate(),emitter:this.#z,dataMerge:""===n?void 0:C({serverURL:n,apiRoute:t.apiRoute,depth:t.mergeDepth,fetchFn:t.mergeFetch}),debounceMs:t.debounceMs,heartbeatMs:t.heartbeatMs,intersectionRootMargin:t.intersectionRootMargin,scopeBindingsByOwner:t.scopeBindingsByOwner,skipUnchanged:t.skipUnchanged,revealEditedField:t.revealEditedField,autoBind:t.autoBind,eventSourcePolicy:t.eventSourcePolicy,dependencies:t.dependencies,strategies:t.strategies,disableVisibilityGate:t.disableVisibilityGate,visibilityGateThreshold:t.visibilityGateThreshold,enableA11y:t.enableA11y,a11yLocale:t.a11yLocale,onHeartbeatTimeout:()=>{this.#B.unlockOrigin()},lockedOrigin:()=>this.#B.lockedOrigin,validateToken:t.validateToken,log:this.#u})),this.#z.on("connect",e=>{this.#B.lockOrigin(e.origin)}),!1!==t.autoStart&&this.start()}start(){if(this.#q)return!1;if(this.#W)return this.#j.start(),!0;if(!function isInPreviewContext(){return isInIframe()||function isInPopup(){return"undefined"!=typeof window&&null!=window.opener}()}())return!1;const e=this.#j.start();return e&&(this.#W=!0),e}suspend(){return!(this.#q||!this.#W)&&this.#j.suspend()}resume(){return!(this.#q||!this.#W)&&this.#j.start()}destroy(){if(null!==this.#G)return this.#G;let e,t;this.#q=!0;const n=new Promise((n,r)=>{e=n,t=r});this.#G=n;const r=()=>{this.#z.removeAllListeners(),this.#V=!0};try{this.#j.destroy(),this.#S.destroyAll().finally(r).then(e,t)}catch(e){r(),t(e)}return n}async use(e){if(this.#q)throw new Error("LivePreviewClient: already destroyed");await this.#S.register(e)}async unuse(e){if(this.#V)throw new Error("LivePreviewClient: already destroyed");await this.#S.unregister(e)}refreshCache(){this.#j.refreshCache()}get events(){return this.#z}get plugins(){return this.#S.list()}get status(){return this.#j.status}inspect(){return{...this.#j.inspect(),plugins:this.#S.snapshot()}}get updateCount(){return this.#j.updateCount}get destroyed(){return this.#q}};function initLivePreview(e={}){const t=new LivePreviewClient({...e,autoStart:!1});return t.start()?t:null}function io(e,t,n){if(0===t.length)return;const r={type:"payload-live-preview-focus",field:t};e.postMessage(r,n)}function oo(e,t){return n=>{const r=e();null!=r&&io(r,n,t)}}var so=Object.freeze({NoTrustedOrigin:"LP0101",ReferrerOnlyTrust:"LP0102",PluginIncompatible:"LP0103",ProfileFeatureOmitted:"LP0104",OrphanField:"LP0201",UnattributableUpdate:"LP0202",UnboundField:"LP0203",VisibilityGateDeferred:"LP0301",UnsafeAttributeWrite:"LP0401",TextTargetHasChildren:"LP0402",MissingArrayTemplate:"LP0403",StructuralItemUnkeyed:"LP0404",StructuralDuplicateKey:"LP0405",StructuralUnstableKeys:"LP0406",UnsupportedStrategy:"LP0407",UnknownValueFormat:"LP0408",SanitizerDroppedAttribute:"LP0409",UnrenderedBlockKept:"LP0410",UnfaithfulPatch:"LP0411",ServerFormatReplaced:"LP0412",UnrenderedBlockLost:"LP0413",MessageRejected:"LP0501",TokenRejected:"LP0502",ProtocolShapeUnknown:"LP0503",HandlerThrew:"LP0601",TransformThrew:"LP0602",RendererThrew:"LP0603",StartupFailed:"LP0605",ReadyFailed:"LP0606",HydrationWaitTimedOut:"LP0607",AuditRuntimeMissing:"LP0701",AuditNoFrameAncestors:"LP0702",AuditFrameOptionsBlocks:"LP0703",AuditBindingsExposed:"LP0704",AuditGateThresholdExceeded:"LP0705",AuditUnownedBindings:"LP0706",AuditNoBindings:"LP0707",AuditNotAPage:"LP0708",FragmentRequestFailed:"LP0801",FragmentResponseInvalid:"LP0802",FragmentUnauthorized:"LP0803",FragmentSuperseded:"LP0804",RouteRefreshLoop:"LP0805",FragmentStrategyUnavailable:"LP0806",UnboundChangeRefresh:"LP0807",EscalationUnavailable:"LP0808",V2ReadinessGap:"LP0709",RuntimeOnPublicPage:"LP0710"}),ao="__livePreviewRouteRefresh";function registerRouteRefresh(e){const t="undefined"==typeof window?void 0:window;return void 0===t?()=>{}:(t[ao]=e,()=>{t[ao]===e&&(t[ao]=void 0)})}export{so as DIAGNOSTIC_CODES,EventEmitter,LivePreviewClient,oo as createPreviewFocusReporter,initLivePreview,registerRouteRefresh,io as reportPreviewFocus};
1
+ function detectInitialLocale(){return function(){if("undefined"==typeof document)return;const e=document.documentElement.getAttribute("lang");return null===e||0===e.length?void 0:e}()??function(){if("undefined"==typeof navigator)return;const e=navigator.language;return"string"==typeof e&&e.length>0?e:void 0}()??"en"}var e="payload-live-preview-a11y",t=/* @__PURE__ */new WeakMap;function n(e){null!==e.timer&&(clearTimeout(e.timer),e.timer=null),e.messageNode?.remove(),e.messageNode=null}var r=class{german;document;lease=null;constructor(e,t){const n=t??("undefined"==typeof document?null:document),r=n?.documentElement.getAttribute("lang")??"";this.german=function(e){return/^de(?:[-_]|$)/i.test(e)}(e??(r.length>0?r:detectInitialLocale())),this.document=n}mount(){const r=this.document;if(null==r?.body)return null;this.lease??=function(e){let n=t.get(e);return void 0===n&&(n={element:null,owned:!1,messageNode:null,refs:0,timer:null},t.set(e,n)),n.refs+=1,n}(r);const i=this.lease,o=i.element;if(o?.isConnected&&o.ownerDocument===r)return o;if(null!==o){const e=i.owned;n(i),e&&o.remove()}let s=r.getElementById(e);return i.owned=null===s,null===s&&(s=r.createElement("div"),s.id=e,s.setAttribute("role","status"),s.setAttribute("aria-live","polite"),s.setAttribute("aria-atomic","true"),s.setAttribute("style","position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);clip-path:inset(50%);white-space:nowrap;border:0"),r.body.appendChild(s)),i.element=s,s}announceConnected(){this.say(this.german?"Vorschau verbunden":"Live preview connected")}announceDisconnected(){this.say(this.german?"Vorschau getrennt":"Live preview disconnected")}announceUpdate(e){e<=0||this.say(this.german?`${String(e)} ${1===e?"Änderung":"Änderungen"} angewendet`:`${String(e)} ${1===e?"change":"changes"} applied`)}detach(){const e=this.lease,r=this.document;if(null===e||null===r)return;if(this.lease=null,e.refs-=1,e.refs>0)return;const i=e.element;null!==i&&n(e),e.owned&&i?.remove(),e.element=null,t.delete(r)}say(e){const t=this.mount(),r=this.lease;if(null===t||null===r)return;let i=r.messageNode;i?.parentNode!==t?(i?.remove(),i=t.ownerDocument.createTextNode(t.hasChildNodes()?` ${e}`:e),r.messageNode=i,t.appendChild(i)):i.data=null===i.previousSibling?e:` ${e}`,null!==r.timer&&clearTimeout(r.timer);const o=setTimeout(()=>{r.timer===o&&r.element===t&&n(r)},1500);r.timer=o}};function i(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){const e=o(n);e&&t.push(e)}return t}function o(e){if("object"!=typeof e||null===e)return;const t=e,n=t.name,r=t.type;if("string"!=typeof n||0===n.length)return;if("string"!=typeof r||0===r.length)return;const o=i(t.fields),s=function(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){if("object"!=typeof n||null===n)continue;const e=n,r=e.slug;if("string"!=typeof r||0===r.length)continue;const o=i(e.fields);t.push({...e,slug:r,fields:o})}return t}(t.blocks),a={...t,name:n,type:r};return o.length>0?a.fields=o:delete a.fields,s.length>0?a.blocks=s:delete a.blocks,a}function s(e,t){return void 0===e||t(e)}function a(e,t){return null==e||t(e)}function l(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||null===Object.getPrototypeOf(t)}var u=["data","fieldSchemaJSON","globalSlug","collectionSlug","locale","ready","previewToken","protocolVersion"],c={basic:{since:1},"schema-json":{since:2,observed:"schema"},locale:{since:2,observed:"locale"},"preview-token":{since:3,observed:"preview-token"},"nested-arrays":{since:4},"recursive-diffs":{since:4},"document-events":{since:4,observed:"document-event"},"relationship-events":{since:4,observed:"relationship-event"}},d=Object.keys(c);function negotiateProtocol(e,t=[]){const n="number"==typeof e&&Number.isFinite(e)&&e>=1?Math.floor(e):void 0,r=n??1,i=Math.min(4,r),o=new Set(t),s=/* @__PURE__ */new Set;for(const e of d)(i>=c[e].since||o.has(e))&&s.add(e);return{ours:4,...void 0!==n?{theirs:n}:{theirs:void 0},negotiated:i,capabilities:s,observed:o}}function h(e){return("object"==typeof e&&null!==e||"function"==typeof e)&&"function"==typeof e.then&&(Promise.resolve(e).catch(()=>{}),!0)}function f(e,t){return e.generation===t.generation&&e.revision===t.revision}var p=class{matcher;handlers;boundListener=void 0;attachedTarget=void 0;generation=0;revision=0;queueHead=void 0;queueTail=void 0;constructor(e,t){this.matcher=e,this.handlers=t}attach(e=window){if(void 0!==this.attachedTarget)return;let t=!1;const n=r=>{if(!t||this.boundListener!==n)return;const i=this.generation;try{this.receive(r,i,e)}catch{let e;try{e=r.origin}catch{e=""}this.reportInvalid("shape",e,i)}};this.generation+=1,this.resetQueue(),this.attachedTarget=e,this.boundListener=n;try{e.addEventListener("message",n)}catch(t){this.boundListener===n&&(this.attachedTarget=void 0,this.boundListener=void 0,this.resetQueue());try{e.removeEventListener("message",n)}catch{}throw t}if(this.boundListener===n)t=!0;else try{e.removeEventListener("message",n)}catch{}}detach(){const e=this.attachedTarget,t=this.boundListener;void 0!==e&&void 0!==t&&(this.attachedTarget=void 0,this.boundListener=void 0,this.resetQueue(),e.removeEventListener("message",t))}advanceGeneration(){return void 0!==this.attachedTarget&&(this.generation+=1,this.resetQueue(),!0)}static sendReady(e,t){const n={type:"payload-live-preview",ready:!0,protocolVersion:4};for(const r of e)for(const e of t)try{r.postMessage(n,e)}catch{}}receive(e,t,n){const r=e.origin;if(!this.matchesOrigin(r,t))return void this.reportInvalid("origin",r,t);if(!this.matchesSource(e,n))return void this.reportInvalid("source",r,t);const o=e.data;var c;if("object"==typeof(c=o)&&null!==c&&"type"in c&&"string"==typeof c.type)switch(o.type){case"payload-live-preview":return function(e){const t=e;return!(void 0!==t.data&&null!==t.data&&!l(t.data))&&a(t.fieldSchemaJSON,e=>Array.isArray(e))&&a(t.globalSlug,e=>"string"==typeof e)&&a(t.collectionSlug,e=>"string"==typeof e)&&a(t.locale,e=>"string"==typeof e)&&a(t.ready,e=>"boolean"==typeof e)&&a(t.previewToken,e=>"string"==typeof e)&&a(t.protocolVersion,e=>"number"==typeof e)}(o)?void this.dispatchUpdate(function(e){const t={...e};for(const e of u)null===Reflect.get(t,e)&&Reflect.deleteProperty(t,e);if(!Array.isArray(t.fieldSchemaJSON))return t;let n;try{n=i(t.fieldSchemaJSON)}catch{n=[]}return{...t,fieldSchemaJSON:n}}(o),r,t):void this.reportInvalid("shape",r,t);case"payload-document-event":return function(e){const t=e;return s(t.action,e=>"updated"===e||"created"===e||"deleted"===e)&&s(t.slug,e=>"string"==typeof e)&&s(t.id,e=>"string"==typeof e||Number.isFinite(e))}(o)?void this.invokeHandler(t,this.handlers.onDocumentEvent,o,r):void this.reportInvalid("shape",r,t);case"payload-live-preview-focus":{const e=function(e){const t=e.field;return"string"==typeof t&&t.length>0?t:void 0}(o);return void 0===e?void this.reportInvalid("shape",r,t):void this.invokeHandler(t,this.handlers.onFocusField,e,r)}default:this.reportInvalid("type",r,t)}else this.reportInvalid("shape",r,t)}dispatchUpdate(e,t,n){const r=l(e.data);if(!this.isCurrentGeneration(n))return;const i=r?{generation:n,revision:this.revision+=1}:void 0,o=this.handlers.validateToken;if(!this.isCurrentGeneration(n))return;if(void 0===o)return void this.commitUpdate(e,t,n,i);if(!0===e.ready&&void 0===e.data)return void this.commitUpdate(e,t,n,void 0);const s={generation:n,message:e,origin:t,messageRevision:i,verdict:void 0,next:void 0};let a;this.enqueue(s);try{a=o(e.previewToken,t)}catch{return void this.settleValidation(s,!1)}"boolean"!=typeof a?Promise.resolve(a).then(e=>{this.settleValidation(s,!0===e)},()=>{this.settleValidation(s,!1)}):this.settleValidation(s,a)}settleValidation(e,t){e.verdict=t,this.drainQueue(e.generation)}drainQueue(e){for(;this.isCurrentGeneration(e);){const t=this.queueHead;if(void 0===t)return;if(this.matchesOrigin(t.origin,e)){if(void 0===t.verdict)return;this.dequeue(t)&&(t.verdict?this.commitUpdate(t.message,t.origin,t.generation,t.messageRevision):this.reportInvalid("token",t.origin,t.generation))}else{if(!this.dequeue(t))continue;this.reportInvalid("origin",t.origin,t.generation)}}}commitUpdate(e,t,n,r){void 0===r?this.invokeHandler(n,this.handlers.onUpdate,e,t):this.invokeHandler(n,this.handlers.onUpdate,e,t,r)}reportInvalid(e,t,n){this.invokeHandler(n,this.handlers.onInvalid,e,t)}matchesSource(e,t){if("parent-or-opener"!==this.handlers.sourcePolicy)return!0;try{const n=e.source;if("object"!=typeof n||null===n)return!1;const r=t.parent;return r!==t&&n===r||n===t.opener}catch{return!1}}matchesOrigin(e,t){try{return!0===(this.isCurrentGeneration(t)&&this.matcher(e))&&this.isCurrentGeneration(t)}catch{return!1}}invokeHandler(e,t,...n){if(void 0!==t&&this.isCurrentGeneration(e))try{h(t(...n))}catch{}}isCurrentGeneration(e){return void 0!==this.attachedTarget&&this.generation===e}enqueue(e){void 0===this.queueTail?this.queueHead=e:this.queueTail.next=e,this.queueTail=e}dequeue(e){return this.queueHead===e&&(this.queueHead=e.next,void 0===this.queueHead&&(this.queueTail=void 0),!0)}resetQueue(){this.queueHead=void 0,this.queueTail=void 0}};function m(e){return(...t)=>{try{h(e(...t))}catch{}}}function g(){}var v=m((...e)=>console.error(...e)),y=m((...e)=>console.warn(...e)),b=m((...e)=>console.debug(...e)),w={"structural arrays":'data-payload-type="array" and keyed lists',"array templates":"data-payload-array-template","server-rendered fragments":"data-payload-fragment boundaries","route refreshes":'data-payload-strategy="route" and bindings in <head>',"screen-reader announcements":"the aria-live region","auto-binding":"autoBind: 'unique'"},S=/* @__PURE__ */new Set;function k(e){S.has(e)||(S.add(e),y(`[live-preview] LP0104: this page carries the lean runtime, which leaves out ${e} (${w[e]}). The elements are left as the server rendered them. Remove \`runtime: LEAN_RUNTIME\` to get the full runtime.`))}function A(e){return"undefined"!=typeof __LEAN_BUILD__&&__LEAN_BUILD__?function(e){return!1!==e.enableA11y&&k("screen-reader announcements"),null}(e):function(e){if(!1===e.enableA11y)return null;const t=e.root,n=void 0===t?void 0:function(e){return 9===e.nodeType}(t)?t:t.ownerDocument;return new r(e.a11yLocale,n)}(e)}function T(e){if("undefined"==typeof window)return;const t=[];window.parent!==window&&t.push(window.parent),window.opener instanceof Window&&t.push(window.opener),p.sendReady(t,e)}function C(e){const t={};for(const[n,r]of Object.entries(e))void 0!==r&&(t[n]=r);return t}var $=/* @__PURE__ */new Set(["tabs","row","collapsible"]);function R(e,t=""){const n=/* @__PURE__ */new Map;return N(e,t,n),n}function N(e,t,n){for(const r of e){if($.has(r.type)){r.fields&&N(r.fields,t,n);continue}const e=""===t?r.name:`${t}.${r.name}`;if(n.set(e,r),"group"===r.type)r.fields&&N(r.fields,e,n);else if("array"===r.type&&r.fields)N(r.fields,`${e}.*`,n);else if("blocks"===r.type&&r.blocks)for(const t of r.blocks)N(t.fields,`${e}.*.${t.slug}`,n)}}function P(e,t){if(e.has(t))return e.get(t);const n=t.replace(/\.\d+(?=\.|$)/g,".*");return e.has(n)?e.get(n):void 0}function L(e){if("object"!=typeof e||null===e)return;const t=e.id;return"string"==typeof t||"number"==typeof t?t:void 0}function F(e){if("object"!=typeof e||null===e)return;const t=e.blockType;return"string"==typeof t?t:void 0}function x(e,t){return t.every(e=>void 0!==L(e))?function(e,t){const n=[],r=/* @__PURE__ */new Map;for(let t=0;t<e.length;t+=1){const n=L(e[t]);void 0!==n&&r.set(n,t)}const i=/* @__PURE__ */new Set;for(let o=0;o<t.length;o+=1){const s=t[o],a=L(s);if(void 0===a){n.push({kind:"insert",index:o,value:s});continue}const l=r.get(a);if(void 0===l){n.push({kind:"insert",index:o,value:s});continue}i.add(l);const u=e[l];F(u)===F(s)?(l!==o&&n.push({kind:"move",from:l,to:o,value:s}),U(u,s)||n.push({kind:"update",index:o,value:s})):n.push({kind:"replace",index:o,oldValue:u,value:s})}for(let t=0;t<e.length;t+=1)i.has(t)||n.push({kind:"remove",index:t,value:e[t]});return n}(e,t):function(e,t){const n=[],r=Math.min(e.length,t.length);for(let i=0;i<r;i+=1)U(e[i],t[i])||n.push({kind:"update",index:i,value:t[i]});if(t.length>e.length)for(let r=e.length;r<t.length;r+=1)n.push({kind:"insert",index:r,value:t[r]});if(e.length>t.length)for(let r=t.length;r<e.length;r+=1)n.push({kind:"remove",index:r,value:e[r]});return n}(e,t)}function U(e,t){if(Object.is(e,t))return!0;if("object"!=typeof e||"object"!=typeof t||null===e||null===t)return!1;const n=e,r=t,i=Object.keys(n),o=Object.keys(r);if(i.length!==o.length)return!1;for(const e of i)if(!Object.is(n[e],r[e]))return!1;return!0}var M={text:"text",textarea:"textarea",richText:"richText",email:"email",number:"number",checkbox:"checkbox",date:"date",select:"select",radio:"radio",array:"array",blocks:"blocks",group:"text",tabs:"text",row:"text",collapsible:"text",relationship:"relationship",upload:"upload",point:"text",json:"text",code:"text",ui:"text"},E=/* @__PURE__ */new Set(["http:","https:","mailto:","tel:"]),I=/^\s*(?:javascript|data|vbscript|file|blob|about)\s*:/i,O=/^(?:\.{1,2}\/|[a-zA-Z0-9_-]+\/?)/,_=/^[\\/]{2}/,D=/[\t\n\r]/g;function isSafeUrl(e){if("string"!=typeof e)return!1;const t=e.trim().replace(D,"");if(0===t.length)return!1;if(I.test(t))return!1;if(t.startsWith("#")||t.startsWith("?"))return!0;if(_.test(t))return!0;if(t.startsWith("/"))return!0;try{const e=new URL(t);return E.has(e.protocol)}catch{return O.test(t)}}function isExternalHttpUrl(e){const t=e.trim().replace(D,"");return/^https?:\/\//i.test(t)||_.test(t)}var z=/* @__PURE__ */new Set(["style","srcdoc","formaction","form","id","name","is","srcset","imagesrcset"]),B=/* @__PURE__ */new Set(["href","src","poster","cite","action","xlink:href","data"]);function H(e){return!e.startsWith("on")&&!z.has(e)}function j(e){return e.onUnfaithfulPatch??("ignore"===e.onUnboundChange?"ignore":"escalate")}function W(e,t,n,r){if(t.reportedUnfaithful.has(n.element))return;t.reportedUnfaithful.add(n.element),t.unfaithfulCount+=1,t.unfaithfulFields.add(n.fieldName);const i=e.onUnfaithfulPatch;"ignore"!==i&&("warn"!==i?(e.log("LP0411",n.fieldName,r),t.unfaithfulPatches.push(n)):e.warn(`[live-preview] LP0411: "${n.fieldName}" ${r}`))}function q(e,t){return!e.unfaithfulFields.has(t)&&(e.unfaithfulFields.add(t),e.unfaithfulCount+=1,!0)}var V=/* @__PURE__ */new Set(["date","number","checkbox"]);function G(e){return"INPUT"===e.tagName||"TEXTAREA"===e.tagName?e.value:e.textContent}function K(e){const t=e.trim();return JSON.stringify(t.length>40?`${t.slice(0,40)}…`:t)}var J=/* @__PURE__ */new WeakSet;function Q(e){return J.add(e),e}function X(e){switch(typeof e){case"string":return e.length>65536?void 0:`s:${e}`;case"number":return`n:${Object.is(e,-0)?"-0":String(e)}`;case"boolean":return"b:"+(e?"1":"0");case"bigint":return`i:${String(e)}`;case"undefined":return"u";case"object":{if(null===e)return"z";let t;try{t=JSON.stringify(e)}catch{return}return t.length>65536?void 0:`o:${t}`}case"symbol":case"function":return}}var Z=class{previous=null;diff(e,t){const n=this.previous,r=null===n,i=/* @__PURE__ */new Map,o=/* @__PURE__ */new Set;for(const[t,r]of Object.entries(e)){const e=X(r);i.set(t,e),null!==n&&void 0!==e&&n.get(t)===e||o.add(t)}if(null!==n)for(const e of n.keys())i.has(e)||o.add(e);this.previous=i;const s=/* @__PURE__ */new Set;for(const[e,n]of Object.entries(t))if(o.has(e))for(const e of n)s.add(e);return{changed:o,invalidated:s,baseline:r}}reset(){this.previous=null}},Y="data-payload-fragment";function ee(e){return e.closest(`[${Y}]`)}function te(e){const t=e.getAttribute("data-payload-strategy");return null!==t&&t.length>0?"patch"===t||"fragment"===t||"route"===t?t:void 0:null!==ee(e)?"fragment":null!==e.closest("head")?"route":"patch"}function ne(e,t){return void 0===t||""===t?`collection:${e}`:`collection:${e}:${t}`}function re(e){return"string"==typeof e&&e.length>0}function ie(e,t){return null!==t&&void 0!==e&&t.includes(e)}function oe(e){const t=e.id;return"string"==typeof t&&t.length>0?t:"number"==typeof t&&Number.isFinite(t)?String(t):void 0}var se=/* @__PURE__ */new Set(["id","_id","createdAt","updatedAt","createdBy","updatedBy","_status","globalType","collection","locale","localized"]);function ae(e,t,n){const r=e.get(t);return void 0!==r&&(!1===n||r.some(e=>ie(e.owner,n)))}function le(e,t,n){const r=`${t}.`;for(const[t,i]of e.entries())if(t.startsWith(r)){if(!1===n)return!0;if(i.some(e=>ie(e.owner,n)))return!0}return!1}function ue(e,t){if(void 0===t||0===t.length)return e;const n=`_${t}`;return e.endsWith(n)?e.slice(0,-n.length):e}function ce(e,t,n){let r;return i=>{if(ae(e,i,n))return!0;const o=ue(i,t);return!(o===i||!ae(e,o,n))||!!le(e,i,n)||!(o===i||!le(e,o,n))||(r??=function(e,t){const n=/* @__PURE__ */new Set;for(const[r,i]of e.entries())for(const e of i)(!1===t||ie(e.owner,t))&&void 0!==e.locale&&n.add(`${r}_${e.locale}`);return n}(e,n),r.has(i))}}function de(e,t,n,r){const i=ce(e,n,r),o=[];for(const e of t)se.has(e)||i(e)||o.push(e);return o}var he=/* @__PURE__ */new Set(["text","textarea","email","number","checkbox","date","select","radio","point","code","json","ui","html"]),fe={},pe=class{rawChanges=new Z;resolved=null;queued=null;pending=null;timer=null;openUntil=0;decide(e,t){const n=t.message.data??{},{changed:r}=this.rawChanges.diff(n,fe);if(!function(e){const{cache:t,emitter:n}=e;if(t.islands.length>0)return!0;if(n.listenerCount("beforeUpdate")>0||n.listenerCount("afterUpdate")>0)return!0;for(const e of t.values()){if(ge(e)||e.fieldName.includes("."))return!0;if(ye(e.hrefField)||ye(e.srcField)||ye(e.altField))return!0}return void 0!==e.strategies.fragment&&null!==e.root.querySelector(`[${Y}]`)}(e))return{merge:!1,fields:n};const i=this.resolved;if(null===i)return this.resolved=n,{merge:!0,fields:n};const o={...i};let s=t.forceRender;for(const a of r){const r=n[a];if(se.has(a)){o[a]=r;continue}const l=me(a,i[a],r,e.cache,t.schemaIndex);"own"!==l&&(s=!0),"keep"!==l&&(o[a]=r)}return this.resolved=o,{merge:s,fields:o}}request(e,t,n){const r=Date.now();return r>=this.openUntil?(this.dropQueued(),this.openUntil=r+t,{leading:!0,result:e.merge(n)}):(this.queued=n,this.openUntil=r+t,this.pending??=function(){let e;return{promise:new Promise(t=>{e=t}),settle:e}}(),null!==this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.flush(e)},t),{leading:!1,result:this.pending.promise})}recordMerged(e){this.resolved=e}destroy(){this.dropQueued(),this.openUntil=0}dropQueued(){null!==this.timer&&clearTimeout(this.timer),this.timer=null,this.queued=null,this.pending?.settle({status:"superseded"}),this.pending=null}flush(e){const t=this.pending,n=this.queued;this.timer=null,this.pending=null,this.queued=null,null!==t&&null!==n&&e.merge(n).then(t.settle,()=>{t.settle({status:"unavailable"})})}};function me(e,t,n,r,i){return ve(n)?!ve(t)||function(e,t,n){const r=void 0===n?void 0:P(n,e);return void 0!==r&&!he.has(r.type)||!0===t.get(e)?.some(ge)||le(t,e,!1)}(e,r,i)?"keep":null==t?"ask":"own":"ask"}function ge(e){return!he.has(e.fieldType)}function ve(e){return null===e||"object"!=typeof e&&"function"!=typeof e}function ye(e){return!0===e?.includes(".")}var be=class{negotiation=negotiateProtocol(void 0);observed=/* @__PURE__ */new Set;observe(e,t){const n=e.filter(e=>!this.observed.has(e));if(0!==n.length){for(const e of n)this.observed.add(e);this.negotiation=negotiateProtocol(this.negotiation.theirs,this.observed),t("protocol",`observed=${n.join(",")}`)}}applyVersion(e,t){const n=this.negotiation;if(n.theirs===e)return;const r=negotiateProtocol(e,this.observed);this.negotiation=r,r.negotiated!==n.negotiated&&t("protocol","ours=4",`theirs=${e}`,`negotiated=${r.negotiated}`)}};function we(e){return null!==e&&e.forceRender&&!e.completed}var Se=class{lastIdentity=void 0;edit(e){const t=e.externallyUpdatedRelationship;if("object"!=typeof t||null===t)return null;const n=JSON.stringify([t.entitySlug,oe(t),t.updatedAt]),r=n!==this.lastIdentity;return this.lastIdentity=n,r&&function(e,t){const n=t.globalSlug??t.collectionSlug;if("string"!=typeof n||e.entitySlug!==n)return!0;const r=oe(e),i=oe(t.data??{});return void 0!==r&&void 0!==i&&r!==i}(t,e)?t:null}};function ke(e){try{return!0===e.matchMedia?.("(prefers-reduced-motion: reduce)").matches}catch{return!1}}var Ae=class{#e;reveal(e,t,n){return e===this.#e?"skipped-same":(this.#e=e,function(e,t){return function(e,t){const n=e.getBoundingClientRect(),r=n.bottom>0&&n.top<t.innerHeight,i=n.right>0&&n.left<t.innerWidth;return r&&i}(e,t)?"already-visible":(e.scrollIntoView({behavior:ke(t)?"auto":"smooth",block:"center"}),"revealed")}(t,n))}reset(){this.#e=void 0}},Te=class{seen=/* @__PURE__ */new Map;note(e,t,n){const r=X(n);if(void 0===r)return;const i=`${t.owner??""}\0${t.locale??""}\0${t.fieldName}`,o=this.seen.get(i);void 0!==o?o!==r&&(e.revealIdentities.push([i,r]),e.revealTarget??=t):this.seen.set(i,r)}commit(e){for(const[t,n]of e.revealIdentities)this.seen.set(t,n);e.revealIdentities=[];const t=e.revealTarget;return e.revealTarget=void 0,t}},Ce=class{started=!1;suspended=!1;deferredStart=null;hydration="idle";activeUpdate=null;locale=void 0;schema=void 0;schemaIndex=void 0;updateCount=0;supersededCount=0;completedCount=0;skippedUnchangedCount=0;lastFlush=null;absentFields=/* @__PURE__ */new Set;warnedOrphanFields=/* @__PURE__ */new Set;warnedStrategy=/* @__PURE__ */new WeakSet;warnedUnattributableMessage=!1;warnedVisibilityGate=!1;warnedFragmentFallback=!1;warnedEscalationUnavailable=!1;warnedProtocolShape=!1;reportedUnfaithful=/* @__PURE__ */new WeakSet;checkedServerFormat=/* @__PURE__ */new WeakSet;unfaithfulPatches=[];unfaithfulCount=0;escalatedCount=0;unfaithfulFields=/* @__PURE__ */new Set;autoBindSearchMs=void 0;autoBindGuesses=null;warnedForeignSource=!1;lastAppliedIdentity=/* @__PURE__ */new WeakMap;revealLedger=new Te;fragmentStats={rendered:0,failed:0,superseded:0};routeStats={refreshes:0,failed:0,refused:0,loopStopped:0};fragmentController=null;routeController=null;routeRetry=null;routeRefreshOwed=!1;readyTimers=[];revealer=new Ae;changes=new Z;merges=new pe;protocol=new be;relationships=new Se;isRunning(){return this.started}isCurrent(e){return this.started&&this.activeUpdate===e}complete(e){e.completed||(e.completed=!0,this.completedCount+=1)}abortStrategies(){null!==this.routeRetry&&(clearTimeout(this.routeRetry),this.routeRetry=null,this.routeRefreshOwed=!0);for(const e of["fragmentController","routeController"]){const t=this[e];null!==t&&(this[e]=null,t.abort())}}},$e=class{constructor(e,t){this.deps=e,this.state=t,this.instanceContext=C({renderRichText:e.renderRichText,sanitizerPolicy:e.sanitizerPolicy,reportUnfaithful:(n,r)=>{W(e,t,n,r)}})}deps;state;instanceContext;apply(e){const{deps:t,state:n}=this,r=n.activeUpdate;if(null===r||void 0===e.revision||!f(r.revision,e.revision)||!n.isCurrent(r))return!1;const{target:i,value:o}=e,s=void 0!==r.schemaIndex?P(r.schemaIndex,i.fieldName):void 0;let a,l=function(e,t){if(e.explicitFieldType)return e.fieldType;if(void 0!==t){const e=function(e){if(Object.prototype.hasOwnProperty.call(M,e))return M[e]}(t);if(void 0!==e)return e}return e.fieldType}(i,s?.type);"text"===l&&!0!==i.explicitFieldType&&function(e){if("object"!=typeof e||null===e||!("root"in e))return!1;const t=e.root;return"object"==typeof t&&null!==t&&Array.isArray(t.children)}(o)&&(l="richText");try{a=t.resolveRenderer(l,i)}catch(e){return this.fail(r,e)}if(!n.isCurrent(r))return!1;const u=t.emitter.listenerCount("elementUpdate")>0,c=u?"INPUT"===(d=i.element).tagName||"TEXTAREA"===d.tagName?d.value:"IMG"===d.tagName?d.src:d.textContent:void 0;var d;if(!n.isCurrent(r))return!1;const h={allFields:e.allFields,locale:i.locale??r.locale,schema:s,...this.instanceContext};!0===i.hidesWhenEmpty&&i.element.toggleAttribute("hidden",function(e){return null==e||("string"==typeof e?0===e.trim().length:Array.isArray(e)&&0===e.length)}(o));try{if(void 0!==i.targetAttribute){if("blocked"===function(e,t,n){const r=t.toLowerCase().trim();if(0===r.length)return"blocked";if(!H(r))return"blocked";if(null==n)return e.removeAttribute(r),"applied";if("string"!=typeof n&&"number"!=typeof n&&"boolean"!=typeof n)return"blocked";const i=String(n);return B.has(r)&&!isSafeUrl(i)?"blocked":(e.setAttribute(r,i),"applied")}(i.element,i.targetAttribute,o))return t.warn(`[live-preview] LP0401: refused to write "${i.fieldName}" into attribute "${i.targetAttribute}"`),!1}else{if(void 0===a)return t.log("no renderer for",l),W(t,n,i,`has no renderer for "${l}"`),!1;{const e=function(e,t,n,r){if("ignore"===e.onUnfaithfulPatch)return;if(void 0!==n.format||!V.has(r))return;if(t.checkedServerFormat.has(n.element))return;t.checkedServerFormat.add(n.element);const i=G(n.element);return i.trim().length>0?i:void 0}(t,n,i,l),r=function(e,t,n,r){return e.render(t,n,r)}(a,i,o,h);if(!1===r&&function(e){return J.has(e.render)}(a))return W(t,n,i,`is a value ${a.name} cannot render`),!1;void 0!==e&&function(e,t,n){const r=G(t.element);r!==n&&e.warn(`[live-preview] LP0412: "${t.fieldName}" showed ${K(n)}, the patch wrote ${K(r)} — either an edit that arrived before the preview connected, or a template that formats this value differently. Set data-payload-format to match it.`)}(t,i,e)}}}catch(e){return this.fail(r,e)}if(!n.isCurrent(r))return!1;u&&t.emitter.emitWhile("elementUpdate",{element:i.element,fieldName:i.fieldName,previousValue:c,nextValue:o,revision:r.revision.revision,receivedAt:r.receivedAt,source:"patch"},()=>n.isCurrent(r));const p=n.isCurrent(r);return p&&(void 0!==e.valueIdentity?n.lastAppliedIdentity.set(i.element,e.valueIdentity):n.lastAppliedIdentity.delete(i.element)),p}fail(e,t){if(!this.state.isCurrent(e))return!1;const n=t instanceof Error?t:new Error(String(t));return this.deps.emitter.emitWhile("error",{error:n,context:"renderer",code:"LP0603"},()=>this.state.isCurrent(e)),!1}};function Re(...e){const t=/* @__PURE__ */new Map;for(const n of e)for(const[e,r]of Object.entries(n)){let n=t.get(e);void 0===n&&(n=/* @__PURE__ */new Set,t.set(e,n));for(const e of r)n.add(e)}const n={};for(const[e,r]of t)n[e]=[...r];return n}function Ne(e,t){const n={};for(const r of t)r!==e&&(n[r]=[e]);return n}var Pe="data-payload-island",Le=`astro-island, [${Pe}]`;function Fe(e){return"patch"===e.getAttribute(Pe)}function xe(e){return function(e){return"astro-island"===e.tagName.toLowerCase()||e.hasAttribute(Pe)}(e)&&!Fe(e)}var Ue="data-payload-field",Me="data-payload-type",Ee="data-payload-attribute",Ie="data-payload-href",Oe="data-payload-src",_e="data-payload-alt",De="data-payload-array-template",ze="data-payload-array-separator",Be="data-payload-locale",He="data-payload-richtext",je="data-payload-html",We="data-payload-array",qe="data-payload-structural",Ve="data-payload-owner",Ge="data-payload-depends",Ke="data-payload-strategy",Je="data-payload-boundary",Qe="data-payload-guessed",Xe=[Ue,Me,Ee,Ie,Oe,_e,De,ze,Be,He,je,We,qe,Ve,Ge,Ke,Je,"type"],Ze=`[${Ue}]`,Ye=`[${Ve}]`;function et(e){const t=e.closest(Ye)?.getAttribute(Ve);return null==t||0===t.length?void 0:t}var tt=/^[a-z][a-z0-9-]*:[a-z][a-z0-9-]*$/i,nt=/* @__PURE__ */new Set(["text","textarea","richText","email","number","checkbox","date","select","radio","array","blocks","group","tabs","row","collapsible","relationship","upload","point","json","code","ui","html","url","image","structural-array"]);function rt(e){return nt.has(e)||tt.test(e)}var it=class{entriesByField=/* @__PURE__ */new Map;entryByElement=/* @__PURE__ */new WeakMap;filter;count=0;dependencies=null;islandRoots=[];constructor(e={}){this.filter=e.filter??st}dependencyMap(){if(null!==this.dependencies)return this.dependencies;const e=[];for(const t of this.values())void 0!==t.dependsOn&&e.push(Ne(t.fieldName,t.dependsOn));return this.dependencies=Re(...e),this.dependencies}get islands(){return this.islandRoots}buildFromRoot(e){const t=performance.now();this.clear();let n=0;for(const t of e.querySelectorAll(Ze))void 0!==this.add(t)&&(n+=1);return this.islandRoots=function(e){const t=[];for(const n of e.querySelectorAll(Le))Fe(n)||t.push(n);return t}(e),{elementCount:n,fieldCount:this.entriesByField.size,durationMs:performance.now()-t}}add(e){const t=this.filter(e)?this.resolveBinding(e):void 0,n=this.entryByElement.get(e);if(this.dependencies=null,void 0!==t)return void 0!==n&&this.replaceEntry(n,t)?(this.entryByElement.set(e,t),t):(void 0!==n&&this.removeEntry(e,n),this.append(t),this.entryByElement.set(e,t),t);void 0!==n&&this.removeEntry(e,n)}remove(e){const t=this.entryByElement.get(e);return!!t&&(this.dependencies=null,this.removeEntry(e,t))}get(e){return this.entriesByField.get(e)}getByElement(e){return this.entryByElement.get(e)}get fieldCount(){return this.entriesByField.size}get elementCount(){return this.count}entries(){return this.entriesByField.entries()}*values(){for(const e of this.entriesByField.values())yield*e}has(e){return this.entryByElement.has(e)}clear(){this.entriesByField.clear(),this.entryByElement=/* @__PURE__ */new WeakMap,this.count=0,this.dependencies=null,this.islandRoots=[]}replaceEntry(e,t){if(e.fieldName!==t.fieldName)return!1;const n=this.entriesByField.get(e.fieldName),r=void 0===n?-1:n.indexOf(e);return!(void 0===n||r<0||(n[r]=t,0))}removeEntry(e,t){this.entryByElement.delete(e);const n=this.entriesByField.get(t.fieldName),r=void 0===n?-1:n.indexOf(t);return!(void 0===n||r<0||(n.splice(r,1),0===n.length&&this.entriesByField.delete(t.fieldName),this.count-=1,0))}append(e){const t=this.entriesByField.get(e.fieldName);t?t.push(e):this.entriesByField.set(e.fieldName,[e]),this.count+=1}resolveBinding(e){const t=e.getAttribute(Ue);if(null===t||0===t.length)return;const n=e.getAttribute(Me),r=e.getAttribute(Ee),i=e.getAttribute(Ie),o=e.getAttribute(Oe),s=e.getAttribute(_e),a=e.getAttribute(De),l=e.getAttribute(ze),u=e.getAttribute(Be),c=e.getAttribute("data-payload-format"),d=et(e),h=function(e){if(null==e)return[];const t=/* @__PURE__ */new Set,n=[];for(const r of e.split(/[\s,]+/)){const e=r.trim();0===e.length||t.has(e)||(t.add(e),n.push(e))}return n}(e.getAttribute(Ge)),f=e.getAttribute(Ke),p=e.getAttribute(Qe),m=ee(e);return{element:e,fieldName:t,fieldType:ot(e),explicitFieldType:null!==n&&rt(n),strategyKind:te(e)??"unknown",...null!==m?{fragmentBoundary:m}:{},...null!==r&&r.length>0?{targetAttribute:r}:{},...null!==i&&i.length>0?{hrefField:i}:{},...null!==o&&o.length>0?{srcField:o}:{},...null!==s&&s.length>0?{altField:s}:{},...null!==a?{arrayTemplate:a}:{},...null!==l?{arraySeparator:l}:{},...null!==u&&u.length>0?{locale:u}:{},...null!==c&&c.length>0?{format:c}:{},...void 0!==d?{owner:d}:{},...h.length>0?{dependsOn:h}:{},...null!==f&&f.length>0?{strategy:f}:{},...e.hasAttribute(Je)?{hidesWhenEmpty:!0}:{},...null!==p?{guessed:p}:{}}}};function ot(e){const t=e.getAttribute(Me);if(null!==t&&rt(t))return t;if(e.hasAttribute(He))return"richText";if(e.hasAttribute(je))return"html";if(e.hasAttribute(qe))return"structural-array";if(e.hasAttribute(We))return"array";if("IMG"===e.tagName)return"image";if("A"===e.tagName)return"url";if("TIME"===e.tagName)return"date";if("INPUT"===e.tagName){const t=e.type;if("checkbox"===t)return"checkbox";if("number"===t)return"number";if("date"===t||"datetime-local"===t)return"date"}return"text"}function st(){return!0}function at(e,t){return e.length>0&&e.length<=t&&"."!==e&&".."!==e&&!e.includes("/")&&!e.includes("\\")&&!function(e){for(const t of e){const e=t.codePointAt(0)??0;if(e<=31||127===e)return!0}return!1}(e)}function lt(e){return at(e,128)&&!e.includes("?")&&!e.includes("#")}var ut=class{serverURL;apiRoute;depth;fetchFn;log;inflight=null;attempt=0;destroyDepth=0;constructor(e){this.serverURL=function(e){let t=e.length;for(;e.endsWith("/",t);)t-=1;return e.slice(0,t)}(e.serverURL);const t=e.apiRoute??"/api";this.apiRoute=t.startsWith("/")?t:`/${t}`,this.depth=e.depth??1,this.fetchFn=e.fetchFn,this.log=m(e.log??g)}canMerge(e){return null!==this.endpointOf(e)}endpointOf(e){try{const n=e.globalSlug;if(n)return lt(n)?`globals/${encodeURIComponent(n)}`:null;const r=e.collectionSlug??"",i=e.data.id;return lt(r)&&("number"==typeof(t=i)?Number.isFinite(t):"string"==typeof t&&at(t,512))?`${encodeURIComponent(r)}/${encodeURIComponent(String(i))}`:null}catch{return null}var t}async merge(e){if(this.destroyDepth>0)return{status:"superseded"};const t=this.attempt+=1,n=this.inflight;this.inflight=null;let r=null;const i=()=>this.attempt!==t;try{if(n?.abort(),i())return{status:"superseded"};const t=this.endpointOf(e);if(null===t)return i()?{status:"superseded"}:{status:"unavailable"};const o=this.fetchFn??("function"==typeof fetch?fetch:void 0);if(void 0===o)return{status:"unavailable"};r=new AbortController,this.inflight=r;const s=`${this.serverURL}${this.apiRoute}/${t}`,a=await o(s,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json","X-Payload-HTTP-Method-Override":"GET"},body:JSON.stringify({data:e.data,depth:this.depth,flattenLocales:!1,locale:e.locale}),signal:r.signal});if(i())return{status:"superseded"};if(!a.ok)return this.log("merge HTTP",a.status,s),{status:"unavailable"};const l=await a.json();return i()?{status:"superseded"}:null===l||"object"!=typeof l||Array.isArray(l)?(this.log("merge invalid",s),{status:"unavailable"}):{status:"merged",doc:l}}catch(e){return i()?{status:"superseded"}:(this.log("merge exception",e),{status:"unavailable"})}finally{this.inflight===r&&(this.inflight=null)}}destroy(){this.attempt+=1;const e=this.inflight;this.inflight=null,this.destroyDepth+=1;try{e?.abort()}finally{this.destroyDepth-=1}}},ct="2.0.5",dt={name:"payload-2",fieldTyping:"schema",populatesRelationships:"admin",documentEvents:!1},ht={name:"payload-3",fieldTyping:"heuristic",populatesRelationships:"server",documentEvents:!0},ft={name:"unknown",fieldTyping:"heuristic",populatesRelationships:"server",documentEvents:!1};function detectProtocolProfile(e){return e.has("schema-json")?dt:e.has("document-events")||e.has("relationship-events")?ht:ft}var pt=class{callbacks;debounceMs;rootMargin;visible=/* @__PURE__ */new Set;mutation=null;intersection=null;debounceTimer=null;generation=0;constructor(e,t={}){this.callbacks=e,this.debounceMs=t.mutationDebounceMs??100,this.rootMargin=t.intersectionRootMargin??"200px"}start(e){const t=this.generation;this.stop();const n=t+1;if(this.generation!==n)return;let r=null,i=null;try{r=new MutationObserver(e=>{this.handleMutations(e,n)}),i=new IntersectionObserver(e=>{this.handleIntersection(e,n)},{rootMargin:this.rootMargin,threshold:0}),r.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[...Xe]})}catch(e){throw r?.disconnect(),i?.disconnect(),e}if(this.generation!==n)return r.disconnect(),void i.disconnect();this.mutation=r,this.intersection=i}observeElement(e){this.intersection?.observe(e)}unobserveElement(e){this.intersection?.unobserve(e),this.visible.delete(e)}markVisible(e,t){t?this.visible.add(e):this.visible.delete(e)}isVisible(e){return this.visible.has(e)}stop(){this.generation+=1;const e=this.debounceTimer,t=this.mutation,n=this.intersection;this.debounceTimer=null,this.mutation=null,this.intersection=null,this.visible.clear(),null!==e&&clearTimeout(e);try{t?.disconnect()}finally{n?.disconnect()}}handleMutations(e,t){if(!this.isCurrentGeneration(t)||!function(e){for(const t of e){if("attributes"===t.type&&null!==t.attributeName&&Xe.includes(t.attributeName)&&(t.attributeName===Ue||t.attributeName===Ve||1===t.target.nodeType&&t.target.hasAttribute(Ue)))return!0;for(const e of t.addedNodes)if(mt(e))return!0;for(const e of t.removedNodes)if(mt(e))return!0}return!1}(e))return;null!==this.debounceTimer&&clearTimeout(this.debounceTimer);const n=setTimeout(()=>{this.isCurrentGeneration(t)&&this.debounceTimer===n&&(this.debounceTimer=null,this.callbacks.onStructuralChange())},this.debounceMs);this.debounceTimer=n}handleIntersection(e,t){for(const n of e){if(!this.isCurrentGeneration(t))return;const{target:e}=n;if(n.isIntersecting){if(this.visible.has(e))continue;this.visible.add(e),this.callbacks.onVisibilityChange(e,!0)}else this.visible.has(e)&&(this.visible.delete(e),this.callbacks.onVisibilityChange(e,!1))}}isCurrentGeneration(e){return this.generation===e&&null!==this.intersection}};function mt(e){if(1!==e.nodeType)return!1;const t=e;return t.hasAttribute(Ue)||null!==t.querySelector(`[${Ue}]`)}var gt="[data-payload-field]";function vt(){if("undefined"==typeof window)return;const e=window;return e.__livePreviewHydration??={armed:!1,committed:!1,commits:[],onCommit:void 0,waiters:[]}}function yt(){const e=vt();if(void 0===e||e.armed)return;e.armed=!0;const t=window,n=t.__REACT_DEVTOOLS_GLOBAL_HOOK__??=function(){const e=/* @__PURE__ */new Map;return{supportsFiber:!0,renderers:e,inject:t=>{const n=e.size+1;return e.set(n,t),n}}}(),r=n.onCommitFiberRoot;n.onCommitFiberRoot=function(t,n,...i){try{r?.call(this,t,n,...i)}catch{}const o=n?.containerInfo;void 0===e.onCommit?e.commits.push(o):e.onCommit(o)}}function bt(e){e.committed=!0;const t=e.waiters;e.waiters=[];for(const e of t)e()}function wt(e,t){const n=e.waiters.indexOf(t);n>=0&&e.waiters.splice(n,1)}function St(e,t,n){if(e.committed)return null;let r=null;const i=()=>{null!==r&&clearTimeout(r),r=null,t("committed")};return e.waiters.push(i),r=setTimeout(()=>{r=null,wt(e,i),t("timed-out")},n),()=>{null!==r&&clearTimeout(r),r=null,wt(e,i)}}var kt="__vue_app__";function At(){if("undefined"==typeof window)return;const e=window;return e.__livePreviewVueHydration??={armed:!1,committed:!1,waiters:[]}}function Tt(e){return Object.prototype.hasOwnProperty.call(e,kt)?e[kt]:void 0}function Ct(){const e=At();if(void 0===e||e.armed)return;e.armed=!0;const t=Element.prototype;void 0===Object.getOwnPropertyDescriptor(t,kt)&&Object.defineProperty(t,kt,{configurable:!0,get:()=>{},set(e){Object.defineProperty(this,kt,{value:e,writable:!0,configurable:!0,enumerable:!0});const t=At();void 0===t||t.committed||null===this.querySelector(gt)||function(e,t){const n=t?.$nuxt;!0!==n?.isHydrating||"function"!=typeof n.hook?bt(e):n.hook("app:suspense:resolve",()=>{e.committed||bt(e)})}(t,e)}})}function $t(e){if(void 0===e.hydration)return void e.startNow();const t=t=>{e.later(()=>{Rt(e,t)})},n="react"===e.hydration?function(e,t=5e3){yt();const n=vt();if(void 0===n)return null;if(void 0===n.onCommit){const e=e=>{!n.committed&&function(e){const t=e;return 9===t?.nodeType||null!=t?.querySelector?.(gt)}(e)&&bt(n)};n.onCommit=e;for(const t of n.commits.splice(0))e(t)}return St(n,e,t)}(t):function(e,t,n=5e3){Ct();const r=At();return void 0===r?null:(!r.committed&&function(e){for(let t=e.querySelector(gt);null!==t;t=t.parentElement)if(void 0!==Tt(t))return!0;return!1}(e)&&bt(r),St(r,t,n))}(e.root,t);null!==n?(e.defer(n),e.hydrated("waiting")):Rt(e,"committed")}function Rt(e,t){e.hydrated(t),"timed-out"===t&&e.warn(`[live-preview] LP0607: no ${"react"===e.hydration?"React commit":"Vue mount"} in ${String(5e3)} ms; started without waiting for hydration.`),e.startNow()}var Nt=class{timeoutMs;onTimeout;handle=null;lastKick=0;constructor(e){this.timeoutMs=e.timeoutMs??0,this.onTimeout=e.onTimeout}kick(){if(this.lastKick=Date.now(),this.timeoutMs<=0)return;null!==this.handle&&clearTimeout(this.handle);const e=setTimeout(()=>{this.handle===e&&(this.handle=null,this.onTimeout())},this.timeoutMs);this.handle=e}stop(){null!==this.handle&&(clearTimeout(this.handle),this.handle=null)}get lastKickAt(){return this.lastKick}get pending(){return null!==this.handle}},Pt=class{current="disconnected";get status(){return this.current}markConnected(){return this.transition("connected")}markDisconnected(){return this.transition("disconnected")}transition(e){return this.current!==e&&(this.current=e,!0)}},Lt=/* @__PURE__ */new Set(["true","false","yes","no","on","off"]),Ft=/^[\d\s.,:+/-]+$/u,xt=/^[a-z][a-z0-9_-]*$/u,Ut=/^[a-z]{2,3}(?:[-_][A-Za-z0-9]{2,8})*$/u,Mt=/* @__PURE__ */new Set(["SCRIPT","STYLE","TEMPLATE","TITLE","NOSCRIPT","TEXTAREA","SELECT","OPTION","INPUT","IFRAME"]);function Et(e,t=13){if("string"!=typeof e)return!1;const n=e.trim();return!(n.length<t||Ft.test(n)||Lt.has(n.toLowerCase())||xt.test(n)||Ut.test(n))}function It(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function Ot(e,t,n=13){const r=/* @__PURE__ */new Map,i=(e,t,n)=>{r.set(e,r.has(e)?null:{field:t,media:n})};for(const[r,o]of Object.entries(e)){if(se.has(r))continue;const e=ue(r,t);if(Et(o,n))i(o.trim(),e,!1);else if(It(o))if("string"==typeof o.url)i(o.url,e,!0);else if(!("id"in o)&&!("_id"in o))for(const[t,r]of Object.entries(o))!se.has(t)&&Et(r,n)&&i(r.trim(),`${e}.${t}`,!1)}return r}function _t(e){if("http://www.w3.org/1999/xhtml"!==e.namespaceURI||Mt.has(e.tagName))return!0;if(e.hasAttribute(Ue)||e.hasAttribute("data-payload-no-bind")||e.hasAttribute("data-payload-owned")||xe(e))return!0;const t=e.getAttribute("contenteditable");return null!==t&&"false"!==t}function Dt(e){let t;for(let n=e.firstChild;null!==n;n=n.nextSibling){if(1===n.nodeType)return;if(3!==n.nodeType)continue;const e=n.data.trim();if(0!==e.length){if(void 0!==t)return;t=e}}return t}function zt(e){return H(e)&&!e.startsWith("data-payload-")&&"value"!==e}function Bt(e,t,n){let r=e.byElement.get(t);void 0===r&&(r={attributes:/* @__PURE__ */new Map},e.byElement.set(t,r));let i=e.byField.get(n.field);return void 0===i&&(i=/* @__PURE__ */new Set,e.byField.set(n.field,i)),i.add(t),r}function Ht(e,t){for(let n=e.firstElementChild;null!==n;n=n.nextElementSibling){if(_t(n))continue;const e=Dt(n),r=void 0===e?void 0:t.values.get(e);null==r||r.media||(Bt(t,n,r).text=r.field);for(const e of n.getAttributeNames()){if(!zt(e))continue;const r=t.values.get(n.getAttribute(e)??"");null!=r&&(!r.media||"IMG"===n.tagName&&"src"===e)&&Bt(t,n,r).attributes.set(e,r)}Ht(n,t)}}function jt(e,t,n){const r=e.tagName;if(void 0!==t){const i={[Ue]:t};if("A"===r){const e=n.get("href");void 0===e?i[Me]="text":e!==t&&(i[Ie]=e)}return{element:e,fieldName:t,matched:Dt(e)??"",stamps:i}}if("IMG"===r){const t=n.get("src");if(void 0!==t){const r=n.get("alt");return{element:e,fieldName:t,matched:e.getAttribute("src")??"",attribute:"src",stamps:{[Ue]:t,...void 0!==r&&r!==t?{[_e]:r}:{}}}}}const i=n.entries().next();if(i.done)return;const[o,s]=i.value;return{element:e,fieldName:s,matched:e.getAttribute(o)??"",attribute:o,stamps:{[Ue]:s,[Ee]:o}}}function Wt(e,t){const n={values:t,byElement:/* @__PURE__ */new Map,byField:/* @__PURE__ */new Map};t.size>0&&!_t(e)&&Ht(e,n);const r=e=>1===n.byField.get(e)?.size,i=[];for(const[e,t]of n.byElement){const n=void 0!==t.text&&r(t.text)?t.text:void 0,o=/* @__PURE__ */new Map;for(const[e,n]of t.attributes)r(n.field)&&o.set(e,n.field);const s=jt(e,n,o);void 0!==s&&i.push(s)}return i}function qt(e){return 9===e.nodeType?e.body:e}function Vt(e,t,n,r){const i=[];for(const o of t){const{element:t}=o;if(!t.hasAttribute(Ue)&&(!1===n||ie(et(t),n))){for(const[e,n]of Object.entries(o.stamps))t.setAttribute(e,n);if(t.setAttribute(Qe,o.matched),void 0!==e.cache.add(t))e.observers.observeElement(t),e.log("autoBind",o.fieldName,"→",`<${t.tagName.toLowerCase()}>`,o.attribute??"text",JSON.stringify(o.matched),r),i.push(o);else{for(const e of Object.keys(o.stamps))t.removeAttribute(e);t.removeAttribute(Qe)}}}return i}var Gt=/* @__PURE__ */new Set(["__proto__","prototype","constructor"]);function Kt(e,t,n,r=!1){if(r&&void 0!==n){const r=Jt(e,`${t}_${n}`);if(void 0!==r)return r}const i=Jt(e,t);if(void 0!==i)return i;if(t.includes(".")){let n=e,r=!0;for(const e of t.split(".")){if(Gt.has(e)||null===n||"object"!=typeof n){r=!1;break}if(n=Jt(n,e),void 0===n){r=!1;break}}if(r)return n}return void 0===n?void 0:Jt(e,`${t}_${n}`)}function Jt(e,t){if(!Gt.has(t)&&Object.prototype.hasOwnProperty.call(e,t))return e[t]}function Qt(e,t,n,r){return Kt(e,n,t.locale??r,void 0!==t.locale)}function Xt(e,t,n,r){const i=X(t);if(void 0===i)return;const o=[e.hrefField,e.srcField,e.altField];let s=i;for(const t of o){if(void 0===t||0===t.length)continue;const i=X(Qt(n,e,t,r));if(void 0===i)return;s+=`|${t}=${i}`}return s}function Zt(e,t,n,r,i){const{warned:o,warn:s}=e;if(o.has(n)||t(n))return;o.add(n);const a=`data-payload-field="${ue(n,r)}"`;s(""!==i?`[live-preview] LP0203: field "${n}" has a value and no <… ${a}> on this page; editing it changes nothing here. Expected where the page shows part of the document: inspect().fidelity.fields lists these, onUnfaithfulPatch decides whether a server render is asked for.`:`[live-preview] LP0201: no <… ${a}> for the empty field "${n}"; render the anchor unconditionally so edits to an empty field have somewhere to land.`)}function Yt(e){const t=typeof e;return"string"===t||"number"===t||"boolean"===t||"bigint"===t}function en(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}var tn=/* @__PURE__ */Symbol.for("payload-live-preview.trusted-types");function nn(e){const t=function(){const e=function(){const e=globalThis,t=e[tn];if(void 0!==t)return t;const n={};return e[tn]=n,n}();if(void 0!==e.override)return e.override;if(void 0!==e.auto)return e.auto;const t=function(){const e=globalThis.trustedTypes;if("object"==typeof e&&null!==e)return"function"==typeof e.createPolicy?e:void 0}();try{e.auto=void 0===t?null:t.createPolicy("payload-live-preview",{createHTML:e=>e})}catch{e.auto=null}return e.auto}();return null===t?e:t.createHTML(e)}var rn=/* @__PURE__ */new Set(["open","value","checked","selected"]);function on(e,t){for(const n of t.keyAttributes){const t=e.getAttribute(n);if(null!==t&&t.length>0)return`${n}=${t}`}}function sn(e){if(e.tagName.toLowerCase().includes("-"))return!0;if(e.hasAttribute(Pe)||e.hasAttribute("data-payload-owned"))return!0;const t=e.getAttribute("contenteditable");return null!==t&&"false"!==t}function an(e,t,n){if(!function(e,t){return e.tagName===t.tagName&&e.namespaceURI===t.namespaceURI&&!sn(e)&&!sn(t)}(e,t))return t;const r=dn(e);return function(e,t){for(const n of Array.from(e.attributes))t.hasAttribute(n.name)||rn.has(n.name.toLowerCase())||e.removeAttribute(n.name);for(const n of Array.from(t.attributes))e.getAttribute(n.name)!==n.value&&e.setAttribute(n.name,n.value)}(e,t),!0!==n.retainChildrenOf?.(e,t)&&function(e,t,n){const r=function(e,t){const n=/* @__PURE__ */new Map;let r;for(const i of Array.from(e.children)){const e=on(i,t);void 0!==e&&(n.has(e)?r??=e.slice(e.indexOf("=")+1):n.set(e,i))}return void 0!==r&&t.onDuplicateKey?.(e,r),n}(e,n),i=new Set(r.values()),o=Array.from(e.childNodes).filter(e=>!i.has(e)),s=/* @__PURE__ */new Set,a=/* @__PURE__ */new Set,l=Array.from(t.childNodes);let u=e.firstChild,c=0;for(let t=0;t<l.length;t+=1){const i=l[t];let d=null,h=i instanceof Element?on(i,n):void 0;if(void 0!==h&&a.has(h)&&(h=void 0),void 0!==h){a.add(h);const e=r.get(h);if(void 0!==e&&!s.has(e)&&(d=ln(e,i,n)===e?e:null,null===d)){e.replaceWith(i),s.add(i),u=i.nextSibling;continue}}else{for(;c<o.length;){const r=o[c];if(c+=1,!s.has(r)){if(cn(r,i)){d=ln(r,i,n)===r?r:null,null===d&&(e.replaceChild(i,r),s.add(i),u=i.nextSibling);break}if(r instanceof Element){const n=l[t+1];if(!(i instanceof Element)||void 0!==n&&cn(r,n)){c-=1;break}e.replaceChild(i,r),s.add(i),u=i.nextSibling;break}if(!(i instanceof Element)){e.replaceChild(i,r),s.add(i),u=i.nextSibling;break}}}if(null===d&&s.has(i))continue}const f=d??i;for(s.add(f);null!==u&&u!==f&&!s.has(u)&&un(u);)u=u.nextSibling;f!==u&&e.insertBefore(f,u),u=f.nextSibling}for(const t of Array.from(e.childNodes))s.has(t)||t.remove()}(e,t,n),hn(r),e}function ln(e,t,n){return e instanceof Element&&t instanceof Element?sn(e)&&sn(t)?e:an(e,t,n):(e.nodeValue!==t.nodeValue&&(e.nodeValue=t.nodeValue),e)}function un(e){return e.nodeType===Node.TEXT_NODE&&0===(e.nodeValue??"").trim().length}function cn(e,t){return e.nodeType===t.nodeType&&(!(e instanceof Element&&t instanceof Element)||e.tagName===t.tagName&&e.namespaceURI===t.namespaceURI)}function dn(e){const t=e.ownerDocument.activeElement;return t instanceof HTMLElement&&e.contains(t)?{element:t,selection:t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement?[t.selectionStart,t.selectionEnd]:null}:null}function hn(e){if(null===e)return;const{element:t,selection:n}=e;if(t.ownerDocument.activeElement!==t&&t.isConnected)try{t.focus({preventScroll:!0});const[e,r]=n??[null,null];null!==e&&null!==r&&t.setSelectionRange(e,r)}catch{}}var fn=/* @__PURE__ */new Set;function pn(e){fn.has(e)||(fn.add(e),function(e){try{console.warn(e)}catch{}}(`[live-preview] LP0409: the strict sanitizer removed \`${e}\` from written markup; the 1.x default (\`sanitizerPolicy: 'compat'\`) kept it. ${function(e){return e.startsWith("data-payload-")?"A binding inside CMS content is refused by design — an editor could otherwise aim a write at any element on the page (docs/security.md)":"id"===e||"name"===e?"CMS content that can name an element can shadow a global of that name — DOM clobbering, refused by design (docs/security.md)":"List it in `allowedDataAttributes` if the page needs it, or set `sanitizerPolicy: 'compat'` to keep every `data-*` as 1.x did"}(e)}.`))}var mn=/* @__PURE__ */new Set(["p","br","strong","b","em","i","u","s","strike","mark","small","h1","h2","h3","h4","h5","h6","ul","ol","li","dl","dt","dd","blockquote","code","pre","kbd","samp","var","a","span","div","section","article","aside","header","footer","nav","figure","figcaption","img","picture","source","audio","video","sub","sup","hr","time","abbr","cite","q","table","thead","tbody","tfoot","tr","th","td","caption","colgroup","col"]),gn=/* @__PURE__ */new Set(["input","button","textarea","select","option","label"]),vn=/* @__PURE__ */new Set(["script","style","iframe","object","embed","link","meta","base","form","input","button","select","textarea","svg","math","template","frame","frameset","noframes","noscript"]),yn=/* @__PURE__ */new Set(["id","class","lang","dir","title","role","tabindex"]),bn="aria-",wn="data-",Sn={a:/* @__PURE__ */new Set(["href","target","rel","download","hreflang","type"]),img:/* @__PURE__ */new Set(["src","srcset","sizes","alt","width","height","loading","decoding"]),picture:/* @__PURE__ */new Set([]),source:/* @__PURE__ */new Set(["src","srcset","sizes","type","media"]),audio:/* @__PURE__ */new Set(["src","controls","autoplay","loop","muted","preload"]),video:/* @__PURE__ */new Set(["src","poster","controls","autoplay","loop","muted","preload","width","height","playsinline"]),time:/* @__PURE__ */new Set(["datetime"]),abbr:/* @__PURE__ */new Set(["title"]),q:/* @__PURE__ */new Set(["cite"]),blockquote:/* @__PURE__ */new Set(["cite"]),table:/* @__PURE__ */new Set(["summary"]),th:/* @__PURE__ */new Set(["colspan","rowspan","scope","headers","abbr"]),td:/* @__PURE__ */new Set(["colspan","rowspan","headers"]),col:/* @__PURE__ */new Set(["span"]),colgroup:/* @__PURE__ */new Set(["span"]),ol:/* @__PURE__ */new Set(["start","reversed","type"]),li:/* @__PURE__ */new Set(["value"]),code:/* @__PURE__ */new Set(["class"]),pre:/* @__PURE__ */new Set(["class"])},kn=/* @__PURE__ */new Set(["href","src","cite","poster"]),An=class extends Error{name="SanitizerEnvironmentError"},Tn=/* @__PURE__ */new Set(["id","name","data-payload-key","data-payload-nested-key","data-payload-nested-template"]),Cn=/* @__PURE__ */Symbol.for("payload-live-preview.sanitizer-document");function $n(e,t,n){const r=Rn();if(!r)throw"undefined"!=typeof __INLINE_BUILD__&&__INLINE_BUILD__?new Error("sanitizeHtml needs a DOM"):new An("sanitizeHtml needs a DOM; provide one with setSanitizerDocument() during SSR.");if(""===e)return"";const i=function(e,t){const n=e?.policy??t??"strict";if(!e){const e=/* @__PURE__ */new Map;for(const[t,n]of Object.entries(Sn))e.set(t,n);return{allowedTags:mn,attrByTag:e,allowFormControls:!1,templateMode:!1,mode:n,allowedData:/* @__PURE__ */new Set}}const r=new Set(mn);if(e.additionalAllowedTags?.forEach(e=>r.add(e)),!0===e.allowFormControls)for(const e of gn)r.add(e);const i=/* @__PURE__ */new Map;for(const[e,t]of Object.entries(Sn))i.set(e,t);for(const[t,n]of Object.entries(e.additionalAllowedAttributes??{})){const e=new Set(i.get(t));for(const t of n)e.add(t);i.set(t,e)}return{allowedTags:r,attrByTag:i,allowFormControls:!0===e.allowFormControls,templateMode:!0===e.templateMode,mode:n,allowedData:new Set(e.allowedDataAttributes?.map(e=>e.toLowerCase()))}}(n,t),o=r.createElement("template");return o.innerHTML=nn(e),Nn(o.content,i),o.innerHTML}function Rn(){if("undefined"==typeof __INLINE_BUILD__||!__INLINE_BUILD__){const e=globalThis[Cn];if(e)return e}if("undefined"!=typeof document)return document}function Nn(e,t){for(const n of Array.from(e.childNodes))1===n.nodeType?Pn(n,t):8===n.nodeType&&n.remove()}function Pn(e,t){const n=e.tagName.toLowerCase();if(!vn.has(n)||t.allowFormControls&&gn.has(n)){if(!t.allowedTags.has(n))return Nn(e,t),void e.replaceWith(...e.childNodes);!function(e,t,n){const r=n.attrByTag.get(t);for(const t of Array.from(e.attributes)){const i=t.name.toLowerCase();if(i.startsWith("on")||"style"===i)e.removeAttribute(t.name);else{if("strict"===n.mode){if(n.templateMode&&Tn.has(i))continue;if("id"===i||"name"===i||i.startsWith("data-payload-")){e.removeAttribute(t.name),"name"===i&&!0!==r?.has(i)||pn(i);continue}if(i.startsWith(wn)){n.allowedData.has(i)||(e.removeAttribute(t.name),pn(i));continue}if(yn.has(i)||i.startsWith(bn))continue}else if(yn.has(i)||i.startsWith(bn)||i.startsWith(wn))continue;r?.has(i)?kn.has(i)&&!isSafeUrl(t.value)?e.removeAttribute(t.name):"srcset"!==i||Ln(t.value)||e.removeAttribute(t.name):e.removeAttribute(t.name)}}}(e,n,t),"a"===n&&function(e){const t=e.getAttribute("href");null!==t&&isExternalHttpUrl(t)&&(e.setAttribute("rel","noopener noreferrer"),e.hasAttribute("target")||e.setAttribute("target","_blank"))}(e),Nn(e,t)}else e.remove()}function Ln(e){for(const t of e.split(",")){const e=t.trim();if(0===e.length)continue;const[n=e]=e.split(/\s/,1);if(!isSafeUrl(n))return!1}return!0}var Fn=Object.freeze({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"}),xn=/[&<>"'/`=]/g;function escapeHtml(e){return e.replace(xn,e=>Fn[e])}var Un=Object.freeze({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"}),Mn=/[&<>"']/g;function escapeHtmlAttribute(e){return e.replace(Mn,e=>Un[e])}var En=/\{\{([\s\S]*?)\}\}/g;function In(e){const t=/* @__PURE__ */new Set;for(const n of e)if("object"==typeof n&&null!==n)for(const e of Object.keys(n))t.add(e);return t}function On(e,t,n,r,i){const o="object"==typeof t&&null!==t?t:null;return e.replace(En,(e,s)=>null!==o&&function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(o,s)?escapeHtml(r(Reflect.get(o,s))):null===o&&"value"===s?escapeHtml(r(t)):"index"===s?String(n):null!==o&&!0===i?.has(s)?"":e)}function _n(e){const t=e.children,n=t[0];if(void 0===n)return[];const r=[];for(const{name:e,value:i}of Array.from(n.attributes)){if(!H(e)||e.startsWith("data-payload-"))continue;let n=!0;for(let r=1;r<t.length&&n;r+=1)n=t[r]?.getAttribute(e)===i;n&&r.push([e,i])}return r}function Dn(e,t){for(const[n,r]of t)e.hasAttribute(n)||e.setAttribute(n,r)}function zn(e){if(null==e)return"";if("string"==typeof e)return e;if("number"==typeof e||"boolean"==typeof e||"bigint"==typeof e)return String(e);try{return JSON.stringify(e)}catch{return""}}function Bn(e){return null==e||""===e}function Hn(e,t){const n=e.get(t);return void 0!==n&&(e.delete(t),e.set(t,n)),n}function jn(e,t,n,r){return e.set(t,n),function(e,t){for(const n of e.keys()){if(e.size<=t)break;e.delete(n)}}(e,r),n}var Wn=["input","textarea","select","option","button","label","details","summary","dialog","video","audio","progress","meter"],qn=["type","name","placeholder","open","disabled","readonly","required","checked","selected","value","min","max","step","rows","cols","for","controls","muted","loop","poster","src"],Vn=/<([a-z][a-z0-9]*(?:-[a-z0-9]+)+)\b/gi,Gn=/* @__PURE__ */new Map;function Kn(e){const t=Hn(Gn,e);if(void 0!==t)return t;const n=new Set(Wn);for(const t of e.matchAll(Vn)){const e=t[1]?.toLowerCase();void 0!==e&&n.add(e)}const r={};for(const e of n)r[e]=qn;const i={additionalAllowedTags:[...n],additionalAllowedAttributes:r,allowFormControls:!0,templateMode:!0};return jn(Gn,e,i,64)}var Jn="data-payload-key",Qn="data-payload-nested-key",Xn="data-payload-nested-template";function Zn(e){const t=er(e.container,e.patches,e);return null===t?null:tr(t,e.store,{morph:e.morph??!0,onDuplicateKey:e.onDuplicateKey})}function Yn(e,t){return t.hasAttribute(Qn)&&t.hasAttribute(Xn)}function er(e,t,n){const r=function(e,t,n){const{template:r,nextItems:i,forceRender:o=!1,store:s,sanitizerPolicy:a}=n,l=s.get(e),u=_n(e),c=In(i),d=Array.from(e.children),h=lr(d,Jn),f=/* @__PURE__ */new Set,p=[];for(let s=0;s<i.length;s+=1){const m=i[s],g=ar(m);let v=void 0===g?d[s]??null:ur(h,g)??null;null!==v&&f.has(v)&&(v=null),null!==v&&f.add(v);const y=t.replaces.has(s),b=o||t.renders.has(s)||null===v?cr(e.ownerDocument,r,m,s,a,u,c):void 0;if(null===b)return null;const w=void 0===b?[]:nr(y?null:v,b,m,void 0===g?void 0:l?.get(g),n);if(null===w)return null;p.push([s,v,b,w,y])}return p}(e,function(e){const t=/* @__PURE__ */new Set,n=/* @__PURE__ */new Set;for(const r of e)"insert"===r.kind||"update"===r.kind?t.add(r.index):"replace"===r.kind&&(t.add(r.index),n.add(r.index));return{renders:t,replaces:n}}(t),n);return null===r?null:[e,r,n.nextItems]}function tr(e,t,n){const[r,i,o]=e,s=/* @__PURE__ */new Set;let a=!1;const l=dn(r);for(const[e,o,l,u,c]of i){let i=o;if(void 0!==l){const e=!(!n.morph||c||null===o)&&an(o,l,{keyAttributes:[Jn,Qn],retainChildrenOf:Yn,...void 0!==n.onDuplicateKey?{onDuplicateKey:n.onDuplicateKey}:{}})===o;if(!e)for(const[e,t]of u)null!==e&&(ir(e,t),t.replaceWith(e));for(const[,,e]of u)void 0!==e&&tr(e,t,n);e?a=!0:(null!==o&&(o.replaceWith(l),a=!0),i=l)}if(null===i)continue;const d=r.children[e]??null;i!==d&&(r.insertBefore(i,d),a=!0),s.add(i)}for(const e of Array.from(r.children))s.has(e)||(e.remove(),a=!0);hn(l);const u=function(e,t){let n=t.get(e);return n||(n=/* @__PURE__ */new Map,t.set(e,n)),n}(r,t);u.clear();for(const e of o)sr(u,e);return a}function nr(e,t,n,r,i){const o=lr(null===e?[]:rr(e),Qn),s=[];for(const e of rr(t)){const t=e.getAttribute(Qn);if(null===t)continue;const a=ur(o,t)??null,l=e.getAttribute(Xn),u=l?a:null,c=u?.getAttribute(Xn)??null;let d;if(l){const o=or(n,t);if(void 0!==o||null!==u){const n=o??[],s=x(null===u?[]:or(r,t)??[],n),a=null!==u&&c!==l;if((s.length>0||a)&&(d=er(u??e,s,{template:l,nextItems:n,forceRender:a,store:i.store,sanitizerPolicy:i.sanitizerPolicy})??void 0,void 0===d))return null}}s.push([u,e,d])}return s}function rr(e){return Array.from(e.querySelectorAll(`[${Qn}]`)).filter(t=>{let n=t.parentElement;for(;null!==n&&n!==e;){if(n.hasAttribute(Qn))return!1;n=n.parentElement}return n===e})}function ir(e,t){for(const n of Array.from(e.attributes))t.hasAttribute(n.name)||e.removeAttribute(n.name);for(const n of Array.from(t.attributes))e.getAttribute(n.name)!==n.value&&e.setAttribute(n.name,n.value)}function or(e,t){if("object"!=typeof e||null===e)return;const n=e[t];return Array.isArray(n)?n:void 0}function sr(e,t){const n=ar(t);void 0!==n&&e.set(n,t)}function ar(e){if("object"!=typeof e||null===e)return;const t=e.id;return"string"==typeof t||"number"==typeof t?String(t):void 0}function lr(e,t){const n=/* @__PURE__ */new Map;for(let r=e.length-1;r>=0;r-=1){const i=e[r];if(void 0===i)continue;const o=i.getAttribute(t);if(null===o)continue;const s=n.get(o);void 0===s?n.set(o,[i]):s.push(i)}return n}function ur(e,t){return e.get(t)?.pop()}function cr(e,t,n,r,i,o,s){const a=$n(On(t,n,r,zn,s),i,Kn(t)),l=e.createElement("template");l.innerHTML=nn(a);const u=l.content.firstElementChild;if(!u)return null;Dn(u,o);const c=ar(n);return void 0!==c&&u.setAttribute(Jn,c),u}function dr(e,t,n){t.warnedFragmentFallback||(t.warnedFragmentFallback=!0,e.warn(`[live-preview] LP0806: "${n.fieldName}" asks for the fragment strategy but no handler is configured; patching instead`))}function hr(e,t,n){t.warnedStrategy.has(n.element)||(t.warnedStrategy.add(n.element),e.warn(`[live-preview] LP0407: "${n.fieldName}" asks for strategy "${String(n.strategy)}"; only patch, fragment and route exist`))}var fr=class{constructor(e,t,n){this.deps=e,this.state=t,this.host=n}deps;state;host;planFragments(e){const t=this.deps.strategies.fragment;return void 0===t?null:pr(t,t.plan(this.deps.root,e))}escalateUnfaithful(e,t,n){if(e.routeRefreshed)return;const{fragment:r,route:i}=this.deps.strategies,o=void 0===r?void 0:function(e){const t=[];for(const n of e){const e=n.fragmentBoundary;if(void 0===e)return;t.includes(e)||t.push(e)}return t}(n);if(void 0!==r&&void 0!==o)return this.state.escalatedCount+=n.length,e.pendingFragments+=o.length,void this.runFragments(e,t,pr(r,o));void 0!==i?(this.state.escalatedCount+=n.length,this.refreshRoute(e,t,i)):this.warnEscalationUnavailable(n.length)}warnEscalationUnavailable(e){const{deps:t,state:n}=this;n.warnedEscalationUnavailable||(n.warnedEscalationUnavailable=!0,t.warn(`[live-preview] LP0808: onUnfaithfulPatch: 'escalate' has nowhere to go: ${String(e)} field(s) fell short and no route or fragment strategy is configured. Set routeStrategy: true or fragments: { endpoint }, or onUnfaithfulPatch: 'warn' to keep the patch and say so.`))}hasUnboundChange(e,t){const{deps:n,state:r}=this;if(e.baseline||e.routeRefreshed)return!1;const i=de(n.cache,e.touched,e.locale,t);let o=0;for(const e of i)q(r,e)&&(o+=1);const[s]=i;return void 0!==s&&"escalate"===n.onUnfaithfulPatch&&(void 0===n.strategies.route?(this.warnEscalationUnavailable(i.length),!1):(n.log("route","LP0807",`field "${s}" has no binding; refreshing the route`),r.escalatedCount+=o,!0))}hasRouteBinding(e){for(const[t,n]of this.deps.cache.entries())if(e.has(t)&&n.some(e=>"route"===e.strategyKind))return!0;return!1}async runFragments(e,t,n){const{deps:r,state:i}=this,o=new AbortController;i.fragmentController=o;const s=()=>i.isCurrent(e)&&!o.signal.aborted,{emitter:a}=r,{message:l}=e,u=e.revision.revision,c=e.receivedAt,d={root:r.root,revision:u,receivedAt:c,fields:t.fields,locale:e.locale,collectionSlug:"string"==typeof l.collectionSlug?l.collectionSlug:void 0,globalSlug:"string"==typeof l.globalSlug?l.globalSlug:void 0,signal:o.signal,isCurrent:s,log:(e,t)=>{r.log("fragment",e,t)},morph:(e,t)=>{!function(e,t){const n=e.ownerDocument.createElement("template");n.innerHTML=nn(t);const r=e.cloneNode(!1);r.append(n.content),an(e,r,{keyAttributes:[Jn]})}(e,t)},patch:n=>{this.patchFallback(e,t,n)},rendered:(t,n,r)=>{e.pendingFragments-=1,a.emitWhile("fragmentRender",{element:t,id:n,key:r,status:"rendered",revision:u,receivedAt:c},s)},failed:(t,n,i,o,l)=>{e.pendingFragments-=1;const d=`fragment "${n}" fell back to patch: ${l}`;r.log("fragment",o,d),a.emitWhile("error",{error:new Error(d),context:"fragment",code:o},s),a.emitWhile("fragmentRender",{element:t,id:n,key:i,status:"failed",code:o,revision:u,receivedAt:c},s)}};let h={rendered:0,failed:0,superseded:0};try{h=await n.strategy.render(d,n.boundaries)}catch(i){if(r.log("fragment","LP0801",i),s()){for(const r of n.boundaries)this.patchFallback(e,t,r);h={rendered:0,failed:n.boundaries.length,superseded:0}}}i.fragmentStats.rendered+=h.rendered,i.fragmentStats.failed+=h.failed,i.fragmentStats.superseded+=h.superseded,s()&&(i.fragmentController===o&&(i.fragmentController=null),e.pendingFragments=0,h.rendered>0&&this.host.restoreGuesses(e,t),0===r.scheduler.pendingCount&&i.complete(e),this.host.revealPending(e),s()&&0!==h.rendered&&0!==a.listenerCount("afterUpdate")&&a.emitWhile("afterUpdate",{data:t,updatedCount:h.rendered,durationMs:Date.now()-c,revision:u,receivedAt:c,source:"fragment"},s))}async refreshRoute(e,t,n){const{deps:r,state:i}=this;if(e.routeRefreshed)return i.routeStats.loopStopped+=1,void r.log("route","LP0805",`revision ${String(e.revision.revision)} asked for a second refresh`);e.routeRefreshed=!0,await this.runRoute(e,t,n)}armRouteRetry(e,t,n,r){const{state:i}=this;null!==i.routeRetry&&clearTimeout(i.routeRetry),i.routeRetry=setTimeout(()=>{i.routeRetry=null,i.isCurrent(e)&&this.runRoute(e,t,n)},r)}async runRoute(e,t,n){const{deps:r,state:i}=this,o=i.routeStats,s=new AbortController;i.routeController=s;const a=()=>i.isCurrent(e)&&!s.signal.aborted;let l;try{l=await n.refresh({revision:e.revision.revision,receivedAt:e.receivedAt,signal:s.signal,isCurrent:a,log:(e,t)=>{r.log("route",e,t)},retryAfter:r=>{this.armRouteRetry(e,t,n,r)}})}catch(e){r.log("route","LP0801",e),l="failed"}if(a()){if(i.routeController===s&&(i.routeController=null),"refreshed"===l){if(o.refreshes+=1,i.lastAppliedIdentity=/* @__PURE__ */new WeakMap,this.host.restoreGuesses(e,t),this.host.rebuildCache(),!a())return;return this.host.reapply(e,t),void(r.emitter.listenerCount("afterUpdate")>0&&r.emitter.emitWhile("afterUpdate",{data:t,updatedCount:r.cache.elementCount,durationMs:Date.now()-e.receivedAt,revision:e.revision.revision,receivedAt:e.receivedAt,source:"route"},a))}"failed"===l?o.failed+=1:"refused"===l&&(o.refused+=1),this.host.reapply(e,t)}}warnFragmentFallback(e){dr(this.deps,this.state,e)}warnUnsupportedStrategy(e){hr(this.deps,this.state,e)}patchFallback(e,t,n){for(const[r,i]of this.deps.cache.entries())for(const o of i){if(o.fragmentBoundary!==n)continue;const i=Qt(t.fields,o,r,e.locale);void 0!==i&&this.deps.scheduler.schedule({target:o,value:this.host.transform(o,i,t.fields,()=>!0),allFields:t.fields,revision:e.revision,data:t})}}};function pr(e,t){const n=new Set(t);return{boundaries:t,strategy:e,covers:e=>void 0!==e.fragmentBoundary&&n.has(e.fragmentBoundary)}}function mr(e,t,n,r,i){const o=e.transformValue;if(void 0===o)return n;try{const e=o(t.fieldName,n,{element:t.element,allFields:r},i),s=h(e);if(!i())return n;if(s)throw new TypeError(`Transform for "${t.fieldName}" returned a thenable; transforms must be synchronous`);return e}catch(t){if(!i())return n;const r=t instanceof Error?t:new Error(String(t));return e.emitter.emit("error",{error:r,context:"transform",code:"LP0602"}),n}}var gr=/* @__PURE__ */new Set,vr=class{constructor(e,t,n){this.deps=e,this.state=t,this.strategies="undefined"!=typeof __LEAN_BUILD__&&__LEAN_BUILD__?function(e,t){return{planFragments:()=>null,escalateUnfaithful:()=>{},hasUnboundChange:(n,r)=>{if(n.baseline)return!1;const i=de(e.cache,n.touched,n.locale,r);for(const e of i)q(t,e);return!1},hasRouteBinding:()=>!1,runFragments:()=>Promise.resolve(),refreshRoute:()=>(k("route refreshes"),Promise.resolve()),warnFragmentFallback:n=>{k("server-rendered fragments"),dr(e,t,n)},warnUnsupportedStrategy:n=>{hr(e,t,n)}}}(e,t):new fr(e,t,{reapply:(e,t)=>{this.scheduleAllFields(e,t)},transform:(t,n,r,i)=>mr(e,t,n,r,i),rebuildCache:n,restoreGuesses:(e,t)=>{this.restoreGuesses(e,t)},revealPending:e=>{this.revealPending(e)}})}deps;state;strategies;handleUpdate(e,t,n){const{deps:r,state:i}=this;if(r.heartbeat.kick(),i.protocol.observe(function(e){const t=[];return Array.isArray(e.fieldSchemaJSON)&&t.push("schema-json"),"string"==typeof e.locale&&t.push("locale"),"string"==typeof e.previewToken&&t.push("preview-token"),"object"==typeof e.externallyUpdatedRelationship&&null!==e.externallyUpdatedRelationship&&t.push("relationship-events"),t}(e),r.log),void 0===e.data)return void(void 0!==e.protocolVersion&&i.protocol.applyVersion(e.protocolVersion,r.log));if(void 0===n)return;const o=i.relationships.edit(e);null!==o&&r.emitter.emit("relationshipUpdate",{detail:o,timestamp:Date.now()}),"string"==typeof e.locale&&(i.locale=e.locale),Array.isArray(e.fieldSchemaJSON)&&(i.schema=e.fieldSchemaJSON,i.schemaIndex=R(e.fieldSchemaJSON));const s={revision:n,message:e,locale:i.locale,schema:i.schema,schemaIndex:i.schemaIndex,receivedAt:Date.now(),forceRender:null!==o||we(i.activeUpdate),touched:/* @__PURE__ */new Set,baseline:!1,invalidated:/* @__PURE__ */new Set,revealTarget:void 0,revealIdentities:[],pendingFragments:0,routeRefreshed:!1,cancelled:!1,completed:!1},a=i.activeUpdate;if(i.abortStrategies(),null===a||a.completed||(i.supersededCount+=1),i.activeUpdate=s,r.scheduler.acceptRevision(n),i.updateCount+=1,void 0===e.protocolVersion||(i.protocol.applyVersion(e.protocolVersion,r.log),i.isCurrent(s))){if(r.connection.markConnected()){if(r.a11y?.announceConnected(),r.emitter.emit("connect",{origin:t,timestamp:Date.now()}),!i.isCurrent(s))return;if(r.log("connection","disconnected","→","connected"),!i.isCurrent(s))return}this.processUpdate(s).catch(e=>{r.log("update failed:",e)})}}async processUpdate(e){const{deps:t,state:n}=this,r=await this.resolveIncomingFields(e);if(null===r||!n.isCurrent(e))return;const i=this.dataFor(e,r);t.emitter.listenerCount("beforeUpdate")>0&&(!await t.emitter.emitWhile("beforeUpdate",{data:i,revision:e.revision.revision,receivedAt:e.receivedAt,source:"patch",cancel:()=>{e.cancelled=!0,t.scheduler.cancelRevision(e.revision)}},()=>!e.cancelled&&n.isCurrent(e))||e.cancelled||!n.isCurrent(e))||this.applyFields(e,i,!1)}dataFor(e,t){const{message:n}=e;return{fields:t,...void 0!==e.schema?{schema:e.schema}:{},..."string"==typeof n.globalSlug?{globalSlug:n.globalSlug}:{},..."string"==typeof n.collectionSlug?{collectionSlug:n.collectionSlug}:{},...void 0!==e.locale?{locale:e.locale}:{}}}applyFields(e,t,n){const{deps:r,state:i}=this,o=Re(r.dependencies,r.cache.dependencyMap()),s=i.changes.diff(t.fields,o);if(s.baseline&&!n&&"off"!==r.autoBind)if("undefined"!=typeof __LEAN_BUILD__&&__LEAN_BUILD__)k("auto-binding");else{const n=this.ownerKeysForUpdate(e,t.fields);!function(e,t,n,r,i){const o=performance.now(),s=qt(e.root),a=Ot(n,r),l=null===s?[]:Vt(e,Wt(s,a),i,"on the first message");t.autoBindGuesses=function(e,t){const n=/* @__PURE__ */new Set;for(const{fieldName:e,stamps:r}of t){n.add(e);for(const e of[Ie,_e]){const t=r[e];void 0!==t&&n.add(t)}}const r=/* @__PURE__ */new Map;for(const[t,i]of e)null!==i&&n.has(i.field)&&r.set(t,i);return{fields:n,values:r}}(a,l),t.autoBindSearchMs=performance.now()-o,l.length}(r,i,t.fields,e.locale,n)}e.baseline=s.baseline,e.invalidated=n?gr:s.invalidated,e.touched=n?gr:/* @__PURE__ */new Set([...s.changed,...s.invalidated]),this.scheduleAllFields(e,t)}async resolveIncomingFields(e){const{deps:t,state:n}=this,r=e.message.data??{};if(null===t.merger)return r;if("admin"===detectProtocolProfile(n.protocol.observed).populatesRelationships)return r;const i=n.merges.decide(t,e);if(!i.merge)return i.fields;const{message:o}=e,s=n.merges.request(t.merger,t.mergeWindowMs,{collectionSlug:o.collectionSlug,globalSlug:o.globalSlug,data:r,locale:e.locale});if(!s.leading)return this.applyMerged(e,s.result).catch(e=>{t.log("update failed:",e)}),i.fields;const a=await s.result;return n.isCurrent(e)?"merged"===a.status?(n.merges.recordMerged(a.doc),a.doc):"superseded"===a.status?null:i.fields:null}async applyMerged(e,t){const{state:n}=this,r=await t;"merged"===r.status&&n.isCurrent(e)&&(n.merges.recordMerged(r.doc),this.applyFields(e,this.dataFor(e,r.doc),!0))}scheduleAllFields(e,t){const{deps:n,state:r}=this;if(!r.isCurrent(e))return;const i=()=>r.isCurrent(e),o=this.ownerKeysForUpdate(e,t.fields),{touched:s}=e,a=n.strategies.route,l=this.strategies.hasUnboundChange(e,o),u=r.routeRefreshOwed;if(void 0!==a&&!e.routeRefreshed&&(l||u||a.plan(n.root,s)||this.strategies.hasRouteBinding(s)))return r.routeRefreshOwed=!1,void this.strategies.refreshRoute(e,t,a);const c=this.strategies.planFragments(s),d=n.skipUnchanged;let h=0;for(const[s,a]of n.cache.entries()){if(!i())return;for(const l of a){if(!1!==o&&!ie(l.owner,o))continue;if(!0===c?.covers(l)){if(n.revealEditedField){const n=Qt(t.fields,l,s,e.locale);r.revealLedger.note(e,l,n)}continue}const a=l.strategyKind??te(l.element)??"unknown";if("unknown"===a){this.strategies.warnUnsupportedStrategy(l);continue}"fragment"===a&&null===c&&this.strategies.warnFragmentFallback(l);const u=Qt(t.fields,l,s,e.locale);if(void 0===u){r.absentFields.add(s);continue}if(n.revealEditedField&&r.revealLedger.note(e,l,u),!i())return;const f=mr(n,l,u,t.fields,i);if(!i())return;const p=d?Xt(l,f,t.fields,e.locale):void 0,m=r.lastAppliedIdentity.get(l.element);if(!e.forceRender&&n.skipUnchanged&&void 0!==p&&m===p&&!e.invalidated.has(s)){r.skippedUnchangedCount+=1;continue}const g={target:l,value:f,allFields:t.fields,revision:e.revision,data:t,valueIdentity:p};n.scheduler.schedule(g),h+=1}}(function(e,t,n,r){const{cache:i}=e;if(0===i.fieldCount)return;if(!1!==r&&!function(e,t){for(const n of e.values())if(ie(n.owner,t))return!0;return!1}(i,r))return;const o=ce(i,n,r);for(const[r,i]of Object.entries(t)){if(se.has(r))continue;if(Yt(i)){Zt(e,o,r,n,i);continue}if(!en(i)||o(r))continue;const t=ue(r,n);for(const[r,s]of Object.entries(i))Yt(s)&&!se.has(r)&&Zt(e,o,`${t}.${r}`,n,s)}})({cache:n.cache,warned:r.warnedOrphanFields,warn:n.warn},t.fields,e.locale,o),null!==c&&c.boundaries.length>0&&(e.pendingFragments=c.boundaries.length,this.strategies.runFragments(e,t,c)),0===h&&0===e.pendingFragments&&(r.complete(e),this.revealPending(e),this.notifyIslands(e,t))}notifyIslands(e,t){0!==e.touched.size&&function(e,t){for(const n of e)n.dispatchEvent(new CustomEvent("payload-live-preview:update",{detail:t,bubbles:!1}));e.length}(this.deps.cache.islands,{fields:t.fields,revision:e.revision.revision,receivedAt:e.receivedAt,locale:e.locale})}restoreGuesses(e,t){const{deps:n,state:r}=this;if("off"!==n.autoBind&&null!==r.autoBindGuesses&&("undefined"==typeof __LEAN_BUILD__||!__LEAN_BUILD__)){const i=this.ownerKeysForUpdate(e,t.fields);!function(e,t,n,r,i){const o=t.autoBindGuesses,s=qt(e.root);if(null===o||0===o.fields.size||null===s)return 0;const a=new Map(o.values);for(const[e,t]of Ot(n,r)){if(null===t||!o.fields.has(t.field))continue;const n=a.get(e);void 0===n?a.set(e,t):n?.field!==t.field&&a.set(e,null)}Vt(e,Wt(s,a),i,"after a server render").length}(n,r,t.fields,e.locale,i)}}ownerKeysForUpdate(e,t){const{deps:n,state:r}=this;if(!n.scopeBindingsByOwner)return!1;const{message:i}=e,o=function(e){if(re(e.globalSlug))return[(t=e.globalSlug,`global:${t}`)];var t;if(!re(e.collectionSlug))return null;const n=ne(e.collectionSlug);return re(e.documentId)?[n,ne(e.collectionSlug,e.documentId)]:[n]}({globalSlug:"string"==typeof i.globalSlug?i.globalSlug:void 0,collectionSlug:"string"==typeof i.collectionSlug?i.collectionSlug:void 0,documentId:oe(t)});return null!==o||r.warnedUnattributableMessage||(r.warnedUnattributableMessage=!0,n.warn("[live-preview] LP0202: scopeBindingsByOwner: update names no document; nothing applied")),o}onFlush(e){const{deps:t,state:n}=this;n.lastFlush=e,e.deferred>0&&!n.warnedVisibilityGate&&(n.warnedVisibilityGate=!0,t.warn(`[live-preview] LP0301: visibility gate held ${String(e.deferred)} off-screen update(s) until scrolled into view; see visibilityGateThreshold`));const{revision:r,data:i}=e;if(void 0===r)return;const o=n.activeUpdate;if(null===o||!n.isCurrent(o)||!f(o.revision,r))return;0===o.pendingFragments&&n.complete(o);const s=()=>n.isCurrent(o)&&f(o.revision,r);if(this.revealPending(o),!s())return;const a=n.unfaithfulPatches;a.length>0&&(n.unfaithfulPatches=[],void 0!==i&&this.strategies.escalateUnfaithful(o,i,a),!s())||void 0!==i&&(e.applied>0&&t.a11y?.announceUpdate(e.applied),s()&&(this.notifyIslands(o,i),s()&&0!==e.applied&&0!==t.emitter.listenerCount("afterUpdate")&&t.emitter.emitWhile("afterUpdate",{data:i,updatedCount:e.applied,durationMs:e.durationMs,revision:r.revision,receivedAt:o.receivedAt,source:"patch"},s)))}revealPending(e){const t=this.state.revealLedger.commit(e);if(void 0!==t)try{this.revealBinding(t)}catch(e){this.deps.log("reveal",e)}}revealField(e){const t=this.deps.cache.get(e)?.[0];return void 0===t?"no-element":this.revealBinding(t)}revealBinding(e){const{element:t}=e,n=t.ownerDocument.defaultView;if(null===n)return"no-element";const r=`${e.owner??""} ${e.fieldName}`;return this.state.revealer.reveal(r,t,n)}},yr=class{apply;debounceMs;maxWaitMs;isVisible;gateThresholdValue;gateDisabled;getCacheSize;onFlush;scheduleFrame;cancelFrame;pending=/* @__PURE__ */new Map;replay=/* @__PURE__ */new Map;activeFlushes=/* @__PURE__ */new Set;debounceTimer=null;debounceToken=0;deadlineTimer=null;frameHandle=null;frameToken=0;windowUntil=0;activeRevision=null;activeRevisionCancelled=!1;constructor(e,t){this.apply=e,this.debounceMs=t.debounceMs??50,this.maxWaitMs=t.maxWaitMs??4*this.debounceMs,this.isVisible=t.isVisible,this.gateThresholdValue=t.visibilityGateThreshold??50,this.gateDisabled=t.disableVisibilityGate??!1,this.getCacheSize=t.getCacheSize,this.onFlush=t.onFlush,this.scheduleFrame=t.scheduleFrame??("function"==typeof requestAnimationFrame?requestAnimationFrame.bind(globalThis):e=>setTimeout(()=>{e(performance.now())},0)),this.cancelFrame=t.cancelFrame??("function"==typeof cancelAnimationFrame?cancelAnimationFrame.bind(globalThis):e=>{clearTimeout(e)})}schedule(e){if(void 0!==e.revision){if(this.activeRevisionCancelled)return;if(null===this.activeRevision||!f(e.revision,this.activeRevision))return}const t=this.pending.get(e.target.element);t?(t.value=e.value,t.allFields=e.allFields,t.revision=e.revision,t.data=e.data,t.valueIdentity=e.valueIdentity):this.pending.set(e.target.element,{target:e.target,value:e.value,allFields:e.allFields,revision:e.revision,data:e.data,valueIdentity:e.valueIdentity}),this.armDebounce()}acceptRevision(e){var t,n;null!==this.activeRevision&&f(e,this.activeRevision)||null!==this.activeRevision&&(t=e,n=this.activeRevision,(t.generation!==n.generation?t.generation-n.generation:t.revision-n.revision)<0)||(this.cancelScheduledWork(),this.clearWork(),this.activeRevision=e,this.activeRevisionCancelled=!1)}cancelRevision(e){null!==this.activeRevision&&f(e,this.activeRevision)&&(this.cancelScheduledWork(),this.clearWork(),this.activeRevisionCancelled=!0)}flushNow(){return this.cancelScheduledWork(),this.flush()}notifyVisible(e){const t=this.replay.get(e);if(!t)return;if(this.replay.delete(e),!this.isCurrent(t))return;const n=performance.now(),r=this.didApply(t)?1:0;this.onFlush?.(this.statsFor(t,r,0,performance.now()-n,1===r?[t.target.fieldName]:[]))}retarget(e){this.retargetBuffer(this.pending,e),this.retargetBuffer(this.replay,e);for(const t of this.activeFlushes)this.retargetBuffer(t,e)}forget(e){this.pending.delete(e),this.replay.delete(e);for(const t of this.activeFlushes)t.delete(e)}destroy(){this.cancelScheduledWork(),this.clearWork(),this.activeRevision=null,this.activeRevisionCancelled=!1,this.windowUntil=0}get pendingCount(){return this.pending.size}get replayCount(){return this.replay.size}get gateThreshold(){return this.gateThresholdValue}get gateActive(){return!this.gateDisabled&&this.getCacheSize()>this.gateThresholdValue}armDebounce(){const e=Date.now(),t=e>=this.windowUntil;if(this.windowUntil=e+this.debounceMs,t)return void this.requestFrame();const n=this.debounceToken+=1,r=this.debounceTimer;if(this.debounceTimer=null,null!==r&&clearTimeout(r),this.debounceToken!==n)return;const i=setTimeout(()=>{this.debounceToken===n&&(this.debounceTimer=null,this.pending.size>0&&this.requestFrame())},this.debounceMs);this.debounceToken===n&&(this.debounceTimer=i),null===this.deadlineTimer&&this.maxWaitMs>this.debounceMs&&(this.deadlineTimer=setTimeout(()=>{this.deadlineTimer=null,this.pending.size>0&&this.requestFrame()},this.maxWaitMs))}requestFrame(){const e=this.frameToken+=1,t=this.frameHandle;if(this.frameHandle=null,null!==t&&this.cancelFrame(t),this.frameToken!==e)return;let n=!1;const r=this.scheduleFrame(()=>{this.frameToken===e&&(n=!0,this.frameHandle=null,this.flush())});n||this.frameToken!==e||(this.frameHandle=r)}flush(){const e=performance.now();this.clearDeadline();const t=this.gateActive,n=this.pending;this.pending=/* @__PURE__ */new Map;let r=0;const i=[];let o,s=0;this.activeFlushes.add(n);try{for(const e of n.values()){if(!this.isCurrent(e))continue;const n=!t||this.isVisible(e.target.element);this.isCurrent(e)&&(o??=e,n?(this.replay.delete(e.target.element),this.didApply(e)&&(r+=1,i.push(e.target.fieldName))):(this.replay.set(e.target.element,e),s+=1))}}finally{this.activeFlushes.delete(n)}const a=this.statsFor(o,r,s,performance.now()-e,i);return this.onFlush?.(a),a}isCurrent(e){return void 0===e.revision||!this.activeRevisionCancelled&&null!==this.activeRevision&&f(e.revision,this.activeRevision)}didApply(e){return!1!==this.apply(e)||(t=this.apply,!J.has(t));var t}retargetBuffer(e,t){const n=e.get(t.element);void 0!==n&&(n.target.fieldName===t.fieldName&&n.target.locale===t.locale?n.target=t:e.delete(t.element))}clearWork(){this.pending.clear(),this.replay.clear();for(const e of this.activeFlushes)e.clear()}statsFor(e,t,n,r,i){return{applied:t,appliedFields:i,deferred:n,durationMs:r,...void 0!==e?.revision?{revision:e.revision}:{},...void 0!==e?.data?{data:e.data}:{}}}clearDeadline(){null!==this.deadlineTimer&&(clearTimeout(this.deadlineTimer),this.deadlineTimer=null)}cancelScheduledWork(){const e=this.debounceTimer,t=this.frameHandle;this.debounceToken+=1,this.frameToken+=1,this.debounceTimer=null,this.frameHandle=null,this.clearDeadline(),null!==e&&clearTimeout(e),null!==t&&this.cancelFrame(t)}},br=[0,500,1e3,2e3],wr=class{deps;state=new Ce;pipeline;writer;rootSentinel=null;observedRoot=null;constructor(e){const{emitter:t,renderers:n}=e,r=void 0===e.log?g:m(e.log),i=void 0===e.warn?y:m(e.warn),o=e.root??("undefined"!=typeof document?document:void 0);if(void 0===o)throw new Error("LivePreviewRuntime: no document; pass options.root");const s=new it({filter:e=>!function isInsideIsland(e){let t=e;for(;null!==t;){if(xe(t))return!0;t=t.parentElement}return!1}(e)}),a=new pt({onStructuralChange:()=>{this.rebuildCache()},onVisibilityChange:(e,t)=>{t&&l.notifyVisible(e)}},void 0!==e.intersectionRootMargin?{intersectionRootMargin:e.intersectionRootMargin}:{}),l=new yr(Q(e=>this.writer.apply(e)),{...void 0!==e.debounceMs?{debounceMs:e.debounceMs}:{},...void 0!==e.disableVisibilityGate?{disableVisibilityGate:e.disableVisibilityGate}:{},...void 0!==e.visibilityGateThreshold?{visibilityGateThreshold:e.visibilityGateThreshold}:{},isVisible:e=>a.isVisible(e),getCacheSize:()=>s.elementCount,onFlush:e=>{this.pipeline.onFlush(e)}}),u=new p(e.originMatcher,{onUpdate:(e,t,n)=>{this.pipeline.handleUpdate(e,t,n)},onDocumentEvent:()=>{this.state.protocol.observe(["document-events"],r),t.emit("documentSave",{timestamp:Date.now()})},onFocusField:e=>{this.deps.revealEditedField&&this.pipeline.revealField(e)},onInvalid:(e,n)=>{if("token"===e){const e=new Error(`Preview token rejected (origin: ${n})`);t.emit("error",{error:e,context:"token",code:"LP0502"})}"shape"!==e&&"type"!==e||this.state.warnedProtocolShape||(this.state.warnedProtocolShape=!0,i(`[live-preview] LP0503: ${n} posted a message this runtime does not recognise (${"type"===e?"unknown message type":"unexpected shape"}); it was ignored. A newer Payload or a custom sender: check that the versions match.`)),"source"!==e||this.state.warnedForeignSource||(this.state.warnedForeignSource=!0,i(`[live-preview] LP0501: a message from ${n} was ignored because it did not come from the window that framed or opened this page. \`eventSourcePolicy\` is 'parent-or-opener' by default since 2.0, where 1.x accepted any window on a trusted origin. Set \`eventSourcePolicy: 'any'\` if the admin posts from elsewhere.`)),r("LP0501 message rejected:",e,n)},...void 0!==e.validateToken?{validateToken:e.validateToken}:{},...void 0!==e.eventSourcePolicy?{sourcePolicy:e.eventSourcePolicy}:{}}),c=e.dataMerge;this.deps={emitter:t,cache:s,observers:a,scheduler:l,bus:u,connection:new Pt,heartbeat:new Nt({...void 0!==e.heartbeatMs?{timeoutMs:e.heartbeatMs}:{},onTimeout:()=>{this.onHeartbeatTimeout()}}),renderers:n,resolveRenderer:e.resolveRenderer??(e=>n[e]),transformValue:e.transformValue,renderRichText:e.renderRichText,sanitizerPolicy:e.sanitizerPolicy,root:o,readyTargets:"function"==typeof e.readyTargets?e.readyTargets:/* @__PURE__ */(e=>()=>e)(e.readyTargets),sendReady:e.sendReady??T,onHeartbeatTimeout:e.onHeartbeatTimeout,log:r,warn:i,a11y:A(e),merger:void 0===c?null:new ut({serverURL:c.serverURL,...void 0!==c.apiRoute?{apiRoute:c.apiRoute}:{},...void 0!==c.depth?{depth:c.depth}:{},...void 0!==c.fetchFn?{fetchFn:c.fetchFn}:{},log:r}),mergeWindowMs:e.debounceMs??50,scopeBindingsByOwner:!0===e.scopeBindingsByOwner,lockedOrigin:e.lockedOrigin??(()=>{}),skipUnchanged:!0===e.skipUnchanged,dependencies:e.dependencies??{},strategies:e.strategies??{},revealEditedField:!0===e.revealEditedField,onUnfaithfulPatch:j(e),autoBind:e.autoBind??"off",hydration:e.hydration},this.writer=new $e(this.deps,this.state),this.pipeline=new vr(this.deps,this.state,()=>{this.rebuildCache()})}start(){const{state:e}=this;if(e.isRunning())return!1;e.started=!0,e.suspended=!1;try{return function(e){"react"===e.hydration?yt():"vue"===e.hydration&&Ct();const{root:t}=e;if(!function(e){return 9===e.nodeType}(t)||"loading"!==t.readyState)return void $t(e);const n=()=>{e.isRunning()&&e.later(()=>{$t(e)})};t.addEventListener("DOMContentLoaded",n,{once:!0}),e.defer(()=>{t.removeEventListener("DOMContentLoaded",n)})}(this.startupHost()),!0}catch(e){throw this.rollbackFailedStart(),e}}startupHost(){const{state:e,deps:t}=this;return{root:t.root,hydration:t.hydration,isRunning:()=>e.isRunning(),defer:t=>{e.deferredStart=t},later:t=>{e.deferredStart=null;try{t()}catch(e){this.rollbackFailedStart(),this.reportError(e,"startup","LP0605")}},hydrated:t=>{e.hydration=t},warn:t.warn,startNow:()=>{this.startNow()}}}startNow(){const{state:e,deps:t}=this;if(!e.isRunning())return;const n=Sr(t.root)?kr(t.root):t.root;if(null===n)throw new Error("LivePreviewRuntime: document.body unavailable");if(t.observers.start(n),this.observedRoot=n,this.watchRootReplacement(),this.buildCacheAndObserve(),e.isRunning()&&(t.bus.attach(),t.emitter.emitWhile("init",{timestamp:Date.now()},()=>e.isRunning()),e.isRunning()))for(const n of br){if(!e.isRunning())return;0===n?t.sendReady(t.readyTargets()):e.readyTimers.push(setTimeout(()=>{e.isRunning()&&this.sendReadyAfterStart()},n))}}suspend(){if(!this.state.isRunning())return!1;const e=this.release();return this.state.suspended=!0,e&&this.deps.emitter.emit("disconnect",{reason:"unload",timestamp:Date.now()}),!0}destroy(){const{state:e,deps:t}=this;if(!e.isRunning()&&!e.suspended)return;const n=!!e.isRunning()&&this.release();e.suspended=!1,n&&t.emitter.emit("disconnect",{reason:"destroy",timestamp:Date.now()}),t.a11y?.detach(),t.emitter.emit("destroy",{timestamp:Date.now()})}release(){const{state:e,deps:t}=this;e.activeUpdate=null,e.started=!1;const n=e.deferredStart;e.deferredStart=null,null!==n&&this.runCleanup(n);for(const t of e.readyTimers)this.runCleanup(()=>{clearTimeout(t)});return e.readyTimers.length=0,this.runCleanup(()=>{t.heartbeat.stop()}),this.runCleanup(()=>{t.bus.detach()}),e.abortStrategies(),this.runCleanup(()=>{this.rootSentinel?.disconnect(),this.rootSentinel=null,this.observedRoot=null}),this.runCleanup(()=>{t.observers.stop()}),this.runCleanup(()=>{t.scheduler.destroy()}),this.runCleanup(()=>{t.merger?.destroy(),e.merges.destroy()}),t.cache.clear(),t.connection.markDisconnected()}rollbackFailedStart(){this.release(),this.runCleanup(()=>{this.deps.a11y?.detach()})}runCleanup(e){try{e()}catch(e){this.deps.log("cleanup failed:",e)}}refreshCache(){this.state.isRunning()&&(this.state.revealer.reset(),this.followReplacedRoot()||this.rebuildCache())}watchRootReplacement(){const{root:e}=this.deps;Sr(e)&&"undefined"!=typeof MutationObserver&&(this.rootSentinel?.disconnect(),this.rootSentinel=new MutationObserver(()=>{this.followReplacedRoot()}),this.rootSentinel.observe(e.documentElement,{childList:!0}))}followReplacedRoot(){const{root:e}=this.deps;if(!this.state.isRunning()||!Sr(e))return!1;const t=kr(e);return null!==t&&t!==this.observedRoot&&(this.observedRoot=t,this.deps.observers.start(t),this.rebuildCache(),!0)}get status(){return this.deps.connection.status}get cache(){return this.deps.cache}get updateCount(){return this.state.updateCount}get protocol(){return this.state.protocol.negotiation}inspect(){return function(e,t){const{cache:n,scheduler:r}=e,i=t.protocol.negotiation,o=t.activeUpdate,s=t.lastFlush,a=[],l=/* @__PURE__ */new Set,u=[];for(const[e,t]of n.entries()){a.push(e);for(const n of t)void 0!==n.owner&&l.add(n.owner),void 0!==n.guessed&&u.push({field:e,matched:n.guessed,attribute:n.targetAttribute??("IMG"===n.element.tagName?"src":void 0)})}return{version:ct,started:t.started,status:e.connection.status,origins:{trusted:[...e.readyTargets()],locked:e.lockedOrigin()},protocol:{ours:i.ours,theirs:i.theirs,negotiated:i.negotiated,capabilities:[...i.capabilities].sort(),observed:[...i.observed].sort(),profile:detectProtocolProfile(i.observed).name},revisions:{accepted:t.updateCount,superseded:t.supersededCount,completed:t.completedCount,skippedUnchanged:t.skippedUnchangedCount,active:null===o?void 0:o.revision.revision},bindings:{elements:n.elementCount,fields:n.fieldCount,fieldNames:a.sort(),absentFields:[...t.absentFields].sort(),orphanFields:[...t.warnedOrphanFields].sort(),ownerScoped:e.scopeBindingsByOwner,owners:[...l].sort(),guessed:u.sort((e,t)=>e.field.localeCompare(t.field)),autoBind:{mode:e.autoBind,searchMs:t.autoBindSearchMs}},route:{handler:void 0!==e.strategies.route,...t.routeStats},fidelity:{mode:e.onUnfaithfulPatch,canEscalate:void 0!==e.strategies.fragment||void 0!==e.strategies.route,unfaithful:t.unfaithfulCount,escalated:t.escalatedCount,fields:[...t.unfaithfulFields].sort()},hydration:{mode:e.hydration??"off",state:t.hydration},fragments:{handler:void 0!==e.strategies.fragment,inFlight:o?.pendingFragments??0,...t.fragmentStats},scheduler:{pending:r.pendingCount,deferred:r.replayCount,visibilityGateThreshold:r.gateThreshold,visibilityGateActive:r.gateActive,lastFlush:null===s?void 0:{applied:s.applied,appliedFields:s.appliedFields,deferred:s.deferred,durationMs:s.durationMs}},plugins:[],renderers:Object.keys(e.renderers).sort()}}(this.deps,this.state)}buildCacheAndObserve(){const{state:e,deps:t}=this;if(!e.isRunning())return;const n=t.cache.buildFromRoot(t.root);if(t.log("cache",n),e.isRunning()&&(t.emitter.emitWhile("cacheRefresh",n,()=>e.isRunning()),e.isRunning()))for(const n of t.cache.values()){if(!e.isRunning())return;t.observers.observeElement(n.element)}}rebuildCache(){const{state:e,deps:t}=this;if(!e.isRunning())return;const n=/* @__PURE__ */new Map;for(const e of t.cache.values())n.set(e.element,e),t.observers.unobserveElement(e.element);if(this.buildCacheAndObserve(),e.isRunning()){for(const e of t.cache.values()){const r=n.get(e.element);r?.fieldName===e.fieldName?t.scheduler.retarget(e):t.scheduler.forget(e.element),n.delete(e.element)}for(const e of n.values())t.scheduler.forget(e.element)}}onHeartbeatTimeout(){const{state:e,deps:t}=this;if(!e.isRunning())return;t.bus.advanceGeneration();const n=e.activeUpdate;e.activeUpdate=null,null!==n&&t.scheduler.cancelRevision(n.revision),t.merger?.destroy(),e.merges.destroy();const r=t.connection.markDisconnected();try{t.onHeartbeatTimeout?.()}catch(e){t.log("heartbeat:",e)}if(e.isRunning()){if(r&&this.isIdleDisconnected()){if(t.a11y?.announceDisconnected(),t.emitter.emitWhile("disconnect",{reason:"timeout",timestamp:Date.now()},()=>this.isIdleDisconnected()),!e.isRunning())return;if(this.isIdleDisconnected()&&t.log("connection","connected","→","disconnected"),!e.isRunning())return}this.sendReadyAfterStart()}}sendReadyAfterStart(){try{this.deps.sendReady(this.deps.readyTargets())}catch(e){this.reportError(e,"ready","LP0606")}}reportError(e,t,n){const r=e instanceof Error?e:new Error(String(e));this.deps.emitter.emit("error",{error:r,context:t,code:n})}isIdleDisconnected(){return this.state.isRunning()&&"disconnected"===this.deps.connection.status&&null===this.state.activeUpdate}};function Sr(e){return 9===e.nodeType}function kr(e){return e.body}var EventEmitter=class{#t=/* @__PURE__ */new Map;#n=/* @__PURE__ */new Map;on(e,t){return this.#r(this.#t,e,t)}once(e,t){return this.#r(this.#n,e,t)}off(e,t){this.#i(this.#t,e,t),this.#i(this.#n,e,t)}async emit(e,t){await this.#o(e,t)}async emitWhile(e,t,n){return this.#o(e,t,n)}async#o(e,t,n){const r=()=>n?.()??!0;if(!r())return!1;const i=this.#t.get(e);if(i)for(const n of[...i]){if(!r())return!1;if(await this.#s(n,t,e),!r())return!1}if(!r())return!1;const o=this.#n.get(e);if(o&&o.size>0){const n=[...o];this.#n.delete(e);for(const i of n){if(!r())return!1;if(await this.#s(i,t,e),!r())return!1}}return r()}listenerCount(e){return(this.#t.get(e)?.size??0)+(this.#n.get(e)?.size??0)}removeAllListeners(e){if(void 0===e)return this.#t.clear(),void this.#n.clear();this.#t.delete(e),this.#n.delete(e)}eventNames(){const e=/* @__PURE__ */new Set;for(const t of this.#t.keys())e.add(t);for(const t of this.#n.keys())e.add(t);return[...e]}#r(e,t,n){let r=e.get(t);return r||(r=/* @__PURE__ */new Set,e.set(t,r)),r.add(n),()=>{this.#i(e,t,n)}}#i(e,t,n){const r=e.get(t);void 0!==r&&(r.delete(n),0===r.size&&e.delete(t))}async#s(e,t,n){try{await e(t)}catch(e){const t="string"==typeof n||"number"==typeof n?String(n):"<event>";v(`[live-preview] LP0601: handler for "${t}" threw:`,e)}}};function isInIframe(){if("undefined"==typeof window)return!1;try{return window.self!==window.top}catch{return!0}}function isDevMode(){const e=function(){if("undefined"==typeof process)return;const e=process.env.NODE_ENV;return"string"==typeof e?e:void 0}();if(void 0!==e)return"production"!==e;if("undefined"!=typeof window){const e=window.location.hostname;return"localhost"===e||"127.0.0.1"===e}return!1}var Ar=/^https?:\/\/(localhost|127\.0\.0\.1)(?::\d+)?$/i,Tr=/^https?:\/\/[^/?#\s]+$/i,Cr=[3e3,3001,3333,4e3,4321,5e3,5173,5174,8e3,8080,8888,9e3],OriginDetector=class{#a;constructor(e={}){const t=/* @__PURE__ */new Set;for(const n of e.additionalOrigins??[]){const e=$r(n);void 0!==e&&t.add(e)}let n;if(e.enableReferrerDetection??1){const t=e.referrer??("undefined"!=typeof document?document.referrer:"");if(t.length>0)try{const e=new URL(t).origin;e&&"null"!==e&&(n=e)}catch{}}const r=(e.enableLocalhostMatching??!0)&&(e.forceDevMode??isDevMode());this.#a=[t,n,r,void 0!==n,void 0]}matches(e){return 0!==e.length&&"null"!==e&&(void 0!==this.#a[4]?e===this.#a[4]:!!this.#a[0].has(e)||0===this.#a[0].size&&void 0!==this.#a[1]&&e===this.#a[1]||!(!this.#a[2]||!Ar.test(e)))}lockOrigin(e){return!!this.matches(e)&&(this.#a[4]=e,!0)}unlockOrigin(){const e=this.#a[4];return this.#a[4]=void 0,e}get lockedOrigin(){return this.#a[4]}enumerate(){if(void 0!==this.#a[4])return[this.#a[4]];const e=new Set(this.#a[0]);if(0===this.#a[0].size&&void 0!==this.#a[1]&&e.add(this.#a[1]),this.#a[2])for(const t of Cr)e.add(`http://localhost:${String(t)}`),e.add(`http://127.0.0.1:${String(t)}`);return[...e]}get referrerWasAvailable(){return this.#a[3]}get isProductionUnconfigured(){return!(!isInIframe()||this.#a[0].size>0||this.#a[2]||void 0!==this.#a[1])}get isReferrerOnlyTrust(){return!(this.#a[0].size>0||this.#a[2]||void 0===this.#a[1])}};function $r(e){const t=e.trim();if(0!==t.length)try{const e=new URL(t);if("http:"!==e.protocol&&"https:"!==e.protocol)return;if(!Tr.test(e.origin))return;return e.origin}catch{return}}var Rr=()=>{},Nr=class{#l;#u;#c=/* @__PURE__ */new Set;#a="staging";constructor(e,t){this.#l=e,this.#u=t}assertOpen(){if("closed"===this.#a)throw new Error(`Plugin context for "${this.#l}" is no longer active`)}get active(){return"active"===this.#a}eligible(){return"closed"!==this.#a}own(e){return this.assertOpen(),this.#d({kind:"cleanup",acquire:void 0,finalize:void 0,cleanup:e,disposed:!1})}stage(e,t,n){this.assertOpen();const r={kind:e,acquire:t,finalize:n,cleanup:void 0,disposed:!1},i=this.#d(r);if("active"===this.#a)try{this.#h(r)}catch(e){throw this.#f(r),e}return i}counts(){const e={transform:0,renderer:0,subscription:0,cleanup:0};for(const t of this.#c)e[t.kind]+=1;return e}commit(){if("staging"!==this.#a)throw new Error(`Plugin context for "${this.#l}" cannot be committed`);this.#a="committing";try{for(const e of this.#c)this.#h(e);this.#a="active"}catch(e){throw this.close(),e}}close(){if("closed"!==this.#a){this.#a="closed";for(const e of[...this.#c].reverse())this.#f(e);this.#c.clear()}}#d(e){return this.#c.add(e),()=>{this.#f(e)}}#h(e){if(e.disposed||void 0!==e.cleanup||void 0===e.acquire)return;const t=e.acquire();e.cleanup=t??Rr}#f(e){if(e.disposed)return;e.disposed=!0,this.#c.delete(e);const t=e.cleanup;if(e.cleanup=void 0,void 0!==t)try{h(t())&&this.#u(`plugin "${this.#l}" cleanup returned a Promise/thenable; cleanups must be synchronous`)}catch(e){this.#u(`plugin "${this.#l}" cleanup failed:`,e)}try{e.finalize?.()}catch(e){this.#u(`plugin "${this.#l}" cleanup failed:`,e)}}},Pr=class{#p;#m;#g=/* @__PURE__ */new Set;constructor(e,t){this.#p=e,this.#m=t}on(e,t){return this.#v("on",e,t)}once(e,t){return this.#v("once",e,t)}off(e,t){const n=t;for(const t of[...this.#g])t.event===e&&t.handler===n&&t.dispose()}emit(e,t){return this.#m.assertOpen(),this.#p.emit(e,t)}emitWhile(e,t,n){return this.#m.assertOpen(),this.#p.emitWhile(e,t,()=>{if(!this.#m.eligible())return!1;const e=n();return!!this.#m.eligible()&&e})}listenerCount(e){let t=0;for(const n of this.#g)n.event===e&&(t+=1);return t}removeAllListeners(e){for(const t of[...this.#g])void 0!==e&&t.event!==e||t.dispose()}eventNames(){const e=/* @__PURE__ */new Set;for(const t of this.#g)e.add(t.event);return[...e]}#v(e,t,n){this.#m.assertOpen();const r=n,i=[...this.#g].find(n=>n.kind===e&&n.event===t&&n.handler===r);if(void 0!==i)return i.dispose;let o=Rr,s=!0;const a=async t=>{this.#m.active&&s&&("once"===e&&o(),await n(t))},l={kind:e,event:t,handler:r,dispose:Rr};return o=this.#m.stage("subscription",()=>this.#p[e](t,a),()=>{s=!1,this.#g.delete(l)}),l.dispose=o,this.#g.add(l),o}},Lr=class{#p;#y;#b;#w;#u;#S=/* @__PURE__ */new Map;#k=/* @__PURE__ */new Map;#A=/* @__PURE__ */new Map;#T=/* @__PURE__ */new Set;#C=/* @__PURE__ */new Map;#$=Promise.resolve();#R=0;constructor(e){this.#p=e.events,this.#y=e.config,this.#b=e.registerFieldRenderer,this.#u=m(e.log);const t=e.onTransformError;this.#w=void 0===t?void 0:m((...e)=>{const n=e[0];try{return t(n)}catch(e){return void this.#u("transform error reporter failed:",e)}})}register(e){return this.#R>0?this.#N(e,!1):this.#P(()=>this.#N(e,!0))}unregister(e){return this.#R>0?this.#L(e,!1):this.#P(async()=>{await this.#L(e,!0)})}destroyAll(){return this.#R>0?this.#F(!1):this.#P(async()=>{await this.#F(!0)})}applyTransforms(e,t,n,r){const i=this.#C.get(e);if(void 0===i||0===i.length)return t;let o=t;for(const s of[...i]){if(!s.active)continue;const{transform:i}=s;if(!1===r?.())return t;try{o=i(o,{fieldName:e,element:n.element,allFields:n.allFields});const s=h(o);if(!1===r?.())return t;if(s)throw new TypeError(`Transform for "${e}" returned a Promise/thenable; transforms must be synchronous`)}catch(n){if(!1===r?.())return t;const i=n instanceof Error?n:new Error(String(n));return this.#u(`transform for "${e}" failed:`,i),this.#w?.(i),t}}return o}list(){return[...this.#S.keys()]}snapshot(){const e=[],t=(e,t,n,r)=>{const i=r.counts();return{name:e,version:t,state:n,registrations:{transforms:i.transform,renderers:i.renderer,subscriptions:i.subscription,cleanups:i.cleanup}}};for(const[n,r]of this.#k)e.push(t(n,void 0,"initializing",r.scope));for(const[n,r]of this.#S)e.push(t(n,r.plugin.version,"active",r.scope));for(const t of this.#A.keys())e.push({name:t,version:void 0,state:"tearing-down",registrations:{transforms:0,renderers:0,subscriptions:0,cleanups:0}});return e}get size(){return this.#S.size}async#N(e,t){if(this.#S.has(e.name)||this.#k.has(e.name)||this.#A.has(e.name))return void this.#u(`plugin "${e.name}" already registered`);const n=function(e,t){if(void 0!==e){if(void 0!==e.runtime&&!function(e,t){const n=function(e){const t=/^v?(\d+)\.(\d+)\.(\d+)/.exec(e.trim());if(null!==t)return[Number(t[1]),Number(t[2]),Number(t[3])]}(e);return void 0!==n&&t.split("||").some(e=>{const r=e.trim().split(/\s+/).filter(e=>e.length>0);return 0===r.length?""===e.trim()&&""===t.trim():r.every(e=>function(e,t){const n=t.trim();if(""===n||"*"===n)return!0;const r=/^(\^|~|>=|<=|>|<|=)?\s*v?(\d+)\.(\d+)\.(\d+)/.exec(n);if(null===r)return!1;const i=r[1]??"=",o=[Number(r[2]),Number(r[3]),Number(r[4])],s=function(e,t){for(let n=0;n<3;n+=1){const r=(e[n]??0)-(t[n]??0);if(0!==r)return r}return 0}(e,o);switch(i){case"=":return 0===s;case">":return s>0;case">=":return s>=0;case"<":return s<0;case"<=":return s<=0;case"~":return s>=0&&e[0]===o[0]&&e[1]===o[1];case"^":return!(s<0)&&(o[0]>0?e[0]===o[0]:o[1]>0?0===e[0]&&e[1]===o[1]:0===e[0]&&0===e[1]&&e[2]===o[2]);default:return!1}}(n,e))})}(t,e.runtime))return`declares runtime ${e.runtime}, this runtime is ${t}`;if(void 0!==e.protocol){if(!Number.isInteger(e.protocol)||e.protocol<1)return`declares an invalid protocol version ${String(e.protocol)}`;if(e.protocol<4)return`declares protocol ${String(e.protocol)}, this runtime speaks ${String(4)}`}}}(e.compat,ct);if(void 0!==n)return void this.#x(e.name,n);const r=new Nr(e.name,this.#u),i=this.#U(e.name,r),o={scope:r,cancelled:!1};this.#k.set(e.name,o);try{if(await this.#M(()=>e.init(i),t),o.cancelled)return;r.commit()}catch(t){return r.close(),void(o.cancelled||this.#u(`plugin "${e.name}" init failed:`,t))}finally{this.#k.get(e.name)===o&&this.#k.delete(e.name)}this.#S.set(e.name,{plugin:e,scope:r}),this.#u(`plugin "${e.name}" registered`)}#x(e,t){const n=`plugin "${e}" refused: ${t}`;this.#u(n),this.#p.emit("error",{error:new Error(n),context:"plugin",code:"LP0103"})}#U(e,t){return{events:new Pr(this.#p,t),registerFieldRenderer:e=>{t.stage("renderer",()=>{const t=this.#b(e);return"function"==typeof t?t:void 0})},registerTransform:(e,n)=>{const r={transform:n,active:!1};t.stage("transform",()=>{r.active=!0;const t=this.#C.get(e);return void 0===t?this.#C.set(e,[r]):t.push(r),()=>{r.active=!1;const t=this.#C.get(e);if(void 0===t)return;const n=t.indexOf(r);n>=0&&t.splice(n,1),0===t.length&&this.#C.delete(e)}})},registerCleanup:e=>{t.own(e)},getConfig:()=>this.#y,log:(...t)=>{this.#u(`[${e}]`,...t)}}}#L(e,t){const n=this.#k.get(e);if(void 0!==n)return n.cancelled=!0,n.scope.close(),Promise.resolve();const r=this.#A.get(e);if(void 0!==r)return this.#T.has(e)?Promise.resolve():t?this.#E(r):r;const i=this.#S.get(e);if(void 0===i)return Promise.resolve();this.#S.delete(e),i.scope.close();const o=Promise.resolve().then(()=>this.#I(e,i.plugin,t));return this.#A.set(e,o),o.then(()=>{this.#A.get(e)===o&&this.#A.delete(e)}),o}async#I(e,t,n){if(void 0!==t.destroy){this.#T.add(e);try{await this.#M(()=>t.destroy?.(),n)}catch(t){this.#u(`plugin "${e}" destroy failed:`,t)}finally{this.#T.delete(e)}}}async#F(e){for(const e of this.#k.values())e.cancelled=!0,e.scope.close();const t=[...this.#S.keys()];for(const n of t)await this.#L(n,e)}async#M(e,t){t?await this.#E(Promise.resolve().then(e)):await e()}async#E(e){this.#R+=1;try{await e}finally{this.#R-=1}}#P(e){const t=this.#$.then(e);return this.#$=t.catch(e=>{this.#u("plugin manager mutation failed:",e)}),t}},Fr=class{#O;#_;#D=/* @__PURE__ */new Map;constructor(e){this.#O=e,this.#_={...e}}get renderers(){return this.#_}resolve(e){return this.#_[e]}register(e){const t=e.name,n={renderer:e},r=this.#D.get(t);void 0===r?this.#D.set(t,[n]):r.push(n),this.#_[t]=e;let i=!0;return()=>{if(!i)return;i=!1;const e=this.#D.get(t);if(void 0===e)return;const r=e.indexOf(n);if(r<0)return;const o=r===e.length-1;if(e.splice(r,1),0===e.length&&this.#D.delete(t),!o)return;const s=e.at(-1),a=s?.renderer??this.#O[t];void 0===a?Reflect.deleteProperty(this.#_,t):this.#_[t]=a}}},xr={1:"left",2:"center",3:"right",4:"justify"},Ur=/* @__PURE__ */new Set(["left","center","right","justify","start","end"]);function Mr(e){const t=e.format;return"string"==typeof t&&Ur.has(t)?t:"number"==typeof t?xr[t]:void 0}function Er(e){const t=e.indent;return"number"==typeof t&&t>0?t:0}function Ir(e){return"rtl"===e.direction?' dir="rtl"':"ltr"===e.direction?' dir="ltr"':""}function Or(e){const t=Mr(e),n=Er(e),r=[];return void 0!==t&&r.push(`lp-align-${t}`),n>0&&r.push(`lp-indent-${String(n)}`),0===r.length?"":` class="${r.join(" ")}"`}var _r=/* @__PURE__ */new Set(["h1","h2","h3","h4","h5","h6"]);function Dr(e){return"object"==typeof e&&null!==e?e:void 0}function zr(e){return Dr(e)}function Br(e){return e.replace(/[^a-zA-Z0-9_-]/g,"-").toLowerCase()}function Hr(e){return"string"==typeof e&&e.length>0?e:void 0}function jr(e){const t=Hr(e.title)??Hr(e.name)??Hr(e.slug);return void 0!==t?t:void 0===e.id?void 0:String(e.id)}var Wr=' target="_blank" rel="noopener noreferrer"',qr=(e,t)=>{const n=t.renderChildren(e.children??[]),r=Dr(e.fields),i=function(e,t){if("internal"===t?.linkType)return function(e){const t=Dr(Dr(e)?.value),n=t?.url;if("string"==typeof n&&n.length>0)return n;const r=t?.slug;return"string"==typeof r&&r.length>0?`/${r}`:void 0}(t.doc);const n=t?.url??e.url;return"string"==typeof n&&n.length>0?n:void 0}(e,r);if(void 0===i||!isSafeUrl(i))return n;const o="string"==typeof e.title?` title="${escapeHtml(e.title)}"`:"";return`<a href="${escapeHtmlAttribute(i)}"${function(e,t,n){if(!0===t?.newTab||isExternalHttpUrl(n))return Wr;const r="string"==typeof e.target?e.target:"";return""===r?"":"_blank"===r?Wr:` target="${escapeHtml(r)}"`}(e,r,i)}${o}>${n}</a>`};function Vr(e){if("string"==typeof e.text)return e.text;if(!e.children)return"";let t="";for(const n of e.children)t+=Vr(n);return t}function Gr(e){return`${"number"==typeof e.width?` width="${String(e.width)}"`:""}${"number"==typeof e.height?` height="${String(e.height)}"`:""}`}function Kr(e){return"string"==typeof e.mimeType?` type="${escapeHtmlAttribute(e.mimeType)}"`:""}var Jr=/* @__PURE__ */new Map;function Qr(e){return Jr.get(e)}var Xr=".lp-block:empty,.lp-inline-block:empty";function Zr(e,t,n,r){const i=Dr(e.fields)??{},o="string"==typeof i.blockType?i.blockType:"",s=Br(o),a=""===s?r:`${r} ${r}--${s}`;if(""!==o){const e=Qr(o)??Qr(s);if(e)return e(i,{renderChildren:t.renderChildren});t.onUnrenderedBlock?.(o,a)}return`<${n} class="${a}"></${n}>`}function Yr(e,t){return"number"==typeof t&&t>1?` ${e}="${String(t)}"`:""}var ei={text:e=>{let t=escapeHtml("string"==typeof e.text?e.text:"");const n="number"==typeof e.format?e.format:0;return!!(16&n)&&(t=`<code>${t}</code>`),!!(1&n)&&(t=`<strong>${t}</strong>`),!!(2&n)&&(t=`<em>${t}</em>`),!!(8&n)&&(t=`<u>${t}</u>`),!!(4&n)&&(t=`<s>${t}</s>`),!!(32&n)&&(t=`<sub>${t}</sub>`),!!(64&n)&&(t=`<sup>${t}</sup>`),!!(128&n)&&(t=`<mark>${t}</mark>`),t},paragraph:(e,t)=>{const n=t.renderChildren(e.children??[]);return`<p${Ir(e)}${Or(e)}>${n}</p>`},heading:(e,t)=>{const n="string"==typeof e.tag?e.tag.toLowerCase():"h2",r=_r.has(n)?n:"h2",i=t.renderChildren(e.children??[]);return`<${r}${Ir(e)}${Or(e)}>${i}</${r}>`},list:(e,t)=>{const n="string"==typeof e.listType?e.listType:"bullet",r="number"===n?"ol":"ul",i="number"===n&&"number"==typeof e.start&&e.start>1?` start="${String(e.start)}"`:"",o="check"===n?' role="list"':"",s=t.renderChildren(e.children??[]);return`<${r}${Ir(e)}${Or(e)}${i}${o}>${s}</${r}>`},listitem:(e,t)=>{const n=t.renderChildren(e.children??[]);if("boolean"==typeof e.checked)return`<li role="checkbox" aria-checked="${e.checked?"true":"false"}"${Or(e)}>${n}</li>`;const r="number"==typeof e.value?` value="${escapeHtml(String(e.value))}"`:"";return`<li${Ir(e)}${Or(e)}${r}>${n}</li>`},link:qr,autolink:qr,quote:(e,t)=>{const n=t.renderChildren(e.children??[]);return`<blockquote${Ir(e)}${Or(e)}>${n}</blockquote>`},code:e=>{const t=Br("string"==typeof e.language?e.language:"");return`<pre><code${""===t?"":` class="language-${t}"`}>${escapeHtml(Vr(e))}</code></pre>`},"code-highlight":e=>{const t="string"==typeof e.text?e.text:"";return`<span${"string"==typeof e.highlightType?` class="token-${Br(e.highlightType)}"`:""}>${escapeHtml(t)}</span>`},linebreak:()=>"<br>",horizontalrule:()=>"<hr>",tab:()=>"\t",upload:e=>{const t=zr(e.value);if(void 0===t)return"";const n=t.url;if("string"!=typeof n||!isSafeUrl(n))return"";const r="string"==typeof t.mimeType?t.mimeType:"";return r.startsWith("video/")?function(e,t){return`<video controls${Gr(e)}><source src="${escapeHtmlAttribute(t)}"${Kr(e)}></video>`}(t,n):r.startsWith("audio/")?function(e,t){return`<audio controls><source src="${escapeHtmlAttribute(t)}"${Kr(e)}></audio>`}(t,n):""===r||r.startsWith("image/")?function(e,t){const n="string"==typeof e.alt?escapeHtml(e.alt):"";return`<img src="${escapeHtmlAttribute(t)}" alt="${n}"${Gr(e)} loading="lazy" decoding="async">`}(t,n):function(e,t){const n="string"==typeof e.filename?escapeHtml(e.filename):escapeHtml(t);return`<a href="${escapeHtmlAttribute(t)}" target="_blank" rel="noopener noreferrer">${n}</a>`}(t,n)},relationship:e=>{const t="string"==typeof e.relationTo?e.relationTo:"",n=Dr(e.value),r=escapeHtml((n&&jr(n))??`#${t}`),i=Br(t),o=""===i?' class="lp-relation"':` class="lp-relation lp-relation--${i}"`,s=n?.url;return"string"==typeof s&&isSafeUrl(s)?`<a href="${escapeHtmlAttribute(s)}"${o}>${r}</a>`:`<span${o}>${r}</span>`},block:(e,t)=>Zr(e,t,"div","lp-block"),inlineBlock:(e,t)=>Zr(e,t,"span","lp-inline-block"),table:(e,t)=>`<table${Ir(e)}><tbody>${t.renderChildren(e.children??[])}</tbody></table>`,tablerow:(e,t)=>`<tr>${t.renderChildren(e.children??[])}</tr>`,tablecell:(e,t)=>{const n="number"==typeof e.headerState?e.headerState:0,r=3&n?"th":"td";return`<${r}${1===n?' scope="col"':2===n?' scope="row"':""}${Yr("colspan",e.colSpan)}${Yr("rowspan",e.rowSpan)}>${t.renderChildren(e.children??[])}</${r}>`}},ti=/* @__PURE__ */new Map,ni=!1;function ri(e){if("object"!=typeof e||null===e)return!1;if(!("root"in e))return!1;const t=e.root;return"object"==typeof t&&null!==t&&"children"in t&&Array.isArray(t.children)}function ii(e,t){const n=(r=e.type,ti.get(r)??ei[r]);var r;return n?n(e,t):void 0!==e.children?t.renderChildren(e.children):""}function oi(e){if("string"==typeof e.text)return e.text;if("linebreak"===e.type)return"\n";if(void 0===e.children)return"";let t="";for(const n of e.children)t+=oi(n);return t}function si(e="text"){const t=/* @__PURE__ */new WeakSet;return{name:e,render:/* @__PURE__ */Q((e,n)=>{const r=e.element,i=function(e){return null==e?"":ri(e)?ri(t=e)?t.root.children.map(oi).join("\n").trim():"":"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e?String(e):JSON.stringify(e);var t}(n);if("INPUT"!==r.tagName&&"TEXTAREA"!==r.tagName)return function(e){return null!==e.querySelector(":scope > :not(br)")}(r)&&!r.hasAttribute("data-payload-text")?(function(e,t,n){e.has(t)||(e.add(t),y(`[live-preview] LP0402: Skipping text update for "${n}": <${t.tagName.toLowerCase()}> has structured children. Move data-payload-field to the value element, or add data-payload-text to replace them.`))}(t,r,e.fieldName),!1):void(i.includes("\n")||i.includes("\r")?r.innerHTML=nn(function(e){return escapeHtml(e).replace(/\r\n|\r|\n/g,"<br>")}(i)):r.textContent=i);r.value=i})}}var ai=/* @__PURE__ */new Set,li=/* @__PURE__ */new Set,ui=/* @__PURE__ */new Set(["DIV","SECTION","ARTICLE"]),ci={name:"richText",render:/* @__PURE__ */Q((e,t,n)=>{const r=e.element;if(Bn(t))return void(r.textContent="");const i=n.sanitizerPolicy;if(void 0!==n.renderRichText){const o=n.renderRichText(t,{fieldName:e.fieldName,element:r,locale:n.locale});return void(r.innerHTML=nn($n(o,i)))}if(ri(t)){const o=/* @__PURE__ */new Map,s=function(e,t){const n=e.cloneNode(!1);n.innerHTML=nn(t);const r=function(e,t){const n=e.firstElementChild;if(null!==n?.nextElementSibling||t.children.length<2)return null;if(!ui.has(n.tagName)||n.hasAttribute(Ue))return null;for(const e of t.children)if(e.tagName===n.tagName&&e.className===n.className)return null;return n}(e,n)??e,i=/* @__PURE__ */new Map,o=n.querySelectorAll(Xr);if(o.length>0&&null!==r.firstElementChild){const e=[];di(r,n,e);for(const[t,n]of e)t.replaceWith(n),n.matches(Xr)||i.set(t.className,!1);for(const e of o)null!==e.parentNode&&i.set(e.className,!0)}return r.replaceChildren(...n.childNodes),i}(r,$n(function(e,t={}){if(!ri(e))return"";const n=function(e){const t={renderChildren:e=>{let n="";for(const r of e)n+=ii(r,t);return n},resolveAlignment:Mr,resolveIndent:Er,onUnrenderedBlock:e};return t}(t.onUnrenderedBlock).renderChildren(e.root.children);return!1===t.sanitize?n:void 0!==Rn()?function sanitizeHtml(e,t){return $n(e,void 0,t)}(n):(function(){if(!ni){ni=!0;try{console.warn('[live-preview] lexicalToHtml() has no sanitizer document and returned unsanitised HTML; call setSanitizerDocument() (linkedom/jsdom) for server rendering, see "HTML sanitization" in docs/security.md.')}catch{}}}(),n)}(t,{sanitize:!1,onUnrenderedBlock:(e,t)=>{o.set(t,e)}}),i));for(const[t,r]of s){const i=o.get(t);void 0!==i&&hi(e,n,i,r)}return}if("string"!=typeof t)return!1;r.innerHTML=nn($n(t,i))})};function di(e,t,n){if(e.children.length!==t.children.length)return;let r=e.firstElementChild,i=t.firstElementChild;for(;null!==r&&null!==i;)i.matches(Xr)?n.push([i,r]):di(r,i,n),r=r.nextElementSibling,i=i.nextElementSibling}function hi(e,t,n,r){r&&t.reportUnfaithful?.(e,`lost the markup the server drew for block "${n}"`);const i=r?li:ai;i.has(n)||(i.add(n),y(`[live-preview] ${r?`LP0413: no renderer for block "${n}", and the markup the server rendered for it is lost.`:`LP0410: no renderer for block "${n}"; keeping what the server rendered for it.`} Register one with registerBlockRenderer().`))}var fi={name:"html",render(e,t,n){if(Bn(t))return void(e.element.textContent="");const r="string"==typeof t?t:zn(t);e.element.innerHTML=nn($n(r,n.sanitizerPolicy))}},pi=/* @__PURE__ */new WeakSet;function mi(e,t,n){return"string"!=typeof n||0===n.length?{kind:"none"}:isSafeUrl(n)?{kind:"safe",url:n}:(pi.has(e)||(pi.add(e),y(`[live-preview] LP0401: refused an unsafe URL for "${t}" on <${e.tagName.toLowerCase()}>; the attribute was cleared.`)),{kind:"unsafe"})}function gi(e,t=e=>e){return{name:e,render(e,n,r){const i=e.element;if(Bn(n))return void function(e){"INPUT"!==e.tagName&&"TEXTAREA"!==e.tagName?(e.removeAttribute("href"),e.textContent=""):e.value=""}(i);const o=zn(n);if("INPUT"!==i.tagName&&"TEXTAREA"!==i.tagName){if("A"===i.tagName){const n=e.hrefField,s=void 0===n||0===n.length?t(o):Kt(r.allFields,n,r.locale,void 0!==e.locale),a=mi(i,e.fieldName,s);"safe"===a.kind?i.setAttribute("href",a.url):"unsafe"===a.kind&&i.removeAttribute("href")}i.textContent=o}else i.value=o}}}var vi=gi("url"),yi=/^[a-zA-Z][a-zA-Z0-9+.-]*:/,bi=gi("email",function(e){const t=e.trim();return yi.test(t)||!t.includes("@")?t:`mailto:${t}`}),wi=["src","srcset","sizes"];function Si(e){for(const t of wi)e.removeAttribute(t)}function ki(e,t,n){e.src=t;const r=function(e){if(void 0===e?.sizes)return;const t=[];for(const n of Object.values(e.sizes))"string"==typeof n.url&&"number"==typeof n.width&&isSafeUrl(n.url)&&t.push(`${Ai(n.url)} ${String(n.width)}w`);return 0!==t.length?("number"==typeof e.width&&"string"==typeof e.url&&isSafeUrl(e.url)&&t.push(`${Ai(e.url)} ${String(e.width)}w`),t.join(", ")):void 0}(n);if(void 0===r)return e.removeAttribute("srcset"),void e.removeAttribute("sizes");e.setAttribute("srcset",r)}function Ai(e){return e.replace(/[\s,]/g,encodeURIComponent)}var Ti={name:"image",render:/* @__PURE__ */Q((e,t,n)=>{const r=e.element;if(Bn(t))return void Ci(r);const i=void 0!==e.locale,{media:o,candidate:s}=function(e,t,n,r){const i=void 0!==e.srcField&&e.srcField.length>0?Kt(n.allFields,e.srcField,n.locale,r):t,o=zr(i);return{media:o,candidate:void 0===o?i:o.url}}(e,t,n,i),a=mi(r,e.fieldName,s);if("none"===a.kind)return!1;if("unsafe"!==a.kind){if("IMG"===r.tagName){const t=r;ki(t,a.url,o);const s=function(e,t,n,r,i){if(void 0!==t&&t.length>0){const e=Kt(n,t,r,i);return"string"==typeof e?e:void 0}return e?.alt}(o,e.altField,n.allFields,n.locale,i);return void(void 0!==s&&(t.alt=s))}r.style.backgroundImage=`url('${function(e){return e.replace(/['"()\\]/g,"\\$&")}(a.url)}')`}else Ci(r)})};function Ci(e){"IMG"===e.tagName?Si(e):e.style.backgroundImage=""}var $i={name:"upload",render:/* @__PURE__ */Q((e,t)=>{const n=e.element;if(Bn(t))return void Ri(n);const r=zr(t);if(void 0===r)return!1;const i=mi(n,e.fieldName,r.url);if("none"===i.kind)return!1;if("unsafe"===i.kind)return void Ri(n);const o=i.url;if("IMG"===n.tagName){const e=n;return ki(e,o,r),void(void 0!==r.alt&&(e.alt=r.alt))}if("A"===n.tagName)return n.setAttribute("href",o),void(n.textContent=r.filename??o);const s=escapeHtml(r.filename??o);n.innerHTML=nn(`<a href="${escapeHtmlAttribute(o)}">${s}</a>`)})};function Ri(e){"IMG"!==e.tagName?(e.removeAttribute("href"),e.textContent=""):Si(e)}var Ni={name:"relationship",render(e,t){const n=e.element;if(Bn(t))return n.removeAttribute("href"),void(n.textContent="");if("A"===n.tagName&&!Array.isArray(t)){const r=mi(n,e.fieldName,Dr(t)?.url);"safe"===r.kind?n.setAttribute("href",r.url):"unsafe"===r.kind&&n.removeAttribute("href")}n.textContent=Array.isArray(t)?t.map(Pi).join(", "):Pi(t)}};function Pi(e){const t=Dr(e);return void 0===t?zn(e):jr(t)??""}var Li={name:"select",render(e,t,n){const r=e.element,i=Bn(t)?[]:function(e){return Array.isArray(e)?e.map(zn):[zn(e)]}(t);if("SELECT"!==r.tagName){if("INPUT"===r.tagName&&"radio"===r.type){const e=r;return void(e.checked=i.includes(e.value))}r.textContent=i.map(e=>function(e,t){const n=t.schema?.options;if(!Array.isArray(n))return e;for(const t of n){const n=Dr(t);if(void 0!==n&&zn(n.value)===e)return"string"==typeof n.label?n.label:e}return e}(e,n)).join(", ")}else!function(e,t){if(e.multiple)for(const n of Array.from(e.options))n.selected=t.includes(n.value);else e.value=t[0]??""}(r,i)}},Fi=/* @__PURE__ */new Set(["","false","0","off","no"]),xi={name:"checkbox",render(e,t){const n=e.element,r=function(e){return"boolean"==typeof e?e:"string"==typeof e?!Fi.has(e.trim().toLowerCase()):"number"==typeof e?0!==e:null!=e}(t);"INPUT"!==n.tagName||"checkbox"!==n.type?n.hasAttribute("aria-checked")?n.setAttribute("aria-checked",r?"true":"false"):n.textContent=r?"true":"false":n.checked=r}},Ui=/* @__PURE__ */new Map,Mi=/* @__PURE__ */new Map;function Ei(e,t){const n=e??"";if(null==t)return n;const r=Ii(t);return"{}"===r?n:`${n}|${r}`}function Ii(e){if(null===e||"object"!=typeof e)return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(e=>Ii(e)).join(",")}]`;const t=e,n=Object.keys(t).sort(),r=[];for(const e of n){const n=t[e];void 0!==n&&r.push(`${JSON.stringify(e)}:${Ii(n)}`)}return`{${r.join(",")}}`}var Oi=/* @__PURE__ */new Set(["short","medium","long","full"]),_i=/* @__PURE__ */new Set(["short","medium","long","full"]),Di=/^[A-Za-z]{3}$/u,zi=/^[0-4]$/u;function Bi(e){return{kind:"date",options:e}}function Hi(e){return{kind:"number",options:e}}var ji=/* @__PURE__ */new WeakSet;function Wi(e,t,n,r){if(void 0===t||""===t)return;const i=function(e){const t=e.indexOf(":"),n=-1===t?e:e.slice(0,t),r=-1===t?void 0:e.slice(t+1);switch(n){case"date":return void 0===r?Bi({dateStyle:"medium"}):Oi.has(r)?Bi({dateStyle:r}):void 0;case"time":return void 0===r?Bi({timeStyle:"short"}):_i.has(r)?Bi({timeStyle:r}):void 0;case"datetime":return void 0===r?Bi({dateStyle:"medium",timeStyle:"short"}):Oi.has(r)?Bi({dateStyle:r,timeStyle:"short"===r?"short":"medium"}):void 0;case"number":if(void 0===r)return Hi({});if(!zi.test(r))return;return Hi({minimumFractionDigits:Number(r),maximumFractionDigits:Number(r)});case"currency":if(void 0===r||!Di.test(r))return;return Hi({style:"currency",currency:r.toUpperCase()});case"percent":return void 0===r?Hi({style:"percent"}):void 0;default:return}}(t);if(void 0!==i){if(i.kind===e)return i.options}else!function(e,t,n){ji.has(e)||(ji.add(e),y(`[live-preview] LP0408: data-payload-format="${n}" on "${t}" is not a known format; the default formatting was used. Known: date, date:short|medium|long|full, time, datetime, number, number:0-4, currency:XXX, percent.`))}(n,r,t)}var qi={name:"date",render(e,t,n){const r=e.element;if(Bn(t))return void("INPUT"===r.tagName?r.value="":(r.removeAttribute("datetime"),r.textContent=""));const i="number"==typeof t?t:zn(t),o=new Date(i),s=!Number.isNaN(o.getTime()),a=String(i);"INPUT"!==r.tagName?("TIME"===r.tagName&&r.setAttribute("datetime",s?o.toISOString():a),r.textContent=s?function(e,t,n){const r=t.locale??n.locale??detectInitialLocale(),i=Wi("date",t.format,t.element,t.fieldName)??Vi;try{return function(e,t){const n=Ei(e,t);return Hn(Mi,n)??jn(Mi,n,new Intl.DateTimeFormat(e,t),64)}(r,i).format(e)}catch{return e.toISOString()}}(o,e,n):a):r.value=s?function(e,t){const n=`${String(t.getFullYear()).padStart(4,"0")}-${Gi(t.getMonth()+1)}-${Gi(t.getDate())}`,r=`${Gi(t.getHours())}:${Gi(t.getMinutes())}`;return"date"===e?n:"datetime-local"===e?`${n}T${r}`:"time"===e?r:t.toISOString()}(r.type,o):a}},Vi={dateStyle:"medium",timeStyle:"short"};function Gi(e){return String(e).padStart(2,"0")}var Ki={name:"number",render(e,t,n){const r=e.element;if(Bn(t))return void("INPUT"===r.tagName?r.value="":r.textContent="");const i="number"==typeof t?t:Number(zn(t));Number.isNaN(i)?r.textContent=zn(t):"INPUT"!==r.tagName?r.textContent=function(e,t,n){const r=t.locale??n.locale??detectInitialLocale(),i=Wi("number",t.format,t.element,t.fieldName);try{return function(e,t){const n=Ei(e,t);return Hn(Ui,n)??jn(Ui,n,new Intl.NumberFormat(e,t),64)}(r,i).format(e)}catch{return String(e)}}(i,e,n):r.value=String(i)}},Ji={name:"array",render:/* @__PURE__ */Q((e,t,n)=>{const r=e.element;if(Bn(t))return void(r.textContent="");if(!Array.isArray(t))return!1;const i=e.arrayTemplate;if(void 0!==i&&i.length>0){const e=function(e,t){const n=In(t);let r="";for(let i=0;i<t.length;i+=1)r+=On(e,t[i],i,zn,n);return r}(i,t),o=n.sanitizerPolicy,s=Kn(i),a=_n(r);r.innerHTML=nn($n(e,o,s));for(const e of Array.from(r.children))Dn(e,a);return}r.textContent=t.map(zn).join(e.arraySeparator??", ")})};function Qi(){const e=/* @__PURE__ */new WeakMap,t=/* @__PURE__ */new WeakSet,n=/* @__PURE__ */new WeakMap,r=/* @__PURE__ */new WeakMap;return{name:"structural-array",render:/* @__PURE__ */Q((i,o,s)=>{const a=Bn(o)?[]:o;if(!Array.isArray(a))return!1;const l=i.element,u=i.arrayTemplate;if(void 0===u||0===u.length)return function(e,t,n){e.has(t)||(e.add(t),y(`[live-preview] LP0403: Skipping structural update for "${n}": <${t.tagName.toLowerCase()} data-payload-structural> needs data-payload-array-template (for example "<li>{{label}}</li>").`))}(t,l,i.fieldName),!1;const c=e.get(l),d=Xi(l),h=x(c?.values??d.map((e,t)=>null===e?{__payloadDomPosition:t}:{id:e}),a),f=function(e,t,n){return void 0===e||e.template!==t||!function(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}(e.domSnapshot,n)}(c,u,d);if(0===h.length&&!f)return e.set(l,{values:a.slice(),template:u,domSnapshot:d}),!1;!function(e,t,n,r,i){const o=i.map(Zi),s=/* @__PURE__ */new Set,a=o.find(e=>!(void 0===e||!s.has(e)&&(s.add(e),1)));if(void 0!==a&&Yi(e,t,n,a),o.some(e=>void 0===e)&&eo(e,t,"LP0404",`LP0404: an item of "${n}" has no id and pairs by position, so an insert re-renders every row after it. Give items a stable id.`),r?.length===i.length&&i.length>1){const i=new Set(r.map(Zi).filter(e=>void 0!==e)),s=o.some(e=>void 0!==e&&i.has(e));i.size>0&&!s&&eo(e,t,"LP0406",`LP0406: every key of "${n}" changed at once; the source generates ids per message, so no item can be retained across updates.`)}}(n,l,i.fieldName,c?.values,a);const p=Zn({template:u,container:l,patches:h,nextItems:a,store:r,forceRender:f,sanitizerPolicy:s.sanitizerPolicy,onDuplicateKey:(e,t)=>{Yi(n,e,i.fieldName,t)}});return null!==p&&(e.set(l,{values:a.slice(),template:u,domSnapshot:Xi(l)}),!!p&&void 0)})}}function Xi(e){return Array.from(e.children,e=>e.getAttribute(Jn))}function Zi(e){if("object"!=typeof e||null===e)return;const t=e.id;return"string"==typeof t||"number"==typeof t?String(t):void 0}function Yi(e,t,n,r){eo(e,t,"LP0405",`LP0405: two items of "${n}" share the key "${r}"; later ones pair by position. Make \`id\` unique per item.`)}function eo(e,t,n,r){let i=e.get(t);void 0===i&&(i=/* @__PURE__ */new Set,e.set(t,i)),i.has(n)||(i.add(n),y(`[live-preview] ${r}`))}var to=/* @__PURE__ */new Map;function no(e,t){return{name:e,render(){k(t)}}}var ro=Object.freeze({disableReferrerDetection:!0,eventSourcePolicy:"parent-or-opener",skipUnchanged:!0,sanitizerPolicy:"strict"}),io=Object.freeze({disableReferrerDetection:!1,eventSourcePolicy:"any",skipUnchanged:!1,sanitizerPolicy:"compat"});function oo(e){return void 0===e?void 0:!e}var LivePreviewClient=class{#z=new EventEmitter;#B;#H;#j;#S;#u;#W=!1;#q=!1;#V=!1;#G=null;constructor(e={}){const t=function(e){const t="v1"===e.defaults?io:ro;return{...e,skipUnchanged:e.skipUnchanged??t.skipUnchanged,disableReferrerDetection:e.disableReferrerDetection??t.disableReferrerDetection,eventSourcePolicy:e.eventSourcePolicy??t.eventSourcePolicy,sanitizerPolicy:e.sanitizerPolicy??t.sanitizerPolicy}}(e),n=t.serverURL??"";!function(e){if("v1"!==e.defaults&&""!==(e.serverURL??"")&&null==e.mergeDepth)throw new Error("payload-live-preview: `serverURL` needs an explicit `mergeDepth` under the 2.0 defaults — choose the population depth deliberately (0 for none), or pass `defaults: 'v1'` to keep the 1.x default of 1 while migrating (ADR 0007, entry 10).")}({defaults:e.defaults,serverURL:n,mergeDepth:t.mergeDepth});const r=t.debug??isDevMode();this.#u=r?(...e)=>{b("[live-preview]",...e)}:g,this.#B=new OriginDetector(C({additionalOrigins:t.allowedOrigins,enableReferrerDetection:oo(t.disableReferrerDetection),enableLocalhostMatching:oo(t.disableLocalhostMatching)})),this.#B.isProductionUnconfigured&&this.#u("no trusted origin could be detected — set allowedOrigins"),this.#H=new Fr(function(){const e=[ci,fi,vi,bi,Ti,$i,Ni,Li,{...Li,name:"radio"},xi,qi,Ki,..."undefined"!=typeof __LEAN_BUILD__&&__LEAN_BUILD__?[no("array","structural arrays"),no("blocks","structural arrays")]:[Ji,{...Ji,name:"blocks"}]];return function(e=[]){const t={};for(const n of e)t[n.name]=n;for(const[e,n]of to)t[e]=n;return Object.freeze(t)}([si("text"),si("textarea"),...e,..."undefined"!=typeof __LEAN_BUILD__&&__LEAN_BUILD__?[]:[Qi()]])}()),this.#S=new Lr({events:this.#z,config:Object.freeze({...t}),registerFieldRenderer:e=>this.#H.register(e),onTransformError:e=>{this.#z.emit("error",{error:e,context:"transform",code:"LP0602"})},log:this.#u}),this.#j=new wr(C({root:t.root,renderers:this.#H.renderers,resolveRenderer:(e,n)=>t.resolveRenderer?.(e,n)??this.#H.resolve(e),renderRichText:t.renderRichText,sanitizerPolicy:t.sanitizerPolicy,transformValue:(e,t,n,r)=>this.#S.applyTransforms(e,t,n,r),originMatcher:e=>this.#B.matches(e),readyTargets:()=>this.#B.enumerate(),emitter:this.#z,dataMerge:""===n?void 0:C({serverURL:n,apiRoute:t.apiRoute,depth:t.mergeDepth,fetchFn:t.mergeFetch}),debounceMs:t.debounceMs,heartbeatMs:t.heartbeatMs,intersectionRootMargin:t.intersectionRootMargin,scopeBindingsByOwner:t.scopeBindingsByOwner,skipUnchanged:t.skipUnchanged,revealEditedField:t.revealEditedField,autoBind:t.autoBind,eventSourcePolicy:t.eventSourcePolicy,dependencies:t.dependencies,strategies:t.strategies,disableVisibilityGate:t.disableVisibilityGate,visibilityGateThreshold:t.visibilityGateThreshold,enableA11y:t.enableA11y,a11yLocale:t.a11yLocale,onHeartbeatTimeout:()=>{this.#B.unlockOrigin()},lockedOrigin:()=>this.#B.lockedOrigin,validateToken:t.validateToken,log:this.#u})),this.#z.on("connect",e=>{this.#B.lockOrigin(e.origin)}),!1!==t.autoStart&&this.start()}start(){if(this.#q)return!1;if(this.#W)return this.#j.start(),!0;if(!function isInPreviewContext(){return isInIframe()||function isInPopup(){return"undefined"!=typeof window&&null!=window.opener}()}())return!1;const e=this.#j.start();return e&&(this.#W=!0),e}suspend(){return!(this.#q||!this.#W)&&this.#j.suspend()}resume(){return!(this.#q||!this.#W)&&this.#j.start()}destroy(){if(null!==this.#G)return this.#G;let e,t;this.#q=!0;const n=new Promise((n,r)=>{e=n,t=r});this.#G=n;const r=()=>{this.#z.removeAllListeners(),this.#V=!0};try{this.#j.destroy(),this.#S.destroyAll().finally(r).then(e,t)}catch(e){r(),t(e)}return n}async use(e){if(this.#q)throw new Error("LivePreviewClient: already destroyed");await this.#S.register(e)}async unuse(e){if(this.#V)throw new Error("LivePreviewClient: already destroyed");await this.#S.unregister(e)}refreshCache(){this.#j.refreshCache()}get events(){return this.#z}get plugins(){return this.#S.list()}get status(){return this.#j.status}inspect(){return{...this.#j.inspect(),plugins:this.#S.snapshot()}}get updateCount(){return this.#j.updateCount}get destroyed(){return this.#q}};function initLivePreview(e={}){const t=new LivePreviewClient({...e,autoStart:!1});return t.start()?t:null}function so(e,t,n){if(0===t.length)return;const r={type:"payload-live-preview-focus",field:t};e.postMessage(r,n)}function ao(e,t){return n=>{const r=e();null!=r&&so(r,n,t)}}var lo=Object.freeze({NoTrustedOrigin:"LP0101",ReferrerOnlyTrust:"LP0102",PluginIncompatible:"LP0103",ProfileFeatureOmitted:"LP0104",OrphanField:"LP0201",UnattributableUpdate:"LP0202",UnboundField:"LP0203",VisibilityGateDeferred:"LP0301",UnsafeAttributeWrite:"LP0401",TextTargetHasChildren:"LP0402",MissingArrayTemplate:"LP0403",StructuralItemUnkeyed:"LP0404",StructuralDuplicateKey:"LP0405",StructuralUnstableKeys:"LP0406",UnsupportedStrategy:"LP0407",UnknownValueFormat:"LP0408",SanitizerDroppedAttribute:"LP0409",UnrenderedBlockKept:"LP0410",UnfaithfulPatch:"LP0411",ServerFormatReplaced:"LP0412",UnrenderedBlockLost:"LP0413",MessageRejected:"LP0501",TokenRejected:"LP0502",ProtocolShapeUnknown:"LP0503",HandlerThrew:"LP0601",TransformThrew:"LP0602",RendererThrew:"LP0603",StartupFailed:"LP0605",ReadyFailed:"LP0606",HydrationWaitTimedOut:"LP0607",AuditRuntimeMissing:"LP0701",AuditNoFrameAncestors:"LP0702",AuditFrameOptionsBlocks:"LP0703",AuditBindingsExposed:"LP0704",AuditGateThresholdExceeded:"LP0705",AuditUnownedBindings:"LP0706",AuditNoBindings:"LP0707",AuditNotAPage:"LP0708",FragmentRequestFailed:"LP0801",FragmentResponseInvalid:"LP0802",FragmentUnauthorized:"LP0803",FragmentSuperseded:"LP0804",RouteRefreshLoop:"LP0805",FragmentStrategyUnavailable:"LP0806",UnboundChangeRefresh:"LP0807",EscalationUnavailable:"LP0808",V2ReadinessGap:"LP0709",RuntimeOnPublicPage:"LP0710"}),uo="__livePreviewRouteRefresh";function registerRouteRefresh(e){const t="undefined"==typeof window?void 0:window;return void 0===t?()=>{}:(t[uo]=e,()=>{t[uo]===e&&(t[uo]=void 0)})}export{lo as DIAGNOSTIC_CODES,EventEmitter,LivePreviewClient,ao as createPreviewFocusReporter,initLivePreview,registerRouteRefresh,so as reportPreviewFocus};
2
2
  //# sourceMappingURL=client.js.map