@modudraft/core 0.1.3 → 0.1.5
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/catalog/archetypes.json +613 -0
- package/dist/catalog/protocols.json +8 -0
- package/dist/catalog/tools.json +1142 -0
- package/dist/catalog-schema.d.ts +70 -0
- package/dist/catalog-schema.d.ts.map +1 -0
- package/dist/catalog-schema.js +31 -0
- package/dist/catalog.d.ts +11 -0
- package/dist/catalog.d.ts.map +1 -0
- package/dist/catalog.js +12 -0
- package/dist/color.d.ts +2 -0
- package/dist/color.d.ts.map +1 -0
- package/dist/color.js +82 -0
- package/dist/grouping.d.ts +4 -0
- package/dist/grouping.d.ts.map +1 -0
- package/dist/grouping.js +95 -0
- package/dist/icons.d.ts +9 -0
- package/dist/icons.d.ts.map +1 -0
- package/dist/icons.generated.d.ts +4 -0
- package/dist/icons.generated.d.ts.map +1 -0
- package/dist/icons.generated.js +127 -0
- package/dist/icons.js +23 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/{src/index.ts → dist/index.js} +0 -1
- package/dist/layout.d.ts +8 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/layout.js +71 -0
- package/dist/mermaid-import.d.ts +12 -0
- package/dist/mermaid-import.d.ts.map +1 -0
- package/dist/mermaid-import.js +102 -0
- package/dist/sysdraw-file.d.ts +123 -0
- package/dist/sysdraw-file.d.ts.map +1 -0
- package/dist/sysdraw-file.js +215 -0
- package/dist/types.d.ts +70 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +4 -1
- package/src/catalog/archetypes.json +0 -613
- package/src/catalog/protocols.json +0 -8
- package/src/catalog/tools.json +0 -1142
- package/src/catalog-schema.ts +0 -45
- package/src/catalog.ts +0 -29
- package/src/color.ts +0 -89
- package/src/grouping.ts +0 -108
- package/src/icons.generated.ts +0 -252
- package/src/icons.ts +0 -28
- package/src/layout.ts +0 -104
- package/src/mermaid-import.ts +0 -118
- package/src/sysdraw-file.ts +0 -250
- package/src/types.ts +0 -75
- package/tsconfig.json +0 -17
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { getArchetype } from "./catalog";
|
|
2
|
+
const HEADER_RE = /^(?:flowchart|graph)\s+(LR|RL|TD|TB|BT)\s*;?\s*$/i;
|
|
3
|
+
const IGNORED_RE = /^(?:subgraph\b|end\b|classDef\b|class\b|style\b|linkStyle\b|click\b|%%)/;
|
|
4
|
+
const ARROW_RE = /\s*(?:--\s+([^>]+?)\s+-->|-->\|([^|]*)\||-->)\s*/;
|
|
5
|
+
const stripQuotes = (s) => {
|
|
6
|
+
const t = s.trim();
|
|
7
|
+
return t.startsWith('"') && t.endsWith('"') ? t.slice(1, -1) : t;
|
|
8
|
+
};
|
|
9
|
+
function parseNodeToken(token) {
|
|
10
|
+
const t = token.trim();
|
|
11
|
+
const shapes = [
|
|
12
|
+
[/^(\w[\w-]*)\[\((.+)\)\]$/, "database"],
|
|
13
|
+
[/^(\w[\w-]*)\{\{(.+)\}\}$/, "gateway"],
|
|
14
|
+
[/^(\w[\w-]*)\(\[(.+)\]\)$/, "compute"],
|
|
15
|
+
[/^(\w[\w-]*)\[\/(.+)\/\]$/, "compute"],
|
|
16
|
+
[/^(\w[\w-]*)\(\((.+)\)\)$/, "cache"],
|
|
17
|
+
[/^(\w[\w-]*)>(.+)\]$/, "queue"],
|
|
18
|
+
[/^(\w[\w-]*)\[(.+)\]$/, "compute"],
|
|
19
|
+
[/^(\w[\w-]*)\{(.+)\}$/, "compute"],
|
|
20
|
+
[/^(\w[\w-]*)\((.+)\)$/, "compute"],
|
|
21
|
+
];
|
|
22
|
+
for (const [re, archetype] of shapes) {
|
|
23
|
+
const m = t.match(re);
|
|
24
|
+
if (m)
|
|
25
|
+
return { id: m[1], label: stripQuotes(m[2]), archetype, explicit: true };
|
|
26
|
+
}
|
|
27
|
+
const bare = t.match(/^(\w[\w-]*)$/);
|
|
28
|
+
if (bare)
|
|
29
|
+
return {
|
|
30
|
+
id: bare[1],
|
|
31
|
+
label: bare[1],
|
|
32
|
+
archetype: "compute",
|
|
33
|
+
explicit: false,
|
|
34
|
+
};
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
export function parseMermaid(text) {
|
|
38
|
+
let direction = "LR";
|
|
39
|
+
const nodesById = new Map();
|
|
40
|
+
const explicitIds = new Set();
|
|
41
|
+
const edges = [];
|
|
42
|
+
const ensureNode = (token) => {
|
|
43
|
+
const parsed = parseNodeToken(token);
|
|
44
|
+
if (!parsed)
|
|
45
|
+
return null;
|
|
46
|
+
const existing = nodesById.get(parsed.id);
|
|
47
|
+
if (!existing || (parsed.explicit && !explicitIds.has(parsed.id))) {
|
|
48
|
+
const archetype = parsed.archetype;
|
|
49
|
+
nodesById.set(parsed.id, {
|
|
50
|
+
id: parsed.id,
|
|
51
|
+
type: "sysNode",
|
|
52
|
+
position: { x: 0, y: 0 },
|
|
53
|
+
data: {
|
|
54
|
+
archetype,
|
|
55
|
+
concreteTool: getArchetype(archetype)?.defaultTool ?? "",
|
|
56
|
+
label: parsed.label,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
if (parsed.explicit)
|
|
60
|
+
explicitIds.add(parsed.id);
|
|
61
|
+
}
|
|
62
|
+
return parsed.id;
|
|
63
|
+
};
|
|
64
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
65
|
+
const line = raw.trim();
|
|
66
|
+
if (!line)
|
|
67
|
+
continue;
|
|
68
|
+
const header = line.match(HEADER_RE);
|
|
69
|
+
if (header) {
|
|
70
|
+
const dir = header[1].toUpperCase();
|
|
71
|
+
direction = dir === "LR" || dir === "RL" ? "LR" : "TB";
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (IGNORED_RE.test(line))
|
|
75
|
+
continue;
|
|
76
|
+
const normalized = line.replace(/-\.+->/g, "-->").replace(/==>/g, "-->");
|
|
77
|
+
const parts = normalized.split(ARROW_RE);
|
|
78
|
+
if (parts.length === 1) {
|
|
79
|
+
ensureNode(line);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
let prevId = ensureNode(parts[0]);
|
|
83
|
+
for (let i = 1; i < parts.length - 1; i += 3) {
|
|
84
|
+
const label = parts[i] ?? parts[i + 1];
|
|
85
|
+
const nextId = ensureNode(parts[i + 2]);
|
|
86
|
+
if (prevId && nextId) {
|
|
87
|
+
edges.push({
|
|
88
|
+
id: `mermaid-e${edges.length}`,
|
|
89
|
+
source: prevId,
|
|
90
|
+
target: nextId,
|
|
91
|
+
type: "sysEdge",
|
|
92
|
+
data: label !== undefined ? { label: label.trim() } : {},
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
prevId = nextId ?? prevId;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (nodesById.size === 0) {
|
|
99
|
+
return { ok: false, error: "No nodes found — check your Mermaid syntax." };
|
|
100
|
+
}
|
|
101
|
+
return { ok: true, nodes: [...nodesById.values()], edges, direction };
|
|
102
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { AppNode, SysEdge, ViewMode, NodeStyle } from "./types";
|
|
3
|
+
export declare const SYSDRAW_VERSION = "1.3.0";
|
|
4
|
+
export declare const sysdrawFileSchema: z.ZodObject<{
|
|
5
|
+
version: z.ZodString;
|
|
6
|
+
meta: z.ZodDefault<z.ZodCatch<z.ZodObject<{
|
|
7
|
+
title: z.ZodOptional<z.ZodString>;
|
|
8
|
+
lastModified: z.ZodOptional<z.ZodString>;
|
|
9
|
+
viewMode: z.ZodOptional<z.ZodEnum<{
|
|
10
|
+
minimalist: "minimalist";
|
|
11
|
+
real: "real";
|
|
12
|
+
}>>;
|
|
13
|
+
nodeStyle: z.ZodOptional<z.ZodEnum<{
|
|
14
|
+
symbol: "symbol";
|
|
15
|
+
card: "card";
|
|
16
|
+
plate: "plate";
|
|
17
|
+
}>>;
|
|
18
|
+
locked: z.ZodOptional<z.ZodBoolean>;
|
|
19
|
+
}, z.core.$strip>>>;
|
|
20
|
+
nodes: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
21
|
+
id: z.ZodString;
|
|
22
|
+
type: z.ZodCatch<z.ZodLiteral<"sysNode">>;
|
|
23
|
+
position: z.ZodObject<{
|
|
24
|
+
x: z.ZodNumber;
|
|
25
|
+
y: z.ZodNumber;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
data: z.ZodObject<{
|
|
28
|
+
archetype: z.ZodString;
|
|
29
|
+
concreteTool: z.ZodString;
|
|
30
|
+
label: z.ZodString;
|
|
31
|
+
customProperties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
34
|
+
id: z.ZodString;
|
|
35
|
+
type: z.ZodLiteral<"noteNode">;
|
|
36
|
+
position: z.ZodObject<{
|
|
37
|
+
x: z.ZodNumber;
|
|
38
|
+
y: z.ZodNumber;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
data: z.ZodObject<{
|
|
41
|
+
text: z.ZodString;
|
|
42
|
+
color: z.ZodOptional<z.ZodString>;
|
|
43
|
+
size: z.ZodOptional<z.ZodEnum<{
|
|
44
|
+
normal: "normal";
|
|
45
|
+
small: "small";
|
|
46
|
+
title: "title";
|
|
47
|
+
}>>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
50
|
+
id: z.ZodString;
|
|
51
|
+
type: z.ZodLiteral<"boundaryNode">;
|
|
52
|
+
position: z.ZodObject<{
|
|
53
|
+
x: z.ZodNumber;
|
|
54
|
+
y: z.ZodNumber;
|
|
55
|
+
}, z.core.$strip>;
|
|
56
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
57
|
+
height: z.ZodOptional<z.ZodNumber>;
|
|
58
|
+
data: z.ZodObject<{
|
|
59
|
+
label: z.ZodString;
|
|
60
|
+
color: z.ZodOptional<z.ZodString>;
|
|
61
|
+
}, z.core.$strip>;
|
|
62
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
63
|
+
id: z.ZodString;
|
|
64
|
+
type: z.ZodLiteral<"stepNode">;
|
|
65
|
+
position: z.ZodObject<{
|
|
66
|
+
x: z.ZodNumber;
|
|
67
|
+
y: z.ZodNumber;
|
|
68
|
+
}, z.core.$strip>;
|
|
69
|
+
data: z.ZodObject<{
|
|
70
|
+
n: z.ZodOptional<z.ZodNumber>;
|
|
71
|
+
label: z.ZodOptional<z.ZodString>;
|
|
72
|
+
color: z.ZodOptional<z.ZodString>;
|
|
73
|
+
}, z.core.$strip>;
|
|
74
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
75
|
+
id: z.ZodString;
|
|
76
|
+
type: z.ZodLiteral<"arrowNode">;
|
|
77
|
+
position: z.ZodObject<{
|
|
78
|
+
x: z.ZodNumber;
|
|
79
|
+
y: z.ZodNumber;
|
|
80
|
+
}, z.core.$strip>;
|
|
81
|
+
data: z.ZodObject<{
|
|
82
|
+
dx: z.ZodNumber;
|
|
83
|
+
dy: z.ZodNumber;
|
|
84
|
+
color: z.ZodOptional<z.ZodString>;
|
|
85
|
+
lineStyle: z.ZodOptional<z.ZodEnum<{
|
|
86
|
+
solid: "solid";
|
|
87
|
+
dashed: "dashed";
|
|
88
|
+
dotted: "dotted";
|
|
89
|
+
}>>;
|
|
90
|
+
}, z.core.$strip>;
|
|
91
|
+
}, z.core.$strip>]>>;
|
|
92
|
+
edges: z.ZodArray<z.ZodObject<{
|
|
93
|
+
id: z.ZodString;
|
|
94
|
+
source: z.ZodString;
|
|
95
|
+
target: z.ZodString;
|
|
96
|
+
type: z.ZodCatch<z.ZodLiteral<"sysEdge">>;
|
|
97
|
+
animated: z.ZodOptional<z.ZodBoolean>;
|
|
98
|
+
data: z.ZodOptional<z.ZodObject<{
|
|
99
|
+
label: z.ZodOptional<z.ZodString>;
|
|
100
|
+
protocol: z.ZodOptional<z.ZodString>;
|
|
101
|
+
color: z.ZodOptional<z.ZodString>;
|
|
102
|
+
customProperties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
103
|
+
}, z.core.$strip>>;
|
|
104
|
+
}, z.core.$strip>>;
|
|
105
|
+
}, z.core.$strip>;
|
|
106
|
+
export type SysdrawFile = z.infer<typeof sysdrawFileSchema>;
|
|
107
|
+
export declare function serializeSysdraw(state: {
|
|
108
|
+
nodes: AppNode[];
|
|
109
|
+
edges: SysEdge[];
|
|
110
|
+
viewMode: ViewMode;
|
|
111
|
+
nodeStyle: NodeStyle;
|
|
112
|
+
title?: string;
|
|
113
|
+
locked?: boolean;
|
|
114
|
+
}): string;
|
|
115
|
+
export type ParseResult = {
|
|
116
|
+
ok: true;
|
|
117
|
+
data: SysdrawFile;
|
|
118
|
+
} | {
|
|
119
|
+
ok: false;
|
|
120
|
+
error: string;
|
|
121
|
+
};
|
|
122
|
+
export declare function parseSysdraw(text: string): ParseResult;
|
|
123
|
+
//# sourceMappingURL=sysdraw-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sysdraw-file.d.ts","sourceRoot":"","sources":["../src/sysdraw-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EACV,OAAO,EACP,OAAO,EACP,QAAQ,EACR,SAAS,EAIV,MAAM,SAAS,CAAC;AAGjB,eAAO,MAAM,eAAe,UAAU,CAAC;AAgGvC,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAK5B,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D,wBAAgB,gBAAgB,CAAC,KAAK,EAAE;IACtC,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,EAAE,SAAS,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,GAAG,MAAM,CAuGT;AAED,MAAM,MAAM,WAAW,GACnB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,WAAW,CAAA;CAAE,GAC/B;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjC,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAgBtD"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { absolutizeAll } from "./grouping";
|
|
3
|
+
export const SYSDRAW_VERSION = "1.3.0";
|
|
4
|
+
const positionSchema = z.object({ x: z.number(), y: z.number() });
|
|
5
|
+
const sysNodeSchema = z.object({
|
|
6
|
+
id: z.string().min(1),
|
|
7
|
+
type: z.literal("sysNode").catch("sysNode"),
|
|
8
|
+
position: positionSchema,
|
|
9
|
+
data: z.object({
|
|
10
|
+
archetype: z.string().min(1),
|
|
11
|
+
concreteTool: z.string().min(1),
|
|
12
|
+
label: z.string(),
|
|
13
|
+
customProperties: z.record(z.string(), z.string()).optional(),
|
|
14
|
+
}),
|
|
15
|
+
});
|
|
16
|
+
const noteNodeSchema = z.object({
|
|
17
|
+
id: z.string().min(1),
|
|
18
|
+
type: z.literal("noteNode"),
|
|
19
|
+
position: positionSchema,
|
|
20
|
+
data: z.object({
|
|
21
|
+
text: z.string(),
|
|
22
|
+
color: z.string().optional(),
|
|
23
|
+
size: z.enum(["small", "normal", "title"]).optional(),
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
const boundaryNodeSchema = z.object({
|
|
27
|
+
id: z.string().min(1),
|
|
28
|
+
type: z.literal("boundaryNode"),
|
|
29
|
+
position: positionSchema,
|
|
30
|
+
width: z.number().optional(),
|
|
31
|
+
height: z.number().optional(),
|
|
32
|
+
data: z.object({
|
|
33
|
+
label: z.string(),
|
|
34
|
+
color: z.string().optional(),
|
|
35
|
+
}),
|
|
36
|
+
});
|
|
37
|
+
const stepNodeSchema = z.object({
|
|
38
|
+
id: z.string().min(1),
|
|
39
|
+
type: z.literal("stepNode"),
|
|
40
|
+
position: positionSchema,
|
|
41
|
+
data: z.object({
|
|
42
|
+
n: z.number().optional(),
|
|
43
|
+
label: z.string().optional(),
|
|
44
|
+
color: z.string().optional(),
|
|
45
|
+
}),
|
|
46
|
+
});
|
|
47
|
+
const arrowNodeSchema = z.object({
|
|
48
|
+
id: z.string().min(1),
|
|
49
|
+
type: z.literal("arrowNode"),
|
|
50
|
+
position: positionSchema,
|
|
51
|
+
data: z.object({
|
|
52
|
+
dx: z.number(),
|
|
53
|
+
dy: z.number(),
|
|
54
|
+
color: z.string().optional(),
|
|
55
|
+
lineStyle: z.enum(["solid", "dashed", "dotted"]).optional(),
|
|
56
|
+
}),
|
|
57
|
+
});
|
|
58
|
+
const anyNodeSchema = z.union([
|
|
59
|
+
sysNodeSchema,
|
|
60
|
+
noteNodeSchema,
|
|
61
|
+
boundaryNodeSchema,
|
|
62
|
+
stepNodeSchema,
|
|
63
|
+
arrowNodeSchema,
|
|
64
|
+
]);
|
|
65
|
+
const edgeSchema = z.object({
|
|
66
|
+
id: z.string().min(1),
|
|
67
|
+
source: z.string().min(1),
|
|
68
|
+
target: z.string().min(1),
|
|
69
|
+
type: z.literal("sysEdge").catch("sysEdge"),
|
|
70
|
+
animated: z.boolean().optional(),
|
|
71
|
+
data: z
|
|
72
|
+
.object({
|
|
73
|
+
label: z.string().optional(),
|
|
74
|
+
protocol: z.string().optional(),
|
|
75
|
+
color: z.string().optional(),
|
|
76
|
+
customProperties: z.record(z.string(), z.string()).optional(),
|
|
77
|
+
})
|
|
78
|
+
.optional(),
|
|
79
|
+
});
|
|
80
|
+
const metaSchema = z
|
|
81
|
+
.object({
|
|
82
|
+
title: z.string().optional(),
|
|
83
|
+
lastModified: z.string().optional(),
|
|
84
|
+
viewMode: z.enum(["minimalist", "real"]).optional(),
|
|
85
|
+
nodeStyle: z.enum(["symbol", "card", "plate"]).optional(),
|
|
86
|
+
locked: z.boolean().optional(),
|
|
87
|
+
})
|
|
88
|
+
.catch({});
|
|
89
|
+
export const sysdrawFileSchema = z.object({
|
|
90
|
+
version: z.string(),
|
|
91
|
+
meta: metaSchema.default({}),
|
|
92
|
+
nodes: z.array(anyNodeSchema),
|
|
93
|
+
edges: z.array(edgeSchema),
|
|
94
|
+
});
|
|
95
|
+
export function serializeSysdraw(state) {
|
|
96
|
+
const sourceNodes = absolutizeAll(state.nodes);
|
|
97
|
+
const serializedNodes = sourceNodes.map((n) => {
|
|
98
|
+
if (n.type === "noteNode") {
|
|
99
|
+
return {
|
|
100
|
+
id: n.id,
|
|
101
|
+
type: "noteNode",
|
|
102
|
+
position: n.position,
|
|
103
|
+
data: {
|
|
104
|
+
text: n.data.text,
|
|
105
|
+
...(n.data.color !== undefined ? { color: n.data.color } : {}),
|
|
106
|
+
...(n.data.size !== undefined ? { size: n.data.size } : {}),
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
if (n.type === "boundaryNode") {
|
|
111
|
+
return {
|
|
112
|
+
id: n.id,
|
|
113
|
+
type: "boundaryNode",
|
|
114
|
+
position: n.position,
|
|
115
|
+
...(n.width !== undefined ? { width: n.width } : {}),
|
|
116
|
+
...(n.height !== undefined ? { height: n.height } : {}),
|
|
117
|
+
data: {
|
|
118
|
+
label: n.data.label,
|
|
119
|
+
...(n.data.color !== undefined ? { color: n.data.color } : {}),
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
if (n.type === "stepNode") {
|
|
124
|
+
const sn = n;
|
|
125
|
+
return {
|
|
126
|
+
id: sn.id,
|
|
127
|
+
type: "stepNode",
|
|
128
|
+
position: sn.position,
|
|
129
|
+
data: {
|
|
130
|
+
n: sn.data.n ?? 0,
|
|
131
|
+
...(sn.data.label !== undefined ? { label: sn.data.label } : {}),
|
|
132
|
+
...(sn.data.color !== undefined ? { color: sn.data.color } : {}),
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
if (n.type === "arrowNode") {
|
|
137
|
+
const an = n;
|
|
138
|
+
return {
|
|
139
|
+
id: an.id,
|
|
140
|
+
type: "arrowNode",
|
|
141
|
+
position: an.position,
|
|
142
|
+
data: {
|
|
143
|
+
dx: an.data.dx,
|
|
144
|
+
dy: an.data.dy,
|
|
145
|
+
...(an.data.color !== undefined ? { color: an.data.color } : {}),
|
|
146
|
+
...(an.data.lineStyle !== undefined
|
|
147
|
+
? { lineStyle: an.data.lineStyle }
|
|
148
|
+
: {}),
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
// sysNode
|
|
153
|
+
const sn = n;
|
|
154
|
+
return {
|
|
155
|
+
id: sn.id,
|
|
156
|
+
type: "sysNode",
|
|
157
|
+
position: sn.position,
|
|
158
|
+
data: {
|
|
159
|
+
archetype: sn.data.archetype,
|
|
160
|
+
concreteTool: sn.data.concreteTool,
|
|
161
|
+
label: sn.data.label,
|
|
162
|
+
...(sn.data.customProperties
|
|
163
|
+
? { customProperties: sn.data.customProperties }
|
|
164
|
+
: {}),
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
});
|
|
168
|
+
const file = {
|
|
169
|
+
version: SYSDRAW_VERSION,
|
|
170
|
+
meta: {
|
|
171
|
+
title: state.title ?? "architecture",
|
|
172
|
+
lastModified: new Date().toISOString(),
|
|
173
|
+
viewMode: state.viewMode,
|
|
174
|
+
nodeStyle: state.nodeStyle,
|
|
175
|
+
...(state.locked ? { locked: true } : {}),
|
|
176
|
+
},
|
|
177
|
+
nodes: serializedNodes,
|
|
178
|
+
edges: state.edges.map((e) => ({
|
|
179
|
+
id: e.id,
|
|
180
|
+
source: e.source,
|
|
181
|
+
target: e.target,
|
|
182
|
+
type: "sysEdge",
|
|
183
|
+
...(e.animated ? { animated: true } : {}),
|
|
184
|
+
data: {
|
|
185
|
+
...(e.data?.label !== undefined ? { label: e.data.label } : {}),
|
|
186
|
+
...(e.data?.protocol !== undefined
|
|
187
|
+
? { protocol: e.data.protocol }
|
|
188
|
+
: {}),
|
|
189
|
+
...(e.data?.color !== undefined ? { color: e.data.color } : {}),
|
|
190
|
+
...(e.data?.customProperties !== undefined
|
|
191
|
+
? { customProperties: e.data.customProperties }
|
|
192
|
+
: {}),
|
|
193
|
+
},
|
|
194
|
+
})),
|
|
195
|
+
};
|
|
196
|
+
return JSON.stringify(file, null, 2);
|
|
197
|
+
}
|
|
198
|
+
export function parseSysdraw(text) {
|
|
199
|
+
let json;
|
|
200
|
+
try {
|
|
201
|
+
json = JSON.parse(text);
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
return { ok: false, error: "File is not valid JSON." };
|
|
205
|
+
}
|
|
206
|
+
const result = sysdrawFileSchema.safeParse(json);
|
|
207
|
+
if (!result.success) {
|
|
208
|
+
const issue = result.error.issues[0];
|
|
209
|
+
return {
|
|
210
|
+
ok: false,
|
|
211
|
+
error: `Invalid file — ${issue.path.join(".") || "root"}: ${issue.message}`,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
return { ok: true, data: result.data };
|
|
215
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export type ViewMode = "minimalist" | "real";
|
|
2
|
+
export type NodeStyle = "symbol" | "card" | "plate";
|
|
3
|
+
export type LayoutDirection = "LR" | "TB";
|
|
4
|
+
export type SysNodeData = {
|
|
5
|
+
archetype: string;
|
|
6
|
+
concreteTool: string;
|
|
7
|
+
label: string;
|
|
8
|
+
customProperties?: Record<string, string>;
|
|
9
|
+
};
|
|
10
|
+
export type NoteNodeData = {
|
|
11
|
+
text: string;
|
|
12
|
+
color?: string;
|
|
13
|
+
size?: "small" | "normal" | "title";
|
|
14
|
+
};
|
|
15
|
+
export type BoundaryNodeData = {
|
|
16
|
+
label: string;
|
|
17
|
+
color?: string;
|
|
18
|
+
};
|
|
19
|
+
export type StepNodeData = {
|
|
20
|
+
n?: number;
|
|
21
|
+
label?: string;
|
|
22
|
+
color?: string;
|
|
23
|
+
};
|
|
24
|
+
export type ArrowNodeData = {
|
|
25
|
+
dx: number;
|
|
26
|
+
dy: number;
|
|
27
|
+
color?: string;
|
|
28
|
+
lineStyle?: "solid" | "dashed" | "dotted";
|
|
29
|
+
};
|
|
30
|
+
export type SysEdgeData = {
|
|
31
|
+
label?: string;
|
|
32
|
+
protocol?: string;
|
|
33
|
+
color?: string;
|
|
34
|
+
customProperties?: Record<string, string>;
|
|
35
|
+
};
|
|
36
|
+
type CoreNode<TData, TType extends string = string> = {
|
|
37
|
+
id: string;
|
|
38
|
+
type: TType;
|
|
39
|
+
position: {
|
|
40
|
+
x: number;
|
|
41
|
+
y: number;
|
|
42
|
+
};
|
|
43
|
+
data: TData;
|
|
44
|
+
parentId?: string;
|
|
45
|
+
width?: number;
|
|
46
|
+
height?: number;
|
|
47
|
+
measured?: {
|
|
48
|
+
width?: number;
|
|
49
|
+
height?: number;
|
|
50
|
+
};
|
|
51
|
+
zIndex?: number;
|
|
52
|
+
selected?: boolean;
|
|
53
|
+
};
|
|
54
|
+
export type SysNode = CoreNode<SysNodeData, "sysNode">;
|
|
55
|
+
export type NoteNode = CoreNode<NoteNodeData, "noteNode">;
|
|
56
|
+
export type BoundaryNode = CoreNode<BoundaryNodeData, "boundaryNode">;
|
|
57
|
+
export type StepNode = CoreNode<StepNodeData, "stepNode">;
|
|
58
|
+
export type ArrowNode = CoreNode<ArrowNodeData, "arrowNode">;
|
|
59
|
+
export type AppNode = SysNode | NoteNode | BoundaryNode | StepNode | ArrowNode;
|
|
60
|
+
export type SysEdge = {
|
|
61
|
+
id: string;
|
|
62
|
+
source: string;
|
|
63
|
+
target: string;
|
|
64
|
+
type?: string;
|
|
65
|
+
animated?: boolean;
|
|
66
|
+
selected?: boolean;
|
|
67
|
+
data?: SysEdgeData;
|
|
68
|
+
};
|
|
69
|
+
export {};
|
|
70
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,YAAY,GAAG,MAAM,CAAC;AAC7C,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AACpD,MAAM,MAAM,eAAe,GAAG,IAAI,GAAG,IAAI,CAAC;AAE1C,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C,CAAC;AAMF,KAAK,QAAQ,CAAC,KAAK,EAAE,KAAK,SAAS,MAAM,GAAG,MAAM,IAAI;IACpD,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,KAAK,CAAC;IACZ,QAAQ,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACnC,IAAI,EAAE,KAAK,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;AACvD,MAAM,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;AAC1D,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;AACtE,MAAM,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;AAC1D,MAAM,MAAM,SAAS,GAAG,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;AAC7D,MAAM,MAAM,OAAO,GAAG,OAAO,GAAG,QAAQ,GAAG,YAAY,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE/E,MAAM,MAAM,OAAO,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modudraft/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Modudraft scene model, shape ops, and serialization — no React",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -23,6 +23,9 @@
|
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"typescript": "~6.0.2"
|
|
25
25
|
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
26
29
|
"publishConfig": {
|
|
27
30
|
"access": "public"
|
|
28
31
|
}
|