dsh-mermaid-plus 0.1.3 → 0.1.4
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/client.js +48 -2
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -470,7 +470,7 @@ window.__ModuleLoader__.load({
|
|
|
470
470
|
.dsh-mdm-lb-btn:focus-visible{outline:2px solid #8ab4f8;outline-offset:2px}
|
|
471
471
|
.dsh-mdm-lb-stage{flex:1;min-height:0;display:flex;align-items:center;justify-content:center;overflow:hidden;touch-action:none;cursor:grab}
|
|
472
472
|
.dsh-mdm-lb-stage[data-dragging="true"]{cursor:grabbing}
|
|
473
|
-
.dsh-mdm-lb-canvas{transform-origin:center center;will-change:transform;flex:none}
|
|
473
|
+
.dsh-mdm-lb-canvas{transform-origin:center center;will-change:transform;flex:none;padding:24px;border-radius:14px;box-sizing:content-box;box-shadow:0 18px 60px rgba(0,0,0,.5)}
|
|
474
474
|
.dsh-mdm-lb-canvas svg{display:block;width:100%;height:100%;max-width:none}
|
|
475
475
|
.dsh-mdm-lb-hint{padding:0 14px 12px;font-size:11px;line-height:1.4;color:rgba(242,245,250,.6);text-align:center;flex:none}
|
|
476
476
|
@media (prefers-reduced-motion: no-preference){.dsh-mdm-lb{animation:dsh-mdm-in .15s ease-out}}
|
|
@@ -740,6 +740,8 @@ window.__ModuleLoader__.load({
|
|
|
740
740
|
const scheme = currentScheme();
|
|
741
741
|
const palette = readPalette(scheme);
|
|
742
742
|
paletteSignature = palette.signature;
|
|
743
|
+
entry.surface = palette.palette.background;
|
|
744
|
+
entry.surfaceDark = palette.dark;
|
|
743
745
|
const key = `${paletteSignature}\u0000${source}`;
|
|
744
746
|
if (key === entry.hash && entry.state === 'ok') return;
|
|
745
747
|
entry.hash = key;
|
|
@@ -789,6 +791,8 @@ window.__ModuleLoader__.load({
|
|
|
789
791
|
throw new Error('mermaid produced an empty diagram');
|
|
790
792
|
}
|
|
791
793
|
remember(key, result.svg);
|
|
794
|
+
entry.surface = palette.palette.background;
|
|
795
|
+
entry.surfaceDark = palette.dark;
|
|
792
796
|
entry.canvas.replaceChildren(svgFragment(result.svg));
|
|
793
797
|
entry.state = 'ok';
|
|
794
798
|
paint(entry);
|
|
@@ -827,6 +831,40 @@ window.__ModuleLoader__.load({
|
|
|
827
831
|
/** The one open fullscreen viewer, or null. */
|
|
828
832
|
let lightbox = null;
|
|
829
833
|
|
|
834
|
+
/**
|
|
835
|
+
* Force a colour to be opaque.
|
|
836
|
+
*
|
|
837
|
+
* A translucent surface would let the dark backdrop through and defeat the
|
|
838
|
+
* point, so an `rgba()` value below full alpha falls back to the theme's solid
|
|
839
|
+
* base. Hex and named colours are opaque by definition.
|
|
840
|
+
* @param color - any CSS colour string from the design tokens.
|
|
841
|
+
* @param dark - whether the dark fallback applies.
|
|
842
|
+
* @returns an opaque colour string.
|
|
843
|
+
*/
|
|
844
|
+
function opaqueSurface(color, dark) {
|
|
845
|
+
const match = /^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)(?:[,\s/]+([\d.]+%?))?\s*\)$/i.exec(color);
|
|
846
|
+
if (match === null) return color;
|
|
847
|
+
const raw = match[4];
|
|
848
|
+
const alpha = raw === undefined ? 1 : raw.endsWith('%') ? Number.parseFloat(raw) / 100 : Number.parseFloat(raw);
|
|
849
|
+
if (alpha >= 1) return color;
|
|
850
|
+
return dark ? '#1b1c1f' : '#ffffff';
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
/** The surface a diagram should sit on, from its own record or the live tokens. */
|
|
854
|
+
function knownSurface(entry) {
|
|
855
|
+
const dark = typeof entry?.surfaceDark === 'boolean' ? entry.surfaceDark : currentScheme() === 'dark';
|
|
856
|
+
if (typeof entry?.surface === 'string' && entry.surface !== '') {
|
|
857
|
+
return { color: opaqueSurface(entry.surface, dark), dark };
|
|
858
|
+
}
|
|
859
|
+
let color = '';
|
|
860
|
+
try {
|
|
861
|
+
color = window.getComputedStyle(document.documentElement).getPropertyValue('--dsw-alias-bg-base').trim();
|
|
862
|
+
} catch {
|
|
863
|
+
color = '';
|
|
864
|
+
}
|
|
865
|
+
return { color: opaqueSurface(color === '' ? '#ffffff' : color, dark), dark };
|
|
866
|
+
}
|
|
867
|
+
|
|
830
868
|
/** A diagram's natural size, read from its viewBox with sane fallbacks. */
|
|
831
869
|
function naturalSize(svg) {
|
|
832
870
|
const box = (svg.getAttribute('viewBox') ?? '').trim().split(/[\s,]+/).map(Number);
|
|
@@ -914,6 +952,12 @@ window.__ModuleLoader__.load({
|
|
|
914
952
|
canvas.className = 'dsh-mdm-lb-canvas';
|
|
915
953
|
canvas.style.width = `${size.width}px`;
|
|
916
954
|
canvas.style.height = `${size.height}px`;
|
|
955
|
+
// Paint the palette this diagram was rendered for. Without it the
|
|
956
|
+
// transparent SVG sits on the dark backdrop and dark labels vanish.
|
|
957
|
+
const surface = knownSurface(entry);
|
|
958
|
+
canvas.style.background = surface.color;
|
|
959
|
+
canvas.style.border = `1px solid ${surface.dark ? 'rgba(255,255,255,.16)' : 'rgba(0,0,0,.08)'}`;
|
|
960
|
+
canvas.setAttribute('data-dsh-mermaid-surface', surface.dark ? 'dark' : 'light');
|
|
917
961
|
const clone = source.cloneNode(true);
|
|
918
962
|
clone.style.width = '100%';
|
|
919
963
|
clone.style.height = '100%';
|
|
@@ -941,7 +985,9 @@ window.__ModuleLoader__.load({
|
|
|
941
985
|
const fit = () => {
|
|
942
986
|
const availableWidth = Math.max(80, stage.clientWidth - 48);
|
|
943
987
|
const availableHeight = Math.max(80, stage.clientHeight - 48);
|
|
944
|
-
|
|
988
|
+
// The sheet's padding scales with the diagram, so fit against the
|
|
989
|
+
// padded box rather than the bare viewBox.
|
|
990
|
+
view.fit = Math.min(availableWidth / (size.width + 48), availableHeight / (size.height + 48));
|
|
945
991
|
// Never blow a small diagram up past 1.5x: filling the window with two
|
|
946
992
|
// giant boxes looks broken, and dense diagrams are already large.
|
|
947
993
|
view.scale = Math.max(view.min, Math.min(view.fit, 1.5));
|
package/package.json
CHANGED