payload-live-preview 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -8
- package/dist/adapters/astro/index.js +1 -1
- package/dist/adapters/astro/index.js.map +1 -1
- package/dist/adapters/astro/middleware-entry.js +1 -1
- package/dist/adapters/astro/middleware-entry.js.map +1 -1
- package/dist/adapters/nextjs/index.js +1 -1
- package/dist/adapters/nextjs/index.js.map +1 -1
- package/dist/adapters/nuxt/index.js +1 -1
- package/dist/adapters/nuxt/index.js.map +1 -1
- package/dist/adapters/sveltekit/index.js +1 -1
- package/dist/adapters/sveltekit/index.js.map +1 -1
- package/dist/client.cjs +1 -1
- package/dist/client.cjs.map +1 -1
- package/dist/client.js +1 -1
- package/dist/client.js.map +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +3 -2
- package/dist/core.d.ts +3 -2
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/doctor-cli.d.ts +1 -1
- package/dist/doctor-cli.js +1 -1
- package/dist/doctor-cli.js.map +1 -1
- package/dist/doctor.d.ts +2 -2
- package/dist/doctor.js +1 -1
- package/dist/doctor.js.map +1 -1
- package/dist/fragment.cjs.map +1 -1
- package/dist/fragment.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lean.cjs +1 -1
- package/dist/lean.cjs.map +1 -1
- package/dist/lean.js +1 -1
- package/dist/lean.js.map +1 -1
- package/dist/lexical.cjs +1 -1
- package/dist/lexical.cjs.map +1 -1
- package/dist/lexical.js +1 -1
- package/dist/lexical.js.map +1 -1
- package/dist/plugins.cjs +1 -1
- package/dist/plugins.cjs.map +1 -1
- package/dist/plugins.js +1 -1
- package/dist/plugins.js.map +1 -1
- package/dist/{probe-DqaItcwX.d.ts → probe-DX_4wsBu.d.ts} +6 -0
- package/dist/server.cjs +1 -1
- package/dist/server.cjs.map +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/structural.cjs +2 -2
- package/dist/structural.cjs.map +1 -1
- package/dist/structural.js +2 -2
- package/dist/structural.js.map +1 -1
- package/package.json +1 -1
package/dist/core.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e="2.0.2";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 t="payload-live-preview-a11y",n=/* @__PURE__ */new WeakMap;function r(e){null!==e.timer&&(clearTimeout(e.timer),e.timer=null),e.messageNode?.remove(),e.messageNode=null}var i=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 e=this.document;if(null==e?.body)return null;this.lease??=function(e){let t=n.get(e);return void 0===t&&(t={element:null,owned:!1,messageNode:null,refs:0,timer:null},n.set(e,t)),t.refs+=1,t}(e);const i=this.lease,o=i.element;if(o?.isConnected&&o.ownerDocument===e)return o;if(null!==o){const e=i.owned;r(i),e&&o.remove()}let s=e.getElementById(t);return i.owned=null===s,null===s&&(s=e.createElement("div"),s.id=t,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"),e.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,t=this.document;if(null===e||null===t)return;if(this.lease=null,e.refs-=1,e.refs>0)return;const i=e.element;null!==i&&r(e),e.owned&&i?.remove(),e.element=null,n.delete(t)}say(e){const t=this.mount(),n=this.lease;if(null===t||null===n)return;let i=n.messageNode;i?.parentNode!==t?(i?.remove(),i=t.ownerDocument.createTextNode(t.hasChildNodes()?` ${e}`:e),n.messageNode=i,t.appendChild(i)):i.data=null===i.previousSibling?e:` ${e}`,null!==n.timer&&clearTimeout(n.timer);const o=setTimeout(()=>{n.timer===o&&n.element===t&&r(n)},1500);n.timer=o}};function o(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){const e=s(n);e&&t.push(e)}return t}function s(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 i=o(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 i=o(e.fields);t.push({...e,slug:r,fields:i})}return t}(t.blocks),a={...t,name:n,type:r};return i.length>0?a.fields=i:delete a.fields,s.length>0?a.blocks=s:delete a.blocks,a}function a(e,t){return void 0===e||t(e)}function l(e,t){return null==e||t(e)}function u(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||null===Object.getPrototypeOf(t)}var c=["data","fieldSchemaJSON","globalSlug","collectionSlug","locale","ready","previewToken","protocolVersion"],d=4,h={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"}},f=Object.keys(h);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 f)(i>=h[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 hasCapability(e,t){return e.capabilities.has(t)}function p(e){return("object"==typeof e&&null!==e||"function"==typeof e)&&"function"==typeof e.then&&(Promise.resolve(e).catch(()=>{}),!0)}function m(e,t){return e.generation===t.generation&&e.revision===t.revision}var g=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 i=e.data;var s;if("object"==typeof(s=i)&&null!==s&&"type"in s&&"string"==typeof s.type)switch(i.type){case"payload-live-preview":return function(e){const t=e;return!(void 0!==t.data&&null!==t.data&&!u(t.data))&&l(t.fieldSchemaJSON,e=>Array.isArray(e))&&l(t.globalSlug,e=>"string"==typeof e)&&l(t.collectionSlug,e=>"string"==typeof e)&&l(t.locale,e=>"string"==typeof e)&&l(t.ready,e=>"boolean"==typeof e)&&l(t.previewToken,e=>"string"==typeof e)&&l(t.protocolVersion,e=>"number"==typeof e)}(i)?void this.dispatchUpdate(function(e){const t={...e};for(const e of c)null===Reflect.get(t,e)&&Reflect.deleteProperty(t,e);if(!Array.isArray(t.fieldSchemaJSON))return t;let n;try{n=o(t.fieldSchemaJSON)}catch{n=[]}return{...t,fieldSchemaJSON:n}}(i),r,t):void this.reportInvalid("shape",r,t);case"payload-document-event":return function(e){const t=e;return a(t.action,e=>"updated"===e||"created"===e||"deleted"===e)&&a(t.slug,e=>"string"==typeof e)&&a(t.id,e=>"string"==typeof e||Number.isFinite(e))}(i)?void this.invokeHandler(t,this.handlers.onDocumentEvent,i,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}(i);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=u(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{p(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 v(e){return(...t)=>{try{p(e(...t))}catch{}}}function y(){}var b=v((...e)=>console.error(...e)),w=v((...e)=>console.warn(...e)),S=v((...e)=>console.debug(...e)),k={"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'"},A=/* @__PURE__ */new Set;function T(e){A.has(e)||(A.add(e),w(`[live-preview] LP0104: this page carries the lean runtime, which leaves out ${e} (${k[e]}). The elements are left as the server rendered them. Remove \`runtime: LEAN_RUNTIME\` to get the full runtime.`))}function C(e){return"undefined"!=typeof __LEAN_BUILD__&&__LEAN_BUILD__?function(e){return!1!==e.enableA11y&&T("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 i(e.a11yLocale,n)}(e)}function $(e){if("undefined"==typeof window)return;const t=[];window.parent!==window&&t.push(window.parent),window.opener instanceof Window&&t.push(window.opener),g.sendReady(t,e)}function R(e){const t={};for(const[n,r]of Object.entries(e))void 0!==r&&(t[n]=r);return t}var P=/* @__PURE__ */new Set(["tabs","row","collapsible"]);function N(e,t=""){const n=/* @__PURE__ */new Map;return F(e,t,n),n}function F(e,t,n){for(const r of e){if(P.has(r.type)){r.fields&&F(r.fields,t,n);continue}const e=""===t?r.name:`${t}.${r.name}`;if(n.set(e,r),"group"===r.type)r.fields&&F(r.fields,e,n);else if("array"===r.type&&r.fields)F(r.fields,`${e}.*`,n);else if("blocks"===r.type&&r.blocks)for(const t of r.blocks)F(t.fields,`${e}.*.${t.slug}`,n)}}function L(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 x(e){if("object"!=typeof e||null===e)return;const t=e.id;return"string"==typeof t||"number"==typeof t?t:void 0}function M(e){if("object"!=typeof e||null===e)return;const t=e.blockType;return"string"==typeof t?t:void 0}function U(e,t){return t.every(e=>void 0!==x(e))?function(e,t){const n=[],r=/* @__PURE__ */new Map;for(let t=0;t<e.length;t+=1){const n=x(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=x(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];M(u)===M(s)?(l!==o&&n.push({kind:"move",from:l,to:o,value:s}),E(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)E(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 E(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 I={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"},O=/* @__PURE__ */new Set(["http:","https:","mailto:","tel:"]),_=/^\s*(?:javascript|data|vbscript|file|blob|about)\s*:/i,z=/^(?:\.{1,2}\/|[a-zA-Z0-9_-]+\/?)/,D=/^[\\/]{2}/,B=/[\t\n\r]/g;function isSafeUrl(e){if("string"!=typeof e)return!1;const t=e.trim().replace(B,"");if(0===t.length)return!1;if(_.test(t))return!1;if(t.startsWith("#")||t.startsWith("?"))return!0;if(D.test(t))return!0;if(t.startsWith("/"))return!0;try{const e=new URL(t);return O.has(e.protocol)}catch{return z.test(t)}}function isExternalHttpUrl(e){const t=e.trim().replace(B,"");return/^https?:\/\//i.test(t)||D.test(t)}var j=/* @__PURE__ */new Set(["style","srcdoc","formaction","form","id","name","is","srcset","imagesrcset"]),H=/* @__PURE__ */new Set(["href","src","poster","cite","action","xlink:href","data"]);function W(e){return!e.startsWith("on")&&!j.has(e)}function q(e){return e.onUnfaithfulPatch??("ignore"===e.onUnboundChange?"ignore":"escalate")}function V(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 G(e,t){return!e.unfaithfulFields.has(t)&&(e.unfaithfulFields.add(t),e.unfaithfulCount+=1,!0)}var K=/* @__PURE__ */new Set(["date","number","checkbox"]);function J(e){return"INPUT"===e.tagName||"TEXTAREA"===e.tagName?e.value:e.textContent}function Q(e){const t=e.trim();return JSON.stringify(t.length>40?`${t.slice(0,40)}…`:t)}var X=/* @__PURE__ */new WeakSet;function Z(e){return X.add(e),e}function Y(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 ee=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=Y(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}},te="data-payload-fragment";function ne(e){return e.closest(`[${te}]`)}function re(e){const t=e.getAttribute("data-payload-strategy");return null!==t&&t.length>0?"patch"===t||"fragment"===t||"route"===t?t:void 0:null!==ne(e)?"fragment":null!==e.closest("head")?"route":"patch"}function ie(e,t){return void 0===t||""===t?`collection:${e}`:`collection:${e}:${t}`}function oe(e){return"string"==typeof e&&e.length>0}function se(e,t){return null!==t&&void 0!==e&&t.includes(e)}function ae(e){const t=e.id;return"string"==typeof t&&t.length>0?t:"number"==typeof t&&Number.isFinite(t)?String(t):void 0}var le=/* @__PURE__ */new Set(["id","_id","createdAt","updatedAt","createdBy","updatedBy","_status","globalType","collection","locale","localized"]);function ue(e,t,n){const r=e.get(t);return void 0!==r&&(!1===n||r.some(e=>se(e.owner,n)))}function ce(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=>se(e.owner,n)))return!0}return!1}function de(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 he(e,t,n){let r;return i=>{if(ue(e,i,n))return!0;const o=de(i,t);return!(o===i||!ue(e,o,n))||!!ce(e,i,n)||!(o===i||!ce(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||se(e.owner,t))&&void 0!==e.locale&&n.add(`${r}_${e.locale}`);return n}(e,n),r.has(i))}}function fe(e,t,n,r){const i=he(e,n,r),o=[];for(const e of t)le.has(e)||i(e)||o.push(e);return o}var pe=/* @__PURE__ */new Set(["text","textarea","email","number","checkbox","date","select","radio","point","code","json","ui","html"]),me={},ge=class{rawChanges=new ee;resolved=null;queued=null;pending=null;timer=null;openUntil=0;decide(e,t){const n=t.message.data??{},{changed:r}=this.rawChanges.diff(n,me);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(ye(e)||e.fieldName.includes("."))return!0;if(we(e.hrefField)||we(e.srcField)||we(e.altField))return!0}return void 0!==e.strategies.fragment&&null!==e.root.querySelector(`[${te}]`)}(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(le.has(a)){o[a]=r;continue}const l=ve(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 ve(e,t,n,r,i){return be(n)?!be(t)||function(e,t,n){const r=void 0===n?void 0:L(n,e);return void 0!==r&&!pe.has(r.type)||!0===t.get(e)?.some(ye)||ce(t,e,!1)}(e,r,i)?"keep":null==t?"ask":"own":"ask"}function ye(e){return!pe.has(e.fieldType)}function be(e){return null===e||"object"!=typeof e&&"function"!=typeof e}function we(e){return!0===e?.includes(".")}var Se=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 ke(e){return null!==e&&e.forceRender&&!e.completed}var Ae=class{lastIdentity=void 0;edit(e){const t=e.externallyUpdatedRelationship;if("object"!=typeof t||null===t)return null;const n=JSON.stringify([t.entitySlug,ae(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=ae(e),i=ae(t.data??{});return void 0!==r&&void 0!==i&&r!==i}(t,e)?t:null}};function Te(e){try{return!0===e.matchMedia?.("(prefers-reduced-motion: reduce)").matches}catch{return!1}}var Ce=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:Te(t)?"auto":"smooth",block:"center"}),"revealed")}(t,n))}reset(){this.#e=void 0}},$e=class{seen=/* @__PURE__ */new Map;note(e,t,n){const r=Y(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}},Re=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;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 $e;fragmentStats={rendered:0,failed:0,superseded:0};routeStats={refreshes:0,failed:0,refused:0,loopStopped:0};fragmentController=null;routeController=null;routeRetry=null;readyTimers=[];revealer=new Ce;changes=new ee;merges=new ge;protocol=new Se;relationships=new Ae;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);for(const e of["fragmentController","routeController"]){const t=this[e];null!==t&&(this[e]=null,t.abort())}}},Pe=class{constructor(e,t){this.deps=e,this.state=t,this.instanceContext=R({renderRichText:e.renderRichText,sanitizerPolicy:e.sanitizerPolicy,reportUnfaithful:(n,r)=>{V(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||!m(r.revision,e.revision)||!n.isCurrent(r))return!1;const{target:i,value:o}=e,s=void 0!==r.schemaIndex?L(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(I,e))return I[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(!W(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 H.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),V(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||!K.has(r))return;if(t.checkedServerFormat.has(n.element))return;t.checkedServerFormat.add(n.element);const i=J(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 X.has(e.render)}(a))return V(t,n,i,`is a value ${a.name} cannot render`),!1;void 0!==e&&function(e,t,n){const r=J(t.element);r!==n&&e.warn(`[live-preview] LP0412: "${t.fieldName}" showed ${Q(n)}, the patch wrote ${Q(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 f=n.isCurrent(r);return f&&(void 0!==e.valueIdentity?n.lastAppliedIdentity.set(i.element,e.valueIdentity):n.lastAppliedIdentity.delete(i.element)),f}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 Ne(...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 Fe(e,t){const n={};for(const r of t)r!==e&&(n[r]=[e]);return n}var Le="payload-live-preview:update",xe="data-payload-island",Me=`astro-island, [${xe}]`;function Ue(e){return"patch"===e.getAttribute(xe)}function Ee(e){return function(e){return"astro-island"===e.tagName.toLowerCase()||e.hasAttribute(xe)}(e)&&!Ue(e)}function isInsideIsland(e){let t=e;for(;null!==t;){if(Ee(t))return!0;t=t.parentElement}return!1}var Ie="data-payload-field",Oe="data-payload-type",_e="data-payload-attribute",ze="data-payload-href",De="data-payload-src",Be="data-payload-alt",je="data-payload-array-template",He="data-payload-array-separator",We="data-payload-locale",qe="data-payload-richtext",Ve="data-payload-html",Ge="data-payload-array",Ke="data-payload-structural",Je="data-payload-owner",Qe="data-payload-depends",Xe="data-payload-strategy",Ze="data-payload-boundary",Ye="data-payload-guessed",et=[Ie,Oe,_e,ze,De,Be,je,He,We,qe,Ve,Ge,Ke,Je,Qe,Xe,Ze,"type"],tt=`[${Ie}]`,nt=`[${Je}]`;function rt(e){const t=e.closest(nt)?.getAttribute(Je);return null==t||0===t.length?void 0:t}var it=/^[a-z][a-z0-9-]*:[a-z][a-z0-9-]*$/i,ot=/* @__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 st(e){return ot.has(e)||it.test(e)}var at=class{entriesByField=/* @__PURE__ */new Map;entryByElement=/* @__PURE__ */new WeakMap;filter;count=0;dependencies=null;islandRoots=[];constructor(e={}){this.filter=e.filter??ut}dependencyMap(){if(null!==this.dependencies)return this.dependencies;const e=[];for(const t of this.values())void 0!==t.dependsOn&&e.push(Fe(t.fieldName,t.dependsOn));return this.dependencies=Ne(...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(tt))void 0!==this.add(t)&&(n+=1);return this.islandRoots=function(e){const t=[];for(const n of e.querySelectorAll(Me))Ue(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(Ie);if(null===t||0===t.length)return;const n=e.getAttribute(Oe),r=e.getAttribute(_e),i=e.getAttribute(ze),o=e.getAttribute(De),s=e.getAttribute(Be),a=e.getAttribute(je),l=e.getAttribute(He),u=e.getAttribute(We),c=e.getAttribute("data-payload-format"),d=rt(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(Qe)),f=e.getAttribute(Xe),p=e.getAttribute(Ye),m=ne(e);return{element:e,fieldName:t,fieldType:lt(e),explicitFieldType:null!==n&&st(n),strategyKind:re(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(Ze)?{hidesWhenEmpty:!0}:{},...null!==p?{guessed:p}:{}}}};function lt(e){const t=e.getAttribute(Oe);if(null!==t&&st(t))return t;if(e.hasAttribute(qe))return"richText";if(e.hasAttribute(Ve))return"html";if(e.hasAttribute(Ke))return"structural-array";if(e.hasAttribute(Ge))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 ut(){return!0}function ct(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 dt(e){return ct(e,128)&&!e.includes("?")&&!e.includes("#")}var ht=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=v(e.log??y)}canMerge(e){return null!==this.endpointOf(e)}endpointOf(e){try{const n=e.globalSlug;if(n)return dt(n)?`globals/${encodeURIComponent(n)}`:null;const r=e.collectionSlug??"",i=e.data.id;return dt(r)&&("number"==typeof(t=i)?Number.isFinite(t):"string"==typeof t&&ct(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}}},ft={name:"payload-2",fieldTyping:"schema",populatesRelationships:"admin",documentEvents:!1},pt={name:"payload-3",fieldTyping:"heuristic",populatesRelationships:"server",documentEvents:!0},mt={name:"unknown",fieldTyping:"heuristic",populatesRelationships:"server",documentEvents:!1};function detectProtocolProfile(e){return e.has("schema-json")?ft:e.has("document-events")||e.has("relationship-events")?pt:mt}var gt=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:[...et]})}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&&et.includes(t.attributeName)&&(t.attributeName===Ie||t.attributeName===Je||1===t.target.nodeType&&t.target.hasAttribute(Ie)))return!0;for(const e of t.addedNodes)if(vt(e))return!0;for(const e of t.removedNodes)if(vt(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 vt(e){if(1!==e.nodeType)return!1;const t=e;return t.hasAttribute(Ie)||null!==t.querySelector(`[${Ie}]`)}var yt="[data-payload-field]";function bt(){if("undefined"==typeof window)return;const e=window;return e.__livePreviewHydration??={armed:!1,committed:!1,commits:[],onCommit:void 0,waiters:[]}}function wt(){const e=bt();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 St(e){e.committed=!0;const t=e.waiters;e.waiters=[];for(const e of t)e()}function kt(e,t){const n=e.waiters.indexOf(t);n>=0&&e.waiters.splice(n,1)}function At(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,kt(e,i),t("timed-out")},n),()=>{null!==r&&clearTimeout(r),r=null,kt(e,i)}}var Tt="__vue_app__";function Ct(){if("undefined"==typeof window)return;const e=window;return e.__livePreviewVueHydration??={armed:!1,committed:!1,waiters:[]}}function $t(e){return Object.prototype.hasOwnProperty.call(e,Tt)?e[Tt]:void 0}function Rt(){const e=Ct();if(void 0===e||e.armed)return;e.armed=!0;const t=Element.prototype;void 0===Object.getOwnPropertyDescriptor(t,Tt)&&Object.defineProperty(t,Tt,{configurable:!0,get:()=>{},set(e){Object.defineProperty(this,Tt,{value:e,writable:!0,configurable:!0,enumerable:!0});const t=Ct();void 0===t||t.committed||null===this.querySelector(yt)||function(e,t){const n=t?.$nuxt;!0!==n?.isHydrating||"function"!=typeof n.hook?St(e):n.hook("app:suspense:resolve",()=>{e.committed||St(e)})}(t,e)}})}function Pt(e){if(void 0===e.hydration)return void e.startNow();const t=t=>{e.later(()=>{Nt(e,t)})},n="react"===e.hydration?function(e,t=5e3){wt();const n=bt();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?.(yt)}(e)&&St(n)};n.onCommit=e;for(const t of n.commits.splice(0))e(t)}return At(n,e,t)}(t):function(e,t,n=5e3){Rt();const r=Ct();return void 0===r?null:(!r.committed&&function(e){for(let t=e.querySelector(yt);null!==t;t=t.parentElement)if(void 0!==$t(t))return!0;return!1}(e)&&St(r),At(r,t,n))}(e.root,t);null!==n?(e.defer(n),e.hydrated("waiting")):Nt(e,"committed")}function Nt(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 Ft=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}},Lt=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)}},xt=/* @__PURE__ */new Set(["true","false","yes","no","on","off"]),Mt=/^[\d\s.,:+/-]+$/u,Ut=/^[a-z][a-z0-9_-]*$/u,Et=/^[a-z]{2,3}(?:[-_][A-Za-z0-9]{2,8})*$/u,It=/* @__PURE__ */new Set(["SCRIPT","STYLE","TEMPLATE","TITLE","NOSCRIPT","TEXTAREA","SELECT","OPTION","INPUT","IFRAME"]);function Ot(e,t=13){if("string"!=typeof e)return!1;const n=e.trim();return!(n.length<t||Mt.test(n)||xt.has(n.toLowerCase())||Ut.test(n)||Et.test(n))}function _t(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function zt(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(le.has(r))continue;const e=de(r,t);if(Ot(o,n))i(o.trim(),e,!1);else if(_t(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))!le.has(t)&&Ot(r,n)&&i(r.trim(),`${e}.${t}`,!1)}return r}function Dt(e){if("http://www.w3.org/1999/xhtml"!==e.namespaceURI||It.has(e.tagName))return!0;if(e.hasAttribute(Ie)||e.hasAttribute("data-payload-no-bind")||e.hasAttribute("data-payload-owned")||Ee(e))return!0;const t=e.getAttribute("contenteditable");return null!==t&&"false"!==t}function Bt(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 jt(e){return W(e)&&!e.startsWith("data-payload-")&&"value"!==e}function Ht(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 Wt(e,t){for(let n=e.firstElementChild;null!==n;n=n.nextElementSibling){if(Dt(n))continue;const e=Bt(n),r=void 0===e?void 0:t.values.get(e);null==r||r.media||(Ht(t,n,r).text=r.field);for(const e of n.getAttributeNames()){if(!jt(e))continue;const r=t.values.get(n.getAttribute(e)??"");null!=r&&(!r.media||"IMG"===n.tagName&&"src"===e)&&Ht(t,n,r).attributes.set(e,r)}Wt(n,t)}}function qt(e,t,n){const r=e.tagName;if(void 0!==t){const i={[Ie]:t};if("A"===r){const e=n.get("href");void 0===e?i[Oe]="text":e!==t&&(i[ze]=e)}return{element:e,fieldName:t,matched:Bt(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:{[Ie]:t,...void 0!==r&&r!==t?{[Be]: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:{[Ie]:s,[_e]:o}}}function Vt(e,t){const n={values:t,byElement:/* @__PURE__ */new Map,byField:/* @__PURE__ */new Map};t.size>0&&!Dt(e)&&Wt(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=qt(e,n,o);void 0!==s&&i.push(s)}return i}function Gt(e){return 9===e.nodeType?e.body:e}function Kt(e,t,n,r){const i=[];for(const o of t){const{element:t}=o;if(!t.hasAttribute(Ie)&&(!1===n||se(rt(t),n))){for(const[e,n]of Object.entries(o.stamps))t.setAttribute(e,n);if(t.setAttribute(Ye,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(Ye)}}}return i}var Jt,Qt=/* @__PURE__ */new Set(["__proto__","prototype","constructor"]);function Xt(e,t,n,r=!1){if(r&&void 0!==n){const r=Zt(e,`${t}_${n}`);if(void 0!==r)return r}const i=Zt(e,t);if(void 0!==i)return i;if(t.includes(".")){let n=e,r=!0;for(const e of t.split(".")){if(Qt.has(e)||null===n||"object"!=typeof n){r=!1;break}if(n=Zt(n,e),void 0===n){r=!1;break}}if(r)return n}return void 0===n?void 0:Zt(e,`${t}_${n}`)}function Zt(e,t){if(!Qt.has(t)&&Object.prototype.hasOwnProperty.call(e,t))return e[t]}function Yt(e,t,n,r){return Xt(e,n,t.locale??r,void 0!==t.locale)}function en(e,t,n,r){const i=Y(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=Y(Yt(n,e,t,r));if(void 0===i)return;s+=`|${t}=${i}`}return s}function tn(e,t,n,r){const{warned:i,warn:o}=e;i.has(n)||t(n)||(i.add(n),o(`[live-preview] LP0201: no <… data-payload-field="${de(n,r)}"> for field "${n}"; render the anchor unconditionally so edits to an empty field have somewhere to land.`))}function nn(e){const t=typeof e;return"string"===t||"number"===t||"boolean"===t||"bigint"===t}function rn(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function on(e){const t=function(){if(void 0!==Jt)return Jt;const e=function(){const e=globalThis.trustedTypes;if("object"==typeof e&&null!==e)return"function"==typeof e.createPolicy?e:void 0}();try{Jt=void 0===e?null:e.createPolicy("payload-live-preview",{createHTML:e=>e})}catch{Jt=null}return Jt}();return null===t?e:t.createHTML(e)}var sn=/* @__PURE__ */new Set(["open","value","checked","selected"]);function an(e,t){for(const n of t.keyAttributes){const t=e.getAttribute(n);if(null!==t&&t.length>0)return`${n}=${t}`}}function ln(e){if(e.tagName.toLowerCase().includes("-"))return!0;if(e.hasAttribute(xe)||e.hasAttribute("data-payload-owned"))return!0;const t=e.getAttribute("contenteditable");return null!==t&&"false"!==t}function un(e,t,n){if(!function(e,t){return e.tagName===t.tagName&&e.namespaceURI===t.namespaceURI&&!ln(e)&&!ln(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)||sn.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=an(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?an(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=cn(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(hn(r,i)){d=cn(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&&hn(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)&&dn(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 cn(e,t,n){return e instanceof Element&&t instanceof Element?ln(e)&&ln(t)?e:un(e,t,n):(e.nodeValue!==t.nodeValue&&(e.nodeValue=t.nodeValue),e)}function dn(e){return e.nodeType===Node.TEXT_NODE&&0===(e.nodeValue??"").trim().length}function hn(e,t){return e.nodeType===t.nodeType&&(!(e instanceof Element&&t instanceof Element)||e.tagName===t.tagName&&e.namespaceURI===t.namespaceURI)}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 setSanitizerDocument(e){globalThis[Cn]=e??void 0}function sanitizeHtml(e,t){return $n(e,void 0,t)}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=on(e),Pn(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 Pn(e,t){for(const n of Array.from(e.childNodes))1===n.nodeType?Nn(n,t):8===n.nodeType&&n.remove()}function Nn(e,t){const n=e.tagName.toLowerCase();if(!vn.has(n)||t.allowFormControls&&gn.has(n)){if(!t.allowedTags.has(n))return Pn(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||Fn(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),Pn(e,t)}else e.remove()}function Fn(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 Ln=Object.freeze({"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="}),xn=/[&<>"'/`=]/g;function escapeHtml(e){return e.replace(xn,e=>Ln[e])}var Mn=Object.freeze({"&":"&","<":"<",">":">",'"':""","'":"'"}),Un=/[&<>"']/g;function escapeHtmlAttribute(e){return e.replace(Un,e=>Mn[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(!W(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 zn(e,t){for(const[n,r]of t)e.hasAttribute(n)||e.setAttribute(n,r)}function Dn(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 jn(e,t){const n=e.get(t);return void 0!==n&&(e.delete(t),e.set(t,n)),n}function Hn(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=jn(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 Hn(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;for(const[e,o,l,u,c]of i){let i=o;if(void 0!==l){const e=!(!n.morph||c||null===o)&&un(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);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)sr(l,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=U(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,Dn,s),i,Kn(t)),l=e.createElement("template");l.innerHTML=on(a);const u=l.content.firstElementChild;if(!u)return null;zn(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))}hasUnboundChange(e,t){const{deps:n,state:r}=this;if(e.baseline||e.routeRefreshed)return!1;const i=fe(n.cache,e.touched,e.locale,t);let o=0;for(const e of i)G(r,e)&&(o+=1);const[s]=i;return void 0!==s&&"escalate"===n.onUnfaithfulPatch&&void 0!==n.strategies.route&&(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=on(t);const r=e.cloneNode(!1);r.append(n.content),un(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=Yt(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=p(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=fe(e.cache,n.touched,n.locale,r);for(const e of i)G(t,e);return!1},hasRouteBinding:()=>!1,runFragments:()=>Promise.resolve(),refreshRoute:()=>(T("route refreshes"),Promise.resolve()),warnFragmentFallback:n=>{T("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=N(e.fieldSchemaJSON));const s={revision:n,message:e,locale:i.locale,schema:i.schema,schemaIndex:i.schemaIndex,receivedAt:Date.now(),forceRender:null!==o||ke(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=Ne(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__)T("auto-binding");else{const n=this.ownerKeysForUpdate(e,t.fields);!function(e,t,n,r,i){const o=performance.now(),s=Gt(e.root),a=zt(n,r),l=null===s?[]:Kt(e,Vt(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[ze,Be]){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);if(void 0!==a&&!e.routeRefreshed&&(l||a.plan(n.root,s)||this.strategies.hasRouteBinding(s)))return void this.strategies.refreshRoute(e,t,a);const u=this.strategies.planFragments(s),c=n.skipUnchanged;let d=0;for(const[s,a]of n.cache.entries()){if(!i())return;for(const l of a){if(!1!==o&&!se(l.owner,o))continue;if(!0===u?.covers(l)){if(n.revealEditedField){const n=Yt(t.fields,l,s,e.locale);r.revealLedger.note(e,l,n)}continue}const a=l.strategyKind??re(l.element)??"unknown";if("unknown"===a){this.strategies.warnUnsupportedStrategy(l);continue}"fragment"===a&&null===u&&this.strategies.warnFragmentFallback(l);const h=Yt(t.fields,l,s,e.locale);if(void 0===h){r.absentFields.add(s);continue}if(n.revealEditedField&&r.revealLedger.note(e,l,h),!i())return;const f=mr(n,l,h,t.fields,i);if(!i())return;const p=c?en(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),d+=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(se(n.owner,t))return!0;return!1}(i,r))return;const o=he(i,n,r);for(const[r,i]of Object.entries(t)){if(le.has(r))continue;if(nn(i)){tn(e,o,r,n);continue}if(!rn(i)||o(r))continue;const t=de(r,n);for(const[r,s]of Object.entries(i))nn(s)&&!le.has(r)&&tn(e,o,`${t}.${r}`,n)}})({cache:n.cache,warned:r.warnedOrphanFields,warn:n.warn},t.fields,e.locale,o),null!==u&&u.boundaries.length>0&&(e.pendingFragments=u.boundaries.length,this.strategies.runFragments(e,t,u)),0===d&&0===e.pendingFragments&&(r.complete(e),this.revealPending(e))}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=Gt(e.root);if(null===o||0===o.fields.size||null===s)return 0;const a=new Map(o.values);for(const[e,t]of zt(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)}Kt(e,Vt(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(oe(e.globalSlug))return[(t=e.globalSlug,`global:${t}`)];var t;if(!oe(e.collectionSlug))return null;const n=ie(e.collectionSlug);return oe(e.documentId)?[n,ie(e.collectionSlug,e.documentId)]:[n]}({globalSlug:"string"==typeof i.globalSlug?i.globalSlug:void 0,collectionSlug:"string"==typeof i.collectionSlug?i.collectionSlug:void 0,documentId:ae(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)||!m(o.revision,r))return;0===o.pendingFragments&&n.complete(o);const s=()=>n.isCurrent(o)&&m(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())||0!==e.applied&&void 0!==i&&(t.a11y?.announceUpdate(e.applied),s()&&(function(e,t){for(const n of e)n.dispatchEvent(new CustomEvent(Le,{detail:t,bubbles:!1}));e.length}(t.cache.islands,{fields:i.fields,revision:r.revision,receivedAt:o.receivedAt,locale:o.locale}),s()&&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||!m(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&&m(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&&m(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&&m(e.revision,this.activeRevision)}didApply(e){return!1!==this.apply(e)||(t=this.apply,!X.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 Re;pipeline;writer;rootSentinel=null;observedRoot=null;constructor(e){const{emitter:t,renderers:n}=e,r=void 0===e.log?y:v(e.log),i=void 0===e.warn?w:v(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 at({filter:e=>!isInsideIsland(e)}),a=new gt({onStructuralChange:()=>{this.rebuildCache()},onVisibilityChange:(e,t)=>{t&&l.notifyVisible(e)}},void 0!==e.intersectionRootMargin?{intersectionRootMargin:e.intersectionRootMargin}:{}),l=new yr(Z(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 g(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 Lt,heartbeat:new Ft({...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??$,onHeartbeatTimeout:e.onHeartbeatTimeout,log:r,warn:i,a11y:C(e),merger:void 0===c?null:new ht({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:q(e),autoBind:e.autoBind??"off",hydration:e.hydration},this.writer=new Pe(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?wt():"vue"===e.hydration&&Rt();const{root:t}=e;if(!function(e){return 9===e.nodeType}(t)||"loading"!==t.readyState)return void Pt(e);const n=()=>{e.isRunning()&&e.later(()=>{Pt(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(t,n){const{cache:r,scheduler:i}=t,o=n.protocol.negotiation,s=n.activeUpdate,a=n.lastFlush,l=[],u=/* @__PURE__ */new Set,c=[];for(const[e,t]of r.entries()){l.push(e);for(const n of t)void 0!==n.owner&&u.add(n.owner),void 0!==n.guessed&&c.push({field:e,matched:n.guessed,attribute:n.targetAttribute??("IMG"===n.element.tagName?"src":void 0)})}return{version:e,started:n.started,status:t.connection.status,origins:{trusted:[...t.readyTargets()],locked:t.lockedOrigin()},protocol:{ours:o.ours,theirs:o.theirs,negotiated:o.negotiated,capabilities:[...o.capabilities].sort(),observed:[...o.observed].sort(),profile:detectProtocolProfile(o.observed).name},revisions:{accepted:n.updateCount,superseded:n.supersededCount,completed:n.completedCount,skippedUnchanged:n.skippedUnchangedCount,active:null===s?void 0:s.revision.revision},bindings:{elements:r.elementCount,fields:r.fieldCount,fieldNames:l.sort(),absentFields:[...n.absentFields].sort(),orphanFields:[...n.warnedOrphanFields].sort(),ownerScoped:t.scopeBindingsByOwner,owners:[...u].sort(),guessed:c.sort((e,t)=>e.field.localeCompare(t.field)),autoBind:{mode:t.autoBind,searchMs:n.autoBindSearchMs}},route:{handler:void 0!==t.strategies.route,...n.routeStats},fidelity:{mode:t.onUnfaithfulPatch,unfaithful:n.unfaithfulCount,escalated:n.escalatedCount,fields:[...n.unfaithfulFields].sort()},hydration:{mode:t.hydration??"off",state:n.hydration},fragments:{handler:void 0!==t.strategies.fragment,inFlight:s?.pendingFragments??0,...n.fragmentStats},scheduler:{pending:i.pendingCount,deferred:i.replayCount,visibilityGateThreshold:i.gateThreshold,visibilityGateActive:i.gateActive,lastFlush:null===a?void 0:{applied:a.applied,appliedFields:a.appliedFields,deferred:a.deferred,durationMs:a.durationMs}},plugins:[],renderers:Object.keys(t.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>";b(`[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 isInPopup(){return"undefined"!=typeof window&&null!=window.opener}function isInPreviewContext(){return isInIframe()||isInPopup()}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=()=>{},Pr=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{p(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)}}},Nr=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}},Fr=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=v(e.log);const t=e.onTransformError;this.#w=void 0===t?void 0:v((...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.#P(e,!1):this.#N(()=>this.#P(e,!0))}unregister(e){return this.#R>0?this.#F(e,!1):this.#N(async()=>{await this.#F(e,!0)})}destroyAll(){return this.#R>0?this.#L(!1):this.#N(async()=>{await this.#L(!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=p(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#P(t,n){if(this.#S.has(t.name)||this.#k.has(t.name)||this.#A.has(t.name))return void this.#u(`plugin "${t.name}" already registered`);const r=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)}`}}}(t.compat,e);if(void 0!==r)return void this.#x(t.name,r);const i=new Pr(t.name,this.#u),o=this.#M(t.name,i),s={scope:i,cancelled:!1};this.#k.set(t.name,s);try{if(await this.#U(()=>t.init(o),n),s.cancelled)return;i.commit()}catch(e){return i.close(),void(s.cancelled||this.#u(`plugin "${t.name}" init failed:`,e))}finally{this.#k.get(t.name)===s&&this.#k.delete(t.name)}this.#S.set(t.name,{plugin:t,scope:i}),this.#u(`plugin "${t.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"})}#M(e,t){return{events:new Nr(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)}}}#F(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.#U(()=>t.destroy?.(),n)}catch(t){this.#u(`plugin "${e}" destroy failed:`,t)}finally{this.#T.delete(e)}}}async#L(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.#F(n,e)}async#U(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}}#N(e){const t=this.#$.then(e);return this.#$=t.catch(e=>{this.#u("plugin manager mutation failed:",e)}),t}},Lr=class{#O;#_;#z=/* @__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.#z.get(t);void 0===r?this.#z.set(t,[n]):r.push(n),this.#_[t]=e;let i=!0;return()=>{if(!i)return;i=!1;const e=this.#z.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.#z.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"},Mr=/* @__PURE__ */new Set(["left","center","right","justify","start","end"]);function Ur(e){const t=e.format;return"string"==typeof t&&Mr.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=Ur(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 zr(e){return"object"==typeof e&&null!==e?e:void 0}function Dr(e){return zr(e)}function Br(e){return e.replace(/[^a-zA-Z0-9_-]/g,"-").toLowerCase()}function jr(e){return"string"==typeof e&&e.length>0?e:void 0}function Hr(e){const t=jr(e.title)??jr(e.name)??jr(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=zr(e.fields),i=function(e,t){if("internal"===t?.linkType)return function(e){const t=zr(zr(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=zr(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=Dr(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=zr(e.value),r=escapeHtml((n&&Hr(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__ */Z((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),w(`[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=on(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__ */Z((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=on($n(o,i)))}if(ri(t)){const o=/* @__PURE__ */new Map,s=function(e,t){const n=e.cloneNode(!1);n.innerHTML=on(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(Ie))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:Ur,resolveIndent:Er,onUnrenderedBlock:e};return t}(t.onUnrenderedBlock).renderChildren(e.root.children);return!1===t.sanitize?n:void 0!==Rn()?sanitizeHtml(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=on($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),w(`[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:Dn(t);e.element.innerHTML=on($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),w(`[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=Dn(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):Xt(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__ */Z((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?Xt(n.allFields,e.srcField,n.locale,r):t,o=Dr(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=Xt(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__ */Z((e,t)=>{const n=e.element;if(Bn(t))return void Ri(n);const r=Dr(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=on(`<a href="${escapeHtmlAttribute(o)}">${s}</a>`)})};function Ri(e){"IMG"!==e.tagName?(e.removeAttribute("href"),e.textContent=""):Si(e)}var Pi={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,zr(t)?.url);"safe"===r.kind?n.setAttribute("href",r.url):"unsafe"===r.kind&&n.removeAttribute("href")}n.textContent=Array.isArray(t)?t.map(Ni).join(", "):Ni(t)}};function Ni(e){const t=zr(e);return void 0===t?Dn(e):Hr(t)??""}var Fi={name:"select",render(e,t,n){const r=e.element,i=Bn(t)?[]:function(e){return Array.isArray(e)?e.map(Dn):[Dn(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=zr(t);if(void 0!==n&&Dn(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)}},Li=/* @__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?!Li.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}},Mi=/* @__PURE__ */new Map,Ui=/* @__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"]),zi=/^[A-Za-z]{3}$/u,Di=/^[0-4]$/u;function Bi(e){return{kind:"date",options:e}}function ji(e){return{kind:"number",options:e}}var Hi=/* @__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 ji({});if(!Di.test(r))return;return ji({minimumFractionDigits:Number(r),maximumFractionDigits:Number(r)});case"currency":if(void 0===r||!zi.test(r))return;return ji({style:"currency",currency:r.toUpperCase()});case"percent":return void 0===r?ji({style:"percent"}):void 0;default:return}}(t);if(void 0!==i){if(i.kind===e)return i.options}else!function(e,t,n){Hi.has(e)||(Hi.add(e),w(`[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:Dn(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 jn(Ui,n)??Hn(Ui,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(Dn(t));Number.isNaN(i)?r.textContent=Dn(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 jn(Mi,n)??Hn(Mi,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__ */Z((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,Dn,n);return r}(i,t),o=n.sanitizerPolicy,s=Kn(i),a=_n(r);r.innerHTML=on($n(e,o,s));for(const e of Array.from(r.children))zn(e,a);return}r.textContent=t.map(Dn).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__ */Z((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),w(`[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=U(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),w(`[live-preview] ${r}`))}var to=/* @__PURE__ */new Map;function no(e,t){return{name:e,render(){T(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 so,LivePreviewClient=class{#D=new EventEmitter;#B;#j;#H;#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)=>{S("[live-preview]",...e)}:y,this.#B=new OriginDetector(R({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.#j=new Lr(function(){const e=[ci,fi,vi,bi,Ti,$i,Pi,Fi,{...Fi,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 Fr({events:this.#D,config:Object.freeze({...t}),registerFieldRenderer:e=>this.#j.register(e),onTransformError:e=>{this.#D.emit("error",{error:e,context:"transform",code:"LP0602"})},log:this.#u}),this.#H=new wr(R({root:t.root,renderers:this.#j.renderers,resolveRenderer:(e,n)=>t.resolveRenderer?.(e,n)??this.#j.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.#D,dataMerge:""===n?void 0:R({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.#D.on("connect",e=>{this.#B.lockOrigin(e.origin)}),!1!==t.autoStart&&this.start()}start(){if(this.#q)return!1;if(this.#W)return this.#H.start(),!0;if(!isInPreviewContext())return!1;const e=this.#H.start();return e&&(this.#W=!0),e}suspend(){return!(this.#q||!this.#W)&&this.#H.suspend()}resume(){return!(this.#q||!this.#W)&&this.#H.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.#D.removeAllListeners(),this.#V=!0};try{this.#H.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.#H.refreshCache()}get events(){return this.#D}get plugins(){return this.#S.list()}get status(){return this.#H.status}inspect(){return{...this.#H.inspect(),plugins:this.#S.snapshot()}}get updateCount(){return this.#H.updateCount}get destroyed(){return this.#q}};function initLivePreview(e={}){const t=new LivePreviewClient({...e,autoStart:!1});return t.start()?t:null}function setCspCrypto(e){so=e??void 0}function generateCspNonce(e=16){if(!Number.isInteger(e)||e<8)throw new RangeError(`generateCspNonce: bytes must be an integer >= 8, got ${String(e)}`);const t=function(){if(so?.getRandomValues)return so;const e=globalThis.crypto;return e?.getRandomValues?e:void 0}();if(!t)throw new Error("generateCspNonce: Web Crypto is unavailable. On Node 18 call setCspCrypto(webcrypto) once at startup, or run with --experimental-global-webcrypto. We won't fabricate a predictable nonce — that would silently defeat the entire CSP.");const n=new Uint8Array(e);return t.getRandomValues(n),function(e){let t="";for(const n of e)t+=String.fromCharCode(n);return("function"==typeof btoa?btoa(t):Buffer.from(e).toString("base64")).replaceAll("+","-").replaceAll("/","_").replaceAll("=","")}(n)}function buildFrameAncestors(e={}){const{self:t=!0,origins:n=[],allowNone:r=!1}=e,i=/* @__PURE__ */new Set,o=[];if(r&&!t&&0===n.length)return"'none'";t&&(o.push("'self'"),i.add("'self'"));for(const e of n){const t=e.trim();0===t.length||i.has(t)||(i.add(t),o.push(t))}return o.length>0?o.join(" "):"'none'"}function buildScriptSrcWithNonce(e,t={}){if(0===e.length)throw new RangeError("buildScriptSrcWithNonce: nonce is empty");const{self:n=!0,extra:r=[],strictDynamic:i=!1}=t,o=[];n&&o.push("'self'"),o.push(`'nonce-${e}'`),i&&o.push("'strict-dynamic'");for(const e of r){const t=e.trim();t.length>0&&o.push(t)}return o.join(" ")}var ao="payload-live-preview.authorized-preview-context",lo=Symbol.for(ao);function isAuthorizedPreviewContext(e){return"object"==typeof e&&null!==e&&!0===e[lo]&&Object.isFrozen(e)}var uo={basic:{gates:"data updates are applied to bound elements",fallback:"none — every peer has it"},"schema-json":{gates:"field typing from fieldSchemaJSON (Payload 2.x) and the payload-2 profile",fallback:"field types come from DOM heuristics and Lexical auto-detection"},locale:{gates:"locale-aware field resolution (`title_de` before `title`) and the locale on island events",fallback:"bindings resolve the unsuffixed field value"},"preview-token":{gates:"per-message token validation (library extension)",fallback:"messages carry no token; validateToken cannot be satisfied"},"nested-arrays":{gates:"keyed array diffs below the top level",fallback:"array updates replace the whole array"},"recursive-diffs":{gates:"recursive object diffs",fallback:"nested objects re-render as a unit"},"document-events":{gates:"the `documentSave` runtime event, the document-save plugin and the payload-3 profile",fallback:"no documentSave event; a save is not distinguishable from an edit"},"relationship-events":{gates:"the `relationshipUpdate` runtime event and an unconditional re-render of the update that carries it",fallback:"a related document edited in a drawer shows up on the next data update only"}},co="__livePreviewRouteRefresh";function registerRouteRefresh(e){const t="undefined"==typeof window?void 0:window;return void 0===t?()=>{}:(t[co]=e,()=>{t[co]===e&&(t[co]=void 0)})}var ho=Object.freeze({NoTrustedOrigin:"LP0101",ReferrerOnlyTrust:"LP0102",PluginIncompatible:"LP0103",ProfileFeatureOmitted:"LP0104",OrphanField:"LP0201",UnattributableUpdate:"LP0202",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",V2ReadinessGap:"LP0709",RuntimeOnPublicPage:"LP0710"});function bind(e,t){return fo(e,t)}function bindByPath(e,t){const n=function(e){const t=[],n=new Proxy({},{get(e,r){if("symbol"!=typeof r)return/^\d+$/.test(r)||t.push(r),n}});try{e(n)}catch{}return t}(e);if(0===n.length)throw new Error("bindByPath: the picker did not read any field — return data.<field> instead of a constant");return fo(n.join("."),t)}function fo(e,t){if(0===e.length)throw new Error("bind: field name must be a non-empty string");const n={"data-payload-field":e};return void 0!==t?.attribute&&(n["data-payload-attribute"]=t.attribute),void 0!==t?.type&&(n["data-payload-type"]=t.type),!0===t?.richtext&&(n["data-payload-richtext"]=""),!0===t?.html&&(n["data-payload-html"]=""),void 0!==t?.locale&&(n["data-payload-locale"]=t.locale),void 0!==t?.alt&&(n["data-payload-alt"]=t.alt),void 0!==t?.href&&(n["data-payload-href"]=t.href),void 0!==t?.arrayTemplate&&(n["data-payload-array-template"]=t.arrayTemplate),n}var po=/^[a-z][a-z0-9-]{0,63}$/u,mo=Object.freeze({});function createPreviewBindings(e){const t=isAuthorizedPreviewContext(e.authorization),n=void 0!==e.owner&&e.owner.length>0?e.owner:void 0;return Object.freeze({authorized:t,bind:(e,n)=>t?bind(e,n):mo,bindByPath:(e,n)=>t?bindByPath(e,n):mo,owner:()=>t&&void 0!==n?{"data-payload-owner":n}:mo,boundary:(e,n={})=>{const r=function(e,t){if(!po.test(e))throw new RangeError(`createPreviewBindings().boundary(): "${e}" is not a registry id — lowercase, starting with a letter, then letters, digits or hyphens (max 64). The runtime would post it and the endpoint would refuse it.`);const n=t.key;if(void 0!==n&&(0===n.length||n.length>128))throw new RangeError(`createPreviewBindings().boundary(): the key for "${e}" must be 1 to ${String(128)} characters.`);const r=t.dependsOn??[];return{"data-payload-fragment":e,...void 0!==n?{"data-payload-fragment-key":n}:{},...r.length>0?{"data-payload-depends":r.join(",")}:{}}}(e,n);return t?r:mo}})}var go=!0;export{ao as AUTHORIZED_PREVIEW_BRAND_KEY,h as CAPABILITY_DECLARATIONS,uo as CAPABILITY_DOCUMENTATION,go as CORE_ENTRY,ho as DIAGNOSTIC_CODES,EventEmitter,Le as ISLAND_EVENT,d as LIBRARY_PROTOCOL_VERSION,LivePreviewClient,OriginDetector,f as PROTOCOL_CAPABILITIES,e as VERSION,bind,bindByPath,buildFrameAncestors,buildScriptSrcWithNonce,createPreviewBindings,detectInitialLocale,detectProtocolProfile,escapeHtml,escapeHtmlAttribute,generateCspNonce,hasCapability,initLivePreview,isAuthorizedPreviewContext,isDevMode,isExternalHttpUrl,isInIframe,isInPopup,isInPreviewContext,isInsideIsland,isSafeUrl,negotiateProtocol,registerRouteRefresh,sanitizeHtml,setCspCrypto,setSanitizerDocument};
|
|
1
|
+
var e="2.0.3";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 t="payload-live-preview-a11y",n=/* @__PURE__ */new WeakMap;function r(e){null!==e.timer&&(clearTimeout(e.timer),e.timer=null),e.messageNode?.remove(),e.messageNode=null}var i=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 e=this.document;if(null==e?.body)return null;this.lease??=function(e){let t=n.get(e);return void 0===t&&(t={element:null,owned:!1,messageNode:null,refs:0,timer:null},n.set(e,t)),t.refs+=1,t}(e);const i=this.lease,o=i.element;if(o?.isConnected&&o.ownerDocument===e)return o;if(null!==o){const e=i.owned;r(i),e&&o.remove()}let s=e.getElementById(t);return i.owned=null===s,null===s&&(s=e.createElement("div"),s.id=t,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"),e.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,t=this.document;if(null===e||null===t)return;if(this.lease=null,e.refs-=1,e.refs>0)return;const i=e.element;null!==i&&r(e),e.owned&&i?.remove(),e.element=null,n.delete(t)}say(e){const t=this.mount(),n=this.lease;if(null===t||null===n)return;let i=n.messageNode;i?.parentNode!==t?(i?.remove(),i=t.ownerDocument.createTextNode(t.hasChildNodes()?` ${e}`:e),n.messageNode=i,t.appendChild(i)):i.data=null===i.previousSibling?e:` ${e}`,null!==n.timer&&clearTimeout(n.timer);const o=setTimeout(()=>{n.timer===o&&n.element===t&&r(n)},1500);n.timer=o}};function o(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){const e=s(n);e&&t.push(e)}return t}function s(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 i=o(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 i=o(e.fields);t.push({...e,slug:r,fields:i})}return t}(t.blocks),a={...t,name:n,type:r};return i.length>0?a.fields=i:delete a.fields,s.length>0?a.blocks=s:delete a.blocks,a}function a(e,t){return void 0===e||t(e)}function l(e,t){return null==e||t(e)}function u(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||null===Object.getPrototypeOf(t)}var d=["data","fieldSchemaJSON","globalSlug","collectionSlug","locale","ready","previewToken","protocolVersion"],c=4,h={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"}},f=Object.keys(h);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 f)(i>=h[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 hasCapability(e,t){return e.capabilities.has(t)}function p(e){return("object"==typeof e&&null!==e||"function"==typeof e)&&"function"==typeof e.then&&(Promise.resolve(e).catch(()=>{}),!0)}function m(e,t){return e.generation===t.generation&&e.revision===t.revision}var g=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 i=e.data;var s;if("object"==typeof(s=i)&&null!==s&&"type"in s&&"string"==typeof s.type)switch(i.type){case"payload-live-preview":return function(e){const t=e;return!(void 0!==t.data&&null!==t.data&&!u(t.data))&&l(t.fieldSchemaJSON,e=>Array.isArray(e))&&l(t.globalSlug,e=>"string"==typeof e)&&l(t.collectionSlug,e=>"string"==typeof e)&&l(t.locale,e=>"string"==typeof e)&&l(t.ready,e=>"boolean"==typeof e)&&l(t.previewToken,e=>"string"==typeof e)&&l(t.protocolVersion,e=>"number"==typeof e)}(i)?void this.dispatchUpdate(function(e){const t={...e};for(const e of d)null===Reflect.get(t,e)&&Reflect.deleteProperty(t,e);if(!Array.isArray(t.fieldSchemaJSON))return t;let n;try{n=o(t.fieldSchemaJSON)}catch{n=[]}return{...t,fieldSchemaJSON:n}}(i),r,t):void this.reportInvalid("shape",r,t);case"payload-document-event":return function(e){const t=e;return a(t.action,e=>"updated"===e||"created"===e||"deleted"===e)&&a(t.slug,e=>"string"==typeof e)&&a(t.id,e=>"string"==typeof e||Number.isFinite(e))}(i)?void this.invokeHandler(t,this.handlers.onDocumentEvent,i,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}(i);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=u(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{p(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 v(e){return(...t)=>{try{p(e(...t))}catch{}}}function y(){}var b=v((...e)=>console.error(...e)),w=v((...e)=>console.warn(...e)),S=v((...e)=>console.debug(...e)),k={"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'"},A=/* @__PURE__ */new Set;function T(e){A.has(e)||(A.add(e),w(`[live-preview] LP0104: this page carries the lean runtime, which leaves out ${e} (${k[e]}). The elements are left as the server rendered them. Remove \`runtime: LEAN_RUNTIME\` to get the full runtime.`))}function C(e){return"undefined"!=typeof __LEAN_BUILD__&&__LEAN_BUILD__?function(e){return!1!==e.enableA11y&&T("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 i(e.a11yLocale,n)}(e)}function R(e){if("undefined"==typeof window)return;const t=[];window.parent!==window&&t.push(window.parent),window.opener instanceof Window&&t.push(window.opener),g.sendReady(t,e)}function $(e){const t={};for(const[n,r]of Object.entries(e))void 0!==r&&(t[n]=r);return t}var P=/* @__PURE__ */new Set(["tabs","row","collapsible"]);function N(e,t=""){const n=/* @__PURE__ */new Map;return F(e,t,n),n}function F(e,t,n){for(const r of e){if(P.has(r.type)){r.fields&&F(r.fields,t,n);continue}const e=""===t?r.name:`${t}.${r.name}`;if(n.set(e,r),"group"===r.type)r.fields&&F(r.fields,e,n);else if("array"===r.type&&r.fields)F(r.fields,`${e}.*`,n);else if("blocks"===r.type&&r.blocks)for(const t of r.blocks)F(t.fields,`${e}.*.${t.slug}`,n)}}function L(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 x(e){if("object"!=typeof e||null===e)return;const t=e.id;return"string"==typeof t||"number"==typeof t?t:void 0}function M(e){if("object"!=typeof e||null===e)return;const t=e.blockType;return"string"==typeof t?t:void 0}function U(e,t){return t.every(e=>void 0!==x(e))?function(e,t){const n=[],r=/* @__PURE__ */new Map;for(let t=0;t<e.length;t+=1){const n=x(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=x(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];M(u)===M(s)?(l!==o&&n.push({kind:"move",from:l,to:o,value:s}),E(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)E(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 E(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 I={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"},O=/* @__PURE__ */new Set(["http:","https:","mailto:","tel:"]),_=/^\s*(?:javascript|data|vbscript|file|blob|about)\s*:/i,z=/^(?:\.{1,2}\/|[a-zA-Z0-9_-]+\/?)/,D=/^[\\/]{2}/,B=/[\t\n\r]/g;function isSafeUrl(e){if("string"!=typeof e)return!1;const t=e.trim().replace(B,"");if(0===t.length)return!1;if(_.test(t))return!1;if(t.startsWith("#")||t.startsWith("?"))return!0;if(D.test(t))return!0;if(t.startsWith("/"))return!0;try{const e=new URL(t);return O.has(e.protocol)}catch{return z.test(t)}}function isExternalHttpUrl(e){const t=e.trim().replace(B,"");return/^https?:\/\//i.test(t)||D.test(t)}var j=/* @__PURE__ */new Set(["style","srcdoc","formaction","form","id","name","is","srcset","imagesrcset"]),H=/* @__PURE__ */new Set(["href","src","poster","cite","action","xlink:href","data"]);function W(e){return!e.startsWith("on")&&!j.has(e)}function q(e){return e.onUnfaithfulPatch??("ignore"===e.onUnboundChange?"ignore":"escalate")}function V(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 G(e,t){return!e.unfaithfulFields.has(t)&&(e.unfaithfulFields.add(t),e.unfaithfulCount+=1,!0)}var K=/* @__PURE__ */new Set(["date","number","checkbox"]);function J(e){return"INPUT"===e.tagName||"TEXTAREA"===e.tagName?e.value:e.textContent}function Q(e){const t=e.trim();return JSON.stringify(t.length>40?`${t.slice(0,40)}…`:t)}var X=/* @__PURE__ */new WeakSet;function Z(e){return X.add(e),e}function Y(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 ee=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=Y(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}},te="data-payload-fragment";function ne(e){return e.closest(`[${te}]`)}function re(e){const t=e.getAttribute("data-payload-strategy");return null!==t&&t.length>0?"patch"===t||"fragment"===t||"route"===t?t:void 0:null!==ne(e)?"fragment":null!==e.closest("head")?"route":"patch"}function ie(e,t){return void 0===t||""===t?`collection:${e}`:`collection:${e}:${t}`}function oe(e){return"string"==typeof e&&e.length>0}function se(e,t){return null!==t&&void 0!==e&&t.includes(e)}function ae(e){const t=e.id;return"string"==typeof t&&t.length>0?t:"number"==typeof t&&Number.isFinite(t)?String(t):void 0}var le=/* @__PURE__ */new Set(["id","_id","createdAt","updatedAt","createdBy","updatedBy","_status","globalType","collection","locale","localized"]);function ue(e,t,n){const r=e.get(t);return void 0!==r&&(!1===n||r.some(e=>se(e.owner,n)))}function de(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=>se(e.owner,n)))return!0}return!1}function ce(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 he(e,t,n){let r;return i=>{if(ue(e,i,n))return!0;const o=ce(i,t);return!(o===i||!ue(e,o,n))||!!de(e,i,n)||!(o===i||!de(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||se(e.owner,t))&&void 0!==e.locale&&n.add(`${r}_${e.locale}`);return n}(e,n),r.has(i))}}function fe(e,t,n,r){const i=he(e,n,r),o=[];for(const e of t)le.has(e)||i(e)||o.push(e);return o}var pe=/* @__PURE__ */new Set(["text","textarea","email","number","checkbox","date","select","radio","point","code","json","ui","html"]),me={},ge=class{rawChanges=new ee;resolved=null;queued=null;pending=null;timer=null;openUntil=0;decide(e,t){const n=t.message.data??{},{changed:r}=this.rawChanges.diff(n,me);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(ye(e)||e.fieldName.includes("."))return!0;if(we(e.hrefField)||we(e.srcField)||we(e.altField))return!0}return void 0!==e.strategies.fragment&&null!==e.root.querySelector(`[${te}]`)}(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(le.has(a)){o[a]=r;continue}const l=ve(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 ve(e,t,n,r,i){return be(n)?!be(t)||function(e,t,n){const r=void 0===n?void 0:L(n,e);return void 0!==r&&!pe.has(r.type)||!0===t.get(e)?.some(ye)||de(t,e,!1)}(e,r,i)?"keep":null==t?"ask":"own":"ask"}function ye(e){return!pe.has(e.fieldType)}function be(e){return null===e||"object"!=typeof e&&"function"!=typeof e}function we(e){return!0===e?.includes(".")}var Se=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 ke(e){return null!==e&&e.forceRender&&!e.completed}var Ae=class{lastIdentity=void 0;edit(e){const t=e.externallyUpdatedRelationship;if("object"!=typeof t||null===t)return null;const n=JSON.stringify([t.entitySlug,ae(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=ae(e),i=ae(t.data??{});return void 0!==r&&void 0!==i&&r!==i}(t,e)?t:null}};function Te(e){try{return!0===e.matchMedia?.("(prefers-reduced-motion: reduce)").matches}catch{return!1}}var Ce=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:Te(t)?"auto":"smooth",block:"center"}),"revealed")}(t,n))}reset(){this.#e=void 0}},Re=class{seen=/* @__PURE__ */new Map;note(e,t,n){const r=Y(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}},$e=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;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 Re;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 Ce;changes=new ee;merges=new ge;protocol=new Se;relationships=new Ae;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())}}},Pe=class{constructor(e,t){this.deps=e,this.state=t,this.instanceContext=$({renderRichText:e.renderRichText,sanitizerPolicy:e.sanitizerPolicy,reportUnfaithful:(n,r)=>{V(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||!m(r.revision,e.revision)||!n.isCurrent(r))return!1;const{target:i,value:o}=e,s=void 0!==r.schemaIndex?L(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(I,e))return I[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,d=u?"INPUT"===(c=i.element).tagName||"TEXTAREA"===c.tagName?c.value:"IMG"===c.tagName?c.src:c.textContent:void 0;var c;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(!W(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 H.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),V(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||!K.has(r))return;if(t.checkedServerFormat.has(n.element))return;t.checkedServerFormat.add(n.element);const i=J(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 X.has(e.render)}(a))return V(t,n,i,`is a value ${a.name} cannot render`),!1;void 0!==e&&function(e,t,n){const r=J(t.element);r!==n&&e.warn(`[live-preview] LP0412: "${t.fieldName}" showed ${Q(n)}, the patch wrote ${Q(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:d,nextValue:o,revision:r.revision.revision,receivedAt:r.receivedAt,source:"patch"},()=>n.isCurrent(r));const f=n.isCurrent(r);return f&&(void 0!==e.valueIdentity?n.lastAppliedIdentity.set(i.element,e.valueIdentity):n.lastAppliedIdentity.delete(i.element)),f}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 Ne(...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 Fe(e,t){const n={};for(const r of t)r!==e&&(n[r]=[e]);return n}var Le="payload-live-preview:update",xe="data-payload-island",Me=`astro-island, [${xe}]`;function Ue(e){return"patch"===e.getAttribute(xe)}function Ee(e){return function(e){return"astro-island"===e.tagName.toLowerCase()||e.hasAttribute(xe)}(e)&&!Ue(e)}function isInsideIsland(e){let t=e;for(;null!==t;){if(Ee(t))return!0;t=t.parentElement}return!1}var Ie="data-payload-field",Oe="data-payload-type",_e="data-payload-attribute",ze="data-payload-href",De="data-payload-src",Be="data-payload-alt",je="data-payload-array-template",He="data-payload-array-separator",We="data-payload-locale",qe="data-payload-richtext",Ve="data-payload-html",Ge="data-payload-array",Ke="data-payload-structural",Je="data-payload-owner",Qe="data-payload-depends",Xe="data-payload-strategy",Ze="data-payload-boundary",Ye="data-payload-guessed",et=[Ie,Oe,_e,ze,De,Be,je,He,We,qe,Ve,Ge,Ke,Je,Qe,Xe,Ze,"type"],tt=`[${Ie}]`,nt=`[${Je}]`;function rt(e){const t=e.closest(nt)?.getAttribute(Je);return null==t||0===t.length?void 0:t}var it=/^[a-z][a-z0-9-]*:[a-z][a-z0-9-]*$/i,ot=/* @__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 st(e){return ot.has(e)||it.test(e)}var at=class{entriesByField=/* @__PURE__ */new Map;entryByElement=/* @__PURE__ */new WeakMap;filter;count=0;dependencies=null;islandRoots=[];constructor(e={}){this.filter=e.filter??ut}dependencyMap(){if(null!==this.dependencies)return this.dependencies;const e=[];for(const t of this.values())void 0!==t.dependsOn&&e.push(Fe(t.fieldName,t.dependsOn));return this.dependencies=Ne(...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(tt))void 0!==this.add(t)&&(n+=1);return this.islandRoots=function(e){const t=[];for(const n of e.querySelectorAll(Me))Ue(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(Ie);if(null===t||0===t.length)return;const n=e.getAttribute(Oe),r=e.getAttribute(_e),i=e.getAttribute(ze),o=e.getAttribute(De),s=e.getAttribute(Be),a=e.getAttribute(je),l=e.getAttribute(He),u=e.getAttribute(We),d=e.getAttribute("data-payload-format"),c=rt(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(Qe)),f=e.getAttribute(Xe),p=e.getAttribute(Ye),m=ne(e);return{element:e,fieldName:t,fieldType:lt(e),explicitFieldType:null!==n&&st(n),strategyKind:re(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!==d&&d.length>0?{format:d}:{},...void 0!==c?{owner:c}:{},...h.length>0?{dependsOn:h}:{},...null!==f&&f.length>0?{strategy:f}:{},...e.hasAttribute(Ze)?{hidesWhenEmpty:!0}:{},...null!==p?{guessed:p}:{}}}};function lt(e){const t=e.getAttribute(Oe);if(null!==t&&st(t))return t;if(e.hasAttribute(qe))return"richText";if(e.hasAttribute(Ve))return"html";if(e.hasAttribute(Ke))return"structural-array";if(e.hasAttribute(Ge))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 ut(){return!0}function dt(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 ct(e){return dt(e,128)&&!e.includes("?")&&!e.includes("#")}var ht=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=v(e.log??y)}canMerge(e){return null!==this.endpointOf(e)}endpointOf(e){try{const n=e.globalSlug;if(n)return ct(n)?`globals/${encodeURIComponent(n)}`:null;const r=e.collectionSlug??"",i=e.data.id;return ct(r)&&("number"==typeof(t=i)?Number.isFinite(t):"string"==typeof t&&dt(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}}},ft={name:"payload-2",fieldTyping:"schema",populatesRelationships:"admin",documentEvents:!1},pt={name:"payload-3",fieldTyping:"heuristic",populatesRelationships:"server",documentEvents:!0},mt={name:"unknown",fieldTyping:"heuristic",populatesRelationships:"server",documentEvents:!1};function detectProtocolProfile(e){return e.has("schema-json")?ft:e.has("document-events")||e.has("relationship-events")?pt:mt}var gt=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:[...et]})}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&&et.includes(t.attributeName)&&(t.attributeName===Ie||t.attributeName===Je||1===t.target.nodeType&&t.target.hasAttribute(Ie)))return!0;for(const e of t.addedNodes)if(vt(e))return!0;for(const e of t.removedNodes)if(vt(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 vt(e){if(1!==e.nodeType)return!1;const t=e;return t.hasAttribute(Ie)||null!==t.querySelector(`[${Ie}]`)}var yt="[data-payload-field]";function bt(){if("undefined"==typeof window)return;const e=window;return e.__livePreviewHydration??={armed:!1,committed:!1,commits:[],onCommit:void 0,waiters:[]}}function wt(){const e=bt();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 St(e){e.committed=!0;const t=e.waiters;e.waiters=[];for(const e of t)e()}function kt(e,t){const n=e.waiters.indexOf(t);n>=0&&e.waiters.splice(n,1)}function At(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,kt(e,i),t("timed-out")},n),()=>{null!==r&&clearTimeout(r),r=null,kt(e,i)}}var Tt="__vue_app__";function Ct(){if("undefined"==typeof window)return;const e=window;return e.__livePreviewVueHydration??={armed:!1,committed:!1,waiters:[]}}function Rt(e){return Object.prototype.hasOwnProperty.call(e,Tt)?e[Tt]:void 0}function $t(){const e=Ct();if(void 0===e||e.armed)return;e.armed=!0;const t=Element.prototype;void 0===Object.getOwnPropertyDescriptor(t,Tt)&&Object.defineProperty(t,Tt,{configurable:!0,get:()=>{},set(e){Object.defineProperty(this,Tt,{value:e,writable:!0,configurable:!0,enumerable:!0});const t=Ct();void 0===t||t.committed||null===this.querySelector(yt)||function(e,t){const n=t?.$nuxt;!0!==n?.isHydrating||"function"!=typeof n.hook?St(e):n.hook("app:suspense:resolve",()=>{e.committed||St(e)})}(t,e)}})}function Pt(e){if(void 0===e.hydration)return void e.startNow();const t=t=>{e.later(()=>{Nt(e,t)})},n="react"===e.hydration?function(e,t=5e3){wt();const n=bt();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?.(yt)}(e)&&St(n)};n.onCommit=e;for(const t of n.commits.splice(0))e(t)}return At(n,e,t)}(t):function(e,t,n=5e3){$t();const r=Ct();return void 0===r?null:(!r.committed&&function(e){for(let t=e.querySelector(yt);null!==t;t=t.parentElement)if(void 0!==Rt(t))return!0;return!1}(e)&&St(r),At(r,t,n))}(e.root,t);null!==n?(e.defer(n),e.hydrated("waiting")):Nt(e,"committed")}function Nt(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 Ft=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}},Lt=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)}},xt=/* @__PURE__ */new Set(["true","false","yes","no","on","off"]),Mt=/^[\d\s.,:+/-]+$/u,Ut=/^[a-z][a-z0-9_-]*$/u,Et=/^[a-z]{2,3}(?:[-_][A-Za-z0-9]{2,8})*$/u,It=/* @__PURE__ */new Set(["SCRIPT","STYLE","TEMPLATE","TITLE","NOSCRIPT","TEXTAREA","SELECT","OPTION","INPUT","IFRAME"]);function Ot(e,t=13){if("string"!=typeof e)return!1;const n=e.trim();return!(n.length<t||Mt.test(n)||xt.has(n.toLowerCase())||Ut.test(n)||Et.test(n))}function _t(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function zt(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(le.has(r))continue;const e=ce(r,t);if(Ot(o,n))i(o.trim(),e,!1);else if(_t(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))!le.has(t)&&Ot(r,n)&&i(r.trim(),`${e}.${t}`,!1)}return r}function Dt(e){if("http://www.w3.org/1999/xhtml"!==e.namespaceURI||It.has(e.tagName))return!0;if(e.hasAttribute(Ie)||e.hasAttribute("data-payload-no-bind")||e.hasAttribute("data-payload-owned")||Ee(e))return!0;const t=e.getAttribute("contenteditable");return null!==t&&"false"!==t}function Bt(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 jt(e){return W(e)&&!e.startsWith("data-payload-")&&"value"!==e}function Ht(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 Wt(e,t){for(let n=e.firstElementChild;null!==n;n=n.nextElementSibling){if(Dt(n))continue;const e=Bt(n),r=void 0===e?void 0:t.values.get(e);null==r||r.media||(Ht(t,n,r).text=r.field);for(const e of n.getAttributeNames()){if(!jt(e))continue;const r=t.values.get(n.getAttribute(e)??"");null!=r&&(!r.media||"IMG"===n.tagName&&"src"===e)&&Ht(t,n,r).attributes.set(e,r)}Wt(n,t)}}function qt(e,t,n){const r=e.tagName;if(void 0!==t){const i={[Ie]:t};if("A"===r){const e=n.get("href");void 0===e?i[Oe]="text":e!==t&&(i[ze]=e)}return{element:e,fieldName:t,matched:Bt(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:{[Ie]:t,...void 0!==r&&r!==t?{[Be]: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:{[Ie]:s,[_e]:o}}}function Vt(e,t){const n={values:t,byElement:/* @__PURE__ */new Map,byField:/* @__PURE__ */new Map};t.size>0&&!Dt(e)&&Wt(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=qt(e,n,o);void 0!==s&&i.push(s)}return i}function Gt(e){return 9===e.nodeType?e.body:e}function Kt(e,t,n,r){const i=[];for(const o of t){const{element:t}=o;if(!t.hasAttribute(Ie)&&(!1===n||se(rt(t),n))){for(const[e,n]of Object.entries(o.stamps))t.setAttribute(e,n);if(t.setAttribute(Ye,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(Ye)}}}return i}var Jt=/* @__PURE__ */new Set(["__proto__","prototype","constructor"]);function Qt(e,t,n,r=!1){if(r&&void 0!==n){const r=Xt(e,`${t}_${n}`);if(void 0!==r)return r}const i=Xt(e,t);if(void 0!==i)return i;if(t.includes(".")){let n=e,r=!0;for(const e of t.split(".")){if(Jt.has(e)||null===n||"object"!=typeof n){r=!1;break}if(n=Xt(n,e),void 0===n){r=!1;break}}if(r)return n}return void 0===n?void 0:Xt(e,`${t}_${n}`)}function Xt(e,t){if(!Jt.has(t)&&Object.prototype.hasOwnProperty.call(e,t))return e[t]}function Zt(e,t,n,r){return Qt(e,n,t.locale??r,void 0!==t.locale)}function Yt(e,t,n,r){const i=Y(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=Y(Zt(n,e,t,r));if(void 0===i)return;s+=`|${t}=${i}`}return s}function en(e,t,n,r){const{warned:i,warn:o}=e;i.has(n)||t(n)||(i.add(n),o(`[live-preview] LP0201: no <… data-payload-field="${ce(n,r)}"> for field "${n}"; render the anchor unconditionally so edits to an empty field have somewhere to land.`))}function tn(e){const t=typeof e;return"string"===t||"number"===t||"boolean"===t||"bigint"===t}function nn(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}var rn=/* @__PURE__ */Symbol.for("payload-live-preview.trusted-types");function on(e){const t=function(){const e=function(){const e=globalThis,t=e[rn];if(void 0!==t)return t;const n={};return e[rn]=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 sn=/* @__PURE__ */new Set(["open","value","checked","selected"]);function an(e,t){for(const n of t.keyAttributes){const t=e.getAttribute(n);if(null!==t&&t.length>0)return`${n}=${t}`}}function ln(e){if(e.tagName.toLowerCase().includes("-"))return!0;if(e.hasAttribute(xe)||e.hasAttribute("data-payload-owned"))return!0;const t=e.getAttribute("contenteditable");return null!==t&&"false"!==t}function un(e,t,n){if(!function(e,t){return e.tagName===t.tagName&&e.namespaceURI===t.namespaceURI&&!ln(e)&&!ln(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)||sn.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=an(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,d=0;for(let t=0;t<l.length;t+=1){const i=l[t];let c=null,h=i instanceof Element?an(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)&&(c=dn(e,i,n)===e?e:null,null===c)){e.replaceWith(i),s.add(i),u=i.nextSibling;continue}}else{for(;d<o.length;){const r=o[d];if(d+=1,!s.has(r)){if(hn(r,i)){c=dn(r,i,n)===r?r:null,null===c&&(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&&hn(r,n)){d-=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===c&&s.has(i))continue}const f=c??i;for(s.add(f);null!==u&&u!==f&&!s.has(u)&&cn(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 dn(e,t,n){return e instanceof Element&&t instanceof Element?ln(e)&&ln(t)?e:un(e,t,n):(e.nodeValue!==t.nodeValue&&(e.nodeValue=t.nodeValue),e)}function cn(e){return e.nodeType===Node.TEXT_NODE&&0===(e.nodeValue??"").trim().length}function hn(e,t){return e.nodeType===t.nodeType&&(!(e instanceof Element&&t instanceof Element)||e.tagName===t.tagName&&e.namespaceURI===t.namespaceURI)}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 setSanitizerDocument(e){globalThis[Cn]=e??void 0}function sanitizeHtml(e,t){return Rn(e,void 0,t)}function Rn(e,t,n){const r=$n();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=on(e),Pn(o.content,i),o.innerHTML}function $n(){if("undefined"==typeof __INLINE_BUILD__||!__INLINE_BUILD__){const e=globalThis[Cn];if(e)return e}if("undefined"!=typeof document)return document}function Pn(e,t){for(const n of Array.from(e.childNodes))1===n.nodeType?Nn(n,t):8===n.nodeType&&n.remove()}function Nn(e,t){const n=e.tagName.toLowerCase();if(!vn.has(n)||t.allowFormControls&&gn.has(n)){if(!t.allowedTags.has(n))return Pn(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||Fn(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),Pn(e,t)}else e.remove()}function Fn(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 Ln=Object.freeze({"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="}),xn=/[&<>"'/`=]/g;function escapeHtml(e){return e.replace(xn,e=>Ln[e])}var Mn=Object.freeze({"&":"&","<":"<",">":">",'"':""","'":"'"}),Un=/[&<>"']/g;function escapeHtmlAttribute(e){return e.replace(Un,e=>Mn[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(!W(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 zn(e,t){for(const[n,r]of t)e.hasAttribute(n)||e.setAttribute(n,r)}function Dn(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 jn(e,t){const n=e.get(t);return void 0!==n&&(e.delete(t),e.set(t,n)),n}function Hn(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=jn(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 Hn(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),d=In(i),c=Array.from(e.children),h=lr(c,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?c[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?dr(e.ownerDocument,r,m,s,a,u,d):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;for(const[e,o,l,u,d]of i){let i=o;if(void 0!==l){const e=!(!n.morph||d||null===o)&&un(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 c=r.children[e]??null;i!==c&&(r.insertBefore(i,c),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)sr(l,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,d=u?.getAttribute(Xn)??null;let c;if(l){const o=or(n,t);if(void 0!==o||null!==u){const n=o??[],s=U(null===u?[]:or(r,t)??[],n),a=null!==u&&d!==l;if((s.length>0||a)&&(c=er(u??e,s,{template:l,nextItems:n,forceRender:a,store:i.store,sanitizerPolicy:i.sanitizerPolicy})??void 0,void 0===c))return null}}s.push([u,e,c])}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 dr(e,t,n,r,i,o,s){const a=Rn(On(t,n,r,Dn,s),i,Kn(t)),l=e.createElement("template");l.innerHTML=on(a);const u=l.content.firstElementChild;if(!u)return null;zn(u,o);const d=ar(n);return void 0!==d&&u.setAttribute(Jn,d),u}function cr(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))}hasUnboundChange(e,t){const{deps:n,state:r}=this;if(e.baseline||e.routeRefreshed)return!1;const i=fe(n.cache,e.touched,e.locale,t);let o=0;for(const e of i)G(r,e)&&(o+=1);const[s]=i;return void 0!==s&&"escalate"===n.onUnfaithfulPatch&&void 0!==n.strategies.route&&(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,d=e.receivedAt,c={root:r.root,revision:u,receivedAt:d,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=on(t);const r=e.cloneNode(!1);r.append(n.content),un(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:d},s)},failed:(t,n,i,o,l)=>{e.pendingFragments-=1;const c=`fragment "${n}" fell back to patch: ${l}`;r.log("fragment",o,c),a.emitWhile("error",{error:new Error(c),context:"fragment",code:o},s),a.emitWhile("fragmentRender",{element:t,id:n,key:i,status:"failed",code:o,revision:u,receivedAt:d},s)}};let h={rendered:0,failed:0,superseded:0};try{h=await n.strategy.render(c,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()-d,revision:u,receivedAt:d,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){cr(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=Zt(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=p(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=fe(e.cache,n.touched,n.locale,r);for(const e of i)G(t,e);return!1},hasRouteBinding:()=>!1,runFragments:()=>Promise.resolve(),refreshRoute:()=>(T("route refreshes"),Promise.resolve()),warnFragmentFallback:n=>{T("server-rendered fragments"),cr(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=N(e.fieldSchemaJSON));const s={revision:n,message:e,locale:i.locale,schema:i.schema,schemaIndex:i.schemaIndex,receivedAt:Date.now(),forceRender:null!==o||ke(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=Ne(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__)T("auto-binding");else{const n=this.ownerKeysForUpdate(e,t.fields);!function(e,t,n,r,i){const o=performance.now(),s=Gt(e.root),a=zt(n,r),l=null===s?[]:Kt(e,Vt(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[ze,Be]){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 d=this.strategies.planFragments(s),c=n.skipUnchanged;let h=0;for(const[s,a]of n.cache.entries()){if(!i())return;for(const l of a){if(!1!==o&&!se(l.owner,o))continue;if(!0===d?.covers(l)){if(n.revealEditedField){const n=Zt(t.fields,l,s,e.locale);r.revealLedger.note(e,l,n)}continue}const a=l.strategyKind??re(l.element)??"unknown";if("unknown"===a){this.strategies.warnUnsupportedStrategy(l);continue}"fragment"===a&&null===d&&this.strategies.warnFragmentFallback(l);const u=Zt(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=c?Yt(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(se(n.owner,t))return!0;return!1}(i,r))return;const o=he(i,n,r);for(const[r,i]of Object.entries(t)){if(le.has(r))continue;if(tn(i)){en(e,o,r,n);continue}if(!nn(i)||o(r))continue;const t=ce(r,n);for(const[r,s]of Object.entries(i))tn(s)&&!le.has(r)&&en(e,o,`${t}.${r}`,n)}})({cache:n.cache,warned:r.warnedOrphanFields,warn:n.warn},t.fields,e.locale,o),null!==d&&d.boundaries.length>0&&(e.pendingFragments=d.boundaries.length,this.strategies.runFragments(e,t,d)),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(Le,{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=Gt(e.root);if(null===o||0===o.fields.size||null===s)return 0;const a=new Map(o.values);for(const[e,t]of zt(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)}Kt(e,Vt(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(oe(e.globalSlug))return[(t=e.globalSlug,`global:${t}`)];var t;if(!oe(e.collectionSlug))return null;const n=ie(e.collectionSlug);return oe(e.documentId)?[n,ie(e.collectionSlug,e.documentId)]:[n]}({globalSlug:"string"==typeof i.globalSlug?i.globalSlug:void 0,collectionSlug:"string"==typeof i.collectionSlug?i.collectionSlug:void 0,documentId:ae(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)||!m(o.revision,r))return;0===o.pendingFragments&&n.complete(o);const s=()=>n.isCurrent(o)&&m(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||!m(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&&m(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&&m(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&&m(e.revision,this.activeRevision)}didApply(e){return!1!==this.apply(e)||(t=this.apply,!X.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 $e;pipeline;writer;rootSentinel=null;observedRoot=null;constructor(e){const{emitter:t,renderers:n}=e,r=void 0===e.log?y:v(e.log),i=void 0===e.warn?w:v(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 at({filter:e=>!isInsideIsland(e)}),a=new gt({onStructuralChange:()=>{this.rebuildCache()},onVisibilityChange:(e,t)=>{t&&l.notifyVisible(e)}},void 0!==e.intersectionRootMargin?{intersectionRootMargin:e.intersectionRootMargin}:{}),l=new yr(Z(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 g(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}:{}}),d=e.dataMerge;this.deps={emitter:t,cache:s,observers:a,scheduler:l,bus:u,connection:new Lt,heartbeat:new Ft({...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??R,onHeartbeatTimeout:e.onHeartbeatTimeout,log:r,warn:i,a11y:C(e),merger:void 0===d?null:new ht({serverURL:d.serverURL,...void 0!==d.apiRoute?{apiRoute:d.apiRoute}:{},...void 0!==d.depth?{depth:d.depth}:{},...void 0!==d.fetchFn?{fetchFn:d.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:q(e),autoBind:e.autoBind??"off",hydration:e.hydration},this.writer=new Pe(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?wt():"vue"===e.hydration&&$t();const{root:t}=e;if(!function(e){return 9===e.nodeType}(t)||"loading"!==t.readyState)return void Pt(e);const n=()=>{e.isRunning()&&e.later(()=>{Pt(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(t,n){const{cache:r,scheduler:i}=t,o=n.protocol.negotiation,s=n.activeUpdate,a=n.lastFlush,l=[],u=/* @__PURE__ */new Set,d=[];for(const[e,t]of r.entries()){l.push(e);for(const n of t)void 0!==n.owner&&u.add(n.owner),void 0!==n.guessed&&d.push({field:e,matched:n.guessed,attribute:n.targetAttribute??("IMG"===n.element.tagName?"src":void 0)})}return{version:e,started:n.started,status:t.connection.status,origins:{trusted:[...t.readyTargets()],locked:t.lockedOrigin()},protocol:{ours:o.ours,theirs:o.theirs,negotiated:o.negotiated,capabilities:[...o.capabilities].sort(),observed:[...o.observed].sort(),profile:detectProtocolProfile(o.observed).name},revisions:{accepted:n.updateCount,superseded:n.supersededCount,completed:n.completedCount,skippedUnchanged:n.skippedUnchangedCount,active:null===s?void 0:s.revision.revision},bindings:{elements:r.elementCount,fields:r.fieldCount,fieldNames:l.sort(),absentFields:[...n.absentFields].sort(),orphanFields:[...n.warnedOrphanFields].sort(),ownerScoped:t.scopeBindingsByOwner,owners:[...u].sort(),guessed:d.sort((e,t)=>e.field.localeCompare(t.field)),autoBind:{mode:t.autoBind,searchMs:n.autoBindSearchMs}},route:{handler:void 0!==t.strategies.route,...n.routeStats},fidelity:{mode:t.onUnfaithfulPatch,unfaithful:n.unfaithfulCount,escalated:n.escalatedCount,fields:[...n.unfaithfulFields].sort()},hydration:{mode:t.hydration??"off",state:n.hydration},fragments:{handler:void 0!==t.strategies.fragment,inFlight:s?.pendingFragments??0,...n.fragmentStats},scheduler:{pending:i.pendingCount,deferred:i.replayCount,visibilityGateThreshold:i.gateThreshold,visibilityGateActive:i.gateActive,lastFlush:null===a?void 0:{applied:a.applied,appliedFields:a.appliedFields,deferred:a.deferred,durationMs:a.durationMs}},plugins:[],renderers:Object.keys(t.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>";b(`[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 isInPopup(){return"undefined"!=typeof window&&null!=window.opener}function isInPreviewContext(){return isInIframe()||isInPopup()}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=Rr(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 Rr(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 $r=()=>{},Pr=class{#l;#u;#d=/* @__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.#c({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.#c(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.#d)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.#d)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.#d].reverse())this.#f(e);this.#d.clear()}}#c(e){return this.#d.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??$r}#f(e){if(e.disposed)return;e.disposed=!0,this.#d.delete(e);const t=e.cleanup;if(e.cleanup=void 0,void 0!==t)try{p(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)}}},Nr=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=$r,s=!0;const a=async t=>{this.#m.active&&s&&("once"===e&&o(),await n(t))},l={kind:e,event:t,handler:r,dispose:$r};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}},Fr=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;#R=Promise.resolve();#$=0;constructor(e){this.#p=e.events,this.#y=e.config,this.#b=e.registerFieldRenderer,this.#u=v(e.log);const t=e.onTransformError;this.#w=void 0===t?void 0:v((...e)=>{const n=e[0];try{return t(n)}catch(e){return void this.#u("transform error reporter failed:",e)}})}register(e){return this.#$>0?this.#P(e,!1):this.#N(()=>this.#P(e,!0))}unregister(e){return this.#$>0?this.#F(e,!1):this.#N(async()=>{await this.#F(e,!0)})}destroyAll(){return this.#$>0?this.#L(!1):this.#N(async()=>{await this.#L(!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=p(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#P(t,n){if(this.#S.has(t.name)||this.#k.has(t.name)||this.#A.has(t.name))return void this.#u(`plugin "${t.name}" already registered`);const r=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)}`}}}(t.compat,e);if(void 0!==r)return void this.#x(t.name,r);const i=new Pr(t.name,this.#u),o=this.#M(t.name,i),s={scope:i,cancelled:!1};this.#k.set(t.name,s);try{if(await this.#U(()=>t.init(o),n),s.cancelled)return;i.commit()}catch(e){return i.close(),void(s.cancelled||this.#u(`plugin "${t.name}" init failed:`,e))}finally{this.#k.get(t.name)===s&&this.#k.delete(t.name)}this.#S.set(t.name,{plugin:t,scope:i}),this.#u(`plugin "${t.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"})}#M(e,t){return{events:new Nr(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)}}}#F(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.#U(()=>t.destroy?.(),n)}catch(t){this.#u(`plugin "${e}" destroy failed:`,t)}finally{this.#T.delete(e)}}}async#L(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.#F(n,e)}async#U(e,t){t?await this.#E(Promise.resolve().then(e)):await e()}async#E(e){this.#$+=1;try{await e}finally{this.#$-=1}}#N(e){const t=this.#R.then(e);return this.#R=t.catch(e=>{this.#u("plugin manager mutation failed:",e)}),t}},Lr=class{#O;#_;#z=/* @__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.#z.get(t);void 0===r?this.#z.set(t,[n]):r.push(n),this.#_[t]=e;let i=!0;return()=>{if(!i)return;i=!1;const e=this.#z.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.#z.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"},Mr=/* @__PURE__ */new Set(["left","center","right","justify","start","end"]);function Ur(e){const t=e.format;return"string"==typeof t&&Mr.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=Ur(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 zr(e){return"object"==typeof e&&null!==e?e:void 0}function Dr(e){return zr(e)}function Br(e){return e.replace(/[^a-zA-Z0-9_-]/g,"-").toLowerCase()}function jr(e){return"string"==typeof e&&e.length>0?e:void 0}function Hr(e){const t=jr(e.title)??jr(e.name)??jr(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=zr(e.fields),i=function(e,t){if("internal"===t?.linkType)return function(e){const t=zr(zr(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=zr(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=Dr(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=zr(e.value),r=escapeHtml((n&&Hr(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__ */Z((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),w(`[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=on(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"]),di={name:"richText",render:/* @__PURE__ */Z((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=on(Rn(o,i)))}if(ri(t)){const o=/* @__PURE__ */new Map,s=function(e,t){const n=e.cloneNode(!1);n.innerHTML=on(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(Ie))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=[];ci(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,Rn(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:Ur,resolveIndent:Er,onUnrenderedBlock:e};return t}(t.onUnrenderedBlock).renderChildren(e.root.children);return!1===t.sanitize?n:void 0!==$n()?sanitizeHtml(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=on(Rn(t,i))})};function ci(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]):ci(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),w(`[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:Dn(t);e.element.innerHTML=on(Rn(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),w(`[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=Dn(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):Qt(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__ */Z((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?Qt(n.allFields,e.srcField,n.locale,r):t,o=Dr(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=Qt(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 Ri={name:"upload",render:/* @__PURE__ */Z((e,t)=>{const n=e.element;if(Bn(t))return void $i(n);const r=Dr(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 $i(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=on(`<a href="${escapeHtmlAttribute(o)}">${s}</a>`)})};function $i(e){"IMG"!==e.tagName?(e.removeAttribute("href"),e.textContent=""):Si(e)}var Pi={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,zr(t)?.url);"safe"===r.kind?n.setAttribute("href",r.url):"unsafe"===r.kind&&n.removeAttribute("href")}n.textContent=Array.isArray(t)?t.map(Ni).join(", "):Ni(t)}};function Ni(e){const t=zr(e);return void 0===t?Dn(e):Hr(t)??""}var Fi={name:"select",render(e,t,n){const r=e.element,i=Bn(t)?[]:function(e){return Array.isArray(e)?e.map(Dn):[Dn(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=zr(t);if(void 0!==n&&Dn(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)}},Li=/* @__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?!Li.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}},Mi=/* @__PURE__ */new Map,Ui=/* @__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"]),zi=/^[A-Za-z]{3}$/u,Di=/^[0-4]$/u;function Bi(e){return{kind:"date",options:e}}function ji(e){return{kind:"number",options:e}}var Hi=/* @__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 ji({});if(!Di.test(r))return;return ji({minimumFractionDigits:Number(r),maximumFractionDigits:Number(r)});case"currency":if(void 0===r||!zi.test(r))return;return ji({style:"currency",currency:r.toUpperCase()});case"percent":return void 0===r?ji({style:"percent"}):void 0;default:return}}(t);if(void 0!==i){if(i.kind===e)return i.options}else!function(e,t,n){Hi.has(e)||(Hi.add(e),w(`[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:Dn(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 jn(Ui,n)??Hn(Ui,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(Dn(t));Number.isNaN(i)?r.textContent=Dn(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 jn(Mi,n)??Hn(Mi,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__ */Z((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,Dn,n);return r}(i,t),o=n.sanitizerPolicy,s=Kn(i),a=_n(r);r.innerHTML=on(Rn(e,o,s));for(const e of Array.from(r.children))zn(e,a);return}r.textContent=t.map(Dn).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__ */Z((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),w(`[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 d=e.get(l),c=Xi(l),h=U(d?.values??c.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)}(d,u,c);if(0===h.length&&!f)return e.set(l,{values:a.slice(),template:u,domSnapshot:c}),!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,d?.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),w(`[live-preview] ${r}`))}var to=/* @__PURE__ */new Map;function no(e,t){return{name:e,render(){T(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 so,LivePreviewClient=class{#D=new EventEmitter;#B;#j;#H;#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)=>{S("[live-preview]",...e)}:y,this.#B=new OriginDetector($({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.#j=new Lr(function(){const e=[di,fi,vi,bi,Ti,Ri,Pi,Fi,{...Fi,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 Fr({events:this.#D,config:Object.freeze({...t}),registerFieldRenderer:e=>this.#j.register(e),onTransformError:e=>{this.#D.emit("error",{error:e,context:"transform",code:"LP0602"})},log:this.#u}),this.#H=new wr($({root:t.root,renderers:this.#j.renderers,resolveRenderer:(e,n)=>t.resolveRenderer?.(e,n)??this.#j.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.#D,dataMerge:""===n?void 0:$({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.#D.on("connect",e=>{this.#B.lockOrigin(e.origin)}),!1!==t.autoStart&&this.start()}start(){if(this.#q)return!1;if(this.#W)return this.#H.start(),!0;if(!isInPreviewContext())return!1;const e=this.#H.start();return e&&(this.#W=!0),e}suspend(){return!(this.#q||!this.#W)&&this.#H.suspend()}resume(){return!(this.#q||!this.#W)&&this.#H.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.#D.removeAllListeners(),this.#V=!0};try{this.#H.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.#H.refreshCache()}get events(){return this.#D}get plugins(){return this.#S.list()}get status(){return this.#H.status}inspect(){return{...this.#H.inspect(),plugins:this.#S.snapshot()}}get updateCount(){return this.#H.updateCount}get destroyed(){return this.#q}};function initLivePreview(e={}){const t=new LivePreviewClient({...e,autoStart:!1});return t.start()?t:null}function setCspCrypto(e){so=e??void 0}function generateCspNonce(e=16){if(!Number.isInteger(e)||e<8)throw new RangeError(`generateCspNonce: bytes must be an integer >= 8, got ${String(e)}`);const t=function(){if(so?.getRandomValues)return so;const e=globalThis.crypto;return e?.getRandomValues?e:void 0}();if(!t)throw new Error("generateCspNonce: Web Crypto is unavailable. On Node 18 call setCspCrypto(webcrypto) once at startup, or run with --experimental-global-webcrypto. We won't fabricate a predictable nonce — that would silently defeat the entire CSP.");const n=new Uint8Array(e);return t.getRandomValues(n),function(e){let t="";for(const n of e)t+=String.fromCharCode(n);return("function"==typeof btoa?btoa(t):Buffer.from(e).toString("base64")).replaceAll("+","-").replaceAll("/","_").replaceAll("=","")}(n)}function buildFrameAncestors(e={}){const{self:t=!0,origins:n=[],allowNone:r=!1}=e,i=/* @__PURE__ */new Set,o=[];if(r&&!t&&0===n.length)return"'none'";t&&(o.push("'self'"),i.add("'self'"));for(const e of n){const t=e.trim();0===t.length||i.has(t)||(i.add(t),o.push(t))}return o.length>0?o.join(" "):"'none'"}function buildScriptSrcWithNonce(e,t={}){if(0===e.length)throw new RangeError("buildScriptSrcWithNonce: nonce is empty");const{self:n=!0,extra:r=[],strictDynamic:i=!1}=t,o=[];n&&o.push("'self'"),o.push(`'nonce-${e}'`),i&&o.push("'strict-dynamic'");for(const e of r){const t=e.trim();t.length>0&&o.push(t)}return o.join(" ")}var ao="payload-live-preview.authorized-preview-context",lo=Symbol.for(ao);function isAuthorizedPreviewContext(e){return"object"==typeof e&&null!==e&&!0===e[lo]&&Object.isFrozen(e)}var uo={basic:{gates:"data updates are applied to bound elements",fallback:"none — every peer has it"},"schema-json":{gates:"field typing from fieldSchemaJSON (Payload 2.x) and the payload-2 profile",fallback:"field types come from DOM heuristics and Lexical auto-detection"},locale:{gates:"locale-aware field resolution (`title_de` before `title`) and the locale on island events",fallback:"bindings resolve the unsuffixed field value"},"preview-token":{gates:"per-message token validation (library extension)",fallback:"messages carry no token; validateToken cannot be satisfied"},"nested-arrays":{gates:"keyed array diffs below the top level",fallback:"array updates replace the whole array"},"recursive-diffs":{gates:"recursive object diffs",fallback:"nested objects re-render as a unit"},"document-events":{gates:"the `documentSave` runtime event, the document-save plugin and the payload-3 profile",fallback:"no documentSave event; a save is not distinguishable from an edit"},"relationship-events":{gates:"the `relationshipUpdate` runtime event and an unconditional re-render of the update that carries it",fallback:"a related document edited in a drawer shows up on the next data update only"}},co="__livePreviewRouteRefresh";function registerRouteRefresh(e){const t="undefined"==typeof window?void 0:window;return void 0===t?()=>{}:(t[co]=e,()=>{t[co]===e&&(t[co]=void 0)})}var ho=Object.freeze({NoTrustedOrigin:"LP0101",ReferrerOnlyTrust:"LP0102",PluginIncompatible:"LP0103",ProfileFeatureOmitted:"LP0104",OrphanField:"LP0201",UnattributableUpdate:"LP0202",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",V2ReadinessGap:"LP0709",RuntimeOnPublicPage:"LP0710"});function bind(e,t){return fo(e,t)}function bindByPath(e,t){const n=function(e){const t=[],n=new Proxy({},{get(e,r){if("symbol"!=typeof r)return/^\d+$/.test(r)||t.push(r),n}});try{e(n)}catch{}return t}(e);if(0===n.length)throw new Error("bindByPath: the picker did not read any field — return data.<field> instead of a constant");return fo(n.join("."),t)}function fo(e,t){if(0===e.length)throw new Error("bind: field name must be a non-empty string");const n={"data-payload-field":e};return void 0!==t?.attribute&&(n["data-payload-attribute"]=t.attribute),void 0!==t?.type&&(n["data-payload-type"]=t.type),!0===t?.richtext&&(n["data-payload-richtext"]=""),!0===t?.html&&(n["data-payload-html"]=""),void 0!==t?.locale&&(n["data-payload-locale"]=t.locale),void 0!==t?.alt&&(n["data-payload-alt"]=t.alt),void 0!==t?.href&&(n["data-payload-href"]=t.href),void 0!==t?.arrayTemplate&&(n["data-payload-array-template"]=t.arrayTemplate),n}var po=/^[a-z][a-z0-9-]{0,63}$/u,mo=Object.freeze({});function createPreviewBindings(e){const t=isAuthorizedPreviewContext(e.authorization),n=void 0!==e.owner&&e.owner.length>0?e.owner:void 0;return Object.freeze({authorized:t,bind:(e,n)=>t?bind(e,n):mo,bindByPath:(e,n)=>t?bindByPath(e,n):mo,owner:()=>t&&void 0!==n?{"data-payload-owner":n}:mo,boundary:(e,n={})=>{const r=function(e,t){if(!po.test(e))throw new RangeError(`createPreviewBindings().boundary(): "${e}" is not a registry id — lowercase, starting with a letter, then letters, digits or hyphens (max 64). The runtime would post it and the endpoint would refuse it.`);const n=t.key;if(void 0!==n&&(0===n.length||n.length>128))throw new RangeError(`createPreviewBindings().boundary(): the key for "${e}" must be 1 to ${String(128)} characters.`);const r=t.dependsOn??[];return{"data-payload-fragment":e,...void 0!==n?{"data-payload-fragment-key":n}:{},...r.length>0?{"data-payload-depends":r.join(",")}:{}}}(e,n);return t?r:mo}})}var go=!0;export{ao as AUTHORIZED_PREVIEW_BRAND_KEY,h as CAPABILITY_DECLARATIONS,uo as CAPABILITY_DOCUMENTATION,go as CORE_ENTRY,ho as DIAGNOSTIC_CODES,EventEmitter,Le as ISLAND_EVENT,c as LIBRARY_PROTOCOL_VERSION,LivePreviewClient,OriginDetector,f as PROTOCOL_CAPABILITIES,e as VERSION,bind,bindByPath,buildFrameAncestors,buildScriptSrcWithNonce,createPreviewBindings,detectInitialLocale,detectProtocolProfile,escapeHtml,escapeHtmlAttribute,generateCspNonce,hasCapability,initLivePreview,isAuthorizedPreviewContext,isDevMode,isExternalHttpUrl,isInIframe,isInPopup,isInPreviewContext,isInsideIsland,isSafeUrl,negotiateProtocol,registerRouteRefresh,sanitizeHtml,setCspCrypto,setSanitizerDocument};
|
|
2
2
|
//# sourceMappingURL=core.js.map
|