@skydesign/tf 0.2.2

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,182 @@
1
+ import * as d3_2 from 'd3';
2
+
3
+ declare interface DrawOp {
4
+ op: string;
5
+ grad?: string;
6
+ color?: string;
7
+ points?: number[][];
8
+ rect?: number[];
9
+ pt?: number[];
10
+ align?: string;
11
+ width?: number;
12
+ size?: number;
13
+ face?: string;
14
+ text?: string;
15
+ style?: string;
16
+ }
17
+
18
+ /**
19
+ * Lightweight edge metadata returned to consumers after rendering.
20
+ * Provides the essential identifiers needed for edge navigation.
21
+ */
22
+ declare interface EdgeInfo {
23
+ /** Internal Graphviz ID */
24
+ id: number;
25
+ /** Edge index from EdgeContent (used for selection and navigation) */
26
+ index: number;
27
+ /** Source node name */
28
+ sourceNodeId: string;
29
+ /** Target node name */
30
+ targetNodeId: string;
31
+ /** Displayable label text (null if no label) */
32
+ label: string | null;
33
+ }
34
+
35
+ declare interface GraphvizJson {
36
+ name: string;
37
+ directed: boolean;
38
+ strict: boolean;
39
+ bb?: string;
40
+ objects?: GraphvizObject[];
41
+ edges?: GraphvizObject[];
42
+ }
43
+
44
+ declare interface GraphvizObject {
45
+ _gvid: number;
46
+ name: string;
47
+ _draw_?: DrawOp[];
48
+ _ldraw_?: DrawOp[];
49
+ _hdraw_?: DrawOp[];
50
+ _tdraw_?: DrawOp[];
51
+ bb?: string;
52
+ pos?: string;
53
+ width?: string;
54
+ height?: string;
55
+ label?: string;
56
+ head?: number;
57
+ tail?: number;
58
+ }
59
+
60
+ /**
61
+ * Render graph using custom SVG based on Graphviz JSON output
62
+ * @param maxDepth - Edge depth to filter by (null = show all)
63
+ * @param includeLesserDepths - If true, show depth <= maxDepth; if false, show only exact depth
64
+ * @param config - Layout configuration
65
+ * @returns Object containing zoom behavior and SVG references for imperative control
66
+ */
67
+ /** Pan/zoom transform: g = translate(x,y) scale(k). */
68
+ declare interface InitialTransform {
69
+ x: number;
70
+ y: number;
71
+ k: number;
72
+ }
73
+
74
+ /**
75
+ * Layout configuration for the Graphviz custom layout renderer.
76
+ * All layout-related constants are consolidated here for easy customization.
77
+ */
78
+ declare interface LayoutConfig {
79
+ /** Horizontal extension at start/end of edges (in pixels) */
80
+ horizontalExtension: number;
81
+ /** Minimum distance between edge midY values (in pixels) */
82
+ minEdgeDistance: number;
83
+ /** Threshold for skipping vertical segments (in pixels) */
84
+ minVerticalSegment: number;
85
+ /** Radius for self-loop edges (in pixels) */
86
+ loopRadius: number;
87
+ /** Spacing between edges (in pixels) */
88
+ edgeSpacing: number;
89
+ /** Corner radius for edge paths (in pixels) */
90
+ cornerRadius: number;
91
+ /** Width of arrowhead (in pixels) */
92
+ arrowWidth: number;
93
+ /** Height of arrowhead (in pixels) */
94
+ arrowHeight: number;
95
+ /** Extra height for edge labels (in pixels) */
96
+ labelHeight: number;
97
+ /** Font size for edge labels (in pixels) */
98
+ labelFontSize: number;
99
+ /** Padding around label text (in pixels) */
100
+ labelPadding: number;
101
+ /** Corner radius for label background (in pixels) */
102
+ labelCornerRadius: number;
103
+ /** Spacing between nodes (in pixels) */
104
+ nodeSpacing: number;
105
+ /** Threshold for considering edges as nearly horizontal (in pixels) */
106
+ nearlyHorizontalThreshold: number;
107
+ /** Threshold for nearly aligned edges in 3seg path (in pixels) */
108
+ nearlyAlignedThreshold: number;
109
+ }
110
+
111
+ /**
112
+ * Run graphviz layout in Node (no Web Worker). Same call the worker makes:
113
+ * `graphviz.layout(dot, "json", "dot")`. Deterministic for a given dot + wasm
114
+ * version, so server and client layouts match.
115
+ */
116
+ export declare function layoutDot(dot: string): Promise<GraphvizJson>;
117
+
118
+ declare interface NodeMapping {
119
+ sourceNodeId: string;
120
+ targetNodeId: string;
121
+ }
122
+
123
+ declare type NodeMappingArg = Parameters<typeof renderCustomGraph>[2];
124
+
125
+ declare function renderCustomGraph(container: HTMLDivElement, json: GraphvizJson, _nodeMapping?: Record<string, NodeMapping>, maxDepth?: number | null, includeLesserDepths?: boolean, config?: LayoutConfig, useOrthogonalRendering?: boolean, svgFontSize?: number, debug?: boolean, selectedEdgeId?: number | null, onEdgeSelect?: (edgeIndex: number | null) => void, nodeWidth?: number, nodeHeight?: number, nodeColumnSpacing?: number, enableWheelZoom?: boolean, extra?: RenderExtraOptions): {
126
+ zoomBehavior: d3_2.ZoomBehavior<SVGSVGElement, unknown>;
127
+ svgElement: SVGSVGElement;
128
+ gElement: SVGGElement;
129
+ baseFontSize: number;
130
+ viewBoxWidth: number;
131
+ edges: EdgeInfo[];
132
+ initialTransform: InitialTransform;
133
+ };
134
+
135
+ /** Convenience: dot string → static SVG string (layout + render in one call). */
136
+ export declare function renderDotToString(dot: string, opts?: RenderToStringOptions): Promise<RenderToStringResult>;
137
+
138
+ declare interface RenderExtraOptions {
139
+ /**
140
+ * Headless (Node / SSR) mode. Skips the d3-zoom attachment and never calls
141
+ * `getBBox`/`getComputedTextLength`; bakes a deterministic initial transform
142
+ * straight onto `<g>` so the SVG can be serialized to a string. Geometry is
143
+ * fully determined by the graphviz JSON, so it matches the browser render.
144
+ */
145
+ headless?: boolean;
146
+ /**
147
+ * Use this exact initial transform instead of measuring the fit via
148
+ * `getBBox`. Pass the `initialTransform` returned from a headless render so
149
+ * the hydrated interactive graph lines up with the SSR'd SVG pixel-for-pixel
150
+ * (no jump on handover). When omitted in non-headless mode, the legacy
151
+ * getBBox-based fit is used (unchanged behavior for existing callers).
152
+ */
153
+ initialTransform?: InitialTransform;
154
+ }
155
+
156
+ /**
157
+ * Render a graphviz layout JSON to a static SVG string (headless).
158
+ * Arguments mirror how `GraphvizRenderer` calls `renderCustomGraph`, so the
159
+ * output matches the browser render.
160
+ */
161
+ export declare function renderToString(json: GraphvizJson, opts?: RenderToStringOptions): RenderToStringResult;
162
+
163
+ export declare interface RenderToStringOptions {
164
+ nodeMapping?: NodeMappingArg;
165
+ layoutConfig?: LayoutConfig;
166
+ /** Base font size; the renderer also lifts it to the max `_ldraw_` size in the JSON (matches GraphvizRenderer). */
167
+ svgFontSize?: number;
168
+ nodeWidth?: number;
169
+ nodeHeight?: number;
170
+ nodeColumnSpacing?: number;
171
+ }
172
+
173
+ export declare interface RenderToStringResult {
174
+ /** Serialized `<svg>…</svg>` markup, ready to inline into HTML. */
175
+ svg: string;
176
+ /** Pass to the client `GraphvizRenderer`'s `initialTransform` prop for no-jump hydration. */
177
+ initialTransform: InitialTransform;
178
+ viewBoxWidth: number;
179
+ edges: EdgeInfo[];
180
+ }
181
+
182
+ export { }