layerchart 2.0.0-next.0 → 2.0.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) 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 +155 -0
  4. package/dist/components/AnnotationLine.svelte.d.ts +28 -0
  5. package/dist/components/AnnotationPoint.svelte +121 -0
  6. package/dist/components/AnnotationPoint.svelte.d.ts +32 -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 +287 -174
  14. package/dist/components/Axis.svelte.d.ts +116 -0
  15. package/dist/components/Bar.svelte +163 -107
  16. package/dist/components/Bar.svelte.d.ts +48 -0
  17. package/dist/components/Bars.svelte +54 -68
  18. package/dist/components/Bars.svelte.d.ts +27 -0
  19. package/dist/components/Blur.svelte +31 -7
  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 +60 -15
  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 +47 -12
  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 +28 -13
  66. package/dist/components/Graticule.svelte.d.ts +11 -52
  67. package/dist/components/Grid.svelte +226 -114
  68. package/dist/components/Grid.svelte.d.ts +70 -0
  69. package/dist/components/Group.svelte +132 -105
  70. package/dist/components/Group.svelte.d.ts +53 -0
  71. package/dist/components/Highlight.svelte +409 -307
  72. package/dist/components/Highlight.svelte.d.ts +107 -0
  73. package/dist/components/Hull.svelte +96 -45
  74. package/dist/components/Hull.svelte.d.ts +40 -30
  75. package/dist/components/Labels.svelte +125 -46
  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 +143 -70
  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 +105 -62
  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 +437 -176
  118. package/dist/components/Text.svelte.d.ts +130 -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 +106 -75
  131. package/dist/components/Voronoi.svelte.d.ts +40 -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 +450 -393
  135. package/dist/components/charts/AreaChart.svelte.d.ts +61 -0
  136. package/dist/components/charts/BarChart.svelte +454 -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 +369 -314
  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 +334 -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 +55 -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 +321 -155
  156. package/dist/components/layout/Canvas.svelte.d.ts +104 -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 +246 -78
  166. package/dist/components/tooltip/Tooltip.svelte.d.ts +149 -31
  167. package/dist/components/tooltip/TooltipContext.svelte +409 -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.d.ts +18 -14
  184. package/dist/docs/Code.svelte.d.ts +26 -22
  185. package/dist/docs/ConnectorSweepMenuField.svelte +17 -0
  186. package/dist/docs/ConnectorSweepMenuField.svelte.d.ts +7 -0
  187. package/dist/docs/ConnectorTypeMenuField.svelte +17 -0
  188. package/dist/docs/ConnectorTypeMenuField.svelte.d.ts +7 -0
  189. package/dist/docs/CurveMenuField.svelte +14 -3
  190. package/dist/docs/CurveMenuField.svelte.d.ts +9 -18
  191. package/dist/docs/GeoDebug.svelte +47 -42
  192. package/dist/docs/GeoDebug.svelte.d.ts +4 -16
  193. package/dist/docs/Header1.svelte.d.ts +27 -16
  194. package/dist/docs/Json.svelte.d.ts +20 -16
  195. package/dist/docs/Layout.svelte.d.ts +18 -13
  196. package/dist/docs/Link.svelte.d.ts +33 -21
  197. package/dist/docs/PathDataMenuField.svelte +14 -10
  198. package/dist/docs/PathDataMenuField.svelte.d.ts +8 -18
  199. package/dist/docs/Preview.svelte +20 -7
  200. package/dist/docs/Preview.svelte.d.ts +12 -22
  201. package/dist/docs/TilesetField.svelte.d.ts +21 -17
  202. package/dist/docs/TransformDebug.svelte +5 -6
  203. package/dist/docs/TransformDebug.svelte.d.ts +18 -14
  204. package/dist/docs/ViewSourceButton.svelte.d.ts +21 -17
  205. package/dist/types/d3-shape-extentions.d.ts +7 -0
  206. package/dist/utils/afterTick.d.ts +5 -0
  207. package/dist/utils/afterTick.js +8 -0
  208. package/dist/utils/arcText.svelte.d.ts +57 -0
  209. package/dist/utils/arcText.svelte.js +262 -0
  210. package/dist/utils/array.d.ts +9 -1
  211. package/dist/utils/array.js +13 -0
  212. package/dist/utils/attributes.d.ts +29 -0
  213. package/dist/utils/attributes.js +40 -0
  214. package/dist/utils/canvas.js +47 -10
  215. package/dist/utils/chart.d.ts +78 -0
  216. package/dist/utils/chart.js +512 -0
  217. package/dist/utils/color.d.ts +1 -0
  218. package/dist/utils/color.js +8 -0
  219. package/dist/utils/common.d.ts +3 -5
  220. package/dist/utils/common.js +3 -2
  221. package/dist/utils/connectorUtils.d.ts +21 -0
  222. package/dist/utils/connectorUtils.js +111 -0
  223. package/dist/utils/createId.d.ts +7 -0
  224. package/dist/utils/createId.js +9 -0
  225. package/dist/utils/debug.d.ts +1 -0
  226. package/dist/utils/debug.js +84 -0
  227. package/dist/utils/filterObject.d.ts +9 -0
  228. package/dist/utils/filterObject.js +12 -0
  229. package/dist/utils/graph/dagre.d.ts +34 -0
  230. package/dist/utils/graph/dagre.js +78 -0
  231. package/dist/utils/graph/dagre.test.d.ts +1 -0
  232. package/dist/utils/{graph.test.js → graph/dagre.test.js} +19 -33
  233. package/dist/utils/graph/sankey.d.ts +28 -0
  234. package/dist/utils/{graph.js → graph/sankey.js} +13 -41
  235. package/dist/utils/index.d.ts +3 -1
  236. package/dist/utils/index.js +3 -1
  237. package/dist/utils/key.svelte.d.ts +3 -0
  238. package/dist/utils/key.svelte.js +11 -0
  239. package/dist/utils/legendPayload.d.ts +7 -0
  240. package/dist/utils/legendPayload.js +8 -0
  241. package/dist/utils/motion.svelte.d.ts +140 -0
  242. package/dist/utils/motion.svelte.js +180 -0
  243. package/dist/utils/motion.test.d.ts +1 -0
  244. package/dist/utils/motion.test.js +213 -0
  245. package/dist/utils/{rect.d.ts → rect.svelte.d.ts} +7 -4
  246. package/dist/utils/rect.svelte.js +105 -0
  247. package/dist/utils/scales.svelte.d.ts +90 -0
  248. package/dist/utils/{scales.js → scales.svelte.js} +100 -39
  249. package/dist/utils/stack.d.ts +2 -3
  250. package/dist/utils/stack.js +1 -1
  251. package/dist/utils/string.js +87 -0
  252. package/dist/utils/ticks.d.ts +8 -2
  253. package/dist/utils/ticks.js +28 -0
  254. package/dist/utils/ticks.test.d.ts +1 -0
  255. package/dist/utils/ticks.test.js +67 -0
  256. package/dist/utils/types.d.ts +81 -0
  257. package/package.json +25 -24
  258. package/dist/components/ChartContext.svelte +0 -295
  259. package/dist/components/ChartContext.svelte.d.ts +0 -139
  260. package/dist/components/TransformContext.svelte.d.ts +0 -158
  261. package/dist/stores/motionStore.d.ts +0 -30
  262. package/dist/stores/motionStore.js +0 -62
  263. package/dist/utils/graph.d.ts +0 -37
  264. package/dist/utils/rect.js +0 -107
  265. package/dist/utils/scales.d.ts +0 -66
  266. /package/dist/{utils/graph.test.d.ts → components/charts/types.js} +0 -0
