@storyblok/js 2.2.3 → 2.2.4

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -32,8 +32,6 @@
32
32
 
33
33
  ## 🚀 Usage
34
34
 
35
- <!-- -->
36
-
37
35
  > If you are first-time user of the Storyblok, read the [Getting Started](https://www.storyblok.com/docs/guide/getting-started?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-js) guide to get a project ready in less than 5 minutes.
38
36
 
39
37
  ### Installation
@@ -1,4 +1,4 @@
1
- (function(d,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(d=typeof globalThis<"u"?globalThis:d||self,g(d.storyblok={}))})(this,function(d){"use strict";let g=!1;const O=[],v=n=>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}g?r():O.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=n,s.id="storyblok-javascript-bridge",s.onerror=r=>t(r),s.onload=r=>{O.forEach(o=>o()),g=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var C=Object.defineProperty,G=(n,e,t)=>e in n?C(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,h=(n,e,t)=>(G(n,typeof e!="symbol"?e+"":e,t),t);function N(n){return!(n!==n||n===1/0||n===-1/0)}function x(n,e,t){if(!N(e))throw new TypeError("Expected `limit` to be a finite number");if(!N(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],o=0;const i=function(){o++;const a=setTimeout(function(){o--,s.length>0&&i(),r=r.filter(function(u){return u!==a})},t);r.indexOf(a)<0&&r.push(a);const l=s.shift();l.resolve(n.apply(l.self,l.args))},c=function(...a){const l=this;return new Promise(function(u,p){s.push({resolve:u,reject:p,args:a,self:l}),o<e&&i()})};return c.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},c}const B=function(n,e){const t={};for(const s in n){const r=n[s];e.indexOf(s)>-1&&r!==null&&(t[s]=r)}return t},$=n=>n==="email",M=()=>({singleTag:"hr"}),D=()=>({tag:"blockquote"}),L=()=>({tag:"ul"}),V=n=>({tag:["pre",{tag:"code",attrs:n.attrs}]}),F=()=>({singleTag:"br"}),W=n=>({tag:`h${n.attrs.level}`}),K=n=>({singleTag:[{tag:"img",attrs:B(n.attrs,["src","alt","title"])}]}),q=()=>({tag:"li"}),z=()=>({tag:"ol"}),X=()=>({tag:"p"}),Y=n=>({tag:[{tag:"span",attrs:{["data-type"]:"emoji",["data-name"]:n.attrs.name,emoji:n.attrs.emoji}}]}),J=()=>({tag:"b"}),Z=()=>({tag:"strike"}),Q=()=>({tag:"u"}),ee=()=>({tag:"strong"}),te=()=>({tag:"code"}),se=()=>({tag:"i"}),re=n=>{const e={...n.attrs},{linktype:t="url"}=n.attrs;if($(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),e.custom){for(const s in e.custom)e[s]=e.custom[s];delete e.custom}return{tag:[{tag:"a",attrs:e}]}},oe=n=>({tag:[{tag:"span",attrs:n.attrs}]}),ne=()=>({tag:"sub"}),ie=()=>({tag:"sup"}),ae=n=>({tag:[{tag:"span",attrs:n.attrs}]}),le=n=>{var e;return(e=n.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${n.attrs.color};`}}]}:{tag:""}},ce=n=>{var e;return(e=n.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${n.attrs.color}`}}]}:{tag:""}},A={nodes:{horizontal_rule:M,blockquote:D,bullet_list:L,code_block:V,hard_break:F,heading:W,image:K,list_item:q,ordered_list:z,paragraph:X,emoji:Y},marks:{bold:J,strike:Z,underline:Q,strong:ee,code:te,italic:se,link:re,styled:oe,subscript:ne,superscript:ie,anchor:ae,highlight:le,textStyle:ce}},he=function(n){const e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},t=/[&<>"']/g,s=RegExp(t.source);return n&&s.test(n)?n.replace(t,r=>e[r]):n};class f{constructor(e){h(this,"marks"),h(this,"nodes"),e||(e=A),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}){if(e&&e.content&&Array.isArray(e.content)){let s="";return e.content.forEach(r=>{s+=this.renderNode(r)}),t.optimizeImages?this.optimizeImages(s,t.optimizeImages):s}return console.warn(`The render method must receive an Object with a "content" field.
1
+ (function(d,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(d=typeof globalThis<"u"?globalThis:d||self,g(d.storyblok={}))})(this,function(d){"use strict";let g=!1;const O=[],v=n=>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}g?r():O.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=n,s.id="storyblok-javascript-bridge",s.onerror=r=>t(r),s.onload=r=>{O.forEach(o=>o()),g=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var G=Object.defineProperty,C=(n,e,t)=>e in n?G(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,h=(n,e,t)=>(C(n,typeof e!="symbol"?e+"":e,t),t);function N(n){return!(n!==n||n===1/0||n===-1/0)}function x(n,e,t){if(!N(e))throw new TypeError("Expected `limit` to be a finite number");if(!N(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],o=0;const i=function(){o++;const a=setTimeout(function(){o--,s.length>0&&i(),r=r.filter(function(u){return u!==a})},t);r.indexOf(a)<0&&r.push(a);const l=s.shift();l.resolve(n.apply(l.self,l.args))},c=function(...a){const l=this;return new Promise(function(u,p){s.push({resolve:u,reject:p,args:a,self:l}),o<e&&i()})};return c.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},c}const B=function(n,e){const t={};for(const s in n){const r=n[s];e.indexOf(s)>-1&&r!==null&&(t[s]=r)}return t},$=n=>n==="email",D=()=>({singleTag:"hr"}),M=()=>({tag:"blockquote"}),L=()=>({tag:"ul"}),V=n=>({tag:["pre",{tag:"code",attrs:n.attrs}]}),F=()=>({singleTag:"br"}),W=n=>({tag:`h${n.attrs.level}`}),K=n=>({singleTag:[{tag:"img",attrs:B(n.attrs,["src","alt","title"])}]}),X=()=>({tag:"li"}),z=()=>({tag:"ol"}),q=()=>({tag:"p"}),J=n=>({tag:[{tag:"span",attrs:{["data-type"]:"emoji",["data-name"]:n.attrs.name,emoji:n.attrs.emoji}}]}),Y=()=>({tag:"b"}),Z=()=>({tag:"strike"}),Q=()=>({tag:"u"}),ee=()=>({tag:"strong"}),te=()=>({tag:"code"}),se=()=>({tag:"i"}),re=n=>{const e={...n.attrs},{linktype:t="url"}=n.attrs;if($(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),e.custom){for(const s in e.custom)e[s]=e.custom[s];delete e.custom}return{tag:[{tag:"a",attrs:e}]}},oe=n=>({tag:[{tag:"span",attrs:n.attrs}]}),ne=()=>({tag:"sub"}),ie=()=>({tag:"sup"}),ae=n=>({tag:[{tag:"span",attrs:n.attrs}]}),le=n=>{var e;return(e=n.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${n.attrs.color};`}}]}:{tag:""}},ce=n=>{var e;return(e=n.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${n.attrs.color}`}}]}:{tag:""}},A={nodes:{horizontal_rule:D,blockquote:M,bullet_list:L,code_block:V,hard_break:F,heading:W,image:K,list_item:X,ordered_list:z,paragraph:q,emoji:J},marks:{bold:Y,strike:Z,underline:Q,strong:ee,code:te,italic:se,link:re,styled:oe,subscript:ne,superscript:ie,anchor:ae,highlight:le,textStyle:ce}},he=function(n){const e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},t=/[&<>"']/g,s=RegExp(t.source);return n&&s.test(n)?n.replace(t,r=>e[r]):n};class b{constructor(e){h(this,"marks"),h(this,"nodes"),e||(e=A),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}){if(e&&e.content&&Array.isArray(e.content)){let s="";return e.content.forEach(r=>{s+=this.renderNode(r)}),t.optimizeImages?this.optimizeImages(s,t.optimizeImages):s}return console.warn(`The render method must receive an Object with a "content" field.
2
2
  The "content" field must be an array of nodes as the type ISbRichtext.
3
3
  ISbRichtext:
4
4
  content?: ISbRichtext[]
@@ -21,4 +21,4 @@
21
21
  }
22
22
  ],
23
23
  type: 'doc'
24
- }`),""}optimizeImages(e,t){let s=0,r=0,o="",i="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(o+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(o+=`height="${t.height}" `,r=t.height),(t.loading==="lazy"||t.loading==="eager")&&(o+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(o+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(i+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(i+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(i+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(i+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(i+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(i+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(i+=`:rotate(${t.filters.rotate})`),i.length>0&&(i="/filters"+i))),o.length>0&&(e=e.replace(/<img/g,`<img ${o.trim()}`));const c=s>0||r>0||i.length>0?`${s}x${r}${i}`:"";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/${c}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var l,u;const p=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(p&&p.length>0){const _={srcset:(l=t.srcset)==null?void 0:l.map(m=>{if(typeof m=="number")return`//${p}/m/${m}x0${i} ${m}w`;if(typeof m=="object"&&m.length===2){let I=0,P=0;return typeof m[0]=="number"&&(I=m[0]),typeof m[1]=="number"&&(P=m[1]),`//${p}/m/${I}x${P}${i} ${I}w`}}).join(", "),sizes:(u=t.sizes)==null?void 0:u.map(m=>m).join(", ")};let E="";return _.srcset&&(E+=`srcset="${_.srcset}" `),_.sizes&&(E+=`sizes="${_.sizes}" `),a.replace(/<img/g,`<img ${E.trim()}`)}return a})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const o=this.getMatchingMark(r);o&&o.tag!==""&&t.push(this.renderOpeningTag(o.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(he(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html?t.push(s.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const o=this.getMatchingMark(r);o&&o.tag!==""&&t.push(this.renderClosingTag(o.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let r=`<${s.tag}`;if(s.attrs)for(const o in s.attrs){const i=s.attrs[o];i!==null&&(r+=` ${o}="${i}"`)}return`${r}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}renderEmoji(e){if(e.attrs.emoji)return e.attrs.emoji;const t=[{tag:"img",attrs:{src:e.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(t," /")}}class y{constructor(){h(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1),h(this,"getOptionsPage",(e,t=25,s=1)=>({...e,per_page:t,page:s})),h(this,"delay",e=>new Promise(t=>setTimeout(t,e))),h(this,"arrayFrom",(e=0,t)=>[...Array(e)].map(t)),h(this,"range",(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return this.arrayFrom(s,(o,i)=>i*r+e)}),h(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),h(this,"flatMap",(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[]))}stringify(e,t,s){const r=[];for(const o in e){if(!Object.prototype.hasOwnProperty.call(e,o))continue;const i=e[o],c=s?"":encodeURIComponent(o);let a;typeof i=="object"?a=this.stringify(i,t?t+encodeURIComponent("["+c+"]"):c,Array.isArray(i)):a=(t?t+encodeURIComponent("["+c+"]"):c)+"="+encodeURIComponent(i),r.push(a)}return r.join("&")}getRegionURL(e){const t="api.storyblok.com",s="api-us.storyblok.com",r="app.storyblokchina.cn";switch(e){case"us":return s;case"cn":return r;default:return t}}}class ue{constructor(e){h(this,"baseURL"),h(this,"timeout"),h(this,"headers"),h(this,"responseInterceptor"),h(this,"fetch"),h(this,"ejectInterceptor"),h(this,"url"),h(this,"parameters"),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={}}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 y;t=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),o=new AbortController,{signal:i}=o;let c;this.timeout&&(c=setTimeout(()=>o.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:i});this.timeout&&clearTimeout(c);const l=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(l)):this._statusHandler(l)}catch(a){return{message:a}}}eject(){this.ejectInterceptor=!0}_statusHandler(e){const t=/20[0-6]/g;return new Promise((s,r)=>{if(t.test(`${e.status}`))return s(e);const o={message:new Error(e.statusText),status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};r(o)})}}const w="SB-Agent",k={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"2.2.3"};let T={};const b={};class de{constructor(e,t){h(this,"client"),h(this,"maxRetries"),h(this,"throttle"),h(this,"accessToken"),h(this,"cache"),h(this,"helpers"),h(this,"resolveCounter"),h(this,"relations"),h(this,"links"),h(this,"richTextResolver"),h(this,"resolveNestedRelations");let s=e.endpoint||t;if(!s){const i=new y().getRegionURL,c=e.https===!1?"http":"https";e.oauthToken?s=`${c}://${i(e.region)}/v1`:s=`${c}://${i(e.region)}/v2`}const r=new Headers;if(r.set("Content-Type","application/json"),r.set("Accept","application/json"),e.headers)for(const i in e.headers)r.set(i,e.headers[i]);r.has(w)||(r.set(w,k.defaultAgentName),r.set(k.defaultAgentVersion,k.packageVersion));let o=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),o=3),e.rateLimit&&(o=e.rateLimit),e.richTextSchema?this.richTextResolver=new f(e.richTextSchema):this.richTextResolver=new f,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=x(this.throttledRequest,o,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new y,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.client=new ue({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.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=b[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t){return this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,r){const o=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,o)}get(e,t){t||(t={});const s=`/${e}`,r=this.factoryParamOptions(s,t);return this.cacheResponse(s,r)}async getAll(e,t,s){const r=(t==null?void 0:t.per_page)||25,o=`/${e}`,i=o.split("/"),c=s||i[i.length-1],a=1,l=await this.makeRequest(o,t,r,a),u=l.total?Math.ceil(l.total/r):1,p=await this.helpers.asyncMap(this.helpers.range(a,u),_=>this.makeRequest(o,t,r,_+1));return this.helpers.flatMap([l,...p],_=>Object.values(_.data[c]))}post(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("post",s,t))}put(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("put",s,t))}delete(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("delete",s,t))}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_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]))}_insertRelations(e,t,s,r){if(s.indexOf(`${e.component}.${t}`)>-1){if(typeof e[t]=="string")this.relations[r][e[t]]&&(e[t]=this._cleanCopy(this.relations[r][e[t]]));else if(e[t]&&e[t].constructor===Array){const o=[];e[t].forEach(i=>{this.relations[r][i]&&o.push(this._cleanCopy(this.relations[r][i]))}),e[t]=o}}}iterateTree(e,t,s){const r=o=>{if(o!=null){if(o.constructor===Array)for(let i=0;i<o.length;i++)r(o[i]);else if(o.constructor===Object){if(o._stopResolving)return;for(const i in o)(o.component&&o._uid||o.type==="link")&&(this._insertRelations(o,i,t,s),this._insertLinks(o,i,s)),r(o[i])}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const o=e.link_uuids.length,i=[],c=50;for(let a=0;a<o;a+=c){const l=Math.min(o,a+c);i.push(e.link_uuids.slice(a,l))}for(let a=0;a<i.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:i[a].join(",")})).data.stories.forEach(l=>{r.push(l)})}else r=e.links;r.forEach(o=>{this.links[s][o.uuid]={...o,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const o=e.rel_uuids.length,i=[],c=50;for(let a=0;a<o;a+=c){const l=Math.min(o,a+c);i.push(e.rel_uuids.slice(a,l))}for(let a=0;a<i.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:i[a].join(",")})).data.stories.forEach(l=>{r.push(l)})}else r=e.rels;r&&r.length>0&&r.forEach(o=>{this.relations[s][o.uuid]={...o,_stopResolving:!0}})}async resolveStories(e,t,s){var r,o;let i=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(i=t.resolve_relations.split(",")),await this.resolveRelations(e,t,s)),t.resolve_links&&["1","story","url"].indexOf(t.resolve_links)>-1&&((r=e.links)!=null&&r.length||(o=e.link_uuids)!=null&&o.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const c in this.relations[s])this.iterateTree(this.relations[s][c],i,s);e.story?this.iterateTree(e.story,i,s):e.stories.forEach(c=>{this.iterateTree(c,i,s)}),delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s){const r=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 i=await o.get(r);if(i)return Promise.resolve(i)}return new Promise((i,c)=>{try{(async()=>{var a;try{const l=await this.throttle("get",e,t);let u={data:l.data,headers:l.headers};if((a=l.headers)!=null&&a["per-page"]&&(u=Object.assign({},u,{perPage:l.headers["per-page"]?parseInt(l.headers["per-page"]):0,total:l.headers["per-page"]?parseInt(l.headers.total):0})),l.status!=200)return c(l);if(u.data.story||u.data.stories){const p=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(u.data,t,`${p}`)}return t.version==="published"&&e!="/cdn/spaces/me"&&await o.set(r,u),u.data.cv&&t.token&&(t.version=="draft"&&b[t.token]!=u.data.cv&&await this.flushCache(),b[t.token]=u.data.cv),i(u)}catch(l){return c(l)}})()}catch{}})}throttledRequest(e,t,s){return this.client[e](t,s)}cacheVersions(){return b}cacheVersion(){return b[this.accessToken]}setCacheVersion(e){this.accessToken&&(b[this.accessToken]=e)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(T[e])},getAll(){return Promise.resolve(T)},set(e,t){return T[e]=t,Promise.resolve(void 0)},flush(){return T={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve(void 0)},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}}const pe=(n={})=>{const{apiOptions:e}=n;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 de(e)}},me=n=>{if(typeof n!="object"||typeof n._editable>"u")return{};const e=JSON.parse(n._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let R;const S="https://app.storyblok.com/f/storyblok-v2-latest.js",j=(n,e,t={})=>{var c;const r=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",i=+new URL((c=window.location)==null?void 0:c.href).searchParams.get("_storyblok")===n;if(!(!r||!i)){if(!n){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],l=>{l.action==="input"&&l.story.id===n?e(l.story):(l.action==="change"||l.action==="published")&&l.storyId===n&&window.location.reload()})})}},_e=(n={})=>{var u,p;const{bridge:e,accessToken:t,use:s=[],apiOptions:r={},richText:o={}}=n;r.accessToken=r.accessToken||t;const i={bridge:e,apiOptions:r};let c={};s.forEach(_=>{c={...c,..._(i)}});const l=!(typeof window>"u")&&((p=(u=window.location)==null?void 0:u.search)==null?void 0:p.includes("_storyblok_tk"));return e!==!1&&l&&v(S),R=new f(o.schema),o.resolver&&U(R,o.resolver),c},U=(n,e)=>{n.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},H=n=>{var e,t;return!n||((e=n==null?void 0:n.content)==null?void 0:e[0].type)!=="blok"&&!((t=n==null?void 0:n.content)!=null&&t[0].content)},ge=(n,e,t)=>{let s=t||R;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return H(n)?"":(e&&(s=new f(e.schema),e.resolver&&U(s,e.resolver)),s.render(n))},be=()=>v(S);d.RichTextResolver=f,d.RichTextSchema=A,d.apiPlugin=pe,d.isRichTextEmpty=H,d.loadStoryblokBridge=be,d.registerStoryblokBridge=j,d.renderRichText=ge,d.storyblokEditable=me,d.storyblokInit=_e,d.useStoryblokBridge=j,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
24
+ }`),""}optimizeImages(e,t){let s=0,r=0,o="",i="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(o+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(o+=`height="${t.height}" `,r=t.height),(t.loading==="lazy"||t.loading==="eager")&&(o+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(o+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(i+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(i+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(i+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(i+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(i+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(i+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(i+=`:rotate(${t.filters.rotate})`),i.length>0&&(i="/filters"+i))),o.length>0&&(e=e.replace(/<img/g,`<img ${o.trim()}`));const c=s>0||r>0||i.length>0?`${s}x${r}${i}`:"";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/${c}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var l,u;const p=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(p&&p.length>0){const _={srcset:(l=t.srcset)==null?void 0:l.map(m=>{if(typeof m=="number")return`//${p}/m/${m}x0${i} ${m}w`;if(typeof m=="object"&&m.length===2){let I=0,P=0;return typeof m[0]=="number"&&(I=m[0]),typeof m[1]=="number"&&(P=m[1]),`//${p}/m/${I}x${P}${i} ${I}w`}}).join(", "),sizes:(u=t.sizes)==null?void 0:u.map(m=>m).join(", ")};let E="";return _.srcset&&(E+=`srcset="${_.srcset}" `),_.sizes&&(E+=`sizes="${_.sizes}" `),a.replace(/<img/g,`<img ${E.trim()}`)}return a})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const o=this.getMatchingMark(r);o&&o.tag!==""&&t.push(this.renderOpeningTag(o.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(he(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html?t.push(s.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const o=this.getMatchingMark(r);o&&o.tag!==""&&t.push(this.renderClosingTag(o.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let r=`<${s.tag}`;if(s.attrs)for(const o in s.attrs){const i=s.attrs[o];i!==null&&(r+=` ${o}="${i}"`)}return`${r}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}renderEmoji(e){if(e.attrs.emoji)return e.attrs.emoji;const t=[{tag:"img",attrs:{src:e.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(t," /")}}class y{constructor(){h(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1),h(this,"getOptionsPage",(e,t=25,s=1)=>({...e,per_page:t,page:s})),h(this,"delay",e=>new Promise(t=>setTimeout(t,e))),h(this,"arrayFrom",(e=0,t)=>[...Array(e)].map(t)),h(this,"range",(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return this.arrayFrom(s,(o,i)=>i*r+e)}),h(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),h(this,"flatMap",(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[]))}stringify(e,t,s){const r=[];for(const o in e){if(!Object.prototype.hasOwnProperty.call(e,o))continue;const i=e[o],c=s?"":encodeURIComponent(o);let a;typeof i=="object"?a=this.stringify(i,t?t+encodeURIComponent("["+c+"]"):c,Array.isArray(i)):a=(t?t+encodeURIComponent("["+c+"]"):c)+"="+encodeURIComponent(i),r.push(a)}return r.join("&")}getRegionURL(e){const t="api.storyblok.com",s="api-us.storyblok.com",r="app.storyblokchina.cn";switch(e){case"us":return s;case"cn":return r;default:return t}}}class ue{constructor(e){h(this,"baseURL"),h(this,"timeout"),h(this,"headers"),h(this,"responseInterceptor"),h(this,"fetch"),h(this,"ejectInterceptor"),h(this,"url"),h(this,"parameters"),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={}}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 y;t=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),o=new AbortController,{signal:i}=o;let c;this.timeout&&(c=setTimeout(()=>o.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:i});this.timeout&&clearTimeout(c);const l=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(l)):this._statusHandler(l)}catch(a){return{message:a}}}eject(){this.ejectInterceptor=!0}_statusHandler(e){const t=/20[0-6]/g;return new Promise((s,r)=>{if(t.test(`${e.status}`))return s(e);const o={message:new Error(e.statusText),status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};r(o)})}}const w="SB-Agent",k={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"2.2.4"};let T={};const f={};class de{constructor(e,t){h(this,"client"),h(this,"maxRetries"),h(this,"throttle"),h(this,"accessToken"),h(this,"cache"),h(this,"helpers"),h(this,"resolveCounter"),h(this,"relations"),h(this,"links"),h(this,"richTextResolver"),h(this,"resolveNestedRelations");let s=e.endpoint||t;if(!s){const i=new y().getRegionURL,c=e.https===!1?"http":"https";e.oauthToken?s=`${c}://${i(e.region)}/v1`:s=`${c}://${i(e.region)}/v2`}const r=new Headers;if(r.set("Content-Type","application/json"),r.set("Accept","application/json"),e.headers)for(const i in e.headers)r.set(i,e.headers[i]);r.has(w)||(r.set(w,k.defaultAgentName),r.set(k.defaultAgentVersion,k.packageVersion));let o=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),o=3),e.rateLimit&&(o=e.rateLimit),e.richTextSchema?this.richTextResolver=new b(e.richTextSchema):this.richTextResolver=new b,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=x(this.throttledRequest,o,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new y,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.client=new ue({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.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=f[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t){return this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,r){const o=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,o)}get(e,t){t||(t={});const s=`/${e}`,r=this.factoryParamOptions(s,t);return this.cacheResponse(s,r)}async getAll(e,t,s){const r=(t==null?void 0:t.per_page)||25,o=`/${e}`,i=o.split("/"),c=s||i[i.length-1],a=1,l=await this.makeRequest(o,t,r,a),u=l.total?Math.ceil(l.total/r):1,p=await this.helpers.asyncMap(this.helpers.range(a,u),_=>this.makeRequest(o,t,r,_+1));return this.helpers.flatMap([l,...p],_=>Object.values(_.data[c]))}post(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("post",s,t))}put(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("put",s,t))}delete(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("delete",s,t))}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_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]))}_insertRelations(e,t,s,r){if(s.indexOf(`${e.component}.${t}`)>-1){if(typeof e[t]=="string")this.relations[r][e[t]]&&(e[t]=this._cleanCopy(this.relations[r][e[t]]));else if(e[t]&&e[t].constructor===Array){const o=[];e[t].forEach(i=>{this.relations[r][i]&&o.push(this._cleanCopy(this.relations[r][i]))}),e[t]=o}}}iterateTree(e,t,s){const r=o=>{if(o!=null){if(o.constructor===Array)for(let i=0;i<o.length;i++)r(o[i]);else if(o.constructor===Object){if(o._stopResolving)return;for(const i in o)(o.component&&o._uid||o.type==="link")&&(this._insertRelations(o,i,t,s),this._insertLinks(o,i,s)),r(o[i])}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const o=e.link_uuids.length,i=[],c=50;for(let a=0;a<o;a+=c){const l=Math.min(o,a+c);i.push(e.link_uuids.slice(a,l))}for(let a=0;a<i.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:i[a].join(",")})).data.stories.forEach(l=>{r.push(l)})}else r=e.links;r.forEach(o=>{this.links[s][o.uuid]={...o,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const o=e.rel_uuids.length,i=[],c=50;for(let a=0;a<o;a+=c){const l=Math.min(o,a+c);i.push(e.rel_uuids.slice(a,l))}for(let a=0;a<i.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:i[a].join(",")})).data.stories.forEach(l=>{r.push(l)})}else r=e.rels;r&&r.length>0&&r.forEach(o=>{this.relations[s][o.uuid]={...o,_stopResolving:!0}})}async resolveStories(e,t,s){var r,o;let i=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(i=t.resolve_relations.split(",")),await this.resolveRelations(e,t,s)),t.resolve_links&&["1","story","url"].indexOf(t.resolve_links)>-1&&((r=e.links)!=null&&r.length||(o=e.link_uuids)!=null&&o.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const c in this.relations[s])this.iterateTree(this.relations[s][c],i,s);e.story?this.iterateTree(e.story,i,s):e.stories.forEach(c=>{this.iterateTree(c,i,s)}),delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s){const r=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 i=await o.get(r);if(i)return Promise.resolve(i)}return new Promise((i,c)=>{try{(async()=>{var a;try{const l=await this.throttle("get",e,t);let u={data:l.data,headers:l.headers};if((a=l.headers)!=null&&a["per-page"]&&(u=Object.assign({},u,{perPage:l.headers["per-page"]?parseInt(l.headers["per-page"]):0,total:l.headers["per-page"]?parseInt(l.headers.total):0})),l.status!=200)return c(l);if(u.data.story||u.data.stories){const p=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(u.data,t,`${p}`)}return t.version==="published"&&e!="/cdn/spaces/me"&&await o.set(r,u),u.data.cv&&t.token&&(t.version=="draft"&&f[t.token]!=u.data.cv&&await this.flushCache(),f[t.token]=u.data.cv),i(u)}catch(l){return c(l)}})()}catch{}})}throttledRequest(e,t,s){return this.client[e](t,s)}cacheVersions(){return f}cacheVersion(){return f[this.accessToken]}setCacheVersion(e){this.accessToken&&(f[this.accessToken]=e)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(T[e])},getAll(){return Promise.resolve(T)},set(e,t){return T[e]=t,Promise.resolve(void 0)},flush(){return T={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve(void 0)},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}}const pe=(n={})=>{const{apiOptions:e}=n;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 de(e)}},me=n=>{if(typeof n!="object"||typeof n._editable>"u")return{};const e=JSON.parse(n._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let R;const S="https://app.storyblok.com/f/storyblok-v2-latest.js",j=(n,e,t={})=>{var c;const r=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",i=+new URL((c=window.location)==null?void 0:c.href).searchParams.get("_storyblok")===n;if(!(!r||!i)){if(!n){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],l=>{l.action==="input"&&l.story.id===n?e(l.story):(l.action==="change"||l.action==="published")&&l.storyId===n&&window.location.reload()})})}},_e=(n={})=>{var u,p;const{bridge:e,accessToken:t,use:s=[],apiOptions:r={},richText:o={}}=n;r.accessToken=r.accessToken||t;const i={bridge:e,apiOptions:r};let c={};s.forEach(_=>{c={...c,..._(i)}});const l=!(typeof window>"u")&&((p=(u=window.location)==null?void 0:u.search)==null?void 0:p.includes("_storyblok_tk"));return e!==!1&&l&&v(S),R=new b(o.schema),o.resolver&&U(R,o.resolver),c},U=(n,e)=>{n.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},H=n=>{var e,t;return!n||((e=n==null?void 0:n.content)==null?void 0:e[0].type)!=="blok"&&!((t=n==null?void 0:n.content)!=null&&t[0].content)},ge=(n,e,t)=>{let s=t||R;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return H(n)?"":(e&&(s=new b(e.schema),e.resolver&&U(s,e.resolver)),s.render(n))},fe=()=>v(S);d.RichTextResolver=b,d.RichTextSchema=A,d.apiPlugin=pe,d.isRichTextEmpty=H,d.loadStoryblokBridge=fe,d.registerStoryblokBridge=j,d.renderRichText=ge,d.storyblokEditable=me,d.storyblokInit=_e,d.useStoryblokBridge=j,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
@@ -60,9 +60,9 @@ const P = function(n, e) {
60
60
  e.indexOf(s) > -1 && r !== null && (t[s] = r);
61
61
  }
