@voltro/cms 0.85.0 → 0.87.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 (244) hide show
  1. package/CHANGELOG.md +5987 -0
  2. package/README.md +138 -0
  3. package/THIRD-PARTY-NOTICES.md +864 -253
  4. package/dist/ContentForm.js +282 -0
  5. package/dist/RichDocumentEditor.js +550 -0
  6. package/dist/RichDocumentView.js +177 -0
  7. package/dist/RichTextSurface.js +135 -0
  8. package/dist/aiCandidates.js +199 -0
  9. package/dist/aiOperations.js +152 -0
  10. package/dist/applicationBuildSnapshotService.js +101 -0
  11. package/dist/assetRenditions.js +102 -0
  12. package/dist/assetRevision.js +46 -0
  13. package/dist/assetUseRights.js +72 -0
  14. package/dist/audiences.js +31 -0
  15. package/dist/availability.js +124 -0
  16. package/dist/blueprint.js +166 -0
  17. package/dist/build.d.ts +3063 -0
  18. package/dist/build.js +37 -0
  19. package/dist/buildApplicationAdmission.js +16 -0
  20. package/dist/buildApplicationCatalog.js +136 -0
  21. package/dist/buildApplicationCatalogTable.js +24 -0
  22. package/dist/buildApplicationRest.js +99 -0
  23. package/dist/buildApplicationUpload.js +111 -0
  24. package/dist/buildSnapshot.js +401 -0
  25. package/dist/buildSnapshotApplicationPin.js +32 -0
  26. package/dist/buildSnapshotRest.js +210 -0
  27. package/dist/buildSnapshotService.js +265 -0
  28. package/dist/buildSnapshotTables.js +25 -0
  29. package/dist/bulk.js +282 -0
  30. package/dist/cacheIdentity.js +152 -0
  31. package/dist/changes.js +307 -0
  32. package/dist/cmsContext.js +229 -0
  33. package/dist/collections.js +224 -0
  34. package/dist/consent.js +29 -0
  35. package/dist/contentLocations.js +53 -0
  36. package/dist/contentProjection.js +83 -0
  37. package/dist/contentRouteIdentity.js +13 -0
  38. package/dist/contentRouteMaterializer.js +97 -0
  39. package/dist/contentRouteTypes.js +39 -0
  40. package/dist/contentSeo.js +189 -0
  41. package/dist/contentTreePath.js +60 -0
  42. package/dist/contentType.js +208 -0
  43. package/dist/contentValues.js +18 -0
  44. package/dist/contentfulImport.js +162 -0
  45. package/dist/copies.js +89 -0
  46. package/dist/cutover.js +202 -0
  47. package/dist/deliveryChecks.js +138 -0
  48. package/dist/domainHost.js +7 -0
  49. package/dist/domains.js +139 -0
  50. package/dist/draftTexts.js +164 -0
  51. package/dist/duplicates.js +78 -0
  52. package/dist/edgePurge.js +69 -0
  53. package/dist/editHistory.js +113 -0
  54. package/dist/effectForm.js +11 -0
  55. package/dist/environmentAliases.js +138 -0
  56. package/dist/environments.js +147 -0
  57. package/dist/errors.js +107 -0
  58. package/dist/experiments.js +528 -0
  59. package/dist/exposure.js +28 -0
  60. package/dist/extensionManifest.js +81 -0
  61. package/dist/extensions.js +314 -0
  62. package/dist/fieldSchema.js +199 -0
  63. package/dist/formStrings.js +74 -0
  64. package/dist/frontendBindings.js +99 -0
  65. package/dist/frontendMedia.js +18 -0
  66. package/dist/glossary.js +73 -0
  67. package/dist/history.js +54 -0
  68. package/dist/htmlImport.js +297 -0
  69. package/dist/index.d.ts +771 -54
  70. package/dist/index.js +89 -6082
  71. package/dist/initializePublicRoutes.js +28 -0
  72. package/dist/liveContentRouteView.js +76 -0
  73. package/dist/media.js +29 -0
  74. package/dist/metrics.js +46 -0
  75. package/dist/migration.js +193 -0
  76. package/dist/migrationStages.js +13 -0
  77. package/dist/nativeOutputDeploymentService.js +205 -0
  78. package/dist/outputActivation.js +234 -0
  79. package/dist/outputActivationOrigin.js +51 -0
  80. package/dist/outputActivationStore.js +411 -0
  81. package/dist/outputActivationTables.js +11 -0
  82. package/dist/outputActivationTarget.js +81 -0
  83. package/dist/outputActivationTargetTable.js +25 -0
  84. package/dist/outputDeployment.js +174 -0
  85. package/dist/outputDeploymentRest.js +168 -0
  86. package/dist/outputDeploymentService.js +241 -0
  87. package/dist/outputRouteGraph.js +177 -0
  88. package/dist/outputSafetyArtifact.js +147 -0
  89. package/dist/outputTargetRest.js +62 -0
  90. package/dist/pathSegmentEncoding.js +4 -0
  91. package/dist/presenceAnchors.js +68 -0
  92. package/dist/preview.js +31 -0
  93. package/dist/privateCmsTransport.js +76 -0
  94. package/dist/privateNativeRouteReservation.js +10 -0
  95. package/dist/promotion.js +116 -0
  96. package/dist/publicBuild.js +90 -0
  97. package/dist/publicBuildRest.js +98 -0
  98. package/dist/publicBuildService.js +63 -0
  99. package/dist/publicOutputHttp.js +129 -0
  100. package/dist/publicOutputService.js +287 -0
  101. package/dist/publicPresentation.js +17 -0
  102. package/dist/publicRouteDispositionAdmission.js +38 -0
  103. package/dist/publicRouteHistoryStore.js +12 -0
  104. package/dist/publicRouteHistoryView.js +34 -0
  105. package/dist/publicRouteIntegrity.js +5 -0
  106. package/dist/publicRouteMutation.js +6 -0
  107. package/dist/publicRouteNamespace.js +134 -0
  108. package/dist/publicRoutePublication.js +36 -0
  109. package/dist/publicRouteRegistry.js +17 -0
  110. package/dist/publicRouteRegistryBinding.js +194 -0
  111. package/dist/publicRouteRegistryDefinition.js +76 -0
  112. package/dist/publicRouteSitePublication.js +40 -0
  113. package/dist/publicRouteTables.js +13 -0
  114. package/dist/publicRouteUrl.js +18 -0
  115. package/dist/publicationSeo.js +52 -0
  116. package/dist/publicationState.js +296 -0
  117. package/dist/quality.js +188 -0
  118. package/dist/reconfigurePublicRoutes.js +41 -0
  119. package/dist/recurrence.js +78 -0
  120. package/dist/redirects.js +130 -0
  121. package/dist/referenceGraph.js +224 -0
  122. package/dist/references.js +173 -0
  123. package/dist/release.js +241 -0
  124. package/dist/renderReadAuthority.js +43 -0
  125. package/dist/renderReadGrant.js +137 -0
  126. package/dist/rest.js +52 -0
  127. package/dist/review.js +160 -0
  128. package/dist/richDocument.js +521 -0
  129. package/dist/richInline.js +100 -0
  130. package/dist/routeDispositionGraph.js +44 -0
  131. package/dist/routeDispositionRest.js +51 -0
  132. package/dist/routeDispositionService.js +73 -0
  133. package/dist/routeDispositionStore.js +289 -0
  134. package/dist/routeDispositionTables.js +5 -0
  135. package/dist/routeDispositions.js +91 -0
  136. package/dist/routeHistoryStorage.js +320 -0
  137. package/dist/routeHistoryStore.js +12 -0
  138. package/dist/schedule.js +80 -0
  139. package/dist/search.js +148 -0
  140. package/dist/selectionIntent.js +164 -0
  141. package/dist/seo.js +31 -0
  142. package/dist/series.js +105 -0
  143. package/dist/share.js +112 -0
  144. package/dist/siteBindings.js +159 -0
  145. package/dist/siteBuildCandidate.js +104 -0
  146. package/dist/siteDelivery.js +115 -0
  147. package/dist/siteState.js +47 -0
  148. package/dist/snapshotAddressGraph.js +55 -0
  149. package/dist/snapshotAddressRead.js +73 -0
  150. package/dist/snapshotAppConsumer.js +71 -0
  151. package/dist/snapshotAppExecution.js +102 -0
  152. package/dist/snapshotApplication.js +75 -0
  153. package/dist/snapshotApprovedRouteDispositions.js +44 -0
  154. package/dist/snapshotAssetAssembly.js +70 -0
  155. package/dist/snapshotAssetAssemblyRest.js +50 -0
  156. package/dist/snapshotBindingRead.js +61 -0
  157. package/dist/snapshotCodeSeo.js +29 -0
  158. package/dist/snapshotComponent.js +34 -0
  159. package/dist/snapshotComponentSource.js +24 -0
  160. package/dist/snapshotConsumer.js +87 -0
  161. package/dist/snapshotContentIdentity.js +10 -0
  162. package/dist/snapshotDefinitions.js +264 -0
  163. package/dist/snapshotDocumentAssembly.js +193 -0
  164. package/dist/snapshotDocumentAssemblyRest.js +84 -0
  165. package/dist/snapshotDocumentProjection.js +202 -0
  166. package/dist/snapshotDocumentTransfer.js +35 -0
  167. package/dist/snapshotDocumentTransferRest.js +80 -0
  168. package/dist/snapshotDomains.js +56 -0
  169. package/dist/snapshotEnvironment.js +31 -0
  170. package/dist/snapshotFieldPlan.js +85 -0
  171. package/dist/snapshotFrontend.js +103 -0
  172. package/dist/snapshotLink.js +8 -0
  173. package/dist/snapshotMedia.js +111 -0
  174. package/dist/snapshotMediaCapture.js +246 -0
  175. package/dist/snapshotMediaFields.js +225 -0
  176. package/dist/snapshotMediaRead.js +185 -0
  177. package/dist/snapshotMediaReader.js +13 -0
  178. package/dist/snapshotObservation.js +16 -0
  179. package/dist/snapshotObservedRouteHistory.js +34 -0
  180. package/dist/snapshotOutputTransfer.js +78 -0
  181. package/dist/snapshotPageLoader.js +7 -0
  182. package/dist/snapshotPageSeo.js +59 -0
  183. package/dist/snapshotPathLocale.js +15 -0
  184. package/dist/snapshotPresentation.js +86 -0
  185. package/dist/snapshotPresentationPolicy.js +12 -0
  186. package/dist/snapshotProjection.js +119 -0
  187. package/dist/snapshotPublicAccess.js +161 -0
  188. package/dist/snapshotPublicRouteHistory.js +40 -0
  189. package/dist/snapshotReadAdmission.js +38 -0
  190. package/dist/snapshotRedirectOutput.js +151 -0
  191. package/dist/snapshotRedirectTargets.js +24 -0
  192. package/dist/snapshotRedirects.js +132 -0
  193. package/dist/snapshotReference.js +8 -0
  194. package/dist/snapshotReferenceAddress.js +10 -0
  195. package/dist/snapshotReferenceGraph.js +79 -0
  196. package/dist/snapshotReferenceRead.js +65 -0
  197. package/dist/snapshotRelease.js +99 -0
  198. package/dist/snapshotRender.js +361 -0
  199. package/dist/snapshotRenderDependencies.js +178 -0
  200. package/dist/snapshotRenditions.js +88 -0
  201. package/dist/snapshotRichDocument.js +62 -0
  202. package/dist/snapshotRoleTransfer.js +106 -0
  203. package/dist/snapshotRoleTransferRest.js +99 -0
  204. package/dist/snapshotRouteAdmission.js +71 -0
  205. package/dist/snapshotRouteDispatch.js +111 -0
  206. package/dist/snapshotRouteDispositionPlan.js +73 -0
  207. package/dist/snapshotRouteRead.js +43 -0
  208. package/dist/snapshotRoutes.js +79 -0
  209. package/dist/snapshotRouting.js +113 -0
  210. package/dist/snapshotSeo.js +179 -0
  211. package/dist/snapshotSeoControls.js +101 -0
  212. package/dist/snapshotSeoDocumentInventory.js +115 -0
  213. package/dist/snapshotSeoDocuments.js +129 -0
  214. package/dist/snapshotSeoMerge.js +85 -0
  215. package/dist/snapshotSeoMetadata.js +137 -0
  216. package/dist/snapshotSeoOutput.js +173 -0
  217. package/dist/snapshotSeoPathSets.js +105 -0
  218. package/dist/snapshotSeoRead.js +88 -0
  219. package/dist/snapshotSite.js +128 -0
  220. package/dist/snapshotSitemapFiles.js +36 -0
  221. package/dist/snapshotTreeDependencies.js +58 -0
  222. package/dist/snapshotTreeLoader.js +10 -0
  223. package/dist/snapshotTreeRead.js +158 -0
  224. package/dist/staticPathSet.js +177 -0
  225. package/dist/staticPathSetRest.js +129 -0
  226. package/dist/staticPathSetService.js +249 -0
  227. package/dist/staticPathSetStore.js +338 -0
  228. package/dist/stewardship.js +146 -0
  229. package/dist/taxonomy.js +36 -0
  230. package/dist/team.js +103 -0
  231. package/dist/templates.js +106 -0
  232. package/dist/trackChanges.js +197 -0
  233. package/dist/translation.js +64 -0
  234. package/dist/tree.js +87 -0
  235. package/dist/usage.js +50 -0
  236. package/dist/validation.js +192 -0
  237. package/dist/visualEditing.js +60 -0
  238. package/dist/web.d.ts +709 -7
  239. package/dist/web.js +50 -2
  240. package/dist/workflow.js +322 -0
  241. package/dist/write.js +419 -0
  242. package/dist/xliff.js +325 -0
  243. package/package.json +20 -6
  244. package/dist/presenceAnchors-4iHAVQB3.js +0 -4367
