@storyblok/astro 5.0.2 → 5.1.0-alpha.2
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 +28 -14
- package/dev-toolbar/toolbarApp.ts +5 -7
- package/dist/storyblok-astro.js +27 -15
- package/dist/storyblok-astro.mjs +860 -891
- package/dist/types/content-layer/storyblokLoader.d.ts +7 -0
- package/dist/types/content-layer/syncContentUpdate.d.ts +4 -0
- package/dist/types/dev-toolbar/toolbarApp.d.ts +2 -6
- package/dist/types/index.d.ts +9 -3
- package/dist/types/node_modules/astro/dist/runtime/client/dev-toolbar/ui-library/icons.d.ts +35 -0
- package/dist/types/node_modules/astro/dist/toolbar/index.d.ts +2 -0
- package/dist/types/utils/initStoryblokBridge.d.ts +2 -0
- package/live-preview/handleStoryblokMessage.ts +2 -0
- package/package.json +2 -2
- package/utils/initStoryblokBridge.ts +11 -0
- package/dist/types/utils/generateFinalBridgeObject.d.ts +0 -3
- package/dist/types/utils/parseAstCode.d.ts +0 -7
- package/dist/types/vite-plugins/vite-plugin-storyblok-bridge.d.ts +0 -12
- package/utils/generateFinalBridgeObject.ts +0 -33
- package/utils/parseAstCode.ts +0 -66
package/README.md
CHANGED
|
@@ -375,33 +375,47 @@ export default defineConfig({
|
|
|
375
375
|
});
|
|
376
376
|
```
|
|
377
377
|
|
|
378
|
-
|
|
378
|
+
1. Additionally, please use `getLiveStory` on your Astro pages for getting live story.
|
|
379
379
|
|
|
380
380
|
```jsx
|
|
381
381
|
//pages/[...slug].astro
|
|
382
382
|
---
|
|
383
|
-
import {
|
|
383
|
+
import { getLiveStory, useStoryblokApi, type ISbStoryData } from "@storyblok/astro";
|
|
384
384
|
import StoryblokComponent from "@storyblok/astro/StoryblokComponent.astro";
|
|
385
385
|
|
|
386
386
|
const { slug } = Astro.params;
|
|
387
387
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
{}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
388
|
+
let story: ISbStoryData = null;
|
|
389
|
+
|
|
390
|
+
const liveStory = await getLiveStory(Astro);
|
|
391
|
+
|
|
392
|
+
if (liveStory) {
|
|
393
|
+
story = liveStory;
|
|
394
|
+
} else {
|
|
395
|
+
const sbApi = useStoryblokApi();
|
|
396
|
+
const { data } = await sbApi.get(
|
|
397
|
+
`cdn/stories/${slug === undefined ? "home" : slug}`,
|
|
398
|
+
{
|
|
399
|
+
version: "draft",
|
|
400
|
+
resolve_relations: ["featured-articles.posts"],
|
|
401
|
+
}
|
|
402
|
+
);
|
|
403
|
+
story = data?.story;
|
|
404
|
+
}
|
|
400
405
|
---
|
|
401
406
|
|
|
402
407
|
<StoryblokComponent blok={story.content} />
|
|
403
408
|
```
|
|
409
|
+
2. You can also listen to when the live preview is updated.
|
|
404
410
|
|
|
411
|
+
```js
|
|
412
|
+
<script>
|
|
413
|
+
document.addEventListener("storyblok-live-preview-updated", () => {
|
|
414
|
+
// console.log("Live preview: body updated");
|
|
415
|
+
// initUnoCssRuntime(); regenerate all the css
|
|
416
|
+
});
|
|
417
|
+
</script>
|
|
418
|
+
```
|
|
405
419
|
## The Storyblok JavaScript SDK Ecosystem
|
|
406
420
|
|
|
407
421
|

|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { defineToolbarApp } from "astro/toolbar";
|
|
2
|
+
|
|
2
3
|
import {
|
|
3
4
|
isDefinedIcon,
|
|
4
5
|
type Icon,
|
|
5
6
|
} from "astro/runtime/client/dev-toolbar/ui-library/icons.js";
|
|
6
7
|
|
|
7
|
-
const storyblokLogo = `<svg width="45px" height="53px" viewBox="0 0 45 53" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
8
|
+
export const storyblokLogo = `<svg width="45px" height="53px" viewBox="0 0 45 53" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
8
9
|
<g id="storyblok-logo-kit" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
9
10
|
<g id="storyblok-partner-logo" transform="translate(-59.000000, -169.000000)" fill-rule="nonzero">
|
|
10
11
|
<g id="storyblok-symbol" transform="translate(59.000000, 169.000000)">
|
|
@@ -35,10 +36,7 @@ function createWindowElement(content: string) {
|
|
|
35
36
|
return windowElement;
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
export default {
|
|
39
|
-
id: "storyblok",
|
|
40
|
-
name: "Storyblok",
|
|
41
|
-
icon: storyblokLogo,
|
|
39
|
+
export default defineToolbarApp({
|
|
42
40
|
init(canvas) {
|
|
43
41
|
createCanvas();
|
|
44
42
|
|
|
@@ -182,4 +180,4 @@ export default {
|
|
|
182
180
|
canvas.append(windowComponent);
|
|
183
181
|
}
|
|
184
182
|
},
|
|
185
|
-
}
|
|
183
|
+
});
|
package/dist/storyblok-astro.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(g,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(g=typeof globalThis<"u"?globalThis:g||self,b(g.storyblokAstro={}))})(this,function(g){"use strict";function b(o,e,t){const s="virtual:storyblok-init",r="\0"+s;return{name:"vite-plugin-storyblok-init",async resolveId(n){if(n===s)return r},async load(n){if(n===r)return`
|
|
2
2
|
import { storyblokInit, apiPlugin } from "@storyblok/js";
|
|
3
3
|
const { storyblokApi } = storyblokInit({
|
|
4
4
|
accessToken: "${o}",
|
|
5
|
-
use: ${
|
|
5
|
+
use: ${e?"[]":"[apiPlugin]"},
|
|
6
6
|
apiOptions: ${JSON.stringify(t)},
|
|
7
7
|
});
|
|
8
8
|
export const storyblokApiInstance = storyblokApi;
|
|
9
|
-
`}}}const
|
|
9
|
+
`}}}const D=/[\p{Lu}]/u,F=/[\p{Ll}]/u,_=/^[\p{Lu}](?![\p{Lu}])/gu,A=/([\p{Alpha}\p{N}_]|$)/u,S=/[_.\- ]+/,J=new RegExp("^"+S.source),I=new RegExp(S.source+A.source,"gu"),O=new RegExp("\\d+"+A.source,"gu"),q=(o,e,t,s)=>{let r=!1,n=!1,i=!1,l=!1;for(let a=0;a<o.length;a++){const c=o[a];l=a>2?o[a-3]==="-":!0,r&&D.test(c)?(o=o.slice(0,a)+"-"+o.slice(a),r=!1,i=n,n=!0,a++):n&&i&&F.test(c)&&(!l||s)?(o=o.slice(0,a-1)+"-"+o.slice(a-1),i=n,n=!1,r=!0):(r=e(c)===c&&t(c)!==c,i=n,n=t(c)===c&&e(c)!==c)}return o},V=(o,e)=>(_.lastIndex=0,o.replaceAll(_,t=>e(t))),K=(o,e)=>(I.lastIndex=0,O.lastIndex=0,o.replaceAll(O,(t,s,r)=>["_","-"].includes(o.charAt(r+t.length))?t:e(t)).replaceAll(I,(t,s)=>e(s)));function L(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(n=>n.trim()).filter(n=>n.length).join("-"):o=o.trim(),o.length===0)return"";const t=e.locale===!1?n=>n.toLowerCase():n=>n.toLocaleLowerCase(e.locale),s=e.locale===!1?n=>n.toUpperCase():n=>n.toLocaleUpperCase(e.locale);return o.length===1?S.test(o)?"":e.pascalCase?s(o):t(o):(o!==t(o)&&(o=q(o,t,s,e.preserveConsecutiveUppercase)),o=o.replace(J,""),o=e.preserveConsecutiveUppercase?V(o,t):t(o),e.pascalCase&&(o=s(o.charAt(0))+o.slice(1)),K(o,s))}function W(o,e,t,s){const r="virtual:storyblok-components",n="\0"+r;return{name:"vite-plugin-storyblok-components",async resolveId(i){if(i===r)return n},async load(i){if(i===n){const l=[],a=[];for await(const[h,u]of Object.entries(e)){const p=await this.resolve("/"+o+"/"+u+".astro");if(p)l.push(`import ${L(h)} from "${p.id}"`);else if(t)a.push(h);else throw new Error(`Component could not be found for blok "${h}"! Does "${"/"+o+"/"+u}.astro" exist?`)}let c="";if(t)if(c=",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?`);l.push(`import FallbackComponent from "${h.id}"`)}else l.push("import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'");if(Object.values(e).length)return`${l.join(";")};export default {${Object.keys(e).filter(h=>!a.includes(h)).map(h=>L(h)).join(",")}${c}}`;if(t)return`${l[0]}; export default {${c.replace(",","")}}`;throw new Error(`Currently, no Storyblok components are registered in astro.config.mjs.
|
|
10
10
|
Please register your components or enable the fallback component.
|
|
11
|
-
Detailed information can be found here: https://github.com/storyblok/storyblok-astro`)}}}}function
|
|
11
|
+
Detailed information can be found here: https://github.com/storyblok/storyblok-astro`)}}}}function Z(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)}`}}}let j=!1;const E=[],x=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}j?r():E.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=>{E.forEach(n=>n()),j=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var Y=Object.defineProperty,G=(o,e,t)=>e in o?Y(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,d=(o,e,t)=>G(o,typeof e!="symbol"?e+"":e,t);function P(o){return!(o!==o||o===1/0||o===-1/0)}function Q(o,e,t){if(!P(e))throw new TypeError("Expected `limit` to be a finite number");if(!P(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],n=0;const i=function(){n++;const a=setTimeout(function(){n--,s.length>0&&i(),r=r.filter(function(h){return h!==a})},t);r.indexOf(a)<0&&r.push(a);const c=s.shift();c.resolve(o.apply(c.self,c.args))},l=function(...a){const c=this;return new Promise(function(h,u){s.push({resolve:h,reject:u,args:a,self:c}),n<e&&i()})};return l.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},l}class v{constructor(){d(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1),d(this,"getOptionsPage",(e,t=25,s=1)=>({...e,per_page:t,page:s})),d(this,"delay",e=>new Promise(t=>setTimeout(t,e))),d(this,"arrayFrom",(e=0,t)=>[...Array(e)].map(t)),d(this,"range",(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return this.arrayFrom(s,(n,i)=>i*r+e)}),d(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),d(this,"flatMap",(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[])),d(this,"escapeHTML",function(e){const t={"&":"&","<":"<",">":">",'"':""","'":"'"},s=/[&<>"']/g,r=RegExp(s.source);return e&&r.test(e)?e.replace(s,n=>t[n]):e})}stringify(e,t,s){const r=[];for(const n in e){if(!Object.prototype.hasOwnProperty.call(e,n))continue;const i=e[n],l=s?"":encodeURIComponent(n);let a;typeof i=="object"?a=this.stringify(i,t?t+encodeURIComponent("["+l+"]"):l,Array.isArray(i)):a=(t?t+encodeURIComponent("["+l+"]"):l)+"="+encodeURIComponent(i),r.push(a)}return r.join("&")}getRegionURL(e){const t="api.storyblok.com",s="api-us.storyblok.com",r="app.storyblokchina.cn",n="api-ap.storyblok.com",i="api-ca.storyblok.com";switch(e){case"us":return s;case"cn":return r;case"ap":return n;case"ca":return i;default:return t}}}const X=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},ee=o=>o==="email",te=()=>({singleTag:"hr"}),se=()=>({tag:"blockquote"}),re=()=>({tag:"ul"}),oe=o=>({tag:["pre",{tag:"code",attrs:o.attrs}]}),ne=()=>({singleTag:"br"}),ie=o=>({tag:`h${o.attrs.level}`}),ae=o=>({singleTag:[{tag:"img",attrs:X(o.attrs,["src","alt","title"])}]}),le=()=>({tag:"li"}),ce=()=>({tag:"ol"}),he=()=>({tag:"p"}),ue=o=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":o.attrs.name,emoji:o.attrs.emoji}}]}),de=()=>({tag:"b"}),pe=()=>({tag:"s"}),fe=()=>({tag:"u"}),ge=()=>({tag:"strong"}),ye=()=>({tag:"code"}),me=()=>({tag:"i"}),be=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||"")),ee(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}]}},ke=o=>({tag:[{tag:"span",attrs:o.attrs}]}),ve=()=>({tag:"sub"}),we=()=>({tag:"sup"}),Se=o=>({tag:[{tag:"span",attrs:o.attrs}]}),Te=o=>{var e;return(e=o.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${o.attrs.color};`}}]}:{tag:""}},Ce=o=>{var e;return(e=o.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${o.attrs.color}`}}]}:{tag:""}},N={nodes:{horizontal_rule:te,blockquote:se,bullet_list:re,code_block:oe,hard_break:ne,heading:ie,image:ae,list_item:le,ordered_list:ce,paragraph:he,emoji:ue},marks:{bold:de,strike:pe,underline:fe,strong:ge,code:ye,italic:me,link:be,styled:ke,subscript:ve,superscript:we,anchor:Se,highlight:Te,textStyle:Ce}},Re=function(o){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,s=RegExp(t.source);return o&&s.test(o)?o.replace(t,r=>e[r]):o};let M=!1;class $e{constructor(e){d(this,"marks"),d(this,"nodes"),e||(e=N),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},s=!0){if(!M&&s&&(console.warn("Warning ⚠️: The RichTextResolver class is deprecated and will be removed in the next major release. Please use the `@storyblok/richtext` package instead. https://github.com/storyblok/richtext/"),M=!0),e&&e.content&&Array.isArray(e.content)){let r="";return e.content.forEach(n=>{r+=this.renderNode(n)}),t.optimizeImages?this.optimizeImages(r,t.optimizeImages):r}return console.warn(`The render method must receive an Object with a "content" field.
|
|
12
12
|
The "content" field must be an array of nodes as the type ISbRichtext.
|
|
13
13
|
ISbRichtext:
|
|
14
14
|
content?: ISbRichtext[]
|
|
@@ -31,30 +31,42 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
|
|
|
31
31
|
}
|
|
32
32
|
],
|
|
33
33
|
type: 'doc'
|
|
34
|
-
}`),""}optimizeImages(r,t){let i=0,s=0,l="",u="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(l+=`width="${t.width}" `,i=t.width),typeof t.height=="number"&&t.height>0&&(l+=`height="${t.height}" `,s=t.height),(t.loading==="lazy"||t.loading==="eager")&&(l+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(l+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(u+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(u+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(u+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(u+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(u+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(u+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(u+=`:rotate(${t.filters.rotate})`),u.length>0&&(u="/filters"+u))),l.length>0&&(r=r.replace(/<img/g,`<img ${l.trim()}`));const f=i>0||s>0||u.length>0?`${i}x${s}${u}`:"";return r=r.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${f}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(r=r.replace(/<img.*?src=["|'](.*?)["|']/g,p=>{var y,_;const A=p.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(A&&A.length>0){const S={srcset:(y=t.srcset)==null?void 0:y.map(w=>{if(typeof w=="number")return`//${A}/m/${w}x0${u} ${w}w`;if(typeof w=="object"&&w.length===2){let L=0,J=0;return typeof w[0]=="number"&&(L=w[0]),typeof w[1]=="number"&&(J=w[1]),`//${A}/m/${L}x${J}${u} ${L}w`}}).join(", "),sizes:(_=t.sizes)==null?void 0:_.map(w=>w).join(", ")};let j="";return S.srcset&&(j+=`srcset="${S.srcset}" `),S.sizes&&(j+=`sizes="${S.sizes}" `),p.replace(/<img/g,`<img ${j.trim()}`)}return p})),r}renderNode(r){const t=[];r.marks&&r.marks.forEach(s=>{const l=this.getMatchingMark(s);l&&l.tag!==""&&t.push(this.renderOpeningTag(l.tag))});const i=this.getMatchingNode(r);return i&&i.tag&&t.push(this.renderOpeningTag(i.tag)),r.content?r.content.forEach(s=>{t.push(this.renderNode(s))}):r.text?t.push(Pt(r.text)):i&&i.singleTag?t.push(this.renderTag(i.singleTag," /")):i&&i.html?t.push(i.html):r.type==="emoji"&&t.push(this.renderEmoji(r)),i&&i.tag&&t.push(this.renderClosingTag(i.tag)),r.marks&&r.marks.slice(0).reverse().forEach(s=>{const l=this.getMatchingMark(s);l&&l.tag!==""&&t.push(this.renderClosingTag(l.tag))}),t.join("")}renderTag(r,t){return r.constructor===String?`<${r}${t}>`:r.map(i=>{if(i.constructor===String)return`<${i}${t}>`;{let s=`<${i.tag}`;if(i.attrs){for(const l in i.attrs)if(Object.prototype.hasOwnProperty.call(i.attrs,l)){const u=i.attrs[l];u!==null&&(s+=` ${l}="${u}"`)}}return`${s}${t}>`}}).join("")}renderOpeningTag(r){return this.renderTag(r,"")}renderClosingTag(r){return r.constructor===String?`</${r}>`:r.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(r){const t=this.nodes[r.type];if(typeof t=="function")return t(r)}getMatchingMark(r){const t=this.marks[r.type];if(typeof t=="function")return t(r)}renderEmoji(r){if(r.attrs.emoji)return r.attrs.emoji;const t=[{tag:"img",attrs:{src:r.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(t," /")}}const ke=Mt,Nt=o=>{if(typeof o!="object"||typeof o._editable>"u")return{};try{const r=JSON.parse(o._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return r?{"data-blok-c":JSON.stringify(r),"data-blok-uid":r.id+"-"+r.uid}:{}}catch{return{}}};let zt,Lt="https://app.storyblok.com/f/storyblok-v2-latest.js";const Dt=(o,r)=>{o.addNode("blok",t=>{let i="";return t.attrs.body.forEach(s=>{i+=r(s.component,s)}),{html:i}})},Ut=o=>!o||!(o!=null&&o.content.some(r=>r.content||r.type==="blok"||r.type==="horizontal_rule")),Bt=(o,r,t)=>{let i=t||zt;if(!i){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return Ut(o)?"":(r&&(i=new ke(r.schema),r.resolver&&Dt(i,r.resolver)),i.render(o,{},!1))},Ft=()=>ot(Lt);function Ht(o){let r={resolveRelations:[]};function t(i){i&&Array.isArray(r.resolveRelations)&&r.resolveRelations.push(...Array.isArray(i)?i:[i])}for(const i of o)if(i.options){const{apiOptions:s,bridgeOptions:l}=i.options;if(t(s==null?void 0:s.resolve_relations),l){const{resolveRelations:u,...f}=l;t(u),Object.assign(r,f)}}return r.resolveRelations=[...new Set(r.resolveRelations)],r}var q=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function qt(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var G={exports:{}};G.exports,function(o,r){var t=200,i="__lodash_hash_undefined__",s=800,l=16,u=9007199254740991,f="[object Arguments]",p="[object Array]",y="[object AsyncFunction]",_="[object Boolean]",A="[object Date]",S="[object Error]",j="[object Function]",w="[object GeneratorFunction]",L="[object Map]",J="[object Number]",nr="[object Null]",Ie="[object Object]",or="[object Proxy]",ar="[object RegExp]",ir="[object Set]",sr="[object String]",lr="[object Undefined]",cr="[object WeakMap]",ur="[object ArrayBuffer]",fr="[object DataView]",dr="[object Float32Array]",pr="[object Float64Array]",gr="[object Int8Array]",hr="[object Int16Array]",br="[object Int32Array]",yr="[object Uint8Array]",mr="[object Uint8ClampedArray]",vr="[object Uint16Array]",_r="[object Uint32Array]",wr=/[\\^$.*+?()[\]{}|]/g,Tr=/^\[object .+?Constructor\]$/,kr=/^(?:0|[1-9]\d*)$/,b={};b[dr]=b[pr]=b[gr]=b[hr]=b[br]=b[yr]=b[mr]=b[vr]=b[_r]=!0,b[f]=b[p]=b[ur]=b[_]=b[fr]=b[A]=b[S]=b[j]=b[L]=b[J]=b[Ie]=b[ar]=b[ir]=b[sr]=b[cr]=!1;var Oe=typeof q=="object"&&q&&q.Object===Object&&q,Ar=typeof self=="object"&&self&&self.Object===Object&&self,D=Oe||Ar||Function("return this")(),je=r&&!r.nodeType&&r,U=je&&!0&&o&&!o.nodeType&&o,Ce=U&&U.exports===je,re=Ce&&Oe.process,$e=function(){try{var e=U&&U.require&&U.require("util").types;return e||re&&re.binding&&re.binding("util")}catch{}}(),xe=$e&&$e.isTypedArray;function Sr(e,n,a){switch(a.length){case 0:return e.call(n);case 1:return e.call(n,a[0]);case 2:return e.call(n,a[0],a[1]);case 3:return e.call(n,a[0],a[1],a[2])}return e.apply(n,a)}function Ir(e,n){for(var a=-1,c=Array(e);++a<e;)c[a]=n(a);return c}function Or(e){return function(n){return e(n)}}function jr(e,n){return e==null?void 0:e[n]}function Cr(e,n){return function(a){return e(n(a))}}var $r=Array.prototype,xr=Function.prototype,K=Object.prototype,ne=D["__core-js_shared__"],W=xr.toString,$=K.hasOwnProperty,Ee=function(){var e=/[^.]+$/.exec(ne&&ne.keys&&ne.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),Re=K.toString,Er=W.call(Object),Rr=RegExp("^"+W.call($).replace(wr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),X=Ce?D.Buffer:void 0,Pe=D.Symbol,Me=D.Uint8Array;X&&X.allocUnsafe;var Ne=Cr(Object.getPrototypeOf,Object),ze=Object.create,Pr=K.propertyIsEnumerable,Mr=$r.splice,x=Pe?Pe.toStringTag:void 0,Y=function(){try{var e=ie(Object,"defineProperty");return e({},"",{}),e}catch{}}(),Nr=X?X.isBuffer:void 0,Le=Math.max,zr=Date.now,De=ie(D,"Map"),B=ie(Object,"create"),Lr=function(){function e(){}return function(n){if(!R(n))return{};if(ze)return ze(n);e.prototype=n;var a=new e;return e.prototype=void 0,a}}();function E(e){var n=-1,a=e==null?0:e.length;for(this.clear();++n<a;){var c=e[n];this.set(c[0],c[1])}}function Dr(){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 Br(e){var n=this.__data__;if(B){var a=n[e];return a===i?void 0:a}return $.call(n,e)?n[e]:void 0}function Fr(e){var n=this.__data__;return B?n[e]!==void 0:$.call(n,e)}function Hr(e,n){var a=this.__data__;return this.size+=this.has(e)?0:1,a[e]=B&&n===void 0?i:n,this}E.prototype.clear=Dr,E.prototype.delete=Ur,E.prototype.get=Br,E.prototype.has=Fr,E.prototype.set=Hr;function C(e){var n=-1,a=e==null?0:e.length;for(this.clear();++n<a;){var c=e[n];this.set(c[0],c[1])}}function qr(){this.__data__=[],this.size=0}function Gr(e){var n=this.__data__,a=Z(n,e);if(a<0)return!1;var c=n.length-1;return a==c?n.pop():Mr.call(n,a,1),--this.size,!0}function Jr(e){var n=this.__data__,a=Z(n,e);return a<0?void 0:n[a][1]}function Kr(e){return Z(this.__data__,e)>-1}function Wr(e,n){var a=this.__data__,c=Z(a,e);return c<0?(++this.size,a.push([e,n])):a[c][1]=n,this}C.prototype.clear=qr,C.prototype.delete=Gr,C.prototype.get=Jr,C.prototype.has=Kr,C.prototype.set=Wr;function P(e){var n=-1,a=e==null?0:e.length;for(this.clear();++n<a;){var c=e[n];this.set(c[0],c[1])}}function Xr(){this.size=0,this.__data__={hash:new E,map:new(De||C),string:new E}}function Yr(e){var n=V(this,e).delete(e);return this.size-=n?1:0,n}function Zr(e){return V(this,e).get(e)}function Qr(e){return V(this,e).has(e)}function Vr(e,n){var a=V(this,e),c=a.size;return a.set(e,n),this.size+=a.size==c?0:1,this}P.prototype.clear=Xr,P.prototype.delete=Yr,P.prototype.get=Zr,P.prototype.has=Qr,P.prototype.set=Vr;function M(e){var n=this.__data__=new C(e);this.size=n.size}function en(){this.__data__=new C,this.size=0}function tn(e){var n=this.__data__,a=n.delete(e);return this.size=n.size,a}function rn(e){return this.__data__.get(e)}function nn(e){return this.__data__.has(e)}function on(e,n){var a=this.__data__;if(a instanceof C){var c=a.__data__;if(!De||c.length<t-1)return c.push([e,n]),this.size=++a.size,this;a=this.__data__=new P(c)}return a.set(e,n),this.size=a.size,this}M.prototype.clear=en,M.prototype.delete=tn,M.prototype.get=rn,M.prototype.has=nn,M.prototype.set=on;function an(e,n){var a=ce(e),c=!a&&le(e),d=!a&&!c&&qe(e),h=!a&&!c&&!d&&Je(e),m=a||c||d||h,g=m?Ir(e.length,String):[],v=g.length;for(var I in e)m&&(I=="length"||d&&(I=="offset"||I=="parent")||h&&(I=="buffer"||I=="byteLength"||I=="byteOffset")||Fe(I,v))||g.push(I);return g}function oe(e,n,a){(a!==void 0&&!ee(e[n],a)||a===void 0&&!(n in e))&&ae(e,n,a)}function sn(e,n,a){var c=e[n];(!($.call(e,n)&&ee(c,a))||a===void 0&&!(n in e))&&ae(e,n,a)}function Z(e,n){for(var a=e.length;a--;)if(ee(e[a][0],n))return a;return-1}function ae(e,n,a){n=="__proto__"&&Y?Y(e,n,{configurable:!0,enumerable:!0,value:a,writable:!0}):e[n]=a}var ln=wn();function Q(e){return e==null?e===void 0?lr:nr:x&&x in Object(e)?Tn(e):jn(e)}function Ue(e){return F(e)&&Q(e)==f}function cn(e){if(!R(e)||In(e))return!1;var n=fe(e)?Rr:Tr;return n.test(En(e))}function un(e){return F(e)&&Ge(e.length)&&!!b[Q(e)]}function fn(e){if(!R(e))return On(e);var n=He(e),a=[];for(var c in e)c=="constructor"&&(n||!$.call(e,c))||a.push(c);return a}function Be(e,n,a,c,d){e!==n&&ln(n,function(h,m){if(d||(d=new M),R(h))dn(e,n,m,a,Be,c,d);else{var g=c?c(se(e,m),h,m+"",e,n,d):void 0;g===void 0&&(g=h),oe(e,m,g)}},Ke)}function dn(e,n,a,c,d,h,m){var g=se(e,a),v=se(n,a),I=m.get(v);if(I){oe(e,a,I);return}var k=h?h(g,v,a+"",e,n,m):void 0,H=k===void 0;if(H){var de=ce(v),pe=!de&&qe(v),Xe=!de&&!pe&&Je(v);k=v,de||pe||Xe?ce(g)?k=g:Rn(g)?k=mn(g):pe?(H=!1,k=hn(v)):Xe?(H=!1,k=yn(v)):k=[]:Pn(v)||le(v)?(k=g,le(g)?k=Mn(g):(!R(g)||fe(g))&&(k=kn(v))):H=!1}H&&(m.set(v,k),d(k,v,c,h,m),m.delete(v)),oe(e,a,k)}function pn(e,n){return $n(Cn(e,n,We),e+"")}var gn=Y?function(e,n){return Y(e,"toString",{configurable:!0,enumerable:!1,value:zn(n),writable:!0})}:We;function hn(e,n){return e.slice()}function bn(e){var n=new e.constructor(e.byteLength);return new Me(n).set(new Me(e)),n}function yn(e,n){var a=bn(e.buffer);return new e.constructor(a,e.byteOffset,e.length)}function mn(e,n){var a=-1,c=e.length;for(n||(n=Array(c));++a<c;)n[a]=e[a];return n}function vn(e,n,a,c){var d=!a;a||(a={});for(var h=-1,m=n.length;++h<m;){var g=n[h],v=void 0;v===void 0&&(v=e[g]),d?ae(a,g,v):sn(a,g,v)}return a}function _n(e){return pn(function(n,a){var c=-1,d=a.length,h=d>1?a[d-1]:void 0,m=d>2?a[2]:void 0;for(h=e.length>3&&typeof h=="function"?(d--,h):void 0,m&&An(a[0],a[1],m)&&(h=d<3?void 0:h,d=1),n=Object(n);++c<d;){var g=a[c];g&&e(n,g,c,h)}return n})}function wn(e){return function(n,a,c){for(var d=-1,h=Object(n),m=c(n),g=m.length;g--;){var v=m[++d];if(a(h[v],v,h)===!1)break}return n}}function V(e,n){var a=e.__data__;return Sn(n)?a[typeof n=="string"?"string":"hash"]:a.map}function ie(e,n){var a=jr(e,n);return cn(a)?a:void 0}function Tn(e){var n=$.call(e,x),a=e[x];try{e[x]=void 0;var c=!0}catch{}var d=Re.call(e);return c&&(n?e[x]=a:delete e[x]),d}function kn(e){return typeof e.constructor=="function"&&!He(e)?Lr(Ne(e)):{}}function Fe(e,n){var a=typeof e;return n=n??u,!!n&&(a=="number"||a!="symbol"&&kr.test(e))&&e>-1&&e%1==0&&e<n}function An(e,n,a){if(!R(a))return!1;var c=typeof n;return(c=="number"?ue(a)&&Fe(n,a.length):c=="string"&&n in a)?ee(a[n],e):!1}function Sn(e){var n=typeof e;return n=="string"||n=="number"||n=="symbol"||n=="boolean"?e!=="__proto__":e===null}function In(e){return!!Ee&&Ee in e}function He(e){var n=e&&e.constructor,a=typeof n=="function"&&n.prototype||K;return e===a}function On(e){var n=[];if(e!=null)for(var a in Object(e))n.push(a);return n}function jn(e){return Re.call(e)}function Cn(e,n,a){return n=Le(n===void 0?e.length-1:n,0),function(){for(var c=arguments,d=-1,h=Le(c.length-n,0),m=Array(h);++d<h;)m[d]=c[n+d];d=-1;for(var g=Array(n+1);++d<n;)g[d]=c[d];return g[n]=a(m),Sr(e,this,g)}}function se(e,n){if(!(n==="constructor"&&typeof e[n]=="function")&&n!="__proto__")return e[n]}var $n=xn(gn);function xn(e){var n=0,a=0;return function(){var c=zr(),d=l-(c-a);if(a=c,d>0){if(++n>=s)return arguments[0]}else n=0;return e.apply(void 0,arguments)}}function En(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")&&!Pr.call(e,"callee")},ce=Array.isArray;function ue(e){return e!=null&&Ge(e.length)&&!fe(e)}function Rn(e){return F(e)&&ue(e)}var qe=Nr||Ln;function fe(e){if(!R(e))return!1;var n=Q(e);return n==j||n==w||n==y||n==or}function Ge(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 Pn(e){if(!F(e)||Q(e)!=Ie)return!1;var n=Ne(e);if(n===null)return!0;var a=$.call(n,"constructor")&&n.constructor;return typeof a=="function"&&a instanceof a&&W.call(a)==Er}var Je=xe?Or(xe):un;function Mn(e){return vn(e,Ke(e))}function Ke(e){return ue(e)?an(e):fn(e)}var Nn=_n(function(e,n,a,c){Be(e,n,a,c)});function zn(e){return function(){return e}}function We(e){return e}function Ln(){return!1}o.exports=Nn}(G,G.exports);var Gt=G.exports;const Jt=qt(Gt);function Kt(o){let r={};function t(i,s){if((s==null?void 0:s.type)==="AwaitExpression"&&s.argument.type==="CallExpression"&&s.argument.callee.type==="Identifier"&&s.argument.callee.name==="useStoryblok"){const l=s.argument.arguments;if(l&&l[1].type==="ObjectExpression"){const u=Ae(l[1].properties);r={...r,apiOptions:u}}if(l&&l[2].type==="ObjectExpression"){const u=Ae(l[2].properties);r={...r,bridgeOptions:u}}}}return Jt({},o,t),r}function Ae(o){const r={};return o.reduce((t,i)=>{if(i.type!=="Property")return t;const{key:s,value:l}=i,{type:u}=l;if(s.type!=="Identifier")return t;if(u==="Literal")t[s.name]=l.value;else if(u==="ArrayExpression"){const f=l.elements.reduce((p,y)=>y.type==="Literal"&&y.value?[...p,y.value]:p,[]);t[s.name]=f}return t},r)}let z=[];function Wt(o,r){const t="virtual:storyblok-bridge",i="\0"+t;if(!o||r!=="server")return{name:"vite-plugin-storyblok-bridge",resolveId(f){if(f===t)return i},load(f){if(f===i)return"export const bridgeOptions = null"}};let s=[],l=null,u;return{name:"vite-plugin-storyblok-bridge",async resolveId(f){if(f===t)return i},async transform(f,p){var j;if(p.includes("node_modules")&&!p.includes("/pages/")||!f.includes("useStoryblok")||!((j=this.getModuleInfo(p).meta)!=null&&j.astro))return;const[,..._]=p.split("src/pages/"),A=_.join("/").replace(".astro",""),S=Kt(this.parse(f));z.length&&(s=z.filter(w=>w.url!==A)),s.push({url:A,options:S}),l&&(u&&clearTimeout(u),u=setTimeout(()=>{Xt(z,s)||(z.length!==0&&(l.restart(),console.info("Bridge options updated. Restarting...")),z=[...s])},1e3))},async load(f){if(f===i)return`export const bridgeOptions = ${JSON.stringify(Ht(s))}`},configureServer(f){l=f}}}function Xt(o=[],r=[]){return r.every(({url:t,options:i})=>{const s=o.find(l=>(l==null?void 0:l.url)===t);return s&&JSON.stringify(i)===JSON.stringify(s.options)})}let Se;async function Yt(o){const{action:r,story:t}=o||{};if(r==="input"&&t){const i=async()=>{const l=await Qt(t),u=document.body;if(l.outerHTML===u.outerHTML)return;const f=document.querySelector('[data-blok-focused="true"]');Zt(u,l,f)};clearTimeout(Se),Se=setTimeout(i,500)}["published","change"].includes(o==null?void 0:o.action)&&location.reload()}function Zt(o,r,t){if(t){const i=t.getAttribute("data-blok-uid"),s=r.querySelector(`[data-blok-uid="${i}"]`);s&&(s.setAttribute("data-blok-focused","true"),t.replaceWith(s))}else o.replaceWith(r)}async function Qt(o){const t=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(t,"text/html").body}function Vt(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),globalThis.storyblokApiInstance}async function er(o,r={},t={},i){globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly");let s=null;if(i&&i.locals._storyblok_preview_data)s=i.locals._storyblok_preview_data;else{const{data:l}=await globalThis.storyblokApiInstance.get(o,r,t);s=l.story}return s}function tr(o,r){const t=globalThis.storyblokApiInstance.richTextResolver;if(!t){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return Bt(o,r,t)}function rr(o){const r={useCustomApi:!1,bridge:!0,componentsDir:"src",enableFallbackComponent:!1,livePreview:!1,...o};return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:t,updateConfig:i,addDevToolbarApp:s,addMiddleware:l,config:u})=>{if(i({vite:{plugins:[N(r.accessToken,r.useCustomApi,r.apiOptions),rt(r.componentsDir,r.components,r.enableFallbackComponent,r.customFallbackComponent),nt(r),Wt(r.livePreview,u.output)]}}),r.livePreview&&(u==null?void 0:u.output)!=="server")throw new Error("To utilize the Astro Storyblok Live feature, Astro must be configured to run in SSR mode. Please disable this feature or switch Astro to SSR mode.");if(t("page-ssr",`
|
|
34
|
+
}`),""}optimizeImages(e,t){let s=0,r=0,n="",i="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(n+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(n+=`height="${t.height}" `,r=t.height),(t.loading==="lazy"||t.loading==="eager")&&(n+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(n+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(i+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(i+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(i+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(i+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(i+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(i+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(i+=`:rotate(${t.filters.rotate})`),i.length>0&&(i="/filters"+i))),n.length>0&&(e=e.replace(/<img/g,`<img ${n.trim()}`));const l=s>0||r>0||i.length>0?`${s}x${r}${i}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${l}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var c,h;const u=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(u&&u.length>0){const p={srcset:(c=t.srcset)==null?void 0:c.map(f=>{if(typeof f=="number")return`//${u}/m/${f}x0${i} ${f}w`;if(typeof f=="object"&&f.length===2){let $=0,z=0;return typeof f[0]=="number"&&($=f[0]),typeof f[1]=="number"&&(z=f[1]),`//${u}/m/${$}x${z}${i} ${$}w`}}).join(", "),sizes:(h=t.sizes)==null?void 0:h.map(f=>f).join(", ")};let y="";return p.srcset&&(y+=`srcset="${p.srcset}" `),p.sizes&&(y+=`sizes="${p.sizes}" `),a.replace(/<img/g,`<img ${y.trim()}`)}return a})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const n=this.getMatchingMark(r);n&&n.tag!==""&&t.push(this.renderOpeningTag(n.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(Re(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 n=this.getMatchingMark(r);n&&n.tag!==""&&t.push(this.renderClosingTag(n.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 n in s.attrs)if(Object.prototype.hasOwnProperty.call(s.attrs,n)){const i=s.attrs[n];i!==null&&(r+=` ${n}="${i}"`)}}return`${r}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}renderEmoji(e){if(e.attrs.emoji)return e.attrs.emoji;const t=[{tag:"img",attrs:{src:e.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(t," /")}}const k=$e;class _e{constructor(e){d(this,"baseURL"),d(this,"timeout"),d(this,"headers"),d(this,"responseInterceptor"),d(this,"fetch"),d(this,"ejectInterceptor"),d(this,"url"),d(this,"parameters"),d(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),n=new AbortController,{signal:i}=n;let l;this.timeout&&(l=setTimeout(()=>n.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:i,...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}_statusHandler(e){const t=/20[0-6]/g;return new Promise((s,r)=>{if(t.test(`${e.status}`))return s(e);const n={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};r(n)})}}const Ae=_e,U="SB-Agent",T={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"};let w={};const m={};class Ie{constructor(e,t){d(this,"client"),d(this,"maxRetries"),d(this,"retriesDelay"),d(this,"throttle"),d(this,"accessToken"),d(this,"cache"),d(this,"helpers"),d(this,"resolveCounter"),d(this,"relations"),d(this,"links"),d(this,"richTextResolver"),d(this,"resolveNestedRelations"),d(this,"stringifiedStoriesCache");let s=e.endpoint||t;if(!s){const i=new v().getRegionURL,l=e.https===!1?"http":"https";e.oauthToken?s=`${l}://${i(e.region)}/v1`:s=`${l}://${i(e.region)}/v2`}const r=new Headers;r.set("Content-Type","application/json"),r.set("Accept","application/json"),e.headers&&(e.headers.constructor.name==="Headers"?e.headers.entries().toArray():Object.entries(e.headers)).forEach(([i,l])=>{r.set(i,l)}),r.has(U)||(r.set(U,T.defaultAgentName),r.set(T.defaultAgentVersion,T.packageVersion));let n=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=e.rateLimit),e.richTextSchema?this.richTextResolver=new k(e.richTextSchema):this.richTextResolver=new k,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=Q(this.throttledRequest,n,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 Ae({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=m[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,n){const i=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,i,void 0,n)}get(e,t,s){t||(t={});const r=`/${e}`,n=this.factoryParamOptions(r,t);return this.cacheResponse(r,n,void 0,s)}async getAll(e,t,s,r){const n=(t==null?void 0:t.per_page)||25,i=`/${e}`,l=i.split("/"),a=s||l[l.length-1],c=1,h=await this.makeRequest(i,t,n,c,r),u=h.total?Math.ceil(h.total/n):1,p=await this.helpers.asyncMap(this.helpers.range(c,u),y=>this.makeRequest(i,t,n,y+1,r));return this.helpers.flatMap([h,...p],y=>Object.values(y.data[a]))}post(e,t,s){const r=`/${e}`;return Promise.resolve(this.throttle("post",r,t,s))}put(e,t,s){const r=`/${e}`;return Promise.resolve(this.throttle("put",r,t,s))}delete(e,t,s){const r=`/${e}`;return Promise.resolve(this.throttle("delete",r,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 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(n=>this.getStoryReference(r,n)).filter(Boolean)))}iterateTree(e,t,s){const r=n=>{if(n!=null){if(n.constructor===Array)for(let i=0;i<n.length;i++)r(n[i]);else if(n.constructor===Object){if(n._stopResolving)return;for(const i in n)(n.component&&n._uid||n.type==="link")&&(this._insertRelations(n,i,t,s),this._insertLinks(n,i,s)),r(n[i])}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const n=e.link_uuids.length,i=[],l=50;for(let a=0;a<n;a+=l){const c=Math.min(n,a+l);i.push(e.link_uuids.slice(a,c))}for(let a=0;a<i.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:i[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.links;r.forEach(n=>{this.links[s][n.uuid]={...n,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const n=e.rel_uuids.length,i=[],l=50;for(let a=0;a<n;a+=l){const c=Math.min(n,a+l);i.push(e.rel_uuids.slice(a,c))}for(let a=0;a<i.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:i[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(c=>{r.push(c)})}else r=e.rels;r&&r.length>0&&r.forEach(n=>{this.relations[s][n.uuid]={...n,_stopResolving:!0}})}async resolveStories(e,t,s){var r,n;let i=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(i=t.resolve_relations.split(",")),await this.resolveRelations(e,t,s)),t.resolve_links&&["1","story","url","link"].indexOf(t.resolve_links)>-1&&((r=e.links)!=null&&r.length||(n=e.link_uuids)!=null&&n.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const l in this.relations[s])this.iterateTree(this.relations[s][l],i,s);e.story?this.iterateTree(e.story,i,s):e.stories.forEach(l=>{this.iterateTree(l,i,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s,r){const n=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 l=await i.get(n);if(l)return Promise.resolve(l)}return new Promise(async(l,a)=>{var c;try{const h=await this.throttle("get",e,t,r);if(h.status!==200)return a(h);let u={data:h.data,headers:h.headers};if((c=h.headers)!=null&&c["per-page"]&&(u=Object.assign({},u,{perPage:h.headers["per-page"]?parseInt(h.headers["per-page"]):0,total:h.headers["per-page"]?parseInt(h.headers.total):0})),u.data.story||u.data.stories){const p=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(u.data,t,`${p}`)}return t.version==="published"&&e!="/cdn/spaces/me"&&await i.set(n,u),u.data.cv&&t.token&&(t.version==="draft"&&m[t.token]!=u.data.cv&&await this.flushCache(),m[t.token]=t.cv?t.cv:u.data.cv),l(u)}catch(h){if(h.response&&h.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 this.helpers.delay(this.retriesDelay),this.cacheResponse(e,t,s).then(l).catch(a);a(h)}})}throttledRequest(e,t,s,r){return this.client.setFetchOptions(r),this.client[e](t,s)}cacheVersions(){return m}cacheVersion(){return m[this.accessToken]}setCacheVersion(e){this.accessToken&&(m[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(m[this.accessToken]=0)}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.clearCacheVersion(),this}}const Oe=(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 Ie(e)}},Le=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 C,R="https://app.storyblok.com/f/storyblok-v2-latest.js";const je=(o={})=>{var e,t;const{bridge:s,accessToken:r,use:n=[],apiOptions:i={},richText:l={},bridgeUrl:a}=o;i.accessToken=i.accessToken||r;const c={bridge:s,apiOptions:i};let h={};n.forEach(p=>{h={...h,...p(c)}}),a&&(R=a);const u=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return s!==!1&&u&&x(R),C=new k(l.schema),l.resolver&&B(C,l.resolver),h},B=(o,e)=>{o.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},Ee=o=>!o||!(o!=null&&o.content.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule")),xe=(o,e,t)=>{let s=t||C;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return Ee(o)?"":(e&&(s=new k(e.schema),e.resolver&&B(s,e.resolver)),s.render(o,{},!1))},Pe=()=>x(R);function Ne(o){return typeof o=="object"?`const storyblokInstance = new StoryblokBridge(${JSON.stringify(o)});`:"const storyblokInstance = new StoryblokBridge();"}const Me=`<svg width="45px" height="53px" viewBox="0 0 45 53" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
35
|
+
<g id="storyblok-logo-kit" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
36
|
+
<g id="storyblok-partner-logo" transform="translate(-59.000000, -169.000000)" fill-rule="nonzero">
|
|
37
|
+
<g id="storyblok-symbol" transform="translate(59.000000, 169.000000)">
|
|
38
|
+
<path d="M2.32662261,0 C1.03405449,0 0,1.0331384 0,2.27290448 L0,42.8752437 C0,44.1150097 1.03405449,44.8898635 2.27491989,44.8898635 L8.27243596,44.8898635 L8.27243596,53 L15.7176283,44.9415205 L42.9132615,44.9415205 C44.1541269,44.9415205 44.9296678,44.1666667 44.9296678,42.8752437 L44.9296678,2.3245614 C44.9296678,1.08479532 44.2058296,0 42.9132615,0 L2.32662261,0 Z" id="Shape-path-Copy" fill="#0AB3AF"></path>
|
|
39
|
+
<path d="M29.1016723,8.11483254 C30.1351059,8.11483254 31.0135245,8.32132604 31.8402713,8.78593643 C32.6153465,9.19892344 33.33875,9.76678059 33.9071385,10.4378845 C35.0647615,11.8482391 35.6869248,13.6215753 35.6639755,15.445352 C35.6639755,16.7875598 35.3022738,18.0781442 34.630542,19.3171053 C33.9341248,20.5632996 32.8438147,21.5436614 31.5302412,22.1047676 C33.183735,22.569378 34.4755269,23.395352 35.4572888,24.5826897 C36.387379,25.8216507 36.8524241,27.4219754 36.8524241,29.4352871 C36.8524241,30.7258715 36.6168825,31.8756998 36.1290206,32.7391832 C35.6123039,33.668404 34.8372287,34.4427546 33.9071385,35.0106118 C32.9253766,35.6300923 31.8402713,36.1979494 30.600151,36.4560663 C29.3600307,36.7658066 28.0165671,37.0239234 26.6214318,37.0239234 L8.32965751,37.0239234 L8.32965751,8.11483254 L29.1016723,8.11483254 Z M26.1340815,24.271851 L15.77813,24.271851 L15.77813,29.1552028 L25.8851404,29.1552028 C26.4825991,29.1552028 27.0302696,28.9110352 27.4783637,28.5203671 C27.8766695,28.1296989 28.1256107,27.5436967 28.1256107,26.811194 C28.140051,26.1827412 27.948041,25.5663945 27.5779401,25.0531873 C27.1796343,24.5648522 26.7315403,24.271851 26.1340815,24.271851 Z M25.2876816,14.5051475 L15.77813,14.5051475 L15.77813,18.9001641 L25.0885287,18.9001641 C25.586411,18.9001641 26.0842933,18.6559965 26.4825991,18.3629954 C26.9306932,18.0699943 27.1298461,17.4351586 27.1298461,16.6049888 C27.1298461,15.872486 26.9306932,15.3353173 26.5821756,14.9934827 C26.233658,14.7004816 25.7855639,14.5051475 25.2876816,14.5051475 Z" id="Combined-Shape-Copy-3" fill="#FFFFFF"></path>
|
|
40
|
+
</g>
|
|
41
|
+
</g>
|
|
42
|
+
</g>
|
|
43
|
+
</svg>`;let H;async function Ue(o){const{action:e,story:t}=o||{};if(e==="input"&&t){const s=async()=>{const n=await He(t),i=document.body;if(n.outerHTML===i.outerHTML)return;const l=document.querySelector('[data-blok-focused="true"]');Be(i,n,l),document.dispatchEvent(new Event("storyblok-live-preview-updated"))};clearTimeout(H),H=setTimeout(s,500)}["published","change"].includes(o==null?void 0:o.action)&&location.reload()}function Be(o,e,t){if(t){const s=t.getAttribute("data-blok-uid"),r=e.querySelector(`[data-blok-uid="${s}"]`);r&&(r.setAttribute("data-blok-focused","true"),t.replaceWith(r))}else o.replaceWith(e)}async function He(o){const t=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(t,"text/html").body}async function ze(o){const{story:e}=o||{};await fetch(location.origin+"/_refresh",{method:"POST",body:JSON.stringify(e),headers:{"Content-Type":"application/json"}})}function De(o){const{storyblokApi:e}=je({accessToken:o.STORYBLOK_TOKEN,use:[Oe]});return{name:"story-loader",load:async({store:t,meta:s,logger:r,refreshContextData:n})=>{if(!e)throw new Error("storyblokApi is not loaded");if(n!=null&&n.story){r.info("Syncing... story updated in Storyblok");const h=n.story;t.set({data:h,id:h.uuid});return}r.info("Loading stories");const i=s.get("lastPublishedAt"),l=i&&o.version==="published"?{published_at_gt:i}:{},a=await(e==null?void 0:e.getAll("cdn/stories",{version:o.version,...l}));console.log("total = ",a.length),r.info("Clearing store"),o.version==="draft"&&t.clear();let c=i?new Date(i):null;for(const h of a){const u=h.published_at?new Date(h.published_at):null;u&&(!c||u>c)&&(c=u),t.set({data:h,id:h.uuid}),c&&s.set("lastPublishedAt",c.toISOString())}}}}function Fe(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),globalThis.storyblokApiInstance}async function Je(o){let e=null;return o&&o.locals._storyblok_preview_data&&(e=o.locals._storyblok_preview_data),e}function qe(o,e){const t=globalThis.storyblokApiInstance.richTextResolver;if(!t){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return xe(o,e,t)}function Ve({useCustomApi:o=!1,bridge:e=!0,componentsDir:t="src",enableFallbackComponent:s=!1,livePreview:r=!1,contentLayer:n=!1,...i}){const l={useCustomApi:o,bridge:e,componentsDir:t,enableFallbackComponent:s,livePreview:r,contentLayer:n,...i},a=Ne(e);return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:c,updateConfig:h,addDevToolbarApp:u,addMiddleware:p,config:y})=>{if(h({vite:{plugins:[b(l.accessToken,l.useCustomApi,l.apiOptions),W(l.componentsDir,l.components,l.enableFallbackComponent,l.customFallbackComponent),Z(l)]}}),l.livePreview&&(y==null?void 0:y.output)!=="server")throw new Error("To utilize the Astro Storyblok Live feature, Astro must be configured to run in SSR mode. Please disable this feature or switch Astro to SSR mode.");c("page-ssr",`
|
|
35
44
|
import { storyblokApiInstance } from "virtual:storyblok-init";
|
|
36
45
|
globalThis.storyblokApiInstance = storyblokApiInstance;
|
|
37
|
-
`),
|
|
46
|
+
`),e&&!r&&c("page",`
|
|
38
47
|
import { loadStoryblokBridge } from "@storyblok/astro";
|
|
39
48
|
loadStoryblokBridge().then(() => {
|
|
40
49
|
const { StoryblokBridge, location } = window;
|
|
41
|
-
${
|
|
42
|
-
|
|
50
|
+
${a}
|
|
43
51
|
storyblokInstance.on(["published", "change"], (event) => {
|
|
44
52
|
if (!event.slugChanged) {
|
|
45
53
|
location.reload(true);
|
|
46
54
|
}
|
|
47
55
|
});
|
|
48
56
|
});
|
|
49
|
-
`)
|
|
57
|
+
`),r&&(c("page",`
|
|
50
58
|
import { loadStoryblokBridge, handleStoryblokMessage } from "@storyblok/astro";
|
|
51
|
-
import { bridgeOptions } from "virtual:storyblok-bridge";
|
|
52
59
|
console.info("The Storyblok Astro live preview feature is currently in an experimental phase, and its API is subject to change in the future.")
|
|
53
60
|
loadStoryblokBridge().then(() => {
|
|
54
61
|
const { StoryblokBridge, location } = window;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
storyblokInstance.on(["published", "change", "input"], handleStoryblokMessage);
|
|
58
|
-
};
|
|
62
|
+
${a}
|
|
63
|
+
storyblokInstance.on(["published", "change", "input"], handleStoryblokMessage);
|
|
59
64
|
});
|
|
60
|
-
`),
|
|
65
|
+
`),p({entrypoint:"@storyblok/astro/middleware.ts",order:"pre"})),n&&c("page",`
|
|
66
|
+
import { loadStoryblokBridge, syncContentUpdate } from "@storyblok/astro";
|
|
67
|
+
loadStoryblokBridge().then(() => {
|
|
68
|
+
const { StoryblokBridge } = window;
|
|
69
|
+
const storyblokInstance = new StoryblokBridge()
|
|
70
|
+
storyblokInstance.on(["published", "change", "input"], syncContentUpdate);
|
|
71
|
+
});
|
|
72
|
+
`),u({id:"storyblok",name:"Storyblok",icon:Me,entrypoint:"@storyblok/astro/toolbarApp.ts"})},...n?{"astro:server:setup":async({server:c,refreshContent:h})=>{c.middlewares.use("/_refresh",async(u,p)=>{if(u.method!=="POST"){p.writeHead(405,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:"Method Not Allowed"}));return}let y=[];u.on("data",f=>y.push(f)),u.on("end",async()=>{try{const f=JSON.parse(Buffer.concat(y).toString());await(h==null?void 0:h({context:{story:f},loaders:["story-loader"]})),p.writeHead(200,{"Content-Type":"application/json"}),p.end(JSON.stringify({message:"Content refreshed successfully"}))}catch(f){p.writeHead(500,{"Content-Type":"application/json"}),p.end(JSON.stringify({error:`Failed to refresh content: ${f.message}`}))}})})}}:{}}}}g.RichTextResolver=k,g.RichTextSchema=N,g.default=Ve,g.getLiveStory=Je,g.handleStoryblokMessage=Ue,g.loadStoryblokBridge=Pe,g.renderRichText=qe,g.storyblokEditable=Le,g.storyblokLoader=De,g.syncContentUpdate=ze,g.useStoryblokApi=Fe,Object.defineProperties(g,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|