@storyblok/js 3.1.6 → 3.1.8

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,64 +1,65 @@
1
- let N = !1;
2
- const M = [], z = (i) => new Promise((e, t) => {
1
+ let H = !1;
2
+ const U = [], q = (i) => new Promise((e, t) => {
3
3
  if (typeof window > "u" || (window.storyblokRegisterEvent = (r) => {
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
- N ? r() : M.push(r);
8
+ H ? r() : U.push(r);
9
9
  }, document.getElementById("storyblok-javascript-bridge"))) return;
10
10
  const s = document.createElement("script");
11
11
  s.async = !0, s.src = i, s.id = "storyblok-javascript-bridge", s.onerror = (r) => t(r), s.onload = (r) => {
12
- M.forEach((n) => n()), N = !0, e(r);
12
+ U.forEach((n) => n()), H = !0, e(r);
13
13
  }, document.getElementsByTagName("head")[0].appendChild(s);
14
14
  });
15
- var F = Object.defineProperty, K = (i, e, t) => e in i ? F(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, p = (i, e, t) => K(i, typeof e != "symbol" ? e + "" : e, t);
16
- function H(i) {
17
- return !(i !== i || i === 1 / 0 || i === -1 / 0);
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 {
17
+ constructor(e) {
18
+ super(e), this.name = "AbortError";
19
+ }
18
20
  }
19
- function Y(i, e, t) {
20
- if (!H(e))
21
+ function Z(i, e, t) {
22
+ if (!Number.isFinite(e))
21
23
  throw new TypeError("Expected `limit` to be a finite number");
22
- if (!H(t))
24
+ if (!Number.isFinite(t))
23
25
  throw new TypeError("Expected `interval` to be a finite number");
24
26
  const s = [];
25
- let r = [], n = 0;
26
- const o = function() {
27
+ let r = [], n = 0, o = !1;
28
+ const l = async () => {
27
29
  n++;
28
- const a = setTimeout(function() {
29
- n--, s.length > 0 && o(), r = r.filter(function(d) {
30
- return d !== a;
31
- });
30
+ const c = s.shift();
31
+ if (c) {
32
+ const d = await i(...c.args);
33
+ c.resolve(d);
34
+ }
35
+ const u = setTimeout(() => {
36
+ n--, s.length > 0 && l(), r = r.filter((d) => d !== u);
32
37
  }, t);
33
- r.indexOf(a) < 0 && r.push(a);
34
- const h = s.shift();
35
- h.resolve(i.apply(h.self, h.args));
36
- }, l = function(...a) {
37
- const h = this;
38
- return new Promise(function(d, u) {
39
- s.push({
40
- resolve: d,
41
- reject: u,
42
- args: a,
43
- self: h
44
- }), n < e && o();
45
- });
46
- };
47
- return l.abort = function() {
48
- r.forEach(clearTimeout), r = [], s.forEach(function(a) {
49
- a.reject(function() {
50
- Error.call(this, "Throttled function aborted"), this.name = "AbortError";
51
- });
52
- }), s.length = 0;
53
- }, l;
38
+ r.includes(u) || r.push(u);
39
+ }, a = (...c) => o ? Promise.reject(
40
+ new Error(
41
+ "Throttled function is already aborted and not accepting new promises"
42
+ )
43
+ ) : new Promise((u, d) => {
44
+ s.push({
45
+ resolve: u,
46
+ reject: d,
47
+ args: c
48
+ }), n < e && l();
49
+ });
50
+ return a.abort = () => {
51
+ o = !0, r.forEach(clearTimeout), r = [], s.forEach(
52
+ (c) => c.reject(() => new Q("Throttle function aborted"))
53
+ ), s.length = 0;
54
+ }, a;
54
55
  }
55
- class x {
56
+ let O = class {
56
57
  constructor() {
57
- p(this, "isCDNUrl", (e = "") => e.indexOf("/cdn/") > -1), p(this, "getOptionsPage", (e, t = 25, s = 1) => ({
58
+ p(this, "isCDNUrl", (e = "") => e.includes("/cdn/")), p(this, "getOptionsPage", (e, t = 25, s = 1) => ({
58
59
  ...e,
59
60
  per_page: t,
60
61
  page: s
61
- })), p(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), p(this, "arrayFrom", (e = 0, t) => [...Array(e)].map(t)), p(this, "range", (e = 0, t = e) => {
62
+ })), 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) => {
62
63
  const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
63
64
  return this.arrayFrom(s, (n, o) => o * r + e);
64
65
  }), 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) {
@@ -68,16 +69,16 @@ class x {
68
69
  ">": "&gt;",
69
70
  '"': "&quot;",
70
71
  "'": "&#39;"
71
- }, s = /[&<>"']/g, r = RegExp(s.source);
72
+ }, s = /[&<>"']/g, r = new RegExp(s.source);
72
73
  return e && r.test(e) ? e.replace(s, (n) => t[n]) : e;
73
74
  });
74
75
  }
75
76
  /**
76
77
  * @method stringify
77
- * @param {Object} params
78
- * @param {String} prefix
79
- * @param {Boolean} isArray
80
- * @return {String} Stringified object
78
+ * @param {object} params
79
+ * @param {string} prefix
80
+ * @param {boolean} isArray
81
+ * @return {string} Stringified object
81
82
  */
82
83
  stringify(e, t, s) {
83
84
  const r = [];
@@ -88,16 +89,16 @@ class x {
88
89
  let a;
89
90
  typeof o == "object" ? a = this.stringify(
90
91
  o,
91
- t ? t + encodeURIComponent("[" + l + "]") : l,
92
+ t ? t + encodeURIComponent(`[${l}]`) : l,
92
93
  Array.isArray(o)
93
- ) : a = (t ? t + encodeURIComponent("[" + l + "]") : l) + "=" + encodeURIComponent(o), r.push(a);
94
+ ) : a = `${t ? t + encodeURIComponent(`[${l}]`) : l}=${encodeURIComponent(o)}`, r.push(a);
94
95
  }
95
96
  return r.join("&");
96
97
  }
97
98
  /**
98
99
  * @method getRegionURL
99
- * @param {String} regionCode region code, could be eu, us, cn, ap or ca
100
- * @return {String} The base URL of the region
100
+ * @param {string} regionCode region code, could be eu, us, cn, ap or ca
101
+ * @return {string} The base URL of the region
101
102
  */
102
103
  getRegionURL(e) {
103
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,21 +115,21 @@ class x {
114
115
  return t;
115
116
  }
116
117
  }
117
- }
118
- const X = function(i, e) {
118
+ };
119
+ const ee = function(i, e) {
119
120
  const t = {};
120
121
  for (const s in i) {
121
122
  const r = i[s];
122
- e.indexOf(s) > -1 && r !== null && (t[s] = r);
123
+ e.includes(s) && r !== null && (t[s] = r);
123
124
  }
124
125
  return t;
125
- }, W = (i) => i === "email", Q = () => ({
126
+ }, te = (i) => i === "email", se = () => ({
126
127
  singleTag: "hr"
127
- }), Z = () => ({
128
+ }), re = () => ({
128
129
  tag: "blockquote"
129
- }), ee = () => ({
130
+ }), ie = () => ({
130
131
  tag: "ul"
131
- }), te = (i) => ({
132
+ }), ne = (i) => ({
132
133
  tag: [
133
134
  "pre",
134
135
  {
@@ -136,24 +137,24 @@ const X = function(i, e) {
136
137
  attrs: i.attrs
137
138
  }
138
139
  ]
139
- }), se = () => ({
140
+ }), oe = () => ({
140
141
  singleTag: "br"
141
- }), re = (i) => ({
142
+ }), ae = (i) => ({
142
143
  tag: `h${i.attrs.level}`
143
- }), ie = (i) => ({
144
+ }), le = (i) => ({
144
145
  singleTag: [
145
146
  {
146
147
  tag: "img",
147
- attrs: X(i.attrs, ["src", "alt", "title"])
148
+ attrs: ee(i.attrs, ["src", "alt", "title"])
148
149
  }
149
150
  ]
150
- }), ne = () => ({
151
+ }), ce = () => ({
151
152
  tag: "li"
152
- }), oe = () => ({
153
+ }), he = () => ({
153
154
  tag: "ol"
154
- }), ae = () => ({
155
+ }), ue = () => ({
155
156
  tag: "p"
156
- }), le = (i) => ({
157
+ }), de = (i) => ({
157
158
  tag: [
158
159
  {
159
160
  tag: "span",
@@ -164,25 +165,25 @@ const X = function(i, e) {
164
165
  }
165
166
  }
166
167
  ]
167
- }), ce = () => ({
168
+ }), pe = () => ({
168
169
  tag: "b"
169
- }), he = () => ({
170
+ }), ge = () => ({
170
171
  tag: "s"
171
- }), ue = () => ({
172
+ }), fe = () => ({
172
173
  tag: "u"
173
- }), de = () => ({
174
+ }), me = () => ({
174
175
  tag: "strong"
175
- }), pe = () => ({
176
+ }), ye = () => ({
176
177
  tag: "code"
177
- }), ge = () => ({
178
+ }), be = () => ({
178
179
  tag: "i"
179
- }), fe = (i) => {
180
+ }), ke = (i) => {
180
181
  if (!i.attrs)
181
182
  return {
182
183
  tag: ""
183
184
  };
184
- const e = new x().escapeHTML, t = { ...i.attrs }, { linktype: s = "url" } = i.attrs;
185
- if (delete t.linktype, t.href && (t.href = e(i.attrs.href || "")), W(s) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
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) {
186
187
  for (const r in t.custom)
187
188
  t[r] = t.custom[r];
188
189
  delete t.custom;
@@ -195,25 +196,25 @@ const X = function(i, e) {
195
196
  }
196
197
  ]
197
198
  };
198
- }, me = (i) => ({
199
+ }, ve = (i) => ({
199
200
  tag: [
200
201
  {
201
202
  tag: "span",
202
203
  attrs: i.attrs
203
204
  }
204
205
  ]
205
- }), ye = () => ({
206
+ }), $e = () => ({
206
207
  tag: "sub"
207
- }), be = () => ({
208
+ }), Te = () => ({
208
209
  tag: "sup"
209
- }), ke = (i) => ({
210
+ }), we = (i) => ({
210
211
  tag: [
211
212
  {
212
213
  tag: "span",
213
214
  attrs: i.attrs
214
215
  }
215
216
  ]
216
- }), ve = (i) => {
217
+ }), Re = (i) => {
217
218
  var e;
218
219
  return (e = i.attrs) != null && e.color ? {
219
220
  tag: [
@@ -227,7 +228,7 @@ const X = function(i, e) {
227
228
  } : {
228
229
  tag: ""
229
230
  };
230
- }, $e = (i) => {
231
+ }, Se = (i) => {
231
232
  var e;
232
233
  return (e = i.attrs) != null && e.color ? {
233
234
  tag: [
@@ -241,49 +242,49 @@ const X = function(i, e) {
241
242
  } : {
242
243
  tag: ""
243
244
  };
244
- }, Te = {
245
+ }, _e = {
245
246
  nodes: {
246
- horizontal_rule: Q,
247
- blockquote: Z,
248
- bullet_list: ee,
249
- code_block: te,
250
- hard_break: se,
251
- heading: re,
252
- image: ie,
253
- list_item: ne,
254
- ordered_list: oe,
255
- paragraph: ae,
256
- emoji: le
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
258
  },
258
259
  marks: {
259
- bold: ce,
260
- strike: he,
261
- underline: ue,
262
- strong: de,
263
- code: pe,
264
- italic: ge,
265
- link: fe,
266
- styled: me,
267
- subscript: ye,
268
- superscript: be,
269
- anchor: ke,
270
- highlight: ve,
271
- textStyle: $e
272
- }
273
- }, Re = function(i) {
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) {
274
275
  const e = {
275
276
  "&": "&amp;",
276
277
  "<": "&lt;",
277
278
  ">": "&gt;",
278
279
  '"': "&quot;",
279
280
  "'": "&#39;"
280
- }, t = /[&<>"']/g, s = RegExp(t.source);
281
+ }, t = /[&<>"']/g, s = new RegExp(t.source);
281
282
  return i && s.test(i) ? i.replace(t, (r) => e[r]) : i;
282
283
  };
283
- let U = !1;
284
- class we {
284
+ let z = !1;
285
+ class Ie {
285
286
  constructor(e) {
286
- p(this, "marks"), p(this, "nodes"), e || (e = Te), this.marks = e.marks || [], this.nodes = e.nodes || [];
287
+ p(this, "marks"), p(this, "nodes"), e || (e = _e), this.marks = e.marks || [], this.nodes = e.nodes || [];
287
288
  }
288
289
  addNode(e, t) {
289
290
  this.nodes[e] = t;
@@ -292,9 +293,9 @@ class we {
292
293
  this.marks[e] = t;
293
294
  }
294
295
  render(e, t = { optimizeImages: !1 }, s = !0) {
295
- if (!U && s && (console.warn(
296
+ if (!z && s && (console.warn(
296
297
  "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/"
297
- ), U = !0), e && e.content && Array.isArray(e.content)) {
298
+ ), z = !0), e && e.content && Array.isArray(e.content)) {
298
299
  let r = "";
299
300
  return e.content.forEach((n) => {
300
301
  r += this.renderNode(n);
@@ -302,57 +303,58 @@ class we {
302
303
  }
303
304
  return console.warn(
304
305
  `The render method must receive an Object with a "content" field.
305
- The "content" field must be an array of nodes as the type ISbRichtext.
306
- ISbRichtext:
307
- content?: ISbRichtext[]
308
- marks?: ISbRichtext[]
309
- attrs?: any
310
- text?: string
311
- type: string
312
-
313
- Example:
314
- {
315
- content: [
316
- {
317
- content: [
318
- {
319
- text: 'Hello World',
320
- type: 'text'
321
- }
322
- ],
323
- type: 'paragraph'
324
- }
325
- ],
326
- type: 'doc'
327
- }`
306
+ The "content" field must be an array of nodes as the type ISbRichtext.
307
+ ISbRichtext:
308
+ content?: ISbRichtext[]
309
+ marks?: ISbRichtext[]
310
+ attrs?: any
311
+ text?: string
312
+ type: string
313
+
314
+ Example:
315
+ {
316
+ content: [
317
+ {
318
+ content: [
319
+ {
320
+ text: 'Hello World',
321
+ type: 'text'
322
+ }
323
+ ],
324
+ type: 'paragraph'
325
+ }
326
+ ],
327
+ type: 'doc'
328
+ }`
328
329
  ), "";
329
330
  }
330
331
  optimizeImages(e, t) {
331
332
  let s = 0, r = 0, n = "", o = "";
332
- 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-Fa-f]{6}/g) || 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()}`));
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()}`));
333
334
  const l = s > 0 || r > 0 || o.length > 0 ? `${s}x${r}${o}` : "";
334
335
  return e = e.replace(
335
- /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,
336
+ /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,
336
337
  `a.storyblok.com/f/$1/$2.$3/m/${l}`
337
338
  ), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (a) => {
338
- var h, d;
339
- const u = a.match(
340
- /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g
339
+ var c, u;
340
+ const d = a.match(
341
+ /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g
341
342
  );
342
- if (u && u.length > 0) {
343
- const m = {
344
- srcset: (h = t.srcset) == null ? void 0 : h.map((y) => {
343
+ if (d && d.length > 0) {
344
+ const g = {
345
+ srcset: (c = t.srcset) == null ? void 0 : c.map((y) => {
345
346
  if (typeof y == "number")
346
- return `//${u}/m/${y}x0${o} ${y}w`;
347
+ return `//${d}/m/${y}x0${o} ${y}w`;
347
348
  if (typeof y == "object" && y.length === 2) {
348
- let w = 0, E = 0;
349
- return typeof y[0] == "number" && (w = y[0]), typeof y[1] == "number" && (E = y[1]), `//${u}/m/${w}x${E}${o} ${w}w`;
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`;
350
351
  }
352
+ return "";
351
353
  }).join(", "),
352
- sizes: (d = t.sizes) == null ? void 0 : d.map((y) => y).join(", ")
354
+ sizes: (u = t.sizes) == null ? void 0 : u.map((y) => y).join(", ")
353
355
  };
354
- let k = "";
355
- return m.srcset && (k += `srcset="${m.srcset}" `), m.sizes && (k += `sizes="${m.sizes}" `), a.replace(/<img/g, `<img ${k.trim()}`);
356
+ let T = "";
357
+ return g.srcset && (T += `srcset="${g.srcset}" `), g.sizes && (T += `sizes="${g.sizes}" `), a.replace(/<img/g, `<img ${T.trim()}`);
356
358
  }
357
359
  return a;
358
360
  })), e;
@@ -366,7 +368,7 @@ class we {
366
368
  const s = this.getMatchingNode(e);
367
369
  return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
368
370
  t.push(this.renderNode(r));
369
- }) : e.text ? t.push(Re(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) => {
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) => {
370
372
  const n = this.getMatchingMark(r);
371
373
  n && n.tag !== "" && t.push(this.renderClosingTag(n.tag));
372
374
  }), t.join("");
@@ -421,8 +423,8 @@ class we {
421
423
  return this.renderTag(t, " /");
422
424
  }
423
425
  }
424
- const j = we;
425
- class Se {
426
+ const L = Ie;
427
+ class je {
426
428
  constructor(e) {
427
429
  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 = {};
428
430
  }
@@ -461,7 +463,7 @@ class Se {
461
463
  async _methodHandler(e) {
462
464
  let t = `${this.baseURL}${this.url}`, s = null;
463
465
  if (e === "get") {
464
- const a = new x();
466
+ const a = new O();
465
467
  t = `${this.baseURL}${this.url}?${a.stringify(
466
468
  this.parameters
467
469
  )}`;
@@ -479,10 +481,10 @@ class Se {
479
481
  ...this.fetchOptions
480
482
  });
481
483
  this.timeout && clearTimeout(l);
482
- const h = await this._responseHandler(
484
+ const c = await this._responseHandler(
483
485
  a
484
486
  );
485
- return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(h)) : this._statusHandler(h);
487
+ return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(c)) : this._statusHandler(c);
486
488
  } catch (a) {
487
489
  return {
488
490
  message: a
@@ -509,35 +511,39 @@ class Se {
509
511
  });
510
512
  }
511
513
  }
512
- const _e = Se, D = "SB-Agent", L = {
514
+ const xe = je, B = "SB-Agent", C = {
513
515
  defaultAgentName: "SB-JS-CLIENT",
514
516
  defaultAgentVersion: "SB-Agent-Version",
515
517
  packageVersion: "6.0.0"
516
518
  };
517
- let I = {};
518
- const S = {};
519
- class Ee {
519
+ let x = {};
520
+ const E = {};
521
+ class Oe {
520
522
  /**
521
523
  *
522
524
  * @param config ISbConfig interface
523
- * @param endpoint string, optional
525
+ * @param pEndpoint string, optional
524
526
  */
525
527
  constructor(e, t) {
526
528
  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");
527
529
  let s = e.endpoint || t;
528
530
  if (!s) {
529
- const o = new x().getRegionURL, l = e.https === !1 ? "http" : "https";
531
+ const o = new O().getRegionURL, l = e.https === !1 ? "http" : "https";
530
532
  e.oauthToken ? s = `${l}://${o(e.region)}/v1` : s = `${l}://${o(e.region)}/v2`;
531
533
  }
532
534
  const r = new Headers();
533
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]) => {
534
536
  r.set(o, l);
535
- }), r.has(D) || (r.set(D, L.defaultAgentName), r.set(
536
- L.defaultAgentVersion,
537
- L.packageVersion
537
+ }), r.has(B) || (r.set(B, C.defaultAgentName), r.set(
538
+ C.defaultAgentVersion,
539
+ C.packageVersion
538
540
  ));
539
541
  let n = 5;
540
- e.oauthToken && (r.set("Authorization", e.oauthToken), n = 3), e.rateLimit && (n = e.rateLimit), e.richTextSchema ? this.richTextResolver = new j(e.richTextSchema) : this.richTextResolver = new j(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = Y(this.throttledRequest, n, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new x(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new _e({
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(
543
+ this.throttledRequest.bind(this),
544
+ n,
545
+ 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({
541
547
  baseURL: s,
542
548
  timeout: e.timeout || 0,
543
549
  headers: r,
@@ -556,7 +562,7 @@ class Ee {
556
562
  });
557
563
  }
558
564
  parseParams(e) {
559
- 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;
565
+ 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;
560
566
  }
561
567
  factoryParamOptions(e, t) {
562
568
  return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
@@ -574,32 +580,35 @@ class Ee {
574
580
  return this.cacheResponse(r, n, void 0, s);
575
581
  }
576
582
  async getAll(e, t, s, r) {
577
- const n = (t == null ? void 0 : t.per_page) || 25, o = `/${e}`, l = o.split("/"), a = s || l[l.length - 1], h = 1, d = await this.makeRequest(
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(
578
584
  o,
579
585
  t,
580
586
  n,
581
- h,
587
+ a,
582
588
  r
583
- ), u = d.total ? Math.ceil(d.total / n) : 1, m = await this.helpers.asyncMap(
584
- this.helpers.range(h, u),
585
- (k) => this.makeRequest(o, t, n, k + 1, r)
586
- );
587
- return this.helpers.flatMap(
588
- [d, ...m],
589
- (k) => Object.values(k.data[a])
589
+ ), u = c.total ? Math.ceil(c.total / n) : 1, d = await this.helpers.asyncMap(
590
+ this.helpers.range(a, u),
591
+ (g) => this.makeRequest(o, t, n, g + 1, r)
590
592
  );
593
+ return this.helpers.flatMap([c, ...d], (g) => Object.values(g.data[l]));
591
594
  }
592
595
  post(e, t, s) {
593
596
  const r = `/${e}`;
594
- return Promise.resolve(this.throttle("post", r, t, s));
597
+ return Promise.resolve(
598
+ this.throttle("post", r, t, s)
599
+ );
595
600
  }
596
601
  put(e, t, s) {
597
602
  const r = `/${e}`;
598
- return Promise.resolve(this.throttle("put", r, t, s));
603
+ return Promise.resolve(
604
+ this.throttle("put", r, t, s)
605
+ );
599
606
  }
600
607
  delete(e, t, s) {
601
608
  const r = `/${e}`;
602
- return Promise.resolve(this.throttle("delete", r, t, s));
609
+ return Promise.resolve(
610
+ this.throttle("delete", r, t, s)
611
+ );
603
612
  }
604
613
  getStories(e, t) {
605
614
  return this._addResolveLevel(e), this.get("cdn/stories", e, t);
@@ -621,7 +630,7 @@ class Ee {
621
630
  }
622
631
  _insertLinks(e, t, s) {
623
632
  const r = e[t];
624
- r && r.fieldtype == "multilink" && r.linktype == "story" && typeof r.id == "string" && this.links[s][r.id] ? r.story = this._cleanCopy(this.links[s][r.id]) : r && r.linktype === "story" && typeof r.uuid == "string" && this.links[s][r.uuid] && (r.story = this._cleanCopy(this.links[s][r.uuid]));
633
+ r && r.fieldtype === "multilink" && r.linktype === "story" && typeof r.id == "string" && this.links[s][r.id] ? r.story = this._cleanCopy(this.links[s][r.id]) : r && r.linktype === "story" && typeof r.uuid == "string" && this.links[s][r.uuid] && (r.story = this._cleanCopy(this.links[s][r.uuid]));
625
634
  }
626
635
  /**
627
636
  *
@@ -635,7 +644,7 @@ class Ee {
635
644
  )), JSON.parse(this.stringifiedStoriesCache[t])) : t;
636
645
  }
637
646
  _insertRelations(e, t, s, r) {
638
- s.indexOf(`${e.component}.${t}`) > -1 && (typeof e[t] == "string" ? e[t] = this.getStoryReference(r, e[t]) : Array.isArray(e[t]) && (e[t] = e[t].map((n) => this.getStoryReference(r, n)).filter(Boolean)));
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)));
639
648
  }
640
649
  iterateTree(e, t, s) {
641
650
  const r = (n) => {
@@ -667,8 +676,8 @@ class Ee {
667
676
  if (e.link_uuids) {
668
677
  const n = e.link_uuids.length, o = [], l = 50;
669
678
  for (let a = 0; a < n; a += l) {
670
- const h = Math.min(n, a + l);
671
- o.push(e.link_uuids.slice(a, h));
679
+ const c = Math.min(n, a + l);
680
+ o.push(e.link_uuids.slice(a, c));
672
681
  }
673
682
  for (let a = 0; a < o.length; a++)
674
683
  (await this.getStories({
@@ -677,8 +686,8 @@ class Ee {
677
686
  version: t.version,
678
687
  by_uuids: o[a].join(",")
679
688
  })).data.stories.forEach(
680
- (h) => {
681
- r.push(h);
689
+ (c) => {
690
+ r.push(c);
682
691
  }
683
692
  );
684
693
  } else
@@ -695,8 +704,8 @@ class Ee {
695
704
  if (e.rel_uuids) {
696
705
  const n = e.rel_uuids.length, o = [], l = 50;
697
706
  for (let a = 0; a < n; a += l) {
698
- const h = Math.min(n, a + l);
699
- o.push(e.rel_uuids.slice(a, h));
707
+ const c = Math.min(n, a + l);
708
+ o.push(e.rel_uuids.slice(a, c));
700
709
  }
701
710
  for (let a = 0; a < o.length; a++)
702
711
  (await this.getStories({
@@ -705,8 +714,8 @@ class Ee {
705
714
  version: t.version,
706
715
  by_uuids: o[a].join(","),
707
716
  excluding_fields: t.excluding_fields
708
- })).data.stories.forEach((h) => {
709
- r.push(h);
717
+ })).data.stories.forEach((c) => {
718
+ r.push(c);
710
719
  });
711
720
  } else
712
721
  r = e.rels;
@@ -729,7 +738,7 @@ class Ee {
729
738
  async resolveStories(e, t, s) {
730
739
  var r, n;
731
740
  let o = [];
732
- 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"].indexOf(t.resolve_links) > -1 && ((r = e.links) != null && r.length || (n = e.link_uuids) != null && n.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
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)
733
742
  for (const l in this.relations[s])
734
743
  this.iterateTree(
735
744
  this.relations[s][l],
@@ -742,32 +751,37 @@ class Ee {
742
751
  }
743
752
  async cacheResponse(e, t, s, r) {
744
753
  const n = this.helpers.stringify({ url: e, params: t }), o = this.cacheProvider();
745
- if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
754
+ if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e !== "/cdn/spaces/me") {
746
755
  const l = await o.get(n);
747
756
  if (l)
748
757
  return Promise.resolve(l);
749
758
  }
750
759
  return new Promise(async (l, a) => {
751
- var h;
760
+ var c;
752
761
  try {
753
- const d = await this.throttle("get", e, t, r);
754
- if (d.status !== 200)
755
- return a(d);
756
- let u = { data: d.data, headers: d.headers };
757
- if ((h = d.headers) != null && h["per-page"] && (u = Object.assign({}, u, {
758
- perPage: d.headers["per-page"] ? parseInt(d.headers["per-page"]) : 0,
759
- total: d.headers["per-page"] ? parseInt(d.headers.total) : 0
760
- })), u.data.story || u.data.stories) {
761
- const m = this.resolveCounter = ++this.resolveCounter % 1e3;
762
- await this.resolveStories(u.data, t, `${m}`);
762
+ const u = await this.throttle(
763
+ "get",
764
+ e,
765
+ t,
766
+ r
767
+ );
768
+ if (u.status !== 200)
769
+ return a(u);
770
+ let d = { data: u.data, headers: u.headers };
771
+ if ((c = u.headers) != null && c["per-page"] && (d = Object.assign({}, d, {
772
+ perPage: u.headers["per-page"] ? Number.parseInt(u.headers["per-page"]) : 0,
773
+ total: u.headers["per-page"] ? Number.parseInt(u.headers.total) : 0
774
+ })), d.data.story || d.data.stories) {
775
+ const g = this.resolveCounter = ++this.resolveCounter % 1e3;
776
+ await this.resolveStories(d.data, t, `${g}`);
763
777
  }
764
- return t.version === "published" && e != "/cdn/spaces/me" && await o.set(n, u), u.data.cv && t.token && S[t.token] != u.data.cv && (await this.flushCache(), S[t.token] = u.data.cv), l(u);
765
- } catch (d) {
766
- if (d.response && d.status === 429 && (s = typeof s > "u" ? 0 : s + 1, s < this.maxRetries))
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);
779
+ } catch (u) {
780
+ if (u.response && u.status === 429 && (s = typeof s > "u" ? 0 : s + 1, s < this.maxRetries))
767
781
  return console.log(
768
782
  `Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`
769
783
  ), await this.helpers.delay(this.retriesDelay), this.cacheResponse(e, t, s).then(l).catch(a);
770
- a(d);
784
+ a(u);
771
785
  }
772
786
  });
773
787
  }
@@ -775,36 +789,37 @@ class Ee {
775
789
  return this.client.setFetchOptions(r), this.client[e](t, s);
776
790
  }
777
791
  cacheVersions() {
778
- return S;
792
+ return E;
779
793
  }
780
794
  cacheVersion() {
781
- return S[this.accessToken];
795
+ return E[this.accessToken];
782
796
  }
783
797
  setCacheVersion(e) {
784
- this.accessToken && (S[this.accessToken] = e);
798
+ this.accessToken && (E[this.accessToken] = e);
785
799
  }
786
800
  clearCacheVersion() {
787
- this.accessToken && (S[this.accessToken] = 0);
801
+ this.accessToken && (E[this.accessToken] = 0);
788
802
  }
789
803
  cacheProvider() {
790
804
  switch (this.cache.type) {
791
805
  case "memory":
792
806
  return {
793
807
  get(e) {
794
- return Promise.resolve(I[e]);
808
+ return Promise.resolve(x[e]);
795
809
  },
796
810
  getAll() {
797
- return Promise.resolve(I);
811
+ return Promise.resolve(x);
798
812
  },
799
813
  set(e, t) {
800
- return I[e] = t, Promise.resolve(void 0);
814
+ return x[e] = t, Promise.resolve(void 0);
801
815
  },
802
816
  flush() {
803
- return I = {}, Promise.resolve(void 0);
817
+ return x = {}, Promise.resolve(void 0);
804
818
  }
805
819
  };
806
820
  case "custom":
807
- if (this.cache.custom) return this.cache.custom;
821
+ if (this.cache.custom)
822
+ return this.cache.custom;
808
823
  default:
809
824
  return {
810
825
  get() {
@@ -826,7 +841,7 @@ class Ee {
826
841
  return await this.cacheProvider().flush(), this.clearCacheVersion(), this;
827
842
  }
828
843
  }
829
- const Ce = (i = {}) => {
844
+ const ze = (i = {}) => {
830
845
  const { apiOptions: e } = i;
831
846
  if (!e.accessToken) {
832
847
  console.error(
@@ -834,8 +849,8 @@ const Ce = (i = {}) => {
834
849
  );
835
850
  return;
836
851
  }
837
- return { storyblokApi: new Ee(e) };
838
- }, Pe = (i) => {
852
+ return { storyblokApi: new Oe(e) };
853
+ }, Be = (i) => {
839
854
  if (typeof i != "object" || typeof i._editable > "u")
840
855
  return {};
841
856
  try {
@@ -850,25 +865,28 @@ const Ce = (i = {}) => {
850
865
  return {};
851
866
  }
852
867
  };
853
- var b = /* @__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))(b || {}), 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 || {}), B = /* @__PURE__ */ ((i) => (i.TEXT = "text", i))(B || {}), _ = /* @__PURE__ */ ((i) => (i.URL = "url", i.STORY = "story", i.ASSET = "asset", i.EMAIL = "email", i))(_ || {});
854
- function Ie(i, e) {
855
- if (!e) return { src: i, attrs: {} };
868
+ function Le(i, e) {
869
+ if (!e)
870
+ return { src: i, attrs: {} };
856
871
  let t = 0, s = 0;
857
872
  const r = {}, n = [];
858
- function o(a, h, d, u, m) {
859
- typeof a != "number" || a <= h || a >= d ? console.warn(`[StoryblokRichText] - ${u.charAt(0).toUpperCase() + u.slice(1)} value must be a number between ${h} and ${d} (inclusive)`) : m.push(`${u}(${a})`);
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})`);
860
875
  }
861
876
  if (typeof e == "object") {
862
877
  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) {
863
- const { filters: a } = e || {}, { blur: h, brightness: d, fill: u, format: m, grayscale: k, quality: y, rotate: w } = a || {};
864
- h && o(h, 0, 100, "blur", n), y && o(y, 0, 100, "quality", n), d && o(d, 0, 100, "brightness", n), u && n.push(`fill(${u})`), k && n.push("grayscale()"), w && [0, 90, 180, 270].includes(e.filters.rotate || 0) && n.push(`rotate(${w})`), m && ["webp", "png", "jpeg"].includes(m) && n.push(`format(${m})`);
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})`);
865
880
  }
866
881
  e.srcset && (r.srcset = e.srcset.map((a) => {
867
882
  if (typeof a == "number")
868
- return `${i}/m/${a}x0/${n.length > 0 ? "filters:" + n.join(":") : ""} ${a}w`;
883
+ return `${i}/m/${a}x0/${n.length > 0 ? `filters:${n.join(":")}` : ""} ${a}w`;
869
884
  if (Array.isArray(a) && a.length === 2) {
870
- const [h, d] = a;
871
- return `${i}/m/${h}x${d}/${n.length > 0 ? "filters:" + n.join(":") : ""} ${h}w`;
885
+ const [c, u] = a;
886
+ return `${i}/m/${c}x${u}/${n.length > 0 ? `filters:${n.join(":")}` : ""} ${c}w`;
887
+ } else {
888
+ console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");
889
+ return;
872
890
  }
873
891
  }).join(", ")), e.sizes && (r.sizes = e.sizes.join(", "));
874
892
  }
@@ -878,140 +896,175 @@ function Ie(i, e) {
878
896
  attrs: r
879
897
  };
880
898
  }
881
- const xe = (i = {}) => Object.keys(i).map((e) => `${e}="${i[e]}"`).join(" "), je = (i = {}) => Object.keys(i).map((e) => `${e}: ${i[e]}`).join("; ");
882
- function Oe(i) {
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 = [
901
+ "area",
902
+ "base",
903
+ "br",
904
+ "col",
905
+ "embed",
906
+ "hr",
907
+ "img",
908
+ "input",
909
+ "link",
910
+ "meta",
911
+ "param",
912
+ "source",
913
+ "track",
914
+ "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) {
883
917
  return i.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
884
918
  }
885
- function Le(i, e = {}, t) {
886
- const s = xe(e);
887
- return `<${s ? `${i} ${s}` : i}>${Array.isArray(t) ? t.join("") : t || ""}</${i}>`;
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}>`;
888
923
  }
889
- function Ne(i = {}) {
924
+ function De(i = {}) {
890
925
  let e = 0;
891
926
  const {
892
- renderFn: t = Le,
893
- textFn: s = Oe,
927
+ renderFn: t = Me,
928
+ textFn: s = Ne,
894
929
  resolvers: r = {},
895
- optimizeImages: n = !1
896
- } = i, o = (c) => (g) => t(c, { ...g.attrs, key: `${c}-${e}` }, g.children || null), l = (c) => {
897
- const { src: g, alt: f, ...$ } = c.attrs || {};
898
- let T = g, 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, _ = {};
899
938
  if (n) {
900
- const { src: V, attrs: J } = Ie(g, n);
901
- T = V, R = J;
939
+ const { src: K, attrs: Y } = Le(f, n);
940
+ S = K, _ = Y;
902
941
  }
903
- const G = {
904
- src: T,
905
- alt: f || "",
906
- key: `img-${e}`,
907
- ...$,
908
- ...R
942
+ o && (_ = {
943
+ ..._,
944
+ key: `img-${e}`
945
+ });
946
+ const J = {
947
+ src: S,
948
+ alt: m,
949
+ title: b,
950
+ srcset: w,
951
+ sizes: $,
952
+ ..._
909
953
  };
910
- return t("img", G, "");
911
- }, a = (c) => {
912
- const { level: g, ...f } = c.attrs || {};
913
- return t(`h${g}`, { ...f, key: `h${g}-${e}` }, c.children);
914
- }, h = (c) => {
915
- var g, f, $, T;
916
- return t("span", {
917
- "data-type": "emoji",
918
- "data-name": (g = c.attrs) == null ? void 0 : g.name,
919
- emoji: (f = c.attrs) == null ? void 0 : f.emoji,
920
- key: `emoji-${e}`
921
- }, t("img", {
922
- src: ($ = c.attrs) == null ? void 0 : $.fallbackImage,
923
- alt: (T = c.attrs) == null ? void 0 : T.alt,
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);
960
+ }, 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,
924
965
  style: "width: 1.25em; height: 1.25em; vertical-align: text-top",
925
966
  draggable: "false",
926
967
  loading: "lazy"
927
- }, ""));
928
- }, d = (c) => t("pre", { ...c.attrs, key: `code-${e}` }, t("code", { key: `code-${e}` }, c.children || "")), u = (c, g = !1) => ({ text: f, attrs: $ }) => t(c, g ? {
929
- style: je($),
930
- key: `${c}-${e}`
931
- } : { ...$, key: `${c}-${e}` }, f), m = (c) => O(c), k = (c) => {
932
- const { marks: g, ...f } = c;
933
- return "text" in c ? g ? g.reduce(
934
- ($, T) => m({ ...T, text: $ }),
968
+ }), S = {
969
+ "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
972
+ };
973
+ return o && (S.key = `emoji-${e}`), t("span", S, $);
974
+ }, d = (h) => t("pre", {
975
+ ...h.attrs,
976
+ 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 }),
935
988
  // Fix: Ensure render function returns a string
936
- m({ ...f, children: f.children })
989
+ T({ ...m, children: m.children })
937
990
  // Fix: Cast children to string
938
- ) : s(f.text) : "";
939
- }, y = (c) => {
940
- const { linktype: g, href: f, anchor: $, ...T } = c.attrs || {};
941
- let R = "";
942
- switch (g) {
943
- case _.ASSET:
944
- case _.URL:
945
- R = f;
991
+ ) : s(m.text) : "";
992
+ }, R = (h) => {
993
+ const { linktype: f, href: m, anchor: b, ...w } = h.attrs || {};
994
+ let $ = "";
995
+ switch (f) {
996
+ case I.ASSET:
997
+ case I.URL:
998
+ $ = m;
946
999
  break;
947
- case _.EMAIL:
948
- R = `mailto:${f}`;
1000
+ case I.EMAIL:
1001
+ $ = `mailto:${m}`;
949
1002
  break;
950
- case _.STORY:
951
- R = f;
1003
+ case I.STORY:
1004
+ $ = m;
952
1005
  break;
953
1006
  }
954
- return $ && (R = `${R}#${$}`), t("a", { ...T, href: R, key: `a-${e}` }, c.text);
955
- }, w = (c) => {
956
- var g, f;
1007
+ return b && ($ = `${$}#${b}`), t("a", { ...w, href: $, key: `a-${e}` }, h.text);
1008
+ }, j = (h) => {
1009
+ var f, m;
957
1010
  return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), t("span", {
958
- blok: (g = c == null ? void 0 : c.attrs) == null ? void 0 : g.body[0],
959
- id: (f = c.attrs) == null ? void 0 : f.id,
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,
960
1013
  key: `component-${e}`,
961
1014
  style: "display: none"
962
- }, "");
963
- }, E = new Map([
964
- [b.DOCUMENT, o("div")],
965
- [b.HEADING, a],
966
- [b.PARAGRAPH, o("p")],
967
- [b.UL_LIST, o("ul")],
968
- [b.OL_LIST, o("ol")],
969
- [b.LIST_ITEM, o("li")],
970
- [b.IMAGE, l],
971
- [b.EMOJI, h],
972
- [b.CODE_BLOCK, d],
973
- [b.HR, o("hr")],
974
- [b.BR, o("br")],
975
- [b.QUOTE, o("blockquote")],
976
- [b.COMPONENT, w],
977
- [B.TEXT, k],
978
- [v.LINK, y],
979
- [v.ANCHOR, y],
980
- [v.STYLED, u("span", !0)],
981
- [v.BOLD, u("strong")],
982
- [v.TEXT_STYLE, u("span", !0)],
983
- [v.ITALIC, u("em")],
984
- [v.UNDERLINE, u("u")],
985
- [v.STRIKE, u("s")],
986
- [v.CODE, u("code")],
987
- [v.SUPERSCRIPT, u("sup")],
988
- [v.SUBSCRIPT, u("sub")],
989
- [v.HIGHLIGHT, u("mark")],
990
- ...Object.entries(r).map(([c, g]) => [c, g])
1015
+ });
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])
991
1044
  ]);
992
- function P(c) {
1045
+ function M(h) {
993
1046
  e += 1;
994
- const g = E.get(c.type);
995
- if (!g)
996
- return console.error("<Storyblok>", `No resolver found for node type ${c.type}`), "";
997
- if (c.type === "text")
998
- return g(c);
999
- const f = c.content ? c.content.map(O) : void 0;
1000
- return g({
1001
- ...c,
1002
- children: f
1047
+ const f = V.get(h.type);
1048
+ if (!f)
1049
+ return console.error("<Storyblok>", `No resolver found for node type ${h.type}`), "";
1050
+ if (h.type === "text")
1051
+ return f(h);
1052
+ const m = h.content ? h.content.map(A) : void 0;
1053
+ return f({
1054
+ ...h,
1055
+ children: m
1003
1056
  // Fix: Update the type of 'children' to Node[]
1004
1057
  });
1005
1058
  }
1006
- function O(c) {
1007
- return Array.isArray(c) ? c.map(P) : P(c);
1059
+ function A(h) {
1060
+ return Array.isArray(h) ? h.map(M) : M(h);
1008
1061
  }
1009
1062
  return {
1010
- render: O
1063
+ render: A
1011
1064
  };
1012
1065
  }
1013
- let A, C = "https://app.storyblok.com/f/storyblok-v2-latest.js";
1014
- const Me = (i, e, t = {}) => {
1066
+ let P, N = "https://app.storyblok.com/f/storyblok-v2-latest.js";
1067
+ const qe = (i, e, t = {}) => {
1015
1068
  var l;
1016
1069
  const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = +new URL((l = window.location) == null ? void 0 : l.href).searchParams.get(
1017
1070
  "_storyblok"
@@ -1022,13 +1075,13 @@ const Me = (i, e, t = {}) => {
1022
1075
  return;
1023
1076
  }
1024
1077
  window.storyblokRegisterEvent(() => {
1025
- new window.StoryblokBridge(t).on(["input", "published", "change"], (h) => {
1026
- h.action === "input" && h.story.id === i ? e(h.story) : (h.action === "change" || h.action === "published") && h.storyId === i && window.location.reload();
1078
+ 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();
1027
1080
  });
1028
1081
  });
1029
1082
  }
1030
- }, He = (i = {}) => {
1031
- var u, m;
1083
+ }, Ge = (i = {}) => {
1084
+ var d, g;
1032
1085
  const {
1033
1086
  bridge: e,
1034
1087
  accessToken: t,
@@ -1040,12 +1093,12 @@ const Me = (i, e, t = {}) => {
1040
1093
  r.accessToken = r.accessToken || t;
1041
1094
  const l = { bridge: e, apiOptions: r };
1042
1095
  let a = {};
1043
- s.forEach((k) => {
1044
- a = { ...a, ...k(l) };
1045
- }), o && (C = o);
1046
- const d = !(typeof window > "u") && ((m = (u = window.location) == null ? void 0 : u.search) == null ? void 0 : m.includes("_storyblok_tk"));
1047
- return e !== !1 && d && z(C), A = new j(n.schema), n.resolver && q(A, n.resolver), a;
1048
- }, q = (i, e) => {
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) => {
1049
1102
  i.addNode("blok", (t) => {
1050
1103
  let s = "";
1051
1104
  return t.attrs.body.forEach((r) => {
@@ -1054,29 +1107,29 @@ const Me = (i, e, t = {}) => {
1054
1107
  html: s
1055
1108
  };
1056
1109
  });
1057
- }, Ae = (i) => !i || !(i != null && i.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")), Ue = (i, e, t) => {
1058
- let s = t || A;
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;
1059
1112
  if (!s) {
1060
1113
  console.error(
1061
1114
  "Please initialize the Storyblok SDK before calling the renderRichText function"
1062
1115
  );
1063
1116
  return;
1064
1117
  }
1065
- return Ae(i) ? "" : (e && (s = new j(e.schema), e.resolver && q(s, e.resolver)), s.render(i, {}, !1));
1066
- }, De = () => z(C);
1118
+ return He(i) ? "" : (e && (s = new L(e.schema), e.resolver && F(s, e.resolver)), s.render(i, {}, !1));
1119
+ }, Ve = () => q(N);
1067
1120
  export {
1068
- b as BlockTypes,
1121
+ k as BlockTypes,
1069
1122
  v as MarkTypes,
1070
- j as RichTextResolver,
1071
- Te as RichTextSchema,
1072
- B as TextTypes,
1073
- Ce as apiPlugin,
1074
- Ae as isRichTextEmpty,
1075
- De as loadStoryblokBridge,
1076
- Me as registerStoryblokBridge,
1077
- Ue as renderRichText,
1078
- Ne as richTextResolver,
1079
- Pe as storyblokEditable,
1080
- He as storyblokInit,
1081
- Me as useStoryblokBridge
1123
+ L as RichTextResolver,
1124
+ _e as RichTextSchema,
1125
+ G as TextTypes,
1126
+ ze as apiPlugin,
1127
+ He as isRichTextEmpty,
1128
+ Ve as loadStoryblokBridge,
1129
+ qe as registerStoryblokBridge,
1130
+ Fe as renderRichText,
1131
+ De as richTextResolver,
1132
+ Be as storyblokEditable,
1133
+ Ge as storyblokInit,
1134
+ qe as useStoryblokBridge
1082
1135
  };