layerchart 2.0.0-next.37 → 2.0.0-next.39

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 (115) hide show
  1. package/dist/components/AnnotationLine.svelte +15 -2
  2. package/dist/components/AnnotationPoint.svelte +13 -2
  3. package/dist/components/AnnotationRange.svelte +16 -2
  4. package/dist/components/Arc.svelte +3 -3
  5. package/dist/components/Area.svelte +10 -2
  6. package/dist/components/Axis.svelte +43 -26
  7. package/dist/components/Axis.svelte.d.ts +10 -3
  8. package/dist/components/Bar.svelte +6 -5
  9. package/dist/components/Bar.svelte.d.ts +2 -2
  10. package/dist/components/Bars.svelte +3 -3
  11. package/dist/components/Blur.svelte +2 -3
  12. package/dist/components/BrushContext.svelte +44 -44
  13. package/dist/components/Calendar.svelte +21 -4
  14. package/dist/components/Chart.svelte +1 -2
  15. package/dist/components/Chart.svelte.d.ts +10 -3
  16. package/dist/components/ChartClipPath.svelte +1 -1
  17. package/dist/components/Circle.svelte +44 -3
  18. package/dist/components/CircleClipPath.svelte +8 -1
  19. package/dist/components/ClipPath.svelte +1 -2
  20. package/dist/components/ColorRamp.svelte +1 -1
  21. package/dist/components/ComputedStyles.svelte +9 -2
  22. package/dist/components/Connector.svelte +1 -1
  23. package/dist/components/Ellipse.svelte +44 -3
  24. package/dist/components/ForceSimulation.svelte.d.ts +10 -3
  25. package/dist/components/Frame.svelte +1 -1
  26. package/dist/components/GeoCircle.svelte +1 -1
  27. package/dist/components/GeoEdgeFade.svelte +1 -1
  28. package/dist/components/GeoPath.svelte +18 -3
  29. package/dist/components/GeoPoint.svelte +3 -3
  30. package/dist/components/GeoSpline.svelte +1 -1
  31. package/dist/components/GeoTile.svelte +1 -1
  32. package/dist/components/Graticule.svelte +5 -5
  33. package/dist/components/Grid.svelte +57 -60
  34. package/dist/components/Group.svelte +11 -6
  35. package/dist/components/Group.svelte.d.ts +10 -3
  36. package/dist/components/Highlight.svelte +46 -22
  37. package/dist/components/Highlight.svelte.d.ts +4 -0
  38. package/dist/components/Hull.svelte +11 -4
  39. package/dist/components/Labels.svelte +21 -11
  40. package/dist/components/Labels.svelte.d.ts +10 -3
  41. package/dist/components/Legend.svelte +133 -67
  42. package/dist/components/Legend.svelte.d.ts +7 -3
  43. package/dist/components/Line.svelte +40 -3
  44. package/dist/components/LinearGradient.svelte +35 -4
  45. package/dist/components/Link.svelte +1 -1
  46. package/dist/components/Marker.svelte +37 -26
  47. package/dist/components/MonthPath.svelte +14 -3
  48. package/dist/components/MotionPath.svelte +1 -1
  49. package/dist/components/Pack.svelte.d.ts +10 -3
  50. package/dist/components/Partition.svelte.d.ts +10 -3
  51. package/dist/components/Pattern.svelte +5 -5
  52. package/dist/components/Pie.svelte +1 -2
  53. package/dist/components/Points.svelte +1 -3
  54. package/dist/components/Polygon.svelte +27 -3
  55. package/dist/components/RadialGradient.svelte +3 -3
  56. package/dist/components/Rect.svelte +55 -5
  57. package/dist/components/Rect.svelte.d.ts +2 -2
  58. package/dist/components/RectClipPath.svelte +4 -3
  59. package/dist/components/RectClipPath.svelte.d.ts +2 -2
  60. package/dist/components/Rule.svelte +30 -23
  61. package/dist/components/Spline.svelte +29 -10
  62. package/dist/components/Text.svelte +59 -13
  63. package/dist/components/TileImage.svelte +19 -4
  64. package/dist/components/TransformContext.svelte +9 -3
  65. package/dist/components/TransformControls.svelte +72 -17
  66. package/dist/components/Tree.svelte.d.ts +10 -3
  67. package/dist/components/Treemap.svelte.d.ts +10 -3
  68. package/dist/components/Voronoi.svelte +12 -13
  69. package/dist/components/charts/ArcChart.svelte +40 -69
  70. package/dist/components/charts/ArcChart.svelte.d.ts +10 -3
  71. package/dist/components/charts/AreaChart.svelte +19 -42
  72. package/dist/components/charts/AreaChart.svelte.d.ts +10 -3
  73. package/dist/components/charts/BarChart.svelte +7 -18
  74. package/dist/components/charts/BarChart.svelte.d.ts +10 -3
  75. package/dist/components/charts/DefaultTooltip.svelte +2 -2
  76. package/dist/components/charts/DefaultTooltip.svelte.d.ts +1 -1
  77. package/dist/components/charts/LineChart.svelte +61 -66
  78. package/dist/components/charts/LineChart.svelte.d.ts +21 -8
  79. package/dist/components/charts/PieChart.svelte +41 -69
  80. package/dist/components/charts/PieChart.svelte.d.ts +10 -3
  81. package/dist/components/charts/ScatterChart.svelte +8 -19
  82. package/dist/components/charts/ScatterChart.svelte.d.ts +10 -3
  83. package/dist/components/charts/utils.svelte.d.ts +1 -19
  84. package/dist/components/charts/utils.svelte.js +7 -39
  85. package/dist/components/layout/Canvas.svelte +29 -20
  86. package/dist/components/layout/Html.svelte +15 -9
  87. package/dist/components/layout/Svg.svelte +19 -11
  88. package/dist/components/layout/WebGL.svelte +26 -6
  89. package/dist/components/layout/WebGL.svelte.d.ts +5 -2
  90. package/dist/components/tooltip/Tooltip.svelte +60 -29
  91. package/dist/components/tooltip/Tooltip.svelte.d.ts +10 -3
  92. package/dist/components/tooltip/TooltipContext.svelte +73 -36
  93. package/dist/components/tooltip/TooltipContext.svelte.d.ts +17 -3
  94. package/dist/components/tooltip/TooltipHeader.svelte +27 -14
  95. package/dist/components/tooltip/TooltipItem.svelte +41 -33
  96. package/dist/components/tooltip/TooltipList.svelte +12 -10
  97. package/dist/components/tooltip/TooltipSeparator.svelte +18 -10
  98. package/dist/states/series.svelte.d.ts +30 -0
  99. package/dist/states/series.svelte.js +54 -0
  100. package/dist/styles/daisyui-5.css +6 -0
  101. package/dist/styles/shadcn-svelte.css +11 -0
  102. package/dist/styles/skeleton-3.css +15 -0
  103. package/dist/utils/attributes.d.ts +3 -13
  104. package/dist/utils/attributes.js +4 -18
  105. package/dist/utils/common.d.ts +9 -0
  106. package/dist/utils/common.js +18 -1
  107. package/dist/utils/common.test.js +26 -1
  108. package/dist/utils/graph/dagre.d.ts +4 -4
  109. package/dist/utils/graph/dagre.js +5 -7
  110. package/dist/utils/math.d.ts +17 -0
  111. package/dist/utils/math.js +17 -0
  112. package/dist/utils/scales.svelte.js +3 -3
  113. package/dist/utils/stack.js +1 -1
  114. package/dist/utils/types.d.ts +15 -2
  115. package/package.json +25 -22
