@storyblok/astro 6.0.0 → 6.0.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/lib/helpers.d.ts +1 -1
- package/dist/storyblok-astro.es.js +190 -186
- package/dist/storyblok-astro.umd.js +12 -12
- package/package.json +4 -3
package/dist/lib/helpers.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export declare function useStoryblokApi(): StoryblokClient;
|
|
|
4
4
|
export declare function getLiveStory(Astro: Readonly<AstroGlobal>): Promise<ISbStoryData<import('@storyblok/js').StoryblokComponentType<string> & {
|
|
5
5
|
[index: string]: any;
|
|
6
6
|
}> | null>;
|
|
7
|
-
export declare function renderRichText(data?: ISbRichtext, options?: SbRichTextOptions): string;
|
|
7
|
+
export declare function renderRichText(data?: ISbRichtext, options?: SbRichTextOptions): string | undefined;
|
|
8
8
|
export declare function initStoryblokBridge(config: boolean | StoryblokBridgeConfigV2): string;
|
|
@@ -7,30 +7,30 @@ const A = `<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>`, E = /[\p{Lu}]/u, L = /[\p{Ll}]/u, k = /^[\p{Lu}](?![\p{Lu}])/gu, x = /([\p{Alpha}\p{N}_]|$)/u,
|
|
10
|
+
</svg>`, E = /[\p{Lu}]/u, L = /[\p{Ll}]/u, k = /^[\p{Lu}](?![\p{Lu}])/gu, x = /([\p{Alpha}\p{N}_]|$)/u, b = /[_.\- ]+/, j = new RegExp("^" + b.source), w = new RegExp(b.source + x.source, "gu"), $ = new RegExp("\\d+" + x.source, "gu"), R = (r, t, e, o) => {
|
|
11
11
|
let s = !1, n = !1, a = !1, l = !1;
|
|
12
12
|
for (let i = 0; i < r.length; i++) {
|
|
13
13
|
const c = r[i];
|
|
14
|
-
l = i > 2 ? r[i - 3] === "-" : !0, s && E.test(c) ? (r = r.slice(0, i) + "-" + r.slice(i), s = !1, a = n, n = !0, i++) : n && a && L.test(c) && (!l || o) ? (r = r.slice(0, i - 1) + "-" + r.slice(i - 1), a = n, n = !1, s = !0) : (s =
|
|
14
|
+
l = i > 2 ? r[i - 3] === "-" : !0, s && E.test(c) ? (r = r.slice(0, i) + "-" + r.slice(i), s = !1, a = n, n = !0, i++) : n && a && L.test(c) && (!l || o) ? (r = r.slice(0, i - 1) + "-" + r.slice(i - 1), a = n, n = !1, s = !0) : (s = t(c) === c && e(c) !== c, a = n, n = e(c) === c && t(c) !== c);
|
|
15
15
|
}
|
|
16
16
|
return r;
|
|
17
|
-
}, M = (r,
|
|
18
|
-
function O(r,
|
|
17
|
+
}, M = (r, t) => (k.lastIndex = 0, r.replaceAll(k, (e) => t(e))), P = (r, t) => (w.lastIndex = 0, $.lastIndex = 0, r.replaceAll($, (e, o, s) => ["_", "-"].includes(r.charAt(s + e.length)) ? e : t(e)).replaceAll(w, (e, o) => t(o)));
|
|
18
|
+
function O(r, t) {
|
|
19
19
|
if (!(typeof r == "string" || Array.isArray(r)))
|
|
20
20
|
throw new TypeError("Expected the input to be `string | string[]`");
|
|
21
|
-
if (
|
|
21
|
+
if (t = {
|
|
22
22
|
pascalCase: !1,
|
|
23
23
|
preserveConsecutiveUppercase: !1,
|
|
24
|
-
...
|
|
24
|
+
...t
|
|
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
|
-
const
|
|
28
|
-
return r.length === 1 ?
|
|
27
|
+
const e = t.locale === !1 ? (n) => n.toLowerCase() : (n) => n.toLocaleLowerCase(t.locale), o = t.locale === !1 ? (n) => n.toUpperCase() : (n) => n.toLocaleUpperCase(t.locale);
|
|
28
|
+
return r.length === 1 ? b.test(r) ? "" : t.pascalCase ? o(r) : e(r) : (r !== e(r) && (r = R(r, e, o, t.preserveConsecutiveUppercase)), r = r.replace(j, ""), r = t.preserveConsecutiveUppercase ? M(r, e) : e(r), t.pascalCase && (r = o(r.charAt(0)) + r.slice(1)), P(r, o));
|
|
29
29
|
}
|
|
30
30
|
function v(r) {
|
|
31
31
|
return O(r);
|
|
32
32
|
}
|
|
33
|
-
function _(r,
|
|
33
|
+
function _(r, t = {}, e, o) {
|
|
34
34
|
const s = "virtual:storyblok-components", n = `\0${s}`;
|
|
35
35
|
return {
|
|
36
36
|
name: "vite-plugin-storyblok-components",
|
|
@@ -41,13 +41,13 @@ function _(r, e = {}, t, o) {
|
|
|
41
41
|
async load(a) {
|
|
42
42
|
if (a === n) {
|
|
43
43
|
const l = [], i = [];
|
|
44
|
-
for await (const [u, p] of Object.entries(
|
|
44
|
+
for await (const [u, p] of Object.entries(t)) {
|
|
45
45
|
const f = await this.resolve(
|
|
46
46
|
`/${r}/${p}.astro`
|
|
47
47
|
);
|
|
48
48
|
if (f)
|
|
49
49
|
l.push(`import ${v(u)} from "${f.id}"`);
|
|
50
|
-
else if (
|
|
50
|
+
else if (e)
|
|
51
51
|
i.push(u);
|
|
52
52
|
else
|
|
53
53
|
throw new Error(
|
|
@@ -55,7 +55,7 @@ function _(r, e = {}, t, o) {
|
|
|
55
55
|
);
|
|
56
56
|
}
|
|
57
57
|
let c = "";
|
|
58
|
-
if (
|
|
58
|
+
if (e)
|
|
59
59
|
if (c = ",FallbackComponent", o) {
|
|
60
60
|
const u = await this.resolve(
|
|
61
61
|
`/${r}/${o}.astro`
|
|
@@ -71,9 +71,9 @@ function _(r, e = {}, t, o) {
|
|
|
71
71
|
l.push(
|
|
72
72
|
"import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'"
|
|
73
73
|
);
|
|
74
|
-
if (Object.values(
|
|
75
|
-
return `${l.join(";")};export default {${Object.keys(
|
|
76
|
-
if (
|
|
74
|
+
if (Object.values(t).length)
|
|
75
|
+
return `${l.join(";")};export default {${Object.keys(t).filter((u) => !i.includes(u)).map((u) => v(u)).join(",")}${c}}`;
|
|
76
|
+
if (e)
|
|
77
77
|
return `${l[0]}; export default {${c.replace(",", "")}}`;
|
|
78
78
|
throw new Error(
|
|
79
79
|
`Currently, no Storyblok components are registered in astro.config.mjs.
|
|
@@ -84,7 +84,7 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
|
|
|
84
84
|
}
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
-
function N(r,
|
|
87
|
+
function N(r, t, e) {
|
|
88
88
|
const o = "virtual:storyblok-init", s = `\0${o}`;
|
|
89
89
|
return {
|
|
90
90
|
name: "vite-plugin-storyblok-init",
|
|
@@ -98,8 +98,8 @@ function N(r, e, t) {
|
|
|
98
98
|
import { storyblokInit, apiPlugin } from "@storyblok/js";
|
|
99
99
|
const { storyblokApi } = storyblokInit({
|
|
100
100
|
accessToken: "${r}",
|
|
101
|
-
use: ${
|
|
102
|
-
apiOptions: ${JSON.stringify(
|
|
101
|
+
use: ${t ? "[]" : "[apiPlugin]"},
|
|
102
|
+
apiOptions: ${JSON.stringify(e)},
|
|
103
103
|
});
|
|
104
104
|
export const storyblokApiInstance = storyblokApi;
|
|
105
105
|
`;
|
|
@@ -107,52 +107,53 @@ function N(r, e, t) {
|
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
109
|
function z(r) {
|
|
110
|
-
const
|
|
110
|
+
const t = "virtual:storyblok-options", e = `\0${t}`;
|
|
111
111
|
return {
|
|
112
112
|
name: "vite-plugin-storyblok-options",
|
|
113
113
|
async resolveId(o) {
|
|
114
|
-
if (o ===
|
|
115
|
-
return
|
|
114
|
+
if (o === t)
|
|
115
|
+
return e;
|
|
116
116
|
},
|
|
117
117
|
async load(o) {
|
|
118
|
-
if (o ===
|
|
118
|
+
if (o === e)
|
|
119
119
|
return `export default ${JSON.stringify(r)}`;
|
|
120
120
|
}
|
|
121
121
|
};
|
|
122
122
|
}
|
|
123
123
|
let C = !1;
|
|
124
|
-
const I = [], B = (r) => new Promise((
|
|
124
|
+
const I = [], B = (r) => new Promise((t, e) => {
|
|
125
125
|
if (typeof window > "u" || (window.storyblokRegisterEvent = (s) => {
|
|
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
|
C ? s() : I.push(s);
|
|
131
|
-
}, document.getElementById("storyblok-javascript-bridge")))
|
|
131
|
+
}, document.getElementById("storyblok-javascript-bridge")))
|
|
132
|
+
return;
|
|
132
133
|
const o = document.createElement("script");
|
|
133
|
-
o.async = !0, o.src = r, o.id = "storyblok-javascript-bridge", o.onerror = (s) =>
|
|
134
|
-
I.forEach((n) => n()), C = !0,
|
|
134
|
+
o.async = !0, o.src = r, o.id = "storyblok-javascript-bridge", o.onerror = (s) => e(s), o.onload = (s) => {
|
|
135
|
+
I.forEach((n) => n()), C = !0, t(s);
|
|
135
136
|
}, document.getElementsByTagName("head")[0].appendChild(o);
|
|
136
137
|
});
|
|
137
|
-
var F = Object.defineProperty, D = (r,
|
|
138
|
+
var F = Object.defineProperty, D = (r, t, e) => t in r ? F(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e, g = (r, t, e) => D(r, typeof t != "symbol" ? t + "" : t, e);
|
|
138
139
|
let U = class {
|
|
139
140
|
constructor() {
|
|
140
|
-
g(this, "isCDNUrl", (r = "") => r.includes("/cdn/")), g(this, "getOptionsPage", (r,
|
|
141
|
+
g(this, "isCDNUrl", (r = "") => r.includes("/cdn/")), g(this, "getOptionsPage", (r, t = 25, e = 1) => ({
|
|
141
142
|
...r,
|
|
142
|
-
per_page:
|
|
143
|
-
page:
|
|
144
|
-
})), g(this, "delay", (r) => new Promise((
|
|
145
|
-
const
|
|
146
|
-
return this.arrayFrom(
|
|
147
|
-
}), g(this, "asyncMap", async (r,
|
|
148
|
-
const
|
|
143
|
+
per_page: t,
|
|
144
|
+
page: e
|
|
145
|
+
})), g(this, "delay", (r) => new Promise((t) => setTimeout(t, r))), g(this, "arrayFrom", (r = 0, t) => Array.from({ length: r }, t)), g(this, "range", (r = 0, t = r) => {
|
|
146
|
+
const e = Math.abs(t - r) || 0, o = r < t ? 1 : -1;
|
|
147
|
+
return this.arrayFrom(e, (s, n) => n * o + r);
|
|
148
|
+
}), g(this, "asyncMap", async (r, t) => Promise.all(r.map(t))), g(this, "flatMap", (r = [], t) => r.map(t).reduce((e, o) => [...e, ...o], [])), g(this, "escapeHTML", function(r) {
|
|
149
|
+
const t = {
|
|
149
150
|
"&": "&",
|
|
150
151
|
"<": "<",
|
|
151
152
|
">": ">",
|
|
152
153
|
'"': """,
|
|
153
154
|
"'": "'"
|
|
154
|
-
},
|
|
155
|
-
return r && o.test(r) ? r.replace(
|
|
155
|
+
}, e = /[&<>"']/g, o = new RegExp(e.source);
|
|
156
|
+
return r && o.test(r) ? r.replace(e, (s) => t[s]) : r;
|
|
156
157
|
});
|
|
157
158
|
}
|
|
158
159
|
/**
|
|
@@ -162,18 +163,18 @@ let U = class {
|
|
|
162
163
|
* @param {boolean} isArray
|
|
163
164
|
* @return {string} Stringified object
|
|
164
165
|
*/
|
|
165
|
-
stringify(r,
|
|
166
|
+
stringify(r, t, e) {
|
|
166
167
|
const o = [];
|
|
167
168
|
for (const s in r) {
|
|
168
169
|
if (!Object.prototype.hasOwnProperty.call(r, s))
|
|
169
170
|
continue;
|
|
170
|
-
const n = r[s], a =
|
|
171
|
+
const n = r[s], a = e ? "" : encodeURIComponent(s);
|
|
171
172
|
let l;
|
|
172
173
|
typeof n == "object" ? l = this.stringify(
|
|
173
174
|
n,
|
|
174
|
-
|
|
175
|
+
t ? t + encodeURIComponent(`[${a}]`) : a,
|
|
175
176
|
Array.isArray(n)
|
|
176
|
-
) : l = `${
|
|
177
|
+
) : l = `${t ? t + encodeURIComponent(`[${a}]`) : a}=${encodeURIComponent(n)}`, o.push(l);
|
|
177
178
|
}
|
|
178
179
|
return o.join("&");
|
|
179
180
|
}
|
|
@@ -183,10 +184,10 @@ let U = class {
|
|
|
183
184
|
* @return {string} The base URL of the region
|
|
184
185
|
*/
|
|
185
186
|
getRegionURL(r) {
|
|
186
|
-
const
|
|
187
|
+
const t = "api.storyblok.com", e = "api-us.storyblok.com", o = "app.storyblokchina.cn", s = "api-ap.storyblok.com", n = "api-ca.storyblok.com";
|
|
187
188
|
switch (r) {
|
|
188
189
|
case "us":
|
|
189
|
-
return
|
|
190
|
+
return e;
|
|
190
191
|
case "cn":
|
|
191
192
|
return o;
|
|
192
193
|
case "ap":
|
|
@@ -194,24 +195,24 @@ let U = class {
|
|
|
194
195
|
case "ca":
|
|
195
196
|
return n;
|
|
196
197
|
default:
|
|
197
|
-
return
|
|
198
|
+
return t;
|
|
198
199
|
}
|
|
199
200
|
}
|
|
200
201
|
};
|
|
201
|
-
const q = function(r,
|
|
202
|
-
const
|
|
202
|
+
const q = function(r, t) {
|
|
203
|
+
const e = {};
|
|
203
204
|
for (const o in r) {
|
|
204
205
|
const s = r[o];
|
|
205
|
-
|
|
206
|
+
t.includes(o) && s !== null && (e[o] = s);
|
|
206
207
|
}
|
|
207
|
-
return
|
|
208
|
-
}, H = (r) => r === "email",
|
|
208
|
+
return e;
|
|
209
|
+
}, H = (r) => r === "email", J = () => ({
|
|
209
210
|
singleTag: "hr"
|
|
210
|
-
}),
|
|
211
|
+
}), W = () => ({
|
|
211
212
|
tag: "blockquote"
|
|
212
213
|
}), V = () => ({
|
|
213
214
|
tag: "ul"
|
|
214
|
-
}),
|
|
215
|
+
}), Z = (r) => ({
|
|
215
216
|
tag: [
|
|
216
217
|
"pre",
|
|
217
218
|
{
|
|
@@ -219,11 +220,11 @@ const q = function(r, e) {
|
|
|
219
220
|
attrs: r.attrs
|
|
220
221
|
}
|
|
221
222
|
]
|
|
222
|
-
}),
|
|
223
|
+
}), G = () => ({
|
|
223
224
|
singleTag: "br"
|
|
224
|
-
}),
|
|
225
|
+
}), K = (r) => ({
|
|
225
226
|
tag: `h${r.attrs.level}`
|
|
226
|
-
}),
|
|
227
|
+
}), Q = (r) => ({
|
|
227
228
|
singleTag: [
|
|
228
229
|
{
|
|
229
230
|
tag: "img",
|
|
@@ -232,7 +233,7 @@ const q = function(r, e) {
|
|
|
232
233
|
]
|
|
233
234
|
}), Y = () => ({
|
|
234
235
|
tag: "li"
|
|
235
|
-
}),
|
|
236
|
+
}), X = () => ({
|
|
236
237
|
tag: "ol"
|
|
237
238
|
}), ee = () => ({
|
|
238
239
|
tag: "p"
|
|
@@ -264,17 +265,17 @@ const q = function(r, e) {
|
|
|
264
265
|
return {
|
|
265
266
|
tag: ""
|
|
266
267
|
};
|
|
267
|
-
const
|
|
268
|
-
if (delete
|
|
269
|
-
for (const s in
|
|
270
|
-
|
|
271
|
-
delete
|
|
268
|
+
const t = new U().escapeHTML, e = { ...r.attrs }, { linktype: o = "url" } = r.attrs;
|
|
269
|
+
if (delete e.linktype, e.href && (e.href = t(r.attrs.href || "")), H(o) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), e.custom) {
|
|
270
|
+
for (const s in e.custom)
|
|
271
|
+
e[s] = e.custom[s];
|
|
272
|
+
delete e.custom;
|
|
272
273
|
}
|
|
273
274
|
return {
|
|
274
275
|
tag: [
|
|
275
276
|
{
|
|
276
277
|
tag: "a",
|
|
277
|
-
attrs:
|
|
278
|
+
attrs: e
|
|
278
279
|
}
|
|
279
280
|
]
|
|
280
281
|
};
|
|
@@ -297,8 +298,8 @@ const q = function(r, e) {
|
|
|
297
298
|
}
|
|
298
299
|
]
|
|
299
300
|
}), pe = (r) => {
|
|
300
|
-
var
|
|
301
|
-
return (
|
|
301
|
+
var t;
|
|
302
|
+
return (t = r.attrs) != null && t.color ? {
|
|
302
303
|
tag: [
|
|
303
304
|
{
|
|
304
305
|
tag: "span",
|
|
@@ -311,8 +312,8 @@ const q = function(r, e) {
|
|
|
311
312
|
tag: ""
|
|
312
313
|
};
|
|
313
314
|
}, fe = (r) => {
|
|
314
|
-
var
|
|
315
|
-
return (
|
|
315
|
+
var t;
|
|
316
|
+
return (t = r.attrs) != null && t.color ? {
|
|
316
317
|
tag: [
|
|
317
318
|
{
|
|
318
319
|
tag: "span",
|
|
@@ -326,15 +327,15 @@ const q = function(r, e) {
|
|
|
326
327
|
};
|
|
327
328
|
}, he = {
|
|
328
329
|
nodes: {
|
|
329
|
-
horizontal_rule:
|
|
330
|
-
blockquote:
|
|
330
|
+
horizontal_rule: J,
|
|
331
|
+
blockquote: W,
|
|
331
332
|
bullet_list: V,
|
|
332
|
-
code_block:
|
|
333
|
-
hard_break:
|
|
334
|
-
heading:
|
|
335
|
-
image:
|
|
333
|
+
code_block: Z,
|
|
334
|
+
hard_break: G,
|
|
335
|
+
heading: K,
|
|
336
|
+
image: Q,
|
|
336
337
|
list_item: Y,
|
|
337
|
-
ordered_list:
|
|
338
|
+
ordered_list: X,
|
|
338
339
|
paragraph: ee,
|
|
339
340
|
emoji: te
|
|
340
341
|
},
|
|
@@ -353,35 +354,35 @@ const q = function(r, e) {
|
|
|
353
354
|
highlight: pe,
|
|
354
355
|
textStyle: fe
|
|
355
356
|
}
|
|
356
|
-
},
|
|
357
|
-
const
|
|
357
|
+
}, ye = function(r) {
|
|
358
|
+
const t = {
|
|
358
359
|
"&": "&",
|
|
359
360
|
"<": "<",
|
|
360
361
|
">": ">",
|
|
361
362
|
'"': """,
|
|
362
363
|
"'": "'"
|
|
363
|
-
},
|
|
364
|
-
return r && o.test(r) ? r.replace(
|
|
364
|
+
}, e = /[&<>"']/g, o = new RegExp(e.source);
|
|
365
|
+
return r && o.test(r) ? r.replace(e, (s) => t[s]) : r;
|
|
365
366
|
};
|
|
366
367
|
let S = !1;
|
|
367
|
-
class
|
|
368
|
-
constructor(
|
|
369
|
-
g(this, "marks"), g(this, "nodes"),
|
|
368
|
+
class be {
|
|
369
|
+
constructor(t) {
|
|
370
|
+
g(this, "marks"), g(this, "nodes"), t || (t = he), this.marks = t.marks || [], this.nodes = t.nodes || [];
|
|
370
371
|
}
|
|
371
|
-
addNode(
|
|
372
|
-
this.nodes[
|
|
372
|
+
addNode(t, e) {
|
|
373
|
+
this.nodes[t] = e;
|
|
373
374
|
}
|
|
374
|
-
addMark(
|
|
375
|
-
this.marks[
|
|
375
|
+
addMark(t, e) {
|
|
376
|
+
this.marks[t] = e;
|
|
376
377
|
}
|
|
377
|
-
render(
|
|
378
|
+
render(t, e = { optimizeImages: !1 }, o = !0) {
|
|
378
379
|
if (!S && o && (console.warn(
|
|
379
380
|
"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/"
|
|
380
|
-
), S = !0),
|
|
381
|
+
), S = !0), t && t.content && Array.isArray(t.content)) {
|
|
381
382
|
let s = "";
|
|
382
|
-
return
|
|
383
|
+
return t.content.forEach((n) => {
|
|
383
384
|
s += this.renderNode(n);
|
|
384
|
-
}),
|
|
385
|
+
}), e.optimizeImages ? this.optimizeImages(s, e.optimizeImages) : s;
|
|
385
386
|
}
|
|
386
387
|
return console.warn(
|
|
387
388
|
`The render method must receive an Object with a "content" field.
|
|
@@ -410,55 +411,55 @@ class ye {
|
|
|
410
411
|
}`
|
|
411
412
|
), "";
|
|
412
413
|
}
|
|
413
|
-
optimizeImages(
|
|
414
|
+
optimizeImages(t, e) {
|
|
414
415
|
let o = 0, s = 0, n = "", a = "";
|
|
415
|
-
typeof
|
|
416
|
+
typeof e != "boolean" && (typeof e.width == "number" && e.width > 0 && (n += `width="${e.width}" `, o = e.width), typeof e.height == "number" && e.height > 0 && (n += `height="${e.height}" `, s = e.height), (e.loading === "lazy" || e.loading === "eager") && (n += `loading="${e.loading}" `), typeof e.class == "string" && e.class.length > 0 && (n += `class="${e.class}" `), e.filters && (typeof e.filters.blur == "number" && e.filters.blur >= 0 && e.filters.blur <= 100 && (a += `:blur(${e.filters.blur})`), typeof e.filters.brightness == "number" && e.filters.brightness >= -100 && e.filters.brightness <= 100 && (a += `:brightness(${e.filters.brightness})`), e.filters.fill && (e.filters.fill.match(/[0-9A-F]{6}/gi) || e.filters.fill === "transparent") && (a += `:fill(${e.filters.fill})`), e.filters.format && ["webp", "png", "jpeg"].includes(e.filters.format) && (a += `:format(${e.filters.format})`), typeof e.filters.grayscale == "boolean" && e.filters.grayscale && (a += ":grayscale()"), typeof e.filters.quality == "number" && e.filters.quality >= 0 && e.filters.quality <= 100 && (a += `:quality(${e.filters.quality})`), e.filters.rotate && [90, 180, 270].includes(e.filters.rotate) && (a += `:rotate(${e.filters.rotate})`), a.length > 0 && (a = `/filters${a}`))), n.length > 0 && (t = t.replace(/<img/g, `<img ${n.trim()}`));
|
|
416
417
|
const l = o > 0 || s > 0 || a.length > 0 ? `${o}x${s}${a}` : "";
|
|
417
|
-
return
|
|
418
|
+
return t = t.replace(
|
|
418
419
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,
|
|
419
420
|
`a.storyblok.com/f/$1/$2.$3/m/${l}`
|
|
420
|
-
), typeof
|
|
421
|
+
), typeof e != "boolean" && (e.sizes || e.srcset) && (t = t.replace(/<img.*?src=["|'](.*?)["|']/g, (i) => {
|
|
421
422
|
var c, u;
|
|
422
423
|
const p = i.match(
|
|
423
424
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g
|
|
424
425
|
);
|
|
425
426
|
if (p && p.length > 0) {
|
|
426
427
|
const f = {
|
|
427
|
-
srcset: (c =
|
|
428
|
+
srcset: (c = e.srcset) == null ? void 0 : c.map((d) => {
|
|
428
429
|
if (typeof d == "number")
|
|
429
430
|
return `//${p}/m/${d}x0${a} ${d}w`;
|
|
430
431
|
if (typeof d == "object" && d.length === 2) {
|
|
431
|
-
let
|
|
432
|
-
return typeof d[0] == "number" && (
|
|
432
|
+
let y = 0, m = 0;
|
|
433
|
+
return typeof d[0] == "number" && (y = d[0]), typeof d[1] == "number" && (m = d[1]), `//${p}/m/${y}x${m}${a} ${y}w`;
|
|
433
434
|
}
|
|
434
435
|
return "";
|
|
435
436
|
}).join(", "),
|
|
436
|
-
sizes: (u =
|
|
437
|
+
sizes: (u = e.sizes) == null ? void 0 : u.map((d) => d).join(", ")
|
|
437
438
|
};
|
|
438
439
|
let h = "";
|
|
439
440
|
return f.srcset && (h += `srcset="${f.srcset}" `), f.sizes && (h += `sizes="${f.sizes}" `), i.replace(/<img/g, `<img ${h.trim()}`);
|
|
440
441
|
}
|
|
441
442
|
return i;
|
|
442
|
-
})),
|
|
443
|
+
})), t;
|
|
443
444
|
}
|
|
444
|
-
renderNode(
|
|
445
|
-
const
|
|
446
|
-
|
|
445
|
+
renderNode(t) {
|
|
446
|
+
const e = [];
|
|
447
|
+
t.marks && t.marks.forEach((s) => {
|
|
447
448
|
const n = this.getMatchingMark(s);
|
|
448
|
-
n && n.tag !== "" &&
|
|
449
|
+
n && n.tag !== "" && e.push(this.renderOpeningTag(n.tag));
|
|
449
450
|
});
|
|
450
|
-
const o = this.getMatchingNode(
|
|
451
|
-
return o && o.tag &&
|
|
452
|
-
|
|
453
|
-
}) :
|
|
451
|
+
const o = this.getMatchingNode(t);
|
|
452
|
+
return o && o.tag && e.push(this.renderOpeningTag(o.tag)), t.content ? t.content.forEach((s) => {
|
|
453
|
+
e.push(this.renderNode(s));
|
|
454
|
+
}) : t.text ? e.push(ye(t.text)) : o && o.singleTag ? e.push(this.renderTag(o.singleTag, " /")) : o && o.html ? e.push(o.html) : t.type === "emoji" && e.push(this.renderEmoji(t)), o && o.tag && e.push(this.renderClosingTag(o.tag)), t.marks && t.marks.slice(0).reverse().forEach((s) => {
|
|
454
455
|
const n = this.getMatchingMark(s);
|
|
455
|
-
n && n.tag !== "" &&
|
|
456
|
-
}),
|
|
456
|
+
n && n.tag !== "" && e.push(this.renderClosingTag(n.tag));
|
|
457
|
+
}), e.join("");
|
|
457
458
|
}
|
|
458
|
-
renderTag(
|
|
459
|
-
return
|
|
459
|
+
renderTag(t, e) {
|
|
460
|
+
return t.constructor === String ? `<${t}${e}>` : t.map((o) => {
|
|
460
461
|
if (o.constructor === String)
|
|
461
|
-
return `<${o}${
|
|
462
|
+
return `<${o}${e}>`;
|
|
462
463
|
{
|
|
463
464
|
let s = `<${o.tag}`;
|
|
464
465
|
if (o.attrs) {
|
|
@@ -468,108 +469,111 @@ class ye {
|
|
|
468
469
|
a !== null && (s += ` ${n}="${a}"`);
|
|
469
470
|
}
|
|
470
471
|
}
|
|
471
|
-
return `${s}${
|
|
472
|
+
return `${s}${e}>`;
|
|
472
473
|
}
|
|
473
474
|
}).join("");
|
|
474
475
|
}
|
|
475
|
-
renderOpeningTag(
|
|
476
|
-
return this.renderTag(
|
|
476
|
+
renderOpeningTag(t) {
|
|
477
|
+
return this.renderTag(t, "");
|
|
477
478
|
}
|
|
478
|
-
renderClosingTag(
|
|
479
|
-
return
|
|
479
|
+
renderClosingTag(t) {
|
|
480
|
+
return t.constructor === String ? `</${t}>` : t.slice(0).reverse().map((e) => e.constructor === String ? `</${e}>` : `</${e.tag}>`).join("");
|
|
480
481
|
}
|
|
481
|
-
getMatchingNode(
|
|
482
|
-
const
|
|
483
|
-
if (typeof
|
|
484
|
-
return t
|
|
482
|
+
getMatchingNode(t) {
|
|
483
|
+
const e = this.nodes[t.type];
|
|
484
|
+
if (typeof e == "function")
|
|
485
|
+
return e(t);
|
|
485
486
|
}
|
|
486
|
-
getMatchingMark(
|
|
487
|
-
const
|
|
488
|
-
if (typeof
|
|
489
|
-
return t
|
|
487
|
+
getMatchingMark(t) {
|
|
488
|
+
const e = this.marks[t.type];
|
|
489
|
+
if (typeof e == "function")
|
|
490
|
+
return e(t);
|
|
490
491
|
}
|
|
491
|
-
renderEmoji(
|
|
492
|
-
if (
|
|
493
|
-
return
|
|
494
|
-
const
|
|
492
|
+
renderEmoji(t) {
|
|
493
|
+
if (t.attrs.emoji)
|
|
494
|
+
return t.attrs.emoji;
|
|
495
|
+
const e = [
|
|
495
496
|
{
|
|
496
497
|
tag: "img",
|
|
497
498
|
attrs: {
|
|
498
|
-
src:
|
|
499
|
+
src: t.attrs.fallbackImage,
|
|
499
500
|
draggable: "false",
|
|
500
501
|
loading: "lazy",
|
|
501
502
|
align: "absmiddle"
|
|
502
503
|
}
|
|
503
504
|
}
|
|
504
505
|
];
|
|
505
|
-
return this.renderTag(
|
|
506
|
+
return this.renderTag(e, " /");
|
|
506
507
|
}
|
|
507
508
|
}
|
|
508
|
-
const
|
|
509
|
+
const Te = (r) => {
|
|
509
510
|
if (typeof r != "object" || typeof r._editable > "u")
|
|
510
511
|
return {};
|
|
511
512
|
try {
|
|
512
|
-
const
|
|
513
|
+
const t = JSON.parse(
|
|
513
514
|
r._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
|
|
514
515
|
);
|
|
515
|
-
return
|
|
516
|
-
"data-blok-c": JSON.stringify(
|
|
517
|
-
"data-blok-uid":
|
|
516
|
+
return t ? {
|
|
517
|
+
"data-blok-c": JSON.stringify(t),
|
|
518
|
+
"data-blok-uid": `${t.id}-${t.uid}`
|
|
518
519
|
} : {};
|
|
519
520
|
} catch {
|
|
520
521
|
return {};
|
|
521
522
|
}
|
|
522
523
|
};
|
|
523
|
-
let
|
|
524
|
-
const
|
|
525
|
-
r.addNode("blok", (
|
|
524
|
+
let me, ke = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
|
525
|
+
const we = (r, t) => {
|
|
526
|
+
r.addNode("blok", (e) => {
|
|
526
527
|
let o = "";
|
|
527
|
-
return
|
|
528
|
-
o +=
|
|
528
|
+
return e.attrs.body.forEach((s) => {
|
|
529
|
+
o += t(s.component, s);
|
|
529
530
|
}), {
|
|
530
531
|
html: o
|
|
531
532
|
};
|
|
532
533
|
});
|
|
533
|
-
},
|
|
534
|
-
|
|
534
|
+
}, $e = (r) => {
|
|
535
|
+
var t;
|
|
536
|
+
return !r || !((t = r == null ? void 0 : r.content) != null && t.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule"));
|
|
537
|
+
}, ve = (r, t, e) => {
|
|
538
|
+
let o = e || me;
|
|
535
539
|
if (!o) {
|
|
536
540
|
console.error(
|
|
537
541
|
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
|
538
542
|
);
|
|
539
543
|
return;
|
|
540
544
|
}
|
|
541
|
-
return
|
|
542
|
-
},
|
|
543
|
-
function
|
|
545
|
+
return $e(r) ? "" : (t && (o = new be(t.schema), t.resolver && we(o, t.resolver)), o.render(r, {}, !1));
|
|
546
|
+
}, xe = () => B(ke);
|
|
547
|
+
function Ae() {
|
|
544
548
|
if (!(globalThis != null && globalThis.storyblokApiInstance))
|
|
545
549
|
throw new Error("storyblokApiInstance has not been initialized correctly");
|
|
546
550
|
return globalThis.storyblokApiInstance;
|
|
547
551
|
}
|
|
548
|
-
async function
|
|
549
|
-
let
|
|
550
|
-
return r && r.locals._storyblok_preview_data && (
|
|
552
|
+
async function Ee(r) {
|
|
553
|
+
let t = null;
|
|
554
|
+
return r && r.locals._storyblok_preview_data && (t = r.locals._storyblok_preview_data), t;
|
|
551
555
|
}
|
|
552
|
-
function
|
|
556
|
+
function Le(r, t) {
|
|
553
557
|
var o;
|
|
554
|
-
const
|
|
555
|
-
if (!
|
|
558
|
+
const e = (o = globalThis == null ? void 0 : globalThis.storyblokApiInstance) == null ? void 0 : o.richTextResolver;
|
|
559
|
+
if (!e)
|
|
556
560
|
throw new Error(
|
|
557
561
|
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
|
558
562
|
);
|
|
559
|
-
return
|
|
563
|
+
return ve(r, t, e);
|
|
560
564
|
}
|
|
561
|
-
function
|
|
565
|
+
function Ce(r) {
|
|
562
566
|
return typeof r == "object" ? `const storyblokInstance = new StoryblokBridge(${JSON.stringify(r)});` : "const storyblokInstance = new StoryblokBridge();";
|
|
563
567
|
}
|
|
564
568
|
function je(r) {
|
|
565
|
-
const
|
|
569
|
+
const t = {
|
|
566
570
|
useCustomApi: !1,
|
|
567
571
|
bridge: !0,
|
|
568
572
|
componentsDir: "src",
|
|
569
573
|
enableFallbackComponent: !1,
|
|
570
574
|
livePreview: !1,
|
|
571
575
|
...r
|
|
572
|
-
},
|
|
576
|
+
}, e = Ce(t.bridge);
|
|
573
577
|
return {
|
|
574
578
|
name: "@storyblok/astro",
|
|
575
579
|
hooks: {
|
|
@@ -584,20 +588,20 @@ function je(r) {
|
|
|
584
588
|
vite: {
|
|
585
589
|
plugins: [
|
|
586
590
|
N(
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
591
|
+
t.accessToken,
|
|
592
|
+
t.useCustomApi,
|
|
593
|
+
t.apiOptions
|
|
590
594
|
),
|
|
591
595
|
_(
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
+
t.componentsDir,
|
|
597
|
+
t.components,
|
|
598
|
+
t.enableFallbackComponent,
|
|
599
|
+
t.customFallbackComponent
|
|
596
600
|
),
|
|
597
|
-
z(
|
|
601
|
+
z(t)
|
|
598
602
|
]
|
|
599
603
|
}
|
|
600
|
-
}),
|
|
604
|
+
}), t.livePreview && (l == null ? void 0 : l.output) !== "server")
|
|
601
605
|
throw new Error(
|
|
602
606
|
"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."
|
|
603
607
|
);
|
|
@@ -607,12 +611,12 @@ function je(r) {
|
|
|
607
611
|
import { storyblokApiInstance } from "virtual:storyblok-init";
|
|
608
612
|
globalThis.storyblokApiInstance = storyblokApiInstance;
|
|
609
613
|
`
|
|
610
|
-
),
|
|
614
|
+
), t.bridge && !t.livePreview && o(
|
|
611
615
|
"page",
|
|
612
616
|
`import { loadStoryblokBridge } from "@storyblok/astro";
|
|
613
617
|
loadStoryblokBridge().then(() => {
|
|
614
618
|
const { StoryblokBridge, location } = window;
|
|
615
|
-
${
|
|
619
|
+
${e}
|
|
616
620
|
storyblokInstance.on(["published", "change"], (event) => {
|
|
617
621
|
if (!event.slugChanged) {
|
|
618
622
|
location.reload(true);
|
|
@@ -620,12 +624,12 @@ function je(r) {
|
|
|
620
624
|
});
|
|
621
625
|
});
|
|
622
626
|
`
|
|
623
|
-
),
|
|
627
|
+
), t.livePreview && (o(
|
|
624
628
|
"page",
|
|
625
629
|
`import { loadStoryblokBridge, handleStoryblokMessage } from "@storyblok/astro";
|
|
626
630
|
loadStoryblokBridge().then(() => {
|
|
627
631
|
const { StoryblokBridge, location } = window;
|
|
628
|
-
${
|
|
632
|
+
${e}
|
|
629
633
|
storyblokInstance.on(["published", "change", "input"], handleStoryblokMessage);
|
|
630
634
|
});
|
|
631
635
|
`
|
|
@@ -643,31 +647,31 @@ function je(r) {
|
|
|
643
647
|
};
|
|
644
648
|
}
|
|
645
649
|
let T;
|
|
646
|
-
async function
|
|
647
|
-
const { action:
|
|
648
|
-
if (
|
|
650
|
+
async function Re(r) {
|
|
651
|
+
const { action: t, story: e } = r || {};
|
|
652
|
+
if (t === "input" && e) {
|
|
649
653
|
const o = async () => {
|
|
650
|
-
const n = await
|
|
654
|
+
const n = await Se(e), a = document.body;
|
|
651
655
|
if (n.outerHTML === a.outerHTML)
|
|
652
656
|
return;
|
|
653
657
|
const l = document.querySelector('[data-blok-focused="true"]');
|
|
654
|
-
|
|
658
|
+
Ie(a, n, l), document.dispatchEvent(new Event("storyblok-live-preview-updated"));
|
|
655
659
|
};
|
|
656
660
|
clearTimeout(T), T = setTimeout(o, 500);
|
|
657
661
|
}
|
|
658
662
|
["published", "change"].includes(r == null ? void 0 : r.action) && location.reload();
|
|
659
663
|
}
|
|
660
|
-
function
|
|
661
|
-
if (
|
|
662
|
-
const o =
|
|
664
|
+
function Ie(r, t, e) {
|
|
665
|
+
if (e) {
|
|
666
|
+
const o = e.getAttribute("data-blok-uid"), s = t.querySelector(
|
|
663
667
|
`[data-blok-uid="${o}"]`
|
|
664
668
|
);
|
|
665
|
-
s && (s.setAttribute("data-blok-focused", "true"),
|
|
669
|
+
s && (s.setAttribute("data-blok-focused", "true"), e.replaceWith(s));
|
|
666
670
|
} else
|
|
667
|
-
r.replaceWith(
|
|
671
|
+
r.replaceWith(t);
|
|
668
672
|
}
|
|
669
|
-
async function
|
|
670
|
-
const
|
|
673
|
+
async function Se(r) {
|
|
674
|
+
const e = await (await fetch(location.href, {
|
|
671
675
|
method: "POST",
|
|
672
676
|
body: JSON.stringify({
|
|
673
677
|
...r,
|
|
@@ -677,17 +681,17 @@ async function Te(r) {
|
|
|
677
681
|
"Content-Type": "application/json"
|
|
678
682
|
}
|
|
679
683
|
})).text();
|
|
680
|
-
return new DOMParser().parseFromString(
|
|
684
|
+
return new DOMParser().parseFromString(e, "text/html").body;
|
|
681
685
|
}
|
|
682
686
|
export {
|
|
683
|
-
|
|
687
|
+
be as RichTextResolver,
|
|
684
688
|
he as RichTextSchema,
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
+
Ee as getLiveStory,
|
|
690
|
+
Re as handleStoryblokMessage,
|
|
691
|
+
xe as loadStoryblokBridge,
|
|
692
|
+
Le as renderRichText,
|
|
689
693
|
je as storyblok,
|
|
690
|
-
|
|
694
|
+
Te as storyblokEditable,
|
|
691
695
|
v as toCamelCase,
|
|
692
|
-
|
|
696
|
+
Ae as useStoryblokApi
|
|
693
697
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(u,
|
|
1
|
+
(function(u,y){typeof exports=="object"&&typeof module<"u"?y(exports):typeof define=="function"&&define.amd?define(["exports"],y):(u=typeof globalThis<"u"?globalThis:u||self,y(u.storyblokAstro={}))})(this,function(u){"use strict";const y=`<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,17 +7,17 @@
|
|
|
7
7
|
</g>
|
|
8
8
|
</g>
|
|
9
9
|
</g>
|
|
10
|
-
</svg>`,
|
|
10
|
+
</svg>`,R=/[\p{Lu}]/u,M=/[\p{Ll}]/u,$=/^[\p{Lu}](?![\p{Lu}])/gu,v=/([\p{Alpha}\p{N}_]|$)/u,b=/[_.\- ]+/,P=new RegExp("^"+b.source),C=new RegExp(b.source+v.source,"gu"),S=new RegExp("\\d+"+v.source,"gu"),O=(r,t,e,o)=>{let s=!1,n=!1,a=!1,l=!1;for(let i=0;i<r.length;i++){const c=r[i];l=i>2?r[i-3]==="-":!0,s&&R.test(c)?(r=r.slice(0,i)+"-"+r.slice(i),s=!1,a=n,n=!0,i++):n&&a&&M.test(c)&&(!l||o)?(r=r.slice(0,i-1)+"-"+r.slice(i-1),a=n,n=!1,s=!0):(s=t(c)===c&&e(c)!==c,a=n,n=e(c)===c&&t(c)!==c)}return r},_=(r,t)=>($.lastIndex=0,r.replaceAll($,e=>t(e))),N=(r,t)=>(C.lastIndex=0,S.lastIndex=0,r.replaceAll(S,(e,o,s)=>["_","-"].includes(r.charAt(s+e.length))?e:t(e)).replaceAll(C,(e,o)=>t(o)));function z(r,t){if(!(typeof r=="string"||Array.isArray(r)))throw new TypeError("Expected the input to be `string | string[]`");if(t={pascalCase:!1,preserveConsecutiveUppercase:!1,...t},Array.isArray(r)?r=r.map(n=>n.trim()).filter(n=>n.length).join("-"):r=r.trim(),r.length===0)return"";const e=t.locale===!1?n=>n.toLowerCase():n=>n.toLocaleLowerCase(t.locale),o=t.locale===!1?n=>n.toUpperCase():n=>n.toLocaleUpperCase(t.locale);return r.length===1?b.test(r)?"":t.pascalCase?o(r):e(r):(r!==e(r)&&(r=O(r,e,o,t.preserveConsecutiveUppercase)),r=r.replace(P,""),r=t.preserveConsecutiveUppercase?_(r,e):e(r),t.pascalCase&&(r=o(r.charAt(0))+r.slice(1)),N(r,o))}function m(r){return z(r)}function B(r,t={},e,o){const s="virtual:storyblok-components",n=`\0${s}`;return{name:"vite-plugin-storyblok-components",async resolveId(a){if(a===s)return n},async load(a){if(a===n){const l=[],i=[];for await(const[d,f]of Object.entries(t)){const h=await this.resolve(`/${r}/${f}.astro`);if(h)l.push(`import ${m(d)} from "${h.id}"`);else if(e)i.push(d);else throw new Error(`Component could not be found for blok "${d}"! Does "${`/${r}/${f}`}.astro" exist?`)}let c="";if(e)if(c=",FallbackComponent",o){const d=await this.resolve(`/${r}/${o}.astro`);if(!d)throw new Error(`Custom fallback component could not be found. Does "${`/${r}/${o}`}.astro" exist?`);l.push(`import FallbackComponent from "${d.id}"`)}else l.push("import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'");if(Object.values(t).length)return`${l.join(";")};export default {${Object.keys(t).filter(d=>!i.includes(d)).map(d=>m(d)).join(",")}${c}}`;if(e)return`${l[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 F(r,e
|
|
12
|
+
Detailed information can be found here: https://github.com/storyblok/storyblok-astro`)}}}}function F(r,t,e){const o="virtual:storyblok-init",s=`\0${o}`;return{name:"vite-plugin-storyblok-init",async resolveId(n){if(n===o)return s},async load(n){if(n===s)return`
|
|
13
13
|
import { storyblokInit, apiPlugin } from "@storyblok/js";
|
|
14
14
|
const { storyblokApi } = storyblokInit({
|
|
15
15
|
accessToken: "${r}",
|
|
16
|
-
use: ${
|
|
17
|
-
apiOptions: ${JSON.stringify(
|
|
16
|
+
use: ${t?"[]":"[apiPlugin]"},
|
|
17
|
+
apiOptions: ${JSON.stringify(e)},
|
|
18
18
|
});
|
|
19
19
|
export const storyblokApiInstance = storyblokApi;
|
|
20
|
-
`}}}function D(r){const
|
|
20
|
+
`}}}function D(r){const t="virtual:storyblok-options",e=`\0${t}`;return{name:"vite-plugin-storyblok-options",async resolveId(o){if(o===t)return e},async load(o){if(o===e)return`export default ${JSON.stringify(r)}`}}}let I=!1;const T=[],U=r=>new Promise((t,e)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=s=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}I?s():T.push(s)},document.getElementById("storyblok-javascript-bridge")))return;const o=document.createElement("script");o.async=!0,o.src=r,o.id="storyblok-javascript-bridge",o.onerror=s=>e(s),o.onload=s=>{T.forEach(n=>n()),I=!0,t(s)},document.getElementsByTagName("head")[0].appendChild(o)});var q=Object.defineProperty,H=(r,t,e)=>t in r?q(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,p=(r,t,e)=>H(r,typeof t!="symbol"?t+"":t,e);let J=class{constructor(){p(this,"isCDNUrl",(r="")=>r.includes("/cdn/")),p(this,"getOptionsPage",(r,t=25,e=1)=>({...r,per_page:t,page:e})),p(this,"delay",r=>new Promise(t=>setTimeout(t,r))),p(this,"arrayFrom",(r=0,t)=>Array.from({length:r},t)),p(this,"range",(r=0,t=r)=>{const e=Math.abs(t-r)||0,o=r<t?1:-1;return this.arrayFrom(e,(s,n)=>n*o+r)}),p(this,"asyncMap",async(r,t)=>Promise.all(r.map(t))),p(this,"flatMap",(r=[],t)=>r.map(t).reduce((e,o)=>[...e,...o],[])),p(this,"escapeHTML",function(r){const t={"&":"&","<":"<",">":">",'"':""","'":"'"},e=/[&<>"']/g,o=new RegExp(e.source);return r&&o.test(r)?r.replace(e,s=>t[s]):r})}stringify(r,t,e){const o=[];for(const s in r){if(!Object.prototype.hasOwnProperty.call(r,s))continue;const n=r[s],a=e?"":encodeURIComponent(s);let l;typeof n=="object"?l=this.stringify(n,t?t+encodeURIComponent(`[${a}]`):a,Array.isArray(n)):l=`${t?t+encodeURIComponent(`[${a}]`):a}=${encodeURIComponent(n)}`,o.push(l)}return o.join("&")}getRegionURL(r){const t="api.storyblok.com",e="api-us.storyblok.com",o="app.storyblokchina.cn",s="api-ap.storyblok.com",n="api-ca.storyblok.com";switch(r){case"us":return e;case"cn":return o;case"ap":return s;case"ca":return n;default:return t}}};const W=function(r,t){const e={};for(const o in r){const s=r[o];t.includes(o)&&s!==null&&(e[o]=s)}return e},V=r=>r==="email",Z=()=>({singleTag:"hr"}),G=()=>({tag:"blockquote"}),K=()=>({tag:"ul"}),Q=r=>({tag:["pre",{tag:"code",attrs:r.attrs}]}),Y=()=>({singleTag:"br"}),X=r=>({tag:`h${r.attrs.level}`}),ee=r=>({singleTag:[{tag:"img",attrs:W(r.attrs,["src","alt","title"])}]}),te=()=>({tag:"li"}),re=()=>({tag:"ol"}),oe=()=>({tag:"p"}),se=r=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":r.attrs.name,emoji:r.attrs.emoji}}]}),ne=()=>({tag:"b"}),ae=()=>({tag:"s"}),le=()=>({tag:"u"}),ie=()=>({tag:"strong"}),ce=()=>({tag:"code"}),ue=()=>({tag:"i"}),de=r=>{if(!r.attrs)return{tag:""};const t=new J().escapeHTML,e={...r.attrs},{linktype:o="url"}=r.attrs;if(delete e.linktype,e.href&&(e.href=t(r.attrs.href||"")),V(o)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),e.custom){for(const s in e.custom)e[s]=e.custom[s];delete e.custom}return{tag:[{tag:"a",attrs:e}]}},ge=r=>({tag:[{tag:"span",attrs:r.attrs}]}),pe=()=>({tag:"sub"}),fe=()=>({tag:"sup"}),he=r=>({tag:[{tag:"span",attrs:r.attrs}]}),ye=r=>{var t;return(t=r.attrs)!=null&&t.color?{tag:[{tag:"span",attrs:{style:`background-color:${r.attrs.color};`}}]}:{tag:""}},be=r=>{var t;return(t=r.attrs)!=null&&t.color?{tag:[{tag:"span",attrs:{style:`color:${r.attrs.color}`}}]}:{tag:""}},A={nodes:{horizontal_rule:Z,blockquote:G,bullet_list:K,code_block:Q,hard_break:Y,heading:X,image:ee,list_item:te,ordered_list:re,paragraph:oe,emoji:se},marks:{bold:ne,strike:ae,underline:le,strong:ie,code:ce,italic:ue,link:de,styled:ge,subscript:pe,superscript:fe,anchor:he,highlight:ye,textStyle:be}},me=function(r){const t={"&":"&","<":"<",">":">",'"':""","'":"'"},e=/[&<>"']/g,o=new RegExp(e.source);return r&&o.test(r)?r.replace(e,s=>t[s]):r};let E=!1;class L{constructor(t){p(this,"marks"),p(this,"nodes"),t||(t=A),this.marks=t.marks||[],this.nodes=t.nodes||[]}addNode(t,e){this.nodes[t]=e}addMark(t,e){this.marks[t]=e}render(t,e={optimizeImages:!1},o=!0){if(!E&&o&&(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/"),E=!0),t&&t.content&&Array.isArray(t.content)){let s="";return t.content.forEach(n=>{s+=this.renderNode(n)}),e.optimizeImages?this.optimizeImages(s,e.optimizeImages):s}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,23 +40,23 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
|
|
|
40
40
|
}
|
|
41
41
|
],
|
|
42
42
|
type: 'doc'
|
|
43
|
-
}`),""}optimizeImages(e
|
|
43
|
+
}`),""}optimizeImages(t,e){let o=0,s=0,n="",a="";typeof e!="boolean"&&(typeof e.width=="number"&&e.width>0&&(n+=`width="${e.width}" `,o=e.width),typeof e.height=="number"&&e.height>0&&(n+=`height="${e.height}" `,s=e.height),(e.loading==="lazy"||e.loading==="eager")&&(n+=`loading="${e.loading}" `),typeof e.class=="string"&&e.class.length>0&&(n+=`class="${e.class}" `),e.filters&&(typeof e.filters.blur=="number"&&e.filters.blur>=0&&e.filters.blur<=100&&(a+=`:blur(${e.filters.blur})`),typeof e.filters.brightness=="number"&&e.filters.brightness>=-100&&e.filters.brightness<=100&&(a+=`:brightness(${e.filters.brightness})`),e.filters.fill&&(e.filters.fill.match(/[0-9A-F]{6}/gi)||e.filters.fill==="transparent")&&(a+=`:fill(${e.filters.fill})`),e.filters.format&&["webp","png","jpeg"].includes(e.filters.format)&&(a+=`:format(${e.filters.format})`),typeof e.filters.grayscale=="boolean"&&e.filters.grayscale&&(a+=":grayscale()"),typeof e.filters.quality=="number"&&e.filters.quality>=0&&e.filters.quality<=100&&(a+=`:quality(${e.filters.quality})`),e.filters.rotate&&[90,180,270].includes(e.filters.rotate)&&(a+=`:rotate(${e.filters.rotate})`),a.length>0&&(a=`/filters${a}`))),n.length>0&&(t=t.replace(/<img/g,`<img ${n.trim()}`));const l=o>0||s>0||a.length>0?`${o}x${s}${a}`:"";return t=t.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${l}`),typeof e!="boolean"&&(e.sizes||e.srcset)&&(t=t.replace(/<img.*?src=["|'](.*?)["|']/g,i=>{var c,d;const f=i.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g);if(f&&f.length>0){const h={srcset:(c=e.srcset)==null?void 0:c.map(g=>{if(typeof g=="number")return`//${f}/m/${g}x0${a} ${g}w`;if(typeof g=="object"&&g.length===2){let w=0,j=0;return typeof g[0]=="number"&&(w=g[0]),typeof g[1]=="number"&&(j=g[1]),`//${f}/m/${w}x${j}${a} ${w}w`}return""}).join(", "),sizes:(d=e.sizes)==null?void 0:d.map(g=>g).join(", ")};let k="";return h.srcset&&(k+=`srcset="${h.srcset}" `),h.sizes&&(k+=`sizes="${h.sizes}" `),i.replace(/<img/g,`<img ${k.trim()}`)}return i})),t}renderNode(t){const e=[];t.marks&&t.marks.forEach(s=>{const n=this.getMatchingMark(s);n&&n.tag!==""&&e.push(this.renderOpeningTag(n.tag))});const o=this.getMatchingNode(t);return o&&o.tag&&e.push(this.renderOpeningTag(o.tag)),t.content?t.content.forEach(s=>{e.push(this.renderNode(s))}):t.text?e.push(me(t.text)):o&&o.singleTag?e.push(this.renderTag(o.singleTag," /")):o&&o.html?e.push(o.html):t.type==="emoji"&&e.push(this.renderEmoji(t)),o&&o.tag&&e.push(this.renderClosingTag(o.tag)),t.marks&&t.marks.slice(0).reverse().forEach(s=>{const n=this.getMatchingMark(s);n&&n.tag!==""&&e.push(this.renderClosingTag(n.tag))}),e.join("")}renderTag(t,e){return t.constructor===String?`<${t}${e}>`:t.map(o=>{if(o.constructor===String)return`<${o}${e}>`;{let s=`<${o.tag}`;if(o.attrs){for(const n in o.attrs)if(Object.prototype.hasOwnProperty.call(o.attrs,n)){const a=o.attrs[n];a!==null&&(s+=` ${n}="${a}"`)}}return`${s}${e}>`}}).join("")}renderOpeningTag(t){return this.renderTag(t,"")}renderClosingTag(t){return t.constructor===String?`</${t}>`:t.slice(0).reverse().map(e=>e.constructor===String?`</${e}>`:`</${e.tag}>`).join("")}getMatchingNode(t){const e=this.nodes[t.type];if(typeof e=="function")return e(t)}getMatchingMark(t){const e=this.marks[t.type];if(typeof e=="function")return e(t)}renderEmoji(t){if(t.attrs.emoji)return t.attrs.emoji;const e=[{tag:"img",attrs:{src:t.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(e," /")}}const ke=r=>{if(typeof r!="object"||typeof r._editable>"u")return{};try{const t=JSON.parse(r._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return t?{"data-blok-c":JSON.stringify(t),"data-blok-uid":`${t.id}-${t.uid}`}:{}}catch{return{}}};let we,$e="https://app.storyblok.com/f/storyblok-v2-latest.js";const ve=(r,t)=>{r.addNode("blok",e=>{let o="";return e.attrs.body.forEach(s=>{o+=t(s.component,s)}),{html:o}})},Ce=r=>{var t;return!r||!((t=r==null?void 0:r.content)!=null&&t.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule"))},Se=(r,t,e)=>{let o=e||we;if(!o){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return Ce(r)?"":(t&&(o=new L(t.schema),t.resolver&&ve(o,t.resolver)),o.render(r,{},!1))},Ie=()=>U($e);function Te(){if(!(globalThis!=null&&globalThis.storyblokApiInstance))throw new Error("storyblokApiInstance has not been initialized correctly");return globalThis.storyblokApiInstance}async function Ae(r){let t=null;return r&&r.locals._storyblok_preview_data&&(t=r.locals._storyblok_preview_data),t}function Ee(r,t){var o;const e=(o=globalThis==null?void 0:globalThis.storyblokApiInstance)==null?void 0:o.richTextResolver;if(!e)throw new Error("Please initialize the Storyblok SDK before calling the renderRichText function");return Se(r,t,e)}function Le(r){return typeof r=="object"?`const storyblokInstance = new StoryblokBridge(${JSON.stringify(r)});`:"const storyblokInstance = new StoryblokBridge();"}function xe(r){const t={useCustomApi:!1,bridge:!0,componentsDir:"src",enableFallbackComponent:!1,livePreview:!1,...r},e=Le(t.bridge);return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:o,updateConfig:s,addDevToolbarApp:n,addMiddleware:a,config:l})=>{if(s({vite:{plugins:[F(t.accessToken,t.useCustomApi,t.apiOptions),B(t.componentsDir,t.components,t.enableFallbackComponent,t.customFallbackComponent),D(t)]}}),t.livePreview&&(l==null?void 0:l.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.");o("page-ssr",`
|
|
44
44
|
import { storyblokApiInstance } from "virtual:storyblok-init";
|
|
45
45
|
globalThis.storyblokApiInstance = storyblokApiInstance;
|
|
46
|
-
`),
|
|
46
|
+
`),t.bridge&&!t.livePreview&&o("page",`import { loadStoryblokBridge } from "@storyblok/astro";
|
|
47
47
|
loadStoryblokBridge().then(() => {
|
|
48
48
|
const { StoryblokBridge, location } = window;
|
|
49
|
-
${
|
|
49
|
+
${e}
|
|
50
50
|
storyblokInstance.on(["published", "change"], (event) => {
|
|
51
51
|
if (!event.slugChanged) {
|
|
52
52
|
location.reload(true);
|
|
53
53
|
}
|
|
54
54
|
});
|
|
55
55
|
});
|
|
56
|
-
`),
|
|
56
|
+
`),t.livePreview&&(o("page",`import { loadStoryblokBridge, handleStoryblokMessage } from "@storyblok/astro";
|
|
57
57
|
loadStoryblokBridge().then(() => {
|
|
58
58
|
const { StoryblokBridge, location } = window;
|
|
59
|
-
${
|
|
59
|
+
${e}
|
|
60
60
|
storyblokInstance.on(["published", "change", "input"], handleStoryblokMessage);
|
|
61
61
|
});
|
|
62
|
-
`),a({entrypoint:"@storyblok/astro/middleware.ts",order:"pre"})),n({id:"storyblok",name:"Storyblok",icon:
|
|
62
|
+
`),a({entrypoint:"@storyblok/astro/middleware.ts",order:"pre"})),n({id:"storyblok",name:"Storyblok",icon:y,entrypoint:"@storyblok/astro/toolbarApp.ts"})}}}}let x;async function je(r){const{action:t,story:e}=r||{};if(t==="input"&&e){const o=async()=>{const n=await Me(e),a=document.body;if(n.outerHTML===a.outerHTML)return;const l=document.querySelector('[data-blok-focused="true"]');Re(a,n,l),document.dispatchEvent(new Event("storyblok-live-preview-updated"))};clearTimeout(x),x=setTimeout(o,500)}["published","change"].includes(r==null?void 0:r.action)&&location.reload()}function Re(r,t,e){if(e){const o=e.getAttribute("data-blok-uid"),s=t.querySelector(`[data-blok-uid="${o}"]`);s&&(s.setAttribute("data-blok-focused","true"),e.replaceWith(s))}else r.replaceWith(t)}async function Me(r){const e=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(e,"text/html").body}u.RichTextResolver=L,u.RichTextSchema=A,u.getLiveStory=Ae,u.handleStoryblokMessage=je,u.loadStoryblokBridge=Ie,u.renderRichText=Ee,u.storyblok=xe,u.storyblokEditable=ke,u.toCamelCase=m,u.useStoryblokApi=Te,Object.defineProperty(u,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": "6.0.
|
|
4
|
+
"version": "6.0.2",
|
|
5
5
|
"private": false,
|
|
6
6
|
"packageManager": "pnpm@9.13.2",
|
|
7
7
|
"description": "Official Astro integration for the Storyblok Headless CMS",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"keywords": [
|
|
18
18
|
"astro",
|
|
19
19
|
"storyblok",
|
|
20
|
-
"astro-sdk"
|
|
20
|
+
"astro-sdk",
|
|
21
|
+
"withastro"
|
|
21
22
|
],
|
|
22
23
|
"exports": {
|
|
23
24
|
".": {
|
|
@@ -71,7 +72,7 @@
|
|
|
71
72
|
"astro": "^3.0.0 || ^4.0.0 || ^5.0.0"
|
|
72
73
|
},
|
|
73
74
|
"dependencies": {
|
|
74
|
-
"@storyblok/js": "3.
|
|
75
|
+
"@storyblok/js": "3.2.3",
|
|
75
76
|
"camelcase": "^8.0.0"
|
|
76
77
|
},
|
|
77
78
|
"devDependencies": {
|