react-next-editor-js 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +877 -0
  3. package/dist/chunk-3QWXTDLY.cjs +486 -0
  4. package/dist/chunk-3QWXTDLY.cjs.map +1 -0
  5. package/dist/chunk-5F6SPYCN.cjs +180 -0
  6. package/dist/chunk-5F6SPYCN.cjs.map +1 -0
  7. package/dist/chunk-6NTSXJX4.js +174 -0
  8. package/dist/chunk-6NTSXJX4.js.map +1 -0
  9. package/dist/chunk-7VYJDBH7.js +261 -0
  10. package/dist/chunk-7VYJDBH7.js.map +1 -0
  11. package/dist/chunk-DBSFCCBG.cjs +1712 -0
  12. package/dist/chunk-DBSFCCBG.cjs.map +1 -0
  13. package/dist/chunk-EFE6RHDL.cjs +4 -0
  14. package/dist/chunk-EFE6RHDL.cjs.map +1 -0
  15. package/dist/chunk-G6YRIEK4.js +3 -0
  16. package/dist/chunk-G6YRIEK4.js.map +1 -0
  17. package/dist/chunk-GFNFJ3FL.cjs +119 -0
  18. package/dist/chunk-GFNFJ3FL.cjs.map +1 -0
  19. package/dist/chunk-IG2YLUFW.js +114 -0
  20. package/dist/chunk-IG2YLUFW.js.map +1 -0
  21. package/dist/chunk-JQXTWLHL.js +176 -0
  22. package/dist/chunk-JQXTWLHL.js.map +1 -0
  23. package/dist/chunk-NJCEHQV3.cjs +454 -0
  24. package/dist/chunk-NJCEHQV3.cjs.map +1 -0
  25. package/dist/chunk-O4GTLC3T.js +478 -0
  26. package/dist/chunk-O4GTLC3T.js.map +1 -0
  27. package/dist/chunk-ODHABIIC.cjs +82 -0
  28. package/dist/chunk-ODHABIIC.cjs.map +1 -0
  29. package/dist/chunk-PZ5AY32C.js +9 -0
  30. package/dist/chunk-PZ5AY32C.js.map +1 -0
  31. package/dist/chunk-Q7SFCCGT.cjs +11 -0
  32. package/dist/chunk-Q7SFCCGT.cjs.map +1 -0
  33. package/dist/chunk-QIUIYBCZ.js +80 -0
  34. package/dist/chunk-QIUIYBCZ.js.map +1 -0
  35. package/dist/chunk-QROUNVQK.js +450 -0
  36. package/dist/chunk-QROUNVQK.js.map +1 -0
  37. package/dist/chunk-T6FR37IC.js +41 -0
  38. package/dist/chunk-T6FR37IC.js.map +1 -0
  39. package/dist/chunk-TI44I654.cjs +265 -0
  40. package/dist/chunk-TI44I654.cjs.map +1 -0
  41. package/dist/chunk-TXPLBAH5.cjs +47 -0
  42. package/dist/chunk-TXPLBAH5.cjs.map +1 -0
  43. package/dist/chunk-U3O54IYI.cjs +187 -0
  44. package/dist/chunk-U3O54IYI.cjs.map +1 -0
  45. package/dist/chunk-VLC7SZMT.js +1669 -0
  46. package/dist/chunk-VLC7SZMT.js.map +1 -0
  47. package/dist/core/index.cjs +232 -0
  48. package/dist/core/index.cjs.map +1 -0
  49. package/dist/core/index.d.cts +122 -0
  50. package/dist/core/index.d.ts +122 -0
  51. package/dist/core/index.js +7 -0
  52. package/dist/core/index.js.map +1 -0
  53. package/dist/defaults-EQD5QKCU.js +4 -0
  54. package/dist/defaults-EQD5QKCU.js.map +1 -0
  55. package/dist/defaults-MLYXD2BG.cjs +49 -0
  56. package/dist/defaults-MLYXD2BG.cjs.map +1 -0
  57. package/dist/docx-BUrf4PFj.d.ts +49 -0
  58. package/dist/docx-DLfSdvXm.d.cts +49 -0
  59. package/dist/docx-LDETXV3L.js +5 -0
  60. package/dist/docx-LDETXV3L.js.map +1 -0
  61. package/dist/docx-N2LKIOK3.cjs +14 -0
  62. package/dist/docx-N2LKIOK3.cjs.map +1 -0
  63. package/dist/export/index.cjs +54 -0
  64. package/dist/export/index.cjs.map +1 -0
  65. package/dist/export/index.d.cts +60 -0
  66. package/dist/export/index.d.ts +60 -0
  67. package/dist/export/index.js +9 -0
  68. package/dist/export/index.js.map +1 -0
  69. package/dist/html-5BXJPQU3.js +7 -0
  70. package/dist/html-5BXJPQU3.js.map +1 -0
  71. package/dist/html-KU2KHLRF.cjs +24 -0
  72. package/dist/html-KU2KHLRF.cjs.map +1 -0
  73. package/dist/import/index.cjs +15 -0
  74. package/dist/import/index.cjs.map +1 -0
  75. package/dist/import/index.d.cts +37 -0
  76. package/dist/import/index.d.ts +37 -0
  77. package/dist/import/index.js +6 -0
  78. package/dist/import/index.js.map +1 -0
  79. package/dist/index.cjs +1035 -0
  80. package/dist/index.cjs.map +1 -0
  81. package/dist/index.d.cts +248 -0
  82. package/dist/index.d.ts +248 -0
  83. package/dist/index.js +885 -0
  84. package/dist/index.js.map +1 -0
  85. package/dist/persistence/index.cjs +37 -0
  86. package/dist/persistence/index.cjs.map +1 -0
  87. package/dist/persistence/index.d.cts +279 -0
  88. package/dist/persistence/index.d.ts +279 -0
  89. package/dist/persistence/index.js +4 -0
  90. package/dist/persistence/index.js.map +1 -0
  91. package/dist/sanitize-7IZ-SW1f.d.ts +361 -0
  92. package/dist/sanitize-CvmgqbsA.d.cts +361 -0
  93. package/dist/server/index.cjs +400 -0
  94. package/dist/server/index.cjs.map +1 -0
  95. package/dist/server/index.d.cts +229 -0
  96. package/dist/server/index.d.ts +229 -0
  97. package/dist/server/index.js +390 -0
  98. package/dist/server/index.js.map +1 -0
  99. package/dist/styles.css +680 -0
  100. package/dist/types-B4z0Quvv.d.cts +193 -0
  101. package/dist/types-B4z0Quvv.d.ts +193 -0
  102. package/package.json +183 -0
