@ts-graphviz/common 0.0.0-pr956-20240225073457

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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @ts-graphviz/common
2
+
3
+ ## 0.0.0-pr956-20240225073457
4
+
5
+ ### Major Changes
6
+
7
+ - [`6b2f0e8`](https://github.com/ts-graphviz/ts-graphviz/commit/6b2f0e8349605b4fe0dd950147ba3a8285b24b24) Thanks [@kamiazya](https://github.com/kamiazya)! - Release v2.0.0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) 2019-2024 Yuki Yamazaki
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # @ts-graphviz/common
2
+
3
+ This package contains type information, constants, and utility functions related to the DOT language attributes, attribute values, and models for ts-graphviz.
4
+
5
+ It is part of the ts-graphviz library, which is split into modular packages to improve maintainability, flexibility, and ease of use.
6
+
7
+ ## Features
8
+
9
+ - Type definitions for DOT language elements, such as attributes and attribute values
10
+ - Constants representing common attribute names and values
11
+ - Utility functions for working with DOT language elements
12
+
13
+ ## Usage
14
+
15
+ Import the necessary types, constants, or utility functions from the `@ts-graphviz/common` package:
16
+
17
+ ```ts
18
+ import { NodeAttributesObject, EdgeAttributesObject } from '@ts-graphviz/common';
19
+ ```
20
+
21
+ Use the imported items in your project to work with the DOT language elements:
22
+
23
+
24
+ ```ts
25
+ const nodeAttr: NodeAttributesObject = {
26
+ label: 'Node label',
27
+ shape: 'ellipse',
28
+ };
29
+
30
+ const edgeAttr: EdgeAttributesObject = {
31
+ label: 'Edge label',
32
+ color: 'red',
33
+ };
34
+ ```
35
+
36
+ For more examples and usage details, please refer to the ts-graphviz documentation.
37
+
38
+
39
+ ## Contributing
40
+
41
+ Contributions to the ts-graphviz project are welcome.
42
+
43
+ Please refer to the main ts-graphviz repository for guidelines on how to contribute.
44
+
45
+ ## License
46
+
47
+ This package is released under the MIT License.
package/lib/common.cjs ADDED
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function _pipe(...args) {
4
+ const [o1, ...operations] = args;
5
+ return (...t) => operations.reduce((acc, f) => f(acc), o1(...t));
6
+ }
7
+ function pipe(o1, ...operations) {
8
+ return _pipe(o1, ...operations);
9
+ }
10
+ const defer = (fn) => (...args) => (src) => fn(src, ...args);
11
+ const toIterable = (f) => ({
12
+ [Symbol.iterator]: f
13
+ });
14
+ const map = defer(
15
+ (src, selector) => Array.from(
16
+ toIterable(function* () {
17
+ for (const v of src) {
18
+ yield selector(v);
19
+ }
20
+ })
21
+ )
22
+ );
23
+ const filter = defer(
24
+ (src, pred) => Array.from(
25
+ toIterable(function* () {
26
+ for (const x of src) {
27
+ if (pred(x)) {
28
+ yield x;
29
+ }
30
+ }
31
+ })
32
+ )
33
+ );
34
+ const RootModelsContext = Object.seal({
35
+ // NOTE: RootModelsContext is also initialized after the model class is declared in the 'core/index.js' module.
36
+ Graph: null,
37
+ Digraph: null,
38
+ Subgraph: null,
39
+ Node: null,
40
+ Edge: null
41
+ });
42
+ function createModelsContext(models) {
43
+ return Object.assign(
44
+ Object.seal(Object.assign({}, RootModelsContext)),
45
+ models
46
+ );
47
+ }
48
+ function isForwardRefNode(object) {
49
+ return typeof object === "object" && object !== null && typeof object.id === "string";
50
+ }
51
+ function isNodeModel(object) {
52
+ return typeof object === "object" && object !== null && object.$$type === "Node" && typeof object.id === "string";
53
+ }
54
+ function isNodeRef(node) {
55
+ return isNodeModel(node) || isForwardRefNode(node);
56
+ }
57
+ function isNodeRefLike(node) {
58
+ return typeof node === "string" || isNodeRef(node);
59
+ }
60
+ function isNodeRefGroupLike(target) {
61
+ return Array.isArray(target) && target.every(isNodeRefLike);
62
+ }
63
+ function isCompass(c) {
64
+ return ["n", "ne", "e", "se", "s", "sw", "w", "nw", "c"].includes(c);
65
+ }
66
+ function toNodeRef(target) {
67
+ if (isNodeRef(target)) {
68
+ return target;
69
+ }
70
+ const [id, port, compass] = target.split(":");
71
+ if (isCompass(compass)) {
72
+ return { id, port, compass };
73
+ }
74
+ return { id, port };
75
+ }
76
+ function toNodeRefGroup(targets) {
77
+ if (targets.length < 2 && (isNodeRefLike(targets[0]) && isNodeRefLike(targets[1])) === false) {
78
+ throw Error("EdgeTargets must have at least 2 elements.");
79
+ }
80
+ return targets.map((t) => toNodeRef(t));
81
+ }
82
+ exports.RootModelsContext = RootModelsContext;
83
+ exports.createModelsContext = createModelsContext;
84
+ exports.filter = filter;
85
+ exports.isCompass = isCompass;
86
+ exports.isForwardRefNode = isForwardRefNode;
87
+ exports.isNodeModel = isNodeModel;
88
+ exports.isNodeRef = isNodeRef;
89
+ exports.isNodeRefGroupLike = isNodeRefGroupLike;
90
+ exports.isNodeRefLike = isNodeRefLike;
91
+ exports.map = map;
92
+ exports.pipe = pipe;
93
+ exports.toNodeRef = toNodeRef;
94
+ exports.toNodeRefGroup = toNodeRefGroup;