layerchart 2.0.0-next.4 → 2.0.0-next.40

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/dist/components/AnnotationLine.svelte +15 -2
  2. package/dist/components/AnnotationPoint.svelte +29 -11
  3. package/dist/components/AnnotationRange.svelte +18 -4
  4. package/dist/components/Arc.svelte +5 -5
  5. package/dist/components/Area.svelte +10 -2
  6. package/dist/components/Axis.svelte +175 -58
  7. package/dist/components/Axis.svelte.d.ts +23 -6
  8. package/dist/components/Bar.svelte +20 -15
  9. package/dist/components/Bar.svelte.d.ts +2 -2
  10. package/dist/components/Bars.svelte +4 -4
  11. package/dist/components/Blur.svelte +7 -6
  12. package/dist/components/Blur.svelte.d.ts +2 -5
  13. package/dist/components/BrushContext.svelte +45 -45
  14. package/dist/components/Calendar.svelte +31 -10
  15. package/dist/components/Calendar.svelte.d.ts +2 -1
  16. package/dist/components/Chart.svelte +76 -27
  17. package/dist/components/Chart.svelte.d.ts +26 -8
  18. package/dist/components/ChartClipPath.svelte +1 -1
  19. package/dist/components/Circle.svelte +44 -3
  20. package/dist/components/CircleClipPath.svelte +8 -1
  21. package/dist/components/ClipPath.svelte +1 -2
  22. package/dist/components/ColorRamp.svelte +1 -1
  23. package/dist/components/ComputedStyles.svelte +9 -2
  24. package/dist/components/Connector.svelte +3 -3
  25. package/dist/components/Connector.svelte.d.ts +1 -1
  26. package/dist/components/Ellipse.svelte +228 -0
  27. package/dist/components/Ellipse.svelte.d.ts +64 -0
  28. package/dist/components/ForceSimulation.svelte +184 -50
  29. package/dist/components/ForceSimulation.svelte.d.ts +95 -21
  30. package/dist/components/Frame.svelte +1 -1
  31. package/dist/components/GeoCircle.svelte +1 -1
  32. package/dist/components/GeoEdgeFade.svelte +1 -1
  33. package/dist/components/GeoPath.svelte +30 -8
  34. package/dist/components/GeoPoint.svelte +4 -5
  35. package/dist/components/GeoSpline.svelte +5 -5
  36. package/dist/components/GeoSpline.svelte.d.ts +1 -1
  37. package/dist/components/GeoTile.svelte +1 -1
  38. package/dist/components/Graticule.svelte +5 -5
  39. package/dist/components/Grid.svelte +60 -63
  40. package/dist/components/Group.svelte +13 -8
  41. package/dist/components/Group.svelte.d.ts +10 -3
  42. package/dist/components/Highlight.svelte +55 -28
  43. package/dist/components/Highlight.svelte.d.ts +4 -0
  44. package/dist/components/Hull.svelte +12 -5
  45. package/dist/components/Labels.svelte +24 -13
  46. package/dist/components/Labels.svelte.d.ts +12 -5
  47. package/dist/components/Legend.svelte +143 -70
  48. package/dist/components/Legend.svelte.d.ts +12 -8
  49. package/dist/components/Line.svelte +40 -3
  50. package/dist/components/LinearGradient.svelte +35 -4
  51. package/dist/components/Link.svelte +1 -1
  52. package/dist/components/Marker.svelte +37 -26
  53. package/dist/components/MonthPath.svelte +26 -12
  54. package/dist/components/MonthPath.svelte.d.ts +4 -3
  55. package/dist/components/MotionPath.svelte +1 -1
  56. package/dist/components/Pack.svelte.d.ts +10 -3
  57. package/dist/components/Partition.svelte.d.ts +10 -3
  58. package/dist/components/Pattern.svelte +5 -5
  59. package/dist/components/Pie.svelte +1 -2
  60. package/dist/components/Points.svelte +11 -72
  61. package/dist/components/Points.svelte.d.ts +1 -8
  62. package/dist/components/Polygon.svelte +309 -0
  63. package/dist/components/Polygon.svelte.d.ts +115 -0
  64. package/dist/components/RadialGradient.svelte +4 -6
  65. package/dist/components/Rect.svelte +55 -5
  66. package/dist/components/Rect.svelte.d.ts +2 -2
  67. package/dist/components/RectClipPath.svelte +4 -3
  68. package/dist/components/RectClipPath.svelte.d.ts +2 -2
  69. package/dist/components/Rule.svelte +167 -77
  70. package/dist/components/Rule.svelte.d.ts +7 -2
  71. package/dist/components/Spline.svelte +59 -28
  72. package/dist/components/Spline.svelte.d.ts +12 -4
  73. package/dist/components/Text.svelte +121 -73
  74. package/dist/components/Text.svelte.d.ts +6 -0
  75. package/dist/components/TileImage.svelte +19 -4
  76. package/dist/components/TransformContext.svelte +9 -3
  77. package/dist/components/TransformControls.svelte +89 -38
  78. package/dist/components/Tree.svelte.d.ts +10 -3
  79. package/dist/components/Treemap.svelte +63 -26
  80. package/dist/components/Treemap.svelte.d.ts +21 -14
  81. package/dist/components/Voronoi.svelte +12 -13
  82. package/dist/components/charts/ArcChart.svelte +43 -71
  83. package/dist/components/charts/ArcChart.svelte.d.ts +10 -3
  84. package/dist/components/charts/AreaChart.svelte +29 -59
  85. package/dist/components/charts/AreaChart.svelte.d.ts +10 -3
  86. package/dist/components/charts/BarChart.svelte +79 -71
  87. package/dist/components/charts/BarChart.svelte.d.ts +10 -3
  88. package/dist/components/charts/DefaultTooltip.svelte +3 -3
  89. package/dist/components/charts/DefaultTooltip.svelte.d.ts +1 -1
  90. package/dist/components/charts/LineChart.svelte +69 -75
  91. package/dist/components/charts/LineChart.svelte.d.ts +21 -8
  92. package/dist/components/charts/PieChart.svelte +44 -71
  93. package/dist/components/charts/PieChart.svelte.d.ts +10 -3
  94. package/dist/components/charts/ScatterChart.svelte +10 -39
  95. package/dist/components/charts/ScatterChart.svelte.d.ts +10 -3
  96. package/dist/components/charts/utils.svelte.d.ts +1 -19
  97. package/dist/components/charts/utils.svelte.js +7 -35
  98. package/dist/components/index.d.ts +4 -0
  99. package/dist/components/index.js +5 -1
  100. package/dist/components/layout/Canvas.svelte +96 -69
  101. package/dist/components/layout/Canvas.svelte.d.ts +6 -0
  102. package/dist/components/layout/Html.svelte +15 -9
  103. package/dist/components/layout/Layer.svelte +6 -4
  104. package/dist/components/layout/Layer.svelte.d.ts +6 -4
  105. package/dist/components/layout/Svg.svelte +19 -11
  106. package/dist/components/layout/WebGL.svelte +26 -6
  107. package/dist/components/layout/WebGL.svelte.d.ts +5 -2
  108. package/dist/components/tooltip/Tooltip.svelte +65 -27
  109. package/dist/components/tooltip/Tooltip.svelte.d.ts +10 -3
  110. package/dist/components/tooltip/TooltipContext.svelte +167 -54
  111. package/dist/components/tooltip/TooltipContext.svelte.d.ts +19 -5
  112. package/dist/components/tooltip/TooltipHeader.svelte +32 -18
  113. package/dist/components/tooltip/TooltipHeader.svelte.d.ts +3 -3
  114. package/dist/components/tooltip/TooltipItem.svelte +46 -37
  115. package/dist/components/tooltip/TooltipItem.svelte.d.ts +3 -3
  116. package/dist/components/tooltip/TooltipList.svelte +12 -10
  117. package/dist/components/tooltip/TooltipSeparator.svelte +18 -10
  118. package/dist/components/tooltip/tooltipMetaContext.d.ts +2 -2
  119. package/dist/docs/Blockquote.svelte +6 -4
  120. package/dist/docs/Blockquote.svelte.d.ts +4 -19
  121. package/dist/docs/Code.svelte +70 -28
  122. package/dist/docs/Code.svelte.d.ts +9 -24
  123. package/dist/docs/Header1.svelte +4 -2
  124. package/dist/docs/Header1.svelte.d.ts +4 -28
  125. package/dist/docs/Json.svelte +11 -3
  126. package/dist/docs/Json.svelte.d.ts +9 -21
  127. package/dist/docs/Layout.svelte +10 -7
  128. package/dist/docs/Layout.svelte.d.ts +4 -19
  129. package/dist/docs/Link.svelte +7 -3
  130. package/dist/docs/Link.svelte.d.ts +4 -38
  131. package/dist/docs/Preview.svelte +22 -23
  132. package/dist/docs/Preview.svelte.d.ts +5 -6
  133. package/dist/docs/TilesetField.svelte +20 -19
  134. package/dist/docs/TilesetField.svelte.d.ts +5 -22
  135. package/dist/docs/ViewSourceButton.svelte +10 -7
  136. package/dist/docs/ViewSourceButton.svelte.d.ts +7 -21
  137. package/dist/states/series.svelte.d.ts +30 -0
  138. package/dist/states/series.svelte.js +54 -0
  139. package/dist/styles/daisyui-5.css +6 -0
  140. package/dist/styles/shadcn-svelte.css +11 -0
  141. package/dist/styles/skeleton-3.css +15 -0
  142. package/dist/utils/arcText.svelte.js +4 -4
  143. package/dist/utils/array.d.ts +11 -0
  144. package/dist/utils/array.js +23 -0
  145. package/dist/utils/array.test.d.ts +1 -0
  146. package/dist/utils/array.test.js +200 -0
  147. package/dist/utils/attributes.d.ts +3 -13
  148. package/dist/utils/attributes.js +4 -18
  149. package/dist/utils/canvas.d.ts +77 -0
  150. package/dist/utils/canvas.js +105 -41
  151. package/dist/utils/common.d.ts +9 -0
  152. package/dist/utils/common.js +18 -1
  153. package/dist/utils/common.test.js +26 -1
  154. package/dist/utils/genData.d.ts +22 -8
  155. package/dist/utils/genData.js +34 -14
  156. package/dist/utils/graph/dagre.d.ts +4 -4
  157. package/dist/utils/graph/dagre.js +5 -7
  158. package/dist/utils/index.d.ts +1 -0
  159. package/dist/utils/index.js +1 -0
  160. package/dist/utils/math.d.ts +17 -0
  161. package/dist/utils/math.js +17 -0
  162. package/dist/utils/path.d.ts +10 -0
  163. package/dist/utils/path.js +30 -0
  164. package/dist/utils/rect.svelte.d.ts +2 -2
  165. package/dist/utils/rect.svelte.js +73 -1
  166. package/dist/utils/scales.svelte.d.ts +9 -3
  167. package/dist/utils/scales.svelte.js +47 -4
  168. package/dist/utils/shape.d.ts +43 -0
  169. package/dist/utils/shape.js +59 -0
  170. package/dist/utils/stack.js +1 -1
  171. package/dist/utils/string.d.ts +49 -0
  172. package/dist/utils/string.js +4 -2
  173. package/dist/utils/ticks.d.ts +15 -4
  174. package/dist/utils/ticks.js +140 -159
  175. package/dist/utils/ticks.test.js +16 -26
  176. package/dist/utils/treemap.d.ts +1 -1
  177. package/dist/utils/types.d.ts +15 -2
  178. package/package.json +35 -35
  179. package/dist/utils/object.js +0 -2
