@relyio/sdk 0.11.0 → 0.13.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +172 -0
  2. package/dist/chunk-3NPPMGB6.js +1092 -0
  3. package/dist/{chunk-7GLDVHIH.js → chunk-6NGJXLOR.js} +65 -67
  4. package/dist/{chunk-4HTIU5YE.cjs → chunk-DEDIJKHY.cjs} +65 -67
  5. package/dist/{chunk-2TIJLV2X.js → chunk-EW23SZPX.js} +43 -65
  6. package/dist/{chunk-PO7CUR5U.cjs → chunk-FOSM4LMM.cjs} +42 -65
  7. package/dist/chunk-Z6GLWSSD.cjs +1106 -0
  8. package/dist/client/index.cjs +3 -3
  9. package/dist/client/index.d.cts +4 -4
  10. package/dist/client/index.d.ts +4 -4
  11. package/dist/client/index.js +1 -1
  12. package/dist/{define-schema-CVi8nwc7.d.ts → define-schema-UHViXKiv.d.ts} +33 -435
  13. package/dist/{define-schema-DqpipEHv.d.cts → define-schema-sWJ8Zn7C.d.cts} +33 -435
  14. package/dist/{define-content-type-ENAod5Ve.d.cts → include-paths-Bs5FhNw2.d.cts} +3505 -483
  15. package/dist/{define-content-type-ENAod5Ve.d.ts → include-paths-Cb7iPCW2.d.ts} +3505 -483
  16. package/dist/index--_u1nPHv.d.cts +507 -0
  17. package/dist/index-8DozAWsA.d.ts +507 -0
  18. package/dist/{index-MLAFUuco.d.cts → index-BT0L8xJj.d.cts} +139 -90
  19. package/dist/{index-BKEAYvvz.d.ts → index-CPjJ25R4.d.ts} +139 -90
  20. package/dist/index.cjs +134 -110
  21. package/dist/index.d.cts +44 -71
  22. package/dist/index.d.ts +44 -71
  23. package/dist/index.js +5 -28
  24. package/dist/markdown/index.cjs +13750 -0
  25. package/dist/markdown/index.d.cts +111 -0
  26. package/dist/markdown/index.d.ts +111 -0
  27. package/dist/markdown/index.js +13742 -0
  28. package/dist/rich-text/index.cjs +49 -0
  29. package/dist/rich-text/index.d.cts +3 -0
  30. package/dist/rich-text/index.d.ts +3 -0
  31. package/dist/rich-text/index.js +4 -0
  32. package/dist/rich-text.d-BWc-5gX1.d.cts +326 -0
  33. package/dist/rich-text.d-BWc-5gX1.d.ts +326 -0
  34. package/dist/schema/index.cjs +34 -38
  35. package/dist/schema/index.d.cts +15 -137
  36. package/dist/schema/index.d.ts +15 -137
  37. package/dist/schema/index.js +1 -1
  38. package/dist/types/index.d.cts +2 -2
  39. package/dist/types/index.d.ts +2 -2
  40. package/package.json +19 -2
  41. package/dist/.tsbuildinfo +0 -1
  42. package/dist/index-BM42r4yg.d.cts +0 -860
  43. package/dist/index-C73cK2Tt.d.ts +0 -860
