@kedataindo/docflow-core 0.0.83 → 0.0.85

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/dist/index.cjs CHANGED
@@ -39,6 +39,7 @@ __export(index_exports, {
39
39
  PaginationPlus: () => PaginationPlus,
40
40
  PerformanceMonitor: () => PerformanceMonitor,
41
41
  SearchAndReplaceExtension: () => SearchAndReplaceExtension,
42
+ SubdocumentProvider: () => SubdocumentProvider,
42
43
  buildAIPrompt: () => buildAIPrompt,
43
44
  clearSearch: () => clearSearch,
44
45
  collaborationExtensions: () => collaborationExtensions,
@@ -59,6 +60,7 @@ __export(index_exports, {
59
60
  replaceAll: () => replaceAll,
60
61
  replaceCurrent: () => replaceCurrent,
61
62
  resolveAction: () => resolveAction,
63
+ sanitizeInlineHTML: () => sanitizeInlineHTML,
62
64
  sanitizePastedHTML: () => sanitizePastedHTML,
63
65
  searchAndReplaceKey: () => searchAndReplaceKey,
64
66
  searchNext: () => searchNext,
@@ -72,7 +74,6 @@ module.exports = __toCommonJS(index_exports);
72
74
 
73
75
  // src/Editor.ts
74
76
  var import_core6 = require("@tiptap/core");
75
- var import_state5 = require("@tiptap/pm/state");
76
77
  var import_starter_kit = __toESM(require("@tiptap/starter-kit"), 1);
77
78
  var import_extension_text_style = __toESM(require("@tiptap/extension-text-style"), 1);
78
79
 
@@ -127,6 +128,9 @@ function createActionMap(editor, plugins) {
127
128
  var import_extension_collaboration = require("@tiptap/extension-collaboration");
128
129
  var import_extension_collaboration_cursor = require("@tiptap/extension-collaboration-cursor");
129
130
  var import_awareness = require("y-protocols/awareness");
131
+ var import_y_indexeddb = require("y-indexeddb");
132
+ var import_y_webrtc = require("y-webrtc");
133
+ var import_y_websocket = require("y-websocket");
130
134
  var Y = __toESM(require("yjs"), 1);
131
135
  var LOCAL_SIGNALING = ["ws://localhost:4444"];
132
136
  var warnedLocalSignaling = false;
@@ -157,28 +161,25 @@ function createAwarenessStates(awareness) {
157
161
  });
158
162
  return states;
159
163
  }
160
- async function createCollaboration(options) {
164
+ function createCollaboration(options) {
161
165
  const ydoc = new Y.Doc();
162
166
  if (options.initialStorageState) {
163
167
  Y.applyUpdate(ydoc, options.initialStorageState);
164
168
  }
165
169
  let persistence;
166
170
  if (options.offline) {
167
- const { IndexeddbPersistence } = await import("y-indexeddb");
168
- persistence = new IndexeddbPersistence(`docflow-${options.room}`, ydoc);
171
+ persistence = new import_y_indexeddb.IndexeddbPersistence(`docflow-${options.room}`, ydoc);
169
172
  }
170
173
  let provider = null;
171
174
  if (options.provider === "webrtc") {
172
- const { WebrtcProvider } = await import("y-webrtc");
173
- provider = new WebrtcProvider(options.room, ydoc, {
175
+ provider = new import_y_webrtc.WebrtcProvider(options.room, ydoc, {
174
176
  signaling: resolveSignalingUrls(options.signaling)
175
177
  });
176
178
  } else if (options.provider === "websocket") {
177
179
  if (!options.websocketUrl) {
178
180
  throw new Error('[Collaboration] websocketUrl is required when provider is "websocket"');
179
181
  }
180
- const { WebsocketProvider } = await import("y-websocket");
181
- provider = new WebsocketProvider(options.websocketUrl, options.room, ydoc);
182
+ provider = new import_y_websocket.WebsocketProvider(options.websocketUrl, options.room, ydoc);
182
183
  }
183
184
  const awareness = provider?.awareness ?? new import_awareness.Awareness(ydoc);
184
185
  awareness.setLocalStateField("user", options.user);
@@ -244,7 +245,8 @@ async function createCollaboration(options) {
244
245
  };
245
246
  return { ydoc, provider, awareness, persistence, whenReady, destroy, setLocalCursorEnabled };
246
247
  }
247
- function collaborationExtensions(setup) {
248
+ function collaborationExtensions(options) {
249
+ const setup = "ydoc" in options ? options : createCollaboration(options);
248
250
  const extensions = [
249
251
  import_extension_collaboration.Collaboration.configure({ document: setup.ydoc })
250
252
  ];
@@ -320,42 +322,6 @@ var BlockAttributesExtension = import_core.Extension.create({
320
322
  }
321
323
  });
322
324
 
323
- // src/collab/seedEmptyFragment.ts
324
- var Y2 = __toESM(require("yjs"), 1);
325
- var PROVISIONAL_SEED_ORIGIN = "docflow:provisional-seed";
326
- function isPristineEmptyParagraph(element) {
327
- return element.length === 0 && Object.keys(element.getAttributes()).length === 0;
328
- }
329
- function seedEmptyFragment(doc, field = "default") {
330
- const fragment = doc.getXmlFragment(field);
331
- const paragraph = new Y2.XmlElement("paragraph");
332
- const observer = (_events, transaction) => {
333
- if (transaction.origin === PROVISIONAL_SEED_ORIGIN) return;
334
- if (paragraph.parent !== fragment) return;
335
- if (!isPristineEmptyParagraph(paragraph)) return;
336
- if (fragment.length < 2) return;
337
- const index = fragment.toArray().indexOf(paragraph);
338
- if (index === -1) return;
339
- doc.transact(() => {
340
- fragment.delete(index);
341
- }, PROVISIONAL_SEED_ORIGIN);
342
- };
343
- let disposed = false;
344
- const dispose = () => {
345
- if (disposed) return;
346
- disposed = true;
347
- fragment.unobserveDeep(observer);
348
- };
349
- if (fragment.length > 0) {
350
- return { seeded: false, dispose };
351
- }
352
- fragment.observeDeep(observer);
353
- doc.transact(() => {
354
- fragment.insert(0, [paragraph]);
355
- }, PROVISIONAL_SEED_ORIGIN);
356
- return { seeded: true, dispose };
357
- }
358
-
359
325
  // src/EditorContext.ts
360
326
  var import_core2 = require("@tiptap/core");
361
327
  var EditorContextExtension = import_core2.Extension.create({
@@ -378,11 +344,336 @@ var EditorContextExtension = import_core2.Extension.create({
378
344
  }
379
345
  });
380
346
 
381
- // src/SearchAndReplace.ts
347
+ // src/ManualColumnResize.ts
382
348
  var import_core3 = require("@tiptap/core");
383
349
  var import_state2 = require("@tiptap/pm/state");
350
+ var ManualColumnResize = import_core3.Extension.create({
351
+ name: "manualColumnResize",
352
+ addProseMirrorPlugins() {
353
+ const key2 = new import_state2.PluginKey("manualColumnResize");
354
+ return [new import_state2.Plugin({
355
+ key: key2,
356
+ view(view) {
357
+ const observer = view;
358
+ function pauseObserver() {
359
+ try {
360
+ observer.domObserver?.stop?.();
361
+ } catch (_) {
362
+ }
363
+ }
364
+ function resumeObserver() {
365
+ try {
366
+ observer.domObserver?.start?.();
367
+ } catch (_) {
368
+ }
369
+ }
370
+ function getMaxContainerWidth(tableEl) {
371
+ let curr = tableEl.parentElement;
372
+ while (curr) {
373
+ const style = window.getComputedStyle(curr);
374
+ const paddingLeft = parseFloat(style.paddingLeft) || 0;
375
+ const paddingRight = parseFloat(style.paddingRight) || 0;
376
+ const availWidth = curr.clientWidth - paddingLeft - paddingRight;
377
+ if (availWidth > 100 && (curr.classList.contains("docs-editor__paper") || curr.classList.contains("docs-editor-page") || curr.classList.contains("ProseMirror") || curr.classList.contains("rm-with-pagination"))) {
378
+ return availWidth;
379
+ }
380
+ curr = curr.parentElement;
381
+ }
382
+ return tableEl.parentElement?.clientWidth || 614;
383
+ }
384
+ const onMouseDown = function(event) {
385
+ if (event.button !== 0) return;
386
+ const td = event.target.closest("td, th");
387
+ if (!td) return;
388
+ const r = td.getBoundingClientRect();
389
+ const parent = td.parentElement;
390
+ if (!parent) return;
391
+ const cellColSpan = td.colSpan || 1;
392
+ let logicalStart = 0;
393
+ let foundCell = false;
394
+ for (const sibling of Array.from(parent.children)) {
395
+ if (sibling === td) {
396
+ foundCell = true;
397
+ break;
398
+ }
399
+ logicalStart += sibling.colSpan || 1;
400
+ }
401
+ if (!foundCell) return;
402
+ const table = td.closest("table");
403
+ if (!table) return;
404
+ const distRight = Math.abs(event.clientX - r.right);
405
+ const distLeft = Math.abs(event.clientX - r.left);
406
+ let targetColIdx = -1;
407
+ if (distRight <= 16) {
408
+ targetColIdx = logicalStart + cellColSpan - 1;
409
+ } else if (distLeft <= 16 && logicalStart > 0) {
410
+ targetColIdx = logicalStart - 1;
411
+ } else {
412
+ return;
413
+ }
414
+ const colsList = table.querySelectorAll("colgroup col");
415
+ const totalCols = colsList.length || table.querySelector("tr")?.children.length || 0;
416
+ const allColWidths = [];
417
+ for (let c = 0; c < totalCols; c++) {
418
+ const colEl = colsList[c];
419
+ const w = colEl ? parseFloat(colEl.style.width) : 0;
420
+ allColWidths[c] = w || initialWidth(table, c);
421
+ }
422
+ const isLastCol = targetColIdx === totalCols - 1;
423
+ const neighborIdx = targetColIdx + 1;
424
+ const startX = event.clientX;
425
+ const startW = allColWidths[targetColIdx] || initialWidth(table, targetColIdx);
426
+ const startNeighborW = !isLastCol ? allColWidths[neighborIdx] || initialWidth(table, neighborIdx) : 0;
427
+ const maxContainerW = getMaxContainerWidth(table);
428
+ let otherColsW = 0;
429
+ allColWidths.forEach((w, idx) => {
430
+ if (idx !== targetColIdx) otherColsW += w;
431
+ });
432
+ const maxNwLastCol = Math.max(20, maxContainerW - otherColsW);
433
+ function updateDOMWidths() {
434
+ let totalWidth = 0;
435
+ allColWidths.forEach((w, idx) => {
436
+ const col = table.querySelector(`colgroup col:nth-child(${idx + 1})`);
437
+ if (col) col.style.setProperty("width", w + "px", "important");
438
+ table.querySelectorAll("tr").forEach(function(row) {
439
+ const cell = row.children[idx];
440
+ if (cell) {
441
+ cell.style.setProperty("width", w + "px", "important");
442
+ cell.setAttribute("width", String(w));
443
+ }
444
+ });
445
+ totalWidth += w;
446
+ });
447
+ if (totalWidth > 0) {
448
+ table.style.setProperty("width", Math.min(totalWidth, maxContainerW) + "px", "important");
449
+ }
450
+ }
451
+ event.stopPropagation();
452
+ let lastNw = startW;
453
+ const onMove = function(e) {
454
+ if (!e.buttons) {
455
+ onUp(e);
456
+ return;
457
+ }
458
+ const rawDiff = e.clientX - startX;
459
+ if (isLastCol) {
460
+ const nw = Math.min(maxNwLastCol, Math.max(20, startW + rawDiff));
461
+ allColWidths[targetColIdx] = nw;
462
+ lastNw = nw;
463
+ } else {
464
+ const delta = Math.max(20 - startW, Math.min(rawDiff, startNeighborW - 20));
465
+ allColWidths[targetColIdx] = startW + delta;
466
+ allColWidths[neighborIdx] = startNeighborW - delta;
467
+ lastNw = allColWidths[targetColIdx];
468
+ }
469
+ let borderPos = table.getBoundingClientRect().left;
470
+ for (let i = 0; i <= targetColIdx; i++) borderPos += allColWidths[i];
471
+ showLine(table, borderPos);
472
+ pauseObserver();
473
+ updateDOMWidths();
474
+ resumeObserver();
475
+ };
476
+ const onUp = function(upEvent) {
477
+ document.removeEventListener("mousemove", onMove);
478
+ document.removeEventListener("mouseup", onUp, true);
479
+ upEvent.stopPropagation();
480
+ hideLine();
481
+ if (lastNw === startW) return;
482
+ try {
483
+ const { state } = view;
484
+ const { doc } = state;
485
+ let tablePos = -1;
486
+ doc.descendants((node, pos) => {
487
+ if (tablePos >= 0) return false;
488
+ if (node.type.name === "table") {
489
+ try {
490
+ const dom = view.nodeDOM(pos);
491
+ if (dom === table || dom instanceof HTMLElement && dom.contains(table) || table.contains(dom)) {
492
+ tablePos = pos;
493
+ return false;
494
+ }
495
+ } catch (_) {
496
+ }
497
+ }
498
+ return true;
499
+ });
500
+ if (tablePos >= 0) {
501
+ const tableNode = doc.nodeAt(tablePos);
502
+ if (tableNode) {
503
+ const tr = state.tr;
504
+ tableNode.forEach((row, rowOffset) => {
505
+ let cellColIdx = 0;
506
+ row.forEach((cell, cellOffset) => {
507
+ const colspan = cell.attrs.colspan || 1;
508
+ const cellPos = tablePos + 1 + rowOffset + 1 + cellOffset;
509
+ const cw = new Array(colspan);
510
+ for (let k = 0; k < colspan; k++) {
511
+ cw[k] = allColWidths[cellColIdx + k] || 100;
512
+ }
513
+ tr.setNodeMarkup(cellPos, null, { ...cell.attrs, colwidth: cw });
514
+ cellColIdx += colspan;
515
+ });
516
+ });
517
+ view.dispatch(tr);
518
+ pauseObserver();
519
+ updateDOMWidths();
520
+ resumeObserver();
521
+ }
522
+ } else {
523
+ console.warn("[Resize] could not find table position in doc");
524
+ }
525
+ } catch (err) {
526
+ console.warn("[Resize] transaction failed, falling back to DOM:", err);
527
+ pauseObserver();
528
+ updateDOMWidths();
529
+ resumeObserver();
530
+ }
531
+ };
532
+ document.addEventListener("mousemove", onMove);
533
+ document.addEventListener("mouseup", onUp, true);
534
+ };
535
+ function initialWidth(table, colIdx) {
536
+ const firstRow = table.querySelector("tr");
537
+ if (!firstRow) return 100;
538
+ const cell = firstRow.children[colIdx];
539
+ if (!cell) return 100;
540
+ return Math.round(cell.getBoundingClientRect().width) || cell.offsetWidth || 100;
541
+ }
542
+ let lineEl = null;
543
+ let isDragging = false;
544
+ function getOrCreateLine() {
545
+ if (!lineEl) {
546
+ lineEl = document.createElement("div");
547
+ lineEl.className = "docflow-active-border-line";
548
+ Object.assign(lineEl.style, {
549
+ position: "fixed",
550
+ width: "3px",
551
+ background: "#06b6d4",
552
+ boxShadow: "0 0 8px rgba(6, 182, 212, 0.9)",
553
+ pointerEvents: "none",
554
+ zIndex: "999999",
555
+ display: "none",
556
+ borderRadius: "1.5px"
557
+ });
558
+ const dotTop = document.createElement("div");
559
+ Object.assign(dotTop.style, {
560
+ position: "absolute",
561
+ top: "-4px",
562
+ left: "-3.5px",
563
+ width: "10px",
564
+ height: "10px",
565
+ borderRadius: "50%",
566
+ background: "#ffffff",
567
+ border: "2px solid #06b6d4"
568
+ });
569
+ const dotBottom = document.createElement("div");
570
+ Object.assign(dotBottom.style, {
571
+ position: "absolute",
572
+ bottom: "-4px",
573
+ left: "-3.5px",
574
+ width: "10px",
575
+ height: "10px",
576
+ borderRadius: "50%",
577
+ background: "#ffffff",
578
+ border: "2px solid #06b6d4"
579
+ });
580
+ lineEl.appendChild(dotTop);
581
+ lineEl.appendChild(dotBottom);
582
+ document.body.appendChild(lineEl);
583
+ }
584
+ return lineEl;
585
+ }
586
+ function showLine(table, borderX) {
587
+ const line = getOrCreateLine();
588
+ const tableRect = table.getBoundingClientRect();
589
+ line.style.left = `${borderX - 1.5}px`;
590
+ line.style.top = `${tableRect.top}px`;
591
+ line.style.height = `${tableRect.height}px`;
592
+ line.style.display = "block";
593
+ document.body.style.cursor = "col-resize";
594
+ view.dom.style.cursor = "col-resize";
595
+ }
596
+ function hideLine() {
597
+ if (lineEl) {
598
+ lineEl.style.display = "none";
599
+ }
600
+ document.body.style.cursor = "";
601
+ view.dom.style.cursor = "";
602
+ }
603
+ const onMouseMoveHover = function(event) {
604
+ if (isDragging) return;
605
+ const target = event.target;
606
+ const td = target.closest("td, th");
607
+ if (!td) {
608
+ hideLine();
609
+ return;
610
+ }
611
+ const r = td.getBoundingClientRect();
612
+ const distRight = Math.abs(event.clientX - r.right);
613
+ const distLeft = Math.abs(event.clientX - r.left);
614
+ const parent = td.parentElement;
615
+ if (!parent) {
616
+ hideLine();
617
+ return;
618
+ }
619
+ const colIdx = Array.from(parent.children).indexOf(td);
620
+ let borderX = -1;
621
+ if (distRight <= 16) {
622
+ borderX = r.right;
623
+ } else if (distLeft <= 16 && colIdx > 0) {
624
+ borderX = r.left;
625
+ }
626
+ if (borderX >= 0) {
627
+ const table = td.closest("table");
628
+ if (table) {
629
+ showLine(table, borderX);
630
+ }
631
+ } else {
632
+ hideLine();
633
+ }
634
+ };
635
+ document.addEventListener("mousemove", onMouseMoveHover, true);
636
+ view.dom.addEventListener("mousedown", function handleMouseDown(event) {
637
+ onMouseDown(event);
638
+ const td = event.target.closest("td, th");
639
+ if (!td) return;
640
+ const r = td.getBoundingClientRect();
641
+ const distRight = Math.abs(event.clientX - r.right);
642
+ const distLeft = Math.abs(event.clientX - r.left);
643
+ const parent = td.parentElement;
644
+ if (!parent) return;
645
+ const colIdx = Array.from(parent.children).indexOf(td);
646
+ if (distRight <= 16 || distLeft <= 16 && colIdx > 0) {
647
+ isDragging = true;
648
+ hideLine();
649
+ const onDragEnd = function() {
650
+ isDragging = false;
651
+ hideLine();
652
+ document.removeEventListener("mouseup", onDragEnd, true);
653
+ };
654
+ document.addEventListener("mouseup", onDragEnd, true);
655
+ }
656
+ }, true);
657
+ return {
658
+ destroy: function() {
659
+ document.removeEventListener("mousemove", onMouseMoveHover, true);
660
+ if (lineEl && lineEl.parentElement) {
661
+ lineEl.parentElement.removeChild(lineEl);
662
+ }
663
+ lineEl = null;
664
+ hideLine();
665
+ }
666
+ };
667
+ }
668
+ })];
669
+ }
670
+ });
671
+
672
+ // src/SearchAndReplace.ts
673
+ var import_core4 = require("@tiptap/core");
674
+ var import_state3 = require("@tiptap/pm/state");
384
675
  var import_view2 = require("@tiptap/pm/view");
385
- var searchAndReplaceKey = new import_state2.PluginKey("searchAndReplace");
676
+ var searchAndReplaceKey = new import_state3.PluginKey("searchAndReplace");
386
677
  var EMPTY_STATE = { query: "", matches: [], activeIndex: 0 };
387
678
  function findMatches(doc, query) {
388
679
  const matches = [];
@@ -407,7 +698,7 @@ function computeState(doc, query, activeIndex = 0) {
407
698
  const matches = findMatches(doc, query);
408
699
  return { query, matches, activeIndex: clampIndex(activeIndex, matches) };
409
700
  }
410
- var searchPlugin = new import_state2.Plugin({
701
+ var searchPlugin = new import_state3.Plugin({
411
702
  key: searchAndReplaceKey,
412
703
  state: {
413
704
  init: () => EMPTY_STATE,
@@ -439,7 +730,7 @@ var searchPlugin = new import_state2.Plugin({
439
730
  }
440
731
  }
441
732
  });
442
- var SearchAndReplaceExtension = import_core3.Extension.create({
733
+ var SearchAndReplaceExtension = import_core4.Extension.create({
443
734
  name: "searchAndReplace",
444
735
  addProseMirrorPlugins() {
445
736
  return [searchPlugin];
@@ -459,7 +750,7 @@ function activateMatch(editor, index) {
459
750
  const match = s.matches[index];
460
751
  const tr = editor.state.tr.setMeta(searchAndReplaceKey, { type: "setActive", index });
461
752
  if (match) {
462
- tr.setSelection(import_state2.TextSelection.create(editor.state.doc, match.from, match.to));
753
+ tr.setSelection(import_state3.TextSelection.create(editor.state.doc, match.from, match.to));
463
754
  tr.scrollIntoView();
464
755
  }
465
756
  editor.view.dispatch(tr);
@@ -496,13 +787,13 @@ function replaceAll(editor, replacement) {
496
787
  return s.matches.length;
497
788
  }
498
789
 
499
- // src/pagination/PaginationPlus.ts
500
- var import_core4 = require("@tiptap/core");
501
- var import_state3 = require("@tiptap/pm/state");
790
+ // ../../node_modules/.pnpm/tiptap-pagination-plus@3.1.0_patch_hash=4857789ba5672a185fb96bdd854e03e0c6ec8ed26abfeea_16730b2b361cd3f71113c52459ed62fd/node_modules/tiptap-pagination-plus/dist/PaginationPlus.js
791
+ var import_core5 = require("@tiptap/core");
792
+ var import_state4 = require("@tiptap/pm/state");
502
793
  var import_transform = require("@tiptap/pm/transform");
503
794
  var import_view3 = require("@tiptap/pm/view");
504
795
 
505
- // src/pagination/utils.ts
796
+ // ../../node_modules/.pnpm/tiptap-pagination-plus@3.1.0_patch_hash=4857789ba5672a185fb96bdd854e03e0c6ec8ed26abfeea_16730b2b361cd3f71113c52459ed62fd/node_modules/tiptap-pagination-plus/dist/utils.js
506
797
  var updateCssVariables = (targetNode, config) => {
507
798
  const cssVariables = {
508
799
  "rm-page-height": `${config.pageHeight}px`,
@@ -529,32 +820,75 @@ var getPageSize = (height, width, marginTop, marginBottom, marginLeft, marginRig
529
820
  marginRight
530
821
  };
531
822
  };
532
- var getHeaderHeightSelector = (pageNumber, type) => {
533
- return type === "actual" ? `.rm-page-header-${pageNumber}` : `.rm-page-header-${pageNumber} .rm-page-header-content`;
534
- };
535
823
  var getHeaderHeight = (targetNode, pageNumbers, type) => {
536
824
  const headerHeightMap = /* @__PURE__ */ new Map();
537
825
  const clientHeader = targetNode.querySelector(getHeaderHeightSelector(0, type));
538
826
  headerHeightMap.set(0, clientHeader ? clientHeader.clientHeight : 0);
539
827
  pageNumbers.forEach((pageNumber) => {
540
- const ch = targetNode.querySelector(getHeaderHeightSelector(pageNumber, type));
541
- headerHeightMap.set(pageNumber, ch ? ch.clientHeight : 0);
828
+ const clientHeader2 = targetNode.querySelector(getHeaderHeightSelector(pageNumber, type));
829
+ const headerHeight = clientHeader2 ? clientHeader2.clientHeight : 0;
830
+ headerHeightMap.set(pageNumber, headerHeight);
542
831
  });
543
832
  return headerHeightMap;
544
833
  };
545
- var getFooterHeightSelector = (pageNumber, type) => {
546
- return type === "actual" ? `.rm-page-footer-${pageNumber}` : `.rm-page-footer-${pageNumber} .rm-page-footer-content`;
834
+ var getHeaderHeightSelector = (pageNumber, type) => {
835
+ return type === "actual" ? `.rm-page-header-${pageNumber}` : `.rm-page-header-${pageNumber} .rm-page-header-content`;
547
836
  };
548
837
  var getFooterHeight = (targetNode, pageNumbers, type) => {
549
838
  const footerHeightMap = /* @__PURE__ */ new Map();
550
839
  const clientFooter = targetNode.querySelector(getFooterHeightSelector(0, type));
551
840
  footerHeightMap.set(0, clientFooter ? clientFooter.clientHeight : 0);
552
841
  pageNumbers.forEach((pageNumber) => {
553
- const cf = targetNode.querySelector(getFooterHeightSelector(pageNumber, type));
554
- footerHeightMap.set(pageNumber, cf ? cf.clientHeight : 0);
842
+ const clientFooter2 = targetNode.querySelector(getFooterHeightSelector(pageNumber, type));
843
+ const footerHeight = clientFooter2 ? clientFooter2.clientHeight : 0;
844
+ footerHeightMap.set(pageNumber, footerHeight);
555
845
  });
556
846
  return footerHeightMap;
557
847
  };
848
+ var getFooterHeightSelector = (pageNumber, type) => {
849
+ return type === "actual" ? `.rm-page-footer-${pageNumber}` : `.rm-page-footer-${pageNumber} .rm-page-footer-content`;
850
+ };
851
+ function deepEqualIterative(a, b) {
852
+ if (a === b)
853
+ return true;
854
+ if (typeof a !== "object" || typeof b !== "object" || a == null || b == null) {
855
+ return false;
856
+ }
857
+ const stack = [{ x: a, y: b }];
858
+ while (stack.length) {
859
+ const _stackItem = stack.pop();
860
+ if (!_stackItem)
861
+ continue;
862
+ const { x, y } = _stackItem;
863
+ if (x === y)
864
+ continue;
865
+ if (typeof x !== typeof y)
866
+ return false;
867
+ if (typeof x !== "object")
868
+ return false;
869
+ if (x == null || y == null)
870
+ return false;
871
+ const xKeys = Object.keys(x);
872
+ const yKeys = Object.keys(y);
873
+ if (xKeys.length !== yKeys.length)
874
+ return false;
875
+ for (const key2 of xKeys) {
876
+ if (!(key2 in y))
877
+ return false;
878
+ const xVal = x[key2];
879
+ const yVal = y[key2];
880
+ if (xVal === yVal)
881
+ continue;
882
+ if (typeof xVal === "object" && typeof yVal === "object") {
883
+ stack.push({ x: xVal, y: yVal });
884
+ } else {
885
+ if (xVal !== yVal)
886
+ return false;
887
+ }
888
+ }
889
+ }
890
+ return true;
891
+ }
558
892
  function getCustomPages(customHeader, customFooter) {
559
893
  return [...Object.keys(customHeader), ...Object.keys(customFooter)].map(Number);
560
894
  }
@@ -569,8 +903,8 @@ function getFooter(footerRightContent, footerLeftContent, onFooterClick, pageNum
569
903
  pageFooterContent.classList.add("rm-page-footer-content");
570
904
  pageFooterContent.style.width = "100%";
571
905
  pageFooterContent.style.overflow = "hidden";
572
- const footerRight = (footerRightContent || "").replace("{page}", `<span class="rm-page-number"></span>`);
573
- const footerLeft = (footerLeftContent || "").replace("{page}", `<span class="rm-page-number"></span>`);
906
+ const footerRight = footerRightContent.replace("{page}", `<span class="rm-page-number"></span>`);
907
+ const footerLeft = footerLeftContent.replace("{page}", `<span class="rm-page-number"></span>`);
574
908
  const pageFooterLeft = document.createElement("div");
575
909
  pageFooterLeft.classList.add("rm-page-footer-left");
576
910
  pageFooterLeft.innerHTML = footerLeft;
@@ -593,8 +927,8 @@ function getHeader(headerRightContent, headerLeftContent, onHeaderClick, pageNum
593
927
  pageHeaderContent.classList.add("rm-page-header-content");
594
928
  pageHeaderContent.style.width = "100%";
595
929
  pageHeaderContent.style.overflow = "hidden";
596
- const headerLeft = (headerLeftContent || "").replace("{page}", `<span class="rm-page-number-plus"></span>`);
597
- const headerRight = (headerRightContent || "").replace("{page}", `<span class="rm-page-number-plus"></span>`);
930
+ const headerLeft = headerLeftContent.replace("{page}", `<span class="rm-page-number-plus"></span>`);
931
+ const headerRight = headerRightContent.replace("{page}", `<span class="rm-page-number-plus"></span>`);
598
932
  const pageHeaderLeft = document.createElement("div");
599
933
  pageHeaderLeft.classList.add("rm-page-header-left");
600
934
  pageHeaderLeft.innerHTML = headerLeft;
@@ -618,40 +952,24 @@ var getHeight = (pageOptions, _headerHeight, _footerHeight) => {
618
952
  };
619
953
  var headerClickEvent = (pageNumber, onHeaderClick) => {
620
954
  return (event) => {
621
- onHeaderClick?.({ event, pageNumber });
955
+ onHeaderClick === null || onHeaderClick === void 0 ? void 0 : onHeaderClick({
956
+ event,
957
+ pageNumber
958
+ });
622
959
  };
623
960
  };
624
961
  var footerClickEvent = (pageNumber, onFooterClick) => {
625
962
  return (event) => {
626
- onFooterClick?.({ event, pageNumber });
963
+ onFooterClick === null || onFooterClick === void 0 ? void 0 : onFooterClick({
964
+ event,
965
+ pageNumber
966
+ });
627
967
  };
628
968
  };
629
969
 
630
- // src/pagination/pageCount.ts
631
- var MAX_PAGES = 1e3;
632
- function grownPageCount(input) {
633
- const { currentPageCount, lastPageGap, pageContentAreaHeight, maxPagesByContent } = input;
634
- if (!(lastPageGap > 0) || !(pageContentAreaHeight > 0)) {
635
- return currentPageCount;
636
- }
637
- const addPage = Math.ceil(lastPageGap / pageContentAreaHeight);
638
- if (!Number.isFinite(addPage) || addPage <= 0) {
639
- return currentPageCount;
640
- }
641
- const contentCap = Math.max(currentPageCount, maxPagesByContent + 1);
642
- const desired = currentPageCount + addPage;
643
- if (desired > contentCap) {
644
- return contentCap;
645
- }
646
- if (desired > MAX_PAGES) {
647
- return currentPageCount;
648
- }
649
- return desired;
650
- }
651
-
652
- // src/pagination/PaginationPlus.ts
970
+ // ../../node_modules/.pnpm/tiptap-pagination-plus@3.1.0_patch_hash=4857789ba5672a185fb96bdd854e03e0c6ec8ed26abfeea_16730b2b361cd3f71113c52459ed62fd/node_modules/tiptap-pagination-plus/dist/PaginationPlus.js
653
971
  var page_count_meta_key = "PAGE_COUNT_META_KEY";
654
- var key = new import_state3.PluginKey("brDecoration");
972
+ var key = new import_state4.PluginKey("brDecoration");
655
973
  function buildDecorations(doc) {
656
974
  const decorations = [];
657
975
  doc.descendants((node, pos) => {
@@ -669,7 +987,7 @@ function buildDecorations(doc) {
669
987
  }
670
988
  var defaultPageConfig = {
671
989
  enabled: true,
672
- pageBreakBackground: "#f1f5f9",
990
+ pageBreakBackground: "#ffffff",
673
991
  pageHeight: 800,
674
992
  pageWidth: 789,
675
993
  marginTop: 20,
@@ -686,17 +1004,14 @@ var defaultPageConfig = {
686
1004
  customHeader: {},
687
1005
  customFooter: {}
688
1006
  };
689
- var defaultOptions = {
690
- pageGapBorderSize: 1,
691
- pageGapBorderColor: "#e5e5e5",
692
- ...defaultPageConfig
693
- };
1007
+ var defaultOptions = Object.assign({ pageGapBorderSize: 1, pageGapBorderColor: "#e5e5e5" }, defaultPageConfig);
694
1008
  var refreshPage = (targetNode, paginationEnabled = true) => {
1009
+ var _a;
695
1010
  const paginationElement = targetNode.querySelector("[data-rm-pagination]");
696
1011
  if (paginationEnabled) {
697
1012
  targetNode.removeAttribute("rm-pagination-disabled");
698
1013
  if (paginationElement) {
699
- const lastPageBreak = paginationElement.lastElementChild?.querySelector(".breaker");
1014
+ const lastPageBreak = (_a = paginationElement.lastElementChild) === null || _a === void 0 ? void 0 : _a.querySelector(".breaker");
700
1015
  if (lastPageBreak) {
701
1016
  const minHeight = lastPageBreak.offsetTop + lastPageBreak.offsetHeight;
702
1017
  targetNode.style.minHeight = `calc(${minHeight}px + 2px)`;
@@ -704,305 +1019,65 @@ var refreshPage = (targetNode, paginationEnabled = true) => {
704
1019
  }
705
1020
  } else {
706
1021
  targetNode.setAttribute("rm-pagination-disabled", "");
707
- targetNode.style.minHeight = "auto";
1022
+ targetNode.style.minHeight = `auto`;
708
1023
  }
709
1024
  };
710
1025
  var getPageConfig = (_storage, _currentOptions) => {
1026
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
711
1027
  const pageConfig = {
712
- enabled: _storage.enabled ?? defaultOptions.enabled,
713
- pageBreakBackground: _storage.pageBreakBackground ?? defaultOptions.pageBreakBackground,
714
- pageHeight: _storage.pageHeight ?? defaultOptions.pageHeight,
715
- pageWidth: _storage.pageWidth ?? defaultPageConfig.pageWidth,
716
- marginTop: _storage.marginTop ?? defaultPageConfig.marginTop,
717
- marginBottom: _storage.marginBottom ?? defaultPageConfig.marginBottom,
718
- marginLeft: _storage.marginLeft ?? defaultPageConfig.marginLeft,
719
- marginRight: _storage.marginRight ?? defaultPageConfig.marginRight,
720
- pageGap: _storage.pageGap ?? defaultPageConfig.pageGap,
721
- contentMarginTop: _storage.contentMarginTop ?? defaultPageConfig.contentMarginTop,
722
- contentMarginBottom: _storage.contentMarginBottom ?? defaultPageConfig.contentMarginBottom,
723
- footerRight: _storage.footerRight ?? defaultPageConfig.footerRight,
724
- footerLeft: _storage.footerLeft ?? defaultPageConfig.footerLeft,
725
- headerRight: _storage.headerRight ?? defaultPageConfig.headerRight,
726
- headerLeft: _storage.headerLeft ?? defaultPageConfig.headerLeft,
727
- customHeader: _storage.customHeader ?? defaultPageConfig.customHeader,
728
- customFooter: _storage.customFooter ?? defaultPageConfig.customFooter
1028
+ enabled: (_a = _storage.enabled) !== null && _a !== void 0 ? _a : defaultOptions.enabled,
1029
+ pageBreakBackground: (_b = _storage.pageBreakBackground) !== null && _b !== void 0 ? _b : defaultOptions.pageBreakBackground,
1030
+ pageHeight: (_c = _storage.pageHeight) !== null && _c !== void 0 ? _c : defaultOptions.pageHeight,
1031
+ pageWidth: (_d = _storage.pageWidth) !== null && _d !== void 0 ? _d : defaultPageConfig.pageWidth,
1032
+ marginTop: (_e = _storage.marginTop) !== null && _e !== void 0 ? _e : defaultPageConfig.marginTop,
1033
+ marginBottom: (_f = _storage.marginBottom) !== null && _f !== void 0 ? _f : defaultPageConfig.marginBottom,
1034
+ marginLeft: (_g = _storage.marginLeft) !== null && _g !== void 0 ? _g : defaultPageConfig.marginLeft,
1035
+ marginRight: (_h = _storage.marginRight) !== null && _h !== void 0 ? _h : defaultPageConfig.marginRight,
1036
+ pageGap: (_j = _storage.pageGap) !== null && _j !== void 0 ? _j : defaultPageConfig.pageGap,
1037
+ contentMarginTop: (_k = _storage.contentMarginTop) !== null && _k !== void 0 ? _k : defaultPageConfig.contentMarginTop,
1038
+ contentMarginBottom: (_l = _storage.contentMarginBottom) !== null && _l !== void 0 ? _l : defaultPageConfig.contentMarginBottom,
1039
+ footerRight: (_m = _storage.footerRight) !== null && _m !== void 0 ? _m : defaultPageConfig.footerRight,
1040
+ footerLeft: (_o = _storage.footerLeft) !== null && _o !== void 0 ? _o : defaultPageConfig.footerLeft,
1041
+ headerRight: (_p = _storage.headerRight) !== null && _p !== void 0 ? _p : defaultPageConfig.headerRight,
1042
+ headerLeft: (_q = _storage.headerLeft) !== null && _q !== void 0 ? _q : defaultPageConfig.headerLeft,
1043
+ customHeader: (_r = _storage.customHeader) !== null && _r !== void 0 ? _r : defaultPageConfig.customHeader,
1044
+ customFooter: (_s = _storage.customFooter) !== null && _s !== void 0 ? _s : defaultPageConfig.customFooter
729
1045
  };
730
1046
  return {
731
1047
  config: pageConfig,
732
- options: { ..._currentOptions, ...pageConfig }
1048
+ options: Object.assign(Object.assign({}, _currentOptions), pageConfig)
733
1049
  };
734
1050
  };
735
1051
  var getPageConfigFromOptions = (_currentOptions) => {
1052
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
736
1053
  return {
737
- enabled: _currentOptions.enabled ?? defaultOptions.enabled,
738
- pageBreakBackground: _currentOptions.pageBreakBackground ?? defaultOptions.pageBreakBackground,
739
- pageHeight: _currentOptions.pageHeight ?? defaultOptions.pageHeight,
740
- pageWidth: _currentOptions.pageWidth ?? defaultPageConfig.pageWidth,
741
- marginTop: _currentOptions.marginTop ?? defaultPageConfig.marginTop,
742
- marginBottom: _currentOptions.marginBottom ?? defaultPageConfig.marginBottom,
743
- marginLeft: _currentOptions.marginLeft ?? defaultPageConfig.marginLeft,
744
- marginRight: _currentOptions.marginRight ?? defaultPageConfig.marginRight,
745
- pageGap: _currentOptions.pageGap ?? defaultPageConfig.pageGap,
746
- contentMarginTop: _currentOptions.contentMarginTop ?? defaultPageConfig.contentMarginTop,
747
- contentMarginBottom: _currentOptions.contentMarginBottom ?? defaultPageConfig.contentMarginBottom,
748
- footerRight: _currentOptions.footerRight ?? defaultPageConfig.footerRight,
749
- footerLeft: _currentOptions.footerLeft ?? defaultPageConfig.footerLeft,
750
- headerRight: _currentOptions.headerRight ?? defaultPageConfig.headerRight,
751
- headerLeft: _currentOptions.headerLeft ?? defaultPageConfig.headerLeft,
752
- customHeader: _currentOptions.customHeader ?? defaultPageConfig.customHeader,
753
- customFooter: _currentOptions.customFooter ?? defaultPageConfig.customFooter
754
- };
755
- };
756
- var paginationKey = new import_state3.PluginKey("pagination");
757
- var getExistingPageCount = (view) => {
758
- const editorDom = view.dom;
759
- const paginationElement = editorDom.querySelector("[data-rm-pagination]");
760
- if (paginationElement) {
761
- return paginationElement.children.length;
762
- }
763
- return 0;
764
- };
765
- var lastContentChild = (editorDom) => {
766
- for (let i = editorDom.children.length - 1; i >= 0; i--) {
767
- const child = editorDom.children[i];
768
- if (!(child instanceof HTMLElement)) continue;
769
- if (child.hasAttribute("data-rm-pagination")) continue;
770
- if (child.classList.contains("rm-page-break")) continue;
771
- return child;
772
- }
773
- return null;
774
- };
775
- var pageGapTracker = /* @__PURE__ */ new WeakMap();
776
- var calculatePageCount = (view, pageOptions, headerHeight = 0, footerHeight = 0) => {
777
- const editorDom = view.dom;
778
- const _pageHeaderHeight = pageOptions.contentMarginTop + pageOptions.marginTop + headerHeight;
779
- const _pageFooterHeight = pageOptions.contentMarginBottom + pageOptions.marginBottom + footerHeight;
780
- const pageContentAreaHeight = pageOptions.pageHeight - _pageHeaderHeight - _pageFooterHeight;
781
- const paginationElement = editorDom.querySelector("[data-rm-pagination]");
782
- const currentPageCount = getExistingPageCount(view);
783
- if (paginationElement) {
784
- const lastElementOfEditor = lastContentChild(editorDom);
785
- const lastPageBreak = paginationElement.lastElementChild?.querySelector(".breaker");
786
- if (lastElementOfEditor && lastPageBreak) {
787
- const lastElementRect = lastElementOfEditor.getBoundingClientRect();
788
- const lastPageBreakRect = lastPageBreak.getBoundingClientRect();
789
- const lastPageGap = lastElementRect.bottom - lastPageBreakRect.bottom;
790
- if (lastPageGap > 0) {
791
- const addPage = Math.ceil(lastPageGap / pageContentAreaHeight);
792
- let totalEditorContentHeight = 0;
793
- for (const child of Array.from(editorDom.children)) {
794
- if (!(child instanceof HTMLElement)) continue;
795
- if (child.hasAttribute("data-rm-pagination")) continue;
796
- if (child.classList.contains("rm-page-break")) continue;
797
- totalEditorContentHeight += child.getBoundingClientRect().height;
798
- }
799
- const maxPagesByContent = Math.ceil(totalEditorContentHeight / pageContentAreaHeight);
800
- const prev = pageGapTracker.get(editorDom);
801
- if (prev && prev.pages < currentPageCount && lastPageGap > prev.gap - 2 && currentPageCount >= maxPagesByContent) {
802
- return currentPageCount;
803
- }
804
- const recent = prev?.recent ?? [];
805
- let flapping = prev?.flapping ?? [];
806
- if (recent.length >= 4 && recent.filter((p) => p === currentPageCount + addPage).length >= 2 && currentPageCount >= maxPagesByContent) {
807
- flapping = [.../* @__PURE__ */ new Set([...flapping, currentPageCount + addPage, currentPageCount])];
808
- pageGapTracker.set(editorDom, { gap: lastPageGap, pages: currentPageCount, recent, flapping });
809
- return currentPageCount;
810
- }
811
- pageGapTracker.set(editorDom, { gap: lastPageGap, pages: currentPageCount, recent, flapping });
812
- return grownPageCount({
813
- currentPageCount,
814
- lastPageGap,
815
- pageContentAreaHeight,
816
- maxPagesByContent
817
- });
818
- } else {
819
- const allBreaksAfterLastElement = Array.from(paginationElement.querySelectorAll(".breaker"));
820
- const allBreaksAfterLastElementRect = allBreaksAfterLastElement.filter(
821
- (element) => element.getBoundingClientRect().top > lastElementRect.bottom
822
- );
823
- const removePage = allBreaksAfterLastElementRect.length;
824
- if (removePage > 1) {
825
- return currentPageCount - (removePage - 1);
826
- } else {
827
- return currentPageCount;
828
- }
829
- }
830
- }
831
- return 1;
832
- } else {
833
- const editorHeight = editorDom.scrollHeight;
834
- let pageCount = Math.ceil(editorHeight / pageContentAreaHeight);
835
- pageCount = pageCount <= 0 ? 1 : pageCount;
836
- return pageCount;
837
- }
838
- };
839
- var getNewPageCount = (view, pageOptions) => {
840
- if (pageOptions.enabled) {
841
- const pageCount = calculatePageCount(view, pageOptions);
842
- return pageCount <= 1 ? 1 : pageCount;
843
- } else return 0;
844
- };
845
- function createDecoration(pageOptions, headerHeightMap, footerHeightMap) {
846
- if (!pageOptions.enabled) return [];
847
- const commonHeaderOptions = {
848
- headerLeft: pageOptions.headerLeft,
849
- headerRight: pageOptions.headerRight
850
- };
851
- const commonFooterOptions = {
852
- footerLeft: pageOptions.footerLeft,
853
- footerRight: pageOptions.footerRight
1054
+ enabled: (_a = _currentOptions.enabled) !== null && _a !== void 0 ? _a : defaultOptions.enabled,
1055
+ pageBreakBackground: (_b = _currentOptions.pageBreakBackground) !== null && _b !== void 0 ? _b : defaultOptions.pageBreakBackground,
1056
+ pageHeight: (_c = _currentOptions.pageHeight) !== null && _c !== void 0 ? _c : defaultOptions.pageHeight,
1057
+ pageWidth: (_d = _currentOptions.pageWidth) !== null && _d !== void 0 ? _d : defaultPageConfig.pageWidth,
1058
+ marginTop: (_e = _currentOptions.marginTop) !== null && _e !== void 0 ? _e : defaultPageConfig.marginTop,
1059
+ marginBottom: (_f = _currentOptions.marginBottom) !== null && _f !== void 0 ? _f : defaultPageConfig.marginBottom,
1060
+ marginLeft: (_g = _currentOptions.marginLeft) !== null && _g !== void 0 ? _g : defaultPageConfig.marginLeft,
1061
+ marginRight: (_h = _currentOptions.marginRight) !== null && _h !== void 0 ? _h : defaultPageConfig.marginRight,
1062
+ pageGap: (_j = _currentOptions.pageGap) !== null && _j !== void 0 ? _j : defaultPageConfig.pageGap,
1063
+ contentMarginTop: (_k = _currentOptions.contentMarginTop) !== null && _k !== void 0 ? _k : defaultPageConfig.contentMarginTop,
1064
+ contentMarginBottom: (_l = _currentOptions.contentMarginBottom) !== null && _l !== void 0 ? _l : defaultPageConfig.contentMarginBottom,
1065
+ footerRight: (_m = _currentOptions.footerRight) !== null && _m !== void 0 ? _m : defaultPageConfig.footerRight,
1066
+ footerLeft: (_o = _currentOptions.footerLeft) !== null && _o !== void 0 ? _o : defaultPageConfig.footerLeft,
1067
+ headerRight: (_p = _currentOptions.headerRight) !== null && _p !== void 0 ? _p : defaultPageConfig.headerRight,
1068
+ headerLeft: (_q = _currentOptions.headerLeft) !== null && _q !== void 0 ? _q : defaultPageConfig.headerLeft,
1069
+ customHeader: (_r = _currentOptions.customHeader) !== null && _r !== void 0 ? _r : defaultPageConfig.customHeader,
1070
+ customFooter: (_s = _currentOptions.customFooter) !== null && _s !== void 0 ? _s : defaultPageConfig.customFooter
854
1071
  };
855
- return [
856
- import_view3.Decoration.widget(
857
- 0,
858
- (view) => {
859
- const _pageGap = pageOptions.pageGap;
860
- const _pageBreakBackground = pageOptions.pageBreakBackground;
861
- const el = document.createElement("div");
862
- el.dataset.rmPagination = "true";
863
- const pageBreakDefinition = (firstPage, pageHeader, pageFooter, headerHeight, footerHeight, pageNumber) => {
864
- const { _pageHeaderHeight, _pageHeight } = getHeight(pageOptions, headerHeight, footerHeight);
865
- const pageContainer = document.createElement("div");
866
- pageContainer.classList.add("rm-page-break");
867
- const page = document.createElement("div");
868
- page.classList.add("page");
869
- page.style.position = "relative";
870
- page.style.float = "left";
871
- page.style.clear = "both";
872
- const marginTop = firstPage ? `calc(${_pageHeaderHeight}px + ${_pageHeight}px)` : _pageHeight + "px";
873
- if (pageNumber) {
874
- page.style.marginTop = `var(--rm-page-content-${pageNumber}, ${marginTop})`;
875
- } else {
876
- page.style.marginTop = firstPage ? `var(--rm-page-content-first, ${marginTop})` : `var(--rm-page-content-general, ${marginTop})`;
877
- }
878
- const pageBreak = document.createElement("div");
879
- pageBreak.classList.add("breaker");
880
- pageBreak.style.width = `calc(100% + var(--rm-margin-left) + var(--rm-margin-right))`;
881
- pageBreak.style.marginLeft = `calc(-1 * var(--rm-margin-left))`;
882
- pageBreak.style.marginRight = `calc(-1 * var(--rm-margin-right))`;
883
- pageBreak.style.position = "relative";
884
- pageBreak.style.float = "left";
885
- pageBreak.style.clear = "both";
886
- pageBreak.style.left = "0px";
887
- pageBreak.style.right = "0px";
888
- pageBreak.style.zIndex = "2";
889
- const pageSpace = document.createElement("div");
890
- pageSpace.classList.add("rm-pagination-gap");
891
- pageSpace.style.height = _pageGap + "px";
892
- pageSpace.style.borderLeft = "1px solid";
893
- pageSpace.style.borderRight = "1px solid";
894
- pageSpace.style.position = "relative";
895
- pageSpace.style.setProperty("width", "calc(100% + 2px)", "important");
896
- pageSpace.style.left = "-1px";
897
- pageSpace.style.backgroundColor = _pageBreakBackground;
898
- pageSpace.style.borderLeftColor = _pageBreakBackground;
899
- pageSpace.style.borderRightColor = _pageBreakBackground;
900
- pageBreak.append(pageFooter, pageSpace, pageHeader);
901
- pageContainer.append(page, pageBreak);
902
- return pageContainer;
903
- };
904
- const _headerHeight = headerHeightMap.get(0) || 0;
905
- const _footerHeight = footerHeightMap.get(0) || 0;
906
- const fragment = document.createDocumentFragment();
907
- const pageCount = getNewPageCount(view, pageOptions);
908
- for (let i = 0; i < pageCount; i++) {
909
- const pageNumber = i + 1;
910
- const headerPageNumber = i + 2;
911
- if (headerPageNumber in pageOptions.customHeader || pageNumber in pageOptions.customFooter || pageNumber in pageOptions.customHeader) {
912
- let _headerOptions = commonHeaderOptions;
913
- let _footerOptions = commonFooterOptions;
914
- let _pageHeaderHeight = _headerHeight;
915
- let _pageFooterHeight = _footerHeight;
916
- if (headerPageNumber in pageOptions.customHeader) {
917
- _headerOptions = pageOptions.customHeader[headerPageNumber] || commonHeaderOptions;
918
- _pageHeaderHeight = headerHeightMap.get(headerPageNumber) || 0;
919
- }
920
- if (pageNumber in pageOptions.customFooter) {
921
- _footerOptions = pageOptions.customFooter[pageNumber] || commonFooterOptions;
922
- _pageFooterHeight = footerHeightMap.get(pageNumber) || 0;
923
- }
924
- const _pageHeader = getHeader(
925
- _headerOptions.headerRight,
926
- _headerOptions.headerLeft,
927
- headerClickEvent(headerPageNumber, pageOptions.onHeaderClick),
928
- headerPageNumber
929
- );
930
- const _pageFooter = getFooter(
931
- _footerOptions.footerRight,
932
- _footerOptions.footerLeft,
933
- footerClickEvent(pageNumber, pageOptions.onFooterClick),
934
- pageNumber
935
- );
936
- const pageBreak = pageBreakDefinition(
937
- i === 0,
938
- _pageHeader,
939
- _pageFooter,
940
- _pageHeaderHeight,
941
- _pageFooterHeight,
942
- pageNumber
943
- );
944
- fragment.appendChild(pageBreak);
945
- } else {
946
- const __pageHeader = getHeader(
947
- commonHeaderOptions.headerRight,
948
- commonHeaderOptions.headerLeft,
949
- headerClickEvent(headerPageNumber, pageOptions.onHeaderClick)
950
- );
951
- const __pageFooter = getFooter(
952
- commonFooterOptions.footerRight,
953
- commonFooterOptions.footerLeft,
954
- footerClickEvent(pageNumber, pageOptions.onFooterClick)
955
- );
956
- fragment.appendChild(pageBreakDefinition(i === 0, __pageHeader, __pageFooter, _headerHeight, _footerHeight));
957
- }
958
- }
959
- el.append(fragment);
960
- el.id = "pages";
961
- el.classList.add("rm-pages-wrapper");
962
- return el;
963
- },
964
- { side: -1 }
965
- ),
966
- import_view3.Decoration.widget(
967
- 0,
968
- () => {
969
- const pageNumber = 1;
970
- let _headerOptions = commonHeaderOptions;
971
- if (pageNumber in pageOptions.customHeader) {
972
- _headerOptions = pageOptions.customHeader[pageNumber];
973
- }
974
- const el = getHeader(
975
- _headerOptions.headerRight,
976
- _headerOptions.headerLeft,
977
- headerClickEvent(pageNumber, pageOptions.onHeaderClick)
978
- );
979
- el.classList.add("rm-first-page-header");
980
- return el;
981
- },
982
- { side: -1 }
983
- )
984
- ];
985
- }
986
- var PAGE_SIZES = {
987
- A4: getPageSize(1123, 794, 95, 95, 76, 76),
988
- A3: getPageSize(1591, 1123, 95, 95, 76, 76),
989
- A5: getPageSize(794, 419, 76, 76, 57, 57),
990
- LETTER: getPageSize(1060, 818, 96, 96, 96, 96),
991
- LEGAL: getPageSize(1404, 818, 96, 96, 96, 96),
992
- TABLOID: getPageSize(1635, 1060, 96, 96, 96, 96)
993
1072
  };
994
- var PaginationPlus = import_core4.Extension.create({
1073
+ var paginationKey = new import_state4.PluginKey("pagination");
1074
+ var PaginationPlus = import_core5.Extension.create({
995
1075
  name: "PaginationPlus",
996
1076
  addOptions() {
997
1077
  return defaultOptions;
998
1078
  },
999
1079
  addStorage() {
1000
- return {
1001
- ...defaultOptions,
1002
- headerHeight: /* @__PURE__ */ new Map(),
1003
- footerHeight: /* @__PURE__ */ new Map(),
1004
- appliedConfig: defaultPageConfig
1005
- };
1080
+ return Object.assign(Object.assign({}, defaultOptions), { headerHeight: /* @__PURE__ */ new Map(), footerHeight: /* @__PURE__ */ new Map(), appliedConfig: defaultPageConfig });
1006
1081
  },
1007
1082
  onCreate() {
1008
1083
  const { options: _currentOptions } = getPageConfig(this.storage, this.options);
@@ -1010,180 +1085,210 @@ var PaginationPlus = import_core4.Extension.create({
1010
1085
  const targetNode = this.editor.view.dom;
1011
1086
  targetNode.classList.add("rm-with-pagination");
1012
1087
  targetNode.style.border = `1px solid var(--rm-page-gap-border-color)`;
1013
- targetNode.style.paddingLeft = "var(--rm-margin-left)";
1014
- targetNode.style.paddingRight = "var(--rm-margin-right)";
1015
- targetNode.style.width = "var(--rm-page-width)";
1016
- updateCssVariables(targetNode, { ..._currentOptions, ...pageConfig });
1017
- if (!document.querySelector("style[data-rm-pagination-style]")) {
1018
- const style = document.createElement("style");
1019
- style.dataset.rmPaginationStyle = "";
1020
- style.textContent = `
1021
- .rm-pagination-gap{
1022
- border-top: 1px solid;
1023
- border-bottom: 1px solid;
1024
- border-color: var(--rm-page-gap-border-color);
1025
- }
1026
- .rm-with-pagination,
1027
- .rm-with-pagination .rm-first-page-header {
1028
- counter-reset: page-number page-number-plus 1;
1029
- }
1030
- .rm-with-pagination .image-plus-wrapper,
1031
- .rm-with-pagination .table-plus td,
1032
- .rm-with-pagination .table-plus th {
1033
- max-height: var(--rm-max-content-child-height);
1034
- overflow-y: auto;
1035
- }
1036
- .rm-with-pagination .image-plus-wrapper {
1037
- overflow-y: visible;
1038
- }
1039
- .rm-with-pagination .rm-page-break {
1040
- counter-increment: page-number page-number-plus;
1041
- }
1042
- .rm-with-pagination .rm-page-break:last-child .rm-pagination-gap {
1043
- display: none;
1044
- }
1045
- .rm-with-pagination .rm-page-break:last-child .rm-page-header {
1046
- display: none;
1047
- }
1048
- .rm-with-pagination table tr td,
1049
- .rm-with-pagination table tr th {
1050
- word-break: break-all;
1051
- }
1052
- .rm-with-pagination table > tr {
1053
- display: grid;
1054
- min-width: 100%;
1055
- }
1056
- .rm-with-pagination table {
1057
- border-collapse: collapse;
1058
- width: 100%;
1059
- display: contents;
1060
- }
1061
- .rm-with-pagination table tbody > tr{
1062
- display: table-row !important;
1063
- }
1064
- .rm-with-pagination *:has(>br.ProseMirror-trailingBreak:only-child) {
1065
- display: table;
1066
- width: 100%;
1067
- }
1068
- .rm-with-pagination .rm-br-decoration {
1069
- display: table;
1070
- width: 100%;
1071
- }
1072
- .rm-with-pagination .table-row-group {
1073
- max-height: var(--rm-max-content-child-height);
1074
- overflow-y: auto;
1075
- width: 100%;
1076
- }
1077
- .rm-with-pagination .rm-page-footer-left,
1078
- .rm-with-pagination .rm-page-footer-right,
1079
- .rm-with-pagination .rm-page-header-left,
1080
- .rm-with-pagination .rm-page-header-right {
1081
- display: inline-block;
1082
- }
1083
- .rm-with-pagination .rm-page-header-left,
1084
- .rm-with-pagination .rm-page-footer-left{
1085
- float: left;
1086
- margin-left: var(--rm-margin-left);
1087
- }
1088
- .rm-with-pagination .rm-page-header-right,
1089
- .rm-with-pagination .rm-page-footer-right{
1090
- float: right;
1091
- margin-right: var(--rm-margin-right);
1092
- }
1093
- .rm-with-pagination .rm-first-page-header .rm-page-header-right{
1094
- margin-right: 0px !important;
1095
- }
1096
- .rm-with-pagination .rm-first-page-header .rm-page-header-left{
1097
- margin-left: 0px !important;
1098
- }
1099
- .rm-with-pagination .rm-page-number::before {
1100
- content: counter(page-number);
1101
- }
1102
- .rm-with-pagination .rm-page-number-plus::before {
1103
- content: counter(page-number-plus);
1104
- }
1105
- .rm-with-pagination .rm-page-header,
1106
- .rm-with-pagination .rm-page-footer{
1107
- width: 100%;
1108
- }
1109
- .rm-with-pagination .rm-page-header{
1110
- padding-bottom: var(--rm-content-margin-top) !important;
1111
- padding-top: var(--rm-margin-top) !important;
1112
- display: inline-flex;
1113
- justify-content: space-between;
1114
- max-height: calc(calc(var(--rm-page-height) * 0.45) - var(--rm-margin-top) - var(--rm-content-margin-top));
1115
- overflow-y: hidden;
1116
- }
1117
- .rm-with-pagination .rm-page-footer{
1118
- padding-top: var(--rm-content-margin-bottom) !important;
1119
- padding-bottom: var(--rm-margin-bottom) !important;
1120
- display: inline-flex;
1121
- justify-content: space-between;
1122
- max-height: calc(calc(var(--rm-page-height) * 0.45) - var(--rm-content-margin-bottom) - var(--rm-margin-bottom));
1123
- overflow-y: hidden;
1124
- }
1125
- .rm-with-pagination[rm-pagination-disabled] {
1126
- padding-top: var(--rm-margin-top) !important;
1127
- padding-bottom: var(--rm-margin-bottom) !important;
1128
- }
1129
- `;
1130
- document.head.appendChild(style);
1131
- }
1088
+ targetNode.style.paddingLeft = `var(--rm-margin-left)`;
1089
+ targetNode.style.paddingRight = `var(--rm-margin-right)`;
1090
+ targetNode.style.width = `var(--rm-page-width)`;
1091
+ updateCssVariables(targetNode, Object.assign(Object.assign({}, _currentOptions), pageConfig));
1092
+ const style = document.createElement("style");
1093
+ style.dataset.rmPaginationStyle = "";
1094
+ style.textContent = `
1095
+ .rm-pagination-gap{
1096
+ border-top: 1px solid;
1097
+ border-bottom: 1px solid;
1098
+ border-color: var(--rm-page-gap-border-color);
1099
+ }
1100
+ .rm-with-pagination,
1101
+ .rm-with-pagination .rm-first-page-header {
1102
+ counter-reset: page-number page-number-plus 1;
1103
+ }
1104
+ .rm-with-pagination .image-plus-wrapper,
1105
+ .rm-with-pagination .table-plus td,
1106
+ .rm-with-pagination .table-plus th {
1107
+ max-height: var(--rm-max-content-child-height);
1108
+ overflow-y: auto;
1109
+ }
1110
+ .rm-with-pagination .image-plus-wrapper {
1111
+ overflow-y: visible;
1112
+ }
1113
+ .rm-with-pagination .rm-page-break {
1114
+ counter-increment: page-number page-number-plus;
1115
+ }
1116
+
1117
+ .rm-with-pagination .rm-page-break:last-child .rm-pagination-gap {
1118
+ display: none;
1119
+ }
1120
+ .rm-with-pagination .rm-page-break:last-child .rm-page-header {
1121
+ display: none;
1122
+ }
1123
+
1124
+ .rm-with-pagination table tr td,
1125
+ .rm-with-pagination table tr th {
1126
+ word-break: break-all;
1127
+ }
1128
+ .rm-with-pagination table > tr {
1129
+ display: grid;
1130
+ min-width: 100%;
1131
+ }
1132
+ .rm-with-pagination table {
1133
+ border-collapse: collapse;
1134
+ width: 100%;
1135
+ display: contents;
1136
+ }
1137
+ .rm-with-pagination table tbody > tr{
1138
+ display: table-row !important;
1139
+ }
1140
+ .rm-with-pagination *:has(>br.ProseMirror-trailingBreak:only-child) {
1141
+ display: table;
1142
+ width: 100%;
1143
+ }
1144
+ .rm-with-pagination .rm-br-decoration {
1145
+ display: table;
1146
+ width: 100%;
1147
+ }
1148
+ .rm-with-pagination .table-row-group {
1149
+ max-height: var(--rm-max-content-child-height);
1150
+ overflow-y: auto;
1151
+ width: 100%;
1152
+ }
1153
+ .rm-with-pagination .rm-page-footer-left,
1154
+ .rm-with-pagination .rm-page-footer-right,
1155
+ .rm-with-pagination .rm-page-header-left,
1156
+ .rm-with-pagination .rm-page-header-right {
1157
+ display: inline-block;
1158
+ }
1159
+
1160
+ .rm-with-pagination .rm-page-header-left,
1161
+ .rm-with-pagination .rm-page-footer-left{
1162
+ float: left;
1163
+ margin-left: var(--rm-margin-left);
1164
+ }
1165
+ .rm-with-pagination .rm-page-header-right,
1166
+ .rm-with-pagination .rm-page-footer-right{
1167
+ float: right;
1168
+ margin-right: var(--rm-margin-right);
1169
+ }
1170
+ .rm-with-pagination .rm-first-page-header .rm-page-header-right{
1171
+ margin-right: 0px !important;
1172
+ }
1173
+ .rm-with-pagination .rm-first-page-header .rm-page-header-left{
1174
+ margin-left: 0px !important;
1175
+ }
1176
+ .rm-with-pagination .rm-page-number::before {
1177
+ content: counter(page-number);
1178
+ }
1179
+ .rm-with-pagination .rm-page-number-plus::before {
1180
+ content: counter(page-number-plus);
1181
+ }
1182
+ .rm-with-pagination .rm-page-header,
1183
+ .rm-with-pagination .rm-page-footer{
1184
+ width: 100%;
1185
+ }
1186
+ .rm-with-pagination .rm-page-header{
1187
+ padding-bottom: var(--rm-content-margin-top) !important;
1188
+ padding-top: var(--rm-margin-top) !important;
1189
+ display: inline-flex;
1190
+ justify-content: space-between;
1191
+ max-height: calc(calc(var(--rm-page-height) * 0.45) - var(--rm-margin-top) - var(--rm-content-margin-top));
1192
+ overflow-y: hidden;
1193
+ }
1194
+ .rm-with-pagination .rm-page-footer{
1195
+ padding-top: var(--rm-content-margin-bottom) !important;
1196
+ padding-bottom: var(--rm-margin-bottom) !important;
1197
+ display: inline-flex;
1198
+ justify-content: space-between;
1199
+ max-height: calc(calc(var(--rm-page-height) * 0.45) - var(--rm-content-margin-bottom) - var(--rm-margin-bottom));
1200
+ overflow-y: hidden;
1201
+ }
1202
+ .rm-with-pagination[rm-pagination-disabled] {
1203
+ padding-top: var(--rm-margin-top) !important;
1204
+ padding-bottom: var(--rm-margin-bottom) !important;
1205
+ }
1206
+ `;
1207
+ document.head.appendChild(style);
1132
1208
  refreshPage(targetNode, _currentOptions.enabled);
1133
1209
  },
1134
1210
  addProseMirrorPlugins() {
1211
+ const editor = this.editor;
1135
1212
  const storage = this.storage;
1136
- const options = this.options;
1137
1213
  return [
1138
- new import_state3.Plugin({
1214
+ new import_state4.Plugin({
1139
1215
  key: paginationKey,
1140
1216
  state: {
1141
- init: () => import_view3.DecorationSet.empty,
1142
- apply: (tr, old) => {
1143
- const { options: _currentOptions, config: pageConfig } = getPageConfig(storage, options);
1144
- if (!pageConfig.enabled) {
1145
- return import_view3.DecorationSet.empty;
1217
+ init: (_, state) => {
1218
+ const _currentOptions = getPageConfigFromOptions(this.options);
1219
+ const pageConfig = getPageConfigFromOptions(this.options);
1220
+ const widgetList = createDecoration(Object.assign(Object.assign({}, this.options), _currentOptions), /* @__PURE__ */ new Map(), /* @__PURE__ */ new Map());
1221
+ storage.pageBreakBackground = _currentOptions.pageBreakBackground;
1222
+ storage.pageHeight = _currentOptions.pageHeight;
1223
+ storage.pageWidth = _currentOptions.pageWidth;
1224
+ storage.marginTop = _currentOptions.marginTop;
1225
+ storage.marginBottom = _currentOptions.marginBottom;
1226
+ storage.marginLeft = _currentOptions.marginLeft;
1227
+ storage.marginRight = _currentOptions.marginRight;
1228
+ storage.pageGap = _currentOptions.pageGap;
1229
+ storage.contentMarginTop = _currentOptions.contentMarginTop;
1230
+ storage.contentMarginBottom = _currentOptions.contentMarginBottom;
1231
+ storage.footerRight = _currentOptions.footerRight;
1232
+ storage.footerLeft = _currentOptions.footerLeft;
1233
+ storage.headerRight = _currentOptions.headerRight;
1234
+ storage.headerLeft = _currentOptions.headerLeft;
1235
+ storage.customHeader = _currentOptions.customHeader;
1236
+ storage.customFooter = _currentOptions.customFooter;
1237
+ storage.headerHeight = /* @__PURE__ */ new Map();
1238
+ storage.footerHeight = /* @__PURE__ */ new Map();
1239
+ storage.appliedConfig = pageConfig;
1240
+ return {
1241
+ decorations: import_view3.DecorationSet.create(state.doc, widgetList)
1242
+ };
1243
+ },
1244
+ apply: (tr, oldDeco, oldState, newState) => {
1245
+ const { options: _currentOptions, config: pageConfig } = getPageConfig(storage, this.options);
1246
+ if (storage.enabled === storage.appliedConfig.enabled && storage.enabled === false && storage.appliedConfig.enabled === false) {
1247
+ return oldDeco;
1146
1248
  }
1147
- const footerHeight = storage.footerHeight;
1148
- const headerHeight = storage.headerHeight;
1149
- const isPageCountChanged = tr.getMeta(page_count_meta_key);
1150
- if (isPageCountChanged || tr.docChanged) {
1151
- return import_view3.DecorationSet.create(
1152
- tr.doc,
1153
- createDecoration(
1154
- { ..._currentOptions, ...pageConfig },
1155
- headerHeight ?? /* @__PURE__ */ new Map(),
1156
- footerHeight ?? /* @__PURE__ */ new Map()
1157
- )
1158
- );
1249
+ const pageCount = getNewPageCount(editor.view, Object.assign(Object.assign({}, _currentOptions), pageConfig));
1250
+ const currentPageCount = getExistingPageCount(editor.view);
1251
+ const getNewDecoration = () => {
1252
+ const { options: _currentOptions2, config: pageConfig2 } = getPageConfig(storage, this.options);
1253
+ updateCssVariables(editor.view.dom, _currentOptions2);
1254
+ let headerHeight = "headerHeight" in this.storage ? this.storage.headerHeight : /* @__PURE__ */ new Map();
1255
+ let footerHeight = "footerHeight" in this.storage ? this.storage.footerHeight : /* @__PURE__ */ new Map();
1256
+ const widgetList = createDecoration(Object.assign(Object.assign({}, _currentOptions2), pageConfig2), headerHeight, footerHeight);
1257
+ storage.appliedConfig = pageConfig2;
1258
+ storage.headerHeight = headerHeight;
1259
+ storage.footerHeight = footerHeight;
1260
+ return {
1261
+ decorations: import_view3.DecorationSet.create(newState.doc, [...widgetList]),
1262
+ footerHeight
1263
+ };
1264
+ };
1265
+ if (
1266
+ // If pagination is enabled only then check for other changes
1267
+ (pageCount > 1 ? pageCount : 1) !== currentPageCount || storage.enabled !== storage.appliedConfig.enabled || storage.pageBreakBackground !== storage.appliedConfig.pageBreakBackground || storage.pageHeight !== storage.appliedConfig.pageHeight || storage.pageWidth !== storage.appliedConfig.pageWidth || storage.marginTop !== storage.appliedConfig.marginTop || storage.marginBottom !== storage.appliedConfig.marginBottom || storage.marginLeft !== storage.appliedConfig.marginLeft || storage.marginRight !== storage.appliedConfig.marginRight || storage.pageGap !== storage.appliedConfig.pageGap || storage.contentMarginTop !== storage.appliedConfig.contentMarginTop || storage.contentMarginBottom !== storage.appliedConfig.contentMarginBottom || storage.headerLeft !== storage.appliedConfig.headerLeft || storage.headerRight !== storage.appliedConfig.headerRight || storage.footerLeft !== storage.appliedConfig.footerLeft || storage.footerRight !== storage.appliedConfig.footerRight || !deepEqualIterative(storage.appliedConfig.customHeader, storage.customHeader) || !deepEqualIterative(storage.appliedConfig.customFooter, storage.customFooter)
1268
+ ) {
1269
+ return getNewDecoration();
1159
1270
  }
1160
- return old;
1271
+ return oldDeco;
1161
1272
  }
1162
1273
  },
1163
1274
  props: {
1164
1275
  decorations(state) {
1165
- return paginationKey.getState(state) ?? import_view3.DecorationSet.empty;
1276
+ var _a;
1277
+ return (_a = this.getState(state)) === null || _a === void 0 ? void 0 : _a.decorations;
1166
1278
  }
1167
1279
  },
1168
- view: () => {
1280
+ view: (editorView) => {
1169
1281
  return {
1170
1282
  update: (view) => {
1171
- const { options: _currentOptions, config: pageConfig } = getPageConfig(storage, options);
1283
+ const { options: _currentOptions, config: pageConfig } = getPageConfig(storage, this.options);
1172
1284
  if (!pageConfig.enabled && !view.dom.hasAttribute("rm-pagination-disabled")) {
1173
1285
  refreshPage(view.dom, false);
1174
1286
  return;
1175
1287
  }
1176
- const pageCount = getNewPageCount(view, { ..._currentOptions, ...pageConfig });
1288
+ const pageCount = getNewPageCount(view, Object.assign(Object.assign({}, _currentOptions), pageConfig));
1177
1289
  const currentPageCount = getExistingPageCount(view);
1178
1290
  const triggerUpdate = (_footerHeight) => {
1179
1291
  requestAnimationFrame(() => {
1180
- const history = pageGapTracker.get(view.dom);
1181
- if (history && history.flapping && history.flapping.includes(pageCount)) {
1182
- return;
1183
- }
1184
- if (history && history.recent) {
1185
- history.recent.push(pageCount);
1186
- }
1187
1292
  const tr = view.state.tr.setMeta(page_count_meta_key, { footerHeight: _footerHeight });
1188
1293
  view.dispatch(tr);
1189
1294
  });
@@ -1207,7 +1312,7 @@ var PaginationPlus = import_core4.Extension.create({
1207
1312
  }
1208
1313
  }
1209
1314
  const pagesSetToCheck = /* @__PURE__ */ new Set([1, ...footerHeightForCurrentPages.keys(), ...headerHeightForCurrentPages.keys()]);
1210
- let missingPageNumber;
1315
+ let missingPageNumber = void 0;
1211
1316
  for (let i = 1; i <= pageCount; i++) {
1212
1317
  if (!pagesSetToCheck.has(i)) {
1213
1318
  missingPageNumber = i;
@@ -1218,18 +1323,18 @@ var PaginationPlus = import_core4.Extension.create({
1218
1323
  pagesSetToCheck.add(missingPageNumber);
1219
1324
  }
1220
1325
  pagesSetToCheck.delete(0);
1221
- const pageContentHeightVariable = {};
1222
- let maxContentHeight;
1326
+ let pageContentHeightVariable = {};
1327
+ let maxContentHeight = void 0;
1223
1328
  for (const page of pagesSetToCheck) {
1224
- const hHeight = headerHeightForCurrentPages.has(page) ? headerHeightForCurrentPages.get(page) || 0 : headerHeightForCurrentPages.get(0) || 0;
1225
- const fHeight = footerHeightForCurrentPages.has(page) ? footerHeightForCurrentPages.get(page) || 0 : footerHeightForCurrentPages.get(0) || 0;
1226
- const { _pageHeaderHeight, _pageHeight } = getHeight(_currentOptions, hHeight, fHeight);
1329
+ const headerHeight2 = headerHeightForCurrentPages.has(page) ? headerHeightForCurrentPages.get(page) || 0 : headerHeightForCurrentPages.get(0) || 0;
1330
+ const footerHeight2 = footerHeightForCurrentPages.has(page) ? footerHeightForCurrentPages.get(page) || 0 : footerHeightForCurrentPages.get(0) || 0;
1331
+ const { _pageHeaderHeight, _pageHeight } = getHeight(_currentOptions, headerHeight2, footerHeight2);
1227
1332
  const contentHeight = page === 1 ? _pageHeight + _pageHeaderHeight : _pageHeight;
1228
1333
  if (page === 1) {
1229
- pageContentHeightVariable["rm-page-content-first"] = `${contentHeight}px`;
1334
+ pageContentHeightVariable[`rm-page-content-first`] = `${contentHeight}px`;
1230
1335
  }
1231
1336
  if (page === missingPageNumber) {
1232
- pageContentHeightVariable["rm-page-content-general"] = `${contentHeight}px`;
1337
+ pageContentHeightVariable[`rm-page-content-general`] = `${contentHeight}px`;
1233
1338
  } else {
1234
1339
  pageContentHeightVariable[`rm-page-content-${page}`] = `${contentHeight}px`;
1235
1340
  }
@@ -1238,28 +1343,25 @@ var PaginationPlus = import_core4.Extension.create({
1238
1343
  }
1239
1344
  }
1240
1345
  if (maxContentHeight) {
1241
- ;
1242
- view.dom.style.setProperty("--rm-max-content-child-height", `${maxContentHeight - 10}px`);
1346
+ view.dom.style.setProperty(`--rm-max-content-child-height`, `${maxContentHeight - 10}px`);
1243
1347
  }
1244
- Object.entries(pageContentHeightVariable).forEach(([k, value]) => {
1245
- ;
1246
- view.dom.style.setProperty(`--${k}`, value);
1348
+ Object.entries(pageContentHeightVariable).forEach(([key2, value]) => {
1349
+ view.dom.style.setProperty(`--${key2}`, value);
1247
1350
  });
1248
1351
  refreshPage(view.dom, _currentOptions.enabled);
1352
+ return;
1249
1353
  }
1250
1354
  };
1251
1355
  }
1252
1356
  }),
1253
- new import_state3.Plugin({
1357
+ new import_state4.Plugin({
1254
1358
  key,
1255
1359
  state: {
1256
1360
  init(_, state) {
1257
1361
  return buildDecorations(state.doc);
1258
1362
  },
1259
1363
  apply(tr, old) {
1260
- if (tr.docChanged || tr.steps.some(
1261
- (step) => step instanceof import_transform.ReplaceStep || step instanceof import_transform.ReplaceAroundStep || step instanceof import_transform.AddMarkStep || step instanceof import_transform.RemoveMarkStep || step instanceof import_transform.RemoveNodeMarkStep || step instanceof import_transform.AttrStep
1262
- )) {
1364
+ if (tr.docChanged || tr.steps.some((step) => step instanceof import_transform.ReplaceStep) || tr.steps.some((step) => step instanceof import_transform.ReplaceAroundStep) || tr.steps.some((step) => step instanceof import_transform.AddMarkStep) || tr.steps.some((step) => step instanceof import_transform.RemoveMarkStep) || tr.steps.some((step) => step instanceof import_transform.RemoveNodeMarkStep) || tr.steps.some((step) => step instanceof import_transform.AttrStep)) {
1263
1365
  return buildDecorations(tr.doc);
1264
1366
  }
1265
1367
  return old;
@@ -1267,7 +1369,8 @@ var PaginationPlus = import_core4.Extension.create({
1267
1369
  },
1268
1370
  props: {
1269
1371
  decorations(state) {
1270
- return key.getState(state) ?? import_view3.DecorationSet.empty;
1372
+ var _a;
1373
+ return (_a = key.getState(state)) !== null && _a !== void 0 ? _a : import_view3.DecorationSet.empty;
1271
1374
  }
1272
1375
  }
1273
1376
  })
@@ -1307,14 +1410,31 @@ var PaginationPlus = import_core4.Extension.create({
1307
1410
  this.storage.marginRight = margins.right;
1308
1411
  return true;
1309
1412
  },
1310
- updateHeaderContent: (left, right) => () => {
1311
- if (left !== void 0) this.storage.headerLeft = left;
1312
- if (right !== void 0) this.storage.headerRight = right;
1413
+ updateContentMargins: (margins) => () => {
1414
+ this.storage.contentMarginTop = margins.top;
1415
+ this.storage.contentMarginBottom = margins.bottom;
1416
+ return true;
1417
+ },
1418
+ updateHeaderContent: (left, right, pageNumber) => () => {
1419
+ if (pageNumber) {
1420
+ this.storage.customHeader = Object.assign(Object.assign({}, this.storage.customHeader), { [pageNumber]: { headerLeft: left, headerRight: right } });
1421
+ } else {
1422
+ this.storage.headerLeft = left;
1423
+ this.storage.headerRight = right;
1424
+ }
1313
1425
  return true;
1314
1426
  },
1315
- updateFooterContent: (left, right) => () => {
1316
- if (left !== void 0) this.storage.footerLeft = left;
1317
- if (right !== void 0) this.storage.footerRight = right;
1427
+ updateFooterContent: (left, right, pageNumber) => () => {
1428
+ if (pageNumber) {
1429
+ this.storage.customFooter = Object.assign(Object.assign({}, this.storage.customFooter), { [pageNumber]: { footerLeft: left, footerRight: right } });
1430
+ } else {
1431
+ this.storage.footerLeft = left;
1432
+ this.storage.footerRight = right;
1433
+ }
1434
+ return true;
1435
+ },
1436
+ togglePagination: () => () => {
1437
+ this.storage.enabled = !this.storage.enabled;
1318
1438
  return true;
1319
1439
  },
1320
1440
  enablePagination: () => () => {
@@ -1328,94 +1448,203 @@ var PaginationPlus = import_core4.Extension.create({
1328
1448
  };
1329
1449
  }
1330
1450
  });
1331
-
1332
- // src/pagination/PaginationCaretFix.ts
1333
- var import_core5 = require("@tiptap/core");
1334
- var import_state4 = require("@tiptap/pm/state");
1335
- var PAGINATION_CLASS = "rm-with-pagination";
1336
- var PAGINATION_DISABLED_ATTR = "rm-pagination-disabled";
1337
- var dragStates = /* @__PURE__ */ new WeakMap();
1338
- var isPaginationActive = (view) => {
1339
- const dom = view.dom;
1340
- return dom.classList.contains(PAGINATION_CLASS) && dom.getAttribute(PAGINATION_DISABLED_ATTR) === null;
1451
+ var getExistingPageCount = (view) => {
1452
+ const editorDom = view.dom;
1453
+ const paginationElement = editorDom.querySelector("[data-rm-pagination]");
1454
+ if (paginationElement) {
1455
+ return paginationElement.children.length;
1456
+ }
1457
+ return 0;
1341
1458
  };
1342
- var isEditable = (view) => view.dom.getAttribute("contenteditable") !== "false";
1343
- var isPlainSingleLeftClick = (event) => event.button === 0 && event.detail === 1 && !event.shiftKey && !event.altKey && !event.ctrlKey && !event.metaKey;
1344
- function posFromTextOffset(view, textNode, offset) {
1345
- if (textNode.nodeType !== Node.TEXT_NODE || !view.dom.contains(textNode)) return null;
1346
- const text = textNode;
1347
- const clamped = Math.min(Math.max(0, offset), text.length);
1348
- const parent = text.parentElement;
1349
- if (parent?.closest?.('[contenteditable="false"]')) return null;
1350
- let pos = view.posAtDOM(text, clamped, -1);
1351
- if (pos < 0) pos = view.posAtDOM(text, clamped, 1);
1352
- if (pos < 0) return null;
1353
- return view.state.doc.resolve(pos).parent.isTextblock ? pos : null;
1354
- }
1355
- function resolvePosFromNativePoint(view, clientX, clientY) {
1356
- const doc = view.dom.ownerDocument;
1357
- if (typeof doc.caretRangeFromPoint !== "function") return null;
1358
- const range = doc.caretRangeFromPoint(clientX, clientY);
1359
- if (!range) return null;
1360
- return posFromTextOffset(view, range.startContainer, range.startOffset);
1361
- }
1362
- function stopDrag(view) {
1363
- const drag = dragStates.get(view);
1364
- if (!drag) return;
1365
- dragStates.delete(view);
1366
- const doc = view.dom.ownerDocument;
1367
- doc.removeEventListener("mousemove", drag.onMouseMove);
1368
- doc.removeEventListener("mouseup", drag.onMouseUp);
1369
- }
1370
- function beginDrag(view, anchorPos) {
1371
- stopDrag(view);
1372
- const doc = view.dom.ownerDocument;
1373
- const onMouseMove = (event) => {
1374
- const drag = dragStates.get(view);
1375
- if (!drag) return;
1376
- const pos = resolvePosFromNativePoint(view, event.clientX, event.clientY);
1377
- if (pos === null) return;
1378
- const from = Math.min(drag.anchorPos, pos);
1379
- const to = Math.max(drag.anchorPos, pos);
1380
- view.dispatch(view.state.tr.setSelection(import_state4.TextSelection.create(view.state.doc, from, to)));
1381
- };
1382
- const onMouseUp = () => {
1383
- stopDrag(view);
1384
- };
1385
- dragStates.set(view, { anchorPos, onMouseMove, onMouseUp });
1386
- doc.addEventListener("mousemove", onMouseMove);
1387
- doc.addEventListener("mouseup", onMouseUp);
1388
- }
1389
- function interceptPaginationMouseDown(view, event) {
1390
- if (!isPaginationActive(view) || !isPlainSingleLeftClick(event) || !isEditable(view)) return false;
1391
- const pos = resolvePosFromNativePoint(view, event.clientX, event.clientY);
1392
- if (pos === null) return false;
1393
- view.focus();
1394
- view.dispatch(view.state.tr.setSelection(import_state4.TextSelection.create(view.state.doc, pos)));
1395
- beginDrag(view, pos);
1396
- return true;
1397
- }
1398
- var PaginationCaretFix = import_core5.Extension.create({
1399
- name: "paginationCaretFix",
1400
- addProseMirrorPlugins() {
1401
- return [
1402
- new import_state4.Plugin({
1403
- key: new import_state4.PluginKey("paginationCaretFix"),
1404
- props: {
1405
- handleDOMEvents: {
1406
- mousedown: (view, event) => {
1407
- try {
1408
- return interceptPaginationMouseDown(view, event);
1409
- } catch {
1410
- return false;
1411
- }
1412
- }
1459
+ var pageGapTracker = /* @__PURE__ */ new WeakMap();
1460
+ var calculatePageCount = (view, pageOptions, headerHeight = 0, footerHeight = 0) => {
1461
+ var _a;
1462
+ const editorDom = view.dom;
1463
+ const _pageHeaderHeight = pageOptions.contentMarginTop + pageOptions.marginTop + headerHeight;
1464
+ const _pageFooterHeight = pageOptions.contentMarginBottom + pageOptions.marginBottom + footerHeight;
1465
+ const pageContentAreaHeight = pageOptions.pageHeight - _pageHeaderHeight - _pageFooterHeight;
1466
+ const paginationElement = editorDom.querySelector("[data-rm-pagination]");
1467
+ const currentPageCount = getExistingPageCount(view);
1468
+ if (paginationElement) {
1469
+ const lastElementOfEditor = editorDom.lastElementChild;
1470
+ const lastPageBreak = (_a = paginationElement.lastElementChild) === null || _a === void 0 ? void 0 : _a.querySelector(".breaker");
1471
+ if (lastElementOfEditor && lastPageBreak) {
1472
+ const lastElementRect = lastElementOfEditor.getBoundingClientRect();
1473
+ const lastPageBreakRect = lastPageBreak.getBoundingClientRect();
1474
+ const lastPageGap = lastElementRect.bottom - lastPageBreakRect.bottom;
1475
+ if (lastPageGap > 0) {
1476
+ const addPage = Math.ceil(lastPageGap / pageContentAreaHeight);
1477
+ if (lastElementRect.height > pageContentAreaHeight) {
1478
+ const isSplittableTable = (lastElementOfEditor === null || lastElementOfEditor === void 0 ? void 0 : lastElementOfEditor.tagName) === "TABLE" && lastElementOfEditor.hasAttribute("data-tps-splittable");
1479
+ if (!isSplittableTable) {
1480
+ return currentPageCount;
1413
1481
  }
1414
1482
  }
1415
- })
1416
- ];
1483
+ const prev = pageGapTracker.get(editorDom);
1484
+ if (prev && prev.pages < currentPageCount && lastPageGap > prev.gap - 2) {
1485
+ return currentPageCount;
1486
+ }
1487
+ pageGapTracker.set(editorDom, { gap: lastPageGap, pages: currentPageCount });
1488
+ let totalEditorContentHeight = 0;
1489
+ for (const child of editorDom.children) {
1490
+ if (!(child instanceof HTMLElement)) continue;
1491
+ if (child.hasAttribute("data-rm-pagination")) continue;
1492
+ if (child.classList.contains("rm-page-break")) continue;
1493
+ totalEditorContentHeight += child.getBoundingClientRect().height;
1494
+ }
1495
+ const maxPagesByContent = Math.ceil(totalEditorContentHeight / pageContentAreaHeight);
1496
+ const contentCap = Math.max(currentPageCount, maxPagesByContent + 1);
1497
+ if (currentPageCount + addPage > contentCap) {
1498
+ return contentCap;
1499
+ }
1500
+ const MAX_PAGES = 1e3;
1501
+ if (currentPageCount + addPage > MAX_PAGES) {
1502
+ return currentPageCount;
1503
+ }
1504
+ return currentPageCount + addPage;
1505
+ } else {
1506
+ pageGapTracker.delete(editorDom);
1507
+ const allBreaksAfterLastElement = Array.from(paginationElement.querySelectorAll(".breaker"));
1508
+ const allBreaksAfterLastElementRect = allBreaksAfterLastElement.filter((element) => element.getBoundingClientRect().top > lastElementRect.bottom);
1509
+ const removePage = allBreaksAfterLastElementRect.length;
1510
+ if (removePage > 1) {
1511
+ return currentPageCount - removePage;
1512
+ } else {
1513
+ return currentPageCount;
1514
+ }
1515
+ }
1516
+ }
1517
+ return 1;
1518
+ } else {
1519
+ const editorHeight = editorDom.scrollHeight;
1520
+ let pageCount = Math.ceil(editorHeight / pageContentAreaHeight);
1521
+ pageCount = pageCount <= 0 ? 1 : pageCount;
1522
+ return pageCount;
1417
1523
  }
1418
- });
1524
+ };
1525
+ var getNewPageCount = (view, pageOptions) => {
1526
+ if (pageOptions.enabled) {
1527
+ const pageCount = calculatePageCount(view, pageOptions);
1528
+ return pageCount <= 1 ? 1 : pageCount;
1529
+ } else {
1530
+ return 0;
1531
+ }
1532
+ };
1533
+ function createDecoration(pageOptions, headerHeightMap, footerHeightMap) {
1534
+ if (!pageOptions.enabled) {
1535
+ return [];
1536
+ }
1537
+ const commonHeaderOptions = { headerLeft: pageOptions.headerLeft, headerRight: pageOptions.headerRight };
1538
+ const commonFooterOptions = { footerLeft: pageOptions.footerLeft, footerRight: pageOptions.footerRight };
1539
+ const pageWidget = import_view3.Decoration.widget(0, (view) => {
1540
+ const _pageGap = pageOptions.pageGap;
1541
+ const _pageBreakBackground = pageOptions.pageBreakBackground;
1542
+ const el = document.createElement("div");
1543
+ el.dataset.rmPagination = "true";
1544
+ const pageBreakDefinition = (firstPage, pageHeader, pageFooter, headerHeight, footerHeight, pageNumber) => {
1545
+ const { _pageHeaderHeight, _pageHeight } = getHeight(pageOptions, headerHeight, footerHeight);
1546
+ const pageContainer = document.createElement("div");
1547
+ pageContainer.classList.add("rm-page-break");
1548
+ const page = document.createElement("div");
1549
+ page.classList.add("page");
1550
+ page.style.position = "relative";
1551
+ page.style.float = "left";
1552
+ page.style.clear = "both";
1553
+ const marginTop = firstPage ? `calc(${_pageHeaderHeight}px + ${_pageHeight}px)` : _pageHeight + "px";
1554
+ if (pageNumber) {
1555
+ page.style.marginTop = `var(--rm-page-content-${pageNumber}, ${marginTop})`;
1556
+ } else {
1557
+ page.style.marginTop = firstPage ? `var(--rm-page-content-first, ${marginTop})` : `var(--rm-page-content-general, ${marginTop})`;
1558
+ }
1559
+ const pageBreak = document.createElement("div");
1560
+ pageBreak.classList.add("breaker");
1561
+ pageBreak.style.width = `calc(100% + var(--rm-margin-left) + var(--rm-margin-right))`;
1562
+ pageBreak.style.marginLeft = `calc(-1 * var(--rm-margin-left))`;
1563
+ pageBreak.style.marginRight = `calc(-1 * var(--rm-margin-right))`;
1564
+ pageBreak.style.position = "relative";
1565
+ pageBreak.style.float = "left";
1566
+ pageBreak.style.clear = "both";
1567
+ pageBreak.style.left = `0px`;
1568
+ pageBreak.style.right = `0px`;
1569
+ pageBreak.style.zIndex = "2";
1570
+ const pageSpace = document.createElement("div");
1571
+ pageSpace.classList.add("rm-pagination-gap");
1572
+ pageSpace.style.height = _pageGap + "px";
1573
+ pageSpace.style.borderLeft = "1px solid";
1574
+ pageSpace.style.borderRight = "1px solid";
1575
+ pageSpace.style.position = "relative";
1576
+ pageSpace.style.setProperty("width", "calc(100% + 2px)", "important");
1577
+ pageSpace.style.left = "-1px";
1578
+ pageSpace.style.backgroundColor = _pageBreakBackground;
1579
+ pageSpace.style.borderLeftColor = _pageBreakBackground;
1580
+ pageSpace.style.borderRightColor = _pageBreakBackground;
1581
+ pageBreak.append(pageFooter, pageSpace, pageHeader);
1582
+ pageContainer.append(page, pageBreak);
1583
+ return pageContainer;
1584
+ };
1585
+ const _headerHeight = headerHeightMap.get(0) || 0;
1586
+ const _footerHeight = footerHeightMap.get(0) || 0;
1587
+ const fragment = document.createDocumentFragment();
1588
+ const pageCount = getNewPageCount(view, pageOptions);
1589
+ for (let i = 0; i < pageCount; i++) {
1590
+ const pageNumber = i + 1;
1591
+ const headerPageNumber = i + 2;
1592
+ if (headerPageNumber in pageOptions.customHeader || pageNumber in pageOptions.customFooter || pageNumber in pageOptions.customHeader) {
1593
+ let _headerOptions = commonHeaderOptions;
1594
+ let _footerOptions = commonFooterOptions;
1595
+ let _pageHeaderHeight = _headerHeight;
1596
+ let _pageFooterHeight = _footerHeight;
1597
+ if (headerPageNumber in pageOptions.customHeader) {
1598
+ _headerOptions = pageOptions.customHeader[headerPageNumber] || commonHeaderOptions;
1599
+ _pageHeaderHeight = headerHeightMap.get(headerPageNumber) || 0;
1600
+ }
1601
+ if (pageNumber in pageOptions.customFooter) {
1602
+ _footerOptions = pageOptions.customFooter[pageNumber] || commonFooterOptions;
1603
+ _pageFooterHeight = footerHeightMap.get(pageNumber) || 0;
1604
+ }
1605
+ let _pageHeader = getHeader(_headerOptions.headerRight, _headerOptions.headerLeft, headerClickEvent(headerPageNumber, pageOptions.onHeaderClick), headerPageNumber);
1606
+ let _pageFooter = getFooter(_footerOptions.footerRight, _footerOptions.footerLeft, footerClickEvent(pageNumber, pageOptions.onFooterClick), pageNumber);
1607
+ let pageBreak = pageBreakDefinition(i === 0, _pageHeader, _pageFooter, _pageHeaderHeight, _pageFooterHeight, pageNumber);
1608
+ fragment.appendChild(pageBreak);
1609
+ } else {
1610
+ const __pageHeader = getHeader(commonHeaderOptions.headerRight, commonHeaderOptions.headerLeft, headerClickEvent(headerPageNumber, pageOptions.onHeaderClick));
1611
+ const __pageFooter = getFooter(commonFooterOptions.footerRight, commonFooterOptions.footerLeft, footerClickEvent(pageNumber, pageOptions.onFooterClick));
1612
+ fragment.appendChild(pageBreakDefinition(i === 0, __pageHeader, __pageFooter, _headerHeight, _footerHeight));
1613
+ }
1614
+ }
1615
+ el.append(fragment);
1616
+ el.id = "pages";
1617
+ el.classList.add("rm-pages-wrapper");
1618
+ return el;
1619
+ }, { side: -1 });
1620
+ const firstHeaderWidget = import_view3.Decoration.widget(0, () => {
1621
+ const pageNumber = 1;
1622
+ let _headerOptions = commonHeaderOptions;
1623
+ if (pageNumber in pageOptions.customHeader) {
1624
+ _headerOptions = pageOptions.customHeader[pageNumber];
1625
+ }
1626
+ const el = getHeader(_headerOptions.headerRight, _headerOptions.headerLeft, headerClickEvent(pageNumber, pageOptions.onHeaderClick));
1627
+ el.classList.add("rm-first-page-header");
1628
+ return el;
1629
+ }, { side: -1 });
1630
+ return [pageWidget, firstHeaderWidget];
1631
+ }
1632
+
1633
+ // ../../node_modules/.pnpm/tiptap-pagination-plus@3.1.0_patch_hash=4857789ba5672a185fb96bdd854e03e0c6ec8ed26abfeea_16730b2b361cd3f71113c52459ed62fd/node_modules/tiptap-pagination-plus/dist/constants.js
1634
+ var A4_PAGE_SIZE = getPageSize(1123, 794, 95, 95, 76, 76);
1635
+ var A3_PAGE_SIZE = getPageSize(1591, 1123, 95, 95, 76, 76);
1636
+ var A5_PAGE_SIZE = getPageSize(794, 419, 76, 76, 57, 57);
1637
+ var LETTER_PAGE_SIZE = getPageSize(1060, 818, 96, 96, 96, 96);
1638
+ var LEGAL_PAGE_SIZE = getPageSize(1404, 818, 96, 96, 96, 96);
1639
+ var TABLOID_PAGE_SIZE = getPageSize(1635, 1060, 96, 96, 96, 96);
1640
+ var PAGE_SIZES = {
1641
+ A4: A4_PAGE_SIZE,
1642
+ A3: A3_PAGE_SIZE,
1643
+ A5: A5_PAGE_SIZE,
1644
+ LETTER: LETTER_PAGE_SIZE,
1645
+ LEGAL: LEGAL_PAGE_SIZE,
1646
+ TABLOID: TABLOID_PAGE_SIZE
1647
+ };
1419
1648
 
1420
1649
  // src/PerformanceMonitor.ts
1421
1650
  var TARGET_FRAME_MS = 1e3 / 60;
@@ -1784,7 +2013,7 @@ function createEditor(options = {}) {
1784
2013
  content: options.content ? migrateContent(options.content) : options.content
1785
2014
  };
1786
2015
  const plugins = migratedOptions.plugins ?? [];
1787
- const collaborationSetup = migratedOptions.collaboration;
2016
+ const collaborationSetup = !migratedOptions.collaboration ? void 0 : "ydoc" in migratedOptions.collaboration ? migratedOptions.collaboration : createCollaboration(migratedOptions.collaboration);
1788
2017
  const performanceMonitor = migratedOptions.debug ? createPerformanceMonitor() : void 0;
1789
2018
  let tiptapEditor = createTiptapEditor(migratedOptions, plugins, collaborationSetup);
1790
2019
  let pluginActions = createActionMap(tiptapEditor, plugins);
@@ -1825,6 +2054,7 @@ function createEditor(options = {}) {
1825
2054
  plugin.hooks?.onDestroy?.(tiptapEditor);
1826
2055
  }
1827
2056
  tiptapEditor.destroy();
2057
+ collaborationSetup?.destroy();
1828
2058
  performanceMonitor?.destroy();
1829
2059
  },
1830
2060
  use: (plugin) => {
@@ -1844,336 +2074,12 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
1844
2074
  const pluginExtensions = collectExtensions(plugins);
1845
2075
  const blockAttrs = options.getPageMap ? BlockAttributesExtension.configure({ pageMap: options.getPageMap }) : BlockAttributesExtension;
1846
2076
  const paginationExt = options.paginationOptions ? PaginationPlus.configure(options.paginationOptions) : PaginationPlus;
1847
- const ManualColumnResize = import_core6.Extension.create({
1848
- name: "manualColumnResize",
1849
- addProseMirrorPlugins() {
1850
- const key2 = new import_state5.PluginKey("manualColumnResize");
1851
- return [new import_state5.Plugin({
1852
- key: key2,
1853
- view(view) {
1854
- function pauseObserver() {
1855
- try {
1856
- view.domObserver?.stop?.();
1857
- } catch (_) {
1858
- }
1859
- }
1860
- function resumeObserver() {
1861
- try {
1862
- view.domObserver?.start?.();
1863
- } catch (_) {
1864
- }
1865
- }
1866
- function getMaxContainerWidth(tableEl) {
1867
- let curr = tableEl.parentElement;
1868
- while (curr) {
1869
- const style = window.getComputedStyle(curr);
1870
- const paddingLeft = parseFloat(style.paddingLeft) || 0;
1871
- const paddingRight = parseFloat(style.paddingRight) || 0;
1872
- const availWidth = curr.clientWidth - paddingLeft - paddingRight;
1873
- if (availWidth > 100 && (curr.classList.contains("docs-editor__paper") || curr.classList.contains("docs-editor-page") || curr.classList.contains("ProseMirror") || curr.classList.contains("rm-with-pagination"))) {
1874
- return availWidth;
1875
- }
1876
- curr = curr.parentElement;
1877
- }
1878
- return tableEl.parentElement?.clientWidth || 614;
1879
- }
1880
- const onMouseDown = function(event) {
1881
- if (event.button !== 0) return;
1882
- const td = event.target.closest("td, th");
1883
- if (!td) return;
1884
- const r = td.getBoundingClientRect();
1885
- const parent = td.parentElement;
1886
- if (!parent) return;
1887
- const cellColSpan = td.colSpan || 1;
1888
- let logicalStart = 0;
1889
- let foundCell = false;
1890
- for (const sibling of Array.from(parent.children)) {
1891
- if (sibling === td) {
1892
- foundCell = true;
1893
- break;
1894
- }
1895
- logicalStart += sibling.colSpan || 1;
1896
- }
1897
- if (!foundCell) return;
1898
- const table = td.closest("table");
1899
- if (!table) return;
1900
- const distRight = Math.abs(event.clientX - r.right);
1901
- const distLeft = Math.abs(event.clientX - r.left);
1902
- let targetColIdx = -1;
1903
- if (distRight <= 16) {
1904
- targetColIdx = logicalStart + cellColSpan - 1;
1905
- } else if (distLeft <= 16 && logicalStart > 0) {
1906
- targetColIdx = logicalStart - 1;
1907
- } else {
1908
- return;
1909
- }
1910
- const colsList = table.querySelectorAll("colgroup col");
1911
- const totalCols = colsList.length || table.querySelector("tr")?.children.length || 0;
1912
- const allColWidths = [];
1913
- for (let c = 0; c < totalCols; c++) {
1914
- const colEl = colsList[c];
1915
- const w = colEl ? parseFloat(colEl.style.width) : 0;
1916
- allColWidths[c] = w || initialWidth(table, c);
1917
- }
1918
- const isLastCol = targetColIdx === totalCols - 1;
1919
- const neighborIdx = targetColIdx + 1;
1920
- const startX = event.clientX;
1921
- const startW = allColWidths[targetColIdx] || initialWidth(table, targetColIdx);
1922
- const startNeighborW = !isLastCol ? allColWidths[neighborIdx] || initialWidth(table, neighborIdx) : 0;
1923
- const maxContainerW = getMaxContainerWidth(table);
1924
- let otherColsW = 0;
1925
- allColWidths.forEach((w, idx) => {
1926
- if (idx !== targetColIdx) otherColsW += w;
1927
- });
1928
- const maxNwLastCol = Math.max(20, maxContainerW - otherColsW);
1929
- function updateDOMWidths() {
1930
- let totalWidth = 0;
1931
- allColWidths.forEach((w, idx) => {
1932
- const col = table.querySelector(`colgroup col:nth-child(${idx + 1})`);
1933
- if (col) col.style.setProperty("width", w + "px", "important");
1934
- table.querySelectorAll("tr").forEach(function(row) {
1935
- const cell = row.children[idx];
1936
- if (cell) {
1937
- cell.style.setProperty("width", w + "px", "important");
1938
- cell.setAttribute("width", String(w));
1939
- }
1940
- });
1941
- totalWidth += w;
1942
- });
1943
- if (totalWidth > 0) {
1944
- table.style.setProperty("width", Math.min(totalWidth, maxContainerW) + "px", "important");
1945
- }
1946
- }
1947
- event.stopPropagation();
1948
- let lastNw = startW;
1949
- const onMove = function(e) {
1950
- if (!e.buttons) {
1951
- onUp(e);
1952
- return;
1953
- }
1954
- const rawDiff = e.clientX - startX;
1955
- if (isLastCol) {
1956
- const nw = Math.min(maxNwLastCol, Math.max(20, startW + rawDiff));
1957
- allColWidths[targetColIdx] = nw;
1958
- lastNw = nw;
1959
- } else {
1960
- const delta = Math.max(20 - startW, Math.min(rawDiff, startNeighborW - 20));
1961
- allColWidths[targetColIdx] = startW + delta;
1962
- allColWidths[neighborIdx] = startNeighborW - delta;
1963
- lastNw = allColWidths[targetColIdx];
1964
- }
1965
- let borderPos = table.getBoundingClientRect().left;
1966
- for (let i = 0; i <= targetColIdx; i++) borderPos += allColWidths[i];
1967
- showLine(table, borderPos);
1968
- pauseObserver();
1969
- updateDOMWidths();
1970
- resumeObserver();
1971
- };
1972
- const onUp = function(upEvent) {
1973
- document.removeEventListener("mousemove", onMove);
1974
- document.removeEventListener("mouseup", onUp, true);
1975
- upEvent.stopPropagation();
1976
- hideLine();
1977
- if (lastNw === startW) return;
1978
- try {
1979
- const { state } = view;
1980
- const { doc } = state;
1981
- let tablePos = -1;
1982
- doc.descendants((node, pos) => {
1983
- if (tablePos >= 0) return false;
1984
- if (node.type.name === "table") {
1985
- try {
1986
- const dom = view.nodeDOM(pos);
1987
- if (dom === table || dom instanceof HTMLElement && dom.contains(table) || table.contains(dom)) {
1988
- tablePos = pos;
1989
- return false;
1990
- }
1991
- } catch (_) {
1992
- }
1993
- }
1994
- return true;
1995
- });
1996
- if (tablePos >= 0) {
1997
- const tableNode = doc.nodeAt(tablePos);
1998
- if (tableNode) {
1999
- const tr = state.tr;
2000
- tableNode.forEach((row, rowOffset) => {
2001
- let cellColIdx = 0;
2002
- row.forEach((cell, cellOffset) => {
2003
- const colspan = cell.attrs.colspan || 1;
2004
- const cellPos = tablePos + 1 + rowOffset + 1 + cellOffset;
2005
- const cw = new Array(colspan);
2006
- for (let k = 0; k < colspan; k++) {
2007
- cw[k] = allColWidths[cellColIdx + k] || 100;
2008
- }
2009
- tr.setNodeMarkup(cellPos, null, { ...cell.attrs, colwidth: cw });
2010
- cellColIdx += colspan;
2011
- });
2012
- });
2013
- view.dispatch(tr);
2014
- pauseObserver();
2015
- updateDOMWidths();
2016
- resumeObserver();
2017
- }
2018
- } else {
2019
- console.warn("[Resize] could not find table position in doc");
2020
- }
2021
- } catch (err) {
2022
- console.warn("[Resize] transaction failed, falling back to DOM:", err);
2023
- pauseObserver();
2024
- updateDOMWidths();
2025
- resumeObserver();
2026
- }
2027
- };
2028
- document.addEventListener("mousemove", onMove);
2029
- document.addEventListener("mouseup", onUp, true);
2030
- };
2031
- function initialWidth(table, colIdx) {
2032
- const firstRow = table.querySelector("tr");
2033
- if (!firstRow) return 100;
2034
- const cell = firstRow.children[colIdx];
2035
- if (!cell) return 100;
2036
- return Math.round(cell.getBoundingClientRect().width) || cell.offsetWidth || 100;
2037
- }
2038
- let lineEl = null;
2039
- let isDragging = false;
2040
- function getOrCreateLine() {
2041
- if (!lineEl) {
2042
- lineEl = document.createElement("div");
2043
- lineEl.className = "docflow-active-border-line";
2044
- Object.assign(lineEl.style, {
2045
- position: "fixed",
2046
- width: "3px",
2047
- background: "#06b6d4",
2048
- boxShadow: "0 0 8px rgba(6, 182, 212, 0.9)",
2049
- pointerEvents: "none",
2050
- zIndex: "999999",
2051
- display: "none",
2052
- borderRadius: "1.5px"
2053
- });
2054
- const dotTop = document.createElement("div");
2055
- Object.assign(dotTop.style, {
2056
- position: "absolute",
2057
- top: "-4px",
2058
- left: "-3.5px",
2059
- width: "10px",
2060
- height: "10px",
2061
- borderRadius: "50%",
2062
- background: "#ffffff",
2063
- border: "2px solid #06b6d4"
2064
- });
2065
- const dotBottom = document.createElement("div");
2066
- Object.assign(dotBottom.style, {
2067
- position: "absolute",
2068
- bottom: "-4px",
2069
- left: "-3.5px",
2070
- width: "10px",
2071
- height: "10px",
2072
- borderRadius: "50%",
2073
- background: "#ffffff",
2074
- border: "2px solid #06b6d4"
2075
- });
2076
- lineEl.appendChild(dotTop);
2077
- lineEl.appendChild(dotBottom);
2078
- document.body.appendChild(lineEl);
2079
- }
2080
- return lineEl;
2081
- }
2082
- function showLine(table, borderX) {
2083
- const line = getOrCreateLine();
2084
- const tableRect = table.getBoundingClientRect();
2085
- line.style.left = `${borderX - 1.5}px`;
2086
- line.style.top = `${tableRect.top}px`;
2087
- line.style.height = `${tableRect.height}px`;
2088
- line.style.display = "block";
2089
- document.body.style.cursor = "col-resize";
2090
- view.dom.style.cursor = "col-resize";
2091
- }
2092
- function hideLine() {
2093
- if (lineEl) {
2094
- lineEl.style.display = "none";
2095
- }
2096
- document.body.style.cursor = "";
2097
- view.dom.style.cursor = "";
2098
- }
2099
- const onMouseMoveHover = function(event) {
2100
- if (isDragging) return;
2101
- const target = event.target;
2102
- const td = target.closest("td, th");
2103
- if (!td) {
2104
- hideLine();
2105
- return;
2106
- }
2107
- const r = td.getBoundingClientRect();
2108
- const distRight = Math.abs(event.clientX - r.right);
2109
- const distLeft = Math.abs(event.clientX - r.left);
2110
- const parent = td.parentElement;
2111
- if (!parent) {
2112
- hideLine();
2113
- return;
2114
- }
2115
- const colIdx = Array.from(parent.children).indexOf(td);
2116
- let borderX = -1;
2117
- if (distRight <= 16) {
2118
- borderX = r.right;
2119
- } else if (distLeft <= 16 && colIdx > 0) {
2120
- borderX = r.left;
2121
- }
2122
- if (borderX >= 0) {
2123
- const table = td.closest("table");
2124
- if (table) {
2125
- showLine(table, borderX);
2126
- }
2127
- } else {
2128
- hideLine();
2129
- }
2130
- };
2131
- document.addEventListener("mousemove", onMouseMoveHover, true);
2132
- view.dom.addEventListener("mousedown", function handleMouseDown(event) {
2133
- onMouseDown(event);
2134
- const td = event.target.closest("td, th");
2135
- if (!td) return;
2136
- const r = td.getBoundingClientRect();
2137
- const distRight = Math.abs(event.clientX - r.right);
2138
- const distLeft = Math.abs(event.clientX - r.left);
2139
- const parent = td.parentElement;
2140
- if (!parent) return;
2141
- const colIdx = Array.from(parent.children).indexOf(td);
2142
- if (distRight <= 16 || distLeft <= 16 && colIdx > 0) {
2143
- isDragging = true;
2144
- hideLine();
2145
- const onDragEnd = function() {
2146
- isDragging = false;
2147
- hideLine();
2148
- document.removeEventListener("mouseup", onDragEnd, true);
2149
- };
2150
- document.addEventListener("mouseup", onDragEnd, true);
2151
- }
2152
- }, true);
2153
- return {
2154
- destroy: function() {
2155
- document.removeEventListener("mousemove", onMouseMoveHover, true);
2156
- if (lineEl && lineEl.parentElement) {
2157
- lineEl.parentElement.removeChild(lineEl);
2158
- }
2159
- lineEl = null;
2160
- hideLine();
2161
- }
2162
- };
2163
- }
2164
- })];
2165
- }
2166
- });
2167
2077
  let extensions = [
2168
2078
  ManualColumnResize,
2169
2079
  baseStarterKit,
2170
2080
  import_extension_text_style.default,
2171
2081
  blockAttrs,
2172
2082
  paginationExt,
2173
- // Always present — fixes caret-on-click misplacement caused by the
2174
- // pagination DOM (header/footer/gap widgets breaking linear coordinates).
2175
- // No-op (gated at runtime) when pagination is off or disabled.
2176
- PaginationCaretFix,
2177
2083
  // Always present — carries host-injected ports (onImageUpload, citation, …)
2178
2084
  // in storage so plugin commands can reach them through the editor instance.
2179
2085
  EditorContextExtension.configure({
@@ -2188,18 +2094,9 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
2188
2094
  ];
2189
2095
  const content = options.collaboration ? void 0 : options.content;
2190
2096
  if (options.collaboration && collaborationSetup) {
2191
- const seed = seedEmptyFragment(collaborationSetup.ydoc);
2192
- if (seed.seeded) {
2193
- extensions.push(
2194
- import_core6.Extension.create({
2195
- name: "provisionalSeedCleanup",
2196
- onDestroy: () => seed.dispose()
2197
- })
2198
- );
2199
- }
2200
2097
  extensions = [...extensions, ...collaborationExtensions(collaborationSetup)];
2201
2098
  }
2202
- const tiptapEditor = new import_core6.Editor({
2099
+ return new import_core6.Editor({
2203
2100
  element: options.target,
2204
2101
  content,
2205
2102
  extensions,
@@ -2214,7 +2111,86 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
2214
2111
  transformPastedHTML: sanitizePastedHTML
2215
2112
  }
2216
2113
  });
2217
- return tiptapEditor;
2114
+ }
2115
+
2116
+ // src/sanitizeInlineHTML.ts
2117
+ var ALLOWED_TAGS = /* @__PURE__ */ new Set(["b", "strong", "i", "em", "u", "br"]);
2118
+ var DROP_TAGS = /* @__PURE__ */ new Set([
2119
+ "script",
2120
+ "style",
2121
+ "template",
2122
+ "noscript",
2123
+ "iframe",
2124
+ "frame",
2125
+ "frameset",
2126
+ "object",
2127
+ "embed",
2128
+ "applet",
2129
+ "svg",
2130
+ "math",
2131
+ "link",
2132
+ "meta",
2133
+ "base",
2134
+ "title",
2135
+ "form",
2136
+ "input",
2137
+ "textarea",
2138
+ "select",
2139
+ "button",
2140
+ "canvas",
2141
+ "audio",
2142
+ "video",
2143
+ "source",
2144
+ "track"
2145
+ ]);
2146
+ function unwrap2(el) {
2147
+ const parent = el.parentNode;
2148
+ if (!parent) return;
2149
+ while (el.firstChild) parent.insertBefore(el.firstChild, el);
2150
+ parent.removeChild(el);
2151
+ }
2152
+ function stripAttributes(el) {
2153
+ for (const attr of Array.from(el.attributes)) el.removeAttribute(attr.name);
2154
+ }
2155
+ function removeComments2(root) {
2156
+ const doc = root.ownerDocument;
2157
+ if (!doc) return;
2158
+ const walker = doc.createTreeWalker(
2159
+ root,
2160
+ 128
2161
+ /* NodeFilter.SHOW_COMMENT */
2162
+ );
2163
+ const comments = [];
2164
+ let node = walker.nextNode();
2165
+ while (node) {
2166
+ comments.push(node);
2167
+ node = walker.nextNode();
2168
+ }
2169
+ for (const comment of comments) comment.parentNode?.removeChild(comment);
2170
+ }
2171
+ function sanitizeInlineHTML(html) {
2172
+ if (!html || typeof html !== "string") return "";
2173
+ if (!html.includes("<")) return html;
2174
+ try {
2175
+ const doc = new DOMParser().parseFromString(html, "text/html");
2176
+ removeComments2(doc.body);
2177
+ for (const tag of DROP_TAGS) {
2178
+ for (const el of Array.from(doc.body.getElementsByTagName(tag))) {
2179
+ el.parentNode?.removeChild(el);
2180
+ }
2181
+ }
2182
+ const walk = (node) => {
2183
+ if (node.nodeType !== 1) return;
2184
+ for (const child of Array.from(node.childNodes)) walk(child);
2185
+ const el = node;
2186
+ if (ALLOWED_TAGS.has(el.tagName.toLowerCase())) stripAttributes(el);
2187
+ else unwrap2(el);
2188
+ };
2189
+ for (const child of Array.from(doc.body.childNodes)) walk(child);
2190
+ return doc.body.innerHTML;
2191
+ } catch {
2192
+ return "";
2193
+ }
2218
2194
  }
2219
2195
 
2220
2196
  // src/FontSize.ts
@@ -2327,6 +2303,113 @@ var FontSizeExtension = import_core7.Extension.create({
2327
2303
  }
2328
2304
  });
2329
2305
 
2306
+ // src/SubdocumentProvider.ts
2307
+ var import_awareness2 = require("y-protocols/awareness");
2308
+ var import_y_websocket2 = require("y-websocket");
2309
+ var Y2 = __toESM(require("yjs"), 1);
2310
+ var SubdocumentProvider = class {
2311
+ parentDoc;
2312
+ subdocs;
2313
+ awareness;
2314
+ options;
2315
+ states = /* @__PURE__ */ new Map();
2316
+ activeQueue = [];
2317
+ parentProvider = null;
2318
+ constructor(options) {
2319
+ this.options = {
2320
+ maxActive: options.maxActive ?? 5,
2321
+ onStateChange: options.onStateChange ?? (() => {
2322
+ }),
2323
+ ...options
2324
+ };
2325
+ this.parentDoc = new Y2.Doc();
2326
+ this.subdocs = this.parentDoc.getMap("subdocs");
2327
+ this.awareness = new import_awareness2.Awareness(this.parentDoc);
2328
+ this.awareness.setLocalStateField("user", this.options.user);
2329
+ this.parentProvider = new import_y_websocket2.WebsocketProvider(
2330
+ this.options.websocketUrl,
2331
+ `${this.options.roomPrefix}/_parent`,
2332
+ this.parentDoc
2333
+ );
2334
+ }
2335
+ /** Create a new subdocument. Does NOT activate it. */
2336
+ createSubdoc(id, initialState) {
2337
+ if (this.states.has(id)) return this.states.get(id).doc;
2338
+ const doc = new Y2.Doc();
2339
+ if (initialState) Y2.applyUpdate(doc, initialState);
2340
+ doc.getXmlFragment("default");
2341
+ this.subdocs.set(id, doc);
2342
+ this.states.set(id, {
2343
+ id,
2344
+ doc,
2345
+ provider: null,
2346
+ active: false
2347
+ });
2348
+ this.options.onStateChange(this.getAllStates());
2349
+ return doc;
2350
+ }
2351
+ /** Activate a subdocument — connects it to the network for live sync. */
2352
+ activate(id) {
2353
+ const state = this.states.get(id);
2354
+ if (!state || state.active) return;
2355
+ if (this.activeQueue.length >= this.options.maxActive) {
2356
+ const oldest = this.activeQueue.shift();
2357
+ if (oldest) this.deactivate(oldest);
2358
+ }
2359
+ const doc = state.doc;
2360
+ const roomName = `${this.options.roomPrefix}/${id}`;
2361
+ const provider = new import_y_websocket2.WebsocketProvider(
2362
+ this.options.websocketUrl,
2363
+ roomName,
2364
+ doc
2365
+ );
2366
+ provider.awareness.setLocalStateField("user", this.options.user);
2367
+ state.provider = provider;
2368
+ state.active = true;
2369
+ this.activeQueue.push(id);
2370
+ this.options.onStateChange(this.getAllStates());
2371
+ }
2372
+ /** Deactivate a subdocument — disconnects it from the network. */
2373
+ deactivate(id) {
2374
+ const state = this.states.get(id);
2375
+ if (!state || !state.active) return;
2376
+ state.provider?.destroy();
2377
+ state.provider = null;
2378
+ state.active = false;
2379
+ const idx = this.activeQueue.indexOf(id);
2380
+ if (idx >= 0) this.activeQueue.splice(idx, 1);
2381
+ this.options.onStateChange(this.getAllStates());
2382
+ }
2383
+ /** Get the Y.XmlFragment for a subdocument. */
2384
+ getFragment(id) {
2385
+ const doc = this.states.get(id)?.doc ?? this.subdocs.get(id);
2386
+ if (!doc) return null;
2387
+ return doc.getXmlFragment("default");
2388
+ }
2389
+ /** Check if a subdocument is currently active (syncing). */
2390
+ isActive(id) {
2391
+ return this.states.get(id)?.active ?? false;
2392
+ }
2393
+ /** Get all subdocument states. */
2394
+ getAllStates() {
2395
+ return Array.from(this.states.values());
2396
+ }
2397
+ /** Get IDs of all active subdocuments. */
2398
+ getActiveIds() {
2399
+ return [...this.activeQueue];
2400
+ }
2401
+ /** Destroy all subdocuments and providers. */
2402
+ destroy() {
2403
+ for (const [id] of this.states) {
2404
+ this.deactivate(id);
2405
+ }
2406
+ this.parentProvider?.destroy();
2407
+ this.parentDoc.destroy();
2408
+ this.states.clear();
2409
+ this.activeQueue.length = 0;
2410
+ }
2411
+ };
2412
+
2330
2413
  // src/ai/prompts.ts
2331
2414
  var CONTEXT_CHAR_CAP = 1500;
2332
2415
  var ONLY_RESULT = "Return ONLY the resulting text \u2014 no preamble, no explanation, no commentary, no markdown fences.";
@@ -2600,6 +2683,7 @@ function openaiCompatibleProvider(config) {
2600
2683
  PaginationPlus,
2601
2684
  PerformanceMonitor,
2602
2685
  SearchAndReplaceExtension,
2686
+ SubdocumentProvider,
2603
2687
  buildAIPrompt,
2604
2688
  clearSearch,
2605
2689
  collaborationExtensions,
@@ -2620,6 +2704,7 @@ function openaiCompatibleProvider(config) {
2620
2704
  replaceAll,
2621
2705
  replaceCurrent,
2622
2706
  resolveAction,
2707
+ sanitizeInlineHTML,
2623
2708
  sanitizePastedHTML,
2624
2709
  searchAndReplaceKey,
2625
2710
  searchNext,