@helping-ai-workflow/md2doc 2.4.2 → 2.5.0

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 (3) hide show
  1. package/README.md +19 -0
  2. package/lib/md2doc.js +322 -0
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -98,6 +98,25 @@ A reference with no file on disk keeps its original `src` and prints
98
98
  Each reference carries its own copy of the payload, so re-using one large diagram
99
99
  in several places grows the HTML accordingly. PDF output is unaffected.
100
100
 
101
+ ### Viewing diagrams
102
+
103
+ Click any image, Mermaid, Graphviz or WaveDrom graphic in the rendered HTML to open it
104
+ full-screen.
105
+
106
+ | Input | Action |
107
+ |---|---|
108
+ | Wheel / shift+wheel | Scroll vertically / horizontally |
109
+ | Ctrl (or ⌘) + wheel | Zoom around the pointer |
110
+ | Drag | Pan |
111
+ | `+` `-` | Zoom in / out |
112
+ | `0` `1` | Fit to window / actual size |
113
+ | Double-click | Toggle fit ↔ 100% |
114
+ | `Esc`, ✕, backdrop click | Close |
115
+
116
+ Vector diagrams open scaled to fill the window; raster images open at actual size. An
117
+ image wrapped in a link stays a link. The overlay is hidden in print and never reaches
118
+ the PDF output.
119
+
101
120
  ### Migration from md2html / md2pdf (v1.x → v2.0.0)
102
121
 
103
122
  | Old | New |
package/lib/md2doc.js CHANGED
@@ -1282,6 +1282,82 @@ const html = `<!DOCTYPE html>
1282
1282
  height: auto;
1283
1283
  margin: 0 auto;
1284
1284
  }
1285
+ /* Anything the reader can pop out. The click handler uses the same
1286
+ selectors, so this cursor and that behaviour cannot drift apart. */
1287
+ .content img,
1288
+ .content .mermaid,
1289
+ .content .graphviz,
1290
+ .content [id^="WaveDrom_Display_"] { cursor: zoom-in; }
1291
+ .content a img { cursor: pointer; }
1292
+
1293
+ .lightbox {
1294
+ position: fixed;
1295
+ inset: 0;
1296
+ z-index: 200;
1297
+ display: flex;
1298
+ flex-direction: column;
1299
+ background: rgba(16, 18, 21, 0.92);
1300
+ }
1301
+ .lightbox[hidden] { display: none; }
1302
+ .lightbox-bar {
1303
+ flex: 0 0 auto;
1304
+ display: flex;
1305
+ align-items: center;
1306
+ justify-content: flex-end;
1307
+ gap: 6px;
1308
+ padding: 8px 12px;
1309
+ background: rgba(0, 0, 0, 0.35);
1310
+ color: #e6edf3;
1311
+ font-size: 13px;
1312
+ }
1313
+ .lightbox-bar button {
1314
+ min-width: 32px;
1315
+ height: 28px;
1316
+ padding: 0 10px;
1317
+ border: 1px solid rgba(255, 255, 255, 0.25);
1318
+ border-radius: 6px;
1319
+ background: rgba(255, 255, 255, 0.08);
1320
+ color: inherit;
1321
+ font: inherit;
1322
+ line-height: 1;
1323
+ cursor: pointer;
1324
+ }
1325
+ .lightbox-bar button:hover { background: rgba(255, 255, 255, 0.18); }
1326
+ .lightbox-zoom-value {
1327
+ min-width: 56px;
1328
+ text-align: center;
1329
+ font-variant-numeric: tabular-nums;
1330
+ }
1331
+ .lightbox-hint {
1332
+ margin-right: auto;
1333
+ opacity: 0.7;
1334
+ font-size: 12px;
1335
+ }
1336
+ /* position: relative makes the stage the canvas's offsetParent, which the
1337
+ cursor-anchored zoom maths depends on. */
1338
+ .lightbox-stage {
1339
+ position: relative;
1340
+ flex: 1 1 auto;
1341
+ overflow: auto;
1342
+ cursor: grab;
1343
+ overscroll-behavior: contain;
1344
+ }
1345
+ .lightbox-stage[data-panning] { cursor: grabbing; }
1346
+ .lightbox-canvas { margin: 0 auto; }
1347
+ /* Sized in px by the runtime; the child follows, so the scroll extent grows
1348
+ with the zoom. A CSS transform would scale the pixels and leave the scroll
1349
+ area at the original size, stranding the edges out of reach. */
1350
+ .lightbox-canvas > * {
1351
+ display: block;
1352
+ width: 100%;
1353
+ height: auto;
1354
+ max-width: none;
1355
+ max-height: none;
1356
+ margin: 0;
1357
+ background: #ffffff;
1358
+ }
1359
+ body[data-lightbox-open] { overflow: hidden; }
1360
+ @media print { .lightbox { display: none !important; } }
1285
1361
  @media (max-width: 1080px) {
1286
1362
  .sidebar-toggle { display: inline-flex; align-items: center; }
1287
1363
  .page-layout {
@@ -1857,6 +1933,7 @@ ${mermaidInitTag}` : ''}
1857
1933
  sidebarScrim.addEventListener('click', () => setSidebarOpen(false));
