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,6 +1,7 @@
1
1
  <script lang="ts" module>
2
- import type { CommonEvents, CommonStyleProps, Without } from '../utils/types.js';
2
+ import type { Snippet } from 'svelte';
3
3
  import type { SVGAttributes } from 'svelte/elements';
4
+ import type { CommonEvents, CommonStyleProps, Without } from '../utils/types.js';
4
5
  import { createMotion, parseMotionProp, type MotionProp } from '../utils/motion.svelte.js';
5
6
  import { renderRect, type ComputedStylesOptions } from '../utils/canvas.js';
6
7
 
@@ -36,6 +37,9 @@
36
37
  ref?: SVGRectElement;
37
38
 
38
39
  motion?: MotionProp<'x' | 'y' | 'width' | 'height'>;
40
+
41
+ /** Children content to render. Note: Only works for Html layers */
42
+ children?: Snippet;
39
43
  } & CommonStyleProps;
40
44
 
41
45
  export type RectProps = RectPropsWithoutHTML &
@@ -45,10 +49,10 @@
45
49
 
46
50
  <script lang="ts">
47
51
  import { cls } from '@layerstack/tailwind';
48
- import { merge } from 'lodash-es';
52
+ import { merge } from '@layerstack/utils';
49
53
 
50
- import { getRenderContext } from './Chart.svelte';
51
- import { registerCanvasComponent } from './layout/Canvas.svelte';
54
+ import { getLayerContext } from '../contexts/layer.js';
55
+ import { registerCanvasComponent } from './layers/Canvas.svelte';
52
56
  import { createKey } from '../utils/key.svelte.js';
53
57
 
54
58
  let {
@@ -65,6 +69,8 @@
65
69
  initialWidth = width,
66
70
  strokeWidth,
67
71
  opacity,
72
+ rx: rxProp,
73
+ ry: ryProp,
68
74
  ref: refProp = $bindable(),
69
75
  motion,
70
76
  class: className,
@@ -75,9 +81,15 @@
75
81
  onpointerleave,
76
82
  onpointerover,
77
83
  onpointerout,
84
+ children,
78
85
  ...restProps
79
86
  }: RectProps = $props();
80
87
 
88
+ // Normalize rx/ry - if only one is provided, use it for both (SVG behavior)
89
+ // Coerce to number for canvas rendering (SVG allows string like "50%")
90
+ const rx = $derived(Number(rxProp ?? ryProp) || 0);
91
+ const ry = $derived(Number(ryProp ?? rxProp) || 0);
92
+
81
93
  let ref = $state<SVGRectElement>();
82
94
 
83
95
  $effect.pre(() => {
@@ -89,7 +101,7 @@
89
101
  const motionWidth = createMotion(initialWidth, () => width, parseMotionProp(motion, 'width'));
90
102
  const motionHeight = createMotion(initialHeight, () => height, parseMotionProp(motion, 'height'));
91
103
 
92
- const renderCtx = getRenderContext();
104
+ const layerCtx = getLayerContext();
93
105
 
94
106
  function render(
95
107
  ctx: CanvasRenderingContext2D,
@@ -102,12 +114,15 @@
102
114
  y: motionY.current,
103
115
  width: motionWidth.current,
104
116
  height: motionHeight.current,
117
+ rx,
118
+ ry,
105
119
  },
106
120
  styleOverrides
107
121
  ? merge({ styles: { strokeWidth } }, styleOverrides)
108
122
  : {
109
123
  styles: { fill, fillOpacity, stroke, strokeWidth, opacity },
110
124
  classes: cls('lc-rect', className),
125
+ style: restProps.style as string | undefined,
111
126
  }
112
127
  );
113
128
  }
@@ -116,7 +131,7 @@
116
131
  const fillKey = createKey(() => fill);
117
132
  const strokeKey = createKey(() => stroke);
118
133
 
