layerchart 2.0.0-next.38 → 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 (96) 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/Bar.svelte +6 -5
  8. package/dist/components/Bar.svelte.d.ts +2 -2
  9. package/dist/components/Bars.svelte +3 -3
  10. package/dist/components/Blur.svelte +2 -3
  11. package/dist/components/BrushContext.svelte +44 -44
  12. package/dist/components/Calendar.svelte +21 -4
  13. package/dist/components/Chart.svelte +1 -2
  14. package/dist/components/ChartClipPath.svelte +1 -1
  15. package/dist/components/Circle.svelte +44 -3
  16. package/dist/components/CircleClipPath.svelte +8 -1
  17. package/dist/components/ClipPath.svelte +1 -2
  18. package/dist/components/ColorRamp.svelte +1 -1
  19. package/dist/components/ComputedStyles.svelte +9 -2
  20. package/dist/components/Connector.svelte +1 -1
  21. package/dist/components/Ellipse.svelte +44 -3
  22. package/dist/components/Frame.svelte +1 -1
  23. package/dist/components/GeoCircle.svelte +1 -1
  24. package/dist/components/GeoEdgeFade.svelte +1 -1
  25. package/dist/components/GeoPath.svelte +18 -3
  26. package/dist/components/GeoPoint.svelte +3 -3
  27. package/dist/components/GeoSpline.svelte +1 -1
  28. package/dist/components/GeoTile.svelte +1 -1
  29. package/dist/components/Graticule.svelte +5 -5
  30. package/dist/components/Grid.svelte +57 -60
  31. package/dist/components/Group.svelte +11 -6
  32. package/dist/components/Highlight.svelte +46 -22
  33. package/dist/components/Highlight.svelte.d.ts +4 -0
  34. package/dist/components/Hull.svelte +11 -4
  35. package/dist/components/Labels.svelte +21 -11
  36. package/dist/components/Legend.svelte +133 -67
  37. package/dist/components/Legend.svelte.d.ts +7 -3
  38. package/dist/components/Line.svelte +40 -3
  39. package/dist/components/LinearGradient.svelte +35 -4
  40. package/dist/components/Link.svelte +1 -1
  41. package/dist/components/Marker.svelte +37 -26
  42. package/dist/components/MonthPath.svelte +14 -3
  43. package/dist/components/MotionPath.svelte +1 -1
  44. package/dist/components/Pattern.svelte +5 -5
  45. package/dist/components/Pie.svelte +1 -2
  46. package/dist/components/Points.svelte +1 -1
  47. package/dist/components/Polygon.svelte +27 -3
  48. package/dist/components/RadialGradient.svelte +3 -3
  49. package/dist/components/Rect.svelte +55 -5
  50. package/dist/components/Rect.svelte.d.ts +2 -2
  51. package/dist/components/RectClipPath.svelte +4 -3
  52. package/dist/components/RectClipPath.svelte.d.ts +2 -2
  53. package/dist/components/Rule.svelte +30 -23
  54. package/dist/components/Spline.svelte +29 -10
  55. package/dist/components/Text.svelte +59 -13
  56. package/dist/components/TileImage.svelte +19 -4
  57. package/dist/components/TransformContext.svelte +9 -3
  58. package/dist/components/TransformControls.svelte +72 -17
  59. package/dist/components/Voronoi.svelte +12 -13
  60. package/dist/components/charts/ArcChart.svelte +40 -69
  61. package/dist/components/charts/AreaChart.svelte +19 -42
  62. package/dist/components/charts/BarChart.svelte +7 -18
  63. package/dist/components/charts/DefaultTooltip.svelte +2 -2
  64. package/dist/components/charts/DefaultTooltip.svelte.d.ts +1 -1
  65. package/dist/components/charts/LineChart.svelte +61 -66
  66. package/dist/components/charts/LineChart.svelte.d.ts +11 -5
  67. package/dist/components/charts/PieChart.svelte +41 -69
  68. package/dist/components/charts/ScatterChart.svelte +8 -19
  69. package/dist/components/charts/utils.svelte.d.ts +1 -19
  70. package/dist/components/charts/utils.svelte.js +7 -39
  71. package/dist/components/layout/Canvas.svelte +29 -20
  72. package/dist/components/layout/Html.svelte +15 -9
  73. package/dist/components/layout/Svg.svelte +19 -11
  74. package/dist/components/layout/WebGL.svelte +26 -6
  75. package/dist/components/layout/WebGL.svelte.d.ts +5 -2
  76. package/dist/components/tooltip/Tooltip.svelte +60 -29
  77. package/dist/components/tooltip/TooltipContext.svelte +73 -36
  78. package/dist/components/tooltip/TooltipContext.svelte.d.ts +7 -0
  79. package/dist/components/tooltip/TooltipHeader.svelte +27 -14
  80. package/dist/components/tooltip/TooltipItem.svelte +41 -33
  81. package/dist/components/tooltip/TooltipList.svelte +12 -10
  82. package/dist/components/tooltip/TooltipSeparator.svelte +18 -10
  83. package/dist/states/series.svelte.d.ts +30 -0
  84. package/dist/states/series.svelte.js +54 -0
  85. package/dist/styles/daisyui-5.css +6 -0
  86. package/dist/styles/shadcn-svelte.css +11 -0
  87. package/dist/styles/skeleton-3.css +15 -0
  88. package/dist/utils/attributes.d.ts +3 -13
  89. package/dist/utils/attributes.js +4 -18
  90. package/dist/utils/common.d.ts +9 -0
  91. package/dist/utils/common.js +18 -1
  92. package/dist/utils/common.test.js +26 -1
  93. package/dist/utils/math.d.ts +17 -0
  94. package/dist/utils/math.js +17 -0
  95. package/dist/utils/types.d.ts +15 -2
  96. package/package.json +5 -1
