@storyblok/js 3.5.0 → 4.0.1

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