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