@kedataindo/docflow-core 0.0.69 → 0.0.71

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