@kedataindo/docflow-core 0.0.69 → 0.0.70

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
@@ -462,13 +462,13 @@ function replaceAll(editor, replacement) {
462
462
  return s.matches.length;
463
463
  }
464
464
 
465
- // ../../node_modules/.pnpm/tiptap-pagination-plus@3.1.0_patch_hash=4857789ba5672a185fb96bdd854e03e0c6ec8ed26abfeea_16730b2b361cd3f71113c52459ed62fd/node_modules/tiptap-pagination-plus/dist/PaginationPlus.js
465
+ // src/pagination/PaginationPlus.ts
466
466
  var import_core4 = require("@tiptap/core");
467
467
  var import_state3 = require("@tiptap/pm/state");
468
468
  var import_transform = require("@tiptap/pm/transform");
469
469
  var import_view3 = require("@tiptap/pm/view");
470
470
 
471
- // ../../node_modules/.pnpm/tiptap-pagination-plus@3.1.0_patch_hash=4857789ba5672a185fb96bdd854e03e0c6ec8ed26abfeea_16730b2b361cd3f71113c52459ed62fd/node_modules/tiptap-pagination-plus/dist/utils.js
471
+ // src/pagination/utils.ts
472
472
  var updateCssVariables = (targetNode, config) => {
473
473
  const cssVariables = {
474
474
  "rm-page-height": `${config.pageHeight}px`,
@@ -495,75 +495,32 @@ var getPageSize = (height, width, marginTop, marginBottom, marginLeft, marginRig
495
495
  marginRight
496
496
  };
497
497
  };
498
+ var getHeaderHeightSelector = (pageNumber, type) => {
499
+ return type === "actual" ? `.rm-page-header-${pageNumber}` : `.rm-page-header-${pageNumber} .rm-page-header-content`;
500
+ };
498
501
  var getHeaderHeight = (targetNode, pageNumbers, type) => {
499
502
  const headerHeightMap = /* @__PURE__ */ new Map();
500
503
  const clientHeader = targetNode.querySelector(getHeaderHeightSelector(0, type));
501
504
  headerHeightMap.set(0, clientHeader ? clientHeader.clientHeight : 0);
502
505
  pageNumbers.forEach((pageNumber) => {
503
- const clientHeader2 = targetNode.querySelector(getHeaderHeightSelector(pageNumber, type));
504
- const headerHeight = clientHeader2 ? clientHeader2.clientHeight : 0;
505
- headerHeightMap.set(pageNumber, headerHeight);
506
+ const ch = targetNode.querySelector(getHeaderHeightSelector(pageNumber, type));
507
+ headerHeightMap.set(pageNumber, ch ? ch.clientHeight : 0);
506
508
  });
507
509
  return headerHeightMap;
508
510
  };
509
- var getHeaderHeightSelector = (pageNumber, type) => {
510
- return type === "actual" ? `.rm-page-header-${pageNumber}` : `.rm-page-header-${pageNumber} .rm-page-header-content`;
511
+ var getFooterHeightSelector = (pageNumber, type) => {
512
+ return type === "actual" ? `.rm-page-footer-${pageNumber}` : `.rm-page-footer-${pageNumber} .rm-page-footer-content`;
511
513
  };
512
514
  var getFooterHeight = (targetNode, pageNumbers, type) => {
513
515
  const footerHeightMap = /* @__PURE__ */ new Map();
514
516
  const clientFooter = targetNode.querySelector(getFooterHeightSelector(0, type));
515
517
  footerHeightMap.set(0, clientFooter ? clientFooter.clientHeight : 0);
516
518
  pageNumbers.forEach((pageNumber) => {
517
- const clientFooter2 = targetNode.querySelector(getFooterHeightSelector(pageNumber, type));
518
- const footerHeight = clientFooter2 ? clientFooter2.clientHeight : 0;
519
- footerHeightMap.set(pageNumber, footerHeight);
519
+ const cf = targetNode.querySelector(getFooterHeightSelector(pageNumber, type));
520
+ footerHeightMap.set(pageNumber, cf ? cf.clientHeight : 0);
520
521
  });
521
522
  return footerHeightMap;
522
523
  };
523
- var getFooterHeightSelector = (pageNumber, type) => {
524
- return type === "actual" ? `.rm-page-footer-${pageNumber}` : `.rm-page-footer-${pageNumber} .rm-page-footer-content`;
525
- };
526
- function deepEqualIterative(a, b) {
527
- if (a === b)
528
- return true;
529
- if (typeof a !== "object" || typeof b !== "object" || a == null || b == null) {
530
- return false;
531
- }
532
- const stack = [{ x: a, y: b }];
533
- while (stack.length) {
534
- const _stackItem = stack.pop();
535
- if (!_stackItem)
536
- continue;
537
- const { x, y } = _stackItem;
538
- if (x === y)
539
- continue;
540
- if (typeof x !== typeof y)
541
- return false;
542
- if (typeof x !== "object")
543
- return false;
544
- if (x == null || y == null)
545
- return false;
546
- const xKeys = Object.keys(x);
547
- const yKeys = Object.keys(y);
548
- if (xKeys.length !== yKeys.length)
549
- return false;
550
- for (const key2 of xKeys) {
551
- if (!(key2 in y))
552
- return false;
553
- const xVal = x[key2];
554
- const yVal = y[key2];
555
- if (xVal === yVal)
556
- continue;
557
- if (typeof xVal === "object" && typeof yVal === "object") {
558
- stack.push({ x: xVal, y: yVal });
559
- } else {
560
- if (xVal !== yVal)
561
- return false;
562
- }
563
- }
564
- }
565
- return true;
566
- }
567
524
  function getCustomPages(customHeader, customFooter) {
568
525
  return [...Object.keys(customHeader), ...Object.keys(customFooter)].map(Number);
569
526
  }
@@ -578,8 +535,8 @@ function getFooter(footerRightContent, footerLeftContent, onFooterClick, pageNum
578
535
  pageFooterContent.classList.add("rm-page-footer-content");
579
536
  pageFooterContent.style.width = "100%";
580
537
  pageFooterContent.style.overflow = "hidden";
581
- const footerRight = footerRightContent.replace("{page}", `<span class="rm-page-number"></span>`);
582
- const footerLeft = footerLeftContent.replace("{page}", `<span class="rm-page-number"></span>`);
538
+ const footerRight = (footerRightContent || "").replace("{page}", `<span class="rm-page-number"></span>`);
539
+ const footerLeft = (footerLeftContent || "").replace("{page}", `<span class="rm-page-number"></span>`);
583
540
  const pageFooterLeft = document.createElement("div");
584
541
  pageFooterLeft.classList.add("rm-page-footer-left");
585
542
  pageFooterLeft.innerHTML = footerLeft;
@@ -602,8 +559,8 @@ function getHeader(headerRightContent, headerLeftContent, onHeaderClick, pageNum
602
559
  pageHeaderContent.classList.add("rm-page-header-content");
603
560
  pageHeaderContent.style.width = "100%";
604
561
  pageHeaderContent.style.overflow = "hidden";
605
- const headerLeft = headerLeftContent.replace("{page}", `<span class="rm-page-number-plus"></span>`);
606
- const headerRight = headerRightContent.replace("{page}", `<span class="rm-page-number-plus"></span>`);
562
+ const headerLeft = (headerLeftContent || "").replace("{page}", `<span class="rm-page-number-plus"></span>`);
563
+ const headerRight = (headerRightContent || "").replace("{page}", `<span class="rm-page-number-plus"></span>`);
607
564
  const pageHeaderLeft = document.createElement("div");
608
565
  pageHeaderLeft.classList.add("rm-page-header-left");
609
566
  pageHeaderLeft.innerHTML = headerLeft;
@@ -627,22 +584,16 @@ var getHeight = (pageOptions, _headerHeight, _footerHeight) => {
627
584
  };
628
585
  var headerClickEvent = (pageNumber, onHeaderClick) => {
629
586
  return (event) => {
630
- onHeaderClick === null || onHeaderClick === void 0 ? void 0 : onHeaderClick({
631
- event,
632
- pageNumber
633
- });
587
+ onHeaderClick?.({ event, pageNumber });
634
588
  };
635
589
  };
636
590
  var footerClickEvent = (pageNumber, onFooterClick) => {
637
591
  return (event) => {
638
- onFooterClick === null || onFooterClick === void 0 ? void 0 : onFooterClick({
639
- event,
640
- pageNumber
641
- });
592
+ onFooterClick?.({ event, pageNumber });
642
593
  };
643
594
  };
644
595
 
645
- // ../../node_modules/.pnpm/tiptap-pagination-plus@3.1.0_patch_hash=4857789ba5672a185fb96bdd854e03e0c6ec8ed26abfeea_16730b2b361cd3f71113c52459ed62fd/node_modules/tiptap-pagination-plus/dist/PaginationPlus.js
596
+ // src/pagination/PaginationPlus.ts
646
597
  var page_count_meta_key = "PAGE_COUNT_META_KEY";
647
598
  var key = new import_state3.PluginKey("brDecoration");
648
599
  function buildDecorations(doc) {
@@ -662,7 +613,7 @@ function buildDecorations(doc) {
662
613
  }
663
614
  var defaultPageConfig = {
664
615
  enabled: true,
665
- pageBreakBackground: "#ffffff",
616
+ pageBreakBackground: "#f1f5f9",
666
617
  pageHeight: 800,
667
618
  pageWidth: 789,
668
619
  marginTop: 20,
@@ -679,14 +630,17 @@ var defaultPageConfig = {
679
630
  customHeader: {},
680
631
  customFooter: {}
681
632
  };
682
- var defaultOptions = Object.assign({ pageGapBorderSize: 1, pageGapBorderColor: "#e5e5e5" }, defaultPageConfig);
633
+ var defaultOptions = {
634
+ pageGapBorderSize: 1,
635
+ pageGapBorderColor: "#e5e5e5",
636
+ ...defaultPageConfig
637
+ };
683
638
  var refreshPage = (targetNode, paginationEnabled = true) => {
684
- var _a;
685
639
  const paginationElement = targetNode.querySelector("[data-rm-pagination]");
686
640
  if (paginationEnabled) {
687
641
  targetNode.removeAttribute("rm-pagination-disabled");
688
642
  if (paginationElement) {
689
- const lastPageBreak = (_a = paginationElement.lastElementChild) === null || _a === void 0 ? void 0 : _a.querySelector(".breaker");
643
+ const lastPageBreak = paginationElement.lastElementChild?.querySelector(".breaker");
690
644
  if (lastPageBreak) {
691
645
  const minHeight = lastPageBreak.offsetTop + lastPageBreak.offsetHeight;
692
646
  targetNode.style.minHeight = `calc(${minHeight}px + 2px)`;
@@ -694,65 +648,304 @@ var refreshPage = (targetNode, paginationEnabled = true) => {
694
648
  }
695
649
  } else {
696
650
  targetNode.setAttribute("rm-pagination-disabled", "");
697
- targetNode.style.minHeight = `auto`;
651
+ targetNode.style.minHeight = "auto";
698
652
  }
699
653
  };
700
654
  var getPageConfig = (_storage, _currentOptions) => {
701
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
702
655
  const pageConfig = {
703
- enabled: (_a = _storage.enabled) !== null && _a !== void 0 ? _a : defaultOptions.enabled,
704
- pageBreakBackground: (_b = _storage.pageBreakBackground) !== null && _b !== void 0 ? _b : defaultOptions.pageBreakBackground,
705
- pageHeight: (_c = _storage.pageHeight) !== null && _c !== void 0 ? _c : defaultOptions.pageHeight,
706
- pageWidth: (_d = _storage.pageWidth) !== null && _d !== void 0 ? _d : defaultPageConfig.pageWidth,
707
- marginTop: (_e = _storage.marginTop) !== null && _e !== void 0 ? _e : defaultPageConfig.marginTop,
708
- marginBottom: (_f = _storage.marginBottom) !== null && _f !== void 0 ? _f : defaultPageConfig.marginBottom,
709
- marginLeft: (_g = _storage.marginLeft) !== null && _g !== void 0 ? _g : defaultPageConfig.marginLeft,
710
- marginRight: (_h = _storage.marginRight) !== null && _h !== void 0 ? _h : defaultPageConfig.marginRight,
711
- pageGap: (_j = _storage.pageGap) !== null && _j !== void 0 ? _j : defaultPageConfig.pageGap,
712
- contentMarginTop: (_k = _storage.contentMarginTop) !== null && _k !== void 0 ? _k : defaultPageConfig.contentMarginTop,
713
- contentMarginBottom: (_l = _storage.contentMarginBottom) !== null && _l !== void 0 ? _l : defaultPageConfig.contentMarginBottom,
714
- footerRight: (_m = _storage.footerRight) !== null && _m !== void 0 ? _m : defaultPageConfig.footerRight,
715
- footerLeft: (_o = _storage.footerLeft) !== null && _o !== void 0 ? _o : defaultPageConfig.footerLeft,
716
- headerRight: (_p = _storage.headerRight) !== null && _p !== void 0 ? _p : defaultPageConfig.headerRight,
717
- headerLeft: (_q = _storage.headerLeft) !== null && _q !== void 0 ? _q : defaultPageConfig.headerLeft,
718
- customHeader: (_r = _storage.customHeader) !== null && _r !== void 0 ? _r : defaultPageConfig.customHeader,
719
- customFooter: (_s = _storage.customFooter) !== null && _s !== void 0 ? _s : defaultPageConfig.customFooter
656
+ enabled: _storage.enabled ?? defaultOptions.enabled,
657
+ pageBreakBackground: _storage.pageBreakBackground ?? defaultOptions.pageBreakBackground,
658
+ pageHeight: _storage.pageHeight ?? defaultOptions.pageHeight,
659
+ pageWidth: _storage.pageWidth ?? defaultPageConfig.pageWidth,
660
+ marginTop: _storage.marginTop ?? defaultPageConfig.marginTop,
661
+ marginBottom: _storage.marginBottom ?? defaultPageConfig.marginBottom,
662
+ marginLeft: _storage.marginLeft ?? defaultPageConfig.marginLeft,
663
+ marginRight: _storage.marginRight ?? defaultPageConfig.marginRight,
664
+ pageGap: _storage.pageGap ?? defaultPageConfig.pageGap,
665
+ contentMarginTop: _storage.contentMarginTop ?? defaultPageConfig.contentMarginTop,
666
+ contentMarginBottom: _storage.contentMarginBottom ?? defaultPageConfig.contentMarginBottom,
667
+ footerRight: _storage.footerRight ?? defaultPageConfig.footerRight,
668
+ footerLeft: _storage.footerLeft ?? defaultPageConfig.footerLeft,
669
+ headerRight: _storage.headerRight ?? defaultPageConfig.headerRight,
670
+ headerLeft: _storage.headerLeft ?? defaultPageConfig.headerLeft,
671
+ customHeader: _storage.customHeader ?? defaultPageConfig.customHeader,
672
+ customFooter: _storage.customFooter ?? defaultPageConfig.customFooter
720
673
  };
721
674
  return {
722
675
  config: pageConfig,
723
- options: Object.assign(Object.assign({}, _currentOptions), pageConfig)
676
+ options: { ..._currentOptions, ...pageConfig }
724
677
  };
725
678
  };
726
679
  var getPageConfigFromOptions = (_currentOptions) => {
727
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
728
680
  return {
729
- enabled: (_a = _currentOptions.enabled) !== null && _a !== void 0 ? _a : defaultOptions.enabled,
730
- pageBreakBackground: (_b = _currentOptions.pageBreakBackground) !== null && _b !== void 0 ? _b : defaultOptions.pageBreakBackground,
731
- pageHeight: (_c = _currentOptions.pageHeight) !== null && _c !== void 0 ? _c : defaultOptions.pageHeight,
732
- pageWidth: (_d = _currentOptions.pageWidth) !== null && _d !== void 0 ? _d : defaultPageConfig.pageWidth,
733
- marginTop: (_e = _currentOptions.marginTop) !== null && _e !== void 0 ? _e : defaultPageConfig.marginTop,
734
- marginBottom: (_f = _currentOptions.marginBottom) !== null && _f !== void 0 ? _f : defaultPageConfig.marginBottom,
735
- marginLeft: (_g = _currentOptions.marginLeft) !== null && _g !== void 0 ? _g : defaultPageConfig.marginLeft,
736
- marginRight: (_h = _currentOptions.marginRight) !== null && _h !== void 0 ? _h : defaultPageConfig.marginRight,
737
- pageGap: (_j = _currentOptions.pageGap) !== null && _j !== void 0 ? _j : defaultPageConfig.pageGap,
738
- contentMarginTop: (_k = _currentOptions.contentMarginTop) !== null && _k !== void 0 ? _k : defaultPageConfig.contentMarginTop,
739
- contentMarginBottom: (_l = _currentOptions.contentMarginBottom) !== null && _l !== void 0 ? _l : defaultPageConfig.contentMarginBottom,
740
- footerRight: (_m = _currentOptions.footerRight) !== null && _m !== void 0 ? _m : defaultPageConfig.footerRight,
741
- footerLeft: (_o = _currentOptions.footerLeft) !== null && _o !== void 0 ? _o : defaultPageConfig.footerLeft,
742
- headerRight: (_p = _currentOptions.headerRight) !== null && _p !== void 0 ? _p : defaultPageConfig.headerRight,
743
- headerLeft: (_q = _currentOptions.headerLeft) !== null && _q !== void 0 ? _q : defaultPageConfig.headerLeft,
744
- customHeader: (_r = _currentOptions.customHeader) !== null && _r !== void 0 ? _r : defaultPageConfig.customHeader,
745
- customFooter: (_s = _currentOptions.customFooter) !== null && _s !== void 0 ? _s : defaultPageConfig.customFooter
681
+ enabled: _currentOptions.enabled ?? defaultOptions.enabled,
682
+ pageBreakBackground: _currentOptions.pageBreakBackground ?? defaultOptions.pageBreakBackground,
683
+ pageHeight: _currentOptions.pageHeight ?? defaultOptions.pageHeight,
684
+ pageWidth: _currentOptions.pageWidth ?? defaultPageConfig.pageWidth,
685
+ marginTop: _currentOptions.marginTop ?? defaultPageConfig.marginTop,
686
+ marginBottom: _currentOptions.marginBottom ?? defaultPageConfig.marginBottom,
687
+ marginLeft: _currentOptions.marginLeft ?? defaultPageConfig.marginLeft,
688
+ marginRight: _currentOptions.marginRight ?? defaultPageConfig.marginRight,
689
+ pageGap: _currentOptions.pageGap ?? defaultPageConfig.pageGap,
690
+ contentMarginTop: _currentOptions.contentMarginTop ?? defaultPageConfig.contentMarginTop,
691
+ contentMarginBottom: _currentOptions.contentMarginBottom ?? defaultPageConfig.contentMarginBottom,
692
+ footerRight: _currentOptions.footerRight ?? defaultPageConfig.footerRight,
693
+ footerLeft: _currentOptions.footerLeft ?? defaultPageConfig.footerLeft,
694
+ headerRight: _currentOptions.headerRight ?? defaultPageConfig.headerRight,
695
+ headerLeft: _currentOptions.headerLeft ?? defaultPageConfig.headerLeft,
696
+ customHeader: _currentOptions.customHeader ?? defaultPageConfig.customHeader,
697
+ customFooter: _currentOptions.customFooter ?? defaultPageConfig.customFooter
746
698
  };
747
699
  };
748
700
  var paginationKey = new import_state3.PluginKey("pagination");
701
+ var getExistingPageCount = (view) => {
702
+ const editorDom = view.dom;
703
+ const paginationElement = editorDom.querySelector("[data-rm-pagination]");
704
+ if (paginationElement) {
705
+ return paginationElement.children.length;
706
+ }
707
+ return 0;
708
+ };
709
+ var pageGapTracker = /* @__PURE__ */ new WeakMap();
710
+ var calculatePageCount = (view, pageOptions, headerHeight = 0, footerHeight = 0) => {
711
+ const editorDom = view.dom;
712
+ const _pageHeaderHeight = pageOptions.contentMarginTop + pageOptions.marginTop + headerHeight;
713
+ const _pageFooterHeight = pageOptions.contentMarginBottom + pageOptions.marginBottom + footerHeight;
714
+ const pageContentAreaHeight = pageOptions.pageHeight - _pageHeaderHeight - _pageFooterHeight;
715
+ const paginationElement = editorDom.querySelector("[data-rm-pagination]");
716
+ const currentPageCount = getExistingPageCount(view);
717
+ if (paginationElement) {
718
+ const lastElementOfEditor = editorDom.lastElementChild;
719
+ const lastPageBreak = paginationElement.lastElementChild?.querySelector(".breaker");
720
+ if (lastElementOfEditor && lastPageBreak) {
721
+ const lastElementRect = lastElementOfEditor.getBoundingClientRect();
722
+ const lastPageBreakRect = lastPageBreak.getBoundingClientRect();
723
+ const lastPageGap = lastElementRect.bottom - lastPageBreakRect.bottom;
724
+ if (lastPageGap > 0) {
725
+ const addPage = Math.ceil(lastPageGap / pageContentAreaHeight);
726
+ if (lastElementRect.height > pageContentAreaHeight) {
727
+ const isSplittableTable = lastElementOfEditor.tagName === "TABLE" && lastElementOfEditor.hasAttribute("data-tps-splittable");
728
+ if (!isSplittableTable) {
729
+ return currentPageCount;
730
+ }
731
+ }
732
+ const prev = pageGapTracker.get(editorDom);
733
+ if (prev && prev.pages < currentPageCount && lastPageGap > prev.gap - 2) {
734
+ return currentPageCount;
735
+ }
736
+ const recent = prev?.recent ?? [];
737
+ let flapping = prev?.flapping ?? [];
738
+ if (recent.length >= 4 && recent.filter((p) => p === currentPageCount + addPage).length >= 2) {
739
+ flapping = [.../* @__PURE__ */ new Set([...flapping, currentPageCount + addPage, currentPageCount])];
740
+ pageGapTracker.set(editorDom, { gap: lastPageGap, pages: currentPageCount, recent, flapping });
741
+ return currentPageCount;
742
+ }
743
+ pageGapTracker.set(editorDom, { gap: lastPageGap, pages: currentPageCount, recent, flapping });
744
+ let totalEditorContentHeight = 0;
745
+ for (const child of Array.from(editorDom.children)) {
746
+ if (!(child instanceof HTMLElement)) continue;
747
+ if (child.hasAttribute("data-rm-pagination")) continue;
748
+ if (child.classList.contains("rm-page-break")) continue;
749
+ totalEditorContentHeight += child.getBoundingClientRect().height;
750
+ }
751
+ const maxPagesByContent = Math.ceil(totalEditorContentHeight / pageContentAreaHeight);
752
+ const contentCap = Math.max(currentPageCount, maxPagesByContent + 1);
753
+ if (currentPageCount + addPage > contentCap) {
754
+ return contentCap;
755
+ }
756
+ const MAX_PAGES = 1e3;
757
+ if (currentPageCount + addPage > MAX_PAGES) {
758
+ return currentPageCount;
759
+ }
760
+ return currentPageCount + addPage;
761
+ } else {
762
+ const allBreaksAfterLastElement = Array.from(paginationElement.querySelectorAll(".breaker"));
763
+ const allBreaksAfterLastElementRect = allBreaksAfterLastElement.filter(
764
+ (element) => element.getBoundingClientRect().top > lastElementRect.bottom
765
+ );
766
+ const removePage = allBreaksAfterLastElementRect.length;
767
+ if (removePage > 1) {
768
+ return currentPageCount - (removePage - 1);
769
+ } else {
770
+ return currentPageCount;
771
+ }
772
+ }
773
+ }
774
+ return 1;
775
+ } else {
776
+ const editorHeight = editorDom.scrollHeight;
777
+ let pageCount = Math.ceil(editorHeight / pageContentAreaHeight);
778
+ pageCount = pageCount <= 0 ? 1 : pageCount;
779
+ return pageCount;
780
+ }
781
+ };
782
+ var getNewPageCount = (view, pageOptions) => {
783
+ if (pageOptions.enabled) {
784
+ const pageCount = calculatePageCount(view, pageOptions);
785
+ return pageCount <= 1 ? 1 : pageCount;
786
+ } else return 0;
787
+ };
788
+ function createDecoration(pageOptions, headerHeightMap, footerHeightMap) {
789
+ if (!pageOptions.enabled) return [];
790
+ const commonHeaderOptions = {
791
+ headerLeft: pageOptions.headerLeft,
792
+ headerRight: pageOptions.headerRight
793
+ };
794
+ const commonFooterOptions = {
795
+ footerLeft: pageOptions.footerLeft,
796
+ footerRight: pageOptions.footerRight
797
+ };
798
+ return [
799
+ import_view3.Decoration.widget(
800
+ 0,
801
+ (view) => {
802
+ const _pageGap = pageOptions.pageGap;
803
+ const _pageBreakBackground = pageOptions.pageBreakBackground;
804
+ const el = document.createElement("div");
805
+ el.dataset.rmPagination = "true";
806
+ const pageBreakDefinition = (firstPage, pageHeader, pageFooter, headerHeight, footerHeight, pageNumber) => {
807
+ const { _pageHeaderHeight, _pageHeight } = getHeight(pageOptions, headerHeight, footerHeight);
808
+ const pageContainer = document.createElement("div");
809
+ pageContainer.classList.add("rm-page-break");
810
+ const page = document.createElement("div");
811
+ page.classList.add("page");
812
+ page.style.position = "relative";
813
+ page.style.float = "left";
814
+ page.style.clear = "both";
815
+ const marginTop = firstPage ? `calc(${_pageHeaderHeight}px + ${_pageHeight}px)` : _pageHeight + "px";
816
+ if (pageNumber) {
817
+ page.style.marginTop = `var(--rm-page-content-${pageNumber}, ${marginTop})`;
818
+ } else {
819
+ page.style.marginTop = firstPage ? `var(--rm-page-content-first, ${marginTop})` : `var(--rm-page-content-general, ${marginTop})`;
820
+ }
821
+ const pageBreak = document.createElement("div");
822
+ pageBreak.classList.add("breaker");
823
+ pageBreak.style.width = `calc(100% + var(--rm-margin-left) + var(--rm-margin-right))`;
824
+ pageBreak.style.marginLeft = `calc(-1 * var(--rm-margin-left))`;
825
+ pageBreak.style.marginRight = `calc(-1 * var(--rm-margin-right))`;
826
+ pageBreak.style.position = "relative";
827
+ pageBreak.style.float = "left";
828
+ pageBreak.style.clear = "both";
829
+ pageBreak.style.left = "0px";
830
+ pageBreak.style.right = "0px";
831
+ pageBreak.style.zIndex = "2";
832
+ const pageSpace = document.createElement("div");
833
+ pageSpace.classList.add("rm-pagination-gap");
834
+ pageSpace.style.height = _pageGap + "px";
835
+ pageSpace.style.borderLeft = "1px solid";
836
+ pageSpace.style.borderRight = "1px solid";
837
+ pageSpace.style.position = "relative";
838
+ pageSpace.style.setProperty("width", "calc(100% + 2px)", "important");
839
+ pageSpace.style.left = "-1px";
840
+ pageSpace.style.backgroundColor = _pageBreakBackground;
841
+ pageSpace.style.borderLeftColor = _pageBreakBackground;
842
+ pageSpace.style.borderRightColor = _pageBreakBackground;
843
+ pageBreak.append(pageFooter, pageSpace, pageHeader);
844
+ pageContainer.append(page, pageBreak);
845
+ return pageContainer;
846
+ };
847
+ const _headerHeight = headerHeightMap.get(0) || 0;
848
+ const _footerHeight = footerHeightMap.get(0) || 0;
849
+ const fragment = document.createDocumentFragment();
850
+ const pageCount = getNewPageCount(view, pageOptions);
851
+ for (let i = 0; i < pageCount; i++) {
852
+ const pageNumber = i + 1;
853
+ const headerPageNumber = i + 2;
854
+ if (headerPageNumber in pageOptions.customHeader || pageNumber in pageOptions.customFooter || pageNumber in pageOptions.customHeader) {
855
+ let _headerOptions = commonHeaderOptions;
856
+ let _footerOptions = commonFooterOptions;
857
+ let _pageHeaderHeight = _headerHeight;
858
+ let _pageFooterHeight = _footerHeight;
859
+ if (headerPageNumber in pageOptions.customHeader) {
860
+ _headerOptions = pageOptions.customHeader[headerPageNumber] || commonHeaderOptions;
861
+ _pageHeaderHeight = headerHeightMap.get(headerPageNumber) || 0;
862
+ }
863
+ if (pageNumber in pageOptions.customFooter) {
864
+ _footerOptions = pageOptions.customFooter[pageNumber] || commonFooterOptions;
865
+ _pageFooterHeight = footerHeightMap.get(pageNumber) || 0;
866
+ }
867
+ const _pageHeader = getHeader(
868
+ _headerOptions.headerRight,
869
+ _headerOptions.headerLeft,
870
+ headerClickEvent(headerPageNumber, pageOptions.onHeaderClick),
871
+ headerPageNumber
872
+ );
873
+ const _pageFooter = getFooter(
874
+ _footerOptions.footerRight,
875
+ _footerOptions.footerLeft,
876
+ footerClickEvent(pageNumber, pageOptions.onFooterClick),
877
+ pageNumber
878
+ );
879
+ const pageBreak = pageBreakDefinition(
880
+ i === 0,
881
+ _pageHeader,
882
+ _pageFooter,
883
+ _pageHeaderHeight,
884
+ _pageFooterHeight,
885
+ pageNumber
886
+ );
887
+ fragment.appendChild(pageBreak);
888
+ } else {
889
+ const __pageHeader = getHeader(
890
+ commonHeaderOptions.headerRight,
891
+ commonHeaderOptions.headerLeft,
892
+ headerClickEvent(headerPageNumber, pageOptions.onHeaderClick)
893
+ );
894
+ const __pageFooter = getFooter(
895
+ commonFooterOptions.footerRight,
896
+ commonFooterOptions.footerLeft,
897
+ footerClickEvent(pageNumber, pageOptions.onFooterClick)
898
+ );
899
+ fragment.appendChild(pageBreakDefinition(i === 0, __pageHeader, __pageFooter, _headerHeight, _footerHeight));
900
+ }
901
+ }
902
+ el.append(fragment);
903
+ el.id = "pages";
904
+ el.classList.add("rm-pages-wrapper");
905
+ return el;
906
+ },
907
+ { side: -1 }
908
+ ),
909
+ import_view3.Decoration.widget(
910
+ 0,
911
+ () => {
912
+ const pageNumber = 1;
913
+ let _headerOptions = commonHeaderOptions;
914
+ if (pageNumber in pageOptions.customHeader) {
915
+ _headerOptions = pageOptions.customHeader[pageNumber];
916
+ }
917
+ const el = getHeader(
918
+ _headerOptions.headerRight,
919
+ _headerOptions.headerLeft,
920
+ headerClickEvent(pageNumber, pageOptions.onHeaderClick)
921
+ );
922
+ el.classList.add("rm-first-page-header");
923
+ return el;
924
+ },
925
+ { side: -1 }
926
+ )
927
+ ];
928
+ }
929
+ var PAGE_SIZES = {
930
+ A4: getPageSize(1123, 794, 95, 95, 76, 76),
931
+ A3: getPageSize(1591, 1123, 95, 95, 76, 76),
932
+ A5: getPageSize(794, 419, 76, 76, 57, 57),
933
+ LETTER: getPageSize(1060, 818, 96, 96, 96, 96),
934
+ LEGAL: getPageSize(1404, 818, 96, 96, 96, 96),
935
+ TABLOID: getPageSize(1635, 1060, 96, 96, 96, 96)
936
+ };
749
937
  var PaginationPlus = import_core4.Extension.create({
750
938
  name: "PaginationPlus",
751
939
  addOptions() {
752
940
  return defaultOptions;
753
941
  },
754
942
  addStorage() {
755
- return Object.assign(Object.assign({}, defaultOptions), { headerHeight: /* @__PURE__ */ new Map(), footerHeight: /* @__PURE__ */ new Map(), appliedConfig: defaultPageConfig });
943
+ return {
944
+ ...defaultOptions,
945
+ headerHeight: /* @__PURE__ */ new Map(),
946
+ footerHeight: /* @__PURE__ */ new Map(),
947
+ appliedConfig: defaultPageConfig
948
+ };
756
949
  },
757
950
  onCreate() {
758
951
  const { options: _currentOptions } = getPageConfig(this.storage, this.options);
@@ -760,210 +953,180 @@ var PaginationPlus = import_core4.Extension.create({
760
953
  const targetNode = this.editor.view.dom;
761
954
  targetNode.classList.add("rm-with-pagination");
762
955
  targetNode.style.border = `1px solid var(--rm-page-gap-border-color)`;
763
- targetNode.style.paddingLeft = `var(--rm-margin-left)`;
764
- targetNode.style.paddingRight = `var(--rm-margin-right)`;
765
- targetNode.style.width = `var(--rm-page-width)`;
766
- updateCssVariables(targetNode, Object.assign(Object.assign({}, _currentOptions), pageConfig));
767
- const style = document.createElement("style");
768
- style.dataset.rmPaginationStyle = "";
769
- style.textContent = `
770
- .rm-pagination-gap{
771
- border-top: 1px solid;
772
- border-bottom: 1px solid;
773
- border-color: var(--rm-page-gap-border-color);
774
- }
775
- .rm-with-pagination,
776
- .rm-with-pagination .rm-first-page-header {
777
- counter-reset: page-number page-number-plus 1;
778
- }
779
- .rm-with-pagination .image-plus-wrapper,
780
- .rm-with-pagination .table-plus td,
781
- .rm-with-pagination .table-plus th {
782
- max-height: var(--rm-max-content-child-height);
783
- overflow-y: auto;
784
- }
785
- .rm-with-pagination .image-plus-wrapper {
786
- overflow-y: visible;
787
- }
788
- .rm-with-pagination .rm-page-break {
789
- counter-increment: page-number page-number-plus;
790
- }
791
-
792
- .rm-with-pagination .rm-page-break:last-child .rm-pagination-gap {
793
- display: none;
794
- }
795
- .rm-with-pagination .rm-page-break:last-child .rm-page-header {
796
- display: none;
797
- }
798
-
799
- .rm-with-pagination table tr td,
800
- .rm-with-pagination table tr th {
801
- word-break: break-all;
802
- }
803
- .rm-with-pagination table > tr {
804
- display: grid;
805
- min-width: 100%;
806
- }
807
- .rm-with-pagination table {
808
- border-collapse: collapse;
809
- width: 100%;
810
- display: contents;
811
- }
812
- .rm-with-pagination table tbody > tr{
813
- display: table-row !important;
814
- }
815
- .rm-with-pagination *:has(>br.ProseMirror-trailingBreak:only-child) {
816
- display: table;
817
- width: 100%;
818
- }
819
- .rm-with-pagination .rm-br-decoration {
820
- display: table;
821
- width: 100%;
822
- }
823
- .rm-with-pagination .table-row-group {
824
- max-height: var(--rm-max-content-child-height);
825
- overflow-y: auto;
826
- width: 100%;
827
- }
828
- .rm-with-pagination .rm-page-footer-left,
829
- .rm-with-pagination .rm-page-footer-right,
830
- .rm-with-pagination .rm-page-header-left,
831
- .rm-with-pagination .rm-page-header-right {
832
- display: inline-block;
833
- }
834
-
835
- .rm-with-pagination .rm-page-header-left,
836
- .rm-with-pagination .rm-page-footer-left{
837
- float: left;
838
- margin-left: var(--rm-margin-left);
839
- }
840
- .rm-with-pagination .rm-page-header-right,
841
- .rm-with-pagination .rm-page-footer-right{
842
- float: right;
843
- margin-right: var(--rm-margin-right);
844
- }
845
- .rm-with-pagination .rm-first-page-header .rm-page-header-right{
846
- margin-right: 0px !important;
847
- }
848
- .rm-with-pagination .rm-first-page-header .rm-page-header-left{
849
- margin-left: 0px !important;
850
- }
851
- .rm-with-pagination .rm-page-number::before {
852
- content: counter(page-number);
853
- }
854
- .rm-with-pagination .rm-page-number-plus::before {
855
- content: counter(page-number-plus);
856
- }
857
- .rm-with-pagination .rm-page-header,
858
- .rm-with-pagination .rm-page-footer{
859
- width: 100%;
860
- }
861
- .rm-with-pagination .rm-page-header{
862
- padding-bottom: var(--rm-content-margin-top) !important;
863
- padding-top: var(--rm-margin-top) !important;
864
- display: inline-flex;
865
- justify-content: space-between;
866
- max-height: calc(calc(var(--rm-page-height) * 0.45) - var(--rm-margin-top) - var(--rm-content-margin-top));
867
- overflow-y: hidden;
868
- }
869
- .rm-with-pagination .rm-page-footer{
870
- padding-top: var(--rm-content-margin-bottom) !important;
871
- padding-bottom: var(--rm-margin-bottom) !important;
872
- display: inline-flex;
873
- justify-content: space-between;
874
- max-height: calc(calc(var(--rm-page-height) * 0.45) - var(--rm-content-margin-bottom) - var(--rm-margin-bottom));
875
- overflow-y: hidden;
876
- }
877
- .rm-with-pagination[rm-pagination-disabled] {
878
- padding-top: var(--rm-margin-top) !important;
879
- padding-bottom: var(--rm-margin-bottom) !important;
880
- }
881
- `;
882
- document.head.appendChild(style);
956
+ targetNode.style.paddingLeft = "var(--rm-margin-left)";
957
+ targetNode.style.paddingRight = "var(--rm-margin-right)";
958
+ targetNode.style.width = "var(--rm-page-width)";
959
+ updateCssVariables(targetNode, { ..._currentOptions, ...pageConfig });
960
+ if (!document.querySelector("style[data-rm-pagination-style]")) {
961
+ const style = document.createElement("style");
962
+ style.dataset.rmPaginationStyle = "";
963
+ style.textContent = `
964
+ .rm-pagination-gap{
965
+ border-top: 1px solid;
966
+ border-bottom: 1px solid;
967
+ border-color: var(--rm-page-gap-border-color);
968
+ }
969
+ .rm-with-pagination,
970
+ .rm-with-pagination .rm-first-page-header {
971
+ counter-reset: page-number page-number-plus 1;
972
+ }
973
+ .rm-with-pagination .image-plus-wrapper,
974
+ .rm-with-pagination .table-plus td,
975
+ .rm-with-pagination .table-plus th {
976
+ max-height: var(--rm-max-content-child-height);
977
+ overflow-y: auto;
978
+ }
979
+ .rm-with-pagination .image-plus-wrapper {
980
+ overflow-y: visible;
981
+ }
982
+ .rm-with-pagination .rm-page-break {
983
+ counter-increment: page-number page-number-plus;
984
+ }
985
+ .rm-with-pagination .rm-page-break:last-child .rm-pagination-gap {
986
+ display: none;
987
+ }
988
+ .rm-with-pagination .rm-page-break:last-child .rm-page-header {
989
+ display: none;
990
+ }
991
+ .rm-with-pagination table tr td,
992
+ .rm-with-pagination table tr th {
993
+ word-break: break-all;
994
+ }
995
+ .rm-with-pagination table > tr {
996
+ display: grid;
997
+ min-width: 100%;
998
+ }
999
+ .rm-with-pagination table {
1000
+ border-collapse: collapse;
1001
+ width: 100%;
1002
+ display: contents;
1003
+ }
1004
+ .rm-with-pagination table tbody > tr{
1005
+ display: table-row !important;
1006
+ }
1007
+ .rm-with-pagination *:has(>br.ProseMirror-trailingBreak:only-child) {
1008
+ display: table;
1009
+ width: 100%;
1010
+ }
1011
+ .rm-with-pagination .rm-br-decoration {
1012
+ display: table;
1013
+ width: 100%;
1014
+ }
1015
+ .rm-with-pagination .table-row-group {
1016
+ max-height: var(--rm-max-content-child-height);
1017
+ overflow-y: auto;
1018
+ width: 100%;
1019
+ }
1020
+ .rm-with-pagination .rm-page-footer-left,
1021
+ .rm-with-pagination .rm-page-footer-right,
1022
+ .rm-with-pagination .rm-page-header-left,
1023
+ .rm-with-pagination .rm-page-header-right {
1024
+ display: inline-block;
1025
+ }
1026
+ .rm-with-pagination .rm-page-header-left,
1027
+ .rm-with-pagination .rm-page-footer-left{
1028
+ float: left;
1029
+ margin-left: var(--rm-margin-left);
1030
+ }
1031
+ .rm-with-pagination .rm-page-header-right,
1032
+ .rm-with-pagination .rm-page-footer-right{
1033
+ float: right;
1034
+ margin-right: var(--rm-margin-right);
1035
+ }
1036
+ .rm-with-pagination .rm-first-page-header .rm-page-header-right{
1037
+ margin-right: 0px !important;
1038
+ }
1039
+ .rm-with-pagination .rm-first-page-header .rm-page-header-left{
1040
+ margin-left: 0px !important;
1041
+ }
1042
+ .rm-with-pagination .rm-page-number::before {
1043
+ content: counter(page-number);
1044
+ }
1045
+ .rm-with-pagination .rm-page-number-plus::before {
1046
+ content: counter(page-number-plus);
1047
+ }
1048
+ .rm-with-pagination .rm-page-header,
1049
+ .rm-with-pagination .rm-page-footer{
1050
+ width: 100%;
1051
+ }
1052
+ .rm-with-pagination .rm-page-header{
1053
+ padding-bottom: var(--rm-content-margin-top) !important;
1054
+ padding-top: var(--rm-margin-top) !important;
1055
+ display: inline-flex;
1056
+ justify-content: space-between;
1057
+ max-height: calc(calc(var(--rm-page-height) * 0.45) - var(--rm-margin-top) - var(--rm-content-margin-top));
1058
+ overflow-y: hidden;
1059
+ }
1060
+ .rm-with-pagination .rm-page-footer{
1061
+ padding-top: var(--rm-content-margin-bottom) !important;
1062
+ padding-bottom: var(--rm-margin-bottom) !important;
1063
+ display: inline-flex;
1064
+ justify-content: space-between;
1065
+ max-height: calc(calc(var(--rm-page-height) * 0.45) - var(--rm-content-margin-bottom) - var(--rm-margin-bottom));
1066
+ overflow-y: hidden;
1067
+ }
1068
+ .rm-with-pagination[rm-pagination-disabled] {
1069
+ padding-top: var(--rm-margin-top) !important;
1070
+ padding-bottom: var(--rm-margin-bottom) !important;
1071
+ }
1072
+ `;
1073
+ document.head.appendChild(style);
1074
+ }
883
1075
  refreshPage(targetNode, _currentOptions.enabled);
884
1076
  },
885
1077
  addProseMirrorPlugins() {
886
- const editor = this.editor;
887
1078
  const storage = this.storage;
1079
+ const options = this.options;
888
1080
  return [
889
1081
  new import_state3.Plugin({
890
1082
  key: paginationKey,
891
1083
  state: {
892
- init: (_, state) => {
893
- const _currentOptions = getPageConfigFromOptions(this.options);
894
- const pageConfig = getPageConfigFromOptions(this.options);
895
- const widgetList = createDecoration(Object.assign(Object.assign({}, this.options), _currentOptions), /* @__PURE__ */ new Map(), /* @__PURE__ */ new Map());
896
- storage.pageBreakBackground = _currentOptions.pageBreakBackground;
897
- storage.pageHeight = _currentOptions.pageHeight;
898
- storage.pageWidth = _currentOptions.pageWidth;
899
- storage.marginTop = _currentOptions.marginTop;
900
- storage.marginBottom = _currentOptions.marginBottom;
901
- storage.marginLeft = _currentOptions.marginLeft;
902
- storage.marginRight = _currentOptions.marginRight;
903
- storage.pageGap = _currentOptions.pageGap;
904
- storage.contentMarginTop = _currentOptions.contentMarginTop;
905
- storage.contentMarginBottom = _currentOptions.contentMarginBottom;
906
- storage.footerRight = _currentOptions.footerRight;
907
- storage.footerLeft = _currentOptions.footerLeft;
908
- storage.headerRight = _currentOptions.headerRight;
909
- storage.headerLeft = _currentOptions.headerLeft;
910
- storage.customHeader = _currentOptions.customHeader;
911
- storage.customFooter = _currentOptions.customFooter;
912
- storage.headerHeight = /* @__PURE__ */ new Map();
913
- storage.footerHeight = /* @__PURE__ */ new Map();
914
- storage.appliedConfig = pageConfig;
915
- return {
916
- decorations: import_view3.DecorationSet.create(state.doc, widgetList)
917
- };
918
- },
919
- apply: (tr, oldDeco, oldState, newState) => {
920
- const { options: _currentOptions, config: pageConfig } = getPageConfig(storage, this.options);
921
- if (storage.enabled === storage.appliedConfig.enabled && storage.enabled === false && storage.appliedConfig.enabled === false) {
922
- return oldDeco;
1084
+ init: () => import_view3.DecorationSet.empty,
1085
+ apply: (tr, old) => {
1086
+ const { options: _currentOptions, config: pageConfig } = getPageConfig(storage, options);
1087
+ if (!pageConfig.enabled) {
1088
+ return import_view3.DecorationSet.empty;
923
1089
  }
924
- const pageCount = getNewPageCount(editor.view, Object.assign(Object.assign({}, _currentOptions), pageConfig));
925
- const currentPageCount = getExistingPageCount(editor.view);
926
- const getNewDecoration = () => {
927
- const { options: _currentOptions2, config: pageConfig2 } = getPageConfig(storage, this.options);
928
- updateCssVariables(editor.view.dom, _currentOptions2);
929
- let headerHeight = "headerHeight" in this.storage ? this.storage.headerHeight : /* @__PURE__ */ new Map();
930
- let footerHeight = "footerHeight" in this.storage ? this.storage.footerHeight : /* @__PURE__ */ new Map();
931
- const widgetList = createDecoration(Object.assign(Object.assign({}, _currentOptions2), pageConfig2), headerHeight, footerHeight);
932
- storage.appliedConfig = pageConfig2;
933
- storage.headerHeight = headerHeight;
934
- storage.footerHeight = footerHeight;
935
- return {
936
- decorations: import_view3.DecorationSet.create(newState.doc, [...widgetList]),
937
- footerHeight
938
- };
939
- };
940
- if (
941
- // If pagination is enabled only then check for other changes
942
- (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)
943
- ) {
944
- return getNewDecoration();
1090
+ const footerHeight = storage.footerHeight;
1091
+ const headerHeight = storage.headerHeight;
1092
+ const isPageCountChanged = tr.getMeta(page_count_meta_key);
1093
+ if (isPageCountChanged || tr.docChanged) {
1094
+ return import_view3.DecorationSet.create(
1095
+ tr.doc,
1096
+ createDecoration(
1097
+ { ..._currentOptions, ...pageConfig },
1098
+ headerHeight ?? /* @__PURE__ */ new Map(),
1099
+ footerHeight ?? /* @__PURE__ */ new Map()
1100
+ )
1101
+ );
945
1102
  }
946
- return oldDeco;
1103
+ return old;
947
1104
  }
948
1105
  },
949
1106
  props: {
950
1107
  decorations(state) {
951
- var _a;
952
- return (_a = this.getState(state)) === null || _a === void 0 ? void 0 : _a.decorations;
1108
+ return paginationKey.getState(state) ?? import_view3.DecorationSet.empty;
953
1109
  }
954
1110
  },
955
- view: (editorView) => {
1111
+ view: () => {
956
1112
  return {
957
1113
  update: (view) => {
958
- const { options: _currentOptions, config: pageConfig } = getPageConfig(storage, this.options);
1114
+ const { options: _currentOptions, config: pageConfig } = getPageConfig(storage, options);
959
1115
  if (!pageConfig.enabled && !view.dom.hasAttribute("rm-pagination-disabled")) {
960
1116
  refreshPage(view.dom, false);
961
1117
  return;
962
1118
  }
963
- const pageCount = getNewPageCount(view, Object.assign(Object.assign({}, _currentOptions), pageConfig));
1119
+ const pageCount = getNewPageCount(view, { ..._currentOptions, ...pageConfig });
964
1120
  const currentPageCount = getExistingPageCount(view);
965
1121
  const triggerUpdate = (_footerHeight) => {
966
1122
  requestAnimationFrame(() => {
1123
+ const history = pageGapTracker.get(view.dom);
1124
+ if (history && history.flapping && history.flapping.includes(pageCount)) {
1125
+ return;
1126
+ }
1127
+ if (history && history.recent) {
1128
+ history.recent.push(pageCount);
1129
+ }
967
1130
  const tr = view.state.tr.setMeta(page_count_meta_key, { footerHeight: _footerHeight });
968
1131
  view.dispatch(tr);
969
1132
  });
@@ -987,7 +1150,7 @@ var PaginationPlus = import_core4.Extension.create({
987
1150
  }
988
1151
  }
989
1152
  const pagesSetToCheck = /* @__PURE__ */ new Set([1, ...footerHeightForCurrentPages.keys(), ...headerHeightForCurrentPages.keys()]);
990
- let missingPageNumber = void 0;
1153
+ let missingPageNumber;
991
1154
  for (let i = 1; i <= pageCount; i++) {
992
1155
  if (!pagesSetToCheck.has(i)) {
993
1156
  missingPageNumber = i;
@@ -998,18 +1161,18 @@ var PaginationPlus = import_core4.Extension.create({
998
1161
  pagesSetToCheck.add(missingPageNumber);
999
1162
  }
1000
1163
  pagesSetToCheck.delete(0);
1001
- let pageContentHeightVariable = {};
1002
- let maxContentHeight = void 0;
1164
+ const pageContentHeightVariable = {};
1165
+ let maxContentHeight;
1003
1166
  for (const page of pagesSetToCheck) {
1004
- const headerHeight2 = headerHeightForCurrentPages.has(page) ? headerHeightForCurrentPages.get(page) || 0 : headerHeightForCurrentPages.get(0) || 0;
1005
- const footerHeight2 = footerHeightForCurrentPages.has(page) ? footerHeightForCurrentPages.get(page) || 0 : footerHeightForCurrentPages.get(0) || 0;
1006
- const { _pageHeaderHeight, _pageHeight } = getHeight(_currentOptions, headerHeight2, footerHeight2);
1167
+ const hHeight = headerHeightForCurrentPages.has(page) ? headerHeightForCurrentPages.get(page) || 0 : headerHeightForCurrentPages.get(0) || 0;
1168
+ const fHeight = footerHeightForCurrentPages.has(page) ? footerHeightForCurrentPages.get(page) || 0 : footerHeightForCurrentPages.get(0) || 0;
1169
+ const { _pageHeaderHeight, _pageHeight } = getHeight(_currentOptions, hHeight, fHeight);
1007
1170
  const contentHeight = page === 1 ? _pageHeight + _pageHeaderHeight : _pageHeight;
1008
1171
  if (page === 1) {
1009
- pageContentHeightVariable[`rm-page-content-first`] = `${contentHeight}px`;
1172
+ pageContentHeightVariable["rm-page-content-first"] = `${contentHeight}px`;
1010
1173
  }
1011
1174
  if (page === missingPageNumber) {
1012
- pageContentHeightVariable[`rm-page-content-general`] = `${contentHeight}px`;
1175
+ pageContentHeightVariable["rm-page-content-general"] = `${contentHeight}px`;
1013
1176
  } else {
1014
1177
  pageContentHeightVariable[`rm-page-content-${page}`] = `${contentHeight}px`;
1015
1178
  }
@@ -1018,13 +1181,14 @@ var PaginationPlus = import_core4.Extension.create({
1018
1181
  }
1019
1182
  }
1020
1183
  if (maxContentHeight) {
1021
- view.dom.style.setProperty(`--rm-max-content-child-height`, `${maxContentHeight - 10}px`);
1184
+ ;
1185
+ view.dom.style.setProperty("--rm-max-content-child-height", `${maxContentHeight - 10}px`);
1022
1186
  }
1023
- Object.entries(pageContentHeightVariable).forEach(([key2, value]) => {
1024
- view.dom.style.setProperty(`--${key2}`, value);
1187
+ Object.entries(pageContentHeightVariable).forEach(([k, value]) => {
1188
+ ;
1189
+ view.dom.style.setProperty(`--${k}`, value);
1025
1190
  });
1026
1191
  refreshPage(view.dom, _currentOptions.enabled);
1027
- return;
1028
1192
  }
1029
1193
  };
1030
1194
  }
@@ -1036,7 +1200,9 @@ var PaginationPlus = import_core4.Extension.create({
1036
1200
  return buildDecorations(state.doc);
1037
1201
  },
1038
1202
  apply(tr, old) {
1039
- 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)) {
1203
+ if (tr.docChanged || tr.steps.some(
1204
+ (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
1205
+ )) {
1040
1206
  return buildDecorations(tr.doc);
1041
1207
  }
1042
1208
  return old;
@@ -1044,8 +1210,7 @@ var PaginationPlus = import_core4.Extension.create({
1044
1210
  },
1045
1211
  props: {
1046
1212
  decorations(state) {
1047
- var _a;
1048
- return (_a = key.getState(state)) !== null && _a !== void 0 ? _a : import_view3.DecorationSet.empty;
1213
+ return key.getState(state) ?? import_view3.DecorationSet.empty;
1049
1214
  }
1050
1215
  }
1051
1216
  })
@@ -1085,31 +1250,14 @@ var PaginationPlus = import_core4.Extension.create({
1085
1250
  this.storage.marginRight = margins.right;
1086
1251
  return true;
1087
1252
  },
1088
- updateContentMargins: (margins) => () => {
1089
- this.storage.contentMarginTop = margins.top;
1090
- this.storage.contentMarginBottom = margins.bottom;
1091
- return true;
1092
- },
1093
- updateHeaderContent: (left, right, pageNumber) => () => {
1094
- if (pageNumber) {
1095
- this.storage.customHeader = Object.assign(Object.assign({}, this.storage.customHeader), { [pageNumber]: { headerLeft: left, headerRight: right } });
1096
- } else {
1097
- this.storage.headerLeft = left;
1098
- this.storage.headerRight = right;
1099
- }
1253
+ updateHeaderContent: (left, right) => () => {
1254
+ if (left !== void 0) this.storage.headerLeft = left;
1255
+ if (right !== void 0) this.storage.headerRight = right;
1100
1256
  return true;
1101
1257
  },
1102
- updateFooterContent: (left, right, pageNumber) => () => {
1103
- if (pageNumber) {
1104
- this.storage.customFooter = Object.assign(Object.assign({}, this.storage.customFooter), { [pageNumber]: { footerLeft: left, footerRight: right } });
1105
- } else {
1106
- this.storage.footerLeft = left;
1107
- this.storage.footerRight = right;
1108
- }
1109
- return true;
1110
- },
1111
- togglePagination: () => () => {
1112
- this.storage.enabled = !this.storage.enabled;
1258
+ updateFooterContent: (left, right) => () => {
1259
+ if (left !== void 0) this.storage.footerLeft = left;
1260
+ if (right !== void 0) this.storage.footerRight = right;
1113
1261
  return true;
1114
1262
  },
1115
1263
  enablePagination: () => () => {
@@ -1123,203 +1271,6 @@ var PaginationPlus = import_core4.Extension.create({
1123
1271
  };
1124
1272
  }
1125
1273
  });
1126
- var getExistingPageCount = (view) => {
1127
- const editorDom = view.dom;
1128
- const paginationElement = editorDom.querySelector("[data-rm-pagination]");
1129
- if (paginationElement) {
1130
- return paginationElement.children.length;
1131
- }
1132
- return 0;
1133
- };
1134
- var pageGapTracker = /* @__PURE__ */ new WeakMap();
1135
- var calculatePageCount = (view, pageOptions, headerHeight = 0, footerHeight = 0) => {
1136
- var _a;
1137
- const editorDom = view.dom;
1138
- const _pageHeaderHeight = pageOptions.contentMarginTop + pageOptions.marginTop + headerHeight;
1139
- const _pageFooterHeight = pageOptions.contentMarginBottom + pageOptions.marginBottom + footerHeight;
1140
- const pageContentAreaHeight = pageOptions.pageHeight - _pageHeaderHeight - _pageFooterHeight;
1141
- const paginationElement = editorDom.querySelector("[data-rm-pagination]");
1142
- const currentPageCount = getExistingPageCount(view);
1143
- if (paginationElement) {
1144
- const lastElementOfEditor = editorDom.lastElementChild;
1145
- const lastPageBreak = (_a = paginationElement.lastElementChild) === null || _a === void 0 ? void 0 : _a.querySelector(".breaker");
1146
- if (lastElementOfEditor && lastPageBreak) {
1147
- const lastElementRect = lastElementOfEditor.getBoundingClientRect();
1148
- const lastPageBreakRect = lastPageBreak.getBoundingClientRect();
1149
- const lastPageGap = lastElementRect.bottom - lastPageBreakRect.bottom;
1150
- if (lastPageGap > 0) {
1151
- const addPage = Math.ceil(lastPageGap / pageContentAreaHeight);
1152
- if (lastElementRect.height > pageContentAreaHeight) {
1153
- const isSplittableTable = (lastElementOfEditor === null || lastElementOfEditor === void 0 ? void 0 : lastElementOfEditor.tagName) === "TABLE" && lastElementOfEditor.hasAttribute("data-tps-splittable");
1154
- if (!isSplittableTable) {
1155
- return currentPageCount;
1156
- }
1157
- }
1158
- const prev = pageGapTracker.get(editorDom);
1159
- if (prev && prev.pages < currentPageCount && lastPageGap > prev.gap - 2) {
1160
- return currentPageCount;
1161
- }
1162
- pageGapTracker.set(editorDom, { gap: lastPageGap, pages: currentPageCount });
1163
- let totalEditorContentHeight = 0;
1164
- for (const child of editorDom.children) {
1165
- if (!(child instanceof HTMLElement)) continue;
1166
- if (child.hasAttribute("data-rm-pagination")) continue;
1167
- if (child.classList.contains("rm-page-break")) continue;
1168
- totalEditorContentHeight += child.getBoundingClientRect().height;
1169
- }
1170
- const maxPagesByContent = Math.ceil(totalEditorContentHeight / pageContentAreaHeight);
1171
- const contentCap = Math.max(currentPageCount, maxPagesByContent + 1);
1172
- if (currentPageCount + addPage > contentCap) {
1173
- return contentCap;
1174
- }
1175
- const MAX_PAGES = 1e3;
1176
- if (currentPageCount + addPage > MAX_PAGES) {
1177
- return currentPageCount;
1178
- }
1179
- return currentPageCount + addPage;
1180
- } else {
1181
- pageGapTracker.delete(editorDom);
1182
- const allBreaksAfterLastElement = Array.from(paginationElement.querySelectorAll(".breaker"));
1183
- const allBreaksAfterLastElementRect = allBreaksAfterLastElement.filter((element) => element.getBoundingClientRect().top > lastElementRect.bottom);
1184
- const removePage = allBreaksAfterLastElementRect.length;
1185
- if (removePage > 1) {
1186
- return currentPageCount - removePage;
1187
- } else {
1188
- return currentPageCount;
1189
- }
1190
- }
1191
- }
1192
- return 1;
1193
- } else {
1194
- const editorHeight = editorDom.scrollHeight;
1195
- let pageCount = Math.ceil(editorHeight / pageContentAreaHeight);
1196
- pageCount = pageCount <= 0 ? 1 : pageCount;
1197
- return pageCount;
1198
- }
1199
- };
1200
- var getNewPageCount = (view, pageOptions) => {
1201
- if (pageOptions.enabled) {
1202
- const pageCount = calculatePageCount(view, pageOptions);
1203
- return pageCount <= 1 ? 1 : pageCount;
1204
- } else {
1205
- return 0;
1206
- }
1207
- };
1208
- function createDecoration(pageOptions, headerHeightMap, footerHeightMap) {
1209
- if (!pageOptions.enabled) {
1210
- return [];
1211
- }
1212
- const commonHeaderOptions = { headerLeft: pageOptions.headerLeft, headerRight: pageOptions.headerRight };
1213
- const commonFooterOptions = { footerLeft: pageOptions.footerLeft, footerRight: pageOptions.footerRight };
1214
- const pageWidget = import_view3.Decoration.widget(0, (view) => {
1215
- const _pageGap = pageOptions.pageGap;
1216
- const _pageBreakBackground = pageOptions.pageBreakBackground;
1217
- const el = document.createElement("div");
1218
- el.dataset.rmPagination = "true";
1219
- const pageBreakDefinition = (firstPage, pageHeader, pageFooter, headerHeight, footerHeight, pageNumber) => {
1220
- const { _pageHeaderHeight, _pageHeight } = getHeight(pageOptions, headerHeight, footerHeight);
1221
- const pageContainer = document.createElement("div");
1222
- pageContainer.classList.add("rm-page-break");
1223
- const page = document.createElement("div");
1224
- page.classList.add("page");
1225
- page.style.position = "relative";
1226
- page.style.float = "left";
1227
- page.style.clear = "both";
1228
- const marginTop = firstPage ? `calc(${_pageHeaderHeight}px + ${_pageHeight}px)` : _pageHeight + "px";
1229
- if (pageNumber) {
1230
- page.style.marginTop = `var(--rm-page-content-${pageNumber}, ${marginTop})`;
1231
- } else {
1232
- page.style.marginTop = firstPage ? `var(--rm-page-content-first, ${marginTop})` : `var(--rm-page-content-general, ${marginTop})`;
1233
- }
1234
- const pageBreak = document.createElement("div");
1235
- pageBreak.classList.add("breaker");
1236
- pageBreak.style.width = `calc(100% + var(--rm-margin-left) + var(--rm-margin-right))`;
1237
- pageBreak.style.marginLeft = `calc(-1 * var(--rm-margin-left))`;
1238
- pageBreak.style.marginRight = `calc(-1 * var(--rm-margin-right))`;
1239
- pageBreak.style.position = "relative";
1240
- pageBreak.style.float = "left";
1241
- pageBreak.style.clear = "both";
1242
- pageBreak.style.left = `0px`;
1243
- pageBreak.style.right = `0px`;
1244
- pageBreak.style.zIndex = "2";
1245
- const pageSpace = document.createElement("div");
1246
- pageSpace.classList.add("rm-pagination-gap");
1247
- pageSpace.style.height = _pageGap + "px";
1248
- pageSpace.style.borderLeft = "1px solid";
1249
- pageSpace.style.borderRight = "1px solid";
1250
- pageSpace.style.position = "relative";
1251
- pageSpace.style.setProperty("width", "calc(100% + 2px)", "important");
1252
- pageSpace.style.left = "-1px";
1253
- pageSpace.style.backgroundColor = _pageBreakBackground;
1254
- pageSpace.style.borderLeftColor = _pageBreakBackground;
1255
- pageSpace.style.borderRightColor = _pageBreakBackground;
1256
- pageBreak.append(pageFooter, pageSpace, pageHeader);
1257
- pageContainer.append(page, pageBreak);
1258
- return pageContainer;
1259
- };
1260
- const _headerHeight = headerHeightMap.get(0) || 0;
1261
- const _footerHeight = footerHeightMap.get(0) || 0;
1262
- const fragment = document.createDocumentFragment();
1263
- const pageCount = getNewPageCount(view, pageOptions);
1264
- for (let i = 0; i < pageCount; i++) {
1265
- const pageNumber = i + 1;
1266
- const headerPageNumber = i + 2;
1267
- if (headerPageNumber in pageOptions.customHeader || pageNumber in pageOptions.customFooter || pageNumber in pageOptions.customHeader) {
1268
- let _headerOptions = commonHeaderOptions;
1269
- let _footerOptions = commonFooterOptions;
1270
- let _pageHeaderHeight = _headerHeight;
1271
- let _pageFooterHeight = _footerHeight;
1272
- if (headerPageNumber in pageOptions.customHeader) {
1273
- _headerOptions = pageOptions.customHeader[headerPageNumber] || commonHeaderOptions;
1274
- _pageHeaderHeight = headerHeightMap.get(headerPageNumber) || 0;
1275
- }
1276
- if (pageNumber in pageOptions.customFooter) {
1277
- _footerOptions = pageOptions.customFooter[pageNumber] || commonFooterOptions;
1278
- _pageFooterHeight = footerHeightMap.get(pageNumber) || 0;
1279
- }
1280
- let _pageHeader = getHeader(_headerOptions.headerRight, _headerOptions.headerLeft, headerClickEvent(headerPageNumber, pageOptions.onHeaderClick), headerPageNumber);
1281
- let _pageFooter = getFooter(_footerOptions.footerRight, _footerOptions.footerLeft, footerClickEvent(pageNumber, pageOptions.onFooterClick), pageNumber);
1282
- let pageBreak = pageBreakDefinition(i === 0, _pageHeader, _pageFooter, _pageHeaderHeight, _pageFooterHeight, pageNumber);
1283
- fragment.appendChild(pageBreak);
1284
- } else {
1285
- const __pageHeader = getHeader(commonHeaderOptions.headerRight, commonHeaderOptions.headerLeft, headerClickEvent(headerPageNumber, pageOptions.onHeaderClick));
1286
- const __pageFooter = getFooter(commonFooterOptions.footerRight, commonFooterOptions.footerLeft, footerClickEvent(pageNumber, pageOptions.onFooterClick));
1287
- fragment.appendChild(pageBreakDefinition(i === 0, __pageHeader, __pageFooter, _headerHeight, _footerHeight));
1288
- }
1289
- }
1290
- el.append(fragment);
1291
- el.id = "pages";
1292
- el.classList.add("rm-pages-wrapper");
1293
- return el;
1294
- }, { side: -1 });
1295
- const firstHeaderWidget = import_view3.Decoration.widget(0, () => {
1296
- const pageNumber = 1;
1297
- let _headerOptions = commonHeaderOptions;
1298
- if (pageNumber in pageOptions.customHeader) {
1299
- _headerOptions = pageOptions.customHeader[pageNumber];
1300
- }
1301
- const el = getHeader(_headerOptions.headerRight, _headerOptions.headerLeft, headerClickEvent(pageNumber, pageOptions.onHeaderClick));
1302
- el.classList.add("rm-first-page-header");
1303
- return el;
1304
- }, { side: -1 });
1305
- return [pageWidget, firstHeaderWidget];
1306
- }
1307
-
1308
- // ../../node_modules/.pnpm/tiptap-pagination-plus@3.1.0_patch_hash=4857789ba5672a185fb96bdd854e03e0c6ec8ed26abfeea_16730b2b361cd3f71113c52459ed62fd/node_modules/tiptap-pagination-plus/dist/constants.js
1309
- var A4_PAGE_SIZE = getPageSize(1123, 794, 95, 95, 76, 76);
1310
- var A3_PAGE_SIZE = getPageSize(1591, 1123, 95, 95, 76, 76);
1311
- var A5_PAGE_SIZE = getPageSize(794, 419, 76, 76, 57, 57);
1312
- var LETTER_PAGE_SIZE = getPageSize(1060, 818, 96, 96, 96, 96);
1313
- var LEGAL_PAGE_SIZE = getPageSize(1404, 818, 96, 96, 96, 96);
1314
- var TABLOID_PAGE_SIZE = getPageSize(1635, 1060, 96, 96, 96, 96);
1315
- var PAGE_SIZES = {
1316
- A4: A4_PAGE_SIZE,
1317
- A3: A3_PAGE_SIZE,
1318
- A5: A5_PAGE_SIZE,
1319
- LETTER: LETTER_PAGE_SIZE,
1320
- LEGAL: LEGAL_PAGE_SIZE,
1321
- TABLOID: TABLOID_PAGE_SIZE
1322
- };
1323
1274
 
1324
1275
  // src/PerformanceMonitor.ts
1325
1276
  var TARGET_FRAME_MS = 1e3 / 60;