Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

storyblok-js-client

Package Overview
Dependencies
Maintainers
7
Versions
197
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

storyblok-js-client - npm Package Compare versions

Comparing version 5.10.5 to 5.10.6

4

dist/index.umd.js

@@ -1,2 +0,2 @@

(function(g,f){typeof exports=="object"&&typeof module<"u"?module.exports=f():typeof define=="function"&&define.amd?define(f):(g=typeof globalThis<"u"?globalThis:g||self,g.StoryblokJSClient=f())})(this,function(){"use strict";var A=Object.defineProperty;var O=(g,f,m)=>f in g?A(g,f,{enumerable:!0,configurable:!0,writable:!0,value:m}):g[f]=m;var h=(g,f,m)=>(O(g,typeof f!="symbol"?f+"":f,m),m);function g(a){return!(a!==a||a===1/0||a===-1/0)}function f(a,t,e){if(!g(t))throw new TypeError("Expected `limit` to be a finite number");if(!g(e))throw new TypeError("Expected `interval` to be a finite number");const r=[];let s=[],i=0;const n=function(){i++;const o=setTimeout(function(){i--,r.length>0&&n(),s=s.filter(function(u){return u!==o})},e);s.indexOf(o)<0&&s.push(o);const l=r.shift();l.resolve(a.apply(l.self,l.args))},c=function(...o){const l=this;return new Promise(function(u,p){r.push({resolve:u,reject:p,args:o,self:l}),i<t&&n()})};return c.abort=function(){s.forEach(clearTimeout),s=[],r.forEach(function(o){o.reject(function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"})}),r.length=0},c}const m=function(a,t){const e={};for(const r in a){const s=a[r];t.indexOf(r)>-1&&s!==null&&(e[r]=s)}return e},C=a=>a==="email",w={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:a=>({tag:["pre",{tag:"code",attrs:a.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:a=>({tag:`h${a.attrs.level}`}),image:a=>({singleTag:[{tag:"img",attrs:m(a.attrs,["src","alt","title"])}]}),list_item:()=>({tag:"li"}),ordered_list:()=>({tag:"ol"}),paragraph:()=>({tag:"p"}),emoji:a=>({tag:[{tag:"span",attrs:{["data-type"]:"emoji",["data-name"]:a.attrs.name,emoji:a.attrs.emoji}}]})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link:a=>{const t={...a.attrs},{linktype:e="url"}=a.attrs;if(C(e)&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),t.custom){for(const r in t.custom)t[r]=t.custom[r];delete t.custom}return{tag:[{tag:"a",attrs:t}]}},styled:a=>({tag:[{tag:"span",attrs:a.attrs}]}),subscript:()=>({tag:"sub"}),superscript:()=>({tag:"sup"}),anchor:a=>({tag:[{tag:"span",attrs:a.attrs}]}),highlight:a=>({tag:[{tag:"span",attrs:{style:`background-color:${a.attrs.color};`}}]}),textStyle:a=>({tag:[{tag:"span",attrs:{style:`color:${a.attrs.color}`}}]})}},E=function(a){const t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},e=/[&<>"']/g,r=RegExp(e.source);return a&&r.test(a)?a.replace(e,s=>t[s]):a};class R{constructor(t){h(this,"marks");h(this,"nodes");t||(t=w),this.marks=t.marks||[],this.nodes=t.nodes||[]}addNode(t,e){this.nodes[t]=e}addMark(t,e){this.marks[t]=e}render(t,e={optimizeImages:!1}){if(t&&t.content&&Array.isArray(t.content)){let r="";return t.content.forEach(s=>{r+=this.renderNode(s)}),e.optimizeImages?this.optimizeImages(r,e.optimizeImages):r}return console.warn(`The render method must receive an Object with a "content" field.
(function(g,f){typeof exports=="object"&&typeof module<"u"?module.exports=f():typeof define=="function"&&define.amd?define(f):(g=typeof globalThis<"u"?globalThis:g||self,g.StoryblokJSClient=f())})(this,function(){"use strict";var A=Object.defineProperty;var O=(g,f,m)=>f in g?A(g,f,{enumerable:!0,configurable:!0,writable:!0,value:m}):g[f]=m;var h=(g,f,m)=>(O(g,typeof f!="symbol"?f+"":f,m),m);function g(a){return!(a!==a||a===1/0||a===-1/0)}function f(a,t,e){if(!g(t))throw new TypeError("Expected `limit` to be a finite number");if(!g(e))throw new TypeError("Expected `interval` to be a finite number");const r=[];let s=[],i=0;const n=function(){i++;const o=setTimeout(function(){i--,r.length>0&&n(),s=s.filter(function(u){return u!==o})},e);s.indexOf(o)<0&&s.push(o);const l=r.shift();l.resolve(a.apply(l.self,l.args))},c=function(...o){const l=this;return new Promise(function(u,p){r.push({resolve:u,reject:p,args:o,self:l}),i<t&&n()})};return c.abort=function(){s.forEach(clearTimeout),s=[],r.forEach(function(o){o.reject(function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"})}),r.length=0},c}const m=function(a,t){const e={};for(const r in a){const s=a[r];t.indexOf(r)>-1&&s!==null&&(e[r]=s)}return e},C=a=>a==="email",w={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:a=>({tag:["pre",{tag:"code",attrs:a.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:a=>({tag:`h${a.attrs.level}`}),image:a=>({singleTag:[{tag:"img",attrs:m(a.attrs,["src","alt","title"])}]}),list_item:()=>({tag:"li"}),ordered_list:()=>({tag:"ol"}),paragraph:()=>({tag:"p"}),emoji:a=>({tag:[{tag:"span",attrs:{["data-type"]:"emoji",["data-name"]:a.attrs.name,emoji:a.attrs.emoji}}]})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link:a=>{const t={...a.attrs},{linktype:e="url"}=a.attrs;if(C(e)&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),t.custom){for(const r in t.custom)t[r]=t.custom[r];delete t.custom}return{tag:[{tag:"a",attrs:t}]}},styled:a=>({tag:[{tag:"span",attrs:a.attrs}]}),subscript:()=>({tag:"sub"}),superscript:()=>({tag:"sup"}),anchor:a=>({tag:[{tag:"span",attrs:a.attrs}]}),highlight:a=>{var e;return(e=a.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${a.attrs.color};`}}]}:{tag:""}},textStyle:a=>{var e;return(e=a.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${a.attrs.color}`}}]}:{tag:""}}}},E=function(a){const t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},e=/[&<>"']/g,r=RegExp(e.source);return a&&r.test(a)?a.replace(e,s=>t[s]):a};class R{constructor(t){h(this,"marks");h(this,"nodes");t||(t=w),this.marks=t.marks||[],this.nodes=t.nodes||[]}addNode(t,e){this.nodes[t]=e}addMark(t,e){this.marks[t]=e}render(t,e={optimizeImages:!1}){if(t&&t.content&&Array.isArray(t.content)){let r="";return t.content.forEach(s=>{r+=this.renderNode(s)}),e.optimizeImages?this.optimizeImages(r,e.optimizeImages):r}return console.warn(`The render method must receive an Object with a "content" field.
The "content" field must be an array of nodes as the type ISbRichtext.

@@ -24,2 +24,2 @@ ISbRichtext:

type: 'doc'
}`),""}optimizeImages(t,e){let r=0,s=0,i="",n="";typeof e!="boolean"&&(typeof e.width=="number"&&e.width>0&&(i+=`width="${e.width}" `,r=e.width),typeof e.height=="number"&&e.height>0&&(i+=`height="${e.height}" `,s=e.height),(e.loading==="lazy"||e.loading==="eager")&&(i+=`loading="${e.loading}" `),typeof e.class=="string"&&e.class.length>0&&(i+=`class="${e.class}" `),e.filters&&(typeof e.filters.blur=="number"&&e.filters.blur>=0&&e.filters.blur<=100&&(n+=`:blur(${e.filters.blur})`),typeof e.filters.brightness=="number"&&e.filters.brightness>=-100&&e.filters.brightness<=100&&(n+=`:brightness(${e.filters.brightness})`),e.filters.fill&&(e.filters.fill.match(/[0-9A-Fa-f]{6}/g)||e.filters.fill==="transparent")&&(n+=`:fill(${e.filters.fill})`),e.filters.format&&["webp","png","jpeg"].includes(e.filters.format)&&(n+=`:format(${e.filters.format})`),typeof e.filters.grayscale=="boolean"&&e.filters.grayscale&&(n+=":grayscale()"),typeof e.filters.quality=="number"&&e.filters.quality>=0&&e.filters.quality<=100&&(n+=`:quality(${e.filters.quality})`),e.filters.rotate&&[90,180,270].includes(e.filters.rotate)&&(n+=`:rotate(${e.filters.rotate})`),n.length>0&&(n="/filters"+n))),i.length>0&&(t=t.replace(/<img/g,`<img ${i.trim()}`));const c=r>0||s>0||n.length>0?`${r}x${s}${n}`:"";return t=t.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${c}`),typeof e!="boolean"&&(e.sizes||e.srcset)&&(t=t.replace(/<img.*?src=["|'](.*?)["|']/g,o=>{var u,p;const l=o.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(l&&l.length>0){const y={srcset:(u=e.srcset)==null?void 0:u.map(d=>{if(typeof d=="number")return`//${l}/m/${d}x0${n} ${d}w`;if(typeof d=="object"&&d.length===2){let v=0,S=0;return typeof d[0]=="number"&&(v=d[0]),typeof d[1]=="number"&&(S=d[1]),`//${l}/m/${v}x${S}${n} ${v}w`}}).join(", "),sizes:(p=e.sizes)==null?void 0:p.map(d=>d).join(", ")};let T="";return y.srcset&&(T+=`srcset="${y.srcset}" `),y.sizes&&(T+=`sizes="${y.sizes}" `),o.replace(/<img/g,`<img ${T.trim()}`)}return o})),t}renderNode(t){const e=[];t.marks&&t.marks.forEach(s=>{const i=this.getMatchingMark(s);i&&e.push(this.renderOpeningTag(i.tag))});const r=this.getMatchingNode(t);return r&&r.tag&&e.push(this.renderOpeningTag(r.tag)),t.content?t.content.forEach(s=>{e.push(this.renderNode(s))}):t.text?e.push(E(t.text)):r&&r.singleTag?e.push(this.renderTag(r.singleTag," /")):r&&r.html?e.push(r.html):t.type==="emoji"&&e.push(this.renderEmoji(t)),r&&r.tag&&e.push(this.renderClosingTag(r.tag)),t.marks&&t.marks.slice(0).reverse().forEach(s=>{const i=this.getMatchingMark(s);i&&e.push(this.renderClosingTag(i.tag))}),e.join("")}renderTag(t,e){return t.constructor===String?`<${t}${e}>`:t.map(s=>{if(s.constructor===String)return`<${s}${e}>`;{let i=`<${s.tag}`;if(s.attrs)for(const n in s.attrs){const c=s.attrs[n];c!==null&&(i+=` ${n}="${c}"`)}return`${i}${e}>`}}).join("")}renderOpeningTag(t){return this.renderTag(t,"")}renderClosingTag(t){return t.constructor===String?`</${t}>`:t.slice(0).reverse().map(r=>r.constructor===String?`</${r}>`:`</${r.tag}>`).join("")}getMatchingNode(t){const e=this.nodes[t.type];if(typeof e=="function")return e(t)}getMatchingMark(t){const e=this.marks[t.type];if(typeof e=="function")return e(t)}renderEmoji(t){if(t.attrs.emoji)return t.attrs.emoji;const e=[{tag:"img",attrs:{src:t.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(e," /")}}class b{constructor(){h(this,"isCDNUrl",(t="")=>t.indexOf("/cdn/")>-1);h(this,"getOptionsPage",(t,e=25,r=1)=>({...t,per_page:e,page:r}));h(this,"delay",t=>new Promise(e=>setTimeout(e,t)));h(this,"arrayFrom",(t=0,e)=>[...Array(t)].map(e));h(this,"range",(t=0,e=t)=>{const r=Math.abs(e-t)||0,s=t<e?1:-1;return this.arrayFrom(r,(i,n)=>n*s+t)});h(this,"asyncMap",async(t,e)=>Promise.all(t.map(e)));h(this,"flatMap",(t=[],e)=>t.map(e).reduce((r,s)=>[...r,...s],[]))}stringify(t,e,r){const s=[];for(const i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;const n=t[i],c=r?"":encodeURIComponent(i);let o;typeof n=="object"?o=this.stringify(n,e?e+encodeURIComponent("["+c+"]"):c,Array.isArray(n)):o=(e?e+encodeURIComponent("["+c+"]"):c)+"="+encodeURIComponent(n),s.push(o)}return s.join("&")}getRegionURL(t){const e="api.storyblok.com",r="api-us.storyblok.com",s="app.storyblokchina.cn";switch(t){case"us":return r;case"cn":return s;default:return e}}}const j=Object.freeze(Object.defineProperty({__proto__:null,SbHelpers:b},Symbol.toStringTag,{value:"Module"}));class x{constructor(t){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=t.baseURL,this.headers=t.headers||new Headers,this.timeout=t!=null&&t.timeout?t.timeout*1e3:0,this.responseInterceptor=t.responseInterceptor,this.fetch=(...e)=>t.fetch?t.fetch(...e):fetch(...e),this.ejectInterceptor=!1,this.url="",this.parameters={}}get(t,e){return this.url=t,this.parameters=e,this._methodHandler("get")}post(t,e){return this.url=t,this.parameters=e,this._methodHandler("post")}put(t,e){return this.url=t,this.parameters=e,this._methodHandler("put")}delete(t,e){return this.url=t,this.parameters=e,this._methodHandler("delete")}async _responseHandler(t){const e=[],r={data:{},headers:{},status:0,statusText:""};t.status!==204&&await t.json().then(s=>{r.data=s});for(const s of t.headers.entries())e[s[0]]=s[1];return r.headers={...e},r.status=t.status,r.statusText=t.statusText,r}async _methodHandler(t){let e=`${this.baseURL}${this.url}`,r=null;if(t==="get"){const o=new b;e=`${this.baseURL}${this.url}?${o.stringify(this.parameters)}`}else r=JSON.stringify(this.parameters);const s=new URL(e),i=new AbortController,{signal:n}=i;let c;this.timeout&&(c=setTimeout(()=>i.abort(),this.timeout));try{const o=await this.fetch(`${s}`,{method:t,headers:this.headers,body:r,signal:n});this.timeout&&clearTimeout(c);const l=await this._responseHandler(o);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(l)):this._statusHandler(l)}catch(o){return{message:o}}}eject(){this.ejectInterceptor=!0}_statusHandler(t){const e=/20[0-6]/g;return new Promise((r,s)=>{if(e.test(`${t.status}`))return r(t);const i={message:new Error(t.statusText),status:t.status,response:Array.isArray(t.data)?t.data[0]:t.data.error||t.data.slug};s(i)})}}let _={};const k={};class ${constructor(t,e){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");if(!e){const i=new b().getRegionURL,n=t.https===!1?"http":"https";t.oauthToken?e=`${n}://${i(t.region)}/v1`:e=`${n}://${i(t.region)}/v2`}const r=new Headers;r.set("Content-Type","application/json"),r.set("Accept","application/json"),r.forEach((i,n)=>{t.headers&&t.headers[n]&&r.set(n,t.headers[n])});let s=5;t.oauthToken&&(r.set("Authorization",t.oauthToken),s=3),t.rateLimit&&(s=t.rateLimit),t.richTextSchema?this.richTextResolver=new R(t.richTextSchema):this.richTextResolver=new R,t.componentResolver&&this.setComponentResolver(t.componentResolver),this.maxRetries=t.maxRetries||5,this.throttle=f(this.throttledRequest,s,1e3),this.accessToken=t.accessToken||"",this.relations={},this.links={},this.cache=t.cache||{clear:"manual"},this.helpers=new b,this.resolveCounter=0,this.resolveNestedRelations=t.resolveNestedRelations||!0,this.client=new x({baseURL:e,timeout:t.timeout||0,headers:r,responseInterceptor:t.responseInterceptor,fetch:t.fetch})}setComponentResolver(t){this.richTextResolver.addNode("blok",e=>{let r="";return e.attrs.body.forEach(s=>{r+=t(s.component,s)}),{html:r}})}parseParams(t){return t.version||(t.version="published"),t.token||(t.token=this.getToken()),t.cv||(t.cv=k[t.token]),Array.isArray(t.resolve_relations)&&(t.resolve_relations=t.resolve_relations.join(",")),t}factoryParamOptions(t,e){return this.helpers.isCDNUrl(t)?this.parseParams(e):e}makeRequest(t,e,r,s){const i=this.factoryParamOptions(t,this.helpers.getOptionsPage(e,r,s));return this.cacheResponse(t,i)}get(t,e){e||(e={});const r=`/${t}`,s=this.factoryParamOptions(r,e);return this.cacheResponse(r,s)}async getAll(t,e,r){const s=(e==null?void 0:e.per_page)||25,i=`/${t}`,n=i.split("/"),c=r||n[n.length-1],o=1,l=await this.makeRequest(i,e,s,o),u=l.total?Math.ceil(l.total/s):1,p=await this.helpers.asyncMap(this.helpers.range(o,u),y=>this.makeRequest(i,e,s,y+1));return this.helpers.flatMap([l,...p],y=>Object.values(y.data[c]))}post(t,e){const r=`/${t}`;return Promise.resolve(this.throttle("post",r,e))}put(t,e){const r=`/${t}`;return Promise.resolve(this.throttle("put",r,e))}delete(t,e){const r=`/${t}`;return Promise.resolve(this.throttle("delete",r,e))}getStories(t){return this.get("cdn/stories",t)}getStory(t,e){return this.get(`cdn/stories/${t}`,e)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_cleanCopy(t){return JSON.parse(JSON.stringify(t))}_insertLinks(t,e,r){const s=t[e];s&&s.fieldtype=="multilink"&&s.linktype=="story"&&typeof s.id=="string"&&this.links[r][s.id]?s.story=this._cleanCopy(this.links[r][s.id]):s&&s.linktype==="story"&&typeof s.uuid=="string"&&this.links[r][s.uuid]&&(s.story=this._cleanCopy(this.links[r][s.uuid]))}_insertRelations(t,e,r,s){if(r.indexOf(`${t.component}.${e}`)>-1){if(typeof t[e]=="string")this.relations[s][t[e]]&&(t[e]=this._cleanCopy(this.relations[s][t[e]]));else if(t[e]&&t[e].constructor===Array){const i=[];t[e].forEach(n=>{this.relations[s][n]&&i.push(this._cleanCopy(this.relations[s][n]))}),t[e]=i}}}iterateTree(t,e,r){const s=i=>{if(i!=null){if(i.constructor===Array)for(let n=0;n<i.length;n++)s(i[n]);else if(i.constructor===Object){if(i._stopResolving)return;for(const n in i)(i.component&&i._uid||i.type==="link")&&(this._insertRelations(i,n,e,r),this._insertLinks(i,n,r)),s(i[n])}}};s(t.content)}async resolveLinks(t,e,r){let s=[];if(t.link_uuids){const i=t.link_uuids.length,n=[],c=50;for(let o=0;o<i;o+=c){const l=Math.min(i,o+c);n.push(t.link_uuids.slice(o,l))}for(let o=0;o<n.length;o++)(await this.getStories({per_page:c,language:e.language,version:e.version,by_uuids:n[o].join(",")})).data.stories.forEach(u=>{s.push(u)})}else s=t.links;s.forEach(i=>{this.links[r][i.uuid]={...i,_stopResolving:!0}})}async resolveRelations(t,e,r){let s=[];if(t.rel_uuids){const i=t.rel_uuids.length,n=[],c=50;for(let o=0;o<i;o+=c){const l=Math.min(i,o+c);n.push(t.rel_uuids.slice(o,l))}for(let o=0;o<n.length;o++)(await this.getStories({per_page:c,language:e.language,version:e.version,by_uuids:n[o].join(",")})).data.stories.forEach(u=>{s.push(u)})}else s=t.rels;s&&s.length>0&&s.forEach(i=>{this.relations[r][i.uuid]={...i,_stopResolving:!0}})}async resolveStories(t,e,r){var i,n;let s=[];if(this.links[r]={},this.relations[r]={},typeof e.resolve_relations<"u"&&e.resolve_relations.length>0&&(typeof e.resolve_relations=="string"&&(s=e.resolve_relations.split(",")),await this.resolveRelations(t,e,r)),e.resolve_links&&["1","story","url"].indexOf(e.resolve_links)>-1&&((i=t.links)!=null&&i.length||(n=t.link_uuids)!=null&&n.length)&&await this.resolveLinks(t,e,r),this.resolveNestedRelations)for(const c in this.relations[r])this.iterateTree(this.relations[r][c],s,r);t.story?this.iterateTree(t.story,s,r):t.stories.forEach(c=>{this.iterateTree(c,s,r)}),delete this.links[r],delete this.relations[r]}async cacheResponse(t,e,r){const s=this.helpers.stringify({url:t,params:e}),i=this.cacheProvider();if(this.cache.clear==="auto"&&e.version==="draft"&&await this.flushCache(),e.version==="published"&&t!="/cdn/spaces/me"){const n=await i.get(s);if(n)return Promise.resolve(n)}return new Promise((n,c)=>{try{(async()=>{var o;try{const l=await this.throttle("get",t,e);let u={data:l.data,headers:l.headers};if((o=l.headers)!=null&&o["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,e,`${p}`)}return e.version==="published"&&t!="/cdn/spaces/me"&&await i.set(s,u),u.data.cv&&e.token&&(e.version=="draft"&&k[e.token]!=u.data.cv&&await this.flushCache(),k[e.token]=u.data.cv),n(u)}catch(l){return c(l)}})()}catch{}})}throttledRequest(t,e,r){return this.client[t](e,r)}cacheVersions(){return k}cacheVersion(){return k[this.accessToken]}setCacheVersion(t){this.accessToken&&(k[this.accessToken]=t)}cacheProvider(){switch(this.cache.type){case"memory":return{get(t){return Promise.resolve(_[t])},getAll(){return Promise.resolve(_)},set(t,e){return _[t]=e,Promise.resolve(void 0)},flush(){return _={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve(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 P=(a,t)=>{for(const e in t)a[e]=t[e]};return P($,{RichtextResolver:R,SbFetch:x,RichTextSchema:w}),P($,j),$});
}`),""}optimizeImages(t,e){let r=0,s=0,i="",n="";typeof e!="boolean"&&(typeof e.width=="number"&&e.width>0&&(i+=`width="${e.width}" `,r=e.width),typeof e.height=="number"&&e.height>0&&(i+=`height="${e.height}" `,s=e.height),(e.loading==="lazy"||e.loading==="eager")&&(i+=`loading="${e.loading}" `),typeof e.class=="string"&&e.class.length>0&&(i+=`class="${e.class}" `),e.filters&&(typeof e.filters.blur=="number"&&e.filters.blur>=0&&e.filters.blur<=100&&(n+=`:blur(${e.filters.blur})`),typeof e.filters.brightness=="number"&&e.filters.brightness>=-100&&e.filters.brightness<=100&&(n+=`:brightness(${e.filters.brightness})`),e.filters.fill&&(e.filters.fill.match(/[0-9A-Fa-f]{6}/g)||e.filters.fill==="transparent")&&(n+=`:fill(${e.filters.fill})`),e.filters.format&&["webp","png","jpeg"].includes(e.filters.format)&&(n+=`:format(${e.filters.format})`),typeof e.filters.grayscale=="boolean"&&e.filters.grayscale&&(n+=":grayscale()"),typeof e.filters.quality=="number"&&e.filters.quality>=0&&e.filters.quality<=100&&(n+=`:quality(${e.filters.quality})`),e.filters.rotate&&[90,180,270].includes(e.filters.rotate)&&(n+=`:rotate(${e.filters.rotate})`),n.length>0&&(n="/filters"+n))),i.length>0&&(t=t.replace(/<img/g,`<img ${i.trim()}`));const c=r>0||s>0||n.length>0?`${r}x${s}${n}`:"";return t=t.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${c}`),typeof e!="boolean"&&(e.sizes||e.srcset)&&(t=t.replace(/<img.*?src=["|'](.*?)["|']/g,o=>{var u,p;const l=o.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(l&&l.length>0){const y={srcset:(u=e.srcset)==null?void 0:u.map(d=>{if(typeof d=="number")return`//${l}/m/${d}x0${n} ${d}w`;if(typeof d=="object"&&d.length===2){let v=0,S=0;return typeof d[0]=="number"&&(v=d[0]),typeof d[1]=="number"&&(S=d[1]),`//${l}/m/${v}x${S}${n} ${v}w`}}).join(", "),sizes:(p=e.sizes)==null?void 0:p.map(d=>d).join(", ")};let T="";return y.srcset&&(T+=`srcset="${y.srcset}" `),y.sizes&&(T+=`sizes="${y.sizes}" `),o.replace(/<img/g,`<img ${T.trim()}`)}return o})),t}renderNode(t){const e=[];t.marks&&t.marks.forEach(s=>{const i=this.getMatchingMark(s);i&&i.tag!==""&&e.push(this.renderOpeningTag(i.tag))});const r=this.getMatchingNode(t);return r&&r.tag&&e.push(this.renderOpeningTag(r.tag)),t.content?t.content.forEach(s=>{e.push(this.renderNode(s))}):t.text?e.push(E(t.text)):r&&r.singleTag?e.push(this.renderTag(r.singleTag," /")):r&&r.html?e.push(r.html):t.type==="emoji"&&e.push(this.renderEmoji(t)),r&&r.tag&&e.push(this.renderClosingTag(r.tag)),t.marks&&t.marks.slice(0).reverse().forEach(s=>{const i=this.getMatchingMark(s);i&&i.tag!==""&&e.push(this.renderClosingTag(i.tag))}),e.join("")}renderTag(t,e){return t.constructor===String?`<${t}${e}>`:t.map(s=>{if(s.constructor===String)return`<${s}${e}>`;{let i=`<${s.tag}`;if(s.attrs)for(const n in s.attrs){const c=s.attrs[n];c!==null&&(i+=` ${n}="${c}"`)}return`${i}${e}>`}}).join("")}renderOpeningTag(t){return this.renderTag(t,"")}renderClosingTag(t){return t.constructor===String?`</${t}>`:t.slice(0).reverse().map(r=>r.constructor===String?`</${r}>`:`</${r.tag}>`).join("")}getMatchingNode(t){const e=this.nodes[t.type];if(typeof e=="function")return e(t)}getMatchingMark(t){const e=this.marks[t.type];if(typeof e=="function")return e(t)}renderEmoji(t){if(t.attrs.emoji)return t.attrs.emoji;const e=[{tag:"img",attrs:{src:t.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(e," /")}}class b{constructor(){h(this,"isCDNUrl",(t="")=>t.indexOf("/cdn/")>-1);h(this,"getOptionsPage",(t,e=25,r=1)=>({...t,per_page:e,page:r}));h(this,"delay",t=>new Promise(e=>setTimeout(e,t)));h(this,"arrayFrom",(t=0,e)=>[...Array(t)].map(e));h(this,"range",(t=0,e=t)=>{const r=Math.abs(e-t)||0,s=t<e?1:-1;return this.arrayFrom(r,(i,n)=>n*s+t)});h(this,"asyncMap",async(t,e)=>Promise.all(t.map(e)));h(this,"flatMap",(t=[],e)=>t.map(e).reduce((r,s)=>[...r,...s],[]))}stringify(t,e,r){const s=[];for(const i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;const n=t[i],c=r?"":encodeURIComponent(i);let o;typeof n=="object"?o=this.stringify(n,e?e+encodeURIComponent("["+c+"]"):c,Array.isArray(n)):o=(e?e+encodeURIComponent("["+c+"]"):c)+"="+encodeURIComponent(n),s.push(o)}return s.join("&")}getRegionURL(t){const e="api.storyblok.com",r="api-us.storyblok.com",s="app.storyblokchina.cn";switch(t){case"us":return r;case"cn":return s;default:return e}}}const j=Object.freeze(Object.defineProperty({__proto__:null,SbHelpers:b},Symbol.toStringTag,{value:"Module"}));class x{constructor(t){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=t.baseURL,this.headers=t.headers||new Headers,this.timeout=t!=null&&t.timeout?t.timeout*1e3:0,this.responseInterceptor=t.responseInterceptor,this.fetch=(...e)=>t.fetch?t.fetch(...e):fetch(...e),this.ejectInterceptor=!1,this.url="",this.parameters={}}get(t,e){return this.url=t,this.parameters=e,this._methodHandler("get")}post(t,e){return this.url=t,this.parameters=e,this._methodHandler("post")}put(t,e){return this.url=t,this.parameters=e,this._methodHandler("put")}delete(t,e){return this.url=t,this.parameters=e,this._methodHandler("delete")}async _responseHandler(t){const e=[],r={data:{},headers:{},status:0,statusText:""};t.status!==204&&await t.json().then(s=>{r.data=s});for(const s of t.headers.entries())e[s[0]]=s[1];return r.headers={...e},r.status=t.status,r.statusText=t.statusText,r}async _methodHandler(t){let e=`${this.baseURL}${this.url}`,r=null;if(t==="get"){const o=new b;e=`${this.baseURL}${this.url}?${o.stringify(this.parameters)}`}else r=JSON.stringify(this.parameters);const s=new URL(e),i=new AbortController,{signal:n}=i;let c;this.timeout&&(c=setTimeout(()=>i.abort(),this.timeout));try{const o=await this.fetch(`${s}`,{method:t,headers:this.headers,body:r,signal:n});this.timeout&&clearTimeout(c);const l=await this._responseHandler(o);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(l)):this._statusHandler(l)}catch(o){return{message:o}}}eject(){this.ejectInterceptor=!0}_statusHandler(t){const e=/20[0-6]/g;return new Promise((r,s)=>{if(e.test(`${t.status}`))return r(t);const i={message:new Error(t.statusText),status:t.status,response:Array.isArray(t.data)?t.data[0]:t.data.error||t.data.slug};s(i)})}}let _={};const k={};class ${constructor(t,e){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");if(!e){const i=new b().getRegionURL,n=t.https===!1?"http":"https";t.oauthToken?e=`${n}://${i(t.region)}/v1`:e=`${n}://${i(t.region)}/v2`}const r=new Headers;r.set("Content-Type","application/json"),r.set("Accept","application/json"),r.forEach((i,n)=>{t.headers&&t.headers[n]&&r.set(n,t.headers[n])});let s=5;t.oauthToken&&(r.set("Authorization",t.oauthToken),s=3),t.rateLimit&&(s=t.rateLimit),t.richTextSchema?this.richTextResolver=new R(t.richTextSchema):this.richTextResolver=new R,t.componentResolver&&this.setComponentResolver(t.componentResolver),this.maxRetries=t.maxRetries||5,this.throttle=f(this.throttledRequest,s,1e3),this.accessToken=t.accessToken||"",this.relations={},this.links={},this.cache=t.cache||{clear:"manual"},this.helpers=new b,this.resolveCounter=0,this.resolveNestedRelations=t.resolveNestedRelations||!0,this.client=new x({baseURL:e,timeout:t.timeout||0,headers:r,responseInterceptor:t.responseInterceptor,fetch:t.fetch})}setComponentResolver(t){this.richTextResolver.addNode("blok",e=>{let r="";return e.attrs.body&&e.attrs.body.forEach(s=>{r+=t(s.component,s)}),{html:r}})}parseParams(t){return t.version||(t.version="published"),t.token||(t.token=this.getToken()),t.cv||(t.cv=k[t.token]),Array.isArray(t.resolve_relations)&&(t.resolve_relations=t.resolve_relations.join(",")),t}factoryParamOptions(t,e){return this.helpers.isCDNUrl(t)?this.parseParams(e):e}makeRequest(t,e,r,s){const i=this.factoryParamOptions(t,this.helpers.getOptionsPage(e,r,s));return this.cacheResponse(t,i)}get(t,e){e||(e={});const r=`/${t}`,s=this.factoryParamOptions(r,e);return this.cacheResponse(r,s)}async getAll(t,e,r){const s=(e==null?void 0:e.per_page)||25,i=`/${t}`,n=i.split("/"),c=r||n[n.length-1],o=1,l=await this.makeRequest(i,e,s,o),u=l.total?Math.ceil(l.total/s):1,p=await this.helpers.asyncMap(this.helpers.range(o,u),y=>this.makeRequest(i,e,s,y+1));return this.helpers.flatMap([l,...p],y=>Object.values(y.data[c]))}post(t,e){const r=`/${t}`;return Promise.resolve(this.throttle("post",r,e))}put(t,e){const r=`/${t}`;return Promise.resolve(this.throttle("put",r,e))}delete(t,e){const r=`/${t}`;return Promise.resolve(this.throttle("delete",r,e))}getStories(t){return this.get("cdn/stories",t)}getStory(t,e){return this.get(`cdn/stories/${t}`,e)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_cleanCopy(t){return JSON.parse(JSON.stringify(t))}_insertLinks(t,e,r){const s=t[e];s&&s.fieldtype=="multilink"&&s.linktype=="story"&&typeof s.id=="string"&&this.links[r][s.id]?s.story=this._cleanCopy(this.links[r][s.id]):s&&s.linktype==="story"&&typeof s.uuid=="string"&&this.links[r][s.uuid]&&(s.story=this._cleanCopy(this.links[r][s.uuid]))}_insertRelations(t,e,r,s){if(r.indexOf(`${t.component}.${e}`)>-1){if(typeof t[e]=="string")this.relations[s][t[e]]&&(t[e]=this._cleanCopy(this.relations[s][t[e]]));else if(t[e]&&t[e].constructor===Array){const i=[];t[e].forEach(n=>{this.relations[s][n]&&i.push(this._cleanCopy(this.relations[s][n]))}),t[e]=i}}}iterateTree(t,e,r){const s=i=>{if(i!=null){if(i.constructor===Array)for(let n=0;n<i.length;n++)s(i[n]);else if(i.constructor===Object){if(i._stopResolving)return;for(const n in i)(i.component&&i._uid||i.type==="link")&&(this._insertRelations(i,n,e,r),this._insertLinks(i,n,r)),s(i[n])}}};s(t.content)}async resolveLinks(t,e,r){let s=[];if(t.link_uuids){const i=t.link_uuids.length,n=[],c=50;for(let o=0;o<i;o+=c){const l=Math.min(i,o+c);n.push(t.link_uuids.slice(o,l))}for(let o=0;o<n.length;o++)(await this.getStories({per_page:c,language:e.language,version:e.version,by_uuids:n[o].join(",")})).data.stories.forEach(u=>{s.push(u)})}else s=t.links;s.forEach(i=>{this.links[r][i.uuid]={...i,_stopResolving:!0}})}async resolveRelations(t,e,r){let s=[];if(t.rel_uuids){const i=t.rel_uuids.length,n=[],c=50;for(let o=0;o<i;o+=c){const l=Math.min(i,o+c);n.push(t.rel_uuids.slice(o,l))}for(let o=0;o<n.length;o++)(await this.getStories({per_page:c,language:e.language,version:e.version,by_uuids:n[o].join(",")})).data.stories.forEach(u=>{s.push(u)})}else s=t.rels;s&&s.length>0&&s.forEach(i=>{this.relations[r][i.uuid]={...i,_stopResolving:!0}})}async resolveStories(t,e,r){var i,n;let s=[];if(this.links[r]={},this.relations[r]={},typeof e.resolve_relations<"u"&&e.resolve_relations.length>0&&(typeof e.resolve_relations=="string"&&(s=e.resolve_relations.split(",")),await this.resolveRelations(t,e,r)),e.resolve_links&&["1","story","url"].indexOf(e.resolve_links)>-1&&((i=t.links)!=null&&i.length||(n=t.link_uuids)!=null&&n.length)&&await this.resolveLinks(t,e,r),this.resolveNestedRelations)for(const c in this.relations[r])this.iterateTree(this.relations[r][c],s,r);t.story?this.iterateTree(t.story,s,r):t.stories.forEach(c=>{this.iterateTree(c,s,r)}),delete this.links[r],delete this.relations[r]}async cacheResponse(t,e,r){const s=this.helpers.stringify({url:t,params:e}),i=this.cacheProvider();if(this.cache.clear==="auto"&&e.version==="draft"&&await this.flushCache(),e.version==="published"&&t!="/cdn/spaces/me"){const n=await i.get(s);if(n)return Promise.resolve(n)}return new Promise((n,c)=>{try{(async()=>{var o;try{const l=await this.throttle("get",t,e);let u={data:l.data,headers:l.headers};if((o=l.headers)!=null&&o["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,e,`${p}`)}return e.version==="published"&&t!="/cdn/spaces/me"&&await i.set(s,u),u.data.cv&&e.token&&(e.version=="draft"&&k[e.token]!=u.data.cv&&await this.flushCache(),k[e.token]=u.data.cv),n(u)}catch(l){return c(l)}})()}catch{}})}throttledRequest(t,e,r){return this.client[t](e,r)}cacheVersions(){return k}cacheVersion(){return k[this.accessToken]}setCacheVersion(t){this.accessToken&&(k[this.accessToken]=t)}cacheProvider(){switch(this.cache.type){case"memory":return{get(t){return Promise.resolve(_[t])},getAll(){return Promise.resolve(_)},set(t,e){return _[t]=e,Promise.resolve(void 0)},flush(){return _={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve(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 P=(a,t)=>{for(const e in t)a[e]=t[e]};return P($,{RichtextResolver:R,SbFetch:x,RichTextSchema:w}),P($,j),$});

@@ -1,2 +0,2 @@

(function(c,l){typeof exports=="object"&&typeof module<"u"?module.exports=l():typeof define=="function"&&define.amd?define(l):(c=typeof globalThis<"u"?globalThis:c||self,c.RichTextResolver=l())})(this,function(){"use strict";var z=Object.defineProperty;var w=(c,l,g)=>l in c?z(c,l,{enumerable:!0,configurable:!0,writable:!0,value:g}):c[l]=g;var p=(c,l,g)=>(w(c,typeof l!="symbol"?l+"":l,g),g);const c=function(s,e){const t={};for(const r in s){const n=s[r];e.indexOf(r)>-1&&n!==null&&(t[r]=n)}return t},l=s=>s==="email",j={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:s=>({tag:["pre",{tag:"code",attrs:s.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:s=>({tag:`h${s.attrs.level}`}),image:s=>({singleTag:[{tag:"img",attrs:c(s.attrs,["src","alt","title"])}]}),list_item:()=>({tag:"li"}),ordered_list:()=>({tag:"ol"}),paragraph:()=>({tag:"p"}),emoji:s=>({tag:[{tag:"span",attrs:{["data-type"]:"emoji",["data-name"]:s.attrs.name,emoji:s.attrs.emoji}}]})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link:s=>{const e={...s.attrs},{linktype:t="url"}=s.attrs;if(l(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),e.custom){for(const r in e.custom)e[r]=e.custom[r];delete e.custom}return{tag:[{tag:"a",attrs:e}]}},styled:s=>({tag:[{tag:"span",attrs:s.attrs}]}),subscript:()=>({tag:"sub"}),superscript:()=>({tag:"sup"}),anchor:s=>({tag:[{tag:"span",attrs:s.attrs}]}),highlight:s=>({tag:[{tag:"span",attrs:{style:`background-color:${s.attrs.color};`}}]}),textStyle:s=>({tag:[{tag:"span",attrs:{style:`color:${s.attrs.color}`}}]})}},T=function(s){const e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},t=/[&<>"']/g,r=RegExp(t.source);return s&&r.test(s)?s.replace(t,n=>e[n]):s};class x{constructor(e){p(this,"marks");p(this,"nodes");e||(e=j),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 r="";return e.content.forEach(n=>{r+=this.renderNode(n)}),t.optimizeImages?this.optimizeImages(r,t.optimizeImages):r}return console.warn(`The render method must receive an Object with a "content" field.
(function(c,l){typeof exports=="object"&&typeof module<"u"?module.exports=l():typeof define=="function"&&define.amd?define(l):(c=typeof globalThis<"u"?globalThis:c||self,c.RichTextResolver=l())})(this,function(){"use strict";var z=Object.defineProperty;var w=(c,l,g)=>l in c?z(c,l,{enumerable:!0,configurable:!0,writable:!0,value:g}):c[l]=g;var p=(c,l,g)=>(w(c,typeof l!="symbol"?l+"":l,g),g);const c=function(s,e){const t={};for(const r in s){const n=s[r];e.indexOf(r)>-1&&n!==null&&(t[r]=n)}return t},l=s=>s==="email",j={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:s=>({tag:["pre",{tag:"code",attrs:s.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:s=>({tag:`h${s.attrs.level}`}),image:s=>({singleTag:[{tag:"img",attrs:c(s.attrs,["src","alt","title"])}]}),list_item:()=>({tag:"li"}),ordered_list:()=>({tag:"ol"}),paragraph:()=>({tag:"p"}),emoji:s=>({tag:[{tag:"span",attrs:{["data-type"]:"emoji",["data-name"]:s.attrs.name,emoji:s.attrs.emoji}}]})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link:s=>{const e={...s.attrs},{linktype:t="url"}=s.attrs;if(l(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),e.custom){for(const r in e.custom)e[r]=e.custom[r];delete e.custom}return{tag:[{tag:"a",attrs:e}]}},styled:s=>({tag:[{tag:"span",attrs:s.attrs}]}),subscript:()=>({tag:"sub"}),superscript:()=>({tag:"sup"}),anchor:s=>({tag:[{tag:"span",attrs:s.attrs}]}),highlight:s=>{var t;return(t=s.attrs)!=null&&t.color?{tag:[{tag:"span",attrs:{style:`background-color:${s.attrs.color};`}}]}:{tag:""}},textStyle:s=>{var t;return(t=s.attrs)!=null&&t.color?{tag:[{tag:"span",attrs:{style:`color:${s.attrs.color}`}}]}:{tag:""}}}},T=function(s){const e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},t=/[&<>"']/g,r=RegExp(t.source);return s&&r.test(s)?s.replace(t,n=>e[n]):s};class x{constructor(e){p(this,"marks");p(this,"nodes");e||(e=j),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 r="";return e.content.forEach(n=>{r+=this.renderNode(n)}),t.optimizeImages?this.optimizeImages(r,t.optimizeImages):r}return console.warn(`The render method must receive an Object with a "content" field.
The "content" field must be an array of nodes as the type ISbRichtext.

@@ -24,2 +24,2 @@ ISbRichtext:

type: 'doc'
}`),""}optimizeImages(e,t){let r=0,n=0,a="",i="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(a+=`width="${t.width}" `,r=t.width),typeof t.height=="number"&&t.height>0&&(a+=`height="${t.height}" `,n=t.height),(t.loading==="lazy"||t.loading==="eager")&&(a+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(a+=`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))),a.length>0&&(e=e.replace(/<img/g,`<img ${a.trim()}`));const o=r>0||n>0||i.length>0?`${r}x${n}${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/${o}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,d=>{var y,$;const u=d.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(u&&u.length>0){const h={srcset:(y=t.srcset)==null?void 0:y.map(f=>{if(typeof f=="number")return`//${u}/m/${f}x0${i} ${f}w`;if(typeof f=="object"&&f.length===2){let b=0,k=0;return typeof f[0]=="number"&&(b=f[0]),typeof f[1]=="number"&&(k=f[1]),`//${u}/m/${b}x${k}${i} ${b}w`}}).join(", "),sizes:($=t.sizes)==null?void 0:$.map(f=>f).join(", ")};let m="";return h.srcset&&(m+=`srcset="${h.srcset}" `),h.sizes&&(m+=`sizes="${h.sizes}" `),d.replace(/<img/g,`<img ${m.trim()}`)}return d})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(n=>{const a=this.getMatchingMark(n);a&&t.push(this.renderOpeningTag(a.tag))});const r=this.getMatchingNode(e);return r&&r.tag&&t.push(this.renderOpeningTag(r.tag)),e.content?e.content.forEach(n=>{t.push(this.renderNode(n))}):e.text?t.push(T(e.text)):r&&r.singleTag?t.push(this.renderTag(r.singleTag," /")):r&&r.html?t.push(r.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),r&&r.tag&&t.push(this.renderClosingTag(r.tag)),e.marks&&e.marks.slice(0).reverse().forEach(n=>{const a=this.getMatchingMark(n);a&&t.push(this.renderClosingTag(a.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(n=>{if(n.constructor===String)return`<${n}${t}>`;{let a=`<${n.tag}`;if(n.attrs)for(const i in n.attrs){const o=n.attrs[i];o!==null&&(a+=` ${i}="${o}"`)}return`${a}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(r=>r.constructor===String?`</${r}>`:`</${r.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," /")}}return x});
}`),""}optimizeImages(e,t){let r=0,n=0,a="",i="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(a+=`width="${t.width}" `,r=t.width),typeof t.height=="number"&&t.height>0&&(a+=`height="${t.height}" `,n=t.height),(t.loading==="lazy"||t.loading==="eager")&&(a+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(a+=`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))),a.length>0&&(e=e.replace(/<img/g,`<img ${a.trim()}`));const o=r>0||n>0||i.length>0?`${r}x${n}${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/${o}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,d=>{var y,$;const u=d.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(u&&u.length>0){const h={srcset:(y=t.srcset)==null?void 0:y.map(f=>{if(typeof f=="number")return`//${u}/m/${f}x0${i} ${f}w`;if(typeof f=="object"&&f.length===2){let b=0,k=0;return typeof f[0]=="number"&&(b=f[0]),typeof f[1]=="number"&&(k=f[1]),`//${u}/m/${b}x${k}${i} ${b}w`}}).join(", "),sizes:($=t.sizes)==null?void 0:$.map(f=>f).join(", ")};let m="";return h.srcset&&(m+=`srcset="${h.srcset}" `),h.sizes&&(m+=`sizes="${h.sizes}" `),d.replace(/<img/g,`<img ${m.trim()}`)}return d})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(n=>{const a=this.getMatchingMark(n);a&&a.tag!==""&&t.push(this.renderOpeningTag(a.tag))});const r=this.getMatchingNode(e);return r&&r.tag&&t.push(this.renderOpeningTag(r.tag)),e.content?e.content.forEach(n=>{t.push(this.renderNode(n))}):e.text?t.push(T(e.text)):r&&r.singleTag?t.push(this.renderTag(r.singleTag," /")):r&&r.html?t.push(r.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),r&&r.tag&&t.push(this.renderClosingTag(r.tag)),e.marks&&e.marks.slice(0).reverse().forEach(n=>{const a=this.getMatchingMark(n);a&&a.tag!==""&&t.push(this.renderClosingTag(a.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(n=>{if(n.constructor===String)return`<${n}${t}>`;{let a=`<${n.tag}`;if(n.attrs)for(const i in n.attrs){const o=n.attrs[i];o!==null&&(a+=` ${i}="${o}"`)}return`${a}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(r=>r.constructor===String?`</${r}>`:`</${r.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," /")}}return x});

@@ -1,1 +0,1 @@

(function(n,s){typeof exports=="object"&&typeof module<"u"?module.exports=s():typeof define=="function"&&define.amd?define(s):(n=typeof globalThis<"u"?globalThis:n||self,n.RichTextSchema=s())})(this,function(){"use strict";const n=function(t,r){const o={};for(const e in t){const a=t[e];r.indexOf(e)>-1&&a!==null&&(o[e]=a)}return o},s=t=>t==="email";return{nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:t=>({tag:["pre",{tag:"code",attrs:t.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:t=>({tag:`h${t.attrs.level}`}),image:t=>({singleTag:[{tag:"img",attrs:n(t.attrs,["src","alt","title"])}]}),list_item:()=>({tag:"li"}),ordered_list:()=>({tag:"ol"}),paragraph:()=>({tag:"p"}),emoji:t=>({tag:[{tag:"span",attrs:{["data-type"]:"emoji",["data-name"]:t.attrs.name,emoji:t.attrs.emoji}}]})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link:t=>{const r={...t.attrs},{linktype:o="url"}=t.attrs;if(s(o)&&(r.href=`mailto:${r.href}`),r.anchor&&(r.href=`${r.href}#${r.anchor}`,delete r.anchor),r.custom){for(const e in r.custom)r[e]=r.custom[e];delete r.custom}return{tag:[{tag:"a",attrs:r}]}},styled:t=>({tag:[{tag:"span",attrs:t.attrs}]}),subscript:()=>({tag:"sub"}),superscript:()=>({tag:"sup"}),anchor:t=>({tag:[{tag:"span",attrs:t.attrs}]}),highlight:t=>({tag:[{tag:"span",attrs:{style:`background-color:${t.attrs.color};`}}]}),textStyle:t=>({tag:[{tag:"span",attrs:{style:`color:${t.attrs.color}`}}]})}}});
(function(s,a){typeof exports=="object"&&typeof module<"u"?module.exports=a():typeof define=="function"&&define.amd?define(a):(s=typeof globalThis<"u"?globalThis:s||self,s.RichTextSchema=a())})(this,function(){"use strict";const s=function(t,r){const e={};for(const n in t){const o=t[n];r.indexOf(n)>-1&&o!==null&&(e[n]=o)}return e},a=t=>t==="email";return{nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:t=>({tag:["pre",{tag:"code",attrs:t.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:t=>({tag:`h${t.attrs.level}`}),image:t=>({singleTag:[{tag:"img",attrs:s(t.attrs,["src","alt","title"])}]}),list_item:()=>({tag:"li"}),ordered_list:()=>({tag:"ol"}),paragraph:()=>({tag:"p"}),emoji:t=>({tag:[{tag:"span",attrs:{["data-type"]:"emoji",["data-name"]:t.attrs.name,emoji:t.attrs.emoji}}]})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link:t=>{const r={...t.attrs},{linktype:e="url"}=t.attrs;if(a(e)&&(r.href=`mailto:${r.href}`),r.anchor&&(r.href=`${r.href}#${r.anchor}`,delete r.anchor),r.custom){for(const n in r.custom)r[n]=r.custom[n];delete r.custom}return{tag:[{tag:"a",attrs:r}]}},styled:t=>({tag:[{tag:"span",attrs:t.attrs}]}),subscript:()=>({tag:"sub"}),superscript:()=>({tag:"sup"}),anchor:t=>({tag:[{tag:"span",attrs:t.attrs}]}),highlight:t=>{var e;return(e=t.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${t.attrs.color};`}}]}:{tag:""}},textStyle:t=>{var e;return(e=t.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${t.attrs.color}`}}]}:{tag:""}}}}});

@@ -187,3 +187,3 @@ import { ResponseFn } from './sbFetch';

anchor?: string;
body: Array<ISbComponentType<any>>;
body?: Array<ISbComponentType<any>>;
href?: string;

@@ -193,3 +193,3 @@ level?: number;

custom?: LinkCustomAttributes;
[key: string]: any;
[key: string]: any | undefined;
};

@@ -196,0 +196,0 @@ }

{
"name": "storyblok-js-client",
"version": "5.10.5",
"version": "5.10.6",
"description": "Universal JavaScript SDK for Storyblok's API",

@@ -64,3 +64,3 @@ "license": "MIT",

"vite": "^4.0.4",
"vitest": "^0.30.0"
"vitest": "^0.31.0"
},

@@ -67,0 +67,0 @@ "release": {

@@ -150,5 +150,7 @@ import throttledQueue from './throttlePromise'

node.attrs.body.forEach((blok) => {
html += resolver(blok.component, blok)
})
if (node.attrs.body) {
node.attrs.body.forEach((blok) => {
html += resolver(blok.component, blok)
})
}

@@ -155,0 +157,0 @@ return {

@@ -205,8 +205,8 @@ import { ResponseFn } from './sbFetch'

anchor?: string
body: Array<ISbComponentType<any>>
body?: Array<ISbComponentType<any>>
href?: string
level?: number
linktype?: string
custom?: LinkCustomAttributes,
[key: string]: any,
custom?: LinkCustomAttributes
[key: string]: any | undefined
}

@@ -213,0 +213,0 @@ }

@@ -275,3 +275,3 @@ import defaultHtmlSerializer from './schema'

if (mark) {
if (mark && mark.tag !== '') {
html.push(this.renderOpeningTag(mark.tag))

@@ -313,3 +313,3 @@ }

if (mark) {
if (mark && mark.tag !== '') {
html.push(this.renderClosingTag(mark.tag))

@@ -316,0 +316,0 @@ }

@@ -198,2 +198,6 @@ import { ISbNode, NodeSchema, MarkSchema, ISbComponentType } from './interfaces'

const highlight: MarkSchema = (node: ISbNode) => {
if (!node.attrs?.color) return {
tag: '',
}
const attrs = {

@@ -213,2 +217,6 @@ ['style']: `background-color:${node.attrs.color};`,

const textStyle: MarkSchema = (node: ISbNode) => {
if (!node.attrs?.color) return {
tag: '',
}
const attrs = {

@@ -215,0 +223,0 @@ ['style']: `color:${node.attrs.color}`,

@@ -504,2 +504,132 @@ export const IMAGE_DATA = {

]
}
export const TEXT_WITH_COLORS_MISSING_PARAMETERS = {
"type": "doc",
"content": [
{
"type": "paragraph",
"content": [
{
"text": "Text with ",
"type": "text"
},
{
"text": "highlight",
"type": "text",
"marks": [
{
"type": "highlight",
"attrs": {
"color": ""
}
}
]
},
{
"text": " colors. And another text ",
"type": "text"
},
{
"text": "with text",
"type": "text",
"marks": [
{
"type": "textStyle",
"attrs": {
"color": null
}
}
]
},
{
"text": " color.",
"type": "text"
}
]
}
]
}
export const TEXT_MISSING_PARAMETERS = {
"type": "doc",
"content": [
{
"type": "paragraph",
"content": [
{
"text": "Text with ",
"type": "text"
},
{
"text": "highlight",
"type": "text",
"marks": [
{
"type": "highlight",
"attrs": {
"color": undefined
}
}
]
},
{
"text": " colors. And another text ",
"type": "text"
},
{
"text": "with text",
"type": "text",
"marks": [
{
"type": "textStyle",
"attrs": {}
}
]
},
{
"text": " color.",
"type": "text"
}
]
},
{
"type": "paragraph",
"content": [
{
"text": "Text with ",
"type": "text"
},
{
"text": "highlight",
"type": "text",
"marks": [
{
"type": "highlight",
"attrs": {
"color": null
}
}
]
},
{
"text": " colors. And another text ",
"type": "text"
},
{
"text": "with text",
"type": "text",
"marks": [
{
"type": "textStyle",
}
]
},
{
"text": " color.",
"type": "text"
}
]
}
]
}

@@ -20,3 +20,5 @@ /* eslint-disable no-undef */

TEXT_WITH_EMOJI,
TEXT_WITH_EMOJI_VIA_FALLBACKIMAGE
TEXT_WITH_EMOJI_VIA_FALLBACKIMAGE,
TEXT_WITH_COLORS_MISSING_PARAMETERS,
TEXT_MISSING_PARAMETERS,
} from './constants/richTextResolver'

@@ -525,1 +527,17 @@

})
test('should not render atributes when they are null or empty string', () => {
const result = resolver.render(TEXT_WITH_COLORS_MISSING_PARAMETERS)
const expected = '<p>Text with highlight colors. And another text with text color.</p>'
expect(result).toBe(expected)
})
test('should not render atributes when they are undefined or broken', () => {
const result = resolver.render(TEXT_MISSING_PARAMETERS)
const expected = '<p>Text with highlight colors. And another text with text color.</p><p>Text with highlight colors. And another text with text color.</p>'
expect(result).toBe(expected)
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc