dsh-mermaid-plus 0.1.2 → 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 +61 -13
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
window.__ModuleLoader__.load({
|
|
2
2
|
id: 'dsh-mermaid-plus',
|
|
3
3
|
factory(require) {
|
|
4
|
+
/** Package name; also the boot-graph entry id and the source of every runtime name. */
|
|
5
|
+
const PKG = 'dsh-mermaid-plus';
|
|
6
|
+
/**
|
|
7
|
+
* Host route serving the vendored runtime, derived from the package name so two
|
|
8
|
+
* diagram plugins can be installed side by side. The Host half derives the same
|
|
9
|
+
* value from its own manifest; the two formulas must stay identical.
|
|
10
|
+
*/
|
|
11
|
+
const RUNTIME_PATH = `/x-${PKG.replace(/^@/, '').replace(/[^a-z0-9]+/gi, '-').toLowerCase()}`;
|
|
12
|
+
/** Bundled Mermaid release; part of the URL so a page reload refetches a new build. */
|
|
13
|
+
const RUNTIME_VERSION = '11.17.0';
|
|
14
|
+
|
|
4
15
|
/** Report one browser-half event to the Host's sink; a failure here is never fatal. */
|
|
5
16
|
function report(event, detail) {
|
|
6
17
|
try {
|
|
@@ -8,7 +19,8 @@ window.__ModuleLoader__.load({
|
|
|
8
19
|
method: 'POST',
|
|
9
20
|
headers: { 'content-type': 'application/json' },
|
|
10
21
|
body: JSON.stringify({ event, detail, href: String(window.location.href), at: Date.now() }),
|
|
11
|
-
keepalive
|
|
22
|
+
// No `keepalive`: on the desktop app's custom scheme the browser
|
|
23
|
+
// drops keepalive requests, and this report is best-effort anyway.
|
|
12
24
|
}).catch(() => undefined);
|
|
13
25
|
} catch {
|
|
14
26
|
/* the report is best effort only */
|
|
@@ -27,16 +39,6 @@ window.__ModuleLoader__.load({
|
|
|
27
39
|
const h = React.createElement;
|
|
28
40
|
|
|
29
41
|
//#region configuration
|
|
30
|
-
/** Package name; also the boot-graph entry id and the source of every runtime name. */
|
|
31
|
-
const PKG = 'dsh-mermaid-plus';
|
|
32
|
-
/**
|
|
33
|
-
* Host route serving the vendored runtime, derived from the package name so two
|
|
34
|
-
* diagram plugins can be installed side by side. The Host half derives the same
|
|
35
|
-
* value from its own manifest; the two formulas must stay identical.
|
|
36
|
-
*/
|
|
37
|
-
const RUNTIME_PATH = `/x-${PKG.replace(/^@/, '').replace(/[^a-z0-9]+/gi, '-').toLowerCase()}`;
|
|
38
|
-
/** Bundled Mermaid release; part of the URL so a page reload refetches a new build. */
|
|
39
|
-
const RUNTIME_VERSION = '11.17.0';
|
|
40
42
|
/**
|
|
41
43
|
* Preference key for the render mode. Namespaced by package name so a second
|
|
42
44
|
* diagram plugin cannot read or overwrite this one's choice.
|
|
@@ -468,7 +470,7 @@ window.__ModuleLoader__.load({
|
|
|
468
470
|
.dsh-mdm-lb-btn:focus-visible{outline:2px solid #8ab4f8;outline-offset:2px}
|
|
469
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}
|
|
470
472
|
.dsh-mdm-lb-stage[data-dragging="true"]{cursor:grabbing}
|
|
471
|
-
.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)}
|
|
472
474
|
.dsh-mdm-lb-canvas svg{display:block;width:100%;height:100%;max-width:none}
|
|
473
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}
|
|
474
476
|
@media (prefers-reduced-motion: no-preference){.dsh-mdm-lb{animation:dsh-mdm-in .15s ease-out}}
|
|
@@ -738,6 +740,8 @@ window.__ModuleLoader__.load({
|
|
|
738
740
|
const scheme = currentScheme();
|
|
739
741
|
const palette = readPalette(scheme);
|
|
740
742
|
paletteSignature = palette.signature;
|
|
743
|
+
entry.surface = palette.palette.background;
|
|
744
|
+
entry.surfaceDark = palette.dark;
|
|
741
745
|
const key = `${paletteSignature}\u0000${source}`;
|
|
742
746
|
if (key === entry.hash && entry.state === 'ok') return;
|
|
743
747
|
entry.hash = key;
|
|
@@ -787,6 +791,8 @@ window.__ModuleLoader__.load({
|
|
|
787
791
|
throw new Error('mermaid produced an empty diagram');
|
|
788
792
|
}
|
|
789
793
|
remember(key, result.svg);
|
|
794
|
+
entry.surface = palette.palette.background;
|
|
795
|
+
entry.surfaceDark = palette.dark;
|
|
790
796
|
entry.canvas.replaceChildren(svgFragment(result.svg));
|
|
791
797
|
entry.state = 'ok';
|
|
792
798
|
paint(entry);
|
|
@@ -825,6 +831,40 @@ window.__ModuleLoader__.load({
|
|
|
825
831
|
/** The one open fullscreen viewer, or null. */
|
|
826
832
|
let lightbox = null;
|
|
827
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
|
+
|
|
828
868
|
/** A diagram's natural size, read from its viewBox with sane fallbacks. */
|
|
829
869
|
function naturalSize(svg) {
|
|
830
870
|
const box = (svg.getAttribute('viewBox') ?? '').trim().split(/[\s,]+/).map(Number);
|
|
@@ -912,6 +952,12 @@ window.__ModuleLoader__.load({
|
|
|
912
952
|
canvas.className = 'dsh-mdm-lb-canvas';
|
|
913
953
|
canvas.style.width = `${size.width}px`;
|
|
914
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');
|
|
915
961
|
const clone = source.cloneNode(true);
|
|
916
962
|
clone.style.width = '100%';
|
|
917
963
|
clone.style.height = '100%';
|
|
@@ -939,7 +985,9 @@ window.__ModuleLoader__.load({
|
|
|
939
985
|
const fit = () => {
|
|
940
986
|
const availableWidth = Math.max(80, stage.clientWidth - 48);
|
|
941
987
|
const availableHeight = Math.max(80, stage.clientHeight - 48);
|
|
942
|
-
|
|
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));
|
|
943
991
|
// Never blow a small diagram up past 1.5x: filling the window with two
|
|
944
992
|
// giant boxes looks broken, and dense diagrams are already large.
|
|
945
993
|
view.scale = Math.max(view.min, Math.min(view.fit, 1.5));
|
package/package.json
CHANGED