@portabletext/block-tools 3.4.1 → 3.5.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.
package/lib/index.cjs CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var sanityBridge = require("@portabletext/sanity-bridge"), schema = require("@portabletext/schema"), flatten = require("lodash/flatten.js"), getRandomValues = require("get-random-values-esm"), isEqual = require("lodash/isEqual.js"), uniq = require("lodash/uniq.js");
3
+ var sanityBridge = require("@portabletext/sanity-bridge"), schema = require("@portabletext/schema"), flatten = require("lodash/flatten.js"), getRandomValues = require("get-random-values-esm"), helpers = require("./_chunks-cjs/helpers.cjs"), isEqual = require("lodash/isEqual.js");
4
4
  function _interopDefaultCompat(e) {
5
5
  return e && typeof e == "object" && "default" in e ? e : { default: e };
6
6
  }
7
- var flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq);
7
+ var flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual);
8
8
  function keyGenerator() {
9
9
  return randomKey(12);
10
10
  }
@@ -18,492 +18,42 @@ for (let i = 0; i < 256; ++i)
18
18
  function randomKey(length) {
19
19
  return whatwgRNG(length).reduce((str, n) => str + byteToHex[n], "").slice(0, length);
20
20
  }
21
- const objectToString = Object.prototype.toString;
22
- function resolveJsType(val) {
23
- switch (objectToString.call(val)) {
24
- case "[object Function]":
25
- return "function";
26
- case "[object Date]":
27
- return "date";
28
- case "[object RegExp]":
29
- return "regexp";
30
- case "[object Arguments]":
31
- return "arguments";
32
- case "[object Array]":
33
- return "array";
34
- case "[object String]":
35
- return "string";
36
- }
37
- return val === null ? "null" : val === void 0 ? "undefined" : val && typeof val == "object" && "nodeType" in val && val.nodeType === 1 ? "element" : val === Object(val) ? "object" : typeof val;
38
- }
39
- function isArbitraryTypedObject(object) {
40
- return isRecord(object) && typeof object._type == "string";
41
- }
42
- function isRecord(value) {
43
- return !!value && (typeof value == "object" || typeof value == "function");
44
- }
45
- function flattenNestedBlocks(context, blocks2) {
46
- return blocks2.flatMap((block) => {
47
- if (isBlockContainer(block))
48
- return flattenNestedBlocks(context, [block.block]);
49
- if (schema.isTextBlock(context, block)) {
50
- const hasBlockObjects = block.children.some((child) => context.schema.blockObjects.some(
51
- (blockObject) => blockObject.name === child._type
52
- )), hasBlocks = block.children.some(
53
- (child) => child._type === "__block" || child._type === "block"
54
- );
55
- if (hasBlockObjects || hasBlocks) {
56
- const splitChildren = getSplitChildren(context, block);
57
- return splitChildren.length === 1 && splitChildren[0].type === "children" && isEqual__default.default(splitChildren[0].children, block.children) ? [block] : splitChildren.flatMap((slice) => slice.type === "block object" ? [slice.block] : slice.type === "block" ? flattenNestedBlocks(context, [
58
- slice.block
59
- ]) : slice.children.length > 0 ? slice.children.every(
60
- (child) => schema.isSpan(context, child) && child.text.trim() === ""
61
- ) ? [] : flattenNestedBlocks(context, [
62
- {
63
- ...block,
64
- children: slice.children
65
- }
66
- ]) : []);
67
- }
68
- return [block];
69
- }
70
- return [block];
71
- });
72
- }
73
- function isBlockContainer(block) {
74
- return block._type === "__block" && isArbitraryTypedObject(block.block);
75
- }
76
- function getSplitChildren(context, block) {
77
- return block.children.reduce(
78
- (slices, child) => {
79
- const knownInlineObject = context.schema.inlineObjects.some(
80
- (inlineObject) => inlineObject.name === child._type
81
- ), knownBlockObject = context.schema.blockObjects.some(
82
- (blockObject) => blockObject.name === child._type
83
- ), lastSlice = slices.pop();
84
- return !schema.isSpan(context, child) && !knownInlineObject && knownBlockObject ? [
85
- ...slices,
86
- ...lastSlice ? [lastSlice] : [],
87
- { type: "block object", block: child }
88
- ] : child._type === "__block" ? [
89
- ...slices,
90
- ...lastSlice ? [lastSlice] : [],
91
- {
92
- type: "block object",
93
- block: child.block
94
- }
95
- ] : child._type === "block" ? [
96
- ...slices,
97
- ...lastSlice ? [lastSlice] : [],
98
- { type: "block", block: child }
99
- ] : lastSlice && lastSlice.type === "children" ? [
100
- ...slices,
101
- {
102
- type: "children",
103
- children: [...lastSlice.children, child]
104
- }
105
- ] : [
106
- ...slices,
107
- ...lastSlice ? [lastSlice] : [],
108
- { type: "children", children: [child] }
109
- ];
110
- },
111
- []
112
- );
113
- }
114
- var s = { 0: 8203, 1: 8204, 2: 8205, 3: 8290, 4: 8291, 5: 8288, 6: 65279, 7: 8289, 8: 119155, 9: 119156, a: 119157, b: 119158, c: 119159, d: 119160, e: 119161, f: 119162 }, c = { 0: 8203, 1: 8204, 2: 8205, 3: 65279 };
115
- new Array(4).fill(String.fromCodePoint(c[0])).join("");
116
- Object.fromEntries(Object.entries(c).map((t) => t.reverse()));
117
- Object.fromEntries(Object.entries(s).map((t) => t.reverse()));
118
- var S = `${Object.values(s).map((t) => `\\u{${t.toString(16)}}`).join("")}`, f = new RegExp(`[${S}]{4,}`, "gu");
119
- function _(t) {
120
- var e;
121
- return { cleaned: t.replace(f, ""), encoded: ((e = t.match(f)) == null ? void 0 : e[0]) || "" };
122
- }
123
- function O(t) {
124
- return t && JSON.parse(_(JSON.stringify(t)).cleaned);
125
- }
126
- const PRESERVE_WHITESPACE_TAGS = ["pre", "textarea", "code"], BLOCK_DEFAULT_STYLE = "normal", DEFAULT_BLOCK = Object.freeze({
127
- _type: "block",
128
- markDefs: [],
129
- style: BLOCK_DEFAULT_STYLE
130
- }), DEFAULT_SPAN = Object.freeze({
131
- _type: "span",
132
- marks: []
133
- }), HTML_BLOCK_TAGS = {
134
- p: DEFAULT_BLOCK,
135
- blockquote: { ...DEFAULT_BLOCK, style: "blockquote" }
136
- }, HTML_SPAN_TAGS = {
137
- span: { object: "text" }
138
- }, HTML_LIST_CONTAINER_TAGS = {
139
- ol: { object: null },
140
- ul: { object: null }
141
- }, HTML_HEADER_TAGS = {
142
- h1: { ...DEFAULT_BLOCK, style: "h1" },
143
- h2: { ...DEFAULT_BLOCK, style: "h2" },
144
- h3: { ...DEFAULT_BLOCK, style: "h3" },
145
- h4: { ...DEFAULT_BLOCK, style: "h4" },
146
- h5: { ...DEFAULT_BLOCK, style: "h5" },
147
- h6: { ...DEFAULT_BLOCK, style: "h6" }
148
- }, HTML_MISC_TAGS = {
149
- br: { ...DEFAULT_BLOCK, style: BLOCK_DEFAULT_STYLE }
150
- }, HTML_DECORATOR_TAGS = {
151
- b: "strong",
152
- strong: "strong",
153
- i: "em",
154
- em: "em",
155
- u: "underline",
156
- s: "strike-through",
157
- strike: "strike-through",
158
- del: "strike-through",
159
- code: "code",
160
- sup: "sup",
161
- sub: "sub",
162
- ins: "ins",
163
- mark: "mark",
164
- small: "small"
165
- }, HTML_LIST_ITEM_TAGS = {
166
- li: {
167
- ...DEFAULT_BLOCK,
168
- style: BLOCK_DEFAULT_STYLE,
169
- level: 1,
170
- listItem: "bullet"
171
- }
172
- }, ELEMENT_MAP = {
173
- ...HTML_BLOCK_TAGS,
174
- ...HTML_SPAN_TAGS,
175
- ...HTML_LIST_CONTAINER_TAGS,
176
- ...HTML_LIST_ITEM_TAGS,
177
- ...HTML_HEADER_TAGS,
178
- ...HTML_MISC_TAGS
179
- };
180
- uniq__default.default(
181
- Object.values(ELEMENT_MAP).filter((tag) => "style" in tag).map((tag) => tag.style)
182
- );
183
- uniq__default.default(
184
- Object.values(HTML_DECORATOR_TAGS)
185
- );
186
- const _XPathResult = {
187
- BOOLEAN_TYPE: 3,
188
- ORDERED_NODE_ITERATOR_TYPE: 5,
189
- UNORDERED_NODE_SNAPSHOT_TYPE: 6
190
- };
191
- var preprocessGDocs = (_html, doc, options) => {
192
- const whitespaceOnPasteMode = options?.unstable_whitespaceOnPasteMode || "preserve";
193
- let gDocsRootOrSiblingNode = doc.evaluate(
194
- '//*[@id and contains(@id, "docs-internal-guid")]',
195
- doc,
196
- null,
197
- _XPathResult.ORDERED_NODE_ITERATOR_TYPE,
198
- null
199
- ).iterateNext();
200
- if (gDocsRootOrSiblingNode) {
201
- const isWrappedRootTag = tagName(gDocsRootOrSiblingNode) === "b";
202
- switch (isWrappedRootTag || (gDocsRootOrSiblingNode = doc.body), whitespaceOnPasteMode) {
203
- case "normalize":
204
- normalizeWhitespace(gDocsRootOrSiblingNode);
205
- break;
206
- case "remove":
207
- removeAllWhitespace(gDocsRootOrSiblingNode);
208
- break;
209
- }
210
- const childNodes = doc.evaluate(
211
- "//*",
212
- doc,
213
- null,
214
- _XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
215
- null
216
- );
217
- for (let i = childNodes.snapshotLength - 1; i >= 0; i--) {
218
- const elm = childNodes.snapshotItem(i);
219
- elm?.setAttribute("data-is-google-docs", "true"), (elm?.parentElement === gDocsRootOrSiblingNode || !isWrappedRootTag && elm.parentElement === doc.body) && (elm?.setAttribute("data-is-root-node", "true"), tagName(elm)), tagName(elm) === "li" && elm.firstChild && tagName(elm?.firstChild) === "img" && elm.removeChild(elm.firstChild);
220
- }
221
- return isWrappedRootTag && doc.body.firstElementChild?.replaceWith(
222
- ...Array.from(gDocsRootOrSiblingNode.childNodes)
223
- ), doc;
224
- }
225
- return doc;
226
- };
227
- const unwantedWordDocumentPaths = [
228
- "/html/text()",
229
- "/html/head/text()",
230
- "/html/body/text()",
231
- "/html/body/ul/text()",
232
- "/html/body/ol/text()",
233
- "//comment()",
234
- "//style",
235
- "//xml",
236
- "//script",
237
- "//meta",
238
- "//link"
239
- ];
240
- var preprocessHTML = (_html, doc) => {
241
- const bodyTextNodes = doc.evaluate(
242
- "/html/body/text()",
243
- doc,
244
- null,
245
- _XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
246
- null
247
- );
248
- for (let i = bodyTextNodes.snapshotLength - 1; i >= 0; i--) {
249
- const node = bodyTextNodes.snapshotItem(i), text = node.textContent || "";
250
- if (text.replace(/[^\S\n]+$/g, "")) {
251
- const newNode = doc.createElement("span");
252
- newNode.appendChild(doc.createTextNode(text)), node.parentNode?.replaceChild(newNode, node);
253
- } else
254
- node.parentNode?.removeChild(node);
255
- }
256
- const unwantedNodes = doc.evaluate(
257
- unwantedWordDocumentPaths.join("|"),
258
- doc,
259
- null,
260
- _XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
261
- null
262
- );
263
- for (let i = unwantedNodes.snapshotLength - 1; i >= 0; i--) {
264
- const unwanted = unwantedNodes.snapshotItem(i);
265
- unwanted && unwanted.parentNode?.removeChild(unwanted);
266
- }
267
- return doc;
268
- }, preprocessNotion = (html, doc) => {
269
- const NOTION_REGEX = /<!-- notionvc:.*?-->/g;
270
- if (html.match(NOTION_REGEX)) {
271
- const childNodes = doc.evaluate(
272
- "//*",
273
- doc,
274
- null,
275
- _XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
276
- null
277
- );
278
- for (let i = childNodes.snapshotLength - 1; i >= 0; i--)
279
- childNodes.snapshotItem(i)?.setAttribute("data-is-notion", "true");
280
- return doc;
281
- }
282
- return doc;
283
- }, preprocessWhitespace = (_2, doc) => {
284
- function processNode(node) {
285
- if (node.nodeType === _XPathResult.BOOLEAN_TYPE && !PRESERVE_WHITESPACE_TAGS.includes(
286
- node.parentElement?.tagName.toLowerCase() || ""
287
- ))
288
- node.textContent = node.textContent?.replace(/\s\s+/g, " ").replace(/[\r\n]+/g, " ") || "";
289
- else
290
- for (let i = 0; i < node.childNodes.length; i++)
291
- processNode(node.childNodes[i]);
292
- }
293
- return processNode(doc.body), doc;
294
- };
295
- const WORD_HTML_REGEX = /(class="?Mso|style=(?:"|')[^"]*?\bmso-|w:WordDocument|<o:\w+>|<\/font>)/, unwantedPaths = [
296
- "//o:p",
297
- "//span[@style='mso-list:Ignore']",
298
- "//span[@style='mso-list: Ignore']"
299
- ], mappedPaths = [
300
- "//p[@class='MsoTocHeading']",
301
- "//p[@class='MsoTitle']",
302
- "//p[@class='MsoToaHeading']",
303
- "//p[@class='MsoSubtitle']",
304
- "//span[@class='MsoSubtleEmphasis']",
305
- "//span[@class='MsoIntenseEmphasis']"
306
- ], elementMap = {
307
- MsoTocHeading: ["h3"],
308
- MsoTitle: ["h1"],
309
- MsoToaHeading: ["h2"],
310
- MsoSubtitle: ["h5"],
311
- MsoSubtleEmphasis: ["span", "em"],
312
- MsoIntenseEmphasis: ["span", "em", "strong"]
313
- // Remove cruft
314
- };
315
- function isWordHtml(html) {
316
- return WORD_HTML_REGEX.test(html);
317
- }
318
- var preprocessWord = (html, doc) => {
319
- if (!isWordHtml(html))
320
- return doc;
321
- const unwantedNodes = doc.evaluate(
322
- unwantedPaths.join("|"),
323
- doc,
324
- (prefix) => prefix === "o" ? "urn:schemas-microsoft-com:office:office" : null,
325
- _XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
326
- null
327
- );
328
- for (let i = unwantedNodes.snapshotLength - 1; i >= 0; i--) {
329
- const unwanted = unwantedNodes.snapshotItem(i);
330
- unwanted?.parentNode && unwanted.parentNode.removeChild(unwanted);
331
- }
332
- const mappedElements = doc.evaluate(
333
- mappedPaths.join("|"),
334
- doc,
335
- null,
336
- _XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
337
- null
338
- );
339
- for (let i = mappedElements.snapshotLength - 1; i >= 0; i--) {
340
- const mappedElm = mappedElements.snapshotItem(i), tags = elementMap[mappedElm.className], text = doc.createTextNode(mappedElm.textContent || "");
341
- if (!tags)
342
- continue;
343
- const parentElement = doc.createElement(tags[0]);
344
- let parent = parentElement, child = parentElement;
345
- tags.slice(1).forEach((tag) => {
346
- child = doc.createElement(tag), parent.appendChild(child), parent = child;
347
- }), child.appendChild(text), mappedElm?.parentNode?.replaceChild(parentElement, mappedElm);
348
- }
349
- return doc;
350
- }, preprocessors = [
351
- preprocessWhitespace,
352
- preprocessNotion,
353
- preprocessWord,
354
- preprocessGDocs,
355
- preprocessHTML
356
- ];
357
- function tagName(el) {
358
- if (el && "tagName" in el)
359
- return el.tagName.toLowerCase();
360
- }
361
- function preprocess(html, parseHtml, options) {
362
- const cleanHTML = O(html), doc = parseHtml(normalizeHtmlBeforePreprocess(cleanHTML));
363
- return preprocessors.forEach((processor) => {
364
- processor(cleanHTML, doc, options);
365
- }), doc;
366
- }
367
- function normalizeHtmlBeforePreprocess(html) {
368
- return html.trim();
369
- }
370
- function defaultParseHtml() {
371
- if (resolveJsType(DOMParser) === "undefined")
372
- throw new Error(
373
- "The native `DOMParser` global which the `Html` deserializer uses by default is not present in this environment. You must supply the `options.parseHtml` function instead."
374
- );
375
- return (html) => new DOMParser().parseFromString(html, "text/html");
376
- }
377
- function nextSpan(block, index) {
378
- const next = block.children[index + 1];
379
- return next && next._type === "span" ? next : null;
380
- }
381
- function prevSpan(block, index) {
382
- const prev = block.children[index - 1];
383
- return prev && prev._type === "span" ? prev : null;
384
- }
385
- function isWhiteSpaceChar(text) {
386
- return ["\xA0", " "].includes(text);
387
- }
388
- function trimWhitespace(schema$1, blocks2) {
389
- return blocks2.forEach((block) => {
390
- schema.isTextBlock({ schema: schema$1 }, block) && block.children.forEach((child, index) => {
391
- if (!isMinimalSpan(child))
392
- return;
393
- const nextChild = nextSpan(block, index), prevChild = prevSpan(block, index);
394
- index === 0 && (child.text = child.text.replace(/^[^\S\n]+/g, "")), index === block.children.length - 1 && (child.text = child.text.replace(/[^\S\n]+$/g, "")), /\s/.test(child.text.slice(Math.max(0, child.text.length - 1))) && nextChild && isMinimalSpan(nextChild) && /\s/.test(nextChild.text.slice(0, 1)) && (child.text = child.text.replace(/[^\S\n]+$/g, "")), /\s/.test(child.text.slice(0, 1)) && prevChild && isMinimalSpan(prevChild) && /\s/.test(prevChild.text.slice(Math.max(0, prevChild.text.length - 1))) && (child.text = child.text.replace(/^[^\S\n]+/g, "")), child.text || block.children.splice(index, 1), prevChild && isEqual__default.default(prevChild.marks, child.marks) && isWhiteSpaceChar(child.text) ? (prevChild.text += " ", block.children.splice(index, 1)) : nextChild && isEqual__default.default(nextChild.marks, child.marks) && isWhiteSpaceChar(child.text) && (nextChild.text = ` ${nextChild.text}`, block.children.splice(index, 1));
395
- });
396
- }), blocks2;
397
- }
398
- function ensureRootIsBlocks(schema$1, objects) {
399
- return objects.reduce((blocks2, node, i, original) => {
400
- if (node._type === "block")
401
- return blocks2.push(node), blocks2;
402
- if (node._type === "__block")
403
- return blocks2.push(node.block), blocks2;
404
- const lastBlock = blocks2[blocks2.length - 1];
405
- if (i > 0 && !schema.isTextBlock({ schema: schema$1 }, original[i - 1]) && schema.isTextBlock({ schema: schema$1 }, lastBlock))
406
- return lastBlock.children.push(node), blocks2;
407
- const block = {
408
- ...DEFAULT_BLOCK,
409
- children: [node]
410
- };
411
- return blocks2.push(block), blocks2;
412
- }, []);
413
- }
414
- function isNodeList(node) {
415
- return Object.prototype.toString.call(node) === "[object NodeList]";
416
- }
417
- function isMinimalSpan(node) {
418
- return node._type === "span";
419
- }
420
- function isMinimalBlock(node) {
421
- return node._type === "block";
422
- }
423
- function isPlaceholderDecorator(node) {
424
- return node._type === "__decorator";
425
- }
426
- function isPlaceholderAnnotation(node) {
427
- return node._type === "__annotation";
428
- }
429
- function isElement(node) {
430
- return node.nodeType === 1;
431
- }
432
- function normalizeWhitespace(rootNode) {
433
- let emptyBlockCount = 0, lastParent = null;
434
- const nodesToRemove = [];
435
- for (let child = rootNode.firstChild; child; child = child.nextSibling) {
436
- if (!isElement(child)) {
437
- normalizeWhitespace(child), emptyBlockCount = 0;
438
- continue;
439
- }
440
- const elm = child;
441
- isWhitespaceBlock(elm) ? (lastParent && elm.parentElement === lastParent ? (emptyBlockCount++, emptyBlockCount > 1 && nodesToRemove.push(elm)) : emptyBlockCount = 1, lastParent = elm.parentElement) : (normalizeWhitespace(child), emptyBlockCount = 0);
442
- }
443
- nodesToRemove.forEach((node) => {
444
- node.parentElement?.removeChild(node);
445
- });
446
- }
447
- function removeAllWhitespace(rootNode) {
448
- const nodesToRemove = [];
449
- function collectNodesToRemove(currentNode) {
450
- if (isElement(currentNode)) {
451
- const elm = currentNode;
452
- if (tagName(elm) === "br" && (tagName(elm.nextElementSibling) === "p" || tagName(elm.previousElementSibling) === "p")) {
453
- nodesToRemove.push(elm);
454
- return;
455
- }
456
- if ((tagName(elm) === "p" || tagName(elm) === "br") && elm?.firstChild?.textContent?.trim() === "") {
457
- nodesToRemove.push(elm);
458
- return;
459
- }
460
- for (let child = elm.firstChild; child; child = child.nextSibling)
461
- collectNodesToRemove(child);
462
- }
463
- }
464
- collectNodesToRemove(rootNode), nodesToRemove.forEach((node) => {
465
- node.parentElement?.removeChild(node);
466
- });
467
- }
468
- function isWhitespaceBlock(elm) {
469
- return ["p", "br"].includes(tagName(elm) || "") && !elm.textContent?.trim();
470
- }
471
- const LIST_CONTAINER_TAGS = Object.keys(HTML_LIST_CONTAINER_TAGS);
21
+ const LIST_CONTAINER_TAGS = Object.keys(helpers.HTML_LIST_CONTAINER_TAGS);
472
22
  function isEmphasis$1(el) {
473
- const style = isElement(el) && el.getAttribute("style");
23
+ const style = helpers.isElement(el) && el.getAttribute("style");
474
24
  return /font-style\s*:\s*italic/.test(style || "");
475
25
  }
