payload-live-preview 1.2.2 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/core.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var t="data-payload-field",e="data-payload-type",n="data-payload-attribute",i="data-payload-href",r="data-payload-src",s="data-payload-alt",o="data-payload-array-template",a="data-payload-array-separator",l="data-payload-locale",u="data-payload-richtext",c="data-payload-html",d="data-payload-array",h="data-payload-structural",f="data-payload-owner",p=[t,e,n,i,r,s,o,a,l,u,c,d,h,f,"type"],g=`[${t}]`,m=`[${f}]`,v=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"]),y=class{#t=new Map;#e=new WeakMap;#n;constructor(t={}){this.#n=t.filter??b}buildFromRoot(t){const e=performance.now();this.clear();const n=t.querySelectorAll(g);let i=0;for(const t of n)void 0!==this.add(t)&&(i+=1);return{elementCount:i,fieldCount:this.#t.size,durationMs:performance.now()-e}}add(t){const e=this.#n(t)?this.#i(t):void 0,n=this.#e.get(t);if(void 0!==e)return void 0!==n&&this.#r(n,e)?(this.#e.set(t,e),e):(void 0!==n&&this.#s(t,n),this.#o(e),this.#e.set(t,e),e);void 0!==n&&this.#s(t,n)}remove(t){const e=this.#e.get(t);return!!e&&this.#s(t,e)}#r(t,e){if(t.fieldName!==e.fieldName)return!1;const n=this.#t.get(t.fieldName);if(!n)return!1;const i=n.indexOf(t);return!(i<0||(n[i]=e,0))}#s(t,e){const n=this.#t.get(e.fieldName);if(!n)return this.#e.delete(t),!1;const i=n.indexOf(e);return i<0?(this.#e.delete(t),!1):(n.splice(i,1),0===n.length&&this.#t.delete(e.fieldName),this.#e.delete(t),!0)}get(t){return this.#t.get(t)}getByElement(t){return this.#e.get(t)}get fieldCount(){return this.#t.size}get elementCount(){let t=0;for(const e of this.#t.values())t+=e.length;return t}entries(){return this.#t.entries()}*values(){for(const t of this.#t.values())yield*t}has(t){return this.#e.has(t)}clear(){this.#t.clear(),this.#e=new WeakMap}#o(t){const e=this.#t.get(t.fieldName);e?e.push(t):this.#t.set(t.fieldName,[t])}#i(p){const g=p.getAttribute(t);if(null===g||0===g.length)return;const y=p.getAttribute(e),b=function(t){const n=t.getAttribute(e);if(null!==n&&v.has(n))return n;if(t.hasAttribute(u))return"richText";if(t.hasAttribute(c))return"html";if(t.hasAttribute(h))return"structural-array";if(t.hasAttribute(d))return"array";if("IMG"===t.tagName)return"image";if("A"===t.tagName)return"url";if("TIME"===t.tagName)return"date";if("INPUT"===t.tagName){const e=t.type;if("checkbox"===e)return"checkbox";if("number"===e)return"number";if("date"===e||"datetime-local"===e)return"date"}return"text"}(p),w=p.getAttribute(n),S=p.getAttribute(i),A=p.getAttribute(r),k=p.getAttribute(s),C=p.getAttribute(o),T=p.getAttribute(a),$=p.getAttribute(l),x=function(t){const e=t.closest(m)?.getAttribute(f);return null==e||0===e.length?void 0:e}(p);return{element:p,fieldName:g,fieldType:b,explicitFieldType:null!==y&&v.has(y),...null!==w&&w.length>0?{targetAttribute:w}:{},...null!==S&&S.length>0?{hrefField:S}:{},...null!==A&&A.length>0?{srcField:A}:{},...null!==k&&k.length>0?{altField:k}:{},...null!==C?{arrayTemplate:C}:{},...null!==T?{arraySeparator:T}:{},...null!==$&&$.length>0?{locale:$}:{},...void 0!==x?{owner:x}:{}}}};function b(){return!0}function w(t,e){return void 0===e||""===e?`collection:${t}`:`collection:${t}:${e}`}function S(t){return"string"==typeof t&&t.length>0}function A(t,e){return null!==e&&void 0!==t&&e.includes(t)}function k(t){const e=t.id;return"string"==typeof e&&e.length>0?e:"number"==typeof e&&Number.isFinite(e)?String(e):void 0}var C=class{s;constructor(t,e={}){this.s=[t,e.mutationDebounceMs??100,e.intersectionRootMargin??"200px",new Set,null,null,null,0]}start(t){const e=this.s[7];this.stop();const n=e+1;if(this.s[7]!==n)return;let i=null,r=null;try{i=new MutationObserver(t=>{this.#a(t,n)}),r=new IntersectionObserver(t=>{this.#l(t,n)},{rootMargin:this.s[2],threshold:0}),i.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[...p]})}catch(t){throw i?.disconnect(),r?.disconnect(),t}if(this.s[7]!==n)return i.disconnect(),void r.disconnect();this.s[4]=i,this.s[5]=r}observeElement(t){this.s[5]?.observe(t)}unobserveElement(t){this.s[5]?.unobserve(t),this.s[3].delete(t)}markVisible(t,e){e?this.s[3].add(t):this.s[3].delete(t)}isVisible(t){return this.s[3].has(t)}stop(){this.s[7]+=1;const t=this.s[6],e=this.s[4],n=this.s[5];this.s[6]=null,this.s[4]=null,this.s[5]=null,this.s[3].clear(),null!==t&&clearTimeout(t);try{e?.disconnect()}finally{n?.disconnect()}}#a(e,n){if(!this.#u(n))return;if(!function(e){for(const n of e){if("attributes"===n.type&&null!==n.attributeName&&p.includes(n.attributeName)&&(n.attributeName===t||n.attributeName===f||1===n.target.nodeType&&n.target.hasAttribute(t)))return!0;for(const t of n.addedNodes)if(T(t))return!0;for(const t of n.removedNodes)if(T(t))return!0}return!1}(e))return;if(!this.#u(n))return;null!==this.s[6]&&clearTimeout(this.s[6]);const i=setTimeout(()=>{this.#u(n)&&this.s[6]===i&&(this.s[6]=null,this.s[0].onStructuralChange())},this.s[1]);this.s[6]=i}#l(t,e){for(const n of t){if(!this.#u(e))return;const t=n.target;if(n.isIntersecting){if(!this.s[3].has(t)&&(this.s[3].add(t),this.s[0].onVisibilityChange(t,!0),!this.#u(e)))return}else if(this.s[3].has(t)&&(this.s[3].delete(t),this.s[0].onVisibilityChange(t,!1),!this.#u(e)))return}}#u(t){return this.s[7]===t&&null!==this.s[5]}};function T(e){if(1!==e.nodeType)return!1;const n=e;return!!n.hasAttribute(t)||null!==n.querySelector(`[${t}]`)}function $(t){if(!Array.isArray(t))return[];const e=[];for(const n of t){const t=x(n);t&&e.push(t)}return e}function x(t){if("object"!=typeof t||null===t)return;const e=t,n=e.name,i=e.type;if("string"!=typeof n||0===n.length)return;if("string"!=typeof i||0===i.length)return;const r=$(e.fields),s=function(t){if(!Array.isArray(t))return[];const e=[];for(const n of t){if("object"!=typeof n||null===n)continue;const t=n,i=t.slug;if("string"!=typeof i||0===i.length)continue;const r=$(t.fields);e.push({...t,slug:i,fields:r})}return e}(e.blocks),o={...e,name:n,type:i};return r.length>0?o.fields=r:delete o.fields,s.length>0?o.blocks=s:delete o.blocks,o}var N={basic:1,"schema-json":2,"preview-token":3,"nested-arrays":4,"recursive-diffs":4};function negotiateProtocol(t){const e="number"==typeof t&&Number.isFinite(t)&&t>=1?Math.floor(t):void 0,n=e??1,i=Math.min(4,n),r=new Set;for(const[t,e]of Object.entries(N))i>=e&&r.add(t);return{ours:4,...void 0!==e?{theirs:e}:{theirs:void 0},negotiated:i,capabilities:r}}function R(t){return("object"==typeof t&&null!==t||"function"==typeof t)&&"function"==typeof t.then&&(Promise.resolve(t).catch(()=>{}),!0)}var M=class{s;constructor(t,e){this.s=[t,e,void 0,void 0,0,0,[],0]}attach(t=window){if(void 0!==this.s[3])return;let e=!1;const n=t=>{if(!e||this.s[2]!==n)return;const i=this.s[4];try{this.#c(t,i)}catch{let e="";try{e=t.origin}catch{}this.#d("shape",e,i)}};this.s[4]+=1,this.#h(),this.s[3]=t,this.s[2]=n;try{t.addEventListener("message",n)}catch(e){this.s[2]===n&&(this.s[3]=void 0,this.s[2]=void 0,this.#h());try{t.removeEventListener("message",n)}catch{}throw e}if(this.s[2]===n)e=!0;else try{t.removeEventListener("message",n)}catch{}}detach(t){const e=this.s[3],n=this.s[2];void 0!==e&&void 0!==n&&(this.s[3]=void 0,this.s[2]=void 0,this.#h(),e.removeEventListener("message",n))}advanceGeneration(){return void 0!==this.s[3]&&(this.s[4]+=1,this.#h(),!0)}static sendReady(t,e){const n=t.length>0;if(!n||0===e.length)return;const i={type:"payload-live-preview",ready:n,protocolVersion:4};for(const n of t)for(const t of e)try{n.postMessage(i,t)}catch{}}#c(t,e){if(!this.#u(e))return;const n=t.origin;if(!this.#u(e))return;if(!this.#f(n,e))return void this.#d("origin",n,e);const i=t.data;if(!this.#u(e))return;const r="object"==typeof(s=i)&&null!==s&&"type"in s&&"string"==typeof s.type;var s;if(!this.#u(e))return;if(!r)return void this.#d("shape",n,e);const o=i.type;if(this.#u(e))switch(o){case"payload-live-preview":{const t=function(t){const e=t;return!!((void 0===e.data||null===e.data||O(e.data))&&I(e.fieldSchemaJSON,t=>Array.isArray(t))&&I(e.globalSlug,t=>"string"==typeof t)&&I(e.collectionSlug,t=>"string"==typeof t)&&I(e.locale,t=>"string"==typeof t)&&I(e.ready,t=>"boolean"==typeof t)&&I(e.previewToken,t=>"string"==typeof t)&&I(e.protocolVersion,t=>"number"==typeof t))}(i);if(!this.#u(e))return;if(!t)return void this.#d("shape",n,e);const r=function(t){const e={...t};for(const t of U)null===Reflect.get(e,t)&&Reflect.deleteProperty(e,t);if(!Array.isArray(e.fieldSchemaJSON))return e;let n;try{n=$(e.fieldSchemaJSON)}catch{n=[]}return{...e,fieldSchemaJSON:n}}(i);if(!this.#u(e))return;return void this.#p(r,n,e)}case"payload-document-event":{const t=function(t){const e=t;return!!E(e.action,t=>"updated"===t||"created"===t||"deleted"===t)&&!!E(e.slug,t=>"string"==typeof t)&&!!E(e.id,t=>"string"==typeof t||"number"==typeof t&&Number.isFinite(t))}(i);if(!this.#u(e))return;if(!t)return void this.#d("shape",n,e);let r;try{r=this.s[1].onDocumentEvent}catch{return}if(!this.#u(e))return;return void this.#g(r,i,n)}default:this.#d("type",n,e)}}#p(t,e,n){if(!this.#u(n))return;const i=t.data;if(!this.#u(n))return;const r=O(i);if(!this.#u(n))return;const s=r?{generation:n,revision:this.s[5]+=1}:void 0;let o;try{o=this.s[1].validateToken}catch{return}if(!this.#u(n))return;if(void 0===o)return void this.#m(t,e,n,s);if(!0===t.ready&&void 0===i)return void this.#m(t,e,n,void 0);const a={generation:n,message:t,origin:e,messageRevision:s,settled:!1,approved:!1};let l;this.s[6].push(a);try{l=o(t.previewToken,e)}catch{return void this.#v(a,!1)}"boolean"!=typeof l?Promise.resolve(l).then(t=>{this.#v(a,!0===t)},()=>{this.#v(a,!1)}):this.#v(a,l)}#v(t,e){this.#u(t.generation)&&(t.approved=e,t.settled=!0,this.#y(t.generation))}#y(t){for(;this.#u(t);){const e=this.s[6][this.s[7]];if(void 0===e)return;if(this.#f(e.origin,t)){if(!e.settled)return;this.#b(e)&&(e.approved?this.#m(e.message,e.origin,e.generation,e.messageRevision):this.#d("token",e.origin,e.generation))}else{if(!this.#b(e))continue;this.#d("origin",e.origin,e.generation)}}}#m(t,e,n,i){if(!this.#u(n))return;let r;try{r=this.s[1].onUpdate}catch{return}this.#u(n)&&(void 0===i?this.#g(r,t,e):this.#g(r,t,e,i))}#d(t,e,n){if(!this.#u(n))return;let i;try{i=this.s[1].onInvalid}catch{return}this.#u(n)&&void 0!==i&&this.#g(i,t,e)}#f(t,e){if(!this.#u(e))return!1;try{return!0===this.s[0](t)&&this.#u(e)}catch{return!1}}#g(t,...e){try{R(t(...e))}catch{}}#u(t){return void 0!==this.s[3]&&this.s[4]===t}#b(t){const e=this.s;return e[6][e[7]]===t&&(e[7]+=1,e[7]===e[6].length?(this.#h(),!0):(e[7]>=1024&&2*e[7]>=e[6].length&&(e[6]=e[6].slice(e[7]),e[7]=0),!0))}#h(){this.s[6]=[],this.s[7]=0}};function E(t,e){return void 0===t||e(t)}function I(t,e){return null==t||e(t)}function O(t){if("object"!=typeof t||null===t)return!1;const e=Object.getPrototypeOf(t);return null===e||null===Object.getPrototypeOf(e)}var U=["data","fieldSchemaJSON","globalSlug","collectionSlug","locale","ready","previewToken","protocolVersion"],P=class{s;constructor(t){this.s=[t.timeoutMs??0,t.onTimeout,null,0]}kick(){if(this.s[3]=Date.now(),this.s[0]<=0)return;null!==this.s[2]&&clearTimeout(this.s[2]);const t=setTimeout(()=>{this.s[2]===t&&(this.s[2]=null,this.s[1]())},this.s[0]);this.s[2]=t}stop(){null!==this.s[2]&&(clearTimeout(this.s[2]),this.s[2]=null)}get lastKickAt(){return this.s[3]}get pending(){return null!==this.s[2]}},L=class{s;constructor(t){this.s=["disconnected",t]}get status(){return this.s[0]}markConnected(){return this.transition("connected")}markConnecting(){return this.transition("connecting")}markDisconnected(){return this.transition("disconnected")}transition(t){if(this.s[0]===t)return!1;const e=this.s[0];return this.s[0]=t,this.s[1](t,e),!0}};function F(t){return(...e)=>{try{R(t(...e))}catch{}}}function j(){}var H=F((...t)=>console.error(...t)),D=F((...t)=>console.warn(...t)),z=F((...t)=>console.debug(...t));function W(t){for(const e of t){const t=e.codePointAt(0);if(void 0!==t&&(t<=31||127===t))return!0}return!1}function G(t){if(void 0===t||0===t.length||t.length>128||"."===t||".."===t||t.includes("/")||t.includes("\\")||t.includes("?")||t.includes("#")||W(t))return!1;try{return encodeURIComponent(t),!0}catch{return!1}}var V=class{s;constructor(t){const e=t.serverURL.replace(/\/+$/,""),n=t.apiRoute??"/api";this.s=[e,n.startsWith("/")?n:`/${n}`,t.depth??1,t.fetchFn,void 0===t.log?j:F(t.log),null,0,0]}canMerge(t){try{return t.globalSlug?G(t.globalSlug):!!G(t.collectionSlug)&&function(t){if("number"==typeof t)return Number.isFinite(t);if("string"!=typeof t||0===t.length||t.length>512||"."===t||".."===t||t.includes("/")||t.includes("\\")||W(t))return!1;try{return encodeURIComponent(t),!0}catch{return!1}}(t.data.id)}catch{return!1}}async merge(t){if(this.s[7]>0)return{status:"superseded"};const e=this.s[6]+1;this.s[6]=e;const n=this.s[5];this.s[5]=null;let i=null;try{if(n?.abort(),!_(this.s,e))return{status:"superseded"};if(!this.canMerge(t))return _(this.s,e)?{status:"unavailable"}:{status:"superseded"};if(!_(this.s,e))return{status:"superseded"};const r=this.s[3]??("function"==typeof fetch?fetch:void 0);if(!_(this.s,e))return{status:"superseded"};if(void 0===r)return{status:"unavailable"};if(i=new AbortController,!_(this.s,e))return i.abort(),{status:"superseded"};this.s[5]=i;const s=t.globalSlug?`globals/${encodeURIComponent(t.globalSlug)}`:`${encodeURIComponent(t.collectionSlug??"")}/${encodeURIComponent(String(t.data.id))}`,o=`${this.s[0]}${this.s[1]}/${s}`,a=JSON.stringify({data:t.data,depth:this.s[2],flattenLocales:!1,...void 0!==t.locale?{locale:t.locale}:{}});if(!_(this.s,e))return{status:"superseded"};const l=await r(o,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json","X-Payload-HTTP-Method-Override":"GET"},body:a,signal:i.signal});if(!_(this.s,e)||B(i.signal))return{status:"superseded"};const u=l.ok;if(!_(this.s,e))return{status:"superseded"};if(!u){const t=l.status;return _(this.s,e)?(this.s[4]("merge HTTP",t,o),_(this.s,e)?{status:"unavailable"}:{status:"superseded"}):{status:"superseded"}}const c=await l.json();return!_(this.s,e)||B(i.signal)?{status:"superseded"}:null===c||"object"!=typeof c||Array.isArray(c)?(this.s[4]("merge invalid",o),_(this.s,e)?{status:"unavailable"}:{status:"superseded"}):{status:"merged",doc:c}}catch(t){return!_(this.s,e)||null!==i&&B(i.signal)?{status:"superseded"}:(this.s[4]("merge exception",t),_(this.s,e)?{status:"unavailable"}:{status:"superseded"})}finally{null!==i&&_(this.s,e)&&this.s[5]===i&&(this.s[5]=null)}}destroy(){this.s[6]+=1;const t=this.s[5];this.s[5]=null,this.s[7]+=1;try{t?.abort()}finally{this.s[7]-=1}}};function _(t,e){return t[6]===e}function B(t){return t.aborted}var q=new Set(["http:","https:","mailto:","tel:"]),J=/^\s*(?:javascript|data|vbscript|file|blob|about)\s*:/i,Q=/^(?:\.{1,2}\/|[a-zA-Z0-9_-]+\/?)/;function isSafeUrl(t){if("string"!=typeof t||0===t.length)return!1;const e=t.trim();if(0===e.length)return!1;if(J.test(e))return!1;if(e.startsWith("#")||e.startsWith("?"))return!0;if(e.startsWith("//"))return!0;if(e.startsWith("/"))return!0;try{const t=new URL(e);return q.has(t.protocol)}catch{return Q.test(e)}}function isExternalHttpUrl(t){if(!isSafeUrl(t))return!1;const e=t.trim();return/^https?:\/\//i.test(e)||/^\/\/[^/]/.test(e)}var X=new Set(["style","srcdoc","formaction","form","id","name","is","srcset","imagesrcset"]),Y=new Set(["href","src","poster","cite","action","xlink:href","data"]),K=new WeakSet;function Z(t){return K.add(t),t}var tt=class{s;constructor(t,e){const n=e.scheduleFrame??("function"==typeof requestAnimationFrame?requestAnimationFrame.bind(globalThis):t=>setTimeout(()=>{t(performance.now())},0)),i=e.cancelFrame??("function"==typeof cancelAnimationFrame?cancelAnimationFrame.bind(globalThis):t=>{clearTimeout(t)});this.s=[t,e.debounceMs??50,e.isVisible,e.visibilityGateThreshold??50,e.disableVisibilityGate??!1,e.getCacheSize,e.onFlush,n,i,new Map,new Map,new Set,null,0,null,0,null,!1]}schedule(t){if(void 0!==t.identity){if(this.s[17])return;if(!et(t.identity,this.s[16]))return}const e=this.s[9],n=e.get(t.target.element);n?(n.value=t.value,n.allFields=t.allFields,n.identity=t.identity,n.data=t.data):e.set(t.target.element,{...t,identity:t.identity,data:t.data}),this.#w()}acceptRevision(t){const e=this.s[16];var n,i;et(t,e)||null!==e&&(i=e,((n=t).generation!==i.generation?n.generation-i.generation:n.revision-i.revision)<0)||(this.#S(),this.#A(),this.s[16]=t,this.s[17]=!1)}cancelRevision(t){et(t,this.s[16])&&(this.#S(),this.#A(),this.s[17]=!0)}flushNow(){return this.#S(),this.#k()}notifyVisible(t){const e=this.s[10],n=e.get(t);if(!n)return;if(e.delete(t),!this.#C(n))return;const i=performance.now(),r=this.#T(n)?1:0;this.s[6]?.(this.#$(n,r,0,performance.now()-i))}retarget(t){this.#x(this.s[9],t),this.#x(this.s[10],t);for(const e of this.s[11])this.#x(e,t)}forget(t){this.s[9].delete(t),this.s[10].delete(t);for(const e of this.s[11])e.delete(t)}destroy(){this.#S(),this.#A(),this.s[16]=null,this.s[17]=!1}get pendingCount(){return this.s[9].size}get replayCount(){return this.s[10].size}#w(){const t=this.s[13]+=1,e=this.s[12];if(this.s[12]=null,null!==e&&clearTimeout(e),this.s[13]!==t)return;const n=setTimeout(()=>{this.s[13]===t&&(this.s[12]=null,this.#N())},this.s[1]);this.s[13]===t&&(this.s[12]=n)}#N(){const t=this.s[15]+=1,e=this.s[14];if(this.s[14]=null,null!==e&&this.s[8](e),this.s[15]!==t)return;let n=!1;const i=this.s[7](()=>{this.s[15]===t&&(n=!0,this.s[14]=null,this.#k())});n||this.s[15]!==t||(this.s[14]=i)}#k(){const t=performance.now(),e=!this.s[4]&&this.s[5]()>this.s[3],n=this.s[9];this.s[9]=new Map;let i,r=0,s=0;this.s[11].add(n);try{for(const t of n.values()){if(!this.#C(t))continue;const n=!e||this.s[2](t.target.element);this.#C(t)&&(i??=t,n?(this.s[10].delete(t.target.element),this.#T(t)&&(r+=1)):(this.s[10].set(t.target.element,t),s+=1))}}finally{this.s[11].delete(n)}const o=this.#$(i,r,s,performance.now()-t);return this.s[6]?.(o),o}#C(t){return void 0===t.identity||!this.s[17]&&et(t.identity,this.s[16])}#T(t){const e=this.s[0];return!1!==e(t)||(n=e,!K.has(n));var n}#x(t,e){const n=t.get(e.element);void 0!==n&&(n.target.fieldName===e.fieldName&&n.target.locale===e.locale?n.target=e:t.delete(e.element))}#A(){this.s[9].clear(),this.s[10].clear();for(const t of this.s[11])t.clear()}#$(t,e,n,i){return{applied:e,deferred:n,durationMs:i,...void 0!==t?.identity?{identity:t.identity}:{},...void 0!==t?.data?{data:t.data}:{}}}#S(){const t=this.s[12],e=this.s[14];this.s[13]+=1,this.s[15]+=1,this.s[12]=null,this.s[14]=null,null!==t&&clearTimeout(t),null!==e&&this.s[8](e)}};function et(t,e){return null!==e&&t.generation===e.generation&&t.revision===e.revision}var nt=new Set(["__proto__","prototype","constructor"]);function it(t,e,n,i=!1){if(i&&void 0!==n){const i=rt(t,`${e}_${n}`);if(void 0!==i)return i}const r=rt(t,e);if(void 0!==r)return r;if(e.includes(".")){let n=t,i=!0;for(const t of e.split(".")){if(nt.has(t)||null===n||"object"!=typeof n){i=!1;break}if(n=rt(n,t),void 0===n){i=!1;break}}if(i)return n}return void 0===n?void 0:rt(t,`${e}_${n}`)}function rt(t,e){if(!nt.has(e)&&Object.prototype.hasOwnProperty.call(t,e))return t[e]}function detectInitialLocale(){const t=function(){if("undefined"==typeof document)return;const t=document.documentElement.getAttribute("lang");return null===t||0===t.length?void 0:t}();if(void 0!==t)return t;const e=function(){if("undefined"==typeof navigator)return;const t=navigator.language;return"string"==typeof t&&t.length>0?t:void 0}();return void 0!==e?e:"en"}var st="payload-live-preview-a11y";function ot(t){return/^de(?:[-_]|$)/i.test(t)}var at=new WeakMap;function lt(t){null!==t[4]&&(clearTimeout(t[4]),t[4]=null),t[2]?.remove(),t[2]=null}var ut=class{s;constructor(t,e){const n=e??("undefined"==typeof document?null:document),i=n?.documentElement.getAttribute("lang")??"";this.s=[ot(t??(i.length>0?i:detectInitialLocale())),n,null]}mount(){const t=this.s[1];if(null==t?.body)return null;let e=this.s[2];null===e&&(e=function(t){let e=at.get(t);return e??=[null,!1,null,0,null],at.set(t,e),e[3]+=1,e}(t),this.s[2]=e);const n=e[0];if(n?.isConnected&&n.ownerDocument===t)return n;if(null!==n){const t=e[1];lt(e),t&&n.remove()}let i=t.getElementById(st);return e[1]=null===i,i||(i=t.createElement("div"),i.id=st,i.setAttribute("role","status"),i.setAttribute("aria-live","polite"),i.setAttribute("aria-atomic","true"),i.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"),t.body.appendChild(i)),e[0]=i,i}announceConnected(){this.say(this.s[0]?"Vorschau verbunden":"Live preview connected")}announceDisconnected(){this.say(this.s[0]?"Vorschau getrennt":"Live preview disconnected")}announceUpdate(t){t<=0||this.say(this.s[0]?`${String(t)} ${1===t?"Änderung":"Änderungen"} angewendet`:`${String(t)} ${1===t?"change":"changes"} applied`)}detach(){const t=this.s[2],e=this.s[1];if(null===t||null===e)return;if(this.s[2]=null,t[3]-=1,t[3]>0)return;const n=t[0];null!==n&&lt(t),t[1]&&n?.remove(),t[0]=null,at.delete(e)}say(t){const e=this.mount(),n=this.s[2];if(null===e||null===n)return;let i=n[2];i?.parentNode!==e?(i?.remove(),i=e.ownerDocument.createTextNode(e.hasChildNodes()?` ${t}`:t),n[2]=i,e.appendChild(i)):i.data=null===i.previousSibling?t:` ${t}`,null!==n[4]&&clearTimeout(n[4]);const r=setTimeout(()=>{n[4]===r&&n[0]===e&&lt(n)},1500);n[4]=r}},ct=new Set(["tabs","row","collapsible"]);function dt(t,e=""){const n=new Map;return ht(t,e,n),n}function ht(t,e,n){for(const i of t){if(ct.has(i.type)){i.fields&&ht(i.fields,e,n);continue}if("group"===i.type){const t=""===e?i.name:`${e}.${i.name}`;n.set(t,i),i.fields&&ht(i.fields,t,n);continue}const t=""===e?i.name:`${e}.${i.name}`;if(n.set(t,i),"array"===i.type&&i.fields)ht(i.fields,`${t}.*`,n);else if("blocks"===i.type&&i.blocks)for(const e of i.blocks)ht(e.fields,`${t}.*.${e.slug}`,n)}}function ft(t){if("object"!=typeof t||null===t)return;const e=t.id;return"string"==typeof e||"number"==typeof e?e:void 0}function pt(t){if("object"!=typeof t||null===t)return;const e=t.blockType;return"string"==typeof e?e:void 0}function gt(t,e){return e.every(t=>void 0!==ft(t))?function(t,e){const n=[],i=new Map;for(let e=0;e<t.length;e+=1){const n=ft(t[e]);void 0!==n&&i.set(n,e)}const r=new Set;for(let s=0;s<e.length;s+=1){const o=e[s],a=ft(o);if(void 0===a){n.push({kind:"insert",index:s,value:o});continue}const l=i.get(a);if(void 0===l){n.push({kind:"insert",index:s,value:o});continue}r.add(l);const u=t[l];pt(u)===pt(o)?(l!==s&&n.push({kind:"move",from:l,to:s,value:o}),mt(u,o)||n.push({kind:"update",index:s,value:o})):n.push({kind:"replace",index:s,oldValue:u,value:o})}for(let e=0;e<t.length;e+=1)r.has(e)||n.push({kind:"remove",index:e,value:t[e]});return n}(t,e):function(t,e){const n=[],i=Math.min(t.length,e.length);for(let r=0;r<i;r+=1)mt(t[r],e[r])||n.push({kind:"update",index:r,value:e[r]});if(e.length>t.length)for(let i=t.length;i<e.length;i+=1)n.push({kind:"insert",index:i,value:e[i]});if(t.length>e.length)for(let i=e.length;i<t.length;i+=1)n.push({kind:"remove",index:i,value:t[i]});return n}(t,e)}function mt(t,e){if(Object.is(t,e))return!0;if("object"!=typeof t||"object"!=typeof e||null===t||null===e)return!1;const n=t,i=e,r=Object.keys(n),s=Object.keys(i);if(r.length!==s.length)return!1;for(const t of r)if(!Object.is(n[t],i[t]))return!1;return!0}var vt={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"},yt=[0,500,1e3,2e3],bt=class{d;l;constructor(t){const e=t.emitter,n=t.renderers,i=t.resolveRenderer??(t=>n[t]),r=t.transformValue,s=t.root??("undefined"!=typeof document?document:null),o=t.readyTargets,a=t.sendReady??St,l=t.onHeartbeatTimeout,u=void 0===t.log?j:F(t.log),c=void 0===t.warn?D:F(t.warn),d=function(t){if(!1===t.enableA11y)return null;const e=void 0===t.root?void 0:9===t.root.nodeType?t.root:t.root.ownerDocument;return new ut(t.a11yLocale,e)}(t),h=void 0!==t.dataMerge?new V({serverURL:t.dataMerge.serverURL,...void 0!==t.dataMerge.apiRoute?{apiRoute:t.dataMerge.apiRoute}:{},...void 0!==t.dataMerge.depth?{depth:t.dataMerge.depth}:{},...void 0!==t.dataMerge.fetchFn?{fetchFn:t.dataMerge.fetchFn}:{},log:(...t)=>{u(...t)}}):null,f=new y,p=new C({onStructuralChange:()=>{this.#R()},onVisibilityChange:(t,e)=>{e&&this.d[3].notifyVisible(t)}},{...void 0!==t.intersectionRootMargin?{intersectionRootMargin:t.intersectionRootMargin}:{}}),g=new tt(Z(t=>this.#M(t)),{...void 0!==t.debounceMs?{debounceMs:t.debounceMs}:{},...void 0!==t.disableVisibilityGate?{disableVisibilityGate:t.disableVisibilityGate}:{},...void 0!==t.visibilityGateThreshold?{visibilityGateThreshold:t.visibilityGateThreshold}:{},isVisible:t=>p.isVisible(t),getCacheSize:()=>f.elementCount,onFlush:t=>{this.#E(t)}}),m=new M(t.originMatcher,{onUpdate:(t,e,n)=>{this.#I(t,e,n)},onDocumentEvent:()=>{e.emit("documentSave",{timestamp:Date.now()})},onInvalid:(t,n)=>{if("token"===t){const t=new Error(`Preview token rejected (origin: ${n})`);e.emit("error",{error:t,context:"token"})}u("message rejected:",t,n)},...void 0!==t.validateToken?{validateToken:t.validateToken}:{}}),v=new L(()=>{}),b=new P({...void 0!==t.heartbeatMs?{timeoutMs:t.heartbeatMs}:{},onTimeout:()=>{this.#O()}});this.d=[e,f,p,g,m,v,b,n,i,r,s,o,a,l,u,c,[],d,h,!0===t.scopeBindingsByOwner],this.l=[void 0,void 0,void 0,negotiateProtocol(void 0),!1,null,0,null,new Set,!1,!1]}start(){if(this.l[4])return!1;this.l[4]=!0;const t=this.d[10];if(wt(t)&&"loading"===t.readyState){const e=()=>{if(this.l[4]){this.l[5]=null;try{this.#U()}catch(t){this.#P(),this.#L(t,"startup")}}};this.l[5]=e;try{t.addEventListener("DOMContentLoaded",e,{once:!0})}catch(t){throw this.#P(),t}return!0}try{return this.#U(),!0}catch(t){throw this.#P(),t}}#U(){if(!this.l[4])return;const t=wt(this.d[10])?this.d[10].body:this.d[10];if(null===t)throw new Error("LivePreviewRuntime: document.body unavailable");if(this.d[2].start(t),this.#F(),this.#j()&&(this.d[4].attach(),this.d[0].emitWhile("init",{timestamp:Date.now()},()=>this.l[4]),this.#j()))for(const t of yt){if(!this.#j())return;if(0===t){if(this.d[12](this.d[11]),!this.#j())return}else{const e=setTimeout(()=>{this.l[4]&&this.#H()},t);this.d[16].push(e)}}}destroy(){this.l[4]&&(this.#D()&&this.d[0].emit("disconnect",{reason:"destroy",timestamp:Date.now()}),this.d[17]?.detach(),this.d[0].emit("destroy",{timestamp:Date.now()}))}#D(){this.l[7]=null,this.l[4]=!1;const t=this.l[5];this.l[5]=null,null!==t&&wt(this.d[10])&&this.#z(()=>{this.d[10].removeEventListener("DOMContentLoaded",t)});for(const t of this.d[16])this.#z(()=>{clearTimeout(t)});return this.d[16].length=0,this.#z(()=>{this.d[6].stop()}),this.#z(()=>{this.d[4].detach()}),this.#z(()=>{this.d[2].stop()}),this.#z(()=>{this.d[3].destroy()}),this.#z(()=>{this.d[18]?.destroy()}),this.d[1].clear(),this.d[5].markDisconnected()}#P(){this.#D(),this.#z(()=>{this.d[17]?.detach()})}#z(t){try{t()}catch(t){this.d[14]("cleanup failed:",t)}}refreshCache(){this.l[4]&&this.#R()}get status(){return this.d[5].status}get cache(){return this.d[1]}get updateCount(){return this.l[6]}get protocol(){return this.l[3]}#F(){if(!this.l[4])return;const t=this.d[1].buildFromRoot(this.d[10]);if(this.d[14]("cache",t),this.#j()&&(this.d[0].emitWhile("cacheRefresh",t,()=>this.l[4]),this.#j()))for(const t of this.d[1].values()){if(!this.#j())return;this.d[2].observeElement(t.element)}}#R(){if(!this.l[4])return;const t=new Map;for(const e of this.d[1].values())t.set(e.element,e),this.d[2].unobserveElement(e.element);if(this.#F(),this.#j()){for(const e of this.d[1].values()){const n=t.get(e.element);n?.fieldName===e.fieldName?this.d[3].retarget(e):this.d[3].forget(e.element),t.delete(e.element)}for(const e of t.values())this.d[3].forget(e.element)}}#W(t){const e=negotiateProtocol(t);e.negotiated!==this.l[3].negotiated&&(this.l[3]=e,this.d[14]("protocol","ours=4",`theirs=${t}`,`negotiated=${e.negotiated}`))}#I(t,e,n){if(this.d[6].kick(),void 0===t.data)return void(void 0!==t.protocolVersion&&this.#W(t.protocolVersion));if(void 0===n)return;"string"==typeof t.locale&&(this.l[0]=t.locale),Array.isArray(t.fieldSchemaJSON)&&(this.l[1]=t.fieldSchemaJSON,this.l[2]=dt(t.fieldSchemaJSON));const i={identity:n,message:t,locale:this.l[0],schema:this.l[1],schemaIndex:this.l[2],cancelled:!1};if(this.l[7]=i,this.d[3].acceptRevision(n),this.l[6]+=1,void 0===t.protocolVersion||(this.#W(t.protocolVersion),this.l[4]&&this.l[7]===i)){if(this.d[5].markConnected()){if(this.d[17]?.announceConnected(),this.d[0].emit("connect",{origin:e,timestamp:Date.now()}),!this.l[4]||this.l[7]!==i)return;if(this.d[14]("connection","disconnected","→","connected"),!this.l[4]||this.l[7]!==i)return}this.#G(i)}}async#G(t){const e=await this.#V(t);if(null===e||!this.l[4]||this.l[7]!==t)return;const{message:n}=t,i={fields:e,...void 0!==t.schema?{schema:t.schema}:{},..."string"==typeof n.globalSlug?{globalSlug:n.globalSlug}:{},..."string"==typeof n.collectionSlug?{collectionSlug:n.collectionSlug}:{},...void 0!==t.locale?{locale:t.locale}:{}};this.d[0].listenerCount("beforeUpdate")>0&&(!await this.d[0].emitWhile("beforeUpdate",{data:i,revision:t.identity.revision,cancel:()=>{t.cancelled=!0,this.d[3].cancelRevision(t.identity)}},()=>!t.cancelled&&this.l[4]&&this.l[7]===t)||t.cancelled||!this.l[4]||this.l[7]!==t)||this.l[4]&&this.l[7]===t&&this.#_(t,i)}async#V(t){const{message:e}=t,n=e.data??{};if(null===this.d[18])return n;const i=await this.d[18].merge({collectionSlug:e.collectionSlug,globalSlug:e.globalSlug,data:n,locale:t.locale});return this.l[4]&&this.l[7]===t?"merged"===i.status?i.doc:"superseded"===i.status?null:n:null}#_(t,e){if(!this.l[4]||this.l[7]!==t)return;const n=()=>this.l[4]&&this.l[7]===t,i=this.#B(t,e.fields);for(const[r,s]of this.d[1].entries()){if(!this.l[4]||this.l[7]!==t)return;for(const o of s){if(!1!==i&&!A(o.owner,i))continue;const s=it(e.fields,r,o.locale??t.locale,void 0!==o.locale);if(void 0===s)continue;if(!this.l[4]||this.l[7]!==t)return;const a=this.#q(o,s,e.fields,n);if(!this.l[4]||this.l[7]!==t)return;const l={target:o,value:a,allFields:e.fields,identity:t.identity,data:e};if(!this.l[4]||this.l[7]!==t)return;this.d[3].schedule(l)}}this.#J(e.fields,t.locale,i)}#B(t,e){if(!this.d[19])return!1;const{message:n}=t,i=function(t){if(S(t.globalSlug))return[(e=t.globalSlug,`global:${e}`)];var e;if(!S(t.collectionSlug))return null;const n=w(t.collectionSlug);return S(t.documentId)?[n,w(t.collectionSlug,t.documentId)]:[n]}({globalSlug:"string"==typeof n.globalSlug?n.globalSlug:void 0,collectionSlug:"string"==typeof n.collectionSlug?n.collectionSlug:void 0,documentId:k(e)});return null!==i||this.l[9]||(this.l[9]=!0,this.d[15]("[live-preview] scopeBindingsByOwner: update names no document; nothing applied")),i}#Q(t){for(const e of this.d[1].values())if(A(e.owner,t))return!0;return!1}#X(t,e){const n=this.d[1].get(t);return void 0!==n&&(!1===e||n.some(t=>A(t.owner,e)))}#J(t,e,n){if(0===this.d[1].fieldCount)return;if(!1!==n&&!this.#Q(n))return;let i;for(const[r,s]of Object.entries(t)){if(this.l[8].has(r))continue;if(kt.has(r))continue;if(!Ct(s))continue;const t=Tt(r,e);if(!(this.#X(r,n)||t!==r&&this.#X(t,n))){if(void 0===i){i=new Set;for(const[t,e]of this.d[1].entries())for(const r of e)(!1===n||A(r.owner,n))&&void 0!==r.locale&&i.add(`${t}_${r.locale}`)}i.has(r)||(this.l[8].add(r),this.d[15](`[live-preview] update arrived for field "${r}" but no <… data-payload-field="${t}"> element exists on this page. Render the binding anchor unconditionally in your template so live edits to an initially-empty field have somewhere to land.`))}}}#q(t,e,n,i){if(void 0===this.d[9])return e;try{const r=this.d[9](t.fieldName,e,{element:t.element,allFields:n},i),s=R(r);if(!i())return e;if(s)throw new TypeError(`Transform for "${t.fieldName}" returned a Promise/thenable; transforms must be synchronous`);return r}catch(t){if(!i())return e;const n=t instanceof Error?t:new Error(String(t));return this.d[0].emit("error",{error:n,context:"transform"}),e}}#j(){return this.l[4]}#Y(t){0!==t.deferred&&(this.l[10]||(this.l[10]=!0,this.d[15](`[live-preview] visibility gate held ${String(t.deferred)} offscreen update(s) until scrolled into view; see visibilityGateThreshold.`)))}#M(t){const e=this.l[7];if(null===e||void 0===t.identity||!At(e.identity,t.identity)||!this.l[4]||this.l[7]!==e)return!1;const n=void 0!==e.schemaIndex?function(t,e){if(t.has(e))return t.get(e);const n=e.replace(/\.\d+(?=\.|$)/g,".*");return t.has(n)?t.get(n):void 0}(e.schemaIndex,t.target.fieldName):void 0,i=t.value;let r,s=function(t,e){if(t.explicitFieldType)return t.fieldType;if(void 0!==e){const t=function(t){if(Object.prototype.hasOwnProperty.call(vt,t))return vt[t]}(e);if(void 0!==t)return t}return t.fieldType}(t.target,n?.type);"text"===s&&!0!==t.target.explicitFieldType&&function(t){if("object"!=typeof t||null===t)return!1;if(!("root"in t))return!1;const e=t.root;return"object"==typeof e&&null!==e&&Array.isArray(e.children)}(i)&&(s="richText");try{r=this.d[8](s)}catch(t){if(!this.l[4]||this.l[7]!==e)return!1;const n=t instanceof Error?t:new Error(String(t));return this.d[0].emitWhile("error",{error:n,context:"renderer"},()=>this.l[4]&&this.l[7]===e),!1}if(!this.l[4]||this.l[7]!==e)return!1;const o=this.d[0].listenerCount("elementUpdate")>0,a=o?"INPUT"===(l=t.target.element).tagName||"TEXTAREA"===l.tagName?l.value:"IMG"===l.tagName?l.src:l.textContent:void 0;var l;if(!this.l[4]||this.l[7]!==e)return!1;const u={allFields:t.allFields,locale:t.target.locale??e.locale,schema:n};try{if(void 0!==t.target.targetAttribute){const e=function(t,e,n){const i=e.toLowerCase().trim();if(0===i.length)return"blocked";if(i.startsWith("on"))return"blocked";if(X.has(i))return"blocked";if(null==n)return t.removeAttribute(i),"applied";if("string"!=typeof n&&"number"!=typeof n&&"boolean"!=typeof n)return"blocked";const r=String(n);return Y.has(i)&&!isSafeUrl(r)?"blocked":(t.setAttribute(i,r),"applied")}(t.target.element,t.target.targetAttribute,i);if("blocked"===e)return this.d[15](`[live-preview] refused to write field "${t.target.fieldName}" into attribute "${t.target.targetAttribute}" (unsafe attribute or value)`),!1}else{if(!r)return this.d[14]("no renderer for",s),!1;{const e=function(t,e,n,i){return t.render(e,n,i)}(r,t.target,i,u);if(!1===e&&function(t){return K.has(t.render)}(r))return!1}}}catch(t){if(!this.l[4]||this.l[7]!==e)return!1;const n=t instanceof Error?t:new Error(String(t));return this.d[0].emitWhile("error",{error:n,context:"renderer"},()=>this.l[4]&&this.l[7]===e),!1}return!(!this.l[4]||this.l[7]!==e)&&(o&&this.d[0].emitWhile("elementUpdate",{element:t.target.element,fieldName:t.target.fieldName,previousValue:a,nextValue:i,revision:e.identity.revision},()=>this.l[4]&&this.l[7]===e),this.l[4]&&this.l[7]===e)}#E(t){this.#Y(t);const{identity:e,data:n}=t;if(0===t.applied||void 0===e||void 0===n)return;const i=this.l[7];if(null===i||!this.l[4]||this.l[7]!==i||!At(i.identity,e))return;const r=()=>this.l[4]&&this.l[7]===i&&At(i.identity,e);this.d[17]?.announceUpdate(t.applied),r()&&0!==this.d[0].listenerCount("afterUpdate")&&this.d[0].emitWhile("afterUpdate",{data:n,updatedCount:t.applied,durationMs:t.durationMs,revision:e.revision},r)}#O(){if(!this.#j())return;this.d[4].advanceGeneration();const t=this.l[7];this.l[7]=null,null!==t&&this.d[3].cancelRevision(t.identity),this.d[18]?.destroy();const e=this.d[5].markDisconnected();try{this.d[13]?.()}catch(t){this.d[14]("heartbeat:",t)}if(this.#j()){if(e&&this.#K()){if(this.d[17]?.announceDisconnected(),this.d[0].emitWhile("disconnect",{reason:"timeout",timestamp:Date.now()},()=>this.#K()),!this.#j())return;if(this.#K()&&(this.d[14]("connection","connected","→","disconnected"),!this.#j()))return}this.#j()&&this.#H()}}#H(){try{this.d[12](this.d[11])}catch(t){this.#L(t,"ready")}}#L(t,e){const n=t instanceof Error?t:new Error(String(t));this.d[0].emit("error",{error:n,context:e})}#K(){return this.l[4]&&"disconnected"===this.d[5].status&&null===this.l[7]}};function wt(t){return 9===t.nodeType}function St(t){if("undefined"==typeof window)return;const e=[];window.parent!==window&&e.push(window.parent),window.opener instanceof Window&&e.push(window.opener),M.sendReady(e,t)}function At(t,e){return t.generation===e.generation&&t.revision===e.revision}var kt=new Set(["id","_id","createdAt","updatedAt","createdBy","updatedBy","_status","globalType","collection","locale","localized"]);function Ct(t){return null!=t&&("string"==typeof t||"number"==typeof t||"boolean"==typeof t||"bigint"==typeof t)}function Tt(t,e){if(!e)return t;const n=`_${e}`;return t.endsWith(n)?t.slice(0,-n.length):t}var $t,xt=class{#Z=new Map;#tt=new Map;on(t,e){return this.#et(this.#Z,t,e)}once(t,e){return this.#et(this.#tt,t,e)}off(t,e){this.#nt(this.#Z,t,e),this.#nt(this.#tt,t,e)}async emit(t,e){await this.#it(t,e)}async emitWhile(t,e,n){return this.#it(t,e,n)}async#it(t,e,n){const i=()=>n?.()??!0;if(!i())return!1;const r=this.#Z.get(t);if(r)for(const n of[...r]){if(!i())return!1;if(await this.#rt(n,e,t),!i())return!1}if(!i())return!1;const s=this.#tt.get(t);if(s&&s.size>0){const n=[...s];this.#tt.delete(t);for(const r of n){if(!i())return!1;if(await this.#rt(r,e,t),!i())return!1}}return i()}listenerCount(t){return(this.#Z.get(t)?.size??0)+(this.#tt.get(t)?.size??0)}removeAllListeners(t){if(void 0===t)return this.#Z.clear(),void this.#tt.clear();this.#Z.delete(t),this.#tt.delete(t)}eventNames(){const t=new Set;for(const e of this.#Z.keys())t.add(e);for(const e of this.#tt.keys())t.add(e);return[...t]}#et(t,e,n){let i=t.get(e);return i||(i=new Set,t.set(e,i)),i.add(n),()=>{this.#nt(t,e,n)}}#nt(t,e,n){const i=t.get(e);void 0!==i&&(i.delete(n),0===i.size&&t.delete(e))}async#rt(t,e,n){try{await t(e)}catch(t){const e="string"==typeof n||"number"==typeof n?String(n):"<event>";H(`[live-preview] handler for "${e}" threw:`,t)}}};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 t=function(){if("undefined"==typeof process)return;const t=process.env.NODE_ENV;return"string"==typeof t?t:void 0}();if(void 0!==t)return"production"!==t;const e=function(){const t=Rt();if(!t)return;const e=t.DEV;return"boolean"==typeof e?e:void 0}();if(void 0!==e)return e;if("undefined"!=typeof window){const t=window.location.hostname;if("localhost"===t||"127.0.0.1"===t)return!0}return!1}function Nt(t){if("undefined"!=typeof process){const e=process.env[t];if("string"==typeof e&&e.length>0)return e}const e=Rt();if(e){const n=e[t];if("string"==typeof n&&n.length>0)return n}}function Rt(){if("undefined"==typeof __INLINE_RUNTIME_BUILD__||!__INLINE_RUNTIME_BUILD__){if(void 0!==$t)return $t??void 0;$t=null;try{const t=new Function("try { return import.meta && import.meta.env; } catch (_) { return undefined; }")();if(t&&"object"==typeof t)return $t=t}catch{}}}var Mt=/^https?:\/\/(localhost|127\.0\.0\.1)(?::\d+)?$/i,Et=/^https?:\/\/[^/?#\s]+$/i,It=["PAYLOAD_ADMIN_ORIGIN","PUBLIC_PAYLOAD_ADMIN_ORIGIN","NEXT_PUBLIC_PAYLOAD_ADMIN_ORIGIN"],Ot=class{#st;constructor(t={}){const e=new Set;for(const n of t.additionalOrigins??[]){const t=Pt(n);void 0!==t&&e.add(t)}for(const t of It){const n=Nt(t);if(void 0!==n)for(const t of n.split(",")){const n=Pt(t);void 0!==n&&e.add(n)}}let n;if(t.enableReferrerDetection??1){const e=t.referrer??("undefined"!=typeof document?document.referrer:"");if(e.length>0)try{const t=new URL(e).origin;t&&"null"!==t&&(n=t)}catch{}}const i=(t.enableLocalhostMatching??!0)&&(t.forceDevMode??isDevMode());this.#st=[e,n,i,void 0!==n,void 0]}matches(t){return 0!==t.length&&"null"!==t&&(void 0!==this.#st[4]?t===this.#st[4]:!!this.#st[0].has(t)||0===this.#st[0].size&&void 0!==this.#st[1]&&t===this.#st[1]||!(!this.#st[2]||!Mt.test(t)))}lockOrigin(t){return!!this.matches(t)&&(this.#st[4]=t,!0)}unlockOrigin(){const t=this.#st[4];return this.#st[4]=void 0,t}get lockedOrigin(){return this.#st[4]}enumerate(){if(void 0!==this.#st[4])return[this.#st[4]];const t=new Set(this.#st[0]);if(0===this.#st[0].size&&void 0!==this.#st[1]&&t.add(this.#st[1]),this.#st[2])for(const e of Ut)t.add(`http://localhost:${String(e)}`),t.add(`http://127.0.0.1:${String(e)}`);return[...t]}get referrerWasAvailable(){return this.#st[3]}get isProductionUnconfigured(){return!(!isInIframe()||this.#st[0].size>0||this.#st[2]||void 0!==this.#st[1])}get isReferrerOnlyTrust(){return!(this.#st[0].size>0||this.#st[2]||void 0===this.#st[1])}},Ut=[3e3,3001,3333,4e3,4321,5e3,5173,5174,8e3,8080,8888,9e3];function Pt(t){const e=t.trim();if(0!==e.length)try{const t=new URL(e);if("http:"!==t.protocol&&"https:"!==t.protocol)return;if(!Et.test(t.origin))return;return t.origin}catch{return}}var Lt,Ft=()=>{},jt=class{#ot;#at;#lt=new Set;#st="staging";constructor(t,e){this.#ot=t,this.#at=e}assertOpen(){if("closed"===this.#st)throw new Error(`Plugin context for "${this.#ot}" is no longer active`)}get active(){return"active"===this.#st}eligible(){return"closed"!==this.#st}own(t){return this.assertOpen(),this.#ut({acquire:void 0,finalize:void 0,cleanup:t,disposed:!1})}stage(t,e){this.assertOpen();const n={acquire:t,finalize:e,cleanup:void 0,disposed:!1},i=this.#ut(n);if("active"===this.#st)try{this.#ct(n)}catch(t){throw this.#dt(n),t}return i}commit(){if("staging"!==this.#st)throw new Error(`Plugin context for "${this.#ot}" cannot be committed`);this.#st="committing";try{for(const t of this.#lt)this.#ct(t);this.#st="active"}catch(t){throw this.close(),t}}close(){if("closed"!==this.#st){this.#st="closed";for(const t of[...this.#lt].reverse())this.#dt(t);this.#lt.clear()}}#ut(t){return this.#lt.add(t),()=>{this.#dt(t)}}#ct(t){if(t.disposed||void 0!==t.cleanup||void 0===t.acquire)return;const e=t.acquire();t.cleanup=e??Ft}#dt(t){if(t.disposed)return;t.disposed=!0,this.#lt.delete(t);const e=t.cleanup;if(t.cleanup=void 0,void 0!==e)try{R(e())&&this.#at(`plugin "${this.#ot}" cleanup returned a Promise/thenable; cleanups must be synchronous`)}catch(t){this.#at(`plugin "${this.#ot}" cleanup failed:`,t)}try{t.finalize?.()}catch(t){this.#at(`plugin "${this.#ot}" cleanup failed:`,t)}}},Ht=class extends xt{#ht;#ft;#pt=new Set;constructor(t,e){super(),this.#ht=t,this.#ft=e}on(t,e){return this.#gt("on",t,e)}once(t,e){return this.#gt("once",t,e)}off(t,e){const n=e;for(const e of[...this.#pt])e.event===t&&e.handler===n&&e.dispose()}emit(t,e){return this.#ft.assertOpen(),this.#ht.emit(t,e)}emitWhile(t,e,n){return this.#ft.assertOpen(),this.#ht.emitWhile(t,e,()=>{if(!this.#ft.eligible())return!1;const t=n();return!!this.#ft.eligible()&&t})}listenerCount(t){let e=0;for(const n of this.#pt)n.event===t&&(e+=1);return e}removeAllListeners(t){for(const e of[...this.#pt])void 0!==t&&e.event!==t||e.dispose()}eventNames(){const t=new Set;for(const e of this.#pt)t.add(e.event);return[...t]}#gt(t,e,n){this.#ft.assertOpen();const i=n,r=[...this.#pt].find(n=>n.kind===t&&n.event===e&&n.handler===i);if(void 0!==r)return r.dispose;let s=Ft,o=!0;const a=async e=>{this.#ft.active&&o&&("once"===t&&s(),await n(e))},l={kind:t,event:e,handler:i,dispose:Ft};return s=this.#ft.stage(()=>this.#ht[t](e,a),()=>{o=!1,this.#pt.delete(l)}),l.dispose=s,this.#pt.add(l),s}},Dt=class{#ht;#mt;#vt;#yt;#at;#bt=new Map;#wt=new Map;#St=new Map;#At=new Set;#kt=new Map;#Ct=Promise.resolve();#Tt=0;constructor(t){this.#ht=t.events,this.#mt=t.config,this.#vt=t.registerFieldRenderer,this.#at=F(t.log);const e=t.onTransformError;this.#yt=void 0===e?void 0:F((...t)=>{const n=t[0];if(n instanceof Error)try{return e(n)}catch(t){return void this.#at("transform error reporter failed:",t)}})}register(t){return this.#Tt>0?this.#$t(t):this.#xt(()=>this.#$t(t))}unregister(t){return this.#Tt>0?this.#Nt(t):this.#xt(async()=>{await this.#Nt(t)})}destroyAll(){return this.#Tt>0?this.#Rt():this.#xt(async()=>{await this.#Rt()})}applyTransforms(t,e,n,i){const r=this.#kt.get(t);if(void 0===r||0===r.length)return e;let s=e;for(const o of[...r]){if(!o.active)continue;const{transform:r}=o;if(!1===i?.())return e;try{s=r(s,{fieldName:t,element:n.element,allFields:n.allFields});const o=R(s);if(!1===i?.())return e;if(o)throw new TypeError(`Transform for "${t}" returned a Promise/thenable; transforms must be synchronous`)}catch(n){if(!1===i?.())return e;const r=n instanceof Error?n:new Error(String(n));return this.#at(`transform for "${t}" failed:`,r),this.#yt?.(r),e}}return s}list(){return[...this.#bt.keys()]}get size(){return this.#bt.size}async#$t(t){if(this.#bt.has(t.name)||this.#wt.has(t.name)||this.#St.has(t.name))return void this.#at(`plugin "${t.name}" already registered`);const e=new jt(t.name,this.#at),n=this.#Mt(t.name,e),i={scope:e,cancelled:!1};this.#wt.set(t.name,i);try{if(await this.#Et(()=>t.init(n)),i.cancelled)return;e.commit()}catch(n){return e.close(),void(i.cancelled||this.#at(`plugin "${t.name}" init failed:`,n))}finally{this.#wt.get(t.name)===i&&this.#wt.delete(t.name)}this.#bt.set(t.name,{plugin:t,scope:e}),this.#at(`plugin "${t.name}" registered`)}#Mt(t,e){return{events:new Ht(this.#ht,e),registerFieldRenderer:t=>{e.stage(()=>{const e=this.#vt(t);return"function"==typeof e?e:void 0})},registerTransform:(t,n)=>{const i={transform:n,active:!1};e.stage(()=>{i.active=!0;const e=this.#kt.get(t);return void 0===e?this.#kt.set(t,[i]):e.push(i),()=>{i.active=!1;const e=this.#kt.get(t);if(void 0===e)return;const n=e.indexOf(i);n>=0&&e.splice(n,1),0===e.length&&this.#kt.delete(t)}})},registerCleanup:t=>{e.own(t)},getConfig:()=>this.#mt,log:(...e)=>{this.#at(`[${t}]`,...e)}}}#Nt(t){const e=this.#wt.get(t);if(void 0!==e)return e.cancelled=!0,e.scope.close(),Promise.resolve();const n=this.#St.get(t);if(void 0!==n)return this.#At.has(t)?Promise.resolve():n;const i=this.#bt.get(t);if(void 0===i)return Promise.resolve();this.#bt.delete(t),i.scope.close();const r=Promise.resolve().then(()=>this.#It(t,i.plugin));return this.#St.set(t,r),r.then(()=>{this.#St.get(t)===r&&this.#St.delete(t)}),r}async#It(t,e){if(void 0!==e.destroy){this.#At.add(t);try{await this.#Et(()=>e.destroy?.())}catch(e){this.#at(`plugin "${t}" destroy failed:`,e)}finally{this.#At.delete(t)}}}async#Rt(){for(const t of this.#wt.values())t.cancelled=!0,t.scope.close();const t=[...this.#bt.keys()];for(const e of t)await this.#Nt(e)}async#Et(t){this.#Tt+=1;try{await t()}finally{this.#Tt-=1}}#xt(t){const e=this.#Ct.then(t);return this.#Ct=e.catch(t=>{this.#at("plugin manager mutation failed:",t)}),e}},zt=class{#Ot;#Ut;#Pt=new Map;constructor(t){this.#Ot=t,this.#Ut={...t}}get renderers(){return this.#Ut}resolve(t){return this.#Ut[t]}register(t){const e=t.name,n={renderer:t},i=this.#Pt.get(e);void 0===i?this.#Pt.set(e,[n]):i.push(n),this.#Ut[e]=t;let r=!0;return()=>{if(!r)return;r=!1;const t=this.#Pt.get(e);if(void 0===t)return;const i=t.indexOf(n);if(i<0)return;const s=i===t.length-1;if(t.splice(i,1),0===t.length&&this.#Pt.delete(e),!s)return;const o=t.at(-1),a=o?.renderer??this.#Ot[e];void 0===a?Reflect.deleteProperty(this.#Ut,e):this.#Ut[e]=a}}},Wt=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"]),Gt=new Set(["script","style","iframe","object","embed","link","meta","base","form","input","button","select","textarea","svg","math","template","frame","frameset","noframes","noscript"]),Vt=new Set(["id","class","lang","dir","title","role","tabindex"]),_t={a:new Set(["href","target","rel","download","hreflang","type"]),img:new Set(["src","srcset","sizes","alt","width","height","loading","decoding"]),picture:new Set([]),source:new Set(["src","srcset","sizes","type","media"]),audio:new Set(["src","controls","autoplay","loop","muted","preload"]),video:new Set(["src","poster","controls","autoplay","loop","muted","preload","width","height","playsinline"]),time:new Set(["datetime"]),abbr:new Set(["title"]),q:new Set(["cite"]),blockquote:new Set(["cite"]),table:new Set(["summary"]),th:new Set(["colspan","rowspan","scope","headers","abbr"]),td:new Set(["colspan","rowspan","headers"]),col:new Set(["span"]),colgroup:new Set(["span"]),ol:new Set(["start","reversed","type"]),li:new Set(["value"]),code:new Set(["class"]),pre:new Set(["class"])},Bt=new Set(["href","src","cite","poster"]),qt=class extends Error{name="SanitizerEnvironmentError"};function sanitizeHtml(t,e){const n=Jt();if(!n)throw new qt("sanitizeHtml needs a DOM; provide one with setSanitizerDocument() during SSR.");if(""===t)return"";const i=function(t){if(!t){const t=new Map;for(const[e,n]of Object.entries(_t))t.set(e,n);return{allowedTags:Wt,attrByTag:t}}const e=new Set(Wt);for(const n of t.additionalAllowedTags??[])e.add(n);const n=new Map;for(const[t,e]of Object.entries(_t))n.set(t,e);for(const[e,i]of Object.entries(t.additionalAllowedAttributes??{})){const t=n.get(e),r=new Set(t??[]);for(const t of i)r.add(t);n.set(e,r)}return{allowedTags:e,attrByTag:n}}(e),r=n.createElement("template");return r.innerHTML=t,Qt(r.content,i),r.innerHTML}function Jt(){return Lt||("undefined"!=typeof document?document:void 0)}function Qt(t,e){for(const n of Array.from(t.childNodes))1===n.nodeType?Xt(n,e):8===n.nodeType&&n.remove()}function Xt(t,e){const n=t.tagName.toLowerCase();if(Gt.has(n))t.remove();else{if(!e.allowedTags.has(n)){Qt(t,e);const n=t.parentNode;if(n){for(;t.firstChild;)n.insertBefore(t.firstChild,t);t.remove()}return}!function(t,e,n){const i=n.attrByTag.get(e);for(const e of Array.from(t.attributes)){const n=e.name.toLowerCase();n.startsWith("on")?t.removeAttribute(e.name):"style"!==n?Vt.has(n)||n.startsWith("aria-")||n.startsWith("data-")||(i?.has(n)?Bt.has(n)&&!isSafeUrl(e.value)?t.removeAttribute(e.name):"srcset"!==n||Yt(e.value)||t.removeAttribute(e.name):t.removeAttribute(e.name)):t.removeAttribute(e.name)}}(t,n,e),"a"===n&&function(t){const e=t.getAttribute("href");null!==e&&isExternalHttpUrl(e)&&(t.setAttribute("rel","noopener noreferrer"),t.hasAttribute("target")||t.setAttribute("target","_blank"))}(t),Qt(t,e)}}function Yt(t){const e=t.split(",");for(const t of e){const e=t.trim();if(0===e.length)continue;const n=e.search(/\s/);if(!isSafeUrl(-1===n?e:e.slice(0,n)))return!1}return!0}var Kt=new Map;function Zt(t,e){Kt.set(t,e)}var te={1:"left",2:"center",3:"right",4:"justify"},ee=new Set(["left","center","right","justify","start","end"]);function ne(t){const e=t.format;if("string"==typeof e&&ee.has(e))return e;if("number"==typeof e){const t=te[e];if(void 0!==t)return t}}function ie(t){const e=t.indent;return"number"==typeof e&&e>0?e:0}function re(t){return"rtl"===t.direction?' dir="rtl"':"ltr"===t.direction?' dir="ltr"':""}function se(t){const e=ne(t),n=ie(t),i=[];return void 0!==e&&i.push(`text-align:${e}`),n>0&&i.push(`padding-inline-start:${String(40*n)}px`),0===i.length?"":` style="${i.join(";")}"`}var oe=Object.freeze({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"}),ae=/[&<>"'/`=]/g;function escapeHtml(t){return""===t?"":t.replace(ae,t=>oe[t])}var le=Object.freeze({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"}),ue=/[&<>"']/g;function escapeHtmlAttribute(t){return""===t?"":t.replace(ue,t=>le[t])}function ce(t){return escapeHtml(t).replace(/\r\n|\r|\n/g,"<br>")}var de=new Set(["h1","h2","h3","h4","h5","h6"]),he=(t,e)=>{const n="string"==typeof t.url?t.url:"",i=e.renderChildren(t.children??[]);if(0===n.length||!isSafeUrl(n))return i;const r=isExternalHttpUrl(n)?' target="_blank" rel="noopener noreferrer"':function(t){const e="string"==typeof t.target?t.target:"";if(0===e.length)return"";const n=escapeHtml(e);return"_blank"===e?' target="_blank" rel="noopener noreferrer"':` target="${n}"`}(t),s="string"==typeof t.title?` title="${escapeHtml(t.title)}"`:"";return`<a href="${escapeHtmlAttribute(n)}"${r}${s}>${i}</a>`};function fe(t){if("string"==typeof t.text)return t.text;if(!t.children)return"";let e="";for(const n of t.children)e+=fe(n);return e}function pe(t){return t.replace(/[^a-zA-Z0-9_-]/g,"")}var ge=new Map;function me(t){return ge.get(t)}function ve(t){return t.replace(/[^a-zA-Z0-9_-]/g,"-").toLowerCase()}Zt("text",t=>{let e=escapeHtml("string"==typeof t.text?t.text:"");const n="number"==typeof t.format?t.format:0;return!!(16&n)&&(e=`<code>${e}</code>`),!!(1&n)&&(e=`<strong>${e}</strong>`),!!(2&n)&&(e=`<em>${e}</em>`),!!(8&n)&&(e=`<u>${e}</u>`),!!(4&n)&&(e=`<s>${e}</s>`),!!(32&n)&&(e=`<sub>${e}</sub>`),!!(64&n)&&(e=`<sup>${e}</sup>`),!!(128&n)&&(e=`<mark>${e}</mark>`),e}),Zt("paragraph",(t,e)=>{const n=e.renderChildren(t.children??[]);return`<p${re(t)}${se(t)}>${n}</p>`}),Zt("heading",(t,e)=>{const n="string"==typeof t.tag?t.tag.toLowerCase():"h2",i=de.has(n)?n:"h2",r=e.renderChildren(t.children??[]);return`<${i}${re(t)}${se(t)}>${r}</${i}>`}),Zt("list",(t,e)=>{const n="string"==typeof t.listType?t.listType:"bullet",i="number"===n?"ol":"ul",r="number"===n&&"number"==typeof t.start&&t.start>1?` start="${String(t.start)}"`:"",s="check"===n?' role="list"':"",o=e.renderChildren(t.children??[]);return`<${i}${re(t)}${se(t)}${r}${s}>${o}</${i}>`}),Zt("listitem",(t,e)=>{const n=e.renderChildren(t.children??[]);if("boolean"==typeof t.checked)return`<li role="checkbox" aria-checked="${t.checked?"true":"false"}"${se(t)}>${n}</li>`;const i="number"==typeof t.value?` value="${escapeHtml(String(t.value))}"`:"";return`<li${re(t)}${se(t)}${i}>${n}</li>`}),Zt("link",he),Zt("autolink",he),Zt("quote",(t,e)=>{const n=e.renderChildren(t.children??[]);return`<blockquote${re(t)}${se(t)}>${n}</blockquote>`}),Zt("code",t=>{const e=pe("string"==typeof t.language?t.language:"");return`<pre><code${""===e?"":` class="language-${e}"`}>${escapeHtml(fe(t))}</code></pre>`}),Zt("code-highlight",t=>{const e="string"==typeof t.text?t.text:"";return`<span${"string"==typeof t.highlightType?` class="token-${pe(t.highlightType)}"`:""}>${escapeHtml(e)}</span>`}),Zt("linebreak",()=>"<br>"),Zt("horizontalrule",()=>"<hr>"),Zt("tab",()=>"\t"),Zt("upload",t=>{const e=function(t){const e=t.value;return"object"!=typeof e||null===e?void 0:e}(t);if(void 0===e)return"";const n=e.url;if("string"!=typeof n||!isSafeUrl(n))return"";const i="string"==typeof e.mimeType?e.mimeType:"";return i.startsWith("video/")?function(t,e){const n="number"==typeof t.width?` width="${String(t.width)}"`:"",i="number"==typeof t.height?` height="${String(t.height)}"`:"",r="string"==typeof t.mimeType?` type="${escapeHtmlAttribute(t.mimeType)}"`:"";return`<video controls${n}${i}><source src="${escapeHtmlAttribute(e)}"${r}></video>`}(e,n):i.startsWith("audio/")?function(t,e){const n="string"==typeof t.mimeType?` type="${escapeHtmlAttribute(t.mimeType)}"`:"";return`<audio controls><source src="${escapeHtmlAttribute(e)}"${n}></audio>`}(e,n):""===i||i.startsWith("image/")?function(t,e){const n="string"==typeof t.alt?escapeHtml(t.alt):"",i="number"==typeof t.width?` width="${String(t.width)}"`:"",r="number"==typeof t.height?` height="${String(t.height)}"`:"";return`<img src="${escapeHtmlAttribute(e)}" alt="${n}"${i}${r} loading="lazy" decoding="async">`}(e,n):function(t,e){const n="string"==typeof t.filename?escapeHtml(t.filename):escapeHtml(e);return`<a href="${escapeHtmlAttribute(e)}" target="_blank" rel="noopener noreferrer">${n}</a>`}(e,n)}),Zt("relationship",t=>{const e="string"==typeof t.relationTo?t.relationTo:"",n=function(t){const e=t.value;return"object"!=typeof e||null===e?void 0:e}(t),i=function(t,e){return void 0===t?""===e?"#":`#${e}`:"string"==typeof t.title&&t.title.length>0?t.title:"string"==typeof t.name&&t.name.length>0?t.name:"string"==typeof t.slug&&t.slug.length>0?t.slug:void 0!==t.id?String(t.id):""===e?"#":`#${e}`}(n,e),r=escapeHtml(i),s=""===e?"":` data-relation-to="${escapeHtml(e)}"`,o=n?.url;return"string"==typeof o&&isSafeUrl(o)?`<a href="${escapeHtmlAttribute(o)}"${s}>${r}</a>`:`<span${s}>${r}</span>`}),Zt("block",(t,e)=>{const n=function(t){const e=t.fields;return"object"!=typeof e||null===e?{}:e}(t),i="string"==typeof n.blockType?n.blockType:"",r=ve(i);if(""!==i){const t=me(i)??me(r);if(t)return t(n,{renderChildren:e.renderChildren})}const s=[];""!==r&&s.push(`data-block-type="${escapeHtml(r)}"`);for(const[t,e]of Object.entries(n)){if("blockType"===t||"id"===t)continue;if(null==e)continue;const n="string"==typeof e||"number"==typeof e||"boolean"==typeof e?String(e):JSON.stringify(e);s.push(`data-block-${ve(t)}="${escapeHtml(n)}"`)}return`<div${0===s.length?"":` ${s.join(" ")}`}></div>`});var ye={renderChildren:Se,resolveAlignment:ne,resolveIndent:ie};function be(t){if("object"!=typeof t||null===t)return!1;if(!("root"in t))return!1;const e=t.root;return"object"==typeof e&&null!==e&&"children"in e&&Array.isArray(e.children)}function we(t){return be(t)?t.root.children.map(ke).join("\n").trim():""}function Se(t){let e="";for(const n of t)e+=Ae(n);return e}function Ae(t){const e=(n=t.type,Kt.get(n));var n;return e?e(t,ye):void 0!==t.children?Se(t.children):""}function ke(t){if("string"==typeof t.text)return t.text;if("linebreak"===t.type)return"\n";if(void 0===t.children)return"";let e="";for(const n of t.children)e+=ke(n);return e}function Ce(){const t=new WeakSet;return{name:"text",render:Z((e,n)=>{const i=e.element,r=function(t){return null==t?"":be(t)?we(t):"string"==typeof t?t:"number"==typeof t||"boolean"==typeof t?String(t):JSON.stringify(t)}(n);if("INPUT"!==i.tagName&&"TEXTAREA"!==i.tagName)return function(t){return null!==t.firstElementChild}(i)&&!i.hasAttribute("data-payload-text")?(function(t,e,n){t.has(e)||(t.add(e),D(`[live-preview] Skipping text update for "${n}": <${e.tagName.toLowerCase()}> has structured children. Move data-payload-field to the value element, or add data-payload-text to replace them.`))}(t,i,e.fieldName),!1):void(r.includes("\n")||r.includes("\r")?i.innerHTML=ce(r):i.textContent=r);i.value=r})}}function Te(t){if(null==t)return"";if("string"==typeof t)return t;if("number"==typeof t||"boolean"==typeof t||"bigint"==typeof t)return String(t);try{return JSON.stringify(t)}catch{return""}}var $e={name:"textarea",render(t,e){const n=t.element,i=be(e)?we(e):Te(e);"INPUT"!==n.tagName&&"TEXTAREA"!==n.tagName?n.innerHTML=ce(i):n.value=i}},xe={name:"richText",render:Z((t,e)=>{if(be(e))t.element.innerHTML=function(t,e={}){if(!be(t))return"";const n=Se(t.root.children);return!1===e.sanitize||void 0===Jt()?n:sanitizeHtml(n)}(e);else{if("string"!=typeof e)return!1;t.element.innerHTML=sanitizeHtml(e)}})},Ne={name:"html",render(t,e){if(null==e)return void(t.element.textContent="");const n="string"==typeof e?e:Te(e);t.element.innerHTML=sanitizeHtml(n)}},Re={name:"url",render(t,e,n){const i=t.element,r=Te(e);if("A"===i.tagName){const s=i,o=t.hrefField,a=void 0===o||0===o.length?e:it(n.allFields,o,n.locale,void 0!==t.locale);return"string"==typeof a&&isSafeUrl(a)&&(s.href=a),void(s.textContent=r)}"INPUT"!==i.tagName&&"TEXTAREA"!==i.tagName?i.textContent=r:i.value=r}},Me={name:"image",render:Z((t,e,n)=>{const i=t.element,r=Ee(e),s=void 0!==t.locale,o=function(t,e,n,i,r,s){if(void 0!==n&&n.length>0){const t=it(i,n,r,s);if("string"==typeof t&&isSafeUrl(t))return t;const e=Ee(t);return void 0!==e?.url&&isSafeUrl(e.url)?e.url:void 0}return void 0!==t?.url&&isSafeUrl(t.url)?t.url:"string"==typeof e&&isSafeUrl(e)?e:void 0}(r,e,t.srcField,n.allFields,n.locale,s);if(void 0===o)return!1;if("IMG"===i.tagName){const e=i;e.src=o;const a=function(t,e,n,i,r){if(void 0!==e&&e.length>0){const t=it(n,e,i,r);return"string"==typeof t?t:void 0}return void 0!==t?.alt?t.alt:void 0}(r,t.altField,n.allFields,n.locale,s);return void(void 0!==a&&(e.alt=a))}i.style.backgroundImage=`url('${function(t){return t.replace(/['"()\\]/g,"\\$&")}(o)}')`})};function Ee(t){if("object"==typeof t&&null!==t)return t}var Ie={name:"upload",render:Z((t,e)=>{const n=t.element,i=function(t){return"object"!=typeof t||null===t?void 0:t}(e);if(void 0===i)return!1;const r=i.url;if("string"!=typeof r||!isSafeUrl(r))return!1;if("IMG"===n.tagName){const t=n;return t.src=r,void(void 0!==i.alt&&(t.alt=i.alt))}if("A"===n.tagName){const t=n;return t.href=r,void(t.textContent=i.filename??r)}const s=void 0!==i.filename?escapeHtml(i.filename):escapeHtml(r);n.innerHTML=`<a href="${escapeHtmlAttribute(r)}">${s}</a>`})},Oe={name:"relationship",render(t,e){const n=t.element,i=function(t){return null==t?[""]:Array.isArray(t)?t.map(Ue):[Ue(t)]}(e),r=i.join(", ");if("A"===n.tagName&&!Array.isArray(e)){const t=n,i=e?.url;return"string"==typeof i&&isSafeUrl(i)&&(t.href=i),void(t.textContent=r)}n.textContent=r}};function Ue(t){if("object"==typeof t&&null!==t){const e=t;return"string"==typeof e.title&&e.title.length>0?e.title:"string"==typeof e.name&&e.name.length>0?e.name:"string"==typeof e.slug&&e.slug.length>0?e.slug:void 0!==e.id?String(e.id):""}return Te(t)}var Pe={name:"select",render(t,e){const n=t.element,i=Le(e);if("SELECT"!==n.tagName){if("INPUT"===n.tagName&&"radio"===n.type){const t=n;return void(t.checked=t.value===i)}n.textContent=i}else n.value=i}};function Le(t){return Array.isArray(t)?t.map(t=>Le(t)).join(", "):Te(t)}var Fe={name:"checkbox",render(t,e){const n=t.element,i=Boolean(e);"INPUT"!==n.tagName||"checkbox"!==n.type?n.hasAttribute("aria-checked")?n.setAttribute("aria-checked",i?"true":"false"):n.textContent=i?"true":"false":n.checked=i}},je=new Map,He=new Map;function De(t,e){const n=t??"";if(null==e)return n;const i=ze(e);return"{}"===i?n:`${n}|${i}`}function ze(t){if(null===t||"object"!=typeof t)return JSON.stringify(t);if(Array.isArray(t))return`[${t.map(t=>ze(t)).join(",")}]`;const e=t,n=Object.keys(e).sort(),i=[];for(const t of n){const n=e[t];void 0!==n&&i.push(`${JSON.stringify(t)}:${ze(n)}`)}return`{${i.join(",")}}`}function We(t){for(;t.size>64;){const e=t.keys().next().value;if(void 0===e)break;t.delete(e)}}var Ge={name:"date",render(t,e,n){const i=t.element;if(null==e||""===e)return void("INPUT"===i.tagName?i.value="":"TIME"===i.tagName?(i.removeAttribute("datetime"),i.textContent=""):i.textContent="");const r="string"==typeof e?e:Te(e),s=new Date(r),o=!Number.isNaN(s.getTime());if("INPUT"!==i.tagName)return"TIME"===i.tagName?(i.setAttribute("datetime",o?s.toISOString():r),void(i.textContent=o?Ve(s,n):r)):void(i.textContent=o?Ve(s,n):r);i.value=o?function(t,e){return"date"===t?e.toISOString().slice(0,10):"datetime-local"===t?e.toISOString().slice(0,16):e.toISOString()}(i.type,s):r}};function Ve(t,e){const n=e.locale??detectInitialLocale();try{return function(t,e){const n=De(t,e),i=He.get(n);if(void 0!==i)return He.delete(n),He.set(n,i),i;const r=new Intl.DateTimeFormat(t,e);return He.set(n,r),We(He),r}(n,{dateStyle:"medium",timeStyle:"short"}).format(t)}catch{return t.toISOString()}}var _e={name:"number",render(t,e,n){const i=t.element;if(null==e||""===e)return void("INPUT"===i.tagName?i.value="":i.textContent="");const r="number"==typeof e?e:Number(Te(e));Number.isNaN(r)?i.textContent=Te(e):"INPUT"!==i.tagName?i.textContent=function(t,e){const n=e.locale??detectInitialLocale();try{return function(t,e){const n=De(t,e),i=je.get(n);if(void 0!==i)return je.delete(n),je.set(n,i),i;const r=new Intl.NumberFormat(t,e);return je.set(n,r),We(je),r}(n).format(t)}catch{return String(t)}}(r,n):i.value=String(r)}},Be=/\{\{([\s\S]*?)\}\}/g;function qe(t,e,n,i){const r="object"==typeof e&&null!==e?e:null;return t.replace(Be,(t,s)=>null!==r&&function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(r,s)?escapeHtml(i(Reflect.get(r,s))):null===r&&"value"===s?escapeHtml(i(e)):"index"===s?String(n):t)}var Je={name:"array",render:Z((t,e)=>{const n=t.element;if(!Array.isArray(e))return!1;const i=t.arrayTemplate;if(void 0!==i&&i.length>0){const t=function(t,e){let n="";for(let i=0;i<e.length;i+=1)n+=Qe(t,e[i],i);return n}(i,e);return void(n.innerHTML=sanitizeHtml(t))}const r=t.arraySeparator??", ";n.textContent=e.map(Xe).join(r)})};function Qe(t,e,n){return qe(t,e,n,Te)}function Xe(t){return Te(t)}var Ye="data-payload-key",Ke="data-payload-nested-key",Ze="data-payload-nested-template";function tn(t){const{template:e,container:n,patches:i,nextItems:r,store:s,forceRender:o=!1}=t,a=en(n,e,i,r,o,s);return null===a?null:nn(a,s)}function en(t,e,n,i,r,s){const o=function(t){const e=new Set,n=new Set;for(const i of t)"insert"===i.kind||"update"===i.kind?e.add(i.index):"replace"===i.kind&&(e.add(i.index),n.add(i.index));return{renders:e,replaces:n}}(n),a=function(t,e,n,i,r,s,o){const a=Array.from(t.children),l=cn(a,Ye),u=new Set,c=[];for(let d=0;d<n.length;d+=1){const h=n[d],f=un(h);let p=void 0===f?a[d]??null:dn(l,f)??null;null!==p&&u.has(p)&&(p=null),null!==p&&u.add(p);const g=i.replaces.has(d),m=r||i.renders.has(d)||null===p?hn(t.ownerDocument,e,h,d):void 0;if(null===m)return null;const v=void 0===m?[]:rn(g?null:p,m,h,s,o);if(null===v)return null;c.push([d,p,m??void 0,v])}return c}(t,e,i,o,r,s.get(t),s);return null===a?null:[t,a,i]}function nn(t,e){const[n,i,r]=t,s=new Set;let o=!1;for(const t of i){const[i,r,a,l]=t;let u=r;if(void 0!==a){for(const t of l)null!==t[0]&&(on(t[0],t[1]),t[1].replaceWith(t[0])),void 0!==t[2]&&nn(t[2],e);null!==r&&(r.replaceWith(a),o=!0),u=a}if(null===u)continue;const c=n.children[i]??null;u!==c&&(n.insertBefore(u,c),o=!0),s.add(u)}for(const t of Array.from(n.children))s.has(t)||(t.remove(),o=!0);const a=function(t,e){let n=e.get(t);return n||(n=new Map,e.set(t,n)),n}(n,e);a.clear();for(const t of r)ln(a,t);return o}function rn(t,e,n,i,r){const s=cn(null===t?[]:sn(t),Ke),o=un(n),a=void 0!==o?i?.get(o):void 0,l=[];for(const t of sn(e)){const e=t.getAttribute(Ke);if(null===e)continue;const i=dn(s,e)??null,o=t.getAttribute(Ze),u=o?i:null,c=u?.getAttribute(Ze)??null;let d;if(o){const i=an(n,e);if(void 0!==i||null!==u){const n=i??[],s=gt(null===u?[]:an(a,e)??[],n),l=null!==u&&c!==o;if((s.length>0||l)&&(d=en(u??t,o,s,n,l,r)??void 0,void 0===d))return null}}l.push([u,t,d])}return l}function sn(t){return Array.from(t.querySelectorAll(`[${Ke}]`)).filter(e=>{let n=e.parentElement;for(;null!==n&&n!==t;){if(n.hasAttribute(Ke))return!1;n=n.parentElement}return n===t})}function on(t,e){for(const n of Array.from(t.attributes))e.hasAttribute(n.name)||t.removeAttribute(n.name);for(const n of Array.from(e.attributes))t.getAttribute(n.name)!==n.value&&t.setAttribute(n.name,n.value)}function an(t,e){if("object"!=typeof t||null===t)return;const n=t[e];return Array.isArray(n)?n:void 0}function ln(t,e){const n=un(e);void 0!==n&&t.set(n,e)}function un(t){if("object"!=typeof t||null===t)return;const e=t.id;return"string"==typeof e||"number"==typeof e?String(e):void 0}function cn(t,e){const n=new Map;for(let i=t.length-1;i>=0;i-=1){const r=t[i];if(void 0===r)continue;const s=r.getAttribute(e);if(null===s)continue;const o=n.get(s);void 0===o?n.set(s,[r]):o.push(r)}return n}function dn(t,e){return t.get(e)?.pop()}function hn(t,e,n,i){const r=function(t,e,n){return qe(t,e,n,Te)}(e,n,i),s=sanitizeHtml(r),o=t.createElement("template");o.innerHTML=s;const a=o.content.firstElementChild;if(!a)return null;const l=un(n);return void 0!==l&&a.setAttribute(Ye,l),a}function fn(){const t=new WeakMap,e=new WeakSet,n=new WeakMap;return{name:"structural-array",render:Z((i,r)=>{if(!Array.isArray(r))return!1;const s=i.element,o=i.arrayTemplate;if(void 0===o||0===o.length)return function(t,e,n){t.has(e)||(t.add(e),D(`[live-preview] Skipping structural update for "${n}": <${e.tagName.toLowerCase()} data-payload-structural> needs data-payload-array-template (for example "<li>{{label}}</li>").`))}(e,s,i.fieldName),!1;const a=t.get(s),l=pn(s),u=gt(a?.values??l.map((t,e)=>null===t?{__payloadDomPosition:e}:{id:t}),r),c=function(t,e,n){return void 0===t||t.template!==e||!function(t,e){return t.length===e.length&&t.every((t,n)=>t===e[n])}(t.domSnapshot,n)}(a,o,l);if(0===u.length&&!c)return t.set(s,{values:r.slice(),template:o,domSnapshot:l}),!1;const d=tn({template:o,container:s,patches:u,nextItems:r,store:n,forceRender:c});return null!==d&&(t.set(s,{values:r.slice(),template:o,domSnapshot:pn(s)}),!!d&&void 0)})}}function pn(t){return Array.from(t.children,t=>t.getAttribute(Ye))}var gn,mn=new Map,vn=[$e,xe,Ne,Re,{...Re,name:"email"},Me,Ie,Oe,Pe,{...Pe,name:"radio"},Fe,Ge,_e,Je,{...Je,name:"blocks"}],yn=class{#Lt=new xt;#Ft;#jt;#Ht;#bt;#at;#Dt=!1;#zt=!1;#Wt=null;constructor(t={}){const e=t.debug??isDevMode();this.#at=e?(...t)=>{z("[live-preview]",...t)}:j,this.#Ft=new Ot({...void 0!==t.allowedOrigins?{additionalOrigins:t.allowedOrigins}:{},...void 0!==t.disableReferrerDetection?{enableReferrerDetection:!t.disableReferrerDetection}:{},...void 0!==t.disableLocalhostMatching?{enableLocalhostMatching:!t.disableLocalhostMatching}:{}}),this.#Ft.isProductionUnconfigured&&this.#at("no trusted origin could be detected — set allowedOrigins or PAYLOAD_ADMIN_ORIGIN"),this.#jt=new zt(function(t=[]){const e={};for(const n of t)e[n.name]=n;for(const[t,n]of mn)e[t]=n;return Object.freeze(e)}([Ce(),...vn,fn()])),this.#bt=new Dt({events:this.#Lt,config:Object.freeze({...t}),registerFieldRenderer:t=>this.#jt.register(t),onTransformError:t=>{this.#Lt.emit("error",{error:t,context:"transform"})},log:this.#at}),this.#Ht=new bt({...void 0!==t.root?{root:t.root}:{},renderers:this.#jt.renderers,resolveRenderer:t=>this.#jt.resolve(t),transformValue:(t,e,n,i)=>this.#bt.applyTransforms(t,e,n,i),originMatcher:t=>this.#Ft.matches(t),readyTargets:this.#Ft.enumerate(),emitter:this.#Lt,...void 0!==t.serverURL&&""!==t.serverURL?{dataMerge:{serverURL:t.serverURL,...void 0!==t.apiRoute?{apiRoute:t.apiRoute}:{},...void 0!==t.mergeDepth?{depth:t.mergeDepth}:{},...void 0!==t.mergeFetch?{fetchFn:t.mergeFetch}:{}}}:{},...void 0!==t.debounceMs?{debounceMs:t.debounceMs}:{},...void 0!==t.heartbeatMs?{heartbeatMs:t.heartbeatMs}:{},...void 0!==t.intersectionRootMargin?{intersectionRootMargin:t.intersectionRootMargin}:{},...void 0!==t.scopeBindingsByOwner?{scopeBindingsByOwner:t.scopeBindingsByOwner}:{},...void 0!==t.disableVisibilityGate?{disableVisibilityGate:t.disableVisibilityGate}:{},...void 0!==t.visibilityGateThreshold?{visibilityGateThreshold:t.visibilityGateThreshold}:{},...void 0!==t.enableA11y?{enableA11y:t.enableA11y}:{},...void 0!==t.a11yLocale?{a11yLocale:t.a11yLocale}:{},onHeartbeatTimeout:()=>{this.#Ft.unlockOrigin()},...void 0!==t.validateToken?{validateToken:t.validateToken}:{},log:this.#at}),this.#Lt.on("connect",t=>{this.#Ft.lockOrigin(t.origin)}),!1!==t.autoStart&&this.start()}start(){if(this.#zt)return!1;if(this.#Dt)return this.#Ht.start(),!0;if(!isInPreviewContext())return!1;const t=this.#Ht.start();return t&&(this.#Dt=!0),t}destroy(){if(null!==this.#Wt)return this.#Wt;let t,e;this.#zt=!0;const n=new Promise((n,i)=>{t=n,e=i});this.#Wt=n;try{this.#Ht.destroy(),this.#bt.destroyAll().finally(()=>{this.#Lt.removeAllListeners()}).then(t,e)}catch(t){this.#Lt.removeAllListeners(),e(t)}return n}async use(t){if(this.#zt)throw new Error("LivePreviewClient: already destroyed");await this.#bt.register(t)}async unuse(t){await this.#bt.unregister(t)}refreshCache(){this.#Ht.refreshCache()}get events(){return this.#Lt}get plugins(){return this.#bt.list()}get status(){return this.#Ht.status}get updateCount(){return this.#Ht.updateCount}get destroyed(){return this.#zt}};function bind(t,e){return bn(t,e)}function bindByPath(t,e){const n=function(t){const e=[],n=new Proxy({},{get(t,i){if("symbol"!=typeof i)return/^\d+$/.test(i)||e.push(i),n}});try{t(n)}catch{}return e}(t);if(0===n.length)throw new Error("bindByPath: the picker did not read any field — return data.<field> instead of a constant");return bn(n.join("."),e)}function bn(t,e){if(0===t.length)throw new Error("bind: field name must be a non-empty string");const n={"data-payload-field":t};return void 0!==e?.attribute&&(n["data-payload-attribute"]=e.attribute),void 0!==e?.type&&(n["data-payload-type"]=e.type),!0===e?.richtext&&(n["data-payload-richtext"]=""),!0===e?.html&&(n["data-payload-html"]=""),void 0!==e?.locale&&(n["data-payload-locale"]=e.locale),n}var wn=Object.freeze({});for(const[t,e]of[[xt,"EventEmitter"],[yn,"LivePreviewClient"],[Ot,"OriginDetector"]])Object.defineProperty(t,"name",{configurable:!0,value:e});exports.CORE_ENTRY=!0,exports.EventEmitter=xt,exports.LIBRARY_PROTOCOL_VERSION=4,exports.LivePreviewClient=yn,exports.OriginDetector=Ot,exports.VERSION="1.2.2",exports.bind=bind,exports.bindByPath=bindByPath,exports.buildFrameAncestors=function buildFrameAncestors(t={}){const{self:e=!0,origins:n=[],allowNone:i=!1}=t,r=new Set,s=[];if(i&&!e&&0===n.length)return"'none'";e&&(s.push("'self'"),r.add("'self'"));for(const t of n){const e=t.trim();0===e.length||r.has(e)||(r.add(e),s.push(e))}return s.length>0?s.join(" "):"'none'"},exports.buildScriptSrcWithNonce=function buildScriptSrcWithNonce(t,e={}){if(0===t.length)throw new RangeError("buildScriptSrcWithNonce: nonce is empty");const{self:n=!0,extra:i=[],strictDynamic:r=!1}=e,s=[];n&&s.push("'self'"),s.push(`'nonce-${t}'`),r&&s.push("'strict-dynamic'");for(const t of i){const e=t.trim();e.length>0&&s.push(e)}return s.join(" ")},exports.createPreviewBindings=function createPreviewBindings(t){const{authorized:e}=t,n=void 0!==t.owner&&t.owner.length>0?t.owner:void 0;return Object.freeze({authorized:e,bind:(t,n)=>e?bind(t,n):wn,bindByPath:(t,n)=>e?bindByPath(t,n):wn,owner:()=>e&&void 0!==n?{"data-payload-owner":n}:wn})},exports.detectInitialLocale=detectInitialLocale,exports.escapeHtml=escapeHtml,exports.escapeHtmlAttribute=escapeHtmlAttribute,exports.generateCspNonce=function generateCspNonce(t=16){if(!Number.isInteger(t)||t<8)throw new RangeError(`generateCspNonce: bytes must be an integer >= 8, got ${String(t)}`);const e=function(){if(gn?.getRandomValues)return gn;const t=globalThis.crypto;return t?.getRandomValues?t:void 0}();if(!e)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(t);return e.getRandomValues(n),function(t){let e="";for(const n of t)e+=String.fromCharCode(n);return("function"==typeof btoa?btoa(e):Buffer.from(t).toString("base64")).replaceAll("+","-").replaceAll("/","_").replaceAll("=","")}(n)},exports.hasCapability=function hasCapability(t,e){return t.capabilities.has(e)},exports.initLivePreview=function initLivePreview(t={}){const e=new yn({...t,autoStart:!1});return e.start()?e:null},exports.isDevMode=isDevMode,exports.isExternalHttpUrl=isExternalHttpUrl,exports.isInIframe=isInIframe,exports.isInPopup=isInPopup,exports.isInPreviewContext=isInPreviewContext,exports.isSafeUrl=isSafeUrl,exports.negotiateProtocol=negotiateProtocol,exports.sanitizeHtml=sanitizeHtml,exports.setCspCrypto=function setCspCrypto(t){gn=t??void 0},exports.setSanitizerDocument=function setSanitizerDocument(t){Lt=t??void 0};
1
+ "use strict";var t="data-payload-field",e="data-payload-type",n="data-payload-attribute",i="data-payload-href",r="data-payload-src",s="data-payload-alt",o="data-payload-array-template",a="data-payload-array-separator",l="data-payload-locale",u="data-payload-richtext",c="data-payload-html",d="data-payload-array",h="data-payload-structural",f="data-payload-owner",p=[t,e,n,i,r,s,o,a,l,u,c,d,h,f,"type"],g=`[${t}]`,m=`[${f}]`,v=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"]),y=class{#t=new Map;#e=new WeakMap;#n;constructor(t={}){this.#n=t.filter??b}buildFromRoot(t){const e=performance.now();this.clear();const n=t.querySelectorAll(g);let i=0;for(const t of n)void 0!==this.add(t)&&(i+=1);return{elementCount:i,fieldCount:this.#t.size,durationMs:performance.now()-e}}add(t){const e=this.#n(t)?this.#i(t):void 0,n=this.#e.get(t);if(void 0!==e)return void 0!==n&&this.#r(n,e)?(this.#e.set(t,e),e):(void 0!==n&&this.#s(t,n),this.#o(e),this.#e.set(t,e),e);void 0!==n&&this.#s(t,n)}remove(t){const e=this.#e.get(t);return!!e&&this.#s(t,e)}#r(t,e){if(t.fieldName!==e.fieldName)return!1;const n=this.#t.get(t.fieldName);if(!n)return!1;const i=n.indexOf(t);return!(i<0||(n[i]=e,0))}#s(t,e){const n=this.#t.get(e.fieldName);if(!n)return this.#e.delete(t),!1;const i=n.indexOf(e);return i<0?(this.#e.delete(t),!1):(n.splice(i,1),0===n.length&&this.#t.delete(e.fieldName),this.#e.delete(t),!0)}get(t){return this.#t.get(t)}getByElement(t){return this.#e.get(t)}get fieldCount(){return this.#t.size}get elementCount(){let t=0;for(const e of this.#t.values())t+=e.length;return t}entries(){return this.#t.entries()}*values(){for(const t of this.#t.values())yield*t}has(t){return this.#e.has(t)}clear(){this.#t.clear(),this.#e=new WeakMap}#o(t){const e=this.#t.get(t.fieldName);e?e.push(t):this.#t.set(t.fieldName,[t])}#i(p){const g=p.getAttribute(t);if(null===g||0===g.length)return;const y=p.getAttribute(e),b=function(t){const n=t.getAttribute(e);if(null!==n&&v.has(n))return n;if(t.hasAttribute(u))return"richText";if(t.hasAttribute(c))return"html";if(t.hasAttribute(h))return"structural-array";if(t.hasAttribute(d))return"array";if("IMG"===t.tagName)return"image";if("A"===t.tagName)return"url";if("TIME"===t.tagName)return"date";if("INPUT"===t.tagName){const e=t.type;if("checkbox"===e)return"checkbox";if("number"===e)return"number";if("date"===e||"datetime-local"===e)return"date"}return"text"}(p),w=p.getAttribute(n),S=p.getAttribute(i),A=p.getAttribute(r),k=p.getAttribute(s),C=p.getAttribute(o),T=p.getAttribute(a),$=p.getAttribute(l),x=function(t){const e=t.closest(m)?.getAttribute(f);return null==e||0===e.length?void 0:e}(p);return{element:p,fieldName:g,fieldType:b,explicitFieldType:null!==y&&v.has(y),...null!==w&&w.length>0?{targetAttribute:w}:{},...null!==S&&S.length>0?{hrefField:S}:{},...null!==A&&A.length>0?{srcField:A}:{},...null!==k&&k.length>0?{altField:k}:{},...null!==C?{arrayTemplate:C}:{},...null!==T?{arraySeparator:T}:{},...null!==$&&$.length>0?{locale:$}:{},...void 0!==x?{owner:x}:{}}}};function b(){return!0}function w(t,e){return void 0===e||""===e?`collection:${t}`:`collection:${t}:${e}`}function S(t){return"string"==typeof t&&t.length>0}function A(t,e){return null!==e&&void 0!==t&&e.includes(t)}function k(t){const e=t.id;return"string"==typeof e&&e.length>0?e:"number"==typeof e&&Number.isFinite(e)?String(e):void 0}var C=class{s;constructor(t,e={}){this.s=[t,e.mutationDebounceMs??100,e.intersectionRootMargin??"200px",new Set,null,null,null,0]}start(t){const e=this.s[7];this.stop();const n=e+1;if(this.s[7]!==n)return;let i=null,r=null;try{i=new MutationObserver(t=>{this.#a(t,n)}),r=new IntersectionObserver(t=>{this.#l(t,n)},{rootMargin:this.s[2],threshold:0}),i.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[...p]})}catch(t){throw i?.disconnect(),r?.disconnect(),t}if(this.s[7]!==n)return i.disconnect(),void r.disconnect();this.s[4]=i,this.s[5]=r}observeElement(t){this.s[5]?.observe(t)}unobserveElement(t){this.s[5]?.unobserve(t),this.s[3].delete(t)}markVisible(t,e){e?this.s[3].add(t):this.s[3].delete(t)}isVisible(t){return this.s[3].has(t)}stop(){this.s[7]+=1;const t=this.s[6],e=this.s[4],n=this.s[5];this.s[6]=null,this.s[4]=null,this.s[5]=null,this.s[3].clear(),null!==t&&clearTimeout(t);try{e?.disconnect()}finally{n?.disconnect()}}#a(e,n){if(!this.#u(n))return;if(!function(e){for(const n of e){if("attributes"===n.type&&null!==n.attributeName&&p.includes(n.attributeName)&&(n.attributeName===t||n.attributeName===f||1===n.target.nodeType&&n.target.hasAttribute(t)))return!0;for(const t of n.addedNodes)if(T(t))return!0;for(const t of n.removedNodes)if(T(t))return!0}return!1}(e))return;if(!this.#u(n))return;null!==this.s[6]&&clearTimeout(this.s[6]);const i=setTimeout(()=>{this.#u(n)&&this.s[6]===i&&(this.s[6]=null,this.s[0].onStructuralChange())},this.s[1]);this.s[6]=i}#l(t,e){for(const n of t){if(!this.#u(e))return;const t=n.target;if(n.isIntersecting){if(!this.s[3].has(t)&&(this.s[3].add(t),this.s[0].onVisibilityChange(t,!0),!this.#u(e)))return}else if(this.s[3].has(t)&&(this.s[3].delete(t),this.s[0].onVisibilityChange(t,!1),!this.#u(e)))return}}#u(t){return this.s[7]===t&&null!==this.s[5]}};function T(e){if(1!==e.nodeType)return!1;const n=e;return!!n.hasAttribute(t)||null!==n.querySelector(`[${t}]`)}function $(t){if(!Array.isArray(t))return[];const e=[];for(const n of t){const t=x(n);t&&e.push(t)}return e}function x(t){if("object"!=typeof t||null===t)return;const e=t,n=e.name,i=e.type;if("string"!=typeof n||0===n.length)return;if("string"!=typeof i||0===i.length)return;const r=$(e.fields),s=function(t){if(!Array.isArray(t))return[];const e=[];for(const n of t){if("object"!=typeof n||null===n)continue;const t=n,i=t.slug;if("string"!=typeof i||0===i.length)continue;const r=$(t.fields);e.push({...t,slug:i,fields:r})}return e}(e.blocks),o={...e,name:n,type:i};return r.length>0?o.fields=r:delete o.fields,s.length>0?o.blocks=s:delete o.blocks,o}var N={basic:1,"schema-json":2,"preview-token":3,"nested-arrays":4,"recursive-diffs":4};function negotiateProtocol(t){const e="number"==typeof t&&Number.isFinite(t)&&t>=1?Math.floor(t):void 0,n=e??1,i=Math.min(4,n),r=new Set;for(const[t,e]of Object.entries(N))i>=e&&r.add(t);return{ours:4,...void 0!==e?{theirs:e}:{theirs:void 0},negotiated:i,capabilities:r}}function R(t){return("object"==typeof t&&null!==t||"function"==typeof t)&&"function"==typeof t.then&&(Promise.resolve(t).catch(()=>{}),!0)}var M=class{s;constructor(t,e){this.s=[t,e,void 0,void 0,0,0,[],0]}attach(t=window){if(void 0!==this.s[3])return;let e=!1;const n=t=>{if(!e||this.s[2]!==n)return;const i=this.s[4];try{this.#c(t,i)}catch{let e="";try{e=t.origin}catch{}this.#d("shape",e,i)}};this.s[4]+=1,this.#h(),this.s[3]=t,this.s[2]=n;try{t.addEventListener("message",n)}catch(e){this.s[2]===n&&(this.s[3]=void 0,this.s[2]=void 0,this.#h());try{t.removeEventListener("message",n)}catch{}throw e}if(this.s[2]===n)e=!0;else try{t.removeEventListener("message",n)}catch{}}detach(t){const e=this.s[3],n=this.s[2];void 0!==e&&void 0!==n&&(this.s[3]=void 0,this.s[2]=void 0,this.#h(),e.removeEventListener("message",n))}advanceGeneration(){return void 0!==this.s[3]&&(this.s[4]+=1,this.#h(),!0)}static sendReady(t,e){const n=t.length>0;if(!n||0===e.length)return;const i={type:"payload-live-preview",ready:n,protocolVersion:4};for(const n of t)for(const t of e)try{n.postMessage(i,t)}catch{}}#c(t,e){if(!this.#u(e))return;const n=t.origin;if(!this.#u(e))return;if(!this.#f(n,e))return void this.#d("origin",n,e);const i=t.data;if(!this.#u(e))return;const r="object"==typeof(s=i)&&null!==s&&"type"in s&&"string"==typeof s.type;var s;if(!this.#u(e))return;if(!r)return void this.#d("shape",n,e);const o=i.type;if(this.#u(e))switch(o){case"payload-live-preview":{const t=function(t){const e=t;return!!((void 0===e.data||null===e.data||O(e.data))&&I(e.fieldSchemaJSON,t=>Array.isArray(t))&&I(e.globalSlug,t=>"string"==typeof t)&&I(e.collectionSlug,t=>"string"==typeof t)&&I(e.locale,t=>"string"==typeof t)&&I(e.ready,t=>"boolean"==typeof t)&&I(e.previewToken,t=>"string"==typeof t)&&I(e.protocolVersion,t=>"number"==typeof t))}(i);if(!this.#u(e))return;if(!t)return void this.#d("shape",n,e);const r=function(t){const e={...t};for(const t of U)null===Reflect.get(e,t)&&Reflect.deleteProperty(e,t);if(!Array.isArray(e.fieldSchemaJSON))return e;let n;try{n=$(e.fieldSchemaJSON)}catch{n=[]}return{...e,fieldSchemaJSON:n}}(i);if(!this.#u(e))return;return void this.#p(r,n,e)}case"payload-document-event":{const t=function(t){const e=t;return!!E(e.action,t=>"updated"===t||"created"===t||"deleted"===t)&&!!E(e.slug,t=>"string"==typeof t)&&!!E(e.id,t=>"string"==typeof t||"number"==typeof t&&Number.isFinite(t))}(i);if(!this.#u(e))return;if(!t)return void this.#d("shape",n,e);let r;try{r=this.s[1].onDocumentEvent}catch{return}if(!this.#u(e))return;return void this.#g(r,i,n)}default:this.#d("type",n,e)}}#p(t,e,n){if(!this.#u(n))return;const i=t.data;if(!this.#u(n))return;const r=O(i);if(!this.#u(n))return;const s=r?{generation:n,revision:this.s[5]+=1}:void 0;let o;try{o=this.s[1].validateToken}catch{return}if(!this.#u(n))return;if(void 0===o)return void this.#m(t,e,n,s);if(!0===t.ready&&void 0===i)return void this.#m(t,e,n,void 0);const a={generation:n,message:t,origin:e,messageRevision:s,settled:!1,approved:!1};let l;this.s[6].push(a);try{l=o(t.previewToken,e)}catch{return void this.#v(a,!1)}"boolean"!=typeof l?Promise.resolve(l).then(t=>{this.#v(a,!0===t)},()=>{this.#v(a,!1)}):this.#v(a,l)}#v(t,e){this.#u(t.generation)&&(t.approved=e,t.settled=!0,this.#y(t.generation))}#y(t){for(;this.#u(t);){const e=this.s[6][this.s[7]];if(void 0===e)return;if(this.#f(e.origin,t)){if(!e.settled)return;this.#b(e)&&(e.approved?this.#m(e.message,e.origin,e.generation,e.messageRevision):this.#d("token",e.origin,e.generation))}else{if(!this.#b(e))continue;this.#d("origin",e.origin,e.generation)}}}#m(t,e,n,i){if(!this.#u(n))return;let r;try{r=this.s[1].onUpdate}catch{return}this.#u(n)&&(void 0===i?this.#g(r,t,e):this.#g(r,t,e,i))}#d(t,e,n){if(!this.#u(n))return;let i;try{i=this.s[1].onInvalid}catch{return}this.#u(n)&&void 0!==i&&this.#g(i,t,e)}#f(t,e){if(!this.#u(e))return!1;try{return!0===this.s[0](t)&&this.#u(e)}catch{return!1}}#g(t,...e){try{R(t(...e))}catch{}}#u(t){return void 0!==this.s[3]&&this.s[4]===t}#b(t){const e=this.s;return e[6][e[7]]===t&&(e[7]+=1,e[7]===e[6].length?(this.#h(),!0):(e[7]>=1024&&2*e[7]>=e[6].length&&(e[6]=e[6].slice(e[7]),e[7]=0),!0))}#h(){this.s[6]=[],this.s[7]=0}};function E(t,e){return void 0===t||e(t)}function I(t,e){return null==t||e(t)}function O(t){if("object"!=typeof t||null===t)return!1;const e=Object.getPrototypeOf(t);return null===e||null===Object.getPrototypeOf(e)}var U=["data","fieldSchemaJSON","globalSlug","collectionSlug","locale","ready","previewToken","protocolVersion"],P=class{s;constructor(t){this.s=[t.timeoutMs??0,t.onTimeout,null,0]}kick(){if(this.s[3]=Date.now(),this.s[0]<=0)return;null!==this.s[2]&&clearTimeout(this.s[2]);const t=setTimeout(()=>{this.s[2]===t&&(this.s[2]=null,this.s[1]())},this.s[0]);this.s[2]=t}stop(){null!==this.s[2]&&(clearTimeout(this.s[2]),this.s[2]=null)}get lastKickAt(){return this.s[3]}get pending(){return null!==this.s[2]}},L=class{s;constructor(t){this.s=["disconnected",t]}get status(){return this.s[0]}markConnected(){return this.transition("connected")}markConnecting(){return this.transition("connecting")}markDisconnected(){return this.transition("disconnected")}transition(t){if(this.s[0]===t)return!1;const e=this.s[0];return this.s[0]=t,this.s[1](t,e),!0}};function F(t){return(...e)=>{try{R(t(...e))}catch{}}}function j(){}var D=F((...t)=>console.error(...t)),H=F((...t)=>console.warn(...t)),z=F((...t)=>console.debug(...t));function W(t){for(const e of t){const t=e.codePointAt(0);if(void 0!==t&&(t<=31||127===t))return!0}return!1}function G(t){if(void 0===t||0===t.length||t.length>128||"."===t||".."===t||t.includes("/")||t.includes("\\")||t.includes("?")||t.includes("#")||W(t))return!1;try{return encodeURIComponent(t),!0}catch{return!1}}var V=class{s;constructor(t){const e=t.serverURL.replace(/\/+$/,""),n=t.apiRoute??"/api";this.s=[e,n.startsWith("/")?n:`/${n}`,t.depth??1,t.fetchFn,void 0===t.log?j:F(t.log),null,0,0]}canMerge(t){try{return t.globalSlug?G(t.globalSlug):!!G(t.collectionSlug)&&function(t){if("number"==typeof t)return Number.isFinite(t);if("string"!=typeof t||0===t.length||t.length>512||"."===t||".."===t||t.includes("/")||t.includes("\\")||W(t))return!1;try{return encodeURIComponent(t),!0}catch{return!1}}(t.data.id)}catch{return!1}}async merge(t){if(this.s[7]>0)return{status:"superseded"};const e=this.s[6]+1;this.s[6]=e;const n=this.s[5];this.s[5]=null;let i=null;try{if(n?.abort(),!_(this.s,e))return{status:"superseded"};if(!this.canMerge(t))return _(this.s,e)?{status:"unavailable"}:{status:"superseded"};if(!_(this.s,e))return{status:"superseded"};const r=this.s[3]??("function"==typeof fetch?fetch:void 0);if(!_(this.s,e))return{status:"superseded"};if(void 0===r)return{status:"unavailable"};if(i=new AbortController,!_(this.s,e))return i.abort(),{status:"superseded"};this.s[5]=i;const s=t.globalSlug?`globals/${encodeURIComponent(t.globalSlug)}`:`${encodeURIComponent(t.collectionSlug??"")}/${encodeURIComponent(String(t.data.id))}`,o=`${this.s[0]}${this.s[1]}/${s}`,a=JSON.stringify({data:t.data,depth:this.s[2],flattenLocales:!1,...void 0!==t.locale?{locale:t.locale}:{}});if(!_(this.s,e))return{status:"superseded"};const l=await r(o,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json","X-Payload-HTTP-Method-Override":"GET"},body:a,signal:i.signal});if(!_(this.s,e)||B(i.signal))return{status:"superseded"};const u=l.ok;if(!_(this.s,e))return{status:"superseded"};if(!u){const t=l.status;return _(this.s,e)?(this.s[4]("merge HTTP",t,o),_(this.s,e)?{status:"unavailable"}:{status:"superseded"}):{status:"superseded"}}const c=await l.json();return!_(this.s,e)||B(i.signal)?{status:"superseded"}:null===c||"object"!=typeof c||Array.isArray(c)?(this.s[4]("merge invalid",o),_(this.s,e)?{status:"unavailable"}:{status:"superseded"}):{status:"merged",doc:c}}catch(t){return!_(this.s,e)||null!==i&&B(i.signal)?{status:"superseded"}:(this.s[4]("merge exception",t),_(this.s,e)?{status:"unavailable"}:{status:"superseded"})}finally{null!==i&&_(this.s,e)&&this.s[5]===i&&(this.s[5]=null)}}destroy(){this.s[6]+=1;const t=this.s[5];this.s[5]=null,this.s[7]+=1;try{t?.abort()}finally{this.s[7]-=1}}};function _(t,e){return t[6]===e}function B(t){return t.aborted}var q=new Set(["http:","https:","mailto:","tel:"]),J=/^\s*(?:javascript|data|vbscript|file|blob|about)\s*:/i,Q=/^(?:\.{1,2}\/|[a-zA-Z0-9_-]+\/?)/;function isSafeUrl(t){if("string"!=typeof t||0===t.length)return!1;const e=t.trim();if(0===e.length)return!1;if(J.test(e))return!1;if(e.startsWith("#")||e.startsWith("?"))return!0;if(e.startsWith("//"))return!0;if(e.startsWith("/"))return!0;try{const t=new URL(e);return q.has(t.protocol)}catch{return Q.test(e)}}function isExternalHttpUrl(t){if(!isSafeUrl(t))return!1;const e=t.trim();return/^https?:\/\//i.test(e)||/^\/\/[^/]/.test(e)}var X=new Set(["style","srcdoc","formaction","form","id","name","is","srcset","imagesrcset"]),Y=new Set(["href","src","poster","cite","action","xlink:href","data"]),K=new WeakSet;function Z(t){return K.add(t),t}var tt=class{s;constructor(t,e){const n=e.scheduleFrame??("function"==typeof requestAnimationFrame?requestAnimationFrame.bind(globalThis):t=>setTimeout(()=>{t(performance.now())},0)),i=e.cancelFrame??("function"==typeof cancelAnimationFrame?cancelAnimationFrame.bind(globalThis):t=>{clearTimeout(t)});this.s=[t,e.debounceMs??50,e.isVisible,e.visibilityGateThreshold??50,e.disableVisibilityGate??!1,e.getCacheSize,e.onFlush,n,i,new Map,new Map,new Set,null,0,null,0,null,!1]}schedule(t){if(void 0!==t.identity){if(this.s[17])return;if(!et(t.identity,this.s[16]))return}const e=this.s[9],n=e.get(t.target.element);n?(n.value=t.value,n.allFields=t.allFields,n.identity=t.identity,n.data=t.data):e.set(t.target.element,{...t,identity:t.identity,data:t.data}),this.#w()}acceptRevision(t){const e=this.s[16];var n,i;et(t,e)||null!==e&&(i=e,((n=t).generation!==i.generation?n.generation-i.generation:n.revision-i.revision)<0)||(this.#S(),this.#A(),this.s[16]=t,this.s[17]=!1)}cancelRevision(t){et(t,this.s[16])&&(this.#S(),this.#A(),this.s[17]=!0)}flushNow(){return this.#S(),this.#k()}notifyVisible(t){const e=this.s[10],n=e.get(t);if(!n)return;if(e.delete(t),!this.#C(n))return;const i=performance.now(),r=this.#T(n)?1:0;this.s[6]?.(this.#$(n,r,0,performance.now()-i))}retarget(t){this.#x(this.s[9],t),this.#x(this.s[10],t);for(const e of this.s[11])this.#x(e,t)}forget(t){this.s[9].delete(t),this.s[10].delete(t);for(const e of this.s[11])e.delete(t)}destroy(){this.#S(),this.#A(),this.s[16]=null,this.s[17]=!1}get pendingCount(){return this.s[9].size}get replayCount(){return this.s[10].size}#w(){const t=this.s[13]+=1,e=this.s[12];if(this.s[12]=null,null!==e&&clearTimeout(e),this.s[13]!==t)return;const n=setTimeout(()=>{this.s[13]===t&&(this.s[12]=null,this.#N())},this.s[1]);this.s[13]===t&&(this.s[12]=n)}#N(){const t=this.s[15]+=1,e=this.s[14];if(this.s[14]=null,null!==e&&this.s[8](e),this.s[15]!==t)return;let n=!1;const i=this.s[7](()=>{this.s[15]===t&&(n=!0,this.s[14]=null,this.#k())});n||this.s[15]!==t||(this.s[14]=i)}#k(){const t=performance.now(),e=!this.s[4]&&this.s[5]()>this.s[3],n=this.s[9];this.s[9]=new Map;let i,r=0,s=0;this.s[11].add(n);try{for(const t of n.values()){if(!this.#C(t))continue;const n=!e||this.s[2](t.target.element);this.#C(t)&&(i??=t,n?(this.s[10].delete(t.target.element),this.#T(t)&&(r+=1)):(this.s[10].set(t.target.element,t),s+=1))}}finally{this.s[11].delete(n)}const o=this.#$(i,r,s,performance.now()-t);return this.s[6]?.(o),o}#C(t){return void 0===t.identity||!this.s[17]&&et(t.identity,this.s[16])}#T(t){const e=this.s[0];return!1!==e(t)||(n=e,!K.has(n));var n}#x(t,e){const n=t.get(e.element);void 0!==n&&(n.target.fieldName===e.fieldName&&n.target.locale===e.locale?n.target=e:t.delete(e.element))}#A(){this.s[9].clear(),this.s[10].clear();for(const t of this.s[11])t.clear()}#$(t,e,n,i){return{applied:e,deferred:n,durationMs:i,...void 0!==t?.identity?{identity:t.identity}:{},...void 0!==t?.data?{data:t.data}:{}}}#S(){const t=this.s[12],e=this.s[14];this.s[13]+=1,this.s[15]+=1,this.s[12]=null,this.s[14]=null,null!==t&&clearTimeout(t),null!==e&&this.s[8](e)}};function et(t,e){return null!==e&&t.generation===e.generation&&t.revision===e.revision}var nt=new Set(["__proto__","prototype","constructor"]);function it(t,e,n,i=!1){if(i&&void 0!==n){const i=rt(t,`${e}_${n}`);if(void 0!==i)return i}const r=rt(t,e);if(void 0!==r)return r;if(e.includes(".")){let n=t,i=!0;for(const t of e.split(".")){if(nt.has(t)||null===n||"object"!=typeof n){i=!1;break}if(n=rt(n,t),void 0===n){i=!1;break}}if(i)return n}return void 0===n?void 0:rt(t,`${e}_${n}`)}function rt(t,e){if(!nt.has(e)&&Object.prototype.hasOwnProperty.call(t,e))return t[e]}function detectInitialLocale(){const t=function(){if("undefined"==typeof document)return;const t=document.documentElement.getAttribute("lang");return null===t||0===t.length?void 0:t}();if(void 0!==t)return t;const e=function(){if("undefined"==typeof navigator)return;const t=navigator.language;return"string"==typeof t&&t.length>0?t:void 0}();return void 0!==e?e:"en"}var st="payload-live-preview-a11y";function ot(t){return/^de(?:[-_]|$)/i.test(t)}var at=new WeakMap;function lt(t){null!==t[4]&&(clearTimeout(t[4]),t[4]=null),t[2]?.remove(),t[2]=null}var ut=class{s;constructor(t,e){const n=e??("undefined"==typeof document?null:document),i=n?.documentElement.getAttribute("lang")??"";this.s=[ot(t??(i.length>0?i:detectInitialLocale())),n,null]}mount(){const t=this.s[1];if(null==t?.body)return null;let e=this.s[2];null===e&&(e=function(t){let e=at.get(t);return e??=[null,!1,null,0,null],at.set(t,e),e[3]+=1,e}(t),this.s[2]=e);const n=e[0];if(n?.isConnected&&n.ownerDocument===t)return n;if(null!==n){const t=e[1];lt(e),t&&n.remove()}let i=t.getElementById(st);return e[1]=null===i,i||(i=t.createElement("div"),i.id=st,i.setAttribute("role","status"),i.setAttribute("aria-live","polite"),i.setAttribute("aria-atomic","true"),i.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"),t.body.appendChild(i)),e[0]=i,i}announceConnected(){this.say(this.s[0]?"Vorschau verbunden":"Live preview connected")}announceDisconnected(){this.say(this.s[0]?"Vorschau getrennt":"Live preview disconnected")}announceUpdate(t){t<=0||this.say(this.s[0]?`${String(t)} ${1===t?"Änderung":"Änderungen"} angewendet`:`${String(t)} ${1===t?"change":"changes"} applied`)}detach(){const t=this.s[2],e=this.s[1];if(null===t||null===e)return;if(this.s[2]=null,t[3]-=1,t[3]>0)return;const n=t[0];null!==n&&lt(t),t[1]&&n?.remove(),t[0]=null,at.delete(e)}say(t){const e=this.mount(),n=this.s[2];if(null===e||null===n)return;let i=n[2];i?.parentNode!==e?(i?.remove(),i=e.ownerDocument.createTextNode(e.hasChildNodes()?` ${t}`:t),n[2]=i,e.appendChild(i)):i.data=null===i.previousSibling?t:` ${t}`,null!==n[4]&&clearTimeout(n[4]);const r=setTimeout(()=>{n[4]===r&&n[0]===e&&lt(n)},1500);n[4]=r}},ct=new Set(["tabs","row","collapsible"]);function dt(t,e=""){const n=new Map;return ht(t,e,n),n}function ht(t,e,n){for(const i of t){if(ct.has(i.type)){i.fields&&ht(i.fields,e,n);continue}if("group"===i.type){const t=""===e?i.name:`${e}.${i.name}`;n.set(t,i),i.fields&&ht(i.fields,t,n);continue}const t=""===e?i.name:`${e}.${i.name}`;if(n.set(t,i),"array"===i.type&&i.fields)ht(i.fields,`${t}.*`,n);else if("blocks"===i.type&&i.blocks)for(const e of i.blocks)ht(e.fields,`${t}.*.${e.slug}`,n)}}function ft(t){if("object"!=typeof t||null===t)return;const e=t.id;return"string"==typeof e||"number"==typeof e?e:void 0}function pt(t){if("object"!=typeof t||null===t)return;const e=t.blockType;return"string"==typeof e?e:void 0}function gt(t,e){return e.every(t=>void 0!==ft(t))?function(t,e){const n=[],i=new Map;for(let e=0;e<t.length;e+=1){const n=ft(t[e]);void 0!==n&&i.set(n,e)}const r=new Set;for(let s=0;s<e.length;s+=1){const o=e[s],a=ft(o);if(void 0===a){n.push({kind:"insert",index:s,value:o});continue}const l=i.get(a);if(void 0===l){n.push({kind:"insert",index:s,value:o});continue}r.add(l);const u=t[l];pt(u)===pt(o)?(l!==s&&n.push({kind:"move",from:l,to:s,value:o}),mt(u,o)||n.push({kind:"update",index:s,value:o})):n.push({kind:"replace",index:s,oldValue:u,value:o})}for(let e=0;e<t.length;e+=1)r.has(e)||n.push({kind:"remove",index:e,value:t[e]});return n}(t,e):function(t,e){const n=[],i=Math.min(t.length,e.length);for(let r=0;r<i;r+=1)mt(t[r],e[r])||n.push({kind:"update",index:r,value:e[r]});if(e.length>t.length)for(let i=t.length;i<e.length;i+=1)n.push({kind:"insert",index:i,value:e[i]});if(t.length>e.length)for(let i=e.length;i<t.length;i+=1)n.push({kind:"remove",index:i,value:t[i]});return n}(t,e)}function mt(t,e){if(Object.is(t,e))return!0;if("object"!=typeof t||"object"!=typeof e||null===t||null===e)return!1;const n=t,i=e,r=Object.keys(n),s=Object.keys(i);if(r.length!==s.length)return!1;for(const t of r)if(!Object.is(n[t],i[t]))return!1;return!0}var vt={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"},yt=[0,500,1e3,2e3],bt=class{d;l;constructor(t){const e=t.emitter,n=t.renderers,i=t.resolveRenderer??(t=>n[t]),r=t.transformValue,s=t.root??("undefined"!=typeof document?document:null),o=t.readyTargets,a=t.sendReady??St,l=t.onHeartbeatTimeout,u=void 0===t.log?j:F(t.log),c=void 0===t.warn?H:F(t.warn),d=function(t){if(!1===t.enableA11y)return null;const e=void 0===t.root?void 0:9===t.root.nodeType?t.root:t.root.ownerDocument;return new ut(t.a11yLocale,e)}(t),h=void 0!==t.dataMerge?new V({serverURL:t.dataMerge.serverURL,...void 0!==t.dataMerge.apiRoute?{apiRoute:t.dataMerge.apiRoute}:{},...void 0!==t.dataMerge.depth?{depth:t.dataMerge.depth}:{},...void 0!==t.dataMerge.fetchFn?{fetchFn:t.dataMerge.fetchFn}:{},log:(...t)=>{u(...t)}}):null,f=new y,p=new C({onStructuralChange:()=>{this.#R()},onVisibilityChange:(t,e)=>{e&&this.d[3].notifyVisible(t)}},{...void 0!==t.intersectionRootMargin?{intersectionRootMargin:t.intersectionRootMargin}:{}}),g=new tt(Z(t=>this.#M(t)),{...void 0!==t.debounceMs?{debounceMs:t.debounceMs}:{},...void 0!==t.disableVisibilityGate?{disableVisibilityGate:t.disableVisibilityGate}:{},...void 0!==t.visibilityGateThreshold?{visibilityGateThreshold:t.visibilityGateThreshold}:{},isVisible:t=>p.isVisible(t),getCacheSize:()=>f.elementCount,onFlush:t=>{this.#E(t)}}),m=new M(t.originMatcher,{onUpdate:(t,e,n)=>{this.#I(t,e,n)},onDocumentEvent:()=>{e.emit("documentSave",{timestamp:Date.now()})},onInvalid:(t,n)=>{if("token"===t){const t=new Error(`Preview token rejected (origin: ${n})`);e.emit("error",{error:t,context:"token"})}u("message rejected:",t,n)},...void 0!==t.validateToken?{validateToken:t.validateToken}:{}}),v=new L(()=>{}),b=new P({...void 0!==t.heartbeatMs?{timeoutMs:t.heartbeatMs}:{},onTimeout:()=>{this.#O()}});this.d=[e,f,p,g,m,v,b,n,i,r,s,o,a,l,u,c,[],d,h,!0===t.scopeBindingsByOwner],this.l=[void 0,void 0,void 0,negotiateProtocol(void 0),!1,null,0,null,new Set,!1,!1]}start(){if(this.l[4])return!1;this.l[4]=!0;const t=this.d[10];if(wt(t)&&"loading"===t.readyState){const e=()=>{if(this.l[4]){this.l[5]=null;try{this.#U()}catch(t){this.#P(),this.#L(t,"startup")}}};this.l[5]=e;try{t.addEventListener("DOMContentLoaded",e,{once:!0})}catch(t){throw this.#P(),t}return!0}try{return this.#U(),!0}catch(t){throw this.#P(),t}}#U(){if(!this.l[4])return;const t=wt(this.d[10])?this.d[10].body:this.d[10];if(null===t)throw new Error("LivePreviewRuntime: document.body unavailable");if(this.d[2].start(t),this.#F(),this.#j()&&(this.d[4].attach(),this.d[0].emitWhile("init",{timestamp:Date.now()},()=>this.l[4]),this.#j()))for(const t of yt){if(!this.#j())return;if(0===t){if(this.d[12](this.d[11]),!this.#j())return}else{const e=setTimeout(()=>{this.l[4]&&this.#D()},t);this.d[16].push(e)}}}suspend(){return!!this.l[4]&&(this.#H()&&this.d[0].emit("disconnect",{reason:"unload",timestamp:Date.now()}),!0)}destroy(){this.l[4]&&(this.#H()&&this.d[0].emit("disconnect",{reason:"destroy",timestamp:Date.now()}),this.d[17]?.detach(),this.d[0].emit("destroy",{timestamp:Date.now()}))}#H(){this.l[7]=null,this.l[4]=!1;const t=this.l[5];this.l[5]=null,null!==t&&wt(this.d[10])&&this.#z(()=>{this.d[10].removeEventListener("DOMContentLoaded",t)});for(const t of this.d[16])this.#z(()=>{clearTimeout(t)});return this.d[16].length=0,this.#z(()=>{this.d[6].stop()}),this.#z(()=>{this.d[4].detach()}),this.#z(()=>{this.d[2].stop()}),this.#z(()=>{this.d[3].destroy()}),this.#z(()=>{this.d[18]?.destroy()}),this.d[1].clear(),this.d[5].markDisconnected()}#P(){this.#H(),this.#z(()=>{this.d[17]?.detach()})}#z(t){try{t()}catch(t){this.d[14]("cleanup failed:",t)}}refreshCache(){this.l[4]&&this.#R()}get status(){return this.d[5].status}get cache(){return this.d[1]}get updateCount(){return this.l[6]}get protocol(){return this.l[3]}#F(){if(!this.l[4])return;const t=this.d[1].buildFromRoot(this.d[10]);if(this.d[14]("cache",t),this.#j()&&(this.d[0].emitWhile("cacheRefresh",t,()=>this.l[4]),this.#j()))for(const t of this.d[1].values()){if(!this.#j())return;this.d[2].observeElement(t.element)}}#R(){if(!this.l[4])return;const t=new Map;for(const e of this.d[1].values())t.set(e.element,e),this.d[2].unobserveElement(e.element);if(this.#F(),this.#j()){for(const e of this.d[1].values()){const n=t.get(e.element);n?.fieldName===e.fieldName?this.d[3].retarget(e):this.d[3].forget(e.element),t.delete(e.element)}for(const e of t.values())this.d[3].forget(e.element)}}#W(t){const e=negotiateProtocol(t);e.negotiated!==this.l[3].negotiated&&(this.l[3]=e,this.d[14]("protocol","ours=4",`theirs=${t}`,`negotiated=${e.negotiated}`))}#I(t,e,n){if(this.d[6].kick(),void 0===t.data)return void(void 0!==t.protocolVersion&&this.#W(t.protocolVersion));if(void 0===n)return;"string"==typeof t.locale&&(this.l[0]=t.locale),Array.isArray(t.fieldSchemaJSON)&&(this.l[1]=t.fieldSchemaJSON,this.l[2]=dt(t.fieldSchemaJSON));const i={identity:n,message:t,locale:this.l[0],schema:this.l[1],schemaIndex:this.l[2],cancelled:!1};if(this.l[7]=i,this.d[3].acceptRevision(n),this.l[6]+=1,void 0===t.protocolVersion||(this.#W(t.protocolVersion),this.l[4]&&this.l[7]===i)){if(this.d[5].markConnected()){if(this.d[17]?.announceConnected(),this.d[0].emit("connect",{origin:e,timestamp:Date.now()}),!this.l[4]||this.l[7]!==i)return;if(this.d[14]("connection","disconnected","→","connected"),!this.l[4]||this.l[7]!==i)return}this.#G(i)}}async#G(t){const e=await this.#V(t);if(null===e||!this.l[4]||this.l[7]!==t)return;const{message:n}=t,i={fields:e,...void 0!==t.schema?{schema:t.schema}:{},..."string"==typeof n.globalSlug?{globalSlug:n.globalSlug}:{},..."string"==typeof n.collectionSlug?{collectionSlug:n.collectionSlug}:{},...void 0!==t.locale?{locale:t.locale}:{}};this.d[0].listenerCount("beforeUpdate")>0&&(!await this.d[0].emitWhile("beforeUpdate",{data:i,revision:t.identity.revision,cancel:()=>{t.cancelled=!0,this.d[3].cancelRevision(t.identity)}},()=>!t.cancelled&&this.l[4]&&this.l[7]===t)||t.cancelled||!this.l[4]||this.l[7]!==t)||this.l[4]&&this.l[7]===t&&this.#_(t,i)}async#V(t){const{message:e}=t,n=e.data??{};if(null===this.d[18])return n;const i=await this.d[18].merge({collectionSlug:e.collectionSlug,globalSlug:e.globalSlug,data:n,locale:t.locale});return this.l[4]&&this.l[7]===t?"merged"===i.status?i.doc:"superseded"===i.status?null:n:null}#_(t,e){if(!this.l[4]||this.l[7]!==t)return;const n=()=>this.l[4]&&this.l[7]===t,i=this.#B(t,e.fields);for(const[r,s]of this.d[1].entries()){if(!this.l[4]||this.l[7]!==t)return;for(const o of s){if(!1!==i&&!A(o.owner,i))continue;const s=it(e.fields,r,o.locale??t.locale,void 0!==o.locale);if(void 0===s)continue;if(!this.l[4]||this.l[7]!==t)return;const a=this.#q(o,s,e.fields,n);if(!this.l[4]||this.l[7]!==t)return;const l={target:o,value:a,allFields:e.fields,identity:t.identity,data:e};if(!this.l[4]||this.l[7]!==t)return;this.d[3].schedule(l)}}this.#J(e.fields,t.locale,i)}#B(t,e){if(!this.d[19])return!1;const{message:n}=t,i=function(t){if(S(t.globalSlug))return[(e=t.globalSlug,`global:${e}`)];var e;if(!S(t.collectionSlug))return null;const n=w(t.collectionSlug);return S(t.documentId)?[n,w(t.collectionSlug,t.documentId)]:[n]}({globalSlug:"string"==typeof n.globalSlug?n.globalSlug:void 0,collectionSlug:"string"==typeof n.collectionSlug?n.collectionSlug:void 0,documentId:k(e)});return null!==i||this.l[9]||(this.l[9]=!0,this.d[15]("[live-preview] scopeBindingsByOwner: update names no document; nothing applied")),i}#Q(t){for(const e of this.d[1].values())if(A(e.owner,t))return!0;return!1}#X(t,e){const n=this.d[1].get(t);return void 0!==n&&(!1===e||n.some(t=>A(t.owner,e)))}#J(t,e,n){if(0===this.d[1].fieldCount)return;if(!1!==n&&!this.#Q(n))return;let i;for(const[r,s]of Object.entries(t)){if(this.l[8].has(r))continue;if(kt.has(r))continue;if(!Ct(s))continue;const t=Tt(r,e);if(!(this.#X(r,n)||t!==r&&this.#X(t,n))){if(void 0===i){i=new Set;for(const[t,e]of this.d[1].entries())for(const r of e)(!1===n||A(r.owner,n))&&void 0!==r.locale&&i.add(`${t}_${r.locale}`)}i.has(r)||(this.l[8].add(r),this.d[15](`[live-preview] update arrived for field "${r}" but no <… data-payload-field="${t}"> element exists on this page. Render the binding anchor unconditionally in your template so live edits to an initially-empty field have somewhere to land.`))}}}#q(t,e,n,i){if(void 0===this.d[9])return e;try{const r=this.d[9](t.fieldName,e,{element:t.element,allFields:n},i),s=R(r);if(!i())return e;if(s)throw new TypeError(`Transform for "${t.fieldName}" returned a Promise/thenable; transforms must be synchronous`);return r}catch(t){if(!i())return e;const n=t instanceof Error?t:new Error(String(t));return this.d[0].emit("error",{error:n,context:"transform"}),e}}#j(){return this.l[4]}#Y(t){0!==t.deferred&&(this.l[10]||(this.l[10]=!0,this.d[15](`[live-preview] visibility gate held ${String(t.deferred)} offscreen update(s) until scrolled into view; see visibilityGateThreshold.`)))}#M(t){const e=this.l[7];if(null===e||void 0===t.identity||!At(e.identity,t.identity)||!this.l[4]||this.l[7]!==e)return!1;const n=void 0!==e.schemaIndex?function(t,e){if(t.has(e))return t.get(e);const n=e.replace(/\.\d+(?=\.|$)/g,".*");return t.has(n)?t.get(n):void 0}(e.schemaIndex,t.target.fieldName):void 0,i=t.value;let r,s=function(t,e){if(t.explicitFieldType)return t.fieldType;if(void 0!==e){const t=function(t){if(Object.prototype.hasOwnProperty.call(vt,t))return vt[t]}(e);if(void 0!==t)return t}return t.fieldType}(t.target,n?.type);"text"===s&&!0!==t.target.explicitFieldType&&function(t){if("object"!=typeof t||null===t)return!1;if(!("root"in t))return!1;const e=t.root;return"object"==typeof e&&null!==e&&Array.isArray(e.children)}(i)&&(s="richText");try{r=this.d[8](s)}catch(t){if(!this.l[4]||this.l[7]!==e)return!1;const n=t instanceof Error?t:new Error(String(t));return this.d[0].emitWhile("error",{error:n,context:"renderer"},()=>this.l[4]&&this.l[7]===e),!1}if(!this.l[4]||this.l[7]!==e)return!1;const o=this.d[0].listenerCount("elementUpdate")>0,a=o?"INPUT"===(l=t.target.element).tagName||"TEXTAREA"===l.tagName?l.value:"IMG"===l.tagName?l.src:l.textContent:void 0;var l;if(!this.l[4]||this.l[7]!==e)return!1;const u={allFields:t.allFields,locale:t.target.locale??e.locale,schema:n};try{if(void 0!==t.target.targetAttribute){const e=function(t,e,n){const i=e.toLowerCase().trim();if(0===i.length)return"blocked";if(i.startsWith("on"))return"blocked";if(X.has(i))return"blocked";if(null==n)return t.removeAttribute(i),"applied";if("string"!=typeof n&&"number"!=typeof n&&"boolean"!=typeof n)return"blocked";const r=String(n);return Y.has(i)&&!isSafeUrl(r)?"blocked":(t.setAttribute(i,r),"applied")}(t.target.element,t.target.targetAttribute,i);if("blocked"===e)return this.d[15](`[live-preview] refused to write field "${t.target.fieldName}" into attribute "${t.target.targetAttribute}" (unsafe attribute or value)`),!1}else{if(!r)return this.d[14]("no renderer for",s),!1;{const e=function(t,e,n,i){return t.render(e,n,i)}(r,t.target,i,u);if(!1===e&&function(t){return K.has(t.render)}(r))return!1}}}catch(t){if(!this.l[4]||this.l[7]!==e)return!1;const n=t instanceof Error?t:new Error(String(t));return this.d[0].emitWhile("error",{error:n,context:"renderer"},()=>this.l[4]&&this.l[7]===e),!1}return!(!this.l[4]||this.l[7]!==e)&&(o&&this.d[0].emitWhile("elementUpdate",{element:t.target.element,fieldName:t.target.fieldName,previousValue:a,nextValue:i,revision:e.identity.revision},()=>this.l[4]&&this.l[7]===e),this.l[4]&&this.l[7]===e)}#E(t){this.#Y(t);const{identity:e,data:n}=t;if(0===t.applied||void 0===e||void 0===n)return;const i=this.l[7];if(null===i||!this.l[4]||this.l[7]!==i||!At(i.identity,e))return;const r=()=>this.l[4]&&this.l[7]===i&&At(i.identity,e);this.d[17]?.announceUpdate(t.applied),r()&&0!==this.d[0].listenerCount("afterUpdate")&&this.d[0].emitWhile("afterUpdate",{data:n,updatedCount:t.applied,durationMs:t.durationMs,revision:e.revision},r)}#O(){if(!this.#j())return;this.d[4].advanceGeneration();const t=this.l[7];this.l[7]=null,null!==t&&this.d[3].cancelRevision(t.identity),this.d[18]?.destroy();const e=this.d[5].markDisconnected();try{this.d[13]?.()}catch(t){this.d[14]("heartbeat:",t)}if(this.#j()){if(e&&this.#K()){if(this.d[17]?.announceDisconnected(),this.d[0].emitWhile("disconnect",{reason:"timeout",timestamp:Date.now()},()=>this.#K()),!this.#j())return;if(this.#K()&&(this.d[14]("connection","connected","→","disconnected"),!this.#j()))return}this.#j()&&this.#D()}}#D(){try{this.d[12](this.d[11])}catch(t){this.#L(t,"ready")}}#L(t,e){const n=t instanceof Error?t:new Error(String(t));this.d[0].emit("error",{error:n,context:e})}#K(){return this.l[4]&&"disconnected"===this.d[5].status&&null===this.l[7]}};function wt(t){return 9===t.nodeType}function St(t){if("undefined"==typeof window)return;const e=[];window.parent!==window&&e.push(window.parent),window.opener instanceof Window&&e.push(window.opener),M.sendReady(e,t)}function At(t,e){return t.generation===e.generation&&t.revision===e.revision}var kt=new Set(["id","_id","createdAt","updatedAt","createdBy","updatedBy","_status","globalType","collection","locale","localized"]);function Ct(t){return null!=t&&("string"==typeof t||"number"==typeof t||"boolean"==typeof t||"bigint"==typeof t)}function Tt(t,e){if(!e)return t;const n=`_${e}`;return t.endsWith(n)?t.slice(0,-n.length):t}var $t,xt=class{#Z=new Map;#tt=new Map;on(t,e){return this.#et(this.#Z,t,e)}once(t,e){return this.#et(this.#tt,t,e)}off(t,e){this.#nt(this.#Z,t,e),this.#nt(this.#tt,t,e)}async emit(t,e){await this.#it(t,e)}async emitWhile(t,e,n){return this.#it(t,e,n)}async#it(t,e,n){const i=()=>n?.()??!0;if(!i())return!1;const r=this.#Z.get(t);if(r)for(const n of[...r]){if(!i())return!1;if(await this.#rt(n,e,t),!i())return!1}if(!i())return!1;const s=this.#tt.get(t);if(s&&s.size>0){const n=[...s];this.#tt.delete(t);for(const r of n){if(!i())return!1;if(await this.#rt(r,e,t),!i())return!1}}return i()}listenerCount(t){return(this.#Z.get(t)?.size??0)+(this.#tt.get(t)?.size??0)}removeAllListeners(t){if(void 0===t)return this.#Z.clear(),void this.#tt.clear();this.#Z.delete(t),this.#tt.delete(t)}eventNames(){const t=new Set;for(const e of this.#Z.keys())t.add(e);for(const e of this.#tt.keys())t.add(e);return[...t]}#et(t,e,n){let i=t.get(e);return i||(i=new Set,t.set(e,i)),i.add(n),()=>{this.#nt(t,e,n)}}#nt(t,e,n){const i=t.get(e);void 0!==i&&(i.delete(n),0===i.size&&t.delete(e))}async#rt(t,e,n){try{await t(e)}catch(t){const e="string"==typeof n||"number"==typeof n?String(n):"<event>";D(`[live-preview] handler for "${e}" threw:`,t)}}};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 t=function(){if("undefined"==typeof process)return;const t=process.env.NODE_ENV;return"string"==typeof t?t:void 0}();if(void 0!==t)return"production"!==t;const e=function(){const t=Rt();if(!t)return;const e=t.DEV;return"boolean"==typeof e?e:void 0}();if(void 0!==e)return e;if("undefined"!=typeof window){const t=window.location.hostname;if("localhost"===t||"127.0.0.1"===t)return!0}return!1}function Nt(t){if("undefined"!=typeof process){const e=process.env[t];if("string"==typeof e&&e.length>0)return e}const e=Rt();if(e){const n=e[t];if("string"==typeof n&&n.length>0)return n}}function Rt(){if("undefined"==typeof __INLINE_RUNTIME_BUILD__||!__INLINE_RUNTIME_BUILD__){if(void 0!==$t)return $t??void 0;$t=null;try{const t=new Function("try { return import.meta && import.meta.env; } catch (_) { return undefined; }")();if(t&&"object"==typeof t)return $t=t}catch{}}}var Mt=/^https?:\/\/(localhost|127\.0\.0\.1)(?::\d+)?$/i,Et=/^https?:\/\/[^/?#\s]+$/i,It=["PAYLOAD_ADMIN_ORIGIN","PUBLIC_PAYLOAD_ADMIN_ORIGIN","NEXT_PUBLIC_PAYLOAD_ADMIN_ORIGIN"],Ot=class{#st;constructor(t={}){const e=new Set;for(const n of t.additionalOrigins??[]){const t=Pt(n);void 0!==t&&e.add(t)}for(const t of It){const n=Nt(t);if(void 0!==n)for(const t of n.split(",")){const n=Pt(t);void 0!==n&&e.add(n)}}let n;if(t.enableReferrerDetection??1){const e=t.referrer??("undefined"!=typeof document?document.referrer:"");if(e.length>0)try{const t=new URL(e).origin;t&&"null"!==t&&(n=t)}catch{}}const i=(t.enableLocalhostMatching??!0)&&(t.forceDevMode??isDevMode());this.#st=[e,n,i,void 0!==n,void 0]}matches(t){return 0!==t.length&&"null"!==t&&(void 0!==this.#st[4]?t===this.#st[4]:!!this.#st[0].has(t)||0===this.#st[0].size&&void 0!==this.#st[1]&&t===this.#st[1]||!(!this.#st[2]||!Mt.test(t)))}lockOrigin(t){return!!this.matches(t)&&(this.#st[4]=t,!0)}unlockOrigin(){const t=this.#st[4];return this.#st[4]=void 0,t}get lockedOrigin(){return this.#st[4]}enumerate(){if(void 0!==this.#st[4])return[this.#st[4]];const t=new Set(this.#st[0]);if(0===this.#st[0].size&&void 0!==this.#st[1]&&t.add(this.#st[1]),this.#st[2])for(const e of Ut)t.add(`http://localhost:${String(e)}`),t.add(`http://127.0.0.1:${String(e)}`);return[...t]}get referrerWasAvailable(){return this.#st[3]}get isProductionUnconfigured(){return!(!isInIframe()||this.#st[0].size>0||this.#st[2]||void 0!==this.#st[1])}get isReferrerOnlyTrust(){return!(this.#st[0].size>0||this.#st[2]||void 0===this.#st[1])}},Ut=[3e3,3001,3333,4e3,4321,5e3,5173,5174,8e3,8080,8888,9e3];function Pt(t){const e=t.trim();if(0!==e.length)try{const t=new URL(e);if("http:"!==t.protocol&&"https:"!==t.protocol)return;if(!Et.test(t.origin))return;return t.origin}catch{return}}var Lt,Ft=()=>{},jt=class{#ot;#at;#lt=new Set;#st="staging";constructor(t,e){this.#ot=t,this.#at=e}assertOpen(){if("closed"===this.#st)throw new Error(`Plugin context for "${this.#ot}" is no longer active`)}get active(){return"active"===this.#st}eligible(){return"closed"!==this.#st}own(t){return this.assertOpen(),this.#ut({acquire:void 0,finalize:void 0,cleanup:t,disposed:!1})}stage(t,e){this.assertOpen();const n={acquire:t,finalize:e,cleanup:void 0,disposed:!1},i=this.#ut(n);if("active"===this.#st)try{this.#ct(n)}catch(t){throw this.#dt(n),t}return i}commit(){if("staging"!==this.#st)throw new Error(`Plugin context for "${this.#ot}" cannot be committed`);this.#st="committing";try{for(const t of this.#lt)this.#ct(t);this.#st="active"}catch(t){throw this.close(),t}}close(){if("closed"!==this.#st){this.#st="closed";for(const t of[...this.#lt].reverse())this.#dt(t);this.#lt.clear()}}#ut(t){return this.#lt.add(t),()=>{this.#dt(t)}}#ct(t){if(t.disposed||void 0!==t.cleanup||void 0===t.acquire)return;const e=t.acquire();t.cleanup=e??Ft}#dt(t){if(t.disposed)return;t.disposed=!0,this.#lt.delete(t);const e=t.cleanup;if(t.cleanup=void 0,void 0!==e)try{R(e())&&this.#at(`plugin "${this.#ot}" cleanup returned a Promise/thenable; cleanups must be synchronous`)}catch(t){this.#at(`plugin "${this.#ot}" cleanup failed:`,t)}try{t.finalize?.()}catch(t){this.#at(`plugin "${this.#ot}" cleanup failed:`,t)}}},Dt=class extends xt{#ht;#ft;#pt=new Set;constructor(t,e){super(),this.#ht=t,this.#ft=e}on(t,e){return this.#gt("on",t,e)}once(t,e){return this.#gt("once",t,e)}off(t,e){const n=e;for(const e of[...this.#pt])e.event===t&&e.handler===n&&e.dispose()}emit(t,e){return this.#ft.assertOpen(),this.#ht.emit(t,e)}emitWhile(t,e,n){return this.#ft.assertOpen(),this.#ht.emitWhile(t,e,()=>{if(!this.#ft.eligible())return!1;const t=n();return!!this.#ft.eligible()&&t})}listenerCount(t){let e=0;for(const n of this.#pt)n.event===t&&(e+=1);return e}removeAllListeners(t){for(const e of[...this.#pt])void 0!==t&&e.event!==t||e.dispose()}eventNames(){const t=new Set;for(const e of this.#pt)t.add(e.event);return[...t]}#gt(t,e,n){this.#ft.assertOpen();const i=n,r=[...this.#pt].find(n=>n.kind===t&&n.event===e&&n.handler===i);if(void 0!==r)return r.dispose;let s=Ft,o=!0;const a=async e=>{this.#ft.active&&o&&("once"===t&&s(),await n(e))},l={kind:t,event:e,handler:i,dispose:Ft};return s=this.#ft.stage(()=>this.#ht[t](e,a),()=>{o=!1,this.#pt.delete(l)}),l.dispose=s,this.#pt.add(l),s}},Ht=class{#ht;#mt;#vt;#yt;#at;#bt=new Map;#wt=new Map;#St=new Map;#At=new Set;#kt=new Map;#Ct=Promise.resolve();#Tt=0;constructor(t){this.#ht=t.events,this.#mt=t.config,this.#vt=t.registerFieldRenderer,this.#at=F(t.log);const e=t.onTransformError;this.#yt=void 0===e?void 0:F((...t)=>{const n=t[0];if(n instanceof Error)try{return e(n)}catch(t){return void this.#at("transform error reporter failed:",t)}})}register(t){return this.#Tt>0?this.#$t(t):this.#xt(()=>this.#$t(t))}unregister(t){return this.#Tt>0?this.#Nt(t):this.#xt(async()=>{await this.#Nt(t)})}destroyAll(){return this.#Tt>0?this.#Rt():this.#xt(async()=>{await this.#Rt()})}applyTransforms(t,e,n,i){const r=this.#kt.get(t);if(void 0===r||0===r.length)return e;let s=e;for(const o of[...r]){if(!o.active)continue;const{transform:r}=o;if(!1===i?.())return e;try{s=r(s,{fieldName:t,element:n.element,allFields:n.allFields});const o=R(s);if(!1===i?.())return e;if(o)throw new TypeError(`Transform for "${t}" returned a Promise/thenable; transforms must be synchronous`)}catch(n){if(!1===i?.())return e;const r=n instanceof Error?n:new Error(String(n));return this.#at(`transform for "${t}" failed:`,r),this.#yt?.(r),e}}return s}list(){return[...this.#bt.keys()]}get size(){return this.#bt.size}async#$t(t){if(this.#bt.has(t.name)||this.#wt.has(t.name)||this.#St.has(t.name))return void this.#at(`plugin "${t.name}" already registered`);const e=new jt(t.name,this.#at),n=this.#Mt(t.name,e),i={scope:e,cancelled:!1};this.#wt.set(t.name,i);try{if(await this.#Et(()=>t.init(n)),i.cancelled)return;e.commit()}catch(n){return e.close(),void(i.cancelled||this.#at(`plugin "${t.name}" init failed:`,n))}finally{this.#wt.get(t.name)===i&&this.#wt.delete(t.name)}this.#bt.set(t.name,{plugin:t,scope:e}),this.#at(`plugin "${t.name}" registered`)}#Mt(t,e){return{events:new Dt(this.#ht,e),registerFieldRenderer:t=>{e.stage(()=>{const e=this.#vt(t);return"function"==typeof e?e:void 0})},registerTransform:(t,n)=>{const i={transform:n,active:!1};e.stage(()=>{i.active=!0;const e=this.#kt.get(t);return void 0===e?this.#kt.set(t,[i]):e.push(i),()=>{i.active=!1;const e=this.#kt.get(t);if(void 0===e)return;const n=e.indexOf(i);n>=0&&e.splice(n,1),0===e.length&&this.#kt.delete(t)}})},registerCleanup:t=>{e.own(t)},getConfig:()=>this.#mt,log:(...e)=>{this.#at(`[${t}]`,...e)}}}#Nt(t){const e=this.#wt.get(t);if(void 0!==e)return e.cancelled=!0,e.scope.close(),Promise.resolve();const n=this.#St.get(t);if(void 0!==n)return this.#At.has(t)?Promise.resolve():n;const i=this.#bt.get(t);if(void 0===i)return Promise.resolve();this.#bt.delete(t),i.scope.close();const r=Promise.resolve().then(()=>this.#It(t,i.plugin));return this.#St.set(t,r),r.then(()=>{this.#St.get(t)===r&&this.#St.delete(t)}),r}async#It(t,e){if(void 0!==e.destroy){this.#At.add(t);try{await this.#Et(()=>e.destroy?.())}catch(e){this.#at(`plugin "${t}" destroy failed:`,e)}finally{this.#At.delete(t)}}}async#Rt(){for(const t of this.#wt.values())t.cancelled=!0,t.scope.close();const t=[...this.#bt.keys()];for(const e of t)await this.#Nt(e)}async#Et(t){this.#Tt+=1;try{await t()}finally{this.#Tt-=1}}#xt(t){const e=this.#Ct.then(t);return this.#Ct=e.catch(t=>{this.#at("plugin manager mutation failed:",t)}),e}},zt=class{#Ot;#Ut;#Pt=new Map;constructor(t){this.#Ot=t,this.#Ut={...t}}get renderers(){return this.#Ut}resolve(t){return this.#Ut[t]}register(t){const e=t.name,n={renderer:t},i=this.#Pt.get(e);void 0===i?this.#Pt.set(e,[n]):i.push(n),this.#Ut[e]=t;let r=!0;return()=>{if(!r)return;r=!1;const t=this.#Pt.get(e);if(void 0===t)return;const i=t.indexOf(n);if(i<0)return;const s=i===t.length-1;if(t.splice(i,1),0===t.length&&this.#Pt.delete(e),!s)return;const o=t.at(-1),a=o?.renderer??this.#Ot[e];void 0===a?Reflect.deleteProperty(this.#Ut,e):this.#Ut[e]=a}}},Wt=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"]),Gt=new Set(["script","style","iframe","object","embed","link","meta","base","form","input","button","select","textarea","svg","math","template","frame","frameset","noframes","noscript"]),Vt=new Set(["id","class","lang","dir","title","role","tabindex"]),_t={a:new Set(["href","target","rel","download","hreflang","type"]),img:new Set(["src","srcset","sizes","alt","width","height","loading","decoding"]),picture:new Set([]),source:new Set(["src","srcset","sizes","type","media"]),audio:new Set(["src","controls","autoplay","loop","muted","preload"]),video:new Set(["src","poster","controls","autoplay","loop","muted","preload","width","height","playsinline"]),time:new Set(["datetime"]),abbr:new Set(["title"]),q:new Set(["cite"]),blockquote:new Set(["cite"]),table:new Set(["summary"]),th:new Set(["colspan","rowspan","scope","headers","abbr"]),td:new Set(["colspan","rowspan","headers"]),col:new Set(["span"]),colgroup:new Set(["span"]),ol:new Set(["start","reversed","type"]),li:new Set(["value"]),code:new Set(["class"]),pre:new Set(["class"])},Bt=new Set(["href","src","cite","poster"]),qt=class extends Error{name="SanitizerEnvironmentError"};function sanitizeHtml(t,e){const n=Jt();if(!n)throw new qt("sanitizeHtml needs a DOM; provide one with setSanitizerDocument() during SSR.");if(""===t)return"";const i=function(t){if(!t){const t=new Map;for(const[e,n]of Object.entries(_t))t.set(e,n);return{allowedTags:Wt,attrByTag:t}}const e=new Set(Wt);for(const n of t.additionalAllowedTags??[])e.add(n);const n=new Map;for(const[t,e]of Object.entries(_t))n.set(t,e);for(const[e,i]of Object.entries(t.additionalAllowedAttributes??{})){const t=n.get(e),r=new Set(t??[]);for(const t of i)r.add(t);n.set(e,r)}return{allowedTags:e,attrByTag:n}}(e),r=n.createElement("template");return r.innerHTML=t,Qt(r.content,i),r.innerHTML}function Jt(){return Lt||("undefined"!=typeof document?document:void 0)}function Qt(t,e){for(const n of Array.from(t.childNodes))1===n.nodeType?Xt(n,e):8===n.nodeType&&n.remove()}function Xt(t,e){const n=t.tagName.toLowerCase();if(Gt.has(n))t.remove();else{if(!e.allowedTags.has(n)){Qt(t,e);const n=t.parentNode;if(n){for(;t.firstChild;)n.insertBefore(t.firstChild,t);t.remove()}return}!function(t,e,n){const i=n.attrByTag.get(e);for(const e of Array.from(t.attributes)){const n=e.name.toLowerCase();n.startsWith("on")?t.removeAttribute(e.name):"style"!==n?Vt.has(n)||n.startsWith("aria-")||n.startsWith("data-")||(i?.has(n)?Bt.has(n)&&!isSafeUrl(e.value)?t.removeAttribute(e.name):"srcset"!==n||Yt(e.value)||t.removeAttribute(e.name):t.removeAttribute(e.name)):t.removeAttribute(e.name)}}(t,n,e),"a"===n&&function(t){const e=t.getAttribute("href");null!==e&&isExternalHttpUrl(e)&&(t.setAttribute("rel","noopener noreferrer"),t.hasAttribute("target")||t.setAttribute("target","_blank"))}(t),Qt(t,e)}}function Yt(t){const e=t.split(",");for(const t of e){const e=t.trim();if(0===e.length)continue;const n=e.search(/\s/);if(!isSafeUrl(-1===n?e:e.slice(0,n)))return!1}return!0}var Kt=new Map;function Zt(t,e){Kt.set(t,e)}var te={1:"left",2:"center",3:"right",4:"justify"},ee=new Set(["left","center","right","justify","start","end"]);function ne(t){const e=t.format;if("string"==typeof e&&ee.has(e))return e;if("number"==typeof e){const t=te[e];if(void 0!==t)return t}}function ie(t){const e=t.indent;return"number"==typeof e&&e>0?e:0}function re(t){return"rtl"===t.direction?' dir="rtl"':"ltr"===t.direction?' dir="ltr"':""}function se(t){const e=ne(t),n=ie(t),i=[];return void 0!==e&&i.push(`text-align:${e}`),n>0&&i.push(`padding-inline-start:${String(40*n)}px`),0===i.length?"":` style="${i.join(";")}"`}var oe=Object.freeze({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"}),ae=/[&<>"'/`=]/g;function escapeHtml(t){return""===t?"":t.replace(ae,t=>oe[t])}var le=Object.freeze({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"}),ue=/[&<>"']/g;function escapeHtmlAttribute(t){return""===t?"":t.replace(ue,t=>le[t])}function ce(t){return escapeHtml(t).replace(/\r\n|\r|\n/g,"<br>")}var de=new Set(["h1","h2","h3","h4","h5","h6"]),he=(t,e)=>{const n="string"==typeof t.url?t.url:"",i=e.renderChildren(t.children??[]);if(0===n.length||!isSafeUrl(n))return i;const r=isExternalHttpUrl(n)?' target="_blank" rel="noopener noreferrer"':function(t){const e="string"==typeof t.target?t.target:"";if(0===e.length)return"";const n=escapeHtml(e);return"_blank"===e?' target="_blank" rel="noopener noreferrer"':` target="${n}"`}(t),s="string"==typeof t.title?` title="${escapeHtml(t.title)}"`:"";return`<a href="${escapeHtmlAttribute(n)}"${r}${s}>${i}</a>`};function fe(t){if("string"==typeof t.text)return t.text;if(!t.children)return"";let e="";for(const n of t.children)e+=fe(n);return e}function pe(t){return t.replace(/[^a-zA-Z0-9_-]/g,"")}var ge=new Map;function me(t){return ge.get(t)}function ve(t){return t.replace(/[^a-zA-Z0-9_-]/g,"-").toLowerCase()}Zt("text",t=>{let e=escapeHtml("string"==typeof t.text?t.text:"");const n="number"==typeof t.format?t.format:0;return!!(16&n)&&(e=`<code>${e}</code>`),!!(1&n)&&(e=`<strong>${e}</strong>`),!!(2&n)&&(e=`<em>${e}</em>`),!!(8&n)&&(e=`<u>${e}</u>`),!!(4&n)&&(e=`<s>${e}</s>`),!!(32&n)&&(e=`<sub>${e}</sub>`),!!(64&n)&&(e=`<sup>${e}</sup>`),!!(128&n)&&(e=`<mark>${e}</mark>`),e}),Zt("paragraph",(t,e)=>{const n=e.renderChildren(t.children??[]);return`<p${re(t)}${se(t)}>${n}</p>`}),Zt("heading",(t,e)=>{const n="string"==typeof t.tag?t.tag.toLowerCase():"h2",i=de.has(n)?n:"h2",r=e.renderChildren(t.children??[]);return`<${i}${re(t)}${se(t)}>${r}</${i}>`}),Zt("list",(t,e)=>{const n="string"==typeof t.listType?t.listType:"bullet",i="number"===n?"ol":"ul",r="number"===n&&"number"==typeof t.start&&t.start>1?` start="${String(t.start)}"`:"",s="check"===n?' role="list"':"",o=e.renderChildren(t.children??[]);return`<${i}${re(t)}${se(t)}${r}${s}>${o}</${i}>`}),Zt("listitem",(t,e)=>{const n=e.renderChildren(t.children??[]);if("boolean"==typeof t.checked)return`<li role="checkbox" aria-checked="${t.checked?"true":"false"}"${se(t)}>${n}</li>`;const i="number"==typeof t.value?` value="${escapeHtml(String(t.value))}"`:"";return`<li${re(t)}${se(t)}${i}>${n}</li>`}),Zt("link",he),Zt("autolink",he),Zt("quote",(t,e)=>{const n=e.renderChildren(t.children??[]);return`<blockquote${re(t)}${se(t)}>${n}</blockquote>`}),Zt("code",t=>{const e=pe("string"==typeof t.language?t.language:"");return`<pre><code${""===e?"":` class="language-${e}"`}>${escapeHtml(fe(t))}</code></pre>`}),Zt("code-highlight",t=>{const e="string"==typeof t.text?t.text:"";return`<span${"string"==typeof t.highlightType?` class="token-${pe(t.highlightType)}"`:""}>${escapeHtml(e)}</span>`}),Zt("linebreak",()=>"<br>"),Zt("horizontalrule",()=>"<hr>"),Zt("tab",()=>"\t"),Zt("upload",t=>{const e=function(t){const e=t.value;return"object"!=typeof e||null===e?void 0:e}(t);if(void 0===e)return"";const n=e.url;if("string"!=typeof n||!isSafeUrl(n))return"";const i="string"==typeof e.mimeType?e.mimeType:"";return i.startsWith("video/")?function(t,e){const n="number"==typeof t.width?` width="${String(t.width)}"`:"",i="number"==typeof t.height?` height="${String(t.height)}"`:"",r="string"==typeof t.mimeType?` type="${escapeHtmlAttribute(t.mimeType)}"`:"";return`<video controls${n}${i}><source src="${escapeHtmlAttribute(e)}"${r}></video>`}(e,n):i.startsWith("audio/")?function(t,e){const n="string"==typeof t.mimeType?` type="${escapeHtmlAttribute(t.mimeType)}"`:"";return`<audio controls><source src="${escapeHtmlAttribute(e)}"${n}></audio>`}(e,n):""===i||i.startsWith("image/")?function(t,e){const n="string"==typeof t.alt?escapeHtml(t.alt):"",i="number"==typeof t.width?` width="${String(t.width)}"`:"",r="number"==typeof t.height?` height="${String(t.height)}"`:"";return`<img src="${escapeHtmlAttribute(e)}" alt="${n}"${i}${r} loading="lazy" decoding="async">`}(e,n):function(t,e){const n="string"==typeof t.filename?escapeHtml(t.filename):escapeHtml(e);return`<a href="${escapeHtmlAttribute(e)}" target="_blank" rel="noopener noreferrer">${n}</a>`}(e,n)}),Zt("relationship",t=>{const e="string"==typeof t.relationTo?t.relationTo:"",n=function(t){const e=t.value;return"object"!=typeof e||null===e?void 0:e}(t),i=function(t,e){return void 0===t?""===e?"#":`#${e}`:"string"==typeof t.title&&t.title.length>0?t.title:"string"==typeof t.name&&t.name.length>0?t.name:"string"==typeof t.slug&&t.slug.length>0?t.slug:void 0!==t.id?String(t.id):""===e?"#":`#${e}`}(n,e),r=escapeHtml(i),s=""===e?"":` data-relation-to="${escapeHtml(e)}"`,o=n?.url;return"string"==typeof o&&isSafeUrl(o)?`<a href="${escapeHtmlAttribute(o)}"${s}>${r}</a>`:`<span${s}>${r}</span>`}),Zt("block",(t,e)=>{const n=function(t){const e=t.fields;return"object"!=typeof e||null===e?{}:e}(t),i="string"==typeof n.blockType?n.blockType:"",r=ve(i);if(""!==i){const t=me(i)??me(r);if(t)return t(n,{renderChildren:e.renderChildren})}const s=[];""!==r&&s.push(`data-block-type="${escapeHtml(r)}"`);for(const[t,e]of Object.entries(n)){if("blockType"===t||"id"===t)continue;if(null==e)continue;const n="string"==typeof e||"number"==typeof e||"boolean"==typeof e?String(e):JSON.stringify(e);s.push(`data-block-${ve(t)}="${escapeHtml(n)}"`)}return`<div${0===s.length?"":` ${s.join(" ")}`}></div>`});var ye={renderChildren:Se,resolveAlignment:ne,resolveIndent:ie};function be(t){if("object"!=typeof t||null===t)return!1;if(!("root"in t))return!1;const e=t.root;return"object"==typeof e&&null!==e&&"children"in e&&Array.isArray(e.children)}function we(t){return be(t)?t.root.children.map(ke).join("\n").trim():""}function Se(t){let e="";for(const n of t)e+=Ae(n);return e}function Ae(t){const e=(n=t.type,Kt.get(n));var n;return e?e(t,ye):void 0!==t.children?Se(t.children):""}function ke(t){if("string"==typeof t.text)return t.text;if("linebreak"===t.type)return"\n";if(void 0===t.children)return"";let e="";for(const n of t.children)e+=ke(n);return e}function Ce(){const t=new WeakSet;return{name:"text",render:Z((e,n)=>{const i=e.element,r=function(t){return null==t?"":be(t)?we(t):"string"==typeof t?t:"number"==typeof t||"boolean"==typeof t?String(t):JSON.stringify(t)}(n);if("INPUT"!==i.tagName&&"TEXTAREA"!==i.tagName)return function(t){return null!==t.firstElementChild}(i)&&!i.hasAttribute("data-payload-text")?(function(t,e,n){t.has(e)||(t.add(e),H(`[live-preview] Skipping text update for "${n}": <${e.tagName.toLowerCase()}> has structured children. Move data-payload-field to the value element, or add data-payload-text to replace them.`))}(t,i,e.fieldName),!1):void(r.includes("\n")||r.includes("\r")?i.innerHTML=ce(r):i.textContent=r);i.value=r})}}function Te(t){if(null==t)return"";if("string"==typeof t)return t;if("number"==typeof t||"boolean"==typeof t||"bigint"==typeof t)return String(t);try{return JSON.stringify(t)}catch{return""}}var $e={name:"textarea",render(t,e){const n=t.element,i=be(e)?we(e):Te(e);"INPUT"!==n.tagName&&"TEXTAREA"!==n.tagName?n.innerHTML=ce(i):n.value=i}},xe={name:"richText",render:Z((t,e)=>{if(be(e))t.element.innerHTML=function(t,e={}){if(!be(t))return"";const n=Se(t.root.children);return!1===e.sanitize||void 0===Jt()?n:sanitizeHtml(n)}(e);else{if("string"!=typeof e)return!1;t.element.innerHTML=sanitizeHtml(e)}})},Ne={name:"html",render(t,e){if(null==e)return void(t.element.textContent="");const n="string"==typeof e?e:Te(e);t.element.innerHTML=sanitizeHtml(n)}},Re={name:"url",render(t,e,n){const i=t.element,r=Te(e);if("A"===i.tagName){const s=i,o=t.hrefField,a=void 0===o||0===o.length?e:it(n.allFields,o,n.locale,void 0!==t.locale);return"string"==typeof a&&isSafeUrl(a)&&(s.href=a),void(s.textContent=r)}"INPUT"!==i.tagName&&"TEXTAREA"!==i.tagName?i.textContent=r:i.value=r}},Me={name:"image",render:Z((t,e,n)=>{const i=t.element,r=Ee(e),s=void 0!==t.locale,o=function(t,e,n,i,r,s){if(void 0!==n&&n.length>0){const t=it(i,n,r,s);if("string"==typeof t&&isSafeUrl(t))return t;const e=Ee(t);return void 0!==e?.url&&isSafeUrl(e.url)?e.url:void 0}return void 0!==t?.url&&isSafeUrl(t.url)?t.url:"string"==typeof e&&isSafeUrl(e)?e:void 0}(r,e,t.srcField,n.allFields,n.locale,s);if(void 0===o)return!1;if("IMG"===i.tagName){const e=i;e.src=o;const a=function(t,e,n,i,r){if(void 0!==e&&e.length>0){const t=it(n,e,i,r);return"string"==typeof t?t:void 0}return void 0!==t?.alt?t.alt:void 0}(r,t.altField,n.allFields,n.locale,s);return void(void 0!==a&&(e.alt=a))}i.style.backgroundImage=`url('${function(t){return t.replace(/['"()\\]/g,"\\$&")}(o)}')`})};function Ee(t){if("object"==typeof t&&null!==t)return t}var Ie={name:"upload",render:Z((t,e)=>{const n=t.element,i=function(t){return"object"!=typeof t||null===t?void 0:t}(e);if(void 0===i)return!1;const r=i.url;if("string"!=typeof r||!isSafeUrl(r))return!1;if("IMG"===n.tagName){const t=n;return t.src=r,void(void 0!==i.alt&&(t.alt=i.alt))}if("A"===n.tagName){const t=n;return t.href=r,void(t.textContent=i.filename??r)}const s=void 0!==i.filename?escapeHtml(i.filename):escapeHtml(r);n.innerHTML=`<a href="${escapeHtmlAttribute(r)}">${s}</a>`})},Oe={name:"relationship",render(t,e){const n=t.element,i=function(t){return null==t?[""]:Array.isArray(t)?t.map(Ue):[Ue(t)]}(e),r=i.join(", ");if("A"===n.tagName&&!Array.isArray(e)){const t=n,i=e?.url;return"string"==typeof i&&isSafeUrl(i)&&(t.href=i),void(t.textContent=r)}n.textContent=r}};function Ue(t){if("object"==typeof t&&null!==t){const e=t;return"string"==typeof e.title&&e.title.length>0?e.title:"string"==typeof e.name&&e.name.length>0?e.name:"string"==typeof e.slug&&e.slug.length>0?e.slug:void 0!==e.id?String(e.id):""}return Te(t)}var Pe={name:"select",render(t,e){const n=t.element,i=Le(e);if("SELECT"!==n.tagName){if("INPUT"===n.tagName&&"radio"===n.type){const t=n;return void(t.checked=t.value===i)}n.textContent=i}else n.value=i}};function Le(t){return Array.isArray(t)?t.map(t=>Le(t)).join(", "):Te(t)}var Fe={name:"checkbox",render(t,e){const n=t.element,i=Boolean(e);"INPUT"!==n.tagName||"checkbox"!==n.type?n.hasAttribute("aria-checked")?n.setAttribute("aria-checked",i?"true":"false"):n.textContent=i?"true":"false":n.checked=i}},je=new Map,De=new Map;function He(t,e){const n=t??"";if(null==e)return n;const i=ze(e);return"{}"===i?n:`${n}|${i}`}function ze(t){if(null===t||"object"!=typeof t)return JSON.stringify(t);if(Array.isArray(t))return`[${t.map(t=>ze(t)).join(",")}]`;const e=t,n=Object.keys(e).sort(),i=[];for(const t of n){const n=e[t];void 0!==n&&i.push(`${JSON.stringify(t)}:${ze(n)}`)}return`{${i.join(",")}}`}function We(t){for(;t.size>64;){const e=t.keys().next().value;if(void 0===e)break;t.delete(e)}}var Ge={name:"date",render(t,e,n){const i=t.element;if(null==e||""===e)return void("INPUT"===i.tagName?i.value="":"TIME"===i.tagName?(i.removeAttribute("datetime"),i.textContent=""):i.textContent="");const r="string"==typeof e?e:Te(e),s=new Date(r),o=!Number.isNaN(s.getTime());if("INPUT"!==i.tagName)return"TIME"===i.tagName?(i.setAttribute("datetime",o?s.toISOString():r),void(i.textContent=o?Ve(s,n):r)):void(i.textContent=o?Ve(s,n):r);i.value=o?function(t,e){return"date"===t?e.toISOString().slice(0,10):"datetime-local"===t?e.toISOString().slice(0,16):e.toISOString()}(i.type,s):r}};function Ve(t,e){const n=e.locale??detectInitialLocale();try{return function(t,e){const n=He(t,e),i=De.get(n);if(void 0!==i)return De.delete(n),De.set(n,i),i;const r=new Intl.DateTimeFormat(t,e);return De.set(n,r),We(De),r}(n,{dateStyle:"medium",timeStyle:"short"}).format(t)}catch{return t.toISOString()}}var _e={name:"number",render(t,e,n){const i=t.element;if(null==e||""===e)return void("INPUT"===i.tagName?i.value="":i.textContent="");const r="number"==typeof e?e:Number(Te(e));Number.isNaN(r)?i.textContent=Te(e):"INPUT"!==i.tagName?i.textContent=function(t,e){const n=e.locale??detectInitialLocale();try{return function(t,e){const n=He(t,e),i=je.get(n);if(void 0!==i)return je.delete(n),je.set(n,i),i;const r=new Intl.NumberFormat(t,e);return je.set(n,r),We(je),r}(n).format(t)}catch{return String(t)}}(r,n):i.value=String(r)}},Be=/\{\{([\s\S]*?)\}\}/g;function qe(t,e,n,i){const r="object"==typeof e&&null!==e?e:null;return t.replace(Be,(t,s)=>null!==r&&function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(r,s)?escapeHtml(i(Reflect.get(r,s))):null===r&&"value"===s?escapeHtml(i(e)):"index"===s?String(n):t)}var Je={name:"array",render:Z((t,e)=>{const n=t.element;if(!Array.isArray(e))return!1;const i=t.arrayTemplate;if(void 0!==i&&i.length>0){const t=function(t,e){let n="";for(let i=0;i<e.length;i+=1)n+=Qe(t,e[i],i);return n}(i,e);return void(n.innerHTML=sanitizeHtml(t))}const r=t.arraySeparator??", ";n.textContent=e.map(Xe).join(r)})};function Qe(t,e,n){return qe(t,e,n,Te)}function Xe(t){return Te(t)}var Ye="data-payload-key",Ke="data-payload-nested-key",Ze="data-payload-nested-template";function tn(t){const{template:e,container:n,patches:i,nextItems:r,store:s,forceRender:o=!1}=t,a=en(n,e,i,r,o,s);return null===a?null:nn(a,s)}function en(t,e,n,i,r,s){const o=function(t){const e=new Set,n=new Set;for(const i of t)"insert"===i.kind||"update"===i.kind?e.add(i.index):"replace"===i.kind&&(e.add(i.index),n.add(i.index));return{renders:e,replaces:n}}(n),a=function(t,e,n,i,r,s,o){const a=Array.from(t.children),l=cn(a,Ye),u=new Set,c=[];for(let d=0;d<n.length;d+=1){const h=n[d],f=un(h);let p=void 0===f?a[d]??null:dn(l,f)??null;null!==p&&u.has(p)&&(p=null),null!==p&&u.add(p);const g=i.replaces.has(d),m=r||i.renders.has(d)||null===p?hn(t.ownerDocument,e,h,d):void 0;if(null===m)return null;const v=void 0===m?[]:rn(g?null:p,m,h,s,o);if(null===v)return null;c.push([d,p,m??void 0,v])}return c}(t,e,i,o,r,s.get(t),s);return null===a?null:[t,a,i]}function nn(t,e){const[n,i,r]=t,s=new Set;let o=!1;for(const t of i){const[i,r,a,l]=t;let u=r;if(void 0!==a){for(const t of l)null!==t[0]&&(on(t[0],t[1]),t[1].replaceWith(t[0])),void 0!==t[2]&&nn(t[2],e);null!==r&&(r.replaceWith(a),o=!0),u=a}if(null===u)continue;const c=n.children[i]??null;u!==c&&(n.insertBefore(u,c),o=!0),s.add(u)}for(const t of Array.from(n.children))s.has(t)||(t.remove(),o=!0);const a=function(t,e){let n=e.get(t);return n||(n=new Map,e.set(t,n)),n}(n,e);a.clear();for(const t of r)ln(a,t);return o}function rn(t,e,n,i,r){const s=cn(null===t?[]:sn(t),Ke),o=un(n),a=void 0!==o?i?.get(o):void 0,l=[];for(const t of sn(e)){const e=t.getAttribute(Ke);if(null===e)continue;const i=dn(s,e)??null,o=t.getAttribute(Ze),u=o?i:null,c=u?.getAttribute(Ze)??null;let d;if(o){const i=an(n,e);if(void 0!==i||null!==u){const n=i??[],s=gt(null===u?[]:an(a,e)??[],n),l=null!==u&&c!==o;if((s.length>0||l)&&(d=en(u??t,o,s,n,l,r)??void 0,void 0===d))return null}}l.push([u,t,d])}return l}function sn(t){return Array.from(t.querySelectorAll(`[${Ke}]`)).filter(e=>{let n=e.parentElement;for(;null!==n&&n!==t;){if(n.hasAttribute(Ke))return!1;n=n.parentElement}return n===t})}function on(t,e){for(const n of Array.from(t.attributes))e.hasAttribute(n.name)||t.removeAttribute(n.name);for(const n of Array.from(e.attributes))t.getAttribute(n.name)!==n.value&&t.setAttribute(n.name,n.value)}function an(t,e){if("object"!=typeof t||null===t)return;const n=t[e];return Array.isArray(n)?n:void 0}function ln(t,e){const n=un(e);void 0!==n&&t.set(n,e)}function un(t){if("object"!=typeof t||null===t)return;const e=t.id;return"string"==typeof e||"number"==typeof e?String(e):void 0}function cn(t,e){const n=new Map;for(let i=t.length-1;i>=0;i-=1){const r=t[i];if(void 0===r)continue;const s=r.getAttribute(e);if(null===s)continue;const o=n.get(s);void 0===o?n.set(s,[r]):o.push(r)}return n}function dn(t,e){return t.get(e)?.pop()}function hn(t,e,n,i){const r=function(t,e,n){return qe(t,e,n,Te)}(e,n,i),s=sanitizeHtml(r),o=t.createElement("template");o.innerHTML=s;const a=o.content.firstElementChild;if(!a)return null;const l=un(n);return void 0!==l&&a.setAttribute(Ye,l),a}function fn(){const t=new WeakMap,e=new WeakSet,n=new WeakMap;return{name:"structural-array",render:Z((i,r)=>{if(!Array.isArray(r))return!1;const s=i.element,o=i.arrayTemplate;if(void 0===o||0===o.length)return function(t,e,n){t.has(e)||(t.add(e),H(`[live-preview] Skipping structural update for "${n}": <${e.tagName.toLowerCase()} data-payload-structural> needs data-payload-array-template (for example "<li>{{label}}</li>").`))}(e,s,i.fieldName),!1;const a=t.get(s),l=pn(s),u=gt(a?.values??l.map((t,e)=>null===t?{__payloadDomPosition:e}:{id:t}),r),c=function(t,e,n){return void 0===t||t.template!==e||!function(t,e){return t.length===e.length&&t.every((t,n)=>t===e[n])}(t.domSnapshot,n)}(a,o,l);if(0===u.length&&!c)return t.set(s,{values:r.slice(),template:o,domSnapshot:l}),!1;const d=tn({template:o,container:s,patches:u,nextItems:r,store:n,forceRender:c});return null!==d&&(t.set(s,{values:r.slice(),template:o,domSnapshot:pn(s)}),!!d&&void 0)})}}function pn(t){return Array.from(t.children,t=>t.getAttribute(Ye))}var gn,mn=new Map,vn=[$e,xe,Ne,Re,{...Re,name:"email"},Me,Ie,Oe,Pe,{...Pe,name:"radio"},Fe,Ge,_e,Je,{...Je,name:"blocks"}],yn=class{#Lt=new xt;#Ft;#jt;#Dt;#bt;#at;#Ht=!1;#zt=!1;#Wt=null;constructor(t={}){const e=t.debug??isDevMode();this.#at=e?(...t)=>{z("[live-preview]",...t)}:j,this.#Ft=new Ot({...void 0!==t.allowedOrigins?{additionalOrigins:t.allowedOrigins}:{},...void 0!==t.disableReferrerDetection?{enableReferrerDetection:!t.disableReferrerDetection}:{},...void 0!==t.disableLocalhostMatching?{enableLocalhostMatching:!t.disableLocalhostMatching}:{}}),this.#Ft.isProductionUnconfigured&&this.#at("no trusted origin could be detected — set allowedOrigins or PAYLOAD_ADMIN_ORIGIN"),this.#jt=new zt(function(t=[]){const e={};for(const n of t)e[n.name]=n;for(const[t,n]of mn)e[t]=n;return Object.freeze(e)}([Ce(),...vn,fn()])),this.#bt=new Ht({events:this.#Lt,config:Object.freeze({...t}),registerFieldRenderer:t=>this.#jt.register(t),onTransformError:t=>{this.#Lt.emit("error",{error:t,context:"transform"})},log:this.#at}),this.#Dt=new bt({...void 0!==t.root?{root:t.root}:{},renderers:this.#jt.renderers,resolveRenderer:t=>this.#jt.resolve(t),transformValue:(t,e,n,i)=>this.#bt.applyTransforms(t,e,n,i),originMatcher:t=>this.#Ft.matches(t),readyTargets:this.#Ft.enumerate(),emitter:this.#Lt,...void 0!==t.serverURL&&""!==t.serverURL?{dataMerge:{serverURL:t.serverURL,...void 0!==t.apiRoute?{apiRoute:t.apiRoute}:{},...void 0!==t.mergeDepth?{depth:t.mergeDepth}:{},...void 0!==t.mergeFetch?{fetchFn:t.mergeFetch}:{}}}:{},...void 0!==t.debounceMs?{debounceMs:t.debounceMs}:{},...void 0!==t.heartbeatMs?{heartbeatMs:t.heartbeatMs}:{},...void 0!==t.intersectionRootMargin?{intersectionRootMargin:t.intersectionRootMargin}:{},...void 0!==t.scopeBindingsByOwner?{scopeBindingsByOwner:t.scopeBindingsByOwner}:{},...void 0!==t.disableVisibilityGate?{disableVisibilityGate:t.disableVisibilityGate}:{},...void 0!==t.visibilityGateThreshold?{visibilityGateThreshold:t.visibilityGateThreshold}:{},...void 0!==t.enableA11y?{enableA11y:t.enableA11y}:{},...void 0!==t.a11yLocale?{a11yLocale:t.a11yLocale}:{},onHeartbeatTimeout:()=>{this.#Ft.unlockOrigin()},...void 0!==t.validateToken?{validateToken:t.validateToken}:{},log:this.#at}),this.#Lt.on("connect",t=>{this.#Ft.lockOrigin(t.origin)}),!1!==t.autoStart&&this.start()}start(){if(this.#zt)return!1;if(this.#Ht)return this.#Dt.start(),!0;if(!isInPreviewContext())return!1;const t=this.#Dt.start();return t&&(this.#Ht=!0),t}suspend(){return!(this.#zt||!this.#Ht)&&this.#Dt.suspend()}resume(){return!(this.#zt||!this.#Ht)&&this.#Dt.start()}destroy(){if(null!==this.#Wt)return this.#Wt;let t,e;this.#zt=!0;const n=new Promise((n,i)=>{t=n,e=i});this.#Wt=n;try{this.#Dt.destroy(),this.#bt.destroyAll().finally(()=>{this.#Lt.removeAllListeners()}).then(t,e)}catch(t){this.#Lt.removeAllListeners(),e(t)}return n}async use(t){if(this.#zt)throw new Error("LivePreviewClient: already destroyed");await this.#bt.register(t)}async unuse(t){await this.#bt.unregister(t)}refreshCache(){this.#Dt.refreshCache()}get events(){return this.#Lt}get plugins(){return this.#bt.list()}get status(){return this.#Dt.status}get updateCount(){return this.#Dt.updateCount}get destroyed(){return this.#zt}};function bind(t,e){return bn(t,e)}function bindByPath(t,e){const n=function(t){const e=[],n=new Proxy({},{get(t,i){if("symbol"!=typeof i)return/^\d+$/.test(i)||e.push(i),n}});try{t(n)}catch{}return e}(t);if(0===n.length)throw new Error("bindByPath: the picker did not read any field — return data.<field> instead of a constant");return bn(n.join("."),e)}function bn(t,e){if(0===t.length)throw new Error("bind: field name must be a non-empty string");const n={"data-payload-field":t};return void 0!==e?.attribute&&(n["data-payload-attribute"]=e.attribute),void 0!==e?.type&&(n["data-payload-type"]=e.type),!0===e?.richtext&&(n["data-payload-richtext"]=""),!0===e?.html&&(n["data-payload-html"]=""),void 0!==e?.locale&&(n["data-payload-locale"]=e.locale),n}var wn=Object.freeze({});for(const[t,e]of[[xt,"EventEmitter"],[yn,"LivePreviewClient"],[Ot,"OriginDetector"]])Object.defineProperty(t,"name",{configurable:!0,value:e});exports.CORE_ENTRY=!0,exports.EventEmitter=xt,exports.LIBRARY_PROTOCOL_VERSION=4,exports.LivePreviewClient=yn,exports.OriginDetector=Ot,exports.VERSION="1.4.0",exports.bind=bind,exports.bindByPath=bindByPath,exports.buildFrameAncestors=function buildFrameAncestors(t={}){const{self:e=!0,origins:n=[],allowNone:i=!1}=t,r=new Set,s=[];if(i&&!e&&0===n.length)return"'none'";e&&(s.push("'self'"),r.add("'self'"));for(const t of n){const e=t.trim();0===e.length||r.has(e)||(r.add(e),s.push(e))}return s.length>0?s.join(" "):"'none'"},exports.buildScriptSrcWithNonce=function buildScriptSrcWithNonce(t,e={}){if(0===t.length)throw new RangeError("buildScriptSrcWithNonce: nonce is empty");const{self:n=!0,extra:i=[],strictDynamic:r=!1}=e,s=[];n&&s.push("'self'"),s.push(`'nonce-${t}'`),r&&s.push("'strict-dynamic'");for(const t of i){const e=t.trim();e.length>0&&s.push(e)}return s.join(" ")},exports.createPreviewBindings=function createPreviewBindings(t){const{authorized:e}=t,n=void 0!==t.owner&&t.owner.length>0?t.owner:void 0;return Object.freeze({authorized:e,bind:(t,n)=>e?bind(t,n):wn,bindByPath:(t,n)=>e?bindByPath(t,n):wn,owner:()=>e&&void 0!==n?{"data-payload-owner":n}:wn})},exports.detectInitialLocale=detectInitialLocale,exports.escapeHtml=escapeHtml,exports.escapeHtmlAttribute=escapeHtmlAttribute,exports.generateCspNonce=function generateCspNonce(t=16){if(!Number.isInteger(t)||t<8)throw new RangeError(`generateCspNonce: bytes must be an integer >= 8, got ${String(t)}`);const e=function(){if(gn?.getRandomValues)return gn;const t=globalThis.crypto;return t?.getRandomValues?t:void 0}();if(!e)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(t);return e.getRandomValues(n),function(t){let e="";for(const n of t)e+=String.fromCharCode(n);return("function"==typeof btoa?btoa(e):Buffer.from(t).toString("base64")).replaceAll("+","-").replaceAll("/","_").replaceAll("=","")}(n)},exports.hasCapability=function hasCapability(t,e){return t.capabilities.has(e)},exports.initLivePreview=function initLivePreview(t={}){const e=new yn({...t,autoStart:!1});return e.start()?e:null},exports.isDevMode=isDevMode,exports.isExternalHttpUrl=isExternalHttpUrl,exports.isInIframe=isInIframe,exports.isInPopup=isInPopup,exports.isInPreviewContext=isInPreviewContext,exports.isSafeUrl=isSafeUrl,exports.negotiateProtocol=negotiateProtocol,exports.sanitizeHtml=sanitizeHtml,exports.setCspCrypto=function setCspCrypto(t){gn=t??void 0},exports.setSanitizerDocument=function setSanitizerDocument(t){Lt=t??void 0};
2
2
  //# sourceMappingURL=core.cjs.map