@helping-ai-workflow/md2doc 3.9.0 → 3.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/md2doc.js +38 -8
  2. package/package.json +1 -1
package/lib/md2doc.js CHANGED
@@ -4668,11 +4668,19 @@ ${mermaidInitTag}`)
4668
4668
  var anchorTop = 0;
4669
4669
  var anchorFrame = 0;
4670
4670
  var suppressAnchorCapture = false;
4671
+ // Column width the anchor was last captured/held at; -1 until the column
4672
+ // ResizeObserver below is installed. See captureScrollAnchor's first guard.
4673
+ var lastAnchorColW = -1;
4671
4674
  var lastLayoutWidth = document.documentElement.clientWidth;
4672
4675
  var lastPixelRatio = window.devicePixelRatio;
4673
4676
 
4674
4677
  function captureScrollAnchor() {
4675
4678
  if (suppressAnchorCapture || !contentEl) return;
4679
+ // A column reflow the ResizeObserver has not delivered yet: during a
4680
+ // splitter drag the next pointermove lands before holdScrollAnchor's
4681
+ // trailing capture frame, so capturing now would pin a post-reflow node
4682
+ // and the observer's restore would then find nothing to correct.
4683
+ if (lastAnchorColW >= 0 && contentEl.clientWidth !== lastAnchorColW) return;
4676
4684
  var rect = contentEl.getBoundingClientRect();
4677
4685
  var hit = document.elementFromPoint(rect.left + rect.width / 2, ANCHOR_LINE);
4678
4686
  var node = (hit && hit.closest) ? hit.closest('main.content > *') : null;
@@ -4724,14 +4732,7 @@ ${mermaidInitTag}`)
4724
4732
  });
4725
4733
  }, { passive: true });
4726
4734
 
4727
- window.addEventListener('resize', function () {
4728
- var width = document.documentElement.clientWidth;
4729
- var ratio = window.devicePixelRatio;
4730
- // A height-only change (a mobile browser hiding its toolbar, a devtools
4731
- // dock) reflows nothing, so correcting the scroll would only jerk the page.
4732
- if (width === lastLayoutWidth && ratio === lastPixelRatio) return;
4733
- lastLayoutWidth = width;
4734
- lastPixelRatio = ratio;
4735
+ function holdScrollAnchor() {
4735
4736
  // Hold the anchor across the whole reflow: the scrollTo below fires scroll
4736
4737
  // events that would otherwise re-capture a mid-reflow position.
4737
4738
  suppressAnchorCapture = true;
@@ -4743,8 +4744,37 @@ ${mermaidInitTag}`)
4743
4744
  captureScrollAnchor();
4744
4745
  });
4745
4746
  });
4747
+ }
4748
+
4749
+ window.addEventListener('resize', function () {
4750
+ var width = document.documentElement.clientWidth;
4751
+ var ratio = window.devicePixelRatio;
4752
+ // A height-only change (a mobile browser hiding its toolbar, a devtools
4753
+ // dock) reflows nothing, so correcting the scroll would only jerk the page.
4754
+ if (width === lastLayoutWidth && ratio === lastPixelRatio) return;
4755
+ lastLayoutWidth = width;
4756
+ lastPixelRatio = ratio;
4757
+ holdScrollAnchor();
4746
4758
  });
4747
4759
 
4760
+ // The column also narrows and widens with no window resize at all: a
4761
+ // sidebar-splitter drag, its double-click reset and the TOC collapse toggle
4762
+ // only move --md2doc-sidebar-w / data-toc-collapsed, so the 'resize' listener
4763
+ // above never hears about them and the reflow slid the page by thousands of
4764
+ // px. Watch the column itself. Width only: its height changes whenever an
4765
+ // image or diagram finishes loading, which reflows nothing above the anchor.
4766
+ // The first callback (fired by observe()) sees the starting width and does
4767
+ // nothing, so a load that lands on a #hash is never pulled back.
4768
+ if (contentEl && typeof ResizeObserver === 'function') {
4769
+ lastAnchorColW = contentEl.clientWidth;
4770
+ new ResizeObserver(function () {
4771
+ var w = contentEl.clientWidth;
4772
+ if (w === lastAnchorColW) return;
4773
+ lastAnchorColW = w;
4774
+ holdScrollAnchor();
4775
+ }).observe(contentEl);
4776
+ }
4777
+
4748
4778
  captureScrollAnchor();
4749
4779
 
4750
4780
  // ── drawio sheet bar ─────────────────────────────────────────────────────
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helping-ai-workflow/md2doc",
3
- "version": "3.9.0",
3
+ "version": "3.9.1",
4
4
  "description": "Markdown → HTML / PDF renderer with WaveDrom, Mermaid, Graphviz, and draw.io support",
5
5
  "keywords": [
6
6
  "markdown",