@voltro/cms 0.83.1 → 0.85.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4367 @@
1
+ import { Schema as e } from "effect";
2
+ import { createElement as t, useEffect as n, useId as r, useMemo as i, useRef as a, useState as o } from "react";
3
+ import { Fragment as s, jsx as c, jsxs as l } from "react/jsx-runtime";
4
+ //#region src/fieldSchema.ts
5
+ var u = (e) => ({
6
+ ...e,
7
+ pipe(...t) {
8
+ let n = e;
9
+ for (let e of t) n = e(n);
10
+ return u(n);
11
+ },
12
+ optional() {
13
+ return u({
14
+ ...e,
15
+ isOptional: !0
16
+ });
17
+ },
18
+ requiredToPublish() {
19
+ return u({
20
+ ...e,
21
+ isOptional: !0,
22
+ publishRequired: !0
23
+ });
24
+ }
25
+ }), d = (e) => (t) => ({
26
+ ...t,
27
+ maxLength: e,
28
+ editorHint: t.kind === "string" && e > 120 ? "textarea" : t.editorHint
29
+ }), f = (e) => (t) => ({
30
+ ...t,
31
+ pattern: e.source
32
+ }), p = () => (e) => ({
33
+ ...e,
34
+ unique: !0
35
+ }), m = (e, t) => u({
36
+ kind: e,
37
+ editorHint: t,
38
+ isOptional: !1
39
+ }), h = {
40
+ String: m("string", "text"),
41
+ Number: m("number", "number"),
42
+ Fraction: u({
43
+ kind: "number",
44
+ editorHint: "number",
45
+ isOptional: !1,
46
+ fraction: !0
47
+ }),
48
+ Boolean: m("boolean", "boolean"),
49
+ Date: m("date", "date"),
50
+ DateTime: m("datetime", "datetime"),
51
+ maxLength: d,
52
+ pattern: f,
53
+ unique: p,
54
+ Literal: (...e) => u({
55
+ kind: "literal",
56
+ editorHint: "select",
57
+ isOptional: !1,
58
+ literals: e
59
+ }),
60
+ Token: (e, t) => {
61
+ let n = e[t];
62
+ if (n === void 0 || Object.keys(n).length === 0) throw Error(`Schema.Token: the design tokens declare no group '${t}'.`);
63
+ return u({
64
+ kind: "literal",
65
+ editorHint: "select",
66
+ isOptional: !1,
67
+ token: t,
68
+ literals: Object.keys(n),
69
+ literalLabels: Object.fromEntries(Object.entries(n).map(([e, t]) => [e, `${e} — ${t}`]))
70
+ });
71
+ },
72
+ Action: (e) => {
73
+ let t = Object.keys(e);
74
+ if (t.length === 0) throw Error("Schema.Action: name at least one action.");
75
+ return u({
76
+ kind: "literal",
77
+ editorHint: "select",
78
+ isOptional: !1,
79
+ action: !0,
80
+ literals: t,
81
+ literalLabels: { ...e }
82
+ });
83
+ },
84
+ RichText: (e = {}) => u({
85
+ kind: "richText",
86
+ editorHint: "richText",
87
+ isOptional: !1,
88
+ richText: e
89
+ }),
90
+ Media: () => u({
91
+ kind: "media",
92
+ editorHint: "media",
93
+ isOptional: !1
94
+ }),
95
+ Reference: (e) => u({
96
+ kind: "reference",
97
+ editorHint: "reference",
98
+ isOptional: !1,
99
+ referenceType: e
100
+ }),
101
+ Array: (e) => u({
102
+ kind: "array",
103
+ editorHint: "array",
104
+ isOptional: !1,
105
+ element: e
106
+ }),
107
+ Struct: (e) => u({
108
+ kind: "struct",
109
+ editorHint: "struct",
110
+ isOptional: !1,
111
+ struct: e
112
+ }),
113
+ Components: (e) => {
114
+ let t = e.map((e) => e.id), n = t.find((e, n) => t.indexOf(e) !== n);
115
+ if (n !== void 0) throw Error(`Schema.Components: component '${n}' is listed twice.`);
116
+ return u({
117
+ kind: "components",
118
+ editorHint: "components",
119
+ isOptional: !1,
120
+ components: e
121
+ });
122
+ }
123
+ }, g = (e) => Object.keys(e).sort().map((t) => {
124
+ let n = e[t], r = n.struct ? `{${g(n.struct)}}` : n.element ? `[${g({ _: n.element })}]` : "";
125
+ return `${t}:${n.kind}${n.isOptional ? "?" : ""}${n.literals ? `(${n.literals.join("|")})` : ""}${n.referenceType ? `->${n.referenceType}` : ""}${r}`;
126
+ }).join(","), _ = (e) => {
127
+ let t = 2166136261;
128
+ for (let n = 0; n < e.length; n++) t ^= e.charCodeAt(n), t = Math.imul(t, 16777619);
129
+ return (t >>> 0).toString(16).padStart(8, "0");
130
+ }, v = (e) => _(`${e.id}|${g(e.props)}`), y = (e) => {
131
+ for (let [t, n] of Object.entries(e)) for (let e of [t, ...Object.keys(n)]) if (!/^[a-z][a-zA-Z0-9]*$/.test(e)) throw Error(`defineDesignTokens: '${e}' must be camelCase letters and digits.`);
132
+ return e;
133
+ }, b = (e) => {
134
+ if (!/^[a-z][a-zA-Z0-9]*$/.test(e.name)) throw Error(`defineRichTextProfile('${e.name}'): the name must be camelCase letters and digits.`);
135
+ if (!Number.isInteger(e.version) || e.version < 1) throw Error(`defineRichTextProfile('${e.name}'): the version is a whole number from 1.`);
136
+ let t = e.styles === void 0 ? void 0 : e.styles.tokens[e.styles.group];
137
+ if (e.styles !== void 0 && (t === void 0 || Object.keys(t).length === 0)) throw Error(`defineRichTextProfile('${e.name}'): the design tokens declare no group '${e.styles.group}'.`);
138
+ let n = e.components ?? [], r = n.map((e) => e.id);
139
+ if (new Set(r).size !== r.length) throw Error(`defineRichTextProfile('${e.name}'): a component is listed twice.`);
140
+ let i = [...e.blocks ?? [
141
+ "paragraph",
142
+ "heading",
143
+ "list",
144
+ "table",
145
+ "image",
146
+ "file"
147
+ ], ...n.length > 0 ? ["component"] : []];
148
+ return {
149
+ name: e.name,
150
+ version: e.version,
151
+ id: `${e.name}@${e.version}`,
152
+ blocks: i,
153
+ headings: e.headings ?? [2, 3],
154
+ marks: e.marks ?? [
155
+ "bold",
156
+ "italic",
157
+ "underline"
158
+ ],
159
+ ...e.styles !== void 0 && t !== void 0 ? { styles: {
160
+ group: e.styles.group,
161
+ tokens: t
162
+ } } : {},
163
+ components: n,
164
+ ...e.contactPoints === void 0 ? {} : { contactPoints: e.contactPoints },
165
+ contactLiterals: e.contactLiterals === !0
166
+ };
167
+ }, ee = (e) => {
168
+ if (!/^[a-z][a-zA-Z0-9]*$/.test(e.id)) throw Error(`defineComponent('${e.id}'): the id must be camelCase letters and digits.`);
169
+ let t = e.props;
170
+ return {
171
+ id: e.id,
172
+ displayName: e.displayName,
173
+ props: t,
174
+ fingerprint: _(`${e.id}|${g(t)}`),
175
+ ...e.consent === void 0 ? {} : { consent: e.consent },
176
+ ...e.description !== void 0 && e.description.trim() !== "" ? { description: e.description.trim() } : {},
177
+ ...e.jobs !== void 0 && e.jobs.length > 0 ? { jobs: [...new Set(e.jobs.map((e) => e.trim()).filter((e) => e !== ""))] } : {},
178
+ ...e.variants === void 0 ? {} : { variants: e.variants },
179
+ ...e.fixtures === void 0 ? {} : { fixtures: e.fixtures },
180
+ ...e.migrations === void 0 ? {} : { migrations: e.migrations }
181
+ };
182
+ }, te = (e, t) => (n) => ({
183
+ ...n,
184
+ derived: {
185
+ source: e,
186
+ transform: t
187
+ }
188
+ }), x = {
189
+ ä: "ae",
190
+ ö: "oe",
191
+ ü: "ue",
192
+ ß: "ss",
193
+ æ: "ae",
194
+ œ: "oe",
195
+ ø: "o",
196
+ å: "a",
197
+ ł: "l",
198
+ đ: "d",
199
+ þ: "th"
200
+ }, ne = (e) => String(e).normalize("NFC").toLowerCase().trim().replace(/[äöüßæœøåłđþ]/g, (e) => x[e] ?? e).normalize("NFKD").replace(/[\u0300-\u036f]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, ""), S = (e) => Array.isArray(e) ? e.map((e) => typeof e == "object" && e ? String(e.componentId ?? "") : "") : [], C = (e, t) => {
201
+ let n = e.templates, r = n === void 0 ? void 0 : t[n.field];
202
+ if (n !== void 0 && typeof r == "string" && r !== "") return n.list.find((e) => e.id === r) ?? null;
203
+ }, w = (e, t) => {
204
+ let n = e.templates, r = C(e, t);
205
+ if (n === void 0 || r === void 0) return [];
206
+ if (r === null) return [{
207
+ field: n.field,
208
+ rule: "unknown",
209
+ message: `no template '${String(t[n.field])}' for ${e.name}`
210
+ }];
211
+ let i = S(t[n.components]), a = [];
212
+ for (let e of r.required ?? []) i.includes(e.id) || a.push({
213
+ field: n.components,
214
+ rule: "required",
215
+ message: `the ${r.displayName} template needs a ${e.displayName}`
216
+ });
217
+ r.first !== void 0 && i.length > 0 && i[0] !== r.first.id && a.push({
218
+ field: n.components,
219
+ rule: "position",
220
+ message: `the ${r.displayName} template starts with a ${r.first.displayName}`
221
+ });
222
+ for (let e of r.max ?? []) i.filter((t) => t === e.component.id).length > e.count && a.push({
223
+ field: n.components,
224
+ rule: "max",
225
+ message: `the ${r.displayName} template allows at most ${e.count} ${e.component.displayName}`
226
+ });
227
+ for (let [n, i] of Object.entries(r.regions ?? {})) {
228
+ let o = S(t[n]), s = i.allowed === void 0 ? void 0 : new Set(i.allowed.map((e) => e.id)), c = new Map((e.fields[n]?.components ?? []).map((e) => [e.id, e.displayName]));
229
+ for (let e of new Set(o)) s !== void 0 && !s.has(e) && a.push({
230
+ field: n,
231
+ rule: "region",
232
+ message: `the ${r.displayName} template does not allow a ${c.get(e) ?? e} in ${n}`
233
+ });
234
+ for (let e of i.required ?? []) o.includes(e.id) || a.push({
235
+ field: n,
236
+ rule: "required",
237
+ message: `the ${r.displayName} template needs a ${e.displayName} in ${n}`
238
+ });
239
+ i.maxItems !== void 0 && o.length > i.maxItems && a.push({
240
+ field: n,
241
+ rule: "max",
242
+ message: `the ${r.displayName} template allows at most ${i.maxItems} in ${n}`
243
+ });
244
+ }
245
+ let o = n.width ?? "width", s = [n.components, ...Object.keys(r.regions ?? {})].flatMap((e) => (Array.isArray(t[e]) ? t[e] : []).map((t, n) => ({
246
+ field: e,
247
+ index: n,
248
+ item: t
249
+ })));
250
+ for (let e of r.widths ?? []) for (let { field: t, index: n, item: i } of s) {
251
+ let s = i?.props?.[o];
252
+ i?.componentId === e.component.id && typeof s == "string" && !e.allowed.includes(s) && a.push({
253
+ field: `${t}[${n}].props.${o}`,
254
+ rule: "width",
255
+ message: `in the ${r.displayName} template a ${e.component.displayName} is ${e.allowed.join(" or ")}, not ${s}`
256
+ });
257
+ }
258
+ if (r.maxDepth !== void 0) for (let { field: e, index: t, item: n } of s) T(n) > r.maxDepth && a.push({
259
+ field: `${e}[${t}]`,
260
+ rule: "depth",
261
+ message: `the ${r.displayName} template nests components at most ${r.maxDepth} deep`
262
+ });
263
+ return a;
264
+ }, T = (e) => {
265
+ let t = Object.values(e?.props ?? {}).filter((e) => Array.isArray(e) && e.some((e) => typeof e == "object" && !!e && typeof e.componentId == "string"));
266
+ return 1 + Math.max(0, ...t.flatMap((e) => e.map(T)));
267
+ }, E = (e, t) => {
268
+ let n = e.templates, r = n?.list.find((e) => e.id === t);
269
+ return n === void 0 || r === void 0 ? null : {
270
+ ...r.values,
271
+ [n.field]: r.id,
272
+ [n.components]: (r.sections ?? []).map((e) => ({
273
+ componentId: e.component.id,
274
+ props: { ...e.props }
275
+ }))
276
+ };
277
+ }, re = (e, t, n) => {
278
+ let r = (t) => {
279
+ throw Error(`defineContentType('${e}'): templates ${t}`);
280
+ }, i = t[n.field];
281
+ (i === void 0 || i.kind !== "string" || !i.isOptional) && r(`field '${n.field}' must be a declared optional string field.`);
282
+ let a = t[n.components];
283
+ (a === void 0 || a.kind !== "components") && r(`components '${n.components}' must be a declared Schema.Components field.`);
284
+ let o = new Set((a?.components ?? []).map((e) => e.id)), s = /* @__PURE__ */ new Set();
285
+ for (let e of n.list) {
286
+ s.has(e.id) && r(`id '${e.id}' is declared twice.`), s.add(e.id);
287
+ let i = [
288
+ ...(e.sections ?? []).map((e) => e.component),
289
+ ...e.required ?? [],
290
+ ...e.first ? [e.first] : [],
291
+ ...(e.max ?? []).map((e) => e.component)
292
+ ];
293
+ for (let t of i) o.has(t.id) || r(`'${e.id}' uses '${t.id}', which '${n.components}' does not allow.`);
294
+ for (let [i, a] of Object.entries(e.regions ?? {})) {
295
+ let o = t[i];
296
+ (o === void 0 || o.kind !== "components" || i === n.components) && r(`'${e.id}' region '${i}' must be another declared Schema.Components field.`);
297
+ let s = new Set((o?.components ?? []).map((e) => e.id));
298
+ for (let t of [...a.allowed ?? [], ...a.required ?? []]) s.has(t.id) || r(`'${e.id}' region '${i}' uses '${t.id}', which '${i}' does not allow.`);
299
+ }
300
+ e.maxDepth !== void 0 && (!Number.isInteger(e.maxDepth) || e.maxDepth < 1) && r(`'${e.id}' maxDepth must be a whole number from 1.`);
301
+ }
302
+ }, ie = 3, D = (e, t) => t === 0 ? e.ordered : (e.sublists?.[t - 1] ?? (e.ordered ? "ordered" : "unordered")) === "ordered", ae = /* @__PURE__ */ new Set([
303
+ "bold",
304
+ "italic",
305
+ "underline"
306
+ ]), oe = /* @__PURE__ */ new Set([
307
+ "paragraph",
308
+ "heading",
309
+ "list",
310
+ "table",
311
+ "image",
312
+ "file",
313
+ "component"
314
+ ]), O = (e) => typeof e == "object" && !!e && !Array.isArray(e), se = () => `rb_${crypto.randomUUID().replace(/-/g, "")}`, ce = () => ({
315
+ type: "doc",
316
+ blocks: []
317
+ }), k = (e, t) => {
318
+ let n = t === void 0 ? {} : { profile: t.id };
319
+ return typeof e == "string" ? {
320
+ type: "doc",
321
+ blocks: e.split(/\n{2,}/).map((e) => e.trim()).filter((e) => e !== "").map((e) => ({
322
+ id: se(),
323
+ type: "paragraph",
324
+ content: [{
325
+ type: "text",
326
+ text: e
327
+ }]
328
+ })),
329
+ ...n
330
+ } : !O(e) || e.type !== "doc" || !Array.isArray(e.blocks) ? e : {
331
+ ...e,
332
+ blocks: e.blocks.map((e) => O(e) && (typeof e.id != "string" || e.id === "") ? {
333
+ ...e,
334
+ id: se()
335
+ } : e),
336
+ ...n
337
+ };
338
+ }, le = /^[^\s@<>()[\],;:"]+@[^\s@<>()[\],;:"]+\.[^\s@<>()[\],;:"]{2,}$/, ue = /^\+?[0-9][0-9 ()/.-]*[0-9]$/, de = (e, t) => {
339
+ if (e === "email") return t.length <= 254 && le.test(t) ? null : "not an e-mail address";
340
+ let n = t.replace(/[^0-9]/g, "").length;
341
+ return ue.test(t) && n >= 5 && n <= 15 ? null : "not a phone number (5 to 15 digits, an optional leading +)";
342
+ }, fe = (e, t) => e === "email" ? `mailto:${t}` : `tel:${t.replace(/[^0-9+]/g, "")}`, pe = (e, t, n) => {
343
+ t !== void 0 && (!O(t) || t.kind !== "insert" && t.kind !== "delete" || typeof t.id != "string" || t.id === "" || typeof t.by != "string" || t.by === "" || typeof t.at != "string" || Number.isNaN(Date.parse(t.at))) && n.push({
344
+ path: `${e}.change`,
345
+ rule: "type",
346
+ message: "a suggested change has an id, a kind (insert or delete), who made it and when"
347
+ });
348
+ }, me = (e, t, n, r) => {
349
+ if (t === void 0) return;
350
+ let i = n.profile?.styles;
351
+ if (i === void 0) return void r.push({
352
+ path: `${e}.style`,
353
+ rule: "profile",
354
+ message: "this field has no styles"
355
+ });
356
+ (typeof t != "string" || !(t in i.tokens)) && r.push({
357
+ path: `${e}.style`,
358
+ rule: "profile",
359
+ message: `a style is one of: ${Object.keys(i.tokens).join(", ")}`
360
+ });
361
+ }, he = (e, t, n, r) => {
362
+ if (!Array.isArray(t)) {
363
+ r.push({
364
+ path: e,
365
+ rule: "type",
366
+ message: "expected a list of inline nodes"
367
+ });
368
+ return;
369
+ }
370
+ let i = n.profile;
371
+ t.forEach((t, a) => {
372
+ let o = `${e}[${a}]`;
373
+ if (!O(t)) return void r.push({
374
+ path: o,
375
+ rule: "type",
376
+ message: "expected an inline node"
377
+ });
378
+ if (pe(o, t.change, r), t.type === "text") {
379
+ typeof t.text != "string" && r.push({
380
+ path: o,
381
+ rule: "type",
382
+ message: "text must be a string"
383
+ });
384
+ let e = t.marks;
385
+ return e !== void 0 && (!Array.isArray(e) || e.some((e) => !ae.has(String(e)))) ? r.push({
386
+ path: o,
387
+ rule: "unknown",
388
+ message: `marks must be ${[...ae].join(" / ")}`
389
+ }) : i !== void 0 && Array.isArray(e) && e.some((e) => !i.marks.includes(e)) && r.push({
390
+ path: `${o}.marks`,
391
+ rule: "profile",
392
+ message: `this field allows the marks: ${i.marks.join(", ") || "none"}`
393
+ }), me(o, t.style, n, r);
394
+ }
395
+ if (t.type === "link") {
396
+ if (n.links === void 0) return void r.push({
397
+ path: o,
398
+ rule: "richText",
399
+ message: "links are not allowed in this field"
400
+ });
401
+ (typeof t.target != "string" || t.target === "") && r.push({
402
+ path: o,
403
+ rule: "required",
404
+ message: "a link needs a target document"
405
+ }), (typeof t.text != "string" || t.text === "") && r.push({
406
+ path: o,
407
+ rule: "required",
408
+ message: "a link needs text"
409
+ });
410
+ return;
411
+ }
412
+ if (t.type === "contact") {
413
+ (typeof t.text != "string" || t.text === "") && r.push({
414
+ path: o,
415
+ rule: "required",
416
+ message: "a contact needs text"
417
+ });
418
+ let e = t.contact;
419
+ if (!O(e)) return void r.push({
420
+ path: `${o}.contact`,
421
+ rule: "type",
422
+ message: "expected a contact point or an address"
423
+ });
424
+ if ("target" in e) {
425
+ if (i?.contactPoints === void 0) return void r.push({
426
+ path: o,
427
+ rule: "profile",
428
+ message: "this field names no contact points"
429
+ });
430
+ (typeof e.target != "string" || e.target === "") && r.push({
431
+ path: `${o}.contact.target`,
432
+ rule: "required",
433
+ message: "a contact needs its contact point"
434
+ });
435
+ return;
436
+ }
437
+ if (i?.contactLiterals !== !0) return void r.push({
438
+ path: o,
439
+ rule: "profile",
440
+ message: "this field takes no one-off addresses or numbers"
441
+ });
442
+ let n = e.channel;
443
+ if (n !== "email" && n !== "phone") return void r.push({
444
+ path: `${o}.contact.channel`,
445
+ rule: "literal",
446
+ message: "a contact is an email or a phone"
447
+ });
448
+ let a = typeof e.value == "string" ? de(n, e.value) : "missing";
449
+ a !== null && r.push({
450
+ path: `${o}.contact.value`,
451
+ rule: "contact",
452
+ message: a
453
+ });
454
+ return;
455
+ }
456
+ r.push({
457
+ path: o,
458
+ rule: "unknown",
459
+ message: `unknown inline node '${String(t.type)}'`
460
+ });
461
+ });
462
+ }, ge = (e, t, n) => {
463
+ let r = [];
464
+ if (!O(t) || t.type !== "doc" || !Array.isArray(t.blocks)) return [{
465
+ path: e,
466
+ rule: "type",
467
+ message: "expected a rich document ({ type: 'doc', blocks })"
468
+ }];
469
+ let i = n.profile, a = /* @__PURE__ */ new Set();
470
+ return t.blocks.forEach((t, o) => {
471
+ let s = `${e}.blocks[${o}]`;
472
+ if (!O(t)) return void r.push({
473
+ path: s,
474
+ rule: "type",
475
+ message: "expected a block"
476
+ });
477
+ let c = t.id;
478
+ typeof c != "string" || c === "" ? r.push({
479
+ path: `${s}.id`,
480
+ rule: "required",
481
+ message: "every block needs an id"
482
+ }) : a.has(c) ? r.push({
483
+ path: `${s}.id`,
484
+ rule: "unique",
485
+ message: `block id '${c}' is used twice`
486
+ }) : a.add(c), pe(s, t.change, r);
487
+ let l = t.type;
488
+ if (i !== void 0 && oe.has(String(l)) && !i.blocks.includes(l)) {
489
+ r.push({
490
+ path: s,
491
+ rule: "profile",
492
+ message: `this field allows the blocks: ${i.blocks.join(", ")}`
493
+ });
494
+ return;
495
+ }
496
+ switch ((l === "paragraph" || l === "heading" || l === "list") && me(s, t.style, n, r), l) {
497
+ case "paragraph": return he(`${s}.content`, t.content, n, r);
498
+ case "heading": return t.level !== 2 && t.level !== 3 ? r.push({
499
+ path: `${s}.level`,
500
+ rule: "literal",
501
+ message: "a heading is level 2 or 3"
502
+ }) : i !== void 0 && !i.headings.includes(t.level) && r.push({
503
+ path: `${s}.level`,
504
+ rule: "profile",
505
+ message: `this field allows heading levels: ${i.headings.join(", ")}`
506
+ }), he(`${s}.content`, t.content, n, r);
507
+ case "list": {
508
+ let e = t.items;
509
+ if (typeof t.ordered != "boolean" && r.push({
510
+ path: `${s}.ordered`,
511
+ rule: "type",
512
+ message: "ordered must be true or false"
513
+ }), !Array.isArray(e)) return void r.push({
514
+ path: `${s}.items`,
515
+ rule: "type",
516
+ message: "expected list items"
517
+ });
518
+ let i = t.levels;
519
+ i !== void 0 && (!Array.isArray(i) || i.length !== e.length ? r.push({
520
+ path: `${s}.levels`,
521
+ rule: "type",
522
+ message: "one level per item"
523
+ }) : i.forEach((e, t) => {
524
+ let n = t === 0 ? -1 : Number(i[t - 1]);
525
+ (!Number.isInteger(e) || e < 0 || e > 3 || e > n + 1) && r.push({
526
+ path: `${s}.levels[${t}]`,
527
+ rule: "level",
528
+ message: "an item sits at most 3 deep, and at most one deeper than the item before it"
529
+ });
530
+ }));
531
+ let a = t.sublists;
532
+ return a !== void 0 && (!Array.isArray(a) || a.length > 3 || a.some((e) => e !== "ordered" && e !== "unordered")) && r.push({
533
+ path: `${s}.sublists`,
534
+ rule: "type",
535
+ message: "at most 3 kinds of nested lists, each ordered or unordered"
536
+ }), e.forEach((e, t) => he(`${s}.items[${t}]`, e, n, r));
537
+ }
538
+ case "table": {
539
+ let e = t.rows;
540
+ return typeof t.header != "boolean" && r.push({
541
+ path: `${s}.header`,
542
+ rule: "type",
543
+ message: "header must be true or false"
544
+ }), Array.isArray(e) ? e.forEach((e, t) => {
545
+ if (!Array.isArray(e)) return void r.push({
546
+ path: `${s}.rows[${t}]`,
547
+ rule: "type",
548
+ message: "expected a row of cells"
549
+ });
550
+ e.forEach((e, i) => he(`${s}.rows[${t}][${i}]`, e, n, r));
551
+ }) : void r.push({
552
+ path: `${s}.rows`,
553
+ rule: "type",
554
+ message: "expected table rows"
555
+ });
556
+ }
557
+ case "image":
558
+ if (n.images === void 0) return void r.push({
559
+ path: s,
560
+ rule: "richText",
561
+ message: "images are not allowed in this field"
562
+ });
563
+ (typeof t.asset != "string" || t.asset === "") && r.push({
564
+ path: `${s}.asset`,
565
+ rule: "required",
566
+ message: "an image needs an asset"
567
+ }), t.caption !== void 0 && typeof t.caption != "string" && r.push({
568
+ path: `${s}.caption`,
569
+ rule: "type",
570
+ message: "a caption is text"
571
+ });
572
+ return;
573
+ case "file":
574
+ if (n.files === void 0) return void r.push({
575
+ path: s,
576
+ rule: "richText",
577
+ message: "downloads are not allowed in this field"
578
+ });
579
+ (typeof t.asset != "string" || t.asset === "") && r.push({
580
+ path: `${s}.asset`,
581
+ rule: "required",
582
+ message: "a download needs a file"
583
+ }), (typeof t.label != "string" || t.label.trim() === "") && r.push({
584
+ path: `${s}.label`,
585
+ rule: "required",
586
+ message: "a download needs the text its link shows"
587
+ });
588
+ return;
589
+ case "component":
590
+ if (i === void 0 || i.components.length === 0) return void r.push({
591
+ path: s,
592
+ rule: "profile",
593
+ message: "components are not allowed in this field"
594
+ });
595
+ if (!i.components.some((e) => e.id === t.componentId)) {
596
+ r.push({
597
+ path: `${s}.componentId`,
598
+ rule: "unknown",
599
+ message: `'${String(t.componentId)}' is not a component this field allows`
600
+ });
601
+ return;
602
+ }
603
+ O(t.props) || r.push({
604
+ path: `${s}.props`,
605
+ rule: "type",
606
+ message: "expected an object"
607
+ });
608
+ return;
609
+ default: r.push({
610
+ path: s,
611
+ rule: "unknown",
612
+ message: `unknown block '${String(t.type)}'`
613
+ });
614
+ }
615
+ }), r;
616
+ }, _e = (e, t, n) => {
617
+ let r = [], i = n.profile?.contactPoints, a = (e, t) => {
618
+ t.forEach((t, a) => {
619
+ t.type === "link" && n.links !== void 0 && t.target !== "" && r.push({
620
+ path: `${e}[${a}]`,
621
+ targetType: n.links,
622
+ targetDocumentId: t.target
623
+ }), t.type === "contact" && i !== void 0 && "target" in t.contact && t.contact.target !== "" && r.push({
624
+ path: `${e}[${a}]`,
625
+ targetType: i,
626
+ targetDocumentId: t.contact.target
627
+ });
628
+ });
629
+ };
630
+ return t.blocks.forEach((t, i) => {
631
+ let o = `${e}.blocks[${i}]`;
632
+ switch (t.type) {
633
+ case "paragraph":
634
+ case "heading": return a(`${o}.content`, t.content);
635
+ case "list": return t.items.forEach((e, t) => a(`${o}.items[${t}]`, e));
636
+ case "table": return t.rows.forEach((e, t) => e.forEach((e, n) => a(`${o}.rows[${t}][${n}]`, e)));
637
+ case "image":
638
+ n.images !== void 0 && t.asset !== "" && r.push({
639
+ path: o,
640
+ targetType: n.images,
641
+ targetDocumentId: t.asset
642
+ });
643
+ return;
644
+ case "file":
645
+ n.files !== void 0 && t.asset !== "" && r.push({
646
+ path: o,
647
+ targetType: n.files,
648
+ targetDocumentId: t.asset
649
+ });
650
+ return;
651
+ case "component": return;
652
+ }
653
+ }), r;
654
+ }, ve = /[*_+[\]()\\{}|]/, ye = (e, t = []) => {
655
+ let n = [], r = "", i = [], a, o = () => {
656
+ if (r === "") return;
657
+ let e = n[n.length - 1];
658
+ e?.type === "text" && (e.marks ?? []).join() === i.join() && e.style === a && e.type === "text" ? n[n.length - 1] = {
659
+ ...e,
660
+ text: e.text + r
661
+ } : n.push({
662
+ type: "text",
663
+ text: r,
664
+ ...i.length > 0 ? { marks: [...i] } : {},
665
+ ...a === void 0 ? {} : { style: a }
666
+ }), r = "";
667
+ }, s = (e, t) => {
668
+ o(), i = t ? i.filter((t) => t !== e) : [...i, e];
669
+ }, c = 0;
670
+ for (; c < e.length;) {
671
+ let l = e[c];
672
+ if (l === "\\" && c + 1 < e.length && ve.test(e[c + 1])) {
673
+ r += e[c + 1], c += 2;
674
+ continue;
675
+ }
676
+ if (e.startsWith("**", c)) {
677
+ let t = i.includes("bold");
678
+ if (t || e.indexOf("**", c + 2) !== -1) {
679
+ s("bold", t), c += 2;
680
+ continue;
681
+ }
682
+ }
683
+ if (e.startsWith("++", c)) {
684
+ let t = i.includes("underline");
685
+ if (t || e.indexOf("++", c + 2) !== -1) {
686
+ s("underline", t), c += 2;
687
+ continue;
688
+ }
689
+ }
690
+ if (l === "_") {
691
+ let t = i.includes("italic");
692
+ if (t || e.indexOf("_", c + 1) !== -1) {
693
+ s("italic", t), c += 1;
694
+ continue;
695
+ }
696
+ }
697
+ if (l === "[") {
698
+ let t = /^\[([^\]]+)\]\((doc|contact|mailto|tel):([^)\s]+)\)/.exec(e.slice(c));
699
+ if (t !== null) {
700
+ o();
701
+ let [, e = "", r, i = ""] = t;
702
+ n.push(r === "doc" ? {
703
+ type: "link",
704
+ text: e,
705
+ target: i
706
+ } : r === "contact" ? {
707
+ type: "contact",
708
+ text: e,
709
+ contact: { target: i }
710
+ } : {
711
+ type: "contact",
712
+ text: e,
713
+ contact: {
714
+ channel: r === "mailto" ? "email" : "phone",
715
+ value: i
716
+ }
717
+ }), c += t[0].length;
718
+ continue;
719
+ }
720
+ }
721
+ if (l === "{" && a === void 0) {
722
+ let n = /^\{([a-z][a-zA-Z0-9]*)\|/.exec(e.slice(c));
723
+ if (n !== null && t.includes(n[1]) && e.indexOf("}", c) !== -1) {
724
+ o(), a = n[1], c += n[0].length;
725
+ continue;
726
+ }
727
+ }
728
+ if (l === "}" && a !== void 0) {
729
+ o(), a = void 0, c += 1;
730
+ continue;
731
+ }
732
+ r += l, c += 1;
733
+ }
734
+ return o(), n;
735
+ }, be = (e) => e.replace(/[*_+[\]()\\{}|]/g, (e) => `\\${e}`), A = (e) => e.map((e) => {
736
+ if (e.type === "link") return `[${be(e.text)}](doc:${e.target})`;
737
+ if (e.type === "contact") {
738
+ let t = "target" in e.contact ? `contact:${e.contact.target}` : `${e.contact.channel === "email" ? "mailto" : "tel"}:${e.contact.value}`;
739
+ return `[${be(e.text)}](${t})`;
740
+ }
741
+ let t = e.marks ?? [], n = t.includes("bold") ? "**" : "", r = t.includes("italic") ? "_" : "", i = t.includes("underline") ? "++" : "", a = `${n}${r}${i}${be(e.text)}${i}${r}${n}`;
742
+ return e.style === void 0 ? a : `{${e.style}|${a}}`;
743
+ }).join(""), xe = (e) => {
744
+ switch (e.type) {
745
+ case "paragraph":
746
+ case "heading": return A(e.content);
747
+ case "list": return e.items.map((t, n) => `${" ".repeat(e.levels?.[n] ?? 0)}${A(t)}`).join("\n");
748
+ case "table": return e.rows.map((e) => e.map(A).join(" | ")).join("\n");
749
+ case "image":
750
+ case "file":
751
+ case "component": return "";
752
+ }
753
+ }, Se = (e, t) => {
754
+ let n = [], r = [];
755
+ for (let i of e.split("\n")) {
756
+ if (i.trim() === "") continue;
757
+ let e = /^[ \t]*/.exec(i)[0].replace(/\t/g, " ").length, a = Math.floor(e / 2), o = Math.min(a, 3, r.length === 0 ? 0 : r[r.length - 1] + 1);
758
+ n.push(ye(i.trim(), t)), r.push(o);
759
+ }
760
+ return r.some((e) => e > 0) ? {
761
+ items: n,
762
+ levels: r
763
+ } : { items: n };
764
+ }, Ce = (e) => e.split("\n").map((e) => e.trim()).filter((e) => e !== ""), we = (e, t, n = []) => {
765
+ switch (e.type) {
766
+ case "paragraph":
767
+ case "heading": return {
768
+ ...e,
769
+ content: ye(t, n)
770
+ };
771
+ case "list": return {
772
+ id: e.id,
773
+ type: "list",
774
+ ordered: e.ordered,
775
+ ...Se(t, n),
776
+ ...e.change === void 0 ? {} : { change: e.change },
777
+ ...e.sublists === void 0 ? {} : { sublists: e.sublists },
778
+ ...e.style === void 0 ? {} : { style: e.style }
779
+ };
780
+ case "table": return {
781
+ ...e,
782
+ rows: Ce(t).map((e) => e.split("|").map((e) => ye(e.trim())))
783
+ };
784
+ case "image":
785
+ case "file":
786
+ case "component": return e;
787
+ }
788
+ }, Te = (e) => {
789
+ let t = (e) => e.map((e) => e.text).join("");
790
+ return e.blocks.map((e) => {
791
+ switch (e.type) {
792
+ case "paragraph":
793
+ case "heading": return t(e.content);
794
+ case "list": return e.items.map(t).join("\n");
795
+ case "table": return e.rows.map((e) => e.map(t).join(" ")).join("\n");
796
+ case "image": return e.caption ?? "";
797
+ case "file": return e.label;
798
+ case "component": return "";
799
+ }
800
+ }).filter((e) => e !== "").join("\n");
801
+ }, j = (e) => e.normalize("NFKC").trim().replace(/\s+/g, " ").toLowerCase(), Ee = (e, t) => {
802
+ let n = /* @__PURE__ */ new Map();
803
+ for (let t of e.terms) {
804
+ n.set(j(t.term), t.term);
805
+ for (let e of t.synonyms ?? []) n.set(j(e), t.term);
806
+ }
807
+ let r = [], i = [];
808
+ for (let e of t) {
809
+ if (typeof e != "string" || e.trim() === "") continue;
810
+ let t = n.get(j(e));
811
+ if (t !== void 0) r.includes(t) || r.push(t);
812
+ else {
813
+ let t = e.normalize("NFKC").trim().replace(/\s+/g, " ");
814
+ i.some((e) => j(e) === j(t)) || i.push(t);
815
+ }
816
+ }
817
+ return {
818
+ terms: r,
819
+ unknown: i
820
+ };
821
+ }, De = (e, t) => {
822
+ let { terms: n, unknown: r } = Ee(e, t);
823
+ return [...n, ...r];
824
+ }, Oe = (e) => {
825
+ if (e.terms.length === 0) return "names no terms";
826
+ let t = /* @__PURE__ */ new Map();
827
+ for (let n of e.terms) for (let e of [n.term, ...n.synonyms ?? []]) {
828
+ let r = j(e), i = t.get(r);
829
+ if (i !== void 0 && i !== n.term) return `'${e}' means both '${i}' and '${n.term}'`;
830
+ t.set(r, n.term);
831
+ }
832
+ return null;
833
+ }, ke = e.Struct({
834
+ field: e.String,
835
+ rule: e.String,
836
+ message: e.String
837
+ }), Ae = class extends e.TaggedError()("ContentValidationFailed", {
838
+ contentType: e.String,
839
+ violations: e.Array(ke)
840
+ }) {}, je = class extends e.TaggedError()("ContentNotFound", {
841
+ contentType: e.String,
842
+ id: e.String,
843
+ stage: e.Literals([
844
+ "draft",
845
+ "published",
846
+ "revision",
847
+ "share"
848
+ ])
849
+ }) {}, Me = class extends e.TaggedError()("ContentGone", {
850
+ contentType: e.String,
851
+ path: e.String
852
+ }) {}, Ne = class extends e.TaggedError()("ContentIdConflict", {
853
+ contentType: e.String,
854
+ id: e.String
855
+ }) {}, Pe = class extends e.TaggedError()("RevisionMismatch", {
856
+ contentType: e.String,
857
+ id: e.String,
858
+ expected: e.String,
859
+ actual: e.String
860
+ }) {}, Fe = class extends e.TaggedError()("ReleaseNotEditable", {
861
+ id: e.String,
862
+ status: e.String
863
+ }) {}, Ie = class extends e.TaggedError()("PreviewShareRejected", { reason: e.Literals(["expiryInPast", "expiryTooFar"]) }) {}, Le = class extends e.TaggedError()("ReviewRequired", {
864
+ contentType: e.String,
865
+ id: e.String,
866
+ revisionId: e.String
867
+ }) {}, Re = class extends e.TaggedError()("ReviewStepRefused", {
868
+ contentType: e.String,
869
+ id: e.String,
870
+ reason: e.Literals([
871
+ "notInReview",
872
+ "selfApproval",
873
+ "ambiguousOrder"
874
+ ])
875
+ }) {}, ze = class extends e.TaggedError()("ReferenceUnavailable", {
876
+ contentType: e.String,
877
+ id: e.String,
878
+ targets: e.Array(e.Struct({
879
+ path: e.String,
880
+ contentType: e.String,
881
+ documentId: e.String,
882
+ reason: e.Literals([
883
+ "blocked",
884
+ "expired",
885
+ "notYet",
886
+ "territory",
887
+ "channel",
888
+ "purpose"
889
+ ])
890
+ }))
891
+ }) {}, Be = class extends e.TaggedError()("QuotaExceeded", {
892
+ quota: e.String,
893
+ limit: e.Number,
894
+ used: e.Number
895
+ }) {}, M = (e) => e.type === "text" ? e.marks ?? [] : [], Ve = (e) => e.type === "text" ? e.style : void 0, He = (e, t) => e.length === t.length && e.every((e) => t.includes(e)), N = (e, t, n, r) => ({
896
+ type: "text",
897
+ text: e,
898
+ ...t.length > 0 ? { marks: [...t].sort() } : {},
899
+ ...n === void 0 ? {} : { style: n },
900
+ ...r === void 0 ? {} : { change: r }
901
+ }), Ue = (e, t) => t === void 0 ? N(e, []) : N(e, M(t), Ve(t), t.change), We = (e, t) => e.change?.id === t.change?.id && e.change?.kind === t.change?.kind, P = (e) => {
902
+ let t = [];
903
+ for (let n of e) {
904
+ if (n.text === "") continue;
905
+ let e = t[t.length - 1];
906
+ n.type === "text" && e?.type === "text" && He(M(e), M(n)) && Ve(e) === Ve(n) && We(e, n) ? t[t.length - 1] = Ue(e.text + n.text, n) : t.push(n.type === "text" ? Ue(n.text, n) : n);
907
+ }
908
+ return t;
909
+ }, F = (e) => e.map((e) => e.text).join(""), Ge = (e, t, n, r) => {
910
+ if (n <= t) return !1;
911
+ let i = 0;
912
+ for (let a of e) {
913
+ let e = i;
914
+ if (i += a.text.length, !(i <= t || e >= n) && (a.type !== "text" || !M(a).includes(r))) return !1;
915
+ }
916
+ return !0;
917
+ }, Ke = (e, t, n, r) => {
918
+ if (n <= t) return e;
919
+ let i = Ge(e, t, n, r), a = [], o = 0;
920
+ for (let s of e) {
921
+ let e = o;
922
+ if (o += s.text.length, s.type !== "text" || o <= t || e >= n) {
923
+ a.push(s);
924
+ continue;
925
+ }
926
+ let c = Math.max(t, e) - e, l = Math.min(n, o) - e, u = M(s), d = Ve(s), f = i ? u.filter((e) => e !== r) : u.includes(r) ? u : [...u, r];
927
+ a.push(N(s.text.slice(0, c), u, d, s.change), N(s.text.slice(c, l), f, d, s.change), N(s.text.slice(l), u, d, s.change));
928
+ }
929
+ return P(a);
930
+ }, I = (e, t, n) => {
931
+ let r = [], i = 0;
932
+ for (let a of e) {
933
+ let e = i;
934
+ i += a.text.length;
935
+ let o = Math.max(t, e) - e, s = Math.min(n, i) - e;
936
+ s <= o || (a.type === "text" ? r.push(Ue(a.text.slice(o, s), a)) : r.push(o === 0 && s === a.text.length ? a : N(a.text.slice(o, s), [], void 0, a.change)));
937
+ }
938
+ return r;
939
+ }, qe = (e, t, n, r) => {
940
+ let i = I(e, 0, t), [a] = n > t ? I(e, t, t + 1) : [], o = a ?? i[i.length - 1];
941
+ return P([
942
+ ...i,
943
+ Ue(r, o),
944
+ ...I(e, n, 2 ** 53 - 1)
945
+ ]);
946
+ }, L = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;"), Je = (e) => e.map((e) => {
947
+ if (e.type === "link") return `<a data-target="${L(e.target)}">${L(e.text)}</a>`;
948
+ if (e.type === "contact") return `<a data-contact="${L("target" in e.contact ? `contact:${e.contact.target}` : `${e.contact.channel}:${e.contact.value}`)}">${L(e.text)}</a>`;
949
+ let t = L(e.text);
950
+ return M(e).includes("underline") && (t = `<u>${t}</u>`), M(e).includes("italic") && (t = `<em>${t}</em>`), M(e).includes("bold") && (t = `<strong>${t}</strong>`), e.style === void 0 ? t : `<span data-style="${L(e.style)}">${t}</span>`;
951
+ }).join(""), Ye = (e) => {
952
+ let t = e.indexOf(":"), n = e.slice(0, t), r = e.slice(t + 1);
953
+ return t <= 0 || r === "" ? null : n === "contact" ? { target: r } : n === "email" || n === "phone" ? {
954
+ channel: n,
955
+ value: r
956
+ } : null;
957
+ }, R = (e) => {
958
+ let t = [], n = (e, r, i) => {
959
+ if (e.nodeType === 3) {
960
+ t.push(N(e.textContent ?? "", r, i));
961
+ return;
962
+ }
963
+ if (e.nodeType !== 1) return;
964
+ let a = e.nodeName.toLowerCase();
965
+ if (a === "br") {
966
+ t.push(N("\n", r, i));
967
+ return;
968
+ }
969
+ if (a === "a" && e.getAttribute?.("data-target")) {
970
+ t.push({
971
+ type: "link",
972
+ target: e.getAttribute("data-target"),
973
+ text: e.textContent ?? ""
974
+ });
975
+ return;
976
+ }
977
+ let o = a === "a" ? Ye(e.getAttribute?.("data-contact") ?? "") : null;
978
+ if (o !== null) {
979
+ t.push({
980
+ type: "contact",
981
+ text: e.textContent ?? "",
982
+ contact: o
983
+ });
984
+ return;
985
+ }
986
+ let s = a === "strong" || a === "b" ? [.../* @__PURE__ */ new Set([...r, "bold"])] : a === "em" || a === "i" ? [.../* @__PURE__ */ new Set([...r, "italic"])] : a === "u" ? [.../* @__PURE__ */ new Set([...r, "underline"])] : r, c = a === "span" ? e.getAttribute?.("data-style") : null;
987
+ for (let t of Array.from(e.childNodes)) n(t, s, c != null && c !== "" ? c : i);
988
+ };
989
+ for (let t of Array.from(e.childNodes)) n(t, [], void 0);
990
+ return P(t);
991
+ }, Xe = (e, t) => e.map((e) => ({
992
+ ...e,
993
+ change: t
994
+ })), Ze = (e) => {
995
+ switch (e.type) {
996
+ case "paragraph":
997
+ case "heading": return [e.content];
998
+ case "list": return e.items;
999
+ case "table": return e.rows.flat();
1000
+ case "image":
1001
+ case "file":
1002
+ case "component": return [];
1003
+ }
1004
+ }, z = (e) => e.change !== void 0 || Ze(e).some((e) => e.some((e) => e.change !== void 0)), Qe = (e) => e.blocks.some(z), $e = /[\p{L}\p{N}_]/u, et = (e, t, n) => {
1005
+ let r = F(e), i = F(t);
1006
+ if (r === i) return t;
1007
+ let a = 0;
1008
+ for (; a < r.length && a < i.length && r[a] === i[a];) a += 1;
1009
+ let o = 0;
1010
+ for (; o < r.length - a && o < i.length - a && r[r.length - 1 - o] === i[i.length - 1 - o];) o += 1;
1011
+ for (; a > 0 && $e.test(r[a - 1]);) --a;
1012
+ for (; o > 0 && $e.test(r[r.length - o]);) --o;
1013
+ return P([
1014
+ ...I(t, 0, a),
1015
+ ...Xe(I(e, a, r.length - o), {
1016
+ ...n,
1017
+ kind: "delete"
1018
+ }),
1019
+ ...Xe(I(t, a, i.length - o), {
1020
+ ...n,
1021
+ kind: "insert"
1022
+ }),
1023
+ ...I(t, i.length - o, i.length)
1024
+ ]);
1025
+ }, tt = (e, t, n) => Array.from({ length: Math.max(e.length, t.length) }, (r, i) => {
1026
+ let a = e[i], o = t[i];
1027
+ return a === void 0 ? Xe(o ?? [], {
1028
+ ...n,
1029
+ kind: "insert"
1030
+ }) : o === void 0 ? Xe(a, {
1031
+ ...n,
1032
+ kind: "delete"
1033
+ }) : et(a, o, n);
1034
+ }), nt = (e, t) => JSON.stringify(e) === JSON.stringify(t), rt = (e, t, n) => {
1035
+ if ((e.type === "paragraph" || e.type === "heading") && t.type === e.type) return {
1036
+ ...t,
1037
+ content: et(e.content, t.content, n)
1038
+ };
1039
+ if (e.type === "list" && t.type === "list") {
1040
+ let r = tt(e.items, t.items, n), i = r.map((n, r) => t.levels?.[r] ?? e.levels?.[r] ?? 0);
1041
+ return {
1042
+ ...t,
1043
+ items: r,
1044
+ ...i.some((e) => e > 0) ? { levels: i } : {}
1045
+ };
1046
+ }
1047
+ if (e.type === "table" && t.type === "table") {
1048
+ let r = Array.from({ length: Math.max(e.rows.length, t.rows.length) }, (r, i) => tt(e.rows[i] ?? [], t.rows[i] ?? [], n));
1049
+ return {
1050
+ ...t,
1051
+ rows: r
1052
+ };
1053
+ }
1054
+ return null;
1055
+ }, it = (e, t, n) => {
1056
+ let r = new Map(e.blocks.map((e) => [e.id, e])), i = new Set(t.blocks.map((e) => e.id)), a = [], o = [];
1057
+ for (let e of t.blocks) {
1058
+ let t = r.get(e.id);
1059
+ if (t === void 0) {
1060
+ o.push({
1061
+ ...e,
1062
+ change: {
1063
+ ...n,
1064
+ kind: "insert"
1065
+ }
1066
+ });
1067
+ continue;
1068
+ }
1069
+ if (nt(t, e)) {
1070
+ o.push(t);
1071
+ continue;
1072
+ }
1073
+ if (z(t)) {
1074
+ a.push(e.id), o.push(t);
1075
+ continue;
1076
+ }
1077
+ let i = rt(t, e, n);
1078
+ if (i !== null) {
1079
+ o.push(i);
1080
+ continue;
1081
+ }
1082
+ o.push({
1083
+ ...t,
1084
+ change: {
1085
+ ...n,
1086
+ kind: "delete"
1087
+ }
1088
+ }, {
1089
+ ...e,
1090
+ id: se(),
1091
+ change: {
1092
+ ...n,
1093
+ kind: "insert"
1094
+ }
1095
+ });
1096
+ }
1097
+ return e.blocks.forEach((t, r) => {
1098
+ if (i.has(t.id)) return;
1099
+ let s = z(t) ? t : {
1100
+ ...t,
1101
+ change: {
1102
+ ...n,
1103
+ kind: "delete"
1104
+ }
1105
+ };
1106
+ z(t) && a.push(t.id);
1107
+ let c = e.blocks.slice(0, r).reverse().find((e) => o.some((t) => t.id === e.id)), l = c === void 0 ? 0 : o.findIndex((e) => e.id === c.id) + 1;
1108
+ for (; l < o.length && o[l].change?.kind === "delete" && !i.has(o[l].id);) l += 1;
1109
+ o.splice(l, 0, s);
1110
+ }), {
1111
+ document: {
1112
+ ...e,
1113
+ blocks: o
1114
+ },
1115
+ conflicts: a
1116
+ };
1117
+ }, at = (e, t) => {
1118
+ if (e === void 0) return "keep";
1119
+ let n = t(e);
1120
+ return n === "keep" ? "keep" : n === "accept" == (e.kind === "insert") ? "unmark" : "drop";
1121
+ }, ot = (e) => {
1122
+ let { change: t, ...n } = e;
1123
+ return n;
1124
+ }, st = (e, t) => P(e.flatMap((e) => {
1125
+ let n = at(e.change, t);
1126
+ return n === "drop" ? [] : [n === "unmark" ? ot(e) : e];
1127
+ })), ct = (e, t) => t.length === 0 && e.length > 0 && e.every((e) => e.change !== void 0), lt = (e, t) => ({
1128
+ ...e,
1129
+ blocks: e.blocks.flatMap((e) => {
1130
+ let n = at(e.change, t);
1131
+ if (n === "drop") return [];
1132
+ let r = n === "unmark" ? ot(e) : e;
1133
+ switch (r.type) {
1134
+ case "paragraph":
1135
+ case "heading": return [{
1136
+ ...r,
1137
+ content: st(r.content, t)
1138
+ }];
1139
+ case "list": {
1140
+ let e = r.items.map((e) => st(e, t)), n = e.map((e, t) => !ct(r.items[t], e)), i = r.levels?.filter((e, t) => n[t]);
1141
+ return [{
1142
+ ...r,
1143
+ items: e.filter((e, t) => n[t]),
1144
+ ...i === void 0 ? {} : { levels: i }
1145
+ }];
1146
+ }
1147
+ case "table": {
1148
+ let e = r.rows.map((e) => e.map((e) => st(e, t)));
1149
+ return [{
1150
+ ...r,
1151
+ rows: e.filter((e, t) => !e.every((e, n) => ct(r.rows[t][n], e)))
1152
+ }];
1153
+ }
1154
+ case "image":
1155
+ case "file":
1156
+ case "component": return [r];
1157
+ }
1158
+ })
1159
+ }), ut = (e) => {
1160
+ let t = /* @__PURE__ */ new Map(), n = (e, n) => {
1161
+ let r = t.get(e.id) ?? {
1162
+ id: e.id,
1163
+ by: e.by,
1164
+ at: e.at,
1165
+ blockIds: [],
1166
+ inserted: "",
1167
+ deleted: "",
1168
+ blocks: 0
1169
+ };
1170
+ return r.blockIds.includes(n) || r.blockIds.push(n), t.set(e.id, r), r;
1171
+ };
1172
+ for (let t of e.blocks) {
1173
+ if (t.change !== void 0) {
1174
+ let e = n(t.change, t.id);
1175
+ e.blocks += 1;
1176
+ let r = Ze(t).map(F).join(" ");
1177
+ t.change.kind === "insert" ? e.inserted += r : e.deleted += r;
1178
+ }
1179
+ for (let e of Ze(t)) for (let r of e) {
1180
+ if (r.change === void 0) continue;
1181
+ let e = n(r.change, t.id);
1182
+ r.change.kind === "insert" ? e.inserted += r.text : e.deleted += r.text;
1183
+ }
1184
+ }
1185
+ return [...t.values()];
1186
+ }, dt = /* @__PURE__ */ new Set([
1187
+ "status",
1188
+ "publishAt",
1189
+ "unpublishAt",
1190
+ "revisionId",
1191
+ "revision",
1192
+ "documentId",
1193
+ "site",
1194
+ "environment",
1195
+ "locale",
1196
+ "tenantId",
1197
+ "createdAt",
1198
+ "updatedAt",
1199
+ "createdBy",
1200
+ "updatedBy"
1201
+ ]), B = (e, t, n) => ({
1202
+ field: e,
1203
+ rule: t,
1204
+ message: n
1205
+ }), V = (e) => typeof e == "object" && !!e && !Array.isArray(e), ft = (e) => e instanceof Date ? !Number.isNaN(e.getTime()) : typeof e == "string" && !Number.isNaN(new Date(e).getTime()), pt = (e, t, n) => {
1206
+ let r = [];
1207
+ return t.maxLength !== void 0 && n.length > t.maxLength && r.push(B(e, "maxLength", `exceeds maxLength(${t.maxLength}) — got ${n.length} characters`)), t.pattern !== void 0 && !new RegExp(t.pattern).test(n) && r.push(B(e, "pattern", `does not match pattern /${t.pattern}/`)), r;
1208
+ }, mt = (e, t, n) => {
1209
+ switch (t.kind) {
1210
+ case "string":
1211
+ case "media":
1212
+ case "reference": return typeof n == "string" ? pt(e, t, n) : [B(e, "type", `expected a string, got ${typeof n}`)];
1213
+ case "number": return typeof n != "number" || !Number.isFinite(n) ? [B(e, "type", "expected a finite number")] : t.fraction !== !0 && !Number.isInteger(n) ? [B(e, "integer", "expected a whole number (declare Schema.Fraction for fractions)")] : [];
1214
+ case "boolean": return typeof n == "boolean" ? [] : [B(e, "type", `expected a boolean, got ${typeof n}`)];
1215
+ case "date":
1216
+ case "datetime": return ft(n) ? [] : [B(e, "type", "expected a Date or a parseable date string")];
1217
+ case "literal": {
1218
+ let r = t.literals ?? [];
1219
+ return typeof n != "string" || !r.includes(n) ? [B(e, "literal", `expected one of: ${r.join(", ")}`)] : [];
1220
+ }
1221
+ case "richText": {
1222
+ let r = t.richText ?? {}, i = k(n), a = ge(e, i, r).map((e) => B(e.path, e.rule, e.message)), o = new Map((r.profile?.components ?? []).map((e) => [e.id, e]));
1223
+ return (V(i) && Array.isArray(i.blocks) ? i.blocks : []).forEach((t, n) => {
1224
+ if (!V(t) || t.type !== "component" || !V(t.props)) return;
1225
+ let r = o.get(String(t.componentId));
1226
+ r !== void 0 && a.push(...H(`${e}.blocks[${n}].props`, r.props, t.props, `component '${r.id}'`, !0));
1227
+ }), a;
1228
+ }
1229
+ case "array": {
1230
+ if (!Array.isArray(n)) return [B(e, "type", "expected an array")];
1231
+ let r = t.element;
1232
+ if (r === void 0) return [];
1233
+ let i = [];
1234
+ return n.forEach((t, n) => i.push(...mt(`${e}[${n}]`, r, t))), i;
1235
+ }
1236
+ case "struct": return V(n) ? H(e, t.struct ?? {}, n, "struct", !1) : [B(e, "type", "expected an object")];
1237
+ case "components": {
1238
+ if (!Array.isArray(n)) return [B(e, "type", "expected a list of components")];
1239
+ let r = new Map((t.components ?? []).map((e) => [e.id, e])), i = [], a = /* @__PURE__ */ new Set();
1240
+ return n.forEach((t, n) => {
1241
+ let o = `${e}[${n}]`;
1242
+ if (!V(t)) {
1243
+ i.push(B(o, "type", "expected a component instance"));
1244
+ return;
1245
+ }
1246
+ let s = t.instanceId;
1247
+ typeof s != "string" || s === "" ? i.push(B(`${o}.instanceId`, "required", "missing instance id")) : a.has(s) ? i.push(B(`${o}.instanceId`, "unique", `instance '${s}' appears twice`)) : a.add(s);
1248
+ let c = r.get(String(t.componentId));
1249
+ if (c === void 0) {
1250
+ i.push(B(`${o}.componentId`, "unknown", `'${String(t.componentId)}' is not a component this field allows`));
1251
+ return;
1252
+ }
1253
+ let l = t.props;
1254
+ if (!V(l)) {
1255
+ i.push(B(`${o}.props`, "type", "expected an object"));
1256
+ return;
1257
+ }
1258
+ i.push(...H(`${o}.props`, c.props, l, `component '${c.id}'`, !0));
1259
+ }), i;
1260
+ }
1261
+ }
1262
+ }, H = (e, t, n, r, i) => {
1263
+ let a = [];
1264
+ for (let [r, o] of Object.entries(t)) {
1265
+ let t = n[r];
1266
+ if (t == null || i && t === "") {
1267
+ o.isOptional || a.push(B(`${e}.${r}`, "required", "missing required field"));
1268
+ continue;
1269
+ }
1270
+ a.push(...mt(`${e}.${r}`, o, t));
1271
+ }
1272
+ for (let i of Object.keys(n)) i in t || a.push(B(`${e}.${i}`, "unknown", `not a declared field of this ${r}`));
1273
+ return a;
1274
+ }, ht = (e, t) => {
1275
+ let n = [];
1276
+ for (let [r, i] of Object.entries(e.fields)) {
1277
+ let e = t[r];
1278
+ if (e == null) {
1279
+ i.isOptional || n.push(B(r, "required", "missing required field"));
1280
+ continue;
1281
+ }
1282
+ n.push(...mt(r, i, e));
1283
+ }
1284
+ let r = t.id;
1285
+ r !== void 0 && typeof r != "string" && n.push(B("id", "type", "expected a string id"));
1286
+ for (let r of Object.keys(t)) r === "id" || r in e.fields || dt.has(r) || n.push(B(r, "unknown", `'${r}' is not a declared field of '${e.name}'`));
1287
+ let i = e.taxonomy;
1288
+ if (i !== void 0 && (i.unknown ?? "refuse") === "refuse" && Array.isArray(t[i.field])) {
1289
+ let { unknown: e } = Ee(i, t[i.field]);
1290
+ e.length > 0 && n.push(B(i.field, "taxonomy", `not in the vocabulary: ${e.join(", ")}`));
1291
+ }
1292
+ return n;
1293
+ }, gt = (e, t) => [...Object.entries(e.fields).filter(([e, n]) => {
1294
+ let r = t[e];
1295
+ return n.publishRequired === !0 && (r == null || typeof r == "string" && r.trim() === "");
1296
+ }).map(([e]) => B(e, "requiredToPublish", "needed before publishing")), ...Object.entries(e.fields).filter(([e, n]) => {
1297
+ let r = t[e];
1298
+ return n.kind === "richText" && V(r) && Array.isArray(r.blocks) && Qe(r);
1299
+ }).map(([e]) => B(e, "pendingChanges", "accept or reject the suggested changes first"))], _t = (e, t) => {
1300
+ let n = ht(e, t);
1301
+ if (n.length > 0) throw new Ae({
1302
+ contentType: e.name,
1303
+ violations: n
1304
+ });
1305
+ }, vt = (e, t) => {
1306
+ let n = { ...t }, r = e.taxonomy;
1307
+ r !== void 0 && Array.isArray(n[r.field]) && (n[r.field] = De(r, n[r.field]));
1308
+ for (let t of e.derivedFields) {
1309
+ let r = e.fields[t]?.derived;
1310
+ r !== void 0 && (n[t] = r.transform(n[r.source], n));
1311
+ }
1312
+ for (let [t, r] of Object.entries(e.fields)) r.kind === "richText" && n[t] !== void 0 && n[t] !== null && (n[t] = yt(r, k(n[t], r.richText?.profile)));
1313
+ for (let [t, r] of Object.entries(e.fields)) r.kind === "components" && Array.isArray(n[t]) && (n[t] = bt(r.components ?? [], n[t]));
1314
+ return n;
1315
+ }, yt = (e, t) => {
1316
+ let n = e.richText?.profile?.components ?? [];
1317
+ return n.length === 0 || !V(t) || !Array.isArray(t.blocks) ? t : {
1318
+ ...t,
1319
+ blocks: t.blocks.map((e) => {
1320
+ if (!V(e) || e.type !== "component") return e;
1321
+ let [t] = bt(n, [{
1322
+ ...e,
1323
+ instanceId: e.id
1324
+ }]);
1325
+ return t === void 0 || t.fingerprint === void 0 ? e : {
1326
+ ...e,
1327
+ props: t.props,
1328
+ fingerprint: t.fingerprint
1329
+ };
1330
+ })
1331
+ };
1332
+ }, bt = (e, t) => {
1333
+ let n = new Map(e.map((e) => [e.id, e]));
1334
+ return t.map((e) => {
1335
+ if (!V(e)) return e;
1336
+ let t = n.get(String(e.componentId)), r = typeof e.instanceId == "string" && e.instanceId !== "" ? e.instanceId : Ct();
1337
+ if (t === void 0) return {
1338
+ ...e,
1339
+ instanceId: r
1340
+ };
1341
+ let i = V(e.props) ? e.props : {}, a = typeof e.fingerprint == "string" ? e.fingerprint : null, o = a !== null && a !== t.fingerprint ? t.migrations?.[a] : void 0;
1342
+ o !== void 0 && (i = o(i));
1343
+ let s = Object.fromEntries(Object.entries(i).map(([e, n]) => {
1344
+ let r = t.props[e];
1345
+ return [e, r?.kind === "components" && Array.isArray(n) ? bt(r.components ?? [], n) : n];
1346
+ }));
1347
+ return {
1348
+ ...e,
1349
+ instanceId: r,
1350
+ props: s,
1351
+ fingerprint: t.fingerprint
1352
+ };
1353
+ });
1354
+ }, xt = (e, t) => {
1355
+ let n = [], r = (e, t, i) => {
1356
+ if (e.kind !== "components" || !Array.isArray(t)) return;
1357
+ let a = new Map((e.components ?? []).map((e) => [e.id, e]));
1358
+ t.forEach((e, t) => {
1359
+ if (!V(e)) return;
1360
+ let o = a.get(String(e.componentId));
1361
+ if (o === void 0) return;
1362
+ let s = typeof e.fingerprint == "string" ? e.fingerprint : null;
1363
+ s !== o.fingerprint && (s === null || o.migrations?.[s] === void 0) && n.push({
1364
+ path: `${i}[${t}]`,
1365
+ componentId: o.id,
1366
+ fingerprint: s
1367
+ });
1368
+ let c = V(e.props) ? e.props : {};
1369
+ for (let [e, n] of Object.entries(o.props)) r(n, c[e], `${i}[${t}].props.${e}`);
1370
+ });
1371
+ };
1372
+ for (let [n, i] of Object.entries(e.fields)) r(i, t[n], n);
1373
+ return n;
1374
+ }, St = (e) => {
1375
+ let t = [];
1376
+ for (let [n, r] of Object.entries(e.fixtures ?? {})) t.push(...H(`fixtures.${n}`, e.props, r, `component '${e.id}'`, !0));
1377
+ for (let [n, r] of Object.entries(e.variants ?? {})) {
1378
+ let i = Object.fromEntries(Object.entries(e.props).filter(([e]) => e in r));
1379
+ t.push(...H(`variants.${n}`, i, r, `component '${e.id}'`, !0));
1380
+ }
1381
+ return t;
1382
+ }, Ct = () => `cins_${globalThis.crypto.randomUUID().replaceAll("-", "")}`, wt = (e, t) => {
1383
+ let n = e[t.parent];
1384
+ return typeof n == "string" && n !== "" ? n : null;
1385
+ }, Tt = (e, t) => {
1386
+ let n = t.order === void 0 ? void 0 : e[t.order];
1387
+ return typeof n == "number" && Number.isFinite(n) ? n : Infinity;
1388
+ }, Et = (e, t) => {
1389
+ let n = e[t.segment];
1390
+ return typeof n == "string" ? n : "";
1391
+ }, Dt = (e, t) => {
1392
+ let n = /* @__PURE__ */ new Map();
1393
+ for (let t of e) {
1394
+ let e = t.row.documentId;
1395
+ typeof e == "string" && !n.has(e) && n.set(e, t);
1396
+ }
1397
+ let r = /* @__PURE__ */ new Map();
1398
+ for (let e of n.values()) {
1399
+ let n = wt(e.row, t), i = r.get(n) ?? [];
1400
+ i.push(e), r.set(n, i);
1401
+ }
1402
+ let i = (e, n) => Tt(e.row, t) - Tt(n.row, t) || Et(e.row, t).localeCompare(Et(n.row, t)) || String(e.row.documentId).localeCompare(String(n.row.documentId)), a = [], o = /* @__PURE__ */ new Set(), s = (e, n) => {
1403
+ for (let c of [...r.get(e) ?? []].sort(i)) {
1404
+ let r = c.row.documentId, i = Et(c.row, t);
1405
+ if (i === "" || o.has(r)) continue;
1406
+ o.add(r);
1407
+ let l = [...n, i];
1408
+ a.push({
1409
+ documentId: r,
1410
+ parent: e,
1411
+ depth: n.length,
1412
+ segments: l,
1413
+ path: l.join("/"),
1414
+ row: c.row,
1415
+ locale: c.locale,
1416
+ fallback: c.fallback
1417
+ }), s(r, l);
1418
+ }
1419
+ };
1420
+ return s(null, []), {
1421
+ nodes: a,
1422
+ orphans: [...n.keys()].filter((e) => !o.has(e)).sort()
1423
+ };
1424
+ }, Ot = (e) => e != null && e !== "", kt = (e, t, n, r = {}) => {
1425
+ let i = new Map(e.nodes.map((e) => [e.documentId, e])), a = r.ancestorsOnly === !0 ? t.parent === null ? void 0 : i.get(t.parent) : t, o = /* @__PURE__ */ new Set();
1426
+ for (; a !== void 0 && !o.has(a.documentId);) {
1427
+ if (o.add(a.documentId), Ot(a.row[n])) return {
1428
+ value: a.row[n],
1429
+ from: a.documentId,
1430
+ how: a.documentId === t.documentId ? "own" : "ancestor"
1431
+ };
1432
+ if (r.mask !== void 0 && a.row[r.mask] === !0) return {
1433
+ value: void 0,
1434
+ from: a.documentId,
1435
+ how: "masked"
1436
+ };
1437
+ a = a.parent === null ? void 0 : i.get(a.parent);
1438
+ }
1439
+ return {
1440
+ value: void 0,
1441
+ from: null,
1442
+ how: "none"
1443
+ };
1444
+ }, At = (e, t, n) => {
1445
+ let r = t.nodes.some((e) => e.documentId === n.documentId) ? {
1446
+ ...t,
1447
+ nodes: t.nodes.map((e) => e.documentId === n.documentId ? n : e)
1448
+ } : {
1449
+ ...t,
1450
+ nodes: [...t.nodes, n]
1451
+ };
1452
+ return Object.entries(e).map(([e, t]) => {
1453
+ let i = t.mask === void 0 ? {} : { mask: t.mask };
1454
+ return {
1455
+ field: e,
1456
+ locked: t.locked === !0,
1457
+ mask: t.mask ?? null,
1458
+ ...kt(r, n, e, i),
1459
+ inherited: kt(r, n, e, {
1460
+ ...i,
1461
+ ancestorsOnly: !0
1462
+ })
1463
+ };
1464
+ });
1465
+ }, U = (e) => Array.isArray(e) ? e.map(U) : typeof e == "object" && e && !(e instanceof Date) ? Object.fromEntries(Object.keys(e).sort().map((t) => [t, U(e[t])])) : e instanceof Date ? e.toISOString() : e === void 0 ? null : e, jt = (e, t, n) => Object.keys(e).filter((e) => JSON.stringify(U(t[e])) !== JSON.stringify(U(n[e]))), Mt = (e, t) => {
1466
+ let n = [...e].sort((e, t) => Number(e.number) - Number(t.number)), r = [], i;
1467
+ for (let e of n) {
1468
+ let n = (e.values ?? {})[t], a = JSON.stringify(U(n));
1469
+ a !== i && (i = a, n != null && n !== "" && r.push({
1470
+ value: n,
1471
+ revisionId: String(e.id),
1472
+ number: Number(e.number),
1473
+ createdAt: e.createdAt,
1474
+ createdBy: e.createdBy
1475
+ }));
1476
+ }
1477
+ return r.reverse();
1478
+ }, Nt = (e) => e.match(/\s+|[^\s]+/g) ?? [], Pt = 4e6, Ft = (e, t) => {
1479
+ let n = Nt(e), r = Nt(t), i = [], a = (e, t) => {
1480
+ if (t === "") return;
1481
+ let n = i[i.length - 1];
1482
+ n !== void 0 && n.op === e ? i[i.length - 1] = {
1483
+ op: e,
1484
+ text: n.text + t
1485
+ } : i.push({
1486
+ op: e,
1487
+ text: t
1488
+ });
1489
+ };
1490
+ if (n.length * r.length > Pt) return a("removed", e), a("added", t), i;
1491
+ let o = Array.from({ length: n.length + 1 }, () => Array(r.length + 1).fill(0));
1492
+ for (let e = n.length - 1; e >= 0; e--) for (let t = r.length - 1; t >= 0; t--) o[e][t] = n[e] === r[t] ? o[e + 1][t + 1] + 1 : Math.max(o[e + 1][t], o[e][t + 1]);
1493
+ let s = 0, c = 0;
1494
+ for (; s < n.length && c < r.length;) n[s] === r[c] ? (a("same", n[s]), s++, c++) : o[s + 1][c] >= o[s][c + 1] ? (a("removed", n[s]), s++) : (a("added", r[c]), c++);
1495
+ for (; s < n.length;) a("removed", n[s++]);
1496
+ for (; c < r.length;) a("added", r[c++]);
1497
+ return i;
1498
+ }, It = (e) => typeof e == "object" && !!e && e.type === "doc" && Array.isArray(e.blocks), W = (e) => {
1499
+ if (e == null) return "";
1500
+ if (typeof e == "string") return e;
1501
+ if (typeof e == "number" || typeof e == "boolean") return String(e);
1502
+ if (e instanceof Date) return e.toISOString();
1503
+ if (It(e)) return Te(e);
1504
+ if (Array.isArray(e)) return e.map(W).join("\n");
1505
+ let t = e;
1506
+ if (typeof t.componentId == "string" && typeof t.props == "object" && t.props !== null) {
1507
+ let e = Object.values(t.props).map(W).filter((e) => e !== "");
1508
+ return `${t.componentId}: ${e.join(" · ")}`;
1509
+ }
1510
+ return JSON.stringify(U(e));
1511
+ }, Lt = (e, t, n) => jt(e, t, n).map((e) => ({
1512
+ field: e,
1513
+ segments: Ft(W(t[e]), W(n[e]))
1514
+ })), Rt = (e) => JSON.stringify([
1515
+ e.id,
1516
+ e.formula,
1517
+ e.unit,
1518
+ [...e.scope].sort(),
1519
+ e.freshness,
1520
+ [...e.quality].sort(),
1521
+ [...e.drill].sort()
1522
+ ]), zt = (e) => {
1523
+ if (!Number.isInteger(e.version) || e.version < 1) throw Error(`metric '${e.id}': version must be a positive integer`);
1524
+ return {
1525
+ ...e,
1526
+ fingerprint: _(Rt(e))
1527
+ };
1528
+ }, Bt = (e, t) => {
1529
+ let n = new Map(t.map((e) => [e.id, e]));
1530
+ return e.filter((e) => {
1531
+ let t = n.get(e.id);
1532
+ return t !== void 0 && t.version === e.version && t.fingerprint !== e.fingerprint;
1533
+ }).map((e) => e.id);
1534
+ }, Vt = (e, t) => {
1535
+ let n = /* @__PURE__ */ new Map(), r = 0;
1536
+ for (let { day: i, value: a } of t) {
1537
+ let t = Date.parse(`${i}T23:59:59.999Z`), o = e.find((e) => Date.parse(e.from) <= t && (e.to === null || Date.parse(e.to) > t));
1538
+ if (o === void 0) {
1539
+ r += a;
1540
+ continue;
1541
+ }
1542
+ let s = n.get(o) ?? {
1543
+ value: 0,
1544
+ days: 0
1545
+ };
1546
+ s.value += a, s.days += 1, n.set(o, s);
1547
+ }
1548
+ return {
1549
+ shares: [...n.entries()].map(([e, t]) => ({
1550
+ ...e,
1551
+ ...t
1552
+ })).sort((e, t) => Date.parse(e.from) - Date.parse(t.from)),
1553
+ unattributed: r
1554
+ };
1555
+ }, Ht = (e) => {
1556
+ let { languages: t, countries: n, returning: r } = e.rule;
1557
+ if ((t?.length ?? 0) === 0 && (n?.length ?? 0) === 0 && r === void 0) throw Error(`defineAudience('${e.id}'): the rule has no condition, so it would match every reader.`);
1558
+ return e;
1559
+ }, Ut = (e, t) => {
1560
+ if (e.languages !== void 0 && e.languages.length > 0) {
1561
+ let n = (t.languages ?? [])[0]?.toLowerCase();
1562
+ if (n === void 0 || !e.languages.some((e) => n === e.toLowerCase() || n.startsWith(`${e.toLowerCase()}-`))) return !1;
1563
+ }
1564
+ if (e.countries !== void 0 && e.countries.length > 0) {
1565
+ let n = t.country?.toUpperCase();
1566
+ if (n === void 0 || !e.countries.some((e) => e.toUpperCase() === n)) return !1;
1567
+ }
1568
+ return e.returning === void 0 || (t.returning ?? !1) === e.returning;
1569
+ }, Wt = (e, t, n) => {
1570
+ let r = new Map(t.map((e) => [e.id, e]));
1571
+ return e.find((e) => {
1572
+ let t = r.get(e.audience);
1573
+ return t !== void 0 && Ut(t.rule, n);
1574
+ }) ?? null;
1575
+ }, Gt = (e) => (e ?? "").split(",").map((e, t) => {
1576
+ let [n, ...r] = e.trim().split(";"), i = Number(r.find((e) => e.trim().startsWith("q="))?.trim().slice(2) ?? "1");
1577
+ return {
1578
+ tag: (n ?? "").trim(),
1579
+ q: Number.isFinite(i) ? i : 0,
1580
+ i: t
1581
+ };
1582
+ }).filter((e) => e.tag !== "" && e.tag !== "*" && e.q > 0).sort((e, t) => t.q - e.q || e.i - t.i).map((e) => e.tag), Kt = {
1583
+ amp: "&",
1584
+ lt: "<",
1585
+ gt: ">",
1586
+ quot: "\"",
1587
+ apos: "'",
1588
+ nbsp: "\xA0",
1589
+ ndash: "–",
1590
+ mdash: "—",
1591
+ hellip: "…",
1592
+ lsquo: "‘",
1593
+ rsquo: "’",
1594
+ ldquo: "“",
1595
+ rdquo: "”",
1596
+ copy: "©",
1597
+ euro: "€"
1598
+ }, qt = (e) => e.replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi, (e, t) => {
1599
+ if (t[0] === "#") {
1600
+ let n = t[1] === "x" || t[1] === "X" ? Number.parseInt(t.slice(2), 16) : Number.parseInt(t.slice(1), 10);
1601
+ return Number.isFinite(n) && n > 0 && n <= 1114111 ? String.fromCodePoint(n) : e;
1602
+ }
1603
+ return Kt[t.toLowerCase()] ?? e;
1604
+ }), Jt = (e) => {
1605
+ try {
1606
+ return decodeURIComponent(e);
1607
+ } catch {
1608
+ return e;
1609
+ }
1610
+ }, Yt = /* @__PURE__ */ new Set([
1611
+ "script",
1612
+ "style",
1613
+ "iframe",
1614
+ "object",
1615
+ "embed",
1616
+ "noscript",
1617
+ "template",
1618
+ "svg",
1619
+ "form",
1620
+ "select",
1621
+ "textarea",
1622
+ "button"
1623
+ ]), Xt = /* @__PURE__ */ new Set([
1624
+ "span",
1625
+ "div",
1626
+ "section",
1627
+ "article",
1628
+ "main",
1629
+ "header",
1630
+ "footer",
1631
+ "figure",
1632
+ "blockquote",
1633
+ "u",
1634
+ "small",
1635
+ "sup",
1636
+ "sub",
1637
+ "code",
1638
+ "pre",
1639
+ "thead",
1640
+ "tbody",
1641
+ "tfoot",
1642
+ "font",
1643
+ "center"
1644
+ ]), Zt = (e) => {
1645
+ let t = {};
1646
+ for (let n of e.matchAll(/([a-zA-Z_:][-a-zA-Z0-9_:.]*)\s*(?:=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g)) t[n[1].toLowerCase()] = qt(n[2] ?? n[3] ?? n[4] ?? "");
1647
+ return t;
1648
+ }, Qt = (e) => {
1649
+ let t = [], n = e.replace(/<!--[\s\S]*?-->/g, ""), r = 0;
1650
+ for (let e of n.matchAll(/<(\/?)([a-zA-Z][a-zA-Z0-9]*)([^>]*)>/g)) {
1651
+ e.index > r && t.push({
1652
+ kind: "text",
1653
+ text: n.slice(r, e.index)
1654
+ });
1655
+ let i = e[3] ?? "";
1656
+ t.push({
1657
+ kind: "tag",
1658
+ tag: {
1659
+ name: e[2].toLowerCase(),
1660
+ closing: e[1] === "/",
1661
+ attrs: Zt(i.replace(/\/\s*$/, "")),
1662
+ selfClosing: /\/\s*$/.test(i)
1663
+ }
1664
+ }), r = e.index + e[0].length;
1665
+ }
1666
+ return r < n.length && t.push({
1667
+ kind: "text",
1668
+ text: n.slice(r)
1669
+ }), t;
1670
+ }, $t = (e, t = {}) => {
1671
+ let n = 0, r = t.newId ?? (() => `rb_import_${++n}`), i = [], a = [], o = (e, t) => {
1672
+ a.some((n) => n.kind === e && n.detail === t) || a.push({
1673
+ kind: e,
1674
+ detail: t
1675
+ });
1676
+ }, s = [], c = null, l = [], u = null, d = null, f = null, p = null, m = !1, h = (e) => {
1677
+ let t = qt(e.replace(/[ \t\r\n\f]+/g, " "));
1678
+ if (t === "" || t === " " && l.length === 0) return;
1679
+ let n = l[l.length - 1];
1680
+ if (c !== null && c.target !== null) {
1681
+ n?.type === "link" && n.target === c.target ? l[l.length - 1] = {
1682
+ ...n,
1683
+ text: n.text + t
1684
+ } : l.push({
1685
+ type: "link",
1686
+ target: c.target,
1687
+ text: t
1688
+ });
1689
+ return;
1690
+ }
1691
+ if (c?.contact !== void 0) {
1692
+ n?.type === "contact" && n.contact === c.contact ? l[l.length - 1] = {
1693
+ ...n,
1694
+ text: n.text + t
1695
+ } : l.push({
1696
+ type: "contact",
1697
+ contact: c.contact,
1698
+ text: t
1699
+ });
1700
+ return;
1701
+ }
1702
+ n?.type === "text" && ((e) => (e ?? []).join() === s.join())(n.marks) ? l[l.length - 1] = {
1703
+ ...n,
1704
+ text: n.text + t
1705
+ } : l.push({
1706
+ type: "text",
1707
+ text: t,
1708
+ ...s.length > 0 ? { marks: [...s] } : {}
1709
+ });
1710
+ }, g = () => {
1711
+ let e = [...l], t = e[0];
1712
+ t !== void 0 && (e[0] = {
1713
+ ...t,
1714
+ text: t.text.replace(/^[ \t\r\n\f]+/, "")
1715
+ });
1716
+ let n = e[e.length - 1];
1717
+ return n !== void 0 && (e[e.length - 1] = {
1718
+ ...n,
1719
+ text: n.text.replace(/[ \t\r\n\f]+$/, "")
1720
+ }), e.filter((e) => e.text !== "");
1721
+ }, _ = () => {
1722
+ if (f === null || f.items.length === 0) return;
1723
+ let { ordered: e, items: t, levels: n, sublists: a } = f, o = e ? "ordered" : "unordered", s = a.some((e) => e !== o) ? { sublists: a } : {};
1724
+ i.push({
1725
+ id: r(),
1726
+ type: "list",
1727
+ ordered: e,
1728
+ items: t,
1729
+ ...n.some((e) => e > 0) ? {
1730
+ levels: n,
1731
+ ...s
1732
+ } : {}
1733
+ });
1734
+ }, v = (e = u) => {
1735
+ let t = g();
1736
+ if (l = [], t.length !== 0) {
1737
+ if (e === "li" && f !== null) {
1738
+ f.items.push(t), f.levels.push(Math.min(f.depth, 3));
1739
+ return;
1740
+ }
1741
+ if (e === "cell" && p?.row) {
1742
+ p.row.push(t);
1743
+ return;
1744
+ }
1745
+ e === "h2" || e === "h3" ? i.push({
1746
+ id: r(),
1747
+ type: "heading",
1748
+ level: e === "h2" ? 2 : 3,
1749
+ content: t
1750
+ }) : i.push({
1751
+ id: r(),
1752
+ type: "paragraph",
1753
+ content: t
1754
+ });
1755
+ }
1756
+ }, y = (e) => {
1757
+ e.split(/\n\s*\n/).forEach((e, t) => {
1758
+ t > 0 && v("p"), h(e);
1759
+ });
1760
+ };
1761
+ for (let n of Qt(e)) {
1762
+ if (d !== null) {
1763
+ n.kind === "tag" && n.tag.closing && n.tag.name === d && (d = null);
1764
+ continue;
1765
+ }
1766
+ if (n.kind === "text") {
1767
+ u === null && f === null && p === null ? y(n.text) : h(n.text);
1768
+ continue;
1769
+ }
1770
+ let { name: e, closing: a, attrs: g } = n.tag;
1771
+ if (Yt.has(e)) {
1772
+ o("unsupportedTag", e), !a && !n.tag.selfClosing && (d = e);
1773
+ continue;
1774
+ }
1775
+ switch (e) {
1776
+ case "p":
1777
+ a ? (v(), u = null) : (v("p"), u = "p");
1778
+ break;
1779
+ case "h1":
1780
+ case "h2":
1781
+ case "h3":
1782
+ case "h4":
1783
+ case "h5":
1784
+ case "h6":
1785
+ a ? (v(), u = null) : (v("p"), u = e === "h1" || e === "h2" ? "h2" : "h3");
1786
+ break;
1787
+ case "br":
1788
+ h(" ");
1789
+ break;
1790
+ case "strong":
1791
+ case "b":
1792
+ case "em":
1793
+ case "i":
1794
+ case "u": {
1795
+ let t = e === "strong" || e === "b" ? "bold" : e === "u" ? "underline" : "italic";
1796
+ if (a) {
1797
+ let e = s.lastIndexOf(t);
1798
+ e >= 0 && s.splice(e, 1);
1799
+ } else s.push(t);
1800
+ break;
1801
+ }
1802
+ case "a":
1803
+ if (a) {
1804
+ c = null;
1805
+ break;
1806
+ }
1807
+ {
1808
+ let e = g.href ?? "", n = /^(mailto|tel):(.+)$/i.exec(e.trim());
1809
+ if (t.contacts === !0 && n !== null) {
1810
+ let e = n[1].toLowerCase() === "mailto" ? "email" : "phone", t = Jt(n[2].split("?")[0]).trim();
1811
+ if (de(e, t) === null) {
1812
+ c = {
1813
+ target: null,
1814
+ contact: {
1815
+ channel: e,
1816
+ value: t
1817
+ }
1818
+ };
1819
+ break;
1820
+ }
1821
+ }
1822
+ let r = t.resolveLink?.(e) ?? null;
1823
+ r === null && e !== "" && o("externalLink", e), c = { target: r };
1824
+ }
1825
+ break;
1826
+ case "img": {
1827
+ let e = g.src ?? "", n = t.resolveImage?.(e) ?? null;
1828
+ if (n === null) {
1829
+ o("image", e), g.alt && h(g.alt);
1830
+ break;
1831
+ }
1832
+ let a = u;
1833
+ v(u === "li" || u === "cell" ? u : "p"), i.push({
1834
+ id: r(),
1835
+ type: "image",
1836
+ asset: n,
1837
+ ...g.alt ? { caption: g.alt } : {}
1838
+ }), u = a;
1839
+ break;
1840
+ }
1841
+ case "ul":
1842
+ case "ol":
1843
+ if (a) {
1844
+ if (f !== null && f.depth > 0) {
1845
+ v("li"), f.depth--, u = "li";
1846
+ break;
1847
+ }
1848
+ v(), _(), f = null, u = null;
1849
+ } else if (f !== null) {
1850
+ v("li"), f.depth++, u = null;
1851
+ let t = Math.min(f.depth, 3) - 1;
1852
+ for (; f.sublists.length < t;) f.sublists.push(f.sublists[f.sublists.length - 1] ?? (f.ordered ? "ordered" : "unordered"));
1853
+ f.sublists.length === t && f.sublists.push(e === "ol" ? "ordered" : "unordered");
1854
+ } else v("p"), f = {
1855
+ ordered: e === "ol",
1856
+ items: [],
1857
+ levels: [],
1858
+ depth: 0,
1859
+ sublists: []
1860
+ }, u = null;
1861
+ break;
1862
+ case "li":
1863
+ a ? (v("li"), u = null) : (v(f === null ? "p" : "li"), u = "li");
1864
+ break;
1865
+ case "table":
1866
+ a ? (p !== null && p.rows.length > 0 && i.push({
1867
+ id: r(),
1868
+ type: "table",
1869
+ header: p.header,
1870
+ rows: p.rows
1871
+ }), p = null) : (v("p"), p = {
1872
+ header: !1,
1873
+ rows: [],
1874
+ row: null
1875
+ });
1876
+ break;
1877
+ case "tr":
1878
+ if (p === null) break;
1879
+ a ? (p.row && p.row.length > 0 && (p.rows.length === 0 && m && (p.header = !0), p.rows.push(p.row)), p.row = null, m = !1) : p.row = [];
1880
+ break;
1881
+ case "th":
1882
+ case "td":
1883
+ a ? (v("cell"), u = null) : (e === "th" && (m = !0), l = [], u = "cell");
1884
+ break;
1885
+ default: Xt.has(e) || o("unsupportedTag", e);
1886
+ }
1887
+ }
1888
+ return v(u ?? "p"), _(), {
1889
+ document: {
1890
+ type: "doc",
1891
+ blocks: i
1892
+ },
1893
+ findings: a
1894
+ };
1895
+ }, en = {
1896
+ bold: "bold",
1897
+ italic: "italic",
1898
+ underline: "underline"
1899
+ }, tn = (e, t = {}) => {
1900
+ let n = 0, r = t.newId ?? (() => `rb_import_${++n}`), i = [], a = (e, t) => {
1901
+ i.some((n) => n.kind === e && n.detail === t) || i.push({
1902
+ kind: e,
1903
+ detail: t
1904
+ });
1905
+ }, o = (e) => {
1906
+ let n = [], r = (e) => {
1907
+ let t = n[n.length - 1];
1908
+ e.type === "text" && t?.type === "text" && (t.marks ?? []).join() === (e.marks ?? []).join() ? n[n.length - 1] = {
1909
+ ...t,
1910
+ text: t.text + e.text
1911
+ } : e.text !== "" && n.push(e);
1912
+ };
1913
+ for (let n of e ?? []) switch (n.nodeType) {
1914
+ case "text": {
1915
+ let e = (n.marks ?? []).map((e) => en[e.type]).filter((e) => e !== void 0);
1916
+ r({
1917
+ type: "text",
1918
+ text: n.value ?? "",
1919
+ ...e.length > 0 ? { marks: e } : {}
1920
+ });
1921
+ break;
1922
+ }
1923
+ case "entry-hyperlink": {
1924
+ let e = n.data?.target?.sys?.id ?? "", i = t.resolveEntry?.(e) ?? null, s = o(n.content).map((e) => e.text).join("");
1925
+ i === null ? (a("externalLink", `entry:${e}`), r({
1926
+ type: "text",
1927
+ text: s
1928
+ })) : r({
1929
+ type: "link",
1930
+ target: i,
1931
+ text: s
1932
+ });
1933
+ break;
1934
+ }
1935
+ case "hyperlink":
1936
+ a("externalLink", n.data?.uri ?? "");
1937
+ for (let e of o(n.content)) r(e);
1938
+ break;
1939
+ default:
1940
+ a("unsupportedTag", n.nodeType);
1941
+ for (let e of o(n.content)) r(e);
1942
+ }
1943
+ let i = n[0];
1944
+ i !== void 0 && (n[0] = {
1945
+ ...i,
1946
+ text: i.text.replace(/^[ \t\r\n\f]+/, "")
1947
+ });
1948
+ let s = n[n.length - 1];
1949
+ return s !== void 0 && (n[n.length - 1] = {
1950
+ ...s,
1951
+ text: s.text.replace(/[ \t\r\n\f]+$/, "")
1952
+ }), n.filter((e) => e.text !== "");
1953
+ }, s = (e) => (e.content ?? []).flatMap((e, t) => {
1954
+ let n = e.nodeType === "paragraph" ? o(e.content) : o([e]);
1955
+ return t > 0 && n.length > 0 ? [{
1956
+ type: "text",
1957
+ text: " "
1958
+ }, ...n] : n;
1959
+ }), c = [];
1960
+ for (let n of e?.content ?? []) switch (n.nodeType) {
1961
+ case "paragraph": {
1962
+ let e = o(n.content);
1963
+ e.length > 0 && c.push({
1964
+ id: r(),
1965
+ type: "paragraph",
1966
+ content: e
1967
+ });
1968
+ break;
1969
+ }
1970
+ case "heading-1":
1971
+ case "heading-2":
1972
+ case "heading-3":
1973
+ case "heading-4":
1974
+ case "heading-5":
1975
+ case "heading-6": {
1976
+ let e = o(n.content);
1977
+ e.length > 0 && c.push({
1978
+ id: r(),
1979
+ type: "heading",
1980
+ level: n.nodeType === "heading-1" || n.nodeType === "heading-2" ? 2 : 3,
1981
+ content: e
1982
+ });
1983
+ break;
1984
+ }
1985
+ case "unordered-list":
1986
+ case "ordered-list": {
1987
+ let e = [], t = [], i = [], a = (e) => e.nodeType === "ordered-list" ? "ordered" : "unordered", o = (r, c) => {
1988
+ for (let l of r.content ?? []) {
1989
+ let r = (l.content ?? []).filter((e) => e.nodeType === "unordered-list" || e.nodeType === "ordered-list"), u = s({
1990
+ ...l,
1991
+ content: (l.content ?? []).filter((e) => !r.includes(e))
1992
+ });
1993
+ u.length > 0 && (e.push(u), t.push(Math.min(c, 3, t.length === 0 ? 0 : t[t.length - 1] + 1)));
1994
+ for (let e of r) {
1995
+ let t = Math.min(c + 1, 3) - 1;
1996
+ for (; i.length < t;) i.push(i[i.length - 1] ?? a(n));
1997
+ i.length === t && i.push(a(e)), o(e, c + 1);
1998
+ }
1999
+ }
2000
+ };
2001
+ o(n, 0);
2002
+ let l = a(n);
2003
+ e.length > 0 && c.push({
2004
+ id: r(),
2005
+ type: "list",
2006
+ ordered: l === "ordered",
2007
+ items: e,
2008
+ ...t.some((e) => e > 0) ? {
2009
+ levels: t,
2010
+ ...i.some((e) => e !== l) ? { sublists: i } : {}
2011
+ } : {}
2012
+ });
2013
+ break;
2014
+ }
2015
+ case "table": {
2016
+ let e = (n.content ?? []).map((e) => (e.content ?? []).map(s)), t = (n.content?.[0]?.content ?? []).some((e) => e.nodeType === "table-header-cell");
2017
+ e.length > 0 && c.push({
2018
+ id: r(),
2019
+ type: "table",
2020
+ header: t,
2021
+ rows: e
2022
+ });
2023
+ break;
2024
+ }
2025
+ case "embedded-asset-block": {
2026
+ let e = n.data?.target?.sys?.id ?? "", i = t.resolveAsset?.(e) ?? null;
2027
+ i === null ? a("image", `asset:${e}`) : c.push({
2028
+ id: r(),
2029
+ type: "image",
2030
+ asset: i
2031
+ });
2032
+ break;
2033
+ }
2034
+ case "hr": break;
2035
+ default: {
2036
+ a("unsupportedTag", n.nodeType);
2037
+ let e = o((n.content ?? []).flatMap((e) => e.nodeType === "paragraph" ? e.content ?? [] : [e]));
2038
+ e.length > 0 && c.push({
2039
+ id: r(),
2040
+ type: "paragraph",
2041
+ content: e
2042
+ });
2043
+ }
2044
+ }
2045
+ return {
2046
+ document: {
2047
+ type: "doc",
2048
+ blocks: c
2049
+ },
2050
+ findings: i
2051
+ };
2052
+ }, nn = (e, t) => e.nodes.find((e) => e.documentId === t && !e.fallback), rn = (e, t) => e.flatMap((e) => {
2053
+ let n = nn(e.tree, t);
2054
+ return n === void 0 ? [] : [{
2055
+ locale: e.locale,
2056
+ path: n.path
2057
+ }];
2058
+ }), an = (e) => {
2059
+ let t = e instanceof Date ? e : typeof e == "string" || typeof e == "number" ? new Date(e) : null;
2060
+ return t === null || Number.isNaN(t.getTime()) ? null : t.toISOString();
2061
+ }, on = (e, t = () => !0) => e.flatMap((n) => n.tree.nodes.filter((e) => !e.fallback && t(e)).map((r) => ({
2062
+ locale: n.locale,
2063
+ path: r.path,
2064
+ documentId: r.documentId,
2065
+ lastmod: an(r.row.updatedAt),
2066
+ alternates: rn(e, r.documentId).filter((n) => {
2067
+ let i = e.find((e) => e.locale === n.locale)?.tree.nodes.find((e) => e.documentId === r.documentId);
2068
+ return i !== void 0 && t(i);
2069
+ })
2070
+ }))), sn = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;"), cn = (e, t, n) => `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">\n${e.map((e) => {
2071
+ let r = e.alternates.length > 1 ? [...e.alternates.map((e) => ` <xhtml:link rel="alternate" hreflang="${sn(e.locale)}" href="${sn(t(e.locale, e.path))}" />`), ...e.alternates.filter((e) => e.locale === n).map((e) => ` <xhtml:link rel="alternate" hreflang="x-default" href="${sn(t(e.locale, e.path))}" />`)] : [], i = e.lastmod === null ? [] : [` <lastmod>${e.lastmod}</lastmod>`];
2072
+ return [
2073
+ " <url>",
2074
+ ` <loc>${sn(t(e.locale, e.path))}</loc>`,
2075
+ ...i,
2076
+ ...r,
2077
+ " </url>"
2078
+ ].join("\n");
2079
+ }).join("\n")}\n</urlset>\n`, ln = /^https:\/\/[a-z0-9.-]+(:\d+)?$/, un = (e) => {
2080
+ for (let t of e) {
2081
+ let e = /* @__PURE__ */ new Set();
2082
+ for (let n of t.vendors ?? []) {
2083
+ if (!/^[a-z][a-zA-Z0-9]*$/.test(n.id) || e.has(n.id)) throw Error(`consent purpose '${t.id}': vendor id '${n.id}' must be a unique camelCase id`);
2084
+ e.add(n.id);
2085
+ for (let e of n.origins) if (!ln.test(e)) throw Error(`consent purpose '${t.id}': vendor '${n.name}' origin '${e}' must be exactly https://host`);
2086
+ }
2087
+ }
2088
+ }, dn = (e, t) => {
2089
+ let n = pn(e, t);
2090
+ return [...new Set(e.filter((e) => n.has(e.id)).flatMap((e) => (e.vendors ?? []).flatMap((e) => e.origins)).filter((e) => ln.test(e)))].sort();
2091
+ }, fn = (e, t, n = "frame-ancestors 'none'; base-uri 'none'; object-src 'none'") => [n, `frame-src ${["'self'", ...dn(e, t)].join(" ")}`].filter((e) => e !== "").join("; "), pn = (e, t) => new Set(e.filter((e) => t[e.id] === e.version).map((e) => e.id)), mn = (e, t, n) => Array.isArray(e) ? e.map((e) => {
2092
+ if (typeof e != "object" || !e) return e;
2093
+ let r = e, i = t.get(String(r.componentId))?.consent;
2094
+ return i === void 0 || n.has(i) ? e : {
2095
+ instanceId: String(r.instanceId ?? ""),
2096
+ componentId: String(r.componentId),
2097
+ consentRequired: i,
2098
+ props: {}
2099
+ };
2100
+ }) : e, hn = (e, t, n) => {
2101
+ let r = { ...t };
2102
+ for (let [i, a] of Object.entries(e.fields)) a.kind === "components" && a.components !== void 0 && (r[i] = mn(t[i], new Map(a.components.map((e) => [e.id, e])), n));
2103
+ return r;
2104
+ }, gn = (e) => new Set(Object.values(e.fields).flatMap((e) => (e.components ?? []).flatMap((e) => e.consent === void 0 ? [] : [e.consent]))), _n = (e) => Array.isArray(e) ? e.filter((e) => typeof e == "string") : [], vn = (e) => {
2105
+ let t = new Map(e.ceiling.map((t) => [t, {
2106
+ tool: t,
2107
+ state: e.defaults.includes(t) ? "on" : "off",
2108
+ decidedAt: null
2109
+ }]));
2110
+ e.chain.forEach((e, n) => {
2111
+ let r = (e, r) => {
2112
+ let i = t.get(e);
2113
+ i !== void 0 && i.state !== "locked" && t.set(e, {
2114
+ tool: e,
2115
+ state: r,
2116
+ decidedAt: n
2117
+ });
2118
+ };
2119
+ for (let t of _n(e.locked)) r(t, "locked");
2120
+ for (let t of _n(e.off)) r(t, "off");
2121
+ for (let t of _n(e.on)) r(t, "on");
2122
+ });
2123
+ let n = e.ceiling.map((e) => t.get(e));
2124
+ return {
2125
+ tools: n.filter((e) => e.state === "on").map((e) => e.tool),
2126
+ explained: n
2127
+ };
2128
+ }, G = class extends Error {
2129
+ reason;
2130
+ _tag = "XliffInvalid";
2131
+ constructor(e) {
2132
+ super(`XLIFF not accepted: ${e}`), this.reason = e;
2133
+ }
2134
+ }, yn = (e) => e.kind === "string" && e.pattern === void 0 && e.derived === void 0 && e.literals === void 0, bn = (e, t, n) => {
2135
+ switch (t.type) {
2136
+ case "paragraph":
2137
+ case "heading": return [{
2138
+ id: `${e}/${t.id}`,
2139
+ source: A(t.content)
2140
+ }];
2141
+ case "list": return t.items.map((n, r) => ({
2142
+ id: `${e}/${t.id}/${r}`,
2143
+ source: A(n)
2144
+ }));
2145
+ case "table": return t.rows.flatMap((n, r) => n.map((n, i) => ({
2146
+ id: `${e}/${t.id}/${r}.${i}`,
2147
+ source: A(n)
2148
+ })));
2149
+ case "image": return t.caption === void 0 || t.caption === "" ? [] : [{
2150
+ id: `${e}/${t.id}/caption`,
2151
+ source: t.caption
2152
+ }];
2153
+ case "file": return t.label === "" ? [] : [{
2154
+ id: `${e}/${t.id}/label`,
2155
+ source: t.label
2156
+ }];
2157
+ case "component": {
2158
+ let r = n.richText?.profile?.components.find((e) => e.id === t.componentId);
2159
+ return r === void 0 ? [] : [...Cn(r.props, t.props, `${e}/${t.id}/`)];
2160
+ }
2161
+ }
2162
+ }, xn = (e) => {
2163
+ let t = e?.blocks;
2164
+ return Array.isArray(t) ? t : [];
2165
+ }, Sn = (e) => Array.isArray(e) ? e : [], Cn = (e, t, n = "") => {
2166
+ let r = [];
2167
+ for (let [i, a] of Object.entries(e)) {
2168
+ let e = `${n}${i}`, o = t[i];
2169
+ if (yn(a)) typeof o == "string" && o.trim() !== "" && r.push({
2170
+ id: e,
2171
+ source: o
2172
+ });
2173
+ else if (a.kind === "richText") for (let t of xn(o)) r.push(...bn(e, t, a));
2174
+ else if (a.kind === "components") {
2175
+ let t = new Map((a.components ?? []).map((e) => [e.id, e]));
2176
+ for (let n of Sn(o)) {
2177
+ let i = n.componentId === void 0 ? void 0 : t.get(n.componentId);
2178
+ i !== void 0 && n.instanceId !== void 0 && r.push(...Cn(i.props, n.props ?? {}, `${e}/${n.instanceId}/`));
2179
+ }
2180
+ }
2181
+ }
2182
+ return r.filter((e) => e.source.trim() !== "");
2183
+ }, wn = (e) => e.some((e) => e.change !== void 0), Tn = (e, t, n) => {
2184
+ switch (t.type) {
2185
+ case "paragraph":
2186
+ case "heading": return wn(t.content) ? [{
2187
+ id: `${e}/${t.id}`,
2188
+ kind: "suggestedChange"
2189
+ }] : [];
2190
+ case "list": return t.items.some(wn) ? [{
2191
+ id: `${e}/${t.id}`,
2192
+ kind: "suggestedChange"
2193
+ }] : [];
2194
+ case "table": return t.rows.some((e) => e.some(wn)) ? [{
2195
+ id: `${e}/${t.id}`,
2196
+ kind: "suggestedChange"
2197
+ }] : [];
2198
+ case "image":
2199
+ case "file": return [];
2200
+ case "component": {
2201
+ let r = n.richText?.profile?.components.find((e) => e.id === t.componentId);
2202
+ return r === void 0 ? [{
2203
+ id: `${e}/${t.id}`,
2204
+ kind: "unknownComponent"
2205
+ }] : [...En(r.props, t.props, `${e}/${t.id}/`)];
2206
+ }
2207
+ }
2208
+ }, En = (e, t, n = "") => {
2209
+ let r = [];
2210
+ for (let [i, a] of Object.entries(e)) {
2211
+ let e = `${n}${i}`, o = t[i];
2212
+ if (a.kind === "richText") for (let t of xn(o)) r.push(...Tn(e, t, a));
2213
+ else if (a.kind === "components") {
2214
+ let t = new Map((a.components ?? []).map((e) => [e.id, e]));
2215
+ for (let n of Sn(o)) {
2216
+ if (n.instanceId === void 0) continue;
2217
+ let i = n.componentId === void 0 ? void 0 : t.get(n.componentId);
2218
+ i === void 0 ? r.push({
2219
+ id: `${e}/${n.instanceId}`,
2220
+ kind: "unknownComponent"
2221
+ }) : r.push(...En(i.props, n.props ?? {}, `${e}/${n.instanceId}/`));
2222
+ }
2223
+ }
2224
+ }
2225
+ return r;
2226
+ }, Dn = (e) => {
2227
+ let t = 2166136261;
2228
+ for (let n of e) for (let e of `${n.id}\u0000${n.source}\u0001`) t ^= e.codePointAt(0) ?? 0, t = Math.imul(t, 16777619) >>> 0;
2229
+ return t.toString(16).padStart(8, "0");
2230
+ }, On = (e, t, n) => {
2231
+ let r = new Map(n.filter((e) => e.target !== void 0).map((e) => [e.id, e.target])), i = (e, t, n) => {
2232
+ let a = { ...t };
2233
+ for (let [o, s] of Object.entries(e)) {
2234
+ let e = `${n}${o}`, c = t[o];
2235
+ if (yn(s)) {
2236
+ let t = r.get(e);
2237
+ t !== void 0 && typeof c == "string" && (a[o] = t);
2238
+ } else if (s.kind === "richText" && typeof c == "object" && c) {
2239
+ let t = s.richText?.profile, n = Object.keys(t?.styles?.tokens ?? {}), l = (e, t) => {
2240
+ let i = r.get(e);
2241
+ return i === void 0 ? t : ye(i, n);
2242
+ };
2243
+ a[o] = {
2244
+ ...c,
2245
+ blocks: xn(c).map((n) => {
2246
+ let a = `${e}/${n.id}`;
2247
+ switch (n.type) {
2248
+ case "paragraph":
2249
+ case "heading": return {
2250
+ ...n,
2251
+ content: l(a, n.content)
2252
+ };
2253
+ case "list": return {
2254
+ ...n,
2255
+ items: n.items.map((e, t) => l(`${a}/${t}`, e))
2256
+ };
2257
+ case "table": return {
2258
+ ...n,
2259
+ rows: n.rows.map((e, t) => e.map((e, n) => l(`${a}/${t}.${n}`, e)))
2260
+ };
2261
+ case "image": {
2262
+ let e = r.get(`${a}/caption`);
2263
+ return e === void 0 ? n : {
2264
+ ...n,
2265
+ caption: e
2266
+ };
2267
+ }
2268
+ case "file": {
2269
+ let e = r.get(`${a}/label`);
2270
+ return e === void 0 ? n : {
2271
+ ...n,
2272
+ label: e
2273
+ };
2274
+ }
2275
+ case "component": {
2276
+ let e = t?.components.find((e) => e.id === n.componentId);
2277
+ return e === void 0 ? n : {
2278
+ ...n,
2279
+ props: i(e.props, n.props, `${a}/`)
2280
+ };
2281
+ }
2282
+ }
2283
+ })
2284
+ };
2285
+ } else if (s.kind === "components" && Array.isArray(c)) {
2286
+ let t = new Map((s.components ?? []).map((e) => [e.id, e]));
2287
+ a[o] = Sn(c).map((n) => {
2288
+ let r = n.componentId === void 0 ? void 0 : t.get(n.componentId);
2289
+ return r === void 0 || n.instanceId === void 0 ? n : {
2290
+ ...n,
2291
+ props: i(r.props, n.props ?? {}, `${e}/${n.instanceId}/`)
2292
+ };
2293
+ });
2294
+ }
2295
+ }
2296
+ return a;
2297
+ };
2298
+ return i(e, t, "");
2299
+ }, kn = (e, t) => {
2300
+ let n = new Set(e.map((e) => e.id)), r = new Map(t.map((e) => [e.id, e])), i = 0, a = 0;
2301
+ for (let e of t) n.has(e.id) && (e.target !== void 0 && e.target.trim() !== "" ? i++ : a++);
2302
+ return {
2303
+ translated: i,
2304
+ untranslated: a,
2305
+ unknown: t.filter((e) => !n.has(e.id)).map((e) => e.id),
2306
+ missing: e.filter((e) => !r.has(e.id)).map((e) => e.id)
2307
+ };
2308
+ }, K = (e) => e.replace(/[&<>"']/g, (e) => ({
2309
+ "&": "&amp;",
2310
+ "<": "&lt;",
2311
+ ">": "&gt;",
2312
+ "\"": "&quot;",
2313
+ "'": "&apos;"
2314
+ })[e]), An = (e) => {
2315
+ let t = Object.entries(e.notes);
2316
+ return [
2317
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
2318
+ `<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.1" srcLang="${K(e.srcLang)}" trgLang="${K(e.trgLang)}">`,
2319
+ ` <file id="${K(e.fileId)}">`,
2320
+ ...t.length === 0 ? [] : [
2321
+ " <notes>",
2322
+ ...t.map(([e, t]) => ` <note category="${K(e)}">${K(t)}</note>`),
2323
+ " </notes>"
2324
+ ],
2325
+ ...e.units.flatMap((e) => [
2326
+ ` <unit id="${K(e.id)}">`,
2327
+ ` <segment${e.state === void 0 ? "" : ` state="${e.state}"`}>`,
2328
+ ` <source>${K(e.source)}</source>`,
2329
+ ...e.target === void 0 ? [] : [` <target>${K(e.target)}</target>`],
2330
+ " </segment>",
2331
+ " </unit>"
2332
+ ]),
2333
+ " </file>",
2334
+ "</xliff>",
2335
+ ""
2336
+ ].join("\n");
2337
+ }, jn = 5242880, Mn = {
2338
+ lt: "<",
2339
+ gt: ">",
2340
+ amp: "&",
2341
+ quot: "\"",
2342
+ apos: "'"
2343
+ }, Nn = (e) => e.replace(/&(#x[0-9a-fA-F]+|#[0-9]+|[a-zA-Z]+);/g, (e, t) => {
2344
+ if (t.startsWith("#x")) return String.fromCodePoint(Number.parseInt(t.slice(2), 16));
2345
+ if (t.startsWith("#")) return String.fromCodePoint(Number.parseInt(t.slice(1), 10));
2346
+ let n = Mn[t];
2347
+ if (n === void 0) throw new G(`unknown entity ${e}`);
2348
+ return n;
2349
+ }), Pn = (e) => e.slice(e.indexOf(":") + 1), Fn = (e) => {
2350
+ if (e.length > jn) throw new G("larger than 5 MB");
2351
+ if (/<!DOCTYPE|<!ENTITY/i.test(e)) throw new G("a DOCTYPE or entity declaration is not allowed");
2352
+ let t = {
2353
+ name: "#root",
2354
+ attrs: {},
2355
+ children: []
2356
+ }, n = [t], r = 0, i = () => n[n.length - 1];
2357
+ for (; r < e.length;) {
2358
+ let a = e.indexOf("<", r);
2359
+ if (a === -1) {
2360
+ i().children.push(Nn(e.slice(r)));
2361
+ break;
2362
+ }
2363
+ if (a > r && i().children.push(Nn(e.slice(r, a))), e.startsWith("<?", a)) {
2364
+ if (r = e.indexOf("?>", a) + 2, r < 2) throw new G("unterminated declaration");
2365
+ continue;
2366
+ }
2367
+ if (e.startsWith("<!--", a)) {
2368
+ if (r = e.indexOf("-->", a) + 3, r < 3) throw new G("unterminated comment");
2369
+ continue;
2370
+ }
2371
+ if (e.startsWith("<![CDATA[", a)) {
2372
+ let t = e.indexOf("]]>", a);
2373
+ if (t === -1) throw new G("unterminated CDATA");
2374
+ i().children.push(e.slice(a + 9, t)), r = t + 3;
2375
+ continue;
2376
+ }
2377
+ let o = e.indexOf(">", a);
2378
+ if (o === -1) throw new G("unterminated tag");
2379
+ let s = e.slice(a + 1, o);
2380
+ if (r = o + 1, s.startsWith("/")) {
2381
+ let e = Pn(s.slice(1).trim()), r = n.pop();
2382
+ if (r === void 0 || r === t || r.name !== e) throw new G(`unexpected </${e}>`);
2383
+ continue;
2384
+ }
2385
+ let c = s.endsWith("/"), l = c ? s.slice(0, -1) : s, u = /^\s*([A-Za-z_][\w.:-]*)/.exec(l);
2386
+ if (u === null) throw new G("malformed tag");
2387
+ let d = {};
2388
+ for (let e of l.slice(u[0].length).matchAll(/([A-Za-z_][\w.:-]*)\s*=\s*("([^"]*)"|'([^']*)')/g)) d[Pn(e[1])] = Nn(e[3] ?? e[4] ?? "");
2389
+ let f = {
2390
+ name: Pn(u[1]),
2391
+ attrs: d,
2392
+ children: []
2393
+ };
2394
+ i().children.push(f), c || n.push(f);
2395
+ }
2396
+ if (n.length !== 1) throw new G(`unclosed <${i().name}>`);
2397
+ let a = t.children.filter((e) => typeof e != "string");
2398
+ if (a.length !== 1) throw new G("not one root element");
2399
+ return a[0];
2400
+ }, q = (e, t) => e.children.filter((e) => typeof e != "string" && e.name === t), In = (e, t) => e.children.map((e) => {
2401
+ if (typeof e == "string") return e;
2402
+ throw new G(`inline <${e.name}> in ${t} is not supported`);
2403
+ }).join(""), Ln = /* @__PURE__ */ new Set([
2404
+ "initial",
2405
+ "translated",
2406
+ "reviewed",
2407
+ "final"
2408
+ ]), Rn = (e) => {
2409
+ let t = Fn(e);
2410
+ if (t.name !== "xliff") throw new G("the root element is not <xliff>");
2411
+ if (!/^2\./.test(t.attrs.version ?? "")) throw new G(`version ${t.attrs.version ?? "(none)"} is not XLIFF 2`);
2412
+ let n = t.attrs.srcLang, r = t.attrs.trgLang;
2413
+ if (!n || !r) throw new G("srcLang and trgLang are required");
2414
+ let i = q(t, "file");
2415
+ if (i.length !== 1) throw new G(`expected one <file>, found ${i.length}`);
2416
+ let a = i[0], o = {};
2417
+ for (let e of q(a, "notes")) for (let t of q(e, "note")) {
2418
+ let e = t.attrs.category;
2419
+ e !== void 0 && (o[e] = In(t, "a note"));
2420
+ }
2421
+ let s = q(a, "unit").map((e) => {
2422
+ let t = e.attrs.id;
2423
+ if (!t) throw new G("a <unit> without an id");
2424
+ let n = q(e, "segment"), r = [], i = [], a;
2425
+ for (let e of n) {
2426
+ let n = q(e, "source")[0];
2427
+ if (n === void 0) throw new G(`unit ${t}: a <segment> without <source>`);
2428
+ r.push(In(n, `unit ${t}`));
2429
+ let o = q(e, "target")[0];
2430
+ o !== void 0 && i.push(In(o, `unit ${t}`));
2431
+ let s = e.attrs.state;
2432
+ s !== void 0 && Ln.has(s) && (a = s);
2433
+ }
2434
+ return {
2435
+ id: t,
2436
+ source: r.join(""),
2437
+ ...i.length === n.length && n.length > 0 ? { target: i.join("") } : {},
2438
+ ...a === void 0 ? {} : { state: a }
2439
+ };
2440
+ });
2441
+ return {
2442
+ srcLang: n,
2443
+ trgLang: r,
2444
+ fileId: a.attrs.id ?? "",
2445
+ notes: o,
2446
+ units: s
2447
+ };
2448
+ }, zn = {
2449
+ blockNames: {
2450
+ paragraph: "Paragraph",
2451
+ heading: "Heading",
2452
+ list: "List",
2453
+ table: "Table",
2454
+ image: "Image",
2455
+ file: "Download",
2456
+ component: "Component"
2457
+ },
2458
+ moveUp: "Move up",
2459
+ moveDown: "Move down",
2460
+ remove: "Remove",
2461
+ moveUpLabel: (e) => `Move ${e} up`,
2462
+ moveDownLabel: (e) => `Move ${e} down`,
2463
+ removeLabel: (e) => `Remove ${e}`,
2464
+ add: "Add",
2465
+ addBlock: "Add block",
2466
+ addComponent: "Add component",
2467
+ findComponent: "Find a component by what it is for",
2468
+ noComponentFound: "No component matches.",
2469
+ otherComponents: "Other",
2470
+ unknownComponent: (e) => `Unknown component '${e}'.`,
2471
+ level: "Level",
2472
+ numbered: "Numbered",
2473
+ numberedAt: (e) => `Numbered at level ${e}`,
2474
+ headerRow: "First row is the header",
2475
+ image: "Image",
2476
+ file: "File",
2477
+ fileLabel: "Link text",
2478
+ caption: "Caption",
2479
+ text: "Text",
2480
+ listItems: "Items, one per line (two spaces in front nest an item)",
2481
+ tableRows: "Rows, one per line, cells split by |",
2482
+ linkTo: "Link to",
2483
+ linkText: "Link text",
2484
+ insertLink: "Insert link",
2485
+ item: (e, t) => `${e} ${t}`,
2486
+ addItem: "Add entry",
2487
+ bold: "Bold",
2488
+ italic: "Italic",
2489
+ underline: "Underline",
2490
+ style: "Style",
2491
+ noStyle: "No style",
2492
+ component: "Component",
2493
+ contactKind: "Contact",
2494
+ contactPoint: "Contact point",
2495
+ contactEmail: "E-mail address",
2496
+ contactPhone: "Phone number",
2497
+ contactValue: "Address or number",
2498
+ contactText: "Contact text",
2499
+ insertContact: "Insert contact",
2500
+ suggestedChanges: "Suggested changes — accept or reject them to edit this block again.",
2501
+ changeBy: (e, t, n) => [
2502
+ `${e}:`,
2503
+ t === "" ? "" : `adds “${t}”`,
2504
+ n === "" ? "" : `removes “${n}”`,
2505
+ t === "" && n === "" ? "changes the block" : ""
2506
+ ].filter((e) => e !== "").join(" "),
2507
+ accept: "Accept",
2508
+ reject: "Reject",
2509
+ acceptLabel: (e) => `Accept the change by ${e}`,
2510
+ rejectLabel: (e) => `Reject the change by ${e}`
2511
+ }, Bn = (e) => e === void 0 ? zn : {
2512
+ ...zn,
2513
+ ...e,
2514
+ blockNames: {
2515
+ ...zn.blockNames,
2516
+ ...e.blockNames
2517
+ }
2518
+ }, Vn = [
2519
+ "inventory",
2520
+ "mapping",
2521
+ "dryRun",
2522
+ "reconciliation",
2523
+ "delta",
2524
+ "cutover",
2525
+ "fallback",
2526
+ "uat"
2527
+ ], Hn = /^[A-Za-z0-9_.:-]{1,120}$/, Un = (e) => typeof e == "object" && !!e && !Array.isArray(e), J = (e) => typeof e == "string" && Hn.test(e), Wn = (e) => Number.isInteger(e) && e >= 0 && e <= 1e6, Gn = (e) => typeof e == "string" && /^\/(?![/\\])[^\s]*$/.test(e) && e.length <= 2e3, Kn = (e) => {
2528
+ if (!Un(e) || !J(e.id) || !J(e.pick) || !Gn(e.returnTo) || !Un(e.target)) return null;
2529
+ let t = e.target;
2530
+ if (!J(t.type) || !J(t.field)) return null;
2531
+ let n = t.documentId !== void 0 || t.revisionId !== void 0;
2532
+ if ((n ? !(J(t.documentId) && J(t.revisionId)) || t.formId !== void 0 : !J(t.formId)) || t.instanceId !== void 0 != (t.prop !== void 0) || t.instanceId !== void 0 && (!J(t.instanceId) || !J(t.prop) || t.blockId !== void 0) || t.locale !== void 0 && !J(t.locale) || t.blockId !== void 0 && !J(t.blockId)) return null;
2533
+ let r = t.selection;
2534
+ return r !== void 0 && !(Un(r) && Wn(r.start) && Wn(r.end) && r.end > r.start && t.blockId !== void 0) || e.label !== void 0 && (typeof e.label != "string" || e.label.length > 200) || e.kind !== void 0 && !J(e.kind) ? null : {
2535
+ id: e.id,
2536
+ pick: e.pick,
2537
+ returnTo: e.returnTo,
2538
+ ...typeof e.label == "string" ? { label: e.label } : {},
2539
+ ...typeof e.kind == "string" ? { kind: e.kind } : {},
2540
+ target: {
2541
+ type: t.type,
2542
+ field: t.field,
2543
+ ...n ? {
2544
+ documentId: t.documentId,
2545
+ revisionId: t.revisionId
2546
+ } : { formId: t.formId },
2547
+ ...t.instanceId === void 0 ? {} : {
2548
+ instanceId: t.instanceId,
2549
+ prop: t.prop
2550
+ },
2551
+ ...t.locale === void 0 ? {} : { locale: t.locale },
2552
+ ...t.blockId === void 0 ? {} : { blockId: t.blockId },
2553
+ ...Un(r) ? { selection: {
2554
+ start: r.start,
2555
+ end: r.end
2556
+ } } : {}
2557
+ }
2558
+ };
2559
+ }, qn = (e) => {
2560
+ let t = new TextEncoder().encode(e), n = "";
2561
+ for (let e of t) n += String.fromCharCode(e);
2562
+ return btoa(n).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
2563
+ }, Jn = (e) => {
2564
+ try {
2565
+ let t = atob(e.replace(/-/g, "+").replace(/_/g, "/"));
2566
+ return new TextDecoder("utf-8", { fatal: !0 }).decode(Uint8Array.from(t, (e) => e.charCodeAt(0)));
2567
+ } catch {
2568
+ return null;
2569
+ }
2570
+ }, Yn = (e) => qn(JSON.stringify(e)), Xn = (e) => {
2571
+ if (e == null || e === "" || e.length > 6e3) return null;
2572
+ let t = Jn(e);
2573
+ if (t === null) return null;
2574
+ try {
2575
+ return Kn(JSON.parse(t));
2576
+ } catch {
2577
+ return null;
2578
+ }
2579
+ }, Zn = (e, t, n, r) => {
2580
+ if (e.type !== "paragraph" && e.type !== "heading") return null;
2581
+ let i = e.content, a = F(i).length;
2582
+ if (n === void 0 || n.end > a) {
2583
+ if (r === void 0 || r === "") return null;
2584
+ let n = a === 0 || /\s$/.test(F(i)) ? [] : [{
2585
+ type: "text",
2586
+ text: " "
2587
+ }];
2588
+ return {
2589
+ ...e,
2590
+ content: P([
2591
+ ...i,
2592
+ ...n,
2593
+ {
2594
+ type: "link",
2595
+ target: t,
2596
+ text: r
2597
+ }
2598
+ ])
2599
+ };
2600
+ }
2601
+ let o = F(i).slice(n.start, n.end);
2602
+ return {
2603
+ ...e,
2604
+ content: P([
2605
+ ...I(i, 0, n.start),
2606
+ {
2607
+ type: "link",
2608
+ target: t,
2609
+ text: o
2610
+ },
2611
+ ...I(i, n.end, a)
2612
+ ])
2613
+ };
2614
+ }, Qn = (e, t, n, r) => {
2615
+ if (n.intentId !== t.id) return {
2616
+ ok: !1,
2617
+ reason: "otherIntent"
2618
+ };
2619
+ let { target: i } = t;
2620
+ if (i.formId !== void 0) {
2621
+ if (r.formId !== i.formId) return {
2622
+ ok: !1,
2623
+ reason: "otherDocument"
2624
+ };
2625
+ } else {
2626
+ if (r.documentId !== i.documentId) return {
2627
+ ok: !1,
2628
+ reason: "otherDocument"
2629
+ };
2630
+ if (r.revisionId !== i.revisionId) return {
2631
+ ok: !1,
2632
+ reason: "revisionMoved"
2633
+ };
2634
+ }
2635
+ if (i.instanceId !== void 0 && i.prop !== void 0) {
2636
+ let t = Array.isArray(e[i.field]) ? e[i.field] : [], r = t.findIndex((e) => e.instanceId === i.instanceId);
2637
+ if (r < 0) return {
2638
+ ok: !1,
2639
+ reason: "targetGone"
2640
+ };
2641
+ let a = i.prop;
2642
+ return {
2643
+ ok: !0,
2644
+ values: {
2645
+ ...e,
2646
+ [i.field]: t.map((e, t) => t === r ? {
2647
+ ...e,
2648
+ props: {
2649
+ ...e.props,
2650
+ [a]: n.documentId
2651
+ }
2652
+ } : e)
2653
+ }
2654
+ };
2655
+ }
2656
+ if (i.blockId === void 0) return {
2657
+ ok: !0,
2658
+ values: {
2659
+ ...e,
2660
+ [i.field]: n.documentId
2661
+ }
2662
+ };
2663
+ let a = k(e[i.field] ?? ""), o = Array.isArray(a.blocks) ? a.blocks.findIndex((e) => e.id === i.blockId) : -1;
2664
+ if (o < 0) return {
2665
+ ok: !1,
2666
+ reason: "targetGone"
2667
+ };
2668
+ let s = a.blocks[o], c = s.type === "image" || s.type === "file" ? {
2669
+ ...s,
2670
+ asset: n.documentId
2671
+ } : Zn(s, n.documentId, i.selection, n.title);
2672
+ return c === null ? {
2673
+ ok: !1,
2674
+ reason: "targetGone"
2675
+ } : {
2676
+ ok: !0,
2677
+ values: {
2678
+ ...e,
2679
+ [i.field]: {
2680
+ ...a,
2681
+ blocks: a.blocks.map((e, t) => t === o ? c : e)
2682
+ }
2683
+ }
2684
+ };
2685
+ }, $n = /^(utm_[a-z]+|fbclid|gclid|dclid|msclkid|mc_[a-z]+|_ga|_gl|ref)$/i, er = (e) => {
2686
+ let t = 2166136261;
2687
+ for (let n of e) t ^= n.codePointAt(0) ?? 0, t = Math.imul(t, 16777619) >>> 0;
2688
+ return t.toString(36);
2689
+ }, tr = (e) => new Map((e ?? "").split(";").map((e) => e.trim()).filter((e) => e.includes("=")).map((e) => [e.slice(0, e.indexOf("=")).trim(), e.slice(e.indexOf("=") + 1).trim()])), nr = (e, t) => t.startsWith("cookie:") ? tr(e.headers.cookie).get(t.slice(7)) : e.headers[t.toLowerCase()], rr = (e) => {
2690
+ if (!e.startsWith("/") || /%2f|%5c|%25|%00/i.test(e) || e.includes("\\")) return null;
2691
+ let t;
2692
+ try {
2693
+ t = decodeURIComponent(e);
2694
+ } catch {
2695
+ return null;
2696
+ }
2697
+ let n = t.split("/").slice(1);
2698
+ return n.some((e, t) => e === "." || e === ".." || e === "" && t < n.length - 1) ? null : `/${n.map((e) => encodeURIComponent(e)).join("/")}`;
2699
+ }, ir = (e, t) => {
2700
+ if (t === void 0 || t === "") return e.fallback;
2701
+ if (e.values.includes(t)) return t;
2702
+ let n = t.split(",").map((e) => e.split(";")[0].trim()).filter((e) => e !== "");
2703
+ for (let t of n) {
2704
+ let n = e.values.find((e) => e.toLowerCase() === t.toLowerCase());
2705
+ if (n !== void 0) return n;
2706
+ let r = e.values.find((e) => e.toLowerCase().split("-")[0] === t.toLowerCase().split("-")[0]);
2707
+ if (r !== void 0) return r;
2708
+ }
2709
+ return e.fallback;
2710
+ }, ar = (e, t) => {
2711
+ switch (e.type) {
2712
+ case "string": return t.length <= (e.maxLength ?? 200) ? t : null;
2713
+ case "int": {
2714
+ if (!/^-?\d{1,9}$/.test(t)) return null;
2715
+ let n = Number(t);
2716
+ return e.min !== void 0 && n < e.min || e.max !== void 0 && n > e.max ? null : String(n);
2717
+ }
2718
+ case "enum": return e.values.includes(t) ? t : null;
2719
+ }
2720
+ }, or = (e) => [
2721
+ e.locale,
2722
+ e.audience,
2723
+ e.consent
2724
+ ].reduce((e, t) => e * (t?.values.length ?? 1), 1) * (e.query ?? []).reduce((e, t) => e * (t.type === "enum" ? t.values.length + 1 : t.type === "int" && t.min !== void 0 && t.max !== void 0 ? t.max - t.min + 2 : 1), 1), sr = (e, t, n) => {
2725
+ let r = [], i = (e, t) => ({
2726
+ cacheable: !1,
2727
+ reason: e,
2728
+ detail: t,
2729
+ cacheControl: "private, no-store",
2730
+ explain: r
2731
+ }), a = t.method.toUpperCase();
2732
+ if (a !== "GET" && a !== "HEAD") return i("method", `${a} is never shared-cached`);
2733
+ if (t.headers.authorization !== void 0) return i("credential", "the request carries authorization");
2734
+ for (let n of e.credentials ?? []) if (nr(t, n) !== void 0) return i("credential", `the request carries ${n}`);
2735
+ let o = rr(t.path);
2736
+ if (o === null) return i("path", `the path ${t.path.slice(0, 120)} has no single canonical form`);
2737
+ let s = or(e), c = e.cardinalityBudget ?? 64;
2738
+ if (s > c) return i("budget", `${s} variants exceed the budget of ${c}`);
2739
+ let l = t.host.toLowerCase().replace(/:(80|443)$/, "");
2740
+ r.push({
2741
+ dimension: "host",
2742
+ included: !0,
2743
+ value: l,
2744
+ why: "the site and domain binding"
2745
+ }), r.push({
2746
+ dimension: "path",
2747
+ included: !0,
2748
+ value: o,
2749
+ why: "canonical encoding"
2750
+ });
2751
+ let u = new Map((e.query ?? []).map((e) => [e.name, e])), d = [];
2752
+ for (let [e, n] of new URLSearchParams(t.query)) {
2753
+ let t = u.get(e);
2754
+ if (t === void 0) {
2755
+ r.push({
2756
+ dimension: `query:${e}`,
2757
+ included: !1,
2758
+ value: n,
2759
+ why: $n.test(e) ? "tracking parameter" : "not declared by the route"
2760
+ });
2761
+ continue;
2762
+ }
2763
+ let i = ar(t, n);
2764
+ if (i === null || i === "" || i === String(t.default ?? "")) {
2765
+ r.push({
2766
+ dimension: `query:${e}`,
2767
+ included: !1,
2768
+ value: n,
2769
+ why: i === null ? "not a valid value" : "empty or the default"
2770
+ });
2771
+ continue;
2772
+ }
2773
+ d.some(([t]) => t === e) || (d.push([e, i]), r.push({
2774
+ dimension: `query:${e}`,
2775
+ included: !0,
2776
+ value: i,
2777
+ why: `declared ${t.type}`
2778
+ }));
2779
+ }
2780
+ d.sort(([e], [t]) => e.localeCompare(t));
2781
+ let f = [], p = (e, n) => {
2782
+ if (n === void 0) return null;
2783
+ let i = nr(t, n.from), a = ir(n, i);
2784
+ return r.push({
2785
+ dimension: e,
2786
+ included: !0,
2787
+ value: a,
2788
+ why: i === void 0 ? `not given: ${n.fallback}` : `from ${n.from}, one of ${n.values.length}`
2789
+ }), n.from.startsWith("cookie:") ? f.includes("cookie") || f.push("cookie") : f.push(n.from), a;
2790
+ }, m = p("locale", e.locale), h = p("audience", e.audience), g = p("consent", e.consent);
2791
+ r.push({
2792
+ dimension: "checkpoint",
2793
+ included: !0,
2794
+ value: n.checkpoint,
2795
+ why: "the publication this answer belongs to"
2796
+ });
2797
+ let _ = [
2798
+ "v1",
2799
+ l,
2800
+ o,
2801
+ d.map(([e, t]) => `${e}=${t}`).join("&"),
2802
+ `locale=${m ?? ""}`,
2803
+ `audience=${h ?? ""}`,
2804
+ `consent=${g ?? ""}`,
2805
+ `checkpoint=${n.checkpoint}`
2806
+ ].join("|");
2807
+ return {
2808
+ cacheable: !0,
2809
+ key: _,
2810
+ fingerprint: er(_),
2811
+ vary: f,
2812
+ purge: {
2813
+ route: e.route,
2814
+ tags: [...new Set(n.tags ?? [])].sort()
2815
+ },
2816
+ variants: s,
2817
+ explain: r
2818
+ };
2819
+ }, cr = (e) => {
2820
+ let t = (e["cache-control"] ?? "").toLowerCase();
2821
+ return e["set-cookie"] === void 0 && !/\b(private|no-store)\b/.test(t);
2822
+ }, lr = (e, t, n) => {
2823
+ if (!t.cacheable) return { "cache-control": t.cacheControl };
2824
+ let r = n.staleWhileRevalidate === void 0 ? "" : `, stale-while-revalidate=${n.staleWhileRevalidate}`, i = `public, max-age=0, s-maxage=${n.maxAge}${r}`, a = t.vary.length === 0 ? {} : { vary: t.vary.join(", ") }, o = { "x-cache-identity": t.fingerprint };
2825
+ return e === "fastly" ? {
2826
+ "cache-control": "public, max-age=0",
2827
+ "surrogate-control": `max-age=${n.maxAge}${r}`,
2828
+ "surrogate-key": t.purge.tags.join(" "),
2829
+ ...a,
2830
+ ...o
2831
+ } : {
2832
+ "cache-control": i,
2833
+ "cache-tag": t.purge.tags.join(","),
2834
+ ...a,
2835
+ ...o
2836
+ };
2837
+ }, ur = /^[\w:.\-/@]{1,256}$/, dr = 30, fr = (e) => {
2838
+ if (e.length > 2048 || /[\s]/.test(e)) return null;
2839
+ try {
2840
+ let t = new URL(e);
2841
+ return t.protocol === "https:" || t.protocol === "http:" ? t.toString() : null;
2842
+ } catch {
2843
+ return null;
2844
+ }
2845
+ }, pr = (e, t, n, r = []) => {
2846
+ let i = [...new Set(n.filter((e) => ur.test(e)))], a = [...new Set(r.map(fr).filter((e) => e !== null))];
2847
+ if (t.target === "") return [];
2848
+ let o = t.token === null || t.token === "" ? {} : { authorization: `Bearer ${t.token}` };
2849
+ switch (e) {
2850
+ case "cloudflare": {
2851
+ let e = `https://api.cloudflare.com/client/v4/zones/${encodeURIComponent(t.target)}/purge_cache`, n = (t) => ({
2852
+ url: e,
2853
+ method: "POST",
2854
+ headers: {
2855
+ "content-type": "application/json",
2856
+ ...o
2857
+ },
2858
+ body: JSON.stringify(t)
2859
+ });
2860
+ return [...mr(i).map((e) => n({ tags: e })), ...mr(a).map((e) => n({ files: e }))];
2861
+ }
2862
+ case "fastly": {
2863
+ let e = t.token === null || t.token === "" ? {} : { "fastly-key": t.token };
2864
+ return [...i.length === 0 ? [] : [{
2865
+ url: `https://api.fastly.com/service/${encodeURIComponent(t.target)}/purge`,
2866
+ method: "POST",
2867
+ headers: {
2868
+ "surrogate-key": i.join(" "),
2869
+ ...e
2870
+ }
2871
+ }], ...a.map((t) => ({
2872
+ url: `https://api.fastly.com/purge/${t.replace(/^https?:\/\//, "")}`,
2873
+ method: "POST",
2874
+ headers: { ...e }
2875
+ }))];
2876
+ }
2877
+ case "webhook": {
2878
+ let e;
2879
+ try {
2880
+ e = new URL(t.target);
2881
+ } catch {
2882
+ return [];
2883
+ }
2884
+ return e.protocol !== "https:" && e.hostname !== "localhost" && e.hostname !== "127.0.0.1" || i.length === 0 && a.length === 0 ? [] : [{
2885
+ url: e.toString(),
2886
+ method: "POST",
2887
+ headers: {
2888
+ "content-type": "application/json",
2889
+ ...o
2890
+ },
2891
+ body: JSON.stringify(a.length === 0 ? { tags: i } : {
2892
+ tags: i,
2893
+ urls: a
2894
+ })
2895
+ }];
2896
+ }
2897
+ }
2898
+ }, mr = (e) => {
2899
+ let t = [];
2900
+ for (let n = 0; n < e.length; n += dr) t.push(e.slice(n, n + dr));
2901
+ return t;
2902
+ }, Y = ({ content: e, resolve: t }) => e.map((e, n) => {
2903
+ if (e.type === "link" || e.type === "contact") {
2904
+ let r = e.type === "link" ? t.hrefOf(e.target) : "target" in e.contact ? t.contactHrefOf(e.contact.target) : fe(e.contact.channel, e.contact.value);
2905
+ return r === void 0 ? /* @__PURE__ */ c("span", { children: e.text }, n) : /* @__PURE__ */ c("a", {
2906
+ href: r,
2907
+ children: e.text
2908
+ }, n);
2909
+ }
2910
+ let r = e.marks ?? [], i = e.text;
2911
+ return r.includes("underline") && (i = /* @__PURE__ */ c("u", { children: i })), r.includes("italic") && (i = /* @__PURE__ */ c("em", { children: i })), r.includes("bold") && (i = /* @__PURE__ */ c("strong", { children: i })), /* @__PURE__ */ c("span", {
2912
+ ...e.style === void 0 ? {} : { "data-style": e.style },
2913
+ children: i
2914
+ }, n);
2915
+ }).map((t, n) => {
2916
+ let r = e[n]?.change;
2917
+ if (r === void 0) return t;
2918
+ let i = r.kind === "insert" ? "ins" : "del";
2919
+ return /* @__PURE__ */ c(i, {
2920
+ "data-change-id": r.id,
2921
+ title: r.by,
2922
+ children: t
2923
+ }, n);
2924
+ }), hr = (e) => "style" in e && e.style !== void 0 ? { "data-style": e.style } : {}, gr = ({ block: e, resolve: t, renderImage: n, renderComponent: r, fileHrefOf: i }) => {
2925
+ switch (e.type) {
2926
+ case "paragraph": return /* @__PURE__ */ c("p", {
2927
+ "data-block-id": e.id,
2928
+ ...hr(e),
2929
+ children: /* @__PURE__ */ c(Y, {
2930
+ content: e.content,
2931
+ resolve: t
2932
+ })
2933
+ });
2934
+ case "heading": return e.level === 2 ? /* @__PURE__ */ c("h2", {
2935
+ "data-block-id": e.id,
2936
+ ...hr(e),
2937
+ children: /* @__PURE__ */ c(Y, {
2938
+ content: e.content,
2939
+ resolve: t
2940
+ })
2941
+ }) : /* @__PURE__ */ c("h3", {
2942
+ "data-block-id": e.id,
2943
+ ...hr(e),
2944
+ children: /* @__PURE__ */ c(Y, {
2945
+ content: e.content,
2946
+ resolve: t
2947
+ })
2948
+ });
2949
+ case "list": {
2950
+ let n = e.levels ?? e.items.map(() => 0), r = (t) => D(e, t) ? "ol" : "ul", i = (a, o) => {
2951
+ let s = [], u = a;
2952
+ for (; u < e.items.length && n[u] >= o;) {
2953
+ let n = u, [a, d] = i(u + 1, o + 1), f = r(o + 1);
2954
+ s.push(/* @__PURE__ */ l("li", { children: [/* @__PURE__ */ c(Y, {
2955
+ content: e.items[n],
2956
+ resolve: t
2957
+ }), a.length > 0 ? /* @__PURE__ */ c(f, { children: a }) : null] }, n)), u = d;
2958
+ }
2959
+ return [s, u];
2960
+ }, a = r(0);
2961
+ return /* @__PURE__ */ c(a, {
2962
+ "data-block-id": e.id,
2963
+ ...hr(e),
2964
+ children: i(0, 0)[0]
2965
+ });
2966
+ }
2967
+ case "table": {
2968
+ let [n, ...r] = e.header ? e.rows : [void 0, ...e.rows];
2969
+ return /* @__PURE__ */ l("table", {
2970
+ "data-block-id": e.id,
2971
+ children: [n === void 0 ? null : /* @__PURE__ */ c("thead", { children: /* @__PURE__ */ c("tr", { children: n.map((e, n) => /* @__PURE__ */ c("th", {
2972
+ scope: "col",
2973
+ children: /* @__PURE__ */ c(Y, {
2974
+ content: e,
2975
+ resolve: t
2976
+ })
2977
+ }, n)) }) }), /* @__PURE__ */ c("tbody", { children: r.map((e, n) => /* @__PURE__ */ c("tr", { children: (e ?? []).map((e, n) => /* @__PURE__ */ c("td", { children: /* @__PURE__ */ c(Y, {
2978
+ content: e,
2979
+ resolve: t
2980
+ }) }, n)) }, n)) })]
2981
+ });
2982
+ }
2983
+ case "image": return n === void 0 ? null : /* @__PURE__ */ c("div", {
2984
+ "data-block-id": e.id,
2985
+ children: n(e)
2986
+ });
2987
+ case "file": {
2988
+ let t = i(e.asset);
2989
+ return t === void 0 ? null : /* @__PURE__ */ c("p", {
2990
+ "data-block-id": e.id,
2991
+ "data-file": !0,
2992
+ children: /* @__PURE__ */ c("a", {
2993
+ href: t,
2994
+ download: !0,
2995
+ children: e.label
2996
+ })
2997
+ });
2998
+ }
2999
+ case "component": return r === void 0 ? null : /* @__PURE__ */ c("div", {
3000
+ "data-block-id": e.id,
3001
+ "data-component": e.componentId,
3002
+ children: r(e)
3003
+ });
3004
+ }
3005
+ }, _r = ({ block: e, children: t }) => e.change === void 0 || t === null ? t : /* @__PURE__ */ c("div", {
3006
+ "data-change": e.change.kind,
3007
+ "data-change-id": e.change.id,
3008
+ title: e.change.by,
3009
+ children: t
3010
+ }), vr = ({ document: e, hrefOf: t = () => void 0, renderImage: n, contactHrefOf: r = () => void 0, renderComponent: i, fileHrefOf: a = () => void 0 }) => {
3011
+ let o = {
3012
+ hrefOf: t,
3013
+ contactHrefOf: r
3014
+ }, l = k(e);
3015
+ return ge("", l, {
3016
+ images: "*",
3017
+ links: "*"
3018
+ }).some((e) => e.rule === "type" || e.rule === "unknown") ? null : /* @__PURE__ */ c(s, { children: l.blocks.map((e) => /* @__PURE__ */ c(_r, {
3019
+ block: e,
3020
+ children: /* @__PURE__ */ c(gr, {
3021
+ block: e,
3022
+ resolve: o,
3023
+ renderImage: n,
3024
+ renderComponent: i,
3025
+ fileHrefOf: a
3026
+ })
3027
+ }, e.id)) });
3028
+ }, yr = (e, t, n) => {
3029
+ let r = 0, i = null, a = (e) => {
3030
+ if (i === null) {
3031
+ if (e === t && e.nodeType !== 3) {
3032
+ for (let t = 0; t < n && t < e.childNodes.length; t++) r += br(e.childNodes[t]);
3033
+ i = r;
3034
+ return;
3035
+ }
3036
+ if (e.nodeType === 3) {
3037
+ if (e === t) {
3038
+ i = r + n;
3039
+ return;
3040
+ }
3041
+ r += (e.textContent ?? "").length;
3042
+ return;
3043
+ }
3044
+ if (e.nodeName === "BR") {
3045
+ r += 1;
3046
+ return;
3047
+ }
3048
+ for (let t of Array.from(e.childNodes)) a(t);
3049
+ }
3050
+ };
3051
+ return a(e), i ?? r;
3052
+ }, br = (e) => e.nodeType === 3 ? (e.textContent ?? "").length : e.nodeName === "BR" ? 1 : Array.from(e.childNodes).reduce((e, t) => e + br(t), 0), xr = (e, t) => {
3053
+ let n = 0, r = null, i = (e) => {
3054
+ if (r === null) {
3055
+ if (e.nodeType === 3) {
3056
+ let i = (e.textContent ?? "").length;
3057
+ if (t <= n + i) {
3058
+ r = [e, t - n];
3059
+ return;
3060
+ }
3061
+ n += i;
3062
+ return;
3063
+ }
3064
+ if (e.nodeName === "BR") {
3065
+ if (t <= n) {
3066
+ r = [e.parentNode, Array.from(e.parentNode.childNodes).indexOf(e)];
3067
+ return;
3068
+ }
3069
+ n += 1;
3070
+ return;
3071
+ }
3072
+ for (let t of Array.from(e.childNodes)) i(t);
3073
+ }
3074
+ };
3075
+ return i(e), r ?? [e, e.childNodes.length];
3076
+ }, X = (e) => {
3077
+ let t = e.ownerDocument.getSelection();
3078
+ if (t === null || t.rangeCount === 0) return null;
3079
+ let n = t.getRangeAt(0);
3080
+ return !e.contains(n.startContainer) || !e.contains(n.endContainer) ? null : [yr(e, n.startContainer, n.startOffset), yr(e, n.endContainer, n.endOffset)];
3081
+ }, Sr = (e, t, n) => {
3082
+ let r = e.ownerDocument.getSelection();
3083
+ if (r === null) return;
3084
+ let i = e.ownerDocument.createRange(), [a, o] = xr(e, t), [s, c] = xr(e, n);
3085
+ i.setStart(a, o), i.setEnd(s, c), r.removeAllRanges(), r.addRange(i);
3086
+ }, Cr = (e) => {
3087
+ let { id: r, labelledBy: i, content: o, onChange: s, words: c } = e, l = a(null), u = a("");
3088
+ n(() => {
3089
+ let e = l.current;
3090
+ if (e === null) return;
3091
+ let t = JSON.stringify(o);
3092
+ if (t === u.current) return;
3093
+ u.current = t;
3094
+ let n = e.ownerDocument.activeElement === e ? X(e) : null, r = e.textContent ?? "";
3095
+ if (e.innerHTML = Je(o), n === null) return;
3096
+ let i = e.textContent ?? "", a = 0;
3097
+ for (; a < r.length && a < i.length && r[a] === i[a];) a += 1;
3098
+ let s = (e) => Math.min(i.length, e <= a ? e : e + i.length - r.length);
3099
+ Sr(e, s(n[0]), s(n[1]));
3100
+ }, [o]);
3101
+ let d = (e, t) => {
3102
+ let n = l.current;
3103
+ n !== null && (u.current = JSON.stringify(e), n.innerHTML = Je(e), t !== void 0 && Sr(n, t[0], t[1]), s(e));
3104
+ }, f = () => {
3105
+ let e = l.current;
3106
+ if (e === null) return;
3107
+ let t = R(e);
3108
+ u.current = JSON.stringify(t), s(t);
3109
+ }, p = (e) => {
3110
+ let t = l.current, n = t === null ? null : X(t);
3111
+ n !== null && n[0] !== n[1] && d(Ke(R(t), n[0], n[1], e), n);
3112
+ }, m = (e) => {
3113
+ let t = {
3114
+ b: "bold",
3115
+ i: "italic",
3116
+ u: "underline"
3117
+ }[e.key.toLowerCase()];
3118
+ if ((e.ctrlKey || e.metaKey) && t !== void 0) {
3119
+ e.preventDefault(), p(t);
3120
+ return;
3121
+ }
3122
+ if (e.key === "Enter") {
3123
+ if (e.preventDefault(), !e.shiftKey || l.current === null) return;
3124
+ let t = X(l.current);
3125
+ t !== null && d(qe(R(l.current), t[0], t[1], "\n"), [t[0] + 1, t[0] + 1]);
3126
+ }
3127
+ }, h = (e) => {
3128
+ e.preventDefault();
3129
+ let t = l.current, n = e.clipboardData?.getData("text/plain") ?? "", r = t === null ? null : X(t);
3130
+ r !== null && n !== "" && d(qe(R(t), r[0], r[1], n), [r[0] + n.length, r[0] + n.length]);
3131
+ }, g = (e) => {
3132
+ let t = l.current, n = t === null ? null : X(t);
3133
+ return n !== null && Ge(o, n[0], n[1], e);
3134
+ }, _ = (e) => e.preventDefault();
3135
+ return t("div", { "data-cms-rich-surface": !0 }, t("div", {
3136
+ role: "toolbar",
3137
+ "aria-controls": r,
3138
+ "data-cms-rich-marks": !0
3139
+ }, t("button", {
3140
+ type: "button",
3141
+ onMouseDown: _,
3142
+ onClick: () => p("bold"),
3143
+ "aria-pressed": g("bold"),
3144
+ "aria-label": c.bold
3145
+ }, t("strong", null, "B")), t("button", {
3146
+ type: "button",
3147
+ onMouseDown: _,
3148
+ onClick: () => p("italic"),
3149
+ "aria-pressed": g("italic"),
3150
+ "aria-label": c.italic
3151
+ }, t("em", null, "I")), t("button", {
3152
+ type: "button",
3153
+ onMouseDown: _,
3154
+ onClick: () => p("underline"),
3155
+ "aria-pressed": g("underline"),
3156
+ "aria-label": c.underline
3157
+ }, t("u", null, "U"))), t("div", {
3158
+ id: r,
3159
+ ref: l,
3160
+ role: "textbox",
3161
+ "aria-multiline": !0,
3162
+ "aria-labelledby": i,
3163
+ contentEditable: !0,
3164
+ suppressContentEditableWarning: !0,
3165
+ tabIndex: 0,
3166
+ onInput: f,
3167
+ onKeyDown: m,
3168
+ onPaste: h,
3169
+ "data-cms-rich-text": !0
3170
+ }));
3171
+ }, wr = (e) => {
3172
+ let t = k(e ?? ""), n = t.blocks;
3173
+ return Array.isArray(n) ? t : {
3174
+ type: "doc",
3175
+ blocks: []
3176
+ };
3177
+ }, Tr = (e, t) => {
3178
+ let n = se();
3179
+ switch (e) {
3180
+ case "paragraph": return {
3181
+ id: n,
3182
+ type: e,
3183
+ content: []
3184
+ };
3185
+ case "heading": return {
3186
+ id: n,
3187
+ type: e,
3188
+ level: t.profile?.headings[0] ?? 2,
3189
+ content: []
3190
+ };
3191
+ case "list": return {
3192
+ id: n,
3193
+ type: e,
3194
+ ordered: !1,
3195
+ items: []
3196
+ };
3197
+ case "table": return {
3198
+ id: n,
3199
+ type: e,
3200
+ header: !0,
3201
+ rows: []
3202
+ };
3203
+ case "image": return {
3204
+ id: n,
3205
+ type: e,
3206
+ asset: ""
3207
+ };
3208
+ case "file": return {
3209
+ id: n,
3210
+ type: e,
3211
+ asset: "",
3212
+ label: ""
3213
+ };
3214
+ case "component": return {
3215
+ id: n,
3216
+ type: e,
3217
+ componentId: t.profile?.components[0]?.id ?? "",
3218
+ props: {}
3219
+ };
3220
+ }
3221
+ }, Er = ({ id: e, options: t, renderPicker: n, onInsert: r, words: i }) => {
3222
+ let a = t.profile?.contactPoints !== void 0 && n !== void 0 ? t.profile.contactPoints : void 0, u = t.profile?.contactLiterals === !0, [d, f] = o(a === void 0 ? "email" : "point"), [p, m] = o(""), [h, g] = o("");
3223
+ if (a === void 0 && !u) return null;
3224
+ let _ = d === "point" ? { target: p } : {
3225
+ channel: d,
3226
+ value: p.trim()
3227
+ };
3228
+ return /* @__PURE__ */ l("div", {
3229
+ "data-cms-rich-contact": !0,
3230
+ children: [
3231
+ /* @__PURE__ */ c("label", {
3232
+ htmlFor: `${e}-contact-kind`,
3233
+ children: i.contactKind
3234
+ }),
3235
+ /* @__PURE__ */ l("select", {
3236
+ id: `${e}-contact-kind`,
3237
+ value: d,
3238
+ onChange: (e) => {
3239
+ f(e.target.value), m("");
3240
+ },
3241
+ children: [
3242
+ a === void 0 ? null : /* @__PURE__ */ c("option", {
3243
+ value: "point",
3244
+ children: i.contactPoint
3245
+ }),
3246
+ u ? /* @__PURE__ */ c("option", {
3247
+ value: "email",
3248
+ children: i.contactEmail
3249
+ }) : null,
3250
+ u ? /* @__PURE__ */ c("option", {
3251
+ value: "phone",
3252
+ children: i.contactPhone
3253
+ }) : null
3254
+ ]
3255
+ }),
3256
+ d === "point" && a !== void 0 ? /* @__PURE__ */ l(s, { children: [/* @__PURE__ */ c("label", {
3257
+ htmlFor: `${e}-contact-value`,
3258
+ children: i.contactPoint
3259
+ }), n?.({
3260
+ id: `${e}-contact-value`,
3261
+ type: a,
3262
+ value: p,
3263
+ onChange: m,
3264
+ role: "contact"
3265
+ })] }) : /* @__PURE__ */ l(s, { children: [/* @__PURE__ */ c("label", {
3266
+ htmlFor: `${e}-contact-value`,
3267
+ children: i.contactValue
3268
+ }), /* @__PURE__ */ c("input", {
3269
+ id: `${e}-contact-value`,
3270
+ type: d === "email" ? "email" : "tel",
3271
+ value: p,
3272
+ onChange: (e) => m(e.target.value)
3273
+ })] }),
3274
+ /* @__PURE__ */ c("label", {
3275
+ htmlFor: `${e}-contact-text`,
3276
+ children: i.contactText
3277
+ }),
3278
+ /* @__PURE__ */ c("input", {
3279
+ id: `${e}-contact-text`,
3280
+ value: h,
3281
+ onChange: (e) => g(e.target.value)
3282
+ }),
3283
+ /* @__PURE__ */ c("button", {
3284
+ type: "button",
3285
+ disabled: p.trim() === "" || h.trim() === "",
3286
+ onClick: () => {
3287
+ r({
3288
+ type: "contact",
3289
+ text: h.trim(),
3290
+ contact: _
3291
+ }), m(""), g("");
3292
+ },
3293
+ children: i.insertContact
3294
+ })
3295
+ ]
3296
+ });
3297
+ }, Dr = ({ id: e, type: t, renderPicker: n, onInsert: r, words: i, target: a }) => {
3298
+ let [u, d] = o(""), [f, p] = o("");
3299
+ return /* @__PURE__ */ l("div", {
3300
+ "data-cms-rich-link": !0,
3301
+ role: "group",
3302
+ "aria-labelledby": `${e}-link-label`,
3303
+ children: [
3304
+ /* @__PURE__ */ c("span", {
3305
+ id: `${e}-link-label`,
3306
+ children: i.linkTo
3307
+ }),
3308
+ n({
3309
+ id: `${e}-link-target`,
3310
+ type: t,
3311
+ value: u,
3312
+ onChange: d,
3313
+ target: a,
3314
+ role: "link",
3315
+ labelledBy: `${e}-link-label`
3316
+ }),
3317
+ u === "" ? null : /* @__PURE__ */ l(s, { children: [
3318
+ /* @__PURE__ */ c("label", {
3319
+ htmlFor: `${e}-link-text`,
3320
+ children: i.linkText
3321
+ }),
3322
+ /* @__PURE__ */ c("input", {
3323
+ id: `${e}-link-text`,
3324
+ value: f,
3325
+ onChange: (e) => p(e.target.value)
3326
+ }),
3327
+ /* @__PURE__ */ c("button", {
3328
+ type: "button",
3329
+ disabled: f.trim() === "",
3330
+ onClick: () => {
3331
+ r({
3332
+ type: "link",
3333
+ target: u,
3334
+ text: f.trim()
3335
+ }), d(""), p("");
3336
+ },
3337
+ children: i.insertLink
3338
+ })
3339
+ ] })
3340
+ ]
3341
+ });
3342
+ }, Or = (e) => {
3343
+ let { id: t, name: n, field: a, value: u, onChange: d, renderPicker: f, renderBlockAside: p, renderComponentProps: m } = e, h = Bn(e.strings), g = a.richText ?? {}, _ = g.profile, v = Object.keys(_?.styles?.tokens ?? {}), y = i(() => wr(u), [u]), b = r(), [ee, te] = o({}), [x, ne] = o("paragraph"), S = Object.keys(h.blockNames).filter((e) => e !== "image" || g.images !== void 0 && f !== void 0).filter((e) => e !== "file" || g.files !== void 0 && f !== void 0).filter((e) => _ === void 0 ? e !== "component" : _.blocks.includes(e)).filter((e) => e !== "component" || m !== void 0), C = (e) => d({
3344
+ type: "doc",
3345
+ blocks: e
3346
+ }), w = (e, t) => C(y.blocks.map((n, r) => r === e ? t : n)), T = (e, t) => {
3347
+ if (t < 0 || t >= y.blocks.length) return;
3348
+ let n = [...y.blocks], [r] = n.splice(e, 1);
3349
+ r !== void 0 && n.splice(t, 0, r), C(n);
3350
+ }, E = (e, t, n) => {
3351
+ te((e) => ({
3352
+ ...e,
3353
+ [t.id]: n
3354
+ })), w(e, we(t, n, v));
3355
+ }, re = (e, t, n, r) => E(e, t, `${n}${n === "" || n.endsWith(" ") || n.endsWith("\n") ? "" : " "}${A([r])}`), ie = y.blocks.map((t, r) => {
3356
+ let i = `${h.blockNames[t.type]} ${r + 1}`, a = `${b}-${t.id}`, o = ee[t.id] ?? xe(t);
3357
+ if (z(t)) {
3358
+ let e = ut({
3359
+ type: "doc",
3360
+ blocks: [t]
3361
+ });
3362
+ return /* @__PURE__ */ l("fieldset", {
3363
+ "data-cms-rich-block": t.type,
3364
+ "data-cms-block-id": t.id,
3365
+ "data-cms-rich-suggested": !0,
3366
+ children: [
3367
+ /* @__PURE__ */ c("legend", { children: i }),
3368
+ /* @__PURE__ */ c("p", { children: h.suggestedChanges }),
3369
+ /* @__PURE__ */ c("div", {
3370
+ "data-cms-rich-preview": !0,
3371
+ children: /* @__PURE__ */ c(vr, { document: {
3372
+ type: "doc",
3373
+ blocks: [t]
3374
+ } })
3375
+ }),
3376
+ /* @__PURE__ */ c("ul", { children: e.map((e) => /* @__PURE__ */ l("li", { children: [
3377
+ h.changeBy(e.by, e.inserted, e.deleted),
3378
+ " ",
3379
+ /* @__PURE__ */ c("button", {
3380
+ type: "button",
3381
+ "aria-label": h.acceptLabel(e.by),
3382
+ onClick: () => d(lt(y, (t) => t.id === e.id ? "accept" : "keep")),
3383
+ children: h.accept
3384
+ }),
3385
+ " ",
3386
+ /* @__PURE__ */ c("button", {
3387
+ type: "button",
3388
+ "aria-label": h.rejectLabel(e.by),
3389
+ onClick: () => d(lt(y, (t) => t.id === e.id ? "reject" : "keep")),
3390
+ children: h.reject
3391
+ })
3392
+ ] }, e.id)) }),
3393
+ p?.(t.id, i) ?? null
3394
+ ]
3395
+ }, t.id);
3396
+ }
3397
+ return /* @__PURE__ */ l("fieldset", {
3398
+ "data-cms-rich-block": t.type,
3399
+ "data-cms-block-id": t.id,
3400
+ children: [
3401
+ /* @__PURE__ */ c("legend", { children: i }),
3402
+ t.type === "heading" ? /* @__PURE__ */ l(s, { children: [/* @__PURE__ */ c("label", {
3403
+ htmlFor: `${a}-level`,
3404
+ children: h.level
3405
+ }), /* @__PURE__ */ c("select", {
3406
+ id: `${a}-level`,
3407
+ value: t.level,
3408
+ onChange: (e) => w(r, {
3409
+ ...t,
3410
+ level: e.target.value === "3" ? 3 : 2
3411
+ }),
3412
+ children: (_?.headings ?? [2, 3]).map((e) => /* @__PURE__ */ c("option", {
3413
+ value: e,
3414
+ children: e
3415
+ }, e))
3416
+ })] }) : null,
3417
+ _?.styles !== void 0 && (t.type === "paragraph" || t.type === "heading" || t.type === "list") ? /* @__PURE__ */ l(s, { children: [/* @__PURE__ */ c("label", {
3418
+ htmlFor: `${a}-style`,
3419
+ children: h.style
3420
+ }), /* @__PURE__ */ l("select", {
3421
+ id: `${a}-style`,
3422
+ value: t.style ?? "",
3423
+ onChange: (e) => {
3424
+ let { style: n, ...i } = t;
3425
+ w(r, e.target.value === "" ? i : {
3426
+ ...i,
3427
+ style: e.target.value
3428
+ });
3429
+ },
3430
+ children: [/* @__PURE__ */ c("option", {
3431
+ value: "",
3432
+ children: h.noStyle
3433
+ }), Object.entries(_.styles.tokens).map(([e, t]) => /* @__PURE__ */ c("option", {
3434
+ value: e,
3435
+ children: `${e} — ${t}`
3436
+ }, e))]
3437
+ })] }) : null,
3438
+ t.type === "list" ? /* @__PURE__ */ l(s, { children: [/* @__PURE__ */ l("label", { children: [
3439
+ /* @__PURE__ */ c("input", {
3440
+ type: "checkbox",
3441
+ checked: t.ordered,
3442
+ onChange: (e) => w(r, {
3443
+ ...t,
3444
+ ordered: e.target.checked
3445
+ })
3446
+ }),
3447
+ " ",
3448
+ h.numbered
3449
+ ] }), Array.from({ length: Math.max(0, ...t.levels ?? []) }, (e, t) => t + 1).map((e) => /* @__PURE__ */ l("label", { children: [
3450
+ /* @__PURE__ */ c("input", {
3451
+ type: "checkbox",
3452
+ checked: D(t, e),
3453
+ onChange: (n) => w(r, {
3454
+ ...t,
3455
+ sublists: Array.from({ length: Math.max(e, t.sublists?.length ?? 0) }, (r, i) => i === e - 1 ? n.target.checked ? "ordered" : "unordered" : D(t, i + 1) ? "ordered" : "unordered")
3456
+ })
3457
+ }),
3458
+ " ",
3459
+ h.numberedAt(e + 1)
3460
+ ] }, e))] }) : null,
3461
+ t.type === "table" ? /* @__PURE__ */ l("label", { children: [
3462
+ /* @__PURE__ */ c("input", {
3463
+ type: "checkbox",
3464
+ checked: t.header,
3465
+ onChange: (e) => w(r, {
3466
+ ...t,
3467
+ header: e.target.checked
3468
+ })
3469
+ }),
3470
+ " ",
3471
+ h.headerRow
3472
+ ] }) : null,
3473
+ t.type === "component" ? /* @__PURE__ */ l(s, { children: [
3474
+ /* @__PURE__ */ c("label", {
3475
+ htmlFor: `${a}-component`,
3476
+ children: h.component
3477
+ }),
3478
+ /* @__PURE__ */ c("select", {
3479
+ id: `${a}-component`,
3480
+ value: t.componentId,
3481
+ onChange: (e) => w(r, {
3482
+ id: t.id,
3483
+ type: "component",
3484
+ componentId: e.target.value,
3485
+ props: {}
3486
+ }),
3487
+ children: (_?.components ?? []).map((e) => /* @__PURE__ */ c("option", {
3488
+ value: e.id,
3489
+ children: e.displayName
3490
+ }, e.id))
3491
+ }),
3492
+ ((e) => e === void 0 ? /* @__PURE__ */ c("p", { children: h.unknownComponent(t.componentId) }) : /* @__PURE__ */ c("div", {
3493
+ "data-cms-instance": t.id,
3494
+ "data-cms-component": t.componentId,
3495
+ children: m?.(e, t.props, (e) => w(r, {
3496
+ ...t,
3497
+ props: e
3498
+ }))
3499
+ }))(_?.components.find((e) => e.id === t.componentId))
3500
+ ] }) : t.type === "image" ? /* @__PURE__ */ l(s, { children: [
3501
+ /* @__PURE__ */ c("label", {
3502
+ htmlFor: `${a}-asset`,
3503
+ children: h.image
3504
+ }),
3505
+ f?.({
3506
+ id: `${a}-asset`,
3507
+ type: g.images ?? "",
3508
+ value: t.asset,
3509
+ onChange: (e) => w(r, {
3510
+ ...t,
3511
+ asset: e
3512
+ }),
3513
+ target: {
3514
+ field: n,
3515
+ blockId: t.id
3516
+ },
3517
+ role: "image"
3518
+ }),
3519
+ /* @__PURE__ */ c("label", {
3520
+ htmlFor: `${a}-caption`,
3521
+ children: h.caption
3522
+ }),
3523
+ /* @__PURE__ */ c("input", {
3524
+ id: `${a}-caption`,
3525
+ value: t.caption ?? "",
3526
+ onChange: (e) => w(r, e.target.value === "" ? {
3527
+ id: t.id,
3528
+ type: "image",
3529
+ asset: t.asset
3530
+ } : {
3531
+ ...t,
3532
+ caption: e.target.value
3533
+ })
3534
+ })
3535
+ ] }) : t.type === "file" ? /* @__PURE__ */ l(s, { children: [
3536
+ /* @__PURE__ */ c("label", {
3537
+ htmlFor: `${a}-asset`,
3538
+ children: h.file
3539
+ }),
3540
+ f?.({
3541
+ id: `${a}-asset`,
3542
+ type: g.files ?? "",
3543
+ value: t.asset,
3544
+ onChange: (e) => w(r, {
3545
+ ...t,
3546
+ asset: e
3547
+ }),
3548
+ target: {
3549
+ field: n,
3550
+ blockId: t.id
3551
+ },
3552
+ role: "file"
3553
+ }),
3554
+ /* @__PURE__ */ c("label", {
3555
+ htmlFor: `${a}-label`,
3556
+ children: h.fileLabel
3557
+ }),
3558
+ /* @__PURE__ */ c("input", {
3559
+ id: `${a}-label`,
3560
+ value: t.label,
3561
+ onChange: (e) => w(r, {
3562
+ ...t,
3563
+ label: e.target.value
3564
+ })
3565
+ })
3566
+ ] }) : e.surface === "visual" && (t.type === "paragraph" || t.type === "heading") ? /* @__PURE__ */ l(s, { children: [
3567
+ /* @__PURE__ */ c("span", {
3568
+ id: `${a}-label`,
3569
+ "data-cms-rich-label": !0,
3570
+ children: h.text
3571
+ }),
3572
+ /* @__PURE__ */ c(Cr, {
3573
+ id: `${a}-text`,
3574
+ labelledBy: `${a}-label`,
3575
+ content: t.content,
3576
+ onChange: (e) => w(r, {
3577
+ ...t,
3578
+ content: e
3579
+ }),
3580
+ words: {
3581
+ bold: h.bold,
3582
+ italic: h.italic,
3583
+ underline: h.underline
3584
+ }
3585
+ }),
3586
+ g.links !== void 0 && f !== void 0 && t.type === "paragraph" ? /* @__PURE__ */ c(Dr, {
3587
+ id: a,
3588
+ type: g.links,
3589
+ renderPicker: f,
3590
+ words: h,
3591
+ target: {
3592
+ field: n,
3593
+ blockId: t.id
3594
+ },
3595
+ onInsert: (e) => w(r, {
3596
+ ...t,
3597
+ content: P([
3598
+ ...t.content,
3599
+ ...F(t.content).match(/(^|\s)$/) ? [] : [{
3600
+ type: "text",
3601
+ text: " "
3602
+ }],
3603
+ e
3604
+ ])
3605
+ })
3606
+ }) : null,
3607
+ t.type === "paragraph" ? /* @__PURE__ */ c(Er, {
3608
+ id: a,
3609
+ options: g,
3610
+ renderPicker: f,
3611
+ words: h,
3612
+ onInsert: (e) => w(r, {
3613
+ ...t,
3614
+ content: P([
3615
+ ...t.content,
3616
+ ...F(t.content).match(/(^|\s)$/) ? [] : [{
3617
+ type: "text",
3618
+ text: " "
3619
+ }],
3620
+ e
3621
+ ])
3622
+ })
3623
+ }) : null
3624
+ ] }) : /* @__PURE__ */ l(s, { children: [
3625
+ /* @__PURE__ */ c("label", {
3626
+ htmlFor: `${a}-text`,
3627
+ children: t.type === "list" ? h.listItems : t.type === "table" ? h.tableRows : h.text
3628
+ }),
3629
+ /* @__PURE__ */ c("textarea", {
3630
+ id: `${a}-text`,
3631
+ value: o,
3632
+ onChange: (e) => E(r, t, e.target.value)
3633
+ }),
3634
+ g.links !== void 0 && f !== void 0 && (t.type === "paragraph" || t.type === "list") ? /* @__PURE__ */ c(Dr, {
3635
+ id: a,
3636
+ type: g.links,
3637
+ renderPicker: f,
3638
+ words: h,
3639
+ target: {
3640
+ field: n,
3641
+ blockId: t.id
3642
+ },
3643
+ onInsert: (e) => re(r, t, o, e)
3644
+ }) : null,
3645
+ t.type === "paragraph" || t.type === "list" ? /* @__PURE__ */ c(Er, {
3646
+ id: a,
3647
+ options: g,
3648
+ renderPicker: f,
3649
+ words: h,
3650
+ onInsert: (e) => re(r, t, o, e)
3651
+ }) : null
3652
+ ] }),
3653
+ /* @__PURE__ */ l("div", {
3654
+ "data-cms-rich-actions": !0,
3655
+ children: [
3656
+ /* @__PURE__ */ c("button", {
3657
+ type: "button",
3658
+ "aria-label": h.moveUpLabel(i),
3659
+ disabled: r === 0,
3660
+ onClick: () => T(r, r - 1),
3661
+ children: h.moveUp
3662
+ }),
3663
+ /* @__PURE__ */ c("button", {
3664
+ type: "button",
3665
+ "aria-label": h.moveDownLabel(i),
3666
+ disabled: r === y.blocks.length - 1,
3667
+ onClick: () => T(r, r + 1),
3668
+ children: h.moveDown
3669
+ }),
3670
+ /* @__PURE__ */ c("button", {
3671
+ type: "button",
3672
+ "aria-label": h.removeLabel(i),
3673
+ onClick: () => C(y.blocks.filter((e, t) => t !== r)),
3674
+ children: h.remove
3675
+ })
3676
+ ]
3677
+ }),
3678
+ p?.(t.id, i) ?? null
3679
+ ]
3680
+ }, t.id);
3681
+ });
3682
+ return /* @__PURE__ */ l("div", {
3683
+ id: t,
3684
+ "data-cms-rich-document": !0,
3685
+ children: [ie, /* @__PURE__ */ l("div", {
3686
+ "data-cms-rich-add": !0,
3687
+ children: [
3688
+ /* @__PURE__ */ c("label", {
3689
+ htmlFor: `${t}-add`,
3690
+ children: h.addBlock
3691
+ }),
3692
+ /* @__PURE__ */ c("select", {
3693
+ id: `${t}-add`,
3694
+ value: S.includes(x) ? x : S[0] ?? "paragraph",
3695
+ onChange: (e) => ne(e.target.value),
3696
+ children: S.map((e) => /* @__PURE__ */ c("option", {
3697
+ value: e,
3698
+ children: h.blockNames[e]
3699
+ }, e))
3700
+ }),
3701
+ /* @__PURE__ */ c("button", {
3702
+ type: "button",
3703
+ onClick: () => C([...y.blocks, Tr(S.includes(x) ? x : S[0] ?? "paragraph", g)]),
3704
+ children: h.add
3705
+ })
3706
+ ]
3707
+ })]
3708
+ });
3709
+ }, kr = ({ id: e, name: n, field: r, value: i, onChange: a }) => t("input", {
3710
+ type: "text",
3711
+ id: e,
3712
+ name: n,
3713
+ ...r.maxLength === void 0 ? {} : { maxLength: r.maxLength },
3714
+ value: i == null ? "" : String(i),
3715
+ onChange: (e) => a(e.target.value)
3716
+ }), Ar = ({ id: e, name: n, field: r, value: i, onChange: a }) => t("textarea", {
3717
+ id: e,
3718
+ name: n,
3719
+ ...r.maxLength === void 0 ? {} : { maxLength: r.maxLength },
3720
+ value: i == null ? "" : String(i),
3721
+ onChange: (e) => a(e.target.value)
3722
+ }), jr = ({ id: e, name: n, field: r, value: i, onChange: a }) => t("input", {
3723
+ type: "number",
3724
+ ...r.fraction === !0 ? { step: "any" } : {},
3725
+ id: e,
3726
+ name: n,
3727
+ value: i == null ? "" : String(i),
3728
+ onChange: (e) => a(e.target.value === "" ? null : Number(e.target.value))
3729
+ }), Mr = ({ id: e, name: n, value: r, onChange: i }) => t("input", {
3730
+ type: "checkbox",
3731
+ id: e,
3732
+ name: n,
3733
+ checked: r === !0,
3734
+ onChange: (e) => i(e.target.checked)
3735
+ }), Nr = (e) => ({ id: n, name: r, value: i, onChange: a }) => t("input", {
3736
+ type: e,
3737
+ id: n,
3738
+ name: r,
3739
+ value: i == null ? "" : String(i),
3740
+ onChange: (e) => a(e.target.value)
3741
+ }), Pr = ({ id: e, name: n, field: r, value: i, onChange: a }) => t("select", {
3742
+ id: e,
3743
+ name: n,
3744
+ value: i == null ? "" : String(i),
3745
+ onChange: (e) => a(e.target.value)
3746
+ }, [t("option", {
3747
+ key: "",
3748
+ value: ""
3749
+ }, ""), ...(r.literals ?? []).map((e) => t("option", {
3750
+ key: e,
3751
+ value: e
3752
+ }, r.literalLabels?.[e] ?? e))]), Fr = (e) => ({ id: n, name: r, value: i, onChange: a }) => t("textarea", {
3753
+ id: n,
3754
+ name: r,
3755
+ "data-cms-widget": e,
3756
+ value: i == null ? "" : typeof i == "string" ? i : JSON.stringify(i),
3757
+ onChange: (e) => a(e.target.value)
3758
+ }), Ir = (e) => {
3759
+ let { id: n, label: r, element: i, value: o, onChange: s, widgets: c, strings: l } = e, u = Bn(l), d = Array.isArray(o) ? o : [], f = a(d);
3760
+ f.current = d;
3761
+ let p = Br(i.editorHint, c), m = (e, t) => {
3762
+ if (t < 0 || t >= d.length) return;
3763
+ let n = [...d], [r] = n.splice(e, 1);
3764
+ n.splice(t, 0, r), s(n);
3765
+ }, h = i.kind === "number" ? 0 : i.kind !== "boolean" && "", g = d.map((e, a) => {
3766
+ let o = u.item(r, a + 1), c = `${n}-${a}`;
3767
+ return t("fieldset", {
3768
+ key: a,
3769
+ "data-cms-array-entry": a
3770
+ }, t("legend", null, t("label", { htmlFor: c }, o)), t(p, {
3771
+ id: c,
3772
+ name: `${n}[${a}]`,
3773
+ field: i,
3774
+ value: e,
3775
+ onChange: (e) => s(f.current.map((t, n) => n === a ? e : t))
3776
+ }), t("div", { "data-cms-array-actions": !0 }, t("button", {
3777
+ type: "button",
3778
+ "aria-label": u.moveUpLabel(o),
3779
+ disabled: a === 0,
3780
+ onClick: () => m(a, a - 1)
3781
+ }, u.moveUp), t("button", {
3782
+ type: "button",
3783
+ "aria-label": u.moveDownLabel(o),
3784
+ disabled: a === d.length - 1,
3785
+ onClick: () => m(a, a + 1)
3786
+ }, u.moveDown), t("button", {
3787
+ type: "button",
3788
+ "aria-label": u.removeLabel(o),
3789
+ onClick: () => s(d.filter((e, t) => t !== a))
3790
+ }, u.remove)));
3791
+ });
3792
+ return t("div", {
3793
+ id: n,
3794
+ "data-cms-array": !0
3795
+ }, g, t("button", {
3796
+ type: "button",
3797
+ "data-cms-array-add": !0,
3798
+ onClick: () => s([...f.current, h])
3799
+ }, u.addItem));
3800
+ }, Lr = (e) => Array.isArray(e) ? e.filter((e) => typeof e == "object" && !!e && typeof e.componentId == "string") : [], Rr = (e) => {
3801
+ let { id: n, definitions: r, value: i, onChange: s, widgets: c, renderPicker: l, fieldLabel: u, strings: d } = e, f = Bn(d), p = Lr(i), m = a(p);
3802
+ m.current = p;
3803
+ let [h, g] = o(r[0]?.id ?? ""), [_, v] = o(""), y = new Map(r.map((e) => [e.id, e])), b = (e) => s(e), ee = (e, t) => b(m.current.map((n, r) => r === e ? {
3804
+ ...n,
3805
+ props: t
3806
+ } : n)), te = (e, t) => {
3807
+ if (t < 0 || t >= p.length) return;
3808
+ let n = [...p], [r] = n.splice(e, 1);
3809
+ r !== void 0 && n.splice(t, 0, r), b(n);
3810
+ }, x = p.map((n, r) => {
3811
+ let i = y.get(n.componentId), a = `${i?.displayName ?? n.componentId} ${r + 1}`;
3812
+ return t("fieldset", {
3813
+ key: n.instanceId ?? `new-${r}`,
3814
+ "data-cms-component": n.componentId,
3815
+ ...n.instanceId === void 0 ? {} : { "data-cms-instance": n.instanceId }
3816
+ }, t("legend", null, a), i === void 0 ? t("p", null, f.unknownComponent(n.componentId)) : t(Vr, {
3817
+ contentType: { fields: i.props },
3818
+ value: n.props,
3819
+ onChange: (e) => ee(r, e),
3820
+ ...((t) => t === void 0 ? {} : { widgetTarget: (n) => ({
3821
+ field: e.field,
3822
+ instanceId: t,
3823
+ prop: n
3824
+ }) })(n.instanceId),
3825
+ ...c ? { widgets: c } : {},
3826
+ ...l ? { renderPicker: l } : {},
3827
+ ...u ? { fieldLabel: (e) => u(`${i.id}.${e}`) } : {},
3828
+ ...d ? { strings: d } : {}
3829
+ }), t("div", { "data-cms-component-actions": !0 }, t("button", {
3830
+ type: "button",
3831
+ "aria-label": f.moveUpLabel(a),
3832
+ disabled: r === 0,
3833
+ onClick: () => te(r, r - 1)
3834
+ }, f.moveUp), t("button", {
3835
+ type: "button",
3836
+ "aria-label": f.moveDownLabel(a),
3837
+ disabled: r === p.length - 1,
3838
+ onClick: () => te(r, r + 1)
3839
+ }, f.moveDown), t("button", {
3840
+ type: "button",
3841
+ "aria-label": f.removeLabel(a),
3842
+ onClick: () => b(p.filter((e, t) => t !== r))
3843
+ }, f.remove)));
3844
+ }), ne = `${n}-add`, S = _.trim().toLowerCase(), C = r.filter((e) => S === "" || [
3845
+ e.displayName,
3846
+ e.description ?? "",
3847
+ ...e.jobs ?? []
3848
+ ].some((e) => e.toLowerCase().includes(S))), w = /* @__PURE__ */ new Map();
3849
+ for (let e of C) {
3850
+ let t = e.jobs?.[0] ?? "";
3851
+ w.set(t, [...w.get(t) ?? [], e]);
3852
+ }
3853
+ let T = (e) => [t("option", {
3854
+ key: e.id,
3855
+ value: e.id,
3856
+ title: e.description
3857
+ }, e.displayName), ...Object.keys(e.variants ?? {}).map((n) => t("option", {
3858
+ key: `${e.id}::${n}`,
3859
+ value: `${e.id}::${n}`,
3860
+ title: e.description
3861
+ }, `${e.displayName} — ${n}`))], E = [...w].sort(([e], [t]) => e === "" ? 1 : t === "" ? -1 : e.localeCompare(t)), [re = ""] = h.split("::"), ie = C.some((e) => e.id === re) ? h : C[0]?.id ?? "", [D = "", ae] = ie.split("::"), oe = `${n}-find`;
3862
+ return t("div", {
3863
+ id: n,
3864
+ "data-cms-components": !0
3865
+ }, x, t("div", { "data-cms-component-add": !0 }, t("label", { htmlFor: oe }, f.findComponent), t("input", {
3866
+ id: oe,
3867
+ type: "search",
3868
+ value: _,
3869
+ onChange: (e) => v(e.target.value)
3870
+ }), t("label", { htmlFor: ne }, f.addComponent), C.length === 0 ? t("p", { role: "status" }, f.noComponentFound) : t("select", {
3871
+ id: ne,
3872
+ value: ie,
3873
+ onChange: (e) => g(e.target.value)
3874
+ }, w.size === 1 && E[0]?.[0] === "" ? C.flatMap(T) : E.map(([e, n]) => t("optgroup", {
3875
+ key: e || "~other",
3876
+ label: e || f.otherComponents
3877
+ }, n.flatMap(T)))), D !== "" && y.get(D)?.description !== void 0 ? t("p", { "data-cms-component-description": !0 }, y.get(D)?.description) : null, t("button", {
3878
+ type: "button",
3879
+ disabled: !y.has(D),
3880
+ onClick: () => b([...p, {
3881
+ instanceId: Ct(),
3882
+ componentId: D,
3883
+ props: { ...ae === void 0 ? {} : y.get(D)?.variants?.[ae] ?? {} }
3884
+ }])
3885
+ }, f.add)));
3886
+ }, zr = {
3887
+ text: kr,
3888
+ textarea: Ar,
3889
+ number: jr,
3890
+ boolean: Mr,
3891
+ date: Nr("date"),
3892
+ datetime: Nr("datetime-local"),
3893
+ select: Pr,
3894
+ richText: Or,
3895
+ media: Fr("media"),
3896
+ reference: Fr("reference"),
3897
+ array: Fr("array"),
3898
+ struct: Fr("struct"),
3899
+ components: Fr("components")
3900
+ }, Br = (e, t) => t?.[e] ?? zr[e], Vr = (e) => {
3901
+ let { contentType: n, value: i, onChange: o, widgets: s, fieldWidgets: c, renderPicker: l, renderFieldAside: u, renderBlockAside: d, fieldLabel: f, strings: p, richTextSurface: m, widgetTarget: h } = e, g = r(), _ = a(i);
3902
+ _.current = i;
3903
+ let v = (e, t) => o({
3904
+ ..._.current,
3905
+ [e]: t
3906
+ }), y = Object.entries(n.fields).map(([e, n]) => {
3907
+ let r = `${g}-${e}`, a = u?.(e) ?? null, o = f?.(e) ?? e, _ = c?.[e];
3908
+ return _ === void 0 && n.editorHint === "array" && s?.array === void 0 && n.element !== void 0 && n.element.kind !== "struct" && n.element.kind !== "array" ? t("div", {
3909
+ key: e,
3910
+ "data-cms-field": e,
3911
+ role: "group",
3912
+ "aria-labelledby": `${r}-label`
3913
+ }, t("span", {
3914
+ id: `${r}-label`,
3915
+ "data-cms-field-label": !0
3916
+ }, o), t(Ir, {
3917
+ id: r,
3918
+ label: o,
3919
+ element: n.element,
3920
+ value: i[e],
3921
+ onChange: (t) => v(e, t),
3922
+ widgets: s,
3923
+ strings: p
3924
+ }), a) : _ === void 0 && n.editorHint === "components" && s?.components === void 0 ? t("div", {
3925
+ key: e,
3926
+ "data-cms-field": e,
3927
+ role: "group",
3928
+ "aria-labelledby": `${r}-label`
3929
+ }, t("span", {
3930
+ id: `${r}-label`,
3931
+ "data-cms-field-label": !0
3932
+ }, o), t(Rr, {
3933
+ id: r,
3934
+ field: e,
3935
+ definitions: n.components ?? [],
3936
+ value: i[e],
3937
+ onChange: (t) => v(e, t),
3938
+ widgets: s,
3939
+ renderPicker: l,
3940
+ fieldLabel: f,
3941
+ strings: p
3942
+ }), a) : _ === void 0 && n.editorHint === "richText" && s?.richText === void 0 ? t("div", {
3943
+ key: e,
3944
+ "data-cms-field": e,
3945
+ role: "group",
3946
+ "aria-labelledby": `${r}-label`
3947
+ }, t("span", {
3948
+ id: `${r}-label`,
3949
+ "data-cms-field-label": !0
3950
+ }, o), t(Or, {
3951
+ id: r,
3952
+ name: e,
3953
+ field: n,
3954
+ value: i[e],
3955
+ onChange: (t) => v(e, t),
3956
+ ...l ? { renderPicker: l } : {},
3957
+ ...d ? { renderBlockAside: (t, n) => d(e, t, n) } : {},
3958
+ ...p ? { strings: p } : {},
3959
+ ...m ? { surface: m } : {},
3960
+ renderComponentProps: (e, n, r) => t(Vr, {
3961
+ contentType: { fields: e.props },
3962
+ value: { ...n },
3963
+ onChange: r,
3964
+ ...s ? { widgets: s } : {},
3965
+ ...l ? { renderPicker: l } : {},
3966
+ ...f ? { fieldLabel: (t) => f(`${e.id}.${t}`) } : {},
3967
+ ...p ? { strings: p } : {}
3968
+ })
3969
+ }), a) : t("div", {
3970
+ key: e,
3971
+ "data-cms-field": e,
3972
+ ...n.publishRequired === !0 ? { "data-cms-required-to-publish": !0 } : {}
3973
+ }, t("label", { htmlFor: r }, o), t(_ ?? Br(n.editorHint, s), {
3974
+ id: r,
3975
+ name: e,
3976
+ field: n,
3977
+ value: i[e],
3978
+ onChange: (t) => v(e, t),
3979
+ target: h?.(e) ?? { field: e }
3980
+ }), a);
3981
+ });
3982
+ return t("div", { "data-cms-form": !0 }, ...y);
3983
+ }, Hr = 100, Ur = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})$/, Wr = /^\d{4}-\d{2}-\d{2}$/, Z = 6e4, Gr = /* @__PURE__ */ new Map(), Kr = (e) => {
3984
+ let t = Gr.get(e);
3985
+ return t === void 0 && (t = new Intl.DateTimeFormat("en-US", {
3986
+ timeZone: e,
3987
+ hourCycle: "h23",
3988
+ year: "numeric",
3989
+ month: "2-digit",
3990
+ day: "2-digit",
3991
+ hour: "2-digit",
3992
+ minute: "2-digit",
3993
+ second: "2-digit"
3994
+ }), Gr.set(e, t)), t;
3995
+ }, qr = (e) => {
3996
+ try {
3997
+ return Kr(e), !0;
3998
+ } catch {
3999
+ return !1;
4000
+ }
4001
+ }, Jr = (e, t) => {
4002
+ let n = Kr(t).formatToParts(new Date(e)), r = (e) => Number(n.find((t) => t.type === e)?.value);
4003
+ return (Date.UTC(r("year"), r("month") - 1, r("day"), r("hour"), r("minute"), r("second")) - Math.floor(e / 1e3) * 1e3) / Z;
4004
+ }, Yr = (e, t) => {
4005
+ let n = Ur.exec(e);
4006
+ if (n === null) throw RangeError(`not a local wall time (YYYY-MM-DDTHH:mm): ${e}`);
4007
+ let r = Date.UTC(Number(n[1]), Number(n[2]) - 1, Number(n[3]), Number(n[4]), Number(n[5])), i = Jr(r - 720 * Z, t), a = Jr(r + 720 * Z, t), o = [.../* @__PURE__ */ new Set([i, a])].map((e) => r - e * Z).filter((e) => Jr(e, t) * Z === r - e).sort((e, t) => e - t);
4008
+ return o.length === 0 ? {
4009
+ instant: /* @__PURE__ */ new Date(r - i * Z),
4010
+ adjusted: "gap"
4011
+ } : o.length > 1 ? {
4012
+ instant: new Date(o[0]),
4013
+ adjusted: "fold"
4014
+ } : { instant: new Date(o[0]) };
4015
+ }, Q = (e) => String(e).padStart(2, "0"), Xr = (e, t) => new Date(Date.UTC(e, t, 0)).getUTCDate(), Zr = (e, t, n) => {
4016
+ let [r, i, a, o, s] = [
4017
+ 1,
4018
+ 2,
4019
+ 3,
4020
+ 4,
4021
+ 5
4022
+ ].map((t) => Number(e[t]));
4023
+ if (t === "month") {
4024
+ let e = i - 1 + n, t = r + Math.floor(e / 12), c = e % 12 + 1, l = Math.min(a, Xr(t, c));
4025
+ return {
4026
+ local: `${t}-${Q(c)}-${Q(l)}T${Q(o)}:${Q(s)}`,
4027
+ clamped: l !== a
4028
+ };
4029
+ }
4030
+ let c = new Date(Date.UTC(r, i - 1, a + n * (t === "week" ? 7 : 1)));
4031
+ return {
4032
+ local: `${c.getUTCFullYear()}-${Q(c.getUTCMonth() + 1)}-${Q(c.getUTCDate())}T${Q(o)}:${Q(s)}`,
4033
+ clamped: !1
4034
+ };
4035
+ }, Qr = (e, t) => t * (e === "day" ? 1440 : e === "week" ? 10080 : 40320), $r = (e) => {
4036
+ let t = [], n = e.interval ?? 1;
4037
+ Ur.test(e.start) || t.push("start must be a local wall time, YYYY-MM-DDTHH:mm"), qr(e.zone) || t.push(`unknown time zone '${e.zone}'`), (!Number.isInteger(e.count) || e.count < 1 || e.count > 100) && t.push("count must be between 1 and 100"), (!Number.isInteger(n) || n < 1 || n > 52) && t.push("interval must be between 1 and 52"), !Number.isInteger(e.durationMinutes) || e.durationMinutes < 1 ? t.push("an occurrence must last at least a minute") : e.durationMinutes >= Qr(e.every, n) && t.push("an occurrence must end before the next one starts");
4038
+ for (let n of e.except ?? []) Wr.test(n) || t.push(`not a local date (YYYY-MM-DD): ${n}`);
4039
+ return t;
4040
+ }, ei = (e) => {
4041
+ let t = $r(e);
4042
+ if (t.length > 0) throw RangeError(t.join("; "));
4043
+ let n = Ur.exec(e.start), r = e.interval ?? 1, i = new Set(e.except ?? []), a = [];
4044
+ for (let t = 0; t < e.count; t++) {
4045
+ let { local: o, clamped: s } = Zr(n, e.every, t * r);
4046
+ if (i.has(o.slice(0, 10))) continue;
4047
+ let { instant: c, adjusted: l } = Yr(o, e.zone), u = l ?? (s ? "clamped" : void 0);
4048
+ a.push({
4049
+ index: t,
4050
+ local: o,
4051
+ startsAt: c,
4052
+ endsAt: new Date(c.getTime() + e.durationMinutes * Z),
4053
+ ...u === void 0 ? {} : { adjusted: u }
4054
+ });
4055
+ }
4056
+ return a;
4057
+ }, ti = (e, t, n) => (Array.isArray(e) ? e : []).flatMap((e) => {
4058
+ let r = e;
4059
+ return typeof r == "object" && r && typeof r[t] == "string" ? [{
4060
+ id: r[t],
4061
+ name: String(r[n] ?? ""),
4062
+ raw: JSON.stringify(r)
4063
+ }] : [];
4064
+ }), ni = (e, t, n, r, i) => {
4065
+ let a = new Map(e.map((e, t) => [e.id, t])), o = new Map(t.map((e, t) => [e.id, t])), s = t.find((e) => !a.has(e.id));
4066
+ if (s !== void 0) return {
4067
+ label: i.add(r(s)),
4068
+ key: `add:${n}:${s.id}`
4069
+ };
4070
+ let c = e.find((e) => !o.has(e.id));
4071
+ if (c !== void 0) return {
4072
+ label: i.remove(r(c)),
4073
+ key: `remove:${n}:${c.id}`
4074
+ };
4075
+ let l = t.flatMap((t, n) => e[n]?.id === t.id ? [] : [n]);
4076
+ if (l.length === 2 && l[1] === l[0] + 1 && t[l[0]]?.id === e[l[1]]?.id) {
4077
+ let [t, a] = [e[l[0]], e[l[1]]];
4078
+ return {
4079
+ label: i.swap(r(t), r(a)),
4080
+ key: `move:${n}:${t.id}:${a.id}:${l[0]}`
4081
+ };
4082
+ }
4083
+ let u = t.find((e, t) => (a.get(e.id) ?? t) > t);
4084
+ if (u !== void 0) return {
4085
+ label: i.moveUp(r(u)),
4086
+ key: `move:${n}:${u.id}:${o.get(u.id)}`
4087
+ };
4088
+ let d = t.find((e, t) => (a.get(e.id) ?? t) < t);
4089
+ if (d !== void 0) return {
4090
+ label: i.moveDown(r(d)),
4091
+ key: `move:${n}:${d.id}:${o.get(d.id)}`
4092
+ };
4093
+ let f = t.find((t) => t.raw !== e[a.get(t.id) ?? -1]?.raw);
4094
+ return {
4095
+ label: i.edit(f === void 0 ? i.fieldLabel(n) : r(f)),
4096
+ key: `edit:${n}${f === void 0 ? "" : `:${f.id}`}`
4097
+ };
4098
+ }, ri = (e, t, n, r) => {
4099
+ let i = jt(e, t, n);
4100
+ if (i.length === 0) return null;
4101
+ if (i.length > 1) return {
4102
+ label: r.edit(i.map(r.fieldLabel).join(", ")),
4103
+ key: `edit:${i.join(",")}`
4104
+ };
4105
+ let a = i[0], o = e[a];
4106
+ if (o?.editorHint === "components") return ni(ti(t[a], "instanceId", "componentId"), ti(n[a], "instanceId", "componentId"), a, (e) => r.componentLabel(e.name), r);
4107
+ if (o?.editorHint === "richText") {
4108
+ let e = (e) => ti(e?.blocks, "id", "type"), i = ni(e(t[a]), e(n[a]), a, (e) => r.blockLabel(e.name), r);
4109
+ return i.key.startsWith("edit:") ? {
4110
+ label: i.label,
4111
+ key: `edit:${a}`
4112
+ } : i;
4113
+ }
4114
+ return {
4115
+ label: r.edit(r.fieldLabel(a)),
4116
+ key: `edit:${a}`
4117
+ };
4118
+ }, ii = {
4119
+ past: [],
4120
+ future: []
4121
+ }, ai = (e, t, n, r, i = {}) => {
4122
+ let a = e.past[e.past.length - 1];
4123
+ return a !== void 0 && a.key === n.key && r - a.at <= (i.mergeMs ?? 1500) ? {
4124
+ past: [...e.past.slice(0, -1), {
4125
+ ...a,
4126
+ label: n.label,
4127
+ at: r
4128
+ }],
4129
+ future: []
4130
+ } : {
4131
+ past: [...e.past, {
4132
+ values: t,
4133
+ label: n.label,
4134
+ key: n.key,
4135
+ at: r
4136
+ }].slice(-(i.limit ?? 100)),
4137
+ future: []
4138
+ };
4139
+ }, oi = (e, t) => {
4140
+ let n = e.past[e.past.length - 1];
4141
+ return n === void 0 ? null : {
4142
+ values: n.values,
4143
+ label: n.label,
4144
+ history: {
4145
+ past: e.past.slice(0, -1),
4146
+ future: [{
4147
+ ...n,
4148
+ values: t
4149
+ }, ...e.future]
4150
+ }
4151
+ };
4152
+ }, si = (e, t) => {
4153
+ let n = e.future[0];
4154
+ return n === void 0 ? null : {
4155
+ values: n.values,
4156
+ label: n.label,
4157
+ history: {
4158
+ past: [...e.past, {
4159
+ ...n,
4160
+ values: t
4161
+ }],
4162
+ future: e.future.slice(1)
4163
+ }
4164
+ };
4165
+ }, ci = "voltro.cms.visual/1", li = () => Array.from(globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16)), (e) => e.toString(16).padStart(2, "0")).join(""), ui = /^[A-Za-z_][A-Za-z0-9_]*(\.\d+)?$/, di = (e, t) => {
4166
+ if (e.origin !== t.origin) return null;
4167
+ let n = e.data;
4168
+ if (typeof n != "object" || !n) return null;
4169
+ let r = n;
4170
+ return r.protocol === "voltro.cms.visual/1" && typeof r.nonce == "string" && r.nonce === t.nonce ? r : null;
4171
+ }, fi = (e, t) => {
4172
+ let n = di(e, t);
4173
+ if (n === null) return null;
4174
+ let r = {
4175
+ protocol: ci,
4176
+ nonce: t.nonce
4177
+ };
4178
+ return n.kind === "ready" ? {
4179
+ ...r,
4180
+ kind: "ready"
4181
+ } : typeof n.path != "string" || !ui.test(n.path) ? null : n.kind === "select" ? {
4182
+ ...r,
4183
+ kind: "select",
4184
+ path: n.path
4185
+ } : n.kind === "move" && Number.isInteger(n.to) && n.to >= 0 ? {
4186
+ ...r,
4187
+ kind: "move",
4188
+ path: n.path,
4189
+ to: n.to
4190
+ } : null;
4191
+ }, pi = (e, t) => {
4192
+ let n = di(e, t);
4193
+ return n === null || n.kind !== "values" || typeof n.values != "object" || n.values === null || Array.isArray(n.values) ? null : {
4194
+ protocol: ci,
4195
+ nonce: t.nonce,
4196
+ kind: "values",
4197
+ values: n.values
4198
+ };
4199
+ }, mi = (e, t) => ({
4200
+ protocol: ci,
4201
+ nonce: e.nonce,
4202
+ ...t
4203
+ }), hi = (e) => ({ "data-cms-source": e }), gi = (e) => {
4204
+ let t = e;
4205
+ return (typeof t?.closest == "function" ? t.closest("[data-cms-source]") : null)?.getAttribute("data-cms-source") ?? null;
4206
+ }, _i = (e) => {
4207
+ let [t = "", n] = e.split(".");
4208
+ return n === void 0 ? { field: t } : {
4209
+ field: t,
4210
+ index: Number(n)
4211
+ };
4212
+ }, vi = (e, t, n) => {
4213
+ let r = Math.max(0, Math.min(e.length - 1, n));
4214
+ if (t < 0 || t >= e.length || t === r) return e;
4215
+ let i = [...e], [a] = i.splice(t, 1);
4216
+ return i.splice(r, 0, a), i;
4217
+ }, yi = (e, t) => {
4218
+ if (!ui.test(t)) return null;
4219
+ let { field: n, index: r } = _i(t), i = e.querySelector(`[data-cms-field="${n}"]`);
4220
+ return i === null || r === void 0 ? i : i.querySelectorAll("[data-cms-components] > [data-cms-component]")[r] ?? null;
4221
+ }, bi = [
4222
+ "dashboard",
4223
+ "sidebar",
4224
+ "fieldWidget",
4225
+ "entryTab",
4226
+ "releaseCheck",
4227
+ "assetAction",
4228
+ "settings"
4229
+ ], xi = (e, t) => {
4230
+ let n = new Map((e.settings ?? []).map((e) => [e.key, e])), r = [];
4231
+ for (let [i, a] of Object.entries(t)) {
4232
+ let t = n.get(i);
4233
+ if (t === void 0) {
4234
+ r.push(`"${i}" is not a setting of ${e.id}`);
4235
+ continue;
4236
+ }
4237
+ t.kind === "number" ? typeof a != "number" || !Number.isFinite(a) ? r.push(`"${i}" is a number`) : (t.min !== void 0 && a < t.min || t.max !== void 0 && a > t.max) && r.push(`"${i}" is between ${t.min ?? "…"} and ${t.max ?? "…"}`) : t.kind === "boolean" ? typeof a != "boolean" && r.push(`"${i}" is true or false`) : (typeof a != "string" || !t.options.includes(a)) && r.push(`"${i}" is one of ${t.options.join(", ")}`);
4238
+ }
4239
+ return r;
4240
+ }, Si = (e, t) => Object.fromEntries((e.settings ?? []).map((n) => {
4241
+ let r = t[n.key];
4242
+ return [n.key, xi(e, { [n.key]: r }).length === 0 && r !== void 0 ? r : n.default];
4243
+ })), Ci = /* @__PURE__ */ new Set(["content:read", "content:write"]), wi = /^(?=.{1,253}$)([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/, Ti = /^[A-Z][A-Z0-9_]{0,63}$/, Ei = /^[a-z][a-z0-9-]{0,62}$/, Di = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/, Oi = (e) => Ci.has(e) || e.startsWith("egress:") && wi.test(e.slice(7)) || e.startsWith("secret:") && Ti.test(e.slice(7)), ki = (e) => {
4244
+ let t = [];
4245
+ Ei.test(e.id) || t.push(`id "${e.id}": lowercase letters, digits and dashes, starting with a letter`), e.name.trim() === "" && t.push("name is empty"), e.publisher.trim() === "" && t.push("publisher is empty"), Di.test(e.version) || t.push(`version "${e.version}": major.minor.patch`);
4246
+ let n = /* @__PURE__ */ new Set();
4247
+ for (let r of e.capabilities) Oi(r) ? n.has(r) && t.push(`capability "${r}" is listed twice`) : t.push(`capability "${r}" is not one an extension can ask for`), n.add(r);
4248
+ for (let n of e.slots) bi.includes(n) || t.push(`slot "${n}" is not a place in the editor`);
4249
+ let r = e.slots.includes("fieldWidget");
4250
+ r && (e.fields ?? []).length === 0 && t.push("a field widget names the fields it shows beside"), !r && e.fields !== void 0 && t.push("fields belong to the fieldWidget slot");
4251
+ for (let n of e.fields ?? []) /^[A-Za-z][A-Za-z0-9]*$/.test(n) || t.push(`field "${n}" is not a field name`);
4252
+ let i = e.slots.includes("settings");
4253
+ i && (e.settings ?? []).length === 0 && t.push("the settings slot lists its settings"), !i && e.settings !== void 0 && t.push("settings belong to the settings slot");
4254
+ let a = /* @__PURE__ */ new Set();
4255
+ for (let n of e.settings ?? []) /^[A-Za-z][A-Za-z0-9]*$/.test(n.key) || t.push(`setting "${n.key}" is not a key`), a.has(n.key) && t.push(`setting "${n.key}" is listed twice`), a.add(n.key), xi({
4256
+ ...e,
4257
+ settings: [n]
4258
+ }, { [n.key]: n.default }).length > 0 && t.push(`setting "${n.key}": its default is not a value it allows`);
4259
+ return t;
4260
+ }, Ai = (e, t) => {
4261
+ let n = e.split(".").map(Number), r = t.split(".").map(Number);
4262
+ for (let e = 0; e < 3; e++) {
4263
+ let t = (n[e] ?? 0) - (r[e] ?? 0);
4264
+ if (t !== 0) return t;
4265
+ }
4266
+ return 0;
4267
+ }, ji = (e, t) => t.filter((t) => !e.includes(t)), Mi = class extends e.TaggedError()("ExtensionAccessDenied", {
4268
+ extensionId: e.String,
4269
+ capability: e.String
4270
+ }) {}, Ni = e.Struct({
4271
+ id: e.String,
4272
+ name: e.String,
4273
+ version: e.String,
4274
+ publisher: e.String,
4275
+ capabilities: e.Array(e.String),
4276
+ slots: e.Array(e.String),
4277
+ fields: e.optional(e.Array(e.String)),
4278
+ settings: e.optional(e.Array(e.Union([
4279
+ e.Struct({
4280
+ key: e.String,
4281
+ label: e.String,
4282
+ kind: e.Literal("number"),
4283
+ default: e.Number,
4284
+ min: e.optional(e.Number),
4285
+ max: e.optional(e.Number)
4286
+ }),
4287
+ e.Struct({
4288
+ key: e.String,
4289
+ label: e.String,
4290
+ kind: e.Literal("boolean"),
4291
+ default: e.Boolean
4292
+ }),
4293
+ e.Struct({
4294
+ key: e.String,
4295
+ label: e.String,
4296
+ kind: e.Literal("choice"),
4297
+ default: e.String,
4298
+ options: e.Array(e.String)
4299
+ })
4300
+ ])))
4301
+ }), Pi = /^[A-Za-z0-9_.:/-]{1,120}$/, $ = (e) => typeof e == "string" && Pi.test(e), Fi = (e) => Number.isInteger(e) && e >= 0 && e <= 1e6, Ii = (e) => typeof e == "number" && Number.isFinite(e) && e >= 0 && e <= 1, Li = (e) => {
4302
+ if (typeof e != "object" || !e) return null;
4303
+ let t = e;
4304
+ switch (t.kind) {
4305
+ case "view": return $(t.view) ? {
4306
+ kind: "view",
4307
+ view: t.view
4308
+ } : null;
4309
+ case "field": return $(t.field) ? {
4310
+ kind: "field",
4311
+ field: t.field
4312
+ } : null;
4313
+ case "component": return $(t.field) && $(t.instanceId) && $(t.componentId) ? {
4314
+ kind: "component",
4315
+ field: t.field,
4316
+ instanceId: t.instanceId,
4317
+ componentId: t.componentId
4318
+ } : null;
4319
+ case "slot": return $(t.field) && $(t.instanceId) && $(t.componentId) && $(t.prop) ? {
4320
+ kind: "slot",
4321
+ field: t.field,
4322
+ instanceId: t.instanceId,
4323
+ componentId: t.componentId,
4324
+ prop: t.prop
4325
+ } : null;
4326
+ case "selection": return $(t.field) && Fi(t.start) && Fi(t.end) && t.end >= t.start ? {
4327
+ kind: "selection",
4328
+ field: t.field,
4329
+ start: t.start,
4330
+ end: t.end
4331
+ } : null;
4332
+ case "assetRegion": return Ii(t.x) && Ii(t.y) && Ii(t.width) && Ii(t.height) && t.x + t.width <= 1 && t.y + t.height <= 1 ? {
4333
+ kind: "assetRegion",
4334
+ x: t.x,
4335
+ y: t.y,
4336
+ width: t.width,
4337
+ height: t.height
4338
+ } : null;
4339
+ default: return null;
4340
+ }
4341
+ }, Ri = (e) => {
4342
+ let t = e;
4343
+ if (typeof t != "object" || !t || typeof t.closest != "function") return null;
4344
+ let n = t.closest("[data-cms-field]"), r = t.closest("[data-cms-instance]");
4345
+ if (r != null) {
4346
+ let e = r.parentElement?.closest?.("[data-cms-field]") ?? null, t = e?.getAttribute("data-cms-field") ?? null, i = r.getAttribute("data-cms-instance"), a = r.getAttribute("data-cms-component"), o = n != null && n !== e ? n.getAttribute("data-cms-field") : null;
4347
+ if (t !== null && i !== null && a !== null) return Li(o === null ? {
4348
+ kind: "component",
4349
+ field: t,
4350
+ instanceId: i,
4351
+ componentId: a
4352
+ } : {
4353
+ kind: "slot",
4354
+ field: t,
4355
+ instanceId: i,
4356
+ componentId: a,
4357
+ prop: o
4358
+ });
4359
+ }
4360
+ let i = n?.getAttribute("data-cms-field") ?? null;
4361
+ return i === null ? null : Li({
4362
+ kind: "field",
4363
+ field: i
4364
+ });
4365
+ };
4366
+ //#endregion
4367
+ export { Rn as $, je as $t, $r as A, v as An, At, or as B, ut as Bt, ri as C, _e as Cn, Bt as Ct, Hr as D, E as Dn, Mt as Dt, oi as E, C as En, Lt as Et, Cr as F, d as Fn, gt as Ft, Yn as G, R as Gt, cr as H, it as Ht, X as I, f as In, xt as It, zn as J, P as Jt, Kn as K, Je as Kt, vr as L, ne as Ln, _t as Lt, Vr as M, y as Mn, vt as Mt, Br as N, b as Nn, St as Nt, qr as O, w as On, W as Ot, Or as P, te as Pn, ht as Pt, kn as Q, Ne as Qt, pr as R, p as Rn, z as Rt, ii as S, ge as Sn, zt as St, si as T, re as Tn, Ft as Tt, Qn as U, et as Ut, lr as V, lt as Vt, Xn as W, Ge as Wt, G as X, Ke as Xt, Bn as Y, qe as Yt, On as Z, Me as Zt, pi as _, D as _n, Ht as _t, Ni as a, Le as an, un as at, gi as b, ye as bn, Wt as bt, ki as c, Ee as cn, hn as ct, Si as d, ie as dn, rn as dt, Ae as en, An as et, ci as f, xe as fn, on as ft, _i as g, A as gn, $t as gt, li as h, ce as hn, qt as ht, Mi as i, Fe as in, vn as it, Yr as j, ee as jn, kt as jt, ei as k, h as kn, Dt as kt, ji as l, Oe as ln, pn as lt, vi as m, de as mn, tn as mt, Ri as n, Be as nn, Cn as nt, Ai as o, Re as on, fn as ot, yi as p, fe as pn, cn as pt, Vn as q, F as qt, bi as r, ze as rn, Dn as rt, Oi as s, Pe as sn, dn as st, Li as t, Ie as tn, En as tt, xi as u, De as un, gn as ut, fi as v, se as vn, Gt as vt, ai as w, we as wn, jt as wt, mi as x, Te as xn, Vt as xt, hi as y, k as yn, Ut as yt, sr as z, Qe as zt };