payload-live-preview 1.0.2 → 1.0.4

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.
Files changed (71) hide show
  1. package/README.md +150 -84
  2. package/dist/adapters/astro/RichText.astro +8 -4
  3. package/dist/adapters/astro/index.d.ts +84 -9
  4. package/dist/adapters/astro/index.js +1 -363
  5. package/dist/adapters/astro/index.js.map +1 -1
  6. package/dist/adapters/astro/middleware-entry.d.ts +1 -1
  7. package/dist/adapters/astro/middleware-entry.js +1 -296
  8. package/dist/adapters/astro/middleware-entry.js.map +1 -1
  9. package/dist/adapters/nextjs/index.d.ts +24 -10
  10. package/dist/adapters/nextjs/index.js +1 -305
  11. package/dist/adapters/nextjs/index.js.map +1 -1
  12. package/dist/adapters/nuxt/index.d.ts +20 -10
  13. package/dist/adapters/nuxt/index.js +1 -293
  14. package/dist/adapters/nuxt/index.js.map +1 -1
  15. package/dist/adapters/sveltekit/index.d.ts +22 -6
  16. package/dist/adapters/sveltekit/index.js +1 -272
  17. package/dist/adapters/sveltekit/index.js.map +1 -1
  18. package/dist/codegen-astro.js +1 -609
  19. package/dist/codegen-astro.js.map +1 -1
  20. package/dist/codegen-cli.js +1 -665
  21. package/dist/codegen-cli.js.map +1 -1
  22. package/dist/codegen.cjs +1 -550
  23. package/dist/codegen.cjs.map +1 -1
  24. package/dist/codegen.js +1 -546
  25. package/dist/codegen.js.map +1 -1
  26. package/dist/core.cjs +1 -3719
  27. package/dist/core.cjs.map +1 -1
  28. package/dist/core.d.cts +1210 -7
  29. package/dist/core.d.ts +1210 -7
  30. package/dist/core.js +1 -3692
  31. package/dist/core.js.map +1 -1
  32. package/dist/index.cjs +1 -4118
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +1359 -34
  35. package/dist/index.d.ts +1359 -34
  36. package/dist/index.js +1 -4075
  37. package/dist/index.js.map +1 -1
  38. package/dist/{middleware-BwIlf0jW.d.cts → middleware-CkSeLZ-9.d.ts} +35 -19
  39. package/dist/payload.cjs +1 -30
  40. package/dist/payload.cjs.map +1 -1
  41. package/dist/payload.d.cts +4 -3
  42. package/dist/payload.d.ts +4 -3
  43. package/dist/payload.js +1 -28
  44. package/dist/payload.js.map +1 -1
  45. package/package.json +55 -16
  46. package/dist/adapters/astro/index.cjs +0 -370
  47. package/dist/adapters/astro/index.cjs.map +0 -1
  48. package/dist/adapters/astro/index.d.cts +0 -105
  49. package/dist/adapters/astro/middleware-entry.cjs +0 -303
  50. package/dist/adapters/astro/middleware-entry.cjs.map +0 -1
  51. package/dist/adapters/astro/middleware-entry.d.cts +0 -15
  52. package/dist/adapters/nextjs/index.cjs +0 -309
  53. package/dist/adapters/nextjs/index.cjs.map +0 -1
  54. package/dist/adapters/nextjs/index.d.cts +0 -75
  55. package/dist/adapters/nuxt/index.cjs +0 -299
  56. package/dist/adapters/nuxt/index.cjs.map +0 -1
  57. package/dist/adapters/nuxt/index.d.cts +0 -126
  58. package/dist/adapters/sveltekit/index.cjs +0 -275
  59. package/dist/adapters/sveltekit/index.cjs.map +0 -1
  60. package/dist/adapters/sveltekit/index.d.cts +0 -80
  61. package/dist/bind-BSgxoQhN.d.cts +0 -1137
  62. package/dist/bind-BSgxoQhN.d.ts +0 -1137
  63. package/dist/codegen-astro.cjs +0 -612
  64. package/dist/codegen-astro.cjs.map +0 -1
  65. package/dist/codegen-astro.d.cts +0 -54
  66. package/dist/codegen-cli.cjs +0 -669
  67. package/dist/codegen-cli.cjs.map +0 -1
  68. package/dist/codegen-cli.d.cts +0 -19
  69. package/dist/middleware-BwIlf0jW.d.ts +0 -168
  70. package/dist/preview-request-DAvxm18T.d.cts +0 -68
  71. package/dist/preview-request-DAvxm18T.d.ts +0 -68