476
26
  function isStrong$1(el) {
477
- const style = isElement(el) && el.getAttribute("style");
27
+ const style = helpers.isElement(el) && el.getAttribute("style");
478
28
  return /font-weight\s*:\s*700/.test(style || "");
479
29
  }
480
30
  function isUnderline$1(el) {
481
- if (!isElement(el) || tagName(el.parentNode) === "a")
31
+ if (!helpers.isElement(el) || helpers.tagName(el.parentNode) === "a")
482
32
  return !1;
483
- const style = isElement(el) && el.getAttribute("style");
33
+ const style = helpers.isElement(el) && el.getAttribute("style");
484
34
  return /text-decoration\s*:\s*underline/.test(style || "");
485
35
  }
486
36
  function isStrikethrough(el) {
487
- const style = isElement(el) && el.getAttribute("style");
37
+ const style = helpers.isElement(el) && el.getAttribute("style");
488
38
  return /text-decoration\s*:\s*(?:.*line-through.*;)/.test(style || "");
489
39
  }
490
40
  function isGoogleDocs(el) {
491
- return isElement(el) && !!el.getAttribute("data-is-google-docs");
41
+ return helpers.isElement(el) && !!el.getAttribute("data-is-google-docs");
492
42
  }
493
43
  function isRootNode(el) {
494
- return isElement(el) && !!el.getAttribute("data-is-root-node");
44
+ return helpers.isElement(el) && !!el.getAttribute("data-is-root-node");
495
45
  }
