glassbrain 0.2.0-alpha.5 → 0.2.0-alpha.7
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/README.md +18 -12
- package/dist/adapters.js +25 -1
- package/dist/chunks/{chunk-3JGZ27DC.js → chunk-3KUNYSJE.js} +6 -3
- package/dist/chunks/{chunk-F4HDKER4.js → chunk-FNTYI7VP.js} +291 -112
- package/dist/chunks/{chunk-WUBELTBU.js → chunk-GZSWZSSE.js} +392 -339
- package/dist/chunks/{chunk-G7XWVKHN.js → chunk-LK77SYCN.js} +39 -5
- package/dist/chunks/{chunk-ISWKAU5G.js → chunk-Q35ZKWKF.js} +3 -5
- package/dist/cli/glassbrain.js +552 -380
- package/dist/cli/viewer.js +92 -63
- package/dist/core.d.ts +1 -0
- package/dist/core.js +13 -5
- package/dist/edit.d.ts +5 -3
- package/dist/index.js +15 -7
- package/dist/internal.js +15 -7
- package/dist/kinds.d.ts +23 -0
- package/dist/layers.d.ts +1 -1
- package/dist/model.d.ts +15 -5
- package/dist/profile.d.ts +14 -2
- package/dist/react/DetailPanel.js +2 -2
- package/dist/react/GlassPlanes.d.ts +11 -0
- package/dist/react/GraphCanvas.d.ts +2 -0
- package/dist/react/GraphCanvas.js +4 -4
- package/dist/react/icons.d.ts +2 -0
- package/dist/strings.d.ts +2 -2
- package/dist/tree.d.ts +11 -0
- package/package.json +1 -1
- package/schema/graph.schema.json +125 -23
- package/schema/profile.schema.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/layers.ts
|
|
2
2
|
var EMPTY = { layers: [], layerOf: /* @__PURE__ */ new Map() };
|
|
3
|
-
function orderedChildren(children, id) {
|
|
3
|
+
function orderedChildren(children, id, unordered = false) {
|
|
4
|
+
if (unordered) return null;
|
|
4
5
|
const kids = children.get(id) ?? [];
|
|
5
6
|
if (kids.length < 2) return null;
|
|
6
7
|
const withOrder = kids.filter((n) => typeof n.order === "number" && Number.isFinite(n.order));
|
|
@@ -29,10 +30,10 @@ function deriveLayers(model, colors = [], force = false) {
|
|
|
29
30
|
let anchor;
|
|
30
31
|
if (roots.length === 1) {
|
|
31
32
|
anchor = roots[0];
|
|
32
|
-
ordered = orderedChildren(children, anchor.id);
|
|
33
|
+
ordered = orderedChildren(children, anchor.id, anchor.data?.unordered === true);
|
|
33
34
|
if (!ordered && force) ordered = children.get(anchor.id) ?? null;
|
|
34
|
-
} else if (
|
|
35
|
-
ordered = roots;
|
|
35
|
+
} else if (roots.length > 1 && (force || roots.every((n) => n.order !== void 0))) {
|
|
36
|
+
ordered = [...roots].sort((a, b) => (a.order ?? Infinity) - (b.order ?? Infinity));
|
|
36
37
|
}
|
|
37
38
|
if (!ordered || ordered.length < 2) return EMPTY;
|
|
38
39
|
const layers = ordered.map((n, i) => ({
|
|
@@ -58,9 +59,42 @@ function layerIndexOf(derived, id) {
|
|
|
58
59
|
return lid ? derived.layers.findIndex((l) => l.id === lid) : -1;
|
|
59
60
|
}
|
|
60
61
|
|
|
62
|
+
// src/kinds.ts
|
|
63
|
+
function kindDistribution(items) {
|
|
64
|
+
const counts = /* @__PURE__ */ new Map();
|
|
65
|
+
for (const item of items) if (item.kind) counts.set(item.kind, (counts.get(item.kind) ?? 0) + 1);
|
|
66
|
+
const sizes = [...counts].map(([kind, count]) => ({ kind, count })).sort((a, b) => b.count - a.count || a.kind.localeCompare(b.kind));
|
|
67
|
+
const typed = sizes.reduce((sum, row) => sum + row.count, 0);
|
|
68
|
+
const effective = sizes.reduce((sum, row) => sum + Math.sqrt(row.count / typed), 0) ** 2;
|
|
69
|
+
const fragmentation = typed > 1 ? effective / Math.log(typed) : 0;
|
|
70
|
+
return {
|
|
71
|
+
total: items.length,
|
|
72
|
+
typed,
|
|
73
|
+
missing: items.length - typed,
|
|
74
|
+
count: sizes.length,
|
|
75
|
+
sizes,
|
|
76
|
+
effective,
|
|
77
|
+
fragmentation,
|
|
78
|
+
reason: typed >= 10 && fragmentation > 2 ? "too fragmented" : null
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function kindHeading(space, d) {
|
|
82
|
+
return `${space} kinds: ${d.count}${d.reason ? ` (${d.reason})` : ""}`;
|
|
83
|
+
}
|
|
84
|
+
function kindSummary(space, d, labels = {}) {
|
|
85
|
+
return [
|
|
86
|
+
kindHeading(space, d),
|
|
87
|
+
...d.sizes.map((row) => `${Object.hasOwn(labels, row.kind) ? labels[row.kind] : row.kind} ${row.count}/${d.total}`),
|
|
88
|
+
...d.missing ? [`(no kind) ${d.missing}/${d.total}`] : []
|
|
89
|
+
].join(" | ");
|
|
90
|
+
}
|
|
91
|
+
|
|
61
92
|
export {
|
|
62
93
|
orderedChildren,
|
|
63
94
|
childrenMap,
|
|
64
95
|
deriveLayers,
|
|
65
|
-
layerIndexOf
|
|
96
|
+
layerIndexOf,
|
|
97
|
+
kindDistribution,
|
|
98
|
+
kindHeading,
|
|
99
|
+
kindSummary
|
|
66
100
|
};
|
|
@@ -28,8 +28,8 @@ var EN = {
|
|
|
28
28
|
more: "More",
|
|
29
29
|
origins: "Source",
|
|
30
30
|
allOrigins: "All sources",
|
|
31
|
-
issuesTip: (e, w) => [e && `${e} error${e > 1 ? "s" : ""}`, w && `${w} warning${w > 1 ? "s" : ""}`].filter(Boolean).join(" \xB7 "),
|
|
32
|
-
issuesTitle: (e, w) => `Checks \xB7 ${[e && `${e} errors`, w && `${w} warnings`].filter(Boolean).join(" \xB7 ")}`,
|
|
31
|
+
issuesTip: (e, w, i) => [e && `${e} error${e > 1 ? "s" : ""}`, w && `${w} warning${w > 1 ? "s" : ""}`, i && `${i} info`].filter(Boolean).join(" \xB7 "),
|
|
32
|
+
issuesTitle: (e, w, i) => `Checks \xB7 ${[e && `${e} errors`, w && `${w} warnings`, i && `${i} info`].filter(Boolean).join(" \xB7 ")}`,
|
|
33
33
|
moreItems: (n) => `${n} more`,
|
|
34
34
|
cameraTip: "Scroll / two fingers to pan \xB7 \u2318 + scroll or pinch to zoom",
|
|
35
35
|
zoomIn: "Zoom in (+)",
|
|
@@ -84,9 +84,7 @@ var EN = {
|
|
|
84
84
|
"no-node": "Node not found",
|
|
85
85
|
"no-parent": "Parent not found",
|
|
86
86
|
cycle: "Cannot be placed inside itself",
|
|
87
|
-
"
|
|
88
|
-
"multiple-roots": "Keep one root: choose an existing parent",
|
|
89
|
-
"order-mixed": "Siblings must all be numbered or all unordered",
|
|
87
|
+
"invalid-position": "Choose a different node in the same children list",
|
|
90
88
|
"order-invalid": "Order must be positive and unique among siblings (blank = unordered)",
|
|
91
89
|
"has-children": "Has children \u2014 delete or move them first",
|
|
92
90
|
"no-endpoint": "Pick both ends",
|