@storyblok/astro 4.0.4-next.2 → 4.0.4-next.4

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