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.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";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 p="data-payload-fragment",g="data-payload-fragment-key";function m(e){const t=e.getAttribute(p);if(null===t||0===t.length)return null;const n=e.getAttribute(g);return{element:e,id:t,key:null===n||0===n.length?void 0:n,dependsOn:f(e.getAttribute("data-payload-depends"))}}function h(e,t){const n=[];for(const r of e.querySelectorAll(`[${p}]`)){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 y="x-payload-fragment-version";function b(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,b(o,t+1,n)),r>n)break;return r}function v(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function A(e){if(!v(e))return null;const{html:t,boundary:n,revision:r,metadata:o}=e;return"string"!=typeof t?null:v(n)&&"string"==typeof n.id?void 0!==n.key&&"string"!=typeof n.key||"number"!=typeof r?null:v(o)&&"string"==typeof o.renderedAt&&"string"==typeof o.renderer?e:null:null}function L(e){return e.reason instanceof Error?e.reason:new DOMException("The operation was aborted.","AbortError")}function P(e){return!0===e?.aborted}var S={status:"superseded"};function w(e,t){return{status:"failed",code:e,reason:t}}function E(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&&P(i))throw L(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(L(i)))};r=()=>{i.removeEventListener("abort",e)},i.addEventListener("abort",e,{once:!0}),P(i)&&e()}}),void 0!==i&&P(i))throw r(),L(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 p=!1;const g=a(()=>(p=!0,async function(a,s){const l=()=>a.signal.aborted;if(l())return S;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()?S:d.timedOut()?w("LP0801",`timeout after ${String(o)} ms`):w("LP0801",t(e));let p,g=!1;try{try{p=await(n.fetch??fetch)(r,{method:"POST",credentials:"same-origin",headers:{...n.headers,accept:"application/json","content-type":"application/json",[y]:String(1)},body:JSON.stringify(c),signal:d.signal})}catch(e){return f(e)}if(l())return S;if(401===p.status||403===p.status)return w("LP0803",`endpoint refused the preview (${String(p.status)})`);if(!p.ok)return w("LP0801",`endpoint answered ${String(p.status)}`);const e=p.headers.get("content-type")??"";if(!e.toLowerCase().startsWith("application/json"))return w("LP0802",`unexpected content type "${e}"`);if(Number(p.headers.get("content-length")??"0")>i)return w("LP0802","response exceeds the size limit");if(d.signal.aborted)return f(d.signal.reason);let t,u;try{g=!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()}(p,i,d.signal)}catch(e){return f(e)}if(l())return S;if(d.timedOut())return w("LP0801",`timeout after ${String(o)} ms`);if(null===t)return w("LP0802","response exceeds the size limit");try{u=JSON.parse(t)}catch{return w("LP0802","response is not JSON")}const m=A(u);return null===m?w("LP0802","response has the wrong shape"):m.boundary.id!==s.id||m.boundary.key!==s.key?w("LP0802","response is for another boundary"):m.revision!==a.revision?S:{status:"rendered",html:m.html,metadata:m.metadata}}finally{if(d.dispose(),void 0!==p&&!g)try{p.body?.cancel().catch(()=>{})}catch{}}}(l,u)),l.signal).catch(e=>{if(!p&&l.signal.aborted)return S;throw e});s.set(d,g);const m=()=>{s.get(d)===g&&s.delete(d)};return g.then(m,m),g}}var T=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"}),x=/* @__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 N(e,t,n){if(!F(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)||x.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=O(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(F(r,o)){d=O(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&&F(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 p=d??o;for(a.add(p);null!==u&&u!==p&&!a.has(u)&&k(u);)u=u.nextSibling;p!==u&&e.insertBefore(p,u),u=p.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 O(e,t,n){return e instanceof Element&&t instanceof Element?N(e,t,n):(e.nodeValue!==t.nodeValue&&(e.nodeValue=t.nodeValue),e)}function k(e){return e.nodeType===Node.TEXT_NODE&&0===(e.nodeValue??"").trim().length}function F(e,t){return e.nodeType===t.nodeType&&(!(e instanceof Element&&t instanceof Element)||e.tagName===t.tagName&&e.namespaceURI===t.namespaceURI)}var C="data-payload-strategy",U="data-payload-field",M="x-payload-live-preview";function I(e){const t=e.getAttribute(C);return null!==t?"route"===t:null!==e.closest("head")}function $(e){const t=e.getAttribute(U),n=f(e.getAttribute("data-payload-depends"));return null===t||0===t.length?n:[t,...n]}function D(e){return!e.hasAttribute(r)&&("META"===e.tagName?e.hasAttribute("name")||e.hasAttribute("property"):"LINK"===e.tagName&&"canonical"===e.getAttribute("rel"))}function B(e){return{plan:(e,t)=>h(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}}}exports.DIAGNOSTIC_CODES=T,exports.FRAGMENT_ATTRIBUTE=p,exports.FRAGMENT_KEY_ATTRIBUTE=g,exports.FRAGMENT_PROTOCOL_VERSION=1,exports.FRAGMENT_VERSION_HEADER=y,exports.ROUTE_REFRESH_HEADER=M,exports.collectFragmentBoundaries=h,exports.createFragmentHandler=E,exports.createFragmentStrategy=function(e){return B(E(e))},exports.createRouteStrategy=function(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(`[${U}], [${C}="route"]`)){if(!I(r)||!1===n?.inScope(r))continue;const e=$(r);if(0===e.length||e.some(e=>t.has(e)))return!0}return!1},async refresh(c){const f=Date.now(),m=a-(f-s);if(m>0)return c.retryAfter?.(m),c.log("LP0805",`route refresh for revision ${String(c.revision)} refused: the previous one was ${String(f-s)} ms ago`),"refused";s=f;const h=n.document??document,y=n.location??location,b=n.window??window,v=e(c.signal,i),A=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 A(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",[M]:"route"},signal:v.signal})}catch(e){return A(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(D),a=Array.from(t.head.children).filter(D),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()}(h,n);const s=(L=h.body,Array.from(L.querySelectorAll("astro-island")));return N(h.body,n.body,{boundary:o,retainBoundary:d,keyAttributes:["data-payload-key",g,p],retainChildrenOf:e=>e.hasAttribute(p)}),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 A(e)}}finally{v.dispose()}var L}}},exports.describeBoundary=m,exports.fragmentStrategyFrom=B,exports.isRouteBound=I,exports.parseFragmentRequest=function(e,t=64){const n=function(e,t=64){if(!Number.isInteger(t)||t<0||t>64)return null;if(!v(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 v(d)?b(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},exports.parseFragmentResponse=A,exports.resolveStrategy=function(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(`[${p}]`)}(e)?"fragment":null!==e.closest("head")?"route":"patch"};
|
|
1
|
+
"use strict";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 p="data-payload-fragment",g="data-payload-fragment-key";function h(e){const t=e.getAttribute(p);if(null===t||0===t.length)return null;const n=e.getAttribute(g);return{element:e,id:t,key:null===n||0===n.length?void 0:n,dependsOn:f(e.getAttribute("data-payload-depends"))}}function m(e,t){const n=[];for(const r of e.querySelectorAll(`[${p}]`)){const e=h(r);null===e||isInsideIsland(r)||e.dependsOn.length>0&&!e.dependsOn.some(e=>t.has(e))||n.push(e)}return n}var y="x-payload-fragment-version";function b(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,b(o,t+1,n)),r>n)break;return r}function v(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function A(e){if(!v(e))return null;const{html:t,boundary:n,revision:r,metadata:o}=e;return"string"!=typeof t?null:v(n)&&"string"==typeof n.id?void 0!==n.key&&"string"!=typeof n.key||"number"!=typeof r?null:v(o)&&"string"==typeof o.renderedAt&&"string"==typeof o.renderer?e:null:null}function L(e){return e.reason instanceof Error?e.reason:new DOMException("The operation was aborted.","AbortError")}function P(e){return!0===e?.aborted}var S={status:"superseded"};function w(e,t){return{status:"failed",code:e,reason:t}}function E(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&&P(i))throw L(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(L(i)))};r=()=>{i.removeEventListener("abort",e)},i.addEventListener("abort",e,{once:!0}),P(i)&&e()}}),void 0!==i&&P(i))throw r(),L(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 p=!1;const g=a(()=>(p=!0,async function(a,s){const l=()=>a.signal.aborted;if(l())return S;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()?S:d.timedOut()?w("LP0801",`timeout after ${String(o)} ms`):w("LP0801",t(e));let p,g=!1;try{try{p=await(n.fetch??fetch)(r,{method:"POST",credentials:"same-origin",headers:{...n.headers,accept:"application/json","content-type":"application/json",[y]:String(1)},body:JSON.stringify(c),signal:d.signal})}catch(e){return f(e)}if(l())return S;if(401===p.status||403===p.status)return w("LP0803",`endpoint refused the preview (${String(p.status)})`);if(!p.ok)return w("LP0801",`endpoint answered ${String(p.status)}`);const e=p.headers.get("content-type")??"";if(!e.toLowerCase().startsWith("application/json"))return w("LP0802",`unexpected content type "${e}"`);if(Number(p.headers.get("content-length")??"0")>i)return w("LP0802","response exceeds the size limit");if(d.signal.aborted)return f(d.signal.reason);let t,u;try{g=!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()}(p,i,d.signal)}catch(e){return f(e)}if(l())return S;if(d.timedOut())return w("LP0801",`timeout after ${String(o)} ms`);if(null===t)return w("LP0802","response exceeds the size limit");try{u=JSON.parse(t)}catch{return w("LP0802","response is not JSON")}const h=A(u);return null===h?w("LP0802","response has the wrong shape"):h.boundary.id!==s.id||h.boundary.key!==s.key?w("LP0802","response is for another boundary"):h.revision!==a.revision?S:{status:"rendered",html:h.html,metadata:h.metadata}}finally{if(d.dispose(),void 0!==p&&!g)try{p.body?.cancel().catch(()=>{})}catch{}}}(l,u)),l.signal).catch(e=>{if(!p&&l.signal.aborted)return S;throw e});s.set(d,g);const h=()=>{s.get(d)===g&&s.delete(d)};return g.then(h,h),g}}var T=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"}),x=/* @__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 N(e,t,n){if(!F(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)||x.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=O(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(F(r,o)){d=O(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&&F(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 p=d??o;for(a.add(p);null!==u&&u!==p&&!a.has(u)&&k(u);)u=u.nextSibling;p!==u&&e.insertBefore(p,u),u=p.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 O(e,t,n){return e instanceof Element&&t instanceof Element?N(e,t,n):(e.nodeValue!==t.nodeValue&&(e.nodeValue=t.nodeValue),e)}function k(e){return e.nodeType===Node.TEXT_NODE&&0===(e.nodeValue??"").trim().length}function F(e,t){return e.nodeType===t.nodeType&&(!(e instanceof Element&&t instanceof Element)||e.tagName===t.tagName&&e.namespaceURI===t.namespaceURI)}var C="data-payload-strategy",M="data-payload-field",U="x-payload-live-preview";function I(e){const t=e.getAttribute(C);return null!==t?"route"===t:null!==e.closest("head")}function $(e){const t=e.getAttribute(M),n=f(e.getAttribute("data-payload-depends"));return null===t||0===t.length?n:[t,...n]}function D(e){return!e.hasAttribute(r)&&("META"===e.tagName?e.hasAttribute("name")||e.hasAttribute("property"):"LINK"===e.tagName&&"canonical"===e.getAttribute("rel"))}function B(e){return{plan:(e,t)=>m(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=h(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}}}exports.DIAGNOSTIC_CODES=T,exports.FRAGMENT_ATTRIBUTE=p,exports.FRAGMENT_KEY_ATTRIBUTE=g,exports.FRAGMENT_PROTOCOL_VERSION=1,exports.FRAGMENT_VERSION_HEADER=y,exports.ROUTE_REFRESH_HEADER=U,exports.collectFragmentBoundaries=m,exports.createFragmentHandler=E,exports.createFragmentStrategy=function(e){return B(E(e))},exports.createRouteStrategy=function(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(`[${M}], [${C}="route"]`)){if(!I(r)||!1===n?.inScope(r))continue;const e=$(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),A=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 A(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",[U]:"route"},signal:v.signal})}catch(e){return A(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(D),a=Array.from(t.head.children).filter(D),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=(L=m.body,Array.from(L.querySelectorAll("astro-island")));return N(m.body,n.body,{boundary:o,retainBoundary:d,keyAttributes:["data-payload-key",g,p],retainChildrenOf:e=>e.hasAttribute(p)}),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 A(e)}}finally{v.dispose()}var L}}},exports.describeBoundary=h,exports.fragmentStrategyFrom=B,exports.isRouteBound=I,exports.parseFragmentRequest=function(e,t=64){const n=function(e,t=64){if(!Number.isInteger(t)||t<0||t>64)return null;if(!v(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 v(d)?b(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},exports.parseFragmentResponse=A,exports.resolveStrategy=function(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(`[${p}]`)}(e)?"fragment":null!==e.closest("head")?"route":"patch"};
|
|
2
2
|
//# sourceMappingURL=fragment.cjs.map
|