@zombie-mermaid/mermaid-parser 3.2.0 → 4.1.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/dist/index.cjs +3 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -1
- package/dist/index.d.ts +26 -1
- package/dist/index.js +684 -254
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/xychart-colors.test.ts +34 -0
- package/src/class/parser.ts +8 -13
- package/src/class/types.ts +13 -0
- package/src/flowchart-parser.ts +1324 -0
- package/src/index.ts +4 -2
- package/src/sequence/types.ts +2 -0
- package/src/xychart/colors.ts +10 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zombie-mermaid/mermaid-parser",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Parsers for class, ER, sequence, and XY chart diagrams — the per-type parse functions both svg-renderer and ascii-renderer import directly.",
|
|
6
6
|
"repository": {
|
|
@@ -35,6 +35,6 @@
|
|
|
35
35
|
"LICENSE"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@zombie-mermaid/core": "
|
|
38
|
+
"@zombie-mermaid/core": "4.1.0"
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -117,6 +117,40 @@ describe('getSeriesColor', () => {
|
|
|
117
117
|
})
|
|
118
118
|
})
|
|
119
119
|
|
|
120
|
+
describe('first-three-series separation (#1244)', () => {
|
|
121
|
+
// CIE76 ΔE between two sRGB hex colors.
|
|
122
|
+
function lab(hex: string): [number, number, number] {
|
|
123
|
+
const lin = (i: number) => {
|
|
124
|
+
const v = parseInt(hex.slice(i, i + 2), 16) / 255
|
|
125
|
+
return v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4
|
|
126
|
+
}
|
|
127
|
+
const [r, g, b] = [lin(1), lin(3), lin(5)] as const
|
|
128
|
+
const x = (0.4124 * r + 0.3576 * g + 0.1805 * b) / 0.95047
|
|
129
|
+
const y = 0.2126 * r + 0.7152 * g + 0.0722 * b
|
|
130
|
+
const z = (0.0193 * r + 0.1192 * g + 0.9505 * b) / 1.08883
|
|
131
|
+
const f = (t: number) =>
|
|
132
|
+
t > 0.008856 ? Math.cbrt(t) : 7.787 * t + 16 / 116
|
|
133
|
+
return [116 * f(y) - 16, 500 * (f(x) - f(y)), 200 * (f(y) - f(z))]
|
|
134
|
+
}
|
|
135
|
+
const deltaE = (a: string, b: string) => {
|
|
136
|
+
const [l1, a1, b1] = lab(a)
|
|
137
|
+
const [l2, a2, b2] = lab(b)
|
|
138
|
+
return Math.hypot(l1 - l2, a1 - a2, b1 - b2)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// The pre-fix palette had ΔE 9 between series 0 and 2 (two similar blues).
|
|
142
|
+
for (const bg of ['#ffffff', '#1a1b26']) {
|
|
143
|
+
it(`keeps series 0, 1 and 2 at least 25 ΔE apart on ${bg}`, () => {
|
|
144
|
+
const c0 = getSeriesColor(0, '#3b82f6', bg)
|
|
145
|
+
const c1 = getSeriesColor(1, '#3b82f6', bg)
|
|
146
|
+
const c2 = getSeriesColor(2, '#3b82f6', bg)
|
|
147
|
+
expect(deltaE(c0, c1)).toBeGreaterThanOrEqual(25)
|
|
148
|
+
expect(deltaE(c0, c2)).toBeGreaterThanOrEqual(25)
|
|
149
|
+
expect(deltaE(c1, c2)).toBeGreaterThanOrEqual(25)
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
})
|
|
153
|
+
|
|
120
154
|
/** Minimal hex→HSL helper for assertions (mirrors colors.ts's private hexToHsl). */
|
|
121
155
|
function hexLightness(hex: string): [number, number, number] {
|
|
122
156
|
const h = hex.replace('#', '')
|
package/src/class/parser.ts
CHANGED
|
@@ -478,19 +478,14 @@ function parseMember(
|
|
|
478
478
|
}
|
|
479
479
|
}
|
|
480
480
|
|
|
481
|
-
// It's an attribute
|
|
482
|
-
//
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
type = parts[0]
|
|
490
|
-
name = parts.slice(1).join(' ')
|
|
491
|
-
} else {
|
|
492
|
-
name = parts[0] ?? rest
|
|
493
|
-
}
|
|
481
|
+
// It's an attribute. Mermaid renders attribute text verbatim (its
|
|
482
|
+
// ClassMember keeps everything after the visibility marker as one id and
|
|
483
|
+
// only splits methods into name/params/return type), so `String name`,
|
|
484
|
+
// `name Type` and `name: Type` all display as written. Splitting two
|
|
485
|
+
// tokens into Type + name guessed the order and flipped `-data Map` into
|
|
486
|
+
// `- Map: data` (#1265).
|
|
487
|
+
const name = parseGenericTypes(rest)
|
|
488
|
+
const type: string | undefined = undefined
|
|
494
489
|
|
|
495
490
|
const isStatic = name.endsWith('$')
|
|
496
491
|
const isAbstract = name.endsWith('*')
|
package/src/class/types.ts
CHANGED
|
@@ -110,6 +110,19 @@ export interface PositionedClassDiagram {
|
|
|
110
110
|
classes: PositionedClassNode[]
|
|
111
111
|
relationships: PositionedClassRelationship[]
|
|
112
112
|
notes: PositionedClassNote[]
|
|
113
|
+
/** Namespace frames, drawn behind their member classes */
|
|
114
|
+
namespaces: PositionedClassNamespace[]
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** A `namespace Name { ... }` block's frame, in diagram coordinates */
|
|
118
|
+
export interface PositionedClassNamespace {
|
|
119
|
+
name: string
|
|
120
|
+
/** Ids of the member classes the frame encloses */
|
|
121
|
+
classIds: string[]
|
|
122
|
+
x: number
|
|
123
|
+
y: number
|
|
124
|
+
width: number
|
|
125
|
+
height: number
|
|
113
126
|
}
|
|
114
127
|
|
|
115
128
|
export interface PositionedClassNote {
|