@@ -0,0 +1,1712 @@
1
+ 'use strict';
2
+
3
+ var chunkTXPLBAH5_cjs = require('./chunk-TXPLBAH5.cjs');
4
+ var chunk5F6SPYCN_cjs = require('./chunk-5F6SPYCN.cjs');
5
+ var chunkU3O54IYI_cjs = require('./chunk-U3O54IYI.cjs');
6
+ var chunkQ7SFCCGT_cjs = require('./chunk-Q7SFCCGT.cjs');
7
+ var prosemirrorModel = require('prosemirror-model');
8
+ var prosemirrorTables = require('prosemirror-tables');
9
+ var prosemirrorHistory = require('prosemirror-history');
10
+ var prosemirrorCommands = require('prosemirror-commands');
11
+ var prosemirrorSchemaList = require('prosemirror-schema-list');
12
+ var prosemirrorState = require('prosemirror-state');
13
+ var prosemirrorDropcursor = require('prosemirror-dropcursor');
14
+ var prosemirrorGapcursor = require('prosemirror-gapcursor');
15
+ var prosemirrorInputrules = require('prosemirror-inputrules');
16
+ var prosemirrorKeymap = require('prosemirror-keymap');
17
+ var prosemirrorView = require('prosemirror-view');
18
+
19
+ // src/core/schema/nodes.ts
20
+ var nodes_exports = {};
21
+ chunkQ7SFCCGT_cjs.__export(nodes_exports, {
22
+ blockquote: () => blockquote,
23
+ bullet_list: () => bullet_list,
24
+ doc: () => doc,
25
+ hard_break: () => hard_break,
26
+ heading: () => heading,
27
+ horizontal_rule: () => horizontal_rule,
28
+ image: () => image,
29
+ list_item: () => list_item,
30
+ nodeAlign: () => nodeAlign,
31
+ ordered_list: () => ordered_list,
32
+ page_break: () => page_break,
33
+ paragraph: () => paragraph,
34
+ text: () => text
35
+ });
36
+
37
+ // src/core/schema/attrs.ts
38
+ var ALIGN_VALUES = [
39
+ "left",
40
+ "center",
41
+ "right",
42
+ "justify"
43
+ ];
44
+ var MAX_INDENT = 12;
45
+ var INDENT_STEP_EM = 3;
46
+ var blockAttrs = {
47
+ align: { default: null },
48
+ indent: { default: 0 },
49
+ lineHeight: { default: null }
50
+ };
51
+ function readBlockAttrs(dom) {
52
+ const textAlign = dom.style.textAlign || dom.getAttribute("align") || "";
53
+ const align = ALIGN_VALUES.includes(textAlign) ? textAlign : null;
54
+ let indent = 0;
55
+ const marginLeft = dom.style.marginLeft;
56
+ if (marginLeft) {
57
+ const em2 = parseFloat(marginLeft);
58
+ if (Number.isFinite(em2) && em2 > 0) {
59
+ const unit = /px$/.test(marginLeft) ? em2 / 16 : em2;
60
+ indent = Math.min(MAX_INDENT, Math.max(0, Math.round(unit / INDENT_STEP_EM)));
61
+ }
62
+ }
63
+ let lineHeight = null;
64
+ const lh = dom.style.lineHeight;
65
+ if (lh) {
66
+ const value = parseFloat(lh);
67
+ if (Number.isFinite(value) && value > 0 && value <= 10) {
68
+ lineHeight = Math.round(value * 100) / 100;
69
+ }
70
+ }
71
+ return { align, indent, lineHeight };
72
+ }
73
+ function blockDOMAttrs(node, extra) {
74
+ const attrs = node.attrs;
75
+ const styles = [];
76
+ const align = chunkTXPLBAH5_cjs.cssAlign(attrs.align);
77
+ if (align) styles.push(`text-align: ${align}`);
78
+ const indent = chunkTXPLBAH5_cjs.cssInteger(attrs.indent, 0, MAX_INDENT);
79
+ if (indent && indent > 0) styles.push(`margin-left: ${indent * INDENT_STEP_EM}em`);
80
+ const lineHeight = chunkTXPLBAH5_cjs.cssNumber(attrs.lineHeight, 0.1, 10);
81
+ if (lineHeight) styles.push(`line-height: ${lineHeight}`);
82
+ const out = { ...extra };
83
+ if (styles.length) out.style = styles.join("; ");
84
+ return out;
85
+ }
86
+ function clampIndent(value) {
87
+ if (!Number.isFinite(value)) return 0;
88
+ return Math.min(MAX_INDENT, Math.max(0, Math.round(value)));
89
+ }
90
+ function isTextAlign(value) {
91
+ return typeof value === "string" && ALIGN_VALUES.includes(value);
92
+ }
93
+
94
+ // src/core/schema/nodes.ts
95
+ var doc = { content: "block+" };
96
+ var text = { group: "inline" };
97
+ var paragraph = {
98
+ group: "block",
99
+ content: "inline*",
100
+ attrs: { ...blockAttrs },
101
+ parseDOM: [{ tag: "p", getAttrs: (dom) => readBlockAttrs(dom) }],
102
+ toDOM(node) {
103
+ return ["p", blockDOMAttrs(node), 0];
104
+ }
105
+ };
106
+ var heading = {
107
+ group: "block",
108
+ content: "inline*",
109
+ defining: true,
110
+ attrs: { level: { default: 1 }, ...blockAttrs },
111
+ parseDOM: [1, 2, 3, 4, 5, 6].map((level) => ({
112
+ tag: `h${level}`,
113
+ getAttrs: (dom) => ({
114
+ level,
115
+ ...readBlockAttrs(dom)
116
+ })
117
+ })),
118
+ toDOM(node) {
119
+ const level = node.attrs.level || 1;
120
+ return [`h${Math.min(6, Math.max(1, level))}`, blockDOMAttrs(node), 0];
121
+ }
122
+ };
123
+ var blockquote = {
124
+ group: "block",
125
+ content: "block+",
126
+ defining: true,
127
+ parseDOM: [{ tag: "blockquote" }],
128
+ toDOM() {
129
+ return ["blockquote", { class: "rne-blockquote" }, 0];
130
+ }
131
+ };
132
+ var horizontal_rule = {
133
+ group: "block",
134
+ parseDOM: [{ tag: "hr" }],
135
+ toDOM() {
136
+ return ["hr", { class: "rne-hr" }];
137
+ }
138
+ };
139
+ var page_break = {
140
+ group: "block",
141
+ atom: true,
142
+ selectable: true,
143
+ parseDOM: [{ tag: "div[data-page-break]" }, { tag: "div.rne-page-break" }],
144
+ toDOM() {
145
+ return [
146
+ "div",
147
+ { "data-page-break": "true", class: "rne-page-break", contenteditable: "false" }
148
+ ];
149
+ }
150
+ };
151
+ var hard_break = {
152
+ inline: true,
153
+ group: "inline",
154
+ selectable: false,
155
+ parseDOM: [{ tag: "br" }],
156
+ toDOM() {
157
+ return ["br"];
158
+ }
159
+ };
160
+ var MAX_IMAGE_WIDTH = 2e3;
161
+ var image = {
162
+ inline: true,
163
+ group: "inline",
164
+ draggable: true,
165
+ attrs: {
166
+ src: {},
167
+ alt: { default: null },
168
+ title: { default: null },
169
+ width: { default: null }
170
+ },
171
+ parseDOM: [
172
+ {
173
+ tag: "img[src]",
174
+ getAttrs(dom) {
175
+ const el = dom;
176
+ const src = chunk5F6SPYCN_cjs.sanitizeImageSrc(el.getAttribute("src"));
177
+ if (!src) return false;
178
+ const widthAttr = el.getAttribute("width") ?? el.style.width;
179
+ let width = null;
180
+ if (widthAttr) {
181
+ const num = parseInt(widthAttr, 10);
182
+ if (Number.isFinite(num) && num > 0) width = Math.min(MAX_IMAGE_WIDTH, num);
183
+ }
184
+ return {
185
+ src,
186
+ alt: el.getAttribute("alt"),
187
+ title: el.getAttribute("title"),
188
+ width
189
+ };
190
+ }
191
+ }
192
+ ],
193
+ toDOM(node) {
194
+ const { src, alt, title, width } = node.attrs;
195
+ const safeSrc = chunk5F6SPYCN_cjs.sanitizeImageSrc(src) ?? "";
196
+ const attrs = { src: safeSrc, class: "rne-image" };
197
+ if (alt) attrs.alt = alt;
198
+ if (title) attrs.title = title;
199
+ const safeWidth = chunkTXPLBAH5_cjs.cssInteger(width, 1, MAX_IMAGE_WIDTH);
200
+ if (safeWidth) attrs.style = `width: ${safeWidth}px`;
201
+ return ["img", attrs];
202
+ }
203
+ };
204
+ var list_item = {
205
+ content: "paragraph block*",
206
+ defining: true,
207
+ attrs: { checked: { default: null } },
208
+ parseDOM: [
209
+ {
210
+ tag: "li",
211
+ getAttrs(dom) {
212
+ const el = dom;
213
+ const dc = el.getAttribute("data-checked");
214
+ if (dc === "true") return { checked: true };
215
+ if (dc === "false") return { checked: false };
216
+ return { checked: null };
217
+ }
218
+ }
219
+ ],
220
+ toDOM(node) {
221
+ const checked = node.attrs.checked;
222
+ if (checked === null) return ["li", 0];
223
+ return [
224
+ "li",
225
+ { "data-checked": String(checked), class: "rne-task-item" },
226
+ ["span", { class: "rne-task-checkbox", contenteditable: "false" }],
227
+ ["div", { class: "rne-task-content" }, 0]
228
+ ];
229
+ }
230
+ };
231
+ var bullet_list = {
232
+ group: "block",
233
+ content: "list_item+",
234
+ attrs: { kind: { default: "bullet" } },
235
+ parseDOM: [
236
+ {
237
+ tag: "ul",
238
+ getAttrs(dom) {
239
+ const el = dom;
240
+ const isTask = el.getAttribute("data-type") === "task" || el.classList.contains("rne-task-list") || !!el.querySelector("li[data-checked]");
241
+ return { kind: isTask ? "task" : "bullet" };
242
+ }
243
+ }
244
+ ],
245
+ toDOM(node) {
246
+ const kind = node.attrs.kind;
247
+ return kind === "task" ? ["ul", { "data-type": "task", class: "rne-task-list" }, 0] : ["ul", { class: "rne-bullet-list" }, 0];
248
+ }
249
+ };
250
+ var ordered_list = {
251
+ group: "block",
252
+ content: "list_item+",
253
+ attrs: { order: { default: 1 } },
254
+ parseDOM: [
255
+ {
256
+ tag: "ol",
257
+ getAttrs(dom) {
258
+ const el = dom;
259
+ const start = el.getAttribute("start");
260
+ const order = start ? parseInt(start, 10) : 1;
261
+ return { order: Number.isFinite(order) && order > 0 ? order : 1 };
262
+ }
263
+ }
264
+ ],
265
+ toDOM(node) {
266
+ const order = node.attrs.order || 1;
267
+ return order === 1 ? ["ol", { class: "rne-ordered-list" }, 0] : ["ol", { order, start: order, class: "rne-ordered-list" }, 0];
268
+ }
269
+ };
270
+ function nodeAlign(node) {
271
+ return node.attrs?.align ?? null;
272
+ }
273
+
274
+ // src/core/schema/marks.ts
275
+ var marks_exports = {};
276
+ chunkQ7SFCCGT_cjs.__export(marks_exports, {
277
+ code: () => code,
278
+ em: () => em,
279
+ fontFamily: () => fontFamily,
280
+ fontSize: () => fontSize,
281
+ highlight: () => highlight,
282
+ link: () => link,
283
+ strikethrough: () => strikethrough,
284
+ strong: () => strong,
285
+ subscript: () => subscript,
286
+ superscript: () => superscript,
287
+ textColor: () => textColor,
288
+ underline: () => underline
289
+ });
290
+ var strong = {
291
+ parseDOM: [
292
+ { tag: "strong" },
293
+ { tag: "b", getAttrs: (node) => node.style.fontWeight !== "normal" && null },
294
+ { style: "font-weight=400", clearMark: (m) => m.type.name === "strong" },
295
+ {
296
+ style: "font-weight",
297
+ getAttrs: (value) => /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null
298
+ }
299
+ ],
300
+ toDOM() {
301
+ return ["strong", 0];
302
+ }
303
+ };
304
+ var em = {
305
+ parseDOM: [
306
+ { tag: "i" },
307
+ { tag: "em" },
308
+ { style: "font-style=italic" },
309
+ { style: "font-style=normal", clearMark: (m) => m.type.name === "em" }
310
+ ],
311
+ toDOM() {
312
+ return ["em", 0];
313
+ }
314
+ };
315
+ var underline = {
316
+ parseDOM: [
317
+ { tag: "u" },
318
+ {
319
+ style: "text-decoration",
320
+ getAttrs: (value) => value.includes("underline") && null
321
+ },
322
+ {
323
+ style: "text-decoration-line",
324
+ getAttrs: (value) => value.includes("underline") && null
325
+ }
326
+ ],
327
+ toDOM() {
328
+ return ["u", 0];
329
+ }
330
+ };
331
+ var strikethrough = {
332
+ parseDOM: [
333
+ { tag: "s" },
334
+ { tag: "del" },
335
+ { tag: "strike" },
336
+ {
337
+ style: "text-decoration",
338
+ getAttrs: (value) => value.includes("line-through") && null
339
+ }
340
+ ],
341
+ toDOM() {
342
+ return ["s", 0];
343
+ }
344
+ };
345
+ var superscript = {
346
+ excludes: "subscript",
347
+ parseDOM: [{ tag: "sup" }, { style: "vertical-align=super" }],
348
+ toDOM() {
349
+ return ["sup", 0];
350
+ }
351
+ };
352
+ var subscript = {
353
+ excludes: "superscript",
354
+ parseDOM: [{ tag: "sub" }, { style: "vertical-align=sub" }],
355
+ toDOM() {
356
+ return ["sub", 0];
357
+ }
358
+ };
359
+ var code = {
360
+ parseDOM: [{ tag: "code" }],
361
+ toDOM() {
362
+ return ["code", { class: "rne-inline-code" }, 0];
363
+ }
364
+ };
365
+ var link = {
366
+ attrs: {
367
+ href: {},
368
+ title: { default: null },
369
+ target: { default: "_blank" }
370
+ },
371
+ inclusive: false,
372
+ parseDOM: [
373
+ {
374
+ tag: "a[href]",
375
+ getAttrs(dom) {
376
+ const el = dom;
377
+ const rawHref = el.getAttribute("href");
378
+ const href = chunk5F6SPYCN_cjs.sanitizeUrl(rawHref);
379
+ if (!href) return false;
380
+ return {
381
+ href,
382
+ title: el.getAttribute("title"),
383
+ target: el.getAttribute("target") ?? "_blank"
384
+ };
385
+ }
386
+ }
387
+ ],
388
+ toDOM(mark) {
389
+ const href = chunk5F6SPYCN_cjs.sanitizeUrl(mark.attrs.href) ?? "";
390
+ const target = mark.attrs.target || "_blank";
391
+ return [
392
+ "a",
393
+ {
394
+ href,
395
+ title: mark.attrs.title ?? null,
396
+ target,
397
+ rel: "noopener noreferrer nofollow"
398
+ },
399
+ 0
400
+ ];
401
+ }
402
+ };
403
+ var fontFamily = {
404
+ attrs: { family: {} },
405
+ parseDOM: [
406
+ {
407
+ style: "font-family",
408
+ getAttrs: (value) => {
409
+ const family = chunkTXPLBAH5_cjs.cssFontFamily(value);
410
+ return family ? { family } : false;
411
+ }
412
+ }
413
+ ],
414
+ toDOM(mark) {
415
+ const family = chunkTXPLBAH5_cjs.cssFontFamily(mark.attrs.family);
416
+ return family ? ["span", { style: `font-family: ${family}` }, 0] : ["span", 0];
417
+ }
418
+ };
419
+ var fontSize = {
420
+ attrs: { size: {} },
421
+ parseDOM: [
422
+ {
423
+ style: "font-size",
424
+ getAttrs: (value) => {
425
+ const size = parseFontSize(value);
426
+ return size ? { size } : false;
427
+ }
428
+ }
429
+ ],
430
+ toDOM(mark) {
431
+ const size = chunkTXPLBAH5_cjs.cssNumber(mark.attrs.size, 1, 1638);
432
+ return size ? ["span", { style: `font-size: ${size}pt` }, 0] : ["span", 0];
433
+ }
434
+ };
435
+ var textColor = {
436
+ attrs: { color: {} },
437
+ parseDOM: [
438
+ {
439
+ style: "color",
440
+ getAttrs: (value) => {
441
+ const color = chunkTXPLBAH5_cjs.normalizeCssColor(value);
442
+ return color ? { color } : false;
443
+ }
444
+ }
445
+ ],
446
+ toDOM(mark) {
447
+ const color = chunkTXPLBAH5_cjs.normalizeCssColor(mark.attrs.color);
448
+ return color ? ["span", { style: `color: ${color}` }, 0] : ["span", 0];
449
+ }
450
+ };
451
+ var highlight = {
452
+ attrs: { color: { default: "#fff2a8" } },
453
+ parseDOM: [
454
+ { tag: "mark" },
455
+ {
456
+ style: "background-color",
457
+ getAttrs: (value) => {
458
+ const color = chunkTXPLBAH5_cjs.normalizeCssColor(value);
459
+ return color ? { color } : false;
460
+ }
461
+ }
462
+ ],
463
+ toDOM(mark) {
464
+ const color = chunkTXPLBAH5_cjs.normalizeCssColor(mark.attrs.color) ?? "#fff2a8";
465
+ return ["mark", { style: `background-color: ${color}` }, 0];
466
+ }
467
+ };
468
+ function parseFontSize(value) {
469
+ const match = /(\d+(?:\.\d+)?)\s*(pt|px)?/.exec(value);
470
+ if (!match) return null;
471
+ const num = parseFloat(match[1]);
472
+ if (!Number.isFinite(num) || num <= 0) return null;
473
+ const pt = (match[2] ?? "pt") === "px" ? num * 0.75 : num;
474
+ return chunkTXPLBAH5_cjs.cssNumber(Math.round(pt * 100) / 100, 1, 1638);
475
+ }
476
+
477
+ // src/core/schema/schema.ts
478
+ function buildSchema(features = {}) {
479
+ const f = { ...chunkU3O54IYI_cjs.DEFAULT_FEATURES, ...features };
480
+ const nodes = {
481
+ doc,
482
+ paragraph
483
+ };
484
+ if (f.headings) nodes.heading = heading;
485
+ if (f.blockquote) nodes.blockquote = blockquote;
486
+ if (f.horizontalRule) nodes.horizontal_rule = horizontal_rule;
487
+ if (f.bulletList || f.orderedList || f.taskList) {
488
+ nodes.list_item = list_item;
489
+ if (f.bulletList || f.taskList) nodes.bullet_list = bullet_list;
490
+ if (f.orderedList) nodes.ordered_list = ordered_list;
491
+ }
492
+ if (f.table) {
493
+ const tnodes = prosemirrorTables.tableNodes({
494
+ tableGroup: "block",
495
+ cellContent: "block+",
496
+ cellAttributes: {
497
+ background: {
498
+ default: null,
499
+ getFromDOM(dom) {
500
+ return dom.style.backgroundColor || null;
501
+ },
502
+ setDOMAttr(value, attrs) {
503
+ const color = chunkTXPLBAH5_cjs.normalizeCssColor(value);
504
+ if (color) {
505
+ attrs.style = `${attrs.style || ""}background-color: ${color};`;
506
+ }
507
+ }
508
+ },
509
+ align: {
510
+ default: null,
511
+ getFromDOM(dom) {
512
+ return dom.style.textAlign || null;
513
+ },
514
+ setDOMAttr(value, attrs) {
515
+ const align = chunkTXPLBAH5_cjs.cssAlign(value);
516
+ if (align) {
517
+ attrs.style = `${attrs.style || ""}text-align: ${align};`;
518
+ }
519
+ }
520
+ }
521
+ }
522
+ });
523
+ Object.assign(nodes, tnodes);
524
+ }
525
+ if (f.image) nodes.image = image;
526
+ if (f.pageBreak) nodes.page_break = page_break;
527
+ nodes.text = text;
528
+ nodes.hard_break = hard_break;
529
+ const marks = {};
530
+ if (f.link) marks.link = link;
531
+ if (f.bold) marks.strong = strong;
532
+ if (f.italic) marks.em = em;
533
+ if (f.underline) marks.underline = underline;
534
+ if (f.strikethrough) marks.strikethrough = strikethrough;
535
+ if (f.superscript) marks.superscript = superscript;
536
+ if (f.subscript) marks.subscript = subscript;
537
+ if (f.code) marks.code = code;
538
+ if (f.fontFamily) marks.fontFamily = fontFamily;
539
+ if (f.fontSize) marks.fontSize = fontSize;
540
+ if (f.textColor) marks.textColor = textColor;
541
+ if (f.highlight) marks.highlight = highlight;
542
+ return new prosemirrorModel.Schema({ nodes, marks });
543
+ }
544
+ var defaultSchema = buildSchema();
545
+
546
+ // src/core/commands/helpers.ts
547
+ function isMarkActive(state, type) {
548
+ const { from, $from, to, empty } = state.selection;
549
+ if (empty) {
550
+ return !!type.isInSet(state.storedMarks || $from.marks());
551
+ }
552
+ return state.doc.rangeHasMark(from, to, type);
553
+ }
554
+ function getActiveMarkAttrs(state, type) {
555
+ const { $from, empty } = state.selection;
556
+ if (empty) {
557
+ const mark = type.isInSet(state.storedMarks || $from.marks());
558
+ return mark ? mark.attrs : null;
559
+ }
560
+ const { from, to } = state.selection;
561
+ let attrs = null;
562
+ state.doc.nodesBetween(from, to, (node) => {
563
+ if (attrs) return false;
564
+ const mark = node.marks.find((m) => m.type === type);
565
+ if (mark) attrs = mark.attrs;
566
+ return true;
567
+ });
568
+ return attrs;
569
+ }
570
+ function isBlockActive(state, type, attrs) {
571
+ const { from, to } = state.selection;
572
+ let found = false;
573
+ let allMatch = true;
574
+ state.doc.nodesBetween(from, to, (node) => {
575
+ if (node.type.isTextblock || node.type === type) {
576
+ if (node.type === type && matchAttrs(node.attrs, attrs)) {
577
+ found = true;
578
+ } else if (node.type.isTextblock) {
579
+ if (!(node.type === type && matchAttrs(node.attrs, attrs))) allMatch = false;
580
+ }
581
+ }
582
+ return true;
583
+ });
584
+ return found && allMatch;
585
+ }
586
+ function matchAttrs(nodeAttrs, attrs) {
587
+ if (!attrs) return true;
588
+ return Object.keys(attrs).every((key) => nodeAttrs[key] === attrs[key]);
589
+ }
590
+ function isInNode(state, type) {
591
+ const { $from } = state.selection;
592
+ for (let depth = $from.depth; depth > 0; depth--) {
593
+ if ($from.node(depth).type === type) return true;
594
+ }
595
+ return false;
596
+ }
597
+ function defaultEnabled(run) {
598
+ return (state) => run(state, void 0, void 0);
599
+ }
600
+
601
+ // src/core/commands/marks.ts
602
+ function setMark(type, attrs) {
603
+ return (state, dispatch) => {
604
+ const { selection } = state;
605
+ if (dispatch) {
606
+ const tr = state.tr;
607
+ if (selection.empty) {
608
+ tr.addStoredMark(type.create(attrs));
609
+ } else {
610
+ for (const range of selection.ranges) {
611
+ const { $from, $to } = range;
612
+ tr.addMark($from.pos, $to.pos, type.create(attrs));
613
+ }
614
+ tr.scrollIntoView();
615
+ }
616
+ dispatch(tr);
617
+ }
618
+ return true;
619
+ };
620
+ }
621
+ function unsetMark(type) {
622
+ return (state, dispatch) => {
623
+ const { selection } = state;
624
+ if (dispatch) {
625
+ const tr = state.tr;
626
+ if (selection.empty) {
627
+ tr.removeStoredMark(type);
628
+ } else {
629
+ for (const range of selection.ranges) {
630
+ tr.removeMark(range.$from.pos, range.$to.pos, type);
631
+ }
632
+ }
633
+ dispatch(tr);
634
+ }
635
+ return true;
636
+ };
637
+ }
638
+ function toggle(type) {
639
+ const run = prosemirrorCommands.toggleMark(type);
640
+ return {
641
+ run,
642
+ isActive: (state) => isMarkActive(state, type),
643
+ isEnabled: (state) => run(state, void 0, void 0)
644
+ };
645
+ }
646
+ function createMarkCommands(schema) {
647
+ const cmds = {};
648
+ const m = schema.marks;
649
+ if (m.strong) cmds.bold = toggle(m.strong);
650
+ if (m.em) cmds.italic = toggle(m.em);
651
+ if (m.underline) cmds.underline = toggle(m.underline);
652
+ if (m.strikethrough) cmds.strikethrough = toggle(m.strikethrough);
653
+ if (m.superscript) cmds.superscript = toggle(m.superscript);
654
+ if (m.subscript) cmds.subscript = toggle(m.subscript);
655
+ if (m.code) cmds.code = toggle(m.code);
656
+ return cmds;
657
+ }
658
+ function createParametricMarkCommands(schema) {
659
+ const m = schema.marks;
660
+ return {
661
+ setFontFamily: (family) => m.fontFamily ? setMark(m.fontFamily, { family }) : noop,
662
+ clearFontFamily: () => m.fontFamily ? unsetMark(m.fontFamily) : noop,
663
+ setFontSize: (size) => m.fontSize ? setMark(m.fontSize, { size }) : noop,
664
+ clearFontSize: () => m.fontSize ? unsetMark(m.fontSize) : noop,
665
+ setTextColor: (color) => m.textColor ? setMark(m.textColor, { color }) : noop,
666
+ clearTextColor: () => m.textColor ? unsetMark(m.textColor) : noop,
667
+ setHighlight: (color) => m.highlight ? setMark(m.highlight, { color }) : noop,
668
+ clearHighlight: () => m.highlight ? unsetMark(m.highlight) : noop,
669
+ getActiveFontFamily: (state) => m.fontFamily ? getActiveMarkAttrs(state, m.fontFamily)?.family ?? null : null,
670
+ getActiveFontSize: (state) => m.fontSize ? getActiveMarkAttrs(state, m.fontSize)?.size ?? null : null,
671
+ getActiveTextColor: (state) => m.textColor ? getActiveMarkAttrs(state, m.textColor)?.color ?? null : null
672
+ };
673
+ }
674
+ var noop = () => false;
675
+ var noop2 = () => false;
676
+ function setTextblockAttr(attr, value) {
677
+ return (state, dispatch) => {
678
+ const { from, to } = state.selection;
679
+ let applicable = false;
680
+ const tr = state.tr;
681
+ state.doc.nodesBetween(from, to, (node, pos) => {
682
+ if (node.isTextblock && attr in (node.type.spec.attrs ?? {})) {
683
+ applicable = true;
684
+ if (dispatch) tr.setNodeAttribute(pos, attr, value);
685
+ }
686
+ return true;
687
+ });
688
+ if (!applicable) return false;
689
+ if (dispatch) dispatch(tr.scrollIntoView());
690
+ return true;
691
+ };
692
+ }
693
+ function isTextblockAttrActive(state, attr, value) {
694
+ const { from, to } = state.selection;
695
+ let any = false;
696
+ let all = true;
697
+ state.doc.nodesBetween(from, to, (node) => {
698
+ if (node.isTextblock && attr in (node.type.spec.attrs ?? {})) {
699
+ any = true;
700
+ if (node.attrs[attr] !== value) all = false;
701
+ }
702
+ return true;
703
+ });
704
+ return any && all;
705
+ }
706
+ function changeIndent(delta) {
707
+ return (state, dispatch) => {
708
+ const { from, to } = state.selection;
709
+ let changed = false;
710
+ const tr = state.tr;
711
+ state.doc.nodesBetween(from, to, (node, pos) => {
712
+ if (node.isTextblock && "indent" in (node.type.spec.attrs ?? {})) {
713
+ const next = clampIndent(node.attrs.indent + delta);
714
+ if (next !== node.attrs.indent) {
715
+ changed = true;
716
+ if (dispatch) tr.setNodeAttribute(pos, "indent", next);
717
+ }
718
+ }
719
+ return true;
720
+ });
721
+ if (!changed) return false;
722
+ if (dispatch) dispatch(tr.scrollIntoView());
723
+ return true;
724
+ };
725
+ }
726
+ function insertBlock(type) {
727
+ return (state, dispatch) => {
728
+ if (!type) return false;
729
+ if (dispatch) {
730
+ dispatch(state.tr.replaceSelectionWith(type.create()).scrollIntoView());
731
+ }
732
+ return true;
733
+ };
734
+ }
735
+ function createBlockCommands(schema) {
736
+ const n = schema.nodes;
737
+ const cmds = {};
738
+ if (n.paragraph) {
739
+ const run = prosemirrorCommands.setBlockType(n.paragraph);
740
+ cmds.paragraph = {
741
+ run,
742
+ isActive: (state) => isBlockActive(state, n.paragraph),
743
+ isEnabled: (state) => run(state, void 0, void 0)
744
+ };
745
+ }
746
+ if (schema.nodes.blockquote) {
747
+ const wrap = prosemirrorCommands.wrapIn(schema.nodes.blockquote);
748
+ cmds.blockquote = {
749
+ run: (state, dispatch, view) => {
750
+ if (isInNode(state, schema.nodes.blockquote)) return prosemirrorCommands.lift(state, dispatch);
751
+ return wrap(state, dispatch, view);
752
+ },
753
+ isActive: (state) => isInNode(state, schema.nodes.blockquote)
754
+ };
755
+ }
756
+ if (n.horizontal_rule) {
757
+ const run = insertBlock(n.horizontal_rule);
758
+ cmds.horizontalRule = { run, isEnabled: (state) => run(state, void 0, void 0) };
759
+ }
760
+ if (n.page_break) {
761
+ const run = insertBlock(n.page_break);
762
+ cmds.pageBreak = { run, isEnabled: (state) => run(state, void 0, void 0) };
763
+ }
764
+ if (n.paragraph?.spec.attrs && "align" in n.paragraph.spec.attrs) {
765
+ const aligns = [
766
+ ["alignLeft", "left"],
767
+ ["alignCenter", "center"],
768
+ ["alignRight", "right"],
769
+ ["alignJustify", "justify"]
770
+ ];
771
+ for (const [name, value] of aligns) {
772
+ const run = setTextblockAttr("align", value);
773
+ cmds[name] = {
774
+ run,
775
+ isActive: (state) => isTextblockAttrActive(state, "align", value),
776
+ isEnabled: (state) => run(state, void 0, void 0)
777
+ };
778
+ }
779
+ const indentRun = changeIndent(1);
780
+ const outdentRun = changeIndent(-1);
781
+ cmds.indent = { run: indentRun, isEnabled: (state) => indentRun(state, void 0, void 0) };
782
+ cmds.outdent = {
783
+ run: outdentRun,
784
+ isEnabled: (state) => outdentRun(state, void 0, void 0)
785
+ };
786
+ }
787
+ return cmds;
788
+ }
789
+ function createParametricBlockCommands(schema) {
790
+ const n = schema.nodes;
791
+ return {
792
+ setParagraph: () => n.paragraph ? prosemirrorCommands.setBlockType(n.paragraph) : noop2,
793
+ setHeading: (level) => n.heading ? prosemirrorCommands.setBlockType(n.heading, { level }) : noop2,
794
+ setAlign: (align) => setTextblockAttr("align", align),
795
+ setLineHeight: (lineHeight) => setTextblockAttr("lineHeight", lineHeight)
796
+ };
797
+ }
798
+ function findParentList(state, listTypes) {
799
+ const { $from } = state.selection;
800
+ for (let depth = $from.depth; depth > 0; depth--) {
801
+ const node = $from.node(depth);
802
+ if (listTypes.includes(node.type)) {
803
+ return { node, pos: $from.before(depth), depth };
804
+ }
805
+ }
806
+ return null;
807
+ }
808
+ function setItemsChecked(tr, list, listPos, checked) {
809
+ let offset = listPos + 1;
810
+ list.forEach((child) => {
811
+ if (child.type.name === "list_item" && child.attrs.checked !== checked) {
812
+ tr.setNodeAttribute(offset, "checked", checked);
813
+ }
814
+ offset += child.nodeSize;
815
+ });
816
+ }
817
+ function toggleList(schema, targetType, targetAttrs) {
818
+ const listItem = schema.nodes.list_item;
819
+ const listTypes = [schema.nodes.bullet_list, schema.nodes.ordered_list].filter(
820
+ Boolean
821
+ );
822
+ return (state, dispatch, view) => {
823
+ const parent = findParentList(state, listTypes);
824
+ if (!parent) {
825
+ const wrap = prosemirrorSchemaList.wrapInList(targetType, targetAttrs);
826
+ if (targetAttrs.kind === "task") {
827
+ return wrap(
828
+ state,
829
+ (tr) => {
830
+ if (!dispatch) return;
831
+ const next = tr.doc.resolve(tr.selection.from);
832
+ for (let depth = next.depth; depth > 0; depth--) {
833
+ const node = next.node(depth);
834
+ if (node.type === targetType) {
835
+ setItemsChecked(tr, node, next.before(depth), false);
836
+ break;
837
+ }
838
+ }
839
+ dispatch(tr);
840
+ },
841
+ view
842
+ );
843
+ }
844
+ return wrap(state, dispatch, view);
845
+ }
846
+ const sameType = parent.node.type === targetType;
847
+ const sameKind = targetType.name !== "bullet_list" || parent.node.attrs.kind === targetAttrs.kind;
848
+ if (sameType && sameKind) {
849
+ return prosemirrorSchemaList.liftListItem(listItem)(state, dispatch, view);
850
+ }
851
+ if (dispatch) {
852
+ const tr = state.tr.setNodeMarkup(parent.pos, targetType, targetAttrs);
853
+ const checked = targetAttrs.kind === "task" ? false : null;
854
+ setItemsChecked(tr, parent.node, parent.pos, checked);
855
+ dispatch(tr.scrollIntoView());
856
+ }
857
+ return true;
858
+ };
859
+ }
860
+ function isInList(state, type, kind) {
861
+ const { $from } = state.selection;
862
+ for (let depth = $from.depth; depth > 0; depth--) {
863
+ const node = $from.node(depth);
864
+ if (node.type === type && (kind === void 0 || node.attrs.kind === kind)) return true;
865
+ }
866
+ return false;
867
+ }
868
+ function createListCommands(schema) {
869
+ const n = schema.nodes;
870
+ const cmds = {};
871
+ if (!n.list_item) return cmds;
872
+ if (n.bullet_list) {
873
+ const run = toggleList(schema, n.bullet_list, { kind: "bullet" });
874
+ cmds.bulletList = {
875
+ run,
876
+ isActive: (state) => isInList(state, n.bullet_list, "bullet")
877
+ };
878
+ }
879
+ if (n.ordered_list) {
880
+ const run = toggleList(schema, n.ordered_list, { order: 1 });
881
+ cmds.orderedList = {
882
+ run,
883
+ isActive: (state) => isInList(state, n.ordered_list)
884
+ };
885
+ }
886
+ if (n.bullet_list) {
887
+ const run = toggleList(schema, n.bullet_list, { kind: "task" });
888
+ cmds.taskList = {
889
+ run,
890
+ isActive: (state) => isInList(state, n.bullet_list, "task")
891
+ };
892
+ }
893
+ const sink = prosemirrorSchemaList.sinkListItem(n.list_item);
894
+ const liftItem = prosemirrorSchemaList.liftListItem(n.list_item);
895
+ cmds.sinkListItem = { run: sink, isEnabled: (state) => sink(state, void 0, void 0) };
896
+ cmds.liftListItem = { run: liftItem, isEnabled: (state) => liftItem(state, void 0, void 0) };
897
+ return cmds;
898
+ }
899
+
900
+ // src/core/commands/format.ts
901
+ function clearFormatting(schema) {
902
+ return (state, dispatch) => {
903
+ const { from, to, empty } = state.selection;
904
+ if (empty) return false;
905
+ if (dispatch) {
906
+ const tr = state.tr;
907
+ tr.removeMark(from, to);
908
+ state.doc.nodesBetween(from, to, (node, pos) => {
909
+ if (!node.isTextblock) return true;
910
+ const specAttrs = node.type.spec.attrs ?? {};
911
+ if (schema.nodes.heading && node.type === schema.nodes.heading && schema.nodes.paragraph) {
912
+ tr.setNodeMarkup(pos, schema.nodes.paragraph, {
913
+ align: null,
914
+ indent: 0,
915
+ lineHeight: null
916
+ });
917
+ } else {
918
+ const attrs = { ...node.attrs };
919
+ if ("align" in specAttrs) attrs.align = null;
920
+ if ("indent" in specAttrs) attrs.indent = 0;
921
+ if ("lineHeight" in specAttrs) attrs.lineHeight = null;
922
+ tr.setNodeMarkup(pos, void 0, attrs);
923
+ }
924
+ return true;
925
+ });
926
+ dispatch(tr.scrollIntoView());
927
+ }
928
+ return true;
929
+ };
930
+ }
931
+ function createFormatCommands(schema) {
932
+ const run = clearFormatting(schema);
933
+ return {
934
+ clearFormatting: {
935
+ run,
936
+ isEnabled: (state) => !state.selection.empty
937
+ }
938
+ };
939
+ }
940
+
941
+ // src/core/commands/links.ts
942
+ function linkRangeAt(state, type, pos) {
943
+ const $pos = state.doc.resolve(pos);
944
+ const mark = type.isInSet($pos.marks());
945
+ if (!mark) return null;
946
+ let start = pos;
947
+ let end = pos;
948
+ while (start > 0 && mark.isInSet(state.doc.resolve(start - 1).marks())) start--;
949
+ const docSize = state.doc.content.size;
950
+ while (end < docSize && mark.isInSet(state.doc.resolve(end + 1).marks())) end++;
951
+ return { from: start, to: end };
952
+ }
953
+ function setLink(type, attrs) {
954
+ return (state, dispatch) => {
955
+ const href = chunk5F6SPYCN_cjs.sanitizeUrl(attrs.href);
956
+ if (!href) return false;
957
+ const markAttrs = { href, title: attrs.title ?? null, target: attrs.target ?? "_blank" };
958
+ const { empty, from, to } = state.selection;
959
+ if (dispatch) {
960
+ const tr = state.tr;
961
+ if (empty) {
962
+ const text2 = state.schema.text(href, [type.create(markAttrs)]);
963
+ tr.replaceSelectionWith(text2, false);
964
+ } else {
965
+ tr.addMark(from, to, type.create(markAttrs));
966
+ }
967
+ dispatch(tr.scrollIntoView());
968
+ }
969
+ return true;
970
+ };
971
+ }
972
+ function removeLink(type) {
973
+ return (state, dispatch) => {
974
+ const { empty, from, to } = state.selection;
975
+ if (empty) {
976
+ const range = linkRangeAt(state, type, from);
977
+ if (!range) return false;
978
+ if (dispatch) dispatch(state.tr.removeMark(range.from, range.to, type));
979
+ return true;
980
+ }
981
+ if (!state.doc.rangeHasMark(from, to, type)) return false;
982
+ if (dispatch) dispatch(state.tr.removeMark(from, to, type));
983
+ return true;
984
+ };
985
+ }
986
+ function createLinkCommands(schema) {
987
+ const type = schema.marks.link;
988
+ if (!type) {
989
+ const noop3 = () => false;
990
+ return {
991
+ commands: {},
992
+ setLink: (_attrs) => noop3,
993
+ removeLink: noop3,
994
+ getActiveLink: (_state) => null,
995
+ isLinkActive: (_state) => false
996
+ };
997
+ }
998
+ const commands = {
999
+ removeLink: {
1000
+ run: removeLink(type),
1001
+ isEnabled: (state) => isMarkActive(state, type)
1002
+ }
1003
+ };
1004
+ return {
1005
+ commands,
1006
+ setLink: (attrs) => setLink(type, attrs),
1007
+ removeLink: removeLink(type),
1008
+ getActiveLink: (state) => getActiveMarkAttrs(state, type),
1009
+ isLinkActive: (state) => isMarkActive(state, type)
1010
+ };
1011
+ }
1012
+ function insertImage(schema, attrs) {
1013
+ return (state, dispatch) => {
1014
+ const type = schema.nodes.image;
1015
+ if (!type) return false;
1016
+ const src = chunk5F6SPYCN_cjs.sanitizeImageSrc(attrs.src);
1017
+ if (!src) return false;
1018
+ if (dispatch) {
1019
+ const node = type.create({
1020
+ src,
1021
+ alt: attrs.alt ?? null,
1022
+ title: attrs.title ?? null,
1023
+ width: attrs.width ?? null
1024
+ });
1025
+ dispatch(state.tr.replaceSelectionWith(node).scrollIntoView());
1026
+ }
1027
+ return true;
1028
+ };
1029
+ }
1030
+ function createTableNode(schema, rows, cols, withHeaderRow) {
1031
+ const { table, table_row, table_cell, table_header } = schema.nodes;
1032
+ if (!table || !table_row || !table_cell) return null;
1033
+ const headerType = table_header ?? table_cell;
1034
+ const rowNodes = [];
1035
+ for (let r = 0; r < rows; r++) {
1036
+ const cells = [];
1037
+ for (let c = 0; c < cols; c++) {
1038
+ const cellType = withHeaderRow && r === 0 ? headerType : table_cell;
1039
+ const cell = cellType.createAndFill();
1040
+ if (!cell) return null;
1041
+ cells.push(cell);
1042
+ }
1043
+ rowNodes.push(table_row.create(null, cells));
1044
+ }
1045
+ return table.create(null, rowNodes);
1046
+ }
1047
+ function insertTable(schema, rows = 3, cols = 3, withHeaderRow = true) {
1048
+ return (state, dispatch) => {
1049
+ const node = createTableNode(schema, rows, cols, withHeaderRow);
1050
+ if (!node) return false;
1051
+ if (dispatch) dispatch(state.tr.replaceSelectionWith(node).scrollIntoView());
1052
+ return true;
1053
+ };
1054
+ }
1055
+ function createTableCommands(schema) {
1056
+ if (!schema.nodes.table) return {};
1057
+ const wrap = (run) => ({
1058
+ run,
1059
+ isEnabled: (state) => run(state, void 0, void 0)
1060
+ });
1061
+ return {
1062
+ addRowBefore: wrap(prosemirrorTables.addRowBefore),
1063
+ addRowAfter: wrap(prosemirrorTables.addRowAfter),
1064
+ deleteRow: wrap(prosemirrorTables.deleteRow),
1065
+ addColumnBefore: wrap(prosemirrorTables.addColumnBefore),
1066
+ addColumnAfter: wrap(prosemirrorTables.addColumnAfter),
1067
+ deleteColumn: wrap(prosemirrorTables.deleteColumn),
1068
+ mergeCells: wrap(prosemirrorTables.mergeCells),
1069
+ splitCell: wrap(prosemirrorTables.splitCell),
1070
+ toggleHeaderRow: wrap(prosemirrorTables.toggleHeaderRow),
1071
+ toggleHeaderColumn: wrap(prosemirrorTables.toggleHeaderColumn),
1072
+ deleteTable: wrap(prosemirrorTables.deleteTable)
1073
+ };
1074
+ }
1075
+
1076
+ // src/core/commands/index.ts
1077
+ function createCommands(schema) {
1078
+ const registry = {
1079
+ undo: { run: prosemirrorHistory.undo, isEnabled: (state) => prosemirrorHistory.undo(state) },
1080
+ redo: { run: prosemirrorHistory.redo, isEnabled: (state) => prosemirrorHistory.redo(state) },
1081
+ ...createMarkCommands(schema),
1082
+ ...createBlockCommands(schema),
1083
+ ...createListCommands(schema),
1084
+ ...createFormatCommands(schema),
1085
+ ...createTableCommands(schema)
1086
+ };
1087
+ const linkApi = createLinkCommands(schema);
1088
+ Object.assign(registry, linkApi.commands);
1089
+ return {
1090
+ registry,
1091
+ marks: createParametricMarkCommands(schema),
1092
+ blocks: createParametricBlockCommands(schema),
1093
+ links: linkApi,
1094
+ insert: {
1095
+ image: (attrs) => insertImage(schema, attrs),
1096
+ table: (rows = 3, cols = 3, withHeaderRow = true) => insertTable(schema, rows, cols, withHeaderRow)
1097
+ }
1098
+ };
1099
+ }
1100
+ var editingCommands = {
1101
+ selectAll: prosemirrorCommands.selectAll,
1102
+ selectParentNode: prosemirrorCommands.selectParentNode,
1103
+ deleteSelection: prosemirrorCommands.deleteSelection,
1104
+ joinBackward: prosemirrorCommands.joinBackward,
1105
+ joinForward: prosemirrorCommands.joinForward
1106
+ };
1107
+ function buildInputRules(schema) {
1108
+ const rules = [...prosemirrorInputrules.smartQuotes, prosemirrorInputrules.ellipsis, prosemirrorInputrules.emDash];
1109
+ const n = schema.nodes;
1110
+ if (n.blockquote) {
1111
+ rules.push(prosemirrorInputrules.wrappingInputRule(/^\s*>\s$/, n.blockquote));
1112
+ }
1113
+ if (n.ordered_list) {
1114
+ rules.push(
1115
+ prosemirrorInputrules.wrappingInputRule(
1116
+ /^(\d+)\.\s$/,
1117
+ n.ordered_list,
1118
+ (match) => ({ order: +match[1] }),
1119
+ (match, node) => node.childCount + node.attrs.order === +match[1]
1120
+ )
1121
+ );
1122
+ }
1123
+ if (n.bullet_list) {
1124
+ rules.push(prosemirrorInputrules.wrappingInputRule(/^\s*([-+*])\s$/, n.bullet_list));
1125
+ }
1126
+ if (n.heading) {
1127
+ rules.push(
1128
+ prosemirrorInputrules.textblockTypeInputRule(/^(#{1,6})\s$/, n.heading, (match) => ({
1129
+ level: match[1].length
1130
+ }))
1131
+ );
1132
+ }
1133
+ return prosemirrorInputrules.inputRules({ rules });
1134
+ }
1135
+ function buildKeymapPlugins(schema) {
1136
+ const bindings = {};
1137
+ const m = schema.marks;
1138
+ const n = schema.nodes;
1139
+ const bind = (key, cmd) => {
1140
+ if (cmd) bindings[key] = cmd;
1141
+ };
1142
+ bind("Mod-z", prosemirrorHistory.undo);
1143
+ bind("Shift-Mod-z", prosemirrorHistory.redo);
1144
+ bind("Mod-y", prosemirrorHistory.redo);
1145
+ if (m.strong) bind("Mod-b", prosemirrorCommands.toggleMark(m.strong));
1146
+ if (m.em) bind("Mod-i", prosemirrorCommands.toggleMark(m.em));
1147
+ if (m.underline) bind("Mod-u", prosemirrorCommands.toggleMark(m.underline));
1148
+ if (m.strikethrough) bind("Mod-Shift-s", prosemirrorCommands.toggleMark(m.strikethrough));
1149
+ if (m.code) bind("Mod-e", prosemirrorCommands.toggleMark(m.code));
1150
+ if (m.superscript) bind("Mod-.", prosemirrorCommands.toggleMark(m.superscript));
1151
+ if (m.subscript) bind("Mod-,", prosemirrorCommands.toggleMark(m.subscript));
1152
+ if (n.paragraph) bind("Shift-Mod-0", prosemirrorCommands.setBlockType(n.paragraph));
1153
+ if (n.heading) {
1154
+ for (let level = 1; level <= 6; level++) {
1155
+ bind(`Shift-Mod-${level}`, prosemirrorCommands.setBlockType(n.heading, { level }));
1156
+ }
1157
+ }
1158
+ const listItem = n.list_item;
1159
+ if (listItem) {
1160
+ bind("Enter", prosemirrorSchemaList.splitListItem(listItem));
1161
+ }
1162
+ const tabChain = [];
1163
+ const shiftTabChain = [];
1164
+ if (n.table) {
1165
+ tabChain.push(prosemirrorTables.goToNextCell(1));
1166
+ shiftTabChain.push(prosemirrorTables.goToNextCell(-1));
1167
+ }
1168
+ if (listItem) {
1169
+ tabChain.push(prosemirrorSchemaList.sinkListItem(listItem));
1170
+ shiftTabChain.push(prosemirrorSchemaList.liftListItem(listItem));
1171
+ }
1172
+ tabChain.push(changeIndent(1));
1173
+ shiftTabChain.push(changeIndent(-1));
1174
+ bindings["Tab"] = prosemirrorCommands.chainCommands(...tabChain);
1175
+ bindings["Shift-Tab"] = prosemirrorCommands.chainCommands(...shiftTabChain);
1176
+ if (n.hard_break) {
1177
+ const br = n.hard_break;
1178
+ const insertBreak = prosemirrorCommands.chainCommands(prosemirrorCommands.exitCode, (state, dispatch) => {
1179
+ if (dispatch) dispatch(state.tr.replaceSelectionWith(br.create()).scrollIntoView());
1180
+ return true;
1181
+ });
1182
+ bind("Shift-Enter", insertBreak);
1183
+ bind("Mod-Enter", insertBreak);
1184
+ }
1185
+ return [prosemirrorKeymap.keymap(bindings), prosemirrorKeymap.keymap(prosemirrorCommands.baseKeymap)];
1186
+ }
1187
+ function placeholderPlugin(text2) {
1188
+ return new prosemirrorState.Plugin({
1189
+ props: {
1190
+ decorations(state) {
1191
+ const { doc: doc2 } = state;
1192
+ const isEmpty = doc2.childCount === 1 && doc2.firstChild != null && doc2.firstChild.isTextblock && doc2.firstChild.content.size === 0;
1193
+ if (!isEmpty) return null;
1194
+ const decoration = prosemirrorView.Decoration.node(0, doc2.firstChild.nodeSize, {
1195
+ class: "rne-empty",
1196
+ "data-placeholder": text2
1197
+ });
1198
+ return prosemirrorView.DecorationSet.create(doc2, [decoration]);
1199
+ }
1200
+ }
1201
+ });
1202
+ }
1203
+ function taskListPlugin(schema) {
1204
+ return new prosemirrorState.Plugin({
1205
+ props: {
1206
+ handleDOMEvents: {
1207
+ mousedown(view, event) {
1208
+ if (!view.editable) return false;
1209
+ const target = event.target;
1210
+ if (!target || !target.classList?.contains("rne-task-checkbox")) return false;
1211
+ try {
1212
+ const pos = view.posAtDOM(target, 0);
1213
+ if (pos == null || pos < 0) return false;
1214
+ const $pos = view.state.doc.resolve(pos);
1215
+ for (let depth = $pos.depth; depth > 0; depth--) {
1216
+ const node = $pos.node(depth);
1217
+ if (node.type === schema.nodes.list_item && node.attrs.checked !== null) {
1218
+ const itemPos = $pos.before(depth);
1219
+ const tr = view.state.tr.setNodeAttribute(itemPos, "checked", !node.attrs.checked);
1220
+ view.dispatch(tr);
1221
+ event.preventDefault();
1222
+ return true;
1223
+ }
1224
+ }
1225
+ } catch {
1226
+ return false;
1227
+ }
1228
+ return false;
1229
+ }
1230
+ }
1231
+ }
1232
+ });
1233
+ }
1234
+
1235
+ // src/core/pagination/compute.ts
1236
+ var EPS = 0.5;
1237
+ function toUnits(blocks) {
1238
+ const units = [];
1239
+ for (const block of blocks) {
1240
+ if (!Number.isFinite(block.top) || !Number.isFinite(block.height)) continue;
1241
+ if (block.lines && block.lines.length > 1) {
1242
+ block.lines.forEach((line, i) => {
1243
+ if (!Number.isFinite(line.top) || !Number.isFinite(line.height)) return;
1244
+ units.push({ pos: line.pos, top: line.top, height: line.height, inline: i > 0 });
1245
+ });
1246
+ } else {
1247
+ units.push({ pos: block.pos, top: block.top, height: block.height, inline: false });
1248
+ }
1249
+ }
1250
+ units.sort((a, b) => a.top - b.top);
1251
+ return units;
1252
+ }
1253
+ function computePagination(blocks, geo) {
1254
+ const contentHeight = Math.max(1, geo.contentHeight);
1255
+ const interPageOffset = Math.max(0, geo.interPageOffset);
1256
+ const units = toUnits(blocks);
1257
+ const breaks = [];
1258
+ const pageContentTops = [0];
1259
+ let pageStart = 0;
1260
+ let cumSpacer = 0;
1261
+ let pageIndex = 0;
1262
+ for (const unit of units) {
1263
+ const bottom = unit.top + unit.height;
1264
+ const overflows = bottom - pageStart > contentHeight + EPS;
1265
+ const startsBelowPageTop = unit.top - pageStart > EPS;
1266
+ if (overflows && startsBelowPageTop) {
1267
+ const usedHeight = unit.top - pageStart;
1268
+ const spacerHeight = Math.max(0, contentHeight - usedHeight) + interPageOffset;
1269
+ pageIndex += 1;
1270
+ cumSpacer += spacerHeight;
1271
+ breaks.push({ pos: unit.pos, spacerHeight, pageIndex, inline: unit.inline });
1272
+ pageContentTops.push(unit.top + cumSpacer);
1273
+ pageStart = unit.top;
1274
+ }
1275
+ }
1276
+ return { breaks, pageCount: pageIndex + 1, pageContentTops };
1277
+ }
1278
+ function paginationEquals(a, b) {
1279
+ if (a === b) return true;
1280
+ if (!a || !b) return false;
1281
+ if (a.pageCount !== b.pageCount || a.breaks.length !== b.breaks.length) return false;
1282
+ for (let i = 0; i < a.breaks.length; i++) {
1283
+ const x = a.breaks[i];
1284
+ const y = b.breaks[i];
1285
+ if (x.pos !== y.pos || Math.abs(x.spacerHeight - y.spacerHeight) > 1) return false;
1286
+ }
1287
+ return true;
1288
+ }
1289
+
1290
+ // src/core/pagination/plugin.ts
1291
+ var LINE_SPLIT_MIN_RATIO = 0.25;
1292
+ var MAX_LINES_PER_BLOCK = 4e3;
1293
+ var paginationKey = new prosemirrorState.PluginKey("rne-pagination");
1294
+ function buildDecorations(doc2, result) {
1295
+ if (!result || result.breaks.length === 0) return prosemirrorView.DecorationSet.empty;
1296
+ const decorations = result.breaks.map(
1297
+ (br) => prosemirrorView.Decoration.widget(
1298
+ br.pos,
1299
+ () => {
1300
+ const el = document.createElement("span");
1301
+ el.className = `rne-page-spacer${br.inline ? " rne-page-spacer--inline" : ""}`;
1302
+ el.style.display = "block";
1303
+ el.style.width = "100%";
1304
+ el.style.height = `${Math.max(0, br.spacerHeight)}px`;
1305
+ el.setAttribute("contenteditable", "false");
1306
+ el.setAttribute("aria-hidden", "true");
1307
+ return el;
1308
+ },
1309
+ {
1310
+ side: -1,
1311
+ key: `rne-pb:${br.pos}:${Math.round(br.spacerHeight)}`,
1312
+ ignoreSelection: true,
1313
+ marks: []
1314
+ }
1315
+ )
1316
+ );
1317
+ return prosemirrorView.DecorationSet.create(doc2, decorations);
1318
+ }
1319
+ function paginationPlugin(options) {
1320
+ return new prosemirrorState.Plugin({
1321
+ key: paginationKey,
1322
+ state: {
1323
+ init: () => ({ result: null, decorations: prosemirrorView.DecorationSet.empty }),
1324
+ apply(tr, prev) {
1325
+ const meta = tr.getMeta(paginationKey);
1326
+ if (meta) {
1327
+ return { result: meta.result, decorations: buildDecorations(tr.doc, meta.result) };
1328
+ }
1329
+ if (tr.docChanged) {
1330
+ const result = prev.result ? {
1331
+ ...prev.result,
1332
+ breaks: prev.result.breaks.map((b) => ({ ...b, pos: tr.mapping.map(b.pos) }))
1333
+ } : prev.result;
1334
+ return { result, decorations: prev.decorations.map(tr.mapping, tr.doc) };
1335
+ }
1336
+ return prev;
1337
+ }
1338
+ },
1339
+ props: {
1340
+ decorations(state) {
1341
+ return paginationKey.getState(state)?.decorations ?? prosemirrorView.DecorationSet.empty;
1342
+ }
1343
+ },
1344
+ view(view) {
1345
+ return new PaginationView(view, options);
1346
+ }
1347
+ });
1348
+ }
1349
+ var PaginationView = class {
1350
+ constructor(view, options) {
1351
+ this.scheduled = false;
1352
+ this.destroyed = false;
1353
+ this.resizeObserver = null;
1354
+ this.onWindowResize = () => this.schedule();
1355
+ this.onAssetLoad = (e) => {
1356
+ if (e.target?.tagName === "IMG") this.schedule();
1357
+ };
1358
+ this.view = view;
1359
+ this.options = options;
1360
+ if (typeof ResizeObserver !== "undefined") {
1361
+ this.resizeObserver = new ResizeObserver(() => this.schedule());
1362
+ this.resizeObserver.observe(view.dom);
1363
+ }
1364
+ if (typeof window !== "undefined") {
1365
+ window.addEventListener("resize", this.onWindowResize);
1366
+ }
1367
+ view.dom.addEventListener("load", this.onAssetLoad, true);
1368
+ options.register?.(() => this.schedule());
1369
+ this.schedule();
1370
+ }
1371
+ update(view, prevState) {
1372
+ this.view = view;
1373
+ if (view.state.doc !== prevState.doc) this.schedule();
1374
+ }
1375
+ schedule() {
1376
+ if (this.scheduled || this.destroyed) return;
1377
+ this.scheduled = true;
1378
+ const raf = typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : (cb) => setTimeout(() => cb(0), 16);
1379
+ raf(() => {
1380
+ this.scheduled = false;
1381
+ if (!this.destroyed) this.measure();
1382
+ });
1383
+ }
1384
+ measure() {
1385
+ try {
1386
+ const geo = this.options.getGeometry();
1387
+ const bg = this.options.getBackgroundLayer();
1388
+ if (!geo || !bg || geo.contentHeightPx <= 0 || geo.pageHeightPx <= 0) {
1389
+ this.clearBackground(bg);
1390
+ return;
1391
+ }
1392
+ const current = paginationKey.getState(this.view.state)?.result ?? null;
1393
+ const blocks = this.measureBlocks(geo, current);
1394
+ const result = computePagination(blocks, {
1395
+ contentHeight: geo.contentHeightPx,
1396
+ interPageOffset: geo.interPageOffsetPx
1397
+ });
1398
+ this.renderBackground(bg, geo, result);
1399
+ this.options.onPageCount?.(result.pageCount);
1400
+ if (!paginationEquals(result, current)) {
1401
+ this.view.dispatch(this.view.state.tr.setMeta(paginationKey, { result }));
1402
+ }
1403
+ } catch {
1404
+ }
1405
+ }
1406
+ /** Measure top-level blocks in spacer-independent natural coordinates. */
1407
+ measureBlocks(geo, current) {
1408
+ const view = this.view;
1409
+ const contentRect = view.dom.getBoundingClientRect();
1410
+ const paddingTop = geo.marginTopPx;
1411
+ const currentBreaks = current?.breaks ?? [];
1412
+ const lineSplitThreshold = geo.contentHeightPx * LINE_SPLIT_MIN_RATIO;
1413
+ const offsets = [];
1414
+ const naturalTops = [];
1415
+ const rectHeights = [];
1416
+ const elements = [];
1417
+ const splittable = [];
1418
+ view.state.doc.forEach((node, offset) => {
1419
+ let dom = null;
1420
+ try {
1421
+ dom = view.nodeDOM(offset);
1422
+ } catch {
1423
+ dom = null;
1424
+ }
1425
+ if (!(dom instanceof HTMLElement)) return;
1426
+ const rect = dom.getBoundingClientRect();
1427
+ const renderedTop = rect.top - contentRect.top;
1428
+ let spacerBefore = 0;
1429
+ for (const br of currentBreaks) if (br.pos <= offset) spacerBefore += br.spacerHeight;
1430
+ offsets.push(offset);
1431
+ naturalTops.push(renderedTop - spacerBefore - paddingTop);
1432
+ rectHeights.push(rect.height);
1433
+ elements.push(dom);
1434
+ splittable.push(!node.isAtom && node.type.name !== "table");
1435
+ });
1436
+ const blocks = [];
1437
+ for (let i = 0; i < offsets.length; i++) {
1438
+ const height = i < offsets.length - 1 ? Math.max(rectHeights[i], naturalTops[i + 1] - naturalTops[i]) : rectHeights[i];
1439
+ let lines;
1440
+ if (splittable[i] && rectHeights[i] > lineSplitThreshold) {
1441
+ lines = this.measureLines(elements[i], offsets[i], contentRect, paddingTop, currentBreaks);
1442
+ }
1443
+ blocks.push({ pos: offsets[i], top: naturalTops[i], height, lines });
1444
+ }
1445
+ return blocks;
1446
+ }
1447
+ /**
1448
+ * Measure the line boxes of a tall, splittable block in spacer-independent
1449
+ * natural coordinates so the block can break across pages at line boundaries.
1450
+ * Returns `undefined` (block moves whole) if measurement is unavailable or a
1451
+ * line position cannot be resolved — never throws.
1452
+ */
1453
+ measureLines(dom, blockOffset, contentRect, paddingTop, currentBreaks) {
1454
+ try {
1455
+ if (typeof document === "undefined" || typeof document.createRange !== "function") {
1456
+ return void 0;
1457
+ }
1458
+ const range = document.createRange();
1459
+ range.selectNodeContents(dom);
1460
+ const rects = range.getClientRects();
1461
+ if (!rects || rects.length === 0) return void 0;
1462
+ const rawLines = [];
1463
+ for (let i = 0; i < rects.length && rawLines.length < MAX_LINES_PER_BLOCK; i++) {
1464
+ const r = rects[i];
1465
+ if (r.width <= 0 || r.height <= 0) continue;
1466
+ const last = rawLines[rawLines.length - 1];
1467
+ if (last && Math.abs(last.top - r.top) < 3) {
1468
+ last.bottom = Math.max(last.bottom, r.bottom);
1469
+ last.left = Math.min(last.left, r.left);
1470
+ } else {
1471
+ rawLines.push({ top: r.top, bottom: r.bottom, left: r.left });
1472
+ }
1473
+ }
1474
+ if (rawLines.length < 2) return void 0;
1475
+ const spacerBeforePos = (pos) => {
1476
+ let total = 0;
1477
+ for (const br of currentBreaks) if (br.pos <= pos) total += br.spacerHeight;
1478
+ return total;
1479
+ };
1480
+ const lines = [];
1481
+ for (let i = 0; i < rawLines.length; i++) {
1482
+ const rl = rawLines[i];
1483
+ let pos;
1484
+ if (i === 0) {
1485
+ pos = blockOffset;
1486
+ } else {
1487
+ const at = this.view.posAtCoords({ left: rl.left + 1, top: (rl.top + rl.bottom) / 2 });
1488
+ if (!at) continue;
1489
+ pos = at.pos;
1490
+ }
1491
+ const naturalTop = rl.top - contentRect.top - spacerBeforePos(pos) - paddingTop;
1492
+ lines.push({ pos, top: naturalTop, height: rl.bottom - rl.top });
1493
+ }
1494
+ return lines.length >= 2 ? lines : void 0;
1495
+ } catch {
1496
+ return void 0;
1497
+ }
1498
+ }
1499
+ renderBackground(bg, geo, result) {
1500
+ while (bg.firstChild) bg.removeChild(bg.firstChild);
1501
+ const { pageContentTops, pageCount } = result;
1502
+ const headerCfg = this.options.header;
1503
+ const footerCfg = this.options.footer;
1504
+ for (let p = 0; p < pageCount; p++) {
1505
+ const sheetTop = pageContentTops[p] ?? p * (geo.contentHeightPx + geo.interPageOffsetPx);
1506
+ const sheet = document.createElement("div");
1507
+ sheet.className = "rne-page-sheet";
1508
+ sheet.style.top = `${sheetTop}px`;
1509
+ sheet.style.height = `${geo.pageHeightPx}px`;
1510
+ sheet.style.width = `${geo.pageWidthPx}px`;
1511
+ bg.appendChild(sheet);
1512
+ if (headerCfg?.show && headerCfg.text) {
1513
+ bg.appendChild(
1514
+ this.runningElement(
1515
+ "rne-page-header",
1516
+ interpolate(headerCfg.text, p + 1, pageCount),
1517
+ sheetTop + geo.marginTopPx * 0.35,
1518
+ geo,
1519
+ headerCfg.align ?? "left"
1520
+ )
1521
+ );
1522
+ }
1523
+ const footerText = footerCfg?.text ?? (footerCfg?.pageNumbers ? "Page {page} of {pages}" : void 0);
1524
+ if ((footerCfg?.show || footerCfg?.pageNumbers) && footerText) {
1525
+ bg.appendChild(
1526
+ this.runningElement(
1527
+ "rne-page-footer",
1528
+ interpolate(footerText, p + 1, pageCount),
1529
+ sheetTop + geo.pageHeightPx - geo.marginBottomPx * 0.6,
1530
+ geo,
1531
+ footerCfg.align ?? "center"
1532
+ )
1533
+ );
1534
+ }
1535
+ }
1536
+ const lastTop = pageContentTops[pageCount - 1] ?? 0;
1537
+ const totalHeight = lastTop + geo.pageHeightPx;
1538
+ bg.style.height = `${totalHeight}px`;
1539
+ const container = bg.parentElement;
1540
+ if (container) container.style.minHeight = `${totalHeight}px`;
1541
+ }
1542
+ runningElement(className, text2, top, geo, align) {
1543
+ const el = document.createElement("div");
1544
+ el.className = className;
1545
+ el.textContent = text2;
1546
+ el.style.position = "absolute";
1547
+ el.style.top = `${top}px`;
1548
+ el.style.left = `${geo.marginLeftPx}px`;
1549
+ el.style.width = `${geo.contentWidthPx}px`;
1550
+ el.style.textAlign = align;
1551
+ el.setAttribute("aria-hidden", "true");
1552
+ return el;
1553
+ }
1554
+ clearBackground(bg) {
1555
+ if (!bg) return;
1556
+ while (bg.firstChild) bg.removeChild(bg.firstChild);
1557
+ bg.style.height = "";
1558
+ const container = bg.parentElement;
1559
+ if (container) container.style.minHeight = "";
1560
+ }
1561
+ destroy() {
1562
+ this.destroyed = true;
1563
+ this.resizeObserver?.disconnect();
1564
+ if (typeof window !== "undefined") window.removeEventListener("resize", this.onWindowResize);
1565
+ this.view.dom.removeEventListener("load", this.onAssetLoad, true);
1566
+ }
1567
+ };
1568
+ function interpolate(text2, page, pages) {
1569
+ return text2.replace(/\{page\}/g, String(page)).replace(/\{pages\}/g, String(pages));
1570
+ }
1571
+
1572
+ // src/core/plugins/index.ts
1573
+ function pasteSanitizerPlugin() {
1574
+ return new prosemirrorState.Plugin({
1575
+ props: {
1576
+ transformPastedHTML(html) {
1577
+ return chunk5F6SPYCN_cjs.sanitizeHtmlSync(html);
1578
+ }
1579
+ }
1580
+ });
1581
+ }
1582
+ function buildPlugins(schema, options = {}) {
1583
+ const plugins = [];
1584
+ if (options.history !== false) {
1585
+ plugins.push(prosemirrorHistory.history());
1586
+ }
1587
+ plugins.push(buildInputRules(schema));
1588
+ plugins.push(...buildKeymapPlugins(schema));
1589
+ plugins.push(prosemirrorDropcursor.dropCursor({ color: "var(--rne-accent, #df4a36)", width: 2 }));
1590
+ plugins.push(prosemirrorGapcursor.gapCursor());
1591
+ if (schema.nodes.table) {
1592
+ plugins.push(prosemirrorTables.columnResizing());
1593
+ plugins.push(prosemirrorTables.tableEditing());
1594
+ }
1595
+ plugins.push(taskListPlugin(schema));
1596
+ plugins.push(pasteSanitizerPlugin());
1597
+ if (options.placeholder) {
1598
+ plugins.push(placeholderPlugin(options.placeholder));
1599
+ }
1600
+ if (options.pagination) {
1601
+ plugins.push(paginationPlugin(options.pagination));
1602
+ }
1603
+ if (options.appendTransaction) {
1604
+ const hook = options.appendTransaction;
1605
+ plugins.push(new prosemirrorState.Plugin({ appendTransaction: (trs, oldS, newS) => hook(trs, oldS, newS) ?? null }));
1606
+ }
1607
+ if (options.extraPlugins?.length) {
1608
+ plugins.push(...options.extraPlugins);
1609
+ }
1610
+ return plugins;
1611
+ }
1612
+ function createDoc(schema, content) {
1613
+ if (content == null) return emptyDoc(schema);
1614
+ if (typeof content === "string") {
1615
+ return docFromText(schema, content);
1616
+ }
1617
+ try {
1618
+ const node = prosemirrorModel.Node.fromJSON(schema, content);
1619
+ node.check();
1620
+ return node;
1621
+ } catch (err) {
1622
+ console.error("[react-next-editor] Invalid initial content, using empty document.", err);
1623
+ return emptyDoc(schema);
1624
+ }
1625
+ }
1626
+ function emptyDoc(schema) {
1627
+ const doc2 = schema.nodes.doc.createAndFill();
1628
+ if (!doc2) throw new Error("Schema cannot create an empty document.");
1629
+ return doc2;
1630
+ }
1631
+ function docFromText(schema, text2) {
1632
+ const paragraphType = schema.nodes.paragraph;
1633
+ const lines = text2.split(/\r\n|\r|\n/);
1634
+ const paragraphs = lines.map(
1635
+ (line) => line ? paragraphType.create(null, schema.text(line)) : paragraphType.createAndFill()
1636
+ );
1637
+ if (paragraphs.length === 0) return emptyDoc(schema);
1638
+ return schema.nodes.doc.create(null, paragraphs);
1639
+ }
1640
+ function createEditorState(options) {
1641
+ const { schema, plugins, content } = options;
1642
+ return prosemirrorState.EditorState.create({
1643
+ doc: createDoc(schema, content),
1644
+ plugins
1645
+ });
1646
+ }
1647
+
1648
+ // src/core/utils.ts
1649
+ function countDocument(doc2) {
1650
+ let text2 = "";
1651
+ doc2.descendants((node) => {
1652
+ if (node.isText && node.text) {
1653
+ text2 += node.text;
1654
+ } else if (node.type.name === "hard_break") {
1655
+ text2 += " ";
1656
+ }
1657
+ return true;
1658
+ });
1659
+ const trimmed = text2.trim();
1660
+ const words = trimmed ? trimmed.split(/\s+/).length : 0;
1661
+ return {
1662
+ words,
1663
+ characters: text2.length,
1664
+ charactersNoSpaces: text2.replace(/\s/g, "").length
1665
+ };
1666
+ }
1667
+
1668
+ Object.defineProperty(exports, "splitListItem", {
1669
+ enumerable: true,
1670
+ get: function () { return prosemirrorSchemaList.splitListItem; }
1671
+ });
1672
+ exports.INDENT_STEP_EM = INDENT_STEP_EM;
1673
+ exports.MAX_INDENT = MAX_INDENT;
1674
+ exports.blockAttrs = blockAttrs;
1675
+ exports.blockDOMAttrs = blockDOMAttrs;
1676
+ exports.buildInputRules = buildInputRules;
1677
+ exports.buildKeymapPlugins = buildKeymapPlugins;
1678
+ exports.buildPlugins = buildPlugins;
1679
+ exports.buildSchema = buildSchema;
1680
+ exports.changeIndent = changeIndent;
1681
+ exports.clampIndent = clampIndent;
1682
+ exports.clearFormatting = clearFormatting;
1683
+ exports.countDocument = countDocument;
1684
+ exports.createCommands = createCommands;
1685
+ exports.createDoc = createDoc;
1686
+ exports.createEditorState = createEditorState;
1687
+ exports.createTableNode = createTableNode;
1688
+ exports.defaultEnabled = defaultEnabled;
1689
+ exports.defaultSchema = defaultSchema;
1690
+ exports.editingCommands = editingCommands;
1691
+ exports.getActiveMarkAttrs = getActiveMarkAttrs;
1692
+ exports.insertImage = insertImage;
1693
+ exports.insertTable = insertTable;
1694
+ exports.isBlockActive = isBlockActive;
1695
+ exports.isInNode = isInNode;
1696
+ exports.isMarkActive = isMarkActive;
1697
+ exports.isTextAlign = isTextAlign;
1698
+ exports.isTextblockAttrActive = isTextblockAttrActive;
1699
+ exports.marks_exports = marks_exports;
1700
+ exports.nodes_exports = nodes_exports;
1701
+ exports.paginationKey = paginationKey;
1702
+ exports.paginationPlugin = paginationPlugin;
1703
+ exports.placeholderPlugin = placeholderPlugin;
1704
+ exports.readBlockAttrs = readBlockAttrs;
1705
+ exports.removeLink = removeLink;
1706
+ exports.setLink = setLink;
1707
+ exports.setMark = setMark;
1708
+ exports.setTextblockAttr = setTextblockAttr;
1709
+ exports.taskListPlugin = taskListPlugin;
1710
+ exports.unsetMark = unsetMark;
1711
+ //# sourceMappingURL=chunk-DBSFCCBG.cjs.map
1712
+ //# sourceMappingURL=chunk-DBSFCCBG.cjs.map