nicevg 0.21.0 → 0.22.1
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.d.ts +12 -0
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/native/darwin-arm64/libnicevg_ffi.dylib +0 -0
- package/native/darwin-x64/libnicevg_ffi.dylib +0 -0
- package/native/linux-arm64/libnicevg_ffi.so +0 -0
- package/native/linux-x64/libnicevg_ffi.so +0 -0
- package/native/win32-x64/nicevg_ffi.dll +0 -0
- package/package.json +1 -1
- package/src/index.ts +18 -1
package/dist/index.d.ts
CHANGED
|
@@ -41,7 +41,9 @@ export interface Bounds {
|
|
|
41
41
|
* apart by their `from` and `to`.
|
|
42
42
|
*/
|
|
43
43
|
export interface SketchConnector {
|
|
44
|
+
/** The node it leaves, or `"node.port"` for a port its style marks `data-port`. */
|
|
44
45
|
from: string;
|
|
46
|
+
/** The node it reaches, or `"node.port"`. */
|
|
45
47
|
to: string;
|
|
46
48
|
points?: Point[];
|
|
47
49
|
/** Its text, lines split at `\n`, placed beside it. */
|
|
@@ -102,6 +104,12 @@ export interface DiagramNode {
|
|
|
102
104
|
allowOverlap?: boolean;
|
|
103
105
|
/** Drawn by a style: its texts are kept clear of, but not checked to fit. */
|
|
104
106
|
custom?: boolean;
|
|
107
|
+
/** The points its style marks `data-port`, each facing out of the side it lies on. */
|
|
108
|
+
ports?: {
|
|
109
|
+
name: string;
|
|
110
|
+
point: Point;
|
|
111
|
+
side: "top" | "right" | "bottom" | "left";
|
|
112
|
+
}[];
|
|
105
113
|
}
|
|
106
114
|
export interface DiagramConnector {
|
|
107
115
|
/** Its id in an SVG; a sketch's connectors get one for their labels to refer to. */
|
|
@@ -109,6 +117,10 @@ export interface DiagramConnector {
|
|
|
109
117
|
from: string;
|
|
110
118
|
to: string;
|
|
111
119
|
points: Point[];
|
|
120
|
+
/** The port of `from` it leaves, when it names one. */
|
|
121
|
+
fromPort?: string;
|
|
122
|
+
/** The port of `to` it reaches, when it names one. */
|
|
123
|
+
toPort?: string;
|
|
112
124
|
}
|
|
113
125
|
export interface DiagramLabel {
|
|
114
126
|
id: string;
|
package/dist/index.js
CHANGED
|
@@ -72,6 +72,12 @@ function sketchRequest({ nodes, edges, connectors, style, rootAttrs }) {
|
|
|
72
72
|
if (edges && connectors) {
|
|
73
73
|
throw new NicevgError("edges and connectors are the same; pass one of them");
|
|
74
74
|
}
|
|
75
|
+
const ids = new Set(nodes.map((node) => node.id));
|
|
76
|
+
// A node's id as it is, else split at the last dot into a node and its port.
|
|
77
|
+
const end = (name) => {
|
|
78
|
+
const dot = name.lastIndexOf(".");
|
|
79
|
+
return ids.has(name) || dot < 0 ? { node: name } : { node: name.slice(0, dot), port: name.slice(dot + 1) };
|
|
80
|
+
};
|
|
75
81
|
return {
|
|
76
82
|
nodes: nodes.map((node, index) => {
|
|
77
83
|
if (typeof node.class !== "string") {
|
|
@@ -84,7 +90,10 @@ function sketchRequest({ nodes, edges, connectors, style, rootAttrs }) {
|
|
|
84
90
|
const { id, x, y, parent, allowOverlap } = node;
|
|
85
91
|
return { id, x, y, parent, allowOverlap, svg: String(draw(node)) };
|
|
86
92
|
}),
|
|
87
|
-
connectors: edges ?? connectors,
|
|
93
|
+
connectors: (edges ?? connectors)?.map(({ from, to, ...connector }) => {
|
|
94
|
+
const [start, finish] = [end(from), end(to)];
|
|
95
|
+
return { ...connector, from: start.node, fromPort: start.port, to: finish.node, toPort: finish.port };
|
|
96
|
+
}),
|
|
88
97
|
rootAttrs: rootAttrs && Object.fromEntries(Object.entries(rootAttrs).map(([name, value]) => [name, String(value)])),
|
|
89
98
|
};
|
|
90
99
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,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K,CAAC,IAAI,EAAE,EAAE,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;QACxG,CAAC,CAAC;QACF,SAAS,EAAE,SAAS,IAAI,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KACpH,CAAC;AACJ,CAAC"}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -49,7 +49,9 @@ export interface Bounds {
|
|
|
49
49
|
* apart by their `from` and `to`.
|
|
50
50
|
*/
|
|
51
51
|
export interface SketchConnector {
|
|
52
|
+
/** The node it leaves, or `"node.port"` for a port its style marks `data-port`. */
|
|
52
53
|
from: string;
|
|
54
|
+
/** The node it reaches, or `"node.port"`. */
|
|
53
55
|
to: string;
|
|
54
56
|
points?: Point[];
|
|
55
57
|
/** Its text, lines split at `\n`, placed beside it. */
|
|
@@ -112,6 +114,8 @@ export interface DiagramNode {
|
|
|
112
114
|
allowOverlap?: boolean;
|
|
113
115
|
/** Drawn by a style: its texts are kept clear of, but not checked to fit. */
|
|
114
116
|
custom?: boolean;
|
|
117
|
+
/** The points its style marks `data-port`, each facing out of the side it lies on. */
|
|
118
|
+
ports?: { name: string; point: Point; side: "top" | "right" | "bottom" | "left" }[];
|
|
115
119
|
}
|
|
116
120
|
|
|
117
121
|
export interface DiagramConnector {
|
|
@@ -120,6 +124,10 @@ export interface DiagramConnector {
|
|
|
120
124
|
from: string;
|
|
121
125
|
to: string;
|
|
122
126
|
points: Point[];
|
|
127
|
+
/** The port of `from` it leaves, when it names one. */
|
|
128
|
+
fromPort?: string;
|
|
129
|
+
/** The port of `to` it reaches, when it names one. */
|
|
130
|
+
toPort?: string;
|
|
123
131
|
}
|
|
124
132
|
|
|
125
133
|
export interface DiagramLabel {
|
|
@@ -211,6 +219,12 @@ function sketchRequest<Node extends SketchNode>({ nodes, edges, connectors, styl
|
|
|
211
219
|
if (edges && connectors) {
|
|
212
220
|
throw new NicevgError("edges and connectors are the same; pass one of them");
|
|
213
221
|
}
|
|
222
|
+
const ids = new Set(nodes.map((node) => node.id));
|
|
223
|
+
// A node's id as it is, else split at the last dot into a node and its port.
|
|
224
|
+
const end = (name: string) => {
|
|
225
|
+
const dot = name.lastIndexOf(".");
|
|
226
|
+
return ids.has(name) || dot < 0 ? { node: name } : { node: name.slice(0, dot), port: name.slice(dot + 1) };
|
|
227
|
+
};
|
|
214
228
|
return {
|
|
215
229
|
nodes: nodes.map((node, index) => {
|
|
216
230
|
if (typeof node.class !== "string") {
|
|
@@ -223,7 +237,10 @@ function sketchRequest<Node extends SketchNode>({ nodes, edges, connectors, styl
|
|
|
223
237
|
const { id, x, y, parent, allowOverlap } = node;
|
|
224
238
|
return { id, x, y, parent, allowOverlap, svg: String(draw(node)) };
|
|
225
239
|
}),
|
|
226
|
-
connectors: edges ?? connectors,
|
|
240
|
+
connectors: (edges ?? connectors)?.map(({ from, to, ...connector }) => {
|
|
241
|
+
const [start, finish] = [end(from), end(to)];
|
|
242
|
+
return { ...connector, from: start.node, fromPort: start.port, to: finish.node, toPort: finish.port };
|
|
243
|
+
}),
|
|
227
244
|
rootAttrs: rootAttrs && Object.fromEntries(Object.entries(rootAttrs).map(([name, value]) => [name, String(value)])),
|
|
228
245
|
};
|
|
229
246
|
}
|