@storyblok/astro 6.1.0-alpha.1 → 6.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/dist/components/StoryblokComponent.astro +6 -9
- package/dist/content-loader/storyblokLoader.d.ts +5 -1
- package/dist/index.d.ts +1 -0
- package/dist/storyblok-astro.es.js +190 -186
- package/dist/storyblok-astro.umd.js +6 -6
- package/dist/vite-plugins/vite-plugin-storyblok-options.d.ts +2 -1
- package/package.json +1 -1
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
---
|
|
2
|
-
import components from
|
|
3
|
-
import options from
|
|
4
|
-
import { toCamelCase } from
|
|
5
|
-
import type { SbBlokData } from
|
|
6
|
-
import type { AstroComponentFactory } from
|
|
2
|
+
import components from 'virtual:storyblok-components';
|
|
3
|
+
import options from 'virtual:storyblok-options';
|
|
4
|
+
import { toCamelCase } from '@storyblok/astro';
|
|
5
|
+
import type { SbBlokData } from '@storyblok/js';
|
|
6
|
+
import type { AstroComponentFactory } from 'astro/runtime/server/index.js';
|
|
7
7
|
|
|
8
8
|
export interface Props {
|
|
9
9
|
blok: SbBlokData;
|
|
10
10
|
[prop: string]: unknown;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
12
|
const { blok, ...props } = Astro.props;
|
|
14
13
|
|
|
15
14
|
if (!blok) {
|
|
@@ -24,16 +23,14 @@ if (!blok) {
|
|
|
24
23
|
let key = toCamelCase(blok.component as string);
|
|
25
24
|
|
|
26
25
|
const componentFound: boolean = key in components;
|
|
27
|
-
|
|
28
26
|
let Component: AstroComponentFactory;
|
|
29
|
-
|
|
30
27
|
if (!componentFound) {
|
|
31
28
|
if (!options.enableFallbackComponent)
|
|
32
29
|
throw new Error(
|
|
33
30
|
`Component could not be found for blok "${blok.component}"! Is it defined in astro.config.mjs?`
|
|
34
31
|
);
|
|
35
32
|
else {
|
|
36
|
-
Component = components[
|
|
33
|
+
Component = components['FallbackComponent'];
|
|
37
34
|
}
|
|
38
35
|
} else {
|
|
39
36
|
Component = components[key];
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { Loader } from 'astro/loaders';
|
|
2
|
+
import { ISbConfig, ISbStoriesParams } from '@storyblok/js';
|
|
2
3
|
interface StoryblokLoaderConfig {
|
|
3
|
-
|
|
4
|
+
accessToken: string;
|
|
4
5
|
version: 'draft' | 'published';
|
|
6
|
+
useCustomApi?: boolean;
|
|
7
|
+
apiOptions?: ISbConfig;
|
|
8
|
+
storiesParams?: ISbStoriesParams;
|
|
5
9
|
}
|
|
6
10
|
export declare function storyblokLoader(config: StoryblokLoaderConfig): Loader;
|
|
7
11
|
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { default as storyblokIntegration } from './lib/storyblok-integration';
|
|
2
2
|
export { storyblokLoader } from './content-loader/storyblokLoader';
|
|
3
3
|
export { getLiveStory, renderRichText, useStoryblokApi } from './lib/helpers';
|
|
4
|
+
export type { IntegrationOptions } from './lib/storyblok-integration';
|
|
4
5
|
export { handleStoryblokMessage } from './live-preview/handleStoryblokMessage';
|
|
5
6
|
export * from './types';
|
|
6
7
|
export { toCamelCase } from './utils/toCamelCase';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const V = `<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">
|
|
2
2
|
<g id="storyblok-logo-kit" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
3
3
|
<g id="storyblok-partner-logo" transform="translate(-59.000000, -169.000000)" fill-rule="nonzero">
|
|
4
4
|
<g id="storyblok-symbol" transform="translate(59.000000, 169.000000)">
|
|
@@ -7,15 +7,15 @@ const B = `<svg width="45px" height="53px" viewBox="0 0 45 53" version="1.1" xml
|
|
|
7
7
|
</g>
|
|
8
8
|
</g>
|
|
9
9
|
</g>
|
|
10
|
-
</svg>`,
|
|
10
|
+
</svg>`, J = /[\p{Lu}]/u, W = /[\p{Ll}]/u, x = /^[\p{Lu}](?![\p{Lu}])/gu, B = /([\p{Alpha}\p{N}_]|$)/u, L = /[_.\- ]+/, Z = new RegExp("^" + L.source), E = new RegExp(L.source + B.source, "gu"), P = new RegExp("\\d+" + B.source, "gu"), G = (r, e, t, s) => {
|
|
11
11
|
let o = !1, n = !1, i = !1, a = !1;
|
|
12
12
|
for (let l = 0; l < r.length; l++) {
|
|
13
13
|
const c = r[l];
|
|
14
|
-
a = l > 2 ? r[l - 3] === "-" : !0, o &&
|
|
14
|
+
a = l > 2 ? r[l - 3] === "-" : !0, o && J.test(c) ? (r = r.slice(0, l) + "-" + r.slice(l), o = !1, i = n, n = !0, l++) : n && i && W.test(c) && (!a || s) ? (r = r.slice(0, l - 1) + "-" + r.slice(l - 1), i = n, n = !1, o = !0) : (o = e(c) === c && t(c) !== c, i = n, n = t(c) === c && e(c) !== c);
|
|
15
15
|
}
|
|
16
16
|
return r;
|
|
17
|
-
},
|
|
18
|
-
function
|
|
17
|
+
}, K = (r, e) => (x.lastIndex = 0, r.replaceAll(x, (t) => e(t))), Y = (r, e) => (E.lastIndex = 0, P.lastIndex = 0, r.replaceAll(P, (t, s, o) => ["_", "-"].includes(r.charAt(o + t.length)) ? t : e(t)).replaceAll(E, (t, s) => e(s)));
|
|
18
|
+
function Q(r, e) {
|
|
19
19
|
if (!(typeof r == "string" || Array.isArray(r)))
|
|
20
20
|
throw new TypeError("Expected the input to be `string | string[]`");
|
|
21
21
|
if (e = {
|
|
@@ -25,12 +25,12 @@ function W(r, e) {
|
|
|
25
25
|
}, Array.isArray(r) ? r = r.map((n) => n.trim()).filter((n) => n.length).join("-") : r = r.trim(), r.length === 0)
|
|
26
26
|
return "";
|
|
27
27
|
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);
|
|
28
|
-
return r.length === 1 ?
|
|
28
|
+
return r.length === 1 ? L.test(r) ? "" : e.pascalCase ? s(r) : t(r) : (r !== t(r) && (r = G(r, t, s, e.preserveConsecutiveUppercase)), r = r.replace(Z, ""), r = e.preserveConsecutiveUppercase ? K(r, t) : t(r), e.pascalCase && (r = s(r.charAt(0)) + r.slice(1)), Y(r, s));
|
|
29
29
|
}
|
|
30
|
-
function
|
|
31
|
-
return
|
|
30
|
+
function j(r) {
|
|
31
|
+
return Q(r);
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function X(r, e = {}, t, s) {
|
|
34
34
|
const o = "virtual:storyblok-components", n = `\0${o}`;
|
|
35
35
|
return {
|
|
36
36
|
name: "vite-plugin-storyblok-components",
|
|
@@ -42,11 +42,11 @@ function K(r, e = {}, t, s) {
|
|
|
42
42
|
if (i === n) {
|
|
43
43
|
const a = [], l = [];
|
|
44
44
|
for await (const [h, u] of Object.entries(e)) {
|
|
45
|
-
const
|
|
45
|
+
const p = await this.resolve(
|
|
46
46
|
`/${r}/${u}.astro`
|
|
47
47
|
);
|
|
48
|
-
if (
|
|
49
|
-
a.push(`import ${
|
|
48
|
+
if (p)
|
|
49
|
+
a.push(`import ${j(h)} from "${p.id}"`);
|
|
50
50
|
else if (t)
|
|
51
51
|
l.push(h);
|
|
52
52
|
else
|
|
@@ -72,7 +72,7 @@ function K(r, e = {}, t, s) {
|
|
|
72
72
|
"import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'"
|
|
73
73
|
);
|
|
74
74
|
if (Object.values(e).length)
|
|
75
|
-
return `${a.join(";")};export default {${Object.keys(e).filter((h) => !l.includes(h)).map((h) =>
|
|
75
|
+
return `${a.join(";")};export default {${Object.keys(e).filter((h) => !l.includes(h)).map((h) => j(h)).join(",")}${c}}`;
|
|
76
76
|
if (t)
|
|
77
77
|
return `${a[0]}; export default {${c.replace(",", "")}}`;
|
|
78
78
|
throw new Error(
|
|
@@ -84,7 +84,7 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
|
|
|
84
84
|
}
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
-
function
|
|
87
|
+
function ee(r, e, t) {
|
|
88
88
|
const s = "virtual:storyblok-init", o = `\0${s}`;
|
|
89
89
|
return {
|
|
90
90
|
name: "vite-plugin-storyblok-init",
|
|
@@ -106,7 +106,7 @@ function Z(r, e, t) {
|
|
|
106
106
|
}
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
|
-
function
|
|
109
|
+
function te(r) {
|
|
110
110
|
const e = "virtual:storyblok-options", t = `\0${e}`;
|
|
111
111
|
return {
|
|
112
112
|
name: "vite-plugin-storyblok-options",
|
|
@@ -120,28 +120,28 @@ function G(r) {
|
|
|
120
120
|
}
|
|
121
121
|
};
|
|
122
122
|
}
|
|
123
|
-
let
|
|
124
|
-
const
|
|
123
|
+
let O = !1;
|
|
124
|
+
const N = [], D = (r) => new Promise((e, t) => {
|
|
125
125
|
if (typeof window > "u" || (window.storyblokRegisterEvent = (o) => {
|
|
126
126
|
if (window.location === window.parent.location) {
|
|
127
127
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
128
128
|
return;
|
|
129
129
|
}
|
|
130
|
-
|
|
130
|
+
O ? o() : N.push(o);
|
|
131
131
|
}, document.getElementById("storyblok-javascript-bridge")))
|
|
132
132
|
return;
|
|
133
133
|
const s = document.createElement("script");
|
|
134
134
|
s.async = !0, s.src = r, s.id = "storyblok-javascript-bridge", s.onerror = (o) => t(o), s.onload = (o) => {
|
|
135
|
-
|
|
135
|
+
N.forEach((n) => n()), O = !0, e(o);
|
|
136
136
|
}, document.getElementsByTagName("head")[0].appendChild(s);
|
|
137
137
|
});
|
|
138
|
-
var
|
|
139
|
-
class
|
|
138
|
+
var se = Object.defineProperty, re = (r, e, t) => e in r ? se(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, d = (r, e, t) => re(r, typeof e != "symbol" ? e + "" : e, t);
|
|
139
|
+
class oe extends Error {
|
|
140
140
|
constructor(e) {
|
|
141
141
|
super(e), this.name = "AbortError";
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
-
function
|
|
144
|
+
function ne(r, e, t) {
|
|
145
145
|
if (!Number.isFinite(e))
|
|
146
146
|
throw new TypeError("Expected `limit` to be a finite number");
|
|
147
147
|
if (!Number.isFinite(t))
|
|
@@ -175,11 +175,11 @@ function ee(r, e, t) {
|
|
|
175
175
|
});
|
|
176
176
|
return l.abort = () => {
|
|
177
177
|
i = !0, o.forEach(clearTimeout), o = [], s.forEach(
|
|
178
|
-
(c) => c.reject(() => new
|
|
178
|
+
(c) => c.reject(() => new oe("Throttle function aborted"))
|
|
179
179
|
), s.length = 0;
|
|
180
180
|
}, l;
|
|
181
181
|
}
|
|
182
|
-
let
|
|
182
|
+
let T = class {
|
|
183
183
|
constructor() {
|
|
184
184
|
d(this, "isCDNUrl", (r = "") => r.includes("/cdn/")), d(this, "getOptionsPage", (r, e = 25, t = 1) => ({
|
|
185
185
|
...r,
|
|
@@ -242,20 +242,20 @@ let v = class {
|
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
};
|
|
245
|
-
const
|
|
245
|
+
const ie = function(r, e) {
|
|
246
246
|
const t = {};
|
|
247
247
|
for (const s in r) {
|
|
248
248
|
const o = r[s];
|
|
249
249
|
e.includes(s) && o !== null && (t[s] = o);
|
|
250
250
|
}
|
|
251
251
|
return t;
|
|
252
|
-
},
|
|
252
|
+
}, ae = (r) => r === "email", le = () => ({
|
|
253
253
|
singleTag: "hr"
|
|
254
|
-
}),
|
|
254
|
+
}), ce = () => ({
|
|
255
255
|
tag: "blockquote"
|
|
256
|
-
}),
|
|
256
|
+
}), he = () => ({
|
|
257
257
|
tag: "ul"
|
|
258
|
-
}),
|
|
258
|
+
}), ue = (r) => ({
|
|
259
259
|
tag: [
|
|
260
260
|
"pre",
|
|
261
261
|
{
|
|
@@ -263,24 +263,24 @@ const te = function(r, e) {
|
|
|
263
263
|
attrs: r.attrs
|
|
264
264
|
}
|
|
265
265
|
]
|
|
266
|
-
}),
|
|
266
|
+
}), de = () => ({
|
|
267
267
|
singleTag: "br"
|
|
268
|
-
}),
|
|
268
|
+
}), pe = (r) => ({
|
|
269
269
|
tag: `h${r.attrs.level}`
|
|
270
|
-
}),
|
|
270
|
+
}), ge = (r) => ({
|
|
271
271
|
singleTag: [
|
|
272
272
|
{
|
|
273
273
|
tag: "img",
|
|
274
|
-
attrs:
|
|
274
|
+
attrs: ie(r.attrs, ["src", "alt", "title"])
|
|
275
275
|
}
|
|
276
276
|
]
|
|
277
|
-
}),
|
|
277
|
+
}), fe = () => ({
|
|
278
278
|
tag: "li"
|
|
279
|
-
}),
|
|
279
|
+
}), ye = () => ({
|
|
280
280
|
tag: "ol"
|
|
281
|
-
}),
|
|
281
|
+
}), me = () => ({
|
|
282
282
|
tag: "p"
|
|
283
|
-
}),
|
|
283
|
+
}), be = (r) => ({
|
|
284
284
|
tag: [
|
|
285
285
|
{
|
|
286
286
|
tag: "span",
|
|
@@ -291,25 +291,25 @@ const te = function(r, e) {
|
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
293
|
]
|
|
294
|
-
}),
|
|
294
|
+
}), ke = () => ({
|
|
295
295
|
tag: "b"
|
|
296
|
-
}),
|
|
296
|
+
}), ve = () => ({
|
|
297
297
|
tag: "s"
|
|
298
|
-
}),
|
|
298
|
+
}), we = () => ({
|
|
299
299
|
tag: "u"
|
|
300
|
-
}),
|
|
300
|
+
}), $e = () => ({
|
|
301
301
|
tag: "strong"
|
|
302
|
-
}),
|
|
302
|
+
}), Te = () => ({
|
|
303
303
|
tag: "code"
|
|
304
|
-
}),
|
|
304
|
+
}), Ce = () => ({
|
|
305
305
|
tag: "i"
|
|
306
|
-
}),
|
|
306
|
+
}), Se = (r) => {
|
|
307
307
|
if (!r.attrs)
|
|
308
308
|
return {
|
|
309
309
|
tag: ""
|
|
310
310
|
};
|
|
311
|
-
const e = new
|
|
312
|
-
if (delete t.linktype, t.href && (t.href = e(r.attrs.href || "")),
|
|
311
|
+
const e = new T().escapeHTML, t = { ...r.attrs }, { linktype: s = "url" } = r.attrs;
|
|
312
|
+
if (delete t.linktype, t.href && (t.href = e(r.attrs.href || "")), ae(s) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
|
|
313
313
|
for (const o in t.custom)
|
|
314
314
|
t[o] = t.custom[o];
|
|
315
315
|
delete t.custom;
|
|
@@ -322,25 +322,25 @@ const te = function(r, e) {
|
|
|
322
322
|
}
|
|
323
323
|
]
|
|
324
324
|
};
|
|
325
|
-
},
|
|
325
|
+
}, _e = (r) => ({
|
|
326
326
|
tag: [
|
|
327
327
|
{
|
|
328
328
|
tag: "span",
|
|
329
329
|
attrs: r.attrs
|
|
330
330
|
}
|
|
331
331
|
]
|
|
332
|
-
}),
|
|
332
|
+
}), Ae = () => ({
|
|
333
333
|
tag: "sub"
|
|
334
|
-
}),
|
|
334
|
+
}), Re = () => ({
|
|
335
335
|
tag: "sup"
|
|
336
|
-
}),
|
|
336
|
+
}), Ie = (r) => ({
|
|
337
337
|
tag: [
|
|
338
338
|
{
|
|
339
339
|
tag: "span",
|
|
340
340
|
attrs: r.attrs
|
|
341
341
|
}
|
|
342
342
|
]
|
|
343
|
-
}),
|
|
343
|
+
}), Le = (r) => {
|
|
344
344
|
var e;
|
|
345
345
|
return (e = r.attrs) != null && e.color ? {
|
|
346
346
|
tag: [
|
|
@@ -354,7 +354,7 @@ const te = function(r, e) {
|
|
|
354
354
|
} : {
|
|
355
355
|
tag: ""
|
|
356
356
|
};
|
|
357
|
-
},
|
|
357
|
+
}, xe = (r) => {
|
|
358
358
|
var e;
|
|
359
359
|
return (e = r.attrs) != null && e.color ? {
|
|
360
360
|
tag: [
|
|
@@ -368,36 +368,36 @@ const te = function(r, e) {
|
|
|
368
368
|
} : {
|
|
369
369
|
tag: ""
|
|
370
370
|
};
|
|
371
|
-
},
|
|
371
|
+
}, Ee = {
|
|
372
372
|
nodes: {
|
|
373
|
-
horizontal_rule:
|
|
374
|
-
blockquote:
|
|
375
|
-
bullet_list:
|
|
376
|
-
code_block:
|
|
377
|
-
hard_break:
|
|
378
|
-
heading:
|
|
379
|
-
image:
|
|
380
|
-
list_item:
|
|
381
|
-
ordered_list:
|
|
382
|
-
paragraph:
|
|
383
|
-
emoji:
|
|
373
|
+
horizontal_rule: le,
|
|
374
|
+
blockquote: ce,
|
|
375
|
+
bullet_list: he,
|
|
376
|
+
code_block: ue,
|
|
377
|
+
hard_break: de,
|
|
378
|
+
heading: pe,
|
|
379
|
+
image: ge,
|
|
380
|
+
list_item: fe,
|
|
381
|
+
ordered_list: ye,
|
|
382
|
+
paragraph: me,
|
|
383
|
+
emoji: be
|
|
384
384
|
},
|
|
385
385
|
marks: {
|
|
386
|
-
bold:
|
|
387
|
-
strike:
|
|
388
|
-
underline:
|
|
389
|
-
strong:
|
|
390
|
-
code:
|
|
391
|
-
italic:
|
|
392
|
-
link:
|
|
393
|
-
styled:
|
|
394
|
-
subscript:
|
|
395
|
-
superscript:
|
|
396
|
-
anchor:
|
|
397
|
-
highlight:
|
|
398
|
-
textStyle:
|
|
399
|
-
}
|
|
400
|
-
},
|
|
386
|
+
bold: ke,
|
|
387
|
+
strike: ve,
|
|
388
|
+
underline: we,
|
|
389
|
+
strong: $e,
|
|
390
|
+
code: Te,
|
|
391
|
+
italic: Ce,
|
|
392
|
+
link: Se,
|
|
393
|
+
styled: _e,
|
|
394
|
+
subscript: Ae,
|
|
395
|
+
superscript: Re,
|
|
396
|
+
anchor: Ie,
|
|
397
|
+
highlight: Le,
|
|
398
|
+
textStyle: xe
|
|
399
|
+
}
|
|
400
|
+
}, Pe = function(r) {
|
|
401
401
|
const e = {
|
|
402
402
|
"&": "&",
|
|
403
403
|
"<": "<",
|
|
@@ -407,10 +407,10 @@ const te = function(r, e) {
|
|
|
407
407
|
}, t = /[&<>"']/g, s = new RegExp(t.source);
|
|
408
408
|
return r && s.test(r) ? r.replace(t, (o) => e[o]) : r;
|
|
409
409
|
};
|
|
410
|
-
let
|
|
411
|
-
class
|
|
410
|
+
let M = !1;
|
|
411
|
+
class C {
|
|
412
412
|
constructor(e) {
|
|
413
|
-
d(this, "marks"), d(this, "nodes"), e || (e =
|
|
413
|
+
d(this, "marks"), d(this, "nodes"), e || (e = Ee), this.marks = e.marks || [], this.nodes = e.nodes || [];
|
|
414
414
|
}
|
|
415
415
|
addNode(e, t) {
|
|
416
416
|
this.nodes[e] = t;
|
|
@@ -419,9 +419,9 @@ class w {
|
|
|
419
419
|
this.marks[e] = t;
|
|
420
420
|
}
|
|
421
421
|
render(e, t = { optimizeImages: !1 }, s = !0) {
|
|
422
|
-
if (!
|
|
422
|
+
if (!M && s && (console.warn(
|
|
423
423
|
"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/"
|
|
424
|
-
),
|
|
424
|
+
), M = !0), e && e.content && Array.isArray(e.content)) {
|
|
425
425
|
let o = "";
|
|
426
426
|
return e.content.forEach((n) => {
|
|
427
427
|
o += this.renderNode(n);
|
|
@@ -467,20 +467,20 @@ class w {
|
|
|
467
467
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g
|
|
468
468
|
);
|
|
469
469
|
if (u && u.length > 0) {
|
|
470
|
-
const
|
|
471
|
-
srcset: (c = t.srcset) == null ? void 0 : c.map((
|
|
472
|
-
if (typeof
|
|
473
|
-
return `//${u}/m/${
|
|
474
|
-
if (typeof
|
|
475
|
-
let
|
|
476
|
-
return typeof
|
|
470
|
+
const p = {
|
|
471
|
+
srcset: (c = t.srcset) == null ? void 0 : c.map((g) => {
|
|
472
|
+
if (typeof g == "number")
|
|
473
|
+
return `//${u}/m/${g}x0${i} ${g}w`;
|
|
474
|
+
if (typeof g == "object" && g.length === 2) {
|
|
475
|
+
let k = 0, b = 0;
|
|
476
|
+
return typeof g[0] == "number" && (k = g[0]), typeof g[1] == "number" && (b = g[1]), `//${u}/m/${k}x${b}${i} ${k}w`;
|
|
477
477
|
}
|
|
478
478
|
return "";
|
|
479
479
|
}).join(", "),
|
|
480
|
-
sizes: (h = t.sizes) == null ? void 0 : h.map((
|
|
480
|
+
sizes: (h = t.sizes) == null ? void 0 : h.map((g) => g).join(", ")
|
|
481
481
|
};
|
|
482
|
-
let
|
|
483
|
-
return
|
|
482
|
+
let m = "";
|
|
483
|
+
return p.srcset && (m += `srcset="${p.srcset}" `), p.sizes && (m += `sizes="${p.sizes}" `), l.replace(/<img/g, `<img ${m.trim()}`);
|
|
484
484
|
}
|
|
485
485
|
return l;
|
|
486
486
|
})), e;
|
|
@@ -494,7 +494,7 @@ class w {
|
|
|
494
494
|
const s = this.getMatchingNode(e);
|
|
495
495
|
return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((o) => {
|
|
496
496
|
t.push(this.renderNode(o));
|
|
497
|
-
}) : e.text ? t.push(
|
|
497
|
+
}) : e.text ? t.push(Pe(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((o) => {
|
|
498
498
|
const n = this.getMatchingMark(o);
|
|
499
499
|
n && n.tag !== "" && t.push(this.renderClosingTag(n.tag));
|
|
500
500
|
}), t.join("");
|
|
@@ -549,7 +549,7 @@ class w {
|
|
|
549
549
|
return this.renderTag(t, " /");
|
|
550
550
|
}
|
|
551
551
|
}
|
|
552
|
-
class
|
|
552
|
+
class je {
|
|
553
553
|
constructor(e) {
|
|
554
554
|
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 = {};
|
|
555
555
|
}
|
|
@@ -588,7 +588,7 @@ class Ie {
|
|
|
588
588
|
async _methodHandler(e) {
|
|
589
589
|
let t = `${this.baseURL}${this.url}`, s = null;
|
|
590
590
|
if (e === "get") {
|
|
591
|
-
const l = new
|
|
591
|
+
const l = new T();
|
|
592
592
|
t = `${this.baseURL}${this.url}?${l.stringify(
|
|
593
593
|
this.parameters
|
|
594
594
|
)}`;
|
|
@@ -636,14 +636,14 @@ class Ie {
|
|
|
636
636
|
});
|
|
637
637
|
}
|
|
638
638
|
}
|
|
639
|
-
const
|
|
639
|
+
const U = "SB-Agent", A = {
|
|
640
640
|
defaultAgentName: "SB-JS-CLIENT",
|
|
641
641
|
defaultAgentVersion: "SB-Agent-Version",
|
|
642
642
|
packageVersion: "6.0.0"
|
|
643
643
|
};
|
|
644
|
-
let
|
|
644
|
+
let $ = {};
|
|
645
645
|
const y = {};
|
|
646
|
-
class
|
|
646
|
+
class Oe {
|
|
647
647
|
/**
|
|
648
648
|
*
|
|
649
649
|
* @param config ISbConfig interface
|
|
@@ -653,22 +653,22 @@ class Le {
|
|
|
653
653
|
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");
|
|
654
654
|
let s = e.endpoint || t;
|
|
655
655
|
if (!s) {
|
|
656
|
-
const i = new
|
|
656
|
+
const i = new T().getRegionURL, a = e.https === !1 ? "http" : "https";
|
|
657
657
|
e.oauthToken ? s = `${a}://${i(e.region)}/v1` : s = `${a}://${i(e.region)}/v2`;
|
|
658
658
|
}
|
|
659
659
|
const o = new Headers();
|
|
660
660
|
o.set("Content-Type", "application/json"), o.set("Accept", "application/json"), e.headers && (e.headers.constructor.name === "Headers" ? e.headers.entries().toArray() : Object.entries(e.headers)).forEach(([i, a]) => {
|
|
661
661
|
o.set(i, a);
|
|
662
|
-
}), o.has(
|
|
663
|
-
|
|
664
|
-
|
|
662
|
+
}), o.has(U) || (o.set(U, A.defaultAgentName), o.set(
|
|
663
|
+
A.defaultAgentVersion,
|
|
664
|
+
A.packageVersion
|
|
665
665
|
));
|
|
666
666
|
let n = 5;
|
|
667
|
-
e.oauthToken && (o.set("Authorization", e.oauthToken), n = 3), e.rateLimit && (n = e.rateLimit), e.richTextSchema ? this.richTextResolver = new
|
|
667
|
+
e.oauthToken && (o.set("Authorization", e.oauthToken), n = 3), e.rateLimit && (n = e.rateLimit), e.richTextSchema ? this.richTextResolver = new C(e.richTextSchema) : this.richTextResolver = new C(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = ne(
|
|
668
668
|
this.throttledRequest.bind(this),
|
|
669
669
|
n,
|
|
670
670
|
1e3
|
|
671
|
-
), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new
|
|
671
|
+
), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new T(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new je({
|
|
672
672
|
baseURL: s,
|
|
673
673
|
timeout: e.timeout || 0,
|
|
674
674
|
headers: o,
|
|
@@ -713,9 +713,9 @@ class Le {
|
|
|
713
713
|
o
|
|
714
714
|
), h = c.total ? Math.ceil(c.total / n) : 1, u = await this.helpers.asyncMap(
|
|
715
715
|
this.helpers.range(l, h),
|
|
716
|
-
(
|
|
716
|
+
(p) => this.makeRequest(i, t, n, p + 1, o)
|
|
717
717
|
);
|
|
718
|
-
return this.helpers.flatMap([c, ...u], (
|
|
718
|
+
return this.helpers.flatMap([c, ...u], (p) => Object.values(p.data[a]));
|
|
719
719
|
}
|
|
720
720
|
post(e, t, s) {
|
|
721
721
|
const o = `/${e}`;
|
|
@@ -929,12 +929,12 @@ class Le {
|
|
|
929
929
|
perPage: h.headers["per-page"] ? Number.parseInt(h.headers["per-page"]) : 0,
|
|
930
930
|
total: h.headers["per-page"] ? Number.parseInt(h.headers.total) : 0
|
|
931
931
|
})), u.data.story || u.data.stories) {
|
|
932
|
-
const
|
|
933
|
-
await this.resolveStories(u.data, t, `${
|
|
932
|
+
const m = this.resolveCounter = ++this.resolveCounter % 1e3;
|
|
933
|
+
await this.resolveStories(u.data, t, `${m}`);
|
|
934
934
|
}
|
|
935
935
|
t.version === "published" && e !== "/cdn/spaces/me" && await i.set(n, u);
|
|
936
|
-
const
|
|
937
|
-
return t.token && u.data.cv && (
|
|
936
|
+
const p = this.cache.clear === "onpreview" && t.version === "draft" || this.cache.clear === "auto";
|
|
937
|
+
return t.token && u.data.cv && (p && y[t.token] && y[t.token] !== u.data.cv && await this.flushCache(), y[t.token] = u.data.cv), a(u);
|
|
938
938
|
} catch (h) {
|
|
939
939
|
if (h.response && h.status === 429 && (s = typeof s > "u" ? 0 : s + 1, s < this.maxRetries))
|
|
940
940
|
return console.log(
|
|
@@ -964,16 +964,16 @@ class Le {
|
|
|
964
964
|
case "memory":
|
|
965
965
|
return {
|
|
966
966
|
get(e) {
|
|
967
|
-
return Promise.resolve(
|
|
967
|
+
return Promise.resolve($[e]);
|
|
968
968
|
},
|
|
969
969
|
getAll() {
|
|
970
|
-
return Promise.resolve(
|
|
970
|
+
return Promise.resolve($);
|
|
971
971
|
},
|
|
972
972
|
set(e, t) {
|
|
973
|
-
return
|
|
973
|
+
return $[e] = t, Promise.resolve(void 0);
|
|
974
974
|
},
|
|
975
975
|
flush() {
|
|
976
|
-
return
|
|
976
|
+
return $ = {}, Promise.resolve(void 0);
|
|
977
977
|
}
|
|
978
978
|
};
|
|
979
979
|
case "custom":
|
|
@@ -1001,7 +1001,7 @@ class Le {
|
|
|
1001
1001
|
return await this.cacheProvider().flush(), this.clearCacheVersion(), this;
|
|
1002
1002
|
}
|
|
1003
1003
|
}
|
|
1004
|
-
const
|
|
1004
|
+
const Ne = (r = {}) => {
|
|
1005
1005
|
const { apiOptions: e } = r;
|
|
1006
1006
|
if (!e || !e.accessToken) {
|
|
1007
1007
|
console.error(
|
|
@@ -1009,8 +1009,8 @@ const Ee = (r = {}) => {
|
|
|
1009
1009
|
);
|
|
1010
1010
|
return;
|
|
1011
1011
|
}
|
|
1012
|
-
return { storyblokApi: new
|
|
1013
|
-
},
|
|
1012
|
+
return { storyblokApi: new Oe(e) };
|
|
1013
|
+
}, He = (r) => {
|
|
1014
1014
|
if (typeof r != "object" || typeof r._editable > "u")
|
|
1015
1015
|
return {};
|
|
1016
1016
|
try {
|
|
@@ -1025,8 +1025,8 @@ const Ee = (r = {}) => {
|
|
|
1025
1025
|
return {};
|
|
1026
1026
|
}
|
|
1027
1027
|
};
|
|
1028
|
-
let
|
|
1029
|
-
const
|
|
1028
|
+
let R, I = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
|
1029
|
+
const z = (r, e) => {
|
|
1030
1030
|
r.addNode("blok", (t) => {
|
|
1031
1031
|
let s = "";
|
|
1032
1032
|
return t.attrs.body.forEach((o) => {
|
|
@@ -1035,7 +1035,7 @@ const M = (r, e) => {
|
|
|
1035
1035
|
html: s
|
|
1036
1036
|
};
|
|
1037
1037
|
});
|
|
1038
|
-
},
|
|
1038
|
+
}, Me = (r = {}) => {
|
|
1039
1039
|
var e, t;
|
|
1040
1040
|
const {
|
|
1041
1041
|
bridge: s,
|
|
@@ -1048,46 +1048,46 @@ const M = (r, e) => {
|
|
|
1048
1048
|
i.accessToken = i.accessToken || o;
|
|
1049
1049
|
const c = { bridge: s, apiOptions: i };
|
|
1050
1050
|
let h = {};
|
|
1051
|
-
n.forEach((
|
|
1052
|
-
h = { ...h, ...
|
|
1053
|
-
}), l && (
|
|
1051
|
+
n.forEach((p) => {
|
|
1052
|
+
h = { ...h, ...p(c) };
|
|
1053
|
+
}), l && (I = l);
|
|
1054
1054
|
const u = !(typeof window > "u") && ((t = (e = window.location) == null ? void 0 : e.search) == null ? void 0 : t.includes("_storyblok_tk"));
|
|
1055
|
-
return s !== !1 && u &&
|
|
1056
|
-
},
|
|
1055
|
+
return s !== !1 && u && D(I), R = new C(a.schema), a.resolver && z(R, a.resolver), h;
|
|
1056
|
+
}, Ue = (r) => {
|
|
1057
1057
|
var e;
|
|
1058
1058
|
return !r || !((e = r == null ? void 0 : r.content) != null && e.some((t) => t.content || t.type === "blok" || t.type === "horizontal_rule"));
|
|
1059
|
-
},
|
|
1060
|
-
let s = t ||
|
|
1059
|
+
}, Fe = (r, e, t) => {
|
|
1060
|
+
let s = t || R;
|
|
1061
1061
|
if (!s) {
|
|
1062
1062
|
console.error(
|
|
1063
1063
|
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
|
1064
1064
|
);
|
|
1065
1065
|
return;
|
|
1066
1066
|
}
|
|
1067
|
-
return
|
|
1068
|
-
},
|
|
1069
|
-
function
|
|
1070
|
-
if (!
|
|
1067
|
+
return Ue(r) ? "" : (e && (s = new C(e.schema), e.resolver && z(s, e.resolver)), s.render(r, {}, !1));
|
|
1068
|
+
}, qe = () => D(I);
|
|
1069
|
+
function Ve() {
|
|
1070
|
+
if (!globalThis.storyblokApiInstance)
|
|
1071
1071
|
throw new Error("storyblokApiInstance has not been initialized correctly");
|
|
1072
1072
|
return globalThis.storyblokApiInstance;
|
|
1073
1073
|
}
|
|
1074
|
-
async function
|
|
1074
|
+
async function Je(r) {
|
|
1075
1075
|
let e = null;
|
|
1076
1076
|
return r && r.locals._storyblok_preview_data && (e = r.locals._storyblok_preview_data), e;
|
|
1077
1077
|
}
|
|
1078
|
-
function
|
|
1078
|
+
function We(r, e) {
|
|
1079
1079
|
var s;
|
|
1080
1080
|
const t = (s = globalThis == null ? void 0 : globalThis.storyblokApiInstance) == null ? void 0 : s.richTextResolver;
|
|
1081
1081
|
if (!t)
|
|
1082
1082
|
throw new Error(
|
|
1083
1083
|
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
|
1084
1084
|
);
|
|
1085
|
-
return
|
|
1085
|
+
return Fe(r, e, t);
|
|
1086
1086
|
}
|
|
1087
|
-
function
|
|
1087
|
+
function Be(r) {
|
|
1088
1088
|
return typeof r == "object" ? `const storyblokInstance = new StoryblokBridge(${JSON.stringify(r)});` : "const storyblokInstance = new StoryblokBridge();";
|
|
1089
1089
|
}
|
|
1090
|
-
function
|
|
1090
|
+
function Ze(r) {
|
|
1091
1091
|
const e = {
|
|
1092
1092
|
useCustomApi: !1,
|
|
1093
1093
|
bridge: !0,
|
|
@@ -1095,7 +1095,7 @@ function He(r) {
|
|
|
1095
1095
|
enableFallbackComponent: !1,
|
|
1096
1096
|
livePreview: !1,
|
|
1097
1097
|
...r
|
|
1098
|
-
}, t =
|
|
1098
|
+
}, t = Be(e.bridge);
|
|
1099
1099
|
return {
|
|
1100
1100
|
name: "@storyblok/astro",
|
|
1101
1101
|
hooks: {
|
|
@@ -1109,18 +1109,18 @@ function He(r) {
|
|
|
1109
1109
|
if (o({
|
|
1110
1110
|
vite: {
|
|
1111
1111
|
plugins: [
|
|
1112
|
-
|
|
1112
|
+
ee(
|
|
1113
1113
|
e.accessToken,
|
|
1114
1114
|
e.useCustomApi,
|
|
1115
1115
|
e.apiOptions
|
|
1116
1116
|
),
|
|
1117
|
-
|
|
1117
|
+
X(
|
|
1118
1118
|
e.componentsDir,
|
|
1119
1119
|
e.components,
|
|
1120
1120
|
e.enableFallbackComponent,
|
|
1121
1121
|
e.customFallbackComponent
|
|
1122
1122
|
),
|
|
1123
|
-
|
|
1123
|
+
te(e)
|
|
1124
1124
|
]
|
|
1125
1125
|
}
|
|
1126
1126
|
}), e.livePreview && (a == null ? void 0 : a.output) !== "server")
|
|
@@ -1161,65 +1161,69 @@ function He(r) {
|
|
|
1161
1161
|
})), n({
|
|
1162
1162
|
id: "storyblok",
|
|
1163
1163
|
name: "Storyblok",
|
|
1164
|
-
icon:
|
|
1164
|
+
icon: V,
|
|
1165
1165
|
entrypoint: "@storyblok/astro/toolbarApp.ts"
|
|
1166
1166
|
});
|
|
1167
1167
|
}
|
|
1168
1168
|
}
|
|
1169
1169
|
};
|
|
1170
1170
|
}
|
|
1171
|
-
function
|
|
1172
|
-
const {
|
|
1173
|
-
accessToken:
|
|
1174
|
-
use: [
|
|
1171
|
+
function Ge(r) {
|
|
1172
|
+
const { accessToken: e, useCustomApi: t, apiOptions: s, version: o, storiesParams: n } = r, { storyblokApi: i } = Me({
|
|
1173
|
+
accessToken: e,
|
|
1174
|
+
use: t ? [] : [Ne],
|
|
1175
|
+
apiOptions: s
|
|
1175
1176
|
});
|
|
1176
1177
|
return {
|
|
1177
1178
|
name: "story-loader",
|
|
1178
|
-
load: async ({ store:
|
|
1179
|
-
if (!
|
|
1179
|
+
load: async ({ store: a, meta: l, logger: c, refreshContextData: h }) => {
|
|
1180
|
+
if (!i)
|
|
1180
1181
|
throw new Error("storyblokApi is not loaded");
|
|
1181
|
-
if (
|
|
1182
|
-
|
|
1183
|
-
const
|
|
1184
|
-
|
|
1185
|
-
data:
|
|
1186
|
-
id:
|
|
1182
|
+
if (h != null && h.story) {
|
|
1183
|
+
c.info("Syncing... story updated in Storyblok");
|
|
1184
|
+
const f = h.story;
|
|
1185
|
+
a.set({
|
|
1186
|
+
data: f,
|
|
1187
|
+
id: f.uuid
|
|
1187
1188
|
});
|
|
1188
1189
|
return;
|
|
1189
1190
|
}
|
|
1190
|
-
|
|
1191
|
-
const
|
|
1192
|
-
|
|
1193
|
-
const
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1191
|
+
c.info("Loading stories");
|
|
1192
|
+
const u = l.get("lastPublishedAt"), p = l.get("lastUpdatedAt"), m = l.get("version"), g = { version: o };
|
|
1193
|
+
u && o === "published" ? g.published_at_gt = u : p && (g.updated_at_gt = p), m !== o && (c.info("Version changed, clearing store"), a.clear()), l.set("version", o);
|
|
1194
|
+
const k = await (i == null ? void 0 : i.getAll("cdn/stories", {
|
|
1195
|
+
...g,
|
|
1196
|
+
...n
|
|
1197
|
+
}));
|
|
1198
|
+
c.info(`Fetched ${k.length} stories`);
|
|
1199
|
+
const b = (f) => f ? new Date(f) : null;
|
|
1200
|
+
let v = b(u), w = b(p);
|
|
1201
|
+
for (const f of k) {
|
|
1202
|
+
const S = b(f.published_at), _ = b(f.updated_at), H = S && (!v || S > v), q = _ && (!w || _ > w);
|
|
1203
|
+
H && (v = S), q && (w = _), a.set({
|
|
1204
|
+
data: f,
|
|
1205
|
+
id: f.uuid
|
|
1206
|
+
}), w && l.set("lastUpdatedAt", w.toISOString()), v && l.set("lastPublishedAt", v.toISOString());
|
|
1203
1207
|
}
|
|
1204
1208
|
}
|
|
1205
1209
|
};
|
|
1206
1210
|
}
|
|
1207
|
-
let
|
|
1208
|
-
async function
|
|
1211
|
+
let F;
|
|
1212
|
+
async function Ke(r) {
|
|
1209
1213
|
const { action: e, story: t } = r || {};
|
|
1210
1214
|
if (e === "input" && t) {
|
|
1211
1215
|
const s = async () => {
|
|
1212
|
-
const n = await
|
|
1216
|
+
const n = await ze(t), i = document.body;
|
|
1213
1217
|
if (n.outerHTML === i.outerHTML)
|
|
1214
1218
|
return;
|
|
1215
1219
|
const a = document.querySelector('[data-blok-focused="true"]');
|
|
1216
|
-
|
|
1220
|
+
De(i, n, a), document.dispatchEvent(new Event("storyblok-live-preview-updated"));
|
|
1217
1221
|
};
|
|
1218
|
-
clearTimeout(
|
|
1222
|
+
clearTimeout(F), F = setTimeout(s, 500);
|
|
1219
1223
|
}
|
|
1220
1224
|
["published", "change"].includes(r == null ? void 0 : r.action) && location.reload();
|
|
1221
1225
|
}
|
|
1222
|
-
function
|
|
1226
|
+
function De(r, e, t) {
|
|
1223
1227
|
if (t) {
|
|
1224
1228
|
const s = t.getAttribute("data-blok-uid"), o = e.querySelector(
|
|
1225
1229
|
`[data-blok-uid="${s}"]`
|
|
@@ -1228,7 +1232,7 @@ function Ne(r, e, t) {
|
|
|
1228
1232
|
} else
|
|
1229
1233
|
r.replaceWith(e);
|
|
1230
1234
|
}
|
|
1231
|
-
async function
|
|
1235
|
+
async function ze(r) {
|
|
1232
1236
|
const t = await (await fetch(location.href, {
|
|
1233
1237
|
method: "POST",
|
|
1234
1238
|
body: JSON.stringify({
|
|
@@ -1242,15 +1246,15 @@ async function Me(r) {
|
|
|
1242
1246
|
return new DOMParser().parseFromString(t, "text/html").body;
|
|
1243
1247
|
}
|
|
1244
1248
|
export {
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1249
|
+
C as RichTextResolver,
|
|
1250
|
+
Ee as RichTextSchema,
|
|
1251
|
+
Je as getLiveStory,
|
|
1252
|
+
Ke as handleStoryblokMessage,
|
|
1253
|
+
qe as loadStoryblokBridge,
|
|
1254
|
+
We as renderRichText,
|
|
1255
|
+
Ze as storyblok,
|
|
1256
|
+
He as storyblokEditable,
|
|
1257
|
+
Ge as storyblokLoader,
|
|
1258
|
+
j as toCamelCase,
|
|
1259
|
+
Ve as useStoryblokApi
|
|
1256
1260
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(f,w){typeof exports=="object"&&typeof module<"u"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(f=typeof globalThis<"u"?globalThis:f||self,w(f.storyblokAstro={}))})(this,function(f){"use strict";const w=`<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">
|
|
2
2
|
<g id="storyblok-logo-kit" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
3
3
|
<g id="storyblok-partner-logo" transform="translate(-59.000000, -169.000000)" fill-rule="nonzero">
|
|
4
4
|
<g id="storyblok-symbol" transform="translate(59.000000, 169.000000)">
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
</g>
|
|
8
8
|
</g>
|
|
9
9
|
</g>
|
|
10
|
-
</svg>`,
|
|
10
|
+
</svg>`,J=/[\p{Lu}]/u,W=/[\p{Ll}]/u,x=/^[\p{Lu}](?![\p{Lu}])/gu,O=/([\p{Alpha}\p{N}_]|$)/u,_=/[_.\- ]+/,Z=new RegExp("^"+_.source),N=new RegExp(_.source+O.source,"gu"),M=new RegExp("\\d+"+O.source,"gu"),G=(r,e,t,s)=>{let o=!1,n=!1,i=!1,a=!1;for(let l=0;l<r.length;l++){const c=r[l];a=l>2?r[l-3]==="-":!0,o&&J.test(c)?(r=r.slice(0,l)+"-"+r.slice(l),o=!1,i=n,n=!0,l++):n&&i&&W.test(c)&&(!a||s)?(r=r.slice(0,l-1)+"-"+r.slice(l-1),i=n,n=!1,o=!0):(o=e(c)===c&&t(c)!==c,i=n,n=t(c)===c&&e(c)!==c)}return r},K=(r,e)=>(x.lastIndex=0,r.replaceAll(x,t=>e(t))),Y=(r,e)=>(N.lastIndex=0,M.lastIndex=0,r.replaceAll(M,(t,s,o)=>["_","-"].includes(r.charAt(o+t.length))?t:e(t)).replaceAll(N,(t,s)=>e(s)));function Q(r,e){if(!(typeof r=="string"||Array.isArray(r)))throw new TypeError("Expected the input to be `string | string[]`");if(e={pascalCase:!1,preserveConsecutiveUppercase:!1,...e},Array.isArray(r)?r=r.map(n=>n.trim()).filter(n=>n.length).join("-"):r=r.trim(),r.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 r.length===1?_.test(r)?"":e.pascalCase?s(r):t(r):(r!==t(r)&&(r=G(r,t,s,e.preserveConsecutiveUppercase)),r=r.replace(Z,""),r=e.preserveConsecutiveUppercase?K(r,t):t(r),e.pascalCase&&(r=s(r.charAt(0))+r.slice(1)),Y(r,s))}function R(r){return Q(r)}function X(r,e={},t,s){const o="virtual:storyblok-components",n=`\0${o}`;return{name:"vite-plugin-storyblok-components",async resolveId(i){if(i===o)return n},async load(i){if(i===n){const a=[],l=[];for await(const[h,u]of Object.entries(e)){const p=await this.resolve(`/${r}/${u}.astro`);if(p)a.push(`import ${R(h)} from "${p.id}"`);else if(t)l.push(h);else throw new Error(`Component could not be found for blok "${h}"! Does "${`/${r}/${u}`}.astro" exist?`)}let c="";if(t)if(c=",FallbackComponent",s){const h=await this.resolve(`/${r}/${s}.astro`);if(!h)throw new Error(`Custom fallback component could not be found. Does "${`/${r}/${s}`}.astro" exist?`);a.push(`import FallbackComponent from "${h.id}"`)}else a.push("import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'");if(Object.values(e).length)return`${a.join(";")};export default {${Object.keys(e).filter(h=>!l.includes(h)).map(h=>R(h)).join(",")}${c}}`;if(t)return`${a[0]}; export default {${c.replace(",","")}}`;throw new Error(`Currently, no Storyblok components are registered in astro.config.mjs.
|
|
11
11
|
Please register your components or enable the fallback component.
|
|
12
|
-
Detailed information can be found here: https://github.com/storyblok/storyblok-astro`)}}}}function
|
|
12
|
+
Detailed information can be found here: https://github.com/storyblok/storyblok-astro`)}}}}function ee(r,e,t){const s="virtual:storyblok-init",o=`\0${s}`;return{name:"vite-plugin-storyblok-init",async resolveId(n){if(n===s)return o},async load(n){if(n===o)return`
|
|
13
13
|
import { storyblokInit, apiPlugin } from "@storyblok/js";
|
|
14
14
|
const { storyblokApi } = storyblokInit({
|
|
15
15
|
accessToken: "${r}",
|
|
@@ -17,7 +17,7 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
|
|
|
17
17
|
apiOptions: ${JSON.stringify(t)},
|
|
18
18
|
});
|
|
19
19
|
export const storyblokApiInstance = storyblokApi;
|
|
20
|
-
`}}}function
|
|
20
|
+
`}}}function te(r){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(r)}`}}}let U=!1;const F=[],B=r=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=o=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}U?o():F.push(o)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=r,s.id="storyblok-javascript-bridge",s.onerror=o=>t(o),s.onload=o=>{F.forEach(n=>n()),U=!0,e(o)},document.getElementsByTagName("head")[0].appendChild(s)});var se=Object.defineProperty,re=(r,e,t)=>e in r?se(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,d=(r,e,t)=>re(r,typeof e!="symbol"?e+"":e,t);class oe extends Error{constructor(e){super(e),this.name="AbortError"}}function ne(r,e,t){if(!Number.isFinite(e))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let o=[],n=0,i=!1;const a=async()=>{n++;const c=s.shift();if(c)try{const u=await r(...c.args);c.resolve(u)}catch(u){c.reject(u)}const h=setTimeout(()=>{n--,s.length>0&&a(),o=o.filter(u=>u!==h)},t);o.includes(h)||o.push(h)},l=(...c)=>i?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((h,u)=>{s.push({resolve:h,reject:u,args:c}),n<e&&a()});return l.abort=()=>{i=!0,o.forEach(clearTimeout),o=[],s.forEach(c=>c.reject(()=>new oe("Throttle function aborted"))),s.length=0},l}let C=class{constructor(){d(this,"isCDNUrl",(r="")=>r.includes("/cdn/")),d(this,"getOptionsPage",(r,e=25,t=1)=>({...r,per_page:e,page:t})),d(this,"delay",r=>new Promise(e=>setTimeout(e,r))),d(this,"arrayFrom",(r=0,e)=>Array.from({length:r},e)),d(this,"range",(r=0,e=r)=>{const t=Math.abs(e-r)||0,s=r<e?1:-1;return this.arrayFrom(t,(o,n)=>n*s+r)}),d(this,"asyncMap",async(r,e)=>Promise.all(r.map(e))),d(this,"flatMap",(r=[],e)=>r.map(e).reduce((t,s)=>[...t,...s],[])),d(this,"escapeHTML",function(r){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,s=new RegExp(t.source);return r&&s.test(r)?r.replace(t,o=>e[o]):r})}stringify(r,e,t){const s=[];for(const o in r){if(!Object.prototype.hasOwnProperty.call(r,o))continue;const n=r[o],i=t?"":encodeURIComponent(o);let a;typeof n=="object"?a=this.stringify(n,e?e+encodeURIComponent(`[${i}]`):i,Array.isArray(n)):a=`${e?e+encodeURIComponent(`[${i}]`):i}=${encodeURIComponent(n)}`,s.push(a)}return s.join("&")}getRegionURL(r){const e="api.storyblok.com",t="api-us.storyblok.com",s="app.storyblokchina.cn",o="api-ap.storyblok.com",n="api-ca.storyblok.com";switch(r){case"us":return t;case"cn":return s;case"ap":return o;case"ca":return n;default:return e}}};const ie=function(r,e){const t={};for(const s in r){const o=r[s];e.includes(s)&&o!==null&&(t[s]=o)}return t},ae=r=>r==="email",le=()=>({singleTag:"hr"}),ce=()=>({tag:"blockquote"}),he=()=>({tag:"ul"}),ue=r=>({tag:["pre",{tag:"code",attrs:r.attrs}]}),de=()=>({singleTag:"br"}),pe=r=>({tag:`h${r.attrs.level}`}),fe=r=>({singleTag:[{tag:"img",attrs:ie(r.attrs,["src","alt","title"])}]}),ge=()=>({tag:"li"}),ye=()=>({tag:"ol"}),me=()=>({tag:"p"}),be=r=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":r.attrs.name,emoji:r.attrs.emoji}}]}),ke=()=>({tag:"b"}),ve=()=>({tag:"s"}),we=()=>({tag:"u"}),$e=()=>({tag:"strong"}),Te=()=>({tag:"code"}),Se=()=>({tag:"i"}),Ce=r=>{if(!r.attrs)return{tag:""};const e=new C().escapeHTML,t={...r.attrs},{linktype:s="url"}=r.attrs;if(delete t.linktype,t.href&&(t.href=e(r.attrs.href||"")),ae(s)&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),t.custom){for(const o in t.custom)t[o]=t.custom[o];delete t.custom}return{tag:[{tag:"a",attrs:t}]}},Ae=r=>({tag:[{tag:"span",attrs:r.attrs}]}),_e=()=>({tag:"sub"}),Re=()=>({tag:"sup"}),Ie=r=>({tag:[{tag:"span",attrs:r.attrs}]}),Le=r=>{var e;return(e=r.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${r.attrs.color};`}}]}:{tag:""}},Ee=r=>{var e;return(e=r.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${r.attrs.color}`}}]}:{tag:""}},D={nodes:{horizontal_rule:le,blockquote:ce,bullet_list:he,code_block:ue,hard_break:de,heading:pe,image:fe,list_item:ge,ordered_list:ye,paragraph:me,emoji:be},marks:{bold:ke,strike:ve,underline:we,strong:$e,code:Te,italic:Se,link:Ce,styled:Ae,subscript:_e,superscript:Re,anchor:Ie,highlight:Le,textStyle:Ee}},Pe=function(r){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,s=new RegExp(t.source);return r&&s.test(r)?r.replace(t,o=>e[o]):r};let z=!1;class ${constructor(e){d(this,"marks"),d(this,"nodes"),e||(e=D),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(!z&&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/"),z=!0),e&&e.content&&Array.isArray(e.content)){let o="";return e.content.forEach(n=>{o+=this.renderNode(n)}),t.optimizeImages?this.optimizeImages(o,t.optimizeImages):o}return console.warn(`The render method must receive an Object with a "content" field.
|
|
21
21
|
The "content" field must be an array of nodes as the type ISbRichtext.
|
|
22
22
|
ISbRichtext:
|
|
23
23
|
content?: ISbRichtext[]
|
|
@@ -40,7 +40,7 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
|
|
|
40
40
|
}
|
|
41
41
|
],
|
|
42
42
|
type: 'doc'
|
|
43
|
-
}`),""}optimizeImages(e,t){let s=0,o=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}" `,o=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-F]{6}/gi)||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 a=s>0||o>0||i.length>0?`${s}x${o}${i}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${a}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,l=>{var c,h;const u=l.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g);if(u&&u.length>0){const f={srcset:(c=t.srcset)==null?void 0:c.map(p=>{if(typeof p=="number")return`//${u}/m/${p}x0${i} ${p}w`;if(typeof p=="object"&&p.length===2){let b=0,k=0;return typeof p[0]=="number"&&(b=p[0]),typeof p[1]=="number"&&(k=p[1]),`//${u}/m/${b}x${k}${i} ${b}w`}return""}).join(", "),sizes:(h=t.sizes)==null?void 0:h.map(p=>p).join(", ")};let y="";return f.srcset&&(y+=`srcset="${f.srcset}" `),f.sizes&&(y+=`sizes="${f.sizes}" `),l.replace(/<img/g,`<img ${y.trim()}`)}return l})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(o=>{const n=this.getMatchingMark(o);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(o=>{t.push(this.renderNode(o))}):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(o=>{const n=this.getMatchingMark(o);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 o=`<${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&&(o+=` ${n}="${i}"`)}}return`${o}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}renderEmoji(e){if(e.attrs.emoji)return e.attrs.emoji;const t=[{tag:"img",attrs:{src:e.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(t," /")}}class Ae{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(o=>{s.data=o});for(const o of e.headers.entries())t[o[0]]=o[1];return s.headers={...t},s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,s=null;if(e==="get"){const l=new $;t=`${this.baseURL}${this.url}?${l.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const o=new URL(t),n=new AbortController,{signal:i}=n;let a;this.timeout&&(a=setTimeout(()=>n.abort(),this.timeout));try{const l=await this.fetch(`${o}`,{method:e,headers:this.headers,body:s,signal:i,...this.fetchOptions});this.timeout&&clearTimeout(a);const c=await this._responseHandler(l);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(c)):this._statusHandler(c)}catch(l){return{message:l}}}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,o)=>{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};o(n)})}}const U="SB-Agent",_={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"};let T={};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 $().getRegionURL,a=e.https===!1?"http":"https";e.oauthToken?s=`${a}://${i(e.region)}/v1`:s=`${a}://${i(e.region)}/v2`}const o=new Headers;o.set("Content-Type","application/json"),o.set("Accept","application/json"),e.headers&&(e.headers.constructor.name==="Headers"?e.headers.entries().toArray():Object.entries(e.headers)).forEach(([i,a])=>{o.set(i,a)}),o.has(U)||(o.set(U,_.defaultAgentName),o.set(_.defaultAgentVersion,_.packageVersion));let n=5;e.oauthToken&&(o.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=e.rateLimit),e.richTextSchema?this.richTextResolver=new w(e.richTextSchema):this.richTextResolver=new w,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=ee(this.throttledRequest.bind(this),n,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new $,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.client=new Ae({baseURL:s,timeout:e.timeout||0,headers:o,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return t.attrs.body&&t.attrs.body.forEach(o=>{s+=e(o.component,o)}),{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,o,n){const i=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,o));return this.cacheResponse(e,i,void 0,n)}get(e,t,s){t||(t={});const o=`/${e}`,n=this.factoryParamOptions(o,t);return this.cacheResponse(o,n,void 0,s)}async getAll(e,t,s,o){const n=(t==null?void 0:t.per_page)||25,i=`/${e}`.replace(/\/$/,""),a=s??i.substring(i.lastIndexOf("/")+1),l=1,c=await this.makeRequest(i,t,n,l,o),h=c.total?Math.ceil(c.total/n):1,u=await this.helpers.asyncMap(this.helpers.range(l,h),f=>this.makeRequest(i,t,n,f+1,o));return this.helpers.flatMap([c,...u],f=>Object.values(f.data[a]))}post(e,t,s){const o=`/${e}`;return Promise.resolve(this.throttle("post",o,t,s))}put(e,t,s){const o=`/${e}`;return Promise.resolve(this.throttle("put",o,t,s))}delete(e,t,s){t||(t={});const o=`/${e}`;return Promise.resolve(this.throttle("delete",o,t,s))}getStories(e,t){return this._addResolveLevel(e),this.get("cdn/stories",e,t)}getStory(e,t,s){return this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t,s)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_addResolveLevel(e){typeof e.resolve_relations<"u"&&(e.resolve_level=2)}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,s){const o=e[t];o&&o.fieldtype==="multilink"&&o.linktype==="story"&&typeof o.id=="string"&&this.links[s][o.id]?o.story=this._cleanCopy(this.links[s][o.id]):o&&o.linktype==="story"&&typeof o.uuid=="string"&&this.links[s][o.uuid]&&(o.story=this._cleanCopy(this.links[s][o.uuid]))}getStoryReference(e,t){return this.relations[e][t]?JSON.parse(this.stringifiedStoriesCache[t]||JSON.stringify(this.relations[e][t])):t}_resolveField(e,t,s){const o=e[t];typeof o=="string"?e[t]=this.getStoryReference(s,o):Array.isArray(o)&&(e[t]=o.map(n=>this.getStoryReference(s,n)).filter(Boolean))}_insertRelations(e,t,s,o){if(Array.isArray(s)?s.find(i=>i.endsWith(`.${t}`)):s.endsWith(`.${t}`)){this._resolveField(e,t,o);return}const n=e.component?`${e.component}.${t}`:t;(Array.isArray(s)?s.includes(n):s===n)&&this._resolveField(e,t,o)}iterateTree(e,t,s){const o=(n,i="")=>{if(!(!n||n._stopResolving)){if(Array.isArray(n))n.forEach((a,l)=>o(a,`${i}[${l}]`));else if(typeof n=="object")for(const a in n){const l=i?`${i}.${a}`:a;(n.component&&n._uid||n.type==="link")&&(this._insertRelations(n,a,t,s),this._insertLinks(n,a,s)),o(n[a],l)}}};o(e.content)}async resolveLinks(e,t,s){let o=[];if(e.link_uuids){const n=e.link_uuids.length,i=[],a=50;for(let l=0;l<n;l+=a){const c=Math.min(n,l+a);i.push(e.link_uuids.slice(l,c))}for(let l=0;l<i.length;l++)(await this.getStories({per_page:a,language:t.language,version:t.version,by_uuids:i[l].join(",")})).data.stories.forEach(c=>{o.push(c)})}else o=e.links;o.forEach(n=>{this.links[s][n.uuid]={...n,_stopResolving:!0}})}async resolveRelations(e,t,s){let o=[];if(e.rel_uuids){const n=e.rel_uuids.length,i=[],a=50;for(let l=0;l<n;l+=a){const c=Math.min(n,l+a);i.push(e.rel_uuids.slice(l,c))}for(let l=0;l<i.length;l++)(await this.getStories({per_page:a,language:t.language,version:t.version,by_uuids:i[l].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(c=>{o.push(c)})}else o=e.rels;o&&o.length>0&&o.forEach(n=>{this.relations[s][n.uuid]={...n,_stopResolving:!0}})}async resolveStories(e,t,s){var o,n;let 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"].includes(t.resolve_links)&&((o=e.links)!=null&&o.length||(n=e.link_uuids)!=null&&n.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const a in this.relations[s])this.iterateTree(this.relations[s][a],i,s);e.story?this.iterateTree(e.story,i,s):e.stories.forEach(a=>{this.iterateTree(a,i,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s,o){const n=this.helpers.stringify({url:e,params:t}),i=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const a=await i.get(n);if(a)return Promise.resolve(a)}return new Promise(async(a,l)=>{var c;try{const h=await this.throttle("get",e,t,o);if(h.status!==200)return l(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"]?Number.parseInt(h.headers["per-page"]):0,total:h.headers["per-page"]?Number.parseInt(h.headers.total):0})),u.data.story||u.data.stories){const y=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(u.data,t,`${y}`)}t.version==="published"&&e!=="/cdn/spaces/me"&&await i.set(n,u);const f=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&u.data.cv&&(f&&m[t.token]&&m[t.token]!==u.data.cv&&await this.flushCache(),m[t.token]=u.data.cv),a(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(a).catch(l);l(h)}})}throttledRequest(e,t,s,o){return this.client.setFetchOptions(o),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(T[e])},getAll(){return Promise.resolve(T)},set(e,t){return T[e]=t,Promise.resolve(void 0)},flush(){return T={},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 Le=(r={})=>{const{apiOptions:e}=r;if(!e||!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new Ie(e)}},Ee=r=>{if(typeof r!="object"||typeof r._editable>"u")return{};try{const e=JSON.parse(r._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":`${e.id}-${e.uid}`}:{}}catch{return{}}};let R,A="https://app.storyblok.com/f/storyblok-v2-latest.js";const F=(r,e)=>{r.addNode("blok",t=>{let s="";return t.attrs.body.forEach(o=>{s+=e(o.component,o)}),{html:s}})},Pe=(r={})=>{var e,t;const{bridge:s,accessToken:o,use:n=[],apiOptions:i={},richText:a={},bridgeUrl:l}=r;i.accessToken=i.accessToken||o;const c={bridge:s,apiOptions:i};let h={};n.forEach(f=>{h={...h,...f(c)}}),l&&(A=l);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(A),R=new w(a.schema),a.resolver&&F(R,a.resolver),h},je=r=>{var e;return!r||!((e=r==null?void 0:r.content)!=null&&e.some(t=>t.content||t.type==="blok"||t.type==="horizontal_rule"))},Oe=(r,e,t)=>{let s=t||R;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return je(r)?"":(e&&(s=new w(e.schema),e.resolver&&F(s,e.resolver)),s.render(r,{},!1))},xe=()=>x(A);function Ne(){if(!(globalThis!=null&&globalThis.storyblokApiInstance))throw new Error("storyblokApiInstance has not been initialized correctly");return globalThis.storyblokApiInstance}async function Me(r){let e=null;return r&&r.locals._storyblok_preview_data&&(e=r.locals._storyblok_preview_data),e}function Ue(r,e){var s;const t=(s=globalThis==null?void 0:globalThis.storyblokApiInstance)==null?void 0:s.richTextResolver;if(!t)throw new Error("Please initialize the Storyblok SDK before calling the renderRichText function");return Oe(r,e,t)}function Fe(r){return typeof r=="object"?`const storyblokInstance = new StoryblokBridge(${JSON.stringify(r)});`:"const storyblokInstance = new StoryblokBridge();"}function Be(r){const e={useCustomApi:!1,bridge:!0,componentsDir:"src",enableFallbackComponent:!1,livePreview:!1,...r},t=Fe(e.bridge);return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:s,updateConfig:o,addDevToolbarApp:n,addMiddleware:i,config:a})=>{if(o({vite:{plugins:[Z(e.accessToken,e.useCustomApi,e.apiOptions),K(e.componentsDir,e.components,e.enableFallbackComponent,e.customFallbackComponent),G(e)]}}),e.livePreview&&(a==null?void 0:a.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.");s("page-ssr",`
|
|
43
|
+
}`),""}optimizeImages(e,t){let s=0,o=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}" `,o=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-F]{6}/gi)||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 a=s>0||o>0||i.length>0?`${s}x${o}${i}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${a}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,l=>{var c,h;const u=l.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g);if(u&&u.length>0){const p={srcset:(c=t.srcset)==null?void 0:c.map(g=>{if(typeof g=="number")return`//${u}/m/${g}x0${i} ${g}w`;if(typeof g=="object"&&g.length===2){let v=0,k=0;return typeof g[0]=="number"&&(v=g[0]),typeof g[1]=="number"&&(k=g[1]),`//${u}/m/${v}x${k}${i} ${v}w`}return""}).join(", "),sizes:(h=t.sizes)==null?void 0:h.map(g=>g).join(", ")};let b="";return p.srcset&&(b+=`srcset="${p.srcset}" `),p.sizes&&(b+=`sizes="${p.sizes}" `),l.replace(/<img/g,`<img ${b.trim()}`)}return l})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(o=>{const n=this.getMatchingMark(o);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(o=>{t.push(this.renderNode(o))}):e.text?t.push(Pe(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(o=>{const n=this.getMatchingMark(o);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 o=`<${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&&(o+=` ${n}="${i}"`)}}return`${o}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}renderEmoji(e){if(e.attrs.emoji)return e.attrs.emoji;const t=[{tag:"img",attrs:{src:e.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(t," /")}}class je{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(o=>{s.data=o});for(const o of e.headers.entries())t[o[0]]=o[1];return s.headers={...t},s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,s=null;if(e==="get"){const l=new C;t=`${this.baseURL}${this.url}?${l.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const o=new URL(t),n=new AbortController,{signal:i}=n;let a;this.timeout&&(a=setTimeout(()=>n.abort(),this.timeout));try{const l=await this.fetch(`${o}`,{method:e,headers:this.headers,body:s,signal:i,...this.fetchOptions});this.timeout&&clearTimeout(a);const c=await this._responseHandler(l);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(c)):this._statusHandler(c)}catch(l){return{message:l}}}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,o)=>{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};o(n)})}}const H="SB-Agent",I={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"};let A={};const m={};class xe{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 C().getRegionURL,a=e.https===!1?"http":"https";e.oauthToken?s=`${a}://${i(e.region)}/v1`:s=`${a}://${i(e.region)}/v2`}const o=new Headers;o.set("Content-Type","application/json"),o.set("Accept","application/json"),e.headers&&(e.headers.constructor.name==="Headers"?e.headers.entries().toArray():Object.entries(e.headers)).forEach(([i,a])=>{o.set(i,a)}),o.has(H)||(o.set(H,I.defaultAgentName),o.set(I.defaultAgentVersion,I.packageVersion));let n=5;e.oauthToken&&(o.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=e.rateLimit),e.richTextSchema?this.richTextResolver=new $(e.richTextSchema):this.richTextResolver=new $,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=ne(this.throttledRequest.bind(this),n,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new C,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.client=new je({baseURL:s,timeout:e.timeout||0,headers:o,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return t.attrs.body&&t.attrs.body.forEach(o=>{s+=e(o.component,o)}),{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,o,n){const i=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,o));return this.cacheResponse(e,i,void 0,n)}get(e,t,s){t||(t={});const o=`/${e}`,n=this.factoryParamOptions(o,t);return this.cacheResponse(o,n,void 0,s)}async getAll(e,t,s,o){const n=(t==null?void 0:t.per_page)||25,i=`/${e}`.replace(/\/$/,""),a=s??i.substring(i.lastIndexOf("/")+1),l=1,c=await this.makeRequest(i,t,n,l,o),h=c.total?Math.ceil(c.total/n):1,u=await this.helpers.asyncMap(this.helpers.range(l,h),p=>this.makeRequest(i,t,n,p+1,o));return this.helpers.flatMap([c,...u],p=>Object.values(p.data[a]))}post(e,t,s){const o=`/${e}`;return Promise.resolve(this.throttle("post",o,t,s))}put(e,t,s){const o=`/${e}`;return Promise.resolve(this.throttle("put",o,t,s))}delete(e,t,s){t||(t={});const o=`/${e}`;return Promise.resolve(this.throttle("delete",o,t,s))}getStories(e,t){return this._addResolveLevel(e),this.get("cdn/stories",e,t)}getStory(e,t,s){return this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t,s)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_addResolveLevel(e){typeof e.resolve_relations<"u"&&(e.resolve_level=2)}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,s){const o=e[t];o&&o.fieldtype==="multilink"&&o.linktype==="story"&&typeof o.id=="string"&&this.links[s][o.id]?o.story=this._cleanCopy(this.links[s][o.id]):o&&o.linktype==="story"&&typeof o.uuid=="string"&&this.links[s][o.uuid]&&(o.story=this._cleanCopy(this.links[s][o.uuid]))}getStoryReference(e,t){return this.relations[e][t]?JSON.parse(this.stringifiedStoriesCache[t]||JSON.stringify(this.relations[e][t])):t}_resolveField(e,t,s){const o=e[t];typeof o=="string"?e[t]=this.getStoryReference(s,o):Array.isArray(o)&&(e[t]=o.map(n=>this.getStoryReference(s,n)).filter(Boolean))}_insertRelations(e,t,s,o){if(Array.isArray(s)?s.find(i=>i.endsWith(`.${t}`)):s.endsWith(`.${t}`)){this._resolveField(e,t,o);return}const n=e.component?`${e.component}.${t}`:t;(Array.isArray(s)?s.includes(n):s===n)&&this._resolveField(e,t,o)}iterateTree(e,t,s){const o=(n,i="")=>{if(!(!n||n._stopResolving)){if(Array.isArray(n))n.forEach((a,l)=>o(a,`${i}[${l}]`));else if(typeof n=="object")for(const a in n){const l=i?`${i}.${a}`:a;(n.component&&n._uid||n.type==="link")&&(this._insertRelations(n,a,t,s),this._insertLinks(n,a,s)),o(n[a],l)}}};o(e.content)}async resolveLinks(e,t,s){let o=[];if(e.link_uuids){const n=e.link_uuids.length,i=[],a=50;for(let l=0;l<n;l+=a){const c=Math.min(n,l+a);i.push(e.link_uuids.slice(l,c))}for(let l=0;l<i.length;l++)(await this.getStories({per_page:a,language:t.language,version:t.version,by_uuids:i[l].join(",")})).data.stories.forEach(c=>{o.push(c)})}else o=e.links;o.forEach(n=>{this.links[s][n.uuid]={...n,_stopResolving:!0}})}async resolveRelations(e,t,s){let o=[];if(e.rel_uuids){const n=e.rel_uuids.length,i=[],a=50;for(let l=0;l<n;l+=a){const c=Math.min(n,l+a);i.push(e.rel_uuids.slice(l,c))}for(let l=0;l<i.length;l++)(await this.getStories({per_page:a,language:t.language,version:t.version,by_uuids:i[l].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(c=>{o.push(c)})}else o=e.rels;o&&o.length>0&&o.forEach(n=>{this.relations[s][n.uuid]={...n,_stopResolving:!0}})}async resolveStories(e,t,s){var o,n;let 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"].includes(t.resolve_links)&&((o=e.links)!=null&&o.length||(n=e.link_uuids)!=null&&n.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const a in this.relations[s])this.iterateTree(this.relations[s][a],i,s);e.story?this.iterateTree(e.story,i,s):e.stories.forEach(a=>{this.iterateTree(a,i,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s,o){const n=this.helpers.stringify({url:e,params:t}),i=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const a=await i.get(n);if(a)return Promise.resolve(a)}return new Promise(async(a,l)=>{var c;try{const h=await this.throttle("get",e,t,o);if(h.status!==200)return l(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"]?Number.parseInt(h.headers["per-page"]):0,total:h.headers["per-page"]?Number.parseInt(h.headers.total):0})),u.data.story||u.data.stories){const b=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(u.data,t,`${b}`)}t.version==="published"&&e!=="/cdn/spaces/me"&&await i.set(n,u);const p=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&u.data.cv&&(p&&m[t.token]&&m[t.token]!==u.data.cv&&await this.flushCache(),m[t.token]=u.data.cv),a(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(a).catch(l);l(h)}})}throttledRequest(e,t,s,o){return this.client.setFetchOptions(o),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(A[e])},getAll(){return Promise.resolve(A)},set(e,t){return A[e]=t,Promise.resolve(void 0)},flush(){return A={},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=(r={})=>{const{apiOptions:e}=r;if(!e||!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new xe(e)}},Ne=r=>{if(typeof r!="object"||typeof r._editable>"u")return{};try{const e=JSON.parse(r._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":`${e.id}-${e.uid}`}:{}}catch{return{}}};let L,E="https://app.storyblok.com/f/storyblok-v2-latest.js";const q=(r,e)=>{r.addNode("blok",t=>{let s="";return t.attrs.body.forEach(o=>{s+=e(o.component,o)}),{html:s}})},Me=(r={})=>{var e,t;const{bridge:s,accessToken:o,use:n=[],apiOptions:i={},richText:a={},bridgeUrl:l}=r;i.accessToken=i.accessToken||o;const c={bridge:s,apiOptions:i};let h={};n.forEach(p=>{h={...h,...p(c)}}),l&&(E=l);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&&B(E),L=new $(a.schema),a.resolver&&q(L,a.resolver),h},Ue=r=>{var e;return!r||!((e=r==null?void 0:r.content)!=null&&e.some(t=>t.content||t.type==="blok"||t.type==="horizontal_rule"))},Fe=(r,e,t)=>{let s=t||L;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return Ue(r)?"":(e&&(s=new $(e.schema),e.resolver&&q(s,e.resolver)),s.render(r,{},!1))},Be=()=>B(E);function De(){if(!globalThis.storyblokApiInstance)throw new Error("storyblokApiInstance has not been initialized correctly");return globalThis.storyblokApiInstance}async function ze(r){let e=null;return r&&r.locals._storyblok_preview_data&&(e=r.locals._storyblok_preview_data),e}function He(r,e){var s;const t=(s=globalThis==null?void 0:globalThis.storyblokApiInstance)==null?void 0:s.richTextResolver;if(!t)throw new Error("Please initialize the Storyblok SDK before calling the renderRichText function");return Fe(r,e,t)}function qe(r){return typeof r=="object"?`const storyblokInstance = new StoryblokBridge(${JSON.stringify(r)});`:"const storyblokInstance = new StoryblokBridge();"}function Ve(r){const e={useCustomApi:!1,bridge:!0,componentsDir:"src",enableFallbackComponent:!1,livePreview:!1,...r},t=qe(e.bridge);return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:s,updateConfig:o,addDevToolbarApp:n,addMiddleware:i,config:a})=>{if(o({vite:{plugins:[ee(e.accessToken,e.useCustomApi,e.apiOptions),X(e.componentsDir,e.components,e.enableFallbackComponent,e.customFallbackComponent),te(e)]}}),e.livePreview&&(a==null?void 0:a.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.");s("page-ssr",`
|
|
44
44
|
import { storyblokApiInstance } from "virtual:storyblok-init";
|
|
45
45
|
globalThis.storyblokApiInstance = storyblokApiInstance;
|
|
46
46
|
`),e.bridge&&!e.livePreview&&s("page",`import { loadStoryblokBridge } from "@storyblok/astro";
|
|
@@ -59,4 +59,4 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
|
|
|
59
59
|
${t}
|
|
60
60
|
storyblokInstance.on(["published", "change", "input"], handleStoryblokMessage);
|
|
61
61
|
});
|
|
62
|
-
`),i({entrypoint:"@storyblok/astro/middleware.ts",order:"pre"})),n({id:"storyblok",name:"Storyblok",icon:
|
|
62
|
+
`),i({entrypoint:"@storyblok/astro/middleware.ts",order:"pre"})),n({id:"storyblok",name:"Storyblok",icon:w,entrypoint:"@storyblok/astro/toolbarApp.ts"})}}}}function Je(r){const{accessToken:e,useCustomApi:t,apiOptions:s,version:o,storiesParams:n}=r,{storyblokApi:i}=Me({accessToken:e,use:t?[]:[Oe],apiOptions:s});return{name:"story-loader",load:async({store:a,meta:l,logger:c,refreshContextData:h})=>{if(!i)throw new Error("storyblokApi is not loaded");if(h!=null&&h.story){c.info("Syncing... story updated in Storyblok");const y=h.story;a.set({data:y,id:y.uuid});return}c.info("Loading stories");const u=l.get("lastPublishedAt"),p=l.get("lastUpdatedAt"),b=l.get("version"),g={version:o};u&&o==="published"?g.published_at_gt=u:p&&(g.updated_at_gt=p),b!==o&&(c.info("Version changed, clearing store"),a.clear()),l.set("version",o);const v=await(i==null?void 0:i.getAll("cdn/stories",{...g,...n}));c.info(`Fetched ${v.length} stories`);const k=y=>y?new Date(y):null;let T=k(u),S=k(p);for(const y of v){const P=k(y.published_at),j=k(y.updated_at),Ke=P&&(!T||P>T),Ye=j&&(!S||j>S);Ke&&(T=P),Ye&&(S=j),a.set({data:y,id:y.uuid}),S&&l.set("lastUpdatedAt",S.toISOString()),T&&l.set("lastPublishedAt",T.toISOString())}}}}let V;async function We(r){const{action:e,story:t}=r||{};if(e==="input"&&t){const s=async()=>{const n=await Ge(t),i=document.body;if(n.outerHTML===i.outerHTML)return;const a=document.querySelector('[data-blok-focused="true"]');Ze(i,n,a),document.dispatchEvent(new Event("storyblok-live-preview-updated"))};clearTimeout(V),V=setTimeout(s,500)}["published","change"].includes(r==null?void 0:r.action)&&location.reload()}function Ze(r,e,t){if(t){const s=t.getAttribute("data-blok-uid"),o=e.querySelector(`[data-blok-uid="${s}"]`);o&&(o.setAttribute("data-blok-focused","true"),t.replaceWith(o))}else r.replaceWith(e)}async function Ge(r){const t=await(await fetch(location.href,{method:"POST",body:JSON.stringify({...r,is_storyblok_preview:!0}),headers:{"Content-Type":"application/json"}})).text();return new DOMParser().parseFromString(t,"text/html").body}f.RichTextResolver=$,f.RichTextSchema=D,f.getLiveStory=ze,f.handleStoryblokMessage=We,f.loadStoryblokBridge=Be,f.renderRichText=He,f.storyblok=Ve,f.storyblokEditable=Ne,f.storyblokLoader=Je,f.toCamelCase=R,f.useStoryblokApi=De,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED