@storyblok/astro 4.0.5-next.1 → 4.0.5

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.
@@ -1,76 +1,147 @@
1
- let _ = !1;
2
- const C = [], P = (o) => new Promise((e, t) => {
3
- if (typeof window > "u" || (window.storyblokRegisterEvent = (r) => {
1
+ function E(r, t, e) {
2
+ const o = "virtual:storyblok-init", s = "\0" + o;
3
+ return {
4
+ name: "vite-plugin-storyblok-init",
5
+ async resolveId(a) {
6
+ if (a === o)
7
+ return s;
8
+ },
9
+ async load(a) {
10
+ if (a === s)
11
+ return `
12
+ import { storyblokInit, apiPlugin } from "@storyblok/js";
13
+ const { storyblokApi } = storyblokInit({
14
+ accessToken: "${r}",
15
+ use: ${t ? "[]" : "[apiPlugin]"},
16
+ apiOptions: ${JSON.stringify(e)},
17
+ });
18
+ export const storyblokApiInstance = storyblokApi;
19
+ `;
20
+ }
21
+ };
22
+ }
23
+ const T = /[\p{Lu}]/u, x = /[\p{Ll}]/u, k = /^[\p{Lu}](?![\p{Lu}])/gu, C = /([\p{Alpha}\p{N}_]|$)/u, m = /[_.\- ]+/, S = new RegExp("^" + m.source), $ = new RegExp(m.source + C.source, "gu"), v = new RegExp("\\d+" + C.source, "gu"), j = (r, t, e, o) => {
24
+ let s = !1, a = !1, n = !1, c = !1;
25
+ for (let l = 0; l < r.length; l++) {
26
+ const i = r[l];
27
+ c = l > 2 ? r[l - 3] === "-" : !0, s && T.test(i) ? (r = r.slice(0, l) + "-" + r.slice(l), s = !1, n = a, a = !0, l++) : a && n && x.test(i) && (!c || o) ? (r = r.slice(0, l - 1) + "-" + r.slice(l - 1), n = a, a = !1, s = !0) : (s = t(i) === i && e(i) !== i, n = a, a = e(i) === i && t(i) !== i);
28
+ }
29
+ return r;
30
+ }, R = (r, t) => (k.lastIndex = 0, r.replaceAll(k, (e) => t(e))), O = (r, t) => ($.lastIndex = 0, v.lastIndex = 0, r.replaceAll(v, (e, o, s) => ["_", "-"].includes(r.charAt(s + e.length)) ? e : t(e)).replaceAll($, (e, o) => t(o)));
31
+ function I(r, t) {
32
+ if (!(typeof r == "string" || Array.isArray(r)))
33
+ throw new TypeError("Expected the input to be `string | string[]`");
34
+ if (t = {
35
+ pascalCase: !1,
36
+ preserveConsecutiveUppercase: !1,
37
+ ...t
38
+ }, Array.isArray(r) ? r = r.map((a) => a.trim()).filter((a) => a.length).join("-") : r = r.trim(), r.length === 0)
39
+ return "";
40
+ const e = t.locale === !1 ? (a) => a.toLowerCase() : (a) => a.toLocaleLowerCase(t.locale), o = t.locale === !1 ? (a) => a.toUpperCase() : (a) => a.toLocaleUpperCase(t.locale);
41
+ return r.length === 1 ? m.test(r) ? "" : t.pascalCase ? o(r) : e(r) : (r !== e(r) && (r = j(r, e, o, t.preserveConsecutiveUppercase)), r = r.replace(S, ""), r = t.preserveConsecutiveUppercase ? R(r, e) : e(r), t.pascalCase && (r = o(r.charAt(0)) + r.slice(1)), O(r, o));
42
+ }
43
+ function N(r, t, e, o) {
44
+ const s = "virtual:storyblok-components", a = "\0" + s;
45
+ return {
46
+ name: "vite-plugin-storyblok-components",
47
+ async resolveId(n) {
48
+ if (n === s)
49
+ return a;
50
+ },
51
+ async load(n) {
52
+ if (n === a) {
53
+ const c = [], l = [];
54
+ for await (const [g, f] of Object.entries(t)) {
55
+ const d = await this.resolve(
56
+ "/" + r + "/" + f + ".astro"
57
+ );
58
+ if (d)
59
+ c.push(`import ${I(g)} from "${d.id}"`);
60
+ else if (e)
61
+ l.push(g);
62
+ else
63
+ throw new Error(
64
+ `Component could not be found for blok "${g}"! Does "${"/" + r + "/" + f}.astro" exist?`
65
+ );
66
+ }
67
+ let i = "";
68
+ if (e)
69
+ if (i = ",FallbackComponent", o) {
70
+ const g = await this.resolve(
71
+ "/" + r + "/" + o + ".astro"
72
+ );
73
+ if (!g)
74
+ throw new Error(
75
+ `Custom fallback component could not be found. Does "${"/" + r + "/" + o}.astro" exist?`
76
+ );
77
+ c.push(
78
+ `import FallbackComponent from "${g.id}"`
79
+ );
80
+ } else
81
+ c.push(
82
+ "import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'"
83
+ );
84
+ if (Object.values(t).length)
85
+ return `${c.join(";")};export default {${Object.keys(t).filter((g) => !l.includes(g)).map((g) => I(g)).join(",")}${i}}`;
86
+ if (e)
87
+ return `${c[0]}; export default {${i.replace(",", "")}}`;
88
+ throw new Error(
89
+ `Currently, no Storyblok components are registered in astro.config.mjs.
90
+ Please register your components or enable the fallback component.
91
+ Detailed information can be found here: https://github.com/storyblok/storyblok-astro`
92
+ );
93
+ }
94
+ }
95
+ };
96
+ }
97
+ function L(r) {
98
+ const t = "virtual:storyblok-options", e = "\0" + t;
99
+ return {
100
+ name: "vite-plugin-storyblok-options",
101
+ async resolveId(o) {
102
+ if (o === t)
103
+ return e;
104
+ },
105
+ async load(o) {
106
+ if (o === e)
107
+ return `export default ${JSON.stringify(r)}`;
108
+ }
109
+ };
110
+ }
111
+ let w = !1;
112
+ const A = [], M = (r) => new Promise((t, e) => {
113
+ if (typeof window > "u" || (window.storyblokRegisterEvent = (s) => {
4
114
  if (window.location === window.parent.location) {
5
115
  console.warn("You are not in Draft Mode or in the Visual Editor.");
6
116
  return;
7
117
  }
8
- _ ? r() : C.push(r);
118
+ w ? s() : A.push(s);
9
119
  }, document.getElementById("storyblok-javascript-bridge")))
10
120
  return;
11
- const s = document.createElement("script");
12
- s.async = !0, s.src = o, s.id = "storyblok-javascript-bridge", s.onerror = (r) => t(r), s.onload = (r) => {
13
- C.forEach((i) => i()), _ = !0, e(r);
14
- }, document.getElementsByTagName("head")[0].appendChild(s);
121
+ const o = document.createElement("script");
122
+ o.async = !0, o.src = r, o.id = "storyblok-javascript-bridge", o.onerror = (s) => e(s), o.onload = (s) => {
123
+ A.forEach((a) => a()), w = !0, t(s);
124
+ }, document.getElementsByTagName("head")[0].appendChild(o);
15
125
  });
16
- var M = Object.defineProperty, U = (o, e, t) => e in o ? M(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t, u = (o, e, t) => (U(o, typeof e != "symbol" ? e + "" : e, t), t);
17
- function A(o) {
18
- return !(o !== o || o === 1 / 0 || o === -1 / 0);
19
- }
20
- function z(o, e, t) {
21
- if (!A(e))
22
- throw new TypeError("Expected `limit` to be a finite number");
23
- if (!A(t))
24
- throw new TypeError("Expected `interval` to be a finite number");
25
- const s = [];
26
- let r = [], i = 0;
27
- const n = function() {
28
- i++;
29
- const a = setTimeout(function() {
30
- i--, s.length > 0 && n(), r = r.filter(function(h) {
31
- return h !== a;
32
- });
33
- }, t);
34
- r.indexOf(a) < 0 && r.push(a);
35
- const l = s.shift();
36
- l.resolve(o.apply(l.self, l.args));
37
- }, c = function(...a) {
38
- const l = this;
39
- return new Promise(function(h, p) {
40
- s.push({
41
- resolve: h,
42
- reject: p,
43
- args: a,
44
- self: l
45
- }), i < e && n();
46
- });
47
- };
48
- return c.abort = function() {
49
- r.forEach(clearTimeout), r = [], s.forEach(function(a) {
50
- a.reject(function() {
51
- Error.call(this, "Throttled function aborted"), this.name = "AbortError";
52
- });
53
- }), s.length = 0;
54
- }, c;
55
- }
56
- class b {
126
+ var P = Object.defineProperty, _ = (r, t, e) => t in r ? P(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e, p = (r, t, e) => (_(r, typeof t != "symbol" ? t + "" : t, e), e);
127
+ class z {
57
128
  constructor() {
58
- u(this, "isCDNUrl", (e = "") => e.indexOf("/cdn/") > -1), u(this, "getOptionsPage", (e, t = 25, s = 1) => ({
59
- ...e,
60
- per_page: t,
61
- page: s
62
- })), u(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), u(this, "arrayFrom", (e = 0, t) => [...Array(e)].map(t)), u(this, "range", (e = 0, t = e) => {
63
- const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
64
- return this.arrayFrom(s, (i, n) => n * r + e);
65
- }), u(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), u(this, "flatMap", (e = [], t) => e.map(t).reduce((s, r) => [...s, ...r], [])), u(this, "escapeHTML", function(e) {
66
- const t = {
129
+ p(this, "isCDNUrl", (t = "") => t.indexOf("/cdn/") > -1), p(this, "getOptionsPage", (t, e = 25, o = 1) => ({
130
+ ...t,
131
+ per_page: e,
132
+ page: o
133
+ })), p(this, "delay", (t) => new Promise((e) => setTimeout(e, t))), p(this, "arrayFrom", (t = 0, e) => [...Array(t)].map(e)), p(this, "range", (t = 0, e = t) => {
134
+ const o = Math.abs(e - t) || 0, s = t < e ? 1 : -1;
135
+ return this.arrayFrom(o, (a, n) => n * s + t);
136
+ }), p(this, "asyncMap", async (t, e) => Promise.all(t.map(e))), p(this, "flatMap", (t = [], e) => t.map(e).reduce((o, s) => [...o, ...s], [])), p(this, "escapeHTML", function(t) {
137
+ const e = {
67
138
  "&": "&amp;",
68
139
  "<": "&lt;",
69
140
  ">": "&gt;",
70
141
  '"': "&quot;",
71
142
  "'": "&#39;"
72
- }, s = /[&<>"']/g, r = RegExp(s.source);
73
- return e && r.test(e) ? e.replace(s, (i) => t[i]) : e;
143
+ }, o = /[&<>"']/g, s = RegExp(o.source);
144
+ return t && s.test(t) ? t.replace(o, (a) => e[a]) : t;
74
145
  });
75
146
  }
76
147
  /**
@@ -80,223 +151,223 @@ class b {
80
151
  * @param {Boolean} isArray
81
152
  * @return {String} Stringified object
82
153
  */
83
- stringify(e, t, s) {
84
- const r = [];
85
- for (const i in e) {
86
- if (!Object.prototype.hasOwnProperty.call(e, i))
154
+ stringify(t, e, o) {
155
+ const s = [];
156
+ for (const a in t) {
157
+ if (!Object.prototype.hasOwnProperty.call(t, a))
87
158
  continue;
88
- const n = e[i], c = s ? "" : encodeURIComponent(i);
89
- let a;
90
- typeof n == "object" ? a = this.stringify(
159
+ const n = t[a], c = o ? "" : encodeURIComponent(a);
160
+ let l;
161
+ typeof n == "object" ? l = this.stringify(
91
162
  n,
92
- t ? t + encodeURIComponent("[" + c + "]") : c,
163
+ e ? e + encodeURIComponent("[" + c + "]") : c,
93
164
  Array.isArray(n)
94
- ) : a = (t ? t + encodeURIComponent("[" + c + "]") : c) + "=" + encodeURIComponent(n), r.push(a);
165
+ ) : l = (e ? e + encodeURIComponent("[" + c + "]") : c) + "=" + encodeURIComponent(n), s.push(l);
95
166
  }
96
- return r.join("&");
167
+ return s.join("&");
97
168
  }
98
169
  /**
99
170
  * @method getRegionURL
100
171
  * @param {String} regionCode region code, could be eu, us, cn, ap or ca
101
172
  * @return {String} The base URL of the region
102
173
  */
103
- getRegionURL(e) {
104
- const t = "api.storyblok.com", s = "api-us.storyblok.com", r = "app.storyblokchina.cn", i = "api-ap.storyblok.com", n = "api-ca.storyblok.com";
105
- switch (e) {
174
+ getRegionURL(t) {
175
+ const e = "api.storyblok.com", o = "api-us.storyblok.com", s = "app.storyblokchina.cn", a = "api-ap.storyblok.com", n = "api-ca.storyblok.com";
176
+ switch (t) {
106
177
  case "us":
107
- return s;
178
+ return o;
108
179
  case "cn":
109
- return r;
180
+ return s;
110
181
  case "ap":
111
- return i;
182
+ return a;
112
183
  case "ca":
113
184
  return n;
114
185
  default:
115
- return t;
186
+ return e;
116
187
  }
117
188
  }
118
189
  }
119
- const F = function(o, e) {
120
- const t = {};
121
- for (const s in o) {
122
- const r = o[s];
123
- e.indexOf(s) > -1 && r !== null && (t[s] = r);
124
- }
125
- return t;
126
- }, H = (o) => o === "email", q = () => ({
190
+ const U = function(r, t) {
191
+ const e = {};
192
+ for (const o in r) {
193
+ const s = r[o];
194
+ t.indexOf(o) > -1 && s !== null && (e[o] = s);
195
+ }
196
+ return e;
197
+ }, D = (r) => r === "email", B = () => ({
127
198
  singleTag: "hr"
128
- }), B = () => ({
199
+ }), q = () => ({
129
200
  tag: "blockquote"
130
- }), D = () => ({
201
+ }), F = () => ({
131
202
  tag: "ul"
132
- }), V = (o) => ({
203
+ }), J = (r) => ({
133
204
  tag: [
134
205
  "pre",
135
206
  {
136
207
  tag: "code",
137
- attrs: o.attrs
208
+ attrs: r.attrs
138
209
  }
139
210
  ]
140
- }), J = () => ({
211
+ }), K = () => ({
141
212
  singleTag: "br"
142
- }), K = (o) => ({
143
- tag: `h${o.attrs.level}`
144
- }), G = (o) => ({
213
+ }), V = (r) => ({
214
+ tag: `h${r.attrs.level}`
215
+ }), H = (r) => ({
145
216
  singleTag: [
146
217
  {
147
218
  tag: "img",
148
- attrs: F(o.attrs, ["src", "alt", "title"])
219
+ attrs: U(r.attrs, ["src", "alt", "title"])
149
220
  }
150
221
  ]
151
- }), W = () => ({
222
+ }), G = () => ({
152
223
  tag: "li"
153
- }), Y = () => ({
224
+ }), W = () => ({
154
225
  tag: "ol"
155
- }), Q = () => ({
226
+ }), Y = () => ({
156
227
  tag: "p"
157
- }), X = (o) => ({
228
+ }), Q = (r) => ({
158
229
  tag: [
159
230
  {
160
231
  tag: "span",
161
232
  attrs: {
162
233
  "data-type": "emoji",
163
- "data-name": o.attrs.name,
164
- emoji: o.attrs.emoji
234
+ "data-name": r.attrs.name,
235
+ emoji: r.attrs.emoji
165
236
  }
166
237
  }
167
238
  ]
168
- }), Z = () => ({
239
+ }), X = () => ({
169
240
  tag: "b"
170
- }), ee = () => ({
241
+ }), Z = () => ({
171
242
  tag: "s"
172
- }), te = () => ({
243
+ }), ee = () => ({
173
244
  tag: "u"
174
- }), se = () => ({
245
+ }), te = () => ({
175
246
  tag: "strong"
176
247
  }), re = () => ({
177
248
  tag: "code"
178
249
  }), oe = () => ({
179
250
  tag: "i"
180
- }), ie = (o) => {
181
- if (!o.attrs)
251
+ }), se = (r) => {
252
+ if (!r.attrs)
182
253
  return {
183
254
  tag: ""
184
255
  };
185
- const e = new b().escapeHTML, t = { ...o.attrs }, { linktype: s = "url" } = o.attrs;
186
- if (delete t.linktype, t.href && (t.href = e(o.attrs.href || "")), H(s) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
187
- for (const r in t.custom)
188
- t[r] = t.custom[r];
189
- delete t.custom;
256
+ const t = new z().escapeHTML, e = { ...r.attrs }, { linktype: o = "url" } = r.attrs;
257
+ if (delete e.linktype, e.href && (e.href = t(r.attrs.href || "")), D(o) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), e.custom) {
258
+ for (const s in e.custom)
259
+ e[s] = e.custom[s];
260
+ delete e.custom;
190
261
  }
191
262
  return {
192
263
  tag: [
193
264
  {
194
265
  tag: "a",
195
- attrs: t
266
+ attrs: e
196
267
  }
197
268
  ]
198
269
  };
199
- }, ne = (o) => ({
270
+ }, ae = (r) => ({
200
271
  tag: [
201
272
  {
202
273
  tag: "span",
203
- attrs: o.attrs
274
+ attrs: r.attrs
204
275
  }
205
276
  ]
206
- }), ae = () => ({
277
+ }), ne = () => ({
207
278
  tag: "sub"
208
279
  }), le = () => ({
209
280
  tag: "sup"
210
- }), ce = (o) => ({
281
+ }), ie = (r) => ({
211
282
  tag: [
212
283
  {
213
284
  tag: "span",
214
- attrs: o.attrs
285
+ attrs: r.attrs
215
286
  }
216
287
  ]
217
- }), he = (o) => {
218
- var e;
219
- return (e = o.attrs) != null && e.color ? {
288
+ }), ce = (r) => {
289
+ var t;
290
+ return (t = r.attrs) != null && t.color ? {
220
291
  tag: [
221
292
  {
222
293
  tag: "span",
223
294
  attrs: {
224
- style: `background-color:${o.attrs.color};`
295
+ style: `background-color:${r.attrs.color};`
225
296
  }
226
297
  }
227
298
  ]
228
299
  } : {
229
300
  tag: ""
230
301
  };
231
- }, ue = (o) => {
232
- var e;
233
- return (e = o.attrs) != null && e.color ? {
302
+ }, ge = (r) => {
303
+ var t;
304
+ return (t = r.attrs) != null && t.color ? {
234
305
  tag: [
235
306
  {
236
307
  tag: "span",
237
308
  attrs: {
238
- style: `color:${o.attrs.color}`
309
+ style: `color:${r.attrs.color}`
239
310
  }
240
311
  }
241
312
  ]
242
313
  } : {
243
314
  tag: ""
244
315
  };
245
- }, pe = {
316
+ }, ue = {
246
317
  nodes: {
247
- horizontal_rule: q,
248
- blockquote: B,
249
- bullet_list: D,
250
- code_block: V,
251
- hard_break: J,
252
- heading: K,
253
- image: G,
254
- list_item: W,
255
- ordered_list: Y,
256
- paragraph: Q,
257
- emoji: X
318
+ horizontal_rule: B,
319
+ blockquote: q,
320
+ bullet_list: F,
321
+ code_block: J,
322
+ hard_break: K,
323
+ heading: V,
324
+ image: H,
325
+ list_item: G,
326
+ ordered_list: W,
327
+ paragraph: Y,
328
+ emoji: Q
258
329
  },
259
330
  marks: {
260
- bold: Z,
261
- strike: ee,
262
- underline: te,
263
- strong: se,
331
+ bold: X,
332
+ strike: Z,
333
+ underline: ee,
334
+ strong: te,
264
335
  code: re,
265
336
  italic: oe,
266
- link: ie,
267
- styled: ne,
268
- subscript: ae,
337
+ link: se,
338
+ styled: ae,
339
+ subscript: ne,
269
340
  superscript: le,
270
- anchor: ce,
271
- highlight: he,
272
- textStyle: ue
341
+ anchor: ie,
342
+ highlight: ce,
343
+ textStyle: ge
273
344
  }
274
- }, de = function(o) {
275
- const e = {
345
+ }, pe = function(r) {
346
+ const t = {
276
347
  "&": "&amp;",
277
348
  "<": "&lt;",
278
349
  ">": "&gt;",
279
350
  '"': "&quot;",
280
351
  "'": "&#39;"
281
- }, t = /[&<>"']/g, s = RegExp(t.source);
282
- return o && s.test(o) ? o.replace(t, (r) => e[r]) : o;
352
+ }, e = /[&<>"']/g, o = RegExp(e.source);
353
+ return r && o.test(r) ? r.replace(e, (s) => t[s]) : r;
283
354
  };
284
- class k {
285
- constructor(e) {
286
- u(this, "marks"), u(this, "nodes"), e || (e = pe), this.marks = e.marks || [], this.nodes = e.nodes || [];
355
+ class fe {
356
+ constructor(t) {
357
+ p(this, "marks"), p(this, "nodes"), t || (t = ue), this.marks = t.marks || [], this.nodes = t.nodes || [];
287
358
  }
288
- addNode(e, t) {
289
- this.nodes[e] = t;
359
+ addNode(t, e) {
360
+ this.nodes[t] = e;
290
361
  }
291
- addMark(e, t) {
292
- this.marks[e] = t;
362
+ addMark(t, e) {
363
+ this.marks[t] = e;
293
364
  }
294
- render(e, t = { optimizeImages: !1 }) {
295
- if (e && e.content && Array.isArray(e.content)) {
296
- let s = "";
297
- return e.content.forEach((r) => {
298
- s += this.renderNode(r);
299
- }), t.optimizeImages ? this.optimizeImages(s, t.optimizeImages) : s;
365
+ render(t, e = { optimizeImages: !1 }) {
366
+ if (t && t.content && Array.isArray(t.content)) {
367
+ let o = "";
368
+ return t.content.forEach((s) => {
369
+ o += this.renderNode(s);
370
+ }), e.optimizeImages ? this.optimizeImages(o, e.optimizeImages) : o;
300
371
  }
301
372
  return console.warn(
302
373
  `The render method must receive an Object with a "content" field.
@@ -325,735 +396,201 @@ class k {
325
396
  }`
326
397
  ), "";
327
398
  }
328
- optimizeImages(e, t) {
329
- let s = 0, r = 0, i = "", n = "";
330
- typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (i += `width="${t.width}" `, s = t.width), typeof t.height == "number" && t.height > 0 && (i += `height="${t.height}" `, r = t.height), (t.loading === "lazy" || t.loading === "eager") && (i += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (i += `class="${t.class}" `), t.filters && (typeof t.filters.blur == "number" && t.filters.blur >= 0 && t.filters.blur <= 100 && (n += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (n += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-Fa-f]{6}/g) || t.filters.fill === "transparent") && (n += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (n += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (n += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (n += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (n += `:rotate(${t.filters.rotate})`), n.length > 0 && (n = "/filters" + n))), i.length > 0 && (e = e.replace(/<img/g, `<img ${i.trim()}`));
331
- const c = s > 0 || r > 0 || n.length > 0 ? `${s}x${r}${n}` : "";
332
- return e = e.replace(
399
+ optimizeImages(t, e) {
400
+ let o = 0, s = 0, a = "", n = "";
401
+ typeof e != "boolean" && (typeof e.width == "number" && e.width > 0 && (a += `width="${e.width}" `, o = e.width), typeof e.height == "number" && e.height > 0 && (a += `height="${e.height}" `, s = e.height), (e.loading === "lazy" || e.loading === "eager") && (a += `loading="${e.loading}" `), typeof e.class == "string" && e.class.length > 0 && (a += `class="${e.class}" `), e.filters && (typeof e.filters.blur == "number" && e.filters.blur >= 0 && e.filters.blur <= 100 && (n += `:blur(${e.filters.blur})`), typeof e.filters.brightness == "number" && e.filters.brightness >= -100 && e.filters.brightness <= 100 && (n += `:brightness(${e.filters.brightness})`), e.filters.fill && (e.filters.fill.match(/[0-9A-Fa-f]{6}/g) || e.filters.fill === "transparent") && (n += `:fill(${e.filters.fill})`), e.filters.format && ["webp", "png", "jpeg"].includes(e.filters.format) && (n += `:format(${e.filters.format})`), typeof e.filters.grayscale == "boolean" && e.filters.grayscale && (n += ":grayscale()"), typeof e.filters.quality == "number" && e.filters.quality >= 0 && e.filters.quality <= 100 && (n += `:quality(${e.filters.quality})`), e.filters.rotate && [90, 180, 270].includes(e.filters.rotate) && (n += `:rotate(${e.filters.rotate})`), n.length > 0 && (n = "/filters" + n))), a.length > 0 && (t = t.replace(/<img/g, `<img ${a.trim()}`));
402
+ const c = o > 0 || s > 0 || n.length > 0 ? `${o}x${s}${n}` : "";
403
+ return t = t.replace(
333
404
  /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,
334
405
  `a.storyblok.com/f/$1/$2.$3/m/${c}`
335
- ), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (a) => {
336
- var l, h;
337
- const p = a.match(
406
+ ), typeof e != "boolean" && (e.sizes || e.srcset) && (t = t.replace(/<img.*?src=["|'](.*?)["|']/g, (l) => {
407
+ var i, g;
408
+ const f = l.match(
338
409
  /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g
339
410
  );
340
- if (p && p.length > 0) {
411
+ if (f && f.length > 0) {
341
412
  const d = {
342
- srcset: (l = t.srcset) == null ? void 0 : l.map((g) => {
343
- if (typeof g == "number")
344
- return `//${p}/m/${g}x0${n} ${g}w`;
345
- if (typeof g == "object" && g.length === 2) {
346
- let v = 0, I = 0;
347
- return typeof g[0] == "number" && (v = g[0]), typeof g[1] == "number" && (I = g[1]), `//${p}/m/${v}x${I}${n} ${v}w`;
413
+ srcset: (i = e.srcset) == null ? void 0 : i.map((u) => {
414
+ if (typeof u == "number")
415
+ return `//${f}/m/${u}x0${n} ${u}w`;
416
+ if (typeof u == "object" && u.length === 2) {
417
+ let b = 0, y = 0;
418
+ return typeof u[0] == "number" && (b = u[0]), typeof u[1] == "number" && (y = u[1]), `//${f}/m/${b}x${y}${n} ${b}w`;
348
419
  }
349
420
  }).join(", "),
350
- sizes: (h = t.sizes) == null ? void 0 : h.map((g) => g).join(", ")
421
+ sizes: (g = e.sizes) == null ? void 0 : g.map((u) => u).join(", ")
351
422
  };
352
- let f = "";
353
- return d.srcset && (f += `srcset="${d.srcset}" `), d.sizes && (f += `sizes="${d.sizes}" `), a.replace(/<img/g, `<img ${f.trim()}`);
423
+ let h = "";
424
+ return d.srcset && (h += `srcset="${d.srcset}" `), d.sizes && (h += `sizes="${d.sizes}" `), l.replace(/<img/g, `<img ${h.trim()}`);
354
425
  }
355
- return a;
356
- })), e;
357
- }
358
- renderNode(e) {
359
- const t = [];
360
- e.marks && e.marks.forEach((r) => {
361
- const i = this.getMatchingMark(r);
362
- i && i.tag !== "" && t.push(this.renderOpeningTag(i.tag));
426
+ return l;
427
+ })), t;
428
+ }
429
+ renderNode(t) {
430
+ const e = [];
431
+ t.marks && t.marks.forEach((s) => {
432
+ const a = this.getMatchingMark(s);
433
+ a && a.tag !== "" && e.push(this.renderOpeningTag(a.tag));
363
434
  });
364
- const s = this.getMatchingNode(e);
365
- return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
366
- t.push(this.renderNode(r));
367
- }) : e.text ? t.push(de(e.text)) : s && s.singleTag ? t.push(this.renderTag(s.singleTag, " /")) : s && s.html ? t.push(s.html) : e.type === "emoji" && t.push(this.renderEmoji(e)), s && s.tag && t.push(this.renderClosingTag(s.tag)), e.marks && e.marks.slice(0).reverse().forEach((r) => {
368
- const i = this.getMatchingMark(r);
369
- i && i.tag !== "" && t.push(this.renderClosingTag(i.tag));
370
- }), t.join("");
371
- }
372
- renderTag(e, t) {
373
- return e.constructor === String ? `<${e}${t}>` : e.map((s) => {
374
- if (s.constructor === String)
375
- return `<${s}${t}>`;
435
+ const o = this.getMatchingNode(t);
436
+ return o && o.tag && e.push(this.renderOpeningTag(o.tag)), t.content ? t.content.forEach((s) => {
437
+ e.push(this.renderNode(s));
438
+ }) : t.text ? e.push(pe(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) => {
439
+ const a = this.getMatchingMark(s);
440
+ a && a.tag !== "" && e.push(this.renderClosingTag(a.tag));
441
+ }), e.join("");
442
+ }
443
+ renderTag(t, e) {
444
+ return t.constructor === String ? `<${t}${e}>` : t.map((o) => {
445
+ if (o.constructor === String)
446
+ return `<${o}${e}>`;
376
447
  {
377
- let r = `<${s.tag}`;
378
- if (s.attrs)
379
- for (const i in s.attrs) {
380
- const n = s.attrs[i];
381
- n !== null && (r += ` ${i}="${n}"`);
448
+ let s = `<${o.tag}`;
449
+ if (o.attrs)
450
+ for (const a in o.attrs) {
451
+ const n = o.attrs[a];
452
+ n !== null && (s += ` ${a}="${n}"`);
382
453
  }
383
- return `${r}${t}>`;
454
+ return `${s}${e}>`;
384
455
  }
385
456
  }).join("");
386
457
  }
387
- renderOpeningTag(e) {
388
- return this.renderTag(e, "");
458
+ renderOpeningTag(t) {
459
+ return this.renderTag(t, "");
389
460
  }
390
- renderClosingTag(e) {
391
- return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((t) => t.constructor === String ? `</${t}>` : `</${t.tag}>`).join("");
461
+ renderClosingTag(t) {
462
+ return t.constructor === String ? `</${t}>` : t.slice(0).reverse().map((e) => e.constructor === String ? `</${e}>` : `</${e.tag}>`).join("");
392
463
  }
393
- getMatchingNode(e) {
394
- const t = this.nodes[e.type];
395
- if (typeof t == "function")
396
- return t(e);
464
+ getMatchingNode(t) {
465
+ const e = this.nodes[t.type];
466
+ if (typeof e == "function")
467
+ return e(t);
397
468
  }
398
- getMatchingMark(e) {
399
- const t = this.marks[e.type];
400
- if (typeof t == "function")
401
- return t(e);
469
+ getMatchingMark(t) {
470
+ const e = this.marks[t.type];
471
+ if (typeof e == "function")
472
+ return e(t);
402
473
  }
403
- renderEmoji(e) {
404
- if (e.attrs.emoji)
405
- return e.attrs.emoji;
406
- const t = [
474
+ renderEmoji(t) {
475
+ if (t.attrs.emoji)
476
+ return t.attrs.emoji;
477
+ const e = [
407
478
  {
408
479
  tag: "img",
409
480
  attrs: {
410
- src: e.attrs.fallbackImage,
481
+ src: t.attrs.fallbackImage,
411
482
  draggable: "false",
412
483
  loading: "lazy",
413
484
  align: "absmiddle"
414
485
  }
415
486
  }
416
487
  ];
417
- return this.renderTag(t, " /");
418
- }
419
- }
420
- class ge {
421
- constructor(e) {
422
- u(this, "baseURL"), u(this, "timeout"), u(this, "headers"), u(this, "responseInterceptor"), u(this, "fetch"), u(this, "ejectInterceptor"), u(this, "url"), u(this, "parameters"), u(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 = {};
423
- }
424
- /**
425
- *
426
- * @param url string
427
- * @param params ISbStoriesParams
428
- * @returns Promise<ISbResponse | Error>
429
- */
430
- get(e, t) {
431
- return this.url = e, this.parameters = t, this._methodHandler("get");
432
- }
433
- post(e, t) {
434
- return this.url = e, this.parameters = t, this._methodHandler("post");
435
- }
436
- put(e, t) {
437
- return this.url = e, this.parameters = t, this._methodHandler("put");
438
- }
439
- delete(e, t) {
440
- return this.url = e, this.parameters = t, this._methodHandler("delete");
441
- }
442
- async _responseHandler(e) {
443
- const t = [], s = {
444
- data: {},
445
- headers: {},
446
- status: 0,
447
- statusText: ""
448
- };
449
- e.status !== 204 && await e.json().then((r) => {
450
- s.data = r;
451
- });
452
- for (const r of e.headers.entries())
453
- t[r[0]] = r[1];
454
- return s.headers = { ...t }, s.status = e.status, s.statusText = e.statusText, s;
455
- }
456
- async _methodHandler(e) {
457
- let t = `${this.baseURL}${this.url}`, s = null;
458
- if (e === "get") {
459
- const a = new b();
460
- t = `${this.baseURL}${this.url}?${a.stringify(
461
- this.parameters
462
- )}`;
463
- } else
464
- s = JSON.stringify(this.parameters);
465
- const r = new URL(t), i = new AbortController(), { signal: n } = i;
466
- let c;
467
- this.timeout && (c = setTimeout(() => i.abort(), this.timeout));
468
- try {
469
- const a = await this.fetch(`${r}`, {
470
- method: e,
471
- headers: this.headers,
472
- body: s,
473
- signal: n,
474
- ...this.fetchOptions
475
- });
476
- this.timeout && clearTimeout(c);
477
- const l = await this._responseHandler(
478
- a
479
- );
480
- return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(l)) : this._statusHandler(l);
481
- } catch (a) {
482
- return {
483
- message: a
484
- };
485
- }
486
- }
487
- setFetchOptions(e = {}) {
488
- Object.keys(e).length > 0 && "method" in e && delete e.method, this.fetchOptions = { ...e };
489
- }
490
- eject() {
491
- this.ejectInterceptor = !0;
492
- }
493
- _statusHandler(e) {
494
- const t = /20[0-6]/g;
495
- return new Promise((s, r) => {
496
- if (t.test(`${e.status}`))
497
- return s(e);
498
- const i = {
499
- message: e.statusText,
500
- status: e.status,
501
- response: Array.isArray(e.data) ? e.data[0] : e.data.error || e.data.slug
502
- };
503
- r(i);
504
- });
505
- }
506
- }
507
- const S = "SB-Agent", w = {
508
- defaultAgentName: "SB-JS-CLIENT",
509
- defaultAgentVersion: "SB-Agent-Version",
510
- packageVersion: "6.0.0"
511
- };
512
- let y = {};
513
- const m = {};
514
- class fe {
515
- /**
516
- *
517
- * @param config ISbConfig interface
518
- * @param endpoint string, optional
519
- */
520
- constructor(e, t) {
521
- u(this, "client"), u(this, "maxRetries"), u(this, "throttle"), u(this, "accessToken"), u(this, "cache"), u(this, "helpers"), u(this, "resolveCounter"), u(this, "relations"), u(this, "links"), u(this, "richTextResolver"), u(this, "resolveNestedRelations"), u(this, "stringifiedStoriesCache");
522
- let s = e.endpoint || t;
523
- if (!s) {
524
- const n = new b().getRegionURL, c = e.https === !1 ? "http" : "https";
525
- e.oauthToken ? s = `${c}://${n(e.region)}/v1` : s = `${c}://${n(e.region)}/v2`;
526
- }
527
- const r = new Headers();
528
- if (r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), e.headers)
529
- for (const n in e.headers)
530
- r.set(n, e.headers[n]);
531
- r.has(S) || (r.set(S, w.defaultAgentName), r.set(
532
- w.defaultAgentVersion,
533
- w.packageVersion
534
- ));
535
- let i = 5;
536
- e.oauthToken && (r.set("Authorization", e.oauthToken), i = 3), e.rateLimit && (i = e.rateLimit), e.richTextSchema ? this.richTextResolver = new k(e.richTextSchema) : this.richTextResolver = new k(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 5, this.throttle = z(this.throttledRequest, i, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new b(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new ge({
537
- baseURL: s,
538
- timeout: e.timeout || 0,
539
- headers: r,
540
- responseInterceptor: e.responseInterceptor,
541
- fetch: e.fetch
542
- });
543
- }
544
- setComponentResolver(e) {
545
- this.richTextResolver.addNode("blok", (t) => {
546
- let s = "";
547
- return t.attrs.body && t.attrs.body.forEach((r) => {
548
- s += e(r.component, r);
549
- }), {
550
- html: s
551
- };
552
- });
553
- }
554
- parseParams(e) {
555
- return e.token || (e.token = this.getToken()), e.cv || (e.cv = m[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
556
- }
557
- factoryParamOptions(e, t) {
558
- return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
559
- }
560
- makeRequest(e, t, s, r) {
561
- const i = this.factoryParamOptions(
562
- e,
563
- this.helpers.getOptionsPage(t, s, r)
564
- );
565
- return this.cacheResponse(e, i);
566
- }
567
- get(e, t, s) {
568
- t || (t = {});
569
- const r = `/${e}`, i = this.factoryParamOptions(r, t);
570
- return this.client.setFetchOptions(s), this.cacheResponse(r, i);
571
- }
572
- async getAll(e, t, s, r) {
573
- const i = (t == null ? void 0 : t.per_page) || 25, n = `/${e}`, c = n.split("/"), a = s || c[c.length - 1], l = 1, h = await this.makeRequest(n, t, i, l), p = h.total ? Math.ceil(h.total / i) : 1;
574
- this.client.setFetchOptions(r);
575
- const d = await this.helpers.asyncMap(
576
- this.helpers.range(l, p),
577
- (f) => this.makeRequest(n, t, i, f + 1)
578
- );
579
- return this.helpers.flatMap(
580
- [h, ...d],
581
- (f) => Object.values(f.data[a])
582
- );
583
- }
584
- post(e, t, s) {
585
- const r = `/${e}`;
586
- return this.client.setFetchOptions(s), Promise.resolve(this.throttle("post", r, t));
587
- }
588
- put(e, t, s) {
589
- const r = `/${e}`;
590
- return this.client.setFetchOptions(s), Promise.resolve(this.throttle("put", r, t));
591
- }
592
- delete(e, t, s) {
593
- const r = `/${e}`;
594
- return this.client.setFetchOptions(s), Promise.resolve(this.throttle("delete", r, t));
595
- }
596
- getStories(e, t) {
597
- return this.client.setFetchOptions(t), this._addResolveLevel(e), this.get("cdn/stories", e);
598
- }
599
- getStory(e, t, s) {
600
- return this.client.setFetchOptions(s), this._addResolveLevel(t), this.get(`cdn/stories/${e}`, t);
601
- }
602
- getToken() {
603
- return this.accessToken;
604
- }
605
- ejectInterceptor() {
606
- this.client.eject();
607
- }
608
- _addResolveLevel(e) {
609
- typeof e.resolve_relations < "u" && (e.resolve_level = 2);
610
- }
611
- _cleanCopy(e) {
612
- return JSON.parse(JSON.stringify(e));
613
- }
614
- _insertLinks(e, t, s) {
615
- const r = e[t];
616
- r && r.fieldtype == "multilink" && r.linktype == "story" && typeof r.id == "string" && this.links[s][r.id] ? r.story = this._cleanCopy(this.links[s][r.id]) : r && r.linktype === "story" && typeof r.uuid == "string" && this.links[s][r.uuid] && (r.story = this._cleanCopy(this.links[s][r.uuid]));
617
- }
618
- /**
619
- *
620
- * @param resolveId A counter number as a string
621
- * @param uuid The uuid of the story
622
- * @returns string | object
623
- */
624
- getStoryReference(e, t) {
625
- return this.relations[e][t] ? (this.stringifiedStoriesCache[t] || (this.stringifiedStoriesCache[t] = JSON.stringify(
626
- this.relations[e][t]
627
- )), JSON.parse(this.stringifiedStoriesCache[t])) : t;
628
- }
629
- _insertRelations(e, t, s, r) {
630
- s.indexOf(`${e.component}.${t}`) > -1 && (typeof e[t] == "string" ? e[t] = this.getStoryReference(r, e[t]) : Array.isArray(e[t]) && (e[t] = e[t].map((i) => this.getStoryReference(r, i)).filter(Boolean)));
631
- }
632
- iterateTree(e, t, s) {
633
- const r = (i) => {
634
- if (i != null) {
635
- if (i.constructor === Array)
636
- for (let n = 0; n < i.length; n++)
637
- r(i[n]);
638
- else if (i.constructor === Object) {
639
- if (i._stopResolving)
640
- return;
641
- for (const n in i)
642
- (i.component && i._uid || i.type === "link") && (this._insertRelations(
643
- i,
644
- n,
645
- t,
646
- s
647
- ), this._insertLinks(
648
- i,
649
- n,
650
- s
651
- )), r(i[n]);
652
- }
653
- }
654
- };
655
- r(e.content);
656
- }
657
- async resolveLinks(e, t, s) {
658
- let r = [];
659
- if (e.link_uuids) {
660
- const i = e.link_uuids.length, n = [], c = 50;
661
- for (let a = 0; a < i; a += c) {
662
- const l = Math.min(i, a + c);
663
- n.push(e.link_uuids.slice(a, l));
664
- }
665
- for (let a = 0; a < n.length; a++)
666
- (await this.getStories({
667
- per_page: c,
668
- language: t.language,
669
- version: t.version,
670
- by_uuids: n[a].join(",")
671
- })).data.stories.forEach(
672
- (l) => {
673
- r.push(l);
674
- }
675
- );
676
- } else
677
- r = e.links;
678
- r.forEach((i) => {
679
- this.links[s][i.uuid] = {
680
- ...i,
681
- _stopResolving: !0
682
- };
683
- });
684
- }
685
- async resolveRelations(e, t, s) {
686
- let r = [];
687
- if (e.rel_uuids) {
688
- const i = e.rel_uuids.length, n = [], c = 50;
689
- for (let a = 0; a < i; a += c) {
690
- const l = Math.min(i, a + c);
691
- n.push(e.rel_uuids.slice(a, l));
692
- }
693
- for (let a = 0; a < n.length; a++)
694
- (await this.getStories({
695
- per_page: c,
696
- language: t.language,
697
- version: t.version,
698
- by_uuids: n[a].join(","),
699
- excluding_fields: t.excluding_fields
700
- })).data.stories.forEach((l) => {
701
- r.push(l);
702
- });
703
- } else
704
- r = e.rels;
705
- r && r.length > 0 && r.forEach((i) => {
706
- this.relations[s][i.uuid] = {
707
- ...i,
708
- _stopResolving: !0
709
- };
710
- });
711
- }
712
- /**
713
- *
714
- * @param responseData
715
- * @param params
716
- * @param resolveId
717
- * @description Resolves the relations and links of the stories
718
- * @returns Promise<void>
719
- *
720
- */
721
- async resolveStories(e, t, s) {
722
- var r, i;
723
- let n = [];
724
- if (this.links[s] = {}, this.relations[s] = {}, 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, s)), t.resolve_links && ["1", "story", "url", "link"].indexOf(t.resolve_links) > -1 && ((r = e.links) != null && r.length || (i = e.link_uuids) != null && i.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
725
- for (const c in this.relations[s])
726
- this.iterateTree(
727
- this.relations[s][c],
728
- n,
729
- s
730
- );
731
- e.story ? this.iterateTree(e.story, n, s) : e.stories.forEach((c) => {
732
- this.iterateTree(c, n, s);
733
- }), this.stringifiedStoriesCache = {}, delete this.links[s], delete this.relations[s];
734
- }
735
- async cacheResponse(e, t, s) {
736
- (typeof s > "u" || !s) && (s = 0);
737
- const r = this.helpers.stringify({ url: e, params: t }), i = this.cacheProvider();
738
- if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
739
- const n = await i.get(r);
740
- if (n)
741
- return Promise.resolve(n);
742
- }
743
- return new Promise(async (n, c) => {
744
- var a;
745
- try {
746
- const l = await this.throttle("get", e, t);
747
- if (l.status !== 200)
748
- return c(l);
749
- let h = { data: l.data, headers: l.headers };
750
- if ((a = l.headers) != null && a["per-page"] && (h = Object.assign({}, h, {
751
- perPage: l.headers["per-page"] ? parseInt(l.headers["per-page"]) : 0,
752
- total: l.headers["per-page"] ? parseInt(l.headers.total) : 0
753
- })), h.data.story || h.data.stories) {
754
- const p = this.resolveCounter = ++this.resolveCounter % 1e3;
755
- await this.resolveStories(h.data, t, `${p}`);
756
- }
757
- return t.version === "published" && e != "/cdn/spaces/me" && await i.set(r, h), h.data.cv && t.token && (t.version === "draft" && m[t.token] != h.data.cv && await this.flushCache(), m[t.token] = t.cv ? t.cv : h.data.cv), n(h);
758
- } catch (l) {
759
- if (l.response && l.status === 429 && (s = s ? s + 1 : 0, s < this.maxRetries))
760
- return console.log(`Hit rate limit. Retrying in ${s} seconds.`), await this.helpers.delay(1e3 * s), this.cacheResponse(e, t, s).then(n).catch(c);
761
- c(l);
762
- }
763
- });
764
- }
765
- throttledRequest(e, t, s) {
766
- return this.client[e](t, s);
767
- }
768
- cacheVersions() {
769
- return m;
770
- }
771
- cacheVersion() {
772
- return m[this.accessToken];
773
- }
774
- setCacheVersion(e) {
775
- this.accessToken && (m[this.accessToken] = e);
776
- }
777
- cacheProvider() {
778
- switch (this.cache.type) {
779
- case "memory":
780
- return {
781
- get(e) {
782
- return Promise.resolve(y[e]);
783
- },
784
- getAll() {
785
- return Promise.resolve(y);
786
- },
787
- set(e, t) {
788
- return y[e] = t, Promise.resolve(void 0);
789
- },
790
- flush() {
791
- return y = {}, Promise.resolve(void 0);
792
- }
793
- };
794
- case "custom":
795
- if (this.cache.custom)
796
- return this.cache.custom;
797
- default:
798
- return {
799
- get() {
800
- return Promise.resolve();
801
- },
802
- getAll() {
803
- return Promise.resolve(void 0);
804
- },
805
- set() {
806
- return Promise.resolve(void 0);
807
- },
808
- flush() {
809
- return Promise.resolve(void 0);
810
- }
811
- };
812
- }
813
- }
814
- async flushCache() {
815
- return await this.cacheProvider().flush(), this;
488
+ return this.renderTag(e, " /");
816
489
  }
817
490
  }
818
- const me = (o = {}) => {
819
- const { apiOptions: e } = o;
820
- if (!e.accessToken) {
821
- console.error(
822
- "You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication"
823
- );
824
- return;
825
- }
826
- return { storyblokApi: new fe(e) };
827
- }, Se = (o) => {
828
- if (typeof o != "object" || typeof o._editable > "u")
491
+ const ke = (r) => {
492
+ if (typeof r != "object" || typeof r._editable > "u")
829
493
  return {};
830
494
  try {
831
- const e = JSON.parse(
832
- o._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
495
+ const t = JSON.parse(
496
+ r._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
833
497
  );
834
- return e ? {
835
- "data-blok-c": JSON.stringify(e),
836
- "data-blok-uid": e.id + "-" + e.uid
498
+ return t ? {
499
+ "data-blok-c": JSON.stringify(t),
500
+ "data-blok-uid": t.id + "-" + t.uid
837
501
  } : {};
838
502
  } catch {
839
503
  return {};
840
504
  }
841
505
  };
842
- let $, R = "https://app.storyblok.com/f/storyblok-v2-latest.js";
843
- const ye = (o = {}) => {
844
- var e, t;
845
- const {
846
- bridge: s,
847
- accessToken: r,
848
- use: i = [],
849
- apiOptions: n = {},
850
- richText: c = {},
851
- bridgeUrl: a
852
- } = o;
853
- n.accessToken = n.accessToken || r;
854
- const l = { bridge: s, apiOptions: n };
855
- let h = {};
856
- i.forEach((d) => {
857
- h = { ...h, ...d(l) };
858
- }), a && (R = a);
859
- const p = !(typeof window > "u") && ((t = (e = window.location) == null ? void 0 : e.search) == null ? void 0 : t.includes("_storyblok_tk"));
860
- return s !== !1 && p && P(R), $ = new k(c.schema), c.resolver && L($, c.resolver), h;
861
- }, L = (o, e) => {
862
- o.addNode("blok", (t) => {
863
- let s = "";
864
- return t.attrs.body.forEach((r) => {
865
- s += e(r.component, r);
506
+ let de, he = "https://app.storyblok.com/f/storyblok-v2-latest.js";
507
+ const be = (r, t) => {
508
+ r.addNode("blok", (e) => {
509
+ let o = "";
510
+ return e.attrs.body.forEach((s) => {
511
+ o += t(s.component, s);
866
512
  }), {
867
- html: s
513
+ html: o
868
514
  };
869
515
  });
870
- }, be = (o) => !o || !(o != null && o.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")), ke = (o, e, t) => {
871
- let s = t || $;
872
- if (!s) {
516
+ }, me = (r) => !r || !(r != null && r.content.some((t) => t.content || t.type === "blok" || t.type === "horizontal_rule")), ye = (r, t, e) => {
517
+ let o = e || de;
518
+ if (!o) {
873
519
  console.error(
874
520
  "Please initialize the Storyblok SDK before calling the renderRichText function"
875
521
  );
876
522
  return;
877
523
  }
878
- return be(o) ? "" : (e && (s = new k(e.schema), e.resolver && L(s, e.resolver)), s.render(o));
879
- }, xe = () => P(R);
880
- function ve(o, e, t) {
881
- const s = "virtual:storyblok-init", r = "\0" + s;
882
- return globalThis.apiPlugin = me, globalThis.storyblokInit = ye, {
883
- name: "vite-plugin-storyblok-init",
884
- async resolveId(i) {
885
- if (i === s)
886
- return r;
887
- },
888
- async load(i) {
889
- if (i === r)
890
- return `
891
- const { storyblokApi } = globalThis.storyblokInit({
892
- accessToken: "${o}",
893
- use: ${e ? "[]" : "[globalThis.apiPlugin]"},
894
- apiOptions: ${JSON.stringify(t)},
895
- });
896
- export const storyblokApiInstance = storyblokApi;
897
- `;
898
- }
899
- };
900
- }
901
- const we = /[\p{Lu}]/u, $e = /[\p{Ll}]/u, x = /^[\p{Lu}](?![\p{Lu}])/gu, N = /([\p{Alpha}\p{N}_]|$)/u, T = /[_.\- ]+/, Re = new RegExp("^" + T.source), O = new RegExp(T.source + N.source, "gu"), E = new RegExp("\\d+" + N.source, "gu"), Te = (o, e, t, s) => {
902
- let r = !1, i = !1, n = !1, c = !1;
903
- for (let a = 0; a < o.length; a++) {
904
- const l = o[a];
905
- c = a > 2 ? o[a - 3] === "-" : !0, r && we.test(l) ? (o = o.slice(0, a) + "-" + o.slice(a), r = !1, n = i, i = !0, a++) : i && n && $e.test(l) && (!c || s) ? (o = o.slice(0, a - 1) + "-" + o.slice(a - 1), n = i, i = !1, r = !0) : (r = e(l) === l && t(l) !== l, n = i, i = t(l) === l && e(l) !== l);
906
- }
907
- return o;
908
- }, Ie = (o, e) => (x.lastIndex = 0, o.replaceAll(x, (t) => e(t))), _e = (o, e) => (O.lastIndex = 0, E.lastIndex = 0, o.replaceAll(E, (t, s, r) => ["_", "-"].includes(o.charAt(r + t.length)) ? t : e(t)).replaceAll(O, (t, s) => e(s)));
909
- function j(o, e) {
910
- if (!(typeof o == "string" || Array.isArray(o)))
911
- throw new TypeError("Expected the input to be `string | string[]`");
912
- if (e = {
913
- pascalCase: !1,
914
- preserveConsecutiveUppercase: !1,
915
- ...e
916
- }, Array.isArray(o) ? o = o.map((i) => i.trim()).filter((i) => i.length).join("-") : o = o.trim(), o.length === 0)
917
- return "";
918
- const t = e.locale === !1 ? (i) => i.toLowerCase() : (i) => i.toLocaleLowerCase(e.locale), s = e.locale === !1 ? (i) => i.toUpperCase() : (i) => i.toLocaleUpperCase(e.locale);
919
- return o.length === 1 ? T.test(o) ? "" : e.pascalCase ? s(o) : t(o) : (o !== t(o) && (o = Te(o, t, s, e.preserveConsecutiveUppercase)), o = o.replace(Re, ""), o = e.preserveConsecutiveUppercase ? Ie(o, t) : t(o), e.pascalCase && (o = s(o.charAt(0)) + o.slice(1)), _e(o, s));
920
- }
921
- function Ce(o, e, t, s) {
922
- const r = "virtual:storyblok-components", i = "\0" + r;
923
- return {
924
- name: "vite-plugin-storyblok-components",
925
- async resolveId(n) {
926
- if (n === r)
927
- return i;
928
- },
929
- async load(n) {
930
- if (n === i) {
931
- const c = [], a = [];
932
- for await (const [h, p] of Object.entries(e)) {
933
- const d = await this.resolve(
934
- "/" + o + "/" + p + ".astro"
935
- );
936
- if (d)
937
- c.push(`import ${j(h)} from "${d.id}"`);
938
- else if (t)
939
- a.push(h);
940
- else
941
- throw new Error(
942
- `Component could not be found for blok "${h}"! Does "${"/" + o + "/" + p}.astro" exist?`
943
- );
944
- }
945
- let l = "";
946
- if (t)
947
- if (l = ",FallbackComponent", s) {
948
- const h = await this.resolve(
949
- "/" + o + "/" + s + ".astro"
950
- );
951
- if (!h)
952
- throw new Error(
953
- `Custom fallback component could not be found. Does "${"/" + o + "/" + s}.astro" exist?`
954
- );
955
- c.push(
956
- `import FallbackComponent from "${h.id}"`
957
- );
958
- } else
959
- c.push(
960
- "import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'"
961
- );
962
- if (Object.values(e).length)
963
- return `${c.join(";")};export default {${Object.keys(e).filter((h) => !a.includes(h)).map((h) => j(h)).join(",")}${l}}`;
964
- if (t)
965
- return `${c[0]}; export default {${l.replace(",", "")}}`;
966
- throw new Error(
967
- `Currently, no Storyblok components are registered in astro.config.mjs.
968
- Please register your components or enable the fallback component.
969
- Detailed information can be found here: https://github.com/storyblok/storyblok-astro`
970
- );
971
- }
972
- }
973
- };
974
- }
975
- function Ae(o) {
976
- const e = "virtual:storyblok-options", t = "\0" + e;
977
- return {
978
- name: "vite-plugin-storyblok-options",
979
- async resolveId(s) {
980
- if (s === e)
981
- return t;
982
- },
983
- async load(s) {
984
- if (s === t)
985
- return `export default ${JSON.stringify(o)}`;
986
- }
987
- };
988
- }
989
- function Oe() {
524
+ return me(r) ? "" : (t && (o = new fe(t.schema), t.resolver && be(o, t.resolver)), o.render(r));
525
+ }, $e = () => M(he);
526
+ function ve() {
990
527
  return globalThis.storyblokApiInstance || console.error("storyblokApiInstance has not been initialized correctly"), globalThis.storyblokApiInstance;
991
528
  }
992
- function Ee(o, e) {
993
- const t = globalThis.storyblokApiInstance.richTextResolver;
994
- if (!t) {
529
+ function Ie(r, t) {
530
+ const e = globalThis.storyblokApiInstance.richTextResolver;
531
+ if (!e) {
995
532
  console.error(
996
533
  "Please initialize the Storyblok SDK before calling the renderRichText function"
997
534
  );
998
535
  return;
999
536
  }
1000
- return ke(o, e, t);
537
+ return ye(r, t, e);
1001
538
  }
1002
- function je(o) {
1003
- const e = {
539
+ function we(r) {
540
+ const t = {
1004
541
  useCustomApi: !1,
1005
542
  bridge: !0,
1006
543
  componentsDir: "src",
1007
544
  enableFallbackComponent: !1,
1008
- ...o
545
+ ...r
1009
546
  };
1010
547
  return {
1011
548
  name: "@storyblok/astro",
1012
549
  hooks: {
1013
550
  "astro:config:setup": ({
1014
- injectScript: t,
1015
- updateConfig: s,
1016
- addDevToolbarApp: r
551
+ injectScript: e,
552
+ updateConfig: o,
553
+ addDevToolbarApp: s
1017
554
  }) => {
1018
- if (s({
555
+ if (o({
1019
556
  vite: {
1020
557
  plugins: [
1021
- ve(
1022
- e.accessToken,
1023
- e.useCustomApi,
1024
- e.apiOptions
558
+ E(
559
+ t.accessToken,
560
+ t.useCustomApi,
561
+ t.apiOptions
1025
562
  ),
1026
- Ce(
1027
- e.componentsDir,
1028
- e.components,
1029
- e.enableFallbackComponent,
1030
- e.customFallbackComponent
563
+ N(
564
+ t.componentsDir,
565
+ t.components,
566
+ t.enableFallbackComponent,
567
+ t.customFallbackComponent
1031
568
  ),
1032
- Ae(e)
569
+ L(t)
1033
570
  ]
1034
571
  }
1035
- }), t(
572
+ }), e(
1036
573
  "page-ssr",
1037
574
  `
1038
575
  import { storyblokApiInstance } from "virtual:storyblok-init";
1039
576
  globalThis.storyblokApiInstance = storyblokApiInstance;
1040
577
  `
1041
- ), e.bridge) {
1042
- let i = "";
1043
- if (typeof e.bridge == "object") {
1044
- const n = { ...e.bridge };
1045
- i = `const storyblokInstance = new StoryblokBridge(${JSON.stringify(
578
+ ), t.bridge) {
579
+ let a = "";
580
+ if (typeof t.bridge == "object") {
581
+ const n = { ...t.bridge };
582
+ a = `const storyblokInstance = new StoryblokBridge(${JSON.stringify(
1046
583
  n
1047
584
  )});`;
1048
585
  } else
1049
- i = "const storyblokInstance = new StoryblokBridge()";
1050
- t(
586
+ a = "const storyblokInstance = new StoryblokBridge()";
587
+ e(
1051
588
  "page",
1052
589
  `
1053
590
  import { loadStoryblokBridge } from "@storyblok/astro";
1054
591
  loadStoryblokBridge().then(() => {
1055
592
  const { StoryblokBridge, location } = window;
1056
- ${i}
593
+ ${a}
1057
594
 
1058
595
  storyblokInstance.on(["published", "change"], (event) => {
1059
596
  if (!event.slugChanged) {
@@ -1064,17 +601,17 @@ function je(o) {
1064
601
  `
1065
602
  );
1066
603
  }
1067
- r("@storyblok/astro/toolbar-app-storyblok.ts");
604
+ s("@storyblok/astro/toolbarApp.ts");
1068
605
  }
1069
606
  }
1070
607
  };
1071
608
  }
1072
609
  export {
1073
- k as RichTextResolver,
1074
- pe as RichTextSchema,
1075
- je as default,
1076
- xe as loadStoryblokBridge,
1077
- Ee as renderRichText,
1078
- Se as storyblokEditable,
1079
- Oe as useStoryblokApi
610
+ fe as RichTextResolver,
611
+ ue as RichTextSchema,
612
+ we as default,
613
+ $e as loadStoryblokBridge,
614
+ Ie as renderRichText,
615
+ ke as storyblokEditable,
616
+ ve as useStoryblokApi
1080
617
  };