@@ -0,0 +1,1092 @@
1
+ import { __name } from './chunk-XQ4QHWZE.js';
2
+
3
+ /* RelyIO SDK - Built with ❤️ by the RelyIO Team */
4
+
5
+ // src/rich-text/anchors.ts
6
+ function richTextHeadingSlug(text) {
7
+ return text.trim().toLowerCase().replace(/[^\p{L}\p{M}\p{N}\s_-]/gu, "").replace(/\s/gu, "-");
8
+ }
9
+ __name(richTextHeadingSlug, "richTextHeadingSlug");
10
+ function isRecord(value) {
11
+ return typeof value === "object" && value !== null && !Array.isArray(value);
12
+ }
13
+ __name(isRecord, "isRecord");
14
+ var BUILT_IN_CONTAINERS = /* @__PURE__ */ new Set([
15
+ "paragraph",
16
+ "heading",
17
+ "quote",
18
+ "list",
19
+ "listItem",
20
+ "codeGroup",
21
+ "table",
22
+ "tableRow",
23
+ "tableCell"
24
+ ]);
25
+ function headingText(heading) {
26
+ if (!Array.isArray(heading.children)) return "";
27
+ let text = "";
28
+ for (const child of heading.children) {
29
+ if (!isRecord(child)) continue;
30
+ if (child._type === "lineBreak") text += " ";
31
+ else if (child._type === "text" && typeof child.text === "string") text += child.text;
32
+ }
33
+ return text;
34
+ }
35
+ __name(headingText, "headingText");
36
+ function richTextHeadingAnchors(value) {
37
+ return anchorsAcross([value]);
38
+ }
39
+ __name(richTextHeadingAnchors, "richTextHeadingAnchors");
40
+ function entryHeadingAnchors(entry) {
41
+ return anchorsAcross(isRecord(entry) ? Object.values(entry) : []);
42
+ }
43
+ __name(entryHeadingAnchors, "entryHeadingAnchors");
44
+ function anchorsAcross(values) {
45
+ const anchors = /* @__PURE__ */ new Map();
46
+ const taken = /* @__PURE__ */ new Map();
47
+ const unique = /* @__PURE__ */ __name((slug) => {
48
+ let anchor = slug;
49
+ const seen = taken.get(slug);
50
+ if (seen !== void 0) {
51
+ let count = seen;
52
+ do {
53
+ count += 1;
54
+ anchor = `${slug}-${count}`;
55
+ } while (taken.has(anchor));
56
+ taken.set(slug, count);
57
+ }
58
+ taken.set(anchor, 0);
59
+ return anchor;
60
+ }, "unique");
61
+ const visit = /* @__PURE__ */ __name((nodes) => {
62
+ for (const node of nodes) {
63
+ if (!isRecord(node) || typeof node._type !== "string") continue;
64
+ if (node._type === "heading") {
65
+ const slug = richTextHeadingSlug(headingText(node));
66
+ if (slug !== "") anchors.set(node, unique(slug));
67
+ continue;
68
+ }
69
+ if (BUILT_IN_CONTAINERS.has(node._type) && Array.isArray(node.children)) visit(node.children);
70
+ }
71
+ }, "visit");
72
+ for (const value of values) {
73
+ if (isRecord(value) && value._type === "richText" && Array.isArray(value.children)) {
74
+ visit(value.children);
75
+ }
76
+ }
77
+ return anchors;
78
+ }
79
+ __name(anchorsAcross, "anchorsAcross");
80
+
81
+ // src/binding/key-path.ts
82
+ var ITEM_SELECTOR = "[_key==";
83
+ function formatKeyPath(listPath, key, field) {
84
+ const item = `${listPath}${ITEM_SELECTOR}${JSON.stringify(key)}]`;
85
+ return field === void 0 ? item : `${item}.${field}`;
86
+ }
87
+ __name(formatKeyPath, "formatKeyPath");
88
+ function parseKeyPath(path) {
89
+ const segments = [];
90
+ let at = 0;
91
+ let expectField = true;
92
+ while (at < path.length) {
93
+ if (path.startsWith(ITEM_SELECTOR, at)) {
94
+ const previous = segments[segments.length - 1];
95
+ if (expectField || previous === void 0 || !("field" in previous)) return null;
96
+ const quoted = readQuoted(path, at + ITEM_SELECTOR.length);
97
+ if (quoted === null || path[quoted.end] !== "]") return null;
98
+ segments.push({ key: quoted.value });
99
+ at = quoted.end + 1;
100
+ if (at < path.length && path[at] !== "." && !path.startsWith(ITEM_SELECTOR, at)) return null;
101
+ if (path[at] === ".") {
102
+ at += 1;
103
+ expectField = true;
104
+ }
105
+ continue;
106
+ }
107
+ let end = at;
108
+ while (end < path.length && path[end] !== "." && path[end] !== "[") end += 1;
109
+ const field = path.slice(at, end);
110
+ if (field.length === 0) return null;
111
+ segments.push({ field });
112
+ expectField = false;
113
+ at = end;
114
+ if (path[at] === ".") {
115
+ at += 1;
116
+ expectField = true;
117
+ if (at === path.length) return null;
118
+ } else if (at < path.length && !path.startsWith(ITEM_SELECTOR, at)) {
119
+ return null;
120
+ }
121
+ }
122
+ return segments.length === 0 || expectField ? null : segments;
123
+ }
124
+ __name(parseKeyPath, "parseKeyPath");
125
+ function readQuoted(path, start) {
126
+ if (path[start] !== '"') return null;
127
+ for (let end = start + 1; end < path.length; end += 1) {
128
+ if (path[end] === "\\") {
129
+ end += 1;
130
+ continue;
131
+ }
132
+ if (path[end] !== '"') continue;
133
+ try {
134
+ const value = JSON.parse(path.slice(start, end + 1));
135
+ return typeof value === "string" && value.length > 0 ? { value, end: end + 1 } : null;
136
+ } catch {
137
+ return null;
138
+ }
139
+ }
140
+ return null;
141
+ }
142
+ __name(readQuoted, "readQuoted");
143
+
144
+ // src/binding/relyio-field.ts
145
+ var BINDING_VERSION = "1";
146
+ function relyioField(subject, path) {
147
+ if (subject === void 0) return void 0;
148
+ if (isBindingShaped(subject)) return continued(subject, path);
149
+ const field = typeof path === "string" ? path : String(path);
150
+ const metadata = subject._metadata;
151
+ const attributes = {
152
+ "data-relyio-entry": requireMetadata(metadata, "id", field),
153
+ "data-relyio-type": requireMetadata(metadata, "type", field),
154
+ "data-relyio-field": field,
155
+ "data-relyio-locale": requireMetadata(metadata, "locale", field),
156
+ "data-relyio-v": BINDING_VERSION
157
+ };
158
+ requireKeyPath("entry", field, field);
159
+ return attributes;
160
+ }
161
+ __name(relyioField, "relyioField");
162
+ function isBindingShaped(value) {
163
+ return "data-relyio-field" in value;
164
+ }
165
+ __name(isBindingShaped, "isBindingShaped");
166
+ function continued(binding, path) {
167
+ const spelled = typeof path === "string" ? path : `{ _key: ${JSON.stringify(path._key)} }`;
168
+ const complete = binding["data-relyio-v"] === BINDING_VERSION && [
169
+ binding["data-relyio-entry"],
170
+ binding["data-relyio-type"],
171
+ binding["data-relyio-field"],
172
+ binding["data-relyio-locale"]
173
+ ].every((value) => typeof value === "string" && value.length > 0);
174
+ if (!complete) {
175
+ throw new TypeError(
176
+ `relyioField(binding, '${spelled}'): the binding is not one relyioField returned \u2014 continue the attributes relyioField(entry, field) gave, or a renderer handed you.`
177
+ );
178
+ }
179
+ const field = typeof path === "string" ? `${binding["data-relyio-field"]}.${path}` : formatKeyPath(binding["data-relyio-field"], path._key);
180
+ requireKeyPath("binding", spelled, field);
181
+ return {
182
+ "data-relyio-entry": binding["data-relyio-entry"],
183
+ "data-relyio-type": binding["data-relyio-type"],
184
+ "data-relyio-field": field,
185
+ "data-relyio-locale": binding["data-relyio-locale"],
186
+ "data-relyio-v": BINDING_VERSION
187
+ };
188
+ }
189
+ __name(continued, "continued");
190
+ function requireKeyPath(form, given, field) {
191
+ if (parseKeyPath(field) !== null) return;
192
+ throw new TypeError(
193
+ `relyioField(${form}, '${given}'): '${field}' is not a field or a key path. Name a field (\`title\`), or a value inside one by its items\u2019 keys (\`sections[_key=="k1"].heading\`).`
194
+ );
195
+ }
196
+ __name(requireKeyPath, "requireKeyPath");
197
+ function requireMetadata(metadata, key, field) {
198
+ const value = metadata?.[key];
199
+ if (typeof value !== "string" || value.length === 0) {
200
+ throw new TypeError(
201
+ `relyioField(entry, '${field}'): the entry has no _metadata.${key}, so the field cannot be bound. Pass an entry as the RelyIO API returned it.`
202
+ );
203
+ }
204
+ return value;
205
+ }
206
+ __name(requireMetadata, "requireMetadata");
207
+
208
+ // src/rich-text/render.ts
209
+ var RICH_TEXT_VOID_TAGS = /* @__PURE__ */ new Set([
210
+ "hr",
211
+ "br",
212
+ "input"
213
+ ]);
214
+ var BUILT_IN_NODES = {
215
+ paragraph: true,
216
+ heading: true,
217
+ quote: true,
218
+ list: true,
219
+ listItem: true,
220
+ codeBlock: true,
221
+ codeGroup: true,
222
+ table: true,
223
+ tableRow: true,
224
+ tableCell: true,
225
+ divider: true,
226
+ text: true,
227
+ lineBreak: true
228
+ };
229
+ function isDeclaredRichTextNode(node) {
230
+ if (typeof node !== "object" || node === null) return false;
231
+ const type = node._type;
232
+ return typeof type === "string" && type !== "" && !Object.prototype.hasOwnProperty.call(BUILT_IN_NODES, type);
233
+ }
234
+ __name(isDeclaredRichTextNode, "isDeclaredRichTextNode");
235
+ var PLAIN = Object.freeze({ header: false });
236
+ var HEADER = Object.freeze({ header: true });
237
+ var headingAnchors = /* @__PURE__ */ new Map();
238
+ function renderRichText(value, target, options = {}) {
239
+ const held = value;
240
+ if (held._type !== "richText") {
241
+ const drawn = block(held, target);
242
+ return drawn === void 0 ? [] : [drawn];
243
+ }
244
+ const outer = headingAnchors;
245
+ headingAnchors = options.anchors ?? richTextHeadingAnchors(held);
246
+ try {
247
+ return Array.isArray(held.children) ? blocks(held.children, target) : [];
248
+ } finally {
249
+ headingAnchors = outer;
250
+ }
251
+ }
252
+ __name(renderRichText, "renderRichText");
253
+ function blocks(nodes, target) {
254
+ const out = [];
255
+ for (const node of nodes) {
256
+ const drawn = block(node, target);
257
+ if (drawn !== void 0) out.push(drawn);
258
+ }
259
+ return out;
260
+ }
261
+ __name(blocks, "blocks");
262
+ var HEADING_TAGS = {
263
+ 1: "h1",
264
+ 2: "h2",
265
+ 3: "h3",
266
+ 4: "h4",
267
+ 5: "h5",
268
+ 6: "h6"
269
+ };
270
+ function block(node, target) {
271
+ if (isDeclaredRichTextNode(node)) {
272
+ return target.declared(node, "block");
273
+ }
274
+ switch (node._type) {
275
+ case "paragraph": {
276
+ return target.node(
277
+ node,
278
+ inline(node.children, target),
279
+ (contents) => target.element("p", void 0, contents, node._key),
280
+ PLAIN
281
+ );
282
+ }
283
+ case "heading": {
284
+ const tag = HEADING_TAGS[node.level] ?? "p";
285
+ const anchor = headingAnchors.get(node);
286
+ return target.node(
287
+ node,
288
+ inline(node.children, target),
289
+ (contents) => target.element(
290
+ tag,
291
+ anchor === void 0 ? void 0 : { id: anchor },
292
+ contents,
293
+ node._key
294
+ ),
295
+ PLAIN
296
+ );
297
+ }
298
+ case "quote": {
299
+ return target.node(
300
+ node,
301
+ blocks(node.children, target),
302
+ (contents) => target.element("blockquote", void 0, contents, node._key),
303
+ PLAIN
304
+ );
305
+ }
306
+ case "list": {
307
+ return list(node, target);
308
+ }
309
+ case "codeBlock": {
310
+ return code(node, target);
311
+ }
312
+ case "codeGroup": {
313
+ const tabs = [];
314
+ for (const tab of node.children) {
315
+ if (tab._type === "codeBlock") tabs.push(code(tab, target));
316
+ }
317
+ return target.node(
318
+ node,
319
+ tabs,
320
+ (contents) => target.element("div", void 0, contents, node._key),
321
+ PLAIN
322
+ );
323
+ }
324
+ case "table": {
325
+ return table(node, target);
326
+ }
327
+ case "divider": {
328
+ return target.node(node, [], () => target.element("hr", void 0, [], node._key), PLAIN);
329
+ }
330
+ default: {
331
+ return void 0;
332
+ }
333
+ }
334
+ }
335
+ __name(block, "block");
336
+ function list(node, target) {
337
+ let tag;
338
+ switch (node.style) {
339
+ case "bullet":
340
+ case "task": {
341
+ tag = "ul";
342
+ break;
343
+ }
344
+ case "numbered": {
345
+ tag = "ol";
346
+ break;
347
+ }
348
+ default: {
349
+ node.style;
350
+ tag = "ul";
351
+ }
352
+ }
353
+ const start = node.style === "numbered" && Number.isSafeInteger(node.start) && node.start !== 1 ? node.start : void 0;
354
+ const items = [];
355
+ for (const item of node.children) {
356
+ if (item._type === "listItem") items.push(listItem(item, node.style === "task", target));
357
+ }
358
+ return target.node(
359
+ node,
360
+ items,
361
+ (contents) => target.element(tag, start === void 0 ? void 0 : { start }, contents, node._key),
362
+ PLAIN
363
+ );
364
+ }
365
+ __name(list, "list");
366
+ function listItem(item, task, target) {
367
+ return target.node(
368
+ item,
369
+ blocks(item.children, target),
370
+ (contents) => {
371
+ if (!task) return target.element("li", void 0, contents, item._key);
372
+ const box = target.element(
373
+ "input",
374
+ item.checked === true ? { type: "checkbox", disabled: true, checked: true } : { type: "checkbox", disabled: true },
375
+ [],
376
+ void 0
377
+ );
378
+ return target.element("li", void 0, [box, ...contents], item._key);
379
+ },
380
+ PLAIN
381
+ );
382
+ }
383
+ __name(listItem, "listItem");
384
+ function code(node, target) {
385
+ const language = typeof node.language === "string" && node.language !== "" ? node.language : void 0;
386
+ const caption = nonEmpty(node.filename) ?? nonEmpty(node.label);
387
+ return target.node(
388
+ node,
389
+ [target.text(node.text)],
390
+ (contents) => {
391
+ const pre = /* @__PURE__ */ __name((key) => target.element(
392
+ "pre",
393
+ void 0,
394
+ [
395
+ target.element(
396
+ "code",
397
+ language === void 0 ? void 0 : { class: `language-${language}` },
398
+ contents,
399
+ void 0
400
+ )
401
+ ],
402
+ key
403
+ ), "pre");
404
+ if (caption === void 0) return pre(node._key);
405
+ return target.element(
406
+ "figure",
407
+ void 0,
408
+ [
409
+ target.element("figcaption", void 0, [target.text(caption)], void 0),
410
+ pre(void 0)
411
+ ],
412
+ node._key
413
+ );
414
+ },
415
+ PLAIN
416
+ );
417
+ }
418
+ __name(code, "code");
419
+ function nonEmpty(value) {
420
+ return typeof value === "string" && value !== "" ? value : void 0;
421
+ }
422
+ __name(nonEmpty, "nonEmpty");
423
+ function table(node, target) {
424
+ const rows = node.children.filter((row) => row._type === "tableRow");
425
+ const [first, ...rest] = rows;
426
+ const header = node.headerRow === true ? first : void 0;
427
+ const body = header === void 0 ? rows : rest;
428
+ const sections = [];
429
+ if (header !== void 0) {
430
+ sections.push(target.element("thead", void 0, [tableRow(header, true, target)], void 0));
431
+ }
432
+ if (body.length > 0) {
433
+ sections.push(
434
+ target.element(
435
+ "tbody",
436
+ void 0,
437
+ body.map((row) => tableRow(row, false, target)),
438
+ void 0
439
+ )
440
+ );
441
+ }
442
+ return target.node(
443
+ node,
444
+ sections,
445
+ (contents) => target.element("table", void 0, contents, node._key),
446
+ PLAIN
447
+ );
448
+ }
449
+ __name(table, "table");
450
+ function tableRow(row, header, target) {
451
+ const cells = [];
452
+ for (const cell of row.children) {
453
+ if (cell._type === "tableCell") cells.push(tableCell(cell, header, target));
454
+ }
455
+ return target.node(
456
+ row,
457
+ cells,
458
+ (contents) => target.element("tr", void 0, contents, row._key),
459
+ header ? HEADER : PLAIN
460
+ );
461
+ }
462
+ __name(tableRow, "tableRow");
463
+ function tableCell(cell, header, target) {
464
+ let attributes;
465
+ switch (cell.align) {
466
+ case "left":
467
+ case "center":
468
+ case "right": {
469
+ attributes = { style: `text-align:${cell.align}` };
470
+ break;
471
+ }
472
+ case void 0: {
473
+ attributes = void 0;
474
+ break;
475
+ }
476
+ default: {
477
+ cell.align;
478
+ attributes = void 0;
479
+ }
480
+ }
481
+ return target.node(
482
+ cell,
483
+ blocks(cell.children, target),
484
+ (contents) => target.element(header ? "th" : "td", attributes, contents, cell._key),
485
+ header ? HEADER : PLAIN
486
+ );
487
+ }
488
+ __name(tableCell, "tableCell");
489
+ function inline(nodes, target) {
490
+ const out = [];
491
+ let runs = [];
492
+ const flush = /* @__PURE__ */ __name(() => {
493
+ if (runs.length > 0) out.push(...marked(runs, target));
494
+ runs = [];
495
+ }, "flush");
496
+ for (const node of nodes) {
497
+ if (isDeclaredRichTextNode(node)) {
498
+ flush();
499
+ const drawn = target.declared(node, "inline");
500
+ if (drawn !== void 0) out.push(drawn);
501
+ continue;
502
+ }
503
+ switch (node._type) {
504
+ case "text": {
505
+ runs.push({ span: node, drawn: 0 });
506
+ break;
507
+ }
508
+ case "lineBreak": {
509
+ flush();
510
+ out.push(target.node(node, [], () => target.element("br", void 0, [], node._key), PLAIN));
511
+ break;
512
+ }
513
+ default: {
514
+ flush();
515
+ }
516
+ }
517
+ }
518
+ flush();
519
+ return out;
520
+ }
521
+ __name(inline, "inline");
522
+ function marked(runs, target) {
523
+ const out = [];
524
+ let index = 0;
525
+ while (index < runs.length) {
526
+ const run = runs[index];
527
+ const mark = run.span.marks?.[run.drawn];
528
+ if (mark === void 0) {
529
+ out.push(target.text(run.span.text));
530
+ index += 1;
531
+ continue;
532
+ }
533
+ let end = index + 1;
534
+ while (end < runs.length && sameMark(nextMark(runs[end]), mark)) end += 1;
535
+ const inner = marked(
536
+ runs.slice(index, end).map((each) => ({ span: each.span, drawn: each.drawn + 1 })),
537
+ target
538
+ );
539
+ out.push(...applyMark(mark, inner, target));
540
+ index = end;
541
+ }
542
+ return out;
543
+ }
544
+ __name(marked, "marked");
545
+ function nextMark(run) {
546
+ return run.span.marks?.[run.drawn];
547
+ }
548
+ __name(nextMark, "nextMark");
549
+ function sameMark(a, b) {
550
+ if (a?._type !== b._type) return false;
551
+ if (a._type === "link" && b._type === "link") return a.href === b.href;
552
+ if (a._type === "entryLink" && b._type === "entryLink") {
553
+ return linkedEntryId(a) === linkedEntryId(b) && a.anchor === b.anchor;
554
+ }
555
+ return true;
556
+ }
557
+ __name(sameMark, "sameMark");
558
+ function linkedEntryId(link) {
559
+ const to = link.to;
560
+ if (typeof to === "object" && to !== null && "_metadata" in to) {
561
+ const metadata = to._metadata;
562
+ return metadata?.id ?? to;
563
+ }
564
+ return to;
565
+ }
566
+ __name(linkedEntryId, "linkedEntryId");
567
+ var MARK_TAGS = {
568
+ bold: "strong",
569
+ italic: "em",
570
+ underline: "u",
571
+ strike: "s",
572
+ code: "code",
573
+ highlight: "mark",
574
+ subscript: "sub",
575
+ superscript: "sup"
576
+ };
577
+ function applyMark(mark, inner, target) {
578
+ switch (mark._type) {
579
+ case "entryLink": {
580
+ return [target.entryLink(mark, inner)];
581
+ }
582
+ case "link": {
583
+ const href = safeRichTextHref(mark.href);
584
+ if (href === void 0) return inner;
585
+ return [
586
+ target.mark(mark, inner, (contents) => target.element("a", { href }, contents, void 0))
587
+ ];
588
+ }
589
+ case "bold":
590
+ case "italic":
591
+ case "underline":
592
+ case "strike":
593
+ case "code":
594
+ case "highlight":
595
+ case "subscript":
596
+ case "superscript": {
597
+ const tag = MARK_TAGS[mark._type];
598
+ return [
599
+ target.mark(mark, inner, (contents) => target.element(tag, void 0, contents, void 0))
600
+ ];
601
+ }
602
+ default: {
603
+ return inner;
604
+ }
605
+ }
606
+ }
607
+ __name(applyMark, "applyMark");
608
+ var SAFE_SCHEMES = /* @__PURE__ */ new Set(["http", "https", "mailto", "tel"]);
609
+ var SCHEME = /^([a-z][a-z\d+.-]*):/i;
610
+ function safeRichTextHref(href) {
611
+ if (typeof href !== "string") return void 0;
612
+ let read = "";
613
+ for (const character of href) {
614
+ const code3 = character.codePointAt(0);
615
+ if (code3 === 9 || code3 === 10 || code3 === 13) continue;
616
+ read += character;
617
+ }
618
+ read = trimControls(read);
619
+ if (read === "") return void 0;
620
+ const scheme = SCHEME.exec(read);
621
+ if (scheme === null) return href;
622
+ return SAFE_SCHEMES.has(scheme[1].toLowerCase()) ? href : void 0;
623
+ }
624
+ __name(safeRichTextHref, "safeRichTextHref");
625
+ function trimControls(text) {
626
+ let start = 0;
627
+ let end = text.length;
628
+ while (start < end && text.charCodeAt(start) <= 32) start += 1;
629
+ while (end > start && text.charCodeAt(end - 1) <= 32) end -= 1;
630
+ return text.slice(start, end);
631
+ }
632
+ __name(trimControls, "trimControls");
633
+
634
+ // src/rich-text/html.ts
635
+ function escapeHtml(text) {
636
+ return String(text).replace(/["&'<>]/g, (character) => HTML_ESCAPES[character] ?? character);
637
+ }
638
+ __name(escapeHtml, "escapeHtml");
639
+ var HTML_ESCAPES = {
640
+ '"': "&quot;",
641
+ "&": "&amp;",
642
+ "'": "&#x27;",
643
+ "<": "&lt;",
644
+ ">": "&gt;"
645
+ };
646
+ function attributesOf(attributes) {
647
+ if (attributes === void 0) return "";
648
+ let written = "";
649
+ for (const [name, value] of Object.entries(attributes)) {
650
+ written += value === true ? ` ${name}=""` : ` ${name}="${escapeHtml(String(value))}"`;
651
+ }
652
+ return written;
653
+ }
654
+ __name(attributesOf, "attributesOf");
655
+ var VOID_ELEMENTS = /* @__PURE__ */ new Set([
656
+ "area",
657
+ "base",
658
+ "br",
659
+ "col",
660
+ "embed",
661
+ "hr",
662
+ "img",
663
+ "input",
664
+ "link",
665
+ "meta",
666
+ "source",
667
+ "track",
668
+ "wbr"
669
+ ]);
670
+ var RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set(["script", "style", "textarea", "title"]);
671
+ var BOUND = /\sdata-relyio-entry(?:[\s=/>]|$)/i;
672
+ function tagEnd(html, start) {
673
+ let quote;
674
+ for (let index = start + 1; index < html.length; index++) {
675
+ const character = html[index];
676
+ if (quote !== void 0) {
677
+ if (character === quote) quote = void 0;
678
+ } else if (character === '"' || character === "'") {
679
+ quote = character;
680
+ } else if (character === ">") {
681
+ return index + 1;
682
+ }
683
+ }
684
+ return -1;
685
+ }
686
+ __name(tagEnd, "tagEnd");
687
+ var TAG_NAME = /^<\/?([A-Za-z][\w:-]*)/;
688
+ function soleElementStartTag(html) {
689
+ const from = html.length - html.trimStart().length;
690
+ const to = html.trimEnd().length;
691
+ const root = TAG_NAME.exec(html.slice(from));
692
+ if (root === null || html[from + 1] === "/") return void 0;
693
+ let depth = 0;
694
+ let index = from;
695
+ let startTag;
696
+ while (index < to) {
697
+ if (depth === 0 && startTag !== void 0) return void 0;
698
+ const open = html.indexOf("<", index);
699
+ if (open !== index) {
700
+ if (depth === 0) return void 0;
701
+ if (open === -1 || open >= to) return void 0;
702
+ index = open;
703
+ continue;
704
+ }
705
+ if (html.startsWith("<!--", index)) {
706
+ if (depth === 0) return void 0;
707
+ const close = html.indexOf("-->", index + 4);
708
+ if (close === -1) return void 0;
709
+ index = close + 3;
710
+ continue;
711
+ }
712
+ const name = TAG_NAME.exec(html.slice(index));
713
+ if (name === null) {
714
+ if (depth === 0) return void 0;
715
+ index += 1;
716
+ continue;
717
+ }
718
+ const end = tagEnd(html, index);
719
+ if (end === -1 || end > to) return void 0;
720
+ const tag = (name[1] ?? "").toLowerCase();
721
+ if (html[index + 1] === "/") {
722
+ depth -= 1;
723
+ if (depth < 0) return void 0;
724
+ index = end;
725
+ continue;
726
+ }
727
+ const selfClosing = html[end - 2] === "/";
728
+ if (startTag === void 0) {
729
+ let insertAt = selfClosing ? end - 2 : end - 1;
730
+ while (insertAt > index && /\s/.test(html[insertAt - 1] ?? "")) insertAt -= 1;
731
+ startTag = { insertAt, tag: html.slice(index, end) };
732
+ }
733
+ if (selfClosing || VOID_ELEMENTS.has(tag)) {
734
+ index = end;
735
+ continue;
736
+ }
737
+ if (RAW_TEXT_ELEMENTS.has(tag)) {
738
+ const close = html.toLowerCase().indexOf(`</${tag}`, end);
739
+ if (close === -1) return void 0;
740
+ depth += 1;
741
+ index = close;
742
+ continue;
743
+ }
744
+ depth += 1;
745
+ index = end;
746
+ }
747
+ return depth === 0 ? startTag : void 0;
748
+ }
749
+ __name(soleElementStartTag, "soleElementStartTag");
750
+ function stamped(html, binding) {
751
+ if (binding === void 0) return html;
752
+ const root = soleElementStartTag(html);
753
+ if (root === void 0) return html;
754
+ if (BOUND.test(root.tag)) return html;
755
+ return `${html.slice(0, root.insertAt)}${attributesOf(binding)}${html.slice(root.insertAt)}`;
756
+ }
757
+ __name(stamped, "stamped");
758
+ function htmlTarget(declared2, entryLink, field) {
759
+ return {
760
+ element(tag, attributes, children) {
761
+ return RICH_TEXT_VOID_TAGS.has(tag) ? `<${tag}${attributesOf(attributes)}/>` : `<${tag}${attributesOf(attributes)}>${children.join("")}</${tag}>`;
762
+ },
763
+ text: escapeHtml,
764
+ node: /* @__PURE__ */ __name((_node, contents, draw) => draw(contents), "node"),
765
+ mark: /* @__PURE__ */ __name((_mark, contents, draw) => draw(contents), "mark"),
766
+ // A value built by hand holding an entry link no writer draws: its text, with no anchor
767
+ entryLink: /* @__PURE__ */ __name((link, contents) => entryLink === void 0 ? contents.join("") : entryLink(link, contents.join("")), "entryLink"),
768
+ // A declared node's writer (REL-1807), handed the node's key path below the field's binding and
769
+ // stamped with it (REL-2142); no binding asks the core nothing
770
+ declared(node) {
771
+ const write = Object.prototype.hasOwnProperty.call(declared2, node._type) ? declared2[node._type] : void 0;
772
+ if (write === void 0) return void 0;
773
+ const binding = field === void 0 ? void 0 : relyioField(field, node);
774
+ return stamped(write(node, binding), binding);
775
+ }
776
+ };
777
+ }
778
+ __name(htmlTarget, "htmlTarget");
779
+ function richTextToHtml(value, ...[options]) {
780
+ if (value === void 0) return "";
781
+ const declared2 = options?.declared ?? {};
782
+ const entryLink = options?.entryLink;
783
+ return renderRichText(
784
+ value,
785
+ htmlTarget(declared2, entryLink, options?.field),
786
+ options?.anchors === void 0 ? {} : { anchors: options.anchors }
787
+ ).join("");
788
+ }
789
+ __name(richTextToHtml, "richTextToHtml");
790
+
791
+ // src/rich-text/markdown.ts
792
+ var entryLinkWriter;
793
+ var writers = {};
794
+ function declared(node) {
795
+ const type = node._type;
796
+ const write = Object.prototype.hasOwnProperty.call(writers, type) ? writers[type] : void 0;
797
+ return write === void 0 ? void 0 : write(node);
798
+ }
799
+ __name(declared, "declared");
800
+ function richTextToMarkdown(value, ...[options]) {
801
+ if (value === void 0) return "";
802
+ const tree = value;
803
+ const held = tree._type === "richText" ? tree.children : [tree];
804
+ if (!Array.isArray(held)) return "";
805
+ const outer = writers;
806
+ const outerLink = entryLinkWriter;
807
+ writers = options?.declared ?? {};
808
+ entryLinkWriter = options?.entryLink;
809
+ try {
810
+ const written = blocks2(held);
811
+ return written.length === 0 ? "" : `${written.join("\n\n")}
812
+ `;
813
+ } finally {
814
+ writers = outer;
815
+ entryLinkWriter = outerLink;
816
+ }
817
+ }
818
+ __name(richTextToMarkdown, "richTextToMarkdown");
819
+ function blocks2(nodes) {
820
+ const out = [];
821
+ for (const node of nodes) {
822
+ const written = block2(node);
823
+ if (written !== void 0 && written !== "") out.push(written);
824
+ }
825
+ return out;
826
+ }
827
+ __name(blocks2, "blocks");
828
+ function block2(node) {
829
+ if (isDeclaredRichTextNode(node)) return declared(node);
830
+ switch (node._type) {
831
+ case "paragraph": {
832
+ return escapeLineStarts(inline2(node.children, "\\\n"));
833
+ }
834
+ case "heading": {
835
+ const text = inline2(node.children, " ").trim();
836
+ if (text === "") return void 0;
837
+ const level = Number.isInteger(node.level) ? Math.min(Math.max(node.level, 1), 6) : 1;
838
+ return `${"#".repeat(level)} ${text.replace(/ (#+)$/, " \\$1")}`;
839
+ }
840
+ case "quote": {
841
+ const inner = blocks2(node.children).join("\n\n");
842
+ if (inner === "") return void 0;
843
+ return inner.split("\n").map((line) => line === "" ? ">" : `> ${line}`).join("\n");
844
+ }
845
+ case "list": {
846
+ return list2(node);
847
+ }
848
+ case "codeBlock": {
849
+ return code2(node);
850
+ }
851
+ case "codeGroup": {
852
+ const tabs = node.children.filter((tab) => tab._type === "codeBlock").map((tab) => code2(tab));
853
+ return tabs.length === 0 ? void 0 : tabs.join("\n\n");
854
+ }
855
+ case "table": {
856
+ return table2(node);
857
+ }
858
+ case "divider": {
859
+ return "---";
860
+ }
861
+ default: {
862
+ return void 0;
863
+ }
864
+ }
865
+ }
866
+ __name(block2, "block");
867
+ function list2(node) {
868
+ const items = node.children.filter((item) => item._type === "listItem");
869
+ if (items.length === 0) return void 0;
870
+ const first = node.style === "numbered" && Number.isSafeInteger(node.start) ? node.start : 1;
871
+ return items.map((item, index) => {
872
+ let marker;
873
+ switch (node.style) {
874
+ case "numbered": {
875
+ marker = `${first + index}.`;
876
+ break;
877
+ }
878
+ case "task": {
879
+ marker = item.checked === true ? "- [x]" : "- [ ]";
880
+ break;
881
+ }
882
+ case "bullet": {
883
+ marker = "-";
884
+ break;
885
+ }
886
+ default: {
887
+ node.style;
888
+ marker = "-";
889
+ }
890
+ }
891
+ const indent = " ".repeat(node.style === "task" ? 2 : marker.length + 1);
892
+ let body = "";
893
+ for (const child of item.children) {
894
+ const part = block2(child);
895
+ if (part === void 0 || part === "") continue;
896
+ if (body !== "") body += interruptsParagraph(child) ? "\n" : "\n\n";
897
+ body += part;
898
+ }
899
+ if (body === "") return marker;
900
+ return `${marker} ${body.split("\n").map((line, at) => at === 0 || line === "" ? line : `${indent}${line}`).join("\n")}`;
901
+ }).join("\n");
902
+ }
903
+ __name(list2, "list");
904
+ function interruptsParagraph(node) {
905
+ if (node._type !== "list") return false;
906
+ return node.style !== "numbered" || node.start === void 0 || node.start === 1;
907
+ }
908
+ __name(interruptsParagraph, "interruptsParagraph");
909
+ function code2(node) {
910
+ const text = typeof node.text === "string" ? node.text : "";
911
+ const longest = Math.max(0, ...[...text.matchAll(/`+/g)].map((run) => run[0].length));
912
+ const fence = "`".repeat(Math.max(3, longest + 1));
913
+ const language = typeof node.language === "string" ? node.language.split(/\s/)[0] ?? "" : "";
914
+ const info = language.includes("`") ? "" : language;
915
+ return text === "" ? `${fence}${info}
916
+ ${fence}` : `${fence}${info}
917
+ ${text}
918
+ ${fence}`;
919
+ }
920
+ __name(code2, "code");
921
+ function table2(node) {
922
+ const rows = node.children.filter((row) => row._type === "tableRow").map((row) => row.children.filter((cell) => cell._type === "tableCell"));
923
+ if (rows.length === 0) return void 0;
924
+ const columns = Math.max(...rows.map((cells) => cells.length));
925
+ if (columns === 0) return void 0;
926
+ const text = rows.map(
927
+ (cells) => Array.from({ length: columns }, (_, at) => {
928
+ const cell = cells[at];
929
+ if (cell === void 0) return "";
930
+ const paragraphs = cell.children.filter((paragraph) => paragraph._type === "paragraph").map((paragraph) => inline2(paragraph.children, " ").trim()).filter((paragraph) => paragraph !== "");
931
+ return paragraphs.join(" ").replace(/\|/g, "\\|");
932
+ })
933
+ );
934
+ const alignments = Array.from({ length: columns }, (_, at) => rows[0][at]?.align);
935
+ const header = node.headerRow === true ? text[0] : Array.from({ length: columns }, () => "");
936
+ const body = node.headerRow === true ? text.slice(1) : text;
937
+ const widths = Array.from(
938
+ { length: columns },
939
+ (_, at) => Math.max(3, ...[header, ...body].map((cells) => cells[at].length))
940
+ );
941
+ const line = /* @__PURE__ */ __name((cells) => `| ${cells.map((cell, at) => cell.padEnd(widths[at])).join(" | ")} |`, "line");
942
+ const delimiter = `| ${alignments.map((align, at) => {
943
+ const width = widths[at];
944
+ switch (align) {
945
+ case "left": {
946
+ return `:${"-".repeat(width - 1)}`;
947
+ }
948
+ case "center": {
949
+ return `:${"-".repeat(width - 2)}:`;
950
+ }
951
+ case "right": {
952
+ return `${"-".repeat(width - 1)}:`;
953
+ }
954
+ case void 0: {
955
+ return "-".repeat(width);
956
+ }
957
+ default: {
958
+ return "-".repeat(width);
959
+ }
960
+ }
961
+ }).join(" | ")} |`;
962
+ return [line(header), delimiter, ...body.map((cells) => line(cells))].join("\n");
963
+ }
964
+ __name(table2, "table");
965
+ function inline2(nodes, lineBreak) {
966
+ let out = "";
967
+ let runs = [];
968
+ const flush = /* @__PURE__ */ __name(() => {
969
+ out += marked2(runs);
970
+ runs = [];
971
+ }, "flush");
972
+ for (const node of nodes) {
973
+ if (isDeclaredRichTextNode(node)) {
974
+ flush();
975
+ out += declared(node) ?? "";
976
+ continue;
977
+ }
978
+ switch (node._type) {
979
+ case "text": {
980
+ runs.push({ span: node, drawn: 0 });
981
+ break;
982
+ }
983
+ case "lineBreak": {
984
+ flush();
985
+ out += lineBreak;
986
+ break;
987
+ }
988
+ default: {
989
+ flush();
990
+ }
991
+ }
992
+ }
993
+ flush();
994
+ return out;
995
+ }
996
+ __name(inline2, "inline");
997
+ function marked2(runs) {
998
+ let out = "";
999
+ let index = 0;
1000
+ while (index < runs.length) {
1001
+ const run = runs[index];
1002
+ const mark = run.span.marks?.[run.drawn];
1003
+ if (mark === void 0) {
1004
+ out += escapeText(run.span.text);
1005
+ index += 1;
1006
+ continue;
1007
+ }
1008
+ let end = index + 1;
1009
+ while (end < runs.length && sameMark(runs[end].span.marks?.[runs[end].drawn], mark)) end += 1;
1010
+ if (mark._type === "code") {
1011
+ out += codeSpan(
1012
+ runs.slice(index, end).map((each) => each.span.text).join("")
1013
+ );
1014
+ index = end;
1015
+ continue;
1016
+ }
1017
+ const inner = marked2(
1018
+ runs.slice(index, end).map((each) => ({ span: each.span, drawn: each.drawn + 1 }))
1019
+ );
1020
+ out += applyMark2(mark, inner);
1021
+ index = end;
1022
+ }
1023
+ return out;
1024
+ }
1025
+ __name(marked2, "marked");
1026
+ function applyMark2(mark, inner) {
1027
+ switch (mark._type) {
1028
+ case "entryLink": {
1029
+ return entryLinkWriter === void 0 || inner === "" ? inner : entryLinkWriter(mark, inner);
1030
+ }
1031
+ case "link": {
1032
+ const href = safeRichTextHref(mark.href);
1033
+ if (href === void 0 || inner === "") return inner;
1034
+ return `[${inner}](${destination(href)})`;
1035
+ }
1036
+ case "bold": {
1037
+ return delimit("**", inner);
1038
+ }
1039
+ case "italic": {
1040
+ return delimit("*", inner);
1041
+ }
1042
+ case "strike": {
1043
+ return delimit("~~", inner);
1044
+ }
1045
+ case "code": {
1046
+ return inner;
1047
+ }
1048
+ case "underline":
1049
+ case "highlight":
1050
+ case "subscript":
1051
+ case "superscript": {
1052
+ return inner;
1053
+ }
1054
+ default: {
1055
+ return inner;
1056
+ }
1057
+ }
1058
+ }
1059
+ __name(applyMark2, "applyMark");
1060
+ function delimit(delimiter, inner) {
1061
+ const match = /^(\s*)([\s\S]*?)(\s*)$/.exec(inner);
1062
+ const [, before = "", core = "", after = ""] = match;
1063
+ if (core === "") return inner;
1064
+ return `${before}${delimiter}${core}${delimiter}${after}`;
1065
+ }
1066
+ __name(delimit, "delimit");
1067
+ function codeSpan(text) {
1068
+ const longest = Math.max(0, ...[...text.matchAll(/`+/g)].map((run) => run[0].length));
1069
+ const fence = "`".repeat(longest + 1);
1070
+ const padded = /^`|`$/.test(text) || /^ .*[^ ].* $/.test(text) ? ` ${text} ` : text;
1071
+ return `${fence}${padded}${fence}`;
1072
+ }
1073
+ __name(codeSpan, "codeSpan");
1074
+ function destination(href) {
1075
+ if (!/[\s()<>]/.test(href)) return href;
1076
+ return `<${href.replace(/</g, "%3C").replace(/>/g, "%3E").replace(/\s/g, "%20")}>`;
1077
+ }
1078
+ __name(destination, "destination");
1079
+ function escapeText(text) {
1080
+ return String(text).replace(/[\\`*_[\]<>~]/g, "\\$&").replace(/&(?=#?[\da-z]+;)/gi, "\\&");
1081
+ }
1082
+ __name(escapeText, "escapeText");
1083
+ function escapeLineStarts(paragraph) {
1084
+ return paragraph.split("\n").map(
1085
+ (line) => line.replace(/^(#{1,6})(?=\s|$)/, "\\$1").replace(/^([+=-])/, "\\$1").replace(/^(\d+)([).])/, "$1\\$2")
1086
+ ).join("\n");
1087
+ }
1088
+ __name(escapeLineStarts, "escapeLineStarts");
1089
+
1090
+ export { RICH_TEXT_VOID_TAGS, entryHeadingAnchors, escapeHtml, formatKeyPath, isDeclaredRichTextNode, parseKeyPath, relyioField, renderRichText, richTextHeadingAnchors, richTextHeadingSlug, richTextToHtml, richTextToMarkdown, safeRichTextHref };
1091
+ //# sourceMappingURL=chunk-3NPPMGB6.js.map
1092
+ //# sourceMappingURL=chunk-3NPPMGB6.js.map