@prismicio/migrate 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +96 -0
  3. package/dist/errors/PrismicRichTextError.cjs +6 -0
  4. package/dist/errors/PrismicRichTextError.cjs.map +1 -0
  5. package/dist/errors/PrismicRichTextError.d.ts +2 -0
  6. package/dist/errors/PrismicRichTextError.js +6 -0
  7. package/dist/errors/PrismicRichTextError.js.map +1 -0
  8. package/dist/errors/PrismicRichTextSerializerError.cjs +7 -0
  9. package/dist/errors/PrismicRichTextSerializerError.cjs.map +1 -0
  10. package/dist/errors/PrismicRichTextSerializerError.d.ts +3 -0
  11. package/dist/errors/PrismicRichTextSerializerError.js +7 -0
  12. package/dist/errors/PrismicRichTextSerializerError.js.map +1 -0
  13. package/dist/htmlAsRichText.cjs +11 -0
  14. package/dist/htmlAsRichText.cjs.map +1 -0
  15. package/dist/htmlAsRichText.d.ts +78 -0
  16. package/dist/htmlAsRichText.js +11 -0
  17. package/dist/htmlAsRichText.js.map +1 -0
  18. package/dist/index.cjs +9 -0
  19. package/dist/index.cjs.map +1 -0
  20. package/dist/index.d.ts +4 -0
  21. package/dist/index.js +9 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/lib/RichTextFieldBuilder.cjs +115 -0
  24. package/dist/lib/RichTextFieldBuilder.cjs.map +1 -0
  25. package/dist/lib/RichTextFieldBuilder.d.ts +35 -0
  26. package/dist/lib/RichTextFieldBuilder.js +115 -0
  27. package/dist/lib/RichTextFieldBuilder.js.map +1 -0
  28. package/dist/lib/filterRichTextField.cjs +87 -0
  29. package/dist/lib/filterRichTextField.cjs.map +1 -0
  30. package/dist/lib/filterRichTextField.d.ts +10 -0
  31. package/dist/lib/filterRichTextField.js +87 -0
  32. package/dist/lib/filterRichTextField.js.map +1 -0
  33. package/dist/lib/hastSerializerHelpers.cjs +95 -0
  34. package/dist/lib/hastSerializerHelpers.cjs.map +1 -0
  35. package/dist/lib/hastSerializerHelpers.d.ts +28 -0
  36. package/dist/lib/hastSerializerHelpers.js +95 -0
  37. package/dist/lib/hastSerializerHelpers.js.map +1 -0
  38. package/dist/lib/hastToRichText.cjs +164 -0
  39. package/dist/lib/hastToRichText.cjs.map +1 -0
  40. package/dist/lib/hastToRichText.d.ts +30 -0
  41. package/dist/lib/hastToRichText.js +164 -0
  42. package/dist/lib/hastToRichText.js.map +1 -0
  43. package/dist/lib/rehypeRichText.cjs +59 -0
  44. package/dist/lib/rehypeRichText.cjs.map +1 -0
  45. package/dist/lib/rehypeRichText.d.ts +65 -0
  46. package/dist/lib/rehypeRichText.js +59 -0
  47. package/dist/lib/rehypeRichText.js.map +1 -0
  48. package/dist/types.d.ts +57 -0
  49. package/package.json +95 -0
  50. package/src/errors/PrismicRichTextError.ts +1 -0
  51. package/src/errors/PrismicRichTextSerializerError.ts +3 -0
  52. package/src/htmlAsRichText.ts +117 -0
  53. package/src/index.ts +7 -0
  54. package/src/lib/RichTextFieldBuilder.ts +164 -0
  55. package/src/lib/filterRichTextField.ts +158 -0
  56. package/src/lib/hastSerializerHelpers.ts +151 -0
  57. package/src/lib/hastToRichText.ts +294 -0
  58. package/src/lib/rehypeRichText.ts +185 -0
  59. package/src/types.ts +72 -0
