@sqlrooms/cosmos 0.4.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/LICENSE.md +9 -0
- package/dist/CosmosGraph.d.ts +64 -0
- package/dist/CosmosGraph.d.ts.map +1 -0
- package/dist/CosmosGraph.js +54 -0
- package/dist/CosmosGraph.js.map +1 -0
- package/dist/CosmosGraphContext.d.ts +76 -0
- package/dist/CosmosGraphContext.d.ts.map +1 -0
- package/dist/CosmosGraphContext.js +95 -0
- package/dist/CosmosGraphContext.js.map +1 -0
- package/dist/CosmosGraphControls.d.ts +48 -0
- package/dist/CosmosGraphControls.d.ts.map +1 -0
- package/dist/CosmosGraphControls.js +41 -0
- package/dist/CosmosGraphControls.js.map +1 -0
- package/dist/CosmosSimulationControls.d.ts +79 -0
- package/dist/CosmosSimulationControls.d.ts.map +1 -0
- package/dist/CosmosSimulationControls.js +140 -0
- package/dist/CosmosSimulationControls.js.map +1 -0
- package/dist/components/CosmosGraph.d.ts +14 -0
- package/dist/components/CosmosGraph.d.ts.map +1 -0
- package/dist/components/CosmosGraph.js +130 -0
- package/dist/components/CosmosGraph.js.map +1 -0
- package/dist/config.d.ts +24 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +18 -0
- package/dist/config.js.map +1 -0
- package/dist/hooks/index.d.ts +29 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +29 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useGraph.d.ts +49 -0
- package/dist/hooks/useGraph.d.ts.map +1 -0
- package/dist/hooks/useGraph.js +93 -0
- package/dist/hooks/useGraph.js.map +1 -0
- package/dist/hooks/useGraphConfig.d.ts +101 -0
- package/dist/hooks/useGraphConfig.d.ts.map +1 -0
- package/dist/hooks/useGraphConfig.js +53 -0
- package/dist/hooks/useGraphConfig.js.map +1 -0
- package/dist/hooks/useHoverState.d.ts +55 -0
- package/dist/hooks/useHoverState.d.ts.map +1 -0
- package/dist/hooks/useHoverState.js +57 -0
- package/dist/hooks/useHoverState.js.map +1 -0
- package/dist/hooks/useRelativeCoordinates.d.ts +2 -0
- package/dist/hooks/useRelativeCoordinates.d.ts.map +1 -0
- package/dist/hooks/useRelativeCoordinates.js +10 -0
- package/dist/hooks/useRelativeCoordinates.js.map +1 -0
- package/dist/index.d.ts +92 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +92 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/coordinates.d.ts +32 -0
- package/dist/utils/coordinates.d.ts.map +1 -0
- package/dist/utils/coordinates.js +29 -0
- package/dist/utils/coordinates.js.map +1 -0
- package/package.json +38 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { useState, useCallback } from 'react';
|
|
2
|
+
import { hasClientCoordinates } from '../utils/coordinates';
|
|
3
|
+
/**
|
|
4
|
+
* A custom hook that manages hover state for graph points.
|
|
5
|
+
*
|
|
6
|
+
* This hook provides functionality to:
|
|
7
|
+
* - Track which point is currently being hovered
|
|
8
|
+
* - Store the hover position coordinates
|
|
9
|
+
* - Clear the hover state
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* const Graph = () => {
|
|
14
|
+
* const calcRelativeCoords = useRelativeCoordinates(containerRef);
|
|
15
|
+
* const { hoveredPoint, onPointMouseOver, clearHoverState } = useHoverState(calcRelativeCoords);
|
|
16
|
+
*
|
|
17
|
+
* return (
|
|
18
|
+
* <div ref={containerRef}>
|
|
19
|
+
* <CosmosGraph
|
|
20
|
+
* onPointMouseOver={onPointMouseOver}
|
|
21
|
+
* onPointMouseOut={clearHoverState}
|
|
22
|
+
* />
|
|
23
|
+
* {hoveredPoint && (
|
|
24
|
+
* <Tooltip
|
|
25
|
+
* x={hoveredPoint.position[0]}
|
|
26
|
+
* y={hoveredPoint.position[1]}
|
|
27
|
+
* />
|
|
28
|
+
* )}
|
|
29
|
+
* </div>
|
|
30
|
+
* );
|
|
31
|
+
* };
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @param calcRelativeCoordinates - A function that converts client coordinates to container-relative coordinates
|
|
35
|
+
* @returns An object containing the hover state and handlers
|
|
36
|
+
*/
|
|
37
|
+
export const useHoverState = (calcRelativeCoordinates) => {
|
|
38
|
+
const [hoveredPoint, setHoveredPoint] = useState(null);
|
|
39
|
+
const onPointMouseOver = useCallback((index, _pointPosition, event) => {
|
|
40
|
+
if (hasClientCoordinates(event)) {
|
|
41
|
+
setHoveredPoint({
|
|
42
|
+
index,
|
|
43
|
+
position: calcRelativeCoordinates(event.clientX, event.clientY),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}, [calcRelativeCoordinates]);
|
|
47
|
+
const clearHoverState = useCallback(() => setHoveredPoint(null), []);
|
|
48
|
+
return {
|
|
49
|
+
/** The current hover state, containing the index and position of the hovered point, or null if no point is hovered */
|
|
50
|
+
hoveredPoint,
|
|
51
|
+
/** Handler to be called when a point is hovered. Updates the hover state with the point's index and position */
|
|
52
|
+
onPointMouseOver,
|
|
53
|
+
/** Handler to clear the hover state, typically called when the mouse leaves a point */
|
|
54
|
+
clearHoverState,
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=useHoverState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useHoverState.js","sourceRoot":"","sources":["../../src/hooks/useHoverState.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAE,WAAW,EAAC,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAC,oBAAoB,EAAC,MAAM,sBAAsB,CAAC;AAe1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,uBAAkE,EAClE,EAAE;IACF,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAa,IAAI,CAAC,CAAC;IAEnE,MAAM,gBAAgB,GACpB,WAAW,CACT,CACE,KAAa,EACb,cAAgC,EAChC,KAA8B,EAC9B,EAAE;QACF,IAAI,oBAAoB,CAAC,KAAK,CAAC,EAAE,CAAC;YAChC,eAAe,CAAC;gBACd,KAAK;gBACL,QAAQ,EAAE,uBAAuB,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC;aAChE,CAAC,CAAC;QACL,CAAC;IACH,CAAC,EACD,CAAC,uBAAuB,CAAC,CAC1B,CAAC;IAEJ,MAAM,eAAe,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;IAErE,OAAO;QACL,sHAAsH;QACtH,YAAY;QACZ,gHAAgH;QAChH,gBAAgB;QAChB,uFAAuF;QACvF,eAAe;KAChB,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRelativeCoordinates.d.ts","sourceRoot":"","sources":["../../src/hooks/useRelativeCoordinates.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,sBAAsB,iBACnB,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,SAGpC,MAAM,KAAK,MAAM,KAAG,CAAC,MAAM,EAAE,MAAM,CAO1C,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
export const useRelativeCoordinates = (containerRef) => {
|
|
3
|
+
return useCallback((x, y) => {
|
|
4
|
+
if (!containerRef.current)
|
|
5
|
+
return [0, 0];
|
|
6
|
+
const rect = containerRef.current.getBoundingClientRect();
|
|
7
|
+
return [x - rect.left, y - rect.top];
|
|
8
|
+
}, [containerRef]);
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=useRelativeCoordinates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRelativeCoordinates.js","sourceRoot":"","sources":["../../src/hooks/useRelativeCoordinates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,OAAO,CAAC;AAElC,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,YAA0C,EAC1C,EAAE;IACF,OAAO,WAAW,CAChB,CAAC,CAAS,EAAE,CAAS,EAAoB,EAAE;QACzC,IAAI,CAAC,YAAY,CAAC,OAAO;YAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACzC,MAAM,IAAI,GAAG,YAAY,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC;QAC1D,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IACvC,CAAC,EACD,CAAC,YAAY,CAAC,CACf,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @sqlrooms/cosmos - A React wrapper for the Cosmograph visualization library
|
|
3
|
+
*
|
|
4
|
+
* This package provides React components and hooks for creating interactive graph visualizations
|
|
5
|
+
* using the Cosmograph WebGL-based graph visualization library. It includes components for
|
|
6
|
+
* rendering graphs, managing graph state, and controlling graph interactions.
|
|
7
|
+
*
|
|
8
|
+
* @example Basic usage
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import { CosmosGraph, CosmosGraphControls } from '@sqlrooms/cosmos';
|
|
11
|
+
*
|
|
12
|
+
* const MyGraph = () => {
|
|
13
|
+
* return (
|
|
14
|
+
* <div style={{ width: '800px', height: '600px' }}>
|
|
15
|
+
* <CosmosGraph
|
|
16
|
+
* config={graphConfig}
|
|
17
|
+
* pointPositions={positions}
|
|
18
|
+
* pointColors={colors}
|
|
19
|
+
* pointSizes={sizes}
|
|
20
|
+
* >
|
|
21
|
+
* <CosmosGraphControls />
|
|
22
|
+
* </CosmosGraph>
|
|
23
|
+
* </div>
|
|
24
|
+
* );
|
|
25
|
+
* };
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @packageDocumentation
|
|
29
|
+
*/
|
|
30
|
+
export { CosmosGraph } from './CosmosGraph';
|
|
31
|
+
export { CosmosGraphControls } from './CosmosGraphControls';
|
|
32
|
+
/**
|
|
33
|
+
* A component that provides fine-grained controls for the graph simulation parameters.
|
|
34
|
+
* Must be used within a CosmosGraph component as it relies on the CosmosGraphContext.
|
|
35
|
+
*
|
|
36
|
+
* Features:
|
|
37
|
+
* - Slider controls for gravity, repulsion, link strength, link distance, friction, and decay
|
|
38
|
+
* - Real-time parameter adjustment with immediate visual feedback
|
|
39
|
+
* - Tooltips with parameter descriptions
|
|
40
|
+
* - Customizable positioning
|
|
41
|
+
*
|
|
42
|
+
* @example Basic usage
|
|
43
|
+
* ```tsx
|
|
44
|
+
* <CosmosGraph {...graphProps}>
|
|
45
|
+
* <CosmosSimulationControls />
|
|
46
|
+
* </CosmosGraph>
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @example Custom positioning
|
|
50
|
+
* ```tsx
|
|
51
|
+
* <CosmosGraph {...graphProps}>
|
|
52
|
+
* <CosmosSimulationControls className="absolute bottom-4 left-4" />
|
|
53
|
+
* </CosmosGraph>
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export { CosmosSimulationControls } from './CosmosSimulationControls';
|
|
57
|
+
export type { CosmosGraphProps } from './CosmosGraph';
|
|
58
|
+
export { useCosmosGraph } from './CosmosGraphContext';
|
|
59
|
+
export { useGraph, useHoverState, useGraphConfig } from './hooks';
|
|
60
|
+
export type { HoverState } from './hooks/useHoverState';
|
|
61
|
+
export type { WithClientCoordinates } from './utils/coordinates';
|
|
62
|
+
export { hasClientCoordinates } from './utils/coordinates';
|
|
63
|
+
/**
|
|
64
|
+
* Zod schema for validating and describing graph simulation configuration parameters.
|
|
65
|
+
*
|
|
66
|
+
* Available parameters:
|
|
67
|
+
* - `simulationGravity` (number): Gravity force in the simulation. Controls how strongly nodes are pulled toward the center.
|
|
68
|
+
* - `simulationRepulsion` (number): Repulsion force between nodes. Higher values make nodes push away from each other more strongly.
|
|
69
|
+
* - `simulationLinkSpring` (number): Spring force for links between nodes. Higher values make connected nodes pull together more strongly.
|
|
70
|
+
* - `simulationLinkDistance` (number): Target distance between linked nodes. Defines the natural length of links in the simulation.
|
|
71
|
+
* - `simulationFriction` (number): Friction coefficient in the simulation. Higher values make node movement more damped.
|
|
72
|
+
* - `simulationDecay` (number): Decay coefficient in the simulation. Lower values make the simulation "cool down" more slowly.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```tsx
|
|
76
|
+
* import { CosmosSimulationConfigSchema } from '@sqlrooms/cosmos';
|
|
77
|
+
*
|
|
78
|
+
* const config = {
|
|
79
|
+
* simulationGravity: 0.1,
|
|
80
|
+
* simulationRepulsion: 1.0,
|
|
81
|
+
* simulationLinkSpring: 1.0,
|
|
82
|
+
* simulationLinkDistance: 10,
|
|
83
|
+
* simulationFriction: 0.85,
|
|
84
|
+
* simulationDecay: 1000
|
|
85
|
+
* };
|
|
86
|
+
*
|
|
87
|
+
* // Validate the config
|
|
88
|
+
* const validConfig = CosmosSimulationConfigSchema.parse(config);
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export { CosmosSimulationConfigSchema } from './config';
|
|
92
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAC,wBAAwB,EAAC,MAAM,4BAA4B,CAAC;AACpE,YAAY,EAAC,gBAAgB,EAAC,MAAM,eAAe,CAAC;AAGpD,OAAO,EAAC,cAAc,EAAC,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAC,QAAQ,EAAE,aAAa,EAAE,cAAc,EAAC,MAAM,SAAS,CAAC;AAChE,YAAY,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAGtD,YAAY,EAAC,qBAAqB,EAAC,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAC,oBAAoB,EAAC,MAAM,qBAAqB,CAAC;AAGzD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,EAAC,4BAA4B,EAAC,MAAM,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @sqlrooms/cosmos - A React wrapper for the Cosmograph visualization library
|
|
3
|
+
*
|
|
4
|
+
* This package provides React components and hooks for creating interactive graph visualizations
|
|
5
|
+
* using the Cosmograph WebGL-based graph visualization library. It includes components for
|
|
6
|
+
* rendering graphs, managing graph state, and controlling graph interactions.
|
|
7
|
+
*
|
|
8
|
+
* @example Basic usage
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import { CosmosGraph, CosmosGraphControls } from '@sqlrooms/cosmos';
|
|
11
|
+
*
|
|
12
|
+
* const MyGraph = () => {
|
|
13
|
+
* return (
|
|
14
|
+
* <div style={{ width: '800px', height: '600px' }}>
|
|
15
|
+
* <CosmosGraph
|
|
16
|
+
* config={graphConfig}
|
|
17
|
+
* pointPositions={positions}
|
|
18
|
+
* pointColors={colors}
|
|
19
|
+
* pointSizes={sizes}
|
|
20
|
+
* >
|
|
21
|
+
* <CosmosGraphControls />
|
|
22
|
+
* </CosmosGraph>
|
|
23
|
+
* </div>
|
|
24
|
+
* );
|
|
25
|
+
* };
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @packageDocumentation
|
|
29
|
+
*/
|
|
30
|
+
// Components
|
|
31
|
+
export { CosmosGraph } from './CosmosGraph';
|
|
32
|
+
export { CosmosGraphControls } from './CosmosGraphControls';
|
|
33
|
+
/**
|
|
34
|
+
* A component that provides fine-grained controls for the graph simulation parameters.
|
|
35
|
+
* Must be used within a CosmosGraph component as it relies on the CosmosGraphContext.
|
|
36
|
+
*
|
|
37
|
+
* Features:
|
|
38
|
+
* - Slider controls for gravity, repulsion, link strength, link distance, friction, and decay
|
|
39
|
+
* - Real-time parameter adjustment with immediate visual feedback
|
|
40
|
+
* - Tooltips with parameter descriptions
|
|
41
|
+
* - Customizable positioning
|
|
42
|
+
*
|
|
43
|
+
* @example Basic usage
|
|
44
|
+
* ```tsx
|
|
45
|
+
* <CosmosGraph {...graphProps}>
|
|
46
|
+
* <CosmosSimulationControls />
|
|
47
|
+
* </CosmosGraph>
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @example Custom positioning
|
|
51
|
+
* ```tsx
|
|
52
|
+
* <CosmosGraph {...graphProps}>
|
|
53
|
+
* <CosmosSimulationControls className="absolute bottom-4 left-4" />
|
|
54
|
+
* </CosmosGraph>
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export { CosmosSimulationControls } from './CosmosSimulationControls';
|
|
58
|
+
// Context and hooks
|
|
59
|
+
export { useCosmosGraph } from './CosmosGraphContext';
|
|
60
|
+
export { useGraph, useHoverState, useGraphConfig } from './hooks';
|
|
61
|
+
export { hasClientCoordinates } from './utils/coordinates';
|
|
62
|
+
// Configuration
|
|
63
|
+
/**
|
|
64
|
+
* Zod schema for validating and describing graph simulation configuration parameters.
|
|
65
|
+
*
|
|
66
|
+
* Available parameters:
|
|
67
|
+
* - `simulationGravity` (number): Gravity force in the simulation. Controls how strongly nodes are pulled toward the center.
|
|
68
|
+
* - `simulationRepulsion` (number): Repulsion force between nodes. Higher values make nodes push away from each other more strongly.
|
|
69
|
+
* - `simulationLinkSpring` (number): Spring force for links between nodes. Higher values make connected nodes pull together more strongly.
|
|
70
|
+
* - `simulationLinkDistance` (number): Target distance between linked nodes. Defines the natural length of links in the simulation.
|
|
71
|
+
* - `simulationFriction` (number): Friction coefficient in the simulation. Higher values make node movement more damped.
|
|
72
|
+
* - `simulationDecay` (number): Decay coefficient in the simulation. Lower values make the simulation "cool down" more slowly.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```tsx
|
|
76
|
+
* import { CosmosSimulationConfigSchema } from '@sqlrooms/cosmos';
|
|
77
|
+
*
|
|
78
|
+
* const config = {
|
|
79
|
+
* simulationGravity: 0.1,
|
|
80
|
+
* simulationRepulsion: 1.0,
|
|
81
|
+
* simulationLinkSpring: 1.0,
|
|
82
|
+
* simulationLinkDistance: 10,
|
|
83
|
+
* simulationFriction: 0.85,
|
|
84
|
+
* simulationDecay: 1000
|
|
85
|
+
* };
|
|
86
|
+
*
|
|
87
|
+
* // Validate the config
|
|
88
|
+
* const validConfig = CosmosSimulationConfigSchema.parse(config);
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export { CosmosSimulationConfigSchema } from './config';
|
|
92
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,aAAa;AACb,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAC,wBAAwB,EAAC,MAAM,4BAA4B,CAAC;AAGpE,oBAAoB;AACpB,OAAO,EAAC,cAAc,EAAC,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAC,QAAQ,EAAE,aAAa,EAAE,cAAc,EAAC,MAAM,SAAS,CAAC;AAKhE,OAAO,EAAC,oBAAoB,EAAC,MAAM,qBAAqB,CAAC;AAEzD,gBAAgB;AAChB;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,EAAC,4BAA4B,EAAC,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for objects that contain client coordinates.
|
|
3
|
+
* Typically used with mouse or pointer events.
|
|
4
|
+
*/
|
|
5
|
+
export type WithClientCoordinates = {
|
|
6
|
+
/** The horizontal coordinate relative to the client area */
|
|
7
|
+
clientX: number;
|
|
8
|
+
/** The vertical coordinate relative to the client area */
|
|
9
|
+
clientY: number;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Type guard that checks if an unknown value has client coordinates.
|
|
13
|
+
*
|
|
14
|
+
* This function performs a runtime check to ensure that an object has valid
|
|
15
|
+
* clientX and clientY number properties. It's useful for handling events
|
|
16
|
+
* that may or may not include coordinate information.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const handleEvent = (event: unknown) => {
|
|
21
|
+
* if (hasClientCoordinates(event)) {
|
|
22
|
+
* // TypeScript now knows event has clientX and clientY
|
|
23
|
+
* console.log(event.clientX, event.clientY);
|
|
24
|
+
* }
|
|
25
|
+
* };
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @param event - The value to check for client coordinates
|
|
29
|
+
* @returns A type predicate indicating if the value has client coordinates
|
|
30
|
+
*/
|
|
31
|
+
export declare const hasClientCoordinates: (event: unknown) => event is WithClientCoordinates;
|
|
32
|
+
//# sourceMappingURL=coordinates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coordinates.d.ts","sourceRoot":"","sources":["../../src/utils/coordinates.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,4DAA4D;IAC5D,OAAO,EAAE,MAAM,CAAC;IAChB,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,oBAAoB,UACxB,OAAO,KACb,KAAK,IAAI,qBASX,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type guard that checks if an unknown value has client coordinates.
|
|
3
|
+
*
|
|
4
|
+
* This function performs a runtime check to ensure that an object has valid
|
|
5
|
+
* clientX and clientY number properties. It's useful for handling events
|
|
6
|
+
* that may or may not include coordinate information.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const handleEvent = (event: unknown) => {
|
|
11
|
+
* if (hasClientCoordinates(event)) {
|
|
12
|
+
* // TypeScript now knows event has clientX and clientY
|
|
13
|
+
* console.log(event.clientX, event.clientY);
|
|
14
|
+
* }
|
|
15
|
+
* };
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param event - The value to check for client coordinates
|
|
19
|
+
* @returns A type predicate indicating if the value has client coordinates
|
|
20
|
+
*/
|
|
21
|
+
export const hasClientCoordinates = (event) => {
|
|
22
|
+
return (typeof event === 'object' &&
|
|
23
|
+
event !== null &&
|
|
24
|
+
'clientX' in event &&
|
|
25
|
+
'clientY' in event &&
|
|
26
|
+
typeof event.clientX === 'number' &&
|
|
27
|
+
typeof event.clientY === 'number');
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=coordinates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coordinates.js","sourceRoot":"","sources":["../../src/utils/coordinates.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,KAAc,EACkB,EAAE;IAClC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,SAAS,IAAI,KAAK;QAClB,SAAS,IAAI,KAAK;QAClB,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;QACjC,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,CAClC,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sqlrooms/cosmos",
|
|
3
|
+
"version": "0.4.2",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"private": false,
|
|
9
|
+
"author": "Ilya Boyandin <ilya@boyandin.me>",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/sqlrooms/sqlrooms.git"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@cosmograph/cosmos": "2.0.0-beta.22",
|
|
23
|
+
"@sqlrooms/ui": "0.4.2",
|
|
24
|
+
"lucide-react": "^0.474.0",
|
|
25
|
+
"zod": "^3.24.1"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"react": "*",
|
|
29
|
+
"react-dom": "*"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"dev": "tsc -w",
|
|
33
|
+
"build": "tsc",
|
|
34
|
+
"lint": "eslint .",
|
|
35
|
+
"typedoc": "typedoc"
|
|
36
|
+
},
|
|
37
|
+
"gitHead": "c71b75c7c6f391e0760803bcac674b8a59368922"
|
|
38
|
+
}
|