@storyblok/astro 6.0.1 → 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,15 +7,15 @@ 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, y = /[_.\- ]+/, R = new RegExp("^" + y.source), w = new RegExp(y.source + x.source, "gu"), $ = new RegExp("\\d+" + x.source, "gu"), j = (r, e, t, 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 = e(c) === c && t(c) !== c, a = n, n = t(c) === c && e(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, e) => (k.lastIndex = 0, r.replaceAll(k, (t) => e(t))), P = (r, e) => (w.lastIndex = 0, $.lastIndex = 0, r.replaceAll($, (t, o, s) => ["_", "-"].includes(r.charAt(s + t.length)) ? t : e(t)).replaceAll(w, (t, o) => e(o)));
18
- function O(r, e) {
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
21
  if (e = {
@@ -24,57 +24,57 @@ function O(r, e) {
24
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 t = e.locale === !1 ? (n) => n.toLowerCase() : (n) => n.toLocaleLowerCase(e.locale), o = e.locale === !1 ? (n) => n.toUpperCase() : (n) => n.toLocaleUpperCase(e.locale);
28
- return r.length === 1 ? y.test(r) ? "" : e.pascalCase ? o(r) : t(r) : (r !== t(r) && (r = j(r, t, o, e.preserveConsecutiveUppercase)), r = r.replace(R, ""), r = e.preserveConsecutiveUppercase ? M(r, t) : t(r), e.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, e = {}, t, 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(e)) {
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}"`);
48
+ if (g)
49
+ a.push(`import ${I(h)} from "${g.id}"`);
50
50
  else if (t)
51
- i.push(u);
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
58
  if (t)
59
- if (c = ",FallbackComponent", o) {
60
- const u = await this.resolve(
61
- `/${r}/${o}.astro`
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
74
  if (Object.values(e).length)
75
- return `${l.join(";")};export default {${Object.keys(e).filter((u) => !i.includes(u)).map((u) => v(u)).join(",")}${c}}`;
75
+ return `${a.join(";")};export default {${Object.keys(e).filter((h) => !l.includes(h)).map((h) => I(h)).join(",")}${c}}`;
76
76
  if (t)
77
- return `${l[0]}; export default {${c.replace(",", "")}}`;
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,16 +84,16 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
84
84
  }
85
85
  };
86
86
  }
87
- function N(r, e, t) {
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({
@@ -106,53 +106,97 @@ function N(r, e, t) {
106
106
  }
107
107
  };
108
108
  }
109
- function z(r) {
109
+ function G(r) {
110
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 === e)
113
+ async resolveId(s) {
114
+ if (s === e)
115
115
  return t;
116
116
  },
117
- async load(o) {
118
- if (o === t)
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((e, t) => {
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);
131
- }, document.getElementById("storyblok-javascript-bridge"))) return;
132
- const o = document.createElement("script");
133
- o.async = !0, o.src = r, o.id = "storyblok-javascript-bridge", o.onerror = (s) => t(s), o.onload = (s) => {
134
- I.forEach((n) => n()), C = !0, e(s);
135
- }, document.getElementsByTagName("head")[0].appendChild(o);
130
+ L ? o() : E.push(o);
131
+ }, document.getElementById("storyblok-javascript-bridge")))
132
+ return;
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);
136
137
  });
