@storyblok/js 4.4.3 → 4.4.5

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.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * name: @storyblok/js
3
- * (c) 2025
3
+ * (c) 2026
4
4
  * description: SDK to integrate Storyblok into your project using JavaScript.
5
5
  * author: undefined
6
6
  */
7
- (function(_,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(_=typeof globalThis<"u"?globalThis:_||self,g(_.storyblok={}))})(this,function(_){"use strict";var Be=Object.defineProperty;var De=(_,g,A)=>g in _?Be(_,g,{enumerable:!0,configurable:!0,writable:!0,value:A}):_[g]=A;var b=(_,g,A)=>De(_,typeof g!="symbol"?g+"":g,A);let g=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}({}),A=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}({}),V=function(e){return e.TEXT="text",e}({}),N=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"],ae=(e={})=>{const{custom:t,...s}=e,r={...s,...t};return Object.keys(r).map(i=>`${i}="${r[i]}"`).join(" ")},le=(e={})=>Object.keys(e).map(t=>`${t}: ${e[t]}`).join("; ");function ce(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}const O=e=>Object.fromEntries(Object.entries(e).filter(([t,s])=>s!==void 0));function ue(e,t){if(!t)return{src:e,attrs:{}};let s=0,r=0;const i={},n=[];function l(u,c,m,p,v){typeof u!="number"||u<=c||u>=m?console.warn(`[StoryblokRichText] - ${p.charAt(0).toUpperCase()+p.slice(1)} value must be a number between ${c} and ${m} (inclusive)`):v.push(`${p}(${u})`)}if(typeof t=="object"){if(t.width!==void 0&&(typeof t.width=="number"&&t.width>=0?(i.width=t.width,s=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?(i.height=t.height,r=t.height):console.warn("[StoryblokRichText] - Height value must be a number greater than or equal to 0")),t.height===0&&t.width===0&&(delete i.width,delete i.height,console.warn("[StoryblokRichText] - Width and height values cannot both be 0")),t.loading&&["lazy","eager"].includes(t.loading)&&(i.loading=t.loading),t.class&&(i.class=t.class),t.filters){const{filters:u}=t||{},{blur:c,brightness:m,fill:p,format:v,grayscale:L,quality:k,rotate:C}=u||{};c&&l(c,0,100,"blur",n),k&&l(k,0,100,"quality",n),m&&l(m,0,100,"brightness",n),p&&n.push(`fill(${p})`),L&&n.push("grayscale()"),C&&[0,90,180,270].includes(t.filters.rotate||0)&&n.push(`rotate(${C})`),v&&["webp","png","jpeg"].includes(v)&&n.push(`format(${v})`)}t.srcset&&(i.srcset=t.srcset.map(u=>{if(typeof u=="number")return`${e}/m/${u}x0/${n.length>0?`filters:${n.join(":")}`:""} ${u}w`;if(Array.isArray(u)&&u.length===2){const[c,m]=u;return`${e}/m/${c}x${m}/${n.length>0?`filters:${n.join(":")}`:""} ${c}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),t.sizes&&(i.sizes=t.sizes.join(", "))}let a=`${e}/m/`;return(s>0||r>0)&&(a=`${a}${s}x${r}/`),n.length>0&&(a=`${a}filters:${n.join(":")}`),{src:a,attrs:i}}function Y(e,t={},s){const r=ae(t),i=r?`${e} ${r}`:e,n=Array.isArray(s)?s.join(""):s||"";if(e){if(oe.includes(e))return`<${i}>`}else return n;return`<${i}>${n}</${e}>`}function J(e={}){const t=new Map,{renderFn:s=Y,textFn:r=ce,resolvers:i={},optimizeImages:n=!1,keyedResolvers:l=!1}=e,a=s!==Y,u=(o={})=>{const{textAlign:h,class:d,id:f,style:y,...E}=o,R=[];return y&&R.push(y.endsWith(";")?y:`${y};`),h&&R.push(`text-align: ${h};`),O({...E,class:d,id:f,...R.length>0?{style:R.join(" ")}:{}})},c=o=>(h,d)=>{const f=u(h.attrs);return d.render(o,f,h.children||null)},m=(o,h)=>{const{src:d,alt:f,title:y,srcset:E,sizes:R}=o.attrs||{};let w=d,S={};if(n){const{src:qe,attrs:Fe}=ue(d,n);w=qe,S=Fe}const P={src:w,alt:f,title:y,srcset:E,sizes:R,...S};return h.render("img",O(P))},p=(o,h)=>{const{level:d,...f}=o.attrs||{},y=u(f);return h.render(`h${d}`,y,o.children)},v=(o,h)=>{var f,y,E,R;const d=h.render("img",{src:(f=o.attrs)==null?void 0:f.fallbackImage,alt:(y=o.attrs)==null?void 0:y.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":(E=o.attrs)==null?void 0:E.name,"data-emoji":(R=o.attrs)==null?void 0:R.emoji},d)},L=(o,h)=>h.render("pre",o.attrs||{},h.render("code",{},o.children||"")),k=(o,h=!1)=>({text:d,attrs:f},y)=>{const{class:E,id:R,...w}=f||{},S=h?{class:E,id:R,style:le(w)||void 0}:f||{};return y.render(o,O(S),d)},C=o=>z(o),D=o=>{const{marks:h,...d}=o;if("text"in o){if(h)return h.reduce((y,E)=>C({...E,text:y}),C({...d,children:d.children}));const f=o.attrs||{};if(l){const y=t.get("txt")||0;t.set("txt",y+1),f.key=`txt-${y}`}return r(d.text,f)}return""},se=(o,h)=>{const{linktype:d,href:f,anchor:y,...E}=o.attrs||{};let R="";switch(d){case N.ASSET:case N.URL:R=f;break;case N.EMAIL:R=`mailto:${f}`;break;case N.STORY:R=f,y&&(R=`${R}#${y}`);break;default:R=f;break}const w={...E};return R&&(w.href=R),h.render("a",w,o.text)},Me=(o,h)=>{var d,f;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),h.render("span",{blok:(d=o==null?void 0:o.attrs)==null?void 0:d.body[0],id:(f=o.attrs)==null?void 0:f.id,style:"display: none"})},He=(o,h)=>{const d=u(o.attrs),f=o.children||null;return h.render("table",d,h.render("tbody",{},f))},Ue=(o,h)=>{const d=u(o.attrs);return h.render("tr",d,o.children)},$e=(o,h)=>{const{colspan:d,rowspan:f,colwidth:y,backgroundColor:E,textAlign:R,...w}=o.attrs||{},S=[];y&&S.push(`width: ${y}px;`),E&&S.push(`background-color: ${E};`),R&&S.push(`text-align: ${R};`);const P={...w,...d>1?{colspan:d}:{},...f>1?{rowspan:f}:{},...S.length>0?{style:S.join(" ")}:{}};return h.render("td",O(P),o.children)},je=(o,h)=>{const{colspan:d,rowspan:f,colwidth:y,backgroundColor:E,textAlign:R,...w}=o.attrs||{},S=[];y&&S.push(`width: ${y}px;`),E&&S.push(`background-color: ${E};`),R&&S.push(`text-align: ${R};`);const P={...w,...d>1?{colspan:d}:{},...f>1?{rowspan:f}:{},...S.length>0?{style:S.join(" ")}:{}};return h.render("th",O(P),o.children)},ie=new Map([[g.DOCUMENT,c("")],[g.HEADING,p],[g.PARAGRAPH,c("p")],[g.UL_LIST,c("ul")],[g.OL_LIST,c("ol")],[g.LIST_ITEM,c("li")],[g.IMAGE,m],[g.EMOJI,v],[g.CODE_BLOCK,L],[g.HR,c("hr")],[g.BR,c("br")],[g.QUOTE,c("blockquote")],[g.COMPONENT,Me],[V.TEXT,D],[A.LINK,se],[A.ANCHOR,se],[A.STYLED,k("span",!0)],[A.BOLD,k("strong")],[A.TEXT_STYLE,k("span",!0)],[A.ITALIC,k("em")],[A.UNDERLINE,k("u")],[A.STRIKE,k("s")],[A.CODE,k("code")],[A.SUPERSCRIPT,k("sup")],[A.SUBSCRIPT,k("sub")],[A.HIGHLIGHT,k("mark")],[g.TABLE,He],[g.TABLE_ROW,Ue],[g.TABLE_CELL,$e],[g.TABLE_HEADER,je]]),ne=new Map([...ie,...Object.entries(i).map(([o,h])=>[o,h])]),Ge=()=>({render:(d,f={},y)=>{if(l&&d){const E=t.get(d)||0;t.set(d,E+1),f.key=`${d}-${E}`}return s(d,f,y)},originalResolvers:ie,mergedResolvers:ne});function U(o){const h=ne.get(o.type);if(!h)return console.error("<Storyblok>",`No resolver found for node type ${o.type}`),"";const d=Ge();if(o.type==="text")return h(o,d);const f=o.content?o.content.map(z):void 0;return h({...o,children:f},d)}function z(o){return o.type==="doc"?a?o.content.map(U):o.content.map(U).join(""):Array.isArray(o)?o.map(U):U(o)}return{render:z}}let K=!1;const W=[],Q=e=>new Promise((t,s)=>{if(typeof window>"u"){s(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));return}if(window.storyblokRegisterEvent=i=>{if(!window.location.search.includes("_storyblok")){console.warn("You are not in Draft Mode or in the Visual Editor.");return}K?i():W.push(i)},document.getElementById("storyblok-javascript-bridge")){t(void 0);return}const r=document.createElement("script");r.async=!0,r.src=e,r.id="storyblok-javascript-bridge",r.onerror=i=>s(i),r.onload=i=>{W.forEach(n=>n()),K=!0,t(i)},document.getElementsByTagName("head")[0].appendChild(r)}),$=(e="")=>e.includes("/cdn/"),he=(e,t=25,s=1)=>({...e,per_page:t,page:s}),de=e=>new Promise(t=>setTimeout(t,e)),fe=(e=0,t)=>Array.from({length:e},t),ge=(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return fe(s,(i,n)=>n*r+e)},ye=async(e,t)=>Promise.all(e.map(t)),be=(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[]),j=(e,t,s)=>{const r=[];for(const i in e){if(!Object.prototype.hasOwnProperty.call(e,i))continue;const n=e[i];if(n==null)continue;const l=s?"":encodeURIComponent(i);let a;typeof n=="object"?a=j(n,t?t+encodeURIComponent(`[${l}]`):l,Array.isArray(n)):a=`${t?t+encodeURIComponent(`[${l}]`):l}=${encodeURIComponent(n)}`,r.push(a)}return r.join("&")},X=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 me=class{constructor(e){b(this,"baseURL");b(this,"timeout");b(this,"headers");b(this,"responseInterceptor");b(this,"fetch");b(this,"ejectInterceptor");b(this,"url");b(this,"parameters");b(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=[],s={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(r=>{s.data=r});for(const r of e.headers.entries())t[r[0]]=r[1];return s.headers={...t},s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,s=null;e==="get"?t=`${this.baseURL}${this.url}?${j(this.parameters)}`:s=JSON.stringify(this.parameters);const r=new URL(t),i=new AbortController,{signal:n}=i;let l=null;this.timeout&&(l=setTimeout(()=>i.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:n,...this.fetchOptions});this.timeout&&l&&clearTimeout(l);const u=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(u)):this._statusHandler(u)}catch(a){return{message:a}}}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((s,r)=>{if(t.test(`${e.status}`))return s(e);const i={message:this._normalizeErrorMessage(e.data),status:e.status,response:e};r(i)})}},pe=me;const Z="SB-Agent",G={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"7.0.0"},ee={DRAFT:"draft",PUBLISHED:"published"},Re=25,q={SMALL:25,MEDIUM:50,LARGE:75},I={SINGLE_OR_SMALL:50,MEDIUM:15,LARGE:10,VERY_LARGE:6},F=1e3,x=3;function ve(e){return e.version===ee.DRAFT}function _e(e,t){const s=e.includes("/cdn/stories/"),r=e.split("/").length>3&&!e.endsWith("/cdn/stories"),i="find_by"in t;return s&&r||i}function Ee(e){return e<=q.SMALL?I.SINGLE_OR_SMALL:e<=q.MEDIUM?I.MEDIUM:e<=q.LARGE?I.LARGE:I.VERY_LARGE}function M(e,t,s={},r){if(s.userRateLimit!==void 0)return Math.min(s.userRateLimit,F);if(s.serverHeadersRateLimit!==void 0)return Math.min(s.serverHeadersRateLimit,F);if(r!==void 0)return r;if(t&&!ve(t))return F;if(_e(e,t))return I.SINGLE_OR_SMALL;const i=t.per_page||Re;return Ee(i)}function Ae(e){if(!e)return null;const t=e["x-ratelimit"]||e["X-RateLimit"],s=e["x-ratelimit-policy"]||e["X-RateLimit-Policy"];if(!t&&!s)return null;const r={};if(t){const i=t.match(/r=(\d+)/);i&&(r.remaining=Number.parseInt(i[1],10))}if(s){const i=s.match(/q=(\d+)/);i&&(r.max=Number.parseInt(i[1],10))}return Object.keys(r).length>0?r:null}function ke(e,t=!1){return{userRateLimit:e,serverHeadersRateLimit:void 0,isManagementApi:t}}var Le=class extends Error{constructor(e){super(e),this.name="AbortError"}};function Se(e,t,s){if(!Number.isFinite(t))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(s))throw new TypeError("Expected `interval` to be a finite number");const r=[];let i=[],n=0,l=!1;const a=async()=>{n++;const c=r.shift();if(c)try{const p=await e(...c.args);c.resolve(p)}catch(p){c.reject(p)}const m=setTimeout(()=>{n--,r.length>0&&a(),i=i.filter(p=>p!==m)},s);i.includes(m)||i.push(m)},u=(...c)=>l?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((m,p)=>{r.push({resolve:m,reject:p,args:c}),n<t&&a()});return u.abort=()=>{l=!0,i.forEach(clearTimeout),i=[],r.forEach(c=>c.reject(()=>new Le("Throttle function aborted"))),r.length=0},u}var we=Se,Te=class{constructor(e,t=1e3){b(this,"queues");b(this,"interval");b(this,"throttledRequestFn");this.queues=new Map,this.interval=t,this.throttledRequestFn=e}getQueue(e){let t=this.queues.get(e);return t||(t=we(this.throttledRequestFn,e,this.interval),this.queues.set(e,t)),t}execute(e,...t){return this.getQueue(e)(...t)}abortAll(){this.queues.forEach(e=>{var t;(t=e.abort)==null||t.call(e)}),this.queues.clear()}getQueueCount(){return this.queues.size}};let H={};const T={};var Ce=class{constructor(e,t){b(this,"client");b(this,"maxRetries");b(this,"retriesDelay");b(this,"throttleManager");b(this,"accessToken");b(this,"cache");b(this,"resolveCounter");b(this,"relations");b(this,"links");b(this,"version");b(this,"rateLimitConfig");b(this,"richTextResolver");b(this,"resolveNestedRelations");b(this,"stringifiedStoriesCache");b(this,"inlineAssets");let s=e.endpoint||t;if(!s){const i=e.https===!1?"http":"https";e.oauthToken?s=`${i}://${X(e.region)}/v1`:s=`${i}://${X(e.region)}/v2`}const r=new Headers;r.set("Content-Type","application/json"),r.set("Accept","application/json"),e.headers&&(e.headers.constructor.name==="Headers"?e.headers.entries().toArray():Object.entries(e.headers)).forEach(([n,l])=>{r.set(n,l)}),r.has(Z)||(r.set(Z,G.defaultAgentName),r.set(G.defaultAgentVersion,G.packageVersion)),e.oauthToken&&r.set("Authorization",e.oauthToken),this.rateLimitConfig=ke(e.rateLimit,!!e.oauthToken),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttleManager=new Te(this.throttledRequest.bind(this),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||ee.PUBLISHED,this.inlineAssets=e.inlineAssets||!1,this.client=new pe({baseURL:s,timeout:e.timeout||0,headers:r,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=T[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 $(e)?this.parseParams(t):t}makeRequest(e,t,s,r,i){const n=this.factoryParamOptions(e,he(t,s,r));return this.cacheResponse(e,n,void 0,i)}get(e,t={},s){t||(t={});const r=`/${e}`;$(r)&&(t.version=t.version||this.version);const i=this.factoryParamOptions(r,t);return this.cacheResponse(r,i,void 0,s)}async getAll(e,t={},s,r){const i=(t==null?void 0:t.per_page)||25,n=`/${e}`.replace(/\/$/,""),l=s??n.substring(n.lastIndexOf("/")+1);t.version=t.version||this.version;const a=1,u=await this.makeRequest(n,t,i,a,r),c=u.total?Math.ceil(u.total/(u.perPage||i)):1,m=await ye(ge(a,c),p=>this.makeRequest(n,t,i,p+1,r));return be([u,...m],p=>Object.values(p.data[l]))}post(e,t={},s){const r=`/${e}`,i=M(void 0,void 0,this.rateLimitConfig,x);return this.throttleManager.execute(i,"post",r,t,s)}put(e,t={},s){const r=`/${e}`,i=M(void 0,void 0,this.rateLimitConfig,x);return this.throttleManager.execute(i,"put",r,t,s)}delete(e,t={},s){t||(t={});const r=`/${e}`,i=M(void 0,void 0,this.rateLimitConfig,x);return this.throttleManager.execute(i,"delete",r,t,s)}getStories(e={},t){return this._addResolveLevel(e),this.get("cdn/stories",e,t)}getStory(e,t={},s){return this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t,s)}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,s){const r=e[t];r&&r.fieldtype==="multilink"&&r.linktype==="story"&&typeof r.id=="string"&&this.links[s][r.id]?r.story=this._cleanCopy(this.links[s][r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[s][r.uuid]&&(r.story=this._cleanCopy(this.links[s][r.uuid]))}getStoryReference(e,t){return this.relations[e][t]?JSON.parse(this.stringifiedStoriesCache[t]||JSON.stringify(this.relations[e][t])):t}_resolveField(e,t,s){const r=e[t];typeof r=="string"?e[t]=this.getStoryReference(s,r):Array.isArray(r)&&(e[t]=r.map(i=>this.getStoryReference(s,i)).filter(Boolean))}_insertRelations(e,t,s,r){if(Array.isArray(s)?s.find(l=>l.endsWith(`.${t}`)):s.endsWith(`.${t}`)){this._resolveField(e,t,r);return}const n=e.component?`${e.component}.${t}`:t;(Array.isArray(s)?s.includes(n):s===n)&&this._resolveField(e,t,r)}iterateTree(e,t,s){const r=(i,n="")=>{if(!(!i||i._stopResolving)){if(Array.isArray(i))i.forEach((l,a)=>r(l,`${n}[${a}]`));else if(typeof i=="object")for(const l in i){const a=n?`${n}.${l}`:l;(i.component&&i._uid||i.type==="link")&&(this._insertRelations(i,l,t,s),this._insertLinks(i,l,s)),r(i[l],a)}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const i=e.link_uuids.length,n=[],l=50;for(let a=0;a<i;a+=l){const u=Math.min(i,a+l);n.push(e.link_uuids.slice(a,u))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.links;r.forEach(i=>{this.links[s][i.uuid]={...i,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const i=e.rel_uuids.length,n=[],l=50;for(let a=0;a<i;a+=l){const u=Math.min(i,a+l);n.push(e.rel_uuids.slice(a,u))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(c=>{r.push(c)});r.length>0&&(e.rels=r,delete e.rel_uuids)}else r=e.rels;r&&r.length>0&&r.forEach(i=>{this.relations[s][i.uuid]={...i,_stopResolving:!0}})}async resolveStories(e,t,s){var i,n;let r=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(r=t.resolve_relations.split(",")),await this.resolveRelations(e,t,s)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((i=e.links)!=null&&i.length||(n=e.link_uuids)!=null&&n.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const l in this.relations[s])this.iterateTree(this.relations[s][l],r,s);e.story?this.iterateTree(e.story,r,s):e.stories.forEach(l=>{this.iterateTree(l,r,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s,r){const i=j({url:e,params:t}),n=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const c=await n.get(i);if(c)return Promise.resolve(c)}const a=!$(e)&&this.rateLimitConfig.isManagementApi?x:void 0,u=M(e,t,this.rateLimitConfig,a);return new Promise(async(c,m)=>{var p;try{const v=await this.throttleManager.execute(u,"get",e,t,r);if(v.status!==200)return m(v);let L={data:v.data,headers:v.headers};const k=Ae(v.headers);if((k==null?void 0:k.max)!==void 0&&(this.rateLimitConfig.serverHeadersRateLimit=k.max),(p=v.headers)!=null&&p["per-page"]&&(L=Object.assign({},L,{perPage:v.headers["per-page"]?Number.parseInt(v.headers["per-page"]):0,total:v.headers["per-page"]?Number.parseInt(v.headers.total):0})),L.data.story||L.data.stories){const D=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(L.data,t,`${D}`),L=await this.processInlineAssets(L)}t.version==="published"&&e!=="/cdn/spaces/me"&&await n.set(i,L);const C=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&L.data.cv&&(C&&T[t.token]&&T[t.token]!==L.data.cv&&await this.flushCache(),T[t.token]=L.data.cv),c(L)}catch(v){if(v.response&&v.status===429&&(s=typeof s>"u"?0:s+1,s<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${this.retriesDelay/1e3} seconds.`),await de(this.retriesDelay),this.cacheResponse(e,t,s).then(c).catch(m);m(v)}})}throttledRequest(e,t,s,r){return this.client.setFetchOptions(r),this.client[e](t,s)}cacheVersions(){return T}cacheVersion(){return T[this.accessToken]}setCacheVersion(e){this.accessToken&&(T[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(T[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(H[e])},getAll(){return Promise.resolve(H)},set(e,t){return H[e]=t,Promise.resolve(void 0)},flush(){return H={},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=s=>{if(!s||typeof s!="object")return s;if(Array.isArray(s))return s.map(i=>t(i));let r={...s};r.fieldtype==="asset"&&Array.isArray(e.data.assets)&&(r={...e.data.assets.find(i=>i.id===r.id),...r});for(const i in r)typeof r[i]=="object"&&(r[i]=t(r[i]));return r};return e.data.story&&(e.data.story.content=t(e.data.story.content)),e.data.stories&&(e.data.stories=e.data.stories.map(s=>(s.content=t(s.content),s))),e}},te=Ce;const Oe=(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 te(t)}},Ie=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 B="https://app.storyblok.com/f/storyblok-v2-latest.js";const re=(e,t,s={})=>{var a;const i=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",n=new URL((a=window.location)==null?void 0:a.href).searchParams.get("_storyblok"),l=n!==null&&+n===e;if(!(!i||!l)){if(!e){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(s).on(["input","published","change"],c=>{var m;c&&(c.action==="input"&&((m=c.story)==null?void 0:m.id)===e?t(c.story):(c.action==="change"||c.action==="published")&&c.storyId===e&&window.location.reload())})})}},Pe=(e={})=>{var m,p;const{bridge:t,accessToken:s,use:r=[],apiOptions:i={},bridgeUrl:n}=e;i.accessToken=i.accessToken||s;const l={bridge:t,apiOptions:i};let a={};r.forEach(v=>{a={...a,...v(l)}}),n&&(B=n);const c=!(typeof window>"u")&&((p=(m=window.location)==null?void 0:m.search)==null?void 0:p.includes("_storyblok_tk"));return t!==!1&&c&&Q(B),a};function Ne(e,t){return J(t).render(e)}const xe=()=>Q(B);_.BlockTypes=g,_.MarkTypes=A,_.StoryblokClient=te,_.TextTypes=V,_.apiPlugin=Oe,_.loadStoryblokBridge=xe,_.registerStoryblokBridge=re,_.renderRichText=Ne,_.richTextResolver=J,_.storyblokEditable=Ie,_.storyblokInit=Pe,_.useStoryblokBridge=re,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
7
+ (function(_,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(_=typeof globalThis<"u"?globalThis:_||self,g(_.storyblok={}))})(this,function(_){"use strict";var Fe=Object.defineProperty;var Be=(_,g,k)=>g in _?Fe(_,g,{enumerable:!0,configurable:!0,writable:!0,value:k}):_[g]=k;var b=(_,g,k)=>Be(_,typeof g!="symbol"?g+"":g,k);let g=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}({}),k=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}({}),D=function(e){return e.TEXT="text",e}({}),N=function(e){return e.URL="url",e.STORY="story",e.ASSET="asset",e.EMAIL="email",e}({});const ne=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],oe=(e={})=>{const{custom:t,...s}=e,r={...s,...t};return Object.keys(r).map(i=>`${i}="${r[i]}"`).join(" ")},ae=(e={})=>Object.keys(e).map(t=>`${t}: ${e[t]}`).join("; ");function le(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}const O=e=>Object.fromEntries(Object.entries(e).filter(([t,s])=>s!==void 0));function ce(e,t){if(!t)return{src:e,attrs:{}};let s=0,r=0;const i={},n=[];function l(u,c,m,p,v){typeof u!="number"||u<=c||u>=m?console.warn(`[StoryblokRichText] - ${p.charAt(0).toUpperCase()+p.slice(1)} value must be a number between ${c} and ${m} (inclusive)`):v.push(`${p}(${u})`)}if(typeof t=="object"){if(t.width!==void 0&&(typeof t.width=="number"&&t.width>=0?(i.width=t.width,s=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?(i.height=t.height,r=t.height):console.warn("[StoryblokRichText] - Height value must be a number greater than or equal to 0")),t.height===0&&t.width===0&&(delete i.width,delete i.height,console.warn("[StoryblokRichText] - Width and height values cannot both be 0")),t.loading&&["lazy","eager"].includes(t.loading)&&(i.loading=t.loading),t.class&&(i.class=t.class),t.filters){const{filters:u}=t||{},{blur:c,brightness:m,fill:p,format:v,grayscale:L,quality:A,rotate:C}=u||{};c&&l(c,0,100,"blur",n),A&&l(A,0,100,"quality",n),m&&l(m,0,100,"brightness",n),p&&n.push(`fill(${p})`),L&&n.push("grayscale()"),C&&[0,90,180,270].includes(t.filters.rotate||0)&&n.push(`rotate(${C})`),v&&["webp","png","jpeg"].includes(v)&&n.push(`format(${v})`)}t.srcset&&(i.srcset=t.srcset.map(u=>{if(typeof u=="number")return`${e}/m/${u}x0/${n.length>0?`filters:${n.join(":")}`:""} ${u}w`;if(Array.isArray(u)&&u.length===2){const[c,m]=u;return`${e}/m/${c}x${m}/${n.length>0?`filters:${n.join(":")}`:""} ${c}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),t.sizes&&(i.sizes=t.sizes.join(", "))}let a=`${e}/m/`;return(s>0||r>0)&&(a=`${a}${s}x${r}/`),n.length>0&&(a=`${a}filters:${n.join(":")}`),{src:a,attrs:i}}function V(e,t={},s){const r=oe(t),i=r?`${e} ${r}`:e,n=Array.isArray(s)?s.join(""):s||"";if(e){if(ne.includes(e))return`<${i}>`}else return n;return`<${i}>${n}</${e}>`}function Y(e={}){const t=new Map,{renderFn:s=V,textFn:r=le,resolvers:i={},optimizeImages:n=!1,keyedResolvers:l=!1}=e,a=s!==V,u=(o={})=>{const{textAlign:h,class:d,id:f,style:y,...E}=o,R=[];return y&&R.push(y.endsWith(";")?y:`${y};`),h&&R.push(`text-align: ${h};`),O({...E,class:d,id:f,...R.length>0?{style:R.join(" ")}:{}})},c=o=>(h,d)=>{const f=u(h.attrs);return d.render(o,f,h.children||null)},m=(o,h)=>{const{src:d,alt:f,title:y,srcset:E,sizes:R}=o.attrs||{};let w=d,S={};if(n){const{src:Ge,attrs:qe}=ce(d,n);w=Ge,S=qe}const P={src:w,alt:f,title:y,srcset:E,sizes:R,...S};return h.render("img",O(P))},p=(o,h)=>{const{level:d,...f}=o.attrs||{},y=u(f);return h.render(`h${d}`,y,o.children)},v=(o,h)=>{var f,y,E,R;const d=h.render("img",{src:(f=o.attrs)==null?void 0:f.fallbackImage,alt:(y=o.attrs)==null?void 0:y.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":(E=o.attrs)==null?void 0:E.name,"data-emoji":(R=o.attrs)==null?void 0:R.emoji},d)},L=(o,h)=>h.render("pre",o.attrs||{},h.render("code",{},o.children||"")),A=(o,h=!1)=>({text:d,attrs:f},y)=>{const{class:E,id:R,...w}=f||{},S=h?{class:E,id:R,style:ae(w)||void 0}:f||{};return y.render(o,O(S),d)},C=o=>z(o),B=o=>{const{marks:h,...d}=o;if("text"in o){if(h)return h.reduce((y,E)=>C({...E,text:y}),C({...d,children:d.children}));const f=o.attrs||{};if(l){const y=t.get("txt")||0;t.set("txt",y+1),f.key=`txt-${y}`}return r(d.text,f)}return""},re=(o,h)=>{const{linktype:d,href:f,anchor:y,...E}=o.attrs||{};let R="";switch(d){case N.ASSET:case N.URL:R=f;break;case N.EMAIL:R=`mailto:${f}`;break;case N.STORY:R=f,y&&(R=`${R}#${y}`);break;default:R=f;break}const w={...E};return R&&(w.href=R),h.render("a",w,o.text)},xe=(o,h)=>{var d,f;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),h.render("span",{blok:(d=o==null?void 0:o.attrs)==null?void 0:d.body[0],id:(f=o.attrs)==null?void 0:f.id,style:"display: none"})},Me=(o,h)=>{const d=u(o.attrs),f=o.children||null;return h.render("table",d,h.render("tbody",{},f))},$e=(o,h)=>{const d=u(o.attrs);return h.render("tr",d,o.children)},He=(o,h)=>{const{colspan:d,rowspan:f,colwidth:y,backgroundColor:E,textAlign:R,...w}=o.attrs||{},S=[];y&&S.push(`width: ${y}px;`),E&&S.push(`background-color: ${E};`),R&&S.push(`text-align: ${R};`);const P={...w,...d>1?{colspan:d}:{},...f>1?{rowspan:f}:{},...S.length>0?{style:S.join(" ")}:{}};return h.render("td",O(P),o.children)},Ue=(o,h)=>{const{colspan:d,rowspan:f,colwidth:y,backgroundColor:E,textAlign:R,...w}=o.attrs||{},S=[];y&&S.push(`width: ${y}px;`),E&&S.push(`background-color: ${E};`),R&&S.push(`text-align: ${R};`);const P={...w,...d>1?{colspan:d}:{},...f>1?{rowspan:f}:{},...S.length>0?{style:S.join(" ")}:{}};return h.render("th",O(P),o.children)},se=new Map([[g.DOCUMENT,c("")],[g.HEADING,p],[g.PARAGRAPH,c("p")],[g.UL_LIST,c("ul")],[g.OL_LIST,c("ol")],[g.LIST_ITEM,c("li")],[g.IMAGE,m],[g.EMOJI,v],[g.CODE_BLOCK,L],[g.HR,c("hr")],[g.BR,c("br")],[g.QUOTE,c("blockquote")],[g.COMPONENT,xe],[D.TEXT,B],[k.LINK,re],[k.ANCHOR,re],[k.STYLED,A("span",!0)],[k.BOLD,A("strong")],[k.TEXT_STYLE,A("span",!0)],[k.ITALIC,A("em")],[k.UNDERLINE,A("u")],[k.STRIKE,A("s")],[k.CODE,A("code")],[k.SUPERSCRIPT,A("sup")],[k.SUBSCRIPT,A("sub")],[k.HIGHLIGHT,A("mark")],[g.TABLE,Me],[g.TABLE_ROW,$e],[g.TABLE_CELL,He],[g.TABLE_HEADER,Ue]]),ie=new Map([...se,...Object.entries(i).map(([o,h])=>[o,h])]),je=()=>({render:(d,f={},y)=>{if(l&&d){const E=t.get(d)||0;t.set(d,E+1),f.key=`${d}-${E}`}return s(d,f,y)},originalResolvers:se,mergedResolvers:ie});function H(o){const h=ie.get(o.type);if(!h)return console.error("<Storyblok>",`No resolver found for node type ${o.type}`),"";const d=je();if(o.type==="text")return h(o,d);const f=o.content?o.content.map(z):void 0;return h({...o,children:f},d)}function z(o){return o.type==="doc"?a?o.content.map(H):o.content.map(H).join(""):Array.isArray(o)?o.map(H):H(o)}return{render:z}}let J=!1;const K=[],W=e=>new Promise((t,s)=>{if(typeof window>"u"){s(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));return}if(window.storyblokRegisterEvent=i=>{if(!window.location.search.includes("_storyblok")){console.warn("You are not in Draft Mode or in the Visual Editor.");return}J?i():K.push(i)},document.getElementById("storyblok-javascript-bridge")){t(void 0);return}const r=document.createElement("script");r.async=!0,r.src=e,r.id="storyblok-javascript-bridge",r.onerror=i=>s(i),r.onload=i=>{K.forEach(n=>n()),J=!0,t(i)},document.getElementsByTagName("head")[0].appendChild(r)}),U=(e="")=>e.includes("/cdn/"),ue=(e,t=25,s=1)=>({...e,per_page:t,page:s}),he=e=>new Promise(t=>setTimeout(t,e)),de=(e=0,t)=>Array.from({length:e},t),fe=(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return de(s,(i,n)=>n*r+e)},ge=async(e,t)=>Promise.all(e.map(t)),ye=(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[]),j=(e,t,s)=>{const r=[];for(const i in e){if(!Object.prototype.hasOwnProperty.call(e,i))continue;const n=e[i];if(n==null)continue;const l=s?"":encodeURIComponent(i);let a;typeof n=="object"?a=j(n,t?t+encodeURIComponent(`[${l}]`):l,Array.isArray(n)):a=`${t?t+encodeURIComponent(`[${l}]`):l}=${encodeURIComponent(n)}`,r.push(a)}return r.join("&")},Q=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 be=class{constructor(e){b(this,"baseURL");b(this,"timeout");b(this,"headers");b(this,"responseInterceptor");b(this,"fetch");b(this,"ejectInterceptor");b(this,"url");b(this,"parameters");b(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=[],s={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(r=>{s.data=r});for(const r of e.headers.entries())t[r[0]]=r[1];return s.headers={...t},s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,s=null;e==="get"?t=`${this.baseURL}${this.url}?${j(this.parameters)}`:s=JSON.stringify(this.parameters);const r=new URL(t),i=new AbortController,{signal:n}=i;let l=null;this.timeout&&(l=setTimeout(()=>i.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:n,...this.fetchOptions});this.timeout&&l&&clearTimeout(l);const u=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(u)):this._statusHandler(u)}catch(a){return a.name==="AbortError"?{message:"Request timeout: The request was aborted due to timeout"}:{message:a.message||a.toString()||"An unknown error occurred"}}}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((s,r)=>{if(t.test(`${e.status}`))return s(e);const i={message:this._normalizeErrorMessage(e.data),status:e.status,response:e};r(i)})}},me=be;const X="SB-Agent",G={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"7.0.0"},pe={PUBLISHED:"published"},Re=25,q={SMALL:25,MEDIUM:50,LARGE:75},I={SINGLE_OR_SMALL:50,MEDIUM:15,LARGE:10,VERY_LARGE:6},Z=1e3,x=3;function ve(e,t){const s=e.includes("/cdn/stories/"),r=e.split("/").length>3&&!e.endsWith("/cdn/stories"),i="find_by"in t;return s&&r||i}function _e(e){return e<=q.SMALL?I.SINGLE_OR_SMALL:e<=q.MEDIUM?I.MEDIUM:e<=q.LARGE?I.LARGE:I.VERY_LARGE}function M(e,t,s={},r){if(s.userRateLimit!==void 0)return Math.min(s.userRateLimit,Z);if(s.serverHeadersRateLimit!==void 0)return Math.min(s.serverHeadersRateLimit,Z);if(r!==void 0)return r;if(!e||!t||ve(e,t))return I.SINGLE_OR_SMALL;const i=t.per_page||Re;return _e(i)}function Ee(e){if(!e)return null;const t=e["x-ratelimit"]||e["X-RateLimit"],s=e["x-ratelimit-policy"]||e["X-RateLimit-Policy"];if(!t&&!s)return null;const r={};if(t){const i=t.match(/r=(\d+)/);i&&(r.remaining=Number.parseInt(i[1],10))}if(s){const i=s.match(/q=(\d+)/);i&&(r.max=Number.parseInt(i[1],10))}return Object.keys(r).length>0?r:null}function ke(e,t=!1){return{userRateLimit:e,serverHeadersRateLimit:void 0,isManagementApi:t}}var Ae=class extends Error{constructor(e){super(e),this.name="AbortError"}};function Le(e,t,s){if(!Number.isFinite(t))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(s))throw new TypeError("Expected `interval` to be a finite number");const r=[];let i=[],n=0,l=!1;const a=async()=>{n++;const c=r.shift();if(c)try{const p=await e(...c.args);c.resolve(p)}catch(p){c.reject(p)}const m=setTimeout(()=>{n--,r.length>0&&a(),i=i.filter(p=>p!==m)},s);i.includes(m)||i.push(m)},u=(...c)=>l?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((m,p)=>{r.push({resolve:m,reject:p,args:c}),n<t&&a()});return u.abort=()=>{l=!0,i.forEach(clearTimeout),i=[],r.forEach(c=>c.reject(()=>new Ae("Throttle function aborted"))),r.length=0},u}var Se=Le,we=class{constructor(e,t=1e3){b(this,"queues");b(this,"interval");b(this,"throttledRequestFn");this.queues=new Map,this.interval=t,this.throttledRequestFn=e}getQueue(e){let t=this.queues.get(e);return t||(t=Se(this.throttledRequestFn,e,this.interval),this.queues.set(e,t)),t}execute(e,...t){return this.getQueue(e)(...t)}abortAll(){this.queues.forEach(e=>{var t;(t=e.abort)==null||t.call(e)}),this.queues.clear()}getQueueCount(){return this.queues.size}};let $={};const T={};var Te=class{constructor(e,t){b(this,"client");b(this,"maxRetries");b(this,"retriesDelay");b(this,"throttleManager");b(this,"accessToken");b(this,"cache");b(this,"resolveCounter");b(this,"relations");b(this,"links");b(this,"version");b(this,"rateLimitConfig");b(this,"richTextResolver");b(this,"resolveNestedRelations");b(this,"stringifiedStoriesCache");b(this,"inlineAssets");let s=e.endpoint||t;if(!s){const i=e.https===!1?"http":"https";e.oauthToken?s=`${i}://${Q(e.region)}/v1`:s=`${i}://${Q(e.region)}/v2`}const r=new Headers;r.set("Content-Type","application/json"),r.set("Accept","application/json"),e.headers&&(e.headers.constructor.name==="Headers"?e.headers.entries().toArray():Object.entries(e.headers)).forEach(([n,l])=>{r.set(n,l)}),r.has(X)||(r.set(X,G.defaultAgentName),r.set(G.defaultAgentVersion,G.packageVersion)),e.oauthToken&&r.set("Authorization",e.oauthToken),this.rateLimitConfig=ke(e.rateLimit,!!e.oauthToken),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttleManager=new we(this.throttledRequest.bind(this),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||pe.PUBLISHED,this.inlineAssets=e.inlineAssets||!1,this.client=new me({baseURL:s,timeout:e.timeout||0,headers:r,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=T[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 U(e)?this.parseParams(t):t}makeRequest(e,t,s,r,i){const n=this.factoryParamOptions(e,ue(t,s,r));return this.cacheResponse(e,n,void 0,i)}get(e,t={},s){t||(t={});const r=`/${e}`;U(r)&&(t.version=t.version||this.version);const i=this.factoryParamOptions(r,t);return this.cacheResponse(r,i,void 0,s)}async getAll(e,t={},s,r){const i=(t==null?void 0:t.per_page)||25,n=`/${e}`.replace(/\/$/,""),l=s??n.substring(n.lastIndexOf("/")+1);t.version=t.version||this.version;const a=1,u=await this.makeRequest(n,t,i,a,r),c=u.total?Math.ceil(u.total/(u.perPage||i)):1,m=await ge(fe(a,c),p=>this.makeRequest(n,t,i,p+1,r));return ye([u,...m],p=>Object.values(p.data[l]))}post(e,t={},s){const r=`/${e}`,i=M(void 0,void 0,this.rateLimitConfig,x);return this.throttleManager.execute(i,"post",r,t,s)}put(e,t={},s){const r=`/${e}`,i=M(void 0,void 0,this.rateLimitConfig,x);return this.throttleManager.execute(i,"put",r,t,s)}delete(e,t={},s){t||(t={});const r=`/${e}`,i=M(void 0,void 0,this.rateLimitConfig,x);return this.throttleManager.execute(i,"delete",r,t,s)}getStories(e={},t){return this._addResolveLevel(e),this.get("cdn/stories",e,t)}getStory(e,t={},s){return this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t,s)}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,s){const r=e[t];r&&r.fieldtype==="multilink"&&r.linktype==="story"&&typeof r.id=="string"&&this.links[s][r.id]?r.story=this._cleanCopy(this.links[s][r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[s][r.uuid]&&(r.story=this._cleanCopy(this.links[s][r.uuid]))}getStoryReference(e,t){return this.relations[e][t]?JSON.parse(this.stringifiedStoriesCache[t]||JSON.stringify(this.relations[e][t])):t}_resolveField(e,t,s){const r=e[t];typeof r=="string"?e[t]=this.getStoryReference(s,r):Array.isArray(r)&&(e[t]=r.map(i=>this.getStoryReference(s,i)).filter(Boolean))}_insertRelations(e,t,s,r){if(Array.isArray(s)?s.find(l=>l.endsWith(`.${t}`)):s.endsWith(`.${t}`)){this._resolveField(e,t,r);return}const n=e.component?`${e.component}.${t}`:t;(Array.isArray(s)?s.includes(n):s===n)&&this._resolveField(e,t,r)}iterateTree(e,t,s){const r=(i,n="")=>{if(!(!i||i._stopResolving)){if(Array.isArray(i))i.forEach((l,a)=>r(l,`${n}[${a}]`));else if(typeof i=="object")for(const l in i){const a=n?`${n}.${l}`:l;(i.component&&i._uid||i.type==="link")&&(this._insertRelations(i,l,t,s),this._insertLinks(i,l,s)),r(i[l],a)}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const i=e.link_uuids.length,n=[],l=50;for(let a=0;a<i;a+=l){const u=Math.min(i,a+l);n.push(e.link_uuids.slice(a,u))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.links;r.forEach(i=>{this.links[s][i.uuid]={...i,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const i=e.rel_uuids.length,n=[],l=50;for(let a=0;a<i;a+=l){const u=Math.min(i,a+l);n.push(e.rel_uuids.slice(a,u))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(c=>{r.push(c)});r.length>0&&(e.rels=r,delete e.rel_uuids)}else r=e.rels;r&&r.length>0&&r.forEach(i=>{this.relations[s][i.uuid]={...i,_stopResolving:!0}})}async resolveStories(e,t,s){var i,n;let r=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(r=t.resolve_relations.split(",")),await this.resolveRelations(e,t,s)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((i=e.links)!=null&&i.length||(n=e.link_uuids)!=null&&n.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const l in this.relations[s])this.iterateTree(this.relations[s][l],r,s);e.story?this.iterateTree(e.story,r,s):e.stories.forEach(l=>{this.iterateTree(l,r,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s,r){const i=j({url:e,params:t}),n=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const c=await n.get(i);if(c)return Promise.resolve(c)}const a=!U(e)&&this.rateLimitConfig.isManagementApi?x:void 0,u=M(e,t,this.rateLimitConfig,a);return new Promise(async(c,m)=>{var p;try{const v=await this.throttleManager.execute(u,"get",e,t,r);if(v.status!==200)return m(v);let L={data:v.data,headers:v.headers};const A=Ee(v.headers);if((A==null?void 0:A.max)!==void 0&&(this.rateLimitConfig.serverHeadersRateLimit=A.max),(p=v.headers)!=null&&p["per-page"]&&(L=Object.assign({},L,{perPage:v.headers["per-page"]?Number.parseInt(v.headers["per-page"]):0,total:v.headers["per-page"]?Number.parseInt(v.headers.total):0})),L.data.story||L.data.stories){const B=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(L.data,t,`${B}`),L=await this.processInlineAssets(L)}t.version==="published"&&e!=="/cdn/spaces/me"&&await n.set(i,L);const C=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&L.data.cv&&(C&&T[t.token]&&T[t.token]!==L.data.cv&&await this.flushCache(),T[t.token]=L.data.cv),c(L)}catch(v){if(v.response&&v.status===429&&(s=typeof s>"u"?0:s+1,s<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${this.retriesDelay/1e3} seconds.`),await he(this.retriesDelay),this.cacheResponse(e,t,s).then(c).catch(m);m(v)}})}throttledRequest(e,t,s,r){return this.client.setFetchOptions(r),this.client[e](t,s)}cacheVersions(){return T}cacheVersion(){return T[this.accessToken]}setCacheVersion(e){this.accessToken&&(T[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(T[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve($[e])},getAll(){return Promise.resolve($)},set(e,t){return $[e]=t,Promise.resolve(void 0)},flush(){return $={},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=s=>{if(!s||typeof s!="object")return s;if(Array.isArray(s))return s.map(i=>t(i));let r={...s};r.fieldtype==="asset"&&Array.isArray(e.data.assets)&&(r={...e.data.assets.find(i=>i.id===r.id),...r});for(const i in r)typeof r[i]=="object"&&(r[i]=t(r[i]));return r};return e.data.story&&(e.data.story.content=t(e.data.story.content)),e.data.stories&&(e.data.stories=e.data.stories.map(s=>(s.content=t(s.content),s))),e}},ee=Te;const Ce=(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 ee(t)}},Ie=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 F="https://app.storyblok.com/f/storyblok-v2-latest.js";const te=(e,t,s={})=>{var a;const i=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",n=new URL((a=window.location)==null?void 0:a.href).searchParams.get("_storyblok"),l=n!==null&&+n===e;if(!(!i||!l)){if(!e){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(s).on(["input","published","change"],c=>{var m;c&&(c.action==="input"&&((m=c.story)==null?void 0:m.id)===e?t(c.story):(c.action==="change"||c.action==="published")&&c.storyId===e&&window.location.reload())})})}},Oe=(e={})=>{var m,p;const{bridge:t,accessToken:s,use:r=[],apiOptions:i={},bridgeUrl:n}=e;i.accessToken=i.accessToken||s;const l={bridge:t,apiOptions:i};let a={};r.forEach(v=>{a={...a,...v(l)}}),n&&(F=n);const c=!(typeof window>"u")&&((p=(m=window.location)==null?void 0:m.search)==null?void 0:p.includes("_storyblok_tk"));return t!==!1&&c&&W(F),a};function Pe(e,t){return Y(t).render(e)}const Ne=()=>W(F);_.BlockTypes=g,_.MarkTypes=k,_.StoryblokClient=ee,_.TextTypes=D,_.apiPlugin=Ce,_.loadStoryblokBridge=Ne,_.registerStoryblokBridge=te,_.renderRichText=Pe,_.richTextResolver=Y,_.storyblokEditable=Ie,_.storyblokInit=Oe,_.useStoryblokBridge=te,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
@@ -1,22 +1,22 @@
1
1
  /**
2
2
  * name: @storyblok/js
3
- * (c) 2025
3
+ * (c) 2026
4
4
  * description: SDK to integrate Storyblok into your project using JavaScript.
5
5
  * author: undefined
6
6
  */
7
- var ce = Object.defineProperty;
8
- var ue = (e, t, r) => t in e ? ce(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
9
- var y = (e, t, r) => ue(e, typeof t != "symbol" ? t + "" : t, r);
7
+ var le = Object.defineProperty;
8
+ var ce = (e, t, r) => t in e ? le(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
9
+ var y = (e, t, r) => ce(e, typeof t != "symbol" ? t + "" : t, r);
10
10
  let E = /* @__PURE__ */ function(e) {
11
11
  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;
12
12
  }({}), w = /* @__PURE__ */ function(e) {
13
13
  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;
14
- }({}), he = /* @__PURE__ */ function(e) {
14
+ }({}), ue = /* @__PURE__ */ function(e) {
15
15
  return e.TEXT = "text", e;
16
16
  }({}), x = /* @__PURE__ */ function(e) {
17
17
  return e.URL = "url", e.STORY = "story", e.ASSET = "asset", e.EMAIL = "email", e;
18
18
  }({});
19
- const de = [
19
+ const he = [
20
20
  "area",
21
21
  "base",
22
22
  "br",
@@ -31,18 +31,18 @@ const de = [
31
31
  "source",
32
32
  "track",
33
33
  "wbr"
34
- ], fe = (e = {}) => {
34
+ ], de = (e = {}) => {
35
35
  const { custom: t, ...r } = e, s = {
36
36
  ...r,
37
37
  ...t
38
38
  };
39
39
  return Object.keys(s).map((i) => `${i}="${s[i]}"`).join(" ");
40
- }, ge = (e = {}) => Object.keys(e).map((t) => `${t}: ${e[t]}`).join("; ");
41
- function ye(e) {
40
+ }, fe = (e = {}) => Object.keys(e).map((t) => `${t}: ${e[t]}`).join("; ");
41
+ function ge(e) {
42
42
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
43
43
  }
44
44
  const O = (e) => Object.fromEntries(Object.entries(e).filter(([t, r]) => r !== void 0));
45
- function be(e, t) {
45
+ function ye(e, t) {
46
46
  if (!t) return {
47
47
  src: e,
48
48
  attrs: {}
@@ -83,15 +83,15 @@ function be(e, t) {
83
83
  attrs: i
84
84
  };
85
85
  }
86
- function J(e, t = {}, r) {
87
- const s = fe(t), i = s ? `${e} ${s}` : e, n = Array.isArray(r) ? r.join("") : r || "";
86
+ function Y(e, t = {}, r) {
87
+ const s = de(t), i = s ? `${e} ${s}` : e, n = Array.isArray(r) ? r.join("") : r || "";
88
88
  if (e) {
89
- if (de.includes(e)) return `<${i}>`;
89
+ if (he.includes(e)) return `<${i}>`;
90
90
  } else return n;
91
91
  return `<${i}>${n}</${e}>`;
92
92
  }
93
- function me(e = {}) {
94
- const t = /* @__PURE__ */ new Map(), { renderFn: r = J, textFn: s = ye, resolvers: i = {}, optimizeImages: n = !1, keyedResolvers: l = !1 } = e, a = r !== J, u = (o = {}) => {
93
+ function be(e = {}) {
94
+ const t = /* @__PURE__ */ new Map(), { renderFn: r = Y, textFn: s = ge, resolvers: i = {}, optimizeImages: n = !1, keyedResolvers: l = !1 } = e, a = r !== Y, u = (o = {}) => {
95
95
  const { textAlign: h, class: d, id: f, style: g, ...v } = o, p = [];
96
96
  return g && p.push(g.endsWith(";") ? g : `${g};`), h && p.push(`text-align: ${h};`), O({
97
97
  ...v,
@@ -106,10 +106,10 @@ function me(e = {}) {
106
106
  const { src: d, alt: f, title: g, srcset: v, sizes: p } = o.attrs || {};
107
107
  let k = d, L = {};
108
108
  if (n) {
109
- const { src: ae, attrs: le } = be(d, n);
110
- k = ae, L = le;
109
+ const { src: oe, attrs: ae } = ye(d, n);
110
+ k = oe, L = ae;
111
111
  }
112
- const C = {
112
+ const I = {
113
113
  src: k,
114
114
  alt: f,
115
115
  title: g,
@@ -117,7 +117,7 @@ function me(e = {}) {
117
117
  sizes: p,
118
118
  ...L
119
119
  };
120
- return h.render("img", O(C));
120
+ return h.render("img", O(I));
121
121
  }, m = (o, h) => {
122
122
  const { level: d, ...f } = o.attrs || {}, g = u(f);
123
123
  return h.render(`h${d}`, g, o.children);
@@ -139,10 +139,10 @@ function me(e = {}) {
139
139
  const { class: v, id: p, ...k } = f || {}, L = h ? {
140
140
  class: v,
141
141
  id: p,
142
- style: ge(k) || void 0
142
+ style: fe(k) || void 0
143
143
  } : f || {};
144
144
  return g.render(o, O(L), d);
145
- }, T = (o) => $(o), U = (o) => {
145
+ }, T = (o) => U(o), H = (o) => {
146
146
  const { marks: h, ...d } = o;
147
147
  if ("text" in o) {
148
148
  if (h) return h.reduce((g, v) => T({
@@ -180,40 +180,40 @@ function me(e = {}) {
180
180
  }
181
181
  const k = { ...v };
182
182
  return p && (k.href = p), h.render("a", k, o.text);
183
- }, te = (o, h) => {
183
+ }, ee = (o, h) => {
184
184
  var d, f;
185
185
  return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), h.render("span", {
186
186
  blok: (d = o == null ? void 0 : o.attrs) == null ? void 0 : d.body[0],
187
187
  id: (f = o.attrs) == null ? void 0 : f.id,
188
188
  style: "display: none"
189
189
  });
190
- }, re = (o, h) => {
190
+ }, te = (o, h) => {
191
191
  const d = u(o.attrs), f = o.children || null;
192
192
  return h.render("table", d, h.render("tbody", {}, f));
193
- }, se = (o, h) => {
193
+ }, re = (o, h) => {
194
194
  const d = u(o.attrs);
195
195
  return h.render("tr", d, o.children);
196
- }, ie = (o, h) => {
196
+ }, se = (o, h) => {
197
197
  const { colspan: d, rowspan: f, colwidth: g, backgroundColor: v, textAlign: p, ...k } = o.attrs || {}, L = [];
198
198
  g && L.push(`width: ${g}px;`), v && L.push(`background-color: ${v};`), p && L.push(`text-align: ${p};`);
199
- const C = {
199
+ const I = {
200
200
  ...k,
201
201
  ...d > 1 ? { colspan: d } : {},
202
202
  ...f > 1 ? { rowspan: f } : {},
203
203
  ...L.length > 0 ? { style: L.join(" ") } : {}
204
204
  };
205
- return h.render("td", O(C), o.children);
206
- }, ne = (o, h) => {
205
+ return h.render("td", O(I), o.children);
206
+ }, ie = (o, h) => {
207
207
  const { colspan: d, rowspan: f, colwidth: g, backgroundColor: v, textAlign: p, ...k } = o.attrs || {}, L = [];
208
208
  g && L.push(`width: ${g}px;`), v && L.push(`background-color: ${v};`), p && L.push(`text-align: ${p};`);
209
- const C = {
209
+ const I = {
210
210
  ...k,
211
211
  ...d > 1 ? { colspan: d } : {},
212
212
  ...f > 1 ? { rowspan: f } : {},
213
213
  ...L.length > 0 ? { style: L.join(" ") } : {}
214
214
  };
215
- return h.render("th", O(C), o.children);
216
- }, V = /* @__PURE__ */ new Map([
215
+ return h.render("th", O(I), o.children);
216
+ }, D = /* @__PURE__ */ new Map([
217
217
  [E.DOCUMENT, c("")],
218
218
  [E.HEADING, m],
219
219
  [E.PARAGRAPH, c("p")],
@@ -226,8 +226,8 @@ function me(e = {}) {
226
226
  [E.HR, c("hr")],
227
227
  [E.BR, c("br")],
228
228
  [E.QUOTE, c("blockquote")],
229
- [E.COMPONENT, te],
230
- [he.TEXT, U],
229
+ [E.COMPONENT, ee],
230
+ [ue.TEXT, H],
231
231
  [w.LINK, z],
232
232
  [w.ANCHOR, z],
233
233
  [w.STYLED, _("span", !0)],
@@ -240,11 +240,11 @@ function me(e = {}) {
240
240
  [w.SUPERSCRIPT, _("sup")],
241
241
  [w.SUBSCRIPT, _("sub")],
242
242
  [w.HIGHLIGHT, _("mark")],
243
- [E.TABLE, re],
244
- [E.TABLE_ROW, se],
245
- [E.TABLE_CELL, ie],
246
- [E.TABLE_HEADER, ne]
247
- ]), Y = new Map([...V, ...Object.entries(i).map(([o, h]) => [o, h])]), oe = () => ({
243
+ [E.TABLE, te],
244
+ [E.TABLE_ROW, re],
245
+ [E.TABLE_CELL, se],
246
+ [E.TABLE_HEADER, ie]
247
+ ]), V = new Map([...D, ...Object.entries(i).map(([o, h]) => [o, h])]), ne = () => ({
248
248
  render: (d, f = {}, g) => {
249
249
  if (l && d) {
250
250
  const v = t.get(d) || 0;
@@ -252,28 +252,28 @@ function me(e = {}) {
252
252
  }
253
253
  return r(d, f, g);
254
254
  },
255
- originalResolvers: V,
256
- mergedResolvers: Y
255
+ originalResolvers: D,
256
+ mergedResolvers: V
257
257
  });
258
258
  function P(o) {
259
- const h = Y.get(o.type);
259
+ const h = V.get(o.type);
260
260
  if (!h)
261
261
  return console.error("<Storyblok>", `No resolver found for node type ${o.type}`), "";
262
- const d = oe();
262
+ const d = ne();
263
263
  if (o.type === "text") return h(o, d);
264
- const f = o.content ? o.content.map($) : void 0;
264
+ const f = o.content ? o.content.map(U) : void 0;
265
265
  return h({
266
266
  ...o,
267
267
  children: f
268
268
  }, d);
269
269
  }
270
- function $(o) {
270
+ function U(o) {
271
271
  return o.type === "doc" ? a ? o.content.map(P) : o.content.map(P).join("") : Array.isArray(o) ? o.map(P) : P(o);
272
272
  }
273
- return { render: $ };
273
+ return { render: U };
274
274
  }
275
- let K = !1;
276
- const W = [], Z = (e) => new Promise((t, r) => {
275
+ let J = !1;
276
+ const K = [], Z = (e) => new Promise((t, r) => {
277
277
  if (typeof window > "u") {
278
278
  r(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));
279
279
  return;
@@ -283,23 +283,23 @@ const W = [], Z = (e) => new Promise((t, r) => {
283
283
  console.warn("You are not in Draft Mode or in the Visual Editor.");
284
284
  return;
285
285
  }
286
- K ? i() : W.push(i);
286
+ J ? i() : K.push(i);
287
287
  }, document.getElementById("storyblok-javascript-bridge")) {
288
288
  t(void 0);
289
289
  return;
290
290
  }
291
291
  const s = document.createElement("script");
292
292
  s.async = !0, s.src = e, s.id = "storyblok-javascript-bridge", s.onerror = (i) => r(i), s.onload = (i) => {
293
- W.forEach((n) => n()), K = !0, t(i);
293
+ K.forEach((n) => n()), J = !0, t(i);
294
294
  }, document.getElementsByTagName("head")[0].appendChild(s);
295
- }), j = (e = "") => e.includes("/cdn/"), pe = (e, t = 25, r = 1) => ({
295
+ }), j = (e = "") => e.includes("/cdn/"), me = (e, t = 25, r = 1) => ({
296
296
  ...e,
297
297
  per_page: t,
298
298
  page: r
299
- }), Re = (e) => new Promise((t) => setTimeout(t, e)), ve = (e = 0, t) => Array.from({ length: e }, t), _e = (e = 0, t = e) => {
299
+ }), pe = (e) => new Promise((t) => setTimeout(t, e)), Re = (e = 0, t) => Array.from({ length: e }, t), ve = (e = 0, t = e) => {
300
300
  const r = Math.abs(t - e) || 0, s = e < t ? 1 : -1;
301
- return ve(r, (i, n) => n * s + e);
302
- }, Ee = async (e, t) => Promise.all(e.map(t)), Ae = (e = [], t) => e.map(t).reduce((r, s) => [...r, ...s], []), B = (e, t, r) => {
301
+ return Re(r, (i, n) => n * s + e);
302
+ }, _e = async (e, t) => Promise.all(e.map(t)), Ee = (e = [], t) => e.map(t).reduce((r, s) => [...r, ...s], []), B = (e, t, r) => {
303
303
  const s = [];
304
304
  for (const i in e) {
305
305
  if (!Object.prototype.hasOwnProperty.call(e, i)) continue;
@@ -310,7 +310,7 @@ const W = [], Z = (e) => new Promise((t, r) => {
310
310
  typeof n == "object" ? a = B(n, t ? t + encodeURIComponent(`[${l}]`) : l, Array.isArray(n)) : a = `${t ? t + encodeURIComponent(`[${l}]`) : l}=${encodeURIComponent(n)}`, s.push(a);
311
311
  }
312
312
  return s.join("&");
313
- }, Q = (e) => {
313
+ }, W = (e) => {
314
314
  const t = {
315
315
  eu: "api.storyblok.com",
316
316
  us: "api-us.storyblok.com",
@@ -320,7 +320,7 @@ const W = [], Z = (e) => new Promise((t, r) => {
320
320
  };
321
321
  return t[e] ?? t.eu;
322
322
  };
323
- var Le = class {
323
+ var Ae = class {
324
324
  constructor(e) {
325
325
  y(this, "baseURL");
326
326
  y(this, "timeout");
@@ -382,7 +382,7 @@ var Le = class {
382
382
  const u = await this._responseHandler(a);
383
383
  return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(u)) : this._statusHandler(u);
384
384
  } catch (a) {
385
- return { message: a };
385
+ return a.name === "AbortError" ? { message: "Request timeout: The request was aborted due to timeout" } : { message: a.message || a.toString() || "An unknown error occurred" };
386
386
  }
387
387
  }
388
388
  setFetchOptions(e = {}) {
@@ -420,44 +420,39 @@ var Le = class {
420
420
  s(i);
421
421
  });
422
422
  }
423
- }, we = Le;
424
- const X = "SB-Agent", G = {
423
+ }, Le = Ae;
424
+ const Q = "SB-Agent", G = {
425
425
  defaultAgentName: "SB-JS-CLIENT",
426
426
  defaultAgentVersion: "SB-Agent-Version",
427
427
  packageVersion: "7.0.0"
428
- }, ee = {
429
- DRAFT: "draft",
428
+ }, we = {
430
429
  PUBLISHED: "published"
431
430
  }, ke = 25, q = {
432
431
  SMALL: 25,
433
432
  MEDIUM: 50,
434
433
  LARGE: 75
435
- }, I = {
434
+ }, C = {
436
435
  SINGLE_OR_SMALL: 50,
437
436
  MEDIUM: 15,
438
437
  LARGE: 10,
439
438
  VERY_LARGE: 6
440
- }, F = 1e3, N = 3;
441
- function Se(e) {
442
- return e.version === ee.DRAFT;
443
- }
444
- function Te(e, t) {
439
+ }, X = 1e3, N = 3;
440
+ function Se(e, t) {
445
441
  const r = e.includes("/cdn/stories/"), s = e.split("/").length > 3 && !e.endsWith("/cdn/stories"), i = "find_by" in t;
446
442
  return r && s || i;
447
443
  }
448
- function Ce(e) {
449
- return e <= q.SMALL ? I.SINGLE_OR_SMALL : e <= q.MEDIUM ? I.MEDIUM : e <= q.LARGE ? I.LARGE : I.VERY_LARGE;
444
+ function Te(e) {
445
+ return e <= q.SMALL ? C.SINGLE_OR_SMALL : e <= q.MEDIUM ? C.MEDIUM : e <= q.LARGE ? C.LARGE : C.VERY_LARGE;
450
446
  }
451
- function H(e, t, r = {}, s) {
452
- if (r.userRateLimit !== void 0) return Math.min(r.userRateLimit, F);
453
- if (r.serverHeadersRateLimit !== void 0) return Math.min(r.serverHeadersRateLimit, F);
447
+ function M(e, t, r = {}, s) {
448
+ if (r.userRateLimit !== void 0) return Math.min(r.userRateLimit, X);
449
+ if (r.serverHeadersRateLimit !== void 0) return Math.min(r.serverHeadersRateLimit, X);
454
450
  if (s !== void 0) return s;
455
- if (t && !Se(t)) return F;
456
- if (Te(e, t)) return I.SINGLE_OR_SMALL;
451
+ if (!e || !t || Se(e, t)) return C.SINGLE_OR_SMALL;
457
452
  const i = t.per_page || ke;
458
- return Ce(i);
453
+ return Te(i);
459
454
  }
460
- function Oe(e) {
455
+ function Ce(e) {
461
456
  if (!e) return null;
462
457
  const t = e["x-ratelimit"] || e["X-RateLimit"], r = e["x-ratelimit-policy"] || e["X-RateLimit-Policy"];
463
458
  if (!t && !r) return null;
@@ -479,12 +474,12 @@ function Ie(e, t = !1) {
479
474
  isManagementApi: t
480
475
  };
481
476
  }
482
- var Pe = class extends Error {
477
+ var Oe = class extends Error {
483
478
  constructor(e) {
484
479
  super(e), this.name = "AbortError";
485
480
  }
486
481
  };
487
- function xe(e, t, r) {
482
+ function Pe(e, t, r) {
488
483
  if (!Number.isFinite(t)) throw new TypeError("Expected `limit` to be a finite number");
489
484
  if (!Number.isFinite(r)) throw new TypeError("Expected `interval` to be a finite number");
490
485
  const s = [];
@@ -510,10 +505,10 @@ function xe(e, t, r) {
510
505
  }), n < t && a();
511
506
  });
512
507
  return u.abort = () => {
513
- l = !0, i.forEach(clearTimeout), i = [], s.forEach((c) => c.reject(() => new Pe("Throttle function aborted"))), s.length = 0;
508
+ l = !0, i.forEach(clearTimeout), i = [], s.forEach((c) => c.reject(() => new Oe("Throttle function aborted"))), s.length = 0;
514
509
  }, u;
515
510
  }
516
- var Ne = xe, He = class {
511
+ var xe = Pe, Ne = class {
517
512
  constructor(e, t = 1e3) {
518
513
  y(this, "queues");
519
514
  y(this, "interval");
@@ -525,7 +520,7 @@ var Ne = xe, He = class {
525
520
  */
526
521
  getQueue(e) {
527
522
  let t = this.queues.get(e);
528
- return t || (t = Ne(this.throttledRequestFn, e, this.interval), this.queues.set(e, t)), t;
523
+ return t || (t = xe(this.throttledRequestFn, e, this.interval), this.queues.set(e, t)), t;
529
524
  }
530
525
  /**
531
526
  * Executes a request through the appropriate throttle queue based on rate limit
@@ -549,7 +544,7 @@ var Ne = xe, He = class {
549
544
  return this.queues.size;
550
545
  }
551
546
  };
552
- let M = {};
547
+ let $ = {};
553
548
  const S = {};
554
549
  var Me = class {
555
550
  /**
@@ -580,12 +575,12 @@ var Me = class {
580
575
  let r = e.endpoint || t;
581
576
  if (!r) {
582
577
  const i = e.https === !1 ? "http" : "https";
583
- e.oauthToken ? r = `${i}://${Q(e.region)}/v1` : r = `${i}://${Q(e.region)}/v2`;
578
+ e.oauthToken ? r = `${i}://${W(e.region)}/v1` : r = `${i}://${W(e.region)}/v2`;
584
579
  }
585
580
  const s = new Headers();
586
581
  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, l]) => {
587
582
  s.set(n, l);
588
- }), s.has(X) || (s.set(X, G.defaultAgentName), s.set(G.defaultAgentVersion, G.packageVersion)), e.oauthToken && s.set("Authorization", e.oauthToken), this.rateLimitConfig = Ie(e.rateLimit, !!e.oauthToken), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttleManager = new He(this.throttledRequest.bind(this), 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 || ee.PUBLISHED, this.inlineAssets = e.inlineAssets || !1, this.client = new we({
583
+ }), s.has(Q) || (s.set(Q, G.defaultAgentName), s.set(G.defaultAgentVersion, G.packageVersion)), e.oauthToken && s.set("Authorization", e.oauthToken), this.rateLimitConfig = Ie(e.rateLimit, !!e.oauthToken), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttleManager = new Ne(this.throttledRequest.bind(this), 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 || we.PUBLISHED, this.inlineAssets = e.inlineAssets || !1, this.client = new Le({
589
584
  baseURL: r,
590
585
  timeout: e.timeout || 0,
591
586
  headers: s,
@@ -600,7 +595,7 @@ var Me = class {
600
595
  return j(e) ? this.parseParams(t) : t;
601
596
  }
602
597
  makeRequest(e, t, r, s, i) {
603
- const n = this.factoryParamOptions(e, pe(t, r, s));
598
+ const n = this.factoryParamOptions(e, me(t, r, s));
604
599
  return this.cacheResponse(e, n, void 0, i);
605
600
  }
606
601
  get(e, t = {}, r) {
@@ -613,20 +608,20 @@ var Me = class {
613
608
  async getAll(e, t = {}, r, s) {
614
609
  const i = (t == null ? void 0 : t.per_page) || 25, n = `/${e}`.replace(/\/$/, ""), l = r ?? n.substring(n.lastIndexOf("/") + 1);
615
610
  t.version = t.version || this.version;
616
- const a = 1, u = await this.makeRequest(n, t, i, a, s), c = u.total ? Math.ceil(u.total / (u.perPage || i)) : 1, b = await Ee(_e(a, c), (m) => this.makeRequest(n, t, i, m + 1, s));
617
- return Ae([u, ...b], (m) => Object.values(m.data[l]));
611
+ const a = 1, u = await this.makeRequest(n, t, i, a, s), c = u.total ? Math.ceil(u.total / (u.perPage || i)) : 1, b = await _e(ve(a, c), (m) => this.makeRequest(n, t, i, m + 1, s));
612
+ return Ee([u, ...b], (m) => Object.values(m.data[l]));
618
613
  }
619
614
  post(e, t = {}, r) {
620
- const s = `/${e}`, i = H(void 0, void 0, this.rateLimitConfig, N);
615
+ const s = `/${e}`, i = M(void 0, void 0, this.rateLimitConfig, N);
621
616
  return this.throttleManager.execute(i, "post", s, t, r);
622
617
  }
623
618
  put(e, t = {}, r) {
624
- const s = `/${e}`, i = H(void 0, void 0, this.rateLimitConfig, N);
619
+ const s = `/${e}`, i = M(void 0, void 0, this.rateLimitConfig, N);
625
620
  return this.throttleManager.execute(i, "put", s, t, r);
626
621
  }
627
622
  delete(e, t = {}, r) {
628
623
  t || (t = {});
629
- const s = `/${e}`, i = H(void 0, void 0, this.rateLimitConfig, N);
624
+ const s = `/${e}`, i = M(void 0, void 0, this.rateLimitConfig, N);
630
625
  return this.throttleManager.execute(i, "delete", s, t, r);
631
626
  }
632
627
  getStories(e = {}, t) {
@@ -802,7 +797,7 @@ var Me = class {
802
797
  const c = await n.get(i);
803
798
  if (c) return Promise.resolve(c);
804
799
  }
805
- const a = !j(e) && this.rateLimitConfig.isManagementApi ? N : void 0, u = H(e, t, this.rateLimitConfig, a);
800
+ const a = !j(e) && this.rateLimitConfig.isManagementApi ? N : void 0, u = M(e, t, this.rateLimitConfig, a);
806
801
  return new Promise(async (c, b) => {
807
802
  var m;
808
803
  try {
@@ -812,20 +807,20 @@ var Me = class {
812
807
  data: R.data,
813
808
  headers: R.headers
814
809
  };
815
- const _ = Oe(R.headers);
810
+ const _ = Ce(R.headers);
816
811
  if ((_ == null ? void 0 : _.max) !== void 0 && (this.rateLimitConfig.serverHeadersRateLimit = _.max), (m = R.headers) != null && m["per-page"] && (A = Object.assign({}, A, {
817
812
  perPage: R.headers["per-page"] ? Number.parseInt(R.headers["per-page"]) : 0,
818
813
  total: R.headers["per-page"] ? Number.parseInt(R.headers.total) : 0
819
814
  })), A.data.story || A.data.stories) {
820
- const U = this.resolveCounter = ++this.resolveCounter % 1e3;
821
- await this.resolveStories(A.data, t, `${U}`), A = await this.processInlineAssets(A);
815
+ const H = this.resolveCounter = ++this.resolveCounter % 1e3;
816
+ await this.resolveStories(A.data, t, `${H}`), A = await this.processInlineAssets(A);
822
817
  }
823
818
  t.version === "published" && e !== "/cdn/spaces/me" && await n.set(i, A);
824
819
  const T = this.cache.clear === "onpreview" && t.version === "draft" || this.cache.clear === "auto";
825
820
  return t.token && A.data.cv && (T && S[t.token] && S[t.token] !== A.data.cv && await this.flushCache(), S[t.token] = A.data.cv), c(A);
826
821
  } catch (R) {
827
822
  if (R.response && R.status === 429 && (r = typeof r > "u" ? 0 : r + 1, r < this.maxRetries))
828
- return console.log(`Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`), await Re(this.retriesDelay), this.cacheResponse(e, t, r).then(c).catch(b);
823
+ return console.log(`Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`), await pe(this.retriesDelay), this.cacheResponse(e, t, r).then(c).catch(b);
829
824
  b(R);
830
825
  }
831
826
  });
@@ -850,16 +845,16 @@ var Me = class {
850
845
  case "memory":
851
846
  return {
852
847
  get(e) {
853
- return Promise.resolve(M[e]);
848
+ return Promise.resolve($[e]);
854
849
  },
855
850
  getAll() {
856
- return Promise.resolve(M);
851
+ return Promise.resolve($);
857
852
  },
858
853
  set(e, t) {
859
- return M[e] = t, Promise.resolve(void 0);
854
+ return $[e] = t, Promise.resolve(void 0);
860
855
  },
861
856
  flush() {
862
- return M = {}, Promise.resolve(void 0);
857
+ return $ = {}, Promise.resolve(void 0);
863
858
  }
864
859
  };
865
860
  case "custom":
@@ -899,8 +894,8 @@ var Me = class {
899
894
  };
900
895
  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;
901
896
  }
902
- }, Ue = Me;
903
- const je = (e = {}) => {
897
+ }, $e = Me;
898
+ const Ue = (e = {}) => {
904
899
  const { apiOptions: t } = e;
905
900
  if (!t || !t.accessToken) {
906
901
  console.error(
@@ -908,8 +903,8 @@ const je = (e = {}) => {
908
903
  );
909
904
  return;
910
905
  }
911
- return { storyblokApi: new Ue(t) };
912
- }, Ge = (e) => {
906
+ return { storyblokApi: new $e(t) };
907
+ }, je = (e) => {
913
908
  if (typeof e != "object" || typeof e._editable > "u")
914
909
  return {};
915
910
  try {
@@ -924,8 +919,8 @@ const je = (e = {}) => {
924
919
  return {};
925
920
  }
926
921
  };
927
- let D = "https://app.storyblok.com/f/storyblok-v2-latest.js";
928
- const qe = (e, t, r = {}) => {
922
+ let F = "https://app.storyblok.com/f/storyblok-v2-latest.js";
923
+ const Ge = (e, t, r = {}) => {
929
924
  var a;
930
925
  const i = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", n = new URL((a = window.location) == null ? void 0 : a.href).searchParams.get(
931
926
  "_storyblok"
@@ -942,7 +937,7 @@ const qe = (e, t, r = {}) => {
942
937
  });
943
938
  });
944
939
  }
945
- }, Fe = (e = {}) => {
940
+ }, qe = (e = {}) => {
946
941
  var b, m;
947
942
  const {
948
943
  bridge: t,
@@ -956,25 +951,25 @@ const qe = (e, t, r = {}) => {
956
951
  let a = {};
957
952
  s.forEach((R) => {
958
953
  a = { ...a, ...R(l) };
959
- }), n && (D = n);
954
+ }), n && (F = n);
960
955
  const c = !(typeof window > "u") && ((m = (b = window.location) == null ? void 0 : b.search) == null ? void 0 : m.includes("_storyblok_tk"));
961
- return t !== !1 && c && Z(D), a;
956
+ return t !== !1 && c && Z(F), a;
962
957
  };
963
- function De(e, t) {
964
- return me(t).render(e);
958
+ function Fe(e, t) {
959
+ return be(t).render(e);
965
960
  }
966
- const Be = () => Z(D);
961
+ const Be = () => Z(F);
967
962
  export {
968
963
  E as BlockTypes,
969
964
  w as MarkTypes,
970
- Ue as StoryblokClient,
971
- he as TextTypes,
972
- je as apiPlugin,
965
+ $e as StoryblokClient,
966
+ ue as TextTypes,
967
+ Ue as apiPlugin,
973
968
  Be as loadStoryblokBridge,
974
- qe as registerStoryblokBridge,
975
- De as renderRichText,
976
- me as richTextResolver,
977
- Ge as storyblokEditable,
978
- Fe as storyblokInit,
979
- qe as useStoryblokBridge
969
+ Ge as registerStoryblokBridge,
970
+ Fe as renderRichText,
971
+ be as richTextResolver,
972
+ je as storyblokEditable,
973
+ qe as storyblokInit,
974
+ Ge as useStoryblokBridge
980
975
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@storyblok/js",
3
3
  "type": "module",
4
- "version": "4.4.3",
4
+ "version": "4.4.5",
5
5
  "private": false,
6
6
  "description": "SDK to integrate Storyblok into your project using JavaScript.",
7
7
  "license": "MIT",
@@ -28,8 +28,8 @@
28
28
  "dist"
29
29
  ],
30
30
  "dependencies": {
31
- "@storyblok/richtext": "3.8.2",
32
- "storyblok-js-client": "7.2.1"
31
+ "storyblok-js-client": "7.2.3",
32
+ "@storyblok/richtext": "3.8.2"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@tsconfig/recommended": "^1.0.8",