@@ -0,0 +1,35 @@
1
+ import type { RTInlineNode, RTNode, RTTextNode, RichTextField } from "@prismicio/client";
2
+ /**
3
+ * Omits keys from a type, distributing the operation over a union.
4
+ *
5
+ * Taken from the `type-fest` package.
6
+ *
7
+ * @see https://github.com/sindresorhus/type-fest/blob/8a45ba048767aaffcebc7d190172d814a739feb0/source/distributed-omit.d.ts
8
+ */
9
+ type DistributedOmit<ObjectType, KeyType extends keyof ObjectType> = ObjectType extends unknown ? Omit<ObjectType, KeyType> : never;
10
+ /**
11
+ * An inline node without its `start` and `end` properties.
12
+ */
13
+ export type RTPartialInlineNode = DistributedOmit<RTInlineNode, "start" | "end">;
14
+ export declare class RichTextFieldBuilder {
15
+ #private;
16
+ appendNode(node: RTNode): void;
17
+ appendTextNode(type: RTTextNode["type"], direction?: "ltr" | "rtl"): void;
18
+ appendSpan(span: RTInlineNode): void;
19
+ appendSpan(partialSpan: RTPartialInlineNode, length: number): void;
20
+ appendText(text: string): void;
21
+ build(): RichTextField;
22
+ /**
23
+ * Cleans up the current last node.
24
+ */
25
+ private cleanupLast;
26
+ /**
27
+ * Determines if a node is a text node.
28
+ *
29
+ * @param node - rich text node to check.
30
+ *
31
+ * @returns `true` if `node` is a text node, `false` otherwise.
32
+ */
33
+ private isTextNode;
34
+ }
35
+ export {};
@@ -0,0 +1,115 @@
1
+ var __typeError = (msg) => {
2
+ throw TypeError(msg);
3
+ };
4
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
+ var _nodes, _RichTextFieldBuilder_instances, last_get;
8
+ import { PrismicRichTextError } from "../errors/PrismicRichTextError.js";
9
+ class RichTextFieldBuilder {
10
+ constructor() {
11
+ __privateAdd(this, _RichTextFieldBuilder_instances);
12
+ __privateAdd(this, _nodes, []);
13
+ }
14
+ appendNode(node) {
15
+ this.cleanupLast();
16
+ __privateGet(this, _nodes).push(node);
17
+ }
18
+ appendTextNode(type, direction = "ltr") {
19
+ this.appendNode({
20
+ type,
21
+ text: "",
22
+ spans: [],
23
+ direction
24
+ });
25
+ }
26
+ appendSpan(spanOrPartialSpan, length) {
27
+ var _a;
28
+ if (!this.isTextNode(__privateGet(this, _RichTextFieldBuilder_instances, last_get))) {
29
+ throw new PrismicRichTextError("Cannot add span to non-text last node");
30
+ }
31
+ let span;
32
+ if ("start" in spanOrPartialSpan && "end" in spanOrPartialSpan) {
33
+ span = spanOrPartialSpan;
34
+ } else {
35
+ const lastLength = __privateGet(this, _RichTextFieldBuilder_instances, last_get).text.length;
36
+ span = {
37
+ ...spanOrPartialSpan,
38
+ start: lastLength,
39
+ end: lastLength + length
40
+ };
41
+ }
42
+ let lastIdenticalSpanIndex = -1;
43
+ for (let i = __privateGet(this, _RichTextFieldBuilder_instances, last_get).spans.length - 1; i >= 0; i--) {
44
+ const lastSpan = __privateGet(this, _RichTextFieldBuilder_instances, last_get).spans[i];
45
+ if (span.type === "strong" || span.type === "em") {
46
+ if (lastSpan.type === span.type) {
47
+ lastIdenticalSpanIndex = i;
48
+ break;
49
+ }
50
+ } else if (span.type === "label") {
51
+ if (lastSpan.type === "label" && lastSpan.data.label === span.data.label) {
52
+ lastIdenticalSpanIndex = i;
53
+ break;
54
+ }
55
+ } else if (span.type === "hyperlink") {
56
+ if (lastSpan.type === "hyperlink") {
57
+ const isSameLink = Object.entries(span.data).every(([key, value]) => lastSpan.data[key] === value);
58
+ if (isSameLink) {
59
+ lastIdenticalSpanIndex = i;
60
+ break;
61
+ }
62
+ }
63
+ }
64
+ }
65
+ if (span.start === span.end) {
66
+ return;
67
+ }
68
+ if (((_a = __privateGet(this, _RichTextFieldBuilder_instances, last_get).spans[lastIdenticalSpanIndex]) == null ? void 0 : _a.end) === span.start) {
69
+ __privateGet(this, _RichTextFieldBuilder_instances, last_get).spans[lastIdenticalSpanIndex].end = span.end;
70
+ } else {
71
+ __privateGet(this, _RichTextFieldBuilder_instances, last_get).spans.push(span);
72
+ }
73
+ }
74
+ appendText(text) {
75
+ if (!this.isTextNode(__privateGet(this, _RichTextFieldBuilder_instances, last_get))) {
76
+ throw new PrismicRichTextError("Cannot append text to non-text last node");
77
+ }
78
+ if (__privateGet(this, _RichTextFieldBuilder_instances, last_get).text) {
79
+ __privateGet(this, _RichTextFieldBuilder_instances, last_get).text += text;
80
+ } else {
81
+ __privateGet(this, _RichTextFieldBuilder_instances, last_get).text = text.trimStart();
82
+ }
83
+ }
84
+ build() {
85
+ this.cleanupLast();
86
+ return __privateGet(this, _nodes);
87
+ }
88
+ /**
89
+ * Cleans up the current last node.
90
+ */
91
+ cleanupLast() {
92
+ if (this.isTextNode(__privateGet(this, _RichTextFieldBuilder_instances, last_get))) {
93
+ __privateGet(this, _RichTextFieldBuilder_instances, last_get).text = __privateGet(this, _RichTextFieldBuilder_instances, last_get).text.trimEnd();
94
+ }
95
+ }
96
+ /**
97
+ * Determines if a node is a text node.
98
+ *
99
+ * @param node - rich text node to check.
100
+ *
101
+ * @returns `true` if `node` is a text node, `false` otherwise.
102
+ */
103
+ isTextNode(node) {
104
+ return !!node && node.type !== "image" && node.type !== "embed";
105
+ }
106
+ }
107
+ _nodes = new WeakMap();
108
+ _RichTextFieldBuilder_instances = new WeakSet();
109
+ last_get = function() {
110
+ return __privateGet(this, _nodes)[__privateGet(this, _nodes).length - 1];
111
+ };
112
+ export {
113
+ RichTextFieldBuilder
114
+ };
115
+ //# sourceMappingURL=RichTextFieldBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RichTextFieldBuilder.js","sources":["../../../src/lib/RichTextFieldBuilder.ts"],"sourcesContent":["import type {\n\tRTInlineNode,\n\tRTLinkNode,\n\tRTNode,\n\tRTTextNode,\n\tRichTextField,\n} from \"@prismicio/client\"\n\nimport { PrismicRichTextError } from \"../errors/PrismicRichTextError\"\n\n/**\n * Omits keys from a type, distributing the operation over a union.\n *\n * Taken from the `type-fest` package.\n *\n * @see https://github.com/sindresorhus/type-fest/blob/8a45ba048767aaffcebc7d190172d814a739feb0/source/distributed-omit.d.ts\n */\ntype DistributedOmit<\n\tObjectType,\n\tKeyType extends keyof ObjectType,\n> = ObjectType extends unknown ? Omit<ObjectType, KeyType> : never\n\n/**\n * An inline node without its `start` and `end` properties.\n */\nexport type RTPartialInlineNode = DistributedOmit<RTInlineNode, \"start\" | \"end\">\n\nexport class RichTextFieldBuilder {\n\t#nodes: RTNode[] = []\n\n\tget #last(): RTNode | undefined {\n\t\treturn this.#nodes[this.#nodes.length - 1]\n\t}\n\n\tappendNode(node: RTNode): void {\n\t\tthis.cleanupLast()\n\n\t\tthis.#nodes.push(node)\n\t}\n\n\tappendTextNode(\n\t\ttype: RTTextNode[\"type\"],\n\t\tdirection: \"ltr\" | \"rtl\" = \"ltr\",\n\t): void {\n\t\tthis.appendNode({\n\t\t\ttype,\n\t\t\ttext: \"\",\n\t\t\tspans: [],\n\t\t\tdirection,\n\t\t})\n\t}\n\n\tappendSpan(span: RTInlineNode): void\n\tappendSpan(partialSpan: RTPartialInlineNode, length: number): void\n\tappendSpan(\n\t\tspanOrPartialSpan: RTInlineNode | RTPartialInlineNode,\n\t\tlength?: number,\n\t): void {\n\t\tif (!this.isTextNode(this.#last)) {\n\t\t\tthrow new PrismicRichTextError(\"Cannot add span to non-text last node\")\n\t\t}\n\n\t\tlet span: RTInlineNode\n\t\tif (\"start\" in spanOrPartialSpan && \"end\" in spanOrPartialSpan) {\n\t\t\tspan = spanOrPartialSpan\n\t\t} else {\n\t\t\tconst lastLength = this.#last.text.length\n\n\t\t\tspan = {\n\t\t\t\t...spanOrPartialSpan,\n\t\t\t\tstart: lastLength,\n\t\t\t\tend: lastLength + length!,\n\t\t\t}\n\t\t}\n\n\t\tlet lastIdenticalSpanIndex = -1\n\t\tfor (let i = this.#last.spans.length - 1; i >= 0; i--) {\n\t\t\tconst lastSpan = this.#last.spans[i]\n\n\t\t\tif (span.type === \"strong\" || span.type === \"em\") {\n\t\t\t\tif (lastSpan.type === span.type) {\n\t\t\t\t\tlastIdenticalSpanIndex = i\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t} else if (span.type === \"label\") {\n\t\t\t\tif (\n\t\t\t\t\tlastSpan.type === \"label\" &&\n\t\t\t\t\tlastSpan.data.label === span.data.label\n\t\t\t\t) {\n\t\t\t\t\tlastIdenticalSpanIndex = i\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t} else if (span.type === \"hyperlink\") {\n\t\t\t\tif (lastSpan.type === \"hyperlink\") {\n\t\t\t\t\t// Check that all data fields are the same. Since it's not a\n\t\t\t\t\t// deep equal operation, this doesn't guarantee a perfect\n\t\t\t\t\t// match with content relationship.\n\t\t\t\t\tconst isSameLink = (\n\t\t\t\t\t\tObject.entries(span.data) as [keyof RTLinkNode[\"data\"], unknown][]\n\t\t\t\t\t).every(([key, value]) => lastSpan.data[key] === value)\n\n\t\t\t\t\tif (isSameLink) {\n\t\t\t\t\t\tlastIdenticalSpanIndex = i\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Ignore empty spans.\n\t\tif (span.start === span.end) {\n\t\t\treturn\n\t\t}\n\n\t\t// Prefer to extend the last span of the same type end\n\t\t// position if it ends at the start of the new span.\n\t\tif (this.#last.spans[lastIdenticalSpanIndex]?.end === span.start) {\n\t\t\tthis.#last.spans[lastIdenticalSpanIndex].end = span.end\n\t\t} else {\n\t\t\tthis.#last.spans.push(span)\n\t\t}\n\t}\n\n\tappendText(text: string): void {\n\t\tif (!this.isTextNode(this.#last)) {\n\t\t\tthrow new PrismicRichTextError(\"Cannot append text to non-text last node\")\n\t\t}\n\n\t\tif (this.#last.text) {\n\t\t\tthis.#last.text += text\n\t\t} else {\n\t\t\tthis.#last.text = text.trimStart()\n\t\t}\n\t}\n\n\tbuild(): RichTextField {\n\t\t// Ensure that the last text node is trimmed.\n\t\tthis.cleanupLast()\n\n\t\t// Because `RichTextField` is defined as a non-empty\n\t\t// array, we have to cast `RTNode[]` to `RichTextField`.\n\t\treturn this.#nodes as RichTextField\n\t}\n\n\t/**\n\t * Cleans up the current last node.\n\t */\n\tprivate cleanupLast(): void {\n\t\tif (this.isTextNode(this.#last)) {\n\t\t\tthis.#last.text = this.#last.text.trimEnd()\n\t\t}\n\t}\n\n\t/**\n\t * Determines if a node is a text node.\n\t *\n\t * @param node - rich text node to check.\n\t *\n\t * @returns `true` if `node` is a text node, `false` otherwise.\n\t */\n\tprivate isTextNode(node?: RTNode): node is RTTextNode {\n\t\treturn !!node && node.type !== \"image\" && node.type !== \"embed\"\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;MA2Ba,qBAAoB;AAAA;;AAChC,+BAAmB,CAAA;AAAA;AAAA,EAMnB,WAAW,MAAY;AACtB,SAAK,YAAW;AAEX,uBAAA,QAAO,KAAK,IAAI;AAAA,EACtB;AAAA,EAEA,eACC,MACA,YAA2B,OAAK;AAEhC,SAAK,WAAW;AAAA,MACf;AAAA,MACA,MAAM;AAAA,MACN,OAAO,CAAE;AAAA,MACT;AAAA,IAAA,CACA;AAAA,EACF;AAAA,EAIA,WACC,mBACA,QAAe;;AAEf,QAAI,CAAC,KAAK,WAAW,mBAAK,0CAAK,GAAG;AAC3B,YAAA,IAAI,qBAAqB,uCAAuC;AAAA,IACvE;AAEI,QAAA;AACA,QAAA,WAAW,qBAAqB,SAAS,mBAAmB;AACxD,aAAA;AAAA,IAAA,OACD;AACA,YAAA,aAAa,mBAAK,2CAAM,KAAK;AAE5B,aAAA;AAAA,QACN,GAAG;AAAA,QACH,OAAO;AAAA,QACP,KAAK,aAAa;AAAA,MAAA;AAAA,IAEpB;AAEA,QAAI,yBAAyB;AACpB,aAAA,IAAI,mBAAK,2CAAM,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;AACtD,YAAM,WAAW,mBAAK,2CAAM,MAAM,CAAC;AAEnC,UAAI,KAAK,SAAS,YAAY,KAAK,SAAS,MAAM;AAC7C,YAAA,SAAS,SAAS,KAAK,MAAM;AACP,mCAAA;AACzB;AAAA,QACD;AAAA,MAAA,WACU,KAAK,SAAS,SAAS;AAEhC,YAAA,SAAS,SAAS,WAClB,SAAS,KAAK,UAAU,KAAK,KAAK,OACjC;AACwB,mCAAA;AACzB;AAAA,QACD;AAAA,MAAA,WACU,KAAK,SAAS,aAAa;AACjC,YAAA,SAAS,SAAS,aAAa;AAIlC,gBAAM,aACL,OAAO,QAAQ,KAAK,IAAI,EACvB,MAAM,CAAC,CAAC,KAAK,KAAK,MAAM,SAAS,KAAK,GAAG,MAAM,KAAK;AAEtD,cAAI,YAAY;AACU,qCAAA;AACzB;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAGI,QAAA,KAAK,UAAU,KAAK,KAAK;AAC5B;AAAA,IACD;AAIA,UAAI,wBAAK,2CAAM,MAAM,sBAAsB,MAAvC,mBAA0C,SAAQ,KAAK,OAAO;AACjE,yBAAK,2CAAM,MAAM,sBAAsB,EAAE,MAAM,KAAK;AAAA,IAAA,OAC9C;AACD,yBAAA,2CAAM,MAAM,KAAK,IAAI;AAAA,IAC3B;AAAA,EACD;AAAA,EAEA,WAAW,MAAY;AACtB,QAAI,CAAC,KAAK,WAAW,mBAAK,0CAAK,GAAG;AAC3B,YAAA,IAAI,qBAAqB,0CAA0C;AAAA,IAC1E;AAEI,QAAA,mBAAK,2CAAM,MAAM;AACpB,yBAAK,2CAAM,QAAQ;AAAA,IAAA,OACb;AACD,yBAAA,2CAAM,OAAO,KAAK,UAAS;AAAA,IACjC;AAAA,EACD;AAAA,EAEA,QAAK;AAEJ,SAAK,YAAW;AAIhB,WAAO,mBAAK;AAAA,EACb;AAAA;AAAA;AAAA;AAAA,EAKQ,cAAW;AAClB,QAAI,KAAK,WAAW,mBAAK,0CAAK,GAAG;AAChC,yBAAK,2CAAM,OAAO,mBAAK,2CAAM,KAAK;IACnC;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASQ,WAAW,MAAa;AAC/B,WAAO,CAAC,CAAC,QAAQ,KAAK,SAAS,WAAW,KAAK,SAAS;AAAA,EACzD;AACA;AAvIA;;AAEI,WAAK,WAAA;AACR,SAAO,mBAAK,QAAO,mBAAK,QAAO,SAAS,CAAC;AAC1C;"}
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const client = require("@prismicio/client");
4
+ const getAllowedNodeTypes = (model) => {
5
+ var _a;
6
+ const allowedNodeTypes = [];
7
+ if (model.config) {
8
+ if ("multi" in model.config && model.config.multi) {
9
+ allowedNodeTypes.push(...model.config.multi.split(","));
10
+ } else if ("single" in model.config && model.config.single) {
11
+ allowedNodeTypes.push(...model.config.single.split(","));
12
+ }
13
+ if ((_a = model.config.labels) == null ? void 0 : _a.length) {
14
+ allowedNodeTypes.push("label");
15
+ }
16
+ }
17
+ return allowedNodeTypes;
18
+ };
19
+ const filterImageNode = (node, model) => {
20
+ var _a, _b;
21
+ if (!((_a = model.config) == null ? void 0 : _a.allowTargetBlank) && ((_b = node.linkTo) == null ? void 0 : _b.link_type) === client.LinkType.Web) {
22
+ return {
23
+ ...node,
24
+ linkTo: {
25
+ ...node.linkTo,
26
+ target: void 0
27
+ }
28
+ };
29
+ }
30
+ return node;
31
+ };
32
+ const filterTextNode = (node, model, allowedNodeTypes) => {
33
+ var _a, _b, _c;
34
+ const filteredNode = {
35
+ ...node,
36
+ spans: []
37
+ };
38
+ for (let i = 0; i < node.spans.length; i++) {
39
+ const span = node.spans[i];
40
+ if (allowedNodeTypes.includes(span.type)) {
41
+ if (span.type === client.RichTextNodeType.hyperlink) {
42
+ if (!((_a = model.config) == null ? void 0 : _a.allowTargetBlank) && span.data.link_type === client.LinkType.Web) {
43
+ filteredNode.spans.push({
44
+ ...span,
45
+ data: {
46
+ ...span.data,
47
+ target: void 0
48
+ }
49
+ });
50
+ } else {
51
+ filteredNode.spans.push(span);
52
+ }
53
+ } else if (span.type === client.RichTextNodeType.label) {
54
+ if ((_c = (_b = model.config) == null ? void 0 : _b.labels) == null ? void 0 : _c.includes(span.data.label)) {
55
+ filteredNode.spans.push(span);
56
+ }
57
+ } else {
58
+ filteredNode.spans.push(span);
59
+ }
60
+ }
61
+ }
62
+ return filteredNode;
63
+ };
64
+ const filterRichTextField = (richTextField, model) => {
65
+ const nodes = [];
66
+ const allowedNodeTypes = getAllowedNodeTypes(model);
67
+ for (
68
+ let i = 0;
69
+ // Only process the first node if it's a "single" node rich text type
70
+ i < (model.config && "multi" in model.config ? richTextField.length : 1);
71
+ i++
72
+ ) {
73
+ const node = richTextField[i];
74
+ if (allowedNodeTypes.includes(node.type)) {
75
+ if (node.type === client.RichTextNodeType.image) {
76
+ nodes.push(filterImageNode(node, model));
77
+ } else if (node.type === client.RichTextNodeType.embed) {
78
+ nodes.push(node);
79
+ } else {
80
+ nodes.push(filterTextNode(node, model, allowedNodeTypes));
81
+ }
82
+ }
83
+ }
84
+ return nodes;
85
+ };
86
+ exports.filterRichTextField = filterRichTextField;
87
+ //# sourceMappingURL=filterRichTextField.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filterRichTextField.cjs","sources":["../../../src/lib/filterRichTextField.ts"],"sourcesContent":["import type {\n\tCustomTypeModelRichTextField,\n\tRTImageNode,\n\tRTNode,\n\tRTTextNode,\n\tRichTextField,\n\tRichTextNodeTypes,\n\tTitleField,\n} from \"@prismicio/client\"\nimport { LinkType, RichTextNodeType } from \"@prismicio/client\"\n\n/**\n * Get allowed nodes types from a rich text or title field custom type model.\n *\n * @param model - A rich text or title field custom type model.\n *\n * @returns An array of allowed nodes types.\n */\nconst getAllowedNodeTypes = (\n\tmodel: CustomTypeModelRichTextField,\n): RichTextNodeTypes[] => {\n\tconst allowedNodeTypes: RichTextNodeTypes[] = [] // An empty array means no nodes are allowed by default.\n\n\tif (model.config) {\n\t\tif (\"multi\" in model.config && model.config.multi) {\n\t\t\tallowedNodeTypes.push(\n\t\t\t\t...(model.config.multi.split(\",\") as RichTextNodeTypes[]),\n\t\t\t)\n\t\t} else if (\"single\" in model.config && model.config.single) {\n\t\t\tallowedNodeTypes.push(\n\t\t\t\t...(model.config.single.split(\",\") as RichTextNodeTypes[]),\n\t\t\t)\n\t\t}\n\n\t\tif (model.config.labels?.length) {\n\t\t\tallowedNodeTypes.push(\"label\")\n\t\t}\n\t}\n\n\treturn allowedNodeTypes\n}\n\n/**\n * Filter an image node based on given model.\n *\n * @param node - An image node to filter.\n * @param model - A rich text or title field custom type model.\n *\n * @returns A filtered image node based on the given model.\n */\nconst filterImageNode = (\n\tnode: RTImageNode,\n\tmodel: CustomTypeModelRichTextField,\n): RTImageNode => {\n\tif (\n\t\t!model.config?.allowTargetBlank &&\n\t\tnode.linkTo?.link_type === LinkType.Web\n\t) {\n\t\treturn {\n\t\t\t...node,\n\t\t\tlinkTo: {\n\t\t\t\t...node.linkTo,\n\t\t\t\ttarget: undefined,\n\t\t\t},\n\t\t}\n\t}\n\n\treturn node\n}\n\n/**\n * Filter a text node based on given model.\n *\n * @param node - A text node to filter.\n * @param model - A rich text or title field custom type model.\n * @param allowedNodeTypes - An array of allowed nodes types.\n *\n * @returns A filtered text node based on the given model.\n */\nconst filterTextNode = (\n\tnode: RTTextNode,\n\tmodel: CustomTypeModelRichTextField,\n\tallowedNodeTypes: RichTextNodeTypes[],\n): RTTextNode => {\n\tconst filteredNode: RTTextNode = {\n\t\t...node,\n\t\tspans: [],\n\t}\n\n\tfor (let i = 0; i < node.spans.length; i++) {\n\t\tconst span = node.spans[i]\n\n\t\tif (allowedNodeTypes.includes(span.type)) {\n\t\t\tif (span.type === RichTextNodeType.hyperlink) {\n\t\t\t\tif (\n\t\t\t\t\t!model.config?.allowTargetBlank &&\n\t\t\t\t\tspan.data.link_type === LinkType.Web\n\t\t\t\t) {\n\t\t\t\t\tfilteredNode.spans.push({\n\t\t\t\t\t\t...span,\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t...span.data,\n\t\t\t\t\t\t\ttarget: undefined,\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tfilteredNode.spans.push(span)\n\t\t\t\t}\n\t\t\t} else if (span.type === RichTextNodeType.label) {\n\t\t\t\tif (model.config?.labels?.includes(span.data.label)) {\n\t\t\t\t\tfilteredNode.spans.push(span)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfilteredNode.spans.push(span)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn filteredNode\n}\n\n/**\n * Filter a rich text field based on given model.\n *\n * @param richTextField - A rich text or title field from Prismic.\n * @param model - A rich text or title field custom type model.\n *\n * @returns A rich text or title field filtered based on the given model.\n */\nexport const filterRichTextField = <Field extends RichTextField | TitleField>(\n\trichTextField: Field,\n\tmodel: CustomTypeModelRichTextField,\n): Field => {\n\tconst nodes: RTNode[] = []\n\n\tconst allowedNodeTypes = getAllowedNodeTypes(model)\n\n\tfor (\n\t\tlet i = 0;\n\t\t// Only process the first node if it's a \"single\" node rich text type\n\t\ti < (model.config && \"multi\" in model.config ? richTextField.length : 1);\n\t\ti++\n\t) {\n\t\tconst node = richTextField[i]\n\n\t\tif (allowedNodeTypes.includes(node.type)) {\n\t\t\tif (node.type === RichTextNodeType.image) {\n\t\t\t\tnodes.push(filterImageNode(node, model))\n\t\t\t} else if (node.type === RichTextNodeType.embed) {\n\t\t\t\tnodes.push(node)\n\t\t\t} else {\n\t\t\t\tnodes.push(filterTextNode(node, model, allowedNodeTypes))\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nodes as Field\n}\n"],"names":["LinkType","RichTextNodeType"],"mappings":";;;AAkBA,MAAM,sBAAsB,CAC3B,UACwB;;AACxB,QAAM,mBAAwC,CAAA;AAE9C,MAAI,MAAM,QAAQ;AACjB,QAAI,WAAW,MAAM,UAAU,MAAM,OAAO,OAAO;AAClD,uBAAiB,KAChB,GAAI,MAAM,OAAO,MAAM,MAAM,GAAG,CAAyB;AAAA,IAAA,WAEhD,YAAY,MAAM,UAAU,MAAM,OAAO,QAAQ;AAC3D,uBAAiB,KAChB,GAAI,MAAM,OAAO,OAAO,MAAM,GAAG,CAAyB;AAAA,IAE5D;AAEI,SAAA,WAAM,OAAO,WAAb,mBAAqB,QAAQ;AAChC,uBAAiB,KAAK,OAAO;AAAA,IAC9B;AAAA,EACD;AAEO,SAAA;AACR;AAUA,MAAM,kBAAkB,CACvB,MACA,UACgB;;AAEf,MAAA,GAAC,WAAM,WAAN,mBAAc,uBACf,UAAK,WAAL,mBAAa,eAAcA,gBAAS,KACnC;AACM,WAAA;AAAA,MACN,GAAG;AAAA,MACH,QAAQ;AAAA,QACP,GAAG,KAAK;AAAA,QACR,QAAQ;AAAA,MACR;AAAA,IAAA;AAAA,EAEH;AAEO,SAAA;AACR;AAWA,MAAM,iBAAiB,CACtB,MACA,OACA,qBACe;;AACf,QAAM,eAA2B;AAAA,IAChC,GAAG;AAAA,IACH,OAAO,CAAE;AAAA,EAAA;AAGV,WAAS,IAAI,GAAG,IAAI,KAAK,MAAM,QAAQ,KAAK;AACrC,UAAA,OAAO,KAAK,MAAM,CAAC;AAEzB,QAAI,iBAAiB,SAAS,KAAK,IAAI,GAAG;AACrC,UAAA,KAAK,SAASC,OAAA,iBAAiB,WAAW;AAE5C,YAAA,GAAC,WAAM,WAAN,mBAAc,qBACf,KAAK,KAAK,cAAcD,gBAAS,KAChC;AACD,uBAAa,MAAM,KAAK;AAAA,YACvB,GAAG;AAAA,YACH,MAAM;AAAA,cACL,GAAG,KAAK;AAAA,cACR,QAAQ;AAAA,YACR;AAAA,UAAA,CACD;AAAA,QAAA,OACK;AACO,uBAAA,MAAM,KAAK,IAAI;AAAA,QAC7B;AAAA,MACU,WAAA,KAAK,SAASC,OAAAA,iBAAiB,OAAO;AAChD,aAAI,iBAAM,WAAN,mBAAc,WAAd,mBAAsB,SAAS,KAAK,KAAK,QAAQ;AACvC,uBAAA,MAAM,KAAK,IAAI;AAAA,QAC7B;AAAA,MAAA,OACM;AACO,qBAAA,MAAM,KAAK,IAAI;AAAA,MAC7B;AAAA,IACD;AAAA,EACD;AAEO,SAAA;AACR;AAUa,MAAA,sBAAsB,CAClC,eACA,UACU;AACV,QAAM,QAAkB,CAAA;AAElB,QAAA,mBAAmB,oBAAoB,KAAK;AAElD;AAAA,QACK,IAAI;AAAA;AAAA,IAER,KAAK,MAAM,UAAU,WAAW,MAAM,SAAS,cAAc,SAAS;AAAA,IACtE;AAAA,IACC;AACK,UAAA,OAAO,cAAc,CAAC;AAE5B,QAAI,iBAAiB,SAAS,KAAK,IAAI,GAAG;AACrC,UAAA,KAAK,SAASA,OAAA,iBAAiB,OAAO;AACzC,cAAM,KAAK,gBAAgB,MAAM,KAAK,CAAC;AAAA,MAC7B,WAAA,KAAK,SAASA,OAAAA,iBAAiB,OAAO;AAChD,cAAM,KAAK,IAAI;AAAA,MAAA,OACT;AACN,cAAM,KAAK,eAAe,MAAM,OAAO,gBAAgB,CAAC;AAAA,MACzD;AAAA,IACD;AAAA,EACD;AAEO,SAAA;AACR;;"}
@@ -0,0 +1,10 @@
1
+ import type { CustomTypeModelRichTextField, RichTextField, TitleField } from "@prismicio/client";
2
+ /**
3
+ * Filter a rich text field based on given model.
4
+ *
5
+ * @param richTextField - A rich text or title field from Prismic.
6
+ * @param model - A rich text or title field custom type model.
7
+ *
8
+ * @returns A rich text or title field filtered based on the given model.
9
+ */
10
+ export declare const filterRichTextField: <Field extends RichTextField | TitleField>(richTextField: Field, model: CustomTypeModelRichTextField) => Field;
@@ -0,0 +1,87 @@
1
+ import { RichTextNodeType, LinkType } from "@prismicio/client";
2
+ const getAllowedNodeTypes = (model) => {
3
+ var _a;
4
+ const allowedNodeTypes = [];
5
+ if (model.config) {
6
+ if ("multi" in model.config && model.config.multi) {
7
+ allowedNodeTypes.push(...model.config.multi.split(","));
8
+ } else if ("single" in model.config && model.config.single) {
9
+ allowedNodeTypes.push(...model.config.single.split(","));
10
+ }
11
+ if ((_a = model.config.labels) == null ? void 0 : _a.length) {
12
+ allowedNodeTypes.push("label");
13
+ }
14
+ }
15
+ return allowedNodeTypes;
16
+ };
17
+ const filterImageNode = (node, model) => {
18
+ var _a, _b;
19
+ if (!((_a = model.config) == null ? void 0 : _a.allowTargetBlank) && ((_b = node.linkTo) == null ? void 0 : _b.link_type) === LinkType.Web) {
20
+ return {
21
+ ...node,
22
+ linkTo: {
23
+ ...node.linkTo,
24
+ target: void 0
25
+ }
26
+ };
27
+ }
28
+ return node;
29
+ };
30
+ const filterTextNode = (node, model, allowedNodeTypes) => {
31
+ var _a, _b, _c;
32
+ const filteredNode = {
33
+ ...node,
34
+ spans: []
35
+ };
36
+ for (let i = 0; i < node.spans.length; i++) {
37
+ const span = node.spans[i];
38
+ if (allowedNodeTypes.includes(span.type)) {
39
+ if (span.type === RichTextNodeType.hyperlink) {
40
+ if (!((_a = model.config) == null ? void 0 : _a.allowTargetBlank) && span.data.link_type === LinkType.Web) {
41
+ filteredNode.spans.push({
42
+ ...span,
43
+ data: {
44
+ ...span.data,
45
+ target: void 0
46
+ }
47
+ });
48
+ } else {
49
+ filteredNode.spans.push(span);
50
+ }
51
+ } else if (span.type === RichTextNodeType.label) {
52
+ if ((_c = (_b = model.config) == null ? void 0 : _b.labels) == null ? void 0 : _c.includes(span.data.label)) {
53
+ filteredNode.spans.push(span);
54
+ }
55
+ } else {
56
+ filteredNode.spans.push(span);
57
+ }
58
+ }
59
+ }
60
+ return filteredNode;
61
+ };
62
+ const filterRichTextField = (richTextField, model) => {
63
+ const nodes = [];
64
+ const allowedNodeTypes = getAllowedNodeTypes(model);
65
+ for (
66
+ let i = 0;
67
+ // Only process the first node if it's a "single" node rich text type
68
+ i < (model.config && "multi" in model.config ? richTextField.length : 1);
69
+ i++
70
+ ) {
71
+ const node = richTextField[i];
72
+ if (allowedNodeTypes.includes(node.type)) {
73
+ if (node.type === RichTextNodeType.image) {
74
+ nodes.push(filterImageNode(node, model));
75
+ } else if (node.type === RichTextNodeType.embed) {
76
+ nodes.push(node);
77
+ } else {
78
+ nodes.push(filterTextNode(node, model, allowedNodeTypes));
79
+ }
80
+ }
81
+ }
82
+ return nodes;
83
+ };
84
+ export {
85
+ filterRichTextField
86
+ };
87
+ //# sourceMappingURL=filterRichTextField.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filterRichTextField.js","sources":["../../../src/lib/filterRichTextField.ts"],"sourcesContent":["import type {\n\tCustomTypeModelRichTextField,\n\tRTImageNode,\n\tRTNode,\n\tRTTextNode,\n\tRichTextField,\n\tRichTextNodeTypes,\n\tTitleField,\n} from \"@prismicio/client\"\nimport { LinkType, RichTextNodeType } from \"@prismicio/client\"\n\n/**\n * Get allowed nodes types from a rich text or title field custom type model.\n *\n * @param model - A rich text or title field custom type model.\n *\n * @returns An array of allowed nodes types.\n */\nconst getAllowedNodeTypes = (\n\tmodel: CustomTypeModelRichTextField,\n): RichTextNodeTypes[] => {\n\tconst allowedNodeTypes: RichTextNodeTypes[] = [] // An empty array means no nodes are allowed by default.\n\n\tif (model.config) {\n\t\tif (\"multi\" in model.config && model.config.multi) {\n\t\t\tallowedNodeTypes.push(\n\t\t\t\t...(model.config.multi.split(\",\") as RichTextNodeTypes[]),\n\t\t\t)\n\t\t} else if (\"single\" in model.config && model.config.single) {\n\t\t\tallowedNodeTypes.push(\n\t\t\t\t...(model.config.single.split(\",\") as RichTextNodeTypes[]),\n\t\t\t)\n\t\t}\n\n\t\tif (model.config.labels?.length) {\n\t\t\tallowedNodeTypes.push(\"label\")\n\t\t}\n\t}\n\n\treturn allowedNodeTypes\n}\n\n/**\n * Filter an image node based on given model.\n *\n * @param node - An image node to filter.\n * @param model - A rich text or title field custom type model.\n *\n * @returns A filtered image node based on the given model.\n */\nconst filterImageNode = (\n\tnode: RTImageNode,\n\tmodel: CustomTypeModelRichTextField,\n): RTImageNode => {\n\tif (\n\t\t!model.config?.allowTargetBlank &&\n\t\tnode.linkTo?.link_type === LinkType.Web\n\t) {\n\t\treturn {\n\t\t\t...node,\n\t\t\tlinkTo: {\n\t\t\t\t...node.linkTo,\n\t\t\t\ttarget: undefined,\n\t\t\t},\n\t\t}\n\t}\n\n\treturn node\n}\n\n/**\n * Filter a text node based on given model.\n *\n * @param node - A text node to filter.\n * @param model - A rich text or title field custom type model.\n * @param allowedNodeTypes - An array of allowed nodes types.\n *\n * @returns A filtered text node based on the given model.\n */\nconst filterTextNode = (\n\tnode: RTTextNode,\n\tmodel: CustomTypeModelRichTextField,\n\tallowedNodeTypes: RichTextNodeTypes[],\n): RTTextNode => {\n\tconst filteredNode: RTTextNode = {\n\t\t...node,\n\t\tspans: [],\n\t}\n\n\tfor (let i = 0; i < node.spans.length; i++) {\n\t\tconst span = node.spans[i]\n\n\t\tif (allowedNodeTypes.includes(span.type)) {\n\t\t\tif (span.type === RichTextNodeType.hyperlink) {\n\t\t\t\tif (\n\t\t\t\t\t!model.config?.allowTargetBlank &&\n\t\t\t\t\tspan.data.link_type === LinkType.Web\n\t\t\t\t) {\n\t\t\t\t\tfilteredNode.spans.push({\n\t\t\t\t\t\t...span,\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t...span.data,\n\t\t\t\t\t\t\ttarget: undefined,\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tfilteredNode.spans.push(span)\n\t\t\t\t}\n\t\t\t} else if (span.type === RichTextNodeType.label) {\n\t\t\t\tif (model.config?.labels?.includes(span.data.label)) {\n\t\t\t\t\tfilteredNode.spans.push(span)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfilteredNode.spans.push(span)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn filteredNode\n}\n\n/**\n * Filter a rich text field based on given model.\n *\n * @param richTextField - A rich text or title field from Prismic.\n * @param model - A rich text or title field custom type model.\n *\n * @returns A rich text or title field filtered based on the given model.\n */\nexport const filterRichTextField = <Field extends RichTextField | TitleField>(\n\trichTextField: Field,\n\tmodel: CustomTypeModelRichTextField,\n): Field => {\n\tconst nodes: RTNode[] = []\n\n\tconst allowedNodeTypes = getAllowedNodeTypes(model)\n\n\tfor (\n\t\tlet i = 0;\n\t\t// Only process the first node if it's a \"single\" node rich text type\n\t\ti < (model.config && \"multi\" in model.config ? richTextField.length : 1);\n\t\ti++\n\t) {\n\t\tconst node = richTextField[i]\n\n\t\tif (allowedNodeTypes.includes(node.type)) {\n\t\t\tif (node.type === RichTextNodeType.image) {\n\t\t\t\tnodes.push(filterImageNode(node, model))\n\t\t\t} else if (node.type === RichTextNodeType.embed) {\n\t\t\t\tnodes.push(node)\n\t\t\t} else {\n\t\t\t\tnodes.push(filterTextNode(node, model, allowedNodeTypes))\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nodes as Field\n}\n"],"names":[],"mappings":";AAkBA,MAAM,sBAAsB,CAC3B,UACwB;;AACxB,QAAM,mBAAwC,CAAA;AAE9C,MAAI,MAAM,QAAQ;AACjB,QAAI,WAAW,MAAM,UAAU,MAAM,OAAO,OAAO;AAClD,uBAAiB,KAChB,GAAI,MAAM,OAAO,MAAM,MAAM,GAAG,CAAyB;AAAA,IAAA,WAEhD,YAAY,MAAM,UAAU,MAAM,OAAO,QAAQ;AAC3D,uBAAiB,KAChB,GAAI,MAAM,OAAO,OAAO,MAAM,GAAG,CAAyB;AAAA,IAE5D;AAEI,SAAA,WAAM,OAAO,WAAb,mBAAqB,QAAQ;AAChC,uBAAiB,KAAK,OAAO;AAAA,IAC9B;AAAA,EACD;AAEO,SAAA;AACR;AAUA,MAAM,kBAAkB,CACvB,MACA,UACgB;;AAEf,MAAA,GAAC,WAAM,WAAN,mBAAc,uBACf,UAAK,WAAL,mBAAa,eAAc,SAAS,KACnC;AACM,WAAA;AAAA,MACN,GAAG;AAAA,MACH,QAAQ;AAAA,QACP,GAAG,KAAK;AAAA,QACR,QAAQ;AAAA,MACR;AAAA,IAAA;AAAA,EAEH;AAEO,SAAA;AACR;AAWA,MAAM,iBAAiB,CACtB,MACA,OACA,qBACe;;AACf,QAAM,eAA2B;AAAA,IAChC,GAAG;AAAA,IACH,OAAO,CAAE;AAAA,EAAA;AAGV,WAAS,IAAI,GAAG,IAAI,KAAK,MAAM,QAAQ,KAAK;AACrC,UAAA,OAAO,KAAK,MAAM,CAAC;AAEzB,QAAI,iBAAiB,SAAS,KAAK,IAAI,GAAG;AACrC,UAAA,KAAK,SAAS,iBAAiB,WAAW;AAE5C,YAAA,GAAC,WAAM,WAAN,mBAAc,qBACf,KAAK,KAAK,cAAc,SAAS,KAChC;AACD,uBAAa,MAAM,KAAK;AAAA,YACvB,GAAG;AAAA,YACH,MAAM;AAAA,cACL,GAAG,KAAK;AAAA,cACR,QAAQ;AAAA,YACR;AAAA,UAAA,CACD;AAAA,QAAA,OACK;AACO,uBAAA,MAAM,KAAK,IAAI;AAAA,QAC7B;AAAA,MACU,WAAA,KAAK,SAAS,iBAAiB,OAAO;AAChD,aAAI,iBAAM,WAAN,mBAAc,WAAd,mBAAsB,SAAS,KAAK,KAAK,QAAQ;AACvC,uBAAA,MAAM,KAAK,IAAI;AAAA,QAC7B;AAAA,MAAA,OACM;AACO,qBAAA,MAAM,KAAK,IAAI;AAAA,MAC7B;AAAA,IACD;AAAA,EACD;AAEO,SAAA;AACR;AAUa,MAAA,sBAAsB,CAClC,eACA,UACU;AACV,QAAM,QAAkB,CAAA;AAElB,QAAA,mBAAmB,oBAAoB,KAAK;AAElD;AAAA,QACK,IAAI;AAAA;AAAA,IAER,KAAK,MAAM,UAAU,WAAW,MAAM,SAAS,cAAc,SAAS;AAAA,IACtE;AAAA,IACC;AACK,UAAA,OAAO,cAAc,CAAC;AAE5B,QAAI,iBAAiB,SAAS,KAAK,IAAI,GAAG;AACrC,UAAA,KAAK,SAAS,iBAAiB,OAAO;AACzC,cAAM,KAAK,gBAAgB,MAAM,KAAK,CAAC;AAAA,MAC7B,WAAA,KAAK,SAAS,iBAAiB,OAAO;AAChD,cAAM,KAAK,IAAI;AAAA,MAAA,OACT;AACN,cAAM,KAAK,eAAe,MAAM,OAAO,gBAAgB,CAAC;AAAA,MACzD;AAAA,IACD;AAAA,EACD;AAEO,SAAA;AACR;"}
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const client = require("@prismicio/client");
4
+ const hastUtilToHtml = require("hast-util-to-html");
5
+ const PrismicRichTextSerializerError = require("../errors/PrismicRichTextSerializerError.cjs");
6
+ const serializeImage = (node) => {
7
+ var _a, _b, _c, _d, _e;
8
+ const src = (_a = node.properties) == null ? void 0 : _a.src;
9
+ if (!src) {
10
+ throw new PrismicRichTextSerializerError.PrismicRichTextSerializerError("Element of type `img` is missing an `src` attribute");
11
+ }
12
+ const url = new URL(src, "https://noop.com");
13
+ let width = (_b = node.properties) == null ? void 0 : _b.width;
14
+ let height = (_c = node.properties) == null ? void 0 : _c.height;
15
+ let x = 0;
16
+ let y = 0;
17
+ let zoom = 1;
18
+ if (url.hostname === "images.prismic.io") {
19
+ if (url.searchParams.has("w")) {
20
+ width = Number(url.searchParams.get("w"));
21
+ }
22
+ if (url.searchParams.has("h")) {
23
+ height = Number(url.searchParams.get("h"));
24
+ }
25
+ if (url.searchParams.has("rect")) {
26
+ const [rectX, rextY, rectW, _rectH] = url.searchParams.get("rect").split(",");
27
+ x = Number(rectX);
28
+ y = Number(rextY);
29
+ if (width) {
30
+ zoom = Math.max(1, width / Number(rectW));
31
+ }
32
+ }
33
+ }
34
+ return {
35
+ type: "image",
36
+ id: "",
37
+ url: src,
38
+ alt: ((_d = node.properties) == null ? void 0 : _d.alt) ?? "",
39
+ copyright: ((_e = node.properties) == null ? void 0 : _e.copyright) ?? null,
40
+ // This is not accurate. We're doing the casting because it seems the migration API
41
+ // accepts `undefined` values for those fields which is more convenient to us here.
42
+ // See: https://github.com/prismicio/prismic-client/pull/342#discussion_r1683650185
43
+ dimensions: { width, height },
44
+ edit: { x, y, zoom, background: "transparent" }
45
+ };
46
+ };
47
+ const serializeEmbed = (node) => {
48
+ var _a, _b, _c, _d;
49
+ const src = (_a = node.properties) == null ? void 0 : _a.src;
50
+ if (!src) {
51
+ throw new PrismicRichTextSerializerError.PrismicRichTextSerializerError("Element of type `embed` is missing an `src` attribute");
52
+ }
53
+ const oembedBase = {
54
+ version: "1.0",
55
+ embed_url: src,
56
+ html: hastUtilToHtml.toHtml(node),
57
+ title: (_b = node.properties) == null ? void 0 : _b.title
58
+ };
59
+ const width = (_c = node.properties) == null ? void 0 : _c.width;
60
+ const height = (_d = node.properties) == null ? void 0 : _d.height;
61
+ node.children = [];
62
+ if (width && height) {
63
+ return {
64
+ type: "embed",
65
+ oembed: { ...oembedBase, type: client.OEmbedType.Rich, width, height }
66
+ };
67
+ } else {
68
+ return {
69
+ type: "embed",
70
+ oembed: { ...oembedBase, type: client.OEmbedType.Link }
71
+ };
72
+ }
73
+ };
74
+ const serializeSpan = (node, rtPartialInlineNode) => {
75
+ var _a, _b;
76
+ if (rtPartialInlineNode.type === "hyperlink" && !("data" in rtPartialInlineNode)) {
77
+ const url = (_a = node.properties) == null ? void 0 : _a.href;
78
+ if (!url) {
79
+ throw new PrismicRichTextSerializerError.PrismicRichTextSerializerError("Element of type `hyperlink` is missing an `href` attribute");
80
+ }
81
+ return {
82
+ type: "hyperlink",
83
+ data: {
84
+ link_type: client.LinkType.Web,
85
+ url,
86
+ target: (_b = node.properties) == null ? void 0 : _b.target
87
+ }
88
+ };
89
+ }
90
+ return rtPartialInlineNode;
91
+ };
92
+ exports.serializeEmbed = serializeEmbed;
93
+ exports.serializeImage = serializeImage;
94
+ exports.serializeSpan = serializeSpan;
95
+ //# sourceMappingURL=hastSerializerHelpers.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hastSerializerHelpers.cjs","sources":["../../../src/lib/hastSerializerHelpers.ts"],"sourcesContent":["import { LinkType, OEmbedType } from \"@prismicio/client\"\nimport type { RTEmbedNode, RTImageNode, RTLinkNode } from \"@prismicio/client\"\nimport type { Element } from \"hast\"\nimport { toHtml } from \"hast-util-to-html\"\n\nimport { PrismicRichTextSerializerError } from \"../errors/PrismicRichTextSerializerError\"\n\nimport type { RTPartialInlineNode } from \"./RichTextFieldBuilder\"\n\n/**\n * Serializes a hast {@link Element} node to a {@link RTImageNode}.\n *\n * @param node - A hast node to serialize.\n *\n * @returns Equivalent {@link RTImageNode}.\n */\nexport const serializeImage = (node: Element): RTImageNode => {\n\tconst src = node.properties?.src as string | undefined\n\n\tif (!src) {\n\t\tthrow new PrismicRichTextSerializerError(\n\t\t\t\"Element of type `img` is missing an `src` attribute\",\n\t\t)\n\t}\n\n\tconst url = new URL(src, \"https://noop.com\")\n\n\tlet width = node.properties?.width as number | undefined\n\tlet height = node.properties?.height as number | undefined\n\tlet x = 0\n\tlet y = 0\n\tlet zoom = 1\n\n\t// Attempt to infer the image dimensions from the URL imgix parameters.\n\tif (url.hostname === \"images.prismic.io\") {\n\t\tif (url.searchParams.has(\"w\")) {\n\t\t\twidth = Number(url.searchParams.get(\"w\"))\n\t\t}\n\n\t\tif (url.searchParams.has(\"h\")) {\n\t\t\theight = Number(url.searchParams.get(\"h\"))\n\t\t}\n\n\t\tif (url.searchParams.has(\"rect\")) {\n\t\t\tconst [rectX, rextY, rectW, _rectH] = url.searchParams\n\t\t\t\t.get(\"rect\")!\n\t\t\t\t.split(\",\")\n\n\t\t\tx = Number(rectX)\n\t\t\ty = Number(rextY)\n\n\t\t\t// This is not perfect but it's supposed to work on images without constraints.\n\t\t\tif (width) {\n\t\t\t\tzoom = Math.max(1, width / Number(rectW))\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\ttype: \"image\",\n\t\tid: \"\",\n\t\turl: src,\n\t\talt: (node.properties?.alt as string) ?? \"\",\n\t\tcopyright: (node.properties?.copyright as string) ?? null,\n\t\t// This is not accurate. We're doing the casting because it seems the migration API\n\t\t// accepts `undefined` values for those fields which is more convenient to us here.\n\t\t// See: https://github.com/prismicio/prismic-client/pull/342#discussion_r1683650185\n\t\tdimensions: { width: width as number, height: height as number },\n\t\tedit: { x, y, zoom, background: \"transparent\" },\n\t}\n}\n\n/**\n * Serializes a hast {@link Element} node to a {@link RTEmbedNode}.\n *\n * @param node - A hast node to serialize.\n *\n * @returns Equivalent {@link RTEmbedNode}.\n */\nexport const serializeEmbed = (node: Element): RTEmbedNode => {\n\tconst src = node.properties?.src as string | undefined\n\n\tif (!src) {\n\t\tthrow new PrismicRichTextSerializerError(\n\t\t\t\"Element of type `embed` is missing an `src` attribute\",\n\t\t)\n\t}\n\n\tconst oembedBase = {\n\t\tversion: \"1.0\",\n\t\tembed_url: src,\n\t\thtml: toHtml(node),\n\t\ttitle: node.properties?.title as string | undefined,\n\t}\n\n\tconst width = node.properties?.width as number | undefined\n\tconst height = node.properties?.height as number | undefined\n\n\t// Remove the children of the embed node as we don't want to process them.\n\tnode.children = []\n\n\tif (width && height) {\n\t\treturn {\n\t\t\ttype: \"embed\",\n\t\t\toembed: { ...oembedBase, type: OEmbedType.Rich, width, height },\n\t\t}\n\t} else {\n\t\treturn {\n\t\t\ttype: \"embed\",\n\t\t\toembed: { ...oembedBase, type: OEmbedType.Link },\n\t\t}\n\t}\n}\n\n/**\n * Serializes a hast {@link Element} node to a {@link RTPartialInlineNode}.\n *\n * @param node - A hast node to serialize.\n * @param rtPartialInlineNode - A partial rich text node.\n *\n * @returns Equivalent {@link RTPartialInlineNode}.\n */\nexport const serializeSpan = (\n\tnode: Element,\n\trtPartialInlineNode:\n\t\t| RTPartialInlineNode\n\t\t| Omit<RTLinkNode, \"start\" | \"end\" | \"data\">,\n): RTPartialInlineNode => {\n\tif (\n\t\trtPartialInlineNode.type === \"hyperlink\" &&\n\t\t!(\"data\" in rtPartialInlineNode)\n\t) {\n\t\tconst url = node.properties?.href as string | undefined\n\t\tif (!url) {\n\t\t\tthrow new PrismicRichTextSerializerError(\n\t\t\t\t\"Element of type `hyperlink` is missing an `href` attribute\",\n\t\t\t)\n\t\t}\n\n\t\treturn {\n\t\t\ttype: \"hyperlink\",\n\t\t\tdata: {\n\t\t\t\tlink_type: LinkType.Web,\n\t\t\t\turl,\n\t\t\t\ttarget: node.properties?.target as string | undefined,\n\t\t\t},\n\t\t}\n\t}\n\n\treturn rtPartialInlineNode\n}\n"],"names":["PrismicRichTextSerializerError","toHtml","OEmbedType","LinkType"],"mappings":";;;;;AAgBa,MAAA,iBAAiB,CAAC,SAA8B;;AACtD,QAAA,OAAM,UAAK,eAAL,mBAAiB;AAE7B,MAAI,CAAC,KAAK;AACH,UAAA,IAAIA,+BAAAA,+BACT,qDAAqD;AAAA,EAEvD;AAEA,QAAM,MAAM,IAAI,IAAI,KAAK,kBAAkB;AAEvC,MAAA,SAAQ,UAAK,eAAL,mBAAiB;AACzB,MAAA,UAAS,UAAK,eAAL,mBAAiB;AAC9B,MAAI,IAAI;AACR,MAAI,IAAI;AACR,MAAI,OAAO;AAGP,MAAA,IAAI,aAAa,qBAAqB;AACzC,QAAI,IAAI,aAAa,IAAI,GAAG,GAAG;AAC9B,cAAQ,OAAO,IAAI,aAAa,IAAI,GAAG,CAAC;AAAA,IACzC;AAEA,QAAI,IAAI,aAAa,IAAI,GAAG,GAAG;AAC9B,eAAS,OAAO,IAAI,aAAa,IAAI,GAAG,CAAC;AAAA,IAC1C;AAEA,QAAI,IAAI,aAAa,IAAI,MAAM,GAAG;AACjC,YAAM,CAAC,OAAO,OAAO,OAAO,MAAM,IAAI,IAAI,aACxC,IAAI,MAAM,EACV,MAAM,GAAG;AAEX,UAAI,OAAO,KAAK;AAChB,UAAI,OAAO,KAAK;AAGhB,UAAI,OAAO;AACV,eAAO,KAAK,IAAI,GAAG,QAAQ,OAAO,KAAK,CAAC;AAAA,MACzC;AAAA,IACD;AAAA,EACD;AAEO,SAAA;AAAA,IACN,MAAM;AAAA,IACN,IAAI;AAAA,IACJ,KAAK;AAAA,IACL,OAAM,UAAK,eAAL,mBAAiB,QAAkB;AAAA,IACzC,aAAY,UAAK,eAAL,mBAAiB,cAAwB;AAAA;AAAA;AAAA;AAAA,IAIrD,YAAY,EAAE,OAAwB,OAA0B;AAAA,IAChE,MAAM,EAAE,GAAG,GAAG,MAAM,YAAY,cAAe;AAAA,EAAA;AAEjD;AASa,MAAA,iBAAiB,CAAC,SAA8B;;AACtD,QAAA,OAAM,UAAK,eAAL,mBAAiB;AAE7B,MAAI,CAAC,KAAK;AACH,UAAA,IAAIA,+BAAAA,+BACT,uDAAuD;AAAA,EAEzD;AAEA,QAAM,aAAa;AAAA,IAClB,SAAS;AAAA,IACT,WAAW;AAAA,IACX,MAAMC,sBAAO,IAAI;AAAA,IACjB,QAAO,UAAK,eAAL,mBAAiB;AAAA,EAAA;AAGnB,QAAA,SAAQ,UAAK,eAAL,mBAAiB;AACzB,QAAA,UAAS,UAAK,eAAL,mBAAiB;AAGhC,OAAK,WAAW;AAEhB,MAAI,SAAS,QAAQ;AACb,WAAA;AAAA,MACN,MAAM;AAAA,MACN,QAAQ,EAAE,GAAG,YAAY,MAAMC,OAAAA,WAAW,MAAM,OAAO,OAAQ;AAAA,IAAA;AAAA,SAE1D;AACC,WAAA;AAAA,MACN,MAAM;AAAA,MACN,QAAQ,EAAE,GAAG,YAAY,MAAMA,OAAAA,WAAW,KAAM;AAAA,IAAA;AAAA,EAElD;AACD;AAUa,MAAA,gBAAgB,CAC5B,MACA,wBAGwB;;AACxB,MACC,oBAAoB,SAAS,eAC7B,EAAE,UAAU,sBACX;AACK,UAAA,OAAM,UAAK,eAAL,mBAAiB;AAC7B,QAAI,CAAC,KAAK;AACH,YAAA,IAAIF,+BAAAA,+BACT,4DAA4D;AAAA,IAE9D;AAEO,WAAA;AAAA,MACN,MAAM;AAAA,MACN,MAAM;AAAA,QACL,WAAWG,OAAS,SAAA;AAAA,QACpB;AAAA,QACA,SAAQ,UAAK,eAAL,mBAAiB;AAAA,MACzB;AAAA,IAAA;AAAA,EAEH;AAEO,SAAA;AACR;;;;"}
@@ -0,0 +1,28 @@
1
+ import type { RTEmbedNode, RTImageNode, RTLinkNode } from "@prismicio/client";
2
+ import type { Element } from "hast";
3
+ import type { RTPartialInlineNode } from "./RichTextFieldBuilder";
4
+ /**
5
+ * Serializes a hast {@link Element} node to a {@link RTImageNode}.
6
+ *
7
+ * @param node - A hast node to serialize.
8
+ *
9
+ * @returns Equivalent {@link RTImageNode}.
10
+ */
11
+ export declare const serializeImage: (node: Element) => RTImageNode;
12
+ /**
13
+ * Serializes a hast {@link Element} node to a {@link RTEmbedNode}.
14
+ *
15
+ * @param node - A hast node to serialize.
16
+ *
17
+ * @returns Equivalent {@link RTEmbedNode}.
18
+ */
19
+ export declare const serializeEmbed: (node: Element) => RTEmbedNode;
20
+ /**
21
+ * Serializes a hast {@link Element} node to a {@link RTPartialInlineNode}.
22
+ *
23
+ * @param node - A hast node to serialize.
24
+ * @param rtPartialInlineNode - A partial rich text node.
25
+ *
26
+ * @returns Equivalent {@link RTPartialInlineNode}.
27
+ */
28
+ export declare const serializeSpan: (node: Element, rtPartialInlineNode: RTPartialInlineNode | Omit<RTLinkNode, "start" | "end" | "data">) => RTPartialInlineNode;
@@ -0,0 +1,95 @@
1
+ import { OEmbedType, LinkType } from "@prismicio/client";
2
+ import { toHtml } from "hast-util-to-html";
3
+ import { PrismicRichTextSerializerError } from "../errors/PrismicRichTextSerializerError.js";
4
+ const serializeImage = (node) => {
5
+ var _a, _b, _c, _d, _e;
6
+ const src = (_a = node.properties) == null ? void 0 : _a.src;
7
+ if (!src) {
8
+ throw new PrismicRichTextSerializerError("Element of type `img` is missing an `src` attribute");
9
+ }
10
+ const url = new URL(src, "https://noop.com");
11
+ let width = (_b = node.properties) == null ? void 0 : _b.width;
12
+ let height = (_c = node.properties) == null ? void 0 : _c.height;
13
+ let x = 0;
14
+ let y = 0;
15
+ let zoom = 1;
16
+ if (url.hostname === "images.prismic.io") {
17
+ if (url.searchParams.has("w")) {
18
+ width = Number(url.searchParams.get("w"));
19
+ }
20
+ if (url.searchParams.has("h")) {
21
+ height = Number(url.searchParams.get("h"));
22
+ }
23
+ if (url.searchParams.has("rect")) {
24
+ const [rectX, rextY, rectW, _rectH] = url.searchParams.get("rect").split(",");
25
+ x = Number(rectX);
26
+ y = Number(rextY);
27
+ if (width) {
28
+ zoom = Math.max(1, width / Number(rectW));
29
+ }
30
+ }
31
+ }
32
+ return {
33
+ type: "image",
34
+ id: "",
35
+ url: src,
36
+ alt: ((_d = node.properties) == null ? void 0 : _d.alt) ?? "",
37
+ copyright: ((_e = node.properties) == null ? void 0 : _e.copyright) ?? null,
38
+ // This is not accurate. We're doing the casting because it seems the migration API
39
+ // accepts `undefined` values for those fields which is more convenient to us here.
40
+ // See: https://github.com/prismicio/prismic-client/pull/342#discussion_r1683650185
41
+ dimensions: { width, height },
42
+ edit: { x, y, zoom, background: "transparent" }
43
+ };
44
+ };
45
+ const serializeEmbed = (node) => {
46
+ var _a, _b, _c, _d;
47
+ const src = (_a = node.properties) == null ? void 0 : _a.src;
48
+ if (!src) {
49
+ throw new PrismicRichTextSerializerError("Element of type `embed` is missing an `src` attribute");
50
+ }
51
+ const oembedBase = {
52
+ version: "1.0",
53
+ embed_url: src,
54
+ html: toHtml(node),
55
+ title: (_b = node.properties) == null ? void 0 : _b.title
56
+ };
57
+ const width = (_c = node.properties) == null ? void 0 : _c.width;
58
+ const height = (_d = node.properties) == null ? void 0 : _d.height;
59
+ node.children = [];
60
+ if (width && height) {
61
+ return {
62
+ type: "embed",
63
+ oembed: { ...oembedBase, type: OEmbedType.Rich, width, height }
64
+ };
65
+ } else {
66
+ return {
67
+ type: "embed",
68
+ oembed: { ...oembedBase, type: OEmbedType.Link }
69
+ };
70
+ }
71
+ };
72
+ const serializeSpan = (node, rtPartialInlineNode) => {
73
+ var _a, _b;
74
+ if (rtPartialInlineNode.type === "hyperlink" && !("data" in rtPartialInlineNode)) {
75
+ const url = (_a = node.properties) == null ? void 0 : _a.href;
76
+ if (!url) {
77
+ throw new PrismicRichTextSerializerError("Element of type `hyperlink` is missing an `href` attribute");
78
+ }
79
+ return {
80
+ type: "hyperlink",
81
+ data: {
82
+ link_type: LinkType.Web,
83
+ url,
84
+ target: (_b = node.properties) == null ? void 0 : _b.target
85
+ }
86
+ };
87
+ }
88
+ return rtPartialInlineNode;
89
+ };
90
+ export {
91
+ serializeEmbed,
92
+ serializeImage,
93
+ serializeSpan
94
+ };
95
+ //# sourceMappingURL=hastSerializerHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hastSerializerHelpers.js","sources":["../../../src/lib/hastSerializerHelpers.ts"],"sourcesContent":["import { LinkType, OEmbedType } from \"@prismicio/client\"\nimport type { RTEmbedNode, RTImageNode, RTLinkNode } from \"@prismicio/client\"\nimport type { Element } from \"hast\"\nimport { toHtml } from \"hast-util-to-html\"\n\nimport { PrismicRichTextSerializerError } from \"../errors/PrismicRichTextSerializerError\"\n\nimport type { RTPartialInlineNode } from \"./RichTextFieldBuilder\"\n\n/**\n * Serializes a hast {@link Element} node to a {@link RTImageNode}.\n *\n * @param node - A hast node to serialize.\n *\n * @returns Equivalent {@link RTImageNode}.\n */\nexport const serializeImage = (node: Element): RTImageNode => {\n\tconst src = node.properties?.src as string | undefined\n\n\tif (!src) {\n\t\tthrow new PrismicRichTextSerializerError(\n\t\t\t\"Element of type `img` is missing an `src` attribute\",\n\t\t)\n\t}\n\n\tconst url = new URL(src, \"https://noop.com\")\n\n\tlet width = node.properties?.width as number | undefined\n\tlet height = node.properties?.height as number | undefined\n\tlet x = 0\n\tlet y = 0\n\tlet zoom = 1\n\n\t// Attempt to infer the image dimensions from the URL imgix parameters.\n\tif (url.hostname === \"images.prismic.io\") {\n\t\tif (url.searchParams.has(\"w\")) {\n\t\t\twidth = Number(url.searchParams.get(\"w\"))\n\t\t}\n\n\t\tif (url.searchParams.has(\"h\")) {\n\t\t\theight = Number(url.searchParams.get(\"h\"))\n\t\t}\n\n\t\tif (url.searchParams.has(\"rect\")) {\n\t\t\tconst [rectX, rextY, rectW, _rectH] = url.searchParams\n\t\t\t\t.get(\"rect\")!\n\t\t\t\t.split(\",\")\n\n\t\t\tx = Number(rectX)\n\t\t\ty = Number(rextY)\n\n\t\t\t// This is not perfect but it's supposed to work on images without constraints.\n\t\t\tif (width) {\n\t\t\t\tzoom = Math.max(1, width / Number(rectW))\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\ttype: \"image\",\n\t\tid: \"\",\n\t\turl: src,\n\t\talt: (node.properties?.alt as string) ?? \"\",\n\t\tcopyright: (node.properties?.copyright as string) ?? null,\n\t\t// This is not accurate. We're doing the casting because it seems the migration API\n\t\t// accepts `undefined` values for those fields which is more convenient to us here.\n\t\t// See: https://github.com/prismicio/prismic-client/pull/342#discussion_r1683650185\n\t\tdimensions: { width: width as number, height: height as number },\n\t\tedit: { x, y, zoom, background: \"transparent\" },\n\t}\n}\n\n/**\n * Serializes a hast {@link Element} node to a {@link RTEmbedNode}.\n *\n * @param node - A hast node to serialize.\n *\n * @returns Equivalent {@link RTEmbedNode}.\n */\nexport const serializeEmbed = (node: Element): RTEmbedNode => {\n\tconst src = node.properties?.src as string | undefined\n\n\tif (!src) {\n\t\tthrow new PrismicRichTextSerializerError(\n\t\t\t\"Element of type `embed` is missing an `src` attribute\",\n\t\t)\n\t}\n\n\tconst oembedBase = {\n\t\tversion: \"1.0\",\n\t\tembed_url: src,\n\t\thtml: toHtml(node),\n\t\ttitle: node.properties?.title as string | undefined,\n\t}\n\n\tconst width = node.properties?.width as number | undefined\n\tconst height = node.properties?.height as number | undefined\n\n\t// Remove the children of the embed node as we don't want to process them.\n\tnode.children = []\n\n\tif (width && height) {\n\t\treturn {\n\t\t\ttype: \"embed\",\n\t\t\toembed: { ...oembedBase, type: OEmbedType.Rich, width, height },\n\t\t}\n\t} else {\n\t\treturn {\n\t\t\ttype: \"embed\",\n\t\t\toembed: { ...oembedBase, type: OEmbedType.Link },\n\t\t}\n\t}\n}\n\n/**\n * Serializes a hast {@link Element} node to a {@link RTPartialInlineNode}.\n *\n * @param node - A hast node to serialize.\n * @param rtPartialInlineNode - A partial rich text node.\n *\n * @returns Equivalent {@link RTPartialInlineNode}.\n */\nexport const serializeSpan = (\n\tnode: Element,\n\trtPartialInlineNode:\n\t\t| RTPartialInlineNode\n\t\t| Omit<RTLinkNode, \"start\" | \"end\" | \"data\">,\n): RTPartialInlineNode => {\n\tif (\n\t\trtPartialInlineNode.type === \"hyperlink\" &&\n\t\t!(\"data\" in rtPartialInlineNode)\n\t) {\n\t\tconst url = node.properties?.href as string | undefined\n\t\tif (!url) {\n\t\t\tthrow new PrismicRichTextSerializerError(\n\t\t\t\t\"Element of type `hyperlink` is missing an `href` attribute\",\n\t\t\t)\n\t\t}\n\n\t\treturn {\n\t\t\ttype: \"hyperlink\",\n\t\t\tdata: {\n\t\t\t\tlink_type: LinkType.Web,\n\t\t\t\turl,\n\t\t\t\ttarget: node.properties?.target as string | undefined,\n\t\t\t},\n\t\t}\n\t}\n\n\treturn rtPartialInlineNode\n}\n"],"names":[],"mappings":";;;AAgBa,MAAA,iBAAiB,CAAC,SAA8B;;AACtD,QAAA,OAAM,UAAK,eAAL,mBAAiB;AAE7B,MAAI,CAAC,KAAK;AACH,UAAA,IAAI,+BACT,qDAAqD;AAAA,EAEvD;AAEA,QAAM,MAAM,IAAI,IAAI,KAAK,kBAAkB;AAEvC,MAAA,SAAQ,UAAK,eAAL,mBAAiB;AACzB,MAAA,UAAS,UAAK,eAAL,mBAAiB;AAC9B,MAAI,IAAI;AACR,MAAI,IAAI;AACR,MAAI,OAAO;AAGP,MAAA,IAAI,aAAa,qBAAqB;AACzC,QAAI,IAAI,aAAa,IAAI,GAAG,GAAG;AAC9B,cAAQ,OAAO,IAAI,aAAa,IAAI,GAAG,CAAC;AAAA,IACzC;AAEA,QAAI,IAAI,aAAa,IAAI,GAAG,GAAG;AAC9B,eAAS,OAAO,IAAI,aAAa,IAAI,GAAG,CAAC;AAAA,IAC1C;AAEA,QAAI,IAAI,aAAa,IAAI,MAAM,GAAG;AACjC,YAAM,CAAC,OAAO,OAAO,OAAO,MAAM,IAAI,IAAI,aACxC,IAAI,MAAM,EACV,MAAM,GAAG;AAEX,UAAI,OAAO,KAAK;AAChB,UAAI,OAAO,KAAK;AAGhB,UAAI,OAAO;AACV,eAAO,KAAK,IAAI,GAAG,QAAQ,OAAO,KAAK,CAAC;AAAA,MACzC;AAAA,IACD;AAAA,EACD;AAEO,SAAA;AAAA,IACN,MAAM;AAAA,IACN,IAAI;AAAA,IACJ,KAAK;AAAA,IACL,OAAM,UAAK,eAAL,mBAAiB,QAAkB;AAAA,IACzC,aAAY,UAAK,eAAL,mBAAiB,cAAwB;AAAA;AAAA;AAAA;AAAA,IAIrD,YAAY,EAAE,OAAwB,OAA0B;AAAA,IAChE,MAAM,EAAE,GAAG,GAAG,MAAM,YAAY,cAAe;AAAA,EAAA;AAEjD;AASa,MAAA,iBAAiB,CAAC,SAA8B;;AACtD,QAAA,OAAM,UAAK,eAAL,mBAAiB;AAE7B,MAAI,CAAC,KAAK;AACH,UAAA,IAAI,+BACT,uDAAuD;AAAA,EAEzD;AAEA,QAAM,aAAa;AAAA,IAClB,SAAS;AAAA,IACT,WAAW;AAAA,IACX,MAAM,OAAO,IAAI;AAAA,IACjB,QAAO,UAAK,eAAL,mBAAiB;AAAA,EAAA;AAGnB,QAAA,SAAQ,UAAK,eAAL,mBAAiB;AACzB,QAAA,UAAS,UAAK,eAAL,mBAAiB;AAGhC,OAAK,WAAW;AAEhB,MAAI,SAAS,QAAQ;AACb,WAAA;AAAA,MACN,MAAM;AAAA,MACN,QAAQ,EAAE,GAAG,YAAY,MAAM,WAAW,MAAM,OAAO,OAAQ;AAAA,IAAA;AAAA,SAE1D;AACC,WAAA;AAAA,MACN,MAAM;AAAA,MACN,QAAQ,EAAE,GAAG,YAAY,MAAM,WAAW,KAAM;AAAA,IAAA;AAAA,EAElD;AACD;AAUa,MAAA,gBAAgB,CAC5B,MACA,wBAGwB;;AACxB,MACC,oBAAoB,SAAS,eAC7B,EAAE,UAAU,sBACX;AACK,UAAA,OAAM,UAAK,eAAL,mBAAiB;AAC7B,QAAI,CAAC,KAAK;AACH,YAAA,IAAI,+BACT,4DAA4D;AAAA,IAE9D;AAEO,WAAA;AAAA,MACN,MAAM;AAAA,MACN,MAAM;AAAA,QACL,WAAW,SAAS;AAAA,QACpB;AAAA,QACA,SAAQ,UAAK,eAAL,mBAAiB;AAAA,MACzB;AAAA,IAAA;AAAA,EAEH;AAEO,SAAA;AACR;"}