@storyblok/vue 9.2.3 → 9.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,5 +4,5 @@
4
4
  * description: SDK to integrate Storyblok into your project using Vue.
5
5
  * author: Storyblok
6
6
  */
7
- (function(k,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],f):(k=typeof globalThis<"u"?globalThis:k||self,f(k.storyblokVue={},k.Vue))})(this,function(k,f){"use strict";function C(r,e,t){this.type=r,this.tag=e,this.attrs=null,this.map=null,this.nesting=t,this.level=0,this.children=null,this.content="",this.markup="",this.info="",this.meta=null,this.block=!1,this.hidden=!1}C.prototype.attrIndex=function(r){if(!this.attrs)return-1;const e=this.attrs;for(let t=0,s=e.length;t<s;t++)if(e[t][0]===r)return t;return-1},C.prototype.attrPush=function(r){this.attrs?this.attrs.push(r):this.attrs=[r]},C.prototype.attrSet=function(r,e){const t=this.attrIndex(r),s=[r,e];t<0?this.attrPush(s):this.attrs[t]=s},C.prototype.attrGet=function(r){const e=this.attrIndex(r);let t=null;return e>=0&&(t=this.attrs[e][1]),t},C.prototype.attrJoin=function(r,e){const t=this.attrIndex(r);t<0?this.attrPush([r,e]):this.attrs[t][1]=this.attrs[t][1]+" "+e};const oe="[a-zA-Z_:][a-zA-Z0-9:._-]*",ne="[^\"'=<>`\\x00-\\x20]+",ie="'[^']*'",ae='"[^"]*"',le="(?:"+ne+"|"+ie+"|"+ae+")",ce="(?:\\s+"+oe+"(?:\\s*=\\s*"+le+")?)",ue="<[A-Za-z][A-Za-z0-9\\-]*"+ce+"*\\s*\\/?>",he="<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>",de=new RegExp("^(?:"+ue+"|"+he+")");new RegExp(de.source+"\\s*$");const V=[];for(let r=0;r<256;r++)V.push(0);"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(r){V[r.charCodeAt(0)]=1});let v=function(r){return r.DOCUMENT="doc",r.HEADING="heading",r.PARAGRAPH="paragraph",r.QUOTE="blockquote",r.OL_LIST="ordered_list",r.UL_LIST="bullet_list",r.LIST_ITEM="list_item",r.CODE_BLOCK="code_block",r.HR="horizontal_rule",r.BR="hard_break",r.IMAGE="image",r.EMOJI="emoji",r.COMPONENT="blok",r.TABLE="table",r.TABLE_ROW="tableRow",r.TABLE_CELL="tableCell",r.TABLE_HEADER="tableHeader",r}({}),E=function(r){return r.BOLD="bold",r.STRONG="strong",r.STRIKE="strike",r.UNDERLINE="underline",r.ITALIC="italic",r.CODE="code",r.LINK="link",r.ANCHOR="anchor",r.STYLED="styled",r.SUPERSCRIPT="superscript",r.SUBSCRIPT="subscript",r.TEXT_STYLE="textStyle",r.HIGHLIGHT="highlight",r}({}),z=function(r){return r.TEXT="text",r}({}),j=function(r){return r.URL="url",r.STORY="story",r.ASSET="asset",r.EMAIL="email",r}({});function pe(r,e){if(!e)return{src:r,attrs:{}};let t=0,s=0;const o={},n=[];function a(i,u,y,m,A){typeof i!="number"||i<=u||i>=y?console.warn(`[StoryblokRichText] - ${m.charAt(0).toUpperCase()+m.slice(1)} value must be a number between ${u} and ${y} (inclusive)`):A.push(`${m}(${i})`)}if(typeof e=="object"){if(typeof e.width=="number"&&e.width>0?(o.width=e.width,t=e.width):console.warn("[StoryblokRichText] - Width value must be a number greater than 0"),e.height&&typeof e.height=="number"&&e.height>0?(o.height=e.height,s=e.height):console.warn("[StoryblokRichText] - Height value must be a number greater than 0"),e.loading&&["lazy","eager"].includes(e.loading)&&(o.loading=e.loading),e.class&&(o.class=e.class),e.filters){const{filters:i}=e||{},{blur:u,brightness:y,fill:m,format:A,grayscale:R,quality:L,rotate:x}=i||{};u&&a(u,0,100,"blur",n),L&&a(L,0,100,"quality",n),y&&a(y,0,100,"brightness",n),m&&n.push(`fill(${m})`),R&&n.push("grayscale()"),x&&[0,90,180,270].includes(e.filters.rotate||0)&&n.push(`rotate(${x})`),A&&["webp","png","jpeg"].includes(A)&&n.push(`format(${A})`)}e.srcset&&(o.srcset=e.srcset.map(i=>{if(typeof i=="number")return`${r}/m/${i}x0/${n.length>0?`filters:${n.join(":")}`:""} ${i}w`;if(Array.isArray(i)&&i.length===2){const[u,y]=i;return`${r}/m/${u}x${y}/${n.length>0?`filters:${n.join(":")}`:""} ${u}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),e.sizes&&(o.sizes=e.sizes.join(", "))}let c=`${r}/m/`;return t>0&&s>0&&(c=`${c}${t}x${s}/`),n.length>0&&(c=`${c}filters:${n.join(":")}`),{src:c,attrs:o}}const fe=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],ye=(r={})=>Object.keys(r).map(e=>`${e}="${r[e]}"`).join(" "),me=(r={})=>Object.keys(r).map(e=>`${e}: ${r[e]}`).join("; ");function be(r){return r.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}const O=r=>Object.fromEntries(Object.entries(r).filter(([e,t])=>t!==void 0));function F(r,e={},t){const s=ye(e),o=s?`${r} ${s}`:r,n=Array.isArray(t)?t.join(""):t||"";if(r){if(fe.includes(r))return`<${o}>`}else return n;return`<${o}>${n}</${r}>`}function D(r={}){const e=new Map,{renderFn:t=F,textFn:s=be,resolvers:o={},optimizeImages:n=!1,keyedResolvers:a=!1}=r,c=t!==F,i=l=>(h,d)=>{const p=h.attrs||{};return d.render(l,p,h.children||null)},u=(l,h)=>{const{src:d,alt:p,title:g,srcset:T,sizes:_}=l.attrs||{};let w=d,$={};if(n){const{src:We,attrs:Xe}=pe(d,n);w=We,$=Xe}const Ze={src:w,alt:p,title:g,srcset:T,sizes:_,...$};return h.render("img",O(Ze))},y=(l,h)=>{const{level:d,...p}=l.attrs||{};return h.render(`h${d}`,p,l.children)},m=(l,h)=>{var d,p,g,T;const _=h.render("img",{src:(d=l.attrs)==null?void 0:d.fallbackImage,alt:(p=l.attrs)==null?void 0:p.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"});return h.render("span",{"data-type":"emoji","data-name":(g=l.attrs)==null?void 0:g.name,"data-emoji":(T=l.attrs)==null?void 0:T.emoji},_)},A=(l,h)=>h.render("pre",l.attrs||{},h.render("code",{},l.children||"")),R=(l,h=!1)=>({text:d,attrs:p},g)=>{const{class:T,id:_,...w}=p||{},$=h?{class:T,id:_,style:me(w)||void 0}:p||{};return g.render(l,O($),d)},L=l=>M(l),x=l=>{const{marks:h,...d}=l;if("text"in l){if(h)return h.reduce((g,T)=>L({...T,text:g}),L({...d,children:d.children}));const p=l.attrs||{};if(a){const g=e.get("txt")||0;e.set("txt",g+1),p.key=`txt-${g}`}return s(d.text,p)}return""},te=(l,h)=>{const{linktype:d,href:p,anchor:g,...T}=l.attrs||{};let _="";switch(d){case j.ASSET:case j.URL:_=p;break;case j.EMAIL:_=`mailto:${p}`;break;case j.STORY:_=p,g&&(_=`${_}#${g}`);break;default:_=p;break}const w={...T};return _&&(w.href=_),h.render("a",w,l.text)},Fe=(l,h)=>{var d,p;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),h.render("span",{blok:(d=l==null?void 0:l.attrs)==null?void 0:d.body[0],id:(p=l.attrs)==null?void 0:p.id,style:"display: none"})},Ge=(l,h)=>{const d={},p=h.render("tbody",{},l.children);return h.render("table",d,p)},qe=(l,h)=>{const d={};return h.render("tr",d,l.children)},Je=(l,h)=>{const{colspan:d,rowspan:p,colwidth:g,backgroundColor:T,..._}=l.attrs||{},w={..._};d>1&&(w.colspan=d),p>1&&(w.rowspan=p);const $=[];return g&&$.push(`width: ${g}px;`),T&&$.push(`background-color: ${T};`),$.length>0&&(w.style=$.join(" ")),h.render("td",O(w),l.children)},Ke=(l,h)=>{const{colspan:d,rowspan:p,colwidth:g,backgroundColor:T,..._}=l.attrs||{},w={..._};d>1&&(w.colspan=d),p>1&&(w.rowspan=p);const $=[];return g&&$.push(`width: ${g}px;`),T&&$.push(`background-color: ${T};`),$.length>0&&(w.style=$.join(" ")),h.render("th",O(w),l.children)},re=new Map([[v.DOCUMENT,i("")],[v.HEADING,y],[v.PARAGRAPH,i("p")],[v.UL_LIST,i("ul")],[v.OL_LIST,i("ol")],[v.LIST_ITEM,i("li")],[v.IMAGE,u],[v.EMOJI,m],[v.CODE_BLOCK,A],[v.HR,i("hr")],[v.BR,i("br")],[v.QUOTE,i("blockquote")],[v.COMPONENT,Fe],[z.TEXT,x],[E.LINK,te],[E.ANCHOR,te],[E.STYLED,R("span",!0)],[E.BOLD,R("strong")],[E.TEXT_STYLE,R("span",!0)],[E.ITALIC,R("em")],[E.UNDERLINE,R("u")],[E.STRIKE,R("s")],[E.CODE,R("code")],[E.SUPERSCRIPT,R("sup")],[E.SUBSCRIPT,R("sub")],[E.HIGHLIGHT,R("mark")],[v.TABLE,Ge],[v.TABLE_ROW,qe],[v.TABLE_CELL,Je],[v.TABLE_HEADER,Ke]]),se=new Map([...re,...Object.entries(o).map(([l,h])=>[l,h])]),Ye=()=>({render:(l,h={},d)=>{if(a&&l){const p=e.get(l)||0;e.set(l,p+1),h.key=`${l}-${p}`}return t(l,h,d)},originalResolvers:re,mergedResolvers:se});function N(l){const h=se.get(l.type);if(!h)return console.error("<Storyblok>",`No resolver found for node type ${l.type}`),"";const d=Ye();if(l.type==="text")return h(l,d);const p=l.content?l.content.map(M):void 0;return h({...l,children:p},d)}function M(l){return l.type==="doc"?c?l.content.map(N):l.content.map(N).join(""):Array.isArray(l)?l.map(N):N(l)}return{render:M}}let G=!1;const q=[],ge=r=>new Promise((e,t)=>{if(typeof window>"u"){t(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));return}if(window.storyblokRegisterEvent=o=>{if(!window.location.search.includes("_storyblok")){console.warn("You are not in Draft Mode or in the Visual Editor.");return}G?o():q.push(o)},document.getElementById("storyblok-javascript-bridge")){e(void 0);return}const s=document.createElement("script");s.async=!0,s.src=r,s.id="storyblok-javascript-bridge",s.onerror=o=>t(o),s.onload=o=>{q.forEach(n=>n()),G=!0,e(o)},document.getElementsByTagName("head")[0].appendChild(s)});var ke=Object.defineProperty,ve=(r,e,t)=>e in r?ke(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,b=(r,e,t)=>ve(r,typeof e!="symbol"?e+"":e,t);class _e extends Error{constructor(e){super(e),this.name="AbortError"}}function we(r,e,t){if(!Number.isFinite(e))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let o=[],n=0,a=!1;const c=async()=>{n++;const u=s.shift();if(u)try{const m=await r(...u.args);u.resolve(m)}catch(m){u.reject(m)}const y=setTimeout(()=>{n--,s.length>0&&c(),o=o.filter(m=>m!==y)},t);o.includes(y)||o.push(y)},i=(...u)=>a?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((y,m)=>{s.push({resolve:y,reject:m,args:u}),n<e&&c()});return i.abort=()=>{a=!0,o.forEach(clearTimeout),o=[],s.forEach(u=>u.reject(()=>new _e("Throttle function aborted"))),s.length=0},i}const J=(r="")=>r.includes("/cdn/"),Te=(r,e=25,t=1)=>({...r,per_page:e,page:t}),Re=r=>new Promise(e=>setTimeout(e,r)),$e=(r=0,e)=>Array.from({length:r},e),Ee=(r=0,e=r)=>{const t=Math.abs(e-r)||0,s=r<e?1:-1;return $e(t,(o,n)=>n*s+r)},Ae=async(r,e)=>Promise.all(r.map(e)),Se=(r=[],e)=>r.map(e).reduce((t,s)=>[...t,...s],[]),B=(r,e,t)=>{const s=[];for(const o in r){if(!Object.prototype.hasOwnProperty.call(r,o))continue;const n=r[o];if(n==null)continue;const a=t?"":encodeURIComponent(o);let c;typeof n=="object"?c=B(n,e?e+encodeURIComponent(`[${a}]`):a,Array.isArray(n)):c=`${e?e+encodeURIComponent(`[${a}]`):a}=${encodeURIComponent(n)}`,s.push(c)}return s.join("&")},K=r=>{const e={eu:"api.storyblok.com",us:"api-us.storyblok.com",cn:"app.storyblokchina.cn",ap:"api-ap.storyblok.com",ca:"api-ca.storyblok.com"};return e[r]??e.eu};class Ce{constructor(e){b(this,"baseURL"),b(this,"timeout"),b(this,"headers"),b(this,"responseInterceptor"),b(this,"fetch"),b(this,"ejectInterceptor"),b(this,"url"),b(this,"parameters"),b(this,"fetchOptions"),this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={},this.fetchOptions={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t??{},this._methodHandler("delete")}async _responseHandler(e){const t=[],s={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(o=>{s.data=o});for(const o of e.headers.entries())t[o[0]]=o[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;e==="get"?t=`${this.baseURL}${this.url}?${B(this.parameters)}`:s=JSON.stringify(this.parameters);const o=new URL(t),n=new AbortController,{signal:a}=n;let c;this.timeout&&(c=setTimeout(()=>n.abort(),this.timeout));try{const i=await this.fetch(`${o}`,{method:e,headers:this.headers,body:s,signal:a,...this.fetchOptions});this.timeout&&clearTimeout(c);const u=await this._responseHandler(i);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(u)):this._statusHandler(u)}catch(i){return{message:i}}}setFetchOptions(e={}){Object.keys(e).length>0&&"method"in e&&delete e.method,this.fetchOptions={...e}}eject(){this.ejectInterceptor=!0}_normalizeErrorMessage(e){if(Array.isArray(e))return e[0]||"Unknown error";if(e&&typeof e=="object"){if(e.error)return e.error;for(const t in e){if(Array.isArray(e[t]))return`${t}: ${e[t][0]}`;if(typeof e[t]=="string")return`${t}: ${e[t]}`}if(e.slug)return e.slug}return"Unknown error"}_statusHandler(e){const t=/20[0-6]/g;return new Promise((s,o)=>{if(t.test(`${e.status}`))return s(e);const n={message:this._normalizeErrorMessage(e.data),status:e.status,response:e};o(n)})}}const Y="SB-Agent",H={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"7.0.0"},Ie={PUBLISHED:"published"};let P={};const S={};class Le{constructor(e,t){b(this,"client"),b(this,"maxRetries"),b(this,"retriesDelay"),b(this,"throttle"),b(this,"accessToken"),b(this,"cache"),b(this,"resolveCounter"),b(this,"relations"),b(this,"links"),b(this,"version"),b(this,"richTextResolver"),b(this,"resolveNestedRelations"),b(this,"stringifiedStoriesCache"),b(this,"inlineAssets");let s=e.endpoint||t;if(!s){const a=e.https===!1?"http":"https";e.oauthToken?s=`${a}://${K(e.region)}/v1`:s=`${a}://${K(e.region)}/v2`}const o=new Headers;o.set("Content-Type","application/json"),o.set("Accept","application/json"),e.headers&&(e.headers.constructor.name==="Headers"?e.headers.entries().toArray():Object.entries(e.headers)).forEach(([a,c])=>{o.set(a,c)}),o.has(Y)||(o.set(Y,H.defaultAgentName),o.set(H.defaultAgentVersion,H.packageVersion));let n=5;e.oauthToken&&(o.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=e.rateLimit),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=we(this.throttledRequest.bind(this),n,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.version=e.version||Ie.PUBLISHED,this.inlineAssets=e.inlineAssets||!1,this.client=new Ce({baseURL:s,timeout:e.timeout||0,headers:o,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=S[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),typeof e.resolve_relations<"u"&&(e.resolve_level=2),e}factoryParamOptions(e,t){return J(e)?this.parseParams(t):t}makeRequest(e,t,s,o,n){const a=this.factoryParamOptions(e,Te(t,s,o));return this.cacheResponse(e,a,void 0,n)}get(e,t={},s){t||(t={});const o=`/${e}`;J(o)&&(t.version=t.version||this.version);const n=this.factoryParamOptions(o,t);return this.cacheResponse(o,n,void 0,s)}async getAll(e,t={},s,o){const n=(t==null?void 0:t.per_page)||25,a=`/${e}`.replace(/\/$/,""),c=s??a.substring(a.lastIndexOf("/")+1);t.version=t.version||this.version;const i=1,u=await this.makeRequest(a,t,n,i,o),y=u.total?Math.ceil(u.total/(u.perPage||n)):1,m=await Ae(Ee(i,y),A=>this.makeRequest(a,t,n,A+1,o));return Se([u,...m],A=>Object.values(A.data[c]))}post(e,t={},s){const o=`/${e}`;return this.throttle("post",o,t,s)}put(e,t={},s){const o=`/${e}`;return this.throttle("put",o,t,s)}delete(e,t={},s){t||(t={});const o=`/${e}`;return this.throttle("delete",o,t,s)}getStories(e={},t){return this._addResolveLevel(e),this.get("cdn/stories",e,t)}getStory(e,t={},s){return this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t,s)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_addResolveLevel(e){typeof e.resolve_relations<"u"&&(e.resolve_level=2)}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,s){const o=e[t];o&&o.fieldtype==="multilink"&&o.linktype==="story"&&typeof o.id=="string"&&this.links[s][o.id]?o.story=this._cleanCopy(this.links[s][o.id]):o&&o.linktype==="story"&&typeof o.uuid=="string"&&this.links[s][o.uuid]&&(o.story=this._cleanCopy(this.links[s][o.uuid]))}getStoryReference(e,t){return this.relations[e][t]?JSON.parse(this.stringifiedStoriesCache[t]||JSON.stringify(this.relations[e][t])):t}_resolveField(e,t,s){const o=e[t];typeof o=="string"?e[t]=this.getStoryReference(s,o):Array.isArray(o)&&(e[t]=o.map(n=>this.getStoryReference(s,n)).filter(Boolean))}_insertRelations(e,t,s,o){if(Array.isArray(s)?s.find(a=>a.endsWith(`.${t}`)):s.endsWith(`.${t}`)){this._resolveField(e,t,o);return}const n=e.component?`${e.component}.${t}`:t;(Array.isArray(s)?s.includes(n):s===n)&&this._resolveField(e,t,o)}iterateTree(e,t,s){const o=(n,a="")=>{if(!(!n||n._stopResolving)){if(Array.isArray(n))n.forEach((c,i)=>o(c,`${a}[${i}]`));else if(typeof n=="object")for(const c in n){const i=a?`${a}.${c}`:c;(n.component&&n._uid||n.type==="link")&&(this._insertRelations(n,c,t,s),this._insertLinks(n,c,s)),o(n[c],i)}}};o(e.content)}async resolveLinks(e,t,s){let o=[];if(e.link_uuids){const n=e.link_uuids.length,a=[],c=50;for(let i=0;i<n;i+=c){const u=Math.min(n,i+c);a.push(e.link_uuids.slice(i,u))}for(let i=0;i<a.length;i++)(await this.getStories({per_page:c,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:a[i].join(",")})).data.stories.forEach(u=>{o.push(u)})}else o=e.links;o.forEach(n=>{this.links[s][n.uuid]={...n,_stopResolving:!0}})}async resolveRelations(e,t,s){let o=[];if(e.rel_uuids){const n=e.rel_uuids.length,a=[],c=50;for(let i=0;i<n;i+=c){const u=Math.min(n,i+c);a.push(e.rel_uuids.slice(i,u))}for(let i=0;i<a.length;i++)(await this.getStories({per_page:c,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:a[i].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(u=>{o.push(u)});o.length>0&&(e.rels=o,delete e.rel_uuids)}else o=e.rels;o&&o.length>0&&o.forEach(n=>{this.relations[s][n.uuid]={...n,_stopResolving:!0}})}async resolveStories(e,t,s){var o,n;let a=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(a=t.resolve_relations.split(",")),await this.resolveRelations(e,t,s)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((o=e.links)!=null&&o.length||(n=e.link_uuids)!=null&&n.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const c in this.relations[s])this.iterateTree(this.relations[s][c],a,s);e.story?this.iterateTree(e.story,a,s):e.stories.forEach(c=>{this.iterateTree(c,a,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s,o){const n=B({url:e,params:t}),a=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const c=await a.get(n);if(c)return Promise.resolve(c)}return new Promise(async(c,i)=>{var u;try{const y=await this.throttle("get",e,t,o);if(y.status!==200)return i(y);let m={data:y.data,headers:y.headers};if((u=y.headers)!=null&&u["per-page"]&&(m=Object.assign({},m,{perPage:y.headers["per-page"]?Number.parseInt(y.headers["per-page"]):0,total:y.headers["per-page"]?Number.parseInt(y.headers.total):0})),m.data.story||m.data.stories){const R=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(m.data,t,`${R}`),m=await this.processInlineAssets(m)}t.version==="published"&&e!=="/cdn/spaces/me"&&await a.set(n,m);const A=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&m.data.cv&&(A&&S[t.token]&&S[t.token]!==m.data.cv&&await this.flushCache(),S[t.token]=m.data.cv),c(m)}catch(y){if(y.response&&y.status===429&&(s=typeof s>"u"?0:s+1,s<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${this.retriesDelay/1e3} seconds.`),await Re(this.retriesDelay),this.cacheResponse(e,t,s).then(c).catch(i);i(y)}})}throttledRequest(e,t,s,o){return this.client.setFetchOptions(o),this.client[e](t,s)}cacheVersions(){return S}cacheVersion(){return S[this.accessToken]}setCacheVersion(e){this.accessToken&&(S[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(S[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(P[e])},getAll(){return Promise.resolve(P)},set(e,t){return P[e]=t,Promise.resolve(void 0)},flush(){return P={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve()},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this.clearCacheVersion(),this}async processInlineAssets(e){if(!this.inlineAssets)return e;const t=s=>{if(!s||typeof s!="object")return s;if(Array.isArray(s))return s.map(n=>t(n));let o={...s};o.fieldtype==="asset"&&Array.isArray(e.data.assets)&&(o={...o,...e.data.assets.find(n=>n.id===o.id)});for(const n in o)typeof o[n]=="object"&&(o[n]=t(o[n]));return o};return e.data.story&&(e.data.story.content=t(e.data.story.content)),e.data.stories&&(e.data.stories=e.data.stories.map(s=>(s.content=t(s.content),s))),e}}const je=(r={})=>{const{apiOptions:e}=r;if(!e||!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new Le(e)}},Oe=r=>{if(typeof r!="object"||typeof r._editable>"u")return{};try{const e=JSON.parse(r._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":`${e.id}-${e.uid}`}:{}}catch{return{}}};let Z="https://app.storyblok.com/f/storyblok-v2-latest.js";const W=(r,e,t={})=>{var s;const o=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",n=new URL((s=window.location)==null?void 0:s.href).searchParams.get("_storyblok"),a=n!==null&&+n===r;if(!(!o||!a)){if(!r){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],c=>{var i;c&&(c.action==="input"&&((i=c.story)==null?void 0:i.id)===r?e(c.story):(c.action==="change"||c.action==="published")&&c.storyId===r&&window.location.reload())})})}},Pe=(r={})=>{var e,t;const{bridge:s,accessToken:o,use:n=[],apiOptions:a={},bridgeUrl:c}=r;a.accessToken=a.accessToken||o;const i={bridge:s,apiOptions:a};let u={};n.forEach(m=>{u={...u,...m(i)}}),c&&(Z=c);const y=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return s!==!1&&y&&ge(Z),u};function xe(r,e){return D(e).render(r)}const U=f.defineComponent({__name:"StoryblokComponent",props:{blok:{}},setup(r,{expose:e}){var c;const t=r,s=f.ref();e({value:s});const o=typeof f.resolveDynamicComponent(t.blok.component)!="string",n=f.inject("VueSDKOptions"),a=f.ref((c=t.blok.component)==null?void 0:c.replace(/_/g,"-"));return!o&&n&&(n.enableFallbackComponent?(a.value=n.customFallbackComponent??"FallbackComponent",typeof f.resolveDynamicComponent(a.value)=="string"&&console.error(`Is the Fallback component "${a.value}" registered properly?`)):console.error(`Component could not be found for blok "${t.blok.component}"! Is it defined in main.ts as "app.component("${t.blok.component}", ${t.blok.component});"?`)),(i,u)=>(f.openBlock(),f.createBlock(f.resolveDynamicComponent(a.value),f.mergeProps({ref_key:"blokRef",ref:s},{...i.$props,...i.$attrs}),null,16))}}),Ne=r=>{var e,t;return f.h(U,{blok:(e=r==null?void 0:r.attrs)==null?void 0:e.body[0],id:(t=r.attrs)==null?void 0:t.id},r.children)};function X(r){const e={renderFn:f.h,textFn:f.createTextVNode,keyedResolvers:!0,resolvers:{[v.COMPONENT]:Ne,...r.resolvers}};return D(e)}const Q=f.defineComponent({__name:"StoryblokRichText",props:{doc:{},resolvers:{}},setup(r){const e=r,t=f.ref(),s=()=>t.value;return f.watch([()=>e.doc,()=>e.resolvers],([o,n])=>{const{render:a}=X({resolvers:n??{}});t.value=a(o)},{immediate:!0,deep:!0}),(o,n)=>(f.openBlock(),f.createBlock(s))}}),De={beforeMount(r,e){if(e.value){const t=Oe(e.value);Object.keys(t).length>0&&(r.setAttribute("data-blok-c",t["data-blok-c"]),r.setAttribute("data-blok-uid",t["data-blok-uid"]),r.classList.add("storyblok__outline"))}}},ee=r=>{console.error(`You can't use ${r} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
8
- `)};let I=null;const Be=()=>(I||ee("useStoryblokApi"),I),He=async(r,e={},t={})=>{const s=f.ref(null);if(t.resolveRelations=t.resolveRelations??e.resolve_relations,t.resolveLinks=t.resolveLinks??e.resolve_links,f.onMounted(()=>{s.value&&s.value.id&&W(s.value.id,o=>s.value=o,t)}),I){const{data:o}=await I.get(`cdn/stories/${r}`,e);s.value=o.story}else ee("useStoryblok");return s},Ue={install(r,e={}){r.directive("editable",De),r.component("StoryblokComponent",U),r.component("StoryblokRichText",Q),e.enableFallbackComponent&&!e.customFallbackComponent&&r.component("FallbackComponent",f.defineAsyncComponent(()=>Promise.resolve().then(()=>ze)));const{storyblokApi:t}=Pe(e);I=t||null,r.provide("VueSDKOptions",e)}},Me={class:"fallback-component"},Ve={class:"component"},ze=Object.freeze(Object.defineProperty({__proto__:null,default:((r,e)=>{const t=r.__vccOpts||r;for(const[s,o]of e)t[s]=o;return t})(f.defineComponent({__name:"FallbackComponent",props:{blok:{}},setup(r){return(e,t)=>(f.openBlock(),f.createElementBlock("div",Me,[f.createElementVNode("p",null,[t[0]||(t[0]=f.createTextVNode(" Component could not be found for blok ")),f.createElementVNode("span",Ve,f.toDisplayString(e.blok.component),1),t[1]||(t[1]=f.createTextVNode("! Is it configured correctly? "))])]))}}),[["__scopeId","data-v-9abcd1f2"]])},Symbol.toStringTag,{value:"Module"}));k.BlockTypes=v,k.MarkTypes=E,k.StoryblokComponent=U,k.StoryblokRichText=Q,k.StoryblokVue=Ue,k.TextTypes=z,k.apiPlugin=je,k.renderRichText=xe,k.richTextResolver=D,k.useStoryblok=He,k.useStoryblokApi=Be,k.useStoryblokBridge=W,k.useStoryblokRichText=X,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
7
+ (function(k,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],f):(k=typeof globalThis<"u"?globalThis:k||self,f(k.storyblokVue={},k.Vue))})(this,function(k,f){"use strict";var oe=Object.defineProperty,ne=(e,t,r)=>t in e?oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,b=(e,t,r)=>ne(e,typeof t!="symbol"?t+"":t,r);function C(e,t,r){this.type=e,this.tag=t,this.attrs=null,this.map=null,this.nesting=r,this.level=0,this.children=null,this.content="",this.markup="",this.info="",this.meta=null,this.block=!1,this.hidden=!1}C.prototype.attrIndex=function(e){if(!this.attrs)return-1;const t=this.attrs;for(let r=0,s=t.length;r<s;r++)if(t[r][0]===e)return r;return-1},C.prototype.attrPush=function(e){this.attrs?this.attrs.push(e):this.attrs=[e]},C.prototype.attrSet=function(e,t){const r=this.attrIndex(e),s=[e,t];r<0?this.attrPush(s):this.attrs[r]=s},C.prototype.attrGet=function(e){const t=this.attrIndex(e);let r=null;return t>=0&&(r=this.attrs[t][1]),r},C.prototype.attrJoin=function(e,t){const r=this.attrIndex(e);r<0?this.attrPush([e,t]):this.attrs[r][1]=this.attrs[r][1]+" "+t};const ie="[a-zA-Z_:][a-zA-Z0-9:._-]*",ae="[^\"'=<>`\\x00-\\x20]+",le="'[^']*'",ce='"[^"]*"',ue="(?:"+ae+"|"+le+"|"+ce+")",he="(?:\\s+"+ie+"(?:\\s*=\\s*"+ue+")?)",de="<[A-Za-z][A-Za-z0-9\\-]*"+he+"*\\s*\\/?>",pe="<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>",fe=new RegExp("^(?:"+de+"|"+pe+")");new RegExp(fe.source+"\\s*$");const M=[];for(let e=0;e<256;e++)M.push(0);"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(e){M[e.charCodeAt(0)]=1});let v=function(e){return e.DOCUMENT="doc",e.HEADING="heading",e.PARAGRAPH="paragraph",e.QUOTE="blockquote",e.OL_LIST="ordered_list",e.UL_LIST="bullet_list",e.LIST_ITEM="list_item",e.CODE_BLOCK="code_block",e.HR="horizontal_rule",e.BR="hard_break",e.IMAGE="image",e.EMOJI="emoji",e.COMPONENT="blok",e.TABLE="table",e.TABLE_ROW="tableRow",e.TABLE_CELL="tableCell",e.TABLE_HEADER="tableHeader",e}({}),$=function(e){return e.BOLD="bold",e.STRONG="strong",e.STRIKE="strike",e.UNDERLINE="underline",e.ITALIC="italic",e.CODE="code",e.LINK="link",e.ANCHOR="anchor",e.STYLED="styled",e.SUPERSCRIPT="superscript",e.SUBSCRIPT="subscript",e.TEXT_STYLE="textStyle",e.HIGHLIGHT="highlight",e}({}),V=function(e){return e.TEXT="text",e}({}),j=function(e){return e.URL="url",e.STORY="story",e.ASSET="asset",e.EMAIL="email",e}({});function ye(e,t){if(!t)return{src:e,attrs:{}};let r=0,s=0;const o={},n=[];function l(c,u,y,m,E){typeof c!="number"||c<=u||c>=y?console.warn(`[StoryblokRichText] - ${m.charAt(0).toUpperCase()+m.slice(1)} value must be a number between ${u} and ${y} (inclusive)`):E.push(`${m}(${c})`)}if(typeof t=="object"){if(typeof t.width=="number"&&t.width>0?(o.width=t.width,r=t.width):console.warn("[StoryblokRichText] - Width value must be a number greater than 0"),t.height&&typeof t.height=="number"&&t.height>0?(o.height=t.height,s=t.height):console.warn("[StoryblokRichText] - Height value must be a number greater than 0"),t.loading&&["lazy","eager"].includes(t.loading)&&(o.loading=t.loading),t.class&&(o.class=t.class),t.filters){const{filters:c}=t||{},{blur:u,brightness:y,fill:m,format:E,grayscale:A,quality:L,rotate:x}=c||{};u&&l(u,0,100,"blur",n),L&&l(L,0,100,"quality",n),y&&l(y,0,100,"brightness",n),m&&n.push(`fill(${m})`),A&&n.push("grayscale()"),x&&[0,90,180,270].includes(t.filters.rotate||0)&&n.push(`rotate(${x})`),E&&["webp","png","jpeg"].includes(E)&&n.push(`format(${E})`)}t.srcset&&(o.srcset=t.srcset.map(c=>{if(typeof c=="number")return`${e}/m/${c}x0/${n.length>0?`filters:${n.join(":")}`:""} ${c}w`;if(Array.isArray(c)&&c.length===2){const[u,y]=c;return`${e}/m/${u}x${y}/${n.length>0?`filters:${n.join(":")}`:""} ${u}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),t.sizes&&(o.sizes=t.sizes.join(", "))}let a=`${e}/m/`;return r>0&&s>0&&(a=`${a}${r}x${s}/`),n.length>0&&(a=`${a}filters:${n.join(":")}`),{src:a,attrs:o}}const me=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],be=(e={})=>Object.keys(e).map(t=>`${t}="${e[t]}"`).join(" "),ge=(e={})=>Object.keys(e).map(t=>`${t}: ${e[t]}`).join("; ");function ke(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}const O=e=>Object.fromEntries(Object.entries(e).filter(([t,r])=>r!==void 0));function z(e,t={},r){const s=be(t),o=s?`${e} ${s}`:e,n=Array.isArray(r)?r.join(""):r||"";if(e){if(me.includes(e))return`<${o}>`}else return n;return`<${o}>${n}</${e}>`}function D(e={}){const t=new Map,{renderFn:r=z,textFn:s=ke,resolvers:o={},optimizeImages:n=!1,keyedResolvers:l=!1}=e,a=r!==z,c=i=>(h,d)=>{const p=h.attrs||{};return d.render(i,p,h.children||null)},u=(i,h)=>{const{src:d,alt:p,title:g,srcset:T,sizes:_}=i.attrs||{};let w=d,R={};if(n){const{src:et,attrs:tt}=ye(d,n);w=et,R=tt}const Qe={src:w,alt:p,title:g,srcset:T,sizes:_,...R};return h.render("img",O(Qe))},y=(i,h)=>{const{level:d,...p}=i.attrs||{};return h.render(`h${d}`,p,i.children)},m=(i,h)=>{var d,p,g,T;const _=h.render("img",{src:(d=i.attrs)==null?void 0:d.fallbackImage,alt:(p=i.attrs)==null?void 0:p.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"});return h.render("span",{"data-type":"emoji","data-name":(g=i.attrs)==null?void 0:g.name,"data-emoji":(T=i.attrs)==null?void 0:T.emoji},_)},E=(i,h)=>h.render("pre",i.attrs||{},h.render("code",{},i.children||"")),A=(i,h=!1)=>({text:d,attrs:p},g)=>{const{class:T,id:_,...w}=p||{},R=h?{class:T,id:_,style:ge(w)||void 0}:p||{};return g.render(i,O(R),d)},L=i=>F(i),x=i=>{const{marks:h,...d}=i;if("text"in i){if(h)return h.reduce((g,T)=>L({...T,text:g}),L({...d,children:d.children}));const p=i.attrs||{};if(l){const g=t.get("txt")||0;t.set("txt",g+1),p.key=`txt-${g}`}return s(d.text,p)}return""},te=(i,h)=>{const{linktype:d,href:p,anchor:g,...T}=i.attrs||{};let _="";switch(d){case j.ASSET:case j.URL:_=p;break;case j.EMAIL:_=`mailto:${p}`;break;case j.STORY:_=p,g&&(_=`${_}#${g}`);break;default:_=p;break}const w={...T};return _&&(w.href=_),h.render("a",w,i.text)},Ke=(i,h)=>{var d,p;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),h.render("span",{blok:(d=i==null?void 0:i.attrs)==null?void 0:d.body[0],id:(p=i.attrs)==null?void 0:p.id,style:"display: none"})},Je=(i,h)=>{const d={},p=h.render("tbody",{},i.children);return h.render("table",d,p)},Ye=(i,h)=>{const d={};return h.render("tr",d,i.children)},Ze=(i,h)=>{const{colspan:d,rowspan:p,colwidth:g,backgroundColor:T,..._}=i.attrs||{},w={..._};d>1&&(w.colspan=d),p>1&&(w.rowspan=p);const R=[];return g&&R.push(`width: ${g}px;`),T&&R.push(`background-color: ${T};`),R.length>0&&(w.style=R.join(" ")),h.render("td",O(w),i.children)},We=(i,h)=>{const{colspan:d,rowspan:p,colwidth:g,backgroundColor:T,..._}=i.attrs||{},w={..._};d>1&&(w.colspan=d),p>1&&(w.rowspan=p);const R=[];return g&&R.push(`width: ${g}px;`),T&&R.push(`background-color: ${T};`),R.length>0&&(w.style=R.join(" ")),h.render("th",O(w),i.children)},re=new Map([[v.DOCUMENT,c("")],[v.HEADING,y],[v.PARAGRAPH,c("p")],[v.UL_LIST,c("ul")],[v.OL_LIST,c("ol")],[v.LIST_ITEM,c("li")],[v.IMAGE,u],[v.EMOJI,m],[v.CODE_BLOCK,E],[v.HR,c("hr")],[v.BR,c("br")],[v.QUOTE,c("blockquote")],[v.COMPONENT,Ke],[V.TEXT,x],[$.LINK,te],[$.ANCHOR,te],[$.STYLED,A("span",!0)],[$.BOLD,A("strong")],[$.TEXT_STYLE,A("span",!0)],[$.ITALIC,A("em")],[$.UNDERLINE,A("u")],[$.STRIKE,A("s")],[$.CODE,A("code")],[$.SUPERSCRIPT,A("sup")],[$.SUBSCRIPT,A("sub")],[$.HIGHLIGHT,A("mark")],[v.TABLE,Je],[v.TABLE_ROW,Ye],[v.TABLE_CELL,Ze],[v.TABLE_HEADER,We]]),se=new Map([...re,...Object.entries(o).map(([i,h])=>[i,h])]),Xe=()=>({render:(i,h={},d)=>{if(l&&i){const p=t.get(i)||0;t.set(i,p+1),h.key=`${i}-${p}`}return r(i,h,d)},originalResolvers:re,mergedResolvers:se});function N(i){const h=se.get(i.type);if(!h)return console.error("<Storyblok>",`No resolver found for node type ${i.type}`),"";const d=Xe();if(i.type==="text")return h(i,d);const p=i.content?i.content.map(F):void 0;return h({...i,children:p},d)}function F(i){return i.type==="doc"?a?i.content.map(N):i.content.map(N).join(""):Array.isArray(i)?i.map(N):N(i)}return{render:F}}let G=!1;const q=[],ve=e=>new Promise((t,r)=>{if(typeof window>"u"){r(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));return}if(window.storyblokRegisterEvent=o=>{if(!window.location.search.includes("_storyblok")){console.warn("You are not in Draft Mode or in the Visual Editor.");return}G?o():q.push(o)},document.getElementById("storyblok-javascript-bridge")){t(void 0);return}const s=document.createElement("script");s.async=!0,s.src=e,s.id="storyblok-javascript-bridge",s.onerror=o=>r(o),s.onload=o=>{q.forEach(n=>n()),G=!0,t(o)},document.getElementsByTagName("head")[0].appendChild(s)});var _e=class extends Error{constructor(e){super(e),this.name="AbortError"}};function we(e,t,r){if(!Number.isFinite(t))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(r))throw new TypeError("Expected `interval` to be a finite number");const s=[];let o=[],n=0,l=!1;const a=async()=>{n++;const u=s.shift();if(u)try{const m=await e(...u.args);u.resolve(m)}catch(m){u.reject(m)}const y=setTimeout(()=>{n--,s.length>0&&a(),o=o.filter(m=>m!==y)},r);o.includes(y)||o.push(y)},c=(...u)=>l?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((y,m)=>{s.push({resolve:y,reject:m,args:u}),n<t&&a()});return c.abort=()=>{l=!0,o.forEach(clearTimeout),o=[],s.forEach(u=>u.reject(()=>new _e("Throttle function aborted"))),s.length=0},c}var Te=we;const K=(e="")=>e.includes("/cdn/"),Re=(e,t=25,r=1)=>({...e,per_page:t,page:r}),$e=e=>new Promise(t=>setTimeout(t,e)),Ae=(e=0,t)=>Array.from({length:e},t),Ee=(e=0,t=e)=>{const r=Math.abs(t-e)||0,s=e<t?1:-1;return Ae(r,(o,n)=>n*s+e)},Se=async(e,t)=>Promise.all(e.map(t)),Ce=(e=[],t)=>e.map(t).reduce((r,s)=>[...r,...s],[]),B=(e,t,r)=>{const s=[];for(const o in e){if(!Object.prototype.hasOwnProperty.call(e,o))continue;const n=e[o];if(n==null)continue;const l=r?"":encodeURIComponent(o);let a;typeof n=="object"?a=B(n,t?t+encodeURIComponent(`[${l}]`):l,Array.isArray(n)):a=`${t?t+encodeURIComponent(`[${l}]`):l}=${encodeURIComponent(n)}`,s.push(a)}return s.join("&")},J=e=>{const t={eu:"api.storyblok.com",us:"api-us.storyblok.com",cn:"app.storyblokchina.cn",ap:"api-ap.storyblok.com",ca:"api-ca.storyblok.com"};return t[e]??t.eu};var Ie=class{constructor(e){b(this,"baseURL"),b(this,"timeout"),b(this,"headers"),b(this,"responseInterceptor"),b(this,"fetch"),b(this,"ejectInterceptor"),b(this,"url"),b(this,"parameters"),b(this,"fetchOptions"),this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={},this.fetchOptions={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t??{},this._methodHandler("delete")}async _responseHandler(e){const t=[],r={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(s=>{r.data=s});for(const s of e.headers.entries())t[s[0]]=s[1];return r.headers={...t},r.status=e.status,r.statusText=e.statusText,r}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,r=null;e==="get"?t=`${this.baseURL}${this.url}?${B(this.parameters)}`:r=JSON.stringify(this.parameters);const s=new URL(t),o=new AbortController,{signal:n}=o;let l;this.timeout&&(l=setTimeout(()=>o.abort(),this.timeout));try{const a=await this.fetch(`${s}`,{method:e,headers:this.headers,body:r,signal:n,...this.fetchOptions});this.timeout&&clearTimeout(l);const c=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(c)):this._statusHandler(c)}catch(a){return{message:a}}}setFetchOptions(e={}){Object.keys(e).length>0&&"method"in e&&delete e.method,this.fetchOptions={...e}}eject(){this.ejectInterceptor=!0}_normalizeErrorMessage(e){if(Array.isArray(e))return e[0]||"Unknown error";if(e&&typeof e=="object"){if(e.error)return e.error;for(const t in e){if(Array.isArray(e[t]))return`${t}: ${e[t][0]}`;if(typeof e[t]=="string")return`${t}: ${e[t]}`}if(e.slug)return e.slug}return"Unknown error"}_statusHandler(e){const t=/20[0-6]/g;return new Promise((r,s)=>{if(t.test(`${e.status}`))return r(e);const o={message:this._normalizeErrorMessage(e.data),status:e.status,response:e};s(o)})}},Le=Ie;const Y="SB-Agent",H={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"7.0.0"},je={PUBLISHED:"published"};let P={};const S={};var Oe=class{constructor(e,t){b(this,"client"),b(this,"maxRetries"),b(this,"retriesDelay"),b(this,"throttle"),b(this,"accessToken"),b(this,"cache"),b(this,"resolveCounter"),b(this,"relations"),b(this,"links"),b(this,"version"),b(this,"richTextResolver"),b(this,"resolveNestedRelations"),b(this,"stringifiedStoriesCache"),b(this,"inlineAssets");let r=e.endpoint||t;if(!r){const n=e.https===!1?"http":"https";e.oauthToken?r=`${n}://${J(e.region)}/v1`:r=`${n}://${J(e.region)}/v2`}const s=new Headers;s.set("Content-Type","application/json"),s.set("Accept","application/json"),e.headers&&(e.headers.constructor.name==="Headers"?e.headers.entries().toArray():Object.entries(e.headers)).forEach(([n,l])=>{s.set(n,l)}),s.has(Y)||(s.set(Y,H.defaultAgentName),s.set(H.defaultAgentVersion,H.packageVersion));let o=5;e.oauthToken&&(s.set("Authorization",e.oauthToken),o=3),e.rateLimit&&(o=e.rateLimit),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=Te(this.throttledRequest.bind(this),o,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.version=e.version||je.PUBLISHED,this.inlineAssets=e.inlineAssets||!1,this.client=new Le({baseURL:r,timeout:e.timeout||0,headers:s,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=S[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),typeof e.resolve_relations<"u"&&(e.resolve_level=2),e}factoryParamOptions(e,t){return K(e)?this.parseParams(t):t}makeRequest(e,t,r,s,o){const n=this.factoryParamOptions(e,Re(t,r,s));return this.cacheResponse(e,n,void 0,o)}get(e,t={},r){t||(t={});const s=`/${e}`;K(s)&&(t.version=t.version||this.version);const o=this.factoryParamOptions(s,t);return this.cacheResponse(s,o,void 0,r)}async getAll(e,t={},r,s){const o=(t==null?void 0:t.per_page)||25,n=`/${e}`.replace(/\/$/,""),l=r??n.substring(n.lastIndexOf("/")+1);t.version=t.version||this.version;const a=1,c=await this.makeRequest(n,t,o,a,s),u=c.total?Math.ceil(c.total/(c.perPage||o)):1,y=await Se(Ee(a,u),m=>this.makeRequest(n,t,o,m+1,s));return Ce([c,...y],m=>Object.values(m.data[l]))}post(e,t={},r){const s=`/${e}`;return this.throttle("post",s,t,r)}put(e,t={},r){const s=`/${e}`;return this.throttle("put",s,t,r)}delete(e,t={},r){t||(t={});const s=`/${e}`;return this.throttle("delete",s,t,r)}getStories(e={},t){return this._addResolveLevel(e),this.get("cdn/stories",e,t)}getStory(e,t={},r){return this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t,r)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_addResolveLevel(e){typeof e.resolve_relations<"u"&&(e.resolve_level=2)}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,r){const s=e[t];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]))}getStoryReference(e,t){return this.relations[e][t]?JSON.parse(this.stringifiedStoriesCache[t]||JSON.stringify(this.relations[e][t])):t}_resolveField(e,t,r){const s=e[t];typeof s=="string"?e[t]=this.getStoryReference(r,s):Array.isArray(s)&&(e[t]=s.map(o=>this.getStoryReference(r,o)).filter(Boolean))}_insertRelations(e,t,r,s){if(Array.isArray(r)?r.find(n=>n.endsWith(`.${t}`)):r.endsWith(`.${t}`)){this._resolveField(e,t,s);return}const o=e.component?`${e.component}.${t}`:t;(Array.isArray(r)?r.includes(o):r===o)&&this._resolveField(e,t,s)}iterateTree(e,t,r){const s=(o,n="")=>{if(!(!o||o._stopResolving)){if(Array.isArray(o))o.forEach((l,a)=>s(l,`${n}[${a}]`));else if(typeof o=="object")for(const l in o){const a=n?`${n}.${l}`:l;(o.component&&o._uid||o.type==="link")&&(this._insertRelations(o,l,t,r),this._insertLinks(o,l,r)),s(o[l],a)}}};s(e.content)}async resolveLinks(e,t,r){let s=[];if(e.link_uuids){const o=e.link_uuids.length,n=[],l=50;for(let a=0;a<o;a+=l){const c=Math.min(o,a+l);n.push(e.link_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{s.push(c)})}else s=e.links;s.forEach(o=>{this.links[r][o.uuid]={...o,_stopResolving:!0}})}async resolveRelations(e,t,r){let s=[];if(e.rel_uuids){const o=e.rel_uuids.length,n=[],l=50;for(let a=0;a<o;a+=l){const c=Math.min(o,a+l);n.push(e.rel_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(c=>{s.push(c)});s.length>0&&(e.rels=s,delete e.rel_uuids)}else s=e.rels;s&&s.length>0&&s.forEach(o=>{this.relations[r][o.uuid]={...o,_stopResolving:!0}})}async resolveStories(e,t,r){var s,o;let n=[];if(this.links[r]={},this.relations[r]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(n=t.resolve_relations.split(",")),await this.resolveRelations(e,t,r)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((s=e.links)!=null&&s.length||(o=e.link_uuids)!=null&&o.length)&&await this.resolveLinks(e,t,r),this.resolveNestedRelations)for(const l in this.relations[r])this.iterateTree(this.relations[r][l],n,r);e.story?this.iterateTree(e.story,n,r):e.stories.forEach(l=>{this.iterateTree(l,n,r)}),this.stringifiedStoriesCache={},delete this.links[r],delete this.relations[r]}async cacheResponse(e,t,r,s){const o=B({url:e,params:t}),n=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const l=await n.get(o);if(l)return Promise.resolve(l)}return new Promise(async(l,a)=>{var c;try{const u=await this.throttle("get",e,t,s);if(u.status!==200)return a(u);let y={data:u.data,headers:u.headers};if((c=u.headers)!=null&&c["per-page"]&&(y=Object.assign({},y,{perPage:u.headers["per-page"]?Number.parseInt(u.headers["per-page"]):0,total:u.headers["per-page"]?Number.parseInt(u.headers.total):0})),y.data.story||y.data.stories){const E=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(y.data,t,`${E}`),y=await this.processInlineAssets(y)}t.version==="published"&&e!=="/cdn/spaces/me"&&await n.set(o,y);const m=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&y.data.cv&&(m&&S[t.token]&&S[t.token]!==y.data.cv&&await this.flushCache(),S[t.token]=y.data.cv),l(y)}catch(u){if(u.response&&u.status===429&&(r=typeof r>"u"?0:r+1,r<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${this.retriesDelay/1e3} seconds.`),await $e(this.retriesDelay),this.cacheResponse(e,t,r).then(l).catch(a);a(u)}})}throttledRequest(e,t,r,s){return this.client.setFetchOptions(s),this.client[e](t,r)}cacheVersions(){return S}cacheVersion(){return S[this.accessToken]}setCacheVersion(e){this.accessToken&&(S[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(S[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(P[e])},getAll(){return Promise.resolve(P)},set(e,t){return P[e]=t,Promise.resolve(void 0)},flush(){return P={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve()},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this.clearCacheVersion(),this}async processInlineAssets(e){if(!this.inlineAssets)return e;const t=r=>{if(!r||typeof r!="object")return r;if(Array.isArray(r))return r.map(o=>t(o));let s={...r};s.fieldtype==="asset"&&Array.isArray(e.data.assets)&&(s={...s,...e.data.assets.find(o=>o.id===s.id)});for(const o in s)typeof s[o]=="object"&&(s[o]=t(s[o]));return s};return e.data.story&&(e.data.story.content=t(e.data.story.content)),e.data.stories&&(e.data.stories=e.data.stories.map(r=>(r.content=t(r.content),r))),e}},Pe=Oe;const xe=(e={})=>{const{apiOptions:t}=e;if(!t||!t.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 Pe(t)}},Ne=e=>{if(typeof e!="object"||typeof e._editable>"u")return{};try{const t=JSON.parse(e._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return t?{"data-blok-c":JSON.stringify(t),"data-blok-uid":`${t.id}-${t.uid}`}:{}}catch{return{}}};let Z="https://app.storyblok.com/f/storyblok-v2-latest.js";const W=(e,t,r={})=>{var s;const o=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",n=new URL((s=window.location)==null?void 0:s.href).searchParams.get("_storyblok"),l=n!==null&&+n===e;if(!(!o||!l)){if(!e){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(r).on(["input","published","change"],a=>{var c;a&&(a.action==="input"&&((c=a.story)==null?void 0:c.id)===e?t(a.story):(a.action==="change"||a.action==="published")&&a.storyId===e&&window.location.reload())})})}},De=(e={})=>{var t,r;const{bridge:s,accessToken:o,use:n=[],apiOptions:l={},bridgeUrl:a}=e;l.accessToken=l.accessToken||o;const c={bridge:s,apiOptions:l};let u={};n.forEach(m=>{u={...u,...m(c)}}),a&&(Z=a);const y=!(typeof window>"u")&&((r=(t=window.location)==null?void 0:t.search)==null?void 0:r.includes("_storyblok_tk"));return s!==!1&&y&&ve(Z),u};function Be(e,t){return D(t).render(e)}const U=f.defineComponent({__name:"StoryblokComponent",props:{blok:{}},setup(e,{expose:t}){var a;const r=e,s=f.ref();t({value:s});const o=typeof f.resolveDynamicComponent(r.blok.component)!="string",n=f.inject("VueSDKOptions"),l=f.ref((a=r.blok.component)==null?void 0:a.replace(/_/g,"-"));return!o&&n&&(n.enableFallbackComponent?(l.value=n.customFallbackComponent??"FallbackComponent",typeof f.resolveDynamicComponent(l.value)=="string"&&console.error(`Is the Fallback component "${l.value}" registered properly?`)):console.error(`Component could not be found for blok "${r.blok.component}"! Is it defined in main.ts as "app.component("${r.blok.component}", ${r.blok.component});"?`)),(c,u)=>(f.openBlock(),f.createBlock(f.resolveDynamicComponent(l.value),f.mergeProps({ref_key:"blokRef",ref:s},{...c.$props,...c.$attrs}),null,16))}}),He=e=>{var t,r;return f.h(U,{blok:(t=e==null?void 0:e.attrs)==null?void 0:t.body[0],id:(r=e.attrs)==null?void 0:r.id},e.children)};function X(e){const t={renderFn:f.h,textFn:f.createTextVNode,keyedResolvers:!0,resolvers:{[v.COMPONENT]:He,...e.resolvers}};return D(t)}const Q=f.defineComponent({__name:"StoryblokRichText",props:{doc:{},resolvers:{}},setup(e){const t=e,r=f.ref(),s=()=>r.value;return f.watch([()=>t.doc,()=>t.resolvers],([o,n])=>{const{render:l}=X({resolvers:n??{}});r.value=l(o)},{immediate:!0,deep:!0}),(o,n)=>(f.openBlock(),f.createBlock(s))}}),Ue={beforeMount(e,t){if(t.value){const r=Ne(t.value);Object.keys(r).length>0&&(e.setAttribute("data-blok-c",r["data-blok-c"]),e.setAttribute("data-blok-uid",r["data-blok-uid"]),e.classList.add("storyblok__outline"))}}},ee=e=>{console.error(`You can't use ${e} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
8
+ `)};let I=null;const Fe=()=>(I||ee("useStoryblokApi"),I),Me=async(e,t={},r={})=>{const s=f.ref(null);if(r.resolveRelations=r.resolveRelations??t.resolve_relations,r.resolveLinks=r.resolveLinks??t.resolve_links,f.onMounted(()=>{s.value&&s.value.id&&W(s.value.id,o=>s.value=o,r)}),I){const{data:o}=await I.get(`cdn/stories/${e}`,t);s.value=o.story}else ee("useStoryblok");return s},Ve={install(e,t={}){e.directive("editable",Ue),e.component("StoryblokComponent",U),e.component("StoryblokRichText",Q),t.enableFallbackComponent&&!t.customFallbackComponent&&e.component("FallbackComponent",f.defineAsyncComponent(()=>Promise.resolve().then(()=>qe)));const{storyblokApi:r}=De(t);I=r||null,e.provide("VueSDKOptions",t)}},ze={class:"fallback-component"},Ge={class:"component"},qe=Object.freeze(Object.defineProperty({__proto__:null,default:((e,t)=>{const r=e.__vccOpts||e;for(const[s,o]of t)r[s]=o;return r})(f.defineComponent({__name:"FallbackComponent",props:{blok:{}},setup(e){return(t,r)=>(f.openBlock(),f.createElementBlock("div",ze,[f.createElementVNode("p",null,[r[0]||(r[0]=f.createTextVNode(" Component could not be found for blok ")),f.createElementVNode("span",Ge,f.toDisplayString(t.blok.component),1),r[1]||(r[1]=f.createTextVNode("! Is it configured correctly? "))])]))}}),[["__scopeId","data-v-9abcd1f2"]])},Symbol.toStringTag,{value:"Module"}));k.BlockTypes=v,k.MarkTypes=$,k.StoryblokComponent=U,k.StoryblokRichText=Q,k.StoryblokVue=Ve,k.TextTypes=V,k.apiPlugin=xe,k.renderRichText=Be,k.richTextResolver=D,k.useStoryblok=Me,k.useStoryblokApi=Fe,k.useStoryblokBridge=W,k.useStoryblokRichText=X,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});