@storyblok/astro 9.0.11 → 10.0.0
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/dist/components/StoryblokComponent.astro +1 -1
- package/dist/components/StoryblokRichText.astro +14 -0
- package/dist/components/richtext/ElementTag.astro +32 -0
- package/dist/components/richtext/RenderChildren.astro +26 -0
- package/dist/components/richtext/RenderImage.astro +24 -0
- package/dist/components/richtext/RenderLinkGroup.astro +31 -0
- package/dist/components/richtext/RenderLinkInner.astro +18 -0
- package/dist/components/richtext/RenderNode.astro +46 -0
- package/dist/components/richtext/RenderStaticChildren.astro +23 -0
- package/dist/components/richtext/RenderStaticStructure.astro +35 -0
- package/dist/components/richtext/RenderTable.astro +20 -0
- package/dist/components/richtext/RenderTextNodeWithMarks.astro +34 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +1902 -0
- package/dist/lib/client.d.ts +0 -1
- package/dist/lib/client.ts +0 -1
- package/dist/public.d.ts +16 -34
- package/dist/types.d.ts +2 -2
- package/dist/utils/richtext-helpers.d.ts +12 -0
- package/package.json +9 -12
- package/dist/components/FallbackComponent.d.ts +0 -6
- package/dist/lib/richTextToHTML.d.ts +0 -27
- package/dist/lib/richTextToHTML.ts +0 -94
- package/dist/storyblok-astro.es.js +0 -39004
- package/dist/storyblok-astro.umd.js +0 -143
package/dist/index.js
ADDED
|
@@ -0,0 +1,1902 @@
|
|
|
1
|
+
const et = `
|
|
2
|
+
<svg class="logo-storyblok logo-storyblok--dark" role="img" aria-label="Storyblok Official Logo" viewBox="0 0 19 22" xmlns="http://www.w3.org/2000/svg">
|
|
3
|
+
<path d="M29.0287 14.9132C28.2686 14.9132 27.5302 14.8018 26.7918 14.5568C26.0988 14.3265 25.462 13.9468 24.924 13.4432L25.9013 11.7504C26.4443 12.1291 26.9655 12.4186 27.4867 12.6414C27.9862 12.8641 28.4858 12.9532 28.9636 12.9532C29.3111 12.9532 29.5934 12.8864 29.7888 12.7527C29.9843 12.6414 30.0712 12.4409 30.0712 12.1959C30.0712 11.9732 29.9626 11.7504 29.702 11.6168C29.2938 11.4162 28.8636 11.2666 28.4206 11.1714L26.9003 10.6591C26.4877 10.4809 26.1619 10.3027 25.9013 10.1023C25.6407 9.92408 25.4452 9.67908 25.3366 9.43408C25.2184 9.1529 25.1592 8.84935 25.1629 8.54317C25.1502 7.66646 25.5255 6.83107 26.1836 6.27136C26.4877 6.00408 26.8786 5.80363 27.313 5.64772C27.7473 5.49181 28.2251 5.42499 28.7247 5.42499C29.3979 5.42499 30.0277 5.51408 30.6141 5.69226C31.2005 5.89272 31.7652 6.22681 32.3081 6.71681L31.244 8.38726C30.8236 8.07881 30.3722 7.81747 29.8974 7.60772C29.4848 7.42954 29.1156 7.36272 28.7247 7.36272C28.4423 7.36272 28.1817 7.40726 27.9862 7.5409C27.7691 7.65226 27.6822 7.85272 27.6822 8.11999C27.6822 8.38726 27.7908 8.56545 28.008 8.69908C28.2251 8.83272 28.6595 8.96635 29.2459 9.12226C29.7903 9.26289 30.3268 9.4339 30.853 9.63454C31.2874 9.81272 31.6349 10.0132 31.9172 10.2136C32.4511 10.6169 32.7463 11.2726 32.6991 11.9509C32.6991 12.8641 32.3733 13.5768 31.7 14.1114C31.0485 14.6459 30.1798 14.9132 29.0287 14.9132ZM39.7792 14.2673C39.41 14.4232 38.9756 14.5791 38.4978 14.7127C38.02 14.8464 37.5422 14.9354 37.0427 14.9354C36.6952 14.9354 36.3911 14.8909 36.0871 14.8018C35.7915 14.7134 35.5176 14.5616 35.2835 14.3564C35.0663 14.1782 34.8926 13.9109 34.7623 13.6214C34.632 13.3095 34.5451 12.9309 34.5451 12.4854V7.69681H33.4158V5.60317H34.5668V2.68545H37.2599V5.5809H39.0842V7.69681H37.2599V11.5277C37.2599 11.8173 37.325 12.04 37.4771 12.1959C37.6291 12.3073 37.8245 12.3741 38.0417 12.3741C38.2589 12.3741 38.4761 12.3518 38.6715 12.2627C38.8887 12.1959 39.0842 12.1291 39.2362 12.04L39.7575 14.2673H39.7792ZM44.8612 14.9132C44.1701 14.9255 43.4835 14.7968 42.8414 14.5345C41.7112 14.076 40.8261 13.1439 40.409 11.9732C39.9823 10.8102 39.9823 9.52792 40.409 8.36499C40.8261 7.19423 41.7112 6.26214 42.8414 5.80363C43.4278 5.55863 44.1011 5.42499 44.8612 5.42499C46.1833 5.36117 47.4671 5.88947 48.3795 6.87272C48.7922 7.2959 49.0962 7.80817 49.3134 8.36499C49.758 9.5322 49.758 10.8282 49.3134 11.9954C48.8937 13.1518 48.0186 14.0734 46.9027 14.5345C46.2538 14.7998 45.5596 14.9285 44.8612 14.9132ZM42.9066 10.1914C42.9066 10.9041 43.0803 11.4832 43.4495 11.9064C43.8405 12.3518 44.3183 12.5745 44.8829 12.5745C45.4284 12.5853 45.9487 12.3391 46.2946 11.9064C46.4683 11.6836 46.5987 11.4609 46.7072 11.1491C46.8158 10.8595 46.8593 10.5254 46.8593 10.1914C46.8593 9.45636 46.6638 8.87726 46.2946 8.45408C45.9254 8.00863 45.4476 7.78589 44.8829 7.78589C44.3394 7.78464 43.8229 8.02909 43.4712 8.45408C43.2975 8.67681 43.1455 8.89954 43.0369 9.21136C42.939 9.52794 42.8949 9.85944 42.9066 10.1914ZM56.6541 7.98636C56.0026 7.98636 55.3945 8.09772 54.8515 8.32045C54.3736 8.48572 53.9666 8.81646 53.7005 9.2559V14.7573H50.9857V5.60317H53.4833V7.42954C53.7873 6.8059 54.1783 6.3159 54.6778 5.98181C55.1556 5.62545 55.6551 5.44726 56.1981 5.42499H56.4804L56.6541 5.44726V7.96408V7.98636ZM57.8486 16.1159C58.2263 16.2505 58.6217 16.3256 59.0214 16.3386C59.3472 16.3386 59.6078 16.2273 59.8033 16.0045C59.977 15.7818 60.129 15.3364 60.2811 14.7573L56.893 5.60317H59.6947L61.7579 12.3518L63.5605 5.60317H66.1015L62.6918 16.2273C62.1569 18.0318 60.3638 19.1157 58.5653 18.7218C58.3481 18.6773 58.0875 18.6104 57.8486 18.4991V16.1159ZM72.5301 14.9133C71.8568 14.9133 71.2487 14.7795 70.7492 14.4677C70.2417 14.1818 69.8208 13.758 69.533 13.2427V14.7573H67.1657V2.01727H69.9022V7.09545C70.4962 6.02938 71.6157 5.38681 72.8124 5.42499C73.3771 5.42499 73.8983 5.53636 74.3761 5.80363C74.8539 6.02636 75.2448 6.38272 75.614 6.8059C76.6831 8.32739 76.974 10.2831 76.3959 12.0623C76.1787 12.6414 75.8746 13.1536 75.5054 13.5768C74.7429 14.4342 73.6616 14.9198 72.5301 14.9133ZM71.7699 12.5745C72.6515 12.5764 73.4369 12.0037 73.7245 11.1491C74.043 10.2518 73.887 9.24956 73.3119 8.49863C72.9724 8.0401 72.4398 7.7753 71.8785 7.7859C71.4659 7.7859 71.0749 7.94181 70.7057 8.23136C70.3582 8.54317 70.0759 8.92181 69.8805 9.38954V11.305C70.2309 12.0628 70.9738 12.5476 71.7916 12.5523L71.7699 12.5745ZM78.0247 2.01727H80.7395V11.4832C80.7395 12.1959 81.0218 12.53 81.6082 12.53C81.9183 12.5309 82.2239 12.4545 82.4987 12.3073L82.8679 14.3786C82.1072 14.7203 81.2875 14.902 80.4572 14.9132C79.6753 14.9132 79.0672 14.6904 78.6546 14.2895C78.2202 13.8441 78.003 13.265 78.003 12.4632V2.01727H78.0247ZM87.9933 14.9132C87.3023 14.9255 86.6157 14.7968 85.9736 14.5345C84.8367 14.0789 83.9437 13.1469 83.5194 11.9732C82.8914 10.2226 83.2408 8.26037 84.4316 6.85045C84.8659 6.40499 85.3437 6.0709 85.9518 5.80363C86.5382 5.55863 87.2115 5.42499 87.9716 5.42499C89.2937 5.36117 90.5776 5.88947 91.49 6.87272C91.9243 7.2959 92.2066 7.80817 92.4238 8.36499C93.0767 10.1133 92.7249 12.0889 91.5117 13.4877C91.099 13.9332 90.5995 14.2895 89.9914 14.5345C89.3493 14.7968 88.6627 14.9255 87.9716 14.9132H87.9933ZM86.017 10.1914C86.017 10.9041 86.1907 11.4832 86.5599 11.9064C86.9509 12.3518 87.4287 12.5745 87.9933 12.5745C88.5382 12.5821 89.0571 12.3364 89.405 11.9064C89.5788 11.6836 89.7091 11.4609 89.8177 11.1491C89.9262 10.8595 89.9697 10.5254 89.9697 10.1914C89.9697 9.45636 89.7742 8.87726 89.405 8.45408C89.0358 8.00863 88.558 7.78589 87.9933 7.78589C87.4498 7.78464 86.9334 8.02909 86.5817 8.45408C86.4079 8.67681 86.2559 8.89954 86.1473 9.21136C86.0387 9.52317 86.017 9.83499 86.017 10.1914ZM100.112 14.7573L97.7882 11.06L96.8326 12.0845V14.7573H94.1178V2.01727H96.8326V9.38954L99.8514 5.60317H102.74L99.5256 9.54545L103.001 14.7573H100.112Z" fill="currentColor"></path>
|
|
4
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M0 1.71089C0 0.76599 0.76599 0 1.71089 0H17.1089C18.0538 0 18.8198 0.76599 18.8198 1.71089V17.1089C18.8198 18.0538 18.0538 18.8198 17.1089 18.8198H7.13145L4.57616 20.9297C4.24445 21.2036 3.74366 20.9676 3.74366 20.5375V18.8198H1.71089C0.76599 18.8198 0 18.0538 0 17.1089V1.71089ZM3.74233 3.10946H11.9675C13.7438 3.10946 15.1839 4.5495 15.1839 6.32587C15.1839 7.74936 14.2592 8.95687 12.9777 9.38045C14.4761 9.65447 15.6117 10.9667 15.6117 12.5443C15.6117 14.3207 14.1717 15.7607 12.3953 15.7607H3.74247V9.54229H3.74233V3.10946ZM10.583 6.00384H6.73607V7.93369H10.583C11.1159 7.93369 11.5479 7.50168 11.5479 6.96877C11.5479 6.43585 11.1159 6.00384 10.583 6.00384ZM6.73607 10.2925H10.9035C11.4956 10.2925 11.9757 10.7725 11.9757 11.3647C11.9757 11.9568 11.4956 12.4368 10.9035 12.4368H6.73607V10.2925Z" fill="currentColor"></path>
|
|
5
|
+
</svg>
|
|
6
|
+
`;
|
|
7
|
+
function tt(e, t, r) {
|
|
8
|
+
const n = "virtual:storyblok-init", s = `\0${n}`;
|
|
9
|
+
return {
|
|
10
|
+
name: "vite-plugin-storyblok-init",
|
|
11
|
+
async resolveId(i) {
|
|
12
|
+
if (i === n)
|
|
13
|
+
return s;
|
|
14
|
+
},
|
|
15
|
+
async load(i) {
|
|
16
|
+
if (i === s)
|
|
17
|
+
return `
|
|
18
|
+
import { storyblokInit, apiPlugin } from "@storyblok/astro";
|
|
19
|
+
const { storyblokApi } = storyblokInit({
|
|
20
|
+
accessToken: "${e}",
|
|
21
|
+
use: ${t ? "[]" : "[apiPlugin]"},
|
|
22
|
+
apiOptions: ${JSON.stringify(r)},
|
|
23
|
+
});
|
|
24
|
+
export const storyblokApiInstance = storyblokApi;
|
|
25
|
+
`;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function rt(e) {
|
|
30
|
+
const t = "virtual:storyblok-options", r = `\0${t}`;
|
|
31
|
+
return {
|
|
32
|
+
name: "vite-plugin-storyblok-options",
|
|
33
|
+
async resolveId(n) {
|
|
34
|
+
if (n === t)
|
|
35
|
+
return r;
|
|
36
|
+
},
|
|
37
|
+
async load(n) {
|
|
38
|
+
if (n === r)
|
|
39
|
+
return `export default ${JSON.stringify(e)}`;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function Pr() {
|
|
44
|
+
if (!globalThis?.storyblokApiInstance)
|
|
45
|
+
throw new Error("storyblokApiInstance has not been initialized correctly");
|
|
46
|
+
return globalThis.storyblokApiInstance;
|
|
47
|
+
}
|
|
48
|
+
async function Or(e) {
|
|
49
|
+
let t = null;
|
|
50
|
+
return e && e.locals._storyblok_preview_data && (t = e.locals._storyblok_preview_data.story || null), t;
|
|
51
|
+
}
|
|
52
|
+
async function Ir({
|
|
53
|
+
locals: e
|
|
54
|
+
}) {
|
|
55
|
+
const { story: t, serverData: r } = e._storyblok_preview_data || {};
|
|
56
|
+
return { story: t, serverData: r };
|
|
57
|
+
}
|
|
58
|
+
function nt(e) {
|
|
59
|
+
return typeof e == "object" ? `const storyblokInstance = new StoryblokBridge(${JSON.stringify(e)});` : "const storyblokInstance = new StoryblokBridge();";
|
|
60
|
+
}
|
|
61
|
+
function st(e) {
|
|
62
|
+
return e.endsWith(".astro") ? e : `${e}.astro`;
|
|
63
|
+
}
|
|
64
|
+
function le(e) {
|
|
65
|
+
return `/${e.trim().replace(/^\/+/, "").replace(/\/+$/, "").replace(/\/{2,}/g, "/")}`;
|
|
66
|
+
}
|
|
67
|
+
const it = /[\p{Lu}]/u, ot = /[\p{Ll}]/u, ke = /^[\p{Lu}](?![\p{Lu}])/gu, He = /([\p{Alpha}\p{N}_]|$)/u, pe = /[_.\- ]+/, at = new RegExp("^" + pe.source), Ae = new RegExp(pe.source + He.source, "gu"), _e = new RegExp("\\d+" + He.source, "gu"), lt = (e, t, r, n) => {
|
|
68
|
+
let s = !1, i = !1, o = !1, a = !1;
|
|
69
|
+
for (let l = 0; l < e.length; l++) {
|
|
70
|
+
const c = e[l];
|
|
71
|
+
a = l > 2 ? e[l - 3] === "-" : !0, s && it.test(c) ? (e = e.slice(0, l) + "-" + e.slice(l), s = !1, o = i, i = !0, l++) : i && o && ot.test(c) && (!a || n) ? (e = e.slice(0, l - 1) + "-" + e.slice(l - 1), o = i, i = !1, s = !0) : (s = t(c) === c && r(c) !== c, o = i, i = r(c) === c && t(c) !== c);
|
|
72
|
+
}
|
|
73
|
+
return e;
|
|
74
|
+
}, ct = (e, t) => (ke.lastIndex = 0, e.replaceAll(ke, (r) => t(r))), ut = (e, t) => (Ae.lastIndex = 0, _e.lastIndex = 0, e.replaceAll(_e, (r, n, s) => ["_", "-"].includes(e.charAt(s + r.length)) ? r : t(r)).replaceAll(Ae, (r, n) => t(n)));
|
|
75
|
+
function ft(e, t) {
|
|
76
|
+
if (!(typeof e == "string" || Array.isArray(e)))
|
|
77
|
+
throw new TypeError("Expected the input to be `string | string[]`");
|
|
78
|
+
if (t = {
|
|
79
|
+
pascalCase: !1,
|
|
80
|
+
preserveConsecutiveUppercase: !1,
|
|
81
|
+
...t
|
|
82
|
+
}, Array.isArray(e) ? e = e.map((i) => i.trim()).filter((i) => i.length).join("-") : e = e.trim(), e.length === 0)
|
|
83
|
+
return "";
|
|
84
|
+
const r = t.locale === !1 ? (i) => i.toLowerCase() : (i) => i.toLocaleLowerCase(t.locale), n = t.locale === !1 ? (i) => i.toUpperCase() : (i) => i.toLocaleUpperCase(t.locale);
|
|
85
|
+
return e.length === 1 ? pe.test(e) ? "" : t.pascalCase ? n(e) : r(e) : (e !== r(e) && (e = lt(e, r, n, t.preserveConsecutiveUppercase)), e = e.replace(at, ""), e = t.preserveConsecutiveUppercase ? ct(e, r) : r(e), t.pascalCase && (e = n(e.charAt(0)) + e.slice(1)), ut(e, n));
|
|
86
|
+
}
|
|
87
|
+
function dt(e) {
|
|
88
|
+
return ft(e);
|
|
89
|
+
}
|
|
90
|
+
const Ue = "virtual:import-storyblok-components", we = `\0${Ue}`;
|
|
91
|
+
function ht(e, t, r, n) {
|
|
92
|
+
return {
|
|
93
|
+
name: "vite-plugin-import-storyblok-components",
|
|
94
|
+
/**
|
|
95
|
+
* Resolves virtual module imports
|
|
96
|
+
*/
|
|
97
|
+
async resolveId(s) {
|
|
98
|
+
if (s === Ue)
|
|
99
|
+
return we;
|
|
100
|
+
},
|
|
101
|
+
/**
|
|
102
|
+
* Generates the virtual module content with dynamic imports
|
|
103
|
+
*/
|
|
104
|
+
async load(s) {
|
|
105
|
+
if (s !== we)
|
|
106
|
+
return;
|
|
107
|
+
const i = await yt(
|
|
108
|
+
this,
|
|
109
|
+
t,
|
|
110
|
+
r,
|
|
111
|
+
n
|
|
112
|
+
), o = await gt(
|
|
113
|
+
this,
|
|
114
|
+
e,
|
|
115
|
+
t,
|
|
116
|
+
r
|
|
117
|
+
);
|
|
118
|
+
return pt(
|
|
119
|
+
t,
|
|
120
|
+
i,
|
|
121
|
+
o
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function pt(e, t, r) {
|
|
127
|
+
return `
|
|
128
|
+
// Import utilities and fallback component
|
|
129
|
+
import { toCamelCase } from '@storyblok/astro';
|
|
130
|
+
|
|
131
|
+
// Dynamically import all Storyblok components using Vite's glob import
|
|
132
|
+
const modules = import.meta.glob('${`${le(e)}/storyblok/**/*.astro`}', { eager: true });
|
|
133
|
+
// Process imported modules into a components object
|
|
134
|
+
const storyblokComponents = {};
|
|
135
|
+
const createComponentLoader = (module) => {
|
|
136
|
+
return async () => module?.default ?? module;
|
|
137
|
+
};
|
|
138
|
+
const registerComponent = (name, component) => {
|
|
139
|
+
Object.defineProperty(storyblokComponents, name, {
|
|
140
|
+
enumerable: true,
|
|
141
|
+
configurable: true,
|
|
142
|
+
get: () => createComponentLoader(component),
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
for (const filePath in modules) {
|
|
146
|
+
// Extract component name from file path (remove extension)
|
|
147
|
+
const fileName = filePath.split('/').pop();
|
|
148
|
+
const componentName = toCamelCase(fileName?.replace(/.[^/.]+$/, '') ?? '');
|
|
149
|
+
if (componentName) {
|
|
150
|
+
registerComponent(componentName, modules[filePath]);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Manual components
|
|
155
|
+
${r.join(`
|
|
156
|
+
|
|
157
|
+
`)}
|
|
158
|
+
// Add fallback component if enabled
|
|
159
|
+
${t}
|
|
160
|
+
// Export the components object for use in Storyblok initialization
|
|
161
|
+
export { storyblokComponents };
|
|
162
|
+
`.trim();
|
|
163
|
+
}
|
|
164
|
+
async function yt(e, t, r, n) {
|
|
165
|
+
if (!r)
|
|
166
|
+
return "";
|
|
167
|
+
if (!n)
|
|
168
|
+
return ce({
|
|
169
|
+
componentName: "FallbackComponent",
|
|
170
|
+
importPath: "@storyblok/astro/FallbackComponent.astro"
|
|
171
|
+
});
|
|
172
|
+
const s = Ve(
|
|
173
|
+
t,
|
|
174
|
+
n
|
|
175
|
+
), i = await e.resolve(s);
|
|
176
|
+
if (!i)
|
|
177
|
+
throw new Error(
|
|
178
|
+
`Custom fallback component could not be found. Does "${s}" exist?`
|
|
179
|
+
);
|
|
180
|
+
return ce({
|
|
181
|
+
componentName: "FallbackComponent",
|
|
182
|
+
importPath: i.id
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
async function gt(e, t, r, n) {
|
|
186
|
+
const s = [];
|
|
187
|
+
for (const [i, o] of Object.entries(t)) {
|
|
188
|
+
const a = Ve(r, o), l = await e.resolve(a);
|
|
189
|
+
if (!l) {
|
|
190
|
+
if (!n)
|
|
191
|
+
throw new Error(
|
|
192
|
+
`Component could not be found for blok "${i}"! Does "${a}" exist?`
|
|
193
|
+
);
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
const c = dt(i);
|
|
197
|
+
s.push(ce({
|
|
198
|
+
componentName: c,
|
|
199
|
+
importPath: l.id
|
|
200
|
+
}));
|
|
201
|
+
}
|
|
202
|
+
return s;
|
|
203
|
+
}
|
|
204
|
+
function Ve(e, t) {
|
|
205
|
+
const n = `${le(e)}${le(t)}`;
|
|
206
|
+
return st(n);
|
|
207
|
+
}
|
|
208
|
+
function ce({
|
|
209
|
+
componentName: e,
|
|
210
|
+
importPath: t
|
|
211
|
+
}) {
|
|
212
|
+
return `
|
|
213
|
+
import ${e} from '${t}';
|
|
214
|
+
registerComponent('${e}', ${e});
|
|
215
|
+
`.trim();
|
|
216
|
+
}
|
|
217
|
+
function Nr(e) {
|
|
218
|
+
const t = {
|
|
219
|
+
useCustomApi: !1,
|
|
220
|
+
bridge: !0,
|
|
221
|
+
componentsDir: "src",
|
|
222
|
+
enableFallbackComponent: !1,
|
|
223
|
+
livePreview: !1,
|
|
224
|
+
...e
|
|
225
|
+
}, {
|
|
226
|
+
accessToken: r,
|
|
227
|
+
useCustomApi: n,
|
|
228
|
+
apiOptions: s,
|
|
229
|
+
componentsDir: i,
|
|
230
|
+
customFallbackComponent: o,
|
|
231
|
+
enableFallbackComponent: a,
|
|
232
|
+
components: l,
|
|
233
|
+
bridge: c,
|
|
234
|
+
livePreview: u
|
|
235
|
+
} = t, h = nt(t.bridge);
|
|
236
|
+
return {
|
|
237
|
+
name: "@storyblok/astro",
|
|
238
|
+
hooks: {
|
|
239
|
+
"astro:config:setup": ({
|
|
240
|
+
injectScript: v,
|
|
241
|
+
updateConfig: T,
|
|
242
|
+
addDevToolbarApp: C,
|
|
243
|
+
addMiddleware: R,
|
|
244
|
+
config: W
|
|
245
|
+
}) => {
|
|
246
|
+
if (T({
|
|
247
|
+
vite: {
|
|
248
|
+
plugins: [
|
|
249
|
+
tt(r, n, s),
|
|
250
|
+
ht(
|
|
251
|
+
l || {},
|
|
252
|
+
i,
|
|
253
|
+
a,
|
|
254
|
+
o
|
|
255
|
+
),
|
|
256
|
+
rt(t)
|
|
257
|
+
]
|
|
258
|
+
}
|
|
259
|
+
}), u && W?.output !== "server")
|
|
260
|
+
throw new Error(
|
|
261
|
+
"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."
|
|
262
|
+
);
|
|
263
|
+
v(
|
|
264
|
+
"page-ssr",
|
|
265
|
+
`
|
|
266
|
+
import { storyblokApiInstance } from "virtual:storyblok-init";
|
|
267
|
+
globalThis.storyblokApiInstance = storyblokApiInstance;
|
|
268
|
+
`
|
|
269
|
+
), c && !u && v(
|
|
270
|
+
"page",
|
|
271
|
+
`import { loadStoryblokBridge } from "@storyblok/astro";
|
|
272
|
+
loadStoryblokBridge().then(() => {
|
|
273
|
+
const { StoryblokBridge, location } = window;
|
|
274
|
+
${h}
|
|
275
|
+
storyblokInstance.on(["published", "change"], (event) => {
|
|
276
|
+
if (!event.slugChanged) {
|
|
277
|
+
location.reload(true);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
`
|
|
282
|
+
), u && (v(
|
|
283
|
+
"page",
|
|
284
|
+
`import { loadStoryblokBridge, handleStoryblokMessage } from "@storyblok/astro";
|
|
285
|
+
loadStoryblokBridge().then(() => {
|
|
286
|
+
const { StoryblokBridge, location } = window;
|
|
287
|
+
${h}
|
|
288
|
+
storyblokInstance.on(["published", "change", "input"], handleStoryblokMessage);
|
|
289
|
+
});
|
|
290
|
+
`
|
|
291
|
+
), R({
|
|
292
|
+
entrypoint: "@storyblok/astro/middleware.ts",
|
|
293
|
+
order: "pre"
|
|
294
|
+
})), C({
|
|
295
|
+
id: "storyblok",
|
|
296
|
+
name: "Storyblok",
|
|
297
|
+
icon: et,
|
|
298
|
+
entrypoint: "@storyblok/astro/toolbarApp.ts"
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
function xr(e) {
|
|
305
|
+
const t = JSON.stringify(e);
|
|
306
|
+
return t === void 0 ? "null" : t.replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029").replace(/&/g, "\\u0026");
|
|
307
|
+
}
|
|
308
|
+
var Se = 11;
|
|
309
|
+
function mt(e, t) {
|
|
310
|
+
var r = t.attributes, n, s, i, o, a;
|
|
311
|
+
if (!(t.nodeType === Se || e.nodeType === Se)) {
|
|
312
|
+
for (var l = r.length - 1; l >= 0; l--)
|
|
313
|
+
n = r[l], s = n.name, i = n.namespaceURI, o = n.value, i ? (s = n.localName || s, a = e.getAttributeNS(i, s), a !== o && (n.prefix === "xmlns" && (s = n.name), e.setAttributeNS(i, s, o))) : (a = e.getAttribute(s), a !== o && e.setAttribute(s, o));
|
|
314
|
+
for (var c = e.attributes, u = c.length - 1; u >= 0; u--)
|
|
315
|
+
n = c[u], s = n.name, i = n.namespaceURI, i ? (s = n.localName || s, t.hasAttributeNS(i, s) || e.removeAttributeNS(i, s)) : t.hasAttribute(s) || e.removeAttribute(s);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
var B, bt = "http://www.w3.org/1999/xhtml", b = typeof document > "u" ? void 0 : document, vt = !!b && "content" in b.createElement("template"), Ct = !!b && b.createRange && "createContextualFragment" in b.createRange();
|
|
319
|
+
function kt(e) {
|
|
320
|
+
var t = b.createElement("template");
|
|
321
|
+
return t.innerHTML = e, t.content.childNodes[0];
|
|
322
|
+
}
|
|
323
|
+
function At(e) {
|
|
324
|
+
B || (B = b.createRange(), B.selectNode(b.body));
|
|
325
|
+
var t = B.createContextualFragment(e);
|
|
326
|
+
return t.childNodes[0];
|
|
327
|
+
}
|
|
328
|
+
function _t(e) {
|
|
329
|
+
var t = b.createElement("body");
|
|
330
|
+
return t.innerHTML = e, t.childNodes[0];
|
|
331
|
+
}
|
|
332
|
+
function wt(e) {
|
|
333
|
+
return e = e.trim(), vt ? kt(e) : Ct ? At(e) : _t(e);
|
|
334
|
+
}
|
|
335
|
+
function z(e, t) {
|
|
336
|
+
var r = e.nodeName, n = t.nodeName, s, i;
|
|
337
|
+
return r === n ? !0 : (s = r.charCodeAt(0), i = n.charCodeAt(0), s <= 90 && i >= 97 ? r === n.toUpperCase() : i <= 90 && s >= 97 ? n === r.toUpperCase() : !1);
|
|
338
|
+
}
|
|
339
|
+
function St(e, t) {
|
|
340
|
+
return !t || t === bt ? b.createElement(e) : b.createElementNS(t, e);
|
|
341
|
+
}
|
|
342
|
+
function Tt(e, t) {
|
|
343
|
+
for (var r = e.firstChild; r; ) {
|
|
344
|
+
var n = r.nextSibling;
|
|
345
|
+
t.appendChild(r), r = n;
|
|
346
|
+
}
|
|
347
|
+
return t;
|
|
348
|
+
}
|
|
349
|
+
function ne(e, t, r) {
|
|
350
|
+
e[r] !== t[r] && (e[r] = t[r], e[r] ? e.setAttribute(r, "") : e.removeAttribute(r));
|
|
351
|
+
}
|
|
352
|
+
var Te = {
|
|
353
|
+
OPTION: function(e, t) {
|
|
354
|
+
var r = e.parentNode;
|
|
355
|
+
if (r) {
|
|
356
|
+
var n = r.nodeName.toUpperCase();
|
|
357
|
+
n === "OPTGROUP" && (r = r.parentNode, n = r && r.nodeName.toUpperCase()), n === "SELECT" && !r.hasAttribute("multiple") && (e.hasAttribute("selected") && !t.selected && (e.setAttribute("selected", "selected"), e.removeAttribute("selected")), r.selectedIndex = -1);
|
|
358
|
+
}
|
|
359
|
+
ne(e, t, "selected");
|
|
360
|
+
},
|
|
361
|
+
/**
|
|
362
|
+
* The "value" attribute is special for the <input> element since it sets
|
|
363
|
+
* the initial value. Changing the "value" attribute without changing the
|
|
364
|
+
* "value" property will have no effect since it is only used to the set the
|
|
365
|
+
* initial value. Similar for the "checked" attribute, and "disabled".
|
|
366
|
+
*/
|
|
367
|
+
INPUT: function(e, t) {
|
|
368
|
+
ne(e, t, "checked"), ne(e, t, "disabled"), e.value !== t.value && (e.value = t.value), t.hasAttribute("value") || e.removeAttribute("value");
|
|
369
|
+
},
|
|
370
|
+
TEXTAREA: function(e, t) {
|
|
371
|
+
var r = t.value;
|
|
372
|
+
e.value !== r && (e.value = r);
|
|
373
|
+
var n = e.firstChild;
|
|
374
|
+
if (n) {
|
|
375
|
+
var s = n.nodeValue;
|
|
376
|
+
if (s == r || !r && s == e.placeholder)
|
|
377
|
+
return;
|
|
378
|
+
n.nodeValue = r;
|
|
379
|
+
}
|
|
380
|
+
},
|
|
381
|
+
SELECT: function(e, t) {
|
|
382
|
+
if (!t.hasAttribute("multiple")) {
|
|
383
|
+
for (var r = -1, n = 0, s = e.firstChild, i, o; s; )
|
|
384
|
+
if (o = s.nodeName && s.nodeName.toUpperCase(), o === "OPTGROUP")
|
|
385
|
+
i = s, s = i.firstChild, s || (s = i.nextSibling, i = null);
|
|
386
|
+
else {
|
|
387
|
+
if (o === "OPTION") {
|
|
388
|
+
if (s.hasAttribute("selected")) {
|
|
389
|
+
r = n;
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
n++;
|
|
393
|
+
}
|
|
394
|
+
s = s.nextSibling, !s && i && (s = i.nextSibling, i = null);
|
|
395
|
+
}
|
|
396
|
+
e.selectedIndex = r;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}, P = 1, Re = 11, Le = 3, Ee = 8;
|
|
400
|
+
function w() {
|
|
401
|
+
}
|
|
402
|
+
function Rt(e) {
|
|
403
|
+
if (e)
|
|
404
|
+
return e.getAttribute && e.getAttribute("id") || e.id;
|
|
405
|
+
}
|
|
406
|
+
function Lt(e) {
|
|
407
|
+
return function(r, n, s) {
|
|
408
|
+
if (s || (s = {}), typeof n == "string")
|
|
409
|
+
if (r.nodeName === "#document" || r.nodeName === "HTML") {
|
|
410
|
+
var i = n;
|
|
411
|
+
n = b.createElement("html"), n.innerHTML = i;
|
|
412
|
+
} else if (r.nodeName === "BODY") {
|
|
413
|
+
var o = n;
|
|
414
|
+
n = b.createElement("html"), n.innerHTML = o;
|
|
415
|
+
var a = n.querySelector("body");
|
|
416
|
+
a && (n = a);
|
|
417
|
+
} else
|
|
418
|
+
n = wt(n);
|
|
419
|
+
else n.nodeType === Re && (n = n.firstElementChild);
|
|
420
|
+
var l = s.getNodeKey || Rt, c = s.onBeforeNodeAdded || w, u = s.onNodeAdded || w, h = s.onBeforeElUpdated || w, v = s.onElUpdated || w, T = s.onBeforeNodeDiscarded || w, C = s.onNodeDiscarded || w, R = s.onBeforeElChildrenUpdated || w, W = s.skipFromChildren || w, me = s.addChild || function(f, d) {
|
|
421
|
+
return f.appendChild(d);
|
|
422
|
+
}, Y = s.childrenOnly === !0, L = /* @__PURE__ */ Object.create(null), H = [];
|
|
423
|
+
function U(f) {
|
|
424
|
+
H.push(f);
|
|
425
|
+
}
|
|
426
|
+
function be(f, d) {
|
|
427
|
+
if (f.nodeType === P)
|
|
428
|
+
for (var g = f.firstChild; g; ) {
|
|
429
|
+
var p = void 0;
|
|
430
|
+
d && (p = l(g)) ? U(p) : (C(g), g.firstChild && be(g, d)), g = g.nextSibling;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
function V(f, d, g) {
|
|
434
|
+
T(f) !== !1 && (d && d.removeChild(f), C(f), be(f, g));
|
|
435
|
+
}
|
|
436
|
+
function X(f) {
|
|
437
|
+
if (f.nodeType === P || f.nodeType === Re)
|
|
438
|
+
for (var d = f.firstChild; d; ) {
|
|
439
|
+
var g = l(d);
|
|
440
|
+
g && (L[g] = d), X(d), d = d.nextSibling;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
X(r);
|
|
444
|
+
function Q(f) {
|
|
445
|
+
u(f);
|
|
446
|
+
for (var d = f.firstChild; d; ) {
|
|
447
|
+
var g = d.nextSibling, p = l(d);
|
|
448
|
+
if (p) {
|
|
449
|
+
var y = L[p];
|
|
450
|
+
y && z(d, y) ? (d.parentNode.replaceChild(y, d), D(y, d)) : Q(d);
|
|
451
|
+
} else
|
|
452
|
+
Q(d);
|
|
453
|
+
d = g;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
function Ye(f, d, g) {
|
|
457
|
+
for (; d; ) {
|
|
458
|
+
var p = d.nextSibling;
|
|
459
|
+
(g = l(d)) ? U(g) : V(
|
|
460
|
+
d,
|
|
461
|
+
f,
|
|
462
|
+
!0
|
|
463
|
+
/* skip keyed nodes */
|
|
464
|
+
), d = p;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
function D(f, d, g) {
|
|
468
|
+
var p = l(d);
|
|
469
|
+
if (p && delete L[p], !g) {
|
|
470
|
+
var y = h(f, d);
|
|
471
|
+
if (y === !1 || (y instanceof HTMLElement && (f = y, X(f)), e(f, d), v(f), R(f, d) === !1))
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
f.nodeName !== "TEXTAREA" ? Xe(f, d) : Te.TEXTAREA(f, d);
|
|
475
|
+
}
|
|
476
|
+
function Xe(f, d) {
|
|
477
|
+
var g = W(f, d), p = d.firstChild, y = f.firstChild, E, k, $, F, A;
|
|
478
|
+
e: for (; p; ) {
|
|
479
|
+
for (F = p.nextSibling, E = l(p); !g && y; ) {
|
|
480
|
+
if ($ = y.nextSibling, p.isSameNode && p.isSameNode(y)) {
|
|
481
|
+
p = F, y = $;
|
|
482
|
+
continue e;
|
|
483
|
+
}
|
|
484
|
+
k = l(y);
|
|
485
|
+
var q = y.nodeType, _ = void 0;
|
|
486
|
+
if (q === p.nodeType && (q === P ? (E ? E !== k && ((A = L[E]) ? $ === A ? _ = !1 : (f.insertBefore(A, y), k ? U(k) : V(
|
|
487
|
+
y,
|
|
488
|
+
f,
|
|
489
|
+
!0
|
|
490
|
+
/* skip keyed nodes */
|
|
491
|
+
), y = A, k = l(y)) : _ = !1) : k && (_ = !1), _ = _ !== !1 && z(y, p), _ && D(y, p)) : (q === Le || q == Ee) && (_ = !0, y.nodeValue !== p.nodeValue && (y.nodeValue = p.nodeValue))), _) {
|
|
492
|
+
p = F, y = $;
|
|
493
|
+
continue e;
|
|
494
|
+
}
|
|
495
|
+
k ? U(k) : V(
|
|
496
|
+
y,
|
|
497
|
+
f,
|
|
498
|
+
!0
|
|
499
|
+
/* skip keyed nodes */
|
|
500
|
+
), y = $;
|
|
501
|
+
}
|
|
502
|
+
if (E && (A = L[E]) && z(A, p))
|
|
503
|
+
g || me(f, A), D(A, p);
|
|
504
|
+
else {
|
|
505
|
+
var re = c(p);
|
|
506
|
+
re !== !1 && (re && (p = re), p.actualize && (p = p.actualize(f.ownerDocument || b)), me(f, p), Q(p));
|
|
507
|
+
}
|
|
508
|
+
p = F, y = $;
|
|
509
|
+
}
|
|
510
|
+
Ye(f, y, k);
|
|
511
|
+
var Ce = Te[f.nodeName];
|
|
512
|
+
Ce && Ce(f, d);
|
|
513
|
+
}
|
|
514
|
+
var m = r, j = m.nodeType, ve = n.nodeType;
|
|
515
|
+
if (!Y) {
|
|
516
|
+
if (j === P)
|
|
517
|
+
ve === P ? z(r, n) || (C(r), m = Tt(r, St(n.nodeName, n.namespaceURI))) : m = n;
|
|
518
|
+
else if (j === Le || j === Ee) {
|
|
519
|
+
if (ve === j)
|
|
520
|
+
return m.nodeValue !== n.nodeValue && (m.nodeValue = n.nodeValue), m;
|
|
521
|
+
m = n;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
if (m === n)
|
|
525
|
+
C(r);
|
|
526
|
+
else {
|
|
527
|
+
if (n.isSameNode && n.isSameNode(m))
|
|
528
|
+
return;
|
|
529
|
+
if (D(m, n, Y), H)
|
|
530
|
+
for (var ee = 0, Qe = H.length; ee < Qe; ee++) {
|
|
531
|
+
var te = L[H[ee]];
|
|
532
|
+
te && V(te, te.parentNode, !1);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
return !Y && m !== r && r.parentNode && (m.actualize && (m = m.actualize(r.ownerDocument || b)), r.parentNode.replaceChild(m, r)), m;
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
var Et = Lt(mt);
|
|
539
|
+
let se, Z = null;
|
|
540
|
+
const $t = 500, Mt = "__STORYBLOK_SERVERDATA__", De = "data-blok-focused", N = "data-blok-uid", Pt = "data-preserve-state", Ot = "storyblok-live-preview", It = "storyblok-live-preview-updating", $e = "storyblok-live-preview-updated";
|
|
541
|
+
function Nt() {
|
|
542
|
+
const e = document.querySelector(
|
|
543
|
+
`meta[name="${Ot}"]`
|
|
544
|
+
);
|
|
545
|
+
return e?.content === "disabled" || e?.content === "false";
|
|
546
|
+
}
|
|
547
|
+
async function Hr(e) {
|
|
548
|
+
const { action: t, story: r } = e || {};
|
|
549
|
+
if (["published", "change"].includes(t)) {
|
|
550
|
+
location.reload();
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
if (t === "input" && r) {
|
|
554
|
+
if (Nt())
|
|
555
|
+
return;
|
|
556
|
+
Z && Z.abort(), se && clearTimeout(se), se = setTimeout(async () => {
|
|
557
|
+
try {
|
|
558
|
+
await xt(r);
|
|
559
|
+
} catch (n) {
|
|
560
|
+
if (n instanceof Error && n.name === "AbortError")
|
|
561
|
+
return;
|
|
562
|
+
console.error("Failed to update live preview:", n);
|
|
563
|
+
}
|
|
564
|
+
}, $t);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
async function xt(e) {
|
|
568
|
+
if (ie(
|
|
569
|
+
It,
|
|
570
|
+
{ story: e },
|
|
571
|
+
!0
|
|
572
|
+
).defaultPrevented)
|
|
573
|
+
return;
|
|
574
|
+
const r = document.body, n = Ft(r), s = await jt(e, n);
|
|
575
|
+
if (s.outerHTML === r.outerHTML) {
|
|
576
|
+
ie($e, { story: e });
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
const i = document.querySelector(`[${De}="true"]`);
|
|
580
|
+
Ut(r, s, i), ie($e, { story: e });
|
|
581
|
+
}
|
|
582
|
+
function Ht(e, t) {
|
|
583
|
+
const r = e.attributes.getNamedItem(N)?.value, n = t.attributes.getNamedItem(N)?.value;
|
|
584
|
+
r === n && Array.from(e.attributes).forEach((s) => {
|
|
585
|
+
if (s.name === N)
|
|
586
|
+
return;
|
|
587
|
+
const i = s.value, o = t.getAttribute(s.name);
|
|
588
|
+
(!t.hasAttribute(s.name) || o !== i) && t.setAttribute(s.name, i);
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
function Ut(e, t, r) {
|
|
592
|
+
let n = !0;
|
|
593
|
+
if (r) {
|
|
594
|
+
const s = r.getAttribute(N), i = t.querySelector(
|
|
595
|
+
`[data-blok-uid="${s}"]`
|
|
596
|
+
);
|
|
597
|
+
i && (i.setAttribute(De, "true"), Me(r, i), n = !1);
|
|
598
|
+
}
|
|
599
|
+
n && Me(e, t);
|
|
600
|
+
}
|
|
601
|
+
function Vt(e) {
|
|
602
|
+
if (e.nodeType === 1) {
|
|
603
|
+
const t = e.getAttribute(N);
|
|
604
|
+
if (t)
|
|
605
|
+
return t;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
function Me(e, t) {
|
|
609
|
+
Et(e, t, {
|
|
610
|
+
getNodeKey: Vt,
|
|
611
|
+
onBeforeElUpdated: (r, n) => r.hasAttribute(Pt) ? !1 : (Ht(r, n), !0)
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
const Dt = (e) => {
|
|
615
|
+
if (e === null || typeof e != "object" || Array.isArray(e))
|
|
616
|
+
return !1;
|
|
617
|
+
const t = Object.getPrototypeOf(e);
|
|
618
|
+
return t === Object.prototype || t === null;
|
|
619
|
+
};
|
|
620
|
+
async function jt(e, t) {
|
|
621
|
+
Z = new AbortController();
|
|
622
|
+
const r = {
|
|
623
|
+
story: {
|
|
624
|
+
...e,
|
|
625
|
+
is_storyblok_preview: !0
|
|
626
|
+
},
|
|
627
|
+
...Dt(t) && { serverData: t }
|
|
628
|
+
}, n = await fetch(location.href, {
|
|
629
|
+
method: "POST",
|
|
630
|
+
body: JSON.stringify(r),
|
|
631
|
+
headers: {
|
|
632
|
+
"Content-Type": "application/json"
|
|
633
|
+
},
|
|
634
|
+
signal: Z.signal
|
|
635
|
+
});
|
|
636
|
+
if (!n.ok)
|
|
637
|
+
throw new Error(
|
|
638
|
+
`Failed to fetch updated HTML: ${n.status} ${n.statusText}`
|
|
639
|
+
);
|
|
640
|
+
const s = await n.text();
|
|
641
|
+
return new DOMParser().parseFromString(s, "text/html").body;
|
|
642
|
+
}
|
|
643
|
+
function ie(e, t, r = !1) {
|
|
644
|
+
const n = new CustomEvent(e, { detail: t, cancelable: r });
|
|
645
|
+
return document.dispatchEvent(n), n;
|
|
646
|
+
}
|
|
647
|
+
function Ft(e) {
|
|
648
|
+
const t = e.querySelector(`#${Mt}`);
|
|
649
|
+
if (!t?.textContent)
|
|
650
|
+
return null;
|
|
651
|
+
try {
|
|
652
|
+
return JSON.parse(t.textContent || "{}");
|
|
653
|
+
} catch (r) {
|
|
654
|
+
return console.error("Failed to parse server data:", r), null;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
const qt = ["_storyblok", "_storyblok_c", "_storyblok_tk[space_id]"];
|
|
658
|
+
function Ur(e, t) {
|
|
659
|
+
const r = e.searchParams;
|
|
660
|
+
return !(!qt.every((s) => r.has(s)) || t?.spaceId && r.get("_storyblok_tk[space_id]") !== t.spaceId);
|
|
661
|
+
}
|
|
662
|
+
function Bt(e, t) {
|
|
663
|
+
if (!t) return {
|
|
664
|
+
src: e,
|
|
665
|
+
attrs: {}
|
|
666
|
+
};
|
|
667
|
+
let r = 0, n = 0;
|
|
668
|
+
const s = {}, i = [];
|
|
669
|
+
function o(l, c, u, h, v) {
|
|
670
|
+
typeof l != "number" || l <= c || l >= u ? console.warn(`[StoryblokRichText] - ${h.charAt(0).toUpperCase() + h.slice(1)} value must be a number between ${c} and ${u} (inclusive)`) : v.push(`${h}(${l})`);
|
|
671
|
+
}
|
|
672
|
+
if (typeof t == "object") {
|
|
673
|
+
if (t.width !== void 0 && (typeof t.width == "number" && t.width >= 0 ? (s.width = t.width, r = t.width) : console.warn("[StoryblokRichText] - Width value must be a number greater than or equal to 0")), t.height !== void 0 && (typeof t.height == "number" && t.height >= 0 ? (s.height = t.height, n = t.height) : console.warn("[StoryblokRichText] - Height value must be a number greater than or equal to 0")), t.height === 0 && t.width === 0 && (delete s.width, delete s.height, console.warn("[StoryblokRichText] - Width and height values cannot both be 0")), t.loading && ["lazy", "eager"].includes(t.loading) && (s.loading = t.loading), t.class && (s.class = t.class), t.filters) {
|
|
674
|
+
const { filters: l } = t || {}, { blur: c, brightness: u, fill: h, format: v, grayscale: T, quality: C, rotate: R } = l || {};
|
|
675
|
+
c && o(c, 0, 100, "blur", i), C && o(C, 0, 100, "quality", i), u && o(u, 0, 100, "brightness", i), h && i.push(`fill(${h})`), T && i.push("grayscale()"), R && [
|
|
676
|
+
0,
|
|
677
|
+
90,
|
|
678
|
+
180,
|
|
679
|
+
270
|
|
680
|
+
].includes(t.filters.rotate || 0) && i.push(`rotate(${R})`), v && [
|
|
681
|
+
"webp",
|
|
682
|
+
"png",
|
|
683
|
+
"jpeg"
|
|
684
|
+
].includes(v) && i.push(`format(${v})`);
|
|
685
|
+
}
|
|
686
|
+
t.srcset && (s.srcset = t.srcset.map((l) => {
|
|
687
|
+
if (typeof l == "number") return `${e}/m/${l}x0/${i.length > 0 ? `filters:${i.join(":")}` : ""} ${l}w`;
|
|
688
|
+
if (Array.isArray(l) && l.length === 2) {
|
|
689
|
+
const [c, u] = l;
|
|
690
|
+
return `${e}/m/${c}x${u}/${i.length > 0 ? `filters:${i.join(":")}` : ""} ${c}w`;
|
|
691
|
+
} else {
|
|
692
|
+
console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
}).join(", ")), t.sizes && (s.sizes = t.sizes.join(", "));
|
|
696
|
+
}
|
|
697
|
+
let a = `${e}/m/`;
|
|
698
|
+
return (r > 0 || n > 0) && (a = `${a}${r}x${n}/`), i.length > 0 && (a = `${a}filters:${i.join(":")}`), {
|
|
699
|
+
src: a,
|
|
700
|
+
attrs: s
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
function ue(e, t) {
|
|
704
|
+
if (e === t) return !0;
|
|
705
|
+
if (e == null || t === null || t === void 0) return e === t;
|
|
706
|
+
if (typeof e != typeof t || typeof e != "object" || Array.isArray(e) !== Array.isArray(t)) return !1;
|
|
707
|
+
if (Array.isArray(e))
|
|
708
|
+
return e.length !== t.length ? !1 : e.every((s, i) => ue(s, t[i]));
|
|
709
|
+
const r = Object.keys(e), n = Object.keys(t);
|
|
710
|
+
return r.length !== n.length ? !1 : r.every((s) => Object.prototype.hasOwnProperty.call(t, s) && ue(e[s], t[s]));
|
|
711
|
+
}
|
|
712
|
+
const zt = [
|
|
713
|
+
"area",
|
|
714
|
+
"base",
|
|
715
|
+
"br",
|
|
716
|
+
"col",
|
|
717
|
+
"embed",
|
|
718
|
+
"hr",
|
|
719
|
+
"img",
|
|
720
|
+
"input",
|
|
721
|
+
"link",
|
|
722
|
+
"meta",
|
|
723
|
+
"param",
|
|
724
|
+
"source",
|
|
725
|
+
"track",
|
|
726
|
+
"wbr"
|
|
727
|
+
];
|
|
728
|
+
function Gt(e) {
|
|
729
|
+
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
730
|
+
}
|
|
731
|
+
function Zt() {
|
|
732
|
+
const e = /* @__PURE__ */ new Map();
|
|
733
|
+
return (t) => {
|
|
734
|
+
const r = (e.get(t) || 0) + 1;
|
|
735
|
+
return e.set(t, r), `${t}-${r}`;
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
const Kt = (e) => `h${typeof e?.level == "number" ? Math.min(6, Math.max(1, e.level)) : 1}`, K = {
|
|
739
|
+
paragraph: {
|
|
740
|
+
tag: "p",
|
|
741
|
+
content: !0
|
|
742
|
+
},
|
|
743
|
+
doc: null,
|
|
744
|
+
text: null,
|
|
745
|
+
emoji: {
|
|
746
|
+
tag: "img",
|
|
747
|
+
attrs: {
|
|
748
|
+
style: "width: 1.25em; height: 1.25em; vertical-align: text-top;",
|
|
749
|
+
draggable: "false",
|
|
750
|
+
loading: "lazy"
|
|
751
|
+
}
|
|
752
|
+
},
|
|
753
|
+
blockquote: {
|
|
754
|
+
tag: "blockquote",
|
|
755
|
+
content: !0
|
|
756
|
+
},
|
|
757
|
+
heading: { resolve: Kt },
|
|
758
|
+
bullet_list: {
|
|
759
|
+
tag: "ul",
|
|
760
|
+
content: !0
|
|
761
|
+
},
|
|
762
|
+
ordered_list: {
|
|
763
|
+
tag: "ol",
|
|
764
|
+
attrs: { order: 1 },
|
|
765
|
+
content: !0
|
|
766
|
+
},
|
|
767
|
+
list_item: {
|
|
768
|
+
tag: "li",
|
|
769
|
+
content: !0
|
|
770
|
+
},
|
|
771
|
+
code_block: {
|
|
772
|
+
tag: "pre",
|
|
773
|
+
children: [{
|
|
774
|
+
tag: "code",
|
|
775
|
+
content: !0
|
|
776
|
+
}]
|
|
777
|
+
},
|
|
778
|
+
hard_break: { tag: "br" },
|
|
779
|
+
horizontal_rule: { tag: "hr" },
|
|
780
|
+
image: { tag: "img" },
|
|
781
|
+
table: {
|
|
782
|
+
tag: "table",
|
|
783
|
+
content: !0
|
|
784
|
+
},
|
|
785
|
+
tableRow: {
|
|
786
|
+
tag: "tr",
|
|
787
|
+
content: !0
|
|
788
|
+
},
|
|
789
|
+
tableCell: {
|
|
790
|
+
tag: "td",
|
|
791
|
+
attrs: {
|
|
792
|
+
colspan: 1,
|
|
793
|
+
rowspan: 1
|
|
794
|
+
},
|
|
795
|
+
content: !0
|
|
796
|
+
},
|
|
797
|
+
tableHeader: {
|
|
798
|
+
tag: "th",
|
|
799
|
+
attrs: {
|
|
800
|
+
colspan: 1,
|
|
801
|
+
rowspan: 1
|
|
802
|
+
},
|
|
803
|
+
content: !0
|
|
804
|
+
},
|
|
805
|
+
blok: null
|
|
806
|
+
}, Jt = {
|
|
807
|
+
link: {
|
|
808
|
+
tag: "a",
|
|
809
|
+
attrs: {
|
|
810
|
+
rel: "noopener noreferrer nofollow",
|
|
811
|
+
linktype: "url",
|
|
812
|
+
custom: {}
|
|
813
|
+
},
|
|
814
|
+
content: !0
|
|
815
|
+
},
|
|
816
|
+
bold: {
|
|
817
|
+
tag: "strong",
|
|
818
|
+
content: !0
|
|
819
|
+
},
|
|
820
|
+
italic: {
|
|
821
|
+
tag: "em",
|
|
822
|
+
content: !0
|
|
823
|
+
},
|
|
824
|
+
strike: {
|
|
825
|
+
tag: "s",
|
|
826
|
+
content: !0
|
|
827
|
+
},
|
|
828
|
+
underline: {
|
|
829
|
+
tag: "u",
|
|
830
|
+
content: !0
|
|
831
|
+
},
|
|
832
|
+
code: {
|
|
833
|
+
tag: "code",
|
|
834
|
+
content: !0
|
|
835
|
+
},
|
|
836
|
+
superscript: {
|
|
837
|
+
tag: "sup",
|
|
838
|
+
content: !0
|
|
839
|
+
},
|
|
840
|
+
subscript: {
|
|
841
|
+
tag: "sub",
|
|
842
|
+
content: !0
|
|
843
|
+
},
|
|
844
|
+
highlight: {
|
|
845
|
+
tag: "mark",
|
|
846
|
+
content: !0
|
|
847
|
+
},
|
|
848
|
+
textStyle: {
|
|
849
|
+
tag: "span",
|
|
850
|
+
content: !0
|
|
851
|
+
},
|
|
852
|
+
anchor: {
|
|
853
|
+
tag: "span",
|
|
854
|
+
content: !0
|
|
855
|
+
},
|
|
856
|
+
styled: {
|
|
857
|
+
tag: "span",
|
|
858
|
+
content: !0
|
|
859
|
+
}
|
|
860
|
+
};
|
|
861
|
+
function je(e) {
|
|
862
|
+
return Object.entries(e).filter(([, t]) => fe(t)).map(([t, r]) => `${Xt(t)}: ${r};`).join(" ");
|
|
863
|
+
}
|
|
864
|
+
function Wt(e) {
|
|
865
|
+
return e.split(";").map((t) => t.trim()).filter(Boolean).reduce((t, r) => {
|
|
866
|
+
const n = r.indexOf(":");
|
|
867
|
+
if (n === -1) return t;
|
|
868
|
+
const s = r.slice(0, n).trim(), i = r.slice(n + 1).trim();
|
|
869
|
+
return !s || !i || (t[Yt(s)] = i), t;
|
|
870
|
+
}, {});
|
|
871
|
+
}
|
|
872
|
+
function Yt(e) {
|
|
873
|
+
return e.replace(/-([a-z])/g, (t, r) => r.toUpperCase());
|
|
874
|
+
}
|
|
875
|
+
function Xt(e) {
|
|
876
|
+
return e.replace(/[A-Z]/g, (t) => `-${t.toLowerCase()}`);
|
|
877
|
+
}
|
|
878
|
+
function fe(e) {
|
|
879
|
+
return e != null && e !== "";
|
|
880
|
+
}
|
|
881
|
+
const Qt = {
|
|
882
|
+
highlight: { color: "backgroundColor" },
|
|
883
|
+
textStyle: { color: "color" },
|
|
884
|
+
paragraph: { textAlign: "textAlign" },
|
|
885
|
+
heading: { textAlign: "textAlign" },
|
|
886
|
+
tableCell: {
|
|
887
|
+
backgroundColor: "backgroundColor",
|
|
888
|
+
colwidth: "width"
|
|
889
|
+
},
|
|
890
|
+
tableHeader: { colwidth: "width" }
|
|
891
|
+
}, er = {
|
|
892
|
+
fallbackImage: "src",
|
|
893
|
+
body: "data-body",
|
|
894
|
+
colspan: "colSpan",
|
|
895
|
+
rowspan: "rowSpan",
|
|
896
|
+
name: "data-name",
|
|
897
|
+
emoji: "data-emoji",
|
|
898
|
+
order: "start"
|
|
899
|
+
}, tr = /* @__PURE__ */ new Set([
|
|
900
|
+
"level",
|
|
901
|
+
"linktype",
|
|
902
|
+
"uuid",
|
|
903
|
+
"anchor",
|
|
904
|
+
"meta_data",
|
|
905
|
+
"copyright",
|
|
906
|
+
"source"
|
|
907
|
+
]), rr = /* @__PURE__ */ new Set([
|
|
908
|
+
"colspan",
|
|
909
|
+
"rowspan",
|
|
910
|
+
"order"
|
|
911
|
+
]);
|
|
912
|
+
function nr(e) {
|
|
913
|
+
const { linktype: t, href: r, anchor: n } = e;
|
|
914
|
+
if (t === "story") return `${typeof r == "string" ? r : ""}${typeof n == "string" && n ? `#${n}` : ""}`;
|
|
915
|
+
if (t === "email" && typeof r == "string") return `mailto:${r.replace(/^mailto:/, "")}`;
|
|
916
|
+
}
|
|
917
|
+
function sr(e) {
|
|
918
|
+
const t = {};
|
|
919
|
+
let r = {};
|
|
920
|
+
if (!(e in K)) return {
|
|
921
|
+
staticAttrs: r,
|
|
922
|
+
staticStyle: t
|
|
923
|
+
};
|
|
924
|
+
const n = K[e];
|
|
925
|
+
if (!n || !("attrs" in n)) return {
|
|
926
|
+
staticAttrs: r,
|
|
927
|
+
staticStyle: t
|
|
928
|
+
};
|
|
929
|
+
const s = n.attrs || {}, i = "style" in s && typeof s.style == "string" ? s.style : "", { style: o, ...a } = s;
|
|
930
|
+
return r = a, i && Object.assign(t, Wt(i)), {
|
|
931
|
+
staticAttrs: r,
|
|
932
|
+
staticStyle: t
|
|
933
|
+
};
|
|
934
|
+
}
|
|
935
|
+
function ir(e) {
|
|
936
|
+
return Array.isArray(e) ? e[0] != null ? `${e[0]}px` : void 0 : typeof e == "number" || typeof e == "string" ? e : String(e);
|
|
937
|
+
}
|
|
938
|
+
function or(e, t, r, n, s, i, o) {
|
|
939
|
+
if (!fe(t) || tr.has(e) || rr.has(e) && t === 1) return;
|
|
940
|
+
if (e in n) {
|
|
941
|
+
const l = n[e], c = ir(t);
|
|
942
|
+
c !== void 0 && fe(c) && (i[l] = c);
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
const a = s[e] ?? e;
|
|
946
|
+
if (a === "custom" && r === "link" && typeof t == "object" && t !== null) {
|
|
947
|
+
for (const [l, c] of Object.entries(t)) o[l] = String(c);
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
if (typeof t == "object" && t !== null) {
|
|
951
|
+
o[a] = JSON.stringify(t);
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
o[a] = t;
|
|
955
|
+
}
|
|
956
|
+
function Fe(e, t = {}, r = {}) {
|
|
957
|
+
const { staticAttrs: n, staticStyle: s } = sr(e), i = { ...s }, o = {}, a = Qt[e] || {}, l = {
|
|
958
|
+
...er,
|
|
959
|
+
...r
|
|
960
|
+
}, c = {
|
|
961
|
+
...n,
|
|
962
|
+
...t
|
|
963
|
+
};
|
|
964
|
+
for (const [u, h] of Object.entries(c)) or(u, h, e, a, l, i, o);
|
|
965
|
+
if (e === "link") {
|
|
966
|
+
const u = nr(t);
|
|
967
|
+
u !== void 0 && (o.href = u);
|
|
968
|
+
}
|
|
969
|
+
return {
|
|
970
|
+
...o,
|
|
971
|
+
...Object.keys(i).length > 0 && { style: i }
|
|
972
|
+
};
|
|
973
|
+
}
|
|
974
|
+
const ar = (e) => String(e).replace(/[&"'<>]/g, (t) => {
|
|
975
|
+
switch (t) {
|
|
976
|
+
case "&":
|
|
977
|
+
return "&";
|
|
978
|
+
case '"':
|
|
979
|
+
return """;
|
|
980
|
+
case "'":
|
|
981
|
+
return "'";
|
|
982
|
+
case "<":
|
|
983
|
+
return "<";
|
|
984
|
+
case ">":
|
|
985
|
+
return ">";
|
|
986
|
+
default:
|
|
987
|
+
return t;
|
|
988
|
+
}
|
|
989
|
+
});
|
|
990
|
+
function J(e) {
|
|
991
|
+
if (e.type !== "text" || !e.marks) return null;
|
|
992
|
+
for (const t of e.marks) if (t.type === "link") return t;
|
|
993
|
+
return null;
|
|
994
|
+
}
|
|
995
|
+
function qe(e, t) {
|
|
996
|
+
return !e || !t ? !1 : ue(e.attrs ?? {}, t.attrs ?? {});
|
|
997
|
+
}
|
|
998
|
+
function Vr(e) {
|
|
999
|
+
return e.type !== "text" || !e.marks ? [] : e.marks.filter((t) => t.type !== "link");
|
|
1000
|
+
}
|
|
1001
|
+
function Dr(e) {
|
|
1002
|
+
const t = [];
|
|
1003
|
+
let r = 0;
|
|
1004
|
+
const n = e.length;
|
|
1005
|
+
for (; r < n; ) {
|
|
1006
|
+
const s = e[r], i = J(s);
|
|
1007
|
+
if (i) {
|
|
1008
|
+
const o = [s];
|
|
1009
|
+
let a = r + 1;
|
|
1010
|
+
for (; a < n && qe(i, J(e[a])); )
|
|
1011
|
+
o.push(e[a]), a++;
|
|
1012
|
+
t.push({
|
|
1013
|
+
nodes: o,
|
|
1014
|
+
linkMark: i,
|
|
1015
|
+
_key: `group-link-${r}`
|
|
1016
|
+
}), r = a;
|
|
1017
|
+
} else
|
|
1018
|
+
t.push({
|
|
1019
|
+
nodes: [s],
|
|
1020
|
+
linkMark: null,
|
|
1021
|
+
_key: `group-node-${r}`
|
|
1022
|
+
}), r++;
|
|
1023
|
+
}
|
|
1024
|
+
return t;
|
|
1025
|
+
}
|
|
1026
|
+
function Be(e) {
|
|
1027
|
+
const t = e.content;
|
|
1028
|
+
if (!t?.length) return !1;
|
|
1029
|
+
for (const r of t) if (r.type !== "tableHeader") return !1;
|
|
1030
|
+
return !0;
|
|
1031
|
+
}
|
|
1032
|
+
function jr(e) {
|
|
1033
|
+
if (!e?.length) return {
|
|
1034
|
+
headerRows: [],
|
|
1035
|
+
bodyRows: []
|
|
1036
|
+
};
|
|
1037
|
+
let t = 0;
|
|
1038
|
+
for (; t < e.length && Be(e[t]); ) t++;
|
|
1039
|
+
return {
|
|
1040
|
+
headerRows: e.slice(0, t),
|
|
1041
|
+
bodyRows: e.slice(t)
|
|
1042
|
+
};
|
|
1043
|
+
}
|
|
1044
|
+
function lr(e, t = !1) {
|
|
1045
|
+
if (!e) return [];
|
|
1046
|
+
if (Array.isArray(e)) return e;
|
|
1047
|
+
const r = e.type === "doc" ? e.content || [] : [e];
|
|
1048
|
+
return t ? ze(r, Zt()) : r;
|
|
1049
|
+
}
|
|
1050
|
+
function ze(e, t) {
|
|
1051
|
+
return e.map((r) => ({
|
|
1052
|
+
...r,
|
|
1053
|
+
_key: t(r.type),
|
|
1054
|
+
marks: r.marks?.map((n) => ({
|
|
1055
|
+
...n,
|
|
1056
|
+
_key: t(n.type)
|
|
1057
|
+
})),
|
|
1058
|
+
content: r.content ? ze(r.content, t) : void 0
|
|
1059
|
+
}));
|
|
1060
|
+
}
|
|
1061
|
+
function ye(e) {
|
|
1062
|
+
const t = e.type, r = K[t] ?? Jt[t];
|
|
1063
|
+
return r ? "resolve" in r && typeof r.resolve == "function" ? r.resolve(e.attrs) : "tag" in r && typeof r.tag == "string" ? r.tag : null : null;
|
|
1064
|
+
}
|
|
1065
|
+
function Ge(e) {
|
|
1066
|
+
return zt.includes(e);
|
|
1067
|
+
}
|
|
1068
|
+
function cr(e) {
|
|
1069
|
+
const t = K[e.type];
|
|
1070
|
+
return t && "children" in t ? t.children : null;
|
|
1071
|
+
}
|
|
1072
|
+
function ur(e) {
|
|
1073
|
+
let t = "";
|
|
1074
|
+
for (const r in e) {
|
|
1075
|
+
const n = e[r];
|
|
1076
|
+
n != null && (t += ` ${r}="${ar(n)}"`);
|
|
1077
|
+
}
|
|
1078
|
+
return t;
|
|
1079
|
+
}
|
|
1080
|
+
function Fr(e, t) {
|
|
1081
|
+
const r = lr(e);
|
|
1082
|
+
return r?.length ? Ze(r, t) : "";
|
|
1083
|
+
}
|
|
1084
|
+
function de(e, t) {
|
|
1085
|
+
if (e.type === "text") return Ke(e, e.marks, t);
|
|
1086
|
+
const r = e.content ? Ze(e.content, t) : "", n = t?.renderers?.[e.type];
|
|
1087
|
+
if (n) return n({
|
|
1088
|
+
...e,
|
|
1089
|
+
children: r,
|
|
1090
|
+
context: t
|
|
1091
|
+
});
|
|
1092
|
+
if (e.type === "blok")
|
|
1093
|
+
return console.warn('"blok" nodes require a custom renderer in renderRichText.'), "";
|
|
1094
|
+
const s = ye(e);
|
|
1095
|
+
if (!s) return r;
|
|
1096
|
+
if (e.type === "image" && t?.optimizeImage) return fr(e, t);
|
|
1097
|
+
const i = x(e.type, e.attrs);
|
|
1098
|
+
if (Ge(s)) return `<${s}${i}>`;
|
|
1099
|
+
if (e.type === "table") return `<${s}${i}>${pr(e.content, t)}</${s}>`;
|
|
1100
|
+
const o = cr(e);
|
|
1101
|
+
return o ? `<${s}>${Je(e.type, o, e.attrs, r)}</${s}>` : `<${s}${i}>${r}</${s}>`;
|
|
1102
|
+
}
|
|
1103
|
+
function fr(e, t) {
|
|
1104
|
+
const r = e.attrs, n = r?.src;
|
|
1105
|
+
let s = r;
|
|
1106
|
+
if (n) {
|
|
1107
|
+
const { src: o, attrs: a } = Bt(n, t.optimizeImage);
|
|
1108
|
+
s = {
|
|
1109
|
+
...r,
|
|
1110
|
+
src: o,
|
|
1111
|
+
...a
|
|
1112
|
+
};
|
|
1113
|
+
}
|
|
1114
|
+
const i = x("image", s);
|
|
1115
|
+
return i ? `<img${i}>` : "<img>";
|
|
1116
|
+
}
|
|
1117
|
+
function Ze(e, t) {
|
|
1118
|
+
let r = "", n = 0;
|
|
1119
|
+
const s = e.length;
|
|
1120
|
+
for (; n < s; ) {
|
|
1121
|
+
const i = e[n], o = J(i);
|
|
1122
|
+
if (o) {
|
|
1123
|
+
let a = n + 1;
|
|
1124
|
+
for (; a < s && qe(o, J(e[a])); ) a++;
|
|
1125
|
+
r += hr(e, n, a, o, t), n = a;
|
|
1126
|
+
} else
|
|
1127
|
+
r += de(i, t), n++;
|
|
1128
|
+
}
|
|
1129
|
+
return r;
|
|
1130
|
+
}
|
|
1131
|
+
function Ke(e, t, r) {
|
|
1132
|
+
let n = Gt(e.text);
|
|
1133
|
+
if (!t?.length) return n;
|
|
1134
|
+
for (const s of t) n = dr(n, s, r);
|
|
1135
|
+
return n;
|
|
1136
|
+
}
|
|
1137
|
+
function dr(e, t, r) {
|
|
1138
|
+
const n = r?.renderers?.[t.type];
|
|
1139
|
+
if (n) return n({
|
|
1140
|
+
...t,
|
|
1141
|
+
children: e
|
|
1142
|
+
});
|
|
1143
|
+
const s = ye(t);
|
|
1144
|
+
return s ? `<${s}${x(t.type, t.attrs)}>${e}</${s}>` : e;
|
|
1145
|
+
}
|
|
1146
|
+
function hr(e, t, r, n, s) {
|
|
1147
|
+
let i = "";
|
|
1148
|
+
for (let l = t; l < r; l++) {
|
|
1149
|
+
const c = e[l], u = c.marks?.filter((h) => h.type !== "link");
|
|
1150
|
+
i += Ke(c, u, s);
|
|
1151
|
+
}
|
|
1152
|
+
const o = s?.renderers?.[n.type];
|
|
1153
|
+
if (o) return o({
|
|
1154
|
+
...n,
|
|
1155
|
+
children: i
|
|
1156
|
+
});
|
|
1157
|
+
const a = ye(n);
|
|
1158
|
+
return a ? `<${a}${x(n.type, n.attrs)}>${i}</${a}>` : i;
|
|
1159
|
+
}
|
|
1160
|
+
function pr(e, t) {
|
|
1161
|
+
if (!e?.length) return "";
|
|
1162
|
+
let r = 0;
|
|
1163
|
+
for (; r < e.length && Be(e[r]); ) r++;
|
|
1164
|
+
let n = "";
|
|
1165
|
+
if (r > 0) {
|
|
1166
|
+
n += "<thead>";
|
|
1167
|
+
for (let s = 0; s < r; s++) n += de(e[s], t);
|
|
1168
|
+
n += "</thead>";
|
|
1169
|
+
}
|
|
1170
|
+
if (r < e.length) {
|
|
1171
|
+
n += "<tbody>";
|
|
1172
|
+
for (let s = r; s < e.length; s++) n += de(e[s], t);
|
|
1173
|
+
n += "</tbody>";
|
|
1174
|
+
}
|
|
1175
|
+
return n;
|
|
1176
|
+
}
|
|
1177
|
+
function Je(e, t, r, n) {
|
|
1178
|
+
let s = "";
|
|
1179
|
+
for (const i of t) {
|
|
1180
|
+
const { tag: o, children: a, attrs: l } = i, c = x(e, {
|
|
1181
|
+
...l,
|
|
1182
|
+
...r
|
|
1183
|
+
});
|
|
1184
|
+
if (Ge(o)) s += `<${o}${c}>`;
|
|
1185
|
+
else {
|
|
1186
|
+
const u = a ? Je(e, a, r, n) : n;
|
|
1187
|
+
s += `<${o}${c}>${u}</${o}>`;
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
return s;
|
|
1191
|
+
}
|
|
1192
|
+
function x(e, t) {
|
|
1193
|
+
const r = Fe(e, t, {
|
|
1194
|
+
colspan: "colspan",
|
|
1195
|
+
rowspan: "rowspan"
|
|
1196
|
+
}), n = r.style, s = { ...r };
|
|
1197
|
+
return n && (s.style = je(n)), ur(s);
|
|
1198
|
+
}
|
|
1199
|
+
function qr(e) {
|
|
1200
|
+
return typeof e == "function" || typeof e == "object" && e !== null && "isAstroComponentFactory" in e;
|
|
1201
|
+
}
|
|
1202
|
+
function Br(e, t) {
|
|
1203
|
+
const r = Fe(e, t, {
|
|
1204
|
+
colspan: "colspan",
|
|
1205
|
+
rowspan: "rowspan"
|
|
1206
|
+
}), n = r?.style, s = { ...r };
|
|
1207
|
+
return n && (s.style = je(n)), s;
|
|
1208
|
+
}
|
|
1209
|
+
const oe = (e = "") => e.includes("/cdn/"), yr = (e, t = 25, r = 1) => ({
|
|
1210
|
+
...e,
|
|
1211
|
+
per_page: t,
|
|
1212
|
+
page: r
|
|
1213
|
+
}), gr = (e) => new Promise((t) => setTimeout(t, e)), mr = (e = 0, t) => Array.from({ length: e }, t), br = (e = 0, t = e) => {
|
|
1214
|
+
const r = Math.abs(t - e) || 0, n = e < t ? 1 : -1;
|
|
1215
|
+
return mr(r, (s, i) => i * n + e);
|
|
1216
|
+
}, vr = async (e, t) => Promise.all(e.map(t)), Cr = (e = [], t) => e.map(t).reduce((r, n) => [...r, ...n], []), Pe = (e) => {
|
|
1217
|
+
if (/%[0-9A-F]{2}/i.test(e)) try {
|
|
1218
|
+
return decodeURIComponent(e);
|
|
1219
|
+
} catch {
|
|
1220
|
+
return e;
|
|
1221
|
+
}
|
|
1222
|
+
return e;
|
|
1223
|
+
}, ge = (e, t, r) => {
|
|
1224
|
+
const n = [];
|
|
1225
|
+
for (const s in e) {
|
|
1226
|
+
if (!Object.prototype.hasOwnProperty.call(e, s)) continue;
|
|
1227
|
+
const i = e[s];
|
|
1228
|
+
if (i == null) continue;
|
|
1229
|
+
const o = r ? "" : encodeURIComponent(s);
|
|
1230
|
+
let a;
|
|
1231
|
+
typeof i == "object" ? a = ge(i, t ? t + encodeURIComponent(`[${o}]`) : o, Array.isArray(i)) : a = `${t ? t + encodeURIComponent(`[${o}]`) : o}=${encodeURIComponent(i)}`, n.push(a);
|
|
1232
|
+
}
|
|
1233
|
+
return n.join("&");
|
|
1234
|
+
}, Oe = (e) => {
|
|
1235
|
+
const t = {
|
|
1236
|
+
eu: "api.storyblok.com",
|
|
1237
|
+
us: "api-us.storyblok.com",
|
|
1238
|
+
cn: "app.storyblokchina.cn",
|
|
1239
|
+
ap: "api-ap.storyblok.com",
|
|
1240
|
+
ca: "api-ca.storyblok.com"
|
|
1241
|
+
};
|
|
1242
|
+
return t[e] ?? t.eu;
|
|
1243
|
+
};
|
|
1244
|
+
var kr = class {
|
|
1245
|
+
baseURL;
|
|
1246
|
+
timeout;
|
|
1247
|
+
headers;
|
|
1248
|
+
responseInterceptor;
|
|
1249
|
+
fetch;
|
|
1250
|
+
ejectInterceptor;
|
|
1251
|
+
url;
|
|
1252
|
+
parameters;
|
|
1253
|
+
fetchOptions;
|
|
1254
|
+
constructor(e) {
|
|
1255
|
+
this.baseURL = e.baseURL, this.headers = e.headers || new Headers(), this.timeout = 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 = {};
|
|
1256
|
+
}
|
|
1257
|
+
/**
|
|
1258
|
+
*
|
|
1259
|
+
* @param url string
|
|
1260
|
+
* @param params ISbStoriesParams
|
|
1261
|
+
* @returns Promise<ISbResponse | Error>
|
|
1262
|
+
*/
|
|
1263
|
+
get(e, t) {
|
|
1264
|
+
return this.url = e, this.parameters = t, this._methodHandler("get");
|
|
1265
|
+
}
|
|
1266
|
+
post(e, t) {
|
|
1267
|
+
return this.url = e, this.parameters = t, this._methodHandler("post");
|
|
1268
|
+
}
|
|
1269
|
+
put(e, t) {
|
|
1270
|
+
return this.url = e, this.parameters = t, this._methodHandler("put");
|
|
1271
|
+
}
|
|
1272
|
+
patch(e, t) {
|
|
1273
|
+
return this.url = e, this.parameters = t, this._methodHandler("patch");
|
|
1274
|
+
}
|
|
1275
|
+
delete(e, t) {
|
|
1276
|
+
return this.url = e, this.parameters = t ?? {}, this._methodHandler("delete");
|
|
1277
|
+
}
|
|
1278
|
+
async _responseHandler(e) {
|
|
1279
|
+
const t = [], r = {
|
|
1280
|
+
data: {},
|
|
1281
|
+
headers: {},
|
|
1282
|
+
status: 0,
|
|
1283
|
+
statusText: ""
|
|
1284
|
+
};
|
|
1285
|
+
e.status !== 204 && await e.json().then((n) => {
|
|
1286
|
+
r.data = n;
|
|
1287
|
+
});
|
|
1288
|
+
for (const n of e.headers.entries()) t[n[0]] = n[1];
|
|
1289
|
+
return r.headers = { ...t }, r.status = e.status, r.statusText = e.statusText, r;
|
|
1290
|
+
}
|
|
1291
|
+
async _methodHandler(e) {
|
|
1292
|
+
let t = `${this.baseURL}${this.url}`, r = null;
|
|
1293
|
+
e === "get" ? t = `${this.baseURL}${this.url}?${ge(this.parameters)}` : r = JSON.stringify(this.parameters);
|
|
1294
|
+
const n = new URL(t), s = new AbortController(), { signal: i } = s;
|
|
1295
|
+
let o = null;
|
|
1296
|
+
this.timeout && (o = setTimeout(() => s.abort(), this.timeout));
|
|
1297
|
+
try {
|
|
1298
|
+
const a = await this.fetch(`${n}`, {
|
|
1299
|
+
method: e,
|
|
1300
|
+
headers: this.headers,
|
|
1301
|
+
body: r,
|
|
1302
|
+
signal: i,
|
|
1303
|
+
...this.fetchOptions
|
|
1304
|
+
});
|
|
1305
|
+
this.timeout && o && clearTimeout(o);
|
|
1306
|
+
const l = await this._responseHandler(a);
|
|
1307
|
+
return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(l)) : this._statusHandler(l);
|
|
1308
|
+
} catch (a) {
|
|
1309
|
+
return a.name === "AbortError" ? { message: "Request timeout: The request was aborted due to timeout" } : { message: a.message || a.toString() || "An unknown error occurred" };
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
setFetchOptions(e = {}) {
|
|
1313
|
+
Object.keys(e).length > 0 && "method" in e && delete e.method, this.fetchOptions = { ...e };
|
|
1314
|
+
}
|
|
1315
|
+
eject() {
|
|
1316
|
+
this.ejectInterceptor = !0;
|
|
1317
|
+
}
|
|
1318
|
+
/**
|
|
1319
|
+
* Normalizes error messages from different response structures
|
|
1320
|
+
* @param data The response data that might contain error information
|
|
1321
|
+
* @returns A normalized error message string
|
|
1322
|
+
*/
|
|
1323
|
+
_normalizeErrorMessage(e) {
|
|
1324
|
+
if (Array.isArray(e)) return e[0] || "Unknown error";
|
|
1325
|
+
if (e && typeof e == "object") {
|
|
1326
|
+
if (e.error) return e.error;
|
|
1327
|
+
for (const t in e) {
|
|
1328
|
+
if (Array.isArray(e[t])) return `${t}: ${e[t][0]}`;
|
|
1329
|
+
if (typeof e[t] == "string") return `${t}: ${e[t]}`;
|
|
1330
|
+
}
|
|
1331
|
+
if (e.slug) return e.slug;
|
|
1332
|
+
}
|
|
1333
|
+
return "Unknown error";
|
|
1334
|
+
}
|
|
1335
|
+
_statusHandler(e) {
|
|
1336
|
+
const t = /20[0-6]/g;
|
|
1337
|
+
return new Promise((r, n) => {
|
|
1338
|
+
if (t.test(`${e.status}`)) return r(e);
|
|
1339
|
+
n({
|
|
1340
|
+
message: this._normalizeErrorMessage(e.data),
|
|
1341
|
+
status: e.status,
|
|
1342
|
+
response: e
|
|
1343
|
+
});
|
|
1344
|
+
});
|
|
1345
|
+
}
|
|
1346
|
+
};
|
|
1347
|
+
const Ar = {
|
|
1348
|
+
PUBLISHED: "published"
|
|
1349
|
+
}, _r = 25, ae = {
|
|
1350
|
+
SMALL: 25,
|
|
1351
|
+
MEDIUM: 50,
|
|
1352
|
+
LARGE: 75
|
|
1353
|
+
}, M = {
|
|
1354
|
+
SINGLE_OR_SMALL: 50,
|
|
1355
|
+
MEDIUM: 15,
|
|
1356
|
+
LARGE: 10,
|
|
1357
|
+
VERY_LARGE: 6
|
|
1358
|
+
}, Ie = 1e3, O = 3;
|
|
1359
|
+
function wr(e, t) {
|
|
1360
|
+
const r = e.includes("/cdn/stories/"), n = e.split("/").length > 3 && !e.endsWith("/cdn/stories"), s = "find_by" in t;
|
|
1361
|
+
return r && n || s;
|
|
1362
|
+
}
|
|
1363
|
+
function Sr(e) {
|
|
1364
|
+
return e <= ae.SMALL ? M.SINGLE_OR_SMALL : e <= ae.MEDIUM ? M.MEDIUM : e <= ae.LARGE ? M.LARGE : M.VERY_LARGE;
|
|
1365
|
+
}
|
|
1366
|
+
function I(e, t, r = {}, n) {
|
|
1367
|
+
return r.userRateLimit !== void 0 ? Math.min(r.userRateLimit, Ie) : r.serverHeadersRateLimit !== void 0 ? Math.min(r.serverHeadersRateLimit, Ie) : n !== void 0 ? n : !e || !t || wr(e, t) ? M.SINGLE_OR_SMALL : Sr(t.per_page || _r);
|
|
1368
|
+
}
|
|
1369
|
+
function Tr(e) {
|
|
1370
|
+
if (!e) return null;
|
|
1371
|
+
const t = e["x-ratelimit"] || e["X-RateLimit"], r = e["x-ratelimit-policy"] || e["X-RateLimit-Policy"];
|
|
1372
|
+
if (!t && !r) return null;
|
|
1373
|
+
const n = {};
|
|
1374
|
+
if (t) {
|
|
1375
|
+
const s = t.match(/r=(\d+)/);
|
|
1376
|
+
s && (n.remaining = Number.parseInt(s[1], 10));
|
|
1377
|
+
}
|
|
1378
|
+
if (r) {
|
|
1379
|
+
const s = r.match(/q=(\d+)/);
|
|
1380
|
+
s && (n.max = Number.parseInt(s[1], 10));
|
|
1381
|
+
}
|
|
1382
|
+
return Object.keys(n).length > 0 ? n : null;
|
|
1383
|
+
}
|
|
1384
|
+
function Rr(e, t = !1) {
|
|
1385
|
+
return {
|
|
1386
|
+
userRateLimit: e,
|
|
1387
|
+
serverHeadersRateLimit: void 0,
|
|
1388
|
+
isManagementApi: t
|
|
1389
|
+
};
|
|
1390
|
+
}
|
|
1391
|
+
var Lr = class extends Error {
|
|
1392
|
+
constructor(e) {
|
|
1393
|
+
super(e), this.name = "AbortError";
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
function Er(e, t, r) {
|
|
1397
|
+
if (!Number.isFinite(t)) throw new TypeError("Expected `limit` to be a finite number");
|
|
1398
|
+
if (!Number.isFinite(r)) throw new TypeError("Expected `interval` to be a finite number");
|
|
1399
|
+
const n = [];
|
|
1400
|
+
let s = [], i = 0, o = !1;
|
|
1401
|
+
const a = async () => {
|
|
1402
|
+
i++;
|
|
1403
|
+
const c = n.shift();
|
|
1404
|
+
if (c) try {
|
|
1405
|
+
const h = await e(...c.args);
|
|
1406
|
+
c.resolve(h);
|
|
1407
|
+
} catch (h) {
|
|
1408
|
+
c.reject(h);
|
|
1409
|
+
}
|
|
1410
|
+
const u = setTimeout(() => {
|
|
1411
|
+
i--, n.length > 0 && a(), s = s.filter((h) => h !== u);
|
|
1412
|
+
}, r);
|
|
1413
|
+
s.includes(u) || s.push(u);
|
|
1414
|
+
}, l = (...c) => o ? Promise.reject(/* @__PURE__ */ new Error("Throttled function is already aborted and not accepting new promises")) : new Promise((u, h) => {
|
|
1415
|
+
n.push({
|
|
1416
|
+
resolve: u,
|
|
1417
|
+
reject: h,
|
|
1418
|
+
args: c
|
|
1419
|
+
}), i < t && a();
|
|
1420
|
+
});
|
|
1421
|
+
return l.abort = () => {
|
|
1422
|
+
o = !0, s.forEach(clearTimeout), s = [], n.forEach((c) => c.reject(() => new Lr("Throttle function aborted"))), n.length = 0;
|
|
1423
|
+
}, l;
|
|
1424
|
+
}
|
|
1425
|
+
var $r = class {
|
|
1426
|
+
queues;
|
|
1427
|
+
interval;
|
|
1428
|
+
throttledRequestFn;
|
|
1429
|
+
constructor(e, t = 1e3) {
|
|
1430
|
+
this.queues = /* @__PURE__ */ new Map(), this.interval = t, this.throttledRequestFn = e;
|
|
1431
|
+
}
|
|
1432
|
+
/**
|
|
1433
|
+
* Gets or creates a throttle queue for the specified rate limit
|
|
1434
|
+
*/
|
|
1435
|
+
getQueue(e) {
|
|
1436
|
+
let t = this.queues.get(e);
|
|
1437
|
+
return t || (t = Er(this.throttledRequestFn, e, this.interval), this.queues.set(e, t)), t;
|
|
1438
|
+
}
|
|
1439
|
+
/**
|
|
1440
|
+
* Executes a request through the appropriate throttle queue based on rate limit
|
|
1441
|
+
*/
|
|
1442
|
+
execute(e, ...t) {
|
|
1443
|
+
return this.getQueue(e)(...t);
|
|
1444
|
+
}
|
|
1445
|
+
/**
|
|
1446
|
+
* Aborts all throttle queues
|
|
1447
|
+
*/
|
|
1448
|
+
abortAll() {
|
|
1449
|
+
this.queues.forEach((e) => {
|
|
1450
|
+
e.abort?.();
|
|
1451
|
+
}), this.queues.clear();
|
|
1452
|
+
}
|
|
1453
|
+
/**
|
|
1454
|
+
* Gets the number of active queues
|
|
1455
|
+
*/
|
|
1456
|
+
getQueueCount() {
|
|
1457
|
+
return this.queues.size;
|
|
1458
|
+
}
|
|
1459
|
+
};
|
|
1460
|
+
let G = {};
|
|
1461
|
+
const S = {};
|
|
1462
|
+
var Mr = class {
|
|
1463
|
+
client;
|
|
1464
|
+
maxRetries;
|
|
1465
|
+
retriesDelay;
|
|
1466
|
+
throttleManager;
|
|
1467
|
+
accessToken;
|
|
1468
|
+
cache;
|
|
1469
|
+
resolveCounter;
|
|
1470
|
+
relations;
|
|
1471
|
+
links;
|
|
1472
|
+
version;
|
|
1473
|
+
rateLimitConfig;
|
|
1474
|
+
cvMode;
|
|
1475
|
+
/**
|
|
1476
|
+
* @deprecated This property is deprecated. Use the standalone `richTextResolver` from `@storyblok/richtext` instead.
|
|
1477
|
+
* @see https://github.com/storyblok/richtext
|
|
1478
|
+
*/
|
|
1479
|
+
richTextResolver;
|
|
1480
|
+
resolveNestedRelations;
|
|
1481
|
+
stringifiedStoriesCache;
|
|
1482
|
+
inlineAssets;
|
|
1483
|
+
/**
|
|
1484
|
+
*
|
|
1485
|
+
* @param config ISbConfig interface
|
|
1486
|
+
* @param pEndpoint string, optional
|
|
1487
|
+
*/
|
|
1488
|
+
constructor(e, t) {
|
|
1489
|
+
let r = e.endpoint || t;
|
|
1490
|
+
if (!r) {
|
|
1491
|
+
const s = e.https === !1 ? "http" : "https";
|
|
1492
|
+
e.oauthToken ? r = `${s}://${Oe(e.region)}/v1` : r = `${s}://${Oe(e.region)}/v2`;
|
|
1493
|
+
}
|
|
1494
|
+
const n = new Headers();
|
|
1495
|
+
!e.oauthToken && typeof window < "u" || n.set("Content-Type", "application/json"), n.set("Accept", "application/json"), e.headers && (e.headers.constructor.name === "Headers" ? e.headers.entries().toArray() : Object.entries(e.headers)).forEach(([s, i]) => {
|
|
1496
|
+
n.set(s, i);
|
|
1497
|
+
}), e.oauthToken && n.set("Authorization", e.oauthToken), this.rateLimitConfig = Rr(e.rateLimit, !!e.oauthToken), this.maxRetries = e.maxRetries || 10, this.retriesDelay = e.retriesDelay ?? 300, this.throttleManager = new $r(this.throttledRequest.bind(this), 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.cvMode = e.cache?.cv ?? "auto", this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.version = e.version || Ar.PUBLISHED, this.inlineAssets = e.inlineAssets || !1, this.client = new kr({
|
|
1498
|
+
baseURL: r,
|
|
1499
|
+
timeout: e.timeout || 0,
|
|
1500
|
+
headers: n,
|
|
1501
|
+
responseInterceptor: e.responseInterceptor,
|
|
1502
|
+
fetch: e.fetch
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
parseParams(e) {
|
|
1506
|
+
return e.token || (e.token = this.getToken()), !e.cv && this.cvMode === "auto" && (e.cv = S[e.token]), Array.isArray(e.resolve_relations) ? e.resolve_relations = e.resolve_relations.map(Pe).join(",") : typeof e.resolve_relations == "string" && (e.resolve_relations = Pe(e.resolve_relations)), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
|
|
1507
|
+
}
|
|
1508
|
+
factoryParamOptions(e, t) {
|
|
1509
|
+
return oe(e) ? this.parseParams(t) : t;
|
|
1510
|
+
}
|
|
1511
|
+
makeRequest(e, t, r, n, s) {
|
|
1512
|
+
const i = this.factoryParamOptions(e, yr(t, r, n));
|
|
1513
|
+
return this.cacheResponse(e, i, void 0, s);
|
|
1514
|
+
}
|
|
1515
|
+
get(e, t = {}, r) {
|
|
1516
|
+
t || (t = {});
|
|
1517
|
+
const n = `/${e}`;
|
|
1518
|
+
oe(n) && (t.version = t.version || this.version);
|
|
1519
|
+
const s = this.factoryParamOptions(n, t);
|
|
1520
|
+
return this.cacheResponse(n, s, void 0, r);
|
|
1521
|
+
}
|
|
1522
|
+
async getAll(e, t = {}, r, n) {
|
|
1523
|
+
const s = t?.per_page || 25, i = `/${e}`.replace(/\/$/, ""), o = r ?? i.substring(i.lastIndexOf("/") + 1);
|
|
1524
|
+
t.version = t.version || this.version;
|
|
1525
|
+
const a = 1, l = await this.makeRequest(i, t, s, a, n);
|
|
1526
|
+
return Cr([l, ...await vr(br(a, l.total ? Math.ceil(l.total / (l.perPage || s)) : 1), (c) => this.makeRequest(i, t, s, c + 1, n))], (c) => Object.values(c.data[o]));
|
|
1527
|
+
}
|
|
1528
|
+
post(e, t = {}, r) {
|
|
1529
|
+
const n = `/${e}`, s = I(void 0, void 0, this.rateLimitConfig, O);
|
|
1530
|
+
return this.throttleManager.execute(s, "post", n, t, r);
|
|
1531
|
+
}
|
|
1532
|
+
put(e, t = {}, r) {
|
|
1533
|
+
const n = `/${e}`, s = I(void 0, void 0, this.rateLimitConfig, O);
|
|
1534
|
+
return this.throttleManager.execute(s, "put", n, t, r);
|
|
1535
|
+
}
|
|
1536
|
+
patch(e, t = {}, r) {
|
|
1537
|
+
const n = `/${e}`, s = I(void 0, void 0, this.rateLimitConfig, O);
|
|
1538
|
+
return this.throttleManager.execute(s, "patch", n, t, r);
|
|
1539
|
+
}
|
|
1540
|
+
delete(e, t = {}, r) {
|
|
1541
|
+
t || (t = {});
|
|
1542
|
+
const n = `/${e}`, s = I(void 0, void 0, this.rateLimitConfig, O);
|
|
1543
|
+
return this.throttleManager.execute(s, "delete", n, t, r);
|
|
1544
|
+
}
|
|
1545
|
+
getStories(e = {}, t) {
|
|
1546
|
+
return this._addResolveLevel(e), this.get("cdn/stories", e, t);
|
|
1547
|
+
}
|
|
1548
|
+
getStory(e, t = {}, r) {
|
|
1549
|
+
return this._addResolveLevel(t), this.get(`cdn/stories/${e}`, t, r);
|
|
1550
|
+
}
|
|
1551
|
+
getToken() {
|
|
1552
|
+
return this.accessToken;
|
|
1553
|
+
}
|
|
1554
|
+
ejectInterceptor() {
|
|
1555
|
+
this.client.eject();
|
|
1556
|
+
}
|
|
1557
|
+
_addResolveLevel(e) {
|
|
1558
|
+
typeof e.resolve_relations < "u" && (e.resolve_level = 2);
|
|
1559
|
+
}
|
|
1560
|
+
_cleanCopy(e) {
|
|
1561
|
+
return JSON.parse(JSON.stringify(e));
|
|
1562
|
+
}
|
|
1563
|
+
_insertLinks(e, t, r) {
|
|
1564
|
+
const n = e[t];
|
|
1565
|
+
n && n.fieldtype === "multilink" && n.linktype === "story" && typeof n.id == "string" && this.links[r][n.id] ? n.story = this._cleanCopy(this.links[r][n.id]) : n && n.linktype === "story" && typeof n.uuid == "string" && this.links[r][n.uuid] && (n.story = this._cleanCopy(this.links[r][n.uuid]));
|
|
1566
|
+
}
|
|
1567
|
+
/**
|
|
1568
|
+
*
|
|
1569
|
+
* @param resolveId A counter number as a string
|
|
1570
|
+
* @param uuid The uuid of the story
|
|
1571
|
+
* @returns string | object
|
|
1572
|
+
*/
|
|
1573
|
+
getStoryReference(e, t) {
|
|
1574
|
+
return this.relations[e][t] ? JSON.parse(this.stringifiedStoriesCache[t] || JSON.stringify(this.relations[e][t])) : t;
|
|
1575
|
+
}
|
|
1576
|
+
/**
|
|
1577
|
+
* Resolves a field's value by replacing UUIDs with their corresponding story references
|
|
1578
|
+
* @param jtree - The JSON tree object containing the field to resolve
|
|
1579
|
+
* @param treeItem - The key of the field to resolve
|
|
1580
|
+
* @param resolveId - The unique identifier for the current resolution context
|
|
1581
|
+
*
|
|
1582
|
+
* This method handles both single string UUIDs and arrays of UUIDs:
|
|
1583
|
+
* - For single strings: directly replaces the UUID with the story reference
|
|
1584
|
+
* - For arrays: maps through each UUID and replaces with corresponding story references
|
|
1585
|
+
*/
|
|
1586
|
+
_resolveField(e, t, r) {
|
|
1587
|
+
const n = e[t];
|
|
1588
|
+
typeof n == "string" ? e[t] = this.getStoryReference(r, n) : Array.isArray(n) && (e[t] = n.map((s) => this.getStoryReference(r, s)).filter(Boolean));
|
|
1589
|
+
}
|
|
1590
|
+
/**
|
|
1591
|
+
* Inserts relations into the JSON tree by resolving references
|
|
1592
|
+
* @param jtree - The JSON tree object to process
|
|
1593
|
+
* @param treeItem - The current field being processed
|
|
1594
|
+
* @param fields - The relation patterns to resolve (string or array of strings)
|
|
1595
|
+
* @param resolveId - The unique identifier for the current resolution context
|
|
1596
|
+
*
|
|
1597
|
+
* This method handles two types of relation patterns:
|
|
1598
|
+
* 1. Nested relations: matches fields that end with the current field name
|
|
1599
|
+
* Example: If treeItem is "event_type", it matches patterns like "*.event_type"
|
|
1600
|
+
*
|
|
1601
|
+
* 2. Direct component relations: matches exact component.field patterns
|
|
1602
|
+
* Example: "event.event_type" for component "event" and field "event_type"
|
|
1603
|
+
*
|
|
1604
|
+
* The method supports both string and array formats for the fields parameter,
|
|
1605
|
+
* allowing flexible specification of relation patterns.
|
|
1606
|
+
*/
|
|
1607
|
+
_insertRelations(e, t, r, n) {
|
|
1608
|
+
if (Array.isArray(r) ? r.find((i) => i.endsWith(`.${t}`)) : r.endsWith(`.${t}`)) {
|
|
1609
|
+
this._resolveField(e, t, n);
|
|
1610
|
+
return;
|
|
1611
|
+
}
|
|
1612
|
+
const s = e.component ? `${e.component}.${t}` : t;
|
|
1613
|
+
(Array.isArray(r) ? r.includes(s) : r === s) && this._resolveField(e, t, n);
|
|
1614
|
+
}
|
|
1615
|
+
/**
|
|
1616
|
+
* Recursively traverses and resolves relations in the story content tree
|
|
1617
|
+
* @param story - The story object containing the content to process
|
|
1618
|
+
* @param fields - The relation patterns to resolve
|
|
1619
|
+
* @param resolveId - The unique identifier for the current resolution context
|
|
1620
|
+
*/
|
|
1621
|
+
iterateTree(e, t, r) {
|
|
1622
|
+
const n = (s, i = "") => {
|
|
1623
|
+
if (!(!s || s._stopResolving)) {
|
|
1624
|
+
if (Array.isArray(s)) s.forEach((o, a) => n(o, `${i}[${a}]`));
|
|
1625
|
+
else if (typeof s == "object") for (const o in s) {
|
|
1626
|
+
const a = i ? `${i}.${o}` : o;
|
|
1627
|
+
(s.component && s._uid || s.type === "link") && (this._insertRelations(s, o, t, r), this._insertLinks(s, o, r)), n(s[o], a);
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
};
|
|
1631
|
+
n(e.content);
|
|
1632
|
+
}
|
|
1633
|
+
async resolveLinks(e, t, r) {
|
|
1634
|
+
let n = [];
|
|
1635
|
+
if (e.link_uuids) {
|
|
1636
|
+
const s = e.link_uuids.length, i = [], o = 50;
|
|
1637
|
+
for (let a = 0; a < s; a += o) {
|
|
1638
|
+
const l = Math.min(s, a + o);
|
|
1639
|
+
i.push(e.link_uuids.slice(a, l));
|
|
1640
|
+
}
|
|
1641
|
+
for (let a = 0; a < i.length; a++) (await this.getStories({
|
|
1642
|
+
per_page: o,
|
|
1643
|
+
language: t.language,
|
|
1644
|
+
version: t.version,
|
|
1645
|
+
starts_with: t.starts_with,
|
|
1646
|
+
by_uuids: i[a].join(",")
|
|
1647
|
+
})).data.stories.forEach((l) => {
|
|
1648
|
+
n.push(l);
|
|
1649
|
+
});
|
|
1650
|
+
} else n = e.links;
|
|
1651
|
+
n.forEach((s) => {
|
|
1652
|
+
this.links[r][s.uuid] = {
|
|
1653
|
+
...s,
|
|
1654
|
+
_stopResolving: !0
|
|
1655
|
+
};
|
|
1656
|
+
});
|
|
1657
|
+
}
|
|
1658
|
+
async resolveRelations(e, t, r) {
|
|
1659
|
+
let n = [];
|
|
1660
|
+
if (e.rel_uuids) {
|
|
1661
|
+
const s = e.rel_uuids.length, i = [], o = 50;
|
|
1662
|
+
for (let a = 0; a < s; a += o) {
|
|
1663
|
+
const l = Math.min(s, a + o);
|
|
1664
|
+
i.push(e.rel_uuids.slice(a, l));
|
|
1665
|
+
}
|
|
1666
|
+
for (let a = 0; a < i.length; a++) (await this.getStories({
|
|
1667
|
+
per_page: o,
|
|
1668
|
+
language: t.language,
|
|
1669
|
+
version: t.version,
|
|
1670
|
+
starts_with: t.starts_with,
|
|
1671
|
+
by_uuids: i[a].join(","),
|
|
1672
|
+
excluding_fields: t.excluding_fields
|
|
1673
|
+
})).data.stories.forEach((l) => {
|
|
1674
|
+
n.push(l);
|
|
1675
|
+
});
|
|
1676
|
+
n.length > 0 && (e.rels = n, delete e.rel_uuids);
|
|
1677
|
+
} else n = e.rels;
|
|
1678
|
+
n && n.length > 0 && n.forEach((s) => {
|
|
1679
|
+
this.relations[r][s.uuid] = {
|
|
1680
|
+
...s,
|
|
1681
|
+
_stopResolving: !0
|
|
1682
|
+
};
|
|
1683
|
+
});
|
|
1684
|
+
}
|
|
1685
|
+
/**
|
|
1686
|
+
*
|
|
1687
|
+
* @param responseData
|
|
1688
|
+
* @param params
|
|
1689
|
+
* @param resolveId
|
|
1690
|
+
* @description Resolves the relations and links of the stories
|
|
1691
|
+
* @returns Promise<void>
|
|
1692
|
+
*
|
|
1693
|
+
*/
|
|
1694
|
+
async resolveStories(e, t, r) {
|
|
1695
|
+
let n = [];
|
|
1696
|
+
if (this.links[r] = {}, this.relations[r] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (n = t.resolve_relations.split(",")), await this.resolveRelations(e, t, r)), t.resolve_links && [
|
|
1697
|
+
"1",
|
|
1698
|
+
"story",
|
|
1699
|
+
"url",
|
|
1700
|
+
"link"
|
|
1701
|
+
].includes(t.resolve_links) && (e.links?.length || e.link_uuids?.length) && await this.resolveLinks(e, t, r), this.resolveNestedRelations) for (const s in this.relations[r]) this.iterateTree(this.relations[r][s], n, r);
|
|
1702
|
+
e.story ? this.iterateTree(e.story, n, r) : e.stories.forEach((s) => {
|
|
1703
|
+
this.iterateTree(s, n, r);
|
|
1704
|
+
}), this.stringifiedStoriesCache = {}, delete this.links[r], delete this.relations[r];
|
|
1705
|
+
}
|
|
1706
|
+
async cacheResponse(e, t, r, n) {
|
|
1707
|
+
const s = ge({
|
|
1708
|
+
url: e,
|
|
1709
|
+
params: t
|
|
1710
|
+
}), i = this.cacheProvider();
|
|
1711
|
+
if (t.version === "published" && e !== "/cdn/spaces/me") {
|
|
1712
|
+
const l = await i.get(s);
|
|
1713
|
+
if (l) return Promise.resolve(l);
|
|
1714
|
+
}
|
|
1715
|
+
const o = !oe(e) && this.rateLimitConfig.isManagementApi ? O : void 0, a = I(e, t, this.rateLimitConfig, o);
|
|
1716
|
+
return new Promise(async (l, c) => {
|
|
1717
|
+
try {
|
|
1718
|
+
const u = await this.throttleManager.execute(a, "get", e, t, n);
|
|
1719
|
+
if (u.status !== 200) return c(u);
|
|
1720
|
+
let h = {
|
|
1721
|
+
data: u.data,
|
|
1722
|
+
headers: u.headers
|
|
1723
|
+
};
|
|
1724
|
+
const v = Tr(u.headers);
|
|
1725
|
+
if (v?.max !== void 0 && (this.rateLimitConfig.serverHeadersRateLimit = v.max), u.headers?.["per-page"] && (h = Object.assign({}, h, {
|
|
1726
|
+
perPage: u.headers["per-page"] ? Number.parseInt(u.headers["per-page"]) : 0,
|
|
1727
|
+
total: u.headers["per-page"] ? Number.parseInt(u.headers.total) : 0
|
|
1728
|
+
})), h.data.story || h.data.stories) {
|
|
1729
|
+
const C = this.resolveCounter = ++this.resolveCounter % 1e3;
|
|
1730
|
+
await this.resolveStories(h.data, t, `${C}`), h = await this.processInlineAssets(h);
|
|
1731
|
+
}
|
|
1732
|
+
t.version === "published" && e !== "/cdn/spaces/me" && await i.set(s, h);
|
|
1733
|
+
const T = this.cache.clear === "onpreview" && t.version === "draft" || this.cache.clear === "auto";
|
|
1734
|
+
return t.token && h.data.cv && (T && S[t.token] && S[t.token] !== h.data.cv && await this.flushCache(), S[t.token] = h.data.cv), l(h);
|
|
1735
|
+
} catch (u) {
|
|
1736
|
+
if (u.response && u.status === 429 && (r = typeof r > "u" ? 0 : r + 1, r < this.maxRetries))
|
|
1737
|
+
return console.log(`Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`), await gr(this.retriesDelay), this.cacheResponse(e, t, r).then(l).catch(c);
|
|
1738
|
+
c(u);
|
|
1739
|
+
}
|
|
1740
|
+
});
|
|
1741
|
+
}
|
|
1742
|
+
throttledRequest(e, t, r, n) {
|
|
1743
|
+
return this.client.setFetchOptions(n), this.client[e](t, r);
|
|
1744
|
+
}
|
|
1745
|
+
cacheVersions() {
|
|
1746
|
+
return S;
|
|
1747
|
+
}
|
|
1748
|
+
cacheVersion() {
|
|
1749
|
+
return S[this.accessToken];
|
|
1750
|
+
}
|
|
1751
|
+
setCacheVersion(e) {
|
|
1752
|
+
this.accessToken && (S[this.accessToken] = e);
|
|
1753
|
+
}
|
|
1754
|
+
clearCacheVersion() {
|
|
1755
|
+
this.accessToken && (S[this.accessToken] = 0);
|
|
1756
|
+
}
|
|
1757
|
+
cacheProvider() {
|
|
1758
|
+
switch (this.cache.type) {
|
|
1759
|
+
case "memory":
|
|
1760
|
+
return {
|
|
1761
|
+
get(e) {
|
|
1762
|
+
return Promise.resolve(G[e]);
|
|
1763
|
+
},
|
|
1764
|
+
getAll() {
|
|
1765
|
+
return Promise.resolve(G);
|
|
1766
|
+
},
|
|
1767
|
+
set(e, t) {
|
|
1768
|
+
return G[e] = t, Promise.resolve(void 0);
|
|
1769
|
+
},
|
|
1770
|
+
flush() {
|
|
1771
|
+
return G = {}, Promise.resolve(void 0);
|
|
1772
|
+
}
|
|
1773
|
+
};
|
|
1774
|
+
case "custom":
|
|
1775
|
+
if (this.cache.custom) return this.cache.custom;
|
|
1776
|
+
default:
|
|
1777
|
+
return {
|
|
1778
|
+
get() {
|
|
1779
|
+
return Promise.resolve();
|
|
1780
|
+
},
|
|
1781
|
+
getAll() {
|
|
1782
|
+
return Promise.resolve(void 0);
|
|
1783
|
+
},
|
|
1784
|
+
set() {
|
|
1785
|
+
return Promise.resolve(void 0);
|
|
1786
|
+
},
|
|
1787
|
+
flush() {
|
|
1788
|
+
return Promise.resolve(void 0);
|
|
1789
|
+
}
|
|
1790
|
+
};
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
async flushCache() {
|
|
1794
|
+
return await this.cacheProvider().flush(), this.clearCacheVersion(), this;
|
|
1795
|
+
}
|
|
1796
|
+
async processInlineAssets(e) {
|
|
1797
|
+
if (!this.inlineAssets) return e;
|
|
1798
|
+
const t = (r) => {
|
|
1799
|
+
if (!r || typeof r != "object") return r;
|
|
1800
|
+
if (Array.isArray(r)) return r.map((s) => t(s));
|
|
1801
|
+
let n = { ...r };
|
|
1802
|
+
n.fieldtype === "asset" && Array.isArray(e.data.assets) && (n = {
|
|
1803
|
+
...e.data.assets.find((s) => s.id === n.id),
|
|
1804
|
+
...n
|
|
1805
|
+
});
|
|
1806
|
+
for (const s in n) typeof n[s] == "object" && (n[s] = t(n[s]));
|
|
1807
|
+
return n;
|
|
1808
|
+
};
|
|
1809
|
+
return e.data.story && (e.data.story.content = t(e.data.story.content)), e.data.stories && (e.data.stories = e.data.stories.map((r) => (r.content = t(r.content), r))), e;
|
|
1810
|
+
}
|
|
1811
|
+
};
|
|
1812
|
+
let Ne = !1;
|
|
1813
|
+
const xe = [], We = (e) => new Promise((t, r) => {
|
|
1814
|
+
if (typeof window > "u") {
|
|
1815
|
+
r(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));
|
|
1816
|
+
return;
|
|
1817
|
+
}
|
|
1818
|
+
if (window.storyblokRegisterEvent = (s) => {
|
|
1819
|
+
if (!window.location.search.includes("_storyblok")) {
|
|
1820
|
+
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
1821
|
+
return;
|
|
1822
|
+
}
|
|
1823
|
+
Ne ? s() : xe.push(s);
|
|
1824
|
+
}, document.getElementById("storyblok-javascript-bridge")) {
|
|
1825
|
+
t(void 0);
|
|
1826
|
+
return;
|
|
1827
|
+
}
|
|
1828
|
+
const n = document.createElement("script");
|
|
1829
|
+
n.async = !0, n.src = e, n.id = "storyblok-javascript-bridge", n.onerror = (s) => r(s), n.onload = (s) => {
|
|
1830
|
+
xe.forEach((i) => i()), Ne = !0, t(s);
|
|
1831
|
+
}, document.getElementsByTagName("head")[0].appendChild(n);
|
|
1832
|
+
}), zr = (e = {}) => {
|
|
1833
|
+
const { apiOptions: t } = e;
|
|
1834
|
+
if (!t || !t.accessToken) {
|
|
1835
|
+
console.error(
|
|
1836
|
+
"You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication"
|
|
1837
|
+
);
|
|
1838
|
+
return;
|
|
1839
|
+
}
|
|
1840
|
+
return { storyblokApi: new Mr(t) };
|
|
1841
|
+
}, Gr = (e) => {
|
|
1842
|
+
if (typeof e != "object" || typeof e._editable > "u")
|
|
1843
|
+
return {};
|
|
1844
|
+
try {
|
|
1845
|
+
const t = JSON.parse(
|
|
1846
|
+
e._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
|
|
1847
|
+
);
|
|
1848
|
+
return t ? {
|
|
1849
|
+
"data-blok-c": JSON.stringify(t),
|
|
1850
|
+
"data-blok-uid": `${t.id}-${t.uid}`
|
|
1851
|
+
} : {};
|
|
1852
|
+
} catch {
|
|
1853
|
+
return {};
|
|
1854
|
+
}
|
|
1855
|
+
};
|
|
1856
|
+
let he = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
|
1857
|
+
const Zr = (e = {}) => {
|
|
1858
|
+
var t, r;
|
|
1859
|
+
const {
|
|
1860
|
+
bridge: n,
|
|
1861
|
+
accessToken: s,
|
|
1862
|
+
use: i = [],
|
|
1863
|
+
apiOptions: o = {},
|
|
1864
|
+
bridgeUrl: a
|
|
1865
|
+
} = e;
|
|
1866
|
+
o.accessToken = o.accessToken || s;
|
|
1867
|
+
const l = { bridge: n, apiOptions: o };
|
|
1868
|
+
let c = {};
|
|
1869
|
+
i.forEach((h) => {
|
|
1870
|
+
c = { ...c, ...h(l) };
|
|
1871
|
+
}), a && (he = a);
|
|
1872
|
+
const u = !(typeof window > "u") && ((r = (t = window.location) == null ? void 0 : t.search) == null ? void 0 : r.includes("_storyblok_tk"));
|
|
1873
|
+
return n !== !1 && u && We(he), c;
|
|
1874
|
+
}, Kr = () => We(he);
|
|
1875
|
+
export {
|
|
1876
|
+
zr as apiPlugin,
|
|
1877
|
+
ur as attrsToHtmlString,
|
|
1878
|
+
Br as buildAstroAttrs,
|
|
1879
|
+
Bt as buildStoryblokImage,
|
|
1880
|
+
Vr as getInnerMarks,
|
|
1881
|
+
Or as getLiveStory,
|
|
1882
|
+
Ir as getPayload,
|
|
1883
|
+
cr as getStaticChildren,
|
|
1884
|
+
Dr as groupLinkNodes,
|
|
1885
|
+
Hr as handleStoryblokMessage,
|
|
1886
|
+
Ur as isEditorRequest,
|
|
1887
|
+
Ge as isSelfClosing,
|
|
1888
|
+
qr as isValidAstroComponent,
|
|
1889
|
+
Kr as loadStoryblokBridge,
|
|
1890
|
+
lr as normalizeNodes,
|
|
1891
|
+
Fe as processAttrs,
|
|
1892
|
+
Fr as renderRichText,
|
|
1893
|
+
ye as resolveTag,
|
|
1894
|
+
xr as sanitizeJSON,
|
|
1895
|
+
jr as splitTableRows,
|
|
1896
|
+
Nr as storyblok,
|
|
1897
|
+
Gr as storyblokEditable,
|
|
1898
|
+
Zr as storyblokInit,
|
|
1899
|
+
je as styleToString,
|
|
1900
|
+
dt as toCamelCase,
|
|
1901
|
+
Pr as useStoryblokApi
|
|
1902
|
+
};
|