@@ -81,7 +81,7 @@
81
81
  import { createLinearGradient, getComputedStyles } from '../utils/canvas.js';
82
82
  import { parsePercent } from '../utils/math.js';
83
83
  import { createId } from '../utils/createId.js';
84
- import { extractLayerProps, layerClass } from '../utils/attributes.js';
84
+ import { extractLayerProps } from '../utils/attributes.js';
85
85
  import { cls } from '@layerstack/tailwind';
86
86
 
87
87
  const uid = $props.id();
@@ -113,6 +113,35 @@
113
113
 
114
114
  let canvasGradient = $state<CanvasGradient>();
115
115
 
116
+ function createCSSGradient(): string {
117
+ if (!stops?.length) return '';
118
+
119
+ let direction: string;
120
+ if (rotate !== undefined) {
121
+ // Convert SVG rotation to CSS linear-gradient angle
122
+ // SVG: rotate(0) on horizontal gradient = left-to-right = CSS 90deg
123
+ // SVG: rotate(0) on vertical gradient = top-to-bottom = CSS 180deg
124
+ const baseAngle = vertical ? 180 : 90;
125
+ const cssAngle = baseAngle + rotate;
126
+ direction = `${cssAngle}deg`;
127
+ } else {
128
+ // Use direction keywords when no rotation is specified
129
+ direction = vertical ? 'to bottom' : 'to right';
130
+ }
131
+
132
+ const cssStops = stops
133
+ .map((stop, i) => {
134
+ if (Array.isArray(stop)) {
135
+ return `${stop[1]} ${stop[0]}`;
136
+ } else {
137
+ return `${stop} ${i * (100 / (stops.length - 1))}%`;
138
+ }
139
+ })
140
+ .join(', ');
141
+
142
+ return `linear-gradient(${direction}, ${cssStops})`;
143
+ }
144
+
116
145
  function render(_ctx: CanvasRenderingContext2D) {
117
146
  // Use `getComputedStyles()` to convert each stop (if using CSS variables and/or classes) to color values
118
147
  const _stops = stops.map((stop, i) => {
@@ -170,7 +199,7 @@
170
199
  {y2}
171
200
  gradientTransform={rotate ? `rotate(${rotate})` : ''}
172
201
  gradientUnits={units}
173
- {...extractLayerProps(restProps, 'linear-gradient')}
202
+ {...extractLayerProps(restProps, 'lc-linear-gradient')}
174
203
  >
175
204
  {#if stopsContent}
176
205
  {@render stopsContent?.()}
@@ -180,13 +209,13 @@
180
209
  <stop
181
210
  offset={stop[0]}
182
211
  stop-color={stop[1]}
183
- class={cls(layerClass('linear-gradient-stop'), className)}
212
+ class={cls('lc-linear-gradient-stop', className)}
184
213
  />
185
214
  {:else}
186
215
  <stop
187
216
  offset="{i * (100 / (stops.length - 1))}%"
188
217
  stop-color={stop}
189
- class={cls(layerClass('linear-gradient-stop'), className)}
218
+ class={cls('lc-linear-gradient-stop', className)}
190
219
  />
191
220
  {/if}
192
221
  {/each}
@@ -195,4 +224,6 @@
195
224
  </defs>
196
225
 
197
226
  {@render children?.({ id, gradient: `url(#${id})` })}
227
+ {:else if renderCtx === 'html'}
228
+ {@render children?.({ id, gradient: createCSSGradient() })}
198
229
  {/if}
@@ -173,5 +173,5 @@ TODO:
173
173
  {type}
174
174
  {curve}
175
175
  {sweep}
176
- {...extractLayerProps(restProps, 'link')}
176
+ {...extractLayerProps(restProps, 'lc-link')}
177
177
  />
@@ -73,7 +73,6 @@
73
73
  <script lang="ts">
74
74
  import { cls } from '@layerstack/tailwind';
75
75
  import { createId } from '../utils/createId.js';
76
- import { layerClass } from '../utils/attributes.js';
77
76
 
78
77
  const uid = $props.id();
79
78
 
@@ -104,39 +103,51 @@
104
103
  {refX}
105
104
  {refY}
106
105
  {viewBox}
106
+ data-type={type}
107
107
  {...restProps}
108
- class={cls(
109
- layerClass('marker'),
110
- 'overflow-visible',
111
- // stroke
112
- restProps.stroke == null &&
113
- (['arrow', 'circle-stroke', 'line'].includes(type ?? '')
114
- ? 'stroke-[context-stroke]'
115
- : type === 'circle'
116
- ? 'stroke-surface-100'
117
- : 'stroke-none'),
118
- // extra stroke attrs
119
- '[stroke-linecap:round] [stroke-linejoin:round]',
120
- //fill
121
- restProps.fill == null &&
122
- (['triangle', 'dot', 'circle'].includes(type ?? '')
123
- ? 'fill-[context-stroke]'
124
- : type === 'circle-stroke'
125
- ? 'fill-surface-100'
126
- : 'fill-none'),
127
- className
128
- )}
108
+ class={cls('lc-marker', className)}
129
109
  >
130
110
  {#if children}
131
111
  {@render children()}
132
112
  {:else if type === 'triangle'}
133
- <path d="M 0 0 L 10 5 L 0 10 z" class={layerClass('marker-triangle')} />
113
+ <path d="M 0 0 L 10 5 L 0 10 z" class="lc-marker-triangle" />
134
114
  {:else if type === 'arrow'}
135
- <polyline points="0 0, 10 5, 0 10" class={layerClass('marker-arrow')} />
115
+ <polyline points="0 0, 10 5, 0 10" class="lc-marker-arrow" />
136
116
  {:else if type === 'circle' || type === 'circle-stroke' || type === 'dot'}
137
- <circle cx={5} cy={5} r={5} class={layerClass('marker-circle')} />
117
+ <circle cx={5} cy={5} r={5} class="lc-marker-circle" />
138
118
  {:else if type === 'line'}
139
- <polyline points="5 0, 5 10" class={layerClass('marker-line')} />
119
+ <polyline points="5 0, 5 10" class="lc-marker-line" />
140
120
  {/if}
141
121
  </marker>
142
122
  </defs>
123
+
124
+ <style>
125
+ @layer base {
126
+ :global(:where(.lc-marker)) {
127
+ overflow: visible;
128
+
129
+ &[data-type='arrow'],
130
+ &[data-type='circle-stroke'],
131
+ &[data-type='line'] {
132
+ fill: none;
133
+ stroke: context-stroke;
134
+ stroke-linecap: round;
135
+ stroke-linejoin: round;
136
+ }
137
+
138
+ &[data-type='circle'] {
139
+ stroke: var(--color-surface-100, light-dark(white, black));
140
+ }
141
+
142
+ &[data-type='triangle'],
143
+ &[data-type='dot'],
144
+ &[data-type='circle'] {
145
+ fill: context-stroke;
146
+ }
147
+
148
+ &[data-type='circle-stroke'] {
149
+ fill: var(--color-surface-100, light-dark(white, black));
150
+ }
151
+ }
152
+ }
153
+ </style>
@@ -30,10 +30,9 @@
30
30
  </script>
31
31
 
32
32
  <script lang="ts">
33
- import { timeWeek, timeMonth, timeYear } from 'd3-time';
33
+ import { timeWeek, timeYear } from 'd3-time';
34
34
  import { cls } from '@layerstack/tailwind';
35
35
  import { endOfInterval } from '@layerstack/utils';
36
- import { layerClass } from '../utils/attributes.js';
37
36
  import Spline, { type SplinePropsWithoutHTML } from './Spline.svelte';
38
37
 
39
38
  let {
@@ -75,6 +74,18 @@
75
74
  bind:pathRef
76
75
  {pathData}
77
76
  fill="none"
78
- class={cls(layerClass('month-path'), 'stroke-surface-content/20', className)}
77
+ class={cls('lc-month-path', className)}
79
78
  {...restProps}
80
79
  />
80
+
81
+ <style>
82
+ @layer components {
83
+ :global(:where(.lc-month-path)) {
84
+ --stroke-color: color-mix(
85
+ in oklab,
86
+ var(--color-surface-content, currentColor) 20%,
87
+ transparent
88
+ );
89
+ }
90
+ }
91
+ </style>
@@ -100,7 +100,7 @@
100
100
  {fill}
101
101
  {rotate}
102
102
  bind:this={ref}
103
- {...extractLayerProps(restProps, 'motion-path')}
103
+ {...extractLayerProps(restProps, 'lc-motion-path')}
104
104
  >
105
105
  <mpath href="#{pathId}" />
106
106
  </animateMotion>
@@ -25,10 +25,17 @@ export type PackProps<T> = {
25
25
  nodes: HierarchyCircularNode<T>[];
26
26
  }]>;
27
27
  };
28
+ declare function $$render<T>(): {
29
+ props: PackProps<T>;
30
+ exports: {};
31
+ bindings: "nodes";
32
+ slots: {};
33
+ events: {};
34
+ };
28
35
  declare class __sveltets_Render<T> {
29
- props(): PackProps<T>;
30
- events(): {};
31
- slots(): {};
36
+ props(): ReturnType<typeof $$render<T>>['props'];
37
+ events(): ReturnType<typeof $$render<T>>['events'];
38
+ slots(): ReturnType<typeof $$render<T>>['slots'];
32
39
  bindings(): "nodes";
33
40
  exports(): {};
34
41
  }
@@ -32,10 +32,17 @@ export type PartitionProps<T> = {
32
32
  nodes: HierarchyRectangularNode<T>[];
33
33
  }]>;
34
34
  };
35
+ declare function $$render<T>(): {
36
+ props: PartitionProps<T>;
37
+ exports: {};
38
+ bindings: "nodes";
39
+ slots: {};
40
+ events: {};
41
+ };
35
42
  declare class __sveltets_Render<T> {
36
- props(): PartitionProps<T>;
37
- events(): {};
38
- slots(): {};
43
+ props(): ReturnType<typeof $$render<T>>['props'];
44
+ events(): ReturnType<typeof $$render<T>>['events'];
45
+ slots(): ReturnType<typeof $$render<T>>['slots'];
39
46
  bindings(): "nodes";
40
47
  exports(): {};
41
48
  }
@@ -154,7 +154,7 @@
154
154
  const lineDefs = Array.isArray(linesProp) ? linesProp : linesProp === true ? [{}] : [linesProp];
155
155
  for (const line of lineDefs) {
156
156
  // const spacing = Math.abs(line.spacing);
157
- const stroke = line.color ?? 'var(--color-surface-content)';
157
+ const stroke = line.color ?? 'var(--color-surface-content, currentColor)';
158
158
  const strokeWidth = line.width ?? 1;
159
159
  const opacity = line.opacity ?? 1;
160
160
 
@@ -217,7 +217,7 @@
217
217
  cx: size / 4,
218
218
  cy: size / 4,
219
219
  r: circle.radius ?? 1,
220
- fill: circle.color ?? 'var(--color-surface-content)',
220
+ fill: circle.color ?? 'var(--color-surface-content, currentColor)',
221
221
  opacity: circle.opacity ?? 1,
222
222
  },
223
223
  {
@@ -225,7 +225,7 @@
225
225
  cx: (size * 3) / 4,
226
226
  cy: (size * 3) / 4,
227
227
  r: circle.radius ?? 1,
228
- fill: circle.color ?? 'var(--color-surface-content)',
228
+ fill: circle.color ?? 'var(--color-surface-content, currentColor)',
229
229
  opacity: circle.opacity ?? 1,
230
230
  }
231
231
  );
@@ -235,7 +235,7 @@
235
235
  cx: size / 2,
236
236
  cy: size / 2,
237
237
  r: circle.radius ?? 1,
238
- fill: circle.color ?? 'var(--color-surface-content)',
238
+ fill: circle.color ?? 'var(--color-surface-content, currentColor)',
239
239
  opacity: circle.opacity ?? 1,
240
240
  });
