@cosmos.gl/deck-layers 3.5.0-beta.2

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/LICENCE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright Contributors to the cosmos.gl project.
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 ADDED
@@ -0,0 +1,149 @@
1
+ # @cosmos.gl/deck-layers
2
+
3
+ [deck.gl](https://deck.gl) layers for the [cosmos.gl](https://github.com/cosmosgl/graph)
4
+ GPU force simulation — **zero position readback**. The simulation runs on deck.gl's own
5
+ luma.gl device and the layers sample its live position texture with `texelFetch`:
6
+ point coordinates never leave the GPU, at hundreds of thousands of points.
7
+
8
+ Versions are released in lockstep with `@cosmos.gl/graph` — install matching versions.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install @cosmos.gl/deck-layers @cosmos.gl/graph @deck.gl/core @luma.gl/core @luma.gl/engine
14
+ ```
15
+
16
+ `@cosmos.gl/graph`, `@deck.gl/core` and `@luma.gl/*` are peer dependencies: the whole
17
+ point is that cosmos, deck and the layers share **one** luma.gl device, which requires
18
+ one luma.gl installation. deck.gl `~9.3` pairs with luma.gl `~9.3`.
19
+
20
+ ## CosmosGraphLayer
21
+
22
+ The batteries-included layer: give it points and links, it owns the rest. It creates the
23
+ `GraphSimulation` on deck's device, ingests your data, advances the simulation once per
24
+ frame from deck's timeline while it runs, and lets deck go idle when it settles — no
25
+ render-loop wiring, no `_animate`, no device plumbing.
26
+
27
+ ```js
28
+ import { Deck, OrthographicView } from '@deck.gl/core'
29
+ import { CosmosGraphLayer } from '@cosmos.gl/deck-layers'
30
+
31
+ new Deck({
32
+ views: new OrthographicView(),
33
+ initialViewState: { target: [2048, 2048, 0], zoom: -2 },
34
+ controller: true,
35
+ layers: [
36
+ new CosmosGraphLayer({
37
+ id: 'graph',
38
+ // cosmos-native binary mode — zero copies:
39
+ points: { length: pointCount, initialPositions }, // Float32Array [x0, y0, x1, y1, …]
40
+ links: linkIndices, // Float32Array [src0, tgt0, src1, tgt1, …]
41
+ pickable: true,
42
+ enablePointDrag: true,
43
+ autoHighlight: true,
44
+ }),
45
+ ],
46
+ })
47
+ ```
48
+
49
+ Or hand it plain objects and accessors, the deck-idiomatic way — the layer builds the
50
+ id→index mapping, seeds unset positions randomly, and picking returns your original
51
+ objects:
52
+
53
+ ```js
54
+ new CosmosGraphLayer({
55
+ id: 'graph',
56
+ points: nodes, // e.g. [{ id: 'a', group: 0 }, …]
57
+ links: edges, // e.g. [{ source: 'a', target: 'b' }, …]
58
+ getPointId: (p) => p.id, // lets links reference ids
59
+ getPointColor: (p) => COLORS[p.group],
60
+ getPointSize: (p) => p.weight,
61
+ simulationConfig: { simulationGravity: 0.25, simulationRepulsion: 1.5 },
62
+ onSimulationCreated: (simulation) => { /* pause, pin, restart, sparse writes */ },
63
+ pickable: true,
64
+ })
65
+ ```
66
+
67
+ - **Picking**: `info.elementType` is `'point'` or `'link'`, `info.index` is the
68
+ point/link index, and `info.object` is your original record in object mode.
69
+ - **Dragging** (`enablePointDrag: true`): a drag grabs the point — pinned on grab, moved
70
+ with the pointer, released per `unpinOnDragEnd`; `dragReheatAlpha` restarts the
71
+ simulation at a low alpha so the graph responds around the moving point. View panning
72
+ is suppressed only while a point is grabbed.
73
+ - **Colors** follow the deck.gl convention: RGBA channels in 0..255.
74
+ - **Simulation control**: pass forces and callbacks through `simulationConfig`
75
+ (`GraphSimulationConfig` from `@cosmos.gl/graph`); take the wheel through
76
+ `onSimulationCreated`.
77
+
78
+ Live examples: the *Integrations* section of the
79
+ [cosmos.gl Storybook](https://cosmosgl.github.io/graph).
80
+
81
+ ## The app-owned tier: primitive layers
82
+
83
+ `CosmosPointsLayer` and `CosmosLinksLayer` are the pure renderers underneath the
84
+ composite, for full control: own the `GraphSimulation`, decide when it steps, share one
85
+ simulation across visualizations, or compose your own layers between points and links.
86
+ Anything exposing `getPointPositionTexture()` (the `PositionTextureSource` type)
87
+ can feed them.
88
+
89
+ ```js
90
+ let deck
91
+ const devicePromise = new Promise((resolve) => {
92
+ deck = new Deck({ /* … */, _animate: true, onDeviceInitialized: resolve, layers: [] })
93
+ })
94
+
95
+ const simulation = new GraphSimulation(config, devicePromise) // deck's device, never destroyed by cosmos
96
+ simulation.setPointPositions(positions)
97
+ simulation.setLinks(links)
98
+ simulation.applyData()
99
+ await simulation.ready
100
+
101
+ deck.setProps({
102
+ onBeforeRender: () => { if (simulation.isSimulationRunning) simulation.step() },
103
+ layers: [
104
+ new CosmosLinksLayer({
105
+ id: 'links',
106
+ graph: simulation,
107
+ // the cosmos pair array read as two interleaved binary attributes — no copy
108
+ data: {
109
+ length: links.length / 2,
110
+ attributes: {
111
+ getLinkSource: { value: links, size: 1, stride: 8 },
112
+ getLinkTarget: { value: links, size: 1, offset: 4, stride: 8 },
113
+ },
114
+ },
115
+ }),
116
+ new CosmosPointsLayer({ id: 'points', graph: simulation, data: { length: pointCount } }),
117
+ ],
118
+ })
119
+
120
+ // Teardown order matters: the device belongs to deck.
121
+ simulation.destroy()
122
+ deck.finalize()
123
+ ```
124
+
125
+ ## The universal fallback: CPU readback
126
+
127
+ When you need stock deck layers (attribute transitions, extensions, text at positions),
128
+ run a headless simulation and snapshot positions into ordinary attributes — the same
129
+ recipe works with any rendering host, at the cost of a per-snapshot GPU→CPU copy.
130
+ Practical up to tens of thousands of points; throttle the snapshots.
131
+
132
+ ```js
133
+ const graph = new GraphSimulation(config) // its own hidden device
134
+ // per animation frame: graph.step()
135
+ // every ~100 ms: await graph.getPointPositionsAsync(positions), then update
136
+ // a ScatterplotLayer/LineLayer with `data: {length, attributes}` and an updateTrigger
137
+ ```
138
+
139
+ ## Constraints
140
+
141
+ - **WebGL 2 only** — the cosmos.gl simulation is WebGL-only; the layer throws an
142
+ actionable error on a WebGPU device.
143
+ - **One luma.gl installation** — a `Device` shared across duplicate luma.gl copies is
144
+ not a supported boundary; keep the peer versions aligned.
145
+ - **2D** — cosmos.gl simulates in a 2D space; `OrthographicView` is the natural fit.
146
+
147
+ ## License
148
+
149
+ MIT
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Premultiplied-style alpha blending with depth writes disabled: points and
3
+ * links are drawn back-to-front by layer order, never by depth.
4
+ *
5
+ * Wire through `defaultProps.parameters`: before every draw, deck resets each
6
+ * model's pipeline parameters from `layer.props.parameters`. Parameters given
7
+ * only at `Model` creation last one frame.
8
+ *
9
+ * Declare the default with `compare: 2`, like the base layer does — a plain
10
+ * object default would drop deep comparison, and every new-but-equal
11
+ * `parameters` object from the caller would count as a prop change.
12
+ */
13
+ export declare const BLEND_PARAMETERS: {
14
+ readonly depthWriteEnabled: false;
15
+ readonly depthCompare: "always";
16
+ readonly blend: true;
17
+ readonly blendColorOperation: "add";
18
+ readonly blendColorSrcFactor: "src-alpha";
19
+ readonly blendColorDstFactor: "one-minus-src-alpha";
20
+ readonly blendAlphaOperation: "add";
21
+ readonly blendAlphaSrcFactor: "one";
22
+ readonly blendAlphaDstFactor: "one-minus-src-alpha";
23
+ };
@@ -0,0 +1,168 @@
1
+ import { CompositeLayer, Accessor, Color, DefaultProps, GetPickingInfoParams, Layer, LayerContext, LayerProps, PickingInfo, Unit, UpdateParameters } from '@deck.gl/core';
2
+ import { GraphSimulation, GraphSimulationConfig } from '@cosmos.gl/graph';
3
+ /**
4
+ * Points input: an array to run accessors over (picking returns the original
5
+ * objects), or the cosmos-native binary form — a point count plus optional
6
+ * `[x0, y0, x1, y1, …]` initial positions. Points without given positions are
7
+ * seeded randomly inside the simulation space.
8
+ */
9
+ export type CosmosGraphPoints<PointDataT> = readonly PointDataT[] | {
10
+ length: number;
11
+ initialPositions?: Float32Array;
12
+ /** Optional binary styling channels, keyed by accessor name (`getPointColor`, `getPointSize`). */
13
+ attributes?: Record<string, unknown>;
14
+ };
15
+ /**
16
+ * Links input: an array to run accessors over, or the cosmos-native
17
+ * `[source0, target0, source1, target1, …]` array of point indices.
18
+ * An array link whose source or target does not resolve to a point is dropped
19
+ * from both the simulation and the rendering, with one warning per data change.
20
+ */
21
+ export type CosmosGraphLinks<LinkDataT> = readonly LinkDataT[] | Float32Array;
22
+ /** Picking info from a CosmosGraphLayer: which kind of element was hit. */
23
+ export type CosmosGraphPickingInfo = PickingInfo & {
24
+ elementType?: 'point' | 'link';
25
+ };
26
+ export type CosmosGraphLayerProps<PointDataT = unknown, LinkDataT = unknown> = CosmosGraphLayerOwnProps<PointDataT, LinkDataT> & LayerProps;
27
+ type CosmosGraphLayerOwnProps<PointDataT, LinkDataT> = {
28
+ /** One entry per point — an array of your objects, or `{ length, initialPositions? }`. */
29
+ points: CosmosGraphPoints<PointDataT>;
30
+ /** One entry per link — an array of your objects, or a flat point-index pair array. */
31
+ links?: CosmosGraphLinks<LinkDataT> | null;
32
+ /**
33
+ * Stable point id accessor. When provided (with array points), link
34
+ * accessors may return ids instead of point indices.
35
+ */
36
+ getPointId?: Accessor<PointDataT, string | number> | null;
37
+ /** Initial `[x, y]` position accessor for array points; points it leaves undefined are seeded randomly. */
38
+ getPointPosition?: Accessor<PointDataT, readonly [number, number] | null | undefined> | null;
39
+ /**
40
+ * Point diameter accessor, in `pointSizeUnits`; `0` hides the point.
41
+ * @default 4
42
+ */
43
+ getPointSize?: Accessor<PointDataT, number>;
44
+ /**
45
+ * Point RGBA color accessor, channels in 0..255.
46
+ * @default [74, 92, 191, 230]
47
+ */
48
+ getPointColor?: Accessor<PointDataT, Color>;
49
+ /**
50
+ * The units of the point diameter.
51
+ * @default 'pixels'
52
+ */
53
+ pointSizeUnits?: Unit;
54
+ /**
55
+ * Source accessor for array links: a point index, or a point id when
56
+ * `getPointId` is set.
57
+ * @default l => l.source
58
+ */
59
+ getLinkSource?: Accessor<LinkDataT, string | number>;
60
+ /**
61
+ * Target accessor for array links: a point index, or a point id when
62
+ * `getPointId` is set.
63
+ * @default l => l.target
64
+ */
65
+ getLinkTarget?: Accessor<LinkDataT, string | number>;
66
+ /**
67
+ * Link RGBA color accessor, channels in 0..255.
68
+ * @default [94, 115, 194, 64]
69
+ */
70
+ getLinkColor?: Accessor<LinkDataT, Color>;
71
+ /**
72
+ * Link width accessor, in `linkWidthUnits`.
73
+ * @default 1
74
+ */
75
+ getLinkWidth?: Accessor<LinkDataT, number>;
76
+ /**
77
+ * The units of the link width.
78
+ * @default 'pixels'
79
+ */
80
+ linkWidthUnits?: Unit;
81
+ /**
82
+ * Lets pointer drags grab a point: pinned on drag start, moved with the
83
+ * pointer, released per `unpinOnDragEnd`. View panning is suppressed while
84
+ * a point is grabbed.
85
+ * @default false
86
+ */
87
+ enablePointDrag?: boolean;
88
+ /**
89
+ * Simulation alpha to restart with when a drag starts, so the graph
90
+ * responds to the moving point; `null` leaves the simulation untouched.
91
+ * @default 0.1
92
+ */
93
+ dragReheatAlpha?: number | null;
94
+ /**
95
+ * Release the point on drag end; `false` keeps it pinned where dropped.
96
+ * @default true
97
+ */
98
+ unpinOnDragEnd?: boolean;
99
+ /** Called when a point drag starts. */
100
+ onPointDragStart?: ((info: CosmosGraphPickingInfo) => void) | null;
101
+ /** Called for every pointer move while a point is dragged. */
102
+ onPointDrag?: ((info: CosmosGraphPickingInfo) => void) | null;
103
+ /** Called when a point drag ends. */
104
+ onPointDragEnd?: ((info: CosmosGraphPickingInfo) => void) | null;
105
+ /** Simulation configuration, passed through to `GraphSimulation` (forces, spaceSize, callbacks). */
106
+ simulationConfig?: GraphSimulationConfig;
107
+ /**
108
+ * Called once with the layer-owned `GraphSimulation` — the escape hatch for
109
+ * advanced control (pause, pinning, sparse position writes).
110
+ */
111
+ onSimulationCreated?: ((simulation: GraphSimulation) => void) | null;
112
+ };
113
+ /** The slice of a deck gesture event the drag handlers need. */
114
+ type DragGestureEvent = {
115
+ stopImmediatePropagation?: () => void;
116
+ };
117
+ /**
118
+ * The batteries-included cosmos.gl graph layer: give it points and links, and
119
+ * it owns the rest. The layer creates a `GraphSimulation` on deck's device,
120
+ * ingests the data, advances the simulation once per animation frame from
121
+ * deck's shared timeline while it runs (deck goes idle when it settles — no
122
+ * `_animate` required), renders through `CosmosLinksLayer` + `CosmosPointsLayer`
123
+ * (positions stay GPU-resident), and destroys the simulation when the layer is
124
+ * removed. Picking reports `elementType: 'point' | 'link'` alongside the index
125
+ * and, for array data, the original object.
126
+ */
127
+ export declare class CosmosGraphLayer<PointDataT = unknown, LinkDataT = unknown> extends CompositeLayer<Required<CosmosGraphLayerOwnProps<PointDataT, LinkDataT>>> {
128
+ static layerName: string;
129
+ static defaultProps: DefaultProps<CosmosGraphLayerProps<unknown, unknown>>;
130
+ state: {
131
+ simulation?: GraphSimulation;
132
+ isReady: boolean;
133
+ pointCount: number;
134
+ pointsData: readonly PointDataT[] | {
135
+ length: number;
136
+ attributes?: Record<string, unknown>;
137
+ };
138
+ linksData: readonly LinkDataT[] | {
139
+ length: number;
140
+ attributes: Record<string, unknown>;
141
+ } | null;
142
+ /** Array links only: the resolved `[source, target]` point-index pairs, one per entry of `linksData`. */
143
+ linkIndices: Float32Array | null;
144
+ draggedPointIndex: number | null;
145
+ animationHandle?: number;
146
+ };
147
+ get isLoaded(): boolean;
148
+ initializeState(): void;
149
+ updateState(params: UpdateParameters<this>): void;
150
+ renderLayers(): Layer[] | null;
151
+ onDragStart(info: PickingInfo, event: DragGestureEvent): boolean;
152
+ onDrag(info: PickingInfo, event: DragGestureEvent): boolean;
153
+ onDragEnd(info: PickingInfo, event: DragGestureEvent): boolean;
154
+ getPickingInfo(params: GetPickingInfoParams): CosmosGraphPickingInfo;
155
+ /** The whole simulation space; lets deck's viewport helpers frame the graph. */
156
+ getBounds(): [number[], number[]] | null;
157
+ finalizeState(context: LayerContext): void;
158
+ /**
159
+ * Points and links have separate index spaces, so the same picking color
160
+ * exists in both sublayers: highlight only the sublayer that was hovered
161
+ * and clear the other, or hovering point N would also tint link N.
162
+ */
163
+ protected _updateAutoHighlight(info: PickingInfo): void;
164
+ private _onTimelineTick;
165
+ private _dragCoordinate;
166
+ private _updateSimulationData;
167
+ }
168
+ export {};
@@ -0,0 +1,18 @@
1
+ import { Texture } from '@luma.gl/core';
2
+ type CosmosLinksBindingProps = {
3
+ positionsTexture: Texture;
4
+ };
5
+ type CosmosLinksUniformProps = {
6
+ pointsTextureSize: number;
7
+ widthUnits: number;
8
+ };
9
+ export type CosmosLinksProps = CosmosLinksBindingProps & CosmosLinksUniformProps;
10
+ export declare const cosmosLinksUniforms: {
11
+ readonly name: "cosmosLinks";
12
+ readonly vs: "layout(std140) uniform cosmosLinksUniforms {\n float pointsTextureSize;\n highp int widthUnits;\n} cosmosLinks;\n";
13
+ readonly uniformTypes: {
14
+ readonly pointsTextureSize: "f32";
15
+ readonly widthUnits: "i32";
16
+ };
17
+ };
18
+ export {};
@@ -0,0 +1,63 @@
1
+ import { Layer, Accessor, Color, DefaultProps, LayerDataSource, LayerProps, Unit, UpdateParameters } from '@deck.gl/core';
2
+ import { Model } from '@luma.gl/engine';
3
+ import { PositionTextureSource } from './types';
4
+ export type CosmosLinksLayerProps<DataT = unknown> = CosmosLinksLayerOwnProps<DataT> & LayerProps;
5
+ type CosmosLinksLayerOwnProps<DataT> = {
6
+ /**
7
+ * One entry per link, in link-index order: an array to run accessors over,
8
+ * or binary form. The cosmos links array `[src0, tgt0, src1, tgt1, …]` maps
9
+ * without a copy as two interleaved attributes over the same buffer:
10
+ * `{ length, attributes: { getLinkSource: { value, size: 1, stride: 8 },
11
+ * getLinkTarget: { value, size: 1, offset: 4, stride: 8 } } }`.
12
+ */
13
+ data: LayerDataSource<DataT>;
14
+ /** The simulation whose live position texture to sample. */
15
+ graph: PositionTextureSource;
16
+ /**
17
+ * Source point index accessor.
18
+ * @default l => l.source
19
+ */
20
+ getLinkSource?: Accessor<DataT, number>;
21
+ /**
22
+ * Target point index accessor.
23
+ * @default l => l.target
24
+ */
25
+ getLinkTarget?: Accessor<DataT, number>;
26
+ /**
27
+ * Link RGBA color accessor, channels in 0..255.
28
+ * @default [94, 115, 194, 64]
29
+ */
30
+ getLinkColor?: Accessor<DataT, Color>;
31
+ /**
32
+ * Link width accessor, in `linkWidthUnits`.
33
+ * @default 1
34
+ */
35
+ getLinkWidth?: Accessor<DataT, number>;
36
+ /**
37
+ * The units of the link width, one of `'meters'`, `'common'`, `'pixels'`.
38
+ * @default 'pixels'
39
+ */
40
+ linkWidthUnits?: Unit;
41
+ };
42
+ /**
43
+ * Renders every cosmos.gl link as an instanced quad stretched between its two
44
+ * endpoints: the vertex shader `texelFetch`es both point positions from the
45
+ * simulation's live GPU texture and extrudes the quad by half the link width
46
+ * in screen space — no position attribute, no CPU copy, no per-frame attribute
47
+ * updates. Endpoint indices, color and width are ordinary deck instanced
48
+ * attributes, and picking works out of the box: the instance index is the
49
+ * link index.
50
+ */
51
+ export declare class CosmosLinksLayer<DataT = unknown> extends Layer<Required<CosmosLinksLayerOwnProps<DataT>>> {
52
+ static layerName: string;
53
+ static defaultProps: DefaultProps<CosmosLinksLayerProps<unknown>>;
54
+ state: {
55
+ model?: Model;
56
+ };
57
+ getShaders(): ReturnType<Layer['getShaders']>;
58
+ initializeState(): void;
59
+ updateState(params: UpdateParameters<this>): void;
60
+ draw(): void;
61
+ private _getModel;
62
+ }
63
+ export {};
@@ -0,0 +1,18 @@
1
+ import { Texture } from '@luma.gl/core';
2
+ type CosmosPointsBindingProps = {
3
+ positionsTexture: Texture;
4
+ };
5
+ type CosmosPointsUniformProps = {
6
+ pointsTextureSize: number;
7
+ sizeUnits: number;
8
+ };
9
+ export type CosmosPointsProps = CosmosPointsBindingProps & CosmosPointsUniformProps;
10
+ export declare const cosmosPointsUniforms: {
11
+ readonly name: "cosmosPoints";
12
+ readonly vs: "layout(std140) uniform cosmosPointsUniforms {\n float pointsTextureSize;\n highp int sizeUnits;\n} cosmosPoints;\n";
13
+ readonly uniformTypes: {
14
+ readonly pointsTextureSize: "f32";
15
+ readonly sizeUnits: "i32";
16
+ };
17
+ };
18
+ export {};
@@ -0,0 +1,49 @@
1
+ import { Layer, Accessor, Color, DefaultProps, LayerDataSource, LayerProps, Unit, UpdateParameters } from '@deck.gl/core';
2
+ import { Model } from '@luma.gl/engine';
3
+ import { PositionTextureSource } from './types';
4
+ export type CosmosPointsLayerProps<DataT = unknown> = CosmosPointsLayerOwnProps<DataT> & LayerProps;
5
+ type CosmosPointsLayerOwnProps<DataT> = {
6
+ /**
7
+ * One entry per simulation point, in point-index order: an array to run
8
+ * accessors over, or `{ length }` when accessors are constants. The length
9
+ * must equal the simulation's point count.
10
+ */
11
+ data: LayerDataSource<DataT>;
12
+ /** The simulation whose live position texture to sample. */
13
+ graph: PositionTextureSource;
14
+ /**
15
+ * Point diameter accessor, in `pointSizeUnits`; `0` hides the point.
16
+ * @default 4
17
+ */
18
+ getPointSize?: Accessor<DataT, number>;
19
+ /**
20
+ * Point RGBA color accessor, channels in 0..255.
21
+ * @default [74, 92, 191, 230]
22
+ */
23
+ getPointColor?: Accessor<DataT, Color>;
24
+ /**
25
+ * The units of the point diameter, one of `'meters'`, `'common'`, `'pixels'`.
26
+ * @default 'pixels'
27
+ */
28
+ pointSizeUnits?: Unit;
29
+ };
30
+ /**
31
+ * Renders every cosmos.gl point as an instanced quad whose position comes from
32
+ * a `texelFetch` on the simulation's live GPU position texture — no position
33
+ * attribute, no CPU copy, no per-frame attribute updates. Color and size are
34
+ * ordinary deck instanced attributes, and picking works out of the box: the
35
+ * instance index is the point index.
36
+ */
37
+ export declare class CosmosPointsLayer<DataT = unknown> extends Layer<Required<CosmosPointsLayerOwnProps<DataT>>> {
38
+ static layerName: string;
39
+ static defaultProps: DefaultProps<CosmosPointsLayerProps<unknown>>;
40
+ state: {
41
+ model?: Model;
42
+ };
43
+ getShaders(): ReturnType<Layer['getShaders']>;
44
+ initializeState(): void;
45
+ updateState(params: UpdateParameters<this>): void;
46
+ draw(): void;
47
+ private _getModel;
48
+ }
49
+ export {};
@@ -0,0 +1,11 @@
1
+ /**
2
+ * deck.gl layers that render a cosmos.gl simulation with **zero position
3
+ * readback**: each draw samples the live GPU position texture exposed by
4
+ * `graph.getPointPositionTexture()` with `texelFetch`, so point coordinates
5
+ * never leave the GPU. The layers share deck.gl's device with the cosmos.gl
6
+ * simulation, which the application owns and steps.
7
+ */
8
+ export { CosmosGraphLayer, type CosmosGraphLayerProps, type CosmosGraphPoints, type CosmosGraphLinks, type CosmosGraphPickingInfo, } from './cosmos-graph-layer';
9
+ export { CosmosPointsLayer, type CosmosPointsLayerProps } from './cosmos-points-layer';
10
+ export { CosmosLinksLayer, type CosmosLinksLayerProps } from './cosmos-links-layer';
11
+ export type { PositionTextureSource } from './types';
package/dist/index.js ADDED
@@ -0,0 +1,570 @@
1
+ import { Layer as U, project32 as W, picking as N, UNIT as M, CompositeLayer as $ } from "@deck.gl/core";
2
+ import { GraphSimulation as B, defaultConfigValues as O } from "@cosmos.gl/graph";
3
+ import { Model as j, Geometry as G } from "@luma.gl/engine";
4
+ const A = {
5
+ depthWriteEnabled: !1,
6
+ depthCompare: "always",
7
+ blend: !0,
8
+ blendColorOperation: "add",
9
+ blendColorSrcFactor: "src-alpha",
10
+ blendColorDstFactor: "one-minus-src-alpha",
11
+ blendAlphaOperation: "add",
12
+ blendAlphaSrcFactor: "one",
13
+ blendAlphaDstFactor: "one-minus-src-alpha"
14
+ }, q = `layout(std140) uniform cosmosPointsUniforms {
15
+ float pointsTextureSize;
16
+ highp int sizeUnits;
17
+ } cosmosPoints;
18
+ `, V = {
19
+ name: "cosmosPoints",
20
+ vs: q,
21
+ uniformTypes: {
22
+ pointsTextureSize: "f32",
23
+ sizeUnits: "i32"
24
+ }
25
+ }, H = [74, 92, 191, 230], Z = (
26
+ /* glsl */
27
+ `#version 300 es
28
+ #define SHADER_NAME cosmos-points-layer-vertex-shader
29
+
30
+ in vec3 positions;
31
+
32
+ in float instanceSizes;
33
+ in vec4 instanceColors;
34
+ in vec3 instancePickingColors;
35
+
36
+ uniform sampler2D positionsTexture;
37
+
38
+ out vec4 vColor;
39
+ out vec2 unitPosition;
40
+ out float outerRadiusPixels;
41
+
42
+ // Collapse the quad so it clips away: nothing rasterizes, nothing picks
43
+ void collapse() {
44
+ gl_Position = vec4(0.0);
45
+ unitPosition = vec2(0.0);
46
+ outerRadiusPixels = 0.0;
47
+ vColor = vec4(0.0);
48
+ }
49
+
50
+ void main(void) {
51
+ int pointIndex = gl_InstanceID;
52
+ int textureSize = int(cosmosPoints.pointsTextureSize);
53
+ // Point i lives at texel (i % size, i / size) as [x, y, i, unused] in space coordinates
54
+ vec4 pointPosition = texelFetch(positionsTexture, ivec2(pointIndex % textureSize, pointIndex / textureSize), 0);
55
+
56
+ // A removed (absent) point's texel is NaN — see PointPositionTexture
57
+ if (isnan(pointPosition.x)) {
58
+ collapse();
59
+ return;
60
+ }
61
+
62
+ geometry.worldPosition = vec3(pointPosition.xy, 0.0);
63
+ geometry.pickingColor = instancePickingColors;
64
+
65
+ // instanceSizes is a diameter; the quad expands by radius
66
+ outerRadiusPixels = project_size_to_pixel(instanceSizes * 0.5, cosmosPoints.sizeUnits);
67
+ // A non-positive size hides the point — and the edge-padding divide below
68
+ // is undefined at zero
69
+ if (outerRadiusPixels <= 0.0) {
70
+ collapse();
71
+ return;
72
+ }
73
+ // Expand the quad so edge smoothing has room outside the circle
74
+ float edgePadding = (outerRadiusPixels + SMOOTH_EDGE_RADIUS) / outerRadiusPixels;
75
+
76
+ unitPosition = edgePadding * positions.xy;
77
+ geometry.uv = unitPosition;
78
+
79
+ vec3 offset = vec3(edgePadding * positions.xy * project_pixel_size(outerRadiusPixels), 0.0);
80
+ DECKGL_FILTER_SIZE(offset, geometry);
81
+ gl_Position = project_position_to_clipspace(geometry.worldPosition, vec3(0.0), offset, geometry.position);
82
+ DECKGL_FILTER_GL_POSITION(gl_Position, geometry);
83
+
84
+ vColor = vec4(instanceColors.rgb, instanceColors.a * layer.opacity);
85
+ DECKGL_FILTER_COLOR(vColor, geometry);
86
+ }
87
+ `
88
+ ), J = (
89
+ /* glsl */
90
+ `#version 300 es
91
+ #define SHADER_NAME cosmos-points-layer-fragment-shader
92
+
93
+ precision highp float;
94
+
95
+ in vec4 vColor;
96
+ in vec2 unitPosition;
97
+ in float outerRadiusPixels;
98
+
99
+ out vec4 fragColor;
100
+
101
+ void main(void) {
102
+ geometry.uv = unitPosition;
103
+
104
+ float distToCenter = length(unitPosition) * outerRadiusPixels;
105
+ float inCircle = smoothedge(distToCenter, outerRadiusPixels);
106
+ if (inCircle == 0.0) {
107
+ discard;
108
+ }
109
+
110
+ fragColor = vec4(vColor.rgb, vColor.a * inCircle);
111
+ DECKGL_FILTER_COLOR(fragColor, geometry);
112
+ }
113
+ `
114
+ ), Q = {
115
+ getPointSize: { type: "accessor", value: 4 },
116
+ getPointColor: { type: "accessor", value: H },
117
+ pointSizeUnits: "pixels",
118
+ parameters: { type: "object", value: A, optional: !0, compare: 2 }
119
+ }, L = class L extends U {
120
+ getShaders() {
121
+ return super.getShaders({ vs: Z, fs: J, modules: [W, N, V] });
122
+ }
123
+ initializeState() {
124
+ this.getAttributeManager().addInstanced({
125
+ instanceSizes: {
126
+ size: 1,
127
+ transition: !0,
128
+ accessor: "getPointSize",
129
+ defaultValue: 4
130
+ },
131
+ instanceColors: {
132
+ size: 4,
133
+ transition: !0,
134
+ type: "unorm8",
135
+ accessor: "getPointColor",
136
+ defaultValue: [...H]
137
+ }
138
+ });
139
+ }
140
+ updateState(e) {
141
+ var t;
142
+ super.updateState(e), e.changeFlags.extensionsChanged && ((t = this.state.model) == null || t.destroy(), this.state.model = this._getModel(), this.getAttributeManager().invalidateAll());
143
+ }
144
+ draw() {
145
+ const e = this.props.graph.getPointPositionTexture(), { model: t } = this.state;
146
+ if (!e || !t || e.pointCount === 0) return;
147
+ const i = {
148
+ pointsTextureSize: e.textureSize,
149
+ sizeUnits: M[this.props.pointSizeUnits],
150
+ positionsTexture: e.texture
151
+ };
152
+ t.shaderInputs.setProps({ cosmosPoints: i }), t.draw(this.context.renderPass);
153
+ }
154
+ _getModel() {
155
+ return new j(this.context.device, {
156
+ ...this.getShaders(),
157
+ id: this.props.id,
158
+ bufferLayout: this.getAttributeManager().getBufferLayouts(),
159
+ geometry: new G({
160
+ topology: "triangle-strip",
161
+ attributes: {
162
+ positions: { size: 3, value: new Float32Array([-1, -1, 0, 1, -1, 0, -1, 1, 0, 1, 1, 0]) }
163
+ }
164
+ }),
165
+ isInstanced: !0
166
+ });
167
+ }
168
+ };
169
+ L.layerName = "CosmosPointsLayer", L.defaultProps = Q;
170
+ let _ = L;
171
+ const X = `layout(std140) uniform cosmosLinksUniforms {
172
+ float pointsTextureSize;
173
+ highp int widthUnits;
174
+ } cosmosLinks;
175
+ `, Y = {
176
+ name: "cosmosLinks",
177
+ vs: X,
178
+ uniformTypes: {
179
+ pointsTextureSize: "f32",
180
+ widthUnits: "i32"
181
+ }
182
+ }, K = [94, 115, 194, 64], ee = (
183
+ /* glsl */
184
+ `#version 300 es
185
+ #define SHADER_NAME cosmos-links-layer-vertex-shader
186
+
187
+ in vec3 positions;
188
+
189
+ in float instanceSourceIndices;
190
+ in float instanceTargetIndices;
191
+ in vec4 instanceColors;
192
+ in float instanceWidths;
193
+ in vec3 instancePickingColors;
194
+
195
+ uniform sampler2D positionsTexture;
196
+
197
+ out vec4 vColor;
198
+ out vec2 uv;
199
+
200
+ // Offset the vertex by half the link width, perpendicular to the link, in
201
+ // screen space. offsetDirection is -1 (left) or 1 (right).
202
+ vec2 getExtrusionOffset(vec2 lineClipspace, float offsetDirection, float width) {
203
+ vec2 dirScreenspace = normalize(lineClipspace * project.viewportSize);
204
+ dirScreenspace = vec2(-dirScreenspace.y, dirScreenspace.x);
205
+ return dirScreenspace * offsetDirection * width / 2.0;
206
+ }
207
+
208
+ vec4 fetchPointPosition(float index, int textureSize) {
209
+ int pointIndex = int(index);
210
+ // Point i lives at texel (i % size, i / size) as [x, y, i, unused] in space coordinates
211
+ return texelFetch(positionsTexture, ivec2(pointIndex % textureSize, pointIndex / textureSize), 0);
212
+ }
213
+
214
+ void main(void) {
215
+ int textureSize = int(cosmosLinks.pointsTextureSize);
216
+ vec4 sourcePosition = fetchPointPosition(instanceSourceIndices, textureSize);
217
+ vec4 targetPosition = fetchPointPosition(instanceTargetIndices, textureSize);
218
+
219
+ // A removed (absent) endpoint's texel is NaN — see PointPositionTexture;
220
+ // collapse the quad so it clips away
221
+ if (isnan(sourcePosition.x) || isnan(targetPosition.x)) {
222
+ gl_Position = vec4(0.0);
223
+ vColor = vec4(0.0);
224
+ uv = vec2(0.0);
225
+ return;
226
+ }
227
+
228
+ vec3 sourceWorld = vec3(sourcePosition.xy, 0.0);
229
+ vec3 targetWorld = vec3(targetPosition.xy, 0.0);
230
+ geometry.worldPosition = sourceWorld;
231
+ geometry.worldPositionAlt = targetWorld;
232
+
233
+ vec4 sourceCommonspace;
234
+ vec4 targetCommonspace;
235
+ vec4 source = project_position_to_clipspace(sourceWorld, vec3(0.0), vec3(0.0), sourceCommonspace);
236
+ vec4 target = project_position_to_clipspace(targetWorld, vec3(0.0), vec3(0.0), targetCommonspace);
237
+
238
+ // positions.x selects the endpoint, positions.y the extrusion side
239
+ float segmentIndex = positions.x;
240
+ vec4 p = mix(source, target, segmentIndex);
241
+ geometry.position = mix(sourceCommonspace, targetCommonspace, segmentIndex);
242
+ uv = positions.xy;
243
+ geometry.uv = uv;
244
+ geometry.pickingColor = instancePickingColors;
245
+
246
+ float widthPixels = project_size_to_pixel(instanceWidths, cosmosLinks.widthUnits);
247
+
248
+ vec3 offset = vec3(getExtrusionOffset(target.xy - source.xy, positions.y, widthPixels), 0.0);
249
+ DECKGL_FILTER_SIZE(offset, geometry);
250
+ DECKGL_FILTER_GL_POSITION(p, geometry);
251
+ gl_Position = p + vec4(project_pixel_size_to_clipspace(offset.xy), 0.0, 0.0);
252
+
253
+ vColor = vec4(instanceColors.rgb, instanceColors.a * layer.opacity);
254
+ DECKGL_FILTER_COLOR(vColor, geometry);
255
+ }
256
+ `
257
+ ), te = (
258
+ /* glsl */
259
+ `#version 300 es
260
+ #define SHADER_NAME cosmos-links-layer-fragment-shader
261
+
262
+ precision highp float;
263
+
264
+ in vec4 vColor;
265
+ in vec2 uv;
266
+
267
+ out vec4 fragColor;
268
+
269
+ void main(void) {
270
+ geometry.uv = uv;
271
+
272
+ fragColor = vColor;
273
+ DECKGL_FILTER_COLOR(fragColor, geometry);
274
+ }
275
+ `
276
+ ), ie = {
277
+ getLinkSource: { type: "accessor", value: (d) => d.source },
278
+ getLinkTarget: { type: "accessor", value: (d) => d.target },
279
+ getLinkColor: { type: "accessor", value: K },
280
+ getLinkWidth: { type: "accessor", value: 1 },
281
+ linkWidthUnits: "pixels",
282
+ parameters: { type: "object", value: A, optional: !0, compare: 2 }
283
+ }, z = class z extends U {
284
+ getShaders() {
285
+ return super.getShaders({ vs: ee, fs: te, modules: [W, N, Y] });
286
+ }
287
+ initializeState() {
288
+ this.getAttributeManager().addInstanced({
289
+ instanceSourceIndices: {
290
+ size: 1,
291
+ accessor: "getLinkSource"
292
+ },
293
+ instanceTargetIndices: {
294
+ size: 1,
295
+ accessor: "getLinkTarget"
296
+ },
297
+ instanceColors: {
298
+ size: 4,
299
+ transition: !0,
300
+ type: "unorm8",
301
+ accessor: "getLinkColor",
302
+ defaultValue: [...K]
303
+ },
304
+ instanceWidths: {
305
+ size: 1,
306
+ transition: !0,
307
+ accessor: "getLinkWidth",
308
+ defaultValue: 1
309
+ }
310
+ });
311
+ }
312
+ updateState(e) {
313
+ var t;
314
+ super.updateState(e), e.changeFlags.extensionsChanged && ((t = this.state.model) == null || t.destroy(), this.state.model = this._getModel(), this.getAttributeManager().invalidateAll());
315
+ }
316
+ draw() {
317
+ const e = this.props.graph.getPointPositionTexture(), { model: t } = this.state;
318
+ if (!e || !t || e.pointCount === 0) return;
319
+ const i = {
320
+ pointsTextureSize: e.textureSize,
321
+ widthUnits: M[this.props.linkWidthUnits],
322
+ positionsTexture: e.texture
323
+ };
324
+ t.shaderInputs.setProps({ cosmosLinks: i }), t.draw(this.context.renderPass);
325
+ }
326
+ _getModel() {
327
+ return new j(this.context.device, {
328
+ ...this.getShaders(),
329
+ id: this.props.id,
330
+ bufferLayout: this.getAttributeManager().getBufferLayouts(),
331
+ geometry: new G({
332
+ topology: "triangle-strip",
333
+ attributes: {
334
+ positions: { size: 3, value: new Float32Array([0, -1, 0, 0, 1, 0, 1, -1, 0, 1, 1, 0]) }
335
+ }
336
+ }),
337
+ isInstanced: !0
338
+ });
339
+ }
340
+ };
341
+ z.layerName = "CosmosLinksLayer", z.defaultProps = ie;
342
+ let I = z;
343
+ const oe = {
344
+ links: null,
345
+ getPointId: { type: "accessor", value: null },
346
+ getPointPosition: { type: "accessor", value: null },
347
+ getPointSize: { type: "accessor", value: 4 },
348
+ getPointColor: { type: "accessor", value: [74, 92, 191, 230] },
349
+ pointSizeUnits: "pixels",
350
+ getLinkSource: { type: "accessor", value: (d) => d.source },
351
+ getLinkTarget: { type: "accessor", value: (d) => d.target },
352
+ getLinkColor: { type: "accessor", value: [94, 115, 194, 64] },
353
+ getLinkWidth: { type: "accessor", value: 1 },
354
+ linkWidthUnits: "pixels",
355
+ enablePointDrag: !1,
356
+ dragReheatAlpha: 0.1,
357
+ unpinOnDragEnd: !0,
358
+ onPointDragStart: { type: "function", value: null, optional: !0 },
359
+ onPointDrag: { type: "function", value: null, optional: !0 },
360
+ onPointDragEnd: { type: "function", value: null, optional: !0 },
361
+ simulationConfig: { type: "object", value: {}, compare: 2 },
362
+ onSimulationCreated: { type: "function", value: null, optional: !0 },
363
+ // getSubLayerProps forwards `parameters` into every sublayer, so the
364
+ // composite must carry the same pipeline-state default the primitives do
365
+ parameters: { type: "object", value: A, optional: !0, compare: 2 }
366
+ }, k = (d, e, t) => typeof d == "function" ? d(e, t) : d, T = class T extends $ {
367
+ get isLoaded() {
368
+ var e;
369
+ return super.isLoaded && !!((e = this.state) != null && e.isReady);
370
+ }
371
+ initializeState() {
372
+ var s, n;
373
+ const { device: e, timeline: t } = this.context;
374
+ if (e.type !== "webgl")
375
+ throw new Error(
376
+ `@cosmos.gl/deck-layers requires a WebGL 2 device — the cosmos.gl simulation is WebGL-only, got '${e.type}'`
377
+ );
378
+ const i = new B(this.props.simulationConfig, Promise.resolve(e));
379
+ this.state = {
380
+ simulation: i,
381
+ isReady: !1,
382
+ pointCount: 0,
383
+ pointsData: { length: 0 },
384
+ linksData: null,
385
+ linkIndices: null,
386
+ draggedPointIndex: null,
387
+ // Step the simulation exactly once per animation frame, independent of
388
+ // draw passes (draw runs per viewport and again while picking)
389
+ animationHandle: t.attachAnimation({ setTime: () => this._onTimelineTick() })
390
+ }, (n = (s = this.props).onSimulationCreated) == null || n.call(s, i), i.ready.then(() => {
391
+ var a;
392
+ if (((a = this.state) == null ? void 0 : a.simulation) !== i) return;
393
+ (this.getCurrentLayer() ?? this).setState({ isReady: !0 });
394
+ }).catch((o) => {
395
+ console.error("@cosmos.gl/deck-layers: simulation failed to initialize", o);
396
+ });
397
+ }
398
+ updateState(e) {
399
+ super.updateState(e);
400
+ const { props: t, oldProps: i, changeFlags: s } = e, n = this.state.simulation;
401
+ if (!n) return;
402
+ s.propsChanged && t.simulationConfig !== i.simulationConfig && n.setConfig(t.simulationConfig);
403
+ const o = typeof s.updateTriggersChanged == "object" ? s.updateTriggersChanged : void 0;
404
+ (t.points !== i.points || t.links !== i.links || !!(o != null && o.getPointPosition || o != null && o.getPointId || o != null && o.getLinkSource || o != null && o.getLinkTarget)) && this._updateSimulationData();
405
+ }
406
+ renderLayers() {
407
+ const { simulation: e, isReady: t, pointCount: i, pointsData: s, linksData: n, linkIndices: o } = this.state;
408
+ if (!e || !t || i === 0) return null;
409
+ const { getPointSize: a, getPointColor: l, pointSizeUnits: c, getLinkColor: P, getLinkWidth: f, linkWidthUnits: y } = this.props, p = this.props.updateTriggers ?? {}, v = [];
410
+ return n && v.push(
411
+ new I(
412
+ this.getSubLayerProps({
413
+ id: "links",
414
+ updateTriggers: {
415
+ getLinkSource: p.getLinkSource,
416
+ getLinkTarget: p.getLinkTarget,
417
+ getLinkColor: p.getLinkColor,
418
+ getLinkWidth: p.getLinkWidth
419
+ }
420
+ }),
421
+ {
422
+ data: n,
423
+ graph: e,
424
+ getLinkColor: P,
425
+ getLinkWidth: f,
426
+ linkWidthUnits: y,
427
+ // getSubLayerProps does not forward `transitions`
428
+ transitions: this.props.transitions
429
+ },
430
+ Array.isArray(n) && o ? {
431
+ // Array links read the endpoints resolved at ingest, so the
432
+ // rendered links are exactly the simulated ones
433
+ getLinkSource: (S, { index: r }) => o[r * 2],
434
+ getLinkTarget: (S, { index: r }) => o[r * 2 + 1]
435
+ } : {}
436
+ )
437
+ ), v.push(
438
+ new _(
439
+ this.getSubLayerProps({
440
+ id: "points",
441
+ updateTriggers: {
442
+ getPointSize: p.getPointSize,
443
+ getPointColor: p.getPointColor
444
+ }
445
+ }),
446
+ {
447
+ data: s,
448
+ graph: e,
449
+ getPointSize: a,
450
+ getPointColor: l,
451
+ pointSizeUnits: c,
452
+ // getSubLayerProps does not forward `transitions`
453
+ transitions: this.props.transitions
454
+ }
455
+ )
456
+ ), v;
457
+ }
458
+ onDragStart(e, t) {
459
+ var a, l, c;
460
+ const { simulation: i } = this.state, { enablePointDrag: s, dragReheatAlpha: n } = this.props, o = e;
461
+ return !s || !i || o.elementType !== "point" || e.index < 0 ? !1 : (this.state.draggedPointIndex = e.index, i.setPinnedPoint(e.index, !0), n !== null && i.start(n), (a = t.stopImmediatePropagation) == null || a.call(t), (c = (l = this.props).onPointDragStart) == null || c.call(l, o), !0);
462
+ }
463
+ onDrag(e, t) {
464
+ var a, l, c;
465
+ const { simulation: i, draggedPointIndex: s } = this.state;
466
+ if (!i || s === null) return !1;
467
+ const [n, o] = this._dragCoordinate(e);
468
+ return i.setPointPosition(s, n, o), (a = t.stopImmediatePropagation) == null || a.call(t), (this.getCurrentLayer() ?? this).setNeedsRedraw(), (c = (l = this.props).onPointDrag) == null || c.call(l, e), !0;
469
+ }
470
+ onDragEnd(e, t) {
471
+ var n, o, a;
472
+ const { simulation: i, draggedPointIndex: s } = this.state;
473
+ return !i || s === null ? !1 : (this.props.unpinOnDragEnd && i.setPinnedPoint(s, !1), this.state.draggedPointIndex = null, (n = t.stopImmediatePropagation) == null || n.call(t), (a = (o = this.props).onPointDragEnd) == null || a.call(o, e), !0);
474
+ }
475
+ getPickingInfo(e) {
476
+ const t = e.info;
477
+ return e.sourceLayer && (t.elementType = e.sourceLayer.id.endsWith("-links") ? "link" : "point"), t;
478
+ }
479
+ /** The whole simulation space; lets deck's viewport helpers frame the graph. */
480
+ getBounds() {
481
+ var t;
482
+ const e = ((t = this.props.simulationConfig) == null ? void 0 : t.spaceSize) ?? O.spaceSize;
483
+ return [[0, 0, 0], [e, e, 0]];
484
+ }
485
+ finalizeState(e) {
486
+ var t, i, s;
487
+ ((t = this.state) == null ? void 0 : t.animationHandle) !== void 0 && this.context.timeline.detachAnimation(this.state.animationHandle), (s = (i = this.state) == null ? void 0 : i.simulation) == null || s.destroy(), super.finalizeState(e);
488
+ }
489
+ /**
490
+ * Points and links have separate index spaces, so the same picking color
491
+ * exists in both sublayers: highlight only the sublayer that was hovered
492
+ * and clear the other, or hovering point N would also tint link N.
493
+ */
494
+ _updateAutoHighlight(e) {
495
+ var t;
496
+ for (const i of this.getSubLayers())
497
+ i.id === ((t = e.sourceLayer) == null ? void 0 : t.id) ? i.updateAutoHighlight(e) : i.updateAutoHighlight({ ...e, picked: !1 });
498
+ }
499
+ _onTimelineTick() {
500
+ const { simulation: e, isReady: t } = this.state ?? {};
501
+ if (!e || !t || !e.isSimulationRunning) return;
502
+ e.step(), (this.getCurrentLayer() ?? this).setNeedsRedraw();
503
+ }
504
+ _dragCoordinate(e) {
505
+ if (e.coordinate) return [e.coordinate[0], e.coordinate[1]];
506
+ const t = this.context.viewport.unproject([e.x, e.y]);
507
+ return [t[0], t[1]];
508
+ }
509
+ _updateSimulationData() {
510
+ var S;
511
+ const e = this.state.simulation;
512
+ if (!e) return;
513
+ const { points: t, links: i, getPointId: s, getPointPosition: n } = this.props, o = ((S = this.props.simulationConfig) == null ? void 0 : S.spaceSize) ?? O.spaceSize, a = () => o * (0.25 + Math.random() * 0.5);
514
+ let l, c, P, f = null;
515
+ if (Array.isArray(t)) {
516
+ const r = t;
517
+ l = r.length, c = new Float32Array(l * 2), s && (f = /* @__PURE__ */ new Map());
518
+ for (let u = 0; u < l; u += 1) {
519
+ const C = r[u], x = { index: u, data: r, target: [] }, m = n ? k(n, C, x) : null;
520
+ c[u * 2] = m ? m[0] : a(), c[u * 2 + 1] = m ? m[1] : a(), f && s && f.set(k(s, C, x), u);
521
+ }
522
+ P = r;
523
+ } else {
524
+ const r = t;
525
+ if (l = r.length, r.initialPositions)
526
+ c = r.initialPositions;
527
+ else {
528
+ c = new Float32Array(l * 2);
529
+ for (let u = 0; u < c.length; u += 1) c[u] = a();
530
+ }
531
+ P = r.attributes ? { length: l, attributes: r.attributes } : { length: l };
532
+ }
533
+ let y = null, p = null, v = null;
534
+ if (i instanceof Float32Array)
535
+ y = i, p = {
536
+ length: i.length / 2,
537
+ attributes: {
538
+ getLinkSource: { value: i, size: 1, stride: 8 },
539
+ getLinkTarget: { value: i, size: 1, offset: 4, stride: 8 }
540
+ }
541
+ };
542
+ else if (Array.isArray(i)) {
543
+ const r = i, { getLinkSource: u, getLinkTarget: C } = this.props, x = (g) => {
544
+ const h = f ? f.get(g) : g;
545
+ return typeof h == "number" && Number.isInteger(h) && h >= 0 && h < l ? h : void 0;
546
+ }, m = [], b = [];
547
+ for (let g = 0; g < r.length; g += 1) {
548
+ const h = r[g], E = { index: g, data: r, target: [] }, w = x(k(u, h, E)), R = x(k(C, h, E));
549
+ w === void 0 || R === void 0 || (m.push(h), b.push(w, R));
550
+ }
551
+ const D = r.length - m.length;
552
+ if (D > 0) {
553
+ const g = f ? "getLinkSource / getLinkTarget against getPointId" : "getLinkSource / getLinkTarget";
554
+ console.warn(
555
+ `@cosmos.gl/deck-layers: dropped ${D} of ${r.length} links whose source or target is not a point — check ${g}`
556
+ );
557
+ }
558
+ y = Float32Array.from(b), v = y, p = m;
559
+ }
560
+ e.setPointPositions(c), e.setLinks(y ?? new Float32Array(0)), e.applyData(), this.setState({ pointCount: l, pointsData: P, linksData: p, linkIndices: v });
561
+ }
562
+ };
563
+ T.layerName = "CosmosGraphLayer", T.defaultProps = oe;
564
+ let F = T;
565
+ export {
566
+ F as CosmosGraphLayer,
567
+ I as CosmosLinksLayer,
568
+ _ as CosmosPointsLayer
569
+ };
570
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/blend-parameters.ts","../src/cosmos-points-layer-uniforms.ts","../src/cosmos-points-layer.ts","../src/cosmos-links-layer-uniforms.ts","../src/cosmos-links-layer.ts","../src/cosmos-graph-layer.ts"],"sourcesContent":["/**\n * Premultiplied-style alpha blending with depth writes disabled: points and\n * links are drawn back-to-front by layer order, never by depth.\n *\n * Wire through `defaultProps.parameters`: before every draw, deck resets each\n * model's pipeline parameters from `layer.props.parameters`. Parameters given\n * only at `Model` creation last one frame.\n *\n * Declare the default with `compare: 2`, like the base layer does — a plain\n * object default would drop deep comparison, and every new-but-equal\n * `parameters` object from the caller would count as a prop change.\n */\nexport const BLEND_PARAMETERS = {\n depthWriteEnabled: false,\n depthCompare: 'always',\n blend: true,\n blendColorOperation: 'add',\n blendColorSrcFactor: 'src-alpha',\n blendColorDstFactor: 'one-minus-src-alpha',\n blendAlphaOperation: 'add',\n blendAlphaSrcFactor: 'one',\n blendAlphaDstFactor: 'one-minus-src-alpha',\n} as const\n","import type { ShaderModule } from '@luma.gl/shadertools'\nimport type { Texture } from '@luma.gl/core'\n\nconst uniformBlock = `\\\nlayout(std140) uniform cosmosPointsUniforms {\n float pointsTextureSize;\n highp int sizeUnits;\n} cosmosPoints;\n`\n\ntype CosmosPointsBindingProps = {\n positionsTexture: Texture;\n}\n\ntype CosmosPointsUniformProps = {\n pointsTextureSize: number;\n sizeUnits: number;\n}\n\nexport type CosmosPointsProps = CosmosPointsBindingProps & CosmosPointsUniformProps\n\nexport const cosmosPointsUniforms = {\n name: 'cosmosPoints',\n vs: uniformBlock,\n uniformTypes: {\n pointsTextureSize: 'f32',\n sizeUnits: 'i32',\n },\n} as const satisfies ShaderModule<CosmosPointsProps>\n","import { Layer, project32, picking, UNIT } from '@deck.gl/core'\nimport type { Accessor, Color, DefaultProps, LayerDataSource, LayerProps, Unit, UpdateParameters } from '@deck.gl/core'\nimport { Model, Geometry } from '@luma.gl/engine'\n\nimport { BLEND_PARAMETERS } from './blend-parameters'\nimport { cosmosPointsUniforms } from './cosmos-points-layer-uniforms'\nimport type { CosmosPointsProps } from './cosmos-points-layer-uniforms'\nimport type { PositionTextureSource } from './types'\n\nconst DEFAULT_POINT_COLOR: [number, number, number, number] = [74, 92, 191, 230]\n\nconst vs = /* glsl */ `\\\n#version 300 es\n#define SHADER_NAME cosmos-points-layer-vertex-shader\n\nin vec3 positions;\n\nin float instanceSizes;\nin vec4 instanceColors;\nin vec3 instancePickingColors;\n\nuniform sampler2D positionsTexture;\n\nout vec4 vColor;\nout vec2 unitPosition;\nout float outerRadiusPixels;\n\n// Collapse the quad so it clips away: nothing rasterizes, nothing picks\nvoid collapse() {\n gl_Position = vec4(0.0);\n unitPosition = vec2(0.0);\n outerRadiusPixels = 0.0;\n vColor = vec4(0.0);\n}\n\nvoid main(void) {\n int pointIndex = gl_InstanceID;\n int textureSize = int(cosmosPoints.pointsTextureSize);\n // Point i lives at texel (i % size, i / size) as [x, y, i, unused] in space coordinates\n vec4 pointPosition = texelFetch(positionsTexture, ivec2(pointIndex % textureSize, pointIndex / textureSize), 0);\n\n // A removed (absent) point's texel is NaN — see PointPositionTexture\n if (isnan(pointPosition.x)) {\n collapse();\n return;\n }\n\n geometry.worldPosition = vec3(pointPosition.xy, 0.0);\n geometry.pickingColor = instancePickingColors;\n\n // instanceSizes is a diameter; the quad expands by radius\n outerRadiusPixels = project_size_to_pixel(instanceSizes * 0.5, cosmosPoints.sizeUnits);\n // A non-positive size hides the point — and the edge-padding divide below\n // is undefined at zero\n if (outerRadiusPixels <= 0.0) {\n collapse();\n return;\n }\n // Expand the quad so edge smoothing has room outside the circle\n float edgePadding = (outerRadiusPixels + SMOOTH_EDGE_RADIUS) / outerRadiusPixels;\n\n unitPosition = edgePadding * positions.xy;\n geometry.uv = unitPosition;\n\n vec3 offset = vec3(edgePadding * positions.xy * project_pixel_size(outerRadiusPixels), 0.0);\n DECKGL_FILTER_SIZE(offset, geometry);\n gl_Position = project_position_to_clipspace(geometry.worldPosition, vec3(0.0), offset, geometry.position);\n DECKGL_FILTER_GL_POSITION(gl_Position, geometry);\n\n vColor = vec4(instanceColors.rgb, instanceColors.a * layer.opacity);\n DECKGL_FILTER_COLOR(vColor, geometry);\n}\n`\n\nconst fs = /* glsl */ `\\\n#version 300 es\n#define SHADER_NAME cosmos-points-layer-fragment-shader\n\nprecision highp float;\n\nin vec4 vColor;\nin vec2 unitPosition;\nin float outerRadiusPixels;\n\nout vec4 fragColor;\n\nvoid main(void) {\n geometry.uv = unitPosition;\n\n float distToCenter = length(unitPosition) * outerRadiusPixels;\n float inCircle = smoothedge(distToCenter, outerRadiusPixels);\n if (inCircle == 0.0) {\n discard;\n }\n\n fragColor = vec4(vColor.rgb, vColor.a * inCircle);\n DECKGL_FILTER_COLOR(fragColor, geometry);\n}\n`\n\nexport type CosmosPointsLayerProps<DataT = unknown> = CosmosPointsLayerOwnProps<DataT> & LayerProps\n\ntype CosmosPointsLayerOwnProps<DataT> = {\n /**\n * One entry per simulation point, in point-index order: an array to run\n * accessors over, or `{ length }` when accessors are constants. The length\n * must equal the simulation's point count.\n */\n data: LayerDataSource<DataT>;\n /** The simulation whose live position texture to sample. */\n graph: PositionTextureSource;\n /**\n * Point diameter accessor, in `pointSizeUnits`; `0` hides the point.\n * @default 4\n */\n getPointSize?: Accessor<DataT, number>;\n /**\n * Point RGBA color accessor, channels in 0..255.\n * @default [74, 92, 191, 230]\n */\n getPointColor?: Accessor<DataT, Color>;\n /**\n * The units of the point diameter, one of `'meters'`, `'common'`, `'pixels'`.\n * @default 'pixels'\n */\n pointSizeUnits?: Unit;\n}\n\nconst defaultProps: DefaultProps<CosmosPointsLayerProps> = {\n getPointSize: { type: 'accessor', value: 4 },\n getPointColor: { type: 'accessor', value: DEFAULT_POINT_COLOR },\n pointSizeUnits: 'pixels',\n parameters: { type: 'object', value: BLEND_PARAMETERS, optional: true, compare: 2 },\n}\n\n/**\n * Renders every cosmos.gl point as an instanced quad whose position comes from\n * a `texelFetch` on the simulation's live GPU position texture — no position\n * attribute, no CPU copy, no per-frame attribute updates. Color and size are\n * ordinary deck instanced attributes, and picking works out of the box: the\n * instance index is the point index.\n */\nexport class CosmosPointsLayer<DataT = unknown> extends Layer<Required<CosmosPointsLayerOwnProps<DataT>>> {\n public static layerName = 'CosmosPointsLayer'\n public static defaultProps = defaultProps\n\n declare public state: { model?: Model }\n\n public getShaders (): ReturnType<Layer['getShaders']> {\n return super.getShaders({ vs, fs, modules: [project32, picking, cosmosPointsUniforms] })\n }\n\n public initializeState (): void {\n this.getAttributeManager()!.addInstanced({\n instanceSizes: {\n size: 1,\n transition: true,\n accessor: 'getPointSize',\n defaultValue: 4,\n },\n instanceColors: {\n size: 4,\n transition: true,\n type: 'unorm8',\n accessor: 'getPointColor',\n defaultValue: [...DEFAULT_POINT_COLOR],\n },\n })\n }\n\n public updateState (params: UpdateParameters<this>): void {\n super.updateState(params)\n\n if (params.changeFlags.extensionsChanged) {\n this.state.model?.destroy()\n this.state.model = this._getModel()\n this.getAttributeManager()!.invalidateAll()\n }\n }\n\n public draw (): void {\n const positionInfo = this.props.graph.getPointPositionTexture()\n const { model } = this.state\n if (!positionInfo || !model || positionInfo.pointCount === 0) return\n\n const moduleProps: CosmosPointsProps = {\n pointsTextureSize: positionInfo.textureSize,\n sizeUnits: UNIT[this.props.pointSizeUnits],\n positionsTexture: positionInfo.texture,\n }\n model.shaderInputs.setProps({ cosmosPoints: moduleProps })\n model.draw(this.context.renderPass)\n }\n\n private _getModel (): Model {\n // A quad that minimally covers the unit circle\n return new Model(this.context.device, {\n ...this.getShaders(),\n id: this.props.id,\n bufferLayout: this.getAttributeManager()!.getBufferLayouts(),\n geometry: new Geometry({\n topology: 'triangle-strip',\n attributes: {\n positions: { size: 3, value: new Float32Array([-1, -1, 0, 1, -1, 0, -1, 1, 0, 1, 1, 0]) },\n },\n }),\n isInstanced: true,\n })\n }\n}\n","import type { ShaderModule } from '@luma.gl/shadertools'\nimport type { Texture } from '@luma.gl/core'\n\nconst uniformBlock = `\\\nlayout(std140) uniform cosmosLinksUniforms {\n float pointsTextureSize;\n highp int widthUnits;\n} cosmosLinks;\n`\n\ntype CosmosLinksBindingProps = {\n positionsTexture: Texture;\n}\n\ntype CosmosLinksUniformProps = {\n pointsTextureSize: number;\n widthUnits: number;\n}\n\nexport type CosmosLinksProps = CosmosLinksBindingProps & CosmosLinksUniformProps\n\nexport const cosmosLinksUniforms = {\n name: 'cosmosLinks',\n vs: uniformBlock,\n uniformTypes: {\n pointsTextureSize: 'f32',\n widthUnits: 'i32',\n },\n} as const satisfies ShaderModule<CosmosLinksProps>\n","import { Layer, project32, picking, UNIT } from '@deck.gl/core'\nimport type { Accessor, Color, DefaultProps, LayerDataSource, LayerProps, Unit, UpdateParameters } from '@deck.gl/core'\nimport { Model, Geometry } from '@luma.gl/engine'\n\nimport { BLEND_PARAMETERS } from './blend-parameters'\nimport { cosmosLinksUniforms } from './cosmos-links-layer-uniforms'\nimport type { CosmosLinksProps } from './cosmos-links-layer-uniforms'\nimport type { PositionTextureSource } from './types'\n\nconst DEFAULT_LINK_COLOR: [number, number, number, number] = [94, 115, 194, 64]\n\nconst vs = /* glsl */ `\\\n#version 300 es\n#define SHADER_NAME cosmos-links-layer-vertex-shader\n\nin vec3 positions;\n\nin float instanceSourceIndices;\nin float instanceTargetIndices;\nin vec4 instanceColors;\nin float instanceWidths;\nin vec3 instancePickingColors;\n\nuniform sampler2D positionsTexture;\n\nout vec4 vColor;\nout vec2 uv;\n\n// Offset the vertex by half the link width, perpendicular to the link, in\n// screen space. offsetDirection is -1 (left) or 1 (right).\nvec2 getExtrusionOffset(vec2 lineClipspace, float offsetDirection, float width) {\n vec2 dirScreenspace = normalize(lineClipspace * project.viewportSize);\n dirScreenspace = vec2(-dirScreenspace.y, dirScreenspace.x);\n return dirScreenspace * offsetDirection * width / 2.0;\n}\n\nvec4 fetchPointPosition(float index, int textureSize) {\n int pointIndex = int(index);\n // Point i lives at texel (i % size, i / size) as [x, y, i, unused] in space coordinates\n return texelFetch(positionsTexture, ivec2(pointIndex % textureSize, pointIndex / textureSize), 0);\n}\n\nvoid main(void) {\n int textureSize = int(cosmosLinks.pointsTextureSize);\n vec4 sourcePosition = fetchPointPosition(instanceSourceIndices, textureSize);\n vec4 targetPosition = fetchPointPosition(instanceTargetIndices, textureSize);\n\n // A removed (absent) endpoint's texel is NaN — see PointPositionTexture;\n // collapse the quad so it clips away\n if (isnan(sourcePosition.x) || isnan(targetPosition.x)) {\n gl_Position = vec4(0.0);\n vColor = vec4(0.0);\n uv = vec2(0.0);\n return;\n }\n\n vec3 sourceWorld = vec3(sourcePosition.xy, 0.0);\n vec3 targetWorld = vec3(targetPosition.xy, 0.0);\n geometry.worldPosition = sourceWorld;\n geometry.worldPositionAlt = targetWorld;\n\n vec4 sourceCommonspace;\n vec4 targetCommonspace;\n vec4 source = project_position_to_clipspace(sourceWorld, vec3(0.0), vec3(0.0), sourceCommonspace);\n vec4 target = project_position_to_clipspace(targetWorld, vec3(0.0), vec3(0.0), targetCommonspace);\n\n // positions.x selects the endpoint, positions.y the extrusion side\n float segmentIndex = positions.x;\n vec4 p = mix(source, target, segmentIndex);\n geometry.position = mix(sourceCommonspace, targetCommonspace, segmentIndex);\n uv = positions.xy;\n geometry.uv = uv;\n geometry.pickingColor = instancePickingColors;\n\n float widthPixels = project_size_to_pixel(instanceWidths, cosmosLinks.widthUnits);\n\n vec3 offset = vec3(getExtrusionOffset(target.xy - source.xy, positions.y, widthPixels), 0.0);\n DECKGL_FILTER_SIZE(offset, geometry);\n DECKGL_FILTER_GL_POSITION(p, geometry);\n gl_Position = p + vec4(project_pixel_size_to_clipspace(offset.xy), 0.0, 0.0);\n\n vColor = vec4(instanceColors.rgb, instanceColors.a * layer.opacity);\n DECKGL_FILTER_COLOR(vColor, geometry);\n}\n`\n\nconst fs = /* glsl */ `\\\n#version 300 es\n#define SHADER_NAME cosmos-links-layer-fragment-shader\n\nprecision highp float;\n\nin vec4 vColor;\nin vec2 uv;\n\nout vec4 fragColor;\n\nvoid main(void) {\n geometry.uv = uv;\n\n fragColor = vColor;\n DECKGL_FILTER_COLOR(fragColor, geometry);\n}\n`\n\nexport type CosmosLinksLayerProps<DataT = unknown> = CosmosLinksLayerOwnProps<DataT> & LayerProps\n\ntype CosmosLinksLayerOwnProps<DataT> = {\n /**\n * One entry per link, in link-index order: an array to run accessors over,\n * or binary form. The cosmos links array `[src0, tgt0, src1, tgt1, …]` maps\n * without a copy as two interleaved attributes over the same buffer:\n * `{ length, attributes: { getLinkSource: { value, size: 1, stride: 8 },\n * getLinkTarget: { value, size: 1, offset: 4, stride: 8 } } }`.\n */\n data: LayerDataSource<DataT>;\n /** The simulation whose live position texture to sample. */\n graph: PositionTextureSource;\n /**\n * Source point index accessor.\n * @default l => l.source\n */\n getLinkSource?: Accessor<DataT, number>;\n /**\n * Target point index accessor.\n * @default l => l.target\n */\n getLinkTarget?: Accessor<DataT, number>;\n /**\n * Link RGBA color accessor, channels in 0..255.\n * @default [94, 115, 194, 64]\n */\n getLinkColor?: Accessor<DataT, Color>;\n /**\n * Link width accessor, in `linkWidthUnits`.\n * @default 1\n */\n getLinkWidth?: Accessor<DataT, number>;\n /**\n * The units of the link width, one of `'meters'`, `'common'`, `'pixels'`.\n * @default 'pixels'\n */\n linkWidthUnits?: Unit;\n}\n\nconst defaultProps: DefaultProps<CosmosLinksLayerProps> = {\n getLinkSource: { type: 'accessor', value: (l: unknown) => (l as { source: number }).source },\n getLinkTarget: { type: 'accessor', value: (l: unknown) => (l as { target: number }).target },\n getLinkColor: { type: 'accessor', value: DEFAULT_LINK_COLOR },\n getLinkWidth: { type: 'accessor', value: 1 },\n linkWidthUnits: 'pixels',\n parameters: { type: 'object', value: BLEND_PARAMETERS, optional: true, compare: 2 },\n}\n\n/**\n * Renders every cosmos.gl link as an instanced quad stretched between its two\n * endpoints: the vertex shader `texelFetch`es both point positions from the\n * simulation's live GPU texture and extrudes the quad by half the link width\n * in screen space — no position attribute, no CPU copy, no per-frame attribute\n * updates. Endpoint indices, color and width are ordinary deck instanced\n * attributes, and picking works out of the box: the instance index is the\n * link index.\n */\nexport class CosmosLinksLayer<DataT = unknown> extends Layer<Required<CosmosLinksLayerOwnProps<DataT>>> {\n public static layerName = 'CosmosLinksLayer'\n public static defaultProps = defaultProps\n\n declare public state: { model?: Model }\n\n public getShaders (): ReturnType<Layer['getShaders']> {\n return super.getShaders({ vs, fs, modules: [project32, picking, cosmosLinksUniforms] })\n }\n\n public initializeState (): void {\n this.getAttributeManager()!.addInstanced({\n instanceSourceIndices: {\n size: 1,\n accessor: 'getLinkSource',\n },\n instanceTargetIndices: {\n size: 1,\n accessor: 'getLinkTarget',\n },\n instanceColors: {\n size: 4,\n transition: true,\n type: 'unorm8',\n accessor: 'getLinkColor',\n defaultValue: [...DEFAULT_LINK_COLOR],\n },\n instanceWidths: {\n size: 1,\n transition: true,\n accessor: 'getLinkWidth',\n defaultValue: 1,\n },\n })\n }\n\n public updateState (params: UpdateParameters<this>): void {\n super.updateState(params)\n\n if (params.changeFlags.extensionsChanged) {\n this.state.model?.destroy()\n this.state.model = this._getModel()\n this.getAttributeManager()!.invalidateAll()\n }\n }\n\n public draw (): void {\n const positionInfo = this.props.graph.getPointPositionTexture()\n const { model } = this.state\n if (!positionInfo || !model || positionInfo.pointCount === 0) return\n\n const moduleProps: CosmosLinksProps = {\n pointsTextureSize: positionInfo.textureSize,\n widthUnits: UNIT[this.props.linkWidthUnits],\n positionsTexture: positionInfo.texture,\n }\n model.shaderInputs.setProps({ cosmosLinks: moduleProps })\n model.draw(this.context.renderPass)\n }\n\n private _getModel (): Model {\n // positions.x selects source/target, positions.y the extrusion side\n return new Model(this.context.device, {\n ...this.getShaders(),\n id: this.props.id,\n bufferLayout: this.getAttributeManager()!.getBufferLayouts(),\n geometry: new Geometry({\n topology: 'triangle-strip',\n attributes: {\n positions: { size: 3, value: new Float32Array([0, -1, 0, 0, 1, 0, 1, -1, 0, 1, 1, 0]) },\n },\n }),\n isInstanced: true,\n })\n }\n}\n","import { CompositeLayer } from '@deck.gl/core'\nimport type {\n Accessor,\n AccessorContext,\n Color,\n DefaultProps,\n GetPickingInfoParams,\n Layer,\n LayerContext,\n LayerProps,\n PickingInfo,\n Unit,\n UpdateParameters,\n} from '@deck.gl/core'\nimport { GraphSimulation, defaultConfigValues } from '@cosmos.gl/graph'\nimport type { GraphSimulationConfig } from '@cosmos.gl/graph'\n\nimport { BLEND_PARAMETERS } from './blend-parameters'\nimport { CosmosPointsLayer } from './cosmos-points-layer'\nimport { CosmosLinksLayer } from './cosmos-links-layer'\n\n/**\n * Points input: an array to run accessors over (picking returns the original\n * objects), or the cosmos-native binary form — a point count plus optional\n * `[x0, y0, x1, y1, …]` initial positions. Points without given positions are\n * seeded randomly inside the simulation space.\n */\nexport type CosmosGraphPoints<PointDataT> = readonly PointDataT[] | {\n length: number;\n initialPositions?: Float32Array;\n /** Optional binary styling channels, keyed by accessor name (`getPointColor`, `getPointSize`). */\n attributes?: Record<string, unknown>;\n}\n\n/**\n * Links input: an array to run accessors over, or the cosmos-native\n * `[source0, target0, source1, target1, …]` array of point indices.\n * An array link whose source or target does not resolve to a point is dropped\n * from both the simulation and the rendering, with one warning per data change.\n */\nexport type CosmosGraphLinks<LinkDataT> = readonly LinkDataT[] | Float32Array\n\n/** Picking info from a CosmosGraphLayer: which kind of element was hit. */\nexport type CosmosGraphPickingInfo = PickingInfo & {\n elementType?: 'point' | 'link';\n}\n\nexport type CosmosGraphLayerProps<PointDataT = unknown, LinkDataT = unknown> =\n CosmosGraphLayerOwnProps<PointDataT, LinkDataT> & LayerProps\n\ntype CosmosGraphLayerOwnProps<PointDataT, LinkDataT> = {\n /** One entry per point — an array of your objects, or `{ length, initialPositions? }`. */\n points: CosmosGraphPoints<PointDataT>;\n /** One entry per link — an array of your objects, or a flat point-index pair array. */\n links?: CosmosGraphLinks<LinkDataT> | null;\n /**\n * Stable point id accessor. When provided (with array points), link\n * accessors may return ids instead of point indices.\n */\n getPointId?: Accessor<PointDataT, string | number> | null;\n /** Initial `[x, y]` position accessor for array points; points it leaves undefined are seeded randomly. */\n getPointPosition?: Accessor<PointDataT, readonly [number, number] | null | undefined> | null;\n /**\n * Point diameter accessor, in `pointSizeUnits`; `0` hides the point.\n * @default 4\n */\n getPointSize?: Accessor<PointDataT, number>;\n /**\n * Point RGBA color accessor, channels in 0..255.\n * @default [74, 92, 191, 230]\n */\n getPointColor?: Accessor<PointDataT, Color>;\n /**\n * The units of the point diameter.\n * @default 'pixels'\n */\n pointSizeUnits?: Unit;\n /**\n * Source accessor for array links: a point index, or a point id when\n * `getPointId` is set.\n * @default l => l.source\n */\n getLinkSource?: Accessor<LinkDataT, string | number>;\n /**\n * Target accessor for array links: a point index, or a point id when\n * `getPointId` is set.\n * @default l => l.target\n */\n getLinkTarget?: Accessor<LinkDataT, string | number>;\n /**\n * Link RGBA color accessor, channels in 0..255.\n * @default [94, 115, 194, 64]\n */\n getLinkColor?: Accessor<LinkDataT, Color>;\n /**\n * Link width accessor, in `linkWidthUnits`.\n * @default 1\n */\n getLinkWidth?: Accessor<LinkDataT, number>;\n /**\n * The units of the link width.\n * @default 'pixels'\n */\n linkWidthUnits?: Unit;\n /**\n * Lets pointer drags grab a point: pinned on drag start, moved with the\n * pointer, released per `unpinOnDragEnd`. View panning is suppressed while\n * a point is grabbed.\n * @default false\n */\n enablePointDrag?: boolean;\n /**\n * Simulation alpha to restart with when a drag starts, so the graph\n * responds to the moving point; `null` leaves the simulation untouched.\n * @default 0.1\n */\n dragReheatAlpha?: number | null;\n /**\n * Release the point on drag end; `false` keeps it pinned where dropped.\n * @default true\n */\n unpinOnDragEnd?: boolean;\n /** Called when a point drag starts. */\n onPointDragStart?: ((info: CosmosGraphPickingInfo) => void) | null;\n /** Called for every pointer move while a point is dragged. */\n onPointDrag?: ((info: CosmosGraphPickingInfo) => void) | null;\n /** Called when a point drag ends. */\n onPointDragEnd?: ((info: CosmosGraphPickingInfo) => void) | null;\n /** Simulation configuration, passed through to `GraphSimulation` (forces, spaceSize, callbacks). */\n simulationConfig?: GraphSimulationConfig;\n /**\n * Called once with the layer-owned `GraphSimulation` — the escape hatch for\n * advanced control (pause, pinning, sparse position writes).\n */\n onSimulationCreated?: ((simulation: GraphSimulation) => void) | null;\n}\n\nconst defaultProps: DefaultProps<CosmosGraphLayerProps> = {\n links: null,\n getPointId: { type: 'accessor', value: null },\n getPointPosition: { type: 'accessor', value: null },\n getPointSize: { type: 'accessor', value: 4 },\n getPointColor: { type: 'accessor', value: [74, 92, 191, 230] },\n pointSizeUnits: 'pixels',\n getLinkSource: { type: 'accessor', value: (l: unknown) => (l as { source: number }).source },\n getLinkTarget: { type: 'accessor', value: (l: unknown) => (l as { target: number }).target },\n getLinkColor: { type: 'accessor', value: [94, 115, 194, 64] },\n getLinkWidth: { type: 'accessor', value: 1 },\n linkWidthUnits: 'pixels',\n enablePointDrag: false,\n dragReheatAlpha: 0.1,\n unpinOnDragEnd: true,\n onPointDragStart: { type: 'function', value: null, optional: true },\n onPointDrag: { type: 'function', value: null, optional: true },\n onPointDragEnd: { type: 'function', value: null, optional: true },\n simulationConfig: { type: 'object', value: {}, compare: 2 },\n onSimulationCreated: { type: 'function', value: null, optional: true },\n // getSubLayerProps forwards `parameters` into every sublayer, so the\n // composite must carry the same pipeline-state default the primitives do\n parameters: { type: 'object', value: BLEND_PARAMETERS, optional: true, compare: 2 },\n}\n\n/** The slice of a deck gesture event the drag handlers need. */\ntype DragGestureEvent = {\n stopImmediatePropagation?: () => void;\n}\n\n/** The update-trigger keys the composite forwards to its sublayers. */\ntype CosmosUpdateTriggers = {\n getPointId?: unknown;\n getPointPosition?: unknown;\n getPointSize?: unknown;\n getPointColor?: unknown;\n getLinkSource?: unknown;\n getLinkTarget?: unknown;\n getLinkColor?: unknown;\n getLinkWidth?: unknown;\n}\n\n/** Resolves a deck accessor (function or constant) for one object. */\nconst resolveAccessor = <In, Out>(accessor: Accessor<In, Out>, object: In, info: AccessorContext<In>): Out =>\n typeof accessor === 'function' ? (accessor as (o: In, i: AccessorContext<In>) => Out)(object, info) : accessor\n\n/**\n * The batteries-included cosmos.gl graph layer: give it points and links, and\n * it owns the rest. The layer creates a `GraphSimulation` on deck's device,\n * ingests the data, advances the simulation once per animation frame from\n * deck's shared timeline while it runs (deck goes idle when it settles — no\n * `_animate` required), renders through `CosmosLinksLayer` + `CosmosPointsLayer`\n * (positions stay GPU-resident), and destroys the simulation when the layer is\n * removed. Picking reports `elementType: 'point' | 'link'` alongside the index\n * and, for array data, the original object.\n */\nexport class CosmosGraphLayer<PointDataT = unknown, LinkDataT = unknown> extends CompositeLayer<\n Required<CosmosGraphLayerOwnProps<PointDataT, LinkDataT>>\n> {\n public static layerName = 'CosmosGraphLayer'\n public static defaultProps = defaultProps\n\n declare public state: {\n simulation?: GraphSimulation;\n isReady: boolean;\n pointCount: number;\n pointsData: readonly PointDataT[] | { length: number; attributes?: Record<string, unknown> };\n linksData: readonly LinkDataT[] | { length: number; attributes: Record<string, unknown> } | null;\n /** Array links only: the resolved `[source, target]` point-index pairs, one per entry of `linksData`. */\n linkIndices: Float32Array | null;\n draggedPointIndex: number | null;\n animationHandle?: number;\n }\n\n public get isLoaded (): boolean {\n return super.isLoaded && Boolean(this.state?.isReady)\n }\n\n public initializeState (): void {\n const { device, timeline } = this.context\n if (device.type !== 'webgl') {\n throw new Error(\n `@cosmos.gl/deck-layers requires a WebGL 2 device — the cosmos.gl simulation is WebGL-only, got '${device.type}'`\n )\n }\n\n const simulation = new GraphSimulation(this.props.simulationConfig, Promise.resolve(device))\n this.state = {\n simulation,\n isReady: false,\n pointCount: 0,\n pointsData: { length: 0 },\n linksData: null,\n linkIndices: null,\n draggedPointIndex: null,\n // Step the simulation exactly once per animation frame, independent of\n // draw passes (draw runs per viewport and again while picking)\n animationHandle: timeline.attachAnimation({ setTime: () => this._onTimelineTick() }),\n }\n\n this.props.onSimulationCreated?.(simulation)\n\n simulation.ready.then(() => {\n // `this` may be a stale descriptor by now; state is the stable identity\n if (this.state?.simulation !== simulation) return\n const layer = this.getCurrentLayer() ?? this\n layer.setState({ isReady: true })\n }).catch((error: Error) => {\n console.error('@cosmos.gl/deck-layers: simulation failed to initialize', error)\n })\n }\n\n public updateState (params: UpdateParameters<this>): void {\n super.updateState(params)\n const { props, oldProps, changeFlags } = params\n const simulation = this.state.simulation\n if (!simulation) return\n\n if (changeFlags.propsChanged && props.simulationConfig !== oldProps.simulationConfig) {\n simulation.setConfig(props.simulationConfig)\n }\n // Link endpoints are resolved at ingest, so a change to the id map or to\n // an endpoint accessor re-ingests like a data change\n const triggers = typeof changeFlags.updateTriggersChanged === 'object'\n ? changeFlags.updateTriggersChanged as CosmosUpdateTriggers\n : undefined\n const dataChanged =\n props.points !== oldProps.points ||\n props.links !== oldProps.links ||\n Boolean(\n triggers?.getPointPosition || triggers?.getPointId || triggers?.getLinkSource || triggers?.getLinkTarget\n )\n if (dataChanged) {\n this._updateSimulationData()\n }\n }\n\n public renderLayers (): Layer[] | null {\n const { simulation, isReady, pointCount, pointsData, linksData, linkIndices } = this.state\n if (!simulation || !isReady || pointCount === 0) return null\n\n const { getPointSize, getPointColor, pointSizeUnits, getLinkColor, getLinkWidth, linkWidthUnits } = this.props\n const triggers: CosmosUpdateTriggers = this.props.updateTriggers ?? {}\n const layers: Layer[] = []\n\n if (linksData) {\n layers.push(\n new CosmosLinksLayer<LinkDataT>(\n this.getSubLayerProps({\n id: 'links',\n updateTriggers: {\n getLinkSource: triggers.getLinkSource,\n getLinkTarget: triggers.getLinkTarget,\n getLinkColor: triggers.getLinkColor,\n getLinkWidth: triggers.getLinkWidth,\n },\n }),\n {\n data: linksData as CosmosLinksLayer<LinkDataT>['props']['data'],\n graph: simulation,\n getLinkColor,\n getLinkWidth,\n linkWidthUnits,\n // getSubLayerProps does not forward `transitions`\n transitions: this.props.transitions,\n },\n Array.isArray(linksData) && linkIndices\n ? {\n // Array links read the endpoints resolved at ingest, so the\n // rendered links are exactly the simulated ones\n getLinkSource: (_: LinkDataT, { index }: AccessorContext<LinkDataT>): number => linkIndices[index * 2] as number,\n getLinkTarget: (_: LinkDataT, { index }: AccessorContext<LinkDataT>): number => linkIndices[index * 2 + 1] as number,\n }\n : {}\n )\n )\n }\n\n layers.push(\n new CosmosPointsLayer<PointDataT>(\n this.getSubLayerProps({\n id: 'points',\n updateTriggers: {\n getPointSize: triggers.getPointSize,\n getPointColor: triggers.getPointColor,\n },\n }),\n {\n data: pointsData as CosmosPointsLayer<PointDataT>['props']['data'],\n graph: simulation,\n getPointSize,\n getPointColor,\n pointSizeUnits,\n // getSubLayerProps does not forward `transitions`\n transitions: this.props.transitions,\n }\n )\n )\n\n return layers\n }\n\n public onDragStart (info: PickingInfo, event: DragGestureEvent): boolean {\n const { simulation } = this.state\n const { enablePointDrag, dragReheatAlpha } = this.props\n const picked = info as CosmosGraphPickingInfo\n if (!enablePointDrag || !simulation || picked.elementType !== 'point' || info.index < 0) return false\n\n // A direct field write: per-gesture state must not re-render sublayers\n this.state.draggedPointIndex = info.index\n simulation.setPinnedPoint(info.index, true)\n if (dragReheatAlpha !== null) simulation.start(dragReheatAlpha)\n // A grabbed point must not also pan the view\n event.stopImmediatePropagation?.()\n this.props.onPointDragStart?.(picked)\n return true\n }\n\n public onDrag (info: PickingInfo, event: DragGestureEvent): boolean {\n const { simulation, draggedPointIndex } = this.state\n if (!simulation || draggedPointIndex === null) return false\n\n const [x, y] = this._dragCoordinate(info)\n simulation.setPointPosition(draggedPointIndex, x, y)\n event.stopImmediatePropagation?.()\n // Repaint even when the simulation is settled and the ticker is idle\n ;(this.getCurrentLayer() ?? this).setNeedsRedraw()\n this.props.onPointDrag?.(info as CosmosGraphPickingInfo)\n return true\n }\n\n public onDragEnd (info: PickingInfo, event: DragGestureEvent): boolean {\n const { simulation, draggedPointIndex } = this.state\n if (!simulation || draggedPointIndex === null) return false\n\n if (this.props.unpinOnDragEnd) simulation.setPinnedPoint(draggedPointIndex, false)\n this.state.draggedPointIndex = null\n event.stopImmediatePropagation?.()\n this.props.onPointDragEnd?.(info as CosmosGraphPickingInfo)\n return true\n }\n\n public getPickingInfo (params: GetPickingInfoParams): CosmosGraphPickingInfo {\n const info: CosmosGraphPickingInfo = params.info\n if (params.sourceLayer) {\n info.elementType = params.sourceLayer.id.endsWith('-links') ? 'link' : 'point'\n }\n return info\n }\n\n /** The whole simulation space; lets deck's viewport helpers frame the graph. */\n public getBounds (): [number[], number[]] | null {\n const spaceSize = this.props.simulationConfig?.spaceSize ?? defaultConfigValues.spaceSize\n return [[0, 0, 0], [spaceSize, spaceSize, 0]]\n }\n\n public finalizeState (context: LayerContext): void {\n if (this.state?.animationHandle !== undefined) {\n this.context.timeline.detachAnimation(this.state.animationHandle)\n }\n this.state?.simulation?.destroy()\n super.finalizeState(context)\n }\n\n /**\n * Points and links have separate index spaces, so the same picking color\n * exists in both sublayers: highlight only the sublayer that was hovered\n * and clear the other, or hovering point N would also tint link N.\n */\n protected _updateAutoHighlight (info: PickingInfo): void {\n for (const layer of this.getSubLayers()) {\n if (layer.id === info.sourceLayer?.id) {\n layer.updateAutoHighlight(info)\n } else {\n layer.updateAutoHighlight({ ...info, picked: false })\n }\n }\n }\n\n private _onTimelineTick (): void {\n const { simulation, isReady } = this.state ?? {}\n if (!simulation || !isReady || !simulation.isSimulationRunning) return\n simulation.step()\n // Repaint the frame this step just computed; when the simulation settles,\n // the flag stops being set and deck goes idle on its own\n const layer = this.getCurrentLayer() ?? this\n layer.setNeedsRedraw()\n }\n\n private _dragCoordinate (info: PickingInfo): [number, number] {\n // info.coordinate is unprojected at the current pointer; it can be absent\n // when the pointer leaves the picked object's viewport\n if (info.coordinate) return [info.coordinate[0] as number, info.coordinate[1] as number]\n const unprojected = this.context.viewport.unproject([info.x, info.y])\n return [unprojected[0] as number, unprojected[1] as number]\n }\n\n private _updateSimulationData (): void {\n const simulation = this.state.simulation\n if (!simulation) return\n const { points, links, getPointId, getPointPosition } = this.props\n const spaceSize = this.props.simulationConfig?.spaceSize ?? defaultConfigValues.spaceSize\n\n // Unseeded points land in the middle half of the space, clear of the walls\n const randomCoordinate = (): number => spaceSize * (0.25 + Math.random() * 0.5)\n\n let pointCount: number\n let positions: Float32Array\n let pointsData: this['state']['pointsData']\n let idToIndex: Map<string | number, number> | null = null\n\n if (Array.isArray(points)) {\n const pointArray = points as readonly PointDataT[]\n pointCount = pointArray.length\n positions = new Float32Array(pointCount * 2)\n if (getPointId) idToIndex = new Map()\n for (let i = 0; i < pointCount; i += 1) {\n const point = pointArray[i] as PointDataT\n const info: AccessorContext<PointDataT> = { index: i, data: pointArray, target: [] }\n const position = getPointPosition ? resolveAccessor(getPointPosition, point, info) : null\n positions[i * 2] = position ? position[0] : randomCoordinate()\n positions[i * 2 + 1] = position ? position[1] : randomCoordinate()\n if (idToIndex && getPointId) idToIndex.set(resolveAccessor(getPointId, point, info), i)\n }\n pointsData = pointArray\n } else {\n const binaryPoints = points as { length: number; initialPositions?: Float32Array; attributes?: Record<string, unknown> }\n pointCount = binaryPoints.length\n if (binaryPoints.initialPositions) {\n positions = binaryPoints.initialPositions\n } else {\n positions = new Float32Array(pointCount * 2)\n for (let i = 0; i < positions.length; i += 1) positions[i] = randomCoordinate()\n }\n pointsData = binaryPoints.attributes\n ? { length: pointCount, attributes: binaryPoints.attributes }\n : { length: pointCount }\n }\n\n let linkArray: Float32Array | null = null\n let linksData: this['state']['linksData'] = null\n let linkIndices: Float32Array | null = null\n if (links instanceof Float32Array) {\n linkArray = links\n // The cosmos pair array feeds deck as two interleaved binary attributes\n linksData = {\n length: links.length / 2,\n attributes: {\n getLinkSource: { value: links, size: 1, stride: 8 },\n getLinkTarget: { value: links, size: 1, offset: 4, stride: 8 },\n },\n }\n } else if (Array.isArray(links)) {\n const linkObjects = links as readonly LinkDataT[]\n const { getLinkSource, getLinkTarget } = this.props\n // An endpoint is a point index, or a point id when the id map exists;\n // anything that does not name a point drops the whole link from both\n // the simulation and the rendering, so the two never disagree\n const resolveEndpoint = (endpoint: string | number): number | undefined => {\n const index = idToIndex ? idToIndex.get(endpoint) : endpoint\n return typeof index === 'number' && Number.isInteger(index) && index >= 0 && index < pointCount\n ? index\n : undefined\n }\n const keptLinks: LinkDataT[] = []\n const keptIndices: number[] = []\n for (let i = 0; i < linkObjects.length; i += 1) {\n const link = linkObjects[i] as LinkDataT\n const info: AccessorContext<LinkDataT> = { index: i, data: linkObjects, target: [] }\n const source = resolveEndpoint(resolveAccessor(getLinkSource, link, info))\n const target = resolveEndpoint(resolveAccessor(getLinkTarget, link, info))\n if (source === undefined || target === undefined) continue\n keptLinks.push(link)\n keptIndices.push(source, target)\n }\n const dropped = linkObjects.length - keptLinks.length\n if (dropped > 0) {\n const hint = idToIndex ? 'getLinkSource / getLinkTarget against getPointId' : 'getLinkSource / getLinkTarget'\n console.warn(\n `@cosmos.gl/deck-layers: dropped ${dropped} of ${linkObjects.length} links whose source or target is not a point — check ${hint}`\n )\n }\n linkArray = Float32Array.from(keptIndices)\n linkIndices = linkArray\n linksData = keptLinks\n }\n\n simulation.setPointPositions(positions)\n simulation.setLinks(linkArray ?? new Float32Array(0))\n simulation.applyData()\n\n this.setState({ pointCount, pointsData, linksData, linkIndices })\n }\n}\n"],"names":["BLEND_PARAMETERS","uniformBlock","cosmosPointsUniforms","DEFAULT_POINT_COLOR","vs","fs","defaultProps","_CosmosPointsLayer","Layer","project32","picking","params","_a","positionInfo","model","moduleProps","UNIT","Model","Geometry","CosmosPointsLayer","cosmosLinksUniforms","DEFAULT_LINK_COLOR","l","_CosmosLinksLayer","CosmosLinksLayer","resolveAccessor","accessor","object","info","_CosmosGraphLayer","CompositeLayer","device","timeline","simulation","GraphSimulation","_b","error","props","oldProps","changeFlags","triggers","isReady","pointCount","pointsData","linksData","linkIndices","getPointSize","getPointColor","pointSizeUnits","getLinkColor","getLinkWidth","linkWidthUnits","layers","_","index","event","enablePointDrag","dragReheatAlpha","picked","_c","draggedPointIndex","x","y","spaceSize","defaultConfigValues","context","layer","unprojected","points","links","getPointId","getPointPosition","randomCoordinate","positions","idToIndex","pointArray","i","point","position","binaryPoints","linkArray","linkObjects","getLinkSource","getLinkTarget","resolveEndpoint","endpoint","keptLinks","keptIndices","link","source","target","dropped","hint","CosmosGraphLayer"],"mappings":";;;AAYO,MAAMA,IAAmB;AAAA,EAC9B,mBAAmB;AAAA,EACnB,cAAc;AAAA,EACd,OAAO;AAAA,EACP,qBAAqB;AAAA,EACrB,qBAAqB;AAAA,EACrB,qBAAqB;AAAA,EACrB,qBAAqB;AAAA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,UACN,mCAAmCiB,CAAO,OAAOV,EAAY,MAAM,wDAAwDW,CAAI;AAAA,QAAA;AAAA,MAEnI;AACA,MAAAZ,IAAY,aAAa,KAAKO,CAAW,GACzC1C,IAAcmC,GACdpC,IAAY0C;AAAA,IACd;AAEA,IAAArD,EAAW,kBAAkBwC,CAAS,GACtCxC,EAAW,SAAS+C,KAAa,IAAI,aAAa,CAAC,CAAC,GACpD/C,EAAW,UAAA,GAEX,KAAK,SAAS,EAAE,YAAAS,GAAY,YAAAC,GAAY,WAAAC,GAAW,aAAAC,GAAa;AAAA,EAClE;AACF;AA9UEhB,EAAc,YAAY,oBAC1BA,EAAc,eAAevB;AAJxB,IAAMuF,IAANhE;"}
@@ -0,0 +1,9 @@
1
+ import { PointPositionTexture } from '@cosmos.gl/graph';
2
+ /**
3
+ * Anything that exposes a live cosmos.gl position texture — a
4
+ * `GraphSimulation`, a headless `Graph`, or a future engine with the same
5
+ * contract. The layers are typed against this shape, never a concrete class.
6
+ */
7
+ export type PositionTextureSource = {
8
+ getPointPositionTexture(): PointPositionTexture | undefined;
9
+ };
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@cosmos.gl/deck-layers",
3
+ "version": "3.5.0-beta.2",
4
+ "description": "deck.gl layers rendering the cosmos.gl GPU force simulation — zero-copy position sampling on a shared luma.gl device",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git://github.com/cosmosgl/graph.git",
11
+ "directory": "integrations/deck-layers"
12
+ },
13
+ "type": "module",
14
+ "sideEffects": false,
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "engines": {
19
+ "node": ">=22.0.0"
20
+ },
21
+ "keywords": [
22
+ "deck.gl",
23
+ "graph",
24
+ "webgl",
25
+ "force",
26
+ "simulation",
27
+ "visualization",
28
+ "layers"
29
+ ],
30
+ "homepage": "https://cosmosgl.github.io/graph",
31
+ "author": "cosmos.gl",
32
+ "peerDependencies": {
33
+ "@deck.gl/core": "~9.3.0",
34
+ "@luma.gl/core": "~9.3.0",
35
+ "@luma.gl/engine": "~9.3.0",
36
+ "@luma.gl/shadertools": "~9.3.0",
37
+ "@cosmos.gl/graph": "^3.5.0-beta.2"
38
+ },
39
+ "devDependencies": {
40
+ "@deck.gl/core": "~9.3.0",
41
+ "@deck.gl/layers": "~9.3.0",
42
+ "@luma.gl/core": "~9.3.6",
43
+ "@luma.gl/engine": "~9.3.6",
44
+ "@luma.gl/shadertools": "~9.3.6",
45
+ "@storybook/html": "^8.4.5",
46
+ "typescript": "^5.9.3",
47
+ "vite": "^6.4.3",
48
+ "vite-plugin-dts": "^4.3.0",
49
+ "@cosmos.gl/graph": "^3.5.0-beta.2"
50
+ },
51
+ "scripts": {
52
+ "build": "vite build",
53
+ "watch": "vite build --watch",
54
+ "typecheck": "tsc -p tsconfig.typecheck.json"
55
+ }
56
+ }