@kgdiff/g6 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.
Files changed (73) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +149 -2
  3. package/dist/color.d.ts +24 -0
  4. package/dist/color.d.ts.map +1 -0
  5. package/dist/color.js +95 -0
  6. package/dist/color.js.map +1 -0
  7. package/dist/constants.d.ts +81 -0
  8. package/dist/constants.d.ts.map +1 -0
  9. package/dist/constants.js +81 -0
  10. package/dist/constants.js.map +1 -0
  11. package/dist/controller.d.ts +126 -0
  12. package/dist/controller.d.ts.map +1 -0
  13. package/dist/controller.js +422 -0
  14. package/dist/controller.js.map +1 -0
  15. package/dist/geometry.d.ts +19 -0
  16. package/dist/geometry.d.ts.map +1 -0
  17. package/dist/geometry.js +43 -0
  18. package/dist/geometry.js.map +1 -0
  19. package/dist/index.d.ts +101 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +99 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/locator.d.ts +24 -0
  24. package/dist/locator.d.ts.map +1 -0
  25. package/dist/locator.js +69 -0
  26. package/dist/locator.js.map +1 -0
  27. package/dist/map-context.d.ts +70 -0
  28. package/dist/map-context.d.ts.map +1 -0
  29. package/dist/map-context.js +44 -0
  30. package/dist/map-context.js.map +1 -0
  31. package/dist/map-edge.d.ts +19 -0
  32. package/dist/map-edge.d.ts.map +1 -0
  33. package/dist/map-edge.js +399 -0
  34. package/dist/map-edge.js.map +1 -0
  35. package/dist/map-node.d.ts +10 -0
  36. package/dist/map-node.d.ts.map +1 -0
  37. package/dist/map-node.js +243 -0
  38. package/dist/map-node.js.map +1 -0
  39. package/dist/map.d.ts +47 -0
  40. package/dist/map.d.ts.map +1 -0
  41. package/dist/map.js +92 -0
  42. package/dist/map.js.map +1 -0
  43. package/dist/node.d.ts +68 -0
  44. package/dist/node.d.ts.map +1 -0
  45. package/dist/node.js +189 -0
  46. package/dist/node.js.map +1 -0
  47. package/dist/options.d.ts +33 -0
  48. package/dist/options.d.ts.map +1 -0
  49. package/dist/options.js +172 -0
  50. package/dist/options.js.map +1 -0
  51. package/dist/patch.d.ts +45 -0
  52. package/dist/patch.d.ts.map +1 -0
  53. package/dist/patch.js +120 -0
  54. package/dist/patch.js.map +1 -0
  55. package/dist/replay.d.ts +20 -0
  56. package/dist/replay.d.ts.map +1 -0
  57. package/dist/replay.js +36 -0
  58. package/dist/replay.js.map +1 -0
  59. package/package.json +54 -3
  60. package/src/color.ts +101 -0
  61. package/src/constants.ts +96 -0
  62. package/src/controller.ts +517 -0
  63. package/src/geometry.ts +44 -0
  64. package/src/index.ts +140 -0
  65. package/src/locator.ts +72 -0
  66. package/src/map-context.ts +119 -0
  67. package/src/map-edge.ts +481 -0
  68. package/src/map-node.ts +272 -0
  69. package/src/map.ts +130 -0
  70. package/src/node.ts +240 -0
  71. package/src/options.ts +215 -0
  72. package/src/patch.ts +133 -0
  73. package/src/replay.ts +59 -0
