concept-atlas-dense-explain 4.1.0 → 4.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "concept-atlas-dense-explain",
3
- "version": "4.1.0",
3
+ "version": "4.1.1",
4
4
  "description": "Portable dense-explanation skill and MDX concept atlas template",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1395,15 +1395,18 @@ export function Tabs({ items = [], children }) {
1395
1395
  Tabs.displayName = 'Tabs';
1396
1396
 
1397
1397
  /**
1398
- * Enlarged reader for a diagram. It re-renders the chart under a fresh id so
1399
- * the full-size copy never collides with the inline SVG, then hands the result
1400
- * to the shared zoom overlay (wheel zoom, drag to pan, Esc to close).
1398
+ * The drawing inside the full-size reader. A diagram is a vector, so enlarging
1399
+ * it has to change its layout size: a CSS `scale()` on the wrapper only
1400
+ * stretches the layer the browser already rasterised, which is what makes a
1401
+ * chart look like a blurry bitmap while it grows. The SVG therefore carries its
1402
+ * own viewBox size (`--diagram-w`, `--diagram-ratio`) and the reader multiplies
1403
+ * that width by the current zoom; panning still rides a transform, because a
1404
+ * translation never resamples.
1401
1405
  */
1402
- function MermaidZoom({ chart, title, onClose }) {
1406
+ function DiagramCanvas({ chart, zoom, onError }) {
1403
1407
  const ref = React.useRef(null);
1404
- const [error, setError] = React.useState('');
1405
1408
 
1406
- React.useEffect(() => {
1409
+ React.useLayoutEffect(() => {
1407
1410
  if (!ref.current) return;
1408
1411
  const source = chart.trim();
1409
1412
  if (!source) return;
@@ -1414,19 +1417,40 @@ function MermaidZoom({ chart, title, onClose }) {
1414
1417
  responsive: false
1415
1418
  });
1416
1419
  ref.current.innerHTML = svg;
1417
- setError('');
1420
+ const el = ref.current.querySelector('svg');
1421
+ const box = el?.viewBox?.baseVal;
1422
+ const width = box?.width || Number(el?.getAttribute('width')) || 0;
1423
+ const height = box?.height || Number(el?.getAttribute('height')) || 0;
1424
+ if (el && width > 0 && height > 0) {
1425
+ el.style.setProperty('--diagram-w', `${width}px`);
1426
+ el.style.setProperty('--diagram-ratio', String(width / height));
1427
+ }
1428
+ onError('');
1418
1429
  } catch (err) {
1419
- setError(err.message || '图表语法错误');
1430
+ onError(err.message || '图表语法错误');
1420
1431
  }
1421
- }, [chart]);
1432
+ }, [chart, onError]);
1433
+
1434
+ return <div className="mermaid-zoom-canvas" ref={ref} style={{ '--zoom': zoom }} />;
1435
+ }
1436
+
1437
+ /**
1438
+ * Enlarged reader for a diagram. It re-renders the chart under a fresh id so
1439
+ * the full-size copy never collides with the inline SVG, then hands the result
1440
+ * to the shared zoom overlay (wheel zoom, drag to pan, Esc to close).
1441
+ */
1442
+ function MermaidZoom({ chart, title, onClose }) {
1443
+ const [error, setError] = React.useState('');
1422
1444
 
1423
1445
  return (
1424
- <ZoomOverlay title={title || '关系草图'} caption={title} onClose={onClose}>
1425
- {error ? (
1426
- <pre className="mermaid-error">{error}</pre>
1427
- ) : (
1428
- <div className="mermaid-zoom-canvas" ref={ref} />
1429
- )}
1446
+ <ZoomOverlay title={title || '关系草图'} caption={title} onClose={onClose} vector>
1447
+ {scale =>
1448
+ error ? (
1449
+ <pre className="mermaid-error">{error}</pre>
1450
+ ) : (
1451
+ <DiagramCanvas chart={chart} zoom={scale} onError={setError} />
1452
+ )
1453
+ }
1430
1454
  </ZoomOverlay>
1431
1455
  );
1432
1456
  }