241
241
  }
@@ -265,7 +265,7 @@
265
265
  {width}
266
266
  {height}
267
267
  patternUnits="userSpaceOnUse"
268
- {...extractLayerProps(restProps, 'pattern')}
268
+ {...extractLayerProps(restProps, 'lc-pattern')}
269
269
  >
270
270
  {#if patternContent}
271
271
  {@render patternContent?.()}
@@ -81,7 +81,6 @@
81
81
  import type { TooltipContextValue } from './tooltip/TooltipContext.svelte';
82
82
  import { getChartContext } from './Chart.svelte';
83
83
  import type { Snippet } from 'svelte';
84
- import { layerClass } from '../utils/attributes.js';
85
84
 
86
85
  /*
87
86
  TODO:
@@ -140,7 +139,7 @@
140
139
  {:else}
141
140
  {#each arcs as arc}
142
141
  <Arc
143
- class={layerClass('pie-arc')}
142
+ class="lc-pie-arc"
144
143
  startAngle={arc.startAngle}
145
144
  endAngle={arc.endAngle}
146
145
  padAngle={arc.padAngle}
@@ -45,11 +45,9 @@
45
45
  </script>
46
46
 
47
47
  <script lang="ts">
48
- import { extent } from 'd3-array';
49
48
  import { pointRadial } from 'd3-shape';
50
49
 
51
50
  import Circle, { type CircleProps } from './Circle.svelte';
52
- import Link from './Link.svelte';
53
51
  import { isScaleBand, type AnyScale } from '../utils/scales.svelte.js';
54
52
  import { accessor, type Accessor } from '../utils/common.js';
55
53
  import { getChartContext } from './Chart.svelte';
@@ -143,7 +141,7 @@
143
141
  {stroke}
144
142
  {strokeWidth}
145
143
  {opacity}
146
- {...extractLayerProps(restProps, 'point')}
144
+ {...extractLayerProps(restProps, 'lc-point')}
147
145
  />
148
146
  {/each}
149
147
  {/if}
@@ -144,7 +144,6 @@
144
144
  import { registerCanvasComponent } from './layout/Canvas.svelte';
145
145
  import { renderPathData, type ComputedStylesOptions } from '../utils/canvas.js';
146
146
  import { createKey } from '../utils/key.svelte.js';
147
- import { layerClass } from '../utils/attributes.js';
148
147
  import { polygon } from '../utils/shape.js';
149
148
  import { roundedPolygonPath } from '../utils/path.js';
150
149
 
@@ -234,7 +233,7 @@
234
233
  ? merge({ styles: { strokeWidth } }, styleOverrides)
235
234
  : {
236
235
  styles: { fill, fillOpacity, stroke, strokeWidth, opacity },
237
- classes: cls(layerClass('polygon'), fill == null && 'fill-surface-content', className),
236
+ classes: cls('lc-polygon', className),
238
237
  }
239
238
  );
240
239
  }
@@ -278,8 +277,33 @@
278
277
  {stroke}
279
278
  stroke-width={strokeWidth}
280
279
  {opacity}
281
- class={cls(layerClass('polygon'), fill == null && 'fill-surface-content', className)}
280
+ class={cls('lc-polygon', className)}
282
281
  {...restProps}
283
282
  bind:this={ref}
284
283
  />
285
284
  {/if}
285
+
286
+ <style>
287
+ @layer base {
288
+ :global(:where(.lc-polygon)) {
289
+ --fill-color: var(--color-surface-content, currentColor);
290
+ --stroke-color: initial;
291
+ }
292
+
293
+ /* Svg | Canvas layers */
294
+ :global(:where(.lc-layout-svg .lc-polygon, svg.lc-polygon):not([fill])) {
295
+ fill: var(--fill-color);
296
+ }
297
+ :global(:where(.lc-layout-svg .lc-polygon, svg.lc-polygon):not([stroke])) {
298
+ stroke: var(--stroke-color);
299
+ }
300
+
301
+ /* Html layers */
302
+ :global(:where(.lc-layout-html .lc-polygon):not([background-color])) {
303
+ background-color: var(--fill-color);
304
+ }
305
+ :global(:where(.lc-layout-html .lc-polygon):not([border-color])) {
306
+ border-color: var(--stroke-color);
307
+ }
308
+ }
309
+ </style>
@@ -89,7 +89,7 @@
89
89
  import { parsePercent } from '../utils/math.js';
