@helping-ai-workflow/md2doc 2.8.0 → 2.8.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 +37 -17
  2. package/package.json +1 -1
package/lib/md2doc.js CHANGED
@@ -2216,7 +2216,8 @@ ${mermaidInitTag}` : ''}
2216
2216
  // scratch, and localStorage keys would go stale when the doc regenerates).
2217
2217
  var ANNO_NS = 'http://www.w3.org/2000/svg';
2218
2218
  var ANNO_COLORS = ['#ef4444', '#3b82f6', '#22c55e', '#f59e0b', '#111827'];
2219
- var ANNO_WIDTHS = [0.6, 1, 1.8];
2219
+ // Office-like absolute stroke widths: rendered px at fit zoom (S/M/L).
2220
+ var ANNO_WIDTHS = [1, 2, 4];
2220
2221
  var annoStore = (typeof WeakMap === 'function') ? new WeakMap() : null;
2221
2222
  var annoShapes = [];
2222
2223
  var annoSvg = null;
@@ -2227,7 +2228,7 @@ ${mermaidInitTag}` : ''}
2227
2228
  var annoRedoStack = [];
2228
2229
  var annoStrokeW = 3;
2229
2230
  var annoColor = ANNO_COLORS[0];
2230
- var annoWidthScale = 1;
2231
+ var annoWidth = ANNO_WIDTHS[1];
2231
2232
  var annoToolButtons = {};
2232
2233
  var annoStyleButtons = [];
2233
2234
  var annoSourceNode = null;
@@ -2367,7 +2368,7 @@ ${mermaidInitTag}` : ''}
2367
2368
  el.setAttribute('stroke-linecap', 'round');
2368
2369
  }
2369
2370
  el.setAttribute('stroke', color);
2370
- el.setAttribute('stroke-width', (annoStrokeW * (shape.ws || 1)).toFixed(1));
2371
+ el.setAttribute('stroke-width', (shape.sw || annoStrokeW).toFixed(2));
2371
2372
  return el;
2372
2373
  }
2373
2374
 
@@ -2411,13 +2412,14 @@ ${mermaidInitTag}` : ''}
2411
2412
  }
2412
2413
  hit.setAttribute('fill', 'none');
2413
2414
  hit.setAttribute('stroke', 'transparent');
2414
- hit.setAttribute('stroke-width', String(annoStrokeW * 5));
2415
+ hit.setAttribute('stroke-width', String(Math.max((shape.sw || annoStrokeW) * 5, 10 / (lightboxFitZoom || 1))));
2415
2416
  hit.setAttribute('data-anno-hit', '');
2416
2417
  g.appendChild(hit);
2417
2418
  }
2418
2419
  annoSvg.appendChild(g);
2419
2420
  });
2420
2421
  if (annoSelected && annoShapes.indexOf(annoSelected) !== -1) {
2422
+ var u = 1.5 / (lightboxFitZoom || 1); // ~1.5px at fit zoom
2421
2423
  var box = annoBBox(annoSelected);
2422
2424
  var ui = document.createElementNS(ANNO_NS, 'rect');
2423
2425
  ui.setAttribute('data-anno-ui', '');
@@ -2425,10 +2427,10 @@ ${mermaidInitTag}` : ''}
2425
2427
  ui.setAttribute('width', Math.max(0.1, box.w)); ui.setAttribute('height', Math.max(0.1, box.h));
2426
2428
  ui.setAttribute('fill', 'none');
2427
2429
  ui.setAttribute('stroke', '#3b82f6');
2428
- ui.setAttribute('stroke-width', String(Math.max(1, annoStrokeW / 2)));
2429
- ui.setAttribute('stroke-dasharray', (annoStrokeW * 2) + ' ' + annoStrokeW);
2430
+ ui.setAttribute('stroke-width', String(u));
2431
+ ui.setAttribute('stroke-dasharray', (u * 4) + ' ' + (u * 2));
2430
2432
  annoSvg.appendChild(ui);
2431
- var hs = annoStrokeW * 3;
2433
+ var hs = u * 6;
2432
2434
  [[box.x, box.y], [box.x + box.w, box.y], [box.x, box.y + box.h], [box.x + box.w, box.y + box.h]]
2433
2435
  .forEach(function (corner, i) {
2434
2436
  var h = document.createElementNS(ANNO_NS, 'rect');
@@ -2460,7 +2462,7 @@ ${mermaidInitTag}` : ''}
2460
2462
  } else if (op.kind === 'style') {
2461
2463
  var style = reverse ? op.before : op.after;
2462
2464
  op.shape.color = style.color;
2463
- op.shape.ws = style.ws;
2465
+ op.shape.sw = style.sw;
2464
2466
  } else if (op.kind === 'clear') {
2465
2467
  if (reverse) op.shapes.forEach(function (s) { annoShapes.push(s); });
2466
2468
  else annoShapes.length = 0;
@@ -2507,21 +2509,21 @@ ${mermaidInitTag}` : ''}
2507
2509
 
2508
2510
  function setAnnoStyle(patch) {
2509
2511
  if (patch.color) annoColor = patch.color;
2510
- if (patch.ws) annoWidthScale = patch.ws;
2512
+ if (patch.w) annoWidth = patch.w;
2511
2513
  annoStyleButtons.forEach(function (entry) {
2512
2514
  entry.button.classList.toggle('is-active',
2513
- entry.kind === 'color' ? entry.value === annoColor : entry.value === annoWidthScale);
2515
+ entry.kind === 'color' ? entry.value === annoColor : entry.value === annoWidth);
2514
2516
  });
2515
2517
  // With a selection, the pickers restyle it (undoably); otherwise they only
2516
2518
  // set the style for the next shape.
2517
2519
  if (annoSelected) {
2518
- var beforeStyle = { color: annoSelected.color, ws: annoSelected.ws };
2520
+ var beforeStyle = { color: annoSelected.color, sw: annoSelected.sw };
2519
2521
  annoSelected.color = patch.color || annoSelected.color;
2520
- annoSelected.ws = patch.ws || annoSelected.ws;
2522
+ if (patch.w) annoSelected.sw = patch.w / (lightboxFitZoom || 1);
2521
2523
  annoPushOp({
2522
2524
  kind: 'style', shape: annoSelected,
2523
2525
  before: beforeStyle,
2524
- after: { color: annoSelected.color, ws: annoSelected.ws },
2526
+ after: { color: annoSelected.color, sw: annoSelected.sw },
2525
2527
  });
2526
2528
  annoRedraw();
2527
2529
  }
@@ -2690,6 +2692,11 @@ ${mermaidInitTag}` : ''}
2690
2692
  annoSelected = null;
