@steffolino/diagram-kit-adapters 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Stefan Stretz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # @steffolino/diagram-kit-adapters
2
+
3
+ Turns an input format into a `@steffolino/diagram-kit-core` `DiagramGraph`.
4
+
5
+ ```ts
6
+ import { fromYaml, fromMermaid, fromArchitectureLandscape } from '@steffolino/diagram-kit-adapters'
7
+ // Node-only, at a separate subpath so browser bundles never pull in node:fs:
8
+ import { fromDirectory } from '@steffolino/diagram-kit-adapters/directory'
9
+ ```
10
+
11
+ - `fromYaml(source)` — hand-authored `{ nodes, edges }` YAML spec.
12
+ - `fromMermaid(source)` — a subset of Mermaid flowchart/graph syntax.
13
+ - `fromArchitectureLandscape(manifest)` — normalizes the JSON shape produced
14
+ by an external `ast`-module walker (bounded contexts, aggregates, routes,
15
+ cross-context import edges).
16
+ - `fromDirectory(rootPath, options)` — walks a directory tree into a
17
+ containment graph. Node-only.
18
+
19
+ Part of the diagram-kit monorepo. See the repo root README for the full
20
+ picture.
package/dist/ast.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ import type { DiagramGraph } from '@steffolino/diagram-kit-core';
2
+ /**
3
+ * Shape produced by a Python `ast`-module walker over a DDD-style backend
4
+ * (contexts with aggregates/routes/adapters/external systems, plus the
5
+ * real cross-context import graph). Field names are snake_case to match
6
+ * that JSON directly — this adapter is meant to consume the manifest
7
+ * as-is, not require a reshaping step in the extractor script.
8
+ *
9
+ * There is no bundled TypeScript/Python AST walker here yet: writing a
10
+ * generic one is real, separate work (see README). This adapter is the
11
+ * normalization half of that pipeline — point an external extractor's
12
+ * JSON output at `fromArchitectureLandscape` and it becomes a
13
+ * DiagramGraph like any other adapter's output.
14
+ */
15
+ export interface ArchitectureLandscapeManifest {
16
+ contexts: Record<string, {
17
+ layers: Record<string, number>;
18
+ aggregates: Array<{
19
+ name: string;
20
+ is_formal_aggregate_root: boolean;
21
+ }>;
22
+ routes: Array<{
23
+ method: string;
24
+ path: string;
25
+ }>;
26
+ adapters: Array<{
27
+ name: string;
28
+ kind: string;
29
+ }>;
30
+ external_systems: string[];
31
+ }>;
32
+ context_edges: Array<{
33
+ from: string;
34
+ to: string;
35
+ import_count: number;
36
+ }>;
37
+ }
38
+ export declare function fromArchitectureLandscape(manifest: ArchitectureLandscapeManifest): DiagramGraph;
39
+ //# sourceMappingURL=ast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,YAAY,EAAe,MAAM,8BAA8B,CAAA;AAG1F;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,EAAE,MAAM,CACd,MAAM,EACN;QACE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAC9B,UAAU,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,wBAAwB,EAAE,OAAO,CAAA;SAAE,CAAC,CAAA;QACtE,MAAM,EAAE,KAAK,CAAC;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;QAC/C,QAAQ,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;QAC/C,gBAAgB,EAAE,MAAM,EAAE,CAAA;KAC3B,CACF,CAAA;IACD,aAAa,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CACzE;AAED,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,6BAA6B,GAAG,YAAY,CAwB/F"}
package/dist/ast.js ADDED
@@ -0,0 +1,25 @@
1
+ import { createGraph, validateGraph } from '@steffolino/diagram-kit-core';
2
+ export function fromArchitectureLandscape(manifest) {
3
+ const nodes = Object.entries(manifest.contexts).map(([contextName, ctx]) => {
4
+ const hasWriteRepository = ctx.aggregates.some((a) => a.is_formal_aggregate_root);
5
+ return {
6
+ id: contextName,
7
+ label: contextName,
8
+ category: 'context',
9
+ badge: hasWriteRepository ? undefined : 'read-only',
10
+ detail: `${ctx.aggregates.length} aggregates, ${ctx.routes.length} routes, ${ctx.adapters.length} adapters`,
11
+ metadata: { externalSystems: ctx.external_systems },
12
+ };
13
+ });
14
+ const edges = manifest.context_edges.map((edge) => ({
15
+ id: `${edge.from}->${edge.to}`,
16
+ source: edge.from,
17
+ target: edge.to,
18
+ weight: edge.import_count,
19
+ kind: 'imports',
20
+ }));
21
+ const graph = createGraph(nodes, edges);
22
+ validateGraph(graph);
23
+ return graph;
24
+ }
25
+ //# sourceMappingURL=ast.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast.js","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AA6BzE,MAAM,UAAU,yBAAyB,CAAC,QAAuC;IAC/E,MAAM,KAAK,GAAkB,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,EAAE,EAAE;QACxF,MAAM,kBAAkB,GAAG,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAA;QACjF,OAAO;YACL,EAAE,EAAE,WAAW;YACf,KAAK,EAAE,WAAW;YAClB,QAAQ,EAAE,SAAS;YACnB,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW;YACnD,MAAM,EAAE,GAAG,GAAG,CAAC,UAAU,CAAC,MAAM,gBAAgB,GAAG,CAAC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,QAAQ,CAAC,MAAM,WAAW;YAC3G,QAAQ,EAAE,EAAE,eAAe,EAAE,GAAG,CAAC,gBAAgB,EAAE;SACpD,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,MAAM,KAAK,GAAkB,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACjE,EAAE,EAAE,GAAG,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,EAAE;QAC9B,MAAM,EAAE,IAAI,CAAC,IAAI;QACjB,MAAM,EAAE,IAAI,CAAC,EAAE;QACf,MAAM,EAAE,IAAI,CAAC,YAAY;QACzB,IAAI,EAAE,SAAS;KAChB,CAAC,CAAC,CAAA;IAEH,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IACvC,aAAa,CAAC,KAAK,CAAC,CAAA;IACpB,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { DiagramGraph } from '@steffolino/diagram-kit-core';
2
+ export interface DirectoryGraphOptions {
3
+ /** Directory/file names to skip entirely, e.g. node_modules, .git. */
4
+ ignore?: string[];
5
+ /** How many levels deep to walk. Default 4. */
6
+ maxDepth?: number;
7
+ /** Include files as leaf nodes, not just directories. Default true. */
8
+ includeFiles?: boolean;
9
+ }
10
+ /** Walks a directory tree and produces a containment graph (parentId + "contains" edges) for structure diagrams. */
11
+ export declare function fromDirectory(rootPath: string, options?: DirectoryGraphOptions): DiagramGraph;
12
+ //# sourceMappingURL=directory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directory.d.ts","sourceRoot":"","sources":["../src/directory.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAe,YAAY,EAAe,MAAM,8BAA8B,CAAA;AAG1F,MAAM,WAAW,qBAAqB;IACpC,sEAAsE;IACtE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,uEAAuE;IACvE,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAID,oHAAoH;AACpH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B,GAAG,YAAY,CAiDjG"}
@@ -0,0 +1,51 @@
1
+ // Node-only: reads the filesystem directly. Import from
2
+ // "@steffolino/diagram-kit-adapters/directory", not the package root, so this never
3
+ // ends up in a browser bundle.
4
+ import { readdirSync, statSync } from 'node:fs';
5
+ import { basename, join, relative } from 'node:path';
6
+ import { createGraph, validateGraph } from '@steffolino/diagram-kit-core';
7
+ const DEFAULT_IGNORE = ['node_modules', '.git', 'dist', 'build', '__pycache__', '.venv'];
8
+ /** Walks a directory tree and produces a containment graph (parentId + "contains" edges) for structure diagrams. */
9
+ export function fromDirectory(rootPath, options = {}) {
10
+ const ignore = new Set(options.ignore ?? DEFAULT_IGNORE);
11
+ const maxDepth = options.maxDepth ?? 4;
12
+ const includeFiles = options.includeFiles ?? true;
13
+ const nodes = [];
14
+ const edges = [];
15
+ function idFor(path) {
16
+ const rel = relative(rootPath, path);
17
+ return rel === '' ? '.' : rel.replace(/\\/g, '/');
18
+ }
19
+ function walk(path, depth, parentId) {
20
+ const id = idFor(path);
21
+ const stats = statSync(path);
22
+ const isDir = stats.isDirectory();
23
+ if (!isDir && !includeFiles)
24
+ return;
25
+ nodes.push({
26
+ id,
27
+ label: basename(path) || path,
28
+ category: isDir ? 'directory' : 'file',
29
+ parentId,
30
+ });
31
+ if (parentId !== undefined) {
32
+ edges.push({
33
+ id: `${parentId}->${id}`,
34
+ source: parentId,
35
+ target: id,
36
+ kind: 'contains',
37
+ });
38
+ }
39
+ if (isDir && depth < maxDepth) {
40
+ const entries = readdirSync(path).filter((entry) => !ignore.has(entry));
41
+ for (const entry of entries.sort()) {
42
+ walk(join(path, entry), depth + 1, id);
43
+ }
44
+ }
45
+ }
46
+ walk(rootPath, 0, undefined);
47
+ const graph = createGraph(nodes, edges);
48
+ validateGraph(graph);
49
+ return graph;
50
+ }
51
+ //# sourceMappingURL=directory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directory.js","sourceRoot":"","sources":["../src/directory.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,oFAAoF;AACpF,+BAA+B;AAC/B,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAWzE,MAAM,cAAc,GAAG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T,EAAE,EAAE,GAAG,QAAQ,KAAK,EAAE,EAAE;gBACxB,MAAM,EAAE,QAAQ;gBAChB,MAAM,EAAE,EAAE;gBACV,IAAI,EAAE,UAAU;aACjB,CAAC,CAAA;QACJ,CAAC;QAED,IAAI,KAAK,IAAI,KAAK,GAAG,QAAQ,EAAE,CAAC;YAC9B,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA;YACvE,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;gBACnC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,EAAE,CAAC,CAAA;YACxC,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,SAAS,CAAC,CAAA;IAE5B,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IACvC,aAAa,CAAC,KAAK,CAAC,CAAA;IACpB,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { DiagramGraph } from '@steffolino/diagram-kit-core';
2
+ /**
3
+ * Hand-authored graph spec shape shared by the YAML and JSON adapters —
4
+ * the same data, just two different textual encodings of it.
5
+ */
6
+ export interface GraphSpec {
7
+ nodes: Array<{
8
+ id: string;
9
+ label?: string;
10
+ detail?: string;
11
+ category?: string;
12
+ badge?: string;
13
+ parent?: string;
14
+ shape?: 'rect' | 'cylinder';
15
+ borderStyle?: 'solid' | 'dashed';
16
+ }>;
17
+ edges?: Array<{
18
+ from: string;
19
+ to: string;
20
+ label?: string;
21
+ weight?: number;
22
+ kind?: string;
23
+ projected?: boolean;
24
+ style?: 'line' | 'block';
25
+ }>;
26
+ }
27
+ export declare function graphFromSpec(spec: GraphSpec, sourceLabel: string): DiagramGraph;
28
+ //# sourceMappingURL=graphSpec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphSpec.d.ts","sourceRoot":"","sources":["../src/graphSpec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,YAAY,EAAe,MAAM,8BAA8B,CAAA;AAG1F;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,KAAK,CAAC;QACX,EAAE,EAAE,MAAM,CAAA;QACV,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,KAAK,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;QAC3B,WAAW,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAA;KACjC,CAAC,CAAA;IACF,KAAK,CAAC,EAAE,KAAK,CAAC;QACZ,IAAI,EAAE,MAAM,CAAA;QACZ,EAAE,EAAE,MAAM,CAAA;QACV,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,SAAS,CAAC,EAAE,OAAO,CAAA;QACnB,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;KACzB,CAAC,CAAA;CACH;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,GAAG,YAAY,CA8BhF"}
@@ -0,0 +1,30 @@
1
+ import { createGraph, validateGraph } from '@steffolino/diagram-kit-core';
2
+ export function graphFromSpec(spec, sourceLabel) {
3
+ if (!spec || !Array.isArray(spec.nodes)) {
4
+ throw new Error(`${sourceLabel} graph spec must have a top-level "nodes" list`);
5
+ }
6
+ const nodes = spec.nodes.map((n) => ({
7
+ id: n.id,
8
+ label: n.label ?? n.id,
9
+ detail: n.detail,
10
+ category: n.category,
11
+ badge: n.badge,
12
+ parentId: n.parent,
13
+ shape: n.shape,
14
+ borderStyle: n.borderStyle,
15
+ }));
16
+ const edges = (spec.edges ?? []).map((e, i) => ({
17
+ id: `${e.from}->${e.to}#${i}`,
18
+ source: e.from,
19
+ target: e.to,
20
+ label: e.label,
21
+ weight: e.weight,
22
+ kind: e.kind,
23
+ projected: e.projected,
24
+ style: e.style,
25
+ }));
26
+ const graph = createGraph(nodes, edges);
27
+ validateGraph(graph);
28
+ return graph;
29
+ }
30
+ //# sourceMappingURL=graphSpec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphSpec.js","sourceRoot":"","sources":["../src/graphSpec.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AA4BzE,MAAM,UAAU,aAAa,CAAC,IAAe,EAAE,WAAmB;IAChE,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,GAAG,WAAW,gDAAgD,CAAC,CAAA;IACjF,CAAC;IAED,MAAM,KAAK,GAAkB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAClD,EAAE,EAAE,CAAC,CAAC,EAAE;QACR,KAAK,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,EAAE;QACtB,MAAM,EAAE,CAAC,CAAC,MAAM;QAChB,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,KAAK,EAAE,CAAC,CAAC,KAAK;QACd,QAAQ,EAAE,CAAC,CAAC,MAAM;QAClB,KAAK,EAAE,CAAC,CAAC,KAAK;QACd,WAAW,EAAE,CAAC,CAAC,WAAW;KAC3B,CAAC,CAAC,CAAA;IAEH,MAAM,KAAK,GAAkB,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QAC7D,EAAE,EAAE,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE;QAC7B,MAAM,EAAE,CAAC,CAAC,IAAI;QACd,MAAM,EAAE,CAAC,CAAC,EAAE;QACZ,KAAK,EAAE,CAAC,CAAC,KAAK;QACd,MAAM,EAAE,CAAC,CAAC,MAAM;QAChB,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,SAAS,EAAE,CAAC,CAAC,SAAS;QACtB,KAAK,EAAE,CAAC,CAAC,KAAK;KACf,CAAC,CAAC,CAAA;IAEH,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IACvC,aAAa,CAAC,KAAK,CAAC,CAAA;IACpB,OAAO,KAAK,CAAA;AACd,CAAC"}
@@ -0,0 +1,10 @@
1
+ export { fromYaml } from './yaml.js';
2
+ export type { YamlGraphSpec } from './yaml.js';
3
+ export { fromJson } from './json.js';
4
+ export type { JsonGraphSpec } from './json.js';
5
+ export { fromTree, fromTreeText } from './tree.js';
6
+ export type { TreeNodeInput } from './tree.js';
7
+ export { fromMermaid } from './mermaid.js';
8
+ export { fromArchitectureLandscape } from './ast.js';
9
+ export type { ArchitectureLandscapeManifest } from './ast.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAClD,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAA;AACpD,YAAY,EAAE,6BAA6B,EAAE,MAAM,UAAU,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ // Browser-safe adapters only. `fromDirectory` uses node:fs and lives at the
2
+ // "@steffolino/diagram-kit-adapters/directory" subpath so bundling this root import
3
+ // into a browser build never pulls in Node built-ins.
4
+ export { fromYaml } from './yaml.js';
5
+ export { fromJson } from './json.js';
6
+ export { fromTree, fromTreeText } from './tree.js';
7
+ export { fromMermaid } from './mermaid.js';
8
+ export { fromArchitectureLandscape } from './ast.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,oFAAoF;AACpF,sDAAsD;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAElD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAA"}
package/dist/json.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import type { DiagramGraph } from '@steffolino/diagram-kit-core';
2
+ import { type GraphSpec } from './graphSpec.js';
3
+ /**
4
+ * Same spec shape as `fromYaml`, just JSON instead of YAML:
5
+ *
6
+ * ```json
7
+ * {
8
+ * "nodes": [
9
+ * { "id": "api", "label": "API", "category": "presentation" },
10
+ * { "id": "domain", "label": "Domain", "category": "core" }
11
+ * ],
12
+ * "edges": [{ "from": "api", "to": "domain", "label": "calls" }]
13
+ * }
14
+ * ```
15
+ *
16
+ * A separate adapter (rather than routing JSON through `fromYaml`'s YAML
17
+ * parser, which happens to accept JSON as a subset) so a malformed-JSON
18
+ * error reads as a JSON syntax error, not a confusing YAML one.
19
+ */
20
+ export type JsonGraphSpec = GraphSpec;
21
+ export declare function fromJson(source: string): DiagramGraph;
22
+ //# sourceMappingURL=json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAChE,OAAO,EAAE,KAAK,SAAS,EAAiB,MAAM,gBAAgB,CAAA;AAE9D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS,CAAA;AAErC,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAQrD"}
package/dist/json.js ADDED
@@ -0,0 +1,12 @@
1
+ import { graphFromSpec } from './graphSpec.js';
2
+ export function fromJson(source) {
3
+ let spec;
4
+ try {
5
+ spec = JSON.parse(source);
6
+ }
7
+ catch (e) {
8
+ throw new Error(`Invalid JSON: ${e instanceof Error ? e.message : String(e)}`);
9
+ }
10
+ return graphFromSpec(spec, 'JSON');
11
+ }
12
+ //# sourceMappingURL=json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.js","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAqB9D,MAAM,UAAU,QAAQ,CAAC,MAAc;IACrC,IAAI,IAAe,CAAA;IACnB,IAAI,CAAC;QACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAc,CAAA;IACxC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;IAChF,CAAC;IACD,OAAO,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;AACpC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { DiagramGraph } from '@steffolino/diagram-kit-core';
2
+ export declare function fromMermaid(source: string): DiagramGraph;
3
+ //# sourceMappingURL=mermaid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mermaid.d.ts","sourceRoot":"","sources":["../src/mermaid.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,YAAY,EAAe,MAAM,8BAA8B,CAAA;AAgC1F,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAoDxD"}
@@ -0,0 +1,79 @@
1
+ import { createGraph, validateGraph } from '@steffolino/diagram-kit-core';
2
+ /**
3
+ * Parses a subset of Mermaid flowchart/graph syntax into a normalized graph
4
+ * so it can be re-rendered with diagram-kit's own layout and theming
5
+ * instead of Mermaid's default styling.
6
+ *
7
+ * Supported:
8
+ * flowchart TD | graph LR ...
9
+ * id[Label] / id(Label) / id{Label} / id((Label)) / id (bare)
10
+ * A --> B | A --- B | A -.-> B | A ==> B
11
+ * A -->|label| B | A -- label --> B
12
+ *
13
+ * Not supported (throws or ignores): subgraphs, styling directives,
14
+ * click/callback bindings, class defs. Treat this as "parse a diagram
15
+ * someone wrote by hand", not a full Mermaid-spec implementation.
16
+ */
17
+ const NODE_SHAPE_PATTERN = /^([A-Za-z0-9_-]+)(?:(\[)([^\]]*)\]|(\()([^)]*)\)|(\{)([^}]*)\})?$/;
18
+ const EDGE_PATTERN = /^(.+?)\s*(-->|---|-\.->|==>)\s*(?:\|([^|]*)\|\s*)?(.+)$/;
19
+ const INLINE_LABEL_EDGE_PATTERN = /^(.+?)\s*--\s*(.+?)\s*-->\s*(.+)$/;
20
+ function parseNodeToken(token) {
21
+ const match = NODE_SHAPE_PATTERN.exec(token.trim());
22
+ if (!match)
23
+ return { id: token.trim() };
24
+ const id = match[1];
25
+ const label = match[3] ?? match[5] ?? match[7];
26
+ return { id, label };
27
+ }
28
+ export function fromMermaid(source) {
29
+ const nodesById = new Map();
30
+ const edges = [];
31
+ let edgeCounter = 0;
32
+ const ensureNode = (id, label) => {
33
+ const existing = nodesById.get(id);
34
+ if (existing) {
35
+ if (label && existing.label === existing.id)
36
+ existing.label = label;
37
+ return;
38
+ }
39
+ nodesById.set(id, { id, label: label ?? id });
40
+ };
41
+ const lines = source
42
+ .split('\n')
43
+ .map((line) => line.trim())
44
+ .filter((line) => line.length > 0 && !line.startsWith('%%'));
45
+ for (const line of lines) {
46
+ if (/^(flowchart|graph)\s+/i.test(line))
47
+ continue;
48
+ if (/^(subgraph|end|classDef|class|click|style)\b/i.test(line))
49
+ continue;
50
+ const inlineLabelMatch = INLINE_LABEL_EDGE_PATTERN.exec(line);
51
+ const plainEdgeMatch = inlineLabelMatch ? null : EDGE_PATTERN.exec(line);
52
+ if (inlineLabelMatch || plainEdgeMatch) {
53
+ // The two patterns capture different group shapes (inline: left,
54
+ // label, right — plain: left, op, label, right), so each needs its
55
+ // own destructuring rather than sharing one positional unpack.
56
+ const [left, label, right] = inlineLabelMatch
57
+ ? [inlineLabelMatch[1], inlineLabelMatch[2], inlineLabelMatch[3]]
58
+ : [plainEdgeMatch[1], plainEdgeMatch[3], plainEdgeMatch[4]];
59
+ const from = parseNodeToken(left);
60
+ const to = parseNodeToken(right);
61
+ ensureNode(from.id, from.label);
62
+ ensureNode(to.id, to.label);
63
+ edges.push({
64
+ id: `mermaid-edge-${edgeCounter++}`,
65
+ source: from.id,
66
+ target: to.id,
67
+ label: label || undefined,
68
+ });
69
+ continue;
70
+ }
71
+ const bare = parseNodeToken(line);
72
+ if (bare.id)
73
+ ensureNode(bare.id, bare.label);
74
+ }
75
+ const graph = createGraph(Array.from(nodesById.values()), edges);
76
+ validateGraph(graph);
77
+ return graph;
78
+ }
79
+ //# sourceMappingURL=mermaid.js.map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CAAA;YAChC,UAAU,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;YAC/B,UAAU,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,CAAA;YAC3B,KAAK,CAAC,IAAI,CAAC;gBACT,EAAE,EAAE,gBAAgB,WAAW,EAAE,EAAE;gBACnC,MAAM,EAAE,IAAI,CAAC,EAAE;gBACf,MAAM,EAAE,EAAE,CAAC,EAAE;gBACb,KAAK,EAAE,KAAK,IAAI,SAAS;aAC1B,CAAC,CAAA;YACF,SAAQ;QACV,CAAC;QAED,MAAM,IAAI,GAAG,cAAc,CAAC,IAAI,CAAC,CAAA;QACjC,IAAI,IAAI,CAAC,EAAE;YAAE,UAAU,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;IAC9C,CAAC;IAED,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,CAAC,CAAA;IAChE,aAAa,CAAC,KAAK,CAAC,CAAA;IACpB,OAAO,KAAK,CAAA;AACd,CAAC"}
package/dist/tree.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ import type { DiagramGraph } from '@steffolino/diagram-kit-core';
2
+ export interface TreeNodeInput {
3
+ /** Defaults to a slug of the path from the root if omitted. */
4
+ id?: string;
5
+ label: string;
6
+ detail?: string;
7
+ category?: string;
8
+ badge?: string;
9
+ shape?: 'rect' | 'cylinder';
10
+ borderStyle?: 'solid' | 'dashed';
11
+ children?: TreeNodeInput[];
12
+ }
13
+ /**
14
+ * Flattens a nested `{ label, children }` tree — the shape most JS tree
15
+ * data (a file-explorer model, a `d3.hierarchy` source, a JSON export of
16
+ * an org chart) already comes in — into a normalized graph with
17
+ * `parentId` containment and zero edges. Pair with `layoutMode:
18
+ * "structural"` or `"stack"`; a "graph" layout would just show every node
19
+ * floating disconnected, since trees-as-input produce no edges.
20
+ */
21
+ export declare function fromTree(root: TreeNodeInput | TreeNodeInput[]): DiagramGraph;
22
+ /**
23
+ * Parses the classic `tree` CLI's box-drawing output (├──/└──/│) into the
24
+ * same nested shape `fromTree` consumes. Falls back to counting plain
25
+ * leading whitespace (auto-detecting the indent unit from the first
26
+ * indented line) for a simple indented list with no box-drawing
27
+ * characters at all.
28
+ */
29
+ export declare function fromTreeText(source: string): DiagramGraph;
30
+ //# sourceMappingURL=tree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["../src/tree.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAe,MAAM,8BAA8B,CAAA;AAG7E,MAAM,WAAW,aAAa;IAC5B,+DAA+D;IAC/D,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;IAC3B,WAAW,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAA;IAChC,QAAQ,CAAC,EAAE,aAAa,EAAE,CAAA;CAC3B;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,aAAa,GAAG,aAAa,EAAE,GAAG,YAAY,CAyC5E;AAUD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CA+DzD"}
package/dist/tree.js ADDED
@@ -0,0 +1,115 @@
1
+ import { createGraph, validateGraph } from '@steffolino/diagram-kit-core';
2
+ /**
3
+ * Flattens a nested `{ label, children }` tree — the shape most JS tree
4
+ * data (a file-explorer model, a `d3.hierarchy` source, a JSON export of
5
+ * an org chart) already comes in — into a normalized graph with
6
+ * `parentId` containment and zero edges. Pair with `layoutMode:
7
+ * "structural"` or `"stack"`; a "graph" layout would just show every node
8
+ * floating disconnected, since trees-as-input produce no edges.
9
+ */
10
+ export function fromTree(root) {
11
+ const roots = Array.isArray(root) ? root : [root];
12
+ const nodes = [];
13
+ const usedIds = new Set();
14
+ function slug(pathParts) {
15
+ const base = pathParts.join('/').toLowerCase().replace(/[^a-z0-9/]+/g, '-');
16
+ let id = base;
17
+ let i = 2;
18
+ while (usedIds.has(id)) {
19
+ id = `${base}#${i++}`;
20
+ }
21
+ return id;
22
+ }
23
+ function visit(input, pathParts, parentId) {
24
+ const path = [...pathParts, input.label];
25
+ const id = input.id ?? slug(path);
26
+ usedIds.add(id);
27
+ nodes.push({
28
+ id,
29
+ label: input.label,
30
+ detail: input.detail,
31
+ category: input.category,
32
+ badge: input.badge,
33
+ shape: input.shape,
34
+ borderStyle: input.borderStyle,
35
+ parentId,
36
+ });
37
+ for (const child of input.children ?? []) {
38
+ visit(child, path, id);
39
+ }
40
+ }
41
+ for (const r of roots)
42
+ visit(r, [], undefined);
43
+ const graph = createGraph(nodes, []);
44
+ validateGraph(graph);
45
+ return graph;
46
+ }
47
+ const BRANCH = /^(├── |└── )/;
48
+ const CONTINUATION = /^(│ | )/;
49
+ function stripAnsi(line) {
50
+ // eslint-disable-next-line no-control-regex
51
+ return line.replace(/\x1b\[[0-9;]*m/g, '');
52
+ }
53
+ /**
54
+ * Parses the classic `tree` CLI's box-drawing output (├──/└──/│) into the
55
+ * same nested shape `fromTree` consumes. Falls back to counting plain
56
+ * leading whitespace (auto-detecting the indent unit from the first
57
+ * indented line) for a simple indented list with no box-drawing
58
+ * characters at all.
59
+ */
60
+ export function fromTreeText(source) {
61
+ const lines = source
62
+ .split('\n')
63
+ .map(stripAnsi)
64
+ .map((l) => l.replace(/\r$/, ''))
65
+ .filter((l) => l.trim().length > 0);
66
+ const usesBoxDrawing = lines.some((l) => BRANCH.test(l) || l.startsWith('│'));
67
+ let entries;
68
+ if (usesBoxDrawing) {
69
+ entries = lines.map((line) => {
70
+ let rest = line;
71
+ let depth = 0;
72
+ for (;;) {
73
+ if (BRANCH.test(rest)) {
74
+ rest = rest.replace(BRANCH, '');
75
+ depth += 1;
76
+ break;
77
+ }
78
+ if (CONTINUATION.test(rest)) {
79
+ rest = rest.replace(CONTINUATION, '');
80
+ depth += 1;
81
+ continue;
82
+ }
83
+ break;
84
+ }
85
+ return { depth, label: rest.trim() };
86
+ });
87
+ }
88
+ else {
89
+ const indents = lines
90
+ .map((l) => l.length - l.trimStart().length)
91
+ .filter((n) => n > 0);
92
+ const unit = indents.length > 0 ? Math.min(...indents) : 2;
93
+ entries = lines.map((line) => {
94
+ const leading = line.length - line.trimStart().length;
95
+ return { depth: Math.round(leading / unit), label: line.trim() };
96
+ });
97
+ }
98
+ const roots = [];
99
+ const stack = [];
100
+ for (const entry of entries) {
101
+ const node = { label: entry.label, children: [] };
102
+ while (stack.length > 0 && stack[stack.length - 1].depth >= entry.depth) {
103
+ stack.pop();
104
+ }
105
+ if (stack.length === 0) {
106
+ roots.push(node);
107
+ }
108
+ else {
109
+ stack[stack.length - 1].node.children.push(node);
110
+ }
111
+ stack.push({ depth: entry.depth, node });
112
+ }
113
+ return fromTree(roots);
114
+ }
115
+ //# sourceMappingURL=tree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree.js","sourceRoot":"","sources":["../src/tree.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAczE;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAqC;IAC5D,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;IACjD,MAAM,KAAK,GAAkB,EAAE,CAAA;IAC/B,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAA;IAEjC,SAAS,IAAI,CAAC,SAAmB;QAC/B,MAAM,IAAI,GAAG,S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AAC,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YACzE,KAAK,CAAC,GAAG,EAAE,CAAA;QACb,CAAC;QACD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAClB,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC,IAAI,CAAC,QAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACpD,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;IAC1C,CAAC;IAED,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAA;AACxB,CAAC"}
package/dist/yaml.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import type { DiagramGraph } from '@steffolino/diagram-kit-core';
2
+ import { type GraphSpec } from './graphSpec.js';
3
+ /**
4
+ * Hand-authored graph spec, e.g.:
5
+ *
6
+ * ```yaml
7
+ * nodes:
8
+ * - id: api
9
+ * label: API
10
+ * category: presentation
11
+ * - id: domain
12
+ * label: Domain
13
+ * category: core
14
+ * edges:
15
+ * - from: api
16
+ * to: domain
17
+ * label: calls
18
+ * ```
19
+ */
20
+ export type YamlGraphSpec = GraphSpec;
21
+ export declare function fromYaml(source: string): DiagramGraph;
22
+ //# sourceMappingURL=yaml.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yaml.d.ts","sourceRoot":"","sources":["../src/yaml.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAChE,OAAO,EAAE,KAAK,SAAS,EAAiB,MAAM,gBAAgB,CAAA;AAE9D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS,CAAA;AAErC,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAGrD"}
package/dist/yaml.js ADDED
@@ -0,0 +1,7 @@
1
+ import { parse } from 'yaml';
2
+ import { graphFromSpec } from './graphSpec.js';
3
+ export function fromYaml(source) {
4
+ const spec = parse(source);
5
+ return graphFromSpec(spec, 'YAML');
6
+ }
7
+ //# sourceMappingURL=yaml.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yaml.js","sourceRoot":"","sources":["../src/yaml.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAA;AAE5B,OAAO,EAAkB,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAqB9D,MAAM,UAAU,QAAQ,CAAC,MAAc;IACrC,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAc,CAAA;IACvC,OAAO,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;AACpC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@steffolino/diagram-kit-adapters",
3
+ "version": "0.1.0",
4
+ "description": "Input adapters (YAML, directory tree, Mermaid subset, source AST) that produce a normalized @steffolino/diagram-kit-core graph.",
5
+ "license": "MIT",
6
+ "author": "Stefan Stretz",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/steffolino/diagram-kit.git",
10
+ "directory": "packages/adapters"
11
+ },
12
+ "homepage": "https://github.com/steffolino/diagram-kit/tree/master/packages/adapters#readme",
13
+ "bugs": "https://github.com/steffolino/diagram-kit/issues",
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "keywords": [
18
+ "diagram",
19
+ "yaml",
20
+ "mermaid",
21
+ "architecture",
22
+ "adapter"
23
+ ],
24
+ "type": "module",
25
+ "sideEffects": false,
26
+ "main": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "default": "./dist/index.js"
32
+ },
33
+ "./directory": {
34
+ "types": "./dist/directory.d.ts",
35
+ "default": "./dist/directory.js"
36
+ }
37
+ },
38
+ "files": [
39
+ "dist",
40
+ "README.md"
41
+ ],
42
+ "dependencies": {
43
+ "yaml": "^2.6.1",
44
+ "@steffolino/diagram-kit-core": "0.1.0"
45
+ },
46
+ "devDependencies": {
47
+ "@types/node": "^22.10.0",
48
+ "typescript": "^5.7.2"
49
+ },
50
+ "scripts": {
51
+ "build": "tsc -p tsconfig.json",
52
+ "dev": "tsc -p tsconfig.json --watch --preserveWatchOutput",
53
+ "typecheck": "tsc -p tsconfig.json --noEmit"
54
+ }
55
+ }