payload-live-preview 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/astro/index.js +1 -1
- package/dist/adapters/astro/index.js.map +1 -1
- package/dist/adapters/astro/middleware-entry.js +1 -1
- package/dist/adapters/astro/middleware-entry.js.map +1 -1
- package/dist/adapters/nextjs/index.js +1 -1
- package/dist/adapters/nextjs/index.js.map +1 -1
- package/dist/adapters/nuxt/index.js +1 -1
- package/dist/adapters/nuxt/index.js.map +1 -1
- package/dist/adapters/sveltekit/index.js +1 -1
- package/dist/adapters/sveltekit/index.js.map +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/core.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
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=[t,e,n,i,r,s,o,a,l,u,c,d,h,"type"],p=`[${t}]`,g=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"]),m=class{#t=new Map;#e=new WeakMap;#n;constructor(t={}){this.#n=t.filter??v}buildFromRoot(t){const e=performance.now();this.clear();const n=t.querySelectorAll(p);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(f){const p=f.getAttribute(t);if(null===p||0===p.length)return;const m=f.getAttribute(e),v=function(t){const n=t.getAttribute(e);if(null!==n&&g.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"}(f),y=f.getAttribute(n),b=f.getAttribute(i),w=f.getAttribute(r),S=f.getAttribute(s),A=f.getAttribute(o),k=f.getAttribute(a),C=f.getAttribute(l);return{element:f,fieldName:p,fieldType:v,explicitFieldType:null!==m&&g.has(m),...null!==y&&y.length>0?{targetAttribute:y}:{},...null!==b&&b.length>0?{hrefField:b}:{},...null!==w&&w.length>0?{srcField:w}:{},...null!==S&&S.length>0?{altField:S}:{},...null!==A?{arrayTemplate:A}:{},...null!==k?{arraySeparator:k}:{},...null!==C&&C.length>0?{locale:C}:{}}}};function v(){return!0}var y=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:[...f]})}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&&f.includes(n.attributeName)&&(n.attributeName===t||1===n.target.nodeType&&n.target.hasAttribute(t)))return!0;for(const t of n.addedNodes)if(b(t))return!0;for(const t of n.removedNodes)if(b(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 b(e){if(1!==e.nodeType)return!1;const n=e;return!!n.hasAttribute(t)||null!==n.querySelector(`[${t}]`)}function w(t){if(!Array.isArray(t))return[];const e=[];for(const n of t){const t=S(n);t&&e.push(t)}return e}function S(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=w(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=w(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 A=4,k={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(k))i>=e&&r.add(t);return{ours:4,...void 0!==e?{theirs:e}:{theirs:void 0},negotiated:i,capabilities:r}}function hasCapability(t,e){return t.capabilities.has(e)}function C(t){return("object"==typeof t&&null!==t||"function"==typeof t)&&"function"==typeof t.then&&(Promise.resolve(t).catch(()=>{}),!0)}var T=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){if(0===t.length||0===e.length)return;const n={type:"payload-live-preview",ready:!0,protocolVersion:4};for(const i of t)for(const t of e)try{i.postMessage(n,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||x(e.data))&&N(e.fieldSchemaJSON,t=>Array.isArray(t))&&N(e.globalSlug,t=>"string"==typeof t)&&N(e.collectionSlug,t=>"string"==typeof t)&&N(e.locale,t=>"string"==typeof t)&&N(e.ready,t=>"boolean"==typeof t)&&N(e.previewToken,t=>"string"==typeof t)&&N(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 M)null===Reflect.get(e,t)&&Reflect.deleteProperty(e,t);if(!Array.isArray(e.fieldSchemaJSON))return e;let n;try{n=w(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.action,t=>"updated"===t||"created"===t||"deleted"===t)&&!!$(e.slug,t=>"string"==typeof t)&&!!$(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=x(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{C(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 $(t,e){return void 0===t||e(t)}function N(t,e){return null==t||e(t)}function x(t){if("object"!=typeof t||null===t)return!1;const e=Object.getPrototypeOf(t);return null===e||null===Object.getPrototypeOf(e)}var M=["data","fieldSchemaJSON","globalSlug","collectionSlug","locale","ready","previewToken","protocolVersion"],R=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]}},E=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 I(t){return(...e)=>{try{C(t(...e))}catch{}}}function O(){}var U=I((...t)=>console.error(...t)),P=I((...t)=>console.warn(...t)),L=I((...t)=>console.debug(...t));function j(t){for(const e of t){const t=e.codePointAt(0);if(void 0!==t&&(t<=31||127===t))return!0}return!1}function F(t){if(void 0===t||0===t.length||t.length>128||"."===t||".."===t||t.includes("/")||t.includes("\\")||t.includes("?")||t.includes("#")||j(t))return!1;try{return encodeURIComponent(t),!0}catch{return!1}}var H=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?O:I(t.log),null,0,0]}canMerge(t){try{return t.globalSlug?F(t.globalSlug):!!F(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("\\")||j(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(),!D(this.s,e))return{status:"superseded"};if(!this.canMerge(t))return D(this.s,e)?{status:"unavailable"}:{status:"superseded"};if(!D(this.s,e))return{status:"superseded"};const r=this.s[3]??("function"==typeof fetch?fetch:void 0);if(!D(this.s,e))return{status:"superseded"};if(void 0===r)return{status:"unavailable"};if(i=new AbortController,!D(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(!D(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(!D(this.s,e)||G(i.signal))return{status:"superseded"};const u=l.ok;if(!D(this.s,e))return{status:"superseded"};if(!u){const t=l.status;return D(this.s,e)?(this.s[4]("merge HTTP",t,o),D(this.s,e)?{status:"unavailable"}:{status:"superseded"}):{status:"superseded"}}const c=await l.json();return!D(this.s,e)||G(i.signal)?{status:"superseded"}:null===c||"object"!=typeof c||Array.isArray(c)?(this.s[4]("merge invalid",o),D(this.s,e)?{status:"unavailable"}:{status:"superseded"}):{status:"merged",doc:c}}catch(t){return!D(this.s,e)||null!==i&&G(i.signal)?{status:"superseded"}:(this.s[4]("merge exception",t),D(this.s,e)?{status:"unavailable"}:{status:"superseded"})}finally{null!==i&&D(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 D(t,e){return t[6]===e}function G(t){return t.aborted}var W=new Set(["http:","https:","mailto:","tel:"]),z=/^\s*(?:javascript|data|vbscript|file|blob|about)\s*:/i,V=/^(?:\.{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(z.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 W.has(t.protocol)}catch{return V.test(e)}}function isExternalHttpUrl(t){if(!isSafeUrl(t))return!1;const e=t.trim();return/^https?:\/\//i.test(e)||/^\/\/[^/]/.test(e)}var _=new Set(["style","srcdoc","formaction","form","id","name","is","srcset","imagesrcset"]),q=new Set(["href","src","poster","cite","action","xlink:href","data"]),B=new WeakSet;function J(t){return B.add(t),t}var Q=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(!X(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;X(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){X(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.#N(this.s[9],t),this.#N(this.s[10],t);for(const e of this.s[11])this.#N(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.#x())},this.s[1]);this.s[13]===t&&(this.s[12]=n)}#x(){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]&&X(t.identity,this.s[16])}#T(t){const e=this.s[0];return!1!==e(t)||(n=e,!B.has(n));var n}#N(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 X(t,e){return null!==e&&t.generation===e.generation&&t.revision===e.revision}var Y=new Set(["__proto__","prototype","constructor"]);function Z(t,e,n,i=!1){if(i&&void 0!==n){const i=K(t,`${e}_${n}`);if(void 0!==i)return i}const r=K(t,e);if(void 0!==r)return r;if(e.includes(".")){let n=t,i=!0;for(const t of e.split(".")){if(Y.has(t)||null===n||"object"!=typeof n){i=!1;break}if(n=K(n,t),void 0===n){i=!1;break}}if(i)return n}return void 0===n?void 0:K(t,`${e}_${n}`)}function K(t,e){if(!Y.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 tt="payload-live-preview-a11y";function et(t){return/^de(?:[-_]|$)/i.test(t)}var nt=new WeakMap;function it(t){null!==t[4]&&(clearTimeout(t[4]),t[4]=null),t[2]?.remove(),t[2]=null}var rt=class{s;constructor(t,e){const n=e??("undefined"==typeof document?null:document),i=n?.documentElement.getAttribute("lang")??"";this.s=[et(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=nt.get(t);return e??=[null,!1,null,0,null],nt.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];it(e),t&&n.remove()}let i=t.getElementById(tt);return e[1]=null===i,i||(i=t.createElement("div"),i.id=tt,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&&it(t),t[1]&&n?.remove(),t[0]=null,nt.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&&it(n)},1500);n[4]=r}},st=new Set(["tabs","row","collapsible"]);function ot(t,e=""){const n=new Map;return at(t,e,n),n}function at(t,e,n){for(const i of t){if(st.has(i.type)){i.fields&&at(i.fields,e,n);continue}if("group"===i.type){const t=""===e?i.name:`${e}.${i.name}`;n.set(t,i),i.fields&&at(i.fields,t,n);continue}const t=""===e?i.name:`${e}.${i.name}`;if(n.set(t,i),"array"===i.type&&i.fields)at(i.fields,`${t}.*`,n);else if("blocks"===i.type&&i.blocks)for(const e of i.blocks)at(e.fields,`${t}.*.${e.slug}`,n)}}function lt(t){if("object"!=typeof t||null===t)return;const e=t.id;return"string"==typeof e||"number"==typeof e?e:void 0}function ut(t){if("object"!=typeof t||null===t)return;const e=t.blockType;return"string"==typeof e?e:void 0}function ct(t,e){return e.every(t=>void 0!==lt(t))?function(t,e){const n=[],i=new Map;for(let e=0;e<t.length;e+=1){const n=lt(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=lt(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];ut(u)===ut(o)?(l!==s&&n.push({kind:"move",from:l,to:s,value:o}),dt(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)dt(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 dt(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 ht={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"},ft=[0,500,1e3,2e3],pt=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??mt,l=t.onHeartbeatTimeout,u=void 0===t.log?O:I(t.log),c=void 0===t.warn?P:I(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 rt(t.a11yLocale,e)}(t),h=void 0!==t.dataMerge?new H({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 m,p=new y({onStructuralChange:()=>{this.#M()},onVisibilityChange:(t,e)=>{e&&this.d[3].notifyVisible(t)}},{...void 0!==t.intersectionRootMargin?{intersectionRootMargin:t.intersectionRootMargin}:{}}),g=new Q(J(t=>this.#R(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)}}),v=new T(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}:{}}),b=new E(()=>{}),w=new R({...void 0!==t.heartbeatMs?{timeoutMs:t.heartbeatMs}:{},onTimeout:()=>{this.#O()}});this.d=[e,f,p,g,v,b,w,n,i,r,s,o,a,l,u,c,[],d,h],this.l=[void 0,void 0,void 0,negotiateProtocol(void 0),!1,null,0,null,new Set]}start(){if(this.l[4])return!1;this.l[4]=!0;const t=this.d[10];if(gt(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=gt(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.#j(),this.#F()&&(this.d[4].attach(),this.d[0].emitWhile("init",{timestamp:Date.now()},()=>this.l[4]),this.#F()))for(const t of ft){if(!this.#F())return;if(0===t){if(this.d[12](this.d[11]),!this.#F())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&>(this.d[10])&&this.#G(()=>{this.d[10].removeEventListener("DOMContentLoaded",t)});for(const t of this.d[16])this.#G(()=>{clearTimeout(t)});return this.d[16].length=0,this.#G(()=>{this.d[6].stop()}),this.#G(()=>{this.d[4].detach()}),this.#G(()=>{this.d[2].stop()}),this.#G(()=>{this.d[3].destroy()}),this.#G(()=>{this.d[18]?.destroy()}),this.d[1].clear(),this.d[5].markDisconnected()}#P(){this.#D(),this.#G(()=>{this.d[17]?.detach()})}#G(t){try{t()}catch(t){this.d[14]("cleanup failed:",t)}}refreshCache(){this.l[4]&&this.#M()}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]}#j(){if(!this.l[4])return;const t=this.d[1].buildFromRoot(this.d[10]);if(this.d[14]("cache",t),this.#F()&&(this.d[0].emitWhile("cacheRefresh",t,()=>this.l[4]),this.#F()))for(const t of this.d[1].values()){if(!this.#F())return;this.d[2].observeElement(t.element)}}#M(){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.#j(),this.#F()){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]=ot(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.#z(i)}}async#z(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;for(const[i,r]of this.d[1].entries()){if(!this.l[4]||this.l[7]!==t)return;for(const s of r){const r=Z(e.fields,i,s.locale??t.locale,void 0!==s.locale);if(void 0===r)continue;if(!this.l[4]||this.l[7]!==t)return;const o=this.#q(s,r,e.fields,n);if(!this.l[4]||this.l[7]!==t)return;const a={target:s,value:o,allFields:e.fields,identity:t.identity,data:e};if(!this.l[4]||this.l[7]!==t)return;this.d[3].schedule(a)}}this.#B(e.fields,t.locale)}#B(t,e){if(0===this.d[1].fieldCount)return;let n;for(const[i,r]of Object.entries(t)){if(this.l[8].has(i))continue;if(yt.has(i))continue;if(!bt(r))continue;const t=wt(i,e);if(void 0===this.d[1].get(i)&&(t===i||void 0===this.d[1].get(t))){if(void 0===n){n=new Set;for(const[t,e]of this.d[1].entries())for(const i of e)void 0!==i.locale&&n.add(`${t}_${i.locale}`)}n.has(i)||(this.l[8].add(i),this.d[15](`[live-preview] update arrived for field "${i}" 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=C(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}}#F(){return this.l[4]}#R(t){const e=this.l[7];if(null===e||void 0===t.identity||!vt(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(ht,t))return ht[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(_.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 q.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 B.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){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||!vt(i.identity,e))return;const r=()=>this.l[4]&&this.l[7]===i&&vt(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.#F())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.#F()){if(e&&this.#J()){if(this.d[17]?.announceDisconnected(),this.d[0].emitWhile("disconnect",{reason:"timeout",timestamp:Date.now()},()=>this.#J()),!this.#F())return;if(this.#J()&&(this.d[14]("connection","connected","→","disconnected"),!this.#F()))return}this.#F()&&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})}#J(){return this.l[4]&&"disconnected"===this.d[5].status&&null===this.l[7]}};function gt(t){return 9===t.nodeType}function mt(t){if("undefined"==typeof window)return;const e=[];window.parent!==window&&e.push(window.parent),window.opener instanceof Window&&e.push(window.opener),T.sendReady(e,t)}function vt(t,e){return t.generation===e.generation&&t.revision===e.revision}var yt=new Set(["id","_id","createdAt","updatedAt","createdBy","updatedBy","_status","globalType","collection","locale","localized"]);function bt(t){return null!=t&&("string"==typeof t||"number"==typeof t||"boolean"==typeof t||"bigint"==typeof t)}function wt(t,e){if(!e)return t;const n=`_${e}`;return t.endsWith(n)?t.slice(0,-n.length):t}var St,At=class{#Q=new Map;#X=new Map;on(t,e){return this.#Y(this.#Q,t,e)}once(t,e){return this.#Y(this.#X,t,e)}off(t,e){this.#Z(this.#Q,t,e),this.#Z(this.#X,t,e)}async emit(t,e){await this.#K(t,e)}async emitWhile(t,e,n){return this.#K(t,e,n)}async#K(t,e,n){const i=()=>n?.()??!0;if(!i())return!1;const r=this.#Q.get(t);if(r)for(const n of[...r]){if(!i())return!1;if(await this.#tt(n,e,t),!i())return!1}if(!i())return!1;const s=this.#X.get(t);if(s&&s.size>0){const n=[...s];this.#X.delete(t);for(const r of n){if(!i())return!1;if(await this.#tt(r,e,t),!i())return!1}}return i()}listenerCount(t){return(this.#Q.get(t)?.size??0)+(this.#X.get(t)?.size??0)}removeAllListeners(t){if(void 0===t)return this.#Q.clear(),void this.#X.clear();this.#Q.delete(t),this.#X.delete(t)}eventNames(){const t=new Set;for(const e of this.#Q.keys())t.add(e);for(const e of this.#X.keys())t.add(e);return[...t]}#Y(t,e,n){let i=t.get(e);return i||(i=new Set,t.set(e,i)),i.add(n),()=>{this.#Z(t,e,n)}}#Z(t,e,n){const i=t.get(e);void 0!==i&&(i.delete(n),0===i.size&&t.delete(e))}async#tt(t,e,n){try{await t(e)}catch(t){const e="string"==typeof n||"number"==typeof n?String(n):"<event>";U(`[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=Ct();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 kt(t){if("undefined"!=typeof process){const e=process.env[t];if("string"==typeof e&&e.length>0)return e}const e=Ct();if(e){const n=e[t];if("string"==typeof n&&n.length>0)return n}}function Ct(){if("undefined"==typeof __INLINE_RUNTIME_BUILD__||!__INLINE_RUNTIME_BUILD__){if(void 0!==St)return St??void 0;St=null;try{const t=new Function("try { return import.meta && import.meta.env; } catch (_) { return undefined; }")();if(t&&"object"==typeof t)return St=t}catch{}}}var Tt=/^https?:\/\/(localhost|127\.0\.0\.1)(?::\d+)?$/i,$t=/^https?:\/\/[^/?#\s]+$/i,Nt=["PAYLOAD_ADMIN_ORIGIN","PUBLIC_PAYLOAD_ADMIN_ORIGIN","NEXT_PUBLIC_PAYLOAD_ADMIN_ORIGIN"],xt=class{#et;constructor(t={}){const e=new Set;for(const n of t.additionalOrigins??[]){const t=Rt(n);void 0!==t&&e.add(t)}for(const t of Nt){const n=kt(t);if(void 0!==n)for(const t of n.split(",")){const n=Rt(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.#et=[e,n,i,void 0!==n,void 0]}matches(t){return 0!==t.length&&"null"!==t&&(void 0!==this.#et[4]?t===this.#et[4]:!!this.#et[0].has(t)||0===this.#et[0].size&&void 0!==this.#et[1]&&t===this.#et[1]||!(!this.#et[2]||!Tt.test(t)))}lockOrigin(t){return!!this.matches(t)&&(this.#et[4]=t,!0)}unlockOrigin(){const t=this.#et[4];return this.#et[4]=void 0,t}get lockedOrigin(){return this.#et[4]}enumerate(){if(void 0!==this.#et[4])return[this.#et[4]];const t=new Set(this.#et[0]);if(0===this.#et[0].size&&void 0!==this.#et[1]&&t.add(this.#et[1]),this.#et[2])for(const e of Mt)t.add(`http://localhost:${String(e)}`),t.add(`http://127.0.0.1:${String(e)}`);return[...t]}get referrerWasAvailable(){return this.#et[3]}get isProductionUnconfigured(){return!(!isInIframe()||this.#et[0].size>0||this.#et[2]||void 0!==this.#et[1])}get isReferrerOnlyTrust(){return!(this.#et[0].size>0||this.#et[2]||void 0===this.#et[1])}},Mt=[3e3,3001,3333,4e3,4321,5e3,5173,5174,8e3,8080,8888,9e3];function Rt(t){const e=t.trim();if(0!==e.length)try{const t=new URL(e);if("http:"!==t.protocol&&"https:"!==t.protocol)return;if(!$t.test(t.origin))return;return t.origin}catch{return}}var Et,It=()=>{},Ot=class{#nt;#it;#rt=new Set;#et="staging";constructor(t,e){this.#nt=t,this.#it=e}assertOpen(){if("closed"===this.#et)throw new Error(`Plugin context for "${this.#nt}" is no longer active`)}get active(){return"active"===this.#et}eligible(){return"closed"!==this.#et}own(t){return this.assertOpen(),this.#st({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.#st(n);if("active"===this.#et)try{this.#ot(n)}catch(t){throw this.#at(n),t}return i}commit(){if("staging"!==this.#et)throw new Error(`Plugin context for "${this.#nt}" cannot be committed`);this.#et="committing";try{for(const t of this.#rt)this.#ot(t);this.#et="active"}catch(t){throw this.close(),t}}close(){if("closed"!==this.#et){this.#et="closed";for(const t of[...this.#rt].reverse())this.#at(t);this.#rt.clear()}}#st(t){return this.#rt.add(t),()=>{this.#at(t)}}#ot(t){if(t.disposed||void 0!==t.cleanup||void 0===t.acquire)return;const e=t.acquire();t.cleanup=e??It}#at(t){if(t.disposed)return;t.disposed=!0,this.#rt.delete(t);const e=t.cleanup;if(t.cleanup=void 0,void 0!==e)try{C(e())&&this.#it(`plugin "${this.#nt}" cleanup returned a Promise/thenable; cleanups must be synchronous`)}catch(t){this.#it(`plugin "${this.#nt}" cleanup failed:`,t)}try{t.finalize?.()}catch(t){this.#it(`plugin "${this.#nt}" cleanup failed:`,t)}}},Ut=class extends At{#lt;#ut;#ct=new Set;constructor(t,e){super(),this.#lt=t,this.#ut=e}on(t,e){return this.#dt("on",t,e)}once(t,e){return this.#dt("once",t,e)}off(t,e){const n=e;for(const e of[...this.#ct])e.event===t&&e.handler===n&&e.dispose()}emit(t,e){return this.#ut.assertOpen(),this.#lt.emit(t,e)}emitWhile(t,e,n){return this.#ut.assertOpen(),this.#lt.emitWhile(t,e,()=>{if(!this.#ut.eligible())return!1;const t=n();return!!this.#ut.eligible()&&t})}listenerCount(t){let e=0;for(const n of this.#ct)n.event===t&&(e+=1);return e}removeAllListeners(t){for(const e of[...this.#ct])void 0!==t&&e.event!==t||e.dispose()}eventNames(){const t=new Set;for(const e of this.#ct)t.add(e.event);return[...t]}#dt(t,e,n){this.#ut.assertOpen();const i=n,r=[...this.#ct].find(n=>n.kind===t&&n.event===e&&n.handler===i);if(void 0!==r)return r.dispose;let s=It,o=!0;const a=async e=>{this.#ut.active&&o&&("once"===t&&s(),await n(e))},l={kind:t,event:e,handler:i,dispose:It};return s=this.#ut.stage(()=>this.#lt[t](e,a),()=>{o=!1,this.#ct.delete(l)}),l.dispose=s,this.#ct.add(l),s}},Pt=class{#lt;#ht;#ft;#pt;#it;#gt=new Map;#mt=new Map;#vt=new Map;#yt=new Set;#bt=new Map;#wt=Promise.resolve();#St=0;constructor(t){this.#lt=t.events,this.#ht=t.config,this.#ft=t.registerFieldRenderer,this.#it=I(t.log);const e=t.onTransformError;this.#pt=void 0===e?void 0:I((...t)=>{const n=t[0];if(n instanceof Error)try{return e(n)}catch(t){return void this.#it("transform error reporter failed:",t)}})}register(t){return this.#St>0?this.#At(t):this.#kt(()=>this.#At(t))}unregister(t){return this.#St>0?this.#Ct(t):this.#kt(async()=>{await this.#Ct(t)})}destroyAll(){return this.#St>0?this.#Tt():this.#kt(async()=>{await this.#Tt()})}applyTransforms(t,e,n,i){const r=this.#bt.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=C(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.#it(`transform for "${t}" failed:`,r),this.#pt?.(r),e}}return s}list(){return[...this.#gt.keys()]}get size(){return this.#gt.size}async#At(t){if(this.#gt.has(t.name)||this.#mt.has(t.name)||this.#vt.has(t.name))return void this.#it(`plugin "${t.name}" already registered`);const e=new Ot(t.name,this.#it),n=this.#$t(t.name,e),i={scope:e,cancelled:!1};this.#mt.set(t.name,i);try{if(await this.#Nt(()=>t.init(n)),i.cancelled)return;e.commit()}catch(n){return e.close(),void(i.cancelled||this.#it(`plugin "${t.name}" init failed:`,n))}finally{this.#mt.get(t.name)===i&&this.#mt.delete(t.name)}this.#gt.set(t.name,{plugin:t,scope:e}),this.#it(`plugin "${t.name}" registered`)}#$t(t,e){return{events:new Ut(this.#lt,e),registerFieldRenderer:t=>{e.stage(()=>{const e=this.#ft(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.#bt.get(t);return void 0===e?this.#bt.set(t,[i]):e.push(i),()=>{i.active=!1;const e=this.#bt.get(t);if(void 0===e)return;const n=e.indexOf(i);n>=0&&e.splice(n,1),0===e.length&&this.#bt.delete(t)}})},registerCleanup:t=>{e.own(t)},getConfig:()=>this.#ht,log:(...e)=>{this.#it(`[${t}]`,...e)}}}#Ct(t){const e=this.#mt.get(t);if(void 0!==e)return e.cancelled=!0,e.scope.close(),Promise.resolve();const n=this.#vt.get(t);if(void 0!==n)return this.#yt.has(t)?Promise.resolve():n;const i=this.#gt.get(t);if(void 0===i)return Promise.resolve();this.#gt.delete(t),i.scope.close();const r=Promise.resolve().then(()=>this.#xt(t,i.plugin));return this.#vt.set(t,r),r.then(()=>{this.#vt.get(t)===r&&this.#vt.delete(t)}),r}async#xt(t,e){if(void 0!==e.destroy){this.#yt.add(t);try{await this.#Nt(()=>e.destroy?.())}catch(e){this.#it(`plugin "${t}" destroy failed:`,e)}finally{this.#yt.delete(t)}}}async#Tt(){for(const t of this.#mt.values())t.cancelled=!0,t.scope.close();const t=[...this.#gt.keys()];for(const e of t)await this.#Ct(e)}async#Nt(t){this.#St+=1;try{await t()}finally{this.#St-=1}}#kt(t){const e=this.#wt.then(t);return this.#wt=e.catch(t=>{this.#it("plugin manager mutation failed:",t)}),e}},Lt=class{#Mt;#Rt;#Et=new Map;constructor(t){this.#Mt=t,this.#Rt={...t}}get renderers(){return this.#Rt}resolve(t){return this.#Rt[t]}register(t){const e=t.name,n={renderer:t},i=this.#Et.get(e);void 0===i?this.#Et.set(e,[n]):i.push(n),this.#Rt[e]=t;let r=!0;return()=>{if(!r)return;r=!1;const t=this.#Et.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.#Et.delete(e),!s)return;const o=t.at(-1),a=o?.renderer??this.#Mt[e];void 0===a?Reflect.deleteProperty(this.#Rt,e):this.#Rt[e]=a}}},jt=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"]),Ft=new Set(["script","style","iframe","object","embed","link","meta","base","form","input","button","select","textarea","svg","math","template","frame","frameset","noframes","noscript"]),Ht=new Set(["id","class","lang","dir","title","role","tabindex"]),Dt={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"])},Gt=new Set(["href","src","cite","poster"]),Wt=class extends Error{name="SanitizerEnvironmentError"};function setSanitizerDocument(t){Et=t??void 0}function sanitizeHtml(t,e){const n=zt();if(!n)throw new Wt("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(Dt))t.set(e,n);return{allowedTags:jt,attrByTag:t}}const e=new Set(jt);for(const n of t.additionalAllowedTags??[])e.add(n);const n=new Map;for(const[t,e]of Object.entries(Dt))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,Vt(r.content,i),r.innerHTML}function zt(){return Et||("undefined"!=typeof document?document:void 0)}function Vt(t,e){for(const n of Array.from(t.childNodes))1===n.nodeType?_t(n,e):8===n.nodeType&&n.remove()}function _t(t,e){const n=t.tagName.toLowerCase();if(Ft.has(n))t.remove();else{if(!e.allowedTags.has(n)){Vt(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?Ht.has(n)||n.startsWith("aria-")||n.startsWith("data-")||(i?.has(n)?Gt.has(n)&&!isSafeUrl(e.value)?t.removeAttribute(e.name):"srcset"!==n||qt(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),Vt(t,e)}}function qt(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 Bt=new Map;function Jt(t,e){Bt.set(t,e)}var Qt={1:"left",2:"center",3:"right",4:"justify"},Xt=new Set(["left","center","right","justify","start","end"]);function Yt(t){const e=t.format;if("string"==typeof e&&Xt.has(e))return e;if("number"==typeof e){const t=Qt[e];if(void 0!==t)return t}}function Zt(t){const e=t.indent;return"number"==typeof e&&e>0?e:0}function Kt(t){return"rtl"===t.direction?' dir="rtl"':"ltr"===t.direction?' dir="ltr"':""}function te(t){const e=Yt(t),n=Zt(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 ee=Object.freeze({"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="}),ne=/[&<>"'/`=]/g;function escapeHtml(t){return""===t?"":t.replace(ne,t=>ee[t])}var ie=Object.freeze({"&":"&","<":"<",">":">",'"':""","'":"'"}),re=/[&<>"']/g;function escapeHtmlAttribute(t){return""===t?"":t.replace(re,t=>ie[t])}function se(t){return escapeHtml(t).replace(/\r\n|\r|\n/g,"<br>")}var oe=new Set(["h1","h2","h3","h4","h5","h6"]),ae=(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 le(t){if("string"==typeof t.text)return t.text;if(!t.children)return"";let e="";for(const n of t.children)e+=le(n);return e}function ue(t){return t.replace(/[^a-zA-Z0-9_-]/g,"")}var ce=new Map;function de(t){return ce.get(t)}function he(t){return t.replace(/[^a-zA-Z0-9_-]/g,"-").toLowerCase()}Jt("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}),Jt("paragraph",(t,e)=>{const n=e.renderChildren(t.children??[]);return`<p${Kt(t)}${te(t)}>${n}</p>`}),Jt("heading",(t,e)=>{const n="string"==typeof t.tag?t.tag.toLowerCase():"h2",i=oe.has(n)?n:"h2",r=e.renderChildren(t.children??[]);return`<${i}${Kt(t)}${te(t)}>${r}</${i}>`}),Jt("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}${Kt(t)}${te(t)}${r}${s}>${o}</${i}>`}),Jt("listitem",(t,e)=>{const n=e.renderChildren(t.children??[]);if("boolean"==typeof t.checked)return`<li role="checkbox" aria-checked="${t.checked?"true":"false"}"${te(t)}>${n}</li>`;const i="number"==typeof t.value?` value="${escapeHtml(String(t.value))}"`:"";return`<li${Kt(t)}${te(t)}${i}>${n}</li>`}),Jt("link",ae),Jt("autolink",ae),Jt("quote",(t,e)=>{const n=e.renderChildren(t.children??[]);return`<blockquote${Kt(t)}${te(t)}>${n}</blockquote>`}),Jt("code",t=>{const e=ue("string"==typeof t.language?t.language:"");return`<pre><code${""===e?"":` class="language-${e}"`}>${escapeHtml(le(t))}</code></pre>`}),Jt("code-highlight",t=>{const e="string"==typeof t.text?t.text:"";return`<span${"string"==typeof t.highlightType?` class="token-${ue(t.highlightType)}"`:""}>${escapeHtml(e)}</span>`}),Jt("linebreak",()=>"<br>"),Jt("horizontalrule",()=>"<hr>"),Jt("tab",()=>"\t"),Jt("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)}),Jt("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>`}),Jt("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=he(i);if(""!==i){const t=de(i)??de(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-${he(t)}="${escapeHtml(n)}"`)}return`<div${0===s.length?"":` ${s.join(" ")}`}></div>`});var fe={renderChildren:me,resolveAlignment:Yt,resolveIndent:Zt};function pe(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 ge(t){return pe(t)?t.root.children.map(ye).join("\n").trim():""}function me(t){let e="";for(const n of t)e+=ve(n);return e}function ve(t){const e=(n=t.type,Bt.get(n));var n;return e?e(t,fe):void 0!==t.children?me(t.children):""}function ye(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+=ye(n);return e}function be(){const t=new WeakSet;return{name:"text",render:J((e,n)=>{const i=e.element,r=function(t){return null==t?"":pe(t)?ge(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),P(`[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=se(r):i.textContent=r);i.value=r})}}function we(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 Se={name:"textarea",render(t,e){const n=t.element,i=pe(e)?ge(e):we(e);"INPUT"!==n.tagName&&"TEXTAREA"!==n.tagName?n.innerHTML=se(i):n.value=i}},Ae={name:"richText",render:J((t,e)=>{if(pe(e))t.element.innerHTML=function(t,e={}){if(!pe(t))return"";const n=me(t.root.children);return!1===e.sanitize||void 0===zt()?n:sanitizeHtml(n)}(e);else{if("string"!=typeof e)return!1;t.element.innerHTML=sanitizeHtml(e)}})},ke={name:"html",render(t,e){if(null==e)return void(t.element.textContent="");const n="string"==typeof e?e:we(e);t.element.innerHTML=sanitizeHtml(n)}},Ce={name:"url",render(t,e,n){const i=t.element,r=we(e);if("A"===i.tagName){const s=i,o=t.hrefField,a=void 0===o||0===o.length?e:Z(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}},Te={name:"image",render:J((t,e,n)=>{const i=t.element,r=$e(e),s=void 0!==t.locale,o=function(t,e,n,i,r,s){if(void 0!==n&&n.length>0){const t=Z(i,n,r,s);if("string"==typeof t&&isSafeUrl(t))return t;const e=$e(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=Z(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 $e(t){if("object"==typeof t&&null!==t)return t}var Ne={name:"upload",render:J((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>`})},xe={name:"relationship",render(t,e){const n=t.element,i=function(t){return null==t?[""]:Array.isArray(t)?t.map(Me):[Me(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 Me(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 we(t)}var Re={name:"select",render(t,e){const n=t.element,i=Ee(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 Ee(t){return Array.isArray(t)?t.map(t=>Ee(t)).join(", "):we(t)}var Ie={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}},Oe=new Map,Ue=new Map;function Pe(t,e){const n=t??"";if(null==e)return n;const i=Le(e);return"{}"===i?n:`${n}|${i}`}function Le(t){if(null===t||"object"!=typeof t)return JSON.stringify(t);if(Array.isArray(t))return`[${t.map(t=>Le(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)}:${Le(n)}`)}return`{${i.join(",")}}`}function je(t){for(;t.size>64;){const e=t.keys().next().value;if(void 0===e)break;t.delete(e)}}var Fe={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:we(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?He(s,n):r)):void(i.textContent=o?He(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 He(t,e){const n=e.locale??detectInitialLocale();try{return function(t,e){const n=Pe(t,e),i=Ue.get(n);if(void 0!==i)return Ue.delete(n),Ue.set(n,i),i;const r=new Intl.DateTimeFormat(t,e);return Ue.set(n,r),je(Ue),r}(n,{dateStyle:"medium",timeStyle:"short"}).format(t)}catch{return t.toISOString()}}var De={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(we(e));Number.isNaN(r)?i.textContent=we(e):"INPUT"!==i.tagName?i.textContent=function(t,e){const n=e.locale??detectInitialLocale();try{return function(t,e){const n=Pe(t,e),i=Oe.get(n);if(void 0!==i)return Oe.delete(n),Oe.set(n,i),i;const r=new Intl.NumberFormat(t,e);return Oe.set(n,r),je(Oe),r}(n).format(t)}catch{return String(t)}}(r,n):i.value=String(r)}},Ge=/\{\{([\s\S]*?)\}\}/g;function We(t,e,n,i){const r="object"==typeof e&&null!==e?e:null;return t.replace(Ge,(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 ze={name:"array",render:J((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+=Ve(t,e[i],i);return n}(i,e);return void(n.innerHTML=sanitizeHtml(t))}const r=t.arraySeparator??", ";n.textContent=e.map(_e).join(r)})};function Ve(t,e,n){return We(t,e,n,we)}function _e(t){return we(t)}var qe="data-payload-key",Be="data-payload-nested-key",Je="data-payload-nested-template";function Qe(t){const{template:e,container:n,patches:i,nextItems:r,store:s,forceRender:o=!1}=t,a=Xe(n,e,i,r,o,s);return null===a?null:Ye(a,s)}function Xe(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=sn(a,qe),u=new Set,c=[];for(let d=0;d<n.length;d+=1){const h=n[d],f=rn(h);let p=void 0===f?a[d]??null:on(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?an(t.ownerDocument,e,h,d):void 0;if(null===m)return null;const v=void 0===m?[]:Ze(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 Ye(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]&&(tn(t[0],t[1]),t[1].replaceWith(t[0])),void 0!==t[2]&&Ye(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)nn(a,t);return o}function Ze(t,e,n,i,r){const s=sn(null===t?[]:Ke(t),Be),o=rn(n),a=void 0!==o?i?.get(o):void 0,l=[];for(const t of Ke(e)){const e=t.getAttribute(Be);if(null===e)continue;const i=on(s,e)??null,o=t.getAttribute(Je),u=o?i:null,c=u?.getAttribute(Je)??null;let d;if(o){const i=en(n,e);if(void 0!==i||null!==u){const n=i??[],s=ct(null===u?[]:en(a,e)??[],n),l=null!==u&&c!==o;if((s.length>0||l)&&(d=Xe(u??t,o,s,n,l,r)??void 0,void 0===d))return null}}l.push([u,t,d])}return l}function Ke(t){return Array.from(t.querySelectorAll(`[${Be}]`)).filter(e=>{let n=e.parentElement;for(;null!==n&&n!==t;){if(n.hasAttribute(Be))return!1;n=n.parentElement}return n===t})}function tn(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 en(t,e){if("object"!=typeof t||null===t)return;const n=t[e];return Array.isArray(n)?n:void 0}function nn(t,e){const n=rn(e);void 0!==n&&t.set(n,e)}function rn(t){if("object"!=typeof t||null===t)return;const e=t.id;return"string"==typeof e||"number"==typeof e?String(e):void 0}function sn(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 on(t,e){return t.get(e)?.pop()}function an(t,e,n,i){const r=function(t,e,n){return We(t,e,n,we)}(e,n,i),s=sanitizeHtml(r),o=t.createElement("template");o.innerHTML=s;const a=o.content.firstElementChild;if(!a)return null;const l=rn(n);return void 0!==l&&a.setAttribute(qe,l),a}function ln(){const t=new WeakMap,e=new WeakSet,n=new WeakMap;return{name:"structural-array",render:J((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),P(`[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=un(s),u=ct(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=Qe({template:o,container:s,patches:u,nextItems:r,store:n,forceRender:c});return null!==d&&(t.set(s,{values:r.slice(),template:o,domSnapshot:un(s)}),!!d&&void 0)})}}function un(t){return Array.from(t.children,t=>t.getAttribute(qe))}var cn=new Map,dn=[Se,Ae,ke,Ce,{...Ce,name:"email"},Te,Ne,xe,Re,{...Re,name:"radio"},Ie,Fe,De,ze,{...ze,name:"blocks"}],hn=class{#It=new At;#Ot;#Ut;#Pt;#gt;#it;#Lt=!1;#jt=!1;#Ft=null;constructor(t={}){const e=t.debug??isDevMode();this.#it=e?(...t)=>{L("[live-preview]",...t)}:O,this.#Ot=new xt({...void 0!==t.allowedOrigins?{additionalOrigins:t.allowedOrigins}:{},...void 0!==t.disableReferrerDetection?{enableReferrerDetection:!t.disableReferrerDetection}:{},...void 0!==t.disableLocalhostMatching?{enableLocalhostMatching:!t.disableLocalhostMatching}:{}}),this.#Ot.isProductionUnconfigured&&this.#it("no trusted origin could be detected — set allowedOrigins or PAYLOAD_ADMIN_ORIGIN"),this.#Ut=new Lt(function(t=[]){const e={};for(const n of t)e[n.name]=n;for(const[t,n]of cn)e[t]=n;return Object.freeze(e)}([be(),...dn,ln()])),this.#gt=new Pt({events:this.#It,config:Object.freeze({...t}),registerFieldRenderer:t=>this.#Ut.register(t),onTransformError:t=>{this.#It.emit("error",{error:t,context:"transform"})},log:this.#it}),this.#Pt=new pt({...void 0!==t.root?{root:t.root}:{},renderers:this.#Ut.renderers,resolveRenderer:t=>this.#Ut.resolve(t),transformValue:(t,e,n,i)=>this.#gt.applyTransforms(t,e,n,i),originMatcher:t=>this.#Ot.matches(t),readyTargets:this.#Ot.enumerate(),emitter:this.#It,...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.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.#Ot.unlockOrigin()},...void 0!==t.validateToken?{validateToken:t.validateToken}:{},log:this.#it}),this.#It.on("connect",t=>{this.#Ot.lockOrigin(t.origin)}),!1!==t.autoStart&&this.start()}start(){if(this.#jt)return!1;if(this.#Lt)return this.#Pt.start(),!0;if(!isInPreviewContext())return!1;const t=this.#Pt.start();return t&&(this.#Lt=!0),t}destroy(){if(null!==this.#Ft)return this.#Ft;let t,e;this.#jt=!0;const n=new Promise((n,i)=>{t=n,e=i});this.#Ft=n;try{this.#Pt.destroy(),this.#gt.destroyAll().finally(()=>{this.#It.removeAllListeners()}).then(t,e)}catch(t){this.#It.removeAllListeners(),e(t)}return n}async use(t){if(this.#jt)throw new Error("LivePreviewClient: already destroyed");await this.#gt.register(t)}async unuse(t){await this.#gt.unregister(t)}refreshCache(){this.#Pt.refreshCache()}get events(){return this.#It}get plugins(){return this.#gt.list()}get status(){return this.#Pt.status}get updateCount(){return this.#Pt.updateCount}get destroyed(){return this.#jt}};function initLivePreview(t={}){const e=new hn({...t,autoStart:!1});return e.start()?e:null}var fn,pn="1.0.4";function setCspCrypto(t){fn=t??void 0}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(fn?.getRandomValues)return fn;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)}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'"}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(" ")}function bind(t,e){return gn(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 gn(n.join("."),e)}function gn(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),n}for(const[t,e]of[[At,"EventEmitter"],[hn,"LivePreviewClient"],[xt,"OriginDetector"]])Object.defineProperty(t,"name",{configurable:!0,value:e});var mn=!0;export{mn as CORE_ENTRY,At as EventEmitter,A as LIBRARY_PROTOCOL_VERSION,hn as LivePreviewClient,xt as OriginDetector,pn as VERSION,bind,bindByPath,buildFrameAncestors,buildScriptSrcWithNonce,detectInitialLocale,escapeHtml,escapeHtmlAttribute,generateCspNonce,hasCapability,initLivePreview,isDevMode,isExternalHttpUrl,isInIframe,isInPopup,isInPreviewContext,isSafeUrl,negotiateProtocol,sanitizeHtml,setCspCrypto,setSanitizerDocument};
|
|
1
|
+
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=[t,e,n,i,r,s,o,a,l,u,c,d,h,"type"],p=`[${t}]`,g=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"]),m=class{#t=new Map;#e=new WeakMap;#n;constructor(t={}){this.#n=t.filter??v}buildFromRoot(t){const e=performance.now();this.clear();const n=t.querySelectorAll(p);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(f){const p=f.getAttribute(t);if(null===p||0===p.length)return;const m=f.getAttribute(e),v=function(t){const n=t.getAttribute(e);if(null!==n&&g.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"}(f),y=f.getAttribute(n),b=f.getAttribute(i),w=f.getAttribute(r),S=f.getAttribute(s),A=f.getAttribute(o),k=f.getAttribute(a),C=f.getAttribute(l);return{element:f,fieldName:p,fieldType:v,explicitFieldType:null!==m&&g.has(m),...null!==y&&y.length>0?{targetAttribute:y}:{},...null!==b&&b.length>0?{hrefField:b}:{},...null!==w&&w.length>0?{srcField:w}:{},...null!==S&&S.length>0?{altField:S}:{},...null!==A?{arrayTemplate:A}:{},...null!==k?{arraySeparator:k}:{},...null!==C&&C.length>0?{locale:C}:{}}}};function v(){return!0}var y=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:[...f]})}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&&f.includes(n.attributeName)&&(n.attributeName===t||1===n.target.nodeType&&n.target.hasAttribute(t)))return!0;for(const t of n.addedNodes)if(b(t))return!0;for(const t of n.removedNodes)if(b(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 b(e){if(1!==e.nodeType)return!1;const n=e;return!!n.hasAttribute(t)||null!==n.querySelector(`[${t}]`)}function w(t){if(!Array.isArray(t))return[];const e=[];for(const n of t){const t=S(n);t&&e.push(t)}return e}function S(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=w(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=w(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 A=4,k={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(k))i>=e&&r.add(t);return{ours:4,...void 0!==e?{theirs:e}:{theirs:void 0},negotiated:i,capabilities:r}}function hasCapability(t,e){return t.capabilities.has(e)}function C(t){return("object"==typeof t&&null!==t||"function"==typeof t)&&"function"==typeof t.then&&(Promise.resolve(t).catch(()=>{}),!0)}var T=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||x(e.data))&&N(e.fieldSchemaJSON,t=>Array.isArray(t))&&N(e.globalSlug,t=>"string"==typeof t)&&N(e.collectionSlug,t=>"string"==typeof t)&&N(e.locale,t=>"string"==typeof t)&&N(e.ready,t=>"boolean"==typeof t)&&N(e.previewToken,t=>"string"==typeof t)&&N(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 M)null===Reflect.get(e,t)&&Reflect.deleteProperty(e,t);if(!Array.isArray(e.fieldSchemaJSON))return e;let n;try{n=w(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.action,t=>"updated"===t||"created"===t||"deleted"===t)&&!!$(e.slug,t=>"string"==typeof t)&&!!$(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=x(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{C(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 $(t,e){return void 0===t||e(t)}function N(t,e){return null==t||e(t)}function x(t){if("object"!=typeof t||null===t)return!1;const e=Object.getPrototypeOf(t);return null===e||null===Object.getPrototypeOf(e)}var M=["data","fieldSchemaJSON","globalSlug","collectionSlug","locale","ready","previewToken","protocolVersion"],R=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]}},E=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 I(t){return(...e)=>{try{C(t(...e))}catch{}}}function O(){}var U=I((...t)=>console.error(...t)),P=I((...t)=>console.warn(...t)),L=I((...t)=>console.debug(...t));function j(t){for(const e of t){const t=e.codePointAt(0);if(void 0!==t&&(t<=31||127===t))return!0}return!1}function F(t){if(void 0===t||0===t.length||t.length>128||"."===t||".."===t||t.includes("/")||t.includes("\\")||t.includes("?")||t.includes("#")||j(t))return!1;try{return encodeURIComponent(t),!0}catch{return!1}}var H=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?O:I(t.log),null,0,0]}canMerge(t){try{return t.globalSlug?F(t.globalSlug):!!F(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("\\")||j(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(),!D(this.s,e))return{status:"superseded"};if(!this.canMerge(t))return D(this.s,e)?{status:"unavailable"}:{status:"superseded"};if(!D(this.s,e))return{status:"superseded"};const r=this.s[3]??("function"==typeof fetch?fetch:void 0);if(!D(this.s,e))return{status:"superseded"};if(void 0===r)return{status:"unavailable"};if(i=new AbortController,!D(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(!D(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(!D(this.s,e)||G(i.signal))return{status:"superseded"};const u=l.ok;if(!D(this.s,e))return{status:"superseded"};if(!u){const t=l.status;return D(this.s,e)?(this.s[4]("merge HTTP",t,o),D(this.s,e)?{status:"unavailable"}:{status:"superseded"}):{status:"superseded"}}const c=await l.json();return!D(this.s,e)||G(i.signal)?{status:"superseded"}:null===c||"object"!=typeof c||Array.isArray(c)?(this.s[4]("merge invalid",o),D(this.s,e)?{status:"unavailable"}:{status:"superseded"}):{status:"merged",doc:c}}catch(t){return!D(this.s,e)||null!==i&&G(i.signal)?{status:"superseded"}:(this.s[4]("merge exception",t),D(this.s,e)?{status:"unavailable"}:{status:"superseded"})}finally{null!==i&&D(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 D(t,e){return t[6]===e}function G(t){return t.aborted}var W=new Set(["http:","https:","mailto:","tel:"]),z=/^\s*(?:javascript|data|vbscript|file|blob|about)\s*:/i,V=/^(?:\.{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(z.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 W.has(t.protocol)}catch{return V.test(e)}}function isExternalHttpUrl(t){if(!isSafeUrl(t))return!1;const e=t.trim();return/^https?:\/\//i.test(e)||/^\/\/[^/]/.test(e)}var _=new Set(["style","srcdoc","formaction","form","id","name","is","srcset","imagesrcset"]),q=new Set(["href","src","poster","cite","action","xlink:href","data"]),B=new WeakSet;function J(t){return B.add(t),t}var Q=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(!X(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;X(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){X(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.#N(this.s[9],t),this.#N(this.s[10],t);for(const e of this.s[11])this.#N(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.#x())},this.s[1]);this.s[13]===t&&(this.s[12]=n)}#x(){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]&&X(t.identity,this.s[16])}#T(t){const e=this.s[0];return!1!==e(t)||(n=e,!B.has(n));var n}#N(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 X(t,e){return null!==e&&t.generation===e.generation&&t.revision===e.revision}var Y=new Set(["__proto__","prototype","constructor"]);function Z(t,e,n,i=!1){if(i&&void 0!==n){const i=K(t,`${e}_${n}`);if(void 0!==i)return i}const r=K(t,e);if(void 0!==r)return r;if(e.includes(".")){let n=t,i=!0;for(const t of e.split(".")){if(Y.has(t)||null===n||"object"!=typeof n){i=!1;break}if(n=K(n,t),void 0===n){i=!1;break}}if(i)return n}return void 0===n?void 0:K(t,`${e}_${n}`)}function K(t,e){if(!Y.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 tt="payload-live-preview-a11y";function et(t){return/^de(?:[-_]|$)/i.test(t)}var nt=new WeakMap;function it(t){null!==t[4]&&(clearTimeout(t[4]),t[4]=null),t[2]?.remove(),t[2]=null}var rt=class{s;constructor(t,e){const n=e??("undefined"==typeof document?null:document),i=n?.documentElement.getAttribute("lang")??"";this.s=[et(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=nt.get(t);return e??=[null,!1,null,0,null],nt.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];it(e),t&&n.remove()}let i=t.getElementById(tt);return e[1]=null===i,i||(i=t.createElement("div"),i.id=tt,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&&it(t),t[1]&&n?.remove(),t[0]=null,nt.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&&it(n)},1500);n[4]=r}},st=new Set(["tabs","row","collapsible"]);function ot(t,e=""){const n=new Map;return at(t,e,n),n}function at(t,e,n){for(const i of t){if(st.has(i.type)){i.fields&&at(i.fields,e,n);continue}if("group"===i.type){const t=""===e?i.name:`${e}.${i.name}`;n.set(t,i),i.fields&&at(i.fields,t,n);continue}const t=""===e?i.name:`${e}.${i.name}`;if(n.set(t,i),"array"===i.type&&i.fields)at(i.fields,`${t}.*`,n);else if("blocks"===i.type&&i.blocks)for(const e of i.blocks)at(e.fields,`${t}.*.${e.slug}`,n)}}function lt(t){if("object"!=typeof t||null===t)return;const e=t.id;return"string"==typeof e||"number"==typeof e?e:void 0}function ut(t){if("object"!=typeof t||null===t)return;const e=t.blockType;return"string"==typeof e?e:void 0}function ct(t,e){return e.every(t=>void 0!==lt(t))?function(t,e){const n=[],i=new Map;for(let e=0;e<t.length;e+=1){const n=lt(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=lt(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];ut(u)===ut(o)?(l!==s&&n.push({kind:"move",from:l,to:s,value:o}),dt(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)dt(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 dt(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 ht={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"},ft=[0,500,1e3,2e3],pt=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??mt,l=t.onHeartbeatTimeout,u=void 0===t.log?O:I(t.log),c=void 0===t.warn?P:I(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 rt(t.a11yLocale,e)}(t),h=void 0!==t.dataMerge?new H({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 m,p=new y({onStructuralChange:()=>{this.#M()},onVisibilityChange:(t,e)=>{e&&this.d[3].notifyVisible(t)}},{...void 0!==t.intersectionRootMargin?{intersectionRootMargin:t.intersectionRootMargin}:{}}),g=new Q(J(t=>this.#R(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)}}),v=new T(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}:{}}),b=new E(()=>{}),w=new R({...void 0!==t.heartbeatMs?{timeoutMs:t.heartbeatMs}:{},onTimeout:()=>{this.#O()}});this.d=[e,f,p,g,v,b,w,n,i,r,s,o,a,l,u,c,[],d,h],this.l=[void 0,void 0,void 0,negotiateProtocol(void 0),!1,null,0,null,new Set]}start(){if(this.l[4])return!1;this.l[4]=!0;const t=this.d[10];if(gt(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=gt(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.#j(),this.#F()&&(this.d[4].attach(),this.d[0].emitWhile("init",{timestamp:Date.now()},()=>this.l[4]),this.#F()))for(const t of ft){if(!this.#F())return;if(0===t){if(this.d[12](this.d[11]),!this.#F())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&>(this.d[10])&&this.#G(()=>{this.d[10].removeEventListener("DOMContentLoaded",t)});for(const t of this.d[16])this.#G(()=>{clearTimeout(t)});return this.d[16].length=0,this.#G(()=>{this.d[6].stop()}),this.#G(()=>{this.d[4].detach()}),this.#G(()=>{this.d[2].stop()}),this.#G(()=>{this.d[3].destroy()}),this.#G(()=>{this.d[18]?.destroy()}),this.d[1].clear(),this.d[5].markDisconnected()}#P(){this.#D(),this.#G(()=>{this.d[17]?.detach()})}#G(t){try{t()}catch(t){this.d[14]("cleanup failed:",t)}}refreshCache(){this.l[4]&&this.#M()}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]}#j(){if(!this.l[4])return;const t=this.d[1].buildFromRoot(this.d[10]);if(this.d[14]("cache",t),this.#F()&&(this.d[0].emitWhile("cacheRefresh",t,()=>this.l[4]),this.#F()))for(const t of this.d[1].values()){if(!this.#F())return;this.d[2].observeElement(t.element)}}#M(){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.#j(),this.#F()){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]=ot(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.#z(i)}}async#z(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;for(const[i,r]of this.d[1].entries()){if(!this.l[4]||this.l[7]!==t)return;for(const s of r){const r=Z(e.fields,i,s.locale??t.locale,void 0!==s.locale);if(void 0===r)continue;if(!this.l[4]||this.l[7]!==t)return;const o=this.#q(s,r,e.fields,n);if(!this.l[4]||this.l[7]!==t)return;const a={target:s,value:o,allFields:e.fields,identity:t.identity,data:e};if(!this.l[4]||this.l[7]!==t)return;this.d[3].schedule(a)}}this.#B(e.fields,t.locale)}#B(t,e){if(0===this.d[1].fieldCount)return;let n;for(const[i,r]of Object.entries(t)){if(this.l[8].has(i))continue;if(yt.has(i))continue;if(!bt(r))continue;const t=wt(i,e);if(void 0===this.d[1].get(i)&&(t===i||void 0===this.d[1].get(t))){if(void 0===n){n=new Set;for(const[t,e]of this.d[1].entries())for(const i of e)void 0!==i.locale&&n.add(`${t}_${i.locale}`)}n.has(i)||(this.l[8].add(i),this.d[15](`[live-preview] update arrived for field "${i}" 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=C(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}}#F(){return this.l[4]}#R(t){const e=this.l[7];if(null===e||void 0===t.identity||!vt(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(ht,t))return ht[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(_.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 q.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 B.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){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||!vt(i.identity,e))return;const r=()=>this.l[4]&&this.l[7]===i&&vt(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.#F())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.#F()){if(e&&this.#J()){if(this.d[17]?.announceDisconnected(),this.d[0].emitWhile("disconnect",{reason:"timeout",timestamp:Date.now()},()=>this.#J()),!this.#F())return;if(this.#J()&&(this.d[14]("connection","connected","→","disconnected"),!this.#F()))return}this.#F()&&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})}#J(){return this.l[4]&&"disconnected"===this.d[5].status&&null===this.l[7]}};function gt(t){return 9===t.nodeType}function mt(t){if("undefined"==typeof window)return;const e=[];window.parent!==window&&e.push(window.parent),window.opener instanceof Window&&e.push(window.opener),T.sendReady(e,t)}function vt(t,e){return t.generation===e.generation&&t.revision===e.revision}var yt=new Set(["id","_id","createdAt","updatedAt","createdBy","updatedBy","_status","globalType","collection","locale","localized"]);function bt(t){return null!=t&&("string"==typeof t||"number"==typeof t||"boolean"==typeof t||"bigint"==typeof t)}function wt(t,e){if(!e)return t;const n=`_${e}`;return t.endsWith(n)?t.slice(0,-n.length):t}var St,At=class{#Q=new Map;#X=new Map;on(t,e){return this.#Y(this.#Q,t,e)}once(t,e){return this.#Y(this.#X,t,e)}off(t,e){this.#Z(this.#Q,t,e),this.#Z(this.#X,t,e)}async emit(t,e){await this.#K(t,e)}async emitWhile(t,e,n){return this.#K(t,e,n)}async#K(t,e,n){const i=()=>n?.()??!0;if(!i())return!1;const r=this.#Q.get(t);if(r)for(const n of[...r]){if(!i())return!1;if(await this.#tt(n,e,t),!i())return!1}if(!i())return!1;const s=this.#X.get(t);if(s&&s.size>0){const n=[...s];this.#X.delete(t);for(const r of n){if(!i())return!1;if(await this.#tt(r,e,t),!i())return!1}}return i()}listenerCount(t){return(this.#Q.get(t)?.size??0)+(this.#X.get(t)?.size??0)}removeAllListeners(t){if(void 0===t)return this.#Q.clear(),void this.#X.clear();this.#Q.delete(t),this.#X.delete(t)}eventNames(){const t=new Set;for(const e of this.#Q.keys())t.add(e);for(const e of this.#X.keys())t.add(e);return[...t]}#Y(t,e,n){let i=t.get(e);return i||(i=new Set,t.set(e,i)),i.add(n),()=>{this.#Z(t,e,n)}}#Z(t,e,n){const i=t.get(e);void 0!==i&&(i.delete(n),0===i.size&&t.delete(e))}async#tt(t,e,n){try{await t(e)}catch(t){const e="string"==typeof n||"number"==typeof n?String(n):"<event>";U(`[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=Ct();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 kt(t){if("undefined"!=typeof process){const e=process.env[t];if("string"==typeof e&&e.length>0)return e}const e=Ct();if(e){const n=e[t];if("string"==typeof n&&n.length>0)return n}}function Ct(){if("undefined"==typeof __INLINE_RUNTIME_BUILD__||!__INLINE_RUNTIME_BUILD__){if(void 0!==St)return St??void 0;St=null;try{const t=new Function("try { return import.meta && import.meta.env; } catch (_) { return undefined; }")();if(t&&"object"==typeof t)return St=t}catch{}}}var Tt=/^https?:\/\/(localhost|127\.0\.0\.1)(?::\d+)?$/i,$t=/^https?:\/\/[^/?#\s]+$/i,Nt=["PAYLOAD_ADMIN_ORIGIN","PUBLIC_PAYLOAD_ADMIN_ORIGIN","NEXT_PUBLIC_PAYLOAD_ADMIN_ORIGIN"],xt=class{#et;constructor(t={}){const e=new Set;for(const n of t.additionalOrigins??[]){const t=Rt(n);void 0!==t&&e.add(t)}for(const t of Nt){const n=kt(t);if(void 0!==n)for(const t of n.split(",")){const n=Rt(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.#et=[e,n,i,void 0!==n,void 0]}matches(t){return 0!==t.length&&"null"!==t&&(void 0!==this.#et[4]?t===this.#et[4]:!!this.#et[0].has(t)||0===this.#et[0].size&&void 0!==this.#et[1]&&t===this.#et[1]||!(!this.#et[2]||!Tt.test(t)))}lockOrigin(t){return!!this.matches(t)&&(this.#et[4]=t,!0)}unlockOrigin(){const t=this.#et[4];return this.#et[4]=void 0,t}get lockedOrigin(){return this.#et[4]}enumerate(){if(void 0!==this.#et[4])return[this.#et[4]];const t=new Set(this.#et[0]);if(0===this.#et[0].size&&void 0!==this.#et[1]&&t.add(this.#et[1]),this.#et[2])for(const e of Mt)t.add(`http://localhost:${String(e)}`),t.add(`http://127.0.0.1:${String(e)}`);return[...t]}get referrerWasAvailable(){return this.#et[3]}get isProductionUnconfigured(){return!(!isInIframe()||this.#et[0].size>0||this.#et[2]||void 0!==this.#et[1])}get isReferrerOnlyTrust(){return!(this.#et[0].size>0||this.#et[2]||void 0===this.#et[1])}},Mt=[3e3,3001,3333,4e3,4321,5e3,5173,5174,8e3,8080,8888,9e3];function Rt(t){const e=t.trim();if(0!==e.length)try{const t=new URL(e);if("http:"!==t.protocol&&"https:"!==t.protocol)return;if(!$t.test(t.origin))return;return t.origin}catch{return}}var Et,It=()=>{},Ot=class{#nt;#it;#rt=new Set;#et="staging";constructor(t,e){this.#nt=t,this.#it=e}assertOpen(){if("closed"===this.#et)throw new Error(`Plugin context for "${this.#nt}" is no longer active`)}get active(){return"active"===this.#et}eligible(){return"closed"!==this.#et}own(t){return this.assertOpen(),this.#st({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.#st(n);if("active"===this.#et)try{this.#ot(n)}catch(t){throw this.#at(n),t}return i}commit(){if("staging"!==this.#et)throw new Error(`Plugin context for "${this.#nt}" cannot be committed`);this.#et="committing";try{for(const t of this.#rt)this.#ot(t);this.#et="active"}catch(t){throw this.close(),t}}close(){if("closed"!==this.#et){this.#et="closed";for(const t of[...this.#rt].reverse())this.#at(t);this.#rt.clear()}}#st(t){return this.#rt.add(t),()=>{this.#at(t)}}#ot(t){if(t.disposed||void 0!==t.cleanup||void 0===t.acquire)return;const e=t.acquire();t.cleanup=e??It}#at(t){if(t.disposed)return;t.disposed=!0,this.#rt.delete(t);const e=t.cleanup;if(t.cleanup=void 0,void 0!==e)try{C(e())&&this.#it(`plugin "${this.#nt}" cleanup returned a Promise/thenable; cleanups must be synchronous`)}catch(t){this.#it(`plugin "${this.#nt}" cleanup failed:`,t)}try{t.finalize?.()}catch(t){this.#it(`plugin "${this.#nt}" cleanup failed:`,t)}}},Ut=class extends At{#lt;#ut;#ct=new Set;constructor(t,e){super(),this.#lt=t,this.#ut=e}on(t,e){return this.#dt("on",t,e)}once(t,e){return this.#dt("once",t,e)}off(t,e){const n=e;for(const e of[...this.#ct])e.event===t&&e.handler===n&&e.dispose()}emit(t,e){return this.#ut.assertOpen(),this.#lt.emit(t,e)}emitWhile(t,e,n){return this.#ut.assertOpen(),this.#lt.emitWhile(t,e,()=>{if(!this.#ut.eligible())return!1;const t=n();return!!this.#ut.eligible()&&t})}listenerCount(t){let e=0;for(const n of this.#ct)n.event===t&&(e+=1);return e}removeAllListeners(t){for(const e of[...this.#ct])void 0!==t&&e.event!==t||e.dispose()}eventNames(){const t=new Set;for(const e of this.#ct)t.add(e.event);return[...t]}#dt(t,e,n){this.#ut.assertOpen();const i=n,r=[...this.#ct].find(n=>n.kind===t&&n.event===e&&n.handler===i);if(void 0!==r)return r.dispose;let s=It,o=!0;const a=async e=>{this.#ut.active&&o&&("once"===t&&s(),await n(e))},l={kind:t,event:e,handler:i,dispose:It};return s=this.#ut.stage(()=>this.#lt[t](e,a),()=>{o=!1,this.#ct.delete(l)}),l.dispose=s,this.#ct.add(l),s}},Pt=class{#lt;#ht;#ft;#pt;#it;#gt=new Map;#mt=new Map;#vt=new Map;#yt=new Set;#bt=new Map;#wt=Promise.resolve();#St=0;constructor(t){this.#lt=t.events,this.#ht=t.config,this.#ft=t.registerFieldRenderer,this.#it=I(t.log);const e=t.onTransformError;this.#pt=void 0===e?void 0:I((...t)=>{const n=t[0];if(n instanceof Error)try{return e(n)}catch(t){return void this.#it("transform error reporter failed:",t)}})}register(t){return this.#St>0?this.#At(t):this.#kt(()=>this.#At(t))}unregister(t){return this.#St>0?this.#Ct(t):this.#kt(async()=>{await this.#Ct(t)})}destroyAll(){return this.#St>0?this.#Tt():this.#kt(async()=>{await this.#Tt()})}applyTransforms(t,e,n,i){const r=this.#bt.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=C(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.#it(`transform for "${t}" failed:`,r),this.#pt?.(r),e}}return s}list(){return[...this.#gt.keys()]}get size(){return this.#gt.size}async#At(t){if(this.#gt.has(t.name)||this.#mt.has(t.name)||this.#vt.has(t.name))return void this.#it(`plugin "${t.name}" already registered`);const e=new Ot(t.name,this.#it),n=this.#$t(t.name,e),i={scope:e,cancelled:!1};this.#mt.set(t.name,i);try{if(await this.#Nt(()=>t.init(n)),i.cancelled)return;e.commit()}catch(n){return e.close(),void(i.cancelled||this.#it(`plugin "${t.name}" init failed:`,n))}finally{this.#mt.get(t.name)===i&&this.#mt.delete(t.name)}this.#gt.set(t.name,{plugin:t,scope:e}),this.#it(`plugin "${t.name}" registered`)}#$t(t,e){return{events:new Ut(this.#lt,e),registerFieldRenderer:t=>{e.stage(()=>{const e=this.#ft(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.#bt.get(t);return void 0===e?this.#bt.set(t,[i]):e.push(i),()=>{i.active=!1;const e=this.#bt.get(t);if(void 0===e)return;const n=e.indexOf(i);n>=0&&e.splice(n,1),0===e.length&&this.#bt.delete(t)}})},registerCleanup:t=>{e.own(t)},getConfig:()=>this.#ht,log:(...e)=>{this.#it(`[${t}]`,...e)}}}#Ct(t){const e=this.#mt.get(t);if(void 0!==e)return e.cancelled=!0,e.scope.close(),Promise.resolve();const n=this.#vt.get(t);if(void 0!==n)return this.#yt.has(t)?Promise.resolve():n;const i=this.#gt.get(t);if(void 0===i)return Promise.resolve();this.#gt.delete(t),i.scope.close();const r=Promise.resolve().then(()=>this.#xt(t,i.plugin));return this.#vt.set(t,r),r.then(()=>{this.#vt.get(t)===r&&this.#vt.delete(t)}),r}async#xt(t,e){if(void 0!==e.destroy){this.#yt.add(t);try{await this.#Nt(()=>e.destroy?.())}catch(e){this.#it(`plugin "${t}" destroy failed:`,e)}finally{this.#yt.delete(t)}}}async#Tt(){for(const t of this.#mt.values())t.cancelled=!0,t.scope.close();const t=[...this.#gt.keys()];for(const e of t)await this.#Ct(e)}async#Nt(t){this.#St+=1;try{await t()}finally{this.#St-=1}}#kt(t){const e=this.#wt.then(t);return this.#wt=e.catch(t=>{this.#it("plugin manager mutation failed:",t)}),e}},Lt=class{#Mt;#Rt;#Et=new Map;constructor(t){this.#Mt=t,this.#Rt={...t}}get renderers(){return this.#Rt}resolve(t){return this.#Rt[t]}register(t){const e=t.name,n={renderer:t},i=this.#Et.get(e);void 0===i?this.#Et.set(e,[n]):i.push(n),this.#Rt[e]=t;let r=!0;return()=>{if(!r)return;r=!1;const t=this.#Et.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.#Et.delete(e),!s)return;const o=t.at(-1),a=o?.renderer??this.#Mt[e];void 0===a?Reflect.deleteProperty(this.#Rt,e):this.#Rt[e]=a}}},jt=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"]),Ft=new Set(["script","style","iframe","object","embed","link","meta","base","form","input","button","select","textarea","svg","math","template","frame","frameset","noframes","noscript"]),Ht=new Set(["id","class","lang","dir","title","role","tabindex"]),Dt={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"])},Gt=new Set(["href","src","cite","poster"]),Wt=class extends Error{name="SanitizerEnvironmentError"};function setSanitizerDocument(t){Et=t??void 0}function sanitizeHtml(t,e){const n=zt();if(!n)throw new Wt("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(Dt))t.set(e,n);return{allowedTags:jt,attrByTag:t}}const e=new Set(jt);for(const n of t.additionalAllowedTags??[])e.add(n);const n=new Map;for(const[t,e]of Object.entries(Dt))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,Vt(r.content,i),r.innerHTML}function zt(){return Et||("undefined"!=typeof document?document:void 0)}function Vt(t,e){for(const n of Array.from(t.childNodes))1===n.nodeType?_t(n,e):8===n.nodeType&&n.remove()}function _t(t,e){const n=t.tagName.toLowerCase();if(Ft.has(n))t.remove();else{if(!e.allowedTags.has(n)){Vt(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?Ht.has(n)||n.startsWith("aria-")||n.startsWith("data-")||(i?.has(n)?Gt.has(n)&&!isSafeUrl(e.value)?t.removeAttribute(e.name):"srcset"!==n||qt(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),Vt(t,e)}}function qt(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 Bt=new Map;function Jt(t,e){Bt.set(t,e)}var Qt={1:"left",2:"center",3:"right",4:"justify"},Xt=new Set(["left","center","right","justify","start","end"]);function Yt(t){const e=t.format;if("string"==typeof e&&Xt.has(e))return e;if("number"==typeof e){const t=Qt[e];if(void 0!==t)return t}}function Zt(t){const e=t.indent;return"number"==typeof e&&e>0?e:0}function Kt(t){return"rtl"===t.direction?' dir="rtl"':"ltr"===t.direction?' dir="ltr"':""}function te(t){const e=Yt(t),n=Zt(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 ee=Object.freeze({"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="}),ne=/[&<>"'/`=]/g;function escapeHtml(t){return""===t?"":t.replace(ne,t=>ee[t])}var ie=Object.freeze({"&":"&","<":"<",">":">",'"':""","'":"'"}),re=/[&<>"']/g;function escapeHtmlAttribute(t){return""===t?"":t.replace(re,t=>ie[t])}function se(t){return escapeHtml(t).replace(/\r\n|\r|\n/g,"<br>")}var oe=new Set(["h1","h2","h3","h4","h5","h6"]),ae=(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 le(t){if("string"==typeof t.text)return t.text;if(!t.children)return"";let e="";for(const n of t.children)e+=le(n);return e}function ue(t){return t.replace(/[^a-zA-Z0-9_-]/g,"")}var ce=new Map;function de(t){return ce.get(t)}function he(t){return t.replace(/[^a-zA-Z0-9_-]/g,"-").toLowerCase()}Jt("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}),Jt("paragraph",(t,e)=>{const n=e.renderChildren(t.children??[]);return`<p${Kt(t)}${te(t)}>${n}</p>`}),Jt("heading",(t,e)=>{const n="string"==typeof t.tag?t.tag.toLowerCase():"h2",i=oe.has(n)?n:"h2",r=e.renderChildren(t.children??[]);return`<${i}${Kt(t)}${te(t)}>${r}</${i}>`}),Jt("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}${Kt(t)}${te(t)}${r}${s}>${o}</${i}>`}),Jt("listitem",(t,e)=>{const n=e.renderChildren(t.children??[]);if("boolean"==typeof t.checked)return`<li role="checkbox" aria-checked="${t.checked?"true":"false"}"${te(t)}>${n}</li>`;const i="number"==typeof t.value?` value="${escapeHtml(String(t.value))}"`:"";return`<li${Kt(t)}${te(t)}${i}>${n}</li>`}),Jt("link",ae),Jt("autolink",ae),Jt("quote",(t,e)=>{const n=e.renderChildren(t.children??[]);return`<blockquote${Kt(t)}${te(t)}>${n}</blockquote>`}),Jt("code",t=>{const e=ue("string"==typeof t.language?t.language:"");return`<pre><code${""===e?"":` class="language-${e}"`}>${escapeHtml(le(t))}</code></pre>`}),Jt("code-highlight",t=>{const e="string"==typeof t.text?t.text:"";return`<span${"string"==typeof t.highlightType?` class="token-${ue(t.highlightType)}"`:""}>${escapeHtml(e)}</span>`}),Jt("linebreak",()=>"<br>"),Jt("horizontalrule",()=>"<hr>"),Jt("tab",()=>"\t"),Jt("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)}),Jt("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>`}),Jt("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=he(i);if(""!==i){const t=de(i)??de(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-${he(t)}="${escapeHtml(n)}"`)}return`<div${0===s.length?"":` ${s.join(" ")}`}></div>`});var fe={renderChildren:me,resolveAlignment:Yt,resolveIndent:Zt};function pe(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 ge(t){return pe(t)?t.root.children.map(ye).join("\n").trim():""}function me(t){let e="";for(const n of t)e+=ve(n);return e}function ve(t){const e=(n=t.type,Bt.get(n));var n;return e?e(t,fe):void 0!==t.children?me(t.children):""}function ye(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+=ye(n);return e}function be(){const t=new WeakSet;return{name:"text",render:J((e,n)=>{const i=e.element,r=function(t){return null==t?"":pe(t)?ge(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),P(`[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=se(r):i.textContent=r);i.value=r})}}function we(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 Se={name:"textarea",render(t,e){const n=t.element,i=pe(e)?ge(e):we(e);"INPUT"!==n.tagName&&"TEXTAREA"!==n.tagName?n.innerHTML=se(i):n.value=i}},Ae={name:"richText",render:J((t,e)=>{if(pe(e))t.element.innerHTML=function(t,e={}){if(!pe(t))return"";const n=me(t.root.children);return!1===e.sanitize||void 0===zt()?n:sanitizeHtml(n)}(e);else{if("string"!=typeof e)return!1;t.element.innerHTML=sanitizeHtml(e)}})},ke={name:"html",render(t,e){if(null==e)return void(t.element.textContent="");const n="string"==typeof e?e:we(e);t.element.innerHTML=sanitizeHtml(n)}},Ce={name:"url",render(t,e,n){const i=t.element,r=we(e);if("A"===i.tagName){const s=i,o=t.hrefField,a=void 0===o||0===o.length?e:Z(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}},Te={name:"image",render:J((t,e,n)=>{const i=t.element,r=$e(e),s=void 0!==t.locale,o=function(t,e,n,i,r,s){if(void 0!==n&&n.length>0){const t=Z(i,n,r,s);if("string"==typeof t&&isSafeUrl(t))return t;const e=$e(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=Z(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 $e(t){if("object"==typeof t&&null!==t)return t}var Ne={name:"upload",render:J((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>`})},xe={name:"relationship",render(t,e){const n=t.element,i=function(t){return null==t?[""]:Array.isArray(t)?t.map(Me):[Me(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 Me(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 we(t)}var Re={name:"select",render(t,e){const n=t.element,i=Ee(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 Ee(t){return Array.isArray(t)?t.map(t=>Ee(t)).join(", "):we(t)}var Ie={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}},Oe=new Map,Ue=new Map;function Pe(t,e){const n=t??"";if(null==e)return n;const i=Le(e);return"{}"===i?n:`${n}|${i}`}function Le(t){if(null===t||"object"!=typeof t)return JSON.stringify(t);if(Array.isArray(t))return`[${t.map(t=>Le(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)}:${Le(n)}`)}return`{${i.join(",")}}`}function je(t){for(;t.size>64;){const e=t.keys().next().value;if(void 0===e)break;t.delete(e)}}var Fe={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:we(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?He(s,n):r)):void(i.textContent=o?He(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 He(t,e){const n=e.locale??detectInitialLocale();try{return function(t,e){const n=Pe(t,e),i=Ue.get(n);if(void 0!==i)return Ue.delete(n),Ue.set(n,i),i;const r=new Intl.DateTimeFormat(t,e);return Ue.set(n,r),je(Ue),r}(n,{dateStyle:"medium",timeStyle:"short"}).format(t)}catch{return t.toISOString()}}var De={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(we(e));Number.isNaN(r)?i.textContent=we(e):"INPUT"!==i.tagName?i.textContent=function(t,e){const n=e.locale??detectInitialLocale();try{return function(t,e){const n=Pe(t,e),i=Oe.get(n);if(void 0!==i)return Oe.delete(n),Oe.set(n,i),i;const r=new Intl.NumberFormat(t,e);return Oe.set(n,r),je(Oe),r}(n).format(t)}catch{return String(t)}}(r,n):i.value=String(r)}},Ge=/\{\{([\s\S]*?)\}\}/g;function We(t,e,n,i){const r="object"==typeof e&&null!==e?e:null;return t.replace(Ge,(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 ze={name:"array",render:J((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+=Ve(t,e[i],i);return n}(i,e);return void(n.innerHTML=sanitizeHtml(t))}const r=t.arraySeparator??", ";n.textContent=e.map(_e).join(r)})};function Ve(t,e,n){return We(t,e,n,we)}function _e(t){return we(t)}var qe="data-payload-key",Be="data-payload-nested-key",Je="data-payload-nested-template";function Qe(t){const{template:e,container:n,patches:i,nextItems:r,store:s,forceRender:o=!1}=t,a=Xe(n,e,i,r,o,s);return null===a?null:Ye(a,s)}function Xe(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=sn(a,qe),u=new Set,c=[];for(let d=0;d<n.length;d+=1){const h=n[d],f=rn(h);let p=void 0===f?a[d]??null:on(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?an(t.ownerDocument,e,h,d):void 0;if(null===m)return null;const v=void 0===m?[]:Ze(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 Ye(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]&&(tn(t[0],t[1]),t[1].replaceWith(t[0])),void 0!==t[2]&&Ye(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)nn(a,t);return o}function Ze(t,e,n,i,r){const s=sn(null===t?[]:Ke(t),Be),o=rn(n),a=void 0!==o?i?.get(o):void 0,l=[];for(const t of Ke(e)){const e=t.getAttribute(Be);if(null===e)continue;const i=on(s,e)??null,o=t.getAttribute(Je),u=o?i:null,c=u?.getAttribute(Je)??null;let d;if(o){const i=en(n,e);if(void 0!==i||null!==u){const n=i??[],s=ct(null===u?[]:en(a,e)??[],n),l=null!==u&&c!==o;if((s.length>0||l)&&(d=Xe(u??t,o,s,n,l,r)??void 0,void 0===d))return null}}l.push([u,t,d])}return l}function Ke(t){return Array.from(t.querySelectorAll(`[${Be}]`)).filter(e=>{let n=e.parentElement;for(;null!==n&&n!==t;){if(n.hasAttribute(Be))return!1;n=n.parentElement}return n===t})}function tn(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 en(t,e){if("object"!=typeof t||null===t)return;const n=t[e];return Array.isArray(n)?n:void 0}function nn(t,e){const n=rn(e);void 0!==n&&t.set(n,e)}function rn(t){if("object"!=typeof t||null===t)return;const e=t.id;return"string"==typeof e||"number"==typeof e?String(e):void 0}function sn(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 on(t,e){return t.get(e)?.pop()}function an(t,e,n,i){const r=function(t,e,n){return We(t,e,n,we)}(e,n,i),s=sanitizeHtml(r),o=t.createElement("template");o.innerHTML=s;const a=o.content.firstElementChild;if(!a)return null;const l=rn(n);return void 0!==l&&a.setAttribute(qe,l),a}function ln(){const t=new WeakMap,e=new WeakSet,n=new WeakMap;return{name:"structural-array",render:J((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),P(`[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=un(s),u=ct(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=Qe({template:o,container:s,patches:u,nextItems:r,store:n,forceRender:c});return null!==d&&(t.set(s,{values:r.slice(),template:o,domSnapshot:un(s)}),!!d&&void 0)})}}function un(t){return Array.from(t.children,t=>t.getAttribute(qe))}var cn=new Map,dn=[Se,Ae,ke,Ce,{...Ce,name:"email"},Te,Ne,xe,Re,{...Re,name:"radio"},Ie,Fe,De,ze,{...ze,name:"blocks"}],hn=class{#It=new At;#Ot;#Ut;#Pt;#gt;#it;#Lt=!1;#jt=!1;#Ft=null;constructor(t={}){const e=t.debug??isDevMode();this.#it=e?(...t)=>{L("[live-preview]",...t)}:O,this.#Ot=new xt({...void 0!==t.allowedOrigins?{additionalOrigins:t.allowedOrigins}:{},...void 0!==t.disableReferrerDetection?{enableReferrerDetection:!t.disableReferrerDetection}:{},...void 0!==t.disableLocalhostMatching?{enableLocalhostMatching:!t.disableLocalhostMatching}:{}}),this.#Ot.isProductionUnconfigured&&this.#it("no trusted origin could be detected — set allowedOrigins or PAYLOAD_ADMIN_ORIGIN"),this.#Ut=new Lt(function(t=[]){const e={};for(const n of t)e[n.name]=n;for(const[t,n]of cn)e[t]=n;return Object.freeze(e)}([be(),...dn,ln()])),this.#gt=new Pt({events:this.#It,config:Object.freeze({...t}),registerFieldRenderer:t=>this.#Ut.register(t),onTransformError:t=>{this.#It.emit("error",{error:t,context:"transform"})},log:this.#it}),this.#Pt=new pt({...void 0!==t.root?{root:t.root}:{},renderers:this.#Ut.renderers,resolveRenderer:t=>this.#Ut.resolve(t),transformValue:(t,e,n,i)=>this.#gt.applyTransforms(t,e,n,i),originMatcher:t=>this.#Ot.matches(t),readyTargets:this.#Ot.enumerate(),emitter:this.#It,...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.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.#Ot.unlockOrigin()},...void 0!==t.validateToken?{validateToken:t.validateToken}:{},log:this.#it}),this.#It.on("connect",t=>{this.#Ot.lockOrigin(t.origin)}),!1!==t.autoStart&&this.start()}start(){if(this.#jt)return!1;if(this.#Lt)return this.#Pt.start(),!0;if(!isInPreviewContext())return!1;const t=this.#Pt.start();return t&&(this.#Lt=!0),t}destroy(){if(null!==this.#Ft)return this.#Ft;let t,e;this.#jt=!0;const n=new Promise((n,i)=>{t=n,e=i});this.#Ft=n;try{this.#Pt.destroy(),this.#gt.destroyAll().finally(()=>{this.#It.removeAllListeners()}).then(t,e)}catch(t){this.#It.removeAllListeners(),e(t)}return n}async use(t){if(this.#jt)throw new Error("LivePreviewClient: already destroyed");await this.#gt.register(t)}async unuse(t){await this.#gt.unregister(t)}refreshCache(){this.#Pt.refreshCache()}get events(){return this.#It}get plugins(){return this.#gt.list()}get status(){return this.#Pt.status}get updateCount(){return this.#Pt.updateCount}get destroyed(){return this.#jt}};function initLivePreview(t={}){const e=new hn({...t,autoStart:!1});return e.start()?e:null}var fn,pn="1.0.5";function setCspCrypto(t){fn=t??void 0}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(fn?.getRandomValues)return fn;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)}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'"}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(" ")}function bind(t,e){return gn(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 gn(n.join("."),e)}function gn(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),n}for(const[t,e]of[[At,"EventEmitter"],[hn,"LivePreviewClient"],[xt,"OriginDetector"]])Object.defineProperty(t,"name",{configurable:!0,value:e});var mn=!0;export{mn as CORE_ENTRY,At as EventEmitter,A as LIBRARY_PROTOCOL_VERSION,hn as LivePreviewClient,xt as OriginDetector,pn as VERSION,bind,bindByPath,buildFrameAncestors,buildScriptSrcWithNonce,detectInitialLocale,escapeHtml,escapeHtmlAttribute,generateCspNonce,hasCapability,initLivePreview,isDevMode,isExternalHttpUrl,isInIframe,isInPopup,isInPreviewContext,isSafeUrl,negotiateProtocol,sanitizeHtml,setCspCrypto,setSanitizerDocument};
|
|
2
2
|
//# sourceMappingURL=core.js.map
|