@storyblok/js 3.1.8 → 3.2.0

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,42 +1,52 @@
1
+ /**
2
+ * name: @storyblok/js
3
+ * (c) 2024
4
+ * description: SDK to integrate Storyblok into your project using JavaScript.
5
+ * author: undefined
6
+ */
1
7
  let H = !1;
2
- const U = [], q = (i) => new Promise((e, t) => {
8
+ const U = [], F = (i) => new Promise((e, t) => {
3
9
  if (typeof window > "u" || (window.storyblokRegisterEvent = (r) => {
4
10
  if (window.location === window.parent.location) {
5
11
  console.warn("You are not in Draft Mode or in the Visual Editor.");
6
12
  return;
7
13
  }
8
14
  H ? r() : U.push(r);
9
- }, document.getElementById("storyblok-javascript-bridge"))) return;
15
+ }, document.getElementById("storyblok-javascript-bridge")))
16
+ return;
10
17
  const s = document.createElement("script");
11
18
  s.async = !0, s.src = i, s.id = "storyblok-javascript-bridge", s.onerror = (r) => t(r), s.onload = (r) => {
12
- U.forEach((n) => n()), H = !0, e(r);
19
+ U.forEach((o) => o()), H = !0, e(r);
13
20
  }, document.getElementsByTagName("head")[0].appendChild(s);
14
21
  });