119
- if (renderCtx === 'canvas') {
134
+ if (layerCtx === 'canvas') {
120
135
  registerCanvasComponent({
121
136
  name: 'Rect',
122
137
  render,
@@ -139,12 +154,15 @@
139
154
  strokeWidth,
140
155
  opacity,
141
156
  className,
157
+ restProps.style,
158
+ rx,
159
+ ry,
142
160
  ],
143
161
  });
144
162
  }
145
163
  </script>
146
164
 
147
- {#if renderCtx === 'svg'}
165
+ {#if layerCtx === 'svg'}
148
166
  <rect
149
167
  x={motionX.current}
150
168
  y={motionY.current}
@@ -155,6 +173,8 @@
155
173
  {stroke}
156
174
  stroke-width={strokeWidth}
157
175
  {opacity}
176
+ {rx}
177
+ {ry}
158
178
  class={cls('lc-rect', className)}
159
179
  {...restProps}
160
180
  {onclick}
@@ -166,7 +186,7 @@
166
186
  {onpointerout}
167
187
  bind:this={ref}
168
188
  />
169
- {:else if renderCtx === 'html'}
189
+ {:else if layerCtx === 'html'}
170
190
  <!-- svelte-ignore a11y_click_events_have_key_events -->
171
191
  <!-- svelte-ignore a11y_no_static_element_interactions -->
172
192
  <div
@@ -180,7 +200,7 @@
180
200
  style:border-width="{strokeWidth}px"
181
201
  style:border-style="solid"
182
202
  style:border-color={stroke}
183
- style:border-radius="{restProps.rx}px"
203
+ style:border-radius="{rx}px"
184
204
  class={cls('lc-rect', className)}
185
205
  {...restProps as any}
186
206
  {onclick}
@@ -190,7 +210,9 @@
190
210
  {onpointerleave}
191
211
  {onpointerover}
192
212
  {onpointerout}
193
- ></div>
213
+ >
214
+ {@render children?.()}
215
+ </div>
194
216
  {/if}
195
217
 
196
218
  <style>
@@ -1,5 +1,6 @@
1
- import type { CommonEvents, CommonStyleProps, Without } from '../utils/types.js';
1
+ import type { Snippet } from 'svelte';
2
2
  import type { SVGAttributes } from 'svelte/elements';
3
+ import type { CommonEvents, CommonStyleProps, Without } from '../utils/types.js';
3
4
  import { type MotionProp } from '../utils/motion.svelte.js';
4
5
  export type RectPropsWithoutHTML = {
5
6
  /**
@@ -29,6 +30,8 @@ export type RectPropsWithoutHTML = {
29
30
  */
30
31
  ref?: SVGRectElement;
31
32
  motion?: MotionProp<'x' | 'y' | 'width' | 'height'>;
33
+ /** Children content to render. Note: Only works for Html layers */
34
+ children?: Snippet;
32
35
  } & CommonStyleProps;
33
36
  export type RectProps = RectPropsWithoutHTML & Without<SVGAttributes<SVGRectElement>, RectPropsWithoutHTML> & CommonEvents;
34
37
  declare const Rect: import("svelte").Component<RectProps, {}, "ref">;
@@ -59,7 +59,7 @@
59
59
  import Circle from './Circle.svelte';
60
60
  import Group from './Group.svelte';
61
61
  import Line, { type LinePropsWithoutHTML } from './Line.svelte';
62
- import { getChartContext } from './Chart.svelte';
62
+ import { getChartContext } from '../contexts/chart.js';
63
63
  import { accessor, chartDataArray, type Accessor } from '../utils/common.js';
64
64
  import { isScaleBand, isScaleNumeric } from '../utils/scales.svelte.js';
65
65
 
@@ -89,7 +89,7 @@
89
89
  type SankeyGraph,
90
90
  } from 'd3-sankey';
91
91
 
92
- import { getChartContext } from './Chart.svelte';
92
+ import { getChartContext } from '../contexts/chart.js';
93
93
 
94
94
  let {
95
95
  nodes: nodesProp = (d: any) => d.nodes,
@@ -1,17 +1,8 @@
1
1
  <script lang="ts" module>
2
- import type { Snippet } from 'svelte';
3
- import type { MarkerOptions } from './MarkerWrapper.svelte';
4
- import type { CommonStyleProps, Without } from '../utils/types.js';
2
+ import type { Without } from '../utils/types.js';
5
3
  import type { SVGAttributes } from 'svelte/elements';
6
4
  import type { CurveFactory, CurveFactoryLineOnly, Line } from 'd3-shape';
7
5
 
8
- import {
9
- createControlledMotion,
10
- createMotion,
11
- extractTweenConfig,
12
- type MotionProp,
13
- type ResolvedMotion,
14
- } from '../utils/motion.svelte.js';
15
6
  import { accessor, type Accessor } from '../utils/common.js';
16
7
 
17
8
  export type SplinePropsWithoutHTML = {
@@ -20,12 +11,6 @@
20
11
  */
21
12
  data?: any;
22
13
 
23
- /**
24
- * Pass `<path d={...} />` explicitly instead of calculating
25
- * from data / context
26
- */
27
- pathData?: string | undefined | null;
28
-
29
14
  /**
30
15
  * Override `x` accessor from Chart context
31
16
  */
@@ -36,26 +21,6 @@
36
21
  */
37
22
  y?: Accessor;
38
23
 
39
- /**
40
- * Whether to animate the drawing of the path over time.
41
- * Pass either `true` or an object with transition options to
42
- * enable the transition.
43
- *
44
- * Works best with `tweened` disabled.
45
- */
46
- draw?: boolean | Parameters<typeof _drawTransition>[1];
47
-
48
- /**
49
- * Curve of spline drawn. Imported via d3-shape.
50
- *
51
- * @example
52
- * import { curveNatural } from 'd3-shape';
53
- * <Spline curve={curveNatural} />
54
- *
55
- * @type {CurveFactory | CurveFactoryLineOnly | undefined}
56
- */
57
- curve?: CurveFactory | CurveFactoryLineOnly;
58
-
59
24
  /**
60
25
  * Function to determine if a point is defined
61
26
  *
@@ -65,48 +30,16 @@
65
30
  defined?: Parameters<Line<any>['defined']>[0];
66
31
 
67
32
  /**
68
- * Marker to attach to both start and end points of the line
69
- */
70
- marker?: MarkerOptions;
71
-
72
- /**
73
- * Marker to attach to the middle point of the line
74
- */
75
- markerMid?: MarkerOptions;
76
-
77
- /**
78
- * Marker to attach to the start point of the line
79
- */
80
- markerStart?: MarkerOptions;
81
-
82
- /**
83
- * Marker to attach to the end point of the line
84
- */
85
- markerEnd?: MarkerOptions;
86
-
87
- /**
88
- * Add additional content at the start of the line.
33
+ * Curve of path drawn. Imported via d3-shape.
89
34
  *
90
- * Receives `{ point: DOMPoint; value: { x: number; y: number } }` as a snippet prop.
91
- */
92
- startContent?: Snippet<[{ point: DOMPoint; value: { x: number; y: number } }]>;
93
-
94
- /**
95
- * Add additional content at the end of the line.
96
- *
97
- * Receives `{ point: DOMPoint; value: { x: number; y: number } }` as a snippet prop.
98
- */
99
- endContent?: Snippet<[{ point: DOMPoint; value: { x: number; y: number } }]>;
100
-
101
- /**
102
- * A reference to the `<path>` element.
35
+ * @example
36
+ * import { curveNatural } from 'd3-shape';
37
+ * <Path curve={curveNatural} />
103
38
  *
104
- * @bindable
39
+ * @type {CurveFactory | CurveFactoryLineOnly | undefined}
105
40
  */
106
- pathRef?: SVGPathElement;
107
-
108
- motion?: MotionProp;
109
- } & CommonStyleProps;
41
+ curve?: CurveFactory | CurveFactoryLineOnly;
42
+ } & Omit<PathProps, 'x' | 'y'>;
110
43
 
111
44
  export type SplineProps = SplinePropsWithoutHTML &
112
45
  Without<SVGAttributes<SVGPathElement>, SplinePropsWithoutHTML>;
@@ -114,67 +47,17 @@
114
47
 
115
48
  <script lang="ts">
116
49
  import { draw as _drawTransition } from 'svelte/transition';
117
- import { cubicInOut } from 'svelte/easing';
118
- import { merge } from 'lodash-es';
119
50
 
120
51
  import { line as d3Line, lineRadial } from 'd3-shape';
121
- import { interpolatePath } from 'd3-interpolate-path';
122
52
  import { max } from 'd3-array';
123
- import { cls } from '@layerstack/tailwind';
124
53
 
125
- import Group from './Group.svelte';
126
54
  import { isScaleBand } from '../utils/scales.svelte.js';
127
- import { flattenPathData } from '../utils/path.js';
128
- import { registerCanvasComponent } from './layout/Canvas.svelte';
129
- import { renderPathData, type ComputedStylesOptions } from '../utils/canvas.js';
130
- import { getRenderContext } from './Chart.svelte';
131
- import MarkerWrapper from './MarkerWrapper.svelte';
132
- import { getChartContext } from './Chart.svelte';
133
- import { createKey } from '../utils/key.svelte.js';
134
- import { createId } from '../utils/createId.js';
55
+ import { getChartContext } from '../contexts/chart.js';
56
+ import Path, { type PathProps } from './Path.svelte';
135
57
 
136
58
  const ctx = getChartContext();
137
59
 
138
- const uid = $props.id();
139
-
140
- let {
141
- data,
142
- pathData,
143
- x,
144
- y,
145
- motion,
146
- draw,
147
- curve,
148
- defined,
149
- fill,
150
- stroke,
151
- strokeWidth,
152
- fillOpacity,
153
- class: className,
154
- marker,
155
- markerStart: markerStartProp,
156
- markerMid: markerMidProp,
157
- markerEnd: markerEndProp,
158
- startContent,
159
- endContent,
160
- opacity,
161
- pathRef: pathRefProp = $bindable(),
162
- ...restProps
163
- }: SplineProps = $props();
164
-
165
- let pathRef = $state<SVGPathElement>();
166
-
167
- $effect.pre(() => {
168
- pathRefProp = pathRef;
169
- });
170
-
171
- const markerStart = $derived(markerStartProp ?? marker);
172
- const markerMid = $derived(markerMidProp ?? marker);
173
- const markerEnd = $derived(markerEndProp ?? marker);
174
-
175
- const markerStartId = $derived(markerStart ? createId('marker-start', uid) : '');
176
- const markerMidId = $derived(markerMid ? createId('marker-mid', uid) : '');
177
- const markerEndId = $derived(markerEnd ? createId('marker-end', uid) : '');
60
+ let { data, x, y, defined, curve, ...restProps }: SplineProps = $props();
178
61
 
179
62
  function getScaleValue(
180
63
  data: any,
@@ -202,42 +85,6 @@
202
85
  const xOffset = $derived(isScaleBand(ctx.xScale) ? ctx.xScale.bandwidth() / 2 : 0);
203
86
  const yOffset = $derived(isScaleBand(ctx.yScale) ? ctx.yScale.bandwidth() / 2 : 0);
204
87
 
205
- const extractedTween = extractTweenConfig(motion);
206
-
207
- const tweenedOptions: ResolvedMotion | undefined = extractedTween
208
- ? {
209
- type: extractedTween.type,
210
- options: { interpolate: interpolatePath, ...extractedTween.options },
211
- }
212
- : undefined;
213
-
214
- /** Provide initial `0` horizontal baseline and initially hide/untrack scale changes so not reactive (only set on initial mount) */
215
- function defaultPathData() {
216
- if (!tweenedOptions) {
217
- // If not tweened, return empty string (faster initial render)
218
- return '';
219
- } else if (pathData) {
220
- // Flatten all `y` coordinates of pre-defined `pathData`
221
- return flattenPathData(pathData, Math.min(ctx.yScale(0) ?? ctx.yRange[0], ctx.yRange[0]));
222
- } else if (ctx.config.x) {
223
- // Only use default line if `x` accessor is defined (cartesian chart)
224
- const path = ctx.radial
225
- ? lineRadial()
226
- .angle((d) => ctx.xScale(xAccessor(d)) + 0) // Never apply xOffset (LineChart radar, BarChart radial, ...)?
227
-
228
- .radius((d) => Math.min(ctx.yScale(0), ctx.yRange[0]))
229
- : d3Line()
230
- .x((d) => ctx.xScale(xAccessor(d)) + xOffset)
231
- .y((d) => Math.min(ctx.yScale(0), ctx.yRange[0]));
232
-
233
- path.defined(defined ?? ((d) => xAccessor(d) != null && yAccessor(d) != null));
234
-
235
- if (curve) path.curve(curve);
236
-
237
- return path(data ?? ctx.data);
238
- }
239
- }
240
-
241
88
  const d = $derived.by(() => {
242
89
  const path = ctx.radial
243
90
  ? lineRadial()
@@ -251,179 +98,8 @@
251
98
  path.defined(defined ?? ((d) => xAccessor(d) != null && yAccessor(d) != null));
252
99
  if (curve) path.curve(curve);
253
100
 
254
- return pathData ?? path(data ?? ctx.data) ?? '';
255
- });
256
-
257
- const tweenedState = createMotion(defaultPathData(), () => d, tweenedOptions);
258
-
259
- const drawTransition = $derived(draw ? _drawTransition : () => ({}));
260
-
261
- let key = $state(Symbol());
262
-
263
- const renderCtx = getRenderContext();
264
-
265
- function render(
266
- ctx: CanvasRenderingContext2D,
267
- styleOverrides: ComputedStylesOptions | undefined
268
- ) {
269
- renderPathData(
270
- ctx,
271
- tweenedState.current,
272
- styleOverrides
273
- ? merge({ styles: { strokeWidth } }, styleOverrides)
274
- : {
275
- styles: { fill, fillOpacity, stroke, strokeWidth, opacity },
276
- classes: cls('lc-spline-path', className),
277
- }
278
- );
279
- }
280
-
281
- // TODO: Use objectId to work around Svelte 4 reactivity issue (even when memoizing gradients)
282
- const fillKey = createKey(() => fill);
283
- const strokeKey = createKey(() => stroke);
284
-
285
- if (renderCtx === 'canvas') {
286
- registerCanvasComponent({
287
- name: 'Spline',
288
- render,
289
- events: {
290
- click: restProps.onclick,
291
- pointerenter: restProps.onpointerenter,
292
- pointermove: restProps.onpointermove,
293
- pointerleave: restProps.onpointerleave,
294
- pointerdown: restProps.onpointerdown,
295
- pointerover: restProps.onpointerover,
296
- pointerout: restProps.onpointerout,
297
- touchmove: restProps.ontouchmove,
298
- },
299
- deps: () => [
300
- fillKey.current,
301
- fillOpacity,
302
- strokeKey.current,
303
- strokeWidth,
304
- opacity,
305
- className,
306
- tweenedState.current,
307
- ],
308
- });
309
- }
310
-
311
- let startPoint = $state<DOMPoint | undefined>();
312
-
313
- const endPointDuration = $derived.by(() => {
314
- if (
315
- typeof draw === 'object' &&
316
- draw.duration !== undefined &&
317
- typeof draw.duration !== 'function'
318
- ) {
319
- return draw.duration;
320
- }
321
- return 800;
322
- });
323
-
324
- const endPoint = createControlledMotion<DOMPoint | undefined>(
325
- undefined,
326
- draw
327
- ? {
328
- type: 'tween',
329
- duration: () => endPointDuration,
330
- easing: typeof draw === 'object' && draw.easing ? draw.easing : cubicInOut,
331
- interpolate() {
332
- return (t: number) => {
333
- const totalLength = pathRef?.getTotalLength() ?? 0;
334
- const point = pathRef?.getPointAtLength(totalLength * t);
335
- return point;
336
- };
337
- },
338
- }
339
- : { type: 'none' }
340
- );
341
-
342
- $effect(() => {
343
- if (!startContent && !endContent) return;
344
- d;
345
- if (!pathRef || !pathRef.getTotalLength()) return;
346
- startPoint = pathRef.getPointAtLength(0);
347
- const totalLength = pathRef.getTotalLength();
348
- endPoint.target = pathRef.getPointAtLength(totalLength);
349
- });
350
-
351
- $effect(() => {
352
- if (!draw) return;
353
- // Anytime the path data changes, redraw
354
- [pathData, data, ctx.data];
355
- key = Symbol();
101
+ return path(data ?? ctx.data) ?? '';
356
102
  });
357
103
  </script>
358
104
 
359
- {#if renderCtx === 'svg'}
360
- {#key key}
361
- <path
362
- d={tweenedState.current}
363
- {...restProps}
364
- class={cls('lc-spline-path', className)}
365
- {fill}
366
- fill-opacity={fillOpacity}
367
- {stroke}
368
- stroke-width={strokeWidth}
369
- {opacity}
370
- marker-start={markerStartId ? `url(#${markerStartId})` : undefined}
371
- marker-mid={markerMidId ? `url(#${markerMidId})` : undefined}
372
- marker-end={markerEndId ? `url(#${markerEndId})` : undefined}
373
- in:drawTransition|global={typeof draw === 'object' ? draw : undefined}
374
- bind:this={pathRef}
375
- />
376
- <MarkerWrapper id={markerStartId} marker={markerStart} />
377
- <MarkerWrapper id={markerMidId} marker={markerMid} />
378
- <MarkerWrapper id={markerEndId} marker={markerEnd} />
379
-
380
- {#if startContent && startPoint}
381
- <Group x={startPoint.x} y={startPoint.y} class="lc-spline-g-start">
382
- {@render startContent({
383
- point: startPoint,
384
- value: {
385
- x: ctx.xScale?.invert?.(startPoint.x),
386
- y: ctx.yScale?.invert?.(startPoint.y),
387
- },
388
- })}
389
- </Group>
390
- {/if}
391
-
392
- {#if endContent && endPoint.current}
393
- <Group x={endPoint.current.x} y={endPoint.current.y} class="lc-spline-g-end">
394
- {@render endContent({
395
- point: endPoint.current,
396
- value: {
397
- x: ctx.xScale?.invert?.(endPoint.current.x),
398
- y: ctx.yScale?.invert?.(endPoint.current.y),
399
- },
400
- })}
401
- </Group>
402
- {/if}
403
- {/key}
404
- {/if}
405
-
406
- <style>
407
- @layer base {
408
- :global(:where(.lc-spline-path)) {
409
- --fill-color: none;
410
- --stroke-color: var(--color-surface-content, currentColor);
411
- }
412
-
413
- /* Svg | Canvas layers */
414
- :global(:where(.lc-layout-svg .lc-spline-path, svg.lc-spline-path):not([fill])) {
415
- fill: var(--fill-color);
416
- }
417
- :global(:where(.lc-layout-svg .lc-spline-path, svg.lc-spline-path):not([stroke])) {
418
- stroke: var(--stroke-color);
419
- }
420
-
421
- /* Html layers */
422
- :global(:where(.lc-layout-html .lc-spline-path):not([background-color])) {
423
- background-color: var(--fill-color);
424
- }
425
- :global(:where(.lc-layout-html .lc-spline-path):not([border-color])) {
426
- border-color: var(--stroke-color);
427
- }
428
- }
429
- </style>
105
+ <Path pathData={d} {...restProps} />
@@ -1,20 +1,12 @@
1
- import type { Snippet } from 'svelte';
2
- import type { MarkerOptions } from './MarkerWrapper.svelte';
3
- import type { CommonStyleProps, Without } from '../utils/types.js';
1
+ import type { Without } from '../utils/types.js';
4
2
  import type { SVGAttributes } from 'svelte/elements';
5
3
  import type { CurveFactory, CurveFactoryLineOnly, Line } from 'd3-shape';
6
- import { type MotionProp } from '../utils/motion.svelte.js';
7
4
  import { type Accessor } from '../utils/common.js';
8
5
  export type SplinePropsWithoutHTML = {
9
6
  /**
10
7
  * Override data instead of using context
11
8
  */
12
9
  data?: any;
13
- /**
14
- * Pass `<path d={...} />` explicitly instead of calculating
15
- * from data / context
16
- */
17
- pathData?: string | undefined | null;
18
10
  /**
19
11
  * Override `x` accessor from Chart context
20
12
  */
@@ -23,24 +15,6 @@ export type SplinePropsWithoutHTML = {
23
15
  * Override `y` accessor from Chart context
24
16
  */
25
17
  y?: Accessor;
26
- /**
27
- * Whether to animate the drawing of the path over time.
28
- * Pass either `true` or an object with transition options to
29
- * enable the transition.
30
- *
31
- * Works best with `tweened` disabled.
32
- */
33
- draw?: boolean | Parameters<typeof _drawTransition>[1];
34
- /**
35
- * Curve of spline drawn. Imported via d3-shape.
36
- *
37
- * @example
38
- * import { curveNatural } from 'd3-shape';
39
- * <Spline curve={curveNatural} />
40
- *
41
- * @type {CurveFactory | CurveFactoryLineOnly | undefined}
42
- */
43
- curve?: CurveFactory | CurveFactoryLineOnly;
44
18
  /**
45
19
  * Function to determine if a point is defined
46
20
  *
@@ -49,55 +23,18 @@ export type SplinePropsWithoutHTML = {
49
23
  */
50
24
  defined?: Parameters<Line<any>['defined']>[0];
51
25
  /**
52
- * Marker to attach to both start and end points of the line
53
- */
54
- marker?: MarkerOptions;
55
- /**
56
- * Marker to attach to the middle point of the line
57
- */
58
- markerMid?: MarkerOptions;
59
- /**
60
- * Marker to attach to the start point of the line
61
- */
62
- markerStart?: MarkerOptions;
63
- /**
64
- * Marker to attach to the end point of the line
65
- */
66
- markerEnd?: MarkerOptions;
67
- /**
68
- * Add additional content at the start of the line.
26
+ * Curve of path drawn. Imported via d3-shape.
69
27
  *
70
- * Receives `{ point: DOMPoint; value: { x: number; y: number } }` as a snippet prop.
71
- */
72
- startContent?: Snippet<[{
73
- point: DOMPoint;
74
- value: {
75
- x: number;
76
- y: number;
77
- };
78
- }]>;
79
- /**
80
- * Add additional content at the end of the line.
81
- *
82
- * Receives `{ point: DOMPoint; value: { x: number; y: number } }` as a snippet prop.
83
- */
84
- endContent?: Snippet<[{
85
- point: DOMPoint;
86
- value: {
87
- x: number;
88
- y: number;
89
- };
90
- }]>;
91
- /**
92
- * A reference to the `<path>` element.
28
+ * @example
29
+ * import { curveNatural } from 'd3-shape';
30
+ * <Path curve={curveNatural} />
93
31
  *
94
- * @bindable
32
+ * @type {CurveFactory | CurveFactoryLineOnly | undefined}
95
33
  */
96
- pathRef?: SVGPathElement;
97
- motion?: MotionProp;
98
- } & CommonStyleProps;
34
+ curve?: CurveFactory | CurveFactoryLineOnly;
35
+ } & Omit<PathProps, 'x' | 'y'>;
99
36
  export type SplineProps = SplinePropsWithoutHTML & Without<SVGAttributes<SVGPathElement>, SplinePropsWithoutHTML>;
100
- import { draw as _drawTransition } from 'svelte/transition';
101
- declare const Spline: import("svelte").Component<SplineProps, {}, "pathRef">;
37
+ import { type PathProps } from './Path.svelte';
38
+ declare const Spline: import("svelte").Component<SplineProps, {}, "">;
102
39
  type Spline = ReturnType<typeof Spline>;
103
40
  export default Spline;