@@ -65,7 +65,6 @@
65
65
  import Spline from './Spline.svelte';
66
66
  import { getChartContext } from './Chart.svelte';
67
67
  import { getGeoContext } from './GeoContext.svelte';
68
- import { layerClass } from '../utils/attributes.js';
69
68
 
70
69
  let {
71
70
  data,
@@ -104,13 +103,13 @@
104
103
  );
105
104
  </script>
106
105
 
107
- <Group {...restProps} class={cls(layerClass('hull-g'), classes.root, className)} bind:ref>
106
+ <Group {...restProps} class={cls('lc-hull-g', classes.root, className)} bind:ref>
108
107
  {#if geoCtx.projection}
109
108
  {@const polygon = geoVoronoi().hull(points)}
110
109
  <GeoPath
111
110
  geojson={polygon}
112
111
  {curve}
113
- class={cls(layerClass('hull-path'), 'fill-transparent', classes.path)}
112
+ class={['lc-hull-path', classes.path]}
114
113
  onclick={(e) => onclick?.(e, { points, polygon })}
115
114
  onpointermove={(e) => onpointermove?.(e, { points, polygon })}
116
115
  {onpointerleave}
@@ -123,10 +122,18 @@
123
122
  x={(d) => d[0]}
124
123
  y={(d) => d[1]}
125
124
  {curve}
126
- class={cls(layerClass('hull-class'), 'fill-transparent', classes.path)}
125
+ class={['lc-hull-class', classes.path]}
127
126
  onclick={(e) => onclick?.(e, { points, polygon })}
128
127
  onpointermove={(e) => onpointermove?.(e, { points, polygon })}
129
128
  {onpointerleave}
130
129
  />
131
130
  {/if}
132
131
  </Group>
132
+
133
+ <style>
134
+ @layer components {
135
+ :global(:where(.lc-hull-path, .lc-hull-geo-path)) {
136
+ fill: transparent;
137
+ }
138
+ }
139
+ </style>
@@ -74,7 +74,7 @@
74
74
  import { isScaleBand } from '../utils/scales.svelte.js';
75
75
  import { getChartContext } from './Chart.svelte';
76
76
  import Group from './Group.svelte';
77
- import { extractLayerProps, layerClass } from '../utils/attributes.js';
77
+ import { extractLayerProps } from '../utils/attributes.js';
78
78
 
79
79
  const ctx = getChartContext();
80
80
 
@@ -174,28 +174,38 @@
174
174
  }
175
175
  </script>
176
176
 
177
- <Group class={layerClass('labels-g')}>
177
+ <Group class="lc-labels-g">
178
178
  <Points {data} {x} {y}>