@@ -0,0 +1,54 @@
1
+ import type { MarkerOptions } from './MarkerWrapper.svelte';
2
+ import type { Without } from '../utils/types.js';
3
+ import type { MotionNoneOption, MotionTweenOption } from '../utils/motion.svelte.js';
4
+ import { type CurveFactory } from 'd3-shape';
5
+ export type LinkPropsWithoutHTML = {
6
+ data?: any;
7
+ /**
8
+ * Update source and target accessors to be compatible with d3-sankey. see: https://github.com/d3/d3-sankey#sankeyLinkHorizontal
9
+ *
10
+ * @default false
11
+ */
12
+ sankey?: boolean;
13
+ source?: (d: any) => any;
14
+ target?: (d: any) => any;
15
+ /**
16
+ * Convenient property to swap x/y accessor logic
17
+ */
18
+ orientation?: 'vertical' | 'horizontal';
19
+ x?: (d: any) => any;
20
+ y?: (d: any) => any;
21
+ curve?: CurveFactory;
22
+ /**
23
+ * Marker to attach to both start and end points of the line
24
+ */
25
+ marker?: MarkerOptions;
26
+ /**
27
+ * Marker to attach to the middle point of the line
28
+ */
29
+ markerMid?: MarkerOptions;
30
+ /**
31
+ * Marker to attach to the start point of the line
32
+ */
33
+ markerStart?: MarkerOptions;
34
+ /**
35
+ * Marker to attach to the end point of the line
36
+ */
37
+ markerEnd?: MarkerOptions;
38
+ /**
39
+ * Apply explicit coordinates to the line. Useful when dealing with
40
+ * force simulation links.
41
+ */
42
+ explicitCoords?: {
43
+ x1: number;
44
+ y1: number;
45
+ x2: number;
46
+ y2: number;
47
+ };
48
+ motion?: MotionTweenOption | MotionNoneOption;
49
+ };
50
+ export type LinkProps = LinkPropsWithoutHTML & Without<ConnectorProps, LinkPropsWithoutHTML>;
51
+ import { type ConnectorProps } from './Connector.svelte';
52
+ declare const Link: import("svelte").Component<LinkProps, {}, "">;
53
+ type Link = ReturnType<typeof Link>;
54
+ export default Link;
@@ -1,37 +1,97 @@
1
- <script lang="ts">
2
- import { cls } from '@layerstack/tailwind';
3
- import { uniqueId } from '@layerstack/utils';
1
+ <script lang="ts" module>
2
+ import type { Without } from '../utils/types.js';
3
+ import type { SVGAttributes } from 'svelte/elements';
4
+
5
+ export type MarkerPropsWithoutHTML = {
6
+ /**
7
+ * The type of marker to render (e.g., arrow, triangle, etc.)
8
+ *
9
+ * Pass `children` to render a custom element/component inside the marker instead.
10
+ */
11
+ type?: 'arrow' | 'triangle' | 'line' | 'circle' | 'circle-stroke' | 'dot';
12
+
13
+ /**
14
+ * Unique identifier for the marker
15
+ */
16
+ id?: string;
17
+
18
+ /**
19
+ * Size of the marker
20
+ * (used as default for width and height if not overridden)
21
+ * @default 10
22
+ */
23
+ size?: number;
4
24
 
5
- /** Defined the type of a default marker, or define your own in the slot */
6
- export let type: 'arrow' | 'triangle' | 'line' | 'circle' | 'circle-stroke' | 'dot' | undefined =
7
- undefined;
25
+ /**
26
+ * Width of the marker (can be a string or number)
27
+ * @default size
28
+ */
29
+ markerWidth?: string | number;
8
30
 
9
- /** Unique id for marker */
10
- export let id: string = uniqueId('marker-');
31
+ /**
32
+ * Height of the marker (can be a string or number)
33
+ * @default size
34
+ */
35
+ markerHeight?: string | number;
11
36
 
12
- /** A number used to determine the size of the bounding box the marker content. */
13
- export let size = 10;
37
+ /**
38
+ * Units for marker dimensions ('userSpaceOnUse' or 'strokeWidth')
39
+ * @default 'userSpaceOnUse'
40
+ */
41
+ markerUnits?: 'userSpaceOnUse' | 'strokeWidth';
14
42
 
15
- /** The width of the marker viewport */
16
- export let markerWidth: string | number = size;
43
+ /**
44
+ * Orientation of the marker
45
+ * ('auto', 'auto-start-reverse', or a specific angle in degrees)
46
+ * @default 'auto-start-reverse'
47
+ */
48
+ orient?: 'auto' | 'auto-start-reverse' | number;
17
49
 
18
- /** The height of the marker viewport */
19
- export let markerHeight: string | number = size;
50
+ /**
51
+ * X-coordinate offset of the marker's reference point
52
+ * @default 9 if type is 'arrow' or 'triangle', otherwise 5
53
+ */
54
+ refX?: string | number;
20
55
 
21
- /** Set the coordinate system for the markerWidth, markerHeight, and `<marker>` contents */
22
- export let markerUnits: 'userSpaceOnUse' | 'strokeWidth' = 'userSpaceOnUse';
56
+ /**
57
+ * Y-coordinate offset of the marker's reference point
58
+ * @default 5
59
+ */
60
+ refY?: string | number;
23
61
 
24
- /** The orientation of the marker relative to the shape it is attached to */
25
- export let orient: 'auto' | 'auto-start-reverse' | number = 'auto-start-reverse';
62
+ /**
63
+ * Viewbox defining the coordinate system for the marker (e.g., '0 0 10 10')
64
+ * @default '0 0 10 10'
65
+ */
66
+ viewBox?: string;
67
+ };
26
68
 
