@storyblok/astro 7.3.2 → 7.3.3

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.
@@ -347,7 +347,13 @@ const xe = [
347
347
  "source",
348
348
  "track",
349
349
  "wbr"
350
- ], He = (e = {}) => Object.keys(e).map((t) => `${t}="${e[t]}"`).join(" "), je = (e = {}) => Object.keys(e).map((t) => `${t}: ${e[t]}`).join("; ");
350
+ ], He = (e = {}) => {
351
+ const { custom: t, ...r } = e, s = {
352
+ ...r,
353
+ ...t
354
+ };
355
+ return Object.keys(s).map((o) => `${o}="${s[o]}"`).join(" ");
356
+ }, je = (e = {}) => Object.keys(e).map((t) => `${t}: ${e[t]}`).join("; ");
351
357
  function Ne(e) {
352
358
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
353
359
  }
@@ -66,4 +66,4 @@
66
66
  ${m}
67
67
  storyblokInstance.on(["published", "change", "input"], handleStoryblokMessage);
68
68
  });
69
- `),L({entrypoint:"@storyblok/astro/middleware.ts",order:"pre"})),A({id:"storyblok",name:"Storyblok",icon:_,entrypoint:"@storyblok/astro/toolbarApp.ts"})}}}}let W;async function Ee(e){const{action:t,story:r}=e||{};if(t==="input"&&r){const s=async()=>{Y("storyblok-live-preview-updating",{story:r});const n=await Le(r),i=document.body;if(n.outerHTML===i.outerHTML)return;const l=document.querySelector('[data-blok-focused="true"]');Se(i,n,l),Y("storyblok-live-preview-updated",{story:r})};clearTimeout(W),W=setTimeout(s,500)}["published","change"].includes(e==null?void 0:e.action)&&location.reload()}function Se(e,t,r){if(r){const s=r.getAttribute("data-blok-uid"),o=t.querySelector(`[data-blok-uid="${s}"]`);o&&(o.setAttribute("data-blok-focused","true"),r.replaceWith(o))}else e.replaceWith(t)}async function Le(e){const r=await(await fetch(location.href,{method:"POST",body:JSON.stringify({...e,is_storyblok_preview:!0}),headers:{"Content-Type":"application/json"}})).text();return new DOMParser().parseFromString(r,"text/html").body}function Y(e,t){document.dispatchEvent(new CustomEvent(e,{detail:t}))}var _e=Object.defineProperty,Ie=(e,t,r)=>t in e?_e(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,g=(e,t,r)=>Ie(e,typeof t!="symbol"?t+"":t,r);let k=function(e){return e.DOCUMENT="doc",e.HEADING="heading",e.PARAGRAPH="paragraph",e.QUOTE="blockquote",e.OL_LIST="ordered_list",e.UL_LIST="bullet_list",e.LIST_ITEM="list_item",e.CODE_BLOCK="code_block",e.HR="horizontal_rule",e.BR="hard_break",e.IMAGE="image",e.EMOJI="emoji",e.COMPONENT="blok",e.TABLE="table",e.TABLE_ROW="tableRow",e.TABLE_CELL="tableCell",e.TABLE_HEADER="tableHeader",e}({}),$=function(e){return e.BOLD="bold",e.STRONG="strong",e.STRIKE="strike",e.UNDERLINE="underline",e.ITALIC="italic",e.CODE="code",e.LINK="link",e.ANCHOR="anchor",e.STYLED="styled",e.SUPERSCRIPT="superscript",e.SUBSCRIPT="subscript",e.TEXT_STYLE="textStyle",e.HIGHLIGHT="highlight",e}({}),Re=function(e){return e.TEXT="text",e}({}),H=function(e){return e.URL="url",e.STORY="story",e.ASSET="asset",e.EMAIL="email",e}({});const Oe=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],Pe=(e={})=>Object.keys(e).map(t=>`${t}="${e[t]}"`).join(" "),He=(e={})=>Object.keys(e).map(t=>`${t}: ${e[t]}`).join("; ");function je(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}const I=e=>Object.fromEntries(Object.entries(e).filter(([t,r])=>r!==void 0));function xe(e,t){if(!t)return{src:e,attrs:{}};let r=0,s=0;const o={},n=[];function i(c,u,f,m,T){typeof c!="number"||c<=u||c>=f?console.warn(`[StoryblokRichText] - ${m.charAt(0).toUpperCase()+m.slice(1)} value must be a number between ${u} and ${f} (inclusive)`):T.push(`${m}(${c})`)}if(typeof t=="object"){if(t.width!==void 0&&(typeof t.width=="number"&&t.width>=0?(o.width=t.width,r=t.width):console.warn("[StoryblokRichText] - Width value must be a number greater than or equal to 0")),t.height!==void 0&&(typeof t.height=="number"&&t.height>=0?(o.height=t.height,s=t.height):console.warn("[StoryblokRichText] - Height value must be a number greater than or equal to 0")),t.height===0&&t.width===0&&(delete o.width,delete o.height,console.warn("[StoryblokRichText] - Width and height values cannot both be 0")),t.loading&&["lazy","eager"].includes(t.loading)&&(o.loading=t.loading),t.class&&(o.class=t.class),t.filters){const{filters:c}=t||{},{blur:u,brightness:f,fill:m,format:T,grayscale:R,quality:A,rotate:L}=c||{};u&&i(u,0,100,"blur",n),A&&i(A,0,100,"quality",n),f&&i(f,0,100,"brightness",n),m&&n.push(`fill(${m})`),R&&n.push("grayscale()"),L&&[0,90,180,270].includes(t.filters.rotate||0)&&n.push(`rotate(${L})`),T&&["webp","png","jpeg"].includes(T)&&n.push(`format(${T})`)}t.srcset&&(o.srcset=t.srcset.map(c=>{if(typeof c=="number")return`${e}/m/${c}x0/${n.length>0?`filters:${n.join(":")}`:""} ${c}w`;if(Array.isArray(c)&&c.length===2){const[u,f]=c;return`${e}/m/${u}x${f}/${n.length>0?`filters:${n.join(":")}`:""} ${u}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),t.sizes&&(o.sizes=t.sizes.join(", "))}let l=`${e}/m/`;return(r>0||s>0)&&(l=`${l}${r}x${s}/`),n.length>0&&(l=`${l}filters:${n.join(":")}`),{src:l,attrs:o}}function K(e,t={},r){const s=Pe(t),o=s?`${e} ${s}`:e,n=Array.isArray(r)?r.join(""):r||"";if(e){if(Oe.includes(e))return`<${o}>`}else return n;return`<${o}>${n}</${e}>`}function X(e={}){const t=new Map,{renderFn:r=K,textFn:s=je,resolvers:o={},optimizeImages:n=!1,keyedResolvers:i=!1}=e,l=r!==K,c=(a={})=>{const{textAlign:h,class:d,id:p,style:y,...C}=a,b=[];return y&&b.push(y.endsWith(";")?y:`${y};`),h&&b.push(`text-align: ${h};`),I({...C,class:d,id:p,...b.length>0?{style:b.join(" ")}:{}})},u=a=>(h,d)=>{const p=c(h.attrs);return d.render(a,p,h.children||null)},f=(a,h)=>{const{src:d,alt:p,title:y,srcset:C,sizes:b}=a.attrs||{};let E=d,w={};if(n){const{src:lt,attrs:ct}=xe(d,n);E=lt,w=ct}const P={src:E,alt:p,title:y,srcset:C,sizes:b,...w};return h.render("img",I(P))},m=(a,h)=>{const{level:d,...p}=a.attrs||{},y=c(p);return h.render(`h${d}`,y,a.children)},T=(a,h)=>{var d,p,y,C;const b=h.render("img",{src:(d=a.attrs)==null?void 0:d.fallbackImage,alt:(p=a.attrs)==null?void 0:p.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"});return h.render("span",{"data-type":"emoji","data-name":(y=a.attrs)==null?void 0:y.name,"data-emoji":(C=a.attrs)==null?void 0:C.emoji},b)},R=(a,h)=>h.render("pre",a.attrs||{},h.render("code",{},a.children||"")),A=(a,h=!1)=>({text:d,attrs:p},y)=>{const{class:C,id:b,...E}=p||{},w=h?{class:C,id:b,style:He(E)||void 0}:p||{};return y.render(a,I(w),d)},L=a=>B(a),O=a=>{const{marks:h,...d}=a;if("text"in a){if(h)return h.reduce((y,C)=>L({...C,text:y}),L({...d,children:d.children}));const p=a.attrs||{};if(i){const y=t.get("txt")||0;t.set("txt",y+1),p.key=`txt-${y}`}return s(d.text,p)}return""},ne=(a,h)=>{const{linktype:d,href:p,anchor:y,...C}=a.attrs||{};let b="";switch(d){case H.ASSET:case H.URL:b=p;break;case H.EMAIL:b=`mailto:${p}`;break;case H.STORY:b=p,y&&(b=`${b}#${y}`);break;default:b=p;break}const E={...C};return b&&(E.href=b),h.render("a",E,a.text)},rt=(a,h)=>{var d,p;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),h.render("span",{blok:(d=a==null?void 0:a.attrs)==null?void 0:d.body[0],id:(p=a.attrs)==null?void 0:p.id,style:"display: none"})},st=(a,h)=>{const d=c(a.attrs),p=a.children||null;return h.render("table",d,h.render("tbody",{},p))},ot=(a,h)=>{const d=c(a.attrs);return h.render("tr",d,a.children)},nt=(a,h)=>{const{colspan:d,rowspan:p,colwidth:y,backgroundColor:C,textAlign:b,...E}=a.attrs||{},w=[];y&&w.push(`width: ${y}px;`),C&&w.push(`background-color: ${C};`),b&&w.push(`text-align: ${b};`);const P={...E,...d>1?{colspan:d}:{},...p>1?{rowspan:p}:{},...w.length>0?{style:w.join(" ")}:{}};return h.render("td",I(P),a.children)},it=(a,h)=>{const{colspan:d,rowspan:p,colwidth:y,backgroundColor:C,textAlign:b,...E}=a.attrs||{},w=[];y&&w.push(`width: ${y}px;`),C&&w.push(`background-color: ${C};`),b&&w.push(`text-align: ${b};`);const P={...E,...d>1?{colspan:d}:{},...p>1?{rowspan:p}:{},...w.length>0?{style:w.join(" ")}:{}};return h.render("th",I(P),a.children)},ie=new Map([[k.DOCUMENT,u("")],[k.HEADING,m],[k.PARAGRAPH,u("p")],[k.UL_LIST,u("ul")],[k.OL_LIST,u("ol")],[k.LIST_ITEM,u("li")],[k.IMAGE,f],[k.EMOJI,T],[k.CODE_BLOCK,R],[k.HR,u("hr")],[k.BR,u("br")],[k.QUOTE,u("blockquote")],[k.COMPONENT,rt],[Re.TEXT,O],[$.LINK,ne],[$.ANCHOR,ne],[$.STYLED,A("span",!0)],[$.BOLD,A("strong")],[$.TEXT_STYLE,A("span",!0)],[$.ITALIC,A("em")],[$.UNDERLINE,A("u")],[$.STRIKE,A("s")],[$.CODE,A("code")],[$.SUPERSCRIPT,A("sup")],[$.SUBSCRIPT,A("sub")],[$.HIGHLIGHT,A("mark")],[k.TABLE,st],[k.TABLE_ROW,ot],[k.TABLE_CELL,nt],[k.TABLE_HEADER,it]]),ae=new Map([...ie,...Object.entries(o).map(([a,h])=>[a,h])]),at=()=>({render:(a,h={},d)=>{if(i&&a){const p=t.get(a)||0;t.set(a,p+1),h.key=`${a}-${p}`}return r(a,h,d)},originalResolvers:ie,mergedResolvers:ae});function x(a){const h=ae.get(a.type);if(!h)return console.error("<Storyblok>",`No resolver found for node type ${a.type}`),"";const d=at();if(a.type==="text")return h(a,d);const p=a.content?a.content.map(B):void 0;return h({...a,children:p},d)}function B(a){return a.type==="doc"?l?a.content.map(x):a.content.map(x).join(""):Array.isArray(a)?a.map(x):x(a)}return{render:B}}let Q=!1;const ee=[],te=e=>new Promise((t,r)=>{if(typeof window>"u"){r(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));return}if(window.storyblokRegisterEvent=o=>{if(!window.location.search.includes("_storyblok")){console.warn("You are not in Draft Mode or in the Visual Editor.");return}Q?o():ee.push(o)},document.getElementById("storyblok-javascript-bridge")){t(void 0);return}const s=document.createElement("script");s.async=!0,s.src=e,s.id="storyblok-javascript-bridge",s.onerror=o=>r(o),s.onload=o=>{ee.forEach(n=>n()),Q=!0,t(o)},document.getElementsByTagName("head")[0].appendChild(s)});var Ne=class extends Error{constructor(e){super(e),this.name="AbortError"}};function Me(e,t,r){if(!Number.isFinite(t))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(r))throw new TypeError("Expected `interval` to be a finite number");const s=[];let o=[],n=0,i=!1;const l=async()=>{n++;const u=s.shift();if(u)try{const m=await e(...u.args);u.resolve(m)}catch(m){u.reject(m)}const f=setTimeout(()=>{n--,s.length>0&&l(),o=o.filter(m=>m!==f)},r);o.includes(f)||o.push(f)},c=(...u)=>i?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((f,m)=>{s.push({resolve:f,reject:m,args:u}),n<t&&l()});return c.abort=()=>{i=!0,o.forEach(clearTimeout),o=[],s.forEach(u=>u.reject(()=>new Ne("Throttle function aborted"))),s.length=0},c}var De=Me;const re=(e="")=>e.includes("/cdn/"),Ue=(e,t=25,r=1)=>({...e,per_page:t,page:r}),Ve=e=>new Promise(t=>setTimeout(t,e)),Be=(e=0,t)=>Array.from({length:e},t),Fe=(e=0,t=e)=>{const r=Math.abs(t-e)||0,s=e<t?1:-1;return Be(r,(o,n)=>n*s+e)},ze=async(e,t)=>Promise.all(e.map(t)),Ze=(e=[],t)=>e.map(t).reduce((r,s)=>[...r,...s],[]),D=(e,t,r)=>{const s=[];for(const o in e){if(!Object.prototype.hasOwnProperty.call(e,o))continue;const n=e[o];if(n==null)continue;const i=r?"":encodeURIComponent(o);let l;typeof n=="object"?l=D(n,t?t+encodeURIComponent(`[${i}]`):i,Array.isArray(n)):l=`${t?t+encodeURIComponent(`[${i}]`):i}=${encodeURIComponent(n)}`,s.push(l)}return s.join("&")},se=e=>{const t={eu:"api.storyblok.com",us:"api-us.storyblok.com",cn:"app.storyblokchina.cn",ap:"api-ap.storyblok.com",ca:"api-ca.storyblok.com"};return t[e]??t.eu};var Ge=class{constructor(e){g(this,"baseURL"),g(this,"timeout"),g(this,"headers"),g(this,"responseInterceptor"),g(this,"fetch"),g(this,"ejectInterceptor"),g(this,"url"),g(this,"parameters"),g(this,"fetchOptions"),this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={},this.fetchOptions={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t??{},this._methodHandler("delete")}async _responseHandler(e){const t=[],r={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(s=>{r.data=s});for(const s of e.headers.entries())t[s[0]]=s[1];return r.headers={...t},r.status=e.status,r.statusText=e.statusText,r}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,r=null;e==="get"?t=`${this.baseURL}${this.url}?${D(this.parameters)}`:r=JSON.stringify(this.parameters);const s=new URL(t),o=new AbortController,{signal:n}=o;let i;this.timeout&&(i=setTimeout(()=>o.abort(),this.timeout));try{const l=await this.fetch(`${s}`,{method:e,headers:this.headers,body:r,signal:n,...this.fetchOptions});this.timeout&&clearTimeout(i);const c=await this._responseHandler(l);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(c)):this._statusHandler(c)}catch(l){return{message:l}}}setFetchOptions(e={}){Object.keys(e).length>0&&"method"in e&&delete e.method,this.fetchOptions={...e}}eject(){this.ejectInterceptor=!0}_normalizeErrorMessage(e){if(Array.isArray(e))return e[0]||"Unknown error";if(e&&typeof e=="object"){if(e.error)return e.error;for(const t in e){if(Array.isArray(e[t]))return`${t}: ${e[t][0]}`;if(typeof e[t]=="string")return`${t}: ${e[t]}`}if(e.slug)return e.slug}return"Unknown error"}_statusHandler(e){const t=/20[0-6]/g;return new Promise((r,s)=>{if(t.test(`${e.status}`))return r(e);const o={message:this._normalizeErrorMessage(e.data),status:e.status,response:e};s(o)})}},qe=Ge;const oe="SB-Agent",U={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"7.0.0"},Je={PUBLISHED:"published"};let j={};const S={};var We=class{constructor(e,t){g(this,"client"),g(this,"maxRetries"),g(this,"retriesDelay"),g(this,"throttle"),g(this,"accessToken"),g(this,"cache"),g(this,"resolveCounter"),g(this,"relations"),g(this,"links"),g(this,"version"),g(this,"richTextResolver"),g(this,"resolveNestedRelations"),g(this,"stringifiedStoriesCache"),g(this,"inlineAssets");let r=e.endpoint||t;if(!r){const n=e.https===!1?"http":"https";e.oauthToken?r=`${n}://${se(e.region)}/v1`:r=`${n}://${se(e.region)}/v2`}const s=new Headers;s.set("Content-Type","application/json"),s.set("Accept","application/json"),e.headers&&(e.headers.constructor.name==="Headers"?e.headers.entries().toArray():Object.entries(e.headers)).forEach(([n,i])=>{s.set(n,i)}),s.has(oe)||(s.set(oe,U.defaultAgentName),s.set(U.defaultAgentVersion,U.packageVersion));let o=5;e.oauthToken&&(s.set("Authorization",e.oauthToken),o=3),e.rateLimit&&(o=e.rateLimit),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=De(this.throttledRequest.bind(this),o,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.version=e.version||Je.PUBLISHED,this.inlineAssets=e.inlineAssets||!1,this.client=new qe({baseURL:r,timeout:e.timeout||0,headers:s,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=S[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),typeof e.resolve_relations<"u"&&(e.resolve_level=2),e}factoryParamOptions(e,t){return re(e)?this.parseParams(t):t}makeRequest(e,t,r,s,o){const n=this.factoryParamOptions(e,Ue(t,r,s));return this.cacheResponse(e,n,void 0,o)}get(e,t={},r){t||(t={});const s=`/${e}`;re(s)&&(t.version=t.version||this.version);const o=this.factoryParamOptions(s,t);return this.cacheResponse(s,o,void 0,r)}async getAll(e,t={},r,s){const o=(t==null?void 0:t.per_page)||25,n=`/${e}`.replace(/\/$/,""),i=r??n.substring(n.lastIndexOf("/")+1);t.version=t.version||this.version;const l=1,c=await this.makeRequest(n,t,o,l,s),u=c.total?Math.ceil(c.total/(c.perPage||o)):1,f=await ze(Fe(l,u),m=>this.makeRequest(n,t,o,m+1,s));return Ze([c,...f],m=>Object.values(m.data[i]))}post(e,t={},r){const s=`/${e}`;return this.throttle("post",s,t,r)}put(e,t={},r){const s=`/${e}`;return this.throttle("put",s,t,r)}delete(e,t={},r){t||(t={});const s=`/${e}`;return this.throttle("delete",s,t,r)}getStories(e={},t){return this._addResolveLevel(e),this.get("cdn/stories",e,t)}getStory(e,t={},r){return this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t,r)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_addResolveLevel(e){typeof e.resolve_relations<"u"&&(e.resolve_level=2)}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,r){const s=e[t];s&&s.fieldtype==="multilink"&&s.linktype==="story"&&typeof s.id=="string"&&this.links[r][s.id]?s.story=this._cleanCopy(this.links[r][s.id]):s&&s.linktype==="story"&&typeof s.uuid=="string"&&this.links[r][s.uuid]&&(s.story=this._cleanCopy(this.links[r][s.uuid]))}getStoryReference(e,t){return this.relations[e][t]?JSON.parse(this.stringifiedStoriesCache[t]||JSON.stringify(this.relations[e][t])):t}_resolveField(e,t,r){const s=e[t];typeof s=="string"?e[t]=this.getStoryReference(r,s):Array.isArray(s)&&(e[t]=s.map(o=>this.getStoryReference(r,o)).filter(Boolean))}_insertRelations(e,t,r,s){if(Array.isArray(r)?r.find(n=>n.endsWith(`.${t}`)):r.endsWith(`.${t}`)){this._resolveField(e,t,s);return}const o=e.component?`${e.component}.${t}`:t;(Array.isArray(r)?r.includes(o):r===o)&&this._resolveField(e,t,s)}iterateTree(e,t,r){const s=(o,n="")=>{if(!(!o||o._stopResolving)){if(Array.isArray(o))o.forEach((i,l)=>s(i,`${n}[${l}]`));else if(typeof o=="object")for(const i in o){const l=n?`${n}.${i}`:i;(o.component&&o._uid||o.type==="link")&&(this._insertRelations(o,i,t,r),this._insertLinks(o,i,r)),s(o[i],l)}}};s(e.content)}async resolveLinks(e,t,r){let s=[];if(e.link_uuids){const o=e.link_uuids.length,n=[],i=50;for(let l=0;l<o;l+=i){const c=Math.min(o,l+i);n.push(e.link_uuids.slice(l,c))}for(let l=0;l<n.length;l++)(await this.getStories({per_page:i,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[l].join(",")})).data.stories.forEach(c=>{s.push(c)})}else s=e.links;s.forEach(o=>{this.links[r][o.uuid]={...o,_stopResolving:!0}})}async resolveRelations(e,t,r){let s=[];if(e.rel_uuids){const o=e.rel_uuids.length,n=[],i=50;for(let l=0;l<o;l+=i){const c=Math.min(o,l+i);n.push(e.rel_uuids.slice(l,c))}for(let l=0;l<n.length;l++)(await this.getStories({per_page:i,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[l].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(c=>{s.push(c)});s.length>0&&(e.rels=s,delete e.rel_uuids)}else s=e.rels;s&&s.length>0&&s.forEach(o=>{this.relations[r][o.uuid]={...o,_stopResolving:!0}})}async resolveStories(e,t,r){var s,o;let n=[];if(this.links[r]={},this.relations[r]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(n=t.resolve_relations.split(",")),await this.resolveRelations(e,t,r)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((s=e.links)!=null&&s.length||(o=e.link_uuids)!=null&&o.length)&&await this.resolveLinks(e,t,r),this.resolveNestedRelations)for(const i in this.relations[r])this.iterateTree(this.relations[r][i],n,r);e.story?this.iterateTree(e.story,n,r):e.stories.forEach(i=>{this.iterateTree(i,n,r)}),this.stringifiedStoriesCache={},delete this.links[r],delete this.relations[r]}async cacheResponse(e,t,r,s){const o=D({url:e,params:t}),n=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const i=await n.get(o);if(i)return Promise.resolve(i)}return new Promise(async(i,l)=>{var c;try{const u=await this.throttle("get",e,t,s);if(u.status!==200)return l(u);let f={data:u.data,headers:u.headers};if((c=u.headers)!=null&&c["per-page"]&&(f=Object.assign({},f,{perPage:u.headers["per-page"]?Number.parseInt(u.headers["per-page"]):0,total:u.headers["per-page"]?Number.parseInt(u.headers.total):0})),f.data.story||f.data.stories){const T=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(f.data,t,`${T}`),f=await this.processInlineAssets(f)}t.version==="published"&&e!=="/cdn/spaces/me"&&await n.set(o,f);const m=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&f.data.cv&&(m&&S[t.token]&&S[t.token]!==f.data.cv&&await this.flushCache(),S[t.token]=f.data.cv),i(f)}catch(u){if(u.response&&u.status===429&&(r=typeof r>"u"?0:r+1,r<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${this.retriesDelay/1e3} seconds.`),await Ve(this.retriesDelay),this.cacheResponse(e,t,r).then(i).catch(l);l(u)}})}throttledRequest(e,t,r,s){return this.client.setFetchOptions(s),this.client[e](t,r)}cacheVersions(){return S}cacheVersion(){return S[this.accessToken]}setCacheVersion(e){this.accessToken&&(S[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(S[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(j[e])},getAll(){return Promise.resolve(j)},set(e,t){return j[e]=t,Promise.resolve(void 0)},flush(){return j={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve()},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this.clearCacheVersion(),this}async processInlineAssets(e){if(!this.inlineAssets)return e;const t=r=>{if(!r||typeof r!="object")return r;if(Array.isArray(r))return r.map(o=>t(o));let s={...r};s.fieldtype==="asset"&&Array.isArray(e.data.assets)&&(s={...e.data.assets.find(o=>o.id===s.id),...s});for(const o in s)typeof s[o]=="object"&&(s[o]=t(s[o]));return s};return e.data.story&&(e.data.story.content=t(e.data.story.content)),e.data.stories&&(e.data.stories=e.data.stories.map(r=>(r.content=t(r.content),r))),e}},Ye=We;const Ke=(e={})=>{const{apiOptions:t}=e;if(!t||!t.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new Ye(t)}},Xe=e=>{if(typeof e!="object"||typeof e._editable>"u")return{};try{const t=JSON.parse(e._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return t?{"data-blok-c":JSON.stringify(t),"data-blok-uid":`${t.id}-${t.uid}`}:{}}catch{return{}}};let V="https://app.storyblok.com/f/storyblok-v2-latest.js";const Qe=(e={})=>{var t,r;const{bridge:s,accessToken:o,use:n=[],apiOptions:i={},bridgeUrl:l}=e;i.accessToken=i.accessToken||o;const c={bridge:s,apiOptions:i};let u={};n.forEach(m=>{u={...u,...m(c)}}),l&&(V=l);const f=!(typeof window>"u")&&((r=(t=window.location)==null?void 0:t.search)==null?void 0:r.includes("_storyblok_tk"));return s!==!1&&f&&te(V),u};function et(e,t){return X(t).render(e)}const tt=()=>te(V);v.apiPlugin=Ke,v.getLiveStory=he,v.handleStoryblokMessage=Ee,v.loadStoryblokBridge=tt,v.renderRichText=et,v.richTextResolver=X,v.storyblok=$e,v.storyblokEditable=Xe,v.storyblokInit=Qe,v.toCamelCase=q,v.useStoryblokApi=ue,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
69
+ `),L({entrypoint:"@storyblok/astro/middleware.ts",order:"pre"})),A({id:"storyblok",name:"Storyblok",icon:_,entrypoint:"@storyblok/astro/toolbarApp.ts"})}}}}let W;async function Ee(e){const{action:t,story:r}=e||{};if(t==="input"&&r){const s=async()=>{Y("storyblok-live-preview-updating",{story:r});const n=await Le(r),i=document.body;if(n.outerHTML===i.outerHTML)return;const l=document.querySelector('[data-blok-focused="true"]');Se(i,n,l),Y("storyblok-live-preview-updated",{story:r})};clearTimeout(W),W=setTimeout(s,500)}["published","change"].includes(e==null?void 0:e.action)&&location.reload()}function Se(e,t,r){if(r){const s=r.getAttribute("data-blok-uid"),o=t.querySelector(`[data-blok-uid="${s}"]`);o&&(o.setAttribute("data-blok-focused","true"),r.replaceWith(o))}else e.replaceWith(t)}async function Le(e){const r=await(await fetch(location.href,{method:"POST",body:JSON.stringify({...e,is_storyblok_preview:!0}),headers:{"Content-Type":"application/json"}})).text();return new DOMParser().parseFromString(r,"text/html").body}function Y(e,t){document.dispatchEvent(new CustomEvent(e,{detail:t}))}var _e=Object.defineProperty,Ie=(e,t,r)=>t in e?_e(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,g=(e,t,r)=>Ie(e,typeof t!="symbol"?t+"":t,r);let k=function(e){return e.DOCUMENT="doc",e.HEADING="heading",e.PARAGRAPH="paragraph",e.QUOTE="blockquote",e.OL_LIST="ordered_list",e.UL_LIST="bullet_list",e.LIST_ITEM="list_item",e.CODE_BLOCK="code_block",e.HR="horizontal_rule",e.BR="hard_break",e.IMAGE="image",e.EMOJI="emoji",e.COMPONENT="blok",e.TABLE="table",e.TABLE_ROW="tableRow",e.TABLE_CELL="tableCell",e.TABLE_HEADER="tableHeader",e}({}),$=function(e){return e.BOLD="bold",e.STRONG="strong",e.STRIKE="strike",e.UNDERLINE="underline",e.ITALIC="italic",e.CODE="code",e.LINK="link",e.ANCHOR="anchor",e.STYLED="styled",e.SUPERSCRIPT="superscript",e.SUBSCRIPT="subscript",e.TEXT_STYLE="textStyle",e.HIGHLIGHT="highlight",e}({}),Re=function(e){return e.TEXT="text",e}({}),H=function(e){return e.URL="url",e.STORY="story",e.ASSET="asset",e.EMAIL="email",e}({});const Oe=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],Pe=(e={})=>{const{custom:t,...r}=e,s={...r,...t};return Object.keys(s).map(o=>`${o}="${s[o]}"`).join(" ")},He=(e={})=>Object.keys(e).map(t=>`${t}: ${e[t]}`).join("; ");function je(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}const I=e=>Object.fromEntries(Object.entries(e).filter(([t,r])=>r!==void 0));function xe(e,t){if(!t)return{src:e,attrs:{}};let r=0,s=0;const o={},n=[];function i(c,u,f,m,T){typeof c!="number"||c<=u||c>=f?console.warn(`[StoryblokRichText] - ${m.charAt(0).toUpperCase()+m.slice(1)} value must be a number between ${u} and ${f} (inclusive)`):T.push(`${m}(${c})`)}if(typeof t=="object"){if(t.width!==void 0&&(typeof t.width=="number"&&t.width>=0?(o.width=t.width,r=t.width):console.warn("[StoryblokRichText] - Width value must be a number greater than or equal to 0")),t.height!==void 0&&(typeof t.height=="number"&&t.height>=0?(o.height=t.height,s=t.height):console.warn("[StoryblokRichText] - Height value must be a number greater than or equal to 0")),t.height===0&&t.width===0&&(delete o.width,delete o.height,console.warn("[StoryblokRichText] - Width and height values cannot both be 0")),t.loading&&["lazy","eager"].includes(t.loading)&&(o.loading=t.loading),t.class&&(o.class=t.class),t.filters){const{filters:c}=t||{},{blur:u,brightness:f,fill:m,format:T,grayscale:R,quality:A,rotate:L}=c||{};u&&i(u,0,100,"blur",n),A&&i(A,0,100,"quality",n),f&&i(f,0,100,"brightness",n),m&&n.push(`fill(${m})`),R&&n.push("grayscale()"),L&&[0,90,180,270].includes(t.filters.rotate||0)&&n.push(`rotate(${L})`),T&&["webp","png","jpeg"].includes(T)&&n.push(`format(${T})`)}t.srcset&&(o.srcset=t.srcset.map(c=>{if(typeof c=="number")return`${e}/m/${c}x0/${n.length>0?`filters:${n.join(":")}`:""} ${c}w`;if(Array.isArray(c)&&c.length===2){const[u,f]=c;return`${e}/m/${u}x${f}/${n.length>0?`filters:${n.join(":")}`:""} ${u}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),t.sizes&&(o.sizes=t.sizes.join(", "))}let l=`${e}/m/`;return(r>0||s>0)&&(l=`${l}${r}x${s}/`),n.length>0&&(l=`${l}filters:${n.join(":")}`),{src:l,attrs:o}}function K(e,t={},r){const s=Pe(t),o=s?`${e} ${s}`:e,n=Array.isArray(r)?r.join(""):r||"";if(e){if(Oe.includes(e))return`<${o}>`}else return n;return`<${o}>${n}</${e}>`}function X(e={}){const t=new Map,{renderFn:r=K,textFn:s=je,resolvers:o={},optimizeImages:n=!1,keyedResolvers:i=!1}=e,l=r!==K,c=(a={})=>{const{textAlign:h,class:d,id:p,style:y,...C}=a,b=[];return y&&b.push(y.endsWith(";")?y:`${y};`),h&&b.push(`text-align: ${h};`),I({...C,class:d,id:p,...b.length>0?{style:b.join(" ")}:{}})},u=a=>(h,d)=>{const p=c(h.attrs);return d.render(a,p,h.children||null)},f=(a,h)=>{const{src:d,alt:p,title:y,srcset:C,sizes:b}=a.attrs||{};let E=d,w={};if(n){const{src:lt,attrs:ct}=xe(d,n);E=lt,w=ct}const P={src:E,alt:p,title:y,srcset:C,sizes:b,...w};return h.render("img",I(P))},m=(a,h)=>{const{level:d,...p}=a.attrs||{},y=c(p);return h.render(`h${d}`,y,a.children)},T=(a,h)=>{var d,p,y,C;const b=h.render("img",{src:(d=a.attrs)==null?void 0:d.fallbackImage,alt:(p=a.attrs)==null?void 0:p.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"});return h.render("span",{"data-type":"emoji","data-name":(y=a.attrs)==null?void 0:y.name,"data-emoji":(C=a.attrs)==null?void 0:C.emoji},b)},R=(a,h)=>h.render("pre",a.attrs||{},h.render("code",{},a.children||"")),A=(a,h=!1)=>({text:d,attrs:p},y)=>{const{class:C,id:b,...E}=p||{},w=h?{class:C,id:b,style:He(E)||void 0}:p||{};return y.render(a,I(w),d)},L=a=>B(a),O=a=>{const{marks:h,...d}=a;if("text"in a){if(h)return h.reduce((y,C)=>L({...C,text:y}),L({...d,children:d.children}));const p=a.attrs||{};if(i){const y=t.get("txt")||0;t.set("txt",y+1),p.key=`txt-${y}`}return s(d.text,p)}return""},ne=(a,h)=>{const{linktype:d,href:p,anchor:y,...C}=a.attrs||{};let b="";switch(d){case H.ASSET:case H.URL:b=p;break;case H.EMAIL:b=`mailto:${p}`;break;case H.STORY:b=p,y&&(b=`${b}#${y}`);break;default:b=p;break}const E={...C};return b&&(E.href=b),h.render("a",E,a.text)},rt=(a,h)=>{var d,p;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),h.render("span",{blok:(d=a==null?void 0:a.attrs)==null?void 0:d.body[0],id:(p=a.attrs)==null?void 0:p.id,style:"display: none"})},st=(a,h)=>{const d=c(a.attrs),p=a.children||null;return h.render("table",d,h.render("tbody",{},p))},ot=(a,h)=>{const d=c(a.attrs);return h.render("tr",d,a.children)},nt=(a,h)=>{const{colspan:d,rowspan:p,colwidth:y,backgroundColor:C,textAlign:b,...E}=a.attrs||{},w=[];y&&w.push(`width: ${y}px;`),C&&w.push(`background-color: ${C};`),b&&w.push(`text-align: ${b};`);const P={...E,...d>1?{colspan:d}:{},...p>1?{rowspan:p}:{},...w.length>0?{style:w.join(" ")}:{}};return h.render("td",I(P),a.children)},it=(a,h)=>{const{colspan:d,rowspan:p,colwidth:y,backgroundColor:C,textAlign:b,...E}=a.attrs||{},w=[];y&&w.push(`width: ${y}px;`),C&&w.push(`background-color: ${C};`),b&&w.push(`text-align: ${b};`);const P={...E,...d>1?{colspan:d}:{},...p>1?{rowspan:p}:{},...w.length>0?{style:w.join(" ")}:{}};return h.render("th",I(P),a.children)},ie=new Map([[k.DOCUMENT,u("")],[k.HEADING,m],[k.PARAGRAPH,u("p")],[k.UL_LIST,u("ul")],[k.OL_LIST,u("ol")],[k.LIST_ITEM,u("li")],[k.IMAGE,f],[k.EMOJI,T],[k.CODE_BLOCK,R],[k.HR,u("hr")],[k.BR,u("br")],[k.QUOTE,u("blockquote")],[k.COMPONENT,rt],[Re.TEXT,O],[$.LINK,ne],[$.ANCHOR,ne],[$.STYLED,A("span",!0)],[$.BOLD,A("strong")],[$.TEXT_STYLE,A("span",!0)],[$.ITALIC,A("em")],[$.UNDERLINE,A("u")],[$.STRIKE,A("s")],[$.CODE,A("code")],[$.SUPERSCRIPT,A("sup")],[$.SUBSCRIPT,A("sub")],[$.HIGHLIGHT,A("mark")],[k.TABLE,st],[k.TABLE_ROW,ot],[k.TABLE_CELL,nt],[k.TABLE_HEADER,it]]),ae=new Map([...ie,...Object.entries(o).map(([a,h])=>[a,h])]),at=()=>({render:(a,h={},d)=>{if(i&&a){const p=t.get(a)||0;t.set(a,p+1),h.key=`${a}-${p}`}return r(a,h,d)},originalResolvers:ie,mergedResolvers:ae});function x(a){const h=ae.get(a.type);if(!h)return console.error("<Storyblok>",`No resolver found for node type ${a.type}`),"";const d=at();if(a.type==="text")return h(a,d);const p=a.content?a.content.map(B):void 0;return h({...a,children:p},d)}function B(a){return a.type==="doc"?l?a.content.map(x):a.content.map(x).join(""):Array.isArray(a)?a.map(x):x(a)}return{render:B}}let Q=!1;const ee=[],te=e=>new Promise((t,r)=>{if(typeof window>"u"){r(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));return}if(window.storyblokRegisterEvent=o=>{if(!window.location.search.includes("_storyblok")){console.warn("You are not in Draft Mode or in the Visual Editor.");return}Q?o():ee.push(o)},document.getElementById("storyblok-javascript-bridge")){t(void 0);return}const s=document.createElement("script");s.async=!0,s.src=e,s.id="storyblok-javascript-bridge",s.onerror=o=>r(o),s.onload=o=>{ee.forEach(n=>n()),Q=!0,t(o)},document.getElementsByTagName("head")[0].appendChild(s)});var Ne=class extends Error{constructor(e){super(e),this.name="AbortError"}};function Me(e,t,r){if(!Number.isFinite(t))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(r))throw new TypeError("Expected `interval` to be a finite number");const s=[];let o=[],n=0,i=!1;const l=async()=>{n++;const u=s.shift();if(u)try{const m=await e(...u.args);u.resolve(m)}catch(m){u.reject(m)}const f=setTimeout(()=>{n--,s.length>0&&l(),o=o.filter(m=>m!==f)},r);o.includes(f)||o.push(f)},c=(...u)=>i?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((f,m)=>{s.push({resolve:f,reject:m,args:u}),n<t&&l()});return c.abort=()=>{i=!0,o.forEach(clearTimeout),o=[],s.forEach(u=>u.reject(()=>new Ne("Throttle function aborted"))),s.length=0},c}var De=Me;const re=(e="")=>e.includes("/cdn/"),Ue=(e,t=25,r=1)=>({...e,per_page:t,page:r}),Ve=e=>new Promise(t=>setTimeout(t,e)),Be=(e=0,t)=>Array.from({length:e},t),Fe=(e=0,t=e)=>{const r=Math.abs(t-e)||0,s=e<t?1:-1;return Be(r,(o,n)=>n*s+e)},ze=async(e,t)=>Promise.all(e.map(t)),Ze=(e=[],t)=>e.map(t).reduce((r,s)=>[...r,...s],[]),D=(e,t,r)=>{const s=[];for(const o in e){if(!Object.prototype.hasOwnProperty.call(e,o))continue;const n=e[o];if(n==null)continue;const i=r?"":encodeURIComponent(o);let l;typeof n=="object"?l=D(n,t?t+encodeURIComponent(`[${i}]`):i,Array.isArray(n)):l=`${t?t+encodeURIComponent(`[${i}]`):i}=${encodeURIComponent(n)}`,s.push(l)}return s.join("&")},se=e=>{const t={eu:"api.storyblok.com",us:"api-us.storyblok.com",cn:"app.storyblokchina.cn",ap:"api-ap.storyblok.com",ca:"api-ca.storyblok.com"};return t[e]??t.eu};var Ge=class{constructor(e){g(this,"baseURL"),g(this,"timeout"),g(this,"headers"),g(this,"responseInterceptor"),g(this,"fetch"),g(this,"ejectInterceptor"),g(this,"url"),g(this,"parameters"),g(this,"fetchOptions"),this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={},this.fetchOptions={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t??{},this._methodHandler("delete")}async _responseHandler(e){const t=[],r={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(s=>{r.data=s});for(const s of e.headers.entries())t[s[0]]=s[1];return r.headers={...t},r.status=e.status,r.statusText=e.statusText,r}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,r=null;e==="get"?t=`${this.baseURL}${this.url}?${D(this.parameters)}`:r=JSON.stringify(this.parameters);const s=new URL(t),o=new AbortController,{signal:n}=o;let i;this.timeout&&(i=setTimeout(()=>o.abort(),this.timeout));try{const l=await this.fetch(`${s}`,{method:e,headers:this.headers,body:r,signal:n,...this.fetchOptions});this.timeout&&clearTimeout(i);const c=await this._responseHandler(l);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(c)):this._statusHandler(c)}catch(l){return{message:l}}}setFetchOptions(e={}){Object.keys(e).length>0&&"method"in e&&delete e.method,this.fetchOptions={...e}}eject(){this.ejectInterceptor=!0}_normalizeErrorMessage(e){if(Array.isArray(e))return e[0]||"Unknown error";if(e&&typeof e=="object"){if(e.error)return e.error;for(const t in e){if(Array.isArray(e[t]))return`${t}: ${e[t][0]}`;if(typeof e[t]=="string")return`${t}: ${e[t]}`}if(e.slug)return e.slug}return"Unknown error"}_statusHandler(e){const t=/20[0-6]/g;return new Promise((r,s)=>{if(t.test(`${e.status}`))return r(e);const o={message:this._normalizeErrorMessage(e.data),status:e.status,response:e};s(o)})}},qe=Ge;const oe="SB-Agent",U={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"7.0.0"},Je={PUBLISHED:"published"};let j={};const S={};var We=class{constructor(e,t){g(this,"client"),g(this,"maxRetries"),g(this,"retriesDelay"),g(this,"throttle"),g(this,"accessToken"),g(this,"cache"),g(this,"resolveCounter"),g(this,"relations"),g(this,"links"),g(this,"version"),g(this,"richTextResolver"),g(this,"resolveNestedRelations"),g(this,"stringifiedStoriesCache"),g(this,"inlineAssets");let r=e.endpoint||t;if(!r){const n=e.https===!1?"http":"https";e.oauthToken?r=`${n}://${se(e.region)}/v1`:r=`${n}://${se(e.region)}/v2`}const s=new Headers;s.set("Content-Type","application/json"),s.set("Accept","application/json"),e.headers&&(e.headers.constructor.name==="Headers"?e.headers.entries().toArray():Object.entries(e.headers)).forEach(([n,i])=>{s.set(n,i)}),s.has(oe)||(s.set(oe,U.defaultAgentName),s.set(U.defaultAgentVersion,U.packageVersion));let o=5;e.oauthToken&&(s.set("Authorization",e.oauthToken),o=3),e.rateLimit&&(o=e.rateLimit),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=De(this.throttledRequest.bind(this),o,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.version=e.version||Je.PUBLISHED,this.inlineAssets=e.inlineAssets||!1,this.client=new qe({baseURL:r,timeout:e.timeout||0,headers:s,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=S[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),typeof e.resolve_relations<"u"&&(e.resolve_level=2),e}factoryParamOptions(e,t){return re(e)?this.parseParams(t):t}makeRequest(e,t,r,s,o){const n=this.factoryParamOptions(e,Ue(t,r,s));return this.cacheResponse(e,n,void 0,o)}get(e,t={},r){t||(t={});const s=`/${e}`;re(s)&&(t.version=t.version||this.version);const o=this.factoryParamOptions(s,t);return this.cacheResponse(s,o,void 0,r)}async getAll(e,t={},r,s){const o=(t==null?void 0:t.per_page)||25,n=`/${e}`.replace(/\/$/,""),i=r??n.substring(n.lastIndexOf("/")+1);t.version=t.version||this.version;const l=1,c=await this.makeRequest(n,t,o,l,s),u=c.total?Math.ceil(c.total/(c.perPage||o)):1,f=await ze(Fe(l,u),m=>this.makeRequest(n,t,o,m+1,s));return Ze([c,...f],m=>Object.values(m.data[i]))}post(e,t={},r){const s=`/${e}`;return this.throttle("post",s,t,r)}put(e,t={},r){const s=`/${e}`;return this.throttle("put",s,t,r)}delete(e,t={},r){t||(t={});const s=`/${e}`;return this.throttle("delete",s,t,r)}getStories(e={},t){return this._addResolveLevel(e),this.get("cdn/stories",e,t)}getStory(e,t={},r){return this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t,r)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_addResolveLevel(e){typeof e.resolve_relations<"u"&&(e.resolve_level=2)}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,r){const s=e[t];s&&s.fieldtype==="multilink"&&s.linktype==="story"&&typeof s.id=="string"&&this.links[r][s.id]?s.story=this._cleanCopy(this.links[r][s.id]):s&&s.linktype==="story"&&typeof s.uuid=="string"&&this.links[r][s.uuid]&&(s.story=this._cleanCopy(this.links[r][s.uuid]))}getStoryReference(e,t){return this.relations[e][t]?JSON.parse(this.stringifiedStoriesCache[t]||JSON.stringify(this.relations[e][t])):t}_resolveField(e,t,r){const s=e[t];typeof s=="string"?e[t]=this.getStoryReference(r,s):Array.isArray(s)&&(e[t]=s.map(o=>this.getStoryReference(r,o)).filter(Boolean))}_insertRelations(e,t,r,s){if(Array.isArray(r)?r.find(n=>n.endsWith(`.${t}`)):r.endsWith(`.${t}`)){this._resolveField(e,t,s);return}const o=e.component?`${e.component}.${t}`:t;(Array.isArray(r)?r.includes(o):r===o)&&this._resolveField(e,t,s)}iterateTree(e,t,r){const s=(o,n="")=>{if(!(!o||o._stopResolving)){if(Array.isArray(o))o.forEach((i,l)=>s(i,`${n}[${l}]`));else if(typeof o=="object")for(const i in o){const l=n?`${n}.${i}`:i;(o.component&&o._uid||o.type==="link")&&(this._insertRelations(o,i,t,r),this._insertLinks(o,i,r)),s(o[i],l)}}};s(e.content)}async resolveLinks(e,t,r){let s=[];if(e.link_uuids){const o=e.link_uuids.length,n=[],i=50;for(let l=0;l<o;l+=i){const c=Math.min(o,l+i);n.push(e.link_uuids.slice(l,c))}for(let l=0;l<n.length;l++)(await this.getStories({per_page:i,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[l].join(",")})).data.stories.forEach(c=>{s.push(c)})}else s=e.links;s.forEach(o=>{this.links[r][o.uuid]={...o,_stopResolving:!0}})}async resolveRelations(e,t,r){let s=[];if(e.rel_uuids){const o=e.rel_uuids.length,n=[],i=50;for(let l=0;l<o;l+=i){const c=Math.min(o,l+i);n.push(e.rel_uuids.slice(l,c))}for(let l=0;l<n.length;l++)(await this.getStories({per_page:i,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[l].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(c=>{s.push(c)});s.length>0&&(e.rels=s,delete e.rel_uuids)}else s=e.rels;s&&s.length>0&&s.forEach(o=>{this.relations[r][o.uuid]={...o,_stopResolving:!0}})}async resolveStories(e,t,r){var s,o;let n=[];if(this.links[r]={},this.relations[r]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(n=t.resolve_relations.split(",")),await this.resolveRelations(e,t,r)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((s=e.links)!=null&&s.length||(o=e.link_uuids)!=null&&o.length)&&await this.resolveLinks(e,t,r),this.resolveNestedRelations)for(const i in this.relations[r])this.iterateTree(this.relations[r][i],n,r);e.story?this.iterateTree(e.story,n,r):e.stories.forEach(i=>{this.iterateTree(i,n,r)}),this.stringifiedStoriesCache={},delete this.links[r],delete this.relations[r]}async cacheResponse(e,t,r,s){const o=D({url:e,params:t}),n=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const i=await n.get(o);if(i)return Promise.resolve(i)}return new Promise(async(i,l)=>{var c;try{const u=await this.throttle("get",e,t,s);if(u.status!==200)return l(u);let f={data:u.data,headers:u.headers};if((c=u.headers)!=null&&c["per-page"]&&(f=Object.assign({},f,{perPage:u.headers["per-page"]?Number.parseInt(u.headers["per-page"]):0,total:u.headers["per-page"]?Number.parseInt(u.headers.total):0})),f.data.story||f.data.stories){const T=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(f.data,t,`${T}`),f=await this.processInlineAssets(f)}t.version==="published"&&e!=="/cdn/spaces/me"&&await n.set(o,f);const m=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&f.data.cv&&(m&&S[t.token]&&S[t.token]!==f.data.cv&&await this.flushCache(),S[t.token]=f.data.cv),i(f)}catch(u){if(u.response&&u.status===429&&(r=typeof r>"u"?0:r+1,r<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${this.retriesDelay/1e3} seconds.`),await Ve(this.retriesDelay),this.cacheResponse(e,t,r).then(i).catch(l);l(u)}})}throttledRequest(e,t,r,s){return this.client.setFetchOptions(s),this.client[e](t,r)}cacheVersions(){return S}cacheVersion(){return S[this.accessToken]}setCacheVersion(e){this.accessToken&&(S[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(S[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(j[e])},getAll(){return Promise.resolve(j)},set(e,t){return j[e]=t,Promise.resolve(void 0)},flush(){return j={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve()},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this.clearCacheVersion(),this}async processInlineAssets(e){if(!this.inlineAssets)return e;const t=r=>{if(!r||typeof r!="object")return r;if(Array.isArray(r))return r.map(o=>t(o));let s={...r};s.fieldtype==="asset"&&Array.isArray(e.data.assets)&&(s={...e.data.assets.find(o=>o.id===s.id),...s});for(const o in s)typeof s[o]=="object"&&(s[o]=t(s[o]));return s};return e.data.story&&(e.data.story.content=t(e.data.story.content)),e.data.stories&&(e.data.stories=e.data.stories.map(r=>(r.content=t(r.content),r))),e}},Ye=We;const Ke=(e={})=>{const{apiOptions:t}=e;if(!t||!t.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new Ye(t)}},Xe=e=>{if(typeof e!="object"||typeof e._editable>"u")return{};try{const t=JSON.parse(e._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return t?{"data-blok-c":JSON.stringify(t),"data-blok-uid":`${t.id}-${t.uid}`}:{}}catch{return{}}};let V="https://app.storyblok.com/f/storyblok-v2-latest.js";const Qe=(e={})=>{var t,r;const{bridge:s,accessToken:o,use:n=[],apiOptions:i={},bridgeUrl:l}=e;i.accessToken=i.accessToken||o;const c={bridge:s,apiOptions:i};let u={};n.forEach(m=>{u={...u,...m(c)}}),l&&(V=l);const f=!(typeof window>"u")&&((r=(t=window.location)==null?void 0:t.search)==null?void 0:r.includes("_storyblok_tk"));return s!==!1&&f&&te(V),u};function et(e,t){return X(t).render(e)}const tt=()=>te(V);v.apiPlugin=Ke,v.getLiveStory=he,v.handleStoryblokMessage=Ee,v.loadStoryblokBridge=tt,v.renderRichText=et,v.richTextResolver=X,v.storyblok=$e,v.storyblokEditable=Xe,v.storyblokInit=Qe,v.toCamelCase=q,v.useStoryblokApi=ue,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@storyblok/astro",
3
3
  "type": "module",
4
- "version": "7.3.2",
4
+ "version": "7.3.3",
5
5
  "private": false,
6
6
  "description": "Official Astro integration for the Storyblok Headless CMS",
7
7
  "author": "Storyblok",
@@ -53,7 +53,7 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "camelcase": "^8.0.0",
56
- "@storyblok/js": "4.3.1"
56
+ "@storyblok/js": "4.3.2"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@cypress/vite-dev-server": "^6.0.3",