179
179
  {#snippet children({ points })}
180
180
  {#each points as point, i (key(point.data, i))}
181
- {@const textProps = extractLayerProps(getTextProps(point), 'labels-text')}
181
+ {@const textProps = extractLayerProps(getTextProps(point), 'lc-labels-text')}
182
182
  {#if childrenProp}
183
183
  {@render childrenProp({ data: point, textProps })}
184
184
  {:else}
185
185
  <Text
186
+ data-placement={placement}
186
187
  {...textProps}
187
188
  {...restProps}
188
- class={cls(
189
- 'text-xs',
190
- placement === 'inside'
191
- ? 'fill-surface-300 stroke-surface-content'
192
- : 'fill-surface-content stroke-surface-100',
193
- textProps.class,
194
- className
195
- )}
189
+ {...extractLayerProps(getTextProps(point), 'lc-labels-text', className ?? '')}
196
190
  />
197
191
  {/if}
198
192
  {/each}
199
193
  {/snippet}
200
194
  </Points>
201
195
  </Group>
196
+
197
+ <style>
198
+ @layer components {
199
+ :global(:where(.lc-labels-text)) {
200
+ font-size: 12px;
201
+
202
+ --fill-color: var(--color-surface-content, currentColor);
203
+ --stroke-color: var(--color-surface-100, light-dark(white, black));
204
+
205
+ &[data-placement='inside'] {
206
+ --fill-color: var(--color-surface-100, light-dark(white, black));
207
+ --stroke-color: var(--color-surface-content, currentColor);
208
+ }
209
+ }
210
+ }
211
+ </style>
@@ -65,10 +65,6 @@
65
65
  */
66
66
  orientation?: 'horizontal' | 'vertical';
67
67
 
68
- onclick?: (e: MouseEvent, detail: LegendItem) => any;
69
- onpointerenter?: (e: MouseEvent, detail: LegendItem) => any;
70
- onpointerleave?: (e: MouseEvent, detail: LegendItem) => any;
71
-
72
68
  /**
73
69
  * Determine display ramp (individual color swatches or continuous ramp)
74
70
  *
@@ -76,6 +72,11 @@
76
72
  */
77
73
  variant?: 'ramp' | 'swatches';
78
74
 
75
+ /**
76
+ * An array of selected items. If provided, the legend fades unselected items.
77
+ */
78
+ selected?: string[];
79
+
79
80
  /**
80
81
  * Classes to apply to the elements.
81
82
  *
@@ -91,6 +92,10 @@
91
92
  item?: string | ((item: LegendItem) => string);
92
93
  };
93
94
 
95
+ onclick?: (e: MouseEvent, detail: LegendItem) => any;
96
+ onpointerenter?: (e: MouseEvent, detail: LegendItem) => any;
97
+ onpointerleave?: (e: MouseEvent, detail: LegendItem) => any;
98
+
94
99
  /**
95
100
  * A bindable reference to the wrapping `<div>` element.
96
101
  *
@@ -116,7 +121,8 @@
116
121
  import { cls } from '@layerstack/tailwind';
117
122
  import type { AnyScale } from '../utils/scales.svelte.js';
118
123
  import { getChartContext } from './Chart.svelte';
119
- import { extractLayerProps, layerClass } from '../utils/attributes.js';
124
+ import { extractLayerProps } from '../utils/attributes.js';
125
+ import { resolveMaybeFn } from '../utils/common.js';
120
126
 
121
127
  let {
122
128
  scale: scaleProp,
@@ -134,6 +140,7 @@
134
140
  onpointerenter,
135
141
  onpointerleave,
136
142
  variant = 'ramp',
143
+ selected = [],
137
144
  classes = {},
138
145
  ref: refProp = $bindable(),
139
146
  class: className,
@@ -296,29 +303,9 @@
296
303
  bind:this={ref}
297
304
  {...restProps}
298
305
  data-placement={placement}
299
- class={cls(
300
- layerClass('legend-container'),
301
- 'inline-block',
302
- 'z-1', // stack above tooltip context layers (band rects, voronoi, ...)
303
- placement && [
304
- 'absolute',
305
- {
306
- 'top-left': 'top-0 left-0',
307
- top: 'top-0 left-1/2 -translate-x-1/2',
308
- 'top-right': 'top-0 right-0',
309
- left: 'top-1/2 left-0 -translate-y-1/2',
310
- center: 'top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2',
311
- right: 'top-1/2 right-0 -translate-y-1/2',
312
- 'bottom-left': 'bottom-0 left-0',
313
- bottom: 'bottom-0 left-1/2 -translate-x-1/2',
314
- 'bottom-right': 'bottom-0 right-0',
315
- }[placement],
316
- ],
317
- className,
318
- classes.root
319
- )}
306
+ class={cls('lc-legend-container', className, classes.root)}
320
307
  >
321
- <div class={cls(layerClass('legend-title'), 'text-[10px] font-semibold', classes.title)}>
308
+ <div class={cls('lc-legend-title', classes.title)}>
322
309
  {title}
323
310
  </div>
324
311
  {#if children}
@@ -331,35 +318,31 @@
331
318
  {width}
332
319
  height={height + tickLengthProp + tickFontSize}
333
320
  viewBox="0 0 {width} {height + tickLengthProp + tickFontSize}"
334
- class={cls(layerClass('legend-ramp-svg'), 'overflow-visible')}
321
+ class={cls('lc-legend-ramp-svg')}
335
322
  >
336
- <g class={layerClass('legend-ramp-g')}>
323
+ <g class="lc-legend-ramp-g">
337
324
  {#if scaleConfig.interpolator}
338
325
  <ColorRamp
339
326
  {width}
340
327
  {height}
341
328
  interpolator={scaleConfig.interpolator}
342
- class={layerClass('legend-color-ramp')}
329
+ class="lc-legend-color-ramp"
343
330
  />
344
331
  {:else if scaleConfig.swatches}
345
332
  {#each scaleConfig.swatches as swatch, i}
346
- <rect {...extractLayerProps(swatch, 'legend-swatch')} />
333
+ <rect {...extractLayerProps(swatch, 'lc-legend-ramp-swatch')} />
347
334
  {/each}
348
335
  {/if}
349
336
  </g>
350
337
 
351
- <g class={layerClass('legend-tick-group')}>
338
+ <g class="lc-legend-tick-group">
352
339
  {#each tickValuesProp ?? scaleConfig.xScale?.ticks?.(ticks) ?? [] as tick, i}
353
340
  <text
354
341
  text-anchor="middle"
355
342
  x={scaleConfig.xScale?.(tick) + scaleConfig.tickLabelOffset}
356
343
  y={height + tickLengthProp + tickFontSize}
357
344
  style:font-size={tickFontSize}
358
- class={cls(
359
- layerClass('legend-tick-text'),
360
- 'text-[10px] fill-surface-content',
361
- classes.label
362
- )}
345
+ class={cls('lc-legend-tick-text', classes.label)}
363
346
  >
364
347
  <!-- @ts-expect-error - improve types -->
365
348
  {tickFormatProp ? format(tick, asAny(tickFormatProp)) : tick}
@@ -371,50 +354,26 @@
371
354
  y1={0}
372
355
  x2={scaleConfig.xScale?.(tick)}
373
356
  y2={height + tickLengthProp}
374
- class={cls(layerClass('legend-tick-line'), 'stroke-surface-content', classes.tick)}
357
+ class={cls('lc-legend-tick-line', classes.tick)}
375
358
  />
376
359
  {/if}
377
360
  {/each}
378
361
  </g>
379
362
  </svg>
380
363
  {:else if variant === 'swatches'}
381
- <div
382
- class={cls(
383
- layerClass('legend-swatch-group'),
384
- 'flex gap-x-4 gap-y-1',
385
- orientation === 'vertical' && 'flex-col',
386
- classes.items
387
- )}
388
- >
364
+ <div class={cls('lc-legend-swatch-group', classes.items)} data-orientation={orientation}>
389
365
  {#each scaleConfig.tickValues ?? scaleConfig.xScale?.ticks?.(ticks) ?? [] as tick}
390
366
  {@const color = scale?.(tick) ?? ''}
391
367
  {@const item = { value: tick, color }}
392
368
  <button
393
- class={cls(
394
- layerClass('legend-swatch-button'),
395
- 'flex items-center gap-1 truncate',
396
- !onclick && 'cursor-auto',
397
- typeof classes.item === 'function' ? classes.item(item) : classes.item
398
- )}
369
+ class={cls('lc-legend-swatch-button', resolveMaybeFn(classes?.item, item))}
370
+ style:opacity={selected.length === 0 || selected.includes(tick) ? 1 : 0.3}
399
371
  onclick={(e) => onclick?.(e, item)}
400
372
  onpointerenter={(e) => onpointerenter?.(e, item)}
401
373
  onpointerleave={(e) => onpointerleave?.(e, item)}
402
374
  >
403
- <div
404
- class={cls(
405
- layerClass('legend-swatch'),
406
- 'h-4 w-4 shrink-0 rounded-full',
407
- classes.swatch
408
- )}
409
- style:background-color={color}
410
- ></div>
411
- <div
412
- class={cls(
413
- layerClass('legend-swatch-label'),
414
- 'text-xs text-surface-content truncate whitespace-nowrap',
415
- classes.label
416
- )}
417
- >
375
+ <div class={cls('lc-legend-swatch', classes.swatch)} style:background-color={color}></div>
376
+ <div class={cls('lc-legend-swatch-label', classes.label)}>
418
377
  <!-- @ts-expect-error - improve types -->
419
378
  {tickFormatProp ? format(tick, asAny(tickFormatProp)) : tick}
420
379
  </div>
@@ -423,3 +382,110 @@
423
382
  </div>
424
383
  {/if}
425
384
  </div>
385
+
386
+ <style>
387
+ @layer components {
388
+ :where(.lc-legend-container) {
389
+ display: inline-block;
390
+ z-index: 1; /*stack above tooltip context layers (band rects, voronoi, ...) */
391
+
392
+ &[data-placement] {
393
+ position: absolute;
394
+ }
395
+
396
+ &[data-placement='top-left'] {
397
+ top: 0;
398
+ left: 0;
399
+ }
400
+ &[data-placement='top'] {
401
+ top: 0;
402
+ left: 50%;
403
+ transform: translateX(-50%);
404
+ }
405
+ &[data-placement='top-right'] {
406
+ top: 0;
407
+ right: 0;
408
+ }
409
+ &[data-placement='left'] {
410
+ top: 50%;
411
+ left: 0;
412
+ transform: translateY(-50%);
413
+ }
414
+ &[data-placement='center'] {
415
+ top: 50%;
416
+ left: 50%;
417
+ transform: translate(-50%, -50%);
418
+ }
419
+ &[data-placement='right'] {
420
+ top: 50%;
421
+ right: 0;
422
+ transform: translateY(-50%);
423
+ }
424
+ &[data-placement='bottom-left'] {
425
+ bottom: 0;
426
+ left: 0;
427
+ }
428
+ &[data-placement='bottom'] {
429
+ bottom: 0;
430
+ left: 50%;
431
+ transform: translateX(-50%);
432
+ }
433
+ &[data-placement='bottom-right'] {
434
+ bottom: 0;
435
+ right: 0;
436
+ }
437
+ }
438
+
439
+ :where(.lc-legend-title) {
440
+ font-size: 10px;
441
+ font-weight: 600;
442
+ }
443
+
444
+ :where(.lc-legend-ramp-svg) {
445
+ overflow: visible;
446
+ }
447
+
448
+ :where(.lc-legend-tick-text) {
449
+ font-size: 10px;
450
+ fill: var(--color-surface-content, currentColor);
451
+ }
452
+
453
+ :where(.lc-legend-tick-line) {
454
+ stroke: var(--color-surface-content, currentColor);
455
+ }
456
+
457
+ :where(.lc-legend-swatch-group) {
458
+ display: flex;
459
+ gap: 0.25rem 1rem;
460
+
461
+ &[data-orientation='vertical'] {
462
+ flex-direction: column;
463
+ }
464
+ }
465
+
466
+ :where(.lc-legend-swatch-button) {
467
+ display: flex;
468
+ align-items: center;
469
+ gap: 0.25rem;
470
+ white-space: nowrap;
471
+ overflow: hidden;
472
+ text-overflow: ellipsis;
473
+ }
474
+
475
+ :where(.lc-legend-swatch) {
476
+ width: 16px;
477
+ height: 16px;
478
+ flex-shrink: 0;
479
+ border-radius: 9999px; /* full */
480
+ }
481
+
482
+ :where(.lc-legend-swatch-label) {
483
+ font-size: 0.75rem; /* text-xs */
484
+ line-height: calc(1 / 0.75);
485
+ color: var(--color-surface-content, currentColor);
486
+ overflow: hidden;
487
+ text-overflow: ellipsis;
488
+ white-space: nowrap;
489
+ }
490
+ }
491
+ </style>
@@ -54,15 +54,16 @@ export type LegendPropsWithoutHTML = {
54
54
  * @default 'horizontal'
55
55
  */
56
56
  orientation?: 'horizontal' | 'vertical';
57
- onclick?: (e: MouseEvent, detail: LegendItem) => any;
58
- onpointerenter?: (e: MouseEvent, detail: LegendItem) => any;
59
- onpointerleave?: (e: MouseEvent, detail: LegendItem) => any;
60
57
  /**
61
58
  * Determine display ramp (individual color swatches or continuous ramp)
62
59
  *
63
60
  * @default 'ramp'
64
61
  */
65
62
  variant?: 'ramp' | 'swatches';
63
+ /**
64
+ * An array of selected items. If provided, the legend fades unselected items.
65
+ */
66
+ selected?: string[];
66
67
  /**
67
68
  * Classes to apply to the elements.
68
69
  *
@@ -77,6 +78,9 @@ export type LegendPropsWithoutHTML = {
77
78
  swatch?: string;
78
79
  item?: string | ((item: LegendItem) => string);
79
80
  };
81
+ onclick?: (e: MouseEvent, detail: LegendItem) => any;
82
+ onpointerenter?: (e: MouseEvent, detail: LegendItem) => any;
83
+ onpointerleave?: (e: MouseEvent, detail: LegendItem) => any;
80
84
  /**
81
85
  * A bindable reference to the wrapping `<div>` element.
82
86
  *
@@ -4,6 +4,7 @@
4
4
  import { renderPathData, type ComputedStylesOptions } from '../utils/canvas.js';
5
5
  import MarkerWrapper, { type MarkerOptions } from './MarkerWrapper.svelte';
6
6
  import type { CommonStyleProps, Without } from '../utils/types.js';
7
+ import { pointsToAngleAndLength } from '../utils/math.js';
7
8
 
8
9
  export type LinePropsWithoutHTML = {
9
10
  /**
@@ -98,7 +99,6 @@
98
99
 
99
100
  import { createKey } from '../utils/key.svelte.js';
100
101
  import { createId } from '../utils/createId.js';
101
- import { layerClass } from '../utils/attributes.js';
102
102
 
103
103
  const uid = $props.id();
104
104
 
@@ -148,7 +148,7 @@
148
148
  ? merge({ styles: { strokeWidth } }, styleOverrides)
149
149
  : {
150
150
  styles: { fill, stroke, strokeWidth, opacity },
151
- classes: className,
151
+ classes: cls('lc-line', className),
152
152
  }
153
153
  );
154
154
  }
@@ -195,10 +195,47 @@
195
195
  marker-start={markerStartId ? `url(#${markerStartId})` : undefined}
196
196
  marker-mid={markerMidId ? `url(#${markerMidId})` : undefined}
197
197
  marker-end={markerEndId ? `url(#${markerEndId})` : undefined}
198
- class={cls(layerClass('line'), stroke === undefined && 'stroke-surface-content', className)}
198
+ class={cls('lc-line', className)}
199
199
  {...restProps}
200
200
  />
201
201
  <MarkerWrapper id={markerStartId} marker={markerStart ?? marker} />
202
202
  <MarkerWrapper id={markerMidId} marker={markerMid ?? marker} />
203
203
  <MarkerWrapper id={markerEndId} marker={markerEnd ?? marker} />
204
+ {:else if renderCtx === 'html'}
205
+ {@const { angle, length } = pointsToAngleAndLength(
206
+ { x: motionX1.current, y: motionY1.current },
207
+ { x: motionX2.current, y: motionY2.current }
208
+ )}
209
+ <!-- STYLE-TODO: Should html use stroke for fill? -->
210
+ <div
211
+ style:position="absolute"
212
+ style:left="{motionX1.current}px"
213
+ style:top="{motionY1.current}px"
214
+ style:width="{length}px"
215
+ style:height="{strokeWidth ?? 1}px"
216
+ style:transform="translateY(-50%) rotate({angle}deg)"
217
+ style:transform-origin="0 50%"
218
+ style:opacity
219
+ style:background-color={stroke}
220
+ class={cls('lc-line', className)}
221
+ style={restProps.style}
222
+ ></div>
204
223
  {/if}
224
+
225
+ <style>
226
+ @layer base {
227
+ :global(:where(.lc-line)) {
228
+ --stroke-color: var(--color-surface-content, currentColor);
229
+ }
230
+
231
+ /* Svg | Canvas layers */
232
+ :global(:where(.lc-layout-svg .lc-line, svg.lc-line):not([stroke])) {
233
+ stroke: var(--stroke-color);
234
+ }
235
+
236
+ /* Html layers */
237
+ :global(:where(.lc-layout-html .lc-line):not([background-color])) {
238
+ background-color: var(--stroke-color);
239
+ }
240
+ }
241
+ </style>
@@ -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>