@@ -71,7 +71,8 @@
71
71
  Without<
72
72
  Omit<SVGAttributes<SVGElement>, 'width' | 'height' | 'x' | 'y' | 'offset'>,
73
73
  BarPropsWithoutHTML
74
- >;
74
+ > &
75
+ CommonEvents;
75
76
  </script>
76
77
 
77
78
  <script lang="ts">
@@ -81,10 +82,10 @@
81
82
  import Rect from './Rect.svelte';
82
83
  import Spline from './Spline.svelte';
83
84
 
84
- import { isScaleBand } from '../utils/scales.svelte.js';
85
+ import { isScaleBand, isScaleTime } from '../utils/scales.svelte.js';
85
86
  import { accessor, type Accessor } from '../utils/common.js';
86
87
  import { getChartContext } from './Chart.svelte';
87
- import type { CommonStyleProps, Without } from '../utils/types.js';
88
+ import type { CommonEvents, CommonStyleProps, Without } from '../utils/types.js';
88
89
  import { extractLayerProps } from '../utils/attributes.js';
89
90
  import { extractTweenConfig, type MotionProp } from '../utils/motion.svelte.js';
90
91
  import Arc from './Arc.svelte';
@@ -127,7 +128,7 @@
127
128
 
128
129
  const dimensions = $derived(getDimensions(data) ?? { x: 0, y: 0, width: 0, height: 0 });