1858
1934
  }
1859
1935
  document.addEventListener('keydown', (event) => {
1936
+ if (lightboxIsOpen()) return;
1860
1937
  if (event.key === 'Escape' && document.body.hasAttribute('data-sidebar-open')) {
1861
1938
  setSidebarOpen(false);
1862
1939
  }
@@ -1945,6 +2022,251 @@ ${mermaidInitTag}` : ''}
1945
2022
  });
1946
2023
 
1947
2024
  captureScrollAnchor();
2025
+
2026
+ // ── Diagram / image lightbox ──────────────────────────────────────────────
2027
+ // Specs are read at 100% but their block diagrams and waveforms are drawn far
2028
+ // wider than the column, so the inline copy is unreadably small. Clicking one
2029
+ // pops it into a modal stage that zooms and scrolls.
2030
+ var LIGHTBOX_TARGETS = 'img, .mermaid, .graphviz, [id^="WaveDrom_Display_"]';
2031
+ var LIGHTBOX_MIN_ZOOM = 0.05;
2032
+ var LIGHTBOX_MAX_ZOOM = 8;
2033
+ var LIGHTBOX_STEP = 1.25;
2034
+ var lightboxEl = null;
2035
+ var lightboxStage = null;
2036
+ var lightboxCanvas = null;
2037
+ var lightboxZoomValue = null;
2038
+ var lightboxZoom = 1;
2039
+ var lightboxFitZoom = 1;
2040
+ var lightboxNaturalW = 1;
2041
+ var lightboxNaturalH = 1;
2042
+ var lightboxReturnScroll = 0;
2043
+
2044
+ function lightboxIsOpen() {
2045
+ return !!lightboxEl && !lightboxEl.hidden;
2046
+ }
2047
+
2048
+ function lightboxButton(label, title, onClick) {
2049
+ var button = document.createElement('button');
2050
+ button.type = 'button';
2051
+ button.textContent = label;
2052
+ button.title = title;
2053
+ button.setAttribute('aria-label', title);
2054
+ button.addEventListener('click', onClick);
2055
+ return button;
2056
+ }
2057
+
2058
+ function computeLightboxFit(isVector) {
2059
+ var pad = 24;
2060
+ var byWidth = (lightboxStage.clientWidth - pad) / lightboxNaturalW;
2061
+ var byHeight = (lightboxStage.clientHeight - pad) / lightboxNaturalH;
2062
+ var fit = Math.min(byWidth, byHeight);
2063
+ if (!isFinite(fit) || fit <= 0) return 1;
2064
+ // Vector art fills the window — a waveform authored at 480px wide is the
2065
+ // whole reason for popping it out. A raster image stops at actual size,
2066
+ // where enlarging past 100% only buys blur.
2067
+ return isVector ? fit : Math.min(fit, 1);
2068
+ }
2069
+
2070
+ function setLightboxZoom(next, anchorX, anchorY) {
2071
+ if (!lightboxCanvas) return;
2072
+ var clamped = Math.min(LIGHTBOX_MAX_ZOOM, Math.max(LIGHTBOX_MIN_ZOOM, next));
2073
+ var stage = lightboxStage;
2074
+ var ax = (typeof anchorX === 'number') ? anchorX : stage.clientWidth / 2;
2075
+ var ay = (typeof anchorY === 'number') ? anchorY : stage.clientHeight / 2;
2076
+ // Keep whatever sits under the anchor point pinned across the zoom.
2077
+ var contentX = stage.scrollLeft + ax - lightboxCanvas.offsetLeft;
2078
+ var contentY = stage.scrollTop + ay - lightboxCanvas.offsetTop;
2079
+ var ratio = clamped / lightboxZoom;
2080
+ lightboxZoom = clamped;
2081
+ // Width in px, not a transform: the scroll extent has to grow with the
2082
+ // zoom, or the enlarged edges can never be scrolled into view.
2083
+ lightboxCanvas.style.width = Math.max(1, Math.round(lightboxNaturalW * clamped)) + 'px';
2084
+ if (lightboxZoomValue) {
2085
+ lightboxZoomValue.textContent = Math.round(clamped * 100) + '%';
2086
+ }
2087
+ stage.scrollLeft = contentX * ratio - ax + lightboxCanvas.offsetLeft;
2088
+ stage.scrollTop = contentY * ratio - ay + lightboxCanvas.offsetTop;
2089
+ }
2090
+
2091
+ function zoomLightboxBy(factor, anchorX, anchorY) {
2092
+ setLightboxZoom(lightboxZoom * factor, anchorX, anchorY);
2093
+ }
2094
+
2095
+ function buildLightbox() {
2096
+ if (lightboxEl) return;
2097
+ lightboxEl = document.createElement('div');
2098
+ lightboxEl.className = 'lightbox';
2099
+ lightboxEl.hidden = true;
2100
+ lightboxEl.setAttribute('role', 'dialog');
2101
+ lightboxEl.setAttribute('aria-modal', 'true');
2102
+
2103
+ var bar = document.createElement('div');
2104
+ bar.className = 'lightbox-bar';
2105
+ var hint = document.createElement('span');
2106
+ hint.className = 'lightbox-hint';
2107
+ hint.textContent = 'scroll to pan · shift+scroll sideways · ctrl+scroll to zoom · drag to pan · esc to close';
2108
+ lightboxZoomValue = document.createElement('span');
2109
+ lightboxZoomValue.className = 'lightbox-zoom-value';
2110
+ lightboxZoomValue.setAttribute('data-lightbox-zoom-value', '');
2111
+ bar.appendChild(hint);
2112
+ bar.appendChild(lightboxButton('−', 'Zoom out', function () { zoomLightboxBy(1 / LIGHTBOX_STEP); }));
2113
+ bar.appendChild(lightboxZoomValue);
2114
+ bar.appendChild(lightboxButton('+', 'Zoom in', function () { zoomLightboxBy(LIGHTBOX_STEP); }));
2115
+ bar.appendChild(lightboxButton('Fit', 'Fit to window', function () { setLightboxZoom(lightboxFitZoom); }));
2116
+ bar.appendChild(lightboxButton('1:1', 'Actual size', function () { setLightboxZoom(1); }));
2117
+ bar.appendChild(lightboxButton('✕', 'Close', closeLightbox));
2118
+
2119
+ lightboxStage = document.createElement('div');
2120
+ lightboxStage.className = 'lightbox-stage';
2121
+ lightboxCanvas = document.createElement('div');
2122
+ lightboxCanvas.className = 'lightbox-canvas';
2123
+ lightboxStage.appendChild(lightboxCanvas);
2124
+ lightboxEl.appendChild(bar);
2125
+ lightboxEl.appendChild(lightboxStage);
2126
+ document.body.appendChild(lightboxEl);
2127
+
2128
+ var panning = false;
2129
+ var panX = 0;
2130
+ var panY = 0;
2131
+ var panDistance = 0;
2132
+
2133
+ lightboxStage.addEventListener('wheel', function (event) {
2134
+ // Plain and shift+wheel stay native scrolling — that is the pan.
2135
+ if (!event.ctrlKey && !event.metaKey) return;
2136
+ event.preventDefault();
2137
+ var rect = lightboxStage.getBoundingClientRect();
2138
+ zoomLightboxBy(
2139
+ event.deltaY < 0 ? LIGHTBOX_STEP : 1 / LIGHTBOX_STEP,
2140
+ event.clientX - rect.left,
2141
+ event.clientY - rect.top
2142
+ );
2143
+ }, { passive: false });
2144
+
2145
+ lightboxStage.addEventListener('mousedown', function (event) {
2146
+ if (event.button !== 0) return;
2147
+ panning = true;
2148
+ panDistance = 0;
2149
+ panX = event.clientX;
2150
+ panY = event.clientY;
2151
+ lightboxStage.setAttribute('data-panning', '');
2152
+ event.preventDefault();
2153
+ });
2154
+ document.addEventListener('mousemove', function (event) {
2155
+ if (!panning) return;
2156
+ var dx = event.clientX - panX;
2157
+ var dy = event.clientY - panY;
2158
+ panX = event.clientX;
2159
+ panY = event.clientY;
2160
+ panDistance += Math.abs(dx) + Math.abs(dy);
2161
+ lightboxStage.scrollLeft -= dx;
2162
+ lightboxStage.scrollTop -= dy;
2163
+ });
2164
+ document.addEventListener('mouseup', function () {
2165
+ if (!panning) return;
2166
+ panning = false;
2167
+ lightboxStage.removeAttribute('data-panning');
2168
+ });
2169
+
2170
+ lightboxStage.addEventListener('click', function (event) {
2171
+ if (panDistance > 4) return;
2172
+ // Only the empty backdrop closes; a click on the artwork must not.
2173
+ if (event.target === lightboxStage) closeLightbox();
2174
+ });
2175
+ lightboxStage.addEventListener('dblclick', function (event) {
2176
+ event.preventDefault();
2177
+ setLightboxZoom(Math.abs(lightboxZoom - 1) < 0.001 ? lightboxFitZoom : 1);
2178
+ });
2179
+ }
2180
+
2181
+ function lightboxSourceOf(node) {
2182
+ if (node.tagName === 'IMG') return node;
2183
+ return node.querySelector('svg') || node;
2184
+ }
2185
+
2186
+ function lightboxNaturalSize(source) {
2187
+ if (source.tagName === 'IMG') {
2188
+ return { w: source.naturalWidth || source.clientWidth || 1, h: source.naturalHeight || source.clientHeight || 1 };
2189
+ }
2190
+ var box = source.viewBox ? source.viewBox.baseVal : null;
2191
+ if (box && box.width) return { w: box.width, h: box.height };
2192
+ var rect = source.getBoundingClientRect();
2193
+ return { w: rect.width || 1, h: rect.height || 1 };
2194
+ }
2195
+
2196
+ function openLightbox(node) {
2197
+ buildLightbox();
2198
+ var source = lightboxSourceOf(node);
2199
+ var size = lightboxNaturalSize(source);
2200
+ lightboxNaturalW = Math.max(1, Math.round(size.w));
2201
+ lightboxNaturalH = Math.max(1, Math.round(size.h));
2202
+
2203
+ var isVector = !!(source.tagName && source.tagName.toLowerCase() === 'svg');
2204
+ var clone = source.cloneNode(true);
2205
+ clone.removeAttribute('id');
2206
+ clone.removeAttribute('class');
2207
+ clone.removeAttribute('style');
2208
+ clone.removeAttribute('width');
2209
+ clone.removeAttribute('height');
2210
+ if (isVector && !clone.getAttribute('viewBox')) {
2211
+ clone.setAttribute('viewBox', '0 0 ' + lightboxNaturalW + ' ' + lightboxNaturalH);
2212
+ }
2213
+ while (lightboxCanvas.firstChild) {
2214
+ lightboxCanvas.removeChild(lightboxCanvas.firstChild);
2215
+ }
2216
+ lightboxCanvas.appendChild(clone);
2217
+
2218
+ lightboxReturnScroll = window.scrollY;
2219
+ suppressAnchorCapture = true;
2220
+ document.body.setAttribute('data-lightbox-open', '');
2221
+ lightboxEl.hidden = false;
2222
+ lightboxStage.scrollTop = 0;
2223
+ lightboxStage.scrollLeft = 0;
2224
+ lightboxZoom = 1;
2225
+ lightboxFitZoom = computeLightboxFit(isVector);
2226
+ setLightboxZoom(lightboxFitZoom);
2227
+ }
2228
+
2229
+ function closeLightbox() {
2230
+ if (!lightboxIsOpen()) return;
2231
+ lightboxEl.hidden = true;
2232
+ document.body.removeAttribute('data-lightbox-open');
2233
+ while (lightboxCanvas.firstChild) {
2234
+ lightboxCanvas.removeChild(lightboxCanvas.firstChild);
2235
+ }
2236
+ window.scrollTo(window.scrollX, lightboxReturnScroll);
2237
+ window.requestAnimationFrame(function () {
2238
+ suppressAnchorCapture = false;
2239
+ captureScrollAnchor();
2240
+ });
2241
+ }
2242
+
2243
+ if (contentEl) {
2244
+ contentEl.addEventListener('click', function (event) {
2245
+ if (event.defaultPrevented || event.button !== 0) return;
2246
+ if (event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) return;
2247
+ var target = (event.target && event.target.closest) ? event.target.closest(LIGHTBOX_TARGETS) : null;
2248
+ if (!target) return;
2249
+ // A linked image is a link first.
2250
+ if (target.closest('a[href]')) return;
2251
+ event.preventDefault();
2252
+ openLightbox(target);
2253
+ });
2254
+ }
2255
+
2256
+ document.addEventListener('keydown', function (event) {
2257
+ if (!lightboxIsOpen()) return;
2258
+ if (event.key === 'Escape') { event.preventDefault(); closeLightbox(); return; }
2259
+ if (event.key === '+' || event.key === '=') { event.preventDefault(); zoomLightboxBy(LIGHTBOX_STEP); return; }
2260
+ if (event.key === '-' || event.key === '_') { event.preventDefault(); zoomLightboxBy(1 / LIGHTBOX_STEP); return; }
2261
+ if (event.key === '0') { event.preventDefault(); setLightboxZoom(lightboxFitZoom); return; }
2262
+ if (event.key === '1') { event.preventDefault(); setLightboxZoom(1); }
2263
+ });
2264
+
2265
+ window.addEventListener('resize', function () {
2266
+ if (!lightboxIsOpen()) return;
2267
+ var shown = lightboxCanvas.firstElementChild;
2268
+ lightboxFitZoom = computeLightboxFit(!!(shown && shown.tagName.toLowerCase() === 'svg'));
2269
+ });
1948
2270
  })();
1949
2271
  </script>
1950
2272
  </body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helping-ai-workflow/md2doc",
3
- "version": "2.4.2",
3
+ "version": "2.5.0",
4
4
  "description": "Markdown → HTML / PDF renderer with WaveDrom, Mermaid, and Graphviz support",
5
5
  "keywords": [
6
6
  "markdown",
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "scripts": {
38
38
  "preinstall": "node scripts/preinstall.js",
39
- "test": "node test/md2doc.test.js && node test/images.test.js && node test/scroll-anchor.test.js && node test/cli.test.js && node test/code-operator.test.js"
39
+ "test": "node test/md2doc.test.js && node test/images.test.js && node test/scroll-anchor.test.js && node test/lightbox.test.js && node test/cli.test.js && node test/code-operator.test.js"
40
40
  },
41
41
  "repository": {
42
42
  "type": "git",