layerchart 2.0.0-next.43 → 2.0.0-next.45

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 (179) hide show
  1. package/LICENSE +1 -1
  2. package/dist/components/AnnotationLine.svelte +1 -1
  3. package/dist/components/AnnotationPoint.svelte +1 -1
  4. package/dist/components/AnnotationRange.svelte +16 -15
  5. package/dist/components/Arc.svelte +10 -10
  6. package/dist/components/Arc.svelte.d.ts +4 -4
  7. package/dist/components/Arc.svelte.test.d.ts +1 -0
  8. package/dist/components/Arc.svelte.test.js +868 -0
  9. package/dist/components/Area.svelte +9 -7
  10. package/dist/components/Axis.svelte +2 -1
  11. package/dist/components/Axis.svelte.d.ts +1 -0
  12. package/dist/components/Bar.svelte +3 -3
  13. package/dist/components/Bars.svelte +1 -1
  14. package/dist/components/Blur.svelte +3 -3
  15. package/dist/components/Bounds.svelte +1 -1
  16. package/dist/components/BrushContext.svelte +1 -1
  17. package/dist/components/Calendar.svelte +2 -2
  18. package/dist/components/Calendar.svelte.d.ts +1 -1
  19. package/dist/components/Chart.svelte +63 -137
  20. package/dist/components/Chart.svelte.d.ts +23 -88
  21. package/dist/components/ChartClipPath.svelte +1 -1
  22. package/dist/components/Circle.svelte +17 -8
  23. package/dist/components/Circle.svelte.d.ts +3 -0
  24. package/dist/components/ClipPath.svelte +4 -4
  25. package/dist/components/Connector.svelte +4 -4
  26. package/dist/components/Connector.svelte.d.ts +3 -3
  27. package/dist/components/Ellipse.svelte +7 -7
  28. package/dist/components/Frame.svelte +1 -1
  29. package/dist/components/GeoContext.svelte +4 -20
  30. package/dist/components/GeoContext.svelte.d.ts +2 -6
  31. package/dist/components/GeoEdgeFade.svelte +1 -1
  32. package/dist/components/GeoPath.svelte +42 -107
  33. package/dist/components/GeoPath.svelte.d.ts +5 -4
  34. package/dist/components/GeoPoint.svelte +5 -5
  35. package/dist/components/GeoSpline.svelte +2 -14
  36. package/dist/components/GeoSpline.svelte.d.ts +1 -1
  37. package/dist/components/GeoTile.svelte +7 -6
  38. package/dist/components/GeoVisible.svelte +1 -1
  39. package/dist/components/Graticule.svelte +4 -7
  40. package/dist/components/Graticule.svelte.d.ts +2 -1
  41. package/dist/components/Grid.svelte +1 -1
  42. package/dist/components/Group.svelte +8 -8
  43. package/dist/components/Highlight.svelte +18 -16
  44. package/dist/components/Hull.svelte +2 -2
  45. package/dist/components/Labels.svelte +1 -1
  46. package/dist/components/Legend.svelte +1 -1
  47. package/dist/components/Line.svelte +9 -7
  48. package/dist/components/LinearGradient.svelte +8 -7
  49. package/dist/components/MonthPath.svelte +5 -11
  50. package/dist/components/MonthPath.svelte.d.ts +2 -2
  51. package/dist/components/Pack.svelte +4 -6
  52. package/dist/components/Pack.svelte.d.ts +2 -4
  53. package/dist/components/Partition.svelte +4 -3
  54. package/dist/components/Partition.svelte.d.ts +2 -1
  55. package/dist/components/Path.svelte +344 -0
  56. package/dist/components/Path.svelte.d.ts +72 -0
  57. package/dist/components/Pattern.svelte +6 -6
  58. package/dist/components/Pie.svelte +2 -2
  59. package/dist/components/Pie.svelte.d.ts +1 -1
  60. package/dist/components/Point.svelte +1 -1
  61. package/dist/components/Points.svelte +1 -1
  62. package/dist/components/Polygon.svelte +8 -6
  63. package/dist/components/RadialGradient.svelte +7 -7
  64. package/dist/components/Rect.svelte +32 -10
  65. package/dist/components/Rect.svelte.d.ts +4 -1
  66. package/dist/components/Rule.svelte +1 -1
  67. package/dist/components/Sankey.svelte +1 -1
  68. package/dist/components/Spline.svelte +13 -337
  69. package/dist/components/Spline.svelte.d.ts +10 -73
  70. package/dist/components/Text.svelte +9 -7
  71. package/dist/components/Threshold.svelte +3 -3
  72. package/dist/components/TransformContext.svelte +10 -143
  73. package/dist/components/TransformControls.svelte +2 -2
  74. package/dist/components/TransformControls.svelte.d.ts +1 -1
  75. package/dist/components/Tree.svelte +4 -3
  76. package/dist/components/Tree.svelte.d.ts +2 -1
  77. package/dist/components/Treemap.svelte +4 -3
  78. package/dist/components/Treemap.svelte.d.ts +2 -1
  79. package/dist/components/Voronoi.svelte +5 -5
  80. package/dist/components/charts/ArcChart.svelte +14 -6
  81. package/dist/components/charts/ArcChart.svelte.d.ts +1 -1
  82. package/dist/components/charts/AreaChart.svelte +12 -6
  83. package/dist/components/charts/BarChart.svelte +12 -6
  84. package/dist/components/charts/DefaultTooltip.svelte +1 -1
  85. package/dist/components/charts/LineChart.svelte +12 -6
  86. package/dist/components/charts/PieChart.svelte +14 -6
  87. package/dist/components/charts/PieChart.svelte.d.ts +1 -1
  88. package/dist/components/charts/ScatterChart.svelte +11 -9
  89. package/dist/components/charts/types.d.ts +7 -6
  90. package/dist/components/index.d.ts +14 -12
  91. package/dist/components/index.js +14 -12
  92. package/dist/components/{layout → layers}/Canvas.svelte +13 -60
  93. package/dist/components/{layout → layers}/Canvas.svelte.d.ts +2 -32
  94. package/dist/components/{layout → layers}/Html.svelte +18 -3
  95. package/dist/components/{layout → layers}/Html.svelte.d.ts +7 -0
  96. package/dist/components/layers/Layer.svelte +85 -0
  97. package/dist/components/{layout → layers}/Layer.svelte.d.ts +7 -3
  98. package/dist/components/{layout → layers}/Svg.svelte +18 -3
  99. package/dist/components/{layout → layers}/Svg.svelte.d.ts +7 -0
  100. package/dist/components/{layout → layers}/WebGL.svelte +1 -1
  101. package/dist/components/{layout → layers}/WebGL.svelte.d.ts +3 -3
  102. package/dist/components/tests/TestHarness.svelte +76 -0
  103. package/dist/components/tests/TestHarness.svelte.d.ts +19 -0
  104. package/dist/components/tooltip/Tooltip.svelte +3 -3
  105. package/dist/components/tooltip/Tooltip.svelte.d.ts +1 -1
  106. package/dist/components/tooltip/TooltipContext.svelte +13 -45
  107. package/dist/components/tooltip/TooltipContext.svelte.d.ts +2 -14
  108. package/dist/components/tooltip/tooltipMetaContext.d.ts +2 -2
  109. package/dist/components/tooltip/tooltipMetaContext.js +2 -2
  110. package/dist/contexts/canvas.d.ts +33 -0
  111. package/dist/contexts/canvas.js +14 -0
  112. package/dist/contexts/chart.d.ts +84 -0
  113. package/dist/contexts/chart.js +10 -0
  114. package/dist/contexts/geo.d.ts +6 -0
  115. package/dist/contexts/geo.js +12 -0
  116. package/dist/contexts/index.d.ts +6 -0
  117. package/dist/contexts/index.js +6 -0
  118. package/dist/contexts/layer.d.ts +3 -0
  119. package/dist/contexts/layer.js +8 -0
  120. package/dist/contexts/settings.d.ts +4 -0
  121. package/dist/contexts/settings.js +10 -0
  122. package/dist/contexts/tooltip.d.ts +15 -0
  123. package/dist/contexts/tooltip.js +8 -0
  124. package/dist/contexts/transform.d.ts +95 -0
  125. package/dist/contexts/transform.js +10 -0
  126. package/dist/index.d.ts +1 -0
  127. package/dist/index.js +1 -0
  128. package/dist/states/settings.svelte.d.ts +12 -0
  129. package/dist/states/settings.svelte.js +10 -0
  130. package/dist/states/transform.svelte.d.ts +9 -0
  131. package/dist/states/transform.svelte.js +31 -0
  132. package/dist/styles/skeleton-4.css +15 -0
  133. package/dist/utils/arcText.svelte.d.ts +1 -1
  134. package/dist/utils/canvas.d.ts +7 -3
  135. package/dist/utils/canvas.js +78 -11
  136. package/dist/utils/color.js +11 -8
  137. package/dist/utils/common.d.ts +8 -1
  138. package/dist/utils/common.js +9 -10
  139. package/dist/utils/index.d.ts +2 -0
  140. package/dist/utils/index.js +2 -0
  141. package/dist/utils/motion.svelte.js +0 -1
  142. package/dist/utils/rect.svelte.d.ts +1 -1
  143. package/dist/utils/rect.svelte.js +17 -9
  144. package/dist/utils/string.d.ts +3 -1
  145. package/package.json +32 -54
  146. package/README.md +0 -41
  147. package/dist/components/layout/Layer.svelte +0 -41
  148. package/dist/docs/Blockquote.svelte +0 -17
  149. package/dist/docs/Blockquote.svelte.d.ts +0 -5
  150. package/dist/docs/Code.svelte +0 -80
  151. package/dist/docs/Code.svelte.d.ts +0 -14
  152. package/dist/docs/ConnectorSweepMenuField.svelte +0 -17
  153. package/dist/docs/ConnectorSweepMenuField.svelte.d.ts +0 -7
  154. package/dist/docs/ConnectorTypeMenuField.svelte +0 -17
  155. package/dist/docs/ConnectorTypeMenuField.svelte.d.ts +0 -7
  156. package/dist/docs/CurveMenuField.svelte +0 -44
  157. package/dist/docs/CurveMenuField.svelte.d.ts +0 -9
  158. package/dist/docs/GeoDebug.svelte +0 -60
  159. package/dist/docs/GeoDebug.svelte.d.ts +0 -4
  160. package/dist/docs/Header1.svelte +0 -16
  161. package/dist/docs/Header1.svelte.d.ts +0 -5
  162. package/dist/docs/Json.svelte +0 -36
  163. package/dist/docs/Json.svelte.d.ts +0 -10
  164. package/dist/docs/Layout.svelte +0 -21
  165. package/dist/docs/Layout.svelte.d.ts +0 -8
  166. package/dist/docs/Link.svelte +0 -9
  167. package/dist/docs/Link.svelte.d.ts +0 -5
  168. package/dist/docs/PathDataMenuField.svelte +0 -78
  169. package/dist/docs/PathDataMenuField.svelte.d.ts +0 -9
  170. package/dist/docs/Preview.svelte +0 -104
  171. package/dist/docs/Preview.svelte.d.ts +0 -13
  172. package/dist/docs/TilesetField.svelte +0 -136
  173. package/dist/docs/TilesetField.svelte.d.ts +0 -6
  174. package/dist/docs/TransformDebug.svelte +0 -22
  175. package/dist/docs/TransformDebug.svelte.d.ts +0 -20
  176. package/dist/docs/ViewSourceButton.svelte +0 -53
  177. package/dist/docs/ViewSourceButton.svelte.d.ts +0 -11
  178. /package/dist/{utils → contexts}/legendPayload.d.ts +0 -0
  179. /package/dist/{utils → contexts}/legendPayload.js +0 -0
