layerchart 2.0.0-next.1 → 2.0.0-next.11

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 (275) hide show
  1. package/dist/actions/movable.d.ts +28 -0
  2. package/dist/actions/movable.js +91 -0
  3. package/dist/components/AnnotationLine.svelte +143 -0
  4. package/dist/components/AnnotationLine.svelte.d.ts +30 -0
  5. package/dist/components/AnnotationPoint.svelte +119 -0
  6. package/dist/components/AnnotationPoint.svelte.d.ts +34 -0
  7. package/dist/components/AnnotationRange.svelte +147 -0
  8. package/dist/components/AnnotationRange.svelte.d.ts +40 -0
  9. package/dist/components/Arc.svelte +344 -151
  10. package/dist/components/Arc.svelte.d.ts +138 -0
  11. package/dist/components/Area.svelte +165 -149
  12. package/dist/components/Area.svelte.d.ts +45 -0
  13. package/dist/components/Axis.svelte +320 -179
  14. package/dist/components/Axis.svelte.d.ts +127 -0
  15. package/dist/components/Bar.svelte +166 -107
  16. package/dist/components/Bar.svelte.d.ts +51 -0
  17. package/dist/components/Bars.svelte +56 -67
  18. package/dist/components/Bars.svelte.d.ts +27 -0
  19. package/dist/components/Blur.svelte +42 -12
  20. package/dist/components/Blur.svelte.d.ts +23 -21
  21. package/dist/components/Bounds.svelte +49 -19
  22. package/dist/components/Bounds.svelte.d.ts +24 -50
  23. package/dist/components/BrushContext.svelte +296 -168
  24. package/dist/components/BrushContext.svelte.d.ts +97 -65
  25. package/dist/components/Calendar.svelte +116 -59
  26. package/dist/components/Calendar.svelte.d.ts +50 -31
  27. package/dist/components/Chart.svelte +1289 -398
  28. package/dist/components/Chart.svelte.d.ts +535 -410
  29. package/dist/components/ChartClipPath.svelte +37 -15
  30. package/dist/components/ChartClipPath.svelte.d.ts +21 -19
  31. package/dist/components/Circle.svelte +124 -85
  32. package/dist/components/Circle.svelte.d.ts +52 -0
  33. package/dist/components/CircleClipPath.svelte +76 -16
  34. package/dist/components/CircleClipPath.svelte.d.ts +46 -0
  35. package/dist/components/ClipPath.svelte +71 -21
  36. package/dist/components/ClipPath.svelte.d.ts +40 -27
  37. package/dist/components/ColorRamp.svelte +75 -9
  38. package/dist/components/ColorRamp.svelte.d.ts +37 -19
  39. package/dist/components/ComputedStyles.svelte +17 -5
  40. package/dist/components/ComputedStyles.svelte.d.ts +11 -19
  41. package/dist/components/Connector.svelte +149 -0
  42. package/dist/components/Connector.svelte.d.ts +51 -0
  43. package/dist/components/Dagre.svelte +211 -122
  44. package/dist/components/Dagre.svelte.d.ts +119 -56
  45. package/dist/components/ForceSimulation.svelte +215 -90
  46. package/dist/components/ForceSimulation.svelte.d.ts +82 -35
  47. package/dist/components/Frame.svelte +33 -13
  48. package/dist/components/Frame.svelte.d.ts +13 -17
  49. package/dist/components/GeoCircle.svelte +29 -16
  50. package/dist/components/GeoCircle.svelte.d.ts +22 -24
  51. package/dist/components/GeoContext.svelte +113 -72
  52. package/dist/components/GeoContext.svelte.d.ts +49 -41
  53. package/dist/components/GeoEdgeFade.svelte +49 -13
  54. package/dist/components/GeoEdgeFade.svelte.d.ts +17 -19
  55. package/dist/components/GeoPath.svelte +157 -127
  56. package/dist/components/GeoPath.svelte.d.ts +48 -36
  57. package/dist/components/GeoPoint.svelte +52 -20
  58. package/dist/components/GeoPoint.svelte.d.ts +25 -22
  59. package/dist/components/GeoSpline.svelte +75 -26
  60. package/dist/components/GeoSpline.svelte.d.ts +29 -20
  61. package/dist/components/GeoTile.svelte +100 -49
  62. package/dist/components/GeoTile.svelte.d.ts +38 -23
  63. package/dist/components/GeoVisible.svelte +17 -9
  64. package/dist/components/GeoVisible.svelte.d.ts +10 -18
  65. package/dist/components/Graticule.svelte +30 -14
  66. package/dist/components/Graticule.svelte.d.ts +11 -52
  67. package/dist/components/Grid.svelte +230 -117
  68. package/dist/components/Grid.svelte.d.ts +71 -0
  69. package/dist/components/Group.svelte +173 -106
  70. package/dist/components/Group.svelte.d.ts +81 -0
  71. package/dist/components/Highlight.svelte +410 -308
  72. package/dist/components/Highlight.svelte.d.ts +107 -0
  73. package/dist/components/Hull.svelte +97 -46
  74. package/dist/components/Hull.svelte.d.ts +40 -30
  75. package/dist/components/Labels.svelte +127 -47
  76. package/dist/components/Labels.svelte.d.ts +70 -27
  77. package/dist/components/Legend.svelte +374 -190
  78. package/dist/components/Legend.svelte.d.ts +95 -44
  79. package/dist/components/Line.svelte +163 -125
  80. package/dist/components/Line.svelte.d.ts +75 -0
  81. package/dist/components/LinearGradient.svelte +153 -78
  82. package/dist/components/LinearGradient.svelte.d.ts +66 -31
  83. package/dist/components/Link.svelte +160 -104
  84. package/dist/components/Link.svelte.d.ts +54 -0
  85. package/dist/components/Marker.svelte +100 -39
  86. package/dist/components/Marker.svelte.d.ts +59 -27
  87. package/dist/components/MarkerWrapper.svelte +35 -0
  88. package/dist/components/MarkerWrapper.svelte.d.ts +18 -0
  89. package/dist/components/MonthPath.svelte +65 -20
  90. package/dist/components/MonthPath.svelte.d.ts +23 -17
  91. package/dist/components/MotionPath.svelte +80 -24
  92. package/dist/components/MotionPath.svelte.d.ts +46 -27
  93. package/dist/components/Pack.svelte +53 -17
  94. package/dist/components/Pack.svelte.d.ts +42 -21
  95. package/dist/components/Partition.svelte +64 -22
  96. package/dist/components/Partition.svelte.d.ts +49 -26
  97. package/dist/components/Pattern.svelte +297 -11
  98. package/dist/components/Pattern.svelte.d.ts +103 -19
  99. package/dist/components/Pie.svelte +122 -76
  100. package/dist/components/Pie.svelte.d.ts +65 -51
  101. package/dist/components/Point.svelte +20 -9
  102. package/dist/components/Point.svelte.d.ts +16 -20
  103. package/dist/components/Points.svelte +148 -137
  104. package/dist/components/Points.svelte.d.ts +45 -34
  105. package/dist/components/RadialGradient.svelte +148 -77
  106. package/dist/components/RadialGradient.svelte.d.ts +69 -31
  107. package/dist/components/Rect.svelte +121 -102
  108. package/dist/components/Rect.svelte.d.ts +36 -0
  109. package/dist/components/RectClipPath.svelte +82 -18
  110. package/dist/components/RectClipPath.svelte.d.ts +55 -0
  111. package/dist/components/Rule.svelte +107 -63
  112. package/dist/components/Rule.svelte.d.ts +40 -19
  113. package/dist/components/Sankey.svelte +132 -55
  114. package/dist/components/Sankey.svelte.d.ts +61 -31
  115. package/dist/components/Spline.svelte +281 -218
  116. package/dist/components/Spline.svelte.d.ts +95 -0
  117. package/dist/components/Text.svelte +463 -197
  118. package/dist/components/Text.svelte.d.ts +136 -0
  119. package/dist/components/Threshold.svelte +48 -16
  120. package/dist/components/Threshold.svelte.d.ts +29 -31
  121. package/dist/components/TileImage.svelte +103 -30
  122. package/dist/components/TileImage.svelte.d.ts +48 -23
  123. package/dist/components/TransformContext.svelte +365 -171
  124. package/dist/components/TransformControls.svelte +50 -26
  125. package/dist/components/TransformControls.svelte.d.ts +27 -19
  126. package/dist/components/Tree.svelte +74 -33
  127. package/dist/components/Tree.svelte.d.ts +42 -30
  128. package/dist/components/Treemap.svelte +119 -42
  129. package/dist/components/Treemap.svelte.d.ts +75 -27
  130. package/dist/components/Voronoi.svelte +153 -103
  131. package/dist/components/Voronoi.svelte.d.ts +42 -41
  132. package/dist/components/charts/ArcChart.svelte +464 -0
  133. package/dist/components/charts/ArcChart.svelte.d.ts +90 -0
  134. package/dist/components/charts/AreaChart.svelte +444 -393
  135. package/dist/components/charts/AreaChart.svelte.d.ts +61 -0
  136. package/dist/components/charts/BarChart.svelte +463 -389
  137. package/dist/components/charts/BarChart.svelte.d.ts +76 -0
  138. package/dist/components/charts/ChartAnnotations.svelte +37 -0
  139. package/dist/components/charts/ChartAnnotations.svelte.d.ts +10 -0
  140. package/dist/components/charts/DefaultTooltip.svelte +60 -0
  141. package/dist/components/charts/DefaultTooltip.svelte.d.ts +10 -0
  142. package/dist/components/charts/LineChart.svelte +366 -315
  143. package/dist/components/charts/LineChart.svelte.d.ts +53 -0
  144. package/dist/components/charts/PieChart.svelte +458 -316
  145. package/dist/components/charts/PieChart.svelte.d.ts +137 -353
  146. package/dist/components/charts/ScatterChart.svelte +332 -296
  147. package/dist/components/charts/ScatterChart.svelte.d.ts +39 -0
  148. package/dist/components/charts/index.d.ts +8 -0
  149. package/dist/components/charts/index.js +7 -0
  150. package/dist/components/charts/types.d.ts +253 -0
  151. package/dist/components/charts/utils.svelte.d.ts +30 -0
  152. package/dist/components/charts/utils.svelte.js +59 -0
  153. package/dist/components/index.d.ts +76 -4
  154. package/dist/components/index.js +76 -5
  155. package/dist/components/layout/Canvas.svelte +347 -171
  156. package/dist/components/layout/Canvas.svelte.d.ts +110 -55
  157. package/dist/components/layout/Html.svelte +82 -42
  158. package/dist/components/layout/Html.svelte.d.ts +39 -28
  159. package/dist/components/layout/Layer.svelte +39 -0
  160. package/dist/components/layout/Layer.svelte.d.ts +17 -0
  161. package/dist/components/layout/Svg.svelte +122 -70
  162. package/dist/components/layout/Svg.svelte.d.ts +53 -34
  163. package/dist/components/layout/WebGL.svelte +135 -0
  164. package/dist/components/layout/WebGL.svelte.d.ts +50 -0
  165. package/dist/components/tooltip/Tooltip.svelte +253 -78
  166. package/dist/components/tooltip/Tooltip.svelte.d.ts +149 -31
  167. package/dist/components/tooltip/TooltipContext.svelte +426 -271
  168. package/dist/components/tooltip/TooltipContext.svelte.d.ts +86 -55
  169. package/dist/components/tooltip/TooltipHeader.svelte +100 -11
  170. package/dist/components/tooltip/TooltipHeader.svelte.d.ts +43 -23
  171. package/dist/components/tooltip/TooltipItem.svelte +167 -27
  172. package/dist/components/tooltip/TooltipItem.svelte.d.ts +63 -31
  173. package/dist/components/tooltip/TooltipList.svelte +22 -3
  174. package/dist/components/tooltip/TooltipList.svelte.d.ts +6 -17
  175. package/dist/components/tooltip/TooltipSeparator.svelte +27 -1
  176. package/dist/components/tooltip/TooltipSeparator.svelte.d.ts +6 -15
  177. package/dist/components/tooltip/index.d.ts +6 -0
  178. package/dist/components/tooltip/index.js +6 -0
  179. package/dist/components/tooltip/tooltipMetaContext.d.ts +79 -0
  180. package/dist/components/tooltip/tooltipMetaContext.js +139 -0
  181. package/dist/components/types.d.ts +1 -0
  182. package/dist/components/types.js +1 -0
  183. package/dist/docs/Blockquote.svelte +3 -1
  184. package/dist/docs/Blockquote.svelte.d.ts +5 -16
  185. package/dist/docs/Code.svelte +20 -12
  186. package/dist/docs/Code.svelte.d.ts +12 -22
  187. package/dist/docs/ConnectorSweepMenuField.svelte +17 -0
  188. package/dist/docs/ConnectorSweepMenuField.svelte.d.ts +7 -0
  189. package/dist/docs/ConnectorTypeMenuField.svelte +17 -0
  190. package/dist/docs/ConnectorTypeMenuField.svelte.d.ts +7 -0
  191. package/dist/docs/CurveMenuField.svelte +14 -3
  192. package/dist/docs/CurveMenuField.svelte.d.ts +9 -18
  193. package/dist/docs/GeoDebug.svelte +47 -42
  194. package/dist/docs/GeoDebug.svelte.d.ts +4 -16
  195. package/dist/docs/Header1.svelte +4 -2
  196. package/dist/docs/Header1.svelte.d.ts +5 -18
  197. package/dist/docs/Json.svelte +11 -3
  198. package/dist/docs/Json.svelte.d.ts +9 -17
  199. package/dist/docs/Layout.svelte +10 -7
  200. package/dist/docs/Layout.svelte.d.ts +5 -15
  201. package/dist/docs/Link.svelte +7 -3
  202. package/dist/docs/Link.svelte.d.ts +5 -27
  203. package/dist/docs/PathDataMenuField.svelte +14 -10
  204. package/dist/docs/PathDataMenuField.svelte.d.ts +8 -18
  205. package/dist/docs/Preview.svelte +20 -7
  206. package/dist/docs/Preview.svelte.d.ts +12 -22
  207. package/dist/docs/TilesetField.svelte +20 -19
  208. package/dist/docs/TilesetField.svelte.d.ts +6 -19
  209. package/dist/docs/TransformDebug.svelte +5 -6
  210. package/dist/docs/TransformDebug.svelte.d.ts +18 -14
  211. package/dist/docs/ViewSourceButton.svelte +7 -4
  212. package/dist/docs/ViewSourceButton.svelte.d.ts +8 -18
  213. package/dist/types/d3-shape-extentions.d.ts +7 -0
  214. package/dist/utils/afterTick.d.ts +5 -0
  215. package/dist/utils/afterTick.js +8 -0
  216. package/dist/utils/arcText.svelte.d.ts +57 -0
  217. package/dist/utils/arcText.svelte.js +262 -0
  218. package/dist/utils/array.d.ts +9 -1
  219. package/dist/utils/array.js +13 -0
  220. package/dist/utils/attributes.d.ts +29 -0
  221. package/dist/utils/attributes.js +40 -0
  222. package/dist/utils/canvas.js +47 -10
  223. package/dist/utils/chart.d.ts +78 -0
  224. package/dist/utils/chart.js +512 -0
  225. package/dist/utils/color.d.ts +1 -0
  226. package/dist/utils/color.js +8 -0
  227. package/dist/utils/common.d.ts +3 -5
  228. package/dist/utils/common.js +3 -2
  229. package/dist/utils/connectorUtils.d.ts +21 -0
  230. package/dist/utils/connectorUtils.js +111 -0
  231. package/dist/utils/createId.d.ts +7 -0
  232. package/dist/utils/createId.js +9 -0
  233. package/dist/utils/debug.d.ts +1 -0
  234. package/dist/utils/debug.js +84 -0
  235. package/dist/utils/filterObject.d.ts +9 -0
  236. package/dist/utils/filterObject.js +12 -0
  237. package/dist/utils/graph/dagre.d.ts +34 -0
  238. package/dist/utils/graph/dagre.js +78 -0
  239. package/dist/utils/graph/dagre.test.d.ts +1 -0
  240. package/dist/utils/{graph.test.js → graph/dagre.test.js} +19 -33
  241. package/dist/utils/graph/sankey.d.ts +28 -0
  242. package/dist/utils/{graph.js → graph/sankey.js} +13 -41
  243. package/dist/utils/index.d.ts +3 -1
  244. package/dist/utils/index.js +3 -1
  245. package/dist/utils/key.svelte.d.ts +3 -0
  246. package/dist/utils/key.svelte.js +11 -0
  247. package/dist/utils/legendPayload.d.ts +7 -0
  248. package/dist/utils/legendPayload.js +8 -0
  249. package/dist/utils/motion.svelte.d.ts +140 -0
  250. package/dist/utils/motion.svelte.js +180 -0
  251. package/dist/utils/motion.test.d.ts +1 -0
  252. package/dist/utils/motion.test.js +213 -0
  253. package/dist/utils/{rect.d.ts → rect.svelte.d.ts} +7 -4
  254. package/dist/utils/rect.svelte.js +105 -0
  255. package/dist/utils/scales.svelte.d.ts +91 -0
  256. package/dist/utils/scales.svelte.js +201 -0
  257. package/dist/utils/stack.d.ts +2 -3
  258. package/dist/utils/stack.js +1 -1
  259. package/dist/utils/string.js +87 -0
  260. package/dist/utils/ticks.d.ts +9 -3
  261. package/dist/utils/ticks.js +122 -147
  262. package/dist/utils/ticks.test.d.ts +1 -0
  263. package/dist/utils/ticks.test.js +57 -0
  264. package/dist/utils/types.d.ts +81 -0
  265. package/package.json +28 -24
  266. package/dist/components/ChartContext.svelte +0 -295
  267. package/dist/components/ChartContext.svelte.d.ts +0 -139
  268. package/dist/components/TransformContext.svelte.d.ts +0 -158
  269. package/dist/stores/motionStore.d.ts +0 -30
  270. package/dist/stores/motionStore.js +0 -62
  271. package/dist/utils/graph.d.ts +0 -37
  272. package/dist/utils/rect.js +0 -107
  273. package/dist/utils/scales.d.ts +0 -66
  274. package/dist/utils/scales.js +0 -136
  275. /package/dist/{utils/graph.test.d.ts → components/charts/types.js} +0 -0