27
- /** The x coordinate for the reference point of the marker */
28
- export let refX: string | number = ['arrow', 'triangle'].includes(type ?? '') ? 9 : 5;
69
+ export type MarkerProps = MarkerPropsWithoutHTML &
70
+ Without<SVGAttributes<SVGMarkerElement>, MarkerPropsWithoutHTML>;
71
+ </script>
72
+
73
+ <script lang="ts">
74
+ import { cls } from '@layerstack/tailwind';
75
+ import { createId } from '../utils/createId.js';
76
+ import { layerClass } from '../utils/attributes.js';
29
77
 
30
- /** The y coordinate for the reference point of the maker */
31
- export let refY: string | number = 5;
78
+ const uid = $props.id();
32
79
 
33
- /** The bound of the SVG viewport for the current SVG fragment */
34
- export let viewBox = '0 0 10 10';
80
+ let {
81
+ type,
82
+ id = createId('marker-', uid),
83
+ size = 10,
84
+ markerWidth = size,
85
+ markerHeight = size,
86
+ markerUnits = 'userSpaceOnUse',
87
+ orient = 'auto-start-reverse',
88
+ refX = ['arrow', 'triangle'].includes(type ?? '') ? 9 : 5,
89
+ refY = 5,
90
+ viewBox = '0 0 10 10',
91
+ class: className,
92
+ children,
93
+ ...restProps
94
+ }: MarkerProps = $props();
35
95
  </script>