@@ -1,4 +1,5 @@
1
1
  <script lang="ts" module>
2
+ import type { Snippet } from 'svelte';
2
3
  import type { CommonStyleProps, Without } from '../utils/types.js';
3
4
 
4
5
  export type CirclePropsWithoutHTML = {
@@ -52,6 +53,9 @@
52
53
  ref?: SVGCircleElement;
53
54
 
54
55
  motion?: MotionProp;
56
+
57
+ /** Children content to render. Note: Only works for Html layers */
58
+ children?: Snippet;
55
59
  } & CommonStyleProps;
56
60
 
57
61
  export type CircleProps = CirclePropsWithoutHTML &
@@ -60,11 +64,11 @@
60
64
 
61
65
  <script lang="ts">
62
66
  import { cls } from '@layerstack/tailwind';
63
- import { merge } from 'lodash-es';
67
+ import { merge } from '@layerstack/utils';
64
68
 
65
- import { getRenderContext } from './Chart.svelte';
69
+ import { getLayerContext } from '../contexts/layer.js';
66
70
  import { createMotion, type MotionProp } from '../utils/motion.svelte.js';
67
- import { registerCanvasComponent } from './layout/Canvas.svelte';
71
+ import { registerCanvasComponent } from './layers/Canvas.svelte';
68
72
  import { renderCircle, type ComputedStylesOptions } from '../utils/canvas.js';
