@storyblok/js 3.5.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,441 +4,338 @@
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 te(r, e) {
8
+ if (!e)
9
+ return { src: r, attrs: {} };
10
+ let t = 0, o = 0;
11
+ const s = {}, n = [];
12
+ function a(h, c, d, y, T) {
13
+ typeof h != "number" || h <= c || h >= d ? console.warn(`[StoryblokRichText] - ${y.charAt(0).toUpperCase() + y.slice(1)} value must be a number between ${c} and ${d} (inclusive)`) : T.push(`${y}(${h})`);
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: h } = e || {}, { blur: c, brightness: d, fill: y, format: T, grayscale: A, quality: _, rotate: S } = h || {};
18
+ c && a(c, 0, 100, "blur", n), _ && a(_, 0, 100, "quality", n), d && a(d, 0, 100, "brightness", n), y && n.push(`fill(${y})`), A && n.push("grayscale()"), S && [0, 90, 180, 270].includes(e.filters.rotate || 0) && n.push(`rotate(${S})`), T && ["webp", "png", "jpeg"].includes(T) && n.push(`format(${T})`);
19
+ }
20
+ e.srcset && (s.srcset = e.srcset.map((h) => {
21
+ if (typeof h == "number")
22
+ return `${r}/m/${h}x0/${n.length > 0 ? `filters:${n.join(":")}` : ""} ${h}w`;
23
+ if (Array.isArray(h) && h.length === 2) {
24
+ const [c, d] = h;
25
+ return `${r}/m/${c}x${d}/${n.length > 0 ? `filters:${n.join(":")}` : ""} ${c}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 l = `${r}/m/`;
33
+ return t > 0 && o > 0 && (l = `${l}${t}x${o}/`), n.length > 0 && (l = `${l}filters:${n.join(":")}`), {
34
+ src: l,
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 || {}), R = /* @__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))(R || {}), F = /* @__PURE__ */ ((r) => (r.TEXT = "text", r))(F || {}), I = /* @__PURE__ */ ((r) => (r.URL = "url", r.STORY = "story", r.ASSET = "asset", r.EMAIL = "email", r))(I || {});
39
+ const se = [
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
+ ], re = (r = {}) => Object.keys(r).map((e) => `${e}="${r[e]}"`).join(" "), oe = (r = {}) => Object.keys(r).map((e) => `${e}: ${r[e]}`).join("; ");
55
+ function ne(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 H(r, e = {}, t) {
60
+ const o = re(e), s = o ? `${r} ${o}` : r, n = Array.isArray(t) ? t.join("") : t || "";
61
+ if (r) {
62
+ if (se.includes(r))
63
+ return `<${s}>`;
64
+ } else return n;
65
+ return `<${s}>${n}</${r}>`;
66
+ }
67
+ function ie(r = {}) {
68
+ const e = /* @__PURE__ */ new Map(), {
69
+ renderFn: t = H,
70
+ textFn: o = ne,
71
+ resolvers: s = {},
72
+ optimizeImages: n = !1,
73
+ keyedResolvers: a = !1
74
+ } = r, l = t !== H, h = () => ({ render: (i, u = {}, p) => {
75
+ if (a && i) {
76
+ const f = e.get(i) || 0;
77
+ e.set(i, f + 1), u.key = `${i}-${f}`;
78
+ }
79
+ return t(i, u, p);
80
+ } }), c = (i) => (u, p) => {
81
+ const f = u.attrs || {};
82
+ return p.render(i, f, u.children || null);
83
+ }, d = (i, u) => {
84
+ const { src: p, alt: f, title: m, srcset: w, sizes: b } = i.attrs || {};
85
+ let k = p, $ = {};
86
+ if (n) {
87
+ const { src: Z, attrs: ee } = te(p, n);
88
+ k = Z, $ = ee;
89
+ }
90
+ const Q = {
91
+ src: k,
92
+ alt: f,
93
+ title: m,
94
+ srcset: w,
95
+ sizes: b,
96
+ ...$
97
+ };
98
+ return u.render("img", O(Q));
99
+ }, y = (i, u) => {
100
+ const { level: p, ...f } = i.attrs || {};
101
+ return u.render(`h${p}`, f, i.children);
102
+ }, T = (i, u) => {
103
+ var p, f, m, w;
104
+ const b = u.render("img", {
105
+ src: (p = i.attrs) == null ? void 0 : p.fallbackImage,
106
+ alt: (f = i.attrs) == null ? void 0 : f.alt,
107
+ style: "width: 1.25em; height: 1.25em; vertical-align: text-top",
108
+ draggable: "false",
109
+ loading: "lazy"
110
+ });
111
+ return u.render("span", {
112
+ "data-type": "emoji",
113
+ "data-name": (m = i.attrs) == null ? void 0 : m.name,
114
+ "data-emoji": (w = i.attrs) == null ? void 0 : w.emoji
115
+ }, b);
116
+ }, A = (i, u) => u.render(
117
+ "pre",
118
+ i.attrs || {},
119
+ u.render("code", {}, i.children || "")
120
+ ), _ = (i, u = !1) => ({ text: p, attrs: f }, m) => {
121
+ const { class: w, id: b, ...k } = f || {}, $ = u ? {
122
+ class: w,
123
+ id: b,
124
+ style: oe(k) || void 0
125
+ } : f || {};
126
+ return m.render(i, O($), p);
127
+ }, S = (i) => C(i), V = (i) => {
128
+ const { marks: u, ...p } = i;
129
+ if ("text" in i) {
130
+ if (u)
131
+ return u.reduce(
132
+ (m, w) => S({ ...w, text: m }),
133
+ S({ ...p, children: p.children })
134
+ );
135
+ const f = i.attrs || {};
136
+ if (a) {
137
+ const m = e.get("txt") || 0;
138
+ e.set("txt", m + 1), f.key = `txt-${m}`;
139
+ }
140
+ return o(p.text, f);
141
+ }
142
+ return "";
143
+ }, B = (i, u) => {
144
+ const { linktype: p, href: f, anchor: m, ...w } = i.attrs || {};
145
+ let b = "";
146
+ switch (p) {
147
+ case I.ASSET:
148
+ case I.URL:
149
+ b = f;
150
+ break;
151
+ case I.EMAIL:
152
+ b = `mailto:${f}`;
153
+ break;
154
+ case I.STORY:
155
+ b = f, m && (b = `${b}#${m}`);
156
+ break;
157
+ default:
158
+ b = f;
159
+ break;
160
+ }
161
+ const k = { ...w };
162
+ return b && (k.href = b), u.render("a", k, i.text);
163
+ }, q = (i, u) => {
164
+ var p, f;
165
+ return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), u.render("span", {
166
+ blok: (p = i == null ? void 0 : i.attrs) == null ? void 0 : p.body[0],
167
+ id: (f = i.attrs) == null ? void 0 : f.id,
168
+ style: "display: none"
169
+ });
170
+ }, J = (i, u) => {
171
+ const p = {}, f = u.render("tbody", {}, i.children);
172
+ return u.render("table", p, f);
173
+ }, Y = (i, u) => {
174
+ const p = {};
175
+ return u.render("tr", p, i.children);
176
+ }, K = (i, u) => {
177
+ const { colspan: p, rowspan: f, colwidth: m, backgroundColor: w, ...b } = i.attrs || {}, k = {
178
+ ...b
179
+ };
180
+ p > 1 && (k.colspan = p), f > 1 && (k.rowspan = f);
181
+ const $ = [];
182
+ return m && $.push(`width: ${m}px;`), w && $.push(`background-color: ${w};`), $.length > 0 && (k.style = $.join(" ")), u.render("td", O(k), i.children);
183
+ }, W = (i, u) => {
184
+ const { colspan: p, rowspan: f, colwidth: m, backgroundColor: w, ...b } = i.attrs || {}, k = {
185
+ ...b
186
+ };
187
+ p > 1 && (k.colspan = p), f > 1 && (k.rowspan = f);
188
+ const $ = [];
189
+ return m && $.push(`width: ${m}px;`), w && $.push(`background-color: ${w};`), $.length > 0 && (k.style = $.join(" ")), u.render("th", O(k), i.children);
190
+ }, X = new Map([
191
+ [v.DOCUMENT, c("")],
192
+ [v.HEADING, y],
193
+ [v.PARAGRAPH, c("p")],
194
+ [v.UL_LIST, c("ul")],
195
+ [v.OL_LIST, c("ol")],
196
+ [v.LIST_ITEM, c("li")],
197
+ [v.IMAGE, d],
198
+ [v.EMOJI, T],
199
+ [v.CODE_BLOCK, A],
200
+ [v.HR, c("hr")],
201
+ [v.BR, c("br")],
202
+ [v.QUOTE, c("blockquote")],
203
+ [v.COMPONENT, q],
204
+ [F.TEXT, V],
205
+ [R.LINK, B],
206
+ [R.ANCHOR, B],
207
+ [R.STYLED, _("span", !0)],
208
+ [R.BOLD, _("strong")],
209
+ [R.TEXT_STYLE, _("span", !0)],
210
+ [R.ITALIC, _("em")],
211
+ [R.UNDERLINE, _("u")],
212
+ [R.STRIKE, _("s")],
213
+ [R.CODE, _("code")],
214
+ [R.SUPERSCRIPT, _("sup")],
215
+ [R.SUBSCRIPT, _("sub")],
216
+ [R.HIGHLIGHT, _("mark")],
217
+ [v.TABLE, J],
218
+ [v.TABLE_ROW, Y],
219
+ [v.TABLE_CELL, K],
220
+ [v.TABLE_HEADER, W],
221
+ ...Object.entries(s).map(([i, u]) => [i, u])
222
+ ]);
223
+ function L(i) {
224
+ const u = X.get(i.type);
225
+ if (!u)
226
+ return console.error("<Storyblok>", `No resolver found for node type ${i.type}`), "";
227
+ const p = h();
228
+ if (i.type === "text")
229
+ return u(i, p);
230
+ const f = i.content ? i.content.map(C) : void 0;
231
+ return u({
232
+ ...i,
233
+ children: f
234
+ }, p);
235
+ }
236
+ function C(i) {
237
+ return i.type === "doc" ? l ? i.content.map(L) : i.content.map(L).join("") : Array.isArray(i) ? i.map(L) : L(i);
238
+ }
239
+ return {
240
+ render: C
241
+ };
242
+ }
243
+ let U = !1;
244
+ const D = [], G = (r) => new Promise((e, t) => {
245
+ if (typeof window > "u" || (window.storyblokRegisterEvent = (s) => {
10
246
  if (window.location === window.parent.location) {
11
247
  console.warn("You are not in Draft Mode or in the Visual Editor.");
12
248
  return;
13
249
  }
14
- z ? r() : D.push(r);
250
+ U ? s() : D.push(s);
15
251
  }, document.getElementById("storyblok-javascript-bridge")))
16
252
  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);
253
+ const o = document.createElement("script");
254
+ o.async = !0, o.src = r, o.id = "storyblok-javascript-bridge", o.onerror = (s) => t(s), o.onload = (s) => {
255
+ D.forEach((n) => n()), U = !0, e(s);
256
+ }, document.getElementsByTagName("head")[0].appendChild(o);
21
257
  });
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 {
258
+ var ae = Object.defineProperty, le = (r, e, t) => e in r ? ae(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, g = (r, e, t) => le(r, typeof e != "symbol" ? e + "" : e, t);
259
+ class ce extends Error {
24
260
  constructor(e) {
25
261
  super(e), this.name = "AbortError";
26
262
  }
27
263
  }
28
- function ae(i, e, t) {
264
+ function he(r, e, t) {
29
265
  if (!Number.isFinite(e))
30
266
  throw new TypeError("Expected `limit` to be a finite number");
31
267
  if (!Number.isFinite(t))
32
268
  throw new TypeError("Expected `interval` to be a finite number");
33
- const s = [];
34
- let r = [], n = 0, o = !1;
35
- const c = async () => {
269
+ const o = [];
270
+ let s = [], n = 0, a = !1;
271
+ const l = async () => {
36
272
  n++;
37
- const h = s.shift();
38
- if (h)
273
+ const c = o.shift();
274
+ if (c)
39
275
  try {
40
- const d = await i(...h.args);
41
- h.resolve(d);
42
- } catch (d) {
43
- h.reject(d);
276
+ const y = await r(...c.args);
277
+ c.resolve(y);
278
+ } catch (y) {
279
+ c.reject(y);
44
280
  }
45
- const u = setTimeout(() => {
46
- n--, s.length > 0 && c(), r = r.filter((d) => d !== u);
281
+ const d = setTimeout(() => {
282
+ n--, o.length > 0 && l(), s = s.filter((y) => y !== d);
47
283
  }, t);
48
- r.includes(u) || r.push(u);
49
- }, a = (...h) => o ? Promise.reject(
284
+ s.includes(d) || s.push(d);
285
+ }, h = (...c) => a ? Promise.reject(
50
286
  new Error(
51
287
  "Throttled function is already aborted and not accepting new promises"
52
288
  )
53
- ) : new Promise((u, d) => {
54
- s.push({
55
- resolve: u,
56
- reject: d,
57
- args: h
58
- }), n < e && c();
289
+ ) : new Promise((d, y) => {
290
+ o.push({
291
+ resolve: d,
292
+ reject: y,
293
+ args: c
294
+ }), n < e && l();
59
295
  });
60
- 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;
64
- }, a;
296
+ return h.abort = () => {
297
+ a = !0, s.forEach(clearTimeout), s = [], o.forEach(
298
+ (c) => c.reject(() => new ce("Throttle function aborted"))
299
+ ), o.length = 0;
300
+ }, h;
65
301
  }
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
302
+ const ue = (r = "") => r.includes("/cdn/"), de = (r, e = 25, t = 1) => ({
303
+ ...r,
304
+ per_page: e,
305
+ page: t
306
+ }), pe = (r) => new Promise((e) => setTimeout(e, r)), fe = (r = 0, e) => Array.from({ length: r }, e), ye = (r = 0, e = r) => {
307
+ const t = Math.abs(e - r) || 0, o = r < e ? 1 : -1;
308
+ return fe(t, (s, n) => n * o + r);
309
+ }, ge = async (r, e) => Promise.all(r.map(e)), me = (r = [], e) => r.map(e).reduce((t, o) => [...t, ...o], []), N = (r, e, t) => {
310
+ const o = [];
311
+ for (const s in r) {
312
+ if (!Object.prototype.hasOwnProperty.call(r, s))
313
+ continue;
314
+ const n = r[s];
315
+ if (n == null)
316
+ continue;
317
+ const a = t ? "" : encodeURIComponent(s);
318
+ let l;
319
+ typeof n == "object" ? l = N(
320
+ n,
321
+ e ? e + encodeURIComponent(`[${a}]`) : a,
322
+ Array.isArray(n)
323
+ ) : l = `${e ? e + encodeURIComponent(`[${a}]`) : a}=${encodeURIComponent(n)}`, o.push(l);
286
324
  }
287
- }, Pe = function(i) {
325
+ return o.join("&");
326
+ }, M = (r) => {
288
327
  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;
328
+ eu: "api.storyblok.com",
329
+ us: "api-us.storyblok.com",
330
+ cn: "app.storyblokchina.cn",
331
+ ap: "api-ap.storyblok.com",
332
+ ca: "api-ca.storyblok.com"
333
+ };
334
+ return e[r] ?? e.eu;
296
335
  };
297
- let q = !1;
298
- class P {
336
+ class be {
299
337
  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 = {};
338
+ 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
339
  }
443
340
  /**
444
341
  *
@@ -459,47 +356,41 @@ class Ne {
459
356
  return this.url = e, this.parameters = t ?? {}, this._methodHandler("delete");
460
357
  }
461
358
  async _responseHandler(e) {
462
- const t = [], s = {
359
+ const t = [], o = {
463
360
  data: {},
464
361
  headers: {},
465
362
  status: 0,
466
363
  statusText: ""
467
364
  };
468
- e.status !== 204 && await e.json().then((r) => {
469
- s.data = r;
365
+ e.status !== 204 && await e.json().then((s) => {
366
+ o.data = s;
470
367
  });
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;
368
+ for (const s of e.headers.entries())
369
+ t[s[0]] = s[1];
370
+ return o.headers = { ...t }, o.status = e.status, o.statusText = e.statusText, o;
474
371
  }
475
372
  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;
485
- let c;
486
- this.timeout && (c = setTimeout(() => n.abort(), this.timeout));
373
+ let t = `${this.baseURL}${this.url}`, o = null;
374
+ e === "get" ? t = `${this.baseURL}${this.url}?${N(this.parameters)}` : o = JSON.stringify(this.parameters);
375
+ const s = new URL(t), n = new AbortController(), { signal: a } = n;
376
+ let l;
377
+ this.timeout && (l = setTimeout(() => n.abort(), this.timeout));
487
378
  try {
488
- const a = await this.fetch(`${r}`, {
379
+ const h = await this.fetch(`${s}`, {
489
380
  method: e,
490
381
  headers: this.headers,
491
- body: s,
492
- signal: o,
382
+ body: o,
383
+ signal: a,
493
384
  ...this.fetchOptions
494
385
  });
495
- this.timeout && clearTimeout(c);
496
- const h = await this._responseHandler(
497
- a
386
+ this.timeout && clearTimeout(l);
387
+ const c = await this._responseHandler(
388
+ h
498
389
  );
499
- return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(h)) : this._statusHandler(h);
500
- } catch (a) {
390
+ return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(c)) : this._statusHandler(c);
391
+ } catch (h) {
501
392
  return {
502
- message: a
393
+ message: h
503
394
  };
504
395
  }
505
396
  }
@@ -509,125 +400,137 @@ class Ne {
509
400
  eject() {
510
401
  this.ejectInterceptor = !0;
511
402
  }
403
+ /**
404
+ * Normalizes error messages from different response structures
405
+ * @param data The response data that might contain error information
406
+ * @returns A normalized error message string
407
+ */
408
+ _normalizeErrorMessage(e) {
409
+ if (Array.isArray(e))
410
+ return e[0] || "Unknown error";
411
+ if (e && typeof e == "object") {
412
+ if (e.error)
413
+ return e.error;
414
+ for (const t in e) {
415
+ if (Array.isArray(e[t]))
416
+ return `${t}: ${e[t][0]}`;
417
+ if (typeof e[t] == "string")
418
+ return `${t}: ${e[t]}`;
419
+ }
420
+ if (e.slug)
421
+ return e.slug;
422
+ }
423
+ return "Unknown error";
424
+ }
512
425
  _statusHandler(e) {
513
426
  const t = /20[0-6]/g;
514
- return new Promise((s, r) => {
427
+ return new Promise((o, s) => {
515
428
  if (t.test(`${e.status}`))
516
- return s(e);
429
+ return o(e);
517
430
  const n = {
518
- message: e.statusText,
431
+ message: this._normalizeErrorMessage(e.data),
519
432
  status: e.status,
520
- response: Array.isArray(e.data) ? e.data[0] : e.data.error || e.data.slug
433
+ response: e
521
434
  };
522
- r(n);
435
+ s(n);
523
436
  });
524
437
  }
525
438
  }
526
- const F = "SB-Agent", H = {
439
+ const z = "SB-Agent", P = {
527
440
  defaultAgentName: "SB-JS-CLIENT",
528
441
  defaultAgentVersion: "SB-Agent-Version",
529
442
  packageVersion: "6.0.0"
443
+ }, ve = {
444
+ DRAFT: "draft"
530
445
  };
531
- let O = {};
532
- const A = {};
533
- class He {
446
+ let j = {};
447
+ const E = {};
448
+ class ke {
534
449
  /**
535
450
  *
536
451
  * @param config ISbConfig interface
537
452
  * @param pEndpoint string, optional
538
453
  */
539
454
  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`;
455
+ 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");
456
+ let o = e.endpoint || t;
457
+ if (!o) {
458
+ const a = e.https === !1 ? "http" : "https";
459
+ e.oauthToken ? o = `${a}://${M(e.region)}/v1` : o = `${a}://${M(e.region)}/v2`;
545
460
  }
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
461
+ const s = new Headers();
462
+ 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(([a, l]) => {
463
+ s.set(a, l);
464
+ }), s.has(z) || (s.set(z, P.defaultAgentName), s.set(
465
+ P.defaultAgentVersion,
466
+ P.packageVersion
552
467
  ));
553
468
  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(
469
+ e.oauthToken && (s.set("Authorization", e.oauthToken), n = 3), e.rateLimit && (n = e.rateLimit), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = he(
555
470
  this.throttledRequest.bind(this),
556
471
  n,
557
472
  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,
473
+ ), 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 || ve.DRAFT, this.inlineAssets = e.inlineAssets || !1, this.client = new be({
474
+ baseURL: o,
560
475
  timeout: e.timeout || 0,
561
- headers: r,
476
+ headers: s,
562
477
  responseInterceptor: e.responseInterceptor,
563
478
  fetch: e.fetch
564
479
  });
565
480
  }
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
481
  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;
482
+ 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
483
  }
579
484
  factoryParamOptions(e, t) {
580
- return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
485
+ return ue(e) ? this.parseParams(t) : t;
581
486
  }
582
- makeRequest(e, t, s, r, n) {
583
- const o = this.factoryParamOptions(
487
+ makeRequest(e, t, o, s, n) {
488
+ const a = this.factoryParamOptions(
584
489
  e,
585
- this.helpers.getOptionsPage(t, s, r)
490
+ de(t, o, s)
586
491
  );
587
- return this.cacheResponse(e, o, void 0, n);
492
+ return this.cacheResponse(e, a, void 0, n);
588
493
  }
589
- get(e, t, s) {
494
+ get(e, t = {}, o) {
590
495
  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,
496
+ const s = `/${e}`;
497
+ t.version = t.version || this.version;
498
+ const n = this.factoryParamOptions(s, t);
499
+ return this.cacheResponse(s, n, void 0, o);
500
+ }
501
+ async getAll(e, t = {}, o, s) {
502
+ const n = (t == null ? void 0 : t.per_page) || 25, a = `/${e}`.replace(/\/$/, ""), l = o ?? a.substring(a.lastIndexOf("/") + 1);
503
+ t.version = t.version || this.version;
504
+ const h = 1, c = await this.makeRequest(
505
+ a,
597
506
  t,
598
507
  n,
599
- 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)
508
+ h,
509
+ s
510
+ ), d = c.total ? Math.ceil(c.total / n) : 1, y = await ge(
511
+ ye(h, d),
512
+ (T) => this.makeRequest(a, t, n, T + 1, s)
604
513
  );
605
- return this.helpers.flatMap([h, ...d], (b) => Object.values(b.data[c]));
514
+ return me([c, ...y], (T) => Object.values(T.data[l]));
606
515
  }
607
- post(e, t, s) {
608
- const r = `/${e}`;
609
- return Promise.resolve(
610
- this.throttle("post", r, t, s)
611
- );
516
+ post(e, t = {}, o) {
517
+ const s = `/${e}`;
518
+ return this.throttle("post", s, t, o);
612
519
  }
613
- put(e, t, s) {
614
- const r = `/${e}`;
615
- return Promise.resolve(
616
- this.throttle("put", r, t, s)
617
- );
520
+ put(e, t = {}, o) {
521
+ const s = `/${e}`;
522
+ return this.throttle("put", s, t, o);
618
523
  }
619
- delete(e, t, s) {
524
+ delete(e, t = {}, o) {
620
525
  t || (t = {});
621
- const r = `/${e}`;
622
- return Promise.resolve(
623
- this.throttle("delete", r, t, s)
624
- );
526
+ const s = `/${e}`;
527
+ return this.throttle("delete", s, t, o);
625
528
  }
626
- getStories(e, t) {
529
+ getStories(e = {}, t) {
627
530
  return this._addResolveLevel(e), this.get("cdn/stories", e, t);
628
531
  }
629
- getStory(e, t, s) {
630
- return this._addResolveLevel(t), this.get(`cdn/stories/${e}`, t, s);
532
+ getStory(e, t = {}, o) {
533
+ return this._addResolveLevel(t), this.get(`cdn/stories/${e}`, t, o);
631
534
  }
632
535
  getToken() {
633
536
  return this.accessToken;
@@ -641,9 +544,9 @@ class He {
641
544
  _cleanCopy(e) {
642
545
  return JSON.parse(JSON.stringify(e));
643
546
  }
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]));
547
+ _insertLinks(e, t, o) {
548
+ const s = e[t];
549
+ 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
550
  }
648
551
  /**
649
552
  *
@@ -664,10 +567,10 @@ class He {
664
567
  * - For single strings: directly replaces the UUID with the story reference
665
568
  * - For arrays: maps through each UUID and replaces with corresponding story references
666
569
  */
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)
570
+ _resolveField(e, t, o) {
571
+ const s = e[t];
572
+ typeof s == "string" ? e[t] = this.getStoryReference(o, s) : Array.isArray(s) && (e[t] = s.map(
573
+ (n) => this.getStoryReference(o, n)
671
574
  ).filter(Boolean));
672
575
  }
673
576
  /**
@@ -687,13 +590,13 @@ class He {
687
590
  * The method supports both string and array formats for the fields parameter,
688
591
  * allowing flexible specification of relation patterns.
689
592
  */
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);
593
+ _insertRelations(e, t, o, s) {
594
+ if (Array.isArray(o) ? o.find((a) => a.endsWith(`.${t}`)) : o.endsWith(`.${t}`)) {
595
+ this._resolveField(e, t, s);
693
596
  return;
694
597
  }
695
598
  const n = e.component ? `${e.component}.${t}` : t;
696
- (Array.isArray(s) ? s.includes(n) : s === n) && this._resolveField(e, t, r);
599
+ (Array.isArray(o) ? o.includes(n) : o === n) && this._resolveField(e, t, s);
697
600
  }
698
601
  /**
699
602
  * Recursively traverses and resolves relations in the story content tree
@@ -701,73 +604,73 @@ class He {
701
604
  * @param fields - The relation patterns to resolve
702
605
  * @param resolveId - The unique identifier for the current resolution context
703
606
  */
704
- iterateTree(e, t, s) {
705
- const r = (n, o = "") => {
607
+ iterateTree(e, t, o) {
608
+ const s = (n, a = "") => {
706
609
  if (!(!n || n._stopResolving)) {
707
610
  if (Array.isArray(n))
708
- n.forEach((c, a) => r(c, `${o}[${a}]`));
611
+ n.forEach((l, h) => s(l, `${a}[${h}]`));
709
612
  else if (typeof n == "object")
710
- 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);
613
+ for (const l in n) {
614
+ const h = a ? `${a}.${l}` : l;
615
+ (n.component && n._uid || n.type === "link") && (this._insertRelations(n, l, t, o), this._insertLinks(n, l, o)), s(n[l], h);
713
616
  }
714
617
  }
715
618
  };
716
- r(e.content);
619
+ s(e.content);
717
620
  }
718
- async resolveLinks(e, t, s) {
719
- let r = [];
621
+ async resolveLinks(e, t, o) {
622
+ let s = [];
720
623
  if (e.link_uuids) {
721
- const n = e.link_uuids.length, o = [], c = 50;
722
- for (let a = 0; a < n; a += c) {
723
- const h = Math.min(n, a + c);
724
- o.push(e.link_uuids.slice(a, h));
624
+ const n = e.link_uuids.length, a = [], l = 50;
625
+ for (let h = 0; h < n; h += l) {
626
+ const c = Math.min(n, h + l);
627
+ a.push(e.link_uuids.slice(h, c));
725
628
  }
726
- for (let a = 0; a < o.length; a++)
629
+ for (let h = 0; h < a.length; h++)
727
630
  (await this.getStories({
728
- per_page: c,
631
+ per_page: l,
729
632
  language: t.language,
730
633
  version: t.version,
731
634
  starts_with: t.starts_with,
732
- by_uuids: o[a].join(",")
635
+ by_uuids: a[h].join(",")
733
636
  })).data.stories.forEach(
734
- (h) => {
735
- r.push(h);
637
+ (c) => {
638
+ s.push(c);
736
639
  }
737
640
  );
738
641
  } else
739
- r = e.links;
740
- r.forEach((n) => {
741
- this.links[s][n.uuid] = {
642
+ s = e.links;
643
+ s.forEach((n) => {
644
+ this.links[o][n.uuid] = {
742
645
  ...n,
743
646
  _stopResolving: !0
744
647
  };
745
648
  });
746
649
  }
747
- async resolveRelations(e, t, s) {
748
- let r = [];
650
+ async resolveRelations(e, t, o) {
651
+ let s = [];
749
652
  if (e.rel_uuids) {
750
- const n = e.rel_uuids.length, o = [], c = 50;
751
- for (let a = 0; a < n; a += c) {
752
- const h = Math.min(n, a + c);
753
- o.push(e.rel_uuids.slice(a, h));
653
+ const n = e.rel_uuids.length, a = [], l = 50;
654
+ for (let h = 0; h < n; h += l) {
655
+ const c = Math.min(n, h + l);
656
+ a.push(e.rel_uuids.slice(h, c));
754
657
  }
755
- for (let a = 0; a < o.length; a++)
658
+ for (let h = 0; h < a.length; h++)
756
659
  (await this.getStories({
757
- per_page: c,
660
+ per_page: l,
758
661
  language: t.language,
759
662
  version: t.version,
760
663
  starts_with: t.starts_with,
761
- by_uuids: o[a].join(","),
664
+ by_uuids: a[h].join(","),
762
665
  excluding_fields: t.excluding_fields
763
- })).data.stories.forEach((h) => {
764
- r.push(h);
666
+ })).data.stories.forEach((c) => {
667
+ s.push(c);
765
668
  });
766
- r.length > 0 && (e.rels = r, delete e.rel_uuids);
669
+ s.length > 0 && (e.rels = s, delete e.rel_uuids);
767
670
  } else
768
- r = e.rels;
769
- r && r.length > 0 && r.forEach((n) => {
770
- this.relations[s][n.uuid] = {
671
+ s = e.rels;
672
+ s && s.length > 0 && s.forEach((n) => {
673
+ this.relations[o][n.uuid] = {
771
674
  ...n,
772
675
  _stopResolving: !0
773
676
  };
@@ -782,88 +685,88 @@ class He {
782
685
  * @returns Promise<void>
783
686
  *
784
687
  */
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])
688
+ async resolveStories(e, t, o) {
689
+ var s, n;
690
+ let a = [];
691
+ if (this.links[o] = {}, this.relations[o] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (a = 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)
692
+ for (const l in this.relations[o])
790
693
  this.iterateTree(
791
- this.relations[s][c],
792
- o,
793
- s
694
+ this.relations[o][l],
695
+ a,
696
+ o
794
697
  );
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];
698
+ e.story ? this.iterateTree(e.story, a, o) : e.stories.forEach((l) => {
699
+ this.iterateTree(l, a, o);
700
+ }), this.stringifiedStoriesCache = {}, delete this.links[o], delete this.relations[o];
798
701
  }
799
- async cacheResponse(e, t, s, r) {
800
- const n = this.helpers.stringify({ url: e, params: t }), o = this.cacheProvider();
702
+ async cacheResponse(e, t, o, s) {
703
+ const n = N({ url: e, params: t }), a = this.cacheProvider();
801
704
  if (t.version === "published" && e !== "/cdn/spaces/me") {
802
- const c = await o.get(n);
803
- if (c)
804
- return Promise.resolve(c);
705
+ const l = await a.get(n);
706
+ if (l)
707
+ return Promise.resolve(l);
805
708
  }
806
- return new Promise(async (c, a) => {
807
- var h;
709
+ return new Promise(async (l, h) => {
710
+ var c;
808
711
  try {
809
- const u = await this.throttle(
712
+ const d = await this.throttle(
810
713
  "get",
811
714
  e,
812
715
  t,
813
- r
716
+ s
814
717
  );
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);
718
+ if (d.status !== 200)
719
+ return h(d);
720
+ let y = { data: d.data, headers: d.headers };
721
+ if ((c = d.headers) != null && c["per-page"] && (y = Object.assign({}, y, {
722
+ perPage: d.headers["per-page"] ? Number.parseInt(d.headers["per-page"]) : 0,
723
+ total: d.headers["per-page"] ? Number.parseInt(d.headers.total) : 0
724
+ })), y.data.story || y.data.stories) {
725
+ const A = this.resolveCounter = ++this.resolveCounter % 1e3;
726
+ await this.resolveStories(y.data, t, `${A}`), y = await this.processInlineAssets(y);
824
727
  }
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))
728
+ t.version === "published" && e !== "/cdn/spaces/me" && await a.set(n, y);
729
+ const T = this.cache.clear === "onpreview" && t.version === "draft" || this.cache.clear === "auto";
730
+ 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), l(y);
731
+ } catch (d) {
732
+ if (d.response && d.status === 429 && (o = typeof o > "u" ? 0 : o + 1, o < this.maxRetries))
830
733
  return console.log(
831
734
  `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);
735
+ ), await pe(this.retriesDelay), this.cacheResponse(e, t, o).then(l).catch(h);
736
+ h(d);
834
737
  }
835
738
  });
836
739
  }
837
- throttledRequest(e, t, s, r) {
838
- return this.client.setFetchOptions(r), this.client[e](t, s);
740
+ throttledRequest(e, t, o, s) {
741
+ return this.client.setFetchOptions(s), this.client[e](t, o);
839
742
  }
840
743
  cacheVersions() {
841
- return A;
744
+ return E;
842
745
  }
843
746
  cacheVersion() {
844
- return A[this.accessToken];
747
+ return E[this.accessToken];
845
748
  }
846
749
  setCacheVersion(e) {
847
- this.accessToken && (A[this.accessToken] = e);
750
+ this.accessToken && (E[this.accessToken] = e);
848
751
  }
849
752
  clearCacheVersion() {
850
- this.accessToken && (A[this.accessToken] = 0);
753
+ this.accessToken && (E[this.accessToken] = 0);
851
754
  }
852
755
  cacheProvider() {
853
756
  switch (this.cache.type) {
854
757
  case "memory":
855
758
  return {
856
759
  get(e) {
857
- return Promise.resolve(O[e]);
760
+ return Promise.resolve(j[e]);
858
761
  },
859
762
  getAll() {
860
- return Promise.resolve(O);
763
+ return Promise.resolve(j);
861
764
  },
862
765
  set(e, t) {
863
- return O[e] = t, Promise.resolve(void 0);
766
+ return j[e] = t, Promise.resolve(void 0);
864
767
  },
865
768
  flush() {
866
- return O = {}, Promise.resolve(void 0);
769
+ return j = {}, Promise.resolve(void 0);
867
770
  }
868
771
  };
869
772
  case "custom":
@@ -892,38 +795,38 @@ class He {
892
795
  async processInlineAssets(e) {
893
796
  if (!this.inlineAssets)
894
797
  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)
798
+ const t = (o) => {
799
+ if (!o || typeof o != "object")
800
+ return o;
801
+ if (Array.isArray(o))
802
+ return o.map((n) => t(n));
803
+ let s = { ...o };
804
+ s.fieldtype === "asset" && Array.isArray(e.data.assets) && (s = {
805
+ ...s,
806
+ ...e.data.assets.find((n) => n.id === s.id)
904
807
  });
905
- for (const n in r)
906
- typeof r[n] == "object" && (r[n] = t(r[n]));
907
- return r;
808
+ for (const n in s)
809
+ typeof s[n] == "object" && (s[n] = t(s[n]));
810
+ return s;
908
811
  };
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;
812
+ 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
813
  }
911
814
  }
912
- const Fe = (i = {}) => {
913
- const { apiOptions: e } = i;
815
+ const we = (r = {}) => {
816
+ const { apiOptions: e } = r;
914
817
  if (!e || !e.accessToken) {
915
818
  console.error(
916
819
  "You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication"
917
820
  );
918
821
  return;
919
822
  }
920
- return { storyblokApi: new He(e) };
921
- }, Ge = (i) => {
922
- if (typeof i != "object" || typeof i._editable > "u")
823
+ return { storyblokApi: new ke(e) };
824
+ }, Te = (r) => {
825
+ if (typeof r != "object" || typeof r._editable > "u")
923
826
  return {};
924
827
  try {
925
828
  const e = JSON.parse(
926
- i._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
829
+ r._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
927
830
  );
928
831
  return e ? {
929
832
  "data-blok-c": JSON.stringify(e),
@@ -933,313 +836,56 @@ const Fe = (i = {}) => {
933
836
  return {};
934
837
  }
935
838
  };
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 = {}) => {
1174
- 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(
839
+ let x = "https://app.storyblok.com/f/storyblok-v2-latest.js";
840
+ const $e = (r, e, t = {}) => {
841
+ var l;
842
+ const s = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", n = new URL((l = window.location) == null ? void 0 : l.href).searchParams.get(
1176
843
  "_storyblok"
1177
- ), o = n !== null && +n === i;
1178
- if (!(!r || !o)) {
1179
- if (!i) {
844
+ ), a = n !== null && +n === r;
845
+ if (!(!s || !a)) {
846
+ if (!r) {
1180
847
  console.warn("Story ID is not defined. Please provide a valid ID.");
1181
848
  return;
1182
849
  }
1183
850
  window.storyblokRegisterEvent(() => {
1184
- 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());
851
+ new window.StoryblokBridge(t).on(["input", "published", "change"], (c) => {
852
+ var d;
853
+ c && (c.action === "input" && ((d = c.story) == null ? void 0 : d.id) === r ? e(c.story) : (c.action === "change" || c.action === "published") && c.storyId === r && window.location.reload());
1187
854
  });
1188
855
  });
1189
856
  }
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;
857
+ }, _e = (r = {}) => {
858
+ var d, y;
1201
859
  const {
1202
860
  bridge: e,
1203
861
  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);
862
+ use: o = [],
863
+ apiOptions: s = {},
864
+ bridgeUrl: n
865
+ } = r;
866
+ s.accessToken = s.accessToken || t;
867
+ const a = { bridge: e, apiOptions: s };
868
+ let l = {};
869
+ o.forEach((T) => {
870
+ l = { ...l, ...T(a) };
871
+ }), n && (x = n);
872
+ const c = !(typeof window > "u") && ((y = (d = window.location) == null ? void 0 : d.search) == null ? void 0 : y.includes("_storyblok_tk"));
873
+ return e !== !1 && c && G(x), l;
874
+ };
875
+ function Re(r, e) {
876
+ return ie(e).render(r);
877
+ }
878
+ const Ee = () => G(x);
1230
879
  export {
1231
- $ as BlockTypes,
1232
- E as MarkTypes,
1233
- P as RichTextResolver,
1234
- Ce as RichTextSchema,
1235
- 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
880
+ v as BlockTypes,
881
+ R as MarkTypes,
882
+ F as TextTypes,
883
+ we as apiPlugin,
884
+ Ee as loadStoryblokBridge,
885
+ $e as registerStoryblokBridge,
886
+ Re as renderRichText,
887
+ ie as richTextResolver,
888
+ Te as storyblokEditable,
889
+ _e as storyblokInit,
890
+ $e as useStoryblokBridge
1245
891
  };