36
96
 
37
97
  <defs>
@@ -44,11 +104,12 @@
44
104
  {refX}
45
105
  {refY}
46
106
  {viewBox}
47
- {...$$restProps}
107
+ {...restProps}
48
108
  class={cls(
109
+ layerClass('marker'),
49
110
  'overflow-visible',
50
111
  // stroke
51
- $$props.stroke == null &&
112
+ restProps.stroke == null &&
52
113
  (['arrow', 'circle-stroke', 'line'].includes(type ?? '')
53
114
  ? 'stroke-[context-stroke]'
54
115
  : type === 'circle'
@@ -57,25 +118,25 @@
57
118
  // extra stroke attrs
58
119
  '[stroke-linecap:round] [stroke-linejoin:round]',
59
120
  //fill
60
- $$props.fill == null &&
121
+ restProps.fill == null &&
61
122
  (['triangle', 'dot', 'circle'].includes(type ?? '')
62
123
  ? 'fill-[context-stroke]'
63
124
  : type === 'circle-stroke'
64
125
  ? 'fill-surface-100'
65
126
  : 'fill-none'),
66
- $$props.class
127
+ className
67
128
  )}
68
129
  >
69
- <slot>
70
- {#if type === 'triangle'}
71
- <path d="M 0 0 L 10 5 L 0 10 z" />
72
- {:else if type === 'arrow'}
73
- <polyline points="0 0, 10 5, 0 10" />
74
- {:else if type === 'circle' || type === 'circle-stroke' || type === 'dot'}
75
- <circle cx={5} cy={5} r={5} />
76
- {:else if type === 'line'}
77
- <polyline points="5 0, 5 10" />
78
- {/if}
79
- </slot>
130
+ {#if children}
131
+ {@render children()}
132
+ {:else if type === 'triangle'}
133
+ <path d="M 0 0 L 10 5 L 0 10 z" class={layerClass('marker-triangle')} />
134
+ {:else if type === 'arrow'}
135
+ <polyline points="0 0, 10 5, 0 10" class={layerClass('marker-arrow')} />
136
+ {:else if type === 'circle' || type === 'circle-stroke' || type === 'dot'}
137
+ <circle cx={5} cy={5} r={5} class={layerClass('marker-circle')} />
138
+ {:else if type === 'line'}
139
+ <polyline points="5 0, 5 10" class={layerClass('marker-line')} />
140
+ {/if}
80
141
  </marker>
81
142
  </defs>
@@ -1,28 +1,60 @@
1
- import { SvelteComponentTyped } from "svelte";
2
- declare const __propDef: {
3
- props: {
4
- [x: string]: any;
5
- type?: "arrow" | "triangle" | "line" | "circle" | "circle-stroke" | "dot" | undefined | undefined;
6
- id?: string | undefined;
7
- size?: number | undefined;
8
- markerWidth?: string | number | undefined;
9
- markerHeight?: string | number | undefined;
10
- markerUnits?: "userSpaceOnUse" | "strokeWidth" | undefined;
11
- orient?: "auto" | "auto-start-reverse" | number | undefined;
12
- refX?: string | number | undefined;
13
- refY?: string | number | undefined;
14
- viewBox?: string | undefined;
15
- };
16
- events: {
17
- [evt: string]: CustomEvent<any>;
18
- };
19
- slots: {
20
- default: {};
21
- };
1
+ import type { Without } from '../utils/types.js';
2
+ import type { SVGAttributes } from 'svelte/elements';
3
+ export type MarkerPropsWithoutHTML = {
4
+ /**
5
+ * The type of marker to render (e.g., arrow, triangle, etc.)
6
+ *
7
+ * Pass `children` to render a custom element/component inside the marker instead.
8
+ */
9
+ type?: 'arrow' | 'triangle' | 'line' | 'circle' | 'circle-stroke' | 'dot';
10
+ /**
11
+ * Unique identifier for the marker
12
+ */
13
+ id?: string;
14
+ /**
15
+ * Size of the marker
16
+ * (used as default for width and height if not overridden)
17
+ * @default 10
18
+ */
19
+ size?: number;
20
+ /**
21
+ * Width of the marker (can be a string or number)
22
+ * @default size
23
+ */
24
+ markerWidth?: string | number;
25
+ /**
26
+ * Height of the marker (can be a string or number)
27
+ * @default size
28
+ */
29
+ markerHeight?: string | number;
30
+ /**
31
+ * Units for marker dimensions ('userSpaceOnUse' or 'strokeWidth')
32
+ * @default 'userSpaceOnUse'
33
+ */
34
+ markerUnits?: 'userSpaceOnUse' | 'strokeWidth';
35
+ /**
36
+ * Orientation of the marker
37
+ * ('auto', 'auto-start-reverse', or a specific angle in degrees)
38
+ * @default 'auto-start-reverse'
39
+ */
40
+ orient?: 'auto' | 'auto-start-reverse' | number;
41
+ /**
42
+ * X-coordinate offset of the marker's reference point
43
+ * @default 9 if type is 'arrow' or 'triangle', otherwise 5
44
+ */
45
+ refX?: string | number;
46
+ /**
47
+ * Y-coordinate offset of the marker's reference point
48
+ * @default 5
49
+ */
50
+ refY?: string | number;
51
+ /**
52
+ * Viewbox defining the coordinate system for the marker (e.g., '0 0 10 10')
53
+ * @default '0 0 10 10'
54
+ */
55
+ viewBox?: string;
22
56
  };
23
- export type MarkerProps = typeof __propDef.props;
24
- export type MarkerEvents = typeof __propDef.events;
25
- export type MarkerSlots = typeof __propDef.slots;
26
- export default class Marker extends SvelteComponentTyped<MarkerProps, MarkerEvents, MarkerSlots> {
27
- }
28
- export {};
57
+ export type MarkerProps = MarkerPropsWithoutHTML & Without<SVGAttributes<SVGMarkerElement>, MarkerPropsWithoutHTML>;
58
+ declare const Marker: import("svelte").Component<MarkerProps, {}, "">;
59
+ type Marker = ReturnType<typeof Marker>;
60
+ export default Marker;
@@ -0,0 +1,35 @@
1
+ <script lang="ts" module>
2
+ import Marker from './Marker.svelte';
3
+ import type { ComponentProps, Snippet } from 'svelte';
4
+
5
+ export type MarkerProps = {
6
+ /**
7
+ * A unique identifier for the marker.
8
+ */
9
+ id: string;
10
+
11
+ /**
12
+ * The marker or marker options to render
13
+ */
14
+ marker?: MarkerOptions;
15
+ };
16
+
17
+ export type MarkerOptions =
18
+ | ComponentProps<typeof Marker>['type']
19
+ | ComponentProps<typeof Marker>
20
+ | Snippet<[{ id: string }]>;
21
+ </script>
22
+
23
+ <script lang="ts">
24
+ let { id, marker }: MarkerProps = $props();
25
+ </script>
26
+
27
+ {#if typeof marker === 'function'}
28
+ {@render marker({ id })}
29
+ {:else if marker}
30
+ <Marker
31
+ {id}
32
+ type={typeof marker === 'string' ? marker : undefined}
33
+ {...typeof marker === 'object' ? marker : null}
34
+ />
35
+ {/if}
@@ -0,0 +1,18 @@
1
+ import Marker from './Marker.svelte';
2
+ import type { ComponentProps, Snippet } from 'svelte';
3
+ export type MarkerProps = {
4
+ /**
5
+ * A unique identifier for the marker.
6
+ */
7
+ id: string;
8
+ /**
9
+ * The marker or marker options to render
10
+ */
11
+ marker?: MarkerOptions;
12
+ };
13
+ export type MarkerOptions = ComponentProps<typeof Marker>['type'] | ComponentProps<typeof Marker> | Snippet<[{
14
+ id: string;
15
+ }]>;
16
+ declare const MarkerWrapper: import("svelte").Component<MarkerProps, {}, "">;
17
+ type MarkerWrapper = ReturnType<typeof MarkerWrapper>;
18
+ export default MarkerWrapper;
@@ -1,32 +1,77 @@
1
+ <script lang="ts" module>
2
+ import type { Without } from '../utils/types.js';
3
+ import type { SVGAttributes } from 'svelte/elements';
4
+
5
+ export type MonthPathPropsWithoutHTML = {
6
+ /**
7
+ * The date to use for the month path.
8
+ */
9
+ date: Date;
10
+
11
+ /**
12
+ * Size of cell.
13
+ * - `number` - sets width/height as same.
14
+ * - array - sets [width, height].
15
+ */
16
+ cellSize: number | [number, number];
17
+
18
+ /**
19
+ * A bindable reference to the underlying `<path>` element.
20
+ *
21
+ * @bindable
22
+ */
23
+ ref?: SVGPathElement;
24
+ };
25
+
26
+ export type MonthPathProps = MonthPathPropsWithoutHTML &
27
+ Without<SVGAttributes<SVGPathElement>, MonthPathPropsWithoutHTML>;
28
+ </script>
29
+
1
30
  <script lang="ts">
2
31
  import { timeWeek, timeYear } from 'd3-time';
3
32
  import { endOfMonth } from 'date-fns';
33
+ import { cls } from '@layerstack/tailwind';
34
+ import { layerClass } from '../utils/attributes.js';
4
35
 
5
- export let date: Date;
36
+ let {
37
+ date,
38
+ cellSize: cellSizeProp,
39
+ ref: refProp = $bindable(),
40
+ class: className,
41
+ ...restProps
42
+ }: MonthPathProps = $props();
6
43
 
7
- /**
8
- * Size of cell. If `number`, sets width/height as same. If array, sets [width,height]. If undefined, is based on Chart width/height
9
- */
10
- export let cellSize: number | [number, number];
44
+ let ref = $state<SVGPathElement>();
45
+ $effect.pre(() => {
46
+ refProp = ref;
47
+ });
11
48
 
12
- $: [cellWidth, cellHeight] = Array.isArray(cellSize) ? cellSize : [cellSize, cellSize];
49
+ const cellSize = $derived(
50
+ Array.isArray(cellSizeProp) ? cellSizeProp : [cellSizeProp, cellSizeProp]
51
+ );
13
52
 
14
53
  // start of month
15
- $: startDayOfWeek = date.getDay();
16
- $: startWeek = timeWeek.count(timeYear(date), date);
54
+ const startDayOfWeek = $derived(date.getDay());
55
+ const startWeek = $derived(timeWeek.count(timeYear(date), date));
17
56
 
18
57
  // end of month
19
- $: monthEnd = endOfMonth(date);
20
- $: endDayOfWeek = monthEnd.getDay();
21
- $: endWeek = timeWeek.count(timeYear(monthEnd), monthEnd);
22
-
23
- $: pathData = `
24
- M${(startWeek + 1) * cellWidth},${startDayOfWeek * cellHeight}
25
- H${startWeek * cellWidth} V${cellHeight * 7}
26
- H${endWeek * cellWidth} V${(endDayOfWeek + 1) * cellHeight}
27
- H${(endWeek + 1) * cellWidth} V0
28
- H${(startWeek + 1) * cellWidth}Z
29
- `;
58
+ const monthEnd = $derived(endOfMonth(date));
59
+ const endDayOfWeek = $derived(monthEnd.getDay());
60
+ const endWeek = $derived(timeWeek.count(timeYear(monthEnd), monthEnd));
61
+
62
+ const pathData = $derived(`
63
+ M${(startWeek + 1) * cellSize[0]},${startDayOfWeek * cellSize[1]}
64
+ H${startWeek * cellSize[0]} V${cellSize[1] * 7}
65
+ H${endWeek * cellSize[0]} V${(endDayOfWeek + 1) * cellSize[1]}
66
+ H${(endWeek + 1) * cellSize[0]} V0
67
+ H${(startWeek + 1) * cellSize[0]}Z
68
+ `);
30
69
  </script>
31
70
 
32
- <path d={pathData} fill="none" class="stroke-surface-content/20" {...$$restProps} />
71
+ <path
72
+ bind:this={ref}
73
+ d={pathData}
74
+ fill="none"
75
+ class={cls(layerClass('month-path'), 'stroke-surface-content/20', className)}
76
+ {...restProps}
77
+ />
@@ -1,18 +1,24 @@
1
- import { SvelteComponentTyped } from "svelte";
2
- declare const __propDef: {
3
- props: {
4
- [x: string]: any;
5
- date: Date;
6
- cellSize: number | [number, number];
7
- };
8
- events: {
9
- [evt: string]: CustomEvent<any>;
10
- };
11
- slots: {};
1
+ import type { Without } from '../utils/types.js';
2
+ import type { SVGAttributes } from 'svelte/elements';
3
+ export type MonthPathPropsWithoutHTML = {
4
+ /**
5
+ * The date to use for the month path.
6
+ */
7
+ date: Date;
8
+ /**
9
+ * Size of cell.
10
+ * - `number` - sets width/height as same.
11
+ * - array - sets [width, height].
12
+ */
13
+ cellSize: number | [number, number];
14
+ /**
15
+ * A bindable reference to the underlying `<path>` element.
16
+ *
17
+ * @bindable
18
+ */
19
+ ref?: SVGPathElement;
12
20
  };
13
- export type MonthPathProps = typeof __propDef.props;
14
- export type MonthPathEvents = typeof __propDef.events;
15
- export type MonthPathSlots = typeof __propDef.slots;
16
- export default class MonthPath extends SvelteComponentTyped<MonthPathProps, MonthPathEvents, MonthPathSlots> {
17
- }
18
- export {};
21
+ export type MonthPathProps = MonthPathPropsWithoutHTML & Without<SVGAttributes<SVGPathElement>, MonthPathPropsWithoutHTML>;
22
+ declare const MonthPath: import("svelte").Component<MonthPathProps, {}, "ref">;
23
+ type MonthPath = ReturnType<typeof MonthPath>;
24
+ export default MonthPath;
@@ -1,26 +1,82 @@
1
- <script lang="ts">
2
- import { onMount } from 'svelte';
3
- import { uniqueId } from '@layerstack/utils';
1
+ <script lang="ts" module>
2
+ import type { Snippet } from 'svelte';
3
+
4
+ export type MotionPathPropsWithoutHTML = {
5
+ /**
6
+ * Id of path to move object along
7
+ */
8
+ pathId?: string;
9
+
10
+ /**
11
+ * Id of object to move along path
12
+ */
13
+ objectId?: string;
14
+
15
+ /**
16
+ * Duration of the animation
17
+ */
18
+ duration: string;
19
+
20
+ /**
21
+ * Number of times the animation will occur
22
+ */
23
+ repeatCount?: number | 'indefinite';
24
+
25
+ /**
26
+ * Final state of the animation. Freeze (last frame) or remove (first frame)
27
+ * https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill#animate
28
+ *
29
+ * @default 'freeze'
30
+ */
31
+ fill?: 'freeze' | 'remove';
4
32
 
5
- /** Id of path to move object along */
6
- export let pathId: string = uniqueId('motionPathId-');
33
+ /**
34
+ * Rotation applied to the element animated along a path, usually to make it pointing
35
+ * in the direction of the animation
36
+ */
37
+ rotate?: number | 'auto' | 'auto-reverse';
7
38
 
8
- /** Id of object to move along path */
9
- export let objectId: string = uniqueId('motionObjectId-');
39
+ /**
40
+ * A bindable reference to the underlying `<animateMotion>` element.
41
+ *
42
+ * @bindable
43
+ */
44
+ ref?: SVGAnimateMotionElement;
10
45
 
11
- /** Duration of the animation */
12
- export let duration: string;
46
+ children?: Snippet<[{ pathId: string; objectId: string }]>;
47
+ };
13
48
 
14
- /** Number of times the animation will occur */
15
- export let repeatCount: number | 'indefinite' | undefined = undefined;
49
+ export type MotionPathProps = MotionPathPropsWithoutHTML &
50
+ Without<
51
+ Omit<SVGAttributes<SVGAnimateMotionElement>, 'dir' | 'href'>,
52
+ MotionPathPropsWithoutHTML
53
+ >;
54
+ </script>
55
+
56
+ <script lang="ts">
57
+ import type { Without } from '../utils/types.js';
58
+ import type { SVGAttributes } from 'svelte/elements';
59
+ import { createId } from '../utils/createId.js';
60
+ import { extractLayerProps } from '../utils/attributes.js';
16
61
 
17
- /** Final state of the animation. Freeze (last frame) or remove (first frame)
18
- * https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill#animate
19
- * */
20
- export let fill: 'freeze' | 'remove' = 'freeze';
62
+ const uid = $props.id();
21
63
 
22
- /** Rotation applied to the element animated along a path, usually to make it pointing in the direction of the animation */
23
- export let rotate: number | 'auto' | 'auto-reverse' | undefined = undefined;
64
+ let {
65
+ pathId = createId('motionPathId-', uid),
66
+ objectId = createId('motionObjectId-', uid),
67
+ duration,
68
+ repeatCount,
69
+ fill = 'freeze',
70
+ rotate,
71
+ ref: refProp = $bindable(),
72
+ children,
73
+ ...restProps
74
+ }: MotionPathPropsWithoutHTML = $props();
75
+
76
+ let ref = $state<SVGAnimateMotionElement>();
77
+ $effect.pre(() => {
78
+ refProp = ref;
79
+ });
24
80
 
25
81
  // TODO: Investigate `calcMode:spline`, `keyTimes`, and `keySplines` to work with `svelte/easing`
26
82
  // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/calcMode
@@ -29,9 +85,10 @@
29
85
  // https://medium.com/javarevisited/animate-your-scalable-vector-graphics-svg-56f5800cd34b
30
86
 
31
87
  // Restart animation anytime the component is remounted (otherwise it only ever plays once)
32
- let animateEl: SVGAnimateMotionElement;
33
- onMount(() => {
34
- animateEl.beginElement();
88
+
89
+ $effect(() => {
90
+ if (!ref) return;
91
+ ref.beginElement();
35
92
  });
36
93
  </script>
37
94
 
@@ -42,12 +99,11 @@
42
99
  {repeatCount}
43
100
  {fill}
44
101
  {rotate}
45
- bind:this={animateEl}
102
+ bind:this={ref}
103
+ {...extractLayerProps(restProps, 'motion-path')}
46
104
  >
47
105
  <mpath href="#{pathId}" />
48
106
  </animateMotion>
49
107
  </defs>
50
108
 
51
- {#if $$slots.default}
52
- <slot {pathId} {objectId} />
53
- {/if}
109
+ {@render children?.({ pathId, objectId })}