glassbrain 0.1.1 → 0.1.3
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 +20 -38
- package/dist/chunks/{chunk-3CNKH3HB.js → chunk-RHWFMVQU.js} +59 -21
- package/dist/chunks/{chunk-UJCALP4P.js → chunk-W357BGA7.js} +202 -177
- package/dist/cli/glassbrain.js +17 -7
- package/dist/cli/viewer.js +222 -225
- package/dist/core.js +3 -1
- package/dist/index.js +4 -2
- package/dist/internal.js +4 -2
- package/dist/react/GraphCanvas.d.ts +1 -1
- package/dist/react/GraphCanvas.js +2 -2
- package/dist/style.d.ts +5 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -155,55 +155,37 @@ Each tool's own notion of "inside" becomes the structure; everything else become
|
|
|
155
155
|
|
|
156
156
|
## 4. Try it yourself
|
|
157
157
|
|
|
158
|
-
|
|
158
|
+
Three ways to try glassbrain—pick whichever fits.
|
|
159
159
|
|
|
160
|
-
- **
|
|
161
|
-
server, no database, no requests of its own, opens from `file://`, can be sent to anyone.
|
|
162
|
-
(Images that node descriptions link to load from their URLs.)
|
|
163
|
-
- **Your data stays plain.** JSON files you can read, diff in git and edit by hand. Nothing
|
|
164
|
-
derived (flags, validation, layout) is ever written back into them.
|
|
165
|
-
- **No lock-in, no key.** Every supported format comes in, `convert` writes plain JSON out, and
|
|
166
|
-
everything runs locally.
|
|
160
|
+
- **Demo.** Explore the [live demo](https://voidixyn.github.io/glassbrain/).
|
|
167
161
|
|
|
168
|
-
**
|
|
162
|
+
- **Agent + npx.** In any context, add **"... using `npx glassbrain`."** to your prompt.
|
|
163
|
+
Skill-free and model-agnostic — any agent that can run terminal commands can use it.
|
|
164
|
+
You get a standalone HTML file to open locally and share.
|
|
169
165
|
|
|
170
|
-
|
|
171
|
-
2. Point it at something you have: `npx glassbrain <file-or-folder>`.
|
|
172
|
-
3. Ask your agent, no skill needed:
|
|
166
|
+
For example:
|
|
173
167
|
|
|
174
|
-
|
|
168
|
+
> Map the detailed plot and character relationships in *Pride and Prejudice*, using `npx glassbrain`.
|
|
175
169
|
|
|
176
|
-
|
|
177
|
-
agent needs nothing else.
|
|
170
|
+
> This refactor changed a lot. Show the architecture before and after, organized into layers, using `npx glassbrain`.
|
|
178
171
|
|
|
179
|
-
|
|
172
|
+
> Turn these research notes into a graph of ideas, evidence, and open questions, using `npx glassbrain`.
|
|
180
173
|
|
|
181
|
-
|
|
174
|
+
- **React.** Embed the graph component in your own app:
|
|
182
175
|
|
|
183
|
-
```bash
|
|
184
|
-
npm i glassbrain cytoscape cytoscape-fcose cytoscape-cose-bilkent
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
```tsx
|
|
188
|
-
import { parseSources, diffModels, GraphCanvas } from 'glassbrain';
|
|
189
|
-
|
|
190
|
-
const model = parseSources([{ origin: 'graph.json', text }]);
|
|
191
|
-
<GraphCanvas model={model} /> // browse
|
|
192
|
-
<GraphCanvas model={after} diff={diffModels(before, after)} /> // compare
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
Colors, layers, field names and your own JSON dialects go in a profile; the canvas can be made
|
|
196
|
-
editable and hands you each edit as a patch. All of it is in [the guide](https://github.com/voidixyn/glassbrain/blob/main/docs/guide.md).
|
|
176
|
+
```bash
|
|
177
|
+
npm i glassbrain cytoscape cytoscape-fcose cytoscape-cose-bilkent
|
|
178
|
+
```
|
|
197
179
|
|
|
198
|
-
|
|
180
|
+
```tsx
|
|
181
|
+
import { parseSources, diffModels, GraphCanvas } from 'glassbrain';
|
|
199
182
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
| 10,000 nodes | 9.7 s | 30 fps |
|
|
183
|
+
const model = parseSources([{ origin: 'graph.json', text }]);
|
|
184
|
+
<GraphCanvas model={model} /> // browse
|
|
185
|
+
<GraphCanvas model={after} diff={diffModels(before, after)} /> // compare
|
|
186
|
+
```
|
|
205
187
|
|
|
206
|
-
|
|
188
|
+
Customize colors, layers, fields and editing in [the guide](https://github.com/voidixyn/glassbrain/blob/main/docs/guide.md).
|
|
207
189
|
|
|
208
190
|
## Questions
|
|
209
191
|
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
anchorOf,
|
|
18
18
|
buildElements,
|
|
19
19
|
checkEdit,
|
|
20
|
+
chromeStyle,
|
|
20
21
|
cls,
|
|
21
22
|
defaultNodeColor,
|
|
22
23
|
defaultProfile,
|
|
@@ -51,7 +52,7 @@ import {
|
|
|
51
52
|
unionSides,
|
|
52
53
|
untheme,
|
|
53
54
|
validateModel
|
|
54
|
-
} from "./chunk-
|
|
55
|
+
} from "./chunk-W357BGA7.js";
|
|
55
56
|
import {
|
|
56
57
|
DetailPanel,
|
|
57
58
|
I,
|
|
@@ -2287,7 +2288,7 @@ function EdgeForm({ source: src, model, onSubmit, onCancel, colorOf }) {
|
|
|
2287
2288
|
}
|
|
2288
2289
|
|
|
2289
2290
|
// src/react/Legend.tsx
|
|
2290
|
-
import { useCallback, useEffect as useEffect3, useMemo as useMemo3, useRef as useRef3, useState as useState3 } from "react";
|
|
2291
|
+
import { useCallback, useEffect as useEffect3, useLayoutEffect as useLayoutEffect2, useMemo as useMemo3, useRef as useRef3, useState as useState3 } from "react";
|
|
2291
2292
|
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
2292
2293
|
function applyLook(profile, look) {
|
|
2293
2294
|
if (!look || !(look.nodePalette || look.edgePalette || look.nodeSize || look.edgeWidth)) return profile;
|
|
@@ -2497,6 +2498,44 @@ function SkeletonEdge({ theme }) {
|
|
|
2497
2498
|
/* @__PURE__ */ jsx3("polygon", { points: "1,5.25 29,3 29,9 1,6.75", fill: `url(#${id})` })
|
|
2498
2499
|
] });
|
|
2499
2500
|
}
|
|
2501
|
+
function LegendFrame({ collapsed, children }) {
|
|
2502
|
+
const root = useRef3(null);
|
|
2503
|
+
const size = useRef3(null);
|
|
2504
|
+
useLayoutEffect2(() => {
|
|
2505
|
+
const el = root.current;
|
|
2506
|
+
const before = size.current;
|
|
2507
|
+
const after = el.getBoundingClientRect();
|
|
2508
|
+
size.current = after;
|
|
2509
|
+
if (!before || before.width === after.width && before.height === after.height || window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
|
|
2510
|
+
const body = el.firstElementChild;
|
|
2511
|
+
body.style.width = `${body.getBoundingClientRect().width}px`;
|
|
2512
|
+
const timing = { duration: 220, easing: "cubic-bezier(.3,.7,.2,1)" };
|
|
2513
|
+
const motion = el.animate([
|
|
2514
|
+
{ width: `${before.width}px`, height: `${before.height}px`, overflow: "clip" },
|
|
2515
|
+
{ width: `${after.width}px`, height: `${after.height}px`, overflow: "clip" }
|
|
2516
|
+
], timing);
|
|
2517
|
+
const fade = body.animate([{ opacity: 0 }, { opacity: 1 }], timing);
|
|
2518
|
+
motion.onfinish = () => {
|
|
2519
|
+
body.style.width = "";
|
|
2520
|
+
size.current = el.getBoundingClientRect();
|
|
2521
|
+
};
|
|
2522
|
+
return () => {
|
|
2523
|
+
if (motion.playState === "running") size.current = el.getBoundingClientRect();
|
|
2524
|
+
motion.cancel();
|
|
2525
|
+
fade.cancel();
|
|
2526
|
+
body.style.width = "";
|
|
2527
|
+
};
|
|
2528
|
+
}, [collapsed]);
|
|
2529
|
+
useLayoutEffect2(() => {
|
|
2530
|
+
const el = root.current;
|
|
2531
|
+
const ro = new ResizeObserver(() => {
|
|
2532
|
+
if (!el.getAnimations().length) size.current = el.getBoundingClientRect();
|
|
2533
|
+
});
|
|
2534
|
+
ro.observe(el);
|
|
2535
|
+
return () => ro.disconnect();
|
|
2536
|
+
}, []);
|
|
2537
|
+
return /* @__PURE__ */ jsx3("div", { className: "gb-legend", ref: root, children });
|
|
2538
|
+
}
|
|
2500
2539
|
function Legend(p) {
|
|
2501
2540
|
const t = useStrings();
|
|
2502
2541
|
const { look, onLook, theme, profile } = p;
|
|
@@ -2587,21 +2626,18 @@ function Legend(p) {
|
|
|
2587
2626
|
const setSkeleton = (c) => onLook({ ...look, skeleton: c });
|
|
2588
2627
|
const name = (k) => profile.kindLabels[k] ?? k;
|
|
2589
2628
|
const shown = (c) => themeColor(theme, c);
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
);
|
|
2603
|
-
}
|
|
2604
|
-
return /* @__PURE__ */ jsxs3("div", { className: "gb-lg", ref: rootRef, children: [
|
|
2629
|
+
const content = p.collapsed ? /* @__PURE__ */ jsx3(
|
|
2630
|
+
"button",
|
|
2631
|
+
{
|
|
2632
|
+
type: "button",
|
|
2633
|
+
className: "gb-lg-toggle",
|
|
2634
|
+
"aria-expanded": false,
|
|
2635
|
+
"aria-label": t.legend,
|
|
2636
|
+
title: t.legend,
|
|
2637
|
+
onClick: () => p.onCollapsed(false),
|
|
2638
|
+
children: /* @__PURE__ */ jsx3(Icon, { d: I.legend })
|
|
2639
|
+
}
|
|
2640
|
+
) : /* @__PURE__ */ jsxs3("div", { className: "gb-lg", ref: rootRef, children: [
|
|
2605
2641
|
p.caption && /* @__PURE__ */ jsx3("div", { className: "gb-lg-cap", children: p.caption }),
|
|
2606
2642
|
/* @__PURE__ */ jsxs3("div", { className: "gb-lg-row", children: [
|
|
2607
2643
|
/* @__PURE__ */ jsx3(
|
|
@@ -2686,6 +2722,7 @@ function Legend(p) {
|
|
|
2686
2722
|
}, children: t.legendReset }) }),
|
|
2687
2723
|
/* @__PURE__ */ jsx3("span", { className: "gb-lg-act", children: /* @__PURE__ */ jsx3("button", { type: "button", className: "gb-lg-btn", onClick: () => p.onCollapsed(true), "aria-expanded": true, "aria-label": t.legend, title: t.legend, children: /* @__PURE__ */ jsx3(Icon, { d: I.collapse, size: 13 }) }) })
|
|
2688
2724
|
] });
|
|
2725
|
+
return /* @__PURE__ */ jsx3(LegendFrame, { collapsed: p.collapsed, children: content });
|
|
2689
2726
|
}
|
|
2690
2727
|
|
|
2691
2728
|
// src/react/DiffOverlay.tsx
|
|
@@ -3179,6 +3216,7 @@ function GraphCanvas(props) {
|
|
|
3179
3216
|
}, [props.look, props.onLookChange]);
|
|
3180
3217
|
const lookProfile = useMemo5(() => applyLook(baseProfile, look), [baseProfile, look]);
|
|
3181
3218
|
const theme = useMemo5(() => look.skeleton ? { ...baseTheme, skeleton: look.skeleton } : baseTheme, [baseTheme, look.skeleton]);
|
|
3219
|
+
const rootStyle = useMemo5(() => ({ ...chromeStyle(theme), ...style }), [theme, style]);
|
|
3182
3220
|
const [legendEmphasis, setLegendEmphasis] = useState4(null);
|
|
3183
3221
|
const emphasis = legendEmphasis ?? hostEmphasis;
|
|
3184
3222
|
const [legendCollapsed, setLegendCollapsed] = useState4(false);
|
|
@@ -4996,7 +5034,7 @@ ${lt}`;
|
|
|
4996
5034
|
return () => window.removeEventListener("keydown", onKey);
|
|
4997
5035
|
}, [compact, zoomBy, fit]);
|
|
4998
5036
|
if (model.nodes.length === 0 && model.errors.length === 0) {
|
|
4999
|
-
return /* @__PURE__ */ jsx5(StringsContext.Provider, { value: strings, children: /* @__PURE__ */ jsxs5("div", { className: `gb-root ${className ?? ""}`, style, children: [
|
|
5037
|
+
return /* @__PURE__ */ jsx5(StringsContext.Provider, { value: strings, children: /* @__PURE__ */ jsxs5("div", { className: `gb-root ${className ?? ""}`, style: rootStyle, children: [
|
|
5000
5038
|
/* @__PURE__ */ jsxs5("div", { className: "gb-empty", children: [
|
|
5001
5039
|
/* @__PURE__ */ jsx5("div", { children: emptyMessage ?? strings.empty }),
|
|
5002
5040
|
editable && !editing && /* @__PURE__ */ jsx5("button", { className: "gb-link", onClick: () => startAdd("node"), children: strings.addNode })
|
|
@@ -5007,7 +5045,7 @@ ${lt}`;
|
|
|
5007
5045
|
const filtering = isFiltering(view);
|
|
5008
5046
|
const panes = !!diff;
|
|
5009
5047
|
const platesOn = !panes && plates.length > 0 && plateAlpha > 0.01;
|
|
5010
|
-
return /* @__PURE__ */ jsx5(StringsContext.Provider, { value: strings, children: /* @__PURE__ */ jsxs5("div", { className: `gb-root ${className ?? ""}`, style, children: [
|
|
5048
|
+
return /* @__PURE__ */ jsx5(StringsContext.Provider, { value: strings, children: /* @__PURE__ */ jsxs5("div", { className: `gb-root ${className ?? ""}`, style: rootStyle, children: [
|
|
5011
5049
|
/* @__PURE__ */ jsxs5("div", { className: "gb-stage", ref: stageRef, style: { background: theme.canvas }, children: [
|
|
5012
5050
|
platesOn && /* @__PURE__ */ jsx5("svg", { className: "gb-planes", style: { opacity: plateAlpha }, children: /* @__PURE__ */ jsx5("g", { transform: `translate(${viewport.pan.x},${viewport.pan.y}) scale(${viewport.zoom})`, children: plates.map((p) => {
|
|
5013
5051
|
const c = plateColors(theme, p.color);
|
|
@@ -5121,7 +5159,7 @@ ${lt}`;
|
|
|
5121
5159
|
model.errors.slice(0, 2).map((e) => e.origin).join(", ") + (model.errors.length > 2 ? ", \u2026" : "")
|
|
5122
5160
|
) })
|
|
5123
5161
|
] }),
|
|
5124
|
-
legend && !compact && /* @__PURE__ */ jsx5(
|
|
5162
|
+
legend && !compact && /* @__PURE__ */ jsx5(
|
|
5125
5163
|
Legend,
|
|
5126
5164
|
{
|
|
5127
5165
|
model,
|
|
@@ -5143,7 +5181,7 @@ ${lt}`;
|
|
|
5143
5181
|
onCollapsed: setLegendCollapsed,
|
|
5144
5182
|
caption: note
|
|
5145
5183
|
}
|
|
5146
|
-
)
|
|
5184
|
+
)
|
|
5147
5185
|
] }),
|
|
5148
5186
|
!compact && /* @__PURE__ */ jsx5(
|
|
5149
5187
|
ZoomDock,
|