15
- var X = Object.defineProperty, W = (i, e, t) => e in i ? X(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, p = (i, e, t) => W(i, typeof e != "symbol" ? e + "" : e, t);
16
- class Q extends Error {
22
+ var Q = Object.defineProperty, Z = (i, e, t) => e in i ? Q(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, p = (i, e, t) => Z(i, typeof e != "symbol" ? e + "" : e, t);
23
+ class ee extends Error {
17
24
  constructor(e) {
18
25
  super(e), this.name = "AbortError";
19
26
  }
20
27
  }
21
- function Z(i, e, t) {
28
+ function te(i, e, t) {
22
29
  if (!Number.isFinite(e))
23
30
  throw new TypeError("Expected `limit` to be a finite number");
24
31
  if (!Number.isFinite(t))
25
32
  throw new TypeError("Expected `interval` to be a finite number");
26
33
  const s = [];
27
- let r = [], n = 0, o = !1;
34
+ let r = [], o = 0, n = !1;
28
35
  const l = async () => {
29
- n++;
36
+ o++;
30
37
  const c = s.shift();
31
- if (c) {
32
- const d = await i(...c.args);
33
- c.resolve(d);
34
- }
38
+ if (c)
39
+ try {
40
+ const d = await i(...c.args);
41
+ c.resolve(d);
42
+ } catch (d) {
43
+ c.reject(d);
44
+ }
35
45
  const u = setTimeout(() => {
36
- n--, s.length > 0 && l(), r = r.filter((d) => d !== u);
46
+ o--, s.length > 0 && l(), r = r.filter((d) => d !== u);
37
47
  }, t);
38
48
  r.includes(u) || r.push(u);
39
- }, a = (...c) => o ? Promise.reject(
49
+ }, a = (...c) => n ? Promise.reject(
40
50
  new Error(
41
51
  "Throttled function is already aborted and not accepting new promises"
42
52
  )
@@ -45,15 +55,15 @@ function Z(i, e, t) {
45
55
  resolve: u,
46
56
  reject: d,
47
57
  args: c
48
- }), n < e && l();
58
+ }), o < e && l();
49
59
  });
50
60
  return a.abort = () => {
51
- o = !0, r.forEach(clearTimeout), r = [], s.forEach(
52
- (c) => c.reject(() => new Q("Throttle function aborted"))
61
+ n = !0, r.forEach(clearTimeout), r = [], s.forEach(
62
+ (c) => c.reject(() => new ee("Throttle function aborted"))
53
63
  ), s.length = 0;
54
64
  }, a;
55
65
  }
56
- let O = class {
66
+ class A {
57
67
  constructor() {
58
68
  p(this, "isCDNUrl", (e = "") => e.includes("/cdn/")), p(this, "getOptionsPage", (e, t = 25, s = 1) => ({
59
69
  ...e,
@@ -61,7 +71,7 @@ let O = class {
61
71
  page: s
62
72
  })), 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) => {
63
73
  const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
64
- return this.arrayFrom(s, (n, o) => o * r + e);
74
+ return this.arrayFrom(s, (o, n) => n * r + e);
65
75
  }), p(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), p(this, "flatMap", (e = [], t) => e.map(t).reduce((s, r) => [...s, ...r], [])), p(this, "escapeHTML", function(e) {
66
76
  const t = {
67
77
  "&": "&amp;",
@@ -70,7 +80,7 @@ let O = class {
70
80
  '"': "&quot;",
71
81
  "'": "&#39;"
72
82
  }, s = /[&<>"']/g, r = new RegExp(s.source);
73
- return e && r.test(e) ? e.replace(s, (n) => t[n]) : e;
83
+ return e && r.test(e) ? e.replace(s, (o) => t[o]) : e;
74
84
  });
75
85
  }
76
86
  /**
@@ -82,16 +92,16 @@ let O = class {
82
92
  */
83
93
  stringify(e, t, s) {
84
94
  const r = [];
85
- for (const n in e) {
86
- if (!Object.prototype.hasOwnProperty.call(e, n))
95
+ for (const o in e) {
96
+ if (!Object.prototype.hasOwnProperty.call(e, o))
87
97
  continue;
88
- const o = e[n], l = s ? "" : encodeURIComponent(n);
98
+ const n = e[o], l = s ? "" : encodeURIComponent(o);
89
99
  let a;
90
- typeof o == "object" ? a = this.stringify(
91
- o,
100
+ typeof n == "object" ? a = this.stringify(
101
+ n,
92
102
  t ? t + encodeURIComponent(`[${l}]`) : l,
93
- Array.isArray(o)
94
- ) : a = `${t ? t + encodeURIComponent(`[${l}]`) : l}=${encodeURIComponent(o)}`, r.push(a);
103
+ Array.isArray(n)
104
+ ) : a = `${t ? t + encodeURIComponent(`[${l}]`) : l}=${encodeURIComponent(n)}`, r.push(a);
95
105
  }
96
106
  return r.join("&");
97
107
  }
@@ -101,35 +111,35 @@ let O = class {
101
111
  * @return {string} The base URL of the region
102
112
  */
103
113
  getRegionURL(e) {
104
- const t = "api.storyblok.com", s = "api-us.storyblok.com", r = "app.storyblokchina.cn", n = "api-ap.storyblok.com", o = "api-ca.storyblok.com";
114
+ const t = "api.storyblok.com", s = "api-us.storyblok.com", r = "app.storyblokchina.cn", o = "api-ap.storyblok.com", n = "api-ca.storyblok.com";
105
115
  switch (e) {
106
116
  case "us":
107
117
  return s;
108
118
  case "cn":
109
119
  return r;
110
120
  case "ap":
111
- return n;
112
- case "ca":
113
121
  return o;
122
+ case "ca":
123
+ return n;
114
124
  default:
115
125
  return t;
116
126
  }
117
127
  }
118
- };
119
- const ee = function(i, e) {
128
+ }
129
+ const se = function(i, e) {
120
130
  const t = {};
121
131
  for (const s in i) {
122
132
  const r = i[s];
123
133
  e.includes(s) && r !== null && (t[s] = r);
124
134
  }
125
135
  return t;
126
- }, te = (i) => i === "email", se = () => ({
136
+ }, re = (i) => i === "email", ie = () => ({
127
137
  singleTag: "hr"
128
- }), re = () => ({
138
+ }), oe = () => ({
129
139
  tag: "blockquote"
130
- }), ie = () => ({
140
+ }), ne = () => ({
131
141
  tag: "ul"
132
- }), ne = (i) => ({
142
+ }), ae = (i) => ({
133
143
  tag: [
134
144
  "pre",
135
145
  {
@@ -137,24 +147,24 @@ const ee = function(i, e) {
137
147
  attrs: i.attrs
138
148
  }
139
149
  ]
140
- }), oe = () => ({
150
+ }), le = () => ({
141
151
  singleTag: "br"
142
- }), ae = (i) => ({
152
+ }), ce = (i) => ({
143
153
  tag: `h${i.attrs.level}`
144
- }), le = (i) => ({
154
+ }), he = (i) => ({
145
155
  singleTag: [
146
156
  {
147
157
  tag: "img",
148
- attrs: ee(i.attrs, ["src", "alt", "title"])
158
+ attrs: se(i.attrs, ["src", "alt", "title"])
149
159
  }
150
160
  ]
151
- }), ce = () => ({
161
+ }), ue = () => ({
152
162
  tag: "li"
153
- }), he = () => ({
163
+ }), de = () => ({
154
164
  tag: "ol"
155
- }), ue = () => ({
165
+ }), pe = () => ({
156
166
  tag: "p"
157
- }), de = (i) => ({
167
+ }), ge = (i) => ({
158
168
  tag: [
159
169
  {
160
170
  tag: "span",
@@ -165,25 +175,25 @@ const ee = function(i, e) {
165
175
  }
166
176
  }
167
177
  ]
168
- }), pe = () => ({
178
+ }), fe = () => ({
169
179
  tag: "b"
170
- }), ge = () => ({
180
+ }), me = () => ({
171
181
  tag: "s"
172
- }), fe = () => ({
182
+ }), ye = () => ({
173
183
  tag: "u"
174
- }), me = () => ({
184
+ }), be = () => ({
175
185
  tag: "strong"
176
- }), ye = () => ({
186
+ }), ke = () => ({
177
187
  tag: "code"
178
- }), be = () => ({
188
+ }), ve = () => ({
179
189
  tag: "i"
180
- }), ke = (i) => {
190
+ }), $e = (i) => {
181
191
  if (!i.attrs)
182
192
  return {
183
193
  tag: ""
184
194
  };
185
- const e = new O().escapeHTML, t = { ...i.attrs }, { linktype: s = "url" } = i.attrs;
186
- if (delete t.linktype, t.href && (t.href = e(i.attrs.href || "")), te(s) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
195
+ const e = new A().escapeHTML, t = { ...i.attrs }, { linktype: s = "url" } = i.attrs;
196
+ if (delete t.linktype, t.href && (t.href = e(i.attrs.href || "")), re(s) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
187
197
  for (const r in t.custom)
188
198
  t[r] = t.custom[r];
189
199
  delete t.custom;
@@ -196,25 +206,25 @@ const ee = function(i, e) {
196
206
  }
197
207
  ]
198
208
  };
199
- }, ve = (i) => ({
209
+ }, Te = (i) => ({
200
210
  tag: [
201
211
  {
202
212
  tag: "span",
203
213
  attrs: i.attrs
204
214
  }
205
215
  ]
206
- }), $e = () => ({
216
+ }), we = () => ({
207
217
  tag: "sub"
208
- }), Te = () => ({
218
+ }), Re = () => ({
209
219
  tag: "sup"
210
- }), we = (i) => ({
220
+ }), Se = (i) => ({
211
221
  tag: [
212
222
  {
213
223
  tag: "span",
214
224
  attrs: i.attrs
215
225
  }
216
226
  ]
217
- }), Re = (i) => {
227
+ }), _e = (i) => {
218
228
  var e;
219
229
  return (e = i.attrs) != null && e.color ? {
220
230
  tag: [
@@ -228,7 +238,7 @@ const ee = function(i, e) {
228
238
  } : {
229
239
  tag: ""
230
240
  };
231
- }, Se = (i) => {
241
+ }, Ee = (i) => {
232
242
  var e;
233
243
  return (e = i.attrs) != null && e.color ? {
234
244
  tag: [
@@ -242,36 +252,36 @@ const ee = function(i, e) {
242
252
  } : {
243
253
  tag: ""
244
254
  };
245
- }, _e = {
255
+ }, je = {
246
256
  nodes: {
247
- horizontal_rule: se,
248
- blockquote: re,
249
- bullet_list: ie,
250
- code_block: ne,
251
- hard_break: oe,
252
- heading: ae,
253
- image: le,
254
- list_item: ce,
255
- ordered_list: he,
256
- paragraph: ue,
257
- emoji: de
257
+ horizontal_rule: ie,
258
+ blockquote: oe,
259
+ bullet_list: ne,
260
+ code_block: ae,
261
+ hard_break: le,
262
+ heading: ce,
263
+ image: he,
264
+ list_item: ue,
265
+ ordered_list: de,
266
+ paragraph: pe,
267
+ emoji: ge
258
268
  },
259
269
  marks: {
260
- bold: pe,
261
- strike: ge,
262
- underline: fe,
263
- strong: me,
264
- code: ye,
265
- italic: be,
266
- link: ke,
267
- styled: ve,
268
- subscript: $e,
269
- superscript: Te,
270
- anchor: we,
271
- highlight: Re,
272
- textStyle: Se
273
- }
274
- }, Ee = function(i) {
270
+ bold: fe,
271
+ strike: me,
272
+ underline: ye,
273
+ strong: be,
274
+ code: ke,
275
+ italic: ve,
276
+ link: $e,
277
+ styled: Te,
278
+ subscript: we,
279
+ superscript: Re,
280
+ anchor: Se,
281
+ highlight: _e,
282
+ textStyle: Ee
283
+ }
284
+ }, Ie = function(i) {
275
285
  const e = {
276
286
  "&": "&amp;",
277
287
  "<": "&lt;",
@@ -282,9 +292,9 @@ const ee = function(i, e) {
282
292
  return i && s.test(i) ? i.replace(t, (r) => e[r]) : i;
283
293
  };
284
294
  let z = !1;
285
- class Ie {
295
+ class xe {
286
296
  constructor(e) {
287
- p(this, "marks"), p(this, "nodes"), e || (e = _e), this.marks = e.marks || [], this.nodes = e.nodes || [];
297
+ p(this, "marks"), p(this, "nodes"), e || (e = je), this.marks = e.marks || [], this.nodes = e.nodes || [];
288
298
  }
289
299
  addNode(e, t) {
290
300
  this.nodes[e] = t;
@@ -297,8 +307,8 @@ class Ie {
297
307
  "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/"
298
308
  ), z = !0), e && e.content && Array.isArray(e.content)) {
299
309
  let r = "";
300
- return e.content.forEach((n) => {
301
- r += this.renderNode(n);
310
+ return e.content.forEach((o) => {
311
+ r += this.renderNode(o);
302
312
  }), t.optimizeImages ? this.optimizeImages(r, t.optimizeImages) : r;
303
313
  }
304
314
  return console.warn(
@@ -329,9 +339,9 @@ class Ie {
329
339
  ), "";
330
340
  }
331
341
  optimizeImages(e, t) {
332
- let s = 0, r = 0, n = "", o = "";
333
- 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}" `, r = 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 && (o += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (o += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-F]{6}/gi) || t.filters.fill === "transparent") && (o += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (o += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (o += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (o += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (o += `:rotate(${t.filters.rotate})`), o.length > 0 && (o = `/filters${o}`))), n.length > 0 && (e = e.replace(/<img/g, `<img ${n.trim()}`));
334
- const l = s > 0 || r > 0 || o.length > 0 ? `${s}x${r}${o}` : "";
342
+ let s = 0, r = 0, o = "", n = "";
343
+ 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}" `, r = 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 && (n += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (n += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-F]{6}/gi) || t.filters.fill === "transparent") && (n += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (n += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (n += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (n += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (n += `:rotate(${t.filters.rotate})`), n.length > 0 && (n = `/filters${n}`))), o.length > 0 && (e = e.replace(/<img/g, `<img ${o.trim()}`));
344
+ const l = s > 0 || r > 0 || n.length > 0 ? `${s}x${r}${n}` : "";
335
345
  return e = e.replace(
336
346
  /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,
337
347
  `a.storyblok.com/f/$1/$2.$3/m/${l}`
@@ -341,20 +351,20 @@ class Ie {
341
351
  /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g
342
352
  );
343
353
  if (d && d.length > 0) {
344
- const g = {
345
- srcset: (c = t.srcset) == null ? void 0 : c.map((y) => {
346
- if (typeof y == "number")
347
- return `//${d}/m/${y}x0${o} ${y}w`;
348
- if (typeof y == "object" && y.length === 2) {
349
- let R = 0, j = 0;
350
- return typeof y[0] == "number" && (R = y[0]), typeof y[1] == "number" && (j = y[1]), `//${d}/m/${R}x${j}${o} ${R}w`;
354
+ const m = {
355
+ srcset: (c = t.srcset) == null ? void 0 : c.map((b) => {
356
+ if (typeof b == "number")
357
+ return `//${d}/m/${b}x0${n} ${b}w`;
358
+ if (typeof b == "object" && b.length === 2) {
359
+ let S = 0, j = 0;
360
+ return typeof b[0] == "number" && (S = b[0]), typeof b[1] == "number" && (j = b[1]), `//${d}/m/${S}x${j}${n} ${S}w`;
351
361
  }
352
362
  return "";
353
363
  }).join(", "),
354
- sizes: (u = t.sizes) == null ? void 0 : u.map((y) => y).join(", ")
364
+ sizes: (u = t.sizes) == null ? void 0 : u.map((b) => b).join(", ")
355
365
  };
356
- let T = "";
357
- return g.srcset && (T += `srcset="${g.srcset}" `), g.sizes && (T += `sizes="${g.sizes}" `), a.replace(/<img/g, `<img ${T.trim()}`);
366
+ let y = "";
367
+ return m.srcset && (y += `srcset="${m.srcset}" `), m.sizes && (y += `sizes="${m.sizes}" `), a.replace(/<img/g, `<img ${y.trim()}`);
358
368
  }
359
369
  return a;
360
370
  })), e;
@@ -362,15 +372,15 @@ class Ie {
362
372
  renderNode(e) {
363
373
  const t = [];
364
374
  e.marks && e.marks.forEach((r) => {
365
- const n = this.getMatchingMark(r);
366
- n && n.tag !== "" && t.push(this.renderOpeningTag(n.tag));
375
+ const o = this.getMatchingMark(r);
376
+ o && o.tag !== "" && t.push(this.renderOpeningTag(o.tag));
367
377
  });
368
378
  const s = this.getMatchingNode(e);
369
379
  return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
370
380
  t.push(this.renderNode(r));
371
- }) : e.text ? t.push(Ee(e.text)) : s && s.singleTag ? t.push(this.renderTag(s.singleTag, " /")) : s && s.html ? t.push(s.html) : e.type === "emoji" && t.push(this.renderEmoji(e)), s && s.tag && t.push(this.renderClosingTag(s.tag)), e.marks && e.marks.slice(0).reverse().forEach((r) => {
372
- const n = this.getMatchingMark(r);
373
- n && n.tag !== "" && t.push(this.renderClosingTag(n.tag));
381
+ }) : 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((r) => {
382
+ const o = this.getMatchingMark(r);
383
+ o && o.tag !== "" && t.push(this.renderClosingTag(o.tag));
374
384
  }), t.join("");
375
385
  }
376
386
  renderTag(e, t) {
@@ -380,10 +390,10 @@ class Ie {
380
390
  {
381
391
  let r = `<${s.tag}`;
382
392
  if (s.attrs) {
383
- for (const n in s.attrs)
384
- if (Object.prototype.hasOwnProperty.call(s.attrs, n)) {
385
- const o = s.attrs[n];
386
- o !== null && (r += ` ${n}="${o}"`);
393
+ for (const o in s.attrs)
394
+ if (Object.prototype.hasOwnProperty.call(s.attrs, o)) {
395
+ const n = s.attrs[o];
396
+ n !== null && (r += ` ${o}="${n}"`);
387
397
  }
388
398
  }
389
399
  return `${r}${t}>`;
@@ -423,8 +433,8 @@ class Ie {
423
433
  return this.renderTag(t, " /");
424
434
  }
425
435
  }
426
- const L = Ie;
427
- class je {
436
+ const L = xe;
437
+ class Oe {
428
438
  constructor(e) {
429
439
  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 = {};
430
440
  }
@@ -444,7 +454,7 @@ class je {
444
454
  return this.url = e, this.parameters = t, this._methodHandler("put");
445
455
  }
446
456
  delete(e, t) {
447
- return this.url = e, this.parameters = t, this._methodHandler("delete");
457
+ return this.url = e, this.parameters = t ?? {}, this._methodHandler("delete");
448
458
  }
449
459
  async _responseHandler(e) {
450
460
  const t = [], s = {
@@ -463,21 +473,21 @@ class je {
463
473
  async _methodHandler(e) {
464
474
  let t = `${this.baseURL}${this.url}`, s = null;
465
475
  if (e === "get") {
466
- const a = new O();
476
+ const a = new A();
467
477
  t = `${this.baseURL}${this.url}?${a.stringify(
468
478
  this.parameters
469
479
  )}`;
470
480
  } else
471
481
  s = JSON.stringify(this.parameters);
472
- const r = new URL(t), n = new AbortController(), { signal: o } = n;
482
+ const r = new URL(t), o = new AbortController(), { signal: n } = o;
473
483
  let l;
474
- this.timeout && (l = setTimeout(() => n.abort(), this.timeout));
484
+ this.timeout && (l = setTimeout(() => o.abort(), this.timeout));
475
485
  try {
476
486
  const a = await this.fetch(`${r}`, {
477
487
  method: e,
478
488
  headers: this.headers,
479
489
  body: s,
480
- signal: o,
490
+ signal: n,
481
491
  ...this.fetchOptions
482
492
  });
483
493
  this.timeout && clearTimeout(l);
@@ -502,23 +512,23 @@ class je {
502
512
  return new Promise((s, r) => {
503
513
  if (t.test(`${e.status}`))
504
514
  return s(e);
505
- const n = {
515
+ const o = {
506
516
  message: e.statusText,
507
517
  status: e.status,
508
518
  response: Array.isArray(e.data) ? e.data[0] : e.data.error || e.data.slug
509
519
  };
510
- r(n);
520
+ r(o);
511
521
  });
512
522
  }
513
523
  }
514
- const xe = je, B = "SB-Agent", C = {
524
+ const Ae = Oe, D = "SB-Agent", P = {
515
525
  defaultAgentName: "SB-JS-CLIENT",
516
526
  defaultAgentVersion: "SB-Agent-Version",
517
527
  packageVersion: "6.0.0"
518
528
  };
519
- let x = {};
529
+ let O = {};
520
530
  const E = {};
521
- class Oe {
531
+ class Le {
522
532
  /**
523
533
  *
524
534
  * @param config ISbConfig interface
@@ -528,22 +538,22 @@ class Oe {
528
538
  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");
529
539
  let s = e.endpoint || t;
530
540
  if (!s) {
531
- const o = new O().getRegionURL, l = e.https === !1 ? "http" : "https";
532
- e.oauthToken ? s = `${l}://${o(e.region)}/v1` : s = `${l}://${o(e.region)}/v2`;
541
+ const n = new A().getRegionURL, l = e.https === !1 ? "http" : "https";
542
+ e.oauthToken ? s = `${l}://${n(e.region)}/v1` : s = `${l}://${n(e.region)}/v2`;
533
543
  }
534
544
  const r = new Headers();
535
- r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), e.headers && (e.headers.constructor.name === "Headers" ? e.headers.entries().toArray() : Object.entries(e.headers)).forEach(([o, l]) => {
536
- r.set(o, l);
537
- }), r.has(B) || (r.set(B, C.defaultAgentName), r.set(
538
- C.defaultAgentVersion,
539
- C.packageVersion
545
+ r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), e.headers && (e.headers.constructor.name === "Headers" ? e.headers.entries().toArray() : Object.entries(e.headers)).forEach(([n, l]) => {
546
+ r.set(n, l);
547
+ }), r.has(D) || (r.set(D, P.defaultAgentName), r.set(
548
+ P.defaultAgentVersion,
549
+ P.packageVersion
540
550
  ));
541
- let n = 5;
542
- e.oauthToken && (r.set("Authorization", e.oauthToken), n = 3), e.rateLimit && (n = 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 = Z(
551
+ let o = 5;
552
+ e.oauthToken && (r.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(
543
553
  this.throttledRequest.bind(this),
544
- n,
554
+ o,
545
555
  1e3
546
- ), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new O(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new xe({
556
+ ), 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({
547
557
  baseURL: s,
548
558
  timeout: e.timeout || 0,
549
559
  headers: r,
@@ -567,30 +577,30 @@ class Oe {
567
577
  factoryParamOptions(e, t) {
568
578
  return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
569
579
  }
570
- makeRequest(e, t, s, r, n) {
571
- const o = this.factoryParamOptions(
580
+ makeRequest(e, t, s, r, o) {
581
+ const n = this.factoryParamOptions(
572
582
  e,
573
583
  this.helpers.getOptionsPage(t, s, r)
574
584
  );
575
- return this.cacheResponse(e, o, void 0, n);
585
+ return this.cacheResponse(e, n, void 0, o);
576
586
  }
577
587
  get(e, t, s) {
578
588
  t || (t = {});
579
- const r = `/${e}`, n = this.factoryParamOptions(r, t);
580
- return this.cacheResponse(r, n, void 0, s);
589
+ const r = `/${e}`, o = this.factoryParamOptions(r, t);
590
+ return this.cacheResponse(r, o, void 0, s);
581
591
  }
582
592
  async getAll(e, t, s, r) {
583
- const n = (t == null ? void 0 : t.per_page) || 25, o = `/${e}`.replace(/\/$/, ""), l = s ?? o.substring(o.lastIndexOf("/") + 1), a = 1, c = await this.makeRequest(
584
- o,
585
- t,
593
+ const o = (t == null ? void 0 : t.per_page) || 25, n = `/${e}`.replace(/\/$/, ""), l = s ?? n.substring(n.lastIndexOf("/") + 1), a = 1, c = await this.makeRequest(
586
594
  n,
595
+ t,
596
+ o,
587
597
  a,
588
598
  r
589
- ), u = c.total ? Math.ceil(c.total / n) : 1, d = await this.helpers.asyncMap(
599
+ ), u = c.total ? Math.ceil(c.total / o) : 1, d = await this.helpers.asyncMap(
590
600
  this.helpers.range(a, u),
591
- (g) => this.makeRequest(o, t, n, g + 1, r)
601
+ (m) => this.makeRequest(n, t, o, m + 1, r)
592
602
  );
593
- return this.helpers.flatMap([c, ...d], (g) => Object.values(g.data[l]));
603
+ return this.helpers.flatMap([c, ...d], (m) => Object.values(m.data[l]));
594
604
  }
595
605
  post(e, t, s) {
596
606
  const r = `/${e}`;
@@ -605,6 +615,7 @@ class Oe {
605
615
  );
606
616
  }
607
617
  delete(e, t, s) {
618
+ t || (t = {});
608
619
  const r = `/${e}`;
609
620
  return Promise.resolve(
610
621
  this.throttle("delete", r, t, s)
@@ -639,34 +650,65 @@ class Oe {
639
650
  * @returns string | object
640
651
  */
641
652
  getStoryReference(e, t) {
642
- return this.relations[e][t] ? (this.stringifiedStoriesCache[t] || (this.stringifiedStoriesCache[t] = JSON.stringify(
643
- this.relations[e][t]
644
- )), JSON.parse(this.stringifiedStoriesCache[t])) : t;
653
+ return this.relations[e][t] ? JSON.parse(this.stringifiedStoriesCache[t] || JSON.stringify(this.relations[e][t])) : t;
654
+ }
655
+ /**
656
+ * Resolves a field's value by replacing UUIDs with their corresponding story references
657
+ * @param jtree - The JSON tree object containing the field to resolve
658
+ * @param treeItem - The key of the field to resolve
659
+ * @param resolveId - The unique identifier for the current resolution context
660
+ *
661
+ * This method handles both single string UUIDs and arrays of UUIDs:
662
+ * - For single strings: directly replaces the UUID with the story reference
663
+ * - For arrays: maps through each UUID and replaces with corresponding story references
664
+ */
665
+ _resolveField(e, t, s) {
666
+ const r = e[t];
667
+ typeof r == "string" ? e[t] = this.getStoryReference(s, r) : Array.isArray(r) && (e[t] = r.map(
668
+ (o) => this.getStoryReference(s, o)
669
+ ).filter(Boolean));
645
670
  }
671
+ /**
672
+ * Inserts relations into the JSON tree by resolving references
673
+ * @param jtree - The JSON tree object to process
674
+ * @param treeItem - The current field being processed
675
+ * @param fields - The relation patterns to resolve (string or array of strings)
676
+ * @param resolveId - The unique identifier for the current resolution context
677
+ *
678
+ * This method handles two types of relation patterns:
679
+ * 1. Nested relations: matches fields that end with the current field name
680
+ * Example: If treeItem is "event_type", it matches patterns like "*.event_type"
681
+ *
682
+ * 2. Direct component relations: matches exact component.field patterns
683
+ * Example: "event.event_type" for component "event" and field "event_type"
684
+ *
685
+ * The method supports both string and array formats for the fields parameter,
686
+ * allowing flexible specification of relation patterns.
687
+ */
646
688
  _insertRelations(e, t, s, r) {
647
- s.includes(`${e.component}.${t}`) && (typeof e[t] == "string" ? e[t] = this.getStoryReference(r, e[t]) : Array.isArray(e[t]) && (e[t] = e[t].map((n) => this.getStoryReference(r, n)).filter(Boolean)));
689
+ if (Array.isArray(s) ? s.find((n) => n.endsWith(`.${t}`)) : s.endsWith(`.${t}`)) {
690
+ this._resolveField(e, t, r);
691
+ return;
692
+ }
693
+ const o = e.component ? `${e.component}.${t}` : t;
694
+ (Array.isArray(s) ? s.includes(o) : s === o) && this._resolveField(e, t, r);
648
695
  }
696
+ /**
697
+ * Recursively traverses and resolves relations in the story content tree
698
+ * @param story - The story object containing the content to process
699
+ * @param fields - The relation patterns to resolve
700
+ * @param resolveId - The unique identifier for the current resolution context
701
+ */
649
702
  iterateTree(e, t, s) {
650
- const r = (n) => {
651
- if (n != null) {
652
- if (n.constructor === Array)
653
- for (let o = 0; o < n.length; o++)
654
- r(n[o]);
655
- else if (n.constructor === Object) {
656
- if (n._stopResolving)
657
- return;
658
- for (const o in n)
659
- (n.component && n._uid || n.type === "link") && (this._insertRelations(
660
- n,
661
- o,
662
- t,
663
- s
664
- ), this._insertLinks(
665
- n,
666
- o,
667
- s
668
- )), r(n[o]);
669
- }
703
+ const r = (o, n = "") => {
704
+ if (!(!o || o._stopResolving)) {
705
+ if (Array.isArray(o))
706
+ o.forEach((l, a) => r(l, `${n}[${a}]`));
707
+ else if (typeof o == "object")
708
+ for (const l in o) {
709
+ const a = n ? `${n}.${l}` : l;
710
+ (o.component && o._uid || o.type === "link") && (this._insertRelations(o, l, t, s), this._insertLinks(o, l, s)), r(o[l], a);
711
+ }
670
712
  }
671
713
  };
672
714
  r(e.content);
@@ -674,17 +716,17 @@ class Oe {
674
716
  async resolveLinks(e, t, s) {
675
717
  let r = [];
676
718
  if (e.link_uuids) {
677
- const n = e.link_uuids.length, o = [], l = 50;
678
- for (let a = 0; a < n; a += l) {
679
- const c = Math.min(n, a + l);
680
- o.push(e.link_uuids.slice(a, c));
719
+ const o = e.link_uuids.length, n = [], l = 50;
720
+ for (let a = 0; a < o; a += l) {
721
+ const c = Math.min(o, a + l);
722
+ n.push(e.link_uuids.slice(a, c));
681
723
  }
682
- for (let a = 0; a < o.length; a++)
724
+ for (let a = 0; a < n.length; a++)
683
725
  (await this.getStories({
684
726
  per_page: l,
685
727
  language: t.language,
686
728
  version: t.version,
687
- by_uuids: o[a].join(",")
729
+ by_uuids: n[a].join(",")
688
730
  })).data.stories.forEach(
689
731
  (c) => {
690
732
  r.push(c);
@@ -692,9 +734,9 @@ class Oe {
692
734
  );
693
735
  } else
694
736
  r = e.links;
695
- r.forEach((n) => {
696
- this.links[s][n.uuid] = {
697
- ...n,
737
+ r.forEach((o) => {
738
+ this.links[s][o.uuid] = {
739
+ ...o,
698
740
  _stopResolving: !0
699
741
  };
700
742
  });
@@ -702,26 +744,26 @@ class Oe {
702
744
  async resolveRelations(e, t, s) {
703
745
  let r = [];
704
746
  if (e.rel_uuids) {
705
- const n = e.rel_uuids.length, o = [], l = 50;
706
- for (let a = 0; a < n; a += l) {
707
- const c = Math.min(n, a + l);
708
- o.push(e.rel_uuids.slice(a, c));
747
+ const o = e.rel_uuids.length, n = [], l = 50;
748
+ for (let a = 0; a < o; a += l) {
749
+ const c = Math.min(o, a + l);
750
+ n.push(e.rel_uuids.slice(a, c));
709
751
  }
710
- for (let a = 0; a < o.length; a++)
752
+ for (let a = 0; a < n.length; a++)
711
753
  (await this.getStories({
712
754
  per_page: l,
713
755
  language: t.language,
714
756
  version: t.version,
715
- by_uuids: o[a].join(","),
757
+ by_uuids: n[a].join(","),
716
758
  excluding_fields: t.excluding_fields
717
759
  })).data.stories.forEach((c) => {
718
760
  r.push(c);
719
761
  });
720
762
  } else
721
763
  r = e.rels;
722
- r && r.length > 0 && r.forEach((n) => {
723
- this.relations[s][n.uuid] = {
724
- ...n,
764
+ r && r.length > 0 && r.forEach((o) => {
765
+ this.relations[s][o.uuid] = {
766
+ ...o,
725
767
  _stopResolving: !0
726
768
  };
727
769
  });
@@ -736,23 +778,23 @@ class Oe {
736
778
  *
737
779
  */
738
780
  async resolveStories(e, t, s) {
739
- var r, n;
740
- let o = [];
741
- if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (o = t.resolve_relations.split(",")), await this.resolveRelations(e, t, s)), t.resolve_links && ["1", "story", "url", "link"].includes(t.resolve_links) && ((r = e.links) != null && r.length || (n = e.link_uuids) != null && n.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
781
+ var r, o;
782
+ let n = [];
783
+ if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (n = t.resolve_relations.split(",")), await this.resolveRelations(e, t, s)), t.resolve_links && ["1", "story", "url", "link"].includes(t.resolve_links) && ((r = e.links) != null && r.length || (o = e.link_uuids) != null && o.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
742
784
  for (const l in this.relations[s])
743
785
  this.iterateTree(
744
786
  this.relations[s][l],
745
- o,
787
+ n,
746
788
  s
747
789
  );
748
- e.story ? this.iterateTree(e.story, o, s) : e.stories.forEach((l) => {
749
- this.iterateTree(l, o, s);
790
+ e.story ? this.iterateTree(e.story, n, s) : e.stories.forEach((l) => {
791
+ this.iterateTree(l, n, s);
750
792
  }), this.stringifiedStoriesCache = {}, delete this.links[s], delete this.relations[s];
751
793
  }
752
794
  async cacheResponse(e, t, s, r) {
753
- const n = this.helpers.stringify({ url: e, params: t }), o = this.cacheProvider();
795
+ const o = this.helpers.stringify({ url: e, params: t }), n = this.cacheProvider();
754
796
  if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e !== "/cdn/spaces/me") {
755
- const l = await o.get(n);
797
+ const l = await n.get(o);
756
798
  if (l)
757
799
  return Promise.resolve(l);
758
800
  }
@@ -772,10 +814,10 @@ class Oe {
772
814
  perPage: u.headers["per-page"] ? Number.parseInt(u.headers["per-page"]) : 0,
773
815
  total: u.headers["per-page"] ? Number.parseInt(u.headers.total) : 0
774
816
  })), d.data.story || d.data.stories) {
775
- const g = this.resolveCounter = ++this.resolveCounter % 1e3;
776
- await this.resolveStories(d.data, t, `${g}`);
817
+ const m = this.resolveCounter = ++this.resolveCounter % 1e3;
818
+ await this.resolveStories(d.data, t, `${m}`);
777
819
  }
778
- return t.version === "published" && e !== "/cdn/spaces/me" && await o.set(n, d), d.data.cv && t.token && E[t.token] !== d.data.cv && (await this.flushCache(), E[t.token] = d.data.cv), l(d);
820
+ return t.version === "published" && e !== "/cdn/spaces/me" && await n.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);
779
821
  } catch (u) {
780
822
  if (u.response && u.status === 429 && (s = typeof s > "u" ? 0 : s + 1, s < this.maxRetries))
781
823
  return console.log(
@@ -805,16 +847,16 @@ class Oe {
805
847
  case "memory":
806
848
  return {
807
849
  get(e) {
808
- return Promise.resolve(x[e]);
850
+ return Promise.resolve(O[e]);
809
851
  },
810
852
  getAll() {
811
- return Promise.resolve(x);
853
+ return Promise.resolve(O);
812
854
  },
813
855
  set(e, t) {
814
- return x[e] = t, Promise.resolve(void 0);
856
+ return O[e] = t, Promise.resolve(void 0);
815
857
  },
816
858
  flush() {
817
- return x = {}, Promise.resolve(void 0);
859
+ return O = {}, Promise.resolve(void 0);
818
860
  }
819
861
  };
820
862
  case "custom":
@@ -843,14 +885,14 @@ class Oe {
843
885
  }
844
886
  const ze = (i = {}) => {
845
887
  const { apiOptions: e } = i;
846
- if (!e.accessToken) {
888
+ if (!e || !e.accessToken) {
847
889
  console.error(
848
890
  "You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication"
849
891
  );
850
892
  return;
851
893
  }
852
- return { storyblokApi: new Oe(e) };
853
- }, Be = (i) => {
894
+ return { storyblokApi: new Le(e) };
895
+ }, De = (i) => {
854
896
  if (typeof i != "object" || typeof i._editable > "u")
855
897
  return {};
856
898
  try {
@@ -859,31 +901,31 @@ const ze = (i = {}) => {
859
901
  );
860
902
  return e ? {
861
903
  "data-blok-c": JSON.stringify(e),
862
- "data-blok-uid": e.id + "-" + e.uid
904
+ "data-blok-uid": `${e.id}-${e.uid}`
863
905
  } : {};
864
906
  } catch {
865
907
  return {};
866
908
  }
867
909
  };
868
- function Le(i, e) {
910
+ function Ce(i, e) {
869
911
  if (!e)
870
912
  return { src: i, attrs: {} };
871
913
  let t = 0, s = 0;
872
- const r = {}, n = [];
873
- function o(a, c, u, d, g) {
874
- typeof a != "number" || a <= c || a >= u ? console.warn(`[StoryblokRichText] - ${d.charAt(0).toUpperCase() + d.slice(1)} value must be a number between ${c} and ${u} (inclusive)`) : g.push(`${d}(${a})`);
914
+ const r = {}, o = [];
915
+ function n(a, c, u, d, m) {
916
+ typeof a != "number" || a <= c || a >= u ? console.warn(`[StoryblokRichText] - ${d.charAt(0).toUpperCase() + d.slice(1)} value must be a number between ${c} and ${u} (inclusive)`) : m.push(`${d}(${a})`);
875
917
  }
876
918
  if (typeof e == "object") {
877
919
  if (typeof e.width == "number" && e.width > 0 ? (r.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 ? (r.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) && (r.loading = e.loading), e.class && (r.class = e.class), e.filters) {
878
- const { filters: a } = e || {}, { blur: c, brightness: u, fill: d, format: g, grayscale: T, quality: y, rotate: R } = a || {};
879
- c && o(c, 0, 100, "blur", n), y && o(y, 0, 100, "quality", n), u && o(u, 0, 100, "brightness", n), d && n.push(`fill(${d})`), T && n.push("grayscale()"), R && [0, 90, 180, 270].includes(e.filters.rotate || 0) && n.push(`rotate(${R})`), g && ["webp", "png", "jpeg"].includes(g) && n.push(`format(${g})`);
920
+ const { filters: a } = e || {}, { blur: c, brightness: u, fill: d, format: m, grayscale: y, quality: b, rotate: S } = a || {};
921
+ c && n(c, 0, 100, "blur", o), b && n(b, 0, 100, "quality", o), u && n(u, 0, 100, "brightness", o), d && o.push(`fill(${d})`), y && o.push("grayscale()"), S && [0, 90, 180, 270].includes(e.filters.rotate || 0) && o.push(`rotate(${S})`), m && ["webp", "png", "jpeg"].includes(m) && o.push(`format(${m})`);
880
922
  }
881
923
  e.srcset && (r.srcset = e.srcset.map((a) => {
882
924
  if (typeof a == "number")
883
- return `${i}/m/${a}x0/${n.length > 0 ? `filters:${n.join(":")}` : ""} ${a}w`;
925
+ return `${i}/m/${a}x0/${o.length > 0 ? `filters:${o.join(":")}` : ""} ${a}w`;
884
926
  if (Array.isArray(a) && a.length === 2) {
885
927
  const [c, u] = a;
886
- return `${i}/m/${c}x${u}/${n.length > 0 ? `filters:${n.join(":")}` : ""} ${c}w`;
928
+ return `${i}/m/${c}x${u}/${o.length > 0 ? `filters:${o.join(":")}` : ""} ${c}w`;
887
929
  } else {
888
930
  console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");
889
931
  return;
@@ -891,13 +933,13 @@ function Le(i, e) {
891
933
  }).join(", ")), e.sizes && (r.sizes = e.sizes.join(", "));
892
934
  }
893
935
  let l = `${i}/m/`;
894
- return t > 0 && s > 0 && (l = `${l}${t}x${s}/`), n.length > 0 && (l = `${l}filters:${n.join(":")}`), {
936
+ return t > 0 && s > 0 && (l = `${l}${t}x${s}/`), o.length > 0 && (l = `${l}filters:${o.join(":")}`), {
895
937
  src: l,
896
938
  attrs: r
897
939
  };
898
940
  }
899
- var k = /* @__PURE__ */ ((i) => (i.DOCUMENT = "doc", i.HEADING = "heading", i.PARAGRAPH = "paragraph", i.QUOTE = "blockquote", i.OL_LIST = "ordered_list", i.UL_LIST = "bullet_list", i.LIST_ITEM = "list_item", i.CODE_BLOCK = "code_block", i.HR = "horizontal_rule", i.BR = "hard_break", i.IMAGE = "image", i.EMOJI = "emoji", i.COMPONENT = "blok", i))(k || {}), v = /* @__PURE__ */ ((i) => (i.BOLD = "bold", i.STRONG = "strong", i.STRIKE = "strike", i.UNDERLINE = "underline", i.ITALIC = "italic", i.CODE = "code", i.LINK = "link", i.ANCHOR = "anchor", i.STYLED = "styled", i.SUPERSCRIPT = "superscript", i.SUBSCRIPT = "subscript", i.TEXT_STYLE = "textStyle", i.HIGHLIGHT = "highlight", i))(v || {}), G = /* @__PURE__ */ ((i) => (i.TEXT = "text", i))(G || {}), I = /* @__PURE__ */ ((i) => (i.URL = "url", i.STORY = "story", i.ASSET = "asset", i.EMAIL = "email", i))(I || {});
900
- const Ae = [
941
+ var $ = /* @__PURE__ */ ((i) => (i.DOCUMENT = "doc", i.HEADING = "heading", i.PARAGRAPH = "paragraph", i.QUOTE = "blockquote", i.OL_LIST = "ordered_list", i.UL_LIST = "bullet_list", i.LIST_ITEM = "list_item", i.CODE_BLOCK = "code_block", i.HR = "horizontal_rule", i.BR = "hard_break", i.IMAGE = "image", i.EMOJI = "emoji", i.COMPONENT = "blok", i))($ || {}), T = /* @__PURE__ */ ((i) => (i.BOLD = "bold", i.STRONG = "strong", i.STRIKE = "strike", i.UNDERLINE = "underline", i.ITALIC = "italic", i.CODE = "code", i.LINK = "link", i.ANCHOR = "anchor", i.STYLED = "styled", i.SUPERSCRIPT = "superscript", i.SUBSCRIPT = "subscript", i.TEXT_STYLE = "textStyle", i.HIGHLIGHT = "highlight", i))(T || {}), G = /* @__PURE__ */ ((i) => (i.TEXT = "text", i))(G || {}), I = /* @__PURE__ */ ((i) => (i.URL = "url", i.STORY = "story", i.ASSET = "asset", i.EMAIL = "email", i))(I || {});
942
+ const Pe = [
901
943
  "area",
902
944
  "base",
903
945
  "br",
@@ -912,224 +954,236 @@ const Ae = [
912
954
  "source",
913
955
  "track",
914
956
  "wbr"
915
- ], Ce = (i = {}) => Object.keys(i).map((e) => `${e}="${i[e]}"`).join(" "), Pe = (i = {}) => Object.keys(i).map((e) => `${e}: ${i[e]}`).join("; ");
916
- function Ne(i) {
957
+ ], Ne = (i = {}) => Object.keys(i).map((e) => `${e}="${i[e]}"`).join(" "), Me = (i = {}) => Object.keys(i).map((e) => `${e}: ${i[e]}`).join("; ");
958
+ function He(i) {
917
959
  return i.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
918
960
  }
919
- const D = (i) => Object.fromEntries(Object.entries(i).filter(([e, t]) => t !== void 0));
920
- function Me(i, e = {}, t) {
921
- const s = Ce(e), r = s ? `${i} ${s}` : i;
922
- return Ae.includes(i) ? `<${r}>` : `<${r}>${Array.isArray(t) ? t.join("") : t || ""}</${i}>`;
961
+ const B = (i) => Object.fromEntries(Object.entries(i).filter(([e, t]) => t !== void 0));
962
+ function q(i, e = {}, t) {
963
+ const s = Ne(e), r = s ? `${i} ${s}` : i, o = Array.isArray(t) ? t.join("") : t || "";
964
+ if (i) {
965
+ if (Pe.includes(i))
966
+ return `<${r}>`;
967
+ } else return o;
968
+ return `<${r}>${o}</${i}>`;
923
969
  }
924
- function De(i = {}) {
970
+ function Be(i = {}) {
925
971
  let e = 0;
926
972
  const {
927
- renderFn: t = Me,
928
- textFn: s = Ne,
973
+ renderFn: t = q,
974
+ textFn: s = He,
929
975
  resolvers: r = {},
930
- optimizeImages: n = !1,
931
- keyedResolvers: o = !1
932
- } = i, l = (h) => (f) => {
933
- const m = f.attrs || {};
934
- return o && (m.key = `${h}-${e}`), t(h, m, f.children || null);
935
- }, a = (h) => {
936
- const { src: f, alt: m, title: b, srcset: w, sizes: $ } = h.attrs || {};
937
- let S = f, _ = {};
938
- if (n) {
939
- const { src: K, attrs: Y } = Le(f, n);
940
- S = K, _ = Y;
976
+ optimizeImages: o = !1,
977
+ keyedResolvers: n = !1
978
+ } = i, l = t !== q, a = (h) => (g) => {
979
+ const f = g.attrs || {};
980
+ return n && (f.key = `${h}-${e}`), t(h, f, g.children || null);
981
+ }, c = (h) => {
982
+ const { src: g, alt: f, title: k, srcset: R, sizes: v } = h.attrs || {};
983
+ let w = g, _ = {};
984
+ if (o) {
985
+ const { src: W, attrs: X } = Ce(g, o);
986
+ w = W, _ = X;
941
987
  }
942
- o && (_ = {
988
+ n && (_ = {
943
989
  ..._,
944
990
  key: `img-${e}`
945
991
  });
946
- const J = {
947
- src: S,
948
- alt: m,
949
- title: b,
950
- srcset: w,
951
- sizes: $,
992
+ const Y = {
993
+ src: w,
994
+ alt: f,
995
+ title: k,
996
+ srcset: R,
997
+ sizes: v,
952
998
  ..._
953
999
  };
954
- return t("img", D(J));
955
- }, c = (h) => {
956
- const { level: f, ...m } = h.attrs || {}, b = {
957
- ...m
958
- };
959
- return o && (b.key = `h${f}-${e}`), t(`h${f}`, b, h.children);
1000
+ return t("img", B(Y));
960
1001
  }, u = (h) => {
961
- var f, m, b, w;
962
- const $ = t("img", {
963
- src: (f = h.attrs) == null ? void 0 : f.fallbackImage,
964
- alt: (m = h.attrs) == null ? void 0 : m.alt,
1002
+ const { level: g, ...f } = h.attrs || {}, k = {
1003
+ ...f
1004
+ };
1005
+ return n && (k.key = `h${g}-${e}`), t(`h${g}`, k, h.children);
1006
+ }, d = (h) => {
1007
+ var g, f, k, R;
1008
+ const v = t("img", {
1009
+ src: (g = h.attrs) == null ? void 0 : g.fallbackImage,
1010
+ alt: (f = h.attrs) == null ? void 0 : f.alt,
965
1011
  style: "width: 1.25em; height: 1.25em; vertical-align: text-top",
966
1012
  draggable: "false",
967
1013
  loading: "lazy"
968
- }), S = {
1014
+ }), w = {
969
1015
  "data-type": "emoji",
970
- "data-name": (b = h.attrs) == null ? void 0 : b.name,
971
- "data-emoji": (w = h.attrs) == null ? void 0 : w.emoji
1016
+ "data-name": (k = h.attrs) == null ? void 0 : k.name,
1017
+ "data-emoji": (R = h.attrs) == null ? void 0 : R.emoji
972
1018
  };
973
- return o && (S.key = `emoji-${e}`), t("span", S, $);
974
- }, d = (h) => t("pre", {
1019
+ return n && (w.key = `emoji-${e}`), t("span", w, v);
1020
+ }, m = (h) => t("pre", {
975
1021
  ...h.attrs,
976
1022
  key: `code-${e}`
977
- }, t("code", { key: `code-${e}` }, h.children || "")), g = (h, f = !1) => ({ text: m, attrs: b }) => {
978
- const { class: w, id: $, ...S } = b || {}, _ = f ? {
979
- class: w,
980
- id: $,
981
- style: Pe(S) || void 0
982
- } : b || {};
983
- return o && (_.key = `${h}-${e}`), t(h, D(_), m);
984
- }, T = (h) => A(h), y = (h) => {
985
- const { marks: f, ...m } = h;
986
- return "text" in h ? f ? f.reduce(
987
- (b, w) => T({ ...w, text: b }),
1023
+ }, t("code", { key: `code-${e}` }, h.children || "")), y = (h, g = !1) => ({ text: f, attrs: k }) => {
1024
+ const { class: R, id: v, ...w } = k || {}, _ = g ? {
1025
+ class: R,
1026
+ id: v,
1027
+ style: Me(w) || void 0
1028
+ } : k || {};
1029
+ return n && (_.key = `${h}-${e}`), t(h, B(_), f);
1030
+ }, b = (h) => C(h), S = (h) => {
1031
+ const { marks: g, ...f } = h;
1032
+ return "text" in h ? g ? g.reduce(
1033
+ (k, R) => b({ ...R, text: k }),
988
1034
  // Fix: Ensure render function returns a string
989
- T({ ...m, children: m.children })
1035
+ b({ ...f, children: f.children })
990
1036
  // Fix: Cast children to string
991
- ) : s(m.text) : "";
992
- }, R = (h) => {
993
- const { linktype: f, href: m, anchor: b, ...w } = h.attrs || {};
994
- let $ = "";
995
- switch (f) {
1037
+ ) : s(f.text) : "";
1038
+ }, j = (h) => {
1039
+ const { linktype: g, href: f, anchor: k, ...R } = h.attrs || {};
1040
+ let v = "";
1041
+ switch (g) {
996
1042
  case I.ASSET:
997
1043
  case I.URL:
998
- $ = m;
1044
+ v = f;
999
1045
  break;
1000
1046
  case I.EMAIL:
1001
- $ = `mailto:${m}`;
1047
+ v = `mailto:${f}`;
1002
1048
  break;
1003
1049
  case I.STORY:
1004
- $ = m;
1050
+ v = f, k && (v = `${v}#${k}`);
1051
+ break;
1052
+ default:
1053
+ v = f;
1005
1054
  break;
1006
1055
  }
1007
- return b && ($ = `${$}#${b}`), t("a", { ...w, href: $, key: `a-${e}` }, h.text);
1008
- }, j = (h) => {
1009
- var f, m;
1056
+ const w = { ...R };
1057
+ return v && (w.href = v), n && (w.key = `a-${e}`), t("a", w, h.text);
1058
+ }, J = (h) => {
1059
+ var g, f;
1010
1060
  return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), t("span", {
1011
- blok: (f = h == null ? void 0 : h.attrs) == null ? void 0 : f.body[0],
1012
- id: (m = h.attrs) == null ? void 0 : m.id,
1061
+ blok: (g = h == null ? void 0 : h.attrs) == null ? void 0 : g.body[0],
1062
+ id: (f = h.attrs) == null ? void 0 : f.id,
1013
1063
  key: `component-${e}`,
1014
1064
  style: "display: none"
1015
1065
  });
1016
- }, V = new Map([
1017
- [k.DOCUMENT, l("div")],
1018
- [k.HEADING, c],
1019
- [k.PARAGRAPH, l("p")],
1020
- [k.UL_LIST, l("ul")],
1021
- [k.OL_LIST, l("ol")],
1022
- [k.LIST_ITEM, l("li")],
1023
- [k.IMAGE, a],
1024
- [k.EMOJI, u],
1025
- [k.CODE_BLOCK, d],
1026
- [k.HR, l("hr")],
1027
- [k.BR, l("br")],
1028
- [k.QUOTE, l("blockquote")],
1029
- [k.COMPONENT, j],
1030
- [G.TEXT, y],
1031
- [v.LINK, R],
1032
- [v.ANCHOR, R],
1033
- [v.STYLED, g("span", !0)],
1034
- [v.BOLD, g("strong")],
1035
- [v.TEXT_STYLE, g("span", !0)],
1036
- [v.ITALIC, g("em")],
1037
- [v.UNDERLINE, g("u")],
1038
- [v.STRIKE, g("s")],
1039
- [v.CODE, g("code")],
1040
- [v.SUPERSCRIPT, g("sup")],
1041
- [v.SUBSCRIPT, g("sub")],
1042
- [v.HIGHLIGHT, g("mark")],
1043
- ...Object.entries(r).map(([h, f]) => [h, f])
1066
+ }, K = new Map([
1067
+ [$.DOCUMENT, a("")],
1068
+ [$.HEADING, u],
1069
+ [$.PARAGRAPH, a("p")],
1070
+ [$.UL_LIST, a("ul")],
1071
+ [$.OL_LIST, a("ol")],
1072
+ [$.LIST_ITEM, a("li")],
1073
+ [$.IMAGE, c],
1074
+ [$.EMOJI, d],
1075
+ [$.CODE_BLOCK, m],
1076
+ [$.HR, a("hr")],
1077
+ [$.BR, a("br")],
1078
+ [$.QUOTE, a("blockquote")],
1079
+ [$.COMPONENT, J],
1080
+ [G.TEXT, S],
1081
+ [T.LINK, j],
1082
+ [T.ANCHOR, j],
1083
+ [T.STYLED, y("span", !0)],
1084
+ [T.BOLD, y("strong")],
1085
+ [T.TEXT_STYLE, y("span", !0)],
1086
+ [T.ITALIC, y("em")],
1087
+ [T.UNDERLINE, y("u")],
1088
+ [T.STRIKE, y("s")],
1089
+ [T.CODE, y("code")],
1090
+ [T.SUPERSCRIPT, y("sup")],
1091
+ [T.SUBSCRIPT, y("sub")],
1092
+ [T.HIGHLIGHT, y("mark")],
1093
+ ...Object.entries(r).map(([h, g]) => [h, g])
1044
1094
  ]);
1045
- function M(h) {
1095
+ function x(h) {
1046
1096
  e += 1;
1047
- const f = V.get(h.type);
1048
- if (!f)
1097
+ const g = K.get(h.type);
1098
+ if (!g)
1049
1099
  return console.error("<Storyblok>", `No resolver found for node type ${h.type}`), "";
1050
1100
  if (h.type === "text")
1051
- return f(h);
1052
- const m = h.content ? h.content.map(A) : void 0;
1053
- return f({
1101
+ return g(h);
1102
+ const f = h.content ? h.content.map(C) : void 0;
1103
+ return g({
1054
1104
  ...h,
1055
- children: m
1105
+ children: f
1056
1106
  // Fix: Update the type of 'children' to Node[]
1057
1107
  });
1058
1108
  }
1059
- function A(h) {
1060
- return Array.isArray(h) ? h.map(M) : M(h);
1109
+ function C(h) {
1110
+ return h.type === "doc" ? l ? h.content.map(x) : h.content.map(x).join("") : Array.isArray(h) ? h.map(x) : x(h);
1061
1111
  }
1062
1112
  return {
1063
- render: A
1113
+ render: C
1064
1114
  };
1065
1115
  }
1066
- let P, N = "https://app.storyblok.com/f/storyblok-v2-latest.js";
1116
+ let N, M = "https://app.storyblok.com/f/storyblok-v2-latest.js";
1067
1117
  const qe = (i, e, t = {}) => {
1068
1118
  var l;
1069
- const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = +new URL((l = window.location) == null ? void 0 : l.href).searchParams.get(
1119
+ const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = new URL((l = window.location) == null ? void 0 : l.href).searchParams.get(
1070
1120
  "_storyblok"
1071
- ) === i;
1072
- if (!(!r || !o)) {
1121
+ ), n = o !== null && +o === i;
1122
+ if (!(!r || !n)) {
1073
1123
  if (!i) {
1074
1124
  console.warn("Story ID is not defined. Please provide a valid ID.");
1075
1125
  return;
1076
1126
  }
1077
1127
  window.storyblokRegisterEvent(() => {
1078
1128
  new window.StoryblokBridge(t).on(["input", "published", "change"], (c) => {
1079
- c.action === "input" && c.story.id === i ? e(c.story) : (c.action === "change" || c.action === "published") && c.storyId === i && window.location.reload();
1129
+ var u;
1130
+ c && (c.action === "input" && ((u = c.story) == null ? void 0 : u.id) === i ? e(c.story) : (c.action === "change" || c.action === "published") && c.storyId === i && window.location.reload());
1080
1131
  });
1081
1132
  });
1082
1133
  }
1083
- }, Ge = (i = {}) => {
1084
- var d, g;
1134
+ }, V = (i, e) => {
1135
+ i.addNode("blok", (t) => {
1136
+ let s = "";
1137
+ return t.attrs.body.forEach((r) => {
1138
+ s += e(r.component, r);
1139
+ }), {
1140
+ html: s
1141
+ };
1142
+ });
1143
+ }, Fe = (i = {}) => {
1144
+ var d, m;
1085
1145
  const {
1086
1146
  bridge: e,
1087
1147
  accessToken: t,
1088
1148
  use: s = [],
1089
1149
  apiOptions: r = {},
1090
- richText: n = {},
1091
- bridgeUrl: o
1150
+ richText: o = {},
1151
+ bridgeUrl: n
1092
1152
  } = i;
1093
1153
  r.accessToken = r.accessToken || t;
1094
1154
  const l = { bridge: e, apiOptions: r };
1095
1155
  let a = {};
1096
- s.forEach((T) => {
1097
- a = { ...a, ...T(l) };
1098
- }), o && (N = o);
1099
- const u = !(typeof window > "u") && ((g = (d = window.location) == null ? void 0 : d.search) == null ? void 0 : g.includes("_storyblok_tk"));
1100
- return e !== !1 && u && q(N), P = new L(n.schema), n.resolver && F(P, n.resolver), a;
1101
- }, F = (i, e) => {
1102
- i.addNode("blok", (t) => {
1103
- let s = "";
1104
- return t.attrs.body.forEach((r) => {
1105
- s += e(r.component, r);
1106
- }), {
1107
- html: s
1108
- };
1109
- });
1110
- }, He = (i) => !i || !(i != null && i.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")), Fe = (i, e, t) => {
1111
- let s = t || P;
1156
+ s.forEach((y) => {
1157
+ a = { ...a, ...y(l) };
1158
+ }), n && (M = n);
1159
+ const u = !(typeof window > "u") && ((m = (d = window.location) == null ? void 0 : d.search) == null ? void 0 : m.includes("_storyblok_tk"));
1160
+ return e !== !1 && u && F(M), N = new L(o.schema), o.resolver && V(N, o.resolver), a;
1161
+ }, Ue = (i) => {
1162
+ var e;
1163
+ return !i || !((e = i == null ? void 0 : i.content) != null && e.some((t) => t.content || t.type === "blok" || t.type === "horizontal_rule"));
1164
+ }, Ge = (i, e, t) => {
1165
+ let s = t || N;
1112
1166
  if (!s) {
1113
1167
  console.error(
1114
1168
  "Please initialize the Storyblok SDK before calling the renderRichText function"
1115
1169
  );
1116
1170
  return;
1117
1171
  }
1118
- return He(i) ? "" : (e && (s = new L(e.schema), e.resolver && F(s, e.resolver)), s.render(i, {}, !1));
1119
- }, Ve = () => q(N);
1172
+ return Ue(i) ? "" : (e && (s = new L(e.schema), e.resolver && V(s, e.resolver)), s.render(i, {}, !1));
1173
+ }, Ve = () => F(M);
1120
1174
  export {
1121
- k as BlockTypes,
1122
- v as MarkTypes,
1175
+ $ as BlockTypes,
1176
+ T as MarkTypes,
1123
1177
  L as RichTextResolver,
1124
- _e as RichTextSchema,
1178
+ je as RichTextSchema,
1125
1179
  G as TextTypes,
1126
1180
  ze as apiPlugin,
1127
- He as isRichTextEmpty,
1181
+ Ue as isRichTextEmpty,
1128
1182
  Ve as loadStoryblokBridge,
1129
1183
  qe as registerStoryblokBridge,
1130
- Fe as renderRichText,
1131
- De as richTextResolver,
1132
- Be as storyblokEditable,
1133
- Ge as storyblokInit,
1184
+ Ge as renderRichText,
1185
+ Be as richTextResolver,
1186
+ De as storyblokEditable,
1187
+ Fe as storyblokInit,
1134
1188
  qe as useStoryblokBridge
1135
1189
  };