payload-live-preview 2.2.2 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -17
- package/dist/adapters/astro/PreviewBoundary.astro +17 -4
- package/dist/adapters/astro/RichText.astro +13 -2
- package/dist/adapters/astro/index.d.ts +7 -7
- package/dist/adapters/astro/index.js +1 -1
- package/dist/adapters/astro/index.js.map +1 -1
- package/dist/adapters/astro/middleware-entry.d.ts +3 -3
- package/dist/adapters/astro/middleware-entry.js +1 -1
- package/dist/adapters/astro/middleware-entry.js.map +1 -1
- package/dist/adapters/nextjs/index.d.ts +2 -2
- package/dist/adapters/nextjs/index.js +1 -1
- package/dist/adapters/nextjs/index.js.map +1 -1
- package/dist/adapters/nuxt/index.d.ts +4 -4
- package/dist/adapters/nuxt/index.js +1 -1
- package/dist/adapters/nuxt/index.js.map +1 -1
- package/dist/adapters/nuxt/module.d.ts +1 -1
- package/dist/adapters/react/index.d.ts +2 -2
- package/dist/adapters/react/index.js +1 -1
- package/dist/adapters/react/index.js.map +1 -1
- package/dist/adapters/sveltekit/index.d.ts +5 -5
- package/dist/adapters/sveltekit/index.js +1 -1
- package/dist/adapters/sveltekit/index.js.map +1 -1
- package/dist/adapters/vue/index.d.ts +2 -2
- package/dist/adapters/vue/index.js +1 -1
- package/dist/adapters/vue/index.js.map +1 -1
- package/dist/client.cjs +1 -1
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +15 -3
- package/dist/client.d.ts +15 -3
- package/dist/client.js +1 -1
- package/dist/client.js.map +1 -1
- package/dist/codegen-astro.js +1 -1
- package/dist/codegen-astro.js.map +1 -1
- package/dist/codegen-cli.js +1 -1
- package/dist/codegen-cli.js.map +1 -1
- package/dist/codegen.cjs +1 -1
- package/dist/codegen.cjs.map +1 -1
- package/dist/codegen.js +1 -1
- package/dist/codegen.js.map +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +139 -4
- package/dist/core.d.ts +139 -4
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/doctor-cli.d.ts +1 -1
- package/dist/doctor-cli.js +1 -1
- package/dist/doctor-cli.js.map +1 -1
- package/dist/doctor.d.ts +2 -2
- package/dist/doctor.js +1 -1
- package/dist/doctor.js.map +1 -1
- package/dist/{document-session-Bkd181PV.d.ts → document-session-BuYuO3ae.d.ts} +27 -2
- package/dist/{fragment-endpoint-CLRpNQ3n.d.ts → fragment-endpoint-CQE_7MKi.d.ts} +1 -1
- package/dist/fragment.cjs +1 -1
- package/dist/fragment.cjs.map +1 -1
- package/dist/fragment.d.cts +6 -2
- package/dist/fragment.d.ts +6 -2
- package/dist/fragment.js +1 -1
- package/dist/fragment.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +73 -12
- package/dist/index.d.ts +73 -12
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lean.cjs +1 -1
- package/dist/lean.cjs.map +1 -1
- package/dist/lean.js +1 -1
- package/dist/lean.js.map +1 -1
- package/dist/lexical.cjs +1 -1
- package/dist/lexical.cjs.map +1 -1
- package/dist/lexical.d.cts +16 -4
- package/dist/lexical.d.ts +16 -4
- package/dist/lexical.js +1 -1
- package/dist/lexical.js.map +1 -1
- package/dist/{locals-zz2gi9dj.d.ts → locals-CyzDKfKU.d.ts} +7 -1
- package/dist/{middleware-CI-UTf6R.d.ts → middleware-Dnt6u4nF.d.ts} +2 -2
- package/dist/{options-CnYybG51.d.ts → options-DTzhFVJ4.d.ts} +13 -1
- package/dist/plugin.cjs +1 -1
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts +15 -9
- package/dist/plugin.d.ts +15 -9
- package/dist/plugin.js +1 -1
- package/dist/plugin.js.map +1 -1
- package/dist/plugins.cjs +1 -1
- package/dist/plugins.cjs.map +1 -1
- package/dist/plugins.d.cts +8 -2
- package/dist/plugins.d.ts +8 -2
- package/dist/plugins.js +1 -1
- package/dist/plugins.js.map +1 -1
- package/dist/{probe-D-IHg9dF.d.ts → probe-afwdYebU.d.ts} +6 -2
- package/dist/server.cjs +1 -1
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +19 -1
- package/dist/server.d.ts +19 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/structural.d.cts +2 -0
- package/dist/structural.d.ts +2 -0
- package/package.json +2 -1
package/dist/fragment.d.cts
CHANGED
|
@@ -33,6 +33,8 @@ declare const DIAGNOSTIC_CODES: Readonly<{
|
|
|
33
33
|
readonly UnattributableUpdate: "LP0202";
|
|
34
34
|
/** An update carried a value for a field the page binds nowhere; editing it changes nothing on this page. */
|
|
35
35
|
readonly UnboundField: "LP0203";
|
|
36
|
+
/** In development: a bound path covers its group under the `descendant` default, which 3.0 changes. */
|
|
37
|
+
readonly CoverageDefaultChanges: "LP0204";
|
|
36
38
|
/** The visibility gate held offscreen writes back until they scroll into view. */
|
|
37
39
|
readonly VisibilityGateDeferred: "LP0301";
|
|
38
40
|
/** A value was refused because the attribute or the value itself is unsafe. */
|
|
@@ -57,7 +59,7 @@ declare const DIAGNOSTIC_CODES: Readonly<{
|
|
|
57
59
|
readonly UnrenderedBlockKept: "LP0410";
|
|
58
60
|
/** A patch cannot reach what the server would have drawn; `onUnfaithfulPatch` decided what happens next. */
|
|
59
61
|
readonly UnfaithfulPatch: "LP0411";
|
|
60
|
-
/** The first write to a date, number or
|
|
62
|
+
/** The first write to a date, number, checkbox, select or radio binding replaced a different reading of the same value. */
|
|
61
63
|
readonly ServerFormatReplaced: "LP0412";
|
|
62
64
|
/** A Lexical block has no renderer, and the write could not keep the markup the server rendered for it; it is gone. */
|
|
63
65
|
readonly UnrenderedBlockLost: "LP0413";
|
|
@@ -77,7 +79,7 @@ declare const DIAGNOSTIC_CODES: Readonly<{
|
|
|
77
79
|
readonly StartupFailed: "LP0605";
|
|
78
80
|
/** Sending the ready handshake failed. */
|
|
79
81
|
readonly ReadyFailed: "LP0606";
|
|
80
|
-
/** The page declared hydration, but no React commit, Vue mount
|
|
82
|
+
/** The page declared hydration, but no React commit, Vue mount, SvelteKit mount or `markHydrated()` call came within the cap; the runtime started without waiting. */
|
|
81
83
|
readonly HydrationWaitTimedOut: "LP0607";
|
|
82
84
|
/** The audit found no runtime in a response that carried preview intent. */
|
|
83
85
|
readonly AuditRuntimeMissing: "LP0701";
|
|
@@ -119,6 +121,8 @@ declare const DIAGNOSTIC_CODES: Readonly<{
|
|
|
119
121
|
readonly V2ReadinessGap: "LP0709";
|
|
120
122
|
/** The preview runtime is served to anonymous visitors, not only inside the admin frame. */
|
|
121
123
|
readonly RuntimeOnPublicPage: "LP0710";
|
|
124
|
+
/** An element carries attributes that only mean something beside `data-payload-field`, and has none. */
|
|
125
|
+
readonly AuditModifierWithoutField: "LP0711";
|
|
122
126
|
}>;
|
|
123
127
|
/** A diagnostic code, as it appears in log output and on the `error` event. */
|
|
124
128
|
type DiagnosticCode = (typeof DIAGNOSTIC_CODES)[keyof typeof DIAGNOSTIC_CODES];
|
package/dist/fragment.d.ts
CHANGED
|
@@ -33,6 +33,8 @@ declare const DIAGNOSTIC_CODES: Readonly<{
|
|
|
33
33
|
readonly UnattributableUpdate: "LP0202";
|
|
34
34
|
/** An update carried a value for a field the page binds nowhere; editing it changes nothing on this page. */
|
|
35
35
|
readonly UnboundField: "LP0203";
|
|
36
|
+
/** In development: a bound path covers its group under the `descendant` default, which 3.0 changes. */
|
|
37
|
+
readonly CoverageDefaultChanges: "LP0204";
|
|
36
38
|
/** The visibility gate held offscreen writes back until they scroll into view. */
|
|
37
39
|
readonly VisibilityGateDeferred: "LP0301";
|
|
38
40
|
/** A value was refused because the attribute or the value itself is unsafe. */
|
|
@@ -57,7 +59,7 @@ declare const DIAGNOSTIC_CODES: Readonly<{
|
|
|
57
59
|
readonly UnrenderedBlockKept: "LP0410";
|
|
58
60
|
/** A patch cannot reach what the server would have drawn; `onUnfaithfulPatch` decided what happens next. */
|
|
59
61
|
readonly UnfaithfulPatch: "LP0411";
|
|
60
|
-
/** The first write to a date, number or
|
|
62
|
+
/** The first write to a date, number, checkbox, select or radio binding replaced a different reading of the same value. */
|
|
61
63
|
readonly ServerFormatReplaced: "LP0412";
|
|
62
64
|
/** A Lexical block has no renderer, and the write could not keep the markup the server rendered for it; it is gone. */
|
|
63
65
|
readonly UnrenderedBlockLost: "LP0413";
|
|
@@ -77,7 +79,7 @@ declare const DIAGNOSTIC_CODES: Readonly<{
|
|
|
77
79
|
readonly StartupFailed: "LP0605";
|
|
78
80
|
/** Sending the ready handshake failed. */
|
|
79
81
|
readonly ReadyFailed: "LP0606";
|
|
80
|
-
/** The page declared hydration, but no React commit, Vue mount
|
|
82
|
+
/** The page declared hydration, but no React commit, Vue mount, SvelteKit mount or `markHydrated()` call came within the cap; the runtime started without waiting. */
|
|
81
83
|
readonly HydrationWaitTimedOut: "LP0607";
|
|
82
84
|
/** The audit found no runtime in a response that carried preview intent. */
|
|
83
85
|
readonly AuditRuntimeMissing: "LP0701";
|
|
@@ -119,6 +121,8 @@ declare const DIAGNOSTIC_CODES: Readonly<{
|
|
|
119
121
|
readonly V2ReadinessGap: "LP0709";
|
|
120
122
|
/** The preview runtime is served to anonymous visitors, not only inside the admin frame. */
|
|
121
123
|
readonly RuntimeOnPublicPage: "LP0710";
|
|
124
|
+
/** An element carries attributes that only mean something beside `data-payload-field`, and has none. */
|
|
125
|
+
readonly AuditModifierWithoutField: "LP0711";
|
|
122
126
|
}>;
|
|
123
127
|
/** A diagnostic code, as it appears in log output and on the `error` event. */
|
|
124
128
|
type DiagnosticCode = (typeof DIAGNOSTIC_CODES)[keyof typeof DIAGNOSTIC_CODES];
|
package/dist/fragment.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function e(e,t){const n=new AbortController;let r=!1;const o=()=>{n.abort()};e.addEventListener("abort",o,{once:!0});const i=setTimeout(()=>{r=!0,n.abort()},t);return{signal:n.signal,timedOut:()=>r,dispose:()=>{clearTimeout(i),e.removeEventListener("abort",o)}}}function t(e){return e instanceof Error?e.message:String(e)}var n="data-payload-island",r="data-payload-owned";function o(e){if(e.tagName.toLowerCase().includes("-")&&!e.hasAttribute("data-payload-morph"))return!0;if(i(e)||e.hasAttribute(r))return!0;const t=e.getAttribute("contenteditable");return null!==t&&"false"!==t}function i(e){return function(e){return"astro-island"===e.tagName.toLowerCase()||e.hasAttribute(n)}(e)&&!("patch"===e.getAttribute(n))}function isInsideIsland(e){let t=e;for(;null!==t;){if(i(t))return!0;t=t.parentElement}return!1}var a=["component-url","component-export","renderer-url","client","opts","before-hydration-url"],s=/* @__PURE__ */new WeakMap,l=/* @__PURE__ */new WeakSet;function u(e){return"astro-island"===e.tagName.toLowerCase()}function c(e){let t="";for(const n of e.querySelectorAll("astro-slot, template[data-astro-template]"))n.parentElement?.closest("astro-island")===e&&(t+=`${n.getAttribute("name")??n.getAttribute("data-astro-template")??""}\0${n.innerHTML}\0`);return t}function d(e,t){if(!u(e)||!u(t))return!0;const n=c(t);if(!a.every(n=>e.getAttribute(n)===t.getAttribute(n))||(s.get(e)??c(e))!==n||e.getAttribute("props")!==t.getAttribute("props")&&!function(e){const t=e.ownerDocument.defaultView?.customElements.get("astro-island");return void 0!==t&&e instanceof t&&Array.isArray(t.observedAttributes)&&t.observedAttributes.includes("props")}(e))return s.set(t,n),!1;s.set(e,n);const r=t.getAttribute("props");return r!==e.getAttribute("props")&&(e.setAttribute("ssr",""),null===r?e.removeAttribute("props"):e.setAttribute("props",r)),!0}function f(e){if(null==e)return[];const t=/* @__PURE__ */new Set,n=[];for(const r of e.split(/[\s,]+/)){const e=r.trim();0===e.length||t.has(e)||(t.add(e),n.push(e))}return n}var g="data-payload-fragment",p="data-payload-fragment-key";function h(e){const t=e.getAttribute("data-payload-strategy");return null!==t&&t.length>0?"patch"===t||"fragment"===t||"route"===t?t:void 0:null!==function(e){return e.closest(`[${g}]`)}(e)?"fragment":null!==e.closest("head")?"route":"patch"}function m(e){const t=e.getAttribute(g);if(null===t||0===t.length)return null;const n=e.getAttribute(p);return{element:e,id:t,key:null===n||0===n.length?void 0:n,dependsOn:f(e.getAttribute("data-payload-depends"))}}function y(e,t){const n=[];for(const r of e.querySelectorAll(`[${g}]`)){const e=m(r);null===e||isInsideIsland(r)||e.dependsOn.length>0&&!e.dependsOn.some(e=>t.has(e))||n.push(e)}return n}var b=1,v="x-payload-fragment-version";function L(e,t,n){if(t>n||"object"!=typeof e||null===e)return t;let r=t;for(const o of Object.values(e))if(r=Math.max(r,L(o,t+1,n)),r>n)break;return r}function A(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function P(e,t=64){const n=function(e,t=64){if(!Number.isInteger(t)||t<0||t>64)return null;if(!A(e))return null;const n=e.fragment;if("string"!=typeof n||!/^[a-z][a-z0-9-]{0,63}$/iu.test(n))return null;const r=e.key;if(void 0!==r&&("string"!=typeof r||r.length>128))return null;const o=e.route;if("string"!=typeof o||!o.startsWith("/")||o.length>2048)return null;const i=e.search;if("string"!=typeof i||i.length>4096||""!==i&&!i.startsWith("?"))return null;const a=e.revision;if("number"!=typeof a||!Number.isInteger(a)||a<0)return null;const s=[];for(const t of["locale","collectionSlug","globalSlug"]){const n=e[t];if(void 0!==n){if("string"!=typeof n||n.length>128)return null;s.push(n)}else s.push(void 0)}const[l,u,c]=s,d=e.fields;return A(d)?L(d,0,t)>t?"field-depth":{fragment:n,..."string"==typeof r?{key:r}:{},route:o,search:i,revision:a,...void 0!==l?{locale:l}:{},...void 0!==u?{collectionSlug:u}:{},...void 0!==c?{globalSlug:c}:{},fields:d}:null}(e,t);return"field-depth"===n?null:n}function w(e){if(!A(e))return null;const{html:t,boundary:n,revision:r,metadata:o}=e;return"string"!=typeof t?null:A(n)&&"string"==typeof n.id?void 0!==n.key&&"string"!=typeof n.key||"number"!=typeof r?null:A(o)&&"string"==typeof o.renderedAt&&"string"==typeof o.renderer?e:null:null}function S(e){return e.reason instanceof Error?e.reason:new DOMException("The operation was aborted.","AbortError")}function E(e){return!0===e?.aborted}var k={status:"superseded"};function T(e,t){return{status:"failed",code:e,reason:t}}function x(n){const r=function(e){const t=()=>{throw new TypeError('createFragmentStrategy: endpoint must be a same-origin path starting with "/"')};if(("string"!=typeof e||!e.startsWith("/")||e.startsWith("//")||e.includes("\\"))&&t(),"undefined"!=typeof location){let n;try{n=new URL(e,location.href)}catch{n=void 0}n?.origin!==location.origin&&t()}return e}(n.endpoint),o=n.timeoutMs??5e3,i=n.maxResponseBytes??524288,a=function(e){let t=0;const n=[],r=()=>{const e=n.shift();void 0===e?t-=1:e.resume()};return async(o,i)=>{if(void 0!==i&&E(i))throw S(i);if(t<e)t+=1;else if(await new Promise((e,t)=>{let r=()=>{};const o={resume:()=>{r(),e()}};if(n.push(o),void 0!==i){const e=()=>{const e=n.indexOf(o);-1!==e&&(n.splice(e,1),r(),t(S(i)))};r=()=>{i.removeEventListener("abort",e)},i.addEventListener("abort",e,{once:!0}),E(i)&&e()}}),void 0!==i&&E(i))throw r(),S(i);try{return await o()}finally{r()}}}(Math.max(1,n.maxConcurrent??4)),s=/* @__PURE__ */new Map,l=/* @__PURE__ */new WeakMap;let u=0;const c=e=>{const t=l.get(e);return void 0!==t?t:(u+=1,l.set(e,u),u)};return(l,u)=>{const d=JSON.stringify([c(l.signal),u.id,u.key,l.revision]),f=s.get(d);if(void 0!==f)return f;let g=!1;const p=a(()=>(g=!0,async function(a,s){const l=()=>a.signal.aborted;if(l())return k;const u=n.location??location,c=function(e){const t={};for(const[n,r]of Object.entries(e))void 0!==r&&(t[n]=r);return t}({fragment:s.id,key:s.key,route:u.pathname,search:u.search,revision:a.revision,locale:a.locale,collectionSlug:a.collectionSlug,globalSlug:a.globalSlug,fields:a.fields}),d=e(a.signal,o),f=e=>l()?k:d.timedOut()?T("LP0801",`timeout after ${String(o)} ms`):T("LP0801",t(e));let g,p=!1;try{try{g=await(n.fetch??fetch)(r,{method:"POST",credentials:"same-origin",headers:{...n.headers,accept:"application/json","content-type":"application/json",[v]:String(1)},body:JSON.stringify(c),signal:d.signal})}catch(e){return f(e)}if(l())return k;if(401===g.status||403===g.status)return T("LP0803",`endpoint refused the preview (${String(g.status)})`);if(!g.ok)return T("LP0801",`endpoint answered ${String(g.status)}`);const e=g.headers.get("content-type")??"";if(!e.toLowerCase().startsWith("application/json"))return T("LP0802",`unexpected content type "${e}"`);if(Number(g.headers.get("content-length")??"0")>i)return T("LP0802","response exceeds the size limit");if(d.signal.aborted)return f(d.signal.reason);let t,u;try{p=!0,t=await async function(e,t,n){const r=e.body;if("object"!=typeof(o=r)||null===o||"function"!=typeof o.getReader){const n=await e.text();return(new TextEncoder).encode(n).byteLength>t?null:n}var o;const i=r.getReader(),a=()=>{i.cancel().catch(()=>{})};n.addEventListener("abort",a,{once:!0});const s=new TextDecoder;let l="",u=0;try{for(;;){const{done:e,value:n}=await i.read();if(e)break;if(u+=n.byteLength,u>t)return a(),null;l+=s.decode(n,{stream:!0})}}finally{n.removeEventListener("abort",a),i.releaseLock()}return l+s.decode()}(g,i,d.signal)}catch(e){return f(e)}if(l())return k;if(d.timedOut())return T("LP0801",`timeout after ${String(o)} ms`);if(null===t)return T("LP0802","response exceeds the size limit");try{u=JSON.parse(t)}catch{return T("LP0802","response is not JSON")}const h=w(u);return null===h?T("LP0802","response has the wrong shape"):h.boundary.id!==s.id||h.boundary.key!==s.key?T("LP0802","response is for another boundary"):h.revision!==a.revision?k:{status:"rendered",html:h.html,metadata:h.metadata}}finally{if(d.dispose(),void 0!==g&&!p)try{g.body?.cancel().catch(()=>{})}catch{}}}(l,u)),l.signal).catch(e=>{if(!g&&l.signal.aborted)return k;throw e});s.set(d,p);const h=()=>{s.get(d)===p&&s.delete(d)};return p.then(h,h),p}}var N=Object.freeze({NoTrustedOrigin:"LP0101",ReferrerOnlyTrust:"LP0102",PluginIncompatible:"LP0103",ProfileFeatureOmitted:"LP0104",OrphanField:"LP0201",UnattributableUpdate:"LP0202",UnboundField:"LP0203",VisibilityGateDeferred:"LP0301",UnsafeAttributeWrite:"LP0401",TextTargetHasChildren:"LP0402",MissingArrayTemplate:"LP0403",StructuralItemUnkeyed:"LP0404",StructuralDuplicateKey:"LP0405",StructuralUnstableKeys:"LP0406",UnsupportedStrategy:"LP0407",UnknownValueFormat:"LP0408",SanitizerDroppedAttribute:"LP0409",UnrenderedBlockKept:"LP0410",UnfaithfulPatch:"LP0411",ServerFormatReplaced:"LP0412",UnrenderedBlockLost:"LP0413",MessageRejected:"LP0501",TokenRejected:"LP0502",ProtocolShapeUnknown:"LP0503",HandlerThrew:"LP0601",TransformThrew:"LP0602",RendererThrew:"LP0603",StartupFailed:"LP0605",ReadyFailed:"LP0606",HydrationWaitTimedOut:"LP0607",AuditRuntimeMissing:"LP0701",AuditNoFrameAncestors:"LP0702",AuditFrameOptionsBlocks:"LP0703",AuditBindingsExposed:"LP0704",AuditGateThresholdExceeded:"LP0705",AuditUnownedBindings:"LP0706",AuditNoBindings:"LP0707",AuditNotAPage:"LP0708",FragmentRequestFailed:"LP0801",FragmentResponseInvalid:"LP0802",FragmentUnauthorized:"LP0803",FragmentSuperseded:"LP0804",RouteRefreshLoop:"LP0805",FragmentStrategyUnavailable:"LP0806",UnboundChangeRefresh:"LP0807",EscalationUnavailable:"LP0808",IslandStartUnavailable:"LP0809",RouteRefreshUnconfirmed:"LP0810",V2ReadinessGap:"LP0709",RuntimeOnPublicPage:"LP0710"}),O=/* @__PURE__ */new Set(["open","value","checked","selected"]);function R(e,t){for(const n of t.keyAttributes){const t=e.getAttribute(n);if(null!==t&&t.length>0)return`${n}=${t}`}}function C(e,t,n){if(!M(e,t))return t;const r=n.boundary??o,i=r(e),a=r(t);if(i||a)return i&&a&&(n.retainBoundary?.(e,t)??1)?e:t;const s=function(e){const t=e.ownerDocument.activeElement;if(!(t instanceof HTMLElement&&e.contains(t)))return null;return{element:t,selection:t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement?[t.selectionStart,t.selectionEnd]:null}}(e);return function(e,t){for(const n of Array.from(e.attributes))t.hasAttribute(n.name)||O.has(n.name.toLowerCase())||e.removeAttribute(n.name);for(const n of Array.from(t.attributes))e.getAttribute(n.name)!==n.value&&e.setAttribute(n.name,n.value)}(e,t),!0!==n.retainChildrenOf?.(e,t)&&function(e,t,n){const r=function(e,t){const n=/* @__PURE__ */new Map;let r;for(const o of Array.from(e.children)){const e=R(o,t);void 0!==e&&(n.has(e)?r??=e.slice(e.indexOf("=")+1):n.set(e,o))}return void 0!==r&&t.onDuplicateKey?.(e,r),n}(e,n),o=new Set(r.values()),i=Array.from(e.childNodes).filter(e=>!o.has(e)),a=/* @__PURE__ */new Set,s=/* @__PURE__ */new Set,l=Array.from(t.childNodes);let u=e.firstChild,c=0;for(let t=0;t<l.length;t+=1){const o=l[t];let d=null,f=o instanceof Element?R(o,n):void 0;if(void 0!==f&&s.has(f)&&(f=void 0),void 0!==f){s.add(f);const e=r.get(f);if(void 0!==e&&!a.has(e)&&(d=U(e,o,n)===e?e:null,null===d)){e.replaceWith(o),a.add(o),u=o.nextSibling;continue}}else{for(;c<i.length;){const r=i[c];if(c+=1,!a.has(r)){if(M(r,o)){d=U(r,o,n)===r?r:null,null===d&&(e.replaceChild(o,r),a.add(o),u=o.nextSibling);break}if(r instanceof Element){const n=l[t+1];if(!(o instanceof Element)||void 0!==n&&M(r,n)){c-=1;break}e.replaceChild(o,r),a.add(o),u=o.nextSibling;break}if(!(o instanceof Element)){e.replaceChild(o,r),a.add(o),u=o.nextSibling;break}}}if(null===d&&a.has(o))continue}const g=d??o;for(a.add(g);null!==u&&u!==g&&!a.has(u)&&$(u);)u=u.nextSibling;g!==u&&e.insertBefore(g,u),u=g.nextSibling}for(const t of Array.from(e.childNodes))a.has(t)||t.remove()}(e,t,n),function(e){if(null===e)return;const{element:t,selection:n}=e;if(t.ownerDocument.activeElement!==t&&t.isConnected)try{t.focus({preventScroll:!0});const[e,r]=n??[null,null];null!==e&&null!==r&&t.setSelectionRange(e,r)}catch{}}(s),e}function U(e,t,n){return e instanceof Element&&t instanceof Element?C(e,t,n):(e.nodeValue!==t.nodeValue&&(e.nodeValue=t.nodeValue),e)}function $(e){return e.nodeType===Node.TEXT_NODE&&0===(e.nodeValue??"").trim().length}function M(e,t){return e.nodeType===t.nodeType&&(!(e instanceof Element&&t instanceof Element)||e.tagName===t.tagName&&e.namespaceURI===t.namespaceURI)}var F="data-payload-strategy",I="data-payload-field",D="x-payload-live-preview";function W(e){const t=e.getAttribute(F);return null!==t?"route"===t:null!==e.closest("head")}function j(e){const t=e.getAttribute(I),n=f(e.getAttribute("data-payload-depends"));return null===t||0===t.length?n:[t,...n]}function B(e){return!e.hasAttribute(r)&&("META"===e.tagName?e.hasAttribute("name")||e.hasAttribute("property"):"LINK"===e.tagName&&"canonical"===e.getAttribute("rel"))}function V(n={}){const i=n.timeoutMs??8e3,a=n.minIntervalMs??1e3;let s=-1/0,u=!1;return{plan(e,t,n){for(const r of e.querySelectorAll(`[${I}], [${F}="route"]`)){if(!W(r)||!1===n?.inScope(r))continue;const e=j(r);if(0===e.length||e.some(e=>t.has(e)))return!0}return!1},async refresh(c){const f=Date.now(),h=a-(f-s);if(h>0)return c.retryAfter?.(h),c.log("LP0805",`route refresh for revision ${String(c.revision)} refused: the previous one was ${String(f-s)} ms ago`),"refused";s=f;const m=n.document??document,y=n.location??location,b=n.window??window,v=e(c.signal,i),L=e=>{if(c.signal.aborted)return"superseded";const n=v.timedOut()?`route refresh timed out after ${String(i)} ms`:t(e);return c.log("LP0801",n),"failed"};try{const e=("undefined"==typeof window?void 0:window)?.__livePreviewRouteRefresh;if(void 0!==e){try{const t=e();"function"==typeof t?.then||u||(u=!0,c.log("LP0810","route refresh returned no promise; re-applied before the host committed (see LivePreviewRouteRefresh)")),await t}catch(e){return L(e)}return c.isCurrent()?"partial":"superseded"}let t;try{t=await(n.fetch??fetch)(y.href,{method:"GET",credentials:"same-origin",cache:"no-store",headers:{accept:"text/html",[D]:"route"},signal:v.signal})}catch(e){return L(e)}if(c.signal.aborted)return"superseded";if(!t.ok||!(t.headers.get("content-type")??"").includes("text/html"))return c.log("LP0802",`route answered ${String(t.status)} ${t.headers.get("content-type")??""}`),"failed";try{const e=await t.text();if(!c.isCurrent())return"superseded";const n=(new DOMParser).parseFromString(e,"text/html"),i=b.scrollX,a=b.scrollY;!function(e,t){const n=Array.from(e.head.children).find(e=>"TITLE"===e.tagName),o=Array.from(t.head.children).find(e=>"TITLE"===e.tagName);n?.hasAttribute(r)||o?.hasAttribute(r)||t.title===e.title||(e.title=t.title);const i=Array.from(e.head.children).filter(B),a=Array.from(t.head.children).filter(B),s=Math.min(i.length,a.length);i.slice(0,s).forEach((t,n)=>{const r=a[n];if(void 0===r)return;if(t.tagName===r.tagName){for(const e of Array.from(t.attributes))r.hasAttribute(e.name)||t.removeAttribute(e.name);for(const e of Array.from(r.attributes))t.getAttribute(e.name)!==e.value&&t.setAttribute(e.name,e.value);return}const o=e.importNode(r,!0);t.replaceWith(o),i[n]=o});let l=i.at(-1);for(const t of a.slice(i.length)){const n=e.importNode(t,!0);void 0===l?e.head.append(n):l.after(n),l=n}for(const e of i.slice(a.length))e.remove()}(m,n);const s=(A=m.body,Array.from(A.querySelectorAll("astro-island")));return C(m.body,n.body,{boundary:o,retainBoundary:d,keyAttributes:["data-payload-key",p,g],retainChildrenOf:e=>e.hasAttribute(g)}),function(e){for(const t of e)t.isConnected||l.has(t)||(l.add(t),t.dispatchEvent(new CustomEvent("astro:unmount")))}(s),b.scrollTo(i,a),"partial"}catch(e){return L(e)}}finally{v.dispose()}var A}}}function z(e){return{plan:(e,t)=>y(e,t).map(e=>e.element),async render(n,r){const o={rendered:0,failed:0,superseded:0},i={revision:n.revision,receivedAt:n.receivedAt,fields:n.fields,locale:n.locale,collectionSlug:n.collectionSlug,globalSlug:n.globalSlug,signal:n.signal};return await Promise.all(r.map(async r=>{const a=m(r);if(null===a)return;let s;try{s=await e(i,a)}catch(e){s={status:"failed",code:"LP0801",reason:t(e)}}return n.isCurrent()&&"superseded"!==s.status?"rendered"===s.status?(n.morph(r,s.html),n.rendered(r,a.id,a.key),void(o.rendered+=1)):(n.failed(r,a.id,a.key,s.code,s.reason),n.isCurrent()&&n.patch(r),void(o.failed+=1)):(o.superseded+=1,void n.log("LP0804",`fragment "${a.id}" for revision ${String(i.revision)} discarded as superseded`))})),o}}}function H(e){return z(x(e))}export{N as DIAGNOSTIC_CODES,g as FRAGMENT_ATTRIBUTE,p as FRAGMENT_KEY_ATTRIBUTE,b as FRAGMENT_PROTOCOL_VERSION,v as FRAGMENT_VERSION_HEADER,D as ROUTE_REFRESH_HEADER,y as collectFragmentBoundaries,x as createFragmentHandler,H as createFragmentStrategy,V as createRouteStrategy,m as describeBoundary,z as fragmentStrategyFrom,W as isRouteBound,P as parseFragmentRequest,w as parseFragmentResponse,h as resolveStrategy};
|
|
1
|
+
function e(e,t){const n=new AbortController;let r=!1;const o=()=>{n.abort()};e.addEventListener("abort",o,{once:!0});const i=setTimeout(()=>{r=!0,n.abort()},t);return{signal:n.signal,timedOut:()=>r,dispose:()=>{clearTimeout(i),e.removeEventListener("abort",o)}}}function t(e){return e instanceof Error?e.message:String(e)}var n="data-payload-island",r="data-payload-owned";function o(e){if(e.tagName.toLowerCase().includes("-")&&!e.hasAttribute("data-payload-morph"))return!0;if(i(e)||e.hasAttribute(r))return!0;const t=e.getAttribute("contenteditable");return null!==t&&"false"!==t}function i(e){return function(e){return"astro-island"===e.tagName.toLowerCase()||e.hasAttribute(n)}(e)&&!("patch"===e.getAttribute(n))}function isInsideIsland(e){let t=e;for(;null!==t;){if(i(t))return!0;t=t.parentElement}return!1}var a=["component-url","component-export","renderer-url","client","opts","before-hydration-url"],s=/* @__PURE__ */new WeakMap,l=/* @__PURE__ */new WeakSet;function u(e){return"astro-island"===e.tagName.toLowerCase()}function c(e){let t="";for(const n of e.querySelectorAll("astro-slot, template[data-astro-template]"))n.parentElement?.closest("astro-island")===e&&(t+=`${n.getAttribute("name")??n.getAttribute("data-astro-template")??""}\0${n.innerHTML}\0`);return t}function d(e,t){if(!u(e)||!u(t))return!0;const n=c(t);if(!a.every(n=>e.getAttribute(n)===t.getAttribute(n))||(s.get(e)??c(e))!==n||e.getAttribute("props")!==t.getAttribute("props")&&!function(e){const t=e.ownerDocument.defaultView?.customElements.get("astro-island");return void 0!==t&&e instanceof t&&Array.isArray(t.observedAttributes)&&t.observedAttributes.includes("props")}(e))return s.set(t,n),!1;s.set(e,n);const r=t.getAttribute("props");return r!==e.getAttribute("props")&&(e.setAttribute("ssr",""),null===r?e.removeAttribute("props"):e.setAttribute("props",r)),!0}function f(e){if(null==e)return[];const t=/* @__PURE__ */new Set,n=[];for(const r of e.split(/[\s,]+/)){const e=r.trim();0===e.length||t.has(e)||(t.add(e),n.push(e))}return n}var g="data-payload-fragment",p="data-payload-fragment-key";function h(e){const t=e.getAttribute("data-payload-strategy");return null!==t&&t.length>0?"patch"===t||"fragment"===t||"route"===t?t:void 0:null!==function(e){return e.closest(`[${g}]`)}(e)?"fragment":null!==e.closest("head")?"route":"patch"}function m(e){const t=e.getAttribute(g);if(null===t||0===t.length)return null;const n=e.getAttribute(p);return{element:e,id:t,key:null===n||0===n.length?void 0:n,dependsOn:f(e.getAttribute("data-payload-depends"))}}function y(e,t){const n=[];for(const r of e.querySelectorAll(`[${g}]`)){const e=m(r);null===e||isInsideIsland(r)||e.dependsOn.length>0&&!e.dependsOn.some(e=>t.has(e))||n.push(e)}return n}var b=1,v="x-payload-fragment-version";function L(e,t,n){if(t>n||"object"!=typeof e||null===e)return t;let r=t;for(const o of Object.values(e))if(r=Math.max(r,L(o,t+1,n)),r>n)break;return r}function A(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function P(e,t=64){const n=function(e,t=64){if(!Number.isInteger(t)||t<0||t>64)return null;if(!A(e))return null;const n=e.fragment;if("string"!=typeof n||!/^[a-z][a-z0-9-]{0,63}$/iu.test(n))return null;const r=e.key;if(void 0!==r&&("string"!=typeof r||r.length>128))return null;const o=e.route;if("string"!=typeof o||!o.startsWith("/")||o.length>2048)return null;const i=e.search;if("string"!=typeof i||i.length>4096||""!==i&&!i.startsWith("?"))return null;const a=e.revision;if("number"!=typeof a||!Number.isInteger(a)||a<0)return null;const s=[];for(const t of["locale","collectionSlug","globalSlug"]){const n=e[t];if(void 0!==n){if("string"!=typeof n||n.length>128)return null;s.push(n)}else s.push(void 0)}const[l,u,c]=s,d=e.fields;return A(d)?L(d,0,t)>t?"field-depth":{fragment:n,..."string"==typeof r?{key:r}:{},route:o,search:i,revision:a,...void 0!==l?{locale:l}:{},...void 0!==u?{collectionSlug:u}:{},...void 0!==c?{globalSlug:c}:{},fields:d}:null}(e,t);return"field-depth"===n?null:n}function w(e){if(!A(e))return null;const{html:t,boundary:n,revision:r,metadata:o}=e;return"string"!=typeof t?null:A(n)&&"string"==typeof n.id?void 0!==n.key&&"string"!=typeof n.key||"number"!=typeof r?null:A(o)&&"string"==typeof o.renderedAt&&"string"==typeof o.renderer?e:null:null}function S(e){return e.reason instanceof Error?e.reason:new DOMException("The operation was aborted.","AbortError")}function E(e){return!0===e?.aborted}var k={status:"superseded"};function T(e,t){return{status:"failed",code:e,reason:t}}function x(n){const r=function(e){const t=()=>{throw new TypeError('createFragmentStrategy: endpoint must be a same-origin path starting with "/"')};if(("string"!=typeof e||!e.startsWith("/")||e.startsWith("//")||e.includes("\\"))&&t(),"undefined"!=typeof location){let n;try{n=new URL(e,location.href)}catch{n=void 0}n?.origin!==location.origin&&t()}return e}(n.endpoint),o=n.timeoutMs??5e3,i=n.maxResponseBytes??524288,a=function(e){let t=0;const n=[],r=()=>{const e=n.shift();void 0===e?t-=1:e.resume()};return async(o,i)=>{if(void 0!==i&&E(i))throw S(i);if(t<e)t+=1;else if(await new Promise((e,t)=>{let r=()=>{};const o={resume:()=>{r(),e()}};if(n.push(o),void 0!==i){const e=()=>{const e=n.indexOf(o);-1!==e&&(n.splice(e,1),r(),t(S(i)))};r=()=>{i.removeEventListener("abort",e)},i.addEventListener("abort",e,{once:!0}),E(i)&&e()}}),void 0!==i&&E(i))throw r(),S(i);try{return await o()}finally{r()}}}(Math.max(1,n.maxConcurrent??4)),s=/* @__PURE__ */new Map,l=/* @__PURE__ */new WeakMap;let u=0;const c=e=>{const t=l.get(e);return void 0!==t?t:(u+=1,l.set(e,u),u)};return(l,u)=>{const d=JSON.stringify([c(l.signal),u.id,u.key,l.revision]),f=s.get(d);if(void 0!==f)return f;let g=!1;const p=a(()=>(g=!0,async function(a,s){const l=()=>a.signal.aborted;if(l())return k;const u=n.location??location,c=function(e){const t={};for(const[n,r]of Object.entries(e))void 0!==r&&(t[n]=r);return t}({fragment:s.id,key:s.key,route:u.pathname,search:u.search,revision:a.revision,locale:a.locale,collectionSlug:a.collectionSlug,globalSlug:a.globalSlug,fields:a.fields}),d=e(a.signal,o),f=e=>l()?k:d.timedOut()?T("LP0801",`timeout after ${String(o)} ms`):T("LP0801",t(e));let g,p=!1;try{try{g=await(n.fetch??fetch)(r,{method:"POST",credentials:"same-origin",headers:{...n.headers,accept:"application/json","content-type":"application/json",[v]:String(1)},body:JSON.stringify(c),signal:d.signal})}catch(e){return f(e)}if(l())return k;if(401===g.status||403===g.status)return T("LP0803",`endpoint refused the preview (${String(g.status)})`);if(!g.ok)return T("LP0801",`endpoint answered ${String(g.status)}`);const e=g.headers.get("content-type")??"";if(!e.toLowerCase().startsWith("application/json"))return T("LP0802",`unexpected content type "${e}"`);if(Number(g.headers.get("content-length")??"0")>i)return T("LP0802","response exceeds the size limit");if(d.signal.aborted)return f(d.signal.reason);let t,u;try{p=!0,t=await async function(e,t,n){const r=e.body;if("object"!=typeof(o=r)||null===o||"function"!=typeof o.getReader){const n=await e.text();return(new TextEncoder).encode(n).byteLength>t?null:n}var o;const i=r.getReader(),a=()=>{i.cancel().catch(()=>{})};n.addEventListener("abort",a,{once:!0});const s=new TextDecoder;let l="",u=0;try{for(;;){const{done:e,value:n}=await i.read();if(e)break;if(u+=n.byteLength,u>t)return a(),null;l+=s.decode(n,{stream:!0})}}finally{n.removeEventListener("abort",a),i.releaseLock()}return l+s.decode()}(g,i,d.signal)}catch(e){return f(e)}if(l())return k;if(d.timedOut())return T("LP0801",`timeout after ${String(o)} ms`);if(null===t)return T("LP0802","response exceeds the size limit");try{u=JSON.parse(t)}catch{return T("LP0802","response is not JSON")}const h=w(u);return null===h?T("LP0802","response has the wrong shape"):h.boundary.id!==s.id||h.boundary.key!==s.key?T("LP0802","response is for another boundary"):h.revision!==a.revision?k:{status:"rendered",html:h.html,metadata:h.metadata}}finally{if(d.dispose(),void 0!==g&&!p)try{g.body?.cancel().catch(()=>{})}catch{}}}(l,u)),l.signal).catch(e=>{if(!g&&l.signal.aborted)return k;throw e});s.set(d,p);const h=()=>{s.get(d)===p&&s.delete(d)};return p.then(h,h),p}}var N=Object.freeze({NoTrustedOrigin:"LP0101",ReferrerOnlyTrust:"LP0102",PluginIncompatible:"LP0103",ProfileFeatureOmitted:"LP0104",OrphanField:"LP0201",UnattributableUpdate:"LP0202",UnboundField:"LP0203",CoverageDefaultChanges:"LP0204",VisibilityGateDeferred:"LP0301",UnsafeAttributeWrite:"LP0401",TextTargetHasChildren:"LP0402",MissingArrayTemplate:"LP0403",StructuralItemUnkeyed:"LP0404",StructuralDuplicateKey:"LP0405",StructuralUnstableKeys:"LP0406",UnsupportedStrategy:"LP0407",UnknownValueFormat:"LP0408",SanitizerDroppedAttribute:"LP0409",UnrenderedBlockKept:"LP0410",UnfaithfulPatch:"LP0411",ServerFormatReplaced:"LP0412",UnrenderedBlockLost:"LP0413",MessageRejected:"LP0501",TokenRejected:"LP0502",ProtocolShapeUnknown:"LP0503",HandlerThrew:"LP0601",TransformThrew:"LP0602",RendererThrew:"LP0603",StartupFailed:"LP0605",ReadyFailed:"LP0606",HydrationWaitTimedOut:"LP0607",AuditRuntimeMissing:"LP0701",AuditNoFrameAncestors:"LP0702",AuditFrameOptionsBlocks:"LP0703",AuditBindingsExposed:"LP0704",AuditGateThresholdExceeded:"LP0705",AuditUnownedBindings:"LP0706",AuditNoBindings:"LP0707",AuditNotAPage:"LP0708",FragmentRequestFailed:"LP0801",FragmentResponseInvalid:"LP0802",FragmentUnauthorized:"LP0803",FragmentSuperseded:"LP0804",RouteRefreshLoop:"LP0805",FragmentStrategyUnavailable:"LP0806",UnboundChangeRefresh:"LP0807",EscalationUnavailable:"LP0808",IslandStartUnavailable:"LP0809",RouteRefreshUnconfirmed:"LP0810",V2ReadinessGap:"LP0709",RuntimeOnPublicPage:"LP0710",AuditModifierWithoutField:"LP0711"}),O=/* @__PURE__ */new Set(["open","value","checked","selected"]);function R(e,t){for(const n of t.keyAttributes){const t=e.getAttribute(n);if(null!==t&&t.length>0)return`${n}=${t}`}}function C(e,t,n){if(!$(e,t))return t;const r=n.boundary??o,i=r(e),a=r(t);if(i||a)return i&&a&&(n.retainBoundary?.(e,t)??1)?e:t;const s=function(e){const t=e.ownerDocument.activeElement;if(!(t instanceof HTMLElement&&e.contains(t)))return null;return{element:t,selection:t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement?[t.selectionStart,t.selectionEnd]:null}}(e);return function(e,t){for(const n of Array.from(e.attributes))t.hasAttribute(n.name)||O.has(n.name.toLowerCase())||e.removeAttribute(n.name);for(const n of Array.from(t.attributes))e.getAttribute(n.name)!==n.value&&e.setAttribute(n.name,n.value)}(e,t),!0!==n.retainChildrenOf?.(e,t)&&function(e,t,n){const r=function(e,t){const n=/* @__PURE__ */new Map;let r;for(const o of Array.from(e.children)){const e=R(o,t);void 0!==e&&(n.has(e)?r??=e.slice(e.indexOf("=")+1):n.set(e,o))}return void 0!==r&&t.onDuplicateKey?.(e,r),n}(e,n),o=new Set(r.values()),i=Array.from(e.childNodes).filter(e=>!o.has(e)),a=/* @__PURE__ */new Set,s=/* @__PURE__ */new Set,l=Array.from(t.childNodes);let u=e.firstChild,c=0;for(let t=0;t<l.length;t+=1){const o=l[t];let d=null,f=o instanceof Element?R(o,n):void 0;if(void 0!==f&&s.has(f)&&(f=void 0),void 0!==f){s.add(f);const e=r.get(f);if(void 0!==e&&!a.has(e)&&(d=U(e,o,n)===e?e:null,null===d)){e.replaceWith(o),a.add(o),u=o.nextSibling;continue}}else{for(;c<i.length;){const r=i[c];if(c+=1,!a.has(r)){if($(r,o)){d=U(r,o,n)===r?r:null,null===d&&(e.replaceChild(o,r),a.add(o),u=o.nextSibling);break}if(r instanceof Element){const n=l[t+1];if(!(o instanceof Element)||void 0!==n&&$(r,n)){c-=1;break}e.replaceChild(o,r),a.add(o),u=o.nextSibling;break}if(!(o instanceof Element)){e.replaceChild(o,r),a.add(o),u=o.nextSibling;break}}}if(null===d&&a.has(o))continue}const g=d??o;for(a.add(g);null!==u&&u!==g&&!a.has(u)&&M(u);)u=u.nextSibling;g!==u&&e.insertBefore(g,u),u=g.nextSibling}for(const t of Array.from(e.childNodes))a.has(t)||t.remove()}(e,t,n),function(e){if(null===e)return;const{element:t,selection:n}=e;if(t.ownerDocument.activeElement!==t&&t.isConnected)try{t.focus({preventScroll:!0});const[e,r]=n??[null,null];null!==e&&null!==r&&t.setSelectionRange(e,r)}catch{}}(s),e}function U(e,t,n){return e instanceof Element&&t instanceof Element?C(e,t,n):(e.nodeValue!==t.nodeValue&&(e.nodeValue=t.nodeValue),e)}function M(e){return e.nodeType===Node.TEXT_NODE&&0===(e.nodeValue??"").trim().length}function $(e,t){return e.nodeType===t.nodeType&&(!(e instanceof Element&&t instanceof Element)||e.tagName===t.tagName&&e.namespaceURI===t.namespaceURI)}var F="data-payload-strategy",I="data-payload-field",D="x-payload-live-preview";function W(e){const t=e.getAttribute(F);return null!==t?"route"===t:null!==e.closest("head")}function j(e){const t=e.getAttribute(I),n=f(e.getAttribute("data-payload-depends"));return null===t||0===t.length?n:[t,...n]}function B(e){return!e.hasAttribute(r)&&("META"===e.tagName?e.hasAttribute("name")||e.hasAttribute("property"):"LINK"===e.tagName&&"canonical"===e.getAttribute("rel"))}function V(n={}){const i=n.timeoutMs??8e3,a=n.minIntervalMs??1e3;let s=-1/0,u=!1;return{plan(e,t,n){for(const r of e.querySelectorAll(`[${I}], [${F}="route"]`)){if(!W(r)||!1===n?.inScope(r))continue;const e=j(r);if(0===e.length||e.some(e=>t.has(e)))return!0}return!1},async refresh(c){const f=Date.now(),h=a-(f-s);if(h>0)return c.retryAfter?.(h),c.log("LP0805",`route refresh for revision ${String(c.revision)} refused: the previous one was ${String(f-s)} ms ago`),"refused";s=f;const m=n.document??document,y=n.location??location,b=n.window??window,v=e(c.signal,i),L=e=>{if(c.signal.aborted)return"superseded";const n=v.timedOut()?`route refresh timed out after ${String(i)} ms`:t(e);return c.log("LP0801",n),"failed"};try{const e=("undefined"==typeof window?void 0:window)?.__livePreviewRouteRefresh;if(void 0!==e){try{const t=e();"function"==typeof t?.then||u||(u=!0,c.log("LP0810","route refresh returned no promise; re-applied before the host committed (see LivePreviewRouteRefresh)")),await t}catch(e){return L(e)}return c.isCurrent()?"partial":"superseded"}let t;try{t=await(n.fetch??fetch)(y.href,{method:"GET",credentials:"same-origin",cache:"no-store",headers:{accept:"text/html",[D]:"route"},signal:v.signal})}catch(e){return L(e)}if(c.signal.aborted)return"superseded";if(!t.ok||!(t.headers.get("content-type")??"").includes("text/html"))return c.log("LP0802",`route answered ${String(t.status)} ${t.headers.get("content-type")??""}`),"failed";try{const e=await t.text();if(!c.isCurrent())return"superseded";const n=(new DOMParser).parseFromString(e,"text/html"),i=b.scrollX,a=b.scrollY;!function(e,t){const n=Array.from(e.head.children).find(e=>"TITLE"===e.tagName),o=Array.from(t.head.children).find(e=>"TITLE"===e.tagName);n?.hasAttribute(r)||o?.hasAttribute(r)||t.title===e.title||(e.title=t.title);const i=Array.from(e.head.children).filter(B),a=Array.from(t.head.children).filter(B),s=Math.min(i.length,a.length);i.slice(0,s).forEach((t,n)=>{const r=a[n];if(void 0===r)return;if(t.tagName===r.tagName){for(const e of Array.from(t.attributes))r.hasAttribute(e.name)||t.removeAttribute(e.name);for(const e of Array.from(r.attributes))t.getAttribute(e.name)!==e.value&&t.setAttribute(e.name,e.value);return}const o=e.importNode(r,!0);t.replaceWith(o),i[n]=o});let l=i.at(-1);for(const t of a.slice(i.length)){const n=e.importNode(t,!0);void 0===l?e.head.append(n):l.after(n),l=n}for(const e of i.slice(a.length))e.remove()}(m,n);const s=(A=m.body,Array.from(A.querySelectorAll("astro-island")));return C(m.body,n.body,{boundary:o,retainBoundary:d,keyAttributes:["data-payload-key",p,g],retainChildrenOf:e=>e.hasAttribute(g)}),function(e){for(const t of e)t.isConnected||l.has(t)||(l.add(t),t.dispatchEvent(new CustomEvent("astro:unmount")))}(s),b.scrollTo(i,a),"partial"}catch(e){return L(e)}}finally{v.dispose()}var A}}}function z(e){return{plan:(e,t)=>y(e,t).map(e=>e.element),async render(n,r){const o={rendered:0,failed:0,superseded:0},i={revision:n.revision,receivedAt:n.receivedAt,fields:n.fields,locale:n.locale,collectionSlug:n.collectionSlug,globalSlug:n.globalSlug,signal:n.signal};return await Promise.all(r.map(async r=>{const a=m(r);if(null===a)return;let s;try{s=await e(i,a)}catch(e){s={status:"failed",code:"LP0801",reason:t(e)}}return n.isCurrent()&&"superseded"!==s.status?"rendered"===s.status?(n.morph(r,s.html),n.rendered(r,a.id,a.key),void(o.rendered+=1)):(n.failed(r,a.id,a.key,s.code,s.reason),n.isCurrent()&&n.patch(r),void(o.failed+=1)):(o.superseded+=1,void n.log("LP0804",`fragment "${a.id}" for revision ${String(i.revision)} discarded as superseded`))})),o}}}function H(e){return z(x(e))}export{N as DIAGNOSTIC_CODES,g as FRAGMENT_ATTRIBUTE,p as FRAGMENT_KEY_ATTRIBUTE,b as FRAGMENT_PROTOCOL_VERSION,v as FRAGMENT_VERSION_HEADER,D as ROUTE_REFRESH_HEADER,y as collectFragmentBoundaries,x as createFragmentHandler,H as createFragmentStrategy,V as createRouteStrategy,m as describeBoundary,z as fragmentStrategyFrom,W as isRouteBound,P as parseFragmentRequest,w as parseFragmentResponse,h as resolveStrategy};
|
|
2
2
|
//# sourceMappingURL=fragment.js.map
|