2691
2693
  annoRedraw();
2692
2694
  }
2695
+ // The baked clone still shows the shape at its old spot — revert to the
2696
+ // base image for the gesture; the overlay alone renders the live shapes.
2697
+ if (annoDraft && annoCloneEl && annoCloneEl.tagName === 'IMG' && annoBaseSrc) {
2698
+ annoCloneEl.src = annoBaseSrc;
2699
+ }
2693
2700
  return;
2694
2701
  }
2695
2702
  var shape;
@@ -2699,7 +2706,7 @@ ${mermaidInitTag}` : ''}
2699
2706
  else if (annoMode === 'a') shape = { type: 'arrow', x1: pt.x, y1: pt.y, x2: pt.x, y2: pt.y };
2700
2707
  else shape = { type: 'rect', x: pt.x, y: pt.y, w: 0, h: 0 };
2701
2708
  shape.color = annoColor;
2702
- shape.ws = annoWidthScale;
2709
+ shape.sw = annoWidth / (lightboxFitZoom || 1);
2703
2710
  annoDraft = { kind: 'draw', shape: shape, start: pt, el: annoShapeEl(shape), clientDist: 0, lastClient: [event.clientX, event.clientY] };
2704
2711
  annoSvg.appendChild(annoDraft.el);
2705
2712
  }
@@ -2766,6 +2773,8 @@ ${mermaidInitTag}` : ''}
2766
2773
  }
2767
2774
  if (d.moved) {
2768
2775
  annoPushOp({ kind: 'geom', shape: d.shape, before: d.before, after: annoGeomOf(d.shape) });
2776
+ } else {
2777
+ annoBake(); // gesture reverted the clone to the base image — restore it
2769
2778
  }
2770
2779
  annoRedraw();
2771
2780
  }
@@ -2845,9 +2854,9 @@ ${mermaidInitTag}` : ''}
2845
2854
  bar.appendChild(swatch);
2846
2855
  });
2847
2856
  [['S', ANNO_WIDTHS[0]], ['M', ANNO_WIDTHS[1]], ['L', ANNO_WIDTHS[2]]].forEach(function (width) {
2848
- var button = lightboxButton(width[0], 'Stroke width ' + width[0], function () { setAnnoStyle({ ws: width[1] }); });
2857
+ var button = lightboxButton(width[0], 'Stroke width ' + width[1] + 'px', function () { setAnnoStyle({ w: width[1] }); });
2849
2858
  button.setAttribute('data-anno-width', String(width[1]));
2850
- if (width[1] === annoWidthScale) button.classList.add('is-active');
2859
+ if (width[1] === annoWidth) button.classList.add('is-active');
2851
2860
  annoStyleButtons.push({ kind: 'width', value: width[1], button: button });
2852
2861
  bar.appendChild(button);
2853
2862
  });
@@ -2948,7 +2957,18 @@ ${mermaidInitTag}` : ''}
2948
2957
 
2949
2958
  var isVector = !!(source.tagName && source.tagName.toLowerCase() === 'svg');
2950
2959
  var clone = source.cloneNode(true);
2951
- clone.removeAttribute('id');
2960
+ // Mermaid scopes its embedded <style> to the svg's #id — dropping the id
2961
+ // kills the theme. Rename it instead (avoids a duplicate id) and rewrite
2962
+ // the scoped selectors to the new name.
2963
+ if (isVector && source.id) {
2964
+ var lightboxCloneId = 'lightbox-' + source.id;
2965
+ clone.setAttribute('id', lightboxCloneId);
2966
+ Array.prototype.forEach.call(clone.querySelectorAll('style'), function (styleEl) {
2967
+ styleEl.textContent = styleEl.textContent.split('#' + source.id).join('#' + lightboxCloneId);
2968
+ });
2969
+ } else {
2970
+ clone.removeAttribute('id');
2971
+ }
2952
2972
  clone.removeAttribute('class');
2953
2973
  clone.removeAttribute('style');
2954
2974
  clone.removeAttribute('width');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helping-ai-workflow/md2doc",
3
- "version": "2.8.0",
3
+ "version": "2.8.1",
4
4
  "description": "Markdown → HTML / PDF renderer with WaveDrom, Mermaid, and Graphviz support",
5
5
  "keywords": [
6
6
  "markdown",