@shibayama/pdgkit 0.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.
@@ -0,0 +1,130 @@
1
+ type Lang = 'ja' | 'en' | 'both';
2
+ type Bilingual = {
3
+ ja?: string;
4
+ en?: string;
5
+ };
6
+ type EdgeOp = 'line' | 'arrow' | 'bidir' | 'dashed' | 'dashed-arrow' | 'thick';
7
+ type Diagnostic = {
8
+ severity: 'error' | 'warning' | 'info';
9
+ line: number;
10
+ col: number;
11
+ message: string;
12
+ };
13
+ type Node = {
14
+ id: string;
15
+ label: Bilingual;
16
+ implicit: boolean;
17
+ };
18
+ type Containment = {
19
+ parent: string;
20
+ children: string[];
21
+ line: number;
22
+ };
23
+ type Edge = {
24
+ from: string;
25
+ to: string;
26
+ op: EdgeOp;
27
+ label?: Bilingual;
28
+ line: number;
29
+ };
30
+ type DiagramKind = 'block' | 'flow' | 'state' | 'seq';
31
+ type Doc = {
32
+ nodes: Map<string, Node>;
33
+ containments: Containment[];
34
+ edges: Edge[];
35
+ diagnostics: Diagnostic[];
36
+ kind: DiagramKind;
37
+ };
38
+
39
+ declare const OP_TABLE: {
40
+ lit: string;
41
+ kind: EdgeOp;
42
+ reverse?: boolean;
43
+ }[];
44
+ declare function parse(source: string): Doc;
45
+ declare function stripComment(line: string): string;
46
+ declare function splitBilingual(text: string): Bilingual;
47
+
48
+ type Box = {
49
+ x: number;
50
+ y: number;
51
+ w: number;
52
+ h: number;
53
+ };
54
+ type Shape = 'box' | 'round' | 'diamond' | 'circle' | 'actor';
55
+ type LaidOutNode = Box & {
56
+ id: string;
57
+ label: Bilingual;
58
+ shape: Shape;
59
+ isContainer: boolean;
60
+ };
61
+ type LaidOutEdge = {
62
+ from: string;
63
+ to: string;
64
+ points: [number, number][];
65
+ label?: Bilingual;
66
+ op: EdgeOp;
67
+ isLifeline?: boolean;
68
+ };
69
+ type LaidOut = {
70
+ nodes: LaidOutNode[];
71
+ edges: LaidOutEdge[];
72
+ width: number;
73
+ height: number;
74
+ kind: Doc['kind'];
75
+ };
76
+ declare function layout(doc: Doc): LaidOut;
77
+
78
+ type RenderOptions = {
79
+ lang?: Lang;
80
+ };
81
+ type LabelPlacement = {
82
+ box: {
83
+ x: number;
84
+ y: number;
85
+ w: number;
86
+ h: number;
87
+ };
88
+ lineA: [number, number];
89
+ lineB: [number, number];
90
+ score: number;
91
+ vertical: boolean;
92
+ anchor: string;
93
+ ja: {
94
+ x: number;
95
+ y: number;
96
+ baseline: string;
97
+ };
98
+ en?: {
99
+ x: number;
100
+ y: number;
101
+ baseline: string;
102
+ };
103
+ };
104
+ declare function render(laid: LaidOut, opts?: RenderOptions): SVGSVGElement;
105
+ declare function chooseLabelPlacement(edge: LaidOutEdge, labels: string[], laid: LaidOut, occupiedLabels?: BoxLike[]): LabelPlacement;
106
+ declare function estimateTextWidth(text: string, fontSize: number): number;
107
+ type BoxLike = {
108
+ x: number;
109
+ y: number;
110
+ w: number;
111
+ h: number;
112
+ };
113
+
114
+ declare function refsToMarkdown(doc: Doc): string;
115
+ declare function refsToCsv(doc: Doc): string;
116
+
117
+ declare const SAMPLE_ORDER: readonly ["block", "system", "iot", "imagePipeline", "controlLoop", "flow", "state", "seq", "handshake"];
118
+ type SampleId = typeof SAMPLE_ORDER[number];
119
+ type Sample = {
120
+ label: string;
121
+ hint: string;
122
+ source: string;
123
+ };
124
+ declare const SAMPLES: Record<SampleId, Sample>;
125
+
126
+ type PatternId = 'cond' | 'container' | 'external' | 'seq' | 'state' | 'bidir' | 'hierarchy' | 'pipeline' | 'parallel' | 'handshake' | 'state_with_cond' | 'system';
127
+ declare const PATTERN_LABEL: Record<PatternId, string>;
128
+ declare const PATTERN_SOURCE: Record<PatternId, string>;
129
+
130
+ export { type Bilingual, type Box, type Containment, type Diagnostic, type DiagramKind, type Doc, type Edge, type EdgeOp, type LabelPlacement, type LaidOut, type LaidOutEdge, type LaidOutNode, type Lang, type Node, OP_TABLE, PATTERN_LABEL, PATTERN_SOURCE, type PatternId, type RenderOptions, SAMPLES, SAMPLE_ORDER, type SampleId, type Shape, chooseLabelPlacement, estimateTextWidth, layout, parse, refsToCsv, refsToMarkdown, render, splitBilingual, stripComment };
package/dist/core.d.ts ADDED
@@ -0,0 +1,130 @@
1
+ type Lang = 'ja' | 'en' | 'both';
2
+ type Bilingual = {
3
+ ja?: string;
4
+ en?: string;
5
+ };
6
+ type EdgeOp = 'line' | 'arrow' | 'bidir' | 'dashed' | 'dashed-arrow' | 'thick';
7
+ type Diagnostic = {
8
+ severity: 'error' | 'warning' | 'info';
9
+ line: number;
10
+ col: number;
11
+ message: string;
12
+ };
13
+ type Node = {
14
+ id: string;
15
+ label: Bilingual;
16
+ implicit: boolean;
17
+ };
18
+ type Containment = {
19
+ parent: string;
20
+ children: string[];
21
+ line: number;
22
+ };
23
+ type Edge = {
24
+ from: string;
25
+ to: string;
26
+ op: EdgeOp;
27
+ label?: Bilingual;
28
+ line: number;
29
+ };
30
+ type DiagramKind = 'block' | 'flow' | 'state' | 'seq';
31
+ type Doc = {
32
+ nodes: Map<string, Node>;
33
+ containments: Containment[];
34
+ edges: Edge[];
35
+ diagnostics: Diagnostic[];
36
+ kind: DiagramKind;
37
+ };
38
+
39
+ declare const OP_TABLE: {
40
+ lit: string;
41
+ kind: EdgeOp;
42
+ reverse?: boolean;
43
+ }[];
44
+ declare function parse(source: string): Doc;
45
+ declare function stripComment(line: string): string;
46
+ declare function splitBilingual(text: string): Bilingual;
47
+
48
+ type Box = {
49
+ x: number;
50
+ y: number;
51
+ w: number;
52
+ h: number;
53
+ };
54
+ type Shape = 'box' | 'round' | 'diamond' | 'circle' | 'actor';
55
+ type LaidOutNode = Box & {
56
+ id: string;
57
+ label: Bilingual;
58
+ shape: Shape;
59
+ isContainer: boolean;
60
+ };
61
+ type LaidOutEdge = {
62
+ from: string;
63
+ to: string;
64
+ points: [number, number][];
65
+ label?: Bilingual;
66
+ op: EdgeOp;
67
+ isLifeline?: boolean;
68
+ };
69
+ type LaidOut = {
70
+ nodes: LaidOutNode[];
71
+ edges: LaidOutEdge[];
72
+ width: number;
73
+ height: number;
74
+ kind: Doc['kind'];
75
+ };
76
+ declare function layout(doc: Doc): LaidOut;
77
+
78
+ type RenderOptions = {
79
+ lang?: Lang;
80
+ };
81
+ type LabelPlacement = {
82
+ box: {
83
+ x: number;
84
+ y: number;
85
+ w: number;
86
+ h: number;
87
+ };
88
+ lineA: [number, number];
89
+ lineB: [number, number];
90
+ score: number;
91
+ vertical: boolean;
92
+ anchor: string;
93
+ ja: {
94
+ x: number;
95
+ y: number;
96
+ baseline: string;
97
+ };
98
+ en?: {
99
+ x: number;
100
+ y: number;
101
+ baseline: string;
102
+ };
103
+ };
104
+ declare function render(laid: LaidOut, opts?: RenderOptions): SVGSVGElement;
105
+ declare function chooseLabelPlacement(edge: LaidOutEdge, labels: string[], laid: LaidOut, occupiedLabels?: BoxLike[]): LabelPlacement;
106
+ declare function estimateTextWidth(text: string, fontSize: number): number;
107
+ type BoxLike = {
108
+ x: number;
109
+ y: number;
110
+ w: number;
111
+ h: number;
112
+ };
113
+
114
+ declare function refsToMarkdown(doc: Doc): string;
115
+ declare function refsToCsv(doc: Doc): string;
116
+
117
+ declare const SAMPLE_ORDER: readonly ["block", "system", "iot", "imagePipeline", "controlLoop", "flow", "state", "seq", "handshake"];
118
+ type SampleId = typeof SAMPLE_ORDER[number];
119
+ type Sample = {
120
+ label: string;
121
+ hint: string;
122
+ source: string;
123
+ };
124
+ declare const SAMPLES: Record<SampleId, Sample>;
125
+
126
+ type PatternId = 'cond' | 'container' | 'external' | 'seq' | 'state' | 'bidir' | 'hierarchy' | 'pipeline' | 'parallel' | 'handshake' | 'state_with_cond' | 'system';
127
+ declare const PATTERN_LABEL: Record<PatternId, string>;
128
+ declare const PATTERN_SOURCE: Record<PatternId, string>;
129
+
130
+ export { type Bilingual, type Box, type Containment, type Diagnostic, type DiagramKind, type Doc, type Edge, type EdgeOp, type LabelPlacement, type LaidOut, type LaidOutEdge, type LaidOutNode, type Lang, type Node, OP_TABLE, PATTERN_LABEL, PATTERN_SOURCE, type PatternId, type RenderOptions, SAMPLES, SAMPLE_ORDER, type SampleId, type Shape, chooseLabelPlacement, estimateTextWidth, layout, parse, refsToCsv, refsToMarkdown, render, splitBilingual, stripComment };