@@ -0,0 +1,140 @@
1
+ import { Spring, Tween } from 'svelte/motion';
2
+ /**
3
+ * Spring motion configuration options
4
+ */
5
+ export type SpringOptions<T = any> = ConstructorParameters<typeof Spring<T>>[1];
6
+ export type SpringSetOptions = Parameters<(typeof Spring)['prototype']['set']>[1];
7
+ /**
8
+ * Tween motion configuration options
9
+ */
10
+ export type TweenOptions<T = any> = ConstructorParameters<typeof Tween<T>>[1];
11
+ export type TweenSetOptions = Parameters<(typeof Tween)['prototype']['set']>[1];
12
+ /**
13
+ * MotionNone is a non-animating state container that provides a compatible
14
+ * interface with Spring and Tween, but updates values immediately without animation.
15
+ * This gives us consistent state management whether animations are enabled or not.
16
+ */
17
+ export type NoneOptions<T = any> = ConstructorParameters<typeof MotionNone<T>>[1];
18
+ export type NoneSetOptions = Parameters<(typeof MotionNone)['prototype']['set']>[1];
19
+ /**
20
+ * Configuration object for Spring animations with additional type discriminator
21
+ */
22
+ export type MotionSpringOption = ({
23
+ type: 'spring';
24
+ } & SpringOptions) | 'spring';
25
+ /**
26
+ * Configuration object for Tween animations with additional type discriminator
27
+ */
28
+ export type MotionTweenOption = ({
29
+ type: 'tween';
30
+ } & TweenOptions) | 'tween';
31
+ /**
32
+ * Configuration object for non-animating state with additional type discriminator
33
+ */
34
+ export type MotionNoneOption = {
35
+ type: 'none';
36
+ } | 'none';
37
+ /**
38
+ * Union type of all possible motion configuration options
39
+ */
40
+ export type MotionOptions = MotionSpringOption | MotionTweenOption | MotionNoneOption;
41
+ type IsDefault<K> = K extends string ? (string extends K ? true : false) : never;
42
+ /**
43
+ * Motion config that can be either a direct motion config or
44
+ * a map of property names to motion configs
45
+ */
46
+ export type MotionProp<K extends string = string> = IsDefault<K> extends true ? MotionOptions : MotionOptions | {
47
+ [prop in K]?: MotionOptions;
48
+ };
49
+ /**
50
+ * Extended Spring class that adds a type discriminator to help with
51
+ * type narrowing in our motion system
52
+ */
53
+ declare class MotionSpring<T = any> extends Spring<T> {
54
+ type: "spring";
55
+ constructor(value: T, options?: SpringOptions<T>);
56
+ }
57
+ /**
58
+ * Extended Tween class that adds a type discriminator to help with
59
+ * type narrowing in our motion system
60
+ */
61
+ declare class MotionTween<T = any> extends Tween<T> {
62
+ type: "tween";
63
+ constructor(value: T, options?: TweenOptions<T>);
64
+ }
65
+ /**
66
+ * MotionNone is a state container that provides the same interface as
67
+ * Spring and Tween but without any animation logic. Values update immediately.
68
+ *
69
+ * This allows components to use a consistent API regardless of whether
70
+ * animations are enabled or not.
71
+ */
72
+ declare class MotionNone<T = any> {
73
+ #private;
74
+ type: "none";
75
+ constructor(value: T, _options?: any);
76
+ /**
77
+ * Updates the value immediately and returns a resolved promise
78
+ * to maintain API compatibility with animated motion classes
79
+ */
80
+ set(value: T, _options?: any): Promise<void>;
81
+ get current(): T;
82
+ get target(): T;
83
+ set target(v: T);
84
+ }
85
+ export type ResolvedTween = {
86
+ type: 'tween';
87
+ options: TweenOptions;
88
+ };
89
+ export type ResolvedSpring = {
90
+ type: 'spring';
91
+ options: SpringOptions;
92
+ };
93
+ export type ResolvedNone = {
94
+ type: 'none';
95
+ options: {};
96
+ };
97
+ /**
98
+ * Union type of all possible resolved motion configurations
99
+ */
100
+ export type ResolvedMotion = ResolvedSpring | ResolvedTween | ResolvedNone;
101
+ /**
102
+ * Internal options for motion state configuration
103
+ */
104
+ type InternalMotionOptions = {
105
+ /**
106
+ * When true, the motion state will only update when explicitly set
107
+ * rather than automatically tracking changes to the source value
108
+ */
109
+ controlled?: boolean;
110
+ };
111
+ export declare function createMotion<T = any>(initialValue: T, getValue: () => T, motionProp: MotionOptions | undefined, options?: InternalMotionOptions): MotionSpring<T> | MotionTween<any> | MotionNone<T>;
112
+ /**
113
+ * Creates a controlled motion state that only updates when explicitly set
114
+ * rather than automatically tracking changes to the source value
115
+ */
116
+ export declare function createControlledMotion<T = any>(initialValue: T, motionProp: MotionOptions | undefined): MotionTween<any> | MotionSpring<T> | MotionNone<T>;
117
+ /**
118
+ * Creates a state tracker for animation completion
119
+ * This helps track whether any motion transitions are currently in progress
120
+ *
121
+ * @returns an object with methods to handle animation promises and check current status
122
+ */
123
+ export declare function createMotionTracker(): {
124
+ handle: (promise: Promise<void> | void) => void;
125
+ readonly current: boolean;
126
+ };
127
+ /**
128
+ * Extracts tween configuration from a motion prop
129
+ * @returns Resolved tween configuration or undefined if not a tween
130
+ */
131
+ export declare function extractTweenConfig<T extends string = never>(prop?: MotionProp<T> | undefined): ResolvedTween | undefined;
132
+ /**
133
+ * Parses and normalizes a motion configuration into a standard format
134
+ *
135
+ * @param config - The motion configuration to parse
136
+ * @param propertyKey - Optional property key when config is a map of properties
137
+ * @returns A standardized motion configuration object
138
+ */
139
+ export declare function parseMotionProp<T extends string = never>(config: MotionProp<T> | undefined | ResolvedMotion, accessor?: string): ResolvedMotion;
140
+ export {};
@@ -0,0 +1,180 @@
1
+ import { Spring, Tween } from 'svelte/motion';
2
+ import { afterTick } from './afterTick.js';
3
+ /**
4
+ * Extended Spring class that adds a type discriminator to help with
5
+ * type narrowing in our motion system
6
+ */
7
+ class MotionSpring extends Spring {
8
+ type = 'spring';
9
+ constructor(value, options) {
10
+ super(value, options);
11
+ }
12
+ }
13
+ /**
14
+ * Extended Tween class that adds a type discriminator to help with
15
+ * type narrowing in our motion system
16
+ */
17
+ class MotionTween extends Tween {
18
+ type = 'tween';
19
+ constructor(value, options) {
20
+ super(value, options);
21
+ }
22
+ }
23
+ /**
24
+ * MotionNone is a state container that provides the same interface as
25
+ * Spring and Tween but without any animation logic. Values update immediately.
26
+ *
27
+ * This allows components to use a consistent API regardless of whether
28
+ * animations are enabled or not.
29
+ */
30
+ class MotionNone {
31
+ type = 'none';
32
+ #current = $state(null);
33
+ #target = $state(null);
34
+ constructor(value, _options = {}) {
35
+ this.#current = value;
36
+ this.#target = value;
37
+ }
38
+ /**
39
+ * Updates the value immediately and returns a resolved promise
40
+ * to maintain API compatibility with animated motion classes
41
+ */
42
+ set(value, _options = {}) {
43
+ this.#current = value;
44
+ this.#target = value;
45
+ return Promise.resolve();
46
+ }
47
+ get current() {
48
+ return this.#current;
49
+ }
50
+ get target() {
51
+ return this.#target;
52
+ }
53
+ set target(v) {
54
+ this.set(v);
55
+ }
56
+ }
57
+ /**
58
+ * Sets up automatic tracking between a source value and a motion state.
59
+ * When the `controlled` option is `true`, the motion state will not update
60
+ * automatically and will only update when explicitly set.
61
+ */
62
+ function setupTracking(motion, getValue, options) {
63
+ if (options.controlled)
64
+ return;
65
+ $effect(() => {
66
+ motion.set(getValue());
67
+ });
68
+ }
69
+ export function createMotion(initialValue, getValue, motionProp, options = {}) {
70
+ const motion = parseMotionProp(motionProp);
71
+ const motionState = motion.type === 'spring'
72
+ ? new MotionSpring(initialValue, motion.options)
73
+ : motion.type === 'tween'
74
+ ? new MotionTween(initialValue, motion.options)
75
+ : new MotionNone(initialValue);
76
+ setupTracking(motionState, getValue, options);
77
+ return motionState;
78
+ }
79
+ /**
80
+ * Creates a controlled motion state that only updates when explicitly set
81
+ * rather than automatically tracking changes to the source value
82
+ */
83
+ export function createControlledMotion(initialValue, motionProp) {
84
+ return createMotion(initialValue, () => initialValue, motionProp, { controlled: true });
85
+ }
86
+ /**
87
+ * Creates a state tracker for animation completion
88
+ * This helps track whether any motion transitions are currently in progress
89
+ *
90
+ * @returns an object with methods to handle animation promises and check current status
91
+ */
92
+ export function createMotionTracker() {
93
+ let latestIndex = 0;
94
+ let current = $state(false);
95
+ function handle(promise) {
96
+ latestIndex += 1;
97
+ if (!promise) {
98
+ current = false;
99
+ return;
100
+ }
101
+ let currIndex = latestIndex;
102
+ current = true;
103
+ promise
104
+ .then(() => {
105
+ if (currIndex === latestIndex) {
106
+ current = false;
107
+ }
108
+ })
109
+ .catch(() => { });
110
+ }
111
+ return {
112
+ handle,
113
+ get current() {
114
+ return current;
115
+ },
116
+ };
117
+ }
118
+ /**
119
+ * Extracts tween configuration from a motion prop
120
+ * @returns Resolved tween configuration or undefined if not a tween
121
+ */
122
+ export function extractTweenConfig(prop) {
123
+ const resolved = parseMotionProp(prop);
124
+ if (resolved.type === 'tween')
125
+ return resolved;
126
+ }
127
+ /**
128
+ * Parses and normalizes a motion configuration into a standard format
129
+ *
130
+ * @param config - The motion configuration to parse
131
+ * @param propertyKey - Optional property key when config is a map of properties
132
+ * @returns A standardized motion configuration object
133
+ */
134
+ export function parseMotionProp(config, accessor) {
135
+ if (typeof config === 'object' && 'type' in config && 'options' in config) {
136
+ if (typeof config.options === 'object')
137
+ return config;
138
+ return { type: config.type, options: {} };
139
+ }
140
+ // Default to no animation if no configuration provided
141
+ if (config === undefined)
142
+ return { type: 'none', options: {} };
143
+ // Case 1: string shorthand ('spring', 'tween', 'none')
144
+ if (typeof config === 'string') {
145
+ if (config === 'spring') {
146
+ return { type: 'spring', options: {} };
147
+ }
148
+ else if (config === 'tween') {
149
+ return { type: 'tween', options: {} };
150
+ }
151
+ return { type: 'none', options: {} };
152
+ }
153
+ // Case 2: Object with explicit type property
154
+ if (typeof config === 'object' && 'type' in config) {
155
+ if (config.type === 'spring') {
156
+ const { type, ...options } = config;
157
+ return { type: 'spring', options };
158
+ }
159
+ else if (config.type === 'tween') {
160
+ const { type, ...options } = config;
161
+ return { type: 'tween', options };
162
+ }
163
+ else {
164
+ return { type: 'none', options: {} };
165
+ }
166
+ }
167
+ // Case 3: Property map object, lookup by property key
168
+ // We've already established config is an object at this point
169
+ if (accessor) {
170
+ const propConfig = config[accessor];
171
+ if (propConfig !== undefined) {
172
+ return parseMotionProp(propConfig);
173
+ }
174
+ }
175
+ // Fallback to no animation
176
+ return {
177
+ type: 'none',
178
+ options: {},
179
+ };
180
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,213 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { parseMotionProp, extractTweenConfig } from './motion.svelte.js';
3
+ describe('parseMotionProp', () => {
4
+ it('should return "none" type when config is undefined', () => {
5
+ const result = parseMotionProp(undefined);
6
+ expect(result).toEqual({ type: 'none', options: {} });
7
+ });
8
+ it('should return an already resolved motion object that may have been parsed earlier in the chain', () => {
9
+ const resolvedMotion = {
10
+ type: 'spring',
11
+ options: {
12
+ stiffness: 0.5,
13
+ damping: 0.8,
14
+ },
15
+ };
16
+ const result = parseMotionProp(resolvedMotion);
17
+ expect(result).toEqual(resolvedMotion);
18
+ });
19
+ describe('string input handling', () => {
20
+ it('should handle "spring" string shorthand', () => {
21
+ const result = parseMotionProp('spring');
22
+ expect(result).toEqual({ type: 'spring', options: {} });
23
+ });
24
+ it('should handle "tween" string shorthand', () => {
25
+ const result = parseMotionProp('tween');
26
+ expect(result).toEqual({ type: 'tween', options: {} });
27
+ });
28
+ it('should handle "none" string shorthand', () => {
29
+ const result = parseMotionProp('none');
30
+ expect(result).toEqual({ type: 'none', options: {} });
31
+ });
32
+ it('should default to "none" for invalid string values', () => {
33
+ const result = parseMotionProp('invalid');
34
+ expect(result).toEqual({ type: 'none', options: {} });
35
+ });
36
+ });
37
+ describe('object with type property', () => {
38
+ it('should handle spring object with options', () => {
39
+ const springConfig = {
40
+ type: 'spring',
41
+ stiffness: 0.5,
42
+ damping: 0.8,
43
+ };
44
+ const result = parseMotionProp(springConfig);
45
+ expect(result).toEqual({
46
+ type: 'spring',
47
+ options: { stiffness: 0.5, damping: 0.8 },
48
+ });
49
+ });
50
+ it('should handle tween object with options', () => {
51
+ const tweenConfig = {
52
+ type: 'tween',
53
+ duration: 300,
54
+ easing: (t) => t,
55
+ };
56
+ const result = parseMotionProp(tweenConfig);
57
+ expect(result).toEqual({
58
+ type: 'tween',
59
+ options: { duration: 300, easing: expect.any(Function) },
60
+ });
61
+ });
62
+ it('should handle none object', () => {
63
+ const noneConfig = {
64
+ type: 'none',
65
+ };
66
+ const result = parseMotionProp(noneConfig);
67
+ expect(result).toEqual({ type: 'none', options: {} });
68
+ });
69
+ });
70
+ describe('property map object with accessor', () => {
71
+ it('should extract a specific property motion config', () => {
72
+ const propMap = {
73
+ x: 'spring',
74
+ y: { type: 'tween', duration: 300 },
75
+ scale: { type: 'spring', stiffness: 0.2 },
76
+ };
77
+ const resultX = parseMotionProp(propMap, 'x');
78
+ expect(resultX).toEqual({ type: 'spring', options: {} });
79
+ const resultY = parseMotionProp(propMap, 'y');
80
+ expect(resultY).toEqual({ type: 'tween', options: { duration: 300 } });
81
+ const resultScale = parseMotionProp(propMap, 'scale');
82
+ expect(resultScale).toEqual({ type: 'spring', options: { stiffness: 0.2 } });
83
+ });
84
+ it('should return "none" type for non-existent accessor', () => {
85
+ const propMap = {
86
+ x: 'spring',
87
+ y: 'tween',
88
+ };
89
+ const result = parseMotionProp(propMap, 'z');
90
+ expect(result).toEqual({ type: 'none', options: {} });
91
+ });
92
+ });
93
+ describe('edge cases', () => {
94
+ it('should handle empty object as "none"', () => {
95
+ const result = parseMotionProp({});
96
+ expect(result).toEqual({ type: 'none', options: {} });
97
+ });
98
+ it('should handle object without type property', () => {
99
+ const invalidObject = {
100
+ stiffness: 0.5,
101
+ damping: 0.8,
102
+ };
103
+ const result = parseMotionProp(invalidObject);
104
+ expect(result).toEqual({ type: 'none', options: {} });
105
+ });
106
+ });
107
+ // Test case 6: Type Generic
108
+ describe('type generic parameter', () => {
109
+ it('should work with explicit generic type parameter', () => {
110
+ const propMap = {
111
+ x: 'spring',
112
+ y: 'tween',
113
+ scale: { type: 'spring', stiffness: 0.3 },
114
+ };
115
+ const result = parseMotionProp(propMap, 'x');
116
+ expect(result).toEqual({ type: 'spring', options: {} });
117
+ });
118
+ });
119
+ });
120
+ describe('extractTweenConfig', () => {
121
+ // Test case 1: Undefined input
122
+ it('should return undefined when config is undefined', () => {
123
+ const result = extractTweenConfig(undefined);
124
+ expect(result).toBeUndefined();
125
+ });
126
+ // Test case 2: String inputs
127
+ describe('string input handling', () => {
128
+ it('should extract tween config from "tween" string shorthand', () => {
129
+ const result = extractTweenConfig('tween');
130
+ expect(result).toEqual({ type: 'tween', options: {} });
131
+ });
132
+ it('should return undefined for "spring" string shorthand', () => {
133
+ const result = extractTweenConfig('spring');
134
+ expect(result).toBeUndefined();
135
+ });
136
+ it('should return undefined for "none" string shorthand', () => {
137
+ const result = extractTweenConfig('none');
138
+ expect(result).toBeUndefined();
139
+ });
140
+ });
141
+ // Test case 3: Object with type property
142
+ describe('object with type property', () => {
143
+ it('should extract tween object with options', () => {
144
+ const tweenConfig = {
145
+ type: 'tween',
146
+ duration: 300,
147
+ easing: (t) => t,
148
+ };
149
+ const result = extractTweenConfig(tweenConfig);
150
+ expect(result).toEqual({
151
+ type: 'tween',
152
+ options: { duration: 300, easing: expect.any(Function) },
153
+ });
154
+ });
155
+ it('should return undefined for spring object', () => {
156
+ const springConfig = {
157
+ type: 'spring',
158
+ stiffness: 0.5,
159
+ damping: 0.8,
160
+ };
161
+ const result = extractTweenConfig(springConfig);
162
+ expect(result).toBeUndefined();
163
+ });
164
+ it('should return undefined for none object', () => {
165
+ const noneConfig = {
166
+ type: 'none',
167
+ };
168
+ const result = extractTweenConfig(noneConfig);
169
+ expect(result).toBeUndefined();
170
+ });
171
+ });
172
+ // Test case 4: Property map object (without accessor)
173
+ describe('property map object without accessor', () => {
174
+ it('should return undefined for property map objects without accessor', () => {
175
+ const propMap = {
176
+ x: 'tween',
177
+ y: { type: 'tween', duration: 300 },
178
+ scale: { type: 'spring', stiffness: 0.2 },
179
+ };
180
+ const result = extractTweenConfig(propMap);
181
+ expect(result).toBeUndefined();
182
+ });
183
+ });
184
+ // Test case 6: Edge cases
185
+ describe('edge cases', () => {
186
+ it('should handle empty object', () => {
187
+ const result = extractTweenConfig({});
188
+ expect(result).toBeUndefined();
189
+ });
190
+ it('should handle object without type property', () => {
191
+ const invalidObject = {
192
+ duration: 300,
193
+ easing: (t) => t,
194
+ };
195
+ const result = extractTweenConfig(invalidObject);
196
+ expect(result).toBeUndefined();
197
+ });
198
+ });
199
+ describe('with generic type parameter', () => {
200
+ it('should work with explicit generic type parameter', () => {
201
+ const propMap = {
202
+ x: 'tween',
203
+ y: { type: 'tween', duration: 400 },
204
+ scale: 'spring',
205
+ };
206
+ // The extractTweenConfig function doesn't directly support accessors,
207
+ // so for this case we manually extract the property first
208
+ const xConfig = propMap.x;
209
+ const result = extractTweenConfig(xConfig);
210
+ expect(result).toEqual({ type: 'tween', options: {} });
211
+ });
212
+ });
213
+ });
@@ -1,6 +1,9 @@
1
- import type { ChartContext } from '../components/ChartContext.svelte';
1
+ import type { ChartContextValue } from '../components/Chart.svelte';
2
2
  import { type Accessor } from './common.js';
3
- /** A set of inset distances, applied to a rectangle to shrink or expand the area represented by that rectangle. */
3
+ /**
4
+ * A set of inset distances, applied to a rectangle to shrink or expand
5
+ * the area represented by that rectangle.
6
+ */
4
7
  export type Insets = {
5
8
  /** Applies an inset all sides of a rectangle: `left`, `right`, `bottom`, and `top` */
6
9
  all?: number;
@@ -28,12 +31,12 @@ type DimensionGetterOptions = {
28
31
  y1?: Accessor;
29
32
  insets?: Insets;
30
33
  };
31
- export declare function createDimensionGetter<TData>(context: ChartContext<TData>, options?: DimensionGetterOptions): import("svelte/store").Readable<(item: any) => {
34
+ export declare function createDimensionGetter<TData>(ctx: ChartContextValue<TData>, getOptions?: () => DimensionGetterOptions): (item: TData) => {
32
35
  x: any;
33
36
  y: any;
34
37
  width: number;
35
38
  height: number;
36
- }>;
39
+ };
37
40
  /**
38
41
  * If value is an array, returns first item, else returns original value
39
42
  * Useful when x/y getters for band scale are an array (such as for histograms)
@@ -0,0 +1,105 @@
1
+ import { accessor } from './common.js';
2
+ import { isScaleBand } from './scales.svelte.js';
3
+ import { max, min } from 'd3-array';
4
+ function resolveInsets(insets) {
5
+ const all = insets?.all ?? 0;
6
+ const x = insets?.x ?? all;
7
+ const y = insets?.y ?? all;
8
+ const left = insets?.left ?? x;
9
+ const right = insets?.right ?? x;
10
+ const top = insets?.top ?? y;
11
+ const bottom = insets?.bottom ?? y;
12
+ return { left, right, bottom, top };
13
+ }
14
+ export function createDimensionGetter(ctx, getOptions) {
15
+ const options = $derived(getOptions?.());
16
+ return (item) => {
17
+ const insets = resolveInsets(options?.insets);
18
+ // Use `xscale.domain()` instead of `$xDomain` to include `nice()` being applied
19
+ const xDomainMinMax = ctx.xScale.domain();
20
+ const yDomainMinMax = ctx.yScale.domain();
21
+ const _x = accessor(options?.x ?? ctx.x);
22
+ const _y = accessor(options?.y ?? ctx.y);
23
+ const _x1 = accessor(options?.x1 ?? ctx.x1);
24
+ const _y1 = accessor(options?.y1 ?? ctx.y1);
25
+ if (isScaleBand(ctx.yScale)) {
26
+ // Horizontal band
27
+ const y = firstValue(ctx.yScale(_y(item)) ?? 0) +
28
+ (ctx.y1Scale ? ctx.y1Scale(_y1(item)) : 0) +
29
+ insets.top;
30
+ const height = Math.max(0, ctx.yScale.bandwidth
31
+ ? (ctx.y1Scale ? (ctx.y1Scale.bandwidth?.() ?? 0) : ctx.yScale.bandwidth()) -
32
+ insets.bottom -
33
+ insets.top
34
+ : 0);
35
+ const xValue = _x(item);
36
+ let left = 0;
37
+ let right = 0;
38
+ if (Array.isArray(xValue)) {
39
+ // Array contains both top and bottom values (stack, etc);
40
+ left = min(xValue);
41
+ right = max(xValue);
42
+ }
43
+ else if (xValue == null) {
44
+ // null/undefined value
45
+ left = 0;
46
+ right = 0;
47
+ }
48
+ else if (xValue > 0) {
49
+ // Positive value
50
+ left = max([0, xDomainMinMax[0]]);
51
+ right = xValue;
52
+ }
53
+ else {
54
+ // Negative value
55
+ left = xValue;
56
+ right = min([0, xDomainMinMax[1]]);
57
+ }
58
+ const x = ctx.xScale(left) + insets.left;
59
+ const width = Math.max(0, ctx.xScale(right) - ctx.xScale(left) - insets.left - insets.right);
60
+ return { x, y, width, height };
61
+ }
62
+ else {
63
+ // Vertical band or linear
64
+ const x = firstValue(ctx.xScale(_x(item))) + (ctx.x1Scale ? ctx.x1Scale(_x1(item)) : 0) + insets.left;
65
+ const width = Math.max(0, ctx.xScale.bandwidth
66
+ ? (ctx.x1Scale ? (ctx.x1Scale.bandwidth?.() ?? 0) : ctx.xScale.bandwidth()) -
67
+ insets.left -
68
+ insets.right
69
+ : 0);
70
+ const yValue = _y(item);
71
+ let top = 0;
72
+ let bottom = 0;
73
+ if (Array.isArray(yValue)) {
74
+ // Array contains both top and bottom values (stack, etc);
75
+ top = max(yValue);
76
+ bottom = min(yValue);
77
+ }
78
+ else if (yValue == null) {
79
+ // null/undefined value
80
+ top = 0;
81
+ bottom = 0;
82
+ }
83
+ else if (yValue > 0) {
84
+ // Positive value
85
+ top = yValue;
86
+ bottom = max([0, yDomainMinMax[0]]);
87
+ }
88
+ else {
89
+ // Negative value
90
+ top = min([0, yDomainMinMax[1]]);
91
+ bottom = yValue;
92
+ }
93
+ const y = ctx.yScale(top) + insets.top;
94
+ const height = ctx.yScale(bottom) - ctx.yScale(top) - insets.bottom - insets.top;
95
+ return { x, y, width, height };
96
+ }
97
+ };
98
+ }
99
+ /**
100
+ * If value is an array, returns first item, else returns original value
101
+ * Useful when x/y getters for band scale are an array (such as for histograms)
102
+ */
103
+ export function firstValue(value) {
104
+ return Array.isArray(value) ? value[0] : value;
105
+ }