@storyblok/react 4.3.6 → 4.4.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,80 +1,80 @@
1
- let H = !1;
2
- const U = [], F = (n) => new Promise((e, t) => {
3
- if (typeof window > "u" || (window.storyblokRegisterEvent = (s) => {
1
+ let U = !1;
2
+ const H = [], F = (r) => new Promise((e, t) => {
3
+ if (typeof window > "u" || (window.storyblokRegisterEvent = (n) => {
4
4
  if (window.location === window.parent.location) {
5
5
  console.warn("You are not in Draft Mode or in the Visual Editor.");
6
6
  return;
7
7
  }
8
- H ? s() : U.push(s);
8
+ U ? n() : H.push(n);
9
9
  }, document.getElementById("storyblok-javascript-bridge")))
10
10
  return;
11
- const r = document.createElement("script");
12
- r.async = !0, r.src = n, r.id = "storyblok-javascript-bridge", r.onerror = (s) => t(s), r.onload = (s) => {
13
- U.forEach((o) => o()), H = !0, e(s);
14
- }, document.getElementsByTagName("head")[0].appendChild(r);
11
+ const s = document.createElement("script");
12
+ s.async = !0, s.src = r, s.id = "storyblok-javascript-bridge", s.onerror = (n) => t(n), s.onload = (n) => {
13
+ H.forEach((o) => o()), U = !0, e(n);
14
+ }, document.getElementsByTagName("head")[0].appendChild(s);
15
15
  });
16
- var Q = Object.defineProperty, Z = (n, e, t) => e in n ? Q(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, p = (n, e, t) => Z(n, typeof e != "symbol" ? e + "" : e, t);
16
+ var Q = Object.defineProperty, Z = (r, e, t) => e in r ? Q(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, p = (r, e, t) => Z(r, typeof e != "symbol" ? e + "" : e, t);
17
17
  class ee extends Error {
18
18
  constructor(e) {
19
19
  super(e), this.name = "AbortError";
20
20
  }
21
21
  }
22
- function te(n, e, t) {
22
+ function te(r, e, t) {
23
23
  if (!Number.isFinite(e))
24
24
  throw new TypeError("Expected `limit` to be a finite number");
25
25
  if (!Number.isFinite(t))
26
26
  throw new TypeError("Expected `interval` to be a finite number");
27
- const r = [];
28
- let s = [], o = 0, i = !1;
27
+ const s = [];
28
+ let n = [], o = 0, i = !1;
29
29
  const l = async () => {
30
30
  o++;
31
- const h = r.shift();
31
+ const h = s.shift();
32
32
  if (h)
33
33
  try {
34
- const d = await n(...h.args);
34
+ const d = await r(...h.args);
35
35
  h.resolve(d);
36
36
  } catch (d) {
37
37
  h.reject(d);
38
38
  }
39
39
  const u = setTimeout(() => {
40
- o--, r.length > 0 && l(), s = s.filter((d) => d !== u);
40
+ o--, s.length > 0 && l(), n = n.filter((d) => d !== u);
41
41
  }, t);
42
- s.includes(u) || s.push(u);
42
+ n.includes(u) || n.push(u);
43
43
  }, a = (...h) => i ? Promise.reject(
44
44
  new Error(
45
45
  "Throttled function is already aborted and not accepting new promises"
46
46
  )
47
47
  ) : new Promise((u, d) => {
48
- r.push({
48
+ s.push({
49
49
  resolve: u,
50
50
  reject: d,
51
51
  args: h
52
52
  }), o < e && l();
53
53
  });
54
54
  return a.abort = () => {
55
- i = !0, s.forEach(clearTimeout), s = [], r.forEach(
55
+ i = !0, n.forEach(clearTimeout), n = [], s.forEach(
56
56
  (h) => h.reject(() => new ee("Throttle function aborted"))
57
- ), r.length = 0;
57
+ ), s.length = 0;
58
58
  }, a;
59
59
  }
60
- class A {
60
+ let A = class {
61
61
  constructor() {
62
- p(this, "isCDNUrl", (e = "") => e.includes("/cdn/")), p(this, "getOptionsPage", (e, t = 25, r = 1) => ({
63
- ...e,
64
- per_page: t,
65
- page: r
66
- })), p(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), p(this, "arrayFrom", (e = 0, t) => Array.from({ length: e }, t)), p(this, "range", (e = 0, t = e) => {
67
- const r = Math.abs(t - e) || 0, s = e < t ? 1 : -1;
68
- return this.arrayFrom(r, (o, i) => i * s + e);
69
- }), p(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), p(this, "flatMap", (e = [], t) => e.map(t).reduce((r, s) => [...r, ...s], [])), p(this, "escapeHTML", function(e) {
70
- const t = {
62
+ p(this, "isCDNUrl", (r = "") => r.includes("/cdn/")), p(this, "getOptionsPage", (r, e = 25, t = 1) => ({
63
+ ...r,
64
+ per_page: e,
65
+ page: t
66
+ })), p(this, "delay", (r) => new Promise((e) => setTimeout(e, r))), p(this, "arrayFrom", (r = 0, e) => Array.from({ length: r }, e)), p(this, "range", (r = 0, e = r) => {
67
+ const t = Math.abs(e - r) || 0, s = r < e ? 1 : -1;
68
+ return this.arrayFrom(t, (n, o) => o * s + r);
69
+ }), p(this, "asyncMap", async (r, e) => Promise.all(r.map(e))), p(this, "flatMap", (r = [], e) => r.map(e).reduce((t, s) => [...t, ...s], [])), p(this, "escapeHTML", function(r) {
70
+ const e = {
71
71
  "&": "&amp;",
72
72
  "<": "&lt;",
73
73
  ">": "&gt;",
74
74
  '"': "&quot;",
75
75
  "'": "&#39;"
76
- }, r = /[&<>"']/g, s = new RegExp(r.source);
77
- return e && s.test(e) ? e.replace(r, (o) => t[o]) : e;
76
+ }, t = /[&<>"']/g, s = new RegExp(t.source);
77
+ return r && s.test(r) ? r.replace(t, (n) => e[n]) : r;
78
78
  });
79
79
  }
80
80
  /**
@@ -84,18 +84,18 @@ class A {
84
84
  * @param {boolean} isArray
85
85
  * @return {string} Stringified object
86
86
  */
87
- stringify(e, t, r) {
87
+ stringify(r, e, t) {
88
88
  const s = [];
89
- for (const o in e) {
90
- if (!Object.prototype.hasOwnProperty.call(e, o))
89
+ for (const n in r) {
90
+ if (!Object.prototype.hasOwnProperty.call(r, n))
91
91
  continue;
92
- const i = e[o], l = r ? "" : encodeURIComponent(o);
93
- let a;
94
- typeof i == "object" ? a = this.stringify(
95
- i,
96
- t ? t + encodeURIComponent(`[${l}]`) : l,
97
- Array.isArray(i)
98
- ) : a = `${t ? t + encodeURIComponent(`[${l}]`) : l}=${encodeURIComponent(i)}`, s.push(a);
92
+ const o = r[n], i = t ? "" : encodeURIComponent(n);
93
+ let l;
94
+ typeof o == "object" ? l = this.stringify(
95
+ o,
96
+ e ? e + encodeURIComponent(`[${i}]`) : i,
97
+ Array.isArray(o)
98
+ ) : l = `${e ? e + encodeURIComponent(`[${i}]`) : i}=${encodeURIComponent(o)}`, s.push(l);
99
99
  }
100
100
  return s.join("&");
101
101
  }
@@ -104,52 +104,52 @@ class A {
104
104
  * @param {string} regionCode region code, could be eu, us, cn, ap or ca
105
105
  * @return {string} The base URL of the region
106
106
  */
107
- getRegionURL(e) {
108
- const t = "api.storyblok.com", r = "api-us.storyblok.com", s = "app.storyblokchina.cn", o = "api-ap.storyblok.com", i = "api-ca.storyblok.com";
109
- switch (e) {
107
+ getRegionURL(r) {
108
+ const e = "api.storyblok.com", t = "api-us.storyblok.com", s = "app.storyblokchina.cn", n = "api-ap.storyblok.com", o = "api-ca.storyblok.com";
109
+ switch (r) {
110
110
  case "us":
111
- return r;
111
+ return t;
112
112
  case "cn":
113
113
  return s;
114
114
  case "ap":
115
- return o;
115
+ return n;
116
116
  case "ca":
117
- return i;
117
+ return o;
118
118
  default:
119
- return t;
119
+ return e;
120
120
  }
121
121
  }
122
- }
123
- const re = function(n, e) {
122
+ };
123
+ const re = function(r, e) {
124
124
  const t = {};
125
- for (const r in n) {
126
- const s = n[r];
127
- e.includes(r) && s !== null && (t[r] = s);
125
+ for (const s in r) {
126
+ const n = r[s];
127
+ e.includes(s) && n !== null && (t[s] = n);
128
128
  }
129
129
  return t;
130
- }, se = (n) => n === "email", ne = () => ({
130
+ }, se = (r) => r === "email", ne = () => ({
131
131
  singleTag: "hr"
132
132
  }), oe = () => ({
133
133
  tag: "blockquote"
134
134
  }), ie = () => ({
135
135
  tag: "ul"
136
- }), ae = (n) => ({
136
+ }), ae = (r) => ({
137
137
  tag: [
138
138
  "pre",
139
139
  {
140
140
  tag: "code",
141
- attrs: n.attrs
141
+ attrs: r.attrs
142
142
  }
143
143
  ]
144
144
  }), le = () => ({
145
145
  singleTag: "br"
146
- }), ce = (n) => ({
147
- tag: `h${n.attrs.level}`
148
- }), he = (n) => ({
146
+ }), ce = (r) => ({
147
+ tag: `h${r.attrs.level}`
148
+ }), he = (r) => ({
149
149
  singleTag: [
150
150
  {
151
151
  tag: "img",
152
- attrs: re(n.attrs, ["src", "alt", "title"])
152
+ attrs: re(r.attrs, ["src", "alt", "title"])
153
153
  }
154
154
  ]
155
155
  }), ue = () => ({
@@ -158,14 +158,14 @@ const re = function(n, e) {
158
158
  tag: "ol"
159
159
  }), pe = () => ({
160
160
  tag: "p"
161
- }), ge = (n) => ({
161
+ }), ge = (r) => ({
162
162
  tag: [
163
163
  {
164
164
  tag: "span",
165
165
  attrs: {
166
166
  "data-type": "emoji",
167
- "data-name": n.attrs.name,
168
- emoji: n.attrs.emoji
167
+ "data-name": r.attrs.name,
168
+ emoji: r.attrs.emoji
169
169
  }
170
170
  }
171
171
  ]
@@ -181,15 +181,15 @@ const re = function(n, e) {
181
181
  tag: "code"
182
182
  }), $e = () => ({
183
183
  tag: "i"
184
- }), ve = (n) => {
185
- if (!n.attrs)
184
+ }), ve = (r) => {
185
+ if (!r.attrs)
186
186
  return {
187
187
  tag: ""
188
188
  };
189
- const e = new A().escapeHTML, t = { ...n.attrs }, { linktype: r = "url" } = n.attrs;
190
- if (delete t.linktype, t.href && (t.href = e(n.attrs.href || "")), se(r) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
191
- for (const s in t.custom)
192
- t[s] = t.custom[s];
189
+ const e = new A().escapeHTML, t = { ...r.attrs }, { linktype: s = "url" } = r.attrs;
190
+ 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) {
191
+ for (const n in t.custom)
192
+ t[n] = t.custom[n];
193
193
  delete t.custom;
194
194
  }
195
195
  return {
@@ -200,46 +200,46 @@ const re = function(n, e) {
200
200
  }
201
201
  ]
202
202
  };
203
- }, Te = (n) => ({
203
+ }, Te = (r) => ({
204
204
  tag: [
205
205
  {
206
206
  tag: "span",
207
- attrs: n.attrs
207
+ attrs: r.attrs
208
208
  }
209
209
  ]
210
210
  }), we = () => ({
211
211
  tag: "sub"
212
212
  }), Re = () => ({
213
213
  tag: "sup"
214
- }), _e = (n) => ({
214
+ }), _e = (r) => ({
215
215
  tag: [
216
216
  {
217
217
  tag: "span",
218
- attrs: n.attrs
218
+ attrs: r.attrs
219
219
  }
220
220
  ]
221
- }), Se = (n) => {
221
+ }), Se = (r) => {
222
222
  var e;
223
- return (e = n.attrs) != null && e.color ? {
223
+ return (e = r.attrs) != null && e.color ? {
224
224
  tag: [
225
225
  {
226
226
  tag: "span",
227
227
  attrs: {
228
- style: `background-color:${n.attrs.color};`
228
+ style: `background-color:${r.attrs.color};`
229
229
  }
230
230
  }
231
231
  ]
232
232
  } : {
233
233
  tag: ""
234
234
  };
235
- }, Ee = (n) => {
235
+ }, Ee = (r) => {
236
236
  var e;
237
- return (e = n.attrs) != null && e.color ? {
237
+ return (e = r.attrs) != null && e.color ? {
238
238
  tag: [
239
239
  {
240
240
  tag: "span",
241
241
  attrs: {
242
- style: `color:${n.attrs.color}`
242
+ style: `color:${r.attrs.color}`
243
243
  }
244
244
  }
245
245
  ]
@@ -275,18 +275,18 @@ const re = function(n, e) {
275
275
  highlight: Se,
276
276
  textStyle: Ee
277
277
  }
278
- }, Ie = function(n) {
278
+ }, Ie = function(r) {
279
279
  const e = {
280
280
  "&": "&amp;",
281
281
  "<": "&lt;",
282
282
  ">": "&gt;",
283
283
  '"': "&quot;",
284
284
  "'": "&#39;"
285
- }, t = /[&<>"']/g, r = new RegExp(t.source);
286
- return n && r.test(n) ? n.replace(t, (s) => e[s]) : n;
285
+ }, t = /[&<>"']/g, s = new RegExp(t.source);
286
+ return r && s.test(r) ? r.replace(t, (n) => e[n]) : r;
287
287
  };
288
288
  let z = !1;
289
- class xe {
289
+ class L {
290
290
  constructor(e) {
291
291
  p(this, "marks"), p(this, "nodes"), e || (e = je), this.marks = e.marks || [], this.nodes = e.nodes || [];
292
292
  }
@@ -296,14 +296,14 @@ class xe {
296
296
  addMark(e, t) {
297
297
  this.marks[e] = t;
298
298
  }
299
- render(e, t = { optimizeImages: !1 }, r = !0) {
300
- if (!z && r && (console.warn(
299
+ render(e, t = { optimizeImages: !1 }, s = !0) {
300
+ if (!z && s && (console.warn(
301
301
  "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/"
302
302
  ), z = !0), e && e.content && Array.isArray(e.content)) {
303
- let s = "";
303
+ let n = "";
304
304
  return e.content.forEach((o) => {
305
- s += this.renderNode(o);
306
- }), t.optimizeImages ? this.optimizeImages(s, t.optimizeImages) : s;
305
+ n += this.renderNode(o);
306
+ }), t.optimizeImages ? this.optimizeImages(n, t.optimizeImages) : n;
307
307
  }
308
308
  return console.warn(
309
309
  `The render method must receive an Object with a "content" field.
@@ -333,9 +333,9 @@ class xe {
333
333
  ), "";
334
334
  }
335
335
  optimizeImages(e, t) {
336
- let r = 0, s = 0, o = "", i = "";
337
- typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (o += `width="${t.width}" `, r = t.width), typeof t.height == "number" && t.height > 0 && (o += `height="${t.height}" `, s = t.height), (t.loading === "lazy" || t.loading === "eager") && (o += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (o += `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}`))), o.length > 0 && (e = e.replace(/<img/g, `<img ${o.trim()}`));
338
- const l = r > 0 || s > 0 || i.length > 0 ? `${r}x${s}${i}` : "";
336
+ let s = 0, n = 0, o = "", i = "";
337
+ typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (o += `width="${t.width}" `, s = t.width), typeof t.height == "number" && t.height > 0 && (o += `height="${t.height}" `, n = t.height), (t.loading === "lazy" || t.loading === "eager") && (o += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (o += `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}`))), o.length > 0 && (e = e.replace(/<img/g, `<img ${o.trim()}`));
338
+ const l = s > 0 || n > 0 || i.length > 0 ? `${s}x${n}${i}` : "";
339
339
  return e = e.replace(
340
340
  /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,
341
341
  `a.storyblok.com/f/$1/$2.$3/m/${l}`
@@ -346,51 +346,51 @@ class xe {
346
346
  );
347
347
  if (d && d.length > 0) {
348
348
  const m = {
349
- srcset: (h = t.srcset) == null ? void 0 : h.map((y) => {
350
- if (typeof y == "number")
351
- return `//${d}/m/${y}x0${i} ${y}w`;
352
- if (typeof y == "object" && y.length === 2) {
349
+ srcset: (h = t.srcset) == null ? void 0 : h.map((b) => {
350
+ if (typeof b == "number")
351
+ return `//${d}/m/${b}x0${i} ${b}w`;
352
+ if (typeof b == "object" && b.length === 2) {
353
353
  let _ = 0, j = 0;
354
- return typeof y[0] == "number" && (_ = y[0]), typeof y[1] == "number" && (j = y[1]), `//${d}/m/${_}x${j}${i} ${_}w`;
354
+ return typeof b[0] == "number" && (_ = b[0]), typeof b[1] == "number" && (j = b[1]), `//${d}/m/${_}x${j}${i} ${_}w`;
355
355
  }
356
356
  return "";
357
357
  }).join(", "),
358
- sizes: (u = t.sizes) == null ? void 0 : u.map((y) => y).join(", ")
358
+ sizes: (u = t.sizes) == null ? void 0 : u.map((b) => b).join(", ")
359
359
  };
360
- let b = "";
361
- return m.srcset && (b += `srcset="${m.srcset}" `), m.sizes && (b += `sizes="${m.sizes}" `), a.replace(/<img/g, `<img ${b.trim()}`);
360
+ let y = "";
361
+ return m.srcset && (y += `srcset="${m.srcset}" `), m.sizes && (y += `sizes="${m.sizes}" `), a.replace(/<img/g, `<img ${y.trim()}`);
362
362
  }
363
363
  return a;
364
364
  })), e;
365
365
  }
366
366
  renderNode(e) {
367
367
  const t = [];
368
- e.marks && e.marks.forEach((s) => {
369
- const o = this.getMatchingMark(s);
368
+ e.marks && e.marks.forEach((n) => {
369
+ const o = this.getMatchingMark(n);
370
370
  o && o.tag !== "" && t.push(this.renderOpeningTag(o.tag));
371
371
  });
372
- const r = this.getMatchingNode(e);
373
- return r && r.tag && t.push(this.renderOpeningTag(r.tag)), e.content ? e.content.forEach((s) => {
374
- t.push(this.renderNode(s));
375
- }) : e.text ? t.push(Ie(e.text)) : r && r.singleTag ? t.push(this.renderTag(r.singleTag, " /")) : r && r.html ? t.push(r.html) : e.type === "emoji" && t.push(this.renderEmoji(e)), r && r.tag && t.push(this.renderClosingTag(r.tag)), e.marks && e.marks.slice(0).reverse().forEach((s) => {
376
- const o = this.getMatchingMark(s);
372
+ const s = this.getMatchingNode(e);
373
+ return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((n) => {
374
+ t.push(this.renderNode(n));
375
+ }) : e.text ? t.push(Ie(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((n) => {
376
+ const o = this.getMatchingMark(n);
377
377
  o && o.tag !== "" && t.push(this.renderClosingTag(o.tag));
378
378
  }), t.join("");
379
379
  }
380
380
  renderTag(e, t) {
381
- return e.constructor === String ? `<${e}${t}>` : e.map((r) => {
382
- if (r.constructor === String)
383
- return `<${r}${t}>`;
381
+ return e.constructor === String ? `<${e}${t}>` : e.map((s) => {
382
+ if (s.constructor === String)
383
+ return `<${s}${t}>`;
384
384
  {
385
- let s = `<${r.tag}`;
386
- if (r.attrs) {
387
- for (const o in r.attrs)
388
- if (Object.prototype.hasOwnProperty.call(r.attrs, o)) {
389
- const i = r.attrs[o];
390
- i !== null && (s += ` ${o}="${i}"`);
385
+ let n = `<${s.tag}`;
386
+ if (s.attrs) {
387
+ for (const o in s.attrs)
388
+ if (Object.prototype.hasOwnProperty.call(s.attrs, o)) {
389
+ const i = s.attrs[o];
390
+ i !== null && (n += ` ${o}="${i}"`);
391
391
  }
392
392
  }
393
- return `${s}${t}>`;
393
+ return `${n}${t}>`;
394
394
  }
395
395
  }).join("");
396
396
  }
@@ -427,8 +427,7 @@ class xe {
427
427
  return this.renderTag(t, " /");
428
428
  }
429
429
  }
430
- const L = xe;
431
- class Oe {
430
+ class xe {
432
431
  constructor(e) {
433
432
  p(this, "baseURL"), p(this, "timeout"), p(this, "headers"), p(this, "responseInterceptor"), p(this, "fetch"), p(this, "ejectInterceptor"), p(this, "url"), p(this, "parameters"), p(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 = {};
434
433
  }
@@ -451,36 +450,36 @@ class Oe {
451
450
  return this.url = e, this.parameters = t ?? {}, this._methodHandler("delete");
452
451
  }
453
452
  async _responseHandler(e) {
454
- const t = [], r = {
453
+ const t = [], s = {
455
454
  data: {},
456
455
  headers: {},
457
456
  status: 0,
458
457
  statusText: ""
459
458
  };
460
- e.status !== 204 && await e.json().then((s) => {
461
- r.data = s;
459
+ e.status !== 204 && await e.json().then((n) => {
460
+ s.data = n;
462
461
  });
463
- for (const s of e.headers.entries())
464
- t[s[0]] = s[1];
465
- return r.headers = { ...t }, r.status = e.status, r.statusText = e.statusText, r;
462
+ for (const n of e.headers.entries())
463
+ t[n[0]] = n[1];
464
+ return s.headers = { ...t }, s.status = e.status, s.statusText = e.statusText, s;
466
465
  }
467
466
  async _methodHandler(e) {
468
- let t = `${this.baseURL}${this.url}`, r = null;
467
+ let t = `${this.baseURL}${this.url}`, s = null;
469
468
  if (e === "get") {
470
469
  const a = new A();
471
470
  t = `${this.baseURL}${this.url}?${a.stringify(
472
471
  this.parameters
473
472
  )}`;
474
473
  } else
475
- r = JSON.stringify(this.parameters);
476
- const s = new URL(t), o = new AbortController(), { signal: i } = o;
474
+ s = JSON.stringify(this.parameters);
475
+ const n = new URL(t), o = new AbortController(), { signal: i } = o;
477
476
  let l;
478
477
  this.timeout && (l = setTimeout(() => o.abort(), this.timeout));
479
478
  try {
480
- const a = await this.fetch(`${s}`, {
479
+ const a = await this.fetch(`${n}`, {
481
480
  method: e,
482
481
  headers: this.headers,
483
- body: r,
482
+ body: s,
484
483
  signal: i,
485
484
  ...this.fetchOptions
486
485
  });
@@ -503,26 +502,26 @@ class Oe {
503
502
  }
504
503
  _statusHandler(e) {
505
504
  const t = /20[0-6]/g;
506
- return new Promise((r, s) => {
505
+ return new Promise((s, n) => {
507
506
  if (t.test(`${e.status}`))
508
- return r(e);
507
+ return s(e);
509
508
  const o = {
510
509
  message: e.statusText,
511
510
  status: e.status,
512
511
  response: Array.isArray(e.data) ? e.data[0] : e.data.error || e.data.slug
513
512
  };
514
- s(o);
513
+ n(o);
515
514
  });
516
515
  }
517
516
  }
518
- const Ae = Oe, D = "SB-Agent", P = {
517
+ const D = "SB-Agent", C = {
519
518
  defaultAgentName: "SB-JS-CLIENT",
520
519
  defaultAgentVersion: "SB-Agent-Version",
521
520
  packageVersion: "6.0.0"
522
521
  };
523
522
  let O = {};
524
- const E = {};
525
- class Le {
523
+ const S = {};
524
+ class Oe {
526
525
  /**
527
526
  *
528
527
  * @param config ISbConfig interface
@@ -530,96 +529,96 @@ class Le {
530
529
  */
531
530
  constructor(e, t) {
532
531
  p(this, "client"), p(this, "maxRetries"), p(this, "retriesDelay"), p(this, "throttle"), p(this, "accessToken"), p(this, "cache"), p(this, "helpers"), p(this, "resolveCounter"), p(this, "relations"), p(this, "links"), p(this, "richTextResolver"), p(this, "resolveNestedRelations"), p(this, "stringifiedStoriesCache");
533
- let r = e.endpoint || t;
534
- if (!r) {
532
+ let s = e.endpoint || t;
533
+ if (!s) {
535
534
  const i = new A().getRegionURL, l = e.https === !1 ? "http" : "https";
536
- e.oauthToken ? r = `${l}://${i(e.region)}/v1` : r = `${l}://${i(e.region)}/v2`;
535
+ e.oauthToken ? s = `${l}://${i(e.region)}/v1` : s = `${l}://${i(e.region)}/v2`;
537
536
  }
538
- const s = new Headers();
539
- s.set("Content-Type", "application/json"), s.set("Accept", "application/json"), e.headers && (e.headers.constructor.name === "Headers" ? e.headers.entries().toArray() : Object.entries(e.headers)).forEach(([i, l]) => {
540
- s.set(i, l);
541
- }), s.has(D) || (s.set(D, P.defaultAgentName), s.set(
542
- P.defaultAgentVersion,
543
- P.packageVersion
537
+ const n = new Headers();
538
+ n.set("Content-Type", "application/json"), n.set("Accept", "application/json"), e.headers && (e.headers.constructor.name === "Headers" ? e.headers.entries().toArray() : Object.entries(e.headers)).forEach(([i, l]) => {
539
+ n.set(i, l);
540
+ }), n.has(D) || (n.set(D, C.defaultAgentName), n.set(
541
+ C.defaultAgentVersion,
542
+ C.packageVersion
544
543
  ));
545
544
  let o = 5;
546
- e.oauthToken && (s.set("Authorization", e.oauthToken), o = 3), e.rateLimit && (o = e.rateLimit), e.richTextSchema ? this.richTextResolver = new L(e.richTextSchema) : this.richTextResolver = new L(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = te(
545
+ e.oauthToken && (n.set("Authorization", e.oauthToken), o = 3), e.rateLimit && (o = e.rateLimit), e.richTextSchema ? this.richTextResolver = new L(e.richTextSchema) : this.richTextResolver = new L(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = te(
547
546
  this.throttledRequest.bind(this),
548
547
  o,
549
548
  1e3
550
- ), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new A(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new Ae({
551
- baseURL: r,
549
+ ), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new A(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new xe({
550
+ baseURL: s,
552
551
  timeout: e.timeout || 0,
553
- headers: s,
552
+ headers: n,
554
553
  responseInterceptor: e.responseInterceptor,
555
554
  fetch: e.fetch
556
555
  });
557
556
  }
558
557
  setComponentResolver(e) {
559
558
  this.richTextResolver.addNode("blok", (t) => {
560
- let r = "";
561
- return t.attrs.body && t.attrs.body.forEach((s) => {
562
- r += e(s.component, s);
559
+ let s = "";
560
+ return t.attrs.body && t.attrs.body.forEach((n) => {
561
+ s += e(n.component, n);
563
562
  }), {
564
- html: r
563
+ html: s
565
564
  };
566
565
  });
567
566
  }
568
567
  parseParams(e) {
569
- return e.token || (e.token = this.getToken()), e.cv || (e.cv = E[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
568
+ return e.token || (e.token = this.getToken()), e.cv || (e.cv = S[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
570
569
  }
571
570
  factoryParamOptions(e, t) {
572
571
  return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
573
572
  }
574
- makeRequest(e, t, r, s, o) {
573
+ makeRequest(e, t, s, n, o) {
575
574
  const i = this.factoryParamOptions(
576
575
  e,
577
- this.helpers.getOptionsPage(t, r, s)
576
+ this.helpers.getOptionsPage(t, s, n)
578
577
  );
579
578
  return this.cacheResponse(e, i, void 0, o);
580
579
  }
581
- get(e, t, r) {
580
+ get(e, t, s) {
582
581
  t || (t = {});
583
- const s = `/${e}`, o = this.factoryParamOptions(s, t);
584
- return this.cacheResponse(s, o, void 0, r);
582
+ const n = `/${e}`, o = this.factoryParamOptions(n, t);
583
+ return this.cacheResponse(n, o, void 0, s);
585
584
  }
586
- async getAll(e, t, r, s) {
587
- const o = (t == null ? void 0 : t.per_page) || 25, i = `/${e}`.replace(/\/$/, ""), l = r ?? i.substring(i.lastIndexOf("/") + 1), a = 1, h = await this.makeRequest(
585
+ async getAll(e, t, s, n) {
586
+ const o = (t == null ? void 0 : t.per_page) || 25, i = `/${e}`.replace(/\/$/, ""), l = s ?? i.substring(i.lastIndexOf("/") + 1), a = 1, h = await this.makeRequest(
588
587
  i,
589
588
  t,
590
589
  o,
591
590
  a,
592
- s
591
+ n
593
592
  ), u = h.total ? Math.ceil(h.total / o) : 1, d = await this.helpers.asyncMap(
594
593
  this.helpers.range(a, u),
595
- (m) => this.makeRequest(i, t, o, m + 1, s)
594
+ (m) => this.makeRequest(i, t, o, m + 1, n)
596
595
  );
597
596
  return this.helpers.flatMap([h, ...d], (m) => Object.values(m.data[l]));
598
597
  }
599
- post(e, t, r) {
600
- const s = `/${e}`;
598
+ post(e, t, s) {
599
+ const n = `/${e}`;
601
600
  return Promise.resolve(
602
- this.throttle("post", s, t, r)
601
+ this.throttle("post", n, t, s)
603
602
  );
604
603
  }
605
- put(e, t, r) {
606
- const s = `/${e}`;
604
+ put(e, t, s) {
605
+ const n = `/${e}`;
607
606
  return Promise.resolve(
608
- this.throttle("put", s, t, r)
607
+ this.throttle("put", n, t, s)
609
608
  );
610
609
  }
611
- delete(e, t, r) {
610
+ delete(e, t, s) {
612
611
  t || (t = {});
613
- const s = `/${e}`;
612
+ const n = `/${e}`;
614
613
  return Promise.resolve(
615
- this.throttle("delete", s, t, r)
614
+ this.throttle("delete", n, t, s)
616
615
  );
617
616
  }
618
617
  getStories(e, t) {
619
618
  return this._addResolveLevel(e), this.get("cdn/stories", e, t);
620
619
  }
621
- getStory(e, t, r) {
622
- return this._addResolveLevel(t), this.get(`cdn/stories/${e}`, t, r);
620
+ getStory(e, t, s) {
621
+ return this._addResolveLevel(t), this.get(`cdn/stories/${e}`, t, s);
623
622
  }
624
623
  getToken() {
625
624
  return this.accessToken;
@@ -633,9 +632,9 @@ class Le {
633
632
  _cleanCopy(e) {
634
633
  return JSON.parse(JSON.stringify(e));
635
634
  }
636
- _insertLinks(e, t, r) {
637
- const s = e[t];
638
- s && s.fieldtype === "multilink" && s.linktype === "story" && typeof s.id == "string" && this.links[r][s.id] ? s.story = this._cleanCopy(this.links[r][s.id]) : s && s.linktype === "story" && typeof s.uuid == "string" && this.links[r][s.uuid] && (s.story = this._cleanCopy(this.links[r][s.uuid]));
635
+ _insertLinks(e, t, s) {
636
+ const n = e[t];
637
+ n && n.fieldtype === "multilink" && n.linktype === "story" && typeof n.id == "string" && this.links[s][n.id] ? n.story = this._cleanCopy(this.links[s][n.id]) : n && n.linktype === "story" && typeof n.uuid == "string" && this.links[s][n.uuid] && (n.story = this._cleanCopy(this.links[s][n.uuid]));
639
638
  }
640
639
  /**
641
640
  *
@@ -656,10 +655,10 @@ class Le {
656
655
  * - For single strings: directly replaces the UUID with the story reference
657
656
  * - For arrays: maps through each UUID and replaces with corresponding story references
658
657
  */
659
- _resolveField(e, t, r) {
660
- const s = e[t];
661
- typeof s == "string" ? e[t] = this.getStoryReference(r, s) : Array.isArray(s) && (e[t] = s.map(
662
- (o) => this.getStoryReference(r, o)
658
+ _resolveField(e, t, s) {
659
+ const n = e[t];
660
+ typeof n == "string" ? e[t] = this.getStoryReference(s, n) : Array.isArray(n) && (e[t] = n.map(
661
+ (o) => this.getStoryReference(s, o)
663
662
  ).filter(Boolean));
664
663
  }
665
664
  /**
@@ -679,13 +678,13 @@ class Le {
679
678
  * The method supports both string and array formats for the fields parameter,
680
679
  * allowing flexible specification of relation patterns.
681
680
  */
682
- _insertRelations(e, t, r, s) {
683
- if (Array.isArray(r) ? r.find((i) => i.endsWith(`.${t}`)) : r.endsWith(`.${t}`)) {
684
- this._resolveField(e, t, s);
681
+ _insertRelations(e, t, s, n) {
682
+ if (Array.isArray(s) ? s.find((i) => i.endsWith(`.${t}`)) : s.endsWith(`.${t}`)) {
683
+ this._resolveField(e, t, n);
685
684
  return;
686
685
  }
687
686
  const o = e.component ? `${e.component}.${t}` : t;
688
- (Array.isArray(r) ? r.includes(o) : r === o) && this._resolveField(e, t, s);
687
+ (Array.isArray(s) ? s.includes(o) : s === o) && this._resolveField(e, t, n);
689
688
  }
690
689
  /**
691
690
  * Recursively traverses and resolves relations in the story content tree
@@ -693,22 +692,22 @@ class Le {
693
692
  * @param fields - The relation patterns to resolve
694
693
  * @param resolveId - The unique identifier for the current resolution context
695
694
  */
696
- iterateTree(e, t, r) {
697
- const s = (o, i = "") => {
695
+ iterateTree(e, t, s) {
696
+ const n = (o, i = "") => {
698
697
  if (!(!o || o._stopResolving)) {
699
698
  if (Array.isArray(o))
700
- o.forEach((l, a) => s(l, `${i}[${a}]`));
699
+ o.forEach((l, a) => n(l, `${i}[${a}]`));
701
700
  else if (typeof o == "object")
702
701
  for (const l in o) {
703
702
  const a = i ? `${i}.${l}` : l;
704
- (o.component && o._uid || o.type === "link") && (this._insertRelations(o, l, t, r), this._insertLinks(o, l, r)), s(o[l], a);
703
+ (o.component && o._uid || o.type === "link") && (this._insertRelations(o, l, t, s), this._insertLinks(o, l, s)), n(o[l], a);
705
704
  }
706
705
  }
707
706
  };
708
- s(e.content);
707
+ n(e.content);
709
708
  }
710
- async resolveLinks(e, t, r) {
711
- let s = [];
709
+ async resolveLinks(e, t, s) {
710
+ let n = [];
712
711
  if (e.link_uuids) {
713
712
  const o = e.link_uuids.length, i = [], l = 50;
714
713
  for (let a = 0; a < o; a += l) {
@@ -723,20 +722,20 @@ class Le {
723
722
  by_uuids: i[a].join(",")
724
723
  })).data.stories.forEach(
725
724
  (h) => {
726
- s.push(h);
725
+ n.push(h);
727
726
  }
728
727
  );
729
728
  } else
730
- s = e.links;
731
- s.forEach((o) => {
732
- this.links[r][o.uuid] = {
729
+ n = e.links;
730
+ n.forEach((o) => {
731
+ this.links[s][o.uuid] = {
733
732
  ...o,
734
733
  _stopResolving: !0
735
734
  };
736
735
  });
737
736
  }
738
- async resolveRelations(e, t, r) {
739
- let s = [];
737
+ async resolveRelations(e, t, s) {
738
+ let n = [];
740
739
  if (e.rel_uuids) {
741
740
  const o = e.rel_uuids.length, i = [], l = 50;
742
741
  for (let a = 0; a < o; a += l) {
@@ -751,12 +750,12 @@ class Le {
751
750
  by_uuids: i[a].join(","),
752
751
  excluding_fields: t.excluding_fields
753
752
  })).data.stories.forEach((h) => {
754
- s.push(h);
753
+ n.push(h);
755
754
  });
756
755
  } else
757
- s = e.rels;
758
- s && s.length > 0 && s.forEach((o) => {
759
- this.relations[r][o.uuid] = {
756
+ n = e.rels;
757
+ n && n.length > 0 && n.forEach((o) => {
758
+ this.relations[s][o.uuid] = {
760
759
  ...o,
761
760
  _stopResolving: !0
762
761
  };
@@ -771,23 +770,23 @@ class Le {
771
770
  * @returns Promise<void>
772
771
  *
773
772
  */
774
- async resolveStories(e, t, r) {
775
- var s, o;
773
+ async resolveStories(e, t, s) {
774
+ var n, o;
776
775
  let i = [];
777
- if (this.links[r] = {}, this.relations[r] = {}, 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, r)), t.resolve_links && ["1", "story", "url", "link"].includes(t.resolve_links) && ((s = e.links) != null && s.length || (o = e.link_uuids) != null && o.length) && await this.resolveLinks(e, t, r), this.resolveNestedRelations)
778
- for (const l in this.relations[r])
776
+ 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) && ((n = e.links) != null && n.length || (o = e.link_uuids) != null && o.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
777
+ for (const l in this.relations[s])
779
778
  this.iterateTree(
780
- this.relations[r][l],
779
+ this.relations[s][l],
781
780
  i,
782
- r
781
+ s
783
782
  );
784
- e.story ? this.iterateTree(e.story, i, r) : e.stories.forEach((l) => {
785
- this.iterateTree(l, i, r);
786
- }), this.stringifiedStoriesCache = {}, delete this.links[r], delete this.relations[r];
783
+ e.story ? this.iterateTree(e.story, i, s) : e.stories.forEach((l) => {
784
+ this.iterateTree(l, i, s);
785
+ }), this.stringifiedStoriesCache = {}, delete this.links[s], delete this.relations[s];
787
786
  }
788
- async cacheResponse(e, t, r, s) {
787
+ async cacheResponse(e, t, s, n) {
789
788
  const o = this.helpers.stringify({ url: e, params: t }), i = this.cacheProvider();
790
- if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e !== "/cdn/spaces/me") {
789
+ if (t.version === "published" && e !== "/cdn/spaces/me") {
791
790
  const l = await i.get(o);
792
791
  if (l)
793
792
  return Promise.resolve(l);
@@ -799,7 +798,7 @@ class Le {
799
798
  "get",
800
799
  e,
801
800
  t,
802
- s
801
+ n
803
802
  );
804
803
  if (u.status !== 200)
805
804
  return a(u);
@@ -808,33 +807,35 @@ class Le {
808
807
  perPage: u.headers["per-page"] ? Number.parseInt(u.headers["per-page"]) : 0,
809
808
  total: u.headers["per-page"] ? Number.parseInt(u.headers.total) : 0
810
809
  })), d.data.story || d.data.stories) {
811
- const m = this.resolveCounter = ++this.resolveCounter % 1e3;
812
- await this.resolveStories(d.data, t, `${m}`);
810
+ const y = this.resolveCounter = ++this.resolveCounter % 1e3;
811
+ await this.resolveStories(d.data, t, `${y}`);
813
812
  }
814
- return t.version === "published" && e !== "/cdn/spaces/me" && await i.set(o, d), d.data.cv && t.token && E[t.token] !== d.data.cv && (await this.flushCache(), E[t.token] = d.data.cv), l(d);
813
+ t.version === "published" && e !== "/cdn/spaces/me" && await i.set(o, d);
814
+ const m = this.cache.clear === "onpreview" && t.version === "draft" || this.cache.clear === "auto";
815
+ return t.token && d.data.cv && (m && S[t.token] && S[t.token] !== d.data.cv && await this.flushCache(), S[t.token] = d.data.cv), l(d);
815
816
  } catch (u) {
816
- if (u.response && u.status === 429 && (r = typeof r > "u" ? 0 : r + 1, r < this.maxRetries))
817
+ if (u.response && u.status === 429 && (s = typeof s > "u" ? 0 : s + 1, s < this.maxRetries))
817
818
  return console.log(
818
819
  `Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`
819
- ), await this.helpers.delay(this.retriesDelay), this.cacheResponse(e, t, r).then(l).catch(a);
820
+ ), await this.helpers.delay(this.retriesDelay), this.cacheResponse(e, t, s).then(l).catch(a);
820
821
  a(u);
821
822
  }
822
823
  });
823
824
  }
824
- throttledRequest(e, t, r, s) {
825
- return this.client.setFetchOptions(s), this.client[e](t, r);
825
+ throttledRequest(e, t, s, n) {
826
+ return this.client.setFetchOptions(n), this.client[e](t, s);
826
827
  }
827
828
  cacheVersions() {
828
- return E;
829
+ return S;
829
830
  }
830
831
  cacheVersion() {
831
- return E[this.accessToken];
832
+ return S[this.accessToken];
832
833
  }
833
834
  setCacheVersion(e) {
834
- this.accessToken && (E[this.accessToken] = e);
835
+ this.accessToken && (S[this.accessToken] = e);
835
836
  }
836
837
  clearCacheVersion() {
837
- this.accessToken && (E[this.accessToken] = 0);
838
+ this.accessToken && (S[this.accessToken] = 0);
838
839
  }
839
840
  cacheProvider() {
840
841
  switch (this.cache.type) {
@@ -856,6 +857,7 @@ class Le {
856
857
  case "custom":
857
858
  if (this.cache.custom)
858
859
  return this.cache.custom;
860
+ // eslint-disable-next-line no-fallthrough
859
861
  default:
860
862
  return {
861
863
  get() {
@@ -877,21 +879,21 @@ class Le {
877
879
  return await this.cacheProvider().flush(), this.clearCacheVersion(), this;
878
880
  }
879
881
  }
880
- const ze = (n = {}) => {
881
- const { apiOptions: e } = n;
882
+ const Ue = (r = {}) => {
883
+ const { apiOptions: e } = r;
882
884
  if (!e || !e.accessToken) {
883
885
  console.error(
884
886
  "You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication"
885
887
  );
886
888
  return;
887
889
  }
888
- return { storyblokApi: new Le(e) };
889
- }, De = (n) => {
890
- if (typeof n != "object" || typeof n._editable > "u")
890
+ return { storyblokApi: new Oe(e) };
891
+ }, He = (r) => {
892
+ if (typeof r != "object" || typeof r._editable > "u")
891
893
  return {};
892
894
  try {
893
895
  const e = JSON.parse(
894
- n._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
896
+ r._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
895
897
  );
896
898
  return e ? {
897
899
  "data-blok-c": JSON.stringify(e),
@@ -901,39 +903,39 @@ const ze = (n = {}) => {
901
903
  return {};
902
904
  }
903
905
  };
904
- function Ce(n, e) {
906
+ function Ae(r, e) {
905
907
  if (!e)
906
- return { src: n, attrs: {} };
907
- let t = 0, r = 0;
908
- const s = {}, o = [];
908
+ return { src: r, attrs: {} };
909
+ let t = 0, s = 0;
910
+ const n = {}, o = [];
909
911
  function i(a, h, u, d, m) {
910
912
  typeof a != "number" || a <= h || a >= u ? console.warn(`[StoryblokRichText] - ${d.charAt(0).toUpperCase() + d.slice(1)} value must be a number between ${h} and ${u} (inclusive)`) : m.push(`${d}(${a})`);
911
913
  }
912
914
  if (typeof e == "object") {
913
- if (typeof e.width == "number" && e.width > 0 ? (s.width = e.width, t = e.width) : console.warn("[StoryblokRichText] - Width value must be a number greater than 0"), e.height && typeof e.height == "number" && e.height > 0 ? (s.height = e.height, r = e.height) : console.warn("[StoryblokRichText] - Height value must be a number greater than 0"), e.loading && ["lazy", "eager"].includes(e.loading) && (s.loading = e.loading), e.class && (s.class = e.class), e.filters) {
914
- const { filters: a } = e || {}, { blur: h, brightness: u, fill: d, format: m, grayscale: b, quality: y, rotate: _ } = a || {};
915
- h && i(h, 0, 100, "blur", o), y && i(y, 0, 100, "quality", o), u && i(u, 0, 100, "brightness", o), d && o.push(`fill(${d})`), b && o.push("grayscale()"), _ && [0, 90, 180, 270].includes(e.filters.rotate || 0) && o.push(`rotate(${_})`), m && ["webp", "png", "jpeg"].includes(m) && o.push(`format(${m})`);
915
+ if (typeof e.width == "number" && e.width > 0 ? (n.width = e.width, t = e.width) : console.warn("[StoryblokRichText] - Width value must be a number greater than 0"), e.height && typeof e.height == "number" && e.height > 0 ? (n.height = e.height, s = e.height) : console.warn("[StoryblokRichText] - Height value must be a number greater than 0"), e.loading && ["lazy", "eager"].includes(e.loading) && (n.loading = e.loading), e.class && (n.class = e.class), e.filters) {
916
+ const { filters: a } = e || {}, { blur: h, brightness: u, fill: d, format: m, grayscale: y, quality: b, rotate: _ } = a || {};
917
+ h && i(h, 0, 100, "blur", o), b && i(b, 0, 100, "quality", o), u && i(u, 0, 100, "brightness", o), d && o.push(`fill(${d})`), y && o.push("grayscale()"), _ && [0, 90, 180, 270].includes(e.filters.rotate || 0) && o.push(`rotate(${_})`), m && ["webp", "png", "jpeg"].includes(m) && o.push(`format(${m})`);
916
918
  }
917
- e.srcset && (s.srcset = e.srcset.map((a) => {
919
+ e.srcset && (n.srcset = e.srcset.map((a) => {
918
920
  if (typeof a == "number")
919
- return `${n}/m/${a}x0/${o.length > 0 ? `filters:${o.join(":")}` : ""} ${a}w`;
921
+ return `${r}/m/${a}x0/${o.length > 0 ? `filters:${o.join(":")}` : ""} ${a}w`;
920
922
  if (Array.isArray(a) && a.length === 2) {
921
923
  const [h, u] = a;
922
- return `${n}/m/${h}x${u}/${o.length > 0 ? `filters:${o.join(":")}` : ""} ${h}w`;
924
+ return `${r}/m/${h}x${u}/${o.length > 0 ? `filters:${o.join(":")}` : ""} ${h}w`;
923
925
  } else {
924
926
  console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");
925
927
  return;
926
928
  }
927
- }).join(", ")), e.sizes && (s.sizes = e.sizes.join(", "));
929
+ }).join(", ")), e.sizes && (n.sizes = e.sizes.join(", "));
928
930
  }
929
- let l = `${n}/m/`;
930
- return t > 0 && r > 0 && (l = `${l}${t}x${r}/`), o.length > 0 && (l = `${l}filters:${o.join(":")}`), {
931
+ let l = `${r}/m/`;
932
+ return t > 0 && s > 0 && (l = `${l}${t}x${s}/`), o.length > 0 && (l = `${l}filters:${o.join(":")}`), {
931
933
  src: l,
932
- attrs: s
934
+ attrs: n
933
935
  };
934
936
  }
935
- var v = /* @__PURE__ */ ((n) => (n.DOCUMENT = "doc", n.HEADING = "heading", n.PARAGRAPH = "paragraph", n.QUOTE = "blockquote", n.OL_LIST = "ordered_list", n.UL_LIST = "bullet_list", n.LIST_ITEM = "list_item", n.CODE_BLOCK = "code_block", n.HR = "horizontal_rule", n.BR = "hard_break", n.IMAGE = "image", n.EMOJI = "emoji", n.COMPONENT = "blok", n))(v || {}), T = /* @__PURE__ */ ((n) => (n.BOLD = "bold", n.STRONG = "strong", n.STRIKE = "strike", n.UNDERLINE = "underline", n.ITALIC = "italic", n.CODE = "code", n.LINK = "link", n.ANCHOR = "anchor", n.STYLED = "styled", n.SUPERSCRIPT = "superscript", n.SUBSCRIPT = "subscript", n.TEXT_STYLE = "textStyle", n.HIGHLIGHT = "highlight", n))(T || {}), G = /* @__PURE__ */ ((n) => (n.TEXT = "text", n))(G || {}), I = /* @__PURE__ */ ((n) => (n.URL = "url", n.STORY = "story", n.ASSET = "asset", n.EMAIL = "email", n))(I || {});
936
- const Pe = [
937
+ var v = /* @__PURE__ */ ((r) => (r.DOCUMENT = "doc", r.HEADING = "heading", r.PARAGRAPH = "paragraph", r.QUOTE = "blockquote", r.OL_LIST = "ordered_list", r.UL_LIST = "bullet_list", r.LIST_ITEM = "list_item", r.CODE_BLOCK = "code_block", r.HR = "horizontal_rule", r.BR = "hard_break", r.IMAGE = "image", r.EMOJI = "emoji", r.COMPONENT = "blok", r))(v || {}), T = /* @__PURE__ */ ((r) => (r.BOLD = "bold", r.STRONG = "strong", r.STRIKE = "strike", r.UNDERLINE = "underline", r.ITALIC = "italic", r.CODE = "code", r.LINK = "link", r.ANCHOR = "anchor", r.STYLED = "styled", r.SUPERSCRIPT = "superscript", r.SUBSCRIPT = "subscript", r.TEXT_STYLE = "textStyle", r.HIGHLIGHT = "highlight", r))(T || {}), G = /* @__PURE__ */ ((r) => (r.TEXT = "text", r))(G || {}), I = /* @__PURE__ */ ((r) => (r.URL = "url", r.STORY = "story", r.ASSET = "asset", r.EMAIL = "email", r))(I || {});
938
+ const Le = [
937
939
  "area",
938
940
  "base",
939
941
  "br",
@@ -948,39 +950,39 @@ const Pe = [
948
950
  "source",
949
951
  "track",
950
952
  "wbr"
951
- ], Ne = (n = {}) => Object.keys(n).map((e) => `${e}="${n[e]}"`).join(" "), Me = (n = {}) => Object.keys(n).map((e) => `${e}: ${n[e]}`).join("; ");
952
- function He(n) {
953
- return n.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
953
+ ], Pe = (r = {}) => Object.keys(r).map((e) => `${e}="${r[e]}"`).join(" "), Ce = (r = {}) => Object.keys(r).map((e) => `${e}: ${r[e]}`).join("; ");
954
+ function Ne(r) {
955
+ return r.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
954
956
  }
955
- const B = (n) => Object.fromEntries(Object.entries(n).filter(([e, t]) => t !== void 0));
956
- function q(n, e = {}, t) {
957
- const r = Ne(e), s = r ? `${n} ${r}` : n, o = Array.isArray(t) ? t.join("") : t || "";
958
- if (n) {
959
- if (Pe.includes(n))
960
- return `<${s}>`;
957
+ const B = (r) => Object.fromEntries(Object.entries(r).filter(([e, t]) => t !== void 0));
958
+ function q(r, e = {}, t) {
959
+ const s = Pe(e), n = s ? `${r} ${s}` : r, o = Array.isArray(t) ? t.join("") : t || "";
960
+ if (r) {
961
+ if (Le.includes(r))
962
+ return `<${n}>`;
961
963
  } else return o;
962
- return `<${s}>${o}</${n}>`;
964
+ return `<${n}>${o}</${r}>`;
963
965
  }
964
- function Be(n = {}) {
966
+ function ze(r = {}) {
965
967
  let e = 0;
966
968
  const {
967
969
  renderFn: t = q,
968
- textFn: r = He,
969
- resolvers: s = {},
970
+ textFn: s = Ne,
971
+ resolvers: n = {},
970
972
  optimizeImages: o = !1,
971
973
  keyedResolvers: i = !1
972
- } = n, l = t !== q, a = (c) => (g) => {
974
+ } = r, l = t !== q, a = (c) => (g) => {
973
975
  const f = g.attrs || {};
974
976
  return i && (f.key = `${c}-${e}`), t(c, f, g.children || null);
975
977
  }, h = (c) => {
976
978
  const { src: g, alt: f, title: k, srcset: R, sizes: $ } = c.attrs || {};
977
- let w = g, S = {};
979
+ let w = g, E = {};
978
980
  if (o) {
979
- const { src: W, attrs: X } = Ce(g, o);
980
- w = W, S = X;
981
+ const { src: W, attrs: X } = Ae(g, o);
982
+ w = W, E = X;
981
983
  }
982
- i && (S = {
983
- ...S,
984
+ i && (E = {
985
+ ...E,
984
986
  key: `img-${e}`
985
987
  });
986
988
  const Y = {
@@ -989,7 +991,7 @@ function Be(n = {}) {
989
991
  title: k,
990
992
  srcset: R,
991
993
  sizes: $,
992
- ...S
994
+ ...E
993
995
  };
994
996
  return t("img", B(Y));
995
997
  }, u = (c) => {
@@ -1014,21 +1016,21 @@ function Be(n = {}) {
1014
1016
  }, m = (c) => t("pre", {
1015
1017
  ...c.attrs,
1016
1018
  key: `code-${e}`
1017
- }, t("code", { key: `code-${e}` }, c.children || "")), b = (c, g = !1) => ({ text: f, attrs: k }) => {
1018
- const { class: R, id: $, ...w } = k || {}, S = g ? {
1019
+ }, t("code", { key: `code-${e}` }, c.children || "")), y = (c, g = !1) => ({ text: f, attrs: k }) => {
1020
+ const { class: R, id: $, ...w } = k || {}, E = g ? {
1019
1021
  class: R,
1020
1022
  id: $,
1021
- style: Me(w) || void 0
1023
+ style: Ce(w) || void 0
1022
1024
  } : k || {};
1023
- return i && (S.key = `${c}-${e}`), t(c, B(S), f);
1024
- }, y = (c) => C(c), _ = (c) => {
1025
+ return i && (E.key = `${c}-${e}`), t(c, B(E), f);
1026
+ }, b = (c) => P(c), _ = (c) => {
1025
1027
  const { marks: g, ...f } = c;
1026
1028
  return "text" in c ? g ? g.reduce(
1027
- (k, R) => y({ ...R, text: k }),
1029
+ (k, R) => b({ ...R, text: k }),
1028
1030
  // Fix: Ensure render function returns a string
1029
- y({ ...f, children: f.children })
1031
+ b({ ...f, children: f.children })
1030
1032
  // Fix: Cast children to string
1031
- ) : r(f.text) : "";
1033
+ ) : s(f.text) : "";
1032
1034
  }, j = (c) => {
1033
1035
  const { linktype: g, href: f, anchor: k, ...R } = c.attrs || {};
1034
1036
  let $ = "";
@@ -1074,17 +1076,17 @@ function Be(n = {}) {
1074
1076
  [G.TEXT, _],
1075
1077
  [T.LINK, j],
1076
1078
  [T.ANCHOR, j],
1077
- [T.STYLED, b("span", !0)],
1078
- [T.BOLD, b("strong")],
1079
- [T.TEXT_STYLE, b("span", !0)],
1080
- [T.ITALIC, b("em")],
1081
- [T.UNDERLINE, b("u")],
1082
- [T.STRIKE, b("s")],
1083
- [T.CODE, b("code")],
1084
- [T.SUPERSCRIPT, b("sup")],
1085
- [T.SUBSCRIPT, b("sub")],
1086
- [T.HIGHLIGHT, b("mark")],
1087
- ...Object.entries(s).map(([c, g]) => [c, g])
1079
+ [T.STYLED, y("span", !0)],
1080
+ [T.BOLD, y("strong")],
1081
+ [T.TEXT_STYLE, y("span", !0)],
1082
+ [T.ITALIC, y("em")],
1083
+ [T.UNDERLINE, y("u")],
1084
+ [T.STRIKE, y("s")],
1085
+ [T.CODE, y("code")],
1086
+ [T.SUPERSCRIPT, y("sup")],
1087
+ [T.SUBSCRIPT, y("sub")],
1088
+ [T.HIGHLIGHT, y("mark")],
1089
+ ...Object.entries(n).map(([c, g]) => [c, g])
1088
1090
  ]);
1089
1091
  function x(c) {
1090
1092
  e += 1;
@@ -1093,91 +1095,91 @@ function Be(n = {}) {
1093
1095
  return console.error("<Storyblok>", `No resolver found for node type ${c.type}`), "";
1094
1096
  if (c.type === "text")
1095
1097
  return g(c);
1096
- const f = c.content ? c.content.map(C) : void 0;
1098
+ const f = c.content ? c.content.map(P) : void 0;
1097
1099
  return g({
1098
1100
  ...c,
1099
1101
  children: f
1100
1102
  // Fix: Update the type of 'children' to Node[]
1101
1103
  });
1102
1104
  }
1103
- function C(c) {
1105
+ function P(c) {
1104
1106
  return c.type === "doc" ? l ? c.content.map(x) : c.content.map(x).join("") : Array.isArray(c) ? c.map(x) : x(c);
1105
1107
  }
1106
1108
  return {
1107
- render: C
1109
+ render: P
1108
1110
  };
1109
1111
  }
1110
1112
  let N, M = "https://app.storyblok.com/f/storyblok-v2-latest.js";
1111
- const qe = (n, e, t = {}) => {
1112
- var r;
1113
- const s = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = new URL((r = window.location) == null ? void 0 : r.href).searchParams.get(
1113
+ const De = (r, e, t = {}) => {
1114
+ var s;
1115
+ const n = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = new URL((s = window.location) == null ? void 0 : s.href).searchParams.get(
1114
1116
  "_storyblok"
1115
- ), i = o !== null && +o === n;
1116
- if (!(!s || !i)) {
1117
- if (!n) {
1117
+ ), i = o !== null && +o === r;
1118
+ if (!(!n || !i)) {
1119
+ if (!r) {
1118
1120
  console.warn("Story ID is not defined. Please provide a valid ID.");
1119
1121
  return;
1120
1122
  }
1121
1123
  window.storyblokRegisterEvent(() => {
1122
1124
  new window.StoryblokBridge(t).on(["input", "published", "change"], (l) => {
1123
1125
  var a;
1124
- l && (l.action === "input" && ((a = l.story) == null ? void 0 : a.id) === n ? e(l.story) : (l.action === "change" || l.action === "published") && l.storyId === n && window.location.reload());
1126
+ l && (l.action === "input" && ((a = l.story) == null ? void 0 : a.id) === r ? e(l.story) : (l.action === "change" || l.action === "published") && l.storyId === r && window.location.reload());
1125
1127
  });
1126
1128
  });
1127
1129
  }
1128
- }, V = (n, e) => {
1129
- n.addNode("blok", (t) => {
1130
- let r = "";
1131
- return t.attrs.body.forEach((s) => {
1132
- r += e(s.component, s);
1130
+ }, V = (r, e) => {
1131
+ r.addNode("blok", (t) => {
1132
+ let s = "";
1133
+ return t.attrs.body.forEach((n) => {
1134
+ s += e(n.component, n);
1133
1135
  }), {
1134
- html: r
1136
+ html: s
1135
1137
  };
1136
1138
  });
1137
- }, Fe = (n = {}) => {
1139
+ }, Be = (r = {}) => {
1138
1140
  var e, t;
1139
1141
  const {
1140
- bridge: r,
1141
- accessToken: s,
1142
+ bridge: s,
1143
+ accessToken: n,
1142
1144
  use: o = [],
1143
1145
  apiOptions: i = {},
1144
1146
  richText: l = {},
1145
1147
  bridgeUrl: a
1146
- } = n;
1147
- i.accessToken = i.accessToken || s;
1148
- const h = { bridge: r, apiOptions: i };
1148
+ } = r;
1149
+ i.accessToken = i.accessToken || n;
1150
+ const h = { bridge: s, apiOptions: i };
1149
1151
  let u = {};
1150
1152
  o.forEach((m) => {
1151
1153
  u = { ...u, ...m(h) };
1152
1154
  }), a && (M = a);
1153
1155
  const d = !(typeof window > "u") && ((t = (e = window.location) == null ? void 0 : e.search) == null ? void 0 : t.includes("_storyblok_tk"));
1154
- return r !== !1 && d && F(M), N = new L(l.schema), l.resolver && V(N, l.resolver), u;
1155
- }, Ue = (n) => {
1156
+ return s !== !1 && d && F(M), N = new L(l.schema), l.resolver && V(N, l.resolver), u;
1157
+ }, Me = (r) => {
1156
1158
  var e;
1157
- return !n || !((e = n == null ? void 0 : n.content) != null && e.some((t) => t.content || t.type === "blok" || t.type === "horizontal_rule"));
1158
- }, Ge = (n, e, t) => {
1159
- let r = t || N;
1160
- if (!r) {
1159
+ return !r || !((e = r == null ? void 0 : r.content) != null && e.some((t) => t.content || t.type === "blok" || t.type === "horizontal_rule"));
1160
+ }, qe = (r, e, t) => {
1161
+ let s = t || N;
1162
+ if (!s) {
1161
1163
  console.error(
1162
1164
  "Please initialize the Storyblok SDK before calling the renderRichText function"
1163
1165
  );
1164
1166
  return;
1165
1167
  }
1166
- return Ue(n) ? "" : (e && (r = new L(e.schema), e.resolver && V(r, e.resolver)), r.render(n, {}, !1));
1167
- }, Ve = () => F(M);
1168
+ return Me(r) ? "" : (e && (s = new L(e.schema), e.resolver && V(s, e.resolver)), s.render(r, {}, !1));
1169
+ }, Fe = () => F(M);
1168
1170
  export {
1169
1171
  v as BlockTypes,
1170
1172
  T as MarkTypes,
1171
1173
  L as RichTextResolver,
1172
1174
  je as RichTextSchema,
1173
1175
  G as TextTypes,
1174
- ze as apiPlugin,
1175
- Ue as isRichTextEmpty,
1176
- Ve as loadStoryblokBridge,
1177
- qe as registerStoryblokBridge,
1178
- Ge as renderRichText,
1179
- Be as richTextResolver,
1180
- De as storyblokEditable,
1181
- Fe as storyblokInit,
1182
- qe as useStoryblokBridge
1176
+ Ue as apiPlugin,
1177
+ Me as isRichTextEmpty,
1178
+ Fe as loadStoryblokBridge,
1179
+ De as registerStoryblokBridge,
1180
+ qe as renderRichText,
1181
+ ze as richTextResolver,
1182
+ He as storyblokEditable,
1183
+ Be as storyblokInit,
1184
+ De as useStoryblokBridge
1183
1185
  };