@bitcobblers/wod-wiki-ui 0.5.29 → 0.6.31

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.
@@ -800,11 +800,12 @@ var SectionGeometryPlugin = class {
800
800
  rects = [];
801
801
  docVersion = 0;
802
802
  listeners = /* @__PURE__ */ new Set();
803
+ pendingNotify = null;
803
804
  update(update) {
804
805
  if (update.docChanged) {
805
806
  this.docVersion++;
806
807
  }
807
- if (update.docChanged || update.viewportChanged || update.geometryChanged) {
808
+ if (update.docChanged || update.geometryChanged) {
808
809
  this.measure();
809
810
  }
810
811
  }
@@ -819,18 +820,19 @@ var SectionGeometryPlugin = class {
819
820
  try {
820
821
  const sectionState = this.view.state.field(sectionField, false);
821
822
  const sections = sectionState?.sections ?? [];
822
- const scrollRect = this.view.scrollDOM?.getBoundingClientRect ? this.view.scrollDOM.getBoundingClientRect() : { top: 0, left: 0, bottom: 0, right: 0 };
823
- const scrollTop = this.view.scrollDOM?.scrollTop ?? 0;
823
+ const docLength = this.view.state.doc.length;
824
824
  this.rects = sections.map((sec) => {
825
- let fromCoords = null;
826
- let toCoords = null;
825
+ const from = Math.max(0, Math.min(sec.from, docLength));
826
+ const to = Math.max(0, Math.min(sec.to, docLength));
827
+ let top = 0;
828
+ let bottom = 20;
827
829
  try {
828
- fromCoords = this.view.coordsAtPos ? this.view.coordsAtPos(sec.from) : null;
829
- toCoords = this.view.coordsAtPos ? this.view.coordsAtPos(sec.to) : null;
830
+ const topBlock = this.view.lineBlockAt(from);
831
+ const bottomBlock = this.view.lineBlockAt(to);
832
+ top = topBlock.top;
833
+ bottom = bottomBlock.top + bottomBlock.height;
830
834
  } catch {
831
835
  }
832
- const top = fromCoords ? fromCoords.top - (scrollRect?.top ?? 0) + scrollTop : 0;
833
- const bottom = toCoords ? toCoords.bottom - (scrollRect?.top ?? 0) + scrollTop : top;
834
836
  const height = Math.max(bottom - top, 20);
835
837
  return {
836
838
  sectionId: sec.id,
@@ -846,11 +848,24 @@ var SectionGeometryPlugin = class {
846
848
  }
847
849
  }
848
850
  notify() {
849
- for (const listener of this.listeners) {
850
- listener(this.rects, this.docVersion);
851
+ if (typeof requestAnimationFrame === "function") {
852
+ if (this.pendingNotify !== null) return;
853
+ this.pendingNotify = requestAnimationFrame(() => {
854
+ this.pendingNotify = null;
855
+ for (const listener of this.listeners) {
856
+ listener(this.rects, this.docVersion);
857
+ }
858
+ });
859
+ } else {
860
+ for (const listener of this.listeners) {
861
+ listener(this.rects, this.docVersion);
862
+ }
851
863
  }
852
864
  }
853
865
  destroy() {
866
+ if (this.pendingNotify !== null && typeof cancelAnimationFrame === "function") {
867
+ cancelAnimationFrame(this.pendingNotify);
868
+ }
854
869
  this.listeners.clear();
855
870
  }
856
871
  };