90
90
  import { getChartContext } from './Chart.svelte';
91
91
  import { createId } from '../utils/createId.js';
92
- import { extractLayerProps, layerClass } from '../utils/attributes.js';
92
+ import { extractLayerProps } from '../utils/attributes.js';
93
93
  import { cls } from '@layerstack/tailwind';
94
94
 
95
95
  const uid = $props.id();
@@ -167,12 +167,12 @@
167
167
  {spreadMethod}
168
168
  gradientTransform={transform}
169
169
  gradientUnits={units}
170
- {...extractLayerProps({ ...restProps, class: className }, 'radial-gradient')}
170
+ {...extractLayerProps({ ...restProps, class: className }, 'lc-radial-gradient')}
171
171
  >
172
172
  {#if stopsContent}
173
173
  {@render stopsContent()}
174
174
  {:else if stops}
175
- {@const stopClass = cls(layerClass('radial-gradient-stop'), className)}
175
+ {@const stopClass = cls('lc-radial-gradient-stop', className)}
176
176
  {#each stops as stop, i}
177
177
  {#if Array.isArray(stop)}
178
178
  <stop offset={stop[0]} stop-color={stop[1]} class={stopClass} />
@@ -1,5 +1,5 @@
1
1
  <script lang="ts" module>
2
- import type { CommonStyleProps, Without } from '../utils/types.js';
2
+ import type { CommonEvents, CommonStyleProps, Without } from '../utils/types.js';
3
3
  import type { SVGAttributes } from 'svelte/elements';
4
4
  import { createMotion, parseMotionProp, type MotionProp } from '../utils/motion.svelte.js';
5
5
  import { renderRect, type ComputedStylesOptions } from '../utils/canvas.js';
@@ -39,7 +39,8 @@
39
39
  } & CommonStyleProps;
40
40
 
41
41
  export type RectProps = RectPropsWithoutHTML &
42
- Without<SVGAttributes<SVGRectElement>, RectPropsWithoutHTML>;
42
+ Without<SVGAttributes<SVGRectElement>, RectPropsWithoutHTML> &
43
+ CommonEvents;
43
44
  </script>
44
45
 
45
46
  <script lang="ts">
@@ -49,7 +50,6 @@
49
50
  import { getRenderContext } from './Chart.svelte';
50
51
  import { registerCanvasComponent } from './layout/Canvas.svelte';
51
52
  import { createKey } from '../utils/key.svelte.js';
52
- import { layerClass } from '../utils/attributes.js';
53
53
 
54
54
  let {
55
55
  height,
@@ -107,7 +107,7 @@
107
107
  ? merge({ styles: { strokeWidth } }, styleOverrides)
108
108
  : {
109
109
  styles: { fill, fillOpacity, stroke, strokeWidth, opacity },
110
- classes: className,
110
+ classes: cls('lc-rect', className),
111
111
  }
112
112
  );
113
113
  }
@@ -155,7 +155,7 @@
155
155
  {stroke}
156
156
  stroke-width={strokeWidth}
157
157
  {opacity}
158
- class={cls(layerClass('rect'), fill == null && 'fill-surface-content', className)}
158
+ class={cls('lc-rect', className)}
159
159
  {...restProps}
160
160
  {onclick}
161
161
  {ondblclick}
@@ -166,4 +166,54 @@
166
166
  {onpointerout}
167
167
  bind:this={ref}
168
168
  />
169
+ {:else if renderCtx === 'html'}
170
+ <!-- svelte-ignore a11y_click_events_have_key_events -->
171
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
172
+ <div
173
+ style:position="absolute"
174
+ style:left="{motionX.current}px"
175
+ style:top="{motionY.current}px"
176
+ style:width="{motionWidth.current}px"
177
+ style:height="{motionHeight.current}px"
178
+ style:background={fill}
179
+ style:background-opacity={opacity}
180
+ style:border-width="{strokeWidth}px"
181
+ style:border-style="solid"
182
+ style:border-color={stroke}
183
+ style:border-radius="{restProps.rx}px"
184
+ class={cls('lc-rect', className)}
185
+ {...restProps as any}
186
+ {onclick}
187
+ {ondblclick}
188
+ {onpointerenter}
189
+ {onpointermove}
190
+ {onpointerleave}
191
+ {onpointerover}
192
+ {onpointerout}
193
+ ></div>
169
194
  {/if}
195
+
196
+ <style>
197
+ @layer base {
198
+ :global(:where(.lc-rect)) {
199
+ --fill-color: var(--color-surface-content, currentColor);
200
+ --stroke-color: initial;
201
+ }
202
+
203
+ /* Svg | Canvas layers */
204
+ :global(:where(.lc-layout-svg .lc-rect, svg.lc-rect):not([fill])) {
205
+ fill: var(--fill-color);
206
+ }
207
+ :global(:where(.lc-layout-svg .lc-rect, svg.lc-rect):not([stroke])) {
208
+ stroke: var(--stroke-color);
209
+ }
210
+
211
+ /* Html layers */
212
+ :global(:where(.lc-layout-html .lc-rect):not([background])) {
213
+ background: var(--fill-color);
214
+ }
215
+ :global(:where(.lc-layout-html .lc-rect):not([border-color])) {
216
+ border-color: var(--stroke-color);
217
+ }
218
+ }
219
+ </style>
@@ -1,4 +1,4 @@
1
- import type { CommonStyleProps, Without } from '../utils/types.js';
1
+ import type { CommonEvents, CommonStyleProps, Without } from '../utils/types.js';
2
2
  import type { SVGAttributes } from 'svelte/elements';
3
3
  import { type MotionProp } from '../utils/motion.svelte.js';
4
4
  export type RectPropsWithoutHTML = {
@@ -30,7 +30,7 @@ export type RectPropsWithoutHTML = {
30
30
  ref?: SVGRectElement;
31
31
  motion?: MotionProp<'x' | 'y' | 'width' | 'height'>;
32
32
  } & CommonStyleProps;
33
- export type RectProps = RectPropsWithoutHTML & Without<SVGAttributes<SVGRectElement>, RectPropsWithoutHTML>;
33
+ export type RectProps = RectPropsWithoutHTML & Without<SVGAttributes<SVGRectElement>, RectPropsWithoutHTML> & CommonEvents;
34
34
  declare const Rect: import("svelte").Component<RectProps, {}, "ref">;
35
35
  type Rect = ReturnType<typeof Rect>;
36
36
  export default Rect;
@@ -1,6 +1,6 @@
1
1
  <script lang="ts" module>
2
2
  import Rect, { type RectPropsWithoutHTML } from './Rect.svelte';
3
- import type { Without } from '../utils/types.js';
3
+ import type { CommonEvents, Without } from '../utils/types.js';
4
4
  import type { SVGAttributes } from 'svelte/elements';
5
5
  import type { Snippet } from 'svelte';
6
6
 
@@ -58,7 +58,8 @@
58
58
  Without<RectPropsWithoutHTML, BaseRectClipPathPropsWithoutHTML>;
59
59
 
60
60
  export type RectClipPathProps = RectClipPathPropsWithoutHTML &
61
- Without<SVGAttributes<SVGElement>, RectClipPathPropsWithoutHTML>;
61
+ Without<SVGAttributes<SVGElement>, RectClipPathPropsWithoutHTML> &
62
+ CommonEvents;
62
63
  </script>
63
64
 
64
65
  <script lang="ts">
@@ -81,7 +82,7 @@
81
82
 
82
83
  <ClipPath {id} {disabled}>
83
84
  {#snippet clip()}
84
- <Rect {x} {y} {...extractLayerProps(restProps, 'clip-path-rect')} />
85
+ <Rect {x} {y} {...extractLayerProps(restProps, 'lc-clip-path-rect')} />
85
86
  {/snippet}
86
87
  {#snippet children({ url })}
87
88
  {@render childrenProp?.({ id, url })}
@@ -1,5 +1,5 @@
1
1
  import { type RectPropsWithoutHTML } from './Rect.svelte';
2
- import type { Without } from '../utils/types.js';
2
+ import type { CommonEvents, Without } from '../utils/types.js';
3
3
  import type { SVGAttributes } from 'svelte/elements';
4
4
  import type { Snippet } from 'svelte';
5
5
  export type BaseRectClipPathPropsWithoutHTML = {
@@ -48,7 +48,7 @@ export type BaseRectClipPathPropsWithoutHTML = {
48
48
  motion?: MotionProp<'x' | 'y' | 'width' | 'height'>;
49
49
  };
50
50
  export type RectClipPathPropsWithoutHTML = BaseRectClipPathPropsWithoutHTML & Without<RectPropsWithoutHTML, BaseRectClipPathPropsWithoutHTML>;
51
- export type RectClipPathProps = RectClipPathPropsWithoutHTML & Without<SVGAttributes<SVGElement>, RectClipPathPropsWithoutHTML>;
51
+ export type RectClipPathProps = RectClipPathPropsWithoutHTML & Without<SVGAttributes<SVGElement>, RectClipPathPropsWithoutHTML> & CommonEvents;
52
52
  import type { MotionProp } from '../utils/motion.svelte.js';
53
53
  declare const RectClipPath: import("svelte").Component<RectClipPathProps, {}, "">;
54
54
  type RectClipPath = ReturnType<typeof RectClipPath>;
@@ -61,7 +61,6 @@
61
61
  import Line, { type LinePropsWithoutHTML } from './Line.svelte';
62
62
  import { getChartContext } from './Chart.svelte';
63
63
  import { accessor, chartDataArray, type Accessor } from '../utils/common.js';
64
- import { layerClass } from '../utils/attributes.js';
65
64
  import { isScaleBand, isScaleNumeric } from '../utils/scales.svelte.js';
66
65
 
67
66
  let {
@@ -188,9 +187,9 @@
188
187
  // $inspect({ lines });
189
188
  </script>
190
189
 
191
- <Group class={layerClass('rule-g')}>
190
+ <Group class="lc-rule-g">
192
191
  {#each lines as line}
193
- {@const stroke = line.stroke}
192
+ {@const stroke = line.stroke ?? strokeProp}
194
193
 
195
194
  {#if ctx.radial}
196
195
  {#if line.axis === 'x'}
@@ -203,23 +202,10 @@
203
202
  {x2}
204
203
  {y2}
205
204
  {stroke}
206
- class={cls(
207
- layerClass('rule-x-radial-line'),
208
- !stroke && 'stroke-surface-content/10',
209
- className
210
- )}
205
+ class={cls('lc-rule-x-radial-line', className)}
211
206
  />
212
207
  {:else if line.axis === 'y'}
213
- <Circle
214
- r={line.y1}
215
- {stroke}
216
- class={cls(
217
- layerClass('rule-y-radial-circle'),
218
- !stroke && 'stroke-surface-content/50',
219
- 'fill-none',
220
- className
221
- )}
222
- />
208
+ <Circle r={line.y1} {stroke} class={cls('lc-rule-y-radial-circle', className)} />
223
209
  {/if}
224
210
  {:else}
225
211
  <Line
@@ -229,12 +215,33 @@
229
215
  x2={line.x2}
230
216
  y2={line.y2}
231
217
  {stroke}
232
- class={cls(
233
- layerClass(line.axis === 'x' ? 'rule-x-line' : 'rule-y-line'),
234
- !stroke && 'stroke-surface-content/50',
235
- className
236
- )}
218
+ class={cls(line.axis === 'x' ? 'lc-rule-x-line' : 'lc-rule-y-line', className)}
237
219
  />
238
220
  {/if}
239
221
  {/each}
240
222
  </Group>
223
+
224
+ <style>
225
+ @layer components {
226
+ /* TODO: better way to handle this without affecting other components? */
227
+ /* Could add a layer between "components" and "base" but would require more setup (and not alignw with TW layers) */
228
+ :global(
229
+ :where(
230
+ .lc-rule-x-line,
231
+ .lc-rule-y-line,
232
+ .lc-rule-x-radial-line,
233
+ .lc-rule-y-radial-circle
234
+ ):not([class*='lc-axis'], [class*='lc-grid'])
235
+ ) {
236
+ --stroke-color: color-mix(
237
+ in oklab,
238
+ var(--color-surface-content, currentColor) 50%,
239
+ transparent
240
+ );
241
+ }
242
+
243
+ :global(:where(.lc-rule-y-radial-circle)) {
244
+ --fill-color: none;
245
+ }
246
+ }
247
+ </style>