@@ -0,0 +1,73 @@
1
+ import { asTyped as e } from "./effectForm.js";
2
+ import { and as t, eq as n, id as r, json as i, table as a, text as o } from "@voltro/database";
3
+ import { tenant as s } from "@voltro/plugin-multitenancy/mixin";
4
+ //#region src/glossary.ts
5
+ var c = "cms_glossary", l = a(c, {
6
+ id: r({ prefix: "cgl" }),
7
+ term: o(),
8
+ termKey: o().maxLength(100),
9
+ locale: o().maxLength(64),
10
+ translation: o().nullable(),
11
+ forbidden: i().nullable(),
12
+ note: o().nullable()
13
+ }).with(s()).unique("cms_glossary_uq_term", [
14
+ "tenantId",
15
+ "termKey",
16
+ "locale"
17
+ ]), u = (e) => e.trim().toLowerCase(), d = (e) => ({
18
+ id: String(e.id),
19
+ term: String(e.term),
20
+ locale: String(e.locale),
21
+ translation: typeof e.translation == "string" ? e.translation : null,
22
+ forbidden: Array.isArray(e.forbidden) ? e.forbidden.filter((e) => typeof e == "string") : [],
23
+ note: typeof e.note == "string" ? e.note : null
24
+ }), f = (e) => {
25
+ let t = [], n = e.term.trim();
26
+ return (n === "" || n.length > 100) && t.push("a term has 1 to 100 characters"), /^[a-z]{2}(-[A-Z]{2})?$/.test(e.locale) || t.push(`"${e.locale}" is not a language`), (e.translation ?? "").length > 100 && t.push("a translation has at most 100 characters"), ((e.forbidden ?? []).length > 20 || (e.forbidden ?? []).some((e) => e.trim() === "" || e.length > 100)) && t.push("at most 20 forbidden translations of 1 to 100 characters"), t;
27
+ }, p = async (e, r, i) => {
28
+ let a = {
29
+ term: i.term.trim(),
30
+ locale: i.locale,
31
+ translation: i.translation === void 0 || i.translation === null || i.translation.trim() === "" ? null : i.translation.trim(),
32
+ forbidden: [...new Set((i.forbidden ?? []).map((e) => e.trim()).filter((e) => e !== ""))],
33
+ note: i.note === void 0 || i.note === null || i.note.trim() === "" ? null : i.note.trim()
34
+ }, [o] = await e.query({
35
+ table: c,
36
+ predicate: t(n("tenantId", r), n("termKey", u(i.term)), n("locale", i.locale)),
37
+ order: [],
38
+ take: 1,
39
+ skip: void 0,
40
+ projection: void 0
41
+ });
42
+ return o === void 0 ? (await e.insert(c, {
43
+ ...a,
44
+ termKey: u(i.term),
45
+ tenantId: r
46
+ }), "added") : (await e.update(c, String(o.id), a), "replaced");
47
+ }, m = async (e, r, i) => {
48
+ let [a] = await e.query({
49
+ table: c,
50
+ predicate: t(n("tenantId", r), n("id", i)),
51
+ order: [],
52
+ take: 1,
53
+ skip: void 0,
54
+ projection: void 0
55
+ });
56
+ return a !== void 0 && (await e.delete(c, i), !0);
57
+ }, h = async (e, r, i) => (await e.query({
58
+ table: c,
59
+ predicate: i === void 0 ? n("tenantId", r) : t(n("tenantId", r), n("locale", i)),
60
+ order: [{
61
+ column: "termKey",
62
+ direction: "asc"
63
+ }],
64
+ take: void 0,
65
+ skip: void 0,
66
+ projection: void 0
67
+ })).map(d), g = (e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), _ = (e, t) => RegExp(`(^|[^\\p{L}\\p{N}])${g(t.trim())}($|[^\\p{L}\\p{N}])`, "iu").test(e), v = (e, t) => t.filter((t) => _(e, t.term)), y = (e, t) => t.flatMap((t) => t.forbidden.filter((t) => _(e, t)).map((e) => ({
68
+ term: t.term,
69
+ found: e,
70
+ use: t.translation
71
+ }))), b = (...t) => e(() => h(...t)), x = (...t) => e(() => m(...t)), S = (...t) => e(() => p(...t));
72
+ //#endregion
73
+ export { c as CMS_GLOSSARY_TABLE, l as cmsGlossaryTable, h as glossary, b as glossaryEffect, f as glossaryInputProblems, y as glossaryProblems, m as removeGlossaryTerm, x as removeGlossaryTermEffect, p as setGlossaryTerm, S as setGlossaryTermEffect, v as termsIn };
@@ -0,0 +1,54 @@
1
+ import { plainTextOf as e } from "./richDocument.js";
2
+ //#region src/history.ts
3
+ var t = (e) => Array.isArray(e) ? e.map(t) : typeof e == "object" && e && !(e instanceof Date) ? Object.fromEntries(Object.keys(e).sort().map((n) => [n, t(e[n])])) : e instanceof Date ? e.toISOString() : e === void 0 ? null : e, n = (e, n, r) => Object.keys(e).filter((e) => JSON.stringify(t(n[e])) !== JSON.stringify(t(r[e]))), r = (e, n) => {
4
+ let r = [...e].sort((e, t) => Number(e.number) - Number(t.number)), i = [], a;
5
+ for (let e of r) {
6
+ let r = (e.values ?? {})[n], o = JSON.stringify(t(r));
7
+ o !== a && (a = o, r != null && r !== "" && i.push({
8
+ value: r,
9
+ revisionId: String(e.id),
10
+ number: Number(e.number),
11
+ createdAt: e.createdAt,
12
+ createdBy: e.createdBy
13
+ }));
14
+ }
15
+ return i.reverse();
16
+ }, i = (e) => e.match(/\s+|[^\s]+/g) ?? [], a = 4e6, o = (e, t) => {
17
+ let n = i(e), r = i(t), o = [], s = (e, t) => {
18
+ if (t === "") return;
19
+ let n = o[o.length - 1];
20
+ n !== void 0 && n.op === e ? o[o.length - 1] = {
21
+ op: e,
22
+ text: n.text + t
23
+ } : o.push({
24
+ op: e,
25
+ text: t
26
+ });
27
+ };
28
+ if (n.length * r.length > a) return s("removed", e), s("added", t), o;
29
+ let c = Array.from({ length: n.length + 1 }, () => Array(r.length + 1).fill(0));
30
+ for (let e = n.length - 1; e >= 0; e--) for (let t = r.length - 1; t >= 0; t--) c[e][t] = n[e] === r[t] ? c[e + 1][t + 1] + 1 : Math.max(c[e + 1][t], c[e][t + 1]);
31
+ let l = 0, u = 0;
32
+ for (; l < n.length && u < r.length;) n[l] === r[u] ? (s("same", n[l]), l++, u++) : c[l + 1][u] >= c[l][u + 1] ? (s("removed", n[l]), l++) : (s("added", r[u]), u++);
33
+ for (; l < n.length;) s("removed", n[l++]);
34
+ for (; u < r.length;) s("added", r[u++]);
35
+ return o;
36
+ }, s = (e) => typeof e == "object" && !!e && e.type === "doc" && Array.isArray(e.blocks), c = (n) => {
37
+ if (n == null) return "";
38
+ if (typeof n == "string") return n;
39
+ if (typeof n == "number" || typeof n == "boolean") return String(n);
40
+ if (n instanceof Date) return n.toISOString();
41
+ if (s(n)) return e(n);
42
+ if (Array.isArray(n)) return n.map(c).join("\n");
43
+ let r = n;
44
+ if (typeof r.componentId == "string" && typeof r.props == "object" && r.props !== null) {
45
+ let e = Object.values(r.props).map(c).filter((e) => e !== "");
46
+ return `${r.componentId}: ${e.join(" · ")}`;
47
+ }
48
+ return JSON.stringify(t(n));
49
+ }, l = (e, t, r) => n(e, t, r).map((e) => ({
50
+ field: e,
51
+ segments: o(c(t[e]), c(r[e]))
52
+ }));
53
+ //#endregion
54
+ export { n as changedFields, o as diffWords, l as fieldDiffs, r as fieldVersions, c as valueText };
@@ -0,0 +1,297 @@
1
+ import { contactLiteralProblem as e } from "./richDocument.js";
2
+ //#region src/htmlImport.ts
3
+ var t = {
4
+ amp: "&",
5
+ lt: "<",
6
+ gt: ">",
7
+ quot: "\"",
8
+ apos: "'",
9
+ nbsp: "\xA0",
10
+ ndash: "–",
11
+ mdash: "—",
12
+ hellip: "…",
13
+ lsquo: "‘",
14
+ rsquo: "’",
15
+ ldquo: "“",
16
+ rdquo: "”",
17
+ copy: "©",
18
+ euro: "€"
19
+ }, n = (e) => e.replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi, (e, n) => {
20
+ if (n[0] === "#") {
21
+ let t = n[1] === "x" || n[1] === "X" ? Number.parseInt(n.slice(2), 16) : Number.parseInt(n.slice(1), 10);
22
+ return Number.isFinite(t) && t > 0 && t <= 1114111 ? String.fromCodePoint(t) : e;
23
+ }
24
+ return t[n.toLowerCase()] ?? e;
25
+ }), r = (e) => {
26
+ try {
27
+ return decodeURIComponent(e);
28
+ } catch {
29
+ return e;
30
+ }
31
+ }, i = /* @__PURE__ */ new Set([
32
+ "script",
33
+ "style",
34
+ "iframe",
35
+ "object",
36
+ "embed",
37
+ "noscript",
38
+ "template",
39
+ "svg",
40
+ "form",
41
+ "select",
42
+ "textarea",
43
+ "button"
44
+ ]), a = /* @__PURE__ */ new Set([
45
+ "span",
46
+ "div",
47
+ "section",
48
+ "article",
49
+ "main",
50
+ "header",
51
+ "footer",
52
+ "figure",
53
+ "blockquote",
54
+ "u",
55
+ "small",
56
+ "sup",
57
+ "sub",
58
+ "code",
59
+ "pre",
60
+ "thead",
61
+ "tbody",
62
+ "tfoot",
63
+ "font",
64
+ "center"
65
+ ]), o = (e) => {
66
+ let t = {};
67
+ for (let r of e.matchAll(/([a-zA-Z_:][-a-zA-Z0-9_:.]*)\s*(?:=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g)) t[r[1].toLowerCase()] = n(r[2] ?? r[3] ?? r[4] ?? "");
68
+ return t;
69
+ }, s = (e) => {
70
+ let t = [], n = e.replace(/<!--[\s\S]*?-->/g, ""), r = 0;
71
+ for (let e of n.matchAll(/<(\/?)([a-zA-Z][a-zA-Z0-9]*)([^>]*)>/g)) {
72
+ e.index > r && t.push({
73
+ kind: "text",
74
+ text: n.slice(r, e.index)
75
+ });
76
+ let i = e[3] ?? "";
77
+ t.push({
78
+ kind: "tag",
79
+ tag: {
80
+ name: e[2].toLowerCase(),
81
+ closing: e[1] === "/",
82
+ attrs: o(i.replace(/\/\s*$/, "")),
83
+ selfClosing: /\/\s*$/.test(i)
84
+ }
85
+ }), r = e.index + e[0].length;
86
+ }
87
+ return r < n.length && t.push({
88
+ kind: "text",
89
+ text: n.slice(r)
90
+ }), t;
91
+ }, c = (t, o = {}) => {
92
+ let c = 0, l = o.newId ?? (() => `rb_import_${++c}`), u = [], d = [], f = (e, t) => {
93
+ d.some((n) => n.kind === e && n.detail === t) || d.push({
94
+ kind: e,
95
+ detail: t
96
+ });
97
+ }, p = [], m = null, h = [], g = null, _ = null, v = null, y = null, b = !1, x = (e) => {
98
+ let t = n(e.replace(/[ \t\r\n\f]+/g, " "));
99
+ if (t === "" || t === " " && h.length === 0) return;
100
+ let r = h[h.length - 1];
101
+ m !== null && m.target !== null ? r?.type === "link" && r.target === m.target ? h[h.length - 1] = {
102
+ ...r,
103
+ text: r.text + t
104
+ } : h.push({
105
+ type: "link",
106
+ target: m.target,
107
+ text: t
108
+ }) : m?.contact === void 0 ? r?.type === "text" && ((e) => (e ?? []).join() === p.join())(r.marks) ? h[h.length - 1] = {
109
+ ...r,
110
+ text: r.text + t
111
+ } : h.push({
112
+ type: "text",
113
+ text: t,
114
+ ...p.length > 0 ? { marks: [...p] } : {}
115
+ }) : r?.type === "contact" && r.contact === m.contact ? h[h.length - 1] = {
116
+ ...r,
117
+ text: r.text + t
118
+ } : h.push({
119
+ type: "contact",
120
+ contact: m.contact,
121
+ text: t
122
+ });
123
+ }, S = () => {
124
+ let e = [...h], t = e[0];
125
+ t !== void 0 && (e[0] = {
126
+ ...t,
127
+ text: t.text.replace(/^[ \t\r\n\f]+/, "")
128
+ });
129
+ let n = e[e.length - 1];
130
+ return n !== void 0 && (e[e.length - 1] = {
131
+ ...n,
132
+ text: n.text.replace(/[ \t\r\n\f]+$/, "")
133
+ }), e.filter((e) => e.text !== "");
134
+ }, C = () => {
135
+ if (v === null || v.items.length === 0) return;
136
+ let { ordered: e, items: t, levels: n, sublists: r } = v, i = e ? "ordered" : "unordered", a = r.some((e) => e !== i) ? { sublists: r } : {};
137
+ u.push({
138
+ id: l(),
139
+ type: "list",
140
+ ordered: e,
141
+ items: t,
142
+ ...n.some((e) => e > 0) ? {
143
+ levels: n,
144
+ ...a
145
+ } : {}
146
+ });
147
+ }, w = (e = g) => {
148
+ let t = S();
149
+ h = [], t.length !== 0 && (e === "li" && v !== null ? (v.items.push(t), v.levels.push(Math.min(v.depth, 3))) : e === "cell" && y?.row ? y.row.push(t) : e === "h2" || e === "h3" ? u.push({
150
+ id: l(),
151
+ type: "heading",
152
+ level: e === "h2" ? 2 : 3,
153
+ content: t
154
+ }) : u.push({
155
+ id: l(),
156
+ type: "paragraph",
157
+ content: t
158
+ }));
159
+ }, T = (e) => {
160
+ e.split(/\n\s*\n/).forEach((e, t) => {
161
+ t > 0 && w("p"), x(e);
162
+ });
163
+ };
164
+ for (let n of s(t)) {
165
+ if (_ !== null) {
166
+ n.kind === "tag" && n.tag.closing && n.tag.name === _ && (_ = null);
167
+ continue;
168
+ }
169
+ if (n.kind === "text") {
170
+ g === null && v === null && y === null ? T(n.text) : x(n.text);
171
+ continue;
172
+ }
173
+ let { name: t, closing: s, attrs: c } = n.tag;
174
+ if (i.has(t)) f("unsupportedTag", t), !s && !n.tag.selfClosing && (_ = t);
175
+ else switch (t) {
176
+ case "p":
177
+ s ? (w(), g = null) : (w("p"), g = "p");
178
+ break;
179
+ case "h1":
180
+ case "h2":
181
+ case "h3":
182
+ case "h4":
183
+ case "h5":
184
+ case "h6":
185
+ s ? (w(), g = null) : (w("p"), g = t === "h1" || t === "h2" ? "h2" : "h3");
186
+ break;
187
+ case "br":
188
+ x(" ");
189
+ break;
190
+ case "strong":
191
+ case "b":
192
+ case "em":
193
+ case "i":
194
+ case "u": {
195
+ let e = t === "strong" || t === "b" ? "bold" : t === "u" ? "underline" : "italic";
196
+ if (s) {
197
+ let t = p.lastIndexOf(e);
198
+ t >= 0 && p.splice(t, 1);
199
+ } else p.push(e);
200
+ break;
201
+ }
202
+ case "a":
203
+ if (s) {
204
+ m = null;
205
+ break;
206
+ }
207
+ {
208
+ let t = c.href ?? "", n = /^(mailto|tel):(.+)$/i.exec(t.trim());
209
+ if (o.contacts === !0 && n !== null) {
210
+ let t = n[1].toLowerCase() === "mailto" ? "email" : "phone", i = r(n[2].split("?")[0]).trim();
211
+ if (e(t, i) === null) {
212
+ m = {
213
+ target: null,
214
+ contact: {
215
+ channel: t,
216
+ value: i
217
+ }
218
+ };
219
+ break;
220
+ }
221
+ }
222
+ let i = o.resolveLink?.(t) ?? null;
223
+ i === null && t !== "" && f("externalLink", t), m = { target: i };
224
+ }
225
+ break;
226
+ case "img": {
227
+ let e = c.src ?? "", t = o.resolveImage?.(e) ?? null;
228
+ if (t === null) {
229
+ f("image", e), c.alt && x(c.alt);
230
+ break;
231
+ }
232
+ let n = g;
233
+ w(g === "li" || g === "cell" ? g : "p"), u.push({
234
+ id: l(),
235
+ type: "image",
236
+ asset: t,
237
+ ...c.alt ? { caption: c.alt } : {}
238
+ }), g = n;
239
+ break;
240
+ }
241
+ case "ul":
242
+ case "ol":
243
+ if (s) {
244
+ if (v !== null && v.depth > 0) {
245
+ w("li"), v.depth--, g = "li";
246
+ break;
247
+ }
248
+ w(), C(), v = null, g = null;
249
+ } else if (v !== null) {
250
+ w("li"), v.depth++, g = null;
251
+ let e = Math.min(v.depth, 3) - 1;
252
+ for (; v.sublists.length < e;) v.sublists.push(v.sublists[v.sublists.length - 1] ?? (v.ordered ? "ordered" : "unordered"));
253
+ v.sublists.length === e && v.sublists.push(t === "ol" ? "ordered" : "unordered");
254
+ } else w("p"), v = {
255
+ ordered: t === "ol",
256
+ items: [],
257
+ levels: [],
258
+ depth: 0,
259
+ sublists: []
260
+ }, g = null;
261
+ break;
262
+ case "li":
263
+ s ? (w("li"), g = null) : (w(v === null ? "p" : "li"), g = "li");
264
+ break;
265
+ case "table":
266
+ s ? (y !== null && y.rows.length > 0 && u.push({
267
+ id: l(),
268
+ type: "table",
269
+ header: y.header,
270
+ rows: y.rows
271
+ }), y = null) : (w("p"), y = {
272
+ header: !1,
273
+ rows: [],
274
+ row: null
275
+ });
276
+ break;
277
+ case "tr":
278
+ if (y === null) break;
279
+ s ? (y.row && y.row.length > 0 && (y.rows.length === 0 && b && (y.header = !0), y.rows.push(y.row)), y.row = null, b = !1) : y.row = [];
280
+ break;
281
+ case "th":
282
+ case "td":
283
+ s ? (w("cell"), g = null) : (t === "th" && (b = !0), h = [], g = "cell");
284
+ break;
285
+ default: a.has(t) || f("unsupportedTag", t);
286
+ }
287
+ }
288
+ return w(g ?? "p"), C(), {
289
+ document: {
290
+ type: "doc",
291
+ blocks: u
292
+ },
293
+ findings: d
294
+ };
295
+ };
296
+ //#endregion
297
+ export { n as decodeEntities, c as richDocumentFromHtml };