@storyblok/astro 6.0.2 → 6.1.0-alpha.1

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