@@ -1961,7 +1985,7 @@ const clampScale = value => Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, +value.toFixed
1961
1985
  * fixed` would otherwise be contained by them). Supports wheel zoom, drag to
1962
1986
  * pan, double-click to toggle 1x/2x, and Escape to close.
1963
1987
  */
1964
- function ZoomOverlay({ title, caption, label, onClose, children }) {
1988
+ function ZoomOverlay({ title, caption, label, onClose, children, vector = false }) {
1965
1989
  const [scale, setScale] = React.useState(1);
1966
1990
  const [offset, setOffset] = React.useState({ x: 0, y: 0 });
1967
1991
  const [dragging, setDragging] = React.useState(false);
@@ -1971,6 +1995,9 @@ function ZoomOverlay({ title, caption, label, onClose, children }) {
1971
1995
  const movedRef = React.useRef(false);
1972
1996
  const scaleRef = React.useRef(scale);
1973
1997
  scaleRef.current = scale;
1998
+ // A vector target (a rendered diagram) receives the zoom as a number and
1999
+ // resizes itself; only a raster target (an image) is scaled as a layer.
2000
+ const content = typeof children === 'function' ? children(scale) : children;
1974
2001
 
1975
2002
  const zoomBy = React.useCallback(delta => setScale(value => clampScale(value + delta)), []);
1976
2003
  const reset = React.useCallback(() => {
@@ -2080,9 +2107,13 @@ function ZoomOverlay({ title, caption, label, onClose, children }) {
2080
2107
  >
2081
2108
  <div
2082
2109
  className="image-zoom-target"
2083
- style={{ transform: `translate(${offset.x}px, ${offset.y}px) scale(${scale})` }}
2110
+ style={
2111
+ vector
2112
+ ? { transform: `translate(${offset.x}px, ${offset.y}px)` }
2113
+ : { transform: `translate(${offset.x}px, ${offset.y}px) scale(${scale})` }
2114
+ }
2084
2115
  >
2085
- {children}
2116
+ {content}
2086
2117
  </div>
2087
2118
  </div>
2088
2119
  {title && (
@@ -2119,9 +2150,19 @@ function ZoomOverlay({ title, caption, label, onClose, children }) {
2119
2150
 
2120
2151
  function ImageZoom({ src, alt, caption, label, onClose }) {
2121
2152
  const title = alt || caption || '图片';
2153
+ const imgRef = React.useRef(null);
2154
+ // An SVG authored without width/height has no intrinsic width, so `width:auto`
2155
+ // inside the shrink-to-fit stage resolves to 0 and the reader opens empty.
2156
+ // Such an image gets the viewer's width instead; a bitmap keeps its own.
2157
+ const sizeSizelessImage = () => {
2158
+ const img = imgRef.current;
2159
+ if (!img || !img.complete || !img.naturalWidth) return;
2160
+ if (img.getBoundingClientRect().width > 0) return;
2161
+ img.style.width = 'min(94vw, 1800px)';
2162
+ };
2122
2163
  return (
2123
2164
  <ZoomOverlay title={title} caption={caption || alt} label={label} onClose={onClose}>
2124
- <img src={src} alt={alt || ''} draggable="false" />
2165
+ <img ref={imgRef} src={src} alt={alt || ''} draggable="false" onLoad={sizeSizelessImage} />
2125
2166
  </ZoomOverlay>
2126
2167
  );
2127
2168
  }
@@ -1 +1 @@
1
- export * from './MDXComponents.jsx';
1
+ export * from './MDXComponents.jsx';
@@ -1,16 +1,16 @@
1
- import React from 'react';
2
- import ReactDOM from 'react-dom/client';
3
- import { App } from './app/App.jsx';
4
- import * as Components from './components/index.js';
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom/client';
3
+ import { App } from './app/App.jsx';
4
+ import * as Components from './components/index.js';
5
5
  import UserDocument from '@concept-atlas/content';
6
-
7
- // Mount MDX application to DOM
8
- const rootElement = document.getElementById('root') || document.getElementById('app');
9
- if (rootElement) {
10
- const root = ReactDOM.createRoot(rootElement);
11
- root.render(
12
- <React.StrictMode>
6
+
7
+ // Mount MDX application to DOM
8
+ const rootElement = document.getElementById('root') || document.getElementById('app');
9
+ if (rootElement) {
10
+ const root = ReactDOM.createRoot(rootElement);
11
+ root.render(
12
+ <React.StrictMode>
13
13
  <App mdxContent={<UserDocument components={Components} />} />
14
- </React.StrictMode>
15
- );
16
- }
14
+ </React.StrictMode>
15
+ );
16
+ }
@@ -3885,6 +3885,9 @@ html[data-carrier='scroll'] #root {
3885
3885
  display: grid;
3886
3886
  place-items: center;
3887
3887
  padding: 28px;
3888
+ /* How much of the viewport a full-size diagram may fill; the reader's fit
3889
+ math and the small-screen override both read it. */
3890
+ --zoom-fit-h: 84vh;
3888
3891
  background: var(--overlay-scrim);
3889
3892
  /* Clip at the viewport, not at the media box: the zoom transform does not
3890
3893
  change layout size, so a stage-sized clip would only ever reveal what the
@@ -3928,12 +3931,19 @@ html[data-carrier='scroll'] #root {
3928
3931
  .image-zoom-stage.is-dragging .image-zoom-target { transition: none; }
3929
3932
 
3930
3933
  /* A diagram keeps its natural aspect inside the viewer and paints on the
3931
- diagram canvas tone, so labels stay legible over the dark scrim. */
3934
+ diagram canvas tone, so labels stay legible over the dark scrim. It is a
3935
+ vector: the reader multiplies its layout width by `--zoom` (a number handed
3936
+ down by ZoomOverlay) instead of scaling a rasterised layer, so every step of
3937
+ the zoom re-renders sharp. `--diagram-w` / `--diagram-ratio` come from the
3938
+ SVG's own viewBox: the fit fills the viewport, never past twice the natural
3939
+ width, and a tall chart is bounded by the height instead — so opening a
3940
+ narrow chart no longer paints a wide empty slab. */
3932
3941
  .mermaid-zoom-canvas svg {
3933
3942
  display: block;
3934
- width: min(94vw, 1800px);
3943
+ width: calc(min(94vw, calc(var(--diagram-w, 1800px) * 2), calc(var(--zoom-fit-h, 84vh) * var(--diagram-ratio, 1.78))) * var(--zoom, 1));
3935
3944
  height: auto;
3936
- max-height: 84vh;
3945
+ max-width: none;
3946
+ max-height: none;
3937
3947
  border-radius: var(--radius-3);
3938
3948
  background: var(--pele-bg);
3939
3949
  box-shadow: var(--shadow-modal);
@@ -4000,9 +4010,8 @@ html[data-carrier='scroll'] #root {
4000
4010
  }
4001
4011
 
4002
4012
  @media (max-width: 760px) {
4003
- .image-zoom-overlay { padding: 12px; }
4013
+ .image-zoom-overlay { padding: 12px; --zoom-fit-h: 74vh; }
4004
4014
  .image-zoom-stage img { max-height: 74vh; }
4005
- .mermaid-zoom-canvas svg { max-height: 74vh; }
4006
4015
  .image-zoom-caption { top: 10px; font-size: 12px; }
4007
4016
  }
4008
4017