@storyblok/astro 4.0.5-next.1 → 4.1.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -42,8 +42,12 @@ Install `@storyblok/astro`:
42
42
  ```bash
43
43
  npm install @storyblok/astro
44
44
  # yarn add @storyblok/astro
45
+ # See below for pnpm
45
46
  ```
46
47
 
48
+ > **Note**
49
+ > With pnpm, hoist Storyblok dependencies publicly with `.npmrc`. For more information, check pnpm documentation on [here](https://pnpm.io/npmrc).
50
+
47
51
  Add the following code to `astro.config.mjs` and replace the `accessToken` with the preview API token of your Storyblok space.
48
52
 
49
53
  ```js
@@ -1,4 +1,14 @@
1
- (function(d,y){typeof exports=="object"&&typeof module<"u"?y(exports):typeof define=="function"&&define.amd?define(["exports"],y):(d=typeof globalThis<"u"?globalThis:d||self,y(d.storyblokAstro={}))})(this,function(d){"use strict";let y=!1;const S=[],A=o=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=r=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}y?r():S.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=o,s.id="storyblok-javascript-bridge",s.onerror=r=>t(r),s.onload=r=>{S.forEach(i=>i()),y=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var z=Object.defineProperty,F=(o,e,t)=>e in o?z(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,u=(o,e,t)=>(F(o,typeof e!="symbol"?e+"":e,t),t);function C(o){return!(o!==o||o===1/0||o===-1/0)}function H(o,e,t){if(!C(e))throw new TypeError("Expected `limit` to be a finite number");if(!C(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],i=0;const n=function(){i++;const a=setTimeout(function(){i--,s.length>0&&n(),r=r.filter(function(h){return h!==a})},t);r.indexOf(a)<0&&r.push(a);const l=s.shift();l.resolve(o.apply(l.self,l.args))},c=function(...a){const l=this;return new Promise(function(h,p){s.push({resolve:h,reject:p,args:a,self:l}),i<e&&n()})};return c.abort=function(){r.forEach(clearTimeout),r=[],s.forEach(function(a){a.reject(function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"})}),s.length=0},c}class v{constructor(){u(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1),u(this,"getOptionsPage",(e,t=25,s=1)=>({...e,per_page:t,page:s})),u(this,"delay",e=>new Promise(t=>setTimeout(t,e))),u(this,"arrayFrom",(e=0,t)=>[...Array(e)].map(t)),u(this,"range",(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return this.arrayFrom(s,(i,n)=>n*r+e)}),u(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),u(this,"flatMap",(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[])),u(this,"escapeHTML",function(e){const t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},s=/[&<>"']/g,r=RegExp(s.source);return e&&r.test(e)?e.replace(s,i=>t[i]):e})}stringify(e,t,s){const r=[];for(const i in e){if(!Object.prototype.hasOwnProperty.call(e,i))continue;const n=e[i],c=s?"":encodeURIComponent(i);let a;typeof n=="object"?a=this.stringify(n,t?t+encodeURIComponent("["+c+"]"):c,Array.isArray(n)):a=(t?t+encodeURIComponent("["+c+"]"):c)+"="+encodeURIComponent(n),r.push(a)}return r.join("&")}getRegionURL(e){const t="api.storyblok.com",s="api-us.storyblok.com",r="app.storyblokchina.cn",i="api-ap.storyblok.com",n="api-ca.storyblok.com";switch(e){case"us":return s;case"cn":return r;case"ap":return i;case"ca":return n;default:return t}}}const q=function(o,e){const t={};for(const s in o){const r=o[s];e.indexOf(s)>-1&&r!==null&&(t[s]=r)}return t},B=o=>o==="email",D=()=>({singleTag:"hr"}),V=()=>({tag:"blockquote"}),J=()=>({tag:"ul"}),K=o=>({tag:["pre",{tag:"code",attrs:o.attrs}]}),G=()=>({singleTag:"br"}),W=o=>({tag:`h${o.attrs.level}`}),Y=o=>({singleTag:[{tag:"img",attrs:q(o.attrs,["src","alt","title"])}]}),Q=()=>({tag:"li"}),X=()=>({tag:"ol"}),Z=()=>({tag:"p"}),ee=o=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":o.attrs.name,emoji:o.attrs.emoji}}]}),te=()=>({tag:"b"}),se=()=>({tag:"s"}),re=()=>({tag:"u"}),oe=()=>({tag:"strong"}),ie=()=>({tag:"code"}),ne=()=>({tag:"i"}),ae=o=>{if(!o.attrs)return{tag:""};const e=new v().escapeHTML,t={...o.attrs},{linktype:s="url"}=o.attrs;if(delete t.linktype,t.href&&(t.href=e(o.attrs.href||"")),B(s)&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),t.custom){for(const r in t.custom)t[r]=t.custom[r];delete t.custom}return{tag:[{tag:"a",attrs:t}]}},le=o=>({tag:[{tag:"span",attrs:o.attrs}]}),ce=()=>({tag:"sub"}),he=()=>({tag:"sup"}),ue=o=>({tag:[{tag:"span",attrs:o.attrs}]}),pe=o=>{var e;return(e=o.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${o.attrs.color};`}}]}:{tag:""}},de=o=>{var e;return(e=o.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${o.attrs.color}`}}]}:{tag:""}},O={nodes:{horizontal_rule:D,blockquote:V,bullet_list:J,code_block:K,hard_break:G,heading:W,image:Y,list_item:Q,ordered_list:X,paragraph:Z,emoji:ee},marks:{bold:te,strike:se,underline:re,strong:oe,code:ie,italic:ne,link:ae,styled:le,subscript:ce,superscript:he,anchor:ue,highlight:pe,textStyle:de}},ge=function(o){const e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},t=/[&<>"']/g,s=RegExp(t.source);return o&&s.test(o)?o.replace(t,r=>e[r]):o};class k{constructor(e){u(this,"marks"),u(this,"nodes"),e||(e=O),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e,t={optimizeImages:!1}){if(e&&e.content&&Array.isArray(e.content)){let s="";return e.content.forEach(r=>{s+=this.renderNode(r)}),t.optimizeImages?this.optimizeImages(s,t.optimizeImages):s}return console.warn(`The render method must receive an Object with a "content" field.
1
+ (function(k,L){typeof exports=="object"&&typeof module<"u"?L(exports):typeof define=="function"&&define.amd?define(["exports"],L):(k=typeof globalThis<"u"?globalThis:k||self,L(k.storyblokAstro={}))})(this,function(k){"use strict";function L(o,t,r){const a="virtual:storyblok-init",s="\0"+a;return{name:"vite-plugin-storyblok-init",async resolveId(l){if(l===a)return s},async load(l){if(l===s)return`
2
+ import { storyblokInit, apiPlugin } from "@storyblok/js";
3
+ const { storyblokApi } = storyblokInit({
4
+ accessToken: "${o}",
5
+ use: ${t?"[]":"[apiPlugin]"},
6
+ apiOptions: ${JSON.stringify(r)},
7
+ });
8
+ export const storyblokApiInstance = storyblokApi;
9
+ `}}}const Ye=/[\p{Lu}]/u,Xe=/[\p{Ll}]/u,ge=/^[\p{Lu}](?![\p{Lu}])/gu,he=/([\p{Alpha}\p{N}_]|$)/u,te=/[_.\- ]+/,Ze=new RegExp("^"+te.source),be=new RegExp(te.source+he.source,"gu"),ye=new RegExp("\\d+"+he.source,"gu"),Qe=(o,t,r,a)=>{let s=!1,l=!1,u=!1,f=!1;for(let g=0;g<o.length;g++){const y=o[g];f=g>2?o[g-3]==="-":!0,s&&Ye.test(y)?(o=o.slice(0,g)+"-"+o.slice(g),s=!1,u=l,l=!0,g++):l&&u&&Xe.test(y)&&(!f||a)?(o=o.slice(0,g-1)+"-"+o.slice(g-1),u=l,l=!1,s=!0):(s=t(y)===y&&r(y)!==y,u=l,l=r(y)===y&&t(y)!==y)}return o},Ve=(o,t)=>(ge.lastIndex=0,o.replaceAll(ge,r=>t(r))),et=(o,t)=>(be.lastIndex=0,ye.lastIndex=0,o.replaceAll(ye,(r,a,s)=>["_","-"].includes(o.charAt(s+r.length))?r:t(r)).replaceAll(be,(r,a)=>t(a)));function me(o,t){if(!(typeof o=="string"||Array.isArray(o)))throw new TypeError("Expected the input to be `string | string[]`");if(t={pascalCase:!1,preserveConsecutiveUppercase:!1,...t},Array.isArray(o)?o=o.map(l=>l.trim()).filter(l=>l.length).join("-"):o=o.trim(),o.length===0)return"";const r=t.locale===!1?l=>l.toLowerCase():l=>l.toLocaleLowerCase(t.locale),a=t.locale===!1?l=>l.toUpperCase():l=>l.toLocaleUpperCase(t.locale);return o.length===1?te.test(o)?"":t.pascalCase?a(o):r(o):(o!==r(o)&&(o=Qe(o,r,a,t.preserveConsecutiveUppercase)),o=o.replace(Ze,""),o=t.preserveConsecutiveUppercase?Ve(o,r):r(o),t.pascalCase&&(o=a(o.charAt(0))+o.slice(1)),et(o,a))}function tt(o,t,r,a){const s="virtual:storyblok-components",l="\0"+s;return{name:"vite-plugin-storyblok-components",async resolveId(u){if(u===s)return l},async load(u){if(u===l){const f=[],g=[];for await(const[_,T]of Object.entries(t)){const S=await this.resolve("/"+o+"/"+T+".astro");if(S)f.push(`import ${me(_)} from "${S.id}"`);else if(r)g.push(_);else throw new Error(`Component could not be found for blok "${_}"! Does "${"/"+o+"/"+T}.astro" exist?`)}let y="";if(r)if(y=",FallbackComponent",a){const _=await this.resolve("/"+o+"/"+a+".astro");if(!_)throw new Error(`Custom fallback component could not be found. Does "${"/"+o+"/"+a}.astro" exist?`);f.push(`import FallbackComponent from "${_.id}"`)}else f.push("import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'");if(Object.values(t).length)return`${f.join(";")};export default {${Object.keys(t).filter(_=>!g.includes(_)).map(_=>me(_)).join(",")}${y}}`;if(r)return`${f[0]}; export default {${y.replace(",","")}}`;throw new Error(`Currently, no Storyblok components are registered in astro.config.mjs.
10
+ Please register your components or enable the fallback component.
11
+ Detailed information can be found here: https://github.com/storyblok/storyblok-astro`)}}}}function rt(o){const t="virtual:storyblok-options",r="\0"+t;return{name:"vite-plugin-storyblok-options",async resolveId(a){if(a===t)return r},async load(a){if(a===r)return`export default ${JSON.stringify(o)}`}}}let ve=!1;const _e=[],nt=o=>new Promise((t,r)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=s=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}ve?s():_e.push(s)},document.getElementById("storyblok-javascript-bridge")))return;const a=document.createElement("script");a.async=!0,a.src=o,a.id="storyblok-javascript-bridge",a.onerror=s=>r(s),a.onload=s=>{_e.forEach(l=>l()),ve=!0,t(s)},document.getElementsByTagName("head")[0].appendChild(a)});var ot=Object.defineProperty,it=(o,t,r)=>t in o?ot(o,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):o[t]=r,O=(o,t,r)=>(it(o,typeof t!="symbol"?t+"":t,r),r);class at{constructor(){O(this,"isCDNUrl",(t="")=>t.indexOf("/cdn/")>-1),O(this,"getOptionsPage",(t,r=25,a=1)=>({...t,per_page:r,page:a})),O(this,"delay",t=>new Promise(r=>setTimeout(r,t))),O(this,"arrayFrom",(t=0,r)=>[...Array(t)].map(r)),O(this,"range",(t=0,r=t)=>{const a=Math.abs(r-t)||0,s=t<r?1:-1;return this.arrayFrom(a,(l,u)=>u*s+t)}),O(this,"asyncMap",async(t,r)=>Promise.all(t.map(r))),O(this,"flatMap",(t=[],r)=>t.map(r).reduce((a,s)=>[...a,...s],[])),O(this,"escapeHTML",function(t){const r={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},a=/[&<>"']/g,s=RegExp(a.source);return t&&s.test(t)?t.replace(a,l=>r[l]):t})}stringify(t,r,a){const s=[];for(const l in t){if(!Object.prototype.hasOwnProperty.call(t,l))continue;const u=t[l],f=a?"":encodeURIComponent(l);let g;typeof u=="object"?g=this.stringify(u,r?r+encodeURIComponent("["+f+"]"):f,Array.isArray(u)):g=(r?r+encodeURIComponent("["+f+"]"):f)+"="+encodeURIComponent(u),s.push(g)}return s.join("&")}getRegionURL(t){const r="api.storyblok.com",a="api-us.storyblok.com",s="app.storyblokchina.cn",l="api-ap.storyblok.com",u="api-ca.storyblok.com";switch(t){case"us":return a;case"cn":return s;case"ap":return l;case"ca":return u;default:return r}}}const st=function(o,t){const r={};for(const a in o){const s=o[a];t.indexOf(a)>-1&&s!==null&&(r[a]=s)}return r},lt=o=>o==="email",ct=()=>({singleTag:"hr"}),ut=()=>({tag:"blockquote"}),ft=()=>({tag:"ul"}),dt=o=>({tag:["pre",{tag:"code",attrs:o.attrs}]}),pt=()=>({singleTag:"br"}),gt=o=>({tag:`h${o.attrs.level}`}),ht=o=>({singleTag:[{tag:"img",attrs:st(o.attrs,["src","alt","title"])}]}),bt=()=>({tag:"li"}),yt=()=>({tag:"ol"}),mt=()=>({tag:"p"}),vt=o=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":o.attrs.name,emoji:o.attrs.emoji}}]}),_t=()=>({tag:"b"}),Tt=()=>({tag:"s"}),wt=()=>({tag:"u"}),kt=()=>({tag:"strong"}),St=()=>({tag:"code"}),At=()=>({tag:"i"}),It=o=>{if(!o.attrs)return{tag:""};const t=new at().escapeHTML,r={...o.attrs},{linktype:a="url"}=o.attrs;if(delete r.linktype,r.href&&(r.href=t(o.attrs.href||"")),lt(a)&&(r.href=`mailto:${r.href}`),r.anchor&&(r.href=`${r.href}#${r.anchor}`,delete r.anchor),r.custom){for(const s in r.custom)r[s]=r.custom[s];delete r.custom}return{tag:[{tag:"a",attrs:r}]}},Ot=o=>({tag:[{tag:"span",attrs:o.attrs}]}),Ct=()=>({tag:"sub"}),$t=()=>({tag:"sup"}),jt=o=>({tag:[{tag:"span",attrs:o.attrs}]}),xt=o=>{var t;return(t=o.attrs)!=null&&t.color?{tag:[{tag:"span",attrs:{style:`background-color:${o.attrs.color};`}}]}:{tag:""}},Et=o=>{var t;return(t=o.attrs)!=null&&t.color?{tag:[{tag:"span",attrs:{style:`color:${o.attrs.color}`}}]}:{tag:""}},Te={nodes:{horizontal_rule:ct,blockquote:ut,bullet_list:ft,code_block:dt,hard_break:pt,heading:gt,image:ht,list_item:bt,ordered_list:yt,paragraph:mt,emoji:vt},marks:{bold:_t,strike:Tt,underline:wt,strong:kt,code:St,italic:At,link:It,styled:Ot,subscript:Ct,superscript:$t,anchor:jt,highlight:xt,textStyle:Et}},Rt=function(o){const t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},r=/[&<>"']/g,a=RegExp(r.source);return o&&a.test(o)?o.replace(r,s=>t[s]):o};class we{constructor(t){O(this,"marks"),O(this,"nodes"),t||(t=Te),this.marks=t.marks||[],this.nodes=t.nodes||[]}addNode(t,r){this.nodes[t]=r}addMark(t,r){this.marks[t]=r}render(t,r={optimizeImages:!1}){if(t&&t.content&&Array.isArray(t.content)){let a="";return t.content.forEach(s=>{a+=this.renderNode(s)}),r.optimizeImages?this.optimizeImages(a,r.optimizeImages):a}return console.warn(`The render method must receive an Object with a "content" field.
2
12
  The "content" field must be an array of nodes as the type ISbRichtext.
3
13
  ISbRichtext:
4
14
  content?: ISbRichtext[]
@@ -21,23 +31,14 @@
21
31
  }
