@storyblok/js 4.0.4-rc.0 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,7 +16,7 @@
16
16
  <a href="https://npmjs.com/package/@storyblok/js" rel="nofollow">
17
17
  <img src="https://img.shields.io/npm/dt/@storyblok/js.svg?style=appveyor&color=8d60ff" alt="npm">
18
18
  </a>
19
- <a href="https://discord.gg/jKrbAMz">
19
+ <a href="https://storyblok.com/join-discord">
20
20
  <img src="https://img.shields.io/discord/700316478792138842?label=Join%20Our%20Discord%20Community&style=appveyor&logo=discord&color=8d60ff">
21
21
  </a>
22
22
  <a href="https://twitter.com/intent/follow?screen_name=storyblok">
@@ -49,7 +49,7 @@ For help, discussion about best practices, or any other conversation that would
49
49
 
50
50
  For community support, chatting with other users, please visit:
51
51
 
52
- - [Discuss Storyblok on Discord](https://discord.gg/jKrbAMz)
52
+ - [Discuss Storyblok on Discord](https://storyblok.com/join-discord)
53
53
 
54
54
  ## Support
55
55
 
@@ -64,7 +64,7 @@ We understand that you might not be able to share your company's project code. P
64
64
 
65
65
  ### Feedback
66
66
 
67
- If you have a question, please ask in the [Discuss Storyblok on Discord](https://discord.gg/jKrbAMz) channel.
67
+ If you have a question, please ask in the [Discuss Storyblok on Discord](https://storyblok.com/join-discord) channel.
68
68
 
69
69
 
70
70
  ## License
@@ -4,4 +4,4 @@
4
4
  * description: SDK to integrate Storyblok into your project using JavaScript.
5
5
  * author: undefined
6
6
  */
7
- (function(w,S){typeof exports=="object"&&typeof module<"u"?S(exports):typeof define=="function"&&define.amd?define(["exports"],S):(w=typeof globalThis<"u"?globalThis:w||self,S(w.storyblok={}))})(this,function(w){"use strict";function S(r,e){if(!e)return{src:r,attrs:{}};let t=0,o=0;const s={},n=[];function l(a,h,d,y,R){typeof a!="number"||a<=h||a>=d?console.warn(`[StoryblokRichText] - ${y.charAt(0).toUpperCase()+y.slice(1)} value must be a number between ${h} and ${d} (inclusive)`):R.push(`${y}(${a})`)}if(typeof e=="object"){if(typeof e.width=="number"&&e.width>0?(s.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?(s.height=e.height,o=e.height):console.warn("[StoryblokRichText] - Height value must be a number greater than 0"),e.loading&&["lazy","eager"].includes(e.loading)&&(s.loading=e.loading),e.class&&(s.class=e.class),e.filters){const{filters:a}=e||{},{blur:h,brightness:d,fill:y,format:R,grayscale:_,quality:L,rotate:C}=a||{};h&&l(h,0,100,"blur",n),L&&l(L,0,100,"quality",n),d&&l(d,0,100,"brightness",n),y&&n.push(`fill(${y})`),_&&n.push("grayscale()"),C&&[0,90,180,270].includes(e.filters.rotate||0)&&n.push(`rotate(${C})`),R&&["webp","png","jpeg"].includes(R)&&n.push(`format(${R})`)}e.srcset&&(s.srcset=e.srcset.map(a=>{if(typeof a=="number")return`${r}/m/${a}x0/${n.length>0?`filters:${n.join(":")}`:""} ${a}w`;if(Array.isArray(a)&&a.length===2){const[h,d]=a;return`${r}/m/${h}x${d}/${n.length>0?`filters:${n.join(":")}`:""} ${h}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),e.sizes&&(s.sizes=e.sizes.join(", "))}let c=`${r}/m/`;return t>0&&o>0&&(c=`${c}${t}x${o}/`),n.length>0&&(c=`${c}filters:${n.join(":")}`),{src:c,attrs:s}}var b=(r=>(r.DOCUMENT="doc",r.HEADING="heading",r.PARAGRAPH="paragraph",r.QUOTE="blockquote",r.OL_LIST="ordered_list",r.UL_LIST="bullet_list",r.LIST_ITEM="list_item",r.CODE_BLOCK="code_block",r.HR="horizontal_rule",r.BR="hard_break",r.IMAGE="image",r.EMOJI="emoji",r.COMPONENT="blok",r.TABLE="table",r.TABLE_ROW="tableRow",r.TABLE_CELL="tableCell",r.TABLE_HEADER="tableHeader",r))(b||{}),$=(r=>(r.BOLD="bold",r.STRONG="strong",r.STRIKE="strike",r.UNDERLINE="underline",r.ITALIC="italic",r.CODE="code",r.LINK="link",r.ANCHOR="anchor",r.STYLED="styled",r.SUPERSCRIPT="superscript",r.SUBSCRIPT="subscript",r.TEXT_STYLE="textStyle",r.HIGHLIGHT="highlight",r))($||{}),N=(r=>(r.TEXT="text",r))(N||{}),I=(r=>(r.URL="url",r.STORY="story",r.ASSET="asset",r.EMAIL="email",r))(I||{});const X=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],Q=(r={})=>Object.keys(r).map(e=>`${e}="${r[e]}"`).join(" "),Z=(r={})=>Object.keys(r).map(e=>`${e}: ${r[e]}`).join("; ");function ee(r){return r.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}const O=r=>Object.fromEntries(Object.entries(r).filter(([e,t])=>t!==void 0));function D(r,e={},t){const o=Q(e),s=o?`${r} ${o}`:r,n=Array.isArray(t)?t.join(""):t||"";if(r){if(X.includes(r))return`<${s}>`}else return n;return`<${s}>${n}</${r}>`}function M(r={}){const e=new Map,{renderFn:t=D,textFn:o=ee,resolvers:s={},optimizeImages:n=!1,keyedResolvers:l=!1}=r,c=t!==D,a=i=>(u,p)=>{const f=u.attrs||{};return p.render(i,f,u.children||null)},h=(i,u)=>{const{src:p,alt:f,title:m,srcset:T,sizes:v}=i.attrs||{};let k=p,E={};if(n){const{src:Ae,attrs:Se}=S(p,n);k=Ae,E=Se}const Ee={src:k,alt:f,title:m,srcset:T,sizes:v,...E};return u.render("img",O(Ee))},d=(i,u)=>{const{level:p,...f}=i.attrs||{};return u.render(`h${p}`,f,i.children)},y=(i,u)=>{var p,f,m,T;const v=u.render("img",{src:(p=i.attrs)==null?void 0:p.fallbackImage,alt:(f=i.attrs)==null?void 0:f.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"});return u.render("span",{"data-type":"emoji","data-name":(m=i.attrs)==null?void 0:m.name,"data-emoji":(T=i.attrs)==null?void 0:T.emoji},v)},R=(i,u)=>u.render("pre",i.attrs||{},u.render("code",{},i.children||"")),_=(i,u=!1)=>({text:p,attrs:f},m)=>{const{class:T,id:v,...k}=f||{},E=u?{class:T,id:v,style:Z(k)||void 0}:f||{};return m.render(i,O(E),p)},L=i=>U(i),C=i=>{const{marks:u,...p}=i;if("text"in i){if(u)return u.reduce((m,T)=>L({...T,text:m}),L({...p,children:p.children}));const f=i.attrs||{};if(l){const m=e.get("txt")||0;e.set("txt",m+1),f.key=`txt-${m}`}return o(p.text,f)}return""},Y=(i,u)=>{const{linktype:p,href:f,anchor:m,...T}=i.attrs||{};let v="";switch(p){case I.ASSET:case I.URL:v=f;break;case I.EMAIL:v=`mailto:${f}`;break;case I.STORY:v=f,m&&(v=`${v}#${m}`);break;default:v=f;break}const k={...T};return v&&(k.href=v),u.render("a",k,i.text)},ke=(i,u)=>{var p,f;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),u.render("span",{blok:(p=i==null?void 0:i.attrs)==null?void 0:p.body[0],id:(f=i.attrs)==null?void 0:f.id,style:"display: none"})},we=(i,u)=>{const p={},f=u.render("tbody",{},i.children);return u.render("table",p,f)},Te=(i,u)=>{const p={};return u.render("tr",p,i.children)},Re=(i,u)=>{const{colspan:p,rowspan:f,colwidth:m,backgroundColor:T,...v}=i.attrs||{},k={...v};p>1&&(k.colspan=p),f>1&&(k.rowspan=f);const E=[];return m&&E.push(`width: ${m}px;`),T&&E.push(`background-color: ${T};`),E.length>0&&(k.style=E.join(" ")),u.render("td",O(k),i.children)},$e=(i,u)=>{const{colspan:p,rowspan:f,colwidth:m,backgroundColor:T,...v}=i.attrs||{},k={...v};p>1&&(k.colspan=p),f>1&&(k.rowspan=f);const E=[];return m&&E.push(`width: ${m}px;`),T&&E.push(`background-color: ${T};`),E.length>0&&(k.style=E.join(" ")),u.render("th",O(k),i.children)},K=new Map([[b.DOCUMENT,a("")],[b.HEADING,d],[b.PARAGRAPH,a("p")],[b.UL_LIST,a("ul")],[b.OL_LIST,a("ol")],[b.LIST_ITEM,a("li")],[b.IMAGE,h],[b.EMOJI,y],[b.CODE_BLOCK,R],[b.HR,a("hr")],[b.BR,a("br")],[b.QUOTE,a("blockquote")],[b.COMPONENT,ke],[N.TEXT,C],[$.LINK,Y],[$.ANCHOR,Y],[$.STYLED,_("span",!0)],[$.BOLD,_("strong")],[$.TEXT_STYLE,_("span",!0)],[$.ITALIC,_("em")],[$.UNDERLINE,_("u")],[$.STRIKE,_("s")],[$.CODE,_("code")],[$.SUPERSCRIPT,_("sup")],[$.SUBSCRIPT,_("sub")],[$.HIGHLIGHT,_("mark")],[b.TABLE,we],[b.TABLE_ROW,Te],[b.TABLE_CELL,Re],[b.TABLE_HEADER,$e]]),W=new Map([...K,...Object.entries(s).map(([i,u])=>[i,u])]),_e=()=>({render:(i,u={},p)=>{if(l&&i){const f=e.get(i)||0;e.set(i,f+1),u.key=`${i}-${f}`}return t(i,u,p)},originalResolvers:K,mergedResolvers:W});function P(i){const u=W.get(i.type);if(!u)return console.error("<Storyblok>",`No resolver found for node type ${i.type}`),"";const p=_e();if(i.type==="text")return u(i,p);const f=i.content?i.content.map(U):void 0;return u({...i,children:f},p)}function U(i){return i.type==="doc"?c?i.content.map(P):i.content.map(P).join(""):Array.isArray(i)?i.map(P):P(i)}return{render:U}}let z=!1;const F=[],G=r=>new Promise((e,t)=>{if(typeof window>"u"){t(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));return}if(window.storyblokRegisterEvent=s=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}z?s():F.push(s)},document.getElementById("storyblok-javascript-bridge")){e(void 0);return}const o=document.createElement("script");o.async=!0,o.src=r,o.id="storyblok-javascript-bridge",o.onerror=s=>t(s),o.onload=s=>{F.forEach(n=>n()),z=!0,e(s)},document.getElementsByTagName("head")[0].appendChild(o)});var te=Object.defineProperty,se=(r,e,t)=>e in r?te(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,g=(r,e,t)=>se(r,typeof e!="symbol"?e+"":e,t);class re extends Error{constructor(e){super(e),this.name="AbortError"}}function oe(r,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 o=[];let s=[],n=0,l=!1;const c=async()=>{n++;const h=o.shift();if(h)try{const y=await r(...h.args);h.resolve(y)}catch(y){h.reject(y)}const d=setTimeout(()=>{n--,o.length>0&&c(),s=s.filter(y=>y!==d)},t);s.includes(d)||s.push(d)},a=(...h)=>l?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((d,y)=>{o.push({resolve:d,reject:y,args:h}),n<e&&c()});return a.abort=()=>{l=!0,s.forEach(clearTimeout),s=[],o.forEach(h=>h.reject(()=>new re("Throttle function aborted"))),o.length=0},a}const ne=(r="")=>r.includes("/cdn/"),ie=(r,e=25,t=1)=>({...r,per_page:e,page:t}),ae=r=>new Promise(e=>setTimeout(e,r)),le=(r=0,e)=>Array.from({length:r},e),ce=(r=0,e=r)=>{const t=Math.abs(e-r)||0,o=r<e?1:-1;return le(t,(s,n)=>n*o+r)},he=async(r,e)=>Promise.all(r.map(e)),ue=(r=[],e)=>r.map(e).reduce((t,o)=>[...t,...o],[]),x=(r,e,t)=>{const o=[];for(const s in r){if(!Object.prototype.hasOwnProperty.call(r,s))continue;const n=r[s];if(n==null)continue;const l=t?"":encodeURIComponent(s);let c;typeof n=="object"?c=x(n,e?e+encodeURIComponent(`[${l}]`):l,Array.isArray(n)):c=`${e?e+encodeURIComponent(`[${l}]`):l}=${encodeURIComponent(n)}`,o.push(c)}return o.join("&")},V=r=>{const e={eu:"api.storyblok.com",us:"api-us.storyblok.com",cn:"app.storyblokchina.cn",ap:"api-ap.storyblok.com",ca:"api-ca.storyblok.com"};return e[r]??e.eu};class de{constructor(e){g(this,"baseURL"),g(this,"timeout"),g(this,"headers"),g(this,"responseInterceptor"),g(this,"fetch"),g(this,"ejectInterceptor"),g(this,"url"),g(this,"parameters"),g(this,"fetchOptions"),this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={},this.fetchOptions={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t??{},this._methodHandler("delete")}async _responseHandler(e){const t=[],o={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(s=>{o.data=s});for(const s of e.headers.entries())t[s[0]]=s[1];return o.headers={...t},o.status=e.status,o.statusText=e.statusText,o}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,o=null;e==="get"?t=`${this.baseURL}${this.url}?${x(this.parameters)}`:o=JSON.stringify(this.parameters);const s=new URL(t),n=new AbortController,{signal:l}=n;let c;this.timeout&&(c=setTimeout(()=>n.abort(),this.timeout));try{const a=await this.fetch(`${s}`,{method:e,headers:this.headers,body:o,signal:l,...this.fetchOptions});this.timeout&&clearTimeout(c);const h=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(h)):this._statusHandler(h)}catch(a){return{message:a}}}setFetchOptions(e={}){Object.keys(e).length>0&&"method"in e&&delete e.method,this.fetchOptions={...e}}eject(){this.ejectInterceptor=!0}_normalizeErrorMessage(e){if(Array.isArray(e))return e[0]||"Unknown error";if(e&&typeof e=="object"){if(e.error)return e.error;for(const t in e){if(Array.isArray(e[t]))return`${t}: ${e[t][0]}`;if(typeof e[t]=="string")return`${t}: ${e[t]}`}if(e.slug)return e.slug}return"Unknown error"}_statusHandler(e){const t=/20[0-6]/g;return new Promise((o,s)=>{if(t.test(`${e.status}`))return o(e);const n={message:this._normalizeErrorMessage(e.data),status:e.status,response:e};s(n)})}}const q="SB-Agent",B={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"},pe={DRAFT:"draft"};let j={};const A={};class fe{constructor(e,t){g(this,"client"),g(this,"maxRetries"),g(this,"retriesDelay"),g(this,"throttle"),g(this,"accessToken"),g(this,"cache"),g(this,"resolveCounter"),g(this,"relations"),g(this,"links"),g(this,"version"),g(this,"richTextResolver"),g(this,"resolveNestedRelations"),g(this,"stringifiedStoriesCache"),g(this,"inlineAssets");let o=e.endpoint||t;if(!o){const l=e.https===!1?"http":"https";e.oauthToken?o=`${l}://${V(e.region)}/v1`:o=`${l}://${V(e.region)}/v2`}const s=new Headers;s.set("Content-Type","application/json"),s.set("Accept","application/json"),e.headers&&(e.headers.constructor.name==="Headers"?e.headers.entries().toArray():Object.entries(e.headers)).forEach(([l,c])=>{s.set(l,c)}),s.has(q)||(s.set(q,B.defaultAgentName),s.set(B.defaultAgentVersion,B.packageVersion));let n=5;e.oauthToken&&(s.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=e.rateLimit),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=oe(this.throttledRequest.bind(this),n,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.version=e.version||pe.DRAFT,this.inlineAssets=e.inlineAssets||!1,this.client=new de({baseURL:o,timeout:e.timeout||0,headers:s,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=A[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 ne(e)?this.parseParams(t):t}makeRequest(e,t,o,s,n){const l=this.factoryParamOptions(e,ie(t,o,s));return this.cacheResponse(e,l,void 0,n)}get(e,t={},o){t||(t={});const s=`/${e}`;t.version=t.version||this.version;const n=this.factoryParamOptions(s,t);return this.cacheResponse(s,n,void 0,o)}async getAll(e,t={},o,s){const n=(t==null?void 0:t.per_page)||25,l=`/${e}`.replace(/\/$/,""),c=o??l.substring(l.lastIndexOf("/")+1);t.version=t.version||this.version;const a=1,h=await this.makeRequest(l,t,n,a,s),d=h.total?Math.ceil(h.total/n):1,y=await he(ce(a,d),R=>this.makeRequest(l,t,n,R+1,s));return ue([h,...y],R=>Object.values(R.data[c]))}post(e,t={},o){const s=`/${e}`;return this.throttle("post",s,t,o)}put(e,t={},o){const s=`/${e}`;return this.throttle("put",s,t,o)}delete(e,t={},o){t||(t={});const s=`/${e}`;return this.throttle("delete",s,t,o)}getStories(e={},t){return this._addResolveLevel(e),this.get("cdn/stories",e,t)}getStory(e,t={},o){return this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t,o)}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,o){const s=e[t];s&&s.fieldtype==="multilink"&&s.linktype==="story"&&typeof s.id=="string"&&this.links[o][s.id]?s.story=this._cleanCopy(this.links[o][s.id]):s&&s.linktype==="story"&&typeof s.uuid=="string"&&this.links[o][s.uuid]&&(s.story=this._cleanCopy(this.links[o][s.uuid]))}getStoryReference(e,t){return this.relations[e][t]?JSON.parse(this.stringifiedStoriesCache[t]||JSON.stringify(this.relations[e][t])):t}_resolveField(e,t,o){const s=e[t];typeof s=="string"?e[t]=this.getStoryReference(o,s):Array.isArray(s)&&(e[t]=s.map(n=>this.getStoryReference(o,n)).filter(Boolean))}_insertRelations(e,t,o,s){if(Array.isArray(o)?o.find(l=>l.endsWith(`.${t}`)):o.endsWith(`.${t}`)){this._resolveField(e,t,s);return}const n=e.component?`${e.component}.${t}`:t;(Array.isArray(o)?o.includes(n):o===n)&&this._resolveField(e,t,s)}iterateTree(e,t,o){const s=(n,l="")=>{if(!(!n||n._stopResolving)){if(Array.isArray(n))n.forEach((c,a)=>s(c,`${l}[${a}]`));else if(typeof n=="object")for(const c in n){const a=l?`${l}.${c}`:c;(n.component&&n._uid||n.type==="link")&&(this._insertRelations(n,c,t,o),this._insertLinks(n,c,o)),s(n[c],a)}}};s(e.content)}async resolveLinks(e,t,o){let s=[];if(e.link_uuids){const n=e.link_uuids.length,l=[],c=50;for(let a=0;a<n;a+=c){const h=Math.min(n,a+c);l.push(e.link_uuids.slice(a,h))}for(let a=0;a<l.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:l[a].join(",")})).data.stories.forEach(h=>{s.push(h)})}else s=e.links;s.forEach(n=>{this.links[o][n.uuid]={...n,_stopResolving:!0}})}async resolveRelations(e,t,o){let s=[];if(e.rel_uuids){const n=e.rel_uuids.length,l=[],c=50;for(let a=0;a<n;a+=c){const h=Math.min(n,a+c);l.push(e.rel_uuids.slice(a,h))}for(let a=0;a<l.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:l[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(h=>{s.push(h)});s.length>0&&(e.rels=s,delete e.rel_uuids)}else s=e.rels;s&&s.length>0&&s.forEach(n=>{this.relations[o][n.uuid]={...n,_stopResolving:!0}})}async resolveStories(e,t,o){var s,n;let l=[];if(this.links[o]={},this.relations[o]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(l=t.resolve_relations.split(",")),await this.resolveRelations(e,t,o)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((s=e.links)!=null&&s.length||(n=e.link_uuids)!=null&&n.length)&&await this.resolveLinks(e,t,o),this.resolveNestedRelations)for(const c in this.relations[o])this.iterateTree(this.relations[o][c],l,o);e.story?this.iterateTree(e.story,l,o):e.stories.forEach(c=>{this.iterateTree(c,l,o)}),this.stringifiedStoriesCache={},delete this.links[o],delete this.relations[o]}async cacheResponse(e,t,o,s){const n=x({url:e,params:t}),l=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const c=await l.get(n);if(c)return Promise.resolve(c)}return new Promise(async(c,a)=>{var h;try{const d=await this.throttle("get",e,t,s);if(d.status!==200)return a(d);let y={data:d.data,headers:d.headers};if((h=d.headers)!=null&&h["per-page"]&&(y=Object.assign({},y,{perPage:d.headers["per-page"]?Number.parseInt(d.headers["per-page"]):0,total:d.headers["per-page"]?Number.parseInt(d.headers.total):0})),y.data.story||y.data.stories){const _=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(y.data,t,`${_}`),y=await this.processInlineAssets(y)}t.version==="published"&&e!=="/cdn/spaces/me"&&await l.set(n,y);const R=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&y.data.cv&&(R&&A[t.token]&&A[t.token]!==y.data.cv&&await this.flushCache(),A[t.token]=y.data.cv),c(y)}catch(d){if(d.response&&d.status===429&&(o=typeof o>"u"?0:o+1,o<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${this.retriesDelay/1e3} seconds.`),await ae(this.retriesDelay),this.cacheResponse(e,t,o).then(c).catch(a);a(d)}})}throttledRequest(e,t,o,s){return this.client.setFetchOptions(s),this.client[e](t,o)}cacheVersions(){return A}cacheVersion(){return A[this.accessToken]}setCacheVersion(e){this.accessToken&&(A[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(A[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(j[e])},getAll(){return Promise.resolve(j)},set(e,t){return j[e]=t,Promise.resolve(void 0)},flush(){return j={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve()},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this.clearCacheVersion(),this}async processInlineAssets(e){if(!this.inlineAssets)return e;const t=o=>{if(!o||typeof o!="object")return o;if(Array.isArray(o))return o.map(n=>t(n));let s={...o};s.fieldtype==="asset"&&Array.isArray(e.data.assets)&&(s={...s,...e.data.assets.find(n=>n.id===s.id)});for(const n in s)typeof s[n]=="object"&&(s[n]=t(s[n]));return s};return e.data.story&&(e.data.story.content=t(e.data.story.content)),e.data.stories&&(e.data.stories=e.data.stories.map(o=>(o.content=t(o.content),o))),e}}const ye=(r={})=>{const{apiOptions:e}=r;if(!e||!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new fe(e)}},ge=r=>{if(typeof r!="object"||typeof r._editable>"u")return{};try{const e=JSON.parse(r._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":`${e.id}-${e.uid}`}:{}}catch{return{}}};let H="https://app.storyblok.com/f/storyblok-v2-latest.js";const J=(r,e,t={})=>{var c;const s=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",n=new URL((c=window.location)==null?void 0:c.href).searchParams.get("_storyblok"),l=n!==null&&+n===r;if(!(!s||!l)){if(!r){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],h=>{var d;h&&(h.action==="input"&&((d=h.story)==null?void 0:d.id)===r?e(h.story):(h.action==="change"||h.action==="published")&&h.storyId===r&&window.location.reload())})})}},me=(r={})=>{var d,y;const{bridge:e,accessToken:t,use:o=[],apiOptions:s={},bridgeUrl:n}=r;s.accessToken=s.accessToken||t;const l={bridge:e,apiOptions:s};let c={};o.forEach(R=>{c={...c,...R(l)}}),n&&(H=n);const h=!(typeof window>"u")&&((y=(d=window.location)==null?void 0:d.search)==null?void 0:y.includes("_storyblok_tk"));return e!==!1&&h&&G(H),c};function be(r,e){return M(e).render(r)}const ve=()=>G(H);w.BlockTypes=b,w.MarkTypes=$,w.TextTypes=N,w.apiPlugin=ye,w.loadStoryblokBridge=ve,w.registerStoryblokBridge=J,w.renderRichText=be,w.richTextResolver=M,w.storyblokEditable=ge,w.storyblokInit=me,w.useStoryblokBridge=J,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
7
+ (function(w,S){typeof exports=="object"&&typeof module<"u"?S(exports):typeof define=="function"&&define.amd?define(["exports"],S):(w=typeof globalThis<"u"?globalThis:w||self,S(w.storyblok={}))})(this,function(w){"use strict";function S(r,e){if(!e)return{src:r,attrs:{}};let t=0,o=0;const s={},n=[];function l(a,h,d,y,R){typeof a!="number"||a<=h||a>=d?console.warn(`[StoryblokRichText] - ${y.charAt(0).toUpperCase()+y.slice(1)} value must be a number between ${h} and ${d} (inclusive)`):R.push(`${y}(${a})`)}if(typeof e=="object"){if(typeof e.width=="number"&&e.width>0?(s.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?(s.height=e.height,o=e.height):console.warn("[StoryblokRichText] - Height value must be a number greater than 0"),e.loading&&["lazy","eager"].includes(e.loading)&&(s.loading=e.loading),e.class&&(s.class=e.class),e.filters){const{filters:a}=e||{},{blur:h,brightness:d,fill:y,format:R,grayscale:_,quality:L,rotate:C}=a||{};h&&l(h,0,100,"blur",n),L&&l(L,0,100,"quality",n),d&&l(d,0,100,"brightness",n),y&&n.push(`fill(${y})`),_&&n.push("grayscale()"),C&&[0,90,180,270].includes(e.filters.rotate||0)&&n.push(`rotate(${C})`),R&&["webp","png","jpeg"].includes(R)&&n.push(`format(${R})`)}e.srcset&&(s.srcset=e.srcset.map(a=>{if(typeof a=="number")return`${r}/m/${a}x0/${n.length>0?`filters:${n.join(":")}`:""} ${a}w`;if(Array.isArray(a)&&a.length===2){const[h,d]=a;return`${r}/m/${h}x${d}/${n.length>0?`filters:${n.join(":")}`:""} ${h}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),e.sizes&&(s.sizes=e.sizes.join(", "))}let c=`${r}/m/`;return t>0&&o>0&&(c=`${c}${t}x${o}/`),n.length>0&&(c=`${c}filters:${n.join(":")}`),{src:c,attrs:s}}var b=(r=>(r.DOCUMENT="doc",r.HEADING="heading",r.PARAGRAPH="paragraph",r.QUOTE="blockquote",r.OL_LIST="ordered_list",r.UL_LIST="bullet_list",r.LIST_ITEM="list_item",r.CODE_BLOCK="code_block",r.HR="horizontal_rule",r.BR="hard_break",r.IMAGE="image",r.EMOJI="emoji",r.COMPONENT="blok",r.TABLE="table",r.TABLE_ROW="tableRow",r.TABLE_CELL="tableCell",r.TABLE_HEADER="tableHeader",r))(b||{}),$=(r=>(r.BOLD="bold",r.STRONG="strong",r.STRIKE="strike",r.UNDERLINE="underline",r.ITALIC="italic",r.CODE="code",r.LINK="link",r.ANCHOR="anchor",r.STYLED="styled",r.SUPERSCRIPT="superscript",r.SUBSCRIPT="subscript",r.TEXT_STYLE="textStyle",r.HIGHLIGHT="highlight",r))($||{}),N=(r=>(r.TEXT="text",r))(N||{}),I=(r=>(r.URL="url",r.STORY="story",r.ASSET="asset",r.EMAIL="email",r))(I||{});const Q=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],Z=(r={})=>Object.keys(r).map(e=>`${e}="${r[e]}"`).join(" "),ee=(r={})=>Object.keys(r).map(e=>`${e}: ${r[e]}`).join("; ");function te(r){return r.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}const O=r=>Object.fromEntries(Object.entries(r).filter(([e,t])=>t!==void 0));function D(r,e={},t){const o=Z(e),s=o?`${r} ${o}`:r,n=Array.isArray(t)?t.join(""):t||"";if(r){if(Q.includes(r))return`<${s}>`}else return n;return`<${s}>${n}</${r}>`}function M(r={}){const e=new Map,{renderFn:t=D,textFn:o=te,resolvers:s={},optimizeImages:n=!1,keyedResolvers:l=!1}=r,c=t!==D,a=i=>(u,p)=>{const f=u.attrs||{};return p.render(i,f,u.children||null)},h=(i,u)=>{const{src:p,alt:f,title:m,srcset:T,sizes:v}=i.attrs||{};let k=p,E={};if(n){const{src:Ae,attrs:Se}=S(p,n);k=Ae,E=Se}const Ee={src:k,alt:f,title:m,srcset:T,sizes:v,...E};return u.render("img",O(Ee))},d=(i,u)=>{const{level:p,...f}=i.attrs||{};return u.render(`h${p}`,f,i.children)},y=(i,u)=>{var p,f,m,T;const v=u.render("img",{src:(p=i.attrs)==null?void 0:p.fallbackImage,alt:(f=i.attrs)==null?void 0:f.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"});return u.render("span",{"data-type":"emoji","data-name":(m=i.attrs)==null?void 0:m.name,"data-emoji":(T=i.attrs)==null?void 0:T.emoji},v)},R=(i,u)=>u.render("pre",i.attrs||{},u.render("code",{},i.children||"")),_=(i,u=!1)=>({text:p,attrs:f},m)=>{const{class:T,id:v,...k}=f||{},E=u?{class:T,id:v,style:ee(k)||void 0}:f||{};return m.render(i,O(E),p)},L=i=>U(i),C=i=>{const{marks:u,...p}=i;if("text"in i){if(u)return u.reduce((m,T)=>L({...T,text:m}),L({...p,children:p.children}));const f=i.attrs||{};if(l){const m=e.get("txt")||0;e.set("txt",m+1),f.key=`txt-${m}`}return o(p.text,f)}return""},K=(i,u)=>{const{linktype:p,href:f,anchor:m,...T}=i.attrs||{};let v="";switch(p){case I.ASSET:case I.URL:v=f;break;case I.EMAIL:v=`mailto:${f}`;break;case I.STORY:v=f,m&&(v=`${v}#${m}`);break;default:v=f;break}const k={...T};return v&&(k.href=v),u.render("a",k,i.text)},ke=(i,u)=>{var p,f;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),u.render("span",{blok:(p=i==null?void 0:i.attrs)==null?void 0:p.body[0],id:(f=i.attrs)==null?void 0:f.id,style:"display: none"})},we=(i,u)=>{const p={},f=u.render("tbody",{},i.children);return u.render("table",p,f)},Te=(i,u)=>{const p={};return u.render("tr",p,i.children)},Re=(i,u)=>{const{colspan:p,rowspan:f,colwidth:m,backgroundColor:T,...v}=i.attrs||{},k={...v};p>1&&(k.colspan=p),f>1&&(k.rowspan=f);const E=[];return m&&E.push(`width: ${m}px;`),T&&E.push(`background-color: ${T};`),E.length>0&&(k.style=E.join(" ")),u.render("td",O(k),i.children)},$e=(i,u)=>{const{colspan:p,rowspan:f,colwidth:m,backgroundColor:T,...v}=i.attrs||{},k={...v};p>1&&(k.colspan=p),f>1&&(k.rowspan=f);const E=[];return m&&E.push(`width: ${m}px;`),T&&E.push(`background-color: ${T};`),E.length>0&&(k.style=E.join(" ")),u.render("th",O(k),i.children)},W=new Map([[b.DOCUMENT,a("")],[b.HEADING,d],[b.PARAGRAPH,a("p")],[b.UL_LIST,a("ul")],[b.OL_LIST,a("ol")],[b.LIST_ITEM,a("li")],[b.IMAGE,h],[b.EMOJI,y],[b.CODE_BLOCK,R],[b.HR,a("hr")],[b.BR,a("br")],[b.QUOTE,a("blockquote")],[b.COMPONENT,ke],[N.TEXT,C],[$.LINK,K],[$.ANCHOR,K],[$.STYLED,_("span",!0)],[$.BOLD,_("strong")],[$.TEXT_STYLE,_("span",!0)],[$.ITALIC,_("em")],[$.UNDERLINE,_("u")],[$.STRIKE,_("s")],[$.CODE,_("code")],[$.SUPERSCRIPT,_("sup")],[$.SUBSCRIPT,_("sub")],[$.HIGHLIGHT,_("mark")],[b.TABLE,we],[b.TABLE_ROW,Te],[b.TABLE_CELL,Re],[b.TABLE_HEADER,$e]]),X=new Map([...W,...Object.entries(s).map(([i,u])=>[i,u])]),_e=()=>({render:(i,u={},p)=>{if(l&&i){const f=e.get(i)||0;e.set(i,f+1),u.key=`${i}-${f}`}return t(i,u,p)},originalResolvers:W,mergedResolvers:X});function P(i){const u=X.get(i.type);if(!u)return console.error("<Storyblok>",`No resolver found for node type ${i.type}`),"";const p=_e();if(i.type==="text")return u(i,p);const f=i.content?i.content.map(U):void 0;return u({...i,children:f},p)}function U(i){return i.type==="doc"?c?i.content.map(P):i.content.map(P).join(""):Array.isArray(i)?i.map(P):P(i)}return{render:U}}let z=!1;const G=[],V=r=>new Promise((e,t)=>{if(typeof window>"u"){t(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));return}if(window.storyblokRegisterEvent=s=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}z?s():G.push(s)},document.getElementById("storyblok-javascript-bridge")){e(void 0);return}const o=document.createElement("script");o.async=!0,o.src=r,o.id="storyblok-javascript-bridge",o.onerror=s=>t(s),o.onload=s=>{G.forEach(n=>n()),z=!0,e(s)},document.getElementsByTagName("head")[0].appendChild(o)});var se=Object.defineProperty,re=(r,e,t)=>e in r?se(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,g=(r,e,t)=>re(r,typeof e!="symbol"?e+"":e,t);class oe extends Error{constructor(e){super(e),this.name="AbortError"}}function ne(r,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 o=[];let s=[],n=0,l=!1;const c=async()=>{n++;const h=o.shift();if(h)try{const y=await r(...h.args);h.resolve(y)}catch(y){h.reject(y)}const d=setTimeout(()=>{n--,o.length>0&&c(),s=s.filter(y=>y!==d)},t);s.includes(d)||s.push(d)},a=(...h)=>l?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((d,y)=>{o.push({resolve:d,reject:y,args:h}),n<e&&c()});return a.abort=()=>{l=!0,s.forEach(clearTimeout),s=[],o.forEach(h=>h.reject(()=>new oe("Throttle function aborted"))),o.length=0},a}const q=(r="")=>r.includes("/cdn/"),ie=(r,e=25,t=1)=>({...r,per_page:e,page:t}),ae=r=>new Promise(e=>setTimeout(e,r)),le=(r=0,e)=>Array.from({length:r},e),ce=(r=0,e=r)=>{const t=Math.abs(e-r)||0,o=r<e?1:-1;return le(t,(s,n)=>n*o+r)},he=async(r,e)=>Promise.all(r.map(e)),ue=(r=[],e)=>r.map(e).reduce((t,o)=>[...t,...o],[]),B=(r,e,t)=>{const o=[];for(const s in r){if(!Object.prototype.hasOwnProperty.call(r,s))continue;const n=r[s];if(n==null)continue;const l=t?"":encodeURIComponent(s);let c;typeof n=="object"?c=B(n,e?e+encodeURIComponent(`[${l}]`):l,Array.isArray(n)):c=`${e?e+encodeURIComponent(`[${l}]`):l}=${encodeURIComponent(n)}`,o.push(c)}return o.join("&")},F=r=>{const e={eu:"api.storyblok.com",us:"api-us.storyblok.com",cn:"app.storyblokchina.cn",ap:"api-ap.storyblok.com",ca:"api-ca.storyblok.com"};return e[r]??e.eu};class de{constructor(e){g(this,"baseURL"),g(this,"timeout"),g(this,"headers"),g(this,"responseInterceptor"),g(this,"fetch"),g(this,"ejectInterceptor"),g(this,"url"),g(this,"parameters"),g(this,"fetchOptions"),this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={},this.fetchOptions={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t??{},this._methodHandler("delete")}async _responseHandler(e){const t=[],o={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(s=>{o.data=s});for(const s of e.headers.entries())t[s[0]]=s[1];return o.headers={...t},o.status=e.status,o.statusText=e.statusText,o}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,o=null;e==="get"?t=`${this.baseURL}${this.url}?${B(this.parameters)}`:o=JSON.stringify(this.parameters);const s=new URL(t),n=new AbortController,{signal:l}=n;let c;this.timeout&&(c=setTimeout(()=>n.abort(),this.timeout));try{const a=await this.fetch(`${s}`,{method:e,headers:this.headers,body:o,signal:l,...this.fetchOptions});this.timeout&&clearTimeout(c);const h=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(h)):this._statusHandler(h)}catch(a){return{message:a}}}setFetchOptions(e={}){Object.keys(e).length>0&&"method"in e&&delete e.method,this.fetchOptions={...e}}eject(){this.ejectInterceptor=!0}_normalizeErrorMessage(e){if(Array.isArray(e))return e[0]||"Unknown error";if(e&&typeof e=="object"){if(e.error)return e.error;for(const t in e){if(Array.isArray(e[t]))return`${t}: ${e[t][0]}`;if(typeof e[t]=="string")return`${t}: ${e[t]}`}if(e.slug)return e.slug}return"Unknown error"}_statusHandler(e){const t=/20[0-6]/g;return new Promise((o,s)=>{if(t.test(`${e.status}`))return o(e);const n={message:this._normalizeErrorMessage(e.data),status:e.status,response:e};s(n)})}}const J="SB-Agent",H={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"7.0.0"},pe={PUBLISHED:"published"};let j={};const A={};class fe{constructor(e,t){g(this,"client"),g(this,"maxRetries"),g(this,"retriesDelay"),g(this,"throttle"),g(this,"accessToken"),g(this,"cache"),g(this,"resolveCounter"),g(this,"relations"),g(this,"links"),g(this,"version"),g(this,"richTextResolver"),g(this,"resolveNestedRelations"),g(this,"stringifiedStoriesCache"),g(this,"inlineAssets");let o=e.endpoint||t;if(!o){const l=e.https===!1?"http":"https";e.oauthToken?o=`${l}://${F(e.region)}/v1`:o=`${l}://${F(e.region)}/v2`}const s=new Headers;s.set("Content-Type","application/json"),s.set("Accept","application/json"),e.headers&&(e.headers.constructor.name==="Headers"?e.headers.entries().toArray():Object.entries(e.headers)).forEach(([l,c])=>{s.set(l,c)}),s.has(J)||(s.set(J,H.defaultAgentName),s.set(H.defaultAgentVersion,H.packageVersion));let n=5;e.oauthToken&&(s.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=e.rateLimit),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=ne(this.throttledRequest.bind(this),n,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.version=e.version||pe.PUBLISHED,this.inlineAssets=e.inlineAssets||!1,this.client=new de({baseURL:o,timeout:e.timeout||0,headers:s,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=A[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 q(e)?this.parseParams(t):t}makeRequest(e,t,o,s,n){const l=this.factoryParamOptions(e,ie(t,o,s));return this.cacheResponse(e,l,void 0,n)}get(e,t={},o){t||(t={});const s=`/${e}`;q(s)&&(t.version=t.version||this.version);const n=this.factoryParamOptions(s,t);return this.cacheResponse(s,n,void 0,o)}async getAll(e,t={},o,s){const n=(t==null?void 0:t.per_page)||25,l=`/${e}`.replace(/\/$/,""),c=o??l.substring(l.lastIndexOf("/")+1);t.version=t.version||this.version;const a=1,h=await this.makeRequest(l,t,n,a,s),d=h.total?Math.ceil(h.total/n):1,y=await he(ce(a,d),R=>this.makeRequest(l,t,n,R+1,s));return ue([h,...y],R=>Object.values(R.data[c]))}post(e,t={},o){const s=`/${e}`;return this.throttle("post",s,t,o)}put(e,t={},o){const s=`/${e}`;return this.throttle("put",s,t,o)}delete(e,t={},o){t||(t={});const s=`/${e}`;return this.throttle("delete",s,t,o)}getStories(e={},t){return this._addResolveLevel(e),this.get("cdn/stories",e,t)}getStory(e,t={},o){return this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t,o)}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,o){const s=e[t];s&&s.fieldtype==="multilink"&&s.linktype==="story"&&typeof s.id=="string"&&this.links[o][s.id]?s.story=this._cleanCopy(this.links[o][s.id]):s&&s.linktype==="story"&&typeof s.uuid=="string"&&this.links[o][s.uuid]&&(s.story=this._cleanCopy(this.links[o][s.uuid]))}getStoryReference(e,t){return this.relations[e][t]?JSON.parse(this.stringifiedStoriesCache[t]||JSON.stringify(this.relations[e][t])):t}_resolveField(e,t,o){const s=e[t];typeof s=="string"?e[t]=this.getStoryReference(o,s):Array.isArray(s)&&(e[t]=s.map(n=>this.getStoryReference(o,n)).filter(Boolean))}_insertRelations(e,t,o,s){if(Array.isArray(o)?o.find(l=>l.endsWith(`.${t}`)):o.endsWith(`.${t}`)){this._resolveField(e,t,s);return}const n=e.component?`${e.component}.${t}`:t;(Array.isArray(o)?o.includes(n):o===n)&&this._resolveField(e,t,s)}iterateTree(e,t,o){const s=(n,l="")=>{if(!(!n||n._stopResolving)){if(Array.isArray(n))n.forEach((c,a)=>s(c,`${l}[${a}]`));else if(typeof n=="object")for(const c in n){const a=l?`${l}.${c}`:c;(n.component&&n._uid||n.type==="link")&&(this._insertRelations(n,c,t,o),this._insertLinks(n,c,o)),s(n[c],a)}}};s(e.content)}async resolveLinks(e,t,o){let s=[];if(e.link_uuids){const n=e.link_uuids.length,l=[],c=50;for(let a=0;a<n;a+=c){const h=Math.min(n,a+c);l.push(e.link_uuids.slice(a,h))}for(let a=0;a<l.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:l[a].join(",")})).data.stories.forEach(h=>{s.push(h)})}else s=e.links;s.forEach(n=>{this.links[o][n.uuid]={...n,_stopResolving:!0}})}async resolveRelations(e,t,o){let s=[];if(e.rel_uuids){const n=e.rel_uuids.length,l=[],c=50;for(let a=0;a<n;a+=c){const h=Math.min(n,a+c);l.push(e.rel_uuids.slice(a,h))}for(let a=0;a<l.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:l[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(h=>{s.push(h)});s.length>0&&(e.rels=s,delete e.rel_uuids)}else s=e.rels;s&&s.length>0&&s.forEach(n=>{this.relations[o][n.uuid]={...n,_stopResolving:!0}})}async resolveStories(e,t,o){var s,n;let l=[];if(this.links[o]={},this.relations[o]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(l=t.resolve_relations.split(",")),await this.resolveRelations(e,t,o)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((s=e.links)!=null&&s.length||(n=e.link_uuids)!=null&&n.length)&&await this.resolveLinks(e,t,o),this.resolveNestedRelations)for(const c in this.relations[o])this.iterateTree(this.relations[o][c],l,o);e.story?this.iterateTree(e.story,l,o):e.stories.forEach(c=>{this.iterateTree(c,l,o)}),this.stringifiedStoriesCache={},delete this.links[o],delete this.relations[o]}async cacheResponse(e,t,o,s){const n=B({url:e,params:t}),l=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const c=await l.get(n);if(c)return Promise.resolve(c)}return new Promise(async(c,a)=>{var h;try{const d=await this.throttle("get",e,t,s);if(d.status!==200)return a(d);let y={data:d.data,headers:d.headers};if((h=d.headers)!=null&&h["per-page"]&&(y=Object.assign({},y,{perPage:d.headers["per-page"]?Number.parseInt(d.headers["per-page"]):0,total:d.headers["per-page"]?Number.parseInt(d.headers.total):0})),y.data.story||y.data.stories){const _=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(y.data,t,`${_}`),y=await this.processInlineAssets(y)}t.version==="published"&&e!=="/cdn/spaces/me"&&await l.set(n,y);const R=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&y.data.cv&&(R&&A[t.token]&&A[t.token]!==y.data.cv&&await this.flushCache(),A[t.token]=y.data.cv),c(y)}catch(d){if(d.response&&d.status===429&&(o=typeof o>"u"?0:o+1,o<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${this.retriesDelay/1e3} seconds.`),await ae(this.retriesDelay),this.cacheResponse(e,t,o).then(c).catch(a);a(d)}})}throttledRequest(e,t,o,s){return this.client.setFetchOptions(s),this.client[e](t,o)}cacheVersions(){return A}cacheVersion(){return A[this.accessToken]}setCacheVersion(e){this.accessToken&&(A[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(A[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(j[e])},getAll(){return Promise.resolve(j)},set(e,t){return j[e]=t,Promise.resolve(void 0)},flush(){return j={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve()},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this.clearCacheVersion(),this}async processInlineAssets(e){if(!this.inlineAssets)return e;const t=o=>{if(!o||typeof o!="object")return o;if(Array.isArray(o))return o.map(n=>t(n));let s={...o};s.fieldtype==="asset"&&Array.isArray(e.data.assets)&&(s={...s,...e.data.assets.find(n=>n.id===s.id)});for(const n in s)typeof s[n]=="object"&&(s[n]=t(s[n]));return s};return e.data.story&&(e.data.story.content=t(e.data.story.content)),e.data.stories&&(e.data.stories=e.data.stories.map(o=>(o.content=t(o.content),o))),e}}const ye=(r={})=>{const{apiOptions:e}=r;if(!e||!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new fe(e)}},ge=r=>{if(typeof r!="object"||typeof r._editable>"u")return{};try{const e=JSON.parse(r._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":`${e.id}-${e.uid}`}:{}}catch{return{}}};let x="https://app.storyblok.com/f/storyblok-v2-latest.js";const Y=(r,e,t={})=>{var c;const s=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",n=new URL((c=window.location)==null?void 0:c.href).searchParams.get("_storyblok"),l=n!==null&&+n===r;if(!(!s||!l)){if(!r){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],h=>{var d;h&&(h.action==="input"&&((d=h.story)==null?void 0:d.id)===r?e(h.story):(h.action==="change"||h.action==="published")&&h.storyId===r&&window.location.reload())})})}},me=(r={})=>{var d,y;const{bridge:e,accessToken:t,use:o=[],apiOptions:s={},bridgeUrl:n}=r;s.accessToken=s.accessToken||t;const l={bridge:e,apiOptions:s};let c={};o.forEach(R=>{c={...c,...R(l)}}),n&&(x=n);const h=!(typeof window>"u")&&((y=(d=window.location)==null?void 0:d.search)==null?void 0:y.includes("_storyblok_tk"));return e!==!1&&h&&V(x),c};function be(r,e){return M(e).render(r)}const ve=()=>V(x);w.BlockTypes=b,w.MarkTypes=$,w.TextTypes=N,w.apiPlugin=ye,w.loadStoryblokBridge=ve,w.registerStoryblokBridge=Y,w.renderRichText=be,w.richTextResolver=M,w.storyblokEditable=ge,w.storyblokInit=me,w.useStoryblokBridge=Y,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
@@ -4,7 +4,7 @@
4
4
  * description: SDK to integrate Storyblok into your project using JavaScript.
5
5
  * author: undefined
6
6
  */
7
- function se(r, e) {
7
+ function re(r, e) {
8
8
  if (!e)
9
9
  return { src: r, attrs: {} };
10
10
  let t = 0, o = 0;
@@ -14,8 +14,8 @@ function se(r, e) {
14
14
  }
15
15
  if (typeof e == "object") {
16
16
  if (typeof e.width == "number" && e.width > 0 ? (s.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 ? (s.height = e.height, o = e.height) : console.warn("[StoryblokRichText] - Height value must be a number greater than 0"), e.loading && ["lazy", "eager"].includes(e.loading) && (s.loading = e.loading), e.class && (s.class = e.class), e.filters) {
17
- const { filters: a } = e || {}, { blur: h, brightness: d, fill: y, format: T, grayscale: R, quality: A, rotate: I } = a || {};
18
- h && l(h, 0, 100, "blur", n), A && l(A, 0, 100, "quality", n), d && l(d, 0, 100, "brightness", n), y && n.push(`fill(${y})`), R && n.push("grayscale()"), I && [0, 90, 180, 270].includes(e.filters.rotate || 0) && n.push(`rotate(${I})`), T && ["webp", "png", "jpeg"].includes(T) && n.push(`format(${T})`);
17
+ const { filters: a } = e || {}, { blur: h, brightness: d, fill: y, format: T, grayscale: $, quality: A, rotate: I } = a || {};
18
+ h && l(h, 0, 100, "blur", n), A && l(A, 0, 100, "quality", n), d && l(d, 0, 100, "brightness", n), y && n.push(`fill(${y})`), $ && n.push("grayscale()"), I && [0, 90, 180, 270].includes(e.filters.rotate || 0) && n.push(`rotate(${I})`), T && ["webp", "png", "jpeg"].includes(T) && n.push(`format(${T})`);
19
19
  }
20
20
  e.srcset && (s.srcset = e.srcset.map((a) => {
21
21
  if (typeof a == "number")
@@ -35,8 +35,8 @@ function se(r, e) {
35
35
  attrs: s
36
36
  };
37
37
  }
38
- var v = /* @__PURE__ */ ((r) => (r.DOCUMENT = "doc", r.HEADING = "heading", r.PARAGRAPH = "paragraph", r.QUOTE = "blockquote", r.OL_LIST = "ordered_list", r.UL_LIST = "bullet_list", r.LIST_ITEM = "list_item", r.CODE_BLOCK = "code_block", r.HR = "horizontal_rule", r.BR = "hard_break", r.IMAGE = "image", r.EMOJI = "emoji", r.COMPONENT = "blok", r.TABLE = "table", r.TABLE_ROW = "tableRow", r.TABLE_CELL = "tableCell", r.TABLE_HEADER = "tableHeader", r))(v || {}), _ = /* @__PURE__ */ ((r) => (r.BOLD = "bold", r.STRONG = "strong", r.STRIKE = "strike", r.UNDERLINE = "underline", r.ITALIC = "italic", r.CODE = "code", r.LINK = "link", r.ANCHOR = "anchor", r.STYLED = "styled", r.SUPERSCRIPT = "superscript", r.SUBSCRIPT = "subscript", r.TEXT_STYLE = "textStyle", r.HIGHLIGHT = "highlight", r))(_ || {}), V = /* @__PURE__ */ ((r) => (r.TEXT = "text", r))(V || {}), S = /* @__PURE__ */ ((r) => (r.URL = "url", r.STORY = "story", r.ASSET = "asset", r.EMAIL = "email", r))(S || {});
39
- const re = [
38
+ var v = /* @__PURE__ */ ((r) => (r.DOCUMENT = "doc", r.HEADING = "heading", r.PARAGRAPH = "paragraph", r.QUOTE = "blockquote", r.OL_LIST = "ordered_list", r.UL_LIST = "bullet_list", r.LIST_ITEM = "list_item", r.CODE_BLOCK = "code_block", r.HR = "horizontal_rule", r.BR = "hard_break", r.IMAGE = "image", r.EMOJI = "emoji", r.COMPONENT = "blok", r.TABLE = "table", r.TABLE_ROW = "tableRow", r.TABLE_CELL = "tableCell", r.TABLE_HEADER = "tableHeader", r))(v || {}), _ = /* @__PURE__ */ ((r) => (r.BOLD = "bold", r.STRONG = "strong", r.STRIKE = "strike", r.UNDERLINE = "underline", r.ITALIC = "italic", r.CODE = "code", r.LINK = "link", r.ANCHOR = "anchor", r.STYLED = "styled", r.SUPERSCRIPT = "superscript", r.SUBSCRIPT = "subscript", r.TEXT_STYLE = "textStyle", r.HIGHLIGHT = "highlight", r))(_ || {}), F = /* @__PURE__ */ ((r) => (r.TEXT = "text", r))(F || {}), S = /* @__PURE__ */ ((r) => (r.URL = "url", r.STORY = "story", r.ASSET = "asset", r.EMAIL = "email", r))(S || {});
39
+ const oe = [
40
40
  "area",
41
41
  "base",
42
42
  "br",
@@ -51,23 +51,23 @@ const re = [
51
51
  "source",
52
52
  "track",
53
53
  "wbr"
54
- ], oe = (r = {}) => Object.keys(r).map((e) => `${e}="${r[e]}"`).join(" "), ne = (r = {}) => Object.keys(r).map((e) => `${e}: ${r[e]}`).join("; ");
55
- function ie(r) {
54
+ ], ne = (r = {}) => Object.keys(r).map((e) => `${e}="${r[e]}"`).join(" "), ie = (r = {}) => Object.keys(r).map((e) => `${e}: ${r[e]}`).join("; ");
55
+ function ae(r) {
56
56
  return r.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
57
57
  }
58
58
  const O = (r) => Object.fromEntries(Object.entries(r).filter(([e, t]) => t !== void 0));
59
59
  function D(r, e = {}, t) {
60
- const o = oe(e), s = o ? `${r} ${o}` : r, n = Array.isArray(t) ? t.join("") : t || "";
60
+ const o = ne(e), s = o ? `${r} ${o}` : r, n = Array.isArray(t) ? t.join("") : t || "";
61
61
  if (r) {
62
- if (re.includes(r))
62
+ if (oe.includes(r))
63
63
  return `<${s}>`;
64
64
  } else return n;
65
65
  return `<${s}>${n}</${r}>`;
66
66
  }
67
- function ae(r = {}) {
67
+ function le(r = {}) {
68
68
  const e = /* @__PURE__ */ new Map(), {
69
69
  renderFn: t = D,
70
- textFn: o = ie,
70
+ textFn: o = ae,
71
71
  resolvers: s = {},
72
72
  optimizeImages: n = !1,
73
73
  keyedResolvers: l = !1
@@ -76,20 +76,20 @@ function ae(r = {}) {
76
76
  return p.render(i, f, u.children || null);
77
77
  }, h = (i, u) => {
78
78
  const { src: p, alt: f, title: m, srcset: w, sizes: b } = i.attrs || {};
79
- let k = p, $ = {};
79
+ let k = p, R = {};
80
80
  if (n) {
81
- const { src: ee, attrs: te } = se(p, n);
82
- k = ee, $ = te;
81
+ const { src: te, attrs: se } = re(p, n);
82
+ k = te, R = se;
83
83
  }
84
- const Z = {
84
+ const ee = {
85
85
  src: k,
86
86
  alt: f,
87
87
  title: m,
88
88
  srcset: w,
89
89
  sizes: b,
90
- ...$
90
+ ...R
91
91
  };
92
- return u.render("img", O(Z));
92
+ return u.render("img", O(ee));
93
93
  }, d = (i, u) => {
94
94
  const { level: p, ...f } = i.attrs || {};
95
95
  return u.render(`h${p}`, f, i.children);
@@ -111,13 +111,13 @@ function ae(r = {}) {
111
111
  "pre",
112
112
  i.attrs || {},
113
113
  u.render("code", {}, i.children || "")
114
- ), R = (i, u = !1) => ({ text: p, attrs: f }, m) => {
115
- const { class: w, id: b, ...k } = f || {}, $ = u ? {
114
+ ), $ = (i, u = !1) => ({ text: p, attrs: f }, m) => {
115
+ const { class: w, id: b, ...k } = f || {}, R = u ? {
116
116
  class: w,
117
117
  id: b,
118
- style: ne(k) || void 0
118
+ style: ie(k) || void 0
119
119
  } : f || {};
120
- return m.render(i, O($), p);
120
+ return m.render(i, O(R), p);
121
121
  }, A = (i) => C(i), I = (i) => {
122
122
  const { marks: u, ...p } = i;
123
123
  if ("text" in i) {
@@ -154,33 +154,33 @@ function ae(r = {}) {
154
154
  }
155
155
  const k = { ...w };
156
156
  return b && (k.href = b), u.render("a", k, i.text);
157
- }, J = (i, u) => {
157
+ }, Y = (i, u) => {
158
158
  var p, f;
159
159
  return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), u.render("span", {
160
160
  blok: (p = i == null ? void 0 : i.attrs) == null ? void 0 : p.body[0],
161
161
  id: (f = i.attrs) == null ? void 0 : f.id,
162
162
  style: "display: none"
163
163
  });
164
- }, Y = (i, u) => {
164
+ }, K = (i, u) => {
165
165
  const p = {}, f = u.render("tbody", {}, i.children);
166
166
  return u.render("table", p, f);
167
- }, K = (i, u) => {
167
+ }, W = (i, u) => {
168
168
  const p = {};
169
169
  return u.render("tr", p, i.children);
170
- }, W = (i, u) => {
170
+ }, X = (i, u) => {
171
171
  const { colspan: p, rowspan: f, colwidth: m, backgroundColor: w, ...b } = i.attrs || {}, k = {
172
172
  ...b
173
173
  };
174
174
  p > 1 && (k.colspan = p), f > 1 && (k.rowspan = f);
175
- const $ = [];
176
- return m && $.push(`width: ${m}px;`), w && $.push(`background-color: ${w};`), $.length > 0 && (k.style = $.join(" ")), u.render("td", O(k), i.children);
177
- }, X = (i, u) => {
175
+ const R = [];
176
+ return m && R.push(`width: ${m}px;`), w && R.push(`background-color: ${w};`), R.length > 0 && (k.style = R.join(" ")), u.render("td", O(k), i.children);
177
+ }, Q = (i, u) => {
178
178
  const { colspan: p, rowspan: f, colwidth: m, backgroundColor: w, ...b } = i.attrs || {}, k = {
179
179
  ...b
180
180
  };
181
181
  p > 1 && (k.colspan = p), f > 1 && (k.rowspan = f);
182
- const $ = [];
183
- return m && $.push(`width: ${m}px;`), w && $.push(`background-color: ${w};`), $.length > 0 && (k.style = $.join(" ")), u.render("th", O(k), i.children);
182
+ const R = [];
183
+ return m && R.push(`width: ${m}px;`), w && R.push(`background-color: ${w};`), R.length > 0 && (k.style = R.join(" ")), u.render("th", O(k), i.children);
184
184
  }, B = /* @__PURE__ */ new Map([
185
185
  [v.DOCUMENT, a("")],
186
186
  [v.HEADING, d],
@@ -194,28 +194,28 @@ function ae(r = {}) {
194
194
  [v.HR, a("hr")],
195
195
  [v.BR, a("br")],
196
196
  [v.QUOTE, a("blockquote")],
197
- [v.COMPONENT, J],
198
- [V.TEXT, I],
197
+ [v.COMPONENT, Y],
198
+ [F.TEXT, I],
199
199
  [_.LINK, H],
200
200
  [_.ANCHOR, H],
201
- [_.STYLED, R("span", !0)],
202
- [_.BOLD, R("strong")],
203
- [_.TEXT_STYLE, R("span", !0)],
204
- [_.ITALIC, R("em")],
205
- [_.UNDERLINE, R("u")],
206
- [_.STRIKE, R("s")],
207
- [_.CODE, R("code")],
208
- [_.SUPERSCRIPT, R("sup")],
209
- [_.SUBSCRIPT, R("sub")],
210
- [_.HIGHLIGHT, R("mark")],
211
- [v.TABLE, Y],
212
- [v.TABLE_ROW, K],
213
- [v.TABLE_CELL, W],
214
- [v.TABLE_HEADER, X]
201
+ [_.STYLED, $("span", !0)],
202
+ [_.BOLD, $("strong")],
203
+ [_.TEXT_STYLE, $("span", !0)],
204
+ [_.ITALIC, $("em")],
205
+ [_.UNDERLINE, $("u")],
206
+ [_.STRIKE, $("s")],
207
+ [_.CODE, $("code")],
208
+ [_.SUPERSCRIPT, $("sup")],
209
+ [_.SUBSCRIPT, $("sub")],
210
+ [_.HIGHLIGHT, $("mark")],
211
+ [v.TABLE, K],
212
+ [v.TABLE_ROW, W],
213
+ [v.TABLE_CELL, X],
214
+ [v.TABLE_HEADER, Q]
215
215
  ]), U = new Map([
216
216
  ...B,
217
217
  ...Object.entries(s).map(([i, u]) => [i, u])
218
- ]), Q = () => ({
218
+ ]), Z = () => ({
219
219
  render: (i, u = {}, p) => {
220
220
  if (l && i) {
221
221
  const f = e.get(i) || 0;
@@ -230,7 +230,7 @@ function ae(r = {}) {
230
230
  const u = U.get(i.type);
231
231
  if (!u)
232
232
  return console.error("<Storyblok>", `No resolver found for node type ${i.type}`), "";
233
- const p = Q();
233
+ const p = Z();
234
234
  if (i.type === "text")
235
235
  return u(i, p);
236
236
  const f = i.content ? i.content.map(C) : void 0;
@@ -247,7 +247,7 @@ function ae(r = {}) {
247
247
  };
248
248
  }
249
249
  let M = !1;
250
- const z = [], q = (r) => new Promise((e, t) => {
250
+ const z = [], J = (r) => new Promise((e, t) => {
251
251
  if (typeof window > "u") {
252
252
  t(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));
253
253
  return;
@@ -267,13 +267,13 @@ const z = [], q = (r) => new Promise((e, t) => {
267
267
  z.forEach((n) => n()), M = !0, e(s);
268
268
  }, document.getElementsByTagName("head")[0].appendChild(o);
269
269
  });
270
- var le = Object.defineProperty, ce = (r, e, t) => e in r ? le(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, g = (r, e, t) => ce(r, typeof e != "symbol" ? e + "" : e, t);
271
- class he extends Error {
270
+ var ce = Object.defineProperty, he = (r, e, t) => e in r ? ce(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, g = (r, e, t) => he(r, typeof e != "symbol" ? e + "" : e, t);
271
+ class ue extends Error {
272
272
  constructor(e) {
273
273
  super(e), this.name = "AbortError";
274
274
  }
275
275
  }
276
- function ue(r, e, t) {
276
+ function de(r, e, t) {
277
277
  if (!Number.isFinite(e))
278
278
  throw new TypeError("Expected `limit` to be a finite number");
279
279
  if (!Number.isFinite(t))
@@ -307,11 +307,11 @@ function ue(r, e, t) {
307
307
  });
308
308
  return a.abort = () => {
309
309
  l = !0, s.forEach(clearTimeout), s = [], o.forEach(
310
- (h) => h.reject(() => new he("Throttle function aborted"))
310
+ (h) => h.reject(() => new ue("Throttle function aborted"))
311
311
  ), o.length = 0;
312
312
  }, a;
313
313
  }
314
- const de = (r = "") => r.includes("/cdn/"), pe = (r, e = 25, t = 1) => ({
314
+ const G = (r = "") => r.includes("/cdn/"), pe = (r, e = 25, t = 1) => ({
315
315
  ...r,
316
316
  per_page: e,
317
317
  page: t
@@ -335,7 +335,7 @@ const de = (r = "") => r.includes("/cdn/"), pe = (r, e = 25, t = 1) => ({
335
335
  ) : c = `${e ? e + encodeURIComponent(`[${l}]`) : l}=${encodeURIComponent(n)}`, o.push(c);
336
336
  }
337
337
  return o.join("&");
338
- }, F = (r) => {
338
+ }, V = (r) => {
339
339
  const e = {
340
340
  eu: "api.storyblok.com",
341
341
  us: "api-us.storyblok.com",
@@ -448,12 +448,12 @@ class ve {
448
448
  });
449
449
  }
450
450
  }
451
- const G = "SB-Agent", P = {
451
+ const q = "SB-Agent", P = {
452
452
  defaultAgentName: "SB-JS-CLIENT",
453
453
  defaultAgentVersion: "SB-Agent-Version",
454
- packageVersion: "6.0.0"
454
+ packageVersion: "7.0.0"
455
455
  }, ke = {
456
- DRAFT: "draft"
456
+ PUBLISHED: "published"
457
457
  };
458
458
  let j = {};
459
459
  const E = {};
@@ -468,21 +468,21 @@ class we {
468
468
  let o = e.endpoint || t;
469
469
  if (!o) {
470
470
  const l = e.https === !1 ? "http" : "https";
471
- e.oauthToken ? o = `${l}://${F(e.region)}/v1` : o = `${l}://${F(e.region)}/v2`;
471
+ e.oauthToken ? o = `${l}://${V(e.region)}/v1` : o = `${l}://${V(e.region)}/v2`;
472
472
  }
473
473
  const s = new Headers();
474
474
  s.set("Content-Type", "application/json"), s.set("Accept", "application/json"), e.headers && (e.headers.constructor.name === "Headers" ? e.headers.entries().toArray() : Object.entries(e.headers)).forEach(([l, c]) => {
475
475
  s.set(l, c);
476
- }), s.has(G) || (s.set(G, P.defaultAgentName), s.set(
476
+ }), s.has(q) || (s.set(q, P.defaultAgentName), s.set(
477
477
  P.defaultAgentVersion,
478
478
  P.packageVersion
479
479
  ));
480
480
  let n = 5;
481
- e.oauthToken && (s.set("Authorization", e.oauthToken), n = 3), e.rateLimit && (n = e.rateLimit), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = ue(
481
+ e.oauthToken && (s.set("Authorization", e.oauthToken), n = 3), e.rateLimit && (n = e.rateLimit), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = de(
482
482
  this.throttledRequest.bind(this),
483
483
  n,
484
484
  1e3
485
- ), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.version = e.version || ke.DRAFT, this.inlineAssets = e.inlineAssets || !1, this.client = new ve({
485
+ ), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.version = e.version || ke.PUBLISHED, this.inlineAssets = e.inlineAssets || !1, this.client = new ve({
486
486
  baseURL: o,
487
487
  timeout: e.timeout || 0,
488
488
  headers: s,
@@ -494,7 +494,7 @@ class we {
494
494
  return e.token || (e.token = this.getToken()), e.cv || (e.cv = E[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
495
495
  }
496
496
  factoryParamOptions(e, t) {
497
- return de(e) ? this.parseParams(t) : t;
497
+ return G(e) ? this.parseParams(t) : t;
498
498
  }
499
499
  makeRequest(e, t, o, s, n) {
500
500
  const l = this.factoryParamOptions(
@@ -506,7 +506,7 @@ class we {
506
506
  get(e, t = {}, o) {
507
507
  t || (t = {});
508
508
  const s = `/${e}`;
509
- t.version = t.version || this.version;
509
+ G(s) && (t.version = t.version || this.version);
510
510
  const n = this.factoryParamOptions(s, t);
511
511
  return this.cacheResponse(s, n, void 0, o);
512
512
  }
@@ -734,8 +734,8 @@ class we {
734
734
  perPage: d.headers["per-page"] ? Number.parseInt(d.headers["per-page"]) : 0,
735
735
  total: d.headers["per-page"] ? Number.parseInt(d.headers.total) : 0
736
736
  })), y.data.story || y.data.stories) {
737
- const R = this.resolveCounter = ++this.resolveCounter % 1e3;
738
- await this.resolveStories(y.data, t, `${R}`), y = await this.processInlineAssets(y);
737
+ const $ = this.resolveCounter = ++this.resolveCounter % 1e3;
738
+ await this.resolveStories(y.data, t, `${$}`), y = await this.processInlineAssets(y);
739
739
  }
740
740
  t.version === "published" && e !== "/cdn/spaces/me" && await l.set(n, y);
741
741
  const T = this.cache.clear === "onpreview" && t.version === "draft" || this.cache.clear === "auto";
@@ -834,7 +834,7 @@ const Te = (r = {}) => {
834
834
  return;
835
835
  }
836
836
  return { storyblokApi: new we(e) };
837
- }, Re = (r) => {
837
+ }, $e = (r) => {
838
838
  if (typeof r != "object" || typeof r._editable > "u")
839
839
  return {};
840
840
  try {
@@ -850,7 +850,7 @@ const Te = (r = {}) => {
850
850
  }
851
851
  };
852
852
  let x = "https://app.storyblok.com/f/storyblok-v2-latest.js";
853
- const $e = (r, e, t = {}) => {
853
+ const Re = (r, e, t = {}) => {
854
854
  var c;
855
855
  const s = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", n = new URL((c = window.location) == null ? void 0 : c.href).searchParams.get(
856
856
  "_storyblok"
@@ -883,22 +883,22 @@ const $e = (r, e, t = {}) => {
883
883
  c = { ...c, ...T(l) };
884
884
  }), n && (x = n);
885
885
  const h = !(typeof window > "u") && ((y = (d = window.location) == null ? void 0 : d.search) == null ? void 0 : y.includes("_storyblok_tk"));
886
- return e !== !1 && h && q(x), c;
886
+ return e !== !1 && h && J(x), c;
887
887
  };
888
888
  function Ee(r, e) {
889
- return ae(e).render(r);
889
+ return le(e).render(r);
890
890
  }
891
- const Ae = () => q(x);
891
+ const Ae = () => J(x);
892
892
  export {
893
893
  v as BlockTypes,
894
894
  _ as MarkTypes,
895
- V as TextTypes,
895
+ F as TextTypes,
896
896
  Te as apiPlugin,
897
897
  Ae as loadStoryblokBridge,
898
- $e as registerStoryblokBridge,
898
+ Re as registerStoryblokBridge,
899
899
  Ee as renderRichText,
900
- ae as richTextResolver,
901
- Re as storyblokEditable,
900
+ le as richTextResolver,
901
+ $e as storyblokEditable,
902
902
  _e as storyblokInit,
903
- $e as useStoryblokBridge
903
+ Re as useStoryblokBridge
904
904
  };
package/package.json CHANGED
@@ -1,16 +1,18 @@
1
1
  {
2
2
  "name": "@storyblok/js",
3
3
  "type": "module",
4
- "version": "4.0.4-rc.0",
4
+ "version": "4.1.1",
5
5
  "private": false,
6
6
  "description": "SDK to integrate Storyblok into your project using JavaScript.",
7
7
  "license": "MIT",
8
+ "homepage": "https://github.com/storyblok/monoblok/tree/main/packages/js#readme",
8
9
  "repository": {
9
10
  "type": "git",
10
- "url": "https://github.com/storyblok/storyblok-js"
11
+ "url": "https://github.com/storyblok/monoblok.git",
12
+ "directory": "packages/js"
11
13
  },
12
14
  "bugs": {
13
- "url": "https://github.com/storyblok/storyblok-js/issues"
15
+ "url": "https://github.com/storyblok/monoblok/issues"
14
16
  },
15
17
  "exports": {
16
18
  ".": {
@@ -26,14 +28,14 @@
26
28
  "dist"
27
29
  ],
28
30
  "dependencies": {
29
- "@storyblok/richtext": "3.3.2-rc.0",
30
- "storyblok-js-client": "npm:@storyblok/js-client@7.0.2-rc.0"
31
+ "@storyblok/richtext": "3.4.0",
32
+ "storyblok-js-client": "7.0.2"
31
33
  },
32
34
  "devDependencies": {
33
35
  "@storyblok/eslint-config": "^0.3.0",
34
36
  "@tsconfig/recommended": "^1.0.8",
35
- "@types/node": "^22.15.1",
36
- "@vitest/ui": "3.1.3",
37
+ "@types/node": "^22.15.18",
38
+ "@vitest/ui": "^3.1.3",
37
39
  "cypress": "^14.3.3",
38
40
  "eslint": "^9.26.0",
39
41
  "eslint-plugin-cypress": "^4.3.0",
@@ -56,7 +58,7 @@
56
58
  "nx": {
57
59
  "implicitDependencies": [
58
60
  "!@storyblok/playground-*",
59
- "@storyblok/js-client"
61
+ "storyblok-js-client"
60
62
  ]
61
63
  },
62
64
  "scripts": {