@deck.gl-community/graph-layers 9.1.0-beta.8 → 9.2.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.
Files changed (252) hide show
  1. package/LICENSE +1 -1
  2. package/dist/_deprecated/old-constants.d.ts +107 -0
  3. package/dist/_deprecated/old-constants.d.ts.map +1 -0
  4. package/dist/_deprecated/old-constants.js +111 -0
  5. package/dist/_deprecated/old-constants.js.map +1 -0
  6. package/dist/core/cache.d.ts +0 -1
  7. package/dist/core/cache.js +0 -1
  8. package/dist/core/constants.d.ts +12 -100
  9. package/dist/core/constants.d.ts.map +1 -1
  10. package/dist/core/constants.js +3 -44
  11. package/dist/core/constants.js.map +1 -1
  12. package/dist/core/graph-engine.d.ts +12 -11
  13. package/dist/core/graph-engine.d.ts.map +1 -1
  14. package/dist/core/graph-engine.js +22 -11
  15. package/dist/core/graph-engine.js.map +1 -1
  16. package/dist/core/graph-layout.d.ts +48 -21
  17. package/dist/core/graph-layout.d.ts.map +1 -1
  18. package/dist/core/graph-layout.js +91 -24
  19. package/dist/core/graph-layout.js.map +1 -1
  20. package/dist/core/interaction-manager.d.ts +6 -4
  21. package/dist/core/interaction-manager.d.ts.map +1 -1
  22. package/dist/core/interaction-manager.js +59 -17
  23. package/dist/core/interaction-manager.js.map +1 -1
  24. package/dist/graph/edge.d.ts +7 -7
  25. package/dist/graph/edge.d.ts.map +1 -1
  26. package/dist/graph/edge.js +3 -6
  27. package/dist/graph/edge.js.map +1 -1
  28. package/dist/graph/graph.d.ts +2 -3
  29. package/dist/graph/graph.js +8 -9
  30. package/dist/graph/graph.js.map +1 -1
  31. package/dist/graph/node.d.ts +7 -8
  32. package/dist/graph/node.d.ts.map +1 -1
  33. package/dist/graph/node.js +3 -5
  34. package/dist/graph/node.js.map +1 -1
  35. package/dist/graph-style-schema.cdn.d.ts +2 -0
  36. package/dist/graph-style-schema.cdn.js +2 -0
  37. package/dist/graph-style-schema.json +12 -0
  38. package/dist/index.cjs +2821 -549
  39. package/dist/index.cjs.map +4 -4
  40. package/dist/index.d.ts +28 -22
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +25 -21
  43. package/dist/index.js.map +1 -1
  44. package/dist/layers/common-layers/flow-path-layer/flow-path-layer-fragment.glsl.d.ts +0 -1
  45. package/dist/layers/common-layers/flow-path-layer/flow-path-layer-fragment.glsl.js +0 -1
  46. package/dist/layers/common-layers/flow-path-layer/flow-path-layer-vertex-tf.glsl.d.ts +0 -1
  47. package/dist/layers/common-layers/flow-path-layer/flow-path-layer-vertex-tf.glsl.js +0 -1
  48. package/dist/layers/common-layers/flow-path-layer/flow-path-layer-vertex.glsl.d.ts +0 -1
  49. package/dist/layers/common-layers/flow-path-layer/flow-path-layer-vertex.glsl.js +0 -1
  50. package/dist/layers/common-layers/flow-path-layer/flow-path-layer.d.ts +0 -1
  51. package/dist/layers/common-layers/flow-path-layer/flow-path-layer.js +0 -1
  52. package/dist/layers/common-layers/marker-layer/atlas-data-url.d.ts +0 -1
  53. package/dist/layers/common-layers/marker-layer/atlas-data-url.js +0 -1
  54. package/dist/layers/common-layers/marker-layer/marker-layer.d.ts +0 -1
  55. package/dist/layers/common-layers/marker-layer/marker-layer.js +2 -3
  56. package/dist/layers/common-layers/marker-layer/marker-list.d.ts +2 -63
  57. package/dist/layers/common-layers/marker-layer/marker-list.d.ts.map +1 -1
  58. package/dist/layers/common-layers/marker-layer/marker-list.js +1 -65
  59. package/dist/layers/common-layers/marker-layer/marker-list.js.map +1 -1
  60. package/dist/layers/common-layers/marker-layer/marker-mapping.d.ts +0 -1
  61. package/dist/layers/common-layers/marker-layer/marker-mapping.js +0 -1
  62. package/dist/layers/common-layers/spline-layer/spline-layer.d.ts +0 -1
  63. package/dist/layers/common-layers/spline-layer/spline-layer.js +0 -1
  64. package/dist/layers/common-layers/zoomable-text-layer/zoomable-text-layer.d.ts +0 -1
  65. package/dist/layers/common-layers/zoomable-text-layer/zoomable-text-layer.js +0 -1
  66. package/dist/layers/edge-attachment-helper.d.ts +15 -0
  67. package/dist/layers/edge-attachment-helper.d.ts.map +1 -0
  68. package/dist/layers/edge-attachment-helper.js +230 -0
  69. package/dist/layers/edge-attachment-helper.js.map +1 -0
  70. package/dist/layers/edge-layer.d.ts +1 -5
  71. package/dist/layers/edge-layer.d.ts.map +1 -1
  72. package/dist/layers/edge-layer.js +9 -11
  73. package/dist/layers/edge-layer.js.map +1 -1
  74. package/dist/layers/edge-layers/arrow-2d-geometry.d.ts +4 -0
  75. package/dist/layers/edge-layers/arrow-2d-geometry.d.ts.map +1 -0
  76. package/dist/layers/edge-layers/arrow-2d-geometry.js +42 -0
  77. package/dist/layers/edge-layers/arrow-2d-geometry.js.map +1 -0
  78. package/dist/layers/edge-layers/curved-edge-layer.d.ts +1 -2
  79. package/dist/layers/edge-layers/curved-edge-layer.js +1 -2
  80. package/dist/layers/edge-layers/edge-arrow-layer.d.ts +21 -0
  81. package/dist/layers/edge-layers/edge-arrow-layer.d.ts.map +1 -0
  82. package/dist/layers/edge-layers/edge-arrow-layer.js +131 -0
  83. package/dist/layers/edge-layers/edge-arrow-layer.js.map +1 -0
  84. package/dist/layers/edge-layers/edge-label-layer.d.ts +1 -2
  85. package/dist/layers/edge-layers/edge-label-layer.js +1 -2
  86. package/dist/layers/edge-layers/flow-layer.d.ts +1 -2
  87. package/dist/layers/edge-layers/flow-layer.js +1 -2
  88. package/dist/layers/edge-layers/path-edge-layer.d.ts +0 -1
  89. package/dist/layers/edge-layers/path-edge-layer.js +0 -1
  90. package/dist/layers/edge-layers/straight-line-edge-layer.d.ts +0 -1
  91. package/dist/layers/edge-layers/straight-line-edge-layer.js +0 -1
  92. package/dist/layers/graph-layer.d.ts +22 -23
  93. package/dist/layers/graph-layer.d.ts.map +1 -1
  94. package/dist/layers/graph-layer.js +218 -62
  95. package/dist/layers/graph-layer.js.map +1 -1
  96. package/dist/layers/node-layers/circle-layer.d.ts +0 -1
  97. package/dist/layers/node-layers/circle-layer.js +0 -1
  98. package/dist/layers/node-layers/image-layer.d.ts +0 -1
  99. package/dist/layers/node-layers/image-layer.js +0 -1
  100. package/dist/layers/node-layers/label-layer.d.ts +1 -2
  101. package/dist/layers/node-layers/label-layer.js +1 -2
  102. package/dist/layers/node-layers/path-rounded-rectangle-layer.d.ts +0 -1
  103. package/dist/layers/node-layers/path-rounded-rectangle-layer.js +1 -2
  104. package/dist/layers/node-layers/rectangle-layer.d.ts +0 -1
  105. package/dist/layers/node-layers/rectangle-layer.js +0 -1
  106. package/dist/layers/node-layers/rounded-rectangle-layer-fragment.d.ts +0 -1
  107. package/dist/layers/node-layers/rounded-rectangle-layer-fragment.js +0 -1
  108. package/dist/layers/node-layers/rounded-rectangle-layer.d.ts +1 -2
  109. package/dist/layers/node-layers/rounded-rectangle-layer.js +2 -3
  110. package/dist/layers/node-layers/zoomable-marker-layer.d.ts +1 -2
  111. package/dist/layers/node-layers/zoomable-marker-layer.js +1 -2
  112. package/dist/layouts/d3-dag/d3-dag-layout.d.ts +117 -0
  113. package/dist/layouts/d3-dag/d3-dag-layout.d.ts.map +1 -0
  114. package/dist/layouts/d3-dag/d3-dag-layout.js +716 -0
  115. package/dist/layouts/d3-dag/d3-dag-layout.js.map +1 -0
  116. package/dist/layouts/d3-force/d3-force-layout.d.ts +4 -4
  117. package/dist/layouts/d3-force/d3-force-layout.d.ts.map +1 -1
  118. package/dist/layouts/d3-force/d3-force-layout.js +25 -10
  119. package/dist/layouts/d3-force/d3-force-layout.js.map +1 -1
  120. package/dist/layouts/d3-force/worker.d.ts +0 -1
  121. package/dist/layouts/d3-force/worker.js +0 -1
  122. package/dist/layouts/experimental/force-multi-graph-layout.d.ts +9 -8
  123. package/dist/layouts/experimental/force-multi-graph-layout.d.ts.map +1 -1
  124. package/dist/layouts/experimental/force-multi-graph-layout.js +15 -11
  125. package/dist/layouts/experimental/force-multi-graph-layout.js.map +1 -1
  126. package/dist/layouts/experimental/hive-plot-layout.d.ts +11 -8
  127. package/dist/layouts/experimental/hive-plot-layout.d.ts.map +1 -1
  128. package/dist/layouts/experimental/hive-plot-layout.js +12 -7
  129. package/dist/layouts/experimental/hive-plot-layout.js.map +1 -1
  130. package/dist/layouts/experimental/radial-layout.d.ts +10 -7
  131. package/dist/layouts/experimental/radial-layout.d.ts.map +1 -1
  132. package/dist/layouts/experimental/radial-layout.js +11 -6
  133. package/dist/layouts/experimental/radial-layout.js.map +1 -1
  134. package/dist/layouts/gpu-force/gpu-force-layout.d.ts +4 -4
  135. package/dist/layouts/gpu-force/gpu-force-layout.d.ts.map +1 -1
  136. package/dist/layouts/gpu-force/gpu-force-layout.js +18 -9
  137. package/dist/layouts/gpu-force/gpu-force-layout.js.map +1 -1
  138. package/dist/layouts/gpu-force/worker.d.ts +0 -1
  139. package/dist/layouts/gpu-force/worker.js +0 -1
  140. package/dist/layouts/simple-layout.d.ts +19 -12
  141. package/dist/layouts/simple-layout.d.ts.map +1 -1
  142. package/dist/layouts/simple-layout.js +26 -15
  143. package/dist/layouts/simple-layout.js.map +1 -1
  144. package/dist/loaders/create-graph.d.ts +1 -2
  145. package/dist/loaders/create-graph.js +3 -4
  146. package/dist/loaders/edge-parsers.d.ts +1 -2
  147. package/dist/loaders/edge-parsers.js +2 -3
  148. package/dist/loaders/edge-parsers.js.map +1 -1
  149. package/dist/loaders/json-loader.d.ts +2 -3
  150. package/dist/loaders/json-loader.d.ts.map +1 -1
  151. package/dist/loaders/json-loader.js +5 -6
  152. package/dist/loaders/json-loader.js.map +1 -1
  153. package/dist/loaders/node-parsers.d.ts +1 -2
  154. package/dist/loaders/node-parsers.js +2 -3
  155. package/dist/loaders/node-parsers.js.map +1 -1
  156. package/dist/loaders/simple-json-graph-loader.d.ts +0 -1
  157. package/dist/loaders/simple-json-graph-loader.d.ts.map +1 -1
  158. package/dist/loaders/simple-json-graph-loader.js +5 -6
  159. package/dist/loaders/simple-json-graph-loader.js.map +1 -1
  160. package/dist/loaders/table-graph-loader.d.ts +3 -4
  161. package/dist/loaders/table-graph-loader.js +5 -6
  162. package/dist/loaders/table-graph-loader.js.map +1 -1
  163. package/dist/style/graph-layer-stylesheet.d.ts +34 -0
  164. package/dist/style/graph-layer-stylesheet.d.ts.map +1 -0
  165. package/dist/style/graph-layer-stylesheet.js +39 -0
  166. package/dist/style/graph-layer-stylesheet.js.map +1 -0
  167. package/dist/style/graph-style-accessor-map.d.ts +93 -0
  168. package/dist/style/graph-style-accessor-map.d.ts.map +1 -0
  169. package/dist/style/graph-style-accessor-map.js +93 -0
  170. package/dist/style/graph-style-accessor-map.js.map +1 -0
  171. package/dist/style/graph-style-engine.d.ts +10 -0
  172. package/dist/style/graph-style-engine.d.ts.map +1 -0
  173. package/dist/style/graph-style-engine.js +163 -0
  174. package/dist/style/graph-style-engine.js.map +1 -0
  175. package/dist/style/graph-stylesheet.schema.d.ts +310 -0
  176. package/dist/style/graph-stylesheet.schema.d.ts.map +1 -0
  177. package/dist/style/graph-stylesheet.schema.js +237 -0
  178. package/dist/style/graph-stylesheet.schema.js.map +1 -0
  179. package/dist/style/style-engine.d.ts +33 -0
  180. package/dist/style/style-engine.d.ts.map +1 -0
  181. package/dist/style/style-engine.js +121 -0
  182. package/dist/style/style-engine.js.map +1 -0
  183. package/dist/style/style-property.d.ts +2 -3
  184. package/dist/style/style-property.d.ts.map +1 -1
  185. package/dist/style/style-property.js +224 -48
  186. package/dist/style/style-property.js.map +1 -1
  187. package/dist/utils/collapsed-chains.d.ts +17 -0
  188. package/dist/utils/collapsed-chains.d.ts.map +1 -0
  189. package/dist/utils/collapsed-chains.js +197 -0
  190. package/dist/utils/collapsed-chains.js.map +1 -0
  191. package/dist/utils/layer-utils.d.ts +0 -1
  192. package/dist/utils/layer-utils.d.ts.map +1 -1
  193. package/dist/utils/layer-utils.js +0 -1
  194. package/dist/utils/log.d.ts +2 -1
  195. package/dist/utils/log.d.ts.map +1 -1
  196. package/dist/utils/log.js +12 -2
  197. package/dist/utils/log.js.map +1 -1
  198. package/dist/utils/node-boundary.d.ts +10 -0
  199. package/dist/utils/node-boundary.d.ts.map +1 -0
  200. package/dist/utils/node-boundary.js +130 -0
  201. package/dist/utils/node-boundary.js.map +1 -0
  202. package/dist/utils/polygon-calculations.d.ts +0 -1
  203. package/dist/utils/polygon-calculations.js +0 -1
  204. package/dist/widgets/long-press-button.d.ts +0 -1
  205. package/dist/widgets/long-press-button.js +0 -1
  206. package/dist/widgets/view-control-widget.d.ts +4 -5
  207. package/dist/widgets/view-control-widget.d.ts.map +1 -1
  208. package/dist/widgets/view-control-widget.js +10 -8
  209. package/dist/widgets/view-control-widget.js.map +1 -1
  210. package/package.json +23 -7
  211. package/src/_deprecated/old-constants.ts +122 -0
  212. package/src/core/constants.ts +21 -43
  213. package/src/core/graph-engine.ts +24 -9
  214. package/src/core/graph-layout.ts +133 -28
  215. package/src/core/interaction-manager.ts +80 -20
  216. package/src/graph/edge.ts +6 -6
  217. package/src/graph/graph.ts +7 -7
  218. package/src/graph/node.ts +6 -6
  219. package/src/index.ts +31 -6
  220. package/src/layers/common-layers/marker-layer/marker-list.ts +62 -64
  221. package/src/layers/edge-attachment-helper.ts +355 -0
  222. package/src/layers/edge-layer.ts +6 -7
  223. package/src/layers/edge-layers/arrow-2d-geometry.ts +51 -0
  224. package/src/layers/edge-layers/edge-arrow-layer.ts +171 -0
  225. package/src/layers/graph-layer.ts +304 -86
  226. package/src/layouts/d3-dag/d3-dag-layout.ts +969 -0
  227. package/src/layouts/d3-force/d3-force-layout.ts +33 -11
  228. package/src/layouts/experimental/force-multi-graph-layout.ts +22 -13
  229. package/src/layouts/experimental/hive-plot-layout.ts +22 -10
  230. package/src/layouts/experimental/radial-layout.ts +20 -8
  231. package/src/layouts/gpu-force/gpu-force-layout.ts +22 -10
  232. package/src/layouts/simple-layout.ts +48 -25
  233. package/src/loaders/edge-parsers.ts +2 -2
  234. package/src/loaders/json-loader.ts +2 -2
  235. package/src/loaders/node-parsers.ts +2 -2
  236. package/src/loaders/simple-json-graph-loader.ts +2 -2
  237. package/src/loaders/table-graph-loader.ts +2 -2
  238. package/src/style/graph-layer-stylesheet.ts +99 -0
  239. package/src/style/graph-style-accessor-map.ts +103 -0
  240. package/src/style/graph-style-engine.ts +229 -0
  241. package/src/style/graph-stylesheet.schema.ts +344 -0
  242. package/src/style/style-engine.ts +168 -0
  243. package/src/style/style-property.ts +314 -51
  244. package/src/utils/collapsed-chains.ts +261 -0
  245. package/src/utils/log.ts +15 -1
  246. package/src/utils/node-boundary.ts +238 -0
  247. package/src/widgets/view-control-widget.tsx +15 -13
  248. package/dist/style/style-sheet.d.ts +0 -11
  249. package/dist/style/style-sheet.d.ts.map +0 -1
  250. package/dist/style/style-sheet.js +0 -253
  251. package/dist/style/style-sheet.js.map +0 -1
  252. package/src/style/style-sheet.ts +0 -277
@@ -0,0 +1,99 @@
1
+ // deck.gl-community
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {GraphStylesheet, GraphStyleType} from './graph-style-engine';
6
+
7
+ export type GraphNodeStyleType = Exclude<
8
+ GraphStyleType,
9
+ 'Edge' | 'edge' | 'edge-label' | 'flow' | 'arrow'
10
+ >;
11
+
12
+ export type GraphEdgeDecoratorType = Extract<GraphStyleType, 'edge-label' | 'flow' | 'arrow'>;
13
+
14
+ export type GraphLayerNodeStyle = GraphStylesheet<GraphNodeStyleType> & {
15
+ pickable?: boolean;
16
+ visible?: boolean;
17
+ data?: (nodes: any[]) => any;
18
+ };
19
+
20
+ export type GraphLayerEdgeDecoratorStyle = GraphStylesheet<GraphEdgeDecoratorType>;
21
+
22
+ type EdgeStyleType = Extract<GraphStyleType, 'Edge' | 'edge'>;
23
+
24
+ export type GraphLayerEdgeStyle = (
25
+ | GraphStylesheet<EdgeStyleType>
26
+ | (Omit<GraphStylesheet<EdgeStyleType>, 'type'> & {type?: EdgeStyleType})
27
+ ) & {
28
+ decorators?: GraphLayerEdgeDecoratorStyle[];
29
+ data?: (edges: any[]) => any;
30
+ visible?: boolean;
31
+ };
32
+
33
+ export type GraphLayerStylesheet = {
34
+ nodes?: GraphLayerNodeStyle[];
35
+ edges?: GraphLayerEdgeStyle | GraphLayerEdgeStyle[];
36
+ };
37
+
38
+ export type GraphLayerStylesheetInput = GraphLayerStylesheet | null | undefined;
39
+
40
+ export type NormalizedGraphLayerStylesheet = {
41
+ nodes: GraphLayerNodeStyle[];
42
+ edges: GraphLayerEdgeStyle[];
43
+ };
44
+
45
+ const DEFAULT_EDGE_STYLE: GraphLayerEdgeStyle = {
46
+ type: 'edge',
47
+ stroke: 'black',
48
+ strokeWidth: 1,
49
+ decorators: []
50
+ };
51
+
52
+ export const DEFAULT_GRAPH_LAYER_STYLESHEET: NormalizedGraphLayerStylesheet = {
53
+ nodes: [],
54
+ edges: [DEFAULT_EDGE_STYLE]
55
+ };
56
+
57
+ export type GraphLayerStylesheetSources = {
58
+ stylesheet?: GraphLayerStylesheetInput;
59
+ nodeStyle?: GraphLayerNodeStyle[];
60
+ edgeStyle?: GraphLayerEdgeStyle | GraphLayerEdgeStyle[];
61
+ };
62
+
63
+ export function normalizeGraphLayerStylesheet({
64
+ stylesheet,
65
+ nodeStyle,
66
+ edgeStyle
67
+ }: GraphLayerStylesheetSources): NormalizedGraphLayerStylesheet {
68
+ const resolvedStylesheet = stylesheet ?? {};
69
+ const resolvedNodeStyles = Array.isArray(resolvedStylesheet.nodes)
70
+ ? resolvedStylesheet.nodes
71
+ : nodeStyle;
72
+
73
+ const resolvedEdgeStyles = resolvedStylesheet.edges ?? edgeStyle;
74
+
75
+ const nodes = Array.isArray(resolvedNodeStyles)
76
+ ? resolvedNodeStyles.filter(Boolean)
77
+ : [...DEFAULT_GRAPH_LAYER_STYLESHEET.nodes];
78
+
79
+ const edgeEntries = Array.isArray(resolvedEdgeStyles)
80
+ ? resolvedEdgeStyles
81
+ : resolvedEdgeStyles
82
+ ? [resolvedEdgeStyles]
83
+ : DEFAULT_GRAPH_LAYER_STYLESHEET.edges;
84
+
85
+ const edges: GraphLayerEdgeStyle[] = (edgeEntries)
86
+ .filter(Boolean)
87
+ .map((edgeStyleEntry) => ({
88
+ ...edgeStyleEntry,
89
+ type: ((edgeStyleEntry).type ?? 'edge'),
90
+ decorators: (edgeStyleEntry).decorators ?? []
91
+ })) as GraphLayerEdgeStyle[];
92
+
93
+ return {
94
+ nodes,
95
+ edges
96
+ };
97
+ }
98
+
99
+ export type {GraphStyleValue, GraphStylesheet, GraphStyleType} from './graph-style-engine';
@@ -0,0 +1,103 @@
1
+ // deck.gl-community
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ const COMMON_DECKGL_PROPS = {
6
+ getOffset: 'offset',
7
+ opacity: 'opacity'
8
+ } as const;
9
+
10
+ export const GRAPH_DECKGL_ACCESSOR_MAP = {
11
+ circle: {
12
+ ...COMMON_DECKGL_PROPS,
13
+ getFillColor: 'fill',
14
+ getLineColor: 'stroke',
15
+ getLineWidth: 'strokeWidth',
16
+ getRadius: 'radius'
17
+ },
18
+
19
+ rectangle: {
20
+ ...COMMON_DECKGL_PROPS,
21
+ getWidth: 'width',
22
+ getHeight: 'height',
23
+ getFillColor: 'fill',
24
+ getLineColor: 'stroke',
25
+ getLineWidth: 'strokeWidth'
26
+ },
27
+
28
+ 'rounded-rectangle': {
29
+ ...COMMON_DECKGL_PROPS,
30
+ getCornerRadius: 'cornerRadius',
31
+ getRadius: 'radius',
32
+ getWidth: 'width',
33
+ getHeight: 'height',
34
+ getFillColor: 'fill',
35
+ getLineColor: 'stroke',
36
+ getLineWidth: 'strokeWidth'
37
+ },
38
+
39
+ 'path-rounded-rectangle': {
40
+ ...COMMON_DECKGL_PROPS,
41
+ getWidth: 'width',
42
+ getHeight: 'height',
43
+ getFillColor: 'fill',
44
+ getLineColor: 'stroke',
45
+ getLineWidth: 'strokeWidth',
46
+ getCornerRadius: 'cornerRadius'
47
+ },
48
+
49
+ label: {
50
+ ...COMMON_DECKGL_PROPS,
51
+ getColor: 'color',
52
+ getText: 'text',
53
+ getSize: 'fontSize',
54
+ getTextAnchor: 'textAnchor',
55
+ getAlignmentBaseline: 'alignmentBaseline',
56
+ getAngle: 'angle',
57
+ scaleWithZoom: 'scaleWithZoom',
58
+ textMaxWidth: 'textMaxWidth',
59
+ textWordBreak: 'textWordBreak',
60
+ textSizeMinPixels: 'textSizeMinPixels'
61
+ },
62
+
63
+ marker: {
64
+ ...COMMON_DECKGL_PROPS,
65
+ getColor: 'fill',
66
+ getSize: 'size',
67
+ getMarker: 'marker',
68
+ scaleWithZoom: 'scaleWithZoom'
69
+ },
70
+
71
+ Edge: {
72
+ getColor: 'stroke',
73
+ getWidth: 'strokeWidth'
74
+ },
75
+ edge: {
76
+ getColor: 'stroke',
77
+ getWidth: 'strokeWidth'
78
+ },
79
+ 'edge-label': {
80
+ getColor: 'color',
81
+ getText: 'text',
82
+ getSize: 'fontSize',
83
+ getTextAnchor: 'textAnchor',
84
+ getAlignmentBaseline: 'alignmentBaseline',
85
+ scaleWithZoom: 'scaleWithZoom',
86
+ textMaxWidth: 'textMaxWidth',
87
+ textWordBreak: 'textWordBreak',
88
+ textSizeMinPixels: 'textSizeMinPixels'
89
+ },
90
+ flow: {
91
+ getColor: 'color',
92
+ getWidth: 'width',
93
+ getSpeed: 'speed',
94
+ getTailLength: 'tailLength'
95
+ },
96
+ arrow: {
97
+ getColor: 'color',
98
+ getSize: 'size',
99
+ getOffset: 'offset'
100
+ }
101
+ } as const;
102
+
103
+ export type GraphDeckGLAccessorMap = typeof GRAPH_DECKGL_ACCESSOR_MAP;
@@ -0,0 +1,229 @@
1
+ // deck.gl-community
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ /* eslint-disable no-continue */
6
+
7
+ import {ZodError, type ZodIssue} from 'zod';
8
+
9
+ import {StyleEngine, type DeckGLUpdateTriggers} from './style-engine';
10
+ import {
11
+ GraphStylesheetSchema,
12
+ type GraphStylesheet,
13
+ type GraphStylesheetParsed
14
+ } from './graph-stylesheet.schema';
15
+ import {GRAPH_DECKGL_ACCESSOR_MAP} from './graph-style-accessor-map';
16
+ import {warn} from '../utils/log';
17
+
18
+ const GRAPH_DECKGL_UPDATE_TRIGGERS: DeckGLUpdateTriggers = {
19
+ circle: ['getFillColor', 'getRadius', 'getLineColor', 'getLineWidth'],
20
+ rectangle: ['getFillColor', 'getLineColor', 'getLineWidth'],
21
+ 'rounded-rectangle': ['getFillColor', 'getLineColor', 'getLineWidth', 'getCornerRadius'],
22
+ 'path-rounded-rectangle': ['getFillColor', 'getLineColor', 'getLineWidth', 'getCornerRadius'],
23
+ label: ['getColor', 'getText', 'getSize', 'getTextAnchor', 'getAlignmentBaseline', 'getAngle'],
24
+ marker: ['getColor', 'getSize', 'getMarker'],
25
+ Edge: ['getColor', 'getWidth'],
26
+ edge: ['getColor', 'getWidth'],
27
+ 'edge-label': ['getColor', 'getText', 'getSize', 'getTextAnchor', 'getAlignmentBaseline'],
28
+ flow: ['getColor', 'getWidth', 'getSpeed', 'getTailLength'],
29
+ arrow: ['getColor', 'getSize', 'getOffset']
30
+ };
31
+
32
+ function formatStylesheetError(error: ZodError) {
33
+ const details = error.issues
34
+ .map((issue) => {
35
+ const path = issue.path.length ? issue.path.join('.') : 'root';
36
+ return ` • ${path}: ${issue.message}`;
37
+ })
38
+ .join('\n');
39
+ return `Invalid graph stylesheet:\n${details}`;
40
+ }
41
+
42
+ export class GraphStyleEngine extends StyleEngine {
43
+ constructor(style: GraphStylesheet, {stateUpdateTrigger}: {stateUpdateTrigger?: unknown} = {}) {
44
+ const result = GraphStylesheetSchema.safeParse(style);
45
+ const parsedStyle = result.success
46
+ ? result.data
47
+ : sanitizeStylesheet(style, result.error.issues);
48
+
49
+ super(parsedStyle as GraphStylesheet, {
50
+ deckglAccessorMap: GRAPH_DECKGL_ACCESSOR_MAP,
51
+ deckglUpdateTriggers: GRAPH_DECKGL_UPDATE_TRIGGERS,
52
+ stateUpdateTrigger
53
+ });
54
+ }
55
+ }
56
+
57
+ export {
58
+ GraphStyleScaleTypeEnum,
59
+ GraphStyleScaleSchema,
60
+ GraphStyleAttributeReferenceSchema,
61
+ GraphStyleLeafValueSchema,
62
+ GraphStyleStateMapSchema,
63
+ GraphStyleValueSchema,
64
+ GraphStylesheetSchema
65
+ } from './graph-stylesheet.schema';
66
+
67
+ export type {
68
+ GraphStylesheet,
69
+ GraphStylesheetInput,
70
+ GraphStylesheetParsed,
71
+ GraphStyleSelector,
72
+ GraphStyleType,
73
+ GraphStyleAttributeReference,
74
+ GraphStyleLeafValue,
75
+ GraphStyleScale,
76
+ GraphStyleScaleType,
77
+ GraphStyleValue
78
+ } from './graph-stylesheet.schema';
79
+
80
+ export {GRAPH_DECKGL_ACCESSOR_MAP} from './graph-style-accessor-map';
81
+
82
+ // eslint-disable-next-line max-statements, complexity
83
+ function sanitizeStylesheet(style: GraphStylesheet, issues: ZodIssue[]): GraphStylesheetParsed {
84
+ if (issues.length) {
85
+ const details = issues
86
+ .map((issue) => {
87
+ const path = issue.path.length ? issue.path.join('.') : 'root';
88
+ return `${path}: ${issue.message}`;
89
+ })
90
+ .join('\n • ');
91
+ warn(`GraphStyleEngine: stylesheet issues detected:\n • ${details}`);
92
+ }
93
+
94
+ const fallbackTypeCandidate =
95
+ typeof (style as {type?: unknown}).type === 'string' ? (style as {type: string}).type : undefined;
96
+ const fallbackCandidates = Array.from(
97
+ new Set(
98
+ [fallbackTypeCandidate, 'edge'].filter(
99
+ (value): value is string => typeof value === 'string' && value.length > 0
100
+ )
101
+ )
102
+ );
103
+
104
+ for (const candidate of fallbackCandidates) {
105
+ const sanitized = cloneValue(style) as Record<string, unknown>;
106
+ sanitized.type = candidate;
107
+
108
+ for (const issue of issues) {
109
+ if (!Array.isArray(issue.path) || issue.path.length === 0) {
110
+ continue;
111
+ }
112
+
113
+ const path = issue.path.filter(
114
+ (segment): segment is string | number =>
115
+ typeof segment === 'string' || typeof segment === 'number'
116
+ );
117
+
118
+ if (path.length === 0) {
119
+ continue;
120
+ }
121
+
122
+ const [rootKey] = path;
123
+ if (rootKey === undefined || rootKey === 'type') {
124
+ continue;
125
+ }
126
+
127
+ if (typeof rootKey === 'string' && rootKey.startsWith(':')) {
128
+ removeNestedProperty(sanitized, path);
129
+ continue;
130
+ }
131
+
132
+ if (typeof rootKey !== 'string') {
133
+ continue;
134
+ }
135
+
136
+ delete sanitized[rootKey];
137
+ }
138
+
139
+ const result = GraphStylesheetSchema.safeParse(sanitized);
140
+ if (result.success) {
141
+ return result.data;
142
+ }
143
+ }
144
+
145
+ // If every fallback failed, rethrow the detailed error so callers know parsing was impossible.
146
+ throw new Error(formatStylesheetError(new ZodError(issues)));
147
+ }
148
+
149
+ function cloneValue<T>(value: T): T {
150
+ if (Array.isArray(value)) {
151
+ return value.map((item) => cloneValue(item)) as unknown as T;
152
+ }
153
+ if (value && typeof value === 'object') {
154
+ if (value instanceof Date) {
155
+ return new Date(value) as unknown as T;
156
+ }
157
+ if (value instanceof RegExp) {
158
+ return new RegExp(value.source, value.flags) as unknown as T;
159
+ }
160
+ const cloned: Record<string, unknown> = {};
161
+ for (const [key, entryValue] of Object.entries(value as Record<string, unknown>)) {
162
+ cloned[key] = cloneValue(entryValue);
163
+ }
164
+ return cloned as unknown as T;
165
+ }
166
+ return value;
167
+ }
168
+
169
+ // eslint-disable-next-line max-statements, complexity
170
+ function removeNestedProperty(target: Record<string, unknown> | unknown[], path: (string | number)[]) {
171
+ if (path.length === 0) {
172
+ return;
173
+ }
174
+
175
+ const [head, ...rest] = path;
176
+ if (head === undefined) {
177
+ return;
178
+ }
179
+
180
+ if (Array.isArray(target)) {
181
+ const index = typeof head === 'number' ? head : Number(head);
182
+ if (!Number.isInteger(index) || index < 0 || index >= target.length) {
183
+ return;
184
+ }
185
+ if (rest.length === 0) {
186
+ target.splice(index, 1);
187
+ return;
188
+ }
189
+ const child = target[index];
190
+ if (!child || typeof child !== 'object') {
191
+ target.splice(index, 1);
192
+ return;
193
+ }
194
+ removeNestedProperty(child as Record<string, unknown> | unknown[], rest);
195
+ if (isEmptyObject(child)) {
196
+ target.splice(index, 1);
197
+ }
198
+ return;
199
+ }
200
+
201
+ const recordTarget = target;
202
+
203
+ if (rest.length === 0) {
204
+ delete recordTarget[head as keyof typeof recordTarget];
205
+ return;
206
+ }
207
+
208
+ const child = recordTarget[head as keyof typeof recordTarget];
209
+ if (!child || typeof child !== 'object') {
210
+ delete recordTarget[head as keyof typeof recordTarget];
211
+ return;
212
+ }
213
+
214
+ removeNestedProperty(child as Record<string, unknown> | unknown[], rest);
215
+
216
+ if (isEmptyObject(child)) {
217
+ delete recordTarget[head as keyof typeof recordTarget];
218
+ }
219
+ }
220
+
221
+ function isEmptyObject(value: unknown): boolean {
222
+ if (Array.isArray(value)) {
223
+ return value.length === 0;
224
+ }
225
+ if (!value || typeof value !== 'object') {
226
+ return false;
227
+ }
228
+ return Object.keys(value as Record<string, unknown>).length === 0;
229
+ }