@storyblok/astro 7.3.1 → 7.3.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.
|
@@ -58,14 +58,14 @@ function ye(e) {
|
|
|
58
58
|
function N(e) {
|
|
59
59
|
return `/${e.trim().replace(/^\/+/, "").replace(/\/+$/, "").replace(/\/{2,}/g, "/")}`;
|
|
60
60
|
}
|
|
61
|
-
const be = /[\p{Lu}]/u, ge = /[\p{Ll}]/u, z = /^[\p{Lu}](?![\p{Lu}])/gu, te = /([\p{Alpha}\p{N}_]|$)/u, D = /[_.\- ]+/, Ce = new RegExp("^" + D.source), Z = new RegExp(D.source + te.source, "gu"), G = new RegExp("\\d+" + te.source, "gu"),
|
|
61
|
+
const be = /[\p{Lu}]/u, ge = /[\p{Ll}]/u, z = /^[\p{Lu}](?![\p{Lu}])/gu, te = /([\p{Alpha}\p{N}_]|$)/u, D = /[_.\- ]+/, Ce = new RegExp("^" + D.source), Z = new RegExp(D.source + te.source, "gu"), G = new RegExp("\\d+" + te.source, "gu"), ve = (e, t, r, s) => {
|
|
62
62
|
let o = !1, n = !1, i = !1, l = !1;
|
|
63
63
|
for (let c = 0; c < e.length; c++) {
|
|
64
64
|
const u = e[c];
|
|
65
65
|
l = c > 2 ? e[c - 3] === "-" : !0, o && be.test(u) ? (e = e.slice(0, c) + "-" + e.slice(c), o = !1, i = n, n = !0, c++) : n && i && ge.test(u) && (!l || s) ? (e = e.slice(0, c - 1) + "-" + e.slice(c - 1), i = n, n = !1, o = !0) : (o = t(u) === u && r(u) !== u, i = n, n = r(u) === u && t(u) !== u);
|
|
66
66
|
}
|
|
67
67
|
return e;
|
|
68
|
-
},
|
|
68
|
+
}, ke = (e, t) => (z.lastIndex = 0, e.replaceAll(z, (r) => t(r))), we = (e, t) => (Z.lastIndex = 0, G.lastIndex = 0, e.replaceAll(G, (r, s, o) => ["_", "-"].includes(e.charAt(o + r.length)) ? r : t(r)).replaceAll(Z, (r, s) => t(s)));
|
|
69
69
|
function Ae(e, t) {
|
|
70
70
|
if (!(typeof e == "string" || Array.isArray(e)))
|
|
71
71
|
throw new TypeError("Expected the input to be `string | string[]`");
|
|
@@ -76,12 +76,12 @@ function Ae(e, t) {
|
|
|
76
76
|
}, Array.isArray(e) ? e = e.map((n) => n.trim()).filter((n) => n.length).join("-") : e = e.trim(), e.length === 0)
|
|
77
77
|
return "";
|
|
78
78
|
const r = t.locale === !1 ? (n) => n.toLowerCase() : (n) => n.toLocaleLowerCase(t.locale), s = t.locale === !1 ? (n) => n.toUpperCase() : (n) => n.toLocaleUpperCase(t.locale);
|
|
79
|
-
return e.length === 1 ? D.test(e) ? "" : t.pascalCase ? s(e) : r(e) : (e !== r(e) && (e =
|
|
79
|
+
return e.length === 1 ? D.test(e) ? "" : t.pascalCase ? s(e) : r(e) : (e !== r(e) && (e = ve(e, r, s, t.preserveConsecutiveUppercase)), e = e.replace(Ce, ""), e = t.preserveConsecutiveUppercase ? ke(e, r) : r(e), t.pascalCase && (e = s(e.charAt(0)) + e.slice(1)), we(e, s));
|
|
80
80
|
}
|
|
81
81
|
function $e(e) {
|
|
82
82
|
return Ae(e);
|
|
83
83
|
}
|
|
84
|
-
function
|
|
84
|
+
function Te(e, t, r, s) {
|
|
85
85
|
const o = "virtual:import-storyblok-components", n = `\0${o}`;
|
|
86
86
|
return {
|
|
87
87
|
name: "vite-plugin-import-storyblok-components",
|
|
@@ -109,7 +109,7 @@ function Ee(e, t, r, s) {
|
|
|
109
109
|
t,
|
|
110
110
|
r
|
|
111
111
|
);
|
|
112
|
-
return
|
|
112
|
+
return Ee(
|
|
113
113
|
t,
|
|
114
114
|
l,
|
|
115
115
|
c
|
|
@@ -117,7 +117,7 @@ function Ee(e, t, r, s) {
|
|
|
117
117
|
}
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
|
-
function
|
|
120
|
+
function Ee(e, t, r) {
|
|
121
121
|
const o = `${N(e)}/storyblok/**/*.astro`;
|
|
122
122
|
return `
|
|
123
123
|
// Import utilities and fallback component
|
|
@@ -227,7 +227,7 @@ function rt(e) {
|
|
|
227
227
|
vite: {
|
|
228
228
|
plugins: [
|
|
229
229
|
pe(r, s, o),
|
|
230
|
-
|
|
230
|
+
Te(
|
|
231
231
|
c || {},
|
|
232
232
|
n,
|
|
233
233
|
l,
|
|
@@ -281,19 +281,19 @@ function rt(e) {
|
|
|
281
281
|
}
|
|
282
282
|
};
|
|
283
283
|
}
|
|
284
|
-
let
|
|
284
|
+
let q;
|
|
285
285
|
async function st(e) {
|
|
286
286
|
const { action: t, story: r } = e || {};
|
|
287
287
|
if (t === "input" && r) {
|
|
288
288
|
const s = async () => {
|
|
289
|
-
|
|
289
|
+
J("storyblok-live-preview-updating", { story: r });
|
|
290
290
|
const n = await Ie(r), i = document.body;
|
|
291
291
|
if (n.outerHTML === i.outerHTML)
|
|
292
292
|
return;
|
|
293
293
|
const l = document.querySelector('[data-blok-focused="true"]');
|
|
294
|
-
Se(i, n, l),
|
|
294
|
+
Se(i, n, l), J("storyblok-live-preview-updated", { story: r });
|
|
295
295
|
};
|
|
296
|
-
clearTimeout(
|
|
296
|
+
clearTimeout(q), q = setTimeout(s, 500);
|
|
297
297
|
}
|
|
298
298
|
["published", "change"].includes(e == null ? void 0 : e.action) && location.reload();
|
|
299
299
|
}
|
|
@@ -319,11 +319,11 @@ async function Ie(e) {
|
|
|
319
319
|
})).text();
|
|
320
320
|
return new DOMParser().parseFromString(r, "text/html").body;
|
|
321
321
|
}
|
|
322
|
-
function
|
|
322
|
+
function J(e, t) {
|
|
323
323
|
document.dispatchEvent(new CustomEvent(e, { detail: t }));
|
|
324
324
|
}
|
|
325
325
|
var Re = Object.defineProperty, Oe = (e, t, r) => t in e ? Re(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, g = (e, t, r) => Oe(e, typeof t != "symbol" ? t + "" : t, r);
|
|
326
|
-
let
|
|
326
|
+
let v = /* @__PURE__ */ function(e) {
|
|
327
327
|
return e.DOCUMENT = "doc", e.HEADING = "heading", e.PARAGRAPH = "paragraph", e.QUOTE = "blockquote", e.OL_LIST = "ordered_list", e.UL_LIST = "bullet_list", e.LIST_ITEM = "list_item", e.CODE_BLOCK = "code_block", e.HR = "horizontal_rule", e.BR = "hard_break", e.IMAGE = "image", e.EMOJI = "emoji", e.COMPONENT = "blok", e.TABLE = "table", e.TABLE_ROW = "tableRow", e.TABLE_CELL = "tableCell", e.TABLE_HEADER = "tableHeader", e;
|
|
328
328
|
}({}), $ = /* @__PURE__ */ function(e) {
|
|
329
329
|
return e.BOLD = "bold", e.STRONG = "strong", e.STRIKE = "strike", e.UNDERLINE = "underline", e.ITALIC = "italic", e.CODE = "code", e.LINK = "link", e.ANCHOR = "anchor", e.STYLED = "styled", e.SUPERSCRIPT = "superscript", e.SUBSCRIPT = "subscript", e.TEXT_STYLE = "textStyle", e.HIGHLIGHT = "highlight", e;
|
|
@@ -363,7 +363,7 @@ function Me(e, t) {
|
|
|
363
363
|
typeof c != "number" || c <= u || c >= f ? console.warn(`[StoryblokRichText] - ${m.charAt(0).toUpperCase() + m.slice(1)} value must be a number between ${u} and ${f} (inclusive)`) : A.push(`${m}(${c})`);
|
|
364
364
|
}
|
|
365
365
|
if (typeof t == "object") {
|
|
366
|
-
if (typeof t.width == "number" && t.width
|
|
366
|
+
if (t.width !== void 0 && (typeof t.width == "number" && t.width >= 0 ? (o.width = t.width, r = t.width) : console.warn("[StoryblokRichText] - Width value must be a number greater than or equal to 0")), t.height !== void 0 && (typeof t.height == "number" && t.height >= 0 ? (o.height = t.height, s = t.height) : console.warn("[StoryblokRichText] - Height value must be a number greater than or equal to 0")), t.height === 0 && t.width === 0 && (delete o.width, delete o.height, console.warn("[StoryblokRichText] - Width and height values cannot both be 0")), t.loading && ["lazy", "eager"].includes(t.loading) && (o.loading = t.loading), t.class && (o.class = t.class), t.filters) {
|
|
367
367
|
const { filters: c } = t || {}, { blur: u, brightness: f, fill: m, format: A, grayscale: _, quality: w, rotate: L } = c || {};
|
|
368
368
|
u && i(u, 0, 100, "blur", n), w && i(w, 0, 100, "quality", n), f && i(f, 0, 100, "brightness", n), m && n.push(`fill(${m})`), _ && n.push("grayscale()"), L && [
|
|
369
369
|
0,
|
|
@@ -388,7 +388,7 @@ function Me(e, t) {
|
|
|
388
388
|
}).join(", ")), t.sizes && (o.sizes = t.sizes.join(", "));
|
|
389
389
|
}
|
|
390
390
|
let l = `${e}/m/`;
|
|
391
|
-
return r > 0
|
|
391
|
+
return (r > 0 || s > 0) && (l = `${l}${r}x${s}/`), n.length > 0 && (l = `${l}filters:${n.join(":")}`), {
|
|
392
392
|
src: l,
|
|
393
393
|
attrs: o
|
|
394
394
|
};
|
|
@@ -414,18 +414,18 @@ function De(e = {}) {
|
|
|
414
414
|
return d.render(a, p, h.children || null);
|
|
415
415
|
}, f = (a, h) => {
|
|
416
416
|
const { src: d, alt: p, title: y, srcset: C, sizes: b } = a.attrs || {};
|
|
417
|
-
let
|
|
417
|
+
let T = d, k = {};
|
|
418
418
|
if (n) {
|
|
419
419
|
const { src: ue, attrs: he } = Me(d, n);
|
|
420
|
-
|
|
420
|
+
T = ue, k = he;
|
|
421
421
|
}
|
|
422
422
|
const I = {
|
|
423
|
-
src:
|
|
423
|
+
src: T,
|
|
424
424
|
alt: p,
|
|
425
425
|
title: y,
|
|
426
426
|
srcset: C,
|
|
427
427
|
sizes: b,
|
|
428
|
-
...
|
|
428
|
+
...k
|
|
429
429
|
};
|
|
430
430
|
return h.render("img", R(I));
|
|
431
431
|
}, m = (a, h) => {
|
|
@@ -446,12 +446,12 @@ function De(e = {}) {
|
|
|
446
446
|
"data-emoji": (C = a.attrs) == null ? void 0 : C.emoji
|
|
447
447
|
}, b);
|
|
448
448
|
}, _ = (a, h) => h.render("pre", a.attrs || {}, h.render("code", {}, a.children || "")), w = (a, h = !1) => ({ text: d, attrs: p }, y) => {
|
|
449
|
-
const { class: C, id: b, ...
|
|
449
|
+
const { class: C, id: b, ...T } = p || {}, k = h ? {
|
|
450
450
|
class: C,
|
|
451
451
|
id: b,
|
|
452
|
-
style: je(
|
|
452
|
+
style: je(T) || void 0
|
|
453
453
|
} : p || {};
|
|
454
|
-
return y.render(a, R(
|
|
454
|
+
return y.render(a, R(k), d);
|
|
455
455
|
}, L = (a) => H(a), S = (a) => {
|
|
456
456
|
const { marks: h, ...d } = a;
|
|
457
457
|
if ("text" in a) {
|
|
@@ -488,8 +488,8 @@ function De(e = {}) {
|
|
|
488
488
|
b = p;
|
|
489
489
|
break;
|
|
490
490
|
}
|
|
491
|
-
const
|
|
492
|
-
return b && (
|
|
491
|
+
const T = { ...C };
|
|
492
|
+
return b && (T.href = b), h.render("a", T, a.text);
|
|
493
493
|
}, oe = (a, h) => {
|
|
494
494
|
var d, p;
|
|
495
495
|
return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), h.render("span", {
|
|
@@ -504,39 +504,39 @@ function De(e = {}) {
|
|
|
504
504
|
const d = c(a.attrs);
|
|
505
505
|
return h.render("tr", d, a.children);
|
|
506
506
|
}, ae = (a, h) => {
|
|
507
|
-
const { colspan: d, rowspan: p, colwidth: y, backgroundColor: C, textAlign: b, ...
|
|
508
|
-
y &&
|
|
507
|
+
const { colspan: d, rowspan: p, colwidth: y, backgroundColor: C, textAlign: b, ...T } = a.attrs || {}, k = [];
|
|
508
|
+
y && k.push(`width: ${y}px;`), C && k.push(`background-color: ${C};`), b && k.push(`text-align: ${b};`);
|
|
509
509
|
const I = {
|
|
510
|
-
...
|
|
510
|
+
...T,
|
|
511
511
|
...d > 1 ? { colspan: d } : {},
|
|
512
512
|
...p > 1 ? { rowspan: p } : {},
|
|
513
|
-
...
|
|
513
|
+
...k.length > 0 ? { style: k.join(" ") } : {}
|
|
514
514
|
};
|
|
515
515
|
return h.render("td", R(I), a.children);
|
|
516
516
|
}, le = (a, h) => {
|
|
517
|
-
const { colspan: d, rowspan: p, colwidth: y, backgroundColor: C, textAlign: b, ...
|
|
518
|
-
y &&
|
|
517
|
+
const { colspan: d, rowspan: p, colwidth: y, backgroundColor: C, textAlign: b, ...T } = a.attrs || {}, k = [];
|
|
518
|
+
y && k.push(`width: ${y}px;`), C && k.push(`background-color: ${C};`), b && k.push(`text-align: ${b};`);
|
|
519
519
|
const I = {
|
|
520
|
-
...
|
|
520
|
+
...T,
|
|
521
521
|
...d > 1 ? { colspan: d } : {},
|
|
522
522
|
...p > 1 ? { rowspan: p } : {},
|
|
523
|
-
...
|
|
523
|
+
...k.length > 0 ? { style: k.join(" ") } : {}
|
|
524
524
|
};
|
|
525
525
|
return h.render("th", R(I), a.children);
|
|
526
526
|
}, B = /* @__PURE__ */ new Map([
|
|
527
|
-
[
|
|
528
|
-
[
|
|
529
|
-
[
|
|
530
|
-
[
|
|
531
|
-
[
|
|
532
|
-
[
|
|
533
|
-
[
|
|
534
|
-
[
|
|
535
|
-
[
|
|
536
|
-
[
|
|
537
|
-
[
|
|
538
|
-
[
|
|
539
|
-
[
|
|
527
|
+
[v.DOCUMENT, u("")],
|
|
528
|
+
[v.HEADING, m],
|
|
529
|
+
[v.PARAGRAPH, u("p")],
|
|
530
|
+
[v.UL_LIST, u("ul")],
|
|
531
|
+
[v.OL_LIST, u("ol")],
|
|
532
|
+
[v.LIST_ITEM, u("li")],
|
|
533
|
+
[v.IMAGE, f],
|
|
534
|
+
[v.EMOJI, A],
|
|
535
|
+
[v.CODE_BLOCK, _],
|
|
536
|
+
[v.HR, u("hr")],
|
|
537
|
+
[v.BR, u("br")],
|
|
538
|
+
[v.QUOTE, u("blockquote")],
|
|
539
|
+
[v.COMPONENT, oe],
|
|
540
540
|
[Pe.TEXT, S],
|
|
541
541
|
[$.LINK, V],
|
|
542
542
|
[$.ANCHOR, V],
|
|
@@ -550,10 +550,10 @@ function De(e = {}) {
|
|
|
550
550
|
[$.SUPERSCRIPT, w("sup")],
|
|
551
551
|
[$.SUBSCRIPT, w("sub")],
|
|
552
552
|
[$.HIGHLIGHT, w("mark")],
|
|
553
|
-
[
|
|
554
|
-
[
|
|
555
|
-
[
|
|
556
|
-
[
|
|
553
|
+
[v.TABLE, ne],
|
|
554
|
+
[v.TABLE_ROW, ie],
|
|
555
|
+
[v.TABLE_CELL, ae],
|
|
556
|
+
[v.TABLE_HEADER, le]
|
|
557
557
|
]), F = new Map([...B, ...Object.entries(o).map(([a, h]) => [a, h])]), ce = () => ({
|
|
558
558
|
render: (a, h = {}, d) => {
|
|
559
559
|
if (i && a) {
|
|
@@ -645,7 +645,7 @@ const X = (e = "") => e.includes("/cdn/"), Fe = (e, t = 25, r = 1) => ({
|
|
|
645
645
|
}), ze = (e) => new Promise((t) => setTimeout(t, e)), Ze = (e = 0, t) => Array.from({ length: e }, t), Ge = (e = 0, t = e) => {
|
|
646
646
|
const r = Math.abs(t - e) || 0, s = e < t ? 1 : -1;
|
|
647
647
|
return Ze(r, (o, n) => n * s + e);
|
|
648
|
-
},
|
|
648
|
+
}, qe = async (e, t) => Promise.all(e.map(t)), Je = (e = [], t) => e.map(t).reduce((r, s) => [...r, ...s], []), U = (e, t, r) => {
|
|
649
649
|
const s = [];
|
|
650
650
|
for (const o in e) {
|
|
651
651
|
if (!Object.prototype.hasOwnProperty.call(e, o)) continue;
|
|
@@ -766,7 +766,7 @@ const ee = "SB-Agent", j = {
|
|
|
766
766
|
PUBLISHED: "published"
|
|
767
767
|
};
|
|
768
768
|
let x = {};
|
|
769
|
-
const
|
|
769
|
+
const E = {};
|
|
770
770
|
var Xe = class {
|
|
771
771
|
/**
|
|
772
772
|
*
|
|
@@ -794,7 +794,7 @@ var Xe = class {
|
|
|
794
794
|
});
|
|
795
795
|
}
|
|
796
796
|
parseParams(e) {
|
|
797
|
-
return e.token || (e.token = this.getToken()), e.cv || (e.cv =
|
|
797
|
+
return e.token || (e.token = this.getToken()), e.cv || (e.cv = E[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
|
|
798
798
|
}
|
|
799
799
|
factoryParamOptions(e, t) {
|
|
800
800
|
return X(e) ? this.parseParams(t) : t;
|
|
@@ -813,8 +813,8 @@ var Xe = class {
|
|
|
813
813
|
async getAll(e, t = {}, r, s) {
|
|
814
814
|
const o = (t == null ? void 0 : t.per_page) || 25, n = `/${e}`.replace(/\/$/, ""), i = r ?? n.substring(n.lastIndexOf("/") + 1);
|
|
815
815
|
t.version = t.version || this.version;
|
|
816
|
-
const l = 1, c = await this.makeRequest(n, t, o, l, s), u = c.total ? Math.ceil(c.total / (c.perPage || o)) : 1, f = await
|
|
817
|
-
return
|
|
816
|
+
const l = 1, c = await this.makeRequest(n, t, o, l, s), u = c.total ? Math.ceil(c.total / (c.perPage || o)) : 1, f = await qe(Ge(l, u), (m) => this.makeRequest(n, t, o, m + 1, s));
|
|
817
|
+
return Je([c, ...f], (m) => Object.values(m.data[i]));
|
|
818
818
|
}
|
|
819
819
|
post(e, t = {}, r) {
|
|
820
820
|
const s = `/${e}`;
|
|
@@ -1020,7 +1020,7 @@ var Xe = class {
|
|
|
1020
1020
|
}
|
|
1021
1021
|
t.version === "published" && e !== "/cdn/spaces/me" && await n.set(o, f);
|
|
1022
1022
|
const m = this.cache.clear === "onpreview" && t.version === "draft" || this.cache.clear === "auto";
|
|
1023
|
-
return t.token && f.data.cv && (m &&
|
|
1023
|
+
return t.token && f.data.cv && (m && E[t.token] && E[t.token] !== f.data.cv && await this.flushCache(), E[t.token] = f.data.cv), i(f);
|
|
1024
1024
|
} catch (u) {
|
|
1025
1025
|
if (u.response && u.status === 429 && (r = typeof r > "u" ? 0 : r + 1, r < this.maxRetries))
|
|
1026
1026
|
return console.log(`Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`), await ze(this.retriesDelay), this.cacheResponse(e, t, r).then(i).catch(l);
|
|
@@ -1032,16 +1032,16 @@ var Xe = class {
|
|
|
1032
1032
|
return this.client.setFetchOptions(s), this.client[e](t, r);
|
|
1033
1033
|
}
|
|
1034
1034
|
cacheVersions() {
|
|
1035
|
-
return
|
|
1035
|
+
return E;
|
|
1036
1036
|
}
|
|
1037
1037
|
cacheVersion() {
|
|
1038
|
-
return
|
|
1038
|
+
return E[this.accessToken];
|
|
1039
1039
|
}
|
|
1040
1040
|
setCacheVersion(e) {
|
|
1041
|
-
this.accessToken && (
|
|
1041
|
+
this.accessToken && (E[this.accessToken] = e);
|
|
1042
1042
|
}
|
|
1043
1043
|
clearCacheVersion() {
|
|
1044
|
-
this.accessToken && (
|
|
1044
|
+
this.accessToken && (E[this.accessToken] = 0);
|
|
1045
1045
|
}
|
|
1046
1046
|
cacheProvider() {
|
|
1047
1047
|
switch (this.cache.type) {
|
|
@@ -1089,8 +1089,8 @@ var Xe = class {
|
|
|
1089
1089
|
if (Array.isArray(r)) return r.map((o) => t(o));
|
|
1090
1090
|
let s = { ...r };
|
|
1091
1091
|
s.fieldtype === "asset" && Array.isArray(e.data.assets) && (s = {
|
|
1092
|
-
...s,
|
|
1093
|
-
...
|
|
1092
|
+
...e.data.assets.find((o) => o.id === s.id),
|
|
1093
|
+
...s
|
|
1094
1094
|
});
|
|
1095
1095
|
for (const o in s) typeof s[o] == "object" && (s[o] = t(s[o]));
|
|
1096
1096
|
return s;
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
apiOptions: ${JSON.stringify(r)},
|
|
12
12
|
});
|
|
13
13
|
export const storyblokApiInstance = storyblokApi;
|
|
14
|
-
`}}}function ce(e){const t="virtual:storyblok-options",r=`\0${t}`;return{name:"vite-plugin-storyblok-options",async resolveId(s){if(s===t)return r},async load(s){if(s===r)return`export default ${JSON.stringify(e)}`}}}function ue(){if(!(globalThis!=null&&globalThis.storyblokApiInstance))throw new Error("storyblokApiInstance has not been initialized correctly");return globalThis.storyblokApiInstance}async function
|
|
14
|
+
`}}}function ce(e){const t="virtual:storyblok-options",r=`\0${t}`;return{name:"vite-plugin-storyblok-options",async resolveId(s){if(s===t)return r},async load(s){if(s===r)return`export default ${JSON.stringify(e)}`}}}function ue(){if(!(globalThis!=null&&globalThis.storyblokApiInstance))throw new Error("storyblokApiInstance has not been initialized correctly");return globalThis.storyblokApiInstance}async function he(e){let t=null;return e&&e.locals._storyblok_preview_data&&(t=e.locals._storyblok_preview_data),t}function de(e){return typeof e=="object"?`const storyblokInstance = new StoryblokBridge(${JSON.stringify(e)});`:"const storyblokInstance = new StoryblokBridge();"}function pe(e){return e.endsWith(".astro")?e:`${e}.astro`}function N(e){return`/${e.trim().replace(/^\/+/,"").replace(/\/+$/,"").replace(/\/{2,}/g,"/")}`}const fe=/[\p{Lu}]/u,me=/[\p{Ll}]/u,F=/^[\p{Lu}](?![\p{Lu}])/gu,z=/([\p{Alpha}\p{N}_]|$)/u,M=/[_.\- ]+/,ye=new RegExp("^"+M.source),Z=new RegExp(M.source+z.source,"gu"),G=new RegExp("\\d+"+z.source,"gu"),be=(e,t,r,s)=>{let o=!1,n=!1,i=!1,l=!1;for(let c=0;c<e.length;c++){const u=e[c];l=c>2?e[c-3]==="-":!0,o&&fe.test(u)?(e=e.slice(0,c)+"-"+e.slice(c),o=!1,i=n,n=!0,c++):n&&i&&me.test(u)&&(!l||s)?(e=e.slice(0,c-1)+"-"+e.slice(c-1),i=n,n=!1,o=!0):(o=t(u)===u&&r(u)!==u,i=n,n=r(u)===u&&t(u)!==u)}return e},ge=(e,t)=>(F.lastIndex=0,e.replaceAll(F,r=>t(r))),Ce=(e,t)=>(Z.lastIndex=0,G.lastIndex=0,e.replaceAll(G,(r,s,o)=>["_","-"].includes(e.charAt(o+r.length))?r:t(r)).replaceAll(Z,(r,s)=>t(s)));function ke(e,t){if(!(typeof e=="string"||Array.isArray(e)))throw new TypeError("Expected the input to be `string | string[]`");if(t={pascalCase:!1,preserveConsecutiveUppercase:!1,...t},Array.isArray(e)?e=e.map(n=>n.trim()).filter(n=>n.length).join("-"):e=e.trim(),e.length===0)return"";const r=t.locale===!1?n=>n.toLowerCase():n=>n.toLocaleLowerCase(t.locale),s=t.locale===!1?n=>n.toUpperCase():n=>n.toLocaleUpperCase(t.locale);return e.length===1?M.test(e)?"":t.pascalCase?s(e):r(e):(e!==r(e)&&(e=be(e,r,s,t.preserveConsecutiveUppercase)),e=e.replace(ye,""),e=t.preserveConsecutiveUppercase?ge(e,r):r(e),t.pascalCase&&(e=s(e.charAt(0))+e.slice(1)),Ce(e,s))}function q(e){return ke(e)}function ve(e,t,r,s){const o="virtual:import-storyblok-components",n=`\0${o}`;return{name:"vite-plugin-import-storyblok-components",async resolveId(i){if(i===o)return n},async load(i){if(i!==n)return;const l=await Ae(this,t,r,s),c=await Te(this,e,t,r);return we(t,l,c)}}}function we(e,t,r){const o=`${N(e)}/storyblok/**/*.astro`;return`
|
|
15
15
|
// Import utilities and fallback component
|
|
16
16
|
import { toCamelCase } from '@storyblok/astro';
|
|
17
17
|
${t}
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
|
|
48
48
|
// Export the components object for use in Storyblok initialization
|
|
49
49
|
export { storyblokComponents };
|
|
50
|
-
`.trim()}async function Ae(e,t,r,s){if(!r)return"";if(s){const o=
|
|
50
|
+
`.trim()}async function Ae(e,t,r,s){if(!r)return"";if(s){const o=J(t,s);if(!await e.resolve(o))throw new Error(`Custom fallback component could not be found. Does "${o}" exist?`);return`import FallbackComponent from '${o}';`}return"import FallbackComponent from '@storyblok/astro/FallbackComponent.astro';"}async function Te(e,t,r,s){const o=[];for await(const[n,i]of Object.entries(t)){const l=J(r,i),c=await e.resolve(l);if(c)o.push(`import ${q(n)} from "${c.id}"`);else if(!s)throw new Error(`Component could not be found for blok "${n}"! Does "${l}" exist?`)}return o}function J(e,t){const s=`${N(e)}${N(t)}`;return pe(s)}function $e(e){const t={useCustomApi:!1,bridge:!0,componentsDir:"src",enableFallbackComponent:!1,livePreview:!1,...e},{accessToken:r,useCustomApi:s,apiOptions:o,componentsDir:n,customFallbackComponent:i,enableFallbackComponent:l,components:c,bridge:u,livePreview:f}=t,m=de(t.bridge);return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:T,updateConfig:R,addDevToolbarApp:A,addMiddleware:L,config:O})=>{if(R({vite:{plugins:[le(r,s,o),ve(c||{},n,l,i),ce(t)]}}),f&&(O==null?void 0:O.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.");T("page-ssr",`
|
|
51
51
|
import { storyblokApiInstance } from "virtual:storyblok-init";
|
|
52
52
|
globalThis.storyblokApiInstance = storyblokApiInstance;
|
|
53
53
|
`),u&&!f&&T("page",`import { loadStoryblokBridge } from "@storyblok/astro";
|
|
@@ -66,4 +66,4 @@
|
|
|
66
66
|
${m}
|
|
67
67
|
storyblokInstance.on(["published", "change", "input"], handleStoryblokMessage);
|
|
68
68
|
});
|
|
69
|
-
`),S({entrypoint:"@storyblok/astro/middleware.ts",order:"pre"})),A({id:"storyblok",name:"Storyblok",icon:_,entrypoint:"@storyblok/astro/toolbarApp.ts"})}}}}let W;async function Ee(e){const{action:t,story:r}=e||{};if(t==="input"&&r){const s=async()=>{Y("storyblok-live-preview-updating",{story:r});const n=await Se(r),i=document.body;if(n.outerHTML===i.outerHTML)return;const l=document.querySelector('[data-blok-focused="true"]');Le(i,n,l),Y("storyblok-live-preview-updated",{story:r})};clearTimeout(W),W=setTimeout(s,500)}["published","change"].includes(e==null?void 0:e.action)&&location.reload()}function Le(e,t,r){if(r){const s=r.getAttribute("data-blok-uid"),o=t.querySelector(`[data-blok-uid="${s}"]`);o&&(o.setAttribute("data-blok-focused","true"),r.replaceWith(o))}else e.replaceWith(t)}async function Se(e){const r=await(await fetch(location.href,{method:"POST",body:JSON.stringify({...e,is_storyblok_preview:!0}),headers:{"Content-Type":"application/json"}})).text();return new DOMParser().parseFromString(r,"text/html").body}function Y(e,t){document.dispatchEvent(new CustomEvent(e,{detail:t}))}var _e=Object.defineProperty,Ie=(e,t,r)=>t in e?_e(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,g=(e,t,r)=>Ie(e,typeof t!="symbol"?t+"":t,r);let k=function(e){return e.DOCUMENT="doc",e.HEADING="heading",e.PARAGRAPH="paragraph",e.QUOTE="blockquote",e.OL_LIST="ordered_list",e.UL_LIST="bullet_list",e.LIST_ITEM="list_item",e.CODE_BLOCK="code_block",e.HR="horizontal_rule",e.BR="hard_break",e.IMAGE="image",e.EMOJI="emoji",e.COMPONENT="blok",e.TABLE="table",e.TABLE_ROW="tableRow",e.TABLE_CELL="tableCell",e.TABLE_HEADER="tableHeader",e}({}),$=function(e){return e.BOLD="bold",e.STRONG="strong",e.STRIKE="strike",e.UNDERLINE="underline",e.ITALIC="italic",e.CODE="code",e.LINK="link",e.ANCHOR="anchor",e.STYLED="styled",e.SUPERSCRIPT="superscript",e.SUBSCRIPT="subscript",e.TEXT_STYLE="textStyle",e.HIGHLIGHT="highlight",e}({}),Re=function(e){return e.TEXT="text",e}({}),H=function(e){return e.URL="url",e.STORY="story",e.ASSET="asset",e.EMAIL="email",e}({});const Oe=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],Pe=(e={})=>Object.keys(e).map(t=>`${t}="${e[t]}"`).join(" "),He=(e={})=>Object.keys(e).map(t=>`${t}: ${e[t]}`).join("; ");function je(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const I=e=>Object.fromEntries(Object.entries(e).filter(([t,r])=>r!==void 0));function xe(e,t){if(!t)return{src:e,attrs:{}};let r=0,s=0;const o={},n=[];function i(c,u,f,m,T){typeof c!="number"||c<=u||c>=f?console.warn(`[StoryblokRichText] - ${m.charAt(0).toUpperCase()+m.slice(1)} value must be a number between ${u} and ${f} (inclusive)`):T.push(`${m}(${c})`)}if(typeof t=="object"){if(typeof t.width=="number"&&t.width>0?(o.width=t.width,r=t.width):console.warn("[StoryblokRichText] - Width value must be a number greater than 0"),t.height&&typeof t.height=="number"&&t.height>0?(o.height=t.height,s=t.height):console.warn("[StoryblokRichText] - Height value must be a number greater than 0"),t.loading&&["lazy","eager"].includes(t.loading)&&(o.loading=t.loading),t.class&&(o.class=t.class),t.filters){const{filters:c}=t||{},{blur:u,brightness:f,fill:m,format:T,grayscale:R,quality:A,rotate:S}=c||{};u&&i(u,0,100,"blur",n),A&&i(A,0,100,"quality",n),f&&i(f,0,100,"brightness",n),m&&n.push(`fill(${m})`),R&&n.push("grayscale()"),S&&[0,90,180,270].includes(t.filters.rotate||0)&&n.push(`rotate(${S})`),T&&["webp","png","jpeg"].includes(T)&&n.push(`format(${T})`)}t.srcset&&(o.srcset=t.srcset.map(c=>{if(typeof c=="number")return`${e}/m/${c}x0/${n.length>0?`filters:${n.join(":")}`:""} ${c}w`;if(Array.isArray(c)&&c.length===2){const[u,f]=c;return`${e}/m/${u}x${f}/${n.length>0?`filters:${n.join(":")}`:""} ${u}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),t.sizes&&(o.sizes=t.sizes.join(", "))}let l=`${e}/m/`;return r>0&&s>0&&(l=`${l}${r}x${s}/`),n.length>0&&(l=`${l}filters:${n.join(":")}`),{src:l,attrs:o}}function K(e,t={},r){const s=Pe(t),o=s?`${e} ${s}`:e,n=Array.isArray(r)?r.join(""):r||"";if(e){if(Oe.includes(e))return`<${o}>`}else return n;return`<${o}>${n}</${e}>`}function X(e={}){const t=new Map,{renderFn:r=K,textFn:s=je,resolvers:o={},optimizeImages:n=!1,keyedResolvers:i=!1}=e,l=r!==K,c=(a={})=>{const{textAlign:d,class:h,id:p,style:y,...C}=a,b=[];return y&&b.push(y.endsWith(";")?y:`${y};`),d&&b.push(`text-align: ${d};`),I({...C,class:h,id:p,...b.length>0?{style:b.join(" ")}:{}})},u=a=>(d,h)=>{const p=c(d.attrs);return h.render(a,p,d.children||null)},f=(a,d)=>{const{src:h,alt:p,title:y,srcset:C,sizes:b}=a.attrs||{};let E=h,w={};if(n){const{src:lt,attrs:ct}=xe(h,n);E=lt,w=ct}const P={src:E,alt:p,title:y,srcset:C,sizes:b,...w};return d.render("img",I(P))},m=(a,d)=>{const{level:h,...p}=a.attrs||{},y=c(p);return d.render(`h${h}`,y,a.children)},T=(a,d)=>{var h,p,y,C;const b=d.render("img",{src:(h=a.attrs)==null?void 0:h.fallbackImage,alt:(p=a.attrs)==null?void 0:p.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"});return d.render("span",{"data-type":"emoji","data-name":(y=a.attrs)==null?void 0:y.name,"data-emoji":(C=a.attrs)==null?void 0:C.emoji},b)},R=(a,d)=>d.render("pre",a.attrs||{},d.render("code",{},a.children||"")),A=(a,d=!1)=>({text:h,attrs:p},y)=>{const{class:C,id:b,...E}=p||{},w=d?{class:C,id:b,style:He(E)||void 0}:p||{};return y.render(a,I(w),h)},S=a=>B(a),O=a=>{const{marks:d,...h}=a;if("text"in a){if(d)return d.reduce((y,C)=>S({...C,text:y}),S({...h,children:h.children}));const p=a.attrs||{};if(i){const y=t.get("txt")||0;t.set("txt",y+1),p.key=`txt-${y}`}return s(h.text,p)}return""},ne=(a,d)=>{const{linktype:h,href:p,anchor:y,...C}=a.attrs||{};let b="";switch(h){case H.ASSET:case H.URL:b=p;break;case H.EMAIL:b=`mailto:${p}`;break;case H.STORY:b=p,y&&(b=`${b}#${y}`);break;default:b=p;break}const E={...C};return b&&(E.href=b),d.render("a",E,a.text)},rt=(a,d)=>{var h,p;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),d.render("span",{blok:(h=a==null?void 0:a.attrs)==null?void 0:h.body[0],id:(p=a.attrs)==null?void 0:p.id,style:"display: none"})},st=(a,d)=>{const h=c(a.attrs),p=a.children||null;return d.render("table",h,d.render("tbody",{},p))},ot=(a,d)=>{const h=c(a.attrs);return d.render("tr",h,a.children)},nt=(a,d)=>{const{colspan:h,rowspan:p,colwidth:y,backgroundColor:C,textAlign:b,...E}=a.attrs||{},w=[];y&&w.push(`width: ${y}px;`),C&&w.push(`background-color: ${C};`),b&&w.push(`text-align: ${b};`);const P={...E,...h>1?{colspan:h}:{},...p>1?{rowspan:p}:{},...w.length>0?{style:w.join(" ")}:{}};return d.render("td",I(P),a.children)},it=(a,d)=>{const{colspan:h,rowspan:p,colwidth:y,backgroundColor:C,textAlign:b,...E}=a.attrs||{},w=[];y&&w.push(`width: ${y}px;`),C&&w.push(`background-color: ${C};`),b&&w.push(`text-align: ${b};`);const P={...E,...h>1?{colspan:h}:{},...p>1?{rowspan:p}:{},...w.length>0?{style:w.join(" ")}:{}};return d.render("th",I(P),a.children)},ie=new Map([[k.DOCUMENT,u("")],[k.HEADING,m],[k.PARAGRAPH,u("p")],[k.UL_LIST,u("ul")],[k.OL_LIST,u("ol")],[k.LIST_ITEM,u("li")],[k.IMAGE,f],[k.EMOJI,T],[k.CODE_BLOCK,R],[k.HR,u("hr")],[k.BR,u("br")],[k.QUOTE,u("blockquote")],[k.COMPONENT,rt],[Re.TEXT,O],[$.LINK,ne],[$.ANCHOR,ne],[$.STYLED,A("span",!0)],[$.BOLD,A("strong")],[$.TEXT_STYLE,A("span",!0)],[$.ITALIC,A("em")],[$.UNDERLINE,A("u")],[$.STRIKE,A("s")],[$.CODE,A("code")],[$.SUPERSCRIPT,A("sup")],[$.SUBSCRIPT,A("sub")],[$.HIGHLIGHT,A("mark")],[k.TABLE,st],[k.TABLE_ROW,ot],[k.TABLE_CELL,nt],[k.TABLE_HEADER,it]]),ae=new Map([...ie,...Object.entries(o).map(([a,d])=>[a,d])]),at=()=>({render:(a,d={},h)=>{if(i&&a){const p=t.get(a)||0;t.set(a,p+1),d.key=`${a}-${p}`}return r(a,d,h)},originalResolvers:ie,mergedResolvers:ae});function x(a){const d=ae.get(a.type);if(!d)return console.error("<Storyblok>",`No resolver found for node type ${a.type}`),"";const h=at();if(a.type==="text")return d(a,h);const p=a.content?a.content.map(B):void 0;return d({...a,children:p},h)}function B(a){return a.type==="doc"?l?a.content.map(x):a.content.map(x).join(""):Array.isArray(a)?a.map(x):x(a)}return{render:B}}let Q=!1;const ee=[],te=e=>new Promise((t,r)=>{if(typeof window>"u"){r(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));return}if(window.storyblokRegisterEvent=o=>{if(!window.location.search.includes("_storyblok")){console.warn("You are not in Draft Mode or in the Visual Editor.");return}Q?o():ee.push(o)},document.getElementById("storyblok-javascript-bridge")){t(void 0);return}const s=document.createElement("script");s.async=!0,s.src=e,s.id="storyblok-javascript-bridge",s.onerror=o=>r(o),s.onload=o=>{ee.forEach(n=>n()),Q=!0,t(o)},document.getElementsByTagName("head")[0].appendChild(s)});var Ne=class extends Error{constructor(e){super(e),this.name="AbortError"}};function Me(e,t,r){if(!Number.isFinite(t))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(r))throw new TypeError("Expected `interval` to be a finite number");const s=[];let o=[],n=0,i=!1;const l=async()=>{n++;const u=s.shift();if(u)try{const m=await e(...u.args);u.resolve(m)}catch(m){u.reject(m)}const f=setTimeout(()=>{n--,s.length>0&&l(),o=o.filter(m=>m!==f)},r);o.includes(f)||o.push(f)},c=(...u)=>i?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((f,m)=>{s.push({resolve:f,reject:m,args:u}),n<t&&l()});return c.abort=()=>{i=!0,o.forEach(clearTimeout),o=[],s.forEach(u=>u.reject(()=>new Ne("Throttle function aborted"))),s.length=0},c}var De=Me;const re=(e="")=>e.includes("/cdn/"),Ue=(e,t=25,r=1)=>({...e,per_page:t,page:r}),Ve=e=>new Promise(t=>setTimeout(t,e)),Be=(e=0,t)=>Array.from({length:e},t),Fe=(e=0,t=e)=>{const r=Math.abs(t-e)||0,s=e<t?1:-1;return Be(r,(o,n)=>n*s+e)},ze=async(e,t)=>Promise.all(e.map(t)),Ze=(e=[],t)=>e.map(t).reduce((r,s)=>[...r,...s],[]),D=(e,t,r)=>{const s=[];for(const o in e){if(!Object.prototype.hasOwnProperty.call(e,o))continue;const n=e[o];if(n==null)continue;const i=r?"":encodeURIComponent(o);let l;typeof n=="object"?l=D(n,t?t+encodeURIComponent(`[${i}]`):i,Array.isArray(n)):l=`${t?t+encodeURIComponent(`[${i}]`):i}=${encodeURIComponent(n)}`,s.push(l)}return s.join("&")},se=e=>{const t={eu:"api.storyblok.com",us:"api-us.storyblok.com",cn:"app.storyblokchina.cn",ap:"api-ap.storyblok.com",ca:"api-ca.storyblok.com"};return t[e]??t.eu};var Ge=class{constructor(e){g(this,"baseURL"),g(this,"timeout"),g(this,"headers"),g(this,"responseInterceptor"),g(this,"fetch"),g(this,"ejectInterceptor"),g(this,"url"),g(this,"parameters"),g(this,"fetchOptions"),this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={},this.fetchOptions={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t??{},this._methodHandler("delete")}async _responseHandler(e){const t=[],r={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(s=>{r.data=s});for(const s of e.headers.entries())t[s[0]]=s[1];return r.headers={...t},r.status=e.status,r.statusText=e.statusText,r}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,r=null;e==="get"?t=`${this.baseURL}${this.url}?${D(this.parameters)}`:r=JSON.stringify(this.parameters);const s=new URL(t),o=new AbortController,{signal:n}=o;let i;this.timeout&&(i=setTimeout(()=>o.abort(),this.timeout));try{const l=await this.fetch(`${s}`,{method:e,headers:this.headers,body:r,signal:n,...this.fetchOptions});this.timeout&&clearTimeout(i);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}_normalizeErrorMessage(e){if(Array.isArray(e))return e[0]||"Unknown error";if(e&&typeof e=="object"){if(e.error)return e.error;for(const t in e){if(Array.isArray(e[t]))return`${t}: ${e[t][0]}`;if(typeof e[t]=="string")return`${t}: ${e[t]}`}if(e.slug)return e.slug}return"Unknown error"}_statusHandler(e){const t=/20[0-6]/g;return new Promise((r,s)=>{if(t.test(`${e.status}`))return r(e);const o={message:this._normalizeErrorMessage(e.data),status:e.status,response:e};s(o)})}},Je=Ge;const oe="SB-Agent",U={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"7.0.0"},qe={PUBLISHED:"published"};let j={};const L={};var We=class{constructor(e,t){g(this,"client"),g(this,"maxRetries"),g(this,"retriesDelay"),g(this,"throttle"),g(this,"accessToken"),g(this,"cache"),g(this,"resolveCounter"),g(this,"relations"),g(this,"links"),g(this,"version"),g(this,"richTextResolver"),g(this,"resolveNestedRelations"),g(this,"stringifiedStoriesCache"),g(this,"inlineAssets");let r=e.endpoint||t;if(!r){const n=e.https===!1?"http":"https";e.oauthToken?r=`${n}://${se(e.region)}/v1`:r=`${n}://${se(e.region)}/v2`}const s=new Headers;s.set("Content-Type","application/json"),s.set("Accept","application/json"),e.headers&&(e.headers.constructor.name==="Headers"?e.headers.entries().toArray():Object.entries(e.headers)).forEach(([n,i])=>{s.set(n,i)}),s.has(oe)||(s.set(oe,U.defaultAgentName),s.set(U.defaultAgentVersion,U.packageVersion));let o=5;e.oauthToken&&(s.set("Authorization",e.oauthToken),o=3),e.rateLimit&&(o=e.rateLimit),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=De(this.throttledRequest.bind(this),o,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.version=e.version||qe.PUBLISHED,this.inlineAssets=e.inlineAssets||!1,this.client=new Je({baseURL:r,timeout:e.timeout||0,headers:s,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=L[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 re(e)?this.parseParams(t):t}makeRequest(e,t,r,s,o){const n=this.factoryParamOptions(e,Ue(t,r,s));return this.cacheResponse(e,n,void 0,o)}get(e,t={},r){t||(t={});const s=`/${e}`;re(s)&&(t.version=t.version||this.version);const o=this.factoryParamOptions(s,t);return this.cacheResponse(s,o,void 0,r)}async getAll(e,t={},r,s){const o=(t==null?void 0:t.per_page)||25,n=`/${e}`.replace(/\/$/,""),i=r??n.substring(n.lastIndexOf("/")+1);t.version=t.version||this.version;const l=1,c=await this.makeRequest(n,t,o,l,s),u=c.total?Math.ceil(c.total/(c.perPage||o)):1,f=await ze(Fe(l,u),m=>this.makeRequest(n,t,o,m+1,s));return Ze([c,...f],m=>Object.values(m.data[i]))}post(e,t={},r){const s=`/${e}`;return this.throttle("post",s,t,r)}put(e,t={},r){const s=`/${e}`;return this.throttle("put",s,t,r)}delete(e,t={},r){t||(t={});const s=`/${e}`;return this.throttle("delete",s,t,r)}getStories(e={},t){return this._addResolveLevel(e),this.get("cdn/stories",e,t)}getStory(e,t={},r){return this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t,r)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_addResolveLevel(e){typeof e.resolve_relations<"u"&&(e.resolve_level=2)}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,r){const s=e[t];s&&s.fieldtype==="multilink"&&s.linktype==="story"&&typeof s.id=="string"&&this.links[r][s.id]?s.story=this._cleanCopy(this.links[r][s.id]):s&&s.linktype==="story"&&typeof s.uuid=="string"&&this.links[r][s.uuid]&&(s.story=this._cleanCopy(this.links[r][s.uuid]))}getStoryReference(e,t){return this.relations[e][t]?JSON.parse(this.stringifiedStoriesCache[t]||JSON.stringify(this.relations[e][t])):t}_resolveField(e,t,r){const s=e[t];typeof s=="string"?e[t]=this.getStoryReference(r,s):Array.isArray(s)&&(e[t]=s.map(o=>this.getStoryReference(r,o)).filter(Boolean))}_insertRelations(e,t,r,s){if(Array.isArray(r)?r.find(n=>n.endsWith(`.${t}`)):r.endsWith(`.${t}`)){this._resolveField(e,t,s);return}const o=e.component?`${e.component}.${t}`:t;(Array.isArray(r)?r.includes(o):r===o)&&this._resolveField(e,t,s)}iterateTree(e,t,r){const s=(o,n="")=>{if(!(!o||o._stopResolving)){if(Array.isArray(o))o.forEach((i,l)=>s(i,`${n}[${l}]`));else if(typeof o=="object")for(const i in o){const l=n?`${n}.${i}`:i;(o.component&&o._uid||o.type==="link")&&(this._insertRelations(o,i,t,r),this._insertLinks(o,i,r)),s(o[i],l)}}};s(e.content)}async resolveLinks(e,t,r){let s=[];if(e.link_uuids){const o=e.link_uuids.length,n=[],i=50;for(let l=0;l<o;l+=i){const c=Math.min(o,l+i);n.push(e.link_uuids.slice(l,c))}for(let l=0;l<n.length;l++)(await this.getStories({per_page:i,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[l].join(",")})).data.stories.forEach(c=>{s.push(c)})}else s=e.links;s.forEach(o=>{this.links[r][o.uuid]={...o,_stopResolving:!0}})}async resolveRelations(e,t,r){let s=[];if(e.rel_uuids){const o=e.rel_uuids.length,n=[],i=50;for(let l=0;l<o;l+=i){const c=Math.min(o,l+i);n.push(e.rel_uuids.slice(l,c))}for(let l=0;l<n.length;l++)(await this.getStories({per_page:i,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[l].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(c=>{s.push(c)});s.length>0&&(e.rels=s,delete e.rel_uuids)}else s=e.rels;s&&s.length>0&&s.forEach(o=>{this.relations[r][o.uuid]={...o,_stopResolving:!0}})}async resolveStories(e,t,r){var s,o;let n=[];if(this.links[r]={},this.relations[r]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(n=t.resolve_relations.split(",")),await this.resolveRelations(e,t,r)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((s=e.links)!=null&&s.length||(o=e.link_uuids)!=null&&o.length)&&await this.resolveLinks(e,t,r),this.resolveNestedRelations)for(const i in this.relations[r])this.iterateTree(this.relations[r][i],n,r);e.story?this.iterateTree(e.story,n,r):e.stories.forEach(i=>{this.iterateTree(i,n,r)}),this.stringifiedStoriesCache={},delete this.links[r],delete this.relations[r]}async cacheResponse(e,t,r,s){const o=D({url:e,params:t}),n=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const i=await n.get(o);if(i)return Promise.resolve(i)}return new Promise(async(i,l)=>{var c;try{const u=await this.throttle("get",e,t,s);if(u.status!==200)return l(u);let f={data:u.data,headers:u.headers};if((c=u.headers)!=null&&c["per-page"]&&(f=Object.assign({},f,{perPage:u.headers["per-page"]?Number.parseInt(u.headers["per-page"]):0,total:u.headers["per-page"]?Number.parseInt(u.headers.total):0})),f.data.story||f.data.stories){const T=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(f.data,t,`${T}`),f=await this.processInlineAssets(f)}t.version==="published"&&e!=="/cdn/spaces/me"&&await n.set(o,f);const m=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&f.data.cv&&(m&&L[t.token]&&L[t.token]!==f.data.cv&&await this.flushCache(),L[t.token]=f.data.cv),i(f)}catch(u){if(u.response&&u.status===429&&(r=typeof r>"u"?0:r+1,r<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${this.retriesDelay/1e3} seconds.`),await Ve(this.retriesDelay),this.cacheResponse(e,t,r).then(i).catch(l);l(u)}})}throttledRequest(e,t,r,s){return this.client.setFetchOptions(s),this.client[e](t,r)}cacheVersions(){return L}cacheVersion(){return L[this.accessToken]}setCacheVersion(e){this.accessToken&&(L[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(L[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(j[e])},getAll(){return Promise.resolve(j)},set(e,t){return j[e]=t,Promise.resolve(void 0)},flush(){return j={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve()},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this.clearCacheVersion(),this}async processInlineAssets(e){if(!this.inlineAssets)return e;const t=r=>{if(!r||typeof r!="object")return r;if(Array.isArray(r))return r.map(o=>t(o));let s={...r};s.fieldtype==="asset"&&Array.isArray(e.data.assets)&&(s={...s,...e.data.assets.find(o=>o.id===s.id)});for(const o in s)typeof s[o]=="object"&&(s[o]=t(s[o]));return s};return e.data.story&&(e.data.story.content=t(e.data.story.content)),e.data.stories&&(e.data.stories=e.data.stories.map(r=>(r.content=t(r.content),r))),e}},Ye=We;const Ke=(e={})=>{const{apiOptions:t}=e;if(!t||!t.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new Ye(t)}},Xe=e=>{if(typeof e!="object"||typeof e._editable>"u")return{};try{const t=JSON.parse(e._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return t?{"data-blok-c":JSON.stringify(t),"data-blok-uid":`${t.id}-${t.uid}`}:{}}catch{return{}}};let V="https://app.storyblok.com/f/storyblok-v2-latest.js";const Qe=(e={})=>{var t,r;const{bridge:s,accessToken:o,use:n=[],apiOptions:i={},bridgeUrl:l}=e;i.accessToken=i.accessToken||o;const c={bridge:s,apiOptions:i};let u={};n.forEach(m=>{u={...u,...m(c)}}),l&&(V=l);const f=!(typeof window>"u")&&((r=(t=window.location)==null?void 0:t.search)==null?void 0:r.includes("_storyblok_tk"));return s!==!1&&f&&te(V),u};function et(e,t){return X(t).render(e)}const tt=()=>te(V);v.apiPlugin=Ke,v.getLiveStory=de,v.handleStoryblokMessage=Ee,v.loadStoryblokBridge=tt,v.renderRichText=et,v.richTextResolver=X,v.storyblok=$e,v.storyblokEditable=Xe,v.storyblokInit=Qe,v.toCamelCase=J,v.useStoryblokApi=ue,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
|
|
69
|
+
`),L({entrypoint:"@storyblok/astro/middleware.ts",order:"pre"})),A({id:"storyblok",name:"Storyblok",icon:_,entrypoint:"@storyblok/astro/toolbarApp.ts"})}}}}let W;async function Ee(e){const{action:t,story:r}=e||{};if(t==="input"&&r){const s=async()=>{Y("storyblok-live-preview-updating",{story:r});const n=await Le(r),i=document.body;if(n.outerHTML===i.outerHTML)return;const l=document.querySelector('[data-blok-focused="true"]');Se(i,n,l),Y("storyblok-live-preview-updated",{story:r})};clearTimeout(W),W=setTimeout(s,500)}["published","change"].includes(e==null?void 0:e.action)&&location.reload()}function Se(e,t,r){if(r){const s=r.getAttribute("data-blok-uid"),o=t.querySelector(`[data-blok-uid="${s}"]`);o&&(o.setAttribute("data-blok-focused","true"),r.replaceWith(o))}else e.replaceWith(t)}async function Le(e){const r=await(await fetch(location.href,{method:"POST",body:JSON.stringify({...e,is_storyblok_preview:!0}),headers:{"Content-Type":"application/json"}})).text();return new DOMParser().parseFromString(r,"text/html").body}function Y(e,t){document.dispatchEvent(new CustomEvent(e,{detail:t}))}var _e=Object.defineProperty,Ie=(e,t,r)=>t in e?_e(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,g=(e,t,r)=>Ie(e,typeof t!="symbol"?t+"":t,r);let k=function(e){return e.DOCUMENT="doc",e.HEADING="heading",e.PARAGRAPH="paragraph",e.QUOTE="blockquote",e.OL_LIST="ordered_list",e.UL_LIST="bullet_list",e.LIST_ITEM="list_item",e.CODE_BLOCK="code_block",e.HR="horizontal_rule",e.BR="hard_break",e.IMAGE="image",e.EMOJI="emoji",e.COMPONENT="blok",e.TABLE="table",e.TABLE_ROW="tableRow",e.TABLE_CELL="tableCell",e.TABLE_HEADER="tableHeader",e}({}),$=function(e){return e.BOLD="bold",e.STRONG="strong",e.STRIKE="strike",e.UNDERLINE="underline",e.ITALIC="italic",e.CODE="code",e.LINK="link",e.ANCHOR="anchor",e.STYLED="styled",e.SUPERSCRIPT="superscript",e.SUBSCRIPT="subscript",e.TEXT_STYLE="textStyle",e.HIGHLIGHT="highlight",e}({}),Re=function(e){return e.TEXT="text",e}({}),H=function(e){return e.URL="url",e.STORY="story",e.ASSET="asset",e.EMAIL="email",e}({});const Oe=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],Pe=(e={})=>Object.keys(e).map(t=>`${t}="${e[t]}"`).join(" "),He=(e={})=>Object.keys(e).map(t=>`${t}: ${e[t]}`).join("; ");function je(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const I=e=>Object.fromEntries(Object.entries(e).filter(([t,r])=>r!==void 0));function xe(e,t){if(!t)return{src:e,attrs:{}};let r=0,s=0;const o={},n=[];function i(c,u,f,m,T){typeof c!="number"||c<=u||c>=f?console.warn(`[StoryblokRichText] - ${m.charAt(0).toUpperCase()+m.slice(1)} value must be a number between ${u} and ${f} (inclusive)`):T.push(`${m}(${c})`)}if(typeof t=="object"){if(t.width!==void 0&&(typeof t.width=="number"&&t.width>=0?(o.width=t.width,r=t.width):console.warn("[StoryblokRichText] - Width value must be a number greater than or equal to 0")),t.height!==void 0&&(typeof t.height=="number"&&t.height>=0?(o.height=t.height,s=t.height):console.warn("[StoryblokRichText] - Height value must be a number greater than or equal to 0")),t.height===0&&t.width===0&&(delete o.width,delete o.height,console.warn("[StoryblokRichText] - Width and height values cannot both be 0")),t.loading&&["lazy","eager"].includes(t.loading)&&(o.loading=t.loading),t.class&&(o.class=t.class),t.filters){const{filters:c}=t||{},{blur:u,brightness:f,fill:m,format:T,grayscale:R,quality:A,rotate:L}=c||{};u&&i(u,0,100,"blur",n),A&&i(A,0,100,"quality",n),f&&i(f,0,100,"brightness",n),m&&n.push(`fill(${m})`),R&&n.push("grayscale()"),L&&[0,90,180,270].includes(t.filters.rotate||0)&&n.push(`rotate(${L})`),T&&["webp","png","jpeg"].includes(T)&&n.push(`format(${T})`)}t.srcset&&(o.srcset=t.srcset.map(c=>{if(typeof c=="number")return`${e}/m/${c}x0/${n.length>0?`filters:${n.join(":")}`:""} ${c}w`;if(Array.isArray(c)&&c.length===2){const[u,f]=c;return`${e}/m/${u}x${f}/${n.length>0?`filters:${n.join(":")}`:""} ${u}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),t.sizes&&(o.sizes=t.sizes.join(", "))}let l=`${e}/m/`;return(r>0||s>0)&&(l=`${l}${r}x${s}/`),n.length>0&&(l=`${l}filters:${n.join(":")}`),{src:l,attrs:o}}function K(e,t={},r){const s=Pe(t),o=s?`${e} ${s}`:e,n=Array.isArray(r)?r.join(""):r||"";if(e){if(Oe.includes(e))return`<${o}>`}else return n;return`<${o}>${n}</${e}>`}function X(e={}){const t=new Map,{renderFn:r=K,textFn:s=je,resolvers:o={},optimizeImages:n=!1,keyedResolvers:i=!1}=e,l=r!==K,c=(a={})=>{const{textAlign:h,class:d,id:p,style:y,...C}=a,b=[];return y&&b.push(y.endsWith(";")?y:`${y};`),h&&b.push(`text-align: ${h};`),I({...C,class:d,id:p,...b.length>0?{style:b.join(" ")}:{}})},u=a=>(h,d)=>{const p=c(h.attrs);return d.render(a,p,h.children||null)},f=(a,h)=>{const{src:d,alt:p,title:y,srcset:C,sizes:b}=a.attrs||{};let E=d,w={};if(n){const{src:lt,attrs:ct}=xe(d,n);E=lt,w=ct}const P={src:E,alt:p,title:y,srcset:C,sizes:b,...w};return h.render("img",I(P))},m=(a,h)=>{const{level:d,...p}=a.attrs||{},y=c(p);return h.render(`h${d}`,y,a.children)},T=(a,h)=>{var d,p,y,C;const b=h.render("img",{src:(d=a.attrs)==null?void 0:d.fallbackImage,alt:(p=a.attrs)==null?void 0:p.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"});return h.render("span",{"data-type":"emoji","data-name":(y=a.attrs)==null?void 0:y.name,"data-emoji":(C=a.attrs)==null?void 0:C.emoji},b)},R=(a,h)=>h.render("pre",a.attrs||{},h.render("code",{},a.children||"")),A=(a,h=!1)=>({text:d,attrs:p},y)=>{const{class:C,id:b,...E}=p||{},w=h?{class:C,id:b,style:He(E)||void 0}:p||{};return y.render(a,I(w),d)},L=a=>B(a),O=a=>{const{marks:h,...d}=a;if("text"in a){if(h)return h.reduce((y,C)=>L({...C,text:y}),L({...d,children:d.children}));const p=a.attrs||{};if(i){const y=t.get("txt")||0;t.set("txt",y+1),p.key=`txt-${y}`}return s(d.text,p)}return""},ne=(a,h)=>{const{linktype:d,href:p,anchor:y,...C}=a.attrs||{};let b="";switch(d){case H.ASSET:case H.URL:b=p;break;case H.EMAIL:b=`mailto:${p}`;break;case H.STORY:b=p,y&&(b=`${b}#${y}`);break;default:b=p;break}const E={...C};return b&&(E.href=b),h.render("a",E,a.text)},rt=(a,h)=>{var d,p;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),h.render("span",{blok:(d=a==null?void 0:a.attrs)==null?void 0:d.body[0],id:(p=a.attrs)==null?void 0:p.id,style:"display: none"})},st=(a,h)=>{const d=c(a.attrs),p=a.children||null;return h.render("table",d,h.render("tbody",{},p))},ot=(a,h)=>{const d=c(a.attrs);return h.render("tr",d,a.children)},nt=(a,h)=>{const{colspan:d,rowspan:p,colwidth:y,backgroundColor:C,textAlign:b,...E}=a.attrs||{},w=[];y&&w.push(`width: ${y}px;`),C&&w.push(`background-color: ${C};`),b&&w.push(`text-align: ${b};`);const P={...E,...d>1?{colspan:d}:{},...p>1?{rowspan:p}:{},...w.length>0?{style:w.join(" ")}:{}};return h.render("td",I(P),a.children)},it=(a,h)=>{const{colspan:d,rowspan:p,colwidth:y,backgroundColor:C,textAlign:b,...E}=a.attrs||{},w=[];y&&w.push(`width: ${y}px;`),C&&w.push(`background-color: ${C};`),b&&w.push(`text-align: ${b};`);const P={...E,...d>1?{colspan:d}:{},...p>1?{rowspan:p}:{},...w.length>0?{style:w.join(" ")}:{}};return h.render("th",I(P),a.children)},ie=new Map([[k.DOCUMENT,u("")],[k.HEADING,m],[k.PARAGRAPH,u("p")],[k.UL_LIST,u("ul")],[k.OL_LIST,u("ol")],[k.LIST_ITEM,u("li")],[k.IMAGE,f],[k.EMOJI,T],[k.CODE_BLOCK,R],[k.HR,u("hr")],[k.BR,u("br")],[k.QUOTE,u("blockquote")],[k.COMPONENT,rt],[Re.TEXT,O],[$.LINK,ne],[$.ANCHOR,ne],[$.STYLED,A("span",!0)],[$.BOLD,A("strong")],[$.TEXT_STYLE,A("span",!0)],[$.ITALIC,A("em")],[$.UNDERLINE,A("u")],[$.STRIKE,A("s")],[$.CODE,A("code")],[$.SUPERSCRIPT,A("sup")],[$.SUBSCRIPT,A("sub")],[$.HIGHLIGHT,A("mark")],[k.TABLE,st],[k.TABLE_ROW,ot],[k.TABLE_CELL,nt],[k.TABLE_HEADER,it]]),ae=new Map([...ie,...Object.entries(o).map(([a,h])=>[a,h])]),at=()=>({render:(a,h={},d)=>{if(i&&a){const p=t.get(a)||0;t.set(a,p+1),h.key=`${a}-${p}`}return r(a,h,d)},originalResolvers:ie,mergedResolvers:ae});function x(a){const h=ae.get(a.type);if(!h)return console.error("<Storyblok>",`No resolver found for node type ${a.type}`),"";const d=at();if(a.type==="text")return h(a,d);const p=a.content?a.content.map(B):void 0;return h({...a,children:p},d)}function B(a){return a.type==="doc"?l?a.content.map(x):a.content.map(x).join(""):Array.isArray(a)?a.map(x):x(a)}return{render:B}}let Q=!1;const ee=[],te=e=>new Promise((t,r)=>{if(typeof window>"u"){r(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));return}if(window.storyblokRegisterEvent=o=>{if(!window.location.search.includes("_storyblok")){console.warn("You are not in Draft Mode or in the Visual Editor.");return}Q?o():ee.push(o)},document.getElementById("storyblok-javascript-bridge")){t(void 0);return}const s=document.createElement("script");s.async=!0,s.src=e,s.id="storyblok-javascript-bridge",s.onerror=o=>r(o),s.onload=o=>{ee.forEach(n=>n()),Q=!0,t(o)},document.getElementsByTagName("head")[0].appendChild(s)});var Ne=class extends Error{constructor(e){super(e),this.name="AbortError"}};function Me(e,t,r){if(!Number.isFinite(t))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(r))throw new TypeError("Expected `interval` to be a finite number");const s=[];let o=[],n=0,i=!1;const l=async()=>{n++;const u=s.shift();if(u)try{const m=await e(...u.args);u.resolve(m)}catch(m){u.reject(m)}const f=setTimeout(()=>{n--,s.length>0&&l(),o=o.filter(m=>m!==f)},r);o.includes(f)||o.push(f)},c=(...u)=>i?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((f,m)=>{s.push({resolve:f,reject:m,args:u}),n<t&&l()});return c.abort=()=>{i=!0,o.forEach(clearTimeout),o=[],s.forEach(u=>u.reject(()=>new Ne("Throttle function aborted"))),s.length=0},c}var De=Me;const re=(e="")=>e.includes("/cdn/"),Ue=(e,t=25,r=1)=>({...e,per_page:t,page:r}),Ve=e=>new Promise(t=>setTimeout(t,e)),Be=(e=0,t)=>Array.from({length:e},t),Fe=(e=0,t=e)=>{const r=Math.abs(t-e)||0,s=e<t?1:-1;return Be(r,(o,n)=>n*s+e)},ze=async(e,t)=>Promise.all(e.map(t)),Ze=(e=[],t)=>e.map(t).reduce((r,s)=>[...r,...s],[]),D=(e,t,r)=>{const s=[];for(const o in e){if(!Object.prototype.hasOwnProperty.call(e,o))continue;const n=e[o];if(n==null)continue;const i=r?"":encodeURIComponent(o);let l;typeof n=="object"?l=D(n,t?t+encodeURIComponent(`[${i}]`):i,Array.isArray(n)):l=`${t?t+encodeURIComponent(`[${i}]`):i}=${encodeURIComponent(n)}`,s.push(l)}return s.join("&")},se=e=>{const t={eu:"api.storyblok.com",us:"api-us.storyblok.com",cn:"app.storyblokchina.cn",ap:"api-ap.storyblok.com",ca:"api-ca.storyblok.com"};return t[e]??t.eu};var Ge=class{constructor(e){g(this,"baseURL"),g(this,"timeout"),g(this,"headers"),g(this,"responseInterceptor"),g(this,"fetch"),g(this,"ejectInterceptor"),g(this,"url"),g(this,"parameters"),g(this,"fetchOptions"),this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={},this.fetchOptions={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t??{},this._methodHandler("delete")}async _responseHandler(e){const t=[],r={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(s=>{r.data=s});for(const s of e.headers.entries())t[s[0]]=s[1];return r.headers={...t},r.status=e.status,r.statusText=e.statusText,r}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,r=null;e==="get"?t=`${this.baseURL}${this.url}?${D(this.parameters)}`:r=JSON.stringify(this.parameters);const s=new URL(t),o=new AbortController,{signal:n}=o;let i;this.timeout&&(i=setTimeout(()=>o.abort(),this.timeout));try{const l=await this.fetch(`${s}`,{method:e,headers:this.headers,body:r,signal:n,...this.fetchOptions});this.timeout&&clearTimeout(i);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}_normalizeErrorMessage(e){if(Array.isArray(e))return e[0]||"Unknown error";if(e&&typeof e=="object"){if(e.error)return e.error;for(const t in e){if(Array.isArray(e[t]))return`${t}: ${e[t][0]}`;if(typeof e[t]=="string")return`${t}: ${e[t]}`}if(e.slug)return e.slug}return"Unknown error"}_statusHandler(e){const t=/20[0-6]/g;return new Promise((r,s)=>{if(t.test(`${e.status}`))return r(e);const o={message:this._normalizeErrorMessage(e.data),status:e.status,response:e};s(o)})}},qe=Ge;const oe="SB-Agent",U={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"7.0.0"},Je={PUBLISHED:"published"};let j={};const S={};var We=class{constructor(e,t){g(this,"client"),g(this,"maxRetries"),g(this,"retriesDelay"),g(this,"throttle"),g(this,"accessToken"),g(this,"cache"),g(this,"resolveCounter"),g(this,"relations"),g(this,"links"),g(this,"version"),g(this,"richTextResolver"),g(this,"resolveNestedRelations"),g(this,"stringifiedStoriesCache"),g(this,"inlineAssets");let r=e.endpoint||t;if(!r){const n=e.https===!1?"http":"https";e.oauthToken?r=`${n}://${se(e.region)}/v1`:r=`${n}://${se(e.region)}/v2`}const s=new Headers;s.set("Content-Type","application/json"),s.set("Accept","application/json"),e.headers&&(e.headers.constructor.name==="Headers"?e.headers.entries().toArray():Object.entries(e.headers)).forEach(([n,i])=>{s.set(n,i)}),s.has(oe)||(s.set(oe,U.defaultAgentName),s.set(U.defaultAgentVersion,U.packageVersion));let o=5;e.oauthToken&&(s.set("Authorization",e.oauthToken),o=3),e.rateLimit&&(o=e.rateLimit),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=De(this.throttledRequest.bind(this),o,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.version=e.version||Je.PUBLISHED,this.inlineAssets=e.inlineAssets||!1,this.client=new qe({baseURL:r,timeout:e.timeout||0,headers:s,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=S[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),typeof e.resolve_relations<"u"&&(e.resolve_level=2),e}factoryParamOptions(e,t){return re(e)?this.parseParams(t):t}makeRequest(e,t,r,s,o){const n=this.factoryParamOptions(e,Ue(t,r,s));return this.cacheResponse(e,n,void 0,o)}get(e,t={},r){t||(t={});const s=`/${e}`;re(s)&&(t.version=t.version||this.version);const o=this.factoryParamOptions(s,t);return this.cacheResponse(s,o,void 0,r)}async getAll(e,t={},r,s){const o=(t==null?void 0:t.per_page)||25,n=`/${e}`.replace(/\/$/,""),i=r??n.substring(n.lastIndexOf("/")+1);t.version=t.version||this.version;const l=1,c=await this.makeRequest(n,t,o,l,s),u=c.total?Math.ceil(c.total/(c.perPage||o)):1,f=await ze(Fe(l,u),m=>this.makeRequest(n,t,o,m+1,s));return Ze([c,...f],m=>Object.values(m.data[i]))}post(e,t={},r){const s=`/${e}`;return this.throttle("post",s,t,r)}put(e,t={},r){const s=`/${e}`;return this.throttle("put",s,t,r)}delete(e,t={},r){t||(t={});const s=`/${e}`;return this.throttle("delete",s,t,r)}getStories(e={},t){return this._addResolveLevel(e),this.get("cdn/stories",e,t)}getStory(e,t={},r){return this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t,r)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_addResolveLevel(e){typeof e.resolve_relations<"u"&&(e.resolve_level=2)}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,r){const s=e[t];s&&s.fieldtype==="multilink"&&s.linktype==="story"&&typeof s.id=="string"&&this.links[r][s.id]?s.story=this._cleanCopy(this.links[r][s.id]):s&&s.linktype==="story"&&typeof s.uuid=="string"&&this.links[r][s.uuid]&&(s.story=this._cleanCopy(this.links[r][s.uuid]))}getStoryReference(e,t){return this.relations[e][t]?JSON.parse(this.stringifiedStoriesCache[t]||JSON.stringify(this.relations[e][t])):t}_resolveField(e,t,r){const s=e[t];typeof s=="string"?e[t]=this.getStoryReference(r,s):Array.isArray(s)&&(e[t]=s.map(o=>this.getStoryReference(r,o)).filter(Boolean))}_insertRelations(e,t,r,s){if(Array.isArray(r)?r.find(n=>n.endsWith(`.${t}`)):r.endsWith(`.${t}`)){this._resolveField(e,t,s);return}const o=e.component?`${e.component}.${t}`:t;(Array.isArray(r)?r.includes(o):r===o)&&this._resolveField(e,t,s)}iterateTree(e,t,r){const s=(o,n="")=>{if(!(!o||o._stopResolving)){if(Array.isArray(o))o.forEach((i,l)=>s(i,`${n}[${l}]`));else if(typeof o=="object")for(const i in o){const l=n?`${n}.${i}`:i;(o.component&&o._uid||o.type==="link")&&(this._insertRelations(o,i,t,r),this._insertLinks(o,i,r)),s(o[i],l)}}};s(e.content)}async resolveLinks(e,t,r){let s=[];if(e.link_uuids){const o=e.link_uuids.length,n=[],i=50;for(let l=0;l<o;l+=i){const c=Math.min(o,l+i);n.push(e.link_uuids.slice(l,c))}for(let l=0;l<n.length;l++)(await this.getStories({per_page:i,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[l].join(",")})).data.stories.forEach(c=>{s.push(c)})}else s=e.links;s.forEach(o=>{this.links[r][o.uuid]={...o,_stopResolving:!0}})}async resolveRelations(e,t,r){let s=[];if(e.rel_uuids){const o=e.rel_uuids.length,n=[],i=50;for(let l=0;l<o;l+=i){const c=Math.min(o,l+i);n.push(e.rel_uuids.slice(l,c))}for(let l=0;l<n.length;l++)(await this.getStories({per_page:i,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[l].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(c=>{s.push(c)});s.length>0&&(e.rels=s,delete e.rel_uuids)}else s=e.rels;s&&s.length>0&&s.forEach(o=>{this.relations[r][o.uuid]={...o,_stopResolving:!0}})}async resolveStories(e,t,r){var s,o;let n=[];if(this.links[r]={},this.relations[r]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(n=t.resolve_relations.split(",")),await this.resolveRelations(e,t,r)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((s=e.links)!=null&&s.length||(o=e.link_uuids)!=null&&o.length)&&await this.resolveLinks(e,t,r),this.resolveNestedRelations)for(const i in this.relations[r])this.iterateTree(this.relations[r][i],n,r);e.story?this.iterateTree(e.story,n,r):e.stories.forEach(i=>{this.iterateTree(i,n,r)}),this.stringifiedStoriesCache={},delete this.links[r],delete this.relations[r]}async cacheResponse(e,t,r,s){const o=D({url:e,params:t}),n=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const i=await n.get(o);if(i)return Promise.resolve(i)}return new Promise(async(i,l)=>{var c;try{const u=await this.throttle("get",e,t,s);if(u.status!==200)return l(u);let f={data:u.data,headers:u.headers};if((c=u.headers)!=null&&c["per-page"]&&(f=Object.assign({},f,{perPage:u.headers["per-page"]?Number.parseInt(u.headers["per-page"]):0,total:u.headers["per-page"]?Number.parseInt(u.headers.total):0})),f.data.story||f.data.stories){const T=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(f.data,t,`${T}`),f=await this.processInlineAssets(f)}t.version==="published"&&e!=="/cdn/spaces/me"&&await n.set(o,f);const m=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&f.data.cv&&(m&&S[t.token]&&S[t.token]!==f.data.cv&&await this.flushCache(),S[t.token]=f.data.cv),i(f)}catch(u){if(u.response&&u.status===429&&(r=typeof r>"u"?0:r+1,r<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${this.retriesDelay/1e3} seconds.`),await Ve(this.retriesDelay),this.cacheResponse(e,t,r).then(i).catch(l);l(u)}})}throttledRequest(e,t,r,s){return this.client.setFetchOptions(s),this.client[e](t,r)}cacheVersions(){return S}cacheVersion(){return S[this.accessToken]}setCacheVersion(e){this.accessToken&&(S[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(S[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(j[e])},getAll(){return Promise.resolve(j)},set(e,t){return j[e]=t,Promise.resolve(void 0)},flush(){return j={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve()},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this.clearCacheVersion(),this}async processInlineAssets(e){if(!this.inlineAssets)return e;const t=r=>{if(!r||typeof r!="object")return r;if(Array.isArray(r))return r.map(o=>t(o));let s={...r};s.fieldtype==="asset"&&Array.isArray(e.data.assets)&&(s={...e.data.assets.find(o=>o.id===s.id),...s});for(const o in s)typeof s[o]=="object"&&(s[o]=t(s[o]));return s};return e.data.story&&(e.data.story.content=t(e.data.story.content)),e.data.stories&&(e.data.stories=e.data.stories.map(r=>(r.content=t(r.content),r))),e}},Ye=We;const Ke=(e={})=>{const{apiOptions:t}=e;if(!t||!t.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new Ye(t)}},Xe=e=>{if(typeof e!="object"||typeof e._editable>"u")return{};try{const t=JSON.parse(e._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return t?{"data-blok-c":JSON.stringify(t),"data-blok-uid":`${t.id}-${t.uid}`}:{}}catch{return{}}};let V="https://app.storyblok.com/f/storyblok-v2-latest.js";const Qe=(e={})=>{var t,r;const{bridge:s,accessToken:o,use:n=[],apiOptions:i={},bridgeUrl:l}=e;i.accessToken=i.accessToken||o;const c={bridge:s,apiOptions:i};let u={};n.forEach(m=>{u={...u,...m(c)}}),l&&(V=l);const f=!(typeof window>"u")&&((r=(t=window.location)==null?void 0:t.search)==null?void 0:r.includes("_storyblok_tk"));return s!==!1&&f&&te(V),u};function et(e,t){return X(t).render(e)}const tt=()=>te(V);v.apiPlugin=Ke,v.getLiveStory=he,v.handleStoryblokMessage=Ee,v.loadStoryblokBridge=tt,v.renderRichText=et,v.richTextResolver=X,v.storyblok=$e,v.storyblokEditable=Xe,v.storyblokInit=Qe,v.toCamelCase=q,v.useStoryblokApi=ue,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/astro",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.3.
|
|
4
|
+
"version": "7.3.2",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Official Astro integration for the Storyblok Headless CMS",
|
|
7
7
|
"author": "Storyblok",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"camelcase": "^8.0.0",
|
|
56
|
-
"@storyblok/js": "4.3.
|
|
56
|
+
"@storyblok/js": "4.3.1"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@cypress/vite-dev-server": "^6.0.3",
|