package/dist/index.js ADDED
@@ -0,0 +1,99 @@
1
+ /**
2
+ * @kgdiff/g6: render kgdiff scenes with AntV G6 v5.
3
+ *
4
+ * For teams whose product already uses G6: the same visual language as the
5
+ * kgdiff viewer (docs/visual-language.md), driven by the same `VisualResolver`,
6
+ * expressed as G6 data, styles and animations.
7
+ *
8
+ * map.ts frame → GraphData (pure)
9
+ * node.ts `kgdiff-node`: circle + ring, glow / offset-ring halo, pulse, struck old name
10
+ * options.ts generated G6 options (no G6 theme, hover states, animations)
11
+ * controller.ts view state → frames → setData / draw; replay; LOD; interaction
12
+ * replay.ts replay sampling plan
13
+ */
14
+ import { Graph } from '@antv/g6';
15
+ import { DiffGraphControllerImpl } from './controller.js';
16
+ import { mapFrame } from './map.js';
17
+ import { registerKgdiffNode } from './node.js';
18
+ /**
19
+ * Convert a resolved frame into G6 v5 `GraphData`: one node per scene node, one edge per
20
+ * scene edge (+ glyph edges for merge/move arcs), with positions and fully resolved styles.
21
+ * Pure; no G6 runtime needed.
22
+ *
23
+ * - Ids: `idPrefix + union id` for scene nodes and edges; glyphs
24
+ * `idPrefix + 'kgdiff-glyph-' + kind + ':' + JSON([source key, target key])` (keys are union
25
+ * ids, or anchor keys; stable across frames, so G6 animates them); anchors
26
+ * `idPrefix + 'kgdiff-anchor-' + JSON(key)`; collapsed pills
27
+ * `idPrefix + 'kgdiff-collapsed-' + group id`. A collision gets a `#2`, `#3`… suffix.
28
+ * - `datum.data` is a `KgdiffDatumData`: kind, scene index, hunk, family (flat primitives).
29
+ * - Edges are `line` or `quadratic` (`curveOffset` from the scene curvature) between the
30
+ * frame's endpoint nodes. Glyph arcs become extra edges between the visible nodes whose discs
31
+ * hold their endpoints; an end with no drawn node there (a split target before it emerges)
32
+ * attaches to an anchor: an invisible, non-interactive point node (`data.kgdiff: 'anchor'`),
33
+ * shared by the arcs of a frame. Arcs with both ends on one node are omitted. Pivot dots become
34
+ * small non-interactive nodes on their node's outline.
35
+ * - Sizes the scene gives in px are world units here (exact at zoom 1). Level of detail is
36
+ * evaluated at zoom 1: labels / badges / arrowheads whose `minZoom` is above 1 are switched
37
+ * off (`createDiffGraph` re-evaluates it at the live zoom).
38
+ * - Ring, glow, pulse and the struck old name use extra style keys drawn by the `kgdiff-node`
39
+ * type that `createDiffGraph` registers; on G6's plain `circle` they are ignored and the halo
40
+ * falls back to G6's built-in band.
41
+ *
42
+ * Deterministic; O(N + E + glyphs). Does not mutate its inputs.
43
+ *
44
+ * @throws KgdiffError(`invalid-input`) when `frame` was not resolved for `scene`.
45
+ */
46
+ export function toG6Data(scene, frame, options = {}) {
47
+ return mapFrame(scene, frame, {
48
+ idPrefix: options.idPrefix ?? '',
49
+ keepHidden: options.keepHidden ?? false,
50
+ zoom: 1,
51
+ }).data;
52
+ }
53
+ const wait = (ms) => new Promise((resolve) => {
54
+ setTimeout(resolve, Math.max(0, ms));
55
+ });
56
+ /**
57
+ * Create a G6 graph in `container` that renders `scene`.
58
+ *
59
+ * The graph uses no G6 theme (`theme: false`): kgdiff's own encodings, a background plugin in
60
+ * `theme.canvas.background`, the `kgdiff-node` node type and a private hover state. Each view
61
+ * change resolves one frame and sends G6 only the difference to the previous one (`addData`,
62
+ * `updateData` with just the changed style keys, `removeData`) before `graph.draw()`; G6
63
+ * animates it over `theme.motion.base` (layers, selection, themes) or the timeline (replay).
64
+ * Calls made while a draw is still running are merged into one update (latest wins). Elements
65
+ * the caller adds to `graph` are left alone; do not `setData` / `clear` the graph yourself.
66
+ *
67
+ * - `options.g6` is merged over the generated options: `behaviors` / `plugins` / `transforms`
68
+ * are appended, plain objects merge recursively, other values replace. `animation: false`
69
+ * disables every animation (replay still keeps its pace).
70
+ * - Interaction (`interactive`, default true): zoom-canvas, drag-canvas, hover (stroke + label
71
+ * like the native viewer), click a changed element → select its hunk, click an unchanged node
72
+ * → select it, click the canvas → clear.
73
+ * - Level of detail follows the camera: crossing a label / badge / arrow threshold re-maps.
74
+ * - `selectHunk(i)` spotlights the hunk and pans to its nodes; in the replay layer it seeks to the
75
+ * end of the hunk's window. `playReplay({ speed })` (default 1×) resolves every window (every
76
+ * chapter in chapter mode) at the end of its spotlight, mid-transform, settle start and end,
77
+ * and lets G6 animate between them; the camera pans to units less than 70% in view. It
78
+ * resolves when finished or `stop()`ped; `setLayer` / `selectHunk` stop it.
79
+ *
80
+ * @throws KgdiffError(`invalid-input`) for invalid arguments (also from the controller's methods,
81
+ * which reject at once after `destroy()`; calls still pending at `destroy()` resolve).
82
+ */
83
+ export async function createDiffGraph(container, scene, options = {}) {
84
+ registerKgdiffNode();
85
+ const controller = new DiffGraphControllerImpl(scene, options, {
86
+ createGraph: (graphOptions) => new Graph(graphOptions),
87
+ wait,
88
+ deadline: wait,
89
+ });
90
+ try {
91
+ await controller.start(container);
92
+ }
93
+ catch (error) {
94
+ controller.destroy();
95
+ throw error;
96
+ }
97
+ return controller;
98
+ }
99
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file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C,SAAS,CAAC,CAAC;IACpC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,UAAU,CAAC,OAAO,EAAE,CAAC;QACrB,MAAM,KAAK,CAAC;IACd,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Which node is at a point? Glyphs only carry endpoint coordinates, so glyph edges are attached
3
+ * to the node whose disc contains the endpoint. A uniform grid keeps each query O(1) on average
4
+ * (O(N) to build, done lazily once per frame and only when the frame has glyphs).
5
+ */
6
+ import type { NodeVisual } from '@kgdiff/scene';
7
+ export declare class NodeLocator {
8
+ private readonly nodes;
9
+ private readonly cells;
10
+ private readonly size;
11
+ private readonly reach;
12
+ /**
13
+ * @param nodes frame nodes (positions and radii, world units)
14
+ * @param accept which node indices may be returned (e.g. visible, present in the output)
15
+ */
16
+ constructor(nodes: readonly NodeVisual[], accept: (index: number) => boolean);
17
+ private key;
18
+ /**
19
+ * Index of the accepted node nearest to (x, y) among those within `r + slack` of it, or -1.
20
+ * Ties go to the lower index, so results are deterministic.
21
+ */
22
+ nearest(x: number, y: number, slack: number): number;
23
+ }
24
+ //# sourceMappingURL=locator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locator.d.ts","sourceRoot":"","sources":["../src/locator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,qBAAa,WAAW;IAUpB,OAAO,CAAC,QAAQ,CAAC,KAAK;IATxB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA+B;IACrD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAE/B;;;OAGG;IACH,YACmB,KAAK,EAAE,SAAS,UAAU,EAAE,EAC7C,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,EAmBnC;IAED,OAAO,CAAC,GAAG;IAIX;;;OAGG;IACH,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAuBnD;CACF"}
@@ -0,0 +1,69 @@
1
+ export class NodeLocator {
2
+ nodes;
3
+ cells = new Map();
4
+ size;
5
+ reach;
6
+ /**
7
+ * @param nodes frame nodes (positions and radii, world units)
8
+ * @param accept which node indices may be returned (e.g. visible, present in the output)
9
+ */
10
+ constructor(nodes, accept) {
11
+ this.nodes = nodes;
12
+ let maxR = 0;
13
+ const members = [];
14
+ for (let i = 0; i < nodes.length; i++) {
15
+ const n = nodes[i];
16
+ if (!accept(i) || !Number.isFinite(n.x) || !Number.isFinite(n.y))
17
+ continue;
18
+ members.push(i);
19
+ if (n.r > maxR)
20
+ maxR = n.r;
21
+ }
22
+ this.reach = maxR;
23
+ this.size = Math.max(16, 2 * maxR);
24
+ for (const i of members) {
25
+ const n = nodes[i];
26
+ const key = this.key(Math.floor(n.x / this.size), Math.floor(n.y / this.size));
27
+ const cell = this.cells.get(key);
28
+ if (cell === undefined)
29
+ this.cells.set(key, [i]);
30
+ else
31
+ cell.push(i);
32
+ }
33
+ }
34
+ key(ix, iy) {
35
+ return `${ix}:${iy}`;
36
+ }
37
+ /**
38
+ * Index of the accepted node nearest to (x, y) among those within `r + slack` of it, or -1.
39
+ * Ties go to the lower index, so results are deterministic.
40
+ */
41
+ nearest(x, y, slack) {
42
+ if (!Number.isFinite(x) || !Number.isFinite(y))
43
+ return -1;
44
+ const ix = Math.floor(x / this.size);
45
+ const iy = Math.floor(y / this.size);
46
+ const rings = Math.max(1, Math.ceil((this.reach + Math.max(0, slack)) / this.size));
47
+ let best = -1;
48
+ let bestD = Number.POSITIVE_INFINITY;
49
+ for (let dx = -rings; dx <= rings; dx++) {
50
+ for (let dy = -rings; dy <= rings; dy++) {
51
+ const cell = this.cells.get(this.key(ix + dx, iy + dy));
52
+ if (cell === undefined)
53
+ continue;
54
+ for (const i of cell) {
55
+ const n = this.nodes[i];
56
+ const d = Math.hypot(n.x - x, n.y - y);
57
+ if (d > Math.max(0, n.r) + slack)
58
+ continue;
59
+ if (d < bestD || (d === bestD && i < best)) {
60
+ best = i;
61
+ bestD = d;
62
+ }
63
+ }
64
+ }
65
+ }
66
+ return best;
67
+ }
68
+ }
69
+ //# sourceMappingURL=locator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locator.js","sourceRoot":"","sources":["../src/locator.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,WAAW;IAUH,KAAK;IATP,KAAK,GAAG,IAAI,GAAG,EAAoB,CAAC;IACpC,IAAI,CAAS;IACb,KAAK,CAAS;IAE/B;;;OAGG;IACH,YACmB,KAA4B,EAC7C,MAAkC;qBADjB,KAAK;QAGtB,IAAI,IAAI,GAAG,CAAC,CAAC;QACb,MAAM,OAAO,GAAa,EAAE,CAAC;QAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAe,CAAC;YACjC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;gBAAE,SAAS;YAC3E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAChB,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI;gBAAE,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC;QAC7B,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;QACnC,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;YACxB,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AG,CAAC,CAAC,CAAC;QACd,IAAI,KAAK,GAAG,MAAM,CAAC,iBAAiB,CAAC;QACrC,KAAK,IAAI,EAAE,GAAG,CAAC,KAAK,EAAE,EAAE,IAAI,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC;YACxC,KAAK,IAAI,EAAE,GAAG,CAAC,KAAK,EAAE,EAAE,IAAI,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC;gBACxC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;gBACxD,IAAI,IAAI,KAAK,SAAS;oBAAE,SAAS;gBACjC,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;oBACrB,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAe,CAAC;oBACtC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;oBACvC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK;wBAAE,SAAS;oBAC3C,IAAI,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC,KAAK,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;wBAC3C,IAAI,GAAG,CAAC,CAAC;wBACT,KAAK,GAAG,CAAC,CAAC;oBACZ,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Shared state and helpers of one `mapFrame` call (see map.ts): the element metadata type, LOD
3
+ * and id bookkeeping, and label text resolution.
4
+ */
5
+ import type { EdgeData, NodeData } from '@antv/g6';
6
+ import type { FrameVisuals, LabelVisual, Scene, Theme } from '@kgdiff/scene';
7
+ import type { NodeLocator } from './locator.js';
8
+ export type NodeStyle = NonNullable<NodeData['style']>;
9
+ export type EdgeStyle = NonNullable<EdgeData['style']>;
10
+ /** Kind of a generated element, stored in `datum.data.kgdiff`. */
11
+ export type ElementKind = 'node' | 'edge' | 'glyph' | 'anchor' | 'collapsed';
12
+ /**
13
+ * `datum.data` of every generated element. Flat primitives only (G6 compares `data` shallowly).
14
+ * - `index`: scene node / edge index; for glyphs the index in `frame.glyphs`; for collapsed
15
+ * pills the index in `frame.collapsed`; for anchors (invisible points glyph arcs attach to
16
+ * where no node is drawn) the scene node at that point, or -1.
17
+ * - `hunk`: index into `scene.hunks` (glyphs: the hunk of their source node, else target), or -1.
18
+ * - `label`: the element's plain label (revealed on hover even when the frame hides it).
19
+ */
20
+ export type KgdiffDatumData = {
21
+ readonly kgdiff: ElementKind;
22
+ readonly index: number;
23
+ readonly hunk: number;
24
+ readonly family: string;
25
+ readonly changed: boolean;
26
+ readonly label: string;
27
+ readonly glyph: string;
28
+ };
29
+ export interface Ctx {
30
+ readonly scene: Scene;
31
+ readonly frame: FrameVisuals;
32
+ readonly theme: Theme;
33
+ readonly bg: string;
34
+ readonly prefix: string;
35
+ readonly keepHidden: boolean;
36
+ readonly zoom: number;
37
+ /** 1 when the node is part of the output. */
38
+ readonly present: Uint8Array;
39
+ /** G6 id of every node index (also those left out). */
40
+ readonly nodeIds: string[];
41
+ readonly used: Set<string>;
42
+ readonly lod: Set<number>;
43
+ /** Drawn nodes, for attaching glyph ends (built lazily). */
44
+ locator: NodeLocator | null;
45
+ /** All scene nodes, for naming glyph anchors (built lazily). */
46
+ anyLocator: NodeLocator | null;
47
+ /** Anchor key → anchor node id, shared by the glyphs of one frame. */
48
+ readonly anchors: Map<string, string>;
49
+ /** Frozen default styles, built once per frame and spread into every element's style. */
50
+ nodeBase: Readonly<NodeStyle> | null;
51
+ edgeBase: Readonly<EdgeStyle> | null;
52
+ }
53
+ /** LOD: visible from `minZoom` on; a missing / NaN threshold shows it (native renderer rule). */
54
+ export declare function shown(minZoom: number, zoom: number): boolean;
55
+ export declare function noteLod(ctx: Ctx, minZoom: number): void;
56
+ /** A unique id: `base`, else `base#2`, `base#3`… (deterministic in output order). */
57
+ export declare function claim(ctx: Ctx, base: string): string;
58
+ export interface Text {
59
+ readonly text: string;
60
+ readonly show: boolean;
61
+ readonly fill: string;
62
+ readonly size: number;
63
+ readonly weight: number;
64
+ /** Absolute (owner alpha × label alpha). */
65
+ readonly opacity: number;
66
+ readonly strike: boolean;
67
+ readonly offset: number;
68
+ }
69
+ export declare function text(l: LabelVisual | null, ownerAlpha: number, ctx: Ctx, fallbackSize: number, fallbackColor: string): Text;
70
+ //# sourceMappingURL=map-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map-context.d.ts","sourceRoot":"","sources":["../src/map-context.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAE7E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,MAAM,SAAS,GAAG,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;AACvD,MAAM,MAAM,SAAS,GAAG,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;AAEvD,kEAAkE;AAClE,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,WAAW,CAAC;AAE7E;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,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AgB,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAEvD;AAED,qFAAqF;AACrF,wBAAgB,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAKpD;AAED,MAAM,WAAW,IAAI;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,4CAA4C;IAC5C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,IAAI,CAClB,CAAC,EAAE,WAAW,GAAG,IAAI,EACrB,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,GAAG,EACR,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,GACpB,IAAI,CAyBN"}
@@ -0,0 +1,44 @@
1
+ import { finite, unit } from './geometry.js';
2
+ /** LOD: visible from `minZoom` on; a missing / NaN threshold shows it (native renderer rule). */
3
+ export function shown(minZoom, zoom) {
4
+ return !(zoom < minZoom);
5
+ }
6
+ export function noteLod(ctx, minZoom) {
7
+ if (minZoom > 0 && Number.isFinite(minZoom))
8
+ ctx.lod.add(minZoom);
9
+ }
10
+ /** A unique id: `base`, else `base#2`, `base#3`… (deterministic in output order). */
11
+ export function claim(ctx, base) {
12
+ let id = base;
13
+ for (let k = 2; ctx.used.has(id); k++)
14
+ id = `${base}#${k}`;
15
+ ctx.used.add(id);
16
+ return id;
17
+ }
18
+ export function text(l, ownerAlpha, ctx, fallbackSize, fallbackColor) {
19
+ if (l === null) {
20
+ return {
21
+ text: '',
22
+ show: false,
23
+ fill: fallbackColor,
24
+ size: fallbackSize,
25
+ weight: ctx.theme.font.weightRegular,
26
+ opacity: 0,
27
+ strike: false,
28
+ offset: 0,
29
+ };
30
+ }
31
+ noteLod(ctx, l.minZoom);
32
+ const opacity = unit(ownerAlpha * l.alpha);
33
+ return {
34
+ text: l.text,
35
+ show: l.text.length > 0 && opacity > 0 && shown(l.minZoom, ctx.zoom),
36
+ fill: l.color,
37
+ size: finite(l.size, fallbackSize),
38
+ weight: finite(l.weight, ctx.theme.font.weightRegular),
39
+ opacity,
40
+ strike: l.strike,
41
+ offset: finite(l.offset, 0),
42
+ };
43
+ }
44
+ //# sourceMappingURL=map-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map-context.js","sourceRoot":"","sources":["../src/map-context.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAoD7C,iGAAiG;AACjG,MAAM,UAAU,KAAK,CAAC,OAAe,EAAE,IAAY;IACjD,OAAO,CAAC,CAAC,IAAI,GAAG,OAAO,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,GAAQ,EAAE,OAAe;IAC/C,IAAI,OAAO,GAAG,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACpE,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,KAAK,CAAC,GAAQ,EAAE,IAAY;IAC1C,IAAI,EAAE,GAAG,IAAI,CAAC;IACd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;QAAE,EAAE,GAAG,GAAG,IAAI,IAAI,CAAC,EAAE,CAAC;IAC3D,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACjB,OAAO,EAAE,CAAC;AACZ,CAAC;AAcD,MAAM,UAAU,IAAI,CAClB,CAAqB,EACrB,UAAkB,EAClB,GAAQ,EACR,YAAoB,EACpB,aAAqB;IAErB,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;QACf,OAAO;YACL,IAAI,EAAE,EAAE;YACR,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,aAAa;YACnB,IAAI,EAAE,YAAY;YAClB,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa;YACpC,OAAO,EAAE,CAAC;YACV,MAAM,EAAE,KAAK;YACb,MAAM,EAAE,CAAC;SACV,CAAC;IACJ,CAAC;IACD,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;IACxB,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;IAC3C,OAAO;QACL,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC;QACpE,IAAI,EAAE,CAAC,CAAC,KAAK;QACb,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,YAAY,CAAC;QAClC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC;QACtD,OAAO;QACP,MAAM,EAAE,CAAC,CAAC,MAAM;QAChB,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;KAC5B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Scene edges and glyphs → G6 edge data (glyph arcs) or small nodes (pivot dots); see map.ts
3
+ * for the conventions.
4
+ */
5
+ import type { EdgeData, NodeData } from '@antv/g6';
6
+ import type { EdgeVisual, GlyphVisual, SceneEdge } from '@kgdiff/scene';
7
+ import { type Ctx } from './map-context.js';
8
+ export declare function mapEdge(se: SceneEdge, ev: EdgeVisual, ctx: Ctx): EdgeData | null;
9
+ export type GlyphDatum = {
10
+ readonly node: NodeData;
11
+ } | {
12
+ readonly edge: EdgeData;
13
+ };
14
+ /**
15
+ * A glyph as G6 data: pivots become nodes, everything else an edge between the ends' nodes or
16
+ * anchors (anchor nodes are pushed to `nodes`). Null when the glyph is invisible or degenerate.
17
+ */
18
+ export declare function mapGlyph(g: GlyphVisual, i: number, ctx: Ctx, nodes: NodeData[]): GlyphDatum | null;
19
+ //# sourceMappingURL=map-edge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map-edge.d.ts","sourceRoot":"","sources":["../src/map-edge.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAc,SAAS,EAAa,MAAM,eAAe,CAAC;AAiB/F,OAAO,EACL,KAAK,GAAG,EAST,MAAM,kBAAkB,CAAC;AAmN1B,wBAAgB,OAAO,CAAC,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,GAAG,QAAQ,GAAG,IAAI,CAkDhF;AAiHD,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC;AAEnF;;;GAGG;AACH,wBAAgB,QAAQ,CACtB,CAAC,EAAE,WAAW,EACd,CAAC,EAAE,MAAM,EACT,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,QAAQ,EAAE,GAChB,UAAU,GAAG,IAAI,CA+DnB"}