payload-live-preview 1.8.0 → 2.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +301 -93
- package/dist/adapters/astro/PreviewBoundary.astro +66 -0
- package/dist/adapters/astro/RichText.astro +6 -0
- package/dist/adapters/astro/index.d.ts +165 -134
- package/dist/adapters/astro/index.js +1 -1
- package/dist/adapters/astro/index.js.map +1 -1
- package/dist/adapters/astro/middleware-entry.d.ts +4 -9
- package/dist/adapters/astro/middleware-entry.js +1 -1
- package/dist/adapters/astro/middleware-entry.js.map +1 -1
- package/dist/adapters/nextjs/index.d.ts +13 -80
- package/dist/adapters/nextjs/index.js +1 -1
- package/dist/adapters/nextjs/index.js.map +1 -1
- package/dist/adapters/nuxt/index.d.ts +46 -106
- package/dist/adapters/nuxt/index.js +1 -1
- package/dist/adapters/nuxt/index.js.map +1 -1
- package/dist/adapters/sveltekit/index.d.ts +10 -75
- package/dist/adapters/sveltekit/index.js +1 -1
- package/dist/adapters/sveltekit/index.js.map +1 -1
- package/dist/client.cjs +2 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +747 -0
- package/dist/client.d.ts +747 -0
- package/dist/client.js +2 -0
- package/dist/client.js.map +1 -0
- package/dist/codegen-astro.d.ts +5 -27
- package/dist/codegen-astro.js +1 -1
- package/dist/codegen-astro.js.map +1 -1
- package/dist/codegen-cli.d.ts +3 -16
- package/dist/codegen-cli.js +1 -1
- package/dist/codegen-cli.js.map +1 -1
- package/dist/codegen.cjs +1 -1
- package/dist/codegen.cjs.map +1 -1
- package/dist/codegen.d.cts +37 -124
- package/dist/codegen.d.ts +37 -124
- package/dist/codegen.js +1 -1
- package/dist/codegen.js.map +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +647 -1100
- package/dist/core.d.ts +647 -1100
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/doctor-cli.d.ts +3 -28
- package/dist/doctor-cli.js +1 -1
- package/dist/doctor-cli.js.map +1 -1
- package/dist/doctor.d.ts +16 -32
- package/dist/doctor.js +1 -1
- package/dist/doctor.js.map +1 -1
- package/dist/fragment.cjs +2 -0
- package/dist/fragment.cjs.map +1 -0
- package/dist/fragment.d.cts +333 -0
- package/dist/fragment.d.ts +333 -0
- package/dist/fragment.js +2 -0
- package/dist/fragment.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +885 -1531
- package/dist/index.d.ts +885 -1531
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lexical.cjs +2 -0
- package/dist/lexical.cjs.map +1 -0
- package/dist/lexical.d.cts +90 -0
- package/dist/lexical.d.ts +90 -0
- package/dist/lexical.js +2 -0
- package/dist/lexical.js.map +1 -0
- package/dist/middleware-CEPsY1P7.d.ts +40 -0
- package/dist/migrate.d.ts +73 -0
- package/dist/migrate.js +2 -0
- package/dist/migrate.js.map +1 -0
- package/dist/options-CEzzfHJu.d.ts +197 -0
- package/dist/payload.cjs +1 -1
- package/dist/payload.cjs.map +1 -1
- package/dist/payload.d.cts +11 -80
- package/dist/payload.d.ts +11 -80
- package/dist/payload.js +1 -1
- package/dist/payload.js.map +1 -1
- package/dist/plugins.cjs +2 -0
- package/dist/plugins.cjs.map +1 -0
- package/dist/plugins.d.cts +509 -0
- package/dist/plugins.d.ts +509 -0
- package/dist/plugins.js +2 -0
- package/dist/plugins.js.map +1 -0
- package/dist/{probe-tMHdim5y.d.ts → probe-CYtvj_Lm.d.ts} +43 -77
- package/dist/server.cjs +2 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +435 -0
- package/dist/server.d.ts +435 -0
- package/dist/server.js +2 -0
- package/dist/server.js.map +1 -0
- package/dist/structural.cjs +3 -0
- package/dist/structural.cjs.map +1 -0
- package/dist/structural.d.cts +243 -0
- package/dist/structural.d.ts +243 -0
- package/dist/structural.js +3 -0
- package/dist/structural.js.map +1 -0
- package/package.json +86 -7
- package/dist/middleware-DD4Hwomt.d.ts +0 -189
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="data-payload-owner",p=[t,e,n,i,r,s,o,a,l,u,c,d,h,f,"type"],g=`[${t}]`,m=`[${f}]`,v=new Set(["text","textarea","richText","email","number","checkbox","date","select","radio","array","blocks","group","tabs","row","collapsible","relationship","upload","point","json","code","ui","html","url","image","structural-array"]),y=class{#t=new Map;#e=new WeakMap;#n;constructor(t={}){this.#n=t.filter??b}buildFromRoot(t){const e=performance.now();this.clear();const n=t.querySelectorAll(g);let i=0;for(const t of n)void 0!==this.add(t)&&(i+=1);return{elementCount:i,fieldCount:this.#t.size,durationMs:performance.now()-e}}add(t){const e=this.#n(t)?this.#i(t):void 0,n=this.#e.get(t);if(void 0!==e)return void 0!==n&&this.#r(n,e)?(this.#e.set(t,e),e):(void 0!==n&&this.#s(t,n),this.#o(e),this.#e.set(t,e),e);void 0!==n&&this.#s(t,n)}remove(t){const e=this.#e.get(t);return!!e&&this.#s(t,e)}#r(t,e){if(t.fieldName!==e.fieldName)return!1;const n=this.#t.get(t.fieldName);if(!n)return!1;const i=n.indexOf(t);return!(i<0||(n[i]=e,0))}#s(t,e){const n=this.#t.get(e.fieldName);if(!n)return this.#e.delete(t),!1;const i=n.indexOf(e);return i<0?(this.#e.delete(t),!1):(n.splice(i,1),0===n.length&&this.#t.delete(e.fieldName),this.#e.delete(t),!0)}get(t){return this.#t.get(t)}getByElement(t){return this.#e.get(t)}get fieldCount(){return this.#t.size}get elementCount(){let t=0;for(const e of this.#t.values())t+=e.length;return t}entries(){return this.#t.entries()}*values(){for(const t of this.#t.values())yield*t}has(t){return this.#e.has(t)}clear(){this.#t.clear(),this.#e=new WeakMap}#o(t){const e=this.#t.get(t.fieldName);e?e.push(t):this.#t.set(t.fieldName,[t])}#i(p){const g=p.getAttribute(t);if(null===g||0===g.length)return;const y=p.getAttribute(e),b=function(t){const n=t.getAttribute(e);if(null!==n&&v.has(n))return n;if(t.hasAttribute(u))return"richText";if(t.hasAttribute(c))return"html";if(t.hasAttribute(h))return"structural-array";if(t.hasAttribute(d))return"array";if("IMG"===t.tagName)return"image";if("A"===t.tagName)return"url";if("TIME"===t.tagName)return"date";if("INPUT"===t.tagName){const e=t.type;if("checkbox"===e)return"checkbox";if("number"===e)return"number";if("date"===e||"datetime-local"===e)return"date"}return"text"}(p),w=p.getAttribute(n),S=p.getAttribute(i),A=p.getAttribute(r),T=p.getAttribute(s),k=p.getAttribute(o),C=p.getAttribute(a),$=p.getAttribute(l),N=function(t){const e=t.closest(m)?.getAttribute(f);return null==e||0===e.length?void 0:e}(p);return{element:p,fieldName:g,fieldType:b,explicitFieldType:null!==y&&v.has(y),...null!==w&&w.length>0?{targetAttribute:w}:{},...null!==S&&S.length>0?{hrefField:S}:{},...null!==A&&A.length>0?{srcField:A}:{},...null!==T&&T.length>0?{altField:T}:{},...null!==k?{arrayTemplate:k}:{},...null!==C?{arraySeparator:C}:{},...null!==$&&$.length>0?{locale:$}:{},...void 0!==N?{owner:N}:{}}}};function b(){return!0}function w(t,e){return void 0===e||""===e?`collection:${t}`:`collection:${t}:${e}`}function S(t){return"string"==typeof t&&t.length>0}function A(t,e){return null!==e&&void 0!==t&&e.includes(t)}function T(t){const e=t.id;return"string"==typeof e&&e.length>0?e:"number"==typeof e&&Number.isFinite(e)?String(e):void 0}var k=class{s;constructor(t,e={}){this.s=[t,e.mutationDebounceMs??100,e.intersectionRootMargin??"200px",new Set,null,null,null,0]}start(t){const e=this.s[7];this.stop();const n=e+1;if(this.s[7]!==n)return;let i=null,r=null;try{i=new MutationObserver(t=>{this.#a(t,n)}),r=new IntersectionObserver(t=>{this.#l(t,n)},{rootMargin:this.s[2],threshold:0}),i.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[...p]})}catch(t){throw i?.disconnect(),r?.disconnect(),t}if(this.s[7]!==n)return i.disconnect(),void r.disconnect();this.s[4]=i,this.s[5]=r}observeElement(t){this.s[5]?.observe(t)}unobserveElement(t){this.s[5]?.unobserve(t),this.s[3].delete(t)}markVisible(t,e){e?this.s[3].add(t):this.s[3].delete(t)}isVisible(t){return this.s[3].has(t)}stop(){this.s[7]+=1;const t=this.s[6],e=this.s[4],n=this.s[5];this.s[6]=null,this.s[4]=null,this.s[5]=null,this.s[3].clear(),null!==t&&clearTimeout(t);try{e?.disconnect()}finally{n?.disconnect()}}#a(e,n){if(!this.#u(n))return;if(!function(e){for(const n of e){if("attributes"===n.type&&null!==n.attributeName&&p.includes(n.attributeName)&&(n.attributeName===t||n.attributeName===f||1===n.target.nodeType&&n.target.hasAttribute(t)))return!0;for(const t of n.addedNodes)if(C(t))return!0;for(const t of n.removedNodes)if(C(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 C(e){if(1!==e.nodeType)return!1;const n=e;return!!n.hasAttribute(t)||null!==n.querySelector(`[${t}]`)}function $(t){if(!Array.isArray(t))return[];const e=[];for(const n of t){const t=N(n);t&&e.push(t)}return e}function N(t){if("object"!=typeof t||null===t)return;const e=t,n=e.name,i=e.type;if("string"!=typeof n||0===n.length)return;if("string"!=typeof i||0===i.length)return;const r=$(e.fields),s=function(t){if(!Array.isArray(t))return[];const e=[];for(const n of t){if("object"!=typeof n||null===n)continue;const t=n,i=t.slug;if("string"!=typeof i||0===i.length)continue;const r=$(t.fields);e.push({...t,slug:i,fields:r})}return e}(e.blocks),o={...e,name:n,type:i};return r.length>0?o.fields=r:delete o.fields,s.length>0?o.blocks=s:delete o.blocks,o}var x=4,M={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(M))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 P(t){return("object"==typeof t&&null!==t||"function"==typeof t)&&"function"==typeof t.then&&(Promise.resolve(t).catch(()=>{}),!0)}var R=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||E(e.data))&&O(e.fieldSchemaJSON,t=>Array.isArray(t))&&O(e.globalSlug,t=>"string"==typeof t)&&O(e.collectionSlug,t=>"string"==typeof t)&&O(e.locale,t=>"string"==typeof t)&&O(e.ready,t=>"boolean"==typeof t)&&O(e.previewToken,t=>"string"==typeof t)&&O(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 I)null===Reflect.get(e,t)&&Reflect.deleteProperty(e,t);if(!Array.isArray(e.fieldSchemaJSON))return e;let n;try{n=$(e.fieldSchemaJSON)}catch{n=[]}return{...e,fieldSchemaJSON:n}}(i);if(!this.#u(e))return;return void this.#p(r,n,e)}case"payload-document-event":{const t=function(t){const e=t;return!!L(e.action,t=>"updated"===t||"created"===t||"deleted"===t)&&!!L(e.slug,t=>"string"==typeof t)&&!!L(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=E(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{P(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 L(t,e){return void 0===t||e(t)}function O(t,e){return null==t||e(t)}function E(t){if("object"!=typeof t||null===t)return!1;const e=Object.getPrototypeOf(t);return null===e||null===Object.getPrototypeOf(e)}var I=["data","fieldSchemaJSON","globalSlug","collectionSlug","locale","ready","previewToken","protocolVersion"],U=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]}},F=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 j(t){return(...e)=>{try{P(t(...e))}catch{}}}function D(){}var H=j((...t)=>console.error(...t)),G=j((...t)=>console.warn(...t)),z=j((...t)=>console.debug(...t));function W(t){for(const e of t){const t=e.codePointAt(0);if(void 0!==t&&(t<=31||127===t))return!0}return!1}function V(t){if(void 0===t||0===t.length||t.length>128||"."===t||".."===t||t.includes("/")||t.includes("\\")||t.includes("?")||t.includes("#")||W(t))return!1;try{return encodeURIComponent(t),!0}catch{return!1}}var B=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?D:j(t.log),null,0,0]}canMerge(t){try{return t.globalSlug?V(t.globalSlug):!!V(t.collectionSlug)&&function(t){if("number"==typeof t)return Number.isFinite(t);if("string"!=typeof t||0===t.length||t.length>512||"."===t||".."===t||t.includes("/")||t.includes("\\")||W(t))return!1;try{return encodeURIComponent(t),!0}catch{return!1}}(t.data.id)}catch{return!1}}async merge(t){if(this.s[7]>0)return{status:"superseded"};const e=this.s[6]+1;this.s[6]=e;const n=this.s[5];this.s[5]=null;let i=null;try{if(n?.abort(),!_(this.s,e))return{status:"superseded"};if(!this.canMerge(t))return _(this.s,e)?{status:"unavailable"}:{status:"superseded"};if(!_(this.s,e))return{status:"superseded"};const r=this.s[3]??("function"==typeof fetch?fetch:void 0);if(!_(this.s,e))return{status:"superseded"};if(void 0===r)return{status:"unavailable"};if(i=new AbortController,!_(this.s,e))return i.abort(),{status:"superseded"};this.s[5]=i;const s=t.globalSlug?`globals/${encodeURIComponent(t.globalSlug)}`:`${encodeURIComponent(t.collectionSlug??"")}/${encodeURIComponent(String(t.data.id))}`,o=`${this.s[0]}${this.s[1]}/${s}`,a=JSON.stringify({data:t.data,depth:this.s[2],flattenLocales:!1,...void 0!==t.locale?{locale:t.locale}:{}});if(!_(this.s,e))return{status:"superseded"};const l=await r(o,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json","X-Payload-HTTP-Method-Override":"GET"},body:a,signal:i.signal});if(!_(this.s,e)||q(i.signal))return{status:"superseded"};const u=l.ok;if(!_(this.s,e))return{status:"superseded"};if(!u){const t=l.status;return _(this.s,e)?(this.s[4]("merge HTTP",t,o),_(this.s,e)?{status:"unavailable"}:{status:"superseded"}):{status:"superseded"}}const c=await l.json();return!_(this.s,e)||q(i.signal)?{status:"superseded"}:null===c||"object"!=typeof c||Array.isArray(c)?(this.s[4]("merge invalid",o),_(this.s,e)?{status:"unavailable"}:{status:"superseded"}):{status:"merged",doc:c}}catch(t){return!_(this.s,e)||null!==i&&q(i.signal)?{status:"superseded"}:(this.s[4]("merge exception",t),_(this.s,e)?{status:"unavailable"}:{status:"superseded"})}finally{null!==i&&_(this.s,e)&&this.s[5]===i&&(this.s[5]=null)}}destroy(){this.s[6]+=1;const t=this.s[5];this.s[5]=null,this.s[7]+=1;try{t?.abort()}finally{this.s[7]-=1}}};function _(t,e){return t[6]===e}function q(t){return t.aborted}var J=new Set(["http:","https:","mailto:","tel:"]),Q=/^\s*(?:javascript|data|vbscript|file|blob|about)\s*:/i,X=/^(?:\.{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(Q.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 J.has(t.protocol)}catch{return X.test(e)}}function isExternalHttpUrl(t){if(!isSafeUrl(t))return!1;const e=t.trim();return/^https?:\/\//i.test(e)||/^\/\/[^/]/.test(e)}var Y=new Set(["style","srcdoc","formaction","form","id","name","is","srcset","imagesrcset"]),K=new Set(["href","src","poster","cite","action","xlink:href","data"]),Z=new WeakSet;function tt(t){return Z.add(t),t}var et=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(!nt(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;nt(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){nt(t,this.s[16])&&(this.#S(),this.#A(),this.s[17]=!0)}flushNow(){return this.#S(),this.#T()}notifyVisible(t){const e=this.s[10],n=e.get(t);if(!n)return;if(e.delete(t),!this.#k(n))return;const i=performance.now(),r=this.#C(n)?1:0;this.s[6]?.(this.#$(n,r,0,performance.now()-i,1===r?[n.target.fieldName]:[]))}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}get gateThreshold(){return this.s[3]}get gateActive(){return!this.s[4]&&this.s[5]()>this.s[3]}#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.#T())});n||this.s[15]!==t||(this.s[14]=i)}#T(){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=0;const r=[];let s,o=0;this.s[11].add(n);try{for(const t of n.values()){if(!this.#k(t))continue;const n=!e||this.s[2](t.target.element);this.#k(t)&&(s??=t,n?(this.s[10].delete(t.target.element),this.#C(t)&&(i+=1,r.push(t.target.fieldName))):(this.s[10].set(t.target.element,t),o+=1))}}finally{this.s[11].delete(n)}const a=this.#$(s,i,o,performance.now()-t,r);return this.s[6]?.(a),a}#k(t){return void 0===t.identity||!this.s[17]&&nt(t.identity,this.s[16])}#C(t){const e=this.s[0];return!1!==e(t)||(n=e,!Z.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,r){return{applied:e,appliedFields:r,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 nt(t,e){return null!==e&&t.generation===e.generation&&t.revision===e.revision}var it="1.8.0",rt=new Set(["__proto__","prototype","constructor"]);function st(t,e,n,i=!1){if(i&&void 0!==n){const i=ot(t,`${e}_${n}`);if(void 0!==i)return i}const r=ot(t,e);if(void 0!==r)return r;if(e.includes(".")){let n=t,i=!0;for(const t of e.split(".")){if(rt.has(t)||null===n||"object"!=typeof n){i=!1;break}if(n=ot(n,t),void 0===n){i=!1;break}}if(i)return n}return void 0===n?void 0:ot(t,`${e}_${n}`)}function ot(t,e){if(!rt.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 at="payload-live-preview-a11y";function lt(t){return/^de(?:[-_]|$)/i.test(t)}var ut=new WeakMap;function ct(t){null!==t[4]&&(clearTimeout(t[4]),t[4]=null),t[2]?.remove(),t[2]=null}var dt=class{s;constructor(t,e){const n=e??("undefined"==typeof document?null:document),i=n?.documentElement.getAttribute("lang")??"";this.s=[lt(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=ut.get(t);return e??=[null,!1,null,0,null],ut.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];ct(e),t&&n.remove()}let i=t.getElementById(at);return e[1]=null===i,i||(i=t.createElement("div"),i.id=at,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&&ct(t),t[1]&&n?.remove(),t[0]=null,ut.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&&ct(n)},1500);n[4]=r}},ht=new Set(["tabs","row","collapsible"]);function ft(t,e=""){const n=new Map;return pt(t,e,n),n}function pt(t,e,n){for(const i of t){if(ht.has(i.type)){i.fields&&pt(i.fields,e,n);continue}if("group"===i.type){const t=""===e?i.name:`${e}.${i.name}`;n.set(t,i),i.fields&&pt(i.fields,t,n);continue}const t=""===e?i.name:`${e}.${i.name}`;if(n.set(t,i),"array"===i.type&&i.fields)pt(i.fields,`${t}.*`,n);else if("blocks"===i.type&&i.blocks)for(const e of i.blocks)pt(e.fields,`${t}.*.${e.slug}`,n)}}function gt(t){if("object"!=typeof t||null===t)return;const e=t.id;return"string"==typeof e||"number"==typeof e?e:void 0}function mt(t){if("object"!=typeof t||null===t)return;const e=t.blockType;return"string"==typeof e?e:void 0}function vt(t,e){return e.every(t=>void 0!==gt(t))?function(t,e){const n=[],i=new Map;for(let e=0;e<t.length;e+=1){const n=gt(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=gt(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];mt(u)===mt(o)?(l!==s&&n.push({kind:"move",from:l,to:s,value:o}),yt(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)yt(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 yt(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 bt={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"},wt=[0,500,1e3,2e3],St=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??Tt,l=t.onHeartbeatTimeout,u=void 0===t.log?D:j(t.log),c=void 0===t.warn?G:j(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 dt(t.a11yLocale,e)}(t),h=void 0!==t.dataMerge?new B({serverURL:t.dataMerge.serverURL,...void 0!==t.dataMerge.apiRoute?{apiRoute:t.dataMerge.apiRoute}:{},...void 0!==t.dataMerge.depth?{depth:t.dataMerge.depth}:{},...void 0!==t.dataMerge.fetchFn?{fetchFn:t.dataMerge.fetchFn}:{},log:(...t)=>{u(...t)}}):null,f=new y,p=new k({onStructuralChange:()=>{this.#M()},onVisibilityChange:(t,e)=>{e&&this.d[3].notifyVisible(t)}},{...void 0!==t.intersectionRootMargin?{intersectionRootMargin:t.intersectionRootMargin}:{}}),g=new et(tt(t=>this.#P(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.#R(t)}}),m=new R(t.originMatcher,{onUpdate:(t,e,n)=>{this.#L(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",code:"LP0502"})}u("LP0501 message rejected:",t,n)},...void 0!==t.validateToken?{validateToken:t.validateToken}:{}}),v=new F(()=>{}),b=new U({...void 0!==t.heartbeatMs?{timeoutMs:t.heartbeatMs}:{},onTimeout:()=>{this.#O()}});this.d=[e,f,p,g,m,v,b,n,i,r,s,o,a,l,u,c,[],d,h,!0===t.scopeBindingsByOwner,t.lockedOrigin??(()=>{})],this.l=[void 0,void 0,void 0,negotiateProtocol(void 0),!1,null,0,null,new Set,!1,!1,0,null,new Set]}start(){if(this.l[4])return!1;this.l[4]=!0;const t=this.d[10];if(At(t)&&"loading"===t.readyState){const e=()=>{if(this.l[4]){this.l[5]=null;try{this.#E()}catch(t){this.#I(),this.#U(t,"startup","LP0605")}}};this.l[5]=e;try{t.addEventListener("DOMContentLoaded",e,{once:!0})}catch(t){throw this.#I(),t}return!0}try{return this.#E(),!0}catch(t){throw this.#I(),t}}#E(){if(!this.l[4])return;const t=At(this.d[10])?this.d[10].body:this.d[10];if(null===t)throw new Error("LivePreviewRuntime: document.body unavailable");if(this.d[2].start(t),this.#F(),this.#j()&&(this.d[4].attach(),this.d[0].emitWhile("init",{timestamp:Date.now()},()=>this.l[4]),this.#j()))for(const t of wt){if(!this.#j())return;if(0===t){if(this.d[12](this.d[11]),!this.#j())return}else{const e=setTimeout(()=>{this.l[4]&&this.#D()},t);this.d[16].push(e)}}}suspend(){return!!this.l[4]&&(this.#H()&&this.d[0].emit("disconnect",{reason:"unload",timestamp:Date.now()}),!0)}destroy(){this.l[4]&&(this.#H()&&this.d[0].emit("disconnect",{reason:"destroy",timestamp:Date.now()}),this.d[17]?.detach(),this.d[0].emit("destroy",{timestamp:Date.now()}))}#H(){this.l[7]=null,this.l[4]=!1;const t=this.l[5];this.l[5]=null,null!==t&&At(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()}#I(){this.#H(),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]}inspect(){const t=this.d[1],e=this.d[3],n=this.l[3],i=this.l[7],r=this.l[12],s=[],o=new Set;for(const[e,n]of t.entries()){s.push(e);for(const t of n)void 0!==t.owner&&o.add(t.owner)}return{version:it,started:this.l[4],status:this.d[5].status,origins:{trusted:[...this.d[11]],locked:this.d[20]()},protocol:{ours:n.ours,theirs:n.theirs,negotiated:n.negotiated,capabilities:[...n.capabilities].sort()},revisions:{accepted:this.l[6],superseded:this.l[11],active:null===i?void 0:i.identity.revision},bindings:{elements:t.elementCount,fields:t.fieldCount,fieldNames:s.sort(),absentFields:[...this.l[13]].sort(),orphanFields:[...this.l[8]].sort(),ownerScoped:this.d[19],owners:[...o].sort()},scheduler:{pending:e.pendingCount,deferred:e.replayCount,visibilityGateThreshold:e.gateThreshold,visibilityGateActive:e.gateActive,lastFlush:null===r?void 0:{applied:r.applied,appliedFields:r.appliedFields,deferred:r.deferred,durationMs:r.durationMs}},renderers:Object.keys(this.d[7]).sort()}}#F(){if(!this.l[4])return;const t=this.d[1].buildFromRoot(this.d[10]);if(this.d[14]("cache",t),this.#j()&&(this.d[0].emitWhile("cacheRefresh",t,()=>this.l[4]),this.#j()))for(const t of this.d[1].values()){if(!this.#j())return;this.d[2].observeElement(t.element)}}#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.#F(),this.#j()){for(const e of this.d[1].values()){const n=t.get(e.element);n?.fieldName===e.fieldName?this.d[3].retarget(e):this.d[3].forget(e.element),t.delete(e.element)}for(const e of t.values())this.d[3].forget(e.element)}}#z(t){const e=this.l[3];if(e.theirs===t)return;const n=negotiateProtocol(t);this.l[3]=n,n.negotiated!==e.negotiated&&this.d[14]("protocol","ours=4",`theirs=${t}`,`negotiated=${n.negotiated}`)}#L(t,e,n){if(this.d[6].kick(),void 0===t.data)return void(void 0!==t.protocolVersion&&this.#z(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]=ft(t.fieldSchemaJSON));const i={identity:n,message:t,locale:this.l[0],schema:this.l[1],schemaIndex:this.l[2],cancelled:!1};if(null!==this.l[7]&&(this.l[11]+=1),this.l[7]=i,this.d[3].acceptRevision(n),this.l[6]+=1,void 0===t.protocolVersion||(this.#z(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.#W(i)}}async#W(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.#B(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}#B(t,e){if(!this.l[4]||this.l[7]!==t)return;const n=()=>this.l[4]&&this.l[7]===t,i=this.#_(t,e.fields);for(const[r,s]of this.d[1].entries()){if(!this.l[4]||this.l[7]!==t)return;for(const o of s){if(!1!==i&&!A(o.owner,i))continue;const s=st(e.fields,r,o.locale??t.locale,void 0!==o.locale);if(void 0===s){this.l[13].add(r);continue}if(!this.l[4]||this.l[7]!==t)return;const a=this.#q(o,s,e.fields,n);if(!this.l[4]||this.l[7]!==t)return;const l={target:o,value:a,allFields:e.fields,identity:t.identity,data:e};if(!this.l[4]||this.l[7]!==t)return;this.d[3].schedule(l)}}this.#J(e.fields,t.locale,i)}#_(t,e){if(!this.d[19])return!1;const{message:n}=t,i=function(t){if(S(t.globalSlug))return[(e=t.globalSlug,`global:${e}`)];var e;if(!S(t.collectionSlug))return null;const n=w(t.collectionSlug);return S(t.documentId)?[n,w(t.collectionSlug,t.documentId)]:[n]}({globalSlug:"string"==typeof n.globalSlug?n.globalSlug:void 0,collectionSlug:"string"==typeof n.collectionSlug?n.collectionSlug:void 0,documentId:T(e)});return null!==i||this.l[9]||(this.l[9]=!0,this.d[15]("[live-preview] LP0202: scopeBindingsByOwner: update names no document; nothing applied")),i}#Q(t){for(const e of this.d[1].values())if(A(e.owner,t))return!0;return!1}#X(t,e){const n=this.d[1].get(t);return void 0!==n&&(!1===e||n.some(t=>A(t.owner,e)))}#J(t,e,n){if(0===this.d[1].fieldCount)return;if(!1!==n&&!this.#Q(n))return;let i;for(const[r,s]of Object.entries(t)){if(this.l[8].has(r))continue;if(Ct.has(r))continue;if(!$t(s))continue;const t=Nt(r,e);if(!(this.#X(r,n)||t!==r&&this.#X(t,n))){if(void 0===i){i=new Set;for(const[t,e]of this.d[1].entries())for(const r of e)(!1===n||A(r.owner,n))&&void 0!==r.locale&&i.add(`${t}_${r.locale}`)}i.has(r)||(this.l[8].add(r),this.d[15](`[live-preview] LP0201: update arrived for field "${r}" but no <… data-payload-field="${t}"> element exists on this page. Render the binding anchor unconditionally in your template so live edits to an initially-empty field have somewhere to land.`))}}}#q(t,e,n,i){if(void 0===this.d[9])return e;try{const r=this.d[9](t.fieldName,e,{element:t.element,allFields:n},i),s=P(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",code:"LP0602"}),e}}#j(){return this.l[4]}#Y(t){0!==t.deferred&&(this.l[10]||(this.l[10]=!0,this.d[15](`[live-preview] LP0301: visibility gate held ${String(t.deferred)} offscreen update(s) until scrolled into view; see visibilityGateThreshold.`)))}#P(t){const e=this.l[7];if(null===e||void 0===t.identity||!kt(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(bt,t))return bt[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",code:"LP0603"},()=>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(Y.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 K.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] LP0401: 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 Z.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",code:"LP0603"},()=>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)}#R(t){this.l[12]=t,this.#Y(t);const{identity:e,data:n}=t;if(0===t.applied||void 0===e||void 0===n)return;const i=this.l[7];if(null===i||!this.l[4]||this.l[7]!==i||!kt(i.identity,e))return;const r=()=>this.l[4]&&this.l[7]===i&&kt(i.identity,e);this.d[17]?.announceUpdate(t.applied),r()&&0!==this.d[0].listenerCount("afterUpdate")&&this.d[0].emitWhile("afterUpdate",{data:n,updatedCount:t.applied,durationMs:t.durationMs,revision:e.revision},r)}#O(){if(!this.#j())return;this.d[4].advanceGeneration();const t=this.l[7];this.l[7]=null,null!==t&&this.d[3].cancelRevision(t.identity),this.d[18]?.destroy();const e=this.d[5].markDisconnected();try{this.d[13]?.()}catch(t){this.d[14]("heartbeat:",t)}if(this.#j()){if(e&&this.#K()){if(this.d[17]?.announceDisconnected(),this.d[0].emitWhile("disconnect",{reason:"timeout",timestamp:Date.now()},()=>this.#K()),!this.#j())return;if(this.#K()&&(this.d[14]("connection","connected","→","disconnected"),!this.#j()))return}this.#j()&&this.#D()}}#D(){try{this.d[12](this.d[11])}catch(t){this.#U(t,"ready","LP0606")}}#U(t,e,n){const i=t instanceof Error?t:new Error(String(t));this.d[0].emit("error",{error:i,context:e,code:n})}#K(){return this.l[4]&&"disconnected"===this.d[5].status&&null===this.l[7]}};function At(t){return 9===t.nodeType}function Tt(t){if("undefined"==typeof window)return;const e=[];window.parent!==window&&e.push(window.parent),window.opener instanceof Window&&e.push(window.opener),R.sendReady(e,t)}function kt(t,e){return t.generation===e.generation&&t.revision===e.revision}var Ct=new Set(["id","_id","createdAt","updatedAt","createdBy","updatedBy","_status","globalType","collection","locale","localized"]);function $t(t){return null!=t&&("string"==typeof t||"number"==typeof t||"boolean"==typeof t||"bigint"==typeof t)}function Nt(t,e){if(!e)return t;const n=`_${e}`;return t.endsWith(n)?t.slice(0,-n.length):t}var xt,Mt=class{#Z=new Map;#tt=new Map;on(t,e){return this.#et(this.#Z,t,e)}once(t,e){return this.#et(this.#tt,t,e)}off(t,e){this.#nt(this.#Z,t,e),this.#nt(this.#tt,t,e)}async emit(t,e){await this.#it(t,e)}async emitWhile(t,e,n){return this.#it(t,e,n)}async#it(t,e,n){const i=()=>n?.()??!0;if(!i())return!1;const r=this.#Z.get(t);if(r)for(const n of[...r]){if(!i())return!1;if(await this.#rt(n,e,t),!i())return!1}if(!i())return!1;const s=this.#tt.get(t);if(s&&s.size>0){const n=[...s];this.#tt.delete(t);for(const r of n){if(!i())return!1;if(await this.#rt(r,e,t),!i())return!1}}return i()}listenerCount(t){return(this.#Z.get(t)?.size??0)+(this.#tt.get(t)?.size??0)}removeAllListeners(t){if(void 0===t)return this.#Z.clear(),void this.#tt.clear();this.#Z.delete(t),this.#tt.delete(t)}eventNames(){const t=new Set;for(const e of this.#Z.keys())t.add(e);for(const e of this.#tt.keys())t.add(e);return[...t]}#et(t,e,n){let i=t.get(e);return i||(i=new Set,t.set(e,i)),i.add(n),()=>{this.#nt(t,e,n)}}#nt(t,e,n){const i=t.get(e);void 0!==i&&(i.delete(n),0===i.size&&t.delete(e))}async#rt(t,e,n){try{await t(e)}catch(t){const e="string"==typeof n||"number"==typeof n?String(n):"<event>";H(`[live-preview] LP0601: handler for "${e}" threw:`,t)}}};function isInIframe(){if("undefined"==typeof window)return!1;try{return window.self!==window.top}catch{return!0}}function isInPopup(){return"undefined"!=typeof window&&null!=window.opener}function isInPreviewContext(){return isInIframe()||isInPopup()}function isDevMode(){const t=function(){if("undefined"==typeof process)return;const t=process.env.NODE_ENV;return"string"==typeof t?t:void 0}();if(void 0!==t)return"production"!==t;const e=function(){const t=Rt();if(!t)return;const e=t.DEV;return"boolean"==typeof e?e:void 0}();if(void 0!==e)return e;if("undefined"!=typeof window){const t=window.location.hostname;if("localhost"===t||"127.0.0.1"===t)return!0}return!1}function Pt(t){if("undefined"!=typeof process){const e=process.env[t];if("string"==typeof e&&e.length>0)return e}const e=Rt();if(e){const n=e[t];if("string"==typeof n&&n.length>0)return n}}function Rt(){if("undefined"==typeof __INLINE_RUNTIME_BUILD__||!__INLINE_RUNTIME_BUILD__){if(void 0!==xt)return xt??void 0;xt=null;try{const t=new Function("try { return import.meta && import.meta.env; } catch (_) { return undefined; }")();if(t&&"object"==typeof t)return xt=t}catch{}}}var Lt=/^https?:\/\/(localhost|127\.0\.0\.1)(?::\d+)?$/i,Ot=/^https?:\/\/[^/?#\s]+$/i,Et=["PAYLOAD_ADMIN_ORIGIN","PUBLIC_PAYLOAD_ADMIN_ORIGIN","NEXT_PUBLIC_PAYLOAD_ADMIN_ORIGIN"],It=class{#st;constructor(t={}){const e=new Set;for(const n of t.additionalOrigins??[]){const t=Ft(n);void 0!==t&&e.add(t)}for(const t of Et){const n=Pt(t);if(void 0!==n)for(const t of n.split(",")){const n=Ft(t);void 0!==n&&e.add(n)}}let n;if(t.enableReferrerDetection??1){const e=t.referrer??("undefined"!=typeof document?document.referrer:"");if(e.length>0)try{const t=new URL(e).origin;t&&"null"!==t&&(n=t)}catch{}}const i=(t.enableLocalhostMatching??!0)&&(t.forceDevMode??isDevMode());this.#st=[e,n,i,void 0!==n,void 0]}matches(t){return 0!==t.length&&"null"!==t&&(void 0!==this.#st[4]?t===this.#st[4]:!!this.#st[0].has(t)||0===this.#st[0].size&&void 0!==this.#st[1]&&t===this.#st[1]||!(!this.#st[2]||!Lt.test(t)))}lockOrigin(t){return!!this.matches(t)&&(this.#st[4]=t,!0)}unlockOrigin(){const t=this.#st[4];return this.#st[4]=void 0,t}get lockedOrigin(){return this.#st[4]}enumerate(){if(void 0!==this.#st[4])return[this.#st[4]];const t=new Set(this.#st[0]);if(0===this.#st[0].size&&void 0!==this.#st[1]&&t.add(this.#st[1]),this.#st[2])for(const e of Ut)t.add(`http://localhost:${String(e)}`),t.add(`http://127.0.0.1:${String(e)}`);return[...t]}get referrerWasAvailable(){return this.#st[3]}get isProductionUnconfigured(){return!(!isInIframe()||this.#st[0].size>0||this.#st[2]||void 0!==this.#st[1])}get isReferrerOnlyTrust(){return!(this.#st[0].size>0||this.#st[2]||void 0===this.#st[1])}},Ut=[3e3,3001,3333,4e3,4321,5e3,5173,5174,8e3,8080,8888,9e3];function Ft(t){const e=t.trim();if(0!==e.length)try{const t=new URL(e);if("http:"!==t.protocol&&"https:"!==t.protocol)return;if(!Ot.test(t.origin))return;return t.origin}catch{return}}var jt,Dt=()=>{},Ht=class{#ot;#at;#lt=new Set;#st="staging";constructor(t,e){this.#ot=t,this.#at=e}assertOpen(){if("closed"===this.#st)throw new Error(`Plugin context for "${this.#ot}" is no longer active`)}get active(){return"active"===this.#st}eligible(){return"closed"!==this.#st}own(t){return this.assertOpen(),this.#ut({acquire:void 0,finalize:void 0,cleanup:t,disposed:!1})}stage(t,e){this.assertOpen();const n={acquire:t,finalize:e,cleanup:void 0,disposed:!1},i=this.#ut(n);if("active"===this.#st)try{this.#ct(n)}catch(t){throw this.#dt(n),t}return i}commit(){if("staging"!==this.#st)throw new Error(`Plugin context for "${this.#ot}" cannot be committed`);this.#st="committing";try{for(const t of this.#lt)this.#ct(t);this.#st="active"}catch(t){throw this.close(),t}}close(){if("closed"!==this.#st){this.#st="closed";for(const t of[...this.#lt].reverse())this.#dt(t);this.#lt.clear()}}#ut(t){return this.#lt.add(t),()=>{this.#dt(t)}}#ct(t){if(t.disposed||void 0!==t.cleanup||void 0===t.acquire)return;const e=t.acquire();t.cleanup=e??Dt}#dt(t){if(t.disposed)return;t.disposed=!0,this.#lt.delete(t);const e=t.cleanup;if(t.cleanup=void 0,void 0!==e)try{P(e())&&this.#at(`plugin "${this.#ot}" cleanup returned a Promise/thenable; cleanups must be synchronous`)}catch(t){this.#at(`plugin "${this.#ot}" cleanup failed:`,t)}try{t.finalize?.()}catch(t){this.#at(`plugin "${this.#ot}" cleanup failed:`,t)}}},Gt=class extends Mt{#ht;#ft;#pt=new Set;constructor(t,e){super(),this.#ht=t,this.#ft=e}on(t,e){return this.#gt("on",t,e)}once(t,e){return this.#gt("once",t,e)}off(t,e){const n=e;for(const e of[...this.#pt])e.event===t&&e.handler===n&&e.dispose()}emit(t,e){return this.#ft.assertOpen(),this.#ht.emit(t,e)}emitWhile(t,e,n){return this.#ft.assertOpen(),this.#ht.emitWhile(t,e,()=>{if(!this.#ft.eligible())return!1;const t=n();return!!this.#ft.eligible()&&t})}listenerCount(t){let e=0;for(const n of this.#pt)n.event===t&&(e+=1);return e}removeAllListeners(t){for(const e of[...this.#pt])void 0!==t&&e.event!==t||e.dispose()}eventNames(){const t=new Set;for(const e of this.#pt)t.add(e.event);return[...t]}#gt(t,e,n){this.#ft.assertOpen();const i=n,r=[...this.#pt].find(n=>n.kind===t&&n.event===e&&n.handler===i);if(void 0!==r)return r.dispose;let s=Dt,o=!0;const a=async e=>{this.#ft.active&&o&&("once"===t&&s(),await n(e))},l={kind:t,event:e,handler:i,dispose:Dt};return s=this.#ft.stage(()=>this.#ht[t](e,a),()=>{o=!1,this.#pt.delete(l)}),l.dispose=s,this.#pt.add(l),s}},zt=class{#ht;#mt;#vt;#yt;#at;#bt=new Map;#wt=new Map;#St=new Map;#At=new Set;#Tt=new Map;#kt=Promise.resolve();#Ct=0;constructor(t){this.#ht=t.events,this.#mt=t.config,this.#vt=t.registerFieldRenderer,this.#at=j(t.log);const e=t.onTransformError;this.#yt=void 0===e?void 0:j((...t)=>{const n=t[0];if(n instanceof Error)try{return e(n)}catch(t){return void this.#at("transform error reporter failed:",t)}})}register(t){return this.#Ct>0?this.#$t(t):this.#Nt(()=>this.#$t(t))}unregister(t){return this.#Ct>0?this.#xt(t):this.#Nt(async()=>{await this.#xt(t)})}destroyAll(){return this.#Ct>0?this.#Mt():this.#Nt(async()=>{await this.#Mt()})}applyTransforms(t,e,n,i){const r=this.#Tt.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=P(s);if(!1===i?.())return e;if(o)throw new TypeError(`Transform for "${t}" returned a Promise/thenable; transforms must be synchronous`)}catch(n){if(!1===i?.())return e;const r=n instanceof Error?n:new Error(String(n));return this.#at(`transform for "${t}" failed:`,r),this.#yt?.(r),e}}return s}list(){return[...this.#bt.keys()]}get size(){return this.#bt.size}async#$t(t){if(this.#bt.has(t.name)||this.#wt.has(t.name)||this.#St.has(t.name))return void this.#at(`plugin "${t.name}" already registered`);const e=new Ht(t.name,this.#at),n=this.#Pt(t.name,e),i={scope:e,cancelled:!1};this.#wt.set(t.name,i);try{if(await this.#Rt(()=>t.init(n)),i.cancelled)return;e.commit()}catch(n){return e.close(),void(i.cancelled||this.#at(`plugin "${t.name}" init failed:`,n))}finally{this.#wt.get(t.name)===i&&this.#wt.delete(t.name)}this.#bt.set(t.name,{plugin:t,scope:e}),this.#at(`plugin "${t.name}" registered`)}#Pt(t,e){return{events:new Gt(this.#ht,e),registerFieldRenderer:t=>{e.stage(()=>{const e=this.#vt(t);return"function"==typeof e?e:void 0})},registerTransform:(t,n)=>{const i={transform:n,active:!1};e.stage(()=>{i.active=!0;const e=this.#Tt.get(t);return void 0===e?this.#Tt.set(t,[i]):e.push(i),()=>{i.active=!1;const e=this.#Tt.get(t);if(void 0===e)return;const n=e.indexOf(i);n>=0&&e.splice(n,1),0===e.length&&this.#Tt.delete(t)}})},registerCleanup:t=>{e.own(t)},getConfig:()=>this.#mt,log:(...e)=>{this.#at(`[${t}]`,...e)}}}#xt(t){const e=this.#wt.get(t);if(void 0!==e)return e.cancelled=!0,e.scope.close(),Promise.resolve();const n=this.#St.get(t);if(void 0!==n)return this.#At.has(t)?Promise.resolve():n;const i=this.#bt.get(t);if(void 0===i)return Promise.resolve();this.#bt.delete(t),i.scope.close();const r=Promise.resolve().then(()=>this.#Lt(t,i.plugin));return this.#St.set(t,r),r.then(()=>{this.#St.get(t)===r&&this.#St.delete(t)}),r}async#Lt(t,e){if(void 0!==e.destroy){this.#At.add(t);try{await this.#Rt(()=>e.destroy?.())}catch(e){this.#at(`plugin "${t}" destroy failed:`,e)}finally{this.#At.delete(t)}}}async#Mt(){for(const t of this.#wt.values())t.cancelled=!0,t.scope.close();const t=[...this.#bt.keys()];for(const e of t)await this.#xt(e)}async#Rt(t){this.#Ct+=1;try{await t()}finally{this.#Ct-=1}}#Nt(t){const e=this.#kt.then(t);return this.#kt=e.catch(t=>{this.#at("plugin manager mutation failed:",t)}),e}},Wt=class{#Ot;#Et;#It=new Map;constructor(t){this.#Ot=t,this.#Et={...t}}get renderers(){return this.#Et}resolve(t){return this.#Et[t]}register(t){const e=t.name,n={renderer:t},i=this.#It.get(e);void 0===i?this.#It.set(e,[n]):i.push(n),this.#Et[e]=t;let r=!0;return()=>{if(!r)return;r=!1;const t=this.#It.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.#It.delete(e),!s)return;const o=t.at(-1),a=o?.renderer??this.#Ot[e];void 0===a?Reflect.deleteProperty(this.#Et,e):this.#Et[e]=a}}},Vt=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"]),Bt=new Set(["script","style","iframe","object","embed","link","meta","base","form","input","button","select","textarea","svg","math","template","frame","frameset","noframes","noscript"]),_t=new Set(["id","class","lang","dir","title","role","tabindex"]),qt={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"])},Jt=new Set(["href","src","cite","poster"]),Qt=class extends Error{name="SanitizerEnvironmentError"};function setSanitizerDocument(t){jt=t??void 0}function sanitizeHtml(t,e){const n=Xt();if(!n)throw new Qt("sanitizeHtml needs a DOM; provide one with setSanitizerDocument() during SSR.");if(""===t)return"";const i=function(t){if(!t){const t=new Map;for(const[e,n]of Object.entries(qt))t.set(e,n);return{allowedTags:Vt,attrByTag:t}}const e=new Set(Vt);for(const n of t.additionalAllowedTags??[])e.add(n);const n=new Map;for(const[t,e]of Object.entries(qt))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,Yt(r.content,i),r.innerHTML}function Xt(){return jt||("undefined"!=typeof document?document:void 0)}function Yt(t,e){for(const n of Array.from(t.childNodes))1===n.nodeType?Kt(n,e):8===n.nodeType&&n.remove()}function Kt(t,e){const n=t.tagName.toLowerCase();if(Bt.has(n))t.remove();else{if(!e.allowedTags.has(n)){Yt(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?_t.has(n)||n.startsWith("aria-")||n.startsWith("data-")||(i?.has(n)?Jt.has(n)&&!isSafeUrl(e.value)?t.removeAttribute(e.name):"srcset"!==n||Zt(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),Yt(t,e)}}function Zt(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 te=new Map;function ee(t,e){te.set(t,e)}var ne={1:"left",2:"center",3:"right",4:"justify"},ie=new Set(["left","center","right","justify","start","end"]);function re(t){const e=t.format;if("string"==typeof e&&ie.has(e))return e;if("number"==typeof e){const t=ne[e];if(void 0!==t)return t}}function se(t){const e=t.indent;return"number"==typeof e&&e>0?e:0}function oe(t){return"rtl"===t.direction?' dir="rtl"':"ltr"===t.direction?' dir="ltr"':""}function ae(t){const e=re(t),n=se(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 le=Object.freeze({"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="}),ue=/[&<>"'/`=]/g;function escapeHtml(t){return""===t?"":t.replace(ue,t=>le[t])}var ce=Object.freeze({"&":"&","<":"<",">":">",'"':""","'":"'"}),de=/[&<>"']/g;function escapeHtmlAttribute(t){return""===t?"":t.replace(de,t=>ce[t])}function he(t){return escapeHtml(t).replace(/\r\n|\r|\n/g,"<br>")}var fe=new Set(["h1","h2","h3","h4","h5","h6"]),pe=(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 ge(t){if("string"==typeof t.text)return t.text;if(!t.children)return"";let e="";for(const n of t.children)e+=ge(n);return e}function me(t){return t.replace(/[^a-zA-Z0-9_-]/g,"")}var ve=new Map;function ye(t){return ve.get(t)}function be(t){return t.replace(/[^a-zA-Z0-9_-]/g,"-").toLowerCase()}ee("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}),ee("paragraph",(t,e)=>{const n=e.renderChildren(t.children??[]);return`<p${oe(t)}${ae(t)}>${n}</p>`}),ee("heading",(t,e)=>{const n="string"==typeof t.tag?t.tag.toLowerCase():"h2",i=fe.has(n)?n:"h2",r=e.renderChildren(t.children??[]);return`<${i}${oe(t)}${ae(t)}>${r}</${i}>`}),ee("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}${oe(t)}${ae(t)}${r}${s}>${o}</${i}>`}),ee("listitem",(t,e)=>{const n=e.renderChildren(t.children??[]);if("boolean"==typeof t.checked)return`<li role="checkbox" aria-checked="${t.checked?"true":"false"}"${ae(t)}>${n}</li>`;const i="number"==typeof t.value?` value="${escapeHtml(String(t.value))}"`:"";return`<li${oe(t)}${ae(t)}${i}>${n}</li>`}),ee("link",pe),ee("autolink",pe),ee("quote",(t,e)=>{const n=e.renderChildren(t.children??[]);return`<blockquote${oe(t)}${ae(t)}>${n}</blockquote>`}),ee("code",t=>{const e=me("string"==typeof t.language?t.language:"");return`<pre><code${""===e?"":` class="language-${e}"`}>${escapeHtml(ge(t))}</code></pre>`}),ee("code-highlight",t=>{const e="string"==typeof t.text?t.text:"";return`<span${"string"==typeof t.highlightType?` class="token-${me(t.highlightType)}"`:""}>${escapeHtml(e)}</span>`}),ee("linebreak",()=>"<br>"),ee("horizontalrule",()=>"<hr>"),ee("tab",()=>"\t"),ee("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)}),ee("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>`}),ee("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=be(i);if(""!==i){const t=ye(i)??ye(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-${be(t)}="${escapeHtml(n)}"`)}return`<div${0===s.length?"":` ${s.join(" ")}`}></div>`});var we={renderChildren:Te,resolveAlignment:re,resolveIndent:se};function Se(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 Ae(t){return Se(t)?t.root.children.map(Ce).join("\n").trim():""}function Te(t){let e="";for(const n of t)e+=ke(n);return e}function ke(t){const e=(n=t.type,te.get(n));var n;return e?e(t,we):void 0!==t.children?Te(t.children):""}function Ce(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+=Ce(n);return e}function $e(){const t=new WeakSet;return{name:"text",render:tt((e,n)=>{const i=e.element,r=function(t){return null==t?"":Se(t)?Ae(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),G(`[live-preview] LP0402: 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=he(r):i.textContent=r);i.value=r})}}function Ne(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 xe={name:"textarea",render(t,e){const n=t.element,i=Se(e)?Ae(e):Ne(e);"INPUT"!==n.tagName&&"TEXTAREA"!==n.tagName?n.innerHTML=he(i):n.value=i}},Me={name:"richText",render:tt((t,e)=>{if(Se(e))t.element.innerHTML=function(t,e={}){if(!Se(t))return"";const n=Te(t.root.children);return!1===e.sanitize||void 0===Xt()?n:sanitizeHtml(n)}(e);else{if("string"!=typeof e)return!1;t.element.innerHTML=sanitizeHtml(e)}})},Pe={name:"html",render(t,e){if(null==e)return void(t.element.textContent="");const n="string"==typeof e?e:Ne(e);t.element.innerHTML=sanitizeHtml(n)}},Re={name:"url",render(t,e,n){const i=t.element,r=Ne(e);if("A"===i.tagName){const s=i,o=t.hrefField,a=void 0===o||0===o.length?e:st(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}},Le={name:"image",render:tt((t,e,n)=>{const i=t.element,r=Oe(e),s=void 0!==t.locale,o=function(t,e,n,i,r,s){if(void 0!==n&&n.length>0){const t=st(i,n,r,s);if("string"==typeof t&&isSafeUrl(t))return t;const e=Oe(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=st(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 Oe(t){if("object"==typeof t&&null!==t)return t}var Ee={name:"upload",render:tt((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>`})},Ie={name:"relationship",render(t,e){const n=t.element,i=function(t){return null==t?[""]:Array.isArray(t)?t.map(Ue):[Ue(t)]}(e),r=i.join(", ");if("A"===n.tagName&&!Array.isArray(e)){const t=n,i=e?.url;return"string"==typeof i&&isSafeUrl(i)&&(t.href=i),void(t.textContent=r)}n.textContent=r}};function Ue(t){if("object"==typeof t&&null!==t){const e=t;return"string"==typeof e.title&&e.title.length>0?e.title:"string"==typeof e.name&&e.name.length>0?e.name:"string"==typeof e.slug&&e.slug.length>0?e.slug:void 0!==e.id?String(e.id):""}return Ne(t)}var Fe={name:"select",render(t,e){const n=t.element,i=je(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 je(t){return Array.isArray(t)?t.map(t=>je(t)).join(", "):Ne(t)}var De={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}},He=new Map,Ge=new Map;function ze(t,e){const n=t??"";if(null==e)return n;const i=We(e);return"{}"===i?n:`${n}|${i}`}function We(t){if(null===t||"object"!=typeof t)return JSON.stringify(t);if(Array.isArray(t))return`[${t.map(t=>We(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)}:${We(n)}`)}return`{${i.join(",")}}`}function Ve(t){for(;t.size>64;){const e=t.keys().next().value;if(void 0===e)break;t.delete(e)}}var Be={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:Ne(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?_e(s,n):r)):void(i.textContent=o?_e(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 _e(t,e){const n=e.locale??detectInitialLocale();try{return function(t,e){const n=ze(t,e),i=Ge.get(n);if(void 0!==i)return Ge.delete(n),Ge.set(n,i),i;const r=new Intl.DateTimeFormat(t,e);return Ge.set(n,r),Ve(Ge),r}(n,{dateStyle:"medium",timeStyle:"short"}).format(t)}catch{return t.toISOString()}}var qe={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(Ne(e));Number.isNaN(r)?i.textContent=Ne(e):"INPUT"!==i.tagName?i.textContent=function(t,e){const n=e.locale??detectInitialLocale();try{return function(t,e){const n=ze(t,e),i=He.get(n);if(void 0!==i)return He.delete(n),He.set(n,i),i;const r=new Intl.NumberFormat(t,e);return He.set(n,r),Ve(He),r}(n).format(t)}catch{return String(t)}}(r,n):i.value=String(r)}},Je=/\{\{([\s\S]*?)\}\}/g;function Qe(t,e,n,i){const r="object"==typeof e&&null!==e?e:null;return t.replace(Je,(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 Xe={name:"array",render:tt((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+=Ye(t,e[i],i);return n}(i,e);return void(n.innerHTML=sanitizeHtml(t))}const r=t.arraySeparator??", ";n.textContent=e.map(Ke).join(r)})};function Ye(t,e,n){return Qe(t,e,n,Ne)}function Ke(t){return Ne(t)}var Ze="data-payload-key",tn="data-payload-nested-key",en="data-payload-nested-template";function nn(t){const{template:e,container:n,patches:i,nextItems:r,store:s,forceRender:o=!1}=t,a=rn(n,e,i,r,o,s);return null===a?null:sn(a,s)}function rn(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=hn(a,Ze),u=new Set,c=[];for(let d=0;d<n.length;d+=1){const h=n[d],f=dn(h);let p=void 0===f?a[d]??null:fn(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?pn(t.ownerDocument,e,h,d):void 0;if(null===m)return null;const v=void 0===m?[]:on(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 sn(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]&&(ln(t[0],t[1]),t[1].replaceWith(t[0])),void 0!==t[2]&&sn(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)cn(a,t);return o}function on(t,e,n,i,r){const s=hn(null===t?[]:an(t),tn),o=dn(n),a=void 0!==o?i?.get(o):void 0,l=[];for(const t of an(e)){const e=t.getAttribute(tn);if(null===e)continue;const i=fn(s,e)??null,o=t.getAttribute(en),u=o?i:null,c=u?.getAttribute(en)??null;let d;if(o){const i=un(n,e);if(void 0!==i||null!==u){const n=i??[],s=vt(null===u?[]:un(a,e)??[],n),l=null!==u&&c!==o;if((s.length>0||l)&&(d=rn(u??t,o,s,n,l,r)??void 0,void 0===d))return null}}l.push([u,t,d])}return l}function an(t){return Array.from(t.querySelectorAll(`[${tn}]`)).filter(e=>{let n=e.parentElement;for(;null!==n&&n!==t;){if(n.hasAttribute(tn))return!1;n=n.parentElement}return n===t})}function ln(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 un(t,e){if("object"!=typeof t||null===t)return;const n=t[e];return Array.isArray(n)?n:void 0}function cn(t,e){const n=dn(e);void 0!==n&&t.set(n,e)}function dn(t){if("object"!=typeof t||null===t)return;const e=t.id;return"string"==typeof e||"number"==typeof e?String(e):void 0}function hn(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 fn(t,e){return t.get(e)?.pop()}function pn(t,e,n,i){const r=function(t,e,n){return Qe(t,e,n,Ne)}(e,n,i),s=sanitizeHtml(r),o=t.createElement("template");o.innerHTML=s;const a=o.content.firstElementChild;if(!a)return null;const l=dn(n);return void 0!==l&&a.setAttribute(Ze,l),a}function gn(){const t=new WeakMap,e=new WeakSet,n=new WeakMap;return{name:"structural-array",render:tt((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),G(`[live-preview] LP0403: 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=mn(s),u=vt(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=nn({template:o,container:s,patches:u,nextItems:r,store:n,forceRender:c});return null!==d&&(t.set(s,{values:r.slice(),template:o,domSnapshot:mn(s)}),!!d&&void 0)})}}function mn(t){return Array.from(t.children,t=>t.getAttribute(Ze))}var vn,yn=new Map,bn=[xe,Me,Pe,Re,{...Re,name:"email"},Le,Ee,Ie,Fe,{...Fe,name:"radio"},De,Be,qe,Xe,{...Xe,name:"blocks"}],wn=class{#Ut=new Mt;#Ft;#jt;#Dt;#bt;#at;#Ht=!1;#Gt=!1;#zt=null;constructor(t={}){const e=t.debug??isDevMode();this.#at=e?(...t)=>{z("[live-preview]",...t)}:D,this.#Ft=new It({...void 0!==t.allowedOrigins?{additionalOrigins:t.allowedOrigins}:{},...void 0!==t.disableReferrerDetection?{enableReferrerDetection:!t.disableReferrerDetection}:{},...void 0!==t.disableLocalhostMatching?{enableLocalhostMatching:!t.disableLocalhostMatching}:{}}),this.#Ft.isProductionUnconfigured&&this.#at("no trusted origin could be detected — set allowedOrigins or PAYLOAD_ADMIN_ORIGIN"),this.#jt=new Wt(function(t=[]){const e={};for(const n of t)e[n.name]=n;for(const[t,n]of yn)e[t]=n;return Object.freeze(e)}([$e(),...bn,gn()])),this.#bt=new zt({events:this.#Ut,config:Object.freeze({...t}),registerFieldRenderer:t=>this.#jt.register(t),onTransformError:t=>{this.#Ut.emit("error",{error:t,context:"transform",code:"LP0602"})},log:this.#at}),this.#Dt=new St({...void 0!==t.root?{root:t.root}:{},renderers:this.#jt.renderers,resolveRenderer:t=>this.#jt.resolve(t),transformValue:(t,e,n,i)=>this.#bt.applyTransforms(t,e,n,i),originMatcher:t=>this.#Ft.matches(t),readyTargets:this.#Ft.enumerate(),emitter:this.#Ut,...void 0!==t.serverURL&&""!==t.serverURL?{dataMerge:{serverURL:t.serverURL,...void 0!==t.apiRoute?{apiRoute:t.apiRoute}:{},...void 0!==t.mergeDepth?{depth:t.mergeDepth}:{},...void 0!==t.mergeFetch?{fetchFn:t.mergeFetch}:{}}}:{},...void 0!==t.debounceMs?{debounceMs:t.debounceMs}:{},...void 0!==t.heartbeatMs?{heartbeatMs:t.heartbeatMs}:{},...void 0!==t.intersectionRootMargin?{intersectionRootMargin:t.intersectionRootMargin}:{},...void 0!==t.scopeBindingsByOwner?{scopeBindingsByOwner:t.scopeBindingsByOwner}:{},...void 0!==t.disableVisibilityGate?{disableVisibilityGate:t.disableVisibilityGate}:{},...void 0!==t.visibilityGateThreshold?{visibilityGateThreshold:t.visibilityGateThreshold}:{},...void 0!==t.enableA11y?{enableA11y:t.enableA11y}:{},...void 0!==t.a11yLocale?{a11yLocale:t.a11yLocale}:{},onHeartbeatTimeout:()=>{this.#Ft.unlockOrigin()},lockedOrigin:()=>this.#Ft.lockedOrigin,...void 0!==t.validateToken?{validateToken:t.validateToken}:{},log:this.#at}),this.#Ut.on("connect",t=>{this.#Ft.lockOrigin(t.origin)}),!1!==t.autoStart&&this.start()}start(){if(this.#Gt)return!1;if(this.#Ht)return this.#Dt.start(),!0;if(!isInPreviewContext())return!1;const t=this.#Dt.start();return t&&(this.#Ht=!0),t}suspend(){return!(this.#Gt||!this.#Ht)&&this.#Dt.suspend()}resume(){return!(this.#Gt||!this.#Ht)&&this.#Dt.start()}destroy(){if(null!==this.#zt)return this.#zt;let t,e;this.#Gt=!0;const n=new Promise((n,i)=>{t=n,e=i});this.#zt=n;try{this.#Dt.destroy(),this.#bt.destroyAll().finally(()=>{this.#Ut.removeAllListeners()}).then(t,e)}catch(t){this.#Ut.removeAllListeners(),e(t)}return n}async use(t){if(this.#Gt)throw new Error("LivePreviewClient: already destroyed");await this.#bt.register(t)}async unuse(t){await this.#bt.unregister(t)}refreshCache(){this.#Dt.refreshCache()}get events(){return this.#Ut}get plugins(){return this.#bt.list()}get status(){return this.#Dt.status}inspect(){return this.#Dt.inspect()}get updateCount(){return this.#Dt.updateCount}get destroyed(){return this.#Gt}};function initLivePreview(t={}){const e=new wn({...t,autoStart:!1});return e.start()?e:null}function setCspCrypto(t){vn=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(vn?.getRandomValues)return vn;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(" ")}var Sn=Object.freeze({NoTrustedOrigin:"LP0101",ReferrerOnlyTrust:"LP0102",OrphanField:"LP0201",UnattributableUpdate:"LP0202",VisibilityGateDeferred:"LP0301",UnsafeAttributeWrite:"LP0401",TextTargetHasChildren:"LP0402",MissingArrayTemplate:"LP0403",MessageRejected:"LP0501",TokenRejected:"LP0502",HandlerThrew:"LP0601",TransformThrew:"LP0602",RendererThrew:"LP0603",StartupFailed:"LP0605",ReadyFailed:"LP0606",AuditRuntimeMissing:"LP0701",AuditNoFrameAncestors:"LP0702",AuditFrameOptionsBlocks:"LP0703",AuditBindingsExposed:"LP0704",AuditGateThresholdExceeded:"LP0705",AuditUnownedBindings:"LP0706",AuditNoBindings:"LP0707",AuditNotAPage:"LP0708"});function bind(t,e){return An(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 An(n.join("."),e)}function An(t,e){if(0===t.length)throw new Error("bind: field name must be a non-empty string");const n={"data-payload-field":t};return void 0!==e?.attribute&&(n["data-payload-attribute"]=e.attribute),void 0!==e?.type&&(n["data-payload-type"]=e.type),!0===e?.richtext&&(n["data-payload-richtext"]=""),!0===e?.html&&(n["data-payload-html"]=""),void 0!==e?.locale&&(n["data-payload-locale"]=e.locale),n}var Tn=Object.freeze({});function createPreviewBindings(t){const{authorized:e}=t,n=void 0!==t.owner&&t.owner.length>0?t.owner:void 0;return Object.freeze({authorized:e,bind:(t,n)=>e?bind(t,n):Tn,bindByPath:(t,n)=>e?bindByPath(t,n):Tn,owner:()=>e&&void 0!==n?{"data-payload-owner":n}:Tn})}for(const[t,e]of[[Mt,"EventEmitter"],[wn,"LivePreviewClient"],[It,"OriginDetector"]])Object.defineProperty(t,"name",{configurable:!0,value:e});var kn=!0;export{kn as CORE_ENTRY,Sn as DIAGNOSTIC_CODES,Mt as EventEmitter,x as LIBRARY_PROTOCOL_VERSION,wn as LivePreviewClient,It as OriginDetector,it as VERSION,bind,bindByPath,buildFrameAncestors,buildScriptSrcWithNonce,createPreviewBindings,detectInitialLocale,escapeHtml,escapeHtmlAttribute,generateCspNonce,hasCapability,initLivePreview,isDevMode,isExternalHttpUrl,isInIframe,isInPopup,isInPreviewContext,isSafeUrl,negotiateProtocol,sanitizeHtml,setCspCrypto,setSanitizerDocument};
|
|
1
|
+
var e="2.0.0-beta.0";function detectInitialLocale(){return function(){if("undefined"==typeof document)return;const e=document.documentElement.getAttribute("lang");return null===e||0===e.length?void 0:e}()??function(){if("undefined"==typeof navigator)return;const e=navigator.language;return"string"==typeof e&&e.length>0?e:void 0}()??"en"}var t="payload-live-preview-a11y",n=/* @__PURE__ */new WeakMap;function r(e){null!==e.timer&&(clearTimeout(e.timer),e.timer=null),e.messageNode?.remove(),e.messageNode=null}var i=class{german;document;lease=null;constructor(e,t){const n=t??("undefined"==typeof document?null:document),r=n?.documentElement.getAttribute("lang")??"";this.german=function(e){return/^de(?:[-_]|$)/i.test(e)}(e??(r.length>0?r:detectInitialLocale())),this.document=n}mount(){const e=this.document;if(null==e?.body)return null;this.lease??=function(e){let t=n.get(e);return void 0===t&&(t={element:null,owned:!1,messageNode:null,refs:0,timer:null},n.set(e,t)),t.refs+=1,t}(e);const i=this.lease,o=i.element;if(o?.isConnected&&o.ownerDocument===e)return o;if(null!==o){const e=i.owned;r(i),e&&o.remove()}let s=e.getElementById(t);return i.owned=null===s,null===s&&(s=e.createElement("div"),s.id=t,s.setAttribute("role","status"),s.setAttribute("aria-live","polite"),s.setAttribute("aria-atomic","true"),s.setAttribute("style","position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);clip-path:inset(50%);white-space:nowrap;border:0"),e.body.appendChild(s)),i.element=s,s}announceConnected(){this.say(this.german?"Vorschau verbunden":"Live preview connected")}announceDisconnected(){this.say(this.german?"Vorschau getrennt":"Live preview disconnected")}announceUpdate(e){e<=0||this.say(this.german?`${String(e)} ${1===e?"Änderung":"Änderungen"} angewendet`:`${String(e)} ${1===e?"change":"changes"} applied`)}detach(){const e=this.lease,t=this.document;if(null===e||null===t)return;if(this.lease=null,e.refs-=1,e.refs>0)return;const i=e.element;null!==i&&r(e),e.owned&&i?.remove(),e.element=null,n.delete(t)}say(e){const t=this.mount(),n=this.lease;if(null===t||null===n)return;let i=n.messageNode;i?.parentNode!==t?(i?.remove(),i=t.ownerDocument.createTextNode(t.hasChildNodes()?` ${e}`:e),n.messageNode=i,t.appendChild(i)):i.data=null===i.previousSibling?e:` ${e}`,null!==n.timer&&clearTimeout(n.timer);const o=setTimeout(()=>{n.timer===o&&n.element===t&&r(n)},1500);n.timer=o}};function o(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){const e=s(n);e&&t.push(e)}return t}function s(e){if("object"!=typeof e||null===e)return;const t=e,n=t.name,r=t.type;if("string"!=typeof n||0===n.length)return;if("string"!=typeof r||0===r.length)return;const i=o(t.fields),s=function(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){if("object"!=typeof n||null===n)continue;const e=n,r=e.slug;if("string"!=typeof r||0===r.length)continue;const i=o(e.fields);t.push({...e,slug:r,fields:i})}return t}(t.blocks),a={...t,name:n,type:r};return i.length>0?a.fields=i:delete a.fields,s.length>0?a.blocks=s:delete a.blocks,a}var a=/* @__PURE__ */new Set(["tabs","row","collapsible"]);function l(e,t=""){const n=/* @__PURE__ */new Map;return c(e,t,n),n}function c(e,t,n){for(const r of e){if(a.has(r.type)){r.fields&&c(r.fields,t,n);continue}const e=""===t?r.name:`${t}.${r.name}`;if(n.set(e,r),"group"===r.type)r.fields&&c(r.fields,e,n);else if("array"===r.type&&r.fields)c(r.fields,`${e}.*`,n);else if("blocks"===r.type&&r.blocks)for(const t of r.blocks)c(t.fields,`${e}.*.${t.slug}`,n)}}function d(e){if("object"!=typeof e||null===e)return;const t=e.id;return"string"==typeof t||"number"==typeof t?t:void 0}function u(e){if("object"!=typeof e||null===e)return;const t=e.blockType;return"string"==typeof t?t:void 0}function h(e,t){return t.every(e=>void 0!==d(e))?function(e,t){const n=[],r=/* @__PURE__ */new Map;for(let t=0;t<e.length;t+=1){const n=d(e[t]);void 0!==n&&r.set(n,t)}const i=/* @__PURE__ */new Set;for(let o=0;o<t.length;o+=1){const s=t[o],a=d(s);if(void 0===a){n.push({kind:"insert",index:o,value:s});continue}const l=r.get(a);if(void 0===l){n.push({kind:"insert",index:o,value:s});continue}i.add(l);const c=e[l];u(c)===u(s)?(l!==o&&n.push({kind:"move",from:l,to:o,value:s}),f(c,s)||n.push({kind:"update",index:o,value:s})):n.push({kind:"replace",index:o,oldValue:c,value:s})}for(let t=0;t<e.length;t+=1)i.has(t)||n.push({kind:"remove",index:t,value:e[t]});return n}(e,t):function(e,t){const n=[],r=Math.min(e.length,t.length);for(let i=0;i<r;i+=1)f(e[i],t[i])||n.push({kind:"update",index:i,value:t[i]});if(t.length>e.length)for(let r=e.length;r<t.length;r+=1)n.push({kind:"insert",index:r,value:t[r]});if(e.length>t.length)for(let r=t.length;r<e.length;r+=1)n.push({kind:"remove",index:r,value:e[r]});return n}(e,t)}function f(e,t){if(Object.is(e,t))return!0;if("object"!=typeof e||"object"!=typeof t||null===e||null===t)return!1;const n=e,r=t,i=Object.keys(n),o=Object.keys(r);if(i.length!==o.length)return!1;for(const e of i)if(!Object.is(n[e],r[e]))return!1;return!0}var p={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"},g=/* @__PURE__ */new Set(["http:","https:","mailto:","tel:"]),m=/^\s*(?:javascript|data|vbscript|file|blob|about)\s*:/i,v=/^(?:\.{1,2}\/|[a-zA-Z0-9_-]+\/?)/,y=/^[\\/]{2}/,b=/[\t\n\r]/g;function isSafeUrl(e){if("string"!=typeof e||0===e.length)return!1;const t=e.trim().replace(b,"");if(0===t.length)return!1;if(m.test(t))return!1;if(t.startsWith("#")||t.startsWith("?"))return!0;if(y.test(t))return!0;if(t.startsWith("/"))return!0;try{const e=new URL(t);return g.has(e.protocol)}catch{return v.test(t)}}function isExternalHttpUrl(e){if(!isSafeUrl(e))return!1;const t=e.trim().replace(b,"");return/^https?:\/\//i.test(t)||y.test(t)}var w=/* @__PURE__ */new Set(["style","srcdoc","formaction","form","id","name","is","srcset","imagesrcset"]),S=/* @__PURE__ */new Set(["href","src","poster","cite","action","xlink:href","data"]),k=/* @__PURE__ */new WeakSet;function A(e){return k.add(e),e}function T(e){switch(typeof e){case"string":return e.length>65536?void 0:`s:${e}`;case"number":return`n:${Object.is(e,-0)?"-0":String(e)}`;case"boolean":return"b:"+(e?"1":"0");case"bigint":return`i:${String(e)}`;case"undefined":return"u";case"object":{if(null===e)return"z";let t;try{t=JSON.stringify(e)}catch{return}return t.length>65536?void 0:`o:${t}`}case"symbol":case"function":return}}var C=class{previous=null;diff(e,t){const n=this.previous,r=/* @__PURE__ */new Map,i=/* @__PURE__ */new Set;for(const[t,o]of Object.entries(e)){const e=T(o);r.set(t,e),null!==n&&void 0!==e&&n.get(t)===e||i.add(t)}if(null!==n)for(const e of n.keys())r.has(e)||i.add(e);this.previous=r;const o=/* @__PURE__ */new Set;for(const[e,n]of Object.entries(t))if(i.has(e))for(const e of n)o.add(e);return{changed:i,invalidated:o}}reset(){this.previous=null}},$=4,R={basic:{since:1},"schema-json":{since:2,observed:"schema"},locale:{since:2,observed:"locale"},"preview-token":{since:3,observed:"preview-token"},"nested-arrays":{since:4},"recursive-diffs":{since:4},"document-events":{since:4,observed:"document-event"},"relationship-events":{since:4,observed:"relationship-event"}},F=Object.keys(R);function negotiateProtocol(e,t=[]){const n="number"==typeof e&&Number.isFinite(e)&&e>=1?Math.floor(e):void 0,r=n??1,i=Math.min(4,r),o=new Set(t),s=/* @__PURE__ */new Set;for(const e of F)(i>=R[e].since||o.has(e))&&s.add(e);return{ours:4,...void 0!==n?{theirs:n}:{theirs:void 0},negotiated:i,capabilities:s,observed:o}}function hasCapability(e,t){return e.capabilities.has(t)}var N=class{negotiation=negotiateProtocol(void 0);observed=/* @__PURE__ */new Set;observe(e,t){const n=e.filter(e=>!this.observed.has(e));if(0!==n.length){for(const e of n)this.observed.add(e);this.negotiation=negotiateProtocol(this.negotiation.theirs,this.observed),t("protocol",`observed=${n.join(",")}`)}}applyVersion(e,t){const n=this.negotiation;if(n.theirs===e)return;const r=negotiateProtocol(e,this.observed);this.negotiation=r,r.negotiated!==n.negotiated&&t("protocol","ours=4",`theirs=${e}`,`negotiated=${r.negotiated}`)}};function x(e){try{return!0===e.matchMedia?.("(prefers-reduced-motion: reduce)").matches}catch{return!1}}var P=class{#e;reveal(e,t,n){return e===this.#e?"skipped-same":(this.#e=e,function(e,t){return function(e,t){const n=e.getBoundingClientRect(),r=n.bottom>0&&n.top<t.innerHeight,i=n.right>0&&n.left<t.innerWidth;return r&&i}(e,t)?"already-visible":(e.scrollIntoView({behavior:x(t)?"auto":"smooth",block:"center"}),"revealed")}(t,n))}reset(){this.#e=void 0}};function L(e,t){return e.generation===t.generation&&e.revision===t.revision}var M=class{started=!1;suspended=!1;deferredStart=null;activeUpdate=null;locale=void 0;schema=void 0;schemaIndex=void 0;updateCount=0;supersededCount=0;completedCount=0;skippedUnchangedCount=0;lastFlush=null;absentFields=/* @__PURE__ */new Set;warnedOrphanFields=/* @__PURE__ */new Set;warnedStrategy=/* @__PURE__ */new WeakSet;warnedUnattributableMessage=!1;warnedVisibilityGate=!1;warnedFragmentFallback=!1;lastAppliedIdentity=/* @__PURE__ */new WeakMap;seenFieldIdentity=/* @__PURE__ */new Map;fragmentStats={rendered:0,failed:0,superseded:0};routeStats={refreshes:0,failed:0,loopStopped:0};fragmentController=null;routeController=null;readyTimers=[];revealer=new P;changes=new C;protocol=new N;isRunning(){return this.started}isCurrent(e){return this.started&&this.activeUpdate===e}complete(e){e.completed||(e.completed=!0,this.completedCount+=1)}abortStrategies(){for(const e of["fragmentController","routeController"]){const t=this[e];null!==t&&(this[e]=null,t.abort())}}},I=class{constructor(e,t){this.deps=e,this.state=t}deps;state;apply(e){const{deps:t,state:n}=this,r=n.activeUpdate;if(null===r||void 0===e.identity||!L(r.identity,e.identity)||!n.isCurrent(r))return!1;const{target:i,value:o}=e,s=void 0!==r.schemaIndex?function(e,t){if(e.has(t))return e.get(t);const n=t.replace(/\.\d+(?=\.|$)/g,".*");return e.has(n)?e.get(n):void 0}(r.schemaIndex,i.fieldName):void 0;let a,l=function(e,t){if(e.explicitFieldType)return e.fieldType;if(void 0!==t){const e=function(e){if(Object.prototype.hasOwnProperty.call(p,e))return p[e]}(t);if(void 0!==e)return e}return e.fieldType}(i,s?.type);"text"===l&&!0!==i.explicitFieldType&&function(e){if("object"!=typeof e||null===e||!("root"in e))return!1;const t=e.root;return"object"==typeof t&&null!==t&&Array.isArray(t.children)}(o)&&(l="richText");try{a=t.resolveRenderer(l,i)}catch(e){return this.fail(r,e)}if(!n.isCurrent(r))return!1;const c=t.emitter.listenerCount("elementUpdate")>0,d=c?"INPUT"===(u=i.element).tagName||"TEXTAREA"===u.tagName?u.value:"IMG"===u.tagName?u.src:u.textContent:void 0;var u;if(!n.isCurrent(r))return!1;const h={allFields:e.allFields,locale:i.locale??r.locale,schema:s,...void 0!==t.renderRichText?{renderRichText:t.renderRichText}:{}};!0===i.boundary&&i.element.toggleAttribute("hidden",function(e){return null==e||("string"==typeof e?0===e.trim().length:Array.isArray(e)&&0===e.length)}(o));try{if(void 0!==i.targetAttribute){if("blocked"===function(e,t,n){const r=t.toLowerCase().trim();if(0===r.length)return"blocked";if(r.startsWith("on"))return"blocked";if(w.has(r))return"blocked";if(null==n)return e.removeAttribute(r),"applied";if("string"!=typeof n&&"number"!=typeof n&&"boolean"!=typeof n)return"blocked";const i=String(n);return S.has(r)&&!isSafeUrl(i)?"blocked":(e.setAttribute(r,i),"applied")}(i.element,i.targetAttribute,o))return t.warn(`[live-preview] LP0401: refused to write "${i.fieldName}" into attribute "${i.targetAttribute}"`),!1}else{if(void 0===a)return t.log("no renderer for",l),!1;{const e=function(e,t,n,r){return e.render(t,n,r)}(a,i,o,h);if(!1===e&&function(e){return k.has(e.render)}(a))return!1}}}catch(e){return this.fail(r,e)}if(!n.isCurrent(r))return!1;c&&t.emitter.emitWhile("elementUpdate",{element:i.element,fieldName:i.fieldName,previousValue:d,nextValue:o,revision:r.identity.revision,receivedAt:r.receivedAt,source:"patch"},()=>n.isCurrent(r));const f=n.isCurrent(r);return f&&(void 0!==e.valueIdentity?n.lastAppliedIdentity.set(i.element,e.valueIdentity):n.lastAppliedIdentity.delete(i.element)),f}fail(e,t){if(!this.state.isCurrent(e))return!1;const n=t instanceof Error?t:new Error(String(t));return this.deps.emitter.emitWhile("error",{error:n,context:"renderer",code:"LP0603"},()=>this.state.isCurrent(e)),!1}};function E(...e){const t=/* @__PURE__ */new Map;for(const n of e)for(const[e,r]of Object.entries(n)){let n=t.get(e);void 0===n&&(n=/* @__PURE__ */new Set,t.set(e,n));for(const e of r)n.add(e)}const n={};for(const[e,r]of t)n[e]=[...r];return n}function U(e,t){const n={};for(const r of t)r!==e&&(n[r]=[e]);return n}var O="payload-live-preview:update",H="data-payload-island",D=`astro-island, [${H}]`;function z(e){return"astro-island"===e.tagName.toLowerCase()||e.hasAttribute(H)}function j(e){return"patch"===e.getAttribute(H)}function isInsideIsland(e){let t=e;for(;null!==t;){if(z(t)&&!j(t))return!0;t=t.parentElement}return!1}function B(e){return e.closest("[data-payload-fragment]")}function W(e){const t=e.getAttribute("data-payload-strategy");return null!==t&&t.length>0?"patch"===t||"fragment"===t||"route"===t?t:void 0:null!==B(e)?"fragment":null!==e.closest("head")?"route":"patch"}var V="data-payload-field",q="data-payload-type",G="data-payload-attribute",_="data-payload-href",K="data-payload-src",J="data-payload-alt",Q="data-payload-array-template",X="data-payload-array-separator",Z="data-payload-locale",Y="data-payload-richtext",ee="data-payload-html",te="data-payload-array",ne="data-payload-structural",re="data-payload-owner",ie="data-payload-depends",oe="data-payload-strategy",se="data-payload-boundary",ae=[V,q,G,_,K,J,Q,X,Z,Y,ee,te,ne,re,ie,oe,se,"type"],le=`[${V}]`,ce=`[${re}]`,de=/^[a-z][a-z0-9-]*:[a-z][a-z0-9-]*$/i,ue=/* @__PURE__ */new Set(["text","textarea","richText","email","number","checkbox","date","select","radio","array","blocks","group","tabs","row","collapsible","relationship","upload","point","json","code","ui","html","url","image","structural-array"]);function he(e){return ue.has(e)||de.test(e)}var fe=class{entriesByField=/* @__PURE__ */new Map;entryByElement=/* @__PURE__ */new WeakMap;filter;count=0;dependencies=null;islandRoots=[];constructor(e={}){this.filter=e.filter??ge}dependencyMap(){if(null!==this.dependencies)return this.dependencies;const e=[];for(const t of this.values())void 0!==t.dependsOn&&e.push(U(t.fieldName,t.dependsOn));return this.dependencies=E(...e),this.dependencies}get islands(){return this.islandRoots}buildFromRoot(e){const t=performance.now();this.clear();let n=0;for(const t of e.querySelectorAll(le))void 0!==this.add(t)&&(n+=1);return this.islandRoots=function(e){const t=[];for(const n of e.querySelectorAll(D))j(n)||t.push(n);return t}(e),{elementCount:n,fieldCount:this.entriesByField.size,durationMs:performance.now()-t}}add(e){const t=this.filter(e)?this.resolveBinding(e):void 0,n=this.entryByElement.get(e);if(this.dependencies=null,void 0!==t)return void 0!==n&&this.replaceEntry(n,t)?(this.entryByElement.set(e,t),t):(void 0!==n&&this.removeEntry(e,n),this.append(t),this.entryByElement.set(e,t),t);void 0!==n&&this.removeEntry(e,n)}remove(e){const t=this.entryByElement.get(e);return!!t&&(this.dependencies=null,this.removeEntry(e,t))}get(e){return this.entriesByField.get(e)}getByElement(e){return this.entryByElement.get(e)}get fieldCount(){return this.entriesByField.size}get elementCount(){return this.count}entries(){return this.entriesByField.entries()}*values(){for(const e of this.entriesByField.values())yield*e}has(e){return this.entryByElement.has(e)}clear(){this.entriesByField.clear(),this.entryByElement=/* @__PURE__ */new WeakMap,this.count=0,this.dependencies=null,this.islandRoots=[]}replaceEntry(e,t){if(e.fieldName!==t.fieldName)return!1;const n=this.entriesByField.get(e.fieldName),r=void 0===n?-1:n.indexOf(e);return!(void 0===n||r<0||(n[r]=t,0))}removeEntry(e,t){this.entryByElement.delete(e);const n=this.entriesByField.get(t.fieldName),r=void 0===n?-1:n.indexOf(t);return!(void 0===n||r<0||(n.splice(r,1),0===n.length&&this.entriesByField.delete(t.fieldName),this.count-=1,0))}append(e){const t=this.entriesByField.get(e.fieldName);t?t.push(e):this.entriesByField.set(e.fieldName,[e]),this.count+=1}resolveBinding(e){const t=e.getAttribute(V);if(null===t||0===t.length)return;const n=e.getAttribute(q),r=e.getAttribute(G),i=e.getAttribute(_),o=e.getAttribute(K),s=e.getAttribute(J),a=e.getAttribute(Q),l=e.getAttribute(X),c=e.getAttribute(Z),d=function(e){const t=e.closest(ce)?.getAttribute(re);return null==t||0===t.length?void 0:t}(e),u=function(e){if(null==e)return[];const t=/* @__PURE__ */new Set,n=[];for(const r of e.split(/[\s,]+/)){const e=r.trim();0===e.length||t.has(e)||(t.add(e),n.push(e))}return n}(e.getAttribute(ie)),h=e.getAttribute(oe),f=B(e);return{element:e,fieldName:t,fieldType:pe(e),explicitFieldType:null!==n&&he(n),strategyKind:W(e)??"unknown",...null!==f?{fragmentBoundary:f}:{},...null!==r&&r.length>0?{targetAttribute:r}:{},...null!==i&&i.length>0?{hrefField:i}:{},...null!==o&&o.length>0?{srcField:o}:{},...null!==s&&s.length>0?{altField:s}:{},...null!==a?{arrayTemplate:a}:{},...null!==l?{arraySeparator:l}:{},...null!==c&&c.length>0?{locale:c}:{},...void 0!==d?{owner:d}:{},...u.length>0?{dependsOn:u}:{},...null!==h&&h.length>0?{strategy:h}:{},...e.hasAttribute(se)?{boundary:!0}:{}}}};function pe(e){const t=e.getAttribute(q);if(null!==t&&he(t))return t;if(e.hasAttribute(Y))return"richText";if(e.hasAttribute(ee))return"html";if(e.hasAttribute(ne))return"structural-array";if(e.hasAttribute(te))return"array";if("IMG"===e.tagName)return"image";if("A"===e.tagName)return"url";if("TIME"===e.tagName)return"date";if("INPUT"===e.tagName){const t=e.type;if("checkbox"===t)return"checkbox";if("number"===t)return"number";if("date"===t||"datetime-local"===t)return"date"}return"text"}function ge(){return!0}function me(e){return("object"==typeof e&&null!==e||"function"==typeof e)&&"function"==typeof e.then&&(Promise.resolve(e).catch(()=>{}),!0)}function ve(e){return(...t)=>{try{me(e(...t))}catch{}}}function ye(){}var be=ve((...e)=>console.error(...e)),we=ve((...e)=>console.warn(...e)),Se=ve((...e)=>console.debug(...e));function ke(e){for(const t of e){const e=t.codePointAt(0);if(void 0!==e&&(e<=31||127===e))return!0}return!1}function Ae(e){if(void 0===e||0===e.length||e.length>128||"."===e||".."===e||e.includes("/")||e.includes("\\")||e.includes("?")||e.includes("#")||ke(e))return!1;try{return encodeURIComponent(e),!0}catch{return!1}}var Te=class{serverURL;apiRoute;depth;fetchFn;log;inflight=null;attempt=0;destroyDepth=0;constructor(e){this.serverURL=e.serverURL.replace(/\/+$/,"");const t=e.apiRoute??"/api";this.apiRoute=t.startsWith("/")?t:`/${t}`,this.depth=e.depth??1,this.fetchFn=e.fetchFn,this.log=void 0===e.log?ye:ve(e.log)}canMerge(e){try{return e.globalSlug?Ae(e.globalSlug):!!Ae(e.collectionSlug)&&function(e){if("number"==typeof e)return Number.isFinite(e);if("string"!=typeof e||0===e.length||e.length>512||"."===e||".."===e||e.includes("/")||e.includes("\\")||ke(e))return!1;try{return encodeURIComponent(e),!0}catch{return!1}}(e.data.id)}catch{return!1}}async merge(e){if(this.destroyDepth>0)return{status:"superseded"};const t=this.attempt+=1,n=this.inflight;this.inflight=null;let r=null;const i=()=>this.attempt!==t;try{if(n?.abort(),i())return{status:"superseded"};if(!this.canMerge(e))return i()?{status:"superseded"}:{status:"unavailable"};const t=this.fetchFn??("function"==typeof fetch?fetch:void 0);if(void 0===t)return{status:"unavailable"};r=new AbortController,this.inflight=r;const o=e.globalSlug?`globals/${encodeURIComponent(e.globalSlug)}`:`${encodeURIComponent(e.collectionSlug??"")}/${encodeURIComponent(String(e.data.id))}`,s=`${this.serverURL}${this.apiRoute}/${o}`,a=await t(s,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json","X-Payload-HTTP-Method-Override":"GET"},body:JSON.stringify({data:e.data,depth:this.depth,flattenLocales:!1,...void 0!==e.locale?{locale:e.locale}:{}}),signal:r.signal});if(i()||Ce(r.signal))return{status:"superseded"};if(!a.ok)return this.log("merge HTTP",a.status,s),{status:"unavailable"};const l=await a.json();return i()||Ce(r.signal)?{status:"superseded"}:null===l||"object"!=typeof l||Array.isArray(l)?(this.log("merge invalid",s),{status:"unavailable"}):{status:"merged",doc:l}}catch(e){return i()||null!==r&&Ce(r.signal)?{status:"superseded"}:(this.log("merge exception",e),{status:"unavailable"})}finally{null===r||i()||this.inflight!==r||(this.inflight=null)}}destroy(){this.attempt+=1;const e=this.inflight;this.inflight=null,this.destroyDepth+=1;try{e?.abort()}finally{this.destroyDepth-=1}}};function Ce(e){return e.aborted}var $e={name:"payload-2",fieldTyping:"schema",populatesRelationships:"admin",documentEvents:!1},Re={name:"payload-3",fieldTyping:"heuristic",populatesRelationships:"server",documentEvents:!0},Fe={name:"unknown",fieldTyping:"heuristic",populatesRelationships:"server",documentEvents:!1};function detectProtocolProfile(e){return e.has("schema-json")?$e:e.has("document-events")||e.has("relationship-events")?Re:Fe}function Ne(e,t){return void 0===e||t(e)}function xe(e,t){return null==e||t(e)}function Pe(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||null===Object.getPrototypeOf(t)}var Le=["data","fieldSchemaJSON","globalSlug","collectionSlug","locale","ready","previewToken","protocolVersion"],Me=class{matcher;handlers;boundListener=void 0;attachedTarget=void 0;generation=0;revision=0;queue=[];queueHead=0;constructor(e,t){this.matcher=e,this.handlers=t}attach(e=window){if(void 0!==this.attachedTarget)return;let t=!1;const n=e=>{if(!t||this.boundListener!==n)return;const r=this.generation;try{this.receive(e,r)}catch{let t;try{t=e.origin}catch{t=""}this.reportInvalid("shape",t,r)}};this.generation+=1,this.resetQueue(),this.attachedTarget=e,this.boundListener=n;try{e.addEventListener("message",n)}catch(t){this.boundListener===n&&(this.attachedTarget=void 0,this.boundListener=void 0,this.resetQueue());try{e.removeEventListener("message",n)}catch{}throw t}if(this.boundListener===n)t=!0;else try{e.removeEventListener("message",n)}catch{}}detach(){const e=this.attachedTarget,t=this.boundListener;void 0!==e&&void 0!==t&&(this.attachedTarget=void 0,this.boundListener=void 0,this.resetQueue(),e.removeEventListener("message",t))}advanceGeneration(){return void 0!==this.attachedTarget&&(this.generation+=1,this.resetQueue(),!0)}static sendReady(e,t){if(0===e.length||0===t.length)return;const n={type:"payload-live-preview",ready:!0,protocolVersion:4};for(const r of e)for(const e of t)try{r.postMessage(n,e)}catch{}}receive(e,t){if(!this.isCurrentGeneration(t))return;const n=e.origin;if(!this.matchesOrigin(n,t))return void this.reportInvalid("origin",n,t);if(!this.matchesSource(e))return void this.reportInvalid("source",n,t);const r=e.data;var i;if("object"==typeof(i=r)&&null!==i&&"type"in i&&"string"==typeof i.type)switch(r.type){case"payload-live-preview":return function(e){const t=e;return!(void 0!==t.data&&null!==t.data&&!Pe(t.data))&&xe(t.fieldSchemaJSON,e=>Array.isArray(e))&&xe(t.globalSlug,e=>"string"==typeof e)&&xe(t.collectionSlug,e=>"string"==typeof e)&&xe(t.locale,e=>"string"==typeof e)&&xe(t.ready,e=>"boolean"==typeof e)&&xe(t.previewToken,e=>"string"==typeof e)&&xe(t.protocolVersion,e=>"number"==typeof e)}(r)?void this.dispatchUpdate(function(e){const t={...e};for(const e of Le)null===Reflect.get(t,e)&&Reflect.deleteProperty(t,e);if(!Array.isArray(t.fieldSchemaJSON))return t;let n;try{n=o(t.fieldSchemaJSON)}catch{n=[]}return{...t,fieldSchemaJSON:n}}(r),n,t):void this.reportInvalid("shape",n,t);case"payload-document-event":return function(e){const t=e;return Ne(t.action,e=>"updated"===e||"created"===e||"deleted"===e)&&Ne(t.slug,e=>"string"==typeof e)&&Ne(t.id,e=>"string"==typeof e||"number"==typeof e&&Number.isFinite(e))}(r)?void this.invokeHandler(t,this.handlers.onDocumentEvent,r,n):void this.reportInvalid("shape",n,t);case"payload-live-preview-focus":{const e=function(e){const t=e.field;return"string"==typeof t&&t.length>0?t:void 0}(r);if(void 0===e)return void this.reportInvalid("shape",n,t);const i=this.handlers.onFocusField;return void(void 0!==i&&this.invokeHandler(t,i,e,n))}default:this.reportInvalid("type",n,t)}else this.reportInvalid("shape",n,t)}dispatchUpdate(e,t,n){const r=Pe(e.data);if(!this.isCurrentGeneration(n))return;const i=r?{generation:n,revision:this.revision+=1}:void 0,o=this.handlers.validateToken;if(!this.isCurrentGeneration(n))return;if(void 0===o)return void this.commitUpdate(e,t,n,i);if(!0===e.ready&&void 0===e.data)return void this.commitUpdate(e,t,n,void 0);const s={generation:n,message:e,origin:t,messageRevision:i,settled:!1,approved:!1};let a;this.queue.push(s);try{a=o(e.previewToken,t)}catch{return void this.settleValidation(s,!1)}"boolean"!=typeof a?Promise.resolve(a).then(e=>{this.settleValidation(s,!0===e)},()=>{this.settleValidation(s,!1)}):this.settleValidation(s,a)}settleValidation(e,t){this.isCurrentGeneration(e.generation)&&(e.approved=t,e.settled=!0,this.drainQueue(e.generation))}drainQueue(e){for(;this.isCurrentGeneration(e);){const t=this.queue[this.queueHead];if(void 0===t)return;if(this.matchesOrigin(t.origin,e)){if(!t.settled)return;this.dequeue(t)&&(t.approved?this.commitUpdate(t.message,t.origin,t.generation,t.messageRevision):this.reportInvalid("token",t.origin,t.generation))}else{if(!this.dequeue(t))continue;this.reportInvalid("origin",t.origin,t.generation)}}}commitUpdate(e,t,n,r){this.isCurrentGeneration(n)&&(void 0===r?this.invokeHandler(n,this.handlers.onUpdate,e,t):this.invokeHandler(n,this.handlers.onUpdate,e,t,r))}reportInvalid(e,t,n){if(!this.isCurrentGeneration(n))return;const r=this.handlers.onInvalid;void 0!==r&&this.invokeHandler(n,r,e,t)}matchesSource(e){if("parent-or-opener"!==this.handlers.sourcePolicy)return!0;const t=this.attachedTarget;if(void 0===t)return!1;try{const n=e.source;if(null===n)return!1;const r=t.parent;if(r!==t&&n===r)return!0;const i=t.opener;return null!=i&&n===i}catch{return!1}}matchesOrigin(e,t){if(!this.isCurrentGeneration(t))return!1;try{return!0===this.matcher(e)&&this.isCurrentGeneration(t)}catch{return!1}}invokeHandler(e,t,...n){if(this.isCurrentGeneration(e))try{me(t(...n))}catch{}}isCurrentGeneration(e){return void 0!==this.attachedTarget&&this.generation===e}dequeue(e){return this.queue[this.queueHead]===e&&(this.queueHead+=1,this.queueHead===this.queue.length?(this.resetQueue(),!0):(this.queueHead>=1024&&2*this.queueHead>=this.queue.length&&(this.queue=this.queue.slice(this.queueHead),this.queueHead=0),!0))}resetQueue(){this.queue=[],this.queueHead=0}},Ie=class{callbacks;debounceMs;rootMargin;visible=/* @__PURE__ */new Set;mutation=null;intersection=null;debounceTimer=null;generation=0;constructor(e,t={}){this.callbacks=e,this.debounceMs=t.mutationDebounceMs??100,this.rootMargin=t.intersectionRootMargin??"200px"}start(e){const t=this.generation;this.stop();const n=t+1;if(this.generation!==n)return;let r=null,i=null;try{r=new MutationObserver(e=>{this.handleMutations(e,n)}),i=new IntersectionObserver(e=>{this.handleIntersection(e,n)},{rootMargin:this.rootMargin,threshold:0}),r.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[...ae]})}catch(e){throw r?.disconnect(),i?.disconnect(),e}if(this.generation!==n)return r.disconnect(),void i.disconnect();this.mutation=r,this.intersection=i}observeElement(e){this.intersection?.observe(e)}unobserveElement(e){this.intersection?.unobserve(e),this.visible.delete(e)}markVisible(e,t){t?this.visible.add(e):this.visible.delete(e)}isVisible(e){return this.visible.has(e)}stop(){this.generation+=1;const e=this.debounceTimer,t=this.mutation,n=this.intersection;this.debounceTimer=null,this.mutation=null,this.intersection=null,this.visible.clear(),null!==e&&clearTimeout(e);try{t?.disconnect()}finally{n?.disconnect()}}handleMutations(e,t){if(!this.isCurrentGeneration(t)||!function(e){for(const t of e){if("attributes"===t.type&&null!==t.attributeName&&ae.includes(t.attributeName)&&(t.attributeName===V||t.attributeName===re||1===t.target.nodeType&&t.target.hasAttribute(V)))return!0;for(const e of t.addedNodes)if(Ee(e))return!0;for(const e of t.removedNodes)if(Ee(e))return!0}return!1}(e))return;null!==this.debounceTimer&&clearTimeout(this.debounceTimer);const n=setTimeout(()=>{this.isCurrentGeneration(t)&&this.debounceTimer===n&&(this.debounceTimer=null,this.callbacks.onStructuralChange())},this.debounceMs);this.debounceTimer=n}handleIntersection(e,t){for(const n of e){if(!this.isCurrentGeneration(t))return;const{target:e}=n;if(n.isIntersecting){if(this.visible.has(e))continue;this.visible.add(e),this.callbacks.onVisibilityChange(e,!0)}else this.visible.has(e)&&(this.visible.delete(e),this.callbacks.onVisibilityChange(e,!1))}}isCurrentGeneration(e){return this.generation===e&&null!==this.intersection}};function Ee(e){if(1!==e.nodeType)return!1;const t=e;return t.hasAttribute(V)||null!==t.querySelector(`[${V}]`)}var Ue=class{timeoutMs;onTimeout;handle=null;lastKick=0;constructor(e){this.timeoutMs=e.timeoutMs??0,this.onTimeout=e.onTimeout}kick(){if(this.lastKick=Date.now(),this.timeoutMs<=0)return;null!==this.handle&&clearTimeout(this.handle);const e=setTimeout(()=>{this.handle===e&&(this.handle=null,this.onTimeout())},this.timeoutMs);this.handle=e}stop(){null!==this.handle&&(clearTimeout(this.handle),this.handle=null)}get lastKickAt(){return this.lastKick}get pending(){return null!==this.handle}},Oe=class{current="disconnected";get status(){return this.current}markConnected(){return this.transition("connected")}markDisconnected(){return this.transition("disconnected")}transition(e){return this.current!==e&&(this.current=e,!0)}};function He(e,t){return void 0===t||""===t?`collection:${e}`:`collection:${e}:${t}`}function De(e){return"string"==typeof e&&e.length>0}function ze(e,t){return null!==t&&void 0!==e&&t.includes(e)}function je(e){const t=e.id;return"string"==typeof t&&t.length>0?t:"number"==typeof t&&Number.isFinite(t)?String(t):void 0}var Be=/* @__PURE__ */new Set(["__proto__","prototype","constructor"]);function We(e,t,n,r=!1){if(r&&void 0!==n){const r=Ve(e,`${t}_${n}`);if(void 0!==r)return r}const i=Ve(e,t);if(void 0!==i)return i;if(t.includes(".")){let n=e,r=!0;for(const e of t.split(".")){if(Be.has(e)||null===n||"object"!=typeof n){r=!1;break}if(n=Ve(n,e),void 0===n){r=!1;break}}if(r)return n}return void 0===n?void 0:Ve(e,`${t}_${n}`)}function Ve(e,t){if(!Be.has(t)&&Object.prototype.hasOwnProperty.call(e,t))return e[t]}var qe,Ge=/* @__PURE__ */new Set(["id","_id","createdAt","updatedAt","createdBy","updatedBy","_status","globalType","collection","locale","localized"]);function _e(e,t,n){const r=e.get(t);return void 0!==r&&(!1===n||r.some(e=>ze(e.owner,n)))}function Ke(e,t){const n=/* @__PURE__ */new Set;for(const[r,i]of e.entries())for(const e of i)(!1===t||ze(e.owner,t))&&void 0!==e.locale&&n.add(`${r}_${e.locale}`);return n}function Je(e){const t=typeof e;return"string"===t||"number"===t||"boolean"===t||"bigint"===t}function Qe(e,t){if(void 0===t||0===t.length)return e;const n=`_${t}`;return e.endsWith(n)?e.slice(0,-n.length):e}function Xe(e){const t=function(){if(void 0!==qe)return qe;const e=function(){const e=globalThis.trustedTypes;if("object"==typeof e&&null!==e)return"function"==typeof e.createPolicy?e:void 0}();if(void 0===e)return qe=null,null;try{qe=e.createPolicy("payload-live-preview",{createHTML:e=>e})}catch{qe=null}return qe}();return null===t?e:t.createHTML(e)}var Ze=/* @__PURE__ */new Set(["open","value","checked","selected"]);function Ye(e,t){for(const n of t.keyAttributes){const t=e.getAttribute(n);if(null!==t&&t.length>0)return`${n}=${t}`}}function et(e){if(e.tagName.toLowerCase().includes("-"))return!0;if(e.hasAttribute(H)||e.hasAttribute("data-payload-owned"))return!0;const t=e.getAttribute("contenteditable");return null!==t&&"false"!==t}function tt(e,t,n){if(!function(e,t){return e.tagName===t.tagName&&e.namespaceURI===t.namespaceURI&&!et(e)&&!et(t)}(e,t))return t;const r=function(e){const t=e.ownerDocument.activeElement;if(!(t instanceof HTMLElement&&e.contains(t)))return null;return{element:t,selection:t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement?[t.selectionStart,t.selectionEnd]:null}}(e);return function(e,t){for(const n of Array.from(e.attributes))t.hasAttribute(n.name)||Ze.has(n.name.toLowerCase())||e.removeAttribute(n.name);for(const n of Array.from(t.attributes))e.getAttribute(n.name)!==n.value&&e.setAttribute(n.name,n.value)}(e,t),!0!==n.retainChildrenOf?.(e,t)&&function(e,t,n){const r=function(e,t){const n=/* @__PURE__ */new Map;let r;for(const i of Array.from(e.children)){const e=Ye(i,t);void 0!==e&&(n.has(e)?r??=e.slice(e.indexOf("=")+1):n.set(e,i))}return void 0!==r&&t.onDuplicateKey?.(e,r),n}(e,n),i=new Set(r.values()),o=Array.from(e.childNodes).filter(e=>!i.has(e)),s=/* @__PURE__ */new Set,a=/* @__PURE__ */new Set,l=Array.from(t.childNodes);let c=e.firstChild,d=0;for(let t=0;t<l.length;t+=1){const i=l[t];let u=null,h=i instanceof Element?Ye(i,n):void 0;if(void 0!==h&&a.has(h)&&(h=void 0),void 0!==h){a.add(h);const e=r.get(h);if(void 0!==e&&!s.has(e)&&(u=nt(e,i,n)===e?e:null,null===u)){e.replaceWith(i),s.add(i),c=i.nextSibling;continue}}else{for(;d<o.length;){const r=o[d];if(d+=1,!s.has(r)){if(it(r,i)){u=nt(r,i,n)===r?r:null,null===u&&(e.replaceChild(i,r),s.add(i),c=i.nextSibling);break}if(r instanceof Element){const n=l[t+1];if(!(i instanceof Element)||void 0!==n&&it(r,n)){d-=1;break}e.replaceChild(i,r),s.add(i),c=i.nextSibling;break}if(!(i instanceof Element)){e.replaceChild(i,r),s.add(i),c=i.nextSibling;break}}}if(null===u&&s.has(i))continue}const f=u??i;for(s.add(f);null!==c&&c!==f&&!s.has(c)&&rt(c);)c=c.nextSibling;f!==c&&e.insertBefore(f,c),c=f.nextSibling}for(const t of Array.from(e.childNodes))s.has(t)||t.remove()}(e,t,n),function(e){if(null===e)return;const{element:t,selection:n}=e;if(t.ownerDocument.activeElement!==t&&t.isConnected)try{t.focus({preventScroll:!0});const[e,r]=n??[null,null];null!==e&&null!==r&&t.setSelectionRange(e,r)}catch{}}(r),e}function nt(e,t,n){return e instanceof Element&&t instanceof Element?et(e)&&et(t)?e:tt(e,t,n):(e.nodeValue!==t.nodeValue&&(e.nodeValue=t.nodeValue),e)}function rt(e){return e.nodeType===Node.TEXT_NODE&&0===(e.nodeValue??"").trim().length}function it(e,t){return e.nodeType===t.nodeType&&(!(e instanceof Element&&t instanceof Element)||e.tagName===t.tagName&&e.namespaceURI===t.namespaceURI)}var ot,st=/* @__PURE__ */new Set(["p","br","strong","b","em","i","u","s","strike","mark","small","h1","h2","h3","h4","h5","h6","ul","ol","li","dl","dt","dd","blockquote","code","pre","kbd","samp","var","a","span","div","section","article","aside","header","footer","nav","figure","figcaption","img","picture","source","audio","video","sub","sup","hr","time","abbr","cite","q","table","thead","tbody","tfoot","tr","th","td","caption","colgroup","col"]),at=/* @__PURE__ */new Set(["input","button","textarea","select","option","label"]),lt=/* @__PURE__ */new Set(["script","style","iframe","object","embed","link","meta","base","form","input","button","select","textarea","svg","math","template","frame","frameset","noframes","noscript"]),ct=/* @__PURE__ */new Set(["id","class","lang","dir","title","role","tabindex"]),dt="aria-",ut="data-",ht={a:/* @__PURE__ */new Set(["href","target","rel","download","hreflang","type"]),img:/* @__PURE__ */new Set(["src","srcset","sizes","alt","width","height","loading","decoding"]),picture:/* @__PURE__ */new Set([]),source:/* @__PURE__ */new Set(["src","srcset","sizes","type","media"]),audio:/* @__PURE__ */new Set(["src","controls","autoplay","loop","muted","preload"]),video:/* @__PURE__ */new Set(["src","poster","controls","autoplay","loop","muted","preload","width","height","playsinline"]),time:/* @__PURE__ */new Set(["datetime"]),abbr:/* @__PURE__ */new Set(["title"]),q:/* @__PURE__ */new Set(["cite"]),blockquote:/* @__PURE__ */new Set(["cite"]),table:/* @__PURE__ */new Set(["summary"]),th:/* @__PURE__ */new Set(["colspan","rowspan","scope","headers","abbr"]),td:/* @__PURE__ */new Set(["colspan","rowspan","headers"]),col:/* @__PURE__ */new Set(["span"]),colgroup:/* @__PURE__ */new Set(["span"]),ol:/* @__PURE__ */new Set(["start","reversed","type"]),li:/* @__PURE__ */new Set(["value"]),code:/* @__PURE__ */new Set(["class"]),pre:/* @__PURE__ */new Set(["class"])},ft=/* @__PURE__ */new Set(["href","src","cite","poster"]),pt=class extends Error{name="SanitizerEnvironmentError"},gt=/* @__PURE__ */new Set(["id","name","data-payload-key","data-payload-nested-key","data-payload-nested-template"]),mt="strict";function setSanitizerDocument(e){ot=e??void 0}function sanitizeHtml(e,t){const n=vt();if(!n)throw"undefined"!=typeof __INLINE_BUILD__&&__INLINE_BUILD__?new Error("sanitizeHtml needs a DOM"):new pt("sanitizeHtml needs a DOM; provide one with setSanitizerDocument() during SSR.");if(""===e)return"";const r=function(e){if(!e){const e=/* @__PURE__ */new Map;for(const[t,n]of Object.entries(ht))e.set(t,n);return{allowedTags:st,attrByTag:e,allowFormControls:!1,templateMode:!1,mode:mt,allowedData:/* @__PURE__ */new Set}}const t=new Set(st);for(const n of e.additionalAllowedTags??[])t.add(n);if(!0===e.allowFormControls)for(const e of at)t.add(e);const n=/* @__PURE__ */new Map;for(const[e,t]of Object.entries(ht))n.set(e,t);for(const[t,r]of Object.entries(e.additionalAllowedAttributes??{})){const e=n.get(t),i=new Set(e??[]);for(const e of r)i.add(e);n.set(t,i)}return{allowedTags:t,attrByTag:n,allowFormControls:!0===e.allowFormControls,templateMode:!0===e.templateMode,mode:e.policy??mt,allowedData:new Set((e.allowedDataAttributes??[]).map(e=>e.toLowerCase()))}}(t),i=n.createElement("template");return i.innerHTML=Xe(e),yt(i.content,r),i.innerHTML}function vt(){return"undefined"!=typeof __INLINE_BUILD__&&__INLINE_BUILD__||!ot?"undefined"!=typeof document?document:void 0:ot}function yt(e,t){for(const n of Array.from(e.childNodes))1===n.nodeType?bt(n,t):8===n.nodeType&&n.remove()}function bt(e,t){const n=e.tagName.toLowerCase();if(!lt.has(n)||t.allowFormControls&&at.has(n)){if(!t.allowedTags.has(n)){yt(e,t);const n=e.parentNode;if(n){for(;e.firstChild;)n.insertBefore(e.firstChild,e);e.remove()}return}!function(e,t,n){const r=n.attrByTag.get(t);for(const t of Array.from(e.attributes)){const i=t.name.toLowerCase();if(i.startsWith("on")||"style"===i)e.removeAttribute(t.name);else{if("strict"===n.mode){if(n.templateMode&>.has(i))continue;if("id"===i||"name"===i||i.startsWith("data-payload-")){e.removeAttribute(t.name);continue}if(i.startsWith(ut)){n.allowedData.has(i)||e.removeAttribute(t.name);continue}if(ct.has(i)||i.startsWith(dt))continue}else if(ct.has(i)||i.startsWith(dt)||i.startsWith(ut))continue;r?.has(i)?ft.has(i)&&!isSafeUrl(t.value)?e.removeAttribute(t.name):"srcset"!==i||wt(t.value)||e.removeAttribute(t.name):e.removeAttribute(t.name)}}}(e,n,t),"a"===n&&function(e){const t=e.getAttribute("href");null!==t&&isExternalHttpUrl(t)&&(e.setAttribute("rel","noopener noreferrer"),e.hasAttribute("target")||e.setAttribute("target","_blank"))}(e),yt(e,t)}else e.remove()}function wt(e){for(const t of e.split(",")){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 St=Object.freeze({"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="}),kt=/[&<>"'/`=]/g;function escapeHtml(e){return""===e?"":e.replace(kt,e=>St[e])}var At=Object.freeze({"&":"&","<":"<",">":">",'"':""","'":"'"}),Tt=/[&<>"']/g;function escapeHtmlAttribute(e){return""===e?"":e.replace(Tt,e=>At[e])}var Ct=/\{\{([\s\S]*?)\}\}/g;function $t(e,t,n,r){const i="object"==typeof t&&null!==t?t:null;return e.replace(Ct,(e,o)=>null!==i&&function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(i,o)?escapeHtml(r(Reflect.get(i,o))):null===i&&"value"===o?escapeHtml(r(t)):"index"===o?String(n):e)}function Rt(e){if(null==e)return"";if("string"==typeof e)return e;if("number"==typeof e||"boolean"==typeof e||"bigint"==typeof e)return String(e);try{return JSON.stringify(e)}catch{return""}}function Ft(e){return null==e||""===e}var Nt=["input","textarea","select","option","button","label","details","summary","dialog","video","audio","progress","meter"],xt=["type","name","placeholder","open","disabled","readonly","required","checked","selected","value","min","max","step","rows","cols","for","controls","muted","loop","poster","src"],Pt=/<([a-z][a-z0-9]*(?:-[a-z0-9]+)+)\b/gi,Lt=/* @__PURE__ */new Map;function Mt(e){const t=Lt.get(e);if(void 0!==t)return t;const n=new Set(Nt);for(const t of e.matchAll(Pt)){const e=t[1]?.toLowerCase();void 0!==e&&n.add(e)}const r={};for(const e of n)r[e]=xt;const i={additionalAllowedTags:[...n],additionalAllowedAttributes:r,allowFormControls:!0,templateMode:!0};return Lt.set(e,i),i}var It="data-payload-key",Et="data-payload-nested-key",Ut="data-payload-nested-template";function Ot(e){const{template:t,container:n,patches:r,nextItems:i,store:o,forceRender:s=!1}=e,a=Dt(n,t,r,i,s,o);return null===a?null:zt(a,o,{morph:e.morph??!0,onDuplicateKey:e.onDuplicateKey})}function Ht(e,t){return t.hasAttribute(Et)&&t.hasAttribute(Ut)}function Dt(e,t,n,r,i,o){const s=function(e,t,n,r,i,o,s){const a=Array.from(e.children),l=_t(a,It),c=/* @__PURE__ */new Set,d=[];for(let u=0;u<n.length;u+=1){const h=n[u],f=Gt(h);let p=void 0===f?a[u]??null:Kt(l,f)??null;null!==p&&c.has(p)&&(p=null),null!==p&&c.add(p);const g=r.replaces.has(u),m=i||r.renders.has(u)||null===p?Jt(e.ownerDocument,t,h,u):void 0;if(null===m)return null;const v=void 0===m?[]:jt(g?null:p,m,h,o,s);if(null===v)return null;d.push([u,p,m??void 0,v,g])}return d}(e,t,r,function(e){const t=/* @__PURE__ */new Set,n=/* @__PURE__ */new Set;for(const r of e)"insert"===r.kind||"update"===r.kind?t.add(r.index):"replace"===r.kind&&(t.add(r.index),n.add(r.index));return{renders:t,replaces:n}}(n),i,o.get(e),o);return null===s?null:[e,s,r]}function zt(e,t,n){const[r,i,o]=e,s=/* @__PURE__ */new Set;let a=!1;for(const[e,o,l,c,d]of i){let i=o;if(void 0!==l){const e=!(!n.morph||d||null===o)&&tt(o,l,{keyAttributes:[It,Et],retainChildrenOf:Ht,...void 0!==n.onDuplicateKey?{onDuplicateKey:n.onDuplicateKey}:{}})===o;if(!e)for(const[e,t]of c)null!==e&&(Wt(e,t),t.replaceWith(e));for(const[,,e]of c)void 0!==e&&zt(e,t,n);e?a=!0:(null!==o&&(o.replaceWith(l),a=!0),i=l)}if(null===i)continue;const u=r.children[e]??null;i!==u&&(r.insertBefore(i,u),a=!0),s.add(i)}for(const e of Array.from(r.children))s.has(e)||(e.remove(),a=!0);const l=function(e,t){let n=t.get(e);return n||(n=/* @__PURE__ */new Map,t.set(e,n)),n}(r,t);l.clear();for(const e of o)qt(l,e);return a}function jt(e,t,n,r,i){const o=_t(null===e?[]:Bt(e),Et),s=Gt(n),a=void 0!==s?r?.get(s):void 0,l=[];for(const e of Bt(t)){const t=e.getAttribute(Et);if(null===t)continue;const r=Kt(o,t)??null,s=e.getAttribute(Ut),c=s?r:null,d=c?.getAttribute(Ut)??null;let u;if(s){const r=Vt(n,t);if(void 0!==r||null!==c){const n=r??[],o=h(null===c?[]:Vt(a,t)??[],n),l=null!==c&&d!==s;if((o.length>0||l)&&(u=Dt(c??e,s,o,n,l,i)??void 0,void 0===u))return null}}l.push([c,e,u])}return l}function Bt(e){return Array.from(e.querySelectorAll(`[${Et}]`)).filter(t=>{let n=t.parentElement;for(;null!==n&&n!==e;){if(n.hasAttribute(Et))return!1;n=n.parentElement}return n===e})}function Wt(e,t){for(const n of Array.from(e.attributes))t.hasAttribute(n.name)||e.removeAttribute(n.name);for(const n of Array.from(t.attributes))e.getAttribute(n.name)!==n.value&&e.setAttribute(n.name,n.value)}function Vt(e,t){if("object"!=typeof e||null===e)return;const n=e[t];return Array.isArray(n)?n:void 0}function qt(e,t){const n=Gt(t);void 0!==n&&e.set(n,t)}function Gt(e){if("object"!=typeof e||null===e)return;const t=e.id;return"string"==typeof t||"number"==typeof t?String(t):void 0}function _t(e,t){const n=/* @__PURE__ */new Map;for(let r=e.length-1;r>=0;r-=1){const i=e[r];if(void 0===i)continue;const o=i.getAttribute(t);if(null===o)continue;const s=n.get(o);void 0===s?n.set(o,[i]):s.push(i)}return n}function Kt(e,t){return e.get(t)?.pop()}function Jt(e,t,n,r){const i=sanitizeHtml($t(t,n,r,Rt),Mt(t)),o=e.createElement("template");o.innerHTML=Xe(i);const s=o.content.firstElementChild;if(!s)return null;const a=Gt(n);return void 0!==a&&s.setAttribute(It,a),s}var Qt=class{constructor(e,t,n){this.deps=e,this.state=t,this.host=n}deps;state;host;planFragments(e){const t=this.deps.strategies.fragment;if(void 0===t)return null;const n=t.plan(this.deps.root,e),r=new Set(n);return{boundaries:n,strategy:t,covers:e=>void 0!==e.fragmentBoundary&&r.has(e.fragmentBoundary)}}hasRouteBinding(e){for(const[t,n]of this.deps.cache.entries())if(e.has(t)&&n.some(e=>"route"===e.strategyKind))return!0;return!1}async runFragments(e,t,n){const{deps:r,state:i}=this,o=new AbortController;i.fragmentController=o;const s=()=>i.isCurrent(e)&&!o.signal.aborted,{emitter:a}=r,{message:l}=e,c=e.identity.revision,d=e.receivedAt,u={root:r.root,revision:c,receivedAt:d,fields:t.fields,locale:e.locale,collectionSlug:"string"==typeof l.collectionSlug?l.collectionSlug:void 0,globalSlug:"string"==typeof l.globalSlug?l.globalSlug:void 0,signal:o.signal,isCurrent:s,log:(e,t)=>{r.log("fragment",e,t)},morph:(e,t)=>{!function(e,t){const n=e.ownerDocument.createElement("template");n.innerHTML=Xe(t);const r=e.cloneNode(!1);r.append(n.content),tt(e,r,{keyAttributes:[It]})}(e,t)},patch:n=>{this.patchFallback(e,t,n)},rendered:(t,n,r)=>{e.pendingFragments-=1,a.emitWhile("fragmentRender",{element:t,id:n,key:r,status:"rendered",revision:c,receivedAt:d},s)},failed:(t,n,r,i,o)=>{e.pendingFragments-=1,a.emitWhile("error",{error:new Error(`fragment "${n}" fell back to patch: ${o}`),context:"fragment",code:i},s),a.emitWhile("fragmentRender",{element:t,id:n,key:r,status:"failed",code:i,revision:c,receivedAt:d},s)}};let h={rendered:0,failed:0,superseded:0};try{h=await n.strategy.render(u,n.boundaries)}catch(i){if(r.log("fragment","LP0801",i),s()){for(const r of n.boundaries)this.patchFallback(e,t,r);h={rendered:0,failed:n.boundaries.length,superseded:0}}}i.fragmentStats.rendered+=h.rendered,i.fragmentStats.failed+=h.failed,i.fragmentStats.superseded+=h.superseded,s()&&(i.fragmentController===o&&(i.fragmentController=null),e.pendingFragments=0,0===r.scheduler.pendingCount&&i.complete(e),this.host.revealPending(e),s()&&0!==h.rendered&&0!==a.listenerCount("afterUpdate")&&a.emitWhile("afterUpdate",{data:t,updatedCount:h.rendered,durationMs:Date.now()-d,revision:c,receivedAt:d,source:"fragment"},s))}async refreshRoute(e,t,n){const{deps:r,state:i}=this,o=i.routeStats;if(e.routeRefreshed)return o.loopStopped+=1,void r.log("route","LP0805",`revision ${String(e.identity.revision)} asked for a second refresh`);e.routeRefreshed=!0;const s=new AbortController;i.routeController=s;const a=()=>i.isCurrent(e)&&!s.signal.aborted;let l;try{l=await n.refresh({revision:e.identity.revision,receivedAt:e.receivedAt,signal:s.signal,isCurrent:a,log:(e,t)=>{r.log("route",e,t)}})}catch(e){r.log("route","LP0801",e),l="failed"}if(a()){if(i.routeController===s&&(i.routeController=null),"refreshed"===l){if(o.refreshes+=1,i.lastAppliedIdentity=/* @__PURE__ */new WeakMap,this.host.rebuildCache(),!a())return;return this.host.reapply(e,t),void(r.emitter.listenerCount("afterUpdate")>0&&r.emitter.emitWhile("afterUpdate",{data:t,updatedCount:r.cache.elementCount,durationMs:Date.now()-e.receivedAt,revision:e.identity.revision,receivedAt:e.receivedAt,source:"route"},a))}"failed"===l&&(o.failed+=1),this.host.reapply(e,t)}}warnFragmentFallback(e){this.state.warnedFragmentFallback||(this.state.warnedFragmentFallback=!0,this.deps.warn(`[live-preview] LP0806: "${e.fieldName}" asks for the fragment strategy but no handler is configured; patching instead`))}warnUnsupportedStrategy(e){this.state.warnedStrategy.has(e.element)||(this.state.warnedStrategy.add(e.element),this.deps.warn(`[live-preview] LP0407: "${e.fieldName}" asks for strategy "${String(e.strategy)}"; only patch, fragment and route exist`))}patchFallback(e,t,n){for(const[r,i]of this.deps.cache.entries())for(const o of i){if(o.fragmentBoundary!==n)continue;const i=We(t.fields,r,o.locale??e.locale,void 0!==o.locale);void 0!==i&&this.deps.scheduler.schedule({target:o,value:this.host.transform(o,i,t.fields,()=>!0),allFields:t.fields,identity:e.identity,data:t})}}},Xt=class{constructor(e,t,n){this.deps=e,this.state=t,this.strategies=new Qt(e,t,{reapply:(e,t)=>{this.scheduleAllFields(e,t)},transform:(e,t,n,r)=>this.transformForBinding(e,t,n,r),rebuildCache:n,revealPending:e=>{this.revealPending(e)}})}deps;state;strategies;handleUpdate(e,t,n){const{deps:r,state:i}=this;if(r.heartbeat.kick(),i.protocol.observe(function(e){const t=[];return Array.isArray(e.fieldSchemaJSON)&&t.push("schema-json"),"string"==typeof e.locale&&t.push("locale"),"string"==typeof e.previewToken&&t.push("preview-token"),"object"==typeof e.externallyUpdatedRelationship&&null!==e.externallyUpdatedRelationship&&t.push("relationship-events"),t}(e),r.log),void 0===e.data)return void(void 0!==e.protocolVersion&&i.protocol.applyVersion(e.protocolVersion,r.log));if(void 0===n)return;const o=e.externallyUpdatedRelationship,s="object"==typeof o&&null!==o;s&&r.emitter.emit("relationshipUpdate",{detail:o,timestamp:Date.now()}),"string"==typeof e.locale&&(i.locale=e.locale),Array.isArray(e.fieldSchemaJSON)&&(i.schema=e.fieldSchemaJSON,i.schemaIndex=l(e.fieldSchemaJSON));const a={identity:n,message:e,locale:i.locale,schema:i.schema,schemaIndex:i.schemaIndex,receivedAt:Date.now(),forceRender:s,touched:/* @__PURE__ */new Set,invalidated:/* @__PURE__ */new Set,revealTarget:void 0,revealIdentities:[],pendingFragments:0,routeRefreshed:!1,cancelled:!1,completed:!1},c=i.activeUpdate;if(i.abortStrategies(),null===c||c.completed||(i.supersededCount+=1),i.activeUpdate=a,r.scheduler.acceptRevision(n),i.updateCount+=1,void 0===e.protocolVersion||(i.protocol.applyVersion(e.protocolVersion,r.log),i.isCurrent(a))){if(r.connection.markConnected()){if(r.a11y?.announceConnected(),r.emitter.emit("connect",{origin:t,timestamp:Date.now()}),!i.isCurrent(a))return;if(r.log("connection","disconnected","→","connected"),!i.isCurrent(a))return}this.processUpdate(a).catch(e=>{r.log("update failed:",e)})}}async processUpdate(e){const{deps:t,state:n}=this,r=await this.resolveIncomingFields(e);if(null===r||!n.isCurrent(e))return;const{message:i}=e,o={fields:r,...void 0!==e.schema?{schema:e.schema}:{},..."string"==typeof i.globalSlug?{globalSlug:i.globalSlug}:{},..."string"==typeof i.collectionSlug?{collectionSlug:i.collectionSlug}:{},...void 0!==e.locale?{locale:e.locale}:{}};if(t.emitter.listenerCount("beforeUpdate")>0&&(!await t.emitter.emitWhile("beforeUpdate",{data:o,revision:e.identity.revision,receivedAt:e.receivedAt,source:"patch",cancel:()=>{e.cancelled=!0,t.scheduler.cancelRevision(e.identity)}},()=>!e.cancelled&&n.isCurrent(e))||e.cancelled||!n.isCurrent(e)))return;const s=E(t.dependencies,t.cache.dependencyMap()),a=n.changes.diff(r,s);e.invalidated=a.invalidated,e.touched=/* @__PURE__ */new Set([...a.changed,...a.invalidated]),this.scheduleAllFields(e,o)}async resolveIncomingFields(e){const{deps:t,state:n}=this,r=e.message.data??{};if(null===t.merger)return r;if("admin"===detectProtocolProfile(n.protocol.observed).populatesRelationships)return r;const{message:i}=e,o=await t.merger.merge({collectionSlug:i.collectionSlug,globalSlug:i.globalSlug,data:r,locale:e.locale});return n.isCurrent(e)?"merged"===o.status?o.doc:"superseded"===o.status?null:r:null}scheduleAllFields(e,t){const{deps:n,state:r}=this;if(!r.isCurrent(e))return;const i=()=>r.isCurrent(e),o=this.ownerKeysForUpdate(e,t.fields),{touched:s}=e,a=n.strategies.route;if(void 0!==a&&!e.routeRefreshed&&(a.plan(n.root,s)||this.strategies.hasRouteBinding(s)))return void this.strategies.refreshRoute(e,t,a);const l=this.strategies.planFragments(s),c=n.skipUnchanged;let d=0;for(const[s,a]of n.cache.entries()){if(!i())return;for(const u of a){if(!1!==o&&!ze(u.owner,o))continue;if(!0===l?.covers(u)){n.revealEditedField&&this.noteRevealCandidate(e,u,this.rawValue(e,u,t));continue}const a=u.strategyKind??W(u.element)??"unknown";if("unknown"===a){this.strategies.warnUnsupportedStrategy(u);continue}"fragment"===a&&null===l&&this.strategies.warnFragmentFallback(u);const h=We(t.fields,s,u.locale??e.locale,void 0!==u.locale);if(void 0===h){r.absentFields.add(s);continue}if(this.noteRevealCandidate(e,u,h),!i())return;const f=this.transformForBinding(u,h,t.fields,i);if(!i())return;const p=c?Zt(u,f,t.fields,e.locale):void 0,g=r.lastAppliedIdentity.get(u.element);if(!e.forceRender&&n.skipUnchanged&&void 0!==p&&g===p&&!e.invalidated.has(s)){r.skippedUnchangedCount+=1;continue}const m={target:u,value:f,allFields:t.fields,identity:e.identity,data:t,valueIdentity:p};n.scheduler.schedule(m),d+=1}}(function(e,t,n,r){const{cache:i,warned:o,warn:s}=e;if(0===i.fieldCount)return;if(!1!==r&&!function(e,t){for(const n of e.values())if(ze(n.owner,t))return!0;return!1}(i,r))return;let a;for(const[e,l]of Object.entries(t)){if(o.has(e)||Ge.has(e))continue;if(!Je(l))continue;const t=Qe(e,n);_e(i,e,r)||t!==e&&_e(i,t,r)||(a??=Ke(i,r),a.has(e)||(o.add(e),s(`[live-preview] LP0201: no <… data-payload-field="${t}"> for field "${e}"; render the anchor unconditionally so edits to an empty field have somewhere to land.`)))}})({cache:n.cache,warned:r.warnedOrphanFields,warn:n.warn},t.fields,e.locale,o),null!==l&&l.boundaries.length>0&&(e.pendingFragments=l.boundaries.length,this.strategies.runFragments(e,t,l)),0===d&&0===e.pendingFragments&&(r.complete(e),this.revealPending(e))}rawValue(e,t,n){return We(n.fields,t.fieldName,t.locale??e.locale,void 0!==t.locale)}noteRevealCandidate(e,t,n){const{deps:r,state:i}=this;if(!r.revealEditedField)return;const o=T(n);if(void 0===o)return;const s=`${t.owner??""}\0${t.locale??""}\0${t.fieldName}`,a=i.seenFieldIdentity.get(s);void 0!==a?a!==o&&(e.revealIdentities.push([s,o]),e.revealTarget??=t):i.seenFieldIdentity.set(s,o)}ownerKeysForUpdate(e,t){const{deps:n,state:r}=this;if(!n.scopeBindingsByOwner)return!1;const{message:i}=e,o=function(e){if(De(e.globalSlug))return[(t=e.globalSlug,`global:${t}`)];var t;if(!De(e.collectionSlug))return null;const n=He(e.collectionSlug);return De(e.documentId)?[n,He(e.collectionSlug,e.documentId)]:[n]}({globalSlug:"string"==typeof i.globalSlug?i.globalSlug:void 0,collectionSlug:"string"==typeof i.collectionSlug?i.collectionSlug:void 0,documentId:je(t)});return null!==o||r.warnedUnattributableMessage||(r.warnedUnattributableMessage=!0,n.warn("[live-preview] LP0202: scopeBindingsByOwner: update names no document; nothing applied")),o}transformForBinding(e,t,n,r){const i=this.deps.transformValue;if(void 0===i)return t;try{const o=i(e.fieldName,t,{element:e.element,allFields:n},r),s=me(o);if(!r())return t;if(s)throw new TypeError(`Transform for "${e.fieldName}" returned a thenable; transforms must be synchronous`);return o}catch(e){if(!r())return t;const n=e instanceof Error?e:new Error(String(e));return this.deps.emitter.emit("error",{error:n,context:"transform",code:"LP0602"}),t}}onFlush(e){const{deps:t,state:n}=this;n.lastFlush=e,e.deferred>0&&!n.warnedVisibilityGate&&(n.warnedVisibilityGate=!0,t.warn(`[live-preview] LP0301: visibility gate held ${String(e.deferred)} off-screen update(s) until scrolled into view; see visibilityGateThreshold`));const{identity:r,data:i}=e;if(void 0===r)return;const o=n.activeUpdate;if(null===o||!n.isCurrent(o)||!L(o.identity,r))return;0===o.pendingFragments&&n.complete(o);const s=()=>n.isCurrent(o)&&L(o.identity,r);this.revealPending(o),s()&&0!==e.applied&&void 0!==i&&(t.a11y?.announceUpdate(e.applied),s()&&(function(e,t){for(const n of e)n.dispatchEvent(new CustomEvent(O,{detail:t,bubbles:!1}));e.length}(t.cache.islands,{fields:i.fields,revision:r.revision,receivedAt:o.receivedAt,locale:o.locale}),s()&&0!==t.emitter.listenerCount("afterUpdate")&&t.emitter.emitWhile("afterUpdate",{data:i,updatedCount:e.applied,durationMs:e.durationMs,revision:r.revision,receivedAt:o.receivedAt,source:"patch"},s)))}revealPending(e){for(const[t,n]of e.revealIdentities)this.state.seenFieldIdentity.set(t,n);e.revealIdentities=[];const t=e.revealTarget;if(void 0!==t){e.revealTarget=void 0;try{this.revealBinding(t)}catch(e){this.deps.log("reveal",e)}}}revealField(e){const t=this.deps.cache.get(e)?.[0];return void 0===t?"no-element":this.revealBinding(t)}revealBinding(e){const{element:t}=e,n=t.ownerDocument.defaultView;if(null===n)return"no-element";const r=`${e.owner??""} ${e.fieldName}`;return this.state.revealer.reveal(r,t,n)}};function Zt(e,t,n,r){const i=T(t);if(void 0===i)return;const o=[e.hrefField,e.srcField,e.altField];let s=i;for(const t of o){if(void 0===t||0===t.length)continue;const i=T(We(n,t,e.locale??r,void 0!==e.locale));if(void 0===i)return;s+=`|${t}=${i}`}return s}var Yt=class{apply;debounceMs;maxWaitMs;isVisible;gateThresholdValue;gateDisabled;getCacheSize;onFlush;scheduleFrame;cancelFrame;pending=/* @__PURE__ */new Map;replay=/* @__PURE__ */new Map;activeFlushes=/* @__PURE__ */new Set;debounceTimer=null;debounceToken=0;deadlineTimer=null;frameHandle=null;frameToken=0;activeIdentity=null;activeRevisionCancelled=!1;constructor(e,t){this.apply=e,this.debounceMs=t.debounceMs??50,this.maxWaitMs=t.maxWaitMs??4*this.debounceMs,this.isVisible=t.isVisible,this.gateThresholdValue=t.visibilityGateThreshold??50,this.gateDisabled=t.disableVisibilityGate??!1,this.getCacheSize=t.getCacheSize,this.onFlush=t.onFlush,this.scheduleFrame=t.scheduleFrame??("function"==typeof requestAnimationFrame?requestAnimationFrame.bind(globalThis):e=>setTimeout(()=>{e(performance.now())},0)),this.cancelFrame=t.cancelFrame??("function"==typeof cancelAnimationFrame?cancelAnimationFrame.bind(globalThis):e=>{clearTimeout(e)})}schedule(e){if(void 0!==e.identity){if(this.activeRevisionCancelled)return;if(!en(e.identity,this.activeIdentity))return}const t=this.pending.get(e.target.element);t?(t.value=e.value,t.allFields=e.allFields,t.identity=e.identity,t.data=e.data,t.valueIdentity=e.valueIdentity):this.pending.set(e.target.element,{target:e.target,value:e.value,allFields:e.allFields,identity:e.identity,data:e.data,valueIdentity:e.valueIdentity}),this.armDebounce()}acceptRevision(e){var t,n;en(e,this.activeIdentity)||null!==this.activeIdentity&&(t=e,n=this.activeIdentity,(t.generation!==n.generation?t.generation-n.generation:t.revision-n.revision)<0)||(this.cancelScheduledWork(),this.clearWork(),this.activeIdentity=e,this.activeRevisionCancelled=!1)}cancelRevision(e){en(e,this.activeIdentity)&&(this.cancelScheduledWork(),this.clearWork(),this.activeRevisionCancelled=!0)}flushNow(){return this.cancelScheduledWork(),this.flush()}notifyVisible(e){const t=this.replay.get(e);if(!t)return;if(this.replay.delete(e),!this.isCurrent(t))return;const n=performance.now(),r=this.didApply(t)?1:0;this.onFlush?.(this.statsFor(t,r,0,performance.now()-n,1===r?[t.target.fieldName]:[]))}retarget(e){this.retargetBuffer(this.pending,e),this.retargetBuffer(this.replay,e);for(const t of this.activeFlushes)this.retargetBuffer(t,e)}forget(e){this.pending.delete(e),this.replay.delete(e);for(const t of this.activeFlushes)t.delete(e)}destroy(){this.cancelScheduledWork(),this.clearWork(),this.activeIdentity=null,this.activeRevisionCancelled=!1}get pendingCount(){return this.pending.size}get replayCount(){return this.replay.size}get gateThreshold(){return this.gateThresholdValue}get gateActive(){return!this.gateDisabled&&this.getCacheSize()>this.gateThresholdValue}armDebounce(){const e=this.debounceToken+=1,t=this.debounceTimer;if(this.debounceTimer=null,null!==t&&clearTimeout(t),this.debounceToken!==e)return;const n=setTimeout(()=>{this.debounceToken===e&&(this.debounceTimer=null,this.requestFrame())},this.debounceMs);this.debounceToken===e&&(this.debounceTimer=n),null===this.deadlineTimer&&this.maxWaitMs>this.debounceMs&&(this.deadlineTimer=setTimeout(()=>{this.deadlineTimer=null,this.pending.size>0&&this.requestFrame()},this.maxWaitMs))}requestFrame(){const e=this.frameToken+=1,t=this.frameHandle;if(this.frameHandle=null,null!==t&&this.cancelFrame(t),this.frameToken!==e)return;let n=!1;const r=this.scheduleFrame(()=>{this.frameToken===e&&(n=!0,this.frameHandle=null,this.flush())});n||this.frameToken!==e||(this.frameHandle=r)}flush(){const e=performance.now();this.clearDeadline();const t=this.gateActive,n=this.pending;this.pending=/* @__PURE__ */new Map;let r=0;const i=[];let o,s=0;this.activeFlushes.add(n);try{for(const e of n.values()){if(!this.isCurrent(e))continue;const n=!t||this.isVisible(e.target.element);this.isCurrent(e)&&(o??=e,n?(this.replay.delete(e.target.element),this.didApply(e)&&(r+=1,i.push(e.target.fieldName))):(this.replay.set(e.target.element,e),s+=1))}}finally{this.activeFlushes.delete(n)}const a=this.statsFor(o,r,s,performance.now()-e,i);return this.onFlush?.(a),a}isCurrent(e){return void 0===e.identity||!this.activeRevisionCancelled&&en(e.identity,this.activeIdentity)}didApply(e){return!1!==this.apply(e)||(t=this.apply,!k.has(t));var t}retargetBuffer(e,t){const n=e.get(t.element);void 0!==n&&(n.target.fieldName===t.fieldName&&n.target.locale===t.locale?n.target=t:e.delete(t.element))}clearWork(){this.pending.clear(),this.replay.clear();for(const e of this.activeFlushes)e.clear()}statsFor(e,t,n,r,i){return{applied:t,appliedFields:i,deferred:n,durationMs:r,...void 0!==e?.identity?{identity:e.identity}:{},...void 0!==e?.data?{data:e.data}:{}}}clearDeadline(){null!==this.deadlineTimer&&(clearTimeout(this.deadlineTimer),this.deadlineTimer=null)}cancelScheduledWork(){const e=this.debounceTimer,t=this.frameHandle;this.debounceToken+=1,this.frameToken+=1,this.debounceTimer=null,this.frameHandle=null,this.clearDeadline(),null!==e&&clearTimeout(e),null!==t&&this.cancelFrame(t)}};function en(e,t){return null!==t&&e.generation===t.generation&&e.revision===t.revision}var tn=[0,500,1e3,2e3],nn=class{deps;state=new M;pipeline;writer;rootSentinel=null;observedRoot=null;constructor(e){const{emitter:t,renderers:n}=e,r=void 0===e.log?ye:ve(e.log),i=void 0===e.warn?we:ve(e.warn),o=e.root??("undefined"!=typeof document?document:null),s=new fe({filter:e=>!isInsideIsland(e)}),a=new Ie({onStructuralChange:()=>{this.rebuildCache()},onVisibilityChange:(e,t)=>{t&&l.notifyVisible(e)}},void 0!==e.intersectionRootMargin?{intersectionRootMargin:e.intersectionRootMargin}:{}),l=new Yt(A(e=>this.writer.apply(e)),{...void 0!==e.debounceMs?{debounceMs:e.debounceMs}:{},...void 0!==e.disableVisibilityGate?{disableVisibilityGate:e.disableVisibilityGate}:{},...void 0!==e.visibilityGateThreshold?{visibilityGateThreshold:e.visibilityGateThreshold}:{},isVisible:e=>a.isVisible(e),getCacheSize:()=>s.elementCount,onFlush:e=>{this.pipeline.onFlush(e)}}),c=new Me(e.originMatcher,{onUpdate:(e,t,n)=>{this.pipeline.handleUpdate(e,t,n)},onDocumentEvent:()=>{this.state.protocol.observe(["document-events"],r),t.emit("documentSave",{timestamp:Date.now()})},onFocusField:e=>{this.deps.revealEditedField&&this.pipeline.revealField(e)},onInvalid:(e,n)=>{if("token"===e){const e=new Error(`Preview token rejected (origin: ${n})`);t.emit("error",{error:e,context:"token",code:"LP0502"})}r("LP0501 message rejected:",e,n)},...void 0!==e.validateToken?{validateToken:e.validateToken}:{},...void 0!==e.eventSourcePolicy?{sourcePolicy:e.eventSourcePolicy}:{}}),d=e.dataMerge;this.deps={emitter:t,cache:s,observers:a,scheduler:l,bus:c,connection:new Oe,heartbeat:new Ue({...void 0!==e.heartbeatMs?{timeoutMs:e.heartbeatMs}:{},onTimeout:()=>{this.onHeartbeatTimeout()}}),renderers:n,resolveRenderer:e.resolveRenderer??(e=>n[e]),transformValue:e.transformValue,renderRichText:e.renderRichText,root:o,readyTargets:"function"==typeof e.readyTargets?e.readyTargets:/* @__PURE__ */(e=>()=>e)(e.readyTargets),sendReady:e.sendReady??an,onHeartbeatTimeout:e.onHeartbeatTimeout,log:r,warn:i,a11y:rn(e),merger:void 0===d?null:new Te({serverURL:d.serverURL,...void 0!==d.apiRoute?{apiRoute:d.apiRoute}:{},...void 0!==d.depth?{depth:d.depth}:{},...void 0!==d.fetchFn?{fetchFn:d.fetchFn}:{},log:r}),scopeBindingsByOwner:!0===e.scopeBindingsByOwner,lockedOrigin:e.lockedOrigin??(()=>{}),skipUnchanged:!0===e.skipUnchanged,dependencies:e.dependencies??{},strategies:e.strategies??{},revealEditedField:!0===e.revealEditedField},this.writer=new I(this.deps,this.state),this.pipeline=new Xt(this.deps,this.state,()=>{this.rebuildCache()})}start(){const{state:e,deps:t}=this;if(e.isRunning())return!1;if(e.started=!0,e.suspended=!1,on(t.root)&&"loading"===t.root.readyState){const n=()=>{if(e.isRunning()){e.deferredStart=null;try{this.startNow()}catch(e){this.rollbackFailedStart(),this.reportError(e,"startup","LP0605")}}};e.deferredStart=n;try{t.root.addEventListener("DOMContentLoaded",n,{once:!0})}catch(e){throw this.rollbackFailedStart(),e}return!0}try{return this.startNow(),!0}catch(e){throw this.rollbackFailedStart(),e}}startNow(){const{state:e,deps:t}=this;if(!e.isRunning())return;const n=on(t.root)?sn(t.root):t.root;if(null===n)throw new Error("LivePreviewRuntime: document.body unavailable");if(t.observers.start(n),this.observedRoot=n,this.watchRootReplacement(),this.buildCacheAndObserve(),e.isRunning()&&(t.bus.attach(),t.emitter.emitWhile("init",{timestamp:Date.now()},()=>e.isRunning()),e.isRunning()))for(const n of tn){if(!e.isRunning())return;0===n?t.sendReady(t.readyTargets()):e.readyTimers.push(setTimeout(()=>{e.isRunning()&&this.sendReadyAfterStart()},n))}}suspend(){if(!this.state.isRunning())return!1;const e=this.release();return this.state.suspended=!0,e&&this.deps.emitter.emit("disconnect",{reason:"unload",timestamp:Date.now()}),!0}destroy(){const{state:e,deps:t}=this;if(!e.isRunning()&&!e.suspended)return;const n=!!e.isRunning()&&this.release();e.suspended=!1,n&&t.emitter.emit("disconnect",{reason:"destroy",timestamp:Date.now()}),t.a11y?.detach(),t.emitter.emit("destroy",{timestamp:Date.now()})}release(){const{state:e,deps:t}=this;e.activeUpdate=null,e.started=!1;const n=e.deferredStart;e.deferredStart=null,null!==n&&on(t.root)&&this.runCleanup(()=>{t.root.removeEventListener("DOMContentLoaded",n)});for(const t of e.readyTimers)this.runCleanup(()=>{clearTimeout(t)});return e.readyTimers.length=0,this.runCleanup(()=>{t.heartbeat.stop()}),this.runCleanup(()=>{t.bus.detach()}),e.abortStrategies(),this.runCleanup(()=>{this.rootSentinel?.disconnect(),this.rootSentinel=null,this.observedRoot=null}),this.runCleanup(()=>{t.observers.stop()}),this.runCleanup(()=>{t.scheduler.destroy()}),this.runCleanup(()=>{t.merger?.destroy()}),t.cache.clear(),t.connection.markDisconnected()}rollbackFailedStart(){this.release(),this.runCleanup(()=>{this.deps.a11y?.detach()})}runCleanup(e){try{e()}catch(e){this.deps.log("cleanup failed:",e)}}refreshCache(){this.state.isRunning()&&(this.state.revealer.reset(),this.followReplacedRoot()||this.rebuildCache())}watchRootReplacement(){const{root:e}=this.deps;on(e)&&"undefined"!=typeof MutationObserver&&(this.rootSentinel?.disconnect(),this.rootSentinel=new MutationObserver(()=>{this.followReplacedRoot()}),this.rootSentinel.observe(e.documentElement,{childList:!0}))}followReplacedRoot(){const{root:e}=this.deps;if(!this.state.isRunning()||!on(e))return!1;const t=sn(e);return null!==t&&t!==this.observedRoot&&(this.observedRoot=t,this.deps.observers.start(t),this.rebuildCache(),!0)}get status(){return this.deps.connection.status}get cache(){return this.deps.cache}get updateCount(){return this.state.updateCount}get protocol(){return this.state.protocol.negotiation}inspect(){return function(t,n){const{cache:r,scheduler:i}=t,o=n.protocol.negotiation,s=n.activeUpdate,a=n.lastFlush,l=[],c=/* @__PURE__ */new Set;for(const[e,t]of r.entries()){l.push(e);for(const e of t)void 0!==e.owner&&c.add(e.owner)}return{version:e,started:n.started,status:t.connection.status,origins:{trusted:[...t.readyTargets()],locked:t.lockedOrigin()},protocol:{ours:o.ours,theirs:o.theirs,negotiated:o.negotiated,capabilities:[...o.capabilities].sort(),observed:[...o.observed].sort(),profile:detectProtocolProfile(o.observed).name},revisions:{accepted:n.updateCount,superseded:n.supersededCount,completed:n.completedCount,skippedUnchanged:n.skippedUnchangedCount,active:null===s?void 0:s.identity.revision},bindings:{elements:r.elementCount,fields:r.fieldCount,fieldNames:l.sort(),absentFields:[...n.absentFields].sort(),orphanFields:[...n.warnedOrphanFields].sort(),ownerScoped:t.scopeBindingsByOwner,owners:[...c].sort()},route:{handler:void 0!==t.strategies.route,...n.routeStats},fragments:{handler:void 0!==t.strategies.fragment,inFlight:s?.pendingFragments??0,...n.fragmentStats},scheduler:{pending:i.pendingCount,deferred:i.replayCount,visibilityGateThreshold:i.gateThreshold,visibilityGateActive:i.gateActive,lastFlush:null===a?void 0:{applied:a.applied,appliedFields:a.appliedFields,deferred:a.deferred,durationMs:a.durationMs}},plugins:[],renderers:Object.keys(t.renderers).sort()}}(this.deps,this.state)}buildCacheAndObserve(){const{state:e,deps:t}=this;if(!e.isRunning())return;const n=t.cache.buildFromRoot(t.root);if(t.log("cache",n),e.isRunning()&&(t.emitter.emitWhile("cacheRefresh",n,()=>e.isRunning()),e.isRunning()))for(const n of t.cache.values()){if(!e.isRunning())return;t.observers.observeElement(n.element)}}rebuildCache(){const{state:e,deps:t}=this;if(!e.isRunning())return;const n=/* @__PURE__ */new Map;for(const e of t.cache.values())n.set(e.element,e),t.observers.unobserveElement(e.element);if(this.buildCacheAndObserve(),e.isRunning()){for(const e of t.cache.values()){const r=n.get(e.element);r?.fieldName===e.fieldName?t.scheduler.retarget(e):t.scheduler.forget(e.element),n.delete(e.element)}for(const e of n.values())t.scheduler.forget(e.element)}}onHeartbeatTimeout(){const{state:e,deps:t}=this;if(!e.isRunning())return;t.bus.advanceGeneration();const n=e.activeUpdate;e.activeUpdate=null,null!==n&&t.scheduler.cancelRevision(n.identity),t.merger?.destroy();const r=t.connection.markDisconnected();try{t.onHeartbeatTimeout?.()}catch(e){t.log("heartbeat:",e)}if(e.isRunning()){if(r&&this.isIdleDisconnected()){if(t.a11y?.announceDisconnected(),t.emitter.emitWhile("disconnect",{reason:"timeout",timestamp:Date.now()},()=>this.isIdleDisconnected()),!e.isRunning())return;if(this.isIdleDisconnected()&&t.log("connection","connected","→","disconnected"),!e.isRunning())return}this.sendReadyAfterStart()}}sendReadyAfterStart(){try{this.deps.sendReady(this.deps.readyTargets())}catch(e){this.reportError(e,"ready","LP0606")}}reportError(e,t,n){const r=e instanceof Error?e:new Error(String(e));this.deps.emitter.emit("error",{error:r,context:t,code:n})}isIdleDisconnected(){return this.state.isRunning()&&"disconnected"===this.deps.connection.status&&null===this.state.activeUpdate}};function rn(e){if(!1===e.enableA11y)return null;const t=e.root,n=void 0===t?void 0:on(t)?t:t.ownerDocument;return new i(e.a11yLocale,n)}function on(e){return 9===e.nodeType}function sn(e){return e.body}function an(e){if("undefined"==typeof window)return;const t=[];window.parent!==window&&t.push(window.parent),window.opener instanceof Window&&t.push(window.opener),Me.sendReady(t,e)}var EventEmitter=class{#t=/* @__PURE__ */new Map;#n=/* @__PURE__ */new Map;on(e,t){return this.#r(this.#t,e,t)}once(e,t){return this.#r(this.#n,e,t)}off(e,t){this.#i(this.#t,e,t),this.#i(this.#n,e,t)}async emit(e,t){await this.#o(e,t)}async emitWhile(e,t,n){return this.#o(e,t,n)}async#o(e,t,n){const r=()=>n?.()??!0;if(!r())return!1;const i=this.#t.get(e);if(i)for(const n of[...i]){if(!r())return!1;if(await this.#s(n,t,e),!r())return!1}if(!r())return!1;const o=this.#n.get(e);if(o&&o.size>0){const n=[...o];this.#n.delete(e);for(const i of n){if(!r())return!1;if(await this.#s(i,t,e),!r())return!1}}return r()}listenerCount(e){return(this.#t.get(e)?.size??0)+(this.#n.get(e)?.size??0)}removeAllListeners(e){if(void 0===e)return this.#t.clear(),void this.#n.clear();this.#t.delete(e),this.#n.delete(e)}eventNames(){const e=/* @__PURE__ */new Set;for(const t of this.#t.keys())e.add(t);for(const t of this.#n.keys())e.add(t);return[...e]}#r(e,t,n){let r=e.get(t);return r||(r=/* @__PURE__ */new Set,e.set(t,r)),r.add(n),()=>{this.#i(e,t,n)}}#i(e,t,n){const r=e.get(t);void 0!==r&&(r.delete(n),0===r.size&&e.delete(t))}async#s(e,t,n){try{await e(t)}catch(e){const t="string"==typeof n||"number"==typeof n?String(n):"<event>";be(`[live-preview] LP0601: handler for "${t}" threw:`,e)}}};function isInIframe(){if("undefined"==typeof window)return!1;try{return window.self!==window.top}catch{return!0}}function isInPopup(){return"undefined"!=typeof window&&null!=window.opener}function isInPreviewContext(){return isInIframe()||isInPopup()}function isDevMode(){const e=function(){if("undefined"==typeof process)return;const e=process.env.NODE_ENV;return"string"==typeof e?e:void 0}();if(void 0!==e)return"production"!==e;if("undefined"!=typeof window){const e=window.location.hostname;return"localhost"===e||"127.0.0.1"===e}return!1}var ln=/^https?:\/\/(localhost|127\.0\.0\.1)(?::\d+)?$/i,cn=/^https?:\/\/[^/?#\s]+$/i,dn=[3e3,3001,3333,4e3,4321,5e3,5173,5174,8e3,8080,8888,9e3],OriginDetector=class{#a;constructor(e={}){const t=/* @__PURE__ */new Set;for(const n of e.additionalOrigins??[]){const e=un(n);void 0!==e&&t.add(e)}let n;if(e.enableReferrerDetection??1){const t=e.referrer??("undefined"!=typeof document?document.referrer:"");if(t.length>0)try{const e=new URL(t).origin;e&&"null"!==e&&(n=e)}catch{}}const r=(e.enableLocalhostMatching??!0)&&(e.forceDevMode??isDevMode());this.#a=[t,n,r,void 0!==n,void 0]}matches(e){return 0!==e.length&&"null"!==e&&(void 0!==this.#a[4]?e===this.#a[4]:!!this.#a[0].has(e)||0===this.#a[0].size&&void 0!==this.#a[1]&&e===this.#a[1]||!(!this.#a[2]||!ln.test(e)))}lockOrigin(e){return!!this.matches(e)&&(this.#a[4]=e,!0)}unlockOrigin(){const e=this.#a[4];return this.#a[4]=void 0,e}get lockedOrigin(){return this.#a[4]}enumerate(){if(void 0!==this.#a[4])return[this.#a[4]];const e=new Set(this.#a[0]);if(0===this.#a[0].size&&void 0!==this.#a[1]&&e.add(this.#a[1]),this.#a[2])for(const t of dn)e.add(`http://localhost:${String(t)}`),e.add(`http://127.0.0.1:${String(t)}`);return[...e]}get referrerWasAvailable(){return this.#a[3]}get isProductionUnconfigured(){return!(!isInIframe()||this.#a[0].size>0||this.#a[2]||void 0!==this.#a[1])}get isReferrerOnlyTrust(){return!(this.#a[0].size>0||this.#a[2]||void 0===this.#a[1])}};function un(e){const t=e.trim();if(0!==t.length)try{const e=new URL(t);if("http:"!==e.protocol&&"https:"!==e.protocol)return;if(!cn.test(e.origin))return;return e.origin}catch{return}}var hn=()=>{},fn=class{#l;#c;#d=/* @__PURE__ */new Set;#a="staging";constructor(e,t){this.#l=e,this.#c=t}assertOpen(){if("closed"===this.#a)throw new Error(`Plugin context for "${this.#l}" is no longer active`)}get active(){return"active"===this.#a}eligible(){return"closed"!==this.#a}own(e){return this.assertOpen(),this.#u({kind:"cleanup",acquire:void 0,finalize:void 0,cleanup:e,disposed:!1})}stage(e,t,n){this.assertOpen();const r={kind:e,acquire:t,finalize:n,cleanup:void 0,disposed:!1},i=this.#u(r);if("active"===this.#a)try{this.#h(r)}catch(e){throw this.#f(r),e}return i}counts(){const e={transform:0,renderer:0,subscription:0,cleanup:0};for(const t of this.#d)e[t.kind]+=1;return e}commit(){if("staging"!==this.#a)throw new Error(`Plugin context for "${this.#l}" cannot be committed`);this.#a="committing";try{for(const e of this.#d)this.#h(e);this.#a="active"}catch(e){throw this.close(),e}}close(){if("closed"!==this.#a){this.#a="closed";for(const e of[...this.#d].reverse())this.#f(e);this.#d.clear()}}#u(e){return this.#d.add(e),()=>{this.#f(e)}}#h(e){if(e.disposed||void 0!==e.cleanup||void 0===e.acquire)return;const t=e.acquire();e.cleanup=t??hn}#f(e){if(e.disposed)return;e.disposed=!0,this.#d.delete(e);const t=e.cleanup;if(e.cleanup=void 0,void 0!==t)try{me(t())&&this.#c(`plugin "${this.#l}" cleanup returned a Promise/thenable; cleanups must be synchronous`)}catch(e){this.#c(`plugin "${this.#l}" cleanup failed:`,e)}try{e.finalize?.()}catch(e){this.#c(`plugin "${this.#l}" cleanup failed:`,e)}}},pn=class{#p;#g;#m=/* @__PURE__ */new Set;constructor(e,t){this.#p=e,this.#g=t}on(e,t){return this.#v("on",e,t)}once(e,t){return this.#v("once",e,t)}off(e,t){const n=t;for(const t of[...this.#m])t.event===e&&t.handler===n&&t.dispose()}emit(e,t){return this.#g.assertOpen(),this.#p.emit(e,t)}emitWhile(e,t,n){return this.#g.assertOpen(),this.#p.emitWhile(e,t,()=>{if(!this.#g.eligible())return!1;const e=n();return!!this.#g.eligible()&&e})}listenerCount(e){let t=0;for(const n of this.#m)n.event===e&&(t+=1);return t}removeAllListeners(e){for(const t of[...this.#m])void 0!==e&&t.event!==e||t.dispose()}eventNames(){const e=/* @__PURE__ */new Set;for(const t of this.#m)e.add(t.event);return[...e]}#v(e,t,n){this.#g.assertOpen();const r=n,i=[...this.#m].find(n=>n.kind===e&&n.event===t&&n.handler===r);if(void 0!==i)return i.dispose;let o=hn,s=!0;const a=async t=>{this.#g.active&&s&&("once"===e&&o(),await n(t))},l={kind:e,event:t,handler:r,dispose:hn};return o=this.#g.stage("subscription",()=>this.#p[e](t,a),()=>{s=!1,this.#m.delete(l)}),l.dispose=o,this.#m.add(l),o}},gn=class{#p;#y;#b;#w;#c;#S=/* @__PURE__ */new Map;#k=/* @__PURE__ */new Map;#A=/* @__PURE__ */new Map;#T=/* @__PURE__ */new Set;#C=/* @__PURE__ */new Map;#$=Promise.resolve();#R=0;constructor(e){this.#p=e.events,this.#y=e.config,this.#b=e.registerFieldRenderer,this.#c=ve(e.log);const t=e.onTransformError;this.#w=void 0===t?void 0:ve((...e)=>{const n=e[0];try{return t(n)}catch(e){return void this.#c("transform error reporter failed:",e)}})}register(e){return this.#R>0?this.#F(e,!1):this.#N(()=>this.#F(e,!0))}unregister(e){return this.#R>0?this.#x(e,!1):this.#N(async()=>{await this.#x(e,!0)})}destroyAll(){return this.#R>0?this.#P(!1):this.#N(async()=>{await this.#P(!0)})}applyTransforms(e,t,n,r){const i=this.#C.get(e);if(void 0===i||0===i.length)return t;let o=t;for(const s of[...i]){if(!s.active)continue;const{transform:i}=s;if(!1===r?.())return t;try{o=i(o,{fieldName:e,element:n.element,allFields:n.allFields});const s=me(o);if(!1===r?.())return t;if(s)throw new TypeError(`Transform for "${e}" returned a Promise/thenable; transforms must be synchronous`)}catch(n){if(!1===r?.())return t;const i=n instanceof Error?n:new Error(String(n));return this.#c(`transform for "${e}" failed:`,i),this.#w?.(i),t}}return o}list(){return[...this.#S.keys()]}snapshot(){const e=[],t=(e,t,n,r)=>{const i=r.counts();return{name:e,version:t,state:n,registrations:{transforms:i.transform,renderers:i.renderer,subscriptions:i.subscription,cleanups:i.cleanup}}};for(const[n,r]of this.#k)e.push(t(n,void 0,"initializing",r.scope));for(const[n,r]of this.#S)e.push(t(n,r.plugin.version,"active",r.scope));for(const t of this.#A.keys())e.push({name:t,version:void 0,state:"tearing-down",registrations:{transforms:0,renderers:0,subscriptions:0,cleanups:0}});return e}get size(){return this.#S.size}async#F(t,n){if(this.#S.has(t.name)||this.#k.has(t.name)||this.#A.has(t.name))return void this.#c(`plugin "${t.name}" already registered`);const r=function(e,t){if(void 0!==e){if(void 0!==e.runtime&&!function(e,t){const n=function(e){const t=/^v?(\d+)\.(\d+)\.(\d+)/.exec(e.trim());if(null!==t)return[Number(t[1]),Number(t[2]),Number(t[3])]}(e);return void 0!==n&&t.split("||").some(e=>{const r=e.trim().split(/\s+/).filter(e=>e.length>0);return 0===r.length?""===e.trim()&&""===t.trim():r.every(e=>function(e,t){const n=t.trim();if(""===n||"*"===n)return!0;const r=/^(\^|~|>=|<=|>|<|=)?\s*v?(\d+)\.(\d+)\.(\d+)/.exec(n);if(null===r)return!1;const i=r[1]??"=",o=[Number(r[2]),Number(r[3]),Number(r[4])],s=function(e,t){for(let n=0;n<3;n+=1){const r=(e[n]??0)-(t[n]??0);if(0!==r)return r}return 0}(e,o);switch(i){case"=":return 0===s;case">":return s>0;case">=":return s>=0;case"<":return s<0;case"<=":return s<=0;case"~":return s>=0&&e[0]===o[0]&&e[1]===o[1];case"^":return!(s<0)&&(o[0]>0?e[0]===o[0]:o[1]>0?0===e[0]&&e[1]===o[1]:0===e[0]&&0===e[1]&&e[2]===o[2]);default:return!1}}(n,e))})}(t,e.runtime))return`declares runtime ${e.runtime}, this runtime is ${t}`;if(void 0!==e.protocol){if(!Number.isInteger(e.protocol)||e.protocol<1)return`declares an invalid protocol version ${String(e.protocol)}`;if(e.protocol<4)return`declares protocol ${String(e.protocol)}, this runtime speaks ${String(4)}`}}}(t.compat,e);if(void 0!==r)return void this.#L(t.name,r);const i=new fn(t.name,this.#c),o=this.#M(t.name,i),s={scope:i,cancelled:!1};this.#k.set(t.name,s);try{if(await this.#I(()=>t.init(o),n),s.cancelled)return;i.commit()}catch(e){return i.close(),void(s.cancelled||this.#c(`plugin "${t.name}" init failed:`,e))}finally{this.#k.get(t.name)===s&&this.#k.delete(t.name)}this.#S.set(t.name,{plugin:t,scope:i}),this.#c(`plugin "${t.name}" registered`)}#L(e,t){const n=`plugin "${e}" refused: ${t}`;this.#c(n),this.#p.emit("error",{error:new Error(n),context:"plugin",code:"LP0103"})}#M(e,t){return{events:new pn(this.#p,t),registerFieldRenderer:e=>{t.stage("renderer",()=>{const t=this.#b(e);return"function"==typeof t?t:void 0})},registerTransform:(e,n)=>{const r={transform:n,active:!1};t.stage("transform",()=>{r.active=!0;const t=this.#C.get(e);return void 0===t?this.#C.set(e,[r]):t.push(r),()=>{r.active=!1;const t=this.#C.get(e);if(void 0===t)return;const n=t.indexOf(r);n>=0&&t.splice(n,1),0===t.length&&this.#C.delete(e)}})},registerCleanup:e=>{t.own(e)},getConfig:()=>this.#y,log:(...t)=>{this.#c(`[${e}]`,...t)}}}#x(e,t){const n=this.#k.get(e);if(void 0!==n)return n.cancelled=!0,n.scope.close(),Promise.resolve();const r=this.#A.get(e);if(void 0!==r)return this.#T.has(e)?Promise.resolve():t?this.#E(r):r;const i=this.#S.get(e);if(void 0===i)return Promise.resolve();this.#S.delete(e),i.scope.close();const o=Promise.resolve().then(()=>this.#U(e,i.plugin,t));return this.#A.set(e,o),o.then(()=>{this.#A.get(e)===o&&this.#A.delete(e)}),o}async#U(e,t,n){if(void 0!==t.destroy){this.#T.add(e);try{await this.#I(()=>t.destroy?.(),n)}catch(t){this.#c(`plugin "${e}" destroy failed:`,t)}finally{this.#T.delete(e)}}}async#P(e){for(const e of this.#k.values())e.cancelled=!0,e.scope.close();const t=[...this.#S.keys()];for(const n of t)await this.#x(n,e)}async#I(e,t){t?await this.#E(Promise.resolve().then(e)):await e()}async#E(e){this.#R+=1;try{await e}finally{this.#R-=1}}#N(e){const t=this.#$.then(e);return this.#$=t.catch(e=>{this.#c("plugin manager mutation failed:",e)}),t}},mn=class{#O;#H;#D=/* @__PURE__ */new Map;constructor(e){this.#O=e,this.#H={...e}}get renderers(){return this.#H}resolve(e){return this.#H[e]}register(e){const t=e.name,n={renderer:e},r=this.#D.get(t);void 0===r?this.#D.set(t,[n]):r.push(n),this.#H[t]=e;let i=!0;return()=>{if(!i)return;i=!1;const e=this.#D.get(t);if(void 0===e)return;const r=e.indexOf(n);if(r<0)return;const o=r===e.length-1;if(e.splice(r,1),0===e.length&&this.#D.delete(t),!o)return;const s=e.at(-1),a=s?.renderer??this.#O[t];void 0===a?Reflect.deleteProperty(this.#H,t):this.#H[t]=a}}},vn={1:"left",2:"center",3:"right",4:"justify"},yn=/* @__PURE__ */new Set(["left","center","right","justify","start","end"]);function bn(e){const t=e.format;return"string"==typeof t&&yn.has(t)?t:"number"==typeof t?vn[t]:void 0}function wn(e){const t=e.indent;return"number"==typeof t&&t>0?t:0}function Sn(e){return"rtl"===e.direction?' dir="rtl"':"ltr"===e.direction?' dir="ltr"':""}function kn(e){const t=bn(e),n=wn(e),r=[];return void 0!==t&&r.push(`lp-align-${t}`),n>0&&r.push(`lp-indent-${String(n)}`),0===r.length?"":` class="${r.join(" ")}"`}var An=/* @__PURE__ */new Set(["h1","h2","h3","h4","h5","h6"]);function Tn(e){return"object"==typeof e&&null!==e?e:void 0}function Cn(e){return Tn(e)}function $n(e){return e.replace(/[^a-zA-Z0-9_-]/g,"-").toLowerCase()}function Rn(e){return"string"==typeof e&&e.length>0?e:void 0}function Fn(e){const t=Rn(e.title)??Rn(e.name)??Rn(e.slug);return void 0!==t?t:void 0===e.id?void 0:String(e.id)}var Nn=' target="_blank" rel="noopener noreferrer"',xn=(e,t)=>{const n=t.renderChildren(e.children??[]),r=Tn(e.fields),i=function(e,t){if("internal"===t?.linkType)return function(e){const t=Tn(Tn(e)?.value),n=t?.url;if("string"==typeof n&&n.length>0)return n;const r=t?.slug;return"string"==typeof r&&r.length>0?`/${r}`:void 0}(t.doc);const n=t?.url??e.url;return"string"==typeof n&&n.length>0?n:void 0}(e,r);if(void 0===i||!isSafeUrl(i))return n;const o="string"==typeof e.title?` title="${escapeHtml(e.title)}"`:"";return`<a href="${escapeHtmlAttribute(i)}"${function(e,t,n){if(!0===t?.newTab||isExternalHttpUrl(n))return Nn;const r="string"==typeof e.target?e.target:"";return""===r?"":"_blank"===r?Nn:` target="${escapeHtml(r)}"`}(e,r,i)}${o}>${n}</a>`};function Pn(e){if("string"==typeof e.text)return e.text;if(!e.children)return"";let t="";for(const n of e.children)t+=Pn(n);return t}function Ln(e){return`${"number"==typeof e.width?` width="${String(e.width)}"`:""}${"number"==typeof e.height?` height="${String(e.height)}"`:""}`}function Mn(e){return"string"==typeof e.mimeType?` type="${escapeHtmlAttribute(e.mimeType)}"`:""}var In=/* @__PURE__ */new Map;function En(e){return In.get(e)}function Un(e,t,n,r){const i=Tn(e.fields)??{},o="string"==typeof i.blockType?i.blockType:"",s=$n(o);if(""!==o){const e=En(o)??En(s);if(e)return e(i,{renderChildren:t.renderChildren})}return`<${n} class="${""===s?r:`${r} ${r}--${s}`}"></${n}>`}function On(e,t){return"number"==typeof t&&t>1?` ${e}="${String(t)}"`:""}var Hn={text:e=>{let t=escapeHtml("string"==typeof e.text?e.text:"");const n="number"==typeof e.format?e.format:0;return!!(16&n)&&(t=`<code>${t}</code>`),!!(1&n)&&(t=`<strong>${t}</strong>`),!!(2&n)&&(t=`<em>${t}</em>`),!!(8&n)&&(t=`<u>${t}</u>`),!!(4&n)&&(t=`<s>${t}</s>`),!!(32&n)&&(t=`<sub>${t}</sub>`),!!(64&n)&&(t=`<sup>${t}</sup>`),!!(128&n)&&(t=`<mark>${t}</mark>`),t},paragraph:(e,t)=>{const n=t.renderChildren(e.children??[]);return`<p${Sn(e)}${kn(e)}>${n}</p>`},heading:(e,t)=>{const n="string"==typeof e.tag?e.tag.toLowerCase():"h2",r=An.has(n)?n:"h2",i=t.renderChildren(e.children??[]);return`<${r}${Sn(e)}${kn(e)}>${i}</${r}>`},list:(e,t)=>{const n="string"==typeof e.listType?e.listType:"bullet",r="number"===n?"ol":"ul",i="number"===n&&"number"==typeof e.start&&e.start>1?` start="${String(e.start)}"`:"",o="check"===n?' role="list"':"",s=t.renderChildren(e.children??[]);return`<${r}${Sn(e)}${kn(e)}${i}${o}>${s}</${r}>`},listitem:(e,t)=>{const n=t.renderChildren(e.children??[]);if("boolean"==typeof e.checked)return`<li role="checkbox" aria-checked="${e.checked?"true":"false"}"${kn(e)}>${n}</li>`;const r="number"==typeof e.value?` value="${escapeHtml(String(e.value))}"`:"";return`<li${Sn(e)}${kn(e)}${r}>${n}</li>`},link:xn,autolink:xn,quote:(e,t)=>{const n=t.renderChildren(e.children??[]);return`<blockquote${Sn(e)}${kn(e)}>${n}</blockquote>`},code:e=>{const t=$n("string"==typeof e.language?e.language:"");return`<pre><code${""===t?"":` class="language-${t}"`}>${escapeHtml(Pn(e))}</code></pre>`},"code-highlight":e=>{const t="string"==typeof e.text?e.text:"";return`<span${"string"==typeof e.highlightType?` class="token-${$n(e.highlightType)}"`:""}>${escapeHtml(t)}</span>`},linebreak:()=>"<br>",horizontalrule:()=>"<hr>",tab:()=>"\t",upload:e=>{const t=Cn(e.value);if(void 0===t)return"";const n=t.url;if("string"!=typeof n||!isSafeUrl(n))return"";const r="string"==typeof t.mimeType?t.mimeType:"";return r.startsWith("video/")?function(e,t){return`<video controls${Ln(e)}><source src="${escapeHtmlAttribute(t)}"${Mn(e)}></video>`}(t,n):r.startsWith("audio/")?function(e,t){return`<audio controls><source src="${escapeHtmlAttribute(t)}"${Mn(e)}></audio>`}(t,n):""===r||r.startsWith("image/")?function(e,t){const n="string"==typeof e.alt?escapeHtml(e.alt):"";return`<img src="${escapeHtmlAttribute(t)}" alt="${n}"${Ln(e)} loading="lazy" decoding="async">`}(t,n):function(e,t){const n="string"==typeof e.filename?escapeHtml(e.filename):escapeHtml(t);return`<a href="${escapeHtmlAttribute(t)}" target="_blank" rel="noopener noreferrer">${n}</a>`}(t,n)},relationship:e=>{const t="string"==typeof e.relationTo?e.relationTo:"",n=Tn(e.value),r=escapeHtml((n&&Fn(n))??`#${t}`),i=$n(t),o=""===i?' class="lp-relation"':` class="lp-relation lp-relation--${i}"`,s=n?.url;return"string"==typeof s&&isSafeUrl(s)?`<a href="${escapeHtmlAttribute(s)}"${o}>${r}</a>`:`<span${o}>${r}</span>`},block:(e,t)=>Un(e,t,"div","lp-block"),inlineBlock:(e,t)=>Un(e,t,"span","lp-inline-block"),table:(e,t)=>`<table${Sn(e)}><tbody>${t.renderChildren(e.children??[])}</tbody></table>`,tablerow:(e,t)=>`<tr>${t.renderChildren(e.children??[])}</tr>`,tablecell:(e,t)=>{const n="number"==typeof e.headerState?e.headerState:0,r=3&n?"th":"td";return`<${r}${1===n?' scope="col"':2===n?' scope="row"':""}${On("colspan",e.colSpan)}${On("rowspan",e.rowSpan)}>${t.renderChildren(e.children??[])}</${r}>`}},Dn=/* @__PURE__ */new Map,zn={renderChildren:Wn,resolveAlignment:bn,resolveIndent:wn},jn=!1;function Bn(e){if("object"!=typeof e||null===e)return!1;if(!("root"in e))return!1;const t=e.root;return"object"==typeof t&&null!==t&&"children"in t&&Array.isArray(t.children)}function Wn(e){let t="";for(const n of e)t+=Vn(n);return t}function Vn(e){const t=(n=e.type,Dn.get(n)??Hn[n]);var n;return t?t(e,zn):void 0!==e.children?Wn(e.children):""}function qn(e){if("string"==typeof e.text)return e.text;if("linebreak"===e.type)return"\n";if(void 0===e.children)return"";let t="";for(const n of e.children)t+=qn(n);return t}function Gn(e="text"){const t=/* @__PURE__ */new WeakSet;return{name:e,render:/* @__PURE__ */A((e,n)=>{const r=e.element,i=function(e){return null==e?"":Bn(e)?Bn(t=e)?t.root.children.map(qn).join("\n").trim():"":"string"==typeof e?e:"number"==typeof e||"boolean"==typeof e?String(e):JSON.stringify(e);var t}(n);if("INPUT"!==r.tagName&&"TEXTAREA"!==r.tagName)return function(e){return null!==e.querySelector(":scope > :not(br)")}(r)&&!r.hasAttribute("data-payload-text")?(function(e,t,n){e.has(t)||(e.add(t),we(`[live-preview] LP0402: Skipping text update for "${n}": <${t.tagName.toLowerCase()}> has structured children. Move data-payload-field to the value element, or add data-payload-text to replace them.`))}(t,r,e.fieldName),!1):void(i.includes("\n")||i.includes("\r")?r.innerHTML=Xe(function(e){return escapeHtml(e).replace(/\r\n|\r|\n/g,"<br>")}(i)):r.textContent=i);r.value=i})}}var _n={name:"richText",render:/* @__PURE__ */A((e,t,n)=>{const r=e.element;if(Ft(t))r.textContent="";else{if(void 0!==n.renderRichText){const i=n.renderRichText(t,{fieldName:e.fieldName,element:r,locale:n.locale});return void(r.innerHTML=Xe(sanitizeHtml(i)))}if(Bn(t))r.innerHTML=Xe(function(e,t={}){if(!Bn(e))return"";const n=Wn(e.root.children);return!1===t.sanitize?n:void 0!==vt()?sanitizeHtml(n):(function(){if(!jn){jn=!0;try{console.warn("[live-preview] lexicalToHtml() has no sanitizer document and returned unsanitised HTML; call setSanitizerDocument() (linkedom/jsdom) for server rendering, see docs/security.md §3.")}catch{}}}(),n)}(t));else{if("string"!=typeof t)return!1;r.innerHTML=Xe(sanitizeHtml(t))}}})},Kn={name:"html",render(e,t){if(Ft(t))return void(e.element.textContent="");const n="string"==typeof t?t:Rt(t);e.element.innerHTML=Xe(sanitizeHtml(n))}},Jn=/* @__PURE__ */new WeakSet;function Qn(e,t,n){return"string"!=typeof n||0===n.length?{kind:"none"}:isSafeUrl(n)?{kind:"safe",url:n}:(Jn.has(e)||(Jn.add(e),we(`[live-preview] LP0401: refused an unsafe URL for "${t}" on <${e.tagName.toLowerCase()}>; the attribute was cleared.`)),{kind:"unsafe"})}function Xn(e,t=e=>e){return{name:e,render(e,n,r){const i=e.element;if(Ft(n))return void function(e){"INPUT"!==e.tagName&&"TEXTAREA"!==e.tagName?(e.removeAttribute("href"),e.textContent=""):e.value=""}(i);const o=Rt(n);if("INPUT"!==i.tagName&&"TEXTAREA"!==i.tagName){if("A"===i.tagName){const n=e.hrefField,s=void 0===n||0===n.length?t(o):We(r.allFields,n,r.locale,void 0!==e.locale),a=Qn(i,e.fieldName,s);"safe"===a.kind?i.setAttribute("href",a.url):"unsafe"===a.kind&&i.removeAttribute("href")}i.textContent=o}else i.value=o}}}var Zn=Xn("url"),Yn=/^[a-zA-Z][a-zA-Z0-9+.-]*:/,er=Xn("email",function(e){const t=e.trim();return Yn.test(t)||!t.includes("@")?t:`mailto:${t}`}),tr=["src","srcset","sizes"];function nr(e){for(const t of tr)e.removeAttribute(t)}function rr(e,t,n){e.src=t;const r=function(e){if(void 0===e?.sizes)return;const t=[];for(const n of Object.values(e.sizes))"string"==typeof n.url&&"number"==typeof n.width&&isSafeUrl(n.url)&&t.push(`${ir(n.url)} ${String(n.width)}w`);return 0!==t.length?("number"==typeof e.width&&"string"==typeof e.url&&isSafeUrl(e.url)&&t.push(`${ir(e.url)} ${String(e.width)}w`),t.join(", ")):void 0}(n);if(void 0===r)return e.removeAttribute("srcset"),void e.removeAttribute("sizes");e.setAttribute("srcset",r)}function ir(e){return e.replace(/[\s,]/g,encodeURIComponent)}var or={name:"image",render:/* @__PURE__ */A((e,t,n)=>{const r=e.element;if(Ft(t))return void sr(r);const i=void 0!==e.locale,{media:o,candidate:s}=function(e,t,n,r){const i=void 0!==e.srcField&&e.srcField.length>0?We(n.allFields,e.srcField,n.locale,r):t,o=Cn(i);return{media:o,candidate:void 0===o?i:o.url}}(e,t,n,i),a=Qn(r,e.fieldName,s);if("none"===a.kind)return!1;if("unsafe"!==a.kind){if("IMG"===r.tagName){const t=r;rr(t,a.url,o);const s=function(e,t,n,r,i){if(void 0!==t&&t.length>0){const e=We(n,t,r,i);return"string"==typeof e?e:void 0}return e?.alt}(o,e.altField,n.allFields,n.locale,i);return void(void 0!==s&&(t.alt=s))}r.style.backgroundImage=`url('${function(e){return e.replace(/['"()\\]/g,"\\$&")}(a.url)}')`}else sr(r)})};function sr(e){"IMG"===e.tagName?nr(e):e.style.backgroundImage=""}var ar={name:"upload",render:/* @__PURE__ */A((e,t)=>{const n=e.element;if(Ft(t))return void lr(n);const r=Cn(t);if(void 0===r)return!1;const i=Qn(n,e.fieldName,r.url);if("none"===i.kind)return!1;if("unsafe"===i.kind)return void lr(n);const o=i.url;if("IMG"===n.tagName){const e=n;return rr(e,o,r),void(void 0!==r.alt&&(e.alt=r.alt))}if("A"===n.tagName)return n.setAttribute("href",o),void(n.textContent=r.filename??o);const s=escapeHtml(r.filename??o);n.innerHTML=Xe(`<a href="${escapeHtmlAttribute(o)}">${s}</a>`)})};function lr(e){"IMG"!==e.tagName?(e.removeAttribute("href"),e.textContent=""):nr(e)}var cr={name:"relationship",render(e,t){const n=e.element;if(Ft(t))return n.removeAttribute("href"),void(n.textContent="");if("A"===n.tagName&&!Array.isArray(t)){const r=Qn(n,e.fieldName,Tn(t)?.url);"safe"===r.kind?n.setAttribute("href",r.url):"unsafe"===r.kind&&n.removeAttribute("href")}n.textContent=Array.isArray(t)?t.map(dr).join(", "):dr(t)}};function dr(e){const t=Tn(e);return void 0===t?Rt(e):Fn(t)??""}var ur={name:"select",render(e,t,n){const r=e.element,i=Ft(t)?[]:function(e){return Array.isArray(e)?e.map(Rt):[Rt(e)]}(t);if("SELECT"!==r.tagName){if("INPUT"===r.tagName&&"radio"===r.type){const e=r;return void(e.checked=i.includes(e.value))}r.textContent=i.map(e=>function(e,t){const n=t.schema?.options;if(!Array.isArray(n))return e;for(const t of n){const n=Tn(t);if(void 0!==n&&Rt(n.value)===e)return"string"==typeof n.label?n.label:e}return e}(e,n)).join(", ")}else!function(e,t){if(e.multiple)for(const n of Array.from(e.options))n.selected=t.includes(n.value);else e.value=t[0]??""}(r,i)}},hr=/* @__PURE__ */new Set(["","false","0","off","no"]),fr={name:"checkbox",render(e,t){const n=e.element,r=function(e){return"boolean"==typeof e?e:"string"==typeof e?!hr.has(e.trim().toLowerCase()):"number"==typeof e?0!==e:null!=e}(t);"INPUT"!==n.tagName||"checkbox"!==n.type?n.hasAttribute("aria-checked")?n.setAttribute("aria-checked",r?"true":"false"):n.textContent=r?"true":"false":n.checked=r}},pr=/* @__PURE__ */new Map,gr=/* @__PURE__ */new Map;function mr(e,t){const n=e??"";if(null==t)return n;const r=vr(t);return"{}"===r?n:`${n}|${r}`}function vr(e){if(null===e||"object"!=typeof e)return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(e=>vr(e)).join(",")}]`;const t=e,n=Object.keys(t).sort(),r=[];for(const e of n){const n=t[e];void 0!==n&&r.push(`${JSON.stringify(e)}:${vr(n)}`)}return`{${r.join(",")}}`}function yr(e){for(;e.size>64;){const t=e.keys().next().value;if(void 0===t)break;e.delete(t)}}var br={name:"date",render(e,t,n){const r=e.element;if(Ft(t))return void("INPUT"===r.tagName?r.value="":(r.removeAttribute("datetime"),r.textContent=""));const i="number"==typeof t?t:Rt(t),o=new Date(i),s=!Number.isNaN(o.getTime()),a=String(i);"INPUT"!==r.tagName?("TIME"===r.tagName&&r.setAttribute("datetime",s?o.toISOString():a),r.textContent=s?function(e,t){const n=t.locale??detectInitialLocale();try{return function(e,t){const n=mr(e,t),r=gr.get(n);if(void 0!==r)return gr.delete(n),gr.set(n,r),r;const i=new Intl.DateTimeFormat(e,t);return gr.set(n,i),yr(gr),i}(n,{dateStyle:"medium",timeStyle:"short"}).format(e)}catch{return e.toISOString()}}(o,n):a):r.value=s?function(e,t){const n=`${String(t.getFullYear()).padStart(4,"0")}-${wr(t.getMonth()+1)}-${wr(t.getDate())}`,r=`${wr(t.getHours())}:${wr(t.getMinutes())}`;return"date"===e?n:"datetime-local"===e?`${n}T${r}`:"time"===e?r:t.toISOString()}(r.type,o):a}};function wr(e){return String(e).padStart(2,"0")}var Sr={name:"number",render(e,t,n){const r=e.element;if(Ft(t))return void("INPUT"===r.tagName?r.value="":r.textContent="");const i="number"==typeof t?t:Number(Rt(t));Number.isNaN(i)?r.textContent=Rt(t):"INPUT"!==r.tagName?r.textContent=function(e,t){const n=t.locale??detectInitialLocale();try{return function(e,t){const n=mr(e,t),r=pr.get(n);if(void 0!==r)return pr.delete(n),pr.set(n,r),r;const i=new Intl.NumberFormat(e,t);return pr.set(n,i),yr(pr),i}(n).format(e)}catch{return String(e)}}(i,n):r.value=String(i)}},kr={name:"array",render:/* @__PURE__ */A((e,t)=>{const n=e.element;if(Ft(t))return void(n.textContent="");if(!Array.isArray(t))return!1;const r=e.arrayTemplate;if(void 0!==r&&r.length>0){const e=function(e,t){let n="";for(let r=0;r<t.length;r+=1)n+=$t(e,t[r],r,Rt);return n}(r,t);return void(n.innerHTML=Xe(sanitizeHtml(e,Mt(r))))}n.textContent=t.map(Rt).join(e.arraySeparator??", ")})};function Ar(){const e=/* @__PURE__ */new WeakMap,t=/* @__PURE__ */new WeakSet,n=/* @__PURE__ */new WeakMap,r=/* @__PURE__ */new WeakMap;return{name:"structural-array",render:/* @__PURE__ */A((i,o)=>{const s=Ft(o)?[]:o;if(!Array.isArray(s))return!1;const a=i.element,l=i.arrayTemplate;if(void 0===l||0===l.length)return function(e,t,n){e.has(t)||(e.add(t),we(`[live-preview] LP0403: Skipping structural update for "${n}": <${t.tagName.toLowerCase()} data-payload-structural> needs data-payload-array-template (for example "<li>{{label}}</li>").`))}(t,a,i.fieldName),!1;const c=e.get(a),d=Tr(a),u=h(c?.values??d.map((e,t)=>null===e?{__payloadDomPosition:t}:{id:e}),s),f=function(e,t,n){return void 0===e||e.template!==t||!function(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}(e.domSnapshot,n)}(c,l,d);if(0===u.length&&!f)return e.set(a,{values:s.slice(),template:l,domSnapshot:d}),!1;!function(e,t,n,r,i){const o=i.map(Cr),s=/* @__PURE__ */new Set,a=o.find(e=>!(void 0===e||!s.has(e)&&(s.add(e),1)));if(void 0!==a&&$r(e,t,n,a),o.some(e=>void 0===e)&&Rr(e,t,"LP0404",`LP0404: an item of "${n}" has no id and pairs by position, so an insert re-renders every row after it. Give items a stable id.`),r?.length===i.length&&i.length>1){const i=new Set(r.map(Cr).filter(e=>void 0!==e)),s=o.some(e=>void 0!==e&&i.has(e));i.size>0&&!s&&Rr(e,t,"LP0406",`LP0406: every key of "${n}" changed at once; the source generates ids per message, so no item can be retained across updates.`)}}(n,a,i.fieldName,c?.values,s);const p=Ot({template:l,container:a,patches:u,nextItems:s,store:r,forceRender:f,onDuplicateKey:(e,t)=>{$r(n,e,i.fieldName,t)}});return null!==p&&(e.set(a,{values:s.slice(),template:l,domSnapshot:Tr(a)}),!!p&&void 0)})}}function Tr(e){return Array.from(e.children,e=>e.getAttribute(It))}function Cr(e){if("object"!=typeof e||null===e)return;const t=e.id;return"string"==typeof t||"number"==typeof t?String(t):void 0}function $r(e,t,n,r){Rr(e,t,"LP0405",`LP0405: two items of "${n}" share the key "${r}"; later ones pair by position. Make \`id\` unique per item.`)}function Rr(e,t,n,r){let i=e.get(t);void 0===i&&(i=/* @__PURE__ */new Set,e.set(t,i)),i.has(n)||(i.add(n),we(`[live-preview] ${r}`))}var Fr=/* @__PURE__ */new Map;function Nr(e){const t={};for(const[n,r]of Object.entries(e))void 0!==r&&(t[n]=r);return t}var xr=Object.freeze({disableReferrerDetection:!0,eventSourcePolicy:"parent-or-opener",skipUnchanged:!0,sanitizerPolicy:"strict"}),Pr=Object.freeze({disableReferrerDetection:!1,eventSourcePolicy:"any",skipUnchanged:!1,sanitizerPolicy:"compat"});function Lr(e){return void 0===e?void 0:!e}var Mr,LivePreviewClient=class{#z=new EventEmitter;#j;#B;#W;#S;#c;#V=!1;#q=!1;#G=!1;#_=null;constructor(e={}){const t=function(e){if("v1"===e.defaults)return e;const t="v1"===e.defaults?Pr:xr;return{...e,skipUnchanged:e.skipUnchanged??t.skipUnchanged,disableReferrerDetection:e.disableReferrerDetection??t.disableReferrerDetection,eventSourcePolicy:e.eventSourcePolicy??t.eventSourcePolicy,sanitizerPolicy:e.sanitizerPolicy??t.sanitizerPolicy}}(e),n=t.serverURL??"";if("v1"!==e.defaults&&""!==n&&void 0===t.mergeDepth)throw new Error("payload-live-preview: `serverURL` needs an explicit `mergeDepth` under the 2.0 defaults — choose the population depth deliberately (0 for none), or pass `defaults: 'v1'` to keep the 1.x default of 1 while migrating (ADR 0007, entry 10).");var r;void 0!==t.sanitizerPolicy&&(r=t.sanitizerPolicy,mt=r);const i=t.debug??isDevMode();this.#c=i?(...e)=>{Se("[live-preview]",...e)}:ye,this.#j=new OriginDetector(Nr({additionalOrigins:t.allowedOrigins,enableReferrerDetection:Lr(t.disableReferrerDetection),enableLocalhostMatching:Lr(t.disableLocalhostMatching)})),this.#j.isProductionUnconfigured&&this.#c("no trusted origin could be detected — set allowedOrigins"),this.#B=new mn(function(){const e=[_n,Kn,Zn,er,or,ar,cr,ur,{...ur,name:"radio"},fr,br,Sr,kr,{...kr,name:"blocks"}];return function(e=[]){const t={};for(const n of e)t[n.name]=n;for(const[e,n]of Fr)t[e]=n;return Object.freeze(t)}([Gn("text"),Gn("textarea"),...e,Ar()])}()),this.#S=new gn({events:this.#z,config:Object.freeze({...t}),registerFieldRenderer:e=>this.#B.register(e),onTransformError:e=>{this.#z.emit("error",{error:e,context:"transform",code:"LP0602"})},log:this.#c}),this.#W=new nn(Nr({root:t.root,renderers:this.#B.renderers,resolveRenderer:(e,n)=>t.resolveRenderer?.(e,n)??this.#B.resolve(e),renderRichText:t.renderRichText,transformValue:(e,t,n,r)=>this.#S.applyTransforms(e,t,n,r),originMatcher:e=>this.#j.matches(e),readyTargets:()=>this.#j.enumerate(),emitter:this.#z,dataMerge:""===n?void 0:Nr({serverURL:n,apiRoute:t.apiRoute,depth:t.mergeDepth,fetchFn:t.mergeFetch}),debounceMs:t.debounceMs,heartbeatMs:t.heartbeatMs,intersectionRootMargin:t.intersectionRootMargin,scopeBindingsByOwner:t.scopeBindingsByOwner,skipUnchanged:t.skipUnchanged,revealEditedField:t.revealEditedField,eventSourcePolicy:t.eventSourcePolicy,dependencies:t.dependencies,strategies:t.strategies,disableVisibilityGate:t.disableVisibilityGate,visibilityGateThreshold:t.visibilityGateThreshold,enableA11y:t.enableA11y,a11yLocale:t.a11yLocale,onHeartbeatTimeout:()=>{this.#j.unlockOrigin()},lockedOrigin:()=>this.#j.lockedOrigin,validateToken:t.validateToken,log:this.#c})),this.#z.on("connect",e=>{this.#j.lockOrigin(e.origin)}),!1!==t.autoStart&&this.start()}start(){if(this.#q)return!1;if(this.#V)return this.#W.start(),!0;if(!isInPreviewContext())return!1;const e=this.#W.start();return e&&(this.#V=!0),e}suspend(){return!(this.#q||!this.#V)&&this.#W.suspend()}resume(){return!(this.#q||!this.#V)&&this.#W.start()}destroy(){if(null!==this.#_)return this.#_;let e,t;this.#q=!0;const n=new Promise((n,r)=>{e=n,t=r});this.#_=n;const r=()=>{this.#z.removeAllListeners(),this.#G=!0};try{this.#W.destroy(),this.#S.destroyAll().finally(r).then(e,t)}catch(e){r(),t(e)}return n}async use(e){if(this.#q)throw new Error("LivePreviewClient: already destroyed");await this.#S.register(e)}async unuse(e){if(this.#G)throw new Error("LivePreviewClient: already destroyed");await this.#S.unregister(e)}refreshCache(){this.#W.refreshCache()}get events(){return this.#z}get plugins(){return this.#S.list()}get status(){return this.#W.status}inspect(){return{...this.#W.inspect(),plugins:this.#S.snapshot()}}get updateCount(){return this.#W.updateCount}get destroyed(){return this.#q}};function initLivePreview(e={}){const t=new LivePreviewClient({...e,autoStart:!1});return t.start()?t:null}function setCspCrypto(e){Mr=e??void 0}function generateCspNonce(e=16){if(!Number.isInteger(e)||e<8)throw new RangeError(`generateCspNonce: bytes must be an integer >= 8, got ${String(e)}`);const t=function(){if(Mr?.getRandomValues)return Mr;const e=globalThis.crypto;return e?.getRandomValues?e:void 0}();if(!t)throw new Error("generateCspNonce: Web Crypto is unavailable. On Node 18 call setCspCrypto(webcrypto) once at startup, or run with --experimental-global-webcrypto. We won't fabricate a predictable nonce — that would silently defeat the entire CSP.");const n=new Uint8Array(e);return t.getRandomValues(n),function(e){let t="";for(const n of e)t+=String.fromCharCode(n);return("function"==typeof btoa?btoa(t):Buffer.from(e).toString("base64")).replaceAll("+","-").replaceAll("/","_").replaceAll("=","")}(n)}function buildFrameAncestors(e={}){const{self:t=!0,origins:n=[],allowNone:r=!1}=e,i=/* @__PURE__ */new Set,o=[];if(r&&!t&&0===n.length)return"'none'";t&&(o.push("'self'"),i.add("'self'"));for(const e of n){const t=e.trim();0===t.length||i.has(t)||(i.add(t),o.push(t))}return o.length>0?o.join(" "):"'none'"}function buildScriptSrcWithNonce(e,t={}){if(0===e.length)throw new RangeError("buildScriptSrcWithNonce: nonce is empty");const{self:n=!0,extra:r=[],strictDynamic:i=!1}=t,o=[];n&&o.push("'self'"),o.push(`'nonce-${e}'`),i&&o.push("'strict-dynamic'");for(const e of r){const t=e.trim();t.length>0&&o.push(t)}return o.join(" ")}var Ir="payload-live-preview.authorized-preview-context",Er=Symbol.for(Ir);function isAuthorizedPreviewContext(e){return"object"==typeof e&&null!==e&&!0===e[Er]&&Object.isFrozen(e)}var Ur={basic:{gates:"data updates are applied to bound elements",fallback:"none — every peer has it"},"schema-json":{gates:"field typing from fieldSchemaJSON (Payload 2.x) and the payload-2 profile",fallback:"field types come from DOM heuristics and Lexical auto-detection"},locale:{gates:"locale-aware field resolution (`title_de` before `title`) and the locale on island events",fallback:"bindings resolve the unsuffixed field value"},"preview-token":{gates:"per-message token validation (library extension)",fallback:"messages carry no token; validateToken cannot be satisfied"},"nested-arrays":{gates:"keyed array diffs below the top level",fallback:"array updates replace the whole array"},"recursive-diffs":{gates:"recursive object diffs",fallback:"nested objects re-render as a unit"},"document-events":{gates:"the `documentSave` runtime event, the document-save plugin and the payload-3 profile",fallback:"no documentSave event; a save is not distinguishable from an edit"},"relationship-events":{gates:"the `relationshipUpdate` runtime event and an unconditional re-render of the update that carries it",fallback:"a related document edited in a drawer shows up on the next data update only"}},Or=Object.freeze({NoTrustedOrigin:"LP0101",ReferrerOnlyTrust:"LP0102",PluginIncompatible:"LP0103",OrphanField:"LP0201",UnattributableUpdate:"LP0202",VisibilityGateDeferred:"LP0301",UnsafeAttributeWrite:"LP0401",TextTargetHasChildren:"LP0402",MissingArrayTemplate:"LP0403",StructuralItemUnkeyed:"LP0404",StructuralDuplicateKey:"LP0405",StructuralUnstableKeys:"LP0406",UnsupportedStrategy:"LP0407",MessageRejected:"LP0501",TokenRejected:"LP0502",HandlerThrew:"LP0601",TransformThrew:"LP0602",RendererThrew:"LP0603",StartupFailed:"LP0605",ReadyFailed:"LP0606",AuditRuntimeMissing:"LP0701",AuditNoFrameAncestors:"LP0702",AuditFrameOptionsBlocks:"LP0703",AuditBindingsExposed:"LP0704",AuditGateThresholdExceeded:"LP0705",AuditUnownedBindings:"LP0706",AuditNoBindings:"LP0707",AuditNotAPage:"LP0708",FragmentRequestFailed:"LP0801",FragmentResponseInvalid:"LP0802",FragmentUnauthorized:"LP0803",FragmentSuperseded:"LP0804",RouteRefreshLoop:"LP0805",FragmentStrategyUnavailable:"LP0806",V2ReadinessGap:"LP0709",RuntimeOnPublicPage:"LP0710"});function bind(e,t){return Hr(e,t)}function bindByPath(e,t){const n=function(e){const t=[],n=new Proxy({},{get(e,r){if("symbol"!=typeof r)return/^\d+$/.test(r)||t.push(r),n}});try{e(n)}catch{}return t}(e);if(0===n.length)throw new Error("bindByPath: the picker did not read any field — return data.<field> instead of a constant");return Hr(n.join("."),t)}function Hr(e,t){if(0===e.length)throw new Error("bind: field name must be a non-empty string");const n={"data-payload-field":e};return void 0!==t?.attribute&&(n["data-payload-attribute"]=t.attribute),void 0!==t?.type&&(n["data-payload-type"]=t.type),!0===t?.richtext&&(n["data-payload-richtext"]=""),!0===t?.html&&(n["data-payload-html"]=""),void 0!==t?.locale&&(n["data-payload-locale"]=t.locale),void 0!==t?.alt&&(n["data-payload-alt"]=t.alt),void 0!==t?.href&&(n["data-payload-href"]=t.href),void 0!==t?.arrayTemplate&&(n["data-payload-array-template"]=t.arrayTemplate),n}var Dr=Object.freeze({});function createPreviewBindings(e){const t=isAuthorizedPreviewContext(e.authorization),n=void 0!==e.owner&&e.owner.length>0?e.owner:void 0;return Object.freeze({authorized:t,bind:(e,n)=>t?bind(e,n):Dr,bindByPath:(e,n)=>t?bindByPath(e,n):Dr,owner:()=>t&&void 0!==n?{"data-payload-owner":n}:Dr})}var zr=!0;export{Ir as AUTHORIZED_PREVIEW_BRAND_KEY,R as CAPABILITY_DECLARATIONS,Ur as CAPABILITY_DOCUMENTATION,zr as CORE_ENTRY,Or as DIAGNOSTIC_CODES,EventEmitter,O as ISLAND_EVENT,$ as LIBRARY_PROTOCOL_VERSION,LivePreviewClient,OriginDetector,F as PROTOCOL_CAPABILITIES,e as VERSION,bind,bindByPath,buildFrameAncestors,buildScriptSrcWithNonce,createPreviewBindings,detectInitialLocale,detectProtocolProfile,escapeHtml,escapeHtmlAttribute,generateCspNonce,hasCapability,initLivePreview,isAuthorizedPreviewContext,isDevMode,isExternalHttpUrl,isInIframe,isInPopup,isInPreviewContext,isInsideIsland,isSafeUrl,negotiateProtocol,sanitizeHtml,setCspCrypto,setSanitizerDocument};
|
|
2
2
|
//# sourceMappingURL=core.js.map
|