137
- var F = Object.defineProperty, D = (r, e, t) => e in r ? F(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, g = (r, e, t) => D(r, typeof e != "symbol" ? e + "" : e, t);
138
- 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 {
139
183
  constructor() {
140
- g(this, "isCDNUrl", (r = "") => r.includes("/cdn/")), g(this, "getOptionsPage", (r, e = 25, t = 1) => ({
184
+ d(this, "isCDNUrl", (r = "") => r.includes("/cdn/")), d(this, "getOptionsPage", (r, e = 25, t = 1) => ({
141
185
  ...r,
142
186
  per_page: e,
143
187
  page: t
144
- })), g(this, "delay", (r) => new Promise((e) => setTimeout(e, r))), g(this, "arrayFrom", (r = 0, e) => Array.from({ length: r }, e)), g(this, "range", (r = 0, e = r) => {
145
- const t = Math.abs(e - r) || 0, o = r < e ? 1 : -1;
146
- return this.arrayFrom(t, (s, n) => n * o + r);
147
- }), g(this, "asyncMap", async (r, e) => Promise.all(r.map(e))), g(this, "flatMap", (r = [], e) => r.map(e).reduce((t, o) => [...t, ...o], [])), g(this, "escapeHTML", function(r) {
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) {
148
192
  const e = {
149
193
  "&": "&amp;",
150
194
  "<": "&lt;",
151
195
  ">": "&gt;",
152
196
  '"': "&quot;",
153
197
  "'": "&#39;"
154
- }, t = /[&<>"']/g, o = new RegExp(t.source);
155
- return r && o.test(r) ? r.replace(t, (s) => e[s]) : r;
198
+ }, t = /[&<>"']/g, s = new RegExp(t.source);
199
+ return r && s.test(r) ? r.replace(t, (o) => e[o]) : r;
156
200
  });
157
201
  }
158
202
  /**
@@ -163,19 +207,19 @@ let U = class {
163
207
  * @return {string} Stringified object
164
208
  */
165
209
  stringify(r, e, t) {
166
- const o = [];
167
- for (const s in r) {
168
- if (!Object.prototype.hasOwnProperty.call(r, s))
210
+ const s = [];
211
+ for (const o in r) {
212
+ if (!Object.prototype.hasOwnProperty.call(r, o))
169
213
  continue;
170
- const n = r[s], a = t ? "" : encodeURIComponent(s);
171
- let l;
172
- 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(
173
217
  n,
174
- e ? e + encodeURIComponent(`[${a}]`) : a,
218
+ e ? e + encodeURIComponent(`[${i}]`) : i,
175
219
  Array.isArray(n)
176
- ) : l = `${e ? e + encodeURIComponent(`[${a}]`) : a}=${encodeURIComponent(n)}`, o.push(l);
220
+ ) : a = `${e ? e + encodeURIComponent(`[${i}]`) : i}=${encodeURIComponent(n)}`, s.push(a);
177
221
  }
178
- return o.join("&");
222
+ return s.join("&");
179
223
  }
180
224
  /**
181
225
  * @method getRegionURL
@@ -183,14 +227,14 @@ let U = class {
183
227
  * @return {string} The base URL of the region
184
228
  */
185
229
  getRegionURL(r) {
186
- const e = "api.storyblok.com", t = "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";
187
231
  switch (r) {
188
232
  case "us":
189
233
  return t;
190
234
  case "cn":
191
- return o;
192
- case "ap":
193
235
  return s;
236
+ case "ap":
237
+ return o;
194
238
  case "ca":
195
239
  return n;
196
240
  default:
@@ -198,20 +242,20 @@ let U = class {
198
242
  }
199
243
  }
200
244
  };
201
- const q = function(r, e) {
245
+ const te = function(r, e) {
202
246
  const t = {};
203
- for (const o in r) {
204
- const s = r[o];
205
- e.includes(o) && s !== null && (t[o] = s);
247
+ for (const s in r) {
248
+ const o = r[s];
249
+ e.includes(s) && o !== null && (t[s] = o);
206
250
  }
207
251
  return t;
208
- }, H = (r) => r === "email", W = () => ({
252
+ }, se = (r) => r === "email", re = () => ({
209
253
  singleTag: "hr"
210
- }), J = () => ({
254
+ }), oe = () => ({
211
255
  tag: "blockquote"
212
- }), V = () => ({
256
+ }), ne = () => ({
213
257
  tag: "ul"
214
- }), K = (r) => ({
258
+ }), ie = (r) => ({
215
259
  tag: [
216
260
  "pre",
217
261
  {
@@ -219,24 +263,24 @@ const q = function(r, e) {
219
263
  attrs: r.attrs
220
264
  }
221
265
  ]
222
- }), Z = () => ({
266
+ }), ae = () => ({
223
267
  singleTag: "br"
224
- }), G = (r) => ({
268
+ }), le = (r) => ({
225
269
  tag: `h${r.attrs.level}`
226
- }), X = (r) => ({
270
+ }), ce = (r) => ({
227
271
  singleTag: [
228
272
  {
229
273
  tag: "img",
230
- attrs: q(r.attrs, ["src", "alt", "title"])
274
+ attrs: te(r.attrs, ["src", "alt", "title"])
231
275
  }
232
276
  ]
233
- }), Y = () => ({
277
+ }), he = () => ({
234
278
  tag: "li"
235
- }), Q = () => ({
279
+ }), ue = () => ({
236
280
  tag: "ol"
237
- }), ee = () => ({
281
+ }), de = () => ({
238
282
  tag: "p"
239
- }), te = (r) => ({
283
+ }), pe = (r) => ({
240
284
  tag: [
241
285
  {
242
286
  tag: "span",
@@ -247,27 +291,27 @@ const q = function(r, e) {
247
291
  }
248
292
  }
249
293
  ]
250
- }), re = () => ({
294
+ }), ge = () => ({
251
295
  tag: "b"
252
- }), oe = () => ({
296
+ }), fe = () => ({
253
297
  tag: "s"
254
- }), se = () => ({
298
+ }), ye = () => ({
255
299
  tag: "u"
256
- }), ne = () => ({
300
+ }), me = () => ({
257
301
  tag: "strong"
258
- }), ae = () => ({
302
+ }), be = () => ({
259
303
  tag: "code"
260
- }), le = () => ({
304
+ }), ke = () => ({
261
305
  tag: "i"
262
- }), ie = (r) => {
306
+ }), ve = (r) => {
263
307
  if (!r.attrs)
264
308
  return {
265
309
  tag: ""
266
310
  };
267
- const e = new U().escapeHTML, t = { ...r.attrs }, { linktype: o = "url" } = r.attrs;
268
- if (delete t.linktype, t.href && (t.href = e(r.attrs.href || "")), H(o) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
269
- for (const s in t.custom)
270
- t[s] = t.custom[s];
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];
271
315
  delete t.custom;
272
316
  }
273
317
  return {
@@ -278,25 +322,25 @@ const q = function(r, e) {
278
322
  }
279
323
  ]
280
324
  };
281
- }, ce = (r) => ({
325
+ }, we = (r) => ({
282
326
  tag: [
283
327
  {
284
328
  tag: "span",
285
329
  attrs: r.attrs
286
330
  }
287
331
  ]
288
- }), ue = () => ({
332
+ }), $e = () => ({
289
333
  tag: "sub"
290
- }), de = () => ({
334
+ }), Te = () => ({
291
335
  tag: "sup"
292
- }), ge = (r) => ({
336
+ }), Se = (r) => ({
293
337
  tag: [
294
338
  {
295
339
  tag: "span",
296
340
  attrs: r.attrs
297
341
  }
298
342
  ]
299
- }), pe = (r) => {
343
+ }), _e = (r) => {
300
344
  var e;
301
345
  return (e = r.attrs) != null && e.color ? {
302
346
  tag: [
@@ -310,7 +354,7 @@ const q = function(r, e) {
310
354
  } : {
311
355
  tag: ""
312
356
  };
313
- }, fe = (r) => {
357
+ }, Ce = (r) => {
314
358
  var e;
315
359
  return (e = r.attrs) != null && e.color ? {
316
360
  tag: [
@@ -324,49 +368,49 @@ const q = function(r, e) {
324
368
  } : {
325
369
  tag: ""
326
370
  };
327
- }, he = {
371
+ }, Re = {
328
372
  nodes: {
329
- horizontal_rule: W,
330
- blockquote: J,
331
- bullet_list: V,
332
- code_block: K,
333
- hard_break: Z,
334
- heading: G,
335
- image: X,
336
- list_item: Y,
337
- ordered_list: Q,
338
- paragraph: ee,
339
- 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
340
384
  },
341
385
  marks: {
342
- bold: re,
343
- strike: oe,
344
- underline: se,
345
- strong: ne,
346
- code: ae,
347
- italic: le,
348
- link: ie,
349
- styled: ce,
350
- subscript: ue,
351
- superscript: de,
352
- anchor: ge,
353
- highlight: pe,
354
- textStyle: fe
355
- }
356
- }, be = function(r) {
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) {
357
401
  const e = {
358
402
  "&": "&amp;",
359
403
  "<": "&lt;",
360
404
  ">": "&gt;",
361
405
  '"': "&quot;",
362
406
  "'": "&#39;"
363
- }, t = /[&<>"']/g, o = new RegExp(t.source);
364
- return r && o.test(r) ? r.replace(t, (s) => e[s]) : r;
407
+ }, t = /[&<>"']/g, s = new RegExp(t.source);
408
+ return r && s.test(r) ? r.replace(t, (o) => e[o]) : r;
365
409
  };
366
- let S = !1;
367
- class ye {
410
+ let x = !1;
411
+ class w {
368
412
  constructor(e) {
369
- g(this, "marks"), g(this, "nodes"), e || (e = he), this.marks = e.marks || [], this.nodes = e.nodes || [];
413
+ d(this, "marks"), d(this, "nodes"), e || (e = Re), this.marks = e.marks || [], this.nodes = e.nodes || [];
370
414
  }
371
415
  addNode(e, t) {
372
416
  this.nodes[e] = t;
@@ -374,14 +418,14 @@ class ye {
374
418
  addMark(e, t) {
375
419
  this.marks[e] = t;
376
420
  }
377
- render(e, t = { optimizeImages: !1 }, o = !0) {
378
- if (!S && o && (console.warn(
421
+ render(e, t = { optimizeImages: !1 }, s = !0) {
422
+ if (!x && s && (console.warn(
379
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/"
380
- ), S = !0), e && e.content && Array.isArray(e.content)) {
381
- let s = "";
424
+ ), x = !0), e && e.content && Array.isArray(e.content)) {
425
+ let o = "";
382
426
  return e.content.forEach((n) => {
383
- s += this.renderNode(n);
384
- }), t.optimizeImages ? this.optimizeImages(s, t.optimizeImages) : s;
427
+ o += this.renderNode(n);
428
+ }), t.optimizeImages ? this.optimizeImages(o, t.optimizeImages) : o;
385
429
  }
386
430
  return console.warn(
387
431
  `The render method must receive an Object with a "content" field.
@@ -411,64 +455,64 @@ class ye {
411
455
  ), "";
412
456
  }
413
457
  optimizeImages(e, t) {
414
- let o = 0, s = 0, n = "", a = "";
415
- typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (n += `width="${t.width}" `, o = t.width), typeof t.height == "number" && t.height > 0 && (n += `height="${t.height}" `, s = 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 && (a += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (a += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-F]{6}/gi) || t.filters.fill === "transparent") && (a += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (a += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (a += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (a += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (a += `:rotate(${t.filters.rotate})`), a.length > 0 && (a = `/filters${a}`))), n.length > 0 && (e = e.replace(/<img/g, `<img ${n.trim()}`));
416
- const l = o > 0 || s > 0 || a.length > 0 ? `${o}x${s}${a}` : "";
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}` : "";
417
461
  return e = e.replace(
418
462
  /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,
419
- `a.storyblok.com/f/$1/$2.$3/m/${l}`
420
- ), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (i) => {
421
- var c, u;
422
- 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(
423
467
  /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g
424
468
  );
425
- if (p && p.length > 0) {
426
- const f = {
427
- srcset: (c = t.srcset) == null ? void 0 : c.map((d) => {
428
- if (typeof d == "number")
429
- return `//${p}/m/${d}x0${a} ${d}w`;
430
- if (typeof d == "object" && d.length === 2) {
431
- let b = 0, m = 0;
432
- return typeof d[0] == "number" && (b = d[0]), typeof d[1] == "number" && (m = d[1]), `//${p}/m/${b}x${m}${a} ${b}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`;
433
477
  }
434
478
  return "";
435
479
  }).join(", "),
436
- sizes: (u = t.sizes) == null ? void 0 : u.map((d) => d).join(", ")
480
+ sizes: (h = t.sizes) == null ? void 0 : h.map((p) => p).join(", ")
437
481
  };
438
- let h = "";
439
- 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()}`);
440
484
  }
441
- return i;
485
+ return l;
442
486
  })), e;
443
487
  }
444
488
  renderNode(e) {
445
489
  const t = [];
446
- e.marks && e.marks.forEach((s) => {
447
- const n = this.getMatchingMark(s);
490
+ e.marks && e.marks.forEach((o) => {
491
+ const n = this.getMatchingMark(o);
448
492
  n && n.tag !== "" && t.push(this.renderOpeningTag(n.tag));
449
493
  });
450
- const o = this.getMatchingNode(e);
451
- return o && o.tag && t.push(this.renderOpeningTag(o.tag)), e.content ? e.content.forEach((s) => {
452
- t.push(this.renderNode(s));
453
- }) : e.text ? t.push(be(e.text)) : o && o.singleTag ? t.push(this.renderTag(o.singleTag, " /")) : o && o.html ? t.push(o.html) : e.type === "emoji" && t.push(this.renderEmoji(e)), o && o.tag && t.push(this.renderClosingTag(o.tag)), e.marks && e.marks.slice(0).reverse().forEach((s) => {
454
- const n = this.getMatchingMark(s);
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);
455
499
  n && n.tag !== "" && t.push(this.renderClosingTag(n.tag));
456
500
  }), t.join("");
457
501
  }
458
502
  renderTag(e, t) {
459
- return e.constructor === String ? `<${e}${t}>` : e.map((o) => {
460
- if (o.constructor === String)
461
- return `<${o}${t}>`;
503
+ return e.constructor === String ? `<${e}${t}>` : e.map((s) => {
504
+ if (s.constructor === String)
505
+ return `<${s}${t}>`;
462
506
  {
463
- let s = `<${o.tag}`;
464
- if (o.attrs) {
465
- for (const n in o.attrs)
466
- if (Object.prototype.hasOwnProperty.call(o.attrs, n)) {
467
- const a = o.attrs[n];
468
- 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}"`);
469
513
  }
470
514
  }
471
- return `${s}${t}>`;
515
+ return `${o}${t}>`;
472
516
  }
473
517
  }).join("");
474
518
  }
@@ -505,7 +549,468 @@ class ye {
505
549
  return this.renderTag(t, " /");
506
550
  }
507
551
  }
508
- const me = ye, xe = (r) => {
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;
1002
+ }
1003
+ }
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) => {
509
1014
  if (typeof r != "object" || typeof r._editable > "u")
510
1015
  return {};
511
1016
  try {
@@ -514,54 +1019,75 @@ const me = ye, xe = (r) => {
514
1019
  );
515
1020
  return e ? {
516
1021
  "data-blok-c": JSON.stringify(e),
517
- "data-blok-uid": e.id + "-" + e.uid
1022
+ "data-blok-uid": `${e.id}-${e.uid}`
518
1023
  } : {};
519
1024
  } catch {
520
1025
  return {};
521
1026
  }
522
1027
  };
523
- let ke, we = "https://app.storyblok.com/f/storyblok-v2-latest.js";
524
- const $e = (r, e) => {
1028
+ let T, S = "https://app.storyblok.com/f/storyblok-v2-latest.js";
1029
+ const M = (r, e) => {
525
1030
  r.addNode("blok", (t) => {
526
- let o = "";
527
- return t.attrs.body.forEach((s) => {
528
- o += e(s.component, s);
1031
+ let s = "";
1032
+ return t.attrs.body.forEach((o) => {
1033
+ s += e(o.component, o);
529
1034
  }), {
530
- html: o
1035
+ html: s
531
1036
  };
532
1037
  });
533
- }, ve = (r) => !r || !(r != null && r.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")), Ce = (r, e, t) => {
534
- let o = t || ke;
535
- 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) {
536
1062
  console.error(
537
1063
  "Please initialize the Storyblok SDK before calling the renderRichText function"
538
1064
  );
539
1065
  return;
540
1066
  }
541
- return ve(r) ? "" : (e && (o = new me(e.schema), e.resolver && $e(o, e.resolver)), o.render(r, {}, !1));
542
- }, Ae = () => B(we);
543
- function Ee() {
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() {
544
1070
  if (!(globalThis != null && globalThis.storyblokApiInstance))
545
1071
  throw new Error("storyblokApiInstance has not been initialized correctly");
546
1072
  return globalThis.storyblokApiInstance;
547
1073
  }
548
- async function Le(r) {
1074
+ async function De(r) {
549
1075
  let e = null;
550
1076
  return r && r.locals._storyblok_preview_data && (e = r.locals._storyblok_preview_data), e;
551
1077
  }
552
- function Re(r, e) {
553
- var o;
554
- const t = (o = globalThis == null ? void 0 : globalThis.storyblokApiInstance) == null ? void 0 : o.richTextResolver;
1078
+ function ze(r, e) {
1079
+ var s;
1080
+ const t = (s = globalThis == null ? void 0 : globalThis.storyblokApiInstance) == null ? void 0 : s.richTextResolver;
555
1081
  if (!t)
556
1082
  throw new Error(
557
1083
  "Please initialize the Storyblok SDK before calling the renderRichText function"
558
1084
  );
559
- return Ce(r, e, t);
1085
+ return je(r, e, t);
560
1086
  }
561
- function Ie(r) {
1087
+ function Oe(r) {
562
1088
  return typeof r == "object" ? `const storyblokInstance = new StoryblokBridge(${JSON.stringify(r)});` : "const storyblokInstance = new StoryblokBridge();";
563
1089
  }
564
- function je(r) {
1090
+ function He(r) {
565
1091
  const e = {
566
1092
  useCustomApi: !1,
567
1093
  bridge: !0,
@@ -569,45 +1095,45 @@ function je(r) {
569
1095
  enableFallbackComponent: !1,
570
1096
  livePreview: !1,
571
1097
  ...r
572
- }, t = Ie(e.bridge);
1098
+ }, t = Oe(e.bridge);
573
1099
  return {
574
1100
  name: "@storyblok/astro",
575
1101
  hooks: {
576
1102
  "astro:config:setup": ({
577
- injectScript: o,
578
- updateConfig: s,
1103
+ injectScript: s,
1104
+ updateConfig: o,
579
1105
  addDevToolbarApp: n,
580
- addMiddleware: a,
581
- config: l
1106
+ addMiddleware: i,
1107
+ config: a
582
1108
  }) => {
583
- if (s({
1109
+ if (o({
584
1110
  vite: {
585
1111
  plugins: [
586
- N(
1112
+ Z(
587
1113
  e.accessToken,
588
1114
  e.useCustomApi,
589
1115
  e.apiOptions
590
1116
  ),
591
- _(
1117
+ K(
592
1118
  e.componentsDir,
593
1119
  e.components,
594
1120
  e.enableFallbackComponent,
595
1121
  e.customFallbackComponent
596
1122
  ),
597
- z(e)
1123
+ G(e)
598
1124
  ]
599
1125
  }
600
- }), e.livePreview && (l == null ? void 0 : l.output) !== "server")
1126
+ }), e.livePreview && (a == null ? void 0 : a.output) !== "server")
601
1127
  throw new Error(
602
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."
603
1129
  );
604
- o(
1130
+ s(
605
1131
  "page-ssr",
606
1132
  `
607
1133
  import { storyblokApiInstance } from "virtual:storyblok-init";
608
1134
  globalThis.storyblokApiInstance = storyblokApiInstance;
609
1135
  `
610
- ), e.bridge && !e.livePreview && o(
1136
+ ), e.bridge && !e.livePreview && s(
611
1137
  "page",
612
1138
  `import { loadStoryblokBridge } from "@storyblok/astro";
613
1139
  loadStoryblokBridge().then(() => {
@@ -620,7 +1146,7 @@ function je(r) {
620
1146
  });
621
1147
  });
622
1148
  `
623
- ), e.livePreview && (o(
1149
+ ), e.livePreview && (s(
624
1150
  "page",
625
1151
  `import { loadStoryblokBridge, handleStoryblokMessage } from "@storyblok/astro";
626
1152
  loadStoryblokBridge().then(() => {
@@ -629,44 +1155,80 @@ function je(r) {
629
1155
  storyblokInstance.on(["published", "change", "input"], handleStoryblokMessage);
630
1156
  });
631
1157
  `
632
- ), a({
1158
+ ), i({
633
1159
  entrypoint: "@storyblok/astro/middleware.ts",
634
1160
  order: "pre"
635
1161
  })), n({
636
1162
  id: "storyblok",
637
1163
  name: "Storyblok",
638
- icon: A,
1164
+ icon: B,
639
1165
  entrypoint: "@storyblok/astro/toolbarApp.ts"
640
1166
  });
641
1167
  }
642
1168
  }
643
1169
  };
644
1170
  }
645
- let T;
646
- async function Me(r) {
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) {
647
1209
  const { action: e, story: t } = r || {};
648
1210
  if (e === "input" && t) {
649
- const o = async () => {
650
- const n = await Te(t), a = document.body;
651
- if (n.outerHTML === a.outerHTML)
1211
+ const s = async () => {
1212
+ const n = await Me(t), i = document.body;
1213
+ if (n.outerHTML === i.outerHTML)
652
1214
  return;
653
- const l = document.querySelector('[data-blok-focused="true"]');
654
- Se(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"));
655
1217
  };
656
- clearTimeout(T), T = setTimeout(o, 500);
1218
+ clearTimeout(j), j = setTimeout(s, 500);
657
1219
  }
658
1220
  ["published", "change"].includes(r == null ? void 0 : r.action) && location.reload();
659
1221
  }
660
- function Se(r, e, t) {
1222
+ function Ne(r, e, t) {
661
1223
  if (t) {
662
- const o = t.getAttribute("data-blok-uid"), s = e.querySelector(
663
- `[data-blok-uid="${o}"]`
1224
+ const s = t.getAttribute("data-blok-uid"), o = e.querySelector(
1225
+ `[data-blok-uid="${s}"]`
664
1226
  );
665
- s && (s.setAttribute("data-blok-focused", "true"), t.replaceWith(s));
1227
+ o && (o.setAttribute("data-blok-focused", "true"), t.replaceWith(o));
666
1228
  } else
667
1229
  r.replaceWith(e);
668
1230
  }
669
- async function Te(r) {
1231
+ async function Me(r) {
670
1232
  const t = await (await fetch(location.href, {
671
1233
  method: "POST",
672
1234
  body: JSON.stringify({
@@ -680,14 +1242,15 @@ async function Te(r) {
680
1242
  return new DOMParser().parseFromString(t, "text/html").body;
681
1243
  }
682
1244
  export {
683
- me as RichTextResolver,
684
- he as RichTextSchema,
685
- Le as getLiveStory,
686
- Me as handleStoryblokMessage,
687
- Ae as loadStoryblokBridge,
688
- Re as renderRichText,
689
- je as storyblok,
690
- xe as storyblokEditable,
691
- v as toCamelCase,
692
- Ee 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
693
1256
  };