@storyblok/js 3.1.7 → 3.1.8

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,24 +1,24 @@
1
- (function(y,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(y=typeof globalThis<"u"?globalThis:y||self,j(y.storyblok={}))})(this,function(y){"use strict";let j=!1;const z=[],B=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}j?r():z.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=>{z.forEach(n=>n()),j=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var W=Object.defineProperty,Q=(i,e,t)=>e in i?W(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,d=(i,e,t)=>Q(i,typeof e!="symbol"?e+"":e,t);function D(i){return!(i!==i||i===1/0||i===-1/0)}function Z(i,e,t){if(!D(e))throw new TypeError("Expected `limit` to be a finite number");if(!D(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],n=0;const o=function(){n++;const a=setTimeout(function(){n--,s.length>0&&o(),r=r.filter(function(u){return u!==a})},t);r.indexOf(a)<0&&r.push(a);const c=s.shift();c.resolve(i.apply(c.self,c.args))},l=function(...a){const c=this;return new Promise(function(u,p){s.push({resolve:u,reject:p,args:a,self:c}),n<e&&o()})};return l.abort=function(){r.forEach(clearTimeout),r=[],s.forEach(function(a){a.reject(function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"})}),s.length=0},l}let L=class{constructor(){d(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1),d(this,"getOptionsPage",(e,t=25,s=1)=>({...e,per_page:t,page:s})),d(this,"delay",e=>new Promise(t=>setTimeout(t,e))),d(this,"arrayFrom",(e=0,t)=>[...Array(e)].map(t)),d(this,"range",(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return this.arrayFrom(s,(n,o)=>o*r+e)}),d(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),d(this,"flatMap",(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[])),d(this,"escapeHTML",function(e){const t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},s=/[&<>"']/g,r=RegExp(s.source);return e&&r.test(e)?e.replace(s,n=>t[n]):e})}stringify(e,t,s){const r=[];for(const n in e){if(!Object.prototype.hasOwnProperty.call(e,n))continue;const o=e[n],l=s?"":encodeURIComponent(n);let a;typeof o=="object"?a=this.stringify(o,t?t+encodeURIComponent("["+l+"]"):l,Array.isArray(o)):a=(t?t+encodeURIComponent("["+l+"]"):l)+"="+encodeURIComponent(o),r.push(a)}return r.join("&")}getRegionURL(e){const t="api.storyblok.com",s="api-us.storyblok.com",r="app.storyblokchina.cn",n="api-ap.storyblok.com",o="api-ca.storyblok.com";switch(e){case"us":return s;case"cn":return r;case"ap":return n;case"ca":return o;default:return t}}};const ee=function(i,e){const t={};for(const s in i){const r=i[s];e.indexOf(s)>-1&&r!==null&&(t[s]=r)}return t},te=i=>i==="email",se=()=>({singleTag:"hr"}),re=()=>({tag:"blockquote"}),ie=()=>({tag:"ul"}),ne=i=>({tag:["pre",{tag:"code",attrs:i.attrs}]}),oe=()=>({singleTag:"br"}),ae=i=>({tag:`h${i.attrs.level}`}),le=i=>({singleTag:[{tag:"img",attrs:ee(i.attrs,["src","alt","title"])}]}),ce=()=>({tag:"li"}),he=()=>({tag:"ol"}),ue=()=>({tag:"p"}),de=i=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":i.attrs.name,emoji:i.attrs.emoji}}]}),pe=()=>({tag:"b"}),ge=()=>({tag:"s"}),fe=()=>({tag:"u"}),me=()=>({tag:"strong"}),ye=()=>({tag:"code"}),be=()=>({tag:"i"}),ke=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||"")),te(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}]}},ve=i=>({tag:[{tag:"span",attrs:i.attrs}]}),$e=()=>({tag:"sub"}),Te=()=>({tag:"sup"}),Re=i=>({tag:[{tag:"span",attrs:i.attrs}]}),we=i=>{var e;return(e=i.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${i.attrs.color};`}}]}:{tag:""}},Se=i=>{var e;return(e=i.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${i.attrs.color}`}}]}:{tag:""}},q={nodes:{horizontal_rule:se,blockquote:re,bullet_list:ie,code_block:ne,hard_break:oe,heading:ae,image:le,list_item:ce,ordered_list:he,paragraph:ue,emoji:de},marks:{bold:pe,strike:ge,underline:fe,strong:me,code:ye,italic:be,link:ke,styled:ve,subscript:$e,superscript:Te,anchor:Re,highlight:we,textStyle:Se}},_e=function(i){const e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},t=/[&<>"']/g,s=RegExp(t.source);return i&&s.test(i)?i.replace(t,r=>e[r]):i};let G=!1;class Ee{constructor(e){d(this,"marks"),d(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(!G&&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/"),G=!0),e&&e.content&&Array.isArray(e.content)){let r="";return e.content.forEach(n=>{r+=this.renderNode(n)}),t.optimizeImages?this.optimizeImages(r,t.optimizeImages):r}return console.warn(`The render method must receive an Object with a "content" field.
2
- The "content" field must be an array of nodes as the type ISbRichtext.
3
- ISbRichtext:
4
- content?: ISbRichtext[]
5
- marks?: ISbRichtext[]
6
- attrs?: any
7
- text?: string
8
- type: string
9
-
10
- Example:
11
- {
12
- content: [
13
- {
14
- content: [
15
- {
16
- text: 'Hello World',
17
- type: 'text'
18
- }
19
- ],
20
- type: 'paragraph'
21
- }
22
- ],
23
- type: 'doc'
24
- }`),""}optimizeImages(e,t){let s=0,r=0,n="",o="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(n+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(n+=`height="${t.height}" `,r=t.height),(t.loading==="lazy"||t.loading==="eager")&&(n+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(n+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(o+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(o+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(o+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(o+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(o+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(o+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(o+=`:rotate(${t.filters.rotate})`),o.length>0&&(o="/filters"+o))),n.length>0&&(e=e.replace(/<img/g,`<img ${n.trim()}`));const l=s>0||r>0||o.length>0?`${s}x${r}${o}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|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 p=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(p&&p.length>0){const g={srcset:(c=t.srcset)==null?void 0:c.map(b=>{if(typeof b=="number")return`//${p}/m/${b}x0${o} ${b}w`;if(typeof b=="object"&&b.length===2){let S=0,C=0;return typeof b[0]=="number"&&(S=b[0]),typeof b[1]=="number"&&(C=b[1]),`//${p}/m/${S}x${C}${o} ${S}w`}}).join(", "),sizes:(u=t.sizes)==null?void 0:u.map(b=>b).join(", ")};let T="";return g.srcset&&(T+=`srcset="${g.srcset}" `),g.sizes&&(T+=`sizes="${g.sizes}" `),a.replace(/<img/g,`<img ${T.trim()}`)}return a})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const n=this.getMatchingMark(r);n&&n.tag!==""&&t.push(this.renderOpeningTag(n.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(_e(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 n=this.getMatchingMark(r);n&&n.tag!==""&&t.push(this.renderClosingTag(n.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 n in s.attrs)if(Object.prototype.hasOwnProperty.call(s.attrs,n)){const o=s.attrs[n];o!==null&&(r+=` ${n}="${o}"`)}}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=Ee;class Ie{constructor(e){d(this,"baseURL"),d(this,"timeout"),d(this,"headers"),d(this,"responseInterceptor"),d(this,"fetch"),d(this,"ejectInterceptor"),d(this,"url"),d(this,"parameters"),d(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),n=new AbortController,{signal:o}=n;let l;this.timeout&&(l=setTimeout(()=>n.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:o,...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 n={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};r(n)})}}const je=Ie,V="SB-Agent",P={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"};let A={};const _={};class Oe{constructor(e,t){d(this,"client"),d(this,"maxRetries"),d(this,"retriesDelay"),d(this,"throttle"),d(this,"accessToken"),d(this,"cache"),d(this,"helpers"),d(this,"resolveCounter"),d(this,"relations"),d(this,"links"),d(this,"richTextResolver"),d(this,"resolveNestedRelations"),d(this,"stringifiedStoriesCache");let s=e.endpoint||t;if(!s){const o=new L().getRegionURL,l=e.https===!1?"http":"https";e.oauthToken?s=`${l}://${o(e.region)}/v1`:s=`${l}://${o(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(([o,l])=>{r.set(o,l)}),r.has(V)||(r.set(V,P.defaultAgentName),r.set(P.defaultAgentVersion,P.packageVersion));let n=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=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=Z(this.throttledRequest,n,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,n){const o=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,o,void 0,n)}get(e,t,s){t||(t={});const r=`/${e}`,n=this.factoryParamOptions(r,t);return this.cacheResponse(r,n,void 0,s)}async getAll(e,t,s,r){const n=(t==null?void 0:t.per_page)||25,o=`/${e}`,l=o.split("/"),a=s||l[l.length-1],c=1,u=await this.makeRequest(o,t,n,c,r),p=u.total?Math.ceil(u.total/n):1,g=await this.helpers.asyncMap(this.helpers.range(c,p),T=>this.makeRequest(o,t,n,T+1,r));return this.helpers.flatMap([u,...g],T=>Object.values(T.data[a]))}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){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]?(this.stringifiedStoriesCache[t]||(this.stringifiedStoriesCache[t]=JSON.stringify(this.relations[e][t])),JSON.parse(this.stringifiedStoriesCache[t])):t}_insertRelations(e,t,s,r){s.indexOf(`${e.component}.${t}`)>-1&&(typeof e[t]=="string"?e[t]=this.getStoryReference(r,e[t]):Array.isArray(e[t])&&(e[t]=e[t].map(n=>this.getStoryReference(r,n)).filter(Boolean)))}iterateTree(e,t,s){const r=n=>{if(n!=null){if(n.constructor===Array)for(let o=0;o<n.length;o++)r(n[o]);else if(n.constructor===Object){if(n._stopResolving)return;for(const o in n)(n.component&&n._uid||n.type==="link")&&(this._insertRelations(n,o,t,s),this._insertLinks(n,o,s)),r(n[o])}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const n=e.link_uuids.length,o=[],l=50;for(let a=0;a<n;a+=l){const c=Math.min(n,a+l);o.push(e.link_uuids.slice(a,c))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:o[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.links;r.forEach(n=>{this.links[s][n.uuid]={...n,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const n=e.rel_uuids.length,o=[],l=50;for(let a=0;a<n;a+=l){const c=Math.min(n,a+l);o.push(e.rel_uuids.slice(a,c))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:o[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(c=>{r.push(c)})}else r=e.rels;r&&r.length>0&&r.forEach(n=>{this.relations[s][n.uuid]={...n,_stopResolving:!0}})}async resolveStories(e,t,s){var r,n;let o=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(o=t.resolve_relations.split(",")),await this.resolveRelations(e,t,s)),t.resolve_links&&["1","story","url","link"].indexOf(t.resolve_links)>-1&&((r=e.links)!=null&&r.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],o,s);e.story?this.iterateTree(e.story,o,s):e.stories.forEach(l=>{this.iterateTree(l,o,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s,r){const n=this.helpers.stringify({url:e,params:t}),o=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const l=await o.get(n);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 p={data:u.data,headers:u.headers};if((c=u.headers)!=null&&c["per-page"]&&(p=Object.assign({},p,{perPage:u.headers["per-page"]?parseInt(u.headers["per-page"]):0,total:u.headers["per-page"]?parseInt(u.headers.total):0})),p.data.story||p.data.stories){const g=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(p.data,t,`${g}`)}return t.version==="published"&&e!="/cdn/spaces/me"&&await o.set(n,p),p.data.cv&&t.token&&_[t.token]!=p.data.cv&&(await this.flushCache(),_[t.token]=p.data.cv),l(p)}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(A[e])},getAll(){return Promise.resolve(A)},set(e,t){return A[e]=t,Promise.resolve(void 0)},flush(){return A={},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.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 Oe(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 Ae(i,e){if(!e)return{src:i,attrs:{}};let t=0,s=0;const r={},n=[];function o(a,c,u,p,g){typeof a!="number"||a<=c||a>=u?console.warn(`[StoryblokRichText] - ${p.charAt(0).toUpperCase()+p.slice(1)} value must be a number between ${c} and ${u} (inclusive)`):g.push(`${p}(${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:p,format:g,grayscale:T,quality:b,rotate:S}=a||{};c&&o(c,0,100,"blur",n),b&&o(b,0,100,"quality",n),u&&o(u,0,100,"brightness",n),p&&n.push(`fill(${p})`),T&&n.push("grayscale()"),S&&[0,90,180,270].includes(e.filters.rotate||0)&&n.push(`rotate(${S})`),g&&["webp","png","jpeg"].includes(g)&&n.push(`format(${g})`)}e.srcset&&(r.srcset=e.srcset.map(a=>{if(typeof a=="number")return`${i}/m/${a}x0/${n.length>0?`filters:${n.join(":")}`:""} ${a}w`;if(Array.isArray(a)&&a.length===2){const[c,u]=a;return`${i}/m/${c}x${u}/${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(", ")),e.sizes&&(r.sizes=e.sizes.join(", "))}let l=`${i}/m/`;return t>0&&s>0&&(l=`${l}${t}x${s}/`),n.length>0&&(l=`${l}filters:${n.join(":")}`),{src:l,attrs:r}}var k=(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))(k||{}),$=(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))($||{}),N=(i=>(i.TEXT="text",i))(N||{}),x=(i=>(i.URL="url",i.STORY="story",i.ASSET="asset",i.EMAIL="email",i))(x||{});const Ce=["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(" "),Ne=(i={})=>Object.keys(i).map(e=>`${e}: ${i[e]}`).join("; ");function Me(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}const J=i=>Object.fromEntries(Object.entries(i).filter(([e,t])=>t!==void 0));function He(i,e={},t){const s=Pe(e),r=s?`${i} ${s}`:i;return Ce.includes(i)?`<${r}>`:`<${r}>${Array.isArray(t)?t.join(""):t||""}</${i}>`}function Ue(i={}){let e=0;const{renderFn:t=He,textFn:s=Me,resolvers:r={},optimizeImages:n=!1,keyedResolvers:o=!1}=i,l=h=>f=>{const m=f.attrs||{};return o&&(m.key=`${h}-${e}`),t(h,m,f.children||null)},a=h=>{const{src:f,alt:m,title:v,srcset:w,sizes:R}=h.attrs||{};let E=f,I={};if(n){const{src:Ve,attrs:Je}=Ae(f,n);E=Ve,I=Je}o&&(I={...I,key:`img-${e}`});const Ge={src:E,alt:m,title:v,srcset:w,sizes:R,...I};return t("img",J(Ge))},c=h=>{const{level:f,...m}=h.attrs||{},v={...m};return o&&(v.key=`h${f}-${e}`),t(`h${f}`,v,h.children)},u=h=>{var f,m,v,w;const R=t("img",{src:(f=h.attrs)==null?void 0:f.fallbackImage,alt:(m=h.attrs)==null?void 0:m.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"}),E={"data-type":"emoji","data-name":(v=h.attrs)==null?void 0:v.name,"data-emoji":(w=h.attrs)==null?void 0:w.emoji};return o&&(E.key=`emoji-${e}`),t("span",E,R)},p=h=>t("pre",{...h.attrs,key:`code-${e}`},t("code",{key:`code-${e}`},h.children||"")),g=(h,f=!1)=>({text:m,attrs:v})=>{const{class:w,id:R,...E}=v||{},I=f?{class:w,id:R,style:Ne(E)||void 0}:v||{};return o&&(I.key=`${h}-${e}`),t(h,J(I),m)},T=h=>U(h),b=h=>{const{marks:f,...m}=h;return"text"in h?f?f.reduce((v,w)=>T({...w,text:v}),T({...m,children:m.children})):s(m.text):""},S=h=>{const{linktype:f,href:m,anchor:v,...w}=h.attrs||{};let R="";switch(f){case x.ASSET:case x.URL:R=m;break;case x.EMAIL:R=`mailto:${m}`;break;case x.STORY:R=m;break}return v&&(R=`${R}#${v}`),t("a",{...w,href:R,key:`a-${e}`},h.text)},C=h=>{var f,m;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),t("span",{blok:(f=h==null?void 0:h.attrs)==null?void 0:f.body[0],id:(m=h.attrs)==null?void 0:m.id,key:`component-${e}`,style:"display: none"})},qe=new Map([[k.DOCUMENT,l("div")],[k.HEADING,c],[k.PARAGRAPH,l("p")],[k.UL_LIST,l("ul")],[k.OL_LIST,l("ol")],[k.LIST_ITEM,l("li")],[k.IMAGE,a],[k.EMOJI,u],[k.CODE_BLOCK,p],[k.HR,l("hr")],[k.BR,l("br")],[k.QUOTE,l("blockquote")],[k.COMPONENT,C],[N.TEXT,b],[$.LINK,S],[$.ANCHOR,S],[$.STYLED,g("span",!0)],[$.BOLD,g("strong")],[$.TEXT_STYLE,g("span",!0)],[$.ITALIC,g("em")],[$.UNDERLINE,g("u")],[$.STRIKE,g("s")],[$.CODE,g("code")],[$.SUPERSCRIPT,g("sup")],[$.SUBSCRIPT,g("sub")],[$.HIGHLIGHT,g("mark")],...Object.entries(r).map(([h,f])=>[h,f])]);function X(h){e+=1;const f=qe.get(h.type);if(!f)return console.error("<Storyblok>",`No resolver found for node type ${h.type}`),"";if(h.type==="text")return f(h);const m=h.content?h.content.map(U):void 0;return f({...h,children:m})}function U(h){return Array.isArray(h)?h.map(X):X(h)}return{render:U}}let M,H="https://app.storyblok.com/f/storyblok-v2-latest.js";const F=(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")===i;if(!(!r||!o)){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=>{c.action==="input"&&c.story.id===i?e(c.story):(c.action==="change"||c.action==="published")&&c.storyId===i&&window.location.reload()})})}},ze=(i={})=>{var p,g;const{bridge:e,accessToken:t,use:s=[],apiOptions:r={},richText:n={},bridgeUrl:o}=i;r.accessToken=r.accessToken||t;const l={bridge:e,apiOptions:r};let a={};s.forEach(T=>{a={...a,...T(l)}}),o&&(H=o);const u=!(typeof window>"u")&&((g=(p=window.location)==null?void 0:p.search)==null?void 0:g.includes("_storyblok_tk"));return e!==!1&&u&&B(H),M=new O(n.schema),n.resolver&&K(M,n.resolver),a},K=(i,e)=>{i.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},Y=i=>!i||!(i!=null&&i.content.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule")),Be=(i,e,t)=>{let s=t||M;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return Y(i)?"":(e&&(s=new O(e.schema),e.resolver&&K(s,e.resolver)),s.render(i,{},!1))},De=()=>B(H);y.BlockTypes=k,y.MarkTypes=$,y.RichTextResolver=O,y.RichTextSchema=q,y.TextTypes=N,y.apiPlugin=xe,y.isRichTextEmpty=Y,y.loadStoryblokBridge=De,y.registerStoryblokBridge=F,y.renderRichText=Be,y.richTextResolver=Ue,y.storyblokEditable=Le,y.storyblokInit=ze,y.useStoryblokBridge=F,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
1
+ (function(y,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(y=typeof globalThis<"u"?globalThis:y||self,j(y.storyblok={}))})(this,function(y){"use strict";let j=!1;const z=[],B=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}j?r():z.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=>{z.forEach(n=>n()),j=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var X=Object.defineProperty,W=(i,e,t)=>e in i?X(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,p=(i,e,t)=>W(i,typeof e!="symbol"?e+"":e,t);class Q extends Error{constructor(e){super(e),this.name="AbortError"}}function Z(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=[],n=0,o=!1;const l=async()=>{n++;const c=s.shift();if(c){const d=await i(...c.args);c.resolve(d)}const u=setTimeout(()=>{n--,s.length>0&&l(),r=r.filter(d=>d!==u)},t);r.includes(u)||r.push(u)},a=(...c)=>o?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}),n<e&&l()});return a.abort=()=>{o=!0,r.forEach(clearTimeout),r=[],s.forEach(c=>c.reject(()=>new Q("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,(n,o)=>o*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,n=>t[n]):e})}stringify(e,t,s){const r=[];for(const n in e){if(!Object.prototype.hasOwnProperty.call(e,n))continue;const o=e[n],l=s?"":encodeURIComponent(n);let a;typeof o=="object"?a=this.stringify(o,t?t+encodeURIComponent(`[${l}]`):l,Array.isArray(o)):a=`${t?t+encodeURIComponent(`[${l}]`):l}=${encodeURIComponent(o)}`,r.push(a)}return r.join("&")}getRegionURL(e){const t="api.storyblok.com",s="api-us.storyblok.com",r="app.storyblokchina.cn",n="api-ap.storyblok.com",o="api-ca.storyblok.com";switch(e){case"us":return s;case"cn":return r;case"ap":return n;case"ca":return o;default:return t}}};const ee=function(i,e){const t={};for(const s in i){const r=i[s];e.includes(s)&&r!==null&&(t[s]=r)}return t},te=i=>i==="email",se=()=>({singleTag:"hr"}),re=()=>({tag:"blockquote"}),ie=()=>({tag:"ul"}),ne=i=>({tag:["pre",{tag:"code",attrs:i.attrs}]}),oe=()=>({singleTag:"br"}),ae=i=>({tag:`h${i.attrs.level}`}),le=i=>({singleTag:[{tag:"img",attrs:ee(i.attrs,["src","alt","title"])}]}),ce=()=>({tag:"li"}),he=()=>({tag:"ol"}),ue=()=>({tag:"p"}),de=i=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":i.attrs.name,emoji:i.attrs.emoji}}]}),pe=()=>({tag:"b"}),ge=()=>({tag:"s"}),fe=()=>({tag:"u"}),me=()=>({tag:"strong"}),ye=()=>({tag:"code"}),be=()=>({tag:"i"}),ke=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||"")),te(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}]}},ve=i=>({tag:[{tag:"span",attrs:i.attrs}]}),$e=()=>({tag:"sub"}),Te=()=>({tag:"sup"}),we=i=>({tag:[{tag:"span",attrs:i.attrs}]}),Re=i=>{var e;return(e=i.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${i.attrs.color};`}}]}:{tag:""}},Se=i=>{var e;return(e=i.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${i.attrs.color}`}}]}:{tag:""}},D={nodes:{horizontal_rule:se,blockquote:re,bullet_list:ie,code_block:ne,hard_break:oe,heading:ae,image:le,list_item:ce,ordered_list:he,paragraph:ue,emoji:de},marks:{bold:pe,strike:ge,underline:fe,strong:me,code:ye,italic:be,link:ke,styled:ve,subscript:$e,superscript:Te,anchor:we,highlight:Re,textStyle:Se}},_e=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 q=!1;class Ee{constructor(e){p(this,"marks"),p(this,"nodes"),e||(e=D),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(!q&&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/"),q=!0),e&&e.content&&Array.isArray(e.content)){let r="";return e.content.forEach(n=>{r+=this.renderNode(n)}),t.optimizeImages?this.optimizeImages(r,t.optimizeImages):r}return console.warn(`The render method must receive an Object with a "content" field.
2
+ The "content" field must be an array of nodes as the type ISbRichtext.
3
+ ISbRichtext:
4
+ content?: ISbRichtext[]
5
+ marks?: ISbRichtext[]
6
+ attrs?: any
7
+ text?: string
8
+ type: string
9
+
10
+ Example:
11
+ {
12
+ content: [
13
+ {
14
+ content: [
15
+ {
16
+ text: 'Hello World',
17
+ type: 'text'
18
+ }
19
+ ],
20
+ type: 'paragraph'
21
+ }
22
+ ],
23
+ type: 'doc'
24
+ }`),""}optimizeImages(e,t){let s=0,r=0,n="",o="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(n+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(n+=`height="${t.height}" `,r=t.height),(t.loading==="lazy"||t.loading==="eager")&&(n+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(n+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(o+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(o+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-F]{6}/gi)||t.filters.fill==="transparent")&&(o+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(o+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(o+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(o+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(o+=`:rotate(${t.filters.rotate})`),o.length>0&&(o=`/filters${o}`))),n.length>0&&(e=e.replace(/<img/g,`<img ${n.trim()}`));const l=s>0||r>0||o.length>0?`${s}x${r}${o}`:"";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 g={srcset:(c=t.srcset)==null?void 0:c.map(b=>{if(typeof b=="number")return`//${d}/m/${b}x0${o} ${b}w`;if(typeof b=="object"&&b.length===2){let S=0,C=0;return typeof b[0]=="number"&&(S=b[0]),typeof b[1]=="number"&&(C=b[1]),`//${d}/m/${S}x${C}${o} ${S}w`}return""}).join(", "),sizes:(u=t.sizes)==null?void 0:u.map(b=>b).join(", ")};let w="";return g.srcset&&(w+=`srcset="${g.srcset}" `),g.sizes&&(w+=`sizes="${g.sizes}" `),a.replace(/<img/g,`<img ${w.trim()}`)}return a})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const n=this.getMatchingMark(r);n&&n.tag!==""&&t.push(this.renderOpeningTag(n.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(_e(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 n=this.getMatchingMark(r);n&&n.tag!==""&&t.push(this.renderClosingTag(n.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 n in s.attrs)if(Object.prototype.hasOwnProperty.call(s.attrs,n)){const o=s.attrs[n];o!==null&&(r+=` ${n}="${o}"`)}}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=Ee;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),n=new AbortController,{signal:o}=n;let l;this.timeout&&(l=setTimeout(()=>n.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:o,...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 n={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};r(n)})}}const je=Ie,G="SB-Agent",P={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"};let A={};const _={};class Oe{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 o=new L().getRegionURL,l=e.https===!1?"http":"https";e.oauthToken?s=`${l}://${o(e.region)}/v1`:s=`${l}://${o(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(([o,l])=>{r.set(o,l)}),r.has(G)||(r.set(G,P.defaultAgentName),r.set(P.defaultAgentVersion,P.packageVersion));let n=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=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=Z(this.throttledRequest.bind(this),n,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,n){const o=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,o,void 0,n)}get(e,t,s){t||(t={});const r=`/${e}`,n=this.factoryParamOptions(r,t);return this.cacheResponse(r,n,void 0,s)}async getAll(e,t,s,r){const n=(t==null?void 0:t.per_page)||25,o=`/${e}`.replace(/\/$/,""),l=s??o.substring(o.lastIndexOf("/")+1),a=1,c=await this.makeRequest(o,t,n,a,r),u=c.total?Math.ceil(c.total/n):1,d=await this.helpers.asyncMap(this.helpers.range(a,u),g=>this.makeRequest(o,t,n,g+1,r));return this.helpers.flatMap([c,...d],g=>Object.values(g.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){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]?(this.stringifiedStoriesCache[t]||(this.stringifiedStoriesCache[t]=JSON.stringify(this.relations[e][t])),JSON.parse(this.stringifiedStoriesCache[t])):t}_insertRelations(e,t,s,r){s.includes(`${e.component}.${t}`)&&(typeof e[t]=="string"?e[t]=this.getStoryReference(r,e[t]):Array.isArray(e[t])&&(e[t]=e[t].map(n=>this.getStoryReference(r,n)).filter(Boolean)))}iterateTree(e,t,s){const r=n=>{if(n!=null){if(n.constructor===Array)for(let o=0;o<n.length;o++)r(n[o]);else if(n.constructor===Object){if(n._stopResolving)return;for(const o in n)(n.component&&n._uid||n.type==="link")&&(this._insertRelations(n,o,t,s),this._insertLinks(n,o,s)),r(n[o])}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const n=e.link_uuids.length,o=[],l=50;for(let a=0;a<n;a+=l){const c=Math.min(n,a+l);o.push(e.link_uuids.slice(a,c))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:o[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.links;r.forEach(n=>{this.links[s][n.uuid]={...n,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const n=e.rel_uuids.length,o=[],l=50;for(let a=0;a<n;a+=l){const c=Math.min(n,a+l);o.push(e.rel_uuids.slice(a,c))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:o[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(c=>{r.push(c)})}else r=e.rels;r&&r.length>0&&r.forEach(n=>{this.relations[s][n.uuid]={...n,_stopResolving:!0}})}async resolveStories(e,t,s){var r,n;let o=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(o=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||(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],o,s);e.story?this.iterateTree(e.story,o,s):e.stories.forEach(l=>{this.iterateTree(l,o,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s,r){const n=this.helpers.stringify({url:e,params:t}),o=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!=="/cdn/spaces/me"){const l=await o.get(n);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 g=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(d.data,t,`${g}`)}return t.version==="published"&&e!=="/cdn/spaces/me"&&await o.set(n,d),d.data.cv&&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(A[e])},getAll(){return Promise.resolve(A)},set(e,t){return A[e]=t,Promise.resolve(void 0)},flush(){return A={},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.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 Oe(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 Ae(i,e){if(!e)return{src:i,attrs:{}};let t=0,s=0;const r={},n=[];function o(a,c,u,d,g){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)`):g.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:g,grayscale:w,quality:b,rotate:S}=a||{};c&&o(c,0,100,"blur",n),b&&o(b,0,100,"quality",n),u&&o(u,0,100,"brightness",n),d&&n.push(`fill(${d})`),w&&n.push("grayscale()"),S&&[0,90,180,270].includes(e.filters.rotate||0)&&n.push(`rotate(${S})`),g&&["webp","png","jpeg"].includes(g)&&n.push(`format(${g})`)}e.srcset&&(r.srcset=e.srcset.map(a=>{if(typeof a=="number")return`${i}/m/${a}x0/${n.length>0?`filters:${n.join(":")}`:""} ${a}w`;if(Array.isArray(a)&&a.length===2){const[c,u]=a;return`${i}/m/${c}x${u}/${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(", ")),e.sizes&&(r.sizes=e.sizes.join(", "))}let l=`${i}/m/`;return t>0&&s>0&&(l=`${l}${t}x${s}/`),n.length>0&&(l=`${l}filters:${n.join(":")}`),{src:l,attrs:r}}var k=(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))(k||{}),$=(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))($||{}),N=(i=>(i.TEXT="text",i))(N||{}),x=(i=>(i.URL="url",i.STORY="story",i.ASSET="asset",i.EMAIL="email",i))(x||{});const Ce=["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(" "),Ne=(i={})=>Object.keys(i).map(e=>`${e}: ${i[e]}`).join("; ");function Me(i){return i.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}const F=i=>Object.fromEntries(Object.entries(i).filter(([e,t])=>t!==void 0));function He(i,e={},t){const s=Pe(e),r=s?`${i} ${s}`:i;return Ce.includes(i)?`<${r}>`:`<${r}>${Array.isArray(t)?t.join(""):t||""}</${i}>`}function Ue(i={}){let e=0;const{renderFn:t=He,textFn:s=Me,resolvers:r={},optimizeImages:n=!1,keyedResolvers:o=!1}=i,l=h=>f=>{const m=f.attrs||{};return o&&(m.key=`${h}-${e}`),t(h,m,f.children||null)},a=h=>{const{src:f,alt:m,title:v,srcset:R,sizes:T}=h.attrs||{};let E=f,I={};if(n){const{src:Fe,attrs:Ve}=Ae(f,n);E=Fe,I=Ve}o&&(I={...I,key:`img-${e}`});const Ge={src:E,alt:m,title:v,srcset:R,sizes:T,...I};return t("img",F(Ge))},c=h=>{const{level:f,...m}=h.attrs||{},v={...m};return o&&(v.key=`h${f}-${e}`),t(`h${f}`,v,h.children)},u=h=>{var f,m,v,R;const T=t("img",{src:(f=h.attrs)==null?void 0:f.fallbackImage,alt:(m=h.attrs)==null?void 0:m.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"}),E={"data-type":"emoji","data-name":(v=h.attrs)==null?void 0:v.name,"data-emoji":(R=h.attrs)==null?void 0:R.emoji};return o&&(E.key=`emoji-${e}`),t("span",E,T)},d=h=>t("pre",{...h.attrs,key:`code-${e}`},t("code",{key:`code-${e}`},h.children||"")),g=(h,f=!1)=>({text:m,attrs:v})=>{const{class:R,id:T,...E}=v||{},I=f?{class:R,id:T,style:Ne(E)||void 0}:v||{};return o&&(I.key=`${h}-${e}`),t(h,F(I),m)},w=h=>U(h),b=h=>{const{marks:f,...m}=h;return"text"in h?f?f.reduce((v,R)=>w({...R,text:v}),w({...m,children:m.children})):s(m.text):""},S=h=>{const{linktype:f,href:m,anchor:v,...R}=h.attrs||{};let T="";switch(f){case x.ASSET:case x.URL:T=m;break;case x.EMAIL:T=`mailto:${m}`;break;case x.STORY:T=m;break}return v&&(T=`${T}#${v}`),t("a",{...R,href:T,key:`a-${e}`},h.text)},C=h=>{var f,m;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),t("span",{blok:(f=h==null?void 0:h.attrs)==null?void 0:f.body[0],id:(m=h.attrs)==null?void 0:m.id,key:`component-${e}`,style:"display: none"})},qe=new Map([[k.DOCUMENT,l("div")],[k.HEADING,c],[k.PARAGRAPH,l("p")],[k.UL_LIST,l("ul")],[k.OL_LIST,l("ol")],[k.LIST_ITEM,l("li")],[k.IMAGE,a],[k.EMOJI,u],[k.CODE_BLOCK,d],[k.HR,l("hr")],[k.BR,l("br")],[k.QUOTE,l("blockquote")],[k.COMPONENT,C],[N.TEXT,b],[$.LINK,S],[$.ANCHOR,S],[$.STYLED,g("span",!0)],[$.BOLD,g("strong")],[$.TEXT_STYLE,g("span",!0)],[$.ITALIC,g("em")],[$.UNDERLINE,g("u")],[$.STRIKE,g("s")],[$.CODE,g("code")],[$.SUPERSCRIPT,g("sup")],[$.SUBSCRIPT,g("sub")],[$.HIGHLIGHT,g("mark")],...Object.entries(r).map(([h,f])=>[h,f])]);function Y(h){e+=1;const f=qe.get(h.type);if(!f)return console.error("<Storyblok>",`No resolver found for node type ${h.type}`),"";if(h.type==="text")return f(h);const m=h.content?h.content.map(U):void 0;return f({...h,children:m})}function U(h){return Array.isArray(h)?h.map(Y):Y(h)}return{render:U}}let M,H="https://app.storyblok.com/f/storyblok-v2-latest.js";const V=(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")===i;if(!(!r||!o)){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=>{c.action==="input"&&c.story.id===i?e(c.story):(c.action==="change"||c.action==="published")&&c.storyId===i&&window.location.reload()})})}},ze=(i={})=>{var d,g;const{bridge:e,accessToken:t,use:s=[],apiOptions:r={},richText:n={},bridgeUrl:o}=i;r.accessToken=r.accessToken||t;const l={bridge:e,apiOptions:r};let a={};s.forEach(w=>{a={...a,...w(l)}}),o&&(H=o);const u=!(typeof window>"u")&&((g=(d=window.location)==null?void 0:d.search)==null?void 0:g.includes("_storyblok_tk"));return e!==!1&&u&&B(H),M=new O(n.schema),n.resolver&&J(M,n.resolver),a},J=(i,e)=>{i.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},K=i=>!i||!(i!=null&&i.content.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule")),Be=(i,e,t)=>{let s=t||M;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return K(i)?"":(e&&(s=new O(e.schema),e.resolver&&J(s,e.resolver)),s.render(i,{},!1))},De=()=>B(H);y.BlockTypes=k,y.MarkTypes=$,y.RichTextResolver=O,y.RichTextSchema=D,y.TextTypes=N,y.apiPlugin=xe,y.isRichTextEmpty=K,y.loadStoryblokBridge=De,y.registerStoryblokBridge=V,y.renderRichText=Be,y.richTextResolver=Ue,y.storyblokEditable=Le,y.storyblokInit=ze,y.useStoryblokBridge=V,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
@@ -1,5 +1,5 @@
1
1
  let H = !1;
2
- const U = [], G = (i) => new Promise((e, t) => {
2
+ const U = [], q = (i) => new Promise((e, t) => {
3
3
  if (typeof window > "u" || (window.storyblokRegisterEvent = (r) => {
4
4
  if (window.location === window.parent.location) {
5
5
  console.warn("You are not in Draft Mode or in the Visual Editor.");
@@ -12,72 +12,73 @@ const U = [], G = (i) => new Promise((e, t) => {
12
12
  U.forEach((n) => n()), H = !0, e(r);
13
13
  }, document.getElementsByTagName("head")[0].appendChild(s);
14
14
  });
15
- var W = Object.defineProperty, Q = (i, e, t) => e in i ? W(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, d = (i, e, t) => Q(i, typeof e != "symbol" ? e + "" : e, t);
16
- function z(i) {
17
- return !(i !== i || i === 1 / 0 || i === -1 / 0);
15
+ var X = Object.defineProperty, W = (i, e, t) => e in i ? X(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, p = (i, e, t) => W(i, typeof e != "symbol" ? e + "" : e, t);
16
+ class Q extends Error {
17
+ constructor(e) {
18
+ super(e), this.name = "AbortError";
19
+ }
18
20
  }
19
21
  function Z(i, e, t) {
20
- if (!z(e))
22
+ if (!Number.isFinite(e))
21
23
  throw new TypeError("Expected `limit` to be a finite number");
22
- if (!z(t))
24
+ if (!Number.isFinite(t))
23
25
  throw new TypeError("Expected `interval` to be a finite number");
24
26
  const s = [];
25
- let r = [], n = 0;
26
- const o = function() {
27
+ let r = [], n = 0, o = !1;
28
+ const l = async () => {
27
29
  n++;
28
- const a = setTimeout(function() {
29
- n--, s.length > 0 && o(), r = r.filter(function(u) {
30
- return u !== a;
31
- });
32
- }, t);
33
- r.indexOf(a) < 0 && r.push(a);
34
30
  const c = s.shift();
35
- c.resolve(i.apply(c.self, c.args));
36
- }, l = function(...a) {
37
- const c = this;
38
- return new Promise(function(u, p) {
39
- s.push({
40
- resolve: u,
41
- reject: p,
42
- args: a,
43
- self: c
44
- }), n < e && o();
45
- });
46
- };
47
- return l.abort = function() {
48
- r.forEach(clearTimeout), r = [], s.forEach(function(a) {
49
- a.reject(function() {
50
- Error.call(this, "Throttled function aborted"), this.name = "AbortError";
51
- });
52
- }), s.length = 0;
53
- }, l;
31
+ if (c) {
32
+ const d = await i(...c.args);
33
+ c.resolve(d);
34
+ }
35
+ const u = setTimeout(() => {
36
+ n--, s.length > 0 && l(), r = r.filter((d) => d !== u);
37
+ }, t);
38
+ r.includes(u) || r.push(u);
39
+ }, a = (...c) => o ? Promise.reject(
40
+ new Error(
41
+ "Throttled function is already aborted and not accepting new promises"
42
+ )
43
+ ) : new Promise((u, d) => {
44
+ s.push({
45
+ resolve: u,
46
+ reject: d,
47
+ args: c
48
+ }), n < e && l();
49
+ });
50
+ return a.abort = () => {
51
+ o = !0, r.forEach(clearTimeout), r = [], s.forEach(
52
+ (c) => c.reject(() => new Q("Throttle function aborted"))
53
+ ), s.length = 0;
54
+ }, a;
54
55
  }
55
56
  let O = class {
56
57
  constructor() {
57
- d(this, "isCDNUrl", (e = "") => e.indexOf("/cdn/") > -1), d(this, "getOptionsPage", (e, t = 25, s = 1) => ({
58
+ p(this, "isCDNUrl", (e = "") => e.includes("/cdn/")), p(this, "getOptionsPage", (e, t = 25, s = 1) => ({
58
59
  ...e,
59
60
  per_page: t,
60
61
  page: s
61
- })), d(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), d(this, "arrayFrom", (e = 0, t) => [...Array(e)].map(t)), d(this, "range", (e = 0, t = e) => {
62
+ })), 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) => {
62
63
  const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
63
64
  return this.arrayFrom(s, (n, o) => o * r + e);
64
- }), d(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), d(this, "flatMap", (e = [], t) => e.map(t).reduce((s, r) => [...s, ...r], [])), d(this, "escapeHTML", function(e) {
65
+ }), 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) {
65
66
  const t = {
66
67
  "&": "&amp;",
67
68
  "<": "&lt;",
68
69
  ">": "&gt;",
69
70
  '"': "&quot;",
70
71
  "'": "&#39;"
71
- }, s = /[&<>"']/g, r = RegExp(s.source);
72
+ }, s = /[&<>"']/g, r = new RegExp(s.source);
72
73
  return e && r.test(e) ? e.replace(s, (n) => t[n]) : e;
73
74
  });
74
75
  }
75
76
  /**
76
77
  * @method stringify
77
- * @param {Object} params
78
- * @param {String} prefix
79
- * @param {Boolean} isArray
80
- * @return {String} Stringified object
78
+ * @param {object} params
79
+ * @param {string} prefix
80
+ * @param {boolean} isArray
81
+ * @return {string} Stringified object
81
82
  */
82
83
  stringify(e, t, s) {
83
84
  const r = [];
@@ -88,16 +89,16 @@ let O = class {
88
89
  let a;
89
90
  typeof o == "object" ? a = this.stringify(
90
91
  o,
91
- t ? t + encodeURIComponent("[" + l + "]") : l,
92
+ t ? t + encodeURIComponent(`[${l}]`) : l,
92
93
  Array.isArray(o)
93
- ) : a = (t ? t + encodeURIComponent("[" + l + "]") : l) + "=" + encodeURIComponent(o), r.push(a);
94
+ ) : a = `${t ? t + encodeURIComponent(`[${l}]`) : l}=${encodeURIComponent(o)}`, r.push(a);
94
95
  }
95
96
  return r.join("&");
96
97
  }
97
98
  /**
98
99
  * @method getRegionURL
99
- * @param {String} regionCode region code, could be eu, us, cn, ap or ca
100
- * @return {String} The base URL of the region
100
+ * @param {string} regionCode region code, could be eu, us, cn, ap or ca
101
+ * @return {string} The base URL of the region
101
102
  */
102
103
  getRegionURL(e) {
103
104
  const t = "api.storyblok.com", s = "api-us.storyblok.com", r = "app.storyblokchina.cn", n = "api-ap.storyblok.com", o = "api-ca.storyblok.com";
@@ -119,7 +120,7 @@ const ee = function(i, e) {
119
120
  const t = {};
120
121
  for (const s in i) {
121
122
  const r = i[s];
122
- e.indexOf(s) > -1 && r !== null && (t[s] = r);
123
+ e.includes(s) && r !== null && (t[s] = r);
123
124
  }
124
125
  return t;
125
126
  }, te = (i) => i === "email", se = () => ({
@@ -206,14 +207,14 @@ const ee = function(i, e) {
206
207
  tag: "sub"
207
208
  }), Te = () => ({
208
209
  tag: "sup"
209
- }), Re = (i) => ({
210
+ }), we = (i) => ({
210
211
  tag: [
211
212
  {
212
213
  tag: "span",
213
214
  attrs: i.attrs
214
215
  }
215
216
  ]
216
- }), we = (i) => {
217
+ }), Re = (i) => {
217
218
  var e;
218
219
  return (e = i.attrs) != null && e.color ? {
219
220
  tag: [
@@ -266,8 +267,8 @@ const ee = function(i, e) {
266
267
  styled: ve,
267
268
  subscript: $e,
268
269
  superscript: Te,
269
- anchor: Re,
270
- highlight: we,
270
+ anchor: we,
271
+ highlight: Re,
271
272
  textStyle: Se
272
273
  }
273
274
  }, Ee = function(i) {
@@ -277,13 +278,13 @@ const ee = function(i, e) {
277
278
  ">": "&gt;",
278
279
  '"': "&quot;",
279
280
  "'": "&#39;"
280
- }, t = /[&<>"']/g, s = RegExp(t.source);
281
+ }, t = /[&<>"']/g, s = new RegExp(t.source);
281
282
  return i && s.test(i) ? i.replace(t, (r) => e[r]) : i;
282
283
  };
283
- let B = !1;
284
+ let z = !1;
284
285
  class Ie {
285
286
  constructor(e) {
286
- d(this, "marks"), d(this, "nodes"), e || (e = _e), this.marks = e.marks || [], this.nodes = e.nodes || [];
287
+ p(this, "marks"), p(this, "nodes"), e || (e = _e), this.marks = e.marks || [], this.nodes = e.nodes || [];
287
288
  }
288
289
  addNode(e, t) {
289
290
  this.nodes[e] = t;
@@ -292,9 +293,9 @@ class Ie {
292
293
  this.marks[e] = t;
293
294
  }
294
295
  render(e, t = { optimizeImages: !1 }, s = !0) {
295
- if (!B && s && (console.warn(
296
+ if (!z && s && (console.warn(
296
297
  "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/"
297
- ), B = !0), e && e.content && Array.isArray(e.content)) {
298
+ ), z = !0), e && e.content && Array.isArray(e.content)) {
298
299
  let r = "";
299
300
  return e.content.forEach((n) => {
300
301
  r += this.renderNode(n);
@@ -302,57 +303,58 @@ class Ie {
302
303
  }
303
304
  return console.warn(
304
305
  `The render method must receive an Object with a "content" field.
305
- The "content" field must be an array of nodes as the type ISbRichtext.
306
- ISbRichtext:
307
- content?: ISbRichtext[]
308
- marks?: ISbRichtext[]
309
- attrs?: any
310
- text?: string
311
- type: string
312
-
313
- Example:
314
- {
315
- content: [
316
- {
317
- content: [
318
- {
319
- text: 'Hello World',
320
- type: 'text'
321
- }
322
- ],
323
- type: 'paragraph'
324
- }
325
- ],
326
- type: 'doc'
327
- }`
306
+ The "content" field must be an array of nodes as the type ISbRichtext.
307
+ ISbRichtext:
308
+ content?: ISbRichtext[]
309
+ marks?: ISbRichtext[]
310
+ attrs?: any
311
+ text?: string
312
+ type: string
313
+
314
+ Example:
315
+ {
316
+ content: [
317
+ {
318
+ content: [
319
+ {
320
+ text: 'Hello World',
321
+ type: 'text'
322
+ }
323
+ ],
324
+ type: 'paragraph'
325
+ }
326
+ ],
327
+ type: 'doc'
328
+ }`
328
329
  ), "";
329
330
  }
330
331
  optimizeImages(e, t) {
331
332
  let s = 0, r = 0, n = "", o = "";
332
- typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (n += `width="${t.width}" `, s = t.width), typeof t.height == "number" && t.height > 0 && (n += `height="${t.height}" `, r = t.height), (t.loading === "lazy" || t.loading === "eager") && (n += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (n += `class="${t.class}" `), t.filters && (typeof t.filters.blur == "number" && t.filters.blur >= 0 && t.filters.blur <= 100 && (o += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (o += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-Fa-f]{6}/g) || t.filters.fill === "transparent") && (o += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (o += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (o += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (o += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (o += `:rotate(${t.filters.rotate})`), o.length > 0 && (o = "/filters" + o))), n.length > 0 && (e = e.replace(/<img/g, `<img ${n.trim()}`));
333
+ typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (n += `width="${t.width}" `, s = t.width), typeof t.height == "number" && t.height > 0 && (n += `height="${t.height}" `, r = t.height), (t.loading === "lazy" || t.loading === "eager") && (n += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (n += `class="${t.class}" `), t.filters && (typeof t.filters.blur == "number" && t.filters.blur >= 0 && t.filters.blur <= 100 && (o += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (o += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-F]{6}/gi) || t.filters.fill === "transparent") && (o += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (o += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (o += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (o += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (o += `:rotate(${t.filters.rotate})`), o.length > 0 && (o = `/filters${o}`))), n.length > 0 && (e = e.replace(/<img/g, `<img ${n.trim()}`));
333
334
  const l = s > 0 || r > 0 || o.length > 0 ? `${s}x${r}${o}` : "";
334
335
  return e = e.replace(
335
- /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,
336
+ /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,
336
337
  `a.storyblok.com/f/$1/$2.$3/m/${l}`
337
338
  ), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (a) => {
338
339
  var c, u;
339
- const p = a.match(
340
- /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g
340
+ const d = a.match(
341
+ /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g
341
342
  );
342
- if (p && p.length > 0) {
343
+ if (d && d.length > 0) {
343
344
  const g = {
344
345
  srcset: (c = t.srcset) == null ? void 0 : c.map((y) => {
345
346
  if (typeof y == "number")
346
- return `//${p}/m/${y}x0${o} ${y}w`;
347
+ return `//${d}/m/${y}x0${o} ${y}w`;
347
348
  if (typeof y == "object" && y.length === 2) {
348
- let w = 0, j = 0;
349
- return typeof y[0] == "number" && (w = y[0]), typeof y[1] == "number" && (j = y[1]), `//${p}/m/${w}x${j}${o} ${w}w`;
349
+ let R = 0, j = 0;
350
+ return typeof y[0] == "number" && (R = y[0]), typeof y[1] == "number" && (j = y[1]), `//${d}/m/${R}x${j}${o} ${R}w`;
350
351
  }
352
+ return "";
351
353
  }).join(", "),
352
354
  sizes: (u = t.sizes) == null ? void 0 : u.map((y) => y).join(", ")
353
355
  };
354
- let k = "";
355
- return g.srcset && (k += `srcset="${g.srcset}" `), g.sizes && (k += `sizes="${g.sizes}" `), a.replace(/<img/g, `<img ${k.trim()}`);
356
+ let T = "";
357
+ return g.srcset && (T += `srcset="${g.srcset}" `), g.sizes && (T += `sizes="${g.sizes}" `), a.replace(/<img/g, `<img ${T.trim()}`);
356
358
  }
357
359
  return a;
358
360
  })), e;
@@ -424,7 +426,7 @@ class Ie {
424
426
  const L = Ie;
425
427
  class je {
426
428
  constructor(e) {
427
- d(this, "baseURL"), d(this, "timeout"), d(this, "headers"), d(this, "responseInterceptor"), d(this, "fetch"), d(this, "ejectInterceptor"), d(this, "url"), d(this, "parameters"), d(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 = {};
429
+ 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 = {};
428
430
  }
429
431
  /**
430
432
  *
@@ -509,7 +511,7 @@ class je {
509
511
  });
510
512
  }
511
513
  }
512
- const xe = je, D = "SB-Agent", C = {
514
+ const xe = je, B = "SB-Agent", C = {
513
515
  defaultAgentName: "SB-JS-CLIENT",
514
516
  defaultAgentVersion: "SB-Agent-Version",
515
517
  packageVersion: "6.0.0"
@@ -520,10 +522,10 @@ class Oe {
520
522
  /**
521
523
  *
522
524
  * @param config ISbConfig interface
523
- * @param endpoint string, optional
525
+ * @param pEndpoint string, optional
524
526
  */
525
527
  constructor(e, t) {
526
- d(this, "client"), d(this, "maxRetries"), d(this, "retriesDelay"), d(this, "throttle"), d(this, "accessToken"), d(this, "cache"), d(this, "helpers"), d(this, "resolveCounter"), d(this, "relations"), d(this, "links"), d(this, "richTextResolver"), d(this, "resolveNestedRelations"), d(this, "stringifiedStoriesCache");
528
+ 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");
527
529
  let s = e.endpoint || t;
528
530
  if (!s) {
529
531
  const o = new O().getRegionURL, l = e.https === !1 ? "http" : "https";
@@ -532,12 +534,16 @@ class Oe {
532
534
  const r = new Headers();
533
535
  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(([o, l]) => {
534
536
  r.set(o, l);
535
- }), r.has(D) || (r.set(D, C.defaultAgentName), r.set(
537
+ }), r.has(B) || (r.set(B, C.defaultAgentName), r.set(
536
538
  C.defaultAgentVersion,
537
539
  C.packageVersion
538
540
  ));
539
541
  let n = 5;
540
- e.oauthToken && (r.set("Authorization", e.oauthToken), n = 3), e.rateLimit && (n = e.rateLimit), e.richTextSchema ? this.richTextResolver = new L(e.richTextSchema) : this.richTextResolver = new L(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = Z(this.throttledRequest, n, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new O(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new xe({
542
+ e.oauthToken && (r.set("Authorization", e.oauthToken), n = 3), e.rateLimit && (n = e.rateLimit), e.richTextSchema ? this.richTextResolver = new L(e.richTextSchema) : this.richTextResolver = new L(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = Z(
543
+ this.throttledRequest.bind(this),
544
+ n,
545
+ 1e3
546
+ ), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new O(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new xe({
541
547
  baseURL: s,
542
548
  timeout: e.timeout || 0,
543
549
  headers: r,
@@ -574,32 +580,35 @@ class Oe {
574
580
  return this.cacheResponse(r, n, void 0, s);
575
581
  }
576
582
  async getAll(e, t, s, r) {
577
- const n = (t == null ? void 0 : t.per_page) || 25, o = `/${e}`, l = o.split("/"), a = s || l[l.length - 1], c = 1, u = await this.makeRequest(
583
+ const n = (t == null ? void 0 : t.per_page) || 25, o = `/${e}`.replace(/\/$/, ""), l = s ?? o.substring(o.lastIndexOf("/") + 1), a = 1, c = await this.makeRequest(
578
584
  o,
579
585
  t,
580
586
  n,
581
- c,
587
+ a,
582
588
  r
583
- ), p = u.total ? Math.ceil(u.total / n) : 1, g = await this.helpers.asyncMap(
584
- this.helpers.range(c, p),
585
- (k) => this.makeRequest(o, t, n, k + 1, r)
586
- );
587
- return this.helpers.flatMap(
588
- [u, ...g],
589
- (k) => Object.values(k.data[a])
589
+ ), u = c.total ? Math.ceil(c.total / n) : 1, d = await this.helpers.asyncMap(
590
+ this.helpers.range(a, u),
591
+ (g) => this.makeRequest(o, t, n, g + 1, r)
590
592
  );
593
+ return this.helpers.flatMap([c, ...d], (g) => Object.values(g.data[l]));
591
594
  }
592
595
  post(e, t, s) {
593
596
  const r = `/${e}`;
594
- return Promise.resolve(this.throttle("post", r, t, s));
597
+ return Promise.resolve(
598
+ this.throttle("post", r, t, s)
599
+ );
595
600
  }
596
601
  put(e, t, s) {
597
602
  const r = `/${e}`;
598
- return Promise.resolve(this.throttle("put", r, t, s));
603
+ return Promise.resolve(
604
+ this.throttle("put", r, t, s)
605
+ );
599
606
  }
600
607
  delete(e, t, s) {
601
608
  const r = `/${e}`;
602
- return Promise.resolve(this.throttle("delete", r, t, s));
609
+ return Promise.resolve(
610
+ this.throttle("delete", r, t, s)
611
+ );
603
612
  }
604
613
  getStories(e, t) {
605
614
  return this._addResolveLevel(e), this.get("cdn/stories", e, t);
@@ -621,7 +630,7 @@ class Oe {
621
630
  }
622
631
  _insertLinks(e, t, s) {
623
632
  const r = e[t];
624
- 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]));
633
+ 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]));
625
634
  }
626
635
  /**
627
636
  *
@@ -635,7 +644,7 @@ class Oe {
635
644
  )), JSON.parse(this.stringifiedStoriesCache[t])) : t;
636
645
  }
637
646
  _insertRelations(e, t, s, r) {
638
- s.indexOf(`${e.component}.${t}`) > -1 && (typeof e[t] == "string" ? e[t] = this.getStoryReference(r, e[t]) : Array.isArray(e[t]) && (e[t] = e[t].map((n) => this.getStoryReference(r, n)).filter(Boolean)));
647
+ s.includes(`${e.component}.${t}`) && (typeof e[t] == "string" ? e[t] = this.getStoryReference(r, e[t]) : Array.isArray(e[t]) && (e[t] = e[t].map((n) => this.getStoryReference(r, n)).filter(Boolean)));
639
648
  }
640
649
  iterateTree(e, t, s) {
641
650
  const r = (n) => {
@@ -729,7 +738,7 @@ class Oe {
729
738
  async resolveStories(e, t, s) {
730
739
  var r, n;
731
740
  let o = [];
732
- if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (o = t.resolve_relations.split(",")), await this.resolveRelations(e, t, s)), t.resolve_links && ["1", "story", "url", "link"].indexOf(t.resolve_links) > -1 && ((r = e.links) != null && r.length || (n = e.link_uuids) != null && n.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
741
+ if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (o = 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 || (n = e.link_uuids) != null && n.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
733
742
  for (const l in this.relations[s])
734
743
  this.iterateTree(
735
744
  this.relations[s][l],
@@ -742,7 +751,7 @@ class Oe {
742
751
  }
743
752
  async cacheResponse(e, t, s, r) {
744
753
  const n = this.helpers.stringify({ url: e, params: t }), o = this.cacheProvider();
745
- if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
754
+ if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e !== "/cdn/spaces/me") {
746
755
  const l = await o.get(n);
747
756
  if (l)
748
757
  return Promise.resolve(l);
@@ -750,18 +759,23 @@ class Oe {
750
759
  return new Promise(async (l, a) => {
751
760
  var c;
752
761
  try {
753
- const u = await this.throttle("get", e, t, r);
762
+ const u = await this.throttle(
763
+ "get",
764
+ e,
765
+ t,
766
+ r
767
+ );
754
768
  if (u.status !== 200)
755
769
  return a(u);
756
- let p = { data: u.data, headers: u.headers };
757
- if ((c = u.headers) != null && c["per-page"] && (p = Object.assign({}, p, {
758
- perPage: u.headers["per-page"] ? parseInt(u.headers["per-page"]) : 0,
759
- total: u.headers["per-page"] ? parseInt(u.headers.total) : 0
760
- })), p.data.story || p.data.stories) {
770
+ let d = { data: u.data, headers: u.headers };
771
+ if ((c = u.headers) != null && c["per-page"] && (d = Object.assign({}, d, {
772
+ perPage: u.headers["per-page"] ? Number.parseInt(u.headers["per-page"]) : 0,
773
+ total: u.headers["per-page"] ? Number.parseInt(u.headers.total) : 0
774
+ })), d.data.story || d.data.stories) {
761
775
  const g = this.resolveCounter = ++this.resolveCounter % 1e3;
762
- await this.resolveStories(p.data, t, `${g}`);
776
+ await this.resolveStories(d.data, t, `${g}`);
763
777
  }
764
- return t.version === "published" && e != "/cdn/spaces/me" && await o.set(n, p), p.data.cv && t.token && E[t.token] != p.data.cv && (await this.flushCache(), E[t.token] = p.data.cv), l(p);
778
+ return t.version === "published" && e !== "/cdn/spaces/me" && await o.set(n, d), d.data.cv && t.token && E[t.token] !== d.data.cv && (await this.flushCache(), E[t.token] = d.data.cv), l(d);
765
779
  } catch (u) {
766
780
  if (u.response && u.status === 429 && (s = typeof s > "u" ? 0 : s + 1, s < this.maxRetries))
767
781
  return console.log(
@@ -804,7 +818,8 @@ class Oe {
804
818
  }
805
819
  };
806
820
  case "custom":
807
- if (this.cache.custom) return this.cache.custom;
821
+ if (this.cache.custom)
822
+ return this.cache.custom;
808
823
  default:
809
824
  return {
810
825
  get() {
@@ -855,13 +870,13 @@ function Le(i, e) {
855
870
  return { src: i, attrs: {} };
856
871
  let t = 0, s = 0;
857
872
  const r = {}, n = [];
858
- function o(a, c, u, p, g) {
859
- typeof a != "number" || a <= c || a >= u ? console.warn(`[StoryblokRichText] - ${p.charAt(0).toUpperCase() + p.slice(1)} value must be a number between ${c} and ${u} (inclusive)`) : g.push(`${p}(${a})`);
873
+ function o(a, c, u, d, g) {
874
+ 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)`) : g.push(`${d}(${a})`);
860
875
  }
861
876
  if (typeof e == "object") {
862
877
  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) {
863
- const { filters: a } = e || {}, { blur: c, brightness: u, fill: p, format: g, grayscale: k, quality: y, rotate: w } = a || {};
864
- c && o(c, 0, 100, "blur", n), y && o(y, 0, 100, "quality", n), u && o(u, 0, 100, "brightness", n), p && n.push(`fill(${p})`), k && n.push("grayscale()"), w && [0, 90, 180, 270].includes(e.filters.rotate || 0) && n.push(`rotate(${w})`), g && ["webp", "png", "jpeg"].includes(g) && n.push(`format(${g})`);
878
+ const { filters: a } = e || {}, { blur: c, brightness: u, fill: d, format: g, grayscale: T, quality: y, rotate: R } = a || {};
879
+ c && o(c, 0, 100, "blur", n), y && o(y, 0, 100, "quality", n), u && o(u, 0, 100, "brightness", n), d && n.push(`fill(${d})`), T && n.push("grayscale()"), R && [0, 90, 180, 270].includes(e.filters.rotate || 0) && n.push(`rotate(${R})`), g && ["webp", "png", "jpeg"].includes(g) && n.push(`format(${g})`);
865
880
  }
866
881
  e.srcset && (r.srcset = e.srcset.map((a) => {
867
882
  if (typeof a == "number")
@@ -881,7 +896,7 @@ function Le(i, e) {
881
896
  attrs: r
882
897
  };
883
898
  }
884
- var v = /* @__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))(v || {}), $ = /* @__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))($ || {}), V = /* @__PURE__ */ ((i) => (i.TEXT = "text", i))(V || {}), I = /* @__PURE__ */ ((i) => (i.URL = "url", i.STORY = "story", i.ASSET = "asset", i.EMAIL = "email", i))(I || {});
899
+ var k = /* @__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))(k || {}), v = /* @__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))(v || {}), 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 || {});
885
900
  const Ae = [
886
901
  "area",
887
902
  "base",
@@ -901,7 +916,7 @@ const Ae = [
901
916
  function Ne(i) {
902
917
  return i.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
903
918
  }
904
- const q = (i) => Object.fromEntries(Object.entries(i).filter(([e, t]) => t !== void 0));
919
+ const D = (i) => Object.fromEntries(Object.entries(i).filter(([e, t]) => t !== void 0));
905
920
  function Me(i, e = {}, t) {
906
921
  const s = Ce(e), r = s ? `${i} ${s}` : i;
907
922
  return Ae.includes(i) ? `<${r}>` : `<${r}>${Array.isArray(t) ? t.join("") : t || ""}</${i}>`;
@@ -918,33 +933,33 @@ function De(i = {}) {
918
933
  const m = f.attrs || {};
919
934
  return o && (m.key = `${h}-${e}`), t(h, m, f.children || null);
920
935
  }, a = (h) => {
921
- const { src: f, alt: m, title: b, srcset: R, sizes: T } = h.attrs || {};
936
+ const { src: f, alt: m, title: b, srcset: w, sizes: $ } = h.attrs || {};
922
937
  let S = f, _ = {};
923
938
  if (n) {
924
- const { src: Y, attrs: X } = Le(f, n);
925
- S = Y, _ = X;
939
+ const { src: K, attrs: Y } = Le(f, n);
940
+ S = K, _ = Y;
926
941
  }
927
942
  o && (_ = {
928
943
  ..._,
929
944
  key: `img-${e}`
930
945
  });
931
- const K = {
946
+ const J = {
932
947
  src: S,
933
948
  alt: m,
934
949
  title: b,
935
- srcset: R,
936
- sizes: T,
950
+ srcset: w,
951
+ sizes: $,
937
952
  ..._
938
953
  };
939
- return t("img", q(K));
954
+ return t("img", D(J));
940
955
  }, c = (h) => {
941
956
  const { level: f, ...m } = h.attrs || {}, b = {
942
957
  ...m
943
958
  };
944
959
  return o && (b.key = `h${f}-${e}`), t(`h${f}`, b, h.children);
945
960
  }, u = (h) => {
946
- var f, m, b, R;
947
- const T = t("img", {
961
+ var f, m, b, w;
962
+ const $ = t("img", {
948
963
  src: (f = h.attrs) == null ? void 0 : f.fallbackImage,
949
964
  alt: (m = h.attrs) == null ? void 0 : m.alt,
950
965
  style: "width: 1.25em; height: 1.25em; vertical-align: text-top",
@@ -953,43 +968,43 @@ function De(i = {}) {
953
968
  }), S = {
954
969
  "data-type": "emoji",
955
970
  "data-name": (b = h.attrs) == null ? void 0 : b.name,
956
- "data-emoji": (R = h.attrs) == null ? void 0 : R.emoji
971
+ "data-emoji": (w = h.attrs) == null ? void 0 : w.emoji
957
972
  };
958
- return o && (S.key = `emoji-${e}`), t("span", S, T);
959
- }, p = (h) => t("pre", {
973
+ return o && (S.key = `emoji-${e}`), t("span", S, $);
974
+ }, d = (h) => t("pre", {
960
975
  ...h.attrs,
961
976
  key: `code-${e}`
962
977
  }, t("code", { key: `code-${e}` }, h.children || "")), g = (h, f = !1) => ({ text: m, attrs: b }) => {
963
- const { class: R, id: T, ...S } = b || {}, _ = f ? {
964
- class: R,
965
- id: T,
978
+ const { class: w, id: $, ...S } = b || {}, _ = f ? {
979
+ class: w,
980
+ id: $,
966
981
  style: Pe(S) || void 0
967
982
  } : b || {};
968
- return o && (_.key = `${h}-${e}`), t(h, q(_), m);
969
- }, k = (h) => A(h), y = (h) => {
983
+ return o && (_.key = `${h}-${e}`), t(h, D(_), m);
984
+ }, T = (h) => A(h), y = (h) => {
970
985
  const { marks: f, ...m } = h;
971
986
  return "text" in h ? f ? f.reduce(
972
- (b, R) => k({ ...R, text: b }),
987
+ (b, w) => T({ ...w, text: b }),
973
988
  // Fix: Ensure render function returns a string
974
- k({ ...m, children: m.children })
989
+ T({ ...m, children: m.children })
975
990
  // Fix: Cast children to string
976
991
  ) : s(m.text) : "";
977
- }, w = (h) => {
978
- const { linktype: f, href: m, anchor: b, ...R } = h.attrs || {};
979
- let T = "";
992
+ }, R = (h) => {
993
+ const { linktype: f, href: m, anchor: b, ...w } = h.attrs || {};
994
+ let $ = "";
980
995
  switch (f) {
981
996
  case I.ASSET:
982
997
  case I.URL:
983
- T = m;
998
+ $ = m;
984
999
  break;
985
1000
  case I.EMAIL:
986
- T = `mailto:${m}`;
1001
+ $ = `mailto:${m}`;
987
1002
  break;
988
1003
  case I.STORY:
989
- T = m;
1004
+ $ = m;
990
1005
  break;
991
1006
  }
992
- return b && (T = `${T}#${b}`), t("a", { ...R, href: T, key: `a-${e}` }, h.text);
1007
+ return b && ($ = `${$}#${b}`), t("a", { ...w, href: $, key: `a-${e}` }, h.text);
993
1008
  }, j = (h) => {
994
1009
  var f, m;
995
1010
  return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), t("span", {
@@ -998,38 +1013,38 @@ function De(i = {}) {
998
1013
  key: `component-${e}`,
999
1014
  style: "display: none"
1000
1015
  });
1001
- }, F = new Map([
1002
- [v.DOCUMENT, l("div")],
1003
- [v.HEADING, c],
1004
- [v.PARAGRAPH, l("p")],
1005
- [v.UL_LIST, l("ul")],
1006
- [v.OL_LIST, l("ol")],
1007
- [v.LIST_ITEM, l("li")],
1008
- [v.IMAGE, a],
1009
- [v.EMOJI, u],
1010
- [v.CODE_BLOCK, p],
1011
- [v.HR, l("hr")],
1012
- [v.BR, l("br")],
1013
- [v.QUOTE, l("blockquote")],
1014
- [v.COMPONENT, j],
1015
- [V.TEXT, y],
1016
- [$.LINK, w],
1017
- [$.ANCHOR, w],
1018
- [$.STYLED, g("span", !0)],
1019
- [$.BOLD, g("strong")],
1020
- [$.TEXT_STYLE, g("span", !0)],
1021
- [$.ITALIC, g("em")],
1022
- [$.UNDERLINE, g("u")],
1023
- [$.STRIKE, g("s")],
1024
- [$.CODE, g("code")],
1025
- [$.SUPERSCRIPT, g("sup")],
1026
- [$.SUBSCRIPT, g("sub")],
1027
- [$.HIGHLIGHT, g("mark")],
1016
+ }, V = new Map([
1017
+ [k.DOCUMENT, l("div")],
1018
+ [k.HEADING, c],
1019
+ [k.PARAGRAPH, l("p")],
1020
+ [k.UL_LIST, l("ul")],
1021
+ [k.OL_LIST, l("ol")],
1022
+ [k.LIST_ITEM, l("li")],
1023
+ [k.IMAGE, a],
1024
+ [k.EMOJI, u],
1025
+ [k.CODE_BLOCK, d],
1026
+ [k.HR, l("hr")],
1027
+ [k.BR, l("br")],
1028
+ [k.QUOTE, l("blockquote")],
1029
+ [k.COMPONENT, j],
1030
+ [G.TEXT, y],
1031
+ [v.LINK, R],
1032
+ [v.ANCHOR, R],
1033
+ [v.STYLED, g("span", !0)],
1034
+ [v.BOLD, g("strong")],
1035
+ [v.TEXT_STYLE, g("span", !0)],
1036
+ [v.ITALIC, g("em")],
1037
+ [v.UNDERLINE, g("u")],
1038
+ [v.STRIKE, g("s")],
1039
+ [v.CODE, g("code")],
1040
+ [v.SUPERSCRIPT, g("sup")],
1041
+ [v.SUBSCRIPT, g("sub")],
1042
+ [v.HIGHLIGHT, g("mark")],
1028
1043
  ...Object.entries(r).map(([h, f]) => [h, f])
1029
1044
  ]);
1030
1045
  function M(h) {
1031
1046
  e += 1;
1032
- const f = F.get(h.type);
1047
+ const f = V.get(h.type);
1033
1048
  if (!f)
1034
1049
  return console.error("<Storyblok>", `No resolver found for node type ${h.type}`), "";
1035
1050
  if (h.type === "text")
@@ -1066,7 +1081,7 @@ const qe = (i, e, t = {}) => {
1066
1081
  });
1067
1082
  }
1068
1083
  }, Ge = (i = {}) => {
1069
- var p, g;
1084
+ var d, g;
1070
1085
  const {
1071
1086
  bridge: e,
1072
1087
  accessToken: t,
@@ -1078,12 +1093,12 @@ const qe = (i, e, t = {}) => {
1078
1093
  r.accessToken = r.accessToken || t;
1079
1094
  const l = { bridge: e, apiOptions: r };
1080
1095
  let a = {};
1081
- s.forEach((k) => {
1082
- a = { ...a, ...k(l) };
1096
+ s.forEach((T) => {
1097
+ a = { ...a, ...T(l) };
1083
1098
  }), o && (N = o);
1084
- const u = !(typeof window > "u") && ((g = (p = window.location) == null ? void 0 : p.search) == null ? void 0 : g.includes("_storyblok_tk"));
1085
- return e !== !1 && u && G(N), P = new L(n.schema), n.resolver && J(P, n.resolver), a;
1086
- }, J = (i, e) => {
1099
+ const u = !(typeof window > "u") && ((g = (d = window.location) == null ? void 0 : d.search) == null ? void 0 : g.includes("_storyblok_tk"));
1100
+ return e !== !1 && u && q(N), P = new L(n.schema), n.resolver && F(P, n.resolver), a;
1101
+ }, F = (i, e) => {
1087
1102
  i.addNode("blok", (t) => {
1088
1103
  let s = "";
1089
1104
  return t.attrs.body.forEach((r) => {
@@ -1092,7 +1107,7 @@ const qe = (i, e, t = {}) => {
1092
1107
  html: s
1093
1108
  };
1094
1109
  });
1095
- }, He = (i) => !i || !(i != null && i.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")), Ve = (i, e, t) => {
1110
+ }, He = (i) => !i || !(i != null && i.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")), Fe = (i, e, t) => {
1096
1111
  let s = t || P;
1097
1112
  if (!s) {
1098
1113
  console.error(
@@ -1100,19 +1115,19 @@ const qe = (i, e, t = {}) => {
1100
1115
  );
1101
1116
  return;
1102
1117
  }
1103
- return He(i) ? "" : (e && (s = new L(e.schema), e.resolver && J(s, e.resolver)), s.render(i, {}, !1));
1104
- }, Je = () => G(N);
1118
+ return He(i) ? "" : (e && (s = new L(e.schema), e.resolver && F(s, e.resolver)), s.render(i, {}, !1));
1119
+ }, Ve = () => q(N);
1105
1120
  export {
1106
- v as BlockTypes,
1107
- $ as MarkTypes,
1121
+ k as BlockTypes,
1122
+ v as MarkTypes,
1108
1123
  L as RichTextResolver,
1109
1124
  _e as RichTextSchema,
1110
- V as TextTypes,
1125
+ G as TextTypes,
1111
1126
  ze as apiPlugin,
1112
1127
  He as isRichTextEmpty,
1113
- Je as loadStoryblokBridge,
1128
+ Ve as loadStoryblokBridge,
1114
1129
  qe as registerStoryblokBridge,
1115
- Ve as renderRichText,
1130
+ Fe as renderRichText,
1116
1131
  De as richTextResolver,
1117
1132
  Be as storyblokEditable,
1118
1133
  Ge as storyblokInit,
@@ -53,7 +53,7 @@ export interface StoryblokBridgeV2 {
53
53
  export type { ISbConfig, // previously StoryblokConfig
54
54
  ISbCache, // previously StoryblokCache
55
55
  ISbResult, // previously StoryblokResult
56
- ISbResponse, ISbError, ISbNode, ISbSchema, ThrottleFn, AsyncFn, ArrayFn, ISbContentMangmntAPI, ISbManagmentApiResult, // previously StoryblokManagmentApiResult
56
+ ISbResponse, ISbError, ISbNode, ISbSchema, ISbThrottle, ISbThrottledRequest, AsyncFn, ArrayFn, ISbContentMangmntAPI, ISbManagmentApiResult, // previously StoryblokManagmentApiResult
57
57
  ISbStories, // previously Stories
58
58
  ISbStory, // previously Story
59
59
  ISbDimensions, ISbComponentType as StoryblokComponentType, ISbStoryData, // previously StoryData
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storyblok/js",
3
- "version": "3.1.7",
3
+ "version": "3.1.8",
4
4
  "description": "SDK to integrate Storyblok into your project using JavaScript.",
5
5
  "main": "./dist/storyblok-js.js",
6
6
  "module": "./dist/storyblok-js.mjs",
@@ -29,17 +29,17 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@storyblok/richtext": "^3.0.0",
32
- "storyblok-js-client": "^6.10.0"
32
+ "storyblok-js-client": "^6.10.2"
33
33
  },
34
34
  "devDependencies": {
35
- "@tsconfig/recommended": "^1.0.7",
36
- "cypress": "^13.15.0",
37
- "eslint-plugin-cypress": "^2.15.1",
38
- "eslint-plugin-jest": "^28.8.0",
35
+ "@tsconfig/recommended": "^1.0.8",
36
+ "cypress": "^13.16.0",
37
+ "eslint-plugin-cypress": "^2.15.2",
38
+ "eslint-plugin-jest": "^28.9.0",
39
39
  "isomorphic-fetch": "^3.0.0",
40
40
  "start-server-and-test": "^2.0.8",
41
- "vite": "^5.4.8",
42
- "vitest": "^2.1.4"
41
+ "vite": "^5.4.11",
42
+ "vitest": "^2.1.5"
43
43
  },
44
44
  "babel": {
45
45
  "presets": [