@bruno00o/graph 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 bruno00o
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,9 @@
1
- # Temporary Holding Version
1
+ # @bruno00o/graph
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Framework-agnostic, typed graph visualization rendered with WebGL2.
4
+
5
+ Early development: nothing is usable yet.
6
+
7
+ ## License
8
+
9
+ MIT
package/dist/db.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { r as GraphInstance } from "./mount-graph-B88WGOQu.js";
2
+ import { O as Point, _ as Key, d as FieldOf } from "./types-D6b86Rt1.js";
3
+ import { Collection, MutationFn, Strategy } from "@tanstack/db";
4
+ export interface PersistPositionsOptions<T extends object, TKey extends string | number> {
5
+ readonly collection: Collection<T, TKey>;
6
+ readonly x?: FieldOf<T, number>;
7
+ readonly y?: FieldOf<T, number>;
8
+ readonly key?: (key: Key) => TKey;
9
+ readonly create?: (key: Key, point: Point) => T;
10
+ readonly mutationFn?: MutationFn<T>;
11
+ readonly strategy?: Strategy;
12
+ }
13
+ export declare function persistPositions<T extends object, TKey extends string | number>(graph: GraphInstance, options: PersistPositionsOptions<T, TKey>): () => void;
14
+ //# sourceMappingURL=db.d.ts.map
package/dist/db.js ADDED
@@ -0,0 +1,85 @@
1
+ import { createPacedMutations, throttleStrategy } from "@tanstack/db";
2
+ // src/db/index.ts
3
+ const defaultWait = 100;
4
+ function pace(wait, run) {
5
+ let timer;
6
+ let next = 0;
7
+ let pending = false;
8
+ const fire = () => {
9
+ timer = void 0;
10
+ pending = false;
11
+ next = Date.now() + wait;
12
+ run();
13
+ };
14
+ return {
15
+ call() {
16
+ pending = true;
17
+ if (timer !== void 0) return;
18
+ const delay = next - Date.now();
19
+ if (delay <= 0) fire();
20
+ else timer = setTimeout(fire, delay);
21
+ },
22
+ flush() {
23
+ if (timer !== void 0) clearTimeout(timer);
24
+ if (pending) fire();
25
+ }
26
+ };
27
+ }
28
+ function persistPositions(graph, options) {
29
+ const { collection, mutationFn, create } = options;
30
+ const xField = options.x ?? "x";
31
+ const yField = options.y ?? "y";
32
+ const keyOf = options.key ?? ((key) => key);
33
+ const write = (positions) => {
34
+ const keys = [];
35
+ const points = [];
36
+ for (const [key, point] of positions) {
37
+ const rowKey = keyOf(key);
38
+ if (collection.has(rowKey)) {
39
+ keys.push(rowKey);
40
+ points.push(point);
41
+ } else if (create) collection.insert(create(key, point));
42
+ }
43
+ if (keys.length === 0) return;
44
+ collection.update(keys, (drafts) => {
45
+ drafts.forEach((draft, i) => {
46
+ const point = points[i];
47
+ if (!point) return;
48
+ const row = draft;
49
+ row[xField] = point.x;
50
+ row[yField] = point.y;
51
+ });
52
+ });
53
+ };
54
+ if (mutationFn) {
55
+ const mutate = createPacedMutations({
56
+ onMutate: write,
57
+ mutationFn,
58
+ strategy: options.strategy ?? throttleStrategy({
59
+ wait: defaultWait,
60
+ leading: true,
61
+ trailing: true
62
+ })
63
+ });
64
+ return graph.on("positionchange", (event) => {
65
+ mutate(event.positions);
66
+ });
67
+ }
68
+ let pending = /* @__PURE__ */ new Map();
69
+ const paced = pace(options.strategy?.options?.wait ?? defaultWait, () => {
70
+ const positions = pending;
71
+ pending = /* @__PURE__ */ new Map();
72
+ write(positions);
73
+ });
74
+ const stop = graph.on("positionchange", (event) => {
75
+ for (const [key, point] of event.positions) pending.set(key, point);
76
+ paced.call();
77
+ });
78
+ return () => {
79
+ stop();
80
+ paced.flush();
81
+ };
82
+ }
83
+ export { persistPositions };
84
+
85
+ //# sourceMappingURL=db.js.map
package/dist/db.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.js","names":[],"sources":["../src/db/index.ts"],"sourcesContent":["import {\n type Collection,\n createPacedMutations,\n type MutationFn,\n type Strategy,\n throttleStrategy,\n} from '@tanstack/db'\nimport type { GraphPositionEvent } from '../host/events'\nimport type { GraphInstance } from '../host/mount-graph'\nimport type { FieldOf, Key, Point } from '../types'\n\nexport interface PersistPositionsOptions<T extends object, TKey extends string | number> {\n readonly collection: Collection<T, TKey>\n readonly x?: FieldOf<T, number>\n readonly y?: FieldOf<T, number>\n readonly key?: (key: Key) => TKey\n readonly create?: (key: Key, point: Point) => T\n readonly mutationFn?: MutationFn<T>\n readonly strategy?: Strategy\n}\n\nconst defaultWait = 100\n\nfunction pace(\n wait: number,\n run: () => void,\n): { readonly call: () => void; readonly flush: () => void } {\n let timer: ReturnType<typeof setTimeout> | undefined\n let next = 0\n let pending = false\n const fire = () => {\n timer = undefined\n pending = false\n next = Date.now() + wait\n run()\n }\n return {\n call() {\n pending = true\n if (timer !== undefined) return\n const delay = next - Date.now()\n if (delay <= 0) fire()\n else timer = setTimeout(fire, delay)\n },\n flush() {\n if (timer !== undefined) clearTimeout(timer)\n if (pending) fire()\n },\n }\n}\n\nexport function persistPositions<T extends object, TKey extends string | number>(\n graph: GraphInstance,\n options: PersistPositionsOptions<T, TKey>,\n): () => void {\n const { collection, mutationFn, create } = options\n const xField: string = options.x ?? 'x'\n const yField: string = options.y ?? 'y'\n const keyOf = options.key ?? ((key: Key) => key as TKey)\n\n const write = (positions: ReadonlyMap<Key, Point>) => {\n const keys: TKey[] = []\n const points: Point[] = []\n for (const [key, point] of positions) {\n const rowKey = keyOf(key)\n if (collection.has(rowKey)) {\n keys.push(rowKey)\n points.push(point)\n } else if (create) {\n collection.insert(create(key, point))\n }\n }\n if (keys.length === 0) return\n collection.update(keys, (drafts) => {\n drafts.forEach((draft, i) => {\n const point = points[i]\n if (!point) return\n const row = draft as Record<string, unknown>\n row[xField] = point.x\n row[yField] = point.y\n })\n })\n }\n\n if (mutationFn) {\n const mutate = createPacedMutations<ReadonlyMap<Key, Point>, T>({\n onMutate: write,\n mutationFn,\n strategy:\n options.strategy ?? throttleStrategy({ wait: defaultWait, leading: true, trailing: true }),\n })\n return graph.on('positionchange', (event: GraphPositionEvent) => {\n mutate(event.positions)\n })\n }\n\n let pending = new Map<Key, Point>()\n const paced = pace(options.strategy?.options?.wait ?? defaultWait, () => {\n const positions = pending\n pending = new Map()\n write(positions)\n })\n const stop = graph.on('positionchange', (event: GraphPositionEvent) => {\n for (const [key, point] of event.positions) pending.set(key, point)\n paced.call()\n })\n return () => {\n stop()\n paced.flush()\n }\n}\n"],"mappings":";;AAqBA,MAAM,cAAc;AAEpB,SAAS,KACP,MACA,KAC2D;CAC3D,IAAI;CACJ,IAAI,OAAO;CACX,IAAI,UAAU;CACd,MAAM,aAAa;EACjB,QAAQ,KAAA;EACR,UAAU;EACV,OAAO,KAAK,IAAI,IAAI;EACpB,IAAI;CACN;CACA,OAAO;EACL,OAAO;GACL,UAAU;GACV,IAAI,UAAU,KAAA,GAAW;GACzB,MAAM,QAAQ,OAAO,KAAK,IAAI;GAC9B,IAAI,SAAS,GAAG,KAAK;QAChB,QAAQ,WAAW,MAAM,KAAK;EACrC;EACA,QAAQ;GACN,IAAI,UAAU,KAAA,GAAW,aAAa,KAAK;GAC3C,IAAI,SAAS,KAAK;EACpB;CACF;AACF;AAEA,SAAgB,iBACd,OACA,SACY;CACZ,MAAM,EAAE,YAAY,YAAY,WAAW;CAC3C,MAAM,SAAiB,QAAQ,KAAK;CACpC,MAAM,SAAiB,QAAQ,KAAK;CACpC,MAAM,QAAQ,QAAQ,SAAS,QAAa;CAE5C,MAAM,SAAS,cAAuC;EACpD,MAAM,OAAe,CAAC;EACtB,MAAM,SAAkB,CAAC;EACzB,KAAK,MAAM,CAAC,KAAK,UAAU,WAAW;GACpC,MAAM,SAAS,MAAM,GAAG;GACxB,IAAI,WAAW,IAAI,MAAM,GAAG;IAC1B,KAAK,KAAK,MAAM;IAChB,OAAO,KAAK,KAAK;GACnB,OAAO,IAAI,QACT,WAAW,OAAO,OAAO,KAAK,KAAK,CAAC;EAExC;EACA,IAAI,KAAK,WAAW,GAAG;EACvB,WAAW,OAAO,OAAO,WAAW;GAClC,OAAO,SAAS,OAAO,MAAM;IAC3B,MAAM,QAAQ,OAAO;IACrB,IAAI,CAAC,OAAO;IACZ,MAAM,MAAM;IACZ,IAAI,UAAU,MAAM;IACpB,IAAI,UAAU,MAAM;GACtB,CAAC;EACH,CAAC;CACH;CAEA,IAAI,YAAY;EACd,MAAM,SAAS,qBAAiD;GAC9D,UAAU;GACV;GACA,UACE,QAAQ,YAAY,iBAAiB;IAAE,MAAM;IAAa,SAAS;IAAM,UAAU;GAAK,CAAC;EAC7F,CAAC;EACD,OAAO,MAAM,GAAG,mBAAmB,UAA8B;GAC/D,OAAO,MAAM,SAAS;EACxB,CAAC;CACH;CAEA,IAAI,0BAAU,IAAI,IAAgB;CAClC,MAAM,QAAQ,KAAK,QAAQ,UAAU,SAAS,QAAQ,mBAAmB;EACvE,MAAM,YAAY;EAClB,0BAAU,IAAI,IAAI;EAClB,MAAM,SAAS;CACjB,CAAC;CACD,MAAM,OAAO,MAAM,GAAG,mBAAmB,UAA8B;EACrE,KAAK,MAAM,CAAC,KAAK,UAAU,MAAM,WAAW,QAAQ,IAAI,KAAK,KAAK;EAClE,MAAM,KAAK;CACb,CAAC;CACD,aAAa;EACX,KAAK;EACL,MAAM,MAAM;CACd;AACF"}
@@ -0,0 +1,19 @@
1
+ import { A as ResolvedTransitions, C as NodeMark, D as NumberScaleType, E as NumberScale, F as StateStyle, I as StateStyles, L as Style, M as SelectMode, N as SourceChange, O as Point, P as SourceSubscription, R as TransitionOptions, S as Mark, T as NodeShape, _ as Key, a as Channel, b as LabelOptions, c as EdgeDash, d as FieldOf, f as FreeState, g as InteractionOptions, h as GraphDefinitionOptions, i as BuiltInState, j as ScalesOptions, k as ResolvedInteraction, l as EdgeMark, m as GraphDefinition, n as Badge, o as ColorScale, p as GraphData, r as BadgeCorner, s as EdgeArrow, t as Accessor, u as EdgeOptions, v as KeyChannel, w as NodeOptions, x as LiveSource, y as KeyFieldOf, z as View } from "./types-D6b86Rt1.js";
2
+ import { C as PositionOrigin, S as GraphTargetEvent, _ as GraphEventName, a as GraphSelection, b as GraphPositionEvent, c as GraphStore, d as ViewOptions, f as mountGraph, g as GraphEventHandler, h as GraphDragEvent, i as GraphPositions, l as GraphView, m as ElementKeysInput, n as GraphElement, o as GraphState, p as ElementKeys, r as GraphInstance, s as GraphStates, t as FitOptions, u as MountGraphOptions, v as GraphEvents, x as GraphTarget, y as GraphPointerEvent } from "./mount-graph-B88WGOQu.js";
3
+ export declare function defineGraph<S extends string = never>(options: GraphDefinitionOptions<S>): GraphDefinition<S>;
4
+ export declare function nodes<T>(data: LiveSource<T>, options?: NodeOptions<NoInfer<T>>): NodeMark<T>;
5
+ export declare function nodes<T extends {
6
+ readonly id: Key;
7
+ }>(data: Iterable<T>, options?: NodeOptions<NoInfer<T>>): NodeMark<T>;
8
+ export declare function nodes<T>(data: Iterable<T>, options: NodeOptions<NoInfer<T>> & {
9
+ readonly key: KeyChannel<NoInfer<T>>;
10
+ }): NodeMark<T>;
11
+ export declare function edges<T>(data: LiveSource<T>, options: EdgeOptions<NoInfer<T>>): EdgeMark<T>;
12
+ export declare function edges<T extends {
13
+ readonly id: Key;
14
+ }>(data: Iterable<T>, options: EdgeOptions<NoInfer<T>>): EdgeMark<T>;
15
+ export declare function edges<T>(data: Iterable<T>, options: EdgeOptions<NoInfer<T>> & {
16
+ readonly key: KeyChannel<NoInfer<T>>;
17
+ }): EdgeMark<T>;
18
+ export { type Accessor, type Badge, type BadgeCorner, type BuiltInState, type Channel, type ColorScale, type EdgeArrow, type EdgeDash, type EdgeMark, type EdgeOptions, type ElementKeys, type ElementKeysInput, type FieldOf, type FitOptions, type FreeState, type GraphData, type GraphDefinition, type GraphDefinitionOptions, type GraphDragEvent, type GraphElement, type GraphEventHandler, type GraphEventName, type GraphEvents, type GraphInstance, type GraphPointerEvent, type GraphPositionEvent, type GraphPositions, type GraphSelection, type GraphState, type GraphStates, type GraphStore, type GraphTarget, type GraphTargetEvent, type GraphView, type InteractionOptions, type Key, type KeyChannel, type KeyFieldOf, type LabelOptions, type LiveSource, type Mark, type MountGraphOptions, type NodeMark, type NodeOptions, type NodeShape, type NumberScale, type NumberScaleType, type Point, type PositionOrigin, type ResolvedInteraction, type ResolvedTransitions, type ScalesOptions, type SelectMode, type SourceChange, type SourceSubscription, type StateStyle, type StateStyles, type Style, type TransitionOptions, type View, type ViewOptions, mountGraph };
19
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,44 @@
1
+ import { n as freeStateNames, r as maxFreeStates, t as mountGraph } from "./mount-graph-BHwq3LOr.js";
2
+ // src/define-graph.ts
3
+ const defaultZoomSpeed = 1;
4
+ const defaultPositionTransition = 120;
5
+ function resolveInteraction(options = {}) {
6
+ const zoom = options.zoom ?? true;
7
+ return Object.freeze({
8
+ pan: options.pan ?? true,
9
+ zoom: zoom === false ? false : Object.freeze({ speed: (zoom === true ? void 0 : zoom.speed) ?? defaultZoomSpeed }),
10
+ select: options.select ?? "multiple",
11
+ drag: options.drag ?? true,
12
+ lasso: options.lasso ?? false,
13
+ keyboard: options.keyboard ?? true
14
+ });
15
+ }
16
+ function defineGraph(options) {
17
+ for (const mark of options.marks) if (mark?.type !== "nodes" && mark?.type !== "edges") throw new TypeError("defineGraph: every mark must come from nodes() or edges()");
18
+ if (freeStateNames(options.states ?? {}).length > maxFreeStates) throw new RangeError(`defineGraph: at most ${maxFreeStates} states besides selected, hovered and focused`);
19
+ return Object.freeze({
20
+ marks: Object.freeze([...options.marks]),
21
+ scales: Object.freeze({ ...options.scales }),
22
+ states: Object.freeze({ ...options.states }),
23
+ interaction: resolveInteraction(options.interaction),
24
+ transitions: Object.freeze({ positions: Math.max(0, options.transitions?.positions ?? defaultPositionTransition) })
25
+ });
26
+ }
27
+ // src/marks.ts
28
+ function nodes(data, options = {}) {
29
+ return Object.freeze({
30
+ type: "nodes",
31
+ data,
32
+ options: Object.freeze({ ...options })
33
+ });
34
+ }
35
+ function edges(data, options) {
36
+ return Object.freeze({
37
+ type: "edges",
38
+ data,
39
+ options: Object.freeze({ ...options })
40
+ });
41
+ }
42
+ export { defineGraph, edges, mountGraph, nodes };
43
+
44
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/define-graph.ts","../src/marks.ts"],"sourcesContent":["import { freeStateNames, maxFreeStates } from './core/state-names'\nimport type {\n GraphDefinition,\n GraphDefinitionOptions,\n InteractionOptions,\n ResolvedInteraction,\n StateStyles,\n} from './types'\n\nconst defaultZoomSpeed = 1\nconst defaultPositionTransition = 120\n\nfunction resolveInteraction(options: InteractionOptions = {}): ResolvedInteraction {\n const zoom = options.zoom ?? true\n return Object.freeze({\n pan: options.pan ?? true,\n zoom:\n zoom === false\n ? false\n : Object.freeze({ speed: (zoom === true ? undefined : zoom.speed) ?? defaultZoomSpeed }),\n select: options.select ?? 'multiple',\n drag: options.drag ?? true,\n lasso: options.lasso ?? false,\n keyboard: options.keyboard ?? true,\n })\n}\n\nexport function defineGraph<S extends string = never>(\n options: GraphDefinitionOptions<S>,\n): GraphDefinition<S> {\n for (const mark of options.marks) {\n if (mark?.type !== 'nodes' && mark?.type !== 'edges') {\n throw new TypeError('defineGraph: every mark must come from nodes() or edges()')\n }\n }\n if (freeStateNames(options.states ?? {}).length > maxFreeStates) {\n throw new RangeError(\n `defineGraph: at most ${maxFreeStates} states besides selected, hovered and focused`,\n )\n }\n return Object.freeze({\n marks: Object.freeze([...options.marks]),\n scales: Object.freeze({ ...options.scales }),\n states: Object.freeze({ ...options.states }) as StateStyles<S>,\n interaction: resolveInteraction(options.interaction),\n transitions: Object.freeze({\n positions: Math.max(0, options.transitions?.positions ?? defaultPositionTransition),\n }),\n })\n}\n","import type {\n EdgeMark,\n EdgeOptions,\n GraphData,\n Key,\n KeyChannel,\n LiveSource,\n NodeMark,\n NodeOptions,\n} from './types'\n\nexport function nodes<T>(data: LiveSource<T>, options?: NodeOptions<NoInfer<T>>): NodeMark<T>\nexport function nodes<T extends { readonly id: Key }>(\n data: Iterable<T>,\n options?: NodeOptions<NoInfer<T>>,\n): NodeMark<T>\nexport function nodes<T>(\n data: Iterable<T>,\n options: NodeOptions<NoInfer<T>> & { readonly key: KeyChannel<NoInfer<T>> },\n): NodeMark<T>\nexport function nodes<T>(data: GraphData<T>, options: NodeOptions<T> = {}): NodeMark<T> {\n return Object.freeze({ type: 'nodes', data, options: Object.freeze({ ...options }) })\n}\n\nexport function edges<T>(data: LiveSource<T>, options: EdgeOptions<NoInfer<T>>): EdgeMark<T>\nexport function edges<T extends { readonly id: Key }>(\n data: Iterable<T>,\n options: EdgeOptions<NoInfer<T>>,\n): EdgeMark<T>\nexport function edges<T>(\n data: Iterable<T>,\n options: EdgeOptions<NoInfer<T>> & { readonly key: KeyChannel<NoInfer<T>> },\n): EdgeMark<T>\nexport function edges<T>(data: GraphData<T>, options: EdgeOptions<T>): EdgeMark<T> {\n return Object.freeze({ type: 'edges', data, options: Object.freeze({ ...options }) })\n}\n"],"mappings":";;AASA,MAAM,mBAAmB;AACzB,MAAM,4BAA4B;AAElC,SAAS,mBAAmB,UAA8B,CAAC,GAAwB;CACjF,MAAM,OAAO,QAAQ,QAAQ;CAC7B,OAAO,OAAO,OAAO;EACnB,KAAK,QAAQ,OAAO;EACpB,MACE,SAAS,QACL,QACA,OAAO,OAAO,EAAE,QAAQ,SAAS,OAAO,KAAA,IAAY,KAAK,UAAU,iBAAiB,CAAC;EAC3F,QAAQ,QAAQ,UAAU;EAC1B,MAAM,QAAQ,QAAQ;EACtB,OAAO,QAAQ,SAAS;EACxB,UAAU,QAAQ,YAAY;CAChC,CAAC;AACH;AAEA,SAAgB,YACd,SACoB;CACpB,KAAK,MAAM,QAAQ,QAAQ,OACzB,IAAI,MAAM,SAAS,WAAW,MAAM,SAAS,SAC3C,MAAM,IAAI,UAAU,2DAA2D;CAGnF,IAAI,eAAe,QAAQ,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,eAChD,MAAM,IAAI,WACR,wBAAwB,cAAc,8CACxC;CAEF,OAAO,OAAO,OAAO;EACnB,OAAO,OAAO,OAAO,CAAC,GAAG,QAAQ,KAAK,CAAC;EACvC,QAAQ,OAAO,OAAO,EAAE,GAAG,QAAQ,OAAO,CAAC;EAC3C,QAAQ,OAAO,OAAO,EAAE,GAAG,QAAQ,OAAO,CAAC;EAC3C,aAAa,mBAAmB,QAAQ,WAAW;EACnD,aAAa,OAAO,OAAO,EACzB,WAAW,KAAK,IAAI,GAAG,QAAQ,aAAa,aAAa,yBAAyB,EACpF,CAAC;CACH,CAAC;AACH;;AC7BA,SAAgB,MAAS,MAAoB,UAA0B,CAAC,GAAgB;CACtF,OAAO,OAAO,OAAO;EAAE,MAAM;EAAS;EAAM,SAAS,OAAO,OAAO,EAAE,GAAG,QAAQ,CAAC;CAAE,CAAC;AACtF;AAWA,SAAgB,MAAS,MAAoB,SAAsC;CACjF,OAAO,OAAO,OAAO;EAAE,MAAM;EAAS;EAAM,SAAS,OAAO,OAAO,EAAE,GAAG,QAAQ,CAAC;CAAE,CAAC;AACtF"}
@@ -0,0 +1,133 @@
1
+ import { O as Point, _ as Key, f as FreeState, m as GraphDefinition, z as View } from "./types-D6b86Rt1.js";
2
+ import { ReadonlyStore } from "@tanstack/store";
3
+ interface Endpoints {
4
+ readonly source: Key;
5
+ readonly target: Key;
6
+ }
7
+ type GraphTarget = {
8
+ readonly kind: "node";
9
+ readonly key: Key;
10
+ readonly datum: unknown;
11
+ } | {
12
+ readonly kind: "edge";
13
+ readonly key: Key;
14
+ readonly datum: unknown;
15
+ };
16
+ interface ElementKeys {
17
+ readonly nodes: readonly Key[];
18
+ readonly edges: readonly Key[];
19
+ }
20
+ interface ElementKeysInput {
21
+ readonly nodes?: Iterable<Key>;
22
+ readonly edges?: Iterable<Key>;
23
+ }
24
+ interface GraphPointerEvent {
25
+ readonly target: GraphTarget | null;
26
+ readonly point: Point;
27
+ readonly world: Point;
28
+ readonly originalEvent: MouseEvent;
29
+ }
30
+ interface GraphTargetEvent {
31
+ readonly target: GraphTarget;
32
+ readonly originalEvent: MouseEvent;
33
+ }
34
+ interface GraphDragEvent {
35
+ readonly target: GraphTarget & {
36
+ readonly kind: "node";
37
+ };
38
+ readonly keys: readonly Key[];
39
+ readonly point: Point;
40
+ readonly world: Point;
41
+ readonly originalEvent: PointerEvent;
42
+ }
43
+ type PositionOrigin = "drag" | "api";
44
+ interface GraphPositionEvent {
45
+ readonly origin: PositionOrigin;
46
+ readonly positions: ReadonlyMap<Key, Point>;
47
+ }
48
+ interface GraphEvents {
49
+ readonly click: GraphPointerEvent;
50
+ readonly doubleclick: GraphPointerEvent;
51
+ readonly contextmenu: GraphPointerEvent;
52
+ readonly pointerenter: GraphTargetEvent;
53
+ readonly pointerleave: GraphTargetEvent;
54
+ readonly dragstart: GraphDragEvent;
55
+ readonly drag: GraphDragEvent;
56
+ readonly dragend: GraphDragEvent;
57
+ readonly positionchange: GraphPositionEvent;
58
+ readonly selectionchange: ElementKeys;
59
+ readonly viewchange: {
60
+ readonly view: View;
61
+ };
62
+ }
63
+ type GraphEventName = keyof GraphEvents;
64
+ type GraphEventHandler<K extends GraphEventName> = (event: GraphEvents[K]) => void;
65
+ interface GraphState<S extends string = string> {
66
+ readonly view: View;
67
+ readonly width: number;
68
+ readonly height: number;
69
+ readonly hovered: GraphTarget | null;
70
+ readonly selection: ElementKeys;
71
+ readonly states: { readonly [K in FreeState<S>]: ElementKeys; };
72
+ readonly positionsVersion: number;
73
+ }
74
+ type GraphStore<S extends string = string> = ReadonlyStore<GraphState<S>>;
75
+ interface ViewOptions {
76
+ readonly duration?: number;
77
+ }
78
+ interface FitOptions extends ViewOptions {
79
+ readonly padding?: number;
80
+ }
81
+ interface GraphView {
82
+ get(): View;
83
+ set(view: View, options?: ViewOptions): void;
84
+ fit(keys?: Iterable<Key>, options?: FitOptions): void;
85
+ zoomBy(factor: number, options?: ViewOptions): void;
86
+ toScreen(point: Point): Point;
87
+ toWorld(point: Point): Point;
88
+ }
89
+ interface GraphElement {
90
+ readonly kind: "node" | "edge";
91
+ readonly key: Key;
92
+ }
93
+ interface GraphSelection {
94
+ get(): ElementKeys;
95
+ set(keys: ElementKeysInput): void;
96
+ clear(): void;
97
+ }
98
+ interface GraphStates<N extends string = string> {
99
+ set(name: N, keys: ElementKeysInput): void;
100
+ add(name: N, keys: ElementKeysInput): void;
101
+ remove(name: N, keys: ElementKeysInput): void;
102
+ clear(name?: N): void;
103
+ has(name: N, element: GraphElement): boolean;
104
+ }
105
+ interface GraphPositions {
106
+ get(key: Key): Point | undefined;
107
+ set(entries: Iterable<readonly [Key, Point]>, options?: ViewOptions): void;
108
+ }
109
+ interface MountGraphOptions<S extends string = string> {
110
+ readonly definition: GraphDefinition<S>;
111
+ readonly ariaLabel: string;
112
+ readonly initialView?: View;
113
+ readonly selection?: ElementKeysInput;
114
+ readonly onSelectionChange?: (selection: ElementKeys) => void;
115
+ }
116
+ interface GraphInstance<S extends string = string> {
117
+ readonly store: GraphStore<S>;
118
+ readonly view: GraphView;
119
+ readonly selection: GraphSelection;
120
+ readonly states: GraphStates<FreeState<S>>;
121
+ readonly positions: GraphPositions;
122
+ readonly element: HTMLElement;
123
+ pick(point: Point): GraphTarget | null;
124
+ neighbors(key: Key): Key[];
125
+ edgesOf(key: Key): Key[];
126
+ endpoints(key: Key): Endpoints | undefined;
127
+ on<K extends GraphEventName>(name: K, handler: GraphEventHandler<K>): () => void;
128
+ update(options: Partial<Omit<MountGraphOptions<S>, "initialView">>): void;
129
+ destroy(): void;
130
+ }
131
+ declare function mountGraph<S extends string = string>(container: HTMLElement, options: MountGraphOptions<S>): GraphInstance<S>;
132
+ export { PositionOrigin as C, GraphTargetEvent as S, GraphEventName as _, GraphSelection as a, GraphPositionEvent as b, GraphStore as c, ViewOptions as d, mountGraph as f, GraphEventHandler as g, GraphDragEvent as h, GraphPositions as i, GraphView as l, ElementKeysInput as m, GraphElement as n, GraphState as o, ElementKeys as p, GraphInstance as r, GraphStates as s, FitOptions as t, MountGraphOptions as u, GraphEvents as v, GraphTarget as x, GraphPointerEvent as y };
133
+ //# sourceMappingURL=mount-graph-B88WGOQu.d.ts.map