69
73
  import type { SVGAttributes } from 'svelte/elements';
70
74
  import { createKey } from '../utils/key.svelte.js';
@@ -84,6 +88,7 @@
84
88
  opacity,
85
89
  class: className,
86
90
  ref: refProp = $bindable(),
91
+ children,
87
92
  ...restProps
88
93
  }: CircleProps = $props();
89
94
 
@@ -97,7 +102,7 @@
97
102
  const initialCy = initialCyProp ?? cy;
98
103
  const initialR = initialRProp ?? r;
99
104
 
100
- const renderCtx = getRenderContext();
105
+ const layerCtx = getLayerContext();
101
106
 
102
107
  const motionCx = createMotion(initialCx, () => cx, motion);
103
108
  const motionCy = createMotion(initialCy, () => cy, motion);
@@ -115,6 +120,7 @@
115
120
  : {
116
121
  styles: { fill, fillOpacity, stroke, strokeWidth, opacity },
117
122
  classes: cls('lc-circle', className),
123
+ style: restProps.style as string | undefined,
118
124
  }
119
125
  );
120
126
  }
@@ -123,7 +129,7 @@
123
129
  const fillKey = createKey(() => fill);
124
130
  const strokeKey = createKey(() => stroke);
125
131
 
126
- if (renderCtx === 'canvas') {
132
+ if (layerCtx === 'canvas') {
127
133
  registerCanvasComponent({
128
134
  name: 'Circle',
129
135
  render,
@@ -144,12 +150,13 @@
144
150
  strokeWidth,
145
151
  opacity,
146
152
  className,
153
+ restProps.style,
147
154
  ],
148
155
  });
149
156
  }
150
157
  </script>
151
158
 
