d2-to-drawio 1.0.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.
- package/LICENSE +21 -0
- package/README.md +172 -0
- package/bin/d2-to-drawio.js +153 -0
- package/package.json +59 -0
- package/src/compile.js +97 -0
- package/src/emit.js +128 -0
- package/src/ids.js +21 -0
- package/src/index.js +129 -0
- package/src/map.js +447 -0
- package/src/special.js +56 -0
- package/src/theme-data.js +25 -0
- package/src/themes.js +27 -0
package/src/themes.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// D2 theme color resolution.
|
|
2
|
+
//
|
|
3
|
+
// The IR reports colors either as literal values (hex, css names) or as D2
|
|
4
|
+
// theme palette codes (N1-N7 neutrals, B1-B6 base, AA2/AA4/AA5, AB4/AB5).
|
|
5
|
+
// Palette data lives in theme-data.js, generated from the official
|
|
6
|
+
// terrastruct/d2 theme catalog.
|
|
7
|
+
|
|
8
|
+
import { THEMES } from './theme-data.js';
|
|
9
|
+
|
|
10
|
+
const CODE = /^(N[1-7]|B[1-6]|AA[245]|AB[45])$/;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Resolve an IR color value to something draw.io accepts.
|
|
14
|
+
* Literal values pass through; theme codes resolve against the palette.
|
|
15
|
+
*/
|
|
16
|
+
export function resolveColor(value, themeID = 0) {
|
|
17
|
+
if (value == null || value === '') return value;
|
|
18
|
+
if (value === 'transparent') return 'none';
|
|
19
|
+
if (!CODE.test(value)) return value;
|
|
20
|
+
const theme = THEMES[String(themeID)] ?? THEMES['0'];
|
|
21
|
+
return (theme && theme.colors[value]) ?? value;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Theme ids the palette table knows about. */
|
|
25
|
+
export function knownThemeIDs() {
|
|
26
|
+
return Object.keys(THEMES).map(Number).sort((a, b) => a - b);
|
|
27
|
+
}
|