62
62
  return t;
63
- }, x = (n) => n === "email", C = () => ({
63
+ }, x = (n) => n === "email", G = () => ({
64
64
  singleTag: "hr"
65
- }), G = () => ({
65
+ }), C = () => ({
66
66
  tag: "blockquote"
67
67
  }), $ = () => ({
68
68
  tag: "ul"
@@ -76,9 +76,9 @@ const P = function(n, e) {
76
76
  ]
77
77
  }), D = () => ({
78
78
  singleTag: "br"
79
- }), M = (n) => ({
80
- tag: `h${n.attrs.level}`
81
79
  }), L = (n) => ({
80
+ tag: `h${n.attrs.level}`
81
+ }), M = (n) => ({
82
82
  singleTag: [
83
83
  {
84
84
  tag: "img",
@@ -102,15 +102,15 @@ const P = function(n, e) {
102
102
  }
103
103
  }
104
104
  ]
105
- }), q = () => ({
105
+ }), X = () => ({
106
106
  tag: "b"
107
107
  }), z = () => ({
108
108
  tag: "strike"
109
- }), X = () => ({
109
+ }), q = () => ({
110
110
  tag: "u"
111
- }), Y = () => ({
112
- tag: "strong"
113
111
  }), J = () => ({
112
+ tag: "strong"
113
+ }), Y = () => ({
114
114
  tag: "code"
115
115
  }), Z = () => ({
116
116
  tag: "i"
@@ -177,24 +177,24 @@ const P = function(n, e) {
177
177
  };
178
178
  }, ie = {
179
179
  nodes: {
180
- horizontal_rule: C,
181
- blockquote: G,
180
+ horizontal_rule: G,
181
+ blockquote: C,
182
182
  bullet_list: $,
183
183
  code_block: B,
184
184
  hard_break: D,
185
- heading: M,
186
- image: L,
185
+ heading: L,
186
+ image: M,
187
187
  list_item: V,
188
188
  ordered_list: F,
189
189
  paragraph: W,
190
190
  emoji: K
191
191
  },
192
192
  marks: {
193
- bold: q,
193
+ bold: X,
194
194
  strike: z,
195
- underline: X,
196
- strong: Y,
197
- code: J,
195
+ underline: q,
196
+ strong: J,
197
+ code: Y,
198
198
  italic: Z,
199
199
  link: Q,
200
200
  styled: ee,
@@ -484,7 +484,7 @@ class le {
484
484
  const N = "SB-Agent", y = {
485
485
  defaultAgentName: "SB-JS-CLIENT",
486
486
  defaultAgentVersion: "SB-Agent-Version",
487
- packageVersion: "2.2.3"
487
+ packageVersion: "2.2.4"
488
488
  };
489
489
  let g = {};
490
490
  const _ = {};
@@ -37,7 +37,7 @@ export interface ISbEventPayload<S extends ISbComponentType<string> = any> {
37
37
  reload?: boolean;
38
38
  }
39
39
  export interface StoryblokBridgeConfigV2 {
40
- resolveRelations?: string[];
40
+ resolveRelations?: string | string[];
41
41
  customParent?: string;
42
42
  preventClicks?: boolean;
43
43
  language?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storyblok/js",
3
- "version": "2.2.3",
3
+ "version": "2.2.4",
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",
@@ -38,7 +38,7 @@
38
38
  "isomorphic-fetch": "^3.0.0",
39
39
  "start-server-and-test": "^1.15.2",
40
40
  "vite": "^4.0.4",
41
- "vitest": "^0.32.4"
41
+ "vitest": "^0.33.0"
42
42
  },
43
43
  "babel": {
44
44
  "presets": [