129
130
 
130
- const isVertical = $derived(isScaleBand(ctx.xScale));
131
+ const isVertical = $derived(isScaleBand(ctx.xScale) || isScaleTime(ctx.xScale));
131
132
  const valueAccessor = $derived(accessor(isVertical ? y : x));
132
133
  const value = $derived(valueAccessor(data));
133
134
  const resolvedValue = $derived(Array.isArray(value) ? greatestAbs(value) : value);
@@ -136,10 +137,10 @@
136
137
  const rounded = $derived(
137
138
  roundedProp === 'edge'
138
139
  ? isVertical
139
- ? resolvedValue >= 0
140
+ ? resolvedValue >= 0 && ctx.yRange[0] > ctx.yRange[1] // not inverted (bottom to top)
140
141
  ? 'top'
141
142
  : 'bottom'
142
- : resolvedValue >= 0
143
+ : resolvedValue >= 0 && ctx.xRange[0] < ctx.xRange[1] // not inverted (left to right)
143
144
  ? 'right'
144
145
  : 'left'
145
146
  : roundedProp
@@ -151,16 +152,20 @@
151
152
  const bottomRight = $derived(['all', 'bottom', 'right', 'bottom-right'].includes(rounded));
152
153
  const width = $derived(dimensions.width);
153
154
  const height = $derived(dimensions.height);
154
- const diameter = $derived(2 * radius);
155
+
156
+ // Clamp radius to prevent extending beyond bounding box
157
+ const r = $derived(Math.min(radius, width / 2, height / 2));
158
+ const diameter = $derived(2 * r);
159
+
155
160
  const pathData = $derived(
156
- `M${dimensions.x + radius},${dimensions.y} h${width - diameter}
157
- ${topRight ? `a${radius},${radius} 0 0 1 ${radius},${radius}` : `h${radius}v${radius}`}
161
+ `M${dimensions.x + r},${dimensions.y} h${width - diameter}
162
+ ${topRight ? `a${r},${r} 0 0 1 ${r},${r}` : `h${r}v${r}`}
158
163
  v${height - diameter}
159
- ${bottomRight ? `a${radius},${radius} 0 0 1 ${-radius},${radius}` : `v${radius}h${-radius}`}
164
+ ${bottomRight ? `a${r},${r} 0 0 1 ${-r},${r}` : `v${r}h${-r}`}
160
165
  h${diameter - width}
161
- ${bottomLeft ? `a${radius},${radius} 0 0 1 ${-radius},${-radius}` : `h${-radius}v${-radius}`}
166
+ ${bottomLeft ? `a${r},${r} 0 0 1 ${-r},${-r}` : `h${-r}v${-r}`}
162
167
  v${diameter - height}
163
- ${topLeft ? `a${radius},${radius} 0 0 1 ${radius},${-radius}` : `v${-radius}h${radius}`}
168
+ ${topLeft ? `a${r},${r} 0 0 1 ${r},${-r}` : `v${-r}h${r}`}
164
169
  z`
165
170
  .split('\n')
166
171
  .join('')
@@ -179,7 +184,7 @@
179
184
  {strokeWidth}
180
185
  {opacity}
181
186
  cornerRadius={radius}
182
- {...extractLayerProps(restProps, 'bar')}
187
+ {...extractLayerProps(restProps, 'lc-bar')}
183
188
  />
184
189
  {:else if rounded === 'all' || rounded === 'none' || radius === 0}
185
190
  <Rect
@@ -195,7 +200,7 @@
195
200
  {initialHeight}
196
201
  {initialWidth}
197
202
  {...dimensions}
198
- {...extractLayerProps(restProps, 'bar')}
203
+ {...extractLayerProps(restProps, 'lc-bar')}
199
204
  />
200
205
  {:else}
201
206
  {@const tweenMotion = extractTweenConfig(motion)}
@@ -207,6 +212,6 @@
207
212
  {strokeWidth}
208
213
  {opacity}
209
214
  motion={tweenMotion}
210
- {...extractLayerProps(restProps, 'bar')}
215
+ {...extractLayerProps(restProps, 'lc-bar')}
211
216
  />
212
217
  {/if}
@@ -41,10 +41,10 @@ export type BarPropsWithoutHTML = {
41
41
  rounded?: 'all' | 'none' | 'edge' | 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
42
42
  motion?: MotionProp<'x' | 'y' | 'width' | 'height'>;
43
43
  } & CommonStyleProps;
44
- export type BarProps = BarPropsWithoutHTML & Without<Omit<SVGAttributes<SVGElement>, 'width' | 'height' | 'x' | 'y' | 'offset'>, BarPropsWithoutHTML>;
44
+ export type BarProps = BarPropsWithoutHTML & Without<Omit<SVGAttributes<SVGElement>, 'width' | 'height' | 'x' | 'y' | 'offset'>, BarPropsWithoutHTML> & CommonEvents;
45
45
  import type { SVGAttributes } from 'svelte/elements';
46
46
  import { type Accessor } from '../utils/common.js';
47
- import type { CommonStyleProps, Without } from '../utils/types.js';
47
+ import type { CommonEvents, CommonStyleProps, Without } from '../utils/types.js';
48
48
  import { type MotionProp } from '../utils/motion.svelte.js';
49
49
  declare const Bar: import("svelte").Component<BarProps, {}, "">;
50
50
  type Bar = ReturnType<typeof Bar>;
@@ -32,9 +32,9 @@
32
32
  import Bar, { type BarProps, type BarPropsWithoutHTML } from './Bar.svelte';
33
33
  import Group from './Group.svelte';
34
34
 
35
- import { chartDataArray } from '../utils/common.js';
36
35
  import { getChartContext } from './Chart.svelte';
37
- import { extractLayerProps, layerClass } from '../utils/attributes.js';
36
+ import { chartDataArray } from '../utils/common.js';
37
+ import { extractLayerProps } from '../utils/attributes.js';
38
38
 
39
39
  let {
40
40
  fill,
@@ -52,7 +52,7 @@
52
52
  const data = $derived(chartDataArray(dataProp ?? ctx.data));
53
53
  </script>
54
54
 
55
- <Group class={layerClass('bars')}>
55
+ <Group class="lc-bars">
56
56
  {#if children}
57
57
  {@render children()}
58
58
  {:else}
@@ -64,7 +64,7 @@
64
64
  {stroke}
65
65
  fill={fill ?? (ctx.config.c ? ctx.cGet(d) : null)}
66
66
  onclick={(e) => onBarClick(e, { data: d })}
67
- {...extractLayerProps(restProps, 'bars-bar')}
67
+ {...extractLayerProps(restProps, 'lc-bars-bar')}
68
68
  />
69
69
  {/each}
70
70
  {/if}
@@ -14,9 +14,9 @@
14
14
 
15
15
  /**
16
16
  * The default children snippet which provides
17
- * the id and url for the filter.
17
+ * the id for the filter.
18
18
  */
19
- children?: Snippet<[{ id: string; url: string }]>;
19
+ children?: Snippet;
20
20
  };
21
21
  </script>
22
22
 
@@ -24,7 +24,6 @@
24
24
  import type { Snippet } from 'svelte';
25
25
  import { getRenderContext } from './Chart.svelte';
26
26
  import { createId } from '../utils/createId.js';
27
- import { layerClass } from '../utils/attributes.js';
28
27
 
29
28
  const uid = $props.id();
30
29
 
@@ -35,14 +34,16 @@
35
34
 
36
35
  {#if renderContext === 'svg'}
37
36
  <defs>
38
- <filter {id} class={layerClass('blur-filter')}>
37
+ <filter {id} class="lc-blur-filter">
39
38
  <feGaussianBlur in="SourceGraphic" {stdDeviation} />
40
39
  </filter>
41
40
  </defs>
42
41
 
43
42
  {#if children}
44
- <g filter="url(#{id})" class={layerClass('blur-g')}>
45
- {@render children({ id, url: `url(#${id})` })}
43
+ <g filter="url(#{id})" class="lc-blur-g">
44
+ {@render children()}
46
45
  </g>
47
46
  {/if}
47
+ {:else if children}
48
+ {@render children()}
48
49
  {/if}
@@ -11,12 +11,9 @@ export type BlurProps = {
11
11
  stdDeviation?: number;
12
12
  /**
13
13
  * The default children snippet which provides
14
- * the id and url for the filter.
14
+ * the id for the filter.
15
15
  */
16
- children?: Snippet<[{
17
- id: string;
18
- url: string;
19
- }]>;
16
+ children?: Snippet;
20
17
  };
21
18
  import type { Snippet } from 'svelte';
22
19
  declare const Blur: import("svelte").Component<BlurProps, {}, "">;
@@ -148,7 +148,6 @@
148
148
  import type { HTMLAttributes } from 'svelte/elements';
149
149
  import { getChartContext } from './Chart.svelte';
150
150
  import type { Snippet } from 'svelte';
151
- import { layerClass } from '../utils/attributes.js';
152
151
 
153
152
  const ctx = getChartContext();
154
153
 
@@ -319,7 +318,7 @@
319
318
  _range.width < RESET_THRESHOLD ||
320
319
  _range.height < RESET_THRESHOLD
321
320
  ) {
322
- // Clicked on frame, or pointer delta was <1
321
+ // Clicked on frame, or pointer delta was less than threshold (default: 1px)
323
322
  if (ignoreResetClick) {
324
323
  logger.debug('ignoring frame click reset');
325
324
  } else {
@@ -463,7 +462,6 @@
463
462
  {#if disabled}
464
463
  {@render children?.({ brushContext })}
465
464
  {:else}
466
- {@const handleClass = layerClass('brush-handle')}
467
465
  <!-- svelte-ignore a11y_no_static_element_interactions -->
468
466
  <div
469
467
  bind:this={rootEl}
@@ -471,12 +469,12 @@
471
469
  style:left="{ctx.padding.left}px"
472
470
  style:width="{ctx.width}px"
473
471
  style:height="{ctx.height}px"
474
- class={cls(layerClass('brush-context'), 'absolute touch-none')}
472
+ class={cls('lc-brush-context')}
475
473
  onpointerdown={createRange}
476
474
  ondblclick={() => selectAll()}
477
475
  >
478
476
  <div
479
- class={cls(layerClass('brush-container'), 'absolute')}
477
+ class={cls('lc-brush-container')}
480
478
  style:top="-{ctx.padding.top ?? 0}px"
481
479
  style:left="-{ctx.padding.left ?? 0}px"
482
480
  style:width="{ctx.containerWidth}px"
@@ -492,13 +490,7 @@
492
490
  style:top="{_range.y}px"
493
491
  style:width="{_range.width}px"
494
492
  style:height="{_range.height}px"
495
- class={cls(
496
- layerClass('brush-range'),
497
- 'absolute bg-surface-content/10 cursor-move select-none',
498
- 'z-10',
499
- classes.range,
500
- range?.class
501
- )}
493
+ class={cls('lc-brush-range', classes.range, range?.class)}
502
494
  onpointerdown={adjustRange}
503
495
  ondblclick={() => reset()}
504
496
  ></div>
@@ -511,14 +503,7 @@
511
503
  style:width="{_range.width}px"
512
504
  style:height="{handleSize}px"
513
505
  data-position="top"
514
- class={cls(
515
- handleClass,
516
- 'cursor-ns-resize select-none',
517
- 'range absolute',
518
- 'z-10',
519
- classes.handle,
520
- handle?.class
521
- )}
506
+ class={cls('lc-brush-handle', classes.handle, handle?.class)}
522
507
  onpointerdown={adjustTop}
523
508
  ondblclick={(e) => {
524
509
  e.stopPropagation();
@@ -536,15 +521,7 @@
536
521
  style:width="{_range.width}px"
537
522
  style:height="{handleSize}px"
538
523
  data-position="bottom"
539
- class={cls(
540
- handleClass,
541
- 'handle bottom',
542
- 'cursor-ns-resize select-none',
543
- 'range absolute',
544
- 'z-10',
545
- classes.handle,
546
- handle?.class
547
- )}
524
+ class={cls('lc-brush-handle', classes.handle, handle?.class)}
548
525
  onpointerdown={adjustBottom}
549
526
  ondblclick={(e) => {
550
527
  e.stopPropagation();
@@ -564,14 +541,7 @@
564
541
  style:width="{handleSize}px"
565
542
  style:height="{_range.height}px"
566
543
  data-position="left"
567
- class={cls(
568
- handleClass,
569
- 'cursor-ew-resize select-none',
570
- 'range absolute',
571
- 'z-10',
572
- classes.handle,
573
- handle?.class
574
- )}
544
+ class={cls('lc-brush-handle', classes.handle, handle?.class)}
575
545
  onpointerdown={adjustLeft}
576
546
  ondblclick={(e) => {
577
547
  e.stopPropagation();
@@ -589,14 +559,7 @@
589
559
  style:width="{handleSize}px"
590
560
  style:height="{_range.height}px"
591
561
  data-position="right"
592
- class={cls(
593
- handleClass,
594
- 'cursor-ew-resize select-none',
595
- 'range absolute',
596
- 'z-10',
597
- classes.handle,
598
- handle?.class
599
- )}
562
+ class={cls('lc-brush-handle', classes.handle, handle?.class)}
600
563
  onpointerdown={adjustRight}
601
564
  ondblclick={(e) => {
602
565
  e.stopPropagation();
@@ -610,3 +573,40 @@
610
573
  {/if}
611
574
  </div>
612
575
  {/if}
576
+
577
+ <style>
578
+ @layer base {
579
+ :where(.lc-brush-context) {
580
+ position: absolute;
581
+ touch-action: none;
582
+ }
583
+
584
+ :where(.lc-brush-container) {
585
+ position: absolute;
586
+ }
587
+
588
+ :where(.lc-brush-range) {
589
+ position: absolute;
590
+ cursor: move;
591
+ user-select: none;
592
+ z-index: 10;
593
+ background: color-mix(in oklab, var(--color-surface-content, currentColor) 10%, transparent);
594
+ }
595
+
596
+ :where(.lc-brush-handle) {
597
+ position: absolute;
598
+ user-select: none;
599
+ z-index: 10;
600
+
601
+ &[data-position='top'],
602
+ &[data-position='bottom'] {
603
+ cursor: ns-resize;
604
+ }
605
+
606
+ &[data-position='left'],
607
+ &[data-position='right'] {
608
+ cursor: ew-resize;
609
+ }
610
+ }
611
+ }
612
+ </style>
@@ -36,14 +36,14 @@
36
36
  /**
37
37
  * Props to pass to the `<text>` element for month labels.
38
38
  */
39
- monthLabel?: Partial<ComponentProps<typeof Text>>;
39
+ monthLabel?: boolean | Partial<ComponentProps<typeof Text>>;
40
40
 
41
41
  /**
42
42
  * Tooltip context to setup mouse events to show tooltip for related data
43
43
  */
44
44
  tooltipContext?: TooltipContextValue;
45
45
 
46
- children?: Snippet<[{ cells: CalendarCell[] }]>;
46
+ children?: Snippet<[{ cells: CalendarCell[]; cellSize: [number, number] }]>;
47
47
  } & Omit<
48
48
  RectPropsWithoutHTML,
49
49
  'children' | 'x' | 'y' | 'width' | 'height' | 'fill' | 'onpointermove' | 'onpointerleave'
@@ -57,7 +57,7 @@
57
57
  import { type ComponentProps, type Snippet } from 'svelte';
58
58
  import { timeDays, timeMonths, timeWeek, timeYear } from 'd3-time';
59
59
  import { index } from 'd3-array';
60
- import { format } from 'date-fns';
60
+ import { format } from '@layerstack/utils';
61
61
 
62
62
  import Rect, { type RectPropsWithoutHTML } from './Rect.svelte';
63
63
  import type { TooltipContextValue } from './tooltip/TooltipContext.svelte';
@@ -74,9 +74,9 @@
74
74
  start,
75
75
  cellSize: cellSizeProp,
76
76
  monthPath = false,
77
+ monthLabel = true,
77
78
  tooltipContext: tooltip,
78
79
  children,
79
- monthLabel,
80
80
  ...restProps
81
81
  }: CalendarPropsWithoutHTML = $props();
82
82
 
@@ -117,7 +117,7 @@
117
117
  </script>
118
118
 
119
119
  {#if children}
120
- {@render children({ cells })}
120
+ {@render children({ cells, cellSize })}
121
121
  {:else}
122
122
  {#each cells as cell}
123
123
  <Rect
@@ -128,20 +128,41 @@
128
128
  fill={cell.color}
129
129
  onpointermove={(e) => tooltip?.show(e, cell.data)}
130
130
  onpointerleave={(e) => tooltip?.hide()}
131
- {...extractLayerProps(restProps, 'calendar-cell', 'stroke-surface-content/5')}
131
+ strokeWidth={1}
132
+ {...extractLayerProps(restProps, 'lc-calendar-cell')}
132
133
  />
133
134
  {/each}
134
135
  {/if}
135
136
 
136
137
  {#if monthPath}
137
138
  {#each yearMonths as date}
138
- <MonthPath {date} {cellSize} {...extractLayerProps(monthPath, 'calendar-month-path')} />
139
+ <MonthPath {date} {cellSize} {...extractLayerProps(monthPath, 'lc-calendar-month-path')} />
140
+ {/each}
141
+ {/if}
139
142
 
143
+ {#if monthLabel}
144
+ {#each yearMonths as date}
140
145
  <Text
141
146
  x={timeWeek.count(timeYear.floor(date), timeWeek.ceil(date)) * cellSize[0]}
142
- y={-4}
143
- value={format(date, 'MMM')}
144
- {...extractLayerProps(monthLabel, 'calendar-month-label', 'text-xs')}
147
+ value={format(date, 'month', { variant: 'short' })}
148
+ capHeight="7px"
149
+ {...extractLayerProps(monthLabel, 'lc-calendar-month-label')}
145
150
  />
146
151
  {/each}
147
152
  {/if}
153
+
154
+ <style>
155
+ @layer components {
156
+ :global(:where(.lc-calendar-cell)) {
157
+ --stroke-color: color-mix(
158
+ in oklab,
159
+ var(--color-surface-content, currentColor) 5%,
160
+ transparent
161
+ );
162
+ }
163
+
164
+ :global(:where(.lc-calendar-month-label)) {
165
+ font-size: 12px;
166
+ }
167
+ }
168
+ </style>
@@ -30,13 +30,14 @@ export type CalendarPropsWithoutHTML = {
30
30
  /**
31
31
  * Props to pass to the `<text>` element for month labels.
32
32
  */
33
- monthLabel?: Partial<ComponentProps<typeof Text>>;
33
+ monthLabel?: boolean | Partial<ComponentProps<typeof Text>>;
34
34
  /**
35
35
  * Tooltip context to setup mouse events to show tooltip for related data
36
36
  */
37
37
  tooltipContext?: TooltipContextValue;
38
38
  children?: Snippet<[{
39
39
  cells: CalendarCell[];
40
+ cellSize: [number, number];
40
41
  }]>;
41
42
  } & Omit<RectPropsWithoutHTML, 'children' | 'x' | 'y' | 'width' | 'height' | 'fill' | 'onpointermove' | 'onpointerleave'>;
42
43
  export type CalendarProps = CalendarPropsWithoutHTML & Without<SVGAttributes<SVGRectElement>, CalendarPropsWithoutHTML>;