@storyblok/js 3.2.1 → 3.2.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.
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * name: @storyblok/js
3
- * (c) 2024
3
+ * (c) 2025
4
4
  * description: SDK to integrate Storyblok into your project using JavaScript.
5
5
  * author: undefined
6
6
  */
7
- (function(y,I){typeof exports=="object"&&typeof module<"u"?I(exports):typeof define=="function"&&define.amd?define(["exports"],I):(y=typeof globalThis<"u"?globalThis:y||self,I(y.storyblok={}))})(this,function(y){"use strict";let I=!1;const B=[],D=i=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=r=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}I?r():B.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=i,s.id="storyblok-javascript-bridge",s.onerror=r=>t(r),s.onload=r=>{B.forEach(o=>o()),I=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var X=Object.defineProperty,Q=(i,e,t)=>e in i?X(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,p=(i,e,t)=>Q(i,typeof e!="symbol"?e+"":e,t);class Z extends Error{constructor(e){super(e),this.name="AbortError"}}function ee(i,e,t){if(!Number.isFinite(e))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],o=0,n=!1;const l=async()=>{o++;const c=s.shift();if(c)try{const d=await i(...c.args);c.resolve(d)}catch(d){c.reject(d)}const u=setTimeout(()=>{o--,s.length>0&&l(),r=r.filter(d=>d!==u)},t);r.includes(u)||r.push(u)},a=(...c)=>n?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((u,d)=>{s.push({resolve:u,reject:d,args:c}),o<e&&l()});return a.abort=()=>{n=!0,r.forEach(clearTimeout),r=[],s.forEach(c=>c.reject(()=>new Z("Throttle function aborted"))),s.length=0},a}class L{constructor(){p(this,"isCDNUrl",(e="")=>e.includes("/cdn/")),p(this,"getOptionsPage",(e,t=25,s=1)=>({...e,per_page:t,page:s})),p(this,"delay",e=>new Promise(t=>setTimeout(t,e))),p(this,"arrayFrom",(e=0,t)=>Array.from({length:e},t)),p(this,"range",(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return this.arrayFrom(s,(o,n)=>n*r+e)}),p(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),p(this,"flatMap",(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[])),p(this,"escapeHTML",function(e){const t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},s=/[&<>"']/g,r=new RegExp(s.source);return e&&r.test(e)?e.replace(s,o=>t[o]):e})}stringify(e,t,s){const r=[];for(const o in e){if(!Object.prototype.hasOwnProperty.call(e,o))continue;const n=e[o],l=s?"":encodeURIComponent(o);let a;typeof n=="object"?a=this.stringify(n,t?t+encodeURIComponent(`[${l}]`):l,Array.isArray(n)):a=`${t?t+encodeURIComponent(`[${l}]`):l}=${encodeURIComponent(n)}`,r.push(a)}return r.join("&")}getRegionURL(e){const t="api.storyblok.com",s="api-us.storyblok.com",r="app.storyblokchina.cn",o="api-ap.storyblok.com",n="api-ca.storyblok.com";switch(e){case"us":return s;case"cn":return r;case"ap":return o;case"ca":return n;default:return t}}}const te=function(i,e){const t={};for(const s in i){const r=i[s];e.includes(s)&&r!==null&&(t[s]=r)}return t},se=i=>i==="email",re=()=>({singleTag:"hr"}),ie=()=>({tag:"blockquote"}),oe=()=>({tag:"ul"}),ne=i=>({tag:["pre",{tag:"code",attrs:i.attrs}]}),ae=()=>({singleTag:"br"}),le=i=>({tag:`h${i.attrs.level}`}),ce=i=>({singleTag:[{tag:"img",attrs:te(i.attrs,["src","alt","title"])}]}),he=()=>({tag:"li"}),ue=()=>({tag:"ol"}),de=()=>({tag:"p"}),pe=i=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":i.attrs.name,emoji:i.attrs.emoji}}]}),ge=()=>({tag:"b"}),fe=()=>({tag:"s"}),me=()=>({tag:"u"}),ye=()=>({tag:"strong"}),be=()=>({tag:"code"}),ke=()=>({tag:"i"}),ve=i=>{if(!i.attrs)return{tag:""};const e=new L().escapeHTML,t={...i.attrs},{linktype:s="url"}=i.attrs;if(delete t.linktype,t.href&&(t.href=e(i.attrs.href||"")),se(s)&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),t.custom){for(const r in t.custom)t[r]=t.custom[r];delete t.custom}return{tag:[{tag:"a",attrs:t}]}},$e=i=>({tag:[{tag:"span",attrs:i.attrs}]}),Te=()=>({tag:"sub"}),we=()=>({tag:"sup"}),Re=i=>({tag:[{tag:"span",attrs:i.attrs}]}),Se=i=>{var e;return(e=i.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${i.attrs.color};`}}]}:{tag:""}},_e=i=>{var e;return(e=i.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${i.attrs.color}`}}]}:{tag:""}},q={nodes:{horizontal_rule:re,blockquote:ie,bullet_list:oe,code_block:ne,hard_break:ae,heading:le,image:ce,list_item:he,ordered_list:ue,paragraph:de,emoji:pe},marks:{bold:ge,strike:fe,underline:me,strong:ye,code:be,italic:ke,link:ve,styled:$e,subscript:Te,superscript:we,anchor:Re,highlight:Se,textStyle:_e}},Ee=function(i){const e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},t=/[&<>"']/g,s=new RegExp(t.source);return i&&s.test(i)?i.replace(t,r=>e[r]):i};let F=!1;class je{constructor(e){p(this,"marks"),p(this,"nodes"),e||(e=q),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e,t={optimizeImages:!1},s=!0){if(!F&&s&&(console.warn("Warning ⚠️: The RichTextResolver class is deprecated and will be removed in the next major release. Please use the `@storyblok/richtext` package instead. https://github.com/storyblok/richtext/"),F=!0),e&&e.content&&Array.isArray(e.content)){let r="";return e.content.forEach(o=>{r+=this.renderNode(o)}),t.optimizeImages?this.optimizeImages(r,t.optimizeImages):r}return console.warn(`The render method must receive an Object with a "content" field.
7
+ (function(b,I){typeof exports=="object"&&typeof module<"u"?I(exports):typeof define=="function"&&define.amd?define(["exports"],I):(b=typeof globalThis<"u"?globalThis:b||self,I(b.storyblok={}))})(this,function(b){"use strict";let I=!1;const B=[],D=i=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=r=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}I?r():B.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=i,s.id="storyblok-javascript-bridge",s.onerror=r=>t(r),s.onload=r=>{B.forEach(o=>o()),I=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var X=Object.defineProperty,Q=(i,e,t)=>e in i?X(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,p=(i,e,t)=>Q(i,typeof e!="symbol"?e+"":e,t);class Z extends Error{constructor(e){super(e),this.name="AbortError"}}function ee(i,e,t){if(!Number.isFinite(e))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],o=0,n=!1;const l=async()=>{o++;const c=s.shift();if(c)try{const d=await i(...c.args);c.resolve(d)}catch(d){c.reject(d)}const u=setTimeout(()=>{o--,s.length>0&&l(),r=r.filter(d=>d!==u)},t);r.includes(u)||r.push(u)},a=(...c)=>n?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((u,d)=>{s.push({resolve:u,reject:d,args:c}),o<e&&l()});return a.abort=()=>{n=!0,r.forEach(clearTimeout),r=[],s.forEach(c=>c.reject(()=>new Z("Throttle function aborted"))),s.length=0},a}let L=class{constructor(){p(this,"isCDNUrl",(e="")=>e.includes("/cdn/")),p(this,"getOptionsPage",(e,t=25,s=1)=>({...e,per_page:t,page:s})),p(this,"delay",e=>new Promise(t=>setTimeout(t,e))),p(this,"arrayFrom",(e=0,t)=>Array.from({length:e},t)),p(this,"range",(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return this.arrayFrom(s,(o,n)=>n*r+e)}),p(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),p(this,"flatMap",(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[])),p(this,"escapeHTML",function(e){const t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},s=/[&<>"']/g,r=new RegExp(s.source);return e&&r.test(e)?e.replace(s,o=>t[o]):e})}stringify(e,t,s){const r=[];for(const o in e){if(!Object.prototype.hasOwnProperty.call(e,o))continue;const n=e[o],l=s?"":encodeURIComponent(o);let a;typeof n=="object"?a=this.stringify(n,t?t+encodeURIComponent(`[${l}]`):l,Array.isArray(n)):a=`${t?t+encodeURIComponent(`[${l}]`):l}=${encodeURIComponent(n)}`,r.push(a)}return r.join("&")}getRegionURL(e){const t="api.storyblok.com",s="api-us.storyblok.com",r="app.storyblokchina.cn",o="api-ap.storyblok.com",n="api-ca.storyblok.com";switch(e){case"us":return s;case"cn":return r;case"ap":return o;case"ca":return n;default:return t}}};const te=function(i,e){const t={};for(const s in i){const r=i[s];e.includes(s)&&r!==null&&(t[s]=r)}return t},se=i=>i==="email",re=()=>({singleTag:"hr"}),ie=()=>({tag:"blockquote"}),oe=()=>({tag:"ul"}),ne=i=>({tag:["pre",{tag:"code",attrs:i.attrs}]}),ae=()=>({singleTag:"br"}),le=i=>({tag:`h${i.attrs.level}`}),ce=i=>({singleTag:[{tag:"img",attrs:te(i.attrs,["src","alt","title"])}]}),he=()=>({tag:"li"}),ue=()=>({tag:"ol"}),de=()=>({tag:"p"}),pe=i=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":i.attrs.name,emoji:i.attrs.emoji}}]}),ge=()=>({tag:"b"}),fe=()=>({tag:"s"}),me=()=>({tag:"u"}),ye=()=>({tag:"strong"}),be=()=>({tag:"code"}),ke=()=>({tag:"i"}),ve=i=>{if(!i.attrs)return{tag:""};const e=new L().escapeHTML,t={...i.attrs},{linktype:s="url"}=i.attrs;if(delete t.linktype,t.href&&(t.href=e(i.attrs.href||"")),se(s)&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),t.custom){for(const r in t.custom)t[r]=t.custom[r];delete t.custom}return{tag:[{tag:"a",attrs:t}]}},$e=i=>({tag:[{tag:"span",attrs:i.attrs}]}),Te=()=>({tag:"sub"}),we=()=>({tag:"sup"}),Re=i=>({tag:[{tag:"span",attrs:i.attrs}]}),Se=i=>{var e;return(e=i.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${i.attrs.color};`}}]}:{tag:""}},_e=i=>{var e;return(e=i.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${i.attrs.color}`}}]}:{tag:""}},q={nodes:{horizontal_rule:re,blockquote:ie,bullet_list:oe,code_block:ne,hard_break:ae,heading:le,image:ce,list_item:he,ordered_list:ue,paragraph:de,emoji:pe},marks:{bold:ge,strike:fe,underline:me,strong:ye,code:be,italic:ke,link:ve,styled:$e,subscript:Te,superscript:we,anchor:Re,highlight:Se,textStyle:_e}},Ee=function(i){const e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},t=/[&<>"']/g,s=new RegExp(t.source);return i&&s.test(i)?i.replace(t,r=>e[r]):i};let F=!1;class O{constructor(e){p(this,"marks"),p(this,"nodes"),e||(e=q),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e,t={optimizeImages:!1},s=!0){if(!F&&s&&(console.warn("Warning ⚠️: The RichTextResolver class is deprecated and will be removed in the next major release. Please use the `@storyblok/richtext` package instead. https://github.com/storyblok/richtext/"),F=!0),e&&e.content&&Array.isArray(e.content)){let r="";return e.content.forEach(o=>{r+=this.renderNode(o)}),t.optimizeImages?this.optimizeImages(r,t.optimizeImages):r}return console.warn(`The render method must receive an Object with a "content" field.
8
8
  The "content" field must be an array of nodes as the type ISbRichtext.
9
9
  ISbRichtext:
10
10
  content?: ISbRichtext[]
@@ -27,4 +27,4 @@
27
27
  }
