@storyblok/react 2.0.19 → 2.1.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.
@@ -0,0 +1,845 @@
1
+ let R = false;
2
+ const T = [], j = (n) => new Promise((e, t) => {
3
+ if (typeof window > "u" || (window.storyblokRegisterEvent = (r) => {
4
+ if (window.location === window.parent.location) {
5
+ console.warn("You are not in Draft Mode or in the Visual Editor.");
6
+ return;
7
+ }
8
+ R ? r() : T.push(r);
9
+ }, document.getElementById("storyblok-javascript-bridge")))
10
+ return;
11
+ const s = document.createElement("script");
12
+ s.async = true, s.src = n, s.id = "storyblok-javascript-bridge", s.onerror = (r) => t(r), s.onload = (r) => {
13
+ T.forEach((i) => i()), R = true, e(r);
14
+ }, document.getElementsByTagName("head")[0].appendChild(s);
15
+ });
16
+ var I = Object.defineProperty, P = (n, e, t) => e in n ? I(n, e, { enumerable: true, configurable: true, writable: true, value: t }) : n[e] = t, h = (n, e, t) => (P(n, typeof e != "symbol" ? e + "" : e, t), t);
17
+ function _(n) {
18
+ return !(n !== n || n === 1 / 0 || n === -1 / 0);
19
+ }
20
+ function S(n, e, t) {
21
+ if (!_(e))
22
+ throw new TypeError("Expected `limit` to be a finite number");
23
+ if (!_(t))
24
+ throw new TypeError("Expected `interval` to be a finite number");
25
+ const s = [];
26
+ let r = [], i = 0;
27
+ const o = function() {
28
+ i++;
29
+ const a = setTimeout(function() {
30
+ i--, s.length > 0 && o(), r = r.filter(function(u) {
31
+ return u !== a;
32
+ });
33
+ }, t);
34
+ r.indexOf(a) < 0 && r.push(a);
35
+ const l = s.shift();
36
+ l.resolve(n.apply(l.self, l.args));
37
+ }, c = function(...a) {
38
+ const l = this;
39
+ return new Promise(function(u, d) {
40
+ s.push({
41
+ resolve: u,
42
+ reject: d,
43
+ args: a,
44
+ self: l
45
+ }), i < e && o();
46
+ });
47
+ };
48
+ return c.abort = function() {
49
+ r.forEach(clearTimeout), r = [], s.forEach(function(a) {
50
+ a.reject(function() {
51
+ Error.call(this, "Throttled function aborted"), this.name = "AbortError";
52
+ });
53
+ }), s.length = 0;
54
+ }, c;
55
+ }
56
+ const C = function(n, e) {
57
+ const t = {};
58
+ for (const s in n) {
59
+ const r = n[s];
60
+ e.indexOf(s) > -1 && r !== null && (t[s] = r);
61
+ }
62
+ return t;
63
+ }, O = (n) => n === "email", A = () => ({
64
+ singleTag: "hr"
65
+ }), N = () => ({
66
+ tag: "blockquote"
67
+ }), L = () => ({
68
+ tag: "ul"
69
+ }), M = (n) => ({
70
+ tag: [
71
+ "pre",
72
+ {
73
+ tag: "code",
74
+ attrs: n.attrs
75
+ }
76
+ ]
77
+ }), z = () => ({
78
+ singleTag: "br"
79
+ }), U = (n) => ({
80
+ tag: `h${n.attrs.level}`
81
+ }), q = (n) => ({
82
+ singleTag: [
83
+ {
84
+ tag: "img",
85
+ attrs: C(n.attrs, ["src", "alt", "title"])
86
+ }
87
+ ]
88
+ }), H = () => ({
89
+ tag: "li"
90
+ }), B = () => ({
91
+ tag: "ol"
92
+ }), D = () => ({
93
+ tag: "p"
94
+ }), F = (n) => ({
95
+ tag: [
96
+ {
97
+ tag: "span",
98
+ attrs: {
99
+ ["data-type"]: "emoji",
100
+ ["data-name"]: n.attrs.name,
101
+ emoji: n.attrs.emoji
102
+ }
103
+ }
104
+ ]
105
+ }), J = () => ({
106
+ tag: "b"
107
+ }), V = () => ({
108
+ tag: "strike"
109
+ }), Y = () => ({
110
+ tag: "u"
111
+ }), K = () => ({
112
+ tag: "strong"
113
+ }), W = () => ({
114
+ tag: "code"
115
+ }), G = () => ({
116
+ tag: "i"
117
+ }), Q = (n) => {
118
+ const e = { ...n.attrs }, { linktype: t = "url" } = n.attrs;
119
+ if (O(t) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), e.custom) {
120
+ for (const s in e.custom)
121
+ e[s] = e.custom[s];
122
+ delete e.custom;
123
+ }
124
+ return {
125
+ tag: [
126
+ {
127
+ tag: "a",
128
+ attrs: e
129
+ }
130
+ ]
131
+ };
132
+ }, X = (n) => ({
133
+ tag: [
134
+ {
135
+ tag: "span",
136
+ attrs: n.attrs
137
+ }
138
+ ]
139
+ }), Z = () => ({
140
+ tag: "sub"
141
+ }), ee = () => ({
142
+ tag: "sup"
143
+ }), te = (n) => ({
144
+ tag: [
145
+ {
146
+ tag: "span",
147
+ attrs: n.attrs
148
+ }
149
+ ]
150
+ }), se = (n) => ({
151
+ tag: [
152
+ {
153
+ tag: "span",
154
+ attrs: {
155
+ style: `background-color:${n.attrs.color};`
156
+ }
157
+ }
158
+ ]
159
+ }), re = (n) => ({
160
+ tag: [
161
+ {
162
+ tag: "span",
163
+ attrs: {
164
+ style: `color:${n.attrs.color}`
165
+ }
166
+ }
167
+ ]
168
+ }), ie = {
169
+ nodes: {
170
+ horizontal_rule: A,
171
+ blockquote: N,
172
+ bullet_list: L,
173
+ code_block: M,
174
+ hard_break: z,
175
+ heading: U,
176
+ image: q,
177
+ list_item: H,
178
+ ordered_list: B,
179
+ paragraph: D,
180
+ emoji: F
181
+ },
182
+ marks: {
183
+ bold: J,
184
+ strike: V,
185
+ underline: Y,
186
+ strong: K,
187
+ code: W,
188
+ italic: G,
189
+ link: Q,
190
+ styled: X,
191
+ subscript: Z,
192
+ superscript: ee,
193
+ anchor: te,
194
+ highlight: se,
195
+ textStyle: re
196
+ }
197
+ }, oe = function(n) {
198
+ const e = {
199
+ "&": "&amp;",
200
+ "<": "&lt;",
201
+ ">": "&gt;",
202
+ '"': "&quot;",
203
+ "'": "&#39;"
204
+ }, t = /[&<>"']/g, s = RegExp(t.source);
205
+ return n && s.test(n) ? n.replace(t, (r) => e[r]) : n;
206
+ };
207
+ class y {
208
+ constructor(e) {
209
+ h(this, "marks"), h(this, "nodes"), e || (e = ie), this.marks = e.marks || [], this.nodes = e.nodes || [];
210
+ }
211
+ addNode(e, t) {
212
+ this.nodes[e] = t;
213
+ }
214
+ addMark(e, t) {
215
+ this.marks[e] = t;
216
+ }
217
+ render(e, t = { optimizeImages: false }) {
218
+ if (e && e.content && Array.isArray(e.content)) {
219
+ let s = "";
220
+ return e.content.forEach((r) => {
221
+ s += this.renderNode(r);
222
+ }), t.optimizeImages ? this.optimizeImages(s, t.optimizeImages) : s;
223
+ }
224
+ return console.warn(
225
+ `The render method must receive an Object with a "content" field.
226
+ The "content" field must be an array of nodes as the type ISbRichtext.
227
+ ISbRichtext:
228
+ content?: ISbRichtext[]
229
+ marks?: ISbRichtext[]
230
+ attrs?: any
231
+ text?: string
232
+ type: string
233
+
234
+ Example:
235
+ {
236
+ content: [
237
+ {
238
+ content: [
239
+ {
240
+ text: 'Hello World',
241
+ type: 'text'
242
+ }
243
+ ],
244
+ type: 'paragraph'
245
+ }
246
+ ],
247
+ type: 'doc'
248
+ }`
249
+ ), "";
250
+ }
251
+ optimizeImages(e, t) {
252
+ let s = 0, r = 0, i = "", o = "";
253
+ typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (i += `width="${t.width}" `, s = t.width), typeof t.height == "number" && t.height > 0 && (i += `height="${t.height}" `, r = t.height), (t.loading === "lazy" || t.loading === "eager") && (i += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (i += `class="${t.class}" `), t.filters && (typeof t.filters.blur == "number" && t.filters.blur >= 0 && t.filters.blur <= 100 && (o += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (o += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-Fa-f]{6}/g) || t.filters.fill === "transparent") && (o += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (o += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (o += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (o += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (o += `:rotate(${t.filters.rotate})`), o.length > 0 && (o = "/filters" + o))), i.length > 0 && (e = e.replace(/<img/g, `<img ${i.trim()}`));
254
+ const c = s > 0 || r > 0 || o.length > 0 ? `${s}x${r}${o}` : "";
255
+ return e = e.replace(
256
+ /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,
257
+ `a.storyblok.com/f/$1/$2.$3/m/${c}`
258
+ ), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (a) => {
259
+ var l, u;
260
+ const d = a.match(
261
+ /a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g
262
+ );
263
+ if (d && d.length > 0) {
264
+ const g = {
265
+ srcset: (l = t.srcset) == null ? void 0 : l.map((p) => {
266
+ if (typeof p == "number")
267
+ return `//${d}/m/${p}x0${o} ${p}w`;
268
+ if (typeof p == "object" && p.length === 2) {
269
+ let k = 0, $ = 0;
270
+ return typeof p[0] == "number" && (k = p[0]), typeof p[1] == "number" && ($ = p[1]), `//${d}/m/${k}x${$}${o} ${k}w`;
271
+ }
272
+ }).join(", "),
273
+ sizes: (u = t.sizes) == null ? void 0 : u.map((p) => p).join(", ")
274
+ };
275
+ let b = "";
276
+ return g.srcset && (b += `srcset="${g.srcset}" `), g.sizes && (b += `sizes="${g.sizes}" `), a.replace(/<img/g, `<img ${b.trim()}`);
277
+ }
278
+ return a;
279
+ })), e;
280
+ }
281
+ renderNode(e) {
282
+ const t = [];
283
+ e.marks && e.marks.forEach((r) => {
284
+ const i = this.getMatchingMark(r);
285
+ i && t.push(this.renderOpeningTag(i.tag));
286
+ });
287
+ const s = this.getMatchingNode(e);
288
+ return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
289
+ t.push(this.renderNode(r));
290
+ }) : e.text ? t.push(oe(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) => {
291
+ const i = this.getMatchingMark(r);
292
+ i && t.push(this.renderClosingTag(i.tag));
293
+ }), t.join("");
294
+ }
295
+ renderTag(e, t) {
296
+ return e.constructor === String ? `<${e}${t}>` : e.map((s) => {
297
+ if (s.constructor === String)
298
+ return `<${s}${t}>`;
299
+ {
300
+ let r = `<${s.tag}`;
301
+ if (s.attrs)
302
+ for (const i in s.attrs) {
303
+ const o = s.attrs[i];
304
+ o !== null && (r += ` ${i}="${o}"`);
305
+ }
306
+ return `${r}${t}>`;
307
+ }
308
+ }).join("");
309
+ }
310
+ renderOpeningTag(e) {
311
+ return this.renderTag(e, "");
312
+ }
313
+ renderClosingTag(e) {
314
+ return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((t) => t.constructor === String ? `</${t}>` : `</${t.tag}>`).join("");
315
+ }
316
+ getMatchingNode(e) {
317
+ const t = this.nodes[e.type];
318
+ if (typeof t == "function")
319
+ return t(e);
320
+ }
321
+ getMatchingMark(e) {
322
+ const t = this.marks[e.type];
323
+ if (typeof t == "function")
324
+ return t(e);
325
+ }
326
+ renderEmoji(e) {
327
+ if (e.attrs.emoji)
328
+ return e.attrs.emoji;
329
+ const t = [
330
+ {
331
+ tag: "img",
332
+ attrs: {
333
+ src: e.attrs.fallbackImage,
334
+ draggable: "false",
335
+ loading: "lazy",
336
+ align: "absmiddle"
337
+ }
338
+ }
339
+ ];
340
+ return this.renderTag(t, " /");
341
+ }
342
+ }
343
+ class v {
344
+ constructor() {
345
+ h(this, "isCDNUrl", (e = "") => e.indexOf("/cdn/") > -1), h(this, "getOptionsPage", (e, t = 25, s = 1) => ({
346
+ ...e,
347
+ per_page: t,
348
+ page: s
349
+ })), h(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), h(this, "arrayFrom", (e = 0, t) => [...Array(e)].map(t)), h(this, "range", (e = 0, t = e) => {
350
+ const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
351
+ return this.arrayFrom(s, (i, o) => o * r + e);
352
+ }), h(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), h(this, "flatMap", (e = [], t) => e.map(t).reduce((s, r) => [...s, ...r], []));
353
+ }
354
+ /**
355
+ * @method stringify
356
+ * @param {Object} params
357
+ * @param {String} prefix
358
+ * @param {Boolean} isArray
359
+ * @return {String} Stringified object
360
+ */
361
+ stringify(e, t, s) {
362
+ const r = [];
363
+ for (const i in e) {
364
+ if (!Object.prototype.hasOwnProperty.call(e, i))
365
+ continue;
366
+ const o = e[i], c = s ? "" : encodeURIComponent(i);
367
+ let a;
368
+ typeof o == "object" ? a = this.stringify(
369
+ o,
370
+ t ? t + encodeURIComponent("[" + c + "]") : c,
371
+ Array.isArray(o)
372
+ ) : a = (t ? t + encodeURIComponent("[" + c + "]") : c) + "=" + encodeURIComponent(o), r.push(a);
373
+ }
374
+ return r.join("&");
375
+ }
376
+ /**
377
+ * @method getRegionURL
378
+ * @param {String} regionCode region code, could be eu, us or cn
379
+ * @return {String} The base URL of the region
380
+ */
381
+ getRegionURL(e) {
382
+ const t = "api.storyblok.com", s = "api-us.storyblok.com", r = "app.storyblokchina.cn";
383
+ switch (e) {
384
+ case "us":
385
+ return s;
386
+ case "cn":
387
+ return r;
388
+ default:
389
+ return t;
390
+ }
391
+ }
392
+ }
393
+ class ne {
394
+ constructor(e) {
395
+ h(this, "baseURL"), h(this, "timeout"), h(this, "headers"), h(this, "responseInterceptor"), h(this, "fetch"), h(this, "ejectInterceptor"), h(this, "url"), h(this, "parameters"), 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 = false, this.url = "", this.parameters = {};
396
+ }
397
+ /**
398
+ *
399
+ * @param url string
400
+ * @param params ISbStoriesParams
401
+ * @returns Promise<ISbResponse | Error>
402
+ */
403
+ get(e, t) {
404
+ return this.url = e, this.parameters = t, this._methodHandler("get");
405
+ }
406
+ post(e, t) {
407
+ return this.url = e, this.parameters = t, this._methodHandler("post");
408
+ }
409
+ put(e, t) {
410
+ return this.url = e, this.parameters = t, this._methodHandler("put");
411
+ }
412
+ delete(e, t) {
413
+ return this.url = e, this.parameters = t, this._methodHandler("delete");
414
+ }
415
+ async _responseHandler(e) {
416
+ const t = [], s = {
417
+ data: {},
418
+ headers: {},
419
+ status: 0,
420
+ statusText: ""
421
+ };
422
+ e.status !== 204 && await e.json().then((r) => {
423
+ s.data = r;
424
+ });
425
+ for (const r of e.headers.entries())
426
+ t[r[0]] = r[1];
427
+ return s.headers = { ...t }, s.status = e.status, s.statusText = e.statusText, s;
428
+ }
429
+ async _methodHandler(e) {
430
+ let t = `${this.baseURL}${this.url}`, s = null;
431
+ if (e === "get") {
432
+ const a = new v();
433
+ t = `${this.baseURL}${this.url}?${a.stringify(
434
+ this.parameters
435
+ )}`;
436
+ } else
437
+ s = JSON.stringify(this.parameters);
438
+ const r = new URL(t), i = new AbortController(), { signal: o } = i;
439
+ let c;
440
+ this.timeout && (c = setTimeout(() => i.abort(), this.timeout));
441
+ try {
442
+ const a = await this.fetch(`${r}`, {
443
+ method: e,
444
+ headers: this.headers,
445
+ body: s,
446
+ signal: o
447
+ });
448
+ this.timeout && clearTimeout(c);
449
+ const l = await this._responseHandler(a);
450
+ return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(l)) : this._statusHandler(l);
451
+ } catch (a) {
452
+ return {
453
+ message: a
454
+ };
455
+ }
456
+ }
457
+ eject() {
458
+ this.ejectInterceptor = true;
459
+ }
460
+ _statusHandler(e) {
461
+ const t = /20[0-6]/g;
462
+ return new Promise((s, r) => {
463
+ if (t.test(`${e.status}`))
464
+ return s(e);
465
+ const i = {
466
+ message: new Error(e.statusText),
467
+ status: e.status,
468
+ response: Array.isArray(e.data) ? e.data[0] : e.data.error || e.data.slug
469
+ };
470
+ r(i);
471
+ });
472
+ }
473
+ }
474
+ let m = {};
475
+ const f = {};
476
+ class ae {
477
+ /**
478
+ *
479
+ * @param config ISbConfig interface
480
+ * @param endpoint string, optional
481
+ */
482
+ constructor(e, t) {
483
+ if (h(this, "client"), h(this, "maxRetries"), h(this, "throttle"), h(this, "accessToken"), h(this, "cache"), h(this, "helpers"), h(this, "resolveCounter"), h(this, "relations"), h(this, "links"), h(this, "richTextResolver"), h(this, "resolveNestedRelations"), !t) {
484
+ const i = new v().getRegionURL, o = e.https === false ? "http" : "https";
485
+ e.oauthToken ? t = `${o}://${i(e.region)}/v1` : t = `${o}://${i(e.region)}/v2`;
486
+ }
487
+ const s = new Headers();
488
+ s.set("Content-Type", "application/json"), s.set("Accept", "application/json"), s.forEach((i, o) => {
489
+ e.headers && e.headers[o] && s.set(o, e.headers[o]);
490
+ });
491
+ let r = 5;
492
+ e.oauthToken && (s.set("Authorization", e.oauthToken), r = 3), e.rateLimit && (r = e.rateLimit), e.richTextSchema ? this.richTextResolver = new y(e.richTextSchema) : this.richTextResolver = new y(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 5, this.throttle = S(this.throttledRequest, r, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new v(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || true, this.client = new ne({
493
+ baseURL: t,
494
+ timeout: e.timeout || 0,
495
+ headers: s,
496
+ responseInterceptor: e.responseInterceptor,
497
+ fetch: e.fetch
498
+ });
499
+ }
500
+ setComponentResolver(e) {
501
+ this.richTextResolver.addNode("blok", (t) => {
502
+ let s = "";
503
+ return t.attrs.body.forEach((r) => {
504
+ s += e(r.component, r);
505
+ }), {
506
+ html: s
507
+ };
508
+ });
509
+ }
510
+ parseParams(e) {
511
+ return e.version || (e.version = "published"), e.token || (e.token = this.getToken()), e.cv || (e.cv = f[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), e;
512
+ }
513
+ factoryParamOptions(e, t) {
514
+ return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
515
+ }
516
+ makeRequest(e, t, s, r) {
517
+ const i = this.factoryParamOptions(
518
+ e,
519
+ this.helpers.getOptionsPage(t, s, r)
520
+ );
521
+ return this.cacheResponse(e, i);
522
+ }
523
+ get(e, t) {
524
+ t || (t = {});
525
+ const s = `/${e}`, r = this.factoryParamOptions(s, t);
526
+ return this.cacheResponse(s, r);
527
+ }
528
+ async getAll(e, t, s) {
529
+ const r = (t == null ? void 0 : t.per_page) || 25, i = `/${e}`, o = i.split("/"), c = s || o[o.length - 1], a = 1, l = await this.makeRequest(i, t, r, a), u = l.total ? Math.ceil(l.total / r) : 1, d = await this.helpers.asyncMap(
530
+ this.helpers.range(a, u),
531
+ (g) => this.makeRequest(i, t, r, g + 1)
532
+ );
533
+ return this.helpers.flatMap(
534
+ [l, ...d],
535
+ (g) => Object.values(g.data[c])
536
+ );
537
+ }
538
+ post(e, t) {
539
+ const s = `/${e}`;
540
+ return Promise.resolve(this.throttle("post", s, t));
541
+ }
542
+ put(e, t) {
543
+ const s = `/${e}`;
544
+ return Promise.resolve(this.throttle("put", s, t));
545
+ }
546
+ delete(e, t) {
547
+ const s = `/${e}`;
548
+ return Promise.resolve(this.throttle("delete", s, t));
549
+ }
550
+ getStories(e) {
551
+ return this.get("cdn/stories", e);
552
+ }
553
+ getStory(e, t) {
554
+ return this.get(`cdn/stories/${e}`, t);
555
+ }
556
+ getToken() {
557
+ return this.accessToken;
558
+ }
559
+ ejectInterceptor() {
560
+ this.client.eject();
561
+ }
562
+ _cleanCopy(e) {
563
+ return JSON.parse(JSON.stringify(e));
564
+ }
565
+ _insertLinks(e, t, s) {
566
+ const r = e[t];
567
+ 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]));
568
+ }
569
+ _insertRelations(e, t, s, r) {
570
+ if (s.indexOf(`${e.component}.${t}`) > -1) {
571
+ if (typeof e[t] == "string")
572
+ this.relations[r][e[t]] && (e[t] = this._cleanCopy(
573
+ this.relations[r][e[t]]
574
+ ));
575
+ else if (e[t] && e[t].constructor === Array) {
576
+ const i = [];
577
+ e[t].forEach((o) => {
578
+ this.relations[r][o] && i.push(this._cleanCopy(this.relations[r][o]));
579
+ }), e[t] = i;
580
+ }
581
+ }
582
+ }
583
+ iterateTree(e, t, s) {
584
+ const r = (i) => {
585
+ if (i != null) {
586
+ if (i.constructor === Array)
587
+ for (let o = 0; o < i.length; o++)
588
+ r(i[o]);
589
+ else if (i.constructor === Object) {
590
+ if (i._stopResolving)
591
+ return;
592
+ for (const o in i)
593
+ (i.component && i._uid || i.type === "link") && (this._insertRelations(
594
+ i,
595
+ o,
596
+ t,
597
+ s
598
+ ), this._insertLinks(
599
+ i,
600
+ o,
601
+ s
602
+ )), r(i[o]);
603
+ }
604
+ }
605
+ };
606
+ r(e.content);
607
+ }
608
+ async resolveLinks(e, t, s) {
609
+ let r = [];
610
+ if (e.link_uuids) {
611
+ const i = e.link_uuids.length, o = [], c = 50;
612
+ for (let a = 0; a < i; a += c) {
613
+ const l = Math.min(i, a + c);
614
+ o.push(e.link_uuids.slice(a, l));
615
+ }
616
+ for (let a = 0; a < o.length; a++)
617
+ (await this.getStories({
618
+ per_page: c,
619
+ language: t.language,
620
+ version: t.version,
621
+ by_uuids: o[a].join(",")
622
+ })).data.stories.forEach(
623
+ (l) => {
624
+ r.push(l);
625
+ }
626
+ );
627
+ } else
628
+ r = e.links;
629
+ r.forEach((i) => {
630
+ this.links[s][i.uuid] = {
631
+ ...i,
632
+ _stopResolving: true
633
+ };
634
+ });
635
+ }
636
+ async resolveRelations(e, t, s) {
637
+ let r = [];
638
+ if (e.rel_uuids) {
639
+ const i = e.rel_uuids.length, o = [], c = 50;
640
+ for (let a = 0; a < i; a += c) {
641
+ const l = Math.min(i, a + c);
642
+ o.push(e.rel_uuids.slice(a, l));
643
+ }
644
+ for (let a = 0; a < o.length; a++)
645
+ (await this.getStories({
646
+ per_page: c,
647
+ language: t.language,
648
+ version: t.version,
649
+ by_uuids: o[a].join(",")
650
+ })).data.stories.forEach((l) => {
651
+ r.push(l);
652
+ });
653
+ } else
654
+ r = e.rels;
655
+ r && r.length > 0 && r.forEach((i) => {
656
+ this.relations[s][i.uuid] = {
657
+ ...i,
658
+ _stopResolving: true
659
+ };
660
+ });
661
+ }
662
+ async resolveStories(e, t, s) {
663
+ var r, i;
664
+ let o = [];
665
+ 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"].indexOf(t.resolve_links) > -1 && ((r = e.links) != null && r.length || (i = e.link_uuids) != null && i.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
666
+ for (const c in this.relations[s])
667
+ this.iterateTree(
668
+ this.relations[s][c],
669
+ o,
670
+ s
671
+ );
672
+ e.story ? this.iterateTree(e.story, o, s) : e.stories.forEach((c) => {
673
+ this.iterateTree(c, o, s);
674
+ }), delete this.links[s], delete this.relations[s];
675
+ }
676
+ async cacheResponse(e, t, s) {
677
+ const r = this.helpers.stringify({ url: e, params: t }), i = this.cacheProvider();
678
+ if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
679
+ const o = await i.get(r);
680
+ if (o)
681
+ return Promise.resolve(o);
682
+ }
683
+ return new Promise((o, c) => {
684
+ try {
685
+ (async () => {
686
+ var a;
687
+ try {
688
+ const l = await this.throttle("get", e, t);
689
+ let u = { data: l.data, headers: l.headers };
690
+ if ((a = l.headers) != null && a["per-page"] && (u = Object.assign({}, u, {
691
+ perPage: l.headers["per-page"] ? parseInt(l.headers["per-page"]) : 0,
692
+ total: l.headers["per-page"] ? parseInt(l.headers.total) : 0
693
+ })), l.status != 200)
694
+ return c(l);
695
+ if (u.data.story || u.data.stories) {
696
+ const d = this.resolveCounter = ++this.resolveCounter % 1e3;
697
+ await this.resolveStories(u.data, t, `${d}`);
698
+ }
699
+ return t.version === "published" && e != "/cdn/spaces/me" && await i.set(r, u), u.data.cv && t.token && (t.version == "draft" && f[t.token] != u.data.cv && await this.flushCache(), f[t.token] = u.data.cv), o(u);
700
+ } catch (l) {
701
+ return c(l);
702
+ }
703
+ })();
704
+ } catch {
705
+ }
706
+ });
707
+ }
708
+ throttledRequest(e, t, s) {
709
+ return this.client[e](t, s);
710
+ }
711
+ cacheVersions() {
712
+ return f;
713
+ }
714
+ cacheVersion() {
715
+ return f[this.accessToken];
716
+ }
717
+ setCacheVersion(e) {
718
+ this.accessToken && (f[this.accessToken] = e);
719
+ }
720
+ cacheProvider() {
721
+ switch (this.cache.type) {
722
+ case "memory":
723
+ return {
724
+ get(e) {
725
+ return Promise.resolve(m[e]);
726
+ },
727
+ getAll() {
728
+ return Promise.resolve(m);
729
+ },
730
+ set(e, t) {
731
+ return m[e] = t, Promise.resolve(void 0);
732
+ },
733
+ flush() {
734
+ return m = {}, Promise.resolve(void 0);
735
+ }
736
+ };
737
+ case "custom":
738
+ if (this.cache.custom)
739
+ return this.cache.custom;
740
+ default:
741
+ return {
742
+ get() {
743
+ return Promise.resolve(void 0);
744
+ },
745
+ getAll() {
746
+ return Promise.resolve(void 0);
747
+ },
748
+ set() {
749
+ return Promise.resolve(void 0);
750
+ },
751
+ flush() {
752
+ return Promise.resolve(void 0);
753
+ }
754
+ };
755
+ }
756
+ }
757
+ async flushCache() {
758
+ return await this.cacheProvider().flush(), this;
759
+ }
760
+ }
761
+ const le = (n = {}) => {
762
+ const { apiOptions: e } = n;
763
+ if (!e.accessToken) {
764
+ console.error(
765
+ "You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication"
766
+ );
767
+ return;
768
+ }
769
+ return { storyblokApi: new ae(e) };
770
+ }, ce = (n) => {
771
+ if (typeof n != "object" || typeof n._editable > "u")
772
+ return {};
773
+ const e = JSON.parse(
774
+ n._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
775
+ );
776
+ return {
777
+ "data-blok-c": JSON.stringify(e),
778
+ "data-blok-uid": e.id + "-" + e.uid
779
+ };
780
+ };
781
+ let w;
782
+ const x = "https://app.storyblok.com/f/storyblok-v2-latest.js", he = (n, e, t = {}) => {
783
+ var c;
784
+ const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = +new URL((c = window.location) == null ? void 0 : c.href).searchParams.get(
785
+ "_storyblok"
786
+ ) === n;
787
+ if (!(!r || !o)) {
788
+ if (!n) {
789
+ console.warn("Story ID is not defined. Please provide a valid ID.");
790
+ return;
791
+ }
792
+ window.storyblokRegisterEvent(() => {
793
+ new window.StoryblokBridge(t).on(["input", "published", "change"], (l) => {
794
+ l.action === "input" && l.story.id === n ? e(l.story) : (l.action === "change" || l.action === "published") && l.storyId === n && window.location.reload();
795
+ });
796
+ });
797
+ }
798
+ }, ue = (n = {}) => {
799
+ var u, d;
800
+ const {
801
+ bridge: e,
802
+ accessToken: t,
803
+ use: s = [],
804
+ apiOptions: r = {},
805
+ richText: i = {}
806
+ } = n;
807
+ r.accessToken = r.accessToken || t;
808
+ const o = { bridge: e, apiOptions: r };
809
+ let c = {};
810
+ s.forEach((g) => {
811
+ c = { ...c, ...g(o) };
812
+ });
813
+ const l = !(typeof window > "u") && ((d = (u = window.location) == null ? void 0 : u.search) == null ? void 0 : d.includes("_storyblok_tk"));
814
+ return e !== false && l && j(x), w = new y(i.schema), i.resolver && E(w, i.resolver), c;
815
+ }, E = (n, e) => {
816
+ n.addNode("blok", (t) => {
817
+ let s = "";
818
+ return t.attrs.body.forEach((r) => {
819
+ s += e(r.component, r);
820
+ }), {
821
+ html: s
822
+ };
823
+ });
824
+ }, de = (n, e, t) => {
825
+ let s = t || w;
826
+ if (!s) {
827
+ console.error(
828
+ "Please initialize the Storyblok SDK before calling the renderRichText function"
829
+ );
830
+ return;
831
+ }
832
+ return n === "" ? "" : n ? (e && (s = new y(e.schema), e.resolver && E(s, e.resolver)), s.render(n)) : (console.warn(`${n} is not a valid Richtext object. This might be because the value of the richtext field is empty.
833
+
834
+ For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`), "");
835
+ }, pe = () => j(x);
836
+ export {
837
+ ce as c,
838
+ de as d,
839
+ he as h,
840
+ ie as i,
841
+ le as l,
842
+ pe as p,
843
+ ue as u,
844
+ y
845
+ };