496
46
  function getListItemStyle$1(el) {
497
- const parentTag = tagName(el.parentNode);
47
+ const parentTag = helpers.tagName(el.parentNode);
498
48
  if (!(parentTag && !LIST_CONTAINER_TAGS.includes(parentTag)))
499
- return tagName(el.parentNode) === "ul" ? "bullet" : "number";
49
+ return helpers.tagName(el.parentNode) === "ul" ? "bullet" : "number";
500
50
  }
501
51
  function getListItemLevel$1(el) {
502
52
  let level = 0;
503
- if (tagName(el) === "li") {
53
+ if (helpers.tagName(el) === "li") {
504
54
  let parentNode = el.parentNode;
505
55
  for (; parentNode; ) {
506
- const parentTag = tagName(parentNode);
56
+ const parentTag = helpers.tagName(parentNode);
507
57
  parentTag && LIST_CONTAINER_TAGS.includes(parentTag) && level++, parentNode = parentNode.parentNode;
508
58
  }
509
59
  } else
@@ -511,22 +61,22 @@ function getListItemLevel$1(el) {
511
61
  return level;
512
62
  }
513
63
  const blocks = {
514
- ...HTML_BLOCK_TAGS,
515
- ...HTML_HEADER_TAGS
64
+ ...helpers.HTML_BLOCK_TAGS,
65
+ ...helpers.HTML_HEADER_TAGS
516
66
  };
517
67
  function getBlockStyle(schema2, el) {
518
- const childTag = tagName(el.firstChild), block = childTag && blocks[childTag];
519
- return block && schema2.styles.some((style) => style.name === block.style) ? block.style : BLOCK_DEFAULT_STYLE;
68
+ const childTag = helpers.tagName(el.firstChild), block = childTag && blocks[childTag];
69
+ return block && schema2.styles.some((style) => style.name === block.style) ? block.style : helpers.BLOCK_DEFAULT_STYLE;
520
70
  }
521
71
  function createGDocsRules(schema2) {
522
72
  return [
523
73
  {
524
74
  deserialize(el, next) {
525
- if (isElement(el) && tagName(el) === "span" && isGoogleDocs(el)) {
75
+ if (helpers.isElement(el) && helpers.tagName(el) === "span" && isGoogleDocs(el)) {
526
76
  if (!el.textContent)
527
77
  return !el.previousSibling && !el.nextSibling && el.setAttribute("data-lonely-child", "true"), next(el.childNodes);
528
78
  const span = {
529
- ...DEFAULT_SPAN,
79
+ ...helpers.DEFAULT_SPAN,
530
80
  marks: [],
531
81
  text: el.textContent
532
82
  };
@@ -536,9 +86,9 @@ function createGDocsRules(schema2) {
536
86
  },
537
87
  {
538
88
  deserialize(el, next) {
539
- if (tagName(el) === "li" && isGoogleDocs(el))
89
+ if (helpers.tagName(el) === "li" && isGoogleDocs(el))
540
90
  return {
541
- ...DEFAULT_BLOCK,
91
+ ...helpers.DEFAULT_BLOCK,
542
92
  listItem: getListItemStyle$1(el),
543
93
  level: getListItemLevel$1(el),
544
94
  style: getBlockStyle(schema2, el),
@@ -548,19 +98,19 @@ function createGDocsRules(schema2) {
548
98
  },
549
99
  {
550
100
  deserialize(el) {
551
- if (tagName(el) === "br" && isGoogleDocs(el) && isElement(el) && el.classList.contains("apple-interchange-newline"))
101
+ if (helpers.tagName(el) === "br" && isGoogleDocs(el) && helpers.isElement(el) && el.classList.contains("apple-interchange-newline"))
552
102
  return {
553
- ...DEFAULT_SPAN,
103
+ ...helpers.DEFAULT_SPAN,
554
104
  text: ""
555
105
  };
556
- if (tagName(el) === "br" && isGoogleDocs(el) && isElement(el) && el?.parentNode?.textContent === "")
106
+ if (helpers.tagName(el) === "br" && isGoogleDocs(el) && helpers.isElement(el) && el?.parentNode?.textContent === "")
557
107
  return {
558
- ...DEFAULT_SPAN,
108
+ ...helpers.DEFAULT_SPAN,
559
109
  text: ""
560
110
  };
561
- if (tagName(el) === "br" && isGoogleDocs(el) && isElement(el) && isRootNode(el))
111
+ if (helpers.tagName(el) === "br" && isGoogleDocs(el) && helpers.isElement(el) && isRootNode(el))
562
112
  return {
563
- ...DEFAULT_SPAN,
113
+ ...helpers.DEFAULT_SPAN,
564
114
  text: ""
565
115
  };
566
116
  }
@@ -570,14 +120,14 @@ function createGDocsRules(schema2) {
570
120
  const whitespaceTextNodeRule = {
571
121
  deserialize(node) {
572
122
  return node.nodeName === "#text" && isWhitespaceTextNode(node) ? {
573
- ...DEFAULT_SPAN,
123
+ ...helpers.DEFAULT_SPAN,
574
124
  marks: [],
575
125
  text: (node.textContent ?? "").replace(/\s\s+/g, " ")
576
126
  } : void 0;
577
127
  }
578
128
  };
579
129
  function isWhitespaceTextNode(node) {
580
- return (node.nodeType === 3 && (node.textContent || "").replace(/[\r\n]/g, " ").replace(/\s\s+/g, " ") === " " && node.nextSibling && node.nextSibling.nodeType !== 3 && node.previousSibling && node.previousSibling.nodeType !== 3 || node.textContent !== " ") && tagName(node.parentNode) !== "body";
130
+ return (node.nodeType === 3 && (node.textContent || "").replace(/[\r\n]/g, " ").replace(/\s\s+/g, " ") === " " && node.nextSibling && node.nextSibling.nodeType !== 3 && node.previousSibling && node.previousSibling.nodeType !== 3 || node.textContent !== " ") && helpers.tagName(node.parentNode) !== "body";
581
131
  }
582
132
  function resolveListItem(schema2, listNodeTagName) {
583
133
  if (listNodeTagName === "ul" && schema2.lists.some((list) => list.name === "bullet"))
@@ -591,7 +141,7 @@ function createHTMLRules(schema2, options) {
591
141
  {
592
142
  // Pre element
593
143
  deserialize(el) {
594
- if (tagName(el) !== "pre")
144
+ if (helpers.tagName(el) !== "pre")
595
145
  return;
596
146
  const isCodeEnabled = schema2.styles.some(
597
147
  (style) => style.name === "code"
@@ -602,7 +152,7 @@ function createHTMLRules(schema2, options) {
602
152
  markDefs: [],
603
153
  children: [
604
154
  {
605
- ...DEFAULT_SPAN,
155
+ ...helpers.DEFAULT_SPAN,
606
156
  marks: isCodeEnabled ? ["code"] : [],
607
157
  text: el.textContent || ""
608
158
  }
@@ -613,11 +163,11 @@ function createHTMLRules(schema2, options) {
613
163
  // Blockquote element
614
164
  {
615
165
  deserialize(el, next) {
616
- if (tagName(el) !== "blockquote")
166
+ if (helpers.tagName(el) !== "blockquote")
617
167
  return;
618
168
  const blocks2 = {
619
- ...HTML_BLOCK_TAGS,
620
- ...HTML_HEADER_TAGS
169
+ ...helpers.HTML_BLOCK_TAGS,
170
+ ...helpers.HTML_HEADER_TAGS
621
171
  };
622
172
  delete blocks2.blockquote;
623
173
  const nonBlockquoteBlocks = Object.keys(blocks2), children = [];
@@ -644,16 +194,16 @@ function createHTMLRules(schema2, options) {
644
194
  {
645
195
  deserialize(el, next) {
646
196
  const blocks2 = {
647
- ...HTML_BLOCK_TAGS,
648
- ...HTML_HEADER_TAGS
649
- }, tag = tagName(el);
197
+ ...helpers.HTML_BLOCK_TAGS,
198
+ ...helpers.HTML_HEADER_TAGS
199
+ }, tag = helpers.tagName(el);
650
200
  let block = tag ? blocks2[tag] : void 0;
651
201
  if (!block)
652
202
  return;
653
- if (el.parentNode && tagName(el.parentNode) === "li")
203
+ if (el.parentNode && helpers.tagName(el.parentNode) === "li")
654
204
  return next(el.childNodes);
655
205
  const blockStyle = block.style;
656
- return schema2.styles.some((style) => style.name === blockStyle) || (block = DEFAULT_BLOCK), {
206
+ return schema2.styles.some((style) => style.name === blockStyle) || (block = helpers.DEFAULT_BLOCK), {
657
207
  ...block,
658
208
  children: next(el.childNodes)
659
209
  };
@@ -662,32 +212,32 @@ function createHTMLRules(schema2, options) {
662
212
  // Ignore span tags
663
213
  {
664
214
  deserialize(el, next) {
665
- const tag = tagName(el);
666
- if (!(!tag || !(tag in HTML_SPAN_TAGS)))
215
+ const tag = helpers.tagName(el);
216
+ if (!(!tag || !(tag in helpers.HTML_SPAN_TAGS)))
667
217
  return next(el.childNodes);
668
218
  }
669
219
  },
670
220
  // Ignore div tags
671
221
  {
672
222
  deserialize(el, next) {
673
- if (tagName(el) === "div")
223
+ if (helpers.tagName(el) === "div")
674
224
  return next(el.childNodes);
675
225
  }
676
226
  },
677
227
  // Ignore list containers
678
228
  {
679
229
  deserialize(el, next) {
680
- const tag = tagName(el);
681
- if (!(!tag || !(tag in HTML_LIST_CONTAINER_TAGS)))
230
+ const tag = helpers.tagName(el);
231
+ if (!(!tag || !(tag in helpers.HTML_LIST_CONTAINER_TAGS)))
682
232
  return next(el.childNodes);
683
233
  }
684
234
  },
685
235
  // Deal with br's
686
236
  {
687
237
  deserialize(el) {
688
- if (tagName(el) === "br")
238
+ if (helpers.tagName(el) === "br")
689
239
  return {
690
- ...DEFAULT_SPAN,
240
+ ...helpers.DEFAULT_SPAN,
691
241
  text: `
692
242
  `
693
243
  };
@@ -696,8 +246,8 @@ function createHTMLRules(schema2, options) {
696
246
  // Deal with list items
697
247
  {
698
248
  deserialize(el, next, block) {
699
- const tag = tagName(el), listItem = tag ? HTML_LIST_ITEM_TAGS[tag] : void 0, parentTag = tagName(el.parentNode) || "";
700
- if (!listItem || !el.parentNode || !HTML_LIST_CONTAINER_TAGS[parentTag])
249
+ const tag = helpers.tagName(el), listItem = tag ? helpers.HTML_LIST_ITEM_TAGS[tag] : void 0, parentTag = helpers.tagName(el.parentNode) || "";
250
+ if (!listItem || !el.parentNode || !helpers.HTML_LIST_CONTAINER_TAGS[parentTag])
701
251
  return;
702
252
  const enabledListItem = resolveListItem(schema2, parentTag);
703
253
  return enabledListItem ? (listItem.listItem = enabledListItem, {
@@ -709,7 +259,7 @@ function createHTMLRules(schema2, options) {
709
259
  // Deal with decorators - this is a limited set of known html elements that we know how to deserialize
710
260
  {
711
261
  deserialize(el, next) {
712
- const decorator = HTML_DECORATOR_TAGS[tagName(el) || ""];
262
+ const decorator = helpers.HTML_DECORATOR_TAGS[helpers.tagName(el) || ""];
713
263
  if (!(!decorator || !schema2.decorators.some(
714
264
  (decoratorType) => decoratorType.name === decorator
715
265
  )))
@@ -724,11 +274,11 @@ function createHTMLRules(schema2, options) {
724
274
  // If not supported just write out the link text and href in plain text.
725
275
  {
726
276
  deserialize(el, next) {
727
- if (tagName(el) !== "a")
277
+ if (helpers.tagName(el) !== "a")
728
278
  return;
729
279
  const linkEnabled = schema2.annotations.some(
730
280
  (annotation) => annotation.name === "link"
731
- ), href = isElement(el) && el.getAttribute("href");
281
+ ), href = helpers.isElement(el) && el.getAttribute("href");
732
282
  return href ? linkEnabled ? {
733
283
  _type: "__annotation",
734
284
  markDef: {
@@ -742,16 +292,16 @@ function createHTMLRules(schema2, options) {
742
292
  },
743
293
  {
744
294
  deserialize(el, next) {
745
- if (isElement(el) && (tagName(el) === "td" || tagName(el) === "th"))
295
+ if (helpers.isElement(el) && (helpers.tagName(el) === "td" || helpers.tagName(el) === "th"))
746
296
  return {
747
- ...DEFAULT_BLOCK,
297
+ ...helpers.DEFAULT_BLOCK,
748
298
  children: next(el.childNodes)
749
299
  };
750
300
  }
751
301
  },
752
302
  {
753
303
  deserialize(el) {
754
- if (isElement(el) && tagName(el) === "img") {
304
+ if (helpers.isElement(el) && helpers.tagName(el) === "img") {
755
305
  const src = el.getAttribute("src") ?? void 0, alt = el.getAttribute("alt") ?? void 0, props = Object.fromEntries(
756
306
  Array.from(el.attributes).map((attr) => [attr.name, attr.value])
757
307
  ), ancestorOfLonelyChild = el?.parentElement?.parentElement?.getAttribute("data-lonely-child"), ancestorOfListItem = el.closest("li") !== null;
@@ -808,27 +358,27 @@ function createHTMLRules(schema2, options) {
808
358
  ];
809
359
  }
810
360
  function isEmphasis(el) {
811
- const style = isElement(el) && el.getAttribute("style");
361
+ const style = helpers.isElement(el) && el.getAttribute("style");
812
362
  return /font-style:italic/.test(style || "");
813
363
  }
814
364
  function isStrong(el) {
815
- const style = isElement(el) && el.getAttribute("style");
365
+ const style = helpers.isElement(el) && el.getAttribute("style");
816
366
  return /font-weight:700/.test(style || "") || /font-weight:600/.test(style || "");
817
367
  }
818
368
  function isUnderline(el) {
819
- const style = isElement(el) && el.getAttribute("style");
369
+ const style = helpers.isElement(el) && el.getAttribute("style");
820
370
  return /text-decoration:underline/.test(style || "");
821
371
  }
822
372
  function isNotion(el) {
823
- return isElement(el) && !!el.getAttribute("data-is-notion");
373
+ return helpers.isElement(el) && !!el.getAttribute("data-is-notion");
824
374
  }
825
375
  function createNotionRules() {
826
376
  return [
827
377
  {
828
378
  deserialize(el) {
829
- if (isElement(el) && tagName(el) === "span" && isNotion(el)) {
379
+ if (helpers.isElement(el) && helpers.tagName(el) === "span" && isNotion(el)) {
830
380
  const span = {
831
- ...DEFAULT_SPAN,
381
+ ...helpers.DEFAULT_SPAN,
832
382
  marks: [],
833
383
  text: el.textContent
834
384
  };
@@ -839,12 +389,12 @@ function createNotionRules() {
839
389
  ];
840
390
  }
841
391
  function getListItemStyle(el) {
842
- const style = isElement(el) && el.getAttribute("style");
392
+ const style = helpers.isElement(el) && el.getAttribute("style");
843
393
  if (style && style.match(/lfo\d+/))
844
394
  return style.match("lfo1") ? "bullet" : "number";
845
395
  }
846
396
  function getListItemLevel(el) {
847
- const style = isElement(el) && el.getAttribute("style");
397
+ const style = helpers.isElement(el) && el.getAttribute("style");
848
398
  if (!style)
849
399
  return;
850
400
  const levelMatch = style.match(/level\d+/);
@@ -854,18 +404,18 @@ function getListItemLevel(el) {
854
404
  return (level ? Number.parseInt(level, 10) : 1) || 1;
855
405
  }
856
406
  function isWordListElement(el) {
857
- return isElement(el) && el.className ? el.className === "MsoListParagraphCxSpFirst" || el.className === "MsoListParagraphCxSpMiddle" || el.className === "MsoListParagraphCxSpLast" : !1;
407
+ return helpers.isElement(el) && el.className ? el.className === "MsoListParagraphCxSpFirst" || el.className === "MsoListParagraphCxSpMiddle" || el.className === "MsoListParagraphCxSpLast" : !1;
858
408
  }
859
409
  function createWordRules() {
860
410
  return [
861
411
  {
862
412
  deserialize(el, next) {
863
- if (tagName(el) === "p" && isWordListElement(el))
413
+ if (helpers.tagName(el) === "p" && isWordListElement(el))
864
414
  return {
865
- ...DEFAULT_BLOCK,
415
+ ...helpers.DEFAULT_BLOCK,
866
416
  listItem: getListItemStyle(el),
867
417
  level: getListItemLevel(el),
868
- style: BLOCK_DEFAULT_STYLE,
418
+ style: helpers.BLOCK_DEFAULT_STYLE,
869
419
  children: next(el.childNodes)
870
420
  };
871
421
  }
@@ -898,8 +448,8 @@ class HtmlDeserializer {
898
448
  matchers: options.matchers
899
449
  });
900
450
  this.schema = schema2, this.keyGenerator = options.keyGenerator ?? keyGenerator, this.rules = [...rules, ...standardRules];
901
- const parseHtml = options.parseHtml || defaultParseHtml();
902
- this.parseHtml = (html) => preprocess(html, parseHtml, { unstable_whitespaceOnPasteMode }).body;
451
+ const parseHtml = options.parseHtml || helpers.defaultParseHtml();
452
+ this.parseHtml = (html) => helpers.preprocess(html, parseHtml, { unstable_whitespaceOnPasteMode }).body;
903
453
  }
904
454
  /**
905
455
  * Deserialize HTML.
@@ -909,11 +459,11 @@ class HtmlDeserializer {
909
459
  */
910
460
  deserialize = (html) => {
911
461
  this._markDefs = [];
912
- const { parseHtml } = this, fragment = parseHtml(html), children = Array.from(fragment.childNodes), blocks2 = trimWhitespace(
462
+ const { parseHtml } = this, fragment = parseHtml(html), children = Array.from(fragment.childNodes), blocks2 = helpers.trimWhitespace(
913
463
  this.schema,
914
- flattenNestedBlocks(
915
- { schema: this.schema, keyGenerator: this.keyGenerator },
916
- ensureRootIsBlocks(
464
+ helpers.flattenNestedBlocks(
465
+ { schema: this.schema },
466
+ helpers.ensureRootIsBlocks(
917
467
  this.schema,
918
468
  this.deserializeElements(children)
919
469
  )
@@ -947,7 +497,7 @@ class HtmlDeserializer {
947
497
  */
948
498
  deserializeElement = (element) => {
949
499
  const next = (elements) => {
950
- if (isNodeList(elements))
500
+ if (helpers.isNodeList(elements))
951
501
  return this.deserializeElements(Array.from(elements));
952
502
  if (Array.isArray(elements))
953
503
  return this.deserializeElements(elements);
@@ -962,7 +512,7 @@ class HtmlDeserializer {
962
512
  const rule = this.rules[i];
963
513
  if (!rule.deserialize)
964
514
  continue;
965
- const ret = rule.deserialize(element, next, block), type = resolveJsType(ret);
515
+ const ret = rule.deserialize(element, next, block), type = helpers.resolveJsType(ret);
966
516
  if (type !== "array" && type !== "object" && type !== "null" && type !== "undefined")
967
517
  throw new Error(
968
518
  `A rule returned an invalid deserialized representation: "${node}".`
@@ -971,15 +521,15 @@ class HtmlDeserializer {
971
521
  {
972
522
  if (ret === null)
973
523
  throw new Error("Deserializer rule returned `null`");
974
- Array.isArray(ret) ? node = ret : isPlaceholderDecorator(ret) ? node = this.deserializeDecorator(ret) : isPlaceholderAnnotation(ret) ? node = this.deserializeAnnotation(ret) : node = ret;
524
+ Array.isArray(ret) ? node = ret : helpers.isPlaceholderDecorator(ret) ? node = this.deserializeDecorator(ret) : helpers.isPlaceholderAnnotation(ret) ? node = this.deserializeAnnotation(ret) : node = ret;
975
525
  }
976
- if (ret && !Array.isArray(ret) && isMinimalBlock(ret) && "listItem" in ret) {
526
+ if (ret && !Array.isArray(ret) && helpers.isMinimalBlock(ret) && "listItem" in ret) {
977
527
  let parent = element.parentNode?.parentNode;
978
- for (; parent && tagName(parent) === "li"; )
528
+ for (; parent && helpers.tagName(parent) === "li"; )
979
529
  parent = parent.parentNode?.parentNode, ret.level = ret.level ? ret.level + 1 : 1;
980
530
  }
981
- ret && !Array.isArray(ret) && isMinimalBlock(ret) && ret.style === "blockquote" && ret.children.forEach((child, index) => {
982
- isMinimalSpan(child) && child.text === "\r" && (child.text = `
531
+ ret && !Array.isArray(ret) && helpers.isMinimalBlock(ret) && ret.style === "blockquote" && ret.children.forEach((child, index) => {
532
+ helpers.isMinimalSpan(child) && child.text === "\r" && (child.text = `
983
533
  `, (index === 0 || index === ret.children.length - 1) && ret.children.splice(index, 1));
984
534
  });
985
535
  break;
@@ -996,9 +546,9 @@ class HtmlDeserializer {
996
546
  */
997
547
  deserializeDecorator = (decorator) => {
998
548
  const { name } = decorator, applyDecorator = (node) => {
999
- if (isPlaceholderDecorator(node))
549
+ if (helpers.isPlaceholderDecorator(node))
1000
550
  return this.deserializeDecorator(node);
1001
- if (isMinimalSpan(node))
551
+ if (helpers.isMinimalSpan(node))
1002
552
  node.marks = node.marks || [], node.text.trim() && node.marks.unshift(name);
1003
553
  else if ("children" in node && Array.isArray(node.children)) {
1004
554
  const block = node;
@@ -1022,9 +572,9 @@ class HtmlDeserializer {
1022
572
  const { markDef } = annotation;
1023
573
  this._markDefs.push(markDef);
1024
574
  const applyAnnotation = (node) => {
1025
- if (isPlaceholderAnnotation(node))
575
+ if (helpers.isPlaceholderAnnotation(node))
1026
576
  return this.deserializeAnnotation(node);
1027
- if (isMinimalSpan(node))
577
+ if (helpers.isMinimalSpan(node))
1028
578
  node.marks = node.marks || [], node.text.trim() && node.marks.unshift(markDef._key);
1029
579
  else if ("children" in node && Array.isArray(node.children)) {
1030
580
  const block = node;