22
32
  ],
23
33
  type: 'doc'
24
- }`),""}optimizeImages(e,t){let s=0,r=0,i="",n="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(i+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(i+=`height="${t.height}" `,r=t.height),(t.loading==="lazy"||t.loading==="eager")&&(i+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(i+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(n+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(n+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(n+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(n+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(n+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(n+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(n+=`:rotate(${t.filters.rotate})`),n.length>0&&(n="/filters"+n))),i.length>0&&(e=e.replace(/<img/g,`<img ${i.trim()}`));const c=s>0||r>0||n.length>0?`${s}x${r}${n}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${c}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var l,h;const p=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(p&&p.length>0){const g={srcset:(l=t.srcset)==null?void 0:l.map(f=>{if(typeof f=="number")return`//${p}/m/${f}x0${n} ${f}w`;if(typeof f=="object"&&f.length===2){let I=0,U=0;return typeof f[0]=="number"&&(I=f[0]),typeof f[1]=="number"&&(U=f[1]),`//${p}/m/${I}x${U}${n} ${I}w`}}).join(", "),sizes:(h=t.sizes)==null?void 0:h.map(f=>f).join(", ")};let m="";return g.srcset&&(m+=`srcset="${g.srcset}" `),g.sizes&&(m+=`sizes="${g.sizes}" `),a.replace(/<img/g,`<img ${m.trim()}`)}return a})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const i=this.getMatchingMark(r);i&&i.tag!==""&&t.push(this.renderOpeningTag(i.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(ge(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html?t.push(s.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const i=this.getMatchingMark(r);i&&i.tag!==""&&t.push(this.renderClosingTag(i.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let r=`<${s.tag}`;if(s.attrs)for(const i in s.attrs){const n=s.attrs[i];n!==null&&(r+=` ${i}="${n}"`)}return`${r}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}renderEmoji(e){if(e.attrs.emoji)return e.attrs.emoji;const t=[{tag:"img",attrs:{src:e.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(t," /")}}class fe{constructor(e){u(this,"baseURL"),u(this,"timeout"),u(this,"headers"),u(this,"responseInterceptor"),u(this,"fetch"),u(this,"ejectInterceptor"),u(this,"url"),u(this,"parameters"),u(this,"fetchOptions"),this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={},this.fetchOptions={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t,this._methodHandler("delete")}async _responseHandler(e){const t=[],s={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(r=>{s.data=r});for(const r of e.headers.entries())t[r[0]]=r[1];return s.headers={...t},s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,s=null;if(e==="get"){const a=new v;t=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),i=new AbortController,{signal:n}=i;let c;this.timeout&&(c=setTimeout(()=>i.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:n,...this.fetchOptions});this.timeout&&clearTimeout(c);const l=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(l)):this._statusHandler(l)}catch(a){return{message:a}}}setFetchOptions(e={}){Object.keys(e).length>0&&"method"in e&&delete e.method,this.fetchOptions={...e}}eject(){this.ejectInterceptor=!0}_statusHandler(e){const t=/20[0-6]/g;return new Promise((s,r)=>{if(t.test(`${e.status}`))return s(e);const i={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};r(i)})}}const x="SB-Agent",T={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"};let w={};const b={};class me{constructor(e,t){u(this,"client"),u(this,"maxRetries"),u(this,"throttle"),u(this,"accessToken"),u(this,"cache"),u(this,"helpers"),u(this,"resolveCounter"),u(this,"relations"),u(this,"links"),u(this,"richTextResolver"),u(this,"resolveNestedRelations"),u(this,"stringifiedStoriesCache");let s=e.endpoint||t;if(!s){const n=new v().getRegionURL,c=e.https===!1?"http":"https";e.oauthToken?s=`${c}://${n(e.region)}/v1`:s=`${c}://${n(e.region)}/v2`}const r=new Headers;if(r.set("Content-Type","application/json"),r.set("Accept","application/json"),e.headers)for(const n in e.headers)r.set(n,e.headers[n]);r.has(x)||(r.set(x,T.defaultAgentName),r.set(T.defaultAgentVersion,T.packageVersion));let i=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),i=3),e.rateLimit&&(i=e.rateLimit),e.richTextSchema?this.richTextResolver=new k(e.richTextSchema):this.richTextResolver=new k,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=H(this.throttledRequest,i,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new v,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.client=new fe({baseURL:s,timeout:e.timeout||0,headers:r,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return t.attrs.body&&t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=b[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),typeof e.resolve_relations<"u"&&(e.resolve_level=2),e}factoryParamOptions(e,t){return this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,r){const i=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,i)}get(e,t,s){t||(t={});const r=`/${e}`,i=this.factoryParamOptions(r,t);return this.client.setFetchOptions(s),this.cacheResponse(r,i)}async getAll(e,t,s,r){const i=(t==null?void 0:t.per_page)||25,n=`/${e}`,c=n.split("/"),a=s||c[c.length-1],l=1,h=await this.makeRequest(n,t,i,l),p=h.total?Math.ceil(h.total/i):1;this.client.setFetchOptions(r);const g=await this.helpers.asyncMap(this.helpers.range(l,p),m=>this.makeRequest(n,t,i,m+1));return this.helpers.flatMap([h,...g],m=>Object.values(m.data[a]))}post(e,t,s){const r=`/${e}`;return this.client.setFetchOptions(s),Promise.resolve(this.throttle("post",r,t))}put(e,t,s){const r=`/${e}`;return this.client.setFetchOptions(s),Promise.resolve(this.throttle("put",r,t))}delete(e,t,s){const r=`/${e}`;return this.client.setFetchOptions(s),Promise.resolve(this.throttle("delete",r,t))}getStories(e,t){return this.client.setFetchOptions(t),this._addResolveLevel(e),this.get("cdn/stories",e)}getStory(e,t,s){return this.client.setFetchOptions(s),this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_addResolveLevel(e){typeof e.resolve_relations<"u"&&(e.resolve_level=2)}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,s){const r=e[t];r&&r.fieldtype=="multilink"&&r.linktype=="story"&&typeof r.id=="string"&&this.links[s][r.id]?r.story=this._cleanCopy(this.links[s][r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[s][r.uuid]&&(r.story=this._cleanCopy(this.links[s][r.uuid]))}getStoryReference(e,t){return this.relations[e][t]?(this.stringifiedStoriesCache[t]||(this.stringifiedStoriesCache[t]=JSON.stringify(this.relations[e][t])),JSON.parse(this.stringifiedStoriesCache[t])):t}_insertRelations(e,t,s,r){s.indexOf(`${e.component}.${t}`)>-1&&(typeof e[t]=="string"?e[t]=this.getStoryReference(r,e[t]):Array.isArray(e[t])&&(e[t]=e[t].map(i=>this.getStoryReference(r,i)).filter(Boolean)))}iterateTree(e,t,s){const r=i=>{if(i!=null){if(i.constructor===Array)for(let n=0;n<i.length;n++)r(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,t,s),this._insertLinks(i,n,s)),r(i[n])}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const i=e.link_uuids.length,n=[],c=50;for(let a=0;a<i;a+=c){const l=Math.min(i,a+c);n.push(e.link_uuids.slice(a,l))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(l=>{r.push(l)})}else r=e.links;r.forEach(i=>{this.links[s][i.uuid]={...i,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const i=e.rel_uuids.length,n=[],c=50;for(let a=0;a<i;a+=c){const l=Math.min(i,a+c);n.push(e.rel_uuids.slice(a,l))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:n[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(l=>{r.push(l)})}else r=e.rels;r&&r.length>0&&r.forEach(i=>{this.relations[s][i.uuid]={...i,_stopResolving:!0}})}async resolveStories(e,t,s){var r,i;let n=[];if(this.links[s]={},this.relations[s]={},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,s)),t.resolve_links&&["1","story","url","link"].indexOf(t.resolve_links)>-1&&((r=e.links)!=null&&r.length||(i=e.link_uuids)!=null&&i.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const c in this.relations[s])this.iterateTree(this.relations[s][c],n,s);e.story?this.iterateTree(e.story,n,s):e.stories.forEach(c=>{this.iterateTree(c,n,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s){(typeof s>"u"||!s)&&(s=0);const r=this.helpers.stringify({url:e,params:t}),i=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const n=await i.get(r);if(n)return Promise.resolve(n)}return new Promise(async(n,c)=>{var a;try{const l=await this.throttle("get",e,t);if(l.status!==200)return c(l);let h={data:l.data,headers:l.headers};if((a=l.headers)!=null&&a["per-page"]&&(h=Object.assign({},h,{perPage:l.headers["per-page"]?parseInt(l.headers["per-page"]):0,total:l.headers["per-page"]?parseInt(l.headers.total):0})),h.data.story||h.data.stories){const p=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(h.data,t,`${p}`)}return t.version==="published"&&e!="/cdn/spaces/me"&&await i.set(r,h),h.data.cv&&t.token&&(t.version==="draft"&&b[t.token]!=h.data.cv&&await this.flushCache(),b[t.token]=t.cv?t.cv:h.data.cv),n(h)}catch(l){if(l.response&&l.status===429&&(s=s?s+1:0,s<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${s} seconds.`),await this.helpers.delay(1e3*s),this.cacheResponse(e,t,s).then(n).catch(c);c(l)}})}throttledRequest(e,t,s){return this.client[e](t,s)}cacheVersions(){return b}cacheVersion(){return b[this.accessToken]}setCacheVersion(e){this.accessToken&&(b[this.accessToken]=e)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(w[e])},getAll(){return Promise.resolve(w)},set(e,t){return w[e]=t,Promise.resolve(void 0)},flush(){return w={},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}}const ye=(o={})=>{const{apiOptions:e}=o;if(!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new me(e)}},be=o=>{if(typeof o!="object"||typeof o._editable>"u")return{};try{const e=JSON.parse(o._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}:{}}catch{return{}}};let $,R="https://app.storyblok.com/f/storyblok-v2-latest.js";const ke=(o={})=>{var e,t;const{bridge:s,accessToken:r,use:i=[],apiOptions:n={},richText:c={},bridgeUrl:a}=o;n.accessToken=n.accessToken||r;const l={bridge:s,apiOptions:n};let h={};i.forEach(g=>{h={...h,...g(l)}}),a&&(R=a);const p=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return s!==!1&&p&&A(R),$=new k(c.schema),c.resolver&&j($,c.resolver),h},j=(o,e)=>{o.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},ve=o=>!o||!(o!=null&&o.content.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule")),we=(o,e,t)=>{let s=t||$;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return ve(o)?"":(e&&(s=new k(e.schema),e.resolver&&j(s,e.resolver)),s.render(o))},Te=()=>A(R);function $e(o,e,t){const s="virtual:storyblok-init",r="\0"+s;return globalThis.apiPlugin=ye,globalThis.storyblokInit=ke,{name:"vite-plugin-storyblok-init",async resolveId(i){if(i===s)return r},async load(i){if(i===r)return`
25
- const { storyblokApi } = globalThis.storyblokInit({
26
- accessToken: "${o}",
27
- use: ${e?"[]":"[globalThis.apiPlugin]"},
28
- apiOptions: ${JSON.stringify(t)},
29
- });
30
- export const storyblokApiInstance = storyblokApi;
31
- `}}}const Re=/[\p{Lu}]/u,_e=/[\p{Ll}]/u,E=/^[\p{Lu}](?![\p{Lu}])/gu,P=/([\p{Alpha}\p{N}_]|$)/u,_=/[_.\- ]+/,Ie=new RegExp("^"+_.source),L=new RegExp(_.source+P.source,"gu"),N=new RegExp("\\d+"+P.source,"gu"),Se=(o,e,t,s)=>{let r=!1,i=!1,n=!1,c=!1;for(let a=0;a<o.length;a++){const l=o[a];c=a>2?o[a-3]==="-":!0,r&&Re.test(l)?(o=o.slice(0,a)+"-"+o.slice(a),r=!1,n=i,i=!0,a++):i&&n&&_e.test(l)&&(!c||s)?(o=o.slice(0,a-1)+"-"+o.slice(a-1),n=i,i=!1,r=!0):(r=e(l)===l&&t(l)!==l,n=i,i=t(l)===l&&e(l)!==l)}return o},Ae=(o,e)=>(E.lastIndex=0,o.replaceAll(E,t=>e(t))),Ce=(o,e)=>(L.lastIndex=0,N.lastIndex=0,o.replaceAll(N,(t,s,r)=>["_","-"].includes(o.charAt(r+t.length))?t:e(t)).replaceAll(L,(t,s)=>e(s)));function M(o,e){if(!(typeof o=="string"||Array.isArray(o)))throw new TypeError("Expected the input to be `string | string[]`");if(e={pascalCase:!1,preserveConsecutiveUppercase:!1,...e},Array.isArray(o)?o=o.map(i=>i.trim()).filter(i=>i.length).join("-"):o=o.trim(),o.length===0)return"";const t=e.locale===!1?i=>i.toLowerCase():i=>i.toLocaleLowerCase(e.locale),s=e.locale===!1?i=>i.toUpperCase():i=>i.toLocaleUpperCase(e.locale);return o.length===1?_.test(o)?"":e.pascalCase?s(o):t(o):(o!==t(o)&&(o=Se(o,t,s,e.preserveConsecutiveUppercase)),o=o.replace(Ie,""),o=e.preserveConsecutiveUppercase?Ae(o,t):t(o),e.pascalCase&&(o=s(o.charAt(0))+o.slice(1)),Ce(o,s))}function Oe(o,e,t,s){const r="virtual:storyblok-components",i="\0"+r;return{name:"vite-plugin-storyblok-components",async resolveId(n){if(n===r)return i},async load(n){if(n===i){const c=[],a=[];for await(const[h,p]of Object.entries(e)){const g=await this.resolve("/"+o+"/"+p+".astro");if(g)c.push(`import ${M(h)} from "${g.id}"`);else if(t)a.push(h);else throw new Error(`Component could not be found for blok "${h}"! Does "${"/"+o+"/"+p}.astro" exist?`)}let l="";if(t)if(l=",FallbackComponent",s){const h=await this.resolve("/"+o+"/"+s+".astro");if(!h)throw new Error(`Custom fallback component could not be found. Does "${"/"+o+"/"+s}.astro" exist?`);c.push(`import FallbackComponent from "${h.id}"`)}else c.push("import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'");if(Object.values(e).length)return`${c.join(";")};export default {${Object.keys(e).filter(h=>!a.includes(h)).map(h=>M(h)).join(",")}${l}}`;if(t)return`${c[0]}; export default {${l.replace(",","")}}`;throw new Error(`Currently, no Storyblok components are registered in astro.config.mjs.
32
- Please register your components or enable the fallback component.
33
- Detailed information can be found here: https://github.com/storyblok/storyblok-astro`)}}}}function xe(o){const e="virtual:storyblok-options",t="\0"+e;return{name:"vite-plugin-storyblok-options",async resolveId(s){if(s===e)return t},async load(s){if(s===t)return`export default ${JSON.stringify(o)}`}}}function je(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),globalThis.storyblokApiInstance}function Ee(o,e){const t=globalThis.storyblokApiInstance.richTextResolver;if(!t){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return we(o,e,t)}function Pe(o){const e={useCustomApi:!1,bridge:!0,componentsDir:"src",enableFallbackComponent:!1,...o};return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:t,updateConfig:s,addDevToolbarApp:r})=>{if(s({vite:{plugins:[$e(e.accessToken,e.useCustomApi,e.apiOptions),Oe(e.componentsDir,e.components,e.enableFallbackComponent,e.customFallbackComponent),xe(e)]}}),t("page-ssr",`
34
+ }`),""}optimizeImages(t,r){let a=0,s=0,l="",u="";typeof r!="boolean"&&(typeof r.width=="number"&&r.width>0&&(l+=`width="${r.width}" `,a=r.width),typeof r.height=="number"&&r.height>0&&(l+=`height="${r.height}" `,s=r.height),(r.loading==="lazy"||r.loading==="eager")&&(l+=`loading="${r.loading}" `),typeof r.class=="string"&&r.class.length>0&&(l+=`class="${r.class}" `),r.filters&&(typeof r.filters.blur=="number"&&r.filters.blur>=0&&r.filters.blur<=100&&(u+=`:blur(${r.filters.blur})`),typeof r.filters.brightness=="number"&&r.filters.brightness>=-100&&r.filters.brightness<=100&&(u+=`:brightness(${r.filters.brightness})`),r.filters.fill&&(r.filters.fill.match(/[0-9A-Fa-f]{6}/g)||r.filters.fill==="transparent")&&(u+=`:fill(${r.filters.fill})`),r.filters.format&&["webp","png","jpeg"].includes(r.filters.format)&&(u+=`:format(${r.filters.format})`),typeof r.filters.grayscale=="boolean"&&r.filters.grayscale&&(u+=":grayscale()"),typeof r.filters.quality=="number"&&r.filters.quality>=0&&r.filters.quality<=100&&(u+=`:quality(${r.filters.quality})`),r.filters.rotate&&[90,180,270].includes(r.filters.rotate)&&(u+=`:rotate(${r.filters.rotate})`),u.length>0&&(u="/filters"+u))),l.length>0&&(t=t.replace(/<img/g,`<img ${l.trim()}`));const f=a>0||s>0||u.length>0?`${a}x${s}${u}`:"";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/${f}`),typeof r!="boolean"&&(r.sizes||r.srcset)&&(t=t.replace(/<img.*?src=["|'](.*?)["|']/g,g=>{var y,_;const T=g.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(T&&T.length>0){const S={srcset:(y=r.srcset)==null?void 0:y.map(w=>{if(typeof w=="number")return`//${T}/m/${w}x0${u} ${w}w`;if(typeof w=="object"&&w.length===2){let z=0,J=0;return typeof w[0]=="number"&&(z=w[0]),typeof w[1]=="number"&&(J=w[1]),`//${T}/m/${z}x${J}${u} ${z}w`}}).join(", "),sizes:(_=r.sizes)==null?void 0:_.map(w=>w).join(", ")};let C="";return S.srcset&&(C+=`srcset="${S.srcset}" `),S.sizes&&(C+=`sizes="${S.sizes}" `),g.replace(/<img/g,`<img ${C.trim()}`)}return g})),t}renderNode(t){const r=[];t.marks&&t.marks.forEach(s=>{const l=this.getMatchingMark(s);l&&l.tag!==""&&r.push(this.renderOpeningTag(l.tag))});const a=this.getMatchingNode(t);return a&&a.tag&&r.push(this.renderOpeningTag(a.tag)),t.content?t.content.forEach(s=>{r.push(this.renderNode(s))}):t.text?r.push(Rt(t.text)):a&&a.singleTag?r.push(this.renderTag(a.singleTag," /")):a&&a.html?r.push(a.html):t.type==="emoji"&&r.push(this.renderEmoji(t)),a&&a.tag&&r.push(this.renderClosingTag(a.tag)),t.marks&&t.marks.slice(0).reverse().forEach(s=>{const l=this.getMatchingMark(s);l&&l.tag!==""&&r.push(this.renderClosingTag(l.tag))}),r.join("")}renderTag(t,r){return t.constructor===String?`<${t}${r}>`:t.map(a=>{if(a.constructor===String)return`<${a}${r}>`;{let s=`<${a.tag}`;if(a.attrs)for(const l in a.attrs){const u=a.attrs[l];u!==null&&(s+=` ${l}="${u}"`)}return`${s}${r}>`}}).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 r=this.nodes[t.type];if(typeof r=="function")return r(t)}getMatchingMark(t){const r=this.marks[t.type];if(typeof r=="function")return r(t)}renderEmoji(t){if(t.attrs.emoji)return t.attrs.emoji;const r=[{tag:"img",attrs:{src:t.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(r," /")}}const Mt=o=>{if(typeof o!="object"||typeof o._editable>"u")return{};try{const t=JSON.parse(o._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return t?{"data-blok-c":JSON.stringify(t),"data-blok-uid":t.id+"-"+t.uid}:{}}catch{return{}}};let Pt,Lt="https://app.storyblok.com/f/storyblok-v2-latest.js";const Nt=(o,t)=>{o.addNode("blok",r=>{let a="";return r.attrs.body.forEach(s=>{a+=t(s.component,s)}),{html:a}})},zt=o=>!o||!(o!=null&&o.content.some(t=>t.content||t.type==="blok"||t.type==="horizontal_rule")),Ut=(o,t,r)=>{let a=r||Pt;if(!a){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return zt(o)?"":(t&&(a=new we(t.schema),t.resolver&&Nt(a,t.resolver)),a.render(o))},Dt=()=>nt(Lt);function Bt(o){let t={resolveRelations:[]};function r(a){a&&(Array.isArray(a)?t.resolveRelations.push(...a):t.resolveRelations.push(a))}for(const a of o)if(a.options){const{apiOptions:s,bridgeOptions:l}=a.options;if(r(s==null?void 0:s.resolve_relations),l){const{resolveRelations:u,...f}=l;r(u),Object.assign(t,f)}}return t.resolveRelations=[...new Set(t.resolveRelations)],t}var q=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ft(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var G={exports:{}};G.exports,function(o,t){var r=200,a="__lodash_hash_undefined__",s=800,l=16,u=9007199254740991,f="[object Arguments]",g="[object Array]",y="[object AsyncFunction]",_="[object Boolean]",T="[object Date]",S="[object Error]",C="[object Function]",w="[object GeneratorFunction]",z="[object Map]",J="[object Number]",rr="[object Null]",Se="[object Object]",nr="[object Proxy]",or="[object RegExp]",ir="[object Set]",ar="[object String]",sr="[object Undefined]",lr="[object WeakMap]",cr="[object ArrayBuffer]",ur="[object DataView]",fr="[object Float32Array]",dr="[object Float64Array]",pr="[object Int8Array]",gr="[object Int16Array]",hr="[object Int32Array]",br="[object Uint8Array]",yr="[object Uint8ClampedArray]",mr="[object Uint16Array]",vr="[object Uint32Array]",_r=/[\\^$.*+?()[\]{}|]/g,Tr=/^\[object .+?Constructor\]$/,wr=/^(?:0|[1-9]\d*)$/,b={};b[fr]=b[dr]=b[pr]=b[gr]=b[hr]=b[br]=b[yr]=b[mr]=b[vr]=!0,b[f]=b[g]=b[cr]=b[_]=b[ur]=b[T]=b[S]=b[C]=b[z]=b[J]=b[Se]=b[or]=b[ir]=b[ar]=b[lr]=!1;var Ae=typeof q=="object"&&q&&q.Object===Object&&q,kr=typeof self=="object"&&self&&self.Object===Object&&self,U=Ae||kr||Function("return this")(),Ie=t&&!t.nodeType&&t,D=Ie&&!0&&o&&!o.nodeType&&o,Oe=D&&D.exports===Ie,re=Oe&&Ae.process,Ce=function(){try{var e=D&&D.require&&D.require("util").types;return e||re&&re.binding&&re.binding("util")}catch{}}(),$e=Ce&&Ce.isTypedArray;function Sr(e,n,i){switch(i.length){case 0:return e.call(n);case 1:return e.call(n,i[0]);case 2:return e.call(n,i[0],i[1]);case 3:return e.call(n,i[0],i[1],i[2])}return e.apply(n,i)}function Ar(e,n){for(var i=-1,c=Array(e);++i<e;)c[i]=n(i);return c}function Ir(e){return function(n){return e(n)}}function Or(e,n){return e==null?void 0:e[n]}function Cr(e,n){return function(i){return e(n(i))}}var $r=Array.prototype,jr=Function.prototype,K=Object.prototype,ne=U["__core-js_shared__"],W=jr.toString,$=K.hasOwnProperty,je=function(){var e=/[^.]+$/.exec(ne&&ne.keys&&ne.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),xe=K.toString,xr=W.call(Object),Er=RegExp("^"+W.call($).replace(_r,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Y=Oe?U.Buffer:void 0,Ee=U.Symbol,Re=U.Uint8Array,Me=Y?Y.allocUnsafe:void 0,Pe=Cr(Object.getPrototypeOf,Object),Le=Object.create,Rr=K.propertyIsEnumerable,Mr=$r.splice,x=Ee?Ee.toStringTag:void 0,X=function(){try{var e=ae(Object,"defineProperty");return e({},"",{}),e}catch{}}(),Pr=Y?Y.isBuffer:void 0,Ne=Math.max,Lr=Date.now,ze=ae(U,"Map"),B=ae(Object,"create"),Nr=function(){function e(){}return function(n){if(!R(n))return{};if(Le)return Le(n);e.prototype=n;var i=new e;return e.prototype=void 0,i}}();function E(e){var n=-1,i=e==null?0:e.length;for(this.clear();++n<i;){var c=e[n];this.set(c[0],c[1])}}function zr(){this.__data__=B?B(null):{},this.size=0}function Ur(e){var n=this.has(e)&&delete this.__data__[e];return this.size-=n?1:0,n}function Dr(e){var n=this.__data__;if(B){var i=n[e];return i===a?void 0:i}return $.call(n,e)?n[e]:void 0}function Br(e){var n=this.__data__;return B?n[e]!==void 0:$.call(n,e)}function Fr(e,n){var i=this.__data__;return this.size+=this.has(e)?0:1,i[e]=B&&n===void 0?a:n,this}E.prototype.clear=zr,E.prototype.delete=Ur,E.prototype.get=Dr,E.prototype.has=Br,E.prototype.set=Fr;function j(e){var n=-1,i=e==null?0:e.length;for(this.clear();++n<i;){var c=e[n];this.set(c[0],c[1])}}function Hr(){this.__data__=[],this.size=0}function qr(e){var n=this.__data__,i=Z(n,e);if(i<0)return!1;var c=n.length-1;return i==c?n.pop():Mr.call(n,i,1),--this.size,!0}function Gr(e){var n=this.__data__,i=Z(n,e);return i<0?void 0:n[i][1]}function Jr(e){return Z(this.__data__,e)>-1}function Kr(e,n){var i=this.__data__,c=Z(i,e);return c<0?(++this.size,i.push([e,n])):i[c][1]=n,this}j.prototype.clear=Hr,j.prototype.delete=qr,j.prototype.get=Gr,j.prototype.has=Jr,j.prototype.set=Kr;function M(e){var n=-1,i=e==null?0:e.length;for(this.clear();++n<i;){var c=e[n];this.set(c[0],c[1])}}function Wr(){this.size=0,this.__data__={hash:new E,map:new(ze||j),string:new E}}function Yr(e){var n=V(this,e).delete(e);return this.size-=n?1:0,n}function Xr(e){return V(this,e).get(e)}function Zr(e){return V(this,e).has(e)}function Qr(e,n){var i=V(this,e),c=i.size;return i.set(e,n),this.size+=i.size==c?0:1,this}M.prototype.clear=Wr,M.prototype.delete=Yr,M.prototype.get=Xr,M.prototype.has=Zr,M.prototype.set=Qr;function P(e){var n=this.__data__=new j(e);this.size=n.size}function Vr(){this.__data__=new j,this.size=0}function en(e){var n=this.__data__,i=n.delete(e);return this.size=n.size,i}function tn(e){return this.__data__.get(e)}function rn(e){return this.__data__.has(e)}function nn(e,n){var i=this.__data__;if(i instanceof j){var c=i.__data__;if(!ze||c.length<r-1)return c.push([e,n]),this.size=++i.size,this;i=this.__data__=new M(c)}return i.set(e,n),this.size=i.size,this}P.prototype.clear=Vr,P.prototype.delete=en,P.prototype.get=tn,P.prototype.has=rn,P.prototype.set=nn;function on(e,n){var i=ce(e),c=!i&&le(e),p=!i&&!c&&He(e),h=!i&&!c&&!p&&Ge(e),m=i||c||p||h,d=m?Ar(e.length,String):[],v=d.length;for(var I in e)(n||$.call(e,I))&&!(m&&(I=="length"||p&&(I=="offset"||I=="parent")||h&&(I=="buffer"||I=="byteLength"||I=="byteOffset")||Be(I,v)))&&d.push(I);return d}function oe(e,n,i){(i!==void 0&&!ee(e[n],i)||i===void 0&&!(n in e))&&ie(e,n,i)}function an(e,n,i){var c=e[n];(!($.call(e,n)&&ee(c,i))||i===void 0&&!(n in e))&&ie(e,n,i)}function Z(e,n){for(var i=e.length;i--;)if(ee(e[i][0],n))return i;return-1}function ie(e,n,i){n=="__proto__"&&X?X(e,n,{configurable:!0,enumerable:!0,value:i,writable:!0}):e[n]=i}var sn=_n();function Q(e){return e==null?e===void 0?sr:rr:x&&x in Object(e)?Tn(e):On(e)}function Ue(e){return F(e)&&Q(e)==f}function ln(e){if(!R(e)||An(e))return!1;var n=fe(e)?Er:Tr;return n.test(xn(e))}function cn(e){return F(e)&&qe(e.length)&&!!b[Q(e)]}function un(e){if(!R(e))return In(e);var n=Fe(e),i=[];for(var c in e)c=="constructor"&&(n||!$.call(e,c))||i.push(c);return i}function De(e,n,i,c,p){e!==n&&sn(n,function(h,m){if(p||(p=new P),R(h))fn(e,n,m,i,De,c,p);else{var d=c?c(se(e,m),h,m+"",e,n,p):void 0;d===void 0&&(d=h),oe(e,m,d)}},Je)}function fn(e,n,i,c,p,h,m){var d=se(e,i),v=se(n,i),I=m.get(v);if(I){oe(e,i,I);return}var A=h?h(d,v,i+"",e,n,m):void 0,H=A===void 0;if(H){var de=ce(v),pe=!de&&He(v),We=!de&&!pe&&Ge(v);A=v,de||pe||We?ce(d)?A=d:En(d)?A=yn(d):pe?(H=!1,A=gn(v,!0)):We?(H=!1,A=bn(v,!0)):A=[]:Rn(v)||le(v)?(A=d,le(d)?A=Mn(d):(!R(d)||fe(d))&&(A=wn(v))):H=!1}H&&(m.set(v,A),p(A,v,c,h,m),m.delete(v)),oe(e,i,A)}function dn(e,n){return $n(Cn(e,n,Ke),e+"")}var pn=X?function(e,n){return X(e,"toString",{configurable:!0,enumerable:!1,value:Ln(n),writable:!0})}:Ke;function gn(e,n){if(n)return e.slice();var i=e.length,c=Me?Me(i):new e.constructor(i);return e.copy(c),c}function hn(e){var n=new e.constructor(e.byteLength);return new Re(n).set(new Re(e)),n}function bn(e,n){var i=n?hn(e.buffer):e.buffer;return new e.constructor(i,e.byteOffset,e.length)}function yn(e,n){var i=-1,c=e.length;for(n||(n=Array(c));++i<c;)n[i]=e[i];return n}function mn(e,n,i,c){var p=!i;i||(i={});for(var h=-1,m=n.length;++h<m;){var d=n[h],v=c?c(i[d],e[d],d,i,e):void 0;v===void 0&&(v=e[d]),p?ie(i,d,v):an(i,d,v)}return i}function vn(e){return dn(function(n,i){var c=-1,p=i.length,h=p>1?i[p-1]:void 0,m=p>2?i[2]:void 0;for(h=e.length>3&&typeof h=="function"?(p--,h):void 0,m&&kn(i[0],i[1],m)&&(h=p<3?void 0:h,p=1),n=Object(n);++c<p;){var d=i[c];d&&e(n,d,c,h)}return n})}function _n(e){return function(n,i,c){for(var p=-1,h=Object(n),m=c(n),d=m.length;d--;){var v=m[e?d:++p];if(i(h[v],v,h)===!1)break}return n}}function V(e,n){var i=e.__data__;return Sn(n)?i[typeof n=="string"?"string":"hash"]:i.map}function ae(e,n){var i=Or(e,n);return ln(i)?i:void 0}function Tn(e){var n=$.call(e,x),i=e[x];try{e[x]=void 0;var c=!0}catch{}var p=xe.call(e);return c&&(n?e[x]=i:delete e[x]),p}function wn(e){return typeof e.constructor=="function"&&!Fe(e)?Nr(Pe(e)):{}}function Be(e,n){var i=typeof e;return n=n??u,!!n&&(i=="number"||i!="symbol"&&wr.test(e))&&e>-1&&e%1==0&&e<n}function kn(e,n,i){if(!R(i))return!1;var c=typeof n;return(c=="number"?ue(i)&&Be(n,i.length):c=="string"&&n in i)?ee(i[n],e):!1}function Sn(e){var n=typeof e;return n=="string"||n=="number"||n=="symbol"||n=="boolean"?e!=="__proto__":e===null}function An(e){return!!je&&je in e}function Fe(e){var n=e&&e.constructor,i=typeof n=="function"&&n.prototype||K;return e===i}function In(e){var n=[];if(e!=null)for(var i in Object(e))n.push(i);return n}function On(e){return xe.call(e)}function Cn(e,n,i){return n=Ne(n===void 0?e.length-1:n,0),function(){for(var c=arguments,p=-1,h=Ne(c.length-n,0),m=Array(h);++p<h;)m[p]=c[n+p];p=-1;for(var d=Array(n+1);++p<n;)d[p]=c[p];return d[n]=i(m),Sr(e,this,d)}}function se(e,n){if(!(n==="constructor"&&typeof e[n]=="function")&&n!="__proto__")return e[n]}var $n=jn(pn);function jn(e){var n=0,i=0;return function(){var c=Lr(),p=l-(c-i);if(i=c,p>0){if(++n>=s)return arguments[0]}else n=0;return e.apply(void 0,arguments)}}function xn(e){if(e!=null){try{return W.call(e)}catch{}try{return e+""}catch{}}return""}function ee(e,n){return e===n||e!==e&&n!==n}var le=Ue(function(){return arguments}())?Ue:function(e){return F(e)&&$.call(e,"callee")&&!Rr.call(e,"callee")},ce=Array.isArray;function ue(e){return e!=null&&qe(e.length)&&!fe(e)}function En(e){return F(e)&&ue(e)}var He=Pr||Nn;function fe(e){if(!R(e))return!1;var n=Q(e);return n==C||n==w||n==y||n==nr}function qe(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=u}function R(e){var n=typeof e;return e!=null&&(n=="object"||n=="function")}function F(e){return e!=null&&typeof e=="object"}function Rn(e){if(!F(e)||Q(e)!=Se)return!1;var n=Pe(e);if(n===null)return!0;var i=$.call(n,"constructor")&&n.constructor;return typeof i=="function"&&i instanceof i&&W.call(i)==xr}var Ge=$e?Ir($e):cn;function Mn(e){return mn(e,Je(e))}function Je(e){return ue(e)?on(e,!0):un(e)}var Pn=vn(function(e,n,i,c){De(e,n,i,c)});function Ln(e){return function(){return e}}function Ke(e){return e}function Nn(){return!1}o.exports=Pn}(G,G.exports);var Ht=G.exports;const qt=Ft(Ht);function Gt(o){let t;function r(a,s){var l,u,f;(s==null?void 0:s.type)==="AwaitExpression"&&((u=(l=s==null?void 0:s.argument)==null?void 0:l.callee)==null?void 0:u.name)==="useStoryblok"&&((f=s==null?void 0:s.argument)==null?void 0:f.arguments).forEach(y=>{var _;(_=y==null?void 0:y.properties)==null||_.forEach(T=>{var S;["apiOptions","bridgeOptions"].includes(T.key.name)&&(t={...t,[T.key.name]:Jt((S=T==null?void 0:T.value)==null?void 0:S.properties)})})})}return qt({},o,r),t}function Jt(o){return o.reduce((t,{key:r,value:a})=>{const{type:s}=a;return t[r.name]=s==="Literal"?a.value:s==="ArrayExpression"?a.elements.map(l=>l.value):a.value,t},{})}let N=[];function Kt(o,t){const r="virtual:storyblok-bridge",a="\0"+r;if(!o||t!=="server")return{name:"vite-plugin-storyblok-bridge",resolveId(f){if(f===r)return a},load(f){if(f===a)return"export const bridgeOptions = null"}};let s=[],l=null,u=null;return{name:"vite-plugin-storyblok-bridge",async resolveId(f){if(f===r)return a},async transform(f,g){var C;if(g.includes("node_modules")&&!g.includes("/pages/")||!f.includes("useStoryblok")||!((C=this.getModuleInfo(g).meta)!=null&&C.astro))return;const[,..._]=g.split("src/pages/"),T=_.join("/").replace(".astro",""),S=Gt(this.parse(f));N.length&&(s=N.filter(w=>w.url!==T)),s.push({url:T,options:S}),l&&(u&&clearTimeout(u),u=setTimeout(()=>{Wt(N,s)||(N.length!==0&&(l.restart(),console.info("Updating bridge options...")),N=[...s])},1e3))},async load(f){if(f===a)return`export const bridgeOptions = ${JSON.stringify(Bt(s))}`},configureServer(f){l=f}}}function Wt(o=[],t=[]){return t.every(({url:r,options:a})=>{const s=o.find(l=>(l==null?void 0:l.url)===r);return s&&JSON.stringify(a)===JSON.stringify(s.options)})}let ke;async function Yt(o){const{action:t,story:r}=o||{};if(t==="input"&&r){const a=async()=>{const l=await Zt(r),u=document.body;if(l.outerHTML===u.outerHTML)return;const f=document.querySelector('[data-blok-focused="true"]');Xt(u,l,f)};clearTimeout(ke),ke=setTimeout(a,1e3)}["published","change"].includes(o==null?void 0:o.action)&&location.reload()}function Xt(o,t,r){if(r){const a=r.getAttribute("data-blok-uid"),s=t.querySelector(`[data-blok-uid="${a}"]`);s&&(s.setAttribute("data-blok-focused","true"),r.replaceWith(s))}else o.replaceWith(t)}async function Zt(o){const r=await(await fetch(location.href,{method:"POST",body:JSON.stringify({...o,is_storyblok_preview:!0}),headers:{"Content-Type":"application/json"}})).text();return new DOMParser().parseFromString(r,"text/html").body}function Qt(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),globalThis.storyblokApiInstance}async function Vt({slug:o,apiOptions:t={},bridgeOptions:r={},Astro:a}){globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly");let s=null;if(a&&a.locals._storyblok_preview_data)s=a.locals._storyblok_preview_data;else{const{data:l}=await globalThis.storyblokApiInstance.get(o,t,r);s=l.story}return s}function er(o,t){const r=globalThis.storyblokApiInstance.richTextResolver;if(!r){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return Ut(o,t,r)}function tr(o){const t={useCustomApi:!1,bridge:!0,componentsDir:"src",enableFallbackComponent:!1,experimentalLivePreview:!1,...o};return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:r,updateConfig:a,addDevToolbarApp:s,addMiddleware:l,config:u})=>{if(a({vite:{plugins:[L(t.accessToken,t.useCustomApi,t.apiOptions),tt(t.componentsDir,t.components,t.enableFallbackComponent,t.customFallbackComponent),rt(t),Kt(t.experimentalLivePreview,u.output)]}}),t.experimentalLivePreview&&(u==null?void 0:u.output)!=="server")throw new Error("To utilize the Astro Storyblok Live feature, Astro must be configured in SSR mode. Please disable this feature or switch Astro to SSR mode.");if(r("page-ssr",`
34
35
  import { storyblokApiInstance } from "virtual:storyblok-init";
35
36
  globalThis.storyblokApiInstance = storyblokApiInstance;
36
- `),e.bridge){let i="";if(typeof e.bridge=="object"){const n={...e.bridge};i=`const storyblokInstance = new StoryblokBridge(${JSON.stringify(n)});`}else i="const storyblokInstance = new StoryblokBridge()";t("page",`
37
+ `),t.bridge&&!t.experimentalLivePreview){let f="";if(typeof t.bridge=="object"){const g={...t.bridge};f=`const storyblokInstance = new StoryblokBridge(${JSON.stringify(g)});`}else f="const storyblokInstance = new StoryblokBridge()";r("page",`
37
38
  import { loadStoryblokBridge } from "@storyblok/astro";
38
39
  loadStoryblokBridge().then(() => {
39
40
  const { StoryblokBridge, location } = window;
40
- ${i}
41
+ ${f}
41
42
 
42
43
  storyblokInstance.on(["published", "change"], (event) => {
43
44
  if (!event.slugChanged) {
@@ -45,4 +46,15 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
45
46
  }
46
47
  });
47
48
  });
48
- `)}r("@storyblok/astro/toolbar-app-storyblok.ts")}}}}d.RichTextResolver=k,d.RichTextSchema=O,d.default=Pe,d.loadStoryblokBridge=Te,d.renderRichText=Ee,d.storyblokEditable=be,d.useStoryblokApi=je,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
49
+ `)}t.experimentalLivePreview&&(r("page",`
50
+ import { loadStoryblokBridge, handleStoryblokMessage } from "@storyblok/astro";
51
+ import { bridgeOptions } from "virtual:storyblok-bridge";
52
+
53
+ loadStoryblokBridge().then(() => {
54
+ const { StoryblokBridge, location } = window;
55
+ if(bridgeOptions){
56
+ const storyblokInstance = new StoryblokBridge(bridgeOptions);
57
+ storyblokInstance.on(["published", "change","input"], handleStoryblokMessage);
58
+ };
59
+ });
60
+ `),l({entrypoint:"@storyblok/astro/middleware.ts",order:"pre"})),s("@storyblok/astro/toolbarApp.ts")}}}}k.RichTextResolver=we,k.RichTextSchema=Te,k.default=tr,k.handleStoryblokMessage=Yt,k.loadStoryblokBridge=Dt,k.renderRichText=er,k.storyblokEditable=Mt,k.useStoryblok=Vt,k.useStoryblokApi=Qt,Object.defineProperties(k,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});