@@ -1,306 +1,2 @@
1
- // src/security/csp.ts
2
- var DEFAULT_NONCE_BYTES = 16;
3
- function generateCspNonce(bytes = DEFAULT_NONCE_BYTES) {
4
- if (!Number.isInteger(bytes) || bytes < 8) {
5
- throw new RangeError(`generateCspNonce: bytes must be an integer >= 8, got ${String(bytes)}`);
6
- }
7
- const crypto = resolveCrypto();
8
- if (!crypto) {
9
- throw new Error(
10
- "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 \u2014 that would silently defeat the entire CSP."
11
- );
12
- }
13
- const buffer = new Uint8Array(bytes);
14
- crypto.getRandomValues(buffer);
15
- return base64UrlEncode(buffer);
16
- }
17
- function resolveCrypto() {
18
- const fromGlobal = globalThis.crypto;
19
- if (fromGlobal?.getRandomValues) return fromGlobal;
20
- return void 0;
21
- }
22
- function base64UrlEncode(bytes) {
23
- let binary = "";
24
- for (const byte of bytes) binary += String.fromCharCode(byte);
25
- const base64 = typeof btoa === "function" ? btoa(binary) : Buffer.from(bytes).toString("base64");
26
- return base64.replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
27
- }
28
- function buildFrameAncestors(options = {}) {
29
- const { self = true, origins = [], allowNone = false } = options;
30
- const seen = /* @__PURE__ */ new Set();
31
- const out = [];
32
- if (allowNone && !self && origins.length === 0) return "'none'";
33
- if (self) {
34
- out.push("'self'");
35
- seen.add("'self'");
36
- }
37
- for (const origin of origins) {
38
- const trimmed = origin.trim();
39
- if (trimmed.length === 0 || seen.has(trimmed)) continue;
40
- seen.add(trimmed);
41
- out.push(trimmed);
42
- }
43
- return out.length > 0 ? out.join(" ") : "'none'";
44
- }
45
- function buildScriptSrcWithNonce(nonce, options = {}) {
46
- if (nonce.length === 0) throw new RangeError("buildScriptSrcWithNonce: nonce is empty");
47
- const { self = true, extra = [], strictDynamic = false } = options;
48
- const parts = [];
49
- if (self) parts.push("'self'");
50
- parts.push(`'nonce-${nonce}'`);
51
- if (strictDynamic) parts.push("'strict-dynamic'");
52
- for (const e of extra) {
53
- const trimmed = e.trim();
54
- if (trimmed.length > 0) parts.push(trimmed);
55
- }
56
- return parts.join(" ");
57
- }
58
- function mergeCspHeader(existing, additions) {
59
- const directives = /* @__PURE__ */ new Map();
60
- for (const part of existing.split(";")) {
61
- const trimmed = part.trim();
62
- if (trimmed.length === 0) continue;
63
- const spaceIndex = trimmed.indexOf(" ");
64
- if (spaceIndex < 0) {
65
- directives.set(trimmed.toLowerCase(), "");
66
- continue;
67
- }
68
- directives.set(
69
- trimmed.slice(0, spaceIndex).toLowerCase(),
70
- trimmed.slice(spaceIndex + 1).trim()
71
- );
72
- }
73
- for (const [rawName, rawAddition] of Object.entries(additions)) {
74
- const name = rawName.toLowerCase();
75
- const addition = typeof rawAddition === "string" ? { value: rawAddition } : rawAddition;
76
- const mode = addition.mode ?? "union";
77
- const current = directives.get(name);
78
- if (mode === "replace" || current === void 0 || current.length === 0) {
79
- directives.set(name, addition.value);
80
- continue;
81
- }
82
- const seen = /* @__PURE__ */ new Set();
83
- const merged = [];
84
- for (const token of [...current.split(/\s+/), ...addition.value.split(/\s+/)]) {
85
- if (token.length === 0 || seen.has(token)) continue;
86
- seen.add(token);
87
- merged.push(token);
88
- }
89
- const withoutNone = merged.filter((token) => token !== "'none'");
90
- directives.set(name, (withoutNone.length > 0 ? withoutNone : merged).join(" "));
91
- }
92
- const out = [];
93
- for (const [name, value] of directives) {
94
- out.push(value.length === 0 ? name : `${name} ${value}`);
95
- }
96
- return out.join("; ");
97
- }
98
-
99
- // src/inline/runtime.generated.ts
100
- var RUNTIME_SOURCE = '"use strict";(()=>{var Xr=Object.defineProperty;var Dn=t=>{throw TypeError(t)};var Zr=(t,e,n)=>e in t?Xr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var $n=(t,e,n)=>Zr(t,typeof e!="symbol"?e+"":e,n),Ft=(t,e,n)=>e.has(t)||Dn("Cannot "+n);var i=(t,e,n)=>(Ft(t,e,"read from private field"),n?n.call(t):e.get(t)),l=(t,e,n)=>e.has(t)?Dn("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,n),d=(t,e,n,r)=>(Ft(t,e,"write to private field"),r?r.call(t,n):e.set(t,n),n),f=(t,e,n)=>(Ft(t,e,"access private method"),n);var F,_,ne,Dt,$t,Tt=class{constructor(){l(this,ne);l(this,F,new Map);l(this,_,new Map)}on(e,n){return f(this,ne,Dt).call(this,i(this,F),e,n)}once(e,n){return f(this,ne,Dt).call(this,i(this,_),e,n)}off(e,n){i(this,F).get(e)?.delete(n),i(this,_).get(e)?.delete(n)}async emit(e,n){let r=i(this,F).get(e);if(r)for(let s of[...r])await f(this,ne,$t).call(this,s,n,e);let o=i(this,_).get(e);if(o&&o.size>0){let s=[...o];i(this,_).delete(e);for(let a of s)await f(this,ne,$t).call(this,a,n,e)}}listenerCount(e){return(i(this,F).get(e)?.size??0)+(i(this,_).get(e)?.size??0)}removeAllListeners(e){if(e===void 0){i(this,F).clear(),i(this,_).clear();return}i(this,F).delete(e),i(this,_).delete(e)}eventNames(){let e=new Set;for(let n of i(this,F).keys())e.add(n);for(let n of i(this,_).keys())e.add(n);return[...e]}};F=new WeakMap,_=new WeakMap,ne=new WeakSet,Dt=function(e,n,r){let o=e.get(n);return o||(o=new Set,e.set(n,o)),o.add(r),()=>{e.get(n)?.delete(r)}},$t=async function(e,n,r){try{await e(n)}catch(o){let s=typeof r=="string"||typeof r=="number"?String(r):"<event>";console.error(`[live-preview] handler for "${s}" threw:`,o)}};var ue="data-payload-field",Un="data-payload-type",Qr="data-payload-attribute",ei="data-payload-href",ti="data-payload-src",ni="data-payload-alt",ri="data-payload-array-template",ii="data-payload-array-separator",oi="data-payload-locale",si=`[${ue}]`,Hn=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"]),E,Y,we,re,Ut,Ht,wt=class{constructor(e={}){l(this,re);l(this,E,new Map);l(this,Y,new WeakMap);l(this,we);d(this,we,e.filter??di)}buildFromRoot(e){let n=performance.now();i(this,E).clear();let r=e.querySelectorAll(si),o=0;for(let s of r){if(!i(this,we).call(this,s))continue;let a=f(this,re,Ht).call(this,s);a&&(f(this,re,Ut).call(this,a),i(this,Y).set(s,a),o+=1)}return{elementCount:o,fieldCount:i(this,E).size,durationMs:performance.now()-n}}add(e){if(!i(this,we).call(this,e))return;let n=f(this,re,Ht).call(this,e);if(n)return f(this,re,Ut).call(this,n),i(this,Y).set(e,n),n}remove(e){let n=i(this,Y).get(e);if(!n)return!1;i(this,Y).delete(e);let r=i(this,E).get(n.fieldName);if(!r)return!1;let o=r.indexOf(n);return o<0?!1:(r.splice(o,1),r.length===0&&i(this,E).delete(n.fieldName),!0)}get(e){return i(this,E).get(e)}getByElement(e){return i(this,Y).get(e)}get fieldCount(){return i(this,E).size}get elementCount(){let e=0;for(let n of i(this,E).values())e+=n.length;return e}entries(){return i(this,E).entries()}*values(){for(let e of i(this,E).values())yield*e}has(e){return i(this,Y).has(e)}clear(){i(this,E).clear()}};E=new WeakMap,Y=new WeakMap,we=new WeakMap,re=new WeakSet,Ut=function(e){let n=i(this,E).get(e.fieldName);if(n){n.push(e);return}i(this,E).set(e.fieldName,[e])},Ht=function(e){let n=e.getAttribute(ue);if(n===null||n.length===0)return;let r=e.getAttribute(Un),o=ai(e),s=e.getAttribute(Qr),a=e.getAttribute(ei),u=e.getAttribute(ti),m=e.getAttribute(ni),T=e.getAttribute(ri),W=e.getAttribute(ii),c=e.getAttribute(oi);return{element:e,fieldName:n,fieldType:o,explicitFieldType:r!==null&&Hn.has(r),...s!==null&&s.length>0?{targetAttribute:s}:{},...a!==null?{hrefField:a}:{},...u!==null?{srcField:u}:{},...m!==null?{altField:m}:{},...T!==null?{arrayTemplate:T}:{},...W!==null?{arraySeparator:W}:{},...c!==null?{locale:c}:{}}};function ai(t){let e=t.getAttribute(Un);if(e!==null&&Hn.has(e))return e;if(t.hasAttribute("data-payload-richtext"))return"richText";if(t.hasAttribute("data-payload-html"))return"html";if(t.hasAttribute("data-payload-structural"))return"structural-array";if(t.hasAttribute("data-payload-array"))return"array";if(t.tagName==="IMG")return"image";if(t.tagName==="A")return"url";if(t.tagName==="TIME")return"date";if(t.tagName==="INPUT"){let n=t.type;if(n==="checkbox")return"checkbox";if(n==="number")return"number";if(n==="date"||n==="datetime-local")return"date"}return"text"}function di(){return!0}var li=100,ui="200px",ce,$e,Ue,M,fe,ie,D,xe,jn,Vn,xt=class{constructor(e,n={}){l(this,xe);l(this,ce);l(this,$e);l(this,Ue);l(this,M,new Set);l(this,fe,null);l(this,ie,null);l(this,D,null);d(this,ce,e),d(this,$e,n.mutationDebounceMs??li),d(this,Ue,n.intersectionRootMargin??ui)}start(e){d(this,fe,new MutationObserver(n=>{f(this,xe,jn).call(this,n)})),i(this,fe).observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[ue]}),d(this,ie,new IntersectionObserver(n=>{f(this,xe,Vn).call(this,n)},{rootMargin:i(this,Ue),threshold:0}))}observeElement(e){i(this,ie)?.observe(e)}unobserveElement(e){i(this,ie)?.unobserve(e),i(this,M).delete(e)}markVisible(e,n){n?i(this,M).add(e):i(this,M).delete(e)}isVisible(e){return i(this,M).has(e)}stop(){i(this,D)!==null&&(clearTimeout(i(this,D)),d(this,D,null)),i(this,fe)?.disconnect(),i(this,ie)?.disconnect(),d(this,fe,null),d(this,ie,null),i(this,M).clear()}};ce=new WeakMap,$e=new WeakMap,Ue=new WeakMap,M=new WeakMap,fe=new WeakMap,ie=new WeakMap,D=new WeakMap,xe=new WeakSet,jn=function(e){ci(e)&&(i(this,D)!==null&&clearTimeout(i(this,D)),d(this,D,setTimeout(()=>{d(this,D,null),i(this,ce).onStructuralChange()},i(this,$e))))},Vn=function(e){for(let n of e){let r=n.target;n.isIntersecting?i(this,M).has(r)||(i(this,M).add(r),i(this,ce).onVisibilityChange(r,!0)):i(this,M).has(r)&&(i(this,M).delete(r),i(this,ce).onVisibilityChange(r,!1))}};function ci(t){for(let e of t){if(e.type==="attributes"&&e.attributeName===ue)return!0;for(let n of e.addedNodes)if(Bn(n))return!0;for(let n of e.removedNodes)if(Bn(n))return!0}return!1}function Bn(t){if(t.nodeType!==Node.ELEMENT_NODE)return!1;let e=t;return e.hasAttribute(ue)?!0:e.querySelector(`[${ue}]`)!==null}var fi={basic:1,"schema-json":2,"preview-token":3,"nested-arrays":4,"recursive-diffs":4};function Bt(t){let e=typeof t=="number"&&Number.isFinite(t)&&t>=1?Math.floor(t):void 0,r=Math.min(4,e??1),o=new Set;for(let[s,a]of Object.entries(fi))r>=a&&o.add(s);return{ours:4,...e!==void 0?{theirs:e}:{theirs:void 0},negotiated:r,capabilities:o}}var Be,x,ve,pe,je,Se,Gn,Wn,He=class{constructor(e,n){l(this,Se);l(this,Be);l(this,x);l(this,ve);l(this,pe,!1);l(this,je,Promise.resolve());d(this,Be,e),d(this,x,n),d(this,ve,r=>{f(this,Se,Gn).call(this,r)})}attach(e=window){i(this,pe)||(e.addEventListener("message",i(this,ve)),d(this,pe,!0))}detach(e=window){i(this,pe)&&(e.removeEventListener("message",i(this,ve)),d(this,pe,!1))}static sendReady(e,n){if(e.length===0||n.length===0)return;let r={type:"payload-live-preview",ready:!0,protocolVersion:4};for(let o of e)for(let s of n)try{o.postMessage(r,s)}catch{}}};Be=new WeakMap,x=new WeakMap,ve=new WeakMap,pe=new WeakMap,je=new WeakMap,Se=new WeakSet,Gn=function(e){let n=e.origin;if(!i(this,Be).call(this,n)){i(this,x).onInvalid?.("origin",n);return}let r=e.data;if(!pi(r)){i(this,x).onInvalid?.("shape",n);return}switch(r.type){case"payload-live-preview":if(!mi(r)){i(this,x).onInvalid?.("shape",n);return}f(this,Se,Wn).call(this,r,n);return;case"payload-document-event":i(this,x).onDocumentEvent(r,n);return;default:i(this,x).onInvalid?.("type",n)}},Wn=function(e,n){let r=i(this,x).validateToken;if(r===void 0){i(this,x).onUpdate(e,n);return}if(e.ready===!0&&e.data===void 0){i(this,x).onUpdate(e,n);return}let o;try{o=r(e.previewToken,n)}catch{i(this,x).onInvalid?.("token",n);return}if(typeof o=="boolean"){o?i(this,x).onUpdate(e,n):i(this,x).onInvalid?.("token",n);return}d(this,je,i(this,je).then(async()=>{let s;try{s=await o}catch{i(this,x).onInvalid?.("token",n);return}s?i(this,x).onUpdate(e,n):i(this,x).onInvalid?.("token",n)}))};function pi(t){return typeof t!="object"||t===null||!("type"in t)?!1:typeof t.type=="string"}function mi(t){let e=t;return!(e.data!==void 0&&!hi(e.data)||e.fieldSchemaJSON!==void 0&&!Array.isArray(e.fieldSchemaJSON)||e.globalSlug!==void 0&&typeof e.globalSlug!="string"||e.collectionSlug!==void 0&&typeof e.collectionSlug!="string"||e.locale!==void 0&&typeof e.locale!="string"||e.ready!==void 0&&typeof e.ready!="boolean"||e.previewToken!==void 0&&typeof e.previewToken!="string"||e.protocolVersion!==void 0&&typeof e.protocolVersion!="number")}function hi(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}var Ee,Ve,C,ze,St=class{constructor(e){l(this,Ee);l(this,Ve);l(this,C,null);l(this,ze,0);d(this,Ee,e.timeoutMs??0),d(this,Ve,e.onTimeout)}kick(){d(this,ze,Date.now()),!(i(this,Ee)<=0)&&(i(this,C)!==null&&clearTimeout(i(this,C)),d(this,C,setTimeout(()=>{d(this,C,null),i(this,Ve).call(this)},i(this,Ee))))}stop(){i(this,C)!==null&&(clearTimeout(i(this,C)),d(this,C,null))}get lastKickAt(){return i(this,ze)}get pending(){return i(this,C)!==null}};Ee=new WeakMap,Ve=new WeakMap,C=new WeakMap,ze=new WeakMap;var me,Ge,ke,vt,Et=class{constructor(e){l(this,ke);l(this,me,"disconnected");l(this,Ge);d(this,Ge,e)}get status(){return i(this,me)}markConnected(){return f(this,ke,vt).call(this,"connected")}markConnecting(){return f(this,ke,vt).call(this,"connecting")}markDisconnected(){return f(this,ke,vt).call(this,"disconnected")}};me=new WeakMap,Ge=new WeakMap,ke=new WeakSet,vt=function(e){if(i(this,me)===e)return!1;let n=i(this,me);return d(this,me,e),i(this,Ge).call(this,e,n),!0};var yi=()=>{},We,Ye,qe,Ke,he,q,kt=class{constructor(e){l(this,We);l(this,Ye);l(this,qe);l(this,Ke);l(this,he);l(this,q,null);d(this,We,e.serverURL.replace(/\\/+$/,""));let n=e.apiRoute??"/api";d(this,Ye,n.startsWith("/")?n:`/${n}`),d(this,qe,e.depth??1),d(this,Ke,e.fetchFn),d(this,he,e.log??yi)}canMerge(e){if(e.globalSlug!==void 0&&e.globalSlug!=="")return!0;if(e.collectionSlug===void 0||e.collectionSlug==="")return!1;let n=e.data.id;return typeof n=="string"||typeof n=="number"}async merge(e){if(!this.canMerge(e))return{status:"unavailable"};let n=i(this,Ke)??(typeof fetch=="function"?fetch:void 0);if(n===void 0)return{status:"unavailable"};i(this,q)?.abort();let r=new AbortController;d(this,q,r);let o=e.globalSlug!==void 0&&e.globalSlug!==""?`globals/${e.globalSlug}`:`${e.collectionSlug}/${String(e.data.id)}`,s=`${i(this,We)}${i(this,Ye)}/${encodeURI(o)}`;try{let a=await n(s,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json","X-Payload-HTTP-Method-Override":"GET"},body:JSON.stringify({data:e.data,depth:i(this,qe),flattenLocales:!1,...e.locale!==void 0?{locale:e.locale}:{}}),signal:r.signal});if(!a.ok)return i(this,he).call(this,"merge fetch failed",a.status,s),{status:"unavailable"};let u=await a.json();return u===null||typeof u!="object"||Array.isArray(u)?(i(this,he).call(this,"merge fetch returned non-object",s),{status:"unavailable"}):{status:"merged",doc:u}}catch(a){return r.signal.aborted?{status:"superseded"}:(i(this,he).call(this,"merge fetch error",a),{status:"unavailable"})}finally{i(this,q)===r&&d(this,q,null)}}destroy(){i(this,q)?.abort(),d(this,q,null)}};We=new WeakMap,Ye=new WeakMap,qe=new WeakMap,Ke=new WeakMap,he=new WeakMap,q=new WeakMap;var gi=new Set(["http:","https:","mailto:","tel:"]),bi=/^\\s*(?:javascript|data|vbscript|file|blob|about)\\s*:/i,Ri=/^(?:\\.{1,2}\\/|[a-zA-Z0-9_-]+\\/?)/;function b(t){if(typeof t!="string"||t.length===0)return!1;let e=t.trim();if(e.length===0||bi.test(e))return!1;if(e.startsWith("#")||e.startsWith("?")||e.startsWith("//")||e.startsWith("/"))return!0;try{let n=new URL(e);return gi.has(n.protocol)}catch{return Ri.test(e)}}function At(t){if(!b(t))return!1;let e=t.trim();return/^https?:\\/\\//i.test(e)||/^\\/\\/[^/]/.test(e)}var Ti=new Set(["style","srcdoc","formaction","form","id","name","is","srcset","imagesrcset"]),wi=new Set(["href","src","poster","cite","action","xlink:href","data"]);function Yn(t,e,n){let r=e.toLowerCase().trim();if(r.length===0||r.startsWith("on")||Ti.has(r))return"blocked";if(n==null)return t.removeAttribute(r),"applied";if(typeof n!="string"&&typeof n!="number"&&typeof n!="boolean")return"blocked";let o=String(n);return wi.has(r)&&!b(o)?"blocked":(t.setAttribute(r,o),"applied")}var Ae,Je,Xe,Ze,Qe,et,tt,nt,Le,$,K,k,U,J,qn,Kn,jt,Lt=class{constructor(e,n){l(this,J);l(this,Ae);l(this,Je);l(this,Xe);l(this,Ze);l(this,Qe);l(this,et);l(this,tt);l(this,nt);l(this,Le);l(this,$,new Map);l(this,K,new Map);l(this,k,null);l(this,U,null);d(this,Ae,e),d(this,Je,n.debounceMs??50),d(this,Xe,n.isVisible),d(this,Ze,n.visibilityGateThreshold??50),d(this,Qe,n.disableVisibilityGate??!1),d(this,et,n.getCacheSize),d(this,tt,n.onFlush),d(this,nt,n.scheduleFrame??(typeof requestAnimationFrame=="function"?requestAnimationFrame.bind(globalThis):r=>setTimeout(()=>{r(performance.now())},0))),d(this,Le,n.cancelFrame??(typeof cancelAnimationFrame=="function"?cancelAnimationFrame.bind(globalThis):r=>{clearTimeout(r)}))}schedule(e){let n=i(this,$).get(e.target.element);n?(n.value=e.value,n.allFields=e.allFields):i(this,$).set(e.target.element,{target:e.target,value:e.value,allFields:e.allFields}),f(this,J,qn).call(this)}flushNow(){return i(this,k)!==null&&(clearTimeout(i(this,k)),d(this,k,null)),f(this,J,jt).call(this)}notifyVisible(e){let n=i(this,K).get(e);n&&(i(this,K).delete(e),i(this,Ae).call(this,n))}forget(e){i(this,$).delete(e),i(this,K).delete(e)}destroy(){i(this,k)!==null&&(clearTimeout(i(this,k)),d(this,k,null)),i(this,U)!==null&&(i(this,Le).call(this,i(this,U)),d(this,U,null)),i(this,$).clear(),i(this,K).clear()}get pendingCount(){return i(this,$).size}get replayCount(){return i(this,K).size}};Ae=new WeakMap,Je=new WeakMap,Xe=new WeakMap,Ze=new WeakMap,Qe=new WeakMap,et=new WeakMap,tt=new WeakMap,nt=new WeakMap,Le=new WeakMap,$=new WeakMap,K=new WeakMap,k=new WeakMap,U=new WeakMap,J=new WeakSet,qn=function(){i(this,k)!==null&&clearTimeout(i(this,k)),d(this,k,setTimeout(()=>{d(this,k,null),f(this,J,Kn).call(this)},i(this,Je)))},Kn=function(){i(this,U)!==null&&i(this,Le).call(this,i(this,U)),d(this,U,i(this,nt).call(this,()=>{d(this,U,null),f(this,J,jt).call(this)}))},jt=function(){var u;let e=performance.now(),n=!i(this,Qe)&&i(this,et).call(this)>i(this,Ze),r=i(this,$);d(this,$,new Map);let o=0,s=0;for(let m of r.values()){if(n&&!i(this,Xe).call(this,m.target.element)){i(this,K).set(m.target.element,m),s+=1;continue}i(this,Ae).call(this,m),o+=1}let a={applied:o,deferred:s,durationMs:performance.now()-e};return(u=i(this,tt))==null||u.call(this,a),a};function Me(){let t=xi();if(t!==void 0)return t;let e=vi();return e!==void 0?e:"en"}function xi(){if(typeof document>"u")return;let t=document.documentElement.getAttribute("lang");return t===null||t.length===0?void 0:t}function vi(){if(typeof navigator>"u")return;let t=navigator.language;return typeof t=="string"&&t.length>0?t:void 0}var Jn="payload-live-preview-a11y",Si=1500,Ei=["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"].join(";"),Xn={connected:"Live preview connected",disconnected:"Live preview disconnected",updated:t=>`${String(t)} ${t===1?"change":"changes"} applied`},ki={en:Xn,de:{connected:"Vorschau verbunden",disconnected:"Vorschau getrennt",updated:t=>`${String(t)} ${t===1?"\\xC4nderung":"\\xC4nderungen"} angewendet`}};function Ai(t){let e=t.split(/[-_]/)[0]?.toLowerCase()??"en";return ki[e]??Xn}var I,ye,H,oe,Zn,Mt,rt=class{constructor(e=Me()){l(this,oe);l(this,I,null);l(this,ye);l(this,H,null);d(this,ye,Ai(e))}announceConnected(){f(this,oe,Mt).call(this,i(this,ye).connected)}announceDisconnected(){f(this,oe,Mt).call(this,i(this,ye).disconnected)}announceUpdate(e){e<=0||f(this,oe,Mt).call(this,i(this,ye).updated(e))}detach(){i(this,H)!==null&&(clearTimeout(i(this,H)),d(this,H,null)),i(this,I)?.parentNode&&i(this,I).parentNode.removeChild(i(this,I))}};I=new WeakMap,ye=new WeakMap,H=new WeakMap,oe=new WeakSet,Zn=function(){if(i(this,I)!==null&&i(this,I).isConnected)return i(this,I);if(typeof document>"u"||document.body===null)return null;let e=document.getElementById(Jn);return e||(e=document.createElement("div"),e.id=Jn,e.setAttribute("role","status"),e.setAttribute("aria-live","polite"),e.setAttribute("aria-atomic","true"),e.setAttribute("style",Ei),document.body.appendChild(e)),d(this,I,e),e},Mt=function(e){let n=f(this,oe,Zn).call(this);n&&(n.textContent=e,i(this,H)!==null&&clearTimeout(i(this,H)),d(this,H,setTimeout(()=>{d(this,H,null),i(this,I)&&(i(this,I).textContent="")},Si)))};var Li=new Set(["tabs","row","collapsible"]);function Vt(t,e=""){let n=new Map;return it(t,e,n),n}function it(t,e,n){for(let r of t){if(Li.has(r.type)){r.fields&&it(r.fields,e,n);continue}if(r.type==="group"){let s=e===""?r.name:`${e}.${r.name}`;n.set(s,r),r.fields&&it(r.fields,s,n);continue}let o=e===""?r.name:`${e}.${r.name}`;if(n.set(o,r),r.type==="array"&&r.fields)it(r.fields,`${o}.*`,n);else if(r.type==="blocks"&&r.blocks)for(let s of r.blocks)it(s.fields,`${o}.*.${s.slug}`,n)}}function zt(t,e){if(t.has(e))return t.get(e);let n=e.replace(/\\.\\d+(?=\\.|$)/g,".*");if(t.has(n))return t.get(n)}function Gt(t){if(typeof t!="object"||t===null)return;let e=t.id;if(typeof e=="string"||typeof e=="number")return e}function Qn(t){if(typeof t!="object"||t===null)return;let e=t.blockType;return typeof e=="string"?e:void 0}function ot(t,e){return e.every(r=>Gt(r)!==void 0)?Mi(t,e):Ii(t,e)}function Mi(t,e){let n=[],r=new Map;for(let s=0;s<t.length;s+=1){let a=Gt(t[s]);a!==void 0&&r.set(a,s)}let o=new Set;for(let s=0;s<e.length;s+=1){let a=e[s],u=Gt(a);if(u===void 0){n.push({kind:"insert",index:s,value:a});continue}let m=r.get(u);if(m===void 0){n.push({kind:"insert",index:s,value:a});continue}o.add(m);let T=t[m];if(Qn(T)!==Qn(a)){n.push({kind:"replace",index:s,oldValue:T,value:a});continue}m!==s&&n.push({kind:"move",from:m,to:s,value:a}),er(T,a)||n.push({kind:"update",index:s,value:a})}for(let s=0;s<t.length;s+=1)o.has(s)||n.push({kind:"remove",index:s,value:t[s]});return n}function Ii(t,e){let n=[],r=Math.min(t.length,e.length);for(let o=0;o<r;o+=1)er(t[o],e[o])||n.push({kind:"update",index:o,value:e[o]});if(e.length>t.length)for(let o=t.length;o<e.length;o+=1)n.push({kind:"insert",index:o,value:e[o]});if(t.length>e.length)for(let o=e.length;o<t.length;o+=1)n.push({kind:"remove",index:o,value:t[o]});return n}function er(t,e){if(Object.is(t,e))return!0;if(typeof t!="object"||typeof e!="object"||t===null||e===null)return!1;let n=t,r=e,o=Object.keys(n),s=Object.keys(r);if(o.length!==s.length)return!1;for(let a of o)if(!Object.is(n[a],r[a]))return!1;return!0}var tr={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"};function Wt(t){if(Object.prototype.hasOwnProperty.call(tr,t))return tr[t]}var Ni=[0,500,1e3,2e3],S,A,X,se,Ie,Z,Ne,st,B,ge,be,at,O,_e,Ce,Q,Re,N,Oe,Pe,Fe,Te,ae,dt,lt,h,Yt,qt,Kt,rr,ir,or,sr,ar,dr,lr,ur,cr,fr,pr,It=class{constructor(e){l(this,h);l(this,S);l(this,A);l(this,X);l(this,se);l(this,Ie);l(this,Z);l(this,Ne);l(this,st);l(this,B);l(this,ge);l(this,be);l(this,at);l(this,O);l(this,_e);l(this,Ce,[]);l(this,Q);l(this,Re);l(this,N);l(this,Oe);l(this,Pe);l(this,Fe,Bt(void 0));l(this,Te,!1);l(this,ae,null);l(this,dt,0);l(this,lt,new Set);d(this,S,e.emitter),d(this,st,e.renderers),d(this,B,e.root??(typeof document<"u"?document:null)),d(this,ge,e.readyTargets),d(this,be,e.sendReady??Fi),d(this,at,e.onHeartbeatTimeout),d(this,O,e.log??Ci),d(this,_e,e.warn??Pi),d(this,Q,_i(e)),d(this,Re,e.dataMerge!==void 0?new kt({serverURL:e.dataMerge.serverURL,...e.dataMerge.apiRoute!==void 0?{apiRoute:e.dataMerge.apiRoute}:{},...e.dataMerge.depth!==void 0?{depth:e.dataMerge.depth}:{},...e.dataMerge.fetchFn!==void 0?{fetchFn:e.dataMerge.fetchFn}:{},log:(...n)=>{i(this,O).call(this,...n)}}):null),d(this,A,new wt),d(this,X,new xt({onStructuralChange:()=>{f(this,h,Kt).call(this)},onVisibilityChange:(n,r)=>{r&&i(this,se).notifyVisible(n)}},{...e.intersectionRootMargin!==void 0?{intersectionRootMargin:e.intersectionRootMargin}:{}})),d(this,se,new Lt(n=>{f(this,h,ur).call(this,n)},{...e.debounceMs!==void 0?{debounceMs:e.debounceMs}:{},...e.disableVisibilityGate!==void 0?{disableVisibilityGate:e.disableVisibilityGate}:{},...e.visibilityGateThreshold!==void 0?{visibilityGateThreshold:e.visibilityGateThreshold}:{},isVisible:n=>i(this,X).isVisible(n),getCacheSize:()=>i(this,A).elementCount,onFlush:n=>{f(this,h,fr).call(this,n)}})),d(this,Ie,new He(e.originMatcher,{onUpdate:(n,r)=>{f(this,h,or).call(this,n,r)},onDocumentEvent:(n,r)=>{f(this,h,ar).call(this,n,r)},onInvalid:(n,r)=>{if(n==="token"){let o=new Error(`Preview token rejected (origin: ${r})`);i(this,S).emit("error",{error:o,context:"token"})}i(this,O).call(this,"message rejected:",n,r)},...e.validateToken!==void 0?{validateToken:e.validateToken}:{}})),d(this,Z,new Et((n,r)=>{i(this,O).call(this,"connection",r,"\\u2192",n)})),d(this,Ne,new St({...e.heartbeatMs!==void 0?{timeoutMs:e.heartbeatMs}:{},onTimeout:()=>{f(this,h,pr).call(this)}}))}start(){if(i(this,Te))return!1;d(this,Te,!0);let e=i(this,B);if(e instanceof Document&&e.readyState==="loading"){let n=()=>{d(this,ae,null),f(this,h,Yt).call(this)};return d(this,ae,n),e.addEventListener("DOMContentLoaded",n,{once:!0}),!0}return f(this,h,Yt).call(this),!0}destroy(){if(!i(this,Te))return;if(d(this,Te,!1),i(this,ae)!==null){let n=i(this,B);n instanceof Document&&n.removeEventListener("DOMContentLoaded",i(this,ae)),d(this,ae,null),i(this,S).emit("destroy",{timestamp:Date.now()});return}for(let n of i(this,Ce))clearTimeout(n);i(this,Ce).length=0,i(this,Ne).stop(),i(this,Ie).detach(),i(this,X).stop(),i(this,se).destroy(),i(this,Re)?.destroy(),i(this,A).clear();let e=i(this,Z).status==="connected";i(this,Z).markDisconnected(),e&&(i(this,Q)?.announceDisconnected(),i(this,S).emit("disconnect",{reason:"destroy",timestamp:Date.now()})),i(this,Q)?.detach(),i(this,S).emit("destroy",{timestamp:Date.now()})}refreshCache(){f(this,h,Kt).call(this)}get status(){return i(this,Z).status}get cache(){return i(this,A)}get updateCount(){return i(this,dt)}get protocol(){return i(this,Fe)}};S=new WeakMap,A=new WeakMap,X=new WeakMap,se=new WeakMap,Ie=new WeakMap,Z=new WeakMap,Ne=new WeakMap,st=new WeakMap,B=new WeakMap,ge=new WeakMap,be=new WeakMap,at=new WeakMap,O=new WeakMap,_e=new WeakMap,Ce=new WeakMap,Q=new WeakMap,Re=new WeakMap,N=new WeakMap,Oe=new WeakMap,Pe=new WeakMap,Fe=new WeakMap,Te=new WeakMap,ae=new WeakMap,dt=new WeakMap,lt=new WeakMap,h=new WeakSet,Yt=function(){f(this,h,qt).call(this),i(this,X).start(i(this,B)instanceof Document?i(this,B).body:i(this,B)),i(this,Ie).attach(),f(this,h,rr).call(this);for(let e of Ni)if(e===0)i(this,be).call(this,i(this,ge));else{let n=setTimeout(()=>{i(this,be).call(this,i(this,ge))},e);i(this,Ce).push(n)}},qt=function(){let e=i(this,A).buildFromRoot(i(this,B));i(this,O).call(this,"cache built",e),i(this,S).emit("cacheRefresh",e);for(let n of i(this,A).values())i(this,X).observeElement(n.element)},Kt=function(){for(let e of i(this,A).values())i(this,X).unobserveElement(e.element),i(this,se).forget(e.element);f(this,h,qt).call(this)},rr=function(){i(this,S).emit("init",{timestamp:Date.now()})},ir=function(e){let n=Bt(e);n.negotiated!==i(this,Fe).negotiated&&(d(this,Fe,n),i(this,O).call(this,"protocol negotiated",`ours=${4}`,`theirs=${e}`,`negotiated=${n.negotiated}`))},or=function(e,n){i(this,Ne).kick(),e.protocolVersion!==void 0&&f(this,h,ir).call(this,e.protocolVersion),e.data!==void 0&&(i(this,Z).markConnected()&&(i(this,Q)?.announceConnected(),i(this,S).emit("connect",{origin:n,timestamp:Date.now()})),d(this,dt,i(this,dt)+1),e.locale!==void 0&&d(this,N,e.locale),e.fieldSchemaJSON!==void 0&&(d(this,Oe,e.fieldSchemaJSON),d(this,Pe,Vt(e.fieldSchemaJSON))),f(this,h,sr).call(this,e).then(r=>{if(r===null)return;let o={fields:r,...i(this,Oe)!==void 0?{schema:i(this,Oe)}:{},...e.globalSlug!==void 0?{globalSlug:e.globalSlug}:{},...e.collectionSlug!==void 0?{collectionSlug:e.collectionSlug}:{},...i(this,N)!==void 0?{locale:i(this,N)}:{}},s=!1;i(this,S).emit("beforeUpdate",{data:o,cancel:()=>{s=!0}}).then(()=>{s||f(this,h,dr).call(this,o)})}))},sr=async function(e){let n=e.data??{};if(i(this,Re)===null)return n;let r=await i(this,Re).merge({collectionSlug:e.collectionSlug,globalSlug:e.globalSlug,data:n,locale:i(this,N)});return r.status==="merged"?r.doc:r.status==="superseded"?null:n},ar=function(e,n){i(this,S).emit("documentSave",{timestamp:Date.now()})},dr=function(e){for(let[n,r]of i(this,A).entries()){let o=Hi(e.fields,n,i(this,N));if(o!==void 0)for(let s of r){let a={target:s,value:o,allFields:e.fields};i(this,se).schedule(a)}}f(this,h,lr).call(this,e.fields)},lr=function(e){if(i(this,A).elementCount===0)return;let n=new Set;for(let[r]of i(this,A).entries())n.add(r);for(let[r,o]of Object.entries(e)){if(i(this,lt).has(r)||Di.has(r)||!$i(o))continue;let s=Ui(r,i(this,N));n.has(r)||n.has(s)||(i(this,lt).add(r),i(this,_e).call(this,`[live-preview] update arrived for field "${r}" but no <\\u2026 data-payload-field="${s}"> 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.`))}},ur=function(e){let n=i(this,Pe)!==void 0?zt(i(this,Pe),e.target.fieldName):void 0,r=f(this,h,cr).call(this,e.target,n?.type);r==="text"&&e.target.explicitFieldType!==!0&&Oi(e.value)&&(r="richText");let o=i(this,st)[r],s=Bi(e.target.element),a={allFields:e.allFields,locale:i(this,N),schema:n};try{e.target.targetAttribute!==void 0?Yn(e.target.element,e.target.targetAttribute,e.value)==="blocked"&&i(this,_e).call(this,`[live-preview] refused to write field "${e.target.fieldName}" into attribute "${e.target.targetAttribute}" (unsafe attribute or value)`):o?o.render(e.target,e.value,a):i(this,O).call(this,"no renderer for",r)}catch(u){let m=u instanceof Error?u:new Error(String(u));i(this,S).emit("error",{error:m,context:"renderer"});return}i(this,S).emit("elementUpdate",{element:e.target.element,fieldName:e.target.fieldName,previousValue:s,nextValue:e.value})},cr=function(e,n){if(e.explicitFieldType)return e.fieldType;if(n!==void 0){let r=Wt(n);if(r!==void 0)return r}return e.fieldType},fr=function(e){e.applied===0&&e.deferred===0||(e.applied>0&&i(this,Q)?.announceUpdate(e.applied),i(this,S).emit("afterUpdate",{data:{fields:{},...i(this,N)!==void 0?{locale:i(this,N)}:{}},updatedCount:e.applied,durationMs:e.durationMs}))},pr=function(){var e;i(this,Z).markDisconnected()&&(i(this,Q)?.announceDisconnected(),i(this,S).emit("disconnect",{reason:"timeout",timestamp:Date.now()}));try{(e=i(this,at))==null||e.call(this)}catch(n){i(this,O).call(this,"onHeartbeatTimeout hook threw:",n)}i(this,be).call(this,i(this,ge))};function _i(t){return t.enableA11y===!1?null:t.a11yLocale!==void 0?new rt(t.a11yLocale):new rt}function Ci(){}function Oi(t){if(typeof t!="object"||t===null||!("root"in t))return!1;let e=t.root;return typeof e!="object"||e===null?!1:Array.isArray(e.children)}function Pi(...t){typeof console<"u"&&typeof console.warn=="function"&&console.warn(...t)}function Fi(t){if(typeof window>"u")return;let e=[];window.parent!==window&&e.push(window.parent),window.opener instanceof Window&&e.push(window.opener),He.sendReady(e,t)}var mr=new Set(["__proto__","prototype","constructor"]),Di=new Set(["id","_id","createdAt","updatedAt","createdBy","updatedBy","_status","globalType","collection","locale","localized"]);function $i(t){return t==null?!1:typeof t=="string"||typeof t=="number"||typeof t=="boolean"||typeof t=="bigint"}function Ui(t,e){if(!e)return t;let n=`_${e}`;return t.endsWith(n)?t.slice(0,-n.length):t}function Hi(t,e,n){let r=nr(t,e);if(r!==void 0)return r;if(e.includes(".")){let o=e.split("."),s=t;for(let a of o){if(mr.has(a)||s===null||typeof s!="object")return;s=s[a]}if(s!==void 0)return s}if(n!==void 0){let o=nr(t,`${e}_${n}`);if(o!==void 0)return o}}function nr(t,e){if(!mr.has(e)&&Object.prototype.hasOwnProperty.call(t,e))return t[e]}function Bi(t){return t.tagName==="INPUT"||t.tagName==="TEXTAREA"?t.value:t.tagName==="IMG"?t.src:t.textContent}function ut(){if(typeof window>"u")return!1;try{return window.self!==window.top}catch{return!0}}function Jt(){return typeof window>"u"?!1:window.opener!=null}function Xt(){return ut()||Jt()}function hr(){let t=ji();if(t!==void 0)return t!=="production";let e=Vi();if(e!==void 0)return e;if(typeof window<"u"){let n=window.location.hostname;if(n==="localhost"||n==="127.0.0.1")return!0}return!1}function yr(t){if(typeof process<"u"){let n=process.env[t];if(typeof n=="string"&&n.length>0)return n}let e=void 0;if(e){let n=e[t];if(typeof n=="string"&&n.length>0)return n}}function ji(){if(typeof process>"u")return;let t="production";return typeof t=="string"?t:void 0}function Vi(){let t=void 0;if(!t)return;let e=t.DEV;return typeof e=="boolean"?e:void 0}var zi=/^https?:\\/\\/(localhost|127\\.0\\.0\\.1)(?::\\d+)?$/i,Gi=/^https?:\\/\\/[^/?#\\s]+$/i,Wi=["PAYLOAD_ADMIN_ORIGIN","PUBLIC_PAYLOAD_ADMIN_ORIGIN","NEXT_PUBLIC_PAYLOAD_ADMIN_ORIGIN"],j,V,de,ct,P,Nt=class{constructor(e={}){l(this,j);l(this,V);l(this,de);l(this,ct);l(this,P);let n=new Set;for(let a of e.additionalOrigins??[]){let u=gr(a);u!==void 0&&n.add(u)}for(let a of Wi){let u=yr(a);if(u!==void 0)for(let m of u.split(",")){let T=gr(m);T!==void 0&&n.add(T)}}d(this,j,n);let r=e.enableReferrerDetection??!0,o;if(r){let a=e.referrer??(typeof document<"u"?document.referrer:"");if(a.length>0)try{let u=new URL(a).origin;u&&u!=="null"&&(o=u)}catch{}}d(this,V,o),d(this,ct,o!==void 0);let s=(e.enableLocalhostMatching??!0)&&(e.forceDevMode??hr());d(this,de,s)}matches(e){return e.length===0||e==="null"?!1:i(this,P)!==void 0?e===i(this,P):!!(i(this,j).has(e)||i(this,j).size===0&&i(this,V)!==void 0&&e===i(this,V)||i(this,de)&&zi.test(e))}lockOrigin(e){return this.matches(e)?(d(this,P,e),!0):!1}unlockOrigin(){let e=i(this,P);return d(this,P,void 0),e}get lockedOrigin(){return i(this,P)}enumerate(){if(i(this,P)!==void 0)return[i(this,P)];let e=new Set(i(this,j));if(i(this,j).size===0&&i(this,V)!==void 0&&e.add(i(this,V)),i(this,de))for(let n of Yi)e.add(`http://localhost:${String(n)}`),e.add(`http://127.0.0.1:${String(n)}`);return[...e]}get referrerWasAvailable(){return i(this,ct)}get isProductionUnconfigured(){return!(!ut()||i(this,j).size>0||i(this,de)||i(this,V)!==void 0)}get isReferrerOnlyTrust(){return i(this,j).size>0||i(this,de)?!1:i(this,V)!==void 0}};j=new WeakMap,V=new WeakMap,de=new WeakMap,ct=new WeakMap,P=new WeakMap;var Yi=[3e3,3001,3333,4e3,4321,5e3,5173,5174,8e3,8080,8888,9e3];function gr(t){let e=t.trim();if(e.length!==0)try{let n=new URL(e);return n.protocol!=="http:"&&n.protocol!=="https:"||!Gi.test(n.origin)?void 0:n.origin}catch{return}}var br={name:"payload-live-preview",version:"1.0.2",description:"Live preview for Payload CMS in Astro and any SSR/static frontend (SvelteKit, Nuxt, Next.js, plain HTML). Patches the DOM live, no rebuild.",author:"relative23",license:"MIT",type:"module",main:"./dist/index.cjs",module:"./dist/index.js",types:"./dist/index.d.ts",exports:{".":{import:{types:"./dist/index.d.ts",default:"./dist/index.js"},require:{types:"./dist/index.d.cts",default:"./dist/index.cjs"}},"./core":{import:{types:"./dist/core.d.ts",default:"./dist/core.js"},require:{types:"./dist/core.d.cts",default:"./dist/core.cjs"}},"./astro":{import:{types:"./dist/adapters/astro/index.d.ts",default:"./dist/adapters/astro/index.js"}},"./nextjs":{import:{types:"./dist/adapters/nextjs/index.d.ts",default:"./dist/adapters/nextjs/index.js"}},"./sveltekit":{import:{types:"./dist/adapters/sveltekit/index.d.ts",default:"./dist/adapters/sveltekit/index.js"}},"./nuxt":{import:{types:"./dist/adapters/nuxt/index.d.ts",default:"./dist/adapters/nuxt/index.js"}},"./codegen":{import:{types:"./dist/codegen.d.ts",default:"./dist/codegen.js"},require:{types:"./dist/codegen.d.cts",default:"./dist/codegen.cjs"}},"./codegen/astro":{import:{types:"./dist/codegen-astro.d.ts",default:"./dist/codegen-astro.js"}},"./payload":{import:{types:"./dist/payload.d.ts",default:"./dist/payload.js"},require:{types:"./dist/payload.d.cts",default:"./dist/payload.cjs"}},"./astro/RichText.astro":"./dist/adapters/astro/RichText.astro","./astro/middleware-entry":{import:{types:"./dist/adapters/astro/middleware-entry.d.ts",default:"./dist/adapters/astro/middleware-entry.js"}}},bin:{"pll-codegen":"./dist/codegen-cli.js"},files:["dist","README.md","LICENSE"],sideEffects:!1,scripts:{prepare:"npm run build:runtime","build:runtime":"tsx scripts/build-runtime.ts",build:"npm run build:runtime && tsup && npm run build:assets","build:assets":`node -e "require(\'node:fs\').copyFileSync(\'src/adapters/astro/RichText.astro\',\'dist/adapters/astro/RichText.astro\')"`,dev:"tsup --watch",test:"vitest run","test:watch":"vitest","test:unit":"vitest run tests/unit","test:integration":"vitest run tests/integration","test:e2e":"playwright test","test:bench":"vitest bench tests/benchmarks","test:coverage":"vitest run --coverage",typecheck:"tsc --noEmit",lint:"eslint .","lint:fix":"eslint . --fix",format:\'prettier --write "src/**/*.ts" "tests/**/*.ts"\',"format:check":\'prettier --check "src/**/*.ts" "tests/**/*.ts"\',check:"npm run typecheck && npm run lint && npm run test",prepublishOnly:"npm run check && npm run build",changeset:"changeset",version:"changeset version",release:"npm run build && changeset publish"},devDependencies:{"@changesets/cli":"^2.31.0","@eslint/js":"^10.0.1","@playwright/test":"^1.61.1","@types/node":"^22.20.1","@vitest/coverage-v8":"^4.1.10",esbuild:"^0.28.1",eslint:"^10.7.0",globals:"^17.7.0",jsdom:"^29.1.1",prettier:"^3.9.5","ts-morph":"^28.0.0",tsup:"^8.5.1",tsx:"^4.23.0",typescript:"^5.9.3","typescript-eslint":"^8.63.0",vitest:"^4.1.10"},keywords:["astro","astro-payload","astro-cms","astro-integration","astro-live-preview","payload","payload-cms","payload-live-preview","payload-plugin","live-preview","preview","cms","headless","headless-cms","lexical","sveltekit","nuxt","nextjs","ssr","framework-agnostic"],peerDependencies:{astro:">=4.0.0 <8.0.0","ts-morph":"^28.0.0"},peerDependenciesMeta:{astro:{optional:!0},"ts-morph":{optional:!0}},engines:{node:">=20.19.0"},publishConfig:{access:"public",provenance:!0},repository:{type:"git",url:"https://github.com/relative23/payload-live-preview.git"},bugs:{url:"https://github.com/relative23/payload-live-preview/issues"},homepage:"https://github.com/relative23/payload-live-preview#readme"};var Rr=br.version;var Zt=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"]),wr=new Set(["script","style","iframe","object","embed","link","meta","base","form","input","button","select","textarea","svg","math","template","frame","frameset","noframes","noscript"]),xr=new Set(["id","class","lang","dir","title","role","tabindex"]),Ki="aria-",Ji="data-",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"])},vr=new Set(["href","src","cite","poster"]),en=class extends Error{constructor(){super(...arguments);$n(this,"name","SanitizerEnvironmentError")}};function Xi(t){if(!t){let r=new Map;for(let[o,s]of Object.entries(Qt))r.set(o,s);return{allowedTags:Zt,attrByTag:r}}let e=new Set(Zt);for(let r of t.additionalAllowedTags??[])e.add(r);let n=new Map;for(let[r,o]of Object.entries(Qt))n.set(r,o);for(let[r,o]of Object.entries(t.additionalAllowedAttributes??{})){let s=n.get(r),a=new Set(s??[]);for(let u of o)a.add(u);n.set(r,a)}return{allowedTags:e,attrByTag:n}}var Tr;function z(t,e){let n=Sr();if(!n)throw new en("sanitizeHtml requires a DOM. Inject one via setSanitizerDocument() for SSR (linkedom, jsdom, happy-dom, \\u2026) or use the plain-text path on the server.");if(t==="")return"";let r=Xi(e),o=n.createElement("template");return o.innerHTML=t,tn(o.content,r),o.innerHTML}function Sr(){if(Tr)return Tr;if(!(typeof document>"u"))return document}function Er(){return Sr()!==void 0}function tn(t,e){for(let n of Array.from(t.childNodes))n.nodeType===Node.ELEMENT_NODE?Zi(n,e):n.nodeType===Node.COMMENT_NODE&&n.remove()}function Zi(t,e){let n=t.tagName.toLowerCase();if(wr.has(n)){t.remove();return}if(!e.allowedTags.has(n)){tn(t,e);let r=t.parentNode;if(r){for(;t.firstChild;)r.insertBefore(t.firstChild,t);t.remove()}return}Qi(t,n,e),n==="a"&&to(t),tn(t,e)}function Qi(t,e,n){let r=n.attrByTag.get(e);for(let o of Array.from(t.attributes)){let s=o.name.toLowerCase();if(s.startsWith("on")){t.removeAttribute(o.name);continue}if(s==="style"){t.removeAttribute(o.name);continue}if(!(xr.has(s)||s.startsWith(Ki)||s.startsWith(Ji))){if(r?.has(s)){(vr.has(s)&&!b(o.value)||s==="srcset"&&!eo(o.value))&&t.removeAttribute(o.name);continue}t.removeAttribute(o.name)}}}function eo(t){let e=t.split(",");for(let n of e){let r=n.trim();if(r.length===0)continue;let o=r.split(/\\s+/,1)[0];if(o===void 0||o.length===0||!b(o))return!1}return!0}function to(t){let e=t.getAttribute("href");e&&At(e)&&(t.setAttribute("rel","noopener noreferrer"),t.hasAttribute("target")||t.setAttribute("target","_blank"))}var qs=Object.freeze({allowedTags:Zt,removeCompletely:wr,globalAttributes:xr,attributesByTag:Qt,urlAttributes:vr});var kr=new Map;function p(t,e){kr.set(t,e)}function Ar(t){return kr.get(t)}var no={1:"left",2:"center",3:"right",4:"justify"},ro=new Set(["left","center","right","justify","start","end"]);function nn(t){let e=t.format;if(typeof e=="string"&&ro.has(e))return e;if(typeof e=="number"){let n=no[e];if(n!==void 0)return n}}function rn(t){let e=t.indent;return typeof e=="number"&&e>0?e:0}function ee(t){return t.direction==="rtl"?\' dir="rtl"\':t.direction==="ltr"?\' dir="ltr"\':""}function G(t){let e=nn(t),n=rn(t),r=[];return e!==void 0&&r.push(`text-align:${e}`),n>0&&r.push(`padding-inline-start:${String(n*40)}px`),r.length===0?"":` style="${r.join(";")}"`}var io=Object.freeze({"&":"&amp;","<":"&lt;",">":"&gt;",\'"\':"&quot;","\'":"&#x27;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"}),oo=/[&<>"\'/`=]/g;function y(t){return t===""?"":t.replace(oo,e=>io[e])}function Lr(t){return t.replace(/[\'"()\\\\]/g,"\\\\$&")}var so=Object.freeze({"&":"&amp;","<":"&lt;",">":"&gt;",\'"\':"&quot;","\'":"&#x27;"}),ao=/[&<>"\']/g;function L(t){return t===""?"":t.replace(ao,e=>so[e])}function _t(t){return y(t).replace(/\\r\\n|\\r|\\n/g,"<br>")}var te={BOLD:1,ITALIC:2,STRIKETHROUGH:4,UNDERLINE:8,CODE:16,SUBSCRIPT:32,SUPERSCRIPT:64,HIGHLIGHT:128};var on=t=>{let e=typeof t.text=="string"?t.text:"",n=y(e),r=typeof t.format=="number"?t.format:0;return(r&te.CODE)!==0&&(n=`<code>${n}</code>`),(r&te.BOLD)!==0&&(n=`<strong>${n}</strong>`),(r&te.ITALIC)!==0&&(n=`<em>${n}</em>`),(r&te.UNDERLINE)!==0&&(n=`<u>${n}</u>`),(r&te.STRIKETHROUGH)!==0&&(n=`<s>${n}</s>`),(r&te.SUBSCRIPT)!==0&&(n=`<sub>${n}</sub>`),(r&te.SUPERSCRIPT)!==0&&(n=`<sup>${n}</sup>`),(r&te.HIGHLIGHT)!==0&&(n=`<mark>${n}</mark>`),n};p("text",on);var sn=(t,e)=>{let n=e.renderChildren(t.children??[]);return`<p${ee(t)}${G(t)}>${n}</p>`};p("paragraph",sn);var lo=new Set(["h1","h2","h3","h4","h5","h6"]),an=(t,e)=>{let n=typeof t.tag=="string"?t.tag.toLowerCase():"h2",r=lo.has(n)?n:"h2",o=e.renderChildren(t.children??[]);return`<${r}${ee(t)}${G(t)}>${o}</${r}>`};p("heading",an);var dn=(t,e)=>{let n=typeof t.listType=="string"?t.listType:"bullet",r=n==="number"?"ol":"ul",o=n==="number"&&typeof t.start=="number"&&t.start>1?` start="${String(t.start)}"`:"",s=n==="check"?\' role="list"\':"",a=e.renderChildren(t.children??[]);return`<${r}${ee(t)}${G(t)}${o}${s}>${a}</${r}>`},ln=(t,e)=>{let n=e.renderChildren(t.children??[]);if(typeof t.checked=="boolean")return`<li role="checkbox" aria-checked="${t.checked?"true":"false"}"${G(t)}>${n}</li>`;let r=typeof t.value=="number"?` value="${y(String(t.value))}"`:"";return`<li${ee(t)}${G(t)}${r}>${n}</li>`};p("list",dn);p("listitem",ln);var ft=(t,e)=>{let n=typeof t.url=="string"?t.url:"",r=e.renderChildren(t.children??[]);if(n.length===0||!b(n))return r;let o=At(n)?\' target="_blank" rel="noopener noreferrer"\':uo(t),s=typeof t.title=="string"?` title="${y(t.title)}"`:"";return`<a href="${L(n)}"${o}${s}>${r}</a>`};function uo(t){let e=typeof t.target=="string"?t.target:"";if(e.length===0)return"";let n=y(e);return e==="_blank"?\' target="_blank" rel="noopener noreferrer"\':` target="${n}"`}p("link",ft);p("autolink",ft);var un=(t,e)=>{let n=e.renderChildren(t.children??[]);return`<blockquote${ee(t)}${G(t)}>${n}</blockquote>`};p("quote",un);var cn=t=>{let e=Ir(typeof t.language=="string"?t.language:""),n=Mr(t);return`<pre><code${e===""?"":` class="language-${e}"`}>${y(n)}</code></pre>`},fn=t=>{let e=typeof t.text=="string"?t.text:"";return`<span${typeof t.highlightType=="string"?` class="token-${Ir(t.highlightType)}"`:""}>${y(e)}</span>`};p("code",cn);p("code-highlight",fn);function Mr(t){if(typeof t.text=="string")return t.text;if(!t.children)return"";let e="";for(let n of t.children)e+=Mr(n);return e}function Ir(t){return t.replace(/[^a-zA-Z0-9_-]/g,"")}var pn=()=>"<br>",mn=()=>"<hr>",hn=()=>" ";p("linebreak",pn);p("horizontalrule",mn);p("tab",hn);var yn=t=>{let e=co(t);if(e===void 0)return"";let n=e.url;if(typeof n!="string"||!b(n))return"";let r=typeof e.mimeType=="string"?e.mimeType:"";return r.startsWith("video/")?po(e,n):r.startsWith("audio/")?mo(e,n):r===""||r.startsWith("image/")?fo(e,n):ho(e,n)};p("upload",yn);function co(t){let e=t.value;if(!(typeof e!="object"||e===null))return e}function fo(t,e){let n=typeof t.alt=="string"?y(t.alt):"",r=typeof t.width=="number"?` width="${String(t.width)}"`:"",o=typeof t.height=="number"?` height="${String(t.height)}"`:"";return`<img src="${L(e)}" alt="${n}"${r}${o} loading="lazy" decoding="async">`}function po(t,e){let n=typeof t.width=="number"?` width="${String(t.width)}"`:"",r=typeof t.height=="number"?` height="${String(t.height)}"`:"",o=typeof t.mimeType=="string"?` type="${L(t.mimeType)}"`:"";return`<video controls${n}${r}><source src="${L(e)}"${o}></video>`}function mo(t,e){let n=typeof t.mimeType=="string"?` type="${L(t.mimeType)}"`:"";return`<audio controls><source src="${L(e)}"${n}></audio>`}function ho(t,e){let n=typeof t.filename=="string"?y(t.filename):y(e);return`<a href="${L(e)}" target="_blank" rel="noopener noreferrer">${n}</a>`}var gn=t=>{let e=typeof t.relationTo=="string"?t.relationTo:"",n=yo(t),r=go(n,e),o=y(r),s=e===""?"":` data-relation-to="${y(e)}"`,a=n?.url;return typeof a=="string"&&b(a)?`<a href="${L(a)}"${s}>${o}</a>`:`<span${s}>${o}</span>`};p("relationship",gn);function yo(t){let e=t.value;if(!(typeof e!="object"||e===null))return e}function go(t,e){return t===void 0?e===""?"#":`#${e}`:typeof t.title=="string"&&t.title.length>0?t.title:typeof t.name=="string"&&t.name.length>0?t.name:typeof t.slug=="string"&&t.slug.length>0?t.slug:t.id!==void 0?String(t.id):e===""?"#":`#${e}`}var bo=new Map;function bn(t){return bo.get(t)}var Rn=(t,e)=>{let n=Ro(t),r=typeof n.blockType=="string"?n.blockType:"",o=Nr(r);if(r!==""){let u=bn(r)??bn(o);if(u)return u(n,{renderChildren:e.renderChildren})}let s=[];o!==""&&s.push(`data-block-type="${y(o)}"`);for(let[u,m]of Object.entries(n)){if(u==="blockType"||u==="id"||m==null)continue;let T=typeof m=="string"||typeof m=="number"||typeof m=="boolean"?String(m):JSON.stringify(m);s.push(`data-block-${Nr(u)}="${y(T)}"`)}return`<div${s.length===0?"":` ${s.join(" ")}`}></div>`};p("block",Rn);function Ro(t){let e=t.fields;return typeof e!="object"||e===null?{}:e}function Nr(t){return t.replace(/[^a-zA-Z0-9_-]/g,"-").toLowerCase()}p("text",on);p("paragraph",sn);p("heading",an);p("list",dn);p("listitem",ln);p("link",ft);p("autolink",ft);p("quote",un);p("code",cn);p("code-highlight",fn);p("linebreak",pn);p("horizontalrule",mn);p("tab",hn);p("upload",yn);p("relationship",gn);p("block",Rn);var To={renderChildren:Tn,resolveAlignment:nn,resolveIndent:rn};function le(t){if(typeof t!="object"||t===null||!("root"in t))return!1;let e=t.root;return typeof e!="object"||e===null||!("children"in e)?!1:Array.isArray(e.children)}function _r(t,e={}){if(!le(t))return"";let n=Tn(t.root.children);return e.sanitize===!1||!Er()?n:z(n)}function Ct(t){return le(t)?t.root.children.map(Cr).join(`\n`).trim():""}function Tn(t){let e="";for(let n of t)e+=wo(n);return e}function wo(t){let e=Ar(t.type);return e?e(t,To):t.children!==void 0?Tn(t.children):""}function Cr(t){if(typeof t.text=="string")return t.text;if(t.type==="linebreak")return`\n`;if(t.children===void 0)return"";let e="";for(let n of t.children)e+=Cr(n);return e}var wn=new Map;function Or(t=[]){for(let n of t)wn.set(n.name,n);let e={};for(let[n,r]of wn)e[n]=r;return Object.freeze(e)}function g(t){wn.set(t.name,t)}var xo="data-payload-text",Pr=new WeakSet,xn={name:"text",render(t,e){let n=t.element,r=Eo(e);if(n.tagName==="INPUT"||n.tagName==="TEXTAREA"){n.value=r;return}if(vo(n)&&!n.hasAttribute(xo)){So(n,t.fieldName);return}if(r.includes(`\n`)||r.includes("\\r")){n.innerHTML=_t(r);return}n.textContent=r}};function vo(t){return t.firstElementChild!==null}function So(t,e){Pr.has(t)||(Pr.add(t),console.warn(`[live-preview] Skipping text update for "${e}" \\u2014 the bound <${t.tagName.toLowerCase()}> has structured child elements. Either move data-payload-field to the element whose textContent is the field value, or opt in with data-payload-text to replace the structure.`))}function Eo(t){return t==null?"":le(t)?Ct(t):typeof t=="string"?t:typeof t=="number"||typeof t=="boolean"?String(t):JSON.stringify(t)}g(xn);function w(t){if(t==null)return"";if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean"||typeof t=="bigint")return String(t);try{return JSON.stringify(t)}catch{return""}}var vn={name:"textarea",render(t,e){let n=t.element,r=le(e)?Ct(e):w(e);if(n.tagName==="INPUT"||n.tagName==="TEXTAREA"){n.value=r;return}n.innerHTML=_t(r)}};g(vn);var Sn={name:"richText",render(t,e){if(le(e)){t.element.innerHTML=_r(e);return}typeof e=="string"&&(t.element.innerHTML=z(e))}};g(Sn);var En={name:"html",render(t,e){if(e==null){t.element.textContent="";return}let n=typeof e=="string"?e:w(e);t.element.innerHTML=z(n)}};g(En);var pt={name:"url",render(t,e,n){let r=t.element,o=w(e);if(r.tagName==="A"){let s=r,a=t.hrefField,u=a?n.allFields[a]:e;typeof u=="string"&&b(u)&&(s.href=u),s.textContent=o;return}if(r.tagName==="INPUT"||r.tagName==="TEXTAREA"){r.value=o;return}r.textContent=o}};g(pt);g({...pt,name:"email"});var kn={name:"image",render(t,e,n){let r=t.element,o=ko(e),s=Ao(o,e);if(s!==void 0){if(r.tagName==="IMG"){let a=r;a.src=s;let u=Lo(o,t.altField,n.allFields);u!==void 0&&(a.alt=u);return}r.style.backgroundImage=`url(\'${Lr(s)}\')`}}};function ko(t){if(!(typeof t!="object"||t===null))return t}function Ao(t,e){if(t?.url!==void 0&&b(t.url))return t.url;if(typeof e=="string"&&b(e))return e}function Lo(t,e,n){if(t?.alt!==void 0)return t.alt;if(e!==void 0){let r=n[e];if(typeof r=="string")return r}}g(kn);var An={name:"upload",render(t,e){let n=t.element,r=Mo(e);if(r===void 0)return;let o=r.url;if(typeof o!="string"||!b(o))return;if(n.tagName==="IMG"){let a=n;a.src=o,r.alt!==void 0&&(a.alt=r.alt);return}if(n.tagName==="A"){let a=n;a.href=o,a.textContent=r.filename??o;return}let s=r.filename!==void 0?y(r.filename):y(o);n.innerHTML=`<a href="${L(o)}">${s}</a>`}};function Mo(t){if(!(typeof t!="object"||t===null))return t}g(An);var Ln={name:"relationship",render(t,e){let n=t.element,o=Io(e).join(", ");if(n.tagName==="A"&&!Array.isArray(e)){let s=n,a=e?.url;typeof a=="string"&&b(a)&&(s.href=a),s.textContent=o;return}n.textContent=o}};function Io(t){return t==null?[""]:Array.isArray(t)?t.map(Fr):[Fr(t)]}function Fr(t){if(typeof t=="object"&&t!==null){let e=t;return typeof e.title=="string"&&e.title.length>0?e.title:typeof e.name=="string"&&e.name.length>0?e.name:typeof e.slug=="string"&&e.slug.length>0?e.slug:e.id!==void 0?String(e.id):""}return w(t)}g(Ln);var mt={name:"select",render(t,e){let n=t.element,r=Dr(e);if(n.tagName==="SELECT"){n.value=r;return}if(n.tagName==="INPUT"&&n.type==="radio"){let o=n;o.checked=o.value===r;return}n.textContent=r}};function Dr(t){return Array.isArray(t)?t.map(e=>Dr(e)).join(", "):w(t)}g(mt);g({...mt,name:"radio"});var Mn={name:"checkbox",render(t,e){let n=t.element,r=!!e;if(n.tagName==="INPUT"&&n.type==="checkbox"){n.checked=r;return}if(n.hasAttribute("aria-checked")){n.setAttribute("aria-checked",r?"true":"false");return}n.textContent=r?"true":"false"}};g(Mn);var ht=new Map,yt=new Map,No=64,_o=No;function $r(t,e){let n=Hr(t,e),r=ht.get(n);if(r!==void 0)return ht.delete(n),ht.set(n,r),r;let o=new Intl.NumberFormat(t,e);return ht.set(n,o),Br(ht),o}function Ur(t,e){let n=Hr(t,e),r=yt.get(n);if(r!==void 0)return yt.delete(n),yt.set(n,r),r;let o=new Intl.DateTimeFormat(t,e);return yt.set(n,o),Br(yt),o}function Hr(t,e){let n=t??"";if(e==null)return n;let r=In(e);return r==="{}"?n:`${n}|${r}`}function In(t){if(t===null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t))return`[${t.map(o=>In(o)).join(",")}]`;let e=t,n=Object.keys(e).sort(),r=[];for(let o of n){let s=e[o];s!==void 0&&r.push(`${JSON.stringify(o)}:${In(s)}`)}return`{${r.join(",")}}`}function Br(t){for(;t.size>_o;){let e=t.keys().next().value;if(e===void 0)break;t.delete(e)}}var Nn={name:"date",render(t,e,n){let r=t.element;if(e==null||e===""){r.tagName==="INPUT"?r.value="":(r.tagName==="TIME"&&r.removeAttribute("datetime"),r.textContent="");return}let o=typeof e=="string"?e:w(e),s=new Date(o),a=!Number.isNaN(s.getTime());if(r.tagName==="INPUT"){r.value=a?Co(r.type,s):o;return}if(r.tagName==="TIME"){r.setAttribute("datetime",a?s.toISOString():o),r.textContent=a?jr(s,n):o;return}r.textContent=a?jr(s,n):o}};function jr(t,e){let n=e.locale??Me();try{return Ur(n,{dateStyle:"medium",timeStyle:"short"}).format(t)}catch{return t.toISOString()}}function Co(t,e){return t==="date"?e.toISOString().slice(0,10):t==="datetime-local"?e.toISOString().slice(0,16):e.toISOString()}g(Nn);var _n={name:"number",render(t,e,n){let r=t.element;if(e==null||e===""){r.tagName==="INPUT"?r.value="":r.textContent="";return}let o=typeof e=="number"?e:Number(w(e));if(Number.isNaN(o)){r.textContent=w(e);return}if(r.tagName==="INPUT"){r.value=String(o);return}r.textContent=Oo(o,n)}};function Oo(t,e){let n=e.locale??Me();try{return $r(n).format(t)}catch{return String(t)}}g(_n);var gt={name:"array",render(t,e){let n=t.element;if(!Array.isArray(e))return;let r=t.arrayTemplate;if(r!==void 0&&r.length>0){let s=Po(r,e);n.innerHTML=z(s);return}let o=t.arraySeparator??", ";n.textContent=e.map($o).join(o)}};function Po(t,e){let n="";for(let r=0;r<e.length;r+=1)n+=Fo(t,e[r],r);return n}function Fo(t,e,n){let r=t;if(typeof e=="object"&&e!==null)for(let[o,s]of Object.entries(e)){let a=new RegExp(`\\\\{\\\\{${Do(o)}\\\\}\\\\}`,"g");r=r.replace(a,y(w(s)))}else r=r.replace(/\\{\\{value\\}\\}/g,y(w(e)));return r=r.replace(/\\{\\{index\\}\\}/g,String(n)),r}function Do(t){return t.replace(/[.*+?^${}()|[\\]\\\\]/g,"\\\\$&")}function $o(t){return w(t)}g(gt);g({...gt,name:"blocks"});function Uo(){return typeof document>"u"?!1:typeof document.startViewTransition=="function"}async function Vr(t){if(!Uo()){t();return}let n=document.startViewTransition.call(document,t);try{await n.finished}catch{}}var Wr="data-payload-key",bt="data-payload-nested-key",Pn="data-payload-nested-template";function Yr(){return new WeakMap}function Pt(t){let{template:e,container:n,patches:r,store:o}=t,s=Bo(n,o),a=[],u=[],m=[],T=[],W=[];for(let c of r)c.kind==="remove"?a.push(c):c.kind==="insert"?u.push(c):c.kind==="move"?m.push(c):c.kind==="update"?T.push(c):W.push(c);a.sort((c,R)=>Ot(R)-Ot(c));for(let c of a){if(c.kind!=="remove")continue;n.children[c.index]?.remove(),jo(s,c.value)}for(let c of W){if(c.kind!=="replace")continue;let R=n.children[c.index],v=On(e,c.value,c.index);!R||!v||(zr(v,c.value,o),n.replaceChild(v,R),Cn(s,c.value))}for(let c of T){if(c.kind!=="update")continue;let R=n.children[c.index],v=On(e,c.value,c.index);!R||!v||(Ho(R,v,c.value,s,o),n.replaceChild(v,R),Cn(s,c.value))}u.sort((c,R)=>Ot(c)-Ot(R));for(let c of u){if(c.kind!=="insert")continue;let R=n.children[c.index]??null,v=On(e,c.value,c.index);v&&(zr(v,c.value,o),n.insertBefore(v,R),Cn(s,c.value))}for(let c of m){if(c.kind!=="move")continue;let R=Rt(c.value),v=R!==void 0?Vo(n,R):null;if(!v)continue;let De=n.children[c.to]??null;v!==De&&n.insertBefore(v,De)}}function zr(t,e,n){let r=t.querySelectorAll(`[${bt}]`);for(let o of Array.from(r)){let s=o.getAttribute(bt);if(s===null)continue;let a=o.getAttribute(Pn);if(!a)continue;let u=Fn(e,s);if(u===void 0)continue;let m=ot([],u);m.length!==0&&Pt({template:a,container:o,patches:m,nextItems:u,store:n})}}function Ho(t,e,n,r,o){let s=t.querySelectorAll(`[${bt}]`);if(s.length===0)return;let a=Rt(n),u=a!==void 0?r.get(a):void 0;for(let m of Array.from(s)){let T=m.getAttribute(bt);if(T===null)continue;let W=e.querySelector(`[${bt}="${qr(T)}"]`);if(!W)continue;W.replaceWith(m);let c=m.getAttribute(Pn)??W.getAttribute(Pn);if(!c)continue;let R=Fn(n,T)??[],v=Fn(u,T)??[],De=ot(v,R);De.length!==0&&Pt({template:c,container:m,patches:De,nextItems:R,store:o})}}function Fn(t,e){if(typeof t!="object"||t===null)return;let n=t[e];if(Array.isArray(n))return n}function Bo(t,e){let n=e.get(t);return n||(n=new Map,e.set(t,n)),n}function Cn(t,e){let n=Rt(e);n!==void 0&&t.set(n,e)}function jo(t,e){let n=Rt(e);n!==void 0&&t.delete(n)}function Ot(t){return t.kind==="move"?t.to:t.index}function Rt(t){if(typeof t!="object"||t===null)return;let e=t.id;if(typeof e=="string"||typeof e=="number")return String(e)}function Vo(t,e){return t.querySelector(`[${Wr}="${qr(e)}"]`)}function qr(t){let e=globalThis.CSS;return e?.escape?e.escape(t):t.replace(/[^a-zA-Z0-9_-]/g,"\\\\$&")}function On(t,e,n){if(typeof document>"u")return null;let r=zo(t,e,n),o=z(r),s=document.createElement("template");s.innerHTML=o;let a=s.content.firstElementChild;if(!a)return null;let u=Rt(e);return u!==void 0&&a.setAttribute(Wr,u),a}function zo(t,e,n){let r=t;if(typeof e=="object"&&e!==null)for(let[o,s]of Object.entries(e)){let a=new RegExp(`\\\\{\\\\{${Go(o)}\\\\}\\\\}`,"g"),u=y(Gr(s));r=r.replace(a,()=>u)}else{let o=y(Gr(e));r=r.replace(/\\{\\{value\\}\\}/g,()=>o)}return r.replace(/\\{\\{index\\}\\}/g,String(n))}function Gr(t){return t==null?"":typeof t=="string"?t:typeof t=="number"||typeof t=="boolean"||typeof t=="bigint"?String(t):JSON.stringify(t)}function Go(t){return t.replace(/[.*+?^${}()|[\\]\\\\]/g,"\\\\$&")}function Kr(){let t=new WeakMap,e=new WeakSet,n=Yr();return{name:"structural-array",render(r,o){if(!Array.isArray(o))return;let s=r.element,a=r.arrayTemplate;if(a===void 0||a.length===0){Wo(e,s,r.fieldName);return}let u=t.get(s)??[],m=ot(u,o);if(m.length===0){t.set(s,o.slice());return}Vr(()=>{Pt({template:a,container:s,patches:m,nextItems:o,store:n})}),t.set(s,o.slice())}}}function Wo(t,e,n){t.has(e)||(t.add(e),console.warn(`[live-preview] Skipping structural update for "${n}" \\u2014 the <${e.tagName.toLowerCase()}> with data-payload-structural is missing data-payload-array-template. Add an inline template (e.g., data-payload-array-template="<li>{{label}}</li>") so the renderer can materialise new items.`))}var Yo=[xn,vn,Sn,En,pt,{...pt,name:"email"},kn,An,Ln,mt,{...mt,name:"radio"},Mn,Nn,_n,gt,{...gt,name:"blocks"}];function Jr(){return Or([...Yo,Kr()])}function qo(){if(typeof window>"u"||!Xt())return;let t=window.__livePreview;if(t!==void 0)return t;let e=Ko(),n=new Nt({additionalOrigins:e.additionalOrigins,enableReferrerDetection:!e.disableReferrerDetection,enableLocalhostMatching:!e.disableLocalhostMatching});n.isProductionUnconfigured?console.warn("[live-preview] No trusted origin could be detected. Set the PAYLOAD_ADMIN_ORIGIN env var or pass `allowedOrigins` to generateInlineScript()."):n.isReferrerOnlyTrust&&console.warn("[live-preview] Trusting the embedding page via document.referrer only \\u2014 any site that frames this page could post preview updates. Pass explicit `allowedOrigins` and serve a `frame-ancestors` CSP for production.");let r=new Tt,o=Jr(),s=new It({renderers:o,originMatcher:u=>n.matches(u),readyTargets:n.enumerate(),emitter:r,...typeof e.serverURL=="string"&&e.serverURL!==""?{dataMerge:{serverURL:e.serverURL,...typeof e.apiRoute=="string"?{apiRoute:e.apiRoute}:{},...typeof e.mergeDepth=="number"?{depth:e.mergeDepth}:{}}}:{},debounceMs:e.debounceMs,heartbeatMs:e.heartbeatMs,intersectionRootMargin:e.intersectionRootMargin,disableVisibilityGate:e.disableVisibilityGate,visibilityGateThreshold:e.visibilityGateThreshold,enableA11y:e.enableA11y,onHeartbeatTimeout:()=>{n.unlockOrigin()},...e.debug?{log:(...u)=>{console.debug("[live-preview]",...u)}}:{}});r.on("connect",u=>{n.lockOrigin(u.origin)}),s.start();let a=Object.freeze({version:Rr,destroy:()=>{s.destroy();let u=window;u.__livePreview===a&&delete u.__livePreview},refresh:()=>{s.refreshCache()},enumerateOrigins:()=>n.enumerate()});return Object.defineProperty(window,"__livePreview",{value:a,writable:!1,configurable:!0}),a}function Ko(){let t=typeof __LIVE_PREVIEW_CONFIG__>"u"?void 0:__LIVE_PREVIEW_CONFIG__;return t!==void 0?t:{additionalOrigins:[],serverURL:"",apiRoute:"/api",mergeDepth:1,debug:!1,debounceMs:50,enableA11y:!0,heartbeatMs:0,disableVisibilityGate:!1,visibilityGateThreshold:50,intersectionRootMargin:"200px",disableReferrerDetection:!1,disableLocalhostMatching:!1}}var Jo=typeof __INLINE_BUILD__>"u"?!1:__INLINE_BUILD__;Jo&&qo();var Pl={isInIframe:ut,isInPopup:Jt,isInPreviewContext:Xt};})();\n';
101
- var RUNTIME_BUILD_INFO = { generatedAt: "2026-07-11T19:02:27.899Z"};
102
-
103
- // src/inline/generator.ts
104
- var DEFAULT_DEBOUNCE_MS = 50;
105
- var DEFAULT_HEARTBEAT_MS = 0;
106
- var DEFAULT_VISIBILITY_GATE_THRESHOLD = 50;
107
- var DEFAULT_INTERSECTION_ROOT_MARGIN = "200px";
108
- function generateInlineScript(config = {}) {
109
- if (RUNTIME_SOURCE.length === 0) {
110
- throw new Error(
111
- "[live-preview] runtime.generated.ts is empty. Run `npm run build:runtime` before bundling."
112
- );
113
- }
114
- const configLiteral = JSON.stringify({
115
- additionalOrigins: config.allowedOrigins ?? [],
116
- serverURL: config.serverURL ?? "",
117
- apiRoute: config.apiRoute ?? "/api",
118
- mergeDepth: config.mergeDepth ?? 1,
119
- debug: config.debug ?? false,
120
- debounceMs: config.debounceMs ?? DEFAULT_DEBOUNCE_MS,
121
- enableA11y: config.enableA11y ?? true,
122
- heartbeatMs: config.heartbeatMs ?? DEFAULT_HEARTBEAT_MS,
123
- disableVisibilityGate: config.disableVisibilityGate ?? false,
124
- visibilityGateThreshold: config.visibilityGateThreshold ?? DEFAULT_VISIBILITY_GATE_THRESHOLD,
125
- intersectionRootMargin: config.intersectionRootMargin ?? DEFAULT_INTERSECTION_ROOT_MARGIN,
126
- disableReferrerDetection: config.disableReferrerDetection ?? false,
127
- disableLocalhostMatching: config.disableLocalhostMatching ?? false
128
- // `<` must never appear literally inside an inline <script> body —
129
- // a consumer-supplied string containing `</script>` would otherwise
130
- // terminate the tag early.
131
- }).replace(/</g, "\\u003C");
132
- const generatedAt = RUNTIME_BUILD_INFO.generatedAt;
133
- return [
134
- `/* payload-live-preview runtime ${generatedAt} */`,
135
- `var __LIVE_PREVIEW_CONFIG__=${configLiteral};`,
136
- `var __INLINE_BUILD__=true;`,
137
- RUNTIME_SOURCE
138
- ].join("\n");
139
- }
140
- function wrapWithScriptTag(body, options = {}) {
141
- const nonceAttr = options.nonce !== void 0 ? ` nonce="${escapeNonce(options.nonce)}"` : "";
142
- return `<script${nonceAttr}>${body}</script>`;
143
- }
144
- function escapeNonce(nonce) {
145
- if (!/^[A-Za-z0-9+/=_-]+$/.test(nonce)) {
146
- throw new RangeError("wrapWithScriptTag: nonce contains invalid characters");
147
- }
148
- return nonce;
149
- }
150
-
151
- // src/adapters/shared/preview-request.ts
152
- var DEFAULT_QUERY_PARAMS = ["preview", "draft", "livePreview"];
153
- function isPreviewRequest(request, options = {}) {
154
- const signals = new Set(options.signals ?? ["query", "fetch-dest", "referer"]);
155
- const queryParams = options.queryParams ?? DEFAULT_QUERY_PARAMS;
156
- const checkFetchDest = (options.checkFetchDest ?? true) && signals.has("fetch-dest");
157
- if (signals.has("query")) {
158
- let url;
159
- try {
160
- url = new URL(request.url);
161
- } catch {
162
- url = void 0;
163
- }
164
- if (url !== void 0) {
165
- for (const param of queryParams) {
166
- const value = url.searchParams.get(param);
167
- if (value === "true" || value === "1") return true;
168
- }
169
- }
170
- }
171
- if (checkFetchDest && request.headers.get("sec-fetch-dest") === "iframe") {
172
- return true;
173
- }
174
- const adminOrigins = signals.has("referer") ? options.adminOrigins ?? [] : [];
175
- if (adminOrigins.length > 0) {
176
- const referer = request.headers.get("referer");
177
- if (referer !== null) {
178
- try {
179
- const refererOrigin = new URL(referer).origin;
180
- for (const adminOrigin of adminOrigins) {
181
- try {
182
- if (new URL(adminOrigin).origin === refererOrigin) return true;
183
- } catch {
184
- }
185
- }
186
- } catch {
187
- }
188
- }
189
- }
190
- return false;
191
- }
192
-
193
- // src/adapters/nextjs/index.ts
194
- var HTML_CONTENT_TYPE = /text\/html/i;
195
- var HEAD_INSERT = /<head(\s[^>]*)?>/i;
196
- function createLivePreviewMiddleware(options = {}) {
197
- let cachedScriptBody;
198
- const scriptBody = () => {
199
- cachedScriptBody ??= buildScriptBody(options);
200
- return cachedScriptBody;
201
- };
202
- return async (request, response) => {
203
- const isPreview = (options.inject ?? "preview-only") === "always" || isPreviewRequest(request, {
204
- ...options.previewQueryParams !== void 0 ? { queryParams: options.previewQueryParams } : {},
205
- ...options.previewSignals !== void 0 ? { signals: options.previewSignals } : {},
206
- adminOrigins: options.allowedOrigins ?? []
207
- });
208
- if (!isPreview) return response;
209
- let outResponse = response;
210
- const apply = (options.autoInject ?? true) && (options.shouldInject?.(request) ?? true);
211
- const contentType = response.headers.get("content-type") ?? "";
212
- if (apply && HTML_CONTENT_TYPE.test(contentType)) {
213
- outResponse = await injectIntoResponse(response, scriptBody());
214
- }
215
- const manageCsp = normalizeManageCsp(options.manageCsp);
216
- if (manageCsp !== false) {
217
- outResponse = addCsp(outResponse, manageCsp, options);
218
- }
219
- return outResponse;
220
- };
221
- }
222
- function renderLivePreviewScript(options = {}) {
223
- const body = generateInlineScript({
224
- ...options.allowedOrigins !== void 0 ? { allowedOrigins: options.allowedOrigins } : {},
225
- ...options.serverURL !== void 0 ? { serverURL: options.serverURL } : {},
226
- ...options.apiRoute !== void 0 ? { apiRoute: options.apiRoute } : {},
227
- ...options.mergeDepth !== void 0 ? { mergeDepth: options.mergeDepth } : {},
228
- ...options.debug !== void 0 ? { debug: options.debug } : {},
229
- ...options.debounceMs !== void 0 ? { debounceMs: options.debounceMs } : {},
230
- ...options.heartbeatMs !== void 0 ? { heartbeatMs: options.heartbeatMs } : {},
231
- ...options.nonce !== void 0 ? { nonce: options.nonce } : {}
232
- });
233
- return wrapWithScriptTag(body, options.nonce !== void 0 ? { nonce: options.nonce } : {});
234
- }
235
- function buildScriptBody(options) {
236
- return generateInlineScript({
237
- ...options.allowedOrigins !== void 0 ? { allowedOrigins: options.allowedOrigins } : {},
238
- ...options.serverURL !== void 0 ? { serverURL: options.serverURL } : {},
239
- ...options.apiRoute !== void 0 ? { apiRoute: options.apiRoute } : {},
240
- ...options.mergeDepth !== void 0 ? { mergeDepth: options.mergeDepth } : {},
241
- ...options.debug !== void 0 ? { debug: options.debug } : {},
242
- ...options.debounceMs !== void 0 ? { debounceMs: options.debounceMs } : {},
243
- ...options.heartbeatMs !== void 0 ? { heartbeatMs: options.heartbeatMs } : {}
244
- });
245
- }
246
- function normalizeManageCsp(value) {
247
- if (value === false) return false;
248
- if (value === "full") return "full";
249
- return "frame-ancestors";
250
- }
251
- async function injectIntoResponse(response, body) {
252
- const nonce = response.headers.get("x-live-preview-nonce") ?? generateCspNonce();
253
- const html = await response.text();
254
- const headers = new Headers(response.headers);
255
- headers.delete("content-length");
256
- headers.set("x-live-preview-nonce", nonce);
257
- if (!HEAD_INSERT.test(html)) {
258
- return new Response(html, {
259
- status: response.status,
260
- statusText: response.statusText,
261
- headers
262
- });
263
- }
264
- const scriptTag = wrapWithScriptTag(body, { nonce });
265
- const out = html.replace(HEAD_INSERT, (match) => `${match}${scriptTag}`);
266
- return new Response(out, {
267
- status: response.status,
268
- statusText: response.statusText,
269
- headers
270
- });
271
- }
272
- function addCsp(response, mode, options) {
273
- const nonce = response.headers.get("x-live-preview-nonce") ?? generateCspNonce();
274
- const frameAncestors = buildFrameAncestors({
275
- self: true,
276
- origins: [...options.allowedOrigins ?? [], ...options.frameAncestorsExtra ?? []]
277
- });
278
- const additions = { "frame-ancestors": frameAncestors };
279
- if (mode === "full") {
280
- additions["script-src"] = buildScriptSrcWithNonce(nonce, {
281
- self: true,
282
- strictDynamic: options.strictDynamic ?? false,
283
- ...options.scriptSrcExtra !== void 0 ? { extra: options.scriptSrcExtra } : {}
284
- });
285
- }
286
- const previous = response.headers.get("content-security-policy") ?? "";
287
- const next = mergeCspHeader(previous, additions);
288
- try {
289
- response.headers.set("x-live-preview-nonce", nonce);
290
- response.headers.set("content-security-policy", next);
291
- return response;
292
- } catch {
293
- const headers = new Headers(response.headers);
294
- headers.set("x-live-preview-nonce", nonce);
295
- headers.set("content-security-policy", next);
296
- return new Response(response.body, {
297
- status: response.status,
298
- statusText: response.statusText,
299
- headers
300
- });
301
- }
302
- }
303
-
304
- export { createLivePreviewMiddleware, renderLivePreviewScript };
305
- //# sourceMappingURL=index.js.map
1
+ var t=Object.defineProperty,e=(e,i)=>t(e,"name",{value:i,configurable:!0}),i=/[\t\n\f\r ]+/,n=/^[\t\n\f\r ]+|[\t\n\f\r ]+$/g;function r(t){return t.replace(/[A-Z]/g,t=>t.toLowerCase())}function l(t=16){if(!Number.isInteger(t)||t<8)throw new RangeError(`generateCspNonce: bytes must be an integer >= 8, got ${String(t)}`);let e=s();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.");let i=new Uint8Array(t);return e.getRandomValues(i),o(i)}function s(){let t=globalThis.crypto;if(t?.getRandomValues)return t}function o(t){let e="";for(let i of t)e+=String.fromCharCode(i);return("function"==typeof btoa?btoa(e):Buffer.from(t).toString("base64")).replaceAll("+","-").replaceAll("/","_").replaceAll("=","")}function a(t={}){let{self:e=!0,origins:i=[],allowNone:n=!1}=t,r=new Set,l=[];if(n&&!e&&0===i.length)return"'none'";e&&(l.push("'self'"),r.add("'self'"));for(let t of i){let e=t.trim();0===e.length||r.has(e)||(r.add(e),l.push(e))}return l.length>0?l.join(" "):"'none'"}function u(t,e={}){if(0===t.length)throw new RangeError("buildScriptSrcWithNonce: nonce is empty");let{self:i=!0,extra:n=[],strictDynamic:r=!1}=e,l=[];i&&l.push("'self'"),l.push(`'nonce-${t}'`),r&&l.push("'strict-dynamic'");for(let t of n){let e=t.trim();e.length>0&&l.push(e)}return l.join(" ")}function h(t,e){let l=new Map;for(let e of t.split(";")){let t=e.replace(n,"");if(0===t.length)continue;let s=t.search(i),o=r(s<0?t:t.slice(0,s));if(l.has(o))continue;let a=s<0?"":t.slice(s).replace(n,"");l.set(o,a)}for(let[t,n]of Object.entries(e)){let e=r(t),s="string"==typeof n?{value:n}:n,o=s.mode??"union",a=l.get(e);if("replace"===o||void 0===a||0===a.length){l.set(e,s.value);continue}let u=new Set,h=[];for(let t of[...a.split(i),...s.value.split(i)])0===t.length||u.has(t)||(u.add(t),h.push(t));let c=h.filter(t=>"'none'"!==t);l.set(e,(c.length>0?c:h).join(" "))}let s=[];for(let[t,e]of l)s.push(0===e.length?t:`${t} ${e}`);return s.join("; ")}e(r,"asciiLowercase"),e(l,"generateCspNonce"),e(s,"resolveCrypto"),e(o,"base64UrlEncode"),e(a,"buildFrameAncestors"),e(u,"buildScriptSrcWithNonce"),e(h,"mergeCspHeader");var c='(()=>{function t(t){return("object"!=typeof t||null===t)&&"function"!=typeof t||"function"!=typeof t.then?0:(Promise.resolve(t).catch(()=>{}),1)}function e(e){return(...i)=>{try{t(e(...i))}catch{}}}function i(){}function n(){return 1}function r(t){if(t.nodeType!==Ge)return 0;let e=t;return e.hasAttribute(be)?1:null!==e.querySelector(`[${be}]`)}function l(t){if(!Array.isArray(t))return[];let e=[];for(let i of t){let t=s(i);t&&e.push(t)}return e}function s(t){if("object"!=typeof t||null===t)return;let e=t,i=e.name,n=e.type;if("string"!=typeof i||0===i.length||"string"!=typeof n||0===n.length)return;let r=l(e.fields),s=function(t){if(!Array.isArray(t))return[];let e=[];for(let i of t){if("object"!=typeof i||null===i)continue;let t=i,n=t.slug;if("string"!=typeof n||0===n.length)continue;let r=l(t.fields);e.push({...t,slug:n,fields:r})}return e}(e.blocks),o={...e,name:i,type:n};return r.length>0?o.fields=r:delete o.fields,s.length>0?o.blocks=s:delete o.blocks,o}function o(t){let e="number"==typeof t&&Number.isFinite(t)&&t>=1?Math.floor(t):void 0,i=Math.min(4,e??1),n=new Set;for(let[t,e]of Object.entries(Ye))i>=e&&n.add(t);return{ours:4,...void 0!==e?{theirs:e}:{theirs:void 0},negotiated:i,capabilities:n}}function a(t,e){return void 0===t||e(t)}function u(t,e){return null==t?1:e(t)}function h(t){if("object"!=typeof t||null===t)return 0;let e=Object.getPrototypeOf(t);return null===e||null===Object.getPrototypeOf(e)}function c(t){for(let e of t){let t=e.codePointAt(0);if(void 0!==t&&(t<=31||127===t))return 1}return 0}function d(t){if(void 0===t||0===t.length||t.length>128||"."===t||".."===t||t.includes("/")||t.includes("\\\\")||t.includes("?")||t.includes("#")||c(t))return 0;try{return encodeURIComponent(t),1}catch{return 0}}function f(t,e){return t[6]===e}function p(t){return t.aborted}function g(t){if("string"!=typeof t||0===t.length)return 0;let e=t.trim();if(0===e.length||gi.test(e))return 0;if(e.startsWith("#")||e.startsWith("?")||e.startsWith("//")||e.startsWith("/"))return 1;try{let t=new URL(e);return pi.has(t.protocol)}catch{return mi.test(e)}}function m(t){if(!g(t))return 0;let e=t.trim();return/^https?:\\/\\//i.test(e)||/^\\/\\/[^/]/.test(e)}function y(t){return bi.add(t),t}function v(t,e){return null!==e&&t.generation===e.generation&&t.revision===e.revision}function b(t,e,i,n=0){if(n&&void 0!==i){let n=w(t,`${e}_${i}`);if(void 0!==n)return n}let r=w(t,e);if(void 0!==r)return r;if(e.includes(".")){let i=t,n=1;for(let t of e.split(".")){if(ji.has(t)||null===i||"object"!=typeof i){n=0;break}if(i=w(i,t),void 0===i){n=0;break}}if(n)return i}return void 0===i?void 0:w(t,`${e}_${i}`)}function w(t,e){if(!ji.has(e)&&Object.prototype.hasOwnProperty.call(t,e))return t[e]}function S(){let t=function(){if(typeof document>"u")return;let t=document.documentElement.getAttribute("lang");return null===t||0===t.length?void 0:t}();if(void 0!==t)return t;let e=function(){if(typeof navigator>"u")return;let t=navigator.language;return"string"==typeof t&&t.length>0?t:void 0}();return void 0!==e?e:"en"}function $(t){return/^de(?:[-_]|$)/i.test(t)}function A(t){null!==t[4]&&(clearTimeout(t[4]),t[4]=null),t[2]?.remove(),t[2]=null}function k(t,e=""){let i=new Map;return T(t,e,i),i}function T(t,e,i){for(let n of t){if(_i.has(n.type)){n.fields&&T(n.fields,e,i);continue}if("group"===n.type){let t=""===e?n.name:`${e}.${n.name}`;i.set(t,n),n.fields&&T(n.fields,t,i);continue}let t=""===e?n.name:`${e}.${n.name}`;if(i.set(t,n),"array"===n.type&&n.fields)T(n.fields,`${t}.*`,i);else if("blocks"===n.type&&n.blocks)for(let e of n.blocks)T(e.fields,`${t}.*.${e.slug}`,i)}}function x(t){if("object"!=typeof t||null===t)return;let e=t.id;return"string"==typeof e||"number"==typeof e?e:void 0}function N(t){if("object"!=typeof t||null===t)return;let e=t.blockType;return"string"==typeof e?e:void 0}function M(t,e){return e.every(t=>void 0!==x(t))?function(t,e){let i=[],n=new Map;for(let e=0;e<t.length;e+=1){let i=x(t[e]);void 0!==i&&n.set(i,e)}let r=new Set;for(let l=0;l<e.length;l+=1){let s=e[l],o=x(s);if(void 0===o){i.push({kind:"insert",index:l,value:s});continue}let a=n.get(o);if(void 0===a){i.push({kind:"insert",index:l,value:s});continue}r.add(a);let u=t[a];N(u)===N(s)?(a!==l&&i.push({kind:"move",from:a,to:l,value:s}),C(u,s)||i.push({kind:"update",index:l,value:s})):i.push({kind:"replace",index:l,oldValue:u,value:s})}for(let e=0;e<t.length;e+=1)r.has(e)||i.push({kind:"remove",index:e,value:t[e]});return i}(t,e):function(t,e){let i=[],n=Math.min(t.length,e.length);for(let r=0;r<n;r+=1)C(t[r],e[r])||i.push({kind:"update",index:r,value:e[r]});if(e.length>t.length)for(let n=t.length;n<e.length;n+=1)i.push({kind:"insert",index:n,value:e[n]});if(t.length>e.length)for(let n=e.length;n<t.length;n+=1)i.push({kind:"remove",index:n,value:t[n]});return i}(t,e)}function C(t,e){if(Object.is(t,e))return 1;if("object"!=typeof t||"object"!=typeof e||null===t||null===e)return 0;let i=t,n=e,r=Object.keys(i),l=Object.keys(n);if(r.length!==l.length)return 0;for(let t of r)if(!Object.is(i[t],n[t]))return 0;return 1}function O(t){return 9===t.nodeType}function j(t){if(typeof window>"u")return;let e=[];window.parent!==window&&e.push(window.parent),window.opener instanceof Window&&e.push(window.opener),Ze.sendReady(e,t)}function I(t,e){return t.generation===e.generation&&t.revision===e.revision}function E(t){return null==t?0:"string"==typeof t||"number"==typeof t||"boolean"==typeof t||"bigint"==typeof t}function R(t,e){if(!e)return t;let i=`_${e}`;return t.endsWith(i)?t.slice(0,-i.length):t}function _(){if(typeof window>"u")return 0;try{return window.self!==window.top}catch{return 1}}function L(t){if(typeof process<"u"){let e=process.env[t];if("string"==typeof e&&e.length>0)return e}}function W(t){let e=t.trim();if(0!==e.length)try{let t=new URL(e);return"http:"!==t.protocol&&"https:"!==t.protocol||!un.test(t.origin)?void 0:t.origin}catch{return}}function P(t,e){let i=F();if(!i)throw new An("sanitizeHtml needs a DOM; provide one with setSanitizerDocument() during SSR.");if(""===t)return"";let n=function(t){if(!t){let t=new Map;for(let[e,i]of Object.entries(bn))t.set(e,i);return{allowedTags:pn,attrByTag:t}}let e=new Set(pn);for(let i of t.additionalAllowedTags??[])e.add(i);let i=new Map;for(let[t,e]of Object.entries(bn))i.set(t,e);for(let[e,n]of Object.entries(t.additionalAllowedAttributes??{})){let t=i.get(e),r=new Set(t??[]);for(let t of n)r.add(t);i.set(e,r)}return{allowedTags:e,attrByTag:i}}(e),r=i.createElement("template");return r.innerHTML=t,D(r.content,n),r.innerHTML}function F(){if(!(typeof document>"u"))return document}function D(t,e){for(let i of Array.from(t.childNodes))i.nodeType===Sn?U(i,e):i.nodeType===$n&&i.remove()}function U(t,e){let i=t.tagName.toLowerCase();if(gn.has(i))t.remove();else{if(!e.allowedTags.has(i)){D(t,e);let i=t.parentNode;if(i){for(;t.firstChild;)i.insertBefore(t.firstChild,t);t.remove()}return}(function(t,e,i){let n=i.attrByTag.get(e);for(let e of Array.from(t.attributes)){let i=e.name.toLowerCase();if(i.startsWith("on"))t.removeAttribute(e.name);else if("style"!==i){if(!(mn.has(i)||i.startsWith(yn)||i.startsWith(vn))){if(n?.has(i)){(wn.has(i)&&!g(e.value)||"srcset"===i&&!z(e.value))&&t.removeAttribute(e.name);continue}t.removeAttribute(e.name)}}else t.removeAttribute(e.name)}})(t,i,e),"a"===i&&function(t){let e=t.getAttribute("href");null===e||!m(e)||(t.setAttribute("rel","noopener noreferrer"),t.hasAttribute("target")||t.setAttribute("target","_blank"))}(t),D(t,e)}}function z(t){let e=t.split(",");for(let t of e){let e=t.trim();if(0===e.length)continue;let i=e.search(/\\s/);if(!g(-1===i?e:e.slice(0,i)))return 0}return 1}function V(t,e){kn.set(t,e)}function G(t){let e=t.format;if("string"==typeof e&&xn.has(e))return e;if("number"==typeof e){let t=Tn[e];if(void 0!==t)return t}}function H(t){let e=t.indent;return"number"==typeof e&&e>0?e:0}function q(t){return"rtl"===t.direction?\' dir="rtl"\':"ltr"===t.direction?\' dir="ltr"\':""}function J(t){let e=G(t),i=H(t),n=[];return void 0!==e&&n.push(`text-align:${e}`),i>0&&n.push(`padding-inline-start:${String(40*i)}px`),0===n.length?"":` style="${n.join(";")}"`}function B(t){return""===t?"":t.replace(Mn,t=>Nn[t])}function X(t){return""===t?"":t.replace(On,t=>Cn[t])}function Y(t){return B(t).replace(/\\r\\n|\\r|\\n/g,"<br>")}function Z(t){if("string"==typeof t.text)return t.text;if(!t.children)return"";let e="";for(let i of t.children)e+=Z(i);return e}function K(t){return t.replace(/[^a-zA-Z0-9_-]/g,"")}function Q(t){return En.get(t)}function tt(t){return t.replace(/[^a-zA-Z0-9_-]/g,"-").toLowerCase()}function et(t){if("object"!=typeof t||null===t||!("root"in t))return 0;let e=t.root;return"object"==typeof e&&null!==e&&"children"in e?Array.isArray(e.children):0}function it(t){return et(t)?t.root.children.map(lt).join("\\n").trim():""}function nt(t){let e="";for(let i of t)e+=rt(i);return e}function rt(t){let e=function(t){return kn.get(t)}(t.type);return e?e(t,jt):void 0!==t.children?nt(t.children):""}function lt(t){if("string"==typeof t.text)return t.text;if("linebreak"===t.type)return"\\n";if(void 0===t.children)return"";let e="";for(let i of t.children)e+=lt(i);return e}function st(){let t=new WeakSet;return{name:"text",render:y((e,i)=>{let n=e.element,r=function(t){return null==t?"":et(t)?it(t):"string"==typeof t?t:"number"==typeof t||"boolean"==typeof t?String(t):JSON.stringify(t)}(i);if("INPUT"!==n.tagName&&"TEXTAREA"!==n.tagName){if(function(t){return null!==t.firstElementChild}(n)&&!n.hasAttribute(It))return function(t,e,i){t.has(e)||(t.add(e),ue(`[live-preview] Skipping text update for "${i}": <${e.tagName.toLowerCase()}> has structured children. Move data-payload-field to the value element, or add data-payload-text to replace them.`))}(t,n,e.fieldName),0;r.includes("\\n")||r.includes("\\r")?n.innerHTML=Y(r):n.textContent=r}else n.value=r})}}function ot(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""}}function at(t){if("object"==typeof t&&null!==t)return t}function ut(t){if("object"==typeof t&&null!==t){let 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 ot(t)}function ht(t){return Array.isArray(t)?t.map(t=>ht(t)).join(", "):ot(t)}function ct(t,e){let i=t??"";if(null==e)return i;let n=dt(e);return"{}"===n?i:`${i}|${n}`}function dt(t){if(null===t||"object"!=typeof t)return JSON.stringify(t);if(Array.isArray(t))return`[${t.map(t=>dt(t)).join(",")}]`;let e=t,i=Object.keys(e).sort(),n=[];for(let t of i){let i=e[t];void 0!==i&&n.push(`${JSON.stringify(t)}:${dt(i)}`)}return`{${n.join(",")}}`}function ft(t){for(;t.size>Gt;){let e=t.keys().next().value;if(void 0===e)break;t.delete(e)}}function pt(t,e,i,n){let r="object"==typeof e&&null!==e?e:null;return t.replace(Jt,(t,l)=>null!==r&&function(t,e){return Object.prototype.hasOwnProperty.call(t,e)}(r,l)?B(n(Reflect.get(r,l))):null===r&&"value"===l?B(n(e)):"index"===l?String(i):t)}function gt(t,e,i){return pt(t,e,i,ot)}function mt(t){return ot(t)}function yt(t){let{template:e,container:i,patches:n,nextItems:r,store:l,forceRender:s=0}=t,o=vt(i,e,n,r,s,l);return null===o?null:bt(o,l)}function vt(t,e,i,n,r,l){let s=function(t){let e=new Set,i=new Set;for(let n of t)"insert"===n.kind||"update"===n.kind?e.add(n.index):"replace"===n.kind&&(e.add(n.index),i.add(n.index));return{renders:e,replaces:i}}(i),o=function(t,e,i,n,r,l,s){let o=Array.from(t.children),a=xt(o,Xt),u=new Set,h=[];for(let c=0;c<i.length;c+=1){let d=i[c],f=Tt(d),p=void 0===f?o[c]??null:Nt(a,f)??null;null!==p&&u.has(p)&&(p=null),null!==p&&u.add(p);let g=n.replaces.has(c),m=r||n.renders.has(c)||null===p?Mt(t.ownerDocument,e,d,c):void 0;if(null===m)return null;let y=void 0===m?[]:wt(g?null:p,m,d,l,s);if(null===y)return null;h.push([c,p,m??void 0,y])}return h}(t,e,n,s,r,l.get(t),l);return null===o?null:[t,o,n]}function bt(t,e){let[i,n,r]=t,l=new Set,s=0;for(let t of n){let[n,r,o,a]=t,u=r;if(void 0!==o){for(let t of a)null!==t[0]&&($t(t[0],t[1]),t[1].replaceWith(t[0])),void 0!==t[2]&&bt(t[2],e);null!==r&&(r.replaceWith(o),s=1),u=o}if(null===u)continue;let h=i.children[n]??null;u!==h&&(i.insertBefore(u,h),s=1),l.add(u)}for(let t of Array.from(i.children))l.has(t)||(t.remove(),s=1);let o=function(t,e){let i=e.get(t);return i||(i=new Map,e.set(t,i)),i}(i,e);o.clear();for(let t of r)kt(o,t);return s}function wt(t,e,i,n,r){let l=xt(null===t?[]:St(t),Yt),s=Tt(i),o=void 0!==s?n?.get(s):void 0,a=[];for(let t of St(e)){let e=t.getAttribute(Yt);if(null===e)continue;let n,s=Nt(l,e)??null,u=t.getAttribute(Zt),h=u?s:null,c=h?.getAttribute(Zt)??null;if(u){let l=At(i,e);if(void 0!==l||null!==h){let i=l??[],s=M(null===h?[]:At(o,e)??[],i),a=null!==h&&c!==u;if((s.length>0||a)&&(n=vt(h??t,u,s,i,a,r)??void 0,void 0===n))return null}}a.push([h,t,n])}return a}function St(t){return Array.from(t.querySelectorAll(`[${Yt}]`)).filter(e=>{let i=e.parentElement;for(;null!==i&&i!==t;){if(i.hasAttribute(Yt))return 0;i=i.parentElement}return i===t})}function $t(t,e){for(let i of Array.from(t.attributes))e.hasAttribute(i.name)||t.removeAttribute(i.name);for(let i of Array.from(e.attributes))t.getAttribute(i.name)!==i.value&&t.setAttribute(i.name,i.value)}function At(t,e){if("object"!=typeof t||null===t)return;let i=t[e];return Array.isArray(i)?i:void 0}function kt(t,e){let i=Tt(e);void 0!==i&&t.set(i,e)}function Tt(t){if("object"!=typeof t||null===t)return;let e=t.id;return"string"==typeof e||"number"==typeof e?String(e):void 0}function xt(t,e){let i=new Map;for(let n=t.length-1;n>=0;n-=1){let r=t[n];if(void 0===r)continue;let l=r.getAttribute(e);if(null===l)continue;let s=i.get(l);void 0===s?i.set(l,[r]):s.push(r)}return i}function Nt(t,e){return t.get(e)?.pop()}function Mt(t,e,i,n){let r=function(t,e,i){return pt(t,e,i,ot)}(e,i,n),l=P(r),s=t.createElement("template");s.innerHTML=l;let o=s.content.firstElementChild;if(!o)return null;let a=Tt(i);return void 0!==a&&o.setAttribute(Xt,a),o}function Ct(){let t=new WeakMap,e=new WeakSet,i=new WeakMap;return{name:"structural-array",render:y((n,r)=>{if(!Array.isArray(r))return 0;let l=n.element,s=n.arrayTemplate;if(void 0===s||0===s.length)return function(t,e,i){t.has(e)||(t.add(e),ue(`[live-preview] Skipping structural update for "${i}": <${e.tagName.toLowerCase()} data-payload-structural> needs data-payload-array-template (for example "<li>{{label}}</li>").`))}(e,l,n.fieldName),0;let o=t.get(l),a=Ot(l),u=o?.values??function(t){return t.map((t,e)=>null===t?{__payloadDomPosition:e}:{id:t})}(a),h=M(u,r),c=function(t,e,i){return void 0===t?1:t.template!==e||!function(t,e){return t.length!==e.length?0:t.every((t,i)=>t===e[i])}(t.domSnapshot,i)}(o,s,a);if(0===h.length&&!c)return t.set(l,{values:r.slice(),template:s,domSnapshot:a}),0;let d=yt({template:s,container:l,patches:h,nextItems:r,store:i,forceRender:c});return null===d?0:(t.set(l,{values:r.slice(),template:s,domSnapshot:Ot(l)}),d?void 0:0)})}}function Ot(t){return Array.from(t.children,t=>t.getAttribute(Xt))}var jt,It,Et,Rt,_t,Lt,Wt,Pt,Ft,Dt,Ut,zt,Vt,Gt,Ht,qt,Jt,Bt,Xt,Yt,Zt,Kt,Qt,te=Object.defineProperty,ee=t=>{throw TypeError(t)},ie=(t,e,i)=>((t,e,i)=>e in t?te(t,e,{enumerable:1,configurable:1,writable:1,value:i}):t[e]=i)(t,"symbol"!=typeof e?e+"":e,i),ne=(t,e,i)=>e.has(t)||ee("Cannot "+i),re=(t,e,i)=>(ne(t,e,"read from private field"),i?i.call(t):e.get(t)),le=(t,e,i)=>e.has(t)?ee("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,i),se=(t,e,i,n)=>(ne(t,e,"write to private field"),n?n.call(t,i):e.set(t,i),i),oe=(t,e,i)=>(ne(t,e,"access private method"),i),ae=e((...t)=>console.error(...t)),ue=e((...t)=>console.warn(...t)),he=e((...t)=>console.debug(...t)),ce=class{constructor(){le(this,pe);le(this,de,new Map);le(this,fe,new Map)}on(t,e){return oe(this,pe,me).call(this,re(this,de),t,e)}once(t,e){return oe(this,pe,me).call(this,re(this,fe),t,e)}off(t,e){oe(this,pe,ye).call(this,re(this,de),t,e),oe(this,pe,ye).call(this,re(this,fe),t,e)}async emit(t,e){await oe(this,pe,ge).call(this,t,e)}async emitWhile(t,e,i){return oe(this,pe,ge).call(this,t,e,i)}listenerCount(t){return(re(this,de).get(t)?.size??0)+(re(this,fe).get(t)?.size??0)}removeAllListeners(t){void 0!==t?(re(this,de).delete(t),re(this,fe).delete(t)):(re(this,de).clear(),re(this,fe).clear())}eventNames(){let t=new Set;for(let e of re(this,de).keys())t.add(e);for(let e of re(this,fe).keys())t.add(e);return[...t]}},de=new WeakMap,fe=new WeakMap,pe=new WeakSet,ge=async function(t,e,i){let n=()=>i?.()??1;if(!n())return 0;let r=re(this,de).get(t);if(r)for(let i of[...r])if(!n()||(await oe(this,pe,ve).call(this,i,e,t),!n()))return 0;if(!n())return 0;let l=re(this,fe).get(t);if(l&&l.size>0){let i=[...l];re(this,fe).delete(t);for(let r of i)if(!n()||(await oe(this,pe,ve).call(this,r,e,t),!n()))return 0}return n()},me=function(t,e,i){let n=t.get(e);return n||(n=new Set,t.set(e,n)),n.add(i),()=>{oe(this,pe,ye).call(this,t,e,i)}},ye=function(t,e,i){let n=t.get(e);void 0!==n&&(n.delete(i),0===n.size&&t.delete(e))},ve=async function(t,e,i){try{await t(e)}catch(t){let e="string"==typeof i||"number"==typeof i?String(i):"<event>";ae(`[live-preview] handler for "${e}" threw:`,t)}},be="data-payload-field",we="data-payload-type",Se="data-payload-attribute",$e="data-payload-href",Ae="data-payload-src",ke="data-payload-alt",Te="data-payload-array-template",xe="data-payload-array-separator",Ne="data-payload-locale",Me="data-payload-richtext",Ce="data-payload-html",Oe="data-payload-array",je="data-payload-structural",Ie=[be,we,Se,$e,Ae,ke,Te,xe,Ne,Me,Ce,Oe,je,"type"],Ee=`[${be}]`,Re=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"]),_e=class{constructor(t={}){le(this,Fe);le(this,Le,new Map);le(this,We,new WeakMap);le(this,Pe);se(this,Pe,t.filter??n)}buildFromRoot(t){let e=performance.now();this.clear();let i=t.querySelectorAll(Ee),n=0;for(let t of i)void 0!==this.add(t)&&(n+=1);return{elementCount:n,fieldCount:re(this,Le).size,durationMs:performance.now()-e}}add(t){let e=re(this,Pe).call(this,t)?oe(this,Fe,Ve).call(this,t):void 0,i=re(this,We).get(t);if(void 0!==e)return void 0!==i&&oe(this,Fe,De).call(this,i,e)?(re(this,We).set(t,e),e):(void 0!==i&&oe(this,Fe,Ue).call(this,t,i),oe(this,Fe,ze).call(this,e),re(this,We).set(t,e),e);void 0!==i&&oe(this,Fe,Ue).call(this,t,i)}remove(t){let e=re(this,We).get(t);return e?oe(this,Fe,Ue).call(this,t,e):0}get(t){return re(this,Le).get(t)}getByElement(t){return re(this,We).get(t)}get fieldCount(){return re(this,Le).size}get elementCount(){let t=0;for(let e of re(this,Le).values())t+=e.length;return t}entries(){return re(this,Le).entries()}*values(){for(let t of re(this,Le).values())yield*t}has(t){return re(this,We).has(t)}clear(){re(this,Le).clear(),se(this,We,new WeakMap)}},Le=new WeakMap,We=new WeakMap,Pe=new WeakMap,Fe=new WeakSet,De=function(t,e){if(t.fieldName!==e.fieldName)return 0;let i=re(this,Le).get(t.fieldName);if(!i)return 0;let n=i.indexOf(t);return n<0?0:(i[n]=e,1)},Ue=function(t,e){let i=re(this,Le).get(e.fieldName);if(!i)return re(this,We).delete(t),0;let n=i.indexOf(e);return n<0?(re(this,We).delete(t),0):(i.splice(n,1),0===i.length&&re(this,Le).delete(e.fieldName),re(this,We).delete(t),1)},ze=function(t){let e=re(this,Le).get(t.fieldName);e?e.push(t):re(this,Le).set(t.fieldName,[t])},Ve=function(t){let e=t.getAttribute(be);if(null===e||0===e.length)return;let i=t.getAttribute(we),n=function(t){let e=t.getAttribute(we);if(null!==e&&Re.has(e))return e;if(t.hasAttribute(Me))return"richText";if(t.hasAttribute(Ce))return"html";if(t.hasAttribute(je))return"structural-array";if(t.hasAttribute(Oe))return"array";if("IMG"===t.tagName)return"image";if("A"===t.tagName)return"url";if("TIME"===t.tagName)return"date";if("INPUT"===t.tagName){let e=t.type;if("checkbox"===e)return"checkbox";if("number"===e)return"number";if("date"===e||"datetime-local"===e)return"date"}return"text"}(t),r=t.getAttribute(Se),l=t.getAttribute($e),s=t.getAttribute(Ae),o=t.getAttribute(ke),a=t.getAttribute(Te),u=t.getAttribute(xe),h=t.getAttribute(Ne);return{element:t,fieldName:e,fieldType:n,explicitFieldType:null!==i&&Re.has(i),...null!==r&&r.length>0?{targetAttribute:r}:{},...null!==l&&l.length>0?{hrefField:l}:{},...null!==s&&s.length>0?{srcField:s}:{},...null!==o&&o.length>0?{altField:o}:{},...null!==a?{arrayTemplate:a}:{},...null!==u?{arraySeparator:u}:{},...null!==h&&h.length>0?{locale:h}:{}}},Ge=1,He=class{constructor(t,e={}){le(this,qe);ie(this,"s");this.s=[t,e.mutationDebounceMs??100,e.intersectionRootMargin??"200px",new Set,null,null,null,0]}start(t){let e=this.s[7];this.stop();let i=e+1;if(this.s[7]!==i)return;let n=null,r=null;try{n=new MutationObserver(t=>{oe(this,qe,Je).call(this,t,i)}),r=new IntersectionObserver(t=>{oe(this,qe,Be).call(this,t,i)},{rootMargin:this.s[2],threshold:0}),n.observe(t,{childList:1,subtree:1,attributes:1,attributeFilter:[...Ie]})}catch(t){throw n?.disconnect(),r?.disconnect(),t}this.s[7]===i?(this.s[4]=n,this.s[5]=r):(n.disconnect(),r.disconnect())}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;let t=this.s[6],e=this.s[4],i=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{i?.disconnect()}}},qe=new WeakSet,Je=function(t,e){if(!oe(this,qe,Xe).call(this,e)||!function(t){for(let e of t){if("attributes"===e.type&&null!==e.attributeName&&Ie.includes(e.attributeName)&&(e.attributeName===be||e.target.nodeType===Ge&&e.target.hasAttribute(be)))return 1;for(let t of e.addedNodes)if(r(t))return 1;for(let t of e.removedNodes)if(r(t))return 1}return 0}(t)||!oe(this,qe,Xe).call(this,e))return;null!==this.s[6]&&clearTimeout(this.s[6]);let i=setTimeout(()=>{!oe(this,qe,Xe).call(this,e)||this.s[6]!==i||(this.s[6]=null,this.s[0].onStructuralChange())},this.s[1]);this.s[6]=i},Be=function(t,e){for(let i of t){if(!oe(this,qe,Xe).call(this,e))return;let t=i.target;if(i.isIntersecting){if(!this.s[3].has(t)&&(this.s[3].add(t),this.s[0].onVisibilityChange(t,1),!oe(this,qe,Xe).call(this,e)))return}else if(this.s[3].has(t)&&(this.s[3].delete(t),this.s[0].onVisibilityChange(t,0),!oe(this,qe,Xe).call(this,e)))return}},Xe=function(t){return this.s[7]===t&&null!==this.s[5]},Ye={basic:1,"schema-json":2,"preview-token":3,"nested-arrays":4,"recursive-diffs":4},Ze=class{constructor(t,e){le(this,Ke);ie(this,"s");this.s=[t,e,void 0,void 0,0,0,[],0]}attach(t=window){if(void 0!==this.s[3])return;let e=0,i=t=>{if(!e||this.s[2]!==i)return;let n=this.s[4];try{oe(this,Ke,Qe).call(this,t,n)}catch{let e="";try{e=t.origin}catch{}oe(this,Ke,ri).call(this,"shape",e,n)}};this.s[4]+=1,oe(this,Ke,ui).call(this),this.s[3]=t,this.s[2]=i;try{t.addEventListener("message",i)}catch(e){this.s[2]===i&&(this.s[3]=void 0,this.s[2]=void 0,oe(this,Ke,ui).call(this));try{t.removeEventListener("message",i)}catch{}throw e}if(this.s[2]===i)e=1;else try{t.removeEventListener("message",i)}catch{}}detach(t){let e=this.s[3],i=this.s[2];void 0===e||void 0===i||(this.s[3]=void 0,this.s[2]=void 0,oe(this,Ke,ui).call(this),e.removeEventListener("message",i))}advanceGeneration(){return void 0===this.s[3]?0:(this.s[4]+=1,oe(this,Ke,ui).call(this),1)}static sendReady(t,e){if(0===t.length||0===e.length)return;let i={type:"payload-live-preview",ready:1,protocolVersion:4};for(let n of t)for(let t of e)try{n.postMessage(i,t)}catch{}}},Ke=new WeakSet,Qe=function(t,e){if(!oe(this,Ke,oi).call(this,e))return;let i=t.origin;if(!oe(this,Ke,oi).call(this,e))return;if(!oe(this,Ke,li).call(this,i,e)){oe(this,Ke,ri).call(this,"origin",i,e);return}let n=t.data;if(!oe(this,Ke,oi).call(this,e))return;let r=function(t){return"object"==typeof t&&null!==t&&"type"in t?"string"==typeof t.type:0}(n);if(!oe(this,Ke,oi).call(this,e))return;if(!r){oe(this,Ke,ri).call(this,"shape",i,e);return}let s=n.type;if(oe(this,Ke,oi).call(this,e))switch(s){case"payload-live-preview":{let t=function(t){let e=t;return!!((void 0===e.data||null===e.data||h(e.data))&&u(e.fieldSchemaJSON,t=>Array.isArray(t))&&u(e.globalSlug,t=>"string"==typeof t)&&u(e.collectionSlug,t=>"string"==typeof t)&&u(e.locale,t=>"string"==typeof t)&&u(e.ready,t=>"boolean"==typeof t)&&u(e.previewToken,t=>"string"==typeof t)&&u(e.protocolVersion,t=>"number"==typeof t))}(n);if(!oe(this,Ke,oi).call(this,e))return;if(!t){oe(this,Ke,ri).call(this,"shape",i,e);return}let r=function(t){let e={...t};for(let t of hi)null===Reflect.get(e,t)&&Reflect.deleteProperty(e,t);if(!Array.isArray(e.fieldSchemaJSON))return e;let i;try{i=l(e.fieldSchemaJSON)}catch{i=[]}return{...e,fieldSchemaJSON:i}}(n);if(!oe(this,Ke,oi).call(this,e))return;oe(this,Ke,ti).call(this,r,i,e);return}case"payload-document-event":{let t=function(t){let e=t;return!(!a(e.action,t=>"updated"===t||"created"===t||"deleted"===t)||!a(e.slug,t=>"string"==typeof t)||!a(e.id,t=>"string"==typeof t||"number"==typeof t&&Number.isFinite(t)))}(n);if(!oe(this,Ke,oi).call(this,e))return;if(!t){oe(this,Ke,ri).call(this,"shape",i,e);return}let r;try{r=this.s[1].onDocumentEvent}catch{return}if(!oe(this,Ke,oi).call(this,e))return;oe(this,Ke,si).call(this,r,n,i);return}default:oe(this,Ke,ri).call(this,"type",i,e)}},ti=function(t,e,i){if(!oe(this,Ke,oi).call(this,i))return;let n=t.data;if(!oe(this,Ke,oi).call(this,i))return;let r=h(n);if(!oe(this,Ke,oi).call(this,i))return;let l,s=r?{generation:i,revision:this.s[5]+=1}:void 0;try{l=this.s[1].validateToken}catch{return}if(!oe(this,Ke,oi).call(this,i))return;if(void 0===l){oe(this,Ke,ni).call(this,t,e,i,s);return}if(1==t.ready&&void 0===n){oe(this,Ke,ni).call(this,t,e,i,void 0);return}let o={generation:i,message:t,origin:e,messageRevision:s,settled:0,approved:0};this.s[6].push(o);let a;try{a=l(t.previewToken,e)}catch{oe(this,Ke,ei).call(this,o,0);return}"boolean"!=typeof a?Promise.resolve(a).then(t=>{oe(this,Ke,ei).call(this,o,1==t)},()=>{oe(this,Ke,ei).call(this,o,0)}):oe(this,Ke,ei).call(this,o,a)},ei=function(t,e){oe(this,Ke,oi).call(this,t.generation)&&(t.approved=e,t.settled=1,oe(this,Ke,ii).call(this,t.generation))},ii=function(t){for(;oe(this,Ke,oi).call(this,t);){let e=this.s[6][this.s[7]];if(void 0===e)return;if(oe(this,Ke,li).call(this,e.origin,t)){if(!e.settled)return;oe(this,Ke,ai).call(this,e)&&(e.approved?oe(this,Ke,ni).call(this,e.message,e.origin,e.generation,e.messageRevision):oe(this,Ke,ri).call(this,"token",e.origin,e.generation))}else{if(!oe(this,Ke,ai).call(this,e))continue;oe(this,Ke,ri).call(this,"origin",e.origin,e.generation)}}},ni=function(t,e,i,n){if(!oe(this,Ke,oi).call(this,i))return;let r;try{r=this.s[1].onUpdate}catch{return}oe(this,Ke,oi).call(this,i)&&(void 0===n?oe(this,Ke,si).call(this,r,t,e):oe(this,Ke,si).call(this,r,t,e,n))},ri=function(t,e,i){if(!oe(this,Ke,oi).call(this,i))return;let n;try{n=this.s[1].onInvalid}catch{return}oe(this,Ke,oi).call(this,i)&&void 0!==n&&oe(this,Ke,si).call(this,n,t,e)},li=function(t,e){if(!oe(this,Ke,oi).call(this,e))return 0;try{return 1==this.s[0](t)&&oe(this,Ke,oi).call(this,e)}catch{return 0}},si=function(e,...i){try{t(e(...i))}catch{}},oi=function(t){return void 0!==this.s[3]&&this.s[4]===t},ai=function(t){let e=this.s;return e[6][e[7]]!==t?0:(e[7]+=1,e[7]===e[6].length?(oe(this,Ke,ui).call(this),1):(e[7]>=1024&&2*e[7]>=e[6].length&&(e[6]=e[6].slice(e[7]),e[7]=0),1))},ui=function(){this.s[6]=[],this.s[7]=0},hi=["data","fieldSchemaJSON","globalSlug","collectionSlug","locale","ready","previewToken","protocolVersion"],ci=class{constructor(t){ie(this,"s");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]);let 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]}},di=class{constructor(t){ie(this,"s");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 0;let e=this.s[0];return this.s[0]=t,this.s[1](t,e),1}},fi=class{constructor(t){ie(this,"s");let n=t.serverURL.replace(/\\/+$/,""),r=t.apiRoute??"/api";this.s=[n,r.startsWith("/")?r:`/${r}`,t.depth??1,t.fetchFn,void 0===t.log?i:e(t.log),null,0,0]}canMerge(t){try{return t.globalSlug?d(t.globalSlug):d(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("\\\\")||c(t))return 0;try{return encodeURIComponent(t),1}catch{return 0}}(t.data.id):0}catch{return 0}}async merge(t){if(this.s[7]>0)return{status:"superseded"};let e=this.s[6]+1;this.s[6]=e;let i=this.s[5];this.s[5]=null;let n=null;try{if(i?.abort(),!f(this.s,e))return{status:"superseded"};if(!this.canMerge(t))return f(this.s,e)?{status:"unavailable"}:{status:"superseded"};if(!f(this.s,e))return{status:"superseded"};let r=this.s[3]??("function"==typeof fetch?fetch:void 0);if(!f(this.s,e))return{status:"superseded"};if(void 0===r)return{status:"unavailable"};if(n=new AbortController,!f(this.s,e))return n.abort(),{status:"superseded"};this.s[5]=n;let l=t.globalSlug?`globals/${encodeURIComponent(t.globalSlug)}`:`${encodeURIComponent(t.collectionSlug??"")}/${encodeURIComponent(String(t.data.id))}`,s=`${this.s[0]}${this.s[1]}/${l}`,o=JSON.stringify({data:t.data,depth:this.s[2],flattenLocales:0,...void 0!==t.locale?{locale:t.locale}:{}});if(!f(this.s,e))return{status:"superseded"};let a=await r(s,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json","X-Payload-HTTP-Method-Override":"GET"},body:o,signal:n.signal});if(!f(this.s,e)||p(n.signal))return{status:"superseded"};let u=a.ok;if(!f(this.s,e))return{status:"superseded"};if(!u){let t=a.status;return f(this.s,e)?(this.s[4]("merge HTTP",t,s),f(this.s,e)?{status:"unavailable"}:{status:"superseded"}):{status:"superseded"}}let h=await a.json();return!f(this.s,e)||p(n.signal)?{status:"superseded"}:null===h||"object"!=typeof h||Array.isArray(h)?(this.s[4]("merge invalid",s),f(this.s,e)?{status:"unavailable"}:{status:"superseded"}):{status:"merged",doc:h}}catch(t){return!f(this.s,e)||null!==n&&p(n.signal)?{status:"superseded"}:(this.s[4]("merge exception",t),f(this.s,e)?{status:"unavailable"}:{status:"superseded"})}finally{null!==n&&f(this.s,e)&&this.s[5]===n&&(this.s[5]=null)}}destroy(){this.s[6]+=1;let t=this.s[5];this.s[5]=null,this.s[7]+=1;try{t?.abort()}finally{this.s[7]-=1}}},pi=new Set(["http:","https:","mailto:","tel:"]),gi=/^\\s*(?:javascript|data|vbscript|file|blob|about)\\s*:/i,mi=/^(?:\\.{1,2}\\/|[a-zA-Z0-9_-]+\\/?)/,yi=new Set(["style","srcdoc","formaction","form","id","name","is","srcset","imagesrcset"]),vi=new Set(["href","src","poster","cite","action","xlink:href","data"]),bi=new WeakSet,wi=class{constructor(t,e){le(this,Si);ie(this,"s");let i=e.scheduleFrame??("function"==typeof requestAnimationFrame?requestAnimationFrame.bind(globalThis):t=>setTimeout(()=>{t(performance.now())},0)),n=e.cancelFrame??("function"==typeof cancelAnimationFrame?cancelAnimationFrame.bind(globalThis):t=>{clearTimeout(t)});this.s=[t,e.debounceMs??50,e.isVisible,e.visibilityGateThreshold??50,e.disableVisibilityGate??0,e.getCacheSize,e.onFlush,i,n,new Map,new Map,new Set,null,0,null,0,null,0]}schedule(t){if(void 0!==t.identity&&(this.s[17]||!v(t.identity,this.s[16])))return;let e=this.s[9],i=e.get(t.target.element);i?(i.value=t.value,i.allFields=t.allFields,i.identity=t.identity,i.data=t.data):e.set(t.target.element,{...t,identity:t.identity,data:t.data}),oe(this,Si,$i).call(this)}acceptRevision(t){let e=this.s[16];v(t,e)||null!==e&&function(t,e){return t.generation!==e.generation?t.generation-e.generation:t.revision-e.revision}(t,e)<0||(oe(this,Si,Oi).call(this),oe(this,Si,Mi).call(this),this.s[16]=t,this.s[17]=0)}cancelRevision(t){v(t,this.s[16])&&(oe(this,Si,Oi).call(this),oe(this,Si,Mi).call(this),this.s[17]=1)}flushNow(){return oe(this,Si,Oi).call(this),oe(this,Si,ki).call(this)}notifyVisible(t){let e=this.s[10],i=e.get(t);if(!i||(e.delete(t),!oe(this,Si,Ti).call(this,i)))return;let n=performance.now(),r=oe(this,Si,xi).call(this,i)?1:0;this.s[6]?.(oe(this,Si,Ci).call(this,i,r,0,performance.now()-n))}retarget(t){oe(this,Si,Ni).call(this,this.s[9],t),oe(this,Si,Ni).call(this,this.s[10],t);for(let e of this.s[11])oe(this,Si,Ni).call(this,e,t)}forget(t){this.s[9].delete(t),this.s[10].delete(t);for(let e of this.s[11])e.delete(t)}destroy(){oe(this,Si,Oi).call(this),oe(this,Si,Mi).call(this),this.s[16]=null,this.s[17]=0}get pendingCount(){return this.s[9].size}get replayCount(){return this.s[10].size}},Si=new WeakSet,$i=function(){let t=this.s[13]+=1,e=this.s[12];if(this.s[12]=null,null!==e&&clearTimeout(e),this.s[13]!==t)return;let i=setTimeout(()=>{this.s[13]===t&&(this.s[12]=null,oe(this,Si,Ai).call(this))},this.s[1]);this.s[13]===t&&(this.s[12]=i)},Ai=function(){let 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 i=0,n=this.s[7](()=>{this.s[15]===t&&(i=1,this.s[14]=null,oe(this,Si,ki).call(this))});!i&&this.s[15]===t&&(this.s[14]=n)},ki=function(){let t=performance.now(),e=!this.s[4]&&this.s[5]()>this.s[3],i=this.s[9];this.s[9]=new Map;let n,r=0,l=0;this.s[11].add(i);try{for(let t of i.values()){if(!oe(this,Si,Ti).call(this,t))continue;let i=!e||this.s[2](t.target.element);if(oe(this,Si,Ti).call(this,t)){if(n??(n=t),!i){this.s[10].set(t.target.element,t),l+=1;continue}this.s[10].delete(t.target.element),oe(this,Si,xi).call(this,t)&&(r+=1)}}}finally{this.s[11].delete(i)}let s=oe(this,Si,Ci).call(this,n,r,l,performance.now()-t);return this.s[6]?.(s),s},Ti=function(t){return void 0===t.identity||!this.s[17]&&v(t.identity,this.s[16])},xi=function(t){let e=this.s[0];return 0!=e(t)||!function(t){return bi.has(t)}(e)},Ni=function(t,e){let i=t.get(e.element);if(void 0!==i){if(i.target.fieldName!==e.fieldName||i.target.locale!==e.locale){t.delete(e.element);return}i.target=e}},Mi=function(){this.s[9].clear(),this.s[10].clear();for(let t of this.s[11])t.clear()},Ci=function(t,e,i,n){return{applied:e,deferred:i,durationMs:n,...void 0!==t?.identity?{identity:t.identity}:{},...void 0!==t?.data?{data:t.data}:{}}},Oi=function(){let 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)},ji=new Set(["__proto__","prototype","constructor"]),Ii="payload-live-preview-a11y",Ei=new WeakMap,Ri=class{constructor(t,e){ie(this,"s");let i=e??(typeof document>"u"?null:document),n=i?.documentElement.getAttribute("lang")??"";this.s=[$(t??(n.length>0?n:S())),i,null]}mount(){let t=this.s[1];if(null==t?.body)return null;let e=this.s[2];null===e&&(e=function(t){let e=Ei.get(t);return e??(e=[null,0,null,0,null]),Ei.set(t,e),e[3]+=1,e}(t),this.s[2]=e);let i=e[0];if(i?.isConnected&&i.ownerDocument===t)return i;if(null!==i){let t=e[1];A(e),t&&i.remove()}let n=t.getElementById(Ii);return e[1]=null===n,n||(n=t.createElement("div"),n.id=Ii,n.setAttribute("role","status"),n.setAttribute("aria-live","polite"),n.setAttribute("aria-atomic","true"),n.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(n)),e[0]=n,n}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?"\\xc4nderung":"\\xc4nderungen"} angewendet`:`${String(t)} ${1===t?"change":"changes"} applied`)}detach(){let t=this.s[2],e=this.s[1];if(null===t||null===e||(this.s[2]=null,t[3]-=1,t[3]>0))return;let i=t[0];null!==i&&A(t),t[1]&&i?.remove(),t[0]=null,Ei.delete(e)}say(t){let e=this.mount(),i=this.s[2];if(null===e||null===i)return;let n=i[2];n?.parentNode!==e?(n?.remove(),n=e.ownerDocument.createTextNode(e.hasChildNodes()?` ${t}`:t),i[2]=n,e.appendChild(n)):n.data=null===n.previousSibling?t:` ${t}`,null!==i[4]&&clearTimeout(i[4]);let r=setTimeout(()=>{i[4]===r&&i[0]===e&&A(i)},1500);i[4]=r}},_i=new Set(["tabs","row","collapsible"]),Li={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"},Wi=[0,500,1e3,2e3],Pi=class{constructor(t){le(this,Fi);ie(this,"d");ie(this,"l");let n=t.emitter,r=t.renderers,l=t.resolveRenderer??(t=>r[t]),s=t.transformValue,a=t.root??(typeof document<"u"?document:null),u=t.readyTargets,h=t.sendReady??j,c=t.onHeartbeatTimeout,d=void 0===t.log?i:e(t.log),f=void 0===t.warn?ue:e(t.warn),p=function(t){if(0==t.enableA11y)return null;let e=void 0===t.root?void 0:9===t.root.nodeType?t.root:t.root.ownerDocument;return new Ri(t.a11yLocale,e)}(t),g=void 0!==t.dataMerge?new fi({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)=>{d(...t)}}):null,m=new _e,v=new He({onStructuralChange:()=>{oe(this,Fi,Hi).call(this)},onVisibilityChange:(t,e)=>{e&&this.d[3].notifyVisible(t)}},{...void 0!==t.intersectionRootMargin?{intersectionRootMargin:t.intersectionRootMargin}:{}}),b=new wi(y(t=>oe(this,Fi,tn).call(this,t)),{...void 0!==t.debounceMs?{debounceMs:t.debounceMs}:{},...void 0!==t.disableVisibilityGate?{disableVisibilityGate:t.disableVisibilityGate}:{},...void 0!==t.visibilityGateThreshold?{visibilityGateThreshold:t.visibilityGateThreshold}:{},isVisible:t=>v.isVisible(t),getCacheSize:()=>m.elementCount,onFlush:t=>{oe(this,Fi,en).call(this,t)}}),w=new Ze(t.originMatcher,{onUpdate:(t,e,i)=>{oe(this,Fi,Ji).call(this,t,e,i)},onDocumentEvent:()=>{n.emit("documentSave",{timestamp:Date.now()})},onInvalid:(t,e)=>{if("token"===t){let t=new Error(`Preview token rejected (origin: ${e})`);n.emit("error",{error:t,context:"token"})}d("message rejected:",t,e)},...void 0!==t.validateToken?{validateToken:t.validateToken}:{}}),S=new di(()=>{}),$=new ci({...void 0!==t.heartbeatMs?{timeoutMs:t.heartbeatMs}:{},onTimeout:()=>{oe(this,Fi,nn).call(this)}});this.d=[n,m,v,b,w,S,$,r,l,s,a,u,h,c,d,f,[],p,g],this.l=[void 0,void 0,void 0,o(void 0),0,null,0,null,new Set]}start(){if(this.l[4])return 0;this.l[4]=1;let t=this.d[10];if(O(t)&&"loading"===t.readyState){let e=()=>{if(this.l[4]){this.l[5]=null;try{oe(this,Fi,Di).call(this)}catch(t){oe(this,Fi,zi).call(this),oe(this,Fi,ln).call(this,t,"startup")}}};this.l[5]=e;try{t.addEventListener("DOMContentLoaded",e,{once:1})}catch(t){throw oe(this,Fi,zi).call(this),t}return 1}try{return oe(this,Fi,Di).call(this),1}catch(t){throw oe(this,Fi,zi).call(this),t}}destroy(){this.l[4]&&(oe(this,Fi,Ui).call(this)&&this.d[0].emit("disconnect",{reason:"destroy",timestamp:Date.now()}),this.d[17]?.detach(),this.d[0].emit("destroy",{timestamp:Date.now()}))}refreshCache(){this.l[4]&&oe(this,Fi,Hi).call(this)}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]}},Fi=new WeakSet,Di=function(){if(!this.l[4])return;let t=O(this.d[10])?function(t){return t.body}(this.d[10]):this.d[10];if(null===t)throw new Error("LivePreviewRuntime: document.body unavailable");if(this.d[2].start(t),oe(this,Fi,Gi).call(this),oe(this,Fi,Qi).call(this)&&(this.d[4].attach(),this.d[0].emitWhile("init",{timestamp:Date.now()},()=>this.l[4]),oe(this,Fi,Qi).call(this)))for(let t of Wi){if(!oe(this,Fi,Qi).call(this))return;if(0===t){if(this.d[12](this.d[11]),!oe(this,Fi,Qi).call(this))return}else{let e=setTimeout(()=>{this.l[4]&&oe(this,Fi,rn).call(this)},t);this.d[16].push(e)}}},Ui=function(){this.l[7]=null,this.l[4]=0;let t=this.l[5];this.l[5]=null,null!==t&&O(this.d[10])&&oe(this,Fi,Vi).call(this,()=>{this.d[10].removeEventListener("DOMContentLoaded",t)});for(let t of this.d[16])oe(this,Fi,Vi).call(this,()=>{clearTimeout(t)});return this.d[16].length=0,oe(this,Fi,Vi).call(this,()=>{this.d[6].stop()}),oe(this,Fi,Vi).call(this,()=>{this.d[4].detach()}),oe(this,Fi,Vi).call(this,()=>{this.d[2].stop()}),oe(this,Fi,Vi).call(this,()=>{this.d[3].destroy()}),oe(this,Fi,Vi).call(this,()=>{this.d[18]?.destroy()}),this.d[1].clear(),this.d[5].markDisconnected()},zi=function(){oe(this,Fi,Ui).call(this),oe(this,Fi,Vi).call(this,()=>{this.d[17]?.detach()})},Vi=function(t){try{t()}catch(t){this.d[14]("cleanup failed:",t)}},Gi=function(){if(!this.l[4])return;let t=this.d[1].buildFromRoot(this.d[10]);if(this.d[14]("cache",t),oe(this,Fi,Qi).call(this)&&(this.d[0].emitWhile("cacheRefresh",t,()=>this.l[4]),oe(this,Fi,Qi).call(this)))for(let t of this.d[1].values()){if(!oe(this,Fi,Qi).call(this))return;this.d[2].observeElement(t.element)}},Hi=function(){if(!this.l[4])return;let t=new Map;for(let e of this.d[1].values())t.set(e.element,e),this.d[2].unobserveElement(e.element);if(oe(this,Fi,Gi).call(this),oe(this,Fi,Qi).call(this)){for(let e of this.d[1].values())t.get(e.element)?.fieldName===e.fieldName?this.d[3].retarget(e):this.d[3].forget(e.element),t.delete(e.element);for(let e of t.values())this.d[3].forget(e.element)}},qi=function(t){let e=o(t);e.negotiated!==this.l[3].negotiated&&(this.l[3]=e,this.d[14]("protocol","ours=4",`theirs=${t}`,`negotiated=${e.negotiated}`))},Ji=function(t,e,i){if(this.d[6].kick(),void 0===t.data){void 0!==t.protocolVersion&&oe(this,Fi,qi).call(this,t.protocolVersion);return}if(void 0===i)return;"string"==typeof t.locale&&(this.l[0]=t.locale),Array.isArray(t.fieldSchemaJSON)&&(this.l[1]=t.fieldSchemaJSON,this.l[2]=k(t.fieldSchemaJSON));let n={identity:i,message:t,locale:this.l[0],schema:this.l[1],schemaIndex:this.l[2],cancelled:0};this.l[7]=n,this.d[3].acceptRevision(i),this.l[6]+=1,(void 0===t.protocolVersion||(oe(this,Fi,qi).call(this,t.protocolVersion),this.l[4]&&this.l[7]===n))&&(this.d[5].markConnected()&&(this.d[17]?.announceConnected(),this.d[0].emit("connect",{origin:e,timestamp:Date.now()}),!this.l[4]||this.l[7]!==n||(this.d[14]("connection","disconnected","\\u2192","connected"),!this.l[4]||this.l[7]!==n))||oe(this,Fi,Bi).call(this,n))},Bi=async function(t){let e=await oe(this,Fi,Xi).call(this,t);if(null===e||!this.l[4]||this.l[7]!==t)return;let{message:i}=t,n={fields:e,...void 0!==t.schema?{schema:t.schema}:{},..."string"==typeof i.globalSlug?{globalSlug:i.globalSlug}:{},..."string"==typeof i.collectionSlug?{collectionSlug:i.collectionSlug}:{},...void 0!==t.locale?{locale:t.locale}:{}};this.d[0].listenerCount("beforeUpdate")>0&&(!await this.d[0].emitWhile("beforeUpdate",{data:n,revision:t.identity.revision,cancel:()=>{t.cancelled=1,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&&oe(this,Fi,Yi).call(this,t,n)},Xi=async function(t){let{message:e}=t,i=e.data??{};if(null===this.d[18])return i;let n=await this.d[18].merge({collectionSlug:e.collectionSlug,globalSlug:e.globalSlug,data:i,locale:t.locale});return this.l[4]&&this.l[7]===t?"merged"===n.status?n.doc:"superseded"===n.status?null:i:null},Yi=function(t,e){if(!this.l[4]||this.l[7]!==t)return;let i=()=>this.l[4]&&this.l[7]===t;for(let[n,r]of this.d[1].entries()){if(!this.l[4]||this.l[7]!==t)return;for(let l of r){let r=b(e.fields,n,l.locale??t.locale,void 0!==l.locale);if(void 0===r)continue;if(!this.l[4]||this.l[7]!==t)return;let s=oe(this,Fi,Ki).call(this,l,r,e.fields,i);if(!this.l[4]||this.l[7]!==t)return;let o={target:l,value:s,allFields:e.fields,identity:t.identity,data:e};if(!this.l[4]||this.l[7]!==t)return;this.d[3].schedule(o)}}oe(this,Fi,Zi).call(this,e.fields,t.locale)},Zi=function(t,e){if(0===this.d[1].fieldCount)return;let i;for(let[n,r]of Object.entries(t)){if(this.l[8].has(n)||on.has(n)||!E(r))continue;let t=R(n,e);if(void 0===this.d[1].get(n)&&(t===n||void 0===this.d[1].get(t))){if(void 0===i){i=new Set;for(let[t,e]of this.d[1].entries())for(let n of e)void 0!==n.locale&&i.add(`${t}_${n.locale}`)}i.has(n)||(this.l[8].add(n),this.d[15](`[live-preview] update arrived for field "${n}" but no <\\u2026 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.`))}}},Ki=function(e,i,n,r){if(void 0===this.d[9])return i;try{let l=this.d[9](e.fieldName,i,{element:e.element,allFields:n},r),s=t(l);if(!r())return i;if(s)throw new TypeError(`Transform for "${e.fieldName}" returned a Promise/thenable; transforms must be synchronous`);return l}catch(t){if(!r())return i;let e=t instanceof Error?t:new Error(String(t));return this.d[0].emit("error",{error:e,context:"transform"}),i}},Qi=function(){return this.l[4]},tn=function(t){let e=this.l[7];if(null===e||void 0===t.identity||!I(e.identity,t.identity)||!this.l[4]||this.l[7]!==e)return 0;let i=void 0!==e.schemaIndex?function(t,e){if(t.has(e))return t.get(e);let i=e.replace(/\\.\\d+(?=\\.|$)/g,".*");return t.has(i)?t.get(i):void 0}(e.schemaIndex,t.target.fieldName):void 0,n=t.value,r=function(t,e){if(t.explicitFieldType)return t.fieldType;if(void 0!==e){let t=function(t){if(Object.prototype.hasOwnProperty.call(Li,t))return Li[t]}(e);if(void 0!==t)return t}return t.fieldType}(t.target,i?.type);"text"===r&&1!=t.target.explicitFieldType&&function(t){if("object"!=typeof t||null===t||!("root"in t))return 0;let e=t.root;return"object"!=typeof e||null===e?0:Array.isArray(e.children)}(n)&&(r="richText");let l;try{l=this.d[8](r)}catch(t){if(!this.l[4]||this.l[7]!==e)return 0;let i=t instanceof Error?t:new Error(String(t));return this.d[0].emitWhile("error",{error:i,context:"renderer"},()=>this.l[4]&&this.l[7]===e),0}if(!this.l[4]||this.l[7]!==e)return 0;let s=this.d[0].listenerCount("elementUpdate")>0,o=s?function(t){return"INPUT"===t.tagName||"TEXTAREA"===t.tagName?t.value:"IMG"===t.tagName?t.src:t.textContent}(t.target.element):void 0;if(!this.l[4]||this.l[7]!==e)return 0;let a={allFields:t.allFields,locale:t.target.locale??e.locale,schema:i};try{if(void 0!==t.target.targetAttribute){if("blocked"===function(t,e,i){let n=e.toLowerCase().trim();if(0===n.length||n.startsWith("on")||yi.has(n))return"blocked";if(null==i)return t.removeAttribute(n),"applied";if("string"!=typeof i&&"number"!=typeof i&&"boolean"!=typeof i)return"blocked";let r=String(i);return vi.has(n)&&!g(r)?"blocked":(t.setAttribute(n,r),"applied")}(t.target.element,t.target.targetAttribute,n))return this.d[15](`[live-preview] refused to write field "${t.target.fieldName}" into attribute "${t.target.targetAttribute}" (unsafe attribute or value)`),0}else{if(!l)return this.d[14]("no renderer for",r),0;if(0==function(t,e,i,n){return t.render(e,i,n)}(l,t.target,n,a)&&function(t){return bi.has(t.render)}(l))return 0}}catch(t){if(!this.l[4]||this.l[7]!==e)return 0;let i=t instanceof Error?t:new Error(String(t));return this.d[0].emitWhile("error",{error:i,context:"renderer"},()=>this.l[4]&&this.l[7]===e),0}return this.l[4]&&this.l[7]===e?(s&&this.d[0].emitWhile("elementUpdate",{element:t.target.element,fieldName:t.target.fieldName,previousValue:o,nextValue:n,revision:e.identity.revision},()=>this.l[4]&&this.l[7]===e),this.l[4]&&this.l[7]===e):0},en=function(t){let{identity:e,data:i}=t;if(0===t.applied||void 0===e||void 0===i)return;let n=this.l[7];if(null===n||!this.l[4]||this.l[7]!==n||!I(n.identity,e))return;let r=()=>this.l[4]&&this.l[7]===n&&I(n.identity,e);this.d[17]?.announceUpdate(t.applied),r()&&0!==this.d[0].listenerCount("afterUpdate")&&this.d[0].emitWhile("afterUpdate",{data:i,updatedCount:t.applied,durationMs:t.durationMs,revision:e.revision},r)},nn=function(){if(!oe(this,Fi,Qi).call(this))return;this.d[4].advanceGeneration();let t=this.l[7];this.l[7]=null,null!==t&&this.d[3].cancelRevision(t.identity),this.d[18]?.destroy();let e=this.d[5].markDisconnected();try{this.d[13]?.()}catch(t){this.d[14]("heartbeat:",t)}oe(this,Fi,Qi).call(this)&&(e&&oe(this,Fi,sn).call(this)&&(this.d[17]?.announceDisconnected(),this.d[0].emitWhile("disconnect",{reason:"timeout",timestamp:Date.now()},()=>oe(this,Fi,sn).call(this)),!oe(this,Fi,Qi).call(this)||oe(this,Fi,sn).call(this)&&(this.d[14]("connection","connected","\\u2192","disconnected"),!oe(this,Fi,Qi).call(this)))||oe(this,Fi,Qi).call(this)&&oe(this,Fi,rn).call(this))},rn=function(){try{this.d[12](this.d[11])}catch(t){oe(this,Fi,ln).call(this,t,"ready")}},ln=function(t,e){let i=t instanceof Error?t:new Error(String(t));this.d[0].emit("error",{error:i,context:e})},sn=function(){return this.l[4]&&"disconnected"===this.d[5].status&&null===this.l[7]},on=new Set(["id","_id","createdAt","updatedAt","createdBy","updatedBy","_status","globalType","collection","locale","localized"]),an=/^https?:\\/\\/(localhost|127\\.0\\.0\\.1)(?::\\d+)?$/i,un=/^https?:\\/\\/[^/?#\\s]+$/i,hn=["PAYLOAD_ADMIN_ORIGIN","PUBLIC_PAYLOAD_ADMIN_ORIGIN","NEXT_PUBLIC_PAYLOAD_ADMIN_ORIGIN"],cn=class{constructor(t={}){le(this,dn);let e=new Set;for(let i of t.additionalOrigins??[]){let t=W(i);void 0!==t&&e.add(t)}for(let t of hn){let i=L(t);if(void 0!==i)for(let t of i.split(",")){let i=W(t);void 0!==i&&e.add(i)}}let i;if(t.enableReferrerDetection??1){let e=t.referrer??(typeof document<"u"?document.referrer:"");if(e.length>0)try{let t=new URL(e).origin;t&&"null"!==t&&(i=t)}catch{}}let n=(t.enableLocalhostMatching??1)&&(t.forceDevMode??function(){let t=function(){if(!(typeof process>"u"))return"production"}();if(void 0!==t)return"production"!==t;0;if(typeof window<"u"){let t=window.location.hostname;if("localhost"===t||"127.0.0.1"===t)return 1}return 0}());se(this,dn,[e,i,n,void 0!==i,void 0])}matches(t){return 0===t.length||"null"===t?0:void 0!==re(this,dn)[4]?t===re(this,dn)[4]:!!(re(this,dn)[0].has(t)||0===re(this,dn)[0].size&&void 0!==re(this,dn)[1]&&t===re(this,dn)[1]||re(this,dn)[2]&&an.test(t))}lockOrigin(t){return this.matches(t)?(re(this,dn)[4]=t,1):0}unlockOrigin(){let t=re(this,dn)[4];return re(this,dn)[4]=void 0,t}get lockedOrigin(){return re(this,dn)[4]}enumerate(){if(void 0!==re(this,dn)[4])return[re(this,dn)[4]];let t=new Set(re(this,dn)[0]);if(0===re(this,dn)[0].size&&void 0!==re(this,dn)[1]&&t.add(re(this,dn)[1]),re(this,dn)[2])for(let e of fn)t.add(`http://localhost:${String(e)}`),t.add(`http://127.0.0.1:${String(e)}`);return[...t]}get referrerWasAvailable(){return re(this,dn)[3]}get isProductionUnconfigured(){return!(!_()||re(this,dn)[0].size>0||re(this,dn)[2]||void 0!==re(this,dn)[1])}get isReferrerOnlyTrust(){return re(this,dn)[0].size>0||re(this,dn)[2]?0:void 0!==re(this,dn)[1]}},dn=new WeakMap,fn=[3e3,3001,3333,4e3,4321,5e3,5173,5174,8e3,8080,8888,9e3],pn=new Set(["p","br","strong","b","em","i","u","s","strike","mark","small","h1","h2","h3","h4","h5","h6","ul","ol","li","dl","dt","dd","blockquote","code","pre","kbd","samp","var","a","span","div","section","article","aside","header","footer","nav","figure","figcaption","img","picture","source","audio","video","sub","sup","hr","time","abbr","cite","q","table","thead","tbody","tfoot","tr","th","td","caption","colgroup","col"]),gn=new Set(["script","style","iframe","object","embed","link","meta","base","form","input","button","select","textarea","svg","math","template","frame","frameset","noframes","noscript"]),mn=new Set(["id","class","lang","dir","title","role","tabindex"]),yn="aria-",vn="data-",bn={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"])},wn=new Set(["href","src","cite","poster"]),Sn=1,$n=8,An=class extends Error{constructor(){super(...arguments);ie(this,"name","SanitizerEnvironmentError")}},kn=(Object.freeze({allowedTags:pn,removeCompletely:gn,globalAttributes:mn,attributesByTag:bn,urlAttributes:wn}),new Map),Tn={1:"left",2:"center",3:"right",4:"justify"},xn=new Set(["left","center","right","justify","start","end"]),Nn=Object.freeze({"&":"&amp;","<":"&lt;",">":"&gt;",\'"\':"&quot;","\'":"&#x27;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"}),Mn=/[&<>"\'/`=]/g,Cn=Object.freeze({"&":"&amp;","<":"&lt;",">":"&gt;",\'"\':"&quot;","\'":"&#x27;"}),On=/[&<>"\']/g,jn=new Set(["h1","h2","h3","h4","h5","h6"]),In=(t,e)=>{let i="string"==typeof t.url?t.url:"",n=e.renderChildren(t.children??[]);if(0===i.length||!g(i))return n;let r=m(i)?\' target="_blank" rel="noopener noreferrer"\':function(t){let e="string"==typeof t.target?t.target:"";if(0===e.length)return"";let i=B(e);return"_blank"===e?\' target="_blank" rel="noopener noreferrer"\':` target="${i}"`}(t),l="string"==typeof t.title?` title="${B(t.title)}"`:"";return`<a href="${X(i)}"${r}${l}>${n}</a>`},En=new Map;V("text",t=>{let e=B("string"==typeof t.text?t.text:""),i="number"==typeof t.format?t.format:0;return!!(16&i)&&(e=`<code>${e}</code>`),!!(1&i)&&(e=`<strong>${e}</strong>`),!!(2&i)&&(e=`<em>${e}</em>`),!!(8&i)&&(e=`<u>${e}</u>`),!!(4&i)&&(e=`<s>${e}</s>`),!!(32&i)&&(e=`<sub>${e}</sub>`),!!(64&i)&&(e=`<sup>${e}</sup>`),!!(128&i)&&(e=`<mark>${e}</mark>`),e});V("paragraph",(t,e)=>{let i=e.renderChildren(t.children??[]);return`<p${q(t)}${J(t)}>${i}</p>`});V("heading",(t,e)=>{let i="string"==typeof t.tag?t.tag.toLowerCase():"h2",n=jn.has(i)?i:"h2",r=e.renderChildren(t.children??[]);return`<${n}${q(t)}${J(t)}>${r}</${n}>`});V("list",(t,e)=>{let i="string"==typeof t.listType?t.listType:"bullet",n="number"===i?"ol":"ul",r="number"===i&&"number"==typeof t.start&&t.start>1?` start="${String(t.start)}"`:"",l="check"===i?\' role="list"\':"",s=e.renderChildren(t.children??[]);return`<${n}${q(t)}${J(t)}${r}${l}>${s}</${n}>`});V("listitem",(t,e)=>{let i=e.renderChildren(t.children??[]);if("boolean"==typeof t.checked)return`<li role="checkbox" aria-checked="${t.checked?"true":"false"}"${J(t)}>${i}</li>`;let n="number"==typeof t.value?` value="${B(String(t.value))}"`:"";return`<li${q(t)}${J(t)}${n}>${i}</li>`});V("link",In);V("autolink",In);V("quote",(t,e)=>{let i=e.renderChildren(t.children??[]);return`<blockquote${q(t)}${J(t)}>${i}</blockquote>`});V("code",t=>{let e=K("string"==typeof t.language?t.language:"");return`<pre><code${""===e?"":` class="language-${e}"`}>${B(Z(t))}</code></pre>`});V("code-highlight",t=>{let e="string"==typeof t.text?t.text:"";return`<span${"string"==typeof t.highlightType?` class="token-${K(t.highlightType)}"`:""}>${B(e)}</span>`});V("linebreak",()=>"<br>");V("horizontalrule",()=>"<hr>");V("tab",()=>"\\t");V("upload",t=>{let e=function(t){let e=t.value;if("object"==typeof e&&null!==e)return e}(t);if(void 0===e)return"";let i=e.url;if("string"!=typeof i||!g(i))return"";let n="string"==typeof e.mimeType?e.mimeType:"";return n.startsWith("video/")?function(t,e){let i="number"==typeof t.width?` width="${String(t.width)}"`:"",n="number"==typeof t.height?` height="${String(t.height)}"`:"",r="string"==typeof t.mimeType?` type="${X(t.mimeType)}"`:"";return`<video controls${i}${n}><source src="${X(e)}"${r}></video>`}(e,i):n.startsWith("audio/")?function(t,e){let i="string"==typeof t.mimeType?` type="${X(t.mimeType)}"`:"";return`<audio controls><source src="${X(e)}"${i}></audio>`}(e,i):""===n||n.startsWith("image/")?function(t,e){let i="string"==typeof t.alt?B(t.alt):"",n="number"==typeof t.width?` width="${String(t.width)}"`:"",r="number"==typeof t.height?` height="${String(t.height)}"`:"";return`<img src="${X(e)}" alt="${i}"${n}${r} loading="lazy" decoding="async">`}(e,i):function(t,e){let i="string"==typeof t.filename?B(t.filename):B(e);return`<a href="${X(e)}" target="_blank" rel="noopener noreferrer">${i}</a>`}(e,i)});V("relationship",t=>{let e="string"==typeof t.relationTo?t.relationTo:"",i=function(t){let e=t.value;if("object"==typeof e&&null!==e)return e}(t),n=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}`}(i,e),r=B(n),l=""===e?"":` data-relation-to="${B(e)}"`,s=i?.url;return"string"==typeof s&&g(s)?`<a href="${X(s)}"${l}>${r}</a>`:`<span${l}>${r}</span>`});V("block",(t,e)=>{let i=function(t){let e=t.fields;return"object"!=typeof e||null===e?{}:e}(t),n="string"==typeof i.blockType?i.blockType:"",r=tt(n);if(""!==n){let t=Q(n)??Q(r);if(t)return t(i,{renderChildren:e.renderChildren})}let l=[];""!==r&&l.push(`data-block-type="${B(r)}"`);for(let[t,e]of Object.entries(i)){if("blockType"===t||"id"===t||null==e)continue;let i="string"==typeof e||"number"==typeof e||"boolean"==typeof e?String(e):JSON.stringify(e);l.push(`data-block-${tt(t)}="${B(i)}"`)}return`<div${0===l.length?"":` ${l.join(" ")}`}></div>`});jt={renderChildren:nt,resolveAlignment:G,resolveIndent:H};It="data-payload-text";Et={name:"textarea",render(t,e){let i=t.element,n=et(e)?it(e):ot(e);"INPUT"!==i.tagName&&"TEXTAREA"!==i.tagName?i.innerHTML=Y(n):i.value=n}};Rt={name:"richText",render:y((t,e)=>{if(et(e))t.element.innerHTML=function(t,e={}){if(!et(t))return"";let i=nt(t.root.children);return 0==e.sanitize||void 0===F()?i:P(i)}(e);else{if("string"!=typeof e)return 0;t.element.innerHTML=P(e)}})};_t={name:"html",render(t,e){if(null==e){t.element.textContent="";return}let i="string"==typeof e?e:ot(e);t.element.innerHTML=P(i)}};Lt={name:"url",render(t,e,i){let n=t.element,r=ot(e);if("A"===n.tagName){let l=n,s=t.hrefField,o=void 0===s||0===s.length?e:b(i.allFields,s,i.locale,void 0!==t.locale);"string"==typeof o&&g(o)&&(l.href=o),l.textContent=r;return}"INPUT"!==n.tagName&&"TEXTAREA"!==n.tagName?n.textContent=r:n.value=r}};Wt={name:"image",render:y((t,e,i)=>{let n=t.element,r=at(e),l=void 0!==t.locale,s=function(t,e,i,n,r,l){if(void 0!==i&&i.length>0){let t=b(n,i,r,l);if("string"==typeof t&&g(t))return t;let e=at(t);return void 0!==e?.url&&g(e.url)?e.url:void 0}return void 0!==t?.url&&g(t.url)?t.url:"string"==typeof e&&g(e)?e:void 0}(r,e,t.srcField,i.allFields,i.locale,l);if(void 0===s)return 0;if("IMG"===n.tagName){let e=n;e.src=s;let o=function(t,e,i,n,r){if(void 0!==e&&e.length>0){let t=b(i,e,n,r);return"string"==typeof t?t:void 0}if(void 0!==t?.alt)return t.alt}(r,t.altField,i.allFields,i.locale,l);void 0!==o&&(e.alt=o);return}n.style.backgroundImage=`url(\'${function(t){return t.replace(/[\'"()\\\\]/g,"\\\\$&")}(s)}\')`})};Pt={name:"upload",render:y((t,e)=>{let i=t.element,n=function(t){if("object"==typeof t&&null!==t)return t}(e);if(void 0===n)return 0;let r=n.url;if("string"!=typeof r||!g(r))return 0;if("IMG"===i.tagName){let t=i;t.src=r,void 0!==n.alt&&(t.alt=n.alt);return}if("A"===i.tagName){let t=i;t.href=r,t.textContent=n.filename??r;return}let l=void 0!==n.filename?B(n.filename):B(r);i.innerHTML=`<a href="${X(r)}">${l}</a>`})};Ft={name:"relationship",render(t,e){let i=t.element,n=function(t){return null==t?[""]:Array.isArray(t)?t.map(ut):[ut(t)]}(e).join(", ");if("A"===i.tagName&&!Array.isArray(e)){let t=i,r=e?.url;"string"==typeof r&&g(r)&&(t.href=r),t.textContent=n;return}i.textContent=n}};Dt={name:"select",render(t,e){let i=t.element,n=ht(e);if("SELECT"!==i.tagName){if("INPUT"===i.tagName&&"radio"===i.type){let t=i;t.checked=t.value===n;return}i.textContent=n}else i.value=n}};Ut={name:"checkbox",render(t,e){let i=t.element,n=!!e;"INPUT"!==i.tagName||"checkbox"!==i.type?i.hasAttribute("aria-checked")?i.setAttribute("aria-checked",n?"true":"false"):i.textContent=n?"true":"false":i.checked=n}};zt=new Map,Vt=new Map,Gt=64;Ht={name:"date",render(t,e,i){let n=t.element;if(null==e||""===e){"INPUT"===n.tagName?n.value="":("TIME"===n.tagName&&n.removeAttribute("datetime"),n.textContent="");return}let r="string"==typeof e?e:ot(e),l=new Date(r),s=!Number.isNaN(l.getTime());"INPUT"!==n.tagName?("TIME"!==n.tagName||n.setAttribute("datetime",s?l.toISOString():r),n.textContent=s?function(t,e){let i=e.locale??S();try{return function(t,e){let i=ct(t,e),n=Vt.get(i);if(void 0!==n)return Vt.delete(i),Vt.set(i,n),n;let r=new Intl.DateTimeFormat(t,e);return Vt.set(i,r),ft(Vt),r}(i,{dateStyle:"medium",timeStyle:"short"}).format(t)}catch{return t.toISOString()}}(l,i):r):n.value=s?function(t,e){return"date"===t?e.toISOString().slice(0,10):"datetime-local"===t?e.toISOString().slice(0,16):e.toISOString()}(n.type,l):r}};qt={name:"number",render(t,e,i){let n=t.element;if(null==e||""===e){"INPUT"===n.tagName?n.value="":n.textContent="";return}let r="number"==typeof e?e:Number(ot(e));Number.isNaN(r)?n.textContent=ot(e):"INPUT"!==n.tagName?n.textContent=function(t,e){let i=e.locale??S();try{return function(t,e){let i=ct(t,e),n=zt.get(i);if(void 0!==n)return zt.delete(i),zt.set(i,n),n;let r=new Intl.NumberFormat(t,e);return zt.set(i,r),ft(zt),r}(i).format(t)}catch{return String(t)}}(r,i):n.value=String(r)}};Jt=/\\{\\{([\\s\\S]*?)\\}\\}/g;Bt={name:"array",render:y((t,e)=>{let i=t.element;if(!Array.isArray(e))return 0;let n=t.arrayTemplate;if(void 0!==n&&n.length>0){let t=function(t,e){let i="";for(let n=0;n<e.length;n+=1)i+=gt(t,e[n],n);return i}(n,e);i.innerHTML=P(t);return}let r=t.arraySeparator??", ";i.textContent=e.map(mt).join(r)})};Xt="data-payload-key",Yt="data-payload-nested-key",Zt="data-payload-nested-template";Kt=new Map;Qt=[Et,Rt,_t,Lt,{...Lt,name:"email"},Wt,Pt,Ft,Dt,{...Dt,name:"radio"},Ut,Ht,qt,Bt,{...Bt,name:"blocks"}];!function(){if(typeof window>"u"||!_()&&(typeof window>"u"||null==window.opener))return;let t=window.__livePreview;if(void 0!==t)return t;let[e=[],i="",n="/api",r=1,l=0,s=50,o=1,a=0,u=0,h=50,c="200px",d=0,f=0]=typeof __LIVE_PREVIEW_CONFIG__>"u"?[]:__LIVE_PREVIEW_CONFIG__,p=new cn({additionalOrigins:e,enableReferrerDetection:!d,enableLocalhostMatching:!f});p.isProductionUnconfigured?ue("[live-preview] No trusted origin. Set PAYLOAD_ADMIN_ORIGIN or pass allowedOrigins to generateInlineScript()."):p.isReferrerOnlyTrust&&ue("[live-preview] document.referrer fallback trusts any framing site. Set allowedOrigins and a frame-ancestors CSP in production.");let g=new ce,m=function(t=[]){let e={};for(let i of t)e[i.name]=i;for(let[t,i]of Kt)e[t]=i;return Object.freeze(e)}([st(),...Qt,Ct()]),y=new Pi({renderers:m,originMatcher:t=>p.matches(t),readyTargets:p.enumerate(),emitter:g,...""!==i?{dataMerge:{serverURL:i,apiRoute:n,depth:r}}:{},debounceMs:s,heartbeatMs:a,intersectionRootMargin:c,disableVisibilityGate:u,visibilityGateThreshold:h,enableA11y:o,onHeartbeatTimeout:()=>{p.unlockOrigin()},...l?{log:(...t)=>{he("[live-preview]",...t)}}:{}});g.on("connect",t=>{p.lockOrigin(t.origin)}),y.start();let v=Object.freeze({version:"1.0.4",destroy:()=>{y.destroy();let t=window;t.__livePreview===v&&delete t.__livePreview},refresh:()=>{y.refreshCache()},enumerateOrigins:()=>p.enumerate()});try{Object.defineProperty(window,"__livePreview",{value:v,writable:0,configurable:1})}catch(t){throw y.destroy(),t}}()})();';function d(t={}){if(0===c.length)throw new Error("[live-preview] runtime.generated.ts is empty. Run `npm run build:runtime` before bundling.");let e=[t.allowedOrigins,t.serverURL,t.apiRoute,t.mergeDepth,t.debug,t.debounceMs,t.enableA11y,t.heartbeatMs,t.disableVisibilityGate,t.visibilityGateThreshold,t.intersectionRootMargin,t.disableReferrerDetection,t.disableLocalhostMatching];for(;e.length>0&&void 0===e.at(-1);)e.pop();return[`var __LIVE_PREVIEW_CONFIG__=${`[${e.map(t=>void 0===t?"":JSON.stringify(t)).join(",")}]`.replace(/</g,"\\u003C")};`,c].join("\n")}function f(t,e={}){return`<script${void 0!==e.nonce?` nonce="${p(e.nonce)}"`:""}>${t}<\/script>`}function p(t){if(!/^[A-Za-z0-9+/=_-]+$/.test(t))throw new RangeError("wrapWithScriptTag: nonce contains invalid characters");return t}e(d,"generateInlineScript"),e(f,"wrapWithScriptTag"),e(p,"escapeNonce");var g=["preview","draft","livePreview"];function m(t,e={}){let i=new Set(e.signals??["query","fetch-dest","referer"]),n=e.queryParams??g,r=(e.checkFetchDest??!0)&&i.has("fetch-dest");if(i.has("query")){let e;try{e=new URL(t.url)}catch{e=void 0}if(void 0!==e)for(let t of n){let i=e.searchParams.get(t);if("true"===i||"1"===i)return!0}}if(r&&"iframe"===t.headers.get("sec-fetch-dest"))return!0;let l=i.has("referer")?e.adminOrigins??[]:[];if(l.length>0){let e=t.headers.get("referer");if(null!==e)try{let t=new URL(e).origin;for(let e of l)try{if(new URL(e).origin===t)return!0}catch{}}catch{}}return!1}e(m,"isPreviewRequest");var y=/text\/html/i,v=/<head(\s[^>]*)?>/i;function b(t={}){let i,n=e(()=>(i??=S(t),i),"scriptBody");return async(e,i)=>{if("always"!==(t.inject??"preview-only")&&!m(e,{...void 0!==t.previewQueryParams?{queryParams:t.previewQueryParams}:{},...void 0!==t.previewSignals?{signals:t.previewSignals}:{},adminOrigins:t.allowedOrigins??[]}))return i;let r=i,l=(t.autoInject??!0)&&(t.shouldInject?.(e)??!0),s=i.headers.get("content-type")??"";l&&y.test(s)&&(r=await T(i,n()));let o=$(t.manageCsp);return!1!==o&&(r=A(r,o,t)),r}}function w(t={}){return f(d({...void 0!==t.allowedOrigins?{allowedOrigins:t.allowedOrigins}:{},...void 0!==t.serverURL?{serverURL:t.serverURL}:{},...void 0!==t.apiRoute?{apiRoute:t.apiRoute}:{},...void 0!==t.mergeDepth?{mergeDepth:t.mergeDepth}:{},...void 0!==t.debug?{debug:t.debug}:{},...void 0!==t.debounceMs?{debounceMs:t.debounceMs}:{},...void 0!==t.heartbeatMs?{heartbeatMs:t.heartbeatMs}:{},...void 0!==t.nonce?{nonce:t.nonce}:{}}),void 0!==t.nonce?{nonce:t.nonce}:{})}function S(t){return d({...void 0!==t.allowedOrigins?{allowedOrigins:t.allowedOrigins}:{},...void 0!==t.serverURL?{serverURL:t.serverURL}:{},...void 0!==t.apiRoute?{apiRoute:t.apiRoute}:{},...void 0!==t.mergeDepth?{mergeDepth:t.mergeDepth}:{},...void 0!==t.debug?{debug:t.debug}:{},...void 0!==t.debounceMs?{debounceMs:t.debounceMs}:{},...void 0!==t.heartbeatMs?{heartbeatMs:t.heartbeatMs}:{}})}function $(t){return!1!==t&&("full"===t?"full":"frame-ancestors")}async function T(t,e){let i=t.headers.get("x-live-preview-nonce")??l(),n=await t.text(),r=new Headers(t.headers);if(r.delete("content-length"),r.set("x-live-preview-nonce",i),!v.test(n))return new Response(n,{status:t.status,statusText:t.statusText,headers:r});let s=f(e,{nonce:i}),o=n.replace(v,t=>`${t}${s}`);return new Response(o,{status:t.status,statusText:t.statusText,headers:r})}function A(t,e,i){let n=t.headers.get("x-live-preview-nonce")??l(),r={"frame-ancestors":a({self:!0,origins:[...i.allowedOrigins??[],...i.frameAncestorsExtra??[]]})};"full"===e&&(r["script-src"]=u(n,{self:!0,strictDynamic:i.strictDynamic??!1,...void 0!==i.scriptSrcExtra?{extra:i.scriptSrcExtra}:{}}));let s=h(t.headers.get("content-security-policy")??"",r);try{return t.headers.set("x-live-preview-nonce",n),t.headers.set("content-security-policy",s),t}catch{let e=new Headers(t.headers);return e.set("x-live-preview-nonce",n),e.set("content-security-policy",s),new Response(t.body,{status:t.status,statusText:t.statusText,headers:e})}}e(b,"createLivePreviewMiddleware"),e(w,"renderLivePreviewScript"),e(S,"buildScriptBody"),e($,"normalizeManageCsp"),e(T,"injectIntoResponse"),e(A,"addCsp");export{b as createLivePreviewMiddleware,w as renderLivePreviewScript};
306
2
  //# sourceMappingURL=index.js.map