28
28
  ],
29
29
  type: 'doc'
30
- }`),""}optimizeImages(e,t){let s=0,r=0,o="",n="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(o+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(o+=`height="${t.height}" `,r=t.height),(t.loading==="lazy"||t.loading==="eager")&&(o+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(o+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(n+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(n+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-F]{6}/gi)||t.filters.fill==="transparent")&&(n+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(n+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(n+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(n+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(n+=`:rotate(${t.filters.rotate})`),n.length>0&&(n=`/filters${n}`))),o.length>0&&(e=e.replace(/<img/g,`<img ${o.trim()}`));const l=s>0||r>0||n.length>0?`${s}x${r}${n}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${l}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var c,u;const d=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g);if(d&&d.length>0){const m={srcset:(c=t.srcset)==null?void 0:c.map(k=>{if(typeof k=="number")return`//${d}/m/${k}x0${n} ${k}w`;if(typeof k=="object"&&k.length===2){let _=0,x=0;return typeof k[0]=="number"&&(_=k[0]),typeof k[1]=="number"&&(x=k[1]),`//${d}/m/${_}x${x}${n} ${_}w`}return""}).join(", "),sizes:(u=t.sizes)==null?void 0:u.map(k=>k).join(", ")};let b="";return m.srcset&&(b+=`srcset="${m.srcset}" `),m.sizes&&(b+=`sizes="${m.sizes}" `),a.replace(/<img/g,`<img ${b.trim()}`)}return a})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const o=this.getMatchingMark(r);o&&o.tag!==""&&t.push(this.renderOpeningTag(o.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(Ee(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html?t.push(s.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const o=this.getMatchingMark(r);o&&o.tag!==""&&t.push(this.renderClosingTag(o.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let r=`<${s.tag}`;if(s.attrs){for(const o in s.attrs)if(Object.prototype.hasOwnProperty.call(s.attrs,o)){const n=s.attrs[o];n!==null&&(r+=` ${o}="${n}"`)}}return`${r}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}renderEmoji(e){if(e.attrs.emoji)return e.attrs.emoji;const t=[{tag:"img",attrs:{src:e.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(t," /")}}const O=je;class Ie{constructor(e){p(this,"baseURL"),p(this,"timeout"),p(this,"headers"),p(this,"responseInterceptor"),p(this,"fetch"),p(this,"ejectInterceptor"),p(this,"url"),p(this,"parameters"),p(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;if(e==="get"){const a=new L;t=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),o=new AbortController,{signal:n}=o;let l;this.timeout&&(l=setTimeout(()=>o.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:n,...this.fetchOptions});this.timeout&&clearTimeout(l);const c=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(c)):this._statusHandler(c)}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}_statusHandler(e){const t=/20[0-6]/g;return new Promise((s,r)=>{if(t.test(`${e.status}`))return s(e);const o={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};r(o)})}}const Oe=Ie,G="SB-Agent",N={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"};let C={};const E={};class Ae{constructor(e,t){p(this,"client"),p(this,"maxRetries"),p(this,"retriesDelay"),p(this,"throttle"),p(this,"accessToken"),p(this,"cache"),p(this,"helpers"),p(this,"resolveCounter"),p(this,"relations"),p(this,"links"),p(this,"richTextResolver"),p(this,"resolveNestedRelations"),p(this,"stringifiedStoriesCache");let s=e.endpoint||t;if(!s){const n=new L().getRegionURL,l=e.https===!1?"http":"https";e.oauthToken?s=`${l}://${n(e.region)}/v1`:s=`${l}://${n(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(G)||(r.set(G,N.defaultAgentName),r.set(N.defaultAgentVersion,N.packageVersion));let o=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),o=3),e.rateLimit&&(o=e.rateLimit),e.richTextSchema?this.richTextResolver=new O(e.richTextSchema):this.richTextResolver=new O,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=ee(this.throttledRequest.bind(this),o,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new L,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.client=new Oe({baseURL:s,timeout:e.timeout||0,headers:r,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return t.attrs.body&&t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=E[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 this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,r,o){const n=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,n,void 0,o)}get(e,t,s){t||(t={});const r=`/${e}`,o=this.factoryParamOptions(r,t);return this.cacheResponse(r,o,void 0,s)}async getAll(e,t,s,r){const o=(t==null?void 0:t.per_page)||25,n=`/${e}`.replace(/\/$/,""),l=s??n.substring(n.lastIndexOf("/")+1),a=1,c=await this.makeRequest(n,t,o,a,r),u=c.total?Math.ceil(c.total/o):1,d=await this.helpers.asyncMap(this.helpers.range(a,u),m=>this.makeRequest(n,t,o,m+1,r));return this.helpers.flatMap([c,...d],m=>Object.values(m.data[l]))}post(e,t,s){const r=`/${e}`;return Promise.resolve(this.throttle("post",r,t,s))}put(e,t,s){const r=`/${e}`;return Promise.resolve(this.throttle("put",r,t,s))}delete(e,t,s){t||(t={});const r=`/${e}`;return Promise.resolve(this.throttle("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(o=>this.getStoryReference(s,o)).filter(Boolean))}_insertRelations(e,t,s,r){if(Array.isArray(s)?s.find(n=>n.endsWith(`.${t}`)):s.endsWith(`.${t}`)){this._resolveField(e,t,r);return}const o=e.component?`${e.component}.${t}`:t;(Array.isArray(s)?s.includes(o):s===o)&&this._resolveField(e,t,r)}iterateTree(e,t,s){const r=(o,n="")=>{if(!(!o||o._stopResolving)){if(Array.isArray(o))o.forEach((l,a)=>r(l,`${n}[${a}]`));else if(typeof o=="object")for(const l in o){const a=n?`${n}.${l}`:l;(o.component&&o._uid||o.type==="link")&&(this._insertRelations(o,l,t,s),this._insertLinks(o,l,s)),r(o[l],a)}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const o=e.link_uuids.length,n=[],l=50;for(let a=0;a<o;a+=l){const c=Math.min(o,a+l);n.push(e.link_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.links;r.forEach(o=>{this.links[s][o.uuid]={...o,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const o=e.rel_uuids.length,n=[],l=50;for(let a=0;a<o;a+=l){const c=Math.min(o,a+l);n.push(e.rel_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:n[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(c=>{r.push(c)})}else r=e.rels;r&&r.length>0&&r.forEach(o=>{this.relations[s][o.uuid]={...o,_stopResolving:!0}})}async resolveStories(e,t,s){var r,o;let n=[];if(this.links[s]={},this.relations[s]={},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,s)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((r=e.links)!=null&&r.length||(o=e.link_uuids)!=null&&o.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const l in this.relations[s])this.iterateTree(this.relations[s][l],n,s);e.story?this.iterateTree(e.story,n,s):e.stories.forEach(l=>{this.iterateTree(l,n,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s,r){const o=this.helpers.stringify({url:e,params:t}),n=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!=="/cdn/spaces/me"){const l=await n.get(o);if(l)return Promise.resolve(l)}return new Promise(async(l,a)=>{var c;try{const u=await this.throttle("get",e,t,r);if(u.status!==200)return a(u);let d={data:u.data,headers:u.headers};if((c=u.headers)!=null&&c["per-page"]&&(d=Object.assign({},d,{perPage:u.headers["per-page"]?Number.parseInt(u.headers["per-page"]):0,total:u.headers["per-page"]?Number.parseInt(u.headers.total):0})),d.data.story||d.data.stories){const m=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(d.data,t,`${m}`)}return t.version==="published"&&e!=="/cdn/spaces/me"&&await n.set(o,d),d.data.cv&&t.token&&E[t.token]!==d.data.cv&&(await this.flushCache(),E[t.token]=d.data.cv),l(d)}catch(u){if(u.response&&u.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 this.helpers.delay(this.retriesDelay),this.cacheResponse(e,t,s).then(l).catch(a);a(u)}})}throttledRequest(e,t,s,r){return this.client.setFetchOptions(r),this.client[e](t,s)}cacheVersions(){return E}cacheVersion(){return E[this.accessToken]}setCacheVersion(e){this.accessToken&&(E[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(E[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(C[e])},getAll(){return Promise.resolve(C)},set(e,t){return C[e]=t,Promise.resolve(void 0)},flush(){return C={},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}}const xe=(i={})=>{const{apiOptions:e}=i;if(!e||!e.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 Ae(e)}},Le=i=>{if(typeof i!="object"||typeof i._editable>"u")return{};try{const e=JSON.parse(i._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":`${e.id}-${e.uid}`}:{}}catch{return{}}};function Ce(i,e){if(!e)return{src:i,attrs:{}};let t=0,s=0;const r={},o=[];function n(a,c,u,d,m){typeof a!="number"||a<=c||a>=u?console.warn(`[StoryblokRichText] - ${d.charAt(0).toUpperCase()+d.slice(1)} value must be a number between ${c} and ${u} (inclusive)`):m.push(`${d}(${a})`)}if(typeof e=="object"){if(typeof e.width=="number"&&e.width>0?(r.width=e.width,t=e.width):console.warn("[StoryblokRichText] - Width value must be a number greater than 0"),e.height&&typeof e.height=="number"&&e.height>0?(r.height=e.height,s=e.height):console.warn("[StoryblokRichText] - Height value must be a number greater than 0"),e.loading&&["lazy","eager"].includes(e.loading)&&(r.loading=e.loading),e.class&&(r.class=e.class),e.filters){const{filters:a}=e||{},{blur:c,brightness:u,fill:d,format:m,grayscale:b,quality:k,rotate:_}=a||{};c&&n(c,0,100,"blur",o),k&&n(k,0,100,"quality",o),u&&n(u,0,100,"brightness",o),d&&o.push(`fill(${d})`),b&&o.push("grayscale()"),_&&[0,90,180,270].includes(e.filters.rotate||0)&&o.push(`rotate(${_})`),m&&["webp","png","jpeg"].includes(m)&&o.push(`format(${m})`)}e.srcset&&(r.srcset=e.srcset.map(a=>{if(typeof a=="number")return`${i}/m/${a}x0/${o.length>0?`filters:${o.join(":")}`:""} ${a}w`;if(Array.isArray(a)&&a.length===2){const[c,u]=a;return`${i}/m/${c}x${u}/${o.length>0?`filters:${o.join(":")}`:""} ${c}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),e.sizes&&(r.sizes=e.sizes.join(", "))}let l=`${i}/m/`;return t>0&&s>0&&(l=`${l}${t}x${s}/`),o.length>0&&(l=`${l}filters:${o.join(":")}`),{src:l,attrs:r}}var v=(i=>(i.DOCUMENT="doc",i.HEADING="heading",i.PARAGRAPH="paragraph",i.QUOTE="blockquote",i.OL_LIST="ordered_list",i.UL_LIST="bullet_list",i.LIST_ITEM="list_item",i.CODE_BLOCK="code_block",i.HR="horizontal_rule",i.BR="hard_break",i.IMAGE="image",i.EMOJI="emoji",i.COMPONENT="blok",i))(v||{}),T=(i=>(i.BOLD="bold",i.STRONG="strong",i.STRIKE="strike",i.UNDERLINE="underline",i.ITALIC="italic",i.CODE="code",i.LINK="link",i.ANCHOR="anchor",i.STYLED="styled",i.SUPERSCRIPT="superscript",i.SUBSCRIPT="subscript",i.TEXT_STYLE="textStyle",i.HIGHLIGHT="highlight",i))(T||{}),M=(i=>(i.TEXT="text",i))(M||{}),A=(i=>(i.URL="url",i.STORY="story",i.ASSET="asset",i.EMAIL="email",i))(A||{});const Pe=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],Ne=(i={})=>Object.keys(i).map(e=>`${e}="${i[e]}"`).join(" "),Me=(i={})=>Object.keys(i).map(e=>`${e}: ${i[e]}`).join("; ");function He(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}const V=i=>Object.fromEntries(Object.entries(i).filter(([e,t])=>t!==void 0));function J(i,e={},t){const s=Ne(e),r=s?`${i} ${s}`:i,o=Array.isArray(t)?t.join(""):t||"";if(i){if(Pe.includes(i))return`<${r}>`}else return o;return`<${r}>${o}</${i}>`}function Ue(i={}){let e=0;const{renderFn:t=J,textFn:s=He,resolvers:r={},optimizeImages:o=!1,keyedResolvers:n=!1}=i,l=t!==J,a=h=>g=>{const f=g.attrs||{};return n&&(f.key=`${h}-${e}`),t(h,f,g.children||null)},c=h=>{const{src:g,alt:f,title:$,srcset:S,sizes:w}=h.attrs||{};let R=g,j={};if(o){const{src:Ve,attrs:Je}=Ce(g,o);R=Ve,j=Je}n&&(j={...j,key:`img-${e}`});const Ge={src:R,alt:f,title:$,srcset:S,sizes:w,...j};return t("img",V(Ge))},u=h=>{const{level:g,...f}=h.attrs||{},$={...f};return n&&($.key=`h${g}-${e}`),t(`h${g}`,$,h.children)},d=h=>{var g,f,$,S;const w=t("img",{src:(g=h.attrs)==null?void 0:g.fallbackImage,alt:(f=h.attrs)==null?void 0:f.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"}),R={"data-type":"emoji","data-name":($=h.attrs)==null?void 0:$.name,"data-emoji":(S=h.attrs)==null?void 0:S.emoji};return n&&(R.key=`emoji-${e}`),t("span",R,w)},m=h=>t("pre",{...h.attrs,key:`code-${e}`},t("code",{key:`code-${e}`},h.children||"")),b=(h,g=!1)=>({text:f,attrs:$})=>{const{class:S,id:w,...R}=$||{},j=g?{class:S,id:w,style:Me(R)||void 0}:$||{};return n&&(j.key=`${h}-${e}`),t(h,V(j),f)},k=h=>z(h),_=h=>{const{marks:g,...f}=h;return"text"in h?g?g.reduce(($,S)=>k({...S,text:$}),k({...f,children:f.children})):s(f.text):""},x=h=>{const{linktype:g,href:f,anchor:$,...S}=h.attrs||{};let w="";switch(g){case A.ASSET:case A.URL:w=f;break;case A.EMAIL:w=`mailto:${f}`;break;case A.STORY:w=f,$&&(w=`${w}#${$}`);break;default:w=f;break}const R={...S};return w&&(R.href=w),n&&(R.key=`a-${e}`),t("a",R,h.text)},qe=h=>{var g,f;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),t("span",{blok:(g=h==null?void 0:h.attrs)==null?void 0:g.body[0],id:(f=h.attrs)==null?void 0:f.id,key:`component-${e}`,style:"display: none"})},Fe=new Map([[v.DOCUMENT,a("")],[v.HEADING,u],[v.PARAGRAPH,a("p")],[v.UL_LIST,a("ul")],[v.OL_LIST,a("ol")],[v.LIST_ITEM,a("li")],[v.IMAGE,c],[v.EMOJI,d],[v.CODE_BLOCK,m],[v.HR,a("hr")],[v.BR,a("br")],[v.QUOTE,a("blockquote")],[v.COMPONENT,qe],[M.TEXT,_],[T.LINK,x],[T.ANCHOR,x],[T.STYLED,b("span",!0)],[T.BOLD,b("strong")],[T.TEXT_STYLE,b("span",!0)],[T.ITALIC,b("em")],[T.UNDERLINE,b("u")],[T.STRIKE,b("s")],[T.CODE,b("code")],[T.SUPERSCRIPT,b("sup")],[T.SUBSCRIPT,b("sub")],[T.HIGHLIGHT,b("mark")],...Object.entries(r).map(([h,g])=>[h,g])]);function P(h){e+=1;const g=Fe.get(h.type);if(!g)return console.error("<Storyblok>",`No resolver found for node type ${h.type}`),"";if(h.type==="text")return g(h);const f=h.content?h.content.map(z):void 0;return g({...h,children:f})}function z(h){return h.type==="doc"?l?h.content.map(P):h.content.map(P).join(""):Array.isArray(h)?h.map(P):P(h)}return{render:z}}let H,U="https://app.storyblok.com/f/storyblok-v2-latest.js";const K=(i,e,t={})=>{var l;const r=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",o=new URL((l=window.location)==null?void 0:l.href).searchParams.get("_storyblok"),n=o!==null&&+o===i;if(!(!r||!n)){if(!i){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],c=>{var u;c&&(c.action==="input"&&((u=c.story)==null?void 0:u.id)===i?e(c.story):(c.action==="change"||c.action==="published")&&c.storyId===i&&window.location.reload())})})}},Y=(i,e)=>{i.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},ze=(i={})=>{var d,m;const{bridge:e,accessToken:t,use:s=[],apiOptions:r={},richText:o={},bridgeUrl:n}=i;r.accessToken=r.accessToken||t;const l={bridge:e,apiOptions:r};let a={};s.forEach(b=>{a={...a,...b(l)}}),n&&(U=n);const u=!(typeof window>"u")&&((m=(d=window.location)==null?void 0:d.search)==null?void 0:m.includes("_storyblok_tk"));return e!==!1&&u&&D(U),H=new O(o.schema),o.resolver&&Y(H,o.resolver),a},W=i=>{var e;return!i||!((e=i==null?void 0:i.content)!=null&&e.some(t=>t.content||t.type==="blok"||t.type==="horizontal_rule"))},Be=(i,e,t)=>{let s=t||H;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return W(i)?"":(e&&(s=new O(e.schema),e.resolver&&Y(s,e.resolver)),s.render(i,{},!1))},De=()=>D(U);y.BlockTypes=v,y.MarkTypes=T,y.RichTextResolver=O,y.RichTextSchema=q,y.TextTypes=M,y.apiPlugin=xe,y.isRichTextEmpty=W,y.loadStoryblokBridge=De,y.registerStoryblokBridge=K,y.renderRichText=Be,y.richTextResolver=Ue,y.storyblokEditable=Le,y.storyblokInit=ze,y.useStoryblokBridge=K,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
30
+ }`),""}optimizeImages(e,t){let s=0,r=0,o="",n="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(o+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(o+=`height="${t.height}" `,r=t.height),(t.loading==="lazy"||t.loading==="eager")&&(o+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(o+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(n+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(n+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-F]{6}/gi)||t.filters.fill==="transparent")&&(n+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(n+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(n+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(n+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(n+=`:rotate(${t.filters.rotate})`),n.length>0&&(n=`/filters${n}`))),o.length>0&&(e=e.replace(/<img/g,`<img ${o.trim()}`));const l=s>0||r>0||n.length>0?`${s}x${r}${n}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${l}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var c,u;const d=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g);if(d&&d.length>0){const m={srcset:(c=t.srcset)==null?void 0:c.map(k=>{if(typeof k=="number")return`//${d}/m/${k}x0${n} ${k}w`;if(typeof k=="object"&&k.length===2){let E=0,x=0;return typeof k[0]=="number"&&(E=k[0]),typeof k[1]=="number"&&(x=k[1]),`//${d}/m/${E}x${x}${n} ${E}w`}return""}).join(", "),sizes:(u=t.sizes)==null?void 0:u.map(k=>k).join(", ")};let y="";return m.srcset&&(y+=`srcset="${m.srcset}" `),m.sizes&&(y+=`sizes="${m.sizes}" `),a.replace(/<img/g,`<img ${y.trim()}`)}return a})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const o=this.getMatchingMark(r);o&&o.tag!==""&&t.push(this.renderOpeningTag(o.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(Ee(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html?t.push(s.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const o=this.getMatchingMark(r);o&&o.tag!==""&&t.push(this.renderClosingTag(o.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let r=`<${s.tag}`;if(s.attrs){for(const o in s.attrs)if(Object.prototype.hasOwnProperty.call(s.attrs,o)){const n=s.attrs[o];n!==null&&(r+=` ${o}="${n}"`)}}return`${r}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}renderEmoji(e){if(e.attrs.emoji)return e.attrs.emoji;const t=[{tag:"img",attrs:{src:e.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(t," /")}}class je{constructor(e){p(this,"baseURL"),p(this,"timeout"),p(this,"headers"),p(this,"responseInterceptor"),p(this,"fetch"),p(this,"ejectInterceptor"),p(this,"url"),p(this,"parameters"),p(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;if(e==="get"){const a=new L;t=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),o=new AbortController,{signal:n}=o;let l;this.timeout&&(l=setTimeout(()=>o.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:n,...this.fetchOptions});this.timeout&&clearTimeout(l);const c=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(c)):this._statusHandler(c)}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}_statusHandler(e){const t=/20[0-6]/g;return new Promise((s,r)=>{if(t.test(`${e.status}`))return s(e);const o={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};r(o)})}}const G="SB-Agent",N={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"};let P={};const _={};class Ie{constructor(e,t){p(this,"client"),p(this,"maxRetries"),p(this,"retriesDelay"),p(this,"throttle"),p(this,"accessToken"),p(this,"cache"),p(this,"helpers"),p(this,"resolveCounter"),p(this,"relations"),p(this,"links"),p(this,"richTextResolver"),p(this,"resolveNestedRelations"),p(this,"stringifiedStoriesCache");let s=e.endpoint||t;if(!s){const n=new L().getRegionURL,l=e.https===!1?"http":"https";e.oauthToken?s=`${l}://${n(e.region)}/v1`:s=`${l}://${n(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(G)||(r.set(G,N.defaultAgentName),r.set(N.defaultAgentVersion,N.packageVersion));let o=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),o=3),e.rateLimit&&(o=e.rateLimit),e.richTextSchema?this.richTextResolver=new O(e.richTextSchema):this.richTextResolver=new O,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=ee(this.throttledRequest.bind(this),o,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new L,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.client=new je({baseURL:s,timeout:e.timeout||0,headers:r,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return t.attrs.body&&t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=_[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 this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,r,o){const n=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,n,void 0,o)}get(e,t,s){t||(t={});const r=`/${e}`,o=this.factoryParamOptions(r,t);return this.cacheResponse(r,o,void 0,s)}async getAll(e,t,s,r){const o=(t==null?void 0:t.per_page)||25,n=`/${e}`.replace(/\/$/,""),l=s??n.substring(n.lastIndexOf("/")+1),a=1,c=await this.makeRequest(n,t,o,a,r),u=c.total?Math.ceil(c.total/o):1,d=await this.helpers.asyncMap(this.helpers.range(a,u),m=>this.makeRequest(n,t,o,m+1,r));return this.helpers.flatMap([c,...d],m=>Object.values(m.data[l]))}post(e,t,s){const r=`/${e}`;return Promise.resolve(this.throttle("post",r,t,s))}put(e,t,s){const r=`/${e}`;return Promise.resolve(this.throttle("put",r,t,s))}delete(e,t,s){t||(t={});const r=`/${e}`;return Promise.resolve(this.throttle("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(o=>this.getStoryReference(s,o)).filter(Boolean))}_insertRelations(e,t,s,r){if(Array.isArray(s)?s.find(n=>n.endsWith(`.${t}`)):s.endsWith(`.${t}`)){this._resolveField(e,t,r);return}const o=e.component?`${e.component}.${t}`:t;(Array.isArray(s)?s.includes(o):s===o)&&this._resolveField(e,t,r)}iterateTree(e,t,s){const r=(o,n="")=>{if(!(!o||o._stopResolving)){if(Array.isArray(o))o.forEach((l,a)=>r(l,`${n}[${a}]`));else if(typeof o=="object")for(const l in o){const a=n?`${n}.${l}`:l;(o.component&&o._uid||o.type==="link")&&(this._insertRelations(o,l,t,s),this._insertLinks(o,l,s)),r(o[l],a)}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const o=e.link_uuids.length,n=[],l=50;for(let a=0;a<o;a+=l){const c=Math.min(o,a+l);n.push(e.link_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.links;r.forEach(o=>{this.links[s][o.uuid]={...o,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const o=e.rel_uuids.length,n=[],l=50;for(let a=0;a<o;a+=l){const c=Math.min(o,a+l);n.push(e.rel_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:n[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(c=>{r.push(c)})}else r=e.rels;r&&r.length>0&&r.forEach(o=>{this.relations[s][o.uuid]={...o,_stopResolving:!0}})}async resolveStories(e,t,s){var r,o;let n=[];if(this.links[s]={},this.relations[s]={},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,s)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((r=e.links)!=null&&r.length||(o=e.link_uuids)!=null&&o.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const l in this.relations[s])this.iterateTree(this.relations[s][l],n,s);e.story?this.iterateTree(e.story,n,s):e.stories.forEach(l=>{this.iterateTree(l,n,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s,r){const o=this.helpers.stringify({url:e,params:t}),n=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const l=await n.get(o);if(l)return Promise.resolve(l)}return new Promise(async(l,a)=>{var c;try{const u=await this.throttle("get",e,t,r);if(u.status!==200)return a(u);let d={data:u.data,headers:u.headers};if((c=u.headers)!=null&&c["per-page"]&&(d=Object.assign({},d,{perPage:u.headers["per-page"]?Number.parseInt(u.headers["per-page"]):0,total:u.headers["per-page"]?Number.parseInt(u.headers.total):0})),d.data.story||d.data.stories){const y=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(d.data,t,`${y}`)}t.version==="published"&&e!=="/cdn/spaces/me"&&await n.set(o,d);const m=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&d.data.cv&&(m&&_[t.token]&&_[t.token]!==d.data.cv&&await this.flushCache(),_[t.token]=d.data.cv),l(d)}catch(u){if(u.response&&u.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 this.helpers.delay(this.retriesDelay),this.cacheResponse(e,t,s).then(l).catch(a);a(u)}})}throttledRequest(e,t,s,r){return this.client.setFetchOptions(r),this.client[e](t,s)}cacheVersions(){return _}cacheVersion(){return _[this.accessToken]}setCacheVersion(e){this.accessToken&&(_[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(_[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(P[e])},getAll(){return Promise.resolve(P)},set(e,t){return P[e]=t,Promise.resolve(void 0)},flush(){return P={},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}}const Oe=(i={})=>{const{apiOptions:e}=i;if(!e||!e.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 Ie(e)}},Ae=i=>{if(typeof i!="object"||typeof i._editable>"u")return{};try{const e=JSON.parse(i._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":`${e.id}-${e.uid}`}:{}}catch{return{}}};function xe(i,e){if(!e)return{src:i,attrs:{}};let t=0,s=0;const r={},o=[];function n(a,c,u,d,m){typeof a!="number"||a<=c||a>=u?console.warn(`[StoryblokRichText] - ${d.charAt(0).toUpperCase()+d.slice(1)} value must be a number between ${c} and ${u} (inclusive)`):m.push(`${d}(${a})`)}if(typeof e=="object"){if(typeof e.width=="number"&&e.width>0?(r.width=e.width,t=e.width):console.warn("[StoryblokRichText] - Width value must be a number greater than 0"),e.height&&typeof e.height=="number"&&e.height>0?(r.height=e.height,s=e.height):console.warn("[StoryblokRichText] - Height value must be a number greater than 0"),e.loading&&["lazy","eager"].includes(e.loading)&&(r.loading=e.loading),e.class&&(r.class=e.class),e.filters){const{filters:a}=e||{},{blur:c,brightness:u,fill:d,format:m,grayscale:y,quality:k,rotate:E}=a||{};c&&n(c,0,100,"blur",o),k&&n(k,0,100,"quality",o),u&&n(u,0,100,"brightness",o),d&&o.push(`fill(${d})`),y&&o.push("grayscale()"),E&&[0,90,180,270].includes(e.filters.rotate||0)&&o.push(`rotate(${E})`),m&&["webp","png","jpeg"].includes(m)&&o.push(`format(${m})`)}e.srcset&&(r.srcset=e.srcset.map(a=>{if(typeof a=="number")return`${i}/m/${a}x0/${o.length>0?`filters:${o.join(":")}`:""} ${a}w`;if(Array.isArray(a)&&a.length===2){const[c,u]=a;return`${i}/m/${c}x${u}/${o.length>0?`filters:${o.join(":")}`:""} ${c}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),e.sizes&&(r.sizes=e.sizes.join(", "))}let l=`${i}/m/`;return t>0&&s>0&&(l=`${l}${t}x${s}/`),o.length>0&&(l=`${l}filters:${o.join(":")}`),{src:l,attrs:r}}var v=(i=>(i.DOCUMENT="doc",i.HEADING="heading",i.PARAGRAPH="paragraph",i.QUOTE="blockquote",i.OL_LIST="ordered_list",i.UL_LIST="bullet_list",i.LIST_ITEM="list_item",i.CODE_BLOCK="code_block",i.HR="horizontal_rule",i.BR="hard_break",i.IMAGE="image",i.EMOJI="emoji",i.COMPONENT="blok",i))(v||{}),T=(i=>(i.BOLD="bold",i.STRONG="strong",i.STRIKE="strike",i.UNDERLINE="underline",i.ITALIC="italic",i.CODE="code",i.LINK="link",i.ANCHOR="anchor",i.STYLED="styled",i.SUPERSCRIPT="superscript",i.SUBSCRIPT="subscript",i.TEXT_STYLE="textStyle",i.HIGHLIGHT="highlight",i))(T||{}),M=(i=>(i.TEXT="text",i))(M||{}),A=(i=>(i.URL="url",i.STORY="story",i.ASSET="asset",i.EMAIL="email",i))(A||{});const Le=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],Pe=(i={})=>Object.keys(i).map(e=>`${e}="${i[e]}"`).join(" "),Ce=(i={})=>Object.keys(i).map(e=>`${e}: ${i[e]}`).join("; ");function Ne(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}const V=i=>Object.fromEntries(Object.entries(i).filter(([e,t])=>t!==void 0));function J(i,e={},t){const s=Pe(e),r=s?`${i} ${s}`:i,o=Array.isArray(t)?t.join(""):t||"";if(i){if(Le.includes(i))return`<${r}>`}else return o;return`<${r}>${o}</${i}>`}function Me(i={}){let e=0;const{renderFn:t=J,textFn:s=Ne,resolvers:r={},optimizeImages:o=!1,keyedResolvers:n=!1}=i,l=t!==J,a=h=>g=>{const f=g.attrs||{};return n&&(f.key=`${h}-${e}`),t(h,f,g.children||null)},c=h=>{const{src:g,alt:f,title:$,srcset:S,sizes:w}=h.attrs||{};let R=g,j={};if(o){const{src:Fe,attrs:Ge}=xe(g,o);R=Fe,j=Ge}n&&(j={...j,key:`img-${e}`});const qe={src:R,alt:f,title:$,srcset:S,sizes:w,...j};return t("img",V(qe))},u=h=>{const{level:g,...f}=h.attrs||{},$={...f};return n&&($.key=`h${g}-${e}`),t(`h${g}`,$,h.children)},d=h=>{var g,f,$,S;const w=t("img",{src:(g=h.attrs)==null?void 0:g.fallbackImage,alt:(f=h.attrs)==null?void 0:f.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"}),R={"data-type":"emoji","data-name":($=h.attrs)==null?void 0:$.name,"data-emoji":(S=h.attrs)==null?void 0:S.emoji};return n&&(R.key=`emoji-${e}`),t("span",R,w)},m=h=>t("pre",{...h.attrs,key:`code-${e}`},t("code",{key:`code-${e}`},h.children||"")),y=(h,g=!1)=>({text:f,attrs:$})=>{const{class:S,id:w,...R}=$||{},j=g?{class:S,id:w,style:Ce(R)||void 0}:$||{};return n&&(j.key=`${h}-${e}`),t(h,V(j),f)},k=h=>z(h),E=h=>{const{marks:g,...f}=h;return"text"in h?g?g.reduce(($,S)=>k({...S,text:$}),k({...f,children:f.children})):s(f.text):""},x=h=>{const{linktype:g,href:f,anchor:$,...S}=h.attrs||{};let w="";switch(g){case A.ASSET:case A.URL:w=f;break;case A.EMAIL:w=`mailto:${f}`;break;case A.STORY:w=f,$&&(w=`${w}#${$}`);break;default:w=f;break}const R={...S};return w&&(R.href=w),n&&(R.key=`a-${e}`),t("a",R,h.text)},Be=h=>{var g,f;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),t("span",{blok:(g=h==null?void 0:h.attrs)==null?void 0:g.body[0],id:(f=h.attrs)==null?void 0:f.id,key:`component-${e}`,style:"display: none"})},De=new Map([[v.DOCUMENT,a("")],[v.HEADING,u],[v.PARAGRAPH,a("p")],[v.UL_LIST,a("ul")],[v.OL_LIST,a("ol")],[v.LIST_ITEM,a("li")],[v.IMAGE,c],[v.EMOJI,d],[v.CODE_BLOCK,m],[v.HR,a("hr")],[v.BR,a("br")],[v.QUOTE,a("blockquote")],[v.COMPONENT,Be],[M.TEXT,E],[T.LINK,x],[T.ANCHOR,x],[T.STYLED,y("span",!0)],[T.BOLD,y("strong")],[T.TEXT_STYLE,y("span",!0)],[T.ITALIC,y("em")],[T.UNDERLINE,y("u")],[T.STRIKE,y("s")],[T.CODE,y("code")],[T.SUPERSCRIPT,y("sup")],[T.SUBSCRIPT,y("sub")],[T.HIGHLIGHT,y("mark")],...Object.entries(r).map(([h,g])=>[h,g])]);function C(h){e+=1;const g=De.get(h.type);if(!g)return console.error("<Storyblok>",`No resolver found for node type ${h.type}`),"";if(h.type==="text")return g(h);const f=h.content?h.content.map(z):void 0;return g({...h,children:f})}function z(h){return h.type==="doc"?l?h.content.map(C):h.content.map(C).join(""):Array.isArray(h)?h.map(C):C(h)}return{render:z}}let H,U="https://app.storyblok.com/f/storyblok-v2-latest.js";const K=(i,e,t={})=>{var l;const r=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",o=new URL((l=window.location)==null?void 0:l.href).searchParams.get("_storyblok"),n=o!==null&&+o===i;if(!(!r||!n)){if(!i){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],c=>{var u;c&&(c.action==="input"&&((u=c.story)==null?void 0:u.id)===i?e(c.story):(c.action==="change"||c.action==="published")&&c.storyId===i&&window.location.reload())})})}},Y=(i,e)=>{i.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},He=(i={})=>{var d,m;const{bridge:e,accessToken:t,use:s=[],apiOptions:r={},richText:o={},bridgeUrl:n}=i;r.accessToken=r.accessToken||t;const l={bridge:e,apiOptions:r};let a={};s.forEach(y=>{a={...a,...y(l)}}),n&&(U=n);const u=!(typeof window>"u")&&((m=(d=window.location)==null?void 0:d.search)==null?void 0:m.includes("_storyblok_tk"));return e!==!1&&u&&D(U),H=new O(o.schema),o.resolver&&Y(H,o.resolver),a},W=i=>{var e;return!i||!((e=i==null?void 0:i.content)!=null&&e.some(t=>t.content||t.type==="blok"||t.type==="horizontal_rule"))},Ue=(i,e,t)=>{let s=t||H;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return W(i)?"":(e&&(s=new O(e.schema),e.resolver&&Y(s,e.resolver)),s.render(i,{},!1))},ze=()=>D(U);b.BlockTypes=v,b.MarkTypes=T,b.RichTextResolver=O,b.RichTextSchema=q,b.TextTypes=M,b.apiPlugin=Oe,b.isRichTextEmpty=W,b.loadStoryblokBridge=ze,b.registerStoryblokBridge=K,b.renderRichText=Ue,b.richTextResolver=Me,b.storyblokEditable=Ae,b.storyblokInit=He,b.useStoryblokBridge=K,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * name: @storyblok/js
3
- * (c) 2024
3
+ * (c) 2025
4
4
  * description: SDK to integrate Storyblok into your project using JavaScript.
5
5
  * author: undefined
6
6
  */
@@ -63,7 +63,7 @@ function te(i, e, t) {
63
63
  ), s.length = 0;
64
64
  }, a;
65
65
  }
66
- class A {
66
+ let A = class {
67
67
  constructor() {
68
68
  p(this, "isCDNUrl", (e = "") => e.includes("/cdn/")), p(this, "getOptionsPage", (e, t = 25, s = 1) => ({
69
69
  ...e,
@@ -125,7 +125,7 @@ class A {
125
125
  return t;
126
126
  }
127
127
  }
128
- }
128
+ };
129
129
  const se = function(i, e) {
130
130
  const t = {};
131
131
  for (const s in i) {
@@ -292,7 +292,7 @@ const se = function(i, e) {
292
292
  return i && s.test(i) ? i.replace(t, (r) => e[r]) : i;
293
293
  };
294
294
  let z = !1;
295
- class xe {
295
+ class L {
296
296
  constructor(e) {
297
297
  p(this, "marks"), p(this, "nodes"), e || (e = je), this.marks = e.marks || [], this.nodes = e.nodes || [];
298
298
  }
@@ -433,8 +433,7 @@ class xe {
433
433
  return this.renderTag(t, " /");
434
434
  }
435
435
  }
436
- const L = xe;
437
- class Oe {
436
+ class xe {
438
437
  constructor(e) {
439
438
  p(this, "baseURL"), p(this, "timeout"), p(this, "headers"), p(this, "responseInterceptor"), p(this, "fetch"), p(this, "ejectInterceptor"), p(this, "url"), p(this, "parameters"), p(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 = {};
440
439
  }
@@ -521,14 +520,14 @@ class Oe {
521
520
  });
522
521
  }
523
522
  }
524
- const Ae = Oe, D = "SB-Agent", P = {
523
+ const D = "SB-Agent", P = {
525
524
  defaultAgentName: "SB-JS-CLIENT",
526
525
  defaultAgentVersion: "SB-Agent-Version",
527
526
  packageVersion: "6.0.0"
528
527
  };
529
528
  let O = {};
530
- const E = {};
531
- class Le {
529
+ const _ = {};
530
+ class Oe {
532
531
  /**
533
532
  *
534
533
  * @param config ISbConfig interface
@@ -553,7 +552,7 @@ class Le {
553
552
  this.throttledRequest.bind(this),
554
553
  o,
555
554
  1e3
556
- ), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new A(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new Ae({
555
+ ), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new A(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new xe({
557
556
  baseURL: s,
558
557
  timeout: e.timeout || 0,
559
558
  headers: r,
@@ -572,7 +571,7 @@ class Le {
572
571
  });
573
572
  }
574
573
  parseParams(e) {
575
- return e.token || (e.token = this.getToken()), e.cv || (e.cv = E[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
574
+ return e.token || (e.token = this.getToken()), e.cv || (e.cv = _[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
576
575
  }
577
576
  factoryParamOptions(e, t) {
578
577
  return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
@@ -793,7 +792,7 @@ class Le {
793
792
  }
794
793
  async cacheResponse(e, t, s, r) {
795
794
  const o = this.helpers.stringify({ url: e, params: t }), n = this.cacheProvider();
796
- if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e !== "/cdn/spaces/me") {
795
+ if (t.version === "published" && e !== "/cdn/spaces/me") {
797
796
  const l = await n.get(o);
798
797
  if (l)
799
798
  return Promise.resolve(l);
@@ -814,10 +813,12 @@ class Le {
814
813
  perPage: u.headers["per-page"] ? Number.parseInt(u.headers["per-page"]) : 0,
815
814
  total: u.headers["per-page"] ? Number.parseInt(u.headers.total) : 0
816
815
  })), d.data.story || d.data.stories) {
817
- const m = this.resolveCounter = ++this.resolveCounter % 1e3;
818
- await this.resolveStories(d.data, t, `${m}`);
816
+ const y = this.resolveCounter = ++this.resolveCounter % 1e3;
817
+ await this.resolveStories(d.data, t, `${y}`);
819
818
  }
820
- return t.version === "published" && e !== "/cdn/spaces/me" && await n.set(o, d), d.data.cv && t.token && E[t.token] !== d.data.cv && (await this.flushCache(), E[t.token] = d.data.cv), l(d);
819
+ t.version === "published" && e !== "/cdn/spaces/me" && await n.set(o, d);
820
+ const m = this.cache.clear === "onpreview" && t.version === "draft" || this.cache.clear === "auto";
821
+ return t.token && d.data.cv && (m && _[t.token] && _[t.token] !== d.data.cv && await this.flushCache(), _[t.token] = d.data.cv), l(d);
821
822
  } catch (u) {
822
823
  if (u.response && u.status === 429 && (s = typeof s > "u" ? 0 : s + 1, s < this.maxRetries))
823
824
  return console.log(
@@ -831,16 +832,16 @@ class Le {
831
832
  return this.client.setFetchOptions(r), this.client[e](t, s);
832
833
  }
833
834
  cacheVersions() {
834
- return E;
835
+ return _;
835
836
  }
836
837
  cacheVersion() {
837
- return E[this.accessToken];
838
+ return _[this.accessToken];
838
839
  }
839
840
  setCacheVersion(e) {
840
- this.accessToken && (E[this.accessToken] = e);
841
+ this.accessToken && (_[this.accessToken] = e);
841
842
  }
842
843
  clearCacheVersion() {
843
- this.accessToken && (E[this.accessToken] = 0);
844
+ this.accessToken && (_[this.accessToken] = 0);
844
845
  }
845
846
  cacheProvider() {
846
847
  switch (this.cache.type) {
@@ -862,6 +863,7 @@ class Le {
862
863
  case "custom":
863
864
  if (this.cache.custom)
864
865
  return this.cache.custom;
866
+ // eslint-disable-next-line no-fallthrough
865
867
  default:
866
868
  return {
867
869
  get() {
@@ -883,7 +885,7 @@ class Le {
883
885
  return await this.cacheProvider().flush(), this.clearCacheVersion(), this;
884
886
  }
885
887
  }
886
- const ze = (i = {}) => {
888
+ const Ue = (i = {}) => {
887
889
  const { apiOptions: e } = i;
888
890
  if (!e || !e.accessToken) {
889
891
  console.error(
@@ -891,8 +893,8 @@ const ze = (i = {}) => {
891
893
  );
892
894
  return;
893
895
  }
894
- return { storyblokApi: new Le(e) };
895
- }, De = (i) => {
896
+ return { storyblokApi: new Oe(e) };
897
+ }, ze = (i) => {
896
898
  if (typeof i != "object" || typeof i._editable > "u")
897
899
  return {};
898
900
  try {
@@ -907,7 +909,7 @@ const ze = (i = {}) => {
907
909
  return {};
908
910
  }
909
911
  };
910
- function Ce(i, e) {
912
+ function Ae(i, e) {
911
913
  if (!e)
912
914
  return { src: i, attrs: {} };
913
915
  let t = 0, s = 0;
@@ -939,7 +941,7 @@ function Ce(i, e) {
939
941
  };
940
942
  }
941
943
  var $ = /* @__PURE__ */ ((i) => (i.DOCUMENT = "doc", i.HEADING = "heading", i.PARAGRAPH = "paragraph", i.QUOTE = "blockquote", i.OL_LIST = "ordered_list", i.UL_LIST = "bullet_list", i.LIST_ITEM = "list_item", i.CODE_BLOCK = "code_block", i.HR = "horizontal_rule", i.BR = "hard_break", i.IMAGE = "image", i.EMOJI = "emoji", i.COMPONENT = "blok", i))($ || {}), T = /* @__PURE__ */ ((i) => (i.BOLD = "bold", i.STRONG = "strong", i.STRIKE = "strike", i.UNDERLINE = "underline", i.ITALIC = "italic", i.CODE = "code", i.LINK = "link", i.ANCHOR = "anchor", i.STYLED = "styled", i.SUPERSCRIPT = "superscript", i.SUBSCRIPT = "subscript", i.TEXT_STYLE = "textStyle", i.HIGHLIGHT = "highlight", i))(T || {}), G = /* @__PURE__ */ ((i) => (i.TEXT = "text", i))(G || {}), I = /* @__PURE__ */ ((i) => (i.URL = "url", i.STORY = "story", i.ASSET = "asset", i.EMAIL = "email", i))(I || {});
942
- const Pe = [
944
+ const Le = [
943
945
  "area",
944
946
  "base",
945
947
  "br",
@@ -954,24 +956,24 @@ const Pe = [
954
956
  "source",
955
957
  "track",
956
958
  "wbr"
957
- ], Ne = (i = {}) => Object.keys(i).map((e) => `${e}="${i[e]}"`).join(" "), Me = (i = {}) => Object.keys(i).map((e) => `${e}: ${i[e]}`).join("; ");
958
- function He(i) {
959
+ ], Ce = (i = {}) => Object.keys(i).map((e) => `${e}="${i[e]}"`).join(" "), Pe = (i = {}) => Object.keys(i).map((e) => `${e}: ${i[e]}`).join("; ");
960
+ function Ne(i) {
959
961
  return i.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
960
962
  }
961
963
  const B = (i) => Object.fromEntries(Object.entries(i).filter(([e, t]) => t !== void 0));
962
964
  function q(i, e = {}, t) {
963
- const s = Ne(e), r = s ? `${i} ${s}` : i, o = Array.isArray(t) ? t.join("") : t || "";
965
+ const s = Ce(e), r = s ? `${i} ${s}` : i, o = Array.isArray(t) ? t.join("") : t || "";
964
966
  if (i) {
965
- if (Pe.includes(i))
967
+ if (Le.includes(i))
966
968
  return `<${r}>`;
967
969
  } else return o;
968
970
  return `<${r}>${o}</${i}>`;
969
971
  }
970
- function Be(i = {}) {
972
+ function De(i = {}) {
971
973
  let e = 0;
972
974
  const {
973
975
  renderFn: t = q,
974
- textFn: s = He,
976
+ textFn: s = Ne,
975
977
  resolvers: r = {},
976
978
  optimizeImages: o = !1,
977
979
  keyedResolvers: n = !1
@@ -980,13 +982,13 @@ function Be(i = {}) {
980
982
  return n && (f.key = `${h}-${e}`), t(h, f, g.children || null);
981
983
  }, c = (h) => {
982
984
  const { src: g, alt: f, title: k, srcset: R, sizes: v } = h.attrs || {};
983
- let w = g, _ = {};
985
+ let w = g, E = {};
984
986
  if (o) {
985
- const { src: W, attrs: X } = Ce(g, o);
986
- w = W, _ = X;
987
+ const { src: W, attrs: X } = Ae(g, o);
988
+ w = W, E = X;
987
989
  }
988
- n && (_ = {
989
- ..._,
990
+ n && (E = {
991
+ ...E,
990
992
  key: `img-${e}`
991
993
  });
992
994
  const Y = {
@@ -995,7 +997,7 @@ function Be(i = {}) {
995
997
  title: k,
996
998
  srcset: R,
997
999
  sizes: v,
998
- ..._
1000
+ ...E
999
1001
  };
1000
1002
  return t("img", B(Y));
1001
1003
  }, u = (h) => {
@@ -1021,12 +1023,12 @@ function Be(i = {}) {
1021
1023
  ...h.attrs,
1022
1024
  key: `code-${e}`
1023
1025
  }, t("code", { key: `code-${e}` }, h.children || "")), y = (h, g = !1) => ({ text: f, attrs: k }) => {
1024
- const { class: R, id: v, ...w } = k || {}, _ = g ? {
1026
+ const { class: R, id: v, ...w } = k || {}, E = g ? {
1025
1027
  class: R,
1026
1028
  id: v,
1027
- style: Me(w) || void 0
1029
+ style: Pe(w) || void 0
1028
1030
  } : k || {};
1029
- return n && (_.key = `${h}-${e}`), t(h, B(_), f);
1031
+ return n && (E.key = `${h}-${e}`), t(h, B(E), f);
1030
1032
  }, b = (h) => C(h), S = (h) => {
1031
1033
  const { marks: g, ...f } = h;
1032
1034
  return "text" in h ? g ? g.reduce(
@@ -1114,7 +1116,7 @@ function Be(i = {}) {
1114
1116
  };
1115
1117
  }
1116
1118
  let N, M = "https://app.storyblok.com/f/storyblok-v2-latest.js";
1117
- const qe = (i, e, t = {}) => {
1119
+ const Be = (i, e, t = {}) => {
1118
1120
  var l;
1119
1121
  const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = new URL((l = window.location) == null ? void 0 : l.href).searchParams.get(
1120
1122
  "_storyblok"
@@ -1140,7 +1142,7 @@ const qe = (i, e, t = {}) => {
1140
1142
  html: s
1141
1143
  };
1142
1144
  });
1143
- }, Fe = (i = {}) => {
1145
+ }, qe = (i = {}) => {
1144
1146
  var d, m;
1145
1147
  const {
1146
1148
  bridge: e,
@@ -1158,10 +1160,10 @@ const qe = (i, e, t = {}) => {
1158
1160
  }), n && (M = n);
1159
1161
  const u = !(typeof window > "u") && ((m = (d = window.location) == null ? void 0 : d.search) == null ? void 0 : m.includes("_storyblok_tk"));
1160
1162
  return e !== !1 && u && F(M), N = new L(o.schema), o.resolver && V(N, o.resolver), a;
1161
- }, Ue = (i) => {
1163
+ }, Me = (i) => {
1162
1164
  var e;
1163
1165
  return !i || !((e = i == null ? void 0 : i.content) != null && e.some((t) => t.content || t.type === "blok" || t.type === "horizontal_rule"));
1164
- }, Ge = (i, e, t) => {
1166
+ }, Fe = (i, e, t) => {
1165
1167
  let s = t || N;
1166
1168
  if (!s) {
1167
1169
  console.error(
@@ -1169,21 +1171,21 @@ const qe = (i, e, t = {}) => {
1169
1171
  );
1170
1172
  return;
1171
1173
  }
1172
- return Ue(i) ? "" : (e && (s = new L(e.schema), e.resolver && V(s, e.resolver)), s.render(i, {}, !1));
1173
- }, Ve = () => F(M);
1174
+ return Me(i) ? "" : (e && (s = new L(e.schema), e.resolver && V(s, e.resolver)), s.render(i, {}, !1));
1175
+ }, Ge = () => F(M);
1174
1176
  export {
1175
1177
  $ as BlockTypes,
1176
1178
  T as MarkTypes,
1177
1179
  L as RichTextResolver,
1178
1180
  je as RichTextSchema,
1179
1181
  G as TextTypes,
1180
- ze as apiPlugin,
1181
- Ue as isRichTextEmpty,
1182
- Ve as loadStoryblokBridge,
1183
- qe as registerStoryblokBridge,
1184
- Ge as renderRichText,
1185
- Be as richTextResolver,
1186
- De as storyblokEditable,
1187
- Fe as storyblokInit,
1188
- qe as useStoryblokBridge
1182
+ Ue as apiPlugin,
1183
+ Me as isRichTextEmpty,
1184
+ Ge as loadStoryblokBridge,
1185
+ Be as registerStoryblokBridge,
1186
+ Fe as renderRichText,
1187
+ De as richTextResolver,
1188
+ ze as storyblokEditable,
1189
+ qe as storyblokInit,
1190
+ Be as useStoryblokBridge
1189
1191
  };
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@storyblok/js",
3
3
  "type": "module",
4
- "version": "3.2.1",
4
+ "version": "3.2.3",
5
5
  "private": false,
6
- "packageManager": "pnpm@9.15.1",
6
+ "packageManager": "pnpm@10.2.0",
7
7
  "description": "SDK to integrate Storyblok into your project using JavaScript.",
8
8
  "license": "MIT",
9
9
  "repository": {
@@ -43,32 +43,46 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@storyblok/richtext": "3.0.2",
46
- "storyblok-js-client": "6.10.6"
46
+ "storyblok-js-client": "6.10.8"
47
47
  },
48
48
  "devDependencies": {
49
- "@commitlint/cli": "^19.6.1",
50
- "@commitlint/config-conventional": "^19.6.0",
49
+ "@commitlint/cli": "^19.7.1",
50
+ "@commitlint/config-conventional": "^19.7.1",
51
51
  "@storyblok/eslint-config": "^0.3.0",
52
52
  "@tsconfig/recommended": "^1.0.8",
53
- "@types/node": "^22.10.2",
53
+ "@types/node": "^22.13.1",
54
+ "@vitest/ui": "3.0.6",
54
55
  "cypress": "^13.17.0",
55
- "eslint": "^9.17.0",
56
+ "eslint": "^9.19.0",
56
57
  "eslint-plugin-cypress": "^4.1.0",
58
+ "jsdom": "^26.0.0",
57
59
  "kolorist": "^1.8.0",
58
- "pathe": "^1.1.2",
60
+ "pathe": "^2.0.2",
59
61
  "simple-git-hooks": "^2.11.1",
60
- "start-server-and-test": "^2.0.9",
61
- "typescript": "^5.7.2",
62
- "vite": "^6.0.5",
62
+ "start-server-and-test": "^2.0.10",
63
+ "typescript": "^5.7.3",
64
+ "vite": "^6.1.0",
63
65
  "vite-plugin-banner": "^0.8.0",
64
- "vite-plugin-dts": "^4.4.0",
65
- "vite-plugin-qrcode": "^0.2.3",
66
- "vitest": "^2.1.8"
66
+ "vite-plugin-dts": "^4.5.0",
67
+ "vite-plugin-qrcode": "^0.2.4",
68
+ "vitest": "^3.0.5"
69
+ },
70
+ "pnpm": {
71
+ "onlyBuiltDependencies": [
72
+ "cypress"
73
+ ]
67
74
  },
68
75
  "commitlint": {
69
76
  "extends": [
70
77
  "@commitlint/config-conventional"
71
- ]
78
+ ],
79
+ "rules": {
80
+ "body-max-line-length": [
81
+ 2,
82
+ "always",
83
+ 200
84
+ ]
85
+ }
72
86
  },
73
87
  "release": {
74
88
  "branches": [