152
- {#if renderCtx === 'svg'}
159
+ {#if layerCtx === 'svg'}
153
160
  <circle
154
161
  bind:this={ref}
155
162
  cx={motionCx.current}
@@ -163,7 +170,7 @@
163
170
  class={cls('lc-circle', className)}
164
171
  {...restProps}
165
172
  />
166
- {:else if renderCtx === 'html'}
173
+ {:else if layerCtx === 'html'}
167
174
  <div
168
175
  style:position="absolute"
169
176
  style:left="{motionCx.current}px"
@@ -179,7 +186,9 @@
179
186
  style:transform="translate(-50%, -50%)"
180
187
  class={cls('lc-circle', className)}
181
188
  {...restProps}
182
- ></div>
189
+ >
190
+ {@render children?.()}
191
+ </div>
183
192
  {/if}
184
193
 
185
194
  <style>
@@ -1,3 +1,4 @@
1
+ import type { Snippet } from 'svelte';
1
2
  import type { CommonStyleProps, Without } from '../utils/types.js';
2
3
  export type CirclePropsWithoutHTML = {
3
4
  /**
@@ -43,6 +44,8 @@ export type CirclePropsWithoutHTML = {
43
44
  */
44
45
  ref?: SVGCircleElement;
45
46
  motion?: MotionProp;
47
+ /** Children content to render. Note: Only works for Html layers */
48
+ children?: Snippet;
46
49
  } & CommonStyleProps;
47
50
  export type CircleProps = CirclePropsWithoutHTML & Without<SVGAttributes<Element>, CirclePropsWithoutHTML>;
48
51
  import { type MotionProp } from '../utils/motion.svelte.js';
@@ -3,7 +3,7 @@
3
3
  import type { Without } from '../utils/types.js';
4
4
  import type { Snippet } from 'svelte';
5
5
  import type { SVGAttributes } from 'svelte/elements';
6
- import { getRenderContext } from './Chart.svelte';
6
+ import { getLayerContext } from '../contexts/layer.js';
7
7
 
8
8
  export type ClipPathPropsWithoutHTML = {
9
9
  /**
@@ -56,10 +56,10 @@
56
56
 
57
57
  const url = $derived(`url(#${id})`);
58
58
 
59
- const renderContext = getRenderContext();
59
+ const layerCtx = getLayerContext();
60
60
  </script>
61
61
 
62
- {#if renderContext === 'svg'}
62
+ {#if layerCtx === 'svg'}
63
63
  <defs>
64
64
  <clipPath {id} {...restProps}>
65
65
  {@render clip?.({ id })}
@@ -72,7 +72,7 @@
72
72
  {/if}
73
73
 
74
74
  {#if children}
75
- {#if disabled || renderContext !== 'svg'}
75
+ {#if disabled || layerCtx !== 'svg'}
76
76
  {@render children({ id, url, useId })}
77
77
  {:else}
78
78
  <g style:clip-path={url} class="lc-clip-path-g">
@@ -46,10 +46,10 @@
46
46
  * @default `d3.curveLinear`
47
47
  */
48
48
  curve?: CurveFactory;
49
- } & SplinePropsWithoutHTML;
49
+ } & PathPropsWithoutHTML;
50
50
 
51
51
  export type ConnectorProps = ConnectorPropsWithoutHTML &
52
- Without<SplineProps, ConnectorPropsWithoutHTML>;
52
+ Without<PathProps, ConnectorPropsWithoutHTML>;
53
53
  </script>
54
54
 
55
55
  <script lang="ts">
@@ -61,7 +61,7 @@
61
61
  type ConnectorSweep,
62
62
  type ConnectorType,
63
63
  } from '../utils/connectorUtils.js';
64
- import Spline, { type SplineProps, type SplinePropsWithoutHTML } from './Spline.svelte';
64
+ import Path, { type PathProps, type PathPropsWithoutHTML } from './Path.svelte';
65
65
  import type { Without } from '../utils/types.js';
66
66
  import { createId } from '../utils/createId.js';
67
67
  import { extractLayerProps } from '../utils/attributes.js';
@@ -135,7 +135,7 @@
135
135
  );
136
136
  </script>
137
137
 
138
- <Spline
138
+ <Path
139
139
  pathData={motionPath.current}
140
140
  bind:pathRef
141
141
  marker-start={markerStartId ? `url(#${markerStartId})` : undefined}
@@ -40,11 +40,11 @@ export type ConnectorPropsWithoutHTML = {
40
40
  * @default `d3.curveLinear`
41
41
  */
42
42
  curve?: CurveFactory;
43
- } & SplinePropsWithoutHTML;
44
- export type ConnectorProps = ConnectorPropsWithoutHTML & Without<SplineProps, ConnectorPropsWithoutHTML>;
43
+ } & PathPropsWithoutHTML;
44
+ export type ConnectorProps = ConnectorPropsWithoutHTML & Without<PathProps, ConnectorPropsWithoutHTML>;
45
45
  import { type CurveFactory } from 'd3-shape';
46
46
  import { type ConnectorCoords, type ConnectorSweep, type ConnectorType } from '../utils/connectorUtils.js';
47
- import { type SplineProps, type SplinePropsWithoutHTML } from './Spline.svelte';
47
+ import { type PathProps, type PathPropsWithoutHTML } from './Path.svelte';
48
48
  import type { Without } from '../utils/types.js';
49
49
  declare const Connector: import("svelte").Component<ConnectorProps, {}, "pathRef">;
50
50
  type Connector = ReturnType<typeof Connector>;
@@ -74,11 +74,11 @@
74
74
 
75
75
  <script lang="ts">
76
76
  import { cls } from '@layerstack/tailwind';
77
- import { merge } from 'lodash-es';
77
+ import { merge } from '@layerstack/utils';
78
78
 
79
- import { getRenderContext } from './Chart.svelte';
79
+ import { getLayerContext } from '../contexts/layer.js';
80
80
  import { createMotion, type MotionProp } from '../utils/motion.svelte.js';
81
- import { registerCanvasComponent } from './layout/Canvas.svelte';
81
+ import { registerCanvasComponent } from './layers/Canvas.svelte';
82
82
  import { renderEllipse, type ComputedStylesOptions } from '../utils/canvas.js';
83
83
  import type { SVGAttributes } from 'svelte/elements';
84
84
  import { createKey } from '../utils/key.svelte.js';
@@ -114,7 +114,7 @@
114
114
  const initialRx = initialRxProp ?? rx;
115
115
  const initialRy = initialRyProp ?? ry;
116
116
 
117
- const renderCtx = getRenderContext();
117
+ const layerCtx = getLayerContext();
118
118
 
119
119
  const motionCx = createMotion(initialCx, () => cx, motion);
120
120
  const motionCy = createMotion(initialCy, () => cy, motion);
@@ -141,7 +141,7 @@
141
141
  const fillKey = createKey(() => fill);
142
142
  const strokeKey = createKey(() => stroke);
143
143
 
144
- if (renderCtx === 'canvas') {
144
+ if (layerCtx === 'canvas') {
145
145
  registerCanvasComponent({
146
146
  name: 'Ellipse',
147
147
  render,
@@ -168,7 +168,7 @@
168
168
  }
169
169
  </script>
170
170
 
171
- {#if renderCtx === 'svg'}
171
+ {#if layerCtx === 'svg'}
172
172
  <ellipse
173
173
  bind:this={ref}
174
174
  cx={motionCx.current}
@@ -183,7 +183,7 @@
183
183
  class={cls('lc-ellipse', className)}
184
184
  {...restProps}
185
185
  />
186
- {:else if renderCtx === 'html'}
186
+ {:else if layerCtx === 'html'}
187
187
  <div
188
188
  style:position="absolute"
189
189
  style:left="{motionCx.current}px"
@@ -18,7 +18,7 @@
18
18
  </script>
19
19
 
20
20
  <script lang="ts">
21
- import { getChartContext } from './Chart.svelte';
21
+ import { getChartContext } from '../contexts/chart.js';
22
22
  import { extractLayerProps } from '../utils/attributes.js';
23
23
 
24
24
  let { ref: refProp = $bindable(), full = false, ...restProps }: FrameProps = $props();
@@ -1,26 +1,10 @@
1
1
  <script lang="ts" module>
2
- import { type GeoPermissibleObjects, type GeoProjection } from 'd3-geo';
3
- import { getTransformContext } from './TransformContext.svelte';
4
- import { Context } from 'runed';
5
- import { getChartContext } from './Chart.svelte';
6
2
  import type { Snippet } from 'svelte';
3
+ import { type GeoPermissibleObjects, type GeoProjection } from 'd3-geo';
7
4
 
8
- export type GeoContextValue = {
9
- projection: GeoProjection | undefined;
10
- };
11
-
12
- /**
13
- * Access or set the current GeoContext.
14
- */
15
- const _GeoContext = new Context<GeoContextValue>('GeoContext');
16
-
17
- export function getGeoContext() {
18
- return _GeoContext.getOr({ projection: undefined } as GeoContextValue);
19
- }
20
-
21
- export function setGeoContext(geo: GeoContextValue) {
22
- return _GeoContext.set(geo);
23
- }
5
+ import { setGeoContext, type GeoContextValue } from '../contexts/geo.js';
6
+ import { getTransformContext } from '../contexts/transform.js';
7
+ import { getChartContext } from '../contexts/chart.js';
24
8
 
25
9
  export type GeoContextProps = {
26
10
  /**
@@ -1,10 +1,6 @@
1
- import { type GeoPermissibleObjects, type GeoProjection } from 'd3-geo';
2
1
  import type { Snippet } from 'svelte';
3
- export type GeoContextValue = {
4
- projection: GeoProjection | undefined;
5
- };
6
- export declare function getGeoContext(): GeoContextValue;
7
- export declare function setGeoContext(geo: GeoContextValue): GeoContextValue;
2
+ import { type GeoPermissibleObjects, type GeoProjection } from 'd3-geo';
3
+ import { type GeoContextValue } from '../contexts/geo.js';
8
4
  export type GeoContextProps = {
9
5
  /**
10
6
  * A d3 projection function. Pass this in as an uncalled function, e.g.
@@ -22,7 +22,7 @@
22
22
  import { scaleLinear } from 'd3-scale';
23
23
  import { geoDistance } from 'd3-geo';
24
24
 
25
- import { getGeoContext } from './GeoContext.svelte';
25
+ import { getGeoContext } from '../contexts/geo.js';
26
26
  import Group, { type GroupProps } from './Group.svelte';
27
27
  import { extractLayerProps } from '../utils/attributes.js';
28
28
 
@@ -1,9 +1,6 @@
1
1
  <script lang="ts" module>
2
- import type { CommonStyleProps, Without } from '../utils/types.js';
3
2
  import type { Snippet } from 'svelte';
4
- import type { PointerEventHandler, SVGAttributes } from 'svelte/elements';
5
- import type { TooltipContextValue } from './tooltip/TooltipContext.svelte';
6
- import { curveLinearClosed, type CurveFactory, type CurveFactoryLineOnly } from 'd3-shape';
3
+ import type { SVGAttributes } from 'svelte/elements';
7
4
  import {
8
5
  geoPath as d3GeoPath,
9
6
  geoTransform as d3geoTransform,
@@ -12,7 +9,11 @@
12
9
  type GeoProjection,
13
10
  type GeoTransformPrototype,
14
11
  } from 'd3-geo';
15
- import { renderPathData, type ComputedStylesOptions } from '../utils/canvas.js';
12
+ import { curveLinearClosed, type CurveFactory, type CurveFactoryLineOnly } from 'd3-shape';
13
+
14
+ import type { CommonStyleProps, Without } from '../utils/types.js';
15
+ import type { TooltipContextValue } from '../contexts/tooltip.js';
16
+ import type { PathProps } from './Path.svelte';
16
17
 
17
18
  export type GeoPathPropsWithoutHTML = {
18
19
  /**
@@ -59,42 +60,45 @@
59
60
  ref?: SVGPathElement;
60
61
 
61
62
  children?: Snippet<[{ geoPath: ReturnType<typeof geoCurvePath> | undefined }]>;
62
- } & CommonStyleProps;
63
+ } & CommonStyleProps &
64
+ Pick<
65
+ PathProps,
66
+ | 'motion'
67
+ | 'draw'
68
+ | 'marker'
69
+ | 'markerStart'
70
+ | 'markerMid'
71
+ | 'markerEnd'
72
+ | 'startContent'
73
+ | 'endContent'
74
+ >;
63
75
 
64
76
  export type GeoPathProps = GeoPathPropsWithoutHTML &
65
77
  Without<SVGAttributes<SVGPathElement>, GeoPathPropsWithoutHTML>;
66
78
  </script>
67
79
 
68
80
  <script lang="ts">
69
- import { merge } from 'lodash-es';
81
+ import { cls } from '@layerstack/tailwind';
70
82
 
71
- import { getRenderContext } from './Chart.svelte';
72
- import { registerCanvasComponent } from './layout/Canvas.svelte';
73
83
  import { geoCurvePath } from '../utils/geo.js';
74
- import { getGeoContext } from './GeoContext.svelte';
75
- import { createKey } from '../utils/key.svelte.js';
84
+ import { getGeoContext } from '../contexts/geo.js';
85
+ import Path from './Path.svelte';
76
86
 
77
87
  let {
78
- fill,
79
- stroke,
80
- strokeWidth,
81
- opacity,
82
88
  geoTransform,
83
89
  geojson,
84
90
  tooltipContext,
85
91
  curve = curveLinearClosed,
86
92
  onclick,
93
+ onpointerenter,
94
+ onpointermove,
95
+ onpointerleave,
87
96
  class: className,
88
97
  ref: refProp = $bindable(),
89
98
  children,
90
99
  ...restProps
91
100
  }: GeoPathProps = $props();
92
101
 
93
- let ref = $state<SVGPathElement>();
94
- $effect.pre(() => {
95
- refProp = ref;
96
- });
97
-
98
102
  const geo = getGeoContext();
99
103
 
100
104
  const projection = $derived(
@@ -111,109 +115,40 @@
111
115
  return geoCurvePath(projection, curve);
112
116
  });
113
117
 
114
- const renderCtx = getRenderContext();
115
-
116
- function render(
117
- ctx: CanvasRenderingContext2D,
118
- styleOverrides: ComputedStylesOptions | undefined
119
- ) {
120
- if (!geojson) return;
121
- const pathData = geoPath?.(geojson);
122
- renderPathData(
123
- ctx,
124
- pathData,
125
- styleOverrides
126
- ? merge({ styles: { strokeWidth } }, styleOverrides)
127
- : {
128
- styles: { fill, stroke, strokeWidth, opacity },
129
- classes: className,
130
- }
131
- );
132
- }
133
-
134
- // TODO: Use objectId to work around Svelte 4 reactivity issue (even when memoizing gradients)
135
- const fillKey = createKey(() => fill);
136
- const strokeKey = createKey(() => stroke);
118
+ const pathData = $derived(geojson ? geoPath?.(geojson) : '');
137
119
 
138
- // Hide `geoPath` and `tooltip` reactivity
120
+ // Hide `geoPath` reactivity from onclick handler
139
121
  function _onClick(e: MouseEvent) {
140
122
  onclick?.(e, geoPath);
141
123
  }
142
124
 
143
- const _onPointerEnter: PointerEventHandler<SVGPathElement> = (e) => {
144
- restProps.onpointerenter?.(e);
125
+ function _onPointerEnter(e: PointerEvent & { currentTarget: EventTarget & SVGPathElement }) {
126
+ onpointerenter?.(e);
145
127
  tooltipContext?.show(e, geojson);
146
- };
128
+ }
147
129
 
148
- const _onPointerMove: PointerEventHandler<SVGPathElement> = (e) => {
149
- restProps.onpointermove?.(e);
130
+ function _onPointerMove(e: PointerEvent & { currentTarget: EventTarget & SVGPathElement }) {
131
+ onpointermove?.(e);
150
132
  tooltipContext?.show(e, geojson);
151
- };
133
+ }
152
134
 
153
- const _onPointerLeave: PointerEventHandler<SVGPathElement> = (e) => {
154
- restProps.onpointerleave?.(e);
135
+ function _onPointerLeave(e: PointerEvent & { currentTarget: EventTarget & SVGPathElement }) {
136
+ onpointerleave?.(e);
155
137
  tooltipContext?.hide();
156
- };
157
-
158
- if (renderCtx === 'canvas') {
159
- registerCanvasComponent({
160
- name: 'GeoPath',
161
- render,
162
- events: {
163
- // Only register events if they are defined (so they are not registered with hit canvas unnecessarily)
164
- click: onclick ? _onClick : undefined,
165
- pointerenter: restProps.onpointerenter || tooltipContext ? _onPointerEnter : undefined,
166
- pointermove: restProps.onpointermove || tooltipContext ? _onPointerMove : undefined,
167
- pointerleave: restProps.onpointerleave || tooltipContext ? _onPointerLeave : undefined,
168
- pointerdown: restProps.onpointerdown,
169
- touchmove: restProps.ontouchmove,
170
- },
171
- deps: () => [
172
- projection,
173
- geojson,
174
- curve,
175
- fillKey.current,
176
- strokeKey.current,
177
- strokeWidth,
178
- opacity,
179
- className,
180
- ],
181
- });
182
138
  }
183
139
  </script>
184
140
 
185
141
  {#if children}
186
142
  {@render children({ geoPath })}
187
- {:else if renderCtx === 'svg'}
188
- <path
189
- bind:this={ref}
143
+ {:else}
144
+ <Path
145
+ {pathData}
190
146
  {...restProps}
191
- d={geojson ? geoPath?.(geojson) : ''}
192
- {fill}
193
- {stroke}
194
- stroke-width={strokeWidth}
195
- {opacity}
196
147
  onclick={_onClick}
197
- onpointerenter={_onPointerEnter}
198
- onpointermove={_onPointerMove}
199
- onpointerleave={_onPointerLeave}
200
- class={['lc-geo-path', className]}
148
+ onpointerenter={tooltipContext || onpointerenter ? _onPointerEnter : undefined}
149
+ onpointermove={tooltipContext || onpointermove ? _onPointerMove : undefined}
150
+ onpointerleave={tooltipContext || onpointerleave ? _onPointerLeave : undefined}
151
+ class={cls('lc-geo-path', className)}
152
+ pathRef={refProp}
201
153
  />
202
154
  {/if}
203
-
204
- <style>
205
- @layer base {
206
- :global(:where(.lc-geo-path)) {
207
- --fill-color: transparent;
208
- --stroke-color: initial;
209
- }
210
-
211
- /* Svg | Canvas layers */
212
- :global(:where(.lc-layout-svg .lc-geo-path, svg.lc-geo-path):not([fill])) {
213
- fill: var(--fill-color);
214
- }
215
- :global(:where(.lc-layout-svg .lc-geo-path, svg.lc-geo-path):not([stroke])) {
216
- stroke: var(--stroke-color);
217
- }
218
- }
219
- </style>
@@ -1,9 +1,10 @@
1
- import type { CommonStyleProps, Without } from '../utils/types.js';
2
1
  import type { Snippet } from 'svelte';
3
2
  import type { SVGAttributes } from 'svelte/elements';
4
- import type { TooltipContextValue } from './tooltip/TooltipContext.svelte';
5
- import { type CurveFactory, type CurveFactoryLineOnly } from 'd3-shape';
6
3
  import { type GeoIdentityTransform, type GeoPermissibleObjects, type GeoProjection, type GeoTransformPrototype } from 'd3-geo';
4
+ import { type CurveFactory, type CurveFactoryLineOnly } from 'd3-shape';
5
+ import type { CommonStyleProps, Without } from '../utils/types.js';
6
+ import type { TooltipContextValue } from '../contexts/tooltip.js';
7
+ import type { PathProps } from './Path.svelte';
7
8
  export type GeoPathPropsWithoutHTML = {
8
9
  /**
9
10
  * GeoJSON data to render
@@ -43,7 +44,7 @@ export type GeoPathPropsWithoutHTML = {
43
44
  children?: Snippet<[{
44
45
  geoPath: ReturnType<typeof geoCurvePath> | undefined;
45
46
  }]>;
46
- } & CommonStyleProps;
47
+ } & CommonStyleProps & Pick<PathProps, 'motion' | 'draw' | 'marker' | 'markerStart' | 'markerMid' | 'markerEnd' | 'startContent' | 'endContent'>;
47
48
  export type GeoPathProps = GeoPathPropsWithoutHTML & Without<SVGAttributes<SVGPathElement>, GeoPathPropsWithoutHTML>;
48
49
  import { geoCurvePath } from '../utils/geo.js';
49
50
  declare const GeoPath: import("svelte").Component<GeoPathProps, {}, "ref">;
@@ -31,8 +31,8 @@
31
31
 
32
32
  <script lang="ts">
33
33
  import Group from './Group.svelte';
34
- import { getRenderContext } from './Chart.svelte';
35
- import { getGeoContext } from './GeoContext.svelte';
34
+ import { getLayerContext } from '../contexts/layer.js';
35
+ import { getGeoContext } from '../contexts/geo.js';
36
36
  import { extractLayerProps } from '../utils/attributes.js';
37
37
 
38
38
  let { lat, long, ref: refProp = $bindable(), children, ...restProps }: GeoPointProps = $props();
@@ -48,10 +48,10 @@
48
48
  const x = $derived(points[0]);
49
49
  const y = $derived(points[1]);
50
50
 
51
- const renderContext = getRenderContext();
51
+ const layerCtx = getLayerContext();
52
52
  </script>
53
53
 
54
- {#if renderContext === 'svg'}
54
+ {#if layerCtx === 'svg'}
55
55
  {#if children}
56
56
  <Group {x} {y} {...extractLayerProps(restProps, 'lc-geo-point-group')}>
57
57
  {@render children({ x, y })}
@@ -61,7 +61,7 @@
61
61
  {/if}
62
62
  {/if}
63
63
 
64
- {#if renderContext === 'canvas'}
64
+ {#if layerCtx === 'canvas'}
65
65
  {#if children}
66
66
  <!-- TODO: Handle Canvas translation. Consolidate with svg use case above -->
67
67
  <!-- <Group {x} {y} {...$$restProps}> -->
@@ -35,21 +35,10 @@
35
35
  <script lang="ts">
36
36
  import { geoOrthographic, geoInterpolate } from 'd3-geo';
37
37
 
38
- import { getGeoContext } from './GeoContext.svelte';
38
+ import { getGeoContext } from '../contexts/geo.js';
39
39
  import { extractLayerProps } from '../utils/attributes.js';
40
40
 
41
- let {
42
- link,
43
- loft = 1.0,
44
- curve = curveNatural,
45
- pathRef: pathRefProp = $bindable(),
46
- ...restProps
47
- }: GeoSplineProps = $props();
48
-
49
- let pathRef = $state<SVGPathElement>();
50
- $effect.pre(() => {
51
- pathRefProp = pathRef;
52
- });
41
+ let { link, loft = 1.0, curve = curveNatural, ...restProps }: GeoSplineProps = $props();
53
42
 
54
43
  const geoCtx = getGeoContext();
55
44
 
@@ -76,7 +65,6 @@
76
65
  </script>
77
66
 
78
67
  <Spline
79
- bind:pathRef
80
68
  data={[source, middle, target]}
81
69
  x={(d) => d[0]}
82
70
  y={(d) => d[1]}
@@ -27,6 +27,6 @@ export type GeoSplinePropsWithoutHTML = {
27
27
  curve?: CurveFactory | CurveFactoryLineOnly;
28
28
  };
29
29
  export type GeoSplineProps = GeoSplinePropsWithoutHTML & Without<SplineProps, GeoSplinePropsWithoutHTML>;
30
- declare const GeoSpline: import("svelte").Component<GeoSplineProps, {}, "pathRef">;
30
+ declare const GeoSpline: import("svelte").Component<GeoSplineProps, {}, "">;
31
31
  type GeoSpline = ReturnType<typeof GeoSpline>;
32
32
  export default GeoSpline;
@@ -44,11 +44,12 @@
44
44
  // @ts-expect-error
45
45
  import { tile as d3Tile } from 'd3-tile';
46
46
 
47
- import { getRenderContext, getChartContext } from './Chart.svelte';
48
- import { registerCanvasComponent } from './layout/Canvas.svelte';
47
+ import { getChartContext } from '../contexts/chart.js';
48
+ import { getLayerContext } from '../contexts/layer.js';
49
+ import { registerCanvasComponent } from './layers/Canvas.svelte';
49
50
  import Group from './Group.svelte';
50
51
  import TileImage from './TileImage.svelte';
51
- import { getGeoContext } from './GeoContext.svelte';
52
+ import { getGeoContext } from '../contexts/geo.js';
52
53
  import { extractLayerProps } from '../utils/attributes.js';
53
54
 
54
55
  let {
@@ -63,7 +64,7 @@
63
64
 
64
65
  const ctx = getChartContext();
65
66
  const geoCtx = getGeoContext();
66
- const renderCtx = getRenderContext();
67
+ const layerCtx = getLayerContext();
67
68
 
68
69
  const center = $derived(geoCtx.projection?.([0, 0]) ?? [0, 0]);
69
70
 
@@ -90,7 +91,7 @@
90
91
  }
91
92
  }
92
93
 
93
- if (renderCtx === 'canvas') {
94
+ if (layerCtx === 'canvas') {
94
95
  registerCanvasComponent({
95
96
  name: 'GeoTile',
96
97
  render,
@@ -99,7 +100,7 @@
99
100
  }
100
101
  </script>
101
102
 
102
- {#if renderCtx === 'svg' && url}
103
+ {#if layerCtx === 'svg' && url}
103
104
  {#if children}
104
105
  {@render children({ tiles })}
105
106
  {:else}
@@ -12,7 +12,7 @@
12
12
 
13
13
  <script lang="ts">
14
14
  import { isVisible } from '../utils/geo.js';
15
- import { getGeoContext } from './GeoContext.svelte';
15
+ import { getGeoContext } from '../contexts/geo.js';
16
16
 
17
17
  let { lat, long, children }: GeoVisibleProps